OOM
public static void main(String[] args) {
long mix = Runtime.getRuntime().maxMemory();
long total = Runtime.getRuntime().totalMemory();
System.out.println(mix/1024 + "k");
System.out.println(total/1024 + "k");
<pre><code> String msg = "hh";
while (true) {
msg += msg;
}
}
1005056k 1005056k [GC (Allocation Failure) [PSYoungGen: 209265K->33608K(305664K)] 209265K->99152K(1005056K), 0.0272325 secs] [Times: user=0.06 sys=0.03, real=0.03 secs] [GC (Allocation Failure) [PSYoungGen: 235261K->744K(305664K)] 694022K->459504K(1005056K), 0.0023951 secs] [Times: user=0.00 sys=0.00, real=0.00 secs] [GC (Allocation Failure) [PSYoungGen: 744K->744K(305664K)] 459504K->459504K(1005056K), 0.0021226 secs] [Times: user=0.00 sys=0.00, real=0.00 secs] [Full GC (Allocation Failure) [PSYoungGen: 744K->0K(305664K)] [ParOldGen: 458760K->262772K(699392K)] 459504K->262772K(1005056K), [Metaspace: 3295K->3295K(1056768K)], 0.0375228 secs] [Times: user=0.22 sys=0.00, real=0.03 secs] [GC (Allocation Failure) [PSYoungGen: 5242K->32K(305664K)] 530159K->524948K(1005056K), 0.0019024 secs] [Times: user=0.00 sys=0.00, real=0.00 secs] [GC (Allocation Failure) [PSYoungGen: 32K->32K(305664K)] 524948K->524948K(1005056K), 0.0017802 secs] [Times: user=0.11 sys=0.00, real=0.02 secs] [Full GC (Allocation Failure) [PSYoungGen: 32K->0K(305664K)] [ParOldGen: 524916K->393844K(699392K)] 524948K->393844K(1005056K), [Metaspace: 3295K->3295K(1056768K)], 0.0280688 secs] [Times: user=0.11 sys=0.00, real=0.02 secs] [GC (Allocation Failure) [PSYoungGen: 5114K->32K(318464K)] 661103K->656020K(1017856K), 0.0049043 secs] [Times: user=0.09 sys=0.00, real=0.02 secs] [Full GC (Ergonomics) [PSYoungGen: 32K->0K(318464K)] [ParOldGen: 655988K->262772K(699392K)] 656020K->262772K(1017856K), [Metaspace: 3295K->3295K(1056768K)], 0.0322692 secs] [Times: user=0.13 sys=0.02, real=0.03 secs] [GC (Allocation Failure) --[PSYoungGen: 262144K->262144K(318464K)] 524916K->787060K(1017856K), 0.0531920 secs] [Times: user=0.09 sys=0.02, real=0.06 secs] [Full GC (Ergonomics) [PSYoungGen: 262144K->0K(318464K)] [ParOldGen: 524916K->524916K(699392K)] 787060K->524916K(1017856K), [Metaspace: 3295K->3295K(1056768K)], 0.0297987 secs] [Times: user=0.09 sys=0.00, real=0.02 secs] [GC (Allocation Failure) [PSYoungGen: 0K->0K(315904K)] 524916K->524916K(1015296K), 0.0026687 secs] [Times: user=0.06 sys=0.01, real=0.02 secs] [Full GC (Allocation Failure) [PSYoungGen: 0K->0K(315904K)] [ParOldGen: 524916K->524898K(699392K)] 524916K->524898K(1015296K), [Metaspace: 3295K->3295K(1056768K)], 0.0775677 secs] [Times: user=0.17 sys=0.00, real=0.08 secs] Heap PSYoungGen total 315904K, used 16972K [0x00000000eab00000, 0x0000000100000000, 0x0000000100000000) eden space 285184K, 5% used [0x00000000eab00000,0x00000000ebb93078,0x00000000fc180000) from space 30720K, 0% used [0x00000000fc180000,0x00000000fc180000,0x00000000fdf80000) to space 28672K, 0% used [0x00000000fe400000,0x00000000fe400000,0x0000000100000000) ParOldGen total 699392K, used 524898K [0x00000000c0000000, 0x00000000eab00000, 0x00000000eab00000) object space 699392K, 75% used [0x00000000c0000000,0x00000000e0098a10,0x00000000eab00000) Metaspace used 3357K, capacity 4496K, committed 4864K, reserved 1056768K class space used 366K, capacity 388K, committed 512K, reserved 1048576K 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:448) at java.lang.StringBuilder.append(StringBuilder.java:136) at com.company.Main.main(Main.java:13)
PSYoungGen + ParOldGen = 虚拟机内存
Metaspace 的物理空间并不在堆中
评论区