From patchwork Fri Apr 7 12:58:34 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Biener X-Patchwork-Id: 748241 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 3w005M50dNz9s8G for ; Fri, 7 Apr 2017 22:59:01 +1000 (AEST) Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.b="jM04UB+0"; 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:date :from:to:subject:message-id:mime-version:content-type; q=dns; s= default; b=ZGUOpcFR+OdmFqd2OP0gvAUPWg7hqSxuRlFu2U29RCN99y/um3Yn9 2OHG+6pbDXHg7FGRYEwH3U77ajb7uKtkt4Y4bfqknET+b1oKGiEmkT3m/hRYv2Ss XCJNJgfN1yve/fAg5+w4a3gNAbydxJW9HWvNZovVqgpTqlfJGcXEJs= 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:date :from:to:subject:message-id:mime-version:content-type; s= default; bh=OUhduAZag9MAS4xgszRDrXfkmow=; b=jM04UB+0ax7r2SxZWjkY 81aod41iFA58BzmwRvpE3mAEQcNzVVFpnuzj9wlTi5pY/Bsj+oRa4MY+oxwZvhVo f5i/Q2oFvEqDBFiUy7YI9uRGZLeoOrRp2eDkeH1UJW3QvW+XjuxAzoE85afX6xt6 lchXfrG8dXCbsw3bgh7RkPs= Received: (qmail 57867 invoked by alias); 7 Apr 2017 12:58:37 -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 57797 invoked by uid 89); 7 Apr 2017 12:58:36 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-16.9 required=5.0 tests=BAYES_00, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, RP_MATCHES_RCVD, SPF_PASS autolearn=ham version=3.3.2 spammy= X-HELO: mx2.suse.de Received: from mx2.suse.de (HELO mx2.suse.de) (195.135.220.15) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Fri, 07 Apr 2017 12:58:34 +0000 Received: from relay1.suse.de (charybdis-ext.suse.de [195.135.220.254]) by mx2.suse.de (Postfix) with ESMTP id 2AB74ABFA for ; Fri, 7 Apr 2017 12:58:34 +0000 (UTC) Date: Fri, 7 Apr 2017 14:58:34 +0200 (CEST) From: Richard Biener To: gcc-patches@gcc.gnu.org Subject: [PATCH] Speedup gt_ggc_m_S Message-ID: User-Agent: Alpine 2.20 (LSU 67 2015-01-07) MIME-Version: 1.0 Currently it looks up the page table entry for the string twice, once in the ggc_allocated_p test (for strings allocated by libcpp?) and once for the final lookup. The following simply turns ggc_allocated_p into a safe_lookup_page_table_entry. Bootstrapped and tested on x86_64-unknown-linux-gnu, queued for GCC 8. Richard. 2017-04-07 Richard Biener * ggc-page.c (ggc_allocated_p): Rename to ... (safe_lookup_page_table_entry): ... this and return the lookup result. (gt_ggc_m_S): Use safe_lookup_page_table_entry. Index: gcc/ggc-page.c =================================================================== --- gcc/ggc-page.c (revision 246758) +++ gcc/ggc-page.c (working copy) @@ -522,7 +522,6 @@ static bool in_gc = false; /* Initial guess as to how many page table entries we might need. */ #define INITIAL_PTE_COUNT 128 -static int ggc_allocated_p (const void *); static page_entry *lookup_page_table_entry (const void *); static void set_page_table_entry (void *, page_entry *); #ifdef USING_MMAP @@ -587,10 +586,11 @@ push_by_depth (page_entry *p, unsigned l #define save_in_use_p(__p) \ (save_in_use_p_i (__p->index_by_depth)) -/* Returns nonzero if P was allocated in GC'able memory. */ +/* Traverse the page table and find the entry for a page. + If the object wasn't allocated in GC return NULL. */ -static inline int -ggc_allocated_p (const void *p) +static inline page_entry * +safe_lookup_page_table_entry (const void *p) { page_entry ***base; size_t L1, L2; @@ -603,7 +603,7 @@ ggc_allocated_p (const void *p) while (1) { if (table == NULL) - return 0; + return NULL; if (table->high_bits == high_bits) break; table = table->next; @@ -614,8 +614,10 @@ ggc_allocated_p (const void *p) /* Extract the level 1 and 2 indices. */ L1 = LOOKUP_L1 (p); L2 = LOOKUP_L2 (p); + if (! base[L1]) + return NULL; - return base[L1] && base[L1][L2]; + return base[L1][L2]; } /* Traverse the page table and find the entry for a page. @@ -1455,12 +1457,14 @@ gt_ggc_m_S (const void *p) unsigned long mask; unsigned long offset; - if (!p || !ggc_allocated_p (p)) + if (!p) return; - /* Look up the page on which the object is alloced. . */ - entry = lookup_page_table_entry (p); - gcc_assert (entry); + /* Look up the page on which the object is alloced. If it was not + GC allocated, gracefully bail out. */ + entry = safe_lookup_page_table_entry (p); + if (!entry) + return; /* Calculate the index of the object on the page; this is its bit position in the in_use_p bitmap. Note that because a char* might