Commit fc5079d3 authored by gdeepti's avatar gdeepti Committed by Commit bot

[wasm] Move Table.Grow implementation to wasm-objects.cc, cleanup

BUG=v8:6325

R=bradnelson@chromium.org

Review-Url: https://codereview.chromium.org/2844163006
Cr-Commit-Position: refs/heads/master@{#45002}
parent 9ede481a
......@@ -609,8 +609,7 @@ void WebAssemblyTableGrow(const v8::FunctionCallbackInfo<v8::Value>& args) {
}
int new_size = static_cast<int>(new_size64);
i::WasmTableObject::Grow(i_isolate, receiver,
static_cast<uint32_t>(new_size - old_size));
receiver->grow(i_isolate, static_cast<uint32_t>(new_size - old_size));
if (new_size != old_size) {
i::Handle<i::FixedArray> new_array =
......
......@@ -2083,10 +2083,8 @@ class InstantiationHelper {
Handle<FixedArray> all_dispatch_tables;
if (!table_instance.table_object.is_null()) {
// Get the existing dispatch table(s) with the WebAssembly.Table object.
all_dispatch_tables = WasmTableObject::AddDispatchTable(
isolate_, table_instance.table_object,
Handle<WasmInstanceObject>::null(), index,
Handle<FixedArray>::null(), Handle<FixedArray>::null());
all_dispatch_tables =
handle(table_instance.table_object->dispatch_tables());
}
// Count the number of table exports for each function (needed for lazy
......@@ -2224,37 +2222,6 @@ void wasm::DetachWebAssemblyMemoryBuffer(Isolate* isolate,
}
}
void wasm::GrowDispatchTables(Isolate* isolate,
Handle<FixedArray> dispatch_tables,
uint32_t old_size, uint32_t count) {
DCHECK_EQ(0, dispatch_tables->length() % 4);
Zone specialization_zone(isolate->allocator(), ZONE_NAME);
for (int i = 0; i < dispatch_tables->length(); i += 4) {
Handle<FixedArray> old_function_table(
FixedArray::cast(dispatch_tables->get(i + 2)));
Handle<FixedArray> old_signature_table(
FixedArray::cast(dispatch_tables->get(i + 3)));
Handle<FixedArray> new_function_table =
isolate->factory()->CopyFixedArrayAndGrow(old_function_table, count);
Handle<FixedArray> new_signature_table =
isolate->factory()->CopyFixedArrayAndGrow(old_signature_table, count);
// Update dispatch tables with new function/signature tables
dispatch_tables->set(i + 2, *new_function_table);
dispatch_tables->set(i + 3, *new_signature_table);
// Patch the code of the respective instance.
CodeSpecialization code_specialization(isolate, &specialization_zone);
code_specialization.PatchTableSize(old_size, old_size + count);
code_specialization.RelocateObject(old_function_table, new_function_table);
code_specialization.RelocateObject(old_signature_table,
new_signature_table);
code_specialization.ApplyToWholeInstance(
WasmInstanceObject::cast(dispatch_tables->get(i)));
}
}
void testing::ValidateInstancesChain(Isolate* isolate,
Handle<WasmModuleObject> module_obj,
int instance_count) {
......
......@@ -443,9 +443,6 @@ void DetachWebAssemblyMemoryBuffer(Isolate* isolate,
void UpdateDispatchTables(Isolate* isolate, Handle<FixedArray> dispatch_tables,
int index, Handle<JSFunction> js_function);
void GrowDispatchTables(Isolate* isolate, Handle<FixedArray> dispatch_tables,
uint32_t old_size, uint32_t count);
//============================================================================
//== Compilation and instantiation ===========================================
//============================================================================
......
......@@ -259,8 +259,6 @@ Handle<WasmTableObject> WasmTableObject::New(Isolate* isolate, uint32_t initial,
return Handle<WasmTableObject>::cast(table_obj);
}
DEFINE_OBJ_GETTER(WasmTableObject, dispatch_tables, kDispatchTables, FixedArray)
Handle<FixedArray> WasmTableObject::AddDispatchTable(
Isolate* isolate, Handle<WasmTableObject> table_obj,
Handle<WasmInstanceObject> instance, int table_index,
......@@ -290,6 +288,8 @@ Handle<FixedArray> WasmTableObject::AddDispatchTable(
DEFINE_OBJ_ACCESSORS(WasmTableObject, functions, kFunctions, FixedArray)
DEFINE_OBJ_GETTER(WasmTableObject, dispatch_tables, kDispatchTables, FixedArray)
uint32_t WasmTableObject::current_length() { return functions()->length(); }
bool WasmTableObject::has_maximum_length() {
......@@ -306,11 +306,36 @@ WasmTableObject* WasmTableObject::cast(Object* object) {
return reinterpret_cast<WasmTableObject*>(object);
}
void WasmTableObject::Grow(Isolate* isolate, Handle<WasmTableObject> table,
uint32_t count) {
Handle<FixedArray> dispatch_tables(table->dispatch_tables());
wasm::GrowDispatchTables(isolate, dispatch_tables,
table->functions()->length(), count);
void WasmTableObject::grow(Isolate* isolate, uint32_t count) {
Handle<FixedArray> dispatch_tables(
FixedArray::cast(GetEmbedderField(kDispatchTables)));
DCHECK_EQ(0, dispatch_tables->length() % 4);
uint32_t old_size = functions()->length();
Zone specialization_zone(isolate->allocator(), ZONE_NAME);
for (int i = 0; i < dispatch_tables->length(); i += 4) {
Handle<FixedArray> old_function_table(
FixedArray::cast(dispatch_tables->get(i + 2)));
Handle<FixedArray> old_signature_table(
FixedArray::cast(dispatch_tables->get(i + 3)));
Handle<FixedArray> new_function_table =
isolate->factory()->CopyFixedArrayAndGrow(old_function_table, count);
Handle<FixedArray> new_signature_table =
isolate->factory()->CopyFixedArrayAndGrow(old_signature_table, count);
// Update dispatch tables with new function/signature tables
dispatch_tables->set(i + 2, *new_function_table);
dispatch_tables->set(i + 3, *new_signature_table);
// Patch the code of the respective instance.
CodeSpecialization code_specialization(isolate, &specialization_zone);
code_specialization.PatchTableSize(old_size, old_size + count);
code_specialization.RelocateObject(old_function_table, new_function_table);
code_specialization.RelocateObject(old_signature_table,
new_signature_table);
code_specialization.ApplyToWholeInstance(
WasmInstanceObject::cast(dispatch_tables->get(i)));
}
}
namespace {
......
......@@ -73,17 +73,16 @@ class WasmTableObject : public JSObject {
DECLARE_CASTS(WasmTableObject);
DECLARE_ACCESSORS(functions, FixedArray);
DECLARE_GETTER(dispatch_tables, FixedArray);
FixedArray* dispatch_tables();
uint32_t current_length();
bool has_maximum_length();
int64_t maximum_length(); // Returns < 0 if no maximum.
void grow(Isolate* isolate, uint32_t count);
static Handle<WasmTableObject> New(Isolate* isolate, uint32_t initial,
int64_t maximum,
Handle<FixedArray>* js_functions);
static void Grow(Isolate* isolate, Handle<WasmTableObject> table,
uint32_t count);
static Handle<FixedArray> AddDispatchTable(
Isolate* isolate, Handle<WasmTableObject> table,
Handle<WasmInstanceObject> instance, int table_index,
......
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