From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Jonas Hahnfeld via "Developers list for Guile, the GNU extensibility library" Newsgroups: gmane.lisp.guile.devel Subject: Re: GC + Java finalization Date: Fri, 19 Nov 2021 14:32:15 +0100 Message-ID: References: <9ce77d5e08d50456eddc575179b68ac17afc9bf6.camel@hahnjo.de> <1cc3648e5196bf23023ec7a0ab95a9ad46f8554c.camel@telenet.be> Reply-To: Jonas Hahnfeld Mime-Version: 1.0 Content-Type: multipart/signed; micalg="pgp-sha256"; protocol="application/pgp-signature"; boundary="=-UHsJfI/pEydevsWMLiqC" Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="21466"; mail-complaints-to="usenet@ciao.gmane.io" User-Agent: Evolution 3.42.1 To: Maxime Devos , guile-devel@gnu.org Original-X-From: guile-devel-bounces+guile-devel=m.gmane-mx.org@gnu.org Fri Nov 19 14:33:03 2021 Return-path: Envelope-to: guile-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 1mo40l-0005NV-7s for guile-devel@m.gmane-mx.org; Fri, 19 Nov 2021 14:33:03 +0100 Original-Received: from localhost ([::1]:56490 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1mo40k-0003oW-8R for guile-devel@m.gmane-mx.org; Fri, 19 Nov 2021 08:33:02 -0500 Original-Received: from eggs.gnu.org ([209.51.188.92]:55402) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mo40A-0003mf-03 for guile-devel@gnu.org; Fri, 19 Nov 2021 08:32:26 -0500 Original-Received: from [2a03:4000:2a:2c1::1] (port=50700 helo=mail.hahnjo.de) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mo407-0008Gr-OX for guile-devel@gnu.org; Fri, 19 Nov 2021 08:32:25 -0500 Original-Received: from [IPv6:2001:16b8:1e92:200:6657:51b0:48f8:9366] (unknown [IPv6:2001:16b8:1e92:200:6657:51b0:48f8:9366]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange ECDHE (P-256) server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mail.hahnjo.de (Postfix) with ESMTPSA id 924DD542889B; Fri, 19 Nov 2021 14:32:20 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=hahnjo.de; s=default; t=1637328740; bh=FYI749aGLByiqDKSCerCoZcB59ffha7Ec15tfo8F72g=; h=Subject:From:To:Date:In-Reply-To:References; b=F+4M82j0hklPKrbgevc5mnLILT0J6YKE/r0L0oCCrlbi5mKUQ32b99oqsU65rdpfP XQGj670y4n+nhgKi/Yz38sK8Rpf4bb+5kJroDKExMhltClxkm3g+EP8Enm+yk/Qhaf /+R6IQwMWlSCtFamYeHSkCMqBJ57jfQ9xXwGfTjyuJ49u4s8hxP+S6yT4wPr368+5m RE37CicxPatlXezPq/H+nHIz5XpfTCivg+bRxfHwRQCgxz77/E8buze248feC/1d9l ABl7IOlJKZDyjHFLe3M/R5YPOXsUK38glvixsnk39i48NG0cigtKrTp1qtQYB7lqhd 5fMRnxWrKyUBQ== In-Reply-To: <1cc3648e5196bf23023ec7a0ab95a9ad46f8554c.camel@telenet.be> X-Host-Lookup-Failed: Reverse DNS lookup failed for 2a03:4000:2a:2c1::1 (failed) Received-SPF: pass client-ip=2a03:4000:2a:2c1::1; envelope-from=hahnjo@hahnjo.de; helo=mail.hahnjo.de X-Spam_score_int: -12 X-Spam_score: -1.3 X-Spam_bar: - X-Spam_report: (-1.3 / 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, RDNS_NONE=0.793, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=no autolearn_force=no X-Spam_action: no action X-BeenThere: guile-devel@gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: "Developers list for Guile, the GNU extensibility library" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: guile-devel-bounces+guile-devel=m.gmane-mx.org@gnu.org Original-Sender: "guile-devel" Xref: news.gmane.io gmane.lisp.guile.devel:20959 Archived-At: --=-UHsJfI/pEydevsWMLiqC Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable Am Freitag, dem 19.11.2021 um 13:13 +0000 schrieb Maxime Devos: > Jonas Hahnfeld schreef op do 15-07-2021 om 20:44 [+0200]: > > From 33af6a98c6801e7b4880d1d3f78f7e2097c2174e Mon Sep 17 00:00:00 > > 2001 > > From: Jonas Hahnfeld > > Date: Fri, 2 Jul 2021 23:03:17 +0200 > > Subject: [PATCH 2/3] Avoid matching calls of scm_gc_free > >=20 > > There is no point in registering memory with the garbage collector > > if it doesn't need to do its job. In fact, calling scm_gc_free in > > a free function is wrong because it relies on Java finalization. > >=20 > > * libguile/random.c (scm_c_random_bignum): Replace matching calls of > > =C2=A0 scm_gc_calloc and scm_gc_free. > > * libguile/regex-posix.c (scm_make_regexp, regex_free): Avoid call > > =C2=A0 of scm_gc_free in free function. > > * test-suite/standalone/test-smob-mark.c (make_x, free_x): Avoid > > =C2=A0 call of scm_gc_free in free function. > > --- > > =C2=A0THANKS=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2= =A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0= =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 | 1 + > > =C2=A0libguile/random.c=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0= =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2= =A0 | 8 ++------ > > =C2=A0libguile/regex-posix.c=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0= =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 | 6 +++--- > > =C2=A0test-suite/standalone/test-smob-mark.c | 4 ++-- > > =C2=A04 files changed, 8 insertions(+), 11 deletions(-) > >=20 > > diff --git a/THANKS b/THANKS > > index aa4877e95..786b65d1a 100644 > > --- a/THANKS > > +++ b/THANKS > > @@ -13,6 +13,7 @@ Contributors since the last release: > > =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 Volker Grabsch > > =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 Julian Graham > > =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 Michael Gran > > +=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 Jonas Hahnfeld > > =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 Daniel Hartwig > > =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2= =A0=C2=A0 No Itisnt > > =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 Neil= Jerram > > diff --git a/libguile/random.c b/libguile/random.c > > index 63da7f5d6..ac400a9fd 100644 > > --- a/libguile/random.c > > +++ b/libguile/random.c > > @@ -324,9 +324,7 @@ scm_c_random_bignum (scm_t_rstate *state, SCM m) > > =C2=A0=C2=A0 /* we know the result will be this big */ > > =C2=A0=C2=A0 mpz_realloc2 (SCM_I_BIG_MPZ (result), m_bits); > > =C2=A0 > > -=C2=A0 random_chunks =3D > > -=C2=A0=C2=A0=C2=A0 (uint32_t *) scm_gc_calloc (num_chunks * sizeof (ui= nt32_t), > > -=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2= =A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0= =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 "r= andom bignum chunks"); > > +=C2=A0 random_chunks =3D (uint32_t *) scm_calloc (num_chunks * sizeof > > (uint32_t)); > > =C2=A0 > > =C2=A0=C2=A0 do > > =C2=A0=C2=A0=C2=A0=C2=A0 { > > @@ -363,9 +361,7 @@ scm_c_random_bignum (scm_t_rstate *state, SCM m) > > =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 /* if result >=3D m, regenerate it= (it is important to > > regenerate > > =C2=A0 all bits in order not to get a distorted distribution) */ > > =C2=A0=C2=A0=C2=A0=C2=A0 } while (mpz_cmp (SCM_I_BIG_MPZ (result), SCM_= I_BIG_MPZ (m)) >=3D > > 0); > > -=C2=A0 scm_gc_free (random_chunks, > > -=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2= =A0=C2=A0=C2=A0 num_chunks * sizeof (uint32_t), > > -=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2= =A0=C2=A0=C2=A0 "random bignum chunks"); > > +=C2=A0 free (random_chunks); >=20 > From the manual (about scm_gc_calloc & friends): >=20 > =E2=80=98Memory blocks allocated this way may > be released explicitly; however, this is not strictly needed, and we > recommend _not_ calling =E2=80=98scm_gc_free=E2=80=99. All memory alloca= ted with > =E2=80=98scm_gc_malloc=E2=80=99 or =E2=80=98scm_gc_malloc_pointerless=E2= =80=99 is automatically > reclaimed when the garbage collector no longer sees any live reference > to it(1).=E2=80=99 >=20 > As such, I'd recommend simply dropping the scm_gc_free > (here and in other places), if the scm_gc_free was problematic > because of Java finalization reasons. We could, but what is the point of registering memory to the garbage collector where we know it won't survive the function? >=20 >=20 > > =C2=A0=C2=A0 return scm_i_normbig (result); > > =C2=A0} > > =C2=A0 > > diff --git a/libguile/regex-posix.c b/libguile/regex-posix.c > > index a08da02db..36bb639e0 100644 > > --- a/libguile/regex-posix.c > > +++ b/libguile/regex-posix.c > > @@ -67,7 +67,7 @@ static size_t > > =C2=A0regex_free (SCM obj) > > =C2=A0{ > > =C2=A0=C2=A0 regfree (SCM_RGX (obj)); > > -=C2=A0 scm_gc_free (SCM_RGX (obj), sizeof(regex_t), "regex"); > > +=C2=A0 free (SCM_RGX (obj)); > > =C2=A0=C2=A0 return 0; > > =C2=A0} > > =C2=A0 > > @@ -164,7 +164,7 @@ SCM_DEFINE (scm_make_regexp, "make-regexp", 1, 0, > > 1, > > =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 flag =3D SCM_CDR (flag); > > =C2=A0=C2=A0=C2=A0=C2=A0 } > > =C2=A0 > > -=C2=A0 rx =3D scm_gc_malloc_pointerless (sizeof (regex_t), "regex"); > > +=C2=A0 rx =3D scm_malloc (sizeof (regex_t)); >=20 > If the regex why scm_gc_malloc_pointerless -> scm_malloc? > Is rx not pointerless? Not sure I understand the question. We don't know what contents libc will write into regex_t. It could be pointers which would be bad for the garbage collector. > You coud simply ... >=20 >=20 > > -=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 scm_gc_free (rx, sizeof(regex_t), "rege= x"); > > +=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 free (rx); >=20 > drop the scm_gc_free AFAIK. No, I cannot as explained in the patch summary: If we use scm_gc_free in a free function of a Smob, this relies on Java finalization because the memory must not be reclaimed in the same cycle. Jonas --=-UHsJfI/pEydevsWMLiqC Content-Type: application/pgp-signature; name="signature.asc" Content-Description: This is a digitally signed message part Content-Transfer-Encoding: 7bit -----BEGIN PGP SIGNATURE----- iQEzBAABCAAdFiEEXw/5YGpL6H9VOgO2kcnDPSxhrNsFAmGXp18ACgkQkcnDPSxh rNuG+Af/WBaJn+T+67QNCyPK3g6CIHnlN7/wIzanSk0EP76kDup0HJWcxS2bFgPd rJJRmT0gUz4D+ny7wZg1Kr9gJL+yvSMsqMW+MFgHQkPFDY2jpEVfgUCcZbQl6PQo CF/knftjjOmEKo0p1bmbmPNbxK11JHKXnc446+haEHHr5QgdT0WHtGAA7ZC6wg4B yKN6ZlTaYc88g8GkWid1yhPoxdIuNGIRO4PJJ4pmbRD2B2Rs6alUaOS533OztRR0 CK4LCPI7thLnKSKTXYLxc8qp0JGJ8EdK74nlNJEGeM4CQi32Aj9VDx4srFHULtt8 Mv8XNN+Ilo0ssKCQG3pVgdpXVfZPgg== =SIdA -----END PGP SIGNATURE----- --=-UHsJfI/pEydevsWMLiqC--