Java Code Examples for jdk.jfr.internal.JVM#getJVM()

The following examples show how to use jdk.jfr.internal.JVM#getJVM() . 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: 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 2
Source File: TestGetStackTraceId.java    From TencentKona-8 with GNU General Public License v2.0 5 votes vote down vote up
public static void main(String... args) {
    FlightRecorder.getFlightRecorder();
    JVM jvm = JVM.getJVM();

    long id10 = getStackIdOfDepth(10);
    assertValid(id10);

    long id5 = getStackIdOfDepth(5);
    assertValid(id5);

    Asserts.assertNotEquals(id5, id10, "Different stack depth must return different stack trace ids");

    assertMaxSkip(jvm);
}
 
Example 3
Source File: TestGetStackTraceId.java    From openjdk-jdk8u with GNU General Public License v2.0 5 votes vote down vote up
public static void main(String... args) {
    FlightRecorder.getFlightRecorder();
    JVM jvm = JVM.getJVM();

    long id10 = getStackIdOfDepth(10);
    assertValid(id10);

    long id5 = getStackIdOfDepth(5);
    assertValid(id5);

    Asserts.assertNotEquals(id5, id10, "Different stack depth must return different stack trace ids");

    assertMaxSkip(jvm);
}
 
Example 4
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);
    }
}
 
Example 5
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 6
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 7
Source File: TestCounterTime.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 {
    // Not enabled
    assertCounterTime();

    JVM jvm = JVM.getJVM();
    jvm.createNativeJFR();
    assertCounterTime();
    // Enabled
    jvm.destroyNativeJFR();
}
 
Example 8
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 9
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 10
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 11
Source File: TestGetAllEventClasses.java    From TencentKona-8 with GNU General Public License v2.0 5 votes vote down vote up
public static void main(String... args) throws ClassNotFoundException {
    JVM jvm = JVM.getJVM();
    // before creating  native
    assertEmptyEventList(jvm);
    jvm.createNativeJFR();
    // after creating native
    assertEmptyEventList(jvm);

    // Test event class load is triggered and only once
    Class<? extends Event> clazz = initialize("jdk.jfr.jvm.HelloWorldEvent1");
    // check that the event class is registered
    assertEventsIncluded(jvm, clazz);
    // second active use of the same event class should not add another class
    // to the list - it would already be loaded
    clazz = initialize(clazz);
    assertEventsIncluded(jvm, clazz);

    // second event class
    Class<? extends Event> clazz2 = initialize("jdk.jfr.jvm.HelloWorldEvent2");
    // the list of event classes should now have two classes registered
    assertEventsIncluded(jvm, clazz, clazz2);

    // verify that an abstract event class is not included
    Class<? extends Event> abstractClass = initialize(MyAbstractEvent.class); // to run <clinit>
    assertEventsExcluded(jvm, abstractClass);

    // verify that a class that is yet to run its <clinit> is not included in the list of event classes
    assertEventsExcluded(jvm, MyUnInitializedEvent.class);

    // ensure old classes are not lost
    assertEventsIncluded(jvm, clazz, clazz2);

    jvm.destroyNativeJFR();
}
 
Example 12
Source File: DCmdStart.java    From dragonwell8_jdk 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);
    }
}
 
Example 13
Source File: DCmdStart.java    From TencentKona-8 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);
    }
}
 
Example 14
Source File: TestCounterTime.java    From dragonwell8_jdk 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 15
Source File: TestGetEventWriter.java    From openjdk-jdk8u 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 16
Source File: TestBeginAndEnd.java    From dragonwell8_jdk 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 17
Source File: TestClassId.java    From dragonwell8_jdk 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 18
Source File: TestGetEventWriter.java    From dragonwell8_jdk 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 19
Source File: TestGetAllEventClasses.java    From openjdk-jdk8u with GNU General Public License v2.0 5 votes vote down vote up
public static void main(String... args) throws ClassNotFoundException {
    JVM jvm = JVM.getJVM();
    // before creating  native
    assertEmptyEventList(jvm);
    jvm.createNativeJFR();
    // after creating native
    assertEmptyEventList(jvm);

    // Test event class load is triggered and only once
    Class<? extends Event> clazz = initialize("jdk.jfr.jvm.HelloWorldEvent1");
    // check that the event class is registered
    assertEventsIncluded(jvm, clazz);
    // second active use of the same event class should not add another class
    // to the list - it would already be loaded
    clazz = initialize(clazz);
    assertEventsIncluded(jvm, clazz);

    // second event class
    Class<? extends Event> clazz2 = initialize("jdk.jfr.jvm.HelloWorldEvent2");
    // the list of event classes should now have two classes registered
    assertEventsIncluded(jvm, clazz, clazz2);

    // verify that an abstract event class is not included
    Class<? extends Event> abstractClass = initialize(MyAbstractEvent.class); // to run <clinit>
    assertEventsExcluded(jvm, abstractClass);

    // verify that a class that is yet to run its <clinit> is not included in the list of event classes
    assertEventsExcluded(jvm, MyUnInitializedEvent.class);

    // ensure old classes are not lost
    assertEventsIncluded(jvm, clazz, clazz2);

    jvm.destroyNativeJFR();
}
 
Example 20
Source File: TestGetStackTraceId.java    From dragonwell8_jdk with GNU General Public License v2.0 5 votes vote down vote up
public static void main(String... args) {
    FlightRecorder.getFlightRecorder();
    JVM jvm = JVM.getJVM();

    long id10 = getStackIdOfDepth(10);
    assertValid(id10);

    long id5 = getStackIdOfDepth(5);
    assertValid(id5);

    Asserts.assertNotEquals(id5, id10, "Different stack depth must return different stack trace ids");

    assertMaxSkip(jvm);
}