--- old/src/share/vm/prims/jvm.cpp 2016-04-26 12:05:16.469268234 +0900 +++ new/src/share/vm/prims/jvm.cpp 2016-04-26 12:05:16.301113541 +0900 @@ -3180,16 +3180,18 @@ } JVM_END -JVM_ENTRY(void, JVM_SetNativeThreadName(JNIEnv* env, jobject jthread, jstring name)) +JVM_ENTRY(void, JVM_SetNativeThreadName(JNIEnv* env, jobject jthread, jstring name, jboolean allowAttachedThread)) JVMWrapper("JVM_SetNativeThreadName"); ResourceMark rm(THREAD); oop java_thread = JNIHandles::resolve_non_null(jthread); JavaThread* thr = java_lang_Thread::thread(java_thread); // Thread naming only supported for the current thread, doesn't work for // target threads. - if (Thread::current() == thr && !thr->has_attached_via_jni()) { - // we don't set the name of an attached thread to avoid stepping - // on other programs + if (Thread::current() == thr && (allowAttachedThread || !thr->has_attached_via_jni())) { + // Sets the native thread name for a JavaThread. If specifically + // requested JNI-attached threads can also have their native name set; + // otherwise we do not modify JNI-attached threads as it may interfere + // with the application that created them. const char *thread_name = java_lang_String::as_utf8_string(JNIHandles::resolve_non_null(name)); os::set_native_thread_name(thread_name); } --- old/src/share/vm/prims/jvm.h 2016-04-26 12:05:17.128875036 +0900 +++ new/src/share/vm/prims/jvm.h 2016-04-26 12:05:16.963723106 +0900 @@ -275,7 +275,7 @@ JVM_GetAllThreads(JNIEnv *env, jclass dummy); JNIEXPORT void JNICALL -JVM_SetNativeThreadName(JNIEnv *env, jobject jthread, jstring name); +JVM_SetNativeThreadName(JNIEnv *env, jobject jthread, jstring name, jboolean allowAttachedThread); /* getStackTrace() and getAllStackTraces() method */ JNIEXPORT jobjectArray JNICALL