Ali p9 teaches you important concepts of Java and JVM

The Java architecture is mainly composed of Java programming language, bytecode, Java API and Java virtual machine related technologies. 1. Write the program in Java language; 2. The front-end compiler (javac) compiles the Java source code into a bytecode file (*.class); 3. The JVM loads the bytecode into it, and then interprets/compiles it to the corresponding platform Machine instructions.
Java language: Java defines approximately 51 keywords.
Java inherits the grammatical structure of C language and adapts the object model of C++. And Java has abandoned many insecure syntax features in C and C++. such as:

Obsolete pointer operations;
automatic memory management;
array boundary checking;
type conversion checking;
thread safety mechanism;
physical environment access restrictions
Insert picture description here

Bytecode:
The compilation result of Java source code is not native machine instructions, but bytecode, which solves the problems of program security and cross-platform portability. We can deploy the compiled bytecode to other environments with jre, and it can also run normally. This is what we often say "compile once, run everywhere"
JavaAPI:
API is an application programming interface, which is some predefined The interface provides applications and developers with the ability to access a set of routines given to software or hardware without having to access the source code or understand the details of the internal working mechanism. It contains a collection of Java's basic class libraries and provides a set of standard methods for accessing host system resources.
Java Virtual Machine:
JVM is an abstract computer defined by a set of specifications. Responsible for loading bytecode into it, interpreting/compiling it into machine instructions on the corresponding platform. The next thing we have to learn is HotSpot VM, which is one of the high-performance virtual machines currently on the market. HotSpot has a hot spot detection function, which can mark a frequently used method or a code block with a large number of effective cycles in the method body as "hot code", and then use the built-in double JIT (Just In Time Compiler) compiler to The bytecode is directly compiled into native machine instructions. Compiler and interpreter coexist in HotSpot, relying on the hot spot detection function to determine whether bytecode instructions are run through interpretation or compiled and run.
Compiler/interpreter running in the virtual machine: The
virtual machine starts and the interpreter starts to work. It is not necessary to wait for the compiler to complete the compilation and then execute it, which can save a lot of compilation time. According to the hot spot detection function, the compiler will compile valuable bytecodes into local machine instructions in exchange for higher program execution efficiency.
Two JIT compilers are embedded in HotSpot: the
system and physical hardware automatically select which compiler, and developers can also manually display the invocation compilation strategy. The hierarchical compilation strategy is enabled by default, and the C1 and C2 compilers coordinate with each other to complete the compilation work.

Client Compiler (C1): Simple and reliable optimization of bytecode, which has achieved faster compilation speed;
Server Compiler (C2): Start some optimizations that take longer to compile to obtain better compilation quality;

Fully explained/fully compiled
Developers can manually call HotSpot VM to use full compiled or fully explained.

Full interpretation: The compiler will stop all work, and the bytecode will completely rely on the interpreter to gradually interpret and execute;
Full compilation: The interpreter will still access and execute under special circumstances that the compiler cannot perform.
Insert picture description here

Java technology features:

Java language independence: JVM can run applications written in java language and other programming languages. The Java language itself does not support other language features, but JVM support (as long as it satisfies and contains the internal instruction set, symbols and other auxiliary information of the jvm, it is a valid bytecode file that can be loaded and run by the JVM)
Fork/Join to achieve multi-core Parallel: (after java5, under the java.util.concurrent package) tasks are split to a minimum, and then each is calculated and run separately. (Such as: Hadoop Map/Reduce)
Java7 new features: switch (support String, binary), try-with-resources automatic resource management, generic inference operator, brand new file system NIO2.0, Fork/Join
32-bit machine maximum Support 4GB memory: Maximum allocation of Java heap memory (windows 1.5G, linux 2~3G)
JDK1.6 update14: Provide pointer compression function, compress 64-bit pointers to 32 bits through operations such as alignment padding, and improve CPU cache usage , Improve the performance of 64-bit JVM. Between update14~update22, the pointer compression can be turned on through the "-XX:+UseCompressedOops" display. After update23, it is turned on by default.

OpenJDK/Oracle JDK:

OpenJDK:
1. HotSpot is written in C++, a small amount of C and assembly, and other content is written in Java (such as base class libraries);
2. It is the open source version of Sun/Oracle JDK (the first version issued in 2009);
3. With Oracle Compared with JDK7, a small amount of code is replaced by other technologies.

Oracle JDK:
1. HotSpot is written in C++, a small amount of C and assembly, and other content is written in Java (such as a base class library);
2. It is suitable for personal development, not for commercial use.

Customized JVM based on OpenJDK in the market:
TaoBao JVM: It has strong performance in a certain business, but it cannot be used universally. It relies heavily on CPU type: Intel CPU. The compilation method uses IntelC and CPP
Complier to improve GC performance. Use crc32 instructions to implement JVM intrinsic and reduce JNI (Jav local interface) call overhead.

Come and thank Xiaobian

Guess you like

Origin blog.csdn.net/dcj19980805/article/details/114750757