jdk.jfr.internal.EventInstrumentation.FieldInfo Java Examples

The following examples show how to use jdk.jfr.internal.EventInstrumentation.FieldInfo. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: EventHandlerCreator.java    From dragonwell8_jdk with GNU General Public License v2.0 5 votes vote down vote up
public EventHandlerCreator(long id, List<SettingInfo> settingInfos, List<FieldInfo> fields) {
    this.classWriter = new ClassWriter(ClassWriter.COMPUTE_FRAMES | ClassWriter.COMPUTE_MAXS);
    this.className = makeEventHandlerName(id);
    this.internalClassName = ASMToolkit.getInternalName(className);
    this.settingInfos = settingInfos;
    this.fields = fields;
}
 
Example #2
Source File: EventHandlerCreator.java    From dragonwell8_jdk with GNU General Public License v2.0 5 votes vote down vote up
private static List<FieldInfo> createFieldInfos(Class<? extends Event> eventClass, EventType type) throws Error {
    List<FieldInfo> fieldInfos = new ArrayList<>();
    for (ValueDescriptor v : type.getFields()) {
        // Only value descriptors that are not fields on the event class.
        if (v != TypeLibrary.STACK_TRACE_FIELD && v != TypeLibrary.THREAD_FIELD) {
            String fieldName = PrivateAccess.getInstance().getFieldName(v);
            String fieldDescriptor = ASMToolkit.getDescriptor(v.getTypeName());
            Class<?> c = eventClass;
            String internalName = null;
            while (c != Event.class) {
                try {
                    Field field = c.getDeclaredField(fieldName);
                    if (c == eventClass || !Modifier.isPrivate(field.getModifiers())) {
                        internalName = ASMToolkit.getInternalName(c.getName());
                        break;
                    }
                } catch (NoSuchFieldException | SecurityException e) {
                    // ignore
                }
                c = c.getSuperclass();
            }
            if (internalName != null) {
                fieldInfos.add(new FieldInfo(fieldName, fieldDescriptor, internalName));
            } else {
                throw new InternalError("Could not locate field " + fieldName + " for event type" + type.getName());
            }
        }
    }
    return fieldInfos;
}
 
Example #3
Source File: EventHandlerCreator.java    From dragonwell8_jdk with GNU General Public License v2.0 5 votes vote down vote up
private void buildConstructor() {
    MethodVisitor mv = classWriter.visitMethod(Opcodes.ACC_PRIVATE, METHOD_EVENT_HANDLER_CONSTRUCTOR.getName(), makeConstructorDescriptor(settingInfos), null, null);
    mv.visitVarInsn(Opcodes.ALOAD, 0); // this
    mv.visitVarInsn(Opcodes.ILOAD, 1); // registered
    mv.visitVarInsn(Opcodes.ALOAD, 2); // event type
    mv.visitVarInsn(Opcodes.ALOAD, 3); // event control
    mv.visitMethodInsn(Opcodes.INVOKESPECIAL, Type.getInternalName(EventHandler.class), METHOD_EVENT_HANDLER_CONSTRUCTOR.getName(), METHOD_EVENT_HANDLER_CONSTRUCTOR.getDescriptor(), false);
    for (SettingInfo si : settingInfos) {
        mv.visitVarInsn(Opcodes.ALOAD, 0); // this
        mv.visitVarInsn(Opcodes.ALOAD, si.index + 4); // Setting Control
        mv.visitFieldInsn(Opcodes.PUTFIELD, internalClassName, si.fieldName, TYPE_SETTING_CONTROL.getDescriptor());
    }
    // initialized string field writers
    int fieldIndex = 0;
    for (FieldInfo field : fields) {
        if (field.isString()) {
            mv.visitVarInsn(Opcodes.ALOAD, 0);
            mv.visitVarInsn(Opcodes.ALOAD, 0);
            mv.visitMethodInsn(Opcodes.INVOKEVIRTUAL, Type.getInternalName(EventHandler.class), "createStringFieldWriter", "()" + TYPE_STRING_POOL.getDescriptor(), false);
            mv.visitFieldInsn(Opcodes.PUTFIELD, internalClassName, FIELD_PREFIX_STRING_POOL + fieldIndex, TYPE_STRING_POOL.getDescriptor());
        }
        fieldIndex++;
    }
    mv.visitInsn(Opcodes.RETURN);
    mv.visitMaxs(0, 0);
    mv.visitEnd();
}
 
