SlideShare une entreprise Scribd logo
1  sur  57
Télécharger pour lire hors ligne
Understanding JVM
Aparna Chaudhary

Friday, October 4, 13
VM
Memory

What’s inside my VM?
Friday, October 4, 13
VM
Memory

Guest OS Memory

What’s inside my VM?
Friday, October 4, 13
JVM Memory
VM
Memory

Guest OS Memory

What’s inside my VM?
Friday, October 4, 13
JVM Memory
VM
Memory

ize

ermS
XX:MaxP
-

PermGen

Guest OS Memory

What’s inside my VM?
Friday, October 4, 13
JVM Memory
VM
Memory

read
S Per Th
-XS
ize

ermS
XX:MaxP
-

Stack

PermGen

Guest OS Memory

What’s inside my VM?
Friday, October 4, 13
HEAP

JVM Memory
VM
Memory

read
S Per Th
-XS
ize

ermS
XX:MaxP
-

Stack

PermGen

Guest OS Memory

What’s inside my VM?
Friday, October 4, 13
HEAP
Initial

-Xms

JVM Memory
VM
Memory

read
S Per Th
-XS
ize

ermS
XX:MaxP
-

Stack

PermGen

Guest OS Memory

What’s inside my VM?
Friday, October 4, 13
-Xmx
HEAP
Initial

-Xms

JVM Memory
VM
Memory

read
S Per Th
-XS
ize

ermS
XX:MaxP
-

Stack

PermGen

Guest OS Memory

What’s inside my VM?
Friday, October 4, 13
OutOfMemoryError
Exception in thread "main": java.lang.OutOfMemoryError:
Java heap space
Exception in thread "main": java.lang.OutOfMemoryError:
PermGen space
Exception in thread "main": java.lang.OutOfMemoryError:
GC overhead limit exceeded
Exception in thread "main": java.lang.OutOfMemoryError:
Unable to create new native thread
and more...

Friday, October 4, 13
OutOfMemoryError

Exception in thread "main":
java.lang.OutOfMemoryError: PermGen Space

Friday, October 4, 13
Perm Gen Space

Used for Storing the JVM’s internal
representation of Java Classes

Friday, October 4, 13
Object

described by

references

Class

references

loaded by

Classl
oader

Life of a class
Friday, October 4, 13
Object

described by

references

Class
references
loaded by
references

Classl
oader

Life of a class
Friday, October 4, 13
references
Object

references

Object

Class
Class

references

references

Classloader1
Classloader2

Life of a class
Friday, October 4, 13
references
Object

references

Object

Class
Class

references

references
Class
Classloader1

Class

Class Class

Class

Class

Class

Class

Classloader2
Class

Class
Class

Class
Class

Class

Class Class
Class
Class

Class
Class
Class

Class
Class

Class

Class

Class

Class
Class

Life of a class
Friday, October 4, 13
references
Object

references

Object

Class
Class

references

references
Class
Classloader1

Class

Class Class

Class

Class

Class

Class

Classloader2
Class

Class
Class

Class
Class

Class

Class Class
Class
Class

Class
Class
Class

Class
Class

Class

Class

Class

Class
Class

Life of a class
Friday, October 4, 13
OOM - PermGen

This occurs when JVM wants to load new class
definitions; but there is not enough space in
PermGen space

Friday, October 4, 13
OOM - PermGen
Symptom
At server startup
Cause
Bigger PermGen footprint
Resolution
Increase PermGen capacity -XX:MaxPermSize

Friday, October 4, 13
OOM - PermGen
Symptom
PermGen space increases gradually
Cause
Possible classloader leak
Resolution
Investigate any third party API you are using
for any potential class loader leak defect

Friday, October 4, 13
OOM - PermGen
Symptom
OOM after deploy-redeploy cycles
Cause
Possible classloader leak in the App Server
Resolution
Someone should fix it for you. Hmm..where is
EAP?

Friday, October 4, 13
OutOfMemoryError

Exception in thread "main":
java.lang.OutOfMemoryError: GC overhead
limit exceeded

