GetTotalSafepointTime.java revision 180
678N/A/*
678N/A * Copyright 2003-2004 Sun Microsystems, Inc. All Rights Reserved.
678N/A * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
678N/A *
678N/A * This code is free software; you can redistribute it and/or modify it
678N/A * under the terms of the GNU General Public License version 2 only, as
678N/A * published by the Free Software Foundation.
678N/A *
678N/A * This code is distributed in the hope that it will be useful, but WITHOUT
678N/A * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
678N/A * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
678N/A * version 2 for more details (a copy is included in the LICENSE file that
678N/A * accompanied this code).
678N/A *
678N/A * You should have received a copy of the GNU General Public License version
678N/A * 2 along with this work; if not, write to the Free Software Foundation,
678N/A * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
678N/A *
678N/A * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
678N/A * CA 95054 USA or visit www.sun.com if you need additional information or
678N/A * have any questions.
678N/A */
678N/A
678N/A/*
678N/A * @test
678N/A * @bug 4858522
678N/A * @summary Basic unit test of HotspotRuntimeMBean.getTotalSafepointTime()
678N/A * @author Steve Bohne
678N/A */
678N/A
678N/A/*
678N/A * This test is just a sanity check and does not check for the correct value.
678N/A */
678N/A
678N/Aimport sun.management.*;
678N/A
678N/Apublic class GetTotalSafepointTime {
678N/A
678N/A private static HotspotRuntimeMBean mbean =
678N/A (HotspotRuntimeMBean)ManagementFactoryHelper.getHotspotRuntimeMBean();
678N/A
678N/A private static final long NUM_THREAD_DUMPS = 100;
678N/A
678N/A // Careful with these values.
678N/A private static final long MIN_VALUE_FOR_PASS = 1;
678N/A private static final long MAX_VALUE_FOR_PASS = Long.MAX_VALUE;
678N/A
678N/A private static boolean trace = false;
678N/A
678N/A public static void main(String args[]) throws Exception {
678N/A if (args.length > 0 && args[0].equals("trace")) {
678N/A trace = true;
678N/A }
678N/A
678N/A // Thread.getAllStackTraces() should cause safepoints.
678N/A // If this test is failing because it doesn't,
678N/A // MIN_VALUE_FOR_PASS should be reset to 0
678N/A for (int i = 0; i < NUM_THREAD_DUMPS; i++) {
678N/A Thread.getAllStackTraces();
678N/A }
678N/A
678N/A long value = mbean.getTotalSafepointTime();
678N/A
678N/A if (trace) {
678N/A System.out.println("Total safepoint time (ms): " + value);
678N/A }
678N/A
678N/A if (value < MIN_VALUE_FOR_PASS || value > MAX_VALUE_FOR_PASS) {
678N/A throw new RuntimeException("Total safepoint time " +
678N/A "illegal value: " + value + " ms " +
678N/A "(MIN = " + MIN_VALUE_FOR_PASS + "; " +
678N/A "MAX = " + MAX_VALUE_FOR_PASS + ")");
678N/A }
678N/A
678N/A for (int i = 0; i < 2 * NUM_THREAD_DUMPS; i++) {
678N/A Thread.getAllStackTraces();
678N/A }
678N/A long value2 = mbean.getTotalSafepointTime();
678N/A
678N/A if (trace) {
678N/A System.out.println("Total safepoint time2 (ms): " + value2);
678N/A }
678N/A
678N/A if (value2 <= value) {
678N/A throw new RuntimeException("Total safepoint time " +
678N/A "did not increase " +
678N/A "(value = " + value + "; " +
678N/A "value2 = " + value2 + ")");
678N/A }
678N/A
678N/A System.out.println("Test passed.");
678N/A }
678N/A}
678N/A