Java VM crashed with insufficient memory "Native memory allocation (malloc) failed to allocate XXXX bytes for CodeCache: no room for vtable chunks"
Environment
- Java
Issue
Java VM crashed with insufficient memory "Native memory allocation (malloc) failed to allocate XXXX bytes for CodeCache: no room for vtable chunks". Java VM crash report hs_err_pid<PID>.log contained the followings:
#
# There is insufficient memory for the Java Runtime Environment to continue.
# Native memory allocation (malloc) failed to allocate 4104 bytes for CodeCache: no room for vtable chunks
# Possible reasons:
# The system is out of physical RAM or swap space
# In 32 bit mode, the process size limit was hit
# Possible solutions:
# Reduce memory load on the system
# Increase physical memory or swap space
# Check if swap backing store is full
# Use 64 bit Java on a 64 bit OS
# Decrease Java heap size (-Xmx/-Xms)
# Decrease number of Java threads
# Decrease Java thread stack sizes (-Xss)
# Set larger code cache with -XX:ReservedCodeCacheSize=
# This output file may be truncated or incomplete.
#
# Out of Memory Error (vtableStubs.cpp:63), pid=24592, tid=139852319278848
#
# JRE version: 6.0_45-b06
# Java VM: Java HotSpot(TM) 64-Bit Server VM (20.45-b01 mixed mode linux-amd64 compressed oops)
Resolution
A similar issue was reported in the Content from bugs.sun.com is not included.bug#7009641. The fix was included in JDK 8 and back-ported to HotSpot 25 by Content from bugs.sun.com is not included.bug#8025329. HotSpot 25 will come with JDK 7 in future release but it has not yet at this moment.
Until the fix is included in JDK 7, you can try the followings as possible workaround:
- Use the latest version of JDK 7 rather than JDK 6 (because code cache handling was improved in JDK 7 by Content from bugs.sun.com is not included.bug#7025742, which has not been included in JDK 6)
- Increase
-XX:ReservedCodeCacheSize=XXX(Default 48MB) and-XX:CodeCacheMinimumFreeSpace=XXX(Default 500KB) and also set-XX:+UseCodeCacheFlushing
Root Cause
- Java VM attempted to native memory allocation (malloc) for CodeCache but
largest_free_blockin Code Cache was smaller than the size Java VM tried to malloc:
# Native memory allocation (malloc) failed to allocate 4104 bytes for CodeCache: no room for vtable chunks
...(snip)...
Code Cache [0x00007f3264000000, 0x00007f3274000000, 0x00007f3274000000)
total_blobs=63379 nmethods=62106 adapters=606 free_code_cache=1850816 largest_free_block=704
- JDK-7009641 : Don't use CodeCache for allocations if it is already full
<Content from bugs.sun.com is not included.http://bugs.sun.com/view_bug.do?bug_id=7009641> - JDK-7025742 : Can not use CodeCache::unallocated_capacity() with fragmented CodeCache
<Content from bugs.sun.com is not included.http://bugs.sun.com/view_bug.do?bug_id=7025742>
Diagnostic Steps
- Ask for Java VM crash report
hs_err_pid<PID>.logand check the details of the message and Code Cache usage at the time. - Check console log if CodeCache was full at that time. When CodeCache is full, the following log messages will be shown in console log:
Java HotSpot(TM) 64-Bit Server VM warning: CodeCache is full. Compiler has been disabled.
Java HotSpot(TM) 64-Bit Server VM warning: Try increasing the code cache size using -XX:ReservedCodeCacheSize=
This solution is part of Red Hat’s fast-track publication program, providing a huge library of solutions that Red Hat engineers have created while supporting our customers. To give you the knowledge you need the instant it becomes available, these articles may be presented in a raw and unedited form.