jdk.jfr.internal.test.WhiteBox Java Examples

The following examples show how to use jdk.jfr.internal.test.WhiteBox. 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: OldObjectSample.java    From TencentKona-8 with GNU General Public License v2.0 6 votes vote down vote up
public static void emit(List<PlatformRecording> recordings, Boolean pathToGcRoots) {
    boolean enabled = false;
    long cutoffNanos = Boolean.TRUE.equals(pathToGcRoots) ? Long.MAX_VALUE : 0L;
    for (PlatformRecording r : recordings) {
        if (r.getState() == RecordingState.RUNNING) {
            if (isEnabled(r)) {
                enabled = true;
                long c = CutoffSetting.parseValueSafe(r.getSettings().get(OLD_OBJECT_CUTOFF));
                cutoffNanos = Math.max(c, cutoffNanos);
            }
        }
    }
    if (enabled) {
        long ticks = Utils.nanosToTicks(cutoffNanos);
        JVM.getJVM().emitOldObjectSamples(ticks, WhiteBox.getWriteAllObjectSamples());
    }
}
 
Example #2
Source File: TestParallelOld.java    From dragonwell8_jdk with GNU General Public License v2.0 6 votes vote down vote up
public static void main(String[] args) throws Exception {
    WhiteBox.setWriteAllObjectSamples(true);

    try (Recording r = new Recording()) {
        r.enable(EventNames.OldObjectSample).withStackTrace().with("cutoff", "infinity");
        r.start();
        allocateFindMe();
        System.gc();
        r.stop();
        List<RecordedEvent> events = Events.fromRecording(r);
        System.out.println(events);
        if (OldObjects.countMatchingEvents(events, FindMe[].class, null, null, -1, "allocateFindMe") == 0) {
            throw new Exception("Could not find leak with " + FindMe[].class);
        }
    }
}
 
Example #3
Source File: TestHeapDeep.java    From dragonwell8_jdk with GNU General Public License v2.0 6 votes vote down vote up
public static void main(String[] args) throws Exception {
    WhiteBox.setWriteAllObjectSamples(true);

    try (Recording r = new Recording()) {
        r.enable(EventNames.OldObjectSample).withStackTrace().with("cutoff", "infinity");
        r.start();
        leak = createChain();
        List<RecordedEvent> events = Events.fromRecording(r);
        if (OldObjects.countMatchingEvents(events, byte[].class, null, null, -1, "createChain") == 0) {
            throw new Exception("Could not find ChainNode");
        }
        for (RecordedEvent e : events) {
            OldObjects.validateReferenceChainLimit(e, OldObjects.MAX_CHAIN_LENGTH);
        }
    }
}
 
Example #4
Source File: TestHeapDeep.java    From openjdk-jdk8u with GNU General Public License v2.0 6 votes vote down vote up
public static void main(String[] args) throws Exception {
    WhiteBox.setWriteAllObjectSamples(true);

    try (Recording r = new Recording()) {
        r.enable(EventNames.OldObjectSample).withStackTrace().with("cutoff", "infinity");
        r.start();
        leak = createChain();
        List<RecordedEvent> events = Events.fromRecording(r);
        if (OldObjects.countMatchingEvents(events, byte[].class, null, null, -1, "createChain") == 0) {
            throw new Exception("Could not find ChainNode");
        }
        for (RecordedEvent e : events) {
            OldObjects.validateReferenceChainLimit(e, OldObjects.MAX_CHAIN_LENGTH);
        }
    }
}
 
Example #5
Source File: TestParallelOld.java    From openjdk-jdk8u with GNU General Public License v2.0 6 votes vote down vote up
public static void main(String[] args) throws Exception {
    WhiteBox.setWriteAllObjectSamples(true);

    try (Recording r = new Recording()) {
        r.enable(EventNames.OldObjectSample).withStackTrace().with("cutoff", "infinity");
        r.start();
        allocateFindMe();
        System.gc();
        r.stop();
        List<RecordedEvent> events = Events.fromRecording(r);
        System.out.println(events);
        if (OldObjects.countMatchingEvents(events, FindMe[].class, null, null, -1, "allocateFindMe") == 0) {
            throw new Exception("Could not find leak with " + FindMe[].class);
        }
    }
}
 
