From patchwork Thu Jan 28 00:44:53 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Patrick Palka X-Patchwork-Id: 574494 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]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 5F9B6140C1C for ; Thu, 28 Jan 2016 11:45:14 +1100 (AEDT) Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.b=dKSObDym; dkim-atps=neutral DomainKey-Signature: a=rsa-sha1; c=nofws; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender:from :to:cc:subject:date:message-id; q=dns; s=default; b=kfIyoa8wPjFy s9ip1lF7UwLJ4P1zDN4jXQROzyUpIaFiVm5FjBhdE8IqdBUBZlvrj1/x54SLx86z s8DwxfluuTssu3jyKSD+22sjVCldXJEbpbkRSpOyxg73oy5vaPG6e4zVWXKktary 2/zB/SFas7SfnmIAqHcOGdGYPHVb98g= DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender:from :to:cc:subject:date:message-id; s=default; bh=TF1EGJMeRgw+CmPpZW O7eBkv7zE=; b=dKSObDymO1gaulazBr2AGe1AWW1UtrTymuEbabpIYTw9F979OK wRe6PzUUjhFAO7/5y6lEz8/jSIOJF7ggpflwhJ1QqSY2HudJdQtAoOSJFjRbTWat lfk/SY3qneVCwiIWipc/TC5ULjmXvn7YR0jamqMSmT2sC3qvOsr0j7/Ho= Received: (qmail 26051 invoked by alias); 28 Jan 2016 00:45:04 -0000 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 Received: (qmail 25995 invoked by uid 89); 28 Jan 2016 00:45:03 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-2.6 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_LOW autolearn=ham version=3.3.2 spammy=RSS, sk:ENABLE, Hx-languages-length:1799 X-HELO: mail-qg0-f42.google.com Received: from mail-qg0-f42.google.com (HELO mail-qg0-f42.google.com) (209.85.192.42) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with (AES128-GCM-SHA256 encrypted) ESMTPS; Thu, 28 Jan 2016 00:45:01 +0000 Received: by mail-qg0-f42.google.com with SMTP id b35so21897174qge.0 for ; Wed, 27 Jan 2016 16:45:01 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:cc:subject:date:message-id; bh=Du1v43phsJjSYAqU5SVhjv0Xox/S8+nMF5pewKIpgSc=; b=LYNovsTF7D2Wz2rqccmxOuR4k2gKModTLxvbH7bVF27kAX4dAUQHunLX6ktnaL5xuN pkfEwVdSMTnRWrsNpsi13pYz40+DY8EJjq195puZJUUCyH4bEGfx3Keba3K0hU6r1rc3 h69/3gFw9GZzyN4LkK+zYxxdhnNtEmVOevb2bjJ2xqa/pfMcWZbUa4SYb22v89WoJS9R LXlYfygFqpnFNbmXCVSnvjjbKHYzzjqMMLh3QzS/cshSBCPNgTqdj/6mUhbdOToU8nUd 1fdcvWVKEIM9O1Ar4PIAQy+WY74yt05L/F03D9qJDOx5x3YRLJ5crnPMl9/ExXVBxl8j ky/A== X-Gm-Message-State: AG10YOSiSj6N5M6CNKztPDMLx8hTS52OKmrqlGICxyNVsViQBbKMKcuuAIphEi3PqIPvDg== X-Received: by 10.140.225.9 with SMTP id v9mr214393qhb.89.1453941899439; Wed, 27 Jan 2016 16:44:59 -0800 (PST) Received: from localhost.localdomain (ool-4353abbc.dyn.optonline.net. [67.83.171.188]) by smtp.gmail.com with ESMTPSA id b135sm2808460qka.2.2016.01.27.16.44.57 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Wed, 27 Jan 2016 16:44:58 -0800 (PST) From: Patrick Palka To: gcc-patches@gcc.gnu.org Cc: jason@redhat.com, Patrick Palka Subject: [PATCH] Fix cp_binding_level reuse logic Date: Wed, 27 Jan 2016 19:44:53 -0500 Message-Id: <1453941893-2946-1-git-send-email-patrick@parcs.ath.cx> In begin_scope(), we are accidentally clearing the entire free_binding_level store whenever we reuse a single GC-alloced cp_binding_level structure from it. This happens because we erroneously update free_binding_level _after_ the pointer pointing to the next available structure has been cleared, rather than doing it the other way around. This patch reorders the two operations. This bug was introduced in commit 43959b95a / r118903 back in 2006, during a refactoring of XNEW/memset -> XCNEW etc. Using a dummy test file of mine (which simply #includes almost all of the C++ stdlib headers), according to -ftime-report and /usr/bin/time -v, this patch reduces the amount of GGC memory allocated from 150MB to 148MB and reduces the maximum RSS from 130MB to 128MB, in each case a reduction of 1.5% or so. Of course, this is because we now reuse more and allocate fewer cp_binding_level structures. Bootstrapped + regtested on x86_64-pc-linux-gnu, OK to commit at this stage? Or for stage 1? gcc/cp/ChangeLog: * name-lookup.c (begin_scope): After reusing a cp_binding_level structure, update free_binding_level before the structure's level_chain field gets cleared. --- gcc/cp/name-lookup.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/gcc/cp/name-lookup.c b/gcc/cp/name-lookup.c index c52d236..92d99aa 100644 --- a/gcc/cp/name-lookup.c +++ b/gcc/cp/name-lookup.c @@ -1557,8 +1557,8 @@ begin_scope (scope_kind kind, tree entity) if (!ENABLE_SCOPE_CHECKING && free_binding_level) { scope = free_binding_level; - memset (scope, 0, sizeof (cp_binding_level)); free_binding_level = scope->level_chain; + memset (scope, 0, sizeof (cp_binding_level)); } else scope = ggc_cleared_alloc ();