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 391 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
402 } // namespace | 402 } // namespace |
403 | 403 |
404 Handle<WasmMemoryObject> WasmMemoryObject::New(Isolate* isolate, | 404 Handle<WasmMemoryObject> WasmMemoryObject::New(Isolate* isolate, |
405 Handle<JSArrayBuffer> buffer, | 405 Handle<JSArrayBuffer> buffer, |
406 int32_t maximum) { | 406 int32_t maximum) { |
407 Handle<JSFunction> memory_ctor( | 407 Handle<JSFunction> memory_ctor( |
408 isolate->native_context()->wasm_memory_constructor()); | 408 isolate->native_context()->wasm_memory_constructor()); |
409 Handle<JSObject> memory_obj = | 409 Handle<JSObject> memory_obj = |
410 isolate->factory()->NewJSObject(memory_ctor, TENURED); | 410 isolate->factory()->NewJSObject(memory_ctor, TENURED); |
411 memory_obj->SetEmbedderField(kWrapperTracerHeader, Smi::kZero); | 411 memory_obj->SetEmbedderField(kWrapperTracerHeader, Smi::kZero); |
412 buffer.is_null() ? memory_obj->SetEmbedderField( | 412 if (buffer.is_null()) { |
413 kArrayBuffer, isolate->heap()->undefined_value()) | 413 const bool enable_guard_regions = EnableGuardRegions(); |
414 : memory_obj->SetEmbedderField(kArrayBuffer, *buffer); | 414 buffer = SetupArrayBuffer(isolate, nullptr, 0, nullptr, 0, false, |
| 415 enable_guard_regions); |
| 416 } |
| 417 memory_obj->SetEmbedderField(kArrayBuffer, *buffer); |
415 Handle<Object> max = isolate->factory()->NewNumber(maximum); | 418 Handle<Object> max = isolate->factory()->NewNumber(maximum); |
416 memory_obj->SetEmbedderField(kMaximum, *max); | 419 memory_obj->SetEmbedderField(kMaximum, *max); |
417 Handle<Symbol> memory_sym(isolate->native_context()->wasm_memory_sym()); | 420 Handle<Symbol> memory_sym(isolate->native_context()->wasm_memory_sym()); |
418 Object::SetProperty(memory_obj, memory_sym, memory_obj, STRICT).Check(); | 421 Object::SetProperty(memory_obj, memory_sym, memory_obj, STRICT).Check(); |
419 return Handle<WasmMemoryObject>::cast(memory_obj); | 422 return Handle<WasmMemoryObject>::cast(memory_obj); |
420 } | 423 } |
421 | 424 |
422 DEFINE_OPTIONAL_OBJ_ACCESSORS(WasmMemoryObject, buffer, kArrayBuffer, | 425 DEFINE_OBJ_ACCESSORS(WasmMemoryObject, buffer, kArrayBuffer, JSArrayBuffer) |
423 JSArrayBuffer) | |
424 DEFINE_OPTIONAL_OBJ_ACCESSORS(WasmMemoryObject, instances_link, kInstancesLink, | 426 DEFINE_OPTIONAL_OBJ_ACCESSORS(WasmMemoryObject, instances_link, kInstancesLink, |
425 WasmInstanceWrapper) | 427 WasmInstanceWrapper) |
426 | 428 |
427 uint32_t WasmMemoryObject::current_pages() { | 429 uint32_t WasmMemoryObject::current_pages() { |
428 uint32_t byte_length; | 430 uint32_t byte_length; |
429 CHECK(buffer()->byte_length()->ToUint32(&byte_length)); | 431 CHECK(buffer()->byte_length()->ToUint32(&byte_length)); |
430 return byte_length / wasm::WasmModule::kPageSize; | 432 return byte_length / wasm::WasmModule::kPageSize; |
431 } | 433 } |
432 | 434 |
433 bool WasmMemoryObject::has_maximum_pages() { | 435 bool WasmMemoryObject::has_maximum_pages() { |
(...skipping 26 matching lines...) Expand all Loading... |
460 | 462 |
461 void WasmMemoryObject::ResetInstancesLink(Isolate* isolate) { | 463 void WasmMemoryObject::ResetInstancesLink(Isolate* isolate) { |
462 Handle<Object> undefined = isolate->factory()->undefined_value(); | 464 Handle<Object> undefined = isolate->factory()->undefined_value(); |
463 SetEmbedderField(kInstancesLink, *undefined); | 465 SetEmbedderField(kInstancesLink, *undefined); |
464 } | 466 } |
465 | 467 |
466 // static | 468 // static |
467 int32_t WasmMemoryObject::Grow(Isolate* isolate, | 469 int32_t WasmMemoryObject::Grow(Isolate* isolate, |
468 Handle<WasmMemoryObject> memory_object, | 470 Handle<WasmMemoryObject> memory_object, |
469 uint32_t pages) { | 471 uint32_t pages) { |
470 Handle<JSArrayBuffer> old_buffer; | 472 Handle<JSArrayBuffer> old_buffer(memory_object->buffer()); |
471 uint32_t old_size = 0; | 473 uint32_t old_size = 0; |
472 Address old_mem_start = nullptr; | 474 CHECK(old_buffer->byte_length()->ToUint32(&old_size)); |
473 if (memory_object->has_buffer()) { | |
474 old_buffer = handle(memory_object->buffer()); | |
475 old_size = old_buffer->byte_length()->Number(); | |
476 old_mem_start = static_cast<Address>(old_buffer->backing_store()); | |
477 } | |
478 Handle<JSArrayBuffer> new_buffer; | 475 Handle<JSArrayBuffer> new_buffer; |
479 // Return current size if grow by 0. | 476 // Return current size if grow by 0. |
480 if (pages == 0) { | 477 if (pages == 0) { |
481 // Even for pages == 0, we need to attach a new JSArrayBuffer with the same | 478 // Even for pages == 0, we need to attach a new JSArrayBuffer with the same |
482 // backing store and neuter the old one to be spec compliant. | 479 // backing store and neuter the old one to be spec compliant. |
483 if (!old_buffer.is_null() && old_size != 0) { | 480 if (old_size != 0) { |
484 new_buffer = SetupArrayBuffer( | 481 new_buffer = SetupArrayBuffer( |
485 isolate, old_buffer->allocation_base(), | 482 isolate, old_buffer->allocation_base(), |
486 old_buffer->allocation_length(), old_buffer->backing_store(), | 483 old_buffer->allocation_length(), old_buffer->backing_store(), |
487 old_size, old_buffer->is_external(), old_buffer->has_guard_region()); | 484 old_size, old_buffer->is_external(), old_buffer->has_guard_region()); |
488 memory_object->set_buffer(*new_buffer); | 485 memory_object->set_buffer(*new_buffer); |
489 } | 486 } |
490 DCHECK_EQ(0, old_size % WasmModule::kPageSize); | 487 DCHECK_EQ(0, old_size % WasmModule::kPageSize); |
491 return old_size / WasmModule::kPageSize; | 488 return old_size / WasmModule::kPageSize; |
492 } | 489 } |
493 if (!memory_object->has_instances_link()) { | 490 if (!memory_object->has_instances_link()) { |
(...skipping 14 matching lines...) Expand all Loading... |
508 DCHECK(instance_wrapper->has_instance()); | 505 DCHECK(instance_wrapper->has_instance()); |
509 Handle<WasmInstanceObject> instance = instance_wrapper->instance_object(); | 506 Handle<WasmInstanceObject> instance = instance_wrapper->instance_object(); |
510 DCHECK(IsWasmInstance(*instance)); | 507 DCHECK(IsWasmInstance(*instance)); |
511 uint32_t max_pages = instance->GetMaxMemoryPages(); | 508 uint32_t max_pages = instance->GetMaxMemoryPages(); |
512 | 509 |
513 // Grow memory object buffer and update instances associated with it. | 510 // Grow memory object buffer and update instances associated with it. |
514 new_buffer = GrowMemoryBuffer(isolate, old_buffer, pages, max_pages); | 511 new_buffer = GrowMemoryBuffer(isolate, old_buffer, pages, max_pages); |
515 if (new_buffer.is_null()) return -1; | 512 if (new_buffer.is_null()) return -1; |
516 DCHECK(!instance_wrapper->has_previous()); | 513 DCHECK(!instance_wrapper->has_previous()); |
517 SetInstanceMemory(isolate, instance, new_buffer); | 514 SetInstanceMemory(isolate, instance, new_buffer); |
| 515 Address old_mem_start = static_cast<Address>(old_buffer->backing_store()); |
518 UncheckedUpdateInstanceMemory(isolate, instance, old_mem_start, old_size); | 516 UncheckedUpdateInstanceMemory(isolate, instance, old_mem_start, old_size); |
519 while (instance_wrapper->has_next()) { | 517 while (instance_wrapper->has_next()) { |
520 instance_wrapper = instance_wrapper->next_wrapper(); | 518 instance_wrapper = instance_wrapper->next_wrapper(); |
521 DCHECK(WasmInstanceWrapper::IsWasmInstanceWrapper(*instance_wrapper)); | 519 DCHECK(WasmInstanceWrapper::IsWasmInstanceWrapper(*instance_wrapper)); |
522 Handle<WasmInstanceObject> instance = instance_wrapper->instance_object(); | 520 Handle<WasmInstanceObject> instance = instance_wrapper->instance_object(); |
523 DCHECK(IsWasmInstance(*instance)); | 521 DCHECK(IsWasmInstance(*instance)); |
524 SetInstanceMemory(isolate, instance, new_buffer); | 522 SetInstanceMemory(isolate, instance, new_buffer); |
525 UncheckedUpdateInstanceMemory(isolate, instance, old_mem_start, old_size); | 523 UncheckedUpdateInstanceMemory(isolate, instance, old_mem_start, old_size); |
526 } | 524 } |
527 } | 525 } |
(...skipping 1052 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1580 if (!array->get(kWrapperInstanceObject)->IsWeakCell()) return false; | 1578 if (!array->get(kWrapperInstanceObject)->IsWeakCell()) return false; |
1581 Isolate* isolate = array->GetIsolate(); | 1579 Isolate* isolate = array->GetIsolate(); |
1582 if (!array->get(kNextInstanceWrapper)->IsUndefined(isolate) && | 1580 if (!array->get(kNextInstanceWrapper)->IsUndefined(isolate) && |
1583 !array->get(kNextInstanceWrapper)->IsFixedArray()) | 1581 !array->get(kNextInstanceWrapper)->IsFixedArray()) |
1584 return false; | 1582 return false; |
1585 if (!array->get(kPreviousInstanceWrapper)->IsUndefined(isolate) && | 1583 if (!array->get(kPreviousInstanceWrapper)->IsUndefined(isolate) && |
1586 !array->get(kPreviousInstanceWrapper)->IsFixedArray()) | 1584 !array->get(kPreviousInstanceWrapper)->IsFixedArray()) |
1587 return false; | 1585 return false; |
1588 return true; | 1586 return true; |
1589 } | 1587 } |
OLD | NEW |