Example #6
Source File: TestReferenceChainLimit.java    From dragonwell8_jdk with GNU General Public License v2.0 6 votes vote down vote up
public static void main(String[] args) throws Exception {
    WhiteBox.setWriteAllObjectSamples(true);

    try (Recording r = new Recording()) {
        r.enable(EventNames.OldObjectSample).withStackTrace().with("cutoff", "infinity");
        r.start();
        leak = createChain();
        List<RecordedEvent> events = Events.fromRecording(r);
        if (OldObjects.countMatchingEvents(events, byte[].class, null, null, -1, "createChain") == 0) {
            throw new Exception("Could not find ChainNode");
        }
        for (RecordedEvent e : events) {
            OldObjects.validateReferenceChainLimit(e, OldObjects.MAX_CHAIN_LENGTH);
        }
    }
}
 
Example #7
Source File: TestSerial.java    From dragonwell8_jdk with GNU General Public License v2.0 6 votes vote down vote up
public static void main(String[] args) throws Throwable {
    WhiteBox.setWriteAllObjectSamples(true);

    try (Recording r = new Recording()) {
        r.enable(EventNames.OldObjectSample).withStackTrace().with("cutoff", "infinity");
        r.start();
        allocateFindMe();
        System.gc();
        r.stop();
        List<RecordedEvent> events = Events.fromRecording(r);
        System.out.println(events);
        if (OldObjects.countMatchingEvents(events, FindMe[].class, null, null, -1, "allocateFindMe") == 0) {
            throw new Exception("Could not find leak with " + FindMe[].class);
        }
    }
}
 
Example #8
Source File: TestG1.java    From dragonwell8_jdk with GNU General Public License v2.0 6 votes vote down vote up
public static void main(String[] args) throws Exception {
    WhiteBox.setWriteAllObjectSamples(true);

    try (Recording r = new Recording()) {
        r.enable(EventNames.OldObjectSample).withStackTrace().with("cutoff", "infinity");
        r.start();
        allocateFindMe();
        System.gc();
        r.stop();
        List<RecordedEvent> events = Events.fromRecording(r);
        System.out.println(events);
        if (OldObjects.countMatchingEvents(events, FindMe[].class, null, null, -1, "allocateFindMe") == 0) {
            throw new Exception("Could not find leak with " + FindMe[].class);
        }
    }
}
 
Example #9
Source File: TestParallel.java    From dragonwell8_jdk with GNU General Public License v2.0 6 votes vote down vote up
public static void main(String[] args) throws Exception {
    WhiteBox.setWriteAllObjectSamples(true);

    try (Recording r = new Recording()) {
        r.enable(EventNames.OldObjectSample).withStackTrace().with("cutoff", "infinity");
        r.start();
        allocateFindMe();
        System.gc();
        r.stop();
        List<RecordedEvent> events = Events.fromRecording(r);
        System.out.println(events);
        if (OldObjects.countMatchingEvents(events, FindMe[].class, null, null, -1, "allocateFindMe") == 0) {
            throw new Exception("Could not find leak with " + FindMe[].class);
        }
    }
}
 
Example #10
Source File: TestListenerLeak.java    From dragonwell8_jdk with GNU General Public License v2.0 6 votes vote down vote up
public static void main(String[] args) throws Exception {
    WhiteBox.setWriteAllObjectSamples(true);

    try (Recording r = new Recording()) {
        r.enable(EventNames.OldObjectSample).withStackTrace().with("cutoff", "infinity");
        r.start();
        listenerLeak();
        r.stop();
        List<RecordedEvent> events = Events.fromRecording(r);
        System.out.println("Event: " + events.size());
        for (RecordedEvent event : events) {
            System.out.println("Event: " + event);
        }
        if (OldObjects.countMatchingEvents(events, Stuff[].class, null, null, -1, "listenerLeak") == 0) {
            throw new Exception("Could not find leak with " + Stuff[].class);
        }
    }
}
 
