`
finalbone
  • 浏览: 55591 次
  • 性别: Icon_minigender_1
  • 来自: 海边
社区版块
存档分类
最新评论

The Garbage-First Garbage Collector

阅读更多

The Garbage-First Garbage Collector (or G1 GC for short) is a new GC that is being introduced in the Java HotSpot VM in JDK 7. An experimental version of G1 has also been released in Java SE 6 Update 14. G1 is the long-term replacement for HotSpot's low-latency Concurrent Mark-Sweep GC (widely referred to as CMS).

Attributes

G1 is a “server-style” GC and has the following attributes.

  • Parallelism and Concurrency. G1 takes advantage of the parallelism that exists in hardware today. It uses all available CPUs (cores, hardware threads, etc.) to speed up its “stop-the-world” pauses when an application's Java threads are stopped to enable GC. It also works concurrently with running Java threads to minimize whole-heap operations during stop-the-world pauses.
  • Generational. Like the other HotSpot GC's, G1 is generational, meaning it treats newly-allocated (aka young) objects and objects that have lived for some time (aka old) differently. It concentrates garbage collection activity on young objects, as they are the ones most likely to be reclaimable, while visiting old objects infrequently. For most Java applications, generational garbage collection has major efficiency advantages over alternative schemes.
  • Compaction. Unlike CMS, G1 performs heap compaction over time. Compaction eliminates potential fragmentation problems to ensure smooth and consistent long-running operation.
  • Predictability. G1 is expected to be more predictable than CMS. This is largely due to the elimination of fragmentation issues that can negatively affect stop-the-world pause times in CMS. Additionally, G1 has a pause prediction model that, in many situations, allows it to often meet (or rarely exceed) a pause time target.

Description

G1 takes a very different approach to heap layout than other HotSpot GCs. In G1, there is no physical separation between the young and old generations. Instead, there is a single contiguous heap which is split into same-sized regions. The young generation is a set of potentially non-contiguous regions, and the same is true for the old generation. This allows G1 to flexibly move resources as needed from the old to the young generation, and vice versa.

Collection in G1 takes place through evacuation pauses, during which the survivors from a set of regions referred to as the collection set are evacuated to another set of regions (the to-space) so that the collection set regions can then be reclaimed. Evacuation pauses are done in parallel, with all available CPUs participating. Most evacuation pauses collect the available young regions, thus are the equivalent of young collections in other HotSpot GCs. Occasionally, select old regions may also be collected during these pauses because G1 piggybacks old generation collection activity on young collections.

Like CMS, G1 periodically performs a concurrent marking phase. The main role of this phase is to identify which old regions are mostly full of garbage objects, as these are the most efficient and desirable to collect. Unlike CMS, G1 does not perform a concurrent sweeping phase. Instead, the most profitable old regions identified by the concurrent marking phase are collected during subsequent evacuation pauses (the piggybacking mentioned above).

Using G1

G1 is still considered experimental and can be enabled with the following two parameters:

-XX:+UnlockExperimentalVMOptions -XX:+UseG1GC

To set a GC pause time goal, use the following parameter:

-XX:MaxGCPauseMillis =50 (for a pause time target of 50ms)

With G1, a time interval can be specified during which a GC pause should last no longer than the time given above:

-XX:GCPauseIntervalMillis =200 (for a pause interval target of 200ms)

Note that the above two options represent goals, not promises or guarantees. They might work well in some situations but not in others, and the GC might not always be able to obey them.

Alternatively, the size of the young generation can be specified explicitly to impact evacuation pause times:

-XX:+G1YoungGenSize=512m (for a 512 megabyte young generation)

G1 also uses the equivalent of survivor spaces, which are, naturally, a set of (potentially non-contiguous) regions. Their size can be specified with the usual parameters (e.g., -XX:SurvivorRatio=6).

Finally, to run G1 at its full potential, try setting these two parameters which are currently disabled by default because they may uncover a rare race condition:

-XX:+G1ParallelRSetUpdatingEnabled -XX:+G1ParallelRSetScanningEnabled

One more thing to note is that G1 is very verbose compared to other HotSpot GCs when -XX:+PrintGCDetails is set. This is because it prints per-GC-thread timings and other information very helpful in profiling and trouble-shooting. If you want a more concise GC log, please switch to using -verbosegc (though it is recommended that the more detailed GC log be obtained).

Status

G1 development is now focused primarily on resolving any remaining reliability issues and improving performance, and also on removing the following limitations:

  • G1 does not fully support the JVM Tool Interface (JVM TI) or Java Management Extensions (JMX), so it is likely that monitoring and management tools will not work correctly with G1.
  • G1 does not support incremental permanent generation collection. If an application does a lot of class unloading and requires permanent generation collection, this will be done during Full GCs.
  • In terms of GC pause times, G1 is sometimes better and sometimes worse than CMS. Work is ongoing to make G1 consistently as good as, if not better than, CMS.

Resources

分享到:
评论

相关推荐

    Garbage-First LSM 论文

    Garbage-First is a server-style garbage collector, targeted for multi-processors with large memories, that meets a soft real-time goal with high probability, while achieving high throughput. Whole-...

    Java.Performance.Companion.0133796825

    this book provides unprecedented detail on two powerful Java platform innovations: the Garbage First (G1) garbage collector and the HotSpot VM Serviceability Agent. Coverage includes Leveraging G1 ...

    JAVA白皮书(英文版)

    1. Introduction to Java ... 10.4.1The First Layer--the Java Language Interpreter 10.4.2The Next Layer--the Higher Level Protocols 10.5HotJava--the Promise 11. Further Reading

    Java Performance Companion(Addison,2016)

    this book provides unprecedented detail on two powerful Java platform innovations: the Garbage First (G1) garbage collector and the HotSpot VM Serviceability Agent. Coverage includes Leveraging G1 ...

    Ruby.Performance.Optimization

    First, you'll learn the best practices for writing Ruby code that's easy not only on the CPU, but also on memory, and that doesn't trigger the dreaded garbage collector. You'll find out that garbage ...

    Java9中的GC调优基础

    Java9引入了很多新的特性,除了闪瞎眼的ModuleSystem和REPL,最重要的变化我认为是默认GC(GarbageCollector)修改为新一代更复杂、更全面、性能更好的G1(Garbage-First)。JDK的维护者在GC选择上一直是比较保守的...

    Ruby Performance Optimization, Why Ruby is Slow, and How to Fix It

    First, you’ll learn the best practices for writing Ruby code that’s easy not only on the CPU, but also on memory, and that doesn’t trigger the dreaded garbage collector. You’ll find out that ...

    java7帮助文档

    Garbage-First Collector is a server-style garbage collector that replaces the Concurrent Mark-Sweep Collector (CMS). Java HotSpot Virtual Machine Performance Enhancements JDBC 4.1 JDBC 4.1 ...

    Beginning Ruby(Apress,3ed,2016)

    Based on the bestselling first and second editions, Beginning Ruby, 3rd Edition is a leading guide to learn Ruby from the ground up. The new edition of this book provides the same excellent ...

    Ruby Performance Optimization(Pragmatic,2015)

    First, you’ll learn the best practices for writing Ruby code that’s easy not only on the CPU, but also on memory, and that doesn’t trigger the dreaded garbage collector. You’ll find out that ...

    eric5-5.3.1

    This is a tool to detect variable cycles which can cause the garbage collector being unable to do his job. Interfaces to additional software packages via plugins Some of the interfaces ...

    Cocoa® Programming for Mac® OS X, Third Edition

    And you will know enough to write your own stylish code. <br>Updated for Mac OS X 10.4 and 10.5, this revised edition includes coverage of Xcode 3, Objective-C 2, Core Data, the garbage collector,...

    Program in LUA 2nd Edition.rar

    Contents Preface xiii I The Language 1 1 Getting Started 3 1.1 Chunks 4 1.2 Some Lexical Conventions 5 ...1.4 The Stand-Alone Interpreter 7 ...31.2 The Garbage Collector 295 Index 299

    DbfDotNet_version_1.0_Source

    In Dbf.Net you don't have to write any code, if you don't want to wait for the garbage collector to collect your individual you can call SaveChanges. Dbf.Net ADO.Net Collapse Copy Codevoid ...

    javacv-platform-1.3.3-src

    // by the garbage collector, but may still be explicitly released by calling release(). // You shall NOT call cvReleaseImage(), cvReleaseMemStorage(), etc. on objects allocated this way. ...

    php.ini-development

    The following are all the settings which are different in either the production ; or development versions of the INIs with respect to PHP's default behavior. ; Please see the actual settings later in...

    操作系统(内存管理)

    /* The memory we search for has to include the memory * control block, but the users of malloc don't need * to know this, so we'll just add it in for them. */ numbytes = numbytes + sizeof...

    Thinking in Java 4th Edition

    How a garbage collector works .. 122 Member initialization ......... 125 Specifying initialization ............. 126 Constructor initialization ... 127 Order of initialization ................ 127 ...

Global site tag (gtag.js) - Google Analytics