mirror of
https://github.com/openjdk/jdk.git
synced 2025-08-27 14:54:52 +02:00
8254842: [JVMCI] copy thread name when attaching libgraal thread to HotSpot
Reviewed-by: kvn, never
This commit is contained in:
parent
5d1397fa9a
commit
017d151e11
3 changed files with 20 additions and 6 deletions
|
@ -2349,13 +2349,25 @@ C2V_VMENTRY_PREFIX(jlong, getCurrentJavaThread, (JNIEnv* env, jobject c2vm))
|
||||||
return (jlong) p2i(thread);
|
return (jlong) p2i(thread);
|
||||||
C2V_END
|
C2V_END
|
||||||
|
|
||||||
C2V_VMENTRY_PREFIX(jboolean, attachCurrentThread, (JNIEnv* env, jobject c2vm, jboolean as_daemon))
|
C2V_VMENTRY_PREFIX(jboolean, attachCurrentThread, (JNIEnv* env, jobject c2vm, jbyteArray name, jboolean as_daemon))
|
||||||
if (thread == NULL) {
|
if (thread == NULL) {
|
||||||
// Called from unattached JVMCI shared library thread
|
// Called from unattached JVMCI shared library thread
|
||||||
|
guarantee(name != NULL, "libjvmci caller must pass non-null name");
|
||||||
|
|
||||||
extern struct JavaVM_ main_vm;
|
extern struct JavaVM_ main_vm;
|
||||||
JNIEnv* hotspotEnv;
|
JNIEnv* hotspotEnv;
|
||||||
jint res = as_daemon ? main_vm.AttachCurrentThreadAsDaemon((void**) &hotspotEnv, NULL) :
|
|
||||||
main_vm.AttachCurrentThread((void**) &hotspotEnv, NULL);
|
int name_len = env->GetArrayLength(name);
|
||||||
|
char name_buf[64]; // Cannot use Resource heap as it requires a current thread
|
||||||
|
int to_copy = MIN2(name_len, (int) sizeof(name_buf) - 1);
|
||||||
|
env->GetByteArrayRegion(name, 0, to_copy, (jbyte*) name_buf);
|
||||||
|
name_buf[to_copy] = '\0';
|
||||||
|
JavaVMAttachArgs attach_args;
|
||||||
|
attach_args.version = JNI_VERSION_1_2;
|
||||||
|
attach_args.name = name_buf;
|
||||||
|
attach_args.group = NULL;
|
||||||
|
jint res = as_daemon ? main_vm.AttachCurrentThreadAsDaemon((void**) &hotspotEnv, &attach_args) :
|
||||||
|
main_vm.AttachCurrentThread((void**) &hotspotEnv, &attach_args);
|
||||||
if (res != JNI_OK) {
|
if (res != JNI_OK) {
|
||||||
JNI_THROW_("attachCurrentThread", InternalError, err_msg("Trying to attach thread returned %d", res), false);
|
JNI_THROW_("attachCurrentThread", InternalError, err_msg("Trying to attach thread returned %d", res), false);
|
||||||
}
|
}
|
||||||
|
@ -2803,7 +2815,7 @@ JNINativeMethod CompilerToVM::methods[] = {
|
||||||
{CC "registerNativeMethods", CC "(" CLASS ")[J", FN_PTR(registerNativeMethods)},
|
{CC "registerNativeMethods", CC "(" CLASS ")[J", FN_PTR(registerNativeMethods)},
|
||||||
{CC "isCurrentThreadAttached", CC "()Z", FN_PTR(isCurrentThreadAttached)},
|
{CC "isCurrentThreadAttached", CC "()Z", FN_PTR(isCurrentThreadAttached)},
|
||||||
{CC "getCurrentJavaThread", CC "()J", FN_PTR(getCurrentJavaThread)},
|
{CC "getCurrentJavaThread", CC "()J", FN_PTR(getCurrentJavaThread)},
|
||||||
{CC "attachCurrentThread", CC "(Z)Z", FN_PTR(attachCurrentThread)},
|
{CC "attachCurrentThread", CC "([BZ)Z", FN_PTR(attachCurrentThread)},
|
||||||
{CC "detachCurrentThread", CC "()V", FN_PTR(detachCurrentThread)},
|
{CC "detachCurrentThread", CC "()V", FN_PTR(detachCurrentThread)},
|
||||||
{CC "translate", CC "(" OBJECT ")J", FN_PTR(translate)},
|
{CC "translate", CC "(" OBJECT ")J", FN_PTR(translate)},
|
||||||
{CC "unhand", CC "(J)" OBJECT, FN_PTR(unhand)},
|
{CC "unhand", CC "(J)" OBJECT, FN_PTR(unhand)},
|
||||||
|
|
|
@ -977,9 +977,10 @@ final class CompilerToVM {
|
||||||
native long getCurrentJavaThread();
|
native long getCurrentJavaThread();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
* @param name name of current thread if in a native image otherwise {@code null}
|
||||||
* @see HotSpotJVMCIRuntime#attachCurrentThread
|
* @see HotSpotJVMCIRuntime#attachCurrentThread
|
||||||
*/
|
*/
|
||||||
native boolean attachCurrentThread(boolean asDaemon);
|
native boolean attachCurrentThread(byte[] name, boolean asDaemon);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @see HotSpotJVMCIRuntime#detachCurrentThread()
|
* @see HotSpotJVMCIRuntime#detachCurrentThread()
|
||||||
|
|
|
@ -1117,7 +1117,8 @@ public final class HotSpotJVMCIRuntime implements JVMCIRuntime {
|
||||||
* the length of the array returned by {@link #registerNativeMethods}
|
* the length of the array returned by {@link #registerNativeMethods}
|
||||||
*/
|
*/
|
||||||
public boolean attachCurrentThread(boolean asDaemon) {
|
public boolean attachCurrentThread(boolean asDaemon) {
|
||||||
return compilerToVm.attachCurrentThread(asDaemon);
|
byte[] name = IS_IN_NATIVE_IMAGE ? Thread.currentThread().getName().getBytes() : null;
|
||||||
|
return compilerToVm.attachCurrentThread(name, asDaemon);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue