jdk.jfr.consumer.RecordedThread Java Examples

The following examples show how to use jdk.jfr.consumer.RecordedThread. 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: IOEvent.java    From TencentKona-8 with GNU General Public License v2.0 6 votes vote down vote up
public static IOEvent createTestEvent(RecordedEvent event) {
    EventType eventType = getEventType(event);
    if (eventType == EventType.UnknownEvent) {
        return null;
    }
    EventField ev = Events.assertField(event, "eventThread");
    RecordedThread t = ev.getValue();
    String thread = t.getJavaName();
    long size = 0L;
    if (isWriteEvent(eventType)) {
        size = Events.assertField(event, "bytesWritten").getValue();
    } else if (isReadEvent(eventType)) {
        size = Events.assertField(event, "bytesRead").getValue();
    }
    String address = getEventAddress(event);
    boolean endOfStream = false;
    if (event.hasField("endOfStream")) {
        endOfStream = event.getValue("endOfStream");
    }
    if (event.hasField("endOfFile")) {
        endOfStream = event.getValue("endOfFile");
    }
    return new IOEvent(thread, eventType, size, address, endOfStream);
}
 
Example #2
Source File: IOEvent.java    From dragonwell8_jdk with GNU General Public License v2.0 6 votes vote down vote up
public static IOEvent createTestEvent(RecordedEvent event) {
    EventType eventType = getEventType(event);
    if (eventType == EventType.UnknownEvent) {
        return null;
    }
    EventField ev = Events.assertField(event, "eventThread");
    RecordedThread t = ev.getValue();
    String thread = t.getJavaName();
    long size = 0L;
    if (isWriteEvent(eventType)) {
        size = Events.assertField(event, "bytesWritten").getValue();
    } else if (isReadEvent(eventType)) {
        size = Events.assertField(event, "bytesRead").getValue();
    }
    String address = getEventAddress(event);
    boolean endOfStream = false;
    if (event.hasField("endOfStream")) {
        endOfStream = event.getValue("endOfStream");
    }
    if (event.hasField("endOfFile")) {
        endOfStream = event.getValue("endOfFile");
    }
    return new IOEvent(thread, eventType, size, address, endOfStream);
}
 
Example #3
Source File: TestJavaMonitorWaitTimeOut.java    From dragonwell8_jdk with GNU General Public License v2.0 6 votes vote down vote up
private static void assertTimeOutEvent(List<RecordedEvent> events, long timeout, String expectedThreadName) {
    for (RecordedEvent e : events) {
        if (isWaitEvent(e)) {
            Long l = e.getValue("timeout");
            if (l == timeout) {
                RecordedThread notifier = e.getValue("notifier");
                String threadName = null;
                if (notifier != null) {
                    threadName = notifier.getJavaName();
                }
                Asserts.assertEquals(threadName, expectedThreadName, "Invalid thread");
                return;
            }
        }
    }
    Asserts.fail("Could not find event with monitorClass" + Lock.class.getName());
}
 
Example #4
Source File: TestMetadataRetention.java    From dragonwell8_jdk with GNU General Public License v2.0 6 votes vote down vote up
private static void validateOldObjectEvent(List<RecordedEvent> events, Instant chunkRotation) throws Throwable {
    for (RecordedEvent event : events) {
        if (event.getEventType().getName().equals(EventNames.OldObjectSample)) {
            // Only check event after the rotation
            if (!event.getStartTime().isBefore(chunkRotation)) {
                System.out.println(event);
                RecordedThread rt = event.getThread();
                if (rt.getJavaName().equals(ALLOCATOR_THREAD_NAME)) {
                    RecordedStackTrace s = event.getStackTrace();
                    assertStackTrace(s, "startRecurse");
                    assertStackTrace(s, "recurse");
                    return;
                }
            }
        }
    }

    Asserts.fail("Did not find an old object event with thread " + ALLOCATOR_THREAD_NAME);
}
 
