江的福的小本本之JVM常用基本配置参数

-Xms:初始大小内存,默认为物理内存的1/64。
等价于-XX:InitialHeapSize
-Xmx:最大分配内存,默认为物理内存的1/4。
等价于-XX:MaxlHeapSize

-Xss:设置单个线程栈的大小,一般默认为512k~1024k。
等价于-XX:ThreadStackSize
这个大小是依赖于平台的。在这里插入图片描述

-Xmn:新生区年轻代的大小。(很少情况下会调)

-XX:MetaspaceSize:设置元空间大小。元空间本质与永久代相似,都是jvm规范中方法区的实现。
不过,元空间与永久代最大的区别在于:
元空间不在虚拟机中,而是使用本地内存。
因此,默认情况下,元空间的大小仅受本地内存的限制。

-XX:+PrintCommandLineFlags:查看命令行参数
以下是我打印下下来的配置参数
-XX:InitialHeapSize=134217728 -XX:MaxHeapSize=2147483648 -XX:+PrintCommandLineFlags -XX:+UseCompressedClassPointers -XX:+UseCompressedOops -XX:+UseParallelGC

-XX:+PrintGCDetails 输出详细的GC收集日志信息
在这里插入图片描述
改变堆内存初始值,使得出现OOM异常
在这里插入图片描述在这里插入图片描述
在这里插入图片描述

hello gc
[GC (Allocation Failure) [PSYoungGen: 1524K->496K(2560K)] 1524K->504K(9728K), 0.0013430 secs] [Times: user=0.00 sys=0.00, real=0.00 secs] 

[GC (Allocation Failure) [PSYoungGen: 496K->416K(2560K)] 504K->424K(9728K), 0.0008321 secs] [Times: user=0.00 sys=0.00, real=0.00 secs] 

[Full GC (Allocation Failure) [PSYoungGen: 416K->0K(2560K)] [ParOldGen: 8K->386K(7168K)] 424K->386K(9728K), [Metaspace: 3018K->3018K(1056768K)], 0.0053982 secs] [Times: user=0.01 sys=0.01, real=0.00 secs] 

[GC (Allocation Failure) [PSYoungGen: 0K->0K(2560K)] 386K->386K(9728K), 0.0004945 secs] [Times: user=0.00 sys=0.00, real=0.00 secs] 

[Full GC (Allocation Failure) [PSYoungGen: 0K->0K(2560K)] [ParOldGen: 386K->368K(7168K)] 386K->368K(9728K), [Metaspace: 3018K->3018K(1056768K)], 0.0050147 secs] [Times: user=0.01 sys=0.00, real=0.01 secs] 

Heap
 PSYoungGen      total 2560K, used 80K [0x00000007bfd00000, 0x00000007c0000000, 0x00000007c0000000)
  eden space 2048K, 3% used [0x00000007bfd00000,0x00000007bfd19fe8,0x00000007bff00000)
  from space 512K, 0% used [0x00000007bff00000,0x00000007bff00000,0x00000007bff80000)
  to   space 512K, 0% used [0x00000007bff80000,0x00000007bff80000,0x00000007c0000000)
 ParOldGen       total 7168K, used 368K [0x00000007bf600000, 0x00000007bfd00000, 0x00000007bfd00000)
  object space 7168K, 5% used [0x00000007bf600000,0x00000007bf65c2b0,0x00000007bfd00000)
  
 Metaspace       used 3084K, capacity 4496K, committed 4864K, reserved 1056768K
  class space    used 338K, capacity 388K, committed 512K, reserved 1048576K
Exception in thread "main" java.lang.OutOfMemoryError: Java heap space
	at com.company.Main.main(Main.java:9)


GC前-GC后-该区总内存

-XX:SurvivalRatio
在这里插入图片描述
-XX:NewRatio在这里插入图片描述

-XX:MaxTenuringThreshold :设置垃圾的最大年龄
即进入老年代的年龄限制
在这里插入图片描述

发布了51 篇原创文章 · 获赞 11 · 访问量 1751

猜你喜欢

转载自blog.csdn.net/weixin_45276914/article/details/105549982