Path: blob/master/test/jdk/java/lang/management/CompilationMXBean/Basic.java
41154 views
/*1* Copyright (c) 2004, 2015, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation.7*8* This code is distributed in the hope that it will be useful, but WITHOUT9* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or10* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License11* version 2 for more details (a copy is included in the LICENSE file that12* accompanied this code).13*14* You should have received a copy of the GNU General Public License version15* 2 along with this work; if not, write to the Free Software Foundation,16* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.17*18* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA19* or visit www.oracle.com if you need additional information or have any20* questions.21*/2223/*24* @test25* @bug 5011189 800492826* @summary Unit test for java.lang.management.CompilationMXBean27*28* @run main/othervm -Xcomp -Xbatch Basic29*/30import java.lang.management.*;3132public class Basic {3334public static void main(String args[]) {35CompilationMXBean mb = ManagementFactory.getCompilationMXBean();36if (mb == null) {37System.out.println("The virtual machine doesn't have a compilation system");38return;39}4041// Exercise getName() method42System.out.println(mb.getName());4344// If compilation time monitoring isn't supported then we are done45if (!mb.isCompilationTimeMonitoringSupported()) {46System.out.println("Compilation time monitoring not supported.");47return;48}4950// Exercise getTotalCompilationTime();51long time;5253// If the compiler has already done some work then we are done54time = mb.getTotalCompilationTime();55if (time > 0) {56printCompilationTime(time);57return;58}5960// Now the hard bit - we do random work on the assumption61// that the compiler will be used.6263System.out.println("Doing random work...");6465java.util.Locale.getAvailableLocales();66java.security.Security.getProviders();67java.nio.channels.spi.SelectorProvider.provider();6869time = mb.getTotalCompilationTime();70if (time > 0) {71printCompilationTime(time);72} else {73throw new RuntimeException("getTimeCompilionTime returns 0");74}75}7677static void printCompilationTime(long time) {78System.out.println("Total compilation time: " + time + " ms");79}80}818283