Commit 77b7be0c authored by mtrofin's avatar mtrofin Committed by Commit bot

Revert of [wasm] further simplification of WasmCompiledModule (patchset #1...

Revert of [wasm] further simplification of WasmCompiledModule (patchset #1 id:1 of https://codereview.chromium.org/2381393002/ )

Reason for revert:
Failures on multiple bots (e.g. https://build.chromium.org/p/client.v8/builders/V8%20Mac%20GC%20Stress/builds/8887)

Original issue's description:
> [wasm] further simplification of WasmCompiledModule
>
> Calculate memory size from the available heap. This avoids
> the bugs due to some numbers being stored as objects (by-ref)
> and thus needing special handling when cloning.
>
> This leaves all the rest of the numbers as read-only.
>
> Further simplified by representing globals size as a Smi.
>
> BUG=
>
> Committed: https://crrev.com/7ced1bdc9df2315ccc07dd17c12736aebf40cb57
> Cr-Commit-Position: refs/heads/master@{#39923}

TBR=bradnelson@google.com,bradnelson@chromium.org
# Skipping CQ checks because original CL landed less than 1 days ago.
NOPRESUBMIT=true
NOTREECHECKS=true
NOTRY=true
BUG=

Review-Url: https://codereview.chromium.org/2385943002
Cr-Commit-Position: refs/heads/master@{#39924}
parent 7ced1bdc
...@@ -852,8 +852,7 @@ static void ResetCompiledModule(Isolate* isolate, JSObject* owner, ...@@ -852,8 +852,7 @@ static void ResetCompiledModule(Isolate* isolate, JSObject* owner,
WasmCompiledModule* compiled_module) { WasmCompiledModule* compiled_module) {
Object* undefined = *isolate->factory()->undefined_value(); Object* undefined = *isolate->factory()->undefined_value();
uint32_t old_mem_size = compiled_module->mem_size(); uint32_t old_mem_size = compiled_module->mem_size();
uint32_t default_mem_size = compiled_module->default_mem_size(); Object* mem_start = compiled_module->ptr_to_mem_start();
Object* mem_start = compiled_module->ptr_to_heap();
Address old_mem_address = nullptr; Address old_mem_address = nullptr;
Address globals_start = Address globals_start =
GetGlobalStartAddressFromCodeTemplate(undefined, owner); GetGlobalStartAddressFromCodeTemplate(undefined, owner);
...@@ -878,8 +877,8 @@ static void ResetCompiledModule(Isolate* isolate, JSObject* owner, ...@@ -878,8 +877,8 @@ static void ResetCompiledModule(Isolate* isolate, JSObject* owner,
RelocInfo::Mode mode = it.rinfo()->rmode(); RelocInfo::Mode mode = it.rinfo()->rmode();
if (RelocInfo::IsWasmMemoryReference(mode) || if (RelocInfo::IsWasmMemoryReference(mode) ||
RelocInfo::IsWasmMemorySizeReference(mode)) { RelocInfo::IsWasmMemorySizeReference(mode)) {
it.rinfo()->update_wasm_memory_reference( it.rinfo()->update_wasm_memory_reference(old_mem_address, nullptr,
old_mem_address, nullptr, old_mem_size, default_mem_size); old_mem_size, old_mem_size);
changed = true; changed = true;
} else { } else {
CHECK(RelocInfo::IsWasmGlobalReference(mode)); CHECK(RelocInfo::IsWasmGlobalReference(mode));
...@@ -894,7 +893,7 @@ static void ResetCompiledModule(Isolate* isolate, JSObject* owner, ...@@ -894,7 +893,7 @@ static void ResetCompiledModule(Isolate* isolate, JSObject* owner,
} }
} }
compiled_module->reset_weak_owning_instance(); compiled_module->reset_weak_owning_instance();
compiled_module->reset_heap(); compiled_module->reset_mem_start();
} }
static void InstanceFinalizer(const v8::WeakCallbackInfo<void>& data) { static void InstanceFinalizer(const v8::WeakCallbackInfo<void>& data) {
...@@ -1051,8 +1050,7 @@ MaybeHandle<WasmCompiledModule> WasmModule::CompileFunctions( ...@@ -1051,8 +1050,7 @@ MaybeHandle<WasmCompiledModule> WasmModule::CompileFunctions(
// and information needed at instantiation time. This object needs to be // and information needed at instantiation time. This object needs to be
// serializable. Instantiation may occur off a deserialized version of this // serializable. Instantiation may occur off a deserialized version of this
// object. // object.
Handle<WasmCompiledModule> ret = WasmCompiledModule::New( Handle<WasmCompiledModule> ret = WasmCompiledModule::New(isolate);
isolate, min_mem_pages, globals_size, mem_export, origin);
ret->set_code_table(code_table); ret->set_code_table(code_table);
if (!indirect_table.is_null()) { if (!indirect_table.is_null()) {
ret->set_indirect_function_tables(indirect_table.ToHandleChecked()); ret->set_indirect_function_tables(indirect_table.ToHandleChecked());
...@@ -1126,8 +1124,12 @@ MaybeHandle<WasmCompiledModule> WasmModule::CompileFunctions( ...@@ -1126,8 +1124,12 @@ MaybeHandle<WasmCompiledModule> WasmModule::CompileFunctions(
Handle<ByteArray> function_name_table = Handle<ByteArray> function_name_table =
BuildFunctionNamesTable(isolate, module_env.module); BuildFunctionNamesTable(isolate, module_env.module);
ret->set_function_names(function_name_table); ret->set_function_names(function_name_table);
ret->set_min_required_memory(min_mem_pages);
if (data_segments.size() > 0) SaveDataSegmentInfo(factory, this, ret); if (data_segments.size() > 0) SaveDataSegmentInfo(factory, this, ret);
DCHECK_EQ(ret->default_mem_size(), temp_instance.mem_size); ret->set_globals_size(globals_size);
ret->set_export_memory(mem_export);
ret->set_origin(origin);
ret->set_mem_size(temp_instance.mem_size);
return ret; return ret;
} }
...@@ -1247,6 +1249,7 @@ MaybeHandle<JSObject> WasmModule::Instantiate(Isolate* isolate, ...@@ -1247,6 +1249,7 @@ MaybeHandle<JSObject> WasmModule::Instantiate(Isolate* isolate,
UNREACHABLE(); UNREACHABLE();
} }
} }
compiled_module->set_mem_size(original->mem_size());
RecordStats(isolate, code_table); RecordStats(isolate, code_table);
} else { } else {
// There was no owner, so we can reuse the original. // There was no owner, so we can reuse the original.
...@@ -1270,7 +1273,7 @@ MaybeHandle<JSObject> WasmModule::Instantiate(Isolate* isolate, ...@@ -1270,7 +1273,7 @@ MaybeHandle<JSObject> WasmModule::Instantiate(Isolate* isolate,
MaybeHandle<JSArrayBuffer> old_memory; MaybeHandle<JSArrayBuffer> old_memory;
// TODO(titzer): handle imported memory properly. // TODO(titzer): handle imported memory properly.
uint32_t min_mem_pages = compiled_module->min_memory_pages(); uint32_t min_mem_pages = compiled_module->min_required_memory();
isolate->counters()->wasm_min_mem_pages_count()->AddSample(min_mem_pages); isolate->counters()->wasm_min_mem_pages_count()->AddSample(min_mem_pages);
// TODO(wasm): re-enable counter for max_mem_pages when we use that field. // TODO(wasm): re-enable counter for max_mem_pages when we use that field.
...@@ -1285,16 +1288,16 @@ MaybeHandle<JSObject> WasmModule::Instantiate(Isolate* isolate, ...@@ -1285,16 +1288,16 @@ MaybeHandle<JSObject> WasmModule::Instantiate(Isolate* isolate,
uint32_t mem_size = static_cast<uint32_t>(memory->byte_length()->Number()); uint32_t mem_size = static_cast<uint32_t>(memory->byte_length()->Number());
LoadDataSegments(compiled_module, mem_start, mem_size); LoadDataSegments(compiled_module, mem_start, mem_size);
uint32_t old_mem_size = compiled_module->has_heap() uint32_t old_mem_size = compiled_module->mem_size();
? compiled_module->mem_size()
: compiled_module->default_mem_size();
Address old_mem_start = Address old_mem_start =
compiled_module->has_heap() compiled_module->has_mem_start()
? static_cast<Address>(compiled_module->heap()->backing_store()) ? static_cast<Address>(
compiled_module->mem_start()->backing_store())
: nullptr; : nullptr;
RelocateInstanceCode(instance, old_mem_start, mem_start, old_mem_size, RelocateInstanceCode(instance, old_mem_start, mem_start, old_mem_size,
mem_size); mem_size);
compiled_module->set_heap(memory); compiled_module->set_mem_size(mem_size);
compiled_module->set_mem_start(memory);
} }
//-------------------------------------------------------------------------- //--------------------------------------------------------------------------
...@@ -1534,26 +1537,6 @@ MaybeHandle<JSObject> WasmModule::Instantiate(Isolate* isolate, ...@@ -1534,26 +1537,6 @@ MaybeHandle<JSObject> WasmModule::Instantiate(Isolate* isolate,
return instance; return instance;
} }
Handle<WasmCompiledModule> WasmCompiledModule::New(Isolate* isolate,
uint32_t min_memory_pages,
uint32_t globals_size,
bool export_memory,
ModuleOrigin origin) {
Handle<FixedArray> ret =
isolate->factory()->NewFixedArray(PropertyIndices::Count, TENURED);
// Globals size is expected to fit into an int without overflow. This is not
// supported by the spec at the moment, however, we don't support array
// buffer sizes over 1g, so, for now, we avoid alocating a HeapNumber for
// the globals size. The CHECK guards this assumption.
CHECK_GE(static_cast<int>(globals_size), 0);
ret->set(kID_min_memory_pages,
Smi::FromInt(static_cast<int>(min_memory_pages)));
ret->set(kID_globals_size, Smi::FromInt(static_cast<int>(globals_size)));
ret->set(kID_export_memory, Smi::FromInt(static_cast<int>(export_memory)));
ret->set(kID_origin, Smi::FromInt(static_cast<int>(origin)));
return handle(WasmCompiledModule::cast(*ret));
}
compiler::CallDescriptor* ModuleEnv::GetCallDescriptor(Zone* zone, compiler::CallDescriptor* ModuleEnv::GetCallDescriptor(Zone* zone,
uint32_t index) { uint32_t index) {
DCHECK(IsValidFunction(index)); DCHECK(IsValidFunction(index));
...@@ -1778,9 +1761,11 @@ void SetInstanceMemory(Handle<JSObject> instance, JSArrayBuffer* buffer) { ...@@ -1778,9 +1761,11 @@ void SetInstanceMemory(Handle<JSObject> instance, JSArrayBuffer* buffer) {
DisallowHeapAllocation no_gc; DisallowHeapAllocation no_gc;
DCHECK(IsWasmObject(*instance)); DCHECK(IsWasmObject(*instance));
instance->SetInternalField(kWasmMemArrayBuffer, buffer); instance->SetInternalField(kWasmMemArrayBuffer, buffer);
WasmCompiledModule* module = Object* module = instance->GetInternalField(kWasmCompiledModule);
WasmCompiledModule::cast(instance->GetInternalField(kWasmCompiledModule)); if (module->IsFixedArray()) {
module->set_ptr_to_heap(buffer); WasmCompiledModule::cast(module)->set_mem_size(
buffer->byte_length()->Number());
}
} }
namespace testing { namespace testing {
......
...@@ -374,6 +374,19 @@ class WasmCompiledModule : public FixedArray { ...@@ -374,6 +374,19 @@ class WasmCompiledModule : public FixedArray {
#define WCM_SMALL_NUMBER(TYPE, NAME) \ #define WCM_SMALL_NUMBER(TYPE, NAME) \
TYPE NAME() const { \ TYPE NAME() const { \
return static_cast<TYPE>(Smi::cast(get(kID_##NAME))->value()); \ return static_cast<TYPE>(Smi::cast(get(kID_##NAME))->value()); \
} \
\
void set_##NAME(TYPE value) { \
set(kID_##NAME, Smi::FromInt(static_cast<int>(value))); \
}
#define WCM_LARGE_NUMBER(TYPE, NAME) \
TYPE NAME() const { \
return static_cast<TYPE>(HeapNumber::cast(get(kID_##NAME))->value()); \
} \
\
void set_##NAME(TYPE value) { \
HeapNumber::cast(get(kID_##NAME))->set_value(static_cast<double>(value)); \
} }
#define WCM_WEAK_LINK(TYPE, NAME) \ #define WCM_WEAK_LINK(TYPE, NAME) \
...@@ -391,11 +404,12 @@ class WasmCompiledModule : public FixedArray { ...@@ -391,11 +404,12 @@ class WasmCompiledModule : public FixedArray {
MACRO(OBJECT, FixedArray, indirect_function_tables) \ MACRO(OBJECT, FixedArray, indirect_function_tables) \
MACRO(OBJECT, String, module_bytes) \ MACRO(OBJECT, String, module_bytes) \
MACRO(OBJECT, ByteArray, function_names) \ MACRO(OBJECT, ByteArray, function_names) \
MACRO(SMALL_NUMBER, uint32_t, min_memory_pages) \ MACRO(LARGE_NUMBER, uint32_t, min_required_memory) \
MACRO(OBJECT, FixedArray, data_segments_info) \ MACRO(OBJECT, FixedArray, data_segments_info) \
MACRO(OBJECT, ByteArray, data_segments) \ MACRO(OBJECT, ByteArray, data_segments) \
MACRO(SMALL_NUMBER, uint32_t, globals_size) \ MACRO(LARGE_NUMBER, uint32_t, globals_size) \
MACRO(OBJECT, JSArrayBuffer, heap) \ MACRO(LARGE_NUMBER, uint32_t, mem_size) \
MACRO(OBJECT, JSArrayBuffer, mem_start) \
MACRO(SMALL_NUMBER, bool, export_memory) \ MACRO(SMALL_NUMBER, bool, export_memory) \
MACRO(SMALL_NUMBER, ModuleOrigin, origin) \ MACRO(SMALL_NUMBER, ModuleOrigin, origin) \
MACRO(WEAK_LINK, WasmCompiledModule, next_instance) \ MACRO(WEAK_LINK, WasmCompiledModule, next_instance) \
...@@ -411,28 +425,34 @@ class WasmCompiledModule : public FixedArray { ...@@ -411,28 +425,34 @@ class WasmCompiledModule : public FixedArray {
}; };
public: public:
static Handle<WasmCompiledModule> New(Isolate* isolate, static Handle<WasmCompiledModule> New(Isolate* isolate) {
uint32_t min_memory_pages, Handle<FixedArray> ret =
uint32_t globals_size, isolate->factory()->NewFixedArray(PropertyIndices::Count, TENURED);
bool export_memory, Handle<HeapNumber> number;
ModuleOrigin origin); #define WCM_INIT_OBJECT(IGNORE1, IGNORE2)
#define WCM_INIT_WEAK_LINK(IGNORE1, IGNORE2)
#define WCM_INIT_SMALL_NUMBER(IGNORE1, IGNORE2)
#define WCM_INIT_LARGE_NUMBER(IGNORE, NAME) \
number = isolate->factory()->NewHeapNumber(0.0, MUTABLE, TENURED); \
ret->set(kID_##NAME, *number);
#define INITIALIZER(KIND, TYPE, NAME) WCM_INIT_##KIND(TYPE, NAME)
WCM_PROPERTY_TABLE(INITIALIZER)
#undef INITIALIZER
return handle(WasmCompiledModule::cast(*ret));
}
static Handle<WasmCompiledModule> Clone(Isolate* isolate, static Handle<WasmCompiledModule> Clone(Isolate* isolate,
Handle<WasmCompiledModule> module) { Handle<WasmCompiledModule> module) {
Handle<WasmCompiledModule> ret = Handle<WasmCompiledModule>::cast( Handle<WasmCompiledModule> ret = Handle<WasmCompiledModule>::cast(
isolate->factory()->CopyFixedArray(module)); isolate->factory()->CopyFixedArray(module));
Handle<HeapNumber> number =
isolate->factory()->NewHeapNumber(0.0, MUTABLE, TENURED);
ret->set(kID_mem_size, *number);
ret->set_mem_size(module->mem_size());
return ret; return ret;
} }
uint32_t mem_size() const {
DCHECK(has_heap());
return heap()->byte_length()->Number();
}
uint32_t default_mem_size() const {
return min_memory_pages() * WasmModule::kPageSize;
}
#define DECLARATION(KIND, TYPE, NAME) WCM_##KIND(TYPE, NAME) #define DECLARATION(KIND, TYPE, NAME) WCM_##KIND(TYPE, NAME)
WCM_PROPERTY_TABLE(DECLARATION) WCM_PROPERTY_TABLE(DECLARATION)
#undef DECLARATION #undef DECLARATION
......
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