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

The following examples show how to use jdk.jfr.ValueDescriptor#getTypeName() . 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: RecordedObject.java    From dragonwell8_jdk with GNU General Public License v2.0 6 votes vote down vote up
private Duration getDuration(long timespan, String name) throws InternalError {
    ValueDescriptor v = getValueDescriptor(descriptors, name, null);
    Timespan ts = v.getAnnotation(Timespan.class);
    if (ts != null) {
        switch (ts.value()) {
        case Timespan.MICROSECONDS:
            return Duration.ofNanos(1000 * timespan);
        case Timespan.SECONDS:
            return Duration.ofSeconds(timespan);
        case Timespan.MILLISECONDS:
            return Duration.ofMillis(timespan);
        case Timespan.NANOSECONDS:
            return Duration.ofNanos(timespan);
        case Timespan.TICKS:
            return Duration.ofNanos(timeConverter.convertTimespan(timespan));
        }
        throw new IllegalArgumentException("Attempt to get " + v.getTypeName() + " field \"" + name + "\" with illegal timespan unit " + ts.value());
    }
    throw new IllegalArgumentException("Attempt to get " + v.getTypeName() + " field \"" + name + "\" with missing @Timespan");
}
 
Example 2
Source File: RecordedObject.java    From TencentKona-8 with GNU General Public License v2.0 6 votes vote down vote up
private Duration getDuration(long timespan, String name) throws InternalError {
    ValueDescriptor v = getValueDescriptor(descriptors, name, null);
    if (timespan == Long.MIN_VALUE) {
        return Duration.ofSeconds(Long.MIN_VALUE, 0);
    }
    Timespan ts = v.getAnnotation(Timespan.class);
    if (ts != null) {
        switch (ts.value()) {
        case Timespan.MICROSECONDS:
            return Duration.ofNanos(1000 * timespan);
        case Timespan.SECONDS:
            return Duration.ofSeconds(timespan);
        case Timespan.MILLISECONDS:
            return Duration.ofMillis(timespan);
        case Timespan.NANOSECONDS:
            return Duration.ofNanos(timespan);
        case Timespan.TICKS:
            return Duration.ofNanos(timeConverter.convertTimespan(timespan));
        }
        throw new IllegalArgumentException("Attempt to get " + v.getTypeName() + " field \"" + name + "\" with illegal timespan unit " + ts.value());
    }
    throw new IllegalArgumentException("Attempt to get " + v.getTypeName() + " field \"" + name + "\" with missing @Timespan");
}
 
Example 3
Source File: RecordedObject.java    From TencentKona-8 with GNU General Public License v2.0 6 votes vote down vote up
private Instant getInstant(long timestamp, String name) {
    ValueDescriptor v = getValueDescriptor(descriptors, name, null);
    Timestamp ts = v.getAnnotation(Timestamp.class);
    if (ts != null) {
        if (timestamp == Long.MIN_VALUE) {
            return Instant.MIN;
        }
        switch (ts.value()) {
        case Timestamp.MILLISECONDS_SINCE_EPOCH:
            return Instant.ofEpochMilli(timestamp);
        case Timestamp.TICKS:
            return Instant.ofEpochSecond(0, timeConverter.convertTimestamp(timestamp));
        }
        throw new IllegalArgumentException("Attempt to get " + v.getTypeName() + " field \"" + name + "\" with illegal timestamp unit " + ts.value());
    }
    throw new IllegalArgumentException("Attempt to get " + v.getTypeName() + " field \"" + name + "\" with missing @Timestamp");
}
 
Example 4
Source File: RecordedObject.java    From openjdk-jdk8u with GNU General Public License v2.0 6 votes vote down vote up
private Duration getDuration(long timespan, String name) throws InternalError {
    ValueDescriptor v = getValueDescriptor(descriptors, name, null);
    if (timespan == Long.MIN_VALUE) {
        return Duration.ofSeconds(Long.MIN_VALUE, 0);
    }
    Timespan ts = v.getAnnotation(Timespan.class);
    if (ts != null) {
        switch (ts.value()) {
        case Timespan.MICROSECONDS:
            return Duration.ofNanos(1000 * timespan);
        case Timespan.SECONDS:
            return Duration.ofSeconds(timespan);
        case Timespan.MILLISECONDS:
            return Duration.ofMillis(timespan);
        case Timespan.NANOSECONDS:
            return Duration.ofNanos(timespan);
        case Timespan.TICKS:
            return Duration.ofNanos(timeConverter.convertTimespan(timespan));
        }
        throw new IllegalArgumentException("Attempt to get " + v.getTypeName() + " field \"" + name + "\" with illegal timespan unit " + ts.value());
    }
    throw new IllegalArgumentException("Attempt to get " + v.getTypeName() + " field \"" + name + "\" with missing @Timespan");
}
 
