JVM method dispatch:修订间差异
第10行: | 第10行: | ||
invoke a static method, the method is from the constant pool by <syntaxhighlight lang="java">index= (indexbyte1 << 8) | indexbyte2</syntaxhighlight> | invoke a static method, the method is from the constant pool by <syntaxhighlight lang="java">index= (indexbyte1 << 8) | indexbyte2</syntaxhighlight> | ||
{| | |||
|+ 說明文字 | |||
|- | |||
| <syntaxhighlight lang="java"> | |||
public class Hello { | |||
public static void sayHello(String msg) { | |||
System.out.println(msg); | |||
} | |||
public static void main(String[] args) { | |||
sayHello("Riguz!"); | |||
} | |||
} | |||
</syntaxhighlight> || 👉 || | |||
<syntaxhighlight lang="java"> | |||
// Riguz! | |||
#4 = String #23 | |||
// com/riguz/Hello.sayHello:(Ljava/lang/String;)V | |||
#5 = Methodref #6.#24 | |||
... | |||
public static void main(java.lang.String[]); | |||
descriptor: ([Ljava/lang/String;)V | |||
flags: ACC_PUBLIC, ACC_STATIC | |||
Code: | |||
stack=1, locals=1, args_size=1 | |||
0: ldc #4 | |||
2: invokestatic #5 | |||
5: return | |||
LineNumberTable: | |||
line 9: 0 | |||
line 10: 5 | |||
} | |||
</syntaxhighlight> | |||
|} | |||
== invokevirtual == | == invokevirtual == |
2021年4月7日 (三) 14:15的版本
Method invocation
invokestatic
invoke a static method:
invokestatic
indexbyte1
indexbyte2
invoke a static method, the method is from the constant pool by
index= (indexbyte1 << 8) | indexbyte2
public class Hello {
public static void sayHello(String msg) {
System.out.println(msg);
}
public static void main(String[] args) {
sayHello("Riguz!");
}
}
|
👉 |
// Riguz!
#4 = String #23
// com/riguz/Hello.sayHello:(Ljava/lang/String;)V
#5 = Methodref #6.#24
...
public static void main(java.lang.String[]);
descriptor: ([Ljava/lang/String;)V
flags: ACC_PUBLIC, ACC_STATIC
Code:
stack=1, locals=1, args_size=1
0: ldc #4
2: invokestatic #5
5: return
LineNumberTable:
line 9: 0
line 10: 5
}
|