Trace跟蹤參數(shù)
-verbose:gc
-XX:+PrintGC
[GC (System.gc()) 2663K->640K(125952K), 0.0097324 secs]
[Full GC (System.gc()) 640K->569K(125952K), 0.0052535 secs]
GC前用了約2663K-> GC后只用了640K(堆的大小約120M)
-XX:+ PrintGCDetails
打印GC詳細(xì)信息。
[GC (System.gc()) [PSYoungGen: 2663K->616K(38400K)] 2663K->624K(125952K), 0.0036339 secs] [Times: user=0.00 sys=0.00, real=0.00 secs]
[Full GC (System.gc()) Disconnected from the target VM, address: '127.0.0.1:57922', transport: 'socket'
[PSYoungGen: 616K->0K(38400K)] [ParOldGen: 8K->569K(87552K)] 624K->569K(125952K), [Metaspace: 2830K->2830K(1056768K)], 0.0061896 secs] [Times: user=0.00 sys=0.00, real=0.01 secs]
Heap
PSYoungGen total 38400K, used 333K [0x00000000d5d80000, 0x00000000d8800000, 0x0000000100000000)
eden space 33280K, 1% used [0x00000000d5d80000,0x00000000d5dd34a8,0x00000000d7e00000)
from space 5120K, 0% used [0x00000000d7e00000,0x00000000d7e00000,0x00000000d8300000)
to space 5120K, 0% used [0x00000000d8300000,0x00000000d8300000,0x00000000d8800000)
ParOldGen total 87552K, used 569K [0x0000000081800000, 0x0000000086d80000, 0x00000000d5d80000)
object space 87552K, 0% used [0x0000000081800000,0x000000008188e540,0x0000000086d80000)
Metaspace used 2839K, capacity 4486K, committed 4864K, reserved 1056768K
class space used 305K, capacity 386K, committed 512K, reserved 1048576K
-XX: + PrintGCTimeStamps
打印GC發(fā)的時(shí)間戳,自JVM啟動(dòng)以后以秒計(jì)量。
0.213: [GC (System.gc()) 2663K->656K(125952K), 0.0134724 secs]
0.226: [Full GC (System.gc()) 656K->569K(125952K), 0.0212011 secs]
-XX:+PrintGCDateStamps // GC發(fā)生的當(dāng)前時(shí)間
2019-02-27T20:21:06.730+0800: [GC (System.gc()) 2663K->632K(125952K), 0.0055284 secs]
2019-02-27T20:21:06.736+0800: [Full GC (System.gc()) 632K->569K(125952K), 0.0045613 secs]
-XX: +PrintHeapAtGC
每次GC 后缤至,都打印堆的詳細(xì)信息。Heap before GC 忱叭,Heap after GC
{Heap before GC invocations=1 (full 0):
PSYoungGen total 38400K, used 2663K [0x00000000d5d80000, 0x00000000d8800000, 0x0000000100000000)
eden space 33280K, 8% used [0x00000000d5d80000,0x00000000d6019dd0,0x00000000d7e00000)
from space 5120K, 0% used [0x00000000d8300000,0x00000000d8300000,0x00000000d8800000)
to space 5120K, 0% used [0x00000000d7e00000,0x00000000d7e00000,0x00000000d8300000)
ParOldGen total 87552K, used 0K [0x0000000081800000, 0x0000000086d80000, 0x00000000d5d80000)
object space 87552K, 0% used [0x0000000081800000,0x0000000081800000,0x0000000086d80000)
Metaspace used 2827K, capacity 4486K, committed 4864K, reserved 1056768K
class space used 304K, capacity 386K, committed 512K, reserved 1048576K
[GC (System.gc()) 2663K->704K(125952K), 0.0007834 secs]
Heap after GC invocations=1 (full 0):
PSYoungGen total 38400K, used 696K [0x00000000d5d80000, 0x00000000d8800000, 0x0000000100000000)
eden space 33280K, 0% used [0x00000000d5d80000,0x00000000d5d80000,0x00000000d7e00000)
from space 5120K, 13% used [0x00000000d7e00000,0x00000000d7eae010,0x00000000d8300000)
to space 5120K, 0% used [0x00000000d8300000,0x00000000d8300000,0x00000000d8800000)
ParOldGen total 87552K, used 8K [0x0000000081800000, 0x0000000086d80000, 0x00000000d5d80000)
object space 87552K, 0% used [0x0000000081800000,0x0000000081802000,0x0000000086d80000)
Metaspace used 2827K, capacity 4486K, committed 4864K, reserved 1056768K
class space used 304K, capacity 386K, committed 512K, reserved 1048576K
}
XX:+PrintGCApplicationStoppedTime
// 輸出GC造成應(yīng)用暫停的時(shí)間
Total time for which application threads were stopped: 0.0002322 seconds, Stopping threads took: 0.0001973 seconds
Total time for which application threads were stopped: 0.0000391 seconds, Stopping threads took: 0.0000119 seconds
Total time for which application threads were stopped: 0.0105439 seconds, Stopping threads took: 0.0000160 seconds
監(jiān)控類的加載
-XX: +TraceClassLoading
[Opened D:\Java\jdk1.8.0_74\jre\lib\rt.jar]
[Loaded java.lang.Object from D:\Java\jdk1.8.0_74\jre\lib\rt.jar]
[Loaded java.io.Serializable from D:\Java\jdk1.8.0_74\jre\lib\rt.jar]
[Loaded java.lang.Comparable from D:\Java\jdk1.8.0_74\jre\lib\rt.jar]
[Loaded java.lang.CharSequence from D:\Java\jdk1.8.0_74\jre\lib\rt.jar]
[Loaded java.lang.String from D:\Java\jdk1.8.0_74\jre\lib\rt.jar]
[Loaded java.lang.reflect.AnnotatedElement from D:\Java\jdk1.8.0_74\jre\lib\rt.jar]
[Loaded java.lang.reflect.GenericDeclaration from D:\Java\jdk1.8.0_74\jre\lib\rt.jar]
[Loaded java.lang.reflect.Type from D:\Java\jdk1.8.0_74\jre\lib\rt.jar]
[Loaded java.lang.Class from D:\Java\jdk1.8.0_74\jre\lib\rt.jar]
...
-XX: +PrintClassHistogram
按下Ctrl+Break后。打印類的使用情況 (怎么操作冈涧?奸攻?窖梁?)
輸出日志
-Xloggc:logs/gc.log
指定GC log的路徑輸出日志文件
-XX:+PrintTenuringDistribution
了解新域的情況,了解獲得使用期的對(duì)象權(quán)赊淑。(不太懂)
Desired survivor size 5242880 bytes, new threshold 7 (max 15)
堆的分配參數(shù)
-Xms:指定最小堆大小汤锨。
初始堆大小锨并,默認(rèn)為物理內(nèi)存的1/64(<1GB)揽趾;默認(rèn)(MinHeapFreeRatio參數(shù)可以調(diào)整)空余堆內(nèi)存小于40%時(shí),JVM就會(huì)增大堆直到-Xmx的最大限制
-Xmx:指定最大堆大小询筏。
默認(rèn)(MaxHeapFreeRatio參數(shù)可以調(diào)整)空余堆內(nèi)存大于70%時(shí)莺治,JVM會(huì)減少堆直到 -Xms的最小限制
eg:-Xmx20m -Xms5m
public static void printXmxXms(){
System.out.print("Xmx=");
System.out.println(Runtime.getRuntime().maxMemory()/1024/1024 + "M");
System.out.print("free mem=");
System.out.println(Runtime.getRuntime().freeMemory()/1024/1024 + "M");
System.out.print("total mem=");
System.out.println(Runtime.getRuntime().totalMemory()/1024/1024 + "M");
}
Xmx=18M // 最大可使用空間
free mem=4M // 當(dāng)前未使用的空間
total mem=5M // 當(dāng)前可用總mem空間
public static void printXmxXms(){
byte[] b = new byte[1024*1024];
System.out.println("分配了1M空間給數(shù)組");
System.out.print("Xmx=");
System.out.println(Runtime.getRuntime().maxMemory()/1024/1024 + "M");
System.out.print("free mem=");
System.out.println(Runtime.getRuntime().freeMemory()/1024/1024 + "M");
System.out.print("total mem=");
System.out.println(Runtime.getRuntime().totalMemory()/1024/1024 + "M");
}
分配了1M空間給數(shù)組
Xmx=18M
free mem=3M
total mem=5M
- Java會(huì)盡可能用最小堆减细,將數(shù)組內(nèi)存調(diào)整為4M
public static void printXmxXms(){
byte[] b = new byte[4*1024*1024];
System.out.println("分配了4M空間給數(shù)組");
System.out.print("Xmx=");
System.out.println(Runtime.getRuntime().maxMemory()/1024/1024 + "M");
System.out.print("free mem=");
System.out.println(Runtime.getRuntime().freeMemory()/1024/1024 + "M");
System.out.print("total mem=");
System.out.println(Runtime.getRuntime().totalMemory()/1024/1024 + "M");
}
分配了4M空間給數(shù)組
Xmx=18M
free mem=5M
total mem=10M
- 分配后再回收狰腌,空閑內(nèi)存會(huì)增多
public static void printXmxXms(){
byte[] b = new byte[4*1024*1024];
System.out.println("分配了4M空間給數(shù)組");
System.gc();
System.out.println("回收內(nèi)存");
System.out.print("Xmx=");
System.out.println(Runtime.getRuntime().maxMemory()/1024/1024 + "M");
System.out.print("free mem=");
System.out.println(Runtime.getRuntime().freeMemory()/1024/1024 + "M");
System.out.print("total mem=");
System.out.println(Runtime.getRuntime().totalMemory()/1024/1024 + "M");
}
分配了4M空間給數(shù)組
回收內(nèi)存
Xmx=18M
free mem=5M
total mem=10M
-Xmx 和 -Xms保持什么關(guān)系土铺,可以讓系統(tǒng)的性能盡可能的好赫蛇?
-Xmn
:設(shè)置新生代的內(nèi)存空間大小。注意:此處的大小是(eden+ 2 survivor space)病瞳。與jmap -heap中顯示的New gen是不同的逗柴。整個(gè)堆大小=新生代大小 + 老生代大小 + 永久代大小耕拷。
在保證堆大小不變的情況下羡榴,增大新生代后,將會(huì)減小老生代大小涉枫。此值對(duì)系統(tǒng)性能影響較大,Sun官方推薦配置為整個(gè)堆的3/8疆拘。
-XX:NewRatio
: 老年代(不包含永久區(qū)):新生代(eden + 2*s)哎迄。例如4回右,即新生代:老年代 = 1:4
隆圆,即年輕代占堆的1/5
-XX:SurvivorRatio
:新生代中Eden:Survivor容量比值壕吹,默認(rèn)值為8娩践,即兩個(gè)Survivor區(qū)與一個(gè)Eden區(qū)的比值為2:8,一個(gè)Survivor區(qū)占整個(gè)年輕代的1/10嗜傅。
-Xss
:每個(gè)線程的堆棧大小粪糙。JDK5.0以后每個(gè)線程堆棧大小為1M,以前每個(gè)線程堆棧大小為256K帐偎。應(yīng)根據(jù)應(yīng)用的線程所需內(nèi)存大小進(jìn)行適當(dāng)調(diào)整蔗牡。在相同物理內(nèi)存下,減小這個(gè)值能生成更多的線程痘煤。但是操作系統(tǒng)對(duì)一個(gè)進(jìn)程內(nèi)的線程數(shù)還是有限制的拨与,不能無(wú)限生成哩治,經(jīng)驗(yàn)值在3000~5000左右秃踩。一般小的應(yīng)用, 如果棧不是很深业筏, 應(yīng)該是128k夠用的憔杨,大的應(yīng)用建議使用256k。這個(gè)選項(xiàng)對(duì)性能影響比較大蒜胖,需要嚴(yán)格的測(cè)試消别。和threadstacksize選項(xiàng)解釋很類似,官方文檔似乎沒(méi)有解釋,在論壇中有這樣一句話:"-Xss is translated in a VM flag named ThreadStackSize”一般設(shè)置這個(gè)值就可以了。
- 通常只有幾百K
- 決定了函數(shù)調(diào)用的深度
- 每個(gè)線程都有獨(dú)立的椞ㄐ唬空間
- 局部變量寻狂、參數(shù)分配在棧上
// 去掉局部變量 調(diào)用層次可以更深
public static void testStackDeep(long a, long b, long c){
long e=1,f=2,g=3,h=4,i=5,k=6,q=7,x=8,y=9,z=10;
count++;
testStackDeep(a,b,c);
}
- -Xss128K結(jié)果:
deep of calling:306
java.lang.StackOverflowError
- -Xss256K結(jié)果:
deep of calling:761
java.lang.StackOverflowError
- -Xss128K 減少局部變量至 long e=1,f=2,g=3,h=4;
deep of calling:451
java.lang.StackOverflowError
-XX:PermSize
:設(shè)置永久代(perm gen)初始值。默認(rèn)值為物理內(nèi)存的1/64朋沮。
-XX:MaxPermSize
:設(shè)置持久代最大值蛇券。物理內(nèi)存的1/4。
例子1:Xmn1m
-Xmx20m -Xms20M -Xmn1m -XX:+PrintGCDetails
byte[] b=null;
for(int i=0;i<10;i++)
b = new byte[1024*1024];
Heap
PSYoungGen total 1536K, used 928K [0x00000000ffe00000, 0x0000000100000000, 0x0000000100000000)
eden space 1024K, 90% used [0x00000000ffe00000,0x00000000ffee82f8,0x00000000fff00000)
from space 512K, 0% used [0x00000000fff80000,0x00000000fff80000,0x0000000100000000)
to space 512K, 0% used [0x00000000fff00000,0x00000000fff00000,0x00000000fff80000)
ParOldGen total 18432K, used 10240K [0x00000000fec00000, 0x00000000ffe00000, 0x00000000ffe00000)
object space 18432K, 55% used [0x00000000fec00000,0x00000000ff6000a0,0x00000000ffe00000)
Metaspace used 2840K, capacity 4486K, committed 4864K, reserved 1056768K
class space used 305K, capacity 386K, committed 512K, reserved 1048576K
- 沒(méi)有觸發(fā)GC
- 全部分配在老年代
例子2: Xmn15m
-Xmx20m -Xms20M -Xmn15m -XX:+PrintGCDetails
Heap
PSYoungGen total 13824K, used 12025K [0x00000000ff100000, 0x0000000100000000, 0x0000000100000000)
eden space 12288K, 97% used [0x00000000ff100000,0x00000000ffcbe598,0x00000000ffd00000)
from space 1536K, 0% used [0x00000000ffe80000,0x00000000ffe80000,0x0000000100000000)
to space 1536K, 0% used [0x00000000ffd00000,0x00000000ffd00000,0x00000000ffe80000)
ParOldGen total 5120K, used 0K [0x00000000fec00000, 0x00000000ff100000, 0x00000000ff100000)
object space 5120K, 0% used [0x00000000fec00000,0x00000000fec00000,0x00000000ff100000)
Metaspace used 2835K, capacity 4486K, committed 4864K, reserved 1056768K
class space used 305K, capacity 386K, committed 512K, reserved 1048576K
- 沒(méi)有觸發(fā)GC
- 全部分配在eden
- 老年代未使用
例子3: Xmn7m
-Xmx20m -Xms20M -Xmn7m -XX:+PrintGCDetails
[GC (Allocation Failure) [PSYoungGen: 5266K->488K(6656K)] 5266K->1616K(19968K), 0.0015067 secs] [Times: user=0.00 sys=0.00, real=0.00 secs]
[GC (Allocation Failure) [PSYoungGen: 5726K->504K(6656K)] 6854K->2680K(19968K), 0.0038591 secs] [Times: user=0.00 sys=0.00, real=0.00 secs]
Heap
PSYoungGen total 6656K, used 1589K [0x00000000ff900000, 0x0000000100000000, 0x0000000100000000)
eden space 6144K, 17% used [0x00000000ff900000,0x00000000ffa0f748,0x00000000fff00000)
from space 512K, 98% used [0x00000000fff80000,0x00000000ffffe030,0x0000000100000000)
to space 512K, 0% used [0x00000000fff00000,0x00000000fff00000,0x00000000fff80000)
ParOldGen total 13312K, used 2176K [0x00000000fec00000, 0x00000000ff900000, 0x00000000ff900000)
object space 13312K, 16% used [0x00000000fec00000,0x00000000fee20020,0x00000000ff900000)
Metaspace used 2835K, capacity 4486K, committed 4864K, reserved 1056768K
class space used 305K, capacity 386K, committed 512K, reserved 1048576K
- 進(jìn)行了2次新生代GC
- from to 不夠用樊拓,需要老年代擔(dān)保纠亚,即部分存放在老年代中
例子4: -XX:SurvivorRatio=2
-Xmx20m -Xms20M -Xmn7m -XX:SurvivorRatio=2 -XX:+PrintGCDetails
調(diào)整幸存代的比例
[GC (Allocation Failure) [PSYoungGen: 3120K->1512K(5632K)] 3120K->1632K(18944K), 0.0011179 secs] [Times: user=0.00 sys=0.00, real=0.00 secs]
[GC (Allocation Failure) [PSYoungGen: 4662K->1528K(5632K)] 4782K->1648K(18944K), 0.0009248 secs] [Times: user=0.00 sys=0.00, real=0.00 secs]
[GC (Allocation Failure) [PSYoungGen: 4670K->1512K(5632K)] 4790K->1656K(18944K), 0.0006121 secs] [Times: user=0.00 sys=0.00, real=0.00 secs]
Heap
PSYoungGen total 5632K, used 3715K [0x00000000ff900000, 0x0000000100000000, 0x0000000100000000)
eden space 4096K, 53% used [0x00000000ff900000,0x00000000ffb26f98,0x00000000ffd00000)
from space 1536K, 98% used [0x00000000ffd00000,0x00000000ffe7a030,0x00000000ffe80000)
to space 1536K, 0% used [0x00000000ffe80000,0x00000000ffe80000,0x0000000100000000)
ParOldGen total 13312K, used 144K [0x00000000fec00000, 0x00000000ff900000, 0x00000000ff900000)
object space 13312K, 1% used [0x00000000fec00000,0x00000000fec24000,0x00000000ff900000)
Metaspace used 2836K, capacity 4486K, committed 4864K, reserved 1056768K
class space used 305K, capacity 386K, committed 512K, reserved 1048576K
- 對(duì)新生代進(jìn)行了3次GC
- from to 空間增大
例子5:-XX:NewRatio 繼續(xù)增大from to
-Xmx20m -Xms20M -Xmn7m -XX:NewRatio=1 -XX:SurvivorRatio=2 -XX:+PrintGCDetails
[GC (Allocation Failure) [PSYoungGen: 4215K->1720K(7680K)] 4215K->1728K(17920K), 0.0015462 secs] [Times: user=0.00 sys=0.00, real=0.00 secs]
[GC (Allocation Failure)[PSYoungGen: 5914K->1720K(7680K)] 5922K->1736K(17920K), 0.0086064 secs] [Times: user=0.00 sys=0.00, real=0.01 secs]
Heap
PSYoungGen total 7680K, used 5036K [0x00000000ff600000, 0x0000000100000000, 0x0000000100000000)
eden space 5120K, 64% used [0x00000000ff600000,0x00000000ff93d270,0x00000000ffb00000)
from space 2560K, 67% used [0x00000000ffd80000,0x00000000fff2e020,0x0000000100000000)
to space 2560K, 0% used [0x00000000ffb00000,0x00000000ffb00000,0x00000000ffd80000)
ParOldGen total 10240K, used 16K [0x00000000fec00000, 0x00000000ff600000, 0x00000000ff600000)
object space 10240K, 0% used [0x00000000fec00000,0x00000000fec04000,0x00000000ff600000)
Metaspace used 2840K, capacity 4486K, committed 4864K, reserved 1056768K
class space used 305K, capacity 386K, committed 512K, reserved 1048576K
- GC次數(shù)降低
- 老年代中存放的數(shù)據(jù)比例很少
例子6:-XX:SurvivorRatio=4 減小幸存代大小增大eden
[GC (Allocation Failure) [PSYoungGen: 6411K->1528K(8704K)] 6411K->1664K(18944K), 0.0009235 secs] [Times: user=0.00 sys=0.00, real=0.00 secs]
Heap
PSYoungGen total 8704K, used 6847K [0x00000000ff600000, 0x0000000100000000, 0x0000000100000000)
eden space 7168K, 74% used [0x00000000ff600000,0x00000000ffb31cd8,0x00000000ffd00000)
from space 1536K, 99% used [0x00000000ffd00000,0x00000000ffe7e020,0x00000000ffe80000)
to space 1536K, 0% used [0x00000000ffe80000,0x00000000ffe80000,0x0000000100000000)
ParOldGen total 10240K, used 136K [0x00000000fec00000, 0x00000000ff600000, 0x00000000ff600000)
object space 10240K, 1% used [0x00000000fec00000,0x00000000fec22000,0x00000000ff600000)
Metaspace used 2836K, capacity 4486K, committed 4864K, reserved 1056768K
class space used 305K, capacity 386K, committed 512K, reserved 1048576K
- 新生代GC次數(shù)只有1次
- 老年代存放數(shù)據(jù)比例也很低
- 空間使用率高
-XX:+HeapDumpOnOutOfMemoryError
OOM時(shí)導(dǎo)出堆信息到文件
-XX:+HeapDumpPath
導(dǎo)出OOM的路徑
-
HeapDump例子:
-Xmx20m -Xms5M -XX:+HeapDumpOnOutOfMemoryError -XX:HeapDumpPath=D:/testHeapDump.dump
Vector vector = new Vector();
for (int i = 0;i<25;i++){
vector.add(new byte[1024*1024]);
}
java.lang.OutOfMemoryError: Java heap space
Dumping heap to D:/testHeapDump.dump ...
Disconnected from the target VM, address: '127.0.0.1:60500', transport: 'socket'
Exception in thread "main" java.lang.OutOfMemoryError: Java heap space
at LookForClassLoader.testHeapDump(LookForClassLoader.java:66)
at LookForClassLoader.main(LookForClassLoader.java:22)
Heap dump file created [15981435 bytes in 0.027 secs]
通過(guò)debug工具打開(kāi)即可
-XX:OnOutOfMemoryError
- 在OOM時(shí),執(zhí)行一個(gè)腳本
- -XX:OnOutOfMemoryError=/xxx/xxx.bat
- 可以在OOM時(shí)筋夏,發(fā)送郵件蒂胞,甚至是重啟程序
堆的分配參數(shù)-總結(jié)
- 根據(jù)實(shí)際事情調(diào)整新生代和幸存代的大小
- 官方推薦新生代占堆的3/8
- 幸存代占新生代的1/10
- 在OOM時(shí),記得Dump出堆条篷,確逼妫可以排查現(xiàn)場(chǎng)問(wèn)題
永久區(qū)分配參數(shù)
-XX:PermSize -XX:MaxPermSize
- 設(shè)置永久區(qū)的初初始空間和最大空間
- 表示一個(gè)系統(tǒng)可以容納多少個(gè)類型
例子:使用CGLIB等庫(kù)的時(shí)候,可能會(huì)產(chǎn)生大量的類赴叹,這些類鸿染,有可能撐爆永久區(qū)導(dǎo)致OOM
打開(kāi)堆的Dump
- 堆空間實(shí)際占用非常少
- 但是永久區(qū)溢出 一樣拋出OOM(即如果堆空間沒(méi)有用完也拋出了OOM,有可能是永久區(qū)溢出導(dǎo)致的)
相關(guān)了解:
-
年輕代(Young Gen)
- 總大小 已使用 [低邊界(在內(nèi)存中的起始位置)稚瘾,當(dāng)前邊界(當(dāng)前被分配到的位置)牡昆,最高邊界(最高能申請(qǐng)到的位置)]
- 年輕代主要存放新創(chuàng)建的對(duì)象,內(nèi)存大小相對(duì)會(huì)比較小,垃圾回收會(huì)比較頻繁丢烘。年輕代分成1個(gè)Eden Space和2個(gè)Suvivor Space(命名為A和B)柱宦。當(dāng)對(duì)象在堆創(chuàng)建時(shí),將進(jìn)入年輕代的Eden Space播瞳。垃圾回收器進(jìn)行垃圾回收時(shí)掸刊,掃描Eden Space和A Suvivor Space,如果對(duì)象仍然存活赢乓,則復(fù)制到B Suvivor Space忧侧,如果B Suvivor Space已經(jīng)滿,則復(fù)制到Old Gen牌芋。同時(shí)蚓炬,在掃描Suvivor Space時(shí),如果對(duì)象已經(jīng)經(jīng)過(guò)了幾次的掃描仍然存活躺屁,JVM認(rèn)為其為一個(gè)持久化對(duì)象肯夏,則將其移到Old Gen。掃描完畢后犀暑,JVM將Eden Space和A Suvivor Space清空驯击,然后交換A和B的角色(即下次垃圾回收時(shí)會(huì)掃描Eden Space和B Suvivor Space。這么做主要是為了減少內(nèi)存碎片的產(chǎn)生耐亏。
-
0x00000000d8800000 - 0x00000000d5d80000 /1024= eden space + from space + to space =可用的容量
年輕代的total = eden space + from space
-
年老代(Tenured Gen)
- 年老代主要存放JVM認(rèn)為生命周期比較長(zhǎng)的對(duì)象(經(jīng)過(guò)幾次的Young Gen的垃圾回收后仍然存在)徊都,內(nèi)存大小相對(duì)會(huì)比較大,垃圾回收也相對(duì)沒(méi)有那么頻繁(譬如可能幾個(gè)小時(shí)一次)广辰。
-
持久代(Perm Gen)
- 持久代主要存放類定義暇矫、字節(jié)碼和常量等很少會(huì)變更的信息。
分代策略
JVM在程序運(yùn)行過(guò)程當(dāng)中轨域,會(huì)創(chuàng)建大量的對(duì)象袱耽,這些對(duì)象杀餐,大部分是短周期的對(duì)象干发,小部分是長(zhǎng)周期的對(duì)象,對(duì)于短周期的對(duì)象史翘,需要頻繁地進(jìn)行垃圾回收以保證無(wú)用對(duì)象盡早被釋放掉枉长,對(duì)于長(zhǎng)周期對(duì)象,則不需要頻率垃圾回收以確保無(wú)謂地垃圾掃描檢測(cè)琼讽。為解決這種矛盾必峰,Sun JVM的內(nèi)存管理采用分代的策略。
參考文檔:https://blog.csdn.net/jisuanjiguoba/article/details/80156781