[wasm] Remove Isolate from module decoder entry points.

R=ahaas@chromium.org

Change-Id: I7c6fd17f36d33451ce7605e74002515295c7ad1c
Reviewed-on: https://chromium-review.googlesource.com/1145195
Reviewed-by: Andreas Haas <ahaas@chromium.org>
Commit-Queue: Michael Starzinger <mstarzinger@chromium.org>
Cr-Commit-Position: refs/heads/master@{#54629}
This commit is contained in:
Michael Starzinger 2018-07-20 14:55:40 +02:00 committed by Commit Bot
parent 9d48eda363
commit 131fb7248a
9 changed files with 52 additions and 61 deletions

View File

@ -2338,9 +2338,10 @@ class AsyncCompileJob::DecodeModule : public AsyncCompileJob::CompileStep {
DisallowHeapAllocation no_allocation;
// Decode the module bytes.
TRACE_COMPILE("(1) Decoding module...\n");
result = AsyncDecodeWasmModule(job_->isolate_, job_->wire_bytes_.start(),
job_->wire_bytes_.end(), false,
kWasmOrigin, job_->async_counters());
result =
DecodeWasmModule(job_->wire_bytes_.start(), job_->wire_bytes_.end(),
false, kWasmOrigin, job_->async_counters().get(),
job_->isolate()->wasm_engine()->allocator());
}
if (result.failed()) {
// Decoding failure; reject the promise and clean up.
@ -2603,7 +2604,8 @@ void AsyncStreamingProcessor::FinishAsyncCompileJobWithError(ResultBase error) {
bool AsyncStreamingProcessor::ProcessModuleHeader(Vector<const uint8_t> bytes,
uint32_t offset) {
TRACE_STREAMING("Process module header...\n");
decoder_.StartDecoding(job_->isolate());
decoder_.StartDecoding(job_->async_counters().get(),
job_->isolate()->wasm_engine()->allocator());
job_->module_ = decoder_.shared_module();
decoder_.DecodeModuleHeader(bytes, offset);
if (!decoder_.ok()) {

View File

@ -288,11 +288,11 @@ class ModuleDecoderImpl : public Decoder {
}
}
void StartDecoding(Isolate* isolate) {
void StartDecoding(Counters* counters, AccountingAllocator* allocator) {
CHECK_NULL(module_);
SetCounters(isolate->counters());
module_.reset(new WasmModule(base::make_unique<Zone>(
isolate->wasm_engine()->allocator(), "signatures")));
SetCounters(counters);
module_.reset(
new WasmModule(base::make_unique<Zone>(allocator, "signatures")));
module_->initial_pages = 0;
module_->maximum_pages = 0;
module_->mem_export = false;
@ -849,8 +849,9 @@ class ModuleDecoderImpl : public Decoder {
}
// Decodes an entire module.
ModuleResult DecodeModule(Isolate* isolate, bool verify_functions = true) {
StartDecoding(isolate);
ModuleResult DecodeModule(Counters* counters, AccountingAllocator* allocator,
bool verify_functions = true) {
StartDecoding(counters, allocator);
uint32_t offset = 0;
Vector<const byte> orig_bytes(start(), end() - start());
DecodeModuleHeader(Vector<const uint8_t>(start(), end() - start()), offset);
@ -1379,9 +1380,10 @@ class ModuleDecoderImpl : public Decoder {
}
};
ModuleResult DecodeWasmModule(Isolate* isolate, const byte* module_start,
const byte* module_end, bool verify_functions,
ModuleOrigin origin, Counters* counters) {
ModuleResult DecodeWasmModule(const byte* module_start, const byte* module_end,
bool verify_functions, ModuleOrigin origin,
Counters* counters,
AccountingAllocator* allocator) {
auto counter =
SELECT_WASM_COUNTER(counters, origin, wasm_decode, module_time);
TimedHistogramScope wasm_decode_module_time_scope(counter);
@ -1396,7 +1398,8 @@ ModuleResult DecodeWasmModule(Isolate* isolate, const byte* module_start,
// Signatures are stored in zone memory, which have the same lifetime
// as the {module}.
ModuleDecoderImpl decoder(module_start, module_end, origin);
ModuleResult result = decoder.DecodeModule(isolate, verify_functions);
ModuleResult result =
decoder.DecodeModule(counters, allocator, verify_functions);
// TODO(bradnelson): Improve histogram handling of size_t.
// TODO(titzer): this isn't accurate, since it doesn't count the data
// allocated on the C++ heap.
@ -1417,10 +1420,12 @@ const std::shared_ptr<WasmModule>& ModuleDecoder::shared_module() const {
return impl_->shared_module();
}
void ModuleDecoder::StartDecoding(Isolate* isolate, ModuleOrigin origin) {
void ModuleDecoder::StartDecoding(Counters* counters,
AccountingAllocator* allocator,
ModuleOrigin origin) {
DCHECK_NULL(impl_);
impl_.reset(new ModuleDecoderImpl(origin));
impl_->StartDecoding(isolate);
impl_->StartDecoding(counters, allocator);
}
void ModuleDecoder::DecodeModuleHeader(Vector<const uint8_t> bytes,
@ -1471,21 +1476,6 @@ SectionCode ModuleDecoder::IdentifyUnknownSection(Decoder& decoder,
bool ModuleDecoder::ok() { return impl_->ok(); }
ModuleResult SyncDecodeWasmModule(Isolate* isolate, const byte* module_start,
const byte* module_end, bool verify_functions,
ModuleOrigin origin) {
return DecodeWasmModule(isolate, module_start, module_end, verify_functions,
origin, isolate->counters());
}
ModuleResult AsyncDecodeWasmModule(
Isolate* isolate, const byte* module_start, const byte* module_end,
bool verify_functions, ModuleOrigin origin,
const std::shared_ptr<Counters> async_counters) {
return DecodeWasmModule(isolate, module_start, module_end, verify_functions,
origin, async_counters.get());
}
FunctionSig* DecodeWasmSignatureForTesting(Zone* zone, const byte* start,
const byte* end) {
ModuleDecoderImpl decoder(start, end, kWasmOrigin);

View File

@ -55,16 +55,9 @@ struct LocalNames {
};
// Decodes the bytes of a wasm module between {module_start} and {module_end}.
V8_EXPORT_PRIVATE ModuleResult SyncDecodeWasmModule(Isolate* isolate,
const byte* module_start,
const byte* module_end,
bool verify_functions,
ModuleOrigin origin);
V8_EXPORT_PRIVATE ModuleResult AsyncDecodeWasmModule(
Isolate* isolate, const byte* module_start, const byte* module_end,
bool verify_functions, ModuleOrigin origin,
const std::shared_ptr<Counters> async_counters);
V8_EXPORT_PRIVATE ModuleResult DecodeWasmModule(
const byte* module_start, const byte* module_end, bool verify_functions,
ModuleOrigin origin, Counters* counters, AccountingAllocator* allocator);
// Exposed for testing. Decodes a single function signature, allocating it
// in the given zone. Returns {nullptr} upon failure.
@ -118,7 +111,7 @@ class ModuleDecoder {
ModuleDecoder();
~ModuleDecoder();
void StartDecoding(Isolate* isolate,
void StartDecoding(Counters* counters, AccountingAllocator* allocator,
ModuleOrigin origin = ModuleOrigin::kWasmOrigin);
void DecodeModuleHeader(Vector<const uint8_t> bytes, uint32_t offset);

View File

@ -25,8 +25,9 @@ WasmEngine::~WasmEngine() = default;
bool WasmEngine::SyncValidate(Isolate* isolate, const ModuleWireBytes& bytes) {
// TODO(titzer): remove dependency on the isolate.
if (bytes.start() == nullptr || bytes.length() == 0) return false;
ModuleResult result = SyncDecodeWasmModule(isolate, bytes.start(),
bytes.end(), true, kWasmOrigin);
ModuleResult result =
DecodeWasmModule(bytes.start(), bytes.end(), true, kWasmOrigin,
isolate->counters(), allocator());
return result.ok();
}
@ -34,8 +35,9 @@ MaybeHandle<WasmModuleObject> WasmEngine::SyncCompileTranslatedAsmJs(
Isolate* isolate, ErrorThrower* thrower, const ModuleWireBytes& bytes,
Handle<Script> asm_js_script,
Vector<const byte> asm_js_offset_table_bytes) {
ModuleResult result = SyncDecodeWasmModule(isolate, bytes.start(),
bytes.end(), false, kAsmJsOrigin);
ModuleResult result =
DecodeWasmModule(bytes.start(), bytes.end(), false, kAsmJsOrigin,
isolate->counters(), allocator());
CHECK(!result.failed());
// Transfer ownership of the WasmModule to the {Managed<WasmModule>} generated
@ -46,8 +48,9 @@ MaybeHandle<WasmModuleObject> WasmEngine::SyncCompileTranslatedAsmJs(
MaybeHandle<WasmModuleObject> WasmEngine::SyncCompile(
Isolate* isolate, ErrorThrower* thrower, const ModuleWireBytes& bytes) {
ModuleResult result = SyncDecodeWasmModule(isolate, bytes.start(),
bytes.end(), false, kWasmOrigin);
ModuleResult result =
DecodeWasmModule(bytes.start(), bytes.end(), false, kWasmOrigin,
isolate->counters(), allocator());
if (result.failed()) {
thrower->CompileFailed("Wasm decoding failed", result);
return {};

View File

@ -534,9 +534,9 @@ MaybeHandle<WasmModuleObject> DeserializeNativeModule(
if (!IsSupportedVersion(isolate, data)) {
return {};
}
ModuleResult decode_result =
SyncDecodeWasmModule(isolate, wire_bytes.start(), wire_bytes.end(), false,
i::wasm::kWasmOrigin);
ModuleResult decode_result = DecodeWasmModule(
wire_bytes.start(), wire_bytes.end(), false, i::wasm::kWasmOrigin,
isolate->counters(), isolate->allocator());
if (!decode_result.ok()) return {};
CHECK_NOT_NULL(decode_result.val);
WasmModule* module = decode_result.val.get();

View File

@ -212,8 +212,9 @@ STREAM_TEST(TestAllBytesArriveAOTCompilerFinishesFirst) {
size_t GetFunctionOffset(i::Isolate* isolate, const uint8_t* buffer,
size_t size, size_t index) {
ModuleResult result = SyncDecodeWasmModule(isolate, buffer, buffer + size,
false, ModuleOrigin::kWasmOrigin);
ModuleResult result =
DecodeWasmModule(buffer, buffer + size, false, ModuleOrigin::kWasmOrigin,
isolate->counters(), isolate->allocator());
CHECK(result.ok());
const WasmFunction* func = &result.val->functions[1];
return func->code.offset();

View File

@ -42,8 +42,9 @@ std::shared_ptr<WasmModule> DecodeWasmModuleForTesting(
const byte* module_end, ModuleOrigin origin, bool verify_functions) {
// Decode the module, but don't verify function bodies, since we'll
// be compiling them anyway.
ModuleResult decoding_result = SyncDecodeWasmModule(
isolate, module_start, module_end, verify_functions, origin);
ModuleResult decoding_result =
DecodeWasmModule(module_start, module_end, verify_functions, origin,
isolate->counters(), isolate->allocator());
if (decoding_result.failed()) {
// Module verification failed. throw.

View File

@ -153,9 +153,9 @@ std::ostream& operator<<(std::ostream& os, const PrintName& name) {
void GenerateTestCase(Isolate* isolate, ModuleWireBytes wire_bytes,
bool compiles) {
constexpr bool kVerifyFunctions = false;
ModuleResult module_res =
SyncDecodeWasmModule(isolate, wire_bytes.start(), wire_bytes.end(),
kVerifyFunctions, ModuleOrigin::kWasmOrigin);
ModuleResult module_res = DecodeWasmModule(
wire_bytes.start(), wire_bytes.end(), kVerifyFunctions,
ModuleOrigin::kWasmOrigin, isolate->counters(), isolate->allocator());
CHECK(module_res.ok());
WasmModule* module = module_res.val.get();
CHECK_NOT_NULL(module);

View File

@ -155,14 +155,15 @@ class WasmModuleVerifyTest : public TestWithIsolateAndZone {
memcpy(temp, header, sizeof(header));
memcpy(temp + sizeof(header), module_start, size);
ModuleResult result =
SyncDecodeWasmModule(isolate(), temp, temp + total, false, kWasmOrigin);
DecodeWasmModule(temp, temp + total, false, kWasmOrigin,
isolate()->counters(), isolate()->allocator());
delete[] temp;
return result;
}
ModuleResult DecodeModuleNoHeader(const byte* module_start,
const byte* module_end) {
return SyncDecodeWasmModule(isolate(), module_start, module_end, false,
kWasmOrigin);
return DecodeWasmModule(module_start, module_end, false, kWasmOrigin,
isolate()->counters(), isolate()->allocator());
}
};