I'm trying to generate bytecode which will create object instance without code initialization logic. Actually I want to reproduce generateSerializationConstructor behavior.
{
mv = cw.visitMethod(ACC_PUBLIC, "newObjectInstance", "()Ljava/lang/Object;", null, null);
mv.visitCode();
mv.visitTypeInsn(NEW, classNameInternal);
mv.visitInsn(DUP);
classNameInternal = "java/lang/Object";
mv.visitMethodInsn(INVOKESPECIAL, classNameInternal, "<init>", "()V");
mv.visitInsn(ARETURN);
mv.visitMaxs(0, 0);
mv.visitEnd();
}
unfortunately I got such error:
java.lang.VerifyError: (class: com/esotericsoftware/reflectasm/benchmark/ConstructorAccessBenchmark$SomeClass__ClassAccess__, method: newObjectInstance signature: ()Ljava/lang/Object;) Call to wrong initialization method
JVM specification prohibits creation of objects without calling proper constructor. However, there are two tricky ways of doing this. Both of them are specific to OpenJDK / Oracle JDK and are not guaranteed to work on all Java implementations.
Both techniques are used in our custom serialization engine which can be found at https://github.com/odnoklassniki/one-nio/blob/master/src/one/nio/serial/
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With