简体   繁体   中英

Loading of java hotspot classes in jvm

Oracle documentation describes /jdk1.7.0/jre/lib/rt.jar as bootstrap classes for java runtime, I am curious if these are ever loaded when running a JDK rather than a JRE and if so how these get replaced with hotspot classes at runtime?

For example rt.jar does not appear to contain a class corresponding to hotspot/jdk/src/share/classes/java/util/Collections.java, so if I add a JDK6 version into eclipse as a JDK and step through the following in a debugger:

Collections.emptySet().iterator();

I get the code corresponding to the rt.jar/java.util.Collections which creates a new iterator instance, wheras the hotspot version from src.zip which pools an empty iterator does not appear to be present.

My understanding has always been that the hotspot code will be what is linked in prior to/during runtime, so I suspect I have just missed the location, but if this is not true how does the hotspot code get linked in?

All Java programs need JRE to run. Even JDK has a sub folder jre inside it. JDK is for the developers to write,compile,profile java programs. All the classes from java.lang and java.util are present inside rt.jar(shortcut for run-time) which will be loaded on every java program execution by the Bootstrap ClassLoader.

src.zip is the source code for Java SE APIs, it doesn't include hot spot source code/ VM code and several other things written in C/C++ but it's open to download for everyone.

I just compared the java.util.Collections.emptySet().iterator() in JAVA_HOME/ src.zip and in JAVA_HOME/jre/lib/rt.jar and found them to be same.

Java SE distributions for versions before the release of the JCL source as part of the OpenJDK reference implementation have differences between their src.zip (with the corresponding compiled classes in rt.jar), and the backported OpenJDK 6 source code that is available online .

The reason is that changes from OpenJDK 7, such as the that pooled iterator, may be backported into OpenJDK 6 versions without the corresponding change being made in any Java SE 6 version, as illustrated by this SCM diagram from the OpenJDK 6 project :

在此处输入图片说明

As Arkantos mentioned, the Bootstrap ClassLoader will load rt.jar , including the Collections.class with the non-pooled iterator in Java SE 6 distributions.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM