Understanding the basic structure of the Java Virtual machine---JVM (1)

Source: Internet
Author: User

1. Basic structure of the JVM

1.1. Class loading Subsystem

The class loading subsystem is responsible for loading class information from a file or network, and the loaded information is stored in the memory space of the method area. The method area may also contain run-time constant information, including string and numeric constants. (This part of the constant information is the memory map of the constant pool portion of the class file.)

1.2. Java Heap

The Java heap is created when the JVM is started, and almost all Java object instances are stored in the Java heap. Heap space is shared by all threads. Depending on the garbage collection mechanism, the Java heap may have different structures. One of the most common structures is to divide the whole heap into the Cenozoic and the old and the enduring generations.

1. Allocation of objects

Objects are first allocated in the Eden area, and after a young GC, if the object is still alive, it will enter S0 (from) or S1 (to). After each young GC, if the object survives, it will be 1 years old, when the object age reaches a certain condition, it will be considered an old age object, Thus entering the old age.

Package Com.hl.heap;public class Simleheap {public int id;public simleheap (int id) {this.id = ID;} public void Show () {System.out.println ("My ID is" + ID);} public static void Main (string[] args) {simleheap S1 = new Simleheap (1); Simleheap s2 = new Simleheap (2); S1.show (); S2.show ();}}

The information for the Simpleheap class is stored in the method area, and the S1 and S2 in the main function are stored in the Java stack and point to two instances in the heap.

1.3. Direct Memory

The Java NIO allows the Java program to use direct memory, which is directly outside the Java heap and directly requests the memory space to the system. Access to direct memory is usually faster than the Java heap, direct memory for frequent read and write scenarios, directly within the Java heap, so its size is not directly limited by the maximum heap size specified by XMX, but the Java heap and direct memory is still limited to the system's maximum memory.

1.4. Garbage collection System

The garbage collector reclaims the method area, the Java heap, and the direct memory.

1.5. Java stack

Each JVM thread has a private Java stack that is created when the Java stack is created. The Java stack holds local variables, method parameters, and calls to Java methods, and returns are closely related.

1.5.1 function call-access Java stack

The stack is a thread-private memory space, and the basic behavior of the thread execution is the function call, and each time the data for the function call is passed through the Java stack. Java stack is a piece of advanced data structure, only support the stack into the stack of two operations. The main content that is saved in the Java stack is the stack frame. Each time a function call, there will be a corresponding stack frame is pressed into the Java stack, each function call ends, there will be a stack frame is ejected Java stack. Java methods have two ways of returning functions, one is normal return, and the other is throwing an exception, either way, which causes the stack to be ejected. In a stack, you must include at least the local variable table, the operand stack, and several parts of the frame data area. The JVM provides the maximum space-XSS the specified line stacks, which determines the maximum depth of the function call.

Structure of the Java stack

1.5.1.1 local Variable table

It is used to hold the parameters of the function and local variables, the variables in the local variable table are only valid in the current function call, when the function call is finished, with the function stack frame destroyed, the local variable table will be destroyed. Because the local variable table is in the stack frame, if the function parameter and the local variable are more, it will cause the local variable table to swell, so that each function call will take up more stack space, resulting in a decrease in the number of nested calls of the function.

1.5.1.2 operand stacks

It is mainly used to save intermediate results during the calculation process and as a temporary storage space for variables in the calculation process. The operand stack is also an advanced data structure, which only supports both stack and stack operations.

1.5.1.3 Frame Data area

A pointer to a constant pool is kept in the frame data area, allowing the program to access the constant pool. When a function returns or an exception occurs, the virtual machine must restore the stack frame of the caller's function and let the caller function continue, and the virtual machine must have an exception handling table to find the code that handles the exception when the exception occurs, so the exception handling table is also an important part of the frame data area.

Allocate on 1.5.1.4 stack

is a JVM-optimized technology that, for private objects of which threads, can be scattered on the stack instead of allocated on the heap. When the function call is finished, it can destroy itself without the need for GC intervention, thus improving system performance.

1.6. Method area

Like the Java heap, a method area is a region of memory shared by all threads. It is used to save the class information of the system, such as the field of the class, method, Chang, etc., the size of the method area determines how many classes the system can save. In JDK1.7, the method area can be understood as the permanent zone in the JDK1.8 is completely removed, instead of the metadata area, the metadata area is a heap of memory, unlike the persistence zone, if the metadata area size is not specified, the virtual opportunity consumes the system memory until it runs out.

1.7. Local Method Stack

The local method stack is very similar to the Java stack, and the biggest difference is that the Java stack is used for Java method calls, while the local method stack is used to invoke the local method (DLL,SO).

1.8. PC (program Counter) register

It is also a private space for each thread, and the Java virtual Opportunity creates a PC register for each Java thread. At any point in time, a Java thread is always executing a method, and the method being executed is called the current method. If the current method is not a local method, the PC register points to the instruction that is currently being executed. If the current method is a local method, then the value of the PC register is undefined.

1.9. Execution engine

The byte code responsible for executing the virtual machine

Copyright Notice: This article is "Hanlin Small courtyard" (huhanlin.com) original article, reproduced when please indicate the source!

Understanding the basic structure of the Java Virtual machine---JVM (1)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.