jdk.jfr.Enabled Java Examples

The following examples show how to use jdk.jfr.Enabled. 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: EventControl.java    From dragonwell8_jdk with GNU General Public License v2.0 6 votes vote down vote up
EventControl(PlatformEventType eventType) {
    eventControls.put(Enabled.NAME, defineEnabled(eventType));
    if (eventType.hasDuration()) {
        eventControls.put(Threshold.NAME, defineThreshold(eventType));
    }
    if (eventType.hasStackTrace()) {
        eventControls.put(StackTrace.NAME, defineStackTrace(eventType));
    }
    if (eventType.hasPeriod()) {
        eventControls.put(Period.NAME, definePeriod(eventType));
    }
    if (eventType.hasCutoff()) {
        eventControls.put(Cutoff.NAME, defineCutoff(eventType));
    }

    ArrayList<AnnotationElement> aes = new ArrayList<>(eventType.getAnnotationElements());
    remove(eventType, aes, Threshold.class);
    remove(eventType, aes, Period.class);
    remove(eventType, aes, Enabled.class);
    remove(eventType, aes, StackTrace.class);
    remove(eventType, aes, Cutoff.class);
    aes.trimToSize();
    eventType.setAnnotations(aes);
    this.type = eventType;
    this.idName = String.valueOf(eventType.getId());
}
 
Example #2
Source File: EventControl.java    From TencentKona-8 with GNU General Public License v2.0 6 votes vote down vote up
EventControl(PlatformEventType eventType) {
    eventControls.put(Enabled.NAME, defineEnabled(eventType));
    if (eventType.hasDuration()) {
        eventControls.put(Threshold.NAME, defineThreshold(eventType));
    }
    if (eventType.hasStackTrace()) {
        eventControls.put(StackTrace.NAME, defineStackTrace(eventType));
    }
    if (eventType.hasPeriod()) {
        eventControls.put(Period.NAME, definePeriod(eventType));
    }
    if (eventType.hasCutoff()) {
        eventControls.put(Cutoff.NAME, defineCutoff(eventType));
    }

    ArrayList<AnnotationElement> aes = new ArrayList<>(eventType.getAnnotationElements());
    remove(eventType, aes, Threshold.class);
    remove(eventType, aes, Period.class);
    remove(eventType, aes, Enabled.class);
    remove(eventType, aes, StackTrace.class);
    remove(eventType, aes, Cutoff.class);
    aes.trimToSize();
    eventType.setAnnotations(aes);
    this.type = eventType;
    this.idName = String.valueOf(eventType.getId());
}
 
Example #3
Source File: EventControl.java    From openjdk-jdk8u with GNU General Public License v2.0 6 votes vote down vote up
EventControl(PlatformEventType eventType) {
    eventControls.put(Enabled.NAME, defineEnabled(eventType));
    if (eventType.hasDuration()) {
        eventControls.put(Threshold.NAME, defineThreshold(eventType));
    }
    if (eventType.hasStackTrace()) {
        eventControls.put(StackTrace.NAME, defineStackTrace(eventType));
    }
    if (eventType.hasPeriod()) {
        eventControls.put(Period.NAME, definePeriod(eventType));
    }
    if (eventType.hasCutoff()) {
        eventControls.put(Cutoff.NAME, defineCutoff(eventType));
    }

    ArrayList<AnnotationElement> aes = new ArrayList<>(eventType.getAnnotationElements());
    remove(eventType, aes, Threshold.class);
    remove(eventType, aes, Period.class);
    remove(eventType, aes, Enabled.class);
    remove(eventType, aes, StackTrace.class);
    remove(eventType, aes, Cutoff.class);
    aes.trimToSize();
    eventType.setAnnotations(aes);
    this.type = eventType;
    this.idName = String.valueOf(eventType.getId());
}
 
