在前几次中已经对G1的理论进行了一个比较详细的了解了,对于G1垃圾收集器最权威的解读肯定得上官网,当咱们将官网的理解透了,那基本上网上对于G1的说明其实最终都是来自于官网,所以接下来会详细来解读Oracle官网对于G1垃圾收集器的权威说明,其网址为:“https://www.oracle.com/technetwork/tutorials/tutorials-1876574.html”,打开如下:

先来解读一下大纲:

好,接下来开启第一小节的解读“Overview”,由于是概览,所以比较简单,大概了解下既可。

Purpose

This tutorial covers the basics of how to use the G1 garbage collector and how it can be used with the Hotspot JVM. You will learn how the G1 collector functions internally, the key command line switches for using G1, and options for logging its operation.

【解读:
“This tutorial covers the basics of how to use the G1 garbage collector and how it can be used with the Hotspot JVM. ”
这个指南涵盖了如何使用G1垃圾收集器的基本知识以及它是如何的应用到Hotspot JVM当中的。
“You will learn how the G1 collector functions internally, the key command line switches for using G1, and options for logging its operation.”
你将了解到G1收集器内部功作的机理,主要的用于G1的一些命令行的开关,以及用于日志操作的一些选项。

Time to Complete

Approximately 1 hour

Introduction

This OBE covers the basics of Java Virtual Machine(JVM) G1 Garbage Collection (GC) in Java. In the first part of the OBE, an overview of the JVM is provided along with an introduction to Garbage Collection and performance. Next students are provided with a review of how the CMS collector works with the Hotspot JVM. Next, a step by step guide to how Garbage Collection works when using the G1 garbage collection with a Hotspot JVM. Following that, a section is provided covering the Garbage Collection command line options available with the G1 garbage collector. Finally, you will learn about logging options to use with the G1 collector.

Hardware and Software Requirements

The following is a list of hardware and software requirements:

      • A PC running Windows XP or later, Mac OS X or Linux. Note that the hands on is done with Windows 7 and has not been tested on all platforms. However, everything should work fine on OS X or Linux. Also a machine with more than one core is preferable.
      • Java 7 Update 9 or later
      • The latest Java 7 Demos and Samples Zip file

Prerequisites

Before starting this tutorial, you should:

        • If you have not done so, download and install the latest version of the Java JDK (JDK 7 u9 or later).
          Java 7 JDK Downloads

好,第一部分的一带而过了,了解既可,接下来看第二节“Java Technology and the JVM”,如下:

Java Overview【略过】

Java is a programming language and computing platform first released by Sun Microsystems in 1995. It is the underlying technology that powers Java programs including utilities, games, and business applications. Java runs on more than 850 million personal computers worldwide, and on billions of devices worldwide, including mobile and TV devices. Java is composed of a number of key components that, as a whole, create the Java platform.

Java Runtime Edition【Java运行时的版本,也略过】

When you download Java, you get the Java Runtime Environment (JRE). The JRE consists of the Java Virtual Machine (JVM), Java platform core classes, and supporting Java platform libraries. All three are required to run Java applications on your computer. With Java 7, Java applications run as desktop applications from the operating system, as a desktop application but installed from the Web using Java Web Start, or as a Web Embedded application in a browser (using JavaFX).

Java Programming Language【Java编程语言,略过】

Java is an object-oriented programming language that includes the following features.

      • Platform Independence - Java applications are compiled into bytecode which is stored in class files and loaded in a JVM. Since applications run in a JVM, they can be run on many different operating systems and devices.
      • Object-Oriented - Java is an object-oriented language that take many of the features of C and C++ and improves upon them.
      • Automatic Garbage Collection - Java automatically allocates and deallocates memory so programs are not burdened with that task.
      • Rich Standard Library - Java includes a vast number of premade objects that can be used to perform such tasks as input/output, networking, and date manipulation.

Java Development Kit【JDK的介绍,略过】

The Java Development Kit (JDK) is a collection of tools for developing Java applications. With the JDK, you can compile programs written in the Java Programming language and run them in a JVM. In addition, the JDK provides tools for packaging and distributing your applications.

The JDK and the JRE share the Java Application Programming Interfaces (Java API). The Java API is a collection of prepackaged libraries developers use to create Java applications. The Java API makes development easier by providing the tools to complete many common programming tasks including string manipulation, date/time processing, networking, and implementing data structures (e.g., lists, maps, stacks, and queues).

