程序员最近都爱上了这个网站  程序员们快来瞅瞅吧!  it98k网:it98k.com

本站消息

站长简介/公众号

  出租广告位,需要合作请联系站长


+关注
已关注

分类  

暂无分类

标签  

暂无标签

日期归档  

暂无数据

Local variable Table In JVM Stack

发布于2022-09-30 16:57     阅读(1166)     评论(0)     点赞(23)     收藏(0)


Today I compile a class to bytecode, and I can't find anything in main method local variable table index 0, It's start from 1, I know a non-static method start 1 because it's 'this' at 0.

Here is the bytecode.

  // this is the main method
  public static void main(java.lang.String[]);
    Code:
       0: iconst_1
       1: istore_1   // index: 1 (what is content at index 0 ?)
       2: iconst_2
       3: istore_2
       4: return

  // this is a static method
  public static void staticMethod();
    Code:
       0: iconst_1
       1: istore_0  // index: 0 (no 'this')
       2: iconst_2
       3: istore_1
       4: return

  // this is a non-static method
  public void nonStaticMethod();
    Code:
       0: iconst_1
       1: istore_1  // index: 1  (index 0 should be 'this')
       2: iconst_1
       3: istore_2
       4: return

Help me please, Thanks!


解决方案


The local variable at index 0 in the main method is the method's argument: a reference to String[]. From the JVM specification:

The Java Virtual Machine uses local variables to pass parameters on method invocation. On class method invocation, any parameters are passed in consecutive local variables starting from local variable 0.

https://docs.oracle.com/javase/specs/jvms/se14/html/jvms-2.html#jvms-2.6.1



所属网站分类: 技术文章 > 问答

作者:黑洞官方问答小能手

链接:http://www.javaheidong.com/blog/article/526443/b71052e7d0ee533db19b/

来源:java黑洞网

任何形式的转载都请注明出处,如有侵权 一经发现 必将追究其法律责任

23 0
收藏该文
已收藏

评论内容:(最多支持255个字符)