From patchwork Fri Oct 14 14:36:55 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jonathan Wakely X-Patchwork-Id: 2715 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:4ac7:0:0:0:0:0 with SMTP id y7csp216963wrs; Fri, 14 Oct 2022 07:38:03 -0700 (PDT) X-Google-Smtp-Source: AMsMyM5Z77yOhVR1N6inpXnagaoVGkFTLGbsMBAvLNOzZhjESErNh1MjCmqctnYXGntGotEZUJmL X-Received: by 2002:aa7:cad5:0:b0:454:88dc:2c22 with SMTP id l21-20020aa7cad5000000b0045488dc2c22mr4535622edt.352.1665758283820; Fri, 14 Oct 2022 07:38:03 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1665758283; cv=none; d=google.com; s=arc-20160816; b=D3CDvlpwP0yjKSr1YThbHD/cU85aaUjjaO202yl47OWqg0kxz5w9qlFGi8dZfWBKyc cBdNEBuqlLdyy07iA15Ka0MQvwCcYJgBZU5ermkY3dD7BRfk86OHGuCQK634P3w63Nmf HEbryI75g8bCm7a1lLf3n6zUV0ETiiIlJVqEGRbzq6GGgf9J67pwo/uhwUrpnKiFdVsK a3oHxcOM+8jy0LE3rB1CnVOAi9IsJbi6FWC+kKlMmIlbrp1AH0LBnGCZPwf0OzdiFBkB B1jpBAXNep0PNKcQJUBkKiAokOZWrmapHZ2Sehz7uMAmT41Dg10AXh1WFOCZyar/l93s bdJQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:reply-to:from:list-subscribe:list-help:list-post :list-archive:list-unsubscribe:list-id:precedence :content-transfer-encoding:mime-version:message-id:date:subject:to :dmarc-filter:delivered-to:dkim-signature:dkim-filter; bh=EDqsHUrwZwXuhLtHaI9tVjtAFOBCyRhZgPYpQ3pUlWY=; b=Nm60qStnBb+bhD0zHxtiDk41OReqvrXSRxfKB2samgkGVofeOWkPHEqIMF98SES3AL bd3rpkQiGJvAFkch+sjs/BsWp3PSZr4/aH8jSkyF/00K8s9vjPqI0Yk0E8puR5xph51y avpFKEQYbiHbKb43DVUgx7BAiS8pIEuucm30Enfvk4qkAdtEwQ6egih97dTtweuhb/sL evO2UmT+R0YE1iqLnYVYbWX1oDLPKcf5cqGh16j31X6X96ztXM7DhNkE13il2pax+Vk7 ZV2xypeghGrYOhpNw+qiz2OtcSOvnKSAthbIZFQ/F4YavW0EHeZY3JPkLyIug3jXtPYA EV6g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=fF7eRD7h; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gnu.org Received: from sourceware.org (server2.sourceware.org. [8.43.85.97]) by mx.google.com with ESMTPS id t20-20020a1709066bd400b00783698dd8b4si2114080ejs.722.2022.10.14.07.38.03 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 14 Oct 2022 07:38:03 -0700 (PDT) Received-SPF: pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) client-ip=8.43.85.97; Authentication-Results: mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=fF7eRD7h; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gnu.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 2F66C384D183 for ; Fri, 14 Oct 2022 14:37:58 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 2F66C384D183 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1665758278; bh=EDqsHUrwZwXuhLtHaI9tVjtAFOBCyRhZgPYpQ3pUlWY=; h=To:Subject:Date:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:From; b=fF7eRD7hdHKzMbyw6crUpj5XBYk69oT0AgoHvL2EgfIgngl+7V4WE9E7Z3CB6ll8q 0lH39FgAkTN8cIp0eJGWbvrlwDvqryUJe7x5c/OMd19plzOuttwo6MyiUZoEg8THDy 4cZLeyxGxuG8WoDrsgNxsRxTg3ZyEKWj++/AuOpk= X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by sourceware.org (Postfix) with ESMTPS id 9574E384D16D for ; Fri, 14 Oct 2022 14:36:57 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 9574E384D16D Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-378-C2a0CG_bPLGIEESMJ9KP9A-1; Fri, 14 Oct 2022 10:36:56 -0400 X-MC-Unique: C2a0CG_bPLGIEESMJ9KP9A-1 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.rdu2.redhat.com [10.11.54.6]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id F3D0387B2A3; Fri, 14 Oct 2022 14:36:55 +0000 (UTC) Received: from localhost (unknown [10.33.36.64]) by smtp.corp.redhat.com (Postfix) with ESMTP id BCF982144B2D; Fri, 14 Oct 2022 14:36:55 +0000 (UTC) To: libstdc++@gcc.gnu.org, gcc-patches@gcc.gnu.org Subject: [committed] libstdc++: Disable all emergency EH pool code if obj-count == 0 Date: Fri, 14 Oct 2022 15:36:55 +0100 Message-Id: <20221014143655.2512929-1-jwakely@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.1 on 10.11.54.6 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com X-Spam-Status: No, score=-11.7 required=5.0 tests=BAYES_00, DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, KAM_NUMSUBJECT, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_NONE, TXREP autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: Jonathan Wakely via Gcc-patches From: Jonathan Wakely Reply-To: Jonathan Wakely Errors-To: gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org Sender: "Gcc-patches" X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1746674158539098329?= X-GMAIL-MSGID: =?utf-8?q?1746674158539098329?= Tested x86_64-linux. Pushed to trunk. -- >8 -- For a zero-sized static pool we can completely elide all code for the EH pool. We no longer need to adjust the static buffer size to ensure at least one free_entry can be created in it, because we no longer use a static buffer at all if obj_count == 0. If the buffer exists, obj_count >= 1 and the buffer will be much larger than sizeof(free_entry). libstdc++-v3/ChangeLog: * libsupc++/eh_alloc.cc [USE_POOL]: New macro. [!USE_POOL] (__gnu_cxx::__freeres, pool): Do not define. [_GLIBCXX_EH_POOL_STATIC] (pool::arena): Do not use std::max. (__cxxabiv1::__cxa_allocate_exception) [!USE_POOL]: Do not use pool. (__cxxabiv1::__cxa_free_exception) [!USE_POOL]: Likewise. (__cxxabiv1::__cxa_allocate_dependent_exception) [!USE_POOL]: Likewise. (__cxxabiv1::__cxa_free_dependent_exception) [!USE_POOL]: Likewise. --- libstdc++-v3/libsupc++/eh_alloc.cc | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/libstdc++-v3/libsupc++/eh_alloc.cc b/libstdc++-v3/libsupc++/eh_alloc.cc index 81b8a1548c6..e93f14c887b 100644 --- a/libstdc++-v3/libsupc++/eh_alloc.cc +++ b/libstdc++-v3/libsupc++/eh_alloc.cc @@ -101,12 +101,21 @@ using namespace __cxxabiv1; #ifdef _GLIBCXX_EH_POOL_NOBJS # if _GLIBCXX_EH_POOL_NOBJS > MAX_OBJ_COUNT # warning "_GLIBCXX_EH_POOL_NOBJS value is too large; ignoring it" +# elif _GLIBCXX_EH_POOL_NOBJS < 0 +# warning "_GLIBCXX_EH_POOL_NOBJS value is negative; ignoring it" # else # undef EMERGENCY_OBJ_COUNT # define EMERGENCY_OBJ_COUNT _GLIBCXX_EH_POOL_NOBJS # endif #endif +#if defined _GLIBCXX_EH_POOL_STATIC && EMERGENCY_OBJ_COUNT == 0 +# define USE_POOL 0 +#else +# define USE_POOL 1 +#endif + +#if USE_POOL namespace __gnu_cxx { void __freeres() noexcept; @@ -161,7 +170,7 @@ namespace #ifdef _GLIBCXX_EH_POOL_STATIC static constexpr std::size_t arena_size = buffer_size_in_bytes(EMERGENCY_OBJ_COUNT, EMERGENCY_OBJ_SIZE); - alignas(void*) char arena[std::max(arena_size, sizeof(free_entry))]; + alignas(void*) char arena[arena_size]; #else char *arena = nullptr; std::size_t arena_size = 0; @@ -374,6 +383,7 @@ namespace __gnu_cxx #endif } } +#endif // USE_POOL extern "C" void * __cxxabiv1::__cxa_allocate_exception(std::size_t thrown_size) noexcept @@ -382,8 +392,10 @@ __cxxabiv1::__cxa_allocate_exception(std::size_t thrown_size) noexcept void *ret = malloc (thrown_size); +#if USE_POOL if (!ret) ret = emergency_pool.allocate (thrown_size); +#endif if (!ret) std::terminate (); @@ -398,9 +410,11 @@ extern "C" void __cxxabiv1::__cxa_free_exception(void *vptr) noexcept { char *ptr = (char *) vptr - sizeof (__cxa_refcounted_exception); +#if USE_POOL if (emergency_pool.in_pool (ptr)) [[__unlikely__]] emergency_pool.free (ptr); else +#endif free (ptr); } @@ -410,8 +424,10 @@ __cxxabiv1::__cxa_allocate_dependent_exception() noexcept { void *ret = malloc (sizeof (__cxa_dependent_exception)); +#if USE_POOL if (!ret) ret = emergency_pool.allocate (sizeof (__cxa_dependent_exception)); +#endif if (!ret) std::terminate (); @@ -426,8 +442,10 @@ extern "C" void __cxxabiv1::__cxa_free_dependent_exception (__cxa_dependent_exception *vptr) noexcept { +#if USE_POOL if (emergency_pool.in_pool (vptr)) [[__unlikely__]] emergency_pool.free (vptr); else +#endif free (vptr); }