Understanding Java GC (i)

Source: Internet
Author: User

Introduction:       
Disclaimer: This document is translated fromSangmin Lee'sUnderstanding Java garbage Collection.Original link:http://www.cubrid.org/blog/dev-platform/understanding-java-garbage-collection/
What's the benefit of knowing how GC works in Java? First, it is the software engineer's curiosity to be satisfied, and secondly, to write more excellent Java applications.This is actually a personal and subjective idea, but I think as a good Java developer,Proficiency and proficiency in GC is a must. If you know the details of the GC's work, it means you can take control of the appthe size of the program. If you seriously consider how to choose the GC algorithm, then you have developed a program for yourthe features are completely manageable. Of course, this is not the norm for judging a good developer. However, theSome people think that GC is an essential skill for good Java developers. This article is the first in the series "Become a Java GC expert". This article will briefly explain the GC, follow-up, Iexamples of GC tuning and status analysis are analyzed. This article will introduce the next GC in a way that is easy to understand. I hope this article can really help you.In fact, my colleagues have published a lot of similar articles in the Java magazine, which are on Twittervery popular, you can also go to see.    text : Well, there are some terms we should know before we get to know the GC. "Stop-the-world", whetheryou see which GC algorithm, the word will appear. It means that the JVM stops running the current application and insteadto execute the GC. When "Stop-the-world" occurs, other threads will be interrupted except for the thread that performs the GC. These interrupted threads resume execution only after the GC work is complete. The so-called GC tuning means we're going to dropThe frequency at which the low GC executes, that is, the number of executions of "Stop-the-world".
The concept of "generation" in GC does not show the allocation and release of memory in code. Some people think that setting the object to null orCall the System.GC () method to display the free memory. Setting the object to null is easy, but calling System.GC ()To a large extent, the performance of the system is affected, so it is not recommended. (Fortunately, so far, I have notI saw a developer do that. )In Java, it is not necessary for developers to display free memory in the code. The GC will find out what's useless.object and Reclaim memory. The GC is created based on the following two presets. (That is, reasoning may be more accurate.) )1) The life cycle of most objects is short and fleeting; 2) The old Generation is controlled by the number of references to the new generation (young Generation). These two presets are the so-called "weak generational hypothesis". Therefore, in order to be morepersuasive, HotSpot VMs will be physically divided into young generation: and Old generationYoung generation: Most of the new objects are located here. Because most of the objects are soon useless., so most of the objects were created in young generation and then destroyed. When an object is destroyed here, we call itminor GC. Old Generation: objects that were not destroyed and survived in young generation are copiedto here. Old generation occupies a lot more space than young generation. Officially for this reason,The GC operates here less often than in young generation. When an object is destroyed here, we call itMajor GC or full GC. look at the words:


Figure 1:GC Area & Data Flow.

The permanent generation in the figure above is also known as Method area, where the class or built-in character set is stored. Note that this is not intended for an old generation object that has survived.          The GC is also recycled here and occurs in the major GC.        Some people may have questions: what if an old generation object refers to a young generation object? In order to deal with this situation, there is a "card table" in the old generation is designed to be, the size of a byte.When this happens, it is recorded in the card table. When the GC is executed at young generation, the table is scanned withoutTo check for references to all objects of the old generation to determine whether to recycle. This watch is managed by a Barrie called "write". This "write Barrie" can guarantee the high performance of the "minor GC". Maybe a high amount of consumption will be producedIn General, the GC's execution time has been shortened. :


Figure 2:card Table Structure.


Well, the first translation here tonight, the level is limited, the shortcomings of the hope that you correct. 2016-05-08 01:49

Understanding Java GC (i)

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.