Java Advanced Chapter (second, JVM memory model, memory management)

Source: Internet
Author: User

JVM memory structures such as

    • The Java heap, which is the largest piece of memory managed by a Java virtual machine. The Java heap is a piece of memory that is shared by all threads and created when the virtual machine is started. The only purpose of this area of memory is to hold object instances where almost all of the object instances are allocated memory.
    • 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.
    • The program counter (program Counter Register), which is a smaller memory space, functions as a line number indicator of the byte code executed by the current thread.
    • JVM Stack (JVM Stacks), like program counters, the Java Virtual machine stack (Java 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 store the local variable table, the Operation Stack, the dynamic link, the method exit, and so on. 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.
    • The local method Stack (Native methods Stacks), the local method stack (Native methods Stacks) and the virtual machine stack play a very similar role, the difference is that the virtual machine stack for virtual machines to execute Java methods (that is, bytecode) service, The local method stack is a service to the native method used by the virtual machine.

Object Assignment Rules

    • The object is first allocated in the Eden area, and the virtual machine executes the minor GC once if there is not enough space in the Eden area.
    • Large objects go directly into the old age (large objects are objects that require a large amount of contiguous memory space). This is done to avoid a large amount of memory copying between the Eden Zone and the two survivor zones (the Cenozoic uses a replication algorithm to collect memory).
    • Long-term survival of the object into the old age. The virtual machine defines an age counter for each object, and if the object passes through 1 minor GC then the object will enter the Survivor area, then each time after the minor GC so the object's age plus 1, know to reach the threshold object into the old age area.
    • Determines the age of the object dynamically. If the sum of all objects of the same age in the survivor area is greater than half the size of survivor space, objects older than or equal to that age can enter the old age directly.
    • Space allocation guarantee. Each time the minor GC is performed, the JVM calculates the average size of the objects moved to the old age area of the survivor area, and if the value is greater than the remaining value of the old age area, a full GC is performed, and if it is less than the check handlepromotionfailure setting, If true, only the monitor GC is performed, and if False the full GC is performed.

Java Advanced Chapter (second, JVM memory model, memory management)

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.