Example #4
Source File: EventHandlerCreator.java    From dragonwell8_jdk with GNU General Public License v2.0 5 votes vote down vote up
private void buildClassInfo() {
    String internalSuperName = ASMToolkit.getInternalName(EventHandler.class.getName());
    classWriter.visit(CLASS_VERSION, Opcodes.ACC_PUBLIC + Opcodes.ACC_FINAL + Opcodes.ACC_SUPER, internalClassName, null, internalSuperName, null);
    for (SettingInfo si : settingInfos) {
        classWriter.visitField(Opcodes.ACC_PUBLIC + Opcodes.ACC_FINAL, si.fieldName, TYPE_SETTING_CONTROL.getDescriptor(), null, null);
    }
    int fieldIndex = 0;
    for (FieldInfo field : fields) {
        if (field.isString()) {
            classWriter.visitField(Opcodes.ACC_PRIVATE | Opcodes.ACC_FINAL, FIELD_PREFIX_STRING_POOL+ fieldIndex, TYPE_STRING_POOL.getDescriptor(), null, null);
        }
        fieldIndex++;
    }
}
 
Example #5
Source File: ASMToolkit.java    From dragonwell8_jdk with GNU General Public License v2.0 5 votes vote down vote up
public static Method makeWriteMethod(List<FieldInfo> fields) {
    StringBuilder sb = new StringBuilder();
    sb.append("(");
    for (FieldInfo v : fields) {
        if (!v.fieldName.equals(EventInstrumentation.FIELD_EVENT_THREAD) && !v.fieldName.equals(EventInstrumentation.FIELD_STACK_TRACE)) {
            sb.append(v.fieldDescriptor);
        }
    }
    sb.append(")V");
    return new Method("write", sb.toString());
}
 
Example #6
Source File: EventHandlerCreator.java    From TencentKona-8 with GNU General Public License v2.0 5 votes vote down vote up
public EventHandlerCreator(long id, List<SettingInfo> settingInfos, List<FieldInfo> fields) {
    this.classWriter = new ClassWriter(ClassWriter.COMPUTE_FRAMES | ClassWriter.COMPUTE_MAXS);
    this.className = makeEventHandlerName(id);
    this.internalClassName = ASMToolkit.getInternalName(className);
    this.settingInfos = settingInfos;
    this.fields = fields;
}
 
Example #7
Source File: EventHandlerCreator.java    From TencentKona-8 with GNU General Public License v2.0 5 votes vote down vote up
private static List<FieldInfo> createFieldInfos(Class<? extends Event> eventClass, EventType type) throws Error {
    List<FieldInfo> fieldInfos = new ArrayList<>();
    for (ValueDescriptor v : type.getFields()) {
        // Only value descriptors that are not fields on the event class.
        if (v != TypeLibrary.STACK_TRACE_FIELD && v != TypeLibrary.THREAD_FIELD) {
            String fieldName = PrivateAccess.getInstance().getFieldName(v);
            String fieldDescriptor = ASMToolkit.getDescriptor(v.getTypeName());
            Class<?> c = eventClass;
            String internalName = null;
            while (c != Event.class) {
                try {
                    Field field = c.getDeclaredField(fieldName);
                    if (c == eventClass || !Modifier.isPrivate(field.getModifiers())) {
                        internalName = ASMToolkit.getInternalName(c.getName());
                        break;
                    }
                } catch (NoSuchFieldException | SecurityException e) {
                    // ignore
                }
                c = c.getSuperclass();
            }
            if (internalName != null) {
                fieldInfos.add(new FieldInfo(fieldName, fieldDescriptor, internalName));
            } else {
                throw new InternalError("Could not locate field " + fieldName + " for event type" + type.getName());
            }
        }
    }
    return fieldInfos;
}
 
