jdk.jfr.internal.MetadataDescriptor.Element Java Examples

The following examples show how to use jdk.jfr.internal.MetadataDescriptor.Element. 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: MetadataReader.java    From dragonwell8_jdk with GNU General Public License v2.0 6 votes vote down vote up
public MetadataReader(DataInput input) throws IOException {
    this.input = input;
    int size = input.readInt();
    this.pool = new ArrayList<>(size);
    for (int i = 0; i < size; i++) {
        this.pool.add(input.readUTF());
    }
    descriptor = new MetadataDescriptor();
    Element root = createElement();
    Element metadata = root.elements("metadata").get(0);
    declareTypes(metadata);
    defineTypes(metadata);
    annotateTypes(metadata);
    buildEvenTypes();
    Element time = root.elements("region").get(0);
    descriptor.gmtOffset = time.attribute(MetadataDescriptor.ATTRIBUTE_GMT_OFFSET, 1);
    descriptor.locale = time.attribute(MetadataDescriptor.ATTRIBUTE_LOCALE, "");
    descriptor.root = root;
    if (LogTag.JFR_SYSTEM_PARSER.shouldLog(LogLevel.TRACE.level)) {
         List<Type> ts = new ArrayList<>(types.values());
         Collections.sort(ts, (x,y) -> x.getName().compareTo(y.getName()));
         for (Type t : ts) {
             t.log("Found", LogTag.JFR_SYSTEM_PARSER, LogLevel.TRACE);
         }
    }
}
 
Example #2
Source File: MetadataReader.java    From dragonwell8_jdk with GNU General Public License v2.0 6 votes vote down vote up
private void declareTypes(Element metadata) {
    for (Element typeElement : metadata.elements(ELEMENT_TYPE)) {
        String typeName = typeElement.attribute(ATTRIBUTE_NAME);
        String superType = typeElement.attribute(ATTRIBUTE_SUPER_TYPE);
        boolean simpleType = typeElement.attribute(ATTRIBUTE_SIMPLE_TYPE) != null;
        long id = typeElement.attribute(ATTRIBUTE_ID, -1);
        Type t;
        if (Type.SUPER_TYPE_EVENT.equals(superType)) {
            t = new PlatformEventType(typeName, id, false, false);
        } else {
            t = new Type(typeName, superType, id, false, simpleType);
        }
        types.put(id, t);
        descriptor.types.add(t);
    }
}
 
Example #3
Source File: MetadataReader.java    From TencentKona-8 with GNU General Public License v2.0 6 votes vote down vote up
private void declareTypes(Element metadata) {
    for (Element typeElement : metadata.elements(ELEMENT_TYPE)) {
        String typeName = typeElement.attribute(ATTRIBUTE_NAME);
        String superType = typeElement.attribute(ATTRIBUTE_SUPER_TYPE);
        boolean simpleType = typeElement.attribute(ATTRIBUTE_SIMPLE_TYPE) != null;
        long id = typeElement.attribute(ATTRIBUTE_ID, -1);
        Type t;
        if (Type.SUPER_TYPE_EVENT.equals(superType)) {
            t = new PlatformEventType(typeName, id, false, false);
        } else {
            t = new Type(typeName, superType, id, false, simpleType);
        }
        types.put(id, t);
        descriptor.types.add(t);
    }
}
 
Example #4
Source File: MetadataReader.java    From openjdk-jdk8u with GNU General Public License v2.0 6 votes vote down vote up
public MetadataReader(DataInput input) throws IOException {
    this.input = input;
    int size = input.readInt();
    this.pool = new ArrayList<>(size);
    for (int i = 0; i < size; i++) {
        this.pool.add(input.readUTF());
    }
    descriptor = new MetadataDescriptor();
    Element root = createElement();
    Element metadata = root.elements("metadata").get(0);
    declareTypes(metadata);
    defineTypes(metadata);
    annotateTypes(metadata);
    buildEvenTypes();
    Element time = root.elements("region").get(0);
    descriptor.gmtOffset = time.attribute(MetadataDescriptor.ATTRIBUTE_GMT_OFFSET, 1);
    descriptor.locale = time.attribute(MetadataDescriptor.ATTRIBUTE_LOCALE, "");
    descriptor.root = root;
    if (Logger.shouldLog(LogTag.JFR_SYSTEM_PARSER, LogLevel.TRACE)) {
         List<Type> ts = new ArrayList<>(types.values());
         Collections.sort(ts, (x,y) -> x.getName().compareTo(y.getName()));
         for (Type t : ts) {
             t.log("Found", LogTag.JFR_SYSTEM_PARSER, LogLevel.TRACE);
         }
    }
}
 
