Commit c224c67a authored by Michael Starzinger's avatar Michael Starzinger Committed by Commit Bot

[wasm] Move {use_trap_handler} field into {NativeModule}.

The predicate in question is specific to the code generated for a given
module, hence specific to the {NativeModule} and independent of the
instance.

R=ahaas@chromium.org

Change-Id: I108ee8126897ed732e8c52b549de170339a125a8
Reviewed-on: https://chromium-review.googlesource.com/1033741
Commit-Queue: Michael Starzinger <mstarzinger@chromium.org>
Reviewed-by: 's avatarAndreas Haas <ahaas@chromium.org>
Cr-Commit-Position: refs/heads/master@{#52886}
parent 0600afdd
...@@ -1517,7 +1517,6 @@ void WasmCompiledModule::WasmCompiledModuleVerify() { ...@@ -1517,7 +1517,6 @@ void WasmCompiledModule::WasmCompiledModuleVerify() {
VerifyObjectField(kWasmModuleOffset); VerifyObjectField(kWasmModuleOffset);
VerifyObjectField(kNativeModuleOffset); VerifyObjectField(kNativeModuleOffset);
VerifyObjectField(kLazyCompileDataOffset); VerifyObjectField(kLazyCompileDataOffset);
VerifyObjectField(kUseTrapHandlerOffset);
} }
void WasmDebugInfo::WasmDebugInfoVerify() { void WasmDebugInfo::WasmDebugInfoVerify() {
......
...@@ -287,7 +287,8 @@ class InstanceBuilder { ...@@ -287,7 +287,8 @@ class InstanceBuilder {
Counters* counters() const { return async_counters().get(); } Counters* counters() const { return async_counters().get(); }
wasm::UseTrapHandler use_trap_handler() const { wasm::UseTrapHandler use_trap_handler() const {
return compiled_module_->use_trap_handler() ? kUseTrapHandler return compiled_module_->GetNativeModule()->use_trap_handler()
? kUseTrapHandler
: kNoTrapHandler; : kNoTrapHandler;
} }
...@@ -489,7 +490,8 @@ ModuleEnv CreateModuleEnvFromCompiledModule( ...@@ -489,7 +490,8 @@ ModuleEnv CreateModuleEnvFromCompiledModule(
DisallowHeapAllocation no_gc; DisallowHeapAllocation no_gc;
WasmModule* module = compiled_module->shared()->module(); WasmModule* module = compiled_module->shared()->module();
wasm::UseTrapHandler use_trap_handler = wasm::UseTrapHandler use_trap_handler =
compiled_module->use_trap_handler() ? kUseTrapHandler : kNoTrapHandler; compiled_module->GetNativeModule()->use_trap_handler() ? kUseTrapHandler
: kNoTrapHandler;
return ModuleEnv(module, use_trap_handler, wasm::kRuntimeExceptionSupport); return ModuleEnv(module, use_trap_handler, wasm::kRuntimeExceptionSupport);
} }
...@@ -3702,7 +3704,8 @@ void CompileJsToWasmWrappers(Isolate* isolate, ...@@ -3702,7 +3704,8 @@ void CompileJsToWasmWrappers(Isolate* isolate,
isolate); isolate);
NativeModule* native_module = compiled_module->GetNativeModule(); NativeModule* native_module = compiled_module->GetNativeModule();
wasm::UseTrapHandler use_trap_handler = wasm::UseTrapHandler use_trap_handler =
compiled_module->use_trap_handler() ? kUseTrapHandler : kNoTrapHandler; compiled_module->GetNativeModule()->use_trap_handler() ? kUseTrapHandler
: kNoTrapHandler;
for (auto exp : compiled_module->shared()->module()->export_table) { for (auto exp : compiled_module->shared()->module()->export_table) {
if (exp.kind != kExternalFunction) continue; if (exp.kind != kExternalFunction) continue;
wasm::WasmCode* wasm_code = wasm::WasmCode* wasm_code =
......
...@@ -16,6 +16,7 @@ ...@@ -16,6 +16,7 @@
#include "src/globals.h" #include "src/globals.h"
#include "src/macro-assembler.h" #include "src/macro-assembler.h"
#include "src/objects-inl.h" #include "src/objects-inl.h"
#include "src/wasm/function-compiler.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-objects.h" #include "src/wasm/wasm-objects.h"
...@@ -338,7 +339,8 @@ NativeModule::NativeModule(uint32_t num_functions, uint32_t num_imports, ...@@ -338,7 +339,8 @@ NativeModule::NativeModule(uint32_t num_functions, uint32_t num_imports,
reinterpret_cast<Isolate*>(code_manager->isolate_), env)), reinterpret_cast<Isolate*>(code_manager->isolate_), env)),
free_memory_(mem->address(), mem->end()), free_memory_(mem->address(), mem->end()),
wasm_code_manager_(code_manager), wasm_code_manager_(code_manager),
can_request_more_memory_(can_request_more) { can_request_more_memory_(can_request_more),
use_trap_handler_(env.use_trap_handler) {
VirtualMemory my_mem; VirtualMemory my_mem;
owned_memory_.push_back(my_mem); owned_memory_.push_back(my_mem);
owned_memory_.back().TakeControl(mem); owned_memory_.back().TakeControl(mem);
......
...@@ -269,16 +269,15 @@ class V8_EXPORT_PRIVATE NativeModule final { ...@@ -269,16 +269,15 @@ class V8_EXPORT_PRIVATE NativeModule final {
void SetSharedModuleData(Handle<WasmSharedModuleData>); void SetSharedModuleData(Handle<WasmSharedModuleData>);
uint32_t num_imported_functions() const { return num_imported_functions_; } uint32_t num_imported_functions() const { return num_imported_functions_; }
const std::vector<WasmCode*>& code_table() const { return code_table_; } const std::vector<WasmCode*>& code_table() const { return code_table_; }
size_t committed_memory() const { return committed_memory_; } size_t committed_memory() const { return committed_memory_; }
bool use_trap_handler() const { return use_trap_handler_; }
void set_lazy_compile_frozen(bool frozen) { lazy_compile_frozen_ = frozen; }
bool lazy_compile_frozen() const { return lazy_compile_frozen_; }
const size_t instance_id = 0; const size_t instance_id = 0;
~NativeModule(); ~NativeModule();
void set_lazy_compile_frozen(bool frozen) { frozen_ = frozen; }
bool lazy_compile_frozen() const { return frozen_; }
private: private:
friend class WasmCodeManager; friend class WasmCodeManager;
friend class NativeModuleSerializer; friend class NativeModuleSerializer;
...@@ -343,10 +342,11 @@ class V8_EXPORT_PRIVATE NativeModule final { ...@@ -343,10 +342,11 @@ class V8_EXPORT_PRIVATE NativeModule final {
WasmCodeManager* wasm_code_manager_; WasmCodeManager* wasm_code_manager_;
base::Mutex allocation_mutex_; base::Mutex allocation_mutex_;
size_t committed_memory_ = 0; size_t committed_memory_ = 0;
int modification_scope_depth_ = 0;
bool can_request_more_memory_; bool can_request_more_memory_;
bool use_trap_handler_;
bool is_executable_ = false; bool is_executable_ = false;
bool frozen_ = false; bool lazy_compile_frozen_ = false;
int modification_scope_depth_ = 0;
DISALLOW_COPY_AND_ASSIGN(NativeModule); DISALLOW_COPY_AND_ASSIGN(NativeModule);
}; };
......
...@@ -209,15 +209,6 @@ OPTIONAL_ACCESSORS(WasmDebugInfo, c_wasm_entry_map, Managed<wasm::SignatureMap>, ...@@ -209,15 +209,6 @@ OPTIONAL_ACCESSORS(WasmDebugInfo, c_wasm_entry_map, Managed<wasm::SignatureMap>,
#define WCM_OBJECT(TYPE, NAME, OFFSET) \ #define WCM_OBJECT(TYPE, NAME, OFFSET) \
WCM_OBJECT_OR_WEAK(TYPE, NAME, OFFSET, value->Is##TYPE()) WCM_OBJECT_OR_WEAK(TYPE, NAME, OFFSET, value->Is##TYPE())
#define WCM_SMALL_CONST_NUMBER(TYPE, NAME, OFFSET) \
TYPE WasmCompiledModule::NAME() const { \
return static_cast<TYPE>(Smi::ToInt(READ_FIELD(this, OFFSET))); \
} \
\
void WasmCompiledModule::set_##NAME(TYPE value) { \
WRITE_FIELD(this, OFFSET, Smi::FromInt(value)); \
}
#define WCM_WEAK_LINK(TYPE, NAME, OFFSET) \ #define WCM_WEAK_LINK(TYPE, NAME, OFFSET) \
WCM_OBJECT_OR_WEAK(WeakCell, weak_##NAME, OFFSET, value->IsWeakCell()) \ WCM_OBJECT_OR_WEAK(WeakCell, weak_##NAME, OFFSET, value->IsWeakCell()) \
\ \
...@@ -235,13 +226,11 @@ WCM_OBJECT(WasmCompiledModule, prev_instance, kPrevInstanceOffset) ...@@ -235,13 +226,11 @@ WCM_OBJECT(WasmCompiledModule, prev_instance, kPrevInstanceOffset)
WCM_WEAK_LINK(WasmInstanceObject, owning_instance, kOwningInstanceOffset) WCM_WEAK_LINK(WasmInstanceObject, owning_instance, kOwningInstanceOffset)
WCM_WEAK_LINK(WasmModuleObject, wasm_module, kWasmModuleOffset) WCM_WEAK_LINK(WasmModuleObject, wasm_module, kWasmModuleOffset)
WCM_OBJECT(Foreign, native_module, kNativeModuleOffset) WCM_OBJECT(Foreign, native_module, kNativeModuleOffset)
WCM_SMALL_CONST_NUMBER(bool, use_trap_handler, kUseTrapHandlerOffset)
ACCESSORS(WasmCompiledModule, raw_next_instance, Object, kNextInstanceOffset); ACCESSORS(WasmCompiledModule, raw_next_instance, Object, kNextInstanceOffset);
ACCESSORS(WasmCompiledModule, raw_prev_instance, Object, kPrevInstanceOffset); ACCESSORS(WasmCompiledModule, raw_prev_instance, Object, kPrevInstanceOffset);
#undef WCM_OBJECT_OR_WEAK #undef WCM_OBJECT_OR_WEAK
#undef WCM_OBJECT #undef WCM_OBJECT
#undef WCM_SMALL_CONST_NUMBER
#undef WCM_WEAK_LINK #undef WCM_WEAK_LINK
#undef READ_PRIMITIVE_FIELD #undef READ_PRIMITIVE_FIELD
#undef WRITE_PRIMITIVE_FIELD #undef WRITE_PRIMITIVE_FIELD
......
...@@ -1369,7 +1369,6 @@ Handle<WasmCompiledModule> WasmCompiledModule::New( ...@@ -1369,7 +1369,6 @@ Handle<WasmCompiledModule> WasmCompiledModule::New(
Handle<WeakCell> weak_native_context = Handle<WeakCell> weak_native_context =
isolate->factory()->NewWeakCell(isolate->native_context()); isolate->factory()->NewWeakCell(isolate->native_context());
compiled_module->set_weak_native_context(*weak_native_context); compiled_module->set_weak_native_context(*weak_native_context);
compiled_module->set_use_trap_handler(env.use_trap_handler);
if (!export_wrappers.is_null()) { if (!export_wrappers.is_null()) {
compiled_module->set_export_wrappers(*export_wrappers); compiled_module->set_export_wrappers(*export_wrappers);
} }
...@@ -1399,7 +1398,6 @@ Handle<WasmCompiledModule> WasmCompiledModule::Clone( ...@@ -1399,7 +1398,6 @@ Handle<WasmCompiledModule> WasmCompiledModule::Clone(
ret->set_weak_wasm_module(module->weak_wasm_module()); ret->set_weak_wasm_module(module->weak_wasm_module());
ret->set_weak_owning_instance(isolate->heap()->empty_weak_cell()); ret->set_weak_owning_instance(isolate->heap()->empty_weak_cell());
ret->set_native_module(module->native_module()); ret->set_native_module(module->native_module());
ret->set_use_trap_handler(module->use_trap_handler());
Handle<FixedArray> export_copy = isolate->factory()->CopyFixedArray( Handle<FixedArray> export_copy = isolate->factory()->CopyFixedArray(
handle(module->export_wrappers(), isolate)); handle(module->export_wrappers(), isolate));
...@@ -1431,7 +1429,7 @@ void WasmCompiledModule::Reset(Isolate* isolate, ...@@ -1431,7 +1429,7 @@ void WasmCompiledModule::Reset(Isolate* isolate,
native_module->SetExecutable(false); native_module->SetExecutable(false);
TRACE("Resetting %zu\n", native_module->instance_id); TRACE("Resetting %zu\n", native_module->instance_id);
if (compiled_module->use_trap_handler()) { if (native_module->use_trap_handler()) {
native_module->ReleaseProtectedInstructions(); native_module->ReleaseProtectedInstructions();
} }
......
...@@ -501,7 +501,6 @@ class WasmCompiledModule : public Struct { ...@@ -501,7 +501,6 @@ class WasmCompiledModule : public Struct {
V(kWasmModuleOffset, kPointerSize) \ V(kWasmModuleOffset, kPointerSize) \
V(kNativeModuleOffset, kPointerSize) \ V(kNativeModuleOffset, kPointerSize) \
V(kLazyCompileDataOffset, kPointerSize) \ V(kLazyCompileDataOffset, kPointerSize) \
V(kUseTrapHandlerOffset, kPointerSize) \
V(kSize, 0) V(kSize, 0)
DEFINE_FIELD_OFFSET_CONSTANTS(HeapObject::kHeaderSize, DEFINE_FIELD_OFFSET_CONSTANTS(HeapObject::kHeaderSize,
...@@ -522,13 +521,6 @@ class WasmCompiledModule : public Struct { ...@@ -522,13 +521,6 @@ class WasmCompiledModule : public Struct {
#define WCM_CONST_OBJECT(TYPE, NAME) WCM_OBJECT_OR_WEAK(TYPE, NAME, private) #define WCM_CONST_OBJECT(TYPE, NAME) WCM_OBJECT_OR_WEAK(TYPE, NAME, private)
#define WCM_SMALL_CONST_NUMBER(TYPE, NAME) \
public: \
inline TYPE NAME() const; \
\
private: \
inline void set_##NAME(TYPE value);
#define WCM_WEAK_LINK(TYPE, NAME) \ #define WCM_WEAK_LINK(TYPE, NAME) \
WCM_OBJECT_OR_WEAK(WeakCell, weak_##NAME, public) \ WCM_OBJECT_OR_WEAK(WeakCell, weak_##NAME, public) \
\ \
...@@ -547,8 +539,6 @@ class WasmCompiledModule : public Struct { ...@@ -547,8 +539,6 @@ class WasmCompiledModule : public Struct {
WCM_WEAK_LINK(WasmInstanceObject, owning_instance) WCM_WEAK_LINK(WasmInstanceObject, owning_instance)
WCM_WEAK_LINK(WasmModuleObject, wasm_module) WCM_WEAK_LINK(WasmModuleObject, wasm_module)
WCM_OBJECT(Foreign, native_module) WCM_OBJECT(Foreign, native_module)
// TODO(mstarzinger): Make {use_trap_handler} smaller.
WCM_SMALL_CONST_NUMBER(bool, use_trap_handler)
public: public:
static Handle<WasmCompiledModule> New(Isolate* isolate, static Handle<WasmCompiledModule> New(Isolate* isolate,
...@@ -688,7 +678,6 @@ class WasmDebugInfo : public Struct { ...@@ -688,7 +678,6 @@ class WasmDebugInfo : public Struct {
#undef WCM_LARGE_NUMBER #undef WCM_LARGE_NUMBER
#undef WCM_OBJECT #undef WCM_OBJECT
#undef WCM_OBJECT_OR_WEAK #undef WCM_OBJECT_OR_WEAK
#undef WCM_SMALL_CONST_NUMBER
#undef WCM_WEAK_LINK #undef WCM_WEAK_LINK
#include "src/objects/object-macros-undef.h" #include "src/objects/object-macros-undef.h"
......
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