Example #5
Source File: TestVMOperation.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 {
    Recording recording = new Recording();
    recording.enable(EVENT_NAME).withThreshold(Duration.ofMillis(0));
    recording.start();
    System.gc();
    recording.stop();

    List<RecordedEvent> events = Events.fromRecording(recording);
    Events.hasEvents(events);
    for (RecordedEvent event : Events.fromRecording(recording)) {
        String operation = Events.assertField(event, "operation").notEmpty().getValue();
        if (operation.equals(VM_OPERATION)) {
            Events.assertField(event, "safepoint").equal(true);
            Events.assertField(event, "blocking").equal(true);
            RecordedThread jt = event.getValue("caller");
            if (Thread.currentThread().getName().equals(jt.getJavaName())) {
                return;
            }
        }
    }
    throw new AssertionError("No matching event with VM operation name " + VM_OPERATION + " and current threasd as caller");
}
 
Example #6
Source File: IOEvent.java    From dragonwell8_jdk with GNU General Public License v2.0 6 votes vote down vote up
public static IOEvent createTestEvent(RecordedEvent event) {
    EventType eventType = getEventType(event);
    if (eventType == EventType.UnknownEvent) {
        return null;
    }
    EventField ev = Events.assertField(event, "eventThread");
    RecordedThread t = ev.getValue();
    String thread = t.getJavaName();
    long size = 0L;
    if (isWriteEvent(eventType)) {
        size = Events.assertField(event, "bytesWritten").getValue();
    } else if (isReadEvent(eventType)) {
        size = Events.assertField(event, "bytesRead").getValue();
    }
    String address = getEventAddress(event);
    boolean endOfStream = false;
    if (event.hasField("endOfStream")) {
        endOfStream = event.getValue("endOfStream");
    }
    if (event.hasField("endOfFile")) {
        endOfStream = event.getValue("endOfFile");
    }
    return new IOEvent(thread, eventType, size, address, endOfStream);
}
 
Example #7
Source File: TestRecordedEventGetThread.java    From TencentKona-8 with GNU General Public License v2.0 6 votes vote down vote up
public static void main(String[] args) throws Throwable {
    Thread currentThread = Thread.currentThread();
    currentThread.setName(MY_THREAD_NAME);
    long expectedThreadId = currentThread.getId();

    Recording r = new Recording();
    r.start();
    SimpleEvent t = new SimpleEvent();
    t.commit();
    r.stop();
    List<RecordedEvent> events = Events.fromRecording(r);
    r.close();
    Events.hasEvents(events);
    RecordedEvent event = events.get(0);
    RecordedThread recordedThread = event.getThread();

    Asserts.assertNotNull(recordedThread);
    Asserts.assertEquals(recordedThread.getJavaName(), MY_THREAD_NAME);
    Asserts.assertEquals(recordedThread.getJavaThreadId(), expectedThreadId);
    Asserts.assertNotNull(recordedThread.getOSThreadId());
    Asserts.assertNotNull(recordedThread.getId());
    Asserts.assertEquals(recordedThread.getOSName(), MY_THREAD_NAME);
}
 
Example #8
Source File: TestEventFactory.java    From TencentKona-8 with GNU General Public License v2.0 6 votes vote down vote up
private static void verifyValues(RecordedEvent event) {
    for (Map.Entry<String, Object> entry : EVENT_VALUES.entrySet()) {
        String fieldName = entry.getKey();
        Object value = event.getValue(fieldName);
        Object expected = EVENT_VALUES.get(fieldName);
        if (expected instanceof Class) {
            value = ((RecordedClass) value).getName();
            expected = ((Class<?>) expected).getName();
        }
        if (expected instanceof Thread) {
            value = ((RecordedThread) value).getJavaName();
            expected = ((Thread) expected).getName();
        }
        Asserts.assertEQ(value, expected);
    }
}
 
Example #9
Source File: TestJcmdStartWithSettings.java    From TencentKona-8 with GNU General Public License v2.0 6 votes vote down vote up
private static void assertHasEvent(File file, String eventType, String threadName) throws Exception {
    for (RecordedEvent event : RecordingFile.readAllEvents(file.toPath())) {
        if (Events.isEventType(event, eventType)) {
            System.out.println(event);
            RecordedThread t = event.getThread();
            if (t == null) {
                throw new Exception("Thread null for event " + eventType);
            }
            if (threadName.equals(t.getJavaName())) {
                System.out.println("Found event: " + event);
                return;
            }
        }
    }
    Asserts.fail("No events of type " + eventType);
}
 
