jdk.jfr.consumer.RecordedClassLoader Java Examples

The following examples show how to use jdk.jfr.consumer.RecordedClassLoader. 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: PrettyWriter.java    From openjdk-jdk8u with GNU General Public License v2.0 6 votes vote down vote up
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 #2
Source File: PrettyWriter.java    From TencentKona-8 with GNU General Public License v2.0 6 votes vote down vote up
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 #3
Source File: TestClassLoaderStatsEvent.java    From openjdk-jdk8u with GNU General Public License v2.0 5 votes vote down vote up
public static void main(String[] args) throws Throwable {
    createDummyClassLoader(CLASS_LOADER_NAME);

    Recording recording = new Recording();
    recording.enable(EVENT_NAME);
    recording.start();
    recording.stop();
    List<RecordedEvent> consumer = Events.fromRecording(recording);
    Events.hasEvents(consumer);

    boolean isAnyFound = false;
    for (RecordedEvent event : consumer) {
        System.out.println("Event:" + event);
        if (Events.assertField(event, "classLoader").getValue() == null) {
            continue;
        }
        RecordedClassLoader recordedClassLoader = event.getValue("classLoader");
        if (CLASSLOADER_TYPE_NAME.equals(recordedClassLoader.getType().getName())) {
            Asserts.assertEquals(CLASS_LOADER_NAME, recordedClassLoader.getName(),
                "Expected class loader name " + CLASS_LOADER_NAME + ", got name " + recordedClassLoader.getName());
            Events.assertField(event, "classCount").equal(1L);
            Events.assertField(event, "chunkSize").above(1L);
            Events.assertField(event, "blockSize").above(1L);
            Events.assertField(event, "anonymousClassCount").equal(1L);
            Events.assertField(event, "anonymousChunkSize").above(1L);
            Events.assertField(event, "anonymousBlockSize").above(1L);
            isAnyFound = true;
        }
    }
    Asserts.assertTrue(isAnyFound, "No events found");
}
 
Example #4
Source File: TestClassLoadEvent.java    From openjdk-jdk8u with GNU General Public License v2.0 5 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));
    TestClassLoader cl = new TestClassLoader();
    recording.start();
    cl.loadClass(TEST_CLASS_NAME);
    recording.stop();

    List<RecordedEvent> events = Events.fromRecording(recording);
    boolean isLoaded = false;
    for (RecordedEvent event : events) {
        RecordedClass loadedClass = event.getValue("loadedClass");
        if (SEARCH_CLASS_NAME.equals(loadedClass.getName())) {
            System.out.println(event);
            //neither package nor module events are available at 8
            //Events.assertClassPackage(loadedClass, SEARCH_PACKAGE_NAME);
            //Events.assertClassModule(loadedClass, SEARCH_MODULE_NAME);
            RecordedClassLoader initiatingClassLoader = event.getValue("initiatingClassLoader");
            Asserts.assertEquals(cl.getClass().getName(), initiatingClassLoader.getType().getName(),
                "Expected type " + cl.getClass().getName() + ", got type " + initiatingClassLoader.getType().getName());
            RecordedClassLoader definingClassLoader = loadedClass.getClassLoader();
            Asserts.assertEquals(BOOT_CLASS_LOADER_NAME, definingClassLoader.getName(),
                "Expected boot loader to be the defining class loader");
            Asserts.assertNull(definingClassLoader.getType(), "boot loader should not have a type");
            isLoaded = true;
        }
    }
    Asserts.assertTrue(isLoaded, "No class load event found for class " + SEARCH_CLASS_NAME);
}
 
Example #5
Source File: PrettyWriter.java    From openjdk-jdk8u with GNU General Public License v2.0 5 votes vote down vote up
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(")");
    }
}
 
