Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(245)

Side by Side Diff: src/wasm/wasm-objects.cc

Issue 2917603002: [wasm] Fix WasmMemoryObject constructor for when a module has no initial memory (Closed)
Patch Set: Created 3 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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
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
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 = old_buffer->byte_length()->Number();
Clemens Hammacher 2017/05/31 07:56:37 Can you use "uint32_t old_size = 0; CHECK(old_buff
gdeepti 2017/06/01 07:01:37 Done.
472 Address old_mem_start = nullptr;
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; 474 Handle<JSArrayBuffer> new_buffer;
479 // Return current size if grow by 0. 475 // Return current size if grow by 0.
480 if (pages == 0) { 476 if (pages == 0) {
481 // Even for pages == 0, we need to attach a new JSArrayBuffer with the same 477 // 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. 478 // backing store and neuter the old one to be spec compliant.
483 if (!old_buffer.is_null() && old_size != 0) { 479 if (!old_buffer.is_null() && old_size != 0) {
Clemens Hammacher 2017/05/31 07:56:37 old_buffer cannot be null here.
gdeepti 2017/06/01 07:01:37 Done.
484 new_buffer = SetupArrayBuffer( 480 new_buffer = SetupArrayBuffer(
485 isolate, old_buffer->allocation_base(), 481 isolate, old_buffer->allocation_base(),
486 old_buffer->allocation_length(), old_buffer->backing_store(), 482 old_buffer->allocation_length(), old_buffer->backing_store(),
487 old_size, old_buffer->is_external(), old_buffer->has_guard_region()); 483 old_size, old_buffer->is_external(), old_buffer->has_guard_region());
488 memory_object->set_buffer(*new_buffer); 484 memory_object->set_buffer(*new_buffer);
489 } 485 }
490 DCHECK_EQ(0, old_size % WasmModule::kPageSize); 486 DCHECK_EQ(0, old_size % WasmModule::kPageSize);
491 return old_size / WasmModule::kPageSize; 487 return old_size / WasmModule::kPageSize;
492 } 488 }
493 if (!memory_object->has_instances_link()) { 489 if (!memory_object->has_instances_link()) {
(...skipping 14 matching lines...) Expand all
508 DCHECK(instance_wrapper->has_instance()); 504 DCHECK(instance_wrapper->has_instance());
509 Handle<WasmInstanceObject> instance = instance_wrapper->instance_object(); 505 Handle<WasmInstanceObject> instance = instance_wrapper->instance_object();
510 DCHECK(IsWasmInstance(*instance)); 506 DCHECK(IsWasmInstance(*instance));
511 uint32_t max_pages = instance->GetMaxMemoryPages(); 507 uint32_t max_pages = instance->GetMaxMemoryPages();
512 508
513 // Grow memory object buffer and update instances associated with it. 509 // Grow memory object buffer and update instances associated with it.
514 new_buffer = GrowMemoryBuffer(isolate, old_buffer, pages, max_pages); 510 new_buffer = GrowMemoryBuffer(isolate, old_buffer, pages, max_pages);
515 if (new_buffer.is_null()) return -1; 511 if (new_buffer.is_null()) return -1;
516 DCHECK(!instance_wrapper->has_previous()); 512 DCHECK(!instance_wrapper->has_previous());
517 SetInstanceMemory(isolate, instance, new_buffer); 513 SetInstanceMemory(isolate, instance, new_buffer);
514 Address old_mem_start = static_cast<Address>(old_buffer->backing_store());
518 UncheckedUpdateInstanceMemory(isolate, instance, old_mem_start, old_size); 515 UncheckedUpdateInstanceMemory(isolate, instance, old_mem_start, old_size);
519 while (instance_wrapper->has_next()) { 516 while (instance_wrapper->has_next()) {
520 instance_wrapper = instance_wrapper->next_wrapper(); 517 instance_wrapper = instance_wrapper->next_wrapper();
521 DCHECK(WasmInstanceWrapper::IsWasmInstanceWrapper(*instance_wrapper)); 518 DCHECK(WasmInstanceWrapper::IsWasmInstanceWrapper(*instance_wrapper));
522 Handle<WasmInstanceObject> instance = instance_wrapper->instance_object(); 519 Handle<WasmInstanceObject> instance = instance_wrapper->instance_object();
523 DCHECK(IsWasmInstance(*instance)); 520 DCHECK(IsWasmInstance(*instance));
524 SetInstanceMemory(isolate, instance, new_buffer); 521 SetInstanceMemory(isolate, instance, new_buffer);
525 UncheckedUpdateInstanceMemory(isolate, instance, old_mem_start, old_size); 522 UncheckedUpdateInstanceMemory(isolate, instance, old_mem_start, old_size);
526 } 523 }
527 } 524 }
(...skipping 1052 matching lines...) Expand 10 before | Expand all | Expand 10 after
1580 if (!array->get(kWrapperInstanceObject)->IsWeakCell()) return false; 1577 if (!array->get(kWrapperInstanceObject)->IsWeakCell()) return false;
1581 Isolate* isolate = array->GetIsolate(); 1578 Isolate* isolate = array->GetIsolate();
1582 if (!array->get(kNextInstanceWrapper)->IsUndefined(isolate) && 1579 if (!array->get(kNextInstanceWrapper)->IsUndefined(isolate) &&
1583 !array->get(kNextInstanceWrapper)->IsFixedArray()) 1580 !array->get(kNextInstanceWrapper)->IsFixedArray())
1584 return false; 1581 return false;
1585 if (!array->get(kPreviousInstanceWrapper)->IsUndefined(isolate) && 1582 if (!array->get(kPreviousInstanceWrapper)->IsUndefined(isolate) &&
1586 !array->get(kPreviousInstanceWrapper)->IsFixedArray()) 1583 !array->get(kPreviousInstanceWrapper)->IsFixedArray())
1587 return false; 1584 return false;
1588 return true; 1585 return true;
1589 } 1586 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698