Example #5
Source File: MetadataReader.java    From openjdk-jdk8u with GNU General Public License v2.0 6 votes vote down vote up
private void declareTypes(Element metadata) {
    for (Element typeElement : metadata.elements(ELEMENT_TYPE)) {
        String typeName = typeElement.attribute(ATTRIBUTE_NAME);
        String superType = typeElement.attribute(ATTRIBUTE_SUPER_TYPE);
        boolean simpleType = typeElement.attribute(ATTRIBUTE_SIMPLE_TYPE) != null;
        long id = typeElement.attribute(ATTRIBUTE_ID, -1);
        Type t;
        if (Type.SUPER_TYPE_EVENT.equals(superType)) {
            t = new PlatformEventType(typeName, id, false, false);
        } else {
            t = new Type(typeName, superType, id, false, simpleType);
        }
        types.put(id, t);
        descriptor.types.add(t);
    }
}
 
Example #6
Source File: MetadataReader.java    From TencentKona-8 with GNU General Public License v2.0 6 votes vote down vote up
public MetadataReader(DataInput input) throws IOException {
    this.input = input;
    int size = input.readInt();
    this.pool = new ArrayList<>(size);
    for (int i = 0; i < size; i++) {
        this.pool.add(input.readUTF());
    }
    descriptor = new MetadataDescriptor();
    Element root = createElement();
    Element metadata = root.elements("metadata").get(0);
    declareTypes(metadata);
    defineTypes(metadata);
    annotateTypes(metadata);
    buildEvenTypes();
    Element time = root.elements("region").get(0);
    descriptor.gmtOffset = time.attribute(MetadataDescriptor.ATTRIBUTE_GMT_OFFSET, 1);
    descriptor.locale = time.attribute(MetadataDescriptor.ATTRIBUTE_LOCALE, "");
    descriptor.root = root;
    if (LogTag.JFR_SYSTEM_PARSER.shouldLog(LogLevel.TRACE.level)) {
         List<Type> ts = new ArrayList<>(types.values());
         Collections.sort(ts, (x,y) -> x.getName().compareTo(y.getName()));
         for (Type t : ts) {
             t.log("Found", LogTag.JFR_SYSTEM_PARSER, LogLevel.TRACE);
         }
    }
}
 
Example #7
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 #8
Source File: MetadataWriter.java    From TencentKona-8 with GNU General Public License v2.0 5 votes vote down vote up
private void buildStringPool(Element element, Set<String> pool) {
    pool.add(element.name);
    for (Attribute a : element.attributes) {
        pool.add(a.name);
        pool.add(a.value);
    }
    for (Element child : element.elements) {
        buildStringPool(child, pool);
    }
}
 
Example #9
Source File: MetadataWriter.java    From TencentKona-8 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 #10
Source File: MetadataReader.java    From openjdk-jdk8u with GNU General Public License v2.0 5 votes vote down vote up
private Element createElement() throws IOException {
    String name = readString();
    Element e = new Element(name);
    int attributeCount = readInt();
    for (int i = 0; i < attributeCount; i++) {
        e.addAttribute(readString(), readString());
    }
    int childrenCount = readInt();
    for (int i = 0; i < childrenCount; i++) {
        e.add(createElement());
    }
    return e;
}
 
Example #11
Source File: MetadataReader.java    From openjdk-jdk8u with GNU General Public License v2.0 5 votes vote down vote up
private Type getType(String attribute, Element element) {
    long id = element.longValue(attribute);
    Type type = types.get(id);
    if (type == null) {
        String name = element.attribute("type");
        throw new IllegalStateException("Type '" + id + "' is not defined for " + name);
    }
    return type;
}
 
