Jvm running data distribution and jvm Data Distribution

Source: Internet
Author: User

Jvm running data distribution and jvm Data Distribution

I have a deep understanding of jvm (java se7 of this version)

Data Area During java Runtime

 

When executing a java program, the java Virtual Machine divides the memory into several different stages and has different time. Different purposes

 

 

First

 

 

Program counter: A small memory space in the jvm. It can be used as the row number of the bytecode file of the current thread. the bytecode interpreter obtains the next instruction by changing this value. Java multithreading is executed by switching the execution time of the processor in turn by threads. Everyone knows the principle of the Modern processor. Each time one core can only run one thread, due to interruptions, therefore, each program counter is independent. The memory of these program Counters is called the memory of the thread. If the thread executes the java method, the program counter refers to the address of the current bytecode instruction. If the native method is used, the program counter value is blank, in this region, the jvm does not define an OutOfMemoryError.

 

 

 

 

Virtual Machine Stack: for example, java memory is roughly divided into stacks. The local variable table in this virtual machine stack is the legendary stack, the thread is private, and the memory model for java method execution is described: each method creates a local variable table, operand stack, dynamic link, and method exit during execution. Each method is called and executed, it indicates a stack frame in the VM Stack from the inbound stack to the outbound stack. The local variable table stores the basic variables (boolean, int, double, float, char) known by the compiler ), there is also a reference type (), renturnAddress type (pointing to a bytecode address). The size of the local variable table is determined during compilation and will not change its size during running, the Virtual Machine stack returns two errors. The first is the requested stack frame greater than the depth of the Virtual Machine stack returns StackOverflowError. The second error is the dynamic expansion of the Virtual Machine stack, outOfMemoryError is reported when the application fails to reach the memory.

 

 

 

Local method Stack: similar to the Virtual Machine stack, but not the java method is the native method. The java specification does not require the virtual machine to freely implement THE native METHOD language and data format, stackOverflowError and OutOfMemoryError are also reported.

 

 

 

 

Java heap: first, it is shared by all threads. The VM starts to create a heap, which is mainly used to store object instances and arrays. the Java garbage processor mainly processes the java heap, therefore, java heap is also called a gc heap. From the perspective of memory collection, it can be divided into new and old generations. From the perspective of memory allocation, it can be divided into private memory regions of multiple threads. java Heap has multiple partitioning methods, but no matter how it is divided, it is a storage object instance. Multiple partitioning aims to better divide memory and reclaim memory, the java heap can be located in non-sequential memory space. As long as the logic is continuous, the java heap can be implemented to a fixed size or scalable size, if memory cannot be allocated to instance objects on the java stack, this OutOfMemoryError will be reported.

 

 

Method Area: The area shared by each thread. It stores the class information, constants, static variables, compiled code by the compiler, and the logical memory of the java heap, scalable implementation. The garbage collection in this region is mainly for the collection of constant pools and the type of garbage collection. The type of garbage collection requires a high level, but the necessary garbage collection is necessary, earlier versions have experienced severe memory leaks.

 

 

Constant pool during runtime: Class Name, method name, and constant in the compiled Class file will be stored in the running constant pool of the method after being loaded to the virtual machine, of course, constants can not only be stored in the constant pool during compilation, but also be stored in the string. intern () method (if the current string exists in the constant pool, the current string is directly returned. if this string does not exist in the constant pool, it is placed in the constant pool and then returned) to be put in the constant pool during running, of course, if the constant Pool cannot be applied to the memory, the classic error OutOfMemoryError will be reported.

 

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.