jdk.jfr.internal.Type Java Examples

The following examples show how to use jdk.jfr.internal.Type. 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: FlightRecorderPermission.java    From openjdk-jdk8u with GNU General Public License v2.0 6 votes vote down vote up
@Override
public Type getType(Object o) {
    if (o instanceof AnnotationElement) {
        return ((AnnotationElement) o).getType();
    }
    if (o instanceof EventType) {
        return ((EventType) o).getType();
    }
    if (o instanceof ValueDescriptor) {
        return ((ValueDescriptor) o).getType();
    }
    if (o instanceof SettingDescriptor) {
        return ((SettingDescriptor) o).getType();
    }
    throw new Error("Unknown type " + o.getClass());
}
 
Example #2
Source File: Metadata.java    From openjdk-jdk8u with GNU General Public License v2.0 6 votes vote down vote up
int groupValue(Type t) {
    String superType = t.getSuperType();
    if (superType == null) {
        return 1;
    }
    if (Type.SUPER_TYPE_ANNOTATION.equals(superType)) {
        return 3;
    }
    if (Type.SUPER_TYPE_SETTING.equals(superType)) {
        return 4;
    }
    if (Type.SUPER_TYPE_EVENT.equals(superType)) {
        return 5;
    }
    return 2; // reserved for enums in the future
}
 
Example #3
Source File: DCmdStart.java    From TencentKona-8 with GNU General Public License v2.0 6 votes vote down vote up
private boolean hasJDKEvents(Map<String, String> settings) {
    String[] eventNames = new String[7];
    eventNames[0] = "FileRead";
    eventNames[1] = "FileWrite";
    eventNames[2] = "SocketRead";
    eventNames[3] = "SocketWrite";
    eventNames[4] = "JavaErrorThrow";
    eventNames[5] = "JavaExceptionThrow";
    eventNames[6] = "FileForce";
    for (String eventName : eventNames) {
        if ("true".equals(settings.get(Type.EVENT_NAME_PREFIX + eventName + "#enabled"))) {
            return true;
        }
    }
    return false;
}
 
Example #4
Source File: ParserFactory.java    From openjdk-jdk8u with GNU General Public License v2.0 6 votes vote down vote up
private Parser createPrimitiveParser(Type type) throws IOException {
    switch (type.getName()) {
    case "int":
        return new IntegerParser();
    case "long":
        return new LongParser();
    case "float":
        return new FloatParser();
    case "double":
        return new DoubleParser();
    case "char":
        return new CharacterParser();
    case "boolean":
        return new BooleanParser();
    case "short":
        return new ShortParser();
    case "byte":
        return new ByteParser();
    case "java.lang.String":
        ConstantMap pool = new ConstantMap(ObjectFactory.create(type, timeConverter), type.getName());
        constantPools.put(type.getId(), pool);
        return new StringParser(pool);
    default:
        throw new IOException("Unknown primitive type " + type.getName());
    }
}
 
Example #5
Source File: ParserFactory.java    From dragonwell8_jdk with GNU General Public License v2.0 6 votes vote down vote up
private Parser createPrimitiveParser(Type type) throws IOException {
    switch (type.getName()) {
    case "int":
        return new IntegerParser();
    case "long":
        return new LongParser();
    case "float":
        return new FloatParser();
    case "double":
        return new DoubleParser();
    case "char":
        return new CharacterParser();
    case "boolean":
        return new BooleanParser();
    case "short":
        return new ShortParser();
    case "byte":
        return new ByteParser();
    case "java.lang.String":
        ConstantMap pool = new ConstantMap(ObjectFactory.create(type, timeConverter), type.getName());
        constantPools.put(type.getId(), pool);
        return new StringParser(pool);
    default:
        throw new IOException("Unknown primitive type " + type.getName());
    }
}
 
