Java和内存布局 [英] java and memory layout
问题描述
伙计们,我正在审查一些问题,但我无法弄清楚,我翻阅了课本,但不确定在哪里可以找到答案...
Hey guys, I'm reviewing some questions but I can't really figure it out, i looked through the text book but i'm not sure where i can find answer...
我知道在没有图片的情况下制作内存图会非常困难,但是请多多包涵.
I know it would be quite hard to do memory diagrams w/o pictures but please bear with me.
interface Lovable
public void love();
class Foo implements Lovable
public void love();
// something
public int val()
// return something1
public class Love
public static void main(String args [])
Foo foo = new Foo()
foo.love()
foo.love()
int bar = =foo.val()
System.out.print(v)
现在,我看到foo是用new
声明的,所以我知道实际的Foo类信息存储在堆中,并且有一个框架?指针?指向堆栈顶部堆中的内存空间(在foo调用任何方法之前).那接口呢?也会存储在堆中吗?
Now, I see that foo is declared with new
, so I know actual Foo class information is stored in heap and there's a frame?pointer? that points to that memory space in heap on top of the stack (before foo calls any methods). so then what about the interface? would that be stored in the heap too?
因此,在堆栈底部将是Love类(也包含int bar),指向堆中Foo foo的指针,foo.love()的框架,另一个foo.love()的框架,是foo.val()的帧,还是打印的框架?
so on the bottom of the stack would be the class Love(also contains int bar), a pointer that points to Foo foo in heap, a frame for foo.love(), another frame foo.love(), a fram for foo.val(), a framee for print?
我明白了吗?还是我真的很遥远?如果您知道我在哪里可以获得更多信息,请告诉我.我非常感谢您的投入.
Am i getting the idea ? or am i really really far off? If you know any where I can get more information, please let me know. I appreciate any input..
推荐答案
Generally, are objects are stored on the heap managed by the garbage collector.
仅 Java 6的最新版本具有转义分析功能,以在对象无法转义时将其存储在堆栈中.
Only the latest release of Java 6 has escape analysis to store objects on the stack if they do not escape.
类信息存储在烫发空间中.
这篇关于Java和内存布局的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!