Bug 1233331 - CodeGenerator: Prepare the invalidation of the recompileInfo as soon as the contraints are recorded. r=jandem

This commit is contained in:
Nicolas B. Pierron 2016-01-11 14:55:16 +00:00
Родитель c195534afa
Коммит 3bc5e9cd27
2 изменённых файлов: 30 добавлений и 38 удалений

Просмотреть файл

@ -0,0 +1,10 @@
x = 0;
try {
a;
b;
} catch (e) {}
var g = newGlobal();
oomTest(function() {
return Debugger(g);
});
eval("function g() {}");

Просмотреть файл

@ -10,6 +10,7 @@
#include "mozilla/Attributes.h"
#include "mozilla/DebugOnly.h"
#include "mozilla/MathAlgorithms.h"
#include "mozilla/ScopeExit.h"
#include "mozilla/SizePrintfMacros.h"
#include "jslibmath.h"
@ -8212,33 +8213,6 @@ CodeGenerator::generate()
return !masm.oom();
}
struct AutoDiscardIonCode
{
JSContext* cx;
RecompileInfo* recompileInfo;
IonScript* ionScript;
bool keep;
AutoDiscardIonCode(JSContext* cx, RecompileInfo* recompileInfo)
: cx(cx), recompileInfo(recompileInfo), ionScript(nullptr), keep(false) {}
~AutoDiscardIonCode() {
if (keep)
return;
// Use js_free instead of IonScript::Destroy: the cache list and
// backedge list are still uninitialized.
if (ionScript)
js_free(ionScript);
recompileInfo->compilerOutput(cx->zone()->types)->invalidate();
}
void keepIonCode() {
keep = true;
}
};
bool
CodeGenerator::linkSharedStubs(JSContext* cx)
{
@ -8309,13 +8283,20 @@ CodeGenerator::link(JSContext* cx, CompilerConstraintList* constraints)
// Check to make sure we didn't have a mid-build invalidation. If so, we
// will trickle to jit::Compile() and return Method_Skipped.
uint32_t warmUpCount = script->getWarmUpCount();
RecompileInfo recompileInfo;
bool isValid;
if (!FinishCompilation(cx, script, constraints, &recompileInfo, &isValid))
return false;
if (!isValid)
// Record constraints. If an error occured, returns false and potentially
// prevent future compilations. Otherwise, if an invalidation occured, then
// skip the current compilation.
RecompileInfo recompileInfo;
bool validRecompiledInfo = false;
if (!FinishCompilation(cx, script, constraints, &recompileInfo, &validRecompiledInfo))
return false;
if (!validRecompiledInfo)
return true;
auto guardRecordedConstraints = mozilla::MakeScopeExit([&] {
// In case of error, invalidate the current recompileInfo.
recompileInfo.compilerOutput(cx->zone()->types)->invalidate();
});
// IonMonkey could have inferred better type information during
// compilation. Since adding the new information to the actual type
@ -8333,8 +8314,6 @@ CodeGenerator::link(JSContext* cx, CompilerConstraintList* constraints)
if (!encodeSafepoints())
return false;
AutoDiscardIonCode discardIonCode(cx, &recompileInfo);
IonScript* ionScript =
IonScript::New(cx, recompileInfo,
graph.totalSlotCount(), argumentSlots, scriptFrameSize,
@ -8346,7 +8325,11 @@ CodeGenerator::link(JSContext* cx, CompilerConstraintList* constraints)
sharedStubs_.length(), optimizationLevel);
if (!ionScript)
return false;
discardIonCode.ionScript = ionScript;
auto guardIonScript = mozilla::MakeScopeExit([&ionScript] {
// Use js_free instead of IonScript::Destroy: the cache list and
// backedge list are still uninitialized.
js_free(ionScript);
});
// Also, note that creating the code here during an incremental GC will
// trace the code and mark all GC things it refers to. This captures any
@ -8549,9 +8532,8 @@ CodeGenerator::link(JSContext* cx, CompilerConstraintList* constraints)
if (IonScriptCounts* counts = extractScriptCounts())
script->addIonCounts(counts);
// Make sure that AutoDiscardIonCode does not free the relevant info.
discardIonCode.keepIonCode();
guardIonScript.release();
guardRecordedConstraints.release();
return true;
}