[译]Java8官方GC调优指南 --(零) 目录

1,334 阅读3分钟

本套文章是Java8官方GC调优指南的全文翻译,点击查看原文,原文章名称《Java Platform, Standard Edition HotSpot Virtual Machine Garbage Collection Tuning Guide》

写在前面

关于GC调优,笔者看过许多相关的总结帖和技术文章,感觉各位大牛总结的也都很不错,但是总感觉差一点。

因为我永远都没办法确定其他帖子的作者是不是所有的知识点都讲到了,想要学会知识还是要去了解到它的官方文档。

学霸的笔记不一定适合所有人,有些知识点学霸觉得都没必要讲出来,可对我们这些菜鸟,这些知识点可能是很关键的。

本着不想漏掉任何细节的思想,我亲自读了读Oracle官方的GC调优指南,发现很多帖子的参考文献应该就是这套文档了。

所以就有了这一系列的翻译文章,我想把官网的文档翻译出来分享给大家,帮助大家了解到知识的本质,我在阅读的过程确实也学到了很多。

你看完这套帖子就会明白,GC调优如果想要做到最优,是一个非常复杂的事情,要结合自己程序的各种情况去思考如何调优,还要通过不断的测试去验证。如果你只是看了几篇技术帖子,没有自己调优的实战经验,面试的时候很容易露出马脚,最起码自己要上手练练。换句话说,如果你的Java程序跑在4C8G以下的小虚拟机上,而且服务压力不大的话,那么你的GC调优经验价值也就不是很大。然而,这样的人往往都是大多数,不是所有开发者都是大厂员工,每天面对几百亿的流量,我们作为二线开发者,了解文档中提到的细节和一些基本原理也是很有必要的。所以我认为先读官方文档,有了自己的思考之后再去看技术帖子和书籍,会加深理解,比直接读书会好很多。

这套文章发完之后我会再写一些思考和总结,但是笔者公司的Java程序的服务压力也都比较轻量,最大就是8G的堆,调优经验也不是很丰富,只能等比例缩小。

个人技术水平有限,如果有任何问题,欢迎指出,谢谢大家!

目录

1 Introduction 引子

2 Ergonomics 工效学

2.1 Garbage Collector, Heap, and Runtime Compiler Default Selections

2.2 Behavior-Based Tuning

2.2.1 Maximum Pause Time Goal

2.2.2 Throughput Goal

2.2.3 Footprint Goal

2.3 Tuning Strategy

3 Generations 分代

3.1 Performance Considerations

3.2 Measurement

4 Sizing the Generations 设置分代大小

4.1 Total Heap

4.2 The Young Generation

4.2.1 Survivor Space Sizing

5 Available Collectors 可用的收集器

5.1 Selecting a Collector

6 The Parallel Collector 平行收集器

6.1 Generations

6.2 Parallel Collector Ergonomics

6.2.1 Priority of Goals

6.2.2 Generation Size Adjustments

6.2.3 Default Heap Size

6.2.3.1 Client JVM Default Initial and Maximum Heap Sizes
6.2.3.2 Server JVM Default Initial and Maximum Heap Sizes
6.2.3.3 Specifying Initial and Maximum Heap Sizes

6.3 Excessive GC Time and OutOfMemoryError

6.4 Measurements

7 The Mostly Concurrent Collectors 并发收集器

7.1 Overhead of Concurrency

7.2 Additional References

8 Concurrent Mark Sweep (CMS) Collector CMS收集器

8.1 Concurrent Mode Failure

8.2 Excessive GC Time and OutOfMemoryError

8.3 Floating Garbage

8.4 Pauses

8.5 Concurrent Phases

8.6 Starting a Concurrent Collection Cycle

8.7 Scheduling Pauses

8.8 Incremental Mode

8.8.1 Command-Line Options

8.8.2 Recommended Options

8.8.3 Basic Troubleshooting

8.9 Measurements

9 Garbage-First Garbage Collector

9.1 Allocation (Evacuation) Failure

9.2 Floating Garbage

9.3 Pauses

9.4 Card Tables and Concurrent Phases

9.5 Starting a Concurrent Collection Cycle

9.6 Pause Time Goal

10 Garbage-First Garbage Collector Tuning

10.1 Garbage Collection Phases

10.2 Young Garbage Collections

10.3 Mixed Garbage Collections

10.4 Phases of the Marking Cycle

10.5 Important Defaults

10.6 How to Unlock Experimental VM Flags

10.7 Recommendations

10.8 Overflow and Exhausted Log Messages

10.9 Humongous Objects and Humongous Allocations

11 Other Considerations

11.1 Finalization and Weak, Soft, and Phantom References

11.2 Explicit Garbage Collection

11.3 Soft References

11.4 Class Metadata