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 Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20 * or visit www.oracle.com if you need additional information or have any
21 * 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 */
31 import java.lang.management.*;
32
33 public 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 }
|
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 Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20 * or visit www.oracle.com if you need additional information or have any
21 * questions.
22 */
23
24 /*
25 * @test
26 * @bug 5011189 8004928
27 * @summary Unit test for java.lang.management.CompilationMXBean
28 *
29 * @run main/othervm -Xcomp -Xbatch Basic
30 */
31 import java.lang.management.*;
32
33 public 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.nio.channels.spi.SelectorProvider.provider();
69
70 time = mb.getTotalCompilationTime();
71 if (time > 0) {
72 printCompilationTime(time);
73 } else {
74 throw new RuntimeException("getTimeCompilionTime returns 0");
75 }
76 }
77
78 static void printCompilationTime(long time) {
79 System.out.println("Total compilation time: " + time + " ms");
80 }
81 }
|