Don't constify upvalues that may retain large amounts of memory.

This commit is contained in:
Mike Pall 2012-08-28 15:24:53 +02:00
parent c7826af5a0
commit 751cd9d821
2 changed files with 30 additions and 3 deletions

View File

@ -155,8 +155,9 @@ lj_parse.o: lj_parse.c lj_obj.h lua.h luaconf.h lj_def.h lj_arch.h \
lj_state.h lj_bc.h lj_ctype.h lj_lex.h lj_parse.h lj_vm.h lj_vmevent.h
lj_record.o: lj_record.c lj_obj.h lua.h luaconf.h lj_def.h lj_arch.h \
lj_err.h lj_errmsg.h lj_str.h lj_tab.h lj_meta.h lj_frame.h lj_bc.h \
lj_ff.h lj_ffdef.h lj_ir.h lj_jit.h lj_ircall.h lj_iropt.h lj_trace.h \
lj_dispatch.h lj_traceerr.h lj_record.h lj_ffrecord.h lj_snap.h lj_vm.h
lj_ctype.h lj_gc.h lj_ff.h lj_ffdef.h lj_ir.h lj_jit.h lj_ircall.h \
lj_iropt.h lj_trace.h lj_dispatch.h lj_traceerr.h lj_record.h \
lj_ffrecord.h lj_snap.h lj_vm.h
lj_snap.o: lj_snap.c lj_obj.h lua.h luaconf.h lj_def.h lj_arch.h lj_gc.h \
lj_tab.h lj_state.h lj_frame.h lj_bc.h lj_ir.h lj_jit.h lj_iropt.h \
lj_trace.h lj_dispatch.h lj_traceerr.h lj_snap.h lj_target.h \

View File

@ -15,6 +15,9 @@
#include "lj_tab.h"
#include "lj_meta.h"
#include "lj_frame.h"
#if LJ_HASFFI
#include "lj_ctype.h"
#endif
#include "lj_bc.h"
#include "lj_ff.h"
#include "lj_ir.h"
@ -1275,6 +1278,29 @@ TRef lj_record_idx(jit_State *J, RecordIndex *ix)
/* -- Upvalue access ------------------------------------------------------ */
/* Check whether upvalue is immutable and ok to constify. */
static int rec_upvalue_constify(jit_State *J, GCupval *uvp)
{
if (uvp->immutable) {
cTValue *o = uvval(uvp);
/* Don't constify objects that may retain large amounts of memory. */
#if LJ_HASFFI
if (tviscdata(o)) {
GCcdata *cd = cdataV(o);
if (!cdataisv(cd) && !(cd->marked & LJ_GC_CDATA_FIN)) {
CType *ct = ctype_raw(ctype_ctsG(J2G(J)), cd->ctypeid);
if (!ctype_hassize(ct->info) || ct->size <= 16)
return 1;
}
return 0;
}
#endif
if (!(tvistab(o) || tvisudata(o) || tvisthread(o)))
return 1;
}
return 0;
}
/* Record upvalue load/store. */
static TRef rec_upvalue(jit_State *J, uint32_t uv, TRef val)
{
@ -1282,7 +1308,7 @@ static TRef rec_upvalue(jit_State *J, uint32_t uv, TRef val)
TRef fn = getcurrf(J);
IRRef uref;
int needbarrier = 0;
if (uvp->immutable) { /* Try to constify immutable upvalue. */
if (rec_upvalue_constify(J, uvp)) { /* Try to constify immutable upvalue. */
TRef tr, kfunc;
lua_assert(val == 0);
if (!tref_isk(fn)) { /* Late specialization of current function. */