Java Memory Area

Source: Internet
Author: User

    1. 1. Java runtime data region

The Java Virtual machine divides the memory it manages into several different data regions during the execution of a Java program.

1.1 Program Counters

A program counter is a small amount of memory space, which can be seen as the line number indicator of the bytecode executed by the current thread. In the virtual machine concept model (only the conceptual model, a variety of virtual machines may be implemented in some more efficient way), the bytecode interpreter works by changing the value of this counter to select the next need to execute the byte code instruction, branch, loop, jump, exception handling, Basic functions such as thread recovery need to rely on this counter to complete.

1.2java Virtual Machine Stack

Like the program counter, the Java Virtual machine stack is also thread-private, with the same life cycle as the thread. The virtual machine stack describes the memory model that the Java method executes: Each method creates a stack frame to store information such as local variable tables, operand stacks, dynamic links, method exits, and so on. Each method from the call to the completion of the process, corresponding to a stack frame in the virtual machine stack into the stack of the process.

In the Java Virtual Machine specification, there are two exceptions to this area: if the thread requests a stack depth greater than the virtual machine allows, the STACKOVERFLOWERROR exception will be thrown, and if sufficient memory cannot be requested during the extension, The OutOfMemoryError exception is thrown.

1.2.1 Local variable table

The local variable table holds various basic data types, object references, and returnaddress types that are known during compilation. The 64-bit length of long and double data takes up 2 local variable space (slots), and the remaining data types occupy only 1. The memory space required for the local variable table is allocated during compilation.

1.3 Local Method Stack

The local method stack works very similarly to the virtual machine stack.

1.4java Heap

The Java heap is a piece of memory that is shared by all threads and created at virtual startup. The only purpose of this memory area is to hold object instances where almost all of the object instances are allocated.

The Java heap is the main area of garbage collector management, so it is often called a "gc heap". From the memory recovery point of view, Java Heap can also be subdivided into: the new generation and the old age, and then detailed can be divided into Eden space, from Survivor space, to survivor space.

The Java heap can be in a physically discontinuous memory space. The size can be controlled by-XMX and-xms, and a OutOfMemoryError exception will be thrown if there is no memory complete instance allocation in the push.

1.5 Method Area

The 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.

1.5.1 running a constant-volume pool

Running a constant pool is part of the method area. class file In addition to the class version, fields, methods, interfaces, and other descriptive information, there is a constant pool, for the compilation period generated by a variety of field volume and symbol reference, which will be loaded in the class load into the method area of the run constant pool.

It is also possible to put new constants into the pool during run time, which is more than the Intern () method of the string class used by developers.

Refer to the in-depth understanding of Java virtual machines

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.