1

Can someone explain how the numbers alongside JVM Opcodes are calculated? I think it is like 1 byte for the opcode and rest of the bytes for operands. Am I correct?

Example:

Method int add12and13() 
 0 bipush 12 
 2 bipush 13 
 4 invokestatic #3 // Method Example.addTwoStatic(II)I 
 7 ireturn
3
  • 1
    Some instructions are just 1 byte. Commented Apr 2, 2016 at 7:21
  • If you are interested in such topics, you should start at the official source first. Commented Apr 2, 2016 at 13:13
  • Don’t forget to accept an answer if it satisfies your needs. Otherwise, add to your question what is still unclear. Commented Apr 8, 2016 at 14:15

1 Answer 1

4

You are right. This is bytecode offset from the method beginning.

bipush has 1 byte parameter, so it totally takes 2 bytes.

invokestatic takes 3 bytes: opcode + 2 bytes for a constant pool index, that is, offset of the next instruction will be +3 bytes from this invokestatic.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.