blob: d4d6d477560684b0e4fac44033fda90d24740b4f [file] [log] [blame]
J. Duke319a3b92007-12-01 00:00:00 +00001/*
2 * Copyright 2004 Sun Microsystems, Inc. All Rights Reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * This code is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation.
8 *
9 * This code is distributed in the hope that it will be useful, but WITHOUT
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
12 * version 2 for more details (a copy is included in the LICENSE file that
13 * accompanied this code).
14 *
15 * You should have received a copy of the GNU General Public License version
16 * 2 along with this work; if not, write to the Free Software Foundation,
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18 *
19 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
20 * CA 95054 USA or visit www.sun.com if you need additional information or
21 * have any questions.
22 */
23
24/*
25 * @test
26 * @bug 5011189
27 * @summary Unit test for java.lang.management.CompilationMXBean
28 *
29 * @run main/othervm -Xcomp -Xbatch -Djava.awt.headless=true Basic
30 */
31import java.lang.management.*;
32
33public class Basic {
34
35 public static void main(String args[]) {
36 CompilationMXBean mb = ManagementFactory.getCompilationMXBean();
37 if (mb == null) {
38 System.out.println("The virtual machine doesn't have a compilation system");
39 return;
40 }
41
42 // Exercise getName() method
43 System.out.println(mb.getName());
44
45 // If compilation time monitoring isn't supported then we are done
46 if (!mb.isCompilationTimeMonitoringSupported()) {
47 System.out.println("Compilation time monitoring not supported.");
48 return;
49 }
50
51 // Exercise getTotalCompilationTime();
52 long time;
53
54 // If the compiler has already done some work then we are done
55 time = mb.getTotalCompilationTime();
56 if (time > 0) {
57 printCompilationTime(time);
58 return;
59 }
60
61 // Now the hard bit - we do random work on the assumption
62 // that the compiler will be used.
63
64 System.out.println("Doing random work...");
65
66 java.util.Locale.getAvailableLocales();
67 java.security.Security.getProviders();
68 java.awt.Toolkit.getDefaultToolkit();
69 javax.swing.UIManager.getInstalledLookAndFeels();
70 java.nio.channels.spi.SelectorProvider.provider();
71
72 time = mb.getTotalCompilationTime();
73 if (time > 0) {
74 printCompilationTime(time);
75 } else {
76 throw new RuntimeException("getTimeCompilionTime returns 0");
77 }
78 }
79
80 static void printCompilationTime(long time) {
81 System.out.println("Total compilation time: " + time + " ms");
82 }
83}