0

I have been learning about the java class format and i was just wondering why sometimes an opcode with a constant pool entry following takes up two bytes in the class file such as with InvokeStatic, but then op-codes such as ldc with an integer index take up only one byte in the class file. Is there any pattern behind this, i am asking this because i am writing a simple byte-code manipulation library and i would like to be able to know weather to write a constant pool index as a byte or a short without hard-coding every single command into the library.

Popgalop
  • 737
  • 2
  • 9
  • 26

1 Answers1

1

Yes there is a pattern: every instruction except ldc takes a two byte index.

Presumably the designers of the bytecode format deciding that loading constants was such a common task that they should provide a shorter instruction for it.

Antimony
  • 37,781
  • 10
  • 100
  • 107