Data zone during Java VM running

Source: Internet
Author: User

Java Virtual Machine is executing JavaProgramThe memory it manages is divided into several different data regions.

It mainly includes the method area, heap area, virtual machine stack, local method stack, and program counter.

The method area and heap area share all the sub-threads of the process, and others are unique to the thread.

 

Program counters

A program counter is a small memory space. Its function can be seen as a row number indicator of the bytecode executed by the current thread. Each thread has an independent program counter, and the counters between threads do not affect each other. It is stored independently and is the private memory of the thread.

Java Virtual Machine stack and local method Stack

The role of the local method stack is very similar to that of the Virtual Machine stack. The difference is that the virtual machine stack executes the Java method, while the local method stack is the native method service used by the virtual machine, sun hotspot combines the two into one. The local method Stack also throws stackoverflowerror and outofmemeoryerror exceptions.

Java heap

Java heap is the main area for managing the Garbage Collector. Therefore, it is often called GC heap. Java heap is a memory area shared by all threads and is created when a virtual machine is started. The only purpose of this region is to store object instances, where almost all object instances are allocated memory.

Method Area

The method area is the same as the Java heap. It is the memory area shared by various threads. It is used to store class information, constants, and static variables loaded by virtual machines. Real-time compiler compiledCodeAnd other data.

Runtime constant pool

The runtime constant pool is part of the method area. It is used to store various literal quantities and symbolic references generated by the compiler. It is also restricted by the method's memory removal. When the constant Pool cannot be applied for memory, an outofmemoryerror exception will be thrown.

Direct Memory

Direct Memory is not part of the VM runtime data zone, nor is it the memory zone defined in the VM specification.

 

Outofmemoryerrot exception

 

Java Heap Overflow

The Java heap is used to store object instances. As long as you constantly create objects and ensure that there is an accessible path between GC roots and objects, the garbage collection mechanism prevents these objects from being cleared, A memory overflow exception occurs when the number of objects reaches the maximum heap capacity limit.

 

Virtual Machine and local method Stack Overflow

 

Running frequent volume pool overflow

To add content to the runtime constant pool, use the string. Intern () Native method. The function of this method is: if the pool already contains a string equal to this string object, a string object representing this string in the pool is returned; otherwise, add the string contained in this string object to the constant pool and return a reference to this string object. Because the constant pool is allocated in the method area, you can use-XX: permsize and-XX: maxpermsize to indirectly limit the capacity of the constant pool in the method area.

 

Method Overflow

 

Local direct memory overflow

Directmemory capacity can be specified through parameters. If this parameter is not specified, the maximum value of the Java heap is the same by default.

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.