Example #6
Source File: ObjectFactory.java    From openjdk-jdk8u with GNU General Public License v2.0 6 votes vote down vote up
public static ObjectFactory<?> create(Type type, TimeConverter timeConverter) {
    switch (type.getName()) {
    case "java.lang.Thread":
        return RecordedThread.createFactory(type, timeConverter);
    case TYPE_PREFIX_VERSION_1 + "StackFrame":
    case TYPE_PREFIX_VERSION_2 + "StackFrame":
        return RecordedFrame.createFactory(type, timeConverter);
    case TYPE_PREFIX_VERSION_1 + "Method":
    case TYPE_PREFIX_VERSION_2 + "Method":
        return RecordedMethod.createFactory(type, timeConverter);
    case TYPE_PREFIX_VERSION_1 + "ThreadGroup":
    case TYPE_PREFIX_VERSION_2 + "ThreadGroup":
        return RecordedThreadGroup.createFactory(type, timeConverter);
    case TYPE_PREFIX_VERSION_1 + "StackTrace":
    case TYPE_PREFIX_VERSION_2 + "StackTrace":
        return RecordedStackTrace.createFactory(type, timeConverter);
    case TYPE_PREFIX_VERSION_1 + "ClassLoader":
    case TYPE_PREFIX_VERSION_2 + "ClassLoader":
        return RecordedClassLoader.createFactory(type, timeConverter);
    case "java.lang.Class":
        return RecordedClass.createFactory(type, timeConverter);
    }
    return null;
}
 
Example #7
Source File: PrettyWriter.java    From TencentKona-8 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 #8
Source File: Metadata.java    From TencentKona-8 with GNU General Public License v2.0 6 votes vote down vote up
int groupValue(Type t) {
    String superType = t.getSuperType();
    if (superType == null) {
        return 1;
    }
    if (Type.SUPER_TYPE_ANNOTATION.equals(superType)) {
        return 3;
    }
    if (Type.SUPER_TYPE_SETTING.equals(superType)) {
        return 4;
    }
    if (Type.SUPER_TYPE_EVENT.equals(superType)) {
        return 5;
    }
    return 2; // reserved for enums in the future
}
 
Example #9
Source File: ObjectFactory.java    From dragonwell8_jdk with GNU General Public License v2.0 6 votes vote down vote up
public static ObjectFactory<?> create(Type type, TimeConverter timeConverter) {
    switch (type.getName()) {
    case "java.lang.Thread":
        return RecordedThread.createFactory(type, timeConverter);
    case Type.ORACLE_TYPE_PREFIX + "StackFrame":
        return RecordedFrame.createFactory(type, timeConverter);
    case Type.ORACLE_TYPE_PREFIX + "Method":
        return RecordedMethod.createFactory(type, timeConverter);
    case Type.ORACLE_TYPE_PREFIX + "ThreadGroup":
        return RecordedThreadGroup.createFactory(type, timeConverter);
    case Type.ORACLE_TYPE_PREFIX + "StackTrace":
        return RecordedStackTrace.createFactory(type, timeConverter);
    case Type.ORACLE_TYPE_PREFIX + "ClassLoader":
        return RecordedClassLoader.createFactory(type, timeConverter);
    case "java.lang.Class":
        return RecordedClass.createFactory(type, timeConverter);
    }
    return null;
}
 
Example #10
Source File: RecordedObject.java    From dragonwell8_jdk with GNU General Public License v2.0 6 votes vote down vote up
private Object[] structifyArray(ValueDescriptor v, Object[] array, int dimension) {
    if (array == null) {
        return null;
    }
    Object[] structArray = new Object[array.length];
    for (int i = 0; i < structArray.length; i++) {
        Object arrayElement = array[i];
        if (dimension == 0) {
            // Hack, no general way to handle structarrays
            // without invoking ObjectFarctory for every instance.
            if ((Type.ORACLE_TYPE_PREFIX + "StackFrame").equals(v.getTypeName())) {
                structArray[i] = new RecordedFrame(v.getFields(), (Object[]) arrayElement, timeConverter);
            } else {
                structArray[i] = new RecordedObject(v.getFields(), (Object[]) arrayElement, timeConverter);
            }
        } else {
            structArray[i] = structifyArray(v, (Object[]) arrayElement, dimension - 1);
        }
    }
    return structArray;
}
 
Example #11
Source File: FlightRecorderPermission.java    From TencentKona-8 with GNU General Public License v2.0 6 votes vote down vote up
@Override
public Type getType(Object o) {
    if (o instanceof AnnotationElement) {
        return ((AnnotationElement) o).getType();
    }
    if (o instanceof EventType) {
        return ((EventType) o).getType();
    }
    if (o instanceof ValueDescriptor) {
        return ((ValueDescriptor) o).getType();
    }
    if (o instanceof SettingDescriptor) {
        return ((SettingDescriptor) o).getType();
    }
    throw new Error("Unknown type " + o.getClass());
}
 