Java Virtual Machine【JVM,也略过,之前学习已经对它有了解过了】

The Java Virtual Machine (JVM) is an abstract computing machine. The JVM is a program that looks like a machine to the programs written to execute in it. This way, Java programs are written to the same set of interfaces and libraries. Each JVM implementation for a specific operating system, translates the Java programming instructions into instructions and commands that run on the local operating system. This way, Java programs achieve platform independence.

The first prototype implementation of the Java virtual machine, done at Sun Microsystems, Inc., emulated the Java virtual machine instruction set in software hosted by a handheld device that resembled a contemporary Personal Digital Assistant (PDA). Oracle's current implementations emulate the Java virtual machine on mobile, desktop and server devices, but the Java virtual machine does not assume any particular implementation technology, host hardware, or host operating system. It is not inherently interpreted, but can just as well be implemented by compiling its instruction set to that of a silicon CPU. It may also be implemented in microcode or directly in silicon.

The Java virtual machine knows nothing of the Java programming language, only of a particular binary format, the class file format. A class file contains Java virtual machine instructions (or bytecodes) and a symbol table, as well as other ancillary information.

For the sake of security, the Java virtual machine imposes strong syntactic and structural constraints on the code in a class file. However, any language with functionality that can be expressed in terms of a valid class file can be hosted by the Java virtual machine. Attracted by a generally available, machine-independent platform, implementors of other languages can turn to the Java virtual machine as a delivery vehicle for their languages. (1) The Java Virtual Machine

Exploring the JVM Architecture【探索JVM架构】

Hotspot Architecture【Hotspot架构】

The HotSpot JVM possesses an architecture that supports a strong foundation of features and capabilities and supports the ability to realize high performance and massive scalability. For example, the HotSpot JVM JIT compilers generate dynamic optimizations. In other words, they make optimization decisions while the Java application is running and generate high-performing native machine instructions targeted for the underlying system architecture. In addition, through the maturing evolution and continuous engineering of its runtime environment and multithreaded garbage collector, the HotSpot JVM yields high scalability on even the largest available computer systems.

【解读:
“The HotSpot JVM possesses an architecture that supports a strong foundation of features and capabilities and supports the ability to realize high performance and massive scalability.”
HotSpot虚拟机它会处理一种架构:支持一个很强特性基础和能力,并且支持实现高性能和可伸缩性的能力。
“For example, the HotSpot JVM JIT compilers generate dynamic optimizations. In other words, they make optimization decisions while the Java application is running and generate high-performing native machine instructions targeted for the underlying system architecture.”
比如说HotSpotJVM的既时编译器可以生成动态优化。换句话说,他们会在Java应用运行时做出一些优化决策,同时面向底层系统架构会生成高性能的底层机器指向。【很显然底层的代码运行效果是最高的嘛】
“In addition, through the maturing evolution and continuous engineering of its runtime environment and multithreaded garbage collector, the HotSpot JVM yields high scalability on even the largest available computer systems.”
此外,通过不断的演进和持续的这种运行期环境的工程化和多线程的垃圾收集器,Hotspot虚拟机既便是在大型的计算机系统当中也能得到很高的伸缩性。

The main components of the JVM include the class loader, the runtime data areas, and the execution engine.

JVM主要的组成部分包含了类加载器【这也是为啥之前我们在学习JVM时对于类加器花了很多时间去学习,因为它在JVM体系中扮演着非常重要的角色】、运行时数据区域和执行引擎。

Key Hotspot Components【Hotspot关键组件】

The key components of the JVM that relate to performance are highlighted in the following image.

与性能相关的JVM的关健组件在下面的图中已经被高度出来了,如Heap、JIT Compiler、Garbage Collector。

 

【解读:关于此图其实在之前的学习中已经见过了,回顾一下:

是不是其实这些信息都是来自于官网,所以。。】

There are three components of the JVM that are focused on when tuning performance. The heap is where your object data is stored. This area is then managed by the garbage collector selected at startup. Most tuning options relate to sizing the heap and choosing the most appropriate garbage collector for your situation. The JIT compiler also has a big impact on performance but rarely requires tuning with the newer versions of the JVM.

解读

“There are three components of the JVM that are focused on when tuning performance. The heap is where your object data is stored. ”

在JVM中有三个组件重点是放在了性能调优上面, 堆是你的对象数据存储的位置。

