SlideShare ist ein Scribd-Unternehmen logo
1 von 38
Tech share Java Memory Management
Garbage Collection Responsibility  Allocating memory Ensuring that any referenced objects remain in memory Recovering memory used by objects that are no longer reachable from references in executing code.
Generation Collection Most allocated objects die young Few references from older to younger objects exist.
Sun hotspot memory model Young Generation Eden Survivor From Survivor To Tenured (Old) Generation Permanent objects describing classes and methods as well as the classes and methods themselves
Garbage Collection Types young generation collection (minor collection) young generation fills up full collection (major collection)  old or permanent generation fills up System.gc() the old generation collection algorithm is used on : Sometimes the old generation is too full to accept all the objects that would be likely to be promoted from the young generation to the old generation if the young generation was collected first.
Fast Allocation bump-the-pointer technique  large contiguous blocks of memory available Thread-Local Allocation Buffers (TLABs) multithread-safe without global locks -XX:TLABWasteTargetPercent   (n/Eden)  -XX:+PrintTLAB
Hotspot Collectors Serial Collector Parallel Collector Parallel Compacting Collector Concurrent Mark-Sweep (CMS) Collector
Hotspot Default garbage collector  Java –version java version "1.6.0_23" Java(TM) SE Runtime Environment (build 1.6.0_23-b05) Java HotSpot(TM) Client VM (build 19.0-b09, mixed mode, sharing)  Server : parallel collector Note: For Java SE 6, the definition of a server-class machine is one with at least 2 CPUs and at least 2GB of physical memory. Client: Serial collector
Serial Collector using a single CPU in a stop-the-world fashion
Serial Collector Yong Generation Collection too large objects are directly copied to old generation -XX:InitialTenuringThreshold=7 -XX:MaxTenuringThreshold=
Serial Collector  Old Generation Collection mark-sweep-compact Mark Mark live objects Sweep Sweep unmarked objects Compact For bump-the-pointer
Serial Collector When to Use: do not have a requirement for low pause times On today’s hardware, less than half a second for full collections (64MB heaps) 1024MB/64MB=16*0.5second = 8second Usage: -XX:+UseSerialGC
Parallel Collector also known as the throughput collector -XX:+PrintGCDetails -XX:+PrintTLAB -XX:MaxTenuringThreshold=7 -XX:PretenureSizeThreshold=2M -XX:+PrintGCTimeStamps -Xms30M -Xmx30M -Xmn2M   -XX:+UseParallelGC PSYoungGen [0x085f0000, 0x087f0000, 0x087f0000) eden space [0x085f0000,0x087673c0,0x08770000)   from space [0x087b0000,0x087b0000,0x087f0000)   to   space [0x08770000,0x08770000,0x087b0000) PSOldGen [0x069f0000, 0x085f0000, 0x085f0000)   object space [0x069f0000,0x070f0070,0x085f0000)
Parallel Collector Young Generation Collection still a stop-the-world and copying collector in parallel using many CPUs
Parallel Collector Old Generation Collection Still mark-sweep-compact  serial operation When to use: often appropriate include those that do batch processing, billing, payroll, scientific computing, and so on. Usage: -XX:+UseParallelGC
Parallel Compacting Collector was introduced in J2SE 5.0 update 6 Note:  willreplace the parallel collector. Young Generation Collection  Same as parallel collector
Parallel Compacting Collector Old Generation Collection  marking phase logically divided into fixed-sized regions GCmarklive objects with multi-thread –XX:ParallelGCThreads=n (By default on a host with N CPUs) summary phase  (serial operation) starting with the leftmost one to examine the density of the regions Calculates and stores the new location of the first byte of live data for each compacted region compaction phase Compact use by summary data
Parallel Compacting Collector When to use: more than one CPU reduces pause times  (multi-thread) Usage: -XX:+UseParallelOldGC -XX:ParallelGCThreads=n
Concurrent Mark-Sweep (CMS) Collector also known as the low-latency collector. Young Generation Collection  Same as parallel collector
Concurrent Mark-Sweep (CMS) Collector Old Generation Collection: identifies the initial set of live objects directly reachable from the application code marks all live objects that are transitively reachable from this set
Concurrent Mark-Sweep (CMS) disadvantage only collector that is non-compacting requirement for larger heap sizes than the other collectors CMS Incremental Mode periodically stopping the concurrent phase to yield back processing to the application –XX:+CMSIncrementalMode
Concurrent Mark-Sweep (CMS) When to use: applications that have a relatively large set of long-lived data (a large old generation) run on machines with two or more processors for any application with a low pause time requirement Usage:  -XX:+UseConcMarkSweepGC –XX:+CMSIncrementalMode (Incremental Mode)
CMS log 2.259: [GC [1 CMS-initial-mark: 4280K(5120K)] 6042K(18944K), 0.0003876 secs] [Times: user=0.00 sys=0.00, real=0.00 secs]  2.260: [CMS-concurrent-mark-start] 2.267: [CMS-concurrent-mark: 0.007/0.007 secs] [Times: user=0.00 sys=0.00, real=0.00 secs]  2.267: [CMS-concurrent-preclean-start] 2.267: [CMS-concurrent-preclean: 0.001/0.001 secs] [Times: user=0.01 sys=0.00, real=0.02 secs]  2.267: [GC[YG occupancy: 1761 K (13824 K)]2.268: [Rescan (parallel) , 0.0001977 secs]2.268: [weak refs processing, 0.0000046 secs] [1 CMS-remark: 4280K(5120K)] 6042K(18944K), 0.0003386 secs] [Times: user=0.00 sys=0.00, real=0.00 secs]  2.268: [CMS-concurrent-sweep-start] 2.269: [CMS-concurrent-sweep: 0.001/0.001 secs] [Times: user=0.00 sys=0.00, real=0.00 secs]  2.269: [CMS-concurrent-reset-start] 2.269: [CMS-concurrent-reset: 0.001/0.001 secs] [Times: user=0.00 sys=0.00, real=0.00 secs]
Disadvantage of non-compactingCode static int alloc_1MB = 1024 * 1024 * 1; public static void main(String[] args) throws Exception {         //UseConcMarkSweepGC         byte[] bytes10 = alloc();  alloc();         byte[] bytes12 = alloc();  alloc();         byte[] bytes14 = alloc();  alloc();         byte[] bytes16 = alloc();  alloc();         byte[] bytes18 = alloc();  alloc();         byte[] bytes20 = alloc();  alloc();         byte[] bytes22 = alloc(); alloc(3);     } static int count = 0;     private static byte[] alloc() {         return alloc(1);     }     private static byte[] alloc(inti) {         count = count +  1 * i ; System.out.println(count + "M");         return new byte[alloc_1MB * i];     }
Disadvantage of non-compactingresult of Parallel&ParallelOld -XX:+UseParallelGC -XX:PretenureSizeThreshold=1k -XX:MaxTenuringThreshold=30 -Xms20M -Xmx20M -Xmn10M  -XX:+PrintGCDetails -XX:+PrintGCTimeStamps -XX:-PrintTenuringDistribution PSYoungGen      total 8960K, used 5336K eden space 7680K, 69% used   from space 1280K, 0% used    to   space 1280K, 0% used  PSOldGen        total 10240K, used 6598K    object space 10240K, 64% used PSPermGen       total 16384K, used 4969K    object space 16384K, 30% used
Disadvantage of non-compactingResult of CMS -XX:+UseConcMarkSweepGC -XX:PretenureSizeThreshold=1k -XX:MaxTenuringThreshold=30 -Xms20M -Xmx20M -Xmn10M  -XX:+PrintGCDetails -XX:+PrintGCTimeStamps -XX:-PrintTenuringDistribution Exception in thread "main" java.lang.OutOfMemoryError: Java heap space  par new generation   total 9216K, used 491K  eden space 8192K,   6% used    from space 1024K,   0% used    to   space 1024K,   0% used  concurrent mark-sweep generation total 10240K, used 398K   concurrent-mark-sweep perm gen total 16384K, used 4947K
VM options -XX:MaxGCPauseMillis=n Pause time -XX:GCTimeRatio=99 1 / (1 + n) Throughput -Xmx –Xms -Xmn (=eden+survivor*2) –XX:SurvivorRatio=32 (1:34) Survivor:Eden -XX:MaxPermSize
Print gc –XX:+PrintGC –XX:+PrintGCDetails –XX:+PrintGCTimeStamps -verbose:gc [GC 325407K->83000K(776768K), 0.2300771 secs] [GC 325816K->83372K(776768K), 0.2454258 secs] [Full GC 267628K->83769K(776768K), 1.8479984 secs]
example -XX:MaxTenuringThreshold=7 -XX:MaxTenuringThreshold=0 -Xms30M -Xmx30M -Xmn10M  -XX:+UseSerialGC  def new generation   total 9216K, used 1106K [0x30be0000, 0x315e0000, 0x315e0000) eden space 8192K,  13% used [0x30be0000, 0x30cf4830, 0x313e0000) from space 1024K,   0% used [0x314e0000, 0x314e0000, 0x315e0000)   to   space 1024K,   0% used [0x313e0000, 0x313e0000, 0x314e0000) -XX:MaxTenuringThreshold=0 -XX:MaxTenuringThreshold=7 -Xms30M -Xmx30M -Xmn10M  -XX:+UseSerialGC  def new generation   total 9216K, used 1292K [0x30be0000, 0x315e0000, 0x315e0000) eden space 8192K,  13% used [0x30be0000, 0x30cf4890, 0x313e0000) from space 1024K,  18% used [0x314e0000, 0x3150e8b0, 0x315e0000)   to   space 1024K,   0% used [0x313e0000, 0x313e0000, 0x314e0000) ,[object Object],-XX:MaxTenuringThreshold=0 –Xms20M –Xmx20M -Xmn18M  -XX:+UseSerialGC Exception in thread "main" java.lang.OutOfMemoryError: Java heap space Notice: for Serial collector & CMS
System.gc()  &  finalize() Code: public class SerialTest {     public static void main(String[] args) throws Exception {         new SerialTest(); System.gc(); Thread.sleep(10); System.out.println("123");     } @Override     protected void finalize() throws Throwable { System.out.println("heloo================finalize");     } } Result: 0.227: [Full GC (System) TLAB: gc thread: 0x08839400 [id: 5820]  ……….. heloo================finalize 123
finalize  twice GC !!!
monitor JVisualVM JConsole JRockit mission control
Garbage-First Garbage Collector G1 GC for short Is a new GC that is being introduced in the Java HotSpot VM in JDK 7 also been released in Java SE 6 Update 14. G1 is the long-term replacement for HotSpot's low-latency Concurrent Mark-Sweep GC (widely referred to as CMS).
Garbage-First Garbage Collector Parallelism and Concurrency. G1 performs heap compaction there is a single contiguous heap which is split into same-sized regions Young/old generation is a set of potentially non-contiguous regions
G1 Collector Heap  garbage-first heap   total 20480K, used 3491K   region size 1024K, 3 young (3072K), 0 survivors (0K)  compacting perm gen  total 16384K, used 4967K    the space 16384K,  30% used No shared spaces configured.
G1 Collector RS: regon set 0.634: [GC pause (young), 0.00846287 secs]    [Parallel Time:   8.3 ms]       [GC Worker Start Time (ms):  633.9  634.3]       [Update RS (ms):  0.0  0.0 Avg:   0.0, Min:   0.0, Max:   0.0]          [Processed Buffers : 0 5           Sum: 5, Avg: 2, Min: 0, Max: 5]       [Ext Root Scanning (ms):  3.6  3.3 Avg:   3.5, Min:   3.3, Max:   3.6]       [Mark Stack Scanning (ms):  0.0  0.0 Avg:   0.0, Min:   0.0, Max:   0.0]       [Scan RS (ms):  0.0  0.0 Avg:   0.0, Min:   0.0, Max:   0.0]       [Object Copy (ms):  3.8  3.6 Avg:   3.7, Min:   3.6, Max:   3.8]       [Termination (ms):  0.0  0.0 Avg:   0.0, Min:   0.0, Max:   0.0]          [Termination Attempts : 1 1           Sum: 2, Avg: 1, Min: 1, Max: 1]       [GC Worker End Time (ms):  641.3  641.3]       [Other:   1.1 ms]    [Clear CT:   0.0 ms]    [Other:   0.2 ms]       [Choose CSet:   0.0 ms]    [ 2868K->1763K(20M)]  [Times: user=0.00 sys=0.00, real=0.00 secs]
comparison
references http://java.sun.com/products/hotspot/whitepaper.html http://www.oracle.com/technetwork/java/javase/tech/vmoptions-jsp-140102.html http://blogs.oracle.com/watt/resource/jvm-options-list.html http://www.iteye.com/topic/802638 http://blog.csdn.net/calvinxiu/archive/2007/05/18/1614473.aspx http://unixboy.iteye.com/blog/174173 http://java.sun.com/performance/reference/whitepapers/tuning.html

Weitere ähnliche Inhalte

Was ist angesagt?

Java Introduction
Java IntroductionJava Introduction
Java Introductionjaveed_mhd
 
Garbage collection
Garbage collectionGarbage collection
Garbage collectionMudit Gupta
 
Java Methods
Java MethodsJava Methods
Java MethodsOXUS 20
 
Exception Handling In Java
Exception Handling In JavaException Handling In Java
Exception Handling In Javaparag
 
Collections In Java
Collections In JavaCollections In Java
Collections In JavaBinoj T E
 
Java EE Introduction
Java EE IntroductionJava EE Introduction
Java EE Introductionejlp12
 
Java Database Connectivity (JDBC)
Java Database Connectivity (JDBC)Java Database Connectivity (JDBC)
Java Database Connectivity (JDBC)Pooja Talreja
 
Core java concepts
Core java  conceptsCore java  concepts
Core java conceptsRam132
 
Java I/O and Object Serialization
Java I/O and Object SerializationJava I/O and Object Serialization
Java I/O and Object SerializationNavneet Prakash
 
JVM Memory Management Details
JVM Memory Management DetailsJVM Memory Management Details
JVM Memory Management DetailsAzul Systems Inc.
 
SOLID Design Principles
SOLID Design PrinciplesSOLID Design Principles
SOLID Design PrinciplesAndreas Enbohm
 
principles of object oriented class design
principles of object oriented class designprinciples of object oriented class design
principles of object oriented class designNeetu Mishra
 

Was ist angesagt? (20)

Java Introduction
Java IntroductionJava Introduction
Java Introduction
 
Garbage collection
Garbage collectionGarbage collection
Garbage collection
 
Core java
Core java Core java
Core java
 
Java Methods
Java MethodsJava Methods
Java Methods
 
Exception Handling In Java
Exception Handling In JavaException Handling In Java
Exception Handling In Java
 
Collections In Java
Collections In JavaCollections In Java
Collections In Java
 
Java EE Introduction
Java EE IntroductionJava EE Introduction
Java EE Introduction
 
Java Database Connectivity (JDBC)
Java Database Connectivity (JDBC)Java Database Connectivity (JDBC)
Java Database Connectivity (JDBC)
 
Methods in Java
Methods in JavaMethods in Java
Methods in Java
 
Core java
Core javaCore java
Core java
 
Java
JavaJava
Java
 
SQLITE Android
SQLITE AndroidSQLITE Android
SQLITE Android
 
Core java concepts
Core java  conceptsCore java  concepts
Core java concepts
 
Sqlite
SqliteSqlite
Sqlite
 
Jdbc connectivity in java
Jdbc connectivity in javaJdbc connectivity in java
Jdbc connectivity in java
 
Java I/O and Object Serialization
Java I/O and Object SerializationJava I/O and Object Serialization
Java I/O and Object Serialization
 
JVM Memory Management Details
JVM Memory Management DetailsJVM Memory Management Details
JVM Memory Management Details
 
SOLID Design Principles
SOLID Design PrinciplesSOLID Design Principles
SOLID Design Principles
 
principles of object oriented class design
principles of object oriented class designprinciples of object oriented class design
principles of object oriented class design
 
Shell programming
Shell programmingShell programming
Shell programming
 

Andere mochten auch

Memory Management: What You Need to Know When Moving to Java 8
Memory Management: What You Need to Know When Moving to Java 8Memory Management: What You Need to Know When Moving to Java 8
Memory Management: What You Need to Know When Moving to Java 8AppDynamics
 
Java memory presentation
Java memory presentationJava memory presentation
Java memory presentationYury Bubnov
 
Java性能调优浅谈
Java性能调优浅谈Java性能调优浅谈
Java性能调优浅谈jxqlovejava
 
An Introduction to JVM Internals and Garbage Collection in Java
An Introduction to JVM Internals and Garbage Collection in JavaAn Introduction to JVM Internals and Garbage Collection in Java
An Introduction to JVM Internals and Garbage Collection in JavaAbhishek Asthana
 
Understanding Java Garbage Collection
Understanding Java Garbage CollectionUnderstanding Java Garbage Collection
Understanding Java Garbage CollectionAzul Systems Inc.
 
3978 Why is Java so different... A Session for Cobol/PLI/Assembler Developers
3978   Why is Java so different... A Session for Cobol/PLI/Assembler Developers3978   Why is Java so different... A Session for Cobol/PLI/Assembler Developers
3978 Why is Java so different... A Session for Cobol/PLI/Assembler Developersnick_garrod
 

Andere mochten auch (12)

The Java Memory Model
The Java Memory ModelThe Java Memory Model
The Java Memory Model
 
Memory Management: What You Need to Know When Moving to Java 8
Memory Management: What You Need to Know When Moving to Java 8Memory Management: What You Need to Know When Moving to Java 8
Memory Management: What You Need to Know When Moving to Java 8
 
Java memory presentation
Java memory presentationJava memory presentation
Java memory presentation
 
Java memory model
Java memory modelJava memory model
Java memory model
 
OAuth 2.0协议
OAuth 2.0协议OAuth 2.0协议
OAuth 2.0协议
 
Java性能调优浅谈
Java性能调优浅谈Java性能调优浅谈
Java性能调优浅谈
 
Java GC, Off-heap workshop
Java GC, Off-heap workshopJava GC, Off-heap workshop
Java GC, Off-heap workshop
 
Tools for Metaspace
Tools for MetaspaceTools for Metaspace
Tools for Metaspace
 
An Introduction to JVM Internals and Garbage Collection in Java
An Introduction to JVM Internals and Garbage Collection in JavaAn Introduction to JVM Internals and Garbage Collection in Java
An Introduction to JVM Internals and Garbage Collection in Java
 
Understanding Java Garbage Collection
Understanding Java Garbage CollectionUnderstanding Java Garbage Collection
Understanding Java Garbage Collection
 
The Java memory model made easy
The Java memory model made easyThe Java memory model made easy
The Java memory model made easy
 
3978 Why is Java so different... A Session for Cobol/PLI/Assembler Developers
3978   Why is Java so different... A Session for Cobol/PLI/Assembler Developers3978   Why is Java so different... A Session for Cobol/PLI/Assembler Developers
3978 Why is Java so different... A Session for Cobol/PLI/Assembler Developers
 

Ähnlich wie java memory management & gc

Chicago-Java-User-Group-Meetup-Some-Garbage-Talk-2015-01-14
Chicago-Java-User-Group-Meetup-Some-Garbage-Talk-2015-01-14Chicago-Java-User-Group-Meetup-Some-Garbage-Talk-2015-01-14
Chicago-Java-User-Group-Meetup-Some-Garbage-Talk-2015-01-14Jayesh Thakrar
 
Sun jdk 1.6 gc english version
Sun jdk 1.6 gc english versionSun jdk 1.6 gc english version
Sun jdk 1.6 gc english versionbluedavy lin
 
JVM performance options. How it works
JVM performance options. How it worksJVM performance options. How it works
JVM performance options. How it worksDmitriy Dumanskiy
 
Garbage First Garbage Collector (G1 GC): Current and Future Adaptability and ...
Garbage First Garbage Collector (G1 GC): Current and Future Adaptability and ...Garbage First Garbage Collector (G1 GC): Current and Future Adaptability and ...
Garbage First Garbage Collector (G1 GC): Current and Future Adaptability and ...Monica Beckwith
 
Am I reading GC logs Correctly?
Am I reading GC logs Correctly?Am I reading GC logs Correctly?
Am I reading GC logs Correctly?Tier1 App
 
Performance tuning jvm
Performance tuning jvmPerformance tuning jvm
Performance tuning jvmPrem Kuppumani
 
Become a Garbage Collection Hero
Become a Garbage Collection HeroBecome a Garbage Collection Hero
Become a Garbage Collection HeroTier1app
 
Pick diamonds from garbage
Pick diamonds from garbagePick diamonds from garbage
Pick diamonds from garbageTier1 App
 
Simple, fast, and scalable torch7 tutorial
Simple, fast, and scalable torch7 tutorialSimple, fast, and scalable torch7 tutorial
Simple, fast, and scalable torch7 tutorialJin-Hwa Kim
 
JVM Garbage Collection Tuning
JVM Garbage Collection TuningJVM Garbage Collection Tuning
JVM Garbage Collection Tuningihji
 
The Technology behind Shadow Warrior, ZTG 2014
The Technology behind Shadow Warrior, ZTG 2014The Technology behind Shadow Warrior, ZTG 2014
The Technology behind Shadow Warrior, ZTG 2014Jarosław Pleskot
 
What you need to know about GC
What you need to know about GCWhat you need to know about GC
What you need to know about GCKelum Senanayake
 
Java profiling Do It Yourself
Java profiling Do It YourselfJava profiling Do It Yourself
Java profiling Do It Yourselfaragozin
 
SRV402 Deep Dive on Amazon EC2 Instances, Featuring Performance Optimization ...
SRV402 Deep Dive on Amazon EC2 Instances, Featuring Performance Optimization ...SRV402 Deep Dive on Amazon EC2 Instances, Featuring Performance Optimization ...
SRV402 Deep Dive on Amazon EC2 Instances, Featuring Performance Optimization ...Amazon Web Services
 
CICS Memory Objects and MEMLIMIT
 CICS Memory Objects and MEMLIMIT CICS Memory Objects and MEMLIMIT
CICS Memory Objects and MEMLIMITDavid Clancy
 
JVM memory management & Diagnostics
JVM memory management & DiagnosticsJVM memory management & Diagnostics
JVM memory management & DiagnosticsDhaval Shah
 
Deep dumpster diving 2010
Deep dumpster diving 2010Deep dumpster diving 2010
Deep dumpster diving 2010RonnBlack
 

Ähnlich wie java memory management & gc (20)

Chicago-Java-User-Group-Meetup-Some-Garbage-Talk-2015-01-14
Chicago-Java-User-Group-Meetup-Some-Garbage-Talk-2015-01-14Chicago-Java-User-Group-Meetup-Some-Garbage-Talk-2015-01-14
Chicago-Java-User-Group-Meetup-Some-Garbage-Talk-2015-01-14
 
Sun jdk 1.6 gc english version
Sun jdk 1.6 gc english versionSun jdk 1.6 gc english version
Sun jdk 1.6 gc english version
 
[BGOUG] Java GC - Friend or Foe
[BGOUG] Java GC - Friend or Foe[BGOUG] Java GC - Friend or Foe
[BGOUG] Java GC - Friend or Foe
 
JVM performance options. How it works
JVM performance options. How it worksJVM performance options. How it works
JVM performance options. How it works
 
Garbage First Garbage Collector (G1 GC): Current and Future Adaptability and ...
Garbage First Garbage Collector (G1 GC): Current and Future Adaptability and ...Garbage First Garbage Collector (G1 GC): Current and Future Adaptability and ...
Garbage First Garbage Collector (G1 GC): Current and Future Adaptability and ...
 
Am I reading GC logs Correctly?
Am I reading GC logs Correctly?Am I reading GC logs Correctly?
Am I reading GC logs Correctly?
 
Performance tuning jvm
Performance tuning jvmPerformance tuning jvm
Performance tuning jvm
 
Become a Garbage Collection Hero
Become a Garbage Collection HeroBecome a Garbage Collection Hero
Become a Garbage Collection Hero
 
Pick diamonds from garbage
Pick diamonds from garbagePick diamonds from garbage
Pick diamonds from garbage
 
Simple, fast, and scalable torch7 tutorial
Simple, fast, and scalable torch7 tutorialSimple, fast, and scalable torch7 tutorial
Simple, fast, and scalable torch7 tutorial
 
JVM Garbage Collection Tuning
JVM Garbage Collection TuningJVM Garbage Collection Tuning
JVM Garbage Collection Tuning
 
alexnet.pdf
alexnet.pdfalexnet.pdf
alexnet.pdf
 
The Technology behind Shadow Warrior, ZTG 2014
The Technology behind Shadow Warrior, ZTG 2014The Technology behind Shadow Warrior, ZTG 2014
The Technology behind Shadow Warrior, ZTG 2014
 
What you need to know about GC
What you need to know about GCWhat you need to know about GC
What you need to know about GC
 
Java profiling Do It Yourself
Java profiling Do It YourselfJava profiling Do It Yourself
Java profiling Do It Yourself
 
SRV402 Deep Dive on Amazon EC2 Instances, Featuring Performance Optimization ...
SRV402 Deep Dive on Amazon EC2 Instances, Featuring Performance Optimization ...SRV402 Deep Dive on Amazon EC2 Instances, Featuring Performance Optimization ...
SRV402 Deep Dive on Amazon EC2 Instances, Featuring Performance Optimization ...
 
CICS Memory Objects and MEMLIMIT
 CICS Memory Objects and MEMLIMIT CICS Memory Objects and MEMLIMIT
CICS Memory Objects and MEMLIMIT
 
Deep Dive on Amazon EC2
Deep Dive on Amazon EC2Deep Dive on Amazon EC2
Deep Dive on Amazon EC2
 
JVM memory management & Diagnostics
JVM memory management & DiagnosticsJVM memory management & Diagnostics
JVM memory management & Diagnostics
 
Deep dumpster diving 2010
Deep dumpster diving 2010Deep dumpster diving 2010
Deep dumpster diving 2010
 

Mehr von exsuns

Hadoop 20111215
Hadoop 20111215Hadoop 20111215
Hadoop 20111215exsuns
 
Statistics
StatisticsStatistics
Statisticsexsuns
 
Cassandra
CassandraCassandra
Cassandraexsuns
 
Hadoop 20111117
Hadoop 20111117Hadoop 20111117
Hadoop 20111117exsuns
 

Mehr von exsuns (6)

Hadoop 20111215
Hadoop 20111215Hadoop 20111215
Hadoop 20111215
 
Statistics
StatisticsStatistics
Statistics
 
R
RR
R
 
Ios
IosIos
Ios
 
Cassandra
CassandraCassandra
Cassandra
 
Hadoop 20111117
Hadoop 20111117Hadoop 20111117
Hadoop 20111117
 

Kürzlich hochgeladen

CNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of ServiceCNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of Servicegiselly40
 
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure serviceWhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure servicePooja Nehwal
 
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 MenDelhi Call girls
 
Breaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountBreaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountPuma Security, LLC
 
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 WorkerThousandEyes
 
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhi
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | DelhiFULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhi
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhisoniya singh
 
Slack Application Development 101 Slides
Slack Application Development 101 SlidesSlack Application Development 101 Slides
Slack Application Development 101 Slidespraypatel2
 
A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024Results
 
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 3652toLead Limited
 
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 2024Rafal Los
 
Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slidevu2urc
 
Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024The Digital Insurer
 
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.pptxHampshireHUG
 
Swan(sea) Song – personal research during my six years at Swansea ... and bey...
Swan(sea) Song – personal research during my six years at Swansea ... and bey...Swan(sea) Song – personal research during my six years at Swansea ... and bey...
Swan(sea) Song – personal research during my six years at Swansea ... and bey...Alan Dix
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationSafe Software
 
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024BookNet Canada
 
[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdfhans926745
 
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 textsMaria Levchenko
 
Google AI Hackathon: LLM based Evaluator for RAG
Google AI Hackathon: LLM based Evaluator for RAGGoogle AI Hackathon: LLM based Evaluator for RAG
Google AI Hackathon: LLM based Evaluator for RAGSujit Pal
 
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...gurkirankumar98700
 

Kürzlich hochgeladen (20)

CNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of ServiceCNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of Service
 
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure serviceWhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
 
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
 
Breaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountBreaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path Mount
 
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
 
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhi
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | DelhiFULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhi
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhi
 
Slack Application Development 101 Slides
Slack Application Development 101 SlidesSlack Application Development 101 Slides
Slack Application Development 101 Slides
 
A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024
 
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
 
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
 
Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slide
 
Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024
 
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
 
Swan(sea) Song – personal research during my six years at Swansea ... and bey...
Swan(sea) Song – personal research during my six years at Swansea ... and bey...Swan(sea) Song – personal research during my six years at Swansea ... and bey...
Swan(sea) Song – personal research during my six years at Swansea ... and bey...
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
 
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
 
[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf
 
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
 
Google AI Hackathon: LLM based Evaluator for RAG
Google AI Hackathon: LLM based Evaluator for RAGGoogle AI Hackathon: LLM based Evaluator for RAG
Google AI Hackathon: LLM based Evaluator for RAG
 
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...
 

java memory management & gc

  • 1. Tech share Java Memory Management
  • 2. Garbage Collection Responsibility Allocating memory Ensuring that any referenced objects remain in memory Recovering memory used by objects that are no longer reachable from references in executing code.
  • 3. Generation Collection Most allocated objects die young Few references from older to younger objects exist.
  • 4. Sun hotspot memory model Young Generation Eden Survivor From Survivor To Tenured (Old) Generation Permanent objects describing classes and methods as well as the classes and methods themselves
  • 5. Garbage Collection Types young generation collection (minor collection) young generation fills up full collection (major collection) old or permanent generation fills up System.gc() the old generation collection algorithm is used on : Sometimes the old generation is too full to accept all the objects that would be likely to be promoted from the young generation to the old generation if the young generation was collected first.
  • 6. Fast Allocation bump-the-pointer technique large contiguous blocks of memory available Thread-Local Allocation Buffers (TLABs) multithread-safe without global locks -XX:TLABWasteTargetPercent (n/Eden) -XX:+PrintTLAB
  • 7. Hotspot Collectors Serial Collector Parallel Collector Parallel Compacting Collector Concurrent Mark-Sweep (CMS) Collector
  • 8. Hotspot Default garbage collector Java –version java version "1.6.0_23" Java(TM) SE Runtime Environment (build 1.6.0_23-b05) Java HotSpot(TM) Client VM (build 19.0-b09, mixed mode, sharing) Server : parallel collector Note: For Java SE 6, the definition of a server-class machine is one with at least 2 CPUs and at least 2GB of physical memory. Client: Serial collector
  • 9. Serial Collector using a single CPU in a stop-the-world fashion
  • 10. Serial Collector Yong Generation Collection too large objects are directly copied to old generation -XX:InitialTenuringThreshold=7 -XX:MaxTenuringThreshold=
  • 11. Serial Collector Old Generation Collection mark-sweep-compact Mark Mark live objects Sweep Sweep unmarked objects Compact For bump-the-pointer
  • 12. Serial Collector When to Use: do not have a requirement for low pause times On today’s hardware, less than half a second for full collections (64MB heaps) 1024MB/64MB=16*0.5second = 8second Usage: -XX:+UseSerialGC
  • 13. Parallel Collector also known as the throughput collector -XX:+PrintGCDetails -XX:+PrintTLAB -XX:MaxTenuringThreshold=7 -XX:PretenureSizeThreshold=2M -XX:+PrintGCTimeStamps -Xms30M -Xmx30M -Xmn2M -XX:+UseParallelGC PSYoungGen [0x085f0000, 0x087f0000, 0x087f0000) eden space [0x085f0000,0x087673c0,0x08770000) from space [0x087b0000,0x087b0000,0x087f0000) to space [0x08770000,0x08770000,0x087b0000) PSOldGen [0x069f0000, 0x085f0000, 0x085f0000) object space [0x069f0000,0x070f0070,0x085f0000)
  • 14. Parallel Collector Young Generation Collection still a stop-the-world and copying collector in parallel using many CPUs
  • 15. Parallel Collector Old Generation Collection Still mark-sweep-compact serial operation When to use: often appropriate include those that do batch processing, billing, payroll, scientific computing, and so on. Usage: -XX:+UseParallelGC
  • 16. Parallel Compacting Collector was introduced in J2SE 5.0 update 6 Note: willreplace the parallel collector. Young Generation Collection Same as parallel collector
  • 17. Parallel Compacting Collector Old Generation Collection marking phase logically divided into fixed-sized regions GCmarklive objects with multi-thread –XX:ParallelGCThreads=n (By default on a host with N CPUs) summary phase (serial operation) starting with the leftmost one to examine the density of the regions Calculates and stores the new location of the first byte of live data for each compacted region compaction phase Compact use by summary data
  • 18. Parallel Compacting Collector When to use: more than one CPU reduces pause times (multi-thread) Usage: -XX:+UseParallelOldGC -XX:ParallelGCThreads=n
  • 19. Concurrent Mark-Sweep (CMS) Collector also known as the low-latency collector. Young Generation Collection Same as parallel collector
  • 20. Concurrent Mark-Sweep (CMS) Collector Old Generation Collection: identifies the initial set of live objects directly reachable from the application code marks all live objects that are transitively reachable from this set
  • 21. Concurrent Mark-Sweep (CMS) disadvantage only collector that is non-compacting requirement for larger heap sizes than the other collectors CMS Incremental Mode periodically stopping the concurrent phase to yield back processing to the application –XX:+CMSIncrementalMode
  • 22. Concurrent Mark-Sweep (CMS) When to use: applications that have a relatively large set of long-lived data (a large old generation) run on machines with two or more processors for any application with a low pause time requirement Usage: -XX:+UseConcMarkSweepGC –XX:+CMSIncrementalMode (Incremental Mode)
  • 23. CMS log 2.259: [GC [1 CMS-initial-mark: 4280K(5120K)] 6042K(18944K), 0.0003876 secs] [Times: user=0.00 sys=0.00, real=0.00 secs] 2.260: [CMS-concurrent-mark-start] 2.267: [CMS-concurrent-mark: 0.007/0.007 secs] [Times: user=0.00 sys=0.00, real=0.00 secs] 2.267: [CMS-concurrent-preclean-start] 2.267: [CMS-concurrent-preclean: 0.001/0.001 secs] [Times: user=0.01 sys=0.00, real=0.02 secs] 2.267: [GC[YG occupancy: 1761 K (13824 K)]2.268: [Rescan (parallel) , 0.0001977 secs]2.268: [weak refs processing, 0.0000046 secs] [1 CMS-remark: 4280K(5120K)] 6042K(18944K), 0.0003386 secs] [Times: user=0.00 sys=0.00, real=0.00 secs] 2.268: [CMS-concurrent-sweep-start] 2.269: [CMS-concurrent-sweep: 0.001/0.001 secs] [Times: user=0.00 sys=0.00, real=0.00 secs] 2.269: [CMS-concurrent-reset-start] 2.269: [CMS-concurrent-reset: 0.001/0.001 secs] [Times: user=0.00 sys=0.00, real=0.00 secs]
  • 24. Disadvantage of non-compactingCode static int alloc_1MB = 1024 * 1024 * 1; public static void main(String[] args) throws Exception { //UseConcMarkSweepGC byte[] bytes10 = alloc(); alloc(); byte[] bytes12 = alloc(); alloc(); byte[] bytes14 = alloc(); alloc(); byte[] bytes16 = alloc(); alloc(); byte[] bytes18 = alloc(); alloc(); byte[] bytes20 = alloc(); alloc(); byte[] bytes22 = alloc(); alloc(3); } static int count = 0; private static byte[] alloc() { return alloc(1); } private static byte[] alloc(inti) { count = count + 1 * i ; System.out.println(count + "M"); return new byte[alloc_1MB * i]; }
  • 25. Disadvantage of non-compactingresult of Parallel&ParallelOld -XX:+UseParallelGC -XX:PretenureSizeThreshold=1k -XX:MaxTenuringThreshold=30 -Xms20M -Xmx20M -Xmn10M -XX:+PrintGCDetails -XX:+PrintGCTimeStamps -XX:-PrintTenuringDistribution PSYoungGen total 8960K, used 5336K eden space 7680K, 69% used from space 1280K, 0% used to space 1280K, 0% used PSOldGen total 10240K, used 6598K object space 10240K, 64% used PSPermGen total 16384K, used 4969K object space 16384K, 30% used
  • 26. Disadvantage of non-compactingResult of CMS -XX:+UseConcMarkSweepGC -XX:PretenureSizeThreshold=1k -XX:MaxTenuringThreshold=30 -Xms20M -Xmx20M -Xmn10M -XX:+PrintGCDetails -XX:+PrintGCTimeStamps -XX:-PrintTenuringDistribution Exception in thread "main" java.lang.OutOfMemoryError: Java heap space par new generation total 9216K, used 491K eden space 8192K, 6% used from space 1024K, 0% used to space 1024K, 0% used concurrent mark-sweep generation total 10240K, used 398K concurrent-mark-sweep perm gen total 16384K, used 4947K
  • 27. VM options -XX:MaxGCPauseMillis=n Pause time -XX:GCTimeRatio=99 1 / (1 + n) Throughput -Xmx –Xms -Xmn (=eden+survivor*2) –XX:SurvivorRatio=32 (1:34) Survivor:Eden -XX:MaxPermSize
  • 28. Print gc –XX:+PrintGC –XX:+PrintGCDetails –XX:+PrintGCTimeStamps -verbose:gc [GC 325407K->83000K(776768K), 0.2300771 secs] [GC 325816K->83372K(776768K), 0.2454258 secs] [Full GC 267628K->83769K(776768K), 1.8479984 secs]
  • 29.
  • 30. System.gc() & finalize() Code: public class SerialTest { public static void main(String[] args) throws Exception { new SerialTest(); System.gc(); Thread.sleep(10); System.out.println("123"); } @Override protected void finalize() throws Throwable { System.out.println("heloo================finalize"); } } Result: 0.227: [Full GC (System) TLAB: gc thread: 0x08839400 [id: 5820] ……….. heloo================finalize 123
  • 31. finalize twice GC !!!
  • 32. monitor JVisualVM JConsole JRockit mission control
  • 33. Garbage-First Garbage Collector G1 GC for short Is a new GC that is being introduced in the Java HotSpot VM in JDK 7 also been released in Java SE 6 Update 14. G1 is the long-term replacement for HotSpot's low-latency Concurrent Mark-Sweep GC (widely referred to as CMS).
  • 34. Garbage-First Garbage Collector Parallelism and Concurrency. G1 performs heap compaction there is a single contiguous heap which is split into same-sized regions Young/old generation is a set of potentially non-contiguous regions
  • 35. G1 Collector Heap garbage-first heap total 20480K, used 3491K region size 1024K, 3 young (3072K), 0 survivors (0K) compacting perm gen total 16384K, used 4967K the space 16384K, 30% used No shared spaces configured.
  • 36. G1 Collector RS: regon set 0.634: [GC pause (young), 0.00846287 secs] [Parallel Time: 8.3 ms] [GC Worker Start Time (ms): 633.9 634.3] [Update RS (ms): 0.0 0.0 Avg: 0.0, Min: 0.0, Max: 0.0] [Processed Buffers : 0 5 Sum: 5, Avg: 2, Min: 0, Max: 5] [Ext Root Scanning (ms): 3.6 3.3 Avg: 3.5, Min: 3.3, Max: 3.6] [Mark Stack Scanning (ms): 0.0 0.0 Avg: 0.0, Min: 0.0, Max: 0.0] [Scan RS (ms): 0.0 0.0 Avg: 0.0, Min: 0.0, Max: 0.0] [Object Copy (ms): 3.8 3.6 Avg: 3.7, Min: 3.6, Max: 3.8] [Termination (ms): 0.0 0.0 Avg: 0.0, Min: 0.0, Max: 0.0] [Termination Attempts : 1 1 Sum: 2, Avg: 1, Min: 1, Max: 1] [GC Worker End Time (ms): 641.3 641.3] [Other: 1.1 ms] [Clear CT: 0.0 ms] [Other: 0.2 ms] [Choose CSet: 0.0 ms] [ 2868K->1763K(20M)] [Times: user=0.00 sys=0.00, real=0.00 secs]
  • 38. references http://java.sun.com/products/hotspot/whitepaper.html http://www.oracle.com/technetwork/java/javase/tech/vmoptions-jsp-140102.html http://blogs.oracle.com/watt/resource/jvm-options-list.html http://www.iteye.com/topic/802638 http://blog.csdn.net/calvinxiu/archive/2007/05/18/1614473.aspx http://unixboy.iteye.com/blog/174173 http://java.sun.com/performance/reference/whitepapers/tuning.html