Friday, October 4, 13
OOM - GC overhead
limit exceeded
Policy to allow the VM to detect potential
OutOfMemoryError conditions earlier and before
it runs out of Java Heap space.
Can be turned off -XX:-UseGCOverheadLimit
But don’t!

Friday, October 4, 13
OOM - GC overhead
limit exceeded
When is this error triggered?

✓Too
✓Too

Friday, October 4, 13

many Full GC iterations
much time spent in GC
OutOfMemoryError

Exception in thread "main":
java.lang.OutOfMemoryError: Unable to
create new native thread

Friday, October 4, 13
OOM - Unable to create
new native thread
JVM is asking a new thread from the OS and
the underlying OS cannot allocate a new
thread anymore.

Friday, October 4, 13
Why?
-Xmx
HEAP
Initial

-Xms

JVM Memory

d

Stack

ize

VM
Memory

PermGen

Threa
-XSS Per
ermS
-XX:MaxP

Guest OS Memory

Friday, October 4, 13

not eno
ugh
stack
space
OOM - Unable to create
new native thread
✓ Check ulimit - process limit
✓ Consider using thread-pools
✓ Reduce heap space or perform

Friday, October 4, 13

vertical scaling
OutOfMemoryError

Exception in thread "main":
java.lang.OutOfMemoryError: Java heap
space

Friday, October 4, 13
JVM Heap Structure
Survivor
Space
Eden

S0

S1

Young
Generation

Friday, October 4, 13

Tenured

Old
Generation
Object Allocation

Eden
From

To
Survivor Spaces

Young Gen = Eden + Survivor Spaces
Friday, October 4, 13
Object Allocation
are allocated in Eden

Just allocated

Eden
From

To
Survivor Spaces

Young Gen = Eden + Survivor Spaces
Friday, October 4, 13
Filling up Eden Space

Eden
From

To
Survivor Spaces
Friday, October 4, 13
Filling up Eden Space
are allocated in Eden

Just allocated

Eden
From

To
Survivor Spaces
Friday, October 4, 13
Minor GC - Copy referenced
objects

Eden
From

To
Survivor Spaces

Unreferenced

Referenced
Friday, October 4, 13
Minor GC - Copy referenced
objects

Eden
From

To
Survivor Spaces

Unreferenced

Referenced
Friday, October 4, 13
Minor GC - Copy referenced
objects

Eden
From

To
Survivor Spaces

Unreferenced

Referenced
Friday, October 4, 13
Minor GC - Copy referenced
objects

Eden

To

1

1

1

1

Survivor Spaces

From

Unreferenced

Referenced
Friday, October 4, 13
Next Minor GC - Object Aging

Eden

From

1

1

1

1

Survivor Spaces

To

Unreferenced

Referenced
Friday, October 4, 13
Next Minor GC - Object Aging

Eden

From

1

1

1

1

Survivor Spaces

To

Unreferenced

Referenced
Friday, October 4, 13
Next Minor GC - Object Aging

Eden

From

1

1

Survivor Spaces

To

Unreferenced

Referenced
Friday, October 4, 13
Next Minor GC - Object Aging

Eden

From

1

2

Survivor Spaces

To

Unreferenced

Referenced
Friday, October 4, 13
Next Minor GC - Object Aging

Eden

From

2 2

Survivor Spaces

To

Unreferenced

Referenced
Friday, October 4, 13
Next Minor GC - Object Aging

Eden

From

2 2 1

Survivor Spaces

To

Unreferenced

Referenced
Friday, October 4, 13
Next Minor GC - Object Aging

Eden

From

2 2 1

Survivor Spaces

1

To

Unreferenced

Referenced
Friday, October 4, 13
Next Minor GC - Additional
Aging

Eden

To

2 2 1

Survivor Spaces

1

From

Unreferenced

Referenced
Friday, October 4, 13
Next Minor GC - Additional
Aging

Eden

To

2

1

Survivor Spaces

From

Unreferenced

Referenced
Friday, October 4, 13
Next Minor GC - Additional
Aging

Eden

To

1

2 3

Survivor Spaces

From

Unreferenced

Referenced
Friday, October 4, 13
Next Minor GC - Promotion
Eden

From

