Java-----JVM Runtime Data area

Source: Internet
Author: User

I. JVM architecture

To understand the runtime data area, first look at the architecture of the JVM and know the overall location and role of the data area in the JVM.

Second, JVM runtime data area 1. Program counter

A smaller memory space, which is the line number indicator of the byte code executed by the current thread , and the bytecode interpreter works by changing the value of the counter to select the next byte-code instruction to be executed, and the basic functions such as branching, jumping, and looping are all dependent on it for implementation. Each thread has a separate program counter, and the counters between the threads do not affect each other, so the zone is thread-private .

When a thread executes a Java method, the counter records the address of the executing virtual machine bytecode instruction, and when the thread executes the native method (called the local operating system method), the value of the counter is empty. In addition, the memory area is the only area in the Java Virtual Machine specification that does not specify any oom (memory overflow: outofmemoryerror) condition.

2.Java virtual machine Stack-JVM Stacks

The JVM stack is thread-private , and each thread creates a JVM stack, and the Java Virtual Machine performs two operations on the Java stack: a stack of frames and a stack.

Whenever a thread calls a Java method, the virtual machine will be a new stack frame in the Java stack of the thread. This stack frame stores data such as parameters of the method, local variables, intermediate results, and so on.

Stack frame

Consists of three parts: local variable, operand stack and frame data area

Local Variables: contains parameters and local variables for the corresponding method , the local variable area stores the data in terms of word length, and is an array space that counts from 0, data type int, float, Object references reference and returnaddress are stored in a storage space, and the values of type Byte, short, and char are converted to int values before they are deposited into the array. Also occupies one storage space at a time, and long and double occupy two contiguous storage spaces in the array.

You can see that at 0 the location stores an implied variable this, with the old representation of the object itself that called the method.

The class method does not have this, because the class method is only related to the class. Regardless of the specific object.

Operand stacks

Virtual machine in the operation of the stack is stored in the operation of the operand and the results of the operation is the compression stack and the stack , the data is stored in the same way as the local variables stored in the same way.

Java Virtual machine China is not a register, which is compatible with the JVM platform-independent features, the virtual machine to the operation of the stack as his workspace, most of the instructions will pop up from here data, perform operations, and then press the results back to the operand stack

Frame Data area

Java stack frames also require some data to support constant pool parsing, normal method return, and exception dispatch, which are stored in the frame data area of the Java stack frame

3. Local methods Stack (Native method Stacks)

This area is very similar to the virtual machine stack, except that the virtual machine stack executes Java method services for the virtual machine, while the local method stack is the local operating system (Native) method service that is used.

4.Java Heap (Java heap)

It is the area where the JVM stores object instances and array values, and it can be assumed that all the memory of objects created by new in Java is allocated here, and that the memory of the objects in the heap needs to wait for the GC to recycle.

5. Method area

The method area is also a very important area in the JVM, which, like the heap, is a thread-shared area . In the method area, information is stored for each class (including the name of the class, method information, field information), static variables, constants, and compiler-compiled code.

In the class file, in addition to the description of the fields, methods, interfaces, and so on, there is a constant pool that stores the literal and symbolic references generated during compilation.

A very important part of the method area is the run-time pool, which is the runtime representation of the constant pool of each class or interface, which is created when classes and interfaces are loaded into the JVM. Of course, not the contents of the class file constant pool can enter the run-time pool, and the new constants can be placed in the run constant pool during runtime, such as The Intern method of string.

In the JVM specification, there is no mandatory requirement for the method area to implement garbage collection. Many people are accustomed to calling the method area "permanent generation" because the hotspot virtual machine implements the method area as a permanent generation, so that the JVM's garbage collector can manage this part of the area as if it were managed by the heap, eliminating the need to specifically design a garbage collection mechanism for this part. Since JDK7, however, the hotspot virtual machine has removed the run-time constant pool from the permanent generation.

Summarize:

Java-----JVM Runtime Data area

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.