| OLD | NEW |
| 1 // Copyright 2015 the V8 project authors. All rights reserved. | 1 // Copyright 2015 the V8 project authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "src/wasm/wasm-objects.h" | 5 #include "src/wasm/wasm-objects.h" |
| 6 #include "src/utils.h" | 6 #include "src/utils.h" |
| 7 | 7 |
| 8 #include "src/assembler-inl.h" | 8 #include "src/assembler-inl.h" |
| 9 #include "src/base/iterator.h" | 9 #include "src/base/iterator.h" |
| 10 #include "src/compiler/wasm-compiler.h" | 10 #include "src/compiler/wasm-compiler.h" |
| (...skipping 241 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 252 Handle<Object> max = isolate->factory()->NewNumber(maximum); | 252 Handle<Object> max = isolate->factory()->NewNumber(maximum); |
| 253 table_obj->SetEmbedderField(kMaximum, *max); | 253 table_obj->SetEmbedderField(kMaximum, *max); |
| 254 | 254 |
| 255 Handle<FixedArray> dispatch_tables = isolate->factory()->NewFixedArray(0); | 255 Handle<FixedArray> dispatch_tables = isolate->factory()->NewFixedArray(0); |
| 256 table_obj->SetEmbedderField(kDispatchTables, *dispatch_tables); | 256 table_obj->SetEmbedderField(kDispatchTables, *dispatch_tables); |
| 257 Handle<Symbol> table_sym(isolate->native_context()->wasm_table_sym()); | 257 Handle<Symbol> table_sym(isolate->native_context()->wasm_table_sym()); |
| 258 Object::SetProperty(table_obj, table_sym, table_obj, STRICT).Check(); | 258 Object::SetProperty(table_obj, table_sym, table_obj, STRICT).Check(); |
| 259 return Handle<WasmTableObject>::cast(table_obj); | 259 return Handle<WasmTableObject>::cast(table_obj); |
| 260 } | 260 } |
| 261 | 261 |
| 262 DEFINE_OBJ_GETTER(WasmTableObject, dispatch_tables, kDispatchTables, FixedArray) | |
| 263 | |
| 264 Handle<FixedArray> WasmTableObject::AddDispatchTable( | 262 Handle<FixedArray> WasmTableObject::AddDispatchTable( |
| 265 Isolate* isolate, Handle<WasmTableObject> table_obj, | 263 Isolate* isolate, Handle<WasmTableObject> table_obj, |
| 266 Handle<WasmInstanceObject> instance, int table_index, | 264 Handle<WasmInstanceObject> instance, int table_index, |
| 267 Handle<FixedArray> function_table, Handle<FixedArray> signature_table) { | 265 Handle<FixedArray> function_table, Handle<FixedArray> signature_table) { |
| 268 Handle<FixedArray> dispatch_tables( | 266 Handle<FixedArray> dispatch_tables( |
| 269 FixedArray::cast(table_obj->GetEmbedderField(kDispatchTables)), isolate); | 267 FixedArray::cast(table_obj->GetEmbedderField(kDispatchTables)), isolate); |
| 270 DCHECK_EQ(0, dispatch_tables->length() % 4); | 268 DCHECK_EQ(0, dispatch_tables->length() % 4); |
| 271 | 269 |
| 272 if (instance.is_null()) return dispatch_tables; | 270 if (instance.is_null()) return dispatch_tables; |
| 273 // TODO(titzer): use weak cells here to avoid leaking instances. | 271 // TODO(titzer): use weak cells here to avoid leaking instances. |
| 274 | 272 |
| 275 // Grow the dispatch table and add a new triple at the end. | 273 // Grow the dispatch table and add a new triple at the end. |
| 276 Handle<FixedArray> new_dispatch_tables = | 274 Handle<FixedArray> new_dispatch_tables = |
| 277 isolate->factory()->CopyFixedArrayAndGrow(dispatch_tables, 4); | 275 isolate->factory()->CopyFixedArrayAndGrow(dispatch_tables, 4); |
| 278 | 276 |
| 279 new_dispatch_tables->set(dispatch_tables->length() + 0, *instance); | 277 new_dispatch_tables->set(dispatch_tables->length() + 0, *instance); |
| 280 new_dispatch_tables->set(dispatch_tables->length() + 1, | 278 new_dispatch_tables->set(dispatch_tables->length() + 1, |
| 281 Smi::FromInt(table_index)); | 279 Smi::FromInt(table_index)); |
| 282 new_dispatch_tables->set(dispatch_tables->length() + 2, *function_table); | 280 new_dispatch_tables->set(dispatch_tables->length() + 2, *function_table); |
| 283 new_dispatch_tables->set(dispatch_tables->length() + 3, *signature_table); | 281 new_dispatch_tables->set(dispatch_tables->length() + 3, *signature_table); |
| 284 | 282 |
| 285 table_obj->SetEmbedderField(WasmTableObject::kDispatchTables, | 283 table_obj->SetEmbedderField(WasmTableObject::kDispatchTables, |
| 286 *new_dispatch_tables); | 284 *new_dispatch_tables); |
| 287 | 285 |
| 288 return new_dispatch_tables; | 286 return new_dispatch_tables; |
| 289 } | 287 } |
| 290 | 288 |
| 291 DEFINE_OBJ_ACCESSORS(WasmTableObject, functions, kFunctions, FixedArray) | 289 DEFINE_OBJ_ACCESSORS(WasmTableObject, functions, kFunctions, FixedArray) |
| 292 | 290 |
| 291 DEFINE_OBJ_GETTER(WasmTableObject, dispatch_tables, kDispatchTables, FixedArray) |
| 292 |
| 293 uint32_t WasmTableObject::current_length() { return functions()->length(); } | 293 uint32_t WasmTableObject::current_length() { return functions()->length(); } |
| 294 | 294 |
| 295 bool WasmTableObject::has_maximum_length() { | 295 bool WasmTableObject::has_maximum_length() { |
| 296 return GetEmbedderField(kMaximum)->Number() >= 0; | 296 return GetEmbedderField(kMaximum)->Number() >= 0; |
| 297 } | 297 } |
| 298 | 298 |
| 299 int64_t WasmTableObject::maximum_length() { | 299 int64_t WasmTableObject::maximum_length() { |
| 300 return static_cast<int64_t>(GetEmbedderField(kMaximum)->Number()); | 300 return static_cast<int64_t>(GetEmbedderField(kMaximum)->Number()); |
| 301 } | 301 } |
| 302 | 302 |
| 303 WasmTableObject* WasmTableObject::cast(Object* object) { | 303 WasmTableObject* WasmTableObject::cast(Object* object) { |
| 304 DCHECK(object && object->IsJSObject()); | 304 DCHECK(object && object->IsJSObject()); |
| 305 // TODO(titzer): brand check for WasmTableObject. | 305 // TODO(titzer): brand check for WasmTableObject. |
| 306 return reinterpret_cast<WasmTableObject*>(object); | 306 return reinterpret_cast<WasmTableObject*>(object); |
| 307 } | 307 } |
| 308 | 308 |
| 309 void WasmTableObject::Grow(Isolate* isolate, Handle<WasmTableObject> table, | 309 void WasmTableObject::grow(Isolate* isolate, uint32_t count) { |
| 310 uint32_t count) { | 310 Handle<FixedArray> dispatch_tables( |
| 311 Handle<FixedArray> dispatch_tables(table->dispatch_tables()); | 311 FixedArray::cast(GetEmbedderField(kDispatchTables))); |
| 312 wasm::GrowDispatchTables(isolate, dispatch_tables, | 312 DCHECK_EQ(0, dispatch_tables->length() % 4); |
| 313 table->functions()->length(), count); | 313 uint32_t old_size = functions()->length(); |
| 314 |
| 315 Zone specialization_zone(isolate->allocator(), ZONE_NAME); |
| 316 for (int i = 0; i < dispatch_tables->length(); i += 4) { |
| 317 Handle<FixedArray> old_function_table( |
| 318 FixedArray::cast(dispatch_tables->get(i + 2))); |
| 319 Handle<FixedArray> old_signature_table( |
| 320 FixedArray::cast(dispatch_tables->get(i + 3))); |
| 321 Handle<FixedArray> new_function_table = |
| 322 isolate->factory()->CopyFixedArrayAndGrow(old_function_table, count); |
| 323 Handle<FixedArray> new_signature_table = |
| 324 isolate->factory()->CopyFixedArrayAndGrow(old_signature_table, count); |
| 325 |
| 326 // Update dispatch tables with new function/signature tables |
| 327 dispatch_tables->set(i + 2, *new_function_table); |
| 328 dispatch_tables->set(i + 3, *new_signature_table); |
| 329 |
| 330 // Patch the code of the respective instance. |
| 331 CodeSpecialization code_specialization(isolate, &specialization_zone); |
| 332 code_specialization.PatchTableSize(old_size, old_size + count); |
| 333 code_specialization.RelocateObject(old_function_table, new_function_table); |
| 334 code_specialization.RelocateObject(old_signature_table, |
| 335 new_signature_table); |
| 336 code_specialization.ApplyToWholeInstance( |
| 337 WasmInstanceObject::cast(dispatch_tables->get(i))); |
| 338 } |
| 314 } | 339 } |
| 315 | 340 |
| 316 namespace { | 341 namespace { |
| 317 | 342 |
| 318 Handle<JSArrayBuffer> GrowMemoryBuffer(Isolate* isolate, | 343 Handle<JSArrayBuffer> GrowMemoryBuffer(Isolate* isolate, |
| 319 Handle<JSArrayBuffer> old_buffer, | 344 Handle<JSArrayBuffer> old_buffer, |
| 320 uint32_t pages, uint32_t max_pages) { | 345 uint32_t pages, uint32_t max_pages) { |
| 321 Address old_mem_start = nullptr; | 346 Address old_mem_start = nullptr; |
| 322 uint32_t old_size = 0; | 347 uint32_t old_size = 0; |
| 323 if (!old_buffer.is_null()) { | 348 if (!old_buffer.is_null()) { |
| (...skipping 1234 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1558 if (!array->get(kWrapperInstanceObject)->IsWeakCell()) return false; | 1583 if (!array->get(kWrapperInstanceObject)->IsWeakCell()) return false; |
| 1559 Isolate* isolate = array->GetIsolate(); | 1584 Isolate* isolate = array->GetIsolate(); |
| 1560 if (!array->get(kNextInstanceWrapper)->IsUndefined(isolate) && | 1585 if (!array->get(kNextInstanceWrapper)->IsUndefined(isolate) && |
| 1561 !array->get(kNextInstanceWrapper)->IsFixedArray()) | 1586 !array->get(kNextInstanceWrapper)->IsFixedArray()) |
| 1562 return false; | 1587 return false; |
| 1563 if (!array->get(kPreviousInstanceWrapper)->IsUndefined(isolate) && | 1588 if (!array->get(kPreviousInstanceWrapper)->IsUndefined(isolate) && |
| 1564 !array->get(kPreviousInstanceWrapper)->IsFixedArray()) | 1589 !array->get(kPreviousInstanceWrapper)->IsFixedArray()) |
| 1565 return false; | 1590 return false; |
| 1566 return true; | 1591 return true; |
| 1567 } | 1592 } |
| OLD | NEW |