Number of instructions in JVM

2020-06-28 12:16发布

问题:

I was asked the following question in an exam today. I still don't know the answer.

Java uses stack for byte code in JVM. Each instruction is of one byte, so how many such instructions (per byte code) are possible in an operating system.

All I know is that the stack is 32 bits wide. Can anybody help me (I am a beginner in JVM)?

回答1:

The expected answer was almost certainly 256, because there are 256 possible values of a byte.

This of course has nothing to do with the actual JVM instruction set. The number of possible instructions can vary anywhere from a couple dozen to an exponentially large number depending on how you count.

The actual JVM instruction set has many unused opcodes, one opcode that conceptually represent more than one instruction, and many instructions that can be encoded in tons of different ways with multiple different opcodes. Many instructions are more than one byte, with a couple that can be up to 64kb long. And that isn't even getting into stuff like how you count the wide prefix.



标签: jvm bytecode