Example #10
Source File: TestVMOperation.java    From TencentKona-8 with GNU General Public License v2.0 6 votes vote down vote up
public static void main(String[] args) throws Throwable {
    Recording recording = new Recording();
    recording.enable(EVENT_NAME).withThreshold(Duration.ofMillis(0));
    recording.start();
    System.gc();
    recording.stop();

    List<RecordedEvent> events = Events.fromRecording(recording);
    Events.hasEvents(events);
    for (RecordedEvent event : Events.fromRecording(recording)) {
        String operation = Events.assertField(event, "operation").notEmpty().getValue();
        if (operation.equals(VM_OPERATION)) {
            Events.assertField(event, "safepoint").equal(true);
            Events.assertField(event, "blocking").equal(true);
            RecordedThread jt = event.getValue("caller");
            if (Thread.currentThread().getName().equals(jt.getJavaName())) {
                return;
            }
        }
    }
    throw new AssertionError("No matching event with VM operation name " + VM_OPERATION + " and current threasd as caller");
}
 
Example #11
Source File: TestExceptionEvents.java    From TencentKona-8 with GNU General Public License v2.0 6 votes vote down vote up
private static void checkThrowableEvents(List<RecordedEvent> events, String eventName,
    int excpectedEvents, Class<?> expectedClass, String expectedMessage) throws Exception {
    int count = 0;
    for(RecordedEvent event : events) {
        if (Events.isEventType(event, eventName)) {
            String message = Events.assertField(event, "message").getValue();
            if (expectedMessage.equals(message)) {
                RecordedThread t = event.getThread();
                String threadName = t.getJavaName();
                if (threadName != null && threadName.equals(Thread.currentThread().getName())) {
                    RecordedClass jc = event.getValue("thrownClass");
                    if (jc.getName().equals(expectedClass.getName())) {
                        count++;
                    }
                }
            }
        }
    }
    Asserts.assertEquals(count, excpectedEvents, "Wrong event count for type " + eventName);
}
 
Example #12
Source File: TestThreadAllocationEvent.java    From TencentKona-8 with GNU General Public License v2.0 6 votes vote down vote up
/**
* Verify that the allocated value never decreases.
* We only compare our own allocator threads. The reason for that is that other threads
* may start/stop at any time, and we do not know if other thread names are unique.
*/
private static void verifyAllocationsNotDecreasing(List<RecordedEvent> events, AllocatorThread[] threads) {
    Collections.sort(events, (u,v) -> u.getEndTime().compareTo(v.getEndTime()));
    long[] prevAllocated = new long[threads.length];
    for (RecordedEvent event : events) {
        RecordedThread rt = Events.assertField(event, "thread").notNull().getValue(); // Check that we have a thread.
        String name = rt.getJavaName();
        for (int i = 0; i < threads.length; i++) {
            if (name.equals(threads[i].getName())) {
                long curr = Events.assertField(event, "allocated").atLeast(prevAllocated[i]).getValue();
                prevAllocated[i] = curr;
            }
        }
    }

    for (int i = 0; i < threads.length; i++) {
        assertGreaterThan(prevAllocated[i], 0L, "No allocations for thread " + threads[i].getName());
    }
}
 
Example #13
Source File: TestThreadAllocationEvent.java    From TencentKona-8 with GNU General Public License v2.0 6 votes vote down vote up
/**
  * Verify that total allocated bytes in JFR event approximately matches the value in ThreadMXBean.
  */
private static void verifyTotalAllocated(List<RecordedEvent> events, AllocatorThread[] threads) {
    boolean[] isEventFound = new boolean[threads.length];
    for (RecordedEvent event : events) {
        RecordedThread rt = Events.assertField(event, "thread").notNull().getValue();
        String name = rt.getJavaName();
        for (int i = 0; i < threads.length; ++i) {
            if (name.equals(threads[i].getName())) {
                System.out.println("Event:" + event);
                long maxAllowed = threads[i].totalAllocated + allowedTotalAllocatedDiff;
                long minAllowed = Math.max(0, threads[i].totalAllocated - allowedTotalAllocatedDiff);
                Events.assertField(event, "allocated").atLeast(minAllowed).atMost(maxAllowed);
                isEventFound[i] = true;
            }
        }
    }
    for (int i = 0; i < threads.length; ++i) {
        assertTrue(isEventFound[i], "No event for thread id " + i);
    }
}
 