Example 5
Source File: RecordedObject.java    From openjdk-jdk8u with GNU General Public License v2.0 6 votes vote down vote up
private Instant getInstant(long timestamp, String name) {
    ValueDescriptor v = getValueDescriptor(descriptors, name, null);
    Timestamp ts = v.getAnnotation(Timestamp.class);
    if (ts != null) {
        if (timestamp == Long.MIN_VALUE) {
            return Instant.MIN;
        }
        switch (ts.value()) {
        case Timestamp.MILLISECONDS_SINCE_EPOCH:
            return Instant.ofEpochMilli(timestamp);
        case Timestamp.TICKS:
            return Instant.ofEpochSecond(0, timeConverter.convertTimestamp(timestamp));
        }
        throw new IllegalArgumentException("Attempt to get " + v.getTypeName() + " field \"" + name + "\" with illegal timestamp unit " + ts.value());
    }
    throw new IllegalArgumentException("Attempt to get " + v.getTypeName() + " field \"" + name + "\" with missing @Timestamp");
}
 
Example 6
Source File: ParserFactory.java    From dragonwell8_jdk 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 7
Source File: RecordedObject.java    From dragonwell8_jdk with GNU General Public License v2.0 5 votes vote down vote up
private Instant getInstant(long timestamp, String name) {
    ValueDescriptor v = getValueDescriptor(descriptors, name, null);
    Timestamp ts = v.getAnnotation(Timestamp.class);
    if (ts != null) {
        switch (ts.value()) {
        case Timestamp.MILLISECONDS_SINCE_EPOCH:
            return Instant.ofEpochMilli(timestamp);
        case Timestamp.TICKS:
            return Instant.ofEpochSecond(0, timeConverter.convertTimestamp(timestamp));
        }
        throw new IllegalArgumentException("Attempt to get " + v.getTypeName() + " field \"" + name + "\" with illegal timestamp unit " + ts.value());
    }
    throw new IllegalArgumentException("Attempt to get " + v.getTypeName() + " field \"" + name + "\" with missing @Timestamp");
}
 
Example 8
Source File: ASMToolkit.java    From dragonwell8_jdk with GNU General Public License v2.0 5 votes vote down vote up
public static Type toType(ValueDescriptor v) {
    String typeName = v.getTypeName();

    switch (typeName) {
    case "byte":
        return Type.BYTE_TYPE;
    case "short":
        return Type.SHORT_TYPE;
    case "int":
        return Type.INT_TYPE;
    case "long":
        return Type.LONG_TYPE;
    case "double":
        return Type.DOUBLE_TYPE;
    case "float":
        return Type.FLOAT_TYPE;
    case "char":
        return Type.CHAR_TYPE;
    case "boolean":
        return Type.BOOLEAN_TYPE;
    case "java.lang.String":
        return TYPE_STRING;
    case "java.lang.Thread":
        return Type_THREAD;
    case "java.lang.Class":
        return TYPE_CLASS;
    }
    // Add support for SettingControl?
   throw new Error("Not a valid type " + v.getTypeName());
}
 
Example 9
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 10
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 11
Source File: ASMToolkit.java    From TencentKona-8 with GNU General Public License v2.0 5 votes vote down vote up
public static Type toType(ValueDescriptor v) {
    String typeName = v.getTypeName();

    switch (typeName) {
    case "byte":
        return Type.BYTE_TYPE;
    case "short":
        return Type.SHORT_TYPE;
    case "int":
        return Type.INT_TYPE;
    case "long":
        return Type.LONG_TYPE;
    case "double":
        return Type.DOUBLE_TYPE;
    case "float":
        return Type.FLOAT_TYPE;
    case "char":
        return Type.CHAR_TYPE;
    case "boolean":
        return Type.BOOLEAN_TYPE;
    case "java.lang.String":
        return TYPE_STRING;
    case "java.lang.Thread":
        return Type_THREAD;
    case "java.lang.Class":
        return TYPE_CLASS;
    }
    // Add support for SettingControl?
   throw new Error("Not a valid type " + v.getTypeName());
}
 
Example 12
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 13
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;
}
 
Example 14
Source File: ASMToolkit.java    From openjdk-jdk8u with GNU General Public License v2.0 5 votes vote down vote up
public static Type toType(ValueDescriptor v) {
    String typeName = v.getTypeName();

    switch (typeName) {
    case "byte":
        return Type.BYTE_TYPE;
    case "short":
        return Type.SHORT_TYPE;
    case "int":
        return Type.INT_TYPE;
    case "long":
        return Type.LONG_TYPE;
    case "double":
        return Type.DOUBLE_TYPE;
    case "float":
        return Type.FLOAT_TYPE;
    case "char":
        return Type.CHAR_TYPE;
    case "boolean":
        return Type.BOOLEAN_TYPE;
    case "java.lang.String":
        return TYPE_STRING;
    case "java.lang.Thread":
        return Type_THREAD;
    case "java.lang.Class":
        return TYPE_CLASS;
    }
    // Add support for SettingControl?
   throw new Error("Not a valid type " + v.getTypeName());
}
 
Example 15
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");
}