Example #12
Source File: MetadataWriter.java    From openjdk-jdk8u with GNU General Public License v2.0 5 votes vote down vote up
public MetadataWriter(MetadataDescriptor descriptor) {
    descriptor.getTypes().forEach(type -> makeTypeElement(metadata, type));

    root.add(metadata);
    Element region = new Element("region");
    region.addAttribute(ATTRIBUTE_LOCALE, descriptor.locale);
    region.addAttribute(ATTRIBUTE_GMT_OFFSET, descriptor.gmtOffset);
    root.add(region);
}
 
Example #13
Source File: MetadataWriter.java    From openjdk-jdk8u with GNU General Public License v2.0 5 votes vote down vote up
private void buildStringPool(Element element, Set<String> pool) {
    pool.add(element.name);
    for (Attribute a : element.attributes) {
        pool.add(a.name);
        pool.add(a.value);
    }
    for (Element child : element.elements) {
        buildStringPool(child, pool);
    }
}
 
Example #14
Source File: MetadataWriter.java    From openjdk-jdk8u with GNU General Public License v2.0 5 votes vote down vote up
private void write(DataOutput output,Element element, HashMap<String, Integer> lookup) throws IOException {
    writeInt(output, lookup.get(element.name));
    writeInt(output, element.attributes.size());
    for (Attribute a : element.attributes) {
        writeInt(output, lookup.get(a.name));
        writeInt(output, lookup.get(a.value));
    }
    writeInt(output, element.elements.size());
    for (Element child : element.elements) {
        write(output, child, lookup);
    }
}
 
Example #15
Source File: MetadataWriter.java    From openjdk-jdk8u with GNU General Public License v2.0 5 votes vote down vote up
private void makeSettingElement(Element typeElement, SettingDescriptor s) {
    Element element = typeElement.newChild(ELEMENT_SETTING);
    element.addAttribute(ATTRIBUTE_NAME, s.getName());
    element.addAttribute(ATTRIBUTE_TYPE_ID, s.getTypeId());
    element.addAttribute(ATTRIBUTE_DEFAULT_VALUE, s.getDefaultValue());
    for (AnnotationElement a : s.getAnnotationElements()) {
        makeAnnotation(element, a);
    }
}
 
Example #16
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 #17
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 #18
Source File: MetadataWriter.java    From TencentKona-8 with GNU General Public License v2.0 5 votes vote down vote up
private void makeSettingElement(Element typeElement, SettingDescriptor s) {
    Element element = typeElement.newChild(ELEMENT_SETTING);
    element.addAttribute(ATTRIBUTE_NAME, s.getName());
    element.addAttribute(ATTRIBUTE_TYPE_ID, s.getTypeId());
    element.addAttribute(ATTRIBUTE_DEFAULT_VALUE, s.getDefaultValue());
    for (AnnotationElement a : s.getAnnotationElements()) {
        makeAnnotation(element, a);
    }
}
 
Example #19
Source File: MetadataWriter.java    From TencentKona-8 with GNU General Public License v2.0 5 votes vote down vote up
private void write(DataOutput output,Element element, HashMap<String, Integer> lookup) throws IOException {
    writeInt(output, lookup.get(element.name));
    writeInt(output, element.attributes.size());
    for (Attribute a : element.attributes) {
        writeInt(output, lookup.get(a.name));
        writeInt(output, lookup.get(a.value));
    }
    writeInt(output, element.elements.size());
    for (Element child : element.elements) {
        write(output, child, lookup);
    }
}
 
Example #20
Source File: MetadataWriter.java    From TencentKona-8 with GNU General Public License v2.0 5 votes vote down vote up
public MetadataWriter(MetadataDescriptor descriptor) {
    descriptor.getTypes().forEach(type -> makeTypeElement(metadata, type));

    root.add(metadata);
    Element region = new Element("region");
    region.addAttribute(ATTRIBUTE_LOCALE, descriptor.locale);
    region.addAttribute(ATTRIBUTE_GMT_OFFSET, descriptor.gmtOffset);
    root.add(region);
}
 
