From 5c87f61e6b1567400d2bd8f452939bb948f16dda Mon Sep 17 00:00:00 2001 From: Roberto Ierusalimschy Date: Thu, 25 Mar 2010 16:37:23 -0300 Subject: major collections in generational mode --- lapi.c | 24 +++++++++++++++--------- 1 file changed, 15 insertions(+), 9 deletions(-) (limited to 'lapi.c') diff --git a/lapi.c b/lapi.c index 59dcb612..3a0dbdae 100644 --- a/lapi.c +++ b/lapi.c @@ -1,5 +1,5 @@ /* -** $Id: lapi.c,v 2.114 2010/03/08 16:55:52 roberto Exp roberto $ +** $Id: lapi.c,v 2.115 2010/03/22 18:28:03 roberto Exp roberto $ ** Lua API ** See Copyright Notice in lua.h */ @@ -928,7 +928,6 @@ LUA_API int lua_gc (lua_State *L, int what, int data) { break; } case LUA_GCRESTART: { - g->gckind = KGC_NORMAL; g->GCthreshold = g->totalbytes; break; } @@ -947,13 +946,19 @@ LUA_API int lua_gc (lua_State *L, int what, int data) { } case LUA_GCSTEP: { lu_mem oldts = g->GCthreshold; - lu_mem a = (cast(lu_mem, data) << 10); - g->GCthreshold = (a <= g->totalbytes) ? g->totalbytes - a : 0; - while (g->GCthreshold <= g->totalbytes) { - luaC_step(L); - if (g->gcstate == GCSpause) { /* end of cycle? */ - res = 1; /* signal it */ - break; + if (g->gckind == KGC_GEN) { /* generational mode? */ + res = (g->lastmajormem == 0); /* 1 if will do major collection */ + luaC_step(L); /* do a single step */ + } + else { + lu_mem a = (cast(lu_mem, data) << 10); + g->GCthreshold = (a <= g->totalbytes) ? g->totalbytes - a : 0; + while (g->GCthreshold <= g->totalbytes) { + luaC_step(L); + if (g->gcstate == GCSpause) { /* end of cycle? */ + res = 1; /* signal it */ + break; + } } } if (oldts == MAX_LUMEM) /* collector was stopped? */ @@ -976,6 +981,7 @@ LUA_API int lua_gc (lua_State *L, int what, int data) { } case LUA_GCGEN: { /* change collector to generational mode */ luaC_runtilstate(L, bitmask(GCSpropagate)); + g->lastmajormem = g->totalbytes; g->gckind = KGC_GEN; break; } -- cgit v1.2.3-55-g6feb