Java 7 (JDK 7) 垃圾收集和 G1 上的文档

发布于 2024-12-14 23:16:20 字数 323 浏览 4 评论 0 原文

Java 7 已经发布有一段时间了,但是我找不到任何关于垃圾收集器配置的好资源,特别是新的 G1 收集器 >。

我的问题:

  1. G1 是 Java 7 中的默认收集器吗?如果不是,我该如何激活 G1?
  2. Java7 中 g1 有哪些可选设置?
  3. Java 7 中的其他收集器(例如 cms并行收集器)是否有任何更改?
  4. 在哪里可以找到有关 Java 7 垃圾收集的优秀文档?

Java 7 has been out for a while now, but I cannot find any good resources on the configuration of the garbage collectors, specifically the new G1 collector.

My questions:

  1. Is G1 the default collector in Java 7 and if not how do I activate G1?
  2. What optional settings does g1 have in Java7?
  3. Were there any changes made to other collectors like cms or the parallel collector in Java 7?
  4. Where can I find good documentation on garbage collection in Java 7?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(8

隱形的亼 2024-12-21 23:16:21

No G1 不是 jdk 1.7.0_02 中默认的垃圾收集器。
默认垃圾收集器取决于机器的类别。
如果机器是服务器类,那么默认的垃圾收集器是吞吐量收集器。
如果机器属于客户端类,则默认垃圾收集器是串行收集器。

No G1 is not default garbage collector in jdk 1.7.0_02.
The default garbage collector depends upon the class of machine.
If the machine is of Server class then the default garbage collector is Throughput Collector.
If the machine is of Client class then the default garbage collector is Serial Collector.

浮萍、无处依 2024-12-21 23:16:21

文档位于 http://www.oracle .com/technetwork/java/javase/tech/g1-intro-jsp-135488.html(Wojtek提供的链接)似乎是唯一包含信息的官方链接,但该信息似乎已过时由于提到的一些标志仅在测试版本中可用,因此它们不再存在于生产版本中。 Oracle 的某个人应该提供一些有关 G1 GC 的更新文档。

The documentation available at http://www.oracle.com/technetwork/java/javase/tech/g1-intro-jsp-135488.html (the link provided by Wojtek) seems to be the only official link with info but the info seems outdated as some of the flags mentioned there were only available in the test builds, they no longer exist in the production releases. Some one from Oracle should provide some updated documentation on the G1 GC.

墨洒年华 2024-12-21 23:16:21

默认情况下,您并不真正想使用 G1 收集器,因为它并不比其他收集器更好。它只适用于特殊目的。

在低延迟应用程序中,它比 CMS 稍好一些,因为它的暂停时间更短、更可预测。 Exchange 中的吞吐量比 CMS 中的 Exchange 差很多。

因此,只有延迟很重要,但吞吐量根本不重要时,这才是好的。如果两者都很重要,那么就继续使用 CMS。

By default you don't really want to use G1 collector, as it is not really better than the others. It is only good for special purposes.

In low latency application is is sligthly better than CMS, as it has a little bit shorter, and more predictable pause times. In exchange the throughput is much worse than CMS in exchange.

So it is only good if the latency is important, but the throughput is not important at all. If both are important, then stay with CMS.

執念 2024-12-21 23:16:20

G1 垃圾收集器不是我安装的 Java 版本 1.7.0_01 中的默认设置。您可以通过使用一些额外的命令行选项来亲自查看:

> java -XX:+PrintCommandLineFlags -XX:+PrintGCDetails -version
-XX:InitialHeapSize=132304640 -XX:MaxHeapSize=2116874240 -XX:ParallelGCThreads=4 -XX:+PrintCommandLineFlags -XX:+PrintGCDetails -XX:+UseCompressedOops -XX:-UseLargePagesIndividualAllocation -XX:+UseParallelGC
java version "1.7.0_01"
Java(TM) SE Runtime Environment (build 1.7.0_01-b08)
Java HotSpot(TM) 64-Bit Server VM (build 21.1-b02, mixed mode)
Heap
 PSYoungGen      total 37696K, used 1293K [0x00000007d5eb0000, 0x00000007d88c0000, 0x0000000800000000)
  eden space 32320K, 4% used [0x00000007d5eb0000,0x00000007d5ff3408,0x00000007d7e40000)
  from space 5376K, 0% used [0x00000007d8380000,0x00000007d8380000,0x00000007d88c0000)
  to   space 5376K, 0% used [0x00000007d7e40000,0x00000007d7e40000,0x00000007d8380000)
 PSOldGen        total 86144K, used 0K [0x0000000781c00000, 0x0000000787020000, 0x00000007d5eb0000)
  object space 86144K, 0% used [0x0000000781c00000,0x0000000781c00000,0x0000000787020000)
 PSPermGen       total 21248K, used 2032K [0x000000077ca00000, 0x000000077dec0000, 0x0000000781c00000)
  object space 21248K, 9% used [0x000000077ca00000,0x000000077cbfc288,0x000000077dec0000)

不过,您不再需要启用实验选项来打开 G1 收集器:

> java -XX:+PrintCommandLineFlags -XX:+PrintGCDetails -XX:+UseG1GC -version
-XX:InitialHeapSize=132304640 -XX:MaxHeapSize=2116874240 -XX:+PrintCommandLineFlags -XX:+PrintGCDetails -XX:+UseCompressedOops -XX:+UseG1GC -XX:-UseLargePagesIndividualAllocation
java version "1.7.0_01"
Java(TM) SE Runtime Environment (build 1.7.0_01-b08)
Java HotSpot(TM) 64-Bit Server VM (build 21.1-b02, mixed mode)
Heap
 garbage-first heap   total 130048K, used 0K [0x000000077ca00000, 0x0000000784900000, 0x00000007fae00000)
  region size 1024K, 1 young (1024K), 0 survivors (0K)
 compacting perm gen  total 20480K, used 2032K [0x00000007fae00000, 0x00000007fc200000, 0x0000000800000000)
   the space 20480K,   9% used [0x00000007fae00000, 0x00000007faffc288, 0x00000007faffc400, 0x00000007fc200000)
No shared spaces configured.

我不知道在哪里可以找到任何好的文档。

The G1 garbage collector is not the default in my installation of Java, version 1.7.0_01. You can see for yourself by using with some extra command line options:

> java -XX:+PrintCommandLineFlags -XX:+PrintGCDetails -version
-XX:InitialHeapSize=132304640 -XX:MaxHeapSize=2116874240 -XX:ParallelGCThreads=4 -XX:+PrintCommandLineFlags -XX:+PrintGCDetails -XX:+UseCompressedOops -XX:-UseLargePagesIndividualAllocation -XX:+UseParallelGC
java version "1.7.0_01"
Java(TM) SE Runtime Environment (build 1.7.0_01-b08)
Java HotSpot(TM) 64-Bit Server VM (build 21.1-b02, mixed mode)
Heap
 PSYoungGen      total 37696K, used 1293K [0x00000007d5eb0000, 0x00000007d88c0000, 0x0000000800000000)
  eden space 32320K, 4% used [0x00000007d5eb0000,0x00000007d5ff3408,0x00000007d7e40000)
  from space 5376K, 0% used [0x00000007d8380000,0x00000007d8380000,0x00000007d88c0000)
  to   space 5376K, 0% used [0x00000007d7e40000,0x00000007d7e40000,0x00000007d8380000)
 PSOldGen        total 86144K, used 0K [0x0000000781c00000, 0x0000000787020000, 0x00000007d5eb0000)
  object space 86144K, 0% used [0x0000000781c00000,0x0000000781c00000,0x0000000787020000)
 PSPermGen       total 21248K, used 2032K [0x000000077ca00000, 0x000000077dec0000, 0x0000000781c00000)
  object space 21248K, 9% used [0x000000077ca00000,0x000000077cbfc288,0x000000077dec0000)

You don't need to enable experimental options to turn on the G1 collector any more, though:

> java -XX:+PrintCommandLineFlags -XX:+PrintGCDetails -XX:+UseG1GC -version
-XX:InitialHeapSize=132304640 -XX:MaxHeapSize=2116874240 -XX:+PrintCommandLineFlags -XX:+PrintGCDetails -XX:+UseCompressedOops -XX:+UseG1GC -XX:-UseLargePagesIndividualAllocation
java version "1.7.0_01"
Java(TM) SE Runtime Environment (build 1.7.0_01-b08)
Java HotSpot(TM) 64-Bit Server VM (build 21.1-b02, mixed mode)
Heap
 garbage-first heap   total 130048K, used 0K [0x000000077ca00000, 0x0000000784900000, 0x00000007fae00000)
  region size 1024K, 1 young (1024K), 0 survivors (0K)
 compacting perm gen  total 20480K, used 2032K [0x00000007fae00000, 0x00000007fc200000, 0x0000000800000000)
   the space 20480K,   9% used [0x00000007fae00000, 0x00000007faffc288, 0x00000007faffc400, 0x00000007fc200000)
No shared spaces configured.

I don't know where you can find any good documentation.

一向肩并 2024-12-21 23:16:20

Oracle 最终在 Java 7 U4 中正式发布了 G1:
http://www.oracle.com/technetwork/java/javase/7u4-relnotes- 1575007.html

说明:
http://docs.oracle.com/javase/7/docs/technotes/ guides/vm/G1.html

命令行选项:
http://www.oracle.com/technetwork/java/javase/ tech/vmoptions-jsp-140102.html#G1Options

不过,我不认为它是 Java 7 中的默认收集器。对于服务器,默认值是 Java 中的并行收集器6.

Oracle finally made G1 official in Java 7 U4:
http://www.oracle.com/technetwork/java/javase/7u4-relnotes-1575007.html

Description:
http://docs.oracle.com/javase/7/docs/technotes/guides/vm/G1.html

Command line options:
http://www.oracle.com/technetwork/java/javase/tech/vmoptions-jsp-140102.html#G1Options

Still, I do not think it is the default collector in Java 7. For servers the default is the Parallel Collector as in Java 6.

一场信仰旅途 2024-12-21 23:16:20

是的,G1 是 Java 1.7 JVM 中新的标准垃圾收集器。

在这里您可以找到大量有关如何使用和配置新垃圾收集器的信息:

使用 G1 G1 仍被认为是实验性的,可以通过以下方式启用
以下两个参数:

-XX:+解锁实验VM选项-XX:+使用G1GC

要设置 GC 暂停时间目标,请使用以下参数:

-XX:MaxGCPauseMillis =50(暂停时间目标为 50 毫秒)

使用 G1,可以指定 GC 暂停的时间间隔
持续时间不应超过上面给出的时间:

-XX:GCPauseIntervalMillis =200(暂停间隔目标为 200 毫秒)

请注意,以上两个选项代表目标,而不是承诺或
保证。它们可能在某些情况下工作良好,但在其他情况下则不然,
并且 GC 可能并不总是能够遵守它们。

或者,可以指定年轻代的大小
明确影响疏散暂停时间:

-XX:+G1YoungGenSize=512m(对于 512 MB 年轻代)

G1 还使用相当于幸存者空间,自然地,
一组(可能不连续的)区域。它们的大小可以是
使用常用参数指定(例如,-XX:SurvivorRatio=6)。

最后,要充分发挥 G1 的潜力,请尝试设置这两个
当前默认禁用的参数,因为它们可能
发现一个罕见的竞争条件:

-XX:+G1ParallelRSetUpdatingEnabled -XX:+G1ParallelRSetScanningEnabled

还要注意的一点是,与其他版本相比,G1 非常冗长
设置 -XX:+PrintGCDetails 时的 HotSpot GC。这是因为它打印
每个 GC 线程的计时和其他信息对分析非常有帮助
和故障排除。如果想要更简洁的GC日志,请切换
使用 -verbosegc (尽管建议更详细的
获取GC日志)。

我还发现这篇文章对于理解G1的内部结构非常有帮助。

更多信息此处

Yes, G1 is the new standard garbage collector in Java 1.7 JVM.

Here you can find plenty of information on how to use and configre the new garbage collector:

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).

