SlideShare uma empresa Scribd logo
1 de 73
Baixar para ler offline
1
Get Rid Of OutOfMemoryError
Messages
Poonam Parhar
Consulting Member of Technical Staff
Java Platform Group, Oracle
Copyright Š 2019 Oracle and/or its affiliates.
The following is intended to outline our general product direction. It is intended for information purposes
only, and may not be incorporated into any contract. It is not a commitment to deliver any material, code,
or functionality, and should not be relied upon in making purchasing decisions. The development,
release, timing, and pricing of any features or functionality described for Oracle’s products may change
and remains at the sole discretion of Oracle Corporation.
Statements in this presentation relating to Oracle’s future plans, expectations, beliefs, intentions and
prospects are “forward-looking statements” and are subject to material risks and uncertainties. A detailed
discussion of these factors and other risks that affect our business is contained in Oracle’s Securities and
Exchange Commission (SEC) filings, including our most recent reports on Form 10-K and Form 10-Q
under the heading “Risk Factors.” These filings are available on the SEC’s website or on Oracle’s website
at http://www.oracle.com/investor. All information in this presentation is current as of September 2019
and Oracle undertakes no duty to update any statement in light of new information or future events.
Safe Harbor
Copyright Š 2019 Oracle and/or its affiliates.
About me
• Poonam Parhar
• JVM Sustaining Engineer at Oracle
• Co-author of the book ‘Java Performance Companion’
• JavaOne RockStar
• Speaker at Java Conferences
• Blog: https://blogs.oracle.com/poonam/
• Published articles
Copyright Š 2019 Oracle and/or its affiliates.
OutOfMemoryError
Exception	in	thread	"main"	java.lang.OutOfMemoryError:	Java	heap	space
at	java.util.Arrays.copyOfRange(Unknown	Source)
at	java.lang.String.<init>(Unknown	Source)
at	java.io.BufferedReader.readLine(Unknown	Source)
at	java.io.BufferedReader.readLine(Unknown	Source)
at	com.abc.ABCParser.dump(ABCParser.java:23)
at	com.abc.ABCParser.mainABCParser.java:59)
Copyright Š 2019 Oracle and/or its affiliates.
• Misconfiguration of	Memory	Pools
• Excessive	use	of	Finalizers
• Explicit	GC	Invocations
• Memory	Leak
• Long	GC	Pauses
• Excessive	GCs
• Application	Failure	with	OutOfMemoryError
• Unexpected	Memory	Growth	
• Poor	Application	Performance	
Symptoms	of
Caused	by
Copyright Š 2019 Oracle and/or its affiliates.
Agenda
Ø OutOfMemoryError
Ø Java Heap Memory Issues
Ø PermGen/Metaspace Memory Issues
Ø OutOfMemoryError due to Finalization
Ø CodeCache Issues
Ø Native Memory Issues
Copyright Š 2019 Oracle and/or its affiliates.
What is OutOfMemoryError?
• When the JVM runs out of space in various memory spaces
• Thrown when JVM can not proceed further with the process
execution
• Unchecked exception subclassed from
java.lang.VirtualMachineError
java.lang.Throwable
java.lang.Error
java.lang.VirtualMachineError
java.lang.OutOfMemoryError
Copyright Š 2019 Oracle and/or its affiliates.
Different Types of OutOfMemoryErrors
• Java Heap
• PermGen
• Metaspace
• Native Memory
Copyright Š 2019 Oracle and/or its affiliates.
OutOfMemoryError: Java Heap space
• Java objects get allocated in the Java Heap
• This error means that the Java Heap is filled with Java Objects
and the application is requesting to allocate more Java Objects
• The JVM has already invoked Full GC (garbage collection of the
whole Java Heap) but could not free up any space
• It could be that the Java Heap is sized smaller than the
application footprint or the application is unintentionally holding
on to some set of objects in the heap
Copyright Š 2019 Oracle and/or its affiliates.
OutOfMemoryError: PermGen Space
• Classes and classes metadata get stored in the PermGen (prior to
JDK 8)
• This means that the PermGen is full with the loaded classes and
their metadata, and the application is requesting to load more
classes
• The JVM has already invoked Full GC including the cleaning of
PermGen but could not free up any space in the PermGen
• It could be that the PermGen is sized smaller than the footprint of
classes and its metadata, or the application is unintentionally
holding on to some set of classes in the PermGen
Copyright Š 2019 Oracle and/or its affiliates.
OutOfMemoryError: Metaspace
• Classes and classes metadata get stored in the Metaspace
• This error means that the Metaspace is full with the loaded
classes and their metadata, and the application is requesting to
load more classes
• The JVM has already invoked Full GC including the cleaning of
Metaspace but could not free up any space in the Metaspace
• It could be that the Metaspace is sized smaller than the footprint
of classes and its metadata, or the application is unintentionally
holding on to some set of classes in the Metaspace
Copyright Š 2019 Oracle and/or its affiliates.
OutOfMemoryError: Compressed class
space
• If UseCompressedClassPointers is enabled, then two separate areas of
native memory are used for class metadata
• By default UseCompressedClassPointers is ON if UseCompressedOops is ON
• 64-bit class pointers are represented by 32-bit offsets
• 32-bit offsets can be used to reference class-metadata stored in the
‘compressed class space’
• By default, 1GB of address space is reserved for the compressed class
space. This can be configured using CompressedClassSpaceSize.
• MaxMetaspaceSize sets an upper limit on the total committed size of both
of these regions
• committed size of compressed class space +committed size of Metaspace<=
MaxMetaspaceSize
Copyright Š 2019 Oracle and/or its affiliates.
_mark
_klass
<Object	Fields>
_mark
_klass
<Object	Fields>
Klass
Klass
Other	
metadata
Other	
metadata
Copyright Š 2019 Oracle and/or its affiliates.
_mark
_klass
<Object	Fields>
_mark
_klass
<Object	Fields>
Klass
Klass
Other	
metadata
Other	
metadata
+UseCompressedClassPointers
Copyright Š 2019 Oracle and/or its affiliates.
Copyright Š 2019 Oracle and/or its affiliates.
# A fatal error has been detected by the Java Runtime Environment:
#
# java.lang.OutOfMemoryError: requested 32756 bytes for ChunkPool::allocate. Out of
swap space?
#
# Internal Error (allocation.cpp:166), pid=2290, tid=27
# Error: ChunkPool::allocate
OutOfMemoryError for Native Memory
# A fatal error has been detected by the Java Runtime Environment:
#
# java.lang.OutOfMemoryError : unable to create new native Thread
What is in Native Memory?
• Java Thread Stacks
• CodeCache used to keep generated compiled code
• Loaded jar and zip files
• Loaded native libraries
• Native resources e.g. files
• Memory allocated from the native code e.g. JNI
Copyright Š 2019 Oracle and/or its affiliates.
Native OutOfMemoryError
• JVM is not able to allocate from native memory
• Not managed by the JVM
• This process or other processes on the system are eating up
native memory
• Can make more room for native allocations by:
• Reducing the Java Heap, PermGen/Metaspace, number of threads
and/or their stack sizes etc.
• Reducing the number of processes running on the system
• If the above don’t help, we might be facing a native memory
leak
• Example: JNI code allocating native buffers
Copyright Š 2019 Oracle and/or its affiliates.
18
Java Heap Memory Issues
Copyright Š 2019 Oracle and/or its affiliates.
Confirm Memory Leak
• Monitor Java Heap usage over time
• If the Full GCs are not able to claim any space in the Old Gen of
the heap then it could be a configuration issue
• Heap might be sized too small
• Increase the heap size and test the application again
• If there is continuous memory growth and the failure persists at
the increased heap size too, there could be a memory leak
Copyright Š 2019 Oracle and/or its affiliates.
Appropriate Heap Size
-Xmx
Copyright Š 2019 Oracle and/or its affiliates.
21
Java Heap: Diagnostic Data
Copyright Š 2019 Oracle and/or its affiliates.
Java Heap: Diagnostic Data
• GC Logs
• Heap Dumps
• Heap Histograms
• JFR: Old Object Sample Event
Copyright Š 2019 Oracle and/or its affiliates.
GC Logs
• Very helpful in determining the heap requirements
• Excessive GCs
• Long GC pauses
Copyright Š 2019 Oracle and/or its affiliates.
GC Logging Options
• Java 9:
• G1: -Xlog:gc*,gc+phases=debug:file=gc.log
• Non-G1: -Xlog:gc*:file=gc.log
• Prior Java Versions
• -XX:+PrintGCDetails
• -XX:+PrintGCTimeStamps
• -XX:+PrintGCDateStamps
• -Xloggc:<gc log file>
Copyright Š 2019 Oracle and/or its affiliates.
GC Logs: Heap Usage
2017-03-21T13:21:39.595+0000: 289634.716: [Full GC [PSYoungGen: 182784K-
>182660K(364544K)] [ParOldGen: 1091964K->1091964K(1092096K)] 1274748K-
>1274625K(1456640K) [PSPermGen: 493573K->493573K(494080K)], 1.2891230 secs]
[Times: user=6.01 sys=0.00, real=1.29 secs]
Copyright Š 2019 Oracle and/or its affiliates.
GC Logs: Excessive GCs
4.381: [Full GC (Ergonomics) [PSYoungGen: 6656K->6656K(7680K)]
[ParOldGen: 16823K->16823K(17920K)] 23479K->23479K(25600K), [Metaspace: 2724K->2724K(1056768K)], 0.0720605 secs]
[Times: user=0.23 sys=0.00, real=0.07 secs]
4.458: [Full GC (Ergonomics) [PSYoungGen: 6656K->6656K(7680K)]
[ParOldGen: 16824K->16824K(17920K)] 23480K->23480K(25600K), [Metaspace: 2724K->2724K(1056768K)], 0.0518873 secs]
[Times: user=0.16 sys=0.00, real=0.05 secs]
4.515: [Full GC (Ergonomics) [PSYoungGen: 6656K->6656K(7680K)]
[ParOldGen: 16826K->16826K(17920K)] 23482K->23482K(25600K), [Metaspace: 2724K->2724K(1056768K)], 0.0530036 secs]
[Times: user=0.19 sys=0.00, real=0.05 secs]
4.573: [Full GC (Ergonomics) [PSYoungGen: 6656K->6656K(7680K)]
[ParOldGen: 16827K->16827K(17920K)] 23483K->23483K(25600K), [Metaspace: 2725K->2725K(1056768K)], 0.0523322 secs] [Times:
user=0.19 sys=0.00, real=0.05 secs]
4.631: [Full GC (Ergonomics) [PSYoungGen: 6656K->6656K(7680K)]
[ParOldGen: 16828K->16828K(17920K)] 23484K->23484K(25600K), [Metaspace: 2729K->2729K(1056768K)], 0.0522808 secs]
[Times: user=0.17 sys=0.00, real=0.05 secs]
4.688: [Full GC (Ergonomics) [PSYoungGen: 6656K->6656K(7680K)]
[ParOldGen: 16830K->16830K(17920K)] 23486K->23486K(25600K), [Metaspace: 2729K->2729K(1056768K)], 0.0522224 secs]
[Times: user=0.19 sys=0.00, real=0.05 secs]
4.746: [Full GC (Ergonomics) [PSYoungGen: 6656K->6656K(7680K)]
[ParOldGen: 16831K->16831K(17920K)] 23487K->23487K(25600K), [Metaspace: 2729K->2729K(1056768K)], 0.0528773 secs] [Times:
user=0.19 sys=0.00, real=0.05 secs]
Copyright Š 2019 Oracle and/or its affiliates.
Heap Dumps
• Most important diagnostic data for troubleshooting memory
issues
• Can be collected using:
• jcmd <pid/main class> GC.heap_dump heapdump.dmp
• jmap -dump:format=b,file=snapshot.jmap <pid>
• JConsole utility, using Mbean HotSpotDiagnostic
• Java Mission Control, using HotSpotDiagnostic or
DiagnosticCommand Mbeans
• -XX:+HeapDumpOnOutOfMemoryError
Copyright Š 2019 Oracle and/or its affiliates.
Copyright Š 2019 Oracle and/or its affiliates.
Copyright Š 2019 Oracle and/or its affiliates.
Heap Histograms
• Quick glimpse of objects in Java heap
• Can be collected using:
• -XX:+PrintClassHistogram, and SIGQUIT on Posix platforms and
SIGBREAK on Windows
• jcmd <process id/main class> GC.class_histogram
filename=Myheaphistogram
• jmap -histo pid
• jhsdb jmap (in JDK 9)
• Java Mission Control (Diagnostic Commands)
Copyright Š 2019 Oracle and/or its affiliates.
Histogram
Copyright Š 2019 Oracle and/or its affiliates.
32
Java Heap: Analysis of
Diagnostic Data
Copyright Š 2019 Oracle and/or its affiliates.
GC Logs Analysis
Copyright Š 2019 Oracle and/or its affiliates.
GC Logs Analysis
• What do we want to look for:
• Are there too many Full GCs?
• Are there GCs with long pauses?
• Are there GCs happening too frequently?
• Manual inspection
• Automatic Analysis tools
• Examples: GCHisto, GCViewer, gceasy.io etc.
Copyright Š 2019 Oracle and/or its affiliates.
Copyright Š 2019 Oracle and/or its affiliates.
Heap Dump Analysis
Copyright Š 2019 Oracle and/or its affiliates.
Eclipse MAT - Memory Analyzer Tool
• Community developed tool for analyzing heap dumps
• Some of the amazing features that it offers are:
• Leak Suspects
• Histograms
• Unreachable objects
• Duplicate Classes
• Path to GC roots
• OQL
Copyright Š 2019 Oracle and/or its affiliates.
Copyright Š 2019 Oracle and/or its affiliates.
Copyright Š 2019 Oracle and/or its affiliates.
Copyright Š 2019 Oracle and/or its affiliates.
JFR: Old Object Sample Event
Copyright Š 2019 Oracle and/or its affiliates.
JFR: Old Object Sample Event
• Old Object Sample Event (Memory Leak Profiler)
• Added in JDK 10
• Sampled allocations tracked in a fixed size priority queue
• Enable dumping of paths to GC roots
• -XX:StartFlightRecording=path-to-gc-roots=true
• jcmd <pid> JFR.dump path-to-gc-roots=true
• Template file to configure cutoff:
<event name="jdk.OldObjectSample">
<setting name="enabled" control="memory-leak-detection-enabled">true</setting>
<setting name="stackTrace" control="memory-leak-detection-stack-trace">true</setting>
<setting name="cutoff" control="memory-leak-detection-cutoff">0 ns</setting>
</event>
• Marcus’s blog post: http://hirt.se/blog/?p=1055
Copyright Š 2019 Oracle and/or its affiliates.42
Copyright Š 2019 Oracle and/or its affiliates.
44
PermGen/MetaSpace
Memory Issues
Copyright Š 2019 Oracle and/or its affiliates.
Confirm Memory Leak
• Monitor PermGen/Metaspace usage over time
• If the Full GCs are not able to claim any space in the
PermGen/Metaspace then it could be a configuration issue
• PermGen/Metaspace might be sized too small
• Increase the PermGen/Metaspace size and test the application
again
• If there is continuous memory growth and the failure persists at
the increased PermGen/Metaspace size too, there could be a
memory leak
Copyright Š 2019 Oracle and/or its affiliates.
Configure PermGen Size
–XX:PermSize=m –XX:MaxPermSize=n
Copyright Š 2019 Oracle and/or its affiliates.
Configure Metaspace Size
-XX:MetaspaceSize=m -XX:MaxMetaspaceSize=n
Copyright Š 2019 Oracle and/or its affiliates.
PermGen/MetaSpace: Diagnostic Data collection and Analysis
Copyright Š 2019 Oracle and/or its affiliates.
PermGen/MetaSpace: Diagnostic Data
collection and Analysis
• GC logs including options:
• –verbose:class
• -XX:+TraceClassLoading –XX:+TraceClassUnloading
• Data collected with:
• jmap –permstat (up to JDK 7)
• jmap –clstats (JDK 8 onwards)
• Heap Dumps
• JDK 8: class statistics information with ‘jcmd <pid>
GC.class_stats’
Copyright Š 2019 Oracle and/or its affiliates.
Make sure that classes get unloaded
• Ensure –Xnoclassgc is not in use
• Ensure that –XX:+CMSClassUnloadingEnabled is used when
using CMS on Java 6 or 7
Copyright Š 2019 Oracle and/or its affiliates.
[Loading weblogic.i18n.logging.MessageDispatcher from
file:/opt/weblogic1213/wlserver/modules/features/weblogic.server.merged.jar]
[Loaded weblogic.i18n.logging.MessageDispatcher from
file:/opt/weblogic1213/wlserver/modules/features/weblogic.server.merged.jar]
[Loaded weblogic.i18n.logging.CoreEnginePrimordialLoggerWrapper from
file:/opt/weblogic1213/wlserver/modules/features/weblogic.server.merged.jar]
[Loading weblogic.logging.WLMessageLogger from
file:/opt/weblogic1213/wlserver/modules/features/weblogic.server.merged.jar]
…
[Loading sun.reflect.GeneratedMethodAccessor486 from __JVM_DefineClass__]
[Loaded sun.reflect.GeneratedMethodAccessor486 from __JVM_DefineClass__]
[Loading sun.reflect.GeneratedMethodAccessor487 from __JVM_DefineClass__]
[Loaded sun.reflect.GeneratedMethodAccessor487 from __JVM_DefineClass__]
[Loading sun.reflect.GeneratedMethodAccessor488 from __JVM_DefineClass__]
[Loaded sun.reflect.GeneratedMethodAccessor488 from __JVM_DefineClass__]
[Loading sun.reflect.GeneratedMethodAccessor489 from __JVM_DefineClass__]
[Loaded sun.reflect.GeneratedMethodAccessor489 from __JVM_DefineClass__]
…
[Unloading class sun.reflect.GeneratedMethodAccessor489 0x000000010128fc30]
[Unloading class sun.reflect.GeneratedMethodAccessor488 0x000000010128f830]
[Unloading class sun.reflect.GeneratedMethodAccessor487 0x000000010128f430]
[Unloading class sun.reflect.GeneratedMethodAccessor486 0x000000010128f030]
[Unloading class sun.reflect.GeneratedMethodAccessor482 0x000000010128e030]
[Unloading class sun.reflect.GeneratedMethodAccessor481 0x000000010128dc30]
[Unloading class sun.reflect.GeneratedSerializationConstructorAccessor297 0x0000000101274c30]
[Unloading class sun.reflect.GeneratedSerializationConstructorAccessor296 0x0000000101274830]
-verbose:class
Copyright Š 2019 Oracle and/or its affiliates.
74062.764: [Full GC (Last ditch collection) 74062.764: [CMS: 1444990K-
>1444951K(2599396K), 6.0356492 secs] 1444990K->1444951K(3046692K), [Metaspace:
4050878K->4050878K(6356992K)], 6.0366164 secs] [Times: user=6.04 sys=0.01, real=6.04
secs]
74068.804: [GC (CMS Initial Mark) [1 CMS-initial-mark: 1444951K(2599396K)]
1445248K(3046692K), 0.9821073 secs] [Times: user=1.23 sys=0.00, real=0.98 secs]
74069.787: [CMS-concurrent-mark-start]
74069.818: [Full GC (Metadata GC Threshold) 74069.818: [CMS74071.433: [CMS-concurrent-
mark: 1.642/1.647 secs] [Times: user=3.33 sys=0.00, real=1.65 secs] (concurrent mode
failure): 1444951K->1444879K(2599396K), 7.5785637 secs] 1445513K->1444879K(3046692K),
[Metaspace: 4050878K->4050878K(6356992K)], 7.5795618 secs] [Times: user=9.19
sys=0.00, real=7.58 secs]
java.lang.OutOfMemoryError: Compressed class space
GC Logs
Copyright Š 2019 Oracle and/or its affiliates.
jmap -clstats 26240
Attaching to process ID 26240, please wait...
Debugger attached successfully. Server compiler detected. JVM version is 25.66-b00
finding class loader instances ..done. computing per loader stat ..done. please
wait.. computing liveness.liveness analysis may be inaccurate ...
class_loader classes bytes parent_loader alive? type
<bootstrap> 513 950353 null live <internal>
0x0000000084e066d0 8 24416 0x0000000084e06740 live
sun/misc/Launcher$AppClassLoader@0x0000000016bef6a0
0x0000000084e06740 0 0 null live
sun/misc/Launcher$ExtClassLoader@0x0000000016befa48
0x0000000084ea18f0 0 0 0x0000000084e066d0 dead
java/util/ResourceBundle$RBClassLoader@0x0000000016c33930
jmap -clstats
Copyright Š 2019 Oracle and/or its affiliates.
Heap Dumps
• Heap Dumps help here too
• Look for classes that should have been unloaded
• Eclipse MAT offers a very nice feature called ‘Duplicate Classes’
• Displays classes that were loaded multiple times by different
classloader instances
• If duplicate classes keep growing over time/redeployments, it’s a red
flag
Copyright Š 2019 Oracle and/or its affiliates.
Copyright Š 2019 Oracle and/or its affiliates.
56
OutOfMemoryError due to
Finalization
Copyright Š 2019 Oracle and/or its affiliates.
Finalization
• OutOfMemoryError can also be caused due to excessive use of
finalizers
• Objects with a finalizer (i.e. a finalize() method) may delay the
reclamation of the space occupied by them
• Finalizer thread needs to invoke the finalize() method of the
instances before those instances can be reclaimed
• If the Finalizer thread does not keep up with the rate at which the
objects become eligible for finalization, JVM might fail with an
OutOfMemoryError
• Deprecated in Java 9
• https://bugs.openjdk.java.net/browse/JDK-8165641
Copyright Š 2019 Oracle and/or its affiliates.
Finalization: Diagnostic Data and Tools
Copyright Š 2019 Oracle and/or its affiliates.
Finalization: Diagnostic Data and Tools
• JConsole
• jmap -finalizerinfo
• Heap Dumps
Copyright Š 2019 Oracle and/or its affiliates.
Copyright Š 2019 Oracle and/or its affiliates.
61
CodeCache is full. Compiler
has been disabled
Copyright Š 2019 Oracle and/or its affiliates.
CodeCache is full. Compiler has been
disabled
• CodeCache is the memory pool to store the compiled code
generated by the JIT compilers
• There is no specific OutOfMemoryError thrown when CodeCache is
full
• Managed by Sweeper
• An emergency CodeCache cleanup is done when it becomes full
• This may discard the compiled code that might be needed shortly after
• Compiler needs to work again to generate the compiled code for those
methods
• Ensure CodeCache size is sufficient
• Increase CodeCache maximum size with ReservedCodeCacheSize
Copyright Š 2019 Oracle and/or its affiliates.
63
OutOfMemoryError: Native
Memory
Copyright Š 2019 Oracle and/or its affiliates.
# A fatal error has been detected by the Java
Runtime Environment:
#
# java.lang.OutOfMemoryError : unable to create
new native Thread
# A fatal error has been detected by the Java
Runtime Environment:
#
# java.lang.OutOfMemoryError: requested 32756
bytes for ChunkPool::allocate. Out of swap
space?
#
# Internal Error (allocation.cpp:166),
pid=2290, tid=27 # Error: ChunkPool::allocate
Native OutOfMemoryError
Copyright Š 2019 Oracle and/or its affiliates.
Native Memory: Diagnostic Data
Copyright Š 2019 Oracle and/or its affiliates.
Native Memory: Diagnostic Data
• For native memory leaks in the JVM
• Native Memory Tracker output
• For native memory leaks outside the JVM
• Process map output with tools like pmap
• Results from native memory leak tools such as jemalloc, libumem,
valgrind etc.
• Core file
Copyright Š 2019 Oracle and/or its affiliates.
Native Memory Tracker
• The Native Memory Tracker (NMT) can be used to track native
memory that is used internally by the JVM
• It cannot track memory allocated outside the JVM or by native
libraries
Copyright Š 2019 Oracle and/or its affiliates.
NMT
• Start the process with NMT enabled by using –
XX:+NativeMemoryTracking
• The output level can be set to a ‘summary’ or ‘detail’ level:
• -XX:NativeMemoryTracking=summary
• -XX:NativeMemoryTracking=detail
• Use jcmd to get the native memory usage details:
• jcmd <pid> VM.native_memory
Copyright Š 2019 Oracle and/or its affiliates.
jcmd 90172 VM.native_memory 90172:
Native Memory Tracking:
Total: reserved=3431296KB, committed=2132244KB
- Java Heap (reserved=2017280KB, committed=2017280KB)
(mmap: reserved=2017280KB, committed=2017280KB)
- Class (reserved=1062088KB, committed=10184KB)
(classes #411)
(malloc=5320KB #190)
(mmap: reserved=1056768KB, committed=4864KB)
- Thread (reserved=15423KB, committed=15423KB)
(thread #16)
(stack: reserved=15360KB, committed=15360KB)
(malloc=45KB #81)
(arena=18KB #30)
- Code (reserved=249658KB, committed=2594KB)
(malloc=58KB #348)
(mmap: reserved=249600KB, committed=2536KB)
- GC (reserved=79628KB, committed=79544KB)
(malloc=5772KB #118)
(mmap: reserved=73856KB, committed=73772KB)
- Compiler (reserved=138KB, committed=138KB)
(malloc=8KB #41)
(arena=131KB #3)
- Internal (reserved=5380KB, committed=5380KB)
(malloc=5316KB #1357)
(mmap: reserved=64KB, committed=64KB)
- Symbol (reserved=1367KB, committed=1367KB)
(malloc=911KB #112)
(arena=456KB #1)
- Native Memory Tracking (reserved=118KB, committed=118KB)
(malloc=66KB #1040)
(tracking overhead=52KB)
- Arena Chunk (reserved=217KB, committed=217KB)
(malloc=217KB)
Copyright Š 2019 Oracle and/or its affiliates.
Native Memory Leaks Outside JVM
• For native memory leaks stemming from outside the JVM, we
need to rely on the native memory leak tools for their detection
and troubleshooting
• Native Memory Leak Detection Tools
• jemalloc
• dbx
• libumem
• valgrind
• purify
• and so on
Copyright Š 2019 Oracle and/or its affiliates.
Summary
• Various OutOfMemoryErrors
• Causes of memory related problems:
• Misconfiguration of Memory Pools
• Excessive use of Finalizers
• Memory Leaks
• Size memory pools appropriately
• Tools to investigate memory leaks
• HeapDumpOnOutOfMemoryError and PrintClassHistogram JVM Options
• JConsole
• jcmd
• jmap
• GC Logs
• Eclipse MAT
• NMT
• Native Memory Leak Detection Tools such as dbx, libumem, valgrind, purify etc.
Copyright Š 2019 Oracle and/or its affiliates.
References
• Troubleshooting Guide:
• https://docs.oracle.com/en/java/javase/12/troubleshoot/index.html
• Blog:
• https://blogs.oracle.com/poonam/
• Free Online Course: Java Virtual Machine Troubleshooting
• http://www.oracle.com/goto/jvm
• Article: https://www.infoq.com/articles/Troubleshooting-Java-
Memory-Issues
Copyright Š 2019 Oracle and/or its affiliates.
73
Get Rid Of OutOfMemoryError
Messages
Poonam Parhar
Consulting Member of Technical Staff
Java Platform Group, Oracle
Copyright Š 2019 Oracle and/or its affiliates.

Mais conteĂşdo relacionado

Mais procurados

クラスローダーについて
クラスローダーについてクラスローダーについて
クラスローダーについて
Suguru ARAKAWA
 
Dalvik仮想マシンのアーキテクチャ 改訂版
Dalvik仮想マシンのアーキテクチャ 改訂版Dalvik仮想マシンのアーキテクチャ 改訂版
Dalvik仮想マシンのアーキテクチャ 改訂版
Takuya Matsunaga
 
ClassLoader Leak Patterns
ClassLoader Leak PatternsClassLoader Leak Patterns
ClassLoader Leak Patterns
nekop
 
「これからはじめるNGINX技術解説~基本編」セミナー (NGINX Back to Basic in JP)
「これからはじめるNGINX技術解説~基本編」セミナー (NGINX Back to Basic in JP)「これからはじめるNGINX技術解説~基本編」セミナー (NGINX Back to Basic in JP)
「これからはじめるNGINX技術解説~基本編」セミナー (NGINX Back to Basic in JP)
NGINX, Inc.
 
日本語テストメソッドについて
日本語テストメソッドについて日本語テストメソッドについて
日本語テストメソッドについて
kumake
 
LogbackからLog4j 2への移行によるアプリケーションのスループット改善 ( JJUG CCC 2021 Fall )
LogbackからLog4j 2への移行によるアプリケーションのスループット改善 ( JJUG CCC 2021 Fall ) LogbackからLog4j 2への移行によるアプリケーションのスループット改善 ( JJUG CCC 2021 Fall )
LogbackからLog4j 2への移行によるアプリケーションのスループット改善 ( JJUG CCC 2021 Fall )
Hironobu Isoda
 
SPAセキュリティ入門~PHP Conference Japan 2021
SPAセキュリティ入門~PHP Conference Japan 2021SPAセキュリティ入門~PHP Conference Japan 2021
SPAセキュリティ入門~PHP Conference Japan 2021
Hiroshi Tokumaru
 

Mais procurados (20)

クラスローダーについて
クラスローダーについてクラスローダーについて
クラスローダーについて
 
PGroonga – Make PostgreSQL fast full text search platform for all languages!
PGroonga – Make PostgreSQL fast full text search platform for all languages!PGroonga – Make PostgreSQL fast full text search platform for all languages!
PGroonga – Make PostgreSQL fast full text search platform for all languages!
 
Dalvik仮想マシンのアーキテクチャ 改訂版
Dalvik仮想マシンのアーキテクチャ 改訂版Dalvik仮想マシンのアーキテクチャ 改訂版
Dalvik仮想マシンのアーキテクチャ 改訂版
 
20190619 AWS Black Belt Online Seminar Dive Deep into AWS Chalice
20190619 AWS Black Belt Online Seminar Dive Deep into AWS Chalice20190619 AWS Black Belt Online Seminar Dive Deep into AWS Chalice
20190619 AWS Black Belt Online Seminar Dive Deep into AWS Chalice
 
ClassLoader Leak Patterns
ClassLoader Leak PatternsClassLoader Leak Patterns
ClassLoader Leak Patterns
 
OpenJDK トラブルシューティング #javacasual
OpenJDK トラブルシューティング #javacasualOpenJDK トラブルシューティング #javacasual
OpenJDK トラブルシューティング #javacasual
 
[Aurora事例祭り]Amazon Aurora を使いこなすためのベストプラクティス
[Aurora事例祭り]Amazon Aurora を使いこなすためのベストプラクティス[Aurora事例祭り]Amazon Aurora を使いこなすためのベストプラクティス
[Aurora事例祭り]Amazon Aurora を使いこなすためのベストプラクティス
 
CEDEC2021 ダウンロード時間を大幅減!~大量のアセットをさばく高速な実装と運用事例の共有~
CEDEC2021 ダウンロード時間を大幅減!~大量のアセットをさばく高速な実装と運用事例の共有~ CEDEC2021 ダウンロード時間を大幅減!~大量のアセットをさばく高速な実装と運用事例の共有~
CEDEC2021 ダウンロード時間を大幅減!~大量のアセットをさばく高速な実装と運用事例の共有~
 
「これからはじめるNGINX技術解説~基本編」セミナー (NGINX Back to Basic in JP)
「これからはじめるNGINX技術解説~基本編」セミナー (NGINX Back to Basic in JP)「これからはじめるNGINX技術解説~基本編」セミナー (NGINX Back to Basic in JP)
「これからはじめるNGINX技術解説~基本編」セミナー (NGINX Back to Basic in JP)
 
トランザクションスクリプトのすすめ
トランザクションスクリプトのすすめトランザクションスクリプトのすすめ
トランザクションスクリプトのすすめ
 
日本語テストメソッドについて
日本語テストメソッドについて日本語テストメソッドについて
日本語テストメソッドについて
 
Multi Chassis LAG for Cloud builders
Multi Chassis LAG for Cloud buildersMulti Chassis LAG for Cloud builders
Multi Chassis LAG for Cloud builders
 
LogbackからLog4j 2への移行によるアプリケーションのスループット改善 ( JJUG CCC 2021 Fall )
LogbackからLog4j 2への移行によるアプリケーションのスループット改善 ( JJUG CCC 2021 Fall ) LogbackからLog4j 2への移行によるアプリケーションのスループット改善 ( JJUG CCC 2021 Fall )
LogbackからLog4j 2への移行によるアプリケーションのスループット改善 ( JJUG CCC 2021 Fall )
 
Firebaseを利用するためにGCPとCloud IAMの 基本を理解しよう
Firebaseを利用するためにGCPとCloud IAMの 基本を理解しようFirebaseを利用するためにGCPとCloud IAMの 基本を理解しよう
Firebaseを利用するためにGCPとCloud IAMの 基本を理解しよう
 
RFC5996(IKEv2)第2版
RFC5996(IKEv2)第2版RFC5996(IKEv2)第2版
RFC5996(IKEv2)第2版
 
Let's Learn to Talk to GC Logs in Java 9
Let's Learn to Talk to GC Logs in Java 9Let's Learn to Talk to GC Logs in Java 9
Let's Learn to Talk to GC Logs in Java 9
 
AWS Black Belt Online Seminar 2018 Amazon DynamoDB Advanced Design Pattern
AWS Black Belt Online Seminar 2018 Amazon DynamoDB Advanced Design PatternAWS Black Belt Online Seminar 2018 Amazon DynamoDB Advanced Design Pattern
AWS Black Belt Online Seminar 2018 Amazon DynamoDB Advanced Design Pattern
 
Eclipse と Liberty プロファイルで始める Java EE 開発ハンズオン #jjug_ccc #ccc_r51
Eclipse と Liberty プロファイルで始める Java EE 開発ハンズオン #jjug_ccc #ccc_r51Eclipse と Liberty プロファイルで始める Java EE 開発ハンズオン #jjug_ccc #ccc_r51
Eclipse と Liberty プロファイルで始める Java EE 開発ハンズオン #jjug_ccc #ccc_r51
 
Dockerfileを改善するためのBest Practice 2019年版
Dockerfileを改善するためのBest Practice 2019年版Dockerfileを改善するためのBest Practice 2019年版
Dockerfileを改善するためのBest Practice 2019年版
 
SPAセキュリティ入門~PHP Conference Japan 2021
SPAセキュリティ入門~PHP Conference Japan 2021SPAセキュリティ入門~PHP Conference Japan 2021
SPAセキュリティ入門~PHP Conference Japan 2021
 

Semelhante a Get Rid Of OutOfMemoryError messages

Why should i switch to Java SE 7
Why should i switch to Java SE 7Why should i switch to Java SE 7
Why should i switch to Java SE 7
Vinay H G
 

Semelhante a Get Rid Of OutOfMemoryError messages (20)

Tuning Java for Big Data
Tuning Java for Big DataTuning Java for Big Data
Tuning Java for Big Data
 
JVMs in Containers
JVMs in ContainersJVMs in Containers
JVMs in Containers
 
JVMs in Containers - Best Practices
JVMs in Containers - Best PracticesJVMs in Containers - Best Practices
JVMs in Containers - Best Practices
 
20191119 Cloud Native Java : GraalVM
20191119 Cloud Native Java : GraalVM20191119 Cloud Native Java : GraalVM
20191119 Cloud Native Java : GraalVM
 
Hotspot & AOT
Hotspot & AOTHotspot & AOT
Hotspot & AOT
 
Java Performance Tuning
Java Performance TuningJava Performance Tuning
Java Performance Tuning
 
Serverless Java - Challenges and Triumphs
Serverless Java - Challenges and TriumphsServerless Java - Challenges and Triumphs
Serverless Java - Challenges and Triumphs
 
Understanding Memory Management In Spark For Fun And Profit
Understanding Memory Management In Spark For Fun And ProfitUnderstanding Memory Management In Spark For Fun And Profit
Understanding Memory Management In Spark For Fun And Profit
 
Troubleshooting Java HotSpot VM
Troubleshooting Java HotSpot VMTroubleshooting Java HotSpot VM
Troubleshooting Java HotSpot VM
 
Serverless Java Challenges & Triumphs
Serverless Java Challenges & TriumphsServerless Java Challenges & Triumphs
Serverless Java Challenges & Triumphs
 
Java performance tuning
Java performance tuningJava performance tuning
Java performance tuning
 
Troubleshooting Tools In JDK
Troubleshooting Tools In JDKTroubleshooting Tools In JDK
Troubleshooting Tools In JDK
 
JDK 10 Java Module System
JDK 10 Java Module SystemJDK 10 Java Module System
JDK 10 Java Module System
 
Java and Serverless - A Match Made In Heaven, Part 1
Java and Serverless - A Match Made In Heaven, Part 1Java and Serverless - A Match Made In Heaven, Part 1
Java and Serverless - A Match Made In Heaven, Part 1
 
Serverless Java: JJUG CCC 2019
Serverless Java: JJUG CCC 2019Serverless Java: JJUG CCC 2019
Serverless Java: JJUG CCC 2019
 
Introduction to Java
Introduction to Java Introduction to Java
Introduction to Java
 
Building Efficient Pipelines in Apache Spark
Building Efficient Pipelines in Apache SparkBuilding Efficient Pipelines in Apache Spark
Building Efficient Pipelines in Apache Spark
 
Java mission control and java flight recorder
Java mission control and java flight recorderJava mission control and java flight recorder
Java mission control and java flight recorder
 
Why should i switch to Java SE 7
Why should i switch to Java SE 7Why should i switch to Java SE 7
Why should i switch to Java SE 7
 
Fastest Servlets in the West
Fastest Servlets in the WestFastest Servlets in the West
Fastest Servlets in the West
 

Último

Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and Myths
Joaquim Jorge
 
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptxEIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
Earley Information Science
 

Último (20)

Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and Myths
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt Robison
 
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
 
08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men
 
Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed texts
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
 
Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Script
 
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024
 
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUnderstanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
 
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptxEIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘
 
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
 
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
 
Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...
 
Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processors
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024
 
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
 

Get Rid Of OutOfMemoryError messages

  • 1. 1 Get Rid Of OutOfMemoryError Messages Poonam Parhar Consulting Member of Technical Staff Java Platform Group, Oracle Copyright Š 2019 Oracle and/or its affiliates.
  • 2. The following is intended to outline our general product direction. It is intended for information purposes only, and may not be incorporated into any contract. It is not a commitment to deliver any material, code, or functionality, and should not be relied upon in making purchasing decisions. The development, release, timing, and pricing of any features or functionality described for Oracle’s products may change and remains at the sole discretion of Oracle Corporation. Statements in this presentation relating to Oracle’s future plans, expectations, beliefs, intentions and prospects are “forward-looking statements” and are subject to material risks and uncertainties. A detailed discussion of these factors and other risks that affect our business is contained in Oracle’s Securities and Exchange Commission (SEC) filings, including our most recent reports on Form 10-K and Form 10-Q under the heading “Risk Factors.” These filings are available on the SEC’s website or on Oracle’s website at http://www.oracle.com/investor. All information in this presentation is current as of September 2019 and Oracle undertakes no duty to update any statement in light of new information or future events. Safe Harbor Copyright Š 2019 Oracle and/or its affiliates.
  • 3. About me • Poonam Parhar • JVM Sustaining Engineer at Oracle • Co-author of the book ‘Java Performance Companion’ • JavaOne RockStar • Speaker at Java Conferences • Blog: https://blogs.oracle.com/poonam/ • Published articles Copyright Š 2019 Oracle and/or its affiliates.
  • 5. • Misconfiguration of Memory Pools • Excessive use of Finalizers • Explicit GC Invocations • Memory Leak • Long GC Pauses • Excessive GCs • Application Failure with OutOfMemoryError • Unexpected Memory Growth • Poor Application Performance Symptoms of Caused by Copyright Š 2019 Oracle and/or its affiliates.
  • 6. Agenda Ø OutOfMemoryError Ø Java Heap Memory Issues Ø PermGen/Metaspace Memory Issues Ø OutOfMemoryError due to Finalization Ø CodeCache Issues Ø Native Memory Issues Copyright Š 2019 Oracle and/or its affiliates.
  • 7. What is OutOfMemoryError? • When the JVM runs out of space in various memory spaces • Thrown when JVM can not proceed further with the process execution • Unchecked exception subclassed from java.lang.VirtualMachineError java.lang.Throwable java.lang.Error java.lang.VirtualMachineError java.lang.OutOfMemoryError Copyright Š 2019 Oracle and/or its affiliates.
  • 8. Different Types of OutOfMemoryErrors • Java Heap • PermGen • Metaspace • Native Memory Copyright Š 2019 Oracle and/or its affiliates.
  • 9. OutOfMemoryError: Java Heap space • Java objects get allocated in the Java Heap • This error means that the Java Heap is filled with Java Objects and the application is requesting to allocate more Java Objects • The JVM has already invoked Full GC (garbage collection of the whole Java Heap) but could not free up any space • It could be that the Java Heap is sized smaller than the application footprint or the application is unintentionally holding on to some set of objects in the heap Copyright Š 2019 Oracle and/or its affiliates.
  • 10. OutOfMemoryError: PermGen Space • Classes and classes metadata get stored in the PermGen (prior to JDK 8) • This means that the PermGen is full with the loaded classes and their metadata, and the application is requesting to load more classes • The JVM has already invoked Full GC including the cleaning of PermGen but could not free up any space in the PermGen • It could be that the PermGen is sized smaller than the footprint of classes and its metadata, or the application is unintentionally holding on to some set of classes in the PermGen Copyright Š 2019 Oracle and/or its affiliates.
  • 11. OutOfMemoryError: Metaspace • Classes and classes metadata get stored in the Metaspace • This error means that the Metaspace is full with the loaded classes and their metadata, and the application is requesting to load more classes • The JVM has already invoked Full GC including the cleaning of Metaspace but could not free up any space in the Metaspace • It could be that the Metaspace is sized smaller than the footprint of classes and its metadata, or the application is unintentionally holding on to some set of classes in the Metaspace Copyright Š 2019 Oracle and/or its affiliates.
  • 12. OutOfMemoryError: Compressed class space • If UseCompressedClassPointers is enabled, then two separate areas of native memory are used for class metadata • By default UseCompressedClassPointers is ON if UseCompressedOops is ON • 64-bit class pointers are represented by 32-bit offsets • 32-bit offsets can be used to reference class-metadata stored in the ‘compressed class space’ • By default, 1GB of address space is reserved for the compressed class space. This can be configured using CompressedClassSpaceSize. • MaxMetaspaceSize sets an upper limit on the total committed size of both of these regions • committed size of compressed class space +committed size of Metaspace<= MaxMetaspaceSize Copyright Š 2019 Oracle and/or its affiliates.
  • 15. Copyright Š 2019 Oracle and/or its affiliates. # A fatal error has been detected by the Java Runtime Environment: # # java.lang.OutOfMemoryError: requested 32756 bytes for ChunkPool::allocate. Out of swap space? # # Internal Error (allocation.cpp:166), pid=2290, tid=27 # Error: ChunkPool::allocate OutOfMemoryError for Native Memory # A fatal error has been detected by the Java Runtime Environment: # # java.lang.OutOfMemoryError : unable to create new native Thread
  • 16. What is in Native Memory? • Java Thread Stacks • CodeCache used to keep generated compiled code • Loaded jar and zip files • Loaded native libraries • Native resources e.g. files • Memory allocated from the native code e.g. JNI Copyright Š 2019 Oracle and/or its affiliates.
  • 17. Native OutOfMemoryError • JVM is not able to allocate from native memory • Not managed by the JVM • This process or other processes on the system are eating up native memory • Can make more room for native allocations by: • Reducing the Java Heap, PermGen/Metaspace, number of threads and/or their stack sizes etc. • Reducing the number of processes running on the system • If the above don’t help, we might be facing a native memory leak • Example: JNI code allocating native buffers Copyright Š 2019 Oracle and/or its affiliates.
  • 18. 18 Java Heap Memory Issues Copyright Š 2019 Oracle and/or its affiliates.
  • 19. Confirm Memory Leak • Monitor Java Heap usage over time • If the Full GCs are not able to claim any space in the Old Gen of the heap then it could be a configuration issue • Heap might be sized too small • Increase the heap size and test the application again • If there is continuous memory growth and the failure persists at the increased heap size too, there could be a memory leak Copyright Š 2019 Oracle and/or its affiliates.
  • 20. Appropriate Heap Size -Xmx Copyright Š 2019 Oracle and/or its affiliates.
  • 21. 21 Java Heap: Diagnostic Data Copyright Š 2019 Oracle and/or its affiliates.
  • 22. Java Heap: Diagnostic Data • GC Logs • Heap Dumps • Heap Histograms • JFR: Old Object Sample Event Copyright Š 2019 Oracle and/or its affiliates.
  • 23. GC Logs • Very helpful in determining the heap requirements • Excessive GCs • Long GC pauses Copyright Š 2019 Oracle and/or its affiliates.
  • 24. GC Logging Options • Java 9: • G1: -Xlog:gc*,gc+phases=debug:file=gc.log • Non-G1: -Xlog:gc*:file=gc.log • Prior Java Versions • -XX:+PrintGCDetails • -XX:+PrintGCTimeStamps • -XX:+PrintGCDateStamps • -Xloggc:<gc log file> Copyright Š 2019 Oracle and/or its affiliates.
  • 25. GC Logs: Heap Usage 2017-03-21T13:21:39.595+0000: 289634.716: [Full GC [PSYoungGen: 182784K- >182660K(364544K)] [ParOldGen: 1091964K->1091964K(1092096K)] 1274748K- >1274625K(1456640K) [PSPermGen: 493573K->493573K(494080K)], 1.2891230 secs] [Times: user=6.01 sys=0.00, real=1.29 secs] Copyright Š 2019 Oracle and/or its affiliates.
  • 26. GC Logs: Excessive GCs 4.381: [Full GC (Ergonomics) [PSYoungGen: 6656K->6656K(7680K)] [ParOldGen: 16823K->16823K(17920K)] 23479K->23479K(25600K), [Metaspace: 2724K->2724K(1056768K)], 0.0720605 secs] [Times: user=0.23 sys=0.00, real=0.07 secs] 4.458: [Full GC (Ergonomics) [PSYoungGen: 6656K->6656K(7680K)] [ParOldGen: 16824K->16824K(17920K)] 23480K->23480K(25600K), [Metaspace: 2724K->2724K(1056768K)], 0.0518873 secs] [Times: user=0.16 sys=0.00, real=0.05 secs] 4.515: [Full GC (Ergonomics) [PSYoungGen: 6656K->6656K(7680K)] [ParOldGen: 16826K->16826K(17920K)] 23482K->23482K(25600K), [Metaspace: 2724K->2724K(1056768K)], 0.0530036 secs] [Times: user=0.19 sys=0.00, real=0.05 secs] 4.573: [Full GC (Ergonomics) [PSYoungGen: 6656K->6656K(7680K)] [ParOldGen: 16827K->16827K(17920K)] 23483K->23483K(25600K), [Metaspace: 2725K->2725K(1056768K)], 0.0523322 secs] [Times: user=0.19 sys=0.00, real=0.05 secs] 4.631: [Full GC (Ergonomics) [PSYoungGen: 6656K->6656K(7680K)] [ParOldGen: 16828K->16828K(17920K)] 23484K->23484K(25600K), [Metaspace: 2729K->2729K(1056768K)], 0.0522808 secs] [Times: user=0.17 sys=0.00, real=0.05 secs] 4.688: [Full GC (Ergonomics) [PSYoungGen: 6656K->6656K(7680K)] [ParOldGen: 16830K->16830K(17920K)] 23486K->23486K(25600K), [Metaspace: 2729K->2729K(1056768K)], 0.0522224 secs] [Times: user=0.19 sys=0.00, real=0.05 secs] 4.746: [Full GC (Ergonomics) [PSYoungGen: 6656K->6656K(7680K)] [ParOldGen: 16831K->16831K(17920K)] 23487K->23487K(25600K), [Metaspace: 2729K->2729K(1056768K)], 0.0528773 secs] [Times: user=0.19 sys=0.00, real=0.05 secs] Copyright Š 2019 Oracle and/or its affiliates.
  • 27. Heap Dumps • Most important diagnostic data for troubleshooting memory issues • Can be collected using: • jcmd <pid/main class> GC.heap_dump heapdump.dmp • jmap -dump:format=b,file=snapshot.jmap <pid> • JConsole utility, using Mbean HotSpotDiagnostic • Java Mission Control, using HotSpotDiagnostic or DiagnosticCommand Mbeans • -XX:+HeapDumpOnOutOfMemoryError Copyright Š 2019 Oracle and/or its affiliates.
  • 28. Copyright Š 2019 Oracle and/or its affiliates.
  • 29. Copyright Š 2019 Oracle and/or its affiliates.
  • 30. Heap Histograms • Quick glimpse of objects in Java heap • Can be collected using: • -XX:+PrintClassHistogram, and SIGQUIT on Posix platforms and SIGBREAK on Windows • jcmd <process id/main class> GC.class_histogram filename=Myheaphistogram • jmap -histo pid • jhsdb jmap (in JDK 9) • Java Mission Control (Diagnostic Commands) Copyright Š 2019 Oracle and/or its affiliates.
  • 31. Histogram Copyright Š 2019 Oracle and/or its affiliates.
  • 32. 32 Java Heap: Analysis of Diagnostic Data Copyright Š 2019 Oracle and/or its affiliates.
  • 33. GC Logs Analysis Copyright Š 2019 Oracle and/or its affiliates.
  • 34. GC Logs Analysis • What do we want to look for: • Are there too many Full GCs? • Are there GCs with long pauses? • Are there GCs happening too frequently? • Manual inspection • Automatic Analysis tools • Examples: GCHisto, GCViewer, gceasy.io etc. Copyright Š 2019 Oracle and/or its affiliates.
  • 35. Copyright Š 2019 Oracle and/or its affiliates.
  • 36. Heap Dump Analysis Copyright Š 2019 Oracle and/or its affiliates.
  • 37. Eclipse MAT - Memory Analyzer Tool • Community developed tool for analyzing heap dumps • Some of the amazing features that it offers are: • Leak Suspects • Histograms • Unreachable objects • Duplicate Classes • Path to GC roots • OQL Copyright Š 2019 Oracle and/or its affiliates.
  • 38. Copyright Š 2019 Oracle and/or its affiliates.
  • 39. Copyright Š 2019 Oracle and/or its affiliates.
  • 40. Copyright Š 2019 Oracle and/or its affiliates.
  • 41. JFR: Old Object Sample Event Copyright Š 2019 Oracle and/or its affiliates.
  • 42. JFR: Old Object Sample Event • Old Object Sample Event (Memory Leak Profiler) • Added in JDK 10 • Sampled allocations tracked in a fixed size priority queue • Enable dumping of paths to GC roots • -XX:StartFlightRecording=path-to-gc-roots=true • jcmd <pid> JFR.dump path-to-gc-roots=true • Template file to configure cutoff: <event name="jdk.OldObjectSample"> <setting name="enabled" control="memory-leak-detection-enabled">true</setting> <setting name="stackTrace" control="memory-leak-detection-stack-trace">true</setting> <setting name="cutoff" control="memory-leak-detection-cutoff">0 ns</setting> </event> • Marcus’s blog post: http://hirt.se/blog/?p=1055 Copyright Š 2019 Oracle and/or its affiliates.42
  • 43. Copyright Š 2019 Oracle and/or its affiliates.
  • 44. 44 PermGen/MetaSpace Memory Issues Copyright Š 2019 Oracle and/or its affiliates.
  • 45. Confirm Memory Leak • Monitor PermGen/Metaspace usage over time • If the Full GCs are not able to claim any space in the PermGen/Metaspace then it could be a configuration issue • PermGen/Metaspace might be sized too small • Increase the PermGen/Metaspace size and test the application again • If there is continuous memory growth and the failure persists at the increased PermGen/Metaspace size too, there could be a memory leak Copyright Š 2019 Oracle and/or its affiliates.
  • 46. Configure PermGen Size –XX:PermSize=m –XX:MaxPermSize=n Copyright Š 2019 Oracle and/or its affiliates.
  • 47. Configure Metaspace Size -XX:MetaspaceSize=m -XX:MaxMetaspaceSize=n Copyright Š 2019 Oracle and/or its affiliates.
  • 48. PermGen/MetaSpace: Diagnostic Data collection and Analysis Copyright Š 2019 Oracle and/or its affiliates.
  • 49. PermGen/MetaSpace: Diagnostic Data collection and Analysis • GC logs including options: • –verbose:class • -XX:+TraceClassLoading –XX:+TraceClassUnloading • Data collected with: • jmap –permstat (up to JDK 7) • jmap –clstats (JDK 8 onwards) • Heap Dumps • JDK 8: class statistics information with ‘jcmd <pid> GC.class_stats’ Copyright Š 2019 Oracle and/or its affiliates.
  • 50. Make sure that classes get unloaded • Ensure –Xnoclassgc is not in use • Ensure that –XX:+CMSClassUnloadingEnabled is used when using CMS on Java 6 or 7 Copyright Š 2019 Oracle and/or its affiliates.
  • 51. [Loading weblogic.i18n.logging.MessageDispatcher from file:/opt/weblogic1213/wlserver/modules/features/weblogic.server.merged.jar] [Loaded weblogic.i18n.logging.MessageDispatcher from file:/opt/weblogic1213/wlserver/modules/features/weblogic.server.merged.jar] [Loaded weblogic.i18n.logging.CoreEnginePrimordialLoggerWrapper from file:/opt/weblogic1213/wlserver/modules/features/weblogic.server.merged.jar] [Loading weblogic.logging.WLMessageLogger from file:/opt/weblogic1213/wlserver/modules/features/weblogic.server.merged.jar] … [Loading sun.reflect.GeneratedMethodAccessor486 from __JVM_DefineClass__] [Loaded sun.reflect.GeneratedMethodAccessor486 from __JVM_DefineClass__] [Loading sun.reflect.GeneratedMethodAccessor487 from __JVM_DefineClass__] [Loaded sun.reflect.GeneratedMethodAccessor487 from __JVM_DefineClass__] [Loading sun.reflect.GeneratedMethodAccessor488 from __JVM_DefineClass__] [Loaded sun.reflect.GeneratedMethodAccessor488 from __JVM_DefineClass__] [Loading sun.reflect.GeneratedMethodAccessor489 from __JVM_DefineClass__] [Loaded sun.reflect.GeneratedMethodAccessor489 from __JVM_DefineClass__] … [Unloading class sun.reflect.GeneratedMethodAccessor489 0x000000010128fc30] [Unloading class sun.reflect.GeneratedMethodAccessor488 0x000000010128f830] [Unloading class sun.reflect.GeneratedMethodAccessor487 0x000000010128f430] [Unloading class sun.reflect.GeneratedMethodAccessor486 0x000000010128f030] [Unloading class sun.reflect.GeneratedMethodAccessor482 0x000000010128e030] [Unloading class sun.reflect.GeneratedMethodAccessor481 0x000000010128dc30] [Unloading class sun.reflect.GeneratedSerializationConstructorAccessor297 0x0000000101274c30] [Unloading class sun.reflect.GeneratedSerializationConstructorAccessor296 0x0000000101274830] -verbose:class Copyright Š 2019 Oracle and/or its affiliates.
  • 52. 74062.764: [Full GC (Last ditch collection) 74062.764: [CMS: 1444990K- >1444951K(2599396K), 6.0356492 secs] 1444990K->1444951K(3046692K), [Metaspace: 4050878K->4050878K(6356992K)], 6.0366164 secs] [Times: user=6.04 sys=0.01, real=6.04 secs] 74068.804: [GC (CMS Initial Mark) [1 CMS-initial-mark: 1444951K(2599396K)] 1445248K(3046692K), 0.9821073 secs] [Times: user=1.23 sys=0.00, real=0.98 secs] 74069.787: [CMS-concurrent-mark-start] 74069.818: [Full GC (Metadata GC Threshold) 74069.818: [CMS74071.433: [CMS-concurrent- mark: 1.642/1.647 secs] [Times: user=3.33 sys=0.00, real=1.65 secs] (concurrent mode failure): 1444951K->1444879K(2599396K), 7.5785637 secs] 1445513K->1444879K(3046692K), [Metaspace: 4050878K->4050878K(6356992K)], 7.5795618 secs] [Times: user=9.19 sys=0.00, real=7.58 secs] java.lang.OutOfMemoryError: Compressed class space GC Logs Copyright Š 2019 Oracle and/or its affiliates.
  • 53. jmap -clstats 26240 Attaching to process ID 26240, please wait... Debugger attached successfully. Server compiler detected. JVM version is 25.66-b00 finding class loader instances ..done. computing per loader stat ..done. please wait.. computing liveness.liveness analysis may be inaccurate ... class_loader classes bytes parent_loader alive? type <bootstrap> 513 950353 null live <internal> 0x0000000084e066d0 8 24416 0x0000000084e06740 live sun/misc/Launcher$AppClassLoader@0x0000000016bef6a0 0x0000000084e06740 0 0 null live sun/misc/Launcher$ExtClassLoader@0x0000000016befa48 0x0000000084ea18f0 0 0 0x0000000084e066d0 dead java/util/ResourceBundle$RBClassLoader@0x0000000016c33930 jmap -clstats Copyright Š 2019 Oracle and/or its affiliates.
  • 54. Heap Dumps • Heap Dumps help here too • Look for classes that should have been unloaded • Eclipse MAT offers a very nice feature called ‘Duplicate Classes’ • Displays classes that were loaded multiple times by different classloader instances • If duplicate classes keep growing over time/redeployments, it’s a red flag Copyright Š 2019 Oracle and/or its affiliates.
  • 55. Copyright Š 2019 Oracle and/or its affiliates.
  • 56. 56 OutOfMemoryError due to Finalization Copyright Š 2019 Oracle and/or its affiliates.
  • 57. Finalization • OutOfMemoryError can also be caused due to excessive use of finalizers • Objects with a finalizer (i.e. a finalize() method) may delay the reclamation of the space occupied by them • Finalizer thread needs to invoke the finalize() method of the instances before those instances can be reclaimed • If the Finalizer thread does not keep up with the rate at which the objects become eligible for finalization, JVM might fail with an OutOfMemoryError • Deprecated in Java 9 • https://bugs.openjdk.java.net/browse/JDK-8165641 Copyright Š 2019 Oracle and/or its affiliates.
  • 58. Finalization: Diagnostic Data and Tools Copyright Š 2019 Oracle and/or its affiliates.
  • 59. Finalization: Diagnostic Data and Tools • JConsole • jmap -finalizerinfo • Heap Dumps Copyright Š 2019 Oracle and/or its affiliates.
  • 60. Copyright Š 2019 Oracle and/or its affiliates.
  • 61. 61 CodeCache is full. Compiler has been disabled Copyright Š 2019 Oracle and/or its affiliates.
  • 62. CodeCache is full. Compiler has been disabled • CodeCache is the memory pool to store the compiled code generated by the JIT compilers • There is no specific OutOfMemoryError thrown when CodeCache is full • Managed by Sweeper • An emergency CodeCache cleanup is done when it becomes full • This may discard the compiled code that might be needed shortly after • Compiler needs to work again to generate the compiled code for those methods • Ensure CodeCache size is sufficient • Increase CodeCache maximum size with ReservedCodeCacheSize Copyright Š 2019 Oracle and/or its affiliates.
  • 63. 63 OutOfMemoryError: Native Memory Copyright Š 2019 Oracle and/or its affiliates.
  • 64. # A fatal error has been detected by the Java Runtime Environment: # # java.lang.OutOfMemoryError : unable to create new native Thread # A fatal error has been detected by the Java Runtime Environment: # # java.lang.OutOfMemoryError: requested 32756 bytes for ChunkPool::allocate. Out of swap space? # # Internal Error (allocation.cpp:166), pid=2290, tid=27 # Error: ChunkPool::allocate Native OutOfMemoryError Copyright Š 2019 Oracle and/or its affiliates.
  • 65. Native Memory: Diagnostic Data Copyright Š 2019 Oracle and/or its affiliates.
  • 66. Native Memory: Diagnostic Data • For native memory leaks in the JVM • Native Memory Tracker output • For native memory leaks outside the JVM • Process map output with tools like pmap • Results from native memory leak tools such as jemalloc, libumem, valgrind etc. • Core file Copyright Š 2019 Oracle and/or its affiliates.
  • 67. Native Memory Tracker • The Native Memory Tracker (NMT) can be used to track native memory that is used internally by the JVM • It cannot track memory allocated outside the JVM or by native libraries Copyright Š 2019 Oracle and/or its affiliates.
  • 68. NMT • Start the process with NMT enabled by using – XX:+NativeMemoryTracking • The output level can be set to a ‘summary’ or ‘detail’ level: • -XX:NativeMemoryTracking=summary • -XX:NativeMemoryTracking=detail • Use jcmd to get the native memory usage details: • jcmd <pid> VM.native_memory Copyright Š 2019 Oracle and/or its affiliates.
  • 69. jcmd 90172 VM.native_memory 90172: Native Memory Tracking: Total: reserved=3431296KB, committed=2132244KB - Java Heap (reserved=2017280KB, committed=2017280KB) (mmap: reserved=2017280KB, committed=2017280KB) - Class (reserved=1062088KB, committed=10184KB) (classes #411) (malloc=5320KB #190) (mmap: reserved=1056768KB, committed=4864KB) - Thread (reserved=15423KB, committed=15423KB) (thread #16) (stack: reserved=15360KB, committed=15360KB) (malloc=45KB #81) (arena=18KB #30) - Code (reserved=249658KB, committed=2594KB) (malloc=58KB #348) (mmap: reserved=249600KB, committed=2536KB) - GC (reserved=79628KB, committed=79544KB) (malloc=5772KB #118) (mmap: reserved=73856KB, committed=73772KB) - Compiler (reserved=138KB, committed=138KB) (malloc=8KB #41) (arena=131KB #3) - Internal (reserved=5380KB, committed=5380KB) (malloc=5316KB #1357) (mmap: reserved=64KB, committed=64KB) - Symbol (reserved=1367KB, committed=1367KB) (malloc=911KB #112) (arena=456KB #1) - Native Memory Tracking (reserved=118KB, committed=118KB) (malloc=66KB #1040) (tracking overhead=52KB) - Arena Chunk (reserved=217KB, committed=217KB) (malloc=217KB) Copyright Š 2019 Oracle and/or its affiliates.
  • 70. Native Memory Leaks Outside JVM • For native memory leaks stemming from outside the JVM, we need to rely on the native memory leak tools for their detection and troubleshooting • Native Memory Leak Detection Tools • jemalloc • dbx • libumem • valgrind • purify • and so on Copyright Š 2019 Oracle and/or its affiliates.
  • 71. Summary • Various OutOfMemoryErrors • Causes of memory related problems: • Misconfiguration of Memory Pools • Excessive use of Finalizers • Memory Leaks • Size memory pools appropriately • Tools to investigate memory leaks • HeapDumpOnOutOfMemoryError and PrintClassHistogram JVM Options • JConsole • jcmd • jmap • GC Logs • Eclipse MAT • NMT • Native Memory Leak Detection Tools such as dbx, libumem, valgrind, purify etc. Copyright Š 2019 Oracle and/or its affiliates.
  • 72. References • Troubleshooting Guide: • https://docs.oracle.com/en/java/javase/12/troubleshoot/index.html • Blog: • https://blogs.oracle.com/poonam/ • Free Online Course: Java Virtual Machine Troubleshooting • http://www.oracle.com/goto/jvm • Article: https://www.infoq.com/articles/Troubleshooting-Java- Memory-Issues Copyright Š 2019 Oracle and/or its affiliates.
  • 73. 73 Get Rid Of OutOfMemoryError Messages Poonam Parhar Consulting Member of Technical Staff Java Platform Group, Oracle Copyright Š 2019 Oracle and/or its affiliates.