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(type.getInternalName(), bytes, Event.class.getClassLoader()).asSubclass(Event.class);
74 }
75
76 private void endClass() {
77 classWriter.visitEnd();
78 }
79
80 private void buildSetMethod() {
81 GeneratorAdapter ga = new GeneratorAdapter(Opcodes.ACC_PUBLIC, SET_METHOD, null, null, classWriter);
82 int index = 0;
83 for (ValueDescriptor v : fields) {
84 ga.loadArg(0);
85 ga.visitLdcInsn(index);
86 Label notEqual = new Label();
87 ga.ifICmp(GeneratorAdapter.NE, notEqual);
88 ga.loadThis();
89 ga.loadArg(1);
90 Type fieldType = ASMToolkit.toType(v);
91 ga.unbox(ASMToolkit.toType(v));
92 ga.putField(type, v.getName(), fieldType);
93 ga.visitInsn(Opcodes.RETURN);
|
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() {
81 GeneratorAdapter ga = new GeneratorAdapter(Opcodes.ACC_PUBLIC, SET_METHOD, null, null, classWriter);
82 int index = 0;
83 for (ValueDescriptor v : fields) {
84 ga.loadArg(0);
85 ga.visitLdcInsn(index);
86 Label notEqual = new Label();
87 ga.ifICmp(GeneratorAdapter.NE, notEqual);
88 ga.loadThis();
89 ga.loadArg(1);
90 Type fieldType = ASMToolkit.toType(v);
91 ga.unbox(ASMToolkit.toType(v));
92 ga.putField(type, v.getName(), fieldType);
93 ga.visitInsn(Opcodes.RETURN);
|