| 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 253 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 264 Isolate* isolate, Handle<WasmTableObject> table_obj, | 264 Isolate* isolate, Handle<WasmTableObject> table_obj, |
| 265 Handle<WasmInstanceObject> instance, int table_index, | 265 Handle<WasmInstanceObject> instance, int table_index, |
| 266 Handle<FixedArray> function_table, Handle<FixedArray> signature_table) { | 266 Handle<FixedArray> function_table, Handle<FixedArray> signature_table) { |
| 267 Handle<FixedArray> dispatch_tables( | 267 Handle<FixedArray> dispatch_tables( |
| 268 FixedArray::cast(table_obj->GetEmbedderField(kDispatchTables)), isolate); | 268 FixedArray::cast(table_obj->GetEmbedderField(kDispatchTables)), isolate); |
| 269 DCHECK_EQ(0, dispatch_tables->length() % 4); | 269 DCHECK_EQ(0, dispatch_tables->length() % 4); |
| 270 | 270 |
| 271 if (instance.is_null()) return dispatch_tables; | 271 if (instance.is_null()) return dispatch_tables; |
| 272 // TODO(titzer): use weak cells here to avoid leaking instances. | 272 // TODO(titzer): use weak cells here to avoid leaking instances. |
| 273 | 273 |
| 274 // Grow the dispatch table and add a new triple at the end. | 274 // Grow the dispatch table and add a new entry at the end. |
| 275 Handle<FixedArray> new_dispatch_tables = | 275 Handle<FixedArray> new_dispatch_tables = |
| 276 isolate->factory()->CopyFixedArrayAndGrow(dispatch_tables, 4); | 276 isolate->factory()->CopyFixedArrayAndGrow(dispatch_tables, 4); |
| 277 | 277 |
| 278 new_dispatch_tables->set(dispatch_tables->length() + 0, *instance); | 278 new_dispatch_tables->set(dispatch_tables->length() + 0, *instance); |
| 279 new_dispatch_tables->set(dispatch_tables->length() + 1, | 279 new_dispatch_tables->set(dispatch_tables->length() + 1, |
| 280 Smi::FromInt(table_index)); | 280 Smi::FromInt(table_index)); |
| 281 new_dispatch_tables->set(dispatch_tables->length() + 2, *function_table); | 281 new_dispatch_tables->set(dispatch_tables->length() + 2, *function_table); |
| 282 new_dispatch_tables->set(dispatch_tables->length() + 3, *signature_table); | 282 new_dispatch_tables->set(dispatch_tables->length() + 3, *signature_table); |
| 283 | 283 |
| 284 table_obj->SetEmbedderField(WasmTableObject::kDispatchTables, | 284 table_obj->SetEmbedderField(WasmTableObject::kDispatchTables, |
| (...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 353 DCHECK_EQ(0, old_size % WasmModule::kPageSize); | 353 DCHECK_EQ(0, old_size % WasmModule::kPageSize); |
| 354 uint32_t old_pages = old_size / WasmModule::kPageSize; | 354 uint32_t old_pages = old_size / WasmModule::kPageSize; |
| 355 DCHECK_GE(std::numeric_limits<uint32_t>::max(), | 355 DCHECK_GE(std::numeric_limits<uint32_t>::max(), |
| 356 old_size + pages * WasmModule::kPageSize); | 356 old_size + pages * WasmModule::kPageSize); |
| 357 if (old_pages > max_pages || pages > max_pages - old_pages) { | 357 if (old_pages > max_pages || pages > max_pages - old_pages) { |
| 358 return Handle<JSArrayBuffer>::null(); | 358 return Handle<JSArrayBuffer>::null(); |
| 359 } | 359 } |
| 360 | 360 |
| 361 // TODO(gdeepti): Change the protection here instead of allocating a new | 361 // TODO(gdeepti): Change the protection here instead of allocating a new |
| 362 // buffer before guard regions are turned on, see issue #5886. | 362 // buffer before guard regions are turned on, see issue #5886. |
| 363 const bool enable_guard_regions = | 363 const bool enable_guard_regions = old_buffer.is_null() |
| 364 (old_buffer.is_null() && EnableGuardRegions()) || | 364 ? EnableGuardRegions() |
| 365 (!old_buffer.is_null() && old_buffer->has_guard_region()); | 365 : old_buffer->has_guard_region(); |
| 366 size_t new_size = | 366 size_t new_size = |
| 367 static_cast<size_t>(old_pages + pages) * WasmModule::kPageSize; | 367 static_cast<size_t>(old_pages + pages) * WasmModule::kPageSize; |
| 368 Handle<JSArrayBuffer> new_buffer = | 368 Handle<JSArrayBuffer> new_buffer = |
| 369 NewArrayBuffer(isolate, new_size, enable_guard_regions); | 369 NewArrayBuffer(isolate, new_size, enable_guard_regions); |
| 370 if (new_buffer.is_null()) return new_buffer; | 370 if (new_buffer.is_null()) return new_buffer; |
| 371 Address new_mem_start = static_cast<Address>(new_buffer->backing_store()); | 371 Address new_mem_start = static_cast<Address>(new_buffer->backing_store()); |
| 372 memcpy(new_mem_start, old_mem_start, old_size); | 372 memcpy(new_mem_start, old_mem_start, old_size); |
| 373 return new_buffer; | 373 return new_buffer; |
| 374 } | 374 } |
| 375 | 375 |
| (...skipping 1214 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1590 if (!array->get(kWrapperInstanceObject)->IsWeakCell()) return false; | 1590 if (!array->get(kWrapperInstanceObject)->IsWeakCell()) return false; |
| 1591 Isolate* isolate = array->GetIsolate(); | 1591 Isolate* isolate = array->GetIsolate(); |
| 1592 if (!array->get(kNextInstanceWrapper)->IsUndefined(isolate) && | 1592 if (!array->get(kNextInstanceWrapper)->IsUndefined(isolate) && |
| 1593 !array->get(kNextInstanceWrapper)->IsFixedArray()) | 1593 !array->get(kNextInstanceWrapper)->IsFixedArray()) |
| 1594 return false; | 1594 return false; |
| 1595 if (!array->get(kPreviousInstanceWrapper)->IsUndefined(isolate) && | 1595 if (!array->get(kPreviousInstanceWrapper)->IsUndefined(isolate) && |
| 1596 !array->get(kPreviousInstanceWrapper)->IsFixedArray()) | 1596 !array->get(kPreviousInstanceWrapper)->IsFixedArray()) |
| 1597 return false; | 1597 return false; |
| 1598 return true; | 1598 return true; |
| 1599 } | 1599 } |
| OLD | NEW |