“This area is then managed by the garbage collector selected at startup. Most tuning options relate to sizing the heap and choosing the most appropriate garbage collector for your situation.”

这个区域接下来是由在启动时所选择的垃圾收集器来管理,大多数调优的选项都是跟调整堆的大小以及为你当前的场景选择最为适合的垃圾收集器。【换句话来说就是说jvm的性能调优主要是两部分,一是调整堆的大小,二是选择最符合当前场景的垃圾收集器】

“The JIT compiler also has a big impact on performance but rarely requires tuning with the newer versions of the JVM.”

既时编译器也会对程序性能产生非常大的影响,但是对于最新版本的JVM是很少需要对它进行调优的。【换言之,也就是其实JTI底层已经对性能做得比较到位了,不需要我们再对它进行任何性能的调优了】

Performance Basics【性能的基础知识】

Typically, when tuning a Java application, the focus is on one of two main goals: responsiveness or throughput. We will refer back to these concepts as the tutorial progresses.

通常,当对一个Java应用进行调优时,其主要是聚焦到这两个主要目标中的其中一个:响应能力和吞吐量。我们会随着教程的进行重新来介绍这些概念。

【其实这两块在之前的理论中也已经说过了,回顾一下:

下面再以官方的角度再来解读一下这俩概念。】

Responsiveness【响应能力】

Responsiveness refers to how quickly an application or system responds with a requested piece of data. Examples include:
响应能力是指的对于一个应用或者一个系统能够多快的响应所请求的数据,比如包话:

      • How quickly a desktop UI responds to an event
        一个桌面UI到底有多快能响应一个事件。
      • How fast a website returns a page
        一个网站多快能返回一个页面。
      • How fast a database query is returned
        一个数据据多快能返回一个查询。

For applications that focus on responsiveness, large pause times are not acceptable. The focus is on responding in short periods of time.

对于关注响应能力的应用来说,长时间的暂时是无法接受的。它的关注点是在短时间内能够及时响应上面。

Throughput【吞吐量】

Throughput focuses on maximizing the amount of work by an application in a specific period of time. Examples of how throughput might be measured include:
吞吐量关注的是在一个指定的时间周期内最大化一个应用的工作总量。吞吐量度量的一些示例包括:

      • The number of transactions completed in a given time.
        在一个给定的时间内完成的事务的数量。
      • The number of jobs that a batch program can complete in an hour.
        在一个小时之内一个批处理程序所完成的工作的数量。
      • The number of database queries that can be completed in an hour.
        在一小时之内能够完成的数据查询的数量。

High pause times are acceptable for applications that focus on throughput. Since high throughput applications focus on benchmarks over longer periods of time, quick response time is not a consideration.
高暂停的时间对于一个关注于吞吐量的应用来说是可以接受的。由于高吞量的应用关注的是长时间的大量任务的执行,快速响应并不值得考虑。

好,接下来关注下一小节“The G1 Garbage Collector”,这里先只分析一小部分,剩下的待下次再继续解读:

The Garbage-First (G1) collector is a server-style garbage collector, targeted for multi-processor machines with large memories. It meets garbage collection (GC) pause time goals with a high probability, while achieving high throughput. The G1 garbage collector is fully supported in Oracle JDK 7 update 4 and later releases. The G1 collector is designed for applications that:
解读

“The Garbage-First (G1) collector is a server-style garbage collector, targeted for multi-processor machines with large memories.”

G1垃圾收集器是一个服务端的垃圾收集器,它针对的是拥有较大内存的多处理器的机器。

“It meets garbage collection (GC) pause time goals with a high probability, while achieving high throughput. ”

它既满足了暂停时间比较短的高性能,又满足吞吐量比较高的目标。

The G1 garbage collector is fully supported in Oracle JDK 7 update 4 and later releases. The G1 collector is designed for applications that:”

G1垃圾收集器是在Oracle的JDK7 update 4及以后的版本得到了完全的支持。G1垃圾收集器是针对这样的应用来进行设计的:

      • Can operate concurrently with applications threads like the CMS collector.
        能够像CMS收集器一样跟应用线程并发的去执行。【CMS本身就是一个并发的收集器,也就是GC线程与应用线程可以同时间执行】
      • Compact free space without lengthy GC induced pause times.
        可以压缩可用的空间,而不会让GC引起暂停时间过长。
      • Need more predictable GC pause durations.
        需要更多的可预测的GC暂停的间隔。【也就是说GC暂停的时间会尽量往我们设置的暂时时间来靠】
      • Do not want to sacrifice a lot of throughput performance.
        不想牺牲大量吞土性能。
      • Do not require a much larger Java heap.
        不想需要大量Java的堆空间。

