8254842: [JVMCI] copy thread name when attaching libgraal thread to HotSpot

Reviewed-by: kvn, never
This commit is contained in:
Doug Simon 2020-10-20 08:38:14 +00:00
parent 5d1397fa9a
commit 017d151e11
3 changed files with 20 additions and 6 deletions

View file

@ -2349,13 +2349,25 @@ C2V_VMENTRY_PREFIX(jlong, getCurrentJavaThread, (JNIEnv* env, jobject c2vm))
return (jlong) p2i(thread);
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) {
// Called from unattached JVMCI shared library thread
guarantee(name != NULL, "libjvmci caller must pass non-null name");
extern struct JavaVM_ main_vm;
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) {
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 "isCurrentThreadAttached", CC "()Z", FN_PTR(isCurrentThreadAttached)},
{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 "translate", CC "(" OBJECT ")J", FN_PTR(translate)},
{CC "unhand", CC "(J)" OBJECT, FN_PTR(unhand)},