aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRoberto Ierusalimschy <roberto@inf.puc-rio.br>2017-04-30 17:43:26 -0300
committerRoberto Ierusalimschy <roberto@inf.puc-rio.br>2017-04-30 17:43:26 -0300
commit8634b2a0119e698e362fdb765f30258e79e1dfd0 (patch)
treec20c79efbbf0bc8fa565c34932e283fc428c9219
parent5ecb31003f8086f057444468d0356771526ec7b4 (diff)
downloadlua-8634b2a0119e698e362fdb765f30258e79e1dfd0.tar.gz
lua-8634b2a0119e698e362fdb765f30258e79e1dfd0.tar.bz2
lua-8634b2a0119e698e362fdb765f30258e79e1dfd0.zip
added 'cachemiss' field to prototype to avoid wasting time checking
hits that fail too often
-rw-r--r--lfunc.c3
-rw-r--r--lgc.c3
-rw-r--r--lobject.h3
-rw-r--r--lvm.c12
4 files changed, 15 insertions, 6 deletions
diff --git a/lfunc.c b/lfunc.c
index 898104ac..5c6ebd27 100644
--- a/lfunc.c
+++ b/lfunc.c
@@ -1,5 +1,5 @@
1/* 1/*
2** $Id: lfunc.c,v 2.46 2017/04/06 13:08:56 roberto Exp roberto $ 2** $Id: lfunc.c,v 2.47 2017/04/11 18:41:09 roberto Exp roberto $
3** Auxiliary functions to manipulate prototypes and closures 3** Auxiliary functions to manipulate prototypes and closures
4** See Copyright Notice in lua.h 4** See Copyright Notice in lua.h
5*/ 5*/
@@ -115,6 +115,7 @@ Proto *luaF_newproto (lua_State *L) {
115 f->sizep = 0; 115 f->sizep = 0;
116 f->code = NULL; 116 f->code = NULL;
117 f->cache = NULL; 117 f->cache = NULL;
118 f->cachemiss = 0;
118 f->sizecode = 0; 119 f->sizecode = 0;
119 f->lineinfo = NULL; 120 f->lineinfo = NULL;
120 f->sizelineinfo = 0; 121 f->sizelineinfo = 0;
diff --git a/lgc.c b/lgc.c
index 692326f3..65f4909c 100644
--- a/lgc.c
+++ b/lgc.c
@@ -1,5 +1,5 @@
1/* 1/*
2** $Id: lgc.c,v 2.225 2017/04/24 16:59:26 roberto Exp $ 2** $Id: lgc.c,v 2.226 2017/04/24 17:52:18 roberto Exp roberto $
3** Garbage Collector 3** Garbage Collector
4** See Copyright Notice in lua.h 4** See Copyright Notice in lua.h
5*/ 5*/
@@ -485,6 +485,7 @@ static int traverseproto (global_State *g, Proto *f) {
485 int i; 485 int i;
486 if (f->cache && iswhite(f->cache)) 486 if (f->cache && iswhite(f->cache))
487 f->cache = NULL; /* allow cache to be collected */ 487 f->cache = NULL; /* allow cache to be collected */
488 f->cachemiss = 0; /* restart counting */
488 markobjectN(g, f->source); 489 markobjectN(g, f->source);
489 for (i = 0; i < f->sizek; i++) /* mark literals */ 490 for (i = 0; i < f->sizek; i++) /* mark literals */
490 markvalue(g, &f->k[i]); 491 markvalue(g, &f->k[i]);
diff --git a/lobject.h b/lobject.h
index c8f9adb3..f8a73a14 100644
--- a/lobject.h
+++ b/lobject.h
@@ -1,5 +1,5 @@
1/* 1/*
2** $Id: lobject.h,v 2.118 2017/04/11 18:41:09 roberto Exp roberto $ 2** $Id: lobject.h,v 2.119 2017/04/24 18:06:12 roberto Exp roberto $
3** Type definitions for Lua objects 3** Type definitions for Lua objects
4** See Copyright Notice in lua.h 4** See Copyright Notice in lua.h
5*/ 5*/
@@ -410,6 +410,7 @@ typedef struct Proto {
410 lu_byte numparams; /* number of fixed parameters */ 410 lu_byte numparams; /* number of fixed parameters */
411 lu_byte is_vararg; 411 lu_byte is_vararg;
412 lu_byte maxstacksize; /* number of registers needed by this function */ 412 lu_byte maxstacksize; /* number of registers needed by this function */
413 lu_byte cachemiss; /* count for successive misses for 'cache' field */
413 int sizeupvalues; /* size of 'upvalues' */ 414 int sizeupvalues; /* size of 'upvalues' */
414 int sizek; /* size of 'k' */ 415 int sizek; /* size of 'k' */
415 int sizecode; 416 int sizecode;
diff --git a/lvm.c b/lvm.c
index 9fa9daf5..744ca6dd 100644
--- a/lvm.c
+++ b/lvm.c
@@ -1,5 +1,5 @@
1/* 1/*
2** $Id: lvm.c,v 2.273 2017/04/26 17:46:52 roberto Exp roberto $ 2** $Id: lvm.c,v 2.274 2017/04/28 20:57:45 roberto Exp roberto $
3** Lua virtual machine 3** Lua virtual machine
4** See Copyright Notice in lua.h 4** See Copyright Notice in lua.h
5*/ 5*/
@@ -618,6 +618,7 @@ static LClosure *getcached (Proto *p, UpVal **encup, StkId base) {
618 if (c->upvals[i]->v != v) 618 if (c->upvals[i]->v != v)
619 return NULL; /* wrong upvalue; cannot reuse closure */ 619 return NULL; /* wrong upvalue; cannot reuse closure */
620 } 620 }
621 p->cachemiss = 0; /* got a hit */
621 } 622 }
622 return c; /* return cached closure (or NULL if no cached closure) */ 623 return c; /* return cached closure (or NULL if no cached closure) */
623} 624}
@@ -644,8 +645,13 @@ static void pushclosure (lua_State *L, Proto *p, UpVal **encup, StkId base,
644 ncl->upvals[i] = encup[uv[i].idx]; 645 ncl->upvals[i] = encup[uv[i].idx];
645 /* new closure is white, so we do not need a barrier here */ 646 /* new closure is white, so we do not need a barrier here */
646 } 647 }
647 if (!isblack(p)) /* cache will not break GC invariant? */ 648 if (p->cachemiss >= 10) /* too many missings? */
648 p->cache = ncl; /* save it on cache for reuse */ 649 p->cache = NULL; /* give up cache */
650 else {
651 if (!isblack(p)) /* cache will not break GC invariant? */
652 p->cache = ncl; /* save it on cache for reuse */
653 p->cachemiss++;
654 }
649} 655}
650 656
651 657