This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
[gccgo] Avoid another deadlock in GC when profiling
- From: Ian Lance Taylor <iant at google dot com>
- To: gcc-patches at gcc dot gnu dot org, gofrontend-dev at googlegroups dot com
- Date: Thu, 26 Aug 2010 15:33:33 -0700
- Subject: [gccgo] Avoid another deadlock in GC when profiling
This patch avoids the other deadlock in GC when profiling: don't let
malloc continue the GC if it is invoked on behalf of the profiler. The
last patch fixed the case where the GC asked the profiler to start the
GC, this patch fixes the case where the GC asks malloc to start the GC.
Committed to gccgo branch.
Ian
diff -r c4496094f7b1 libgo/runtime/malloc.goc
--- a/libgo/runtime/malloc.goc Thu Aug 26 15:09:54 2010 -0700
+++ b/libgo/runtime/malloc.goc Thu Aug 26 15:31:29 2010 -0700
@@ -99,8 +99,16 @@
__sync_bool_compare_and_swap(&m->mallocing, 1, 0);
- if(__sync_bool_compare_and_swap(&m->gcing, 1, 0))
- __go_run_goroutine_gc(0);
+ if(__sync_bool_compare_and_swap(&m->gcing, 1, 0)) {
+ if(!(refflag & RefNoProfiling))
+ __go_run_goroutine_gc(0);
+ else {
+ // We are being called from the profiler. Tell it
+ // to invoke the garbage collector when it is
+ // done. No need to use a sync function here.
+ m->gcing_for_prof = 1;
+ }
+ }
if(!(refflag & RefNoProfiling) && (rate = MemProfileRate) > 0) {
if(size >= (uint32) rate)