Commit 5fb4b176 authored by Eric Holk's avatar Eric Holk Committed by Commit Bot

[wasm] Move wasm objects from Isolate to new WasmEngine object

This is a small refactoring that moves the WasmCodeManager and
CompilationManager from being a part of the Isolate directly to living in a new
WasmEngine object. This makes it easier to change Wasm components without
rebuilding so much of V8, and also enables future changes to Wasm without
affecting unrelated parts of V8.

Bug: v8:7109
Cq-Include-Trybots: master.tryserver.chromium.linux:linux_chromium_rel_ng
Change-Id: Ic89bfc3974483aa909d12556d1386e18785a1d71
Reviewed-on: https://chromium-review.googlesource.com/804824
Commit-Queue: Eric Holk <eholk@chromium.org>
Reviewed-by: 's avatarBen Titzer <titzer@chromium.org>
Cr-Commit-Position: refs/heads/master@{#49848}
parent cb9e7af4
...@@ -2118,6 +2118,7 @@ v8_source_set("v8_base") { ...@@ -2118,6 +2118,7 @@ v8_source_set("v8_base") {
"src/wasm/wasm-code-wrapper.cc", "src/wasm/wasm-code-wrapper.cc",
"src/wasm/wasm-code-wrapper.h", "src/wasm/wasm-code-wrapper.h",
"src/wasm/wasm-debug.cc", "src/wasm/wasm-debug.cc",
"src/wasm/wasm-engine.h",
"src/wasm/wasm-external-refs.cc", "src/wasm/wasm-external-refs.cc",
"src/wasm/wasm-external-refs.h", "src/wasm/wasm-external-refs.h",
"src/wasm/wasm-heap.cc", "src/wasm/wasm-heap.cc",
......
...@@ -84,6 +84,7 @@ ...@@ -84,6 +84,7 @@
#include "src/vm-state-inl.h" #include "src/vm-state-inl.h"
#include "src/wasm/compilation-manager.h" #include "src/wasm/compilation-manager.h"
#include "src/wasm/streaming-decoder.h" #include "src/wasm/streaming-decoder.h"
#include "src/wasm/wasm-engine.h"
#include "src/wasm/wasm-objects-inl.h" #include "src/wasm/wasm-objects-inl.h"
#include "src/wasm/wasm-result.h" #include "src/wasm/wasm-result.h"
#include "src/wasm/wasm-serialization.h" #include "src/wasm/wasm-serialization.h"
...@@ -7887,8 +7888,10 @@ WasmModuleObjectBuilderStreaming::WasmModuleObjectBuilderStreaming( ...@@ -7887,8 +7888,10 @@ WasmModuleObjectBuilderStreaming::WasmModuleObjectBuilderStreaming(
i::Handle<i::JSPromise> promise = Utils::OpenHandle(*GetPromise()); i::Handle<i::JSPromise> promise = Utils::OpenHandle(*GetPromise());
i::Isolate* i_isolate = reinterpret_cast<i::Isolate*>(isolate); i::Isolate* i_isolate = reinterpret_cast<i::Isolate*>(isolate);
streaming_decoder_ = streaming_decoder_ =
i_isolate->wasm_compilation_manager()->StartStreamingCompilation( i_isolate->wasm_engine()
i_isolate, handle(i_isolate->context()), promise); ->compilation_manager()
->StartStreamingCompilation(i_isolate, handle(i_isolate->context()),
promise);
} }
} }
......
...@@ -17,6 +17,7 @@ ...@@ -17,6 +17,7 @@
#include "src/objects-inl.h" #include "src/objects-inl.h"
#include "src/snapshot/serializer-common.h" #include "src/snapshot/serializer-common.h"
#include "src/string-stream.h" #include "src/string-stream.h"
#include "src/wasm/wasm-engine.h"
#include "src/wasm/wasm-heap.h" #include "src/wasm/wasm-heap.h"
namespace v8 { namespace v8 {
...@@ -54,7 +55,8 @@ const char* V8NameConverter::NameOfAddress(byte* pc) const { ...@@ -54,7 +55,8 @@ const char* V8NameConverter::NameOfAddress(byte* pc) const {
return v8_buffer_.start(); return v8_buffer_.start();
} }
wasm::WasmCode* wasm_code = isolate->wasm_code_manager()->LookupCode(pc); wasm::WasmCode* wasm_code =
isolate->wasm_engine()->code_manager()->LookupCode(pc);
if (wasm_code != nullptr) { if (wasm_code != nullptr) {
SNPrintF(v8_buffer_, "%p (%s)", static_cast<void*>(pc), SNPrintF(v8_buffer_, "%p (%s)", static_cast<void*>(pc),
GetWasmCodeKindAsString(wasm_code->kind())); GetWasmCodeKindAsString(wasm_code->kind()));
......
...@@ -16,6 +16,7 @@ ...@@ -16,6 +16,7 @@
#include "src/string-stream.h" #include "src/string-stream.h"
#include "src/visitors.h" #include "src/visitors.h"
#include "src/vm-state-inl.h" #include "src/vm-state-inl.h"
#include "src/wasm/wasm-engine.h"
#include "src/wasm/wasm-heap.h" #include "src/wasm/wasm-heap.h"
#include "src/wasm/wasm-objects-inl.h" #include "src/wasm/wasm-objects-inl.h"
#include "src/zone/zone-containers.h" #include "src/zone/zone-containers.h"
...@@ -439,7 +440,7 @@ StackFrame::Type StackFrame::ComputeType(const StackFrameIteratorBase* iterator, ...@@ -439,7 +440,7 @@ StackFrame::Type StackFrame::ComputeType(const StackFrameIteratorBase* iterator,
// than checking the flag, then getting the code, and then, if both are true // than checking the flag, then getting the code, and then, if both are true
// (non-null, respectivelly), going down the wasm_code path. // (non-null, respectivelly), going down the wasm_code path.
wasm::WasmCode* wasm_code = wasm::WasmCode* wasm_code =
iterator->isolate()->wasm_code_manager()->LookupCode(pc); iterator->isolate()->wasm_engine()->code_manager()->LookupCode(pc);
if (wasm_code != nullptr) { if (wasm_code != nullptr) {
switch (wasm_code->kind()) { switch (wasm_code->kind()) {
case wasm::WasmCode::kInterpreterStub: case wasm::WasmCode::kInterpreterStub:
...@@ -777,7 +778,7 @@ void StandardFrame::IterateCompiledFrame(RootVisitor* v) const { ...@@ -777,7 +778,7 @@ void StandardFrame::IterateCompiledFrame(RootVisitor* v) const {
Address inner_pointer = pc(); Address inner_pointer = pc();
const wasm::WasmCode* wasm_code = const wasm::WasmCode* wasm_code =
FLAG_wasm_jit_to_native FLAG_wasm_jit_to_native
? isolate()->wasm_code_manager()->LookupCode(inner_pointer) ? isolate()->wasm_engine()->code_manager()->LookupCode(inner_pointer)
: nullptr; : nullptr;
SafepointEntry safepoint_entry; SafepointEntry safepoint_entry;
uint32_t stack_slots; uint32_t stack_slots;
...@@ -1713,7 +1714,7 @@ WasmInstanceObject* WasmCompiledFrame::wasm_instance() const { ...@@ -1713,7 +1714,7 @@ WasmInstanceObject* WasmCompiledFrame::wasm_instance() const {
WasmInstanceObject* obj = WasmInstanceObject* obj =
FLAG_wasm_jit_to_native FLAG_wasm_jit_to_native
? WasmInstanceObject::GetOwningInstance( ? WasmInstanceObject::GetOwningInstance(
isolate()->wasm_code_manager()->LookupCode(pc())) isolate()->wasm_engine()->code_manager()->LookupCode(pc()))
: WasmInstanceObject::GetOwningInstanceGC(LookupCode()); : WasmInstanceObject::GetOwningInstanceGC(LookupCode());
// This is a live stack frame; it must have a live instance. // This is a live stack frame; it must have a live instance.
DCHECK_NOT_NULL(obj); DCHECK_NOT_NULL(obj);
...@@ -1738,7 +1739,8 @@ void WasmCompiledFrame::Summarize(std::vector<FrameSummary>* functions) const { ...@@ -1738,7 +1739,8 @@ void WasmCompiledFrame::Summarize(std::vector<FrameSummary>* functions) const {
Handle<WasmInstanceObject> instance; Handle<WasmInstanceObject> instance;
int offset = -1; int offset = -1;
if (FLAG_wasm_jit_to_native) { if (FLAG_wasm_jit_to_native) {
code = WasmCodeWrapper(isolate()->wasm_code_manager()->LookupCode(pc())); code = WasmCodeWrapper(
isolate()->wasm_engine()->code_manager()->LookupCode(pc()));
offset = offset =
static_cast<int>(pc() - code.GetWasmCode()->instructions().start()); static_cast<int>(pc() - code.GetWasmCode()->instructions().start());
instance = Handle<WasmInstanceObject>( instance = Handle<WasmInstanceObject>(
...@@ -1765,8 +1767,9 @@ bool WasmCompiledFrame::at_to_number_conversion() const { ...@@ -1765,8 +1767,9 @@ bool WasmCompiledFrame::at_to_number_conversion() const {
int pos = -1; int pos = -1;
if (FLAG_wasm_jit_to_native) { if (FLAG_wasm_jit_to_native) {
wasm::WasmCode* code = wasm::WasmCode* code =
callee_pc ? isolate()->wasm_code_manager()->LookupCode(callee_pc) callee_pc
: nullptr; ? isolate()->wasm_engine()->code_manager()->LookupCode(callee_pc)
: nullptr;
if (!code || code->kind() != wasm::WasmCode::kWasmToJsWrapper) return false; if (!code || code->kind() != wasm::WasmCode::kWasmToJsWrapper) return false;
int offset = static_cast<int>(callee_pc - code->instructions().start()); int offset = static_cast<int>(callee_pc - code->instructions().start());
pos = FrameSummary::WasmCompiledFrameSummary::GetWasmSourcePosition(code, pos = FrameSummary::WasmCompiledFrameSummary::GetWasmSourcePosition(code,
...@@ -1791,7 +1794,8 @@ int WasmCompiledFrame::LookupExceptionHandlerInTable(int* stack_slots) { ...@@ -1791,7 +1794,8 @@ int WasmCompiledFrame::LookupExceptionHandlerInTable(int* stack_slots) {
*stack_slots = code->stack_slots(); *stack_slots = code->stack_slots();
return table->LookupReturn(pc_offset); return table->LookupReturn(pc_offset);
} }
wasm::WasmCode* code = isolate()->wasm_code_manager()->LookupCode(pc()); wasm::WasmCode* code =
isolate()->wasm_engine()->code_manager()->LookupCode(pc());
if (!code->IsAnonymous()) { if (!code->IsAnonymous()) {
Object* table_entry = Object* table_entry =
code->owner()->compiled_module()->ptr_to_handler_table()->get( code->owner()->compiled_module()->ptr_to_handler_table()->get(
...@@ -1845,7 +1849,7 @@ WasmInstanceObject* WasmInterpreterEntryFrame::wasm_instance() const { ...@@ -1845,7 +1849,7 @@ WasmInstanceObject* WasmInterpreterEntryFrame::wasm_instance() const {
WasmInstanceObject* ret = WasmInstanceObject* ret =
FLAG_wasm_jit_to_native FLAG_wasm_jit_to_native
? WasmInstanceObject::GetOwningInstance( ? WasmInstanceObject::GetOwningInstance(
isolate()->wasm_code_manager()->LookupCode(pc())) isolate()->wasm_engine()->code_manager()->LookupCode(pc()))
: WasmInstanceObject::GetOwningInstanceGC(LookupCode()); : WasmInstanceObject::GetOwningInstanceGC(LookupCode());
// This is a live stack frame, there must be a live wasm instance available. // This is a live stack frame, there must be a live wasm instance available.
DCHECK_NOT_NULL(ret); DCHECK_NOT_NULL(ret);
...@@ -2072,8 +2076,9 @@ void JavaScriptFrame::Iterate(RootVisitor* v) const { ...@@ -2072,8 +2076,9 @@ void JavaScriptFrame::Iterate(RootVisitor* v) const {
void InternalFrame::Iterate(RootVisitor* v) const { void InternalFrame::Iterate(RootVisitor* v) const {
wasm::WasmCode* wasm_code = wasm::WasmCode* wasm_code =
FLAG_wasm_jit_to_native ? isolate()->wasm_code_manager()->LookupCode(pc()) FLAG_wasm_jit_to_native
: nullptr; ? isolate()->wasm_engine()->code_manager()->LookupCode(pc())
: nullptr;
if (wasm_code != nullptr) { if (wasm_code != nullptr) {
DCHECK(wasm_code->kind() == wasm::WasmCode::kLazyStub); DCHECK(wasm_code->kind() == wasm::WasmCode::kLazyStub);
} else { } else {
......
...@@ -54,6 +54,7 @@ ...@@ -54,6 +54,7 @@
#include "src/visitors.h" #include "src/visitors.h"
#include "src/vm-state-inl.h" #include "src/vm-state-inl.h"
#include "src/wasm/compilation-manager.h" #include "src/wasm/compilation-manager.h"
#include "src/wasm/wasm-engine.h"
#include "src/wasm/wasm-heap.h" #include "src/wasm/wasm-heap.h"
#include "src/wasm/wasm-objects.h" #include "src/wasm/wasm-objects.h"
#include "src/zone/accounting-allocator.h" #include "src/zone/accounting-allocator.h"
...@@ -1303,7 +1304,7 @@ Object* Isolate::UnwindAndFindHandler() { ...@@ -1303,7 +1304,7 @@ Object* Isolate::UnwindAndFindHandler() {
set_wasm_caught_exception(exception); set_wasm_caught_exception(exception);
if (FLAG_wasm_jit_to_native) { if (FLAG_wasm_jit_to_native) {
wasm::WasmCode* wasm_code = wasm::WasmCode* wasm_code =
wasm_code_manager()->LookupCode(frame->pc()); wasm_engine()->code_manager()->LookupCode(frame->pc());
return FoundHandler(nullptr, wasm_code->instructions().start(), return FoundHandler(nullptr, wasm_code->instructions().start(),
offset, wasm_code->constant_pool(), return_sp, offset, wasm_code->constant_pool(), return_sp,
frame->fp()); frame->fp());
...@@ -2516,7 +2517,6 @@ Isolate::Isolate(bool enable_serializer) ...@@ -2516,7 +2517,6 @@ Isolate::Isolate(bool enable_serializer)
use_counter_callback_(nullptr), use_counter_callback_(nullptr),
basic_block_profiler_(nullptr), basic_block_profiler_(nullptr),
cancelable_task_manager_(new CancelableTaskManager()), cancelable_task_manager_(new CancelableTaskManager()),
wasm_compilation_manager_(new wasm::CompilationManager()),
abort_on_uncaught_exception_callback_(nullptr), abort_on_uncaught_exception_callback_(nullptr),
total_regexp_code_generated_(0) { total_regexp_code_generated_(0) {
{ {
...@@ -2619,7 +2619,7 @@ void Isolate::Deinit() { ...@@ -2619,7 +2619,7 @@ void Isolate::Deinit() {
optimizing_compile_dispatcher_ = nullptr; optimizing_compile_dispatcher_ = nullptr;
} }
wasm_compilation_manager_->TearDown(); wasm_engine()->compilation_manager()->TearDown();
heap_.mark_compact_collector()->EnsureSweepingCompleted(); heap_.mark_compact_collector()->EnsureSweepingCompleted();
heap_.memory_allocator()->unmapper()->WaitUntilCompleted(); heap_.memory_allocator()->unmapper()->WaitUntilCompleted();
...@@ -2921,16 +2921,15 @@ bool Isolate::Init(StartupDeserializer* des) { ...@@ -2921,16 +2921,15 @@ bool Isolate::Init(StartupDeserializer* des) {
return false; return false;
} }
// Setup the wasm code manager. Currently, there's one per Isolate. // Setup the wasm engine. Currently, there's one per Isolate.
if (!wasm_code_manager_) { const size_t max_code_size =
size_t max_code_size = kMaxWasmCodeMemory; kRequiresCodeRange
if (kRequiresCodeRange) { ? std::min(kMaxWasmCodeMemory,
max_code_size = std::min(max_code_size, heap_.memory_allocator()->code_range()->size())
heap_.memory_allocator()->code_range()->size()); : kMaxWasmCodeMemory;
} wasm_engine_.reset(new wasm::WasmEngine(
wasm_code_manager_.reset(new wasm::WasmCodeManager( std::unique_ptr<wasm::WasmCodeManager>(new wasm::WasmCodeManager(
reinterpret_cast<v8::Isolate*>(this), max_code_size)); reinterpret_cast<v8::Isolate*>(this), max_code_size))));
}
// Initialize the interface descriptors ahead of time. // Initialize the interface descriptors ahead of time.
#define INTERFACE_DESCRIPTOR(Name, ...) \ #define INTERFACE_DESCRIPTOR(Name, ...) \
...@@ -3988,10 +3987,6 @@ void Isolate::PrintWithTimestamp(const char* format, ...) { ...@@ -3988,10 +3987,6 @@ void Isolate::PrintWithTimestamp(const char* format, ...) {
va_end(arguments); va_end(arguments);
} }
wasm::WasmCodeManager* Isolate::wasm_code_manager() {
return wasm_code_manager_.get();
}
bool StackLimitCheck::JsHasOverflowed(uintptr_t gap) const { bool StackLimitCheck::JsHasOverflowed(uintptr_t gap) const {
StackGuard* stack_guard = isolate_->stack_guard(); StackGuard* stack_guard = isolate_->stack_guard();
#ifdef USE_SIMULATOR #ifdef USE_SIMULATOR
......
...@@ -109,8 +109,7 @@ class Interpreter; ...@@ -109,8 +109,7 @@ class Interpreter;
} }
namespace wasm { namespace wasm {
class CompilationManager; class WasmEngine;
class WasmCodeManager;
} }
#define RETURN_FAILURE_IF_SCHEDULED_EXCEPTION(isolate) \ #define RETURN_FAILURE_IF_SCHEDULED_EXCEPTION(isolate) \
...@@ -331,7 +330,7 @@ class ThreadLocalTop BASE_EMBEDDED { ...@@ -331,7 +330,7 @@ class ThreadLocalTop BASE_EMBEDDED {
Object* pending_exception_; Object* pending_exception_;
// TODO(kschimpf): Change this to a stack of caught exceptions (rather than // TODO(kschimpf): Change this to a stack of caught exceptions (rather than
// just innermost catching try block). // just innermost catching try block).
Object* wasm_caught_exception_; Object* wasm_caught_exception_ = nullptr;
// Communication channel between Isolate::FindHandler and the CEntryStub. // Communication channel between Isolate::FindHandler and the CEntryStub.
Context* pending_handler_context_; Context* pending_handler_context_;
...@@ -926,7 +925,7 @@ class Isolate { ...@@ -926,7 +925,7 @@ class Isolate {
} }
StackGuard* stack_guard() { return &stack_guard_; } StackGuard* stack_guard() { return &stack_guard_; }
Heap* heap() { return &heap_; } Heap* heap() { return &heap_; }
V8_EXPORT_PRIVATE wasm::WasmCodeManager* wasm_code_manager(); wasm::WasmEngine* wasm_engine() const { return wasm_engine_.get(); }
StubCache* load_stub_cache() { return load_stub_cache_; } StubCache* load_stub_cache() { return load_stub_cache_; }
StubCache* store_stub_cache() { return store_stub_cache_; } StubCache* store_stub_cache() { return store_stub_cache_; }
DeoptimizerData* deoptimizer_data() { return deoptimizer_data_; } DeoptimizerData* deoptimizer_data() { return deoptimizer_data_; }
...@@ -1288,10 +1287,6 @@ class Isolate { ...@@ -1288,10 +1287,6 @@ class Isolate {
return cancelable_task_manager_; return cancelable_task_manager_;
} }
wasm::CompilationManager* wasm_compilation_manager() {
return wasm_compilation_manager_.get();
}
const AstStringConstants* ast_string_constants() const { const AstStringConstants* ast_string_constants() const {
return ast_string_constants_; return ast_string_constants_;
} }
...@@ -1663,8 +1658,6 @@ class Isolate { ...@@ -1663,8 +1658,6 @@ class Isolate {
CancelableTaskManager* cancelable_task_manager_; CancelableTaskManager* cancelable_task_manager_;
std::unique_ptr<wasm::CompilationManager> wasm_compilation_manager_;
debug::ConsoleDelegate* console_delegate_ = nullptr; debug::ConsoleDelegate* console_delegate_ = nullptr;
v8::Isolate::AbortOnUncaughtExceptionCallback v8::Isolate::AbortOnUncaughtExceptionCallback
...@@ -1683,7 +1676,7 @@ class Isolate { ...@@ -1683,7 +1676,7 @@ class Isolate {
size_t elements_deletion_counter_ = 0; size_t elements_deletion_counter_ = 0;
std::unique_ptr<wasm::WasmCodeManager> wasm_code_manager_; std::unique_ptr<wasm::WasmEngine> wasm_engine_;
// The top entry of the v8::Context::BackupIncumbentScope stack. // The top entry of the v8::Context::BackupIncumbentScope stack.
const v8::Context::BackupIncumbentScope* top_backup_incumbent_scope_ = const v8::Context::BackupIncumbentScope* top_backup_incumbent_scope_ =
......
...@@ -16,6 +16,7 @@ ...@@ -16,6 +16,7 @@
#include "src/ostreams.h" #include "src/ostreams.h"
#include "src/regexp/jsregexp.h" #include "src/regexp/jsregexp.h"
#include "src/transitions-inl.h" #include "src/transitions-inl.h"
#include "src/wasm/wasm-engine.h"
#include "src/wasm/wasm-heap.h" #include "src/wasm/wasm-heap.h"
#include "src/wasm/wasm-objects-inl.h" #include "src/wasm/wasm-objects-inl.h"
...@@ -1897,8 +1898,9 @@ extern void _v8_internal_Print_Object(void* object) { ...@@ -1897,8 +1898,9 @@ extern void _v8_internal_Print_Object(void* object) {
extern void _v8_internal_Print_Code(void* object) { extern void _v8_internal_Print_Code(void* object) {
i::Isolate* isolate = i::Isolate::Current(); i::Isolate* isolate = i::Isolate::Current();
i::wasm::WasmCode* wasm_code = isolate->wasm_code_manager()->LookupCode( i::wasm::WasmCode* wasm_code =
reinterpret_cast<i::Address>(object)); isolate->wasm_engine()->code_manager()->LookupCode(
reinterpret_cast<i::Address>(object));
if (wasm_code) { if (wasm_code) {
wasm_code->Print(isolate); wasm_code->Print(isolate);
return; return;
......
...@@ -20,6 +20,7 @@ ...@@ -20,6 +20,7 @@
#include "src/trap-handler/trap-handler.h" #include "src/trap-handler/trap-handler.h"
#include "src/wasm/memory-tracing.h" #include "src/wasm/memory-tracing.h"
#include "src/wasm/module-compiler.h" #include "src/wasm/module-compiler.h"
#include "src/wasm/wasm-engine.h"
#include "src/wasm/wasm-module.h" #include "src/wasm/wasm-module.h"
#include "src/wasm/wasm-objects-inl.h" #include "src/wasm/wasm-objects-inl.h"
#include "src/wasm/wasm-serialization.h" #include "src/wasm/wasm-serialization.h"
...@@ -500,7 +501,7 @@ RUNTIME_FUNCTION(Runtime_CheckWasmWrapperElision) { ...@@ -500,7 +501,7 @@ RUNTIME_FUNCTION(Runtime_CheckWasmWrapperElision) {
: rinfo->target_address(); : rinfo->target_address();
if (FLAG_wasm_jit_to_native) { if (FLAG_wasm_jit_to_native) {
wasm::WasmCode* target = wasm::WasmCode* target =
isolate->wasm_code_manager()->LookupCode(target_address); isolate->wasm_engine()->code_manager()->LookupCode(target_address);
if (target->kind() == wasm::WasmCode::kFunction) { if (target->kind() == wasm::WasmCode::kFunction) {
++count; ++count;
export_fct = target; export_fct = target;
...@@ -524,7 +525,7 @@ RUNTIME_FUNCTION(Runtime_CheckWasmWrapperElision) { ...@@ -524,7 +525,7 @@ RUNTIME_FUNCTION(Runtime_CheckWasmWrapperElision) {
RelocInfo* rinfo = it.rinfo(); RelocInfo* rinfo = it.rinfo();
Address target_address = rinfo->target_address(); Address target_address = rinfo->target_address();
wasm::WasmCode* target = wasm::WasmCode* target =
isolate->wasm_code_manager()->LookupCode(target_address); isolate->wasm_engine()->code_manager()->LookupCode(target_address);
if (target->kind() == wasm::WasmCode::kFunction) { if (target->kind() == wasm::WasmCode::kFunction) {
++count; ++count;
intermediate_fct = target; intermediate_fct = target;
...@@ -560,7 +561,7 @@ RUNTIME_FUNCTION(Runtime_CheckWasmWrapperElision) { ...@@ -560,7 +561,7 @@ RUNTIME_FUNCTION(Runtime_CheckWasmWrapperElision) {
RelocInfo* rinfo = it.rinfo(); RelocInfo* rinfo = it.rinfo();
Address target_address = rinfo->target_address(); Address target_address = rinfo->target_address();
wasm::WasmCode* target = wasm::WasmCode* target =
isolate->wasm_code_manager()->LookupCode(target_address); isolate->wasm_engine()->code_manager()->LookupCode(target_address);
if (target->kind() == target_kind) { if (target->kind() == target_kind) {
++count; ++count;
} }
......
...@@ -16,6 +16,7 @@ ...@@ -16,6 +16,7 @@
#include "src/trap-handler/trap-handler.h" #include "src/trap-handler/trap-handler.h"
#include "src/v8memory.h" #include "src/v8memory.h"
#include "src/wasm/module-compiler.h" #include "src/wasm/module-compiler.h"
#include "src/wasm/wasm-engine.h"
#include "src/wasm/wasm-heap.h" #include "src/wasm/wasm-heap.h"
#include "src/wasm/wasm-objects.h" #include "src/wasm/wasm-objects.h"
#include "src/wasm/wasm-opcodes.h" #include "src/wasm/wasm-opcodes.h"
...@@ -33,7 +34,7 @@ WasmInstanceObject* GetWasmInstanceOnStackTop(Isolate* isolate) { ...@@ -33,7 +34,7 @@ WasmInstanceObject* GetWasmInstanceOnStackTop(Isolate* isolate) {
WasmInstanceObject* owning_instance = nullptr; WasmInstanceObject* owning_instance = nullptr;
if (FLAG_wasm_jit_to_native) { if (FLAG_wasm_jit_to_native) {
owning_instance = WasmInstanceObject::GetOwningInstance( owning_instance = WasmInstanceObject::GetOwningInstance(
isolate->wasm_code_manager()->LookupCode(pc)); isolate->wasm_engine()->code_manager()->LookupCode(pc));
} else { } else {
owning_instance = WasmInstanceObject::GetOwningInstanceGC( owning_instance = WasmInstanceObject::GetOwningInstanceGC(
isolate->inner_pointer_to_code_cache()->GetCacheEntry(pc)->code); isolate->inner_pointer_to_code_cache()->GetCacheEntry(pc)->code);
......
...@@ -1472,6 +1472,7 @@ ...@@ -1472,6 +1472,7 @@
'wasm/wasm-code-wrapper.cc', 'wasm/wasm-code-wrapper.cc',
'wasm/wasm-code-wrapper.h', 'wasm/wasm-code-wrapper.h',
'wasm/wasm-debug.cc', 'wasm/wasm-debug.cc',
'wasm/wasm-engine.h',
'wasm/wasm-external-refs.cc', 'wasm/wasm-external-refs.cc',
'wasm/wasm-external-refs.h', 'wasm/wasm-external-refs.h',
'wasm/wasm-heap.cc', 'wasm/wasm-heap.cc',
......
...@@ -20,6 +20,7 @@ ...@@ -20,6 +20,7 @@
#include "src/wasm/compilation-manager.h" #include "src/wasm/compilation-manager.h"
#include "src/wasm/module-decoder.h" #include "src/wasm/module-decoder.h"
#include "src/wasm/wasm-code-specialization.h" #include "src/wasm/wasm-code-specialization.h"
#include "src/wasm/wasm-engine.h"
#include "src/wasm/wasm-heap.h" #include "src/wasm/wasm-heap.h"
#include "src/wasm/wasm-js.h" #include "src/wasm/wasm-js.h"
#include "src/wasm/wasm-memory.h" #include "src/wasm/wasm-memory.h"
...@@ -638,8 +639,10 @@ void AsyncCompile(Isolate* isolate, Handle<JSPromise> promise, ...@@ -638,8 +639,10 @@ void AsyncCompile(Isolate* isolate, Handle<JSPromise> promise,
if (FLAG_wasm_test_streaming) { if (FLAG_wasm_test_streaming) {
std::shared_ptr<StreamingDecoder> streaming_decoder = std::shared_ptr<StreamingDecoder> streaming_decoder =
isolate->wasm_compilation_manager()->StartStreamingCompilation( isolate->wasm_engine()
isolate, handle(isolate->context()), promise); ->compilation_manager()
->StartStreamingCompilation(isolate, handle(isolate->context()),
promise);
streaming_decoder->OnBytesReceived(bytes.module_bytes()); streaming_decoder->OnBytesReceived(bytes.module_bytes());
streaming_decoder->Finish(); streaming_decoder->Finish();
return; return;
...@@ -648,7 +651,7 @@ void AsyncCompile(Isolate* isolate, Handle<JSPromise> promise, ...@@ -648,7 +651,7 @@ void AsyncCompile(Isolate* isolate, Handle<JSPromise> promise,
// during asynchronous compilation. // during asynchronous compilation.
std::unique_ptr<byte[]> copy(new byte[bytes.length()]); std::unique_ptr<byte[]> copy(new byte[bytes.length()]);
memcpy(copy.get(), bytes.start(), bytes.length()); memcpy(copy.get(), bytes.start(), bytes.length());
isolate->wasm_compilation_manager()->StartAsyncCompileJob( isolate->wasm_engine()->compilation_manager()->StartAsyncCompileJob(
isolate, std::move(copy), bytes.length(), handle(isolate->context()), isolate, std::move(copy), bytes.length(), handle(isolate->context()),
promise); promise);
} }
...@@ -758,7 +761,7 @@ Address CompileLazy(Isolate* isolate) { ...@@ -758,7 +761,7 @@ Address CompileLazy(Isolate* isolate) {
Maybe<uint32_t> func_index_to_compile = Nothing<uint32_t>(); Maybe<uint32_t> func_index_to_compile = Nothing<uint32_t>();
Handle<Object> exp_deopt_data_entry; Handle<Object> exp_deopt_data_entry;
const wasm::WasmCode* lazy_stub_or_copy = const wasm::WasmCode* lazy_stub_or_copy =
isolate->wasm_code_manager()->LookupCode(it.frame()->pc()); isolate->wasm_engine()->code_manager()->LookupCode(it.frame()->pc());
DCHECK_EQ(wasm::WasmCode::kLazyStub, lazy_stub_or_copy->kind()); DCHECK_EQ(wasm::WasmCode::kLazyStub, lazy_stub_or_copy->kind());
if (!lazy_stub_or_copy->IsAnonymous()) { if (!lazy_stub_or_copy->IsAnonymous()) {
// Then it's an indirect call or via JS->wasm wrapper. // Then it's an indirect call or via JS->wasm wrapper.
...@@ -782,7 +785,7 @@ Address CompileLazy(Isolate* isolate) { ...@@ -782,7 +785,7 @@ Address CompileLazy(Isolate* isolate) {
js_to_wasm_caller_code = handle(it.frame()->LookupCode(), isolate); js_to_wasm_caller_code = handle(it.frame()->LookupCode(), isolate);
} else { } else {
wasm_caller_code = wasm_caller_code =
isolate->wasm_code_manager()->LookupCode(it.frame()->pc()); isolate->wasm_engine()->code_manager()->LookupCode(it.frame()->pc());
offset = Just(static_cast<uint32_t>( offset = Just(static_cast<uint32_t>(
it.frame()->pc() - wasm_caller_code->instructions().start())); it.frame()->pc() - wasm_caller_code->instructions().start()));
if (instance.is_null()) { if (instance.is_null()) {
...@@ -1267,8 +1270,9 @@ const wasm::WasmCode* LazyCompilationOrchestrator::CompileDirectCall( ...@@ -1267,8 +1270,9 @@ const wasm::WasmCode* LazyCompilationOrchestrator::CompileDirectCall(
wasm_caller->constant_pool(), wasm_caller->constant_pool(),
RelocInfo::ModeMask(RelocInfo::WASM_CALL)); RelocInfo::ModeMask(RelocInfo::WASM_CALL));
!it.done(); it.next()) { !it.done(); it.next()) {
const WasmCode* callee = isolate->wasm_code_manager()->LookupCode( const WasmCode* callee =
it.rinfo()->target_address()); isolate->wasm_engine()->code_manager()->LookupCode(
it.rinfo()->target_address());
if (callee->kind() != WasmCode::kLazyStub) { if (callee->kind() != WasmCode::kLazyStub) {
non_compiled_functions.push_back(Nothing<WasmDirectCallData>()); non_compiled_functions.push_back(Nothing<WasmDirectCallData>());
continue; continue;
...@@ -3555,7 +3559,7 @@ void AsyncCompileJob::Abort() { ...@@ -3555,7 +3559,7 @@ void AsyncCompileJob::Abort() {
background_task_manager_.CancelAndWait(); background_task_manager_.CancelAndWait();
if (num_pending_foreground_tasks_ == 0) { if (num_pending_foreground_tasks_ == 0) {
// No task is pending, we can just remove the AsyncCompileJob. // No task is pending, we can just remove the AsyncCompileJob.
isolate_->wasm_compilation_manager()->RemoveJob(this); isolate_->wasm_engine()->compilation_manager()->RemoveJob(this);
} else { } else {
// There is still a compilation task in the task queue. We enter the // There is still a compilation task in the task queue. We enter the
// AbortCompilation state and wait for this compilation task to abort the // AbortCompilation state and wait for this compilation task to abort the
...@@ -3616,14 +3620,14 @@ void AsyncCompileJob::AsyncCompileFailed(ErrorThrower& thrower) { ...@@ -3616,14 +3620,14 @@ void AsyncCompileJob::AsyncCompileFailed(ErrorThrower& thrower) {
if (stream_) stream_->NotifyError(); if (stream_) stream_->NotifyError();
// {job} keeps the {this} pointer alive. // {job} keeps the {this} pointer alive.
std::shared_ptr<AsyncCompileJob> job = std::shared_ptr<AsyncCompileJob> job =
isolate_->wasm_compilation_manager()->RemoveJob(this); isolate_->wasm_engine()->compilation_manager()->RemoveJob(this);
RejectPromise(isolate_, context_, thrower, module_promise_); RejectPromise(isolate_, context_, thrower, module_promise_);
} }
void AsyncCompileJob::AsyncCompileSucceeded(Handle<Object> result) { void AsyncCompileJob::AsyncCompileSucceeded(Handle<Object> result) {
// {job} keeps the {this} pointer alive. // {job} keeps the {this} pointer alive.
std::shared_ptr<AsyncCompileJob> job = std::shared_ptr<AsyncCompileJob> job =
isolate_->wasm_compilation_manager()->RemoveJob(this); isolate_->wasm_engine()->compilation_manager()->RemoveJob(this);
ResolvePromise(isolate_, context_, module_promise_, result); ResolvePromise(isolate_, context_, module_promise_, result);
} }
...@@ -4077,7 +4081,7 @@ class AsyncCompileJob::FinishModule : public CompileStep { ...@@ -4077,7 +4081,7 @@ class AsyncCompileJob::FinishModule : public CompileStep {
class AsyncCompileJob::AbortCompilation : public CompileStep { class AsyncCompileJob::AbortCompilation : public CompileStep {
void RunInForeground() override { void RunInForeground() override {
TRACE_COMPILE("Abort asynchronous compilation ...\n"); TRACE_COMPILE("Abort asynchronous compilation ...\n");
job_->isolate_->wasm_compilation_manager()->RemoveJob(job_); job_->isolate_->wasm_engine()->compilation_manager()->RemoveJob(job_);
} }
}; };
......
// Copyright 2017 the V8 project authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef WASM_ENGINE_H_
#define WASM_ENGINE_H_
#include <memory>
#include "src/wasm/compilation-manager.h"
#include "src/wasm/wasm-heap.h"
namespace v8 {
namespace internal {
namespace wasm {
class CompilationManager;
// The central data structure that represents an engine instance capable of
// loading, instantiating, and executing WASM code.
class WasmEngine {
public:
explicit WasmEngine(std::unique_ptr<WasmCodeManager> code_manager)
: code_manager_(std::move(code_manager)) {}
CompilationManager* compilation_manager() { return &compilation_manager_; }
WasmCodeManager* code_manager() const { return code_manager_.get(); }
private:
CompilationManager compilation_manager_;
std::unique_ptr<WasmCodeManager> code_manager_;
};
} // namespace wasm
} // namespace internal
} // namespace v8
#endif
...@@ -19,6 +19,7 @@ ...@@ -19,6 +19,7 @@
#include "src/wasm/function-body-decoder-impl.h" #include "src/wasm/function-body-decoder-impl.h"
#include "src/wasm/function-body-decoder.h" #include "src/wasm/function-body-decoder.h"
#include "src/wasm/memory-tracing.h" #include "src/wasm/memory-tracing.h"
#include "src/wasm/wasm-engine.h"
#include "src/wasm/wasm-external-refs.h" #include "src/wasm/wasm-external-refs.h"
#include "src/wasm/wasm-limits.h" #include "src/wasm/wasm-limits.h"
#include "src/wasm/wasm-module.h" #include "src/wasm/wasm-module.h"
...@@ -2605,7 +2606,8 @@ class ThreadImpl { ...@@ -2605,7 +2606,8 @@ class ThreadImpl {
Foreign::cast(fun_table->get(static_cast<int>(entry_index))) Foreign::cast(fun_table->get(static_cast<int>(entry_index)))
->foreign_address(); ->foreign_address();
target = target =
isolate->wasm_code_manager()->GetCodeFromStartAddress(first_instr); isolate->wasm_engine()->code_manager()->GetCodeFromStartAddress(
first_instr);
} }
} }
......
...@@ -15,6 +15,7 @@ ...@@ -15,6 +15,7 @@
#include "src/wasm/module-compiler.h" #include "src/wasm/module-compiler.h"
#include "src/wasm/module-decoder.h" #include "src/wasm/module-decoder.h"
#include "src/wasm/wasm-code-specialization.h" #include "src/wasm/wasm-code-specialization.h"
#include "src/wasm/wasm-engine.h"
#include "src/wasm/wasm-memory.h" #include "src/wasm/wasm-memory.h"
#include "src/wasm/wasm-module.h" #include "src/wasm/wasm-module.h"
#include "src/wasm/wasm-objects-inl.h" #include "src/wasm/wasm-objects-inl.h"
...@@ -762,8 +763,9 @@ WasmCodeWrapper WasmExportedFunction::GetWasmCode() { ...@@ -762,8 +763,9 @@ WasmCodeWrapper WasmExportedFunction::GetWasmCode() {
DCHECK(!it.done()); DCHECK(!it.done());
WasmCodeWrapper target; WasmCodeWrapper target;
if (FLAG_wasm_jit_to_native) { if (FLAG_wasm_jit_to_native) {
target = WasmCodeWrapper(GetIsolate()->wasm_code_manager()->LookupCode( target = WasmCodeWrapper(
it.rinfo()->js_to_wasm_address())); GetIsolate()->wasm_engine()->code_manager()->LookupCode(
it.rinfo()->js_to_wasm_address()));
} else { } else {
Code* code = Code::GetCodeFromTargetAddress(it.rinfo()->target_address()); Code* code = Code::GetCodeFromTargetAddress(it.rinfo()->target_address());
if (!IsWasmFunctionCode(code)) continue; if (!IsWasmFunctionCode(code)) continue;
...@@ -1069,7 +1071,7 @@ Handle<WasmCompiledModule> WasmCompiledModule::New( ...@@ -1069,7 +1071,7 @@ Handle<WasmCompiledModule> WasmCompiledModule::New(
wasm::NativeModule* native_module = nullptr; wasm::NativeModule* native_module = nullptr;
{ {
std::unique_ptr<wasm::NativeModule> native_module_ptr = std::unique_ptr<wasm::NativeModule> native_module_ptr =
isolate->wasm_code_manager()->NewNativeModule(*module); isolate->wasm_engine()->code_manager()->NewNativeModule(*module);
native_module = native_module_ptr.release(); native_module = native_module_ptr.release();
Handle<Foreign> native_module_wrapper = Handle<Foreign> native_module_wrapper =
Managed<wasm::NativeModule>::From(isolate, native_module); Managed<wasm::NativeModule>::From(isolate, native_module);
......
...@@ -10,6 +10,7 @@ ...@@ -10,6 +10,7 @@
#include "src/wasm/compilation-manager.h" #include "src/wasm/compilation-manager.h"
#include "src/wasm/module-decoder.h" #include "src/wasm/module-decoder.h"
#include "src/wasm/streaming-decoder.h" #include "src/wasm/streaming-decoder.h"
#include "src/wasm/wasm-engine.h"
#include "src/wasm/wasm-module-builder.h" #include "src/wasm/wasm-module-builder.h"
#include "src/wasm/wasm-module.h" #include "src/wasm/wasm-module.h"
...@@ -103,8 +104,10 @@ class StreamTester { ...@@ -103,8 +104,10 @@ class StreamTester {
i::Handle<i::JSPromise> i_promise = v8::Utils::OpenHandle(*promise_); i::Handle<i::JSPromise> i_promise = v8::Utils::OpenHandle(*promise_);
stream_ = i_isolate->wasm_compilation_manager()->StartStreamingCompilation( stream_ = i_isolate->wasm_engine()
i_isolate, v8::Utils::OpenHandle(*context), i_promise); ->compilation_manager()
->StartStreamingCompilation(
i_isolate, v8::Utils::OpenHandle(*context), i_promise);
} }
std::shared_ptr<StreamingDecoder> stream() { return stream_; } std::shared_ptr<StreamingDecoder> stream() { return stream_; }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment