< prev index next >

test/jdk/sun/management/HotspotRuntimeMBean/GetSafepointSyncTime.java

Print this page

        

*** 1,7 **** /* ! * Copyright (c) 2003, 2015, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it * under the terms of the GNU General Public License version 2 only, as * published by the Free Software Foundation. --- 1,7 ---- /* ! * Copyright (c) 2003, 2018, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it * under the terms of the GNU General Public License version 2 only, as * published by the Free Software Foundation.
*** 21,31 **** * questions. */ /* * @test ! * @bug 4858522 * @summary Basic unit test of HotspotRuntimeMBean.getSafepointSyncTime() * @author Steve Bohne * * @run main/othervm -XX:+UsePerfData GetSafepointSyncTime */ --- 21,31 ---- * questions. */ /* * @test ! * @bug 4858522 8174734 * @summary Basic unit test of HotspotRuntimeMBean.getSafepointSyncTime() * @author Steve Bohne * * @run main/othervm -XX:+UsePerfData GetSafepointSyncTime */
*** 41,93 **** private static HotspotRuntimeMBean mbean = (HotspotRuntimeMBean)ManagementFactoryHelper.getHotspotRuntimeMBean(); private static final long NUM_THREAD_DUMPS = 300; ! // Careful with these values. ! private static final long MIN_VALUE_FOR_PASS = 1; ! private static final long MAX_VALUE_FOR_PASS = Long.MAX_VALUE; public static void main(String args[]) throws Exception { long count = mbean.getSafepointCount(); ! long value = mbean.getSafepointSyncTime(); - // Thread.getAllStackTraces() should cause safepoints. - // If this test is failing because it doesn't, - // MIN_VALUE_FOR_PASS should be reset to 0 for (int i = 0; i < NUM_THREAD_DUMPS; i++) { Thread.getAllStackTraces(); } long count1 = mbean.getSafepointCount(); ! long value1 = mbean.getSafepointSyncTime(); ! System.out.format("Safepoint count=%d (diff=%d), sync time=%d ms (diff=%d)%n", ! count1, count1-count, value1, value1-value); ! if (value1 < MIN_VALUE_FOR_PASS || value1 > MAX_VALUE_FOR_PASS) { ! throw new RuntimeException("Safepoint sync time " + ! "illegal value: " + value1 + " ms " + ! "(MIN = " + MIN_VALUE_FOR_PASS + "; " + ! "MAX = " + MAX_VALUE_FOR_PASS + ")"); ! } for (int i = 0; i < NUM_THREAD_DUMPS; i++) { Thread.getAllStackTraces(); } long count2 = mbean.getSafepointCount(); ! long value2 = mbean.getSafepointSyncTime(); ! ! System.out.format("Safepoint count=%d (diff=%d), sync time=%d ms (diff=%d)%n", ! count2, count2-count1, value2, value2-value1); ! if (value2 <= value1) { ! throw new RuntimeException("Safepoint sync time " + ! "did not increase " + ! "(value1 = " + value1 + "; " + ! "value2 = " + value2 + ")"); ! } System.out.println("Test passed."); } } --- 41,114 ---- private static HotspotRuntimeMBean mbean = (HotspotRuntimeMBean)ManagementFactoryHelper.getHotspotRuntimeMBean(); private static final long NUM_THREAD_DUMPS = 300; ! static void checkPositive(long value, String label) { ! if (value < 0) ! throw new RuntimeException(label + " had a negative value of " ! + value); ! } ! ! static void validate(long count1, long count2, long time1, long time2, ! String label) { ! checkPositive(count1, label + ":count1"); ! checkPositive(count2, label + ":count2"); ! checkPositive(time1, label + ":time1"); ! checkPositive(time2, label + ":time2"); ! ! long countDiff = count2 - count1; ! long timeDiff = time2 - time1; ! ! if (countDiff < NUM_THREAD_DUMPS) { ! throw new RuntimeException(label + ! ": Expected at least " + NUM_THREAD_DUMPS + ! "safepoints but only got " + countDiff); ! } ! ! // getSafepointSyncTime is the accumulated time spent getting to a ! // safepoint, so each safepoint will add a little to this, but the ! // resolution is only milliseconds so we may not see it. ! if (timeDiff < 0) { ! throw new RuntimeException(label + ": Safepoint sync time " + ! "decreased unexpectedly " + ! "(time1 = " + time1 + "; " + ! "time2 = " + time2 + ")"); ! } ! ! System.out.format("%s: Safepoint count=%d (diff=%d), sync time=%d ms (diff=%d)%n", ! label, count2, countDiff, time2, timeDiff); ! ! } public static void main(String args[]) throws Exception { long count = mbean.getSafepointCount(); ! long time = mbean.getSafepointSyncTime(); ! ! checkPositive(count, "count"); ! checkPositive(time, "time"); ! ! // Thread.getAllStackTraces() should cause a safepoint. for (int i = 0; i < NUM_THREAD_DUMPS; i++) { Thread.getAllStackTraces(); } long count1 = mbean.getSafepointCount(); ! long time1 = mbean.getSafepointSyncTime(); ! validate(count, count1, time, time1, "Pass 1"); ! // repeat the experiment for (int i = 0; i < NUM_THREAD_DUMPS; i++) { Thread.getAllStackTraces(); } long count2 = mbean.getSafepointCount(); ! long time2 = mbean.getSafepointSyncTime(); ! validate(count1, count2, time1, time2, "Pass 2"); System.out.println("Test passed."); } }
< prev index next >