Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

What is the architecture of JVM

2025-01-16 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >

Share

Shulou(Shulou.com)06/02 Report--

JVM architecture is what, I believe that many inexperienced people are helpless about this, this article summarizes the causes of the problem and solutions, through this article I hope you can solve this problem.

What is JVM?

A virtual machine is a software implementation of a physical machine. Java was developed with the concept of WORA(Write Once Run Anywhere), which runs on VMs. The compiler compiles Java files into Java .class files, then inputs the.class files into the JVM, which loads and executes the class files. Below is the JVM architecture diagram.

How does JVM work?

As shown, JVM is divided into three main subsystems:

class loader subsystem

runtime data area

execution engine

1. class loader subsystem

Java's dynamic class loading functionality is handled by the class loader subsystem. It's loaded with links. Class files are initialized at runtime, not when the class is first referenced at compile time.

1.1 loaded

Class will be loaded by the component. The boot class loader, extension class loader, and application class loader are three class loaders that help achieve this goal.

Boot Class Loader-responsible for loading classes from the boot classpath, nothing but rt.jar. This loader will get the highest priority.

Extension class loader-responsible for loading classes in ext folder **(jre\lib)**.

Application class loader-responsible for loading application-level classpath, path to the environment variable, etc.

The class loader described above follows a delegation hierarchy algorithm when loading class files.

1.2 link

Validation-Bytecode validator will verify that the generated bytecode is correct, if validation fails, we will get validation error.

Prepare-Memory assigns default values to all static variables.

Resolution-All symbolic memory references are replaced with the original references from the method area.

1.3 initialization

This is the final stage of class loading; here, all static variables are initialized and static blocks are executed.

2. runtime data area

The runtime data area is divided into five main components:

Method Area-All class-level data will be stored here, including static variables. Each JVM has only one method section, which is resource-shared.

Heap-All objects and their corresponding instance variables and arrays are stored here. Each JVM also has only one heap. Because the method area and heap are shared memory by multiple threads, the stored data is not thread-safe.

Stack-Each thread will create a separate runtime stack. Each method call generates an entry in stack memory called a stack frame. All local variables are created in stack memory. The stack area is thread-safe because it is not memory-shared.

The stack area is divided into three sections:

Local variable array-method dependent, where local variables and their corresponding values are stored.

Operand Stack-If any intermediate operations need to be performed, the operand stack acts as a runtime workspace to perform the operations.

Frame Data-All symbols corresponding to methods are stored here. In any exceptional case, catch block information is saved in the frame data.

PC registers-Each thread will have a separate PC register to hold the address of the currently executing instruction once the instruction is executed, the PC register can be updated smoothly to the next instruction.

Native method stack-Native method stack holds native method information. For each thread, a separate native method stack is created.

3. execution engine

Bytecodes assigned to runtime data areas are executed by the execution engine. The execution engine reads the bytecodes and executes them one by one.

Interpreters-Interpreters interpret bytecode faster, but execute slower. The disadvantage of interpreters is that when a method is called multiple times, a new interpretation is required each time.

JIT compiler

- JIT compilers eliminate the shortcomings of interpreters. The execution engine will use the interpreter's help when converting bytecode, but when it finds duplicate code, it uses the JIT compiler, which JIT compiles the entire bytecode and changes it to native code. This native code will be used directly for repeated method invocations, improving the performance of the system.

Intermediate Code Generator-Generate intermediate code

Code Optimizer-responsible for optimizing the intermediate code generated above

Object Code Generator-responsible for generating machine code or native code

Analyzer-A special component that looks for hot spots, i.e. whether a method is called multiple times.

Garbage collector: collects and removes unreferenced objects. Garbage collection can be triggered by calling System.gc(), but execution is not guaranteed. JVM garbage collection collects objects created.

Java Native Interface (JNI): JNI will interact with the native method library and provide the native libraries needed to execute the engine.

Native Method Library: This is the collection of native libraries needed to execute the engine.

After reading the above, do you have any idea what the JVM architecture is? If you still want to learn more skills or want to know more related content, welcome to pay attention to the industry information channel, thank you for reading!

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.

Share To

Internet Technology

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report