0

The title explains it all. I was thinking looking into the jvm one might find a java/lang/Object.so (and same for Class... and any other java class that has native), or equivalent, but it's nowhere to be found. I tried to look into the compilation scripts for the OpenJDK but couldn't make sense of them.

Answer: libjava.so

A relevant link: http://fuseyism.com/openjdk/cvmi/java2vm.xhtml

TuTor
  • 33
  • 5

1 Answers1

1

Firstly, there's the Java code for the Java class library provided by jre/lib/rt.jar. It is not compiled into native code ahead-of-time, but just-in-time by the Hotspot compiler (if executed a threshold number of times, otherwise an interpreter is used) during JVM startup/execution.

There's an optimization called Class Data Sharing that parses classes from rt.jar and stores the internal in-memory class representation used by the JVM in jre/lib/[arch]/[type]/classes.jsa so that the classes covered do not have to be processed again and again. This file can be shared by multiple JVM instances by means of memory mapping.

Then there's jre/lib/[arch]/[type]/libjvm.so, which contains the actual JVM code including the Hotspot compiler.

Lastly, there are a number of additional libraries in jre/lib/[arch] that contain JNI implementations required by the Java class library. For example, libjava.so contains various JNI exports for the java.lang and java.io packages, amonst others.

With Java 9, the Java module system was introduced, which also affected rt.jar. rt.jar was replaced with corresponding modules residing in jmods. Additionally, the architecture was dropped from internal paths and the jre subdirectory does not exist anymore.

Java 9 also introduced an experimental ahead-of-time compiler that could be used to precompile the Java class library, at least in theory. AFAIK, it's still experimental as of Java 14.

horstr
  • 2,377
  • 12
  • 22
  • Side note: `rt.jar` was divided into a number of packages starting with Java 9. They're located in the `jmods` directory; for example, `jmods/java.base.jmod` contains most of the standard library. – Powerlord May 14 '20 at 17:17
  • @Powerlord Thanks for the reminder, I updated the answer accordingly! – horstr May 14 '20 at 17:45
  • Thank you. I guess libjava.so is the answer I was looking for then. – TuTor May 15 '20 at 08:11
  • Some specific methods from JRE are not compiled by JIT, but at runtime are replaced with native implementations. See https://stackoverflow.com/questions/19892322/when-will-jvm-use-intrinsics – rkosegi May 15 '20 at 08:58
  • @rkosegi Yes, but replacing those method calls with equivalent instructions is still done by the JIT. Not all methods will be compiled by the JIT as a general principle of Hotspot, the implementation starts off with interpretation. – horstr May 15 '20 at 09:05