Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/external/mit/lua/dist/src lua: apply upstream bugfix for "GC...



details:   https://anonhg.NetBSD.org/src/rev/789f2fbe8dbe
branches:  trunk
changeset: 374300:789f2fbe8dbe
user:      nikita <nikita%NetBSD.org@localhost>
date:      Mon Apr 17 20:17:58 2023 +0000

description:
lua: apply upstream bugfix for "GC not setting a proper target for next cycle after a full collection in generational mode."

diffstat:

 external/mit/lua/dist/src/lgc.c |  65 ++++++++++++++++++++--------------------
 1 files changed, 32 insertions(+), 33 deletions(-)

diffs (114 lines):

diff -r be88500dc9c7 -r 789f2fbe8dbe external/mit/lua/dist/src/lgc.c
--- a/external/mit/lua/dist/src/lgc.c   Mon Apr 17 20:07:32 2023 +0000
+++ b/external/mit/lua/dist/src/lgc.c   Mon Apr 17 20:17:58 2023 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: lgc.c,v 1.11 2023/04/16 20:46:17 nikita Exp $  */
+/*     $NetBSD: lgc.c,v 1.12 2023/04/17 20:17:58 nikita Exp $  */
 
 /*
 ** Id: lgc.c 
@@ -1044,7 +1044,25 @@ void luaC_checkfinalizer (lua_State *L, 
 ** =======================================================
 */
 
-static void setpause (global_State *g);
+
+/*
+** Set the "time" to wait before starting a new GC cycle; cycle will
+** start when memory use hits the threshold of ('estimate' * pause /
+** PAUSEADJ). (Division by 'estimate' should be OK: it cannot be zero,
+** because Lua cannot even start with less than PAUSEADJ bytes).
+*/
+static void setpause (global_State *g) {
+  l_mem threshold, debt;
+  int pause = getgcparam(g->gcpause);
+  l_mem estimate = g->GCestimate / PAUSEADJ;  /* adjust 'estimate' */
+  lua_assert(estimate > 0);
+  threshold = (pause < MAX_LMEM / estimate)  /* overflow? */
+            ? estimate * pause  /* no overflow */
+            : MAX_LMEM;  /* overflow; truncate to maximum */
+  debt = gettotalbytes(g) - threshold;
+  if (debt > 0) debt = 0;
+  luaE_setdebt(g, debt);
+}
 
 
 /*
@@ -1289,6 +1307,15 @@ static void atomic2gen (lua_State *L, gl
 
 
 /*
+** Set debt for the next minor collection, which will happen when
+** memory grows 'genminormul'%.
+*/
+static void setminordebt (global_State *g) {
+  luaE_setdebt(g, -(cast(l_mem, (gettotalbytes(g) / 100)) * g->genminormul));
+}
+
+
+/*
 ** Enter generational mode. Must go until the end of an atomic cycle
 ** to ensure that all objects are correctly marked and weak tables
 ** are cleared. Then, turn all objects into old and finishes the
@@ -1300,6 +1327,7 @@ static lu_mem entergen (lua_State *L, gl
   luaC_runtilstate(L, bitmask(GCSpropagate));  /* start new cycle */
   numobjs = atomic(L);  /* propagates all and then do the atomic stuff */
   atomic2gen(L, g);
+  setminordebt(g);  /* set debt assuming next cycle will be minor */
   return numobjs;
 }
 
@@ -1346,15 +1374,6 @@ static lu_mem fullgen (lua_State *L, glo
 
 
 /*
-** Set debt for the next minor collection, which will happen when
-** memory grows 'genminormul'%.
-*/
-static void setminordebt (global_State *g) {
-  luaE_setdebt(g, -(cast(l_mem, (gettotalbytes(g) / 100)) * g->genminormul));
-}
-
-
-/*
 ** Does a major collection after last collection was a "bad collection".
 **
 ** When the program is building a big structure, it allocates lots of
@@ -1425,8 +1444,8 @@ static void genstep (lua_State *L, globa
       lu_mem numobjs = fullgen(L, g);  /* do a major collection */
       if (gettotalbytes(g) < majorbase + (majorinc / 2)) {
         /* collected at least half of memory growth since last major
-           collection; keep doing minor collections */
-        setminordebt(g);
+           collection; keep doing minor collections. */
+        lua_assert(g->lastatomic == 0);
       }
       else {  /* bad collection */
         g->lastatomic = numobjs;  /* signal that last collection was bad */
@@ -1453,26 +1472,6 @@ static void genstep (lua_State *L, globa
 
 
 /*
-** Set the "time" to wait before starting a new GC cycle; cycle will
-** start when memory use hits the threshold of ('estimate' * pause /
-** PAUSEADJ). (Division by 'estimate' should be OK: it cannot be zero,
-** because Lua cannot even start with less than PAUSEADJ bytes).
-*/
-static void setpause (global_State *g) {
-  l_mem threshold, debt;
-  int pause = getgcparam(g->gcpause);
-  l_mem estimate = g->GCestimate / PAUSEADJ;  /* adjust 'estimate' */
-  lua_assert(estimate > 0);
-  threshold = (pause < MAX_LMEM / estimate)  /* overflow? */
-            ? estimate * pause  /* no overflow */
-            : MAX_LMEM;  /* overflow; truncate to maximum */
-  debt = gettotalbytes(g) - threshold;
-  if (debt > 0) debt = 0;
-  luaE_setdebt(g, debt);
-}
-
-
-/*
 ** Enter first sweep phase.
 ** The call to 'sweeptolive' makes the pointer point to an object
 ** inside the list (instead of to the header), so that the real sweep do



Home | Main Index | Thread Index | Old Index