Example #14
Source File: TestJavaMonitorWaitTimeOut.java    From TencentKona-8 with GNU General Public License v2.0 6 votes vote down vote up
private static void assertTimeOutEvent(List<RecordedEvent> events, long timeout, String expectedThreadName) {
    for (RecordedEvent e : events) {
        if (isWaitEvent(e)) {
            Long l = e.getValue("timeout");
            if (l == timeout) {
                RecordedThread notifier = e.getValue("notifier");
                String threadName = null;
                if (notifier != null) {
                    threadName = notifier.getJavaName();
                }
                Asserts.assertEquals(threadName, expectedThreadName, "Invalid thread");
                return;
            }
        }
    }
    Asserts.fail("Could not find event with monitorClass" + Lock.class.getName());
}
 
Example #15
Source File: TestMetadataRetention.java    From TencentKona-8 with GNU General Public License v2.0 6 votes vote down vote up
private static void validateOldObjectEvent(List<RecordedEvent> events, Instant chunkRotation) throws Throwable {
    for (RecordedEvent event : events) {
        if (event.getEventType().getName().equals(EventNames.OldObjectSample)) {
            // Only check event after the rotation
            if (!event.getStartTime().isBefore(chunkRotation)) {
                System.out.println(event);
                RecordedThread rt = event.getThread();
                if (rt.getJavaName().equals(ALLOCATOR_THREAD_NAME)) {
                    RecordedStackTrace s = event.getStackTrace();
                    assertStackTrace(s, "startRecurse");
                    assertStackTrace(s, "recurse");
                    return;
                }
            }
        }
    }

    Asserts.fail("Did not find an old object event with thread " + ALLOCATOR_THREAD_NAME);
}
 
Example #16
Source File: TestRecordedObject.java    From dragonwell8_jdk with GNU General Public License v2.0 6 votes vote down vote up
private static void testGetThread(RecordedObject e) {
    RecordedThread thread = e.getValue("threadField");
    if (!thread.getJavaName().equals(THREAD_VALUE.getName())) {
        throw new AssertionError("Expected thread to have name " + THREAD_VALUE.getName());
    }
    assertGetter(x -> {
        // OK to access nullField if it is correct type
        // Chose a second null field with class type
        if ("nullField".equals(x)) {
            return e.getThread("nullField2");
        } else {
            return e.getThread(x);
        }

    }, thread, "thread");
}
 
Example #17
Source File: Events.java    From TencentKona-8 with GNU General Public License v2.0 6 votes vote down vote up
private static void assertThread(RecordedThread eventThread, Thread thread) {
    assertNotNull(eventThread, "Thread in event was null");
    assertEquals(eventThread.getJavaThreadId(), thread.getId(), "Wrong thread id");
    assertEquals(eventThread.getJavaName(), thread.getName(), "Wrong thread name");

    ThreadGroup threadGroup = thread.getThreadGroup();
    RecordedThreadGroup eventThreadGroup = eventThread.getThreadGroup();
    assertNotNull(eventThreadGroup, "eventThreadGroup was null");

    // Iterate and check all threadGroups
    while (eventThreadGroup != null) {
        final String groupName = eventThreadGroup.getName();
        if (threadGroup != null) {
            assertEquals(groupName, threadGroup.getName(), "Wrong threadGroup name");
            threadGroup = threadGroup.getParent();
        } else {
            assertNotNull(groupName, "threadGroup name was null");
            assertFalse(groupName.isEmpty(), "threadGroup name was empty");
        }
        eventThreadGroup = eventThreadGroup.getParent();
    }
}
 
