From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Helmut Eller Newsgroups: gmane.emacs.devel Subject: Re: MPS prstack Date: Fri, 24 May 2024 16:17:29 +0200 Message-ID: <874janpa4m.fsf@gmail.com> References: <87o790qsgm.fsf@gmail.com> <874jap95hi.fsf@gmail.com> Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="36311"; mail-complaints-to="usenet@ciao.gmane.io" User-Agent: Gnus/5.13 (Gnus v5.13) Cc: Eli Zaretskii , Emacs Devel To: Gerd =?utf-8?Q?M=C3=B6llmann?= Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane-mx.org@gnu.org Fri May 24 16:18:25 2024 Return-path: Envelope-to: ged-emacs-devel@m.gmane-mx.org Original-Received: from lists.gnu.org ([209.51.188.17]) by ciao.gmane.io with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1sAVkW-0009Gd-V3 for ged-emacs-devel@m.gmane-mx.org; Fri, 24 May 2024 16:18:25 +0200 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1sAVjn-0000cj-3E; Fri, 24 May 2024 10:17:39 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1sAVjl-0000ZI-Bx for emacs-devel@gnu.org; Fri, 24 May 2024 10:17:37 -0400 Original-Received: from mail-wr1-x430.google.com ([2a00:1450:4864:20::430]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1sAVjj-000083-Cm; Fri, 24 May 2024 10:17:37 -0400 Original-Received: by mail-wr1-x430.google.com with SMTP id ffacd0b85a97d-351da5838fcso7004945f8f.1; Fri, 24 May 2024 07:17:34 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1716560253; x=1717165053; darn=gnu.org; h=mime-version:user-agent:message-id:date:references:in-reply-to :subject:cc:to:from:from:to:cc:subject:date:message-id:reply-to; bh=TWsjdjbcgh6aLFfn70HFMxfR+SabFm10DBEOmrs9WDA=; b=hIRSqolj8EUEm7wB8jU4VR9uKpIc5vDTqhsiq9Gu1OFIS0LFG+HPrOCt7lIC9D2DPO QyjuMYIIpbKVpVd5RHq+S49XmNm69wHWCv2FQT3UnVzaLSe6ITN/hFdSmTroJ0GI3pYc f2qkyXXp1NU1wLANYzPfodbvEhckuwygiXMGhCJ11KrZkqXleUjlPSsWjIBN9a9C1JBk mAUBvzAZfz8NPTZ5wx5vT8zXBCt8fYpe1ywOlcX+Us0vMOzYLL3uT/LdHvVOAPs5JSAx FaVCdp81oM81K9vykJ3smyJoSgqE4BjsCDVv2Xvr9MLw4ULGvJ5CUtZKAQNRxhNcGCTN dikw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1716560253; x=1717165053; h=mime-version:user-agent:message-id:date:references:in-reply-to :subject:cc:to:from:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=TWsjdjbcgh6aLFfn70HFMxfR+SabFm10DBEOmrs9WDA=; b=HTY29ONMXbnvQet7CXfsr/vxQVthyXdoWwEb4uwMqqfOA3L5rPcXAKMYleUT6fPA6d sWmWLE217ITrc9sdzDtvrdfo5lf7BNK0fFzu/iaGBy+kTGqjqneBFPQDxlqxF2QuKjdi Ax9IlpAWfOIeIAk+FpW6fkT9ETp8b6rEOHxeMjTw0hfHC+98+dJzP/NSg+f2YDrWplqR 2daz5klDd9rFVv/C2IFHcUvORzfWuHUMcscTmdU96sRoxzDqW9ghOK0gjki34LAn4Wy9 FRukFJs4nbyPYTcQ5IEHX2lsULEGcJxmwIscuSlIYa3Op8yUqmq7ZaikehCLZpi1lzc2 sdHA== X-Forwarded-Encrypted: i=1; AJvYcCWvOQGmwS+19mHNHoa8SJ7uA2wV4G5nQdFklwoeFCNz9ljPQMkkwIZVJGVw2v/Aysu221KEpWtGmNslUEirD+ntrdJ/ X-Gm-Message-State: AOJu0YxhmoV3guvka6adKI9OPJhutXayGbwtMtKwkGZ3Glrhxtjxk9LP Au856AuWklpqTMiPuJgN227dCJMknIgmdXKwDn13UOcQcQ/HzF04GK/Tqg== X-Google-Smtp-Source: AGHT+IHNA7oTBpwnipNcA8sh3lYbWJKeoET+HbOecevNuliMXn/9SKXnX86WXCau+TsEglzdBgy6VQ== X-Received: by 2002:adf:fa0e:0:b0:352:5f74:6998 with SMTP id ffacd0b85a97d-355221811cemr1422635f8f.18.1716560252478; Fri, 24 May 2024 07:17:32 -0700 (PDT) Original-Received: from caladan (dial-188233.pool.broadband44.net. [212.46.188.233]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-3557a1c9303sm1709415f8f.88.2024.05.24.07.17.31 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 24 May 2024 07:17:31 -0700 (PDT) In-Reply-To: <874jap95hi.fsf@gmail.com> (Helmut Eller's message of "Wed, 22 May 2024 18:27:37 +0200") Received-SPF: pass client-ip=2a00:1450:4864:20::430; envelope-from=eller.helmut@gmail.com; helo=mail-wr1-x430.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_FROM=0.001, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: emacs-devel@gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: "Emacs development discussions." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-devel-bounces+ged-emacs-devel=m.gmane-mx.org@gnu.org Original-Sender: emacs-devel-bounces+ged-emacs-devel=m.gmane-mx.org@gnu.org Xref: news.gmane.io gmane.emacs.devel:319544 Archived-At: --=-=-= Content-Type: text/plain On Wed, May 22 2024, Helmut Eller wrote: > There is another one: ppstack. I wasn't able to create a small test > case for this but ppstack is needed when print-circle=t. The native > compiler uses that a lot. This needs some work. The patches below should help a bit. --=-=-= Content-Type: text/x-diff Content-Disposition: attachment; filename=0001-For-igc_xpalloc_exact-make-PA-an-in-out-parameter.patch >From 316e6894d6d432be763593b2e8ff816f413264dd Mon Sep 17 00:00:00 2001 From: Helmut Eller Date: Fri, 24 May 2024 15:49:23 +0200 Subject: [PATCH 1/2] For igc_xpalloc_exact, make PA an in-out parameter Because igc_xpalloc_exact uses mps_arena_release the scan_area callback may be called before igc_xpalloc_exact returns. With an in-out parameter, the client has the option to receive the new address before the igc_xpalloc_exact returns. * src/igc.h (igc_xpalloc_exact): Change the type of PA. * src/igc.c (igc_xpalloc_exact): Implement the new protocol. * src/print.c (grow_pp_stack, grow_print_stack): Update accordingly. --- src/igc.c | 11 ++++++----- src/igc.h | 6 +++--- src/print.c | 8 ++++---- 3 files changed, 13 insertions(+), 12 deletions(-) diff --git a/src/igc.c b/src/igc.c index dc4512713f7..4f22221e952 100644 --- a/src/igc.c +++ b/src/igc.c @@ -2416,13 +2416,14 @@ scan_xpalloced (mps_ss_t ss, void *start, void *end, void *closure) return scan_area ((struct igc_opaque *)ss, start, end, scan_cell); } -void * -igc_xpalloc_exact (void *pa, ptrdiff_t *nitems, ptrdiff_t nitems_incr_min, - ptrdiff_t nitems_max, ptrdiff_t item_size, - igc_scan_area_t scan_area) +void +igc_xpalloc_exact (void **pa_cell, ptrdiff_t *nitems, + ptrdiff_t nitems_incr_min, ptrdiff_t nitems_max, + ptrdiff_t item_size, igc_scan_area_t scan_area) { IGC_WITH_PARKED (global_igc) { + void *pa = *pa_cell; if (pa) { struct igc_root_list *r = root_find (pa); @@ -2433,8 +2434,8 @@ igc_xpalloc_exact (void *pa, ptrdiff_t *nitems, ptrdiff_t nitems_incr_min, char *end = (char *)pa + *nitems * item_size; root_create (global_igc, pa, end, mps_rank_exact (), scan_xpalloced, scan_area, false); + *pa_cell = pa; } - return pa; } void * diff --git a/src/igc.h b/src/igc.h index fb37ce22e22..5b97787916c 100644 --- a/src/igc.h +++ b/src/igc.h @@ -84,9 +84,9 @@ #define EMACS_IGC_H typedef igc_scan_result_t (*igc_scan_area_t) (struct igc_opaque *, void *start, void *end, igc_scan_cell_t fun); -void *igc_xpalloc_exact (void *pa, ptrdiff_t *nitems, - ptrdiff_t nitems_incr_min, ptrdiff_t nitems_max, - ptrdiff_t item_size, igc_scan_area_t scan); +void igc_xpalloc_exact (void **pa_cell, ptrdiff_t *nitems, + ptrdiff_t nitems_incr_min, ptrdiff_t nitems_max, + ptrdiff_t item_size, igc_scan_area_t scan); void *igc_xnrealloc_ambig (void *pa, ptrdiff_t nitems, ptrdiff_t item_size); diff --git a/src/print.c b/src/print.c index c87597be899..5aec73c15e3 100644 --- a/src/print.c +++ b/src/print.c @@ -1359,8 +1359,8 @@ grow_pp_stack (void) struct print_pp_stack *ps = &ppstack; eassert (ps->sp == ps->size); #ifdef HAVE_MPS - ps->stack = igc_xpalloc_exact (ps->stack, &ps->size, 1, -1, - sizeof *ps->stack, scan_ppstack); + igc_xpalloc_exact ((void **)&ppstack.stack, &ps->size, 1, -1, + sizeof *ps->stack, scan_ppstack); #else ps->stack = xpalloc (ps->stack, &ps->size, 1, -1, sizeof *ps->stack); #endif @@ -2273,8 +2273,8 @@ grow_print_stack (void) struct print_stack *ps = &prstack; eassert (ps->sp == ps->size); #ifdef HAVE_MPS - ps->stack = igc_xpalloc_exact (ps->stack, &ps->size, 1, -1, - sizeof *ps->stack, scan_prstack); + igc_xpalloc_exact ((void **)&prstack.stack, &ps->size, 1, -1, + sizeof *ps->stack, scan_prstack); #else ps->stack = xpalloc (ps->stack, &ps->size, 1, -1, sizeof *ps->stack); #endif -- 2.39.2 --=-=-= Content-Type: text/x-diff Content-Disposition: attachment; filename=0002-Safer-use-of-ppstack.patch >From dd2033d482a29dff2275daf082148ffc2bea16fd Mon Sep 17 00:00:00 2001 From: Helmut Eller Date: Fri, 24 May 2024 16:00:12 +0200 Subject: [PATCH 2/2] Safer use of ppstack In print_pp_entry, the u.values fields holds a pointer into the interior of a vectorlike object. This doesn't work for a moving GC. It's safer to keep the original object and access it with AREF. * print.c (print_pp_entry): Add a vectorlike variant to the union. (scan_ppstack, pp_stack_push_values, print_preprocess): Update accordingly. --- src/print.c | 34 ++++++++++++++++++++++++++++++---- 1 file changed, 30 insertions(+), 4 deletions(-) diff --git a/src/print.c b/src/print.c index 5aec73c15e3..cc86e1e9710 100644 --- a/src/print.c +++ b/src/print.c @@ -1314,7 +1314,11 @@ #define PRINT_CIRCLE_CANDIDATE_P(obj) \ ptrdiff_t n; /* number of values, or 0 if a single value */ union { Lisp_Object value; /* when n = 0 */ +#ifdef HAVE_MPS + Lisp_Object vectorlike; /* when n > 0 */ +#else Lisp_Object *values; /* when n > 0 */ +#endif } u; }; @@ -1345,9 +1349,8 @@ scan_ppstack (struct igc_opaque *op, void *start, void *end, else { eassert (p->n > 0); - for (size_t i = 0; i < p->n; i++) - if (err = scan1 (op, &p->u.values[i]), err != 0) - return err; + if (err = scan1 (op, &p->u.vectorlike), err != 0) + return err; } } return 0; @@ -1376,6 +1379,20 @@ pp_stack_push_value (Lisp_Object value) .u.value = value}; } +#ifdef HAVE_MPS +static inline void +pp_stack_push_values (Lisp_Object vectorlike, ptrdiff_t n) +{ + eassert (VECTORLIKEP (vectorlike)); + eassume (n >= 0); + if (n == 0) + return; + if (ppstack.sp >= ppstack.size) + grow_pp_stack (); + ppstack.stack[ppstack.sp++] + = (struct print_pp_entry){ .n = n, .u.vectorlike = vectorlike }; +} +#else static inline void pp_stack_push_values (Lisp_Object *values, ptrdiff_t n) { @@ -1387,6 +1404,7 @@ pp_stack_push_values (Lisp_Object *values, ptrdiff_t n) ppstack.stack[ppstack.sp++] = (struct print_pp_entry){.n = n, .u.values = values}; } +#endif static inline bool pp_stack_empty_p (void) @@ -1409,7 +1427,11 @@ pp_stack_pop (void) e->n--; if (e->n == 0) --ppstack.sp; /* last value consumed */ +#ifdef HAVE_MPS + return AREF (e->u.vectorlike, e->n); +#else return (++e->u.values)[-1]; +#endif } /* Construct Vprint_number_table for the print-circle feature @@ -1475,13 +1497,17 @@ print_preprocess (Lisp_Object obj) case Lisp_Vectorlike: { - struct Lisp_Vector *vec = XVECTOR (obj); ptrdiff_t size = ASIZE (obj); if (size & PSEUDOVECTOR_FLAG) size &= PSEUDOVECTOR_SIZE_MASK; ptrdiff_t start = (SUB_CHAR_TABLE_P (obj) ? SUB_CHAR_TABLE_OFFSET : 0); +#ifdef HAVE_MPS + pp_stack_push_values (obj, size - start); +#else + struct Lisp_Vector *vec = XVECTOR (obj); pp_stack_push_values (vec->contents + start, size - start); +#endif if (HASH_TABLE_P (obj)) { struct Lisp_Hash_Table *h = XHASH_TABLE (obj); -- 2.39.2 --=-=-=--