Example #11
Source File: TestCMS.java    From openjdk-jdk8u with GNU General Public License v2.0 6 votes vote down vote up
public static void main(String[] args) throws Exception {
    WhiteBox.setWriteAllObjectSamples(true);

    try (Recording r = new Recording()) {
        r.enable(EventNames.OldObjectSample).withStackTrace().with("cutoff", "infinity");
        r.start();
        allocateFindMe();
        System.gc();
        r.stop();
        List<RecordedEvent> events = Events.fromRecording(r);
        System.out.println(events);
        if (OldObjects.countMatchingEvents(events, FindMe[].class, null, null, -1, "allocateFindMe") == 0) {
            throw new Exception("Could not find leak with " + FindMe[].class);
        }
    }
}
 
Example #12
Source File: TestFieldInformation.java    From dragonwell8_jdk with GNU General Public License v2.0 6 votes vote down vote up
public static void main(String[] args) throws Exception {
    WhiteBox.setWriteAllObjectSamples(true);

    try (Recording recording = new Recording()) {
        recording.enable(EventNames.OldObjectSample).withoutStackTrace().with("cutoff", "infinity");
        recording.start();

        addToTestField();

        recording.stop();

        List<RecordedEvent> events = Events.fromRecording(recording);
        Events.hasEvents(events);
        for (RecordedEvent e : events) {
            if (hasValidField(e)) {
                return;
            }
        }
        System.out.println(events);
        Asserts.fail("Could not find old object with field 'testField'");
    }
}
 
Example #13
Source File: TestReferenceChainLimit.java    From openjdk-jdk8u with GNU General Public License v2.0 6 votes vote down vote up
public static void main(String[] args) throws Exception {
    WhiteBox.setWriteAllObjectSamples(true);

    try (Recording r = new Recording()) {
        r.enable(EventNames.OldObjectSample).withStackTrace().with("cutoff", "infinity");
        r.start();
        leak = createChain();
        List<RecordedEvent> events = Events.fromRecording(r);
        if (OldObjects.countMatchingEvents(events, byte[].class, null, null, -1, "createChain") == 0) {
            throw new Exception("Could not find ChainNode");
        }
        for (RecordedEvent e : events) {
            OldObjects.validateReferenceChainLimit(e, OldObjects.MAX_CHAIN_LENGTH);
        }
    }
}
 
Example #14
Source File: TestCMS.java    From dragonwell8_jdk with GNU General Public License v2.0 6 votes vote down vote up
public static void main(String[] args) throws Exception {
    WhiteBox.setWriteAllObjectSamples(true);

    try (Recording r = new Recording()) {
        r.enable(EventNames.OldObjectSample).withStackTrace().with("cutoff", "infinity");
        r.start();
        allocateFindMe();
        System.gc();
        r.stop();
        List<RecordedEvent> events = Events.fromRecording(r);
        System.out.println(events);
        if (OldObjects.countMatchingEvents(events, FindMe[].class, null, null, -1, "allocateFindMe") == 0) {
            throw new Exception("Could not find leak with " + FindMe[].class);
        }
    }
}
 
Example #15
Source File: TestParallel.java    From openjdk-jdk8u with GNU General Public License v2.0 6 votes vote down vote up
public static void main(String[] args) throws Exception {
    WhiteBox.setWriteAllObjectSamples(true);

    try (Recording r = new Recording()) {
        r.enable(EventNames.OldObjectSample).withStackTrace().with("cutoff", "infinity");
        r.start();
        allocateFindMe();
        System.gc();
        r.stop();
        List<RecordedEvent> events = Events.fromRecording(r);
        System.out.println(events);
        if (OldObjects.countMatchingEvents(events, FindMe[].class, null, null, -1, "allocateFindMe") == 0) {
            throw new Exception("Could not find leak with " + FindMe[].class);
        }
    }
}
 