Example #6
Source File: TestClassUnloadEvent.java    From openjdk-jdk8u with GNU General Public License v2.0 5 votes vote down vote up
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 #7
Source File: TestMetadataRetention.java    From TencentKona-8 with GNU General Public License v2.0 5 votes vote down vote up
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 #8
Source File: TestClassLoaderStatsEvent.java    From TencentKona-8 with GNU General Public License v2.0 5 votes vote down vote up
public static void main(String[] args) throws Throwable {
    createDummyClassLoader(CLASS_LOADER_NAME);

    Recording recording = new Recording();
    recording.enable(EVENT_NAME);
    recording.start();
    recording.stop();
    List<RecordedEvent> consumer = Events.fromRecording(recording);
    Events.hasEvents(consumer);

    boolean isAnyFound = false;
    for (RecordedEvent event : consumer) {
        System.out.println("Event:" + event);
        if (Events.assertField(event, "classLoader").getValue() == null) {
            continue;
        }
        RecordedClassLoader recordedClassLoader = event.getValue("classLoader");
        if (CLASSLOADER_TYPE_NAME.equals(recordedClassLoader.getType().getName())) {
            Asserts.assertEquals(CLASS_LOADER_NAME, recordedClassLoader.getName(),
                "Expected class loader name " + CLASS_LOADER_NAME + ", got name " + recordedClassLoader.getName());
            Events.assertField(event, "classCount").equal(1L);
            Events.assertField(event, "chunkSize").above(1L);
            Events.assertField(event, "blockSize").above(1L);
            Events.assertField(event, "anonymousClassCount").equal(1L);
            Events.assertField(event, "anonymousChunkSize").above(1L);
            Events.assertField(event, "anonymousBlockSize").above(1L);
            isAnyFound = true;
        }
    }
    Asserts.assertTrue(isAnyFound, "No events found");
}
 
Example #9
Source File: TestClassDefineEvent.java    From TencentKona-8 with GNU General Public License v2.0 5 votes vote down vote up
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 #10
Source File: TestClassUnloadEvent.java    From TencentKona-8 with GNU General Public License v2.0 5 votes vote down vote up
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 #11
Source File: TestClassLoadEvent.java    From TencentKona-8 with GNU General Public License v2.0 5 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));
    TestClassLoader cl = new TestClassLoader();
    recording.start();
    cl.loadClass(TEST_CLASS_NAME);
    recording.stop();

    List<RecordedEvent> events = Events.fromRecording(recording);
    boolean isLoaded = false;
    for (RecordedEvent event : events) {
        RecordedClass loadedClass = event.getValue("loadedClass");
        if (SEARCH_CLASS_NAME.equals(loadedClass.getName())) {
            System.out.println(event);
            //neither package nor module events are available at 8
            //Events.assertClassPackage(loadedClass, SEARCH_PACKAGE_NAME);
            //Events.assertClassModule(loadedClass, SEARCH_MODULE_NAME);
            RecordedClassLoader initiatingClassLoader = event.getValue("initiatingClassLoader");
            Asserts.assertEquals(cl.getClass().getName(), initiatingClassLoader.getType().getName(),
                "Expected type " + cl.getClass().getName() + ", got type " + initiatingClassLoader.getType().getName());
            RecordedClassLoader definingClassLoader = loadedClass.getClassLoader();
            Asserts.assertEquals(BOOT_CLASS_LOADER_NAME, definingClassLoader.getName(),
                "Expected boot loader to be the defining class loader");
            Asserts.assertNull(definingClassLoader.getType(), "boot loader should not have a type");
            isLoaded = true;
        }
    }
    Asserts.assertTrue(isLoaded, "No class load event found for class " + SEARCH_CLASS_NAME);
}
 
Example #12
Source File: TestClassDefineEvent.java    From openjdk-jdk8u with GNU General Public License v2.0 5 votes vote down vote up
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 #13
Source File: PrettyWriter.java    From TencentKona-8 with GNU General Public License v2.0 5 votes vote down vote up
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(")");
    }
}
 