Example #12
Source File: ObjectFactory.java    From TencentKona-8 with GNU General Public License v2.0 6 votes vote down vote up
public static ObjectFactory<?> create(Type type, TimeConverter timeConverter) {
    switch (type.getName()) {
    case "java.lang.Thread":
        return RecordedThread.createFactory(type, timeConverter);
    case TYPE_PREFIX_VERSION_1 + "StackFrame":
    case TYPE_PREFIX_VERSION_2 + "StackFrame":
        return RecordedFrame.createFactory(type, timeConverter);
    case TYPE_PREFIX_VERSION_1 + "Method":
    case TYPE_PREFIX_VERSION_2 + "Method":
        return RecordedMethod.createFactory(type, timeConverter);
    case TYPE_PREFIX_VERSION_1 + "ThreadGroup":
    case TYPE_PREFIX_VERSION_2 + "ThreadGroup":
        return RecordedThreadGroup.createFactory(type, timeConverter);
    case TYPE_PREFIX_VERSION_1 + "StackTrace":
    case TYPE_PREFIX_VERSION_2 + "StackTrace":
        return RecordedStackTrace.createFactory(type, timeConverter);
    case TYPE_PREFIX_VERSION_1 + "ClassLoader":
    case TYPE_PREFIX_VERSION_2 + "ClassLoader":
        return RecordedClassLoader.createFactory(type, timeConverter);
    case "java.lang.Class":
        return RecordedClass.createFactory(type, timeConverter);
    }
    return null;
}
 
Example #13
Source File: PrettyWriter.java    From dragonwell8_jdk with GNU General Public License v2.0 6 votes vote down vote up
void print(Path source) throws FileNotFoundException, IOException {
    try (RecordingInput input = new RecordingInput(source.toFile())) {
        HashSet<Type> typeSet = new HashSet<>();
        for (ChunkHeader ch = new ChunkHeader(input); !ch.isLastChunk(); ch = ch.nextHeader()) {
            typeSet.addAll(ch.readMetadata().getTypes());
        }
        List<Type> types = new ArrayList<>(typeSet);
        Collections.sort(types, (c1, c2) -> Long.compare(c1.getId(), c2.getId()));
        for (Type t : types) {
            printType(t);
        }
        flush();
    }

    try (RecordingFile es = new RecordingFile(source)) {
        while (es.hasMoreEvents()) {
            print(es.readEvent());
            flush();
        }
    }
    flush();
}
 
Example #14
Source File: PrettyWriter.java    From dragonwell8_jdk with GNU General Public License v2.0 6 votes vote down vote up
private void printType(Type t) throws IOException {
    print("// id: ");
    println(String.valueOf(t.getId()));
    int commentIndex = t.getName().length() + 10;
    String typeName = t.getName();
    int index = typeName.lastIndexOf(".");
    if (index != -1) {
        println("package " + typeName.substring(0, index) + ";");
    }
    printAnnotations(commentIndex, t.getAnnotationElements());
    print("class " + typeName.substring(index + 1));
    String superType = t.getSuperType();
    if (superType != null) {
        print(" extends " + superType);
    }
    println(" {");
    indent();
    for (ValueDescriptor v : t.getFields()) {
        printField(commentIndex, v);
    }
    retract();
    println("}");
    println();
}
 
Example #15
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 #16
Source File: DCmdStart.java    From dragonwell8_jdk with GNU General Public License v2.0 6 votes vote down vote up
private boolean hasJDKEvents(Map<String, String> settings) {
    String[] eventNames = new String[7];
    eventNames[0] = "FileRead";
    eventNames[1] = "FileWrite";
    eventNames[2] = "SocketRead";
    eventNames[3] = "SocketWrite";
    eventNames[4] = "JavaErrorThrow";
    eventNames[5] = "JavaExceptionThrow";
    eventNames[6] = "FileForce";
    for (String eventName : eventNames) {
        if ("true".equals(settings.get(Type.ORACLE_EVENT_PREFIX + eventName + "#enabled"))) {
            return true;
        }
    }
    return false;
}
 
Example #17
Source File: ParserFactory.java    From TencentKona-8 with GNU General Public License v2.0 6 votes vote down vote up
private Parser createPrimitiveParser(Type type) throws IOException {
    switch (type.getName()) {
    case "int":
        return new IntegerParser();
    case "long":
        return new LongParser();
    case "float":
        return new FloatParser();
    case "double":
        return new DoubleParser();
    case "char":
        return new CharacterParser();
    case "boolean":
        return new BooleanParser();
    case "short":
        return new ShortParser();
    case "byte":
        return new ByteParser();
    case "java.lang.String":
        ConstantMap pool = new ConstantMap(ObjectFactory.create(type, timeConverter), type.getName());
        constantPools.put(type.getId(), pool);
        return new StringParser(pool);
    default:
        throw new IOException("Unknown primitive type " + type.getName());
    }
}
 
