问题描述
我一直在阅读Java和垃圾收集垃圾收集,但我对垃圾收集的类型感到困惑。
我们以吞吐量收集器作为例。 (又名平行收集器)。文档说它使用多个线程来为 Major 集合(与串行收集器相同)执行次要集合和单个线程。现在我的问题:
- Full GC的含义如下:a)是否意味着Minor和Major集合都是做了什么?或b)完整的GC ==主要收藏?哪一个是?
- 如果a),是否意味着Minor Collection仍然使用多线程完成,而Major是使用Single完成的?
- 如果b),这是否意味着Young&使用单线程清除旧代?
另外,
4. Full GC只影响OldGeneration或YoungGeneration吗?
预先感谢。
让我解释一下。
这里有一些要理解的东西。默认情况下,在大多数较新的系统中,JVM使用两个不同的垃圾收集器来存储年轻和旧代。在我的机器上:我为年轻一代设计了 Parallel New Collector ,并为老一代设计了并发标记和扫描收集器。
当JVM无法为新对象分配空间时,触发Minor Collection(请记住:新对象始终在Young Generation的Eden区域中分配)。
下一个问题:
和
blockquote>
这取决于。 JVM将每个主要集合报告为完整GC。 [尝试使用这些标志 java -verbose:gc -XX:+ PrintGCDetails -XX:+ PrintGCTimeStamp ]。迂腐的定义是,Full GC首先运行Minor,然后是Major。(尽管如果旧版本已满,在这种情况下,它首先被释放以允许它从年轻一代接收对象),然后切换命令。
好的,回到正题。 JVM将旧版(或旧版)中的主集合视为完整GC。以下是我能够快速写出的一个程序的输出来说明这一点。第一行是Minor GC,第二行是Major(Full)GC。你可以看到,它只发生在老一代(CMS),并能够将老一代从1082K减少到1034K。
- <$ c 11.431:[GC 11.431:[Par新:1152K-> 128K(1152K),0.0009893秒] 2111K-> 1210K(6464K),0.0010182秒] [时间:用户= 0.00 sys = 0.00,实数= 0.00 (完整GC(系统)17.882:[CMS:1082K-> 1034K(5312K),0.0212614秒)。[b] ] = 2034K→1034K(6464K)→〔CMS Perm:9426K→9410K(21248K)〕,0.0213200秒→[时间:用户= 0.02 sys = 0.00,实际= 0.02秒] / b>
下一个问题:
是的。看到我的答案的开始。年轻和老一代由不同的收藏家服务。对于年轻一代,您可以使用以下任何一种方式:
- -XX:+ UseSerialGC
- -XX:+ UseParallelGC
- - XX:+ UseParNewGC
对于老一代,可用选项包括:$ b $
- -XX:+ UseParallelOldGC
- -XX:+ UseConcMarkSweepGC
I have been reading up on Garbage Collection in Java and SO Q&A but I'm confused about types of Garbage Collection.
Let's take Throughput Collector as an example. (aka Parallel Collector). The docs say it uses multiple threads to do the Minor collections and single thread for Major collections (same as Serial collector).
Now my questions:
- What does it mean by a Full GC: a) Does it mean both Minor and Major collections are done? Or b) Full GC == Major Collections? Which one is it?
- If a), does it mean that the Minor Collection is still done using multiple threads whereas the Major was done using Single?
- If b), does it mean both Young & Old Generations were cleared using Single Thread?
Also,4. Does Full GC only affect OldGeneration or YoungGeneration as well?
Thanks in advance.
Let me explain.
Here's something to understand. By default, on most newer systems, JVM uses TWO different Garbage Collectors for Young and Old Generations. On my my machine: I have Parallel New Collector for the Young Generation and Concurrent Mark and Sweep Collector for the Older Generation.
Minor Collection is triggered when then JVM is unable to allocate space for a new Object (Remember: new objects are always allocated in Young Generation's Eden Area).
Next Question:
and,
It depends. JVM reports every Major Collection as Full GC. [Try with these flags java -verbose:gc -XX:+PrintGCDetails -XX:+PrintGCTimeStamp]. The pedantic definition is that Full GC runs Minor first followed by Major (Although the order could be switched if the Older Generation is full in which case it is freed first to allow it to receive objects from the Young Generation).
OK, back to the point. JVM considers Major Collection [in the Older (or Perm) Generation] as Full GC. Below are outputs from a program I was able to quickly write to illustrate the point. The first line is Minor GC and the second is Major (Full) GC. You can see that it only happened in the Older Generation (CMS) and was able to reduce old generation from 1082K to 1034K.
- 11.431: [GC 11.431: [ParNew: 1152K->128K(1152K), 0.0009893 secs] 2111K->1210K(6464K), 0.0010182 secs] [Times: user=0.00 sys=0.00, real=0.00 secs]
- 17.882: [Full GC (System) 17.882: [CMS: 1082K->1034K(5312K), 0.0212614 secs] 2034K->1034K(6464K), [CMS Perm : 9426K->9410K(21248K)], 0.0213200 secs] [Times: user=0.02 sys=0.00, real=0.02 secs]
Next question:
Yes. See the beginning of my answer. Young and Older Generations are served by different Collectors. For Young Generation, you can use any one of the following:
- -XX:+UseSerialGC
- -XX:+UseParallelGC
- -XX:+UseParNewGC
For Old Generation, the available choices are:
- -XX:+UseParallelOldGC
- -XX:+UseConcMarkSweepGC
这篇关于Java主要和次要垃圾收集的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!