Jon*_*ans 7 java parameters stack jvm bytecode
在java字节码中,为什么接收器首先被压入堆栈,然后是所有参数?我似乎记得它与效率有关.
对于方法调用和设置字段都是如此.
方法调用
class X {
int p(int a) {
//Do something
}
int main() {
int ret = p(1);
}
}
Run Code Online (Sandbox Code Playgroud)
主要方法编译为:
aload_0 // Load this onto the stack
iconst_1 // Load constant 1 onto the stack
invokevirtual <int p(int)> from class X
Run Code Online (Sandbox Code Playgroud)
设置字段:
class X {
int x;
int main() {
x = 1;
}
}
Run Code Online (Sandbox Code Playgroud)
主要方法编译为:
aload_0 // Load this onto the stack
iconst_1 // Load constant 1 onto the stack
putfield <int x> from class X
Run Code Online (Sandbox Code Playgroud)
首先被推动的优势在于
| 归档时间: |
|
| 查看次数: |
806 次 |
| 最近记录: |