JVM and Memory
JVM and Memory
Heap, Metaspace, Stack
Stack Memory

Difference between Stack and Heap?
- Stack contains methods, and its primitive values as well as object references.
-
Stack is LIFO.
- Objects are stored in Heap, Stack contains references to them.
- Heap is used for all the application whereas Stack is used by one Thread.
-
Objects in Heap are globally accessible whereas Stack can’t be accessed by other Threads.
- When the memory is full, JVM throws for each case:
- Stack: java.lang.StackOverFlowError
- Heap: java.lang.OutOfMemoryError
Heap options: -Xms, -Xmx
Startup size and Maximum size of Heap memory.
Stack option: -Xss
Stack memory size.
String Pool
Thread Dumps
- jstack
- kill -3
# jstack (jdk)
$ jstack -l <pid> > <file-path>
# kill -3
$ kill -3 <pid>
- JVisualVM
- Java Mission Control (JMC)