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

The following examples show how to use jdk.jfr.ValueDescriptor#isArray() . 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: 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 2
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 3
Source File: PrettyWriter.java    From openjdk-jdk8u with GNU General Public License v2.0 6 votes vote down vote up
private void printField(int commentIndex, ValueDescriptor v, boolean first) {
    if (!first) {
        println();
    }
    printAnnotations(commentIndex, v.getAnnotationElements());
    printIndent();
    Type vType = PrivateAccess.getInstance().getType(v);
    if (Type.SUPER_TYPE_SETTING.equals(vType.getSuperType())) {
        print("static ");
    }
    print(makeSimpleType(v.getTypeName()));
    if (v.isArray()) {
        print("[]");
    }
    print(" ");
    print(v.getName());
    print(";");
    printCommentRef(commentIndex, v.getTypeId());
}
 
Example 4
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 5
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 6
Source File: XMLWriter.java    From dragonwell8_jdk 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 7
Source File: PrettyWriter.java    From dragonwell8_jdk with GNU General Public License v2.0 6 votes vote down vote up
private void printField(int commentIndex, ValueDescriptor v) throws IOException {
    println();
    printAnnotations(commentIndex, v.getAnnotationElements());
    printIndent();
    Type vType = PrivateAccess.getInstance().getType(v);
    if (Type.SUPER_TYPE_SETTING.equals(vType.getSuperType())) {
        print("static ");
    }
    print(makeSimpleType(v.getTypeName()));
    if (v.isArray()) {
        print("[]");
    }
    print(" ");
    print(v.getName());
    print(";");
    printCommentRef(commentIndex, v.getTypeId());
}
 
Example 8
Source File: JSONWriter.java    From dragonwell8_jdk with GNU General Public License v2.0 6 votes vote down vote up
private void printValueDescriptor(boolean first, boolean arrayElement, ValueDescriptor vd, Object value) {
    if (vd.isArray() && !arrayElement) {
        printNewDataStructure(first, arrayElement, vd.getName());
        if (!printIfNull(value)) {
            printArray(vd, (Object[]) value);
        }
        return;
    }
    if (!vd.getFields().isEmpty()) {
        printNewDataStructure(first, arrayElement, vd.getName());
        if (!printIfNull(value)) {
            printObject((RecordedObject) value);
        }
        return;
    }
    printValue(first, arrayElement, vd.getName(), value);
}
 
Example 9
Source File: JSONWriter.java    From openjdk-jdk8u with GNU General Public License v2.0 6 votes vote down vote up
private void printValueDescriptor(boolean first, boolean arrayElement, ValueDescriptor vd, Object value) {
    if (vd.isArray() && !arrayElement) {
        printNewDataStructure(first, arrayElement, vd.getName());
        if (!printIfNull(value)) {
            printArray(vd, (Object[]) value);
        }
        return;
    }
    if (!vd.getFields().isEmpty()) {
        printNewDataStructure(first, arrayElement, vd.getName());
        if (!printIfNull(value)) {
            printObject((RecordedObject) value);
        }
        return;
    }
    printValue(first, arrayElement, vd.getName(), value);
}
 