G1 is planned as the long term replacement for the Concurrent Mark-Sweep Collector (CMS). Comparing G1 with CMS, there are differences that make G1 a better solution. One difference is that G1 is a compacting collector. G1 compacts sufficiently to completely avoid the use of fine-grained free lists for allocation, and instead relies on regions. This considerably simplifies parts of the collector, and mostly eliminates potential fragmentation issues. Also, G1 offers more predictable garbage collection pauses than the CMS collector, and allows users to specify desired pause targets.
解读:

“G1 is planned as the long term replacement for the Concurrent Mark-Sweep Collector (CMS). Comparing G1 with CMS, there are differences that make G1 a better solution. ”

G1从长远的计划是要替换掉CMS,将G1和CMS进行比较,有一些区别使得G1成为一个更加好的解决方案。

“One difference is that G1 is a compacting collector. G1 compacts sufficiently to completely avoid the use of fine-grained free lists for allocation, and instead relies on regions. ”

其中一个区别就是G1是一个压缩的收集器,G1充分的进行压缩来达到完成避免细粒度的free lists分配的使用,同时还依赖于regions。

“This considerably simplifies parts of the collector, and mostly eliminates potential fragmentation issues. Also, G1 offers more predictable garbage collection pauses than the CMS collector, and allows users to specify desired pause targets.”

这样能极大的简化收集器的部分,并且可以极大的消除潜在碎片的问题,此外,相比CMS收集器来说,G1还提供了更多可预计垃圾收集暂停的时间,并且可以让用户来指定它所暂停的目标。

G1 Operational Overview【G1操作概览】

The older garbage collectors (serial, parallel, CMS) all structure the heap into three sections: young generation, old generation, and permanent generation of a fixed memory size.

对于以前垃圾收信器(像serial、parallel、CMS)都是将堆划分为三个部分:年轻代、老年代、固定内存大小的永久代。

上面这张图也是在之前理论学习中接触过的,回顾一下:

All memory objects end up in one of these three sections.

所有的内存对象最终都会被放置到这三个区域当中的一个。

The G1 collector takes a different approach.

G1收集器采取了完全不同的处理办法。

该图也是在之前学习过了,回忆下:

The heap is partitioned into a set of equal-sized heap regions, each a contiguous range of virtual memory. Certain region sets are assigned the same roles (eden, survivor, old) as in the older collectors, but there is not a fixed size for them. This provides greater flexibility in memory usage.

解读:

“The heap is partitioned into a set of equal-sized heap regions, each a contiguous range of virtual memory. ”

这个堆被划分了一组相等大小堆区域,每一个区域都是连续虚拟内存的地址空间。

“Certain region sets are assigned the same roles (eden, survivor, old) as in the older collectors, but there is not a fixed size for them. ”

某些区域的集合会被分配成就像传统的收集器一样相同的角色(如eden、survivor、old),但是对于它们来说并没有指定一个固定的大小的空间。

“This provides greater flexibility in memory usage.”

这就提供了内存使用当中最大的灵活性。

FAQ:这句话是不是有点前后矛盾,如:

其实是这样的:“equal-sized heap regions”是指图中的小方格,这是固定大小的:

而“but there is not a fixed size ”是指的比如Eden空间一定得要占10M,Survivor一定是要占3M,Old一定得要占100M,有可能Eden过一段时间占8M,也有可能是占10M,也有可能占3M,指的是针对每一个角色所占用的大小。

