常用的字节码

常量入

aconst_null null 对象入栈
iconst_m1   int 常量 -1 入栈
iconst_0      int 常量 0 入栈
iconst_5
lconst_1      long 常量 1 入栈
fconst_1      float 1.0 入栈
dconst_1     double 1.0 入栈
bipush         8 位带符号整数入栈
sipush          16 带符号整数入

ldc               常量池中的项入

ldc index

indexu1为指向常量池的有效无符号8位索引


局部变量压栈

xload (x i l f d a)
分别表示 int long float double objectref
xload_n (n 01 2 3)
xaload (x i l f d a b c s)
分别表示 int ,long, float, double, obj ref , byte,char,short
从数组中取得给定索引的值,将该值压栈
iaload
执行前,栈: ..., arrayref ,index
它取得 arrayref 所在数组的 index 的值,并将值压栈
执行后,栈: ...,value

出栈装载入局部变量

xstore (x i l f d a)
栈,存入局部变量
xstore_n (n0 1 2 3)
栈,将值存入第 n 个局部变量
xastore (x i l f d a b c s)
将值存入数组中
iastore
执行 前,栈: ..., arrayref ,index, value
执行后,栈: ...
value 存入 arrayref [index]


通用栈操作(无类型)

nop
pop
出栈顶 1 个字长
dup
复制栈顶 1 个字长,复制内容压入栈

类型转化




整数运算
iadd
ladd
isub
lsub
idiv
ldiv
imul
lmul
iinc

浮点运算

fadd

dadd

扫描二维码关注公众号,回复: 1863770 查看本文章

fsub

dsub

fdiv

ddiv

fmul

dmul

基本工作流程都是,弹出栈顶2个数,做运算,结果入栈

对象操作指令

new
getfield
putfield
getstatic
putstatic

条件控制

ifeq   如果为 0 ,则跳转
ifne   如果不为 0 ,则跳转
iflt    如果小于 0 ,则跳转
ifge   如果大于 0 ,则跳转
if_icmpeq 如果两个 int 相同,则跳转


ifeq

参数byte1,byte2

value出栈,如果栈顶value0则跳转到(byte1<<8)|byte2

执行前,栈:...,value

执行后,栈:...


方法调用

invokevirtual
invokespecial
invokestatic
invokeinterface
xreturn (x i l f d a 或为空 )


invokespecial通常根据引用的类型选择方法,而不是对象的类来选择!即它使用静态绑定而不是动态绑定。

invokespecial对私有方法超类方法 实例初始化方法

xreturn x为空,表示返回void







猜你喜欢

转载自blog.csdn.net/u010325193/article/details/80869153