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() {
i::Handle<i::JSObject>::cast(Utils::OpenHandle(this));
i::Handle<i::WasmCompiledModule> compiled_part =
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));
}
......@@ -7413,7 +7413,7 @@ MaybeLocal<WasmCompiledModule> WasmCompiledModule::Compile(Isolate* isolate,
i::wasm::CreateModuleObjectFromBytes(
i_isolate, start, start + length, &thrower,
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>();
return Local<WasmCompiledModule>::Cast(
Utils::ToLocal(maybe_compiled.ToHandleChecked()));
......
......@@ -179,13 +179,14 @@ MaybeHandle<FixedArray> AsmJs::CompileAsmViaWasm(CompilationInfo* info) {
wasm::ZoneBuffer* module = asm_wasm_result.module_bytes;
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;
compile_timer.Start();
MaybeHandle<JSObject> compiled = wasm::CreateModuleObjectFromBytes(
info->isolate(), module->begin(), module->end(), &thrower,
internal::wasm::kAsmJsOrigin, info->script(), asm_offsets->begin(),
asm_offsets->end());
internal::wasm::kAsmJsOrigin, info->script(), asm_offsets_vec);
DCHECK(!compiled.is_null());
double compile_time = compile_timer.Elapsed().InMillisecondsF();
......
......@@ -1535,7 +1535,7 @@ void WasmFrame::Print(StringStream* accumulator, PrintMode mode,
raw_func_name = STATIC_CHAR_VECTOR("<undefined>");
} else {
raw_func_name = WasmInstanceObject::cast(instance_or_undef)
->get_compiled_module()
->compiled_module()
->GetRawFunctionName(this->function_index());
}
const int kMaxPrintedFunctionName = 64;
......@@ -1578,9 +1578,9 @@ Script* WasmFrame::script() const {
int WasmFrame::position() const {
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(
WasmInstanceObject::cast(wasm_instance())->get_compiled_module(),
WasmInstanceObject::cast(wasm_instance())->compiled_module(),
isolate());
DCHECK_LE(0, position);
position = WasmCompiledModule::GetAsmJsSourcePosition(
......
......@@ -520,7 +520,7 @@ Handle<Object> Isolate::CaptureSimpleStackTrace(Handle<JSReceiver> error_object,
static_cast<int>(wasm_frame->pc() - code->instruction_start());
int flags = 0;
if (instance->get_compiled_module()->is_asm_js()) {
if (instance->compiled_module()->is_asm_js()) {
flags |= FrameArray::kIsAsmJsWasmFrame;
if (wasm_frame->at_to_number_conversion()) {
flags |= FrameArray::kAsmJsAtNumberConversion;
......@@ -705,7 +705,7 @@ class CaptureStackTraceHelper {
if (!function_key_.is_null()) {
Handle<WasmCompiledModule> compiled_module(
frame->wasm_instance()->get_compiled_module(), isolate_);
frame->wasm_instance()->compiled_module(), isolate_);
Handle<String> name = WasmCompiledModule::GetFunctionName(
isolate_, compiled_module, frame->function_index());
JSObject::AddProperty(stack_frame, function_key_, name, NONE);
......@@ -1559,7 +1559,7 @@ bool Isolate::ComputeLocationFromStackTrace(MessageLocation* target,
if (elements->IsWasmFrame(i) || elements->IsAsmJsWasmFrame(i)) {
Handle<WasmCompiledModule> compiled_module(
WasmInstanceObject::cast(elements->WasmInstance(i))
->get_compiled_module());
->compiled_module());
int func_index = elements->WasmFunctionIndex(i)->value();
int code_offset = elements->Offset(i)->value();
// TODO(wasm): Clean this up (bug 5007).
......@@ -1578,7 +1578,7 @@ bool Isolate::ComputeLocationFromStackTrace(MessageLocation* target,
// adding the function offset.
pos += compiled_module->GetFunctionOffset(func_index);
}
Handle<Script> script = compiled_module->script();
Handle<Script> script(compiled_module->script());
*target = MessageLocation(script, pos, pos + 1);
return true;
......
......@@ -657,7 +657,7 @@ Handle<Object> WasmStackFrame::GetFunction() const {
Handle<Object> WasmStackFrame::GetFunctionName() {
Handle<Object> name;
Handle<WasmCompiledModule> compiled_module(
Handle<WasmInstanceObject>::cast(wasm_instance_)->get_compiled_module(),
Handle<WasmInstanceObject>::cast(wasm_instance_)->compiled_module(),
isolate_);
if (!WasmCompiledModule::GetFunctionNameOrNull(isolate_, compiled_module,
wasm_func_index_)
......@@ -704,9 +704,9 @@ Handle<Object> WasmStackFrame::Null() const {
bool WasmStackFrame::HasScript() const { return true; }
Handle<Script> WasmStackFrame::GetScript() const {
return WasmInstanceObject::cast(*wasm_instance_)
->get_compiled_module()
->script();
return handle(
WasmInstanceObject::cast(*wasm_instance_)->compiled_module()->script(),
isolate_);
}
AsmJsWasmStackFrame::AsmJsWasmStackFrame() {}
......@@ -747,8 +747,7 @@ int AsmJsWasmStackFrame::GetPosition() const {
DCHECK_LE(0, offset_);
int byte_offset = code_->SourcePosition(offset_);
Handle<WasmCompiledModule> compiled_module(
WasmInstanceObject::cast(*wasm_instance_)->get_compiled_module(),
isolate_);
WasmInstanceObject::cast(*wasm_instance_)->compiled_module(), isolate_);
DCHECK_LE(0, byte_offset);
return WasmCompiledModule::GetAsmJsSourcePosition(
compiled_module, wasm_func_index_, static_cast<uint32_t>(byte_offset),
......
......@@ -527,7 +527,7 @@ RUNTIME_FUNCTION(Runtime_GetFrameDetails) {
// Add the function name.
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();
Handle<String> func_name = WasmCompiledModule::GetFunctionName(
isolate, compiled_module, func_index);
......
......@@ -742,7 +742,7 @@ RUNTIME_FUNCTION(Runtime_SerializeWasmModule) {
DCHECK(args.length() == 1);
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 =
WasmCompiledModuleSerializer::SerializeWasmModule(isolate, orig);
void* buff = isolate->array_buffer_allocator()->Allocate(data->length());
......
......@@ -231,7 +231,7 @@ std::unique_ptr<ScriptData> WasmCompiledModuleSerializer::SerializeWasmModule(
WasmCompiledModuleSerializer wasm_cs(isolate, 0);
wasm_cs.reference_map()->AddAttachedReference(*isolate->native_context());
wasm_cs.reference_map()->AddAttachedReference(
*compiled_module->module_bytes());
compiled_module->module_bytes());
ScriptData* data = wasm_cs.Serialize(compiled_module);
return std::unique_ptr<ScriptData>(data);
}
......@@ -268,10 +268,12 @@ MaybeHandle<FixedArray> WasmCompiledModuleSerializer::DeserializeWasmModule(
MaybeHandle<HeapObject> obj = deserializer.DeserializeObject(isolate);
if (obj.is_null() || !obj.ToHandleChecked()->IsFixedArray()) return nothing;
Handle<WasmCompiledModule> compiled_module =
Handle<WasmCompiledModule>::cast(obj.ToHandleChecked());
// Cast without type checks, as the module wrapper is not there yet.
Handle<WasmCompiledModule> compiled_module(
static_cast<WasmCompiledModule*>(*obj.ToHandleChecked()), isolate);
WasmCompiledModule::RecreateModuleWrapper(isolate, compiled_module);
DCHECK(WasmCompiledModule::IsWasmCompiledModule(*compiled_module));
return compiled_module;
}
......
......@@ -783,7 +783,7 @@ Maybe<bool> ValueSerializer::WriteWasmModule(Handle<JSObject> object) {
WriteTag(SerializationTag::kWasmModule);
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();
WriteVarint<uint32_t>(wire_bytes_length);
uint8_t* destination = ReserveRawBytes(wire_bytes_length);
......@@ -1554,8 +1554,8 @@ MaybeHandle<JSObject> ValueDeserializer::ReadWasmModule() {
wasm::ErrorThrower thrower(isolate_, "ValueDeserializer::ReadWasmModule");
return wasm::CreateModuleObjectFromBytes(
isolate_, wire_bytes.begin(), wire_bytes.end(), &thrower,
wasm::ModuleOrigin::kWasmOrigin, Handle<Script>::null(), nullptr,
nullptr);
wasm::ModuleOrigin::kWasmOrigin, Handle<Script>::null(),
Vector<const byte>::empty());
}
MaybeHandle<JSObject> ValueDeserializer::ReadHostObject() {
......
......@@ -13,33 +13,11 @@
using namespace v8::internal;
using namespace v8::internal::wasm;
namespace {
enum {
kWasmDebugInfoWasmObj,
kWasmDebugInfoWasmBytesHash,
kWasmDebugInfoAsmJsOffsets,
kWasmDebugInfoNumEntries
};
} // namespace
Handle<WasmDebugInfo> WasmDebugInfo::New(Handle<WasmInstanceObject> instance) {
Isolate *isolate = instance->GetIsolate();
Factory *factory = isolate->factory();
Handle<FixedArray> arr =
factory->NewFixedArray(kWasmDebugInfoNumEntries, TENURED);
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);
Handle<FixedArray> arr = factory->NewFixedArray(kFieldCount, TENURED);
arr->set(kInstance, *instance);
return Handle<WasmDebugInfo>::cast(arr);
}
......@@ -47,9 +25,7 @@ Handle<WasmDebugInfo> WasmDebugInfo::New(Handle<WasmInstanceObject> instance) {
bool WasmDebugInfo::IsDebugInfo(Object *object) {
if (!object->IsFixedArray()) return false;
FixedArray *arr = FixedArray::cast(object);
return arr->length() == kWasmDebugInfoNumEntries &&
IsWasmInstance(arr->get(kWasmDebugInfoWasmObj)) &&
arr->get(kWasmDebugInfoWasmBytesHash)->IsNumber();
return arr->length() == kFieldCount && IsWasmInstance(arr->get(kInstance));
}
WasmDebugInfo *WasmDebugInfo::cast(Object *object) {
......@@ -58,5 +34,5 @@ WasmDebugInfo *WasmDebugInfo::cast(Object *object) {
}
WasmInstanceObject *WasmDebugInfo::wasm_instance() {
return WasmInstanceObject::cast(get(kWasmDebugInfoWasmObj));
return WasmInstanceObject::cast(get(kInstance));
}
......@@ -92,7 +92,7 @@ static i::MaybeHandle<i::WasmModuleObject> CreateModuleObject(
DCHECK(source->IsArrayBuffer() || source->IsTypedArray());
return i::wasm::CreateModuleObjectFromBytes(
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,
......@@ -221,8 +221,7 @@ void WebAssemblyInstance(const v8::FunctionCallbackInfo<v8::Value>& args) {
i::Handle<i::Object> mem_obj = v8::Utils::OpenHandle(*obj);
if (i::WasmJs::IsWasmMemoryObject(i_isolate, mem_obj)) {
memory = i::Handle<i::JSArrayBuffer>(
i::Handle<i::WasmMemoryObject>::cast(mem_obj)->get_buffer(),
i_isolate);
i::Handle<i::WasmMemoryObject>::cast(mem_obj)->buffer(), i_isolate);
} else {
thrower.TypeError("Argument 2 must be a WebAssembly.Memory");
return;
......@@ -402,7 +401,7 @@ void WebAssemblyTableGrow(const v8::FunctionCallbackInfo<v8::Value>& args) {
i::Isolate* i_isolate = reinterpret_cast<i::Isolate*>(isolate);
auto receiver =
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();
int64_t new_size64 = 0;
if (args.Length() > 0 && !args[0]->IntegerValue(context).To(&new_size64)) {
......@@ -444,7 +443,7 @@ void WebAssemblyTableGet(const v8::FunctionCallbackInfo<v8::Value>& args) {
i::Isolate* i_isolate = reinterpret_cast<i::Isolate*>(isolate);
auto receiver =
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;
if (args.Length() > 0 && !args[0]->Int32Value(context).To(&i)) return;
v8::ReturnValue<v8::Value> return_value = args.GetReturnValue();
......@@ -488,7 +487,7 @@ void WebAssemblyTableSet(const v8::FunctionCallbackInfo<v8::Value>& args) {
auto receiver =
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;
if (!args[0]->Int32Value(context).To(&i)) return;
if (i < 0 || i >= array->length()) {
......@@ -498,7 +497,7 @@ void WebAssemblyTableSet(const v8::FunctionCallbackInfo<v8::Value>& args) {
return;
}
i::Handle<i::FixedArray> dispatch_tables(receiver->get_dispatch_tables(),
i::Handle<i::FixedArray> dispatch_tables(receiver->dispatch_tables(),
i_isolate);
if (value->IsNull(i_isolate)) {
i::wasm::UpdateDispatchTables(i_isolate, dispatch_tables, i,
......@@ -555,7 +554,7 @@ void WebAssemblyMemoryGetBuffer(
i::Isolate* i_isolate = reinterpret_cast<i::Isolate*>(isolate);
i::Handle<i::WasmMemoryObject> receiver =
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());
v8::ReturnValue<v8::Value> return_value = args.GetReturnValue();
return_value.Set(Utils::ToLocal(buffer));
......
......@@ -282,7 +282,7 @@ Address GetGlobalStartAddressFromCodeTemplate(Object* undefined,
Address old_address = nullptr;
if (instance->has_globals_buffer()) {
old_address =
static_cast<Address>(instance->get_globals_buffer()->backing_store());
static_cast<Address>(instance->globals_buffer()->backing_store());
}
return old_address;
}
......@@ -551,12 +551,12 @@ static void MemoryInstanceFinalizer(Isolate* isolate,
// If the memory object is destroyed, nothing needs to be done here.
if (!instance->has_memory_object()) return;
Handle<WasmInstanceWrapper> instance_wrapper =
handle(instance->get_instance_wrapper());
handle(instance->instance_wrapper());
DCHECK(WasmInstanceWrapper::IsWasmInstanceWrapper(*instance_wrapper));
DCHECK(instance_wrapper->has_instance());
bool has_prev = instance_wrapper->has_previous();
bool has_next = instance_wrapper->has_next();
Handle<WasmMemoryObject> memory_object(instance->get_memory_object());
Handle<WasmMemoryObject> memory_object(instance->memory_object());
if (!has_prev && !has_next) {
memory_object->ResetInstancesLink(isolate);
......@@ -592,10 +592,10 @@ static void InstanceFinalizer(const v8::WeakCallbackInfo<void>& data) {
JSObject** p = reinterpret_cast<JSObject**>(data.GetParameter());
WasmInstanceObject* owner = reinterpret_cast<WasmInstanceObject*>(*p);
Isolate* isolate = reinterpret_cast<Isolate*>(data.GetIsolate());
// Is a link to shared memory instances exists, update the list of memory
// If a link to shared memory instances exists, update the list of memory
// instances before the instance is destroyed.
if (owner->has_instance_wrapper()) MemoryInstanceFinalizer(isolate, owner);
WasmCompiledModule* compiled_module = owner->get_compiled_module();
WasmCompiledModule* compiled_module = owner->compiled_module();
TRACE("Finalizing %d {\n", compiled_module->instance_id());
DCHECK(compiled_module->has_weak_wasm_module());
WeakCell* weak_wasm_module = compiled_module->ptr_to_weak_wasm_module();
......@@ -670,6 +670,34 @@ std::pair<int, int> GetFunctionOffsetAndLength(
static_cast<int>(func.code_end_offset - func.code_start_offset)};
}
Handle<Script> CreateWasmScript(Isolate* isolate,
const ModuleWireBytes& wire_bytes) {
Handle<Script> script =
isolate->factory()->NewScript(isolate->factory()->empty_string());
script->set_type(Script::TYPE_WASM);
int hash = StringHasher::HashSequentialString(
reinterpret_cast<const char*>(wire_bytes.module_bytes.start()),
wire_bytes.module_bytes.length(), kZeroHashSeed);
const int kBufferSize = 50;
char buffer[kBufferSize];
int url_chars = SNPrintF(ArrayVector(buffer), "wasm://wasm/%08x", hash);
DCHECK(url_chars >= 0 && url_chars < kBufferSize);
MaybeHandle<String> url_str = isolate->factory()->NewStringFromOneByte(
Vector<const uint8_t>(reinterpret_cast<uint8_t*>(buffer), url_chars),
TENURED);
script->set_source_url(*url_str.ToHandleChecked());
int name_chars = SNPrintF(ArrayVector(buffer), "wasm-%08x", hash);
DCHECK(name_chars >= 0 && name_chars < kBufferSize);
MaybeHandle<String> name_str = isolate->factory()->NewStringFromOneByte(
Vector<const uint8_t>(reinterpret_cast<uint8_t*>(buffer), name_chars),
TENURED);
script->set_name(*name_str.ToHandleChecked());
return script;
}
} // namespace
Handle<JSArrayBuffer> wasm::NewArrayBuffer(Isolate* isolate, size_t size,
......@@ -804,7 +832,9 @@ WasmModule::WasmModule(Zone* owned)
MaybeHandle<WasmCompiledModule> WasmModule::CompileFunctions(
Isolate* isolate, Handle<WasmModuleWrapper> 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 {
Factory* factory = isolate->factory();
MaybeHandle<WasmCompiledModule> nothing;
......@@ -885,12 +915,40 @@ MaybeHandle<WasmCompiledModule> WasmModule::CompileFunctions(
}
}
// Create heap objects for script, module bytes and asm.js offset table to be
// stored in the shared module data.
Handle<Script> script;
Handle<ByteArray> asm_js_offset_table;
if (asm_js_script.is_null()) {
script = CreateWasmScript(isolate, wire_bytes);
} else {
script = asm_js_script;
asm_js_offset_table =
isolate->factory()->NewByteArray(asm_js_offset_table_bytes.length());
asm_js_offset_table->copy_in(0, asm_js_offset_table_bytes.start(),
asm_js_offset_table_bytes.length());
}
// TODO(wasm): only save the sections necessary to deserialize a
// {WasmModule}. E.g. function bodies could be omitted.
Handle<String> module_bytes =
factory->NewStringFromOneByte(wire_bytes.module_bytes, TENURED)
.ToHandleChecked();
DCHECK(module_bytes->IsSeqOneByteString());
// Create the shared module data.
// TODO(clemensh): For the same module (same bytes / same hash), we should
// only have one WasmSharedModuleData. Otherwise, we might only set
// breakpoints on a (potentially empty) subset of the instances.
Handle<WasmSharedModuleData> shared = WasmSharedModuleData::New(
isolate, module_wrapper, Handle<SeqOneByteString>::cast(module_bytes),
script, asm_js_offset_table);
// Create the compiled module object, and populate with compiled functions
// and information needed at instantiation time. This object needs to be
// serializable. Instantiation may occur off a deserialized version of this
// object.
Handle<WasmCompiledModule> ret =
WasmCompiledModule::New(isolate, module_wrapper);
Handle<WasmCompiledModule> ret = WasmCompiledModule::New(isolate, shared);
ret->set_code_table(code_table);
ret->set_min_mem_pages(min_mem_pages);
ret->set_max_mem_pages(max_mem_pages);
......@@ -899,6 +957,13 @@ MaybeHandle<WasmCompiledModule> WasmModule::CompileFunctions(
ret->set_empty_function_tables(function_tables);
}
// If we created a wasm script, finish it now and make it public to the
// debugger.
if (asm_js_script.is_null()) {
script->set_wasm_compiled_module(*ret);
isolate->debug()->OnAfterCompile(script);
}
// Compile JS->WASM wrappers for exported functions.
int func_index = 0;
for (auto exp : export_table) {
......@@ -913,16 +978,6 @@ MaybeHandle<WasmCompiledModule> WasmModule::CompileFunctions(
func_index++;
}
{
// TODO(wasm): only save the sections necessary to deserialize a
// {WasmModule}. E.g. function bodies could be omitted.
Handle<String> module_bytes_string =
factory->NewStringFromOneByte(wire_bytes.module_bytes, TENURED)
.ToHandleChecked();
DCHECK(module_bytes_string->IsSeqOneByteString());
ret->set_module_bytes(Handle<SeqOneByteString>::cast(module_bytes_string));
}
return ret;
}
......@@ -1114,9 +1169,7 @@ class WasmInstanceBuilder {
}
compiled_module_->set_code_table(code_table);
}
module_ = reinterpret_cast<WasmModuleWrapper*>(
*compiled_module_->module_wrapper())
->get();
module_ = compiled_module_->module();
//--------------------------------------------------------------------------
// Allocate the instance object.
......@@ -1236,7 +1289,7 @@ class WasmInstanceBuilder {
//--------------------------------------------------------------------------
DCHECK(wasm::IsWasmInstance(*instance));
if (instance->has_memory_object()) {
instance->get_memory_object()->AddInstance(isolate_, instance);
instance->memory_object()->AddInstance(isolate_, instance);
}
//--------------------------------------------------------------------------
......@@ -1300,7 +1353,7 @@ class WasmInstanceBuilder {
// we want all the publishing to happen free from GC interruptions, and
// so we do it in
// one GC-free scope afterwards.
original = handle(owner.ToHandleChecked()->get_compiled_module());
original = handle(owner.ToHandleChecked()->compiled_module());
link_to_original = factory->NewWeakCell(original.ToHandleChecked());
}
// Publish the new instance to the instances chain.
......@@ -1445,7 +1498,8 @@ class WasmInstanceBuilder {
// Load data segments into the memory.
void LoadDataSegments(Address mem_addr, size_t mem_size) {
Handle<SeqOneByteString> module_bytes = compiled_module_->module_bytes();
Handle<SeqOneByteString> module_bytes(compiled_module_->module_bytes(),
isolate_);
for (const WasmDataSegment& segment : module_->data_segments) {
uint32_t source_size = segment.source_size;
// Segments of size == 0 are just nops.
......@@ -1560,7 +1614,7 @@ class WasmInstanceBuilder {
TableInstance& table_instance = table_instances_[num_imported_tables];
table_instance.table_object = Handle<WasmTableObject>::cast(value);
table_instance.js_wrappers = Handle<FixedArray>(
table_instance.table_object->get_functions(), isolate_);
table_instance.table_object->functions(), isolate_);
// TODO(titzer): import table size must match exactly for now.
int table_size = table_instance.js_wrappers->length();
......@@ -1608,7 +1662,7 @@ class WasmInstanceBuilder {
auto memory = Handle<WasmMemoryObject>::cast(value);
DCHECK(WasmJs::IsWasmMemoryObject(isolate_, memory));
instance->set_memory_object(*memory);
memory_ = Handle<JSArrayBuffer>(memory->get_buffer(), isolate_);
memory_ = Handle<JSArrayBuffer>(memory->buffer(), isolate_);
break;
}
case kExternalGlobal: {
......@@ -1789,15 +1843,14 @@ class WasmInstanceBuilder {
Handle<WasmMemoryObject> memory_object;
if (!instance->has_memory_object()) {
// If there was no imported WebAssembly.Memory object, create one.
Handle<JSArrayBuffer> buffer(instance->get_memory_buffer(),
isolate_);
Handle<JSArrayBuffer> buffer(instance->memory_buffer(), isolate_);
memory_object = WasmMemoryObject::New(
isolate_, buffer,
(module_->max_mem_pages != 0) ? module_->max_mem_pages : -1);
instance->set_memory_object(*memory_object);
} else {
memory_object = Handle<WasmMemoryObject>(
instance->get_memory_object(), isolate_);
memory_object =
Handle<WasmMemoryObject>(instance->memory_object(), isolate_);
DCHECK(WasmJs::IsWasmMemoryObject(isolate_, memory_object));
memory_object->ResetInstancesLink(isolate_);
}
......@@ -1992,29 +2045,15 @@ bool wasm::IsWasmInstance(Object* object) {
Handle<Script> wasm::GetScript(Handle<JSObject> instance) {
WasmCompiledModule* compiled_module =
WasmInstanceObject::cast(*instance)->get_compiled_module();
DCHECK(compiled_module->has_script());
return compiled_module->script();
}
Handle<WasmDebugInfo> wasm::GetDebugInfo(Handle<JSObject> object) {
auto instance = Handle<WasmInstanceObject>::cast(object);
if (instance->has_debug_info()) {
Handle<WasmDebugInfo> info(instance->get_debug_info(),
instance->GetIsolate());
return info;
}
Handle<WasmDebugInfo> new_info = WasmDebugInfo::New(instance);
instance->set_debug_info(*new_info);
return new_info;
WasmInstanceObject::cast(*instance)->compiled_module();
return handle(compiled_module->script());
}
// TODO(clemensh): origin can be inferred from asm_js_script; remove it.
MaybeHandle<WasmModuleObject> wasm::CreateModuleObjectFromBytes(
Isolate* isolate, const byte* start, const byte* end, ErrorThrower* thrower,
ModuleOrigin origin, Handle<Script> asm_js_script,
const byte* asm_js_offset_tables_start,
const byte* asm_js_offset_tables_end) {
Vector<const byte> asm_js_offset_table_bytes) {
MaybeHandle<WasmModuleObject> nothing;
ModuleResult result = DecodeWasmModule(isolate, start, end, false, origin);
if (result.failed()) {
......@@ -2031,61 +2070,14 @@ MaybeHandle<WasmModuleObject> wasm::CreateModuleObjectFromBytes(
// Compile the functions of the module, producing a compiled module.
MaybeHandle<WasmCompiledModule> maybe_compiled_module =
result.val->CompileFunctions(isolate, module_wrapper, thrower,
ModuleWireBytes(start, end));
ModuleWireBytes(start, end), asm_js_script,
asm_js_offset_table_bytes);
if (maybe_compiled_module.is_null()) return nothing;
Handle<WasmCompiledModule> compiled_module =
maybe_compiled_module.ToHandleChecked();
DCHECK_EQ(origin == kAsmJsOrigin, !asm_js_script.is_null());
DCHECK(!compiled_module->has_script());
DCHECK(!compiled_module->has_asm_js_offset_table());
if (origin == kAsmJsOrigin) {
// Set script for the asm.js source, and the offset table mapping wasm byte
// offsets to source positions.
compiled_module->set_script(asm_js_script);
size_t offset_table_len =
asm_js_offset_tables_end - asm_js_offset_tables_start;
DCHECK_GE(kMaxInt, offset_table_len);
Handle<ByteArray> offset_table =
isolate->factory()->NewByteArray(static_cast<int>(offset_table_len));
memcpy(offset_table->GetDataStartAddress(), asm_js_offset_tables_start,
offset_table_len);
compiled_module->set_asm_js_offset_table(offset_table);
} else {
// Create a new Script object representing this wasm module, store it in the
// compiled wasm module, and register it at the debugger.
Handle<Script> script =
isolate->factory()->NewScript(isolate->factory()->empty_string());
script->set_type(Script::TYPE_WASM);
DCHECK_GE(kMaxInt, end - start);
int hash = StringHasher::HashSequentialString(
reinterpret_cast<const char*>(start), static_cast<int>(end - start),
kZeroHashSeed);
const int kBufferSize = 50;
char buffer[kBufferSize];
int url_chars = SNPrintF(ArrayVector(buffer), "wasm://wasm/%08x", hash);
DCHECK(url_chars >= 0 && url_chars < kBufferSize);
MaybeHandle<String> url_str = isolate->factory()->NewStringFromOneByte(
Vector<const uint8_t>(reinterpret_cast<uint8_t*>(buffer), url_chars),
TENURED);
script->set_source_url(*url_str.ToHandleChecked());
int name_chars = SNPrintF(ArrayVector(buffer), "wasm-%08x", hash);
DCHECK(name_chars >= 0 && name_chars < kBufferSize);
MaybeHandle<String> name_str = isolate->factory()->NewStringFromOneByte(
Vector<const uint8_t>(reinterpret_cast<uint8_t*>(buffer), name_chars),
TENURED);
script->set_name(*name_str.ToHandleChecked());
script->set_wasm_compiled_module(*compiled_module);
compiled_module->set_script(script);
isolate->debug()->OnAfterCompile(script);
}
return WasmModuleObject::New(isolate, compiled_module);
}
......@@ -2105,7 +2097,7 @@ MaybeHandle<JSArrayBuffer> wasm::GetInstanceMemory(
Isolate* isolate, Handle<WasmInstanceObject> object) {
auto instance = Handle<WasmInstanceObject>::cast(object);
if (instance->has_memory_buffer()) {
return Handle<JSArrayBuffer>(instance->get_memory_buffer(), isolate);
return Handle<JSArrayBuffer>(instance->memory_buffer(), isolate);
}
return MaybeHandle<JSArrayBuffer>();
}
......@@ -2114,7 +2106,7 @@ void SetInstanceMemory(Handle<WasmInstanceObject> instance,
JSArrayBuffer* buffer) {
DisallowHeapAllocation no_gc;
instance->set_memory_buffer(buffer);
instance->get_compiled_module()->set_ptr_to_memory(buffer);
instance->compiled_module()->set_ptr_to_memory(buffer);
}
int32_t wasm::GetInstanceMemorySize(Isolate* isolate,
......@@ -2133,14 +2125,12 @@ int32_t wasm::GetInstanceMemorySize(Isolate* isolate,
uint32_t GetMaxInstanceMemorySize(Isolate* isolate,
Handle<WasmInstanceObject> instance) {
if (instance->has_memory_object()) {
Handle<WasmMemoryObject> memory_object(instance->get_memory_object(),
isolate);
Handle<WasmMemoryObject> memory_object(instance->memory_object(), isolate);
int maximum = memory_object->maximum_pages();
if (maximum > 0) return static_cast<uint32_t>(maximum);
}
uint32_t compiled_max_pages =
instance->get_compiled_module()->max_mem_pages();
uint32_t compiled_max_pages = instance->compiled_module()->max_mem_pages();
isolate->counters()->wasm_max_mem_pages_count()->AddSample(
compiled_max_pages);
if (compiled_max_pages != 0) return compiled_max_pages;
......@@ -2193,12 +2183,12 @@ void UncheckedUpdateInstanceMemory(Isolate* isolate,
Handle<WasmInstanceObject> instance,
Address old_mem_start, uint32_t old_size) {
DCHECK(instance->has_memory_buffer());
Handle<JSArrayBuffer> new_buffer(instance->get_memory_buffer());
Handle<JSArrayBuffer> new_buffer(instance->memory_buffer());
uint32_t new_size = new_buffer->byte_length()->Number();
DCHECK(new_size <= std::numeric_limits<uint32_t>::max());
Address new_mem_start = static_cast<Address>(new_buffer->backing_store());
DCHECK_NOT_NULL(new_mem_start);
Handle<FixedArray> code_table = instance->get_compiled_module()->code_table();
Handle<FixedArray> code_table = instance->compiled_module()->code_table();
RelocateMemoryReferencesInCode(code_table, old_mem_start, new_mem_start,
old_size, new_size);
}
......@@ -2208,8 +2198,7 @@ int32_t wasm::GrowWebAssemblyMemory(Isolate* isolate, Handle<Object> receiver,
DCHECK(WasmJs::IsWasmMemoryObject(isolate, receiver));
Handle<WasmMemoryObject> memory_object =
handle(WasmMemoryObject::cast(*receiver));
Handle<WasmInstanceWrapper> instance_wrapper(
memory_object->get_instances_link());
Handle<WasmInstanceWrapper> instance_wrapper(memory_object->instances_link());
DCHECK(WasmInstanceWrapper::IsWasmInstanceWrapper(*instance_wrapper));
DCHECK(instance_wrapper->has_instance());
Handle<WasmInstanceObject> instance = instance_wrapper->instance_object();
......@@ -2218,8 +2207,7 @@ int32_t wasm::GrowWebAssemblyMemory(Isolate* isolate, Handle<Object> receiver,
uint32_t max_pages = GetMaxInstanceMemorySize(isolate, instance);
// Grow memory object buffer and update instances associated with it.
MaybeHandle<JSArrayBuffer> memory_buffer =
handle(memory_object->get_buffer());
MaybeHandle<JSArrayBuffer> memory_buffer = handle(memory_object->buffer());
Handle<JSArrayBuffer> old_buffer;
uint32_t old_size = 0;
Address old_mem_start = nullptr;
......@@ -2273,8 +2261,8 @@ int32_t wasm::GrowMemory(Isolate* isolate, Handle<WasmInstanceObject> instance,
DCHECK(old_size % WasmModule::kPageSize == 0);
return (old_size / WasmModule::kPageSize);
} else {
return GrowWebAssemblyMemory(
isolate, handle(instance_obj->get_memory_object()), pages);
return GrowWebAssemblyMemory(isolate, handle(instance_obj->memory_object()),
pages);
}
}
......@@ -2283,7 +2271,7 @@ void testing::ValidateInstancesChain(Isolate* isolate,
int instance_count) {
CHECK_GE(instance_count, 0);
DisallowHeapAllocation no_gc;
WasmCompiledModule* compiled_module = module_obj->get_compiled_module();
WasmCompiledModule* compiled_module = module_obj->compiled_module();
CHECK_EQ(JSObject::cast(compiled_module->ptr_to_weak_wasm_module()->value()),
*module_obj);
Object* prev = nullptr;
......@@ -2307,7 +2295,7 @@ void testing::ValidateInstancesChain(Isolate* isolate,
void testing::ValidateModuleState(Isolate* isolate,
Handle<WasmModuleObject> module_obj) {
DisallowHeapAllocation no_gc;
WasmCompiledModule* compiled_module = module_obj->get_compiled_module();
WasmCompiledModule* compiled_module = module_obj->compiled_module();
CHECK(compiled_module->has_weak_wasm_module());
CHECK_EQ(compiled_module->ptr_to_weak_wasm_module()->value(), *module_obj);
CHECK(!compiled_module->has_weak_prev_instance());
......@@ -2318,7 +2306,7 @@ void testing::ValidateModuleState(Isolate* isolate,
void testing::ValidateOrphanedInstance(Isolate* isolate,
Handle<WasmInstanceObject> instance) {
DisallowHeapAllocation no_gc;
WasmCompiledModule* compiled_module = instance->get_compiled_module();
WasmCompiledModule* compiled_module = instance->compiled_module();
CHECK(compiled_module->has_weak_wasm_module());
CHECK(compiled_module->ptr_to_weak_wasm_module()->cleared());
}
......@@ -221,7 +221,9 @@ struct V8_EXPORT_PRIVATE WasmModule {
MaybeHandle<WasmCompiledModule> CompileFunctions(
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;
......@@ -392,7 +394,7 @@ Handle<Script> GetScript(Handle<JSObject> instance);
V8_EXPORT_PRIVATE MaybeHandle<WasmModuleObject> CreateModuleObjectFromBytes(
Isolate* isolate, const byte* start, const byte* end, ErrorThrower* thrower,
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,
const byte* end,
......
......@@ -23,29 +23,38 @@
using namespace v8::internal;
using namespace v8::internal::wasm;
#define DEFINE_ACCESSORS(Container, name, field, type) \
type* Container::get_##name() { \
return type::cast(GetInternalField(field)); \
} \
void Container::set_##name(type* value) { \
return SetInternalField(field, value); \
#define DEFINE_GETTER0(getter, Container, name, field, type) \
type* Container::name() { return type::cast(getter(field)); }
#define DEFINE_ACCESSORS0(getter, setter, Container, name, field, type) \
DEFINE_GETTER0(getter, Container, name, field, type) \
void Container::set_##name(type* value) { return setter(field, value); }
#define DEFINE_OPTIONAL_ACCESSORS0(getter, setter, Container, name, field, \
type) \
DEFINE_ACCESSORS0(getter, setter, Container, name, field, type) \
bool Container::has_##name() { \
return !getter(field)->IsUndefined(GetIsolate()); \
}
#define DEFINE_OPTIONAL_ACCESSORS(Container, name, field, type) \
bool Container::has_##name() { \
return !GetInternalField(field)->IsUndefined(GetIsolate()); \
} \
type* Container::get_##name() { \
return type::cast(GetInternalField(field)); \
} \
void Container::set_##name(type* value) { \
return SetInternalField(field, value); \
}
#define DEFINE_OBJ_GETTER(Container, name, field, type) \
DEFINE_GETTER0(GetInternalField, Container, name, field, type)
#define DEFINE_OBJ_ACCESSORS(Container, name, field, type) \
DEFINE_ACCESSORS0(GetInternalField, SetInternalField, Container, name, \
field, type)
#define DEFINE_OPTIONAL_OBJ_ACCESSORS(Container, name, field, type) \
DEFINE_OPTIONAL_ACCESSORS0(GetInternalField, SetInternalField, Container, \
name, field, type)
#define DEFINE_ARR_GETTER(Container, name, field, type) \
DEFINE_GETTER0(get, Container, name, field, type)
#define DEFINE_ARR_ACCESSORS(Container, name, field, type) \
DEFINE_ACCESSORS0(get, set, Container, name, field, type)
#define DEFINE_OPTIONAL_ARR_ACCESSORS(Container, name, field, type) \
DEFINE_OPTIONAL_ACCESSORS0(get, set, Container, name, field, type)
#define DEFINE_GETTER(Container, name, field, type) \
type* Container::get_##name() { return type::cast(GetInternalField(field)); }
namespace {
static uint32_t SafeUint32(Object* value) {
uint32_t SafeUint32(Object* value) {
if (value->IsSmi()) {
int32_t val = Smi::cast(value)->value();
CHECK_GE(val, 0);
......@@ -58,7 +67,7 @@ static uint32_t SafeUint32(Object* value) {
return static_cast<uint32_t>(num->value());
}
static int32_t SafeInt32(Object* value) {
int32_t SafeInt32(Object* value) {
if (value->IsSmi()) {
return Smi::cast(value)->value();
}
......@@ -69,6 +78,8 @@ static int32_t SafeInt32(Object* value) {
return static_cast<int32_t>(num->value());
}
} // namespace
Handle<WasmModuleObject> WasmModuleObject::New(
Isolate* isolate, Handle<WasmCompiledModule> compiled_module) {
ModuleOrigin origin = compiled_module->module()->origin;
......@@ -107,8 +118,8 @@ bool WasmModuleObject::IsWasmModuleObject(Object* object) {
JSObject::cast(object)->GetInternalFieldCount() == kFieldCount;
}
DEFINE_GETTER(WasmModuleObject, compiled_module, kCompiledModule,
WasmCompiledModule)
DEFINE_OBJ_GETTER(WasmModuleObject, compiled_module, kCompiledModule,
WasmCompiledModule)
Handle<WasmTableObject> WasmTableObject::New(Isolate* isolate, uint32_t initial,
uint32_t maximum,
......@@ -132,7 +143,7 @@ Handle<WasmTableObject> WasmTableObject::New(Isolate* isolate, uint32_t initial,
return Handle<WasmTableObject>::cast(table_obj);
}
DEFINE_GETTER(WasmTableObject, dispatch_tables, kDispatchTables, FixedArray)
DEFINE_OBJ_GETTER(WasmTableObject, dispatch_tables, kDispatchTables, FixedArray)
Handle<FixedArray> WasmTableObject::AddDispatchTable(
Isolate* isolate, Handle<WasmTableObject> table_obj,
......@@ -160,9 +171,9 @@ Handle<FixedArray> WasmTableObject::AddDispatchTable(
return new_dispatch_tables;
}
DEFINE_ACCESSORS(WasmTableObject, functions, kFunctions, FixedArray)
DEFINE_OBJ_ACCESSORS(WasmTableObject, functions, kFunctions, FixedArray)
uint32_t WasmTableObject::current_length() { return get_functions()->length(); }
uint32_t WasmTableObject::current_length() { return functions()->length(); }
uint32_t WasmTableObject::maximum_length() {
return SafeUint32(GetInternalField(kMaximum));
......@@ -189,12 +200,12 @@ Handle<WasmMemoryObject> WasmMemoryObject::New(Isolate* isolate,
return Handle<WasmMemoryObject>::cast(memory_obj);
}
DEFINE_ACCESSORS(WasmMemoryObject, buffer, kArrayBuffer, JSArrayBuffer)
DEFINE_OPTIONAL_ACCESSORS(WasmMemoryObject, instances_link, kInstancesLink,
WasmInstanceWrapper)
DEFINE_OBJ_ACCESSORS(WasmMemoryObject, buffer, kArrayBuffer, JSArrayBuffer)
DEFINE_OPTIONAL_OBJ_ACCESSORS(WasmMemoryObject, instances_link, kInstancesLink,
WasmInstanceWrapper)
uint32_t WasmMemoryObject::current_pages() {
return SafeUint32(get_buffer()->byte_length()) / wasm::WasmModule::kPageSize;
return SafeUint32(buffer()->byte_length()) / wasm::WasmModule::kPageSize;
}
int32_t WasmMemoryObject::maximum_pages() {
......@@ -210,9 +221,9 @@ WasmMemoryObject* WasmMemoryObject::cast(Object* object) {
void WasmMemoryObject::AddInstance(Isolate* isolate,
Handle<WasmInstanceObject> instance) {
Handle<WasmInstanceWrapper> instance_wrapper =
handle(instance->get_instance_wrapper());
handle(instance->instance_wrapper());
if (has_instances_link()) {
Handle<WasmInstanceWrapper> current_wrapper(get_instances_link());
Handle<WasmInstanceWrapper> current_wrapper(instances_link());
DCHECK(WasmInstanceWrapper::IsWasmInstanceWrapper(*current_wrapper));
DCHECK(!current_wrapper->has_previous());
instance_wrapper->set_next_wrapper(*current_wrapper);
......@@ -226,27 +237,31 @@ void WasmMemoryObject::ResetInstancesLink(Isolate* isolate) {
SetInternalField(kInstancesLink, *undefined);
}
DEFINE_ACCESSORS(WasmInstanceObject, compiled_module, kCompiledModule,
WasmCompiledModule)
DEFINE_OPTIONAL_ACCESSORS(WasmInstanceObject, globals_buffer,
kGlobalsArrayBuffer, JSArrayBuffer)
DEFINE_OPTIONAL_ACCESSORS(WasmInstanceObject, memory_buffer, kMemoryArrayBuffer,
JSArrayBuffer)
DEFINE_OPTIONAL_ACCESSORS(WasmInstanceObject, memory_object, kMemoryObject,
WasmMemoryObject)
DEFINE_OPTIONAL_ACCESSORS(WasmInstanceObject, debug_info, kDebugInfo,
WasmDebugInfo)
DEFINE_OPTIONAL_ACCESSORS(WasmInstanceObject, instance_wrapper,
kWasmMemInstanceWrapper, WasmInstanceWrapper)
DEFINE_OBJ_ACCESSORS(WasmInstanceObject, compiled_module, kCompiledModule,
WasmCompiledModule)
DEFINE_OPTIONAL_OBJ_ACCESSORS(WasmInstanceObject, globals_buffer,
kGlobalsArrayBuffer, JSArrayBuffer)
DEFINE_OPTIONAL_OBJ_ACCESSORS(WasmInstanceObject, memory_buffer,
kMemoryArrayBuffer, JSArrayBuffer)
DEFINE_OPTIONAL_OBJ_ACCESSORS(WasmInstanceObject, memory_object, kMemoryObject,
WasmMemoryObject)
DEFINE_OPTIONAL_OBJ_ACCESSORS(WasmInstanceObject, debug_info, kDebugInfo,
WasmDebugInfo)
DEFINE_OPTIONAL_OBJ_ACCESSORS(WasmInstanceObject, instance_wrapper,
kWasmMemInstanceWrapper, WasmInstanceWrapper)
WasmModuleObject* WasmInstanceObject::module_object() {
return WasmModuleObject::cast(*get_compiled_module()->wasm_module());
return *compiled_module()->wasm_module();
}
WasmModule* WasmInstanceObject::module() {
return reinterpret_cast<WasmModuleWrapper*>(
*get_compiled_module()->module_wrapper())
->get();
WasmModule* WasmInstanceObject::module() { return compiled_module()->module(); }
Handle<WasmDebugInfo> WasmInstanceObject::GetOrCreateDebugInfo(
Handle<WasmInstanceObject> instance) {
if (instance->has_debug_info()) return handle(instance->debug_info());
Handle<WasmDebugInfo> new_info = WasmDebugInfo::New(instance);
instance->set_debug_info(*new_info);
return new_info;
}
WasmInstanceObject* WasmInstanceObject::cast(Object* object) {
......@@ -255,7 +270,6 @@ WasmInstanceObject* WasmInstanceObject::cast(Object* object) {
}
bool WasmInstanceObject::IsWasmInstanceObject(Object* object) {
if (!object->IsObject()) return false;
if (!object->IsJSObject()) return false;
JSObject* obj = JSObject::cast(object);
......@@ -337,22 +351,107 @@ Handle<WasmExportedFunction> WasmExportedFunction::New(
return Handle<WasmExportedFunction>::cast(function);
}
bool WasmSharedModuleData::IsWasmSharedModuleData(Object* object) {
if (!object->IsFixedArray()) return false;
FixedArray* arr = FixedArray::cast(object);
if (arr->length() != kFieldCount) return false;
Isolate* isolate = arr->GetIsolate();
if (!arr->get(kModuleWrapper)->IsForeign()) return false;
if (!arr->get(kModuleBytes)->IsUndefined(isolate) &&
!arr->get(kModuleBytes)->IsSeqOneByteString())
return false;
if (!arr->get(kScript)->IsScript()) return false;
if (!arr->get(kAsmJsOffsetTable)->IsUndefined(isolate) &&
!arr->get(kAsmJsOffsetTable)->IsByteArray())
return false;
return true;
}
WasmSharedModuleData* WasmSharedModuleData::cast(Object* object) {
DCHECK(IsWasmSharedModuleData(object));
return reinterpret_cast<WasmSharedModuleData*>(object);
}
wasm::WasmModule* WasmSharedModuleData::module() {
return reinterpret_cast<WasmModuleWrapper*>(get(kModuleWrapper))->get();
}
DEFINE_OPTIONAL_ARR_ACCESSORS(WasmSharedModuleData, module_bytes, kModuleBytes,
SeqOneByteString);
DEFINE_ARR_GETTER(WasmSharedModuleData, script, kScript, Script);
DEFINE_OPTIONAL_ARR_ACCESSORS(WasmSharedModuleData, asm_js_offset_table,
kAsmJsOffsetTable, ByteArray);
Handle<WasmSharedModuleData> WasmSharedModuleData::New(
Isolate* isolate, Handle<Foreign> module_wrapper,
Handle<SeqOneByteString> module_bytes, Handle<Script> script,
Handle<ByteArray> asm_js_offset_table) {
Handle<FixedArray> arr =
isolate->factory()->NewFixedArray(kFieldCount, TENURED);
arr->set(kModuleWrapper, *module_wrapper);
if (!module_bytes.is_null()) {
arr->set(kModuleBytes, *module_bytes);
}
if (!script.is_null()) {
arr->set(kScript, *script);
}
if (!asm_js_offset_table.is_null()) {
arr->set(kAsmJsOffsetTable, *asm_js_offset_table);
}
DCHECK(WasmSharedModuleData::IsWasmSharedModuleData(*arr));
return Handle<WasmSharedModuleData>::cast(arr);
}
bool WasmSharedModuleData::is_asm_js() {
bool asm_js = module()->origin == wasm::ModuleOrigin::kAsmJsOrigin;
DCHECK_EQ(asm_js, script()->type() == Script::TYPE_NORMAL);
DCHECK_EQ(asm_js, has_asm_js_offset_table());
return asm_js;
}
void WasmSharedModuleData::RecreateModuleWrapper(
Isolate* isolate, Handle<WasmSharedModuleData> shared) {
DCHECK(shared->get(kModuleWrapper)->IsUndefined(isolate));
WasmModule* module = nullptr;
{
// We parse the module again directly from the module bytes, so
// the underlying storage must not be moved meanwhile.
DisallowHeapAllocation no_allocation;
SeqOneByteString* module_bytes = shared->module_bytes();
const byte* start =
reinterpret_cast<const byte*>(module_bytes->GetCharsAddress());
const byte* end = start + module_bytes->length();
// TODO(titzer): remember the module origin in the compiled_module
// For now, we assume serialized modules did not originate from asm.js.
ModuleResult result =
DecodeWasmModule(isolate, start, end, false, kWasmOrigin);
CHECK(result.ok());
CHECK_NOT_NULL(result.val);
module = const_cast<WasmModule*>(result.val);
}
Handle<WasmModuleWrapper> module_wrapper =
WasmModuleWrapper::New(isolate, module);
shared->set(kModuleWrapper, *module_wrapper);
DCHECK(WasmSharedModuleData::IsWasmSharedModuleData(*shared));
}
Handle<WasmCompiledModule> WasmCompiledModule::New(
Isolate* isolate, Handle<WasmModuleWrapper> module_wrapper) {
Isolate* isolate, Handle<WasmSharedModuleData> shared) {
Handle<FixedArray> ret =
isolate->factory()->NewFixedArray(PropertyIndices::Count, TENURED);
// WasmCompiledModule::cast would fail since module bytes are not set yet.
// WasmCompiledModule::cast would fail since fields are not set yet.
Handle<WasmCompiledModule> compiled_module(
reinterpret_cast<WasmCompiledModule*>(*ret), isolate);
compiled_module->InitId();
compiled_module->set_module_wrapper(module_wrapper);
compiled_module->set_shared(shared);
return compiled_module;
}
wasm::WasmModule* WasmCompiledModule::module() const {
return reinterpret_cast<WasmModuleWrapper*>(ptr_to_module_wrapper())->get();
}
void WasmCompiledModule::InitId() {
#if DEBUG
static uint32_t instance_id_counter = 0;
......@@ -365,7 +464,8 @@ MaybeHandle<String> WasmCompiledModule::ExtractUtf8StringFromModuleBytes(
Isolate* isolate, Handle<WasmCompiledModule> compiled_module,
uint32_t offset, uint32_t size) {
// TODO(wasm): cache strings from modules if it's a performance win.
Handle<SeqOneByteString> module_bytes = compiled_module->module_bytes();
Handle<SeqOneByteString> module_bytes(compiled_module->module_bytes(),
isolate);
DCHECK_GE(module_bytes->length(), offset);
DCHECK_GE(module_bytes->length() - offset, size);
Address raw = module_bytes->GetCharsAddress() + offset;
......@@ -382,14 +482,17 @@ bool WasmCompiledModule::IsWasmCompiledModule(Object* obj) {
FixedArray* arr = FixedArray::cast(obj);
if (arr->length() != PropertyIndices::Count) return false;
Isolate* isolate = arr->GetIsolate();
#define WCM_CHECK_SMALL_NUMBER(TYPE, NAME) \
if (!arr->get(kID_##NAME)->IsSmi()) return false;
#define WCM_CHECK_OBJECT_OR_WEAK(TYPE, NAME) \
if (!arr->get(kID_##NAME)->IsUndefined(isolate) && \
!arr->get(kID_##NAME)->Is##TYPE()) \
return false;
#define WCM_CHECK_OBJECT(TYPE, NAME) WCM_CHECK_OBJECT_OR_WEAK(TYPE, NAME)
#define WCM_CHECK_WEAK_LINK(TYPE, NAME) WCM_CHECK_OBJECT_OR_WEAK(WeakCell, NAME)
#define WCM_CHECK_TYPE(NAME, TYPE_CHECK) \
do { \
Object* obj = arr->get(kID_##NAME); \
if (!(TYPE_CHECK)) return false; \
} while (false);
#define WCM_CHECK_OBJECT(TYPE, NAME) \
WCM_CHECK_TYPE(NAME, obj->IsUndefined(isolate) || obj->Is##TYPE())
#define WCM_CHECK_WASM_OBJECT(TYPE, NAME) \
WCM_CHECK_TYPE(NAME, TYPE::Is##TYPE(obj))
#define WCM_CHECK_WEAK_LINK(TYPE, NAME) WCM_CHECK_OBJECT(WeakCell, NAME)
#define WCM_CHECK_SMALL_NUMBER(TYPE, NAME) WCM_CHECK_TYPE(NAME, obj->IsSmi())
#define WCM_CHECK(KIND, TYPE, NAME) WCM_CHECK_##KIND(TYPE, NAME)
WCM_PROPERTY_TABLE(WCM_CHECK)
#undef WCM_CHECK
......@@ -412,34 +515,17 @@ void WasmCompiledModule::PrintInstancesChain() {
#endif
}
void WasmCompiledModule::RecreateModuleWrapper(Isolate* isolate,
Handle<FixedArray> array) {
Handle<WasmCompiledModule> compiled_module(
reinterpret_cast<WasmCompiledModule*>(*array), isolate);
WasmModule* module = nullptr;
{
Handle<SeqOneByteString> module_bytes = compiled_module->module_bytes();
// We parse the module again directly from the module bytes, so
// the underlying storage must not be moved meanwhile.
DisallowHeapAllocation no_allocation;
const byte* start =
reinterpret_cast<const byte*>(module_bytes->GetCharsAddress());
const byte* end = start + module_bytes->length();
// TODO(titzer): remember the module origin in the compiled_module
// For now, we assume serialized modules did not originate from asm.js.
ModuleResult result =
DecodeWasmModule(isolate, start, end, false, kWasmOrigin);
CHECK(result.ok());
CHECK_NOT_NULL(result.val);
module = const_cast<WasmModule*>(result.val);
}
Handle<WasmModuleWrapper> module_wrapper =
WasmModuleWrapper::New(isolate, module);
compiled_module->set_module_wrapper(module_wrapper);
DCHECK(WasmCompiledModule::IsWasmCompiledModule(*compiled_module));
void WasmCompiledModule::RecreateModuleWrapper(
Isolate* isolate, Handle<WasmCompiledModule> compiled_module) {
// This method must only be called immediately after deserialization.
// At this point, no module wrapper exists, so the shared module data is
// incomplete.
Handle<WasmSharedModuleData> shared(
static_cast<WasmSharedModuleData*>(compiled_module->get(kID_shared)),
isolate);
DCHECK(!WasmSharedModuleData::IsWasmSharedModuleData(*shared));
WasmSharedModuleData::RecreateModuleWrapper(isolate, shared);
DCHECK(WasmSharedModuleData::IsWasmSharedModuleData(*shared));
}
uint32_t WasmCompiledModule::mem_size() const {
......@@ -472,21 +558,21 @@ Vector<const uint8_t> WasmCompiledModule::GetRawFunctionName(
uint32_t func_index) {
DCHECK_GT(module()->functions.size(), func_index);
WasmFunction& function = module()->functions[func_index];
SeqOneByteString* bytes = ptr_to_module_bytes();
SeqOneByteString* bytes = module_bytes();
DCHECK_GE(bytes->length(), function.name_offset);
DCHECK_GE(bytes->length() - function.name_offset, function.name_length);
return Vector<const uint8_t>(bytes->GetCharsAddress() + function.name_offset,
function.name_length);
}
int WasmCompiledModule::GetFunctionOffset(uint32_t func_index) const {
int WasmCompiledModule::GetFunctionOffset(uint32_t func_index) {
std::vector<WasmFunction>& functions = module()->functions;
if (static_cast<uint32_t>(func_index) >= functions.size()) return -1;
DCHECK_GE(kMaxInt, functions[func_index].code_start_offset);
return static_cast<int>(functions[func_index].code_start_offset);
}
int WasmCompiledModule::GetContainingFunction(uint32_t byte_offset) const {
int WasmCompiledModule::GetContainingFunction(uint32_t byte_offset) {
std::vector<WasmFunction>& functions = module()->functions;
// Binary search for a function containing the given position.
......@@ -536,8 +622,9 @@ enum AsmJsOffsetTableEntryLayout {
Handle<ByteArray> GetDecodedAsmJsOffsetTable(
Handle<WasmCompiledModule> compiled_module, Isolate* isolate) {
DCHECK(compiled_module->has_asm_js_offset_table());
Handle<ByteArray> offset_table = compiled_module->asm_js_offset_table();
DCHECK(compiled_module->is_asm_js());
Handle<ByteArray> offset_table(
compiled_module->shared()->asm_js_offset_table(), isolate);
// The last byte in the asm_js_offset_tables ByteArray tells whether it is
// still encoded (0) or decoded (1).
......@@ -574,7 +661,7 @@ Handle<ByteArray> GetDecodedAsmJsOffsetTable(
Handle<ByteArray> decoded_table =
isolate->factory()->NewByteArray(total_size, TENURED);
decoded_table->set(total_size - 1, AsmJsTableType::Decoded);
compiled_module->set_asm_js_offset_table(decoded_table);
compiled_module->shared()->set_asm_js_offset_table(*decoded_table);
int idx = 0;
std::vector<WasmFunction>& wasm_funs = compiled_module->module()->functions;
......@@ -597,6 +684,7 @@ Handle<ByteArray> GetDecodedAsmJsOffsetTable(
DCHECK_EQ(total_size, idx * kIntSize + 1);
return decoded_table;
}
} // namespace
int WasmCompiledModule::GetAsmJsSourcePosition(
......@@ -640,7 +728,7 @@ v8::debug::WasmDisassembly WasmCompiledModule::DisassembleFunction(
static_cast<uint32_t>(func_index) >= module()->functions.size())
return {};
SeqOneByteString* module_bytes_str = ptr_to_module_bytes();
SeqOneByteString* module_bytes_str = module_bytes();
Vector<const byte> module_bytes(module_bytes_str->GetChars(),
module_bytes_str->length());
......@@ -655,7 +743,7 @@ v8::debug::WasmDisassembly WasmCompiledModule::DisassembleFunction(
bool WasmCompiledModule::GetPossibleBreakpoints(
const v8::debug::Location& start, const v8::debug::Location& end,
std::vector<v8::debug::Location>* locations) const {
std::vector<v8::debug::Location>* locations) {
DisallowHeapAllocation no_gc;
std::vector<WasmFunction>& functions = module()->functions;
......@@ -700,7 +788,7 @@ bool WasmCompiledModule::GetPossibleBreakpoints(
AccountingAllocator alloc;
Zone tmp(&alloc, ZONE_NAME);
const byte* module_start = ptr_to_module_bytes()->GetChars();
const byte* module_start = module_bytes()->GetChars();
for (uint32_t func_idx = start_func_index; func_idx <= end_func_index;
++func_idx) {
......
......@@ -25,14 +25,15 @@ class WasmInstanceWrapper;
static bool Is##name(Object* object); \
static name* cast(Object* object)
#define DECLARE_GETTER(name, type) type* name()
#define DECLARE_ACCESSORS(name, type) \
type* get_##name(); \
void set_##name(type* value)
void set_##name(type* value); \
DECLARE_GETTER(name, type)
#define DECLARE_OPTIONAL_ACCESSORS(name, type) \
bool has_##name(); \
type* get_##name(); \
void set_##name(type* value)
DECLARE_ACCESSORS(name, type)
// Representation of a WebAssembly.Module JavaScript-level object.
class WasmModuleObject : public JSObject {
......@@ -42,7 +43,7 @@ class WasmModuleObject : public JSObject {
DECLARE_CASTS(WasmModuleObject);
WasmCompiledModule* get_compiled_module();
WasmCompiledModule* compiled_module();
static Handle<WasmModuleObject> New(
Isolate* isolate, Handle<WasmCompiledModule> compiled_module);
......@@ -57,7 +58,7 @@ class WasmTableObject : public JSObject {
DECLARE_CASTS(WasmTableObject);
DECLARE_ACCESSORS(functions, FixedArray);
FixedArray* get_dispatch_tables();
FixedArray* dispatch_tables();
uint32_t current_length();
uint32_t maximum_length();
......@@ -119,6 +120,11 @@ class WasmInstanceObject : public JSObject {
WasmModuleObject* module_object();
wasm::WasmModule* module();
// Get the debug info associated with the given wasm object.
// If no debug info exists yet, it is created automatically.
static Handle<WasmDebugInfo> GetOrCreateDebugInfo(
Handle<WasmInstanceObject> instance);
static Handle<WasmInstanceObject> New(
Isolate* isolate, Handle<WasmCompiledModule> compiled_module);
};
......@@ -140,6 +146,36 @@ class WasmExportedFunction : public JSFunction {
Handle<Code> export_wrapper);
};
// Information shared by all WasmCompiledModule objects for the same module.
class WasmSharedModuleData : public FixedArray {
enum Fields {
kModuleWrapper,
kModuleBytes,
kScript,
kAsmJsOffsetTable,
kFieldCount
};
public:
DECLARE_CASTS(WasmSharedModuleData);
DECLARE_GETTER(module, wasm::WasmModule);
DECLARE_OPTIONAL_ACCESSORS(module_bytes, SeqOneByteString);
DECLARE_GETTER(script, Script);
DECLARE_OPTIONAL_ACCESSORS(asm_js_offset_table, ByteArray);
static Handle<WasmSharedModuleData> New(
Isolate* isolate, Handle<Foreign> module_wrapper,
Handle<SeqOneByteString> module_bytes, Handle<Script> script,
Handle<ByteArray> asm_js_offset_table);
// Check whether this module was generated from asm.js source.
bool is_asm_js();
// Recreate the ModuleWrapper from the module bytes after deserialization.
static void RecreateModuleWrapper(Isolate*, Handle<WasmSharedModuleData>);
};
class WasmCompiledModule : public FixedArray {
public:
enum Fields { kFieldCount };
......@@ -149,7 +185,7 @@ class WasmCompiledModule : public FixedArray {
return reinterpret_cast<WasmCompiledModule*>(fixed_array);
}
#define WCM_OBJECT_OR_WEAK(TYPE, NAME, ID) \
#define WCM_OBJECT_OR_WEAK(TYPE, NAME, ID, TYPE_CHECK) \
Handle<TYPE> NAME() const { return handle(ptr_to_##NAME()); } \
\
MaybeHandle<TYPE> maybe_##NAME() const { \
......@@ -159,13 +195,13 @@ class WasmCompiledModule : public FixedArray {
\
TYPE* maybe_ptr_to_##NAME() const { \
Object* obj = get(ID); \
if (!obj->Is##TYPE()) return nullptr; \
if (!(TYPE_CHECK)) return nullptr; \
return TYPE::cast(obj); \
} \
\
TYPE* ptr_to_##NAME() const { \
Object* obj = get(ID); \
DCHECK(obj->Is##TYPE()); \
DCHECK(TYPE_CHECK); \
return TYPE::cast(obj); \
} \
\
......@@ -173,11 +209,18 @@ class WasmCompiledModule : public FixedArray {
\
void set_ptr_to_##NAME(TYPE* value) { set(ID, value); } \
\
bool has_##NAME() const { return get(ID)->Is##TYPE(); } \
bool has_##NAME() const { \
Object* obj = get(ID); \
return TYPE_CHECK; \
} \
\
void reset_##NAME() { set_undefined(ID); }
#define WCM_OBJECT(TYPE, NAME) WCM_OBJECT_OR_WEAK(TYPE, NAME, kID_##NAME)
#define WCM_OBJECT(TYPE, NAME) \
WCM_OBJECT_OR_WEAK(TYPE, NAME, kID_##NAME, obj->Is##TYPE())
#define WCM_WASM_OBJECT(TYPE, NAME) \
WCM_OBJECT_OR_WEAK(TYPE, NAME, kID_##NAME, TYPE::Is##TYPE(obj))
#define WCM_SMALL_NUMBER(TYPE, NAME) \
TYPE NAME() const { \
......@@ -185,21 +228,16 @@ class WasmCompiledModule : public FixedArray {
} \
void set_##NAME(TYPE value) { set(kID_##NAME, Smi::FromInt(value)); }
#define WCM_WEAK_LINK(TYPE, NAME) \
WCM_OBJECT_OR_WEAK(WeakCell, weak_##NAME, kID_##NAME); \
\
Handle<TYPE> NAME() const { \
return handle(TYPE::cast(weak_##NAME()->value())); \
#define WCM_WEAK_LINK(TYPE, NAME) \
WCM_OBJECT_OR_WEAK(WeakCell, weak_##NAME, kID_##NAME, obj->IsWeakCell()); \
\
Handle<TYPE> NAME() const { \
return handle(TYPE::cast(weak_##NAME()->value())); \
}
#define CORE_WCM_PROPERTY_TABLE(MACRO) \
MACRO(WASM_OBJECT, WasmSharedModuleData, shared) \
MACRO(OBJECT, FixedArray, code_table) \
MACRO(OBJECT, Foreign, module_wrapper) \
/* For debugging: */ \
MACRO(OBJECT, SeqOneByteString, module_bytes) \
MACRO(OBJECT, Script, script) \
MACRO(OBJECT, ByteArray, asm_js_offset_table) \
/* End of debugging stuff */ \
MACRO(OBJECT, FixedArray, function_tables) \
MACRO(OBJECT, FixedArray, empty_function_tables) \
MACRO(OBJECT, JSArrayBuffer, memory) \
......@@ -208,7 +246,7 @@ class WasmCompiledModule : public FixedArray {
MACRO(WEAK_LINK, WasmCompiledModule, next_instance) \
MACRO(WEAK_LINK, WasmCompiledModule, prev_instance) \
MACRO(WEAK_LINK, JSObject, owning_instance) \
MACRO(WEAK_LINK, JSObject, wasm_module)
MACRO(WEAK_LINK, WasmModuleObject, wasm_module)
#if DEBUG
#define DEBUG_ONLY_TABLE(MACRO) MACRO(SMALL_NUMBER, uint32_t, instance_id)
......@@ -229,8 +267,8 @@ class WasmCompiledModule : public FixedArray {
};
public:
static Handle<WasmCompiledModule> New(
Isolate* isolate, Handle<Managed<wasm::WasmModule>> module_wrapper);
static Handle<WasmCompiledModule> New(Isolate* isolate,
Handle<WasmSharedModuleData> shared);
static Handle<WasmCompiledModule> Clone(Isolate* isolate,
Handle<WasmCompiledModule> module) {
......@@ -246,21 +284,26 @@ class WasmCompiledModule : public FixedArray {
uint32_t mem_size() const;
uint32_t default_mem_size() const;
wasm::WasmModule* module() const;
#define DECLARATION(KIND, TYPE, NAME) WCM_##KIND(TYPE, NAME)
WCM_PROPERTY_TABLE(DECLARATION)
#undef DECLARATION
static bool IsWasmCompiledModule(Object* obj);
// Allow to call method on WasmSharedModuleData also on this object.
#define FORWARD_SHARED(type, name) \
type name() { return shared()->name(); }
FORWARD_SHARED(SeqOneByteString*, module_bytes)
FORWARD_SHARED(wasm::WasmModule*, module)
FORWARD_SHARED(Script*, script)
FORWARD_SHARED(bool, is_asm_js)
#undef FORWARD_SHARED
// Check whether this module wasm generated from asm.js source.
bool is_asm_js() const { return has_asm_js_offset_table(); }
static bool IsWasmCompiledModule(Object* obj);
void PrintInstancesChain();
// Recreate the ModuleWrapper from the module bytes after deserialization.
static void RecreateModuleWrapper(Isolate* isolate,
Handle<FixedArray> compiled_module);
Handle<WasmCompiledModule> compiled_module);
// Get the function name of the function identified by the given index.
// Returns a null handle if the function is unnamed or the name is not a valid
......@@ -285,12 +328,12 @@ class WasmCompiledModule : public FixedArray {
// Return the byte offset of the function identified by the given index.
// The offset will be relative to the start of the module bytes.
// Returns -1 if the function index is invalid.
int GetFunctionOffset(uint32_t func_index) const;
int GetFunctionOffset(uint32_t func_index);
// Returns the function containing the given byte offset.
// Returns -1 if the byte offset is not contained in any function of this
// module.
int GetContainingFunction(uint32_t byte_offset) const;
int GetContainingFunction(uint32_t byte_offset);
// Translate from byte offset in the module to function number and byte offset
// within that function, encoded as line and column in the position info.
......@@ -299,7 +342,7 @@ class WasmCompiledModule : public FixedArray {
// Get the asm.js source position from a byte offset.
// Must only be called if the associated wasm object was created from asm.js.
static int GetAsmJsSourcePosition(Handle<WasmCompiledModule> debug_info,
static int GetAsmJsSourcePosition(Handle<WasmCompiledModule> compiled_module,
uint32_t func_index, uint32_t byte_offset,
bool is_at_number_conversion);
......@@ -320,7 +363,7 @@ class WasmCompiledModule : public FixedArray {
// Get a list of all possible breakpoints within a given range of this module.
bool GetPossibleBreakpoints(const debug::Location& start,
const debug::Location& end,
std::vector<debug::Location>* locations) const;
std::vector<debug::Location>* locations);
private:
void InitId();
......@@ -329,16 +372,17 @@ class WasmCompiledModule : public FixedArray {
};
// TODO(clemensh): Extend this object for breakpoint support, or remove it.
// TODO(clemensh): Exclude this object from serialization.
class WasmDebugInfo : public FixedArray {
public:
enum class Fields { kFieldCount };
enum Fields { kInstance, kFieldCount };
static Handle<WasmDebugInfo> New(Handle<WasmInstanceObject> instance);
public:
static Handle<WasmDebugInfo> New(Handle<WasmInstanceObject>);
static bool IsDebugInfo(Object* object);
static WasmDebugInfo* cast(Object* object);
static bool IsDebugInfo(Object*);
static WasmDebugInfo* cast(Object*);
WasmInstanceObject* wasm_instance();
DECLARE_GETTER(wasm_instance, WasmInstanceObject);
};
class WasmInstanceWrapper : public FixedArray {
......
......@@ -317,7 +317,8 @@ class WasmSerializationTest {
MaybeHandle<WasmCompiledModule> compiled_module =
decoding_result.val->CompileFunctions(
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());
Handle<JSObject> module_obj = WasmModuleObject::New(
serialization_isolate, compiled_module.ToHandleChecked());
......
......@@ -59,13 +59,12 @@ TEST(CollectPossibleBreakpoints) {
Handle<WasmInstanceObject> instance = runner.module().instance_object();
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}});
CheckLocations(instance->get_compiled_module(), {0, 2}, {0, 4}, {{0, 2}});
CheckLocations(instance->get_compiled_module(), {0, 2}, {0, 5},
{{0, 2}, {0, 4}});
CheckLocations(instance->get_compiled_module(), {0, 6}, {0, 7}, {{0, 6}});
CheckLocations(instance->get_compiled_module(), {0, 6}, {1, 0}, {{0, 6}});
CheckLocations(instance->get_compiled_module(), {0, 7}, {1, 0}, {});
CheckLocationsFail(instance->get_compiled_module(), {0, 8}, {1, 0});
CheckLocations(instance->compiled_module(), {0, 2}, {0, 4}, {{0, 2}});
CheckLocations(instance->compiled_module(), {0, 2}, {0, 5}, {{0, 2}, {0, 4}});
CheckLocations(instance->compiled_module(), {0, 6}, {0, 7}, {{0, 6}});
CheckLocations(instance->compiled_module(), {0, 6}, {1, 0}, {{0, 6}});
CheckLocations(instance->compiled_module(), {0, 7}, {1, 0}, {});
CheckLocationsFail(instance->compiled_module(), {0, 8}, {1, 0});
}
......@@ -267,15 +267,16 @@ class TestingModule : public ModuleEnv {
}
uint32_t AddBytes(Vector<const byte> bytes) {
Handle<SeqOneByteString> old_bytes =
instance_object_->get_compiled_module()->module_bytes();
Handle<SeqOneByteString> old_bytes(
instance_object_->compiled_module()->module_bytes(), isolate_);
uint32_t old_size = static_cast<uint32_t>(old_bytes->length());
ScopedVector<byte> new_bytes(old_size + bytes.length());
memcpy(new_bytes.start(), old_bytes->GetChars(), old_size);
memcpy(new_bytes.start() + old_size, bytes.start(), bytes.length());
Handle<SeqOneByteString> new_bytes_str = Handle<SeqOneByteString>::cast(
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;
}
......@@ -308,18 +309,23 @@ class TestingModule : public ModuleEnv {
}
Handle<WasmInstanceObject> InitInstanceObject() {
Handle<SeqOneByteString> empty_string = Handle<SeqOneByteString>::cast(
isolate_->factory()->NewStringFromOneByte({}).ToHandleChecked());
Handle<Managed<wasm::WasmModule>> module_wrapper =
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 =
WasmCompiledModule::New(isolate_, module_wrapper);
WasmCompiledModule::New(isolate_, shared_module_data);
// Minimally initialize the compiled module such that IsWasmCompiledModule
// passes.
// If tests need more (correct) information, add it later.
compiled_module->set_min_mem_pages(0);
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));
return WasmInstanceObject::New(isolate_, compiled_module);
}
......
......@@ -60,8 +60,8 @@ const Handle<WasmInstanceObject> InstantiateModuleForTesting(
// TODO(wasm): Use {module} instead of decoding the module bytes again.
MaybeHandle<WasmModuleObject> module_object = CreateModuleObjectFromBytes(
isolate, wire_bytes.module_bytes.start(), wire_bytes.module_bytes.end(),
thrower, ModuleOrigin::kWasmOrigin, Handle<Script>::null(), nullptr,
nullptr);
thrower, ModuleOrigin::kWasmOrigin, Handle<Script>::null(),
Vector<const byte>::empty());
if (module_object.is_null()) {
thrower->CompileError("Module pre-validation failed.");
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