Is frame in JVM heap allocated or stack allocated?

The JVM Specification (JSE 8 Edition) mentioned:

Page 12: 2.5.2 JVM Stacks: "Because the JVM stack is never manipulated directly except to push and pop frames, frames may be heap allocated."

Page 15: 2.6: Frames: "Frames are allocated from the JVM stack of the thread creating the frame." And on Page 16: "Note that a frame created by a thread is local to that thread and cannot be referenced by any other thread."

This sounds quite confusing to me. Since a frame is local to the thread that creates the frame, why allocate the frame in heap since heap is shared among all JVM threads? It does not make sense unless something is missed here. The sentence on Page 12 is an interesting statement.

Any hints? Thanks.


JVM stack is an abstraction. It may be allocated anywhere or nowhere at all. Eg if a method is inlined by JIT, it does not have a separate stack frame.

HotSpot JVM uses native thread stack as JVM stack. However there are JVM implementations (CLDC HI, for instance) that allocate JVM stacks in Java Heap. The benefit of this approach is to have a single memory management for everything including thread stacks. Such JVM may run on a platform without standard memory manager (like libc) or even without OS.

JVM Heap is also an abstraction. It is not more "shared" between JVM threads than native thread stacks. The heap may have thread-local areas as well. At the same time native threads stacks reside in virtual memory which is also shared among all threads of the process.

链接地址: http://www.djcxy.com/p/14520.html

上一篇: 如何以编程方式获取堆栈内存统计信息?

下一篇: JVM堆分配或栈分配框架?