Java garbage Collection (1) __java

Source: Internet
Author: User
Tags garbage collection

This article is the first article on the garbage Collection (GC) series. I hope this series of courses will cover some of the principles of garbage collection and some of the major garbage collector in the hotspot virtual machine. This article simply describes what is a common element of garbage collection and different garbage collectors.

Why should we care about garbage collection.

Java Virtual machines manage memory for you, which is handy, but by default it may not turn on optimal optimizations. By understanding some of the principles behind garbage collection, you can easily adjust your collector. A common problem is the efficiency of the garbage collector, which means how long your program takes to execute program code instead of recycling garbage. Another common problem is how long the application pauses.

There are a lot of rumors and rumors about garbage collection, so a detailed understanding of garbage collection algorithms can really help avoid pitfalls and traps. In addition, the internal mechanism of the JVM is well worth seeing for those interested in how the principles of computer science are applied and used.

what does Stop-the-world mean.

Your program (called Mutator in GC) allocates objects at run time, and at some point heap needs to be recycled and all the collectors on hotspot suspend your application, Stop-the-world the term is used to indicate that all mutator processes are paused.

It is possible to implement a garbage collector that does not need to suspend applications, and Azul has implemented a very efficient and no pause collector in the zing virtual machine. This article is not going to discuss how this collector works, but if you are interested and want to know more about this collector, you can see his white paper.

Cenozoic and weak age hypothesis (the young/weak generational hypothesis)

Simply put: Most of the objects that are assigned will soon become inaccessible after they are created. This concept was validated in the 1980s by analyzing the memory allocation and active patterns of a large number of projects. The researchers also found that not only most of the assigned objects would soon become inaccessible after they were created, but that they would exist for a long time once their life cycle reached a specific point. The following picture is from the Sun/oracle study, which shows the life of the object in the form of a histogram.

how the Heap (HEAP) is organized (how is Heap organised).

The Cenozoic hypothesis (young generational hypothesis) introduces the concept of generational garbage collection (generational garbage collection), in which the heap is divided into many regions, The objects placed in each zone are related to their age (object generation time). These garbage collectors (except G1), which are based on the concept of generational garbage collection, have one thing in common: the heap (HEAP) is organized into different spaces.

When objects are initially allocated, they are stored in the Eden space if appropriate. If an object survives a garbage collection, it will eventually be moved to the survivor (survivor) space. When these objects survive in the Survivor (survivor) space for a period of time (an old age-time threshold), they are moved to the older generation (tenured) space. The algorithm properties for reclaiming these spaces vary by collector.

Space separation has many benefits because it allows you to use different algorithms in different spaces. Some GC algorithms are very effective when most objects are unreachable, and some GC algorithms are very effective when most objects are up to date. Because the generational hypothesis (generational hypothesis) is usually a collection of most unreachable objects in the Eden and survivor spaces, most objects are accessible in the old age (tenured) space.

There are also permanent (PermGen) or permanent generations (permanent generation). This particular space is primarily about controlling some of the objects associated with the Java language itself. For example, this holds the information for the loaded class. The permanent generation has been removed in the Java8 and replaced by the Meta Space (metaspace).

several garbage collector

Hotspot virtual machines actually have a lot of different garbage collector. Each garbage collector has different performance characteristics and more (or less) applicable tasks. Some of the more critical garbage collector are as follows:

Parallel Scavenge (PS): The default collector for the recently released JVMs. Stops-the-world are for garbage collection, but are recycled in parallel (for example, using multithreading).

Concurrent Mark Sweep (CMS): There are many stages to this collector, including the Stop the world, but in many stages the collector is running at the same time as the program when it recycles garbage.

incremental Concurrent Mark Sweep (ICMS): A variant of the CMS, designed primarily to reduce application pauses.

Garbage (G1): Recently very stable new collectors, the use of the volume is slowly rising.

Original: https://www.javacodegeeks.com/2013/06/garbage-collection-in-java-1.html

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.