是分配JVM堆中的帧还是堆栈分配? [英] Is frame in JVM heap allocated or stack allocated?

查看:131
本文介绍了是分配JVM堆中的帧还是堆栈分配?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

JVM规范(JSE 8版)提到:



第12页:2.5.2 JVM堆栈:
因为JVM堆栈从不直接操作除了推送和弹出帧之外,帧可能是堆分配的。



页面15:2.6:帧:
帧是从JVM堆栈中分配的创建框架的线程。
和第16页:
请注意,线程创建的帧是该线程的本地帧,不能被任何其他线程引用。



<这对我来说听起来很混乱。由于帧是创建帧的线程的本地,为什么在堆中分配帧,因为堆在所有JVM线程之间共享?除非在这里遗漏一些东西,否则没有意义。第12页上的句子是一个有趣的陈述。



任何提示?谢谢。

解决方案

JVM堆栈是一种抽象。它可以分配到任何地方或任何地方。例如。如果一个方法由JIT内联,它没有单独的堆栈框架。



HotSpot JVM使用本机线程堆栈作为JVM堆栈。但是,有一些JVM实现(例如CLDC HI)在Java Heap中分配JVM堆栈。这种方法的好处是对包括线程堆栈在内的所有内容进行单一内存管理。这样的JVM可以在没有标准内存管理器(如libc)的平台上运行,甚至可以在没有OS的情况下运行。



JVM堆也是一种抽象。 JVM线程之间的共享不是本机线程堆栈。堆也可能具有线程局部区域。同时,本机线程堆栈驻留在虚拟内存中,虚拟内存也在进程的所有线程之间共享。


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. E.g. 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.

这篇关于是分配JVM堆中的帧还是堆栈分配?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