Java堆記憶體_Young Gener_Old Generation_新生代和老年代__Java

來源:互聯網
上載者:User

                                                 

使用JDK8

Java 中的堆是 JVM 所管理的最大的一塊記憶體空間,主要用於存放各種類的執行個體對象。

在 Java 中,堆被劃分成兩個不同的地區:新生代 ( Young )、老年代 ( Old )。新生代 ( Young ) 又被劃分為三個地區:Eden、From Survivor、To Survivor。

這樣劃分的目的是為了使 JVM 能夠更好的管理堆記憶體中的對象,包括記憶體的分配以及回收。

堆的記憶體模型大致為:

JDK8中的預設參數:(windows平台)

見連結:

http://docs.oracle.com/javase/8/docs/technotes/tools/windows/java.html#BABHDABI

http://www.oracle.com/technetwork/java/javase/tech/vmoptions-jsp-140102.html

參數的預設值:

ratio(比,比率;比例;係數) -XX:NewRatio

-XX:NewRatio=ratio

Sets the ratio between young and old generation sizes. By default, this option is set to 2. The following example shows how to set theyoung/old ratio to 1:

-XX:NewRatio=1 -XX:SurvivorRatio

-XX:SurvivorRatio=ratio

Sets the ratio between eden space size and survivor space size. By default, this option is set to 8. The following example shows how to set theeden/survivor space ratio to 4:

-XX:SurvivorRatio=4 -Xmssize

Sets the initial size (in bytes) of the heap. This value must be a multiple of 1024 and greater than 1 MB. Append the letter k or K to indicate kilobytes, m or M to indicate megabytes, g or G to indicate gigabytes.

The following examples show how to set the size of allocated memory to 6 MB using various units:

-Xms6291456

-Xms6144k

-Xms6m

If you do not set this option, then the initial size will be set as the sum of the sizes allocated for the old generation and the young generation. The initial size of the heap for the young generation can be set using the -Xmn option or the -XX:NewSize option. -Xmxsize

Specifies the maximum size (in bytes) of the memory allocation pool in bytes. This value must be a multiple of 1024 and greater than 2 MB. Append the letter k or K to indicate kilobytes, m or M to indicate megabytes, g or G to indicate gigabytes. The default value is chosen at runtime based on system configuration. For server deployments, -Xms and -Xmx are often set to the same value. For more information, see Garbage Collector Ergonomics at http://docs.oracle.com/javase/8/docs/technotes/guides/vm/gc-ergonomics.html

The following examples show how to set the maximum allowed size of allocated memory to 80 MB using various units:

-Xmx83886080

-Xmx81920k

-Xmx80m

The -Xmx option is equivalent to -XX:MaxHeapSize. -XX:MaxHeapSize=size

Sets the maximum size (in byes) of the memory allocation pool. This value must be a multiple of 1024 and greater than 2 MB. Append the letter k or K to indicate kilobytes, m or M to indicate megabytes, g or G to indicate gigabytes. The default value is chosen at runtime based on system configuration. For server deployments, -XX:InitialHeapSize and -XX:MaxHeapSize are often set to the same value. For more information, see Garbage Collector Ergonomics at http://docs.oracle.com/javase/8/docs/technotes/guides/vm/gc-ergonomics.html

The following examples show how to set the maximum allowed size of allocated memory to 80 MB using various units:

-XX:MaxHeapSize=83886080

-XX:MaxHeapSize=81920k

-XX:MaxHeapSize=80m

The -XX:MaxHeapSize option is equivalent to -Xmx.

預設的,新生代 ( Young ) 與老年代 ( Old ) 的比例的值為 1:2 ( 該值可以通過參數 –XX:NewRatio 來指定 ),即:新生代 ( Young ) = 1/3 的堆空間大小。

老年代 ( Old ) = 2/3 的堆空間大小。其中,新生代 ( Young ) 被細分為 Eden 和 兩個 Survivor 地區,這兩個 Survivor 地區分別被命名為 from 和 to,以示區分。

預設的,Edem : from : to = 8 : 1 : 1 ( 可以通過參數 –XX:SurvivorRatio 來設定 ),即: Eden = 8/10 的新生代空間大小,from = to = 1/10 的新生代空間大小。

JVM 每次只會使用 Eden 和其中的一塊 Survivor 地區來為物件服務,所以無論什麼時候,總是有一塊 Survivor 地區是空閑著的。

因此,新生代實際可用的記憶體空間為 9/10 ( 即90% )的新生代空間。

如下圖所示,

                                                 

如下圖所示,

                                                

 

 

轉自:http://www.codeweblog.com/java%E5%A0%86%E5%86%85%E5%AD%98_young-gener_old-generation_%E6%96%B0%E7%94%9F%E4%BB%A3%E5%92%8C%E8%80%81%E5%B9%B4%E4%BB%A3/

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.