From patchwork Sat Jan 22 02:15:04 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ian Lance Taylor X-Patchwork-Id: 79972 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 8B059B70CD for ; Sat, 22 Jan 2011 13:15:40 +1100 (EST) Received: (qmail 9546 invoked by alias); 22 Jan 2011 02:15:38 -0000 Received: (qmail 9538 invoked by uid 22791); 22 Jan 2011 02:15:37 -0000 X-SWARE-Spam-Status: No, hits=-2.2 required=5.0 tests=AWL, BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, SPF_HELO_PASS, 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) (216.239.44.51) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Sat, 22 Jan 2011 02:15:22 +0000 Received: from hpaq1.eem.corp.google.com (hpaq1.eem.corp.google.com [172.25.149.1]) by smtp-out.google.com with ESMTP id p0M2FKsb029474 for ; Fri, 21 Jan 2011 18:15:20 -0800 Received: from ywa6 (ywa6.prod.google.com [10.192.1.6]) by hpaq1.eem.corp.google.com with ESMTP id p0M2FIGD025604 (version=TLSv1/SSLv3 cipher=RC4-MD5 bits=128 verify=NOT) for ; Fri, 21 Jan 2011 18:15:18 -0800 Received: by ywa6 with SMTP id 6so893084ywa.26 for ; Fri, 21 Jan 2011 18:15:17 -0800 (PST) Received: by 10.151.78.13 with SMTP id f13mr1565846ybl.135.1295662517664; Fri, 21 Jan 2011 18:15:17 -0800 (PST) Received: from coign.google.com ([67.218.105.75]) by mx.google.com with ESMTPS id q4sm865641yba.14.2011.01.21.18.15.15 (version=TLSv1/SSLv3 cipher=RC4-MD5); Fri, 21 Jan 2011 18:15:17 -0800 (PST) From: Ian Lance Taylor To: gcc-patches@gcc.gnu.org, gofrontend-dev@googlegroups.com Subject: libgo patch committed: Adjust deadlock avoidance Date: Fri, 21 Jan 2011 18:15:04 -0800 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 Because the finalizer code can call the malloc code but not vice-versa, deadlock avoidance should test whether we have the finalizer lock before testing whether we are doing an malloc. Otherwise we can have malloc deciding to run a gc even when the finalizer lock is still held. Bootstrapped and ran Go testsuite on x86_64-unknown-linux-gnu. Committed to mainline. Ian diff -r f68f39af572b libgo/runtime/go-go.c --- a/libgo/runtime/go-go.c Fri Jan 21 17:58:59 2011 -0800 +++ b/libgo/runtime/go-go.c Fri Jan 21 18:09:14 2011 -0800 @@ -297,6 +297,15 @@ { struct M *pm = m; + if (__sync_bool_compare_and_swap (&pm->holds_finlock, 1, 1)) + { + /* We can't interrupt the thread while it holds the finalizer + lock. Otherwise we can get into a deadlock when mark calls + runtime_walkfintab. */ + __sync_bool_compare_and_swap (&pm->gcing_for_finlock, 0, 1); + return; + } + if (__sync_bool_compare_and_swap (&pm->mallocing, 1, 1)) { /* m->mallocing was already non-zero. We can't interrupt the @@ -315,15 +324,6 @@ return; } - if (__sync_bool_compare_and_swap (&pm->holds_finlock, 1, 1)) - { - /* Similarly, we can't interrupt the thread while it holds the - finalizer lock. Otherwise we can get into a deadlock when - mark calls runtime_walkfintab. */ - __sync_bool_compare_and_swap (&pm->gcing_for_finlock, 0, 1); - return; - } - stop_for_gc (); }