Example #14
Source File: TestMetadataRetention.java    From openjdk-jdk8u with GNU General Public License v2.0 5 votes vote down vote up
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 #15
Source File: TestMetadataRetention.java    From dragonwell8_jdk with GNU General Public License v2.0 5 votes vote down vote up
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 #16
Source File: TestClassLoaderStatsEvent.java    From dragonwell8_jdk with GNU General Public License v2.0 5 votes vote down vote up
public static void main(String[] args) throws Throwable {
    createDummyClassLoader(CLASS_LOADER_NAME);

    Recording recording = new Recording();
    recording.enable(EVENT_NAME);
    recording.start();
    recording.stop();
    List<RecordedEvent> consumer = Events.fromRecording(recording);
    Events.hasEvents(consumer);

    boolean isAnyFound = false;
    for (RecordedEvent event : consumer) {
        System.out.println("Event:" + event);
        if (Events.assertField(event, "classLoader").getValue() == null) {
            continue;
        }
        RecordedClassLoader recordedClassLoader = event.getValue("classLoader");
        if (CLASSLOADER_TYPE_NAME.equals(recordedClassLoader.getType().getName())) {
            //Asserts.assertEquals(CLASS_LOADER_NAME, recordedClassLoader.getName(),
            //    "Expected class loader name " + CLASS_LOADER_NAME + ", got name " + recordedClassLoader.getName());
            Events.assertField(event, "classCount").equal(1L);
            Events.assertField(event, "chunkSize").above(1L);
            Events.assertField(event, "blockSize").above(1L);
            Events.assertField(event, "anonymousClassCount").equal(1L);
            Events.assertField(event, "anonymousChunkSize").above(1L);
            Events.assertField(event, "anonymousBlockSize").above(1L);
            isAnyFound = true;
        }
    }
    Asserts.assertTrue(isAnyFound, "No events found");
}
 
Example #17
Source File: TestClassDefineEvent.java    From dragonwell8_jdk with GNU General Public License v2.0 5 votes vote down vote up
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 #18
Source File: TestClassUnloadEvent.java    From dragonwell8_jdk with GNU General Public License v2.0 5 votes vote down vote up
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());
            /** unsupport class loader name in ajdk8 now
            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 #19
Source File: TestClassLoadEvent.java    From dragonwell8_jdk with GNU General Public License v2.0 5 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));
    TestClassLoader cl = new TestClassLoader();
    recording.start();
    cl.loadClass(TEST_CLASS_NAME);
    recording.stop();

    List<RecordedEvent> events = Events.fromRecording(recording);
    boolean isLoaded = false;
    for (RecordedEvent event : events) {
        RecordedClass loadedClass = event.getValue("loadedClass");
        if (SEARCH_CLASS_NAME.equals(loadedClass.getName())) {
            System.out.println(event);
            /** unsupported now
            Events.assertClassPackage(loadedClass, SEARCH_PACKAGE_NAME);
            Events.assertClassModule(loadedClass, SEARCH_MODULE_NAME);
            */
            RecordedClassLoader initiatingClassLoader = event.getValue("initiatingClassLoader");
            Asserts.assertEquals(cl.getClass().getName(), initiatingClassLoader.getType().getName(),
                "Expected type " + cl.getClass().getName() + ", got type " + initiatingClassLoader.getType().getName());
            RecordedClassLoader definingClassLoader = loadedClass.getClassLoader();
            Asserts.assertEquals(BOOT_CLASS_LOADER_NAME, definingClassLoader.getName(),
                "Expected boot loader to be the defining class loader");
            Asserts.assertNull(definingClassLoader.getType(), "boot loader should not have a type");
            isLoaded = true;
        }
    }
    Asserts.assertTrue(isLoaded, "No class load event found for class " + SEARCH_CLASS_NAME);
}
 
Example #20
Source File: DisplayableSupport.java    From visualvm with GNU General Public License v2.0 4 votes vote down vote up
@Override
String createValue(JFRJDK9Event event, ValueDescriptor descriptor) throws JFRPropertyNotAvailableException {
    Object value = event.getValue(descriptor.getName());
    return value instanceof RecordedClassLoader ? ((RecordedClassLoader)value).getType().getName(): ""; // NOTE: should actually be "bootstrap"
}
 
