JVM Troubleshooting MOOC: Troubleshooting Memory Issues in Java Applications

Similar documents
Lesson 2 Dissecting Memory Problems

JVM Memory Model and GC

Fundamentals of GC Tuning. Charlie Hunt JVM & Performance Junkie

Java Performance Tuning

Do Your GC Logs Speak To You

Java & Coherence Simon Cook - Sales Consultant, FMW for Financial Services

Troubleshooting Memory Problems in Java Applications

Attila Szegedi, Software

Java Platform, Standard Edition HotSpot Virtual Machine Garbage Collection Tuning Guide. Release 10

Understanding Java Garbage Collection

Contents. Created by: Raúl Castillo

The Fundamentals of JVM Tuning

The G1 GC in JDK 9. Erik Duveblad Senior Member of Technical Staf Oracle JVM GC Team October, 2017

Algorithms for Dynamic Memory Management (236780) Lecture 4. Lecturer: Erez Petrank

Java Performance Tuning From A Garbage Collection Perspective. Nagendra Nagarajayya MDE

Name, Scope, and Binding. Outline [1]

Java Memory Management. Märt Bakhoff Java Fundamentals

G1 Garbage Collector Details and Tuning. Simone Bordet

Garbage collection. The Old Way. Manual labor. JVM and other platforms. By: Timo Jantunen

Finally! Real Java for low latency and low jitter

Sustainable Memory Use Allocation & (Implicit) Deallocation (mostly in Java)

Exploiting the Behavior of Generational Garbage Collector

NUMA in High-Level Languages. Patrick Siegler Non-Uniform Memory Architectures Hasso-Plattner-Institut

Garbage Collection (aka Automatic Memory Management) Douglas Q. Hawkins. Why?

Shenandoah An ultra-low pause time Garbage Collector for OpenJDK. Christine H. Flood Roman Kennke

2011 Oracle Corporation and Affiliates. Do not re-distribute!

The Garbage-First Garbage Collector

Garbage Collection. Hwansoo Han

Runtime. The optimized program is ready to run What sorts of facilities are available at runtime

CMSC 330: Organization of Programming Languages

Understanding Java Garbage Collection

Understanding Java Garbage Collection

Acknowledgements These slides are based on Kathryn McKinley s slides on garbage collection as well as E Christopher Lewis s slides

CMSC 330: Organization of Programming Languages

CMSC 330: Organization of Programming Languages. Memory Management and Garbage Collection

Habanero Extreme Scale Software Research Project

Understanding Java Garbage Collection

Concurrent Garbage Collection

CS 345. Garbage Collection. Vitaly Shmatikov. slide 1

Understanding Garbage Collection

The C4 Collector. Or: the Application memory wall will remain until compaction is solved. Gil Tene Balaji Iyengar Michael Wolf

1. Mark-and-Sweep Garbage Collection

CA341 - Comparative Programming Languages

JVM Performance Study Comparing Java HotSpot to Azul Zing Using Red Hat JBoss Data Grid

Memory. don t forget to take out the

NG2C: Pretenuring Garbage Collection with Dynamic Generations for HotSpot Big Data Applications

Lecture 13: Garbage Collection

Managed runtimes & garbage collection. CSE 6341 Some slides by Kathryn McKinley

JVM Performance Tuning with respect to Garbage Collection(GC) policies for WebSphere Application Server V6.1 - Part 1

Understanding Java Garbage Collection

Managed runtimes & garbage collection

Garbage Collection. Weiyuan Li

Garbage Collection Algorithms. Ganesh Bikshandi

JDK 9/10/11 and Garbage Collection

55 New Features In JDK 9

The Z Garbage Collector Scalable Low-Latency GC in JDK 11

The Application Memory Wall

Running class Timing on Java HotSpot VM, 1

Memory management has always involved tradeoffs between numerous optimization possibilities: Schemes to manage problem fall into roughly two camps

Java Performance Tuning and Optimization Student Guide

Compiler Construction D7011E

A JVM Does What? Eva Andreasson Product Manager, Azul Systems

