In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-16 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >
Share
Shulou(Shulou.com)06/01 Report--
How to understand the Jvm architecture in the common knowledge points of Java, aiming at this problem, this article introduces the corresponding analysis and solution in detail, hoping to help more partners who want to solve this problem to find a more simple and feasible method.
JVM is the abbreviation of Java Virtual Machine (Java Virtual Machine). JVM is a specification for computing devices. It is a fictional computer, which is realized by simulating various computer functions on a real computer. The Java virtual machine includes a set of bytecode instructions, a set of registers, a stack, a garbage collection heap, and a storage method domain. JVM shields the information related to the specific operating system platform, so that Java programs only need to generate the object code (bytecode) running on the Java virtual machine, and can run on a variety of platforms without modification. When JVM executes the bytecode, it actually interprets the bytecode as machine instruction execution on a specific platform.
two。 What is the relationship between JRE/JDK/JVM
JRE (Java Runtime Environment,Java runtime environment), that is, the Java platform. All Java programs can only be run under JRE. Ordinary users only need to run the developed java program and install JRE.
JDK (Java Development Kit) is a development kit used by program developers to compile and debug java programs. JDK's tool is also a Java program, which also requires JRE to run. In order to maintain the independence and integrity of JDK, JRE is also part of the installation of JDK. Therefore, under the installation directory of JDK, there is a directory called jre, which is used to store JRE files.
JVM (Java Virtual Machine,Java Virtual Machine) is part of JRE. It is a fictional computer, which is realized by simulating various computer functions on the actual computer. JVM has its own perfect hardware architecture, such as processors, stacks, registers, etc., as well as corresponding instruction systems. The most important feature of the Java language is that it runs across platforms. JVM is used to support operating system independent, cross-platform implementation.
three。 JVM principle
JVM is the core and foundation of java, a virtual processor between java compiler and os platform. It is a kind of abstract computer implemented by software method based on the lower operating system and hardware platform, on which the bytecode program of java can be executed.
The java compiler only needs to target JVM to generate code or bytecode files that JVM can understand. The Java source file is compiled into a bytecode program, and each instruction is translated into different platform machine code through JVM, which is run on a specific platform.
four。 JVM architecture
JVM is divided into three main subsystems:
Class loader subsystem
Runtime data area
Executive engine
1. Class loader subsystem
The dynamic class loading function of Java is handled by the class loader subsystem. When it first references a class at run time (not compile time), it loads, links, and initializes the class file.
Load
Class is loaded by this component. Starting class loaders (BootStrap class Loader), extended class loaders (Extension class Loader), and application class loaders (Application class Loader) help with class loading.
Boot classloader-responsible for loading classes from the startup classpath, nothing more than rt.jar. The loader will be given the highest priority.
Extension class loader-responsible for loading classes in the ext directory (jre\ lib).
Application class loader-responsible for loading the application-level classpath, involving the path environment variables and other etc.
The above class loader follows the delegate hierarchy algorithm (Delegation Hierarchy Algorithm) to load the class file.
Link
Check-the bytecode verifier will check whether the generated bytecode is correct, and if the check fails, we will get a check error.
Prepare-allocate memory and initialize default values to all static variables.
Parsing-all symbolic memory references are replaced by the original reference to the method area (Method Area).
Initialization
This is the final stage of class loading, where all static variables are assigned initial values and static blocks are executed.
two。 Runtime data area (Runtime Data Area)
The runtime data area is divided into five main components:
Method area (Method Area)
All class-level data will be stored here, including static variables. Each JVM has only one method area, which is a shared resource.
Stacking area (Heap Area)
All objects and their corresponding instance variables and arrays will be stored here. There is also only one stack area for each JVM. Because the memory of the method area and heap area is shared by multiple threads, the stored data is not thread-safe.
Stack (Stack Area)
A separate runtime stack is created for each thread. Calls to each function generate a stack frame (Stack Frame) in stack memory. All local variables will be created in stack memory. The stack area is thread-safe because it is not a shared resource. The stack frame is divided into three sub-entities:
Array of local variables-contains multiple local variables associated with the method and the corresponding values will be stored here.
Operand stack-if any intermediate operations need to be performed, the Operand stack acts as a runtime workspace to execute instructions.
Frame data-all symbols of the method are saved here. In the case of any exception, the information of the catch block will be saved in the frame data.
PC register
Each thread has a separate PC register to hold the address of the currently executing instruction, and once the instruction is executed, the pc register is updated to the address of the next instruction.
Local method stack
The local method stack holds local method information. For each thread, a separate local method stack is created.
3. Executive engine
The bytecode assigned to the runtime data area will be executed by the execution engine. The execution engine reads the bytecode and executes it segment by segment.
Interpreter
The interpreter can interpret bytecode quickly, but the execution is slow. The disadvantage of the interpreter is that when a method is called multiple times, it needs to be reinterpreted each time.
JIT compiler
The JIT compiler eliminates the shortcomings of interpreters. The execution engine uses the interpreter to convert the bytecode, but if the code is duplicated, the JIT compiler compiles all the bytecode into the cost machine code. Native code will be used directly for repeated method calls, which improves the performance of the system.
Intermediate code shengchengqi [prompts forbidden words]-generates intermediate code
Code optimizer-responsible for optimizing the intermediate code generated above
Object code shengchengqi [prompt forbidden words]-responsible for generating machine code or native code
Probe (Profiler)-A special component responsible for finding methods that have been called multiple times.
Garbage collector:
Collect and delete unreferenced objects. Garbage collection can be triggered by calling "System.gc ()", but there is no guarantee that garbage collection will actually take place. JVM's garbage collection collects only those objects created by the new keyword. So, if you don't create an object with new, you can use the finalize function to perform cleanup.
Java native interface (JNI): JNI interacts with the local method library and provides the local library needed by the execution engine.
Local method library: it is a collection of local libraries required by the execution engine.
After reading the above, have you mastered the method of Jvm architecture in the common knowledge points of Java? If you want to learn more skills or want to know more about it, you are welcome to follow the industry information channel, thank you for reading!
This is the answer to the question on how to understand the Jvm architecture in the common knowledge points of Java. I hope the above content can be of some help to you. If you still have a lot of doubts to be solved, you can follow the industry information channel to learn more about it.
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.