I have also found this article very helpful in understanding the inners of G1.

Even more info here.

(り薆情海 2024-12-21 23:16:20

1. G1 是 Java 7 中的默认收集器吗(...)

此 Java 5 页面 仍然适用于 Java 7(以及 AFAIK、Java 8):

服务器类 运行服务器VM的机器,垃圾收集器(GC)已从之前的串行收集器(-XX:+UseSerialGC)更改为并行收集器(-XX:+UseParallelGC)。

但还要考虑:

  • 64 位 JVM 不附带 -client VM,因此始终是“服务器类”
  • 从 Java 7 开始,使用 -XX:+UseParallelGC(无论是设置还是隐含)还意味着 - XX:+UseParallelOldGC(即除非明确禁用)

例如,如果在 Windows x64 上运行...

  • Java 7 64 位,则默认情况下会获得并行 GC(对于年轻代和老年代)。
  • Java 8 32 位,默认情况下您会获得串行 GC(两代)

1。 (...) 如何激活 G1?

从 Java 7 开始,只需 -XX:+UseG1GC。也许您还感兴趣的是何时想要:

如果应用程序具有以下一个或多个特征,那么当前使用 CMS 或 ParallelOld 垃圾收集器运行的应用程序将有利于切换到 G1。

  • 超过 50% 的 Java 堆被实时数据占用。
  • 对象分配率或升级率差异很大。
  • 不必要的长时间垃圾收集或压缩暂停(超过 0.5 到 1 秒)

2。 Java7 中 g1 有哪些可选设置?

我自己没有使用过 G1,但是

此处列出了特定于 G1 的选项

< EM>3。 Java 7 中的 (...) cms 或并行收集器是否有更改?

不知道,但是...

G1 计划作为并发标记清除收集器 (CMS) 的长期替代品

4。在哪里可以找到有关 Java 7 垃圾收集的优秀文档?

查找起来可能很痛苦,不是吗?我发现的最好的“中心”页面可能是这个:

http://www.oracle.com/technetwork/java/javase/tech/index-jsp-140228.html

需要一些深入阅读,但如果您需要进行一些调整,那么值得花时间。特别有见地的是:垃圾收集器人体工程学

1. Is G1 the default collector in Java 7 (...)

The rule on this Java 5 page is still applicable in Java 7 (and AFAIK, Java 8):

On server-class machines running the server VM, the garbage collector (GC) has changed from the previous serial collector (-XX:+UseSerialGC) to a parallel collector (-XX:+UseParallelGC).

But also consider:

  • 64-bit JVMs do not come with a -client VM, so are always "server class"
  • Since Java 7, using -XX:+UseParallelGC (whether set or implied) additionally implies -XX:+UseParallelOldGC (i.e. unless explicitly disabled)

For example, if on Windows x64 you run...

  • Java 7 64-bit, you get Parallel GC (for both young and old generations) by default.
  • Java 8 32-bit, you get Serial GC (for both generations) by default

1. (...) how do I activate G1?

As of Java 7, simply -XX:+UseG1GC. Perhaps also of interest is when you would want to:

Applications running today with either the CMS or the ParallelOld garbage collector would benefit switching to G1 if the application has one or more of the following traits.

  • More than 50% of the Java heap is occupied with live data.
  • The rate of object allocation rate or promotion varies significantly.
  • Undesired long garbage collection or compaction pauses (longer than 0.5 to 1 second)

2. What optional settings does g1 have in Java7?

I've not used G1 myself, but I gather that it adheres to the same basic "throughput / ergonomic" flags used to tune the other parallel collectors. In my experience with the Parallel GC, -XX:GCTimeRatio has been the pivotal one in providing the expected speed-memory tradeoff. YMMV.

G1-specific options are listed here

3. Were there changes to (...) cms or the parallel collector in Java 7?

Don't know, but...

G1 is planned as the long term replacement for the Concurrent Mark-Sweep Collector (CMS)

4. Where can I find good documentation on garbage collection in Java 7?

It can be a pain to find, can't it? Probably the best "hub" page I've found is this one:

http://www.oracle.com/technetwork/java/javase/tech/index-jsp-140228.html

Some deep reading required, but worth the time if you need to do some tuning. Particularly insightful is: Garbage Collector Ergonomics

弱骨蛰伏 2024-12-21 23:16:20

1. G1 是 Java 7 中的默认收集器吗?如果不是,如何激活 G1?

G1 不是 Java 7 中的默认收集器。-XX:+UseG1GC 将启用 G1GC

2。 Java7 中 g1 有哪些可选设置?

有很多。请查看 Oracle 文档页面以获取完整信息。

G1 GC 是一种自适应垃圾收集器,其默认设置使其无需修改即可高效工作。

因此,请自定义关键参数

-XX:MaxGCPauseMillis
-XX:G1HeapRegionSize
-XX:ParallelGCThreads
-XX:ConcGCThreads

并将所有其他参数保留为默认值

您已经重新配置了许多 G1GC 参数,如果您遵循上述文档页面,则不需要这些参数。请交叉检查上述建议,尤其是关于 ParallelGCThreadsConcGCThreads 的建议,它们将基于您的 CPU 内核。删除不必要的参数的重新配置。

年轻代大小:避免使用-Xmn选项-XX:NewRatio显式设置年轻代大小。 固定年轻代的大小会覆盖目标暂停时间目标

3. Java 7 中的其他收集器(例如 cms 或并行收集器)是否有任何更改?

Java 7 有一些更改。看看这个 Oracle 发行说明 页面。

4。在哪里可以找到有关 Java 7 中垃圾收集的良好文档?

请参阅 oracle教程页面

1. Is G1 the default collector in Java 7 and if not how do I activate G1?

G1 is not default collector in Java 7. -XX:+UseG1GC will enable G1GC

2. What optional settings does g1 have in Java7?

There are many. Have a look at this oracle documentation page for complete information.

The G1 GC is an adaptive garbage collector with defaults that enable it to work efficiently without modification.

Due to this reason, customize critical parameters

-XX:MaxGCPauseMillis
-XX:G1HeapRegionSize
-XX:ParallelGCThreads
-XX:ConcGCThreads

and leave all other parameters to default value.

You have re-configured many G1GC parameters, which are not required if you follow above documentation page. Please cross check with above recommendations especially on ParallelGCThreads and ConcGCThreads, which are to be based on your CPU cores. Remove re-configuration of un-necessary parameters.

Young Generation Size: Avoid explicitly setting young generation size with the -Xmn option -XX:NewRatio. Fixing the size of the young generation overrides the target pause-time goal.

3. Were there any changes made to other collectors like cms or the parallel collector in Java 7?

There are some changes with Java 7. Have a look at this oracle release notes page.

4. Where can I find good documentation on garbage collection in Java 7?

Refer to oracle tutorial page

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文