THE TROUBLE WITH MEMORY

The Z Garbage Collector Low Latency GC for OpenJDK

The Z Garbage Collector An Introduction

Lesson 3 Diagnostic Data Collection and Analysis tools

Programming Language Implementation

10/26/2017 Universal Java GC analysis tool - Java Garbage collection log analysis made easy

Debugging Your Production JVM TM Machine

Compiler construction 2009

JVM Performance Study Comparing Oracle HotSpot and Azul Zing Using Apache Cassandra

Lecture 15 Garbage Collection

Heap Management. Heap Allocation

Low latency & Mechanical Sympathy: Issues and solutions

Enabling Java in Latency Sensitive Environments

MEMORY MANAGEMENT HEAP, STACK AND GARBAGE COLLECTION

New Java performance developments: compilation and garbage collection

Garbage Collection Techniques

OS-caused Long JVM Pauses - Deep Dive and Solutions

Deallocation Mechanisms. User-controlled Deallocation. Automatic Garbage Collection

JAVA PERFORMANCE. PR SW2 S18 Dr. Prähofer DI Leopoldseder

Contents. 8-1 Copyright (c) N. Afshartous

Welcome to the session...

Typical Issues with Middleware

Automatic Garbage Collection

Implementation Garbage Collection

Run-Time Environments/Garbage Collection

Project. there are a couple of 3 person teams. a new drop with new type checking is coming. regroup or see me or forever hold your peace

Java Garbage Collection. Carol McDonald Java Architect Sun Microsystems, Inc.

Towards High Performance Processing in Modern Java-based Control Systems. Marek Misiowiec Wojciech Buczak, Mark Buttner CERN ICalepcs 2011

TECHNOLOGY WHITE PAPER. Azul Pauseless Garbage Collection. Providing continuous, pauseless operation for Java applications

High Performance Managed Languages. Martin Thompson

CSE P 501 Compilers. Memory Management and Garbage Collec<on Hal Perkins Winter UW CSE P 501 Winter 2016 W-1

Ahead of Time (AOT) Compilation

Comparison of Garbage Collectors in Java Programming Language

Garbage Collection (1)

A new Mono GC. Paolo Molaro October 25, 2006

Garbage Collection. Akim D le, Etienne Renault, Roland Levillain. May 15, CCMP2 Garbage Collection May 15, / 35

It s Good to Have (JVM) Options

Run-time Environments -Part 3

Transcription:

JVM Troubleshooting MOOC: Troubleshooting Memory Issues in Java Applications Poonam Parhar JVM Sustaining Engineer Oracle

Lesson 1 HotSpot JVM Memory Management Poonam Parhar JVM Sustaining Engineer Oracle

Agenda 1. Automatic Memory Management 2. Generational Garbage Collection and Memory Spaces in the HotSpot JVM 3. Garbage Collectors in the HotSpot JVM 4. Garbage Collection Changes Between Java 7, 8 and 9 4

Lesson 1-1 Automatic Memory Management Poonam Parhar JVM Sustaining Engineer Oracle

Automatic Memory Management Memory Management? process of allocating, determining when objects are not referenced, and then de-allocating them Explicit memory management in some programming languages HotSpot JVM employs automatic memory management Managed by a sub-system called the garbage collector The garbage collector in the HotSpot JVM automatically manages memory freeing the programmer from worrying about the object de-allocations 6

Memory allocation examples Example in C language: //allocate memory int* array = (int*)malloc(sizeof(int)*20); //explicitly deallocate memory free(array); Example in Java that employs automatic memory management: //allocate memory for String object String s = new String("Hello World"); //no need to explicitly free memory occupied by 's'. It would be released by the garbage collector when 's' goes out of scope. 7

Object Allocations Heap 8

Object Allocations Heap 9

Fields Heap 10

References Heap 11

Heap 12

Heap 13

Heap 14

Heap 15

Collect Garbage Heap 16

Compact Heap 17

Allocations Continue Object Allocations Heap 18

