`
C_J
  • 浏览: 127851 次
  • 性别: Icon_minigender_1
  • 来自: 北京
社区版块
存档分类
最新评论

关于Azul 并发垃圾回收器

阅读更多

题记:

    总感觉JE讨论的帖子的东西都比较滞后,所以会有意多关注下infoQ上的东西,看看大洋彼岸的程序员们都在关心着什么。本文是说垃圾回收的,原文:http://www.infoq.com/articles/azul_gc_in_detail

根据个人体会和理解,筛选出了文章的重点.

Introduction

Automatic garbage collection frees the programmer from much of the worry about releasing objects that are no longer neededIt also prevents some kinds of common bugs occurring, including certain kinds of memory leaks, dangling pointer bugs (which occur when a piece of memory is freed while there are still pointers to it and one of those pointers is then used) and double free bugs (which occur when the program tries to free a region of memory that has already been freed and perhaps already been allocated again).

垃圾回收机制让程序员不用关心内存释放以及常见的内存错误,比如memory leak,dangling pointer,double free。

it does also have some problems. The most significant is that thus far, practical implementations of garbage collection in commercial Java runtimes have generally involved an unpredictable "pause" during collection.

但这种垃圾回收也存在一些问题,比如JVM的GC在垃圾回收过程中会不可预期地暂停应用线程#应该跟GC的单线程回收有关#

 

As Java programs have expanded in size and complexity, so the garbage collection pause has become an increasingly significant problem for Java software architects.

随着程序越来越复杂,这种回收的pause越来越频繁。

 

A widely used technique in enterprise Java to work around this is to distribute programs. This can both keep the heap size smaller, making the pauses shorter, and also allow some requests to continue whilst others are paused. Increasingly though, this means that Garbage Collector (GC) managed workloads are unable to take full advantage of the capabilities of the hardware on which they run.

 

一种普遍的解决方案是“云”,把程序拆分成集群,这样每台机器heap足够小,减少回收的次数,从而减少pause,且可持续响应用户的请求,但这样GC的回收从某种意义上来说没得到足够的利用。作者还认为当前GC的发展滞后于硬件的发展。

 

 

Collector Mechanisms

Common Tasks

要实现一个collector,必须要做到:

 

  • Identifying the live objects in the memory heap 标记live内存
  • Reclaiming the resources used by those objects that are not live (aka “dead” objects) 回收内存
  • Periodically relocating live objects to create some amount of contiguous free space in order to accommodate the allocation of new objects of varying sizes – this process is referred to as either relocation or compaction

 

Parallelism and Concurrency

Garbage collectors can be either single-threaded or parallel:

回收可以是单线程,也可以是多线程的

  • A single threaded collector uses at most one CPU core to perform garbage collection.
  • A parallel collector uses multiple threads that can perform collection work at the same time, and can therefore make simultaneous use of more than one CPU core

They are also either Stop-the-world or Concurrent:

所以GC也可以是并发的

  • A Stop the world collector performs garbage collection work with the application code stopped.
  • A concurrent collector performs garbage collection work concurrently with program execution, allowing program execution to proceed while collection is done (potentially using separate CPU cores)这种并发的GC可以于业务代码同时运行,GC的回收不会打扰你程序的运行。

Responsiveness and Sensitivity

反应时间和敏感度

 

 

The Azul Garbage Collector

Azul's GPGC collector (which stands for Generational Pauseless Garbage Collector), included in its HotSpot-based JVM, is both parallel and concurrent. GPGC has been widely used in a number of production systems for several years now, and has been successful at removing or significantly reducing sensitivity to the factors that typically cause other concurrent collectors to pause.

 

说道这个GC在一些产品中应用了多年并成功避免了其他并发回收器的“失效”。

 

Azul用到的一些原理:

 

The Loaded Value Barrier

“Self Healing”

How the Azul Algorithm Works

详细没看了,估计看了也不太明白。

 

 

Comparison with existing Garbage Collectors

HotSpot’s Concurrent Mark Sweep (CMS) is a mostly concurrent collector. It performs some garbage collection operations concurrently with program execution, but leaves some operations to long stop-the-world pauses. Tene described it as follows:

Hotspot’s CMS collector uses a full, stop-the-world parallel new generation collector which compacts the new generation on every pass. Since young generation collection is very efficient, this stop-the-world pass typically completes very quickly - in the order of 100s of milliseconds or less.

CMS uses a mostly-concurrent collector for OldGen. It has a mostly concurrent, multipass marker that marks the heap while the mutator is running, and tracks mutations as they happen. It then revisits these mutations and repeats the marking. CMS does a final stop-the-world “catch up” marking of mutations, and also processes all weak and soft refs in a stop-the-world pause.

CMS does not compact concurrently. Instead, it does concurrent sweeping, maintains a free-list, and attempts to satisfy old generation allocations from this free list. However, because the free list is not compacted, free space will inevitably be fragmented, and CMS falls back to a full stop-the-world to compact the heap.

 

 

Oracle’s experimental Garbage First (G1) collector, which is expected to ship as part of Java 7, is an incrementally compacting collector that uses a snapshot-at-the-beginning (henceforth SATB) concurrent marking algorithm and stop-the-world compaction pauses to compact only parts of the heap in each pause. G1 allows the user to set pause time goals, and uses these goal inputs along with topology information collected during its mark phase in order to compact a limited amount of heap space in each pause, in an attempt to contain the amount of the heap references that need to be scanned during each pause.

Tene explains that, given its experimental state, it is still early to tell how G1 will fare with real applications. According to Tene, while G1 is intended to incrementally improve upon CMS’s handling of fragmentation, its compactions are still performed in complete stop-the-world conditions, and its ability to limit the length of incremental compaction pauses strongly depends on an application’s specific heap topology and object relationships. Applications with popular objects or popular heap portions will still experience long stop-the-world pauses when the entire heap needs to be scanned for references that need remapping, and those long pauses, while less frequent, will be no shorter than those experienced by the current CMS collector. As Tene puts it:

If a collector includes code that performs a full heap scan in stop-the-world conditions, that code is intended to run at some point, and application should expect to eventually experience such pauses.

Whilst G1 attempts to improve determinism, it cannot guarantee it. Tene explained:

It does let the user set pause time goals, but will only “try” to follow those goals. Even if OS scheduling was perfect, G1 would not guarantee determinism as its ability to contain individual compaction pauses is inherently sensitive to heap shape. Popular objects and (more importantly) popular heap regions (regions referred to from many other regions, but do not necessarily need to have popular individual objects) will cause G1 to eventually perform a full heap compaction in a single pause if they were to be compacted… Real application patterns (such as slowly churning LRU caches that get lots of hits) will exhibit such heap relationships in the vast majority of the heap, forcing G1 to perform what is effectively full compaction remap scans in a single pause…

A previous InfoQ article provides more of the technical details.

Conclusion

With the introduction of Zing, Azul has made pauseless garbage collection available in a pure software product on commodity hardware, making it more consumable and much easier to adopt. Pauseless garbage collection can:

  1. Allow Java instances to make effective use of the abundant, cheap, commodity hardware capacities that are already available, and grow with future improvements to hardware.
  2. Allow Architects and developers to make aggressive use of memory capacity in their designs, applying techniques such large in-memory, in-process caching, as well as complete in-memory representations to new problem sets.
  3. Allow developers to avoid the fine tuning and re-tuning of current sensitive GC systems.

Azul提供了一个持续的有效的内存回收。更有效地利用硬件资源,鼓励开发者充分使用内存,避免GC的一些额外的优化设置。

上面说到了Java7推出的G1,稍后继续。。

分享到:
评论

相关推荐

    Understanding_Java_Garbage_Collection_v4.pdf

    本文档是一份详细探讨Java垃圾回收机制及其影响的白皮书,标题为《Understanding Java Garbage Collection v4.pdf》,旨在帮助Java开发者和架构师理解垃圾回收器的应用行为、特性和机制,并在Java平台上选择和调整...

    The-Pauseless-GC-Algorithm-Azul

    Azul Systems针对这一挑战开发了一种全新的无暂停垃圾收集算法,该算法不仅能够实现持续的应用执行,还能确保在每个垃圾收集阶段中保持一致的生成器吞吐量。 #### 关键特性与设计目标 ##### 1. 高并发性 Azul的无...

    A-JVM-Does-What-Cliff Click.pdf

    2. 并发、并行收集(Parallel, Concurrent, Collection):JVM 的收集机制能够并发地执行垃圾回收,提高系统的响应速度和吞吐量。 3. 低总分配成本(Low total allocation cost):JVM 的内存分配机制能够尽量减少...

    Understanding_Java_Garbage_Collection_v3

    - **记忆集**:为了减少跨代引用的处理成本,某些代际收集器会维护一个称为“记忆集”的数据结构,记录年轻代对象指向老年代对象的引用,从而优化垃圾回收过程。 - **商业实现**:市场上存在多种商业化的JVM实现,每...

    zulu17.30.15-ca-jdk17.0.1-win_x64.zip

    6. Strongly Connected Components:垃圾收集器改进,优化内存回收效率。 使用Zulu JDK17的优势在于: - 兼容性:Zulu JDK完全符合Java SE标准,可以确保与任何Java SE兼容的应用程序无缝协作。 - 性能:Azul ...

    整理-JVM相关面试题2024

    - **定义**:内存泄漏指的是程序中不再使用的对象未能及时被垃圾回收器回收,导致可用内存逐渐减少。 #### 4.2 两者有什么关系? - **联系**:内存泄漏如果不加以控制,最终可能导致内存溢出。 - **区别**:内存...

    zing核心包

    Zing JVM的亮点在于其C4(Continuous Concurrent Collector)垃圾收集器,这是一个专为减少停顿时间而设计的创新性垃圾回收算法。C4通过使用预测性暂停时间模型(Predictable Pause Time Model)来确保应用程序的...

    对java语言的十个常见误解.rar

    Java的并发模型和内存管理机制使得它非常适合处理大规模并发任务。 3. **误解三:Java代码过于冗长** 虽然Java的语法比Python或JavaScript更为繁琐,但通过使用设计模式、函数式编程特性(自Java 8引入)和现代化...

    Minecraft-Java-Shenandoah-GC:使用出色的并行实时垃圾收集器运行Minecraft Java服务器,以减少延迟

    3. **低暂停时间保证**:通过在后台持续地进行垃圾回收,Shenandoah可以保持较低的暂停时间,即使在处理大量垃圾时也是如此。 4. **内存压力控制**:Shenandoah可以动态调整其工作策略,以保持堆的适当填充水平,...

    Java虚拟机(第二版)1

    第3.5章节是关于垃圾收集的深入研究,3.5.7章节对G1(Garbage-First)垃圾收集器的介绍,揭示了它如何在大型应用中实现低延迟的内存回收。3.6章节详细讲解了JVM内存区域,尤其是3.6.4章节关于Eden区的管理,这部分...

    HCNA-HNTD V2.1入门培训教材.pdf

    作者提供了如何选择合适的垃圾收集器的指导,包括Epsilon收集器、收集器的权衡和垃圾收集器参数总结,以及内存分配与回收策略的实战。 在第四章中,作者介绍了虚拟机性能监控、故障处理工具。基础故障处理工具包括...

    Java虚拟机相关的常见面试问题

    并发收集器如CMS和G1能够在应用程序运行时进行垃圾回收,减少停顿时间。 当CPU使用率飙升或系统响应变慢,可以通过监控工具(如JVisualVM、JConsole、jstack等)检查线程状态、内存使用情况、GC日志等,定位问题...

    JVM相关的常见面试问题汇总.pdf

    - **并发垃圾收集器**: 在应用程序运行的同时进行垃圾回收,减少停顿时间。 - **增量式垃圾收集**: 将堆划分为多个区域,每次只收集一部分区域。 #### 7.7 什么是年轻代? - **年轻代**: 用于存储新创建的对象,...

    Java虚拟机JVM性能优化(一):JVM知识总结

    随着JVM的发展,出现了更为高效的垃圾回收器,如Oracle的G1(Garbage First)和Azul Systems的Zing JVM。 编译优化是另一个提高JVM性能的重要手段。JVM包含即时编译器(Just-In-Time, JIT),它能够在运行时将频繁...

    java虚拟机各种版本

    此外,JVM还实现了垃圾回收机制,自动管理内存,避免了程序员手动管理内存的麻烦。 JVM还有许多优化技术,如分代垃圾收集、并行/并发GC、压缩引用、逃逸分析等,这些都对提升Java应用的性能起到了关键作用。对于...

    Java虚拟机

    常见的垃圾收集算法以及垃圾收集器的特点和工作原理;常见虚拟机监控与故障处理工具的原理和使用方法。第三部分分析了虚拟机的执行子系统,包括类文件结构、虚拟机类加载机制、虚拟机字节码执行引擎。第四部分讲解了...

    Java软件开发实战 Java基础与案例开发详解 2-5 java虚拟机简介 共8页.pdf

    - **自动垃圾回收**:JVM提供了自动内存管理机制,能够自动回收不再使用的对象所占用的内存空间,这大大减轻了程序员的负担。 - **安全性**:JVM通过字节码校验器和沙箱模型等机制确保程序的安全性,防止恶意代码对...

    keyboard:键盘包

    1. **Go语言**:Go,也被称为Golang,是由Google开发的一种静态类型的、编译型的、并发型且具有垃圾回收功能的编程语言。它的设计目标是提高开发者的生产力和程序的运行效率,特别适合编写系统工具和服务器软件。在...

    native-al:原生包

    Go语言的优势在于其垃圾回收机制、并发模型以及简洁的语法,但当涉及到低级硬件交互或高性能计算时,可能会遇到性能瓶颈。因此,Azul3D通过引入原生库,如"native-al",可以充分利用C/C++的性能优势,同时保持Go代码...

    Java JDK 17 (32位Windows系统)

    8. **垃圾收集器改进**:JDK 17对G1和ZGC等垃圾收集器进行了优化,提高了内存回收的效率和应用响应速度。 9. **安全性增强**:JDK 17继续关注安全问题,修复了多个安全漏洞,提高了系统的安全性。 10. **JEP(JDK ...

Global site tag (gtag.js) - Google Analytics