Commit 9716f689 authored by Clemens Hammacher's avatar Clemens Hammacher Committed by Commit Bot

[wasm] Do not store ModuleEnv

Instead, create it when needed and pass it down to the actual
compilation.
This saves memory by making the WasmCompilationUnit smaller and will
eventually allow us to implement the trap handler fallback correctly by
using an updated ModuleEnv in background compilation and tier up.

R=mstarzinger@chromium.org

Bug: v8:5277, v8:8343
Change-Id: I0dc3a37fb88e54eb4822dc99d58ff024f4b2a367
Reviewed-on: https://chromium-review.googlesource.com/c/1293953
Commit-Queue: Clemens Hammacher <clemensh@chromium.org>
Reviewed-by: 's avatarMichael Starzinger <mstarzinger@chromium.org>
Cr-Commit-Position: refs/heads/master@{#56896}
parent 6d28125e
......@@ -5144,8 +5144,8 @@ TurbofanWasmCompilationUnit::TurbofanWasmCompilationUnit(
TurbofanWasmCompilationUnit::~TurbofanWasmCompilationUnit() = default;
SourcePositionTable* TurbofanWasmCompilationUnit::BuildGraphForWasmFunction(
wasm::WasmFeatures* detected, double* decode_ms, MachineGraph* mcgraph,
NodeOriginTable* node_origins) {
wasm::ModuleEnv* env, wasm::WasmFeatures* detected, double* decode_ms,
MachineGraph* mcgraph, NodeOriginTable* node_origins) {
base::ElapsedTimer decode_timer;
if (FLAG_trace_wasm_decode_time) {
decode_timer.Start();
......@@ -5154,12 +5154,12 @@ SourcePositionTable* TurbofanWasmCompilationUnit::BuildGraphForWasmFunction(
// Create a TF graph during decoding.
SourcePositionTable* source_position_table =
new (mcgraph->zone()) SourcePositionTable(mcgraph->graph());
WasmGraphBuilder builder(wasm_unit_->env_, mcgraph->zone(), mcgraph,
WasmGraphBuilder builder(env, mcgraph->zone(), mcgraph,
wasm_unit_->func_body_.sig, source_position_table);
wasm::VoidResult graph_construction_result = wasm::BuildTFGraph(
wasm_unit_->wasm_engine_->allocator(),
wasm_unit_->native_module_->enabled_features(), wasm_unit_->env_->module,
&builder, detected, wasm_unit_->func_body_, node_origins);
wasm_unit_->native_module_->enabled_features(), env->module, &builder,
detected, wasm_unit_->func_body_, node_origins);
if (graph_construction_result.failed()) {
if (FLAG_trace_wasm_compiler) {
StdoutStream{} << "Compilation failed: "
......@@ -5172,7 +5172,7 @@ SourcePositionTable* TurbofanWasmCompilationUnit::BuildGraphForWasmFunction(
builder.LowerInt64();
if (builder.has_simd() &&
(!CpuFeatures::SupportsWasmSimd128() || wasm_unit_->env_->lower_simd)) {
(!CpuFeatures::SupportsWasmSimd128() || env->lower_simd)) {
SimdScalarLowering(
mcgraph,
CreateMachineSignature(mcgraph->zone(), wasm_unit_->func_body_.sig))
......@@ -5182,8 +5182,7 @@ SourcePositionTable* TurbofanWasmCompilationUnit::BuildGraphForWasmFunction(
if (wasm_unit_->func_index_ >= FLAG_trace_wasm_ast_start &&
wasm_unit_->func_index_ < FLAG_trace_wasm_ast_end) {
PrintRawWasmCode(wasm_unit_->wasm_engine_->allocator(),
wasm_unit_->func_body_, wasm_unit_->env_->module,
wasm::kPrintLocals);
wasm_unit_->func_body_, env->module, wasm::kPrintLocals);
}
if (FLAG_trace_wasm_decode_time) {
*decode_ms = decode_timer.Elapsed().InMillisecondsF();
......@@ -5207,7 +5206,7 @@ Vector<const char> GetDebugName(Zone* zone, int index) {
} // namespace
void TurbofanWasmCompilationUnit::ExecuteCompilation(
wasm::WasmFeatures* detected) {
wasm::ModuleEnv* env, wasm::WasmFeatures* detected) {
TRACE_EVENT0(TRACE_DISABLED_BY_DEFAULT("v8.wasm"),
"ExecuteTurbofanCompilation");
double decode_ms = 0;
......@@ -5223,7 +5222,7 @@ void TurbofanWasmCompilationUnit::ExecuteCompilation(
OptimizedCompilationInfo info(GetDebugName(&zone, wasm_unit_->func_index_),
&zone, Code::WASM_FUNCTION);
if (wasm_unit_->env_->runtime_exception_support) {
if (env->runtime_exception_support) {
info.SetWasmRuntimeExceptionSupport();
}
......@@ -5236,8 +5235,8 @@ void TurbofanWasmCompilationUnit::ExecuteCompilation(
? new (&zone)
NodeOriginTable(mcgraph->graph())
: nullptr;
SourcePositionTable* source_positions =
BuildGraphForWasmFunction(detected, &decode_ms, mcgraph, node_origins);
SourcePositionTable* source_positions = BuildGraphForWasmFunction(
env, detected, &decode_ms, mcgraph, node_origins);
if (wasm_unit_->failed()) return;
......@@ -5261,9 +5260,8 @@ void TurbofanWasmCompilationUnit::ExecuteCompilation(
std::unique_ptr<OptimizedCompilationJob> job(Pipeline::NewWasmCompilationJob(
&info, wasm_unit_->wasm_engine_, mcgraph, call_descriptor,
source_positions, node_origins, wasm_unit_->func_body_,
const_cast<wasm::WasmModule*>(wasm_unit_->env_->module),
wasm_unit_->native_module_, wasm_unit_->func_index_,
wasm_unit_->env_->module->origin));
const_cast<wasm::WasmModule*>(env->module), wasm_unit_->native_module_,
wasm_unit_->func_index_, env->module->origin));
if (job->ExecuteJob() == CompilationJob::SUCCEEDED) {
wasm_unit_->SetResult(info.wasm_code());
}
......
......@@ -50,12 +50,13 @@ class TurbofanWasmCompilationUnit {
explicit TurbofanWasmCompilationUnit(wasm::WasmCompilationUnit* wasm_unit);
~TurbofanWasmCompilationUnit();
SourcePositionTable* BuildGraphForWasmFunction(wasm::WasmFeatures* detected,
SourcePositionTable* BuildGraphForWasmFunction(wasm::ModuleEnv* env,
wasm::WasmFeatures* detected,
double* decode_ms,
MachineGraph* mcgraph,
NodeOriginTable* node_origins);
void ExecuteCompilation(wasm::WasmFeatures* detected);
void ExecuteCompilation(wasm::ModuleEnv* env, wasm::WasmFeatures* detected);
private:
wasm::WasmCompilationUnit* const wasm_unit_;
......
......@@ -1872,7 +1872,8 @@ class LiftoffCompiler {
} // namespace
bool LiftoffCompilationUnit::ExecuteCompilation(WasmFeatures* detected) {
bool LiftoffCompilationUnit::ExecuteCompilation(ModuleEnv* env,
WasmFeatures* detected) {
TRACE_EVENT0(TRACE_DISABLED_BY_DEFAULT("v8.wasm"),
"ExecuteLiftoffCompilation");
base::ElapsedTimer compile_timer;
......@@ -1881,15 +1882,14 @@ bool LiftoffCompilationUnit::ExecuteCompilation(WasmFeatures* detected) {
}
Zone zone(wasm_unit_->wasm_engine_->allocator(), "LiftoffCompilationZone");
const WasmModule* module =
wasm_unit_->env_ ? wasm_unit_->env_->module : nullptr;
const WasmModule* module = env ? env->module : nullptr;
auto call_descriptor =
compiler::GetWasmCallDescriptor(&zone, wasm_unit_->func_body_.sig);
base::Optional<TimedHistogramScope> liftoff_compile_time_scope(
base::in_place, wasm_unit_->counters_->liftoff_compile_time());
WasmFullDecoder<Decoder::kValidate, LiftoffCompiler> decoder(
&zone, module, wasm_unit_->native_module_->enabled_features(), detected,
wasm_unit_->func_body_, call_descriptor, wasm_unit_->env_, &zone);
wasm_unit_->func_body_, call_descriptor, env, &zone);
decoder.Decode();
liftoff_compile_time_scope.reset();
LiftoffCompiler* compiler = &decoder.interface();
......
......@@ -11,17 +11,16 @@ namespace v8 {
namespace internal {
namespace wasm {
struct WasmFeatures;
class ErrorThrower;
class WasmCode;
struct ModuleEnv;
class WasmCompilationUnit;
struct WasmFeatures;
class LiftoffCompilationUnit final {
public:
explicit LiftoffCompilationUnit(WasmCompilationUnit* wasm_unit)
: wasm_unit_(wasm_unit) {}
bool ExecuteCompilation(WasmFeatures* detected);
bool ExecuteCompilation(ModuleEnv*, WasmFeatures* detected);
private:
WasmCompilationUnit* const wasm_unit_;
......
......@@ -80,9 +80,7 @@ struct CompilationStateDeleter {
// Wrapper to create a CompilationState exists in order to avoid having
// the CompilationState in the header file.
std::unique_ptr<CompilationState, CompilationStateDeleter> NewCompilationState(
Isolate*, const ModuleEnv&);
ModuleEnv* GetModuleEnv(CompilationState* compilation_state);
Isolate*, NativeModule*);
} // namespace wasm
} // namespace internal
......
......@@ -36,23 +36,22 @@ ExecutionTier WasmCompilationUnit::GetDefaultExecutionTier() {
}
WasmCompilationUnit::WasmCompilationUnit(WasmEngine* wasm_engine,
ModuleEnv* env,
NativeModule* native_module,
FunctionBody body, int index,
Counters* counters, ExecutionTier mode)
: env_(env),
wasm_engine_(wasm_engine),
: wasm_engine_(wasm_engine),
func_body_(body),
counters_(counters),
func_index_(index),
native_module_(native_module),
mode_(mode) {
DCHECK_GE(index, env->module->num_imported_functions);
DCHECK_LT(index, env->module->functions.size());
const WasmModule* module = native_module->module();
DCHECK_GE(index, module->num_imported_functions);
DCHECK_LT(index, module->functions.size());
// Always disable Liftoff for asm.js, for two reasons:
// 1) asm-specific opcodes are not implemented, and
// 2) tier-up does not work with lazy compilation.
if (env->module->origin == kAsmJsOrigin) mode = ExecutionTier::kOptimized;
if (module->origin == kAsmJsOrigin) mode = ExecutionTier::kOptimized;
if (V8_UNLIKELY(FLAG_wasm_tier_mask_for_testing) && index < 32 &&
(FLAG_wasm_tier_mask_for_testing & (1 << index))) {
mode = ExecutionTier::kOptimized;
......@@ -64,12 +63,14 @@ WasmCompilationUnit::WasmCompilationUnit(WasmEngine* wasm_engine,
// {TurbofanWasmCompilationUnit} can be opaque in the header file.
WasmCompilationUnit::~WasmCompilationUnit() = default;
void WasmCompilationUnit::ExecuteCompilation(WasmFeatures* detected) {
auto size_histogram = SELECT_WASM_COUNTER(counters_, env_->module->origin,
wasm, function_size_bytes);
void WasmCompilationUnit::ExecuteCompilation(ModuleEnv* env,
WasmFeatures* detected) {
const WasmModule* module = native_module_->module();
auto size_histogram =
SELECT_WASM_COUNTER(counters_, module->origin, wasm, function_size_bytes);
size_histogram->AddSample(
static_cast<int>(func_body_.end - func_body_.start));
auto timed_histogram = SELECT_WASM_COUNTER(counters_, env_->module->origin,
auto timed_histogram = SELECT_WASM_COUNTER(counters_, module->origin,
wasm_compile, function_time);
TimedHistogramScope wasm_compile_function_time_scope(timed_histogram);
......@@ -80,12 +81,12 @@ void WasmCompilationUnit::ExecuteCompilation(WasmFeatures* detected) {
switch (mode_) {
case ExecutionTier::kBaseline:
if (liftoff_unit_->ExecuteCompilation(detected)) break;
if (liftoff_unit_->ExecuteCompilation(env, detected)) break;
// Otherwise, fall back to turbofan.
SwitchMode(ExecutionTier::kOptimized);
V8_FALLTHROUGH;
case ExecutionTier::kOptimized:
turbofan_unit_->ExecuteCompilation(detected);
turbofan_unit_->ExecuteCompilation(env, detected);
break;
case ExecutionTier::kInterpreter:
UNREACHABLE(); // TODO(titzer): compile interpreter entry stub.
......@@ -136,17 +137,16 @@ void WasmCompilationUnit::SwitchMode(ExecutionTier new_mode) {
// static
WasmCode* WasmCompilationUnit::CompileWasmFunction(
Isolate* isolate, NativeModule* native_module, WasmFeatures* detected,
ErrorThrower* thrower, ModuleEnv* env, const WasmFunction* function,
ExecutionTier mode) {
ErrorThrower* thrower, const WasmFunction* function, ExecutionTier mode) {
ModuleWireBytes wire_bytes(native_module->wire_bytes());
FunctionBody function_body{function->sig, function->code.offset(),
wire_bytes.start() + function->code.offset(),
wire_bytes.start() + function->code.end_offset()};
WasmCompilationUnit unit(isolate->wasm_engine(), env, native_module,
function_body,
WasmCompilationUnit unit(isolate->wasm_engine(), native_module, function_body,
function->func_index, isolate->counters(), mode);
unit.ExecuteCompilation(detected);
ModuleEnv env = native_module->CreateModuleEnv();
unit.ExecuteCompilation(&env, detected);
if (unit.failed()) {
unit.ReportError(thrower);
return nullptr;
......
......@@ -37,13 +37,12 @@ class WasmCompilationUnit final {
// typically means to hold a std::shared_ptr<Counters>).
// If used exclusively from a foreground thread, Isolate::counters() may be
// used by callers to pass Counters.
WasmCompilationUnit(WasmEngine* wasm_engine, ModuleEnv*, NativeModule*,
FunctionBody, int index, Counters*,
ExecutionTier = GetDefaultExecutionTier());
WasmCompilationUnit(WasmEngine*, NativeModule*, FunctionBody, int index,
Counters*, ExecutionTier = GetDefaultExecutionTier());
~WasmCompilationUnit();
void ExecuteCompilation(WasmFeatures* detected);
void ExecuteCompilation(ModuleEnv*, WasmFeatures* detected);
NativeModule* native_module() const { return native_module_; }
ExecutionTier mode() const { return mode_; }
......@@ -58,14 +57,13 @@ class WasmCompilationUnit final {
static WasmCode* CompileWasmFunction(
Isolate* isolate, NativeModule* native_module, WasmFeatures* detected,
ErrorThrower* thrower, ModuleEnv* env, const WasmFunction* function,
ErrorThrower* thrower, const WasmFunction* function,
ExecutionTier = GetDefaultExecutionTier());
private:
friend class LiftoffCompilationUnit;
friend class compiler::TurbofanWasmCompilationUnit;
ModuleEnv* env_;
WasmEngine* wasm_engine_;
FunctionBody func_body_;
Counters* counters_;
......
This diff is collapsed.
......@@ -150,9 +150,8 @@ void WasmCode::LogCode(Isolate* isolate) const {
ModuleWireBytes wire_bytes(native_module()->wire_bytes());
// TODO(herhut): Allow to log code without on-heap round-trip of the name.
ModuleEnv* module_env = GetModuleEnv(native_module()->compilation_state());
WireBytesRef name_ref =
module_env->module->LookupFunctionName(wire_bytes, index());
native_module()->module()->LookupFunctionName(wire_bytes, index());
WasmName name_vec = wire_bytes.GetNameOrNull(name_ref);
if (!name_vec.is_empty()) {
MaybeHandle<String> maybe_name = isolate->factory()->NewStringFromUtf8(
......@@ -339,18 +338,17 @@ WasmCode::~WasmCode() {
NativeModule::NativeModule(Isolate* isolate, const WasmFeatures& enabled,
bool can_request_more, VirtualMemory code_space,
WasmCodeManager* code_manager,
std::shared_ptr<const WasmModule> module,
const ModuleEnv& env)
std::shared_ptr<const WasmModule> module)
: enabled_features_(enabled),
module_(std::move(module)),
compilation_state_(NewCompilationState(isolate, env)),
compilation_state_(NewCompilationState(isolate, this)),
import_wrapper_cache_(std::unique_ptr<WasmImportWrapperCache>(
new WasmImportWrapperCache(this))),
free_code_space_(code_space.region()),
wasm_code_manager_(code_manager),
can_request_more_memory_(can_request_more),
use_trap_handler_(env.use_trap_handler) {
DCHECK_EQ(module_.get(), env.module);
use_trap_handler_(trap_handler::IsTrapHandlerEnabled() ? kUseTrapHandler
: kNoTrapHandler) {
DCHECK_NOT_NULL(module_);
owned_code_space_.emplace_back(std::move(code_space));
owned_code_.reserve(num_functions());
......@@ -386,6 +384,10 @@ void NativeModule::LogWasmCodes(Isolate* isolate) {
}
}
ModuleEnv NativeModule::CreateModuleEnv() const {
return {module(), use_trap_handler_, kRuntimeExceptionSupport};
}
WasmCode* NativeModule::AddOwnedCode(
uint32_t index, Vector<const byte> instructions, uint32_t stack_slots,
size_t safepoint_table_offset, size_t handler_table_offset,
......@@ -932,8 +934,7 @@ bool WasmCodeManager::ShouldForceCriticalMemoryPressureNotification() {
std::unique_ptr<NativeModule> WasmCodeManager::NewNativeModule(
Isolate* isolate, const WasmFeatures& enabled, size_t memory_estimate,
bool can_request_more, std::shared_ptr<const WasmModule> module,
const ModuleEnv& env) {
bool can_request_more, std::shared_ptr<const WasmModule> module) {
if (ShouldForceCriticalMemoryPressureNotification()) {
(reinterpret_cast<v8::Isolate*>(isolate))
->MemoryPressureNotification(MemoryPressureLevel::kCritical);
......@@ -963,7 +964,7 @@ std::unique_ptr<NativeModule> WasmCodeManager::NewNativeModule(
Address end = mem.end();
std::unique_ptr<NativeModule> ret(
new NativeModule(isolate, enabled, can_request_more, std::move(mem), this,
std::move(module), env));
std::move(module)));
TRACE_HEAP("New NativeModule %p: Mem: %" PRIuPTR ",+%zu\n", this, start,
size);
AssignRangesAndAddModule(start, end, ret.get());
......
......@@ -314,6 +314,10 @@ class V8_EXPORT_PRIVATE NativeModule final {
CompilationState* compilation_state() { return compilation_state_.get(); }
// Create a {ModuleEnv} object for compilation. Only valid as long as this
// {NativeModule} is alive.
ModuleEnv CreateModuleEnv() const;
uint32_t num_functions() const {
return module_->num_declared_functions + module_->num_imported_functions;
}
......@@ -349,7 +353,7 @@ class V8_EXPORT_PRIVATE NativeModule final {
NativeModule(Isolate* isolate, const WasmFeatures& enabled_features,
bool can_request_more, VirtualMemory code_space,
WasmCodeManager* code_manager,
std::shared_ptr<const WasmModule> module, const ModuleEnv& env);
std::shared_ptr<const WasmModule> module);
WasmCode* AddAnonymousCode(Handle<Code>, WasmCode::Kind kind,
const char* name = nullptr);
......@@ -473,7 +477,7 @@ class V8_EXPORT_PRIVATE WasmCodeManager final {
std::unique_ptr<NativeModule> NewNativeModule(
Isolate* isolate, const WasmFeatures& enabled_features,
size_t memory_estimate, bool can_request_more,
std::shared_ptr<const WasmModule> module, const ModuleEnv& env);
std::shared_ptr<const WasmModule> module);
NativeModule* LookupNativeModule(Address pc) const;
WasmCode* LookupCode(Address pc) const;
......
......@@ -178,7 +178,6 @@ bool WasmEngine::CompileFunction(Isolate* isolate, NativeModule* native_module,
WasmFeatures detected = kNoWasmFeatures;
WasmCode* ret = WasmCompilationUnit::CompileWasmFunction(
isolate, native_module, &detected, &thrower,
GetModuleEnv(native_module->compilation_state()),
&native_module->module()->functions[function_index], tier);
return ret != nullptr;
}
......
......@@ -175,19 +175,16 @@ enum DispatchTableElements : int {
// static
Handle<WasmModuleObject> WasmModuleObject::New(
Isolate* isolate, const wasm::WasmFeatures& enabled,
std::shared_ptr<const wasm::WasmModule> shared_module, wasm::ModuleEnv& env,
std::shared_ptr<const wasm::WasmModule> shared_module,
OwnedVector<const uint8_t> wire_bytes, Handle<Script> script,
Handle<ByteArray> asm_js_offset_table) {
DCHECK_EQ(shared_module.get(), env.module);
// Create a new {NativeModule} first.
size_t native_memory_estimate =
isolate->wasm_engine()->code_manager()->EstimateNativeModuleSize(
env.module);
shared_module.get());
auto native_module = isolate->wasm_engine()->code_manager()->NewNativeModule(
isolate, enabled, native_memory_estimate,
wasm::NativeModule::kCanAllocateMoreMemory, std::move(shared_module),
env);
wasm::NativeModule::kCanAllocateMoreMemory, std::move(shared_module));
native_module->set_wire_bytes(std::move(wire_bytes));
native_module->SetRuntimeStubs(isolate);
......
......@@ -137,7 +137,7 @@ class WasmModuleObject : public JSObject {
// Creates a new {WasmModuleObject} with a new {NativeModule} underneath.
static Handle<WasmModuleObject> New(
Isolate* isolate, const wasm::WasmFeatures& enabled,
std::shared_ptr<const wasm::WasmModule> module, wasm::ModuleEnv& env,
std::shared_ptr<const wasm::WasmModule> module,
OwnedVector<const uint8_t> wire_bytes, Handle<Script> script,
Handle<ByteArray> asm_js_offset_table);
......
......@@ -268,6 +268,9 @@ size_t NativeModuleSerializer::Measure() const {
}
void NativeModuleSerializer::WriteHeader(Writer* writer) {
// TODO(eholk): We need to properly preserve the flag whether the trap
// handler was used or not when serializing.
writer->Write(native_module_->num_functions());
writer->Write(native_module_->num_imported_functions());
}
......@@ -555,17 +558,10 @@ MaybeHandle<WasmModuleObject> DeserializeNativeModule(
Handle<Script> script =
CreateWasmScript(isolate, wire_bytes, module->source_map_url);
// TODO(eholk): We need to properly preserve the flag whether the trap
// handler was used or not when serializing.
UseTrapHandler use_trap_handler =
trap_handler::IsTrapHandlerEnabled() ? kUseTrapHandler : kNoTrapHandler;
ModuleEnv env(module, use_trap_handler,
RuntimeExceptionSupport::kRuntimeExceptionSupport);
OwnedVector<uint8_t> wire_bytes_copy = OwnedVector<uint8_t>::Of(wire_bytes);
Handle<WasmModuleObject> module_object = WasmModuleObject::New(
isolate, enabled_features, std::move(decode_result).value(), env,
isolate, enabled_features, std::move(decode_result).value(),
std::move(wire_bytes_copy), script, Handle<ByteArray>::null());
NativeModule* native_module = module_object->native_module();
......
......@@ -123,15 +123,11 @@ std::unique_ptr<wasm::NativeModule> AllocateNativeModule(Isolate* isolate,
size_t code_size) {
std::shared_ptr<wasm::WasmModule> module(new wasm::WasmModule());
module->num_declared_functions = 1;
wasm::ModuleEnv env(
module.get(), wasm::UseTrapHandler::kNoTrapHandler,
wasm::RuntimeExceptionSupport::kNoRuntimeExceptionSupport);
// We have to add the code object to a NativeModule, because the
// WasmCallDescriptor assumes that code is on the native heap and not
// within a code object.
return isolate->wasm_engine()->code_manager()->NewNativeModule(
isolate, wasm::kAllWasmFeatures, code_size, false, std::move(module),
env);
isolate, wasm::kAllWasmFeatures, code_size, false, std::move(module));
}
void TestReturnMultipleValues(MachineType type) {
......
......@@ -22,11 +22,8 @@ std::unique_ptr<NativeModule> NewModule(Isolate* isolate) {
std::shared_ptr<WasmModule> module(new WasmModule);
bool can_request_more = false;
size_t size = 100;
ModuleEnv env(module.get(), UseTrapHandler::kNoTrapHandler,
RuntimeExceptionSupport::kNoRuntimeExceptionSupport);
auto native_module =
manager->NewNativeModule(isolate, kAllWasmFeatures, size,
can_request_more, std::move(module), env);
auto native_module = manager->NewNativeModule(
isolate, kAllWasmFeatures, size, can_request_more, std::move(module));
native_module->SetRuntimeStubs(isolate);
return native_module;
}
......
......@@ -354,7 +354,6 @@ TEST(SharedEngineRunThreadedTierUp) {
WasmFeatures detected = kNoWasmFeatures;
WasmCompilationUnit::CompileWasmFunction(
isolate.isolate(), module.get(), &detected, &thrower,
GetModuleEnv(module->compilation_state()),
&module->module()->functions[0], ExecutionTier::kOptimized);
CHECK_EQ(23, isolate.Run(instance));
});
......
......@@ -209,9 +209,8 @@ Handle<WasmInstanceObject> TestingModuleBuilder::InitInstanceObject() {
Handle<Script> script =
isolate_->factory()->NewScript(isolate_->factory()->empty_string());
script->set_type(Script::TYPE_WASM);
ModuleEnv env = CreateModuleEnv();
Handle<WasmModuleObject> module_object =
WasmModuleObject::New(isolate_, enabled_features_, test_module_, env, {},
WasmModuleObject::New(isolate_, enabled_features_, test_module_, {},
script, Handle<ByteArray>::null());
// This method is called when we initialize TestEnvironment. We don't
// have a memory yet, so we won't create it here. We'll update the
......@@ -411,7 +410,7 @@ void WasmFunctionCompiler::Build(const byte* start, const byte* end) {
->native_module()
->wire_bytes();
ModuleEnv module_env = builder_->CreateModuleEnv();
ModuleEnv env = builder_->CreateModuleEnv();
ScopedVector<uint8_t> func_wire_bytes(function_->code.length());
memcpy(func_wire_bytes.start(), wire_bytes.start() + function_->code.offset(),
func_wire_bytes.length());
......@@ -420,11 +419,10 @@ void WasmFunctionCompiler::Build(const byte* start, const byte* end) {
func_wire_bytes.start(), func_wire_bytes.end()};
NativeModule* native_module =
builder_->instance_object()->module_object()->native_module();
WasmCompilationUnit unit(isolate()->wasm_engine(), &module_env, native_module,
func_body, function_->func_index,
isolate()->counters(), tier);
WasmCompilationUnit unit(isolate()->wasm_engine(), native_module, func_body,
function_->func_index, isolate()->counters(), tier);
WasmFeatures unused_detected_features;
unit.ExecuteCompilation(&unused_detected_features);
unit.ExecuteCompilation(&env, &unused_detected_features);
CHECK(!unit.failed());
if (WasmCode::ShouldBeLogged(isolate())) unit.result()->LogCode(isolate());
}
......
......@@ -138,16 +138,12 @@ std::unique_ptr<wasm::NativeModule> AllocateNativeModule(i::Isolate* isolate,
size_t code_size) {
std::shared_ptr<wasm::WasmModule> module(new wasm::WasmModule);
module->num_declared_functions = 1;
wasm::ModuleEnv env(
module.get(), wasm::UseTrapHandler::kNoTrapHandler,
wasm::RuntimeExceptionSupport::kNoRuntimeExceptionSupport);
// We have to add the code object to a NativeModule, because the
// WasmCallDescriptor assumes that code is on the native heap and not
// within a code object.
return isolate->wasm_engine()->code_manager()->NewNativeModule(
isolate, i::wasm::kAllWasmFeatures, code_size, false, std::move(module),
env);
isolate, i::wasm::kAllWasmFeatures, code_size, false, std::move(module));
}
extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) {
......
......@@ -165,10 +165,8 @@ class WasmCodeManagerTest : public TestWithContext,
std::shared_ptr<WasmModule> module(new WasmModule);
module->num_declared_functions = kNumFunctions;
bool can_request_more = style == Growable;
ModuleEnv env(module.get(), UseTrapHandler::kNoTrapHandler,
RuntimeExceptionSupport::kNoRuntimeExceptionSupport);
return manager->NewNativeModule(i_isolate(), kAllWasmFeatures, size,
can_request_more, std::move(module), env);
can_request_more, std::move(module));
}
WasmCode* AddCode(NativeModule* native_module, uint32_t index, size_t size) {
......
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