Bytecode instruction `ldc2_w` transformed to `ldc`
I'm not sure if this is properly a bug or an intentional design decision, so apologies if this is the latter (or if there is an easy solution...)
Problem
Given a bytecode instruction ldc2_w
in a classfile the resultant MethodNode
has
replaced the ldc2_w
instance with an ldc
instruction (i.e., opcode 20 => 18).
Example
Given the following method
void example() {
int i = 65536; // Too big for two bytes
long l = 65537;
}
calling javac ...; javap -c ...;
yields
void example();
Code:
0: ldc #26 // int 65536
2: istore_1
3: ldc2_w #27 // long 65537l
6: lstore_2
7: return
which has width data about the values being loaded (double precision, etc).
Once I've loaded this with asm and inspect the instruction list in the debugger I get the following (note instructions 2 and 6 which are identical modulo their respective values):
Here we see that both ldcxxx
ops have opcode 18 and no other differentiating data.
Why This Matters
In my specific use case I'm simulating the JVM and am depending on the specific asm bytecode values to give me width data. This could be resolved with an extra pass or some sort of lookahead to glean width data but it would be nice to have the expected opcode
Possible Workaround
A potential workaround is to do a prepass to glean type/width data. This is possible but not desirable since isn't obvious to me that there won't be subtleties to a correct implementation that I miss, subtly breaking my software. Further, this seems like a fair amount of implementation work to correct for something that could be known by getting the actual opcode.