This is the mail archive of the
java@gcc.gnu.org
mailing list for the Java project.
RE: libgcj and incremental gc
- From: "Boehm, Hans" <hans dot boehm at hp dot com>
- To: "Andrew Haley" <aph at redhat dot com>, <java at gcc dot gnu dot org>
- Date: Wed, 23 Mar 2005 10:51:48 -0800
- Subject: RE: libgcj and incremental gc
Thanks for trying this. This was on X86? I wonder if the trampolines
just lose execute permission?
I would not in general turn this on by default. But it might be a
useful option. The vague plan I had was to add some mechanism for
turning this on only if both:
- the user asks, and
- the page size is equal to HBLKSIZE
It may be that the GC_ENABLE_INCREMENTAL environment variable should
acquire this meaning. It currently doesn't check the second
condition.
The second condition is necessary to ensure that pointer-free objects
are never write protected.
I think the hard part in making this work is that we would have to
ensure
that system calls only write to pointer-free objects. I think that's
hard only because I'm not sure there's an easy way to find and check
all of them.
Hans
> -----Original Message-----
> From: java-owner@gcc.gnu.org [mailto:java-owner@gcc.gnu.org]
> On Behalf Of Andrew Haley
> Sent: Wednesday, March 23, 2005 8:04 AM
> To: java@gcc.gnu.org
> Subject: libgcj and incremental gc
>
>
> The Boehm gc includes an incremental option, which we've never used.
>
> I've tried to enable it as an experiment, but there are
> problems. In particular, we seem prematurely to reclaim
> trampolines that point to interpreted method bodies.
>
> I'm not going to pursue this any further, but I'm posting the
> patch that enables incremental gc for reference.
>
> Andrew.
>
>
> Index: libjava/include/i386-signal.h
> ===================================================================
> RCS file: /cvs/gcc/gcc/libjava/include/i386-signal.h,v
> retrieving revision 1.19
> diff -p -2 -c -r1.19 i386-signal.h
> *** libjava/include/i386-signal.h 26 Sep 2004 20:38:48
> -0000 1.19
> --- libjava/include/i386-signal.h 23 Mar 2005 15:44:34 -0000
> *************** details. */
> *** 21,38 ****
>
> #define SIGNAL_HANDLER(_name) \
> ! static void _name (int _dummy __attribute__ ((__unused__)))
>
> ! #define MAKE_THROW_FRAME(_exception)
> \
> ! do
> \
> ! {
> \
> ! void **_p = (void **)&_dummy;
> \
> ! volatile struct sigcontext_struct *_regs = (struct
> sigcontext_struct *)++_p; \
> !
> \
> ! /* Advance the program counter so that it is after the
> start of the \
> ! instruction: the x86 exception handler expects
> \
> ! the PC to point to the instruction after a call. */
> \
> ! _regs->eip += 2;
> \
> !
> \
> ! }
> \
> while (0)
>
> --- 21,52 ----
>
> #define SIGNAL_HANDLER(_name) \
> ! static void _name (int _sig __attribute__ ((__unused__)))
>
> ! extern "C" int in_allocd_block (void *addr);
> !
> ! #define MAKE_THROW_FRAME(_exception)
> \
> ! do
> \
> ! {
> \
> ! void **_p = (void **)&_sig;
> \
> ! struct sigcontext_struct *
> \
> ! _regs = (struct sigcontext_struct *)(_p+1);
> \
> !
> \
> ! if (_sig == SIGSEGV)
> \
> ! {
> \
> ! void *addr = (void*)_regs->cr2;
> \
> ! if (in_allocd_block (addr))
> \
> ! {
> \
> ! typedef void (*sighandler_t)(int, struct sigcontext);
> \
> ! sighandler_t handler =
> (sighandler_t)old_sigaction.k_sa_handler; \
> ! (*handler)(_sig, *_regs);
> \
> ! return;
> \
> ! }
> \
> ! }
> \
> ! /* Advance the program counter so that it is after the
> start of the \
> ! instruction: the x86 exception handler expects
> \
> ! the PC to point to the instruction after a call. */
> \
> ! ((volatile struct sigcontext_struct *)_regs)->eip += 2;
> \
> !
> \
> ! }
> \
> while (0)
>
> *************** while (0)
> *** 40,44 ****
> do
> \
> {
> \
> ! void **_p = (void **)&_dummy;
> \
> volatile struct sigcontext_struct *_regs = (struct
> sigcontext_struct *)++_p;\
>
> \
> --- 54,58 ----
> do
> \
> {
> \
> ! void **_p = (void **)&_sig;
> \
> volatile struct sigcontext_struct *_regs = (struct
> sigcontext_struct *)++_p;\
>
> \
> *************** struct old_i386_kernel_sigaction {
> *** 109,112 ****
> --- 123,128 ----
> };
>
> + static struct old_i386_kernel_sigaction old_sigaction;
> +
> #define RESTORE(name, syscall) RESTORE2 (name, syscall)
> # define RESTORE2(name, syscall) \
> *************** do
> \
> *** 133,137 ****
> kact.k_sa_flags = 0x4000000; \
> kact.sa_restorer = restore; \
> ! syscall (SYS_sigaction, SIGSEGV, &kact, NULL); \
> } \
> while (0)
> --- 149,153 ----
> kact.k_sa_flags = 0x4000000; \
> kact.sa_restorer = restore; \
> ! syscall (SYS_sigaction, SIGSEGV, &kact,
> &old_sigaction); \
> } \
> while (0)
> Index: boehm-gc/os_dep.c
> ===================================================================
> RCS file: /cvs/gcc/gcc/boehm-gc/os_dep.c,v
> retrieving revision 1.30
> diff -p -2 -c -r1.30 os_dep.c
> *** boehm-gc/os_dep.c 13 Aug 2004 23:05:30 -0000 1.30
> --- boehm-gc/os_dep.c 23 Mar 2005 15:44:39 -0000
> *************** SIG_PF GC_old_segv_handler; /* Also old
> *** 2358,2361 ****
> --- 2358,2367 ----
> #endif /* !THREADS */
>
> + int
> + in_allocd_block (void *addr)
> + {
> + return (HDR(addr) != 0);
> + }
> +
> /*ARGSUSED*/
> #if !defined(DARWIN)
> Index: libjava/prims.cc
> ===================================================================
> RCS file: /cvs/gcc/gcc/libjava/prims.cc,v
> retrieving revision 1.105
> diff -p -2 -c -r1.105 prims.cc
> *** libjava/prims.cc 10 Mar 2005 19:02:16 -0000 1.105
> --- libjava/prims.cc 23 Mar 2005 15:51:02 -0000
> *************** unblock_signal (int signum __attribute__
> *** 145,148 ****
> --- 145,152 ----
> #endif
>
> + #ifdef FORWARD_SEGV
> + struct gcj_kernel_sigaction old_sigaction;
> + #endif
> +
> #ifdef HANDLE_SEGV
> SIGNAL_HANDLER (catch_segv)
> *************** parse_init_args (JvVMInitArgs* vm_args)
> *** 1070,1073 ****
> --- 1074,1100 ----
> }
>
> + extern "C"
> + {
> + #include <gc_config.h>
> +
> + // Set GC_DEBUG before including gc.h!
> + #ifdef LIBGCJ_GC_DEBUG
> + # define GC_DEBUG
> + #endif
> +
> + #include <gc_mark.h>
> + #include <gc_gcj.h>
> + #include <javaxfc.h> // GC_finalize_all declaration.
> +
> + #ifdef THREAD_LOCAL_ALLOC
> + # define GC_REDIRECT_TO_LOCAL
> + # include <gc_local_alloc.h>
> + #endif
> +
> + // From boehm's misc.c
> + void GC_enable();
> + void GC_disable();
> + };
> +
> jint
> _Jv_CreateJavaVM (JvVMInitArgs* vm_args)
> *************** _Jv_CreateJavaVM (JvVMInitArgs* vm_args)
> *** 1090,1093 ****
> --- 1117,1121 ----
> _Jv_InitThreads ();
> _Jv_InitGC ();
> + GC_enable_incremental ();
> _Jv_InitializeSyncMutex ();
>
>
>