b.addAload(1);
b.addAload(0);
b.addInvokestatic(ClassLookupManager.class.getName(), "getClassData", "(Ljava/lang/String;Ljava/lang/Object;)[B");
b.add(Opcode.DUP);
b.add(Opcode.IFNULL);
JumpMarker jumpEnd = JumpUtils.addJumpInstruction(b);
//now we need to do the findLoadedClasses thing
b.addAload(0);
b.addAload(1);
b.addInvokevirtual("java.lang.ClassLoader", "findLoadedClass", "(Ljava/lang/String;)Ljava/lang/Class;");
b.add(Opcode.DUP);
b.add(Opcode.IFNULL);
JumpMarker notFound = JumpUtils.addJumpInstruction(b);
b.add(Opcode.ARETURN);
notFound.mark();
b.add(Opcode.POP);
b.addAstore(3);
b.addAload(0);
b.addAload(1);
b.addAload(3);
b.addIconst(0);
b.addAload(3);
b.add(Opcode.ARRAYLENGTH);
b.addInvokevirtual("java.lang.ClassLoader", "defineClass", "(Ljava/lang/String;[BII)Ljava/lang/Class;");
if (method.getDescriptor().equals("Ljava/lang/String;Z)Ljava/lang/Class;")) {
b.addIload(2);
} else {
b.addIconst(0);
}
b.add(Opcode.IFEQ);
final JumpMarker linkJumpEnd = JumpUtils.addJumpInstruction(b);
b.add(Opcode.DUP);
b.addAload(0);
b.add(Opcode.SWAP);
b.addInvokevirtual("java.lang.ClassLoader", "resolveClass", "(Ljava/lang/Class;)V");
linkJumpEnd.mark();
b.add(Opcode.ARETURN);
jumpEnd.mark();
b.add(Opcode.POP);
if (!classFile.getName().startsWith("java.") && !classFile.getName().startsWith("com.sun") && !classFile.getName().startsWith("sun")) {
//now we need to check if this is a fakereplace class
//and if so always delegate to the appropriate loader
b.addAload(1);
b.addLdc("org.fakereplace");
b.addInvokevirtual(String.class.getName(), "startsWith", "(Ljava/lang/String;)Z");
b.add(Opcode.IFEQ);
JumpMarker notFakereplace = JumpUtils.addJumpInstruction(b);
//so this is a fakereplace class, delegate to the system loader
b.addInvokestatic(ClassLoader.class.getName(), "getSystemClassLoader", "()Ljava/lang/ClassLoader;");
b.addAload(1);
b.addInvokevirtual(ClassLoader.class.getName(), "loadClass", "(Ljava/lang/String;)Ljava/lang/Class;");
b.add(Opcode.ARETURN);
notFakereplace.mark();
}
iterator.insert(b.get());
method.getCodeAttribute().computeMaxStack();
}