Java Code Examples for jdk.jfr.ValueDescriptor#getName()

The following examples show how to use jdk.jfr.ValueDescriptor#getName() . 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: TypeLibrary.java    From dragonwell8_jdk with GNU General Public License v2.0 6 votes vote down vote up
private static void addUserFields(Class<?> clazz, Type type, List<ValueDescriptor> dynamicFields) {
    Map<String, ValueDescriptor> dynamicFieldSet = new HashMap<>();
    for (ValueDescriptor dynamicField : dynamicFields) {
        dynamicFieldSet.put(dynamicField.getName(), dynamicField);
    }
    List<Type> newTypes = new ArrayList<>();
    for (Field field : Utils.getVisibleEventFields(clazz)) {
        ValueDescriptor vd = dynamicFieldSet.get(field.getName());
        if (vd != null) {
            if (!vd.getTypeName().equals(field.getType().getName())) {
                throw new InternalError("Type expected to match for field " + vd.getName() + " expected "  + field.getName() + " but got " + vd.getName());
            }
            for (AnnotationElement ae : vd.getAnnotationElements()) {
                newTypes.add(PrivateAccess.getInstance().getType(ae));
            }
            newTypes.add(PrivateAccess.getInstance().getType(vd));
        } else {
            vd = createField(field);
        }
        if (vd != null) {
            type.add(vd);
        }
    }
    addTypes(newTypes);
}
 
Example 2
Source File: TypeLibrary.java    From openjdk-jdk8u with GNU General Public License v2.0 6 votes vote down vote up
private static void addUserFields(Class<?> clazz, Type type, List<ValueDescriptor> dynamicFields) {
    Map<String, ValueDescriptor> dynamicFieldSet = new HashMap<>();
    for (ValueDescriptor dynamicField : dynamicFields) {
        dynamicFieldSet.put(dynamicField.getName(), dynamicField);
    }
    List<Type> newTypes = new ArrayList<>();
    for (Field field : Utils.getVisibleEventFields(clazz)) {
        ValueDescriptor vd = dynamicFieldSet.get(field.getName());
        if (vd != null) {
            if (!vd.getTypeName().equals(field.getType().getName())) {
                throw new InternalError("Type expected to match for field " + vd.getName() + " expected "  + field.getName() + " but got " + vd.getName());
            }
            for (AnnotationElement ae : vd.getAnnotationElements()) {
                newTypes.add(PrivateAccess.getInstance().getType(ae));
            }
            newTypes.add(PrivateAccess.getInstance().getType(vd));
        } else {
            vd = createField(field);
        }
        if (vd != null) {
            type.add(vd);
        }
    }
    addTypes(newTypes);
}
 
Example 3
Source File: XMLWriter.java    From openjdk-jdk8u with GNU General Public License v2.0 6 votes vote down vote up
private void printValueDescriptor(ValueDescriptor vd, Object value, int index) {
    boolean arrayElement = index != -1;
    String name = arrayElement ? null : vd.getName();
    if (vd.isArray() && !arrayElement) {
        if (printBeginElement("array", name, value, index)) {
            printArray(vd, (Object[]) value);
            printIndent();
            printEndElement("array");
        }
        return;
    }
    if (!vd.getFields().isEmpty()) {
        if (printBeginElement("struct", name, value, index)) {
            printObject((RecordedObject) value);
            printIndent();
            printEndElement("struct");
        }
        return;
    }
    if (printBeginElement("value", name, value, index)) {
        printEscaped(String.valueOf(value));
        printEndElement("value");
    }
}
 
Example 4
Source File: PrettyWriter.java    From openjdk-jdk8u with GNU General Public License v2.0 6 votes vote down vote up
public void print(RecordedEvent event) {
    currentEvent = event;
    print(event.getEventType().getName(), " ");
    println("{");
    indent();
    for (ValueDescriptor v : event.getFields()) {
        String name = v.getName();
        if (!isZeroDuration(event, name) && !isLateField(name)) {
            printFieldValue(event, v);
        }
    }
    if (event.getThread() != null) {
        printIndent();
        print(EVENT_THREAD_FIELD + " = ");
        printThread(event.getThread(), "");
    }
    if (event.getStackTrace() != null) {
        printIndent();
        print(STACK_TRACE_FIELD + " = ");
        printStackTrace(event.getStackTrace());
    }
    retract();
    printIndent();
    println("}");
    println();
}
 
Example 5
Source File: EventClassBuilder.java    From openjdk-jdk8u with GNU General Public License v2.0 6 votes vote down vote up
private void buildClassInfo() {
    String internalSuperName = ASMToolkit.getInternalName(Event.class.getName());
    String internalClassName = type.getInternalName();
    classWriter.visit(52, Opcodes.ACC_PUBLIC + Opcodes.ACC_FINAL + Opcodes.ACC_SUPER, internalClassName, null, internalSuperName, null);

    for (AnnotationElement a : annotationElements) {
        String descriptor = ASMToolkit.getDescriptor(a.getTypeName());
        AnnotationVisitor av = classWriter.visitAnnotation(descriptor, true);
        for (ValueDescriptor v : a.getValueDescriptors()) {
            Object value = a.getValue(v.getName());
            String name = v.getName();
            if (v.isArray()) {
                AnnotationVisitor arrayVisitor = av.visitArray(name);
                Object[] array = (Object[]) value;
                for (int i = 0; i < array.length; i++) {
                    arrayVisitor.visit(null, array[i]);
                }
                arrayVisitor.visitEnd();
            } else {
                av.visit(name, value);
            }
        }
        av.visitEnd();
    }
}
 
Example 6
Source File: TestEventMetadata.java    From TencentKona-8 with GNU General Public License v2.0 6 votes vote down vote up
public static void main(String[] args) throws Exception {
    Set<String> types = new HashSet<>();
    List<EventType> eventTypes = FlightRecorder.getFlightRecorder().getEventTypes();
    Set<String> eventNames= new HashSet<>();
    for (EventType eventType : eventTypes) {
        verifyEventType(eventType);
        verifyValueDesscriptors(eventType.getFields(), types);
        System.out.println();
        String eventName = eventType.getName();
        if (eventNames.contains(eventName)) {
            throw new Exception("Event with name " +eventName+ " already exists");
        }
        eventNames.add(eventName);
        Set<String> fieldNames = new HashSet<>();
        for (ValueDescriptor v : eventType.getFields()) {
            String fieldName = v.getName();
            if (fieldNames.contains(fieldName)) {
                throw new Exception("Field with name " + fieldName +" is already in use in event name " +eventName);
            }
            fieldNames.add(fieldName);
        }
    }
}
 
Example 7
Source File: TypeLibrary.java    From TencentKona-8 with GNU General Public License v2.0 6 votes vote down vote up
private static void addUserFields(Class<?> clazz, Type type, List<ValueDescriptor> dynamicFields) {
    Map<String, ValueDescriptor> dynamicFieldSet = new HashMap<>();
    for (ValueDescriptor dynamicField : dynamicFields) {
        dynamicFieldSet.put(dynamicField.getName(), dynamicField);
    }
    List<Type> newTypes = new ArrayList<>();
    for (Field field : Utils.getVisibleEventFields(clazz)) {
        ValueDescriptor vd = dynamicFieldSet.get(field.getName());
        if (vd != null) {
            if (!vd.getTypeName().equals(field.getType().getName())) {
                throw new InternalError("Type expected to match for field " + vd.getName() + " expected "  + field.getName() + " but got " + vd.getName());
            }
            for (AnnotationElement ae : vd.getAnnotationElements()) {
                newTypes.add(PrivateAccess.getInstance().getType(ae));
            }
            newTypes.add(PrivateAccess.getInstance().getType(vd));
        } else {
            vd = createField(field);
        }
        if (vd != null) {
            type.add(vd);
        }
    }
    addTypes(newTypes);
}
 
