Skip to content

Commit

Permalink
restore with RESERVED3_NULL
Browse files Browse the repository at this point in the history
  • Loading branch information
lewurm committed Aug 19, 2024
1 parent dcf6130 commit c8a8187
Showing 1 changed file with 14 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,18 @@ 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;

/**
* Initial value of reserved3
*
* - OpenJDK: NULL
* - EspressoVM: NULL
* - GraalVM Native Image: pointer to UnimplementedWithJNIEnvArgument function (see #875)
*/
private static final 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 +115,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 @@ -187,25 +196,21 @@ public static void setFunctionMissingAddresses(int functionCount) {
long ptr = JNI_NATIVE_INTERFACE + CAPABILITIES_OFFSET;

// aka. reserved3
//
// OpenJDK: NULL
// EspressoVM: NULL
// GraalVM Native Image: pointer to UnimplementedWithJNIEnvArgument function (see #875)
long currentTable = memGetAddress(ptr);

if (functionCount == 0) {
if (currentTable != FUNCTION_MISSING_ABORT) {
FUNCTION_MISSING_ABORT_TABLE = NULL;
getAllocator().free(currentTable);
memPutAddress(ptr, NULL);
memPutAddress(ptr, RESERVED3_NULL);
}
} else {
// OpenJDK: NULL
// EspressoVM: pointer to VM internal
// GraalVM Native Image: pointer to UnimplementedWithJNIEnvArgument function (see #875)
long RESERVED0_NULL = memGetAddress(JNI_NATIVE_INTERFACE);

boolean slotAvailable = currentTable == NULL; // on HotSpot or Espresso
boolean slotAvailable = currentTable == RESERVED3_NULL; // on HotSpot or Espresso
slotAvailable |= currentTable == RESERVED0_NULL; // on Native Image

if (!slotAvailable) {
Expand Down

0 comments on commit c8a8187

Please sign in to comment.