Bug 865059 - Don't analyze scripts until they are compiled by baseline when JM is disabled, r=jandem.

This commit is contained in:
Brian Hackett 2013-05-02 08:35:01 -06:00
parent 7f51fee2cd
commit f5117c4b6d
15 changed files with 126 additions and 26 deletions

View File

@ -4367,6 +4367,9 @@ EmitNormalFor(JSContext *cx, BytecodeEmitter *bce, ParseNode *pn, ptrdiff_t top)
if (EmitJump(cx, bce, op, top - bce->offset()) < 0)
return false;
if (!bce->tryNoteList.append(JSTRY_LOOP, bce->stackDepth, top, bce->offset()))
return false;
/* Now fixup all breaks and continues. */
return PopStatementBCE(cx, bce);
}
@ -4553,6 +4556,9 @@ EmitDo(JSContext *cx, BytecodeEmitter *bce, ParseNode *pn)
if (beq < 0)
return false;
if (!bce->tryNoteList.append(JSTRY_LOOP, bce->stackDepth, top, bce->offset()))
return false;
/*
* Be careful: We must set noteIndex2 before noteIndex in case the noteIndex
* note gets bigger.
@ -4609,6 +4615,9 @@ EmitWhile(JSContext *cx, BytecodeEmitter *bce, ParseNode *pn, ptrdiff_t top)
if (beq < 0)
return false;
if (!bce->tryNoteList.append(JSTRY_LOOP, bce->stackDepth, top, bce->offset()))
return false;
if (!SetSrcNoteOffset(cx, bce, noteIndex, 0, beq - jmp))
return false;

View File

@ -435,6 +435,9 @@ HandleException(JSContext *cx, const IonFrameIterator &frame, ResumeFromExceptio
break;
}
case JSTRY_LOOP:
break;
default:
JS_NOT_REACHED("Invalid try note");
}

View File

@ -405,7 +405,7 @@ ScriptAnalysis::analyzeBytecode(JSContext *cx)
if (catchOffset > forwardCatch)
forwardCatch = catchOffset;
if (tn->kind != JSTRY_ITER) {
if (tn->kind != JSTRY_ITER && tn->kind != JSTRY_LOOP) {
if (!addJump(cx, catchOffset, &nextOffset, &forwardJump, &forwardLoop, stackDepth))
return;
getCode(catchOffset).exceptionEntry = true;
@ -1507,7 +1507,7 @@ ScriptAnalysis::analyzeSSA(JSContext *cx)
if (startOffset == offset + 1) {
unsigned catchOffset = startOffset + tn->length;
if (tn->kind != JSTRY_ITER) {
if (tn->kind != JSTRY_ITER && tn->kind != JSTRY_LOOP) {
checkBranchTarget(cx, catchOffset, branchTargets, values, stackDepth);
checkExceptionTarget(cx, catchOffset, exceptionTargets);
}

View File

@ -1752,6 +1752,7 @@ struct JSContext : js::ContextFriendFields,
#endif
inline bool typeInferenceEnabled() const;
inline bool jaegerCompilationAllowed() const;
void updateJITEnabled();

View File

@ -411,6 +411,12 @@ JSContext::typeInferenceEnabled() const
return compartment->zone()->types.inferenceEnabled;
}
inline bool
JSContext::jaegerCompilationAllowed() const
{
return compartment->zone()->types.jaegerCompilationAllowed;
}
inline js::Handle<js::GlobalObject*>
JSContext::global() const
{

View File

@ -2467,10 +2467,12 @@ TypeZone::init(JSContext *cx)
!cx->hasOption(JSOPTION_TYPE_INFERENCE) ||
!cx->runtime->jitSupportsFloatingPoint)
{
jaegerCompilationAllowed = true;
return;
}
inferenceEnabled = true;
jaegerCompilationAllowed = cx->hasOption(JSOPTION_METHODJIT);
}
TypeObject *
@ -2692,13 +2694,28 @@ types::UseNewTypeForInitializer(JSContext *cx, JSScript *script, jsbytecode *pc,
if (key != JSProto_Object && !(key >= JSProto_Int8Array && key <= JSProto_Uint8ClampedArray))
return GenericObject;
AutoEnterAnalysis enter(cx);
/*
* All loops in the script will have a JSTRY_ITER or JSTRY_LOOP try note
* indicating their boundary.
*/
if (!script->ensureRanAnalysis(cx))
return GenericObject;
if (!script->hasTrynotes())
return SingletonObject;
if (script->analysis()->getCode(pc).inLoop)
return GenericObject;
unsigned offset = pc - script->code;
JSTryNote *tn = script->trynotes()->vector;
JSTryNote *tnlimit = tn + script->trynotes()->length;
for (; tn < tnlimit; tn++) {
if (tn->kind != JSTRY_ITER && tn->kind != JSTRY_LOOP)
continue;
unsigned startOffset = script->mainOffset + tn->start;
unsigned endOffset = startOffset + tn->length;
if (offset >= startOffset && offset < endOffset)
return GenericObject;
}
return SingletonObject;
}
@ -5611,8 +5628,16 @@ types::MarkIteratorUnknownSlow(JSContext *cx)
if (JSOp(*pc) != JSOP_ITER)
return;
if (IgnoreTypeChanges(cx, script))
return;
AutoEnterAnalysis enter(cx);
if (!script->ensureRanAnalysis(cx)) {
cx->compartment->types.setPendingNukeTypes(cx);
return;
}
/*
* This script is iterating over an actual Iterator or Generator object, or
* an object with a custom __iterator__ hook. In such cases 'for in' loops
@ -5696,6 +5721,10 @@ void
types::TypeDynamicResult(JSContext *cx, JSScript *script, jsbytecode *pc, Type type)
{
JS_ASSERT(cx->typeInferenceEnabled());
if (IgnoreTypeChanges(cx, script))
return;
AutoEnterAnalysis enter(cx);
/* Directly update associated type sets for applicable bytecodes. */
@ -5801,6 +5830,9 @@ types::TypeMonitorResult(JSContext *cx, JSScript *script, jsbytecode *pc, const
if (!(js_CodeSpec[*pc].format & JOF_TYPESET))
return;
if (IgnoreTypeChanges(cx, script))
return;
AutoEnterAnalysis enter(cx);
if (!script->ensureRanAnalysis(cx)) {

View File

@ -1466,6 +1466,13 @@ struct TypeZone
/* Whether type inference is enabled in this compartment. */
bool inferenceEnabled;
/*
* JM compilation is allowed only if script analysis has been used to
* monitor the behavior of all scripts in this zone since its creation.
* OSR in JM requires this property.
*/
bool jaegerCompilationAllowed;
TypeZone(JS::Zone *zone);
~TypeZone();
void init(JSContext *cx);

View File

@ -573,6 +573,21 @@ MarkIteratorUnknown(JSContext *cx)
MarkIteratorUnknownSlow(cx);
}
/*
* Return whether new type information in the specified script should be
* ignored. Tracking new types in a script requires the script to be analyzed,
* which can consume a large amount of memory when dealing with scripts that
* don't run long enough to be compiled (as is the case for the majority of
* executed scripts in web code).
*/
inline bool
IgnoreTypeChanges(JSContext *cx, JSScript *script)
{
return !script->hasAnalysis() &&
!cx->jaegerCompilationAllowed() &&
script->analyzedArgsUsage();
}
void TypeMonitorCallSlow(JSContext *cx, JSObject *callee, const CallArgs &args,
bool constructing);
@ -586,6 +601,8 @@ TypeMonitorCall(JSContext *cx, const js::CallArgs &args, bool constructing)
if (args.callee().isFunction()) {
JSFunction *fun = args.callee().toFunction();
if (fun->isInterpreted()) {
if (IgnoreTypeChanges(cx, fun->nonLazyScript()))
return true;
if (!fun->nonLazyScript()->ensureRanAnalysis(cx))
return false;
if (cx->typeInferenceEnabled())

View File

@ -565,9 +565,11 @@ js::ExecuteKernel(JSContext *cx, HandleScript script, JSObject &scopeChainArg, c
if (!cx->stack.pushExecuteFrame(cx, script, thisv, scopeChain, type, evalInFrame, &efg))
return false;
if (!script->ensureRanAnalysis(cx))
return false;
TypeScript::SetThis(cx, script, efg.fp()->thisValue());
if (!types::IgnoreTypeChanges(cx, script)) {
if (!script->ensureRanAnalysis(cx))
return false;
TypeScript::SetThis(cx, script, efg.fp()->thisValue());
}
Probes::startExecution(script);
bool ok = RunScript(cx, efg.fp());
@ -3366,7 +3368,11 @@ END_CASE(JSOP_ARRAYPUSH)
regs.sp -= 1;
if (!ok)
goto error;
break;
}
case JSTRY_LOOP:
break;
}
}

View File

@ -1520,8 +1520,12 @@ js::CreateThisForFunctionWithProto(JSContext *cx, HandleObject callee, JSObject
}
if (res && cx->typeInferenceEnabled()) {
RootedScript script(cx, callee->toFunction()->nonLazyScript());
TypeScript::SetThis(cx, script, types::Type::ObjectType(res));
JSScript *script = callee->toFunction()->nonLazyScript();
if (!types::IgnoreTypeChanges(cx, script)) {
if (!script->ensureRanAnalysis(cx))
return NULL;
TypeScript::SetThis(cx, script, types::Type::ObjectType(res));
}
}
return res;
@ -1547,8 +1551,12 @@ js::CreateThisForFunction(JSContext *cx, HandleObject callee, bool newType)
/* Reshape the singleton before passing it as the 'this' value. */
JSObject::clear(cx, nobj);
RootedScript calleeScript(cx, callee->toFunction()->nonLazyScript());
TypeScript::SetThis(cx, calleeScript, types::Type::ObjectType(nobj));
JSScript *calleeScript = callee->toFunction()->nonLazyScript();
if (!IgnoreTypeChanges(cx, calleeScript)) {
if (!calleeScript->ensureRanAnalysis(cx))
return NULL;
TypeScript::SetThis(cx, calleeScript, types::Type::ObjectType(nobj));
}
return nobj;
}