Example #21
Source File: TestRecordedEvent.java    From dragonwell8_jdk with GNU General Public License v2.0 4 votes vote down vote up
public static void main(String[] args) throws Throwable {
    Recording r = new Recording();
    r.start();
    TestEvent t = new TestEvent();
    t.commit();
    r.stop();
    List<RecordedEvent> events = Events.fromRecording(r);
    Events.hasEvents(events);

    Asserts.assertEquals(events.size(), 1);

    RecordedEvent event = events.get(0);
    System.out.println(event);

    List<ValueDescriptor> descriptors = event.getFields();

    System.out.println("Descriptors");
    for (ValueDescriptor descriptor : descriptors) {
        System.out.println(descriptor.getName());
        System.out.println(descriptor.getTypeName());
    }
    System.out.println("Descriptors end");

    Object recordedClass = event.getValue("clzField");
    Asserts.assertTrue(recordedClass instanceof RecordedClass, "Expected Recorded Class got " + recordedClass);

    Object recordedInt = event.getValue("intField");
    Asserts.assertTrue(recordedInt instanceof Integer);

    Object recordedString = event.getValue("stringField");
    System.out.println("recordedString class: " + recordedString.getClass());
    Asserts.assertTrue(recordedString instanceof String);

    Object myClass = event.getValue("myClass");
    Asserts.assertTrue(myClass instanceof RecordedClass, "Expected Recorded Class got " + recordedClass);

    RecordedClass myRecClass = (RecordedClass) myClass;
    Asserts.assertEquals(MyClass.class.getName(), myRecClass.getName(), "Got " + myRecClass.getName());

    Object recordedClassLoader = myRecClass.getValue("classLoader");
    Asserts.assertTrue(recordedClassLoader instanceof RecordedClassLoader, "Expected Recorded ClassLoader got " + recordedClassLoader);

    RecordedClassLoader myRecClassLoader = (RecordedClassLoader)recordedClassLoader;
    ClassLoader cl = MyClass.class.getClassLoader();
    Asserts.assertEquals(cl.getClass().getName(), myRecClassLoader.getType().getName(), "Expected Recorded ClassLoader type to equal loader type");

    Asserts.assertNotNull(myRecClass.getModifiers());
}
 
Example #22
Source File: TestRecordedClassLoader.java    From openjdk-jdk8u with GNU General Public License v2.0 4 votes vote down vote up
public static void main(String[] args) throws Exception {
    Recording recording = new Recording();
    recording.enable(EVENT_NAME).withoutStackTrace();
    TestClassLoader cl = new TestClassLoader();
    recording.start();
    cl.loadClass(TEST_CLASS_NAME);
    recording.stop();

    List<RecordedEvent> events = Events.fromRecording(recording);
    boolean isDefined = false;
    for (RecordedEvent event : events) {
        RecordedClass definedClass = event.getValue("definedClass");
        if (TEST_CLASS_NAME.equals(definedClass.getName())) {
            System.out.println(event);

            // get the RecordedClassLoader from the RecordedClass, the "definedClass"
            RecordedClassLoader definingClassLoader = definedClass.getClassLoader();
            Asserts.assertNotNull(definingClassLoader, "Defining Class Loader should not be null");

            // invoke RecordedClassLoader.getType() in order to validate the type of the RecordedClassLoader
            RecordedClass definingClassLoaderType = definingClassLoader.getType();
            Asserts.assertNotNull(definingClassLoaderType, "The defining Class Loader type should not be null");

            // verify matching types
            Asserts.assertEquals(cl.getClass().getName(), definingClassLoaderType.getName(),
                "Expected type " + cl.getClass().getName() + ", got type " + definingClassLoaderType.getName());

            // get a RecordedClassLoader directly from the "definingClassLoader" field as well
            RecordedClassLoader definingClassLoaderFromField = event.getValue("definingClassLoader");
            Asserts.assertNotNull(definingClassLoaderFromField,
                "Defining Class Loader instantatiated from field should not be null");

            // ensure that the class loader instance used in the test actually has a name
            //Asserts.assertNotNull(cl.getName(),
              //  "Expected a valid name for the TestClassLoader");

            // invoke RecordedClassLoader.getName() to get the name of the class loader instance
            //Asserts.assertEquals(cl.getName(), definingClassLoader.getName(),
              //  "Defining Class Loader should have the same name as the original class loader");
            Asserts.assertEquals(definingClassLoaderFromField.getName(), definingClassLoader.getName(),
                "Defining Class Loader representations should have the same class loader name");

            // invoke uniqueID()
            Asserts.assertGreaterThan(definingClassLoader.getId(), 0L, "Invalid id assignment");

            // second order class loader information ("check class loader of the class loader")
            RecordedClassLoader classLoaderOfDefClassLoader = definingClassLoaderType.getClassLoader();
            Asserts.assertNotNull(classLoaderOfDefClassLoader,
                "The class loader for the definining class loader should not be null");
           // Asserts.assertEquals(cl.getClass().getClassLoader().getName(), classLoaderOfDefClassLoader.getName(),
             //   "Expected class loader name " + cl.getClass().getClassLoader().getName() + ", got name " + classLoaderOfDefClassLoader.getName());

            RecordedClass classLoaderOfDefClassLoaderType = classLoaderOfDefClassLoader.getType();
            Asserts.assertNotNull(classLoaderOfDefClassLoaderType,
                "The class loader type for the defining class loader should not be null");
            Asserts.assertEquals(cl.getClass().getClassLoader().getClass().getName(), classLoaderOfDefClassLoaderType.getName(),
                "Expected type " + cl.getClass().getClassLoader().getClass().getName() + ", got type " + classLoaderOfDefClassLoaderType.getName());

            Asserts.assertGreaterThan(definingClassLoader.getId(), classLoaderOfDefClassLoader.getId(),
                "expected id assignment invariant broken for Class Loaders");

            isDefined = true;
        }
    }
    Asserts.assertTrue(isDefined, "No class define event found to verify RecordedClassLoader");
}
 
