Skip to content

Commit 8990ae7

Browse files
committed
[GR-71328] Avoid VarHandle dispatch in interpreter loop for opcode fetch
PullRequest: graal/22635
2 parents f44455b + b8e9d52 commit 8990ae7

File tree

2 files changed

+12
-7
lines changed
  • substratevm
    • mx.substratevm
    • src/com.oracle.svm.interpreter.metadata/src/com/oracle/svm/interpreter/metadata

2 files changed

+12
-7
lines changed

substratevm/mx.substratevm/suite.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1640,6 +1640,9 @@
16401640
"com.oracle.graal.pointsto",
16411641
],
16421642
"requiresConcealed" : {
1643+
"java.base" : [
1644+
"jdk.internal.misc", # Unsafe
1645+
],
16431646
"jdk.internal.vm.ci" : [
16441647
"jdk.vm.ci.meta",
16451648
"jdk.vm.ci.meta.annotation",

substratevm/src/com.oracle.svm.interpreter.metadata/src/com/oracle/svm/interpreter/metadata/ByteUtils.java

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -25,15 +25,17 @@
2525

2626
package com.oracle.svm.interpreter.metadata;
2727

28-
import java.lang.invoke.MethodHandles;
29-
import java.lang.invoke.VarHandle;
28+
import jdk.internal.misc.Unsafe;
3029

3130
/**
3231
* A collection of utility methods for dealing with bytes, particularly in byte arrays.
3332
*/
3433
public final class ByteUtils {
34+
private static final Unsafe UNSAFE = Unsafe.getUnsafe();
3535

36-
private static final VarHandle BYTE_ARRAY_VARHANDLE = MethodHandles.arrayElementVarHandle(byte[].class);
36+
private static long offsetFor(int index) {
37+
return Unsafe.ARRAY_BYTE_BASE_OFFSET + ((long) index * Unsafe.ARRAY_BYTE_INDEX_SCALE);
38+
}
3739

3840
/**
3941
* Gets a signed 1-byte value.
@@ -76,7 +78,7 @@ public static int beU1(byte[] data, int bci) {
7678
* @return the unsigned 1-byte value at index {@code bci} in array {@code data}
7779
*/
7880
public static int volatileBeU1(byte[] data, int bci) {
79-
return ((byte) BYTE_ARRAY_VARHANDLE.getVolatile(data, bci)) & 0xff;
81+
return UNSAFE.getByteVolatile(data, offsetFor(bci)) & 0xff;
8082
}
8183

8284
/**
@@ -87,7 +89,7 @@ public static int volatileBeU1(byte[] data, int bci) {
8789
* @return the unsigned 1-byte value at index {@code bci} in array {@code data}
8890
*/
8991
public static int opaqueBeU1(byte[] data, int bci) {
90-
return ((byte) BYTE_ARRAY_VARHANDLE.getOpaque(data, bci)) & 0xff;
92+
return UNSAFE.getByteOpaque(data, offsetFor(bci)) & 0xff;
9193
}
9294

9395
/**
@@ -128,7 +130,7 @@ public static int beSVar(byte[] data, int bci, boolean fourByte) {
128130
}
129131
}
130132

131-
public static void opaqueWrite(byte[] array, int index, byte value) {
132-
BYTE_ARRAY_VARHANDLE.setOpaque(array, index, value);
133+
public static void opaqueWrite(byte[] data, int bci, byte value) {
134+
UNSAFE.putByteOpaque(data, offsetFor(bci), value);
133135
}
134136
}

0 commit comments

Comments
 (0)