--- old/src/java.base/share/native/libjli/java.c 2016-04-16 18:18:04.232987200 +0900 +++ new/src/java.base/share/native/libjli/java.c 2016-04-16 18:18:04.143987200 +0900 @@ -125,6 +125,7 @@ static void PrintUsage(JNIEnv* env, jboolean doXUsage); static void ShowSettings(JNIEnv* env, char *optString); static void ListModules(JNIEnv* env, char *optString); +static void SetNativeThreadName(JNIEnv* env, char *name); static void SetPaths(int argc, char **argv); @@ -325,6 +326,7 @@ * mainThread.isAlive() to work as expected. */ #define LEAVE() \ + SetNativeThreadName(env, "DestroyJavaVM"); \ do { \ if ((*vm)->DetachCurrentThread(vm) != JNI_OK) { \ JLI_ReportErrorMessage(JVM_ERROR2); \ @@ -488,6 +490,9 @@ mainArgs = CreateApplicationArgs(env, argv, argc); CHECK_EXCEPTION_NULL_LEAVE(mainArgs); + /* Set native thread name. */ + SetNativeThreadName(env, "main"); + /* Invoke main method. */ (*env)->CallStaticVoidMethod(env, mainClass, mainID, mainArgs); @@ -1686,6 +1691,29 @@ joptString); } +/** + * Set native thread name as possible. + */ +static void +SetNativeThreadName(JNIEnv *env, char *name) +{ + jmethodID currentThreadID, setNativeNameID; + jobject currentThread; + jstring nameString; + jclass cls; + + NULL_CHECK(cls = FindBootStrapClass(env, "java/lang/Thread")); + NULL_CHECK(currentThreadID = (*env)->GetStaticMethodID(env, cls, + "currentThread", "()Ljava/lang/Thread;")); + NULL_CHECK(currentThread = (*env)->CallStaticObjectMethod(env, cls, + currentThreadID)); + NULL_CHECK(setNativeNameID = (*env)->GetMethodID(env, cls, + "setNativeName", "(Ljava/lang/String;Z)V")); + NULL_CHECK(nameString = (*env)->NewStringUTF(env, name)); + (*env)->CallVoidMethod(env, currentThread, setNativeNameID, + nameString, JNI_TRUE); +} + /* * Prints default usage or the Xusage message, see sun.launcher.LauncherHelper.java */