Skip to content

Commit

Permalink
feat(core) GraalVM Native Image compatibility
Browse files Browse the repository at this point in the history
`reserved0` is used by EspressoVM, thus it cannot serve as a "reference NULL" as on HotSpot:
https://github.com/oracle/graal/blob/3149f62458029ffe92b8dcefe0b3e59612684cfa/espresso/src/com.oracle.truffle.espresso.mokapot/include/mokapot.h#L67-L73

The relevant config is `MOKA_LATTE`. `reserved3` is `NULL` though.
  • Loading branch information
lewurm committed Aug 19, 2024
1 parent f0ec143 commit ad4e87e
Showing 1 changed file with 10 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,14 @@ be easy to workaround (attaching the agent at startup, making sure no contexts a
/** The global JNIEnv. */
private static final long JNI_NATIVE_INTERFACE = memGetAddress(getThreadJNIEnv());

/** The offset in JNIEnv at which to store the pointer to the capabilities array. */
private static final int CAPABILITIES_OFFSET = 3 * POINTER_SIZE;

// OpenJDK: NULL
// EspressoVM: NULL
// GraalVM Native Image: pointer to UnimplementedWithJNIEnvArgument function (see #875)
private static long RESERVED3_NULL = memGetAddress(JNI_NATIVE_INTERFACE + CAPABILITIES_OFFSET);

/** The number of pointers in the JNIEnv struct. */
private static final int JNI_NATIVE_INTERFACE_FUNCTION_COUNT;

Expand All @@ -103,9 +111,6 @@ be easy to workaround (attaching the agent at startup, making sure no contexts a
*/
private static long FUNCTION_MISSING_ABORT_TABLE = NULL;

/** The offset in JNIEnv at which to store the pointer to the capabilities array. */
private static final int CAPABILITIES_OFFSET = 3 * POINTER_SIZE;

static {
int JNI_VERSION = GetVersion();

Expand Down Expand Up @@ -184,21 +189,17 @@ public static void setCapabilities(long capabilities) {

// Ensures FUNCTION_MISSING_ABORT will be called even if no context is current,
public static void setFunctionMissingAddresses(int functionCount) {
// OpenJDK: NULL
// GraalVM Native Image: pointer to UnimplementedWithJNIEnvArgument function (see #875)
long RESERVED0_NULL = memGetAddress(JNI_NATIVE_INTERFACE);

long ptr = JNI_NATIVE_INTERFACE + CAPABILITIES_OFFSET;

long currentTable = memGetAddress(ptr);
if (functionCount == 0) {
if (currentTable != RESERVED0_NULL) {
if (currentTable != RESERVED3_NULL) {
FUNCTION_MISSING_ABORT_TABLE = NULL;
getAllocator().free(currentTable);
memPutAddress(ptr, NULL);
}
} else {
if (currentTable != RESERVED0_NULL) {
if (currentTable != RESERVED3_NULL) {
throw new IllegalStateException("setFunctionMissingAddresses has been called already");
}
if (currentTable != NULL) {
Expand Down

0 comments on commit ad4e87e

Please sign in to comment.