Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(core) EspressoVM compatibility #1003

Closed
wants to merge 8 commits into from
Closed
Changes from 1 commit
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
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) {
lewurm marked this conversation as resolved.
Show resolved Hide resolved
FUNCTION_MISSING_ABORT_TABLE = NULL;
getAllocator().free(currentTable);
memPutAddress(ptr, NULL);
}
} else {
if (currentTable != RESERVED0_NULL) {
if (currentTable != RESERVED3_NULL) {
lewurm marked this conversation as resolved.
Show resolved Hide resolved
throw new IllegalStateException("setFunctionMissingAddresses has been called already");
}
if (currentTable != NULL) {
Expand Down Expand Up @@ -233,4 +234,4 @@ public static boolean areCapabilitiesDifferent(PointerBuffer ref, PointerBuffer
return false;
}

}
}