Example 10
Source File: TestClasses.java    From dragonwell8_jdk with GNU General Public License v2.0 5 votes vote down vote up
public static void main(String[] args) throws Throwable {
    @SuppressWarnings("rawtypes")
    Map<String, Class> valid = new HashMap<>();
    valid.put("byte", byte.class);
    valid.put("short", short.class);
    valid.put("int", int.class);
    valid.put("char", char.class);
    valid.put("float", float.class);
    valid.put("double", double.class);
    valid.put("boolean", boolean.class);
    valid.put("double", double.class);
    valid.put("long", long.class);
    valid.put("java.lang.String", String.class);
    valid.put("java.lang.Class", Class.class);
    valid.put("java.lang.Thread", Thread.class);

    for (String name : valid.keySet()) {
        Class<?> t = valid.get(name);
        System.out.println(t.getName());
        ValueDescriptor d = new ValueDescriptor(t, "dummy");
        String typeName = d.getTypeName() + (d.isArray() ? "[]" : "");
        System.out.printf("%s -> typeName %s%n", name, typeName);
        Asserts.assertEquals(name, typeName, "Wrong type name");
    }

    // Test some illegal classes
    verifyIllegalArg(()->{new ValueDescriptor(Float.class, "ids");}, "Arrays of non-primitives should give Exception");
    verifyIllegalArg(()->{new ValueDescriptor(Integer[].class, "ids");}, "Arrays of non-primitives should give Exception");
    verifyIllegalArg(()->{new ValueDescriptor(Class[].class, "ids");}, "Arrays of non-primitives should give Exception");
    verifyIllegalArg(()->{new ValueDescriptor(MyClass.class, "MyClass");}, "MyClass should give Exception");
}
 
Example 11
Source File: ParserFactory.java    From TencentKona-8 with GNU General Public License v2.0 5 votes vote down vote up
private Parser createParser(ValueDescriptor v) throws IOException {
    boolean constantPool = PrivateAccess.getInstance().isConstantPool(v);
    if (v.isArray()) {
        Type valueType = PrivateAccess.getInstance().getType(v);
        ValueDescriptor element = PrivateAccess.getInstance().newValueDescriptor(v.getName(), valueType, v.getAnnotationElements(), 0, constantPool, null);
        return new ArrayParser(createParser(element));
    }
    long id = v.getTypeId();
    Type type = types.get(id);
    if (type == null) {
        throw new IOException("Type '" + v.getTypeName() + "' is not defined");
    }
    if (constantPool) {
        ConstantMap pool = constantPools.get(id);
        if (pool == null) {
            pool = new ConstantMap(ObjectFactory.create(type, timeConverter), type.getName());
            constantPools.put(id, pool);
        }
        return new ConstantMapValueParser(pool);
    }
    Parser parser = parsers.get(id);
    if (parser == null) {
        if (!v.getFields().isEmpty()) {
            return createCompositeParser(type);
        } else {
            return registerParserType(type, createPrimitiveParser(type));
        }
    }
    return parser;
}
 
Example 12
Source File: MetadataWriter.java    From openjdk-jdk8u with GNU General Public License v2.0 5 votes vote down vote up
private void makeFieldElement(Element typeElement, ValueDescriptor v) {
    Element element = typeElement.newChild(ELEMENT_FIELD);
    element.addAttribute(ATTRIBUTE_NAME, v.getName());
    element.addAttribute(ATTRIBUTE_TYPE_ID, v.getTypeId());
    if (v.isArray()) {
        element.addAttribute(ATTRIBUTE_DIMENSION, 1);
    }
    if (PrivateAccess.getInstance().isConstantPool(v)) {
        element.addAttribute(ATTRIBUTE_CONSTANT_POOL, true);
    }
    for (AnnotationElement a : v.getAnnotationElements()) {
        makeAnnotation(element, a);
    }
}
 
Example 13
Source File: Type.java    From TencentKona-8 with GNU General Public License v2.0 5 votes vote down vote up
void log(String action, LogTag logTag, LogLevel level) {
    if (logTag.shouldLog(level.level) && !isSimpleType()) {
        Logger.log(logTag, LogLevel.TRACE, action + " " + typeText() + " " + getLogName() + " {");
        for (ValueDescriptor v : getFields()) {
            String array = v.isArray() ? "[]" : "";
            Logger.log(logTag, LogLevel.TRACE, "  " + v.getTypeName() + array + " " + v.getName() + ";");
        }
        Logger.log(logTag, LogLevel.TRACE, "}");
    } else {
        if (logTag.shouldLog(LogLevel.INFO.level) && !isSimpleType()) {
            Logger.log(logTag, LogLevel.INFO, action + " " + typeText() + " " + getLogName());
        }
    }
}
 