Example #18
Source File: Metadata.java    From TencentKona-8 with GNU General Public License v2.0 5 votes vote down vote up
@Override
public void execute(Deque<String> options) throws UserSyntaxException, UserDataException {
    Path file = getJFRInputFile(options);

    boolean showIds = false;
    int optionCount = options.size();
    while (optionCount > 0) {
        if (acceptOption(options, "--ids")) {
            showIds = true;
        }
        if (optionCount == options.size()) {
            // No progress made
            throw new UserSyntaxException("unknown option " + options.peek());
        }
        optionCount = options.size();
    }

    try (PrintWriter pw = new PrintWriter(System.out)) {
        PrettyWriter prettyWriter = new PrettyWriter(pw);
        prettyWriter.setShowIds(showIds);
        try (RecordingFile rf = new RecordingFile(file)) {
            List<Type> types = RecordingInternals.INSTANCE.readTypes(rf);
            Collections.sort(types, new TypeComparator());
            for (Type type : types) {
                prettyWriter.printType(type);
            }
            prettyWriter.flush(true);
        } catch (IOException ioe) {
            couldNotReadError(file, ioe);
        }
    }
}
 
Example #19
Source File: RecordedFrame.java    From TencentKona-8 with GNU General Public License v2.0 5 votes vote down vote up
static ObjectFactory<RecordedFrame> createFactory(Type type, TimeConverter timeConverter) {
    return new ObjectFactory<RecordedFrame>(type) {
        @Override
        RecordedFrame createTyped(List<ValueDescriptor> desc, long id, Object[] object) {
            return new RecordedFrame(desc, object, timeConverter);
        }
    };
}
 
Example #20
Source File: Metadata.java    From TencentKona-8 with GNU General Public License v2.0 5 votes vote down vote up
@Override
public int compare(Type t1, Type t2) {
    int g1 = groupValue(t1);
    int g2 = groupValue(t2);
    if (g1 == g2) {
        String n1 = t1.getName();
        String n2 = t2.getName();
        String package1 = n1.substring(0, n1.lastIndexOf('.') + 1);
        String package2 = n2.substring(0, n2.lastIndexOf('.') + 1);

        if (package1.equals(package2)) {
            return n1.compareTo(n2);
        } else {
            // Ensure that jdk.* are printed first
            // This makes it easier to find user defined events at the end.
            if (Type.SUPER_TYPE_EVENT.equals(t1.getSuperType()) && !package1.equals(package2)) {
                if (package1.equals("jdk.jfr")) {
                    return -1;
                }
                if (package2.equals("jdk.jfr")) {
                    return 1;
                }
            }
            return package1.compareTo(package2);
        }
    } else {
        return Integer.compare(groupValue(t1), groupValue(t2));
    }
}
 
Example #21
Source File: RecordingFile.java    From TencentKona-8 with GNU General Public License v2.0 5 votes vote down vote up
private void aggregateTypeForChunk(ChunkHeader ch, List<Type> types, HashSet<Long> foundIds) throws IOException {
    MetadataDescriptor m = ch.readMetadata();
    for (Type t : m.getTypes()) {
        if (!foundIds.contains(t.getId())) {
            types.add(t);
            foundIds.add(t.getId());
        }
    }
}
 
Example #22
Source File: RecordingFile.java    From TencentKona-8 with GNU General Public License v2.0 5 votes vote down vote up
List<Type> readTypes() throws IOException  {
    ensureOpen();
    List<Type> types = new ArrayList<>();
    HashSet<Long> foundIds = new HashSet<>();
    try (RecordingInput ri = new RecordingInput(file)) {
        ChunkHeader ch = new ChunkHeader(ri);
        aggregateTypeForChunk(ch, types, foundIds);
        while (!ch.isLastChunk()) {
            ch = ch.nextHeader();
            aggregateTypeForChunk(ch, types, foundIds);
        }
    }
    return types;
}
 
Example #23
Source File: RecordedClass.java    From TencentKona-8 with GNU General Public License v2.0 5 votes vote down vote up
static ObjectFactory<RecordedClass> createFactory(Type type, TimeConverter timeConverter) {
    return new ObjectFactory<RecordedClass>(type) {
        @Override
        RecordedClass createTyped(List<ValueDescriptor> desc, long id, Object[] object) {
            return new RecordedClass(desc, id, object, timeConverter);
        }
    };
}
 
