]> git.ipfire.org Git - thirdparty/LuaJIT.git/commitdiff
Reset the hotcount table after a JIT off to on transition.
authorMike Pall <mike>
Thu, 4 Feb 2010 19:40:00 +0000 (20:40 +0100)
committerMike Pall <mike>
Thu, 4 Feb 2010 19:40:00 +0000 (20:40 +0100)
src/lib_jit.c
src/lj_dispatch.c
src/lj_dispatch.h

index 4da079c8fe38e5fd907a93ce69d5aa16de32b854..0728fc3ad140bddd184df2c98047a4f829e4399f 100644 (file)
@@ -437,9 +437,6 @@ static int jitopt_flag(jit_State *J, const char *str)
   return 0;  /* No match. */
 }
 
-/* Forward declaration. */
-static void jit_init_hotcount(jit_State *J);
-
 /* Parse optimization parameter. */
 static int jitopt_param(jit_State *J, const char *str)
 {
@@ -453,7 +450,7 @@ static int jitopt_param(jit_State *J, const char *str)
        lj_str_numconv(&str[len+1], &tv)) {
       J->param[i] = lj_num2int(tv.n);
       if (i == JIT_P_hotloop)
-       jit_init_hotcount(J);
+       lj_dispatch_init_hotcount(J2G(J));
       return 1;  /* Ok. */
     }
     lst += 1+len;
@@ -498,16 +495,6 @@ JIT_PARAMDEF(JIT_PARAMINIT)
 #undef JIT_PARAMINIT
   0
 };
-
-/* Initialize hotcount table. */
-static void jit_init_hotcount(jit_State *J)
-{
-  HotCount start = (HotCount)J->param[JIT_P_hotloop];
-  HotCount *hotcount = J2GG(J)->hotcount;
-  uint32_t i;
-  for (i = 0; i < HOTCOUNT_SIZE; i++)
-    hotcount[i] = start;
-}
 #endif
 
 /* Arch-dependent CPU detection. */
@@ -570,7 +557,6 @@ static void jit_init(lua_State *L)
   jit_State *J = L2J(L);
   J->flags = flags | JIT_F_ON | JIT_F_OPT_DEFAULT;
   memcpy(J->param, jit_param_default, sizeof(J->param));
-  jit_init_hotcount(J);
   lj_dispatch_update(G(L));
 #else
   UNUSED(flags);
index 1e5b574c29242a914570cd90797541aaa9992486..a94afea9e2dcd33abcd743cd16f55b5d45d49b34 100644 (file)
@@ -34,6 +34,18 @@ void lj_dispatch_init(GG_State *GG)
   disp[BC_LOOP] = disp[BC_ILOOP];
 }
 
+#if LJ_HASJIT
+/* Initialize hotcount table. */
+void lj_dispatch_init_hotcount(global_State *g)
+{
+  HotCount start = (HotCount)G2J(g)->param[JIT_P_hotloop];
+  HotCount *hotcount = G2GG(g)->hotcount;
+  uint32_t i;
+  for (i = 0; i < HOTCOUNT_SIZE; i++)
+    hotcount[i] = start;
+}
+#endif
+
 /* Update dispatch table depending on various flags. */
 void lj_dispatch_update(global_State *g)
 {
@@ -77,6 +89,10 @@ void lj_dispatch_update(global_State *g)
       disp[BC_ITERL] = f_iterl;
       disp[BC_LOOP] = f_loop;
     }
+#if LJ_HASJIT
+    if ((mode & 1) && !(oldmode & 1))  /* JIT off to on transition. */
+      lj_dispatch_init_hotcount(g);
+#endif
   }
 }
 
index ce9d9e119c63aaa84e8412f298d4f8d408da0c06..cb5e5f64aea6b8ec9c76985084fab4a8870965f1 100644 (file)
@@ -56,6 +56,7 @@ typedef struct GG_State {
 
 /* Dispatch table management. */
 LJ_FUNC void lj_dispatch_init(GG_State *GG);
+LJ_FUNC void lj_dispatch_init_hotcount(global_State *g);
 LJ_FUNC void lj_dispatch_update(global_State *g);
 
 /* Instruction dispatch callback for instr/line hooks or when recording. */