Skip to content

Commit

Permalink
Address PR feedback
Browse files Browse the repository at this point in the history
  • Loading branch information
kg committed Nov 7, 2022
1 parent e8178df commit 8a986c1
Showing 1 changed file with 10 additions and 18 deletions.
28 changes: 10 additions & 18 deletions src/mono/wasm/runtime/roots.ts
Original file line number Diff line number Diff line change
Expand Up @@ -287,15 +287,8 @@ class WasmJsOwnedRoot<T extends MonoObject> implements WasmRoot<T> {
}

set(value: T): T {
if (value === <any>0) {
// The expensive write barrier is only necessary when storing a managed pointer into
// a root because doing that changes its reachability/liveness
const address32 = this.__buffer.get_address_32(this.__index);
Module.HEAPU32[address32] = 0;
} else {
const destinationAddress = this.__buffer.get_address(this.__index);
cwraps.mono_wasm_write_managed_pointer_unsafe(destinationAddress, <ManagedPointer>value);
}
const destinationAddress = this.__buffer.get_address(this.__index);
cwraps.mono_wasm_write_managed_pointer_unsafe(destinationAddress, <ManagedPointer>value);
return value;
}

Expand Down Expand Up @@ -334,7 +327,10 @@ class WasmJsOwnedRoot<T extends MonoObject> implements WasmRoot<T> {
}

clear(): void {
this.set(<any>0);
// .set performs an expensive write barrier, and that is not necessary in most cases
// for clear since clearing a root cannot cause new objects to survive a GC
const address32 = this.__buffer.get_address_32(this.__index);
Module.HEAPU32[address32] = 0;
}

release(): void {
Expand Down Expand Up @@ -388,13 +384,7 @@ class WasmExternalRoot<T extends MonoObject> implements WasmRoot<T> {
}

set(value: T): T {
if (value === <any>0) {
// The expensive write barrier is only necessary when storing a managed pointer into
// a root because doing that changes its reachability/liveness
Module.HEAPU32[<any>this.__external_address >>> 2] = 0;
} else {
cwraps.mono_wasm_write_managed_pointer_unsafe(this.__external_address, <ManagedPointer>value);
}
cwraps.mono_wasm_write_managed_pointer_unsafe(this.__external_address, <ManagedPointer>value);
return value;
}

Expand Down Expand Up @@ -433,7 +423,9 @@ class WasmExternalRoot<T extends MonoObject> implements WasmRoot<T> {
}

clear(): void {
this.set(<any>0);
// .set performs an expensive write barrier, and that is not necessary in most cases
// for clear since clearing a root cannot cause new objects to survive a GC
Module.HEAPU32[<any>this.__external_address >>> 2] = 0;
}

release(): void {
Expand Down

0 comments on commit 8a986c1

Please sign in to comment.