Error when computing stack map frames
I am trying to instrument the byte code of
org.hsqldb.jdbc.JDBCStatement#executeBatch(int[]) method and I use ASM to
recompute the frames and the stack size for me. ASM does unfortunately not
compute the correct frames and a verifier error is thrown
I broke down the problem to adding an additional variable of type int to the
method. To do so, I am manually incresing the index of all variables by 1 if an
offset does not match that of an argument. As an example, this means that the
offset for "this" remains 0 but the offset for 1 is mapped to 2 etc. This works
for most methods.
I can reproduce very similar behavior by recompiling
org.hsqldb.jdbc.JDBCStatement#executeBatch(int[]) with an additional variable
int value = 0;
at the beginning of the method.
I attached byte code output for:
1. The original byte code that is fed to a ClassReader
2. The actual outcome that is produced by a ClassWriter when adding the
statement "int value = 0" to the beginning of the method and remapping all the
offsets.
3. The expected outcome as produced by javac when adding this manually.
If you diff (2) and (3) you can see some minor, insignificant differences
caused by the way the byte code is generated. The root cause is the stack map
frame in line 76 of (2) compared to line 73 of (3). ASM computes the stack map
frame to be
FRAME APPEND [org/hsqldb/navigator/RowSetNavigator T I]
where javac adds
FRAME APPEND [org/hsqldb/navigator/RowSetNavigator [I I]