0

I'm trying to do static analysis of bytecode in Prolog. I'm using the bcel library to get instruction list from a MethodGen. For aload_0, I get 0:aload_0[42](1)

I understand aload_0 is meant to load 0th Local variable. But I'm having a hard time understanding the next bits i.e [42](1). It's also there for other instructions, for eg:

invokespecial[183](3) 8
return[177](1)

Can someone please explain what are those?. Would highly appreciate it!

Holger
  • 285,553
  • 42
  • 434
  • 765
CodeSsscala
  • 729
  • 3
  • 11
  • 23
  • The normal way of using a Java API, is to query the object properties via the class members, whose names are usually self-explanatory, rather than doing guesswork about the format of the `toString()` output. Besides that, [it is documented](https://commons.apache.org/proper/commons-bcel/apidocs/org/apache/bcel/generic/Instruction.html#toString-boolean-): `Long output format: "[""]" "("")"` – Holger Jan 12 '17 at 15:43
  • @Holger Thank you for enlightening me.I had checked the documentation as I claimed and got the answer, just forgot to mark it answered here. – CodeSsscala Jan 12 '17 at 15:48

1 Answers1

2

42 is the opcode for aload_0. 183 is the opcode for invokespecial. 177 is return and so on. The 8 after invokespecial is probably the 16 bit constant pool index that the instruction uses.

https://docs.oracle.com/javase/specs/jvms/se8/html/jvms-7.html

Antimony
  • 37,781
  • 10
  • 100
  • 107
  • Note that the OP failed to do correct formatting, the String actually is `invokespecial[183](3) 8`, which matches [its documentation](https://commons.apache.org/proper/commons-bcel/apidocs/org/apache/bcel/generic/CPInstruction.html#toString-boolean-): `Long output format: "[""]" "("")" "<"< constant pool index>">"`, so your guess is right, but the OP should read the documentation instead of asking us for guesses… – Holger Jan 12 '17 at 15:46