Java Code Examples for jdk.jfr.consumer.RecordedThread#getJavaName()
The following examples show how to use
jdk.jfr.consumer.RecordedThread#getJavaName() .
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: TestThreadAllocationEvent.java From openjdk-jdk8u with GNU General Public License v2.0 | 6 votes |
/** * 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 2
Source File: TestExceptionEvents.java From openjdk-jdk8u with GNU General Public License v2.0 | 6 votes |
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 3
Source File: TestJavaMonitorWaitTimeOut.java From TencentKona-8 with GNU General Public License v2.0 | 6 votes |
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: TestThreadAllocationEvent.java From TencentKona-8 with GNU General Public License v2.0 | 6 votes |
/** * 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 5
Source File: TestThreadAllocationEvent.java From TencentKona-8 with GNU General Public License v2.0 | 6 votes |
/** * 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 6
Source File: TestExceptionEvents.java From TencentKona-8 with GNU General Public License v2.0 | 6 votes |
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 7
Source File: TestJavaMonitorWaitTimeOut.java From openjdk-jdk8u with GNU General Public License v2.0 | 6 votes |
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 8
Source File: IOEvent.java From dragonwell8_jdk with GNU General Public License v2.0 | 6 votes |
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 9
Source File: TestJavaMonitorWaitTimeOut.java From dragonwell8_jdk with GNU General Public License v2.0 | 6 votes |
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 10
Source File: TestThreadAllocationEvent.java From dragonwell8_jdk with GNU General Public License v2.0 | 6 votes |
/** * 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 11
Source File: TestThreadAllocationEvent.java From openjdk-jdk8u with GNU General Public License v2.0 | 6 votes |
/** * 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 12
Source File: IOEvent.java From openjdk-jdk8u with GNU General Public License v2.0 | 6 votes |
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 13
Source File: StressAllocationGCEvents.java From dragonwell8_jdk with GNU General Public License v2.0 | 5 votes |
private void checkEvent(RecordedEvent event) throws Exception { // skip check if allocation failure comes not from diver RecordedThread thread = event.getThread(); String threadName = thread.getJavaName(); if (!threadName.contains(THREAD_NAME)) { System.out.println("Skip event not from pool (from internals)"); System.out.println(" Thread Id: " + thread.getJavaThreadId() + " Thread name: " + threadName); return; } RecordedStackTrace stackTrace = event.getStackTrace(); List<RecordedFrame> frames = stackTrace.getFrames(); //String[] stacktrace = StackTraceHelper.buildStackTraceFromFrames(frames); if (!(frames.get(0).getMethod().getName().equals(DIVER_FRAME_NAME))) { System.out.println("Skip stacktrace check for: \n" + String.join("\n", threadName)); return; } assertTrue(frames.size() > RECURSION_DEPTH, "Stack trace should contain at least one more entry than the ones generated by the test recursion"); for (int i = 0; i < RECURSION_DEPTH; i++) { assertEquals(frames.get(i).getMethod().getName(), DIVER_FRAME_NAME, "Frame " + i + " is wrong: \n" + String.join("\n", threadName)); } assertNotEquals(frames.get(RECURSION_DEPTH).getMethod().getName(), DIVER_FRAME_NAME, "Too many diver frames: \n" + String.join("\n", threadName)); }
Example 14
Source File: StressAllocationGCEvents.java From TencentKona-8 with GNU General Public License v2.0 | 5 votes |
private void checkEvent(RecordedEvent event) throws Exception { // skip check if allocation failure comes not from diver RecordedThread thread = event.getThread(); String threadName = thread.getJavaName(); if (!threadName.contains(THREAD_NAME)) { System.out.println("Skip event not from pool (from internals)"); System.out.println(" Thread Id: " + thread.getJavaThreadId() + " Thread name: " + threadName); return; } RecordedStackTrace stackTrace = event.getStackTrace(); List<RecordedFrame> frames = stackTrace.getFrames(); //String[] stacktrace = StackTraceHelper.buildStackTraceFromFrames(frames); if (!(frames.get(0).getMethod().getName().equals(DIVER_FRAME_NAME))) { System.out.println("Skip stacktrace check for: \n" + String.join("\n", threadName)); return; } assertTrue(frames.size() > RECURSION_DEPTH, "Stack trace should contain at least one more entry than the ones generated by the test recursion"); for (int i = 0; i < RECURSION_DEPTH; i++) { assertEquals(frames.get(i).getMethod().getName(), DIVER_FRAME_NAME, "Frame " + i + " is wrong: \n" + String.join("\n", threadName)); } assertNotEquals(frames.get(RECURSION_DEPTH).getMethod().getName(), DIVER_FRAME_NAME, "Too many diver frames: \n" + String.join("\n", threadName)); }
Example 15
Source File: DisplayableSupport.java From visualvm with GNU General Public License v2.0 | 5 votes |
@Override String createValue(JFRJDK9Event event, ValueDescriptor descriptor) throws JFRPropertyNotAvailableException { Object value = event.getValue(descriptor.getName()); RecordedThread thread = value instanceof RecordedThread ? (RecordedThread)value : null; if (thread == null) return ""; String name = thread.getJavaName(); return name != null ? name : thread.getOSName(); }
Example 16
Source File: StressAllocationGCEvents.java From openjdk-jdk8u with GNU General Public License v2.0 | 5 votes |
private void checkEvent(RecordedEvent event) throws Exception { // skip check if allocation failure comes not from diver RecordedThread thread = event.getThread(); String threadName = thread.getJavaName(); if (!threadName.contains(THREAD_NAME)) { System.out.println("Skip event not from pool (from internals)"); System.out.println(" Thread Id: " + thread.getJavaThreadId() + " Thread name: " + threadName); return; } RecordedStackTrace stackTrace = event.getStackTrace(); List<RecordedFrame> frames = stackTrace.getFrames(); //String[] stacktrace = StackTraceHelper.buildStackTraceFromFrames(frames); if (!(frames.get(0).getMethod().getName().equals(DIVER_FRAME_NAME))) { System.out.println("Skip stacktrace check for: \n" + String.join("\n", threadName)); return; } assertTrue(frames.size() > RECURSION_DEPTH, "Stack trace should contain at least one more entry than the ones generated by the test recursion"); for (int i = 0; i < RECURSION_DEPTH; i++) { assertEquals(frames.get(i).getMethod().getName(), DIVER_FRAME_NAME, "Frame " + i + " is wrong: \n" + String.join("\n", threadName)); } assertNotEquals(frames.get(RECURSION_DEPTH).getMethod().getName(), DIVER_FRAME_NAME, "Too many diver frames: \n" + String.join("\n", threadName)); }
Example 17
Source File: AllocationStackTrace.java From dragonwell8_jdk with GNU General Public License v2.0 | 4 votes |
/** * Performs JFR recording, GC provocation/detection and stacktrace * verification for JFR event. * * @param bean MX bean for desired GC * @param memory allocator for desired type of allocations * @param expectedStack array of expected frames * @throws Exception */ private static boolean allocAndCheck(GarbageCollectorMXBean bean, MemoryAllocator memory, String[] expectedStack) throws Exception { String threadName = Thread.currentThread().getName(); String event = EventNames.AllocationRequiringGC; Recording r = new Recording(); r.enable(event).withStackTrace(); r.start(); long prevCollectionCount = bean.getCollectionCount(); long collectionCount = -1; long iterationCount = 0; do { memory.allocate(); collectionCount = bean.getCollectionCount(); iterationCount++; } while (collectionCount == prevCollectionCount); System.out.println("Allocation num: " + iterationCount); System.out.println("GC detected: " + collectionCount); r.stop(); List<RecordedEvent> events = Events.fromRecording(r); System.out.println("JFR GC events found: " + events.size()); // Find any event that matched the expected stack trace for (RecordedEvent e : events) { System.out.println("Event: " + e); RecordedThread thread = e.getThread(); String eventThreadName = thread.getJavaName(); if (!threadName.equals(eventThreadName)) { continue; } if (matchingStackTrace(e.getStackTrace(), expectedStack)) { return true; } } return false; }
Example 18
Source File: AllocationStackTrace.java From TencentKona-8 with GNU General Public License v2.0 | 4 votes |
/** * Performs JFR recording, GC provocation/detection and stacktrace * verification for JFR event. * * @param bean MX bean for desired GC * @param memory allocator for desired type of allocations * @param expectedStack array of expected frames * @throws Exception */ private static boolean allocAndCheck(GarbageCollectorMXBean bean, MemoryAllocator memory, String[] expectedStack) throws Exception { String threadName = Thread.currentThread().getName(); String event = EventNames.AllocationRequiringGC; Recording r = new Recording(); r.enable(event).withStackTrace(); r.start(); long prevCollectionCount = bean.getCollectionCount(); long collectionCount = -1; long iterationCount = 0; do { memory.allocate(); collectionCount = bean.getCollectionCount(); iterationCount++; } while (collectionCount == prevCollectionCount); System.out.println("Allocation num: " + iterationCount); System.out.println("GC detected: " + collectionCount); r.stop(); List<RecordedEvent> events = Events.fromRecording(r); System.out.println("JFR GC events found: " + events.size()); // Find any event that matched the expected stack trace for (RecordedEvent e : events) { System.out.println("Event: " + e); RecordedThread thread = e.getThread(); String eventThreadName = thread.getJavaName(); if (!threadName.equals(eventThreadName)) { continue; } if (matchingStackTrace(e.getStackTrace(), expectedStack)) { return true; } } return false; }
Example 19
Source File: AllocationStackTrace.java From openjdk-jdk8u with GNU General Public License v2.0 | 4 votes |
/** * Performs JFR recording, GC provocation/detection and stacktrace * verification for JFR event. * * @param bean MX bean for desired GC * @param memory allocator for desired type of allocations * @param expectedStack array of expected frames * @throws Exception */ private static boolean allocAndCheck(GarbageCollectorMXBean bean, MemoryAllocator memory, String[] expectedStack) throws Exception { String threadName = Thread.currentThread().getName(); String event = EventNames.AllocationRequiringGC; Recording r = new Recording(); r.enable(event).withStackTrace(); r.start(); long prevCollectionCount = bean.getCollectionCount(); long collectionCount = -1; long iterationCount = 0; do { memory.allocate(); collectionCount = bean.getCollectionCount(); iterationCount++; } while (collectionCount == prevCollectionCount); System.out.println("Allocation num: " + iterationCount); System.out.println("GC detected: " + collectionCount); r.stop(); List<RecordedEvent> events = Events.fromRecording(r); System.out.println("JFR GC events found: " + events.size()); // Find any event that matched the expected stack trace for (RecordedEvent e : events) { System.out.println("Event: " + e); RecordedThread thread = e.getThread(); String eventThreadName = thread.getJavaName(); if (!threadName.equals(eventThreadName)) { continue; } if (matchingStackTrace(e.getStackTrace(), expectedStack)) { return true; } } return false; }
Example 20
Source File: AllocationStackTrace.java From dragonwell8_jdk with GNU General Public License v2.0 | 4 votes |
/** * Performs JFR recording, GC provocation/detection and stacktrace * verification for JFR event. * * @param bean MX bean for desired GC * @param memory allocator for desired type of allocations * @param expectedStack array of expected frames * @throws Exception */ private static boolean allocAndCheck(GarbageCollectorMXBean bean, MemoryAllocator memory, String[] expectedStack) throws Exception { String threadName = Thread.currentThread().getName(); String event = EventNames.AllocationRequiringGC; Recording r = new Recording(); r.enable(event).withStackTrace(); r.start(); long prevCollectionCount = bean.getCollectionCount(); long collectionCount = -1; long iterationCount = 0; do { memory.allocate(); collectionCount = bean.getCollectionCount(); iterationCount++; } while (collectionCount == prevCollectionCount); System.out.println("Allocation num: " + iterationCount); System.out.println("GC detected: " + collectionCount); r.stop(); List<RecordedEvent> events = Events.fromRecording(r); System.out.println("JFR GC events found: " + events.size()); // Find any event that matched the expected stack trace for (RecordedEvent e : events) { System.out.println("Event: " + e); RecordedThread thread = e.getThread(); String eventThreadName = thread.getJavaName(); if (!threadName.equals(eventThreadName)) { continue; } if (matchingStackTrace(e.getStackTrace(), expectedStack)) { return true; } } return false; }