зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1284056 - Baldr: remove cx_ from ModuleGenerator (r=bbouvier)
MozReview-Commit-ID: 9UeeVdogeAR --HG-- extra : rebase_source : 385da837be7ab2450c1b58b09b6b6cc9480cee2b
This commit is contained in:
Родитель
0ca10d8c16
Коммит
56b8c3504b
|
@ -1661,7 +1661,6 @@ class MOZ_STACK_CLASS ModuleValidator
|
|||
importMap_(cx),
|
||||
arrayViews_(cx),
|
||||
atomicsPresent_(false),
|
||||
mg_(cx),
|
||||
errorString_(nullptr),
|
||||
errorOffset_(UINT32_MAX),
|
||||
errorOverRecursed_(false)
|
||||
|
@ -1754,11 +1753,11 @@ class MOZ_STACK_CLASS ModuleValidator
|
|||
if (!dummyFunction_)
|
||||
return false;
|
||||
|
||||
Assumptions assumptions;
|
||||
if (!assumptions.init(SignalUsage(cx_), cx_->buildIdOp()))
|
||||
CompileArgs args;
|
||||
if (!args.assumptions.init(SignalUsage(cx_), cx_->buildIdOp()))
|
||||
return false;
|
||||
|
||||
auto genData = MakeUnique<ModuleGeneratorData>(assumptions.usesSignal, ModuleKind::AsmJS);
|
||||
auto genData = MakeUnique<ModuleGeneratorData>(args.assumptions.usesSignal, ModuleKind::AsmJS);
|
||||
if (!genData ||
|
||||
!genData->sigs.resize(MaxSigs) ||
|
||||
!genData->funcSigs.resize(MaxFuncs) ||
|
||||
|
@ -1768,14 +1767,13 @@ class MOZ_STACK_CLASS ModuleValidator
|
|||
return false;
|
||||
}
|
||||
|
||||
CacheableChars filename;
|
||||
if (parser_.ss->filename()) {
|
||||
filename = DuplicateString(parser_.ss->filename());
|
||||
if (!filename)
|
||||
args.filename = DuplicateString(parser_.ss->filename());
|
||||
if (!args.filename)
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!mg_.init(Move(genData), Move(filename), Move(assumptions), asmJSMetadata_.get()))
|
||||
if (!mg_.init(Move(genData), Move(args), asmJSMetadata_.get()))
|
||||
return false;
|
||||
|
||||
mg_.bumpMinHeapLength(asmJSMetadata_->minHeapLength);
|
||||
|
|
|
@ -1083,9 +1083,9 @@ DecodeUnknownSections(JSContext* cx, Decoder& d)
|
|||
}
|
||||
|
||||
static UniqueModule
|
||||
DecodeModule(JSContext* cx, UniqueChars file, Assumptions&& assumptions, const ShareableBytes& bytecode)
|
||||
DecodeModule(JSContext* cx, const ShareableBytes& bytecode, CompileArgs&& args)
|
||||
{
|
||||
auto init = js::MakeUnique<ModuleGeneratorData>(assumptions.usesSignal);
|
||||
auto init = js::MakeUnique<ModuleGeneratorData>(args.assumptions.usesSignal);
|
||||
if (!init)
|
||||
return nullptr;
|
||||
|
||||
|
@ -1107,8 +1107,8 @@ DecodeModule(JSContext* cx, UniqueChars file, Assumptions&& assumptions, const S
|
|||
if (!DecodeTableSection(cx, d, init.get()))
|
||||
return nullptr;
|
||||
|
||||
ModuleGenerator mg(cx);
|
||||
if (!mg.init(Move(init), Move(file), Move(assumptions)))
|
||||
ModuleGenerator mg;
|
||||
if (!mg.init(Move(init), Move(args)))
|
||||
return nullptr;
|
||||
|
||||
if (!DecodeMemorySection(cx, d, mg))
|
||||
|
@ -1133,7 +1133,7 @@ DecodeModule(JSContext* cx, UniqueChars file, Assumptions&& assumptions, const S
|
|||
}
|
||||
|
||||
UniqueModule
|
||||
wasm::Compile(JSContext* cx, UniqueChars file, Assumptions&& assumptions, Bytes&& bytecode)
|
||||
wasm::Compile(JSContext* cx, Bytes&& bytecode, CompileArgs&& args)
|
||||
{
|
||||
MOZ_ASSERT(HasCompilerSupport(cx));
|
||||
|
||||
|
@ -1141,7 +1141,7 @@ wasm::Compile(JSContext* cx, UniqueChars file, Assumptions&& assumptions, Bytes&
|
|||
if (!sharedBytes)
|
||||
return nullptr;
|
||||
|
||||
UniqueModule module = DecodeModule(cx, Move(file), Move(assumptions), *sharedBytes);
|
||||
UniqueModule module = DecodeModule(cx, *sharedBytes, Move(args));
|
||||
if (!module) {
|
||||
if (!cx->isExceptionPending())
|
||||
ReportOutOfMemory(cx);
|
||||
|
|
|
@ -26,11 +26,20 @@
|
|||
namespace js {
|
||||
namespace wasm {
|
||||
|
||||
// Compile the given WebAssembly bytecode with the given filename into a
|
||||
// wasm::Module.
|
||||
// Compile the given WebAssembly bytecode with the given assumptions, settings
|
||||
// and filename into a wasm::Module.
|
||||
|
||||
struct CompileArgs
|
||||
{
|
||||
Assumptions assumptions;
|
||||
UniqueChars filename;
|
||||
bool alwaysBaseline;
|
||||
|
||||
CompileArgs() : alwaysBaseline(false) {}
|
||||
};
|
||||
|
||||
UniqueModule
|
||||
Compile(JSContext* cx, UniqueChars filename, Assumptions&& assumptions, Bytes&& code);
|
||||
Compile(JSContext* cx, Bytes&& code, CompileArgs&& compileArgs);
|
||||
|
||||
} // namespace wasm
|
||||
} // namespace js
|
||||
|
|
|
@ -40,19 +40,16 @@ using mozilla::MakeEnumeratedRange;
|
|||
static const unsigned GENERATOR_LIFO_DEFAULT_CHUNK_SIZE = 4 * 1024;
|
||||
static const unsigned COMPILATION_LIFO_DEFAULT_CHUNK_SIZE = 64 * 1024;
|
||||
|
||||
ModuleGenerator::ModuleGenerator(ExclusiveContext* cx)
|
||||
: cx_(cx),
|
||||
ModuleGenerator::ModuleGenerator()
|
||||
: alwaysBaseline_(false),
|
||||
numSigs_(0),
|
||||
lifo_(GENERATOR_LIFO_DEFAULT_CHUNK_SIZE),
|
||||
masmAlloc_(&lifo_),
|
||||
masm_(MacroAssembler::AsmJSToken(), masmAlloc_),
|
||||
funcIndexToExport_(cx),
|
||||
lastPatchedCallsite_(0),
|
||||
startOfUnpatchedBranches_(0),
|
||||
parallel_(false),
|
||||
outstanding_(0),
|
||||
tasks_(cx),
|
||||
freeTasks_(cx),
|
||||
activeFunc_(nullptr),
|
||||
startedFuncDefs_(false),
|
||||
finishedFuncDefs_(false)
|
||||
|
@ -67,12 +64,12 @@ ModuleGenerator::~ModuleGenerator()
|
|||
if (outstanding_) {
|
||||
AutoLockHelperThreadState lock;
|
||||
while (true) {
|
||||
IonCompileTaskVector& worklist = HelperThreadState().wasmWorklist();
|
||||
IonCompileTaskPtrVector& worklist = HelperThreadState().wasmWorklist();
|
||||
MOZ_ASSERT(outstanding_ >= worklist.length());
|
||||
outstanding_ -= worklist.length();
|
||||
worklist.clear();
|
||||
|
||||
IonCompileTaskVector& finished = HelperThreadState().wasmFinishedList();
|
||||
IonCompileTaskPtrVector& finished = HelperThreadState().wasmFinishedList();
|
||||
MOZ_ASSERT(outstanding_ >= finished.length());
|
||||
outstanding_ -= finished.length();
|
||||
finished.clear();
|
||||
|
@ -96,17 +93,20 @@ ModuleGenerator::~ModuleGenerator()
|
|||
}
|
||||
|
||||
bool
|
||||
ModuleGenerator::init(UniqueModuleGeneratorData shared, UniqueChars file, Assumptions&& assumptions,
|
||||
Metadata* maybeMetadata)
|
||||
ModuleGenerator::init(UniqueModuleGeneratorData shared, CompileArgs&& args,
|
||||
Metadata* maybeAsmJSMetadata)
|
||||
{
|
||||
alwaysBaseline_ = args.alwaysBaseline;
|
||||
|
||||
if (!funcIndexToExport_.init())
|
||||
return false;
|
||||
|
||||
linkData_.globalDataLength = AlignBytes(InitialGlobalDataBytes, sizeof(void*));;
|
||||
|
||||
// asm.js passes in an AsmJSMetadata subclass to use instead.
|
||||
if (maybeMetadata) {
|
||||
metadata_ = maybeMetadata;
|
||||
if (maybeAsmJSMetadata) {
|
||||
MOZ_ASSERT(shared->kind == ModuleKind::AsmJS);
|
||||
metadata_ = maybeAsmJSMetadata;
|
||||
} else {
|
||||
metadata_ = js_new<Metadata>();
|
||||
if (!metadata_)
|
||||
|
@ -115,8 +115,8 @@ ModuleGenerator::init(UniqueModuleGeneratorData shared, UniqueChars file, Assump
|
|||
|
||||
metadata_->kind = shared->kind;
|
||||
metadata_->heapUsage = HeapUsage::None;
|
||||
metadata_->filename = Move(file);
|
||||
metadata_->assumptions = Move(assumptions);
|
||||
metadata_->filename = Move(args.filename);
|
||||
metadata_->assumptions = Move(args.assumptions);
|
||||
|
||||
shared_ = Move(shared);
|
||||
|
||||
|
@ -198,7 +198,7 @@ JumpRange()
|
|||
return Min(JitOptions.jumpThreshold, JumpImmediateRange);
|
||||
}
|
||||
|
||||
typedef HashMap<uint32_t, uint32_t> OffsetMap;
|
||||
typedef HashMap<uint32_t, uint32_t, DefaultHasher<uint32_t>, SystemAllocPolicy> OffsetMap;
|
||||
|
||||
bool
|
||||
ModuleGenerator::convertOutOfRangeBranchesToThunks()
|
||||
|
@ -208,7 +208,7 @@ ModuleGenerator::convertOutOfRangeBranchesToThunks()
|
|||
// Create thunks for callsites that have gone out of range. Use a map to
|
||||
// create one thunk for each callee since there is often high reuse.
|
||||
|
||||
OffsetMap alreadyThunked(cx_);
|
||||
OffsetMap alreadyThunked;
|
||||
if (!alreadyThunked.init())
|
||||
return false;
|
||||
|
||||
|
@ -327,6 +327,9 @@ ModuleGenerator::finishTask(IonCompileTask* task)
|
|||
return true;
|
||||
}
|
||||
|
||||
typedef Vector<Offsets, 0, SystemAllocPolicy> OffsetVector;
|
||||
typedef Vector<ProfilingOffsets, 0, SystemAllocPolicy> ProfilingOffsetVector;
|
||||
|
||||
bool
|
||||
ModuleGenerator::finishCodegen()
|
||||
{
|
||||
|
@ -336,9 +339,9 @@ ModuleGenerator::finishCodegen()
|
|||
// larger than the JumpImmediateRange, even local uses of Label will fail
|
||||
// due to the large absolute offsets temporarily stored by Label::bind().
|
||||
|
||||
Vector<Offsets> entries(cx_);
|
||||
Vector<ProfilingOffsets> interpExits(cx_);
|
||||
Vector<ProfilingOffsets> jitExits(cx_);
|
||||
OffsetVector entries;
|
||||
ProfilingOffsetVector interpExits;
|
||||
ProfilingOffsetVector jitExits;
|
||||
EnumeratedArray<JumpTarget, JumpTarget::Limit, Offsets> jumpTargets;
|
||||
Offsets interruptExit;
|
||||
|
||||
|
@ -800,13 +803,6 @@ ModuleGenerator::startFuncDef(uint32_t lineOrBytecode, FunctionGenerator* fg)
|
|||
bool
|
||||
ModuleGenerator::finishFuncDef(uint32_t funcIndex, FunctionGenerator* fg)
|
||||
{
|
||||
TraceLoggerThread* logger = nullptr;
|
||||
if (cx_->isJSContext())
|
||||
logger = TraceLoggerForMainThread(cx_->asJSContext()->runtime());
|
||||
else
|
||||
logger = TraceLoggerForCurrentThread();
|
||||
AutoTraceLog logCompile(logger, TraceLogger_WasmCompilation);
|
||||
|
||||
MOZ_ASSERT(activeFunc_ == fg);
|
||||
|
||||
auto func = js::MakeUnique<FuncBytes>(Move(fg->bytes_),
|
||||
|
@ -817,14 +813,14 @@ ModuleGenerator::finishFuncDef(uint32_t funcIndex, FunctionGenerator* fg)
|
|||
if (!func)
|
||||
return false;
|
||||
|
||||
JSRuntime* rt = cx_->compartment()->runtimeFromAnyThread();
|
||||
bool baselineCompile = rt->options().wasmAlwaysBaseline() && BaselineCanCompile(fg);
|
||||
auto mode = alwaysBaseline_ && BaselineCanCompile(fg)
|
||||
? IonCompileTask::CompileMode::Baseline
|
||||
: IonCompileTask::CompileMode::Ion;
|
||||
|
||||
fg->task_->init(Move(func), baselineCompile ? IonCompileTask::CompileMode::Baseline
|
||||
: IonCompileTask::CompileMode::Ion);
|
||||
fg->task_->init(Move(func), mode);
|
||||
|
||||
if (parallel_) {
|
||||
if (!StartOffThreadWasmCompile(cx_, fg->task_))
|
||||
if (!StartOffThreadWasmCompile(fg->task_))
|
||||
return false;
|
||||
outstanding_++;
|
||||
} else {
|
||||
|
@ -957,11 +953,11 @@ ModuleGenerator::finish(ImportNameVector&& importNames, const ShareableBytes& by
|
|||
if (!finishLinkData(code))
|
||||
return nullptr;
|
||||
|
||||
return cx_->make_unique<Module>(Move(code),
|
||||
Move(linkData_),
|
||||
Move(importNames),
|
||||
Move(exportMap_),
|
||||
Move(dataSegments_),
|
||||
*metadata_,
|
||||
bytecode);
|
||||
return js::MakeUnique<Module>(Move(code),
|
||||
Move(linkData_),
|
||||
Move(importNames),
|
||||
Move(exportMap_),
|
||||
Move(dataSegments_),
|
||||
*metadata_,
|
||||
bytecode);
|
||||
}
|
||||
|
|
|
@ -20,6 +20,7 @@
|
|||
#define wasm_generator_h
|
||||
|
||||
#include "asmjs/WasmBinary.h"
|
||||
#include "asmjs/WasmCompile.h"
|
||||
#include "asmjs/WasmModule.h"
|
||||
#include "jit/MacroAssembler.h"
|
||||
|
||||
|
@ -92,9 +93,12 @@ typedef UniquePtr<ModuleGeneratorData> UniqueModuleGeneratorData;
|
|||
|
||||
class MOZ_STACK_CLASS ModuleGenerator
|
||||
{
|
||||
typedef HashMap<uint32_t, uint32_t> FuncIndexMap;
|
||||
typedef HashMap<uint32_t, uint32_t, DefaultHasher<uint32_t>, SystemAllocPolicy> FuncIndexMap;
|
||||
typedef Vector<IonCompileTask, 0, SystemAllocPolicy> IonCompileTaskVector;
|
||||
typedef Vector<IonCompileTask*, 0, SystemAllocPolicy> IonCompileTaskPtrVector;
|
||||
|
||||
ExclusiveContext* cx_;
|
||||
// Constant parameters
|
||||
bool alwaysBaseline_;
|
||||
|
||||
// Data that is moved into the result of finish()
|
||||
LinkData linkData_;
|
||||
|
@ -118,8 +122,8 @@ class MOZ_STACK_CLASS ModuleGenerator
|
|||
// Parallel compilation
|
||||
bool parallel_;
|
||||
uint32_t outstanding_;
|
||||
Vector<IonCompileTask> tasks_;
|
||||
Vector<IonCompileTask*> freeTasks_;
|
||||
IonCompileTaskVector tasks_;
|
||||
IonCompileTaskPtrVector freeTasks_;
|
||||
|
||||
// Assertions
|
||||
DebugOnly<FunctionGenerator*> activeFunc_;
|
||||
|
@ -137,13 +141,11 @@ class MOZ_STACK_CLASS ModuleGenerator
|
|||
MOZ_MUST_USE bool allocateGlobalBytes(uint32_t bytes, uint32_t align, uint32_t* globalDataOff);
|
||||
|
||||
public:
|
||||
explicit ModuleGenerator(ExclusiveContext* cx);
|
||||
explicit ModuleGenerator();
|
||||
~ModuleGenerator();
|
||||
|
||||
MOZ_MUST_USE bool init(UniqueModuleGeneratorData shared,
|
||||
UniqueChars filename,
|
||||
Assumptions&& assumptions,
|
||||
Metadata* maybeMetadata = nullptr);
|
||||
MOZ_MUST_USE bool init(UniqueModuleGeneratorData shared, CompileArgs&& args,
|
||||
Metadata* maybeAsmJSMetadata = nullptr);
|
||||
|
||||
bool isAsmJS() const { return metadata_->kind == ModuleKind::AsmJS; }
|
||||
SignalUsage usesSignal() const { return metadata_->assumptions.usesSignal; }
|
||||
|
|
|
@ -3441,14 +3441,17 @@ wasm::IonCompileFunction(IonCompileTask* task)
|
|||
bool
|
||||
wasm::CompileFunction(IonCompileTask* task)
|
||||
{
|
||||
TraceLoggerThread* logger = TraceLoggerForCurrentThread();
|
||||
AutoTraceLog logCompile(logger, TraceLogger_WasmCompilation);
|
||||
|
||||
switch (task->mode()) {
|
||||
case wasm::IonCompileTask::CompileMode::Ion:
|
||||
return wasm::IonCompileFunction(task);
|
||||
case wasm::IonCompileTask::CompileMode::Baseline:
|
||||
return wasm::BaselineCompileFunction(task);
|
||||
case wasm::IonCompileTask::CompileMode::None:
|
||||
MOZ_CRASH("Uninitialized task");
|
||||
break;
|
||||
}
|
||||
// Silence gcc 5.2.1 warning.
|
||||
return false;
|
||||
|
||||
MOZ_CRASH("Uninitialized task");
|
||||
}
|
||||
|
|
|
@ -122,19 +122,18 @@ wasm::Eval(JSContext* cx, Handle<TypedArrayObject*> code, HandleObject importObj
|
|||
if (!bytecode.append((uint8_t*)code->viewDataEither().unwrap(), code->byteLength()))
|
||||
return false;
|
||||
|
||||
UniqueChars filename;
|
||||
CompileArgs compileArgs;
|
||||
if (!compileArgs.assumptions.init(SignalUsage(cx), cx->buildIdOp()))
|
||||
return true;
|
||||
|
||||
JS::AutoFilename af;
|
||||
if (DescribeScriptedCaller(cx, &af)) {
|
||||
filename = DuplicateString(cx, af.get());
|
||||
if (!filename)
|
||||
compileArgs.filename = DuplicateString(cx, af.get());
|
||||
if (!compileArgs.filename)
|
||||
return false;
|
||||
}
|
||||
|
||||
Assumptions assumptions;
|
||||
if (!assumptions.init(SignalUsage(cx), cx->buildIdOp()))
|
||||
return true;
|
||||
|
||||
UniqueModule module = Compile(cx, Move(filename), Move(assumptions), Move(bytecode));
|
||||
UniqueModule module = Compile(cx, Move(bytecode), Move(compileArgs));
|
||||
if (!module)
|
||||
return false;
|
||||
|
||||
|
@ -315,22 +314,21 @@ ModuleConstructor(JSContext* cx, unsigned argc, Value* vp)
|
|||
return false;
|
||||
}
|
||||
|
||||
UniqueChars filename;
|
||||
CompileArgs compileArgs;
|
||||
if (!compileArgs.assumptions.init(SignalUsage(cx), cx->buildIdOp()))
|
||||
return true;
|
||||
|
||||
JS::AutoFilename af;
|
||||
if (DescribeScriptedCaller(cx, &af)) {
|
||||
filename = DuplicateString(cx, af.get());
|
||||
if (!filename)
|
||||
compileArgs.filename = DuplicateString(cx, af.get());
|
||||
if (!compileArgs.filename)
|
||||
return false;
|
||||
}
|
||||
|
||||
Assumptions assumptions;
|
||||
if (!assumptions.init(SignalUsage(cx), cx->buildIdOp()))
|
||||
return true;
|
||||
|
||||
if (!CheckCompilerSupport(cx))
|
||||
return false;
|
||||
|
||||
UniqueModule module = Compile(cx, Move(filename), Move(assumptions), Move(bytecode));
|
||||
UniqueModule module = Compile(cx, Move(bytecode), Move(compileArgs));
|
||||
if (!module)
|
||||
return false;
|
||||
|
||||
|
|
|
@ -81,7 +81,7 @@ js::SetFakeCPUCount(size_t count)
|
|||
}
|
||||
|
||||
bool
|
||||
js::StartOffThreadWasmCompile(ExclusiveContext* cx, wasm::IonCompileTask* task)
|
||||
js::StartOffThreadWasmCompile(wasm::IonCompileTask* task)
|
||||
{
|
||||
AutoLockHelperThreadState lock;
|
||||
|
||||
|
@ -1352,10 +1352,6 @@ HelperThread::handleWasmWorkload(AutoLockHelperThreadState& locked)
|
|||
wasm::IonCompileTask* task = wasmTask();
|
||||
{
|
||||
AutoUnlockHelperThreadState unlock(locked);
|
||||
|
||||
TraceLoggerThread* logger = TraceLoggerForCurrentThread();
|
||||
AutoTraceLog logCompile(logger, TraceLogger_WasmCompilation);
|
||||
|
||||
success = wasm::CompileFunction(task);
|
||||
}
|
||||
|
||||
|
|
|
@ -39,7 +39,7 @@ namespace wasm {
|
|||
class FuncIR;
|
||||
class FunctionCompileResults;
|
||||
class IonCompileTask;
|
||||
typedef Vector<IonCompileTask*, 0, SystemAllocPolicy> IonCompileTaskVector;
|
||||
typedef Vector<IonCompileTask*, 0, SystemAllocPolicy> IonCompileTaskPtrVector;
|
||||
} // namespace wasm
|
||||
|
||||
enum class ParseTaskKind
|
||||
|
@ -78,7 +78,7 @@ class GlobalHelperThreadState
|
|||
IonBuilderVector ionWorklist_, ionFinishedList_;
|
||||
|
||||
// wasm worklist and finished jobs.
|
||||
wasm::IonCompileTaskVector wasmWorklist_, wasmFinishedList_;
|
||||
wasm::IonCompileTaskPtrVector wasmWorklist_, wasmFinishedList_;
|
||||
|
||||
public:
|
||||
// For now, only allow a single parallel asm.js compilation to happen at a
|
||||
|
@ -157,11 +157,11 @@ class GlobalHelperThreadState
|
|||
return ionFinishedList_;
|
||||
}
|
||||
|
||||
wasm::IonCompileTaskVector& wasmWorklist() {
|
||||
wasm::IonCompileTaskPtrVector& wasmWorklist() {
|
||||
MOZ_ASSERT(isLocked());
|
||||
return wasmWorklist_;
|
||||
}
|
||||
wasm::IonCompileTaskVector& wasmFinishedList() {
|
||||
wasm::IonCompileTaskPtrVector& wasmFinishedList() {
|
||||
MOZ_ASSERT(isLocked());
|
||||
return wasmFinishedList_;
|
||||
}
|
||||
|
@ -392,7 +392,7 @@ PauseCurrentHelperThread();
|
|||
|
||||
/* Perform MIR optimization and LIR generation on a single function. */
|
||||
bool
|
||||
StartOffThreadWasmCompile(ExclusiveContext* cx, wasm::IonCompileTask* task);
|
||||
StartOffThreadWasmCompile(wasm::IonCompileTask* task);
|
||||
|
||||
/*
|
||||
* Schedule an Ion compilation for a script, given a builder which has been
|
||||
|
|
Загрузка…
Ссылка в новой задаче