Bug 949916 - Fix race between off-main-thread-compilation and PJS. (r=bhackett)

This commit is contained in:
Shu-yu Guo 2013-12-12 23:23:57 -08:00
parent 873a319451
commit f2441f1bc5
4 changed files with 21 additions and 9 deletions

View File

@ -2454,8 +2454,8 @@ InvalidateActivation(FreeOp *fop, uint8_t *ionTop, bool invalidateAll)
IonSpew(IonSpew_Invalidate, "END invalidating activation");
}
static void
StopOffThreadCompilation(JSCompartment *comp)
void
jit::StopAllOffThreadCompilations(JSCompartment *comp)
{
if (!comp->jitCompartment())
return;
@ -2467,7 +2467,7 @@ void
jit::InvalidateAll(FreeOp *fop, Zone *zone)
{
for (CompartmentsInZoneIter comp(zone); !comp.done(); comp.next())
StopOffThreadCompilation(comp);
StopAllOffThreadCompilations(comp);
for (JitActivationIterator iter(fop->runtime()); !iter.done(); ++iter) {
if (iter.activation()->compartment()->zone() == zone) {
@ -2845,10 +2845,10 @@ AutoDebugModeInvalidation::~AutoDebugModeInvalidation()
FreeOp *fop = rt->defaultFreeOp();
if (comp_) {
StopOffThreadCompilation(comp_);
StopAllOffThreadCompilations(comp_);
} else {
for (CompartmentsInZoneIter comp(zone_); !comp.done(); comp.next())
StopOffThreadCompilation(comp);
StopAllOffThreadCompilations(comp);
}
if (invalidateStack) {

View File

@ -391,6 +391,7 @@ CodeGenerator *CompileBackEnd(MIRGenerator *mir, MacroAssembler *maybeMasm = nul
void AttachFinishedCompilations(JSContext *cx);
void FinishOffThreadBuilder(IonBuilder *builder);
void StopAllOffThreadCompilations(JSCompartment *comp);
static inline bool
IsIonEnabled(JSContext *cx)

View File

@ -767,14 +767,14 @@ WorkerThread::handleIonWorkload(WorkerThreadState &state)
FinishOffThreadIonCompile(ionBuilder);
ionBuilder = nullptr;
// Notify the main thread in case it is waiting for the compilation to finish.
state.notifyAll(WorkerThreadState::CONSUMER);
// Ping the main thread so that the compiled code can be incorporated
// at the next operation callback. Don't interrupt Ion code for this, as
// this incorporation can be delayed indefinitely without affecting
// performance as long as the main thread is actually executing Ion code.
runtime->triggerOperationCallback(JSRuntime::TriggerCallbackAnyThreadDontStopIon);
// Notify the main thread in case it is waiting for the compilation to finish.
state.notifyAll(WorkerThreadState::CONSUMER);
}
void

View File

@ -867,8 +867,19 @@ js::ParallelDo::compileForParallelExecution(ExecutionStatus *status)
}
}
}
if (allScriptsPresent)
if (allScriptsPresent) {
// For testing modes, we want to make sure that all off thread
// compilation tasks are finished, so we don't race with
// off-main-thread-compilation setting an interrupt flag while we
// are in the middle of a test, causing unexpected bailouts.
if (mode_ != ForkJoinModeNormal) {
StopAllOffThreadCompilations(cx_->compartment());
if (!js_HandleExecutionInterrupt(cx_))
return fatalError(status);
}
break;
}
}
Spew(SpewCompile, "Compilation complete (final worklist length %d)",