Elementary knowledge of Jvm--java virtual machine

Source: Internet
Author: User

Block of memory at JVM runtime

    1. PC Register: (thread exclusive) Save thread run Java method address
    2. Java Virtual stack (thread exclusive): stack frame for storing threads
    3. Java heap (global share): As the startup of a Java Virtual machine creates an instance of all objects and an array object, and a built-in GC (garbage collection Mechanism)
    4. Method Area: Run a constant pool
    5. Local method Stack: thread-exclusive.

The GC (garbage collection mechanism) in the JVM is one of the Java standpoints. Automatic garbage collection allows Java programmers to reduce their ability to deal with memory and focus on business development and implementation.

The following points are required for garbage collection

    1. What objects can be recycled '
    2. When to recycle
    3. How to Recycle

There are two main types of object definitions for garbage collection:

    • Check if this object has a reference

For example: a =new a (); Then object A is quoted. But this way there is a deadlock, that is, there are two or more objects referencing each other, but these objects are useless. What to do?

    • Check to see if the object is up to the root object.

Only one root,root is directly or indirectly associated with other objects, and if the object is not reached at the root, then the object is "garbage"

There is no deadlock in the way that the root can be reached, which is the mainstream implementation of the JVM GC at present. Of course, the future is still a long way, perhaps there is a better algorithm to achieve it?

When is it recycled?

The generation of garbage objects is usually cycle recovery. A Java program that stops running when garbage is recycled

How to recycle?

    1. Mark-Clean: Mark the object as garbage first, then clean it up so that the space is not contiguous
    2. Copy: Divides the memory into two halves and then copies the valid copy to the other half. This sort of memory space is contiguous.
    3. Mark-Clean-up: Optimize for tag-cleanup and organize contiguous memory space.

Further optimization:

There are always some objects that will always exist such as static variables, thread pools ... These "old undead" there is no need to always check them, can reduce the inspection and cleaning cycle. So there is, the new generation, Laosheng generation, permanent generation

    • Cenozoic : New objects, which are usually local objects, are soon extinct after use. After several cycles, it will be upgraded to Laosheng generation with a survival rate of around 10%
    • Laosheng Generation : From the new generation upgraded to the Laosheng generation, has a more tenacious life, so the garbage cleanup algorithm and cycle are different from the Cenozoic
    • permanent Generation : the permanent generation is not impossible to die, clean or want is only a long period.

Elementary knowledge of Jvm--java virtual machine

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.