Example #18
Source File: TestRecordedEventGetThreadOther.java    From openjdk-jdk8u with GNU General Public License v2.0 6 votes vote down vote up
public static void main(String[] args) throws Throwable {
    Thread.currentThread().setName("MyMainThread");

    PostingThread thread = new PostingThread();
    thread.start();
    thread.join();
    System.out.println("testing dump in file " + dumpFilePath);

    List<RecordedEvent> events = RecordingFile.readAllEvents(dumpFilePath);
    Asserts.assertEquals(events.size(), 1);

    RecordedEvent event = events.get(0);
    RecordedThread recordedThread = event.getThread();

    Asserts.assertNotNull(recordedThread);
    Asserts.assertEquals(recordedThread.getJavaName(), MY_THREAD_NAME);
    Asserts.assertEquals(recordedThread.getJavaThreadId(), expectedThreadId);
    Asserts.assertNotNull(recordedThread.getId());
    Asserts.assertEquals(recordedThread.getOSName(), MY_THREAD_NAME);
}
 
Example #19
Source File: TestRecordedObject.java    From openjdk-jdk8u with GNU General Public License v2.0 6 votes vote down vote up
private static void testGetThread(RecordedObject e) {
    RecordedThread thread = e.getValue("threadField");
    if (!thread.getJavaName().equals(THREAD_VALUE.getName())) {
        throw new AssertionError("Expected thread to have name " + THREAD_VALUE.getName());
    }
    assertGetter(x -> {
        // OK to access nullField if it is correct type
        // Chose a second null field with class type
        if ("nullField".equals(x)) {
            return e.getThread("nullField2");
        } else {
            return e.getThread(x);
        }

    }, thread, "thread");
}
 
Example #20
Source File: TestRecordedEventGetThread.java    From openjdk-jdk8u with GNU General Public License v2.0 6 votes vote down vote up
public static void main(String[] args) throws Throwable {
    Thread currentThread = Thread.currentThread();
    currentThread.setName(MY_THREAD_NAME);
    long expectedThreadId = currentThread.getId();

    Recording r = new Recording();
    r.start();
    SimpleEvent t = new SimpleEvent();
    t.commit();
    r.stop();
    List<RecordedEvent> events = Events.fromRecording(r);
    r.close();
    Events.hasEvents(events);
    RecordedEvent event = events.get(0);
    RecordedThread recordedThread = event.getThread();

    Asserts.assertNotNull(recordedThread);
    Asserts.assertEquals(recordedThread.getJavaName(), MY_THREAD_NAME);
    Asserts.assertEquals(recordedThread.getJavaThreadId(), expectedThreadId);
    Asserts.assertNotNull(recordedThread.getOSThreadId());
    Asserts.assertNotNull(recordedThread.getId());
    Asserts.assertEquals(recordedThread.getOSName(), MY_THREAD_NAME);
}
 
Example #21
Source File: TestEventFactory.java    From openjdk-jdk8u with GNU General Public License v2.0 6 votes vote down vote up
private static void verifyValues(RecordedEvent event) {
    for (Map.Entry<String, Object> entry : EVENT_VALUES.entrySet()) {
        String fieldName = entry.getKey();
        Object value = event.getValue(fieldName);
        Object expected = EVENT_VALUES.get(fieldName);
        if (expected instanceof Class) {
            value = ((RecordedClass) value).getName();
            expected = ((Class<?>) expected).getName();
        }
        if (expected instanceof Thread) {
            value = ((RecordedThread) value).getJavaName();
            expected = ((Thread) expected).getName();
        }
        Asserts.assertEQ(value, expected);
    }
}
 
Example #22
Source File: TestJcmdStartWithSettings.java    From openjdk-jdk8u with GNU General Public License v2.0 6 votes vote down vote up
private static void assertHasEvent(File file, String eventType, String threadName) throws Exception {
    for (RecordedEvent event : RecordingFile.readAllEvents(file.toPath())) {
        if (Events.isEventType(event, eventType)) {
            System.out.println(event);
            RecordedThread t = event.getThread();
            if (t == null) {
                throw new Exception("Thread null for event " + eventType);
            }
            if (threadName.equals(t.getJavaName())) {
                System.out.println("Found event: " + event);
                return;
            }
        }
    }
    Asserts.fail("No events of type " + eventType);
}
 
