jdk.jfr.internal.JVM Java Examples

The following examples show how to use jdk.jfr.internal.JVM. 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: TestUnloadEventClassCount.java    From TencentKona-8 with GNU General Public License v2.0 6 votes vote down vote up
public static void main(String[] args) throws Throwable {
    FlightRecorder.getFlightRecorder();
    myClassLoader = createClassLoaderWithEventClass();
    System.out.println("MyClassLoader instance created");
    long initialCount = JVM.getJVM().getUnloadedEventClassCount();
    System.out.println("Initiali unloaded count is " + initialCount);
    myClassLoader = null;
    System.out.println("Reference to class loader cleared");
    long count = 0;
    do {
        System.gc();
        System.out.println("GC triggered");
        count = JVM.getJVM().getUnloadedEventClassCount();
        System.out.println("Unloaded count was " + count);
        Thread.sleep(1000); // sleep to reduce log
    } while (count != initialCount + 1);
}
 
Example #2
Source File: TestCreateNative.java    From openjdk-jdk8u with GNU General Public License v2.0 6 votes vote down vote up
public static void main(String... args) throws Exception {
    JVM jvm = JVM.getJVM();
    // Ensure that repeated failures can be handled
    for (int i = 1; i < 4; i++) {
        System.out.println("About to try failed initialization, attempt " + i + " out of 3");
        assertFailedInitialization(jvm);
        System.out.println("As expected, initialization failed.");
    }
    // Ensure that Flight Recorder can be initialized properly after failures
    Configuration defConfig = Configuration.getConfiguration("default");
    Recording r = new Recording(defConfig);
    r.start();
    r.stop();
    r.dump(Paths.get("recording.jfr"));
    r.close();
}
 
Example #3
Source File: TestGetAllEventClasses.java    From dragonwell8_jdk with GNU General Public License v2.0 6 votes vote down vote up
@SafeVarargs
private static void assertEvents(JVM jvm, boolean inclusion, Class<? extends Event>... targetEvents) {
    final List<Class<? extends Event>> list = jvm.getAllEventClasses();
    for (Class<? extends Event> ev : targetEvents) {
       if (list.contains(ev)) {
           if (inclusion) {
               continue;
           }
           throw new AssertionError(ev.getName() + " in list but should not be!");
       }
       if (!inclusion) {
           continue;
       }
       throw new AssertionError(ev.getName() + " in not in list but should be!");
   }
}
 
Example #4
Source File: JFRSecurityTestSuite.java    From openjdk-jdk8u with GNU General Public License v2.0 6 votes vote down vote up
private static void checkNoDirectAccess() throws Throwable {
    assertPermission(() -> {
                sm.checkPackageAccess("jdk.jfr.internal");
            }, RuntimePermission.class, null, false);

    assertPermission(() -> {
                Class.forName("jdk.jfr.internal.JVM");
            }, RuntimePermission.class, null, false);

    assertPermission(() -> {
                JVM.getJVM();
            }, RuntimePermission.class, null, false);

    assertPermission(() -> {
                sm.checkPackageAccess("jdk.jfr.events");
            }, RuntimePermission.class, null, false);

    assertPermission(() -> {
                Class.forName("jdk.jfr.events.AbstractJDKEvent");
            }, RuntimePermission.class, null, false);

    assertPermission(() -> {
                sm.checkPackageAccess("jdk.management.jfr.internal");
            }, RuntimePermission.class, null, false);
}
 
Example #5
Source File: TestUnloadingEventClass.java    From openjdk-jdk8u with GNU General Public License v2.0 6 votes vote down vote up
private static void unLoadEventClass() throws Exception {
    long firstCount = jvm.getUnloadedEventClassCount();
    System.out.println("Initial unloaded count: " + firstCount);
    myClassLoader = null;
    System.out.println("Cleared reference to MyClassLoader");
    long newCount = 0;
    do {
        System.out.println("GC triggered");
        System.gc();
        Thread.sleep(1000);
        newCount = jvm.getUnloadedEventClassCount();
        System.out.println("Unloaded count: " + newCount);
    } while (firstCount + 1 != newCount);
    System.out.println("Event class unloaded!");
    System.out.println("Event classes currently on the heap:");
    for (Class<?> eventClass : JVM.getJVM().getAllEventClasses()) {
        //System.out.println(eventClass + " " + (eventClass.getClassLoader() != null ? eventClass.getClassLoader().getName() : null));
    }

}
 
Example #6
Source File: TestUnloadEventClassCount.java    From dragonwell8_jdk with GNU General Public License v2.0 6 votes vote down vote up
public static void main(String[] args) throws Throwable {
    FlightRecorder.getFlightRecorder();
    myClassLoader = createClassLoaderWithEventClass();
    System.out.println("MyClassLoader instance created");
    long initialCount = JVM.getJVM().getUnloadedEventClassCount();
    System.out.println("Initiali unloaded count is " + initialCount);
    myClassLoader = null;
    System.out.println("Reference to class loader cleared");
    long count = 0;
    do {
        System.gc();
        System.out.println("GC triggered");
        count = JVM.getJVM().getUnloadedEventClassCount();
        System.out.println("Unloaded count was " + count);
        Thread.sleep(1000); // sleep to reduce log
    } while (count != initialCount + 1);
}
 
Example #7
Source File: TestCreateNative.java    From dragonwell8_jdk with GNU General Public License v2.0 6 votes vote down vote up
public static void main(String... args) throws Exception {
    JVM jvm = JVM.getJVM();
    // Ensure that repeated failures can be handled
    for (int i = 1; i < 4; i++) {
        System.out.println("About to try failed initialization, attempt " + i + " out of 3");
        assertFailedInitialization(jvm);
        System.out.println("As expected, initialization failed.");
    }
    // Ensure that Flight Recorder can be initialized properly after failures
    Configuration defConfig = Configuration.getConfiguration("default");
    Recording r = new Recording(defConfig);
    r.start();
    r.stop();
    r.dump(Paths.get("recording.jfr"));
    r.close();
}
 
Example #8
Source File: TestUnloadEventClassCount.java    From openjdk-jdk8u with GNU General Public License v2.0 6 votes vote down vote up
public static void main(String[] args) throws Throwable {
    FlightRecorder.getFlightRecorder();
    myClassLoader = createClassLoaderWithEventClass();
    System.out.println("MyClassLoader instance created");
    long initialCount = JVM.getJVM().getUnloadedEventClassCount();
    System.out.println("Initiali unloaded count is " + initialCount);
    myClassLoader = null;
    System.out.println("Reference to class loader cleared");
    long count = 0;
    do {
        System.gc();
        System.out.println("GC triggered");
        count = JVM.getJVM().getUnloadedEventClassCount();
        System.out.println("Unloaded count was " + count);
        Thread.sleep(1000); // sleep to reduce log
    } while (count != initialCount + 1);
}
 
Example #9
Source File: TestGetAllEventClasses.java    From openjdk-jdk8u with GNU General Public License v2.0 6 votes vote down vote up
@SafeVarargs
private static void assertEvents(JVM jvm, boolean inclusion, Class<? extends Event>... targetEvents) {
    final List<Class<? extends Event>> list = jvm.getAllEventClasses();
    for (Class<? extends Event> ev : targetEvents) {
       if (list.contains(ev)) {
           if (inclusion) {
               continue;
           }
           throw new AssertionError(ev.getName() + " in list but should not be!");
       }
       if (!inclusion) {
           continue;
       }
       throw new AssertionError(ev.getName() + " in not in list but should be!");
   }
}
 
Example #10
Source File: TestUnloadingEventClass.java    From dragonwell8_jdk with GNU General Public License v2.0 6 votes vote down vote up
private static void unLoadEventClass() throws Exception {
    long firstCount = jvm.getUnloadedEventClassCount();
    System.out.println("Initial unloaded count: " + firstCount);
    myClassLoader = null;
    System.out.println("Cleared reference to MyClassLoader");
    long newCount = 0;
    do {
        System.out.println("GC triggered");
        System.gc();
        Thread.sleep(1000);
        newCount = jvm.getUnloadedEventClassCount();
        System.out.println("Unloaded count: " + newCount);
    } while (firstCount + 1 != newCount);
    System.out.println("Event class unloaded!");
    System.out.println("Event classes currently on the heap:");
    for (Class<?> eventClass : JVM.getJVM().getAllEventClasses()) {
    }

}
 
Example #11
Source File: TestUnloadingEventClass.java    From TencentKona-8 with GNU General Public License v2.0 6 votes vote down vote up
private static void unLoadEventClass() throws Exception {
    long firstCount = jvm.getUnloadedEventClassCount();
    System.out.println("Initial unloaded count: " + firstCount);
    myClassLoader = null;
    System.out.println("Cleared reference to MyClassLoader");
    long newCount = 0;
    do {
        System.out.println("GC triggered");
        System.gc();
        Thread.sleep(1000);
        newCount = jvm.getUnloadedEventClassCount();
        System.out.println("Unloaded count: " + newCount);
    } while (firstCount + 1 != newCount);
    System.out.println("Event class unloaded!");
    System.out.println("Event classes currently on the heap:");
    for (Class<?> eventClass : JVM.getJVM().getAllEventClasses()) {
        //System.out.println(eventClass + " " + (eventClass.getClassLoader() != null ? eventClass.getClassLoader().getName() : null));
    }

}
 
Example #12
Source File: JFRSecurityTestSuite.java    From TencentKona-8 with GNU General Public License v2.0 6 votes vote down vote up
private static void checkNoDirectAccess() throws Throwable {
    assertPermission(() -> {
                sm.checkPackageAccess("jdk.jfr.internal");
            }, RuntimePermission.class, null, false);

    assertPermission(() -> {
                Class.forName("jdk.jfr.internal.JVM");
            }, RuntimePermission.class, null, false);

    assertPermission(() -> {
                JVM.getJVM();
            }, RuntimePermission.class, null, false);

    assertPermission(() -> {
                sm.checkPackageAccess("jdk.jfr.events");
            }, RuntimePermission.class, null, false);

    assertPermission(() -> {
                Class.forName("jdk.jfr.events.AbstractJDKEvent");
            }, RuntimePermission.class, null, false);

    assertPermission(() -> {
                sm.checkPackageAccess("jdk.management.jfr.internal");
            }, RuntimePermission.class, null, false);
}
 
Example #13
Source File: TestCreateNative.java    From TencentKona-8 with GNU General Public License v2.0 6 votes vote down vote up
public static void main(String... args) throws Exception {
    JVM jvm = JVM.getJVM();
    // Ensure that repeated failures can be handled
    for (int i = 1; i < 4; i++) {
        System.out.println("About to try failed initialization, attempt " + i + " out of 3");
        assertFailedInitialization(jvm);
        System.out.println("As expected, initialization failed.");
    }
    // Ensure that Flight Recorder can be initialized properly after failures
    Configuration defConfig = Configuration.getConfiguration("default");
    Recording r = new Recording(defConfig);
    r.start();
    r.stop();
    r.dump(Paths.get("recording.jfr"));
    r.close();
}
 
Example #14
Source File: TestGetAllEventClasses.java    From TencentKona-8 with GNU General Public License v2.0 6 votes vote down vote up
@SafeVarargs
private static void assertEvents(JVM jvm, boolean inclusion, Class<? extends Event>... targetEvents) {
    final List<Class<? extends Event>> list = jvm.getAllEventClasses();
    for (Class<? extends Event> ev : targetEvents) {
       if (list.contains(ev)) {
           if (inclusion) {
               continue;
           }
           throw new AssertionError(ev.getName() + " in list but should not be!");
       }
       if (!inclusion) {
           continue;
       }
       throw new AssertionError(ev.getName() + " in not in list but should be!");
   }
}
 
Example #15
Source File: TestLogImplementation.java    From openjdk-jdk8u with GNU General Public License v2.0 5 votes vote down vote up
private static void assertLogLevelUnderflow() {
    try {
        JVM.log(JFR_LOG_TAG.ordinal(), 0, (String)null);
    } catch (IllegalArgumentException ex) {
        // Expected
    }
}
 
Example #16
Source File: TestClassId.java    From openjdk-jdk8u with GNU General Public License v2.0 5 votes vote down vote up
public static void main(String... args) {
    assertClassIds();
    JVM jvm = JVM.getJVM();
    jvm.createNativeJFR();
    assertClassIds();
    jvm.destroyNativeJFR();
    assertClassIds();
}
 
Example #17
Source File: TestLogImplementation.java    From openjdk-jdk8u with GNU General Public License v2.0 5 votes vote down vote up
private static void assertLogLevelOverflow() {
    try {
        JVM.log(JFR_LOG_TAG.ordinal(), LogLevel.ERROR.ordinal() + 1, (String)null);
    } catch (IllegalArgumentException ex) {
        // Expected
    }
}
 
Example #18
Source File: TestLogImplementation.java    From openjdk-jdk8u with GNU General Public License v2.0 5 votes vote down vote up
private static void assertLogTagUnderflow() {
    try {
        JVM.log(JFR_LOG_TAG.ordinal() - 1, DEFAULT_TEST_LOG_LEVEL.ordinal(), (String)null);
    } catch (IllegalArgumentException ex) {
        // Expected
    }
}
 
Example #19
Source File: TestCounterTime.java    From openjdk-jdk8u with GNU General Public License v2.0 5 votes vote down vote up
private static void assertCounterTime() throws InterruptedException {
    long time1 = JVM.counterTime();
    assertGreaterThan(time1, 0L, "Counter time can't be negative.");

    Thread.sleep(1);

    long time2 = JVM.counterTime();
    assertGreaterThan(time2, time1, "Counter time must be increasing.");
}
 
Example #20
Source File: TestLogImplementation.java    From openjdk-jdk8u with GNU General Public License v2.0 5 votes vote down vote up
private static void assertLogTagOverflow() {
    try {
        JVM.log(10000, DEFAULT_TEST_LOG_LEVEL.ordinal(), (String)null);
    } catch (IllegalArgumentException ex) {
        // Expected
    }
}
 
Example #21
Source File: TestPid.java    From TencentKona-8 with GNU General Public License v2.0 5 votes vote down vote up
public static void main(String... args) throws InterruptedException {

        JVM jvm = JVM.getJVM();
        String pid = jvm.getPid();

        try {
            String managementPid = String.valueOf(getProcessId());
            assertEquals(pid, managementPid, "Pid doesn't match value returned by RuntimeMXBean");
        } catch (NumberFormatException nfe) {
            throw new AssertionError("Pid must be numeric, but was '" + pid + "'");
        }
    }
 
Example #22
Source File: TestCounterTime.java    From TencentKona-8 with GNU General Public License v2.0 5 votes vote down vote up
private static void assertCounterTime() throws InterruptedException {
    long time1 = JVM.counterTime();
    assertGreaterThan(time1, 0L, "Counter time can't be negative.");

    Thread.sleep(1);

    long time2 = JVM.counterTime();
    assertGreaterThan(time2, time1, "Counter time must be increasing.");
}
 
Example #23
Source File: TestCounterTime.java    From TencentKona-8 with GNU General Public License v2.0 5 votes vote down vote up
public static void main(String... args) throws InterruptedException {
    // Not enabled
    assertCounterTime();

    JVM jvm = JVM.getJVM();
    jvm.createNativeJFR();
    assertCounterTime();
    // Enabled
    jvm.destroyNativeJFR();
}
 
Example #24
Source File: TestCreateNative.java    From TencentKona-8 with GNU General Public License v2.0 5 votes vote down vote up
private static void assertFailedInitialization(JVM jvm) throws Exception {
    try {
        jvm.createFailedNativeJFR();
        throw new Exception("Expected failure when creating native JFR");
    } catch (IllegalStateException ise) {
        String message = ise.getMessage();
        if (!message.equals("Unable to start Jfr")) {
            throw new Exception("Expected failure on initialization of native JFR");
        }
    }
}
 
Example #25
Source File: TestPid.java    From openjdk-jdk8u with GNU General Public License v2.0 5 votes vote down vote up
public static void main(String... args) throws InterruptedException {

        JVM jvm = JVM.getJVM();
        String pid = jvm.getPid();

        try {
            String managementPid = String.valueOf(getProcessId());
            assertEquals(pid, managementPid, "Pid doesn't match value returned by RuntimeMXBean");
        } catch (NumberFormatException nfe) {
            throw new AssertionError("Pid must be numeric, but was '" + pid + "'");
        }
    }
 
Example #26
Source File: TestBeginAndEnd.java    From TencentKona-8 with GNU General Public License v2.0 5 votes vote down vote up
public static void main(String... args) {
    JVM jvm = JVM.getJVM();
    jvm.createNativeJFR();
    jvm.setFileNotification(MAX_CHUNK_SIZE);
    jvm.beginRecording();
    jvm.endRecording();
    jvm.destroyNativeJFR();
}
 
Example #27
Source File: TestLogImplementation.java    From TencentKona-8 with GNU General Public License v2.0 5 votes vote down vote up
private static void assertLogTagOverflow() {
    try {
        JVM.log(10000, DEFAULT_TEST_LOG_LEVEL.ordinal(), (String)null);
    } catch (IllegalArgumentException ex) {
        // Expected
    }
}
 
Example #28
Source File: TestClassId.java    From TencentKona-8 with GNU General Public License v2.0 5 votes vote down vote up
public static void main(String... args) {
    assertClassIds();
    JVM jvm = JVM.getJVM();
    jvm.createNativeJFR();
    assertClassIds();
    jvm.destroyNativeJFR();
    assertClassIds();
}
 
Example #29
Source File: TestGetEventWriter.java    From TencentKona-8 with GNU General Public License v2.0 5 votes vote down vote up
public static void main(String... args) {
    JVM jvm = JVM.getJVM();
    jvm.createNativeJFR();
    EventWriter writer = EventWriter.getEventWriter();
    assertNotNull(writer, "EventWriter should not be null");
    jvm.destroyNativeJFR();
}
 
Example #30
Source File: DCmdStart.java    From openjdk-jdk8u with GNU General Public License v2.0 5 votes vote down vote up
private void initializeWithForcedInstrumentation(Map<String, String> settings) {
    if (!hasJDKEvents(settings)) {
        return;
    }
    JVM jvm = JVM.getJVM();
    try {
       jvm.setForceInstrumentation(true);
        FlightRecorder.getFlightRecorder();
    } finally {
       jvm.setForceInstrumentation(false);
    }
}