@@ -2349,13 +2349,25 @@ C2V_VMENTRY_PREFIX(jlong, getCurrentJavaThread, (JNIEnv* env, jobject c2vm))
2349
2349
return (jlong) p2i(thread);
2350
2350
C2V_END
2351
2351
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))
2353
2353
if (thread == NULL ) {
2354
2354
// Called from unattached JVMCI shared library thread
2355
+ guarantee (name != NULL , " libjvmci caller must pass non-null name" );
2356
+
2355
2357
extern struct JavaVM_ main_vm;
2356
2358
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);
2359
2371
if (res != JNI_OK) {
2360
2372
JNI_THROW_ (" attachCurrentThread" , InternalError, err_msg (" Trying to attach thread returned %d" , res), false );
2361
2373
}
@@ -2803,7 +2815,7 @@ JNINativeMethod CompilerToVM::methods[] = {
2803
2815
{CC " registerNativeMethods" , CC " (" CLASS " )[J" , FN_PTR (registerNativeMethods)},
2804
2816
{CC " isCurrentThreadAttached" , CC " ()Z" , FN_PTR (isCurrentThreadAttached)},
2805
2817
{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)},
2807
2819
{CC " detachCurrentThread" , CC " ()V" , FN_PTR (detachCurrentThread)},
2808
2820
{CC " translate" , CC " (" OBJECT " )J" , FN_PTR (translate)},
2809
2821
{CC " unhand" , CC " (J)" OBJECT, FN_PTR (unhand)},
0 commit comments