Example 14
Source File: TestClasses.java    From openjdk-jdk8u with GNU General Public License v2.0 5 votes vote down vote up
public static void main(String[] args) throws Throwable {
    @SuppressWarnings("rawtypes")
    Map<String, Class> valid = new HashMap<>();
    valid.put("byte", byte.class);
    valid.put("short", short.class);
    valid.put("int", int.class);
    valid.put("char", char.class);
    valid.put("float", float.class);
    valid.put("double", double.class);
    valid.put("boolean", boolean.class);
    valid.put("double", double.class);
    valid.put("long", long.class);
    valid.put("java.lang.String", String.class);
    valid.put("java.lang.Class", Class.class);
    valid.put("java.lang.Thread", Thread.class);

    for (String name : valid.keySet()) {
        Class<?> t = valid.get(name);
        System.out.println(t.getName());
        ValueDescriptor d = new ValueDescriptor(t, "dummy");
        String typeName = d.getTypeName() + (d.isArray() ? "[]" : "");
        System.out.printf("%s -> typeName %s%n", name, typeName);
        Asserts.assertEquals(name, typeName, "Wrong type name");
    }

    // Test some illegal classes
    verifyIllegalArg(()->{new ValueDescriptor(Float.class, "ids");}, "Arrays of non-primitives should give Exception");
    verifyIllegalArg(()->{new ValueDescriptor(Integer[].class, "ids");}, "Arrays of non-primitives should give Exception");
    verifyIllegalArg(()->{new ValueDescriptor(Class[].class, "ids");}, "Arrays of non-primitives should give Exception");
    verifyIllegalArg(()->{new ValueDescriptor(MyClass.class, "MyClass");}, "MyClass should give Exception");
}
 
Example 15
Source File: MetadataWriter.java    From dragonwell8_jdk with GNU General Public License v2.0 5 votes vote down vote up
private void makeAnnotation(Element entity, AnnotationElement annotation) {
    Element element = entity.newChild(ELEMENT_ANNOTATION);
    element.addAttribute(ATTRIBUTE_TYPE_ID, annotation.getTypeId());
    List<Object> values = annotation.getValues();
    int index = 0;
    for (ValueDescriptor v : annotation.getValueDescriptors()) {
        Object value = values.get(index++);
        if (v.isArray()) {
            element.addArrayAttribute(element, v.getName(), value);
        } else {
            element.addAttribute(v.getName(), value);
        }
    }
}
 
Example 16
Source File: MetadataWriter.java    From openjdk-jdk8u with GNU General Public License v2.0 5 votes vote down vote up
private void makeAnnotation(Element entity, AnnotationElement annotation) {
    Element element = entity.newChild(ELEMENT_ANNOTATION);
    element.addAttribute(ATTRIBUTE_TYPE_ID, annotation.getTypeId());
    List<Object> values = annotation.getValues();
    int index = 0;
    for (ValueDescriptor v : annotation.getValueDescriptors()) {
        Object value = values.get(index++);
        if (v.isArray()) {
            element.addArrayAttribute(element, v.getName(), value);
        } else {
            element.addAttribute(v.getName(), value);
        }
    }
}
 
Example 17
Source File: MetadataWriter.java    From TencentKona-8 with GNU General Public License v2.0 5 votes vote down vote up
private void makeFieldElement(Element typeElement, ValueDescriptor v) {
    Element element = typeElement.newChild(ELEMENT_FIELD);
    element.addAttribute(ATTRIBUTE_NAME, v.getName());
    element.addAttribute(ATTRIBUTE_TYPE_ID, v.getTypeId());
    if (v.isArray()) {
        element.addAttribute(ATTRIBUTE_DIMENSION, 1);
    }
    if (PrivateAccess.getInstance().isConstantPool(v)) {
        element.addAttribute(ATTRIBUTE_CONSTANT_POOL, true);
    }
    for (AnnotationElement a : v.getAnnotationElements()) {
        makeAnnotation(element, a);
    }
}
 