Example #23
Source File: TestRecordedEvent.java    From openjdk-jdk8u with GNU General Public License v2.0 4 votes vote down vote up
public static void main(String[] args) throws Throwable {
    Recording r = new Recording();
    r.start();
    TestEvent t = new TestEvent();
    t.commit();
    r.stop();
    List<RecordedEvent> events = Events.fromRecording(r);
    Events.hasEvents(events);

    Asserts.assertEquals(events.size(), 1);

    RecordedEvent event = events.get(0);

    List<ValueDescriptor> descriptors = event.getFields();

    System.out.println("Descriptors");
    for (ValueDescriptor descriptor : descriptors) {
        System.out.println(descriptor.getName());
        System.out.println(descriptor.getTypeName());
    }
    System.out.println("Descriptors end");

    Object recordedClass = event.getValue("clzField");
    Asserts.assertTrue(recordedClass instanceof RecordedClass, "Expected Recorded Class got " + recordedClass);

    Object recordedInt = event.getValue("intField");
    Asserts.assertTrue(recordedInt instanceof Integer);

    Object recordedString = event.getValue("stringField");
    System.out.println("recordedString class: " + recordedString.getClass());
    Asserts.assertTrue(recordedString instanceof String);

    Object myClass = event.getValue("myClass");
    Asserts.assertTrue(myClass instanceof RecordedClass, "Expected Recorded Class got " + recordedClass);

    RecordedClass myRecClass = (RecordedClass) myClass;
    Asserts.assertEquals(MyClass.class.getName(), myRecClass.getName(), "Got " + myRecClass.getName());

    Object recordedClassLoader = myRecClass.getValue("classLoader");
    Asserts.assertTrue(recordedClassLoader instanceof RecordedClassLoader, "Expected Recorded ClassLoader got " + recordedClassLoader);

    RecordedClassLoader myRecClassLoader = (RecordedClassLoader)recordedClassLoader;
    ClassLoader cl = MyClass.class.getClassLoader();
    Asserts.assertEquals(cl.getClass().getName(), myRecClassLoader.getType().getName(), "Expected Recorded ClassLoader type to equal loader type");

    Asserts.assertNotNull(myRecClass.getModifiers());
}
 
Example #24
Source File: PrettyWriter.java    From openjdk-jdk8u with GNU General Public License v2.0 4 votes vote down vote up
private void printValue(Object value, ValueDescriptor field, String postFix) {
    if (value == null) {
        println("N/A" + postFix);
        return;
    }
    if (value instanceof RecordedObject) {
        if (value instanceof RecordedThread) {
            printThread((RecordedThread) value, postFix);
            return;
        }
        if (value instanceof RecordedClass) {
            printClass((RecordedClass) value, postFix);
            return;
        }
        if (value instanceof RecordedClassLoader) {
            printClassLoader((RecordedClassLoader) value, postFix);
            return;
        }
        if (value instanceof RecordedFrame) {
            RecordedFrame frame = (RecordedFrame) value;
            if (frame.isJavaFrame()) {
                printJavaFrame((RecordedFrame) value, postFix);
                return;
            }
        }
        if (value instanceof RecordedMethod) {
            println(formatMethod((RecordedMethod) value));
            return;
        }
        if (field.getTypeName().equals(TYPE_OLD_OBJECT)) {
            printOldObject((RecordedObject) value);
            return;
        }
         print((RecordedObject) value, postFix);
        return;
    }
    if (value.getClass().isArray()) {
        printArray((Object[]) value);
        return;
    }

    if (value instanceof Double) {
        Double d = (Double) value;
        if (Double.isNaN(d) || d == Double.NEGATIVE_INFINITY) {
            println("N/A");
            return;
        }
    }
    if (value instanceof Float) {
        Float f = (Float) value;
        if (Float.isNaN(f) || f == Float.NEGATIVE_INFINITY) {
            println("N/A");
            return;
        }
    }
    if (value instanceof Long) {
        Long l = (Long) value;
        if (l == Long.MIN_VALUE) {
            println("N/A");
            return;
        }
    }
    if (value instanceof Integer) {
        Integer i = (Integer) value;
        if (i == Integer.MIN_VALUE) {
            println("N/A");
            return;
        }
    }

    if (field.getContentType() != null) {
        if (printFormatted(field, value)) {
            return;
        }
    }

    String text = String.valueOf(value);
    if (value instanceof String) {
        text = "\"" + text + "\"";
    }
    println(text);
}
 
