How to avoid "Invalid type in persistent pool" using "ldc_w <classname>" in Jasmin?
I am writing a compiler that generates Jasmin code and want to call a method that takes a class as a parameter.
public class CTest
{
public static void main(String[] args)
throws Exception
{
java.lang.reflect.Array.newInstance(CTest.class, 0);
}
}
So in Jasmine, I think it should be:
.class public CTest2
.super java/lang/Object
.method public static main([Ljava/lang/String;)V
.limit stack 2
.limit locals 1
ldc_w CTest2
iconst_0
invokestatic java/lang/reflect/Array/newInstance(Ljava/lang/Class;I)Ljava/lang/Object;
pop
return
.end method
When I collect it and run it, I get:
Exception in thread "main" java.lang.VerifyError: (class: CTest2, method: main signature: ([Ljava / lang / String;) V) Invalid type in constant pool
A look at the disassembled code for CTest.class (Java version) and CTest2.class (Jasmin version) with "javap -c -verbose" they both seem to configure the constant pool the same way:
const #2 = class #16; // CTest
const #16 = Asciz CTest;
0: ldc_w #2; //class CTest
const #14 = Asciz CTest2;
const #17 = class #14; // CTest2
0: ldc_w #17; //class CTest2
Jasmin, , "ldc_w" , "new" "anewarray" .
.class TraceClassVisitor ASM, .
, ?
+3
1