Java 8u92から増えた -XX:+CrashOnOutOfMemoryErrorと-XX:+ExitOnOutOfMemoryErrorを試してみた

※91だと思ってたら増えたのは92からでした。
試したのはWindowsで。OOM発生時にJVMを確実に落とすオプションらしい。

-XX:+CrashOnOutOfMemoryError

>java -XX:+CrashOnOutOfMemoryError Main
Aborting due to java.lang.OutOfMemoryError: Java heap space
#
# A fatal error has been detected by the Java Runtime Environment:
#
#  Internal Error (debug.cpp:308), pid=6760, tid=0x00000000000026a4
#  fatal error: OutOfMemory encountered: Java heap space
#
# JRE version: Java(TM) SE Runtime Environment (8.0_92-b14) (build 1.8.0_92-b14)

# Java VM: Java HotSpot(TM) 64-Bit Server VM (25.92-b14 mixed mode windows-amd64
 compressed oops)
# Failed to write core dump. Minidumps are not enabled by default on client vers
ions of Windows
#
# An error report file with more information is saved as:
# *\hs_err_pid6760.log
#
# If you would like to submit a bug report, please visit:
#   http://bugreport.java.com/bugreport/crash.jsp
#

hs_err_*.logファイルが出力される。

#
# A fatal error has been detected by the Java Runtime Environment:
#
#  Internal Error (debug.cpp:308), pid=6760, tid=0x00000000000026a4
#  fatal error: OutOfMemory encountered: Java heap space
#
# JRE version: Java(TM) SE Runtime Environment (8.0_92-b14) (build 1.8.0_92-b14)
# Java VM: Java HotSpot(TM) 64-Bit Server VM (25.92-b14 mixed mode windows-amd64 compressed oops)
# Failed to write core dump. Minidumps are not enabled by default on client versions of Windows
#
# If you would like to submit a bug report, please visit:
#   http://bugreport.java.com/bugreport/crash.jsp
#

---------------  T H R E A D  ---------------

Current thread (0x000000000249e000):  JavaThread "main" [_thread_in_vm, id=9892, stack(0x0000000002590000,0x0000000002690000)]

Stack: [0x0000000002590000,0x0000000002690000]
[error occurred during error reporting (printing stack bounds), id 0xc0000005]

Native frames: (J=compiled Java code, j=interpreted, Vv=VM code, C=native code)