1

14

1

2

3

To

Survivor Spaces
Tenured

Unreferenced

Referenced
Friday, October 4, 13
Next Minor GC - Promotion
Eden

From

1

1

2

3

To

Survivor Spaces
Tenured

14

Unreferenced

Referenced
Friday, October 4, 13
Major GC
Eden

From

1

1

1

2

3

To

Survivor Spaces
Tenured

Unreferenced

Referenced
Friday, October 4, 13
Major GC
Eden

From

1

1

1

2

3

To

Survivor Spaces
Tenured

Unreferenced

Referenced
Friday, October 4, 13
Warning!
This knowledge does not make us JVM
experts!
Always focus first on software before
hacking JVM.

Friday, October 4, 13
JVM Diagnosis
jmap
jhat

Friday, October 4, 13
Class Histogram
jmap -F -histo `pgrep java`

Make it a practice to proactively use this
command after a load test and endurance test.

Friday, October 4, 13
Heap Dump
jmap [ option ] <pid>
jmap -F -dump:live,format=b,file=/
var/opt/jboss-as/tmp/io/
heapdump.hprof `pgrep java`
http://docs.oracle.com/javase/6/docs/technotes/tools/share/jmap.html

Friday, October 4, 13
What Next?
Demo
VisualVM
Eclipse Memory Analyzer Tool
Other tools and commands
GC Algorithms (Optional)

Friday, October 4, 13

Contenu connexe

En vedette (20)

Architecture diagram of jvm
Architecture diagram of jvmArchitecture diagram of jvm
Architecture diagram of jvm
 
Java virtual machine
Java virtual machineJava virtual machine
Java virtual machine
 
Jvm Architecture
Jvm ArchitectureJvm Architecture
Jvm Architecture
 
Inside the jvm
Inside the jvmInside the jvm
Inside the jvm
 
Java byte code & virtual machine
Java byte code & virtual machineJava byte code & virtual machine
Java byte code & virtual machine
 
Basics of JVM Tuning
Basics of JVM TuningBasics of JVM Tuning
Basics of JVM Tuning
 
What's Inside a JVM?
What's Inside a JVM?What's Inside a JVM?
What's Inside a JVM?
 
Java virtual machine
Java virtual machineJava virtual machine
Java virtual machine
 
Java Multi Thead Programming
Java Multi Thead ProgrammingJava Multi Thead Programming
Java Multi Thead Programming
 
Threads concept in java
Threads concept in javaThreads concept in java
Threads concept in java
 
QSpiders - Variable Length-Subnet-Masks
QSpiders - Variable Length-Subnet-MasksQSpiders - Variable Length-Subnet-Masks
QSpiders - Variable Length-Subnet-Masks
 
Java And Multithreading
Java And MultithreadingJava And Multithreading
Java And Multithreading
 
Threads in JAVA
Threads in JAVAThreads in JAVA
Threads in JAVA
 
Analyzing awr report
Analyzing awr reportAnalyzing awr report
Analyzing awr report
 
Multithread Programing in Java
Multithread Programing in JavaMultithread Programing in Java
Multithread Programing in Java
 
Multithreading In Java
Multithreading In JavaMultithreading In Java
Multithreading In Java
 
Multithreading in java
Multithreading in javaMultithreading in java
Multithreading in java
 
Lesson 2: Subnetting basics
Lesson 2: Subnetting basicsLesson 2: Subnetting basics
Lesson 2: Subnetting basics
 
Subnetting (FLSM & VLSM) with examples
Subnetting (FLSM & VLSM) with examplesSubnetting (FLSM & VLSM) with examples
Subnetting (FLSM & VLSM) with examples
 
Subnetting
SubnettingSubnetting
Subnetting
 

Dernier

Beyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry InnovationBeyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry InnovationSafe Software
 
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024BookNet Canada
 
DevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platformsDevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platformsSergiu Bodiu
 
The Future of Software Development - Devin AI Innovative Approach.pdf
The Future of Software Development - Devin AI Innovative Approach.pdfThe Future of Software Development - Devin AI Innovative Approach.pdf
The Future of Software Development - Devin AI Innovative Approach.pdfSeasiaInfotech2
 
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek SchlawackFwdays
 