Example #16
Source File: TestJcmdDumpPathToGCRoots.java    From dragonwell8_jdk with GNU General Public License v2.0 6 votes vote down vote up
public static void main(String[] args) throws Exception {
    WhiteBox.setWriteAllObjectSamples(true);

    String settingName = EventNames.OldObjectSample + "#" + "cutoff";

    // dump parameter trumps previous setting
    testDump("path-to-gc-roots=true", Collections.singletonMap(settingName, "infinity"), true);
    testDump("path-to-gc-roots=true", Collections.singletonMap(settingName, "0 ns"), true);
    testDump("path-to-gc-roots=true", Collections.emptyMap(), true);

    testDump("path-to-gc-roots=false", Collections.singletonMap(settingName, "infinity"), false);
    testDump("path-to-gc-roots=false", Collections.singletonMap(settingName, "0 ns"), false);
    testDump("path-to-gc-roots=false", Collections.emptyMap(), false);

    testDump("", Collections.singletonMap(settingName, "infinity"), true);
    testDump("", Collections.singletonMap(settingName, "0 ns"), false);
    testDump("", Collections.emptyMap(), false);
}
 
Example #17
Source File: TestJcmdDumpPathToGCRoots.java    From TencentKona-8 with GNU General Public License v2.0 6 votes vote down vote up
public static void main(String[] args) throws Exception {
    WhiteBox.setWriteAllObjectSamples(true);

    String settingName = EventNames.OldObjectSample + "#" + "cutoff";

    // dump parameter trumps previous setting
    testDump("path-to-gc-roots=true", Collections.singletonMap(settingName, "infinity"), true);
    testDump("path-to-gc-roots=true", Collections.singletonMap(settingName, "0 ns"), true);
    testDump("path-to-gc-roots=true", Collections.emptyMap(), true);

    testDump("path-to-gc-roots=false", Collections.singletonMap(settingName, "infinity"), false);
    testDump("path-to-gc-roots=false", Collections.singletonMap(settingName, "0 ns"), false);
    testDump("path-to-gc-roots=false", Collections.emptyMap(), false);

    testDump("", Collections.singletonMap(settingName, "infinity"), true);
    testDump("", Collections.singletonMap(settingName, "0 ns"), false);
    testDump("", Collections.emptyMap(), false);
}
 
Example #18
Source File: TestSerial.java    From TencentKona-8 with GNU General Public License v2.0 6 votes vote down vote up
public static void main(String[] args) throws Exception {
    WhiteBox.setWriteAllObjectSamples(true);

    try (Recording r = new Recording()) {
        r.enable(EventNames.OldObjectSample).withStackTrace().with("cutoff", "infinity");
        r.start();
        allocateFindMe();
        System.gc();
        r.stop();
        List<RecordedEvent> events = Events.fromRecording(r);
        System.out.println(events);
        if (OldObjects.countMatchingEvents(events, FindMe[].class, null, null, -1, "allocateFindMe") == 0) {
            throw new Exception("Could not find leak with " + FindMe[].class);
        }
    }
}
 
Example #19
Source File: TestFieldInformation.java    From openjdk-jdk8u with GNU General Public License v2.0 6 votes vote down vote up
public static void main(String[] args) throws Exception {
    WhiteBox.setWriteAllObjectSamples(true);

    try (Recording recording = new Recording()) {
        recording.enable(EventNames.OldObjectSample).withoutStackTrace().with("cutoff", "infinity");
        recording.start();

        addToTestField();

        recording.stop();

        List<RecordedEvent> events = Events.fromRecording(recording);
        Events.hasEvents(events);
        for (RecordedEvent e : events) {
            if (hasValidField(e)) {
                return;
            }
        }
        System.out.println(events);
        Asserts.fail("Could not find old object with field 'testField'");
    }
}
 
Example #20
Source File: TestG1.java    From TencentKona-8 with GNU General Public License v2.0 6 votes vote down vote up
public static void main(String[] args) throws Exception {
    WhiteBox.setWriteAllObjectSamples(true);

    try (Recording r = new Recording()) {
        r.enable(EventNames.OldObjectSample).withStackTrace().with("cutoff", "infinity");
        r.start();
        allocateFindMe();
        System.gc();
        r.stop();
        List<RecordedEvent> events = Events.fromRecording(r);
        System.out.println(events);
        if (OldObjects.countMatchingEvents(events, FindMe[].class, null, null, -1, "allocateFindMe") == 0) {
            throw new Exception("Could not find leak with " + FindMe[].class);
        }
    }
}
 
