41

メイン メモリ ドメインがほとんどないことはわかっています。Young、Tenured (Old gen)、および PermGen です。

  • ヤングドメインは、エデンとサバイバー(2個入り)に分かれています。
  • OldGen は生き残ったオブジェクト用です。

MaxTenuringThreshold は、オブジェクトが最終的に OldGen スペースにコピーされるのが早すぎるのを防ぎます。それはかなり明確で理解しやすいです。

しかし、それはどのように機能しますか?ガベージ コレクターは、MaxTenuringThreshold まで生き残っているこれらのオブジェクトをどのように処理していますか? 彼らはどこにいますか?

オブジェクトは、ガベージ コレクションのために Survivor スペースにコピーされています..または、他の方法で発生しますか?

4

2 に答える 2

74

Java ヒープ内の各オブジェクトには、ガベージ コレクション (GC) アルゴリズムで使用されるヘッダーがあります。若いスペース コレクター (オブジェクトの昇格を担当) は、このヘッダーからの数ビットを使用して、生き残ったコレクション オブジェクトの数を追跡します (32 ビット JVM はこれに 4 ビットを使用し、64 ビットはおそらくそれ以上を使用します)。 .

若いスペースの収集中に、すべてのオブジェクトがコピーされます。オブジェクトは、サバイバル スペース (若い GC の前に空のスペース) の 1 つまたは古いスペースにコピーできます。コピーされるオブジェクトごとに、GC アルゴリズムはその経過時間 (生き残ったコレクションの数) を増やします。経過時間が現在の保有期間のしきい値を超えている場合は、古い領域にコピー (昇格) されます。サバイバル スペースがいっぱいになった場合 (オーバーフロー)、オブジェクトを古いスペースに直接コピーすることもできます。

オブジェクトの旅には次のパターンがあります。

  • エデンに割り当てられた
  • 若いGCにより、エデンからサバイバルスペースにコピーされました
  • 若い GC により、サバイバルから (他の) サバイバル スペースにコピーされます (これは数回発生する可能性があります)。
  • 若い GC (またはフル GC) により、サバイバル (またはエデンの可能性) から古いスペースに昇格

実際の保有期間のしきい値は JVM によって動的に調整されますが、MaxTenuringThreshold によって上限が設定されます。

MaxTenuringThreshold=0 を設定すると、すべてのオブジェクトがすぐに昇格されます。

Java ガベージ コレクションに関する記事はほとんどありませんが、詳細についてはそちらを参照してください。

于 2012-11-25T08:01:58.817 に答える
18

(Disclaimer: This covers HotSpot VM only)

As Alexey states, the actually used tenuring threshold is determined by the JVM dynamically. There is very little value in setting it. For most applications the default value of 15 will be high enough, as usually way more object survive the collection. When many objects survive the collection, the survivor spaces overflow directly to old. This is called premature promotion and an indicator of a problem. However it seldom can be solved by tuning MaxTenuringThreshold.

In those cases sometimes SurvivorRatio might be used to increase the space in the survivor spaces, allowing the tenuring to actually work. However, most often enlarging the young generation is the only good choice (from configuration perspective). If you are looking from coding perspective, you should avoid excess object allocation to let tenuring work as designed.

To answer exactly what you asked: When an object reaches its JVM determinded tenuring threshold, it is copied to old. Before that, it will be copied to the empty survivor space. Objects that have been surviving a while but are de-referenced before reaching the threshold are cleaned from survivor very efficiently.

于 2012-11-25T20:43:54.480 に答える