aboutsummaryrefslogtreecommitdiff
path: root/src/lj_record.c
diff options
context:
space:
mode:
authorMike Pall <mike>2012-08-28 15:24:53 +0200
committerMike Pall <mike>2012-08-28 15:24:53 +0200
commit751cd9d82180f1bd99a738acc29bc114995a42e4 (patch)
treef472c16ba66eabf209d938c29a19047780dcce61 /src/lj_record.c
parentc7826af5a0403b48eeeb6c18532dc076146b1966 (diff)
downloadluajit-751cd9d82180f1bd99a738acc29bc114995a42e4.tar.gz
luajit-751cd9d82180f1bd99a738acc29bc114995a42e4.tar.bz2
luajit-751cd9d82180f1bd99a738acc29bc114995a42e4.zip
Don't constify upvalues that may retain large amounts of memory.
Diffstat (limited to 'src/lj_record.c')
-rw-r--r--src/lj_record.c28
1 files changed, 27 insertions, 1 deletions
diff --git a/src/lj_record.c b/src/lj_record.c
index a593af99..ce25f29e 100644
--- a/src/lj_record.c
+++ b/src/lj_record.c
@@ -15,6 +15,9 @@
15#include "lj_tab.h" 15#include "lj_tab.h"
16#include "lj_meta.h" 16#include "lj_meta.h"
17#include "lj_frame.h" 17#include "lj_frame.h"
18#if LJ_HASFFI
19#include "lj_ctype.h"
20#endif
18#include "lj_bc.h" 21#include "lj_bc.h"
19#include "lj_ff.h" 22#include "lj_ff.h"
20#include "lj_ir.h" 23#include "lj_ir.h"
@@ -1275,6 +1278,29 @@ TRef lj_record_idx(jit_State *J, RecordIndex *ix)
1275 1278
1276/* -- Upvalue access ------------------------------------------------------ */ 1279/* -- Upvalue access ------------------------------------------------------ */
1277 1280
1281/* Check whether upvalue is immutable and ok to constify. */
1282static int rec_upvalue_constify(jit_State *J, GCupval *uvp)
1283{
1284 if (uvp->immutable) {
1285 cTValue *o = uvval(uvp);
1286 /* Don't constify objects that may retain large amounts of memory. */
1287#if LJ_HASFFI
1288 if (tviscdata(o)) {
1289 GCcdata *cd = cdataV(o);
1290 if (!cdataisv(cd) && !(cd->marked & LJ_GC_CDATA_FIN)) {
1291 CType *ct = ctype_raw(ctype_ctsG(J2G(J)), cd->ctypeid);
1292 if (!ctype_hassize(ct->info) || ct->size <= 16)
1293 return 1;
1294 }
1295 return 0;
1296 }
1297#endif
1298 if (!(tvistab(o) || tvisudata(o) || tvisthread(o)))
1299 return 1;
1300 }
1301 return 0;
1302}
1303
1278/* Record upvalue load/store. */ 1304/* Record upvalue load/store. */
1279static TRef rec_upvalue(jit_State *J, uint32_t uv, TRef val) 1305static TRef rec_upvalue(jit_State *J, uint32_t uv, TRef val)
1280{ 1306{
@@ -1282,7 +1308,7 @@ static TRef rec_upvalue(jit_State *J, uint32_t uv, TRef val)
1282 TRef fn = getcurrf(J); 1308 TRef fn = getcurrf(J);
1283 IRRef uref; 1309 IRRef uref;
1284 int needbarrier = 0; 1310 int needbarrier = 0;
1285 if (uvp->immutable) { /* Try to constify immutable upvalue. */ 1311 if (rec_upvalue_constify(J, uvp)) { /* Try to constify immutable upvalue. */
1286 TRef tr, kfunc; 1312 TRef tr, kfunc;
1287 lua_assert(val == 0); 1313 lua_assert(val == 0);
1288 if (!tref_isk(fn)) { /* Late specialization of current function. */ 1314 if (!tref_isk(fn)) { /* Late specialization of current function. */