#查看默认回收器(8用的是PS,11用的是G)
[root@ubuntu2004 ~]#java -XX:+PrintCommandLineFlags -version
-XX:InitialHeapSize=31989504 -XX:MaxHeapSize=511832064 -XX:+PrintCommandLineFlags -XX:+UseCompressedClassPointers -XX:+UseCompressedOops -XX:+UseParallelGC
java version "1.8.0_341"
Java(TM) SE Runtime Environment (build 1.8.0_341-b10)
Java HotSpot(TM) 64-Bit Server VM (build 25.341-b10, mixed mode)
[root@ubuntu2004 ~]#cat HeapOom2.java
import java. util. Random;
public class HeapOom2 {
public static void main(String[] args) {
String str = "I am wangxiaochun";
while (true){
str += str + new Random().nextInt(88888888);
}
}
}
#-XX:+UseSerialGC表示Serial+SerialOld
[root@ubuntu2004 ~]#java -Xms10m -Xmx10m -XX:+PrintGCDetails -XX:+UseSerialGC -cp . HeapOom2
[GC (Allocation Failure) [DefNew: 2368K->320K(3072K), 0.0010993 secs] 2368K->656K(9920K), 0.0011677 secs] [Times: user=0.00 sys=0.00, real=0.00 secs]
[GC (Allocation Failure) [DefNew: 2369K->0K(3072K), 0.0009463 secs] 2705K->1254K(9920K), 0.0009739 secs] [Times: user=0.00 sys=0.00, real=0.00 secs]
[GC (Allocation Failure) [DefNew: 2440K->0K(3072K), 0.0018090 secs] 3695K->2850K(9920K), 0.0018634 secs] [Times: user=0.00 sys=0.00, real=0.00 secs]
[GC (Allocation Failure) [DefNew: 1639K->0K(3072K), 0.0009959 secs] 4489K->4446K(9920K), 0.0010349 secs] [Times: user=0.00 sys=0.00, real=0.01 secs]
[GC (Allocation Failure) [DefNew: 1595K->0K(3072K), 0.0007849 secs][Tenured: 6042K->2849K(6848K), 0.0008688 secs] 6042K->2849K(9920K), [Metaspace: 2494K->2494K(1056768K)], 0.0017076 secs] [Times: user=0.00 sys=0.00, real=0.00 secs]
[GC (Allocation Failure) [DefNew: 1643K->1643K(3072K), 0.0000090 secs][Tenured: 6041K->2052K(6848K), 0.0006230 secs] 7684K->2052K(9920K), [Metaspace: 2494K->2494K(1056768K)], 0.0006667 secs] [Times: user=0.00 sys=0.00, real=0.00 secs]
[GC (Allocation Failure) [DefNew: 1645K->1645K(3072K), 0.0000100 secs][Tenured: 5243K->5243K(6848K), 0.0005473 secs] 6889K->5243K(9920K), [Metaspace: 2494K->2494K(1056768K)], 0.0006073 secs] [Times: user=0.00 sys=0.00, real=0.00 secs]
[Full GC (Allocation Failure) [Tenured: 5243K->5030K(6848K), 0.0007026 secs] 5243K->5030K(9920K), [Metaspace: 2494K->2494K(1056768K)], 0.0007167 secs] [Times: user=0.00 sys=0.00, real=0.00 secs]
Exception in thread "main" java.lang.OutOfMemoryError: Java heap space
at java.util.Arrays.copyOf(Arrays.java:3332)
at java.lang.AbstractStringBuilder.ensureCapacityInternal(AbstractStringBuilder.java:124)
at java.lang.AbstractStringBuilder.append(AbstractStringBuilder.java:674)
at java.lang.StringBuilder.append(StringBuilder.java:214)
at HeapOom2.main(HeapOom2.java:6)
Heap
def new generation total 3072K, used 107K [0x00000000ff600000, 0x00000000ff950000, 0x00000000ff950000)
eden space 2752K, 3% used [0x00000000ff600000, 0x00000000ff61acd8, 0x00000000ff8b0000)
from space 320K, 0% used [0x00000000ff900000, 0x00000000ff900000, 0x00000000ff950000)
to space 320K, 0% used [0x00000000ff8b0000, 0x00000000ff8b0000, 0x00000000ff900000)
tenured generation total 6848K, used 5030K [0x00000000ff950000, 0x0000000100000000, 0x0000000100000000)
the space 6848K, 73% used [0x00000000ff950000, 0x00000000ffe39978, 0x00000000ffe39a00, 0x0000000100000000)
Metaspace used 2530K, capacity 4486K, committed 4864K, reserved 1056768K
class space used 270K, capacity 386K, committed 512K, reserved 1048576K
#-XX:+UseParNewGC表示ParNew+SerialOld
[root@ubuntu2004 ~]#java -Xms10m -Xmx10m -XX:+PrintGCDetails -XX:+UseParNewGC -cp . HeapOom2
Java HotSpot(TM) 64-Bit Server VM warning: Using the ParNew young collector with the Serial old collector is deprecated and will likely be removed in a future release
[GC (Allocation Failure) [ParNew: 2372K->265K(3072K), 0.0026340 secs] 2372K->665K(9920K), 0.0027285 secs] [Times: user=0.00 sys=0.00, real=0.00 secs]
[GC (Allocation Failure) [ParNew: 2318K->100K(3072K), 0.0008240 secs] 2718K->1568K(9920K), 0.0008753 secs] [Times: user=0.00 sys=0.00, real=0.00 secs]
[GC (Allocation Failure) [ParNew: 2545K->25K(3072K), 0.0029118 secs] 4013K->3092K(9920K), 0.0030344 secs] [Times: user=0.00 sys=0.00, real=0.01 secs]
[GC (Allocation Failure) [ParNew: 1667K->6K(3072K), 0.0012188 secs] 4734K->5471K(9920K), 0.0013354 secs] [Times: user=0.00 sys=0.00, real=0.00 secs]
[GC (Allocation Failure) [ParNew: 1605K->1605K(3072K), 0.0000530 secs][Tenured: 5465K->2654K(6848K), 0.0010717 secs] 7070K->2654K(9920K), [Metaspace: 2494K->2494K(1056768K)], 0.0013500 secs] [Times: user=0.00 sys=0.00, real=0.00 secs]
[GC (Allocation Failure) [ParNew: 1646K->1646K(3072K), 0.0000669 secs][Tenured: 5852K->1855K(6848K), 0.0009740 secs] 7498K->1855K(9920K), [Metaspace: 2494K->2494K(1056768K)], 0.0013161 secs] [Times: user=0.00 sys=0.00, real=0.00 secs]
[GC (Allocation Failure) [ParNew: 1648K->0K(3072K), 0.0006673 secs][Tenured: 5052K->5052K(6848K), 0.0011648 secs] 6701K->5052K(9920K), [Metaspace: 2494K->2494K(1056768K)], 0.0021430 secs] [Times: user=0.00 sys=0.00, real=0.00 secs]
[Full GC (Allocation Failure) [Tenured: 5052K->5039K(6848K), 0.0027598 secs] 5052K->5039K(9920K), [Metaspace: 2494K->2494K(1056768K)], 0.0040635 secs] [Times: user=0.00 sys=0.00, real=0.01 secs]
Exception in thread "main" java.lang.OutOfMemoryError: Java heap space
at java.util.Arrays.copyOf(Arrays.java:3332)
at java.lang.AbstractStringBuilder.ensureCapacityInternal(AbstractStringBuilder.java:124)
at java.lang.AbstractStringBuilder.append(AbstractStringBuilder.java:674)
at java.lang.StringBuilder.append(StringBuilder.java:214)
at HeapOom2.main(HeapOom2.java:6)
Heap
par new generation total 3072K, used 107K [0x00000000ff600000, 0x00000000ff950000, 0x00000000ff950000)
eden space 2752K, 3% used [0x00000000ff600000, 0x00000000ff61acd8, 0x00000000ff8b0000)
from space 320K, 0% used [0x00000000ff900000, 0x00000000ff900000, 0x00000000ff950000)
to space 320K, 0% used [0x00000000ff8b0000, 0x00000000ff8b0000, 0x00000000ff900000)
tenured generation total 6848K, used 5039K [0x00000000ff950000, 0x0000000100000000, 0x0000000100000000)
the space 6848K, 73% used [0x00000000ff950000, 0x00000000ffe3bef8, 0x00000000ffe3c000, 0x0000000100000000)
Metaspace used 2530K, capacity 4486K, committed 4864K, reserved 1056768K
class space used 270K, capacity 386K, committed 512K, reserved 1048576K
#-XX:+UseParallelGC表示PS+ParOld 此为默认值
[root@ubuntu2004 ~]#java -Xms10m -Xmx10m -XX:+PrintGCDetails -XX:+UseParallelGC -cp . HeapOom2
[GC (Allocation Failure) [PSYoungGen: 1967K->495K(2560K)] 1967K->759K(9728K), 0.0020023 secs] [Times: user=0.00 sys=0.00, real=0.01 secs]
[GC (Allocation Failure) [PSYoungGen: 2535K->495K(2560K)] 2799K->783K(9728K), 0.0008190 secs] [Times: user=0.00 sys=0.00, real=0.00 secs]
[GC (Allocation Failure) [PSYoungGen: 2535K->128K(2560K)] 4423K->2815K(9728K), 0.0009744 secs] [Times: user=0.00 sys=0.00, real=0.00 secs]
[GC (Allocation Failure) [PSYoungGen: 968K->96K(2560K)] 5255K->4382K(9728K), 0.0022313 secs] [Times: user=0.00 sys=0.00, real=0.01 secs]
[GC (Allocation Failure) [PSYoungGen: 96K->128K(2560K)] 4382K->4414K(9728K), 0.0024736 secs] [Times: user=0.00 sys=0.00, real=0.00 secs]
[Full GC (Allocation Failure) [PSYoungGen: 128K->0K(2560K)] [ParOldGen: 4286K->2655K(7168K)] 4414K->2655K(9728K), [Metaspace: 2493K->2493K(1056768K)], 0.0040468 secs] [Times: user=0.01 sys=0.00, real=0.00 secs]
[GC (Allocation Failure) --[PSYoungGen: 1640K->1640K(2560K)] 7495K->7495K(9728K), 0.0011997 secs] [Times: user=0.00 sys=0.00, real=0.01 secs]
[Full GC (Ergonomics) [PSYoungGen: 1640K->0K(2560K)] [ParOldGen: 5854K->1855K(7168K)] 7495K->1855K(9728K), [Metaspace: 2493K->2493K(1056768K)], 0.0038891 secs] [Times: user=0.00 sys=0.01, real=0.00 secs]
[GC (Allocation Failure) [PSYoungGen: 1640K->0K(1536K)] 6695K->5054K(8704K), 0.0011501 secs] [Times: user=0.00 sys=0.00, real=0.00 secs]
[GC (Allocation Failure) [PSYoungGen: 0K->0K(2048K)] 5054K->5054K(9216K), 0.0011806 secs] [Times: user=0.00 sys=0.00, real=0.00 secs]
[Full GC (Allocation Failure) [PSYoungGen: 0K->0K(2048K)] [ParOldGen: 5054K->5054K(7168K)] 5054K->5054K(9216K), [Metaspace: 2493K->2493K(1056768K)], 0.0046238 secs] [Times: user=0.00 sys=0.00, real=0.00 secs]
[GC (Allocation Failure) [PSYoungGen: 0K->0K(2048K)] 5054K->5054K(9216K), 0.0011459 secs] [Times: user=0.00 sys=0.00, real=0.00 secs]
[Full GC (Allocation Failure) [PSYoungGen: 0K->0K(2048K)] [ParOldGen: 5054K->5041K(7168K)] 5054K->5041K(9216K), [Metaspace: 2493K->2493K(1056768K)], 0.0047783 secs] [Times: user=0.01 sys=0.00, real=0.00 secs]
Exception in thread "main" java.lang.OutOfMemoryError: Java heap space
at java.util.Arrays.copyOf(Arrays.java:3332)
at java.lang.AbstractStringBuilder.ensureCapacityInternal(AbstractStringBuilder.java:124)
at java.lang.AbstractStringBuilder.append(AbstractStringBuilder.java:674)
at java.lang.StringBuilder.append(StringBuilder.java:214)
at HeapOom2.main(HeapOom2.java:6)
Heap
PSYoungGen total 2048K, used 41K [0x00000000ffd00000, 0x0000000100000000, 0x0000000100000000)
eden space 1024K, 4% used [0x00000000ffd00000,0x00000000ffd0a538,0x00000000ffe00000)
from space 1024K, 0% used [0x00000000fff00000,0x00000000fff00000,0x0000000100000000)
to space 1024K, 0% used [0x00000000ffe00000,0x00000000ffe00000,0x00000000fff00000)
ParOldGen total 7168K, used 5041K [0x00000000ff600000, 0x00000000ffd00000, 0x00000000ffd00000)
object space 7168K, 70% used [0x00000000ff600000,0x00000000ffaec678,0x00000000ffd00000)
Metaspace used 2529K, capacity 4486K, committed 4864K, reserved 1056768K
class space used 270K, capacity 386K, committed 512K, reserved 1048576K
#-XX:+UseParallelOldGC表示PS+ParOld
[root@ubuntu2004 ~]#java -Xms10m -Xmx10m -XX:+PrintGCDetails -XX:+UseParallelOldGC -cp . HeapOom2
[GC (Allocation Failure) [PSYoungGen: 2009K->495K(2560K)] 2009K->760K(9728K), 0.0021299 secs] [Times: user=0.00 sys=0.00, real=0.00 secs]
[GC (Allocation Failure) [PSYoungGen: 2536K->496K(2560K)] 2800K->760K(9728K), 0.0028162 secs] [Times: user=0.00 sys=0.00, real=0.01 secs]
[GC (Allocation Failure) [PSYoungGen: 2536K->128K(2560K)] 4400K->2792K(9728K), 0.0043149 secs] [Times: user=0.00 sys=0.00, real=0.01 secs]
[GC (Allocation Failure) [PSYoungGen: 968K->96K(2560K)] 5232K->4360K(9728K), 0.0029245 secs] [Times: user=0.00 sys=0.00, real=0.00 secs]
[GC (Allocation Failure) [PSYoungGen: 96K->96K(2560K)] 4360K->4360K(9728K), 0.0018155 secs] [Times: user=0.00 sys=0.00, real=0.00 secs]
[Full GC (Allocation Failure) [PSYoungGen: 96K->0K(2560K)] [ParOldGen: 4264K->2656K(7168K)] 4360K->2656K(9728K), [Metaspace: 2498K->2498K(1056768K)], 0.0033524 secs] [Times: user=0.01 sys=0.00, real=0.01 secs]
[GC (Allocation Failure) --[PSYoungGen: 1640K->1640K(2560K)] 7497K->7497K(9728K), 0.0010023 secs] [Times: user=0.00 sys=0.00, real=0.00 secs]
[Full GC (Ergonomics) [PSYoungGen: 1640K->0K(2560K)] [ParOldGen: 5856K->1856K(7168K)] 7497K->1856K(9728K), [Metaspace: 2498K->2498K(1056768K)], 0.0060131 secs] [Times: user=0.01 sys=0.00, real=0.01 secs]
[GC (Allocation Failure) [PSYoungGen: 1640K->0K(1536K)] 6696K->5056K(8704K), 0.0018837 secs] [Times: user=0.00 sys=0.00, real=0.00 secs]
[GC (Allocation Failure) [PSYoungGen: 0K->0K(2048K)] 5056K->5056K(9216K), 0.0008076 secs] [Times: user=0.00 sys=0.00, real=0.00 secs]
[Full GC (Allocation Failure) [PSYoungGen: 0K->0K(2048K)] [ParOldGen: 5056K->5056K(7168K)] 5056K->5056K(9216K), [Metaspace: 2498K->2498K(1056768K)], 0.0018430 secs] [Times: user=0.00 sys=0.00, real=0.00 secs]
[GC (Allocation Failure) [PSYoungGen: 0K->0K(2048K)] 5056K->5056K(9216K), 0.0006821 secs] [Times: user=0.00 sys=0.00, real=0.00 secs]
[Full GC (Allocation Failure) [PSYoungGen: 0K->0K(2048K)] [ParOldGen: 5056K->5043K(7168K)] 5056K->5043K(9216K), [Metaspace: 2498K->2498K(1056768K)], 0.0027755 secs] [Times: user=0.01 sys=0.00, real=0.01 secs]
Exception in thread "main" java.lang.OutOfMemoryError: Java heap space
at java.util.Arrays.copyOf(Arrays.java:3332)
at java.lang.AbstractStringBuilder.ensureCapacityInternal(AbstractStringBuilder.java:124)
at java.lang.AbstractStringBuilder.append(AbstractStringBuilder.java:674)
at java.lang.StringBuilder.append(StringBuilder.java:214)
at HeapOom2.main(HeapOom2.java:6)
Heap
PSYoungGen total 2048K, used 41K [0x00000000ffd00000, 0x0000000100000000, 0x0000000100000000)
eden space 1024K, 4% used [0x00000000ffd00000,0x00000000ffd0a510,0x00000000ffe00000)
from space 1024K, 0% used [0x00000000fff00000,0x00000000fff00000,0x0000000100000000)
to space 1024K, 0% used [0x00000000ffe00000,0x00000000ffe00000,0x00000000fff00000)
ParOldGen total 7168K, used 5043K [0x00000000ff600000, 0x00000000ffd00000, 0x00000000ffd00000)
object space 7168K, 70% used [0x00000000ff600000,0x00000000ffaecca8,0x00000000ffd00000)
Metaspace used 2533K, capacity 4486K, committed 4864K, reserved 1056768K
class space used 270K, capacity 386K, committed 512K, reserved 1048576K
#-XX:+UseConcMarkSweepGC表示ParNew+CMS
[root@ubuntu2004 ~]#java -Xms10m -Xmx10m -XX:+PrintGCDetails -XX:+UseConcMarkSweepGC -cp . HeapOom2
[GC (Allocation Failure) [ParNew: 2418K->320K(3072K), 0.0029774 secs] 2418K->664K(9920K), 0.0031033 secs] [Times: user=0.01 sys=0.00, real=0.00 secs]
[GC (Allocation Failure) [ParNew: 2369K->47K(3072K), 0.0023639 secs] 2714K->1310K(9920K), 0.0024581 secs] [Times: user=0.00 sys=0.00, real=0.00 secs]
[GC (Allocation Failure) [ParNew: 2495K->11K(3072K), 0.0024174 secs] 3758K->2870K(9920K), 0.0025438 secs] [Times: user=0.00 sys=0.00, real=0.01 secs]
[GC (Allocation Failure) [ParNew: 1661K->2K(3072K), 0.0020660 secs] 4521K->4458K(9920K), 0.0021964 secs] [Times: user=0.01 sys=0.00, real=0.00 secs]
[GC (CMS Initial Mark) [1 CMS-initial-mark: 4455K(6848K)] 6054K(9920K), 0.0005042 secs] [Times: user=0.00 sys=0.00, real=0.00 secs]
[CMS-concurrent-mark-start]
[CMS-concurrent-mark: 0.001/0.001 secs] [Times: user=0.00 sys=0.00, real=0.00 secs]
[CMS-concurrent-preclean-start]
[CMS-concurrent-preclean: 0.000/0.000 secs] [Times: user=0.00 sys=0.00, real=0.00 secs]
[GC (Allocation Failure) [ParNew: 1652K->2K(3072K), 0.0024163 secs][CMS (concurrent mode failure): 6051K->2654K(6848K), 0.0030528 secs] 6107K->2654K(9920K), [Metaspace: 2496K->2496K(1056768K)], 0.0055553 secs] [Times: user=0.00 sys=0.00, real=0.01 secs]
[GC (Allocation Failure) [ParNew: 1649K->1649K(3072K), 0.0000333 secs][CMS: 5846K->1856K(6848K), 0.0024940 secs] 7496K->1856K(9920K), [Metaspace: 2496K->2496K(1056768K)], 0.0026291 secs] [Times: user=0.01 sys=0.00, real=0.00 secs]
[GC (Allocation Failure) [ParNew: 1650K->0K(3072K), 0.0004406 secs][CMS: 5048K->5048K(6848K), 0.0008352 secs] 6698K->5048K(9920K), [Metaspace: 2496K->2496K(1056768K)], 0.0014067 secs] [Times: user=0.00 sys=0.00, real=0.00 secs]
[Full GC (Allocation Failure) [CMS: 5048K->5035K(6848K), 0.0009490 secs] 5048K->5035K(9920K), [Metaspace: 2496K->2496K(1056768K)], 0.0009687 secs] [Times: user=0.00 sys=0.00, real=0.00 secs]
Exception in thread "main" java.lang.OutOfMemoryError: Java heap space
at java.util.Arrays.copyOf(Arrays.java:3332)
at java.lang.AbstractStringBuilder.ensureCapacityInternal(AbstractStringBuilder.java:124)
at java.lang.AbstractStringBuilder.append(AbstractStringBuilder.java:674)
at java.lang.StringBuilder.append(StringBuilder.java:214)
at HeapOom2.main(HeapOom2.java:6)
Heap
par new generation total 3072K, used 109K [0x00000000ff600000, 0x00000000ff950000, 0x00000000ff950000)
eden space 2752K, 3% used [0x00000000ff600000, 0x00000000ff61b760, 0x00000000ff8b0000)
from space 320K, 0% used [0x00000000ff8b0000, 0x00000000ff8b0000, 0x00000000ff900000)
to space 320K, 0% used [0x00000000ff900000, 0x00000000ff900000, 0x00000000ff950000)
concurrent mark-sweep generation total 6848K, used 5035K [0x00000000ff950000, 0x0000000100000000, 0x0000000100000000)
Metaspace used 2531K, capacity 4486K, committed 4864K, reserved 1056768K
class space used 270K, capacity 386K, committed 512K, reserved 1048576K
[GC (CMS Initial Mark) [1 CMS-initial-mark: 5035K(6848K)] 5144K(9920K), 0.0000747 secs] [Times: user=0.00 sys=0.00, real=0.00 secs]
[CMS-concurrent-mark-start]
[CMS-concurrent-mark: 0.000/0.000 secs] [Times: user=0.00 sys=0.00, real=0.00 secs]
[CMS-concurrent-preclean-start]
[CMS-concurrent-preclean: 0.000/0.000 secs] [Times: user=0.00 sys=0.00, real=0.00 secs]
[GC (CMS Final Remark) [YG occupancy: 109 K (3072 K)][Rescan (parallel) , 0.0005387 secs][weak refs processing, 0.0000026 secs][class unloading, 0.0000774 secs][scrub symbol table, 0.0002028 secs][scrub string table, 0.0000510 secs][1 CMS-remark: 5035K(6848K)] 5144K(9920K), 0.0009313 secs] [Times: user=0.00 sys=0.00, real=0.00 secs]
[CMS-concurrent-sweep-start]
[CMS-concurrent-sweep: 0.000/0.000 secs] [Times: user=0.00 sys=0.00, real=0.00 secs]
[CMS-concurrent-reset-start]
[CMS-concurrent-reset: 0.000/0.000 secs] [Times: user=0.00 sys=0.00, real=0.00 secs]