2

我需要一步一步地解释当我们调用时到底发生了什么,java -jar JAR_FILE.jar直到 JVM 完成它的工作并返回。

阶段如何准备好让 JVM 在主机上运行?
调用了哪些函数?创建了哪些线程?
当 JVM 将要关闭时会发生什么?

4

1 回答 1

1

Here is my list of steps it is very high level.

  1. JVM boots up and setups up the various memory areas that the GC will be managing, it will also setup some system threads
  2. Look the jar file manifest to determine the class that has the main method to load
  3. Load the main class and verify that the byte code in the just loaded class is correct and not doing anything illegal.
  4. resolve what classes are needed by the class being loaded and load those classes each class being loaded goes through step 3 and 4
  5. Find the the byte code for the main method and execute it.

This is a really simplified list, full details are much more specific and are probably dependent on the JVM implementation.

You might want to look at this book Inside the Java Virtual Machine 2nd Edition for a something more readable than the JVM spec http://www.artima.com/insidejvm/ed2/

于 2012-08-16T22:53:44.723 回答