use of jdk.internal.org.objectweb.asm.util.CheckClassAdapter in project openj9 by eclipse.
the class Transformer method transform.
public byte[] transform(ClassLoader loader, String className, Class<?> classToTransform, ProtectionDomain protectionDomain, byte[] classfileBuffer) throws IllegalClassFormatException {
try {
if (flag == MODIFY_EXISTING_METHOD) {
// for fast HCR
AgentMain.logger.debug("Instrumenting " + className + " by modifying existing method.");
ClassReader reader = new ClassReader(classToTransform.getCanonicalName());
ClassWriter cw = new ClassWriter(reader, ClassWriter.COMPUTE_FRAMES | ClassWriter.COMPUTE_MAXS);
ClassVisitor visitor = new CustomClassVisitor(cw, classToTransform.getCanonicalName());
reader.accept(visitor, ClassReader.EXPAND_FRAMES);
return cw.toByteArray();
} else if (flag == ADD_NEW_METHOD) {
// for extended HCR
AgentMain.logger.debug("Instrumenting " + className + " by adding a new method.");
ClassReader reader = new ClassReader(classToTransform.getCanonicalName());
ClassWriter cw = new ClassWriter(reader, ClassWriter.COMPUTE_FRAMES | ClassWriter.COMPUTE_MAXS);
ClassVisitor cv = new MethodAddAdapter(new CheckClassAdapter(cw));
reader.accept(cv, ClassReader.SKIP_FRAMES);
return cw.toByteArray();
} else if (flag == ADD_NEW_FIELD) {
// for GCRetransform test
AgentMain.logger.debug("Instrumenting " + className + " by adding a new field.");
ClassReader reader = new ClassReader(classToTransform.getCanonicalName());
ClassWriter cw = new ClassWriter(reader, ClassWriter.COMPUTE_FRAMES | ClassWriter.COMPUTE_MAXS);
FieldNode newField = new FieldNode(Opcodes.ACC_PUBLIC | Opcodes.ACC_STATIC, "new_static_int_array", "[I", null, null);
ClassVisitor cv = new FieldAdder(new CheckClassAdapter(cw), newField, className, _methodName);
reader.accept(cv, ClassReader.SKIP_FRAMES);
return cw.toByteArray();
}
return null;
} catch (IOException e) {
return null;
}
}
Aggregations