Garbage Collector Garbage collector is responsible for Memory allocation Keeping the referenced objects in memory Reclaiming the space used by unreachable objects Unreachable objects are called garbage This whole process of reclaiming memory is garbage collection 19

Summary: Section 1 HotSpot JVM uses automatic memory management Memory is automatically managed by a sub-system called the garbage collector Garbage collector is responsible for Allocations Keeping the alive objects in memory Reclaiming the space used by unreachable objects 20

Lesson 1-2 Generational Garbage Collection and Memory Spaces in the HotSpot JVM Poonam Parhar JVM Sustaining Engineer Oracle

Generational Garbage Collection Memory space is divided into generations Separate pools holding objects of different age ranges Based on hypothesis: Most allocated objects die young Few references from older to younger objects exist To take advantage of this hypothesis, heap is divided into two generations Young: small and collected frequently Old : larger and occupancy grows slowly Minor(young) and Major(Full) collections 22

Young and Old Generation 23

Allocations into the Young Generation Young Generation Old Generation 24

Young Generation Promotions to Old Generation Old Generation 25

Permanent Generation HotSpot JVM prior to JDK 8 had a third generation called Permanent Generation Used for: JVM internal representation of classes and their metadata Class statics Interned strings Contiguous with the Java Heap 26

Metaspace JDK 8 does not have Permanent Generation Class metadata is stored in a new space called Metaspace Not contiguous with the Java Heap Metaspace is allocated out of native memory Maximum space available to the Metaspace is the available system memory This can though be limited by MaxMetaspaceSize JVM option 27

Compressed Class Space If UseCompressedClassesPointers is enabled then two separate areas of memory are used for the classes and its metadata Metaspace Compressed class space 64-bit class pointers are represented with 32-bit offsets Class metadata referenced by the 32-bit offsets is stored in the Compressed Class Space By default compressed class space is sized at 1GB MaxMetaspaceSize sets an upper limit on the committed size of both of these spaces. 28

_mark _klass <Object Fields> _mark _klass <Object Fields> Klass Other metadata Klass Other metadata 29

_mark _klass <Object Fields> _mark _klass <Object Fields> Other metadata Other metadata Klass Klass 30

Code Cache Code Cache is used to store the compiled code generated by the Just-intime compilers It is allocated out of native memory Managed by the Code Cache Sweeper 31

Native Memory Available system memory Not managed by the JVM memory management 32

33

Summary: Section 2 Memory space is divided into memory pools Java Heap Young generation Old generation Classes and metadata space Permanent Generation (before JDK 8) Metaspace (metaspace + compressed class space) (JDK 8 onwards) CodeCache Native Memory 34

Lesson 1-3 Garbage Collectors in the HotSpot JVM Poonam Parhar JVM Sustaining Engineer Oracle

HotSpot Garbage Collectors Serial ParNew ParallelScavenge G1 Serial Old (Mark Sweep Compact) CMS Concurrent mode failure CMS Parallel Old Combination not available in 9 36

HotSpot Garbage Collection Types Young Generation Collection Serial is a stop-the-world, copying collector that uses a single GC thread ParNew is a stop-the-world, copying collector that uses multiple GC threads Parallel Scavenge is a stop-the-world, copying collector that uses multiple GC threads Old Generation Collection Serial Old is a stop-the-world, mark-sweep-compact collector that uses a single GC thread CMS is a mostly concurrent, low-pause collector Parallel Old is a compacting collector that uses multiple GC threads G1 is the Garbage First collector for large heaps and provides reliable short GC pauses Has generations but uses different memory layout 37

How to enable the Collectors UseSerialGC : Serial + Serial Old UseParNewGC : ParNew + Serial Old UseConcMarkSweepGC : ParNew + CMS + Serial Old. CMS is used most of the time to collect the old generation. Serial Old is used when a concurrent mode failure occurs. UseParallelGC : Parallel Scavenge + Parallel Old UseG1GC : G1 GC for both generations 38

Young Collections 39

Young Collections 40