Example 18
Source File: Type.java    From dragonwell8_jdk with GNU General Public License v2.0 5 votes vote down vote up
void log(String action, LogTag logTag, LogLevel level) {
    if (logTag.shouldLog(level.level) && !isSimpleType()) {
        Logger.log(logTag, LogLevel.TRACE, action + " " + typeText() + " " + getLogName() + " {");
        for (ValueDescriptor v : getFields()) {
            String array = v.isArray() ? "[]" : "";
            Logger.log(logTag, LogLevel.TRACE, "  " + v.getTypeName() + array + " " + v.getName() + ";");
        }
        Logger.log(logTag, LogLevel.TRACE, "}");
    } else {
        if (logTag.shouldLog(LogLevel.INFO.level) && !isSimpleType()) {
            Logger.log(logTag, LogLevel.INFO, action + " " + typeText() + " " + getLogName());
        }
    }
}
 
Example 19
Source File: TestClasses.java    From TencentKona-8 with GNU General Public License v2.0 5 votes vote down vote up
public static void main(String[] args) throws Throwable {
    @SuppressWarnings("rawtypes")
    Map<String, Class> valid = new HashMap<>();
    valid.put("byte", byte.class);
    valid.put("short", short.class);
    valid.put("int", int.class);
    valid.put("char", char.class);
    valid.put("float", float.class);
    valid.put("double", double.class);
    valid.put("boolean", boolean.class);
    valid.put("double", double.class);
    valid.put("long", long.class);
    valid.put("java.lang.String", String.class);
    valid.put("java.lang.Class", Class.class);
    valid.put("java.lang.Thread", Thread.class);

    for (String name : valid.keySet()) {
        Class<?> t = valid.get(name);
        System.out.println(t.getName());
        ValueDescriptor d = new ValueDescriptor(t, "dummy");
        String typeName = d.getTypeName() + (d.isArray() ? "[]" : "");
        System.out.printf("%s -> typeName %s%n", name, typeName);
        Asserts.assertEquals(name, typeName, "Wrong type name");
    }

    // Test some illegal classes
    verifyIllegalArg(()->{new ValueDescriptor(Float.class, "ids");}, "Arrays of non-primitives should give Exception");
    verifyIllegalArg(()->{new ValueDescriptor(Integer[].class, "ids");}, "Arrays of non-primitives should give Exception");
    verifyIllegalArg(()->{new ValueDescriptor(Class[].class, "ids");}, "Arrays of non-primitives should give Exception");
    verifyIllegalArg(()->{new ValueDescriptor(MyClass.class, "MyClass");}, "MyClass should give Exception");
}
 
Example 20
Source File: ParserFactory.java    From openjdk-jdk8u with GNU General Public License v2.0 5 votes vote down vote up
private Parser createParser(ValueDescriptor v) throws IOException {
    boolean constantPool = PrivateAccess.getInstance().isConstantPool(v);
    if (v.isArray()) {
        Type valueType = PrivateAccess.getInstance().getType(v);
        ValueDescriptor element = PrivateAccess.getInstance().newValueDescriptor(v.getName(), valueType, v.getAnnotationElements(), 0, constantPool, null);
        return new ArrayParser(createParser(element));
    }
    long id = v.getTypeId();
    Type type = types.get(id);
    if (type == null) {
        throw new IOException("Type '" + v.getTypeName() + "' is not defined");
    }
    if (constantPool) {
        ConstantMap pool = constantPools.get(id);
        if (pool == null) {
            pool = new ConstantMap(ObjectFactory.create(type, timeConverter), type.getName());
            constantPools.put(id, pool);
        }
        return new ConstantMapValueParser(pool);
    }
    Parser parser = parsers.get(id);
    if (parser == null) {
        if (!v.getFields().isEmpty()) {
            return createCompositeParser(type);
        } else {
            return registerParserType(type, createPrimitiveParser(type));
        }
    }
    return parser;
}