[wasm] Inline helpers of WasmModule::origin

R=mstarzinger@chromium.org

Change-Id: I0976bfa57b9ec48fae2b912e78bacfee4f8eeafb
Reviewed-on: https://chromium-review.googlesource.com/1072654
Commit-Queue: Ben Titzer <titzer@chromium.org>
Reviewed-by: Michael Starzinger <mstarzinger@chromium.org>
Cr-Commit-Position: refs/heads/master@{#53368}
This commit is contained in:
Ben L. Titzer 2018-05-25 18:07:28 +02:00 committed by Commit Bot
parent d3c02d30e4
commit ae6e9cc7f4
12 changed files with 95 additions and 98 deletions

View File

@ -2945,7 +2945,7 @@ Node* WasmGraphBuilder::MemBuffer(uint32_t offset) {
Node* WasmGraphBuilder::CurrentMemoryPages() {
// CurrentMemoryPages can not be called from asm.js.
DCHECK_EQ(wasm::kWasmOrigin, env_->module->origin());
DCHECK_EQ(wasm::kWasmOrigin, env_->module->origin);
DCHECK_NOT_NULL(instance_cache_);
Node* mem_size = instance_cache_->mem_size;
DCHECK_NOT_NULL(mem_size);
@ -5112,7 +5112,7 @@ void TurbofanWasmCompilationUnit::ExecuteCompilation() {
source_positions, node_origins, &wasm_compilation_data_,
wasm_unit_->func_body_,
const_cast<wasm::WasmModule*>(wasm_unit_->env_->module),
wasm_unit_->env_->module->origin()));
wasm_unit_->env_->module->origin));
ok_ = job_->ExecuteJob() == CompilationJob::SUCCEEDED;
// TODO(bradnelson): Improve histogram handling of size_t.
wasm_unit_->counters_->wasm_compile_function_peak_memory_bytes()->AddSample(

View File

@ -38,13 +38,13 @@ struct WasmException;
}())
#define RET_ON_PROTOTYPE_OPCODE(flag) \
DCHECK(!this->module_ || !this->module_->is_asm_js()); \
DCHECK(!this->module_ || this->module_->origin == kWasmOrigin); \
if (!FLAG_experimental_wasm_##flag) { \
this->error("Invalid opcode (enable with --experimental-wasm-" #flag ")"); \
}
#define CHECK_PROTOTYPE_OPCODE(flag) \
DCHECK(!this->module_ || !this->module_->is_asm_js()); \
DCHECK(!this->module_ || this->module_->origin == kWasmOrigin); \
if (!FLAG_experimental_wasm_##flag) { \
this->error("Invalid opcode (enable with --experimental-wasm-" #flag ")"); \
break; \
@ -1830,7 +1830,7 @@ class WasmFullDecoder : public WasmDecoder<validate> {
MemoryIndexImmediate<validate> imm(this, this->pc_);
len = 1 + imm.length;
DCHECK_NOT_NULL(this->module_);
if (!VALIDATE(this->module_->is_wasm())) {
if (!VALIDATE(this->module_->origin == kWasmOrigin)) {
this->error("grow_memory is not supported for asmjs modules");
break;
}
@ -1910,7 +1910,8 @@ class WasmFullDecoder : public WasmDecoder<validate> {
}
default: {
// Deal with special asmjs opcodes.
if (this->module_ != nullptr && this->module_->is_asm_js()) {
if (this->module_ != nullptr &&
this->module_->origin == kAsmJsOrigin) {
sig = WasmOpcodes::AsmjsSignature(opcode);
if (sig) {
BuildSimpleOperator(opcode, sig);

View File

@ -846,11 +846,12 @@ DecodeResult VerifyWasmCode(AccountingAllocator* allocator,
DecodeResult VerifyWasmCodeWithStats(AccountingAllocator* allocator,
const wasm::WasmModule* module,
FunctionBody& body, bool is_wasm,
FunctionBody& body, ModuleOrigin origin,
Counters* counters) {
CHECK_LE(0, body.end - body.start);
auto time_counter = is_wasm ? counters->wasm_decode_wasm_function_time()
: counters->wasm_decode_asm_function_time();
auto time_counter = origin == kWasmOrigin
? counters->wasm_decode_wasm_function_time()
: counters->wasm_decode_asm_function_time();
TimedHistogramScope wasm_decode_function_time_scope(time_counter);
return VerifyWasmCode(allocator, module, body);
}

View File

@ -27,6 +27,7 @@ namespace wasm {
typedef compiler::WasmGraphBuilder TFBuilder;
struct WasmModule; // forward declaration of module interface.
enum ModuleOrigin : uint8_t;
// A wrapper around the signature and bytes of a function.
struct FunctionBody {
@ -48,7 +49,7 @@ V8_EXPORT_PRIVATE DecodeResult VerifyWasmCode(AccountingAllocator* allocator,
// isolate::async_counters() to guarantee usability of counters argument.
DecodeResult VerifyWasmCodeWithStats(AccountingAllocator* allocator,
const wasm::WasmModule* module,
FunctionBody& body, bool is_wasm,
FunctionBody& body, ModuleOrigin origin,
Counters* counters);
DecodeResult BuildTFGraph(AccountingAllocator* allocator, TFBuilder* builder,

View File

@ -55,7 +55,7 @@ WasmCompilationUnit::WasmCompilationUnit(Isolate* isolate, ModuleEnv* env,
// 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->is_asm_js()) mode = CompilationMode::kTurbofan;
if (env->module->origin == kAsmJsOrigin) mode = CompilationMode::kTurbofan;
SwitchMode(mode);
}
@ -64,14 +64,12 @@ WasmCompilationUnit::WasmCompilationUnit(Isolate* isolate, ModuleEnv* env,
WasmCompilationUnit::~WasmCompilationUnit() {}
void WasmCompilationUnit::ExecuteCompilation() {
auto size_histogram = env_->module->is_wasm()
? counters_->wasm_wasm_function_size_bytes()
: counters_->wasm_asm_function_size_bytes();
auto size_histogram = SELECT_WASM_COUNTER(counters_, env_->module->origin,
wasm, function_size_bytes);
size_histogram->AddSample(
static_cast<int>(func_body_.end - func_body_.start));
auto timed_histogram = env_->module->is_wasm()
? counters_->wasm_compile_wasm_function_time()
: counters_->wasm_compile_asm_function_time();
auto timed_histogram = SELECT_WASM_COUNTER(counters_, env_->module->origin,
wasm_compile, function_time);
TimedHistogramScope wasm_compile_function_time_scope(timed_histogram);
if (FLAG_trace_wasm_compiler) {

View File

@ -866,7 +866,7 @@ Address CompileLazy(Isolate* isolate,
namespace {
bool compile_lazy(const WasmModule* module) {
return FLAG_wasm_lazy_compilation ||
(FLAG_asm_wasm_lazy_compilation && module->is_asm_js());
(FLAG_asm_wasm_lazy_compilation && module->origin == kAsmJsOrigin);
}
void FlushICache(const wasm::NativeModule* native_module) {
@ -1278,7 +1278,7 @@ void ValidateSequentially(Isolate* isolate, const ModuleWireBytes& wire_bytes,
FunctionBody body{func.sig, func.code.offset(), base + func.code.offset(),
base + func.code.end_offset()};
DecodeResult result = VerifyWasmCodeWithStats(
isolate->allocator(), module, body, module->is_wasm(),
isolate->allocator(), module, body, module->origin,
isolate->async_counters().get());
if (result.failed()) {
TruncatedUserString<> name(wire_bytes.GetName(&func, module));
@ -1297,9 +1297,8 @@ MaybeHandle<WasmModuleObject> CompileToModuleObjectInternal(
WasmModule* wasm_module = module.get();
Handle<Code> centry_stub = CodeFactory::CEntry(isolate);
TimedHistogramScope wasm_compile_module_time_scope(
wasm_module->is_wasm()
? isolate->async_counters()->wasm_compile_wasm_module_time()
: isolate->async_counters()->wasm_compile_asm_module_time());
SELECT_WASM_COUNTER(isolate->async_counters(), wasm_module->origin,
wasm_compile, module_time));
// TODO(6792): No longer needed once WebAssembly code is off heap. Use
// base::Optional to be able to close the scope before notifying the debugger.
base::Optional<CodeSpaceMemoryModificationScope> modification_scope(
@ -1366,7 +1365,7 @@ MaybeHandle<WasmModuleObject> CompileToModuleObjectInternal(
Handle<WasmModuleObject> module_object =
WasmModuleObject::New(isolate, compiled_module, export_wrappers, shared);
if (lazy_compile) {
if (wasm_module->is_wasm()) {
if (wasm_module->origin == kWasmOrigin) {
// Validate wasm modules for lazy compilation. Don't validate asm.js
// modules, they are valid by construction (otherwise a CHECK will fail
// during lazy compilation).
@ -1568,9 +1567,8 @@ MaybeHandle<WasmInstanceObject> InstanceBuilder::Build() {
// From here on, we expect the build pipeline to run without exiting to JS.
DisallowJavascriptExecution no_js(isolate_);
// Record build time into correct bucket, then build instance.
TimedHistogramScope wasm_instantiate_module_time_scope(
module_->is_wasm() ? counters()->wasm_instantiate_wasm_module_time()
: counters()->wasm_instantiate_asm_module_time());
TimedHistogramScope wasm_instantiate_module_time_scope(SELECT_WASM_COUNTER(
counters(), module_->origin, wasm_instantiate, module_time));
Factory* factory = isolate_->factory();
//--------------------------------------------------------------------------
@ -1617,10 +1615,10 @@ MaybeHandle<WasmInstanceObject> InstanceBuilder::Build() {
// Set up the globals for the new instance.
//--------------------------------------------------------------------------
MaybeHandle<JSArrayBuffer> old_globals;
uint32_t globals_size = module_->globals_size;
if (globals_size > 0) {
uint32_t globals_buffer_size = module_->globals_buffer_size;
if (globals_buffer_size > 0) {
void* backing_store =
isolate_->array_buffer_allocator()->Allocate(globals_size);
isolate_->array_buffer_allocator()->Allocate(globals_buffer_size);
if (backing_store == nullptr) {
thrower_->RangeError("Out of memory: wasm globals");
return {};
@ -1630,7 +1628,8 @@ MaybeHandle<WasmInstanceObject> InstanceBuilder::Build() {
constexpr bool is_external = false;
constexpr bool is_wasm_memory = false;
JSArrayBuffer::Setup(globals_, isolate_, is_external, backing_store,
globals_size, SharedFlag::kNotShared, is_wasm_memory);
globals_buffer_size, SharedFlag::kNotShared,
is_wasm_memory);
if (globals_.is_null()) {
thrower_->RangeError("Out of memory: wasm globals");
return {};
@ -1684,9 +1683,9 @@ MaybeHandle<WasmInstanceObject> InstanceBuilder::Build() {
// Allocate the memory array buffer.
//--------------------------------------------------------------------------
uint32_t initial_pages = module_->initial_pages;
(module_->is_wasm() ? counters()->wasm_wasm_min_mem_pages_count()
: counters()->wasm_asm_min_mem_pages_count())
->AddSample(initial_pages);
auto initial_pages_counter = SELECT_WASM_COUNTER(counters(), module_->origin,
wasm, min_mem_pages_count);
initial_pages_counter->AddSample(initial_pages);
if (!memory_.is_null()) {
// Set externally passed ArrayBuffer non neuterable.
@ -1694,7 +1693,8 @@ MaybeHandle<WasmInstanceObject> InstanceBuilder::Build() {
memory->set_is_neuterable(false);
DCHECK_IMPLIES(use_trap_handler(),
module_->is_asm_js() || memory->is_wasm_memory() ||
module_->origin == kAsmJsOrigin ||
memory->is_wasm_memory() ||
memory->backing_store() == nullptr ||
// TODO(836800) Remove once is_wasm_memory transfers over
// post-message.
@ -1816,7 +1816,7 @@ MaybeHandle<WasmInstanceObject> InstanceBuilder::Build() {
WasmSharedModuleData::SetBreakpointsOnNewInstance(
handle(module_object_->shared(), isolate_), instance);
if (FLAG_wasm_interpret_all && module_->is_wasm()) {
if (FLAG_wasm_interpret_all && module_->origin == kWasmOrigin) {
Handle<WasmDebugInfo> debug_info =
WasmInstanceObject::GetOrCreateDebugInfo(instance);
std::vector<int> func_indexes;
@ -2061,7 +2061,7 @@ void InstanceBuilder::SanitizeImports() {
int int_index = static_cast<int>(index);
MaybeHandle<Object> result =
module_->is_asm_js()
module_->origin == kAsmJsOrigin
? LookupImportAsm(int_index, import_name)
: LookupImport(int_index, module_name, import_name);
if (thrower_->error()) {
@ -2127,8 +2127,8 @@ int InstanceBuilder::ProcessImports(Handle<WasmInstanceObject> instance) {
// The imported function is a callable.
Handle<JSReceiver> js_receiver(JSReceiver::cast(*value), isolate_);
Handle<Code> wrapper_code = compiler::CompileWasmToJSWrapper(
isolate_, js_receiver, expected_sig, func_index,
module_->origin(), use_trap_handler());
isolate_, js_receiver, expected_sig, func_index, module_->origin,
use_trap_handler());
RecordStats(*wrapper_code, counters());
WasmCode* wasm_code = native_module->AddCodeCopy(
@ -2280,7 +2280,7 @@ int InstanceBuilder::ProcessImports(Handle<WasmInstanceObject> instance) {
module_name, import_name);
return -1;
}
if (module_->is_asm_js()) {
if (module_->origin == kAsmJsOrigin) {
// Accepting {JSFunction} on top of just primitive values here is a
// workaround to support legacy asm.js code with broken binding. Note
// that using {NaN} (or Smi::kZero) here is what using the observable
@ -2466,15 +2466,22 @@ void InstanceBuilder::ProcessExports(Handle<WasmInstanceObject> instance) {
}
Handle<JSObject> exports_object;
if (module_->is_wasm()) {
// Create the "exports" object.
exports_object = isolate_->factory()->NewJSObjectWithNullProto();
} else if (module_->is_asm_js()) {
Handle<JSFunction> object_function = Handle<JSFunction>(
isolate_->native_context()->object_function(), isolate_);
exports_object = isolate_->factory()->NewJSObject(object_function);
} else {
UNREACHABLE();
bool is_asm_js = false;
switch (module_->origin) {
case kWasmOrigin: {
// Create the "exports" object.
exports_object = isolate_->factory()->NewJSObjectWithNullProto();
break;
}
case kAsmJsOrigin: {
Handle<JSFunction> object_function = Handle<JSFunction>(
isolate_->native_context()->object_function(), isolate_);
exports_object = isolate_->factory()->NewJSObject(object_function);
is_asm_js = true;
break;
}
default:
UNREACHABLE();
}
instance->set_exports_object(*exports_object);
@ -2482,9 +2489,9 @@ void InstanceBuilder::ProcessExports(Handle<WasmInstanceObject> instance) {
isolate_->factory()->InternalizeUtf8String(AsmJs::kSingleFunctionName);
PropertyDescriptor desc;
desc.set_writable(module_->is_asm_js());
desc.set_writable(is_asm_js);
desc.set_enumerable(true);
desc.set_configurable(module_->is_asm_js());
desc.set_configurable(is_asm_js);
// Process each export in the export table.
int export_index = 0; // Index into {export_wrappers}.
@ -2494,7 +2501,7 @@ void InstanceBuilder::ProcessExports(Handle<WasmInstanceObject> instance) {
isolate_, handle(module_object_->shared(), isolate_), exp.name)
.ToHandleChecked();
Handle<JSObject> export_to;
if (module_->is_asm_js() && exp.kind == kExternalFunction &&
if (is_asm_js && exp.kind == kExternalFunction &&
String::Equals(name, single_function_name)) {
export_to = instance;
} else {
@ -2511,7 +2518,7 @@ void InstanceBuilder::ProcessExports(Handle<WasmInstanceObject> instance) {
Handle<Code> export_code =
export_wrappers->GetValueChecked<Code>(isolate_, export_index);
MaybeHandle<String> func_name;
if (module_->is_asm_js()) {
if (is_asm_js) {
// For modules arising from asm.js, honor the names section.
WireBytesRef func_name_ref = module_->LookupName(
module_object_->shared()->module_bytes(), function.func_index);
@ -2605,7 +2612,7 @@ void InstanceBuilder::ProcessExports(Handle<WasmInstanceObject> instance) {
}
DCHECK_EQ(export_index, export_wrappers->length());
if (module_->is_wasm()) {
if (module_->origin == kWasmOrigin) {
v8::Maybe<bool> success =
JSReceiver::SetIntegrityLevel(exports_object, FROZEN, kDontThrow);
DCHECK(success.FromMaybe(false));
@ -2674,7 +2681,7 @@ void InstanceBuilder::LoadTableSegments(Handle<WasmInstanceObject> instance) {
isolate_, module_, is_import ? kNullAddress : call_target,
func_index, use_trap_handler());
MaybeHandle<String> func_name;
if (module_->is_asm_js()) {
if (module_->origin == kAsmJsOrigin) {
// For modules arising from asm.js, honor the names section.
WireBytesRef func_name_ref = module_->LookupName(
module_object_->shared()->module_bytes(), func_index);
@ -3400,7 +3407,8 @@ CompilationState::CompilationState(internal::Isolate* isolate, ModuleEnv& env)
module_env_(env),
max_memory_(GetMaxUsableMemorySize(isolate) / 2),
// TODO(clemensh): Fix fuzzers such that {env.module} is always non-null.
compile_mode_(FLAG_wasm_tier_up && (!env.module || env.module->is_wasm())
compile_mode_(FLAG_wasm_tier_up &&
(!env.module || env.module->origin == kWasmOrigin)
? CompileMode::kTiering
: CompileMode::kRegular),
wire_bytes_(ModuleWireBytes(nullptr, nullptr)),

View File

@ -296,7 +296,7 @@ class ModuleDecoderImpl : public Decoder {
module_->initial_pages = 0;
module_->maximum_pages = 0;
module_->mem_export = false;
module_->set_origin(origin_);
module_->origin = origin_;
}
void DecodeModuleHeader(Vector<const uint8_t> bytes, uint8_t offset) {
@ -518,9 +518,9 @@ class ModuleDecoderImpl : public Decoder {
void DecodeFunctionSection() {
uint32_t functions_count =
consume_count("functions count", kV8MaxWasmFunctions);
(IsWasm() ? GetCounters()->wasm_functions_per_wasm_module()
: GetCounters()->wasm_functions_per_asm_module())
->AddSample(static_cast<int>(functions_count));
auto counter =
SELECT_WASM_COUNTER(GetCounters(), origin_, wasm_functions_per, module);
counter->AddSample(static_cast<int>(functions_count));
module_->functions.reserve(functions_count);
module_->num_declared_functions = functions_count;
for (uint32_t i = 0; ok() && i < functions_count; ++i) {
@ -891,8 +891,6 @@ class ModuleDecoderImpl : public Decoder {
WasmModule* module() { return module_.get(); }
bool IsWasm() { return origin_ == kWasmOrigin; }
Counters* GetCounters() {
DCHECK_NOT_NULL(counters_);
return counters_;
@ -987,7 +985,7 @@ class ModuleDecoderImpl : public Decoder {
void CalculateGlobalOffsets(WasmModule* module) {
uint32_t offset = 0;
if (module->globals.size() == 0) {
module->globals_size = 0;
module->globals_buffer_size = 0;
module->num_imported_mutable_globals = 0;
return;
}
@ -1002,7 +1000,7 @@ class ModuleDecoderImpl : public Decoder {
offset += size;
}
}
module->globals_size = offset;
module->globals_buffer_size = offset;
}
// Verifies the body (code) of a given function.
@ -1020,7 +1018,7 @@ class ModuleDecoderImpl : public Decoder {
start_ + GetBufferRelativeOffset(function->code.offset()),
start_ + GetBufferRelativeOffset(function->code.end_offset())};
DecodeResult result = VerifyWasmCodeWithStats(allocator, module, body,
IsWasm(), GetCounters());
origin_, GetCounters());
if (result.failed()) {
// Wrap the error message from the function decoder.
std::ostringstream wrapped;
@ -1255,7 +1253,7 @@ class ModuleDecoderImpl : public Decoder {
case kLocalF64:
return kWasmF64;
default:
if (IsWasm()) {
if (origin_ == kWasmOrigin) {
switch (t) {
case kLocalS128:
if (FLAG_experimental_wasm_simd) return kWasmS128;
@ -1325,18 +1323,16 @@ class ModuleDecoderImpl : public Decoder {
ModuleResult DecodeWasmModule(Isolate* isolate, const byte* module_start,
const byte* module_end, bool verify_functions,
ModuleOrigin origin, Counters* counters) {
auto counter = origin == kWasmOrigin
? counters->wasm_decode_wasm_module_time()
: counters->wasm_decode_asm_module_time();
auto counter =
SELECT_WASM_COUNTER(counters, origin, wasm_decode, module_time);
TimedHistogramScope wasm_decode_module_time_scope(counter);
size_t size = module_end - module_start;
if (module_start > module_end) return ModuleResult::Error("start > end");
if (size >= kV8MaxWasmModuleSize)
return ModuleResult::Error("size > maximum module size: %zu", size);
// TODO(bradnelson): Improve histogram handling of size_t.
auto size_counter = origin == kWasmOrigin
? counters->wasm_wasm_module_size_bytes()
: counters->wasm_asm_module_size_bytes();
auto size_counter =
SELECT_WASM_COUNTER(counters, origin, wasm, module_size_bytes);
size_counter->AddSample(static_cast<int>(size));
// Signatures are stored in zone memory, which have the same lifetime
// as the {module}.
@ -1347,10 +1343,8 @@ ModuleResult DecodeWasmModule(Isolate* isolate, const byte* module_start,
// allocated on the C++ heap.
// https://bugs.chromium.org/p/chromium/issues/detail?id=657320
if (result.ok()) {
auto peak_counter =
origin == kWasmOrigin
? counters->wasm_decode_wasm_module_peak_memory_bytes()
: counters->wasm_decode_asm_module_peak_memory_bytes();
auto peak_counter = SELECT_WASM_COUNTER(counters, origin, wasm_decode,
module_peak_memory_bytes);
peak_counter->AddSample(
static_cast<int>(result.val->signature_zone->allocation_size()));
}
@ -1454,9 +1448,8 @@ FunctionResult DecodeWasmFunction(Isolate* isolate, Zone* zone,
size_t size = function_end - function_start;
if (function_start > function_end)
return FunctionResult::Error("start > end");
auto size_histogram = module->is_wasm()
? counters->wasm_wasm_function_size_bytes()
: counters->wasm_asm_function_size_bytes();
auto size_histogram =
SELECT_WASM_COUNTER(counters, module->origin, wasm, function_size_bytes);
// TODO(bradnelson): Improve histogram handling of ptrdiff_t.
size_histogram->AddSample(static_cast<int>(size));
if (size > kV8MaxWasmFunctionSize)

View File

@ -128,6 +128,10 @@ struct WasmExport {
enum ModuleOrigin : uint8_t { kWasmOrigin, kAsmJsOrigin };
#define SELECT_WASM_COUNTER(counters, origin, prefix, suffix) \
((origin) == wasm::kWasmOrigin ? (counters)->prefix##_wasm_##suffix() \
: (counters)->prefix##_asm_##suffix())
struct ModuleWireBytes;
// Static representation of a module.
@ -146,14 +150,12 @@ struct V8_EXPORT_PRIVATE WasmModule {
std::vector<WasmGlobal> globals;
// Size of the buffer required for all globals that are not imported and
// mutable.
// TODO(wasm): Rename for clarity?
uint32_t globals_size = 0;
uint32_t globals_buffer_size = 0;
uint32_t num_imported_mutable_globals = 0;
uint32_t num_imported_functions = 0;
uint32_t num_declared_functions = 0;
uint32_t num_exported_functions = 0;
WireBytesRef name = {0, 0};
// TODO(wasm): Add url here, for spec'ed location information.
std::vector<FunctionSig*> signatures; // by signature index
std::vector<uint32_t> signature_ids; // by signature index
std::vector<WasmFunction> functions;
@ -165,24 +167,17 @@ struct V8_EXPORT_PRIVATE WasmModule {
std::vector<WasmTableInit> table_inits;
SignatureMap signature_map; // canonicalizing map for signature indexes.
ModuleOrigin origin = kWasmOrigin; // origin of the module
mutable std::unique_ptr<std::unordered_map<uint32_t, WireBytesRef>> names_;
WasmModule() : WasmModule(nullptr) {}
WasmModule(std::unique_ptr<Zone> owned);
ModuleOrigin origin() const { return origin_; }
void set_origin(ModuleOrigin new_value) { origin_ = new_value; }
bool is_wasm() const { return origin_ == kWasmOrigin; }
bool is_asm_js() const { return origin_ == kAsmJsOrigin; }
WireBytesRef LookupName(const ModuleWireBytes* wire_bytes,
uint32_t function_index) const;
WireBytesRef LookupName(SeqOneByteString* wire_bytes,
uint32_t function_index) const;
void AddNameForTesting(int function_index, WireBytesRef name);
private:
// TODO(kschimpf) - Encapsulate more fields.
ModuleOrigin origin_ = kWasmOrigin; // origin of the module
mutable std::unique_ptr<std::unordered_map<uint32_t, WireBytesRef>> names_;
};
// Interface to the storage (wire bytes) of a wasm module.

View File

@ -988,7 +988,7 @@ Handle<WasmSharedModuleData> WasmSharedModuleData::New(
}
bool WasmSharedModuleData::is_asm_js() {
bool asm_js = module()->is_asm_js();
bool asm_js = module()->origin == wasm::kAsmJsOrigin;
DCHECK_EQ(asm_js, script()->IsUserJavaScript());
DCHECK_EQ(asm_js, has_asm_js_offset_table());
return asm_js;
@ -1195,7 +1195,7 @@ int WasmSharedModuleData::GetSourcePosition(Handle<WasmSharedModuleData> shared,
Isolate* isolate = shared->GetIsolate();
const WasmModule* module = shared->module();
if (!module->is_asm_js()) {
if (module->origin != wasm::kAsmJsOrigin) {
// for non-asm.js modules, we just add the function's start offset
// to make a module-relative position.
return byte_offset + shared->GetFunctionOffset(func_index);

View File

@ -24,7 +24,7 @@ TestingModuleBuilder::TestingModuleBuilder(
runtime_exception_support_(exception_support),
lower_simd_(lower_simd) {
WasmJs::Install(isolate_, true);
test_module_->globals_size = kMaxGlobalsSize;
test_module_->globals_buffer_size = kMaxGlobalsSize;
memset(globals_data_, 0, sizeof(globals_data_));
uint32_t maybe_import_index = 0;
@ -45,7 +45,7 @@ TestingModuleBuilder::TestingModuleBuilder(
CodeSpaceMemoryModificationScope modification_scope(isolate_->heap());
Handle<Code> code = compiler::CompileWasmToJSWrapper(
isolate_, maybe_import->js_function, maybe_import->sig,
maybe_import_index, test_module_->origin(),
maybe_import_index, test_module_->origin,
trap_handler::IsTrapHandlerEnabled() ? kUseTrapHandler
: kNoTrapHandler);
native_module_->ResizeCodeTableForTesting(maybe_import_index + 1,
@ -67,7 +67,7 @@ byte* TestingModuleBuilder::AddMemory(uint32_t size) {
CHECK_NULL(mem_start_);
CHECK_EQ(0, mem_size_);
DCHECK(!instance_object_->has_memory_object());
DCHECK_IMPLIES(test_module_->origin() == kWasmOrigin,
DCHECK_IMPLIES(test_module_->origin == kWasmOrigin,
size % kWasmPageSize == 0);
test_module_->has_memory = true;
uint32_t alloc_size = RoundUp(size, kWasmPageSize);

View File

@ -94,7 +94,7 @@ class TestingModuleBuilder {
TestingModuleBuilder(Zone*, ManuallyImportedJSFunction*, WasmExecutionMode,
RuntimeExceptionSupport, LowerSimd);
void ChangeOriginToAsmjs() { test_module_->set_origin(kAsmJsOrigin); }
void ChangeOriginToAsmjs() { test_module_->origin = kAsmJsOrigin; }
byte* AddMemory(uint32_t size);

View File

@ -205,7 +205,7 @@ constexpr size_t kMaxByteSizedLeb128 = 127;
class TestModuleBuilder {
public:
explicit TestModuleBuilder(ModuleOrigin origin = kWasmOrigin) {
mod.set_origin(origin);
mod.origin = origin;
}
byte AddGlobal(ValueType type, bool mutability = true) {
mod.globals.push_back(