G1垃圾收集器官方文档透彻解读【官方解读】的更多相关文章

  1. scrapy 选择器官方文档

    当抓取网页时,常见的任务是从HTML源码中提取数据.现有的一些库可以达到这个目的: BeautifulSoup lxml Scrapy 提取数据有自己的一套机制.它们被称作选择器(seletors), ...

  2. G1垃圾收集器系统化说明【官方解读】

    还是继续G1官网解读,上一次已经将这三节的东东读完了,如下: 所以接一来则继续往下读: Reviewing Generational GC and CMS[回顾一下CMS收集器] The Concur ...

  3. Cuda 9.2 CuDnn7.0 官方文档解读

    目录 Cuda 9.2 CuDnn7.0 官方文档解读 准备工作(下载) 显卡驱动重装 CUDA安装 系统要求 处理之前安装的cuda文件 下载的deb安装过程 下载的runfile的安装过程 安装完 ...

  4. 【pytest官方文档】解读fixtures - 2. fixtures的调用方式

    既然fixtures是给执行测试做准备工作的,那么pytest如何知道哪些测试函数 或者 fixtures要用到哪一个fixtures呢? 说白了,就是fixtures的调用. 一.测试函数声明传参请 ...

  5. 【pytest官方文档】解读- 插件开发之hooks 函数(钩子)

    上一节讲到如何安装和使用第三方插件,用法很简单.接下来解读下如何自己开发pytest插件. 但是,由于一个插件包含一个或多个钩子函数开发而来,所以在具体开发插件之前还需要先学习hooks函数. 一.什 ...

  6. jQuery Form 表单提交插件----Form 简介,官方文档,官方下载地址

     一.jQuery Form简介 jQuery Form插件是一个优秀的Ajax表单插件,可以非常容易地.无侵入地升级HTML表单以支持Ajax.jQuery Form有两个核心方法 -- ajaxF ...

  7. mysql 新手入门 官方文档+官方中文文档附地址

    点评: 官方文档地址 官方中文文档地址 sql语句扩展

  8. 【pytest官方文档】解读fixtures - 1.什么是fixtures

    在深入了解fixture之前,让我们先看看什么是测试. 一.测试的构成 其实说白了,测试就是在特定的环境.特定的场景下.执行特定的行为,然后确认结果与期望的是否一致. 就拿最常见的登录来说,完成一次正 ...

  9. 【pytest官方文档】解读fixtures - 8. yield和addfinalizer的区别(填坑)

    在上一章中,文末留下了一个坑待填补,疑问是这样的: 目前从官方文档中看到的是 We have to be careful though, because pytest will run that fi ...

随机推荐

  1. MySQL(四)InnoDB中一棵B+树能存多少行数据

    一.InnoDB一棵B+树可以存放多少行数据?(约2千万) 我们都知道计算机在存储数据的时候,有最小存储单元,这就好比我们今天进行现金的流通最小单位是一毛.在计算机中磁盘存储数据最小单元是扇区,一个扇 ...

  2. js18位身份证验证(非原创)

    原文链接 function check_id(value) { var arrExp = [7, 9, 10, 5, 8, 4, 2, 1, 6, 3, 7, 9, 10, 5, 8, 4, 2];/ ...

  3. Elasticsearch聚合操作报错解决办法

    1. 当根据一个类型为text的字段idc进行聚合操作时,查询语句如下: { "aggs": { "top_10_states": { "terms& ...

  4. LeetCode 896. 单调数列(Monotonic Array)

    896. 单调数列 896. Monotonic Array 题目描述 如果数组是单调递增或单调递减的,那么它是单调的. 如果对于所有 i<=j,A[i]<=A[j],那么数组 A 是单调 ...

  5. Arm 环境上面libgdiplus的简单安装配置

    1. 下载libgdiplus的包 wget http://download.mono-project.com/sources/libgdiplus/libgdiplus0-6.0.4.tar.gz ...

  6. 简单实现SpringBoot启动

    一.准备: IDEA 使用简单手写导包实现spring boot,未使用idea自带的spring创建方法 可以更加简单理解springboot启动过程 二.开始 1.打开idea创建project ...

  7. Linux基础-09-磁盘分区、挂载及文件系统管理

    1. 硬件设备与文件名的对应关系 1) 在Linux系统中,每个设备都被当初一个文件来对待. 2) 各种设备在Linux中的文件名 2. 硬盘的结构及硬盘分区 1) 为什么要进行硬盘分区: a) 更容 ...

  8. Composer简介

    Composer 是 PHP 的一个依赖管理工具.它允许你申明项目所依赖的代码库,它会在你的项目中为你安装他们. 依赖管理 Composer 不是一个包管理器.是的,它涉及 "package ...

  9. Python虚拟环境virtualenv的安装与使用详解(转)

    virtualenv参考:https://www.jb51.net/article/114933.htm virtualenvwrapper参考:https://www.jianshu.com/p/7 ...

  10. 测试winform程序到树莓派运行

    啥也不说了,都在下图中了.winform可以在树莓派上跑了