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

Side by Side Diff: src/wasm/wasm-module.h

Issue 2471883003: [wasm] WebAssembly.Memory object can be referenced by multiple Instance objects. (Closed)
Patch Set: Rebase, add Dcheck Created 4 years, 1 month 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 #ifndef V8_WASM_MODULE_H_ 5 #ifndef V8_WASM_MODULE_H_
6 #define V8_WASM_MODULE_H_ 6 #define V8_WASM_MODULE_H_
7 7
8 #include <memory> 8 #include <memory>
9 9
10 #include "src/api.h" 10 #include "src/api.h"
(...skipping 536 matching lines...) Expand 10 before | Expand all | Expand 10 after
547 int GetNumImportedFunctions(Handle<JSObject> instance); 547 int GetNumImportedFunctions(Handle<JSObject> instance);
548 548
549 // Assumed to be called with a code object associated to a wasm module instance. 549 // Assumed to be called with a code object associated to a wasm module instance.
550 // Intended to be called from runtime functions. 550 // Intended to be called from runtime functions.
551 // Returns nullptr on failing to get owning instance. 551 // Returns nullptr on failing to get owning instance.
552 Object* GetOwningWasmInstance(Code* code); 552 Object* GetOwningWasmInstance(Code* code);
553 553
554 MaybeHandle<JSArrayBuffer> GetInstanceMemory(Isolate* isolate, 554 MaybeHandle<JSArrayBuffer> GetInstanceMemory(Isolate* isolate,
555 Handle<JSObject> instance); 555 Handle<JSObject> instance);
556 556
557 void SetInstanceMemoryObject(Handle<JSObject> instance,
558 Handle<Object> mem_object);
559
557 int32_t GetInstanceMemorySize(Isolate* isolate, Handle<JSObject> instance); 560 int32_t GetInstanceMemorySize(Isolate* isolate, Handle<JSObject> instance);
558 561
559 int32_t GrowInstanceMemory(Isolate* isolate, Handle<JSObject> instance, 562 int32_t GrowWebAssemblyMemory(Isolate* isolate, Handle<Object> memory_object,
560 uint32_t pages); 563 uint32_t pages);
564
565 int32_t GrowMemory(Isolate* isolate, Handle<JSObject> instance, uint32_t pages);
561 566
562 void UpdateDispatchTables(Isolate* isolate, Handle<FixedArray> dispatch_tables, 567 void UpdateDispatchTables(Isolate* isolate, Handle<FixedArray> dispatch_tables,
563 int index, Handle<JSFunction> js_function); 568 int index, Handle<JSFunction> js_function);
564 569
570 class WasmInstanceWrapper : public FixedArray {
571 public:
572 static Handle<WasmInstanceWrapper> New(Isolate* isolate,
573 Handle<JSObject> instance);
574 static WasmInstanceWrapper* cast(Object* fixed_array) {
575 SLOW_DCHECK(IsWasmInstanceWrapper(fixed_array));
576 return reinterpret_cast<WasmInstanceWrapper*>(fixed_array);
577 }
578 static bool IsWasmInstanceWrapper(Object* obj);
579 bool has_instance() { return get(kWrapperInstanceObject)->IsWeakCell(); }
580 Handle<JSObject> instance_object() {
581 Object* obj = get(kWrapperInstanceObject);
582 DCHECK(obj->IsWeakCell());
583 WeakCell* cell = WeakCell::cast(obj);
584 DCHECK(cell->value()->IsJSObject());
585 return handle(JSObject::cast(cell->value()));
586 }
587 bool has_next() { return IsWasmInstanceWrapper(get(kNextInstanceWrapper)); }
588 bool has_previous() {
589 return IsWasmInstanceWrapper(get(kPreviousInstanceWrapper));
590 }
591 void set_instance_object(Handle<JSObject> instance, Isolate* isolate);
592 void set_next_wrapper(Object* obj) {
593 DCHECK(IsWasmInstanceWrapper(obj));
594 set(kNextInstanceWrapper, obj);
595 }
596 void set_previous_wrapper(Object* obj) {
597 DCHECK(IsWasmInstanceWrapper(obj));
598 set(kPreviousInstanceWrapper, obj);
599 }
600 Handle<WasmInstanceWrapper> next_wrapper() {
601 Object* obj = get(kNextInstanceWrapper);
602 DCHECK(IsWasmInstanceWrapper(obj));
603 return handle(WasmInstanceWrapper::cast(obj));
604 }
605 Handle<WasmInstanceWrapper> previous_wrapper() {
606 Object* obj = get(kPreviousInstanceWrapper);
607 DCHECK(IsWasmInstanceWrapper(obj));
608 return handle(WasmInstanceWrapper::cast(obj));
609 }
610 void reset_next_wrapper() { set_undefined(kNextInstanceWrapper); }
611 void reset_previous_wrapper() { set_undefined(kPreviousInstanceWrapper); }
612 void reset() {
613 for (int kID = 0; kID < kWrapperPropertyCount; kID++) set_undefined(kID);
614 }
615
616 private:
617 enum {
618 kWrapperInstanceObject,
619 kNextInstanceWrapper,
620 kPreviousInstanceWrapper,
621 kWrapperPropertyCount
622 };
623 };
624
565 namespace testing { 625 namespace testing {
566 626
567 void ValidateInstancesChain(Isolate* isolate, Handle<JSObject> wasm_module, 627 void ValidateInstancesChain(Isolate* isolate, Handle<JSObject> wasm_module,
568 int instance_count); 628 int instance_count);
569 void ValidateModuleState(Isolate* isolate, Handle<JSObject> wasm_module); 629 void ValidateModuleState(Isolate* isolate, Handle<JSObject> wasm_module);
570 void ValidateOrphanedInstance(Isolate* isolate, Handle<JSObject> instance); 630 void ValidateOrphanedInstance(Isolate* isolate, Handle<JSObject> instance);
571 631
572 } // namespace testing 632 } // namespace testing
573 } // namespace wasm 633 } // namespace wasm
574 } // namespace internal 634 } // namespace internal
575 } // namespace v8 635 } // namespace v8
576 636
577 #endif // V8_WASM_MODULE_H_ 637 #endif // V8_WASM_MODULE_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698