Skip to content

Commit b8b324a

Browse files
committed
Remove WasmStore local from bytecode interpreter loop, only used by table instructions.
1 parent 7e1bb02 commit b8b324a

File tree

1 file changed

+23
-25
lines changed

1 file changed

+23
-25
lines changed

wasm/src/org.graalvm.wasm/src/org/graalvm/wasm/nodes/WasmFunctionNode.java

Lines changed: 23 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,6 @@
7979
import org.graalvm.wasm.WasmLanguage;
8080
import org.graalvm.wasm.WasmMath;
8181
import org.graalvm.wasm.WasmModule;
82-
import org.graalvm.wasm.WasmStore;
8382
import org.graalvm.wasm.WasmTable;
8483
import org.graalvm.wasm.WasmType;
8584
import org.graalvm.wasm.api.Vector128;
@@ -265,7 +264,6 @@ public Object executeBodyFromOffset(WasmInstance instance, VirtualFrame frame, i
265264
int stackPointer = startStackPointer;
266265
int lineIndex = startLineIndex;
267266

268-
final WasmStore store = instance.store();
269267
// Note: The module may not have any memories.
270268
final WasmMemory zeroMemory = !codeEntry.usesMemoryZero() ? null : memory(instance, 0);
271269
final WasmMemoryLibrary zeroMemoryLib = !codeEntry.usesMemoryZero() ? null : memoryLib(0);
@@ -546,7 +544,7 @@ public Object executeBodyFromOffset(WasmInstance instance, VirtualFrame frame, i
546544
tableIndex = rawPeekI32(bytecode, offset + 8);
547545
offset += 12;
548546
}
549-
final WasmTable table = store.tables().table(instance.tableAddress(tableIndex));
547+
final WasmTable table = instance.store().tables().table(instance.tableAddress(tableIndex));
550548
final Object[] elements = table.elements();
551549
final int elementIndex = popInt(frame, stackPointer);
552550
if (elementIndex < 0 || elementIndex >= elements.length) {
@@ -1499,13 +1497,13 @@ public Object executeBodyFromOffset(WasmInstance instance, VirtualFrame frame, i
14991497
break;
15001498
case Bytecode.TABLE_GET: {
15011499
final int tableIndex = rawPeekI32(bytecode, offset);
1502-
table_get(store, instance, frame, stackPointer, tableIndex);
1500+
table_get(instance, frame, stackPointer, tableIndex);
15031501
offset += 4;
15041502
break;
15051503
}
15061504
case Bytecode.TABLE_SET: {
15071505
final int tableIndex = rawPeekI32(bytecode, offset);
1508-
table_set(store, instance, frame, stackPointer, tableIndex);
1506+
table_set(instance, frame, stackPointer, tableIndex);
15091507
stackPointer -= 2;
15101508
offset += 4;
15111509
break;
@@ -1580,7 +1578,7 @@ public Object executeBodyFromOffset(WasmInstance instance, VirtualFrame frame, i
15801578
final int n = popInt(frame, stackPointer - 1);
15811579
final int src = popInt(frame, stackPointer - 2);
15821580
final int dst = popInt(frame, stackPointer - 3);
1583-
table_init(store, instance, n, src, dst, tableIndex, elementIndex);
1581+
table_init(instance, n, src, dst, tableIndex, elementIndex);
15841582
stackPointer -= 3;
15851583
offset += 8;
15861584
break;
@@ -1598,7 +1596,7 @@ public Object executeBodyFromOffset(WasmInstance instance, VirtualFrame frame, i
15981596
final int n = popInt(frame, stackPointer - 1);
15991597
final int src = popInt(frame, stackPointer - 2);
16001598
final int dst = popInt(frame, stackPointer - 3);
1601-
table_copy(store, instance, n, src, dst, srcIndex, dstIndex);
1599+
table_copy(instance, n, src, dst, srcIndex, dstIndex);
16021600
stackPointer -= 3;
16031601
offset += 8;
16041602
break;
@@ -1609,15 +1607,15 @@ public Object executeBodyFromOffset(WasmInstance instance, VirtualFrame frame, i
16091607
final int n = popInt(frame, stackPointer - 1);
16101608
final Object val = popReference(frame, stackPointer - 2);
16111609

1612-
final int res = table_grow(store, instance, n, val, tableIndex);
1610+
final int res = table_grow(instance, n, val, tableIndex);
16131611
pushInt(frame, stackPointer - 2, res);
16141612
stackPointer--;
16151613
offset += 4;
16161614
break;
16171615
}
16181616
case Bytecode.TABLE_SIZE: {
16191617
final int tableIndex = rawPeekI32(bytecode, offset);
1620-
table_size(store, instance, frame, stackPointer, tableIndex);
1618+
table_size(instance, frame, stackPointer, tableIndex);
16211619
stackPointer++;
16221620
offset += 4;
16231621
break;
@@ -1628,7 +1626,7 @@ public Object executeBodyFromOffset(WasmInstance instance, VirtualFrame frame, i
16281626
final int n = popInt(frame, stackPointer - 1);
16291627
final Object val = popReference(frame, stackPointer - 2);
16301628
final int i = popInt(frame, stackPointer - 3);
1631-
table_fill(store, instance, n, val, i, tableIndex);
1629+
table_fill(instance, n, val, i, tableIndex);
16321630
stackPointer -= 3;
16331631
offset += 4;
16341632
break;
@@ -4360,8 +4358,8 @@ private static void i64_extend32_s(VirtualFrame frame, int stackPointer) {
43604358
}
43614359

43624360
@TruffleBoundary
4363-
private void table_init(WasmStore store, WasmInstance instance, int length, int source, int destination, int tableIndex, int elementIndex) {
4364-
final WasmTable table = store.tables().table(instance.tableAddress(tableIndex));
4361+
private void table_init(WasmInstance instance, int length, int source, int destination, int tableIndex, int elementIndex) {
4362+
final WasmTable table = instance.store().tables().table(instance.tableAddress(tableIndex));
43654363
final Object[] elementInstance = instance.elemInstance(elementIndex);
43664364
final int elementInstanceLength;
43674365
if (elementInstance == null) {
@@ -4379,8 +4377,8 @@ private void table_init(WasmStore store, WasmInstance instance, int length, int
43794377
table.initialize(elementInstance, source, destination, length);
43804378
}
43814379

4382-
private void table_get(WasmStore store, WasmInstance instance, VirtualFrame frame, int stackPointer, int index) {
4383-
final WasmTable table = store.tables().table(instance.tableAddress(index));
4380+
private void table_get(WasmInstance instance, VirtualFrame frame, int stackPointer, int index) {
4381+
final WasmTable table = instance.store().tables().table(instance.tableAddress(index));
43844382
final int i = popInt(frame, stackPointer - 1);
43854383
if (i < 0 || i >= table.size()) {
43864384
enterErrorBranch();
@@ -4390,8 +4388,8 @@ private void table_get(WasmStore store, WasmInstance instance, VirtualFrame fram
43904388
pushReference(frame, stackPointer - 1, value);
43914389
}
43924390

4393-
private void table_set(WasmStore store, WasmInstance instance, VirtualFrame frame, int stackPointer, int index) {
4394-
final WasmTable table = store.tables().table(instance.tableAddress(index));
4391+
private void table_set(WasmInstance instance, VirtualFrame frame, int stackPointer, int index) {
4392+
final WasmTable table = instance.store().tables().table(instance.tableAddress(index));
43954393
final Object value = popReference(frame, stackPointer - 1);
43964394
final int i = popInt(frame, stackPointer - 2);
43974395
if (i < 0 || i >= table.size()) {
@@ -4401,21 +4399,21 @@ private void table_set(WasmStore store, WasmInstance instance, VirtualFrame fram
44014399
table.set(i, value);
44024400
}
44034401

4404-
private static void table_size(WasmStore store, WasmInstance instance, VirtualFrame frame, int stackPointer, int index) {
4405-
final WasmTable table = store.tables().table(instance.tableAddress(index));
4402+
private static void table_size(WasmInstance instance, VirtualFrame frame, int stackPointer, int index) {
4403+
final WasmTable table = instance.store().tables().table(instance.tableAddress(index));
44064404
pushInt(frame, stackPointer, table.size());
44074405
}
44084406

44094407
@TruffleBoundary
4410-
private static int table_grow(WasmStore store, WasmInstance instance, int length, Object value, int index) {
4411-
final WasmTable table = store.tables().table(instance.tableAddress(index));
4408+
private static int table_grow(WasmInstance instance, int length, Object value, int index) {
4409+
final WasmTable table = instance.store().tables().table(instance.tableAddress(index));
44124410
return table.grow(length, value);
44134411
}
44144412

44154413
@TruffleBoundary
4416-
private void table_copy(WasmStore store, WasmInstance instance, int length, int source, int destination, int sourceTableIndex, int destinationTableIndex) {
4417-
final WasmTable sourceTable = store.tables().table(instance.tableAddress(sourceTableIndex));
4418-
final WasmTable destinationTable = store.tables().table(instance.tableAddress(destinationTableIndex));
4414+
private void table_copy(WasmInstance instance, int length, int source, int destination, int sourceTableIndex, int destinationTableIndex) {
4415+
final WasmTable sourceTable = instance.store().tables().table(instance.tableAddress(sourceTableIndex));
4416+
final WasmTable destinationTable = instance.store().tables().table(instance.tableAddress(destinationTableIndex));
44194417
if (checkOutOfBounds(source, length, sourceTable.size()) || checkOutOfBounds(destination, length, destinationTable.size())) {
44204418
enterErrorBranch();
44214419
throw WasmException.create(Failure.OUT_OF_BOUNDS_TABLE_ACCESS);
@@ -4427,8 +4425,8 @@ private void table_copy(WasmStore store, WasmInstance instance, int length, int
44274425
}
44284426

44294427
@TruffleBoundary
4430-
private void table_fill(WasmStore store, WasmInstance instance, int length, Object value, int offset, int index) {
4431-
final WasmTable table = store.tables().table(instance.tableAddress(index));
4428+
private void table_fill(WasmInstance instance, int length, Object value, int offset, int index) {
4429+
final WasmTable table = instance.store().tables().table(instance.tableAddress(index));
44324430
if (checkOutOfBounds(offset, length, table.size())) {
44334431
enterErrorBranch();
44344432
throw WasmException.create(Failure.OUT_OF_BOUNDS_TABLE_ACCESS);

0 commit comments

Comments
 (0)