]> git.ipfire.org Git - thirdparty/LuaJIT.git/commitdiff
Don't constify upvalues that may retain large amounts of memory.
authorMike Pall <mike>
Tue, 28 Aug 2012 13:24:53 +0000 (15:24 +0200)
committerMike Pall <mike>
Tue, 28 Aug 2012 13:24:53 +0000 (15:24 +0200)
src/Makefile.dep
src/lj_record.c

index 9b130deb9b0663a8735517083c4f9d63ae2cb24b..94a963ba364b4a8e03bf599583b5d6a35d9eb27a 100644 (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 \
index a593af99909979d3e0c5239e62b2814667af8cf3..ce25f29ef8e362cdda1b79072ae611793a5e5cf2 100644 (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. */