Commit 081ac370 authored by clemensh's avatar clemensh Committed by Commit bot

[wasm] Introduce WasmSharedModuleData and refactor other objects

The new object will hold information which is shared by all clones of a
WasmCompiledModule, e.g. the decoded asm.js offset table, and in the
future also breakpoints. From there, we can set them on each new
instantiation of any clone.

While already changing lots of the code base, I also renamed all
getters from "get_foo" to "foo", to conform to the style guide.

R=titzer@chromium.org, yangguo@chromium.org
BUG=v8:5732

Review-Url: https://codereview.chromium.org/2591653002
Cr-Commit-Position: refs/heads/master@{#41862}
parent a48e5ab8
...@@ -7351,7 +7351,7 @@ Local<String> WasmCompiledModule::GetWasmWireBytes() { ...@@ -7351,7 +7351,7 @@ Local<String> WasmCompiledModule::GetWasmWireBytes() {
i::Handle<i::JSObject>::cast(Utils::OpenHandle(this)); i::Handle<i::JSObject>::cast(Utils::OpenHandle(this));
i::Handle<i::WasmCompiledModule> compiled_part = i::Handle<i::WasmCompiledModule> compiled_part =
i::handle(i::WasmCompiledModule::cast(obj->GetInternalField(0))); i::handle(i::WasmCompiledModule::cast(obj->GetInternalField(0)));
i::Handle<i::String> wire_bytes = compiled_part->module_bytes(); i::Handle<i::String> wire_bytes(compiled_part->module_bytes());
return Local<String>::Cast(Utils::ToLocal(wire_bytes)); return Local<String>::Cast(Utils::ToLocal(wire_bytes));
} }
...@@ -7413,7 +7413,7 @@ MaybeLocal<WasmCompiledModule> WasmCompiledModule::Compile(Isolate* isolate, ...@@ -7413,7 +7413,7 @@ MaybeLocal<WasmCompiledModule> WasmCompiledModule::Compile(Isolate* isolate,
i::wasm::CreateModuleObjectFromBytes( i::wasm::CreateModuleObjectFromBytes(
i_isolate, start, start + length, &thrower, i_isolate, start, start + length, &thrower,
i::wasm::ModuleOrigin::kWasmOrigin, i::Handle<i::Script>::null(), i::wasm::ModuleOrigin::kWasmOrigin, i::Handle<i::Script>::null(),
nullptr, nullptr); i::Vector<const uint8_t>::empty());
if (maybe_compiled.is_null()) return MaybeLocal<WasmCompiledModule>(); if (maybe_compiled.is_null()) return MaybeLocal<WasmCompiledModule>();
return Local<WasmCompiledModule>::Cast( return Local<WasmCompiledModule>::Cast(
Utils::ToLocal(maybe_compiled.ToHandleChecked())); Utils::ToLocal(maybe_compiled.ToHandleChecked()));
......
...@@ -179,13 +179,14 @@ MaybeHandle<FixedArray> AsmJs::CompileAsmViaWasm(CompilationInfo* info) { ...@@ -179,13 +179,14 @@ MaybeHandle<FixedArray> AsmJs::CompileAsmViaWasm(CompilationInfo* info) {
wasm::ZoneBuffer* module = asm_wasm_result.module_bytes; wasm::ZoneBuffer* module = asm_wasm_result.module_bytes;
wasm::ZoneBuffer* asm_offsets = asm_wasm_result.asm_offset_table; wasm::ZoneBuffer* asm_offsets = asm_wasm_result.asm_offset_table;
Vector<const byte> asm_offsets_vec(asm_offsets->begin(),
static_cast<int>(asm_offsets->size()));
base::ElapsedTimer compile_timer; base::ElapsedTimer compile_timer;
compile_timer.Start(); compile_timer.Start();
MaybeHandle<JSObject> compiled = wasm::CreateModuleObjectFromBytes( MaybeHandle<JSObject> compiled = wasm::CreateModuleObjectFromBytes(
info->isolate(), module->begin(), module->end(), &thrower, info->isolate(), module->begin(), module->end(), &thrower,
internal::wasm::kAsmJsOrigin, info->script(), asm_offsets->begin(), internal::wasm::kAsmJsOrigin, info->script(), asm_offsets_vec);
asm_offsets->end());
DCHECK(!compiled.is_null()); DCHECK(!compiled.is_null());
double compile_time = compile_timer.Elapsed().InMillisecondsF(); double compile_time = compile_timer.Elapsed().InMillisecondsF();
......
...@@ -1535,7 +1535,7 @@ void WasmFrame::Print(StringStream* accumulator, PrintMode mode, ...@@ -1535,7 +1535,7 @@ void WasmFrame::Print(StringStream* accumulator, PrintMode mode,
raw_func_name = STATIC_CHAR_VECTOR("<undefined>"); raw_func_name = STATIC_CHAR_VECTOR("<undefined>");
} else { } else {
raw_func_name = WasmInstanceObject::cast(instance_or_undef) raw_func_name = WasmInstanceObject::cast(instance_or_undef)
->get_compiled_module() ->compiled_module()
->GetRawFunctionName(this->function_index()); ->GetRawFunctionName(this->function_index());
} }
const int kMaxPrintedFunctionName = 64; const int kMaxPrintedFunctionName = 64;
...@@ -1578,9 +1578,9 @@ Script* WasmFrame::script() const { ...@@ -1578,9 +1578,9 @@ Script* WasmFrame::script() const {
int WasmFrame::position() const { int WasmFrame::position() const {
int position = StandardFrame::position(); int position = StandardFrame::position();
if (wasm_instance()->get_compiled_module()->is_asm_js()) { if (wasm_instance()->compiled_module()->is_asm_js()) {
Handle<WasmCompiledModule> compiled_module( Handle<WasmCompiledModule> compiled_module(
WasmInstanceObject::cast(wasm_instance())->get_compiled_module(), WasmInstanceObject::cast(wasm_instance())->compiled_module(),
isolate()); isolate());
DCHECK_LE(0, position); DCHECK_LE(0, position);
position = WasmCompiledModule::GetAsmJsSourcePosition( position = WasmCompiledModule::GetAsmJsSourcePosition(
......
...@@ -520,7 +520,7 @@ Handle<Object> Isolate::CaptureSimpleStackTrace(Handle<JSReceiver> error_object, ...@@ -520,7 +520,7 @@ Handle<Object> Isolate::CaptureSimpleStackTrace(Handle<JSReceiver> error_object,
static_cast<int>(wasm_frame->pc() - code->instruction_start()); static_cast<int>(wasm_frame->pc() - code->instruction_start());
int flags = 0; int flags = 0;
if (instance->get_compiled_module()->is_asm_js()) { if (instance->compiled_module()->is_asm_js()) {
flags |= FrameArray::kIsAsmJsWasmFrame; flags |= FrameArray::kIsAsmJsWasmFrame;
if (wasm_frame->at_to_number_conversion()) { if (wasm_frame->at_to_number_conversion()) {
flags |= FrameArray::kAsmJsAtNumberConversion; flags |= FrameArray::kAsmJsAtNumberConversion;
...@@ -705,7 +705,7 @@ class CaptureStackTraceHelper { ...@@ -705,7 +705,7 @@ class CaptureStackTraceHelper {
if (!function_key_.is_null()) { if (!function_key_.is_null()) {
Handle<WasmCompiledModule> compiled_module( Handle<WasmCompiledModule> compiled_module(
frame->wasm_instance()->get_compiled_module(), isolate_); frame->wasm_instance()->compiled_module(), isolate_);
Handle<String> name = WasmCompiledModule::GetFunctionName( Handle<String> name = WasmCompiledModule::GetFunctionName(
isolate_, compiled_module, frame->function_index()); isolate_, compiled_module, frame->function_index());
JSObject::AddProperty(stack_frame, function_key_, name, NONE); JSObject::AddProperty(stack_frame, function_key_, name, NONE);
...@@ -1559,7 +1559,7 @@ bool Isolate::ComputeLocationFromStackTrace(MessageLocation* target, ...@@ -1559,7 +1559,7 @@ bool Isolate::ComputeLocationFromStackTrace(MessageLocation* target,
if (elements->IsWasmFrame(i) || elements->IsAsmJsWasmFrame(i)) { if (elements->IsWasmFrame(i) || elements->IsAsmJsWasmFrame(i)) {
Handle<WasmCompiledModule> compiled_module( Handle<WasmCompiledModule> compiled_module(
WasmInstanceObject::cast(elements->WasmInstance(i)) WasmInstanceObject::cast(elements->WasmInstance(i))
->get_compiled_module()); ->compiled_module());
int func_index = elements->WasmFunctionIndex(i)->value(); int func_index = elements->WasmFunctionIndex(i)->value();
int code_offset = elements->Offset(i)->value(); int code_offset = elements->Offset(i)->value();
// TODO(wasm): Clean this up (bug 5007). // TODO(wasm): Clean this up (bug 5007).
...@@ -1578,7 +1578,7 @@ bool Isolate::ComputeLocationFromStackTrace(MessageLocation* target, ...@@ -1578,7 +1578,7 @@ bool Isolate::ComputeLocationFromStackTrace(MessageLocation* target,
// adding the function offset. // adding the function offset.
pos += compiled_module->GetFunctionOffset(func_index); pos += compiled_module->GetFunctionOffset(func_index);
} }
Handle<Script> script = compiled_module->script(); Handle<Script> script(compiled_module->script());
*target = MessageLocation(script, pos, pos + 1); *target = MessageLocation(script, pos, pos + 1);
return true; return true;
......
...@@ -657,7 +657,7 @@ Handle<Object> WasmStackFrame::GetFunction() const { ...@@ -657,7 +657,7 @@ Handle<Object> WasmStackFrame::GetFunction() const {
Handle<Object> WasmStackFrame::GetFunctionName() { Handle<Object> WasmStackFrame::GetFunctionName() {
Handle<Object> name; Handle<Object> name;
Handle<WasmCompiledModule> compiled_module( Handle<WasmCompiledModule> compiled_module(
Handle<WasmInstanceObject>::cast(wasm_instance_)->get_compiled_module(), Handle<WasmInstanceObject>::cast(wasm_instance_)->compiled_module(),
isolate_); isolate_);
if (!WasmCompiledModule::GetFunctionNameOrNull(isolate_, compiled_module, if (!WasmCompiledModule::GetFunctionNameOrNull(isolate_, compiled_module,
wasm_func_index_) wasm_func_index_)
...@@ -704,9 +704,9 @@ Handle<Object> WasmStackFrame::Null() const { ...@@ -704,9 +704,9 @@ Handle<Object> WasmStackFrame::Null() const {
bool WasmStackFrame::HasScript() const { return true; } bool WasmStackFrame::HasScript() const { return true; }
Handle<Script> WasmStackFrame::GetScript() const { Handle<Script> WasmStackFrame::GetScript() const {
return WasmInstanceObject::cast(*wasm_instance_) return handle(
->get_compiled_module() WasmInstanceObject::cast(*wasm_instance_)->compiled_module()->script(),
->script(); isolate_);
} }
AsmJsWasmStackFrame::AsmJsWasmStackFrame() {} AsmJsWasmStackFrame::AsmJsWasmStackFrame() {}
...@@ -747,8 +747,7 @@ int AsmJsWasmStackFrame::GetPosition() const { ...@@ -747,8 +747,7 @@ int AsmJsWasmStackFrame::GetPosition() const {
DCHECK_LE(0, offset_); DCHECK_LE(0, offset_);
int byte_offset = code_->SourcePosition(offset_); int byte_offset = code_->SourcePosition(offset_);
Handle<WasmCompiledModule> compiled_module( Handle<WasmCompiledModule> compiled_module(
WasmInstanceObject::cast(*wasm_instance_)->get_compiled_module(), WasmInstanceObject::cast(*wasm_instance_)->compiled_module(), isolate_);
isolate_);
DCHECK_LE(0, byte_offset); DCHECK_LE(0, byte_offset);
return WasmCompiledModule::GetAsmJsSourcePosition( return WasmCompiledModule::GetAsmJsSourcePosition(
compiled_module, wasm_func_index_, static_cast<uint32_t>(byte_offset), compiled_module, wasm_func_index_, static_cast<uint32_t>(byte_offset),
......
...@@ -527,7 +527,7 @@ RUNTIME_FUNCTION(Runtime_GetFrameDetails) { ...@@ -527,7 +527,7 @@ RUNTIME_FUNCTION(Runtime_GetFrameDetails) {
// Add the function name. // Add the function name.
Handle<WasmCompiledModule> compiled_module( Handle<WasmCompiledModule> compiled_module(
it.wasm_frame()->wasm_instance()->get_compiled_module(), isolate); it.wasm_frame()->wasm_instance()->compiled_module(), isolate);
int func_index = it.wasm_frame()->function_index(); int func_index = it.wasm_frame()->function_index();
Handle<String> func_name = WasmCompiledModule::GetFunctionName( Handle<String> func_name = WasmCompiledModule::GetFunctionName(
isolate, compiled_module, func_index); isolate, compiled_module, func_index);
......
...@@ -742,7 +742,7 @@ RUNTIME_FUNCTION(Runtime_SerializeWasmModule) { ...@@ -742,7 +742,7 @@ RUNTIME_FUNCTION(Runtime_SerializeWasmModule) {
DCHECK(args.length() == 1); DCHECK(args.length() == 1);
CONVERT_ARG_HANDLE_CHECKED_2(WasmModuleObject, module_obj, 0); CONVERT_ARG_HANDLE_CHECKED_2(WasmModuleObject, module_obj, 0);
Handle<WasmCompiledModule> orig = handle(module_obj->get_compiled_module()); Handle<WasmCompiledModule> orig(module_obj->compiled_module());
std::unique_ptr<ScriptData> data = std::unique_ptr<ScriptData> data =
WasmCompiledModuleSerializer::SerializeWasmModule(isolate, orig); WasmCompiledModuleSerializer::SerializeWasmModule(isolate, orig);
void* buff = isolate->array_buffer_allocator()->Allocate(data->length()); void* buff = isolate->array_buffer_allocator()->Allocate(data->length());
......
...@@ -231,7 +231,7 @@ std::unique_ptr<ScriptData> WasmCompiledModuleSerializer::SerializeWasmModule( ...@@ -231,7 +231,7 @@ std::unique_ptr<ScriptData> WasmCompiledModuleSerializer::SerializeWasmModule(
WasmCompiledModuleSerializer wasm_cs(isolate, 0); WasmCompiledModuleSerializer wasm_cs(isolate, 0);
wasm_cs.reference_map()->AddAttachedReference(*isolate->native_context()); wasm_cs.reference_map()->AddAttachedReference(*isolate->native_context());
wasm_cs.reference_map()->AddAttachedReference( wasm_cs.reference_map()->AddAttachedReference(
*compiled_module->module_bytes()); compiled_module->module_bytes());
ScriptData* data = wasm_cs.Serialize(compiled_module); ScriptData* data = wasm_cs.Serialize(compiled_module);
return std::unique_ptr<ScriptData>(data); return std::unique_ptr<ScriptData>(data);
} }
...@@ -268,10 +268,12 @@ MaybeHandle<FixedArray> WasmCompiledModuleSerializer::DeserializeWasmModule( ...@@ -268,10 +268,12 @@ MaybeHandle<FixedArray> WasmCompiledModuleSerializer::DeserializeWasmModule(
MaybeHandle<HeapObject> obj = deserializer.DeserializeObject(isolate); MaybeHandle<HeapObject> obj = deserializer.DeserializeObject(isolate);
if (obj.is_null() || !obj.ToHandleChecked()->IsFixedArray()) return nothing; if (obj.is_null() || !obj.ToHandleChecked()->IsFixedArray()) return nothing;
Handle<WasmCompiledModule> compiled_module = // Cast without type checks, as the module wrapper is not there yet.
Handle<WasmCompiledModule>::cast(obj.ToHandleChecked()); Handle<WasmCompiledModule> compiled_module(
static_cast<WasmCompiledModule*>(*obj.ToHandleChecked()), isolate);
WasmCompiledModule::RecreateModuleWrapper(isolate, compiled_module); WasmCompiledModule::RecreateModuleWrapper(isolate, compiled_module);
DCHECK(WasmCompiledModule::IsWasmCompiledModule(*compiled_module));
return compiled_module; return compiled_module;
} }
......
...@@ -783,7 +783,7 @@ Maybe<bool> ValueSerializer::WriteWasmModule(Handle<JSObject> object) { ...@@ -783,7 +783,7 @@ Maybe<bool> ValueSerializer::WriteWasmModule(Handle<JSObject> object) {
WriteTag(SerializationTag::kWasmModule); WriteTag(SerializationTag::kWasmModule);
WriteRawBytes(&encoding_tag, sizeof(encoding_tag)); WriteRawBytes(&encoding_tag, sizeof(encoding_tag));
Handle<String> wire_bytes = compiled_part->module_bytes(); Handle<String> wire_bytes(compiled_part->module_bytes(), isolate_);
int wire_bytes_length = wire_bytes->length(); int wire_bytes_length = wire_bytes->length();
WriteVarint<uint32_t>(wire_bytes_length); WriteVarint<uint32_t>(wire_bytes_length);
uint8_t* destination = ReserveRawBytes(wire_bytes_length); uint8_t* destination = ReserveRawBytes(wire_bytes_length);
...@@ -1554,8 +1554,8 @@ MaybeHandle<JSObject> ValueDeserializer::ReadWasmModule() { ...@@ -1554,8 +1554,8 @@ MaybeHandle<JSObject> ValueDeserializer::ReadWasmModule() {
wasm::ErrorThrower thrower(isolate_, "ValueDeserializer::ReadWasmModule"); wasm::ErrorThrower thrower(isolate_, "ValueDeserializer::ReadWasmModule");
return wasm::CreateModuleObjectFromBytes( return wasm::CreateModuleObjectFromBytes(
isolate_, wire_bytes.begin(), wire_bytes.end(), &thrower, isolate_, wire_bytes.begin(), wire_bytes.end(), &thrower,
wasm::ModuleOrigin::kWasmOrigin, Handle<Script>::null(), nullptr, wasm::ModuleOrigin::kWasmOrigin, Handle<Script>::null(),
nullptr); Vector<const byte>::empty());
} }
MaybeHandle<JSObject> ValueDeserializer::ReadHostObject() { MaybeHandle<JSObject> ValueDeserializer::ReadHostObject() {
......
...@@ -13,33 +13,11 @@ ...@@ -13,33 +13,11 @@
using namespace v8::internal; using namespace v8::internal;
using namespace v8::internal::wasm; using namespace v8::internal::wasm;
namespace {
enum {
kWasmDebugInfoWasmObj,
kWasmDebugInfoWasmBytesHash,
kWasmDebugInfoAsmJsOffsets,
kWasmDebugInfoNumEntries
};
} // namespace
Handle<WasmDebugInfo> WasmDebugInfo::New(Handle<WasmInstanceObject> instance) { Handle<WasmDebugInfo> WasmDebugInfo::New(Handle<WasmInstanceObject> instance) {
Isolate *isolate = instance->GetIsolate(); Isolate *isolate = instance->GetIsolate();
Factory *factory = isolate->factory(); Factory *factory = isolate->factory();
Handle<FixedArray> arr = Handle<FixedArray> arr = factory->NewFixedArray(kFieldCount, TENURED);
factory->NewFixedArray(kWasmDebugInfoNumEntries, TENURED); arr->set(kInstance, *instance);
arr->set(kWasmDebugInfoWasmObj, *instance);
int hash = 0;
Handle<SeqOneByteString> wasm_bytes =
instance->get_compiled_module()->module_bytes();
{
DisallowHeapAllocation no_gc;
hash = StringHasher::HashSequentialString(
wasm_bytes->GetChars(), wasm_bytes->length(), kZeroHashSeed);
}
Handle<Object> hash_obj = factory->NewNumberFromInt(hash, TENURED);
arr->set(kWasmDebugInfoWasmBytesHash, *hash_obj);
return Handle<WasmDebugInfo>::cast(arr); return Handle<WasmDebugInfo>::cast(arr);
} }
...@@ -47,9 +25,7 @@ Handle<WasmDebugInfo> WasmDebugInfo::New(Handle<WasmInstanceObject> instance) { ...@@ -47,9 +25,7 @@ Handle<WasmDebugInfo> WasmDebugInfo::New(Handle<WasmInstanceObject> instance) {
bool WasmDebugInfo::IsDebugInfo(Object *object) { bool WasmDebugInfo::IsDebugInfo(Object *object) {
if (!object->IsFixedArray()) return false; if (!object->IsFixedArray()) return false;
FixedArray *arr = FixedArray::cast(object); FixedArray *arr = FixedArray::cast(object);
return arr->length() == kWasmDebugInfoNumEntries && return arr->length() == kFieldCount && IsWasmInstance(arr->get(kInstance));
IsWasmInstance(arr->get(kWasmDebugInfoWasmObj)) &&
arr->get(kWasmDebugInfoWasmBytesHash)->IsNumber();
} }
WasmDebugInfo *WasmDebugInfo::cast(Object *object) { WasmDebugInfo *WasmDebugInfo::cast(Object *object) {
...@@ -58,5 +34,5 @@ WasmDebugInfo *WasmDebugInfo::cast(Object *object) { ...@@ -58,5 +34,5 @@ WasmDebugInfo *WasmDebugInfo::cast(Object *object) {
} }
WasmInstanceObject *WasmDebugInfo::wasm_instance() { WasmInstanceObject *WasmDebugInfo::wasm_instance() {
return WasmInstanceObject::cast(get(kWasmDebugInfoWasmObj)); return WasmInstanceObject::cast(get(kInstance));
} }
...@@ -92,7 +92,7 @@ static i::MaybeHandle<i::WasmModuleObject> CreateModuleObject( ...@@ -92,7 +92,7 @@ static i::MaybeHandle<i::WasmModuleObject> CreateModuleObject(
DCHECK(source->IsArrayBuffer() || source->IsTypedArray()); DCHECK(source->IsArrayBuffer() || source->IsTypedArray());
return i::wasm::CreateModuleObjectFromBytes( return i::wasm::CreateModuleObjectFromBytes(
i_isolate, buffer.start, buffer.end, thrower, i::wasm::kWasmOrigin, i_isolate, buffer.start, buffer.end, thrower, i::wasm::kWasmOrigin,
i::Handle<i::Script>::null(), nullptr, nullptr); i::Handle<i::Script>::null(), i::Vector<const byte>::empty());
} }
static bool ValidateModule(v8::Isolate* isolate, static bool ValidateModule(v8::Isolate* isolate,
...@@ -221,8 +221,7 @@ void WebAssemblyInstance(const v8::FunctionCallbackInfo<v8::Value>& args) { ...@@ -221,8 +221,7 @@ void WebAssemblyInstance(const v8::FunctionCallbackInfo<v8::Value>& args) {
i::Handle<i::Object> mem_obj = v8::Utils::OpenHandle(*obj); i::Handle<i::Object> mem_obj = v8::Utils::OpenHandle(*obj);
if (i::WasmJs::IsWasmMemoryObject(i_isolate, mem_obj)) { if (i::WasmJs::IsWasmMemoryObject(i_isolate, mem_obj)) {
memory = i::Handle<i::JSArrayBuffer>( memory = i::Handle<i::JSArrayBuffer>(
i::Handle<i::WasmMemoryObject>::cast(mem_obj)->get_buffer(), i::Handle<i::WasmMemoryObject>::cast(mem_obj)->buffer(), i_isolate);
i_isolate);
} else { } else {
thrower.TypeError("Argument 2 must be a WebAssembly.Memory"); thrower.TypeError("Argument 2 must be a WebAssembly.Memory");
return; return;
...@@ -402,7 +401,7 @@ void WebAssemblyTableGrow(const v8::FunctionCallbackInfo<v8::Value>& args) { ...@@ -402,7 +401,7 @@ void WebAssemblyTableGrow(const v8::FunctionCallbackInfo<v8::Value>& args) {
i::Isolate* i_isolate = reinterpret_cast<i::Isolate*>(isolate); i::Isolate* i_isolate = reinterpret_cast<i::Isolate*>(isolate);
auto receiver = auto receiver =
i::Handle<i::WasmTableObject>::cast(Utils::OpenHandle(*args.This())); i::Handle<i::WasmTableObject>::cast(Utils::OpenHandle(*args.This()));
i::Handle<i::FixedArray> old_array(receiver->get_functions(), i_isolate); i::Handle<i::FixedArray> old_array(receiver->functions(), i_isolate);
int old_size = old_array->length(); int old_size = old_array->length();
int64_t new_size64 = 0; int64_t new_size64 = 0;
if (args.Length() > 0 && !args[0]->IntegerValue(context).To(&new_size64)) { if (args.Length() > 0 && !args[0]->IntegerValue(context).To(&new_size64)) {
...@@ -444,7 +443,7 @@ void WebAssemblyTableGet(const v8::FunctionCallbackInfo<v8::Value>& args) { ...@@ -444,7 +443,7 @@ void WebAssemblyTableGet(const v8::FunctionCallbackInfo<v8::Value>& args) {
i::Isolate* i_isolate = reinterpret_cast<i::Isolate*>(isolate); i::Isolate* i_isolate = reinterpret_cast<i::Isolate*>(isolate);
auto receiver = auto receiver =
i::Handle<i::WasmTableObject>::cast(Utils::OpenHandle(*args.This())); i::Handle<i::WasmTableObject>::cast(Utils::OpenHandle(*args.This()));
i::Handle<i::FixedArray> array(receiver->get_functions(), i_isolate); i::Handle<i::FixedArray> array(receiver->functions(), i_isolate);
int i = 0; int i = 0;
if (args.Length() > 0 && !args[0]->Int32Value(context).To(&i)) return; if (args.Length() > 0 && !args[0]->Int32Value(context).To(&i)) return;
v8::ReturnValue<v8::Value> return_value = args.GetReturnValue(); v8::ReturnValue<v8::Value> return_value = args.GetReturnValue();
...@@ -488,7 +487,7 @@ void WebAssemblyTableSet(const v8::FunctionCallbackInfo<v8::Value>& args) { ...@@ -488,7 +487,7 @@ void WebAssemblyTableSet(const v8::FunctionCallbackInfo<v8::Value>& args) {
auto receiver = auto receiver =
i::Handle<i::WasmTableObject>::cast(Utils::OpenHandle(*args.This())); i::Handle<i::WasmTableObject>::cast(Utils::OpenHandle(*args.This()));
i::Handle<i::FixedArray> array(receiver->get_functions(), i_isolate); i::Handle<i::FixedArray> array(receiver->functions(), i_isolate);
int i; int i;
if (!args[0]->Int32Value(context).To(&i)) return; if (!args[0]->Int32Value(context).To(&i)) return;
if (i < 0 || i >= array->length()) { if (i < 0 || i >= array->length()) {
...@@ -498,7 +497,7 @@ void WebAssemblyTableSet(const v8::FunctionCallbackInfo<v8::Value>& args) { ...@@ -498,7 +497,7 @@ void WebAssemblyTableSet(const v8::FunctionCallbackInfo<v8::Value>& args) {
return; return;
} }
i::Handle<i::FixedArray> dispatch_tables(receiver->get_dispatch_tables(), i::Handle<i::FixedArray> dispatch_tables(receiver->dispatch_tables(),
i_isolate); i_isolate);
if (value->IsNull(i_isolate)) { if (value->IsNull(i_isolate)) {
i::wasm::UpdateDispatchTables(i_isolate, dispatch_tables, i, i::wasm::UpdateDispatchTables(i_isolate, dispatch_tables, i,
...@@ -555,7 +554,7 @@ void WebAssemblyMemoryGetBuffer( ...@@ -555,7 +554,7 @@ void WebAssemblyMemoryGetBuffer(
i::Isolate* i_isolate = reinterpret_cast<i::Isolate*>(isolate); i::Isolate* i_isolate = reinterpret_cast<i::Isolate*>(isolate);
i::Handle<i::WasmMemoryObject> receiver = i::Handle<i::WasmMemoryObject> receiver =
i::Handle<i::WasmMemoryObject>::cast(Utils::OpenHandle(*args.This())); i::Handle<i::WasmMemoryObject>::cast(Utils::OpenHandle(*args.This()));
i::Handle<i::Object> buffer(receiver->get_buffer(), i_isolate); i::Handle<i::Object> buffer(receiver->buffer(), i_isolate);
DCHECK(buffer->IsJSArrayBuffer()); DCHECK(buffer->IsJSArrayBuffer());
v8::ReturnValue<v8::Value> return_value = args.GetReturnValue(); v8::ReturnValue<v8::Value> return_value = args.GetReturnValue();
return_value.Set(Utils::ToLocal(buffer)); return_value.Set(Utils::ToLocal(buffer));
......
This diff is collapsed.
...@@ -221,7 +221,9 @@ struct V8_EXPORT_PRIVATE WasmModule { ...@@ -221,7 +221,9 @@ struct V8_EXPORT_PRIVATE WasmModule {
MaybeHandle<WasmCompiledModule> CompileFunctions( MaybeHandle<WasmCompiledModule> CompileFunctions(
Isolate* isolate, Handle<Managed<WasmModule>> module_wrapper, Isolate* isolate, Handle<Managed<WasmModule>> module_wrapper,
ErrorThrower* thrower, const ModuleWireBytes& wire_bytes) const; ErrorThrower* thrower, const ModuleWireBytes& wire_bytes,
Handle<Script> asm_js_script,
Vector<const byte> asm_js_offset_table_bytes) const;
}; };
typedef Managed<WasmModule> WasmModuleWrapper; typedef Managed<WasmModule> WasmModuleWrapper;
...@@ -392,7 +394,7 @@ Handle<Script> GetScript(Handle<JSObject> instance); ...@@ -392,7 +394,7 @@ Handle<Script> GetScript(Handle<JSObject> instance);
V8_EXPORT_PRIVATE MaybeHandle<WasmModuleObject> CreateModuleObjectFromBytes( V8_EXPORT_PRIVATE MaybeHandle<WasmModuleObject> CreateModuleObjectFromBytes(
Isolate* isolate, const byte* start, const byte* end, ErrorThrower* thrower, Isolate* isolate, const byte* start, const byte* end, ErrorThrower* thrower,
ModuleOrigin origin, Handle<Script> asm_js_script, ModuleOrigin origin, Handle<Script> asm_js_script,
const byte* asm_offset_tables_start, const byte* asm_offset_tables_end); Vector<const byte> asm_offset_table);
V8_EXPORT_PRIVATE bool ValidateModuleBytes(Isolate* isolate, const byte* start, V8_EXPORT_PRIVATE bool ValidateModuleBytes(Isolate* isolate, const byte* start,
const byte* end, const byte* end,
......
This diff is collapsed.
This diff is collapsed.
...@@ -317,7 +317,8 @@ class WasmSerializationTest { ...@@ -317,7 +317,8 @@ class WasmSerializationTest {
MaybeHandle<WasmCompiledModule> compiled_module = MaybeHandle<WasmCompiledModule> compiled_module =
decoding_result.val->CompileFunctions( decoding_result.val->CompileFunctions(
serialization_isolate, module_wrapper, &thrower, serialization_isolate, module_wrapper, &thrower,
ModuleWireBytes(buffer.begin(), buffer.end())); ModuleWireBytes(buffer.begin(), buffer.end()),
Handle<Script>::null(), Vector<const byte>::empty());
CHECK(!compiled_module.is_null()); CHECK(!compiled_module.is_null());
Handle<JSObject> module_obj = WasmModuleObject::New( Handle<JSObject> module_obj = WasmModuleObject::New(
serialization_isolate, compiled_module.ToHandleChecked()); serialization_isolate, compiled_module.ToHandleChecked());
......
...@@ -59,13 +59,12 @@ TEST(CollectPossibleBreakpoints) { ...@@ -59,13 +59,12 @@ TEST(CollectPossibleBreakpoints) {
Handle<WasmInstanceObject> instance = runner.module().instance_object(); Handle<WasmInstanceObject> instance = runner.module().instance_object();
std::vector<debug::Location> locations; std::vector<debug::Location> locations;
CheckLocations(instance->get_compiled_module(), {0, 0}, {1, 0}, CheckLocations(instance->compiled_module(), {0, 0}, {1, 0},
{{0, 1}, {0, 2}, {0, 4}, {0, 6}}); {{0, 1}, {0, 2}, {0, 4}, {0, 6}});
CheckLocations(instance->get_compiled_module(), {0, 2}, {0, 4}, {{0, 2}}); CheckLocations(instance->compiled_module(), {0, 2}, {0, 4}, {{0, 2}});
CheckLocations(instance->get_compiled_module(), {0, 2}, {0, 5}, CheckLocations(instance->compiled_module(), {0, 2}, {0, 5}, {{0, 2}, {0, 4}});
{{0, 2}, {0, 4}}); CheckLocations(instance->compiled_module(), {0, 6}, {0, 7}, {{0, 6}});
CheckLocations(instance->get_compiled_module(), {0, 6}, {0, 7}, {{0, 6}}); CheckLocations(instance->compiled_module(), {0, 6}, {1, 0}, {{0, 6}});
CheckLocations(instance->get_compiled_module(), {0, 6}, {1, 0}, {{0, 6}}); CheckLocations(instance->compiled_module(), {0, 7}, {1, 0}, {});
CheckLocations(instance->get_compiled_module(), {0, 7}, {1, 0}, {}); CheckLocationsFail(instance->compiled_module(), {0, 8}, {1, 0});
CheckLocationsFail(instance->get_compiled_module(), {0, 8}, {1, 0});
} }
...@@ -267,15 +267,16 @@ class TestingModule : public ModuleEnv { ...@@ -267,15 +267,16 @@ class TestingModule : public ModuleEnv {
} }
uint32_t AddBytes(Vector<const byte> bytes) { uint32_t AddBytes(Vector<const byte> bytes) {
Handle<SeqOneByteString> old_bytes = Handle<SeqOneByteString> old_bytes(
instance_object_->get_compiled_module()->module_bytes(); instance_object_->compiled_module()->module_bytes(), isolate_);
uint32_t old_size = static_cast<uint32_t>(old_bytes->length()); uint32_t old_size = static_cast<uint32_t>(old_bytes->length());
ScopedVector<byte> new_bytes(old_size + bytes.length()); ScopedVector<byte> new_bytes(old_size + bytes.length());
memcpy(new_bytes.start(), old_bytes->GetChars(), old_size); memcpy(new_bytes.start(), old_bytes->GetChars(), old_size);
memcpy(new_bytes.start() + old_size, bytes.start(), bytes.length()); memcpy(new_bytes.start() + old_size, bytes.start(), bytes.length());
Handle<SeqOneByteString> new_bytes_str = Handle<SeqOneByteString>::cast( Handle<SeqOneByteString> new_bytes_str = Handle<SeqOneByteString>::cast(
isolate_->factory()->NewStringFromOneByte(new_bytes).ToHandleChecked()); isolate_->factory()->NewStringFromOneByte(new_bytes).ToHandleChecked());
instance_object_->get_compiled_module()->set_module_bytes(new_bytes_str); instance_object_->compiled_module()->shared()->set_module_bytes(
*new_bytes_str);
return old_size; return old_size;
} }
...@@ -308,18 +309,23 @@ class TestingModule : public ModuleEnv { ...@@ -308,18 +309,23 @@ class TestingModule : public ModuleEnv {
} }
Handle<WasmInstanceObject> InitInstanceObject() { Handle<WasmInstanceObject> InitInstanceObject() {
Handle<SeqOneByteString> empty_string = Handle<SeqOneByteString>::cast(
isolate_->factory()->NewStringFromOneByte({}).ToHandleChecked());
Handle<Managed<wasm::WasmModule>> module_wrapper = Handle<Managed<wasm::WasmModule>> module_wrapper =
Managed<wasm::WasmModule>::New(isolate_, &module_, false); Managed<wasm::WasmModule>::New(isolate_, &module_, false);
Handle<Script> script =
isolate_->factory()->NewScript(isolate_->factory()->empty_string());
script->set_type(Script::TYPE_WASM);
Handle<WasmSharedModuleData> shared_module_data =
WasmSharedModuleData::New(isolate_, module_wrapper, empty_string,
script, Handle<ByteArray>::null());
Handle<WasmCompiledModule> compiled_module = Handle<WasmCompiledModule> compiled_module =
WasmCompiledModule::New(isolate_, module_wrapper); WasmCompiledModule::New(isolate_, shared_module_data);
// Minimally initialize the compiled module such that IsWasmCompiledModule // Minimally initialize the compiled module such that IsWasmCompiledModule
// passes. // passes.
// If tests need more (correct) information, add it later. // If tests need more (correct) information, add it later.
compiled_module->set_min_mem_pages(0); compiled_module->set_min_mem_pages(0);
compiled_module->set_max_mem_pages(Smi::kMaxValue); compiled_module->set_max_mem_pages(Smi::kMaxValue);
Handle<SeqOneByteString> empty_string = Handle<SeqOneByteString>::cast(
isolate_->factory()->NewStringFromOneByte({}).ToHandleChecked());
compiled_module->set_module_bytes(empty_string);
DCHECK(WasmCompiledModule::IsWasmCompiledModule(*compiled_module)); DCHECK(WasmCompiledModule::IsWasmCompiledModule(*compiled_module));
return WasmInstanceObject::New(isolate_, compiled_module); return WasmInstanceObject::New(isolate_, compiled_module);
} }
......
...@@ -60,8 +60,8 @@ const Handle<WasmInstanceObject> InstantiateModuleForTesting( ...@@ -60,8 +60,8 @@ const Handle<WasmInstanceObject> InstantiateModuleForTesting(
// TODO(wasm): Use {module} instead of decoding the module bytes again. // TODO(wasm): Use {module} instead of decoding the module bytes again.
MaybeHandle<WasmModuleObject> module_object = CreateModuleObjectFromBytes( MaybeHandle<WasmModuleObject> module_object = CreateModuleObjectFromBytes(
isolate, wire_bytes.module_bytes.start(), wire_bytes.module_bytes.end(), isolate, wire_bytes.module_bytes.start(), wire_bytes.module_bytes.end(),
thrower, ModuleOrigin::kWasmOrigin, Handle<Script>::null(), nullptr, thrower, ModuleOrigin::kWasmOrigin, Handle<Script>::null(),
nullptr); Vector<const byte>::empty());
if (module_object.is_null()) { if (module_object.is_null()) {
thrower->CompileError("Module pre-validation failed."); thrower->CompileError("Module pre-validation failed.");
return Handle<WasmInstanceObject>::null(); return Handle<WasmInstanceObject>::null();
......
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