89

若い世代のガベージ コレクションのアルゴリズムです。

2 つ目 (UseParNewGC) は、同時保有世代ガベージ コレクション ( Java Concurrent および Parallel GCを参照) で自動的にアクティブ化されますが、2 つの並列アルゴリズムに違いはありますか?

4

4 に答える 4

126

After a lot of searching, the best explanation I've found is from Java Performance Tuning website in Question of the month: 1.4.1 Garbage collection algorithms, January 29th, 2003

Young generation garbage collection algorithms

The (original) copying collector (Enabled by default). When this collector kicks in, all application threads are stopped, and the copying collection proceeds using one thread (which means only one CPU even if on a multi-CPU machine). This is known as a stop-the-world collection, because basically the JVM pauses everything else until the collection is completed.

The parallel copying collector (Enabled using -XX:+UseParNewGC). Like the original copying collector, this is a stop-the-world collector. However this collector parallelizes the copying collection over multiple threads, which is more efficient than the original single-thread copying collector for multi-CPU machines (though not for single-CPU machines). This algorithm potentially speeds up young generation collection by a factor equal to the number of CPUs available, when compared to the original singly-threaded copying collector.

The parallel scavenge collector (Enabled using -XX:UseParallelGC). This is like the previous parallel copying collector, but the algorithm is tuned for gigabyte heaps (over 10GB) on multi-CPU machines. This collection algorithm is designed to maximize throughput while minimizing pauses. It has an optional adaptive tuning policy which will automatically resize heap spaces. If you use this collector, you can only use the the original mark-sweep collector in the old generation (i.e. the newer old generation concurrent collector cannot work with this young generation collector).

From this information, it seems the main difference (apart from CMS cooperation) is that UseParallelGC supports ergonomics while UseParNewGC doesn't.

于 2010-01-26T19:05:11.743 に答える
21

パラレル GC

  • XX:+UseParallelGC スカベンジに並列ガベージ コレクションを使用します。(1.4.1 で導入)
  • XX:+UseParallelOldGC フル コレクションに並列ガベージ コレクションを使用します。このオプションを有効にすると、自動的に -XX:+UseParallelGC が設定されます。(5.0 update 6 で導入されました。)

UseParNewGC

UseParNewGC 若い世代のコピー コレクターの並列バージョンが並行コレクターと共に使用されます (つまり、コマンド ラインで -XX:+ UseConcMarkSweepGC が使用されている場合、コマンド ラインで明示的に設定されていない場合、フラグ UseParNewGC も true に設定されます)。 )。

おそらく、理解する最も簡単な方法は、 Alexey Ragozinによって作成されたガベージ コレクション アルゴリズムの組み合わせでした。

<table border="1" style="width:100%">
  <tr>
    <td align="center">Young collector</td>
    <td align="center">Old collector</td>
    <td align="center">JVM option</td>
  </tr>
  <tr>
    <td>Serial (DefNew)</td>
    <td>Serial Mark-Sweep-Compact</td>
    <td>-XX:+UseSerialGC</td>
  </tr>
  <tr>
    <td>Parallel scavenge (PSYoungGen)</td>
    <td>Serial Mark-Sweep-Compact (PSOldGen)</td>
    <td>-XX:+UseParallelGC</td>
  </tr>
  <tr>
    <td>Parallel scavenge (PSYoungGen)</td>
    <td>Parallel Mark-Sweep-Compact (ParOldGen)</td>
    <td>-XX:+UseParallelOldGC</td>
  </tr>
  <tr>
    <td>Serial (DefNew)</td>
    <td>Concurrent Mark Sweep</td>
    <td>
      <p>-XX:+UseConcMarkSweepGC</p>
      <p>-XX:-UseParNewGC</p>
    </td>
  </tr>
  <tr>
    <td>Parallel (ParNew)</td>
    <td>Concurrent Mark Sweep</td>
    <td>
      <p>-XX:+UseConcMarkSweepGC</p>
      <p>-XX:+UseParNewGC</p>
    </td>
  </tr>
  <tr>
    <td colspan="2">G1</td>
    <td>-XX:+UseG1GC</td>
  </tr>
</table>

結論:

  1. -XX:+UseParallelGC を適用して、若い世代のみで並列コレクション メソッドが必要な場合 (ただしそれでも)古い世代のコレクションとしてシリアル マーク スイープ メソッドを使用します。
  2. YOUNG世代 (-XX:+UseParallelGC を自動的に設定)および OLD世代のコレクションに対する並列コレクション メソッドが必要な場合は、-XX:+UseParallelOldGC を適用します。
  3. -XX:+UseParNewGC & -XX:+UseConcMarkSweepGC を適用するのは、YOUNG 世代の並列コレクション メソッドが必要ありOLD世代メモリのコレクションとして CMS メソッドが必要な場合です。
  4. -XX:+UseParallelGC または -XX:+UseParallelOldGC を -XX:+UseConcMarkSweepGC と同時に適用することはできません。そのため、-XX:+UseParNewGC を CMS とペアにする必要があります。それ以外の場合は、-XX:+UseSerialGC を明示的に使用するか、-XX : -若い世代に対してシリアルメソッドを使用する場合は、ParNewGC を使用します
于 2015-06-30T08:46:38.873 に答える
16

通常「並列若い世代のコレクター」として知られる UseParNewGC は、より洗練され効率的であることを除けば、すべての点で並列ガベージ コレクター (-XX:+UseParallelGC) と同じです。また、「同時低休止コレクター」と併用することもできます。

詳細については、 Java GC FAQの質問 22 を参照してください。

UseParNewGC には既知のバグがいくつかあることに注意してください。

于 2010-01-20T13:36:22.160 に答える