Example #23
Source File: TestVMOperation.java    From openjdk-jdk8u with GNU General Public License v2.0 6 votes vote down vote up
public static void main(String[] args) throws Throwable {
    Recording recording = new Recording();
    recording.enable(EVENT_NAME).withThreshold(Duration.ofMillis(0));
    recording.start();
    System.gc();
    recording.stop();

    List<RecordedEvent> events = Events.fromRecording(recording);
    Events.hasEvents(events);
    for (RecordedEvent event : Events.fromRecording(recording)) {
        String operation = Events.assertField(event, "operation").notEmpty().getValue();
        if (operation.equals(VM_OPERATION)) {
            Events.assertField(event, "safepoint").equal(true);
            Events.assertField(event, "blocking").equal(true);
            RecordedThread jt = event.getValue("caller");
            if (Thread.currentThread().getName().equals(jt.getJavaName())) {
                return;
            }
        }
    }
    throw new AssertionError("No matching event with VM operation name " + VM_OPERATION + " and current threasd as caller");
}
 
Example #24
Source File: TestExceptionEvents.java    From openjdk-jdk8u with GNU General Public License v2.0 6 votes vote down vote up
private static void checkThrowableEvents(List<RecordedEvent> events, String eventName,
    int excpectedEvents, Class<?> expectedClass, String expectedMessage) throws Exception {
    int count = 0;
    for(RecordedEvent event : events) {
        if (Events.isEventType(event, eventName)) {
            String message = Events.assertField(event, "message").getValue();
            if (expectedMessage.equals(message)) {
                RecordedThread t = event.getThread();
                String threadName = t.getJavaName();
                if (threadName != null && threadName.equals(Thread.currentThread().getName())) {
                    RecordedClass jc = event.getValue("thrownClass");
                    if (jc.getName().equals(expectedClass.getName())) {
                        count++;
                    }
                }
            }
        }
    }
    Asserts.assertEquals(count, excpectedEvents, "Wrong event count for type " + eventName);
}
 
Example #25
Source File: TestThreadAllocationEvent.java    From openjdk-jdk8u with GNU General Public License v2.0 6 votes vote down vote up
/**
* Verify that the allocated value never decreases.
* We only compare our own allocator threads. The reason for that is that other threads
* may start/stop at any time, and we do not know if other thread names are unique.
*/
private static void verifyAllocationsNotDecreasing(List<RecordedEvent> events, AllocatorThread[] threads) {
    Collections.sort(events, (u,v) -> u.getEndTime().compareTo(v.getEndTime()));
    long[] prevAllocated = new long[threads.length];
    for (RecordedEvent event : events) {
        RecordedThread rt = Events.assertField(event, "thread").notNull().getValue(); // Check that we have a thread.
        String name = rt.getJavaName();
        for (int i = 0; i < threads.length; i++) {
            if (name.equals(threads[i].getName())) {
                long curr = Events.assertField(event, "allocated").atLeast(prevAllocated[i]).getValue();
                prevAllocated[i] = curr;
            }
        }
    }

    for (int i = 0; i < threads.length; i++) {
        assertGreaterThan(prevAllocated[i], 0L, "No allocations for thread " + threads[i].getName());
    }
}
 
Example #26
Source File: TestThreadAllocationEvent.java    From openjdk-jdk8u with GNU General Public License v2.0 6 votes vote down vote up
/**
  * Verify that total allocated bytes in JFR event approximately matches the value in ThreadMXBean.
  */
private static void verifyTotalAllocated(List<RecordedEvent> events, AllocatorThread[] threads) {
    boolean[] isEventFound = new boolean[threads.length];
    for (RecordedEvent event : events) {
        RecordedThread rt = Events.assertField(event, "thread").notNull().getValue();
        String name = rt.getJavaName();
        for (int i = 0; i < threads.length; ++i) {
            if (name.equals(threads[i].getName())) {
                System.out.println("Event:" + event);
                long maxAllowed = threads[i].totalAllocated + allowedTotalAllocatedDiff;
                long minAllowed = Math.max(0, threads[i].totalAllocated - allowedTotalAllocatedDiff);
                Events.assertField(event, "allocated").atLeast(minAllowed).atMost(maxAllowed);
                isEventFound[i] = true;
            }
        }
    }
    for (int i = 0; i < threads.length; ++i) {
        assertTrue(isEventFound[i], "No event for thread id " + i);
    }
}
 
