From patchwork Sun Jul 12 15:58:59 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tom de Vries X-Patchwork-Id: 494136 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 F3FB91402D8 for ; Mon, 13 Jul 2015 01:59:28 +1000 (AEST) Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.b=uFYO4SUC; 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 :message-id:date:from:mime-version:to:subject:references :in-reply-to:content-type; q=dns; s=default; b=oEud/CJpYz9eI9Vi4 4uatmxO+Zre41cdirlRsA0hgCATnHYDSAuWZvYAT4oZgjBtV2HeR1uI7cgz3+Lss oM9USajXhpxtBtVrvZl0c9oWJRqwDBGbCtedsbRdYovIK0YACfx06C/Oc6AxVUPx iEqnfTughA7qG29+bxZnYqEceE= 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 :message-id:date:from:mime-version:to:subject:references :in-reply-to:content-type; s=default; bh=VfoVoxVU4lSOi0b3OOPsVjb Lrrk=; b=uFYO4SUCe9XzMUB418c2QI3D9gODZKWLEfp8yxWrEmLfu04XHqBRGJz 6jSREIQHQtgy52XpHOewvOFSBx5SydMfMozSztCC7m7h3IZCt4vfDj/DixDr04gR /INwbuFeiczlIyAXGxsOF6ts4ApXWFxXRYmhzB5r4c2P5YSfTD7s= Received: (qmail 53113 invoked by alias); 12 Jul 2015 15:59:21 -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 53074 invoked by uid 89); 12 Jul 2015 15:59:19 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-2.7 required=5.0 tests=AWL, BAYES_00, RP_MATCHES_RCVD, SPF_PASS autolearn=ham version=3.3.2 X-HELO: fencepost.gnu.org Received: from fencepost.gnu.org (HELO fencepost.gnu.org) (208.118.235.10) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with (AES128-SHA encrypted) ESMTPS; Sun, 12 Jul 2015 15:59:17 +0000 Received: from eggs.gnu.org ([2001:4830:134:3::10]:38516) by fencepost.gnu.org with esmtps (TLS1.0:RSA_AES_256_CBC_SHA1:256) (Exim 4.82) (envelope-from ) id 1ZEJer-00026V-SW for gcc-patches@gnu.org; Sun, 12 Jul 2015 11:59:14 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ZEJem-00064y-Be for gcc-patches@gnu.org; Sun, 12 Jul 2015 11:59:13 -0400 Received: from relay1.mentorg.com ([192.94.38.131]:53225) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ZEJem-00064s-2e for gcc-patches@gnu.org; Sun, 12 Jul 2015 11:59:08 -0400 Received: from nat-ies.mentorg.com ([192.94.31.2] helo=SVR-IES-FEM-02.mgc.mentorg.com) by relay1.mentorg.com with esmtp id 1ZEJek-0004MJ-Id from Tom_deVries@mentor.com for gcc-patches@gnu.org; Sun, 12 Jul 2015 08:59:07 -0700 Received: from [127.0.0.1] (137.202.0.76) by SVR-IES-FEM-02.mgc.mentorg.com (137.202.0.106) with Microsoft SMTP Server id 14.3.224.2; Sun, 12 Jul 2015 16:59:05 +0100 Message-ID: <55A28EC3.4080202@mentor.com> Date: Sun, 12 Jul 2015 17:58:59 +0200 From: Tom de Vries User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:31.0) Gecko/20100101 Thunderbird/31.7.0 MIME-Version: 1.0 To: "gcc-patches@gnu.org" Subject: [PATCH 5/5] Don't mark live recursively in gt_cleare_cache References: <55A28B9E.1030706@mentor.com> In-Reply-To: <55A28B9E.1030706@mentor.com> X-detected-operating-system: by eggs.gnu.org: Windows NT kernel [generic] [fuzzy] X-Received-From: 192.94.38.131 On 12/07/15 17:45, Tom de Vries wrote: > Hi, > > this patch series implements the forbidding of multi-step garbage > collection liveness dependencies between caches. > > The first four patches downgrade 3 caches to non-cache, since they > introduce multi-step dependencies. This allows us to decouple: > - establishing a policy for multi-step dependencies in caches, and > - fixing issues that allow us to use these 3 as caches again. > > 1. Downgrade debug_args_for_decl to non-cache > 2. Add struct tree_decl_map_hasher > 3. Downgrade debug_expr_for_decl to non-cache > 4. Downgrade value_expr_for_decl to non-cache > 5. Don't mark live recursively in gt_cleare_cache > > Bootstrapped and reg-tested on x86_64, with ENABLE_CHECKING. > > I'll post the patches in response to this email. > This patch: - disables the recursive marking of cache entries during the cache-clear phase - Adds ENABLE_CHECKING code to check that we don't end up with partially dead cache entries OK for trunk? Thanks, - Tom [PATCH 5/5] Don't mark live recursively in gt_cleare_cache 2015-07-10 Tom de Vries PR libgomp/66714 * hash-table.h (gt_cleare_cache): Mark cache entry non-recursively. (gt_cleare_cache) [ENABLE_CHECKING]: Assert non-key components of live entry already marked. Assert dead key component implies dead entry. * tree.h (struct tree_decl_map_cache_hasher) [ENABLE_CHECKING]: Add new function ggc_marked_nonkey_p. * tree.c (struct tree_vec_map_cache_hasher) [ENABLE_CHECKING]: Same. * ubsan.c (struct tree_type_map_cache_hasher) [ENABLE_CHECKING]: Same. * varasm.c (struct tm_clone_hasher) [ENABLE_CHECKING]: Same. * hash-traits.h (struct ggc_cache_remove) [ENABLE_CHECKING]: Same. * trans-mem.c (struct tm_wrapper_hasher) [ENABLE_CHECKING]: Same. * testsuite/libgomp.c/pr66714.c: New test. --- gcc/hash-table.h | 64 +++++++++++++++++++++++++++++++++-- gcc/hash-traits.h | 4 +++ gcc/trans-mem.c | 6 ++++ gcc/tree.c | 6 ++++ gcc/tree.h | 6 ++++ gcc/ubsan.c | 6 ++++ gcc/varasm.c | 6 ++++ libgomp/testsuite/libgomp.c/pr66714.c | 17 ++++++++++ 8 files changed, 113 insertions(+), 2 deletions(-) create mode 100644 libgomp/testsuite/libgomp.c/pr66714.c diff --git a/gcc/hash-table.h b/gcc/hash-table.h index 12e0c96..282ba8a 100644 --- a/gcc/hash-table.h +++ b/gcc/hash-table.h @@ -1046,14 +1046,74 @@ gt_cleare_cache (hash_table *h) if (!h) return; + /* There are roughly 2 types of cache entries. + + I. + + The simple one, that uses ggc_cache_remove::keep_cache_entry. + + int keep_cache_entry (T &e) { return ggc_marked_p (e) ? -1 : 0; } + + The function returns either live (-1) or dead (0), dependent on whether the + entry was marked during the marking phase. + + If the entry is dead, we clear the slot holding the entry. The slot can be + now be reused, and the entry will be freed during the sweeping phase. + + If the entry is live we're done. The entry itself, and anything reachable + from the entry have been marked during the marking phase. + + + II. + + The complex one, with a non-standard keep_cache_entry. + + Say we have a cache entry E with key field to and non-key field from: + + struct sE { + type1 from; + type2 to; + }; + typedef struct sE *E; + + and a keep_cache_entry function: + + int keep_cache_entry (E &e) { return ggc_marked_p (e->from); } + + The function returns either live (1) or dead (0), dependent on whether the + from field of the entry was marked during the marking phase. + + If the from field is dead, we clear the slot holding the entry. The slot + can be now be reused, and the from field will be freed during the sweeping + phase. The to field will be freed during the sweeping phase dependent on + whether it was marked live during the marking phase. Furthermore, we check + that the entry was not marked. If that that check fails, it means that + we ended up with a live entry with a dead from field. + + If the from field is live, we mark the entry non-recursively live, since + the cache may hold the only reference to the entry. + However, we check that anything reachable from the entry has already been + marked during the marking phase. If that that check fails, it means that + we ended up with a live entry with a dead to field. */ + for (typename table::iterator iter = h->begin (); iter != h->end (); ++iter) if (!table::is_empty (*iter) && !table::is_deleted (*iter)) { int res = H::keep_cache_entry (*iter); if (res == 0) - h->clear_slot (&*iter); + { +#ifdef ENABLE_CHECKING + gcc_assert (!ggc_marked_p (*iter)); +#endif + h->clear_slot (&*iter); + } else if (res != -1) - gt_ggc_mx (*iter); + { + ggc_set_mark (*iter); +#ifdef ENABLE_CHECKING + gcc_assert (H::ggc_marked_nonkey_p (*iter)); +#endif + } } } diff --git a/gcc/hash-traits.h b/gcc/hash-traits.h index 450354a..9c0ff65 100644 --- a/gcc/hash-traits.h +++ b/gcc/hash-traits.h @@ -241,6 +241,10 @@ struct ggc_cache_remove : ggc_remove /* Entries are weakly held because this is for caches. */ static void ggc_mx (T &) {} +#ifdef ENABLE_CHECKING + static int ggc_marked_nonkey_p (T &) { return 1; } +#endif + static int keep_cache_entry (T &e) { diff --git a/gcc/trans-mem.c b/gcc/trans-mem.c index c809a2e..70432f3 100644 --- a/gcc/trans-mem.c +++ b/gcc/trans-mem.c @@ -478,6 +478,12 @@ struct tm_wrapper_hasher : ggc_cache_ptr_hash return a->base.from == b->base.from; } +#ifdef ENABLE_CHECKING + static int ggc_marked_nonkey_p (tree_map *&m) { + return ggc_marked_p (m->to); + } +#endif + static int keep_cache_entry (tree_map *&m) { diff --git a/gcc/tree.c b/gcc/tree.c index bb4467d..fbcb37d 100644 --- a/gcc/tree.c +++ b/gcc/tree.c @@ -271,6 +271,12 @@ struct tree_vec_map_cache_hasher : ggc_cache_ptr_hash return a->base.from == b->base.from; } +#ifdef ENABLE_CHECKING + static int ggc_marked_nonkey_p (tree_vec_map *&m) { + return ggc_marked_p (m->to); + } +#endif + static int keep_cache_entry (tree_vec_map *&m) { diff --git a/gcc/tree.h b/gcc/tree.h index 8d8fb7e..c100c365 100644 --- a/gcc/tree.h +++ b/gcc/tree.h @@ -4635,6 +4635,12 @@ struct tree_decl_map_cache_hasher : ggc_cache_ptr_hash return tree_decl_map_eq (a, b); } +#ifdef ENABLE_CHECKING + static int ggc_marked_nonkey_p (tree_decl_map *&m) { + return ggc_marked_p (m->to); + } +#endif + static int keep_cache_entry (tree_decl_map *&m) { diff --git a/gcc/ubsan.c b/gcc/ubsan.c index 19eafab..350ad22 100644 --- a/gcc/ubsan.c +++ b/gcc/ubsan.c @@ -95,6 +95,12 @@ struct tree_type_map_cache_hasher : ggc_cache_ptr_hash return a->type.from == b->type.from; } +#ifdef ENABLE_CHECKING + static int ggc_marked_nonkey_p (tree_type_map *&m) { + return ggc_marked_p (m->decl); + } +#endif + static int keep_cache_entry (tree_type_map *&m) { diff --git a/gcc/varasm.c b/gcc/varasm.c index 3e76032..4e44c43 100644 --- a/gcc/varasm.c +++ b/gcc/varasm.c @@ -5793,6 +5793,12 @@ struct tm_clone_hasher : ggc_cache_ptr_hash static hashval_t hash (tree_map *m) { return tree_map_hash (m); } static bool equal (tree_map *a, tree_map *b) { return tree_map_eq (a, b); } +#ifdef ENABLE_CHECKING + static int ggc_marked_nonkey_p (tree_map *&m) { + return ggc_marked_p (m->to); + } +#endif + static int keep_cache_entry (tree_map *&e) { diff --git a/libgomp/testsuite/libgomp.c/pr66714.c b/libgomp/testsuite/libgomp.c/pr66714.c new file mode 100644 index 0000000..a8c5bbdb --- /dev/null +++ b/libgomp/testsuite/libgomp.c/pr66714.c @@ -0,0 +1,17 @@ +/* { dg-do "compile" } */ +/* { dg-additional-options "--param ggc-min-expand=0" } */ +/* { dg-additional-options "--param ggc-min-heapsize=0" } */ +/* { dg-additional-options "-g" } */ + +/* Minimized from target-2.c. */ + +void +fn3 (int x) +{ + double b[3 * x]; + int i; + #pragma omp target + #pragma omp parallel for + for (i = 0; i < x; i++) + b[i] += 1; +} -- 1.9.1