Example #21
Source File: TestFieldInformation.java    From TencentKona-8 with GNU General Public License v2.0 6 votes vote down vote up
public static void main(String[] args) throws Exception {
    WhiteBox.setWriteAllObjectSamples(true);

    try (Recording recording = new Recording()) {
        recording.enable(EventNames.OldObjectSample).withoutStackTrace().with("cutoff", "infinity");
        recording.start();

        addToTestField();

        recording.stop();

        List<RecordedEvent> events = Events.fromRecording(recording);
        Events.hasEvents(events);
        for (RecordedEvent e : events) {
            if (hasValidField(e)) {
                return;
            }
        }
        System.out.println(events);
        Asserts.fail("Could not find old object with field 'testField'");
    }
}
 
Example #22
Source File: TestG1.java    From openjdk-jdk8u with GNU General Public License v2.0 6 votes vote down vote up
public static void main(String[] args) throws Exception {
    WhiteBox.setWriteAllObjectSamples(true);

    try (Recording r = new Recording()) {
        r.enable(EventNames.OldObjectSample).withStackTrace().with("cutoff", "infinity");
        r.start();
        allocateFindMe();
        System.gc();
        r.stop();
        List<RecordedEvent> events = Events.fromRecording(r);
        System.out.println(events);
        if (OldObjects.countMatchingEvents(events, FindMe[].class, null, null, -1, "allocateFindMe") == 0) {
            throw new Exception("Could not find leak with " + FindMe[].class);
        }
    }
}
 
Example #23
Source File: TestParallel.java    From TencentKona-8 with GNU General Public License v2.0 6 votes vote down vote up
public static void main(String[] args) throws Exception {
    WhiteBox.setWriteAllObjectSamples(true);

    try (Recording r = new Recording()) {
        r.enable(EventNames.OldObjectSample).withStackTrace().with("cutoff", "infinity");
        r.start();
        allocateFindMe();
        System.gc();
        r.stop();
        List<RecordedEvent> events = Events.fromRecording(r);
        System.out.println(events);
        if (OldObjects.countMatchingEvents(events, FindMe[].class, null, null, -1, "allocateFindMe") == 0) {
            throw new Exception("Could not find leak with " + FindMe[].class);
        }
    }
}
 
Example #24
Source File: TestReferenceChainLimit.java    From TencentKona-8 with GNU General Public License v2.0 6 votes vote down vote up
public static void main(String[] args) throws Exception {
    WhiteBox.setWriteAllObjectSamples(true);

    try (Recording r = new Recording()) {
        r.enable(EventNames.OldObjectSample).withStackTrace().with("cutoff", "infinity");
        r.start();
        leak = createChain();
        List<RecordedEvent> events = Events.fromRecording(r);
        if (OldObjects.countMatchingEvents(events, byte[].class, null, null, -1, "createChain") == 0) {
            throw new Exception("Could not find ChainNode");
        }
        for (RecordedEvent e : events) {
            OldObjects.validateReferenceChainLimit(e, OldObjects.MAX_CHAIN_LENGTH);
        }
    }
}
 
Example #25
Source File: TestParallelOld.java    From TencentKona-8 with GNU General Public License v2.0 6 votes vote down vote up
public static void main(String[] args) throws Exception {
    WhiteBox.setWriteAllObjectSamples(true);

    try (Recording r = new Recording()) {
        r.enable(EventNames.OldObjectSample).withStackTrace().with("cutoff", "infinity");
        r.start();
        allocateFindMe();
        System.gc();
        r.stop();
        List<RecordedEvent> events = Events.fromRecording(r);
        System.out.println(events);
        if (OldObjects.countMatchingEvents(events, FindMe[].class, null, null, -1, "allocateFindMe") == 0) {
            throw new Exception("Could not find leak with " + FindMe[].class);
        }
    }
}
 