Example #27
Source File: TestJavaMonitorWaitTimeOut.java    From openjdk-jdk8u with GNU General Public License v2.0 6 votes vote down vote up
private static void assertTimeOutEvent(List<RecordedEvent> events, long timeout, String expectedThreadName) {
    for (RecordedEvent e : events) {
        if (isWaitEvent(e)) {
            Long l = e.getValue("timeout");
            if (l == timeout) {
                RecordedThread notifier = e.getValue("notifier");
                String threadName = null;
                if (notifier != null) {
                    threadName = notifier.getJavaName();
                }
                Asserts.assertEquals(threadName, expectedThreadName, "Invalid thread");
                return;
            }
        }
    }
    Asserts.fail("Could not find event with monitorClass" + Lock.class.getName());
}
 
Example #28
Source File: TestMetadataRetention.java    From openjdk-jdk8u with GNU General Public License v2.0 6 votes vote down vote up
private static void validateOldObjectEvent(List<RecordedEvent> events, Instant chunkRotation) throws Throwable {
    for (RecordedEvent event : events) {
        if (event.getEventType().getName().equals(EventNames.OldObjectSample)) {
            // Only check event after the rotation
            if (!event.getStartTime().isBefore(chunkRotation)) {
                System.out.println(event);
                RecordedThread rt = event.getThread();
                if (rt.getJavaName().equals(ALLOCATOR_THREAD_NAME)) {
                    RecordedStackTrace s = event.getStackTrace();
                    assertStackTrace(s, "startRecurse");
                    assertStackTrace(s, "recurse");
                    return;
                }
            }
        }
    }

    Asserts.fail("Did not find an old object event with thread " + ALLOCATOR_THREAD_NAME);
}
 
Example #29
Source File: IOEvent.java    From openjdk-jdk8u with GNU General Public License v2.0 6 votes vote down vote up
public static IOEvent createTestEvent(RecordedEvent event) {
    EventType eventType = getEventType(event);
    if (eventType == EventType.UnknownEvent) {
        return null;
    }
    EventField ev = Events.assertField(event, "eventThread");
    RecordedThread t = ev.getValue();
    String thread = t.getJavaName();
    long size = 0L;
    if (isWriteEvent(eventType)) {
        size = Events.assertField(event, "bytesWritten").getValue();
    } else if (isReadEvent(eventType)) {
        size = Events.assertField(event, "bytesRead").getValue();
    }
    String address = getEventAddress(event);
    boolean endOfStream = false;
    if (event.hasField("endOfStream")) {
        endOfStream = event.getValue("endOfStream");
    }
    if (event.hasField("endOfFile")) {
        endOfStream = event.getValue("endOfFile");
    }
    return new IOEvent(thread, eventType, size, address, endOfStream);
}
 
Example #30
Source File: Events.java    From openjdk-jdk8u with GNU General Public License v2.0 6 votes vote down vote up
private static void assertThread(RecordedThread eventThread, Thread thread) {
    assertNotNull(eventThread, "Thread in event was null");
    assertEquals(eventThread.getJavaThreadId(), thread.getId(), "Wrong thread id");
    assertEquals(eventThread.getJavaName(), thread.getName(), "Wrong thread name");

    ThreadGroup threadGroup = thread.getThreadGroup();
    RecordedThreadGroup eventThreadGroup = eventThread.getThreadGroup();
    assertNotNull(eventThreadGroup, "eventThreadGroup was null");

    // Iterate and check all threadGroups
    while (eventThreadGroup != null) {
        final String groupName = eventThreadGroup.getName();
        if (threadGroup != null) {
            assertEquals(groupName, threadGroup.getName(), "Wrong threadGroup name");
            threadGroup = threadGroup.getParent();
        } else {
            assertNotNull(groupName, "threadGroup name was null");
            assertFalse(groupName.isEmpty(), "threadGroup name was empty");
        }
        eventThreadGroup = eventThreadGroup.getParent();
    }
}