Memory distribution of Java virtual machines

Source: Internet
Author: User

Java Virtual machine memory is divided into five regions: method Area, heap, virtual machine stack, local method stack, program counter. Where the method area and heap are the memory areas shared by the Java Virtual machine, the virtual machine stack, the local method stack, and the program counter is thread-private.


  1. Program Counter Register):
    The line number indicator of the current thread executing the bytecode. By changing the value of this indicator, select the next byte-code directive that needs to be executed. This memory area is the only area in the Java virtual machine that does not have a outofmemeryerror defined.

  2. Java Virtual machines Stack (Java Visual machine Stacks):
    The virtual machine stack describes the memory model that is executed by the Java method: Each method execution creates a stack frame that stores information such as local variables, operations stacks, method information, dynamic links, method exits, and so on.
    In the Java Virtual Machine specification, there are two exceptions for both zones: 1) If the thread requests a stack depth greater than the virtual machine allows, the STACKOVERFLOWERROR exception will be thrown, and 2) the Java Virtual machine can be dynamically extended, Outofmemeryerror is thrown when sufficient memory cannot be requested

  3. Local methods Stack (Native method Stacks)
    The local method stack is very similar to the Java Virtual machine stack, except that the Java virtual machine stack executes Java method services for the virtual machine, and the local method stack is the native method service used by the virtual machine.
    So the local method stack may also have two exceptions that are identical to the Java Virtual machine stack.

  4. Java heap (Java heaps)
    The Java heap is the largest chunk of memory that the Java Virtual Machine manages, and the Java heap is shared by all Java threads and created at the start of the Java Virtual machine, the only purpose of which is to hold the object instance. Almost all object instances are allocated in the heap. (with the development of JIT compiler, the gradual maturation of escape analysis technology, stack allocation, scalar substitution and other optimization techniques, so that some objects are no longer allocated on the heap.) )
    The size of the Java heap is controlled by the-xmx and-xms two parameters. However, when the heap's memory is no longer expandable, outofmemeryerror will appear.

  5. Method area
    The method area, like the Java heap, is a memory area shared by each thread that stores data such as class information, constants, static variables, and compiled code in a timely manner. Outofmemeryerror is thrown when the method area does not meet the memory allocation requirements.


Memory distribution of Java virtual machines

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.