问题描述
为什么Java具有 IINC
字节码指令?已经有一个 IADD
字节码指令可以用来完成相同的操作.
那为什么 IINC
存在?
只有Java的原始设计者才能回答他们做出特定设计决策的原因.但是,我们可以推测:
IINC
不允许您执行 ILOAD
/ SIPUSH
/ IADD
为什么Java具有 IINC
字节码指令?已经有一个 IADD
字节码指令可以用来完成相同的操作.
那为什么 IINC
存在?
只有Java的原始设计者才能回答他们做出特定设计决策的原因.但是,我们可以推测:
IINC
不允许您执行 ILOAD
/ SIPUSH
/ IADD
code>/ ISTORE
组合.区别在于 IINC
是单个指令,仅占用3或6个字节,而这4个指令序列显然更长.因此, IINC
会稍微减小使用它的字节码的大小.
除此之外,Java的早期版本使用了解释器,其中每条指令在执行过程中都有开销.在这种情况下,使用一条 IINC
指令可能比等效的替代字节码序列要快.请注意,JITting使得这基本上无关紧要,但是 IINC
可以追溯到Java的原始版本.
Why does Java have an IINC
bytecode instruction?There is already an IADD
bytecode instruction that can be used to accomplish the same.
So why does IINC
exist?
Only the original designers of Java can answer why they made particular design decisions. However, we can speculate:
IINC
does not let you do anything that can't already be accomplished by a ILOAD
/SIPUSH
/IADD
/ISTORE
combo. The difference is that IINC
is a single instruction, which only takes 3 or 6 bytes, while the 4 instruction sequence is obviously longer. So IINC
slightly reduces the size of bytecode that uses it.
Apart from that, early versions of Java used an interpreter, where every instruction has overhead during execution. In this case, using a single IINC
instruction could be faster than the equivalent alternative bytecode sequence. Note that JITting has made this largely irrelevant, but IINC
dates back to the original version of Java.
这篇关于Java为什么有IINC字节码指令?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!