[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


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: https://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
	* finalize.c (GC_finalizer_nested, GC_finalizer_skipped): New
	static global variables (used internally by GC_finalize() and
	* 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
	* 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
	* 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.

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

More information about the Gc mailing list