Kludge allowing JM to use type inference without needing recompilation, bug 608746.
authorBrian Hackett <bhackett1024@gmail.com>
Mon, 01 Nov 2010 09:43:25 -0700
changeset 74602 a2e6ee94f4bfa85ac6e30d7f9f828483bcb0bc14
parent 74601 1185c7f42e5d2a80796c69ace2faabace099f4e5
child 74603 d4258341de5ce74ac382429c6ee473d5657efbe7
push id2
push userbsmedberg@mozilla.com
push dateFri, 19 Aug 2011 14:38:13 +0000
bugs608746
milestone2.0b8pre
Kludge allowing JM to use type inference without needing recompilation, bug 608746.
js/src/jsscript.cpp
js/src/shell/js.cpp
--- a/js/src/jsscript.cpp
+++ b/js/src/jsscript.cpp
@@ -1768,17 +1768,18 @@ JSScript::copyClosedSlotsTo(JSScript *ot
 
 js::analyze::Script *
 JSScript::analyze(JSContext *cx)
 {
     if (!analysis)
         makeAnalysis(cx);
     if (!analysis)
         return NULL;
-    analysis->analyze(cx);
+    if (!analysis->hasAnalyzed())
+        analysis->analyze(cx);
     return analysis;
 }
 
 js::analyze::Script *
 JSScript::makeAnalysis(JSContext *cx)
 {
     JS_ASSERT(!analysis);
     analysis = (js::analyze::Script *) cx->calloc(sizeof(js::analyze::Script));
--- a/js/src/shell/js.cpp
+++ b/js/src/shell/js.cpp
@@ -444,16 +444,56 @@ Process(JSContext *cx, JSObject *obj, ch
 
         int64 t1 = PRMJ_Now();
         oldopts = JS_GetOptions(cx);
         JS_SetOptions(cx, oldopts | JSOPTION_COMPILE_N_GO | JSOPTION_NO_SCRIPT_RVAL);
         script = JS_CompileFileHandle(cx, obj, filename, file);
         JS_SetOptions(cx, oldopts);
         if (script) {
             if (!compileOnly) {
+#ifdef JS_TYPE_INFERENCE
+                if (enableTraceJit || enableMethodJit) {
+                    /*
+                     * Disable the jits and run the script under the interpreter
+                     * first to pick up any dynamic types.  This is code is temporary
+                     * until recompilation works :FIXME: bug 608746
+                     */
+
+                    /* Clone the global object for the second run. */
+                    JSObject *nobj = JS_NewGlobalObject(cx, obj->getJSClass());
+                    if (!nobj || !nobj->ensureSlots(cx, obj->numSlots()))
+                        return;
+                    memcpy(nobj->getSlots(), obj->getSlots(), obj->numSlots() * sizeof(Value));
+                    nobj->lastProp = obj->lastProp;
+                    nobj->objShape = obj->objShape;
+                    nobj->proto = obj->proto;
+                    JS_ASSERT(nobj->flags == obj->flags);
+                    JS_ASSERT(!nobj->parent && !obj->parent);
+                    JS_ASSERT(!nobj->privateData && !obj->privateData);
+                    JS_ASSERT(obj == cx->globalObject);
+
+                    if (enableTraceJit)
+                        JS_ToggleOptions(cx, JSOPTION_JIT);
+                    if (enableMethodJit)
+                        JS_ToggleOptions(cx, JSOPTION_METHODJIT);
+
+                    printf("Running interpreter...\n");
+
+                    (void)JS_ExecuteScript(cx, obj, script, NULL);
+                    t1 = PRMJ_Now();
+
+                    if (enableTraceJit)
+                        JS_ToggleOptions(cx, JSOPTION_JIT);
+                    if (enableMethodJit)
+                        JS_ToggleOptions(cx, JSOPTION_METHODJIT);
+
+                    printf("Running JITs...\n");
+                }
+#endif
+
                 (void)JS_ExecuteScript(cx, obj, script, NULL);
                 int64 t2 = PRMJ_Now() - t1;
                 if (printTiming)
                     printf("runtime = %.3f ms\n", double(t2) / PRMJ_USEC_PER_MSEC);
             }
             JS_DestroyScript(cx, script);
         }