public static void main ( String[ ] args) throws InterruptedException {
long totleMemory= Runtime. getRuntime ( ) . totalMemory ( ) ;
long maxMemory = Runtime. getRuntime ( ) . maxMemory ( ) ;
System. out. println ( "-Xms=:" + ( totleMemory/ ( double ) 1024 / 1024 ) + "MB" ) ;
System. out. println ( "-Xmx=:" + ( maxMemory/ ( double ) 1024 / 1024 ) + "MB" ) ;
System. out. println ( "********hello world" ) ;
Thread. sleep ( Integer. MAX_VALUE) ;
}
第一种,查看参数盘点家底
jps - l 检查进程- pid
jinfo - flags { pid} 查看全部jvm信息 1 : non- default vm flags= jvm默认值 2 : command line= 人工设置
jinfo - flag { 具体参数/ ThreadStackSize} { pid}
== == == == == == == == == == == == == == == == == == == == == == == == == == == == == == == == =
boolean 开启或关闭
- XX: + UseparalleGC
== == == == == == == == == == == == == == == == == == == == == == == == == == == == == =
key- value
- XX: MaxHeapSize= 4253024256
== == == == == == == == == == == == == == == == == == == == == == == == == == == == == == == == =
新生代占堆的1 / 3 ,老年代占堆空间的2 / 3 ,Eden占年轻代的8 / 10 ,from占1 / 10. to占1 / 10
- Xms1024m ( 堆- 默认物理内存的1 / 64 ) - Xmx1024m ( 堆= 最大物理内存的1 / 4 ) ,- Xss512k 栈空间私有大小一般(512 k- 1024 k)
- Xmn 新生代大小
- Xms等价于- XX: InitialHeapSize
- Xmx等价于- XX: MaxHeapSize
- Xss等价于- XX: ThreadStackSize
== == == == == == == == == == == == == == == == == == == == == == == == == == == == == == ==
第二种,查看参数盘点家底
java - XX: + PrintFlagsInitial jvm默认 : = 时修改过的 查看默认
java - XX: + PrintFlagsFinal - version 查看
修改
java - XX: + PrintFlagsFinal - XX: MetaspaceSize= 512 m { 运行的java类名}
MetaspaceSize= 21807104
uintx MetaspaceSize: = 536870912
cls 清屏幕
java - XX: + PrintCommandLineFlags - version
== == == == == == == == == == == == == == == == == == == == == == == == == == == == == == == =
- XX: InitialHeapSize= 132236864 - XX: MaxHeapSize= 2115789824 - XX: + PrintCommandLineFlags
- XX: + UseCompressedClassPointers - XX: + UseCompressedOops
- XX: - UseLargePagesIndividualAllocation - XX: + UseParallelGC
== == == == == == == == == == == == == == == == == == == == == == == ==
{ - XX: InitialHeapSize= 132236864
- XX: MaxHeapSize= 2115789824
- XX: + PrintCommandLineFlags
- XX: + UseCompressedClassPointers
- XX: + UseCompressedOops
- XX: - UseLargePagesIndividualAllocation
- XX: + UseParallelGC
java version "1.8.0_191"
Java ( TM) SE Runtime Environment ( build 1.8 .0 _191- b12)
Java HotSpot ( TM) 64 - Bit Server ( 服务端) VM ( build 25.191 - b12, mixed mode) }
== == == == == == == == == == == == == == == == == == == == == == == == == == == == == == == == == ==
- Xms128m - Xmx4096m - Xss1024k - XX: MetaspaceSize= 512 m - XX: + PrintCommandLineFlags - XX: + PrintGCDetails - XX: + UseParallelGC
UseParallelGC并行垃圾回收GC
MetaspaceSize默认20 m
Xss栈默认512 kb- 1024 kb,默认根据硬件决定大小
- Xms10m - Xmx10m - XX: + PrintGCDetails
== == == == == == == == == == == == == == == == == == == == == == == == == == == == == == == == == == == == == == == == == == == == == == == == == == == == == == == == == == == == == ==
[ GC ( Allocation Failure) [ PSYoungGen: 1003 K- > 488K ( 2560 K) ] 1003 K- > 632K ( 9728 K) , 0.0404763 secs] [ Times: user= 0.00 sys= 0.00 , real= 0.06 secs]
[ GC ( Allocation Failure) [ PSYoungGen: 488 K- > 496K ( 2560 K) ] 632 K- > 700K ( 9728 K) , 0.0006947 secs] [ Times: user= 0.00 sys= 0.00 , real= 0.00 secs]
[ Full GC ( Allocation Failure) [ PSYoungGen: 496 K- > 0K ( 2560 K) ] [ ParOldGen: 204 K- > 586K ( 7168 K) ] 700 K- > 586K ( 9728 K) , [ Metaspace: 2933 K- > 2933K ( 1056768 K) ] , 0.0045085 secs] [ Times: user= 0.00 sys= 0.00 , real= 0.00 secs]
[ GC ( Allocation Failure) [ PSYoungGen: 0 K- > 0K ( 2560 K) ] 586 K- > 586K ( 9728 K) , 0.0004559 secs] [ Times: user= 0.00 sys= 0.00 , real= 0.00 secs]
[ Full GC ( Allocation Failure) [ PSYoungGen: 0 K- > 0K ( 2560 K) ] [ ParOldGen: 586 K- > 562K ( 7168 K) ] 586 K- > 562K ( 9728 K) , [ Metaspace: 2933 K- > 2933K ( 1056768 K) ] , 0.0043698 secs] [ Times: user= 0.00 sys= 0.00 , real= 0.00 secs]
Heap
PSYoungGen total 2560 K, used 102 K [ 0x00000000ffd00000 , 0x0000000100000000 , 0x0000000100000000 )
eden space 2048 K, 5 % used [ 0x00000000ffd00000 , 0x00000000ffd19b40 , 0x00000000fff00000 )
from space 512 K, 0 % used [ 0x00000000fff00000 , 0x00000000fff00000 , 0x00000000fff80000 )
to space 512 K, 0 % used [ 0x00000000fff80000 , 0x00000000fff80000 , 0x0000000100000000 )
ParOldGen total 7168 K, used 562 K [ 0x00000000ff600000 , 0x00000000ffd00000 , 0x00000000ffd00000 )
object space 7168 K, 7 % used [ 0x00000000ff600000 , 0x00000000ff68c968 , 0x00000000ffd00000 )
Metaspace used 2965 K, capacity 4494 K, committed 4864 K, reserved 1056768 K
class space used 324 K, capacity 386 K, committed 512 K, reserved 1048576 K
Exception in thread "main" java. lang. OutOfMemoryError: Java heap space
== == == == == == == == == == == == == == == == == == == == == == == == == == == == == == == == == == == == == == == == == == == == == == == == == == == == == == == == == == == == == ==
- XX: SurvivorRato= 8 Eden: s0: s1= 8 : 1 : 1 Eden+ s0+ s1= young
- XX: NewRatio= 2 young: old= 1 : 2 young+ old= heap ( 堆)
- XX: NewRatio= 4 young: old= 1 : 4
== == == == == == == == == == == == == == == == == == == == == == == == == == == == == == == == == == == == ==
新生代到老年代需要在Survivor几次GC jdk7以下31 ( jdk8 ( 0 - 15 ) )
查询:jinfo - flag MaxTenuringThreshold 11685
- XX: MaxTenuringThreshold= 15
创建的对象在经过15 GC后还活着会被放置老年代区