Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions substratevm/mx.substratevm/suite.py
Original file line number Diff line number Diff line change
Expand Up @@ -1640,6 +1640,9 @@
"com.oracle.graal.pointsto",
],
"requiresConcealed" : {
"java.base" : [
"jdk.internal.misc", # Unsafe
],
"jdk.internal.vm.ci" : [
"jdk.vm.ci.meta",
"jdk.vm.ci.meta.annotation",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,15 +25,17 @@

package com.oracle.svm.interpreter.metadata;

import java.lang.invoke.MethodHandles;
import java.lang.invoke.VarHandle;
import jdk.internal.misc.Unsafe;

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

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

/**
* Gets a signed 1-byte value.
Expand Down Expand Up @@ -76,7 +78,7 @@ public static int beU1(byte[] data, int bci) {
* @return the unsigned 1-byte value at index {@code bci} in array {@code data}
*/
public static int volatileBeU1(byte[] data, int bci) {
return ((byte) BYTE_ARRAY_VARHANDLE.getVolatile(data, bci)) & 0xff;
return UNSAFE.getByteVolatile(data, offsetFor(bci)) & 0xff;
}

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

/**
Expand Down Expand Up @@ -128,7 +130,7 @@ public static int beSVar(byte[] data, int bci, boolean fourByte) {
}
}

public static void opaqueWrite(byte[] array, int index, byte value) {
BYTE_ARRAY_VARHANDLE.setOpaque(array, index, value);
public static void opaqueWrite(byte[] data, int bci, byte value) {
UNSAFE.putByteOpaque(data, offsetFor(bci), value);
}
}