an object = an instance of a class = new  类()

 reference = 连接到一个对象。

一、我们源码的方法需要保存的数据:

      1、类方法(static)或是对象方法,

           如果是对象方法要保存 this 的reference:表示当前哪个对象的方法。

          因为对象方法里:可能用到对象的一些数据。

      2、方法参数

      3、程序里的变量

      4、程序里的 literal  value:

      5、编译时常量

      6、计算结果      

因此:方法数据保存在哪里,这一块由Java stacks负责。

二、 Java stacks

        1、构成:多个stack frame

        2、stack frame:就是源码里一个方法数据所需要的空间

三、执行过程     

    一个线程调用一个方法-----jvm    在java stacks上分配一个新的stack frame 去保存数据。

四、stack frame 构成

      1、the local variables section 本地变量区:存放所有的数据,literal 值,变量,编译时常量,计算结果,参数。

           1》a method parameters(方法所有参数):

           2》local variables(本地变量):

      2、operand stack:用push,pop 操作数据。

          operand stack:只是一个临时的计算过程,要用到Local variable table里面的值,然后得出结果,放入到 local variables 区。

      3、frame data::

      

jvm Local Variables ,Operand Stacks


jvm Local Variables ,Operand Stacks

    jvm Local Variables ,Operand Stacks


五、类方法例子:


public static void runClassMethod(int i,long l,float f,double d,Object b,byte x)
{
 for(int i1=0;i1<10;i1++)
System.out.println(i1);
 String s="a";//literal 字符
 String s1="a"+"b";//编译时常量 
System.out.println(s+s1);
}

  JVM:   Local variable table:参数6个+一个i1自变量+1个literal 字符串=8个变量。
        [pc: 0, pc: 59] local: i index: 0 type: int
        [pc: 0, pc: 59] local: l index: 1 type: long
        [pc: 0, pc: 59] local: f index: 3 type: float
        [pc: 0, pc: 59] local: d index: 4 type: double
        [pc: 0, pc: 59] local: b index: 6 type: java.lang.Object
        [pc: 0, pc: 59] local: x index: 7 type: byte
        [pc: 3, pc: 24] local: i1 index: 8 type: int
        [pc: 28, pc: 59] local: s index: 8 type: java.lang.String
        [pc: 32, pc: 59] local: s1 index: 9 type: java.lang.String


   文章:    jvm 说明书(The Java® Virtual Machine Specification Java SE 7 Edition):

       http://docs.oracle.com/javase/specs/jvms/se7/html/

相关文章:

  • 2022-02-06
  • 2021-11-26
  • 2021-09-13
  • 2022-12-23
  • 2021-07-26
  • 2021-05-10
  • 2021-06-22
  • 2022-12-23
猜你喜欢
  • 2022-12-23
  • 2021-05-10
  • 2022-12-23
  • 2021-04-21
  • 2021-05-02
  • 2021-10-21
相关资源
相似解决方案