ASM 5.0-alpha: Initial Frame Position // Duplicate Frame?
ASM 5.0-alpha has changed the behavior regarding the initial frame. The
following method requires a frame at the very beginning, as the first label is
a jump target:
void loop() {
do {
System.out.println("Hello");
} while (true);
}
With ASM 4.1 this class results in the following events when read with
EXPAND_FRAMES:
loop()V
L0
LINENUMBER 12 L0
FRAME FULL [FrameDump] []
GETSTATIC java/lang/System.out : Ljava/io/PrintStream;
LDC "Hello"
INVOKEVIRTUAL java/io/PrintStream.println (Ljava/lang/String;)V
L1
LINENUMBER 13 L1
GOTO L0
With ASM 5.0-alpha we now get a duplicate frame (probably as the implicit
initial frame is also emitted):
loop()V
L0
LINENUMBER 12 L0
FRAME FULL [FrameDump] []
FRAME FULL [FrameDump] []
GETSTATIC java/lang/System.out : Ljava/io/PrintStream;
LDC "Hello"
INVOKEVIRTUAL java/io/PrintStream.println (Ljava/lang/String;)V
L1
LINENUMBER 13 L1
GOTO L0
My problem is that the initial implicit frame is emitted after the jump label.
In our case we need to insert code at the very beginning of every method and
modify all subsequent frames to reflect an additional local variable. So this
means our initialization code has to be inserted after the initial frame but
before the first label -- otherwise the initialization code would be executed
within the loop.
I'm not sure whether the new initial frame behavior is by design or it is a
bug. Also if it is by design I'm not sure how to resolve the contradiction
described above.