What is your understanding of the Java platform? Is it true that “Java is interpreted execution”?

Answers to questions:

Salient features of Java:

  1. Write once, run anywhere;

Because there’s such a thing as a JVM, so you can guarantee that Java code, once written, will run anywhere

  1. garbage collection
  2. Java and JDK, JRE, JVM these things, specific features see this: Java technology architecture module

Java code execution:

Java compilers convert.java files into.class files. Common Java compilers include:

  • The javac compiler will not compile if only the JRE is available. Java file
  • ECJ is a Java compiler written by Eclipse with Java compilation specifications, which is why only the JRE runs in Eclipse
  • .
Because of the JIT compiler, Java is not a crude interpretation execution

Common JVMS provide just-in-time compilers. A JIT compiler is a dynamic compiler that compiles hot code into machine code at run TIME


1.

Research point: basic knowledge understanding; Java platform module; Operation principle

Knowledge extension

Platform understanding can be discussed: Java language features, including generics, Lambda, exception handling, garbage collection, reflection and other language features; Basic class libraries, including collections, IO/NIO, network, concurrency, security and other basic class libraries

You can also talk about some of the underlying concepts and mechanisms of the JVM:

  • For example, Java class loading mechanism, common versions of the embedded class loader, such as Bootstrap, Extension and Application Class Loader;
  • Class loading process:
Load --> Verify --> Link --> initializeCopy the code
  • Basic principles of garbage collection, the most common garbage collectors such as SerialGC, Parallel GC, CMS, G1, etc

Knowledge blueprint for the Java platform

JVM compilation related content

At runtime, the JVM loads bytecode through a class-loader that interprets or compiles execution:

JDK8 is a mixed mode (-xmixed)

  • A JVM running in Server mode makes tens of thousands of calls to gather enough information to compile efficiently;
  • The upper limit of client mode is 1500

Hotspot comes with two different JIT Compiler built-in, C1 and C2

  • C1 corresponds to the Client mode, which is suitable for applications that are sensitive to startup speed.
  • C2 corresponds to the Server mode, which is optimized for long-running server-side applications;
  • The default is hierarchical compilation

When a Java VM starts, you can specify different parameters to select a running mode

  • Specifying “-xint” : interprets only and does not compile the code, which abandons the optimization that jIT-enabled;
  • Specifying “Xcomp” tells the JVM to close the interpreter without interpretation execution

“-xcomp” can cause the JVM to start much slower, and some JIT compiler optimizations, such as branch prediction, are often not optimized effectively without profiling

AOT Compilation (AHEAD-of-time Compilation

  • Bytecode is compiled directly into machine code, avoiding JIT preheating and other overhead
  • The Oracle JDK 9 introduced experimental AOT features and added new jAOTC tools
  • Compile a class or module into an AOT library with the following command:
jaotc --output libHelloWorld.so HelloWorld.class 
jaotc --output libjava.base.so --module java.base
Copy the code

It is then specified on startup

java -XX:AOTLibrary=./libHello.so,./libjava.base.so HelloWorld
Copy the code
  • The Oracle JDK supports hierarchical compilation and collaborative use of AOT. The two are not binary. See this article for more information on AOT use