ASM transforms LDC_W instructions to LDC
Repro steps:
1) Compile this testcase:
public class Testcase
{
public static void main(String[] args)
{
Class<?> c = Testcase.class;
}
}
2) javap -c -p Testcase.class gives:
public class Testcase extends java.lang.Object {
public Testcase();
Code:
0: aload_0
1: invokespecial #9 // Method java/lang/Object."<init>":
()V
4: return
public static void main(java.lang.String[]);
Code:
0: ldc_w #2 // class Testcase
2: astore_1
3: return
}
3) Process the class using ASM 3.3 as follows:
BufferedInputStream in = new BufferedInputStream(new FileInputStream(inputFile));
ClassReader classReader = new ClassReader(in);
BufferedOutputStream out = new BufferedOutputStream(new
FileOutputStream(outputFile));
ClassWriter classWriter = new ClassWriter(ClassWriter.COMPUTE_MAXS);
classReader.accept(classWriter, 0);
out.write(classWriter.toByteArray());
out.close();
4) javap -c -p Testcase.class now gives:
public class Testcase extends java.lang.Object {
public Testcase();
Code:
0: aload_0
1: invokespecial #9 // Method java/lang/Object."<init>":
()V
4: return
public static void main(java.lang.String[]);
Code:
0: ldc #2 // class Testcase
2: astore_1
3: return
}
5) Notice that the LDC_W instruction in the main() method was transformed into
a LDC.