View File

@ -49,12 +49,15 @@ namespace analyze {
/*
* Type of try note associated with each catch or finally block, and also with
* for-in loops.
* for-in and other kinds of loops. Non-for-in loops do not need these notes
* for exception unwinding, but storing their boundaries here is helpful for
* heuristics that need to know whether a given op is inside a loop.
*/
typedef enum JSTryNoteKind {
JSTRY_CATCH,
JSTRY_FINALLY,
JSTRY_ITER
JSTRY_ITER,
JSTRY_LOOP
} JSTryNoteKind;
/*
@ -64,9 +67,9 @@ struct JSTryNote {
uint8_t kind; /* one of JSTryNoteKind */
uint8_t padding; /* explicit padding on uint16_t boundary */
uint16_t stackDepth; /* stack depth upon exception handler entry */
uint32_t start; /* start of the try statement or for-in loop
uint32_t start; /* start of the try statement or loop
relative to script->main */
uint32_t length; /* length of the try statement or for-in loop */
uint32_t length; /* length of the try statement or loop */
};
namespace js {

View File

@ -121,6 +121,8 @@ mjit::Compiler::Compiler(JSContext *cx, JSScript *outerScript,
gcNumber(cx->runtime->gcNumber),
pcLengths(NULL)
{
JS_ASSERT(cx->jaegerCompilationAllowed());
if (!IsIonEnabled(cx)) {
/* Once a script starts getting really hot we will inline calls in it. */
if (!debugMode() && cx->typeInferenceEnabled() && globalObj &&
@ -994,6 +996,9 @@ mjit::CanMethodJIT(JSContext *cx, JSScript *script, jsbytecode *pc,
if (!cx->methodJitEnabled)
return Compile_Abort;
if (!cx->jaegerCompilationAllowed())
return Compile_Abort;
#ifdef JS_ION
if (ion::IsBaselineEnabled(cx) || ion::IsEnabled(cx))
return Compile_Abort;

View File

@ -115,7 +115,11 @@ FindExceptionHandler(JSContext *cx)
cx->regs().sp -= 1;
if (!ok)
goto error;
break;
}
case JSTRY_LOOP:
break;
}
}
} else {

View File

@ -4927,11 +4927,6 @@ ProcessArgs(JSContext *cx, JSObject *obj_, OptionParser *op)
if (op->getBoolOption('s'))
JS_ToggleOptions(cx, JSOPTION_STRICT);
if (op->getBoolOption("no-jm")) {
enableMethodJit = false;
JS_ToggleOptions(cx, JSOPTION_METHODJIT);
}
if (op->getBoolOption('d')) {
JS_SetRuntimeDebugMode(JS_GetRuntime(cx), true);
JS_SetDebugMode(cx, true);
@ -5121,13 +5116,17 @@ Shell(JSContext *cx, OptionParser *op, char **envp)
JSAutoRequest ar(cx);
/*
* First check to see if type inference is enabled. This flag must be set
* on the compartment when it is constructed.
* First check to see if type inference and JM are enabled. These flags
* must be set on the compartment when it is constructed.
*/
if (op->getBoolOption("no-ti")) {
enableTypeInference = false;
JS_ToggleOptions(cx, JSOPTION_TYPE_INFERENCE);
}
if (op->getBoolOption("no-jm")) {
enableMethodJit = false;
JS_ToggleOptions(cx, JSOPTION_METHODJIT);
}
RootedObject glob(cx);
glob = NewGlobalObject(cx, NULL);

View File

@ -26,7 +26,7 @@ namespace js {
* and saved versions. If deserialization fails, the data should be
* invalidated if possible.
*/
static const uint32_t XDR_BYTECODE_VERSION = uint32_t(0xb973c0de - 141);
static const uint32_t XDR_BYTECODE_VERSION = uint32_t(0xb973c0de - 142);
class XDRBuffer {
public: