From patchwork Thu Aug 26 22:33:33 2010 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ian Lance Taylor X-Patchwork-Id: 62811 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from sourceware.org (server1.sourceware.org [209.132.180.131]) by ozlabs.org (Postfix) with SMTP id C2096B70D4 for ; Fri, 27 Aug 2010 08:33:51 +1000 (EST) Received: (qmail 8839 invoked by alias); 26 Aug 2010 22:33:48 -0000 Received: (qmail 8827 invoked by uid 22791); 26 Aug 2010 22:33:47 -0000 X-SWARE-Spam-Status: No, hits=-2.3 required=5.0 tests=AWL, BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, SPF_HELO_PASS, TW_CC, T_RP_MATCHES_RCVD, T_TVD_MIME_NO_HEADERS X-Spam-Check-By: sourceware.org Received: from smtp-out.google.com (HELO smtp-out.google.com) (74.125.121.35) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Thu, 26 Aug 2010 22:33:41 +0000 Received: from wpaz24.hot.corp.google.com (wpaz24.hot.corp.google.com [172.24.198.88]) by smtp-out.google.com with ESMTP id o7QMXcOc004271 for ; Thu, 26 Aug 2010 15:33:39 -0700 Received: from pvh11 (pvh11.prod.google.com [10.241.210.203]) by wpaz24.hot.corp.google.com with ESMTP id o7QMXbbr015211 for ; Thu, 26 Aug 2010 15:33:37 -0700 Received: by pvh11 with SMTP id 11so1223193pvh.18 for ; Thu, 26 Aug 2010 15:33:37 -0700 (PDT) Received: by 10.114.92.17 with SMTP id p17mr12016478wab.38.1282862016713; Thu, 26 Aug 2010 15:33:36 -0700 (PDT) Received: from coign.google.com ([216.239.45.130]) by mx.google.com with ESMTPS id d39sm5272036wam.4.2010.08.26.15.33.35 (version=TLSv1/SSLv3 cipher=RC4-MD5); Thu, 26 Aug 2010 15:33:35 -0700 (PDT) From: Ian Lance Taylor To: gcc-patches@gcc.gnu.org, gofrontend-dev@googlegroups.com Subject: [gccgo] Avoid another deadlock in GC when profiling Date: Thu, 26 Aug 2010 15:33:33 -0700 Message-ID: User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/23.1 (gnu/linux) MIME-Version: 1.0 X-System-Of-Record: true X-IsSubscribed: yes Mailing-List: contact gcc-patches-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Archive: List-Post: List-Help: Sender: gcc-patches-owner@gcc.gnu.org Delivered-To: mailing list gcc-patches@gcc.gnu.org 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)