/* Find out where the JRE is that we will be using. */ if (!GetJREPath(jrepath, so_jrepath, JNI_FALSE) ) { JLI_ReportErrorMessage(JRE_ERROR1); exit(2); } JLI_Snprintf(jvmcfg, so_jvmcfg, "%s%slib%sjvm.cfg", jrepath, FILESEP, FILESEP); /* Find the specified JVM type */ if (ReadKnownVMs(jvmcfg, JNI_FALSE) < 1) { JLI_ReportErrorMessage(CFG_ERROR7); exit(1); }
/** * 创建新的线程 * 这个函数的设计我是没看懂的 * 从jdk的启动开始 执行路径是 t1 t1 t1 t1 t2 t2 * main->JLI_Launch->CreateExecutionEnvironment->MacOSXStartup->main->JLI_Launch->... * 但是注释上说的是 * Mac OS X requires the Cocoa event loop to be run on the "main" * thread. Spawn off a new thread to run main() and pass * this thread off to the Cocoa event loop. * @param argc * @param argv 从JLI_Launch函数带下来的启动参数 * - /jdk/build/macosx-x86_64-server-slowdebug/jdk/bin/java * - VMLoaderTest */ staticvoidMacOSXStartup(int argc, char *argv[]) { // Thread already started? // static修饰的started标识符 即该方法只会被调用一次 static jboolean started = false; if (started) { return; } started = true;
// Hand off arguments structNSAppArgsargs; args.argc = argc; args.argv = argv;
// Fire up the main thread pthread_t main_thr; /** * 系统调用创建线程 * - main_thr 线程创建成功后用来接收线程id * - 线程属性使用默认的 * - apple_main 线程创建好后处于就绪状态 被cpu调度之后 执行的逻辑入口 * - args apple_main执行的启动参数 */ if (pthread_create(&main_thr, NULL, &apple_main, &args) != 0) { JLI_ReportErrorMessageSys("Could not create main thread: %s\n", strerror(errno)); exit(1) } if (pthread_detach(main_thr)) { JLI_ReportErrorMessageSys("pthread_detach() failed: %s\n", strerror(errno)); exit(1); }