上文介绍了HotSpot编译和调试的方法,而这篇文章将迈出正式调试的第一步——调试HotSpot的启动过程。
学习启动过程可以帮助我们了解程序的入口,并对虚拟机的运行有个整体的把握,方便日后深入学习具体的一些模块。

整体的感知启动过程可以在启动时添加_JAVA_LAUNCHER_DEBUG=1的环境变量。这样JVM会输出详细的打印。
通过这些打印,我们大致能了解到启动过程发生了什么。

  1. ----_JAVA_LAUNCHER_DEBUG----
  2. Launcher state:
  3. debug:on
  4. javargs:off
  5. program name:java
  6. launcher name:openjdk
  7. javaw:off
  8. fullversion:1.8.0-internal-debug-xieshang_2020_12_18_09_49-b00
  9. dotversion:1.8
  10. ergo_policy:DEFAULT_ERGONOMICS_POLICY
  11. Command line args:
  12. argv[0] = /home/xieshang/learn-jvm/openjdk/build/linux-x86_64-normal-server-slowdebug/jdk/bin/java
  13. argv[1] = com.insanexs/HelloHotspot
  14. JRE path is /home/xieshang/learn-jvm/openjdk/build/linux-x86_64-normal-server-slowdebug/jdk
  15. jvm.cfg[0] = ->-server<-
  16. jvm.cfg[1] = ->-client<-
  17. 1 micro seconds to parse jvm.cfg
  18. Default VM: server
  19. Does `/home/xieshang/learn-jvm/openjdk/build/linux-x86_64-normal-server-slowdebug/jdk/lib/amd64/server/libjvm.so\' exist ... yes.
  20. mustsetenv: FALSE
  21. JVM path is /home/xieshang/learn-jvm/openjdk/build/linux-x86_64-normal-server-slowdebug/jdk/lib/amd64/server/libjvm.so
  22. 1 micro seconds to LoadJavaVM
  23. JavaVM args:
  24. version 0x00010002, ignoreUnrecognized is JNI_FALSE, nOptions is 5
  25. option[ 0] = \'-Dsun.java.launcher.diag=true\'
  26. option[ 1] = \'-Djava.class.path=/home/xieshang/learn-open-jdk\'
  27. option[ 2] = \'-Dsun.java.command=com.insanexs/HelloHotspot\'
  28. option[ 3] = \'-Dsun.java.launcher=SUN_STANDARD\'
  29. option[ 4] = \'-Dsun.java.launcher.pid=4485\'
  30. 1 micro seconds to InitializeJVM
  31. Main class is \'com.insanexs/HelloHotspot\'
  32. App\'s argc is 0
  33. 1 micro seconds to load main class
  34. ----_JAVA_LAUNCHER_DEBUG----

从上面的打印大致可以看出有这么几步:

  1. 打印了启动器的状态,包括版本号、程序名等
  2. 打印了传给程序命令行参数,第一个是java命令的相信路径,第二个虚拟机将要执行的java代码
  3. 解析JRE路径,解析jvm.cfg
  4. 加载libjvm库
  5. 解析虚拟机参数
  6. 初始化虚拟机
  7. 虚拟机加载要执行的Java主类,解析参数并执行

我们就以上面划分的阶段为整体脉络,再深入的看看各阶段的具体逻辑。

虚拟机程序运行的入口是在main.c/main方法中。之后会调用java.c/JLI_Launch方法。

  1. int
  2. JLI_Launch(int argc, char ** argv, /* main argc, argc */
  3. int jargc, const char** jargv, /* java args */
  4. int appclassc, const char** appclassv, /* app classpath */
  5. const char* fullversion, /* full version defined */
  6. const char* dotversion, /* dot version defined */
  7. const char* pname, /* program name */
  8. const char* lname, /* launcher name */
  9. jboolean javaargs, /* JAVA_ARGS */
  10. jboolean cpwildcard, /* classpath wildcard*/
  11. jboolean javaw, /* windows-only javaw */
  12. jint ergo /* ergonomics class policy */
  13. )
  14. {
  15. /************************** 前期初始化工作和状态打印 ********************/
  16. int mode = LM_UNKNOWN;
  17. char *what = NULL;
  18. char *cpath = 0;
  19. char *main_class = NULL;
  20. int ret;
  21. InvocationFunctions ifn; //和创建虚拟机相关的结构体 指向三个关键的函数
  22. jlong start, end;
  23. char jvmpath[MAXPATHLEN];
  24. char jrepath[MAXPATHLEN];
  25. char jvmcfg[MAXPATHLEN];
  26. _fVersion = fullversion;
  27. _dVersion = dotversion;
  28. _launcher_name = lname;
  29. _program_name = pname;
  30. _is_java_args = javaargs;
  31. _wc_enabled = cpwildcard;
  32. _ergo_policy = ergo;
  33. InitLauncher(javaw);
  34. DumpState(); //打印相关状态
  35. //打印参数
  36. if (JLI_IsTraceLauncher()) {
  37. int i;
  38. printf("Command line args:\n");
  39. for (i = 0; i < argc ; i++) {
  40. printf("argv[%d] = %s\n", i, argv[i]);
  41. }
  42. AddOption("-Dsun.java.launcher.diag=true", NULL);
  43. }
  44. /************************** 检验版本 ********************/
  45. /*
  46. * Make sure the specified version of the JRE is running.
  47. *
  48. * There are three things to note about the SelectVersion() routine:
  49. * 1) If the version running isn\'t correct, this routine doesn\'t
  50. * return (either the correct version has been exec\'d or an error
  51. * was issued).
  52. * 2) Argc and Argv in this scope are *not* altered by this routine.
  53. * It is the responsibility of subsequent code to ignore the
  54. * arguments handled by this routine.
  55. * 3) As a side-effect, the variable "main_class" is guaranteed to
  56. * be set (if it should ever be set). This isn\'t exactly the
  57. * poster child for structured programming, but it is a small
  58. * price to pay for not processing a jar file operand twice.
  59. * (Note: This side effect has been disabled. See comment on
  60. * bugid 5030265 below.)
  61. */
  62. SelectVersion(argc, argv, &main_class); //版本检测
  63. /************************** 创建执行环境 ********************/
  64. CreateExecutionEnvironment(&argc, &argv,
  65. jrepath, sizeof(jrepath),
  66. jvmpath, sizeof(jvmpath),
  67. jvmcfg, sizeof(jvmcfg));//解析相关环境 获取jre路径、jvmlib库和jvm.cfg
  68. /************************** 设置虚拟机环境 ********************/
  69. if (!IsJavaArgs()) {
  70. SetJvmEnvironment(argc,argv);
  71. }
  72. ifn.CreateJavaVM = 0;
  73. ifn.GetDefaultJavaVMInitArgs = 0;
  74. if (JLI_IsTraceLauncher()) {
  75. start = CounterGet();
  76. }
  77. /************************** 加载虚拟机 ********************/
  78. if (!LoadJavaVM(jvmpath, &ifn)) { //加载 主要是从jvmlib库中解析函数地址 赋值给ifn
  79. return(6);
  80. }
  81. if (JLI_IsTraceLauncher()) {
  82. end = CounterGet();
  83. }
  84. JLI_TraceLauncher("%ld micro seconds to LoadJavaVM\n",
  85. (long)(jint)Counter2Micros(end-start));
  86. ++argv;
  87. --argc;
  88. if (IsJavaArgs()) {
  89. /* Preprocess wrapper arguments */
  90. TranslateApplicationArgs(jargc, jargv, &argc, &argv);
  91. if (!AddApplicationOptions(appclassc, appclassv)) {
  92. return(1);
  93. }
  94. } else {
  95. /* Set default CLASSPATH */
  96. cpath = getenv("CLASSPATH"); //添加CLASSPATH
  97. if (cpath == NULL) {
  98. cpath = ".";
  99. }
  100. SetClassPath(cpath);
  101. }
  102. /************************** 解析参数 ********************/
  103. /* Parse command line options; if the return value of
  104. * ParseArguments is false, the program should exit.
  105. */
  106. if (!ParseArguments(&argc, &argv, &mode, &what, &ret, jrepath))
  107. {
  108. return(ret);
  109. }
  110. /* Override class path if -jar flag was specified */
  111. if (mode == LM_JAR) { //如果是java -jar 则覆盖classpath
  112. SetClassPath(what); /* Override class path */
  113. }
  114. /* set the -Dsun.java.command pseudo property */ //解析特殊属性
  115. SetJavaCommandLineProp(what, argc, argv);
  116. /* Set the -Dsun.java.launcher pseudo property */
  117. SetJavaLauncherProp();
  118. /* set the -Dsun.java.launcher.* platform properties */
  119. SetJavaLauncherPlatformProps();
  120. /************************** 初始化虚拟机 ********************/
  121. return JVMInit(&ifn, threadStackSize, argc, argv, mode, what, ret);
  122. }

这个方法比较长,但是可以划分为几个部分去分析:

这里的初始化部分包括一些参数值的声明,特殊结构体InvocationFuntions的声明,启动器的初始化。
其中声明的参数会在后续的启动过程用来存储相关信息,例如保存JVM、JRE相关路径等。
InvocationFuntions是个重要的结构体,其中包含了创建JVM会被调用的三个函数指针。

  1. typedef struct {
  2. CreateJavaVM_t CreateJavaVM; //指向负责创建JavaVM和JNIEnv结构的函数指针
  3. GetDefaultJavaVMInitArgs_t GetDefaultJavaVMInitArgs; //指向获取默认JVM初始参数的函数指针
  4. GetCreatedJavaVMs_t GetCreatedJavaVMs; //指向获取JVM的函数指针
  5. } InvocationFunctions;

InitLaucher方法主要就是根据_JAVA_LAUNCHER_DEBUG这个环境变量会决定后续是否输出DEBUG的打印。
在开启了launcher_debug后,DumpState()方法会打印出启动状态,并且之后打印出命令行参数。

SelectVersion会验证用户指定的java版本和实际执行的java版本是否兼容,如果不兼容会退出进程。用户可以通过_JAVA_VERSION_SET的环境变量或是jar包中manifest文件等方式指定运行的java版本。

CreateExecutionEnvironment会为后续的启动创建执行环境,这一步骤中主要是确定jdk所在的路径,解析jvmcfg和确认libjvm是否存在等。

  1. 主要是根据处理器类型和主路径确定出JRE的路径
  2. 以同样的方式确定jvm.cfg的文件位置,并解析jvm.cfg(jvm.cfg里面是一些虚拟机的默认配置,如常见的指定以客户端或服务端模式运行)
  3. 检查虚拟机类型(-server/-client),可以是jvm.cfg指定或是由启动参数指定
  4. 确定libjvm库的位置,校验库是否存在,这个库核心的函数库

SetJvmEnviroment主要解析NativeMemoryTracking参数,可以用来追踪本地内存的使用情况

前期环境准备好之后,LoadJavaVM()会从之前确定的路径,加载libjvm库,并将其中的库中JNI_CreateJavaVM,JNI_GetDefaultJavaVMInitArgsJNI_GetCreatedJavaVMs三个函数赋值给ifn。
这三个函数会在之后创建虚拟机时被使用。

这里有两个部分,一是解析命令行传入的参数,看是否有特定的JVM配置选项。这些参数会被用于后续虚拟机的创建上。这一过程主要发生在ParseArguments()中。另一个部分就是添加一些特定的虚拟机参数,发生在SetJavaCommandLinePropSetJavaLaucherPropSetJavaLaucherPlatformProps中。

在环境都准备好之后,会由JVMInit()执行虚拟机初始化工作,首先会通过ShowSplashScreen()方法加载启动动画,之后会进入CountinueInNewThread()方法,由新的线程负责创建虚拟机的工作。

通过上文的介绍,我们找到了java.c/ConutinueInNewThread()的方法。这个方法分为两个部分,第一部分就是确定线程栈的深度,第二部分就是由ContinueInNewThread0()这个方法实现真正的虚拟机创建过程。

  1. int
  2. ContinueInNewThread0(int (JNICALL *continuation)(void *), jlong stack_size, void * args) {
  3. int rslt;
  4. #ifndef __solaris__
  5. pthread_t tid;
  6. //声明线程属性
  7. pthread_attr_t attr;
  8. //初始化线程属性并设置相关属性值
  9. pthread_attr_init(&attr);
  10. pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_JOINABLE);
  11. //设置线程栈深度
  12. if (stack_size > 0) {
  13. pthread_attr_setstacksize(&attr, stack_size);
  14. }
  15. //创建线程并执行方法
  16. if (pthread_create(&tid, &attr, (void *(*)(void*))continuation, (void*)args) == 0) { //创建线程 并将运行函数的起始地址和运行参数传入
  17. void * tmp;
  18. pthread_join(tid, &tmp);//阻塞当前线程 等待新线程运行结束返回
  19. rslt = (int)tmp;
  20. } else {
  21. /*
  22. * Continue execution in current thread if for some reason (e.g. out of
  23. * memory/LWP) a new thread can\'t be created. This will likely fail
  24. * later in continuation as JNI_CreateJavaVM needs to create quite a
  25. * few new threads, anyway, just give it a try..
  26. */
  27. rslt = continuation(args);
  28. }
  29. pthread_attr_destroy(&attr);
  30. #else /* __solaris__ */
  31. thread_t tid;
  32. long flags = 0;
  33. if (thr_create(NULL, stack_size, (void *(*)(void *))continuation, args, flags, &tid) == 0) {
  34. void * tmp;
  35. thr_join(tid, NULL, &tmp);
  36. rslt = (int)tmp;
  37. } else {
  38. /* See above. Continue in current thread if thr_create() failed */
  39. rslt = continuation(args);
  40. }
  41. #endif /* !__solaris__ */
  42. return rslt;
  43. }

在这个方法中,首先调用了pthread_create()函数创建了一个新线程,同时旧线程被jion等待新线程运行完成后返回。
pthread_create()是unix操作系统创建线程的函数,它的第一个参数表示线程标识,第二参数表示线程属性,第三个参数表示创建线程所要执行函数的地址,第四个参数则是将要执行的函数的参数。
等到新线程运行完成后,旧的线程也会返回。此时说明运行结束,进程将会退出。

需要注意的是此时传入的函数地址,它是指向java.c/JavaMain()函数。也就是说新创建的线程将会开始执行该函数。

新创建的线程会去执行JavaMain()函数,正式进入了创建虚拟机、运行Java代码的过程。

  1. int JNICALL
  2. JavaMain(void * _args)
  3. {
  4. /*********************获取相关参数****************************/
  5. JavaMainArgs *args = (JavaMainArgs *)_args;
  6. int argc = args->argc;
  7. char **argv = args->argv;
  8. int mode = args->mode;
  9. char *what = args->what;
  10. InvocationFunctions ifn = args->ifn;
  11. JavaVM *vm = 0;
  12. JNIEnv *env = 0;
  13. jclass mainClass = NULL;
  14. jclass appClass = NULL; // actual application class being launched
  15. jmethodID mainID;
  16. jobjectArray mainArgs;
  17. int ret = 0;
  18. jlong start, end;
  19. RegisterThread();
  20. /*******************初始化JVM、打印相关信息********************************/
  21. start = CounterGet();
  22. if (!InitializeJVM(&vm, &env, &ifn)) {
  23. JLI_ReportErrorMessage(JVM_ERROR1);
  24. exit(1);
  25. }
  26. if (showSettings != NULL) {
  27. ShowSettings(env, showSettings);
  28. CHECK_EXCEPTION_LEAVE(1);
  29. }
  30. if (printVersion || showVersion) {
  31. PrintJavaVersion(env, showVersion);
  32. CHECK_EXCEPTION_LEAVE(0);
  33. if (printVersion) {
  34. LEAVE();
  35. }
  36. }
  37. /* If the user specified neither a class name nor a JAR file */
  38. if (printXUsage || printUsage || what == 0 || mode == LM_UNKNOWN) {
  39. PrintUsage(env, printXUsage);
  40. CHECK_EXCEPTION_LEAVE(1);
  41. LEAVE();
  42. }
  43. FreeKnownVMs(); /* after last possible PrintUsage() */
  44. if (JLI_IsTraceLauncher()) {
  45. end = CounterGet();
  46. JLI_TraceLauncher("%ld micro seconds to InitializeJVM\n",
  47. (long)(jint)Counter2Micros(end-start));
  48. }
  49. /* At this stage, argc/argv have the application\'s arguments */
  50. //打印Java程序的参数
  51. if (JLI_IsTraceLauncher()){
  52. int i;
  53. printf("%s is \'%s\'\n", launchModeNames[mode], what);
  54. printf("App\'s argc is %d\n", argc);
  55. for (i=0; i < argc; i++) {
  56. printf(" argv[%2d] = \'%s\'\n", i, argv[i]);
  57. }
  58. }
  59. /******************获取Java程序的主类***************************/
  60. ret = 1;
  61. /*
  62. * Get the application\'s main class.
  63. *
  64. * See bugid 5030265. The Main-Class name has already been parsed
  65. * from the manifest, but not parsed properly for UTF-8 support.
  66. * Hence the code here ignores the value previously extracted and
  67. * uses the pre-existing code to reextract the value. This is
  68. * possibly an end of release cycle expedient. However, it has
  69. * also been discovered that passing some character sets through
  70. * the environment has "strange" behavior on some variants of
  71. * Windows. Hence, maybe the manifest parsing code local to the
  72. * launcher should never be enhanced.
  73. *
  74. * Hence, future work should either:
  75. * 1) Correct the local parsing code and verify that the
  76. * Main-Class attribute gets properly passed through
  77. * all environments,
  78. * 2) Remove the vestages of maintaining main_class through
  79. * the environment (and remove these comments).
  80. *
  81. * This method also correctly handles launching existing JavaFX
  82. * applications that may or may not have a Main-Class manifest entry.
  83. */
  84. mainClass = LoadMainClass(env, mode, what);//加载mainClass
  85. CHECK_EXCEPTION_NULL_LEAVE(mainClass);
  86. /*
  87. * In some cases when launching an application that needs a helper, e.g., a
  88. * JavaFX application with no main method, the mainClass will not be the
  89. * applications own main class but rather a helper class. To keep things
  90. * consistent in the UI we need to track and report the application main class.
  91. */
  92. appClass = GetApplicationClass(env); //获取application class
  93. NULL_CHECK_RETURN_VALUE(appClass, -1);
  94. /*
  95. * PostJVMInit uses the class name as the application name for GUI purposes,
  96. * for example, on OSX this sets the application name in the menu bar for
  97. * both SWT and JavaFX. So we\'ll pass the actual application class here
  98. * instead of mainClass as that may be a launcher or helper class instead
  99. * of the application class.
  100. */
  101. PostJVMInit(env, appClass, vm); // JVM 初始化后置处理
  102. /*
  103. * The LoadMainClass not only loads the main class, it will also ensure
  104. * that the main method\'s signature is correct, therefore further checking
  105. * is not required. The main method is invoked here so that extraneous java
  106. * stacks are not in the application stack trace.
  107. */
  108. /******************找主类的main方法************************/
  109. mainID = (*env)->GetStaticMethodID(env, mainClass, "main",
  110. "([Ljava/lang/String;)V"); //获取main class的 main(String[] args)方法
  111. CHECK_EXCEPTION_NULL_LEAVE(mainID);
  112. /*******************封装参数,调用main方法*****************/
  113. /* Build platform specific argument array */
  114. mainArgs = CreateApplicationArgs(env, argv, argc); //封装 main(String[] args) 方法的参数args
  115. CHECK_EXCEPTION_NULL_LEAVE(mainArgs);
  116. /* Invoke main method. */
  117. (*env)->CallStaticVoidMethod(env, mainClass, mainID, mainArgs); //调用main(String args)方法
  118. /*
  119. * The launcher\'s exit code (in the absence of calls to
  120. * System.exit) will be non-zero if main threw an exception.
  121. */
  122. /*******************获取执行结果 并退出虚拟机**************/
  123. ret = (*env)->ExceptionOccurred(env) == NULL ? 0 : 1; //根据是否有异常 确定退出码
  124. LEAVE(); //线程解绑 销毁JVM
  125. }

之前上文解析得到的命令行参数等都被封装在JavaMainArgs结构体中,传给了JavaMain方法。因此需要从这个结构体中取回参数。
另外,还创建了一些变量用于之后的过程中存储值,譬如jclass,jmethodID等。

上述代码中的InitializeJVM()方法会负责虚拟机的初始化过程。其代码如下:

  1. static jboolean
  2. InitializeJVM(JavaVM **pvm, JNIEnv **penv, InvocationFunctions *ifn)
  3. {
  4. JavaVMInitArgs args;
  5. jint r;
  6. memset(&args, 0, sizeof(args));
  7. args.version = JNI_VERSION_1_2;
  8. args.nOptions = numOptions;
  9. args.options = options;
  10. args.ignoreUnrecognized = JNI_FALSE;
  11. if (JLI_IsTraceLauncher()) {
  12. int i = 0;
  13. printf("JavaVM args:\n ");
  14. printf("version 0x%08lx, ", (long)args.version);
  15. printf("ignoreUnrecognized is %s, ",
  16. args.ignoreUnrecognized ? "JNI_TRUE" : "JNI_FALSE");
  17. printf("nOptions is %ld\n", (long)args.nOptions);
  18. for (i = 0; i < numOptions; i++)
  19. printf(" option[%2d] = \'%s\'\n",
  20. i, args.options[i].optionString);
  21. }
  22. r = ifn->CreateJavaVM(pvm, (void **)penv, &args); //通过ifn的函数指针 调用CreateJavaVM函数初始化JavaVM 和 JNIEnv
  23. JLI_MemFree(options);
  24. return r == JNI_OK;
  25. }

先获取虚拟机参数,在通过ifn结构体中CreateJavaVM指针,调用正式创建Java虚拟机的函数JNI_CreateJavaVM
JNI_CreateJavaVM代码的主要流程如下:

  1. 先由Threads::create_vm()方法创建虚拟机
  2. 给两个重要的指针赋值,分别是JavaVM * 和 JNIEnv
  3. 一些后置处理,例如通过JVMTI(可以说是虚拟机的工具接口,提供了对虚拟机调试、监测等等的功能)、事件提交等

针对第一点,Threads::create_vm()是负责创建虚拟机,整个过程相对复杂,需要初始化很多模块,创建虚拟机的后台线程,加载必要的类等等,这里不做深入分析。之后有时间可以单独分析这一过程。
针对第二点中提到的两个数据结构,非常重要。我们可以看看它们的具体的内容。

JavaVM

JavaVM结构内部包的是JNIInvokeInterface_结构,因此我们直接看一下JNIInvokeInterface_的结构

  1. struct JNIInvokeInterface_ {
  2. //预留字段
  3. void *reserved0;
  4. void *reserved1;
  5. void *reserved2;
  6. jint (JNICALL *DestroyJavaVM)(JavaVM *vm); //销毁虚拟机的函数指针
  7. jint (JNICALL *AttachCurrentThread)(JavaVM *vm, void **penv, void *args); //绑定线程的函数指针
  8. jint (JNICALL *DetachCurrentThread)(JavaVM *vm); //解绑线程的函数指针
  9. jint (JNICALL *GetEnv)(JavaVM *vm, void **penv, jint version); //获取JNIEnv结构的函数指针
  10. jint (JNICALL *AttachCurrentThreadAsDaemon)(JavaVM *vm, void **penv, void *args);//将线程转为后台线程
  11. };

可以看到主要是一些和虚拟机操作的相关函数。

JNIEnv

JNIEnv结构内部包的是JNINativeInterface结构,这个结构同样定义了很多函数指针,代码太长,这里就不直接贴出了。有兴趣的可以在jni.h中自行查看。如果对结构中的方法分类的话,可以分成以下几类:

  • 获取虚拟机信息
  • 获取相关类和方法,方法执行
  • 获取/设置对象字段
  • 静态方法、静态变量的获取与设置
  • 常见类型的对象的创建和释放
  • 创建直接内存、访问锁等

总之,提供了通过C++代码访问Java程序的能力(这对于从事JNI开发的人来说十分重要)。

了解完成虚拟机的初始化过程后,再回到JavaMain()方法中,之后是通过LoadMainClass()GetApplicationClass()方法确定Java代码的主类。
如果我们在运行指定了Java类,那么这个类就是主类。这里还会调用LauncherHelper.checkAndLoadMain()检验主类是否合法。LauncherHelper的Java代码,这里就是上面介绍的JNIEnv的能力在C++的代码中执行Java代码。
对于一些没有主类的程序,需要通过LaucherHelper.getApplicationClass()确定程序类。

再确定了mainClass之后,还需要找到该类定义的main(),获取main()方法,然后将程序参数封装,传递给main()执行,线程会以此为入口,开始执行Java程序。
这里的找方法和执行方法同样是依赖了JNIEnv中GetStaticMethodIDCallStaticVoidMethod
所以我们的main()方法总是static void的。

当线程从Main()方法中返回,说明Java程序已经执行完成(或是异常退出),这时候虚拟机会检查运行结果,并解绑线程销毁虚拟机,最终退出。

版权声明:本文为insaneXs原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。
本文链接:https://www.cnblogs.com/insaneXs/p/14248428.html