JVM的tableswitch/lookupswitch指令的格式为什么在0到3个字节之间有填充?

huangapple go评论92阅读模式
英文:

Why does the format of JVM tableswitch/lookupswitch instruction has between 0 and 3 bytes padding?

问题

我已经理解了tableswitch/lookupswitch的格式。
但是,在0和3个字节之间的填充有什么目的呢?

英文:

I have understanded the format of tableswitch/lookupswitch.
But,what is the purpose of between 0 and 3 bytes padding?

答案1

得分: 4

为了历史原因而存在填充。最早的Java虚拟机没有JIT编译,它们逐条解释字节码指令。为了允许解释器直接从字节码流中读取32位偏移量,这些偏移量是32位对齐的,它们的地址是4字节的精确倍数。

RISC处理器(例如SPARC、ARMv5等)仅允许对齐的内存访问。例如,要用单个CPU指令从内存中读取32位值,地址必须是32位对齐的。如果地址不对齐,则获取32位值需要进行四次8位内存读取,这显然会更慢。

现今,这种优化已不再有用。

英文:

The padding exists for historical reasons. The first Java Virtual Machines did not have JIT compilation, they interpreted bytecode instructions one by one. To allow interpreters read 32-bit offsets directly from the bytecode stream, the offsets are 32-bit aligned - their addresses are exact multiple of 4 bytes.

RISC processors (like SPARC, ARMv5 and earlier, etc.) permitted only aligned memory access. E.g. to read a 32-bit value from memory with a single CPU instruction, the address must be 32-bit aligned. If the address is not aligned, getting a 32-bit value requires four 8-bit memory reads, which is, of course, slower.

Nowadays the optimization is not useful anymore.

huangapple
  • 本文由 发表于 2020年10月27日 17:46:24
  • 转载请务必保留本文链接:https://go.coder-hub.com/64551786.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定