Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Memory regions of Java program?

Tags:

java

I haven't deep dive into how Java treats memory when a program is running as I have been in working at application level. I recently had one instance in which I needed to know owing to performance issues of application.

I have been aware of "stack" , "heap" regions of memory and I thought this is the model of a Java program. However, it turns out that it is much more, and beyond that.

For example, I came across terms like: Eden, s0, s1, Old memory and so on. I was never aware of these terminologies prior.

As Java is / have been changing and so may be these terminologies are/aren't relevant as of Java 8.

Can anyone guide where to get this information and under what circumstance we need to know them? Are these part of main memory that is RAM.

like image 208
CuriousMind Avatar asked Aug 31 '26 15:08

CuriousMind


1 Answers

Eden, s0, s1, Old memory and other memory areas exist only in the context of the specific garbage collector implementation e.g. generational collectors like G1 will divide the heap into mentioned areas however non-generational collectors like ZGC will not.

Start by reviewing the main garbage collectors in the JVM:

  • ParNew
  • CMS
  • G1
  • ZGC / Shenandoah / Azul C4

and then try to understand related concepts:

  • Thread-local allocation buffers (TLAB)
  • Escape analysis
  • String constant pools, string interning, string de-duplication
  • Permanent generation vs Metaspace
  • Object layout e.g. why boolean is not taking 1 bit (word tearing)
  • Native memory e.g. JNI or off-heap memory access

I don't believe that there is a single website that will explain the full JVM memory management approach.

like image 76
Karol Dowbecki Avatar answered Sep 02 '26 05:09

Karol Dowbecki



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!