Example #26
Source File: TestHeapDeep.java    From TencentKona-8 with GNU General Public License v2.0 6 votes vote down vote up
public static void main(String[] args) throws Exception {
    WhiteBox.setWriteAllObjectSamples(true);

    try (Recording r = new Recording()) {
        r.enable(EventNames.OldObjectSample).withStackTrace().with("cutoff", "infinity");
        r.start();
        leak = createChain();
        List<RecordedEvent> events = Events.fromRecording(r);
        if (OldObjects.countMatchingEvents(events, byte[].class, null, null, -1, "createChain") == 0) {
            throw new Exception("Could not find ChainNode");
        }
        for (RecordedEvent e : events) {
            OldObjects.validateReferenceChainLimit(e, OldObjects.MAX_CHAIN_LENGTH);
        }
    }
}
 
Example #27
Source File: TestSerial.java    From openjdk-jdk8u with GNU General Public License v2.0 6 votes vote down vote up
public static void main(String[] args) throws Exception {
    WhiteBox.setWriteAllObjectSamples(true);

    try (Recording r = new Recording()) {
        r.enable(EventNames.OldObjectSample).withStackTrace().with("cutoff", "infinity");
        r.start();
        allocateFindMe();
        System.gc();
        r.stop();
        List<RecordedEvent> events = Events.fromRecording(r);
        System.out.println(events);
        if (OldObjects.countMatchingEvents(events, FindMe[].class, null, null, -1, "allocateFindMe") == 0) {
            throw new Exception("Could not find leak with " + FindMe[].class);
        }
    }
}
 
Example #28
Source File: TestJcmdDumpPathToGCRoots.java    From openjdk-jdk8u with GNU General Public License v2.0 6 votes vote down vote up
public static void main(String[] args) throws Exception {
    WhiteBox.setWriteAllObjectSamples(true);

    String settingName = EventNames.OldObjectSample + "#" + "cutoff";

    // dump parameter trumps previous setting
    testDump("path-to-gc-roots=true", Collections.singletonMap(settingName, "infinity"), true);
    testDump("path-to-gc-roots=true", Collections.singletonMap(settingName, "0 ns"), true);
    testDump("path-to-gc-roots=true", Collections.emptyMap(), true);

    testDump("path-to-gc-roots=false", Collections.singletonMap(settingName, "infinity"), false);
    testDump("path-to-gc-roots=false", Collections.singletonMap(settingName, "0 ns"), false);
    testDump("path-to-gc-roots=false", Collections.emptyMap(), false);

    testDump("", Collections.singletonMap(settingName, "infinity"), true);
    testDump("", Collections.singletonMap(settingName, "0 ns"), false);
    testDump("", Collections.emptyMap(), false);
}
 
Example #29
Source File: OldObjectSample.java    From openjdk-jdk8u with GNU General Public License v2.0 6 votes vote down vote up
public static void emit(List<PlatformRecording> recordings, Boolean pathToGcRoots) {
    boolean enabled = false;
    long cutoffNanos = Boolean.TRUE.equals(pathToGcRoots) ? Long.MAX_VALUE : 0L;
    for (PlatformRecording r : recordings) {
        if (r.getState() == RecordingState.RUNNING) {
            if (isEnabled(r)) {
                enabled = true;
                long c = CutoffSetting.parseValueSafe(r.getSettings().get(OLD_OBJECT_CUTOFF));
                cutoffNanos = Math.max(c, cutoffNanos);
            }
        }
    }
    if (enabled) {
        long ticks = Utils.nanosToTicks(cutoffNanos);
        JVM.getJVM().emitOldObjectSamples(ticks, WhiteBox.getWriteAllObjectSamples());
    }
}
 
Example #30
Source File: TestCMS.java    From TencentKona-8 with GNU General Public License v2.0 6 votes vote down vote up
public static void main(String[] args) throws Exception {
    WhiteBox.setWriteAllObjectSamples(true);

    try (Recording r = new Recording()) {
        r.enable(EventNames.OldObjectSample).withStackTrace().with("cutoff", "infinity");
        r.start();
        allocateFindMe();
        System.gc();
        r.stop();
        List<RecordedEvent> events = Events.fromRecording(r);
        System.out.println(events);
        if (OldObjects.countMatchingEvents(events, FindMe[].class, null, null, -1, "allocateFindMe") == 0) {
            throw new Exception("Could not find leak with " + FindMe[].class);
        }
    }
}