SlideShare a Scribd company logo
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

More Related Content

Viewers also liked

Viewers also liked (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
 

Recently uploaded

Unsubscribed: Combat Subscription Fatigue With a Membership Mentality by Head...
Unsubscribed: Combat Subscription Fatigue With a Membership Mentality by Head...Unsubscribed: Combat Subscription Fatigue With a Membership Mentality by Head...
Unsubscribed: Combat Subscription Fatigue With a Membership Mentality by Head...Product School
 
From Daily Decisions to Bottom Line: Connecting Product Work to Revenue by VP...
From Daily Decisions to Bottom Line: Connecting Product Work to Revenue by VP...From Daily Decisions to Bottom Line: Connecting Product Work to Revenue by VP...
From Daily Decisions to Bottom Line: Connecting Product Work to Revenue by VP...Product School
 
10 Differences between Sales Cloud and CPQ, Blanka Doktorová
10 Differences between Sales Cloud and CPQ, Blanka Doktorová10 Differences between Sales Cloud and CPQ, Blanka Doktorová
10 Differences between Sales Cloud and CPQ, Blanka DoktorováCzechDreamin
 
JMeter webinar - integration with InfluxDB and Grafana
JMeter webinar - integration with InfluxDB and GrafanaJMeter webinar - integration with InfluxDB and Grafana
JMeter webinar - integration with InfluxDB and GrafanaRTTS
 
How world-class product teams are winning in the AI era by CEO and Founder, P...
How world-class product teams are winning in the AI era by CEO and Founder, P...How world-class product teams are winning in the AI era by CEO and Founder, P...
How world-class product teams are winning in the AI era by CEO and Founder, P...Product School
 
De-mystifying Zero to One: Design Informed Techniques for Greenfield Innovati...
De-mystifying Zero to One: Design Informed Techniques for Greenfield Innovati...De-mystifying Zero to One: Design Informed Techniques for Greenfield Innovati...
De-mystifying Zero to One: Design Informed Techniques for Greenfield Innovati...Product School
 
Key Trends Shaping the Future of Infrastructure.pdf
Key Trends Shaping the Future of Infrastructure.pdfKey Trends Shaping the Future of Infrastructure.pdf
Key Trends Shaping the Future of Infrastructure.pdfCheryl Hung
 
Unpacking Value Delivery - Agile Oxford Meetup - May 2024.pptx
Unpacking Value Delivery - Agile Oxford Meetup - May 2024.pptxUnpacking Value Delivery - Agile Oxford Meetup - May 2024.pptx
Unpacking Value Delivery - Agile Oxford Meetup - May 2024.pptxDavid Michel
 
Integrating Telephony Systems with Salesforce: Insights and Considerations, B...
Integrating Telephony Systems with Salesforce: Insights and Considerations, B...Integrating Telephony Systems with Salesforce: Insights and Considerations, B...
Integrating Telephony Systems with Salesforce: Insights and Considerations, B...CzechDreamin
 
Salesforce Adoption – Metrics, Methods, and Motivation, Antone Kom
Salesforce Adoption – Metrics, Methods, and Motivation, Antone KomSalesforce Adoption – Metrics, Methods, and Motivation, Antone Kom
Salesforce Adoption – Metrics, Methods, and Motivation, Antone KomCzechDreamin
 
Mission to Decommission: Importance of Decommissioning Products to Increase E...
Mission to Decommission: Importance of Decommissioning Products to Increase E...Mission to Decommission: Importance of Decommissioning Products to Increase E...
Mission to Decommission: Importance of Decommissioning Products to Increase E...Product School
 
IoT Analytics Company Presentation May 2024
IoT Analytics Company Presentation May 2024IoT Analytics Company Presentation May 2024
IoT Analytics Company Presentation May 2024IoTAnalytics
 
To Graph or Not to Graph Knowledge Graph Architectures and LLMs
To Graph or Not to Graph Knowledge Graph Architectures and LLMsTo Graph or Not to Graph Knowledge Graph Architectures and LLMs
To Graph or Not to Graph Knowledge Graph Architectures and LLMsPaul Groth
 
Essentials of Automations: Optimizing FME Workflows with Parameters
Essentials of Automations: Optimizing FME Workflows with ParametersEssentials of Automations: Optimizing FME Workflows with Parameters
Essentials of Automations: Optimizing FME Workflows with ParametersSafe Software
 
Software Delivery At the Speed of AI: Inflectra Invests In AI-Powered Quality
Software Delivery At the Speed of AI: Inflectra Invests In AI-Powered QualitySoftware Delivery At the Speed of AI: Inflectra Invests In AI-Powered Quality
Software Delivery At the Speed of AI: Inflectra Invests In AI-Powered QualityInflectra
 
Behind the Scenes From the Manager's Chair: Decoding the Secrets of Successfu...
Behind the Scenes From the Manager's Chair: Decoding the Secrets of Successfu...Behind the Scenes From the Manager's Chair: Decoding the Secrets of Successfu...
Behind the Scenes From the Manager's Chair: Decoding the Secrets of Successfu...CzechDreamin
 
SOQL 201 for Admins & Developers: Slice & Dice Your Org’s Data With Aggregate...
SOQL 201 for Admins & Developers: Slice & Dice Your Org’s Data With Aggregate...SOQL 201 for Admins & Developers: Slice & Dice Your Org’s Data With Aggregate...
SOQL 201 for Admins & Developers: Slice & Dice Your Org’s Data With Aggregate...CzechDreamin
 
"Impact of front-end architecture on development cost", Viktor Turskyi
"Impact of front-end architecture on development cost", Viktor Turskyi"Impact of front-end architecture on development cost", Viktor Turskyi
"Impact of front-end architecture on development cost", Viktor TurskyiFwdays
 
Knowledge engineering: from people to machines and back
Knowledge engineering: from people to machines and backKnowledge engineering: from people to machines and back
Knowledge engineering: from people to machines and backElena Simperl
 
Speed Wins: From Kafka to APIs in Minutes
Speed Wins: From Kafka to APIs in MinutesSpeed Wins: From Kafka to APIs in Minutes
Speed Wins: From Kafka to APIs in Minutesconfluent
 

Recently uploaded (20)

Unsubscribed: Combat Subscription Fatigue With a Membership Mentality by Head...
Unsubscribed: Combat Subscription Fatigue With a Membership Mentality by Head...Unsubscribed: Combat Subscription Fatigue With a Membership Mentality by Head...
Unsubscribed: Combat Subscription Fatigue With a Membership Mentality by Head...
 
From Daily Decisions to Bottom Line: Connecting Product Work to Revenue by VP...
From Daily Decisions to Bottom Line: Connecting Product Work to Revenue by VP...From Daily Decisions to Bottom Line: Connecting Product Work to Revenue by VP...
From Daily Decisions to Bottom Line: Connecting Product Work to Revenue by VP...
 
10 Differences between Sales Cloud and CPQ, Blanka Doktorová
10 Differences between Sales Cloud and CPQ, Blanka Doktorová10 Differences between Sales Cloud and CPQ, Blanka Doktorová
10 Differences between Sales Cloud and CPQ, Blanka Doktorová
 
JMeter webinar - integration with InfluxDB and Grafana
JMeter webinar - integration with InfluxDB and GrafanaJMeter webinar - integration with InfluxDB and Grafana
JMeter webinar - integration with InfluxDB and Grafana
 
How world-class product teams are winning in the AI era by CEO and Founder, P...
How world-class product teams are winning in the AI era by CEO and Founder, P...How world-class product teams are winning in the AI era by CEO and Founder, P...
How world-class product teams are winning in the AI era by CEO and Founder, P...
 
De-mystifying Zero to One: Design Informed Techniques for Greenfield Innovati...
De-mystifying Zero to One: Design Informed Techniques for Greenfield Innovati...De-mystifying Zero to One: Design Informed Techniques for Greenfield Innovati...
De-mystifying Zero to One: Design Informed Techniques for Greenfield Innovati...
 
Key Trends Shaping the Future of Infrastructure.pdf
Key Trends Shaping the Future of Infrastructure.pdfKey Trends Shaping the Future of Infrastructure.pdf
Key Trends Shaping the Future of Infrastructure.pdf
 
Unpacking Value Delivery - Agile Oxford Meetup - May 2024.pptx
Unpacking Value Delivery - Agile Oxford Meetup - May 2024.pptxUnpacking Value Delivery - Agile Oxford Meetup - May 2024.pptx
Unpacking Value Delivery - Agile Oxford Meetup - May 2024.pptx
 
Integrating Telephony Systems with Salesforce: Insights and Considerations, B...
Integrating Telephony Systems with Salesforce: Insights and Considerations, B...Integrating Telephony Systems with Salesforce: Insights and Considerations, B...
Integrating Telephony Systems with Salesforce: Insights and Considerations, B...
 
Salesforce Adoption – Metrics, Methods, and Motivation, Antone Kom
Salesforce Adoption – Metrics, Methods, and Motivation, Antone KomSalesforce Adoption – Metrics, Methods, and Motivation, Antone Kom
Salesforce Adoption – Metrics, Methods, and Motivation, Antone Kom
 
Mission to Decommission: Importance of Decommissioning Products to Increase E...
Mission to Decommission: Importance of Decommissioning Products to Increase E...Mission to Decommission: Importance of Decommissioning Products to Increase E...
Mission to Decommission: Importance of Decommissioning Products to Increase E...
 
IoT Analytics Company Presentation May 2024
IoT Analytics Company Presentation May 2024IoT Analytics Company Presentation May 2024
IoT Analytics Company Presentation May 2024
 
To Graph or Not to Graph Knowledge Graph Architectures and LLMs
To Graph or Not to Graph Knowledge Graph Architectures and LLMsTo Graph or Not to Graph Knowledge Graph Architectures and LLMs
To Graph or Not to Graph Knowledge Graph Architectures and LLMs
 
Essentials of Automations: Optimizing FME Workflows with Parameters
Essentials of Automations: Optimizing FME Workflows with ParametersEssentials of Automations: Optimizing FME Workflows with Parameters
Essentials of Automations: Optimizing FME Workflows with Parameters
 
Software Delivery At the Speed of AI: Inflectra Invests In AI-Powered Quality
Software Delivery At the Speed of AI: Inflectra Invests In AI-Powered QualitySoftware Delivery At the Speed of AI: Inflectra Invests In AI-Powered Quality
Software Delivery At the Speed of AI: Inflectra Invests In AI-Powered Quality
 
Behind the Scenes From the Manager's Chair: Decoding the Secrets of Successfu...
Behind the Scenes From the Manager's Chair: Decoding the Secrets of Successfu...Behind the Scenes From the Manager's Chair: Decoding the Secrets of Successfu...
Behind the Scenes From the Manager's Chair: Decoding the Secrets of Successfu...
 
SOQL 201 for Admins & Developers: Slice & Dice Your Org’s Data With Aggregate...
SOQL 201 for Admins & Developers: Slice & Dice Your Org’s Data With Aggregate...SOQL 201 for Admins & Developers: Slice & Dice Your Org’s Data With Aggregate...
SOQL 201 for Admins & Developers: Slice & Dice Your Org’s Data With Aggregate...
 
"Impact of front-end architecture on development cost", Viktor Turskyi
"Impact of front-end architecture on development cost", Viktor Turskyi"Impact of front-end architecture on development cost", Viktor Turskyi
"Impact of front-end architecture on development cost", Viktor Turskyi
 
Knowledge engineering: from people to machines and back
Knowledge engineering: from people to machines and backKnowledge engineering: from people to machines and back
Knowledge engineering: from people to machines and back
 
Speed Wins: From Kafka to APIs in Minutes
Speed Wins: From Kafka to APIs in MinutesSpeed Wins: From Kafka to APIs in Minutes
Speed Wins: From Kafka to APIs in Minutes
 

Understanding JVM