Example #25
Source File: TestRecordedClassLoader.java    From TencentKona-8 with GNU General Public License v2.0 4 votes vote down vote up
public static void main(String[] args) throws Exception {
    Recording recording = new Recording();
    recording.enable(EVENT_NAME).withoutStackTrace();
    TestClassLoader cl = new TestClassLoader();
    recording.start();
    cl.loadClass(TEST_CLASS_NAME);
    recording.stop();

    List<RecordedEvent> events = Events.fromRecording(recording);
    boolean isDefined = false;
    for (RecordedEvent event : events) {
        RecordedClass definedClass = event.getValue("definedClass");
        if (TEST_CLASS_NAME.equals(definedClass.getName())) {
            System.out.println(event);

            // get the RecordedClassLoader from the RecordedClass, the "definedClass"
            RecordedClassLoader definingClassLoader = definedClass.getClassLoader();
            Asserts.assertNotNull(definingClassLoader, "Defining Class Loader should not be null");

            // invoke RecordedClassLoader.getType() in order to validate the type of the RecordedClassLoader
            RecordedClass definingClassLoaderType = definingClassLoader.getType();
            Asserts.assertNotNull(definingClassLoaderType, "The defining Class Loader type should not be null");

            // verify matching types
            Asserts.assertEquals(cl.getClass().getName(), definingClassLoaderType.getName(),
                "Expected type " + cl.getClass().getName() + ", got type " + definingClassLoaderType.getName());

            // get a RecordedClassLoader directly from the "definingClassLoader" field as well
            RecordedClassLoader definingClassLoaderFromField = event.getValue("definingClassLoader");
            Asserts.assertNotNull(definingClassLoaderFromField,
                "Defining Class Loader instantatiated from field should not be null");

            // ensure that the class loader instance used in the test actually has a name
            //Asserts.assertNotNull(cl.getName(),
              //  "Expected a valid name for the TestClassLoader");

            // invoke RecordedClassLoader.getName() to get the name of the class loader instance
            //Asserts.assertEquals(cl.getName(), definingClassLoader.getName(),
              //  "Defining Class Loader should have the same name as the original class loader");
            Asserts.assertEquals(definingClassLoaderFromField.getName(), definingClassLoader.getName(),
                "Defining Class Loader representations should have the same class loader name");

            // invoke uniqueID()
            Asserts.assertGreaterThan(definingClassLoader.getId(), 0L, "Invalid id assignment");

            // second order class loader information ("check class loader of the class loader")
            RecordedClassLoader classLoaderOfDefClassLoader = definingClassLoaderType.getClassLoader();
            Asserts.assertNotNull(classLoaderOfDefClassLoader,
                "The class loader for the definining class loader should not be null");
           // Asserts.assertEquals(cl.getClass().getClassLoader().getName(), classLoaderOfDefClassLoader.getName(),
             //   "Expected class loader name " + cl.getClass().getClassLoader().getName() + ", got name " + classLoaderOfDefClassLoader.getName());

            RecordedClass classLoaderOfDefClassLoaderType = classLoaderOfDefClassLoader.getType();
            Asserts.assertNotNull(classLoaderOfDefClassLoaderType,
                "The class loader type for the defining class loader should not be null");
            Asserts.assertEquals(cl.getClass().getClassLoader().getClass().getName(), classLoaderOfDefClassLoaderType.getName(),
                "Expected type " + cl.getClass().getClassLoader().getClass().getName() + ", got type " + classLoaderOfDefClassLoaderType.getName());

            Asserts.assertGreaterThan(definingClassLoader.getId(), classLoaderOfDefClassLoader.getId(),
                "expected id assignment invariant broken for Class Loaders");

            isDefined = true;
        }
    }
    Asserts.assertTrue(isDefined, "No class define event found to verify RecordedClassLoader");
}
 
