[Gc] A new API func suggested - "anti GC_do_blocking" (part 1/2)

Ivan Maidanski ivmai at mail.ru
Tue Apr 14 11:05:41 PDT 2009


At present, it's impossible to stop "blocking" temporarily inside a user func called from GC_do_blocking() (it wasn't a problem when GC_start/stop_blocking() existed but that approach is broken anyway...).

So, I suggest a new API function - GC_call_with_gc_active(fn, data) which has the opposite to GC_do_blocking(fn, data) functionality (and is somewhat based on GC_call_with_stack_base()).

Possible usage 1: JVM: wrap every native function call into GC_do_blocking(), and wrap every JNI call into GC_call_with_gc_active().

Possible usage 2: correct (optimization-resistant) initialization of GC_stackbottom (on a platform where GC_get_main_stack_base() is unimplemented): main(argv) { return GC_call_with_gc_active(real_main, argv); } (this is similar to GC_call_with_stack_base(<fn>{GC_register_my_thread(sb);...}) usage but for main thread).

Note 1: It's possible to recursively call GC_do_blocking() and GC_call_with_gc_active() each other, and the thread's stack scanning is done accurately - the stack frames "belonging" to the user functions "laying" between every GC_do_blocking and GC_call_with_gc_active are not scanned (including IA64 registers backing store).

Note 2: GC_do_blocking() and GC_call_with_gc_active() are also implemented for the single-threaded case (for the purposes indicated by "usage 2" and "note 1").

Note 3: Darwin threads: not implemented - calls to GC_do_blocking() and GC_call_with_gc_active() are ignored at present (except for thread's stack base adjustment).

Note 4: pthreads on IA64 should compile and work but not tested.

The attached patch is split to 2 parts (just due to mail list constraints).

My current version of GC v7.2alpha1 (snapshot + pending patches) is at: http://www.ivmaisoft.com/sources/jcgo/bdwgc72a1-20090414-ivmai.tar.bz2

PS. There's an idea to add also another API call - int GC_register_my_thread_inactive(void) - which registers the current thread (allocates GC_thread and thread-local-alloc structures) and sets "thread_blocked" on without setting the stack base (the possible JVM usage is "AttachCurrentThread") - but at present (at least) I don't know how to do it in the backward-compatible manner and how to do it for the main thread.


More information about the Gc mailing list