Example #21
Source File: MetadataReader.java    From TencentKona-8 with GNU General Public License v2.0 5 votes vote down vote up
private Type getType(String attribute, Element element) {
    long id = element.longValue(attribute);
    Type type = types.get(id);
    if (type == null) {
        String name = element.attribute("type");
        throw new IllegalStateException("Type '" + id + "' is not defined for " + name);
    }
    return type;
}
 
Example #22
Source File: MetadataReader.java    From TencentKona-8 with GNU General Public License v2.0 5 votes vote down vote up
private Element createElement() throws IOException {
    String name = readString();
    Element e = new Element(name);
    int attributeCount = readInt();
    for (int i = 0; i < attributeCount; i++) {
        e.addAttribute(readString(), readString());
    }
    int childrenCount = readInt();
    for (int i = 0; i < childrenCount; i++) {
        e.add(createElement());
    }
    return e;
}
 
Example #23
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 #24
Source File: MetadataWriter.java    From dragonwell8_jdk 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 #25
Source File: MetadataWriter.java    From dragonwell8_jdk with GNU General Public License v2.0 5 votes vote down vote up
private void makeSettingElement(Element typeElement, SettingDescriptor s) {
    Element element = typeElement.newChild(ELEMENT_SETTING);
    element.addAttribute(ATTRIBUTE_NAME, s.getName());
    element.addAttribute(ATTRIBUTE_TYPE_ID, s.getTypeId());
    element.addAttribute(ATTRIBUTE_DEFAULT_VALUE, s.getDefaultValue());
    for (AnnotationElement a : s.getAnnotationElements()) {
        makeAnnotation(element, a);
    }
}
 
Example #26
Source File: MetadataWriter.java    From dragonwell8_jdk with GNU General Public License v2.0 5 votes vote down vote up
private void write(DataOutput output,Element element, HashMap<String, Integer> lookup) throws IOException {
    writeInt(output, lookup.get(element.name));
    writeInt(output, element.attributes.size());
    for (Attribute a : element.attributes) {
        writeInt(output, lookup.get(a.name));
        writeInt(output, lookup.get(a.value));
    }
    writeInt(output, element.elements.size());
    for (Element child : element.elements) {
        write(output, child, lookup);
    }
}
 
Example #27
Source File: MetadataWriter.java    From dragonwell8_jdk with GNU General Public License v2.0 5 votes vote down vote up
private void buildStringPool(Element element, Set<String> pool) {
    pool.add(element.name);
    for (Attribute a : element.attributes) {
        pool.add(a.name);
        pool.add(a.value);
    }
    for (Element child : element.elements) {
        buildStringPool(child, pool);
    }
}
 
Example #28
Source File: MetadataWriter.java    From dragonwell8_jdk with GNU General Public License v2.0 5 votes vote down vote up
public MetadataWriter(MetadataDescriptor descriptor) {
    descriptor.getTypes().forEach(type -> makeTypeElement(metadata, type));
    root.add(metadata);
    Element region = new Element("region");
    region.addAttribute(ATTRIBUTE_LOCALE, descriptor.locale);
    region.addAttribute(ATTRIBUTE_GMT_OFFSET, descriptor.gmtOffset);
    root.add(region);
}
 
Example #29
Source File: MetadataReader.java    From dragonwell8_jdk with GNU General Public License v2.0 5 votes vote down vote up
private Type getType(String attribute, Element element) {
    long id = element.longValue(attribute);
    Type type = types.get(id);
    if (type == null) {
        String name = element.attribute("type");
        throw new IllegalStateException("Type '" + id + "' is not defined for " + name);
    }
    return type;
}
 
Example #30
Source File: MetadataReader.java    From dragonwell8_jdk with GNU General Public License v2.0 5 votes vote down vote up
private Element createElement() throws IOException {
    String name = readString();
    Element e = new Element(name);
    int attributeCount = readInt();
    for (int i = 0; i < attributeCount; i++) {
        e.addAttribute(readString(), readString());
    }
    int childrenCount = readInt();
    for (int i = 0; i < childrenCount; i++) {
        e.add(createElement());
    }
    return e;
}