문제

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.

도움이 되었습니까?

해결책

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.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top