Java Code Examples for jdk.jfr.internal.test.WhiteBox#setWriteAllObjectSamples()

The following examples show how to use jdk.jfr.internal.test.WhiteBox#setWriteAllObjectSamples() . 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: 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 2
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 3
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 4
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 5
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 6
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 7
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 8
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 9
Source File: TestArrayInformation.java    From TencentKona-8 with GNU General Public License v2.0 5 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();
        for(int i = 0; i < 25; i++) {
          leak.add( buildNestedArray(CHAIN_DEPTH));
        }
        recording.stop();
        List<RecordedEvent> events = Events.fromRecording(recording);
        Events.hasEvents(events);
        verifyObjectArray(events);
    }
}
 
Example 10
Source File: TestLastKnownHeapUsage.java    From TencentKona-8 with GNU General Public License v2.0 5 votes vote down vote up
public static void main(String[] args) throws Exception {
    WhiteBox.setWriteAllObjectSamples(true);
    long last = 0;
    for (int i = 1; i <= 5; i++) {
        long heapUsage = recordOldObjects(i);
        System.out.println("Recording: " + i + " heapUsage=" + heapUsage);
        if (heapUsage < last) {
            throw new Exception("Unexpect decrease of heap usage");
        }
    }
}
 
Example 11
Source File: TestObjectDescription.java    From dragonwell8_jdk with GNU General Public License v2.0 5 votes vote down vote up
public static void main(String[] args) throws Exception {
    WhiteBox.setWriteAllObjectSamples(true);

    testThreadGroupName();
    testThreadName();
    testClassName();
    testSize();
    testEllipsis();
}
 
Example 12
Source File: TestCircularReference.java    From dragonwell8_jdk with GNU General Public License v2.0 5 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).with("cutoff", "infinity").withStackTrace();
        r.start();

        TestCircularReferrer a = new TestCircularReferrer();
        TestCircularReferrer b = new TestCircularReferrer();
        TestCircularReferrer c = new TestCircularReferrer();
        a.setReference(b);
        b.setReference(c);
        c.setReference(a);
        referenceHolder.add(a);

        TestCircularReferrer selfReflector = new TestCircularReferrer();
        selfReflector.setReference(selfReflector);
        referenceHolder.add(selfReflector);

        r.stop();

        List<RecordedEvent> events = Events.fromRecording(r);
        if (events.isEmpty()) {
            throw new AssertionError("Expected Old Object Sample events!");
        }
    }
}
 
Example 13
Source File: TestObjectDescription.java    From TencentKona-8 with GNU General Public License v2.0 5 votes vote down vote up
public static void main(String[] args) throws Exception {
    WhiteBox.setWriteAllObjectSamples(true);

    testThreadGroupName();
    testThreadName();
    testClassName();
    testSize();
    testEllipsis();
}
 
Example 14
Source File: TestHeapShallow.java    From TencentKona-8 with GNU General Public License v2.0 5 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).withStackTrace().with("cutoff", "infinity");
        recording.start();

        addObjectsToShallowArray(leak);
        recording.stop();
        if (OldObjects.countMatchingEvents(recording, "addObjectsToShallowArray", byte[].class, "object", LeakObject.class, -1) < 1) {
            throw new Exception("Could not find shallow leak object");
        }
    }
}
 
Example 15
Source File: TestClassLoaderLeak.java    From openjdk-jdk8u with GNU General Public License v2.0 5 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();
        TestClassLoader testClassLoader = new TestClassLoader();
        for (Class<?> clazz : testClassLoader.loadClasses(OldObjects.MIN_SIZE / 20)) {
            // Allocate array to trigger sampling code path for interpreter / c1
            for (int i = 0; i < 20; i++) {
                Object classArray = Array.newInstance(clazz, 20);
                Array.set(classArray, i, clazz.newInstance());
                classObjects.add(classArray);
            }
        }
        r.stop();
        List<RecordedEvent> events = Events.fromRecording(r);
        Events.hasEvents(events);
        for (RecordedEvent e : events) {
            RecordedObject object = e.getValue("object");
            RecordedClass rc = object.getValue("type");
            if (rc.getName().contains("TestClass")) {
                return;
            }
        }
        Asserts.fail("Could not find class leak");
    }
}
 
Example 16
Source File: TestObjectDescription.java    From openjdk-jdk8u with GNU General Public License v2.0 5 votes vote down vote up
public static void main(String[] args) throws Exception {
    WhiteBox.setWriteAllObjectSamples(true);

    testThreadGroupName();
    testThreadName();
    testClassName();
    testSize();
    testEllipsis();
}
 
