< prev index next >

src/jdk.jfr/share/classes/jdk/jfr/internal/instrument/ConstructorTracerWriter.java

Print this page
rev 52456 : imported patch asm.additional


  33 import jdk.internal.org.objectweb.asm.ClassVisitor;
  34 import jdk.internal.org.objectweb.asm.ClassWriter;
  35 import jdk.internal.org.objectweb.asm.MethodVisitor;
  36 import jdk.internal.org.objectweb.asm.Opcodes;
  37 import jdk.internal.org.objectweb.asm.Type;
  38 
  39 final class ConstructorTracerWriter extends ClassVisitor {
  40 
  41     private ConstructorWriter useInputParameter, noUseInputParameter;
  42 
  43     static byte[] generateBytes(Class<?> clz, byte[] oldBytes) throws IOException {
  44         InputStream in = new ByteArrayInputStream(oldBytes);
  45         ClassReader cr = new ClassReader(in);
  46         ClassWriter cw = new ClassWriter(ClassWriter.COMPUTE_MAXS);
  47         ConstructorTracerWriter ctw = new ConstructorTracerWriter(cw, clz);
  48         cr.accept(ctw, 0);
  49         return cw.toByteArray();
  50     }
  51 
  52     private ConstructorTracerWriter(ClassVisitor cv, Class<?> classToChange) {
  53         super(Opcodes.ASM5, cv);
  54         useInputParameter = new ConstructorWriter(classToChange, true);
  55         noUseInputParameter = new ConstructorWriter(classToChange, false);
  56     }
  57 
  58     private boolean isConstructor(String name) {
  59         return name.equals("<init>");
  60     }
  61 
  62     private boolean takesStringParameter(String desc) {
  63         Type[] types = Type.getArgumentTypes(desc);
  64         if (types.length > 0 && types[0].getClassName().equals(String.class.getName())) {
  65             return true;
  66         }
  67         return false;
  68     }
  69 
  70     @Override
  71     public MethodVisitor visitMethod(int access, String name, String desc, String signature, String[] exceptions) {
  72 
  73         MethodVisitor mv = super.visitMethod(access, name, desc, signature, exceptions);


  33 import jdk.internal.org.objectweb.asm.ClassVisitor;
  34 import jdk.internal.org.objectweb.asm.ClassWriter;
  35 import jdk.internal.org.objectweb.asm.MethodVisitor;
  36 import jdk.internal.org.objectweb.asm.Opcodes;
  37 import jdk.internal.org.objectweb.asm.Type;
  38 
  39 final class ConstructorTracerWriter extends ClassVisitor {
  40 
  41     private ConstructorWriter useInputParameter, noUseInputParameter;
  42 
  43     static byte[] generateBytes(Class<?> clz, byte[] oldBytes) throws IOException {
  44         InputStream in = new ByteArrayInputStream(oldBytes);
  45         ClassReader cr = new ClassReader(in);
  46         ClassWriter cw = new ClassWriter(ClassWriter.COMPUTE_MAXS);
  47         ConstructorTracerWriter ctw = new ConstructorTracerWriter(cw, clz);
  48         cr.accept(ctw, 0);
  49         return cw.toByteArray();
  50     }
  51 
  52     private ConstructorTracerWriter(ClassVisitor cv, Class<?> classToChange) {
  53         super(Opcodes.ASM7, cv);
  54         useInputParameter = new ConstructorWriter(classToChange, true);
  55         noUseInputParameter = new ConstructorWriter(classToChange, false);
  56     }
  57 
  58     private boolean isConstructor(String name) {
  59         return name.equals("<init>");
  60     }
  61 
  62     private boolean takesStringParameter(String desc) {
  63         Type[] types = Type.getArgumentTypes(desc);
  64         if (types.length > 0 && types[0].getClassName().equals(String.class.getName())) {
  65             return true;
  66         }
  67         return false;
  68     }
  69 
  70     @Override
  71     public MethodVisitor visitMethod(int access, String name, String desc, String signature, String[] exceptions) {
  72 
  73         MethodVisitor mv = super.visitMethod(access, name, desc, signature, exceptions);
< prev index next >