Example #4
Source File: EventInstrumentation.java    From dragonwell8_jdk with GNU General Public License v2.0 5 votes vote down vote up
boolean isEnabled() {
    Boolean result = annotationValue(classNode, ANNOTATION_TYPE_ENABLED.getDescriptor(), Boolean.class);
    if (result != null) {
        return result.booleanValue();
    }
    if (superClass != null) {
        Enabled e = superClass.getAnnotation(Enabled.class);
        if (e != null) {
            return e.value();
        }
    }
    return true;
}
 
Example #5
Source File: EventControl.java    From dragonwell8_jdk with GNU General Public License v2.0 5 votes vote down vote up
private static Control defineEnabled(PlatformEventType type) {
    Enabled enabled = type.getAnnotation(Enabled.class);
    // Java events are enabled by default,
    // JVM events are not, maybe they should be? Would lower learning curve
    // there too.
    String def = type.isJVM() ? "false" : "true";
    if (enabled != null) {
        def = Boolean.toString(enabled.value());
    }
    type.add(PrivateAccess.getInstance().newSettingDescriptor(TYPE_ENABLED, Enabled.NAME, def, Collections.emptyList()));
    return new EnabledSetting(type, def);
}
 
Example #6
Source File: PlatformRecorder.java    From dragonwell8_jdk with GNU General Public License v2.0 5 votes vote down vote up
private void emitOldObjectSamples(PlatformRecording recording) {
    Map<String, String> settings = recording.getSettings();
    String s = settings.get("com.oracle.jdk.OldObjectSample#" + Enabled.NAME);
    if ("true".equals(s)) {
        long nanos = CutoffSetting.parseValueSafe(settings.get("com.oracle.jdk.OldObjectSample#" + Cutoff.NAME));
        long ticks = Utils.nanosToTicks(nanos);
        JVM.getJVM().emitOldObjectSamples(ticks, WhiteBox.getWriteAllObjectSamples());
    }
}
 
Example #7
Source File: TestJcmdDumpPathToGCRoots.java    From dragonwell8_jdk with GNU General Public License v2.0 5 votes vote down vote up
private static void testDump(String pathToGcRoots, Map<String, String> settings, boolean expectedChains) throws Exception {
    try (Recording r = new Recording()) {
        Map<String, String> p = new HashMap<>(settings);
        p.put(EventNames.OldObjectSample + "#" + Enabled.NAME, "true");
        r.setName("dodo");
        r.setSettings(p);
        r.setToDisk(true);
        r.start();
        clearLeak();
        System.out.println("Recording id: " + r.getId());
        System.out.println("Settings: " + settings.toString());
        System.out.println("Command: JFR.dump " + pathToGcRoots);
        System.out.println("Chains expected: " + expectedChains);
        buildLeak();
        System.gc();
        System.gc();
        File recording = new File("TestJcmdDumpPathToGCRoots" + r.getId() + ".jfr");
        recording.delete();
        JcmdHelper.jcmd("JFR.dump", "name=dodo", pathToGcRoots, "filename=" + recording.getAbsolutePath());
        r.setSettings(Collections.emptyMap());
        List<RecordedEvent> events = RecordingFile.readAllEvents(recording.toPath());
        if (events.isEmpty()) {
            throw new Exception("No events found in recoding");
        }
        boolean chains = hasChains(events);
        if (expectedChains && !chains) {
            System.out.println(events);
            throw new Exception("Expected chains but found none");
        }
        if (!expectedChains && chains) {
            System.out.println(events);
            throw new Exception("Didn't expect chains but found some");
        }
    }
}
 
Example #8
Source File: EventInstrumentation.java    From TencentKona-8 with GNU General Public License v2.0 5 votes vote down vote up
boolean isEnabled() {
    Boolean result = annotationValue(classNode, ANNOTATION_TYPE_ENABLED.getDescriptor(), Boolean.class);
    if (result != null) {
        return result.booleanValue();
    }
    if (superClass != null) {
        Enabled e = superClass.getAnnotation(Enabled.class);
        if (e != null) {
            return e.value();
        }
    }
    return true;
}
 
