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: MPS prstack Date: Mon, 20 May 2024 19:54:49 +0200 Message-ID: <87o790qsgm.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="4723"; 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 Mon May 20 19:55:30 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 1s97EP-000109-NU for ged-emacs-devel@m.gmane-mx.org; Mon, 20 May 2024 19:55:29 +0200 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1s97Dt-0007KX-RL; Mon, 20 May 2024 13:54:57 -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 1s97Dr-0007Eo-R3 for emacs-devel@gnu.org; Mon, 20 May 2024 13:54:56 -0400 Original-Received: from mail-ej1-x629.google.com ([2a00:1450:4864:20::629]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1s97Dp-0004iF-QU; Mon, 20 May 2024 13:54:55 -0400 Original-Received: by mail-ej1-x629.google.com with SMTP id a640c23a62f3a-a5a89787ea4so702620466b.2; Mon, 20 May 2024 10:54:53 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1716227692; x=1716832492; darn=gnu.org; h=mime-version:user-agent:message-id:date:subject:cc:to:from:from:to :cc:subject:date:message-id:reply-to; bh=aIPGpxNeJYJbTV6srOfUQeDcJZYUN8ZIEgn3uPejWxI=; b=N5fYwbXEU9UzWbTBPWby5IT3KHyi4lx07zBkdt9bZLEF/nyWxRw5B+/SnArfKjDbcm jw5AIglsPON0JXCKCQylj3DqvKdlrHThdpdY2lVTj9zY+jidEg7xvo2MbhydYaqzxknC C9q+0ZvgGoaU5IrbtyR4CDW+ofUFFCD8as2w51bhfAs5FH20u1rCGifzhysqOTnY44Q2 gOU3ECHXnzOYRU5JA/TUyzLREnDkJcTJgknJx/NnVnrhJANzV3HHdkTqRZP50+6pGX3Z kh6owUYPytCq+mKsOE9aXYYHmpEh4w8IwLQlIVuWyz58ZWFK+F2bqNH3CqzFNSxETtgZ sPOQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1716227692; x=1716832492; h=mime-version:user-agent:message-id:date:subject:cc:to:from :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=aIPGpxNeJYJbTV6srOfUQeDcJZYUN8ZIEgn3uPejWxI=; b=dQPfWOEhBRH9FCU68VH/0abx9Tta156Kx1HniMpHy60iXnKayZEa9C9rESgYXkbZNq Skqr613wpToy0ypF956usWudHOJ2jMoX79NyikQDYgX4lkk82cJcdh89Zjd5PNVHwixT Jet3jeqLi0kz2wbGSPXALm2OSYKu37jWY7jooOdu7+15+ThF1STho2htJ0JfREHH8bG3 HgkNer7yoJObaIHz7yMTxJtRMBQkZjWs33Iax1aTglwBM7xrVkyOEV2AposxOb5FJf4u QNsY+981+fzqspimgKi62N8htDpsm8I5o7pu1MzDMgKRmwBqygzVkMCfR+yL+d0+WkB9 aNGQ== X-Forwarded-Encrypted: i=1; AJvYcCUjGd+8VzbcC1ceRQZlyy2k5o3rO2ITgnCMu/e+6R93UC8i8hxM2CWSRz3BvGOUxGaHHjhtnGbg/fo1/gcXbsBJIOwn X-Gm-Message-State: AOJu0YymMI5OEwADxSxmD03u8mLnPEMfHgZabFGlIOmF5kNSVAjVGdk3 W0mVKvOvrL0nuL88CCHcvUQ3NodXgJwBbGjmWhhHHDoWs4yt6ys3W8QB7A== X-Google-Smtp-Source: AGHT+IFnG9MDzYQnsjGa3UXIia1J88lpMuqbHexXn5uQnjKK2hcKNUEzvg9geeD6faB/1mH2QyOB+Q== X-Received: by 2002:a17:906:da8b:b0:a59:bdb7:73f8 with SMTP id a640c23a62f3a-a5a2d66a3b4mr2611685666b.47.1716227691339; Mon, 20 May 2024 10:54:51 -0700 (PDT) Original-Received: from caladan (dial-188233.pool.broadband44.net. [212.46.188.233]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-a5a17b17d02sm1489566566b.218.2024.05.20.10.54.50 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 20 May 2024 10:54:50 -0700 (PDT) Received-SPF: pass client-ip=2a00:1450:4864:20::629; envelope-from=eller.helmut@gmail.com; helo=mail-ej1-x629.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:319429 Archived-At: --=-=-= Content-Type: text/plain In print.c, there is a global variable prstack that is not yet scanned. This causes a crash for comp-tests but this example triggers the same problem: (progn (defun make-tree (i) (cond ((= i 0) nil) (t (list (make-string 10000 i) (make-tree (1- i)) (make-tree (1- i)))))) (prin1-to-string (make-tree 13))) We could create an ambiguous root for this but I thought it would be an interesting exercise to scan it exactly. It's interesting because this is a static variable and the type is only declared in print.c. So I added a new function igc_xpalloc_exact to igc.h. That uses a callback that calls another callback. I'm not sure if this allowed by the MPS rules but it seems to work or at least doesn't seem to crash. WDYT? --=-=-= Content-Type: text/x-diff Content-Disposition: attachment; filename=0001-Add-a-igc_xpalloc_exact-function.patch >From 925a4b0daeef769e6048b068a7c35674000797db Mon Sep 17 00:00:00 2001 From: Helmut Eller Date: Mon, 20 May 2024 17:44:34 +0200 Subject: [PATCH 1/2] Add a igc_xpalloc_exact function * src/igc.h (igc_xpalloc_exact): New. (igc_scan_result_t, igc_opaque, igc_scan_cell_t, igc_scan_area_t): New auxilarry types. * src/igc.c (igc_xpalloc_exact): Implement it. (scan_xpalloced, scan_cell_callback): New helpers. (root_create): Allow a closure argument. (root_create_ambig, root_create_exact, root_create_igc) (root_create_pure): Set the closure argument to NULL. --- src/igc.c | 58 ++++++++++++++++++++++++++++++++++++++++++++++++------- src/igc.h | 18 +++++++++++++++-- 2 files changed, 67 insertions(+), 9 deletions(-) diff --git a/src/igc.c b/src/igc.c index 5e0e2e8fdd2..e2e9af97f94 100644 --- a/src/igc.c +++ b/src/igc.c @@ -2001,15 +2001,28 @@ fix_vector (mps_ss_t ss, struct Lisp_Vector *v) return MPS_RES_OK; } +static igc_scan_result_t +scan_cell_callback (struct igc_opaque *op, Lisp_Object *addr) +{ + mps_ss_t ss = (mps_ss_t)op; + MPS_SCAN_BEGIN (ss) + { + IGC_FIX12_OBJ (ss, addr); + } + MPS_SCAN_END (ss); + return MPS_RES_OK; +} + #pragma GCC diagnostic pop static igc_root_list * root_create (struct igc *gc, void *start, void *end, mps_rank_t rank, - mps_area_scan_t scan, bool ambig) + mps_area_scan_t scan, void *closure, bool ambig) { mps_root_t root; mps_res_t res - = mps_root_create_area (&root, gc->arena, rank, 0, start, end, scan, 0); + = mps_root_create_area (&root, gc->arena, rank, 0, start, end, scan, + closure); IGC_CHECK_RES (res); return register_root (gc, root, start, end, ambig); } @@ -2017,13 +2030,15 @@ root_create (struct igc *gc, void *start, void *end, mps_rank_t rank, static igc_root_list * root_create_ambig (struct igc *gc, void *start, void *end) { - return root_create (gc, start, end, mps_rank_ambig (), scan_ambig, true); + return root_create (gc, start, end, mps_rank_ambig (), scan_ambig, NULL, + true); } static igc_root_list * -root_create_exact (struct igc *gc, void *start, void *end, mps_area_scan_t scan) +root_create_exact (struct igc *gc, void *start, void *end, + mps_area_scan_t scan) { - return root_create (gc, start, end, mps_rank_exact (), scan, false); + return root_create (gc, start, end, mps_rank_exact (), scan, NULL, false); } static void @@ -2115,7 +2130,7 @@ root_create_bc (struct igc_thread_list *t) static void root_create_igc (struct igc *gc) { - root_create (gc, gc, gc + 1, mps_rank_exact (), scan_igc, false); + root_create (gc, gc, gc + 1, mps_rank_exact (), scan_igc, NULL, false); } #ifndef IN_MY_FORK @@ -2124,7 +2139,7 @@ root_create_pure (struct igc *gc) { void *start = &pure[0]; void *end = &pure[PURESIZE]; - root_create (gc, start, end, mps_rank_ambig (), scan_pure, true); + root_create (gc, start, end, mps_rank_ambig (), scan_pure, NULL, true); } #endif @@ -2355,6 +2370,35 @@ igc_xpalloc_ambig (void *pa, ptrdiff_t *nitems, ptrdiff_t nitems_incr_min, return pa; } +static mps_res_t +scan_xpalloced (mps_ss_t ss, void *start, void *end, void *closure) +{ + igc_scan_area_t scan_area = closure; + igc_scan_cell_t scan_cell = (igc_scan_cell_t)scan_cell_callback; + 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) +{ + IGC_WITH_PARKED (global_igc) + { + if (pa) + { + struct igc_root_list *r = root_find (pa); + igc_assert (r != NULL); + destroy_root (&r); + } + pa = xpalloc (pa, nitems, nitems_incr_min, nitems_max, item_size); + char *end = (char *)pa + *nitems * item_size; + root_create (global_igc, pa, end, mps_rank_exact (), + scan_xpalloced, scan_area, false); + } + return pa; +} + void * igc_xnrealloc_ambig (void *pa, ptrdiff_t nitems, ptrdiff_t item_size) { diff --git a/src/igc.h b/src/igc.h index 2fe134bc2d7..384d5acdf1b 100644 --- a/src/igc.h +++ b/src/igc.h @@ -72,8 +72,22 @@ #define EMACS_IGC_H void *igc_realloc_ambig (void *block, size_t size); void igc_xfree (void *p); Lisp_Object *igc_xalloc_lisp_objs_exact (size_t n); -void *igc_xpalloc_ambig (void *pa, ptrdiff_t *nitems, ptrdiff_t nitems_incr_min, - ptrdiff_t nitems_max, ptrdiff_t item_size); + +void *igc_xpalloc_ambig (void *pa, ptrdiff_t *nitems, + ptrdiff_t nitems_incr_min, ptrdiff_t nitems_max, + ptrdiff_t item_size); + +typedef uintptr_t igc_scan_result_t; /* zero means success */ +struct igc_opaque; +typedef igc_scan_result_t (*igc_scan_cell_t) (struct igc_opaque *, + Lisp_Object *addr); +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_xnrealloc_ambig (void *pa, ptrdiff_t nitems, ptrdiff_t item_size); struct Lisp_Vector *igc_alloc_pseudovector (size_t nwords_mem, -- 2.39.2 --=-=-= Content-Type: text/x-diff Content-Disposition: attachment; filename=0002-Allocate-prstack-as-exact-root.patch >From 928270d0f7ad2200fb3b5a6f126fd43c7740bbe3 Mon Sep 17 00:00:00 2001 From: Helmut Eller Date: Mon, 20 May 2024 17:49:29 +0200 Subject: [PATCH 2/2] Allocate prstack as exact root * src/print.c (grow_print_stack): Use igc_xpalloc_exact. (scan_prstack): New. --- src/print.c | 40 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) diff --git a/src/print.c b/src/print.c index 440c1c0e575..f043da92c1f 100644 --- a/src/print.c +++ b/src/print.c @@ -2200,12 +2200,52 @@ named_escape (int i) static struct print_stack prstack = {NULL, 0, 0}; +static igc_scan_result_t +scan_prstack (struct igc_opaque *op, void *start, void *end, + igc_scan_cell_t scan1) +{ + eassert (start == (void *)prstack.stack); + eassert (end == (void *)(prstack.stack + prstack.size)); + struct print_stack_entry *p = start; + struct print_stack_entry *q = p + prstack.sp; + for (; p < q; p++) + { + igc_scan_result_t err = 0; + switch (p->type) + { + case PE_list: + if (err = scan1 (op, &p->u.list.last), err != 0) + return err; + if (err = scan1 (op, &p->u.list.tortoise), err != 0) + return err; + continue; + case PE_rbrac: + continue; + case PE_vector: + if (err = scan1 (op, &p->u.vector.obj), err != 0) + return err; + continue; + case PE_hash: + if (err = scan1 (op, &p->u.hash.obj), err != 0) + return err; + continue; + } + eassert (!"not yet implemented"); + } + return 0; +} + NO_INLINE static void 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); +#else ps->stack = xpalloc (ps->stack, &ps->size, 1, -1, sizeof *ps->stack); +#endif eassert (ps->sp < ps->size); } -- 2.39.2 --=-=-=--