Example 8
Source File: XMLWriter.java    From TencentKona-8 with GNU General Public License v2.0 6 votes vote down vote up
private void printValueDescriptor(ValueDescriptor vd, Object value, int index) {
    boolean arrayElement = index != -1;
    String name = arrayElement ? null : vd.getName();
    if (vd.isArray() && !arrayElement) {
        if (printBeginElement("array", name, value, index)) {
            printArray(vd, (Object[]) value);
            printIndent();
            printEndElement("array");
        }
        return;
    }
    if (!vd.getFields().isEmpty()) {
        if (printBeginElement("struct", name, value, index)) {
            printObject((RecordedObject) value);
            printIndent();
            printEndElement("struct");
        }
        return;
    }
    if (printBeginElement("value", name, value, index)) {
        printEscaped(String.valueOf(value));
        printEndElement("value");
    }
}
 
Example 9
Source File: PrettyWriter.java    From TencentKona-8 with GNU General Public License v2.0 6 votes vote down vote up
public void print(RecordedEvent event) {
    currentEvent = event;
    print(event.getEventType().getName(), " ");
    println("{");
    indent();
    for (ValueDescriptor v : event.getFields()) {
        String name = v.getName();
        if (!isZeroDuration(event, name) && !isLateField(name)) {
            printFieldValue(event, v);
        }
    }
    if (event.getThread() != null) {
        printIndent();
        print(EVENT_THREAD_FIELD + " = ");
        printThread(event.getThread(), "");
    }
    if (event.getStackTrace() != null) {
        printIndent();
        print(STACK_TRACE_FIELD + " = ");
        printStackTrace(event.getStackTrace());
    }
    retract();
    printIndent();
    println("}");
    println();
}
 
Example 10
Source File: EventClassBuilder.java    From TencentKona-8 with GNU General Public License v2.0 6 votes vote down vote up
private void buildClassInfo() {
    String internalSuperName = ASMToolkit.getInternalName(Event.class.getName());
    String internalClassName = type.getInternalName();
    classWriter.visit(52, Opcodes.ACC_PUBLIC + Opcodes.ACC_FINAL + Opcodes.ACC_SUPER, internalClassName, null, internalSuperName, null);

    for (AnnotationElement a : annotationElements) {
        String descriptor = ASMToolkit.getDescriptor(a.getTypeName());
        AnnotationVisitor av = classWriter.visitAnnotation(descriptor, true);
        for (ValueDescriptor v : a.getValueDescriptors()) {
            Object value = a.getValue(v.getName());
            String name = v.getName();
            if (v.isArray()) {
                AnnotationVisitor arrayVisitor = av.visitArray(name);
                Object[] array = (Object[]) value;
                for (int i = 0; i < array.length; i++) {
                    arrayVisitor.visit(null, array[i]);
                }
                arrayVisitor.visitEnd();
            } else {
                av.visit(name, value);
            }
        }
        av.visitEnd();
    }
}
 
Example 11
Source File: TestEventMetadata.java    From dragonwell8_jdk with GNU General Public License v2.0 6 votes vote down vote up
public static void main(String[] args) throws Exception {
    Set<String> types = new HashSet<>();
    List<EventType> eventTypes = FlightRecorder.getFlightRecorder().getEventTypes();
    Set<String> eventNames= new HashSet<>();
    for (EventType eventType : eventTypes) {
        verifyEventType(eventType);
        verifyValueDesscriptors(eventType.getFields(), types);
        System.out.println();
        String eventName = eventType.getName();
        if (eventNames.contains(eventName)) {
            throw new Exception("Event with name " +eventName+ " already exists");
        }
        eventNames.add(eventName);
        Set<String> fieldNames = new HashSet<>();
        for (ValueDescriptor v : eventType.getFields()) {
            String fieldName = v.getName();
            if (fieldNames.contains(fieldName)) {
                throw new Exception("Field with name " + fieldName +" is already in use in event name " +eventName);
            }
            fieldNames.add(fieldName);
        }
    }
}
 
