Skip to content

Commit

Permalink
added HotSpotJVMCIRuntime.getAddressOfReservedLong
Browse files Browse the repository at this point in the history
  • Loading branch information
dougxc committed Nov 25, 2024
1 parent 95a00f8 commit 984c4a4
Show file tree
Hide file tree
Showing 5 changed files with 50 additions and 0 deletions.
2 changes: 2 additions & 0 deletions src/hotspot/share/jvmci/jvmci.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,8 @@ StringEventLog* JVMCI::_verbose_events = nullptr;
volatile intx JVMCI::_first_error_tid = -1;
volatile int JVMCI::_fatal_log_fd = -1;
const char* JVMCI::_fatal_log_filename = nullptr;
volatile jlong JVMCI::_reserved0 = 0L;
volatile jlong JVMCI::_reserved1 = 0L;

CompilerThread* CompilerThreadCanCallJava::update(JavaThread* current, bool new_state) {
if (current->is_Compiler_thread()) {
Expand Down
17 changes: 17 additions & 0 deletions src/hotspot/share/jvmci/jvmci.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,10 @@ class JVMCI : public AllStatic {
max_EventLog_level = 4
};

// Reserved longs for use by JVMCI.
static volatile jlong _reserved0;
static volatile jlong _reserved1;

// Gets the Thread* value for the current thread or null if it's not available.
static Thread* current_thread_or_null();

Expand Down Expand Up @@ -184,6 +188,19 @@ class JVMCI : public AllStatic {

static bool is_compiler_initialized();

/**
* Gets the address of the reserved long field identified by `id`.
* Returns 0L if `id` is not 0 or 1.
*/
static address get_reserved_long(int id) {
if (id == 0) {
return (address) &_reserved0;
} else if (id == 1) {
return (address) &_reserved1;
}
return 0L;
}

/**
* Determines if the VM is sufficiently booted to initialize JVMCI.
*/
Expand Down
10 changes: 10 additions & 0 deletions src/hotspot/share/jvmci/jvmciCompilerToVM.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3228,6 +3228,15 @@ C2V_VMENTRY(void, getOopMapAt, (JNIEnv* env, jobject, ARGUMENT_PAIR(method),
JVMCIENV->copy_longs_from((jlong*)oop_map_buf, oop_map, 0, nwords);
C2V_END

C2V_VMENTRY_0(jlong, getAddressOfReservedLong, (JNIEnv* env, jobject, jint id))
address a = JVMCI::get_reserved_long(id);
if (a == 0L) {
return (jlong) a;
}
THROW_MSG_0(vmSymbols::java_lang_IllegalArgumentException(),
err_msg("%d is not a valid reserved long id", id));
C2V_END

#define CC (char*) /*cast a literal from (const char*)*/
#define FN_PTR(f) CAST_FROM_FN_PTR(void*, &(c2v_ ## f))

Expand Down Expand Up @@ -3390,6 +3399,7 @@ JNINativeMethod CompilerToVM::methods[] = {
{CC "notifyCompilerInliningEvent", CC "(I" HS_METHOD2 HS_METHOD2 "ZLjava/lang/String;I)V", FN_PTR(notifyCompilerInliningEvent)},
{CC "getOopMapAt", CC "(" HS_METHOD2 "I[J)V", FN_PTR(getOopMapAt)},
{CC "updateCompilerThreadCanCallJava", CC "(Z)Z", FN_PTR(updateCompilerThreadCanCallJava)},
{CC "getAddressOfReservedLong", CC "(I)J", FN_PTR(getAddressOfReservedLong)},
};

int CompilerToVM::methods_count() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1522,4 +1522,12 @@ void getOopMapAt(HotSpotResolvedJavaMethodImpl method, int bci, long[] oopMap) {
* @returns false if no change was made, otherwise true
*/
native boolean updateCompilerThreadCanCallJava(boolean newState);

/**
* Gets the address of the reserved long global variable identified by {@code id}.
*
* @param id must be 0 or 1
* @throws IllegalArgumentException if {@code id} is not 0 or 1
*/
native long getAddressOfReservedLong(int id);
}
Original file line number Diff line number Diff line change
Expand Up @@ -655,6 +655,19 @@ public long getThreadLocalLong(int id) {
return compilerToVm.getThreadLocalLong(id);
}

/**
* Gets the address of the volatile long global variable identified by {@code id}.
* The variable is initialized to 0 and is shared by all JVMCI shared library JavaVMs.
* It's up to all callers of this method to coordinate on the semantics of a specific
* global variable.
*
* @param id must be 0 or 1
* @throws IllegalArgumentException if {@code id} is not 0 or 1
*/
public long getAddressOfReservedLong(int id) {
return compilerToVm.getAddressOfReservedLong(id);
}

HotSpotResolvedJavaType createClass(Class<?> javaClass) {
if (javaClass.isPrimitive()) {
return HotSpotResolvedPrimitiveType.forKind(JavaKind.fromJavaClass(javaClass));
Expand Down

0 comments on commit 984c4a4

Please sign in to comment.