Example #8
Source File: EventHandlerCreator.java    From TencentKona-8 with GNU General Public License v2.0 5 votes vote down vote up
private void buildConstructor() {
    MethodVisitor mv = classWriter.visitMethod(Opcodes.ACC_PRIVATE, METHOD_EVENT_HANDLER_CONSTRUCTOR.getName(), makeConstructorDescriptor(settingInfos), null, null);
    mv.visitVarInsn(Opcodes.ALOAD, 0); // this
    mv.visitVarInsn(Opcodes.ILOAD, 1); // registered
    mv.visitVarInsn(Opcodes.ALOAD, 2); // event type
    mv.visitVarInsn(Opcodes.ALOAD, 3); // event control
    mv.visitMethodInsn(Opcodes.INVOKESPECIAL, Type.getInternalName(eventHandlerProxy), METHOD_EVENT_HANDLER_CONSTRUCTOR.getName(), METHOD_EVENT_HANDLER_CONSTRUCTOR.getDescriptor(), false);
    for (SettingInfo si : settingInfos) {
        mv.visitVarInsn(Opcodes.ALOAD, 0); // this
        mv.visitVarInsn(Opcodes.ALOAD, si.index + 4); // Setting Control
        mv.visitFieldInsn(Opcodes.PUTFIELD, internalClassName, si.fieldName, TYPE_SETTING_CONTROL.getDescriptor());
    }
    // initialized string field writers
    int fieldIndex = 0;
    for (FieldInfo field : fields) {
        if (field.isString()) {
            mv.visitVarInsn(Opcodes.ALOAD, 0);
            mv.visitVarInsn(Opcodes.ALOAD, 0);
            mv.visitMethodInsn(Opcodes.INVOKEVIRTUAL, Type.getInternalName(eventHandlerProxy), "createStringFieldWriter", "()" + TYPE_STRING_POOL.getDescriptor(), false);
            mv.visitFieldInsn(Opcodes.PUTFIELD, internalClassName, FIELD_PREFIX_STRING_POOL + fieldIndex, TYPE_STRING_POOL.getDescriptor());
        }
        fieldIndex++;
    }
    mv.visitInsn(Opcodes.RETURN);
    mv.visitMaxs(0, 0);
    mv.visitEnd();
}
 
Example #9
Source File: EventHandlerCreator.java    From TencentKona-8 with GNU General Public License v2.0 5 votes vote down vote up
private void buildClassInfo() {
    String internalSuperName = ASMToolkit.getInternalName(eventHandlerProxy.getName());
    classWriter.visit(CLASS_VERSION, Opcodes.ACC_PUBLIC + Opcodes.ACC_FINAL + Opcodes.ACC_SUPER, internalClassName, null, internalSuperName, null);
    for (SettingInfo si : settingInfos) {
        classWriter.visitField(Opcodes.ACC_PUBLIC + Opcodes.ACC_FINAL, si.fieldName, TYPE_SETTING_CONTROL.getDescriptor(), null, null);
    }
    int fieldIndex = 0;
    for (FieldInfo field : fields) {
        if (field.isString()) {
            classWriter.visitField(Opcodes.ACC_PRIVATE | Opcodes.ACC_FINAL, FIELD_PREFIX_STRING_POOL+ fieldIndex, TYPE_STRING_POOL.getDescriptor(), null, null);
        }
        fieldIndex++;
    }
}
 
Example #10
Source File: ASMToolkit.java    From TencentKona-8 with GNU General Public License v2.0 5 votes vote down vote up
public static Method makeWriteMethod(List<FieldInfo> fields) {
    StringBuilder sb = new StringBuilder();
    sb.append("(");
    for (FieldInfo v : fields) {
        if (!v.fieldName.equals(EventInstrumentation.FIELD_EVENT_THREAD) && !v.fieldName.equals(EventInstrumentation.FIELD_STACK_TRACE)) {
            sb.append(v.fieldDescriptor);
        }
    }
    sb.append(")V");
    return new Method("write", sb.toString());
}
 
Example #11
Source File: EventHandlerCreator.java    From openjdk-jdk8u with GNU General Public License v2.0 5 votes vote down vote up
public EventHandlerCreator(long id, List<SettingInfo> settingInfos, List<FieldInfo> fields) {
    this.classWriter = new ClassWriter(ClassWriter.COMPUTE_FRAMES | ClassWriter.COMPUTE_MAXS);
    this.className = makeEventHandlerName(id);
    this.internalClassName = ASMToolkit.getInternalName(className);
    this.settingInfos = settingInfos;
    this.fields = fields;
}
 
Example #12
Source File: EventHandlerCreator.java    From openjdk-jdk8u with GNU General Public License v2.0 5 votes vote down vote up
private static List<FieldInfo> createFieldInfos(Class<? extends Event> eventClass, EventType type) throws Error {
    List<FieldInfo> fieldInfos = new ArrayList<>();
    for (ValueDescriptor v : type.getFields()) {
        // Only value descriptors that are not fields on the event class.
        if (v != TypeLibrary.STACK_TRACE_FIELD && v != TypeLibrary.THREAD_FIELD) {
            String fieldName = PrivateAccess.getInstance().getFieldName(v);
            String fieldDescriptor = ASMToolkit.getDescriptor(v.getTypeName());
            Class<?> c = eventClass;
            String internalName = null;
            while (c != Event.class) {
                try {
                    Field field = c.getDeclaredField(fieldName);
                    if (c == eventClass || !Modifier.isPrivate(field.getModifiers())) {
                        internalName = ASMToolkit.getInternalName(c.getName());
                        break;
                    }
                } catch (NoSuchFieldException | SecurityException e) {
                    // ignore
                }
                c = c.getSuperclass();
            }
            if (internalName != null) {
                fieldInfos.add(new FieldInfo(fieldName, fieldDescriptor, internalName));
            } else {
                throw new InternalError("Could not locate field " + fieldName + " for event type" + type.getName());
            }
        }
    }
    return fieldInfos;
}
 
