jdk.jfr.consumer.RecordedClass Java Examples
The following examples show how to use
jdk.jfr.consumer.RecordedClass.
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: 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 #2
Source File: TestEventFactory.java From dragonwell8_jdk with GNU General Public License v2.0 | 6 votes |
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 #3
Source File: TestExceptionEvents.java From dragonwell8_jdk 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 #4
Source File: ProfileResults.java From lucene-solr with Apache License 2.0 | 6 votes |
/** * Formats a frame to a formatted line. This is deduplicated on! */ static String frameToString(RecordedFrame frame, boolean lineNumbers) { StringBuilder builder = new StringBuilder(); RecordedMethod method = frame.getMethod(); RecordedClass clazz = method.getType(); if (clazz == null) { builder.append("<<"); builder.append(frame.getType()); builder.append(">>"); } else { builder.append(clazz.getName()); } builder.append("#"); builder.append(method.getName()); builder.append("()"); if (lineNumbers) { builder.append(":"); if (frame.getLineNumber() == -1) { builder.append("(" + frame.getType() + " code)"); } else { builder.append(frame.getLineNumber()); } } return builder.toString(); }
Example #5
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 #6
Source File: TestEventFactory.java From openjdk-jdk8u with GNU General Public License v2.0 | 6 votes |
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 #7
Source File: PrettyWriter.java From openjdk-jdk8u with GNU General Public License v2.0 | 6 votes |
private void printClass(RecordedClass clazz, String postFix) { RecordedClassLoader classLoader = clazz.getClassLoader(); String classLoaderName = "null"; if (classLoader != null) { if (classLoader.getName() != null) { classLoaderName = classLoader.getName(); } else { classLoaderName = classLoader.getType().getName(); } } String className = clazz.getName(); if (className.startsWith("[")) { className = decodeDescriptors(className, "").get(0); } println(className + " (classLoader = " + classLoaderName + ")" + postFix); }
Example #8
Source File: PrettyWriter.java From openjdk-jdk8u with GNU General Public License v2.0 | 6 votes |
void printObject(RecordedObject object, long arraySize) { RecordedClass clazz = object.getClass("type"); if (clazz != null) { String className = clazz.getName(); if (className!= null && className.startsWith("[")) { className = decodeDescriptors(className, arraySize > 0 ? Long.toString(arraySize) : "").get(0); } print(className); String description = object.getString("description"); if (description != null) { print(" "); print(description); } } println(); }
Example #9
Source File: PrettyWriter.java From TencentKona-8 with GNU General Public License v2.0 | 6 votes |
void printObject(RecordedObject object, long arraySize) { RecordedClass clazz = object.getClass("type"); if (clazz != null) { String className = clazz.getName(); if (className!= null && className.startsWith("[")) { className = decodeDescriptors(className, arraySize > 0 ? Long.toString(arraySize) : "").get(0); } print(className); String description = object.getString("description"); if (description != null) { print(" "); print(description); } } println(); }
Example #10
Source File: PrettyWriter.java From TencentKona-8 with GNU General Public License v2.0 | 6 votes |
private void printClass(RecordedClass clazz, String postFix) { RecordedClassLoader classLoader = clazz.getClassLoader(); String classLoaderName = "null"; if (classLoader != null) { if (classLoader.getName() != null) { classLoaderName = classLoader.getName(); } else { classLoaderName = classLoader.getType().getName(); } } String className = clazz.getName(); if (className.startsWith("[")) { className = decodeDescriptors(className, "").get(0); } println(className + " (classLoader = " + classLoaderName + ")" + postFix); }
Example #11
Source File: TestEventFactory.java From TencentKona-8 with GNU General Public License v2.0 | 6 votes |
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 #12
Source File: TestClassUnloadEvent.java From openjdk-jdk8u with GNU General Public License v2.0 | 5 votes |
public static void main(String[] args) throws Throwable { Recording recording = new Recording(); recording.enable(EVENT_PATH).withThreshold(Duration.ofMillis(0)); unloadableClassLoader = new TestClassLoader(); recording.start(); unloadableClassLoader.loadClass(TEST_CLASS_NAME); unloadableClassLoader = null; System.gc(); recording.stop(); List<RecordedEvent> events = Events.fromRecording(recording); Events.hasEvents(events); boolean isAnyFound = false; for (RecordedEvent event : events) { System.out.println("Event:" + event); RecordedClass unloadedClass = event.getValue("unloadedClass"); if (TEST_CLASS_NAME.equals(unloadedClass.getName())) { RecordedClassLoader definingClassLoader = unloadedClass.getClassLoader(); Asserts.assertEquals(TestClassLoader.class.getName(), definingClassLoader.getType().getName(), "Expected " + TestClassLoader.class.getName() + ", got " + definingClassLoader.getType().getName()); //Asserts.assertEquals(TestClassLoader.CLASS_LOADER_NAME, definingClassLoader.getName(), // "Expected " + TestClassLoader.CLASS_LOADER_NAME + ", got " + definingClassLoader.getName()); Asserts.assertFalse(isAnyFound, "Found more than 1 event"); isAnyFound = true; } } Asserts.assertTrue(isAnyFound, "No events found"); }
Example #13
Source File: OldObjects.java From openjdk-jdk8u with GNU General Public License v2.0 | 5 votes |
private static Predicate<RecordedEvent> fieldIsType(Class<?> fieldType) { if (fieldType != null) { return e -> e.hasField("object.type") && ((RecordedClass) e.getValue("object.type")).getName().equals(fieldType.getName()); } else { return e -> true; } }
Example #14
Source File: TestArrayInformation.java From openjdk-jdk8u with GNU General Public License v2.0 | 5 votes |
private static void verifyObjectArray(List<RecordedEvent> events) throws Exception { for (RecordedEvent e : events) { RecordedObject object = e.getValue("object"); RecordedClass objectType = object.getValue("type"); RecordedObject referrer = object.getValue("referrer"); System.out.println(objectType.getName()); if (objectType.getName().equals(ArrayLeak[].class.getName())) { for (int i = 0; i < CHAIN_DEPTH; i++) { object = referrer.getValue("object"); if (object == null) { throw new Exception("Expected referrer object"); } objectType = object.getValue("type"); if (!objectType.getName().equals(Object[].class.getName())) { throw new Exception("Expect array class to be named " + Object[].class + " but found " + objectType.getName()); } RecordedObject field = referrer.getValue("field"); if (field != null) { throw new Exception("Didn't expect to find field"); } RecordedObject array = referrer.getValue("array"); if (array == null) { throw new Exception("Expected array object, but got null"); } int index = referrer.getValue("array.index"); if (index != ARRAY_INDEX) { throw new Exception("Expected array index: " + ARRAY_INDEX + ", but got " + index); } int size = referrer.getValue("array.size"); if (size != ARRAY_SIZE) { throw new Exception("Expected array size: " + ARRAY_SIZE + ", but got " + size); } referrer = object.getValue("referrer"); } return; } } throw new Exception("Could not find event with " + ArrayLeak[].class + " as (leak) object"); }
Example #15
Source File: TestClassDefineEvent.java From openjdk-jdk8u with GNU General Public License v2.0 | 5 votes |
public static void main(String[] args) throws Throwable { Recording recording = new Recording(); recording.enable(EVENT_NAME); TestClassLoader cl = new TestClassLoader(); recording.start(); cl.loadClass(TEST_CLASS_NAME); recording.stop(); List<RecordedEvent> events = Events.fromRecording(recording); boolean foundTestClasses = false; for (RecordedEvent event : events) { System.out.println(event); RecordedClass definedClass = event.getValue("definedClass"); if (TEST_CLASS_NAME.equals(definedClass.getName())) { RecordedClassLoader definingClassLoader = definedClass.getClassLoader(); Asserts.assertNotNull(definingClassLoader, "Defining Class Loader should not be null"); RecordedClass definingClassLoaderType = definingClassLoader.getType(); Asserts.assertNotNull(definingClassLoaderType, "The defining Class Loader type should not be null"); Asserts.assertEquals(cl.getClass().getName(), definingClassLoaderType.getName(), "Expected type " + cl.getClass().getName() + ", got type " + definingClassLoaderType.getName()); //Asserts.assertEquals(cl.getName(), definingClassLoader.getName(), // "Defining Class Loader should have the same name as the original class loader"); foundTestClasses = true; } } Asserts.assertTrue(foundTestClasses, "No class define event found for " + TEST_CLASS_NAME); }
Example #16
Source File: OldObjects.java From openjdk-jdk8u with GNU General Public License v2.0 | 5 votes |
private static Predicate<RecordedEvent> isReferrerType(Class<?> referrerType) { if (referrerType != null) { return e -> { RecordedObject referrer = e.getValue("object.referrer"); return referrer != null ? referrer.hasField("object.type") && ((RecordedClass) referrer.getValue("object.type")).getName().equals(referrerType.getName()) : false; }; } else { return e -> true; } }
Example #17
Source File: OldObjects.java From openjdk-jdk8u with GNU General Public License v2.0 | 5 votes |
public static boolean matchingReferrerClass(RecordedEvent event, String className) { RecordedObject referrer = event.getValue("object.referrer"); if (referrer != null) { if (!referrer.hasField("object.type")) { return false; } String reportedClass = ((RecordedClass) referrer.getValue("object.type")).getName(); if (reportedClass.equals(className)) { return true; } } return false; }
Example #18
Source File: Events.java From TencentKona-8 with GNU General Public License v2.0 | 5 votes |
public static void assertClassModule(final RecordedClass rc, final String moduleNameTarget) { final RecordedObject recordedPackage = getRecordedPackage(rc); final RecordedObject recordedModule = getRecordedModule(recordedPackage); if (recordedModule == null) { if (moduleNameTarget != null) { throw new RuntimeException("RecordedClass module is null!"); } return; } assertTrue(isMatchingTargetName(recordedModule, moduleNameTarget), "mismatched module name! Target is " + moduleNameTarget); }
Example #19
Source File: Events.java From openjdk-jdk8u with GNU General Public License v2.0 | 5 votes |
public static void assertClassModule(final RecordedClass rc, final String moduleNameTarget) { final RecordedObject recordedPackage = getRecordedPackage(rc); final RecordedObject recordedModule = getRecordedModule(recordedPackage); if (recordedModule == null) { if (moduleNameTarget != null) { throw new RuntimeException("RecordedClass module is null!"); } return; } assertTrue(isMatchingTargetName(recordedModule, moduleNameTarget), "mismatched module name! Target is " + moduleNameTarget); }
Example #20
Source File: Events.java From TencentKona-8 with GNU General Public License v2.0 | 5 votes |
public static void assertClassPackage(final RecordedClass rc, final String packageNameTarget) { final RecordedObject recordedPackage = getRecordedPackage(rc); if (recordedPackage == null) { if (packageNameTarget != null) { throw new RuntimeException("RecordedClass package is null!"); } return; } assertTrue(isMatchingTargetName(recordedPackage, packageNameTarget), "mismatched package name! Target is " + packageNameTarget); }
Example #21
Source File: TestClassLoaderLeak.java From TencentKona-8 with GNU General Public License v2.0 | 5 votes |
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 #22
Source File: TestMetadataRetention.java From TencentKona-8 with GNU General Public License v2.0 | 5 votes |
private static void validateClassUnloadEvent(List<RecordedEvent> events) throws Throwable { for (RecordedEvent event : events) { if (event.getEventType().getName().equals(EventNames.ClassUnload)) { RecordedClass unloadedClass = event.getValue("unloadedClass"); if (TEST_CLASS_NAME.equals(unloadedClass.getName())) { RecordedClassLoader definingClassLoader = unloadedClass.getClassLoader(); Asserts.assertEquals(TEST_CLASS_LOADER_NAME, definingClassLoader.getName(), "Expected " + TEST_CLASS_LOADER_NAME + ", got " + definingClassLoader.getType().getName()); return; } } } }
Example #23
Source File: TestAllocationTime.java From TencentKona-8 with GNU General Public License v2.0 | 5 votes |
private static RecordedObject findLeak(List<RecordedEvent> events, String name) throws Exception { for (RecordedEvent e : events) { if (e.getEventType().getName().equals(EventNames.OldObjectSample)) { RecordedObject object = e.getValue("object"); RecordedClass rc = object.getValue("type"); if (rc.getName().equals(Leak[].class.getName())) { return e; } } } return null; }
Example #24
Source File: JFRJDK9Event.java From visualvm with GNU General Public License v2.0 | 5 votes |
@Override public JFRClass getClass(String key) throws JFRPropertyNotAvailableException { Object rclass = getValue(key); if (rclass == null) return null; else if (rclass instanceof RecordedClass) return new JFRJDK9Class((RecordedClass)rclass); else throw new JFRPropertyNotAvailableException("No class value available: " + key); }
Example #25
Source File: OldObjects.java From TencentKona-8 with GNU General Public License v2.0 | 5 votes |
private static Predicate<RecordedEvent> fieldIsType(Class<?> fieldType) { if (fieldType != null) { return e -> e.hasField("object.type") && ((RecordedClass) e.getValue("object.type")).getName().equals(fieldType.getName()); } else { return e -> true; } }
Example #26
Source File: TestLargeRootSet.java From TencentKona-8 with GNU General Public License v2.0 | 5 votes |
public static void main(String[] args) throws Exception { WhiteBox.setWriteAllObjectSamples(true); List<RootThread> threads = new ArrayList<>(); try (Recording r = new Recording()) { r.enable(EventNames.OldObjectSample).withStackTrace().with("cutoff", "infinity"); r.start(); CyclicBarrier cb = new CyclicBarrier(THREAD_COUNT + 1); for (int i = 0; i < THREAD_COUNT; i++) { RootThread t = new RootThread(cb); t.start(); if (i % 10 == 0) { // Give threads some breathing room before starting next batch Thread.sleep(100); } threads.add(t); } cb.await(); System.gc(); r.stop(); cb.await(); List<RecordedEvent> events = Events.fromRecording(r); Events.hasEvents(events); for (RecordedEvent e : events) { RecordedObject ro = e.getValue("object"); RecordedClass rc = ro.getValue("type"); System.out.println(rc.getName()); if (rc.getName().equals(StackObject[].class.getName())) { return; // ok } } Asserts.fail("Could not find root object"); } }
Example #27
Source File: OldObjects.java From TencentKona-8 with GNU General Public License v2.0 | 5 votes |
public static boolean matchingReferrerClass(RecordedEvent event, String className) { RecordedObject referrer = event.getValue("object.referrer"); if (referrer != null) { if (!referrer.hasField("object.type")) { return false; } String reportedClass = ((RecordedClass) referrer.getValue("object.type")).getName(); if (reportedClass.equals(className)) { return true; } } return false; }
Example #28
Source File: OldObjects.java From TencentKona-8 with GNU General Public License v2.0 | 5 votes |
private static Predicate<RecordedEvent> isReferrerType(Class<?> referrerType) { if (referrerType != null) { return e -> { RecordedObject referrer = e.getValue("object.referrer"); return referrer != null ? referrer.hasField("object.type") && ((RecordedClass) referrer.getValue("object.type")).getName().equals(referrerType.getName()) : false; }; } else { return e -> true; } }
Example #29
Source File: TestArrayInformation.java From TencentKona-8 with GNU General Public License v2.0 | 5 votes |
private static void verifyObjectArray(List<RecordedEvent> events) throws Exception { for (RecordedEvent e : events) { RecordedObject object = e.getValue("object"); RecordedClass objectType = object.getValue("type"); RecordedObject referrer = object.getValue("referrer"); System.out.println(objectType.getName()); if (objectType.getName().equals(ArrayLeak[].class.getName())) { for (int i = 0; i < CHAIN_DEPTH; i++) { object = referrer.getValue("object"); if (object == null) { throw new Exception("Expected referrer object"); } objectType = object.getValue("type"); if (!objectType.getName().equals(Object[].class.getName())) { throw new Exception("Expect array class to be named " + Object[].class + " but found " + objectType.getName()); } RecordedObject field = referrer.getValue("field"); if (field != null) { throw new Exception("Didn't expect to find field"); } RecordedObject array = referrer.getValue("array"); if (array == null) { throw new Exception("Expected array object, but got null"); } int index = referrer.getValue("array.index"); if (index != ARRAY_INDEX) { throw new Exception("Expected array index: " + ARRAY_INDEX + ", but got " + index); } int size = referrer.getValue("array.size"); if (size != ARRAY_SIZE) { throw new Exception("Expected array size: " + ARRAY_SIZE + ", but got " + size); } referrer = object.getValue("referrer"); } return; } } throw new Exception("Could not find event with " + ArrayLeak[].class + " as (leak) object"); }
Example #30
Source File: PrettyWriter.java From openjdk-jdk8u with GNU General Public License v2.0 | 5 votes |
private void printClassLoader(RecordedClassLoader cl, String postFix) { // Purposely not printing class loader name to avoid cluttered output RecordedClass clazz = cl.getType(); print(clazz == null ? "null" : clazz.getName()); if (clazz != null) { print(" ("); print("id = "); print(String.valueOf(cl.getId())); println(")"); } }