Example #24
Source File: ParserFactory.java    From TencentKona-8 with GNU General Public License v2.0 5 votes vote down vote up
private CompositeParser createCompositeParser(Type type) throws IOException {
    List<ValueDescriptor> vds = type.getFields();
    Parser[] parsers = new Parser[vds.size()];
    CompositeParser composite = new CompositeParser(parsers);
    // need to pre-register so recursive types can be handled
    registerParserType(type, composite);

    int index = 0;
    for (ValueDescriptor vd : vds) {
        parsers[index++] = createParser(vd);
    }
    return composite;
}
 
Example #25
Source File: ParserFactory.java    From TencentKona-8 with GNU General Public License v2.0 5 votes vote down vote up
private Parser registerParserType(Type t, Parser parser) {
    Parser p = parsers.get(t.getId());
    // check if parser exists (known type)
    if (p != null) {
        return p;
    }
    parsers.put(t.getId(), parser);
    return parser;
}
 
Example #26
Source File: Metadata.java    From openjdk-jdk8u with GNU General Public License v2.0 5 votes vote down vote up
@Override
public int compare(Type t1, Type t2) {
    int g1 = groupValue(t1);
    int g2 = groupValue(t2);
    if (g1 == g2) {
        String n1 = t1.getName();
        String n2 = t2.getName();
        String package1 = n1.substring(0, n1.lastIndexOf('.') + 1);
        String package2 = n2.substring(0, n2.lastIndexOf('.') + 1);

        if (package1.equals(package2)) {
            return n1.compareTo(n2);
        } else {
            // Ensure that jdk.* are printed first
            // This makes it easier to find user defined events at the end.
            if (Type.SUPER_TYPE_EVENT.equals(t1.getSuperType()) && !package1.equals(package2)) {
                if (package1.equals("jdk.jfr")) {
                    return -1;
                }
                if (package2.equals("jdk.jfr")) {
                    return 1;
                }
            }
            return package1.compareTo(package2);
        }
    } else {
        return Integer.compare(groupValue(t1), groupValue(t2));
    }
}
 
Example #27
Source File: ValueDescriptor.java    From dragonwell8_jdk with GNU General Public License v2.0 5 votes vote down vote up
ValueDescriptor(Type type, String name, List<AnnotationElement> annotations, int dimension, boolean constantPool, String fieldName) {
    Objects.requireNonNull(annotations);
    if (dimension < 0) {
        throw new IllegalArgumentException("Dimension must be positive");
    }
    this.name = Objects.requireNonNull(name, "Name of value descriptor can't be null");
    this.type = Objects.requireNonNull(type);
    this.isArray = dimension > 0;
    this.constantPool = constantPool;
    this.annotationConstruct = new AnnotationConstruct(annotations);
    this.javaFieldName = fieldName;
}
 
Example #28
Source File: RecordedClass.java    From openjdk-jdk8u with GNU General Public License v2.0 5 votes vote down vote up
static ObjectFactory<RecordedClass> createFactory(Type type, TimeConverter timeConverter) {
    return new ObjectFactory<RecordedClass>(type) {
        @Override
        RecordedClass createTyped(List<ValueDescriptor> desc, long id, Object[] object) {
            return new RecordedClass(desc, id, object, timeConverter);
        }
    };
}
 
Example #29
Source File: RecordedThread.java    From TencentKona-8 with GNU General Public License v2.0 5 votes vote down vote up
static ObjectFactory<RecordedThread> createFactory(Type type, TimeConverter timeConverter) {
    return new ObjectFactory<RecordedThread>(type) {
        @Override
        RecordedThread createTyped(List<ValueDescriptor> desc, long id, Object[] object) {
            return new RecordedThread(desc, id, object, timeConverter);
        }
    };
}
 
Example #30
Source File: RecordedMethod.java    From openjdk-jdk8u with GNU General Public License v2.0 5 votes vote down vote up
static ObjectFactory<RecordedMethod> createFactory(Type type, TimeConverter timeConverter) {
    return new ObjectFactory<RecordedMethod>(type) {
        @Override
        RecordedMethod createTyped(List<ValueDescriptor> desc, long id, Object[] object) {
            return new RecordedMethod(desc, object, timeConverter);
        }
    };
}