2010-10-26 12:00:54 -07:00
|
|
|
/* -*- Mode: c++; c-basic-offset: 4; tab-width: 40; indent-tabs-mode: nil -*- */
|
|
|
|
/* vim: set ts=40 sw=4 et tw=99: */
|
2012-05-21 04:12:37 -07:00
|
|
|
/* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
2010-10-26 12:00:54 -07:00
|
|
|
|
|
|
|
#include "jsanalyze.h"
|
|
|
|
#include "jsautooplen.h"
|
|
|
|
#include "jscompartment.h"
|
|
|
|
#include "jscntxt.h"
|
|
|
|
|
2011-04-05 18:12:03 -07:00
|
|
|
#include "jsinferinlines.h"
|
|
|
|
#include "jsobjinlines.h"
|
|
|
|
|
2011-04-22 07:59:45 -07:00
|
|
|
namespace js {
|
|
|
|
namespace analyze {
|
2010-10-26 12:00:54 -07:00
|
|
|
|
|
|
|
/////////////////////////////////////////////////////////////////////
|
|
|
|
// Bytecode
|
|
|
|
/////////////////////////////////////////////////////////////////////
|
|
|
|
|
2011-04-22 07:59:45 -07:00
|
|
|
#ifdef DEBUG
|
|
|
|
void
|
|
|
|
PrintBytecode(JSContext *cx, JSScript *script, jsbytecode *pc)
|
|
|
|
{
|
|
|
|
printf("#%u:", script->id());
|
2012-01-20 15:09:56 -08:00
|
|
|
Sprinter sprinter(cx);
|
|
|
|
if (!sprinter.init())
|
|
|
|
return;
|
2011-04-22 07:59:45 -07:00
|
|
|
js_Disassemble1(cx, script, pc, pc - script->code, true, &sprinter);
|
2012-01-20 15:09:56 -08:00
|
|
|
fprintf(stdout, "%s", sprinter.string());
|
2011-04-22 07:59:45 -07:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2010-10-26 12:00:54 -07:00
|
|
|
/////////////////////////////////////////////////////////////////////
|
2011-04-22 07:59:45 -07:00
|
|
|
// Bytecode Analysis
|
2010-10-26 12:00:54 -07:00
|
|
|
/////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
inline bool
|
2011-04-22 07:59:45 -07:00
|
|
|
ScriptAnalysis::addJump(JSContext *cx, unsigned offset,
|
2012-03-21 06:37:43 -07:00
|
|
|
unsigned *currentOffset, unsigned *forwardJump, unsigned *forwardLoop,
|
2011-10-29 17:30:08 -07:00
|
|
|
unsigned stackDepth)
|
2010-10-26 12:00:54 -07:00
|
|
|
{
|
|
|
|
JS_ASSERT(offset < script->length);
|
|
|
|
|
2010-10-29 08:05:55 -07:00
|
|
|
Bytecode *&code = codeArray[offset];
|
2011-10-29 17:30:08 -07:00
|
|
|
if (!code) {
|
2011-09-22 13:22:30 -07:00
|
|
|
code = cx->typeLifoAlloc().new_<Bytecode>();
|
2010-10-29 08:05:55 -07:00
|
|
|
if (!code) {
|
2010-10-26 12:00:54 -07:00
|
|
|
setOOM(cx);
|
|
|
|
return false;
|
|
|
|
}
|
2011-10-29 17:30:08 -07:00
|
|
|
code->stackDepth = stackDepth;
|
2010-10-26 12:00:54 -07:00
|
|
|
}
|
2011-10-29 17:30:08 -07:00
|
|
|
JS_ASSERT(code->stackDepth == stackDepth);
|
2010-10-26 12:00:54 -07:00
|
|
|
|
2010-10-29 08:05:55 -07:00
|
|
|
code->jumpTarget = true;
|
2010-10-26 12:00:54 -07:00
|
|
|
|
|
|
|
if (offset < *currentOffset) {
|
2011-03-26 19:07:13 -07:00
|
|
|
/* Scripts containing loops are never inlined. */
|
|
|
|
isInlineable = false;
|
|
|
|
|
2012-03-21 06:37:43 -07:00
|
|
|
if (code->analyzed) {
|
|
|
|
/*
|
|
|
|
* Backedge in a do-while loop, the body has been analyzed. Rewalk
|
|
|
|
* the body to set inLoop bits.
|
|
|
|
*/
|
|
|
|
for (unsigned i = offset; i <= *currentOffset; i++) {
|
|
|
|
Bytecode *code = maybeCode(i);
|
|
|
|
if (code)
|
|
|
|
code->inLoop = true;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
/*
|
|
|
|
* Backedge in a while/for loop, whose body has not been analyzed
|
|
|
|
* due to a lack of fallthrough at the loop head. Roll back the
|
|
|
|
* offset to analyze the body.
|
|
|
|
*/
|
2010-10-26 12:00:54 -07:00
|
|
|
if (*forwardJump == 0)
|
|
|
|
*forwardJump = *currentOffset;
|
2012-03-21 06:37:43 -07:00
|
|
|
if (*forwardLoop == 0)
|
|
|
|
*forwardLoop = *currentOffset;
|
2010-10-26 12:00:54 -07:00
|
|
|
*currentOffset = offset;
|
|
|
|
}
|
|
|
|
} else if (offset > *forwardJump) {
|
|
|
|
*forwardJump = offset;
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2010-10-29 08:05:55 -07:00
|
|
|
void
|
2011-04-22 07:59:45 -07:00
|
|
|
ScriptAnalysis::analyzeBytecode(JSContext *cx)
|
2010-10-29 08:05:55 -07:00
|
|
|
{
|
2011-04-22 07:59:45 -07:00
|
|
|
JS_ASSERT(cx->compartment->activeAnalysis);
|
|
|
|
JS_ASSERT(!ranBytecode());
|
2011-09-22 13:22:30 -07:00
|
|
|
LifoAlloc &tla = cx->typeLifoAlloc();
|
2010-10-26 12:00:54 -07:00
|
|
|
|
|
|
|
unsigned length = script->length;
|
2011-10-21 14:31:01 -07:00
|
|
|
unsigned nargs = script->function() ? script->function()->nargs : 0;
|
2011-04-22 07:59:45 -07:00
|
|
|
|
|
|
|
numSlots = TotalSlots(script);
|
2010-10-26 12:00:54 -07:00
|
|
|
|
2011-09-22 13:22:30 -07:00
|
|
|
codeArray = tla.newArray<Bytecode*>(length);
|
2012-02-28 19:03:57 -08:00
|
|
|
escapedSlots = tla.newArray<bool>(numSlots);
|
2010-10-26 12:00:54 -07:00
|
|
|
|
2011-10-29 17:30:08 -07:00
|
|
|
if (!codeArray || !escapedSlots) {
|
2010-10-26 12:00:54 -07:00
|
|
|
setOOM(cx);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2010-10-29 08:05:55 -07:00
|
|
|
PodZero(codeArray, length);
|
2010-10-26 12:00:54 -07:00
|
|
|
|
|
|
|
/*
|
2011-04-22 07:59:45 -07:00
|
|
|
* Populate arg and local slots which can escape and be accessed in ways
|
|
|
|
* other than through ARG* and LOCAL* opcodes (though arguments can still
|
|
|
|
* be indirectly read but not written through 'arguments' properties).
|
|
|
|
* All escaping locals are treated as having possible use-before-defs.
|
2012-04-02 08:58:30 -07:00
|
|
|
* Conservatively use 'hasArgsBinding' instead of 'needsArgsObj'
|
2012-01-17 16:35:12 -08:00
|
|
|
* (needsArgsObj requires SSA which requires escapedSlots).
|
2010-10-26 12:00:54 -07:00
|
|
|
*/
|
|
|
|
|
2011-04-22 07:59:45 -07:00
|
|
|
PodZero(escapedSlots, numSlots);
|
|
|
|
|
2012-04-02 08:58:30 -07:00
|
|
|
if (script->bindingsAccessedDynamically || script->compartment()->debugMode() ||
|
|
|
|
script->argumentsHasLocalBinding())
|
2012-03-16 12:02:37 -07:00
|
|
|
{
|
2011-04-22 07:59:45 -07:00
|
|
|
for (unsigned i = 0; i < nargs; i++)
|
|
|
|
escapedSlots[ArgSlot(i)] = true;
|
|
|
|
} else {
|
2012-04-09 16:37:16 -07:00
|
|
|
for (uint32_t i = 0; i < script->numClosedArgs(); i++) {
|
2011-04-22 07:59:45 -07:00
|
|
|
unsigned arg = script->getClosedArg(i);
|
|
|
|
JS_ASSERT(arg < nargs);
|
|
|
|
escapedSlots[ArgSlot(arg)] = true;
|
|
|
|
}
|
2010-10-26 12:00:54 -07:00
|
|
|
}
|
|
|
|
|
2012-03-16 12:02:37 -07:00
|
|
|
if (script->bindingsAccessedDynamically || script->compartment()->debugMode()) {
|
2011-10-29 17:30:08 -07:00
|
|
|
for (unsigned i = 0; i < script->nfixed; i++)
|
2011-04-22 07:59:45 -07:00
|
|
|
escapedSlots[LocalSlot(script, i)] = true;
|
|
|
|
} else {
|
2012-04-09 16:37:16 -07:00
|
|
|
for (uint32_t i = 0; i < script->numClosedVars(); i++) {
|
2011-04-22 07:59:45 -07:00
|
|
|
unsigned local = script->getClosedVar(i);
|
2011-10-29 17:30:08 -07:00
|
|
|
JS_ASSERT(local < script->nfixed);
|
2011-04-22 07:59:45 -07:00
|
|
|
escapedSlots[LocalSlot(script, local)] = true;
|
|
|
|
}
|
2010-10-26 12:00:54 -07:00
|
|
|
}
|
|
|
|
|
2010-11-08 09:28:12 -08:00
|
|
|
/*
|
|
|
|
* If the script is in debug mode, JS_SetFrameReturnValue can be called at
|
|
|
|
* any safe point.
|
|
|
|
*/
|
Automatically turn debug mode on/off when adding/removing debuggees.
This allows most of the tests to run without the -d command-line flag.
Now a compartment is in debug mode if
* JSD1 wants debug mode on, thanks to a JS_SetDebugMode* call; OR
* JSD2 wants debug mode on, because a live Debug object has a debuggee
global in that compartment.
Since this patch only adds the second half of the rule, JSD1 should be
unaffected.
The new rule has three issues:
1. When removeDebuggee is called, it can cause debug mode to be turned
off for a compartment. If any scripts from that compartment are on
the stack, and the methodjit is enabled, returning to those stack
frames will crash.
2. When a Debug object is GC'd, it can cause debug mode to be turned off
for one or more compartments. This causes the same problem with
returning to deleted methodjit code, but the fix is different: such
Debug objects simply should not be GC'd.
3. Setting .enabled to false still does not turn off debug mode
anywhere, so it does not reduce overhead as much as it should.
A possible fix for issue #1 would be to make such removeDebuggee calls
throw; a different possibility is to turn off debug mode but leave all
the scripts alone, accepting the performance loss (as we do for JSD1 in
JSCompartment::setDebugModeFromC). The fix to issues #2 and #3 is to
tweak the rule--and to tweak the rule for Debug object GC-reachability.
--HG--
rename : js/src/jit-test/tests/debug/Debug-ctor.js => js/src/jit-test/tests/debug/Debug-ctor-01.js
2011-06-02 19:58:46 -07:00
|
|
|
if (cx->compartment->debugMode())
|
2011-09-01 12:20:30 -07:00
|
|
|
usesReturnValue_ = true;
|
2010-11-08 09:28:12 -08:00
|
|
|
|
2011-10-21 14:31:01 -07:00
|
|
|
bool heavyweight = script->function() && script->function()->isHeavyweight();
|
|
|
|
|
2012-05-03 03:13:44 -07:00
|
|
|
isJaegerCompileable = true;
|
2012-02-22 10:57:00 -08:00
|
|
|
|
2011-03-26 19:07:13 -07:00
|
|
|
isInlineable = true;
|
2012-04-09 16:37:16 -07:00
|
|
|
if (script->numClosedArgs() || script->numClosedVars() || heavyweight ||
|
2012-04-02 08:58:30 -07:00
|
|
|
script->bindingsAccessedDynamically || script->argumentsHasLocalBinding() ||
|
2012-03-16 12:02:37 -07:00
|
|
|
cx->compartment->debugMode())
|
|
|
|
{
|
2011-03-26 19:07:13 -07:00
|
|
|
isInlineable = false;
|
|
|
|
}
|
|
|
|
|
2011-05-26 12:28:19 -07:00
|
|
|
modifiesArguments_ = false;
|
2012-04-09 16:37:16 -07:00
|
|
|
if (script->numClosedArgs() || heavyweight)
|
2011-05-26 12:28:19 -07:00
|
|
|
modifiesArguments_ = true;
|
|
|
|
|
2011-04-22 07:59:45 -07:00
|
|
|
canTrackVars = true;
|
|
|
|
|
2010-10-26 12:00:54 -07:00
|
|
|
/*
|
|
|
|
* If we are in the middle of one or more jumps, the offset of the highest
|
|
|
|
* target jumping over this bytecode. Includes implicit jumps from
|
|
|
|
* try/catch/finally blocks.
|
|
|
|
*/
|
|
|
|
unsigned forwardJump = 0;
|
|
|
|
|
2012-03-21 06:37:43 -07:00
|
|
|
/* If we are in the middle of a loop, the offset of the highest backedge. */
|
|
|
|
unsigned forwardLoop = 0;
|
|
|
|
|
2010-10-26 12:00:54 -07:00
|
|
|
/*
|
|
|
|
* If we are in the middle of a try block, the offset of the highest
|
|
|
|
* catch/finally/enditer.
|
|
|
|
*/
|
|
|
|
unsigned forwardCatch = 0;
|
|
|
|
|
|
|
|
/* Fill in stack depth and definitions at initial bytecode. */
|
2011-09-22 13:22:30 -07:00
|
|
|
Bytecode *startcode = tla.new_<Bytecode>();
|
2010-10-26 12:00:54 -07:00
|
|
|
if (!startcode) {
|
|
|
|
setOOM(cx);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
startcode->stackDepth = 0;
|
2010-10-29 08:05:55 -07:00
|
|
|
codeArray[0] = startcode;
|
2010-10-26 12:00:54 -07:00
|
|
|
|
2011-07-28 09:16:53 -07:00
|
|
|
/* Number of JOF_TYPESET opcodes we have encountered. */
|
|
|
|
unsigned nTypeSets = 0;
|
|
|
|
types::TypeSet *typeArray = script->types->typeArray();
|
|
|
|
|
2010-10-26 12:00:54 -07:00
|
|
|
unsigned offset, nextOffset = 0;
|
|
|
|
while (nextOffset < length) {
|
|
|
|
offset = nextOffset;
|
|
|
|
|
|
|
|
JS_ASSERT(forwardCatch <= forwardJump);
|
|
|
|
|
|
|
|
/* Check if the current forward jump/try-block has finished. */
|
|
|
|
if (forwardJump && forwardJump == offset)
|
|
|
|
forwardJump = 0;
|
|
|
|
if (forwardCatch && forwardCatch == offset)
|
|
|
|
forwardCatch = 0;
|
|
|
|
|
2010-10-29 08:05:55 -07:00
|
|
|
Bytecode *code = maybeCode(offset);
|
2010-10-26 12:00:54 -07:00
|
|
|
jsbytecode *pc = script->code + offset;
|
|
|
|
|
|
|
|
JSOp op = (JSOp)*pc;
|
|
|
|
JS_ASSERT(op < JSOP_LIMIT);
|
|
|
|
|
|
|
|
/* Immediate successor of this bytecode. */
|
|
|
|
unsigned successorOffset = offset + GetBytecodeLength(pc);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Next bytecode to analyze. This is either the successor, or is an
|
|
|
|
* earlier bytecode if this bytecode has a loop backedge.
|
|
|
|
*/
|
|
|
|
nextOffset = successorOffset;
|
|
|
|
|
2010-10-29 08:05:55 -07:00
|
|
|
if (!code) {
|
2010-10-26 12:00:54 -07:00
|
|
|
/* Haven't found a path by which this bytecode is reachable. */
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2012-03-21 06:37:43 -07:00
|
|
|
/*
|
|
|
|
* Update info about bytecodes inside loops, which may have been
|
|
|
|
* analyzed before the backedge was seen.
|
|
|
|
*/
|
|
|
|
if (forwardLoop) {
|
|
|
|
code->inLoop = true;
|
|
|
|
if (forwardLoop <= offset)
|
|
|
|
forwardLoop = 0;
|
|
|
|
}
|
|
|
|
|
2010-10-29 08:05:55 -07:00
|
|
|
if (code->analyzed) {
|
2010-10-26 12:00:54 -07:00
|
|
|
/* No need to reanalyze, see Bytecode::mergeDefines. */
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2010-10-29 08:05:55 -07:00
|
|
|
code->analyzed = true;
|
2010-10-26 12:00:54 -07:00
|
|
|
|
|
|
|
if (forwardCatch)
|
2010-10-29 08:05:55 -07:00
|
|
|
code->inTryBlock = true;
|
2010-10-26 12:00:54 -07:00
|
|
|
|
2011-12-07 13:15:48 -08:00
|
|
|
if (script->hasBreakpointsAt(pc)) {
|
2010-12-20 09:06:43 -08:00
|
|
|
code->safePoint = true;
|
2011-04-22 07:59:45 -07:00
|
|
|
isInlineable = canTrackVars = false;
|
2011-03-26 19:07:13 -07:00
|
|
|
}
|
2010-12-20 09:06:43 -08:00
|
|
|
|
2010-10-29 08:05:55 -07:00
|
|
|
unsigned stackDepth = code->stackDepth;
|
2010-10-26 12:00:54 -07:00
|
|
|
|
2011-10-29 17:30:08 -07:00
|
|
|
if (!forwardJump)
|
2011-05-12 20:07:23 -07:00
|
|
|
code->unconditional = true;
|
2010-10-26 12:00:54 -07:00
|
|
|
|
2011-07-16 08:25:22 -07:00
|
|
|
/*
|
|
|
|
* Treat decompose ops as no-ops which do not adjust the stack. We will
|
|
|
|
* pick up the stack depths as we go through the decomposed version.
|
|
|
|
*/
|
|
|
|
if (!(js_CodeSpec[op].format & JOF_DECOMPOSE)) {
|
|
|
|
unsigned nuses = GetUseCount(script, offset);
|
|
|
|
unsigned ndefs = GetDefCount(script, offset);
|
2010-10-26 12:00:54 -07:00
|
|
|
|
2011-07-16 08:25:22 -07:00
|
|
|
JS_ASSERT(stackDepth >= nuses);
|
|
|
|
stackDepth -= nuses;
|
|
|
|
stackDepth += ndefs;
|
|
|
|
}
|
2010-10-26 12:00:54 -07:00
|
|
|
|
2011-07-28 09:16:53 -07:00
|
|
|
/*
|
|
|
|
* Assign an observed type set to each reachable JOF_TYPESET opcode.
|
|
|
|
* This may be less than the number of type sets in the script if some
|
|
|
|
* are unreachable, and may be greater in case the number of type sets
|
|
|
|
* overflows a uint16. In the latter case a single type set will be
|
|
|
|
* used for the observed types of all ops after the overflow.
|
|
|
|
*/
|
|
|
|
if ((js_CodeSpec[op].format & JOF_TYPESET) && cx->typeInferenceEnabled()) {
|
|
|
|
if (nTypeSets < script->nTypeSets) {
|
|
|
|
code->observedTypes = &typeArray[nTypeSets++];
|
|
|
|
} else {
|
|
|
|
JS_ASSERT(nTypeSets == UINT16_MAX);
|
|
|
|
code->observedTypes = &typeArray[nTypeSets - 1];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-10-26 12:00:54 -07:00
|
|
|
switch (op) {
|
|
|
|
|
2011-05-05 13:59:29 -07:00
|
|
|
case JSOP_RETURN:
|
|
|
|
case JSOP_STOP:
|
|
|
|
numReturnSites_++;
|
|
|
|
break;
|
|
|
|
|
2010-10-26 12:00:54 -07:00
|
|
|
case JSOP_SETRVAL:
|
|
|
|
case JSOP_POPV:
|
2011-09-01 12:20:30 -07:00
|
|
|
usesReturnValue_ = true;
|
2011-03-26 19:07:13 -07:00
|
|
|
isInlineable = false;
|
2010-10-26 12:00:54 -07:00
|
|
|
break;
|
|
|
|
|
2012-02-22 10:57:00 -08:00
|
|
|
case JSOP_QNAMEPART:
|
|
|
|
case JSOP_QNAMECONST:
|
2012-05-03 03:13:44 -07:00
|
|
|
isJaegerCompileable = false;
|
|
|
|
/* FALL THROUGH */
|
2010-10-26 12:00:54 -07:00
|
|
|
case JSOP_NAME:
|
|
|
|
case JSOP_CALLNAME:
|
|
|
|
case JSOP_BINDNAME:
|
|
|
|
case JSOP_SETNAME:
|
|
|
|
case JSOP_DELNAME:
|
2011-09-01 12:20:30 -07:00
|
|
|
usesScopeChain_ = true;
|
2011-03-26 19:07:13 -07:00
|
|
|
isInlineable = false;
|
|
|
|
break;
|
|
|
|
|
2012-03-24 12:29:36 -07:00
|
|
|
case JSOP_GETALIASEDVAR:
|
|
|
|
case JSOP_CALLALIASEDVAR:
|
2012-04-11 18:09:20 -07:00
|
|
|
case JSOP_SETALIASEDVAR: {
|
2012-03-24 12:29:36 -07:00
|
|
|
JS_ASSERT(!isInlineable);
|
|
|
|
usesScopeChain_ = true;
|
|
|
|
break;
|
2012-04-11 18:09:20 -07:00
|
|
|
}
|
2012-03-24 12:29:36 -07:00
|
|
|
|
2011-04-22 07:59:45 -07:00
|
|
|
case JSOP_DEFFUN:
|
|
|
|
case JSOP_DEFVAR:
|
|
|
|
case JSOP_DEFCONST:
|
|
|
|
case JSOP_SETCONST:
|
2011-09-01 12:20:30 -07:00
|
|
|
extendsScope_ = true;
|
|
|
|
isInlineable = canTrackVars = false;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case JSOP_EVAL:
|
|
|
|
extendsScope_ = true;
|
|
|
|
isInlineable = canTrackVars = false;
|
|
|
|
break;
|
2011-06-08 17:35:11 -07:00
|
|
|
|
2011-04-24 09:26:37 -07:00
|
|
|
case JSOP_ENTERWITH:
|
2011-09-01 12:20:30 -07:00
|
|
|
addsScopeObjects_ = true;
|
2012-05-03 03:13:44 -07:00
|
|
|
isJaegerCompileable = isInlineable = canTrackVars = false;
|
2011-04-22 07:59:45 -07:00
|
|
|
break;
|
|
|
|
|
2011-10-07 12:02:50 -07:00
|
|
|
case JSOP_ENTERLET0:
|
|
|
|
case JSOP_ENTERLET1:
|
2011-09-01 12:20:30 -07:00
|
|
|
case JSOP_ENTERBLOCK:
|
|
|
|
case JSOP_LEAVEBLOCK:
|
|
|
|
addsScopeObjects_ = true;
|
|
|
|
isInlineable = false;
|
|
|
|
break;
|
|
|
|
|
2011-03-26 19:07:13 -07:00
|
|
|
case JSOP_THIS:
|
2011-09-01 12:20:30 -07:00
|
|
|
usesThisValue_ = true;
|
2010-10-26 12:00:54 -07:00
|
|
|
break;
|
|
|
|
|
2011-03-27 07:48:03 -07:00
|
|
|
case JSOP_CALL:
|
|
|
|
case JSOP_NEW:
|
|
|
|
/* Only consider potentially inlineable calls here. */
|
2011-09-01 12:20:30 -07:00
|
|
|
hasFunctionCalls_ = true;
|
2011-03-27 07:48:03 -07:00
|
|
|
break;
|
|
|
|
|
2012-01-09 11:05:06 -08:00
|
|
|
case JSOP_TABLESWITCH: {
|
2011-12-24 06:21:52 -08:00
|
|
|
isInlineable = false;
|
2012-01-09 11:05:06 -08:00
|
|
|
unsigned defaultOffset = offset + GET_JUMP_OFFSET(pc);
|
|
|
|
jsbytecode *pc2 = pc + JUMP_OFFSET_LEN;
|
2012-03-01 18:54:01 -08:00
|
|
|
int32_t low = GET_JUMP_OFFSET(pc2);
|
2010-10-26 12:00:54 -07:00
|
|
|
pc2 += JUMP_OFFSET_LEN;
|
2012-03-01 18:54:01 -08:00
|
|
|
int32_t high = GET_JUMP_OFFSET(pc2);
|
2010-10-26 12:00:54 -07:00
|
|
|
pc2 += JUMP_OFFSET_LEN;
|
|
|
|
|
2012-03-21 06:37:43 -07:00
|
|
|
if (!addJump(cx, defaultOffset, &nextOffset, &forwardJump, &forwardLoop, stackDepth))
|
2010-10-26 12:00:54 -07:00
|
|
|
return;
|
2010-12-06 11:53:53 -08:00
|
|
|
getCode(defaultOffset).switchTarget = true;
|
2010-12-20 09:06:43 -08:00
|
|
|
getCode(defaultOffset).safePoint = true;
|
2010-10-26 12:00:54 -07:00
|
|
|
|
2012-03-01 18:54:01 -08:00
|
|
|
for (int32_t i = low; i <= high; i++) {
|
2012-01-09 11:05:06 -08:00
|
|
|
unsigned targetOffset = offset + GET_JUMP_OFFSET(pc2);
|
2010-10-26 12:00:54 -07:00
|
|
|
if (targetOffset != offset) {
|
2012-03-21 06:37:43 -07:00
|
|
|
if (!addJump(cx, targetOffset, &nextOffset, &forwardJump, &forwardLoop, stackDepth))
|
2010-10-26 12:00:54 -07:00
|
|
|
return;
|
|
|
|
}
|
2010-12-06 11:53:53 -08:00
|
|
|
getCode(targetOffset).switchTarget = true;
|
2010-12-20 09:06:43 -08:00
|
|
|
getCode(targetOffset).safePoint = true;
|
2012-01-09 11:05:06 -08:00
|
|
|
pc2 += JUMP_OFFSET_LEN;
|
2010-10-26 12:00:54 -07:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2012-01-09 11:05:06 -08:00
|
|
|
case JSOP_LOOKUPSWITCH: {
|
2011-12-24 06:21:52 -08:00
|
|
|
isInlineable = false;
|
2012-01-09 11:05:06 -08:00
|
|
|
unsigned defaultOffset = offset + GET_JUMP_OFFSET(pc);
|
|
|
|
jsbytecode *pc2 = pc + JUMP_OFFSET_LEN;
|
2010-10-26 12:00:54 -07:00
|
|
|
unsigned npairs = GET_UINT16(pc2);
|
|
|
|
pc2 += UINT16_LEN;
|
|
|
|
|
2012-03-21 06:37:43 -07:00
|
|
|
if (!addJump(cx, defaultOffset, &nextOffset, &forwardJump, &forwardLoop, stackDepth))
|
2010-10-26 12:00:54 -07:00
|
|
|
return;
|
2010-12-06 11:53:53 -08:00
|
|
|
getCode(defaultOffset).switchTarget = true;
|
2010-12-20 09:06:43 -08:00
|
|
|
getCode(defaultOffset).safePoint = true;
|
2010-10-26 12:00:54 -07:00
|
|
|
|
|
|
|
while (npairs) {
|
2012-02-03 18:53:29 -08:00
|
|
|
pc2 += UINT32_INDEX_LEN;
|
2012-01-09 11:05:06 -08:00
|
|
|
unsigned targetOffset = offset + GET_JUMP_OFFSET(pc2);
|
2012-03-21 06:37:43 -07:00
|
|
|
if (!addJump(cx, targetOffset, &nextOffset, &forwardJump, &forwardLoop, stackDepth))
|
2010-10-26 12:00:54 -07:00
|
|
|
return;
|
2010-12-06 11:53:53 -08:00
|
|
|
getCode(targetOffset).switchTarget = true;
|
2010-12-20 09:06:43 -08:00
|
|
|
getCode(targetOffset).safePoint = true;
|
2012-01-09 11:05:06 -08:00
|
|
|
pc2 += JUMP_OFFSET_LEN;
|
2010-10-26 12:00:54 -07:00
|
|
|
npairs--;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
case JSOP_TRY: {
|
|
|
|
/*
|
|
|
|
* Everything between a try and corresponding catch or finally is conditional.
|
|
|
|
* Note that there is no problem with code which is skipped by a thrown
|
|
|
|
* exception but is not caught by a later handler in the same function:
|
|
|
|
* no more code will execute, and it does not matter what is defined.
|
|
|
|
*/
|
2011-12-24 06:21:52 -08:00
|
|
|
isInlineable = false;
|
2010-10-26 12:00:54 -07:00
|
|
|
JSTryNote *tn = script->trynotes()->vector;
|
|
|
|
JSTryNote *tnlimit = tn + script->trynotes()->length;
|
|
|
|
for (; tn < tnlimit; tn++) {
|
2011-08-09 01:51:59 -07:00
|
|
|
unsigned startOffset = script->mainOffset + tn->start;
|
2010-10-26 12:00:54 -07:00
|
|
|
if (startOffset == offset + 1) {
|
|
|
|
unsigned catchOffset = startOffset + tn->length;
|
|
|
|
|
|
|
|
/* This will overestimate try block code, for multiple catch/finally. */
|
|
|
|
if (catchOffset > forwardCatch)
|
|
|
|
forwardCatch = catchOffset;
|
|
|
|
|
|
|
|
if (tn->kind != JSTRY_ITER) {
|
2012-03-21 06:37:43 -07:00
|
|
|
if (!addJump(cx, catchOffset, &nextOffset, &forwardJump, &forwardLoop, stackDepth))
|
2010-10-26 12:00:54 -07:00
|
|
|
return;
|
2010-10-29 08:05:55 -07:00
|
|
|
getCode(catchOffset).exceptionEntry = true;
|
2010-12-20 09:06:43 -08:00
|
|
|
getCode(catchOffset).safePoint = true;
|
2010-10-26 12:00:54 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2011-05-20 23:24:09 -07:00
|
|
|
case JSOP_GETLOCAL: {
|
2010-10-26 12:00:54 -07:00
|
|
|
/*
|
|
|
|
* Watch for uses of variables not known to be defined, and mark
|
|
|
|
* them as having possible uses before definitions. Ignore GETLOCAL
|
|
|
|
* followed by a POP, these are generated for, e.g. 'var x;'
|
|
|
|
*/
|
2011-05-20 23:24:09 -07:00
|
|
|
jsbytecode *next = pc + JSOP_GETLOCAL_LENGTH;
|
|
|
|
if (JSOp(*next) != JSOP_POP || jumpTarget(next)) {
|
Bug 708735 - Use <stdint.h> types in JSAPI and throughout SpiderMonkey. Continue to provide the {u,}int{8,16,32,64} and JS{Uint,Int}{8,16,32,64} integer types through a single header, however, for a simpler backout strategy -- and also to ease the transition for embedders. r=timeless on switching the jsd API to use the <stdint.h> types, r=luke, r=dmandelin
2011-12-08 19:54:10 -08:00
|
|
|
uint32_t local = GET_SLOTNO(pc);
|
2011-08-09 19:02:24 -07:00
|
|
|
if (local >= script->nfixed) {
|
|
|
|
localsAliasStack_ = true;
|
|
|
|
break;
|
|
|
|
}
|
2010-10-26 12:00:54 -07:00
|
|
|
}
|
|
|
|
break;
|
2011-05-20 23:24:09 -07:00
|
|
|
}
|
2010-10-26 12:00:54 -07:00
|
|
|
|
|
|
|
case JSOP_CALLLOCAL:
|
|
|
|
case JSOP_INCLOCAL:
|
|
|
|
case JSOP_DECLOCAL:
|
|
|
|
case JSOP_LOCALINC:
|
2011-10-29 17:30:08 -07:00
|
|
|
case JSOP_LOCALDEC:
|
2012-03-26 22:29:55 -07:00
|
|
|
case JSOP_SETLOCAL: {
|
Bug 708735 - Use <stdint.h> types in JSAPI and throughout SpiderMonkey. Continue to provide the {u,}int{8,16,32,64} and JS{Uint,Int}{8,16,32,64} integer types through a single header, however, for a simpler backout strategy -- and also to ease the transition for embedders. r=timeless on switching the jsd API to use the <stdint.h> types, r=luke, r=dmandelin
2011-12-08 19:54:10 -08:00
|
|
|
uint32_t local = GET_SLOTNO(pc);
|
2011-08-09 19:02:24 -07:00
|
|
|
if (local >= script->nfixed) {
|
|
|
|
localsAliasStack_ = true;
|
|
|
|
break;
|
|
|
|
}
|
2010-10-26 12:00:54 -07:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2011-03-26 19:07:13 -07:00
|
|
|
case JSOP_SETARG:
|
|
|
|
case JSOP_INCARG:
|
|
|
|
case JSOP_DECARG:
|
|
|
|
case JSOP_ARGINC:
|
|
|
|
case JSOP_ARGDEC:
|
2011-05-26 12:28:19 -07:00
|
|
|
modifiesArguments_ = true;
|
|
|
|
isInlineable = false;
|
|
|
|
break;
|
|
|
|
|
|
|
|
/* Additional opcodes which can be compiled but which can't be inlined. */
|
|
|
|
case JSOP_ARGUMENTS:
|
2011-03-26 19:07:13 -07:00
|
|
|
case JSOP_THROW:
|
|
|
|
case JSOP_EXCEPTION:
|
|
|
|
case JSOP_LAMBDA:
|
|
|
|
case JSOP_DEBUGGER:
|
|
|
|
case JSOP_FUNCALL:
|
|
|
|
case JSOP_FUNAPPLY:
|
|
|
|
isInlineable = false;
|
|
|
|
break;
|
|
|
|
|
2012-02-22 10:57:00 -08:00
|
|
|
/* Additional opcodes which can be both compiled both normally and inline. */
|
|
|
|
case JSOP_NOP:
|
|
|
|
case JSOP_UNDEFINED:
|
|
|
|
case JSOP_GOTO:
|
|
|
|
case JSOP_DEFAULT:
|
|
|
|
case JSOP_IFEQ:
|
|
|
|
case JSOP_IFNE:
|
|
|
|
case JSOP_ITERNEXT:
|
|
|
|
case JSOP_DUP:
|
|
|
|
case JSOP_DUP2:
|
|
|
|
case JSOP_SWAP:
|
|
|
|
case JSOP_PICK:
|
|
|
|
case JSOP_BITOR:
|
|
|
|
case JSOP_BITXOR:
|
|
|
|
case JSOP_BITAND:
|
|
|
|
case JSOP_LT:
|
|
|
|
case JSOP_LE:
|
|
|
|
case JSOP_GT:
|
|
|
|
case JSOP_GE:
|
|
|
|
case JSOP_EQ:
|
|
|
|
case JSOP_NE:
|
|
|
|
case JSOP_LSH:
|
|
|
|
case JSOP_RSH:
|
|
|
|
case JSOP_URSH:
|
|
|
|
case JSOP_ADD:
|
|
|
|
case JSOP_SUB:
|
|
|
|
case JSOP_MUL:
|
|
|
|
case JSOP_DIV:
|
|
|
|
case JSOP_MOD:
|
|
|
|
case JSOP_NOT:
|
|
|
|
case JSOP_BITNOT:
|
|
|
|
case JSOP_NEG:
|
|
|
|
case JSOP_POS:
|
|
|
|
case JSOP_DELPROP:
|
|
|
|
case JSOP_DELELEM:
|
|
|
|
case JSOP_TYPEOF:
|
|
|
|
case JSOP_TYPEOFEXPR:
|
|
|
|
case JSOP_VOID:
|
|
|
|
case JSOP_GETPROP:
|
|
|
|
case JSOP_CALLPROP:
|
|
|
|
case JSOP_LENGTH:
|
|
|
|
case JSOP_GETELEM:
|
|
|
|
case JSOP_CALLELEM:
|
|
|
|
case JSOP_TOID:
|
|
|
|
case JSOP_SETELEM:
|
|
|
|
case JSOP_IMPLICITTHIS:
|
|
|
|
case JSOP_DOUBLE:
|
|
|
|
case JSOP_STRING:
|
|
|
|
case JSOP_ZERO:
|
|
|
|
case JSOP_ONE:
|
|
|
|
case JSOP_NULL:
|
|
|
|
case JSOP_FALSE:
|
|
|
|
case JSOP_TRUE:
|
|
|
|
case JSOP_OR:
|
|
|
|
case JSOP_AND:
|
|
|
|
case JSOP_CASE:
|
|
|
|
case JSOP_STRICTEQ:
|
|
|
|
case JSOP_STRICTNE:
|
|
|
|
case JSOP_ITER:
|
|
|
|
case JSOP_MOREITER:
|
|
|
|
case JSOP_ENDITER:
|
|
|
|
case JSOP_POP:
|
|
|
|
case JSOP_GETARG:
|
|
|
|
case JSOP_CALLARG:
|
|
|
|
case JSOP_BINDGNAME:
|
|
|
|
case JSOP_UINT16:
|
|
|
|
case JSOP_NEWINIT:
|
|
|
|
case JSOP_NEWARRAY:
|
|
|
|
case JSOP_NEWOBJECT:
|
|
|
|
case JSOP_ENDINIT:
|
|
|
|
case JSOP_INITPROP:
|
|
|
|
case JSOP_INITELEM:
|
|
|
|
case JSOP_SETPROP:
|
|
|
|
case JSOP_IN:
|
|
|
|
case JSOP_INSTANCEOF:
|
|
|
|
case JSOP_LINENO:
|
|
|
|
case JSOP_ENUMELEM:
|
|
|
|
case JSOP_CONDSWITCH:
|
|
|
|
case JSOP_LABEL:
|
|
|
|
case JSOP_RETRVAL:
|
|
|
|
case JSOP_GETGNAME:
|
|
|
|
case JSOP_CALLGNAME:
|
|
|
|
case JSOP_SETGNAME:
|
|
|
|
case JSOP_REGEXP:
|
|
|
|
case JSOP_OBJECT:
|
|
|
|
case JSOP_UINT24:
|
|
|
|
case JSOP_GETXPROP:
|
|
|
|
case JSOP_INT8:
|
|
|
|
case JSOP_INT32:
|
|
|
|
case JSOP_HOLE:
|
|
|
|
case JSOP_LOOPHEAD:
|
|
|
|
case JSOP_LOOPENTRY:
|
2012-06-02 11:16:24 -07:00
|
|
|
case JSOP_ACTUALSFILLED:
|
2012-02-22 10:57:00 -08:00
|
|
|
break;
|
|
|
|
|
2010-10-26 12:00:54 -07:00
|
|
|
default:
|
2012-02-22 12:57:25 -08:00
|
|
|
if (!(js_CodeSpec[op].format & JOF_DECOMPOSE))
|
2012-05-03 03:13:44 -07:00
|
|
|
isJaegerCompileable = isInlineable = false;
|
2010-10-26 12:00:54 -07:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
Bug 708735 - Use <stdint.h> types in JSAPI and throughout SpiderMonkey. Continue to provide the {u,}int{8,16,32,64} and JS{Uint,Int}{8,16,32,64} integer types through a single header, however, for a simpler backout strategy -- and also to ease the transition for embedders. r=timeless on switching the jsd API to use the <stdint.h> types, r=luke, r=dmandelin
2011-12-08 19:54:10 -08:00
|
|
|
uint32_t type = JOF_TYPE(js_CodeSpec[op].format);
|
2010-10-26 12:00:54 -07:00
|
|
|
|
|
|
|
/* Check basic jump opcodes, which may or may not have a fallthrough. */
|
2012-01-09 11:05:06 -08:00
|
|
|
if (type == JOF_JUMP) {
|
2010-10-26 12:00:54 -07:00
|
|
|
/* Some opcodes behave differently on their branching path. */
|
2010-10-29 08:05:55 -07:00
|
|
|
unsigned newStackDepth = stackDepth;
|
2010-10-26 12:00:54 -07:00
|
|
|
|
|
|
|
switch (op) {
|
|
|
|
case JSOP_CASE:
|
|
|
|
/* Case instructions do not push the lvalue back when branching. */
|
2010-10-29 08:05:55 -07:00
|
|
|
newStackDepth--;
|
2010-10-26 12:00:54 -07:00
|
|
|
break;
|
|
|
|
|
2010-10-29 08:05:55 -07:00
|
|
|
default:;
|
2010-10-26 12:00:54 -07:00
|
|
|
}
|
|
|
|
|
2012-01-09 11:05:06 -08:00
|
|
|
unsigned targetOffset = offset + GET_JUMP_OFFSET(pc);
|
2012-03-21 06:37:43 -07:00
|
|
|
if (!addJump(cx, targetOffset, &nextOffset, &forwardJump, &forwardLoop, newStackDepth))
|
2010-10-26 12:00:54 -07:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Handle any fallthrough from this opcode. */
|
|
|
|
if (!BytecodeNoFallThrough(op)) {
|
|
|
|
JS_ASSERT(successorOffset < script->length);
|
|
|
|
|
2010-10-29 08:05:55 -07:00
|
|
|
Bytecode *&nextcode = codeArray[successorOffset];
|
2010-10-26 12:00:54 -07:00
|
|
|
|
2011-10-29 17:30:08 -07:00
|
|
|
if (!nextcode) {
|
2011-09-22 13:22:30 -07:00
|
|
|
nextcode = tla.new_<Bytecode>();
|
2010-10-26 12:00:54 -07:00
|
|
|
if (!nextcode) {
|
|
|
|
setOOM(cx);
|
|
|
|
return;
|
|
|
|
}
|
2011-10-29 17:30:08 -07:00
|
|
|
nextcode->stackDepth = stackDepth;
|
2010-10-26 12:00:54 -07:00
|
|
|
}
|
2011-10-29 17:30:08 -07:00
|
|
|
JS_ASSERT(nextcode->stackDepth == stackDepth);
|
2010-10-26 12:00:54 -07:00
|
|
|
|
2012-01-09 11:05:06 -08:00
|
|
|
if (type == JOF_JUMP)
|
2010-12-06 11:53:53 -08:00
|
|
|
nextcode->jumpFallthrough = true;
|
|
|
|
|
2010-11-12 06:25:52 -08:00
|
|
|
/* Treat the fallthrough of a branch instruction as a jump target. */
|
2012-01-09 11:05:06 -08:00
|
|
|
if (type == JOF_JUMP)
|
2010-11-12 06:25:52 -08:00
|
|
|
nextcode->jumpTarget = true;
|
|
|
|
else
|
|
|
|
nextcode->fallthrough = true;
|
2010-10-26 12:00:54 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
JS_ASSERT(!failed());
|
2012-03-21 06:37:43 -07:00
|
|
|
JS_ASSERT(forwardJump == 0 && forwardLoop == 0 && forwardCatch == 0);
|
2011-04-16 06:54:01 -07:00
|
|
|
|
2011-04-22 07:59:45 -07:00
|
|
|
ranBytecode_ = true;
|
2012-01-17 16:35:12 -08:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Always ensure that a script's arguments usage has been analyzed before
|
|
|
|
* entering the script. This allows the functionPrologue to ensure that
|
|
|
|
* arguments are always created eagerly which simplifies interp logic.
|
|
|
|
*/
|
2012-04-02 08:58:30 -07:00
|
|
|
if (!script->analyzedArgsUsage())
|
|
|
|
analyzeSSA(cx);
|
2011-04-16 06:54:01 -07:00
|
|
|
}
|
|
|
|
|
2010-12-06 11:53:53 -08:00
|
|
|
/////////////////////////////////////////////////////////////////////
|
2011-04-22 07:59:45 -07:00
|
|
|
// Lifetime Analysis
|
2010-12-06 11:53:53 -08:00
|
|
|
/////////////////////////////////////////////////////////////////////
|
|
|
|
|
2011-04-22 07:59:45 -07:00
|
|
|
void
|
|
|
|
ScriptAnalysis::analyzeLifetimes(JSContext *cx)
|
2010-12-06 11:53:53 -08:00
|
|
|
{
|
2011-04-22 07:59:45 -07:00
|
|
|
JS_ASSERT(cx->compartment->activeAnalysis && !ranLifetimes() && !failed());
|
2011-03-26 19:07:13 -07:00
|
|
|
|
2011-04-22 07:59:45 -07:00
|
|
|
if (!ranBytecode()) {
|
|
|
|
analyzeBytecode(cx);
|
|
|
|
if (failed())
|
|
|
|
return;
|
|
|
|
}
|
2011-04-05 18:12:03 -07:00
|
|
|
|
2011-09-22 13:22:30 -07:00
|
|
|
LifoAlloc &tla = cx->typeLifoAlloc();
|
2010-12-06 11:53:53 -08:00
|
|
|
|
2011-09-22 13:22:30 -07:00
|
|
|
lifetimes = tla.newArray<LifetimeVariable>(numSlots);
|
2011-04-22 07:59:45 -07:00
|
|
|
if (!lifetimes) {
|
|
|
|
setOOM(cx);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
PodZero(lifetimes, numSlots);
|
2010-12-06 11:53:53 -08:00
|
|
|
|
2011-04-22 07:59:45 -07:00
|
|
|
/*
|
|
|
|
* Variables which are currently dead. On forward branches to locations
|
|
|
|
* where these are live, they need to be marked as live.
|
|
|
|
*/
|
|
|
|
LifetimeVariable **saved = (LifetimeVariable **)
|
|
|
|
cx->calloc_(numSlots * sizeof(LifetimeVariable*));
|
|
|
|
if (!saved) {
|
|
|
|
setOOM(cx);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
unsigned savedCount = 0;
|
2010-12-06 11:53:53 -08:00
|
|
|
|
2011-04-22 07:59:45 -07:00
|
|
|
LoopAnalysis *loop = NULL;
|
2011-04-05 18:12:03 -07:00
|
|
|
|
Bug 708735 - Use <stdint.h> types in JSAPI and throughout SpiderMonkey. Continue to provide the {u,}int{8,16,32,64} and JS{Uint,Int}{8,16,32,64} integer types through a single header, however, for a simpler backout strategy -- and also to ease the transition for embedders. r=timeless on switching the jsd API to use the <stdint.h> types, r=luke, r=dmandelin
2011-12-08 19:54:10 -08:00
|
|
|
uint32_t offset = script->length - 1;
|
2010-12-06 11:53:53 -08:00
|
|
|
while (offset < script->length) {
|
2011-04-22 07:59:45 -07:00
|
|
|
Bytecode *code = maybeCode(offset);
|
2010-12-06 11:53:53 -08:00
|
|
|
if (!code) {
|
|
|
|
offset--;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2011-04-05 18:12:03 -07:00
|
|
|
if (loop && code->safePoint)
|
|
|
|
loop->hasSafePoints = true;
|
|
|
|
|
2011-05-19 10:09:17 -07:00
|
|
|
jsbytecode *pc = script->code + offset;
|
|
|
|
|
|
|
|
JSOp op = (JSOp) *pc;
|
2010-12-06 11:53:53 -08:00
|
|
|
|
2011-12-01 15:13:51 -08:00
|
|
|
if (op == JSOP_LOOPHEAD && code->loop) {
|
2010-12-06 11:53:53 -08:00
|
|
|
/*
|
|
|
|
* This is the head of a loop, we need to go and make sure that any
|
|
|
|
* variables live at the head are live at the backedge and points prior.
|
|
|
|
* For each such variable, look for the last lifetime segment in the body
|
|
|
|
* and extend it to the end of the loop.
|
|
|
|
*/
|
2011-04-22 07:59:45 -07:00
|
|
|
JS_ASSERT(loop == code->loop);
|
|
|
|
unsigned backedge = code->loop->backedge;
|
|
|
|
for (unsigned i = 0; i < numSlots; i++) {
|
|
|
|
if (lifetimes[i].lifetime)
|
|
|
|
extendVariable(cx, lifetimes[i], offset, backedge);
|
2010-12-06 11:53:53 -08:00
|
|
|
}
|
2011-04-05 18:12:03 -07:00
|
|
|
|
2011-04-06 14:04:24 -07:00
|
|
|
loop = loop->parent;
|
|
|
|
JS_ASSERT_IF(loop, loop->head < offset);
|
2010-12-06 11:53:53 -08:00
|
|
|
}
|
|
|
|
|
2011-04-05 18:12:03 -07:00
|
|
|
/* Find the last jump target in the loop, other than the initial entry point. */
|
|
|
|
if (loop && code->jumpTarget && offset != loop->entry && offset > loop->lastBlock)
|
|
|
|
loop->lastBlock = offset;
|
|
|
|
|
2011-07-22 11:53:18 -07:00
|
|
|
if (code->exceptionEntry) {
|
2011-08-15 11:41:52 -07:00
|
|
|
DebugOnly<bool> found = false;
|
2011-07-22 11:53:18 -07:00
|
|
|
JSTryNote *tn = script->trynotes()->vector;
|
|
|
|
JSTryNote *tnlimit = tn + script->trynotes()->length;
|
|
|
|
for (; tn < tnlimit; tn++) {
|
2011-08-09 01:51:59 -07:00
|
|
|
unsigned startOffset = script->mainOffset + tn->start;
|
2011-07-22 11:53:18 -07:00
|
|
|
if (startOffset + tn->length == offset) {
|
2011-07-22 12:47:16 -07:00
|
|
|
/*
|
|
|
|
* Extend all live variables at exception entry to the start of
|
|
|
|
* the try block.
|
|
|
|
*/
|
|
|
|
for (unsigned i = 0; i < numSlots; i++) {
|
|
|
|
if (lifetimes[i].lifetime)
|
|
|
|
ensureVariable(lifetimes[i], startOffset - 1);
|
|
|
|
}
|
|
|
|
|
|
|
|
found = true;
|
2011-07-22 11:53:18 -07:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2011-07-22 12:47:16 -07:00
|
|
|
JS_ASSERT(found);
|
2011-07-22 11:53:18 -07:00
|
|
|
}
|
|
|
|
|
2010-12-06 11:53:53 -08:00
|
|
|
switch (op) {
|
|
|
|
case JSOP_GETARG:
|
2011-04-22 07:59:45 -07:00
|
|
|
case JSOP_CALLARG:
|
2010-12-06 11:53:53 -08:00
|
|
|
case JSOP_GETLOCAL:
|
2011-04-22 07:59:45 -07:00
|
|
|
case JSOP_CALLLOCAL:
|
|
|
|
case JSOP_THIS: {
|
Bug 708735 - Use <stdint.h> types in JSAPI and throughout SpiderMonkey. Continue to provide the {u,}int{8,16,32,64} and JS{Uint,Int}{8,16,32,64} integer types through a single header, however, for a simpler backout strategy -- and also to ease the transition for embedders. r=timeless on switching the jsd API to use the <stdint.h> types, r=luke, r=dmandelin
2011-12-08 19:54:10 -08:00
|
|
|
uint32_t slot = GetBytecodeSlot(script, pc);
|
2011-04-22 07:59:45 -07:00
|
|
|
if (!slotEscapes(slot))
|
|
|
|
addVariable(cx, lifetimes[slot], offset, saved, savedCount);
|
2010-12-06 11:53:53 -08:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2011-04-22 07:59:45 -07:00
|
|
|
case JSOP_SETARG:
|
2012-03-26 22:29:55 -07:00
|
|
|
case JSOP_SETLOCAL: {
|
Bug 708735 - Use <stdint.h> types in JSAPI and throughout SpiderMonkey. Continue to provide the {u,}int{8,16,32,64} and JS{Uint,Int}{8,16,32,64} integer types through a single header, however, for a simpler backout strategy -- and also to ease the transition for embedders. r=timeless on switching the jsd API to use the <stdint.h> types, r=luke, r=dmandelin
2011-12-08 19:54:10 -08:00
|
|
|
uint32_t slot = GetBytecodeSlot(script, pc);
|
2011-04-22 07:59:45 -07:00
|
|
|
if (!slotEscapes(slot))
|
|
|
|
killVariable(cx, lifetimes[slot], offset, saved, savedCount);
|
2011-04-05 18:12:03 -07:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2011-04-22 07:59:45 -07:00
|
|
|
case JSOP_INCARG:
|
|
|
|
case JSOP_DECARG:
|
|
|
|
case JSOP_ARGINC:
|
|
|
|
case JSOP_ARGDEC:
|
2011-04-05 18:12:03 -07:00
|
|
|
case JSOP_INCLOCAL:
|
|
|
|
case JSOP_DECLOCAL:
|
|
|
|
case JSOP_LOCALINC:
|
|
|
|
case JSOP_LOCALDEC: {
|
Bug 708735 - Use <stdint.h> types in JSAPI and throughout SpiderMonkey. Continue to provide the {u,}int{8,16,32,64} and JS{Uint,Int}{8,16,32,64} integer types through a single header, however, for a simpler backout strategy -- and also to ease the transition for embedders. r=timeless on switching the jsd API to use the <stdint.h> types, r=luke, r=dmandelin
2011-12-08 19:54:10 -08:00
|
|
|
uint32_t slot = GetBytecodeSlot(script, pc);
|
2011-04-22 07:59:45 -07:00
|
|
|
if (!slotEscapes(slot)) {
|
|
|
|
killVariable(cx, lifetimes[slot], offset, saved, savedCount);
|
|
|
|
addVariable(cx, lifetimes[slot], offset, saved, savedCount);
|
2011-03-20 08:23:27 -07:00
|
|
|
}
|
2010-12-06 11:53:53 -08:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2011-04-28 13:02:47 -07:00
|
|
|
case JSOP_LOOKUPSWITCH:
|
|
|
|
case JSOP_TABLESWITCH:
|
|
|
|
/* Restore all saved variables. :FIXME: maybe do this precisely. */
|
|
|
|
for (unsigned i = 0; i < savedCount; i++) {
|
|
|
|
LifetimeVariable &var = *saved[i];
|
2011-09-22 13:22:30 -07:00
|
|
|
var.lifetime = tla.new_<Lifetime>(offset, var.savedEnd, var.saved);
|
2011-04-28 13:02:47 -07:00
|
|
|
if (!var.lifetime) {
|
|
|
|
cx->free_(saved);
|
|
|
|
setOOM(cx);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
var.saved = NULL;
|
|
|
|
saved[i--] = saved[--savedCount];
|
|
|
|
}
|
|
|
|
savedCount = 0;
|
|
|
|
break;
|
|
|
|
|
2011-07-22 11:53:18 -07:00
|
|
|
case JSOP_TRY:
|
|
|
|
for (unsigned i = 0; i < numSlots; i++) {
|
|
|
|
LifetimeVariable &var = lifetimes[i];
|
|
|
|
if (var.ensured) {
|
|
|
|
JS_ASSERT(var.lifetime);
|
|
|
|
if (var.lifetime->start == offset)
|
|
|
|
var.ensured = false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
2011-04-28 13:02:47 -07:00
|
|
|
case JSOP_NEW:
|
|
|
|
case JSOP_CALL:
|
|
|
|
case JSOP_EVAL:
|
|
|
|
case JSOP_FUNAPPLY:
|
|
|
|
case JSOP_FUNCALL:
|
|
|
|
if (loop)
|
|
|
|
loop->hasCallsLoops = true;
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:;
|
|
|
|
}
|
|
|
|
|
Bug 708735 - Use <stdint.h> types in JSAPI and throughout SpiderMonkey. Continue to provide the {u,}int{8,16,32,64} and JS{Uint,Int}{8,16,32,64} integer types through a single header, however, for a simpler backout strategy -- and also to ease the transition for embedders. r=timeless on switching the jsd API to use the <stdint.h> types, r=luke, r=dmandelin
2011-12-08 19:54:10 -08:00
|
|
|
uint32_t type = JOF_TYPE(js_CodeSpec[op].format);
|
2012-01-09 11:05:06 -08:00
|
|
|
if (type == JOF_JUMP) {
|
2011-04-05 18:12:03 -07:00
|
|
|
/*
|
|
|
|
* Forward jumps need to pull in all variables which are live at
|
|
|
|
* their target offset --- the variables live before the jump are
|
|
|
|
* the union of those live at the fallthrough and at the target.
|
|
|
|
*/
|
Bug 708735 - Use <stdint.h> types in JSAPI and throughout SpiderMonkey. Continue to provide the {u,}int{8,16,32,64} and JS{Uint,Int}{8,16,32,64} integer types through a single header, however, for a simpler backout strategy -- and also to ease the transition for embedders. r=timeless on switching the jsd API to use the <stdint.h> types, r=luke, r=dmandelin
2011-12-08 19:54:10 -08:00
|
|
|
uint32_t targetOffset = FollowBranch(cx, script, offset);
|
2011-04-22 07:59:45 -07:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Watch for 'continue' statements in the loop body, which are
|
|
|
|
* jumps to the entry offset separate from the initial jump.
|
|
|
|
*/
|
|
|
|
if (loop && loop->entry == targetOffset && loop->entry > loop->lastBlock)
|
|
|
|
loop->lastBlock = loop->entry;
|
|
|
|
|
2010-12-06 11:53:53 -08:00
|
|
|
if (targetOffset < offset) {
|
2011-04-22 07:59:45 -07:00
|
|
|
/* This is a loop back edge, no lifetime to pull in yet. */
|
2011-04-27 23:28:54 -07:00
|
|
|
|
|
|
|
#ifdef DEBUG
|
2010-12-06 11:53:53 -08:00
|
|
|
JSOp nop = JSOp(script->code[targetOffset]);
|
2011-12-07 13:15:48 -08:00
|
|
|
JS_ASSERT(nop == JSOP_LOOPHEAD);
|
2011-04-27 23:28:54 -07:00
|
|
|
#endif
|
2011-04-05 18:12:03 -07:00
|
|
|
|
2011-04-22 07:59:45 -07:00
|
|
|
/*
|
|
|
|
* If we already have a loop, it is an outer loop and we
|
|
|
|
* need to prune the last block in the loop --- we do not
|
|
|
|
* track 'continue' statements for outer loops.
|
|
|
|
*/
|
|
|
|
if (loop && loop->entry > loop->lastBlock)
|
|
|
|
loop->lastBlock = loop->entry;
|
2011-04-05 18:12:03 -07:00
|
|
|
|
2011-09-22 13:22:30 -07:00
|
|
|
LoopAnalysis *nloop = tla.new_<LoopAnalysis>();
|
2011-04-22 07:59:45 -07:00
|
|
|
if (!nloop) {
|
|
|
|
cx->free_(saved);
|
|
|
|
setOOM(cx);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
PodZero(nloop);
|
2011-04-06 14:04:24 -07:00
|
|
|
|
2011-04-22 07:59:45 -07:00
|
|
|
if (loop)
|
|
|
|
loop->hasCallsLoops = true;
|
2011-04-07 16:12:37 -07:00
|
|
|
|
2011-04-22 07:59:45 -07:00
|
|
|
nloop->parent = loop;
|
|
|
|
loop = nloop;
|
2011-04-05 18:12:03 -07:00
|
|
|
|
2011-04-22 07:59:45 -07:00
|
|
|
getCode(targetOffset).loop = loop;
|
|
|
|
loop->head = targetOffset;
|
|
|
|
loop->backedge = offset;
|
|
|
|
loop->lastBlock = loop->head;
|
2011-04-05 18:12:03 -07:00
|
|
|
|
2011-04-22 07:59:45 -07:00
|
|
|
/*
|
|
|
|
* Find the entry jump, which will be a GOTO for 'for' or
|
|
|
|
* 'while' loops or a fallthrough for 'do while' loops.
|
|
|
|
*/
|
Bug 708735 - Use <stdint.h> types in JSAPI and throughout SpiderMonkey. Continue to provide the {u,}int{8,16,32,64} and JS{Uint,Int}{8,16,32,64} integer types through a single header, however, for a simpler backout strategy -- and also to ease the transition for embedders. r=timeless on switching the jsd API to use the <stdint.h> types, r=luke, r=dmandelin
2011-12-08 19:54:10 -08:00
|
|
|
uint32_t entry = targetOffset;
|
2011-04-22 07:59:45 -07:00
|
|
|
if (entry) {
|
|
|
|
do {
|
|
|
|
entry--;
|
|
|
|
} while (!maybeCode(entry));
|
|
|
|
|
|
|
|
jsbytecode *entrypc = script->code + entry;
|
2011-05-19 10:09:17 -07:00
|
|
|
|
2012-01-23 13:51:01 -08:00
|
|
|
if (JSOp(*entrypc) == JSOP_GOTO || JSOp(*entrypc) == JSOP_FILTER)
|
2012-01-09 11:05:06 -08:00
|
|
|
loop->entry = entry + GET_JUMP_OFFSET(entrypc);
|
2011-04-22 07:59:45 -07:00
|
|
|
else
|
2011-04-05 18:12:03 -07:00
|
|
|
loop->entry = targetOffset;
|
2011-04-22 07:59:45 -07:00
|
|
|
} else {
|
|
|
|
/* Do-while loop at the start of the script. */
|
|
|
|
loop->entry = targetOffset;
|
2010-12-06 11:53:53 -08:00
|
|
|
}
|
2012-01-23 13:51:01 -08:00
|
|
|
JS_ASSERT(script->code[loop->entry] == JSOP_LOOPHEAD ||
|
|
|
|
script->code[loop->entry] == JSOP_LOOPENTRY);
|
2011-04-28 13:02:47 -07:00
|
|
|
} else {
|
|
|
|
for (unsigned i = 0; i < savedCount; i++) {
|
|
|
|
LifetimeVariable &var = *saved[i];
|
|
|
|
JS_ASSERT(!var.lifetime && var.saved);
|
|
|
|
if (var.live(targetOffset)) {
|
|
|
|
/*
|
|
|
|
* Jumping to a place where this variable is live. Make a new
|
|
|
|
* lifetime segment for the variable.
|
|
|
|
*/
|
2011-09-22 13:22:30 -07:00
|
|
|
var.lifetime = tla.new_<Lifetime>(offset, var.savedEnd, var.saved);
|
2011-04-28 13:02:47 -07:00
|
|
|
if (!var.lifetime) {
|
|
|
|
cx->free_(saved);
|
|
|
|
setOOM(cx);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
var.saved = NULL;
|
|
|
|
saved[i--] = saved[--savedCount];
|
|
|
|
} else if (loop && !var.savedEnd) {
|
|
|
|
/*
|
|
|
|
* This jump precedes the basic block which killed the variable,
|
|
|
|
* remember it and use it for the end of the next lifetime
|
|
|
|
* segment should the variable become live again. This is needed
|
|
|
|
* for loops, as if we wrap liveness around the loop the isLive
|
|
|
|
* test below may have given the wrong answer.
|
|
|
|
*/
|
|
|
|
var.savedEnd = offset;
|
2011-04-22 07:59:45 -07:00
|
|
|
}
|
2010-12-06 11:53:53 -08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
offset--;
|
|
|
|
}
|
|
|
|
|
2011-04-22 07:59:45 -07:00
|
|
|
cx->free_(saved);
|
|
|
|
|
|
|
|
ranLifetimes_ = true;
|
2010-12-06 11:53:53 -08:00
|
|
|
}
|
|
|
|
|
2012-05-14 22:44:58 -07:00
|
|
|
#ifdef JS_METHODJIT_SPEW
|
2010-12-06 11:53:53 -08:00
|
|
|
void
|
2011-04-22 07:59:45 -07:00
|
|
|
LifetimeVariable::print() const
|
2010-12-06 11:53:53 -08:00
|
|
|
{
|
2011-04-22 07:59:45 -07:00
|
|
|
Lifetime *segment = lifetime ? lifetime : saved;
|
2010-12-06 11:53:53 -08:00
|
|
|
while (segment) {
|
|
|
|
printf(" (%u,%u%s)", segment->start, segment->end, segment->loopTail ? ",tail" : "");
|
|
|
|
segment = segment->next;
|
|
|
|
}
|
|
|
|
printf("\n");
|
|
|
|
}
|
|
|
|
#endif /* DEBUG */
|
|
|
|
|
2011-04-22 07:59:45 -07:00
|
|
|
inline void
|
|
|
|
ScriptAnalysis::addVariable(JSContext *cx, LifetimeVariable &var, unsigned offset,
|
|
|
|
LifetimeVariable **&saved, unsigned &savedCount)
|
2010-12-06 11:53:53 -08:00
|
|
|
{
|
|
|
|
if (var.lifetime) {
|
2011-07-22 11:53:18 -07:00
|
|
|
if (var.ensured)
|
|
|
|
return;
|
|
|
|
|
2010-12-06 11:53:53 -08:00
|
|
|
JS_ASSERT(offset < var.lifetime->start);
|
|
|
|
var.lifetime->start = offset;
|
|
|
|
} else {
|
|
|
|
if (var.saved) {
|
|
|
|
/* Remove from the list of saved entries. */
|
|
|
|
for (unsigned i = 0; i < savedCount; i++) {
|
|
|
|
if (saved[i] == &var) {
|
|
|
|
JS_ASSERT(savedCount);
|
|
|
|
saved[i--] = saved[--savedCount];
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2011-09-22 13:22:30 -07:00
|
|
|
var.lifetime = cx->typeLifoAlloc().new_<Lifetime>(offset, var.savedEnd, var.saved);
|
2011-04-22 07:59:45 -07:00
|
|
|
if (!var.lifetime) {
|
|
|
|
setOOM(cx);
|
|
|
|
return;
|
|
|
|
}
|
2010-12-06 11:53:53 -08:00
|
|
|
var.saved = NULL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-04-22 07:59:45 -07:00
|
|
|
inline void
|
|
|
|
ScriptAnalysis::killVariable(JSContext *cx, LifetimeVariable &var, unsigned offset,
|
|
|
|
LifetimeVariable **&saved, unsigned &savedCount)
|
2010-12-06 11:53:53 -08:00
|
|
|
{
|
2011-04-05 18:12:03 -07:00
|
|
|
if (!var.lifetime) {
|
|
|
|
/* Make a point lifetime indicating the write. */
|
2012-04-10 12:16:42 -07:00
|
|
|
Lifetime *lifetime = cx->typeLifoAlloc().new_<Lifetime>(offset, var.savedEnd, var.saved);
|
|
|
|
if (!lifetime) {
|
2011-04-22 07:59:45 -07:00
|
|
|
setOOM(cx);
|
|
|
|
return;
|
|
|
|
}
|
2012-04-10 12:16:42 -07:00
|
|
|
if (!var.saved)
|
|
|
|
saved[savedCount++] = &var;
|
|
|
|
var.saved = lifetime;
|
2011-04-05 18:12:03 -07:00
|
|
|
var.saved->write = true;
|
2011-04-19 06:39:49 -07:00
|
|
|
var.savedEnd = 0;
|
2011-04-22 07:59:45 -07:00
|
|
|
return;
|
2011-04-05 18:12:03 -07:00
|
|
|
}
|
2011-07-22 11:53:18 -07:00
|
|
|
|
2012-01-05 07:01:18 -08:00
|
|
|
JS_ASSERT_IF(!var.ensured, offset < var.lifetime->start);
|
|
|
|
unsigned start = var.lifetime->start;
|
2010-12-06 11:53:53 -08:00
|
|
|
|
|
|
|
/*
|
|
|
|
* The variable is considered to be live at the bytecode which kills it
|
|
|
|
* (just not at earlier bytecodes). This behavior is needed by downstream
|
|
|
|
* register allocation (see FrameState::bestEvictReg).
|
|
|
|
*/
|
|
|
|
var.lifetime->start = offset;
|
2011-04-05 18:12:03 -07:00
|
|
|
var.lifetime->write = true;
|
2010-12-06 11:53:53 -08:00
|
|
|
|
2012-01-05 07:01:18 -08:00
|
|
|
if (var.ensured) {
|
|
|
|
/*
|
|
|
|
* The variable is live even before the write, due to an enclosing try
|
|
|
|
* block. We need to split the lifetime to indicate there was a write.
|
2012-02-10 18:32:03 -08:00
|
|
|
* We set the new interval's savedEnd to 0, since it will always be
|
|
|
|
* adjacent to the old interval, so it never needs to be extended.
|
2012-01-05 07:01:18 -08:00
|
|
|
*/
|
2012-02-10 18:32:03 -08:00
|
|
|
var.lifetime = cx->typeLifoAlloc().new_<Lifetime>(start, 0, var.lifetime);
|
2012-01-05 07:01:18 -08:00
|
|
|
if (!var.lifetime) {
|
|
|
|
setOOM(cx);
|
|
|
|
return;
|
|
|
|
}
|
2012-02-10 18:32:03 -08:00
|
|
|
var.lifetime->end = offset;
|
2012-01-05 07:01:18 -08:00
|
|
|
} else {
|
|
|
|
var.saved = var.lifetime;
|
|
|
|
var.savedEnd = 0;
|
|
|
|
var.lifetime = NULL;
|
2010-12-06 11:53:53 -08:00
|
|
|
|
2012-01-05 07:01:18 -08:00
|
|
|
saved[savedCount++] = &var;
|
|
|
|
}
|
2010-12-06 11:53:53 -08:00
|
|
|
}
|
|
|
|
|
2011-04-22 07:59:45 -07:00
|
|
|
inline void
|
|
|
|
ScriptAnalysis::extendVariable(JSContext *cx, LifetimeVariable &var,
|
|
|
|
unsigned start, unsigned end)
|
2010-12-06 11:53:53 -08:00
|
|
|
{
|
|
|
|
JS_ASSERT(var.lifetime);
|
2011-07-22 11:53:18 -07:00
|
|
|
if (var.ensured) {
|
|
|
|
/*
|
|
|
|
* If we are still ensured to be live, the try block must scope over
|
|
|
|
* the loop, in which case the variable is already guaranteed to be
|
|
|
|
* live for the entire loop.
|
|
|
|
*/
|
|
|
|
JS_ASSERT(var.lifetime->start < start);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2010-12-06 11:53:53 -08:00
|
|
|
var.lifetime->start = start;
|
|
|
|
|
2011-04-19 06:39:49 -07:00
|
|
|
/*
|
2012-02-10 18:32:03 -08:00
|
|
|
* Consider this code:
|
2011-04-19 06:39:49 -07:00
|
|
|
*
|
2012-02-10 18:32:03 -08:00
|
|
|
* while (...) { (#1)
|
|
|
|
* use x; (#2)
|
|
|
|
* ...
|
|
|
|
* x = ...; (#3)
|
|
|
|
* ...
|
|
|
|
* } (#4)
|
2011-04-19 06:39:49 -07:00
|
|
|
*
|
2012-02-10 18:32:03 -08:00
|
|
|
* Just before analyzing the while statement, there would be a live range
|
|
|
|
* from #1..#2 and a "point range" at #3. The job of extendVariable is to
|
|
|
|
* create a new live range from #3..#4.
|
|
|
|
*
|
|
|
|
* However, more extensions may be required if the definition of x is
|
|
|
|
* conditional. Consider the following.
|
|
|
|
*
|
|
|
|
* while (...) { (#1)
|
|
|
|
* use x; (#2)
|
|
|
|
* ...
|
|
|
|
* if (...) (#5)
|
|
|
|
* x = ...; (#3)
|
|
|
|
* ...
|
|
|
|
* } (#4)
|
|
|
|
*
|
|
|
|
* Assume that x is not used after the loop. Then, before extendVariable is
|
|
|
|
* run, the live ranges would be the same as before (#1..#2 and #3..#3). We
|
|
|
|
* still need to create a range from #3..#4. But, since the assignment at #3
|
|
|
|
* may never run, we also need to create a range from #2..#3. This is done
|
|
|
|
* as follows.
|
|
|
|
*
|
|
|
|
* Each time we create a Lifetime, we store the start of the most recently
|
|
|
|
* seen sequence of conditional code in the Lifetime's savedEnd field. So,
|
|
|
|
* when creating the Lifetime at #2, we set the Lifetime's savedEnd to
|
|
|
|
* #5. (The start of the most recent conditional is cached in each
|
|
|
|
* variable's savedEnd field.) Consequently, extendVariable is able to
|
|
|
|
* create a new interval from #2..#5 using the savedEnd field of the
|
|
|
|
* existing #1..#2 interval.
|
2011-04-19 06:39:49 -07:00
|
|
|
*/
|
|
|
|
|
2010-12-06 11:53:53 -08:00
|
|
|
Lifetime *segment = var.lifetime;
|
2011-04-19 06:39:49 -07:00
|
|
|
while (segment && segment->start < end) {
|
Bug 708735 - Use <stdint.h> types in JSAPI and throughout SpiderMonkey. Continue to provide the {u,}int{8,16,32,64} and JS{Uint,Int}{8,16,32,64} integer types through a single header, however, for a simpler backout strategy -- and also to ease the transition for embedders. r=timeless on switching the jsd API to use the <stdint.h> types, r=luke, r=dmandelin
2011-12-08 19:54:10 -08:00
|
|
|
uint32_t savedEnd = segment->savedEnd;
|
2011-04-19 06:39:49 -07:00
|
|
|
if (!segment->next || segment->next->start >= end) {
|
|
|
|
/*
|
|
|
|
* savedEnd is only set for variables killed in the middle of the
|
|
|
|
* loop. Make a tail segment connecting the last use with the
|
|
|
|
* back edge.
|
|
|
|
*/
|
|
|
|
if (segment->end >= end) {
|
|
|
|
/* Variable known to be live after the loop finishes. */
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
savedEnd = end;
|
|
|
|
}
|
|
|
|
JS_ASSERT(savedEnd <= end);
|
|
|
|
if (savedEnd > segment->end) {
|
2011-09-22 13:22:30 -07:00
|
|
|
Lifetime *tail = cx->typeLifoAlloc().new_<Lifetime>(savedEnd, 0, segment->next);
|
2011-04-22 07:59:45 -07:00
|
|
|
if (!tail) {
|
|
|
|
setOOM(cx);
|
|
|
|
return;
|
|
|
|
}
|
2011-04-19 06:39:49 -07:00
|
|
|
tail->start = segment->end;
|
|
|
|
tail->loopTail = true;
|
2010-12-06 11:53:53 -08:00
|
|
|
|
2011-04-19 06:39:49 -07:00
|
|
|
/*
|
|
|
|
* Clear the segment's saved end, but preserve in the tail if this
|
|
|
|
* is the last segment in the loop and the variable is killed in an
|
|
|
|
* outer loop before the backedge.
|
|
|
|
*/
|
|
|
|
if (segment->savedEnd > end) {
|
|
|
|
JS_ASSERT(savedEnd == end);
|
|
|
|
tail->savedEnd = segment->savedEnd;
|
|
|
|
}
|
|
|
|
segment->savedEnd = 0;
|
|
|
|
|
|
|
|
segment->next = tail;
|
|
|
|
segment = tail->next;
|
|
|
|
} else {
|
|
|
|
JS_ASSERT(segment->savedEnd == 0);
|
|
|
|
segment = segment->next;
|
|
|
|
}
|
|
|
|
}
|
2011-04-22 07:59:45 -07:00
|
|
|
}
|
|
|
|
|
2011-07-22 11:53:18 -07:00
|
|
|
inline void
|
|
|
|
ScriptAnalysis::ensureVariable(LifetimeVariable &var, unsigned until)
|
|
|
|
{
|
|
|
|
JS_ASSERT(var.lifetime);
|
2011-07-26 14:16:59 -07:00
|
|
|
|
|
|
|
/*
|
|
|
|
* If we are already ensured, the current range we are trying to ensure
|
|
|
|
* should already be included.
|
|
|
|
*/
|
|
|
|
if (var.ensured) {
|
|
|
|
JS_ASSERT(var.lifetime->start <= until);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
JS_ASSERT(until < var.lifetime->start);
|
2011-07-22 11:53:18 -07:00
|
|
|
var.lifetime->start = until;
|
|
|
|
var.ensured = true;
|
|
|
|
}
|
|
|
|
|
2011-04-22 07:59:45 -07:00
|
|
|
void
|
|
|
|
ScriptAnalysis::clearAllocations()
|
|
|
|
{
|
|
|
|
/*
|
|
|
|
* Clear out storage used for register allocations in a compilation once
|
|
|
|
* that compilation has finished. Register allocations are only used for
|
|
|
|
* a single compilation.
|
|
|
|
*/
|
|
|
|
for (unsigned i = 0; i < script->length; i++) {
|
|
|
|
Bytecode *code = maybeCode(i);
|
|
|
|
if (code)
|
|
|
|
code->allocation = NULL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/////////////////////////////////////////////////////////////////////
|
|
|
|
// SSA Analysis
|
|
|
|
/////////////////////////////////////////////////////////////////////
|
2010-12-06 11:53:53 -08:00
|
|
|
|
2011-04-22 07:59:45 -07:00
|
|
|
void
|
|
|
|
ScriptAnalysis::analyzeSSA(JSContext *cx)
|
|
|
|
{
|
|
|
|
JS_ASSERT(cx->compartment->activeAnalysis && !ranSSA() && !failed());
|
|
|
|
|
|
|
|
if (!ranLifetimes()) {
|
|
|
|
analyzeLifetimes(cx);
|
|
|
|
if (failed())
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2011-09-22 13:22:30 -07:00
|
|
|
LifoAlloc &tla = cx->typeLifoAlloc();
|
2011-04-22 07:59:45 -07:00
|
|
|
unsigned maxDepth = script->nslots - script->nfixed;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Current value of each variable and stack value. Empty for missing or
|
|
|
|
* untracked entries, i.e. escaping locals and arguments.
|
|
|
|
*/
|
2012-02-23 13:01:27 -08:00
|
|
|
SSAValueInfo *values = (SSAValueInfo *)
|
|
|
|
cx->calloc_((numSlots + maxDepth) * sizeof(SSAValueInfo));
|
2011-04-22 07:59:45 -07:00
|
|
|
if (!values) {
|
|
|
|
setOOM(cx);
|
|
|
|
return;
|
|
|
|
}
|
2011-05-15 23:32:21 -07:00
|
|
|
struct FreeSSAValues {
|
|
|
|
JSContext *cx;
|
2012-02-23 13:01:27 -08:00
|
|
|
SSAValueInfo *values;
|
|
|
|
FreeSSAValues(JSContext *cx, SSAValueInfo *values) : cx(cx), values(values) {}
|
2011-05-15 23:32:21 -07:00
|
|
|
~FreeSSAValues() { cx->free_(values); }
|
|
|
|
} free(cx, values);
|
2011-04-22 07:59:45 -07:00
|
|
|
|
2012-02-23 13:01:27 -08:00
|
|
|
SSAValueInfo *stack = values + numSlots;
|
Bug 708735 - Use <stdint.h> types in JSAPI and throughout SpiderMonkey. Continue to provide the {u,}int{8,16,32,64} and JS{Uint,Int}{8,16,32,64} integer types through a single header, however, for a simpler backout strategy -- and also to ease the transition for embedders. r=timeless on switching the jsd API to use the <stdint.h> types, r=luke, r=dmandelin
2011-12-08 19:54:10 -08:00
|
|
|
uint32_t stackDepth = 0;
|
2011-04-22 07:59:45 -07:00
|
|
|
|
Bug 708735 - Use <stdint.h> types in JSAPI and throughout SpiderMonkey. Continue to provide the {u,}int{8,16,32,64} and JS{Uint,Int}{8,16,32,64} integer types through a single header, however, for a simpler backout strategy -- and also to ease the transition for embedders. r=timeless on switching the jsd API to use the <stdint.h> types, r=luke, r=dmandelin
2011-12-08 19:54:10 -08:00
|
|
|
for (uint32_t slot = ArgSlot(0); slot < numSlots; slot++) {
|
2011-04-22 07:59:45 -07:00
|
|
|
if (trackSlot(slot))
|
2012-02-23 13:01:27 -08:00
|
|
|
values[slot].v.initInitial(slot);
|
2011-04-22 07:59:45 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
2012-02-23 13:01:27 -08:00
|
|
|
* All target offsets for forward jumps we have seen (including ones whose
|
|
|
|
* target we have advanced past). We lazily add pending entries at these
|
|
|
|
* targets for the original value of variables modified before the branch
|
|
|
|
* rejoins.
|
2011-04-22 07:59:45 -07:00
|
|
|
*/
|
Bug 708735 - Use <stdint.h> types in JSAPI and throughout SpiderMonkey. Continue to provide the {u,}int{8,16,32,64} and JS{Uint,Int}{8,16,32,64} integer types through a single header, however, for a simpler backout strategy -- and also to ease the transition for embedders. r=timeless on switching the jsd API to use the <stdint.h> types, r=luke, r=dmandelin
2011-12-08 19:54:10 -08:00
|
|
|
Vector<uint32_t> branchTargets(cx);
|
2011-04-22 07:59:45 -07:00
|
|
|
|
2011-12-24 06:21:52 -08:00
|
|
|
/*
|
2012-02-23 13:01:27 -08:00
|
|
|
* Subset of branchTargets which are exception handlers at future offsets.
|
|
|
|
* Any new value of a variable modified before the target is reached is a
|
|
|
|
* potential value at that target, along with the lazy original value.
|
2011-12-24 06:21:52 -08:00
|
|
|
*/
|
|
|
|
Vector<uint32_t> exceptionTargets(cx);
|
|
|
|
|
Bug 708735 - Use <stdint.h> types in JSAPI and throughout SpiderMonkey. Continue to provide the {u,}int{8,16,32,64} and JS{Uint,Int}{8,16,32,64} integer types through a single header, however, for a simpler backout strategy -- and also to ease the transition for embedders. r=timeless on switching the jsd API to use the <stdint.h> types, r=luke, r=dmandelin
2011-12-08 19:54:10 -08:00
|
|
|
uint32_t offset = 0;
|
2011-04-22 07:59:45 -07:00
|
|
|
while (offset < script->length) {
|
|
|
|
jsbytecode *pc = script->code + offset;
|
2011-07-28 09:16:53 -07:00
|
|
|
JSOp op = (JSOp)*pc;
|
2011-04-22 07:59:45 -07:00
|
|
|
|
Bug 708735 - Use <stdint.h> types in JSAPI and throughout SpiderMonkey. Continue to provide the {u,}int{8,16,32,64} and JS{Uint,Int}{8,16,32,64} integer types through a single header, however, for a simpler backout strategy -- and also to ease the transition for embedders. r=timeless on switching the jsd API to use the <stdint.h> types, r=luke, r=dmandelin
2011-12-08 19:54:10 -08:00
|
|
|
uint32_t successorOffset = offset + GetBytecodeLength(pc);
|
2011-04-22 07:59:45 -07:00
|
|
|
|
|
|
|
Bytecode *code = maybeCode(pc);
|
|
|
|
if (!code) {
|
|
|
|
offset = successorOffset;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2012-02-23 13:01:27 -08:00
|
|
|
if (code->exceptionEntry) {
|
|
|
|
/* Remove from exception targets list, which reflects only future targets. */
|
|
|
|
for (size_t i = 0; i < exceptionTargets.length(); i++) {
|
|
|
|
if (exceptionTargets[i] == offset) {
|
|
|
|
exceptionTargets[i] = exceptionTargets.back();
|
|
|
|
exceptionTargets.popBack();
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-04-22 07:59:45 -07:00
|
|
|
if (code->stackDepth > stackDepth)
|
|
|
|
PodZero(stack + stackDepth, code->stackDepth - stackDepth);
|
|
|
|
stackDepth = code->stackDepth;
|
|
|
|
|
2011-12-01 15:13:51 -08:00
|
|
|
if (op == JSOP_LOOPHEAD && code->loop) {
|
2011-04-22 07:59:45 -07:00
|
|
|
/*
|
|
|
|
* Make sure there is a pending value array for phi nodes at the
|
|
|
|
* loop head. We won't be able to clear these until we reach the
|
|
|
|
* loop's back edge.
|
|
|
|
*
|
|
|
|
* We need phi nodes for all variables which might be modified
|
|
|
|
* during the loop. This ensures that in the loop body we have
|
|
|
|
* already updated state to reflect possible changes that happen
|
|
|
|
* before the back edge, and don't need to go back and fix things
|
|
|
|
* up when we *do* get to the back edge. This could be made lazier.
|
|
|
|
*
|
|
|
|
* We don't make phi nodes for values on the stack at the head of
|
|
|
|
* the loop. These may be popped during the loop (i.e. for ITER
|
|
|
|
* loops), but in such cases the original value is pushed back.
|
|
|
|
*/
|
|
|
|
Vector<SlotValue> *&pending = code->pendingValues;
|
2012-02-23 13:01:27 -08:00
|
|
|
if (!pending) {
|
2011-04-22 07:59:45 -07:00
|
|
|
pending = cx->new_< Vector<SlotValue> >(cx);
|
|
|
|
if (!pending) {
|
|
|
|
setOOM(cx);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Make phi nodes and update state for slots which are already in
|
|
|
|
* pending from previous branches to the loop head, and which are
|
|
|
|
* modified in the body of the loop.
|
|
|
|
*/
|
|
|
|
for (unsigned i = 0; i < pending->length(); i++) {
|
|
|
|
SlotValue &v = (*pending)[i];
|
Bug 708735 - Use <stdint.h> types in JSAPI and throughout SpiderMonkey. Continue to provide the {u,}int{8,16,32,64} and JS{Uint,Int}{8,16,32,64} integer types through a single header, however, for a simpler backout strategy -- and also to ease the transition for embedders. r=timeless on switching the jsd API to use the <stdint.h> types, r=luke, r=dmandelin
2011-12-08 19:54:10 -08:00
|
|
|
if (v.slot < numSlots && liveness(v.slot).firstWrite(code->loop) != UINT32_MAX) {
|
2012-02-23 13:01:27 -08:00
|
|
|
if (v.value.kind() != SSAValue::PHI || v.value.phiOffset() != offset) {
|
2012-03-01 17:48:32 -08:00
|
|
|
JS_ASSERT(v.value.phiOffset() < offset);
|
2011-04-22 07:59:45 -07:00
|
|
|
SSAValue ov = v.value;
|
|
|
|
if (!makePhi(cx, v.slot, offset, &ov))
|
|
|
|
return;
|
|
|
|
insertPhi(cx, ov, v.value);
|
|
|
|
v.value = ov;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (code->fallthrough || code->jumpFallthrough)
|
2012-02-23 13:01:27 -08:00
|
|
|
mergeValue(cx, offset, values[v.slot].v, &v);
|
|
|
|
mergeBranchTarget(cx, values[v.slot], v.slot, branchTargets, offset - 1);
|
|
|
|
values[v.slot].v = v.value;
|
2011-04-22 07:59:45 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Make phi nodes for all other slots which might be modified
|
|
|
|
* during the loop. This ensures that in the loop body we have
|
|
|
|
* already updated state to reflect possible changes that happen
|
|
|
|
* before the back edge, and don't need to go back and fix things
|
|
|
|
* up when we *do* get to the back edge. This could be made lazier.
|
|
|
|
*/
|
Bug 708735 - Use <stdint.h> types in JSAPI and throughout SpiderMonkey. Continue to provide the {u,}int{8,16,32,64} and JS{Uint,Int}{8,16,32,64} integer types through a single header, however, for a simpler backout strategy -- and also to ease the transition for embedders. r=timeless on switching the jsd API to use the <stdint.h> types, r=luke, r=dmandelin
2011-12-08 19:54:10 -08:00
|
|
|
for (uint32_t slot = ArgSlot(0); slot < numSlots + stackDepth; slot++) {
|
2011-04-22 07:59:45 -07:00
|
|
|
if (slot >= numSlots || !trackSlot(slot))
|
|
|
|
continue;
|
Bug 708735 - Use <stdint.h> types in JSAPI and throughout SpiderMonkey. Continue to provide the {u,}int{8,16,32,64} and JS{Uint,Int}{8,16,32,64} integer types through a single header, however, for a simpler backout strategy -- and also to ease the transition for embedders. r=timeless on switching the jsd API to use the <stdint.h> types, r=luke, r=dmandelin
2011-12-08 19:54:10 -08:00
|
|
|
if (liveness(slot).firstWrite(code->loop) == UINT32_MAX)
|
2011-04-22 07:59:45 -07:00
|
|
|
continue;
|
2012-02-23 13:01:27 -08:00
|
|
|
if (values[slot].v.kind() == SSAValue::PHI && values[slot].v.phiOffset() == offset) {
|
2011-04-22 07:59:45 -07:00
|
|
|
/* There is already a pending entry for this slot. */
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
SSAValue ov;
|
|
|
|
if (!makePhi(cx, slot, offset, &ov))
|
|
|
|
return;
|
|
|
|
if (code->fallthrough || code->jumpFallthrough)
|
2012-02-23 13:01:27 -08:00
|
|
|
insertPhi(cx, ov, values[slot].v);
|
|
|
|
mergeBranchTarget(cx, values[slot], slot, branchTargets, offset - 1);
|
|
|
|
values[slot].v = ov;
|
2011-04-22 07:59:45 -07:00
|
|
|
if (!pending->append(SlotValue(slot, ov))) {
|
|
|
|
setOOM(cx);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else if (code->pendingValues) {
|
|
|
|
/*
|
|
|
|
* New values at this point from a previous jump to this bytecode.
|
|
|
|
* If there is fallthrough from the previous instruction, merge
|
|
|
|
* with the current state and create phi nodes where necessary,
|
|
|
|
* otherwise replace current values with the new values.
|
2011-12-24 06:21:52 -08:00
|
|
|
*
|
|
|
|
* Catch blocks are artifically treated as having fallthrough, so
|
|
|
|
* that values written inside the block but not subsequently
|
|
|
|
* overwritten are picked up.
|
2011-04-22 07:59:45 -07:00
|
|
|
*/
|
2012-02-23 13:01:27 -08:00
|
|
|
bool exception = getCode(offset).exceptionEntry;
|
2011-04-22 07:59:45 -07:00
|
|
|
Vector<SlotValue> *pending = code->pendingValues;
|
|
|
|
for (unsigned i = 0; i < pending->length(); i++) {
|
|
|
|
SlotValue &v = (*pending)[i];
|
2011-12-24 06:21:52 -08:00
|
|
|
if (code->fallthrough || code->jumpFallthrough ||
|
2012-02-23 13:01:27 -08:00
|
|
|
(exception && values[v.slot].v.kind() != SSAValue::EMPTY)) {
|
|
|
|
mergeValue(cx, offset, values[v.slot].v, &v);
|
2011-12-24 06:21:52 -08:00
|
|
|
}
|
2012-02-23 13:01:27 -08:00
|
|
|
mergeBranchTarget(cx, values[v.slot], v.slot, branchTargets, offset);
|
|
|
|
values[v.slot].v = v.value;
|
2011-04-22 07:59:45 -07:00
|
|
|
}
|
|
|
|
freezeNewValues(cx, offset);
|
|
|
|
}
|
|
|
|
|
2011-07-16 08:25:22 -07:00
|
|
|
if (js_CodeSpec[op].format & JOF_DECOMPOSE) {
|
|
|
|
offset = successorOffset;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2011-04-22 07:59:45 -07:00
|
|
|
unsigned nuses = GetUseCount(script, offset);
|
|
|
|
unsigned ndefs = GetDefCount(script, offset);
|
|
|
|
JS_ASSERT(stackDepth >= nuses);
|
|
|
|
|
|
|
|
unsigned xuses = ExtendedUse(pc) ? nuses + 1 : nuses;
|
|
|
|
|
|
|
|
if (xuses) {
|
2011-09-22 13:22:30 -07:00
|
|
|
code->poppedValues = tla.newArray<SSAValue>(xuses);
|
2011-04-22 07:59:45 -07:00
|
|
|
if (!code->poppedValues) {
|
|
|
|
setOOM(cx);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
for (unsigned i = 0; i < nuses; i++) {
|
2012-02-23 13:01:27 -08:00
|
|
|
SSAValue &v = stack[stackDepth - 1 - i].v;
|
2011-04-22 07:59:45 -07:00
|
|
|
code->poppedValues[i] = v;
|
|
|
|
v.clear();
|
|
|
|
}
|
|
|
|
if (xuses > nuses) {
|
|
|
|
/*
|
|
|
|
* For SETLOCAL, INCLOCAL, etc. opcodes, add an extra popped
|
|
|
|
* value holding the value of the local before the op.
|
|
|
|
*/
|
Bug 708735 - Use <stdint.h> types in JSAPI and throughout SpiderMonkey. Continue to provide the {u,}int{8,16,32,64} and JS{Uint,Int}{8,16,32,64} integer types through a single header, however, for a simpler backout strategy -- and also to ease the transition for embedders. r=timeless on switching the jsd API to use the <stdint.h> types, r=luke, r=dmandelin
2011-12-08 19:54:10 -08:00
|
|
|
uint32_t slot = GetBytecodeSlot(script, pc);
|
2011-04-22 07:59:45 -07:00
|
|
|
if (trackSlot(slot))
|
2012-02-23 13:01:27 -08:00
|
|
|
code->poppedValues[nuses] = values[slot].v;
|
2011-04-22 07:59:45 -07:00
|
|
|
else
|
|
|
|
code->poppedValues[nuses].clear();
|
|
|
|
}
|
2011-04-27 23:28:54 -07:00
|
|
|
|
|
|
|
if (xuses) {
|
2011-09-22 13:22:30 -07:00
|
|
|
SSAUseChain *useChains = tla.newArray<SSAUseChain>(xuses);
|
2011-04-27 23:28:54 -07:00
|
|
|
if (!useChains) {
|
|
|
|
setOOM(cx);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
PodZero(useChains, xuses);
|
|
|
|
for (unsigned i = 0; i < xuses; i++) {
|
|
|
|
const SSAValue &v = code->poppedValues[i];
|
|
|
|
if (trackUseChain(v)) {
|
|
|
|
SSAUseChain *&uses = useChain(v);
|
|
|
|
useChains[i].popped = true;
|
|
|
|
useChains[i].offset = offset;
|
|
|
|
useChains[i].u.which = i;
|
|
|
|
useChains[i].next = uses;
|
|
|
|
uses = &useChains[i];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2011-04-22 07:59:45 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
stackDepth -= nuses;
|
|
|
|
|
|
|
|
for (unsigned i = 0; i < ndefs; i++)
|
2012-02-23 13:01:27 -08:00
|
|
|
stack[stackDepth + i].v.initPushed(offset, i);
|
2011-04-22 07:59:45 -07:00
|
|
|
|
2011-04-27 23:28:54 -07:00
|
|
|
unsigned xdefs = ExtendedDef(pc) ? ndefs + 1 : ndefs;
|
|
|
|
if (xdefs) {
|
2011-09-22 13:22:30 -07:00
|
|
|
code->pushedUses = tla.newArray<SSAUseChain *>(xdefs);
|
2011-04-27 23:28:54 -07:00
|
|
|
if (!code->pushedUses) {
|
|
|
|
setOOM(cx);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
PodZero(code->pushedUses, xdefs);
|
|
|
|
}
|
|
|
|
|
2011-04-22 07:59:45 -07:00
|
|
|
stackDepth += ndefs;
|
|
|
|
|
2012-01-18 16:40:18 -08:00
|
|
|
if (BytecodeUpdatesSlot(op)) {
|
Bug 708735 - Use <stdint.h> types in JSAPI and throughout SpiderMonkey. Continue to provide the {u,}int{8,16,32,64} and JS{Uint,Int}{8,16,32,64} integer types through a single header, however, for a simpler backout strategy -- and also to ease the transition for embedders. r=timeless on switching the jsd API to use the <stdint.h> types, r=luke, r=dmandelin
2011-12-08 19:54:10 -08:00
|
|
|
uint32_t slot = GetBytecodeSlot(script, pc);
|
2011-04-22 07:59:45 -07:00
|
|
|
if (trackSlot(slot)) {
|
2012-02-23 13:01:27 -08:00
|
|
|
mergeBranchTarget(cx, values[slot], slot, branchTargets, offset);
|
|
|
|
mergeExceptionTarget(cx, values[slot].v, slot, exceptionTargets);
|
|
|
|
values[slot].v.initWritten(slot, offset);
|
2011-04-22 07:59:45 -07:00
|
|
|
}
|
2012-01-18 16:40:18 -08:00
|
|
|
}
|
2011-04-22 07:59:45 -07:00
|
|
|
|
2012-01-18 16:40:18 -08:00
|
|
|
switch (op) {
|
2011-04-22 07:59:45 -07:00
|
|
|
case JSOP_GETARG:
|
2011-05-05 13:59:29 -07:00
|
|
|
case JSOP_GETLOCAL: {
|
Bug 708735 - Use <stdint.h> types in JSAPI and throughout SpiderMonkey. Continue to provide the {u,}int{8,16,32,64} and JS{Uint,Int}{8,16,32,64} integer types through a single header, however, for a simpler backout strategy -- and also to ease the transition for embedders. r=timeless on switching the jsd API to use the <stdint.h> types, r=luke, r=dmandelin
2011-12-08 19:54:10 -08:00
|
|
|
uint32_t slot = GetBytecodeSlot(script, pc);
|
2011-04-22 07:59:45 -07:00
|
|
|
if (trackSlot(slot)) {
|
|
|
|
/*
|
|
|
|
* Propagate the current value of the local to the pushed value,
|
|
|
|
* and remember it with an extended use on the opcode.
|
|
|
|
*/
|
2012-02-23 13:01:27 -08:00
|
|
|
stack[stackDepth - 1].v = code->poppedValues[0] = values[slot].v;
|
2011-04-22 07:59:45 -07:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Short circuit ops which push back one of their operands. */
|
|
|
|
|
|
|
|
case JSOP_MOREITER:
|
2012-02-23 13:01:27 -08:00
|
|
|
stack[stackDepth - 2].v = code->poppedValues[0];
|
2011-04-22 07:59:45 -07:00
|
|
|
break;
|
|
|
|
|
|
|
|
case JSOP_INITPROP:
|
2012-02-23 13:01:27 -08:00
|
|
|
stack[stackDepth - 1].v = code->poppedValues[1];
|
2011-04-22 07:59:45 -07:00
|
|
|
break;
|
|
|
|
|
2012-06-06 19:53:07 -07:00
|
|
|
case JSOP_SPREAD:
|
|
|
|
case JSOP_INITELEM_INC:
|
|
|
|
stack[stackDepth - 2].v = code->poppedValues[2];
|
|
|
|
break;
|
|
|
|
|
2011-04-22 07:59:45 -07:00
|
|
|
case JSOP_INITELEM:
|
2012-02-23 13:01:27 -08:00
|
|
|
stack[stackDepth - 1].v = code->poppedValues[2];
|
2011-04-22 07:59:45 -07:00
|
|
|
break;
|
|
|
|
|
2011-08-10 12:30:34 -07:00
|
|
|
case JSOP_DUP:
|
2012-02-23 13:01:27 -08:00
|
|
|
stack[stackDepth - 1].v = stack[stackDepth - 2].v = code->poppedValues[0];
|
2011-08-10 12:30:34 -07:00
|
|
|
break;
|
|
|
|
|
|
|
|
case JSOP_DUP2:
|
2012-02-23 13:01:27 -08:00
|
|
|
stack[stackDepth - 1].v = stack[stackDepth - 3].v = code->poppedValues[0];
|
|
|
|
stack[stackDepth - 2].v = stack[stackDepth - 4].v = code->poppedValues[1];
|
2011-08-10 12:30:34 -07:00
|
|
|
break;
|
|
|
|
|
2011-07-05 22:54:19 -07:00
|
|
|
case JSOP_SWAP:
|
|
|
|
/* Swap is like pick 1. */
|
|
|
|
case JSOP_PICK: {
|
|
|
|
unsigned pickedDepth = (op == JSOP_SWAP ? 1 : pc[1]);
|
2012-02-23 13:01:27 -08:00
|
|
|
stack[stackDepth - 1].v = code->poppedValues[pickedDepth];
|
2011-07-05 22:54:19 -07:00
|
|
|
for (unsigned i = 0; i < pickedDepth; i++)
|
2012-02-23 13:01:27 -08:00
|
|
|
stack[stackDepth - 2 - i].v = code->poppedValues[i];
|
2011-07-05 22:54:19 -07:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2011-04-26 14:32:52 -07:00
|
|
|
/*
|
|
|
|
* Switch and try blocks preserve the stack between the original op
|
2011-12-24 06:21:52 -08:00
|
|
|
* and all case statements or exception/finally handlers.
|
2011-04-26 14:32:52 -07:00
|
|
|
*/
|
2011-04-22 07:59:45 -07:00
|
|
|
|
2012-01-09 11:05:06 -08:00
|
|
|
case JSOP_TABLESWITCH: {
|
|
|
|
unsigned defaultOffset = offset + GET_JUMP_OFFSET(pc);
|
|
|
|
jsbytecode *pc2 = pc + JUMP_OFFSET_LEN;
|
2012-03-01 18:54:01 -08:00
|
|
|
int32_t low = GET_JUMP_OFFSET(pc2);
|
2011-04-26 14:32:52 -07:00
|
|
|
pc2 += JUMP_OFFSET_LEN;
|
2012-03-01 18:54:01 -08:00
|
|
|
int32_t high = GET_JUMP_OFFSET(pc2);
|
2011-04-26 14:32:52 -07:00
|
|
|
pc2 += JUMP_OFFSET_LEN;
|
2011-04-22 07:59:45 -07:00
|
|
|
|
2012-03-01 18:54:01 -08:00
|
|
|
for (int32_t i = low; i <= high; i++) {
|
2012-01-09 11:05:06 -08:00
|
|
|
unsigned targetOffset = offset + GET_JUMP_OFFSET(pc2);
|
2011-04-26 14:32:52 -07:00
|
|
|
if (targetOffset != offset)
|
2012-03-01 17:48:32 -08:00
|
|
|
checkBranchTarget(cx, targetOffset, branchTargets, values, stackDepth);
|
2012-01-09 11:05:06 -08:00
|
|
|
pc2 += JUMP_OFFSET_LEN;
|
2011-04-26 14:32:52 -07:00
|
|
|
}
|
2012-02-23 13:01:27 -08:00
|
|
|
|
2012-03-01 17:48:32 -08:00
|
|
|
checkBranchTarget(cx, defaultOffset, branchTargets, values, stackDepth);
|
2011-04-26 14:32:52 -07:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2012-01-09 11:05:06 -08:00
|
|
|
case JSOP_LOOKUPSWITCH: {
|
|
|
|
unsigned defaultOffset = offset + GET_JUMP_OFFSET(pc);
|
|
|
|
jsbytecode *pc2 = pc + JUMP_OFFSET_LEN;
|
2011-04-26 14:32:52 -07:00
|
|
|
unsigned npairs = GET_UINT16(pc2);
|
|
|
|
pc2 += UINT16_LEN;
|
|
|
|
|
|
|
|
while (npairs) {
|
2012-02-03 18:53:29 -08:00
|
|
|
pc2 += UINT32_INDEX_LEN;
|
2012-01-09 11:05:06 -08:00
|
|
|
unsigned targetOffset = offset + GET_JUMP_OFFSET(pc2);
|
2012-03-01 17:48:32 -08:00
|
|
|
checkBranchTarget(cx, targetOffset, branchTargets, values, stackDepth);
|
2012-01-09 11:05:06 -08:00
|
|
|
pc2 += JUMP_OFFSET_LEN;
|
2011-04-26 14:32:52 -07:00
|
|
|
npairs--;
|
|
|
|
}
|
2012-02-23 13:01:27 -08:00
|
|
|
|
2012-03-01 17:48:32 -08:00
|
|
|
checkBranchTarget(cx, defaultOffset, branchTargets, values, stackDepth);
|
2011-04-26 14:32:52 -07:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2012-05-19 12:56:17 -07:00
|
|
|
case JSOP_TRY: {
|
2011-04-26 14:32:52 -07:00
|
|
|
JSTryNote *tn = script->trynotes()->vector;
|
|
|
|
JSTryNote *tnlimit = tn + script->trynotes()->length;
|
|
|
|
for (; tn < tnlimit; tn++) {
|
2011-08-09 01:51:59 -07:00
|
|
|
unsigned startOffset = script->mainOffset + tn->start;
|
2011-04-26 14:32:52 -07:00
|
|
|
if (startOffset == offset + 1) {
|
|
|
|
unsigned catchOffset = startOffset + tn->length;
|
|
|
|
|
2011-12-24 06:21:52 -08:00
|
|
|
if (tn->kind != JSTRY_ITER) {
|
2011-04-26 14:32:52 -07:00
|
|
|
checkBranchTarget(cx, catchOffset, branchTargets, values, stackDepth);
|
2011-12-24 06:21:52 -08:00
|
|
|
checkExceptionTarget(cx, catchOffset, exceptionTargets);
|
|
|
|
}
|
2011-04-22 07:59:45 -07:00
|
|
|
}
|
|
|
|
}
|
2011-04-26 14:32:52 -07:00
|
|
|
break;
|
|
|
|
}
|
2011-04-22 07:59:45 -07:00
|
|
|
|
2012-01-20 16:13:23 -08:00
|
|
|
case JSOP_THROW:
|
2012-02-02 16:09:47 -08:00
|
|
|
case JSOP_RETURN:
|
|
|
|
case JSOP_STOP:
|
|
|
|
case JSOP_RETRVAL:
|
2012-01-20 16:13:23 -08:00
|
|
|
mergeAllExceptionTargets(cx, values, exceptionTargets);
|
|
|
|
break;
|
|
|
|
|
2011-04-26 14:32:52 -07:00
|
|
|
default:;
|
|
|
|
}
|
|
|
|
|
Bug 708735 - Use <stdint.h> types in JSAPI and throughout SpiderMonkey. Continue to provide the {u,}int{8,16,32,64} and JS{Uint,Int}{8,16,32,64} integer types through a single header, however, for a simpler backout strategy -- and also to ease the transition for embedders. r=timeless on switching the jsd API to use the <stdint.h> types, r=luke, r=dmandelin
2011-12-08 19:54:10 -08:00
|
|
|
uint32_t type = JOF_TYPE(js_CodeSpec[op].format);
|
2012-01-09 11:05:06 -08:00
|
|
|
if (type == JOF_JUMP) {
|
2011-05-25 08:15:34 -07:00
|
|
|
unsigned targetOffset = FollowBranch(cx, script, offset);
|
2011-04-26 14:32:52 -07:00
|
|
|
checkBranchTarget(cx, targetOffset, branchTargets, values, stackDepth);
|
2011-04-22 07:59:45 -07:00
|
|
|
|
|
|
|
/*
|
|
|
|
* If this is a back edge, we're done with the loop and can freeze
|
|
|
|
* the phi values at the head now.
|
|
|
|
*/
|
|
|
|
if (targetOffset < offset)
|
|
|
|
freezeNewValues(cx, targetOffset);
|
|
|
|
}
|
|
|
|
|
|
|
|
offset = successorOffset;
|
|
|
|
}
|
|
|
|
|
|
|
|
ranSSA_ = true;
|
2012-01-17 16:35:12 -08:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Now that we have full SSA information for the script, analyze whether
|
2012-04-02 08:58:30 -07:00
|
|
|
* we can avoid creating the arguments object.
|
2012-01-17 16:35:12 -08:00
|
|
|
*/
|
2012-04-02 08:58:30 -07:00
|
|
|
if (!script->analyzedArgsUsage())
|
|
|
|
script->setNeedsArgsObj(needsArgsObj(cx));
|
2011-04-22 07:59:45 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Get a phi node's capacity for a given length. */
|
|
|
|
static inline unsigned
|
|
|
|
PhiNodeCapacity(unsigned length)
|
|
|
|
{
|
|
|
|
if (length <= 4)
|
|
|
|
return 4;
|
|
|
|
|
|
|
|
unsigned log2;
|
|
|
|
JS_FLOOR_LOG2(log2, length - 1);
|
|
|
|
return 1 << (log2 + 1);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
Bug 708735 - Use <stdint.h> types in JSAPI and throughout SpiderMonkey. Continue to provide the {u,}int{8,16,32,64} and JS{Uint,Int}{8,16,32,64} integer types through a single header, however, for a simpler backout strategy -- and also to ease the transition for embedders. r=timeless on switching the jsd API to use the <stdint.h> types, r=luke, r=dmandelin
2011-12-08 19:54:10 -08:00
|
|
|
ScriptAnalysis::makePhi(JSContext *cx, uint32_t slot, uint32_t offset, SSAValue *pv)
|
2011-04-22 07:59:45 -07:00
|
|
|
{
|
2011-09-22 13:22:30 -07:00
|
|
|
SSAPhiNode *node = cx->typeLifoAlloc().new_<SSAPhiNode>();
|
|
|
|
SSAValue *options = cx->typeLifoAlloc().newArray<SSAValue>(PhiNodeCapacity(0));
|
2011-04-22 07:59:45 -07:00
|
|
|
if (!node || !options) {
|
|
|
|
setOOM(cx);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
node->slot = slot;
|
|
|
|
node->options = options;
|
|
|
|
pv->initPhi(offset, node);
|
2010-12-06 11:53:53 -08:00
|
|
|
return true;
|
2010-10-26 12:00:54 -07:00
|
|
|
}
|
|
|
|
|
2011-04-22 07:59:45 -07:00
|
|
|
void
|
|
|
|
ScriptAnalysis::insertPhi(JSContext *cx, SSAValue &phi, const SSAValue &v)
|
|
|
|
{
|
|
|
|
JS_ASSERT(phi.kind() == SSAValue::PHI);
|
|
|
|
SSAPhiNode *node = phi.phiNode();
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Filter dupes inserted into small nodes to keep things clean and avoid
|
|
|
|
* extra type constraints, but don't bother on large phi nodes to avoid
|
|
|
|
* quadratic behavior.
|
|
|
|
*/
|
|
|
|
if (node->length <= 8) {
|
|
|
|
for (unsigned i = 0; i < node->length; i++) {
|
2012-01-17 16:35:07 -08:00
|
|
|
if (v == node->options[i])
|
2011-04-22 07:59:45 -07:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-04-27 23:28:54 -07:00
|
|
|
if (trackUseChain(v)) {
|
|
|
|
SSAUseChain *&uses = useChain(v);
|
|
|
|
|
2011-09-22 13:22:30 -07:00
|
|
|
SSAUseChain *use = cx->typeLifoAlloc().new_<SSAUseChain>();
|
2011-04-27 23:28:54 -07:00
|
|
|
if (!use) {
|
|
|
|
setOOM(cx);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
use->popped = false;
|
|
|
|
use->offset = phi.phiOffset();
|
|
|
|
use->u.phi = node;
|
|
|
|
use->next = uses;
|
|
|
|
uses = use;
|
|
|
|
}
|
|
|
|
|
2011-04-22 07:59:45 -07:00
|
|
|
if (node->length < PhiNodeCapacity(node->length)) {
|
|
|
|
node->options[node->length++] = v;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2011-09-22 13:22:30 -07:00
|
|
|
SSAValue *newOptions =
|
|
|
|
cx->typeLifoAlloc().newArray<SSAValue>(PhiNodeCapacity(node->length + 1));
|
2011-04-22 07:59:45 -07:00
|
|
|
if (!newOptions) {
|
|
|
|
setOOM(cx);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
PodCopy(newOptions, node->options, node->length);
|
|
|
|
node->options = newOptions;
|
|
|
|
node->options[node->length++] = v;
|
|
|
|
}
|
|
|
|
|
|
|
|
inline void
|
Bug 708735 - Use <stdint.h> types in JSAPI and throughout SpiderMonkey. Continue to provide the {u,}int{8,16,32,64} and JS{Uint,Int}{8,16,32,64} integer types through a single header, however, for a simpler backout strategy -- and also to ease the transition for embedders. r=timeless on switching the jsd API to use the <stdint.h> types, r=luke, r=dmandelin
2011-12-08 19:54:10 -08:00
|
|
|
ScriptAnalysis::mergeValue(JSContext *cx, uint32_t offset, const SSAValue &v, SlotValue *pv)
|
2011-04-22 07:59:45 -07:00
|
|
|
{
|
2011-04-23 22:36:43 -07:00
|
|
|
/* Make sure that v is accounted for in the pending value or phi value at pv. */
|
2011-04-26 14:32:52 -07:00
|
|
|
JS_ASSERT(v.kind() != SSAValue::EMPTY && pv->value.kind() != SSAValue::EMPTY);
|
2011-04-22 07:59:45 -07:00
|
|
|
|
2012-01-17 16:35:07 -08:00
|
|
|
if (v == pv->value)
|
2011-04-22 07:59:45 -07:00
|
|
|
return;
|
|
|
|
|
2012-03-01 17:48:32 -08:00
|
|
|
if (pv->value.kind() != SSAValue::PHI || pv->value.phiOffset() < offset) {
|
2011-04-22 07:59:45 -07:00
|
|
|
SSAValue ov = pv->value;
|
|
|
|
if (makePhi(cx, pv->slot, offset, &pv->value)) {
|
|
|
|
insertPhi(cx, pv->value, v);
|
|
|
|
insertPhi(cx, pv->value, ov);
|
|
|
|
}
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2012-03-01 17:48:32 -08:00
|
|
|
JS_ASSERT(pv->value.phiOffset() == offset);
|
2011-04-22 07:59:45 -07:00
|
|
|
insertPhi(cx, pv->value, v);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
Bug 708735 - Use <stdint.h> types in JSAPI and throughout SpiderMonkey. Continue to provide the {u,}int{8,16,32,64} and JS{Uint,Int}{8,16,32,64} integer types through a single header, however, for a simpler backout strategy -- and also to ease the transition for embedders. r=timeless on switching the jsd API to use the <stdint.h> types, r=luke, r=dmandelin
2011-12-08 19:54:10 -08:00
|
|
|
ScriptAnalysis::checkPendingValue(JSContext *cx, const SSAValue &v, uint32_t slot,
|
2011-04-22 07:59:45 -07:00
|
|
|
Vector<SlotValue> *pending)
|
|
|
|
{
|
2011-04-27 23:28:54 -07:00
|
|
|
JS_ASSERT(v.kind() != SSAValue::EMPTY);
|
|
|
|
|
2011-04-22 07:59:45 -07:00
|
|
|
for (unsigned i = 0; i < pending->length(); i++) {
|
|
|
|
if ((*pending)[i].slot == slot)
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!pending->append(SlotValue(slot, v)))
|
|
|
|
setOOM(cx);
|
|
|
|
}
|
|
|
|
|
2011-04-26 14:32:52 -07:00
|
|
|
void
|
Bug 708735 - Use <stdint.h> types in JSAPI and throughout SpiderMonkey. Continue to provide the {u,}int{8,16,32,64} and JS{Uint,Int}{8,16,32,64} integer types through a single header, however, for a simpler backout strategy -- and also to ease the transition for embedders. r=timeless on switching the jsd API to use the <stdint.h> types, r=luke, r=dmandelin
2011-12-08 19:54:10 -08:00
|
|
|
ScriptAnalysis::checkBranchTarget(JSContext *cx, uint32_t targetOffset,
|
|
|
|
Vector<uint32_t> &branchTargets,
|
2012-03-01 17:48:32 -08:00
|
|
|
SSAValueInfo *values, uint32_t stackDepth)
|
2011-04-26 14:32:52 -07:00
|
|
|
{
|
|
|
|
unsigned targetDepth = getCode(targetOffset).stackDepth;
|
|
|
|
JS_ASSERT(targetDepth <= stackDepth);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* If there is already an active branch to target, make sure its pending
|
|
|
|
* values reflect any changes made since the first branch. Otherwise, add a
|
|
|
|
* new pending branch and determine its pending values lazily.
|
|
|
|
*/
|
|
|
|
Vector<SlotValue> *&pending = getCode(targetOffset).pendingValues;
|
|
|
|
if (pending) {
|
|
|
|
for (unsigned i = 0; i < pending->length(); i++) {
|
|
|
|
SlotValue &v = (*pending)[i];
|
2012-02-23 13:01:27 -08:00
|
|
|
mergeValue(cx, targetOffset, values[v.slot].v, &v);
|
2011-04-26 14:32:52 -07:00
|
|
|
}
|
|
|
|
} else {
|
2012-03-01 17:48:32 -08:00
|
|
|
pending = cx->new_< Vector<SlotValue> >(cx);
|
|
|
|
if (!pending || !branchTargets.append(targetOffset)) {
|
2011-04-26 14:32:52 -07:00
|
|
|
setOOM(cx);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Make sure there is a pending entry for each value on the stack.
|
|
|
|
* The number of stack entries at join points is usually zero, and
|
|
|
|
* we don't want to look at the active branches while popping and
|
|
|
|
* pushing values in each opcode.
|
|
|
|
*/
|
|
|
|
for (unsigned i = 0; i < targetDepth; i++) {
|
Bug 708735 - Use <stdint.h> types in JSAPI and throughout SpiderMonkey. Continue to provide the {u,}int{8,16,32,64} and JS{Uint,Int}{8,16,32,64} integer types through a single header, however, for a simpler backout strategy -- and also to ease the transition for embedders. r=timeless on switching the jsd API to use the <stdint.h> types, r=luke, r=dmandelin
2011-12-08 19:54:10 -08:00
|
|
|
uint32_t slot = StackSlot(script, i);
|
2012-02-23 13:01:27 -08:00
|
|
|
checkPendingValue(cx, values[slot].v, slot, pending);
|
2011-04-26 14:32:52 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-12-24 06:21:52 -08:00
|
|
|
void
|
|
|
|
ScriptAnalysis::checkExceptionTarget(JSContext *cx, uint32_t catchOffset,
|
|
|
|
Vector<uint32_t> &exceptionTargets)
|
|
|
|
{
|
2012-02-23 13:01:27 -08:00
|
|
|
JS_ASSERT(getCode(catchOffset).exceptionEntry);
|
|
|
|
|
2011-12-24 06:21:52 -08:00
|
|
|
/*
|
|
|
|
* The catch offset will already be in the branch targets, just check
|
|
|
|
* whether this is already a known exception target.
|
|
|
|
*/
|
|
|
|
for (unsigned i = 0; i < exceptionTargets.length(); i++) {
|
|
|
|
if (exceptionTargets[i] == catchOffset)
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (!exceptionTargets.append(catchOffset))
|
|
|
|
setOOM(cx);
|
|
|
|
}
|
|
|
|
|
2011-04-22 07:59:45 -07:00
|
|
|
void
|
2012-02-23 13:01:27 -08:00
|
|
|
ScriptAnalysis::mergeBranchTarget(JSContext *cx, SSAValueInfo &value, uint32_t slot,
|
|
|
|
const Vector<uint32_t> &branchTargets, uint32_t currentOffset)
|
2011-04-22 07:59:45 -07:00
|
|
|
{
|
|
|
|
if (slot >= numSlots) {
|
|
|
|
/*
|
|
|
|
* There is no need to lazily check that there are pending values at
|
|
|
|
* branch targets for slots on the stack, these are added to pending
|
|
|
|
* eagerly.
|
|
|
|
*/
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
JS_ASSERT(trackSlot(slot));
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Before changing the value of a variable, make sure the old value is
|
|
|
|
* marked at the target of any branches jumping over the current opcode.
|
2012-02-23 13:01:27 -08:00
|
|
|
* Only look at new branch targets which have appeared since the last time
|
|
|
|
* the variable was written.
|
2011-04-22 07:59:45 -07:00
|
|
|
*/
|
2012-02-23 13:01:27 -08:00
|
|
|
for (int i = branchTargets.length() - 1; i >= value.branchSize; i--) {
|
|
|
|
if (branchTargets[i] <= currentOffset)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
const Bytecode &code = getCode(branchTargets[i]);
|
|
|
|
|
|
|
|
Vector<SlotValue> *pending = code.pendingValues;
|
|
|
|
checkPendingValue(cx, value.v, slot, pending);
|
2011-04-22 07:59:45 -07:00
|
|
|
}
|
2012-02-23 13:01:27 -08:00
|
|
|
|
|
|
|
value.branchSize = branchTargets.length();
|
2011-04-22 07:59:45 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2011-12-24 06:21:52 -08:00
|
|
|
ScriptAnalysis::mergeExceptionTarget(JSContext *cx, const SSAValue &value, uint32_t slot,
|
|
|
|
const Vector<uint32_t> &exceptionTargets)
|
|
|
|
{
|
|
|
|
JS_ASSERT(trackSlot(slot));
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Update the value at exception targets with the value of a variable
|
|
|
|
* before it is overwritten. Unlike mergeBranchTarget, this is done whether
|
|
|
|
* or not the overwritten value is the value of the variable at the
|
|
|
|
* original branch. Values for a variable which are written after the
|
|
|
|
* try block starts and overwritten before it is finished can still be
|
|
|
|
* seen at exception handlers via exception paths.
|
|
|
|
*/
|
|
|
|
for (unsigned i = 0; i < exceptionTargets.length(); i++) {
|
2012-01-20 16:13:23 -08:00
|
|
|
unsigned offset = exceptionTargets[i];
|
|
|
|
Vector<SlotValue> *pending = getCode(offset).pendingValues;
|
2011-12-24 06:21:52 -08:00
|
|
|
|
|
|
|
bool duplicate = false;
|
|
|
|
for (unsigned i = 0; i < pending->length(); i++) {
|
2012-01-20 16:13:23 -08:00
|
|
|
if ((*pending)[i].slot == slot) {
|
2011-12-24 06:21:52 -08:00
|
|
|
duplicate = true;
|
2012-01-20 16:13:23 -08:00
|
|
|
SlotValue &v = (*pending)[i];
|
|
|
|
mergeValue(cx, offset, value, &v);
|
|
|
|
break;
|
|
|
|
}
|
2011-12-24 06:21:52 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
if (!duplicate && !pending->append(SlotValue(slot, value)))
|
|
|
|
setOOM(cx);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-01-20 16:13:23 -08:00
|
|
|
void
|
2012-02-23 13:01:27 -08:00
|
|
|
ScriptAnalysis::mergeAllExceptionTargets(JSContext *cx, SSAValueInfo *values,
|
2012-01-20 16:13:23 -08:00
|
|
|
const Vector<uint32_t> &exceptionTargets)
|
|
|
|
{
|
|
|
|
for (unsigned i = 0; i < exceptionTargets.length(); i++) {
|
|
|
|
Vector<SlotValue> *pending = getCode(exceptionTargets[i]).pendingValues;
|
|
|
|
for (unsigned i = 0; i < pending->length(); i++) {
|
|
|
|
const SlotValue &v = (*pending)[i];
|
|
|
|
if (trackSlot(v.slot))
|
2012-02-23 13:01:27 -08:00
|
|
|
mergeExceptionTarget(cx, values[v.slot].v, v.slot, exceptionTargets);
|
2011-12-24 06:21:52 -08:00
|
|
|
}
|
|
|
|
}
|
2011-04-22 07:59:45 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
Bug 708735 - Use <stdint.h> types in JSAPI and throughout SpiderMonkey. Continue to provide the {u,}int{8,16,32,64} and JS{Uint,Int}{8,16,32,64} integer types through a single header, however, for a simpler backout strategy -- and also to ease the transition for embedders. r=timeless on switching the jsd API to use the <stdint.h> types, r=luke, r=dmandelin
2011-12-08 19:54:10 -08:00
|
|
|
ScriptAnalysis::freezeNewValues(JSContext *cx, uint32_t offset)
|
2011-04-22 07:59:45 -07:00
|
|
|
{
|
|
|
|
Bytecode &code = getCode(offset);
|
|
|
|
|
|
|
|
Vector<SlotValue> *pending = code.pendingValues;
|
|
|
|
code.pendingValues = NULL;
|
|
|
|
|
|
|
|
unsigned count = pending->length();
|
|
|
|
if (count == 0) {
|
2012-03-01 17:48:32 -08:00
|
|
|
cx->delete_(pending);
|
2011-04-22 07:59:45 -07:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2011-09-22 13:22:30 -07:00
|
|
|
code.newValues = cx->typeLifoAlloc().newArray<SlotValue>(count + 1);
|
2011-04-22 07:59:45 -07:00
|
|
|
if (!code.newValues) {
|
|
|
|
setOOM(cx);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
for (unsigned i = 0; i < count; i++)
|
|
|
|
code.newValues[i] = (*pending)[i];
|
|
|
|
code.newValues[count].slot = 0;
|
|
|
|
code.newValues[count].value.clear();
|
|
|
|
|
2012-03-01 17:48:32 -08:00
|
|
|
cx->delete_(pending);
|
2011-04-22 07:59:45 -07:00
|
|
|
}
|
|
|
|
|
2012-04-02 08:58:30 -07:00
|
|
|
struct NeedsArgsObjState
|
|
|
|
{
|
|
|
|
JSContext *cx;
|
|
|
|
Vector<SSAValue, 16> seen;
|
|
|
|
bool canOptimizeApply;
|
|
|
|
bool haveOptimizedApply;
|
|
|
|
NeedsArgsObjState(JSContext *cx)
|
|
|
|
: cx(cx), seen(cx), canOptimizeApply(true), haveOptimizedApply(false) {}
|
|
|
|
};
|
|
|
|
|
2012-01-17 16:35:12 -08:00
|
|
|
bool
|
2012-04-02 08:58:30 -07:00
|
|
|
ScriptAnalysis::needsArgsObj(NeedsArgsObjState &state, const SSAValue &v)
|
2012-01-17 16:35:12 -08:00
|
|
|
{
|
|
|
|
/*
|
|
|
|
* trackUseChain is false for initial values of variables, which
|
|
|
|
* cannot hold the script's arguments object.
|
|
|
|
*/
|
|
|
|
if (!trackUseChain(v))
|
2012-04-02 08:58:30 -07:00
|
|
|
return false;
|
2012-01-17 16:35:12 -08:00
|
|
|
|
2012-04-02 08:58:30 -07:00
|
|
|
for (unsigned i = 0; i < state.seen.length(); i++) {
|
|
|
|
if (v == state.seen[i])
|
|
|
|
return false;
|
2012-01-17 16:35:12 -08:00
|
|
|
}
|
2012-04-02 08:58:30 -07:00
|
|
|
if (!state.seen.append(v)) {
|
|
|
|
state.cx->compartment->types.setPendingNukeTypes(state.cx);
|
|
|
|
return true;
|
2012-01-17 16:35:12 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
SSAUseChain *use = useChain(v);
|
|
|
|
while (use) {
|
2012-04-02 08:58:30 -07:00
|
|
|
if (needsArgsObj(state, use))
|
|
|
|
return true;
|
2012-01-17 16:35:12 -08:00
|
|
|
use = use->next;
|
|
|
|
}
|
|
|
|
|
2012-04-02 08:58:30 -07:00
|
|
|
return false;
|
2012-01-17 16:35:12 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
2012-04-02 08:58:30 -07:00
|
|
|
ScriptAnalysis::needsArgsObj(NeedsArgsObjState &state, SSAUseChain *use)
|
2012-01-17 16:35:12 -08:00
|
|
|
{
|
|
|
|
if (!use->popped)
|
2012-04-02 08:58:30 -07:00
|
|
|
return needsArgsObj(state, SSAValue::PhiValue(use->offset, use->u.phi));
|
2012-01-17 16:35:12 -08:00
|
|
|
|
|
|
|
jsbytecode *pc = script->code + use->offset;
|
|
|
|
JSOp op = JSOp(*pc);
|
|
|
|
|
|
|
|
if (op == JSOP_POP || op == JSOP_POPN)
|
2012-04-02 08:58:30 -07:00
|
|
|
return false;
|
|
|
|
|
|
|
|
/* SplatApplyArgs can read fp->canonicalActualArg(i) directly. */
|
|
|
|
if (state.canOptimizeApply && op == JSOP_FUNAPPLY && GET_ARGC(pc) == 2 && use->u.which == 0) {
|
2012-02-23 13:59:10 -08:00
|
|
|
#ifdef JS_METHODJIT
|
2012-04-02 08:58:30 -07:00
|
|
|
JS_ASSERT(mjit::IsLowerableFunCallOrApply(pc));
|
2012-02-23 13:59:10 -08:00
|
|
|
#endif
|
2012-04-02 08:58:30 -07:00
|
|
|
state.haveOptimizedApply = true;
|
|
|
|
state.canOptimizeApply = false;
|
|
|
|
return false;
|
|
|
|
}
|
2012-01-17 16:35:12 -08:00
|
|
|
|
|
|
|
/* arguments[i] can read fp->canonicalActualArg(i) directly. */
|
2012-04-02 08:58:30 -07:00
|
|
|
if (!state.haveOptimizedApply && op == JSOP_GETELEM && use->u.which == 1) {
|
|
|
|
state.canOptimizeApply = false;
|
|
|
|
return false;
|
|
|
|
}
|
2012-01-17 16:35:12 -08:00
|
|
|
|
|
|
|
/* arguments.length length can read fp->numActualArgs() directly. */
|
2012-04-02 08:58:30 -07:00
|
|
|
if (!state.haveOptimizedApply && op == JSOP_LENGTH) {
|
|
|
|
state.canOptimizeApply = false;
|
|
|
|
return false;
|
|
|
|
}
|
2012-01-17 16:35:12 -08:00
|
|
|
|
|
|
|
/* Allow assignments to non-closed locals (but not arguments). */
|
|
|
|
|
|
|
|
if (op == JSOP_SETLOCAL) {
|
|
|
|
uint32_t slot = GetBytecodeSlot(script, pc);
|
2012-04-02 08:58:30 -07:00
|
|
|
if (!trackSlot(slot))
|
|
|
|
return true;
|
|
|
|
return needsArgsObj(state, SSAValue::PushedValue(use->offset, 0)) ||
|
|
|
|
needsArgsObj(state, SSAValue::WrittenVar(slot, use->offset));
|
2012-01-17 16:35:12 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
if (op == JSOP_GETLOCAL)
|
2012-04-02 08:58:30 -07:00
|
|
|
return needsArgsObj(state, SSAValue::PushedValue(use->offset, 0));
|
2012-01-17 16:35:12 -08:00
|
|
|
|
2012-04-02 08:58:30 -07:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
|
|
|
ScriptAnalysis::needsArgsObj(JSContext *cx)
|
|
|
|
{
|
|
|
|
JS_ASSERT(script->argumentsHasLocalBinding());
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Since let variables and dynamic name access are not tracked, we cannot
|
|
|
|
* soundly perform this analysis in their presence. Also, debuggers may
|
|
|
|
* want to see 'arguments', so assume every arguments object escapes.
|
|
|
|
*/
|
2012-02-23 13:59:10 -08:00
|
|
|
if (script->bindingsAccessedDynamically || script->numClosedArgs() > 0 ||
|
|
|
|
localsAliasStack() || cx->compartment->debugMode())
|
|
|
|
{
|
2012-04-02 08:58:30 -07:00
|
|
|
return true;
|
2012-02-23 13:59:10 -08:00
|
|
|
}
|
2012-04-02 08:58:30 -07:00
|
|
|
|
|
|
|
unsigned pcOff = script->argumentsBytecode() - script->code;
|
|
|
|
|
|
|
|
NeedsArgsObjState state(cx);
|
|
|
|
return needsArgsObj(state, SSAValue::PushedValue(pcOff, 0));
|
2012-01-17 16:35:12 -08:00
|
|
|
}
|
|
|
|
|
2011-05-05 13:59:29 -07:00
|
|
|
CrossSSAValue
|
|
|
|
CrossScriptSSA::foldValue(const CrossSSAValue &cv)
|
|
|
|
{
|
|
|
|
const Frame &frame = getFrame(cv.frame);
|
|
|
|
const SSAValue &v = cv.v;
|
|
|
|
|
|
|
|
JSScript *parentScript = NULL;
|
|
|
|
ScriptAnalysis *parentAnalysis = NULL;
|
|
|
|
if (frame.parent != INVALID_FRAME) {
|
|
|
|
parentScript = getFrame(frame.parent).script;
|
2011-07-28 09:16:53 -07:00
|
|
|
parentAnalysis = parentScript->analysis();
|
2011-05-05 13:59:29 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
if (v.kind() == SSAValue::VAR && v.varInitial() && parentScript) {
|
Bug 708735 - Use <stdint.h> types in JSAPI and throughout SpiderMonkey. Continue to provide the {u,}int{8,16,32,64} and JS{Uint,Int}{8,16,32,64} integer types through a single header, however, for a simpler backout strategy -- and also to ease the transition for embedders. r=timeless on switching the jsd API to use the <stdint.h> types, r=luke, r=dmandelin
2011-12-08 19:54:10 -08:00
|
|
|
uint32_t slot = v.varSlot();
|
2011-05-05 13:59:29 -07:00
|
|
|
if (slot >= ArgSlot(0) && slot < LocalSlot(frame.script, 0)) {
|
Bug 708735 - Use <stdint.h> types in JSAPI and throughout SpiderMonkey. Continue to provide the {u,}int{8,16,32,64} and JS{Uint,Int}{8,16,32,64} integer types through a single header, however, for a simpler backout strategy -- and also to ease the transition for embedders. r=timeless on switching the jsd API to use the <stdint.h> types, r=luke, r=dmandelin
2011-12-08 19:54:10 -08:00
|
|
|
uint32_t argc = GET_ARGC(frame.parentpc);
|
2011-05-05 13:59:29 -07:00
|
|
|
SSAValue argv = parentAnalysis->poppedValue(frame.parentpc, argc - 1 - (slot - ArgSlot(0)));
|
|
|
|
return foldValue(CrossSSAValue(frame.parent, argv));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (v.kind() == SSAValue::PUSHED) {
|
|
|
|
jsbytecode *pc = frame.script->code + v.pushedOffset();
|
2011-05-19 10:09:17 -07:00
|
|
|
|
2011-05-05 13:59:29 -07:00
|
|
|
switch (JSOp(*pc)) {
|
|
|
|
case JSOP_THIS:
|
|
|
|
if (parentScript) {
|
Bug 708735 - Use <stdint.h> types in JSAPI and throughout SpiderMonkey. Continue to provide the {u,}int{8,16,32,64} and JS{Uint,Int}{8,16,32,64} integer types through a single header, however, for a simpler backout strategy -- and also to ease the transition for embedders. r=timeless on switching the jsd API to use the <stdint.h> types, r=luke, r=dmandelin
2011-12-08 19:54:10 -08:00
|
|
|
uint32_t argc = GET_ARGC(frame.parentpc);
|
2011-05-05 13:59:29 -07:00
|
|
|
SSAValue thisv = parentAnalysis->poppedValue(frame.parentpc, argc);
|
|
|
|
return foldValue(CrossSSAValue(frame.parent, thisv));
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case JSOP_CALL: {
|
|
|
|
/*
|
|
|
|
* If there is a single inline callee with a single return site,
|
|
|
|
* propagate back to that.
|
|
|
|
*/
|
|
|
|
JSScript *callee = NULL;
|
Bug 708735 - Use <stdint.h> types in JSAPI and throughout SpiderMonkey. Continue to provide the {u,}int{8,16,32,64} and JS{Uint,Int}{8,16,32,64} integer types through a single header, however, for a simpler backout strategy -- and also to ease the transition for embedders. r=timeless on switching the jsd API to use the <stdint.h> types, r=luke, r=dmandelin
2011-12-08 19:54:10 -08:00
|
|
|
uint32_t calleeFrame = INVALID_FRAME;
|
2011-05-05 13:59:29 -07:00
|
|
|
for (unsigned i = 0; i < numFrames(); i++) {
|
|
|
|
if (iterFrame(i).parent == cv.frame && iterFrame(i).parentpc == pc) {
|
|
|
|
if (callee)
|
|
|
|
return cv; /* Multiple callees */
|
|
|
|
callee = iterFrame(i).script;
|
|
|
|
calleeFrame = iterFrame(i).index;
|
|
|
|
}
|
|
|
|
}
|
2011-07-28 09:16:53 -07:00
|
|
|
if (callee && callee->analysis()->numReturnSites() == 1) {
|
|
|
|
ScriptAnalysis *analysis = callee->analysis();
|
Bug 708735 - Use <stdint.h> types in JSAPI and throughout SpiderMonkey. Continue to provide the {u,}int{8,16,32,64} and JS{Uint,Int}{8,16,32,64} integer types through a single header, however, for a simpler backout strategy -- and also to ease the transition for embedders. r=timeless on switching the jsd API to use the <stdint.h> types, r=luke, r=dmandelin
2011-12-08 19:54:10 -08:00
|
|
|
uint32_t offset = 0;
|
2011-05-05 13:59:29 -07:00
|
|
|
while (offset < callee->length) {
|
|
|
|
jsbytecode *pc = callee->code + offset;
|
|
|
|
if (analysis->maybeCode(pc) && JSOp(*pc) == JSOP_RETURN)
|
|
|
|
return foldValue(CrossSSAValue(calleeFrame, analysis->poppedValue(pc, 0)));
|
|
|
|
offset += GetBytecodeLength(pc);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2011-08-10 16:06:36 -07:00
|
|
|
case JSOP_TOID: {
|
|
|
|
/*
|
|
|
|
* TOID acts as identity for integers, so to get better precision
|
|
|
|
* we should propagate its popped values forward if it acted as
|
|
|
|
* identity.
|
|
|
|
*/
|
|
|
|
ScriptAnalysis *analysis = frame.script->analysis();
|
|
|
|
SSAValue toidv = analysis->poppedValue(pc, 0);
|
|
|
|
if (analysis->getValueTypes(toidv)->getKnownTypeTag(cx) == JSVAL_TYPE_INT32)
|
|
|
|
return foldValue(CrossSSAValue(cv.frame, toidv));
|
2011-05-10 13:21:44 -07:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2011-05-05 13:59:29 -07:00
|
|
|
default:;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return cv;
|
|
|
|
}
|
|
|
|
|
2011-04-22 07:59:45 -07:00
|
|
|
#ifdef DEBUG
|
|
|
|
|
|
|
|
void
|
|
|
|
ScriptAnalysis::printSSA(JSContext *cx)
|
|
|
|
{
|
2011-07-19 07:21:33 -07:00
|
|
|
AutoEnterAnalysis enter(cx);
|
|
|
|
|
2011-04-22 07:59:45 -07:00
|
|
|
printf("\n");
|
|
|
|
|
|
|
|
for (unsigned offset = 0; offset < script->length; offset++) {
|
|
|
|
Bytecode *code = maybeCode(offset);
|
|
|
|
if (!code)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
jsbytecode *pc = script->code + offset;
|
2011-05-19 10:09:17 -07:00
|
|
|
|
2011-04-22 07:59:45 -07:00
|
|
|
PrintBytecode(cx, script, pc);
|
|
|
|
|
|
|
|
SlotValue *newv = code->newValues;
|
|
|
|
if (newv) {
|
|
|
|
while (newv->slot) {
|
|
|
|
if (newv->value.kind() != SSAValue::PHI || newv->value.phiOffset() != offset) {
|
|
|
|
newv++;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
printf(" phi ");
|
|
|
|
newv->value.print();
|
|
|
|
printf(" [");
|
|
|
|
for (unsigned i = 0; i < newv->value.phiLength(); i++) {
|
|
|
|
if (i)
|
|
|
|
printf(",");
|
|
|
|
newv->value.phiValue(i).print();
|
|
|
|
}
|
|
|
|
printf("]\n");
|
|
|
|
newv++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
unsigned nuses = GetUseCount(script, offset);
|
|
|
|
unsigned xuses = ExtendedUse(pc) ? nuses + 1 : nuses;
|
|
|
|
|
|
|
|
for (unsigned i = 0; i < xuses; i++) {
|
|
|
|
printf(" popped%d: ", i);
|
|
|
|
code->poppedValues[i].print();
|
|
|
|
printf("\n");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-05-19 12:56:17 -07:00
|
|
|
printf("\n");
|
2011-04-22 07:59:45 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
SSAValue::print() const
|
|
|
|
{
|
|
|
|
switch (kind()) {
|
|
|
|
|
|
|
|
case EMPTY:
|
|
|
|
printf("empty");
|
|
|
|
break;
|
|
|
|
|
|
|
|
case PUSHED:
|
|
|
|
printf("pushed:%05u#%u", pushedOffset(), pushedIndex());
|
|
|
|
break;
|
|
|
|
|
|
|
|
case VAR:
|
|
|
|
if (varInitial())
|
|
|
|
printf("initial:%u", varSlot());
|
|
|
|
else
|
|
|
|
printf("write:%05u", varOffset());
|
|
|
|
break;
|
|
|
|
|
|
|
|
case PHI:
|
|
|
|
printf("phi:%05u#%u", phiOffset(), phiSlot());
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
JS_NOT_REACHED("Bad kind");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-12-15 18:08:00 -08:00
|
|
|
void
|
|
|
|
ScriptAnalysis::assertMatchingDebugMode()
|
|
|
|
{
|
|
|
|
JS_ASSERT(!!script->compartment()->debugMode() == !!originalDebugMode_);
|
|
|
|
}
|
|
|
|
|
2011-04-22 07:59:45 -07:00
|
|
|
#endif /* DEBUG */
|
|
|
|
|
2010-10-26 12:00:54 -07:00
|
|
|
} /* namespace analyze */
|
|
|
|
} /* namespace js */
|