The ASM 4.0 user guide describes the byte code for a default public constructor to be
ALOAD 0 INVOKESPECIAL java/lang/Object.<init> ()V RETURN
I wanted to replicate this, created my own class with a default public constructor, and decompiled it. The generated byte code for the constructor looks like the following though:
L0 LINENUMBER 3 L0 ALOAD 0 INVOKESPECIAL java/lang/Object.<init> ()V RETURN L1 LOCALVARIABLE this Lcom/example/EmptyFixture; L0 L1 0 MAXSTACK = 1 MAXLOCALS = 1
My understanding is that everything nested under label
L0, which matched the user guide, is executed. There is unreachable code after the
RETURN, nested under label
L1, which is simply a local variable declaration of
this with the type of the class.
What is the reason to include this variable declaration? What is it used for, especially since it looks like it is unreachable?
The information after L1 is all descriptive; it is not code and cannot be executed, so its ‘reachability’ is meaningless. In other words, even if control flow somehow did reach L1, those lines would not be executed, and if they were put within code that is executed, in this case between L0 and L1, they still would not be executed.
Like the LINENUMBER directive, those lines specify debugging information that is in the classfile. Debugging information is included in the classfile to support debugging, and it is used by the debugger if you debug.