Example 12
Source File: TestEventMetadata.java    From openjdk-jdk8u with GNU General Public License v2.0 6 votes vote down vote up
public static void main(String[] args) throws Exception {
    Set<String> types = new HashSet<>();
    List<EventType> eventTypes = FlightRecorder.getFlightRecorder().getEventTypes();
    Set<String> eventNames= new HashSet<>();
    for (EventType eventType : eventTypes) {
        verifyEventType(eventType);
        verifyValueDesscriptors(eventType.getFields(), types);
        System.out.println();
        String eventName = eventType.getName();
        if (eventNames.contains(eventName)) {
            throw new Exception("Event with name " +eventName+ " already exists");
        }
        eventNames.add(eventName);
        Set<String> fieldNames = new HashSet<>();
        for (ValueDescriptor v : eventType.getFields()) {
            String fieldName = v.getName();
            if (fieldNames.contains(fieldName)) {
                throw new Exception("Field with name " + fieldName +" is already in use in event name " +eventName);
            }
            fieldNames.add(fieldName);
        }
    }
}
 
Example 13
Source File: Events.java    From dragonwell8_jdk with GNU General Public License v2.0 5 votes vote down vote up
public static void assertAnnotation(ValueDescriptor field, Class<? extends java.lang.annotation.Annotation> annotationClass, String value) throws Exception {
    AnnotationElement a = getAnnotation(field, annotationClass);
    Object v = a.getValue("value");
    if (!v.equals(value)) {
        throw new Exception("Expected " + annotationClass.getSimpleName() + " on field " + field.getName() + " to have value " + value + ", but got " + v);
    }
}
 
Example 14
Source File: Events.java    From TencentKona-8 with GNU General Public License v2.0 5 votes vote down vote up
public static void assertAnnotation(ValueDescriptor field, Class<? extends java.lang.annotation.Annotation> annotationClass, String value) throws Exception {
    AnnotationElement a = getAnnotation(field, annotationClass);
    Object v = a.getValue("value");
    if (!v.equals(value)) {
        throw new Exception("Expected " + annotationClass.getSimpleName() + " on field " + field.getName() + " to have value " + value + ", but got " + v);
    }
}
 
Example 15
Source File: TestPrintXML.java    From dragonwell8_jdk with GNU General Public License v2.0 5 votes vote down vote up
@SuppressWarnings("unchecked")
static boolean compare(Object eventObject, Object xmlObject) {
    if (eventObject == null) {
        return xmlObject == null;
    }
    if (eventObject instanceof RecordedObject) {
        RecordedObject re = (RecordedObject) eventObject;
        Map<String, Object> xmlMap = (Map<String, Object>) xmlObject;
        List<ValueDescriptor> fields = re.getFields();
        if (fields.size() != xmlMap.size()) {
            return false;
        }
        for (ValueDescriptor v : fields) {
            String name = v.getName();
            if (!compare(re.getValue(name), xmlMap.get(name))) {
                return false;
            }
        }
        return true;
    }
    if (eventObject.getClass().isArray()) {
        Object[] array = (Object[]) eventObject;
        Object[] xmlArray = (Object[]) xmlObject;
        if (array.length != xmlArray.length) {
            return false;
        }
        for (int i = 0; i < array.length; i++) {
            if (!compare(array[i], xmlArray[i])) {
                return false;
            }
        }
        return true;
    }
    String s1 = String.valueOf(eventObject);
    String s2 = (String) xmlObject;
    return s1.equals(s2);
}
 
