< prev index next >

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

Print this page
rev 52456 : imported patch asm.additional


  89         is.close();
  90         return baos.toByteArray();
  91     }
  92 
  93     private byte[] makeBytecode() throws IOException, ClassNotFoundException {
  94 
  95         // Find the methods to instrument and inline
  96 
  97         final List<Method> instrumentationMethods = new ArrayList<>();
  98         for (final Method m : instrumentor.getDeclaredMethods()) {
  99             JIInstrumentationMethod im = m.getAnnotation(JIInstrumentationMethod.class);
 100             if (im != null) {
 101                 instrumentationMethods.add(m);
 102             }
 103         }
 104 
 105         // We begin by inlining the target's methods into the instrumentor
 106 
 107         ClassNode temporary = new ClassNode();
 108         ClassVisitor inliner = new JIInliner(
 109                 Opcodes.ASM5,
 110                 temporary,
 111                 targetName,
 112                 instrumentorName,
 113                 targetClassReader,
 114                 instrumentationMethods);
 115         instrClassReader.accept(inliner, ClassReader.EXPAND_FRAMES);
 116 
 117         // Now we have the target's methods inlined into the instrumentation code (in 'temporary').
 118         // We now need to replace the target's method with the code in the
 119         // instrumentation method.
 120 
 121         ClassWriter cw = new ClassWriter(ClassWriter.COMPUTE_FRAMES);
 122         JIMethodMergeAdapter ma = new JIMethodMergeAdapter(
 123                 cw,
 124                 temporary,
 125                 instrumentationMethods,
 126                 instrumentor.getAnnotationsByType(JITypeMapping.class));
 127         targetClassReader.accept(ma, ClassReader.EXPAND_FRAMES);
 128 
 129        return cw.toByteArray();


  89         is.close();
  90         return baos.toByteArray();
  91     }
  92 
  93     private byte[] makeBytecode() throws IOException, ClassNotFoundException {
  94 
  95         // Find the methods to instrument and inline
  96 
  97         final List<Method> instrumentationMethods = new ArrayList<>();
  98         for (final Method m : instrumentor.getDeclaredMethods()) {
  99             JIInstrumentationMethod im = m.getAnnotation(JIInstrumentationMethod.class);
 100             if (im != null) {
 101                 instrumentationMethods.add(m);
 102             }
 103         }
 104 
 105         // We begin by inlining the target's methods into the instrumentor
 106 
 107         ClassNode temporary = new ClassNode();
 108         ClassVisitor inliner = new JIInliner(
 109                 Opcodes.ASM7,
 110                 temporary,
 111                 targetName,
 112                 instrumentorName,
 113                 targetClassReader,
 114                 instrumentationMethods);
 115         instrClassReader.accept(inliner, ClassReader.EXPAND_FRAMES);
 116 
 117         // Now we have the target's methods inlined into the instrumentation code (in 'temporary').
 118         // We now need to replace the target's method with the code in the
 119         // instrumentation method.
 120 
 121         ClassWriter cw = new ClassWriter(ClassWriter.COMPUTE_FRAMES);
 122         JIMethodMergeAdapter ma = new JIMethodMergeAdapter(
 123                 cw,
 124                 temporary,
 125                 instrumentationMethods,
 126                 instrumentor.getAnnotationsByType(JITypeMapping.class));
 127         targetClassReader.accept(ma, ClassReader.EXPAND_FRAMES);
 128 
 129        return cw.toByteArray();
< prev index next >