mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-10-14 05:45:37 +00:00
Bug 606890 - Profile short loops twice (r=dmandelin)
This commit is contained in:
parent
123828cfe4
commit
bf5b72e325
@ -662,6 +662,13 @@ public:
|
||||
return Jump(m_assembler.jmp(ARMCondition(cond)));
|
||||
}
|
||||
|
||||
Jump branchSub32(Condition cond, Imm32 imm, Address dest)
|
||||
{
|
||||
ASSERT((cond == Overflow) || (cond == Signed) || (cond == Zero) || (cond == NonZero));
|
||||
sub32(imm, dest);
|
||||
return Jump(m_assembler.jmp(ARMCondition(cond)));
|
||||
}
|
||||
|
||||
Jump branchNeg32(Condition cond, RegisterID srcDest)
|
||||
{
|
||||
ASSERT((cond == Overflow) || (cond == Signed) || (cond == Zero) || (cond == NonZero));
|
||||
|
@ -16495,7 +16495,8 @@ LoopProfile::LoopProfile(JSStackFrame *entryfp, jsbytecode *top, jsbytecode *bot
|
||||
entryfp(entryfp),
|
||||
top(top),
|
||||
bottom(bottom),
|
||||
hits(0)
|
||||
hits(0),
|
||||
undecided(false)
|
||||
{
|
||||
reset();
|
||||
}
|
||||
@ -16608,9 +16609,21 @@ LookupOrAddProfile(JSContext *cx, TraceMonitor *tm, void** traceData, uintN *tra
|
||||
return prof;
|
||||
}
|
||||
|
||||
static LoopProfile *
|
||||
LookupLoopProfile(JSContext *cx, jsbytecode *pc)
|
||||
{
|
||||
TraceMonitor* tm = &JS_TRACE_MONITOR(cx);
|
||||
LoopProfileMap &table = *tm->loopProfiles;
|
||||
if (LoopProfileMap::Ptr p = table.lookup(pc)) {
|
||||
JS_ASSERT(p->value->top == pc);
|
||||
return p->value;
|
||||
} else
|
||||
return NULL;
|
||||
}
|
||||
|
||||
JS_REQUIRES_STACK TracePointAction
|
||||
MonitorTracePoint(JSContext *cx, uintN& inlineCallCount, bool* blacklist,
|
||||
void** traceData, uintN *traceEpoch)
|
||||
void** traceData, uintN *traceEpoch, uint32 *loopCounter, uint32 hits)
|
||||
{
|
||||
if (!cx->profilingEnabled)
|
||||
return RecordTracePoint(cx, inlineCallCount, blacklist, true);
|
||||
@ -16625,13 +16638,15 @@ MonitorTracePoint(JSContext *cx, uintN& inlineCallCount, bool* blacklist,
|
||||
if (tm->profile)
|
||||
return TPA_Nothing;
|
||||
|
||||
jsbytecode* pc = cx->regs->pc;
|
||||
LoopProfile *prof = LookupOrAddProfile(cx, tm, traceData, traceEpoch);
|
||||
if (!prof) {
|
||||
*blacklist = true;
|
||||
return TPA_Nothing;
|
||||
}
|
||||
|
||||
if (prof->hits++ < PROFILE_HOTLOOP)
|
||||
prof->hits += hits;
|
||||
if (prof->hits < PROFILE_HOTLOOP)
|
||||
return TPA_Nothing;
|
||||
|
||||
AutoRetBlacklist autoRetBlacklist(cx->regs->pc, blacklist);
|
||||
@ -16653,7 +16668,14 @@ MonitorTracePoint(JSContext *cx, uintN& inlineCallCount, bool* blacklist,
|
||||
return TPA_Error;
|
||||
|
||||
JS_ASSERT(!cx->isExceptionPending());
|
||||
|
||||
|
||||
/* Look it up again since a reset may have happened during Interpret. */
|
||||
prof = LookupLoopProfile(cx, pc);
|
||||
if (prof && prof->undecided) {
|
||||
*loopCounter = 3000;
|
||||
prof->reset();
|
||||
}
|
||||
|
||||
return TPA_RanStuff;
|
||||
}
|
||||
|
||||
@ -16855,18 +16877,6 @@ LoopProfile::profileOperation(JSContext* cx, JSOp op)
|
||||
return ProfContinue;
|
||||
}
|
||||
|
||||
static LoopProfile *
|
||||
LookupLoopProfile(JSContext *cx, jsbytecode *pc)
|
||||
{
|
||||
TraceMonitor* tm = &JS_TRACE_MONITOR(cx);
|
||||
LoopProfileMap &table = *tm->loopProfiles;
|
||||
if (LoopProfileMap::Ptr p = table.lookup(pc)) {
|
||||
JS_ASSERT(p->value->top == pc);
|
||||
return p->value;
|
||||
} else
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/*
|
||||
* Returns true if the loop would probably take a long time to
|
||||
* compile.
|
||||
@ -16877,6 +16887,9 @@ LoopProfile::isCompilationExpensive(JSContext *cx, uintN depth)
|
||||
if (depth == 0)
|
||||
return true;
|
||||
|
||||
if (!profiled)
|
||||
return false;
|
||||
|
||||
/* Too many ops to compile? */
|
||||
if (numSelfOps == MAX_PROFILE_OPS)
|
||||
return true;
|
||||
@ -16888,7 +16901,7 @@ LoopProfile::isCompilationExpensive(JSContext *cx, uintN depth)
|
||||
/* Ensure that inner loops aren't too expensive. */
|
||||
for (uintN i=0; i<numInnerLoops; i++) {
|
||||
LoopProfile *prof = LookupLoopProfile(cx, innerLoops[i].top);
|
||||
if (prof && prof->isCompilationExpensive(cx, depth-1))
|
||||
if (!prof || prof->isCompilationExpensive(cx, depth-1))
|
||||
return true;
|
||||
}
|
||||
|
||||
@ -16907,13 +16920,16 @@ LoopProfile::isCompilationUnprofitable(JSContext *cx, uintN depth)
|
||||
if (depth == 0)
|
||||
return true;
|
||||
|
||||
if (!profiled)
|
||||
return false;
|
||||
|
||||
if (numAllOps < 15 && allOps[OP_FWDJUMP])
|
||||
return true;
|
||||
|
||||
/* Ensure that inner loops aren't fleeting. */
|
||||
for (uintN i=0; i<numInnerLoops; i++) {
|
||||
LoopProfile *prof = LookupLoopProfile(cx, innerLoops[i].top);
|
||||
if (prof && prof->isCompilationUnprofitable(cx, depth-1))
|
||||
if (!prof || prof->isCompilationUnprofitable(cx, depth-1))
|
||||
return true;
|
||||
}
|
||||
|
||||
@ -16924,7 +16940,12 @@ LoopProfile::isCompilationUnprofitable(JSContext *cx, uintN depth)
|
||||
void
|
||||
LoopProfile::decide(JSContext *cx)
|
||||
{
|
||||
bool wasUndecided = undecided;
|
||||
bool wasTraceOK = traceOK;
|
||||
|
||||
profiled = true;
|
||||
traceOK = false;
|
||||
undecided = false;
|
||||
|
||||
#ifdef DEBUG
|
||||
uintN line = js_PCToLineNumber(cx, entryScript, top);
|
||||
@ -16956,7 +16977,6 @@ LoopProfile::decide(JSContext *cx)
|
||||
debug_only_printf(LC_TMProfiler, "FEATURE selfOpsMult %g\n", numSelfOpsMult);
|
||||
#endif
|
||||
|
||||
traceOK = false;
|
||||
if (count(OP_RECURSIVE)) {
|
||||
debug_only_print0(LC_TMProfiler, "NOTRACE: recursive\n");
|
||||
} else if (count(OP_EVAL)) {
|
||||
@ -16968,12 +16988,17 @@ LoopProfile::decide(JSContext *cx)
|
||||
} else if (isCompilationExpensive(cx, 4)) {
|
||||
debug_only_print0(LC_TMProfiler, "NOTRACE: expensive\n");
|
||||
} else if (maybeShortLoop && numInnerLoops < 2) {
|
||||
debug_only_print0(LC_TMProfiler, "NOTRACE: maybe short\n");
|
||||
if (wasUndecided) {
|
||||
debug_only_print0(LC_TMProfiler, "NOTRACE: maybe short\n");
|
||||
} else {
|
||||
debug_only_print0(LC_TMProfiler, "UNDECIDED: maybe short\n");
|
||||
undecided = true; /* Profile the loop again to see if it's still short. */
|
||||
}
|
||||
} else {
|
||||
uintN goodOps = 0;
|
||||
|
||||
/* The tracer handles these ops well because of type specialization. */
|
||||
goodOps += count(OP_FLOAT)*10 + count(OP_BIT)*10 + count(OP_INT)*5;
|
||||
goodOps += count(OP_FLOAT)*10 + count(OP_BIT)*11 + count(OP_INT)*5;
|
||||
|
||||
/* The tracer handles these ops well because of inlining. */
|
||||
goodOps += (count(OP_CALL) + count(OP_NEW))*20;
|
||||
@ -17002,7 +17027,6 @@ LoopProfile::decide(JSContext *cx)
|
||||
* if we trace the inner loop, we will never call that trace
|
||||
* on its own. We'll only call it from this trace.
|
||||
*/
|
||||
prof->profiled = true;
|
||||
prof->traceOK = true;
|
||||
if (IsBlacklisted(loop.top)) {
|
||||
debug_only_printf(LC_TMProfiler, "Unblacklisting at %d\n",
|
||||
@ -17013,14 +17037,15 @@ LoopProfile::decide(JSContext *cx)
|
||||
}
|
||||
}
|
||||
|
||||
if (!traceOK) {
|
||||
execOK = traceOK;
|
||||
traceOK = wasTraceOK || traceOK;
|
||||
|
||||
if (!traceOK && !undecided) {
|
||||
debug_only_printf(LC_TMProfiler, "Blacklisting at %d\n", line);
|
||||
Blacklist(top);
|
||||
}
|
||||
|
||||
debug_only_print0(LC_TMProfiler, "\n");
|
||||
|
||||
execOK = traceOK;
|
||||
}
|
||||
|
||||
JS_REQUIRES_STACK MonitorResult
|
||||
|
@ -685,6 +685,9 @@ public:
|
||||
/* Whether we have run a complete profile of the loop. */
|
||||
bool profiled;
|
||||
|
||||
/* Sometimes we can't decide in one profile run whether to trace, so we set undecided. */
|
||||
bool undecided;
|
||||
|
||||
/* If we have profiled the loop, this saves the decision of whether to trace it. */
|
||||
bool traceOK;
|
||||
|
||||
@ -1697,7 +1700,7 @@ RecordTracePoint(JSContext*, uintN& inlineCallCount, bool* blacklist);
|
||||
|
||||
extern JS_REQUIRES_STACK TracePointAction
|
||||
MonitorTracePoint(JSContext*, uintN& inlineCallCount, bool* blacklist,
|
||||
void** traceData, uintN *traceEpoch);
|
||||
void** traceData, uintN *traceEpoch, uint32 *loopCounter, uint32 hits);
|
||||
|
||||
extern JS_REQUIRES_STACK TraceRecorder::AbortResult
|
||||
AbortRecording(JSContext* cx, const char* reason);
|
||||
|
@ -58,6 +58,7 @@
|
||||
#include "jscompartment.h"
|
||||
#include "jsobjinlines.h"
|
||||
#include "jsopcodeinlines.h"
|
||||
#include "jshotloop.h"
|
||||
|
||||
#include "jsautooplen.h"
|
||||
|
||||
@ -625,6 +626,10 @@ mjit::Compiler::finishThisUp(JITScript **jitp)
|
||||
scriptTICs[i].hasSlowTraceHint = traceICs[i].slowTraceHint.isSet();
|
||||
if (traceICs[i].slowTraceHint.isSet())
|
||||
scriptTICs[i].slowTraceHint = stubCode.locationOf(traceICs[i].slowTraceHint.get());
|
||||
#ifdef JS_TRACER
|
||||
scriptTICs[i].loopCounterStart = GetHotloop(cx);
|
||||
#endif
|
||||
scriptTICs[i].loopCounter = scriptTICs[i].loopCounterStart;
|
||||
|
||||
stubCode.patch(traceICs[i].addrLabel, &scriptTICs[i]);
|
||||
}
|
||||
@ -4804,6 +4809,11 @@ mjit::Compiler::jumpAndTrace(Jump j, jsbytecode *target, Jump *slow)
|
||||
# if JS_MONOIC
|
||||
ic.addrLabel = stubcc.masm.moveWithPatch(ImmPtr(NULL), Registers::ArgReg1);
|
||||
traceICs[index] = ic;
|
||||
|
||||
Jump nonzero = stubcc.masm.branchSub32(Assembler::NonZero, Imm32(1),
|
||||
Address(Registers::ArgReg1,
|
||||
offsetof(TraceICInfo, loopCounter)));
|
||||
stubcc.jumpInScript(nonzero, target);
|
||||
# endif
|
||||
|
||||
/* Save and restore compiler-tracked PC, so cx->regs is right in InvokeTracer. */
|
||||
@ -4818,11 +4828,10 @@ mjit::Compiler::jumpAndTrace(Jump j, jsbytecode *target, Jump *slow)
|
||||
|
||||
Jump no = stubcc.masm.branchTestPtr(Assembler::Zero, Registers::ReturnReg,
|
||||
Registers::ReturnReg);
|
||||
if (!stubcc.jumpInScript(no, target))
|
||||
return false;
|
||||
restoreFrameRegs(stubcc.masm);
|
||||
stubcc.masm.jump(Registers::ReturnReg);
|
||||
no.linkTo(stubcc.masm.label(), &stubcc.masm);
|
||||
if (!stubcc.jumpInScript(stubcc.masm.jump(), target))
|
||||
return false;
|
||||
#endif
|
||||
return true;
|
||||
}
|
||||
|
@ -964,17 +964,26 @@ RunTracer(VMFrame &f)
|
||||
uintN inlineCallCount = 0;
|
||||
void **traceData;
|
||||
uintN *traceEpoch;
|
||||
uint32 *loopCounter;
|
||||
uint32 hits;
|
||||
#if JS_MONOIC
|
||||
traceData = &tic.traceData;
|
||||
traceEpoch = &tic.traceEpoch;
|
||||
loopCounter = &tic.loopCounter;
|
||||
*loopCounter = 1;
|
||||
hits = tic.loopCounterStart;
|
||||
#else
|
||||
traceData = NULL;
|
||||
traceEpoch = NULL;
|
||||
loopCounter = NULL;
|
||||
hits = 1;
|
||||
#endif
|
||||
tpa = MonitorTracePoint(f.cx, inlineCallCount, &blacklist, traceData, traceEpoch);
|
||||
tpa = MonitorTracePoint(f.cx, inlineCallCount, &blacklist, traceData, traceEpoch,
|
||||
loopCounter, hits);
|
||||
JS_ASSERT(!TRACE_RECORDER(cx));
|
||||
|
||||
#if JS_MONOIC
|
||||
tic.loopCounterStart = *loopCounter;
|
||||
if (blacklist)
|
||||
DisableTraceHint(f, tic);
|
||||
#endif
|
||||
|
@ -153,6 +153,8 @@ struct TraceICInfo {
|
||||
/* This data is used by the tracing JIT. */
|
||||
void *traceData;
|
||||
uintN traceEpoch;
|
||||
uint32 loopCounter;
|
||||
uint32 loopCounterStart;
|
||||
|
||||
bool initialized : 1;
|
||||
bool hasSlowTraceHint : 1;
|
||||
|
Loading…
Reference in New Issue
Block a user