Example #13
Source File: EventHandlerCreator.java    From openjdk-jdk8u with GNU General Public License v2.0 5 votes vote down vote up
private void buildConstructor() {
    MethodVisitor mv = classWriter.visitMethod(Opcodes.ACC_PRIVATE, METHOD_EVENT_HANDLER_CONSTRUCTOR.getName(), makeConstructorDescriptor(settingInfos), null, null);
    mv.visitVarInsn(Opcodes.ALOAD, 0); // this
    mv.visitVarInsn(Opcodes.ILOAD, 1); // registered
    mv.visitVarInsn(Opcodes.ALOAD, 2); // event type
    mv.visitVarInsn(Opcodes.ALOAD, 3); // event control
    mv.visitMethodInsn(Opcodes.INVOKESPECIAL, Type.getInternalName(eventHandlerProxy), METHOD_EVENT_HANDLER_CONSTRUCTOR.getName(), METHOD_EVENT_HANDLER_CONSTRUCTOR.getDescriptor(), false);
    for (SettingInfo si : settingInfos) {
        mv.visitVarInsn(Opcodes.ALOAD, 0); // this
        mv.visitVarInsn(Opcodes.ALOAD, si.index + 4); // Setting Control
        mv.visitFieldInsn(Opcodes.PUTFIELD, internalClassName, si.fieldName, TYPE_SETTING_CONTROL.getDescriptor());
    }
    // initialized string field writers
    int fieldIndex = 0;
    for (FieldInfo field : fields) {
        if (field.isString()) {
            mv.visitVarInsn(Opcodes.ALOAD, 0);
            mv.visitVarInsn(Opcodes.ALOAD, 0);
            mv.visitMethodInsn(Opcodes.INVOKEVIRTUAL, Type.getInternalName(eventHandlerProxy), "createStringFieldWriter", "()" + TYPE_STRING_POOL.getDescriptor(), false);
            mv.visitFieldInsn(Opcodes.PUTFIELD, internalClassName, FIELD_PREFIX_STRING_POOL + fieldIndex, TYPE_STRING_POOL.getDescriptor());
        }
        fieldIndex++;
    }
    mv.visitInsn(Opcodes.RETURN);
    mv.visitMaxs(0, 0);
    mv.visitEnd();
}
 
Example #14
Source File: EventHandlerCreator.java    From openjdk-jdk8u with GNU General Public License v2.0 5 votes vote down vote up
private void buildClassInfo() {
    String internalSuperName = ASMToolkit.getInternalName(eventHandlerProxy.getName());
    classWriter.visit(CLASS_VERSION, Opcodes.ACC_PUBLIC + Opcodes.ACC_FINAL + Opcodes.ACC_SUPER, internalClassName, null, internalSuperName, null);
    for (SettingInfo si : settingInfos) {
        classWriter.visitField(Opcodes.ACC_PUBLIC + Opcodes.ACC_FINAL, si.fieldName, TYPE_SETTING_CONTROL.getDescriptor(), null, null);
    }
    int fieldIndex = 0;
    for (FieldInfo field : fields) {
        if (field.isString()) {
            classWriter.visitField(Opcodes.ACC_PRIVATE | Opcodes.ACC_FINAL, FIELD_PREFIX_STRING_POOL+ fieldIndex, TYPE_STRING_POOL.getDescriptor(), null, null);
        }
        fieldIndex++;
    }
}
 
Example #15
Source File: ASMToolkit.java    From openjdk-jdk8u with GNU General Public License v2.0 5 votes vote down vote up
public static Method makeWriteMethod(List<FieldInfo> fields) {
    StringBuilder sb = new StringBuilder();
    sb.append("(");
    for (FieldInfo v : fields) {
        if (!v.fieldName.equals(EventInstrumentation.FIELD_EVENT_THREAD) && !v.fieldName.equals(EventInstrumentation.FIELD_STACK_TRACE)) {
            sb.append(v.fieldDescriptor);
        }
    }
    sb.append(")V");
    return new Method("write", sb.toString());
}