< prev index next >

core/org.openjdk.jmc.agent/src/main/java/org/openjdk/jmc/agent/jfrnext/impl/JFRNextClassVisitor.java

Print this page




  70         @Override
  71         public void visitEnd() {
  72                 try {
  73                         reflectiveRegister(generateEventClass());
  74                 } catch (Exception e) {
  75                         Logger.getLogger(JFRNextClassVisitor.class.getName()).log(Level.SEVERE,
  76                                         "Failed to generate event class for " + transformDescriptor.toString(), e); //$NON-NLS-1$
  77                 }
  78                 super.visitEnd();
  79         }
  80 
  81         // NOTE: multi-release jars should let us compile against jdk9 and do a direct call here
  82         private void reflectiveRegister(Class<?> generateEventClass) throws Exception {
  83                 Class<?> jfr = Class.forName("jdk.jfr.FlightRecorder"); //$NON-NLS-1$
  84                 Method registerMethod = jfr.getDeclaredMethod("register", Class.class); //$NON-NLS-1$
  85                 registerMethod.invoke(null,  generateEventClass);               
  86         }
  87 
  88         private Class<?> generateEventClass() throws Exception {
  89                 byte[] eventClass = JFRNextEventClassGenerator.generateEventClass(transformDescriptor);
  90                 return TypeUtils.getUnsafe().defineClass(transformDescriptor.getEventClassName(), eventClass, 0,
  91                                 eventClass.length, definingClassLoader, protectionDomain);
  92         }
  93 }


  70         @Override
  71         public void visitEnd() {
  72                 try {
  73                         reflectiveRegister(generateEventClass());
  74                 } catch (Exception e) {
  75                         Logger.getLogger(JFRNextClassVisitor.class.getName()).log(Level.SEVERE,
  76                                         "Failed to generate event class for " + transformDescriptor.toString(), e); //$NON-NLS-1$
  77                 }
  78                 super.visitEnd();
  79         }
  80 
  81         // NOTE: multi-release jars should let us compile against jdk9 and do a direct call here
  82         private void reflectiveRegister(Class<?> generateEventClass) throws Exception {
  83                 Class<?> jfr = Class.forName("jdk.jfr.FlightRecorder"); //$NON-NLS-1$
  84                 Method registerMethod = jfr.getDeclaredMethod("register", Class.class); //$NON-NLS-1$
  85                 registerMethod.invoke(null,  generateEventClass);               
  86         }
  87 
  88         private Class<?> generateEventClass() throws Exception {
  89                 byte[] eventClass = JFRNextEventClassGenerator.generateEventClass(transformDescriptor);
  90                 return TypeUtils.defineClass(transformDescriptor.getEventClassName(), eventClass, 0,
  91                                 eventClass.length, definingClassLoader, protectionDomain);
  92         }
  93 }
< prev index next >