[wasm] Remove {memory_buffer} from WasmInstanceObject.

R=clemensh@chromium.org

Bug: 
Change-Id: I0c92aa07e10dcd1e9d9fd34dcaf23885076721b0
Reviewed-on: https://chromium-review.googlesource.com/735724
Commit-Queue: Ben Titzer <titzer@chromium.org>
Reviewed-by: Clemens Hammacher <clemensh@chromium.org>
Cr-Commit-Position: refs/heads/master@{#48922}
This commit is contained in:
Ben L. Titzer 2017-10-25 13:24:22 +02:00 committed by Commit Bot
parent 6d68788b88
commit 81e472631a
8 changed files with 22 additions and 28 deletions

View File

@ -1057,8 +1057,10 @@ RUNTIME_FUNCTION(Runtime_WasmTraceMemory) {
uint32_t addr = (static_cast<uint32_t>(addr_low) & 0xffff) |
(static_cast<uint32_t>(addr_high) << 16);
uint8_t* mem_start = reinterpret_cast<uint8_t*>(
frame->wasm_instance()->memory_buffer()->allocation_base());
uint8_t* mem_start = reinterpret_cast<uint8_t*>(frame->wasm_instance()
->memory_object()
->array_buffer()
->allocation_base());
int func_index = frame->function_index();
int pos = frame->position();
// TODO(titzer): eliminate dependency on WasmModule definition here.

View File

@ -1841,9 +1841,6 @@ MaybeHandle<WasmInstanceObject> InstanceBuilder::Build() {
mem_start = static_cast<Address>(memory->backing_store());
CHECK(memory->byte_length()->ToUint32(&mem_size));
LoadDataSegments(mem_start, mem_size);
// Just like with globals, we need to keep both the JSArrayBuffer
// and save the start pointer.
instance->set_memory_buffer(*memory);
}
//--------------------------------------------------------------------------
@ -1851,9 +1848,7 @@ MaybeHandle<WasmInstanceObject> InstanceBuilder::Build() {
//--------------------------------------------------------------------------
if (module_->has_memory && !instance->has_memory_object()) {
Handle<WasmMemoryObject> memory_object = WasmMemoryObject::New(
isolate_,
instance->has_memory_buffer() ? handle(instance->memory_buffer())
: Handle<JSArrayBuffer>::null(),
isolate_, memory_,
module_->maximum_pages != 0 ? module_->maximum_pages : -1);
instance->set_memory_object(*memory_object);
}

View File

@ -414,10 +414,11 @@ class InterpreterHandle {
// TODO(clemensh): Add globals to the global scope.
Handle<JSObject> global_scope_object =
isolate_->factory()->NewJSObjectWithNullProto();
if (instance->has_memory_buffer()) {
if (instance->has_memory_object()) {
Handle<String> name = isolate_->factory()->InternalizeOneByteString(
STATIC_CHAR_VECTOR("memory"));
Handle<JSArrayBuffer> memory_buffer(instance->memory_buffer(), isolate_);
Handle<JSArrayBuffer> memory_buffer(
instance->memory_object()->array_buffer(), isolate_);
uint32_t byte_length;
CHECK(memory_buffer->byte_length()->ToUint32(&byte_length));
Handle<JSTypedArray> uint8_array = isolate_->factory()->NewJSTypedArray(

View File

@ -48,8 +48,6 @@ ACCESSORS(WasmInstanceObject, compiled_module, WasmCompiledModule,
ACCESSORS(WasmInstanceObject, exports_object, JSObject, kExportsObjectOffset)
OPTIONAL_ACCESSORS(WasmInstanceObject, memory_object, WasmMemoryObject,
kMemoryObjectOffset)
OPTIONAL_ACCESSORS(WasmInstanceObject, memory_buffer, JSArrayBuffer,
kMemoryBufferOffset)
ACCESSORS(WasmInstanceObject, globals_buffer, JSArrayBuffer,
kGlobalsBufferOffset)
OPTIONAL_ACCESSORS(WasmInstanceObject, debug_info, WasmDebugInfo,

View File

@ -368,7 +368,6 @@ Handle<JSArrayBuffer> GrowMemoryBuffer(Isolate* isolate,
// May GC, because SetSpecializationMemInfoFrom may GC
void SetInstanceMemory(Isolate* isolate, Handle<WasmInstanceObject> instance,
Handle<JSArrayBuffer> buffer) {
instance->set_memory_buffer(*buffer);
auto wasm_context = instance->wasm_context()->get();
wasm_context->mem_start = reinterpret_cast<byte*>(buffer->backing_store());
wasm_context->mem_size = buffer->byte_length()->Number();
@ -385,19 +384,21 @@ void SetInstanceMemory(Isolate* isolate, Handle<WasmInstanceObject> instance,
} // namespace
Handle<WasmMemoryObject> WasmMemoryObject::New(Isolate* isolate,
Handle<JSArrayBuffer> buffer,
int32_t maximum) {
Handle<WasmMemoryObject> WasmMemoryObject::New(
Isolate* isolate, MaybeHandle<JSArrayBuffer> maybe_buffer,
int32_t maximum) {
Handle<JSFunction> memory_ctor(
isolate->native_context()->wasm_memory_constructor());
auto memory_obj = Handle<WasmMemoryObject>::cast(
isolate->factory()->NewJSObject(memory_ctor, TENURED));
if (buffer.is_null()) {
Handle<JSArrayBuffer> buffer;
if (maybe_buffer.is_null()) {
// If no buffer was provided, create a 0-length one.
buffer = wasm::SetupArrayBuffer(isolate, nullptr, 0, nullptr, 0, false,
trap_handler::UseTrapHandler());
} else {
buffer = maybe_buffer.ToHandleChecked();
// Paranoid check that the buffer size makes sense.
uint32_t mem_size = 0;
CHECK(buffer->byte_length()->ToUint32(&mem_size));
@ -532,8 +533,8 @@ Handle<WasmInstanceObject> WasmInstanceObject::New(
}
int32_t WasmInstanceObject::GetMemorySize() {
if (!has_memory_buffer()) return 0;
uint32_t bytes = memory_buffer()->byte_length()->Number();
if (!has_memory_object()) return 0;
uint32_t bytes = memory_object()->array_buffer()->byte_length()->Number();
DCHECK_EQ(0, bytes % WasmModule::kPageSize);
return bytes / WasmModule::kPageSize;
}

View File

@ -159,7 +159,7 @@ class WasmMemoryObject : public JSObject {
inline bool has_maximum_pages();
V8_EXPORT_PRIVATE static Handle<WasmMemoryObject> New(
Isolate* isolate, Handle<JSArrayBuffer> buffer, int32_t maximum);
Isolate* isolate, MaybeHandle<JSArrayBuffer> buffer, int32_t maximum);
static int32_t Grow(Isolate*, Handle<WasmMemoryObject>, uint32_t pages);
static void SetupNewBufferWithSameBackingStore(
@ -175,7 +175,6 @@ class WasmInstanceObject : public JSObject {
DECL_ACCESSORS(compiled_module, WasmCompiledModule)
DECL_ACCESSORS(exports_object, JSObject)
DECL_OPTIONAL_ACCESSORS(memory_object, WasmMemoryObject)
DECL_OPTIONAL_ACCESSORS(memory_buffer, JSArrayBuffer)
DECL_OPTIONAL_ACCESSORS(globals_buffer, JSArrayBuffer)
DECL_OPTIONAL_ACCESSORS(debug_info, WasmDebugInfo)
DECL_OPTIONAL_ACCESSORS(function_tables, FixedArray)
@ -190,7 +189,6 @@ class WasmInstanceObject : public JSObject {
kCompiledModuleIndex,
kExportsObjectIndex,
kMemoryObjectIndex,
kMemoryBufferIndex,
kGlobalsBufferIndex,
kDebugInfoIndex,
kFunctionTablesIndex,
@ -205,7 +203,6 @@ class WasmInstanceObject : public JSObject {
DEF_OFFSET(CompiledModule)
DEF_OFFSET(ExportsObject)
DEF_OFFSET(MemoryObject)
DEF_OFFSET(MemoryBuffer)
DEF_OFFSET(GlobalsBuffer)
DEF_OFFSET(DebugInfo)
DEF_OFFSET(FunctionTables)

View File

@ -693,7 +693,8 @@ TEST(TestInterruptLoop) {
{}, {})
.ToHandleChecked();
Handle<JSArrayBuffer> memory(instance->memory_buffer(), isolate);
Handle<JSArrayBuffer> memory(instance->memory_object()->array_buffer(),
isolate);
int32_t* memory_array = reinterpret_cast<int32_t*>(memory->backing_store());
InterruptThread thread(isolate, memory_array);
@ -1087,7 +1088,8 @@ TEST(Run_WasmModule_Buffer_Externalized_GrowMem) {
ModuleWireBytes(buffer.begin(), buffer.end()),
{}, {})
.ToHandleChecked();
Handle<JSArrayBuffer> memory(instance->memory_buffer(), isolate);
Handle<JSArrayBuffer> memory(instance->memory_object()->array_buffer(),
isolate);
Handle<WasmMemoryObject> mem_obj(instance->memory_object(), isolate);
void* const old_allocation_base = memory->allocation_base();
size_t const old_allocation_length = memory->allocation_length();
@ -1106,7 +1108,7 @@ TEST(Run_WasmModule_Buffer_Externalized_GrowMem) {
wasm::DetachMemoryBuffer(isolate, memory, free_memory);
CHECK_EQ(16, result);
memory = handle(mem_obj->array_buffer());
instance->set_memory_buffer(*memory);
instance->memory_object()->set_array_buffer(*memory);
// Externalize should make no difference without the JS API as in this case
// the buffer is not detached.
v8::Utils::ToLocal(memory)->Externalize();

View File

@ -37,7 +37,6 @@ byte* TestingModuleBuilder::AddMemory(uint32_t size) {
CHECK(!test_module_.has_memory);
CHECK_NULL(mem_start_);
CHECK_EQ(0, mem_size_);
DCHECK(!instance_object_->has_memory_buffer());
DCHECK(!instance_object_->has_memory_object());
test_module_.has_memory = true;
const bool enable_guard_regions =
@ -47,7 +46,6 @@ byte* TestingModuleBuilder::AddMemory(uint32_t size) {
Handle<JSArrayBuffer> new_buffer =
wasm::NewArrayBuffer(isolate_, alloc_size, enable_guard_regions);
CHECK(!new_buffer.is_null());
instance_object_->set_memory_buffer(*new_buffer);
mem_start_ = reinterpret_cast<byte*>(new_buffer->backing_store());
mem_size_ = size;
CHECK(size == 0 || mem_start_);