Bug 739532 - don't malloc BytecodeEmitter (r=jorendorff)
authorLuke Wagner <luke@mozilla.com>
Fri, 23 Mar 2012 11:29:30 -0700
changeset 90533 1c7d12a257d0e784805998a463f4458d3683cb0c
parent 90532 7a78aae4fa278a5c3819baf8fa280ac8910f3924
child 90534 4166e7ce816c0235aeb06c55b72b4abe030dcd94
push id22366
push usermak77@bonardo.net
push dateThu, 29 Mar 2012 15:38:30 +0000
treeherdermozilla-central@ff3521bc6559 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersjorendorff
bugs739532
milestone14.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 739532 - don't malloc BytecodeEmitter (r=jorendorff)
js/src/frontend/BytecodeEmitter.cpp
--- a/js/src/frontend/BytecodeEmitter.cpp
+++ b/js/src/frontend/BytecodeEmitter.cpp
@@ -4888,17 +4888,17 @@ static inline bool
 EmitFor(JSContext *cx, BytecodeEmitter *bce, ParseNode *pn, ptrdiff_t top)
 {
     JS_ASSERT(pn->pn_left->isKind(PNK_FORIN) || pn->pn_left->isKind(PNK_FORHEAD));
     return pn->pn_left->isKind(PNK_FORIN)
            ? EmitForIn(cx, bce, pn, top)
            : EmitNormalFor(cx, bce, pn, top);
 }
 
-static bool
+static JS_NEVER_INLINE bool
 EmitFunc(JSContext *cx, BytecodeEmitter *bce, ParseNode *pn)
 {
 #if JS_HAS_XML_SUPPORT
     if (pn->isArity(PN_NULLARY))
         return Emit1(cx, bce, JSOP_GETFUNNS) >= 0;
 #endif
 
     JSFunction *fun = pn->pn_funbox->function();
@@ -4913,45 +4913,39 @@ EmitFunc(JSContext *cx, BytecodeEmitter 
         JS_ASSERT(bce->inFunction());
         return EmitFunctionDefNop(cx, bce, pn->pn_index);
     }
 
     JS_ASSERT_IF(pn->pn_funbox->tcflags & TCF_FUN_HEAVYWEIGHT,
                  fun->kind() == JSFUN_INTERPRETED);
 
     {
-        /*
-         * Generate code for the function's body.  bce2 is not allocated on the
-         * stack because doing so significantly reduces the maximum depth of
-         * nested functions we can handle.  See bug 696284.
-         */
-        AutoPtr<BytecodeEmitter> bce2(cx);
-        bce2 = cx->new_<BytecodeEmitter>(bce->parser, pn->pn_pos.begin.lineno);
-        if (!bce2 || !bce2->init(cx))
-            return false;
-
-        bce2->flags = pn->pn_funbox->tcflags | TCF_COMPILING | TCF_IN_FUNCTION |
+        BytecodeEmitter bce2(bce->parser, pn->pn_pos.begin.lineno);
+        if (!bce2.init(cx))
+            return false;
+
+        bce2.flags = pn->pn_funbox->tcflags | TCF_COMPILING | TCF_IN_FUNCTION |
                      (bce->flags & TCF_FUN_MIGHT_ALIAS_LOCALS);
-        bce2->bindings.transfer(cx, &pn->pn_funbox->bindings);
-        bce2->setFunction(fun);
-        bce2->funbox = pn->pn_funbox;
-        bce2->parent = bce;
-        bce2->globalScope = bce->globalScope;
+        bce2.bindings.transfer(cx, &pn->pn_funbox->bindings);
+        bce2.setFunction(fun);
+        bce2.funbox = pn->pn_funbox;
+        bce2.parent = bce;
+        bce2.globalScope = bce->globalScope;
 
         /*
          * js::frontend::SetStaticLevel limited static nesting depth to fit in
          * 16 bits and to reserve the all-ones value, thereby reserving the
-         * magic FREE_UPVAR_COOKIE value. Note the bce2->staticLevel assignment
+         * magic FREE_UPVAR_COOKIE value. Note the bce2.staticLevel assignment
          * below.
          */
         JS_ASSERT(bce->staticLevel < JS_BITMASK(16) - 1);
-        bce2->staticLevel = bce->staticLevel + 1;
+        bce2.staticLevel = bce->staticLevel + 1;
 
         /* We measured the max scope depth when we parsed the function. */
-        if (!EmitFunctionScript(cx, bce2.get(), pn->pn_body))
+        if (!EmitFunctionScript(cx, &bce2, pn->pn_body))
             return false;
     }
 
     /* Make the function object a literal in the outer script's pool. */
     unsigned index = bce->objectList.index(pn->pn_funbox);
 
     /* Emit a bytecode pointing to the closure object in its immediate. */
     if (pn->getOp() != JSOP_NOP) {