@@ -2349,13 +2349,25 @@ C2V_VMENTRY_PREFIX(jlong, getCurrentJavaThread, (JNIEnv* env, jobject c2vm))
23492349 return (jlong) p2i(thread);
23502350C2V_END
23512351
2352- C2V_VMENTRY_PREFIX (jboolean, attachCurrentThread, (JNIEnv* env, jobject c2vm, jboolean as_daemon))
2352+ C2V_VMENTRY_PREFIX (jboolean, attachCurrentThread, (JNIEnv* env, jobject c2vm, jbyteArray name, jboolean as_daemon))
23532353 if (thread == NULL ) {
23542354 // Called from unattached JVMCI shared library thread
2355+ guarantee (name != NULL , " libjvmci caller must pass non-null name" );
2356+
23552357 extern struct JavaVM_ main_vm;
23562358 JNIEnv* hotspotEnv;
2357- jint res = as_daemon ? main_vm.AttachCurrentThreadAsDaemon ((void **) &hotspotEnv, NULL ) :
2358- main_vm.AttachCurrentThread ((void **) &hotspotEnv, NULL );
2359+
2360+ int name_len = env->GetArrayLength (name);
2361+ char name_buf[64 ]; // Cannot use Resource heap as it requires a current thread
2362+ int to_copy = MIN2 (name_len, (int ) sizeof (name_buf) - 1 );
2363+ env->GetByteArrayRegion (name, 0 , to_copy, (jbyte*) name_buf);
2364+ name_buf[to_copy] = ' \0 ' ;
2365+ JavaVMAttachArgs attach_args;
2366+ attach_args.version = JNI_VERSION_1_2;
2367+ attach_args.name = name_buf;
2368+ attach_args.group = NULL ;
2369+ jint res = as_daemon ? main_vm.AttachCurrentThreadAsDaemon ((void **) &hotspotEnv, &attach_args) :
2370+ main_vm.AttachCurrentThread ((void **) &hotspotEnv, &attach_args);
23592371 if (res != JNI_OK) {
23602372 JNI_THROW_ (" attachCurrentThread" , InternalError, err_msg (" Trying to attach thread returned %d" , res), false );
23612373 }
@@ -2803,7 +2815,7 @@ JNINativeMethod CompilerToVM::methods[] = {
28032815 {CC " registerNativeMethods" , CC " (" CLASS " )[J" , FN_PTR (registerNativeMethods)},
28042816 {CC " isCurrentThreadAttached" , CC " ()Z" , FN_PTR (isCurrentThreadAttached)},
28052817 {CC " getCurrentJavaThread" , CC " ()J" , FN_PTR (getCurrentJavaThread)},
2806- {CC " attachCurrentThread" , CC " (Z )Z" , FN_PTR (attachCurrentThread)},
2818+ {CC " attachCurrentThread" , CC " ([BZ )Z" , FN_PTR (attachCurrentThread)},
28072819 {CC " detachCurrentThread" , CC " ()V" , FN_PTR (detachCurrentThread)},
28082820 {CC " translate" , CC " (" OBJECT " )J" , FN_PTR (translate)},
28092821 {CC " unhand" , CC " (J)" OBJECT, FN_PTR (unhand)},
0 commit comments