Human Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR SystemsHuman Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR SystemsMark Billinghurst
 
Install Stable Diffusion in windows machine
Install Stable Diffusion in windows machineInstall Stable Diffusion in windows machine
Install Stable Diffusion in windows machinePadma Pradeep
 
"Federated learning: out of reach no matter how close",Oleksandr Lapshyn
"Federated learning: out of reach no matter how close",Oleksandr Lapshyn"Federated learning: out of reach no matter how close",Oleksandr Lapshyn
"Federated learning: out of reach no matter how close",Oleksandr LapshynFwdays
 
Artificial intelligence in cctv survelliance.pptx
Artificial intelligence in cctv survelliance.pptxArtificial intelligence in cctv survelliance.pptx
Artificial intelligence in cctv survelliance.pptxhariprasad279825
 
Scanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL CertsScanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL CertsRizwan Syed
 
WordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your BrandWordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your Brandgvaughan
 
Commit 2024 - Secret Management made easy
Commit 2024 - Secret Management made easyCommit 2024 - Secret Management made easy
Commit 2024 - Secret Management made easyAlfredo García Lavilla
 
AI as an Interface for Commercial Buildings
AI as an Interface for Commercial BuildingsAI as an Interface for Commercial Buildings
AI as an Interface for Commercial BuildingsMemoori
 
Designing IA for AI - Information Architecture Conference 2024
Designing IA for AI - Information Architecture Conference 2024Designing IA for AI - Information Architecture Conference 2024
Designing IA for AI - Information Architecture Conference 2024Enterprise Knowledge
 
Story boards and shot lists for my a level piece
Story boards and shot lists for my a level pieceStory boards and shot lists for my a level piece
Story boards and shot lists for my a level piececharlottematthew16
 
Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024Scott Keck-Warren
 
Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 365Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 3652toLead Limited
 
Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!Commit University
 
"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr Bagan"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr BaganFwdays
 

Dernier (20)

Beyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry InnovationBeyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
 
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
 
DevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platformsDevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platforms
 
The Future of Software Development - Devin AI Innovative Approach.pdf
The Future of Software Development - Devin AI Innovative Approach.pdfThe Future of Software Development - Devin AI Innovative Approach.pdf
The Future of Software Development - Devin AI Innovative Approach.pdf
 
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
 
Human Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR SystemsHuman Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR Systems
 
Install Stable Diffusion in windows machine
Install Stable Diffusion in windows machineInstall Stable Diffusion in windows machine
Install Stable Diffusion in windows machine
 
"Federated learning: out of reach no matter how close",Oleksandr Lapshyn
"Federated learning: out of reach no matter how close",Oleksandr Lapshyn"Federated learning: out of reach no matter how close",Oleksandr Lapshyn
"Federated learning: out of reach no matter how close",Oleksandr Lapshyn
 
E-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptx
E-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptxE-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptx
E-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptx
 
Artificial intelligence in cctv survelliance.pptx
Artificial intelligence in cctv survelliance.pptxArtificial intelligence in cctv survelliance.pptx
Artificial intelligence in cctv survelliance.pptx
 
Scanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL CertsScanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL Certs
 
WordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your BrandWordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your Brand
 
Commit 2024 - Secret Management made easy
Commit 2024 - Secret Management made easyCommit 2024 - Secret Management made easy
Commit 2024 - Secret Management made easy
 
AI as an Interface for Commercial Buildings
AI as an Interface for Commercial BuildingsAI as an Interface for Commercial Buildings
AI as an Interface for Commercial Buildings
 
Designing IA for AI - Information Architecture Conference 2024
Designing IA for AI - Information Architecture Conference 2024Designing IA for AI - Information Architecture Conference 2024
Designing IA for AI - Information Architecture Conference 2024
 
Story boards and shot lists for my a level piece
Story boards and shot lists for my a level pieceStory boards and shot lists for my a level piece
Story boards and shot lists for my a level piece
 
Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024
 
Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 365Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 365
 
Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!
 
"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr Bagan"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr Bagan
 

Understanding JVM