Mark-Sweep-Compact Collector -XX:+UseSerialGC or XX:+UseParNewGC selects Serial Old collector for old generation Stop-the-world old generation collector. Old is collected using mark-sweep-compact. Mark phase: marks all live objects. Sweep phase: sweeps over the heap identifying garbage. Slide phase: the GC performs a sliding compaction, sliding the live objects towards the start of the Heap. 41

Parallel Collector -XX:+UseParallelGC Young Generation collected with Parallel Scavenge Old Generation collected with Parallel collector It is also called the throughput collector Stop-the-world collections Default on Server type machines up until JDK 9 Collection is performed in parallel on multiple cores 42

Concurrent Mark Sweep Collector -XX:+UseConcMarkSweepGC Young gen ParNew collector Old gen CMS collector Low-latency collector, Mostly concurrent No heap compaction fragmentation Free lists link unallocated regions Allocations expensive as compared to bump-the-pointer allocations Additional overhead on young collections Larger heap size requirement and floating garbage Deprecated in Java 9 43

G1 Collector Server-style garbage collector, targeted for multi-processor machines with large memories Meets garbage collection (GC) pause time goals with a high probability, while achieving high throughput. Better GC ergonomics Low pauses without fragmentation Parallelism and concurrency in collections G1 is a compacting collector. Fully supported in Oracle JDK 7 update 4 and later releases Default collector in JDK 9 44

Summary: Section 3 Serial Collector Parallel Collector throughput collector Low Pause Collectors G1 Garbage Collector default in Java 9 CMS deprecated in Java 9 45

References GC Tuning Guide https://docs.oracle.com/javase/9/gctuning/toc.htm Books Garbage Collection: Algorithms for Automatic Dynamic Memory Management. Wiley, Chichester, July 1996. With a chapter on Distributed Garabge Collection by R. Lins. Richard Jones, Antony Hosking, and Elliot Moss. The Garbage Collection Handbook: The Art of Automatic Memory Management. CRC Applied Algorithms and Data Structures. Chapman & Hall, January 2012 46

Lesson 1-4 Garbage Collection Changes Between Java 7, 8 and 9 Poonam Parhar JVM Sustaining Engineer Oracle

JDK 7 Changes 48

Permanent Generation Partially Removed In JDK 7, some things were moved out of PermGen Symbols were moved to native memory Interned strings were moved to the Java Heap Class statics were moved to the Java Heap Might contribute to slight increase in the young collections pause times Can revert this change with XX:+JavaObjectsInPerm 49

JDK 8 Changes 50

Permanent Generation Removed Permanent Generation has been removed in JDK 8 PermGen tuning options are now obsolete in JDK 8 51

MetaSpace in JDK 8 Metaspace added in JDK 8 Classes and metadata stored in the Metaspace It replaces PermGen New Metaspace tuning JVM options added MetaspaceSize MaxMetaspaceSize 52

Class Unloading Related Changes Until JDK 8u40, G1 unloads classes only at Full GCs Classes don t get unloaded during the young or mixed collections and a Full GC is required to unload classes G1 supports concurrent unloading of classes from JDK 8 53

JDK 9 Changes 54

G1 Garbage Collector JDK 9 makes the G1 Garbage collector the default garbage collector It is surely possible to explicitly pick the garbage collector of your choosing For example: -XX:+UseParallelGC would select Parallel GC as the garbage collector 55

CMS Collector JDK 9 deprecates the CMS garbage collector Warning message is issued when -XX:+UseConcMarkSweepGC is used Planned for removal in a future major release 56

GC Combinations Removed in Java 9 DefNew + CMS : -XX:-UseParNewGC -XX:+UseConcMarkSweepGC ParNew + SerialOld : -XX:+UseParNewGC ParNew + icms : -Xincgc ParNew + icms : -XX:+CMSIncrementalMode -XX:+UseConcMarkSweepGC DefNew + icms : -XX:+CMSIncrementalMode -XX:+UseConcMarkSweepGC -XX:-UseParNewGC CMS foreground : -XX:+UseCMSCompactAtFullCollection CMS foreground : -XX:+CMSFullGCsBeforeCompaction CMS foreground : -XX:+UseCMSCollectionPassing 57