Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Invisible java bytecode lines

I am wondering why the line numbers of Java Bytecode are not consecutive.

What happens for example in the (not listed) lines 2 and 3 of the following getter?

public java.lang.String getX();

Code:
0:   aload_0
1:   getfield        #2; //Field x:Ljava/lang/String;
4:   areturn

I'm using the ASM framework to work on bytecode. When visiting the code of a method using the tree API I get these "hidden" instructions as well (however with opcode -1). I would like to know what they are for.

like image 756
nrainer Avatar asked Dec 15 '22 11:12

nrainer


1 Answers

I don't think that 0, 1, 4 are linenumbers but byte offsets in the bytecode.

  • aload_0 is one byte
  • getfield is three bytes (one opcode, one "index" arg with two bytes"
  • areturn is one byte

So 2 and 3 are simply part of the getfield operation.

like image 103
A.H. Avatar answered Dec 31 '22 23:12

A.H.