< prev index next >

src/jdk.jfr/share/classes/jdk/jfr/internal/EventClassBuilder.java

Print this page
rev 52456 : imported patch asm.additional


  40 import jdk.jfr.Event;
  41 import jdk.jfr.ValueDescriptor;
  42 
  43 
  44 // Helper class for building dynamic events
  45 public final class EventClassBuilder {
  46 
  47     private static final Type TYPE_EVENT = Type.getType(Event.class);
  48     private static final Type TYPE_IOBE = Type.getType(IndexOutOfBoundsException.class);
  49     private static final Method DEFAULT_CONSTRUCTOR = Method.getMethod("void <init> ()");
  50     private static final Method SET_METHOD = Method.getMethod("void set (int, java.lang.Object)");
  51     private static final AtomicLong idCounter = new AtomicLong();
  52     private final ClassWriter classWriter = new ClassWriter(ClassWriter.COMPUTE_MAXS | ClassWriter.COMPUTE_FRAMES);
  53     private final String fullClassName;
  54     private final Type type;
  55     private final List<ValueDescriptor> fields;
  56     private final List<AnnotationElement> annotationElements;
  57 
  58     public EventClassBuilder(List<AnnotationElement> annotationElements, List<ValueDescriptor> fields) {
  59         this.fullClassName = "jdk.jfr.DynamicEvent" + idCounter.incrementAndGet();
  60         this.type = Type.getType(fullClassName.replace(".", "/"));
  61         this.fields = fields;
  62         this.annotationElements = annotationElements;
  63     }
  64 
  65     public Class<? extends Event> build() {
  66         buildClassInfo();
  67         buildConstructor();
  68         buildFields();
  69         buildSetMethod();
  70         endClass();
  71         byte[] bytes = classWriter.toByteArray();
  72         ASMToolkit.logASM(fullClassName, bytes);
  73         return SecuritySupport.defineClass(Event.class, bytes).asSubclass(Event.class);
  74     }
  75 
  76     private void endClass() {
  77         classWriter.visitEnd();
  78     }
  79 
  80     private void buildSetMethod() {




  40 import jdk.jfr.Event;
  41 import jdk.jfr.ValueDescriptor;
  42 
  43 
  44 // Helper class for building dynamic events
  45 public final class EventClassBuilder {
  46 
  47     private static final Type TYPE_EVENT = Type.getType(Event.class);
  48     private static final Type TYPE_IOBE = Type.getType(IndexOutOfBoundsException.class);
  49     private static final Method DEFAULT_CONSTRUCTOR = Method.getMethod("void <init> ()");
  50     private static final Method SET_METHOD = Method.getMethod("void set (int, java.lang.Object)");
  51     private static final AtomicLong idCounter = new AtomicLong();
  52     private final ClassWriter classWriter = new ClassWriter(ClassWriter.COMPUTE_MAXS | ClassWriter.COMPUTE_FRAMES);
  53     private final String fullClassName;
  54     private final Type type;
  55     private final List<ValueDescriptor> fields;
  56     private final List<AnnotationElement> annotationElements;
  57 
  58     public EventClassBuilder(List<AnnotationElement> annotationElements, List<ValueDescriptor> fields) {
  59         this.fullClassName = "jdk.jfr.DynamicEvent" + idCounter.incrementAndGet();
  60         this.type = Type.getType("L" + fullClassName.replace(".", "/") + ";");
  61         this.fields = fields;
  62         this.annotationElements = annotationElements;
  63     }
  64 
  65     public Class<? extends Event> build() {
  66         buildClassInfo();
  67         buildConstructor();
  68         buildFields();
  69         buildSetMethod();
  70         endClass();
  71         byte[] bytes = classWriter.toByteArray();
  72         ASMToolkit.logASM(fullClassName, bytes);
  73         return SecuritySupport.defineClass(Event.class, bytes).asSubclass(Event.class);
  74     }
  75 
  76     private void endClass() {
  77         classWriter.visitEnd();
  78     }
  79 
  80     private void buildSetMethod() {


< prev index next >