Java frames: (J=compiled Java code, j=interpreted, Vv=VM code)
j  java.util.Arrays.copyOf([CI)[C+1
j  java.lang.AbstractStringBuilder.expandCapacity(I)V+43
J 29 C1 java.lang.AbstractStringBuilder.append(Ljava/lang/String;)Ljava/lang/AbstractStringBuilder; (50 bytes) @ 0x00000000027a2a84 [0x00000000027a27e0+0x2a4]
J 30 C1 java.lang.StringBuilder.append(Ljava/lang/String;)Ljava/lang/StringBuilder; (8 bytes) @ 0x00000000027a1cc4 [0x00000000027a1c40+0x84]
j  Main.main([Ljava/lang/String;)V+23
v  ~StubRoutines::call_stub

---------------  P R O C E S S  ---------------

Java Threads: ( => current thread )
  0x0000000018a4a000 JavaThread "Service Thread" daemon [_thread_blocked, id=9992, stack(0x0000000019580000,0x0000000019680000)]
  0x00000000174bf800 JavaThread "C1 CompilerThread2" daemon [_thread_blocked, id=4724, stack(0x0000000019350000,0x0000000019450000)]
  0x00000000174ba000 JavaThread "C2 CompilerThread1" daemon [_thread_blocked, id=8940, stack(0x0000000019130000,0x0000000019230000)]
  0x00000000189c2000 JavaThread "C2 CompilerThread0" daemon [_thread_blocked, id=7940, stack(0x0000000018f80000,0x0000000019080000)]
  0x00000000189c1000 JavaThread "Attach Listener" daemon [_thread_blocked, id=10216, stack(0x0000000018e80000,0x0000000018f80000)]
  0x00000000189be000 JavaThread "Signal Dispatcher" daemon [_thread_blocked, id=8304, stack(0x0000000018590000,0x0000000018690000)]
  0x000000001749a800 JavaThread "Finalizer" daemon [_thread_blocked, id=3408, stack(0x00000000188b0000,0x00000000189b0000)]
  0x0000000017453000 JavaThread "Reference Handler" daemon [_thread_blocked, id=5716, stack(0x00000000186e0000,0x00000000187e0000)]
=>0x000000000249e000 JavaThread "main" [_thread_in_vm, id=9892, stack(0x0000000002590000,0x0000000002690000)]

Other Threads:
  0x000000001744b800 VMThread [stack: 0x0000000018460000,0x0000000018560000] [id=8624]
  0x0000000018a62800 WatcherThread [stack: 0x0000000019780000,0x0000000019880000] [id=10172]

VM state:not at safepoint (normal execution)

VM Mutex/Monitor currently owned by a thread: None

Heap:
 PSYoungGen      total 669696K, used 0K [0x00000000d5a00000, 0x00000000fff80000, 0x0000000100000000)
  eden space 669184K, 0% used [0x00000000d5a00000,0x00000000d5a00000,0x00000000fe780000)
  from space 512K, 0% used [0x00000000fff00000,0x00000000fff00000,0x00000000fff80000)
  to   space 1024K, 0% used [0x00000000ffd80000,0x00000000ffd80000,0x00000000ffe80000)
 ParOldGen       total 1388544K, used 786891K [0x0000000080e00000, 0x00000000d5a00000, 0x00000000d5a00000)
  object space 1388544K, 56% used [0x0000000080e00000,0x00000000b0e72f00,0x00000000d5a00000)
 Metaspace       used 2570K, capacity 4486K, committed 4864K, reserved 1056768K
  class space    used 286K, capacity 386K, committed 512K, reserved 1048576K

Card table byte_map: [0x0000000011a50000,0x0000000011e50000] byte_map_base: 0x0000000011649000

Marking Bits: (ParMarkBitMap*) 0x0000000051a964f0
 Begin Bits: [0x0000000012730000, 0x00000000146f8000)
 End Bits:   [0x00000000146f8000, 0x00000000166c0000)

Polling page: 0x0000000000430000

CodeCache: size=245760Kb used=1105Kb max_used=1107Kb free=244654Kb
 bounds [0x0000000002690000, 0x0000000002900000, 0x0000000011690000]
 total_blobs=264 nmethods=30 adapters=148
 compilation: enabled

Compilation events (10 events):
Event: 0.218 Thread 0x00000000174bf800   26  s    3       java.lang.StringBuffer::append (13 bytes)
Event: 0.219 Thread 0x00000000174bf800 nmethod 26 0x00000000027a3ad0 code [0x00000000027a3c60, 0x00000000027a4148]
Event: 0.219 Thread 0x00000000174bf800   27       3       java.lang.String::getChars (62 bytes)
Event: 0.219 Thread 0x00000000174bf800 nmethod 27 0x00000000027a32d0 code [0x00000000027a3480, 0x00000000027a38b8]
Event: 0.220 Thread 0x00000000174bf800   28       3       java.lang.String::indexOf (7 bytes)
Event: 0.220 Thread 0x00000000174bf800 nmethod 28 0x00000000027a2ed0 code [0x00000000027a3040, 0x00000000027a3248]
Event: 0.220 Thread 0x00000000174bf800   29       3       java.lang.AbstractStringBuilder::append (50 bytes)
Event: 0.220 Thread 0x00000000174bf800 nmethod 29 0x00000000027a2650 code [0x00000000027a27e0, 0x00000000027a2ce8]
Event: 0.226 Thread 0x00000000174bf800   30       3       java.lang.StringBuilder::append (8 bytes)
Event: 0.226 Thread 0x00000000174bf800 nmethod 30 0x00000000027a1ad0 code [0x00000000027a1c40, 0x00000000027a1dc8]

GC Heap History (10 events):
Event: 1.552 GC heap before
{Heap before GC invocations=10 (full 2):
 PSYoungGen      total 266752K, used 0K [0x00000000d5a00000, 0x00000000f1c80000, 0x0000000100000000)
  eden space 265728K, 0% used [0x00000000d5a00000,0x00000000d5a00000,0x00000000e5d80000)
  from space 1024K, 0% used [0x00000000e5d80000,0x00000000e5d80000,0x00000000e5e80000)
  to   space 1024K, 0% used [0x00000000f1b80000,0x00000000f1b80000,0x00000000f1c80000)
 ParOldGen       total 1388544K, used 786903K [0x0000000080e00000, 0x00000000d5a00000, 0x00000000d5a00000)
  object space 1388544K, 56% used [0x0000000080e00000,0x00000000b0e75eb0,0x00000000d5a00000)
 Metaspace       used 2570K, capacity 4486K, committed 4864K, reserved 1056768K
  class space    used 286K, capacity 386K, committed 512K, reserved 1048576K
Event: 1.558 GC heap after
Heap after GC invocations=10 (full 2):
 PSYoungGen      total 460288K, used 0K [0x00000000d5a00000, 0x00000000f3000000, 0x0000000100000000)
  eden space 459264K, 0% used [0x00000000d5a00000,0x00000000d5a00000,0x00000000f1a80000)
  from space 1024K, 0% used [0x00000000f1b80000,0x00000000f1b80000,0x00000000f1c80000)
  to   space 1024K, 0% used [0x00000000f1a80000,0x00000000f1a80000,0x00000000f1b80000)
 ParOldGen       total 1388544K, used 786903K [0x0000000080e00000, 0x00000000d5a00000, 0x00000000d5a00000)
  object space 1388544K, 56% used [0x0000000080e00000,0x00000000b0e75eb0,0x00000000d5a00000)
 Metaspace       used 2570K, capacity 4486K, committed 4864K, reserved 1056768K
  class space    used 286K, capacity 386K, committed 512K, reserved 1048576K
}
Event: 1.558 GC heap before
{Heap before GC invocations=11 (full 2):
 PSYoungGen      total 460288K, used 0K [0x00000000d5a00000, 0x00000000f3000000, 0x0000000100000000)
  eden space 459264K, 0% used [0x00000000d5a00000,0x00000000d5a00000,0x00000000f1a80000)
  from space 1024K, 0% used [0x00000000f1b80000,0x00000000f1b80000,0x00000000f1c80000)
  to   space 1024K, 0% used [0x00000000f1a80000,0x00000000f1a80000,0x00000000f1b80000)
 ParOldGen       total 1388544K, used 786903K [0x0000000080e00000, 0x00000000d5a00000, 0x00000000d5a00000)
  object space 1388544K, 56% used [0x0000000080e00000,0x00000000b0e75eb0,0x00000000d5a00000)
 Metaspace       used 2570K, capacity 4486K, committed 4864K, reserved 1056768K
  class space    used 286K, capacity 386K, committed 512K, reserved 1048576K
Event: 1.564 GC heap after
Heap after GC invocations=11 (full 2):
 PSYoungGen      total 460288K, used 0K [0x00000000d5a00000, 0x0000000100000000, 0x0000000100000000)
  eden space 459264K, 0% used [0x00000000d5a00000,0x00000000d5a00000,0x00000000f1a80000)
  from space 1024K, 0% used [0x00000000f1a80000,0x00000000f1a80000,0x00000000f1b80000)
  to   space 1024K, 0% used [0x00000000fff00000,0x00000000fff00000,0x0000000100000000)
 ParOldGen       total 1388544K, used 786903K [0x0000000080e00000, 0x00000000d5a00000, 0x00000000d5a00000)
  object space 1388544K, 56% used [0x0000000080e00000,0x00000000b0e75eb0,0x00000000d5a00000)
 Metaspace       used 2570K, capacity 4486K, committed 4864K, reserved 1056768K
  class space    used 286K, capacity 386K, committed 512K, reserved 1048576K
}
Event: 1.564 GC heap before
{Heap before GC invocations=12 (full 3):
 PSYoungGen      total 460288K, used 0K [0x00000000d5a00000, 0x0000000100000000, 0x0000000100000000)
  eden space 459264K, 0% used [0x00000000d5a00000,0x00000000d5a00000,0x00000000f1a80000)
  from space 1024K, 0% used [0x00000000f1a80000,0x00000000f1a80000,0x00000000f1b80000)
  to   space 1024K, 0% used [0x00000000fff00000,0x00000000fff00000,0x0000000100000000)
 ParOldGen       total 1388544K, used 786903K [0x0000000080e00000, 0x00000000d5a00000, 0x00000000d5a00000)
  object space 1388544K, 56% used [0x0000000080e00000,0x00000000b0e75eb0,0x00000000d5a00000)
 Metaspace       used 2570K, capacity 4486K, committed 4864K, reserved 1056768K
  class space    used 286K, capacity 386K, committed 512K, reserved 1048576K
Event: 1.618 GC heap after
Heap after GC invocations=12 (full 3):
 PSYoungGen      total 460288K, used 0K [0x00000000d5a00000, 0x0000000100000000, 0x0000000100000000)
  eden space 459264K, 0% used [0x00000000d5a00000,0x00000000d5a00000,0x00000000f1a80000)
  from space 1024K, 0% used [0x00000000f1a80000,0x00000000f1a80000,0x00000000f1b80000)
  to   space 1024K, 0% used [0x00000000fff00000,0x00000000fff00000,0x0000000100000000)
 ParOldGen       total 914432K, used 786903K [0x0000000080e00000, 0x00000000b8b00000, 0x00000000d5a00000)
  object space 914432K, 86% used [0x0000000080e00000,0x00000000b0e75e80,0x00000000b8b00000)
 Metaspace       used 2570K, capacity 4486K, committed 4864K, reserved 1056768K
  class space    used 286K, capacity 386K, committed 512K, reserved 1048576K
}
Event: 1.618 GC heap before
{Heap before GC invocations=13 (full 3):
 PSYoungGen      total 460288K, used 0K [0x00000000d5a00000, 0x0000000100000000, 0x0000000100000000)
  eden space 459264K, 0% used [0x00000000d5a00000,0x00000000d5a00000,0x00000000f1a80000)
  from space 1024K, 0% used [0x00000000f1a80000,0x00000000f1a80000,0x00000000f1b80000)
  to   space 1024K, 0% used [0x00000000fff00000,0x00000000fff00000,0x0000000100000000)
 ParOldGen       total 1388544K, used 786903K [0x0000000080e00000, 0x00000000d5a00000, 0x00000000d5a00000)
  object space 1388544K, 56% used [0x0000000080e00000,0x00000000b0e75e80,0x00000000d5a00000)
 Metaspace       used 2570K, capacity 4486K, committed 4864K, reserved 1056768K
  class space    used 286K, capacity 386K, committed 512K, reserved 1048576K
Event: 1.621 GC heap after
Heap after GC invocations=13 (full 3):
 PSYoungGen      total 669696K, used 0K [0x00000000d5a00000, 0x00000000fff80000, 0x0000000100000000)
  eden space 669184K, 0% used [0x00000000d5a00000,0x00000000d5a00000,0x00000000fe780000)
  from space 512K, 0% used [0x00000000fff00000,0x00000000fff00000,0x00000000fff80000)
  to   space 1024K, 0% used [0x00000000ffd80000,0x00000000ffd80000,0x00000000ffe80000)
 ParOldGen       total 1388544K, used 786903K [0x0000000080e00000, 0x00000000d5a00000, 0x00000000d5a00000)
  object space 1388544K, 56% used [0x0000000080e00000,0x00000000b0e75e80,0x00000000d5a00000)
 Metaspace       used 2570K, capacity 4486K, committed 4864K, reserved 1056768K
  class space    used 286K, capacity 386K, committed 512K, reserved 1048576K
}
Event: 1.621 GC heap before
{Heap before GC invocations=14 (full 4):
 PSYoungGen      total 669696K, used 0K [0x00000000d5a00000, 0x00000000fff80000, 0x0000000100000000)
  eden space 669184K, 0% used [0x00000000d5a00000,0x00000000d5a00000,0x00000000fe780000)
  from space 512K, 0% used [0x00000000fff00000,0x00000000fff00000,0x00000000fff80000)
  to   space 1024K, 0% used [0x00000000ffd80000,0x00000000ffd80000,0x00000000ffe80000)
 ParOldGen       total 1388544K, used 786903K [0x0000000080e00000, 0x00000000d5a00000, 0x00000000d5a00000)
  object space 1388544K, 56% used [0x0000000080e00000,0x00000000b0e75e80,0x00000000d5a00000)
 Metaspace       used 2570K, capacity 4486K, committed 4864K, reserved 1056768K
  class space    used 286K, capacity 386K, committed 512K, reserved 1048576K
Event: 1.756 GC heap after
Heap after GC invocations=14 (full 4):
 PSYoungGen      total 669696K, used 0K [0x00000000d5a00000, 0x00000000fff80000, 0x0000000100000000)
  eden space 669184K, 0% used [0x00000000d5a00000,0x00000000d5a00000,0x00000000fe780000)
  from space 512K, 0% used [0x00000000fff00000,0x00000000fff00000,0x00000000fff80000)
  to   space 1024K, 0% used [0x00000000ffd80000,0x00000000ffd80000,0x00000000ffe80000)
 ParOldGen       total 932352K, used 786891K [0x0000000080e00000, 0x00000000b9c80000, 0x00000000d5a00000)
  object space 932352K, 84% used [0x0000000080e00000,0x00000000b0e72f00,0x00000000b9c80000)
 Metaspace       used 2570K, capacity 4486K, committed 4864K, reserved 1056768K
  class space    used 286K, capacity 386K, committed 512K, reserved 1048576K
}

Deoptimization events (0 events):
No events

Internal exceptions (2 events):
Event: 0.098 Thread 0x000000000249e000 Exception <a 'java/lang/NoSuchMethodError': Method sun.misc.Unsafe.defineClass(Ljava/lang/String;[BII)Ljava/lang/Class; name or signature does not match> (0x00000000d5a07cc0) thrown at [D:\re\workspace\8-2-build-windows-amd64-cygwin\jdk8u92\6642\hotspot\sr&#56569;)コ
Event: 0.098 Thread 0x000000000249e000 Exception <a 'java/lang/NoSuchMethodError': Method sun.misc.Unsafe.prefetchRead(Ljava/lang/Object;J)V name or signature does not match> (0x00000000d5a07fa8) thrown at [D:\re\workspace\8-2-build-windows-amd64-cygwin\jdk8u92\6642\hotspot\src\share\vm\prims\j

Events (10 events):
Event: 0.252 Executing VM operation: ParallelGCFailedAllocation
Event: 0.257 Executing VM operation: ParallelGCFailedAllocation done
Event: 0.284 Executing VM operation: ParallelGCFailedAllocation
Event: 0.303 Executing VM operation: ParallelGCFailedAllocation done
Event: 0.885 Executing VM operation: ParallelGCFailedAllocation
Event: 0.999 Executing VM operation: ParallelGCFailedAllocation done
Event: 1.305 Executing VM operation: ParallelGCFailedAllocation
Event: 1.414 Executing VM operation: ParallelGCFailedAllocation done
Event: 1.552 Executing VM operation: ParallelGCFailedAllocation
Event: 1.757 Executing VM operation: ParallelGCFailedAllocation done


Dynamic libraries:
0x000000013fb10000 - 0x000000013fb47000 	C:\ProgramData\Oracle\Java\javapath\java.exe
0x0000000077590000 - 0x000000007773a000 	C:\Windows\SYSTEM32\ntdll.dll
0x0000000077370000 - 0x000000007748f000 	C:\Windows\system32\kernel32.dll
0x000007fefd360000 - 0x000007fefd3ca000 	C:\Windows\system32\KERNELBASE.dll
0x000007fefe220000 - 0x000007fefe2fb000 	C:\Windows\system32\ADVAPI32.dll
0x000007fefd7a0000 - 0x000007fefd83f000 	C:\Windows\system32\msvcrt.dll
0x000007fefd840000 - 0x000007fefd85f000 	C:\Windows\SYSTEM32\sechost.dll
0x000007fefdf50000 - 0x000007fefe07d000 	C:\Windows\system32\RPCRT4.dll
0x0000000077490000 - 0x000000007758a000 	C:\Windows\system32\USER32.dll
0x000007fefe080000 - 0x000007fefe0e7000 	C:\Windows\system32\GDI32.dll
0x000007fefdac0000 - 0x000007fefdace000 	C:\Windows\system32\LPK.dll
0x000007fefd6d0000 - 0x000007fefd79a000 	C:\Windows\system32\USP10.dll
0x000007fefbf00000 - 0x000007fefc0f4000 	C:\Windows\WinSxS\amd64_microsoft.windows.common-controls_6595b64144ccf1df_6.0.7601.18837_none_fa3b1e3d17594757\COMCTL32.dll
0x000007feff330000 - 0x000007feff3a1000 	C:\Windows\system32\SHLWAPI.dll
0x000007fefe0f0000 - 0x000007fefe11e000 	C:\Windows\system32\IMM32.DLL
0x000007fefdda0000 - 0x000007fefdea9000 	C:\Windows\system32\MSCTF.dll
0x000000006aeb0000 - 0x000000006af82000 	C:\Program Files\Java\jre1.8.0_92\bin\msvcr100.dll
0x0000000051280000 - 0x0000000051b16000 	C:\Program Files\Java\jre1.8.0_92\bin\server\jvm.dll
0x000007fef5ac0000 - 0x000007fef5ac9000 	C:\Windows\system32\WSOCK32.dll
0x000007fefda70000 - 0x000007fefdabd000 	C:\Windows\system32\WS2_32.dll
0x000007fefe590000 - 0x000007fefe598000 	C:\Windows\system32\NSI.dll
0x000007fefadf0000 - 0x000007fefae2b000 	C:\Windows\system32\WINMM.dll
0x000007fefc3f0000 - 0x000007fefc3fc000 	C:\Windows\system32\VERSION.dll
0x0000000077760000 - 0x0000000077767000 	C:\Windows\system32\PSAPI.DLL
0x0000000070770000 - 0x000000007077f000 	C:\Program Files\Java\jre1.8.0_92\bin\verify.dll
0x000000006ae80000 - 0x000000006aea9000 	C:\Program Files\Java\jre1.8.0_92\bin\java.dll
0x0000000070740000 - 0x0000000070756000 	C:\Program Files\Java\jre1.8.0_92\bin\zip.dll
0x000007fefe5a0000 - 0x000007feff32a000 	C:\Windows\system32\SHELL32.dll
0x000007fefd860000 - 0x000007fefda63000 	C:\Windows\system32\ole32.dll
0x000007fefd310000 - 0x000007fefd31f000 	C:\Windows\system32\profapi.dll

VM Arguments:
jvm_args: -XX:+CrashOnOutOfMemoryError 
java_command: Main
java_class_path (initial): .
Launcher Type: SUN_STANDARD

Environment Variables:
JAVA_HOME=C:\Program Files\Java\jdk1.8.0_92
PATH=*
USERNAME=*
OS=Windows_NT
PROCESSOR_IDENTIFIER=Intel64 Family 6 Model 69 Stepping 1, GenuineIntel



---------------  S Y S T E M  ---------------

OS: Windows 7 , 64 bit Build 7601 (6.1.7601.23392)

CPU:total 4 (2 cores per cpu, 2 threads per core) family 6 model 69 stepping 1, cmov, cx8, fxsr, mmx, sse, sse2, sse3, ssse3, sse4.1, sse4.2, popcnt, avx, avx2, aes, clmul, erms, lzcnt, ht, tsc, tscinvbit, bmi1, bmi2

Memory: 4k page, physical 8327728k(3156380k free), swap 16653600k(9915304k free)

vm_info: Java HotSpot(TM) 64-Bit Server VM (25.92-b14) for windows-amd64 JRE (1.8.0_92-b14), built on Mar 31 2016 21:03:04 by "java_re" with MS VC++ 10.0 (VS2010)

time: Fri Apr 22 18:26:54 2016
elapsed time: 1 seconds (0d 0h 0m 1s)

-XX:+ExitOnOutOfMemoryError

>java -XX:+ExitOnOutOfMemoryError Main
Terminating due to java.lang.OutOfMemoryError: Java heap space

ファイルは何も出力されない。

まとめ

-XX:+CrashOnOutOfMemoryErrorのほうが出力される情報は多いけど、クラッシュレポートを送ってくれと表示されるのは微妙なので、-XX:+ExitOnOutOfMemoryErrorを使用したほうがよさそう。
その場合、-XX:+HeapDumpOnOutOfMemoryErrorをつけるのを忘れずに。