[英]Does the instruction istore start at index 1 in the main method?
給定指令istore_<n>
及其文檔:
n 必須是當前幀的局部變量數組的索引(第 2.6 節)。
它沒有指定它從哪個索引開始。 我假設為 0。對於給定的 istore 操作,它應該加一。
給定一個簡單的 class:
public class TestingStuff {
public static void main(String[] args) {
int a = 11;
int b = 12;
}
public static void test() {
int c = 13;
int d = 14;
}
}
我希望這兩種方法有不同的框架。 這應該意味着存儲a
和b
的指令將是istore_0
和istore_1
。 以及用於存儲c
和d
的相同索引。 但是由於某種原因, main 方法中的索引從1
開始。 這似乎總是如此。 但我找不到任何有關原因的信息。
來自javap的Output:
public static void main(java.lang.String[]);
descriptor: ([Ljava/lang/String;)V
flags: ACC_PUBLIC, ACC_STATIC
Code:
stack=1, locals=3, args_size=1
0: bipush 11
2: istore_1
3: bipush 12
5: istore_2
6: return
public static void test();
descriptor: ()V
flags: ACC_PUBLIC, ACC_STATIC
Code:
stack=1, locals=2, args_size=0
0: bipush 13
2: istore_0
3: bipush 14
5: istore_1
6: return
是這樣嗎? 如果是這樣,為什么?
static 方法的參數作為局部變量傳入,從 position 0 開始。因此,對於main
, args
數組位於 Z4757FE07FD492A8BE0EA6A76A7、0D683Diling6EZ 0 處的局部變量中。雖然我的代碼確實使用了我的代碼 don't args
0有一個方便的編譯器。
(例如方法, this
是在 position 0,然后剩余的 arguments 從 position 1 開始。)
有關詳細信息,請參閱第 2.6.1 節。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.