This study note is based on the second edition of Understanding the Java Virtual Machine — Advanced JVM Features and Best Practices. The JDK version is based on 1.7. The original intention of the notes is to make a systematic review of the book and deepen the knowledge point impression, so as to understand the content of the book more deeply.
1. The difference between JDK and JRE
- JDK: Java language +Java virtual machine +Java API class library, is the smallest development environment.
- JRE: The Java SE API + Java VM in the Java API is a standard environment for Running Java programs.
2. Java version represents technology
- JDK1.1: JAR file format, JDBC, JavaBeans, RMI, inner classes, reflection
- JDK1.2: EJB, Java Plug-in, Java IDL, Swing, JIT, StrictFP keywords
- JDK1.3: Math, Timer API optimization, JNDI,JavaSoundl class library,Java 2D API
- JDK1.4: Regular expressions, exception chains, NIO, logging classes, XML parser, XSLT converters
- JDK1.5: Auto-boxing, generics, dynamic annotations, enumerations, variable length arguments, forEach, JMM (Java Memory Model), J.U.C(Java and package)
- JDK1.6: dynamic language support, compilation API, micro HTTP server API, locking and synchronization, garbage collection, classloading algorithm optimization
- JDK1.7: G1 collector, upgraded classloader, enhanced support for non-Java language calls
- JDK1.8: Lambda expression….
3. Early Java was slow
Because the interpreter and compiler don’t work together, this means that to execute with the compiler, the compiler has to compile every method, every line of code, regardless of how often they execute at a compile-worthy rate.
What are interpreters and compilers
- Compiler: Compiles Java source programs into intermediate code bytecode files (.class files). It is the most basic development tool (e.g. Javac.exe).
- Interpreter: Find bytecode files (.class files) and interpret them line by line into machine code (binary) files. (such as Java. Exe)
What is a JVM
The JVM is the specification for the Java Virtual machine and can be understood as an interface class. The most used Java VIRTUAL machine currently is HotSpot VM, which is a jVM-specific implementation, equivalent to an implementation class. Hot Spot literally means “hot spot”, so named because of the “hot spot code detection technology” of the VIRTUAL machine, which was designed by a small company. Sun’s VIRTUAL Machine team has released Exact VM, which is named for its “accurate memory management” technology. Sun owns HotSpot VM by buying the small company that developed it and has both of these features.
- Accurate memory management: The virtual machine knows exactly what type of data is stored at a location in memory. (GC improves efficiency, explained in Chapter 2)
- Hot code detection technique: You can find the most compilable code by executing a counter and then inform the JIT compiler to compile it on a method basis. Standard compilation and OSR (replace on the stack) compilation actions are triggered if the method is called frequently and the method is in effect looped many times. With the compiler and interpreter working together properly, optimal program response can be balanced with optimal execution performance, and the time pressure of just-in-time compilation is relatively reduced without waiting for native code output to execute the program. This technique is further explained in Chapter 11.
6. JIT compiler (Just In Time Compile)
The interpreter is slow to interpret line by line into machine code. To improve the efficiency of hot code execution, the virtual machine compiles this code into native machine code at runtime and performs various levels of optimization. The compiler that performs this task is called a JIT compiler. The JIT compiler is part of the JRE.