Example 16
Source File: TestPrintXML.java    From TencentKona-8 with GNU General Public License v2.0 4 votes vote down vote up
@SuppressWarnings("unchecked")
static boolean compare(Object eventObject, Object xmlObject) {
    if (eventObject == null) {
        return xmlObject == null;
    }
    if (eventObject instanceof RecordedObject) {
        RecordedObject re = (RecordedObject) eventObject;
        Map<String, Object> xmlMap = (Map<String, Object>) xmlObject;
        List<ValueDescriptor> fields = re.getFields();
        if (fields.size() != xmlMap.size()) {
            return false;
        }
        for (ValueDescriptor v : fields) {
            String name = v.getName();
            Object xmlValue = xmlMap.get(name);
            Object expectedValue = re.getValue(name);
            if (v.getAnnotation(Timestamp.class) != null) {
                // Make instant of OffsetDateTime
                xmlValue = OffsetDateTime.parse("" + xmlValue).toInstant().toString();
                expectedValue = re.getInstant(name);
            }
            if (v.getAnnotation(Timespan.class) != null) {
                expectedValue = re.getDuration(name);
            }
            if (!compare(expectedValue, xmlValue)) {
                return false;
            }
        }
        return true;
    }
    if (eventObject.getClass().isArray()) {
        Object[] array = (Object[]) eventObject;
        Object[] xmlArray = (Object[]) xmlObject;
        if (array.length != xmlArray.length) {
            return false;
        }
        for (int i = 0; i < array.length; i++) {
            if (!compare(array[i], xmlArray[i])) {
                return false;
            }
        }
        return true;
    }
    String s1 = String.valueOf(eventObject);
    String s2 = (String) xmlObject;
    return s1.equals(s2);
}
 
Example 17
Source File: Events.java    From dragonwell8_jdk with GNU General Public License v2.0 4 votes vote down vote up
public static void hasAnnotation(ValueDescriptor field, Class<? extends java.lang.annotation.Annotation> annotationClass) throws Exception {
    AnnotationElement a = getAnnotation(field, annotationClass);
    if (a == null) {
        throw new Exception("Expected " + annotationClass.getSimpleName() + " on field " + field.getName());
    }
}
 
Example 18
Source File: Events.java    From TencentKona-8 with GNU General Public License v2.0 4 votes vote down vote up
public static void hasAnnotation(ValueDescriptor field, Class<? extends java.lang.annotation.Annotation> annotationClass) throws Exception {
    AnnotationElement a = getAnnotation(field, annotationClass);
    if (a == null) {
        throw new Exception("Expected " + annotationClass.getSimpleName() + " on field " + field.getName());
    }
}
 
Example 19
Source File: Events.java    From openjdk-jdk8u with GNU General Public License v2.0 4 votes vote down vote up
public static void hasAnnotation(ValueDescriptor field, Class<? extends java.lang.annotation.Annotation> annotationClass) throws Exception {
    AnnotationElement a = getAnnotation(field, annotationClass);
    if (a == null) {
        throw new Exception("Expected " + annotationClass.getSimpleName() + " on field " + field.getName());
    }
}
 
Example 20
Source File: TestPrintXML.java    From openjdk-jdk8u with GNU General Public License v2.0 4 votes vote down vote up
@SuppressWarnings("unchecked")
static boolean compare(Object eventObject, Object xmlObject) {
    if (eventObject == null) {
        return xmlObject == null;
    }
    if (eventObject instanceof RecordedObject) {
        RecordedObject re = (RecordedObject) eventObject;
        Map<String, Object> xmlMap = (Map<String, Object>) xmlObject;
        List<ValueDescriptor> fields = re.getFields();
        if (fields.size() != xmlMap.size()) {
            return false;
        }
        for (ValueDescriptor v : fields) {
            String name = v.getName();
            Object xmlValue = xmlMap.get(name);
            Object expectedValue = re.getValue(name);
            if (v.getAnnotation(Timestamp.class) != null) {
                // Make instant of OffsetDateTime
                xmlValue = OffsetDateTime.parse("" + xmlValue).toInstant().toString();
                expectedValue = re.getInstant(name);
            }
            if (v.getAnnotation(Timespan.class) != null) {
                expectedValue = re.getDuration(name);
            }
            if (!compare(expectedValue, xmlValue)) {
                return false;
            }
        }
        return true;
    }
    if (eventObject.getClass().isArray()) {
        Object[] array = (Object[]) eventObject;
        Object[] xmlArray = (Object[]) xmlObject;
        if (array.length != xmlArray.length) {
            return false;
        }
        for (int i = 0; i < array.length; i++) {
            if (!compare(array[i], xmlArray[i])) {
                return false;
            }
        }
        return true;
    }
    String s1 = String.valueOf(eventObject);
    String s2 = (String) xmlObject;
    return s1.equals(s2);
}