JVM Interpretation: Java memory Area

Source: Internet
Author: User

The full name of the JVM is Java Virtual machine, which shields the software and hardware differences associated with each computer platform.
In the days to come, learn the JVM in the form of blogging to make yourself more aware of java!
This series is a summary of the in-depth analysis of javaweb Technology Insider and in-depth understanding of Java Virtual Machine, we welcome you to join together to make progress.
JVM Interpretation first: JVM architecture
"JVM Interpretation" second: JVM class loader ClassLoader

One of the great things that everyone knows about Java is that it does not require programmers to display the allocated memory and reclaim memory, because the virtual machine's automatic memory management mechanism helps us get this done. Let's take a look at how the virtual machine divides memory.
The area of memory that we divide the Java virtual machine into is called the runtime data region. These zones are called run-time data regions because they occur only after the JVM is started. Let's take a look at the classic picture.

Program counter

A program counter is a small amount of memory space that can be seen as the line number indicator of the bytecode executed by the current thread. Because the multithreading of a virtual machine is implemented in a way that threads take turns switching and allocating processor execution time, at any given moment, a processor executes only the instructions in one thread. In order to be able to return to the correct location after the thread switch, each of the threads need to have a separate program counter, which does not affect each other, independent storage, thread private.
If the thread is executing a Java method, this counter logs the virtual machine bytecode instruction address being executed, and if the local method is executed, this counter is empty

This memory area is the only area in the Java Virtual Machine specification that does not stipulate any outofmemoryerror conditions

Virtual Machine Stack

The virtual machine stack is also a thread-private memory area, the stack is always associated with the thread, whenever a thread is created, the JVM will create a corresponding virtual machine stack for this thread, this stack contains multiple stack frames, the stack frame is corresponding to the method, each run a method, will create a stack frame in this stack, The stack frame holds some internal variables, such as variables defined within the method, the method's entry parameters, the return value, and so on.
Each time a method executes, the stack frame pops up the stack frame element as the return value of the method, and clears the stack frame, the stack top of the Java stack is the current execution of the activity stack, is also executing the method, the address in the PC register to do this. Only the local variables of this activity stack can be used by the Operation Stack, and when another method is called in this stack frame, a new stack frame corresponding to it is created, the new stack frame is placed on the top of the stack and becomes the active stack frame, and when all the instructions in this stack frame are executed, the stack frame is removed. Just now the stack frame is also called the active stack frame, and the return value of the front stack frame becomes an operand in the stack frame's Operation Stack. If there is no return value, the operand of the current stack frame does not change.

Heap

A heap is a place where Java objects are stored, a core area of the JVM's management Java objects, each Java object stored in the heap is a copy of the object class, and it replicates all non-static attributes that inherit from the parent class. The heap is shared by all Java threads, and access to it is a matter of synchronization, and the methods and properties need to be consistent.

Method area

The JVM method area is where the class structure information is stored, and a class file is parsed into several parts that the JVM can recognize, and these different parts are stored in different data structures when the class is loaded into the JVM, where constant pools, fields, method data, method bodies, constructors, A proprietary method in the class, instance initialization, and interface initialization exist in this area.
In fact, the method zone is also a heap area, we are often referred to as the Java heap in the permanent zone (Permanent Generation), this area is shared by all threads, this area is usually fixed for a period of time after the program is started, after the JVM has been running for some time, The classes that need to be loaded are usually loaded into the JVM.
The special point of the method area is that it is not frequently recycled by the GC collector as it does in the Java heap, and the information it stores is relatively stable. However, it exists in the Java heap and is still managed by the GC collector.

Run a constant-rate pool

The run-time pool is part of the method area, and in addition to the classes ' versions, fields, methods, and so on, there is a constant pool that holds the various literal and symbolic references generated during the compilation period, and this section loads the run-times pool that the class will load into the method area.

Local method Stack

The local method stack is a space prepared for the JVM to run local methods, similar in function to the Java stack.
These are the partitions of the data area when the virtual runtime is running. The following is a brief introduction to the Direct memory . Direct memory is not part of the data area when the virtual machine is running, nor is it defined in the Java VM specification, but this portion of memory is also used frequently, which can also cause outofmemoryerror anomalies to occur.
After java1.4, a new Input/output class is introduced, which introduces a channel-to-buffer-based I/O method to directly allocate out-of-heap memory directly using a local library of functions. It then operates through a reference to the memory of the Directbytebuffer object that is stored in the Java heap at the latest. Performance can be significantly improved because the Java heap and the native heap are prevented from replicating data back and forth.

Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.

JVM Interpretation: Java memory 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.