jvm stack 个数

来源:互联网 发布:plc编程软件for mac 编辑:程序博客网 时间:2024/06/02 04:59

文章来源  https://www.yqfy.net/texts/bin/

1、stack=1,只有一个返回值 int 0,

本来stack=本地变量+操作堆栈+frame data,但是参数没有使用,

所以根据实际指令来分配堆栈的个数。


public class ret{public static int main(String[] args){return 0;}javap -c -verbose ret.class
public static int main(java.lang.String[]);flags: ACC_PUBLIC, ACC_STATICCode:stack=1, locals=1, args_size=10: iconst_01: ireturn

2、int 32位,下面数太大,只能当成常量看,所以只需要一个堆栈。

 

public class ret{ public static int main(String[] args) {  return 12345678; }}
public static int main(java.lang.String[]);flags: ACC_PUBLIC, ACC_STATICode:stack=1, locals=1, args_size=10: ldc #2 // int 123456782: ireturn

3、Values of type int, float, reference, and returnValue occupy one entry in the local variables array,

  Values of type byte, short, and char are converted to int before being stored into the local variables
  上面两个表示只占一个横条,即stack=1;
  Values of type long and double occupy two consecutive entries in the array
  上面两个表示只占两个横条,即stack=2;