Example #9
Source File: EventControl.java    From TencentKona-8 with GNU General Public License v2.0 5 votes vote down vote up
private static Control defineEnabled(PlatformEventType type) {
    Enabled enabled = type.getAnnotation(Enabled.class);
    // Java events are enabled by default,
    // JVM events are not, maybe they should be? Would lower learning curve
    // there too.
    String def = type.isJVM() ? "false" : "true";
    if (enabled != null) {
        def = Boolean.toString(enabled.value());
    }
    type.add(PrivateAccess.getInstance().newSettingDescriptor(TYPE_ENABLED, Enabled.NAME, def, Collections.emptyList()));
    return new EnabledSetting(type, def);
}
 
Example #10
Source File: TestJcmdDumpPathToGCRoots.java    From TencentKona-8 with GNU General Public License v2.0 5 votes vote down vote up
private static void testDump(String pathToGcRoots, Map<String, String> settings, boolean expectedChains) throws Exception {
    try (Recording r = new Recording()) {
        Map<String, String> p = new HashMap<>(settings);
        p.put(EventNames.OldObjectSample + "#" + Enabled.NAME, "true");
        r.setName("dodo");
        r.setSettings(p);
        r.setToDisk(true);
        r.start();
        clearLeak();
        System.out.println("Recording id: " + r.getId());
        System.out.println("Settings: " + settings.toString());
        System.out.println("Command: JFR.dump " + pathToGcRoots);
        System.out.println("Chains expected: " + expectedChains);
        buildLeak();
        System.gc();
        System.gc();
        File recording = new File("TestJcmdDumpPathToGCRoots" + r.getId() + ".jfr");
        recording.delete();
        JcmdHelper.jcmd("JFR.dump", "name=dodo", pathToGcRoots, "filename=" + recording.getAbsolutePath());
        r.setSettings(Collections.emptyMap());
        List<RecordedEvent> events = RecordingFile.readAllEvents(recording.toPath());
        if (events.isEmpty()) {
            throw new Exception("No events found in recoding");
        }
        boolean chains = hasChains(events);
        if (expectedChains && !chains) {
            System.out.println(events);
            throw new Exception("Expected chains but found none");
        }
        if (!expectedChains && chains) {
            System.out.println(events);
            throw new Exception("Didn't expect chains but found some");
        }
    }
}
 
Example #11
Source File: EventInstrumentation.java    From openjdk-jdk8u with GNU General Public License v2.0 5 votes vote down vote up
boolean isEnabled() {
    Boolean result = annotationValue(classNode, ANNOTATION_TYPE_ENABLED.getDescriptor(), Boolean.class);
    if (result != null) {
        return result.booleanValue();
    }
    if (superClass != null) {
        Enabled e = superClass.getAnnotation(Enabled.class);
        if (e != null) {
            return e.value();
        }
    }
    return true;
}
 
Example #12
Source File: EventControl.java    From openjdk-jdk8u with GNU General Public License v2.0 5 votes vote down vote up
private static Control defineEnabled(PlatformEventType type) {
    Enabled enabled = type.getAnnotation(Enabled.class);
    // Java events are enabled by default,
    // JVM events are not, maybe they should be? Would lower learning curve
    // there too.
    String def = type.isJVM() ? "false" : "true";
    if (enabled != null) {
        def = Boolean.toString(enabled.value());
    }
    type.add(PrivateAccess.getInstance().newSettingDescriptor(TYPE_ENABLED, Enabled.NAME, def, Collections.emptyList()));
    return new EnabledSetting(type, def);
}
 
