src/solaris/bin/java_md_solinux.c::PostJVMInit (linux)
void
PostJVMInit(JNIEnv *env, jstring mainClass, JavaVM *vm)
{
// stubbed out for windows and *nixes.
}
src/windows/bin/java_md.c::PostJVMInit (windows)
void
PostJVMInit(JNIEnv *env, jstring mainClass, JavaVM *vm)
{
// stubbed out for windows and *nixes.
}
src/macosx/bin/java_md_macosx.c::PostJVMInit (mac)
/*
* Note the jvmInstance must be initialized first before entering into
* ShowSplashScreen, as there is a callback into the JLI_GetJavaVMInstance.
*/
void PostJVMInit(JNIEnv *env, jstring mainClass, JavaVM *vm) {
jvmInstance = vm;
SetMainClassForAWT(env, mainClass);
//@see 16.JVMInit
ShowSplashScreen();
}
src/macosx/bin/java_md_macosx.c::SetMainClassForAWT
static void
SetMainClassForAWT(JNIEnv *env, jclass mainClass) {
jclass classClass = NULL;
//@see:16.2.3.ShowSettings
NULL_CHECK(classClass = FindBootStrapClass(env, "java/lang/Class"));
jmethodID getCanonicalNameMID = NULL;
NULL_CHECK(getCanonicalNameMID = (*env)->GetMethodID(env, classClass, "getCanonicalName", "()Ljava/lang/String;"));
jstring mainClassString = NULL;
//调用java.lang.Class::getCanonicalName
//getName与getCanonicalName只在数组和内部类时有区别,getCanonicalName更容易理解
// getName getCanonicalName getSimpleName
// String [] [Ljava.lang.String; java.lang.String[] String[]
// InnerClass OuterClass$InnerClass OuterClass.InnerClass InnerClass
NULL_CHECK(mainClassString = (*env)->CallObjectMethod(env, mainClass, getCanonicalNameMID));
const char *mainClassName = NULL;
//将主类由字符串形式转换为UTF字符数组
NULL_CHECK(mainClassName = (*env)->GetStringUTFChars(env, mainClassString, NULL));
char envVar[80];
/*
* The JAVA_MAIN_CLASS_<pid> environment variable is used to pass
* the name of a Java class whose main() method is invoked by
* the Java launcher code to start the application, to the AWT code
* in order to assign the name to the Apple menu bar when the app
* is active on the Mac.
* The _<pid> part is added to avoid collisions with child processes.
*
* WARNING: This environment variable is an implementation detail and
* isn't meant for use outside of the core platform. The mechanism for
* passing this information from Java launcher to other modules may
* change drastically between update release, and it may even be
* removed or replaced with another mechanism.
*
* NOTE: It is used by SWT, and JavaFX.
*/
//设置环境变量:JAVA_MAIN_CLASS_${PID}=主类::CanonicalName::UTF数组
snprintf(envVar, sizeof(envVar), "JAVA_MAIN_CLASS_%d", getpid());
setenv(envVar, mainClassName, 1);
//释放存储主类字符串和字符数组内存
(*env)->ReleaseStringUTFChars(env, mainClassString, mainClassName);
}