JVM Runtime Data Region resolution

Source: Internet
Author: User

There is a high wall between Java and C + + that is surrounded by dynamic memory allocations and garbage collection techniques, and people outside the walls want to go inside and the people inside the wall want to come out. The Java Virtual machine divides the memory it manages into several different data regions during the execution of a Java program. These zones have their own purpose, as well as the creation and destruction of time, and some regions exist as virtual machine processes start, and some are built and destroyed depending on the start and end of the user thread.
all threads share data area
thread-Isolated data area
First, the program counter (register)
    • Byte code line number indicator executed by the current thread
    • Byte code interpreter work dependent counter control complete
    • By executing the line octave number record, let the thread rotate between each thread to switch between the counters do not affect each other
    • Thread private, life cycle is the same as thread, born with JVM startup, JVM shuts down and dies
    • When a thread executes a Java method, it logs its executing virtual machine bytecode instruction address
    • When the thread executes the Nativan method, the counter record is empty (Undefined)
    • The only area in the Java Virtual Machine specification that does not stipulate any outofmemoryerror conditions
Program Counter Register is a small amount of memory space, and its function can be seen as the current thread execution of the byte code line number indicator. The bytecode interpreter works by changing the value of this counter to pick the next one that needs to be executed.bytecode instruction, branching, looping, jumping, exception handling, thread recoveryand other basic functions need to rely on this counter to complete. Because the multithreading of a Java Virtual machine is implemented in a way that threads take turns switching and allocating processor execution time, at any given moment, a processor (which is a kernel for a multi-drink processor) executes only the instructions in one thread. Therefore, in order to recover the thread after switching to the correct execution location, each thread needs to have a separate program counter, the counters between the threads do not affect each other, independent storage, we call this type of memory area is "thread-private" memory. If the thread is executing a Java method, this counter records the address of the executing virtual machine bytecode instruction, or null (Undefined) If the Natvie method is being executed. This memory area is the only area in the Java Virtual Machine specification that does not stipulate any outofmemoryerror conditions.
Second, Java Virtual machine stack
    • Thread private, life cycle is the same as thread
    • For storing local variables, operation stacks, dynamic links, method exits
    • Each method is called until the completion of the process, corresponding to a stack frame in the virtual machine stack from the stack to the process of the stack
Like the program counter, the Java Virtual machine stack (Java vitual Stacks) is also thread-private, with the same life cycle as the thread. The virtual machine stack describes the memory model that is executed by the Java method: Each time a method is executed, a stack frame is created to storelocal variable table, Operation Stack, dynamic link, method exitand other information. Each method is called until the completion of the process, corresponding to a stack frame in the virtual machine stack from the stack to the process of the stack.Local VariablesTableContains a variety of basic data types (Boolean, Byte, char, short, int, float, long, double) that the compiler has refrained from, and object references Reference) and bytecode instruction address (returnaddress type).
in the Java Virtual Machine specification, two exceptions are specified for this zone:
Stackoverflowerror exception is thrown if the thread requests a stack depth that is greater than the virtual machine's allowable depth;
if the virtual machine stack can be dynamically extended, an OutOfMemoryError exception is thrown when the extension fails to request enough memory.
If the computation in a thread requires a larger Java stacks or native method stack than is permitted, the Java virtual Mac Hine throws aStackoverflowerrorIn Oracle JVM, OutOfMemoryError in IBM JVM, using–xss<size> to set the maximum stack size. The default is a-KB for 32-bit JVMs and a KB for 64-bit JVMs.
third, the local method stackThe local methods Stack (Native method Stacks) 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 Native method service used by the virtual machine. The contents of this section are not Java cores and are not discussed carefully.

iv. java Heap
    • The Java heap (Java heap) is the largest piece of memory managed by a Java virtual machine
    • It is a piece of memory that is shared by all threads and created when the virtual machine is started
    • The heap is the runtime data area from which memory for all class instances and arrays are allocated.
The Java heap is the main battlefield for garbage collection management. According to the Java Virtual Machine specification, the Java heap can be in a physically discontinuous memory space, as long as it is logically contiguous, just like our disk space. When implemented, it can be either fixed-sized or extensible, although the current mainstream virtual machines are implemented in a scalable way. (Controlled by-XMX and-XMS) if there is no memory in the heap to complete the instance assignment, and the heap cannot be extended, a OutOfMemoryError exception will be thrown.
v. Method areasThe method area, like the Java heap, is an area of memory shared by each thread that stores data such as class information, constants, static variables, and code compiled by the immediate compiler that have been loaded by the virtual machine.       The Java Virtual Machine specification has a very loose limit on this area, and you can choose not to implement garbage collection, except that you do not need contiguous memory and can choose a fixed size or extensible, as with the Java heap. According to the Java Virtual Machine specification, a OutOfMemoryError exception is thrown when the method area does not meet the memory allocation requirements.

From for notes (Wiz)

JVM Runtime Data Region resolution

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.