< prev index next > test/hotspot/jtreg/runtime/verifier/CFLH/TestVerify.java
Print this page
* @run main/othervm --patch-module=java.base=. -Dagent.retransform=false -javaagent:redefineagent.jar TestVerify
* @run main/othervm --patch-module=java.base=. -Dagent.retransform=true -javaagent:redefineagent.jar TestVerify
*/
import java.lang.invoke.MethodHandles;
- import java.time.Duration;
import java.lang.classfile.ClassFile;
import java.lang.classfile.ClassTransform;
import java.lang.classfile.MethodTransform;
import java.lang.classfile.constantpool.InterfaceMethodRefEntry;
import java.lang.classfile.instruction.ReturnInstruction;
import jdk.test.lib.helpers.ClassFileInstaller;
import java.io.FileNotFoundException;
public class TestVerify {
! private static final String CLASS_TO_BREAK = "java.time.Duration";
private static final String INTERNAL_CLASS_TO_BREAK = CLASS_TO_BREAK.replace('.', '/');
private static final boolean DEBUG = false;
private static class BadTransformer implements ClassFileTransformer {
import jdk.test.lib.helpers.ClassFileInstaller;
import java.io.FileNotFoundException;
public class TestVerify {
! private static final String CLASS_TO_BREAK = "java.util.Date";
private static final String INTERNAL_CLASS_TO_BREAK = CLASS_TO_BREAK.replace('.', '/');
private static final boolean DEBUG = false;
private static class BadTransformer implements ClassFileTransformer {
System.out.println("Done injecting bug");
}
builder.with(element);
});
! var classTransform = ClassTransform.transformingMethods(mm -> mm.methodName().stringValue().equals("getSeconds"), methodTransform);
byte[] bytes;
try {
var cf = ClassFile.of();
var existingClass = cf.parse(classfileBuffer);
System.out.println("Done injecting bug");
}
builder.with(element);
});
! var classTransform = ClassTransform.transformingMethods(mm -> mm.methodName().stringValue().equals("parse"), methodTransform);
byte[] bytes;
try {
var cf = ClassFile.of();
var existingClass = cf.parse(classfileBuffer);
inst.addTransformer(new BadTransformer(), true);
inst.retransformClasses(clazz);
} else {
// Load the class instrumented with CFLH for the VerifyError.
inst.addTransformer(new BadTransformer());
! System.out.println("1 hour is " + Duration.ofHours(1).getSeconds() + " seconds");
}
throw new RuntimeException("Failed: Did not throw VerifyError");
} catch (VerifyError e) {
System.out.println("Passed: VerifyError " + e.getMessage());
}
inst.addTransformer(new BadTransformer(), true);
inst.retransformClasses(clazz);
} else {
// Load the class instrumented with CFLH for the VerifyError.
inst.addTransformer(new BadTransformer());
! Class<?> cls = Class.forName(CLASS_TO_BREAK);
+ System.out.println("class loaded" + cls);
}
throw new RuntimeException("Failed: Did not throw VerifyError");
} catch (VerifyError e) {
System.out.println("Passed: VerifyError " + e.getMessage());
}
< prev index next >