Example #13
Source File: TestJcmdDumpPathToGCRoots.java    From openjdk-jdk8u with GNU General Public License v2.0 5 votes vote down vote up
private static void testDump(String pathToGcRoots, Map<String, String> settings, boolean expectedChains) throws Exception {
    try (Recording r = new Recording()) {
        Map<String, String> p = new HashMap<>(settings);
        p.put(EventNames.OldObjectSample + "#" + Enabled.NAME, "true");
        r.setName("dodo");
        r.setSettings(p);
        r.setToDisk(true);
        r.start();
        clearLeak();
        System.out.println("Recording id: " + r.getId());
        System.out.println("Settings: " + settings.toString());
        System.out.println("Command: JFR.dump " + pathToGcRoots);
        System.out.println("Chains expected: " + expectedChains);
        buildLeak();
        System.gc();
        System.gc();
        File recording = new File("TestJcmdDumpPathToGCRoots" + r.getId() + ".jfr");
        recording.delete();
        JcmdHelper.jcmd("JFR.dump", "name=dodo", pathToGcRoots, "filename=" + recording.getAbsolutePath());
        r.setSettings(Collections.emptyMap());
        List<RecordedEvent> events = RecordingFile.readAllEvents(recording.toPath());
        if (events.isEmpty()) {
            throw new Exception("No events found in recoding");
        }
        boolean chains = hasChains(events);
        if (expectedChains && !chains) {
            System.out.println(events);
            throw new Exception("Expected chains but found none");
        }
        if (!expectedChains && chains) {
            System.out.println(events);
            throw new Exception("Didn't expect chains but found some");
        }
    }
}
 
Example #14
Source File: TraceHandler.java    From dragonwell8_jdk with GNU General Public License v2.0 4 votes vote down vote up
@Override
public void startElement(String uri, String localName, String qName, Attributes attributes) throws SAXException {
    switch (qName) {
    case ELEMENT_RELATION_DECL:
        String relationalURI = attributes.getValue(ATTRIBUTE_URI);
        String id = attributes.getValue(ATTRIBUTE_ID);
        typedef.put(id, relationalURI);
        break;
    case ELEMENT_PRIMARY_TYPE:
        addTypedef(attributes);
        break;
    case ELEMENT_STRUCT_ARRAY:
        valueDeclarations.add(new ValueDeclaration(type, 1, attributes));
        break;
    case ELEMENT_VALUE:
    case ELEMENT_STRUCT_VALUE:
        valueDeclarations.add(new ValueDeclaration(type, 0, attributes));
        break;
    case ELEMENT_EVENT:
        type = createType(attributes, true, structTypeId++, false);
        boolean stackTrace = getBoolean(attributes, ATTRIBUTE_HAS_STACKTRACE);
        boolean thread = getBoolean(attributes, (ATTRIBUTE_HAS_THREAD));
        boolean instant = getBoolean(attributes, (ATTRIBUTE_IS_INSTANT));
        boolean requestable = getBoolean(attributes, (ATTRIBUTE_IS_REQUESTABLE));
        boolean constant = getBoolean(attributes, (ATTRIBUTE_IS_CONSTANT));
        boolean duration = !requestable && !instant;
        boolean experimental = getBoolean(attributes, ATTRIBUTE_EXPERIMENTAL);
        boolean cutoff =  getBoolean(attributes, ATTRIBUTE_CUTOFF);
        TypeLibrary.addImplicitFields(type, requestable, duration, thread, stackTrace, cutoff);
        ArrayList<AnnotationElement> aes = new ArrayList<>();
        aes.addAll(type.getAnnotationElements());
        if (requestable) {
            String period = constant ? "endChunk" : "everyChunk";
            aes.add(new AnnotationElement(Period.class, period));
        } else {
            if (!instant) {
                aes.add(new AnnotationElement(Threshold.class, "0 ns"));
            }
            if (stackTrace) {
                aes.add(new AnnotationElement(StackTrace.class, true));
            }
        }
        if (cutoff) {
            aes.add(new AnnotationElement(Cutoff.class, Cutoff.INIFITY));
        }
        if (experimental) {
            aes.add(new AnnotationElement(Experimental.class));
        }
        aes.add(new AnnotationElement(Enabled.class, false));
        aes.trimToSize();
        type.setAnnotations(aes);
        break;
    case ELEMENT_CONTENT_TYPE:
        if (attributes.getValue(ATTRIBUTE_BUILTIN_TYPE) != null) {
            type = createType(attributes, false, builtInId(attributes), true);
        } else {
            type = createType(attributes, false, jvmTypeId++, true);
        }
        break;
    case ELEMENT_STRUCT_TYPE:
    case ELEMENT_STRUCT:
        type = createType(attributes, false, structTypeId++, false);
        break;
    }
}