Example 17
Source File: TestCircularReference.java    From openjdk-jdk8u with GNU General Public License v2.0 5 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).with("cutoff", "infinity").withStackTrace();
        r.start();

        TestCircularReferrer a = new TestCircularReferrer();
        TestCircularReferrer b = new TestCircularReferrer();
        TestCircularReferrer c = new TestCircularReferrer();
        a.setReference(b);
        b.setReference(c);
        c.setReference(a);
        referenceHolder.add(a);

        TestCircularReferrer selfReflector = new TestCircularReferrer();
        selfReflector.setReference(selfReflector);
        referenceHolder.add(selfReflector);

        r.stop();

        List<RecordedEvent> events = Events.fromRecording(r);
        if (events.isEmpty()) {
            throw new AssertionError("Expected Old Object Sample events!");
        }
    }
}
 
Example 18
Source File: TestListenerLeak.java    From openjdk-jdk8u with GNU General Public License v2.0 5 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);
        if (OldObjects.countMatchingEvents(events, Stuff[].class, null, null, -1, "listenerLeak") == 0) {
            throw new Exception("Could not find leak with " + Stuff[].class);
        }
    }
}
 
Example 19
Source File: TestAllocationTime.java    From dragonwell8_jdk with GNU General Public License v2.0 4 votes vote down vote up
public static void main(String[] args) throws Exception {
    WhiteBox.setWriteAllObjectSamples(true);

    while(true) {
        try (Recording recording = new Recording()) {
            leak.clear();
            recording.enable(EventNames.OldObjectSample).withStackTrace().with("cutoff", "1 h");
            recording.start();

            BeforeLeakEvent be = new BeforeLeakEvent();
            be.commit();

            // Allocate array to trigger sampling code path for interpreter / c1
            for (int i = 0; i < OldObjects.MIN_SIZE; i++) {
                leak.add(new Leak[0]);
            }

            AfterLeakEvent ae = new AfterLeakEvent();
            ae.commit();

            recording.stop();

            List<RecordedEvent> events = Events.fromRecording(recording);
            Events.hasEvents(events);
            RecordedObject sample = findLeak(events, BeforeLeakEvent.class.getName());
            if (sample != null)  {
                long beforeTime = find(events, BeforeLeakEvent.class.getName()).getValue("startTime");
                long allocationTime = sample.getValue("allocationTime");
                long afterTime = find(events, AfterLeakEvent.class.getName()).getValue("startTime");
                System.out.println("Before time     : " + beforeTime);
                System.out.println("Allocation time : " + allocationTime);
                System.out.println("After time      : " + afterTime);

                if (allocationTime < beforeTime) {
                    throw new Exception("Allocation should not happen this early");
                }
                if (allocationTime > afterTime) {
                    throw new Exception("Allocation should not happen this late");
                }
                return; // sample ok
            }
        }
    }
}
 
Example 20
Source File: TestMetadataRetention.java    From TencentKona-8 with GNU General Public License v2.0 4 votes vote down vote up
public static void main(String[] args) throws Throwable {
    WhiteBox.setWriteAllObjectSamples(true);
    int failedAttempts = 0;
    while (true) {
        try (Recording recording = new Recording()) {
            recording.enable(EventNames.OldObjectSample).withStackTrace();
            recording.enable(EventNames.ClassUnload);
            recording.start();

            // Setup metadata on the Java heap (class, stack trace and thread)
            testClassLoader = new TestClassLoader();
            testClass = testClassLoader.loadClass(TEST_CLASS_NAME);
            allocatorThread = new Thread(TestMetadataRetention::allocateLeak, ALLOCATOR_THREAD_NAME);
            allocatorThread.start();
            allocatorThread.join();

            // Clear out metadata on the heap
            testClassLoader = null;
            testClass = null;
            allocatorThread = null;

            // System.gc() will trigger class unloading if -XX:+ExplicitGCInvokesConcurrent
            // is NOT set. If this flag is set G1 will never unload classes on System.gc()
            // and CMS will not guarantee that all semantically dead classes will be
            // unloaded. As far as the "jfr" key guarantees no VM flags are set from the
            // outside it should be enough with System.gc().
            System.gc();

            // Provoke a chunk rotation, which will flush out ordinary metadata.
            provokeChunkRotation();
            ChunkRotation cr = new ChunkRotation();
            cr.commit();
            recording.stop();

            List<RecordedEvent> events = Events.fromRecording(recording);
            RecordedEvent chunkRotation = findChunkRotationEvent(events);
            try {
                // Sanity check that class was unloaded
                Events.hasEvent(recording, EventNames.ClassUnload);
                validateClassUnloadEvent(events);
                // Validate that metadata for old object event has survived chunk rotation
                Events.hasEvent(recording, EventNames.OldObjectSample);
                validateOldObjectEvent(events, chunkRotation.getStartTime());
            } catch (Throwable t) {
                t.printStackTrace();
                System.err.println("Number of failed attempts " + ++failedAttempts);
                continue;
            }
            break;
        }
    }
}