Example #26
Source File: TestRecordedEvent.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 {
    Recording r = new Recording();
    r.start();
    TestEvent t = new TestEvent();
    t.commit();
    r.stop();
    List<RecordedEvent> events = Events.fromRecording(r);
    Events.hasEvents(events);

    Asserts.assertEquals(events.size(), 1);

    RecordedEvent event = events.get(0);

    List<ValueDescriptor> descriptors = event.getFields();

    System.out.println("Descriptors");
    for (ValueDescriptor descriptor : descriptors) {
        System.out.println(descriptor.getName());
        System.out.println(descriptor.getTypeName());
    }
    System.out.println("Descriptors end");

    Object recordedClass = event.getValue("clzField");
    Asserts.assertTrue(recordedClass instanceof RecordedClass, "Expected Recorded Class got " + recordedClass);

    Object recordedInt = event.getValue("intField");
    Asserts.assertTrue(recordedInt instanceof Integer);

    Object recordedString = event.getValue("stringField");
    System.out.println("recordedString class: " + recordedString.getClass());
    Asserts.assertTrue(recordedString instanceof String);

    Object myClass = event.getValue("myClass");
    Asserts.assertTrue(myClass instanceof RecordedClass, "Expected Recorded Class got " + recordedClass);

    RecordedClass myRecClass = (RecordedClass) myClass;
    Asserts.assertEquals(MyClass.class.getName(), myRecClass.getName(), "Got " + myRecClass.getName());

    Object recordedClassLoader = myRecClass.getValue("classLoader");
    Asserts.assertTrue(recordedClassLoader instanceof RecordedClassLoader, "Expected Recorded ClassLoader got " + recordedClassLoader);

    RecordedClassLoader myRecClassLoader = (RecordedClassLoader)recordedClassLoader;
    ClassLoader cl = MyClass.class.getClassLoader();
    Asserts.assertEquals(cl.getClass().getName(), myRecClassLoader.getType().getName(), "Expected Recorded ClassLoader type to equal loader type");

    Asserts.assertNotNull(myRecClass.getModifiers());
}
 
Example #27
Source File: PrettyWriter.java    From TencentKona-8 with GNU General Public License v2.0 4 votes vote down vote up
private void printValue(Object value, ValueDescriptor field, String postFix) {
    if (value == null) {
        println("N/A" + postFix);
        return;
    }
    if (value instanceof RecordedObject) {
        if (value instanceof RecordedThread) {
            printThread((RecordedThread) value, postFix);
            return;
        }
        if (value instanceof RecordedClass) {
            printClass((RecordedClass) value, postFix);
            return;
        }
        if (value instanceof RecordedClassLoader) {
            printClassLoader((RecordedClassLoader) value, postFix);
            return;
        }
        if (value instanceof RecordedFrame) {
            RecordedFrame frame = (RecordedFrame) value;
            if (frame.isJavaFrame()) {
                printJavaFrame((RecordedFrame) value, postFix);
                return;
            }
        }
        if (value instanceof RecordedMethod) {
            println(formatMethod((RecordedMethod) value));
            return;
        }
        if (field.getTypeName().equals(TYPE_OLD_OBJECT)) {
            printOldObject((RecordedObject) value);
            return;
        }
         print((RecordedObject) value, postFix);
        return;
    }
    if (value.getClass().isArray()) {
        printArray((Object[]) value);
        return;
    }

    if (value instanceof Double) {
        Double d = (Double) value;
        if (Double.isNaN(d) || d == Double.NEGATIVE_INFINITY) {
            println("N/A");
            return;
        }
    }
    if (value instanceof Float) {
        Float f = (Float) value;
        if (Float.isNaN(f) || f == Float.NEGATIVE_INFINITY) {
            println("N/A");
            return;
        }
    }
    if (value instanceof Long) {
        Long l = (Long) value;
        if (l == Long.MIN_VALUE) {
            println("N/A");
            return;
        }
    }
    if (value instanceof Integer) {
        Integer i = (Integer) value;
        if (i == Integer.MIN_VALUE) {
            println("N/A");
            return;
        }
    }

    if (field.getContentType() != null) {
        if (printFormatted(field, value)) {
            return;
        }
    }

    String text = String.valueOf(value);
    if (value instanceof String) {
        text = "\"" + text + "\"";
    }
    println(text);
}
 
Example #28
Source File: TestRecordedClassLoader.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 {
    Recording recording = new Recording();
    recording.enable(EVENT_NAME).withoutStackTrace();
    TestClassLoader cl = new TestClassLoader();
    recording.start();
    cl.loadClass(TEST_CLASS_NAME);
    recording.stop();

    List<RecordedEvent> events = Events.fromRecording(recording);
    boolean isDefined = false;
    System.out.println(events);
    for (RecordedEvent event : events) {
        RecordedClass definedClass = event.getValue("definedClass");
        if (TEST_CLASS_NAME.equals(definedClass.getName())) {
            System.out.println(event);

            // get the RecordedClassLoader from the RecordedClass, the "definedClass"
            RecordedClassLoader definingClassLoader = definedClass.getClassLoader();
            Asserts.assertNotNull(definingClassLoader, "Defining Class Loader should not be null");

            // invoke RecordedClassLoader.getType() in order to validate the type of the RecordedClassLoader
            RecordedClass definingClassLoaderType = definingClassLoader.getType();
            Asserts.assertNotNull(definingClassLoaderType, "The defining Class Loader type should not be null");

            // verify matching types
            Asserts.assertEquals(cl.getClass().getName(), definingClassLoaderType.getName(),
                "Expected type " + cl.getClass().getName() + ", got type " + definingClassLoaderType.getName());

            // get a RecordedClassLoader directly from the "definingClassLoader" field as well
            RecordedClassLoader definingClassLoaderFromField = event.getValue("definingClassLoader");
            Asserts.assertNotNull(definingClassLoaderFromField,
                "Defining Class Loader instantatiated from field should not be null");

            // ensure that the class loader instance used in the test actually has a name
            /** unsupport now
            Asserts.assertNotNull(cl.getName(),
                "Expected a valid name for the TestClassLoader");

            // invoke RecordedClassLoader.getName() to get the name of the class loader instance
            Asserts.assertEquals(cl.getName(), definingClassLoader.getName(),
                "Defining Class Loader should have the same name as the original class loader");
            Asserts.assertEquals(definingClassLoaderFromField.getName(), definingClassLoader.getName(),
                "Defining Class Loader representations should have the same class loader name");
            */

            // invoke uniqueID()
            Asserts.assertGreaterThan(definingClassLoader.getId(), 0L, "Invalid id assignment");

            // second order class loader information ("check class loader of the class loader")
            RecordedClassLoader classLoaderOfDefClassLoader = definingClassLoaderType.getClassLoader();
            Asserts.assertNotNull(classLoaderOfDefClassLoader,
                "The class loader for the definining class loader should not be null");
            /** unsupport now
            Asserts.assertEquals(cl.getClass().getClassLoader().getName(), classLoaderOfDefClassLoader.getName(),
                "Expected class loader name " + cl.getClass().getClassLoader().getName() + ", got name " + classLoaderOfDefClassLoader.getName());
            */

            RecordedClass classLoaderOfDefClassLoaderType = classLoaderOfDefClassLoader.getType();
            Asserts.assertNotNull(classLoaderOfDefClassLoaderType,
                "The class loader type for the defining class loader should not be null");
            Asserts.assertEquals(cl.getClass().getClassLoader().getClass().getName(), classLoaderOfDefClassLoaderType.getName(),
                "Expected type " + cl.getClass().getClassLoader().getClass().getName() + ", got type " + classLoaderOfDefClassLoaderType.getName());

            Asserts.assertGreaterThan(definingClassLoader.getId(), classLoaderOfDefClassLoader.getId(),
                "expected id assignment invariant broken for Class Loaders");

            isDefined = true;
        }
    }
    Asserts.assertTrue(isDefined, "No class define event found to verify RecordedClassLoader");
}