Save registers in gc_alloc() and pass them to gc_safepoint() so the latter can scan them for references. Also save the registers in signal handler and pass them to gc_safepoint(). We need to use pre-allocated thread-local memory because we can't use the stack or malloc() in the signal handler.
Cc: Tomek Grabiec <tgrab...@gmail.com> Cc: Vegard Nossum <vegard.nos...@gmail.com> Signed-off-by: Pekka Enberg <penb...@cs.helsinki.fi> --- include/vm/gc.h | 6 ++++-- vm/gc.c | 11 ++++++++--- vm/signal.c | 8 +++++++- 3 files changed, 19 insertions(+), 6 deletions(-) diff --git a/include/vm/gc.h b/include/vm/gc.h index 343e04d..3b5889e 100644 --- a/include/vm/gc.h +++ b/include/vm/gc.h @@ -3,6 +3,8 @@ #include <stdbool.h> +struct register_state; + extern void *gc_safepoint_page; extern bool verbose_gc; extern bool gc_enabled; @@ -14,7 +16,7 @@ void *gc_alloc(size_t size); void gc_attach_thread(void); void gc_detach_thread(void); -void gc_start(void); -void gc_safepoint(void); +void gc_start(struct register_state *); +void gc_safepoint(struct register_state *); #endif diff --git a/vm/gc.c b/vm/gc.c index 93374bc..76bc5b9 100644 --- a/vm/gc.c +++ b/vm/gc.c @@ -3,6 +3,7 @@ #include <stdio.h> #include <pthread.h> +#include "arch/registers.h" #include "lib/guard-page.h" #include "vm/thread.h" #include "vm/stdlib.h" @@ -34,8 +35,12 @@ void gc_init(void) void *gc_alloc(size_t size) { + struct register_state regs; + + save_registers(®s); + if (gc_enabled) - gc_start(); + gc_start(®s); return zalloc(size); } @@ -94,7 +99,7 @@ static void do_gc_safepoint(void) --nr_in_safepoint; } -void gc_safepoint(void) +void gc_safepoint(struct register_state *regs) { pthread_mutex_lock(&safepoint_mutex); @@ -108,7 +113,7 @@ void gc_safepoint(void) /* * This is the main entrypoint to the stop-the-world GC. */ -void gc_start(void) +void gc_start(struct register_state *regs) { pthread_mutex_lock(&safepoint_mutex); diff --git a/vm/signal.c b/vm/signal.c index 094fec6..63fe0d9 100644 --- a/vm/signal.c +++ b/vm/signal.c @@ -43,6 +43,8 @@ #include <unistd.h> #include <stdio.h> +static __thread struct register_state thread_register_state; + static unsigned long throw_arithmetic_exception(unsigned long src_addr) { signal_new_exception(vm_java_lang_ArithmeticException, @@ -76,7 +78,8 @@ static unsigned long rethrow_bh(unsigned long src_addr) static unsigned long gc_safepoint_bh(unsigned long addr) { - gc_safepoint(); + gc_safepoint(&thread_register_state); + return addr; } @@ -118,6 +121,9 @@ static void sigsegv_handler(int sig, siginfo_t *si, void *ctx) /* Garbage collection safepoint */ if (si->si_addr == gc_safepoint_page) { + ucontext_t *uc = ctx; + + save_signal_registers(&thread_register_state, uc->uc_mcontext.gregs); install_signal_bh(ctx, gc_safepoint_bh); return; } -- 1.5.6.3 ------------------------------------------------------------------------------ Come build with us! The BlackBerry® Developer Conference in SF, CA is the only developer event you need to attend this year. Jumpstart your developing skills, take BlackBerry mobile applications to market and stay ahead of the curve. Join us from November 9-12, 2009. Register now! http://p.sf.net/sfu/devconf _______________________________________________ Jatovm-devel mailing list Jatovm-devel@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/jatovm-devel