SlideShare a Scribd company logo
JVM
A quick view about Java Virtual Machine
Once upon a time...
Java as lang and Platform
Java is also a Programming Language and a Platform. We’ll speak about Java
as Platform in this presentation.
As Language, Java is pretty nice despite of verbosity.
Why use a VM?
Once a program is created, it must be compiled
for each OS. If you want your program for Mac,
compile for Mac. Windows? Same. Linux?
Same…
Furthermore, memory allocation needed be done
manually.
Using JVM, all responsability to handle memory
or run in many OSs is delegated to it.
The JVM abstracts not only the hardware layer
but also the communication with the Operating
System.
How does it work?
Hello.java Hello.class
Javac
JRE
JRE
Java Bytecode
Compiled from "Hello.java"
class HelloJava {
HelloJava();
public static void
main(java.lang.String[]);
}
class HelloJava {
public static void main(String[] args) {
System.out.println("Hello World!");
}
}
Kotlin Bytecode
Compiled from "Hello.kt"
public final class Hello {
public Hello();
}
class Hello
fun main(args: Array<String>) {
println("Hello World!")
}
Heap
Heap
The JVM has a heap, a runtime data
area from which memory for all
class instances and arrays are
allocated. Is shared by all Threads.
It is where the Objects born, grow
and die. Example:
$ java -Xms128m -Xmx512m -jar
homeboy-1.0-SNAPSHOT.jar
To set the maximum Java heap size
we use the option -Xmx.
to set the initial Java heap size
-Xms.
Heap
Eden Survivor Old
PermGen
PermGen
The JVM also allocate objects apart the heap, at
Permgen.
This area stores class related data from class
definitions, structures, methods, field, and
constants.
PermGen
Despite standing in his name, the memory space
from PermGen is also collected in a FullGC.
IT can cause java.lang.OutOfMemoryError:
PermGen space if it runs out if space. This
happens normally when the exaggerated
amount of classes that are loaded into memory.
“PermGen is Dead. Long live PermGen”
-JDK 8 HotSpot JVM
Metaspace
Metaspace is a new memory space - since java
8 - replacing Permgen.
What makes it different of Permgen?
Instead of allocate memory inside JVM, it
allocates in the OS memory.
Garbage Collector
Garbage Collector - a quick view on Heap (again)
Eden Survivor Old
Heap
Garbage collector - Mark and sweep
On the first cycle, this algorithm marks all accessible objects in all
current threads.
On the second cycle Sweeps all objects which were not marked in
the last cycle.
The Mark and Sweep is outdated, but it was a great learning to deal
with non-referenced objects.
Garbage collector - generational copying
● The idea of this algorithm is to divide objects into generations, young and old generation.
● The new generation is usually smaller than the old one (1/3 of the old).
● The GC scans the younger generation, which does not paralyze the JVM.
● Who "survives" is copied to the Old generation and the space of the Young Generation is
made available again.
● The discard does not remove from the memory yet, it just marks the memory as
available.
● Although it is costly to copy an object to the old generation to another part of the Heap,
few survive, so the cost is low.
● Also, copying fewer objects is still "cheaper" than removing objects.
● When Young is crowded, a minor collect runs. At this point objects are sent to the old
generation.
Garbage collector - generational copying
● Depending on the JVM, large objects have the behavior of already being copied to the Old
generation;
● Generational copying copies the objects to the next in a clustered fashion, optimizing
memory and ensuring that there is no memory fragmentation.
● It is possible to increase the proportion of the space allocated to Young Generation by
the option -XX: NewRatio = 1 (50%). By default, 2/3 will be old and 1/3 will be young; by
changing the value to 1, we will have 1/2 for each area.
Garbage collector - Garbage First (G1)
Although it is considered a generational
algorithm, it does not separates the heap in
two generations, but in many small regions.
Dynamically, the G1 chooses some regions
to be collected (which gives the logical
sense of those regions to be a young gen).
JIT Compiler
JIT Compiler (Just in time) or slow is your granny
JIT compiles Java code in Runtime to improve the application
performance.
But I said before that JVM read Bytecode and runs it in a VM,
right?
The first JVMs were the same, but with each version, the JVM is
increased and brought this new feature to the VM.
JIT Compiler (Just in time)
JIT has the ability to do optimization according to the use of the
program and the current conditions. The so-called hotspots.
What JIT does behind the scene?
It compiles for native platform and runs native code optimizing
the application running.
Thanks =)
By João Santana
joaosantana.ti@gmail.com
github.com/jonss

More Related Content

What's hot (7)

PPTX
Java JVM
KadarkaraiSelvam
 
PPTX
Memory leak
Anandraj Kulkarni
 
PPTX
Java Virtual Machine
profbnk
 
PDF
jLove 2020 - Micronaut and graalvm: The power of AoT
Iván López Martín
 
PPTX
Java 2
KadarkaraiSelvam
 
PDF
Ola Bini Evolving The Java Platform
deimos
 
PPT
Inside the JVM
Jim Jagielski
 
Memory leak
Anandraj Kulkarni
 
Java Virtual Machine
profbnk
 
jLove 2020 - Micronaut and graalvm: The power of AoT
Iván López Martín
 
Ola Bini Evolving The Java Platform
deimos
 
Inside the JVM
Jim Jagielski
 

Similar to A quick view about Java Virtual Machine (20)

PDF
Jvm is-your-friend
ColdFusionConference
 
PDF
The JVM is your friend
Kai Koenig
 
PDF
Performance Tuning - Understanding Garbage Collection
Haribabu Nandyal Padmanaban
 
PPT
An Introduction to JVM Internals and Garbage Collection in Java
Abhishek Asthana
 
PPTX
Advanced Java Features: A Deep Dive into JVM, JIT, and GC
Naresh IT
 
PDF
Advanced Java Features: A Deep Dive into JVM, JIT, and GC
Naresh IT
 
ODP
Garbage collection
Mudit Gupta
 
PDF
Владимир Иванов. Java 8 и JVM: что нового в HotSpot
Volha Banadyseva
 
PDF
[BGOUG] Java GC - Friend or Foe
SAP HANA Cloud Platform
 
PPTX
HotSpot JVM Tuning
Gilad Garon
 
PPTX
Garbage collector (gc)
Basant Kumar
 
ODP
Quick introduction to Java Garbage Collector (JVM GC)
Marcos García
 
PDF
JVM Under the Hood
Serkan Özal
 
PDF
Taming The JVM
Matthew McCullough
 
PPTX
Memory Management: What You Need to Know When Moving to Java 8
AppDynamics
 
PDF
An Introduction to Java Compiler and Runtime
Omar Bashir
 
PPTX
Вячеслав Блинов «Java Garbage Collection: A Performance Impact»
Anna Shymchenko
 
PPTX
Вячеслав Блинов «Java Garbage Collection: A Performance Impact»
Anna Shymchenko
 
PDF
"What's New in HotSpot JVM 8" @ JPoint 2014, Moscow, Russia
Vladimir Ivanov
 
PDF
Java Garbage Collection - How it works
Mindfire Solutions
 
Jvm is-your-friend
ColdFusionConference
 
The JVM is your friend
Kai Koenig
 
Performance Tuning - Understanding Garbage Collection
Haribabu Nandyal Padmanaban
 
An Introduction to JVM Internals and Garbage Collection in Java
Abhishek Asthana
 
Advanced Java Features: A Deep Dive into JVM, JIT, and GC
Naresh IT
 
Advanced Java Features: A Deep Dive into JVM, JIT, and GC
Naresh IT
 
Garbage collection
Mudit Gupta
 
Владимир Иванов. Java 8 и JVM: что нового в HotSpot
Volha Banadyseva
 
[BGOUG] Java GC - Friend or Foe
SAP HANA Cloud Platform
 
HotSpot JVM Tuning
Gilad Garon
 
Garbage collector (gc)
Basant Kumar
 
Quick introduction to Java Garbage Collector (JVM GC)
Marcos García
 
JVM Under the Hood
Serkan Özal
 
Taming The JVM
Matthew McCullough
 
Memory Management: What You Need to Know When Moving to Java 8
AppDynamics
 
An Introduction to Java Compiler and Runtime
Omar Bashir
 
Вячеслав Блинов «Java Garbage Collection: A Performance Impact»
Anna Shymchenko
 
Вячеслав Блинов «Java Garbage Collection: A Performance Impact»
Anna Shymchenko
 
"What's New in HotSpot JVM 8" @ JPoint 2014, Moscow, Russia
Vladimir Ivanov
 
Java Garbage Collection - How it works
Mindfire Solutions
 
Ad

Recently uploaded (20)

PDF
From Code to Challenge: Crafting Skill-Based Games That Engage and Reward
aiyshauae
 
PDF
Timothy Rottach - Ramp up on AI Use Cases, from Vector Search to AI Agents wi...
AWS Chicago
 
PDF
Building Real-Time Digital Twins with IBM Maximo & ArcGIS Indoors
Safe Software
 
PDF
Log-Based Anomaly Detection: Enhancing System Reliability with Machine Learning
Mohammed BEKKOUCHE
 
PPTX
Webinar: Introduction to LF Energy EVerest
DanBrown980551
 
PDF
Python basic programing language for automation
DanialHabibi2
 
PDF
July Patch Tuesday
Ivanti
 
PDF
Empower Inclusion Through Accessible Java Applications
Ana-Maria Mihalceanu
 
PPTX
AI Penetration Testing Essentials: A Cybersecurity Guide for 2025
defencerabbit Team
 
PDF
CIFDAQ Market Insights for July 7th 2025
CIFDAQ
 
PDF
NewMind AI - Journal 100 Insights After The 100th Issue
NewMind AI
 
PDF
Reverse Engineering of Security Products: Developing an Advanced Microsoft De...
nwbxhhcyjv
 
PDF
CIFDAQ Weekly Market Wrap for 11th July 2025
CIFDAQ
 
PDF
Exolore The Essential AI Tools in 2025.pdf
Srinivasan M
 
PDF
Newgen 2022-Forrester Newgen TEI_13 05 2022-The-Total-Economic-Impact-Newgen-...
darshakparmar
 
PDF
Presentation - Vibe Coding The Future of Tech
yanuarsinggih1
 
PDF
Blockchain Transactions Explained For Everyone
CIFDAQ
 
PDF
[Newgen] NewgenONE Marvin Brochure 1.pdf
darshakparmar
 
PDF
Bitcoin for Millennials podcast with Bram, Power Laws of Bitcoin
Stephen Perrenod
 
PPTX
Building Search Using OpenSearch: Limitations and Workarounds
Sease
 
From Code to Challenge: Crafting Skill-Based Games That Engage and Reward
aiyshauae
 
Timothy Rottach - Ramp up on AI Use Cases, from Vector Search to AI Agents wi...
AWS Chicago
 
Building Real-Time Digital Twins with IBM Maximo & ArcGIS Indoors
Safe Software
 
Log-Based Anomaly Detection: Enhancing System Reliability with Machine Learning
Mohammed BEKKOUCHE
 
Webinar: Introduction to LF Energy EVerest
DanBrown980551
 
Python basic programing language for automation
DanialHabibi2
 
July Patch Tuesday
Ivanti
 
Empower Inclusion Through Accessible Java Applications
Ana-Maria Mihalceanu
 
AI Penetration Testing Essentials: A Cybersecurity Guide for 2025
defencerabbit Team
 
CIFDAQ Market Insights for July 7th 2025
CIFDAQ
 
NewMind AI - Journal 100 Insights After The 100th Issue
NewMind AI
 
Reverse Engineering of Security Products: Developing an Advanced Microsoft De...
nwbxhhcyjv
 
CIFDAQ Weekly Market Wrap for 11th July 2025
CIFDAQ
 
Exolore The Essential AI Tools in 2025.pdf
Srinivasan M
 
Newgen 2022-Forrester Newgen TEI_13 05 2022-The-Total-Economic-Impact-Newgen-...
darshakparmar
 
Presentation - Vibe Coding The Future of Tech
yanuarsinggih1
 
Blockchain Transactions Explained For Everyone
CIFDAQ
 
[Newgen] NewgenONE Marvin Brochure 1.pdf
darshakparmar
 
Bitcoin for Millennials podcast with Bram, Power Laws of Bitcoin
Stephen Perrenod
 
Building Search Using OpenSearch: Limitations and Workarounds
Sease
 
Ad

A quick view about Java Virtual Machine

  • 1. JVM A quick view about Java Virtual Machine
  • 2. Once upon a time...
  • 3. Java as lang and Platform Java is also a Programming Language and a Platform. We’ll speak about Java as Platform in this presentation. As Language, Java is pretty nice despite of verbosity.
  • 4. Why use a VM? Once a program is created, it must be compiled for each OS. If you want your program for Mac, compile for Mac. Windows? Same. Linux? Same… Furthermore, memory allocation needed be done manually. Using JVM, all responsability to handle memory or run in many OSs is delegated to it. The JVM abstracts not only the hardware layer but also the communication with the Operating System.
  • 5. How does it work? Hello.java Hello.class Javac JRE JRE
  • 6. Java Bytecode Compiled from "Hello.java" class HelloJava { HelloJava(); public static void main(java.lang.String[]); } class HelloJava { public static void main(String[] args) { System.out.println("Hello World!"); } }
  • 7. Kotlin Bytecode Compiled from "Hello.kt" public final class Hello { public Hello(); } class Hello fun main(args: Array<String>) { println("Hello World!") }
  • 9. Heap The JVM has a heap, a runtime data area from which memory for all class instances and arrays are allocated. Is shared by all Threads. It is where the Objects born, grow and die. Example: $ java -Xms128m -Xmx512m -jar homeboy-1.0-SNAPSHOT.jar To set the maximum Java heap size we use the option -Xmx. to set the initial Java heap size -Xms.
  • 12. PermGen The JVM also allocate objects apart the heap, at Permgen. This area stores class related data from class definitions, structures, methods, field, and constants.
  • 13. PermGen Despite standing in his name, the memory space from PermGen is also collected in a FullGC. IT can cause java.lang.OutOfMemoryError: PermGen space if it runs out if space. This happens normally when the exaggerated amount of classes that are loaded into memory.
  • 14. “PermGen is Dead. Long live PermGen” -JDK 8 HotSpot JVM
  • 15. Metaspace Metaspace is a new memory space - since java 8 - replacing Permgen. What makes it different of Permgen? Instead of allocate memory inside JVM, it allocates in the OS memory.
  • 17. Garbage Collector - a quick view on Heap (again) Eden Survivor Old Heap
  • 18. Garbage collector - Mark and sweep On the first cycle, this algorithm marks all accessible objects in all current threads. On the second cycle Sweeps all objects which were not marked in the last cycle. The Mark and Sweep is outdated, but it was a great learning to deal with non-referenced objects.
  • 19. Garbage collector - generational copying ● The idea of this algorithm is to divide objects into generations, young and old generation. ● The new generation is usually smaller than the old one (1/3 of the old). ● The GC scans the younger generation, which does not paralyze the JVM. ● Who "survives" is copied to the Old generation and the space of the Young Generation is made available again. ● The discard does not remove from the memory yet, it just marks the memory as available. ● Although it is costly to copy an object to the old generation to another part of the Heap, few survive, so the cost is low. ● Also, copying fewer objects is still "cheaper" than removing objects. ● When Young is crowded, a minor collect runs. At this point objects are sent to the old generation.
  • 20. Garbage collector - generational copying ● Depending on the JVM, large objects have the behavior of already being copied to the Old generation; ● Generational copying copies the objects to the next in a clustered fashion, optimizing memory and ensuring that there is no memory fragmentation. ● It is possible to increase the proportion of the space allocated to Young Generation by the option -XX: NewRatio = 1 (50%). By default, 2/3 will be old and 1/3 will be young; by changing the value to 1, we will have 1/2 for each area.
  • 21. Garbage collector - Garbage First (G1) Although it is considered a generational algorithm, it does not separates the heap in two generations, but in many small regions. Dynamically, the G1 chooses some regions to be collected (which gives the logical sense of those regions to be a young gen).
  • 23. JIT Compiler (Just in time) or slow is your granny JIT compiles Java code in Runtime to improve the application performance. But I said before that JVM read Bytecode and runs it in a VM, right? The first JVMs were the same, but with each version, the JVM is increased and brought this new feature to the VM.
  • 24. JIT Compiler (Just in time) JIT has the ability to do optimization according to the use of the program and the current conditions. The so-called hotspots. What JIT does behind the scene? It compiles for native platform and runs native code optimizing the application running.
  • 25. Thanks =) By João Santana [email protected] github.com/jonss