opcode study

iconst_n
Integers n = 0..5.

the n indicates the const itself, not the index, and the const would be put into the stack.


istore_n
store integer in local variable n : n = 0..3

it says store integer. store what integer? actually it's the integer from the stack.



iconst_<i> Operation Push int constant
Forms iconst_m1 = 2 (0x2)
iconst_0 = 3 (0x3) iconst_1 = 4 (0x4) iconst_2 = 5 (0x5) iconst_3 = 6 (0x6) iconst_4 = 7 (0x7) iconst_5 = 8 (0x8) Operand Stack
… ⇒
…, <i>

Description Push the int constant <i> (−1, 0, 1, 2, 3, 4 or 5) onto the operand stack.
Notes Each of this family of instructions is equivalent to bipush <i> for the
respective value of <i>, except that the operand <i> is implicit.

at Java Virtual Machine Specification 3rd P366, but when it coms to load the constant 6, what will it going to do?  yes, it would then use bipush 6

iconst and bipush's difference:

The Java virtual machine frequently takes advantage of the likelihood of certain
operands (int constants −1, 0, 1, 2, 3, 4 and 5 in the case of the iconst_<i>
instructions) by making those operands implicit in the opcode. Because the
iconst_0 instruction knows it is going to push an int 0, iconst_0 does not need to
store an operand to tell it what value to push, nor does it need to fetch or decode
an operand. Compiling the push of 0 as bipush 0 would have been correct, but
would have made the compiled code for spin one byte longer. A simple virtual
machine would have also spent additional time fetching and decoding the explicit
operand each time around the loop. Use of implicit operands makes compiled
code more compact and efficient.




  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值