jdk/test/sun/management/HotspotRuntimeMBean/GetSafepointSyncTime.java
author ssadetsky
Mon, 24 Apr 2017 07:10:37 -0700
changeset 45013 03094cd3458e
parent 44423 306c020eb154
permissions -rw-r--r--
8178905: Undecorated frame is not painted on OEL7(Gnome3). Reviewed-by: prr, serb
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
30376
2ccf2cf7ea48 8078896: Add @modules as needed to the jdk_svc tests
ykantser
parents: 26195
diff changeset
     2
 * Copyright (c) 2003, 2015, Oracle and/or its affiliates. All rights reserved.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
90ce3da70b43 Initial load
duke
parents:
diff changeset
     4
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
90ce3da70b43 Initial load
duke
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
90ce3da70b43 Initial load
duke
parents:
diff changeset
     7
 * published by the Free Software Foundation.
90ce3da70b43 Initial load
duke
parents:
diff changeset
     8
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
90ce3da70b43 Initial load
duke
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
90ce3da70b43 Initial load
duke
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
90ce3da70b43 Initial load
duke
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
90ce3da70b43 Initial load
duke
parents:
diff changeset
    13
 * accompanied this code).
90ce3da70b43 Initial load
duke
parents:
diff changeset
    14
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
90ce3da70b43 Initial load
duke
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    18
 *
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 715
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 715
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 715
diff changeset
    21
 * questions.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    22
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    23
90ce3da70b43 Initial load
duke
parents:
diff changeset
    24
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
    25
 * @test
90ce3da70b43 Initial load
duke
parents:
diff changeset
    26
 * @bug     4858522
90ce3da70b43 Initial load
duke
parents:
diff changeset
    27
 * @summary Basic unit test of HotspotRuntimeMBean.getSafepointSyncTime()
90ce3da70b43 Initial load
duke
parents:
diff changeset
    28
 * @author  Steve Bohne
44423
306c020eb154 8176176: fix @modules in jdk_svc tests
iignatyev
parents: 30376
diff changeset
    29
 *
26195
64b54ed39429 8040692: [TESTBUG] sun/management/jmxremote/bootstrap/JvmstatCountersTest.java requires -XX:+UsePerfData option to pass on embedded platforms
jbachorik
parents: 23010
diff changeset
    30
 * @run main/othervm -XX:+UsePerfData GetSafepointSyncTime
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
 * This test is just a sanity check and does not check for the correct value.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
import sun.management.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
public class GetSafepointSyncTime {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
    private static HotspotRuntimeMBean mbean =
403
dc6f4ca08b81 6687508: Update test/sun/management jtreg tests due to sun.management.ManagementFactory class rename
mchung
parents: 2
diff changeset
    42
        (HotspotRuntimeMBean)ManagementFactoryHelper.getHotspotRuntimeMBean();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
    private static final long NUM_THREAD_DUMPS = 300;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
    // Careful with these values.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
    private static final long MIN_VALUE_FOR_PASS = 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
    private static final long MAX_VALUE_FOR_PASS = Long.MAX_VALUE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
    public static void main(String args[]) throws Exception {
21829
a3cac8b5ca51 8028647: Add instrumentation in GetSafepointSyncTime.java and remove it from ProblemList.txt
mchung
parents: 5506
diff changeset
    51
        long count = mbean.getSafepointCount();
a3cac8b5ca51 8028647: Add instrumentation in GetSafepointSyncTime.java and remove it from ProblemList.txt
mchung
parents: 5506
diff changeset
    52
        long value = mbean.getSafepointSyncTime();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
        // Thread.getAllStackTraces() should cause safepoints.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
        // If this test is failing because it doesn't,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
        // MIN_VALUE_FOR_PASS should be reset to 0
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
        for (int i = 0; i < NUM_THREAD_DUMPS; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
            Thread.getAllStackTraces();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
21829
a3cac8b5ca51 8028647: Add instrumentation in GetSafepointSyncTime.java and remove it from ProblemList.txt
mchung
parents: 5506
diff changeset
    61
        long count1 = mbean.getSafepointCount();
a3cac8b5ca51 8028647: Add instrumentation in GetSafepointSyncTime.java and remove it from ProblemList.txt
mchung
parents: 5506
diff changeset
    62
        long value1 = mbean.getSafepointSyncTime();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
21829
a3cac8b5ca51 8028647: Add instrumentation in GetSafepointSyncTime.java and remove it from ProblemList.txt
mchung
parents: 5506
diff changeset
    64
        System.out.format("Safepoint count=%d (diff=%d), sync time=%d ms (diff=%d)%n",
a3cac8b5ca51 8028647: Add instrumentation in GetSafepointSyncTime.java and remove it from ProblemList.txt
mchung
parents: 5506
diff changeset
    65
                          count1, count1-count, value1, value1-value);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
21829
a3cac8b5ca51 8028647: Add instrumentation in GetSafepointSyncTime.java and remove it from ProblemList.txt
mchung
parents: 5506
diff changeset
    67
        if (value1 < MIN_VALUE_FOR_PASS || value1 > MAX_VALUE_FOR_PASS) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
            throw new RuntimeException("Safepoint sync time " +
21829
a3cac8b5ca51 8028647: Add instrumentation in GetSafepointSyncTime.java and remove it from ProblemList.txt
mchung
parents: 5506
diff changeset
    69
                                       "illegal value: " + value1 + " ms " +
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
                                       "(MIN = " + MIN_VALUE_FOR_PASS + "; " +
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
                                       "MAX = " + MAX_VALUE_FOR_PASS + ")");
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
        for (int i = 0; i < NUM_THREAD_DUMPS; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
            Thread.getAllStackTraces();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
21829
a3cac8b5ca51 8028647: Add instrumentation in GetSafepointSyncTime.java and remove it from ProblemList.txt
mchung
parents: 5506
diff changeset
    78
        long count2 = mbean.getSafepointCount();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
        long value2 = mbean.getSafepointSyncTime();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
21829
a3cac8b5ca51 8028647: Add instrumentation in GetSafepointSyncTime.java and remove it from ProblemList.txt
mchung
parents: 5506
diff changeset
    81
        System.out.format("Safepoint count=%d (diff=%d), sync time=%d ms (diff=%d)%n",
a3cac8b5ca51 8028647: Add instrumentation in GetSafepointSyncTime.java and remove it from ProblemList.txt
mchung
parents: 5506
diff changeset
    82
                          count2, count2-count1, value2, value2-value1);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
21829
a3cac8b5ca51 8028647: Add instrumentation in GetSafepointSyncTime.java and remove it from ProblemList.txt
mchung
parents: 5506
diff changeset
    84
        if (value2 <= value1) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
            throw new RuntimeException("Safepoint sync time " +
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
                                       "did not increase " +
21829
a3cac8b5ca51 8028647: Add instrumentation in GetSafepointSyncTime.java and remove it from ProblemList.txt
mchung
parents: 5506
diff changeset
    87
                                       "(value1 = " + value1 + "; " +
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
                                       "value2 = " + value2 + ")");
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
        System.out.println("Test passed.");
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
}