3

I understand how does JVM creates java heap out of available native heap provided by OS.

For any native process like JVM(java.exe), OS allocates address space which is divided into multiple regions like heap, stack, data etc.'

In somewhat same way JVM allocates some address space to the running java program(byecode) which include java heap, stack etc.

I understood that java heap is portion of native heap(provided by OS to JVM(java.exe))

But I am not able to understand where is this "stack" portion coming from.

Is it the part of native heap? Is it part of native stack, just like java heap is part of native heap?

Just like Java Heap vs Native Heap, aren't we having Java Stack vs native Stack?

please help me. I am really struggling to understand stack memory in java.

  • Possible duplicate of [this question](http://stackoverflow.com/questions/38605147/how-does-jvm-uses-native-stack-manually-for-java-function-call) and also [this one](https://stackoverflow.com/questions/16264118/how-jvm-stack-heap-and-threads-are-mapped-to-physical-memory-or-operation-syste?rq=1) – the8472 Jul 27 '16 at 18:38
  • Possible duplicate of [What and where are the stack and heap?](http://stackoverflow.com/questions/79923/what-and-where-are-the-stack-and-heap) – Rupsingh Aug 02 '16 at 07:36

1 Answers1

3

Conceptually, when java.exe starts, the program is given a block of memory by the OS. Part of that block of memory is used by java.exe itself. Another part is for string constants. The rest is for the heap. When a new Thread is started, that thread will be given memory out of the heap to use for its stack. In that way, the (thread) stack is conceptually no different than creating any other object on the heap.

I hope this clears this up for you.

ControlAltDel
  • 33,923
  • 10
  • 53
  • 80