[Gc] Patch to prevent deep recursion from a finalizer (a bit better solution)

Ivan Maidanski ivmai at mail.ru
Thu Aug 6 09:05:54 PDT 2009


Hi!

I've revised my previous solution preventing deep recursion from a finalizer (when it allocates memory) - I've replaced compiler/OS-specific thread-local storage with additional fields in GC_Thread_Rep struct. I've also re-arranged locking/unlocking in GC_notify_or_invoke_finalizers() so to avoid date races when accessing GC_finalizer_now, GC_finalize_on_demand (in addition to GC_gc_no, GC_finalizer_notifier, last_finalizer_notification).

The suggested patch supersedes diff102_cvs fully, is against the current CVS and doesn't depend on any of my pending patches.

For my old solution post, see: http://article.gmane.org/gmane.comp.programming.garbage-collection.boehmgc/2864

ChangeLog entries:

	* finalize.c (GC_fail_count): New external variable declaration.
	* finalize.c (GC_reset_finalizer_nested,
	GC_check_finalizer_nested): New function declarations (if THREADS
	only).
	* finalize.c (GC_finalizer_nested, GC_finalizer_skipped): New
	static global variables (used internally by GC_finalize() and
	GC_check_finalizer_nested()).
	* finalize.c (GC_check_finalizer_nested): New static function
	definition (only if not THREADS, used internally by
	GC_notify_or_invoke_finalizers() to minimize the probability of
	a deep recursion when a client finalizer tries to allocate GC
	memory).
	* finalize.c (GC_finalize): Reset GC_finalizer_nested value (or
	call GC_reset_finalizer_nested()) if last heap expansion failed.
	* finalize.c (GC_notify_or_invoke_finalizers): Access GC_gc_no,
	GC_finalizer_now, GC_finalize_on_demand, GC_finalizer_notifier,
	last_finalizer_notification variables holding the lock (to avoid
	data races).
	* finalize.c (GC_finalizer_notifier): Add comment.
	* finalize.c (GC_notify_or_invoke_finalizers): Add "quick" check
	for an empty finalization queue (only if THREADS and not
	KEEP_BACK_PTRS/MAKE_BACK_GRAPH).
	* finalize.c (GC_notify_or_invoke_finalizers): Call
	GC_check_finalizer_nested() and skip GC_invoke_finalizers() call
	if appropriate.
	* include/private/pthread_support.h (GC_Thread_Rep): Add unsigned
	finalizer_nested and finalizer_skipped fields (for internal use
	by the multi-threaded GC_check_finalizer_nested()).
	* win32_threads.c (GC_Thread_Rep): Ditto.
	* pthread_support.c (GC_reset_finalizer_nested,
	GC_check_finalizer_nested): New function definitions (the
	multi-threaded variants of that in finalize.c).
	* win32_threads.c (GC_reset_finalizer_nested,
	GC_check_finalizer_nested): Ditto.

Bye.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: diff112
Type: application/octet-stream
Size: 9343 bytes
Desc: not available
Url : http://napali.hpl.hp.com/pipermail/gc/attachments/20090806/fb464c28/diff112.obj


More information about the Gc mailing list