author | phh |
Sat, 30 Nov 2019 14:33:05 -0800 | |
changeset 59330 | 5b96c12f909d |
parent 49958 | cc29d7717e3a |
permissions | -rw-r--r-- |
49958
cc29d7717e3a
8199375: [TESTBUG] Open source vm testbase monitoring tests
iignatyev
parents:
diff
changeset
|
1 |
/* |
cc29d7717e3a
8199375: [TESTBUG] Open source vm testbase monitoring tests
iignatyev
parents:
diff
changeset
|
2 |
* Copyright (c) 2007, 2018, Oracle and/or its affiliates. All rights reserved. |
cc29d7717e3a
8199375: [TESTBUG] Open source vm testbase monitoring tests
iignatyev
parents:
diff
changeset
|
3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
cc29d7717e3a
8199375: [TESTBUG] Open source vm testbase monitoring tests
iignatyev
parents:
diff
changeset
|
4 |
* |
cc29d7717e3a
8199375: [TESTBUG] Open source vm testbase monitoring tests
iignatyev
parents:
diff
changeset
|
5 |
* This code is free software; you can redistribute it and/or modify it |
cc29d7717e3a
8199375: [TESTBUG] Open source vm testbase monitoring tests
iignatyev
parents:
diff
changeset
|
6 |
* under the terms of the GNU General Public License version 2 only, as |
cc29d7717e3a
8199375: [TESTBUG] Open source vm testbase monitoring tests
iignatyev
parents:
diff
changeset
|
7 |
* published by the Free Software Foundation. |
cc29d7717e3a
8199375: [TESTBUG] Open source vm testbase monitoring tests
iignatyev
parents:
diff
changeset
|
8 |
* |
cc29d7717e3a
8199375: [TESTBUG] Open source vm testbase monitoring tests
iignatyev
parents:
diff
changeset
|
9 |
* This code is distributed in the hope that it will be useful, but WITHOUT |
cc29d7717e3a
8199375: [TESTBUG] Open source vm testbase monitoring tests
iignatyev
parents:
diff
changeset
|
10 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
cc29d7717e3a
8199375: [TESTBUG] Open source vm testbase monitoring tests
iignatyev
parents:
diff
changeset
|
11 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
cc29d7717e3a
8199375: [TESTBUG] Open source vm testbase monitoring tests
iignatyev
parents:
diff
changeset
|
12 |
* version 2 for more details (a copy is included in the LICENSE file that |
cc29d7717e3a
8199375: [TESTBUG] Open source vm testbase monitoring tests
iignatyev
parents:
diff
changeset
|
13 |
* accompanied this code). |
cc29d7717e3a
8199375: [TESTBUG] Open source vm testbase monitoring tests
iignatyev
parents:
diff
changeset
|
14 |
* |
cc29d7717e3a
8199375: [TESTBUG] Open source vm testbase monitoring tests
iignatyev
parents:
diff
changeset
|
15 |
* You should have received a copy of the GNU General Public License version |
cc29d7717e3a
8199375: [TESTBUG] Open source vm testbase monitoring tests
iignatyev
parents:
diff
changeset
|
16 |
* 2 along with this work; if not, write to the Free Software Foundation, |
cc29d7717e3a
8199375: [TESTBUG] Open source vm testbase monitoring tests
iignatyev
parents:
diff
changeset
|
17 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
cc29d7717e3a
8199375: [TESTBUG] Open source vm testbase monitoring tests
iignatyev
parents:
diff
changeset
|
18 |
* |
cc29d7717e3a
8199375: [TESTBUG] Open source vm testbase monitoring tests
iignatyev
parents:
diff
changeset
|
19 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
cc29d7717e3a
8199375: [TESTBUG] Open source vm testbase monitoring tests
iignatyev
parents:
diff
changeset
|
20 |
* or visit www.oracle.com if you need additional information or have any |
cc29d7717e3a
8199375: [TESTBUG] Open source vm testbase monitoring tests
iignatyev
parents:
diff
changeset
|
21 |
* questions. |
cc29d7717e3a
8199375: [TESTBUG] Open source vm testbase monitoring tests
iignatyev
parents:
diff
changeset
|
22 |
*/ |
cc29d7717e3a
8199375: [TESTBUG] Open source vm testbase monitoring tests
iignatyev
parents:
diff
changeset
|
23 |
|
cc29d7717e3a
8199375: [TESTBUG] Open source vm testbase monitoring tests
iignatyev
parents:
diff
changeset
|
24 |
|
cc29d7717e3a
8199375: [TESTBUG] Open source vm testbase monitoring tests
iignatyev
parents:
diff
changeset
|
25 |
|
cc29d7717e3a
8199375: [TESTBUG] Open source vm testbase monitoring tests
iignatyev
parents:
diff
changeset
|
26 |
/* |
cc29d7717e3a
8199375: [TESTBUG] Open source vm testbase monitoring tests
iignatyev
parents:
diff
changeset
|
27 |
* @test |
cc29d7717e3a
8199375: [TESTBUG] Open source vm testbase monitoring tests
iignatyev
parents:
diff
changeset
|
28 |
* |
cc29d7717e3a
8199375: [TESTBUG] Open source vm testbase monitoring tests
iignatyev
parents:
diff
changeset
|
29 |
* @summary converted from VM Testbase nsk/monitoring/CompilationMXBean/comptimemon001. |
cc29d7717e3a
8199375: [TESTBUG] Open source vm testbase monitoring tests
iignatyev
parents:
diff
changeset
|
30 |
* VM Testbase keywords: [quick, monitoring] |
cc29d7717e3a
8199375: [TESTBUG] Open source vm testbase monitoring tests
iignatyev
parents:
diff
changeset
|
31 |
* VM Testbase readme: |
cc29d7717e3a
8199375: [TESTBUG] Open source vm testbase monitoring tests
iignatyev
parents:
diff
changeset
|
32 |
* DESCRIPTION |
cc29d7717e3a
8199375: [TESTBUG] Open source vm testbase monitoring tests
iignatyev
parents:
diff
changeset
|
33 |
* The test checks that |
cc29d7717e3a
8199375: [TESTBUG] Open source vm testbase monitoring tests
iignatyev
parents:
diff
changeset
|
34 |
* CompilationMBean.isCompilationTimeMonitoringSupported() |
cc29d7717e3a
8199375: [TESTBUG] Open source vm testbase monitoring tests
iignatyev
parents:
diff
changeset
|
35 |
* method returns true. The test performs directly access to management |
cc29d7717e3a
8199375: [TESTBUG] Open source vm testbase monitoring tests
iignatyev
parents:
diff
changeset
|
36 |
* metrics within the same JVM. |
cc29d7717e3a
8199375: [TESTBUG] Open source vm testbase monitoring tests
iignatyev
parents:
diff
changeset
|
37 |
* Note, that the test is correct ONLY against Sun's Hotspot VM. This |
cc29d7717e3a
8199375: [TESTBUG] Open source vm testbase monitoring tests
iignatyev
parents:
diff
changeset
|
38 |
* feature is optional and the method may return either true, or false. |
cc29d7717e3a
8199375: [TESTBUG] Open source vm testbase monitoring tests
iignatyev
parents:
diff
changeset
|
39 |
* However, Sun's implementation must always return true. |
cc29d7717e3a
8199375: [TESTBUG] Open source vm testbase monitoring tests
iignatyev
parents:
diff
changeset
|
40 |
* The test passes, if the JVM has no compilation system, for example the |
cc29d7717e3a
8199375: [TESTBUG] Open source vm testbase monitoring tests
iignatyev
parents:
diff
changeset
|
41 |
* test is invoked with -Xint option. |
cc29d7717e3a
8199375: [TESTBUG] Open source vm testbase monitoring tests
iignatyev
parents:
diff
changeset
|
42 |
* COMMENT |
cc29d7717e3a
8199375: [TESTBUG] Open source vm testbase monitoring tests
iignatyev
parents:
diff
changeset
|
43 |
* Fixed the bug: |
cc29d7717e3a
8199375: [TESTBUG] Open source vm testbase monitoring tests
iignatyev
parents:
diff
changeset
|
44 |
* 4953476 TEST_BUG: The spec is updated accoring to 4944573 and 4947536 |
cc29d7717e3a
8199375: [TESTBUG] Open source vm testbase monitoring tests
iignatyev
parents:
diff
changeset
|
45 |
* |
cc29d7717e3a
8199375: [TESTBUG] Open source vm testbase monitoring tests
iignatyev
parents:
diff
changeset
|
46 |
* @library /vmTestbase |
cc29d7717e3a
8199375: [TESTBUG] Open source vm testbase monitoring tests
iignatyev
parents:
diff
changeset
|
47 |
* /test/lib |
cc29d7717e3a
8199375: [TESTBUG] Open source vm testbase monitoring tests
iignatyev
parents:
diff
changeset
|
48 |
* @run driver jdk.test.lib.FileInstaller . . |
cc29d7717e3a
8199375: [TESTBUG] Open source vm testbase monitoring tests
iignatyev
parents:
diff
changeset
|
49 |
* @run main/othervm/timeout=300 nsk.monitoring.CompilationMXBean.comptimemon001.comptimemon001 |
cc29d7717e3a
8199375: [TESTBUG] Open source vm testbase monitoring tests
iignatyev
parents:
diff
changeset
|
50 |
*/ |
cc29d7717e3a
8199375: [TESTBUG] Open source vm testbase monitoring tests
iignatyev
parents:
diff
changeset
|
51 |
|
cc29d7717e3a
8199375: [TESTBUG] Open source vm testbase monitoring tests
iignatyev
parents:
diff
changeset
|
52 |
package nsk.monitoring.CompilationMXBean.comptimemon001; |
cc29d7717e3a
8199375: [TESTBUG] Open source vm testbase monitoring tests
iignatyev
parents:
diff
changeset
|
53 |
|
cc29d7717e3a
8199375: [TESTBUG] Open source vm testbase monitoring tests
iignatyev
parents:
diff
changeset
|
54 |
import java.io.*; |
cc29d7717e3a
8199375: [TESTBUG] Open source vm testbase monitoring tests
iignatyev
parents:
diff
changeset
|
55 |
import nsk.share.test.*; |
cc29d7717e3a
8199375: [TESTBUG] Open source vm testbase monitoring tests
iignatyev
parents:
diff
changeset
|
56 |
import nsk.share.TestFailure; |
cc29d7717e3a
8199375: [TESTBUG] Open source vm testbase monitoring tests
iignatyev
parents:
diff
changeset
|
57 |
import nsk.monitoring.share.*; |
cc29d7717e3a
8199375: [TESTBUG] Open source vm testbase monitoring tests
iignatyev
parents:
diff
changeset
|
58 |
import java.lang.management.*; |
cc29d7717e3a
8199375: [TESTBUG] Open source vm testbase monitoring tests
iignatyev
parents:
diff
changeset
|
59 |
|
cc29d7717e3a
8199375: [TESTBUG] Open source vm testbase monitoring tests
iignatyev
parents:
diff
changeset
|
60 |
public class comptimemon001 extends MonitoringTestBase implements Initializable { |
cc29d7717e3a
8199375: [TESTBUG] Open source vm testbase monitoring tests
iignatyev
parents:
diff
changeset
|
61 |
private CompilationMXBean compilation; |
cc29d7717e3a
8199375: [TESTBUG] Open source vm testbase monitoring tests
iignatyev
parents:
diff
changeset
|
62 |
private int iterations = 30; |
cc29d7717e3a
8199375: [TESTBUG] Open source vm testbase monitoring tests
iignatyev
parents:
diff
changeset
|
63 |
|
cc29d7717e3a
8199375: [TESTBUG] Open source vm testbase monitoring tests
iignatyev
parents:
diff
changeset
|
64 |
public void initialize() { |
cc29d7717e3a
8199375: [TESTBUG] Open source vm testbase monitoring tests
iignatyev
parents:
diff
changeset
|
65 |
if (monitoringFactory.hasCompilationMXBean()) |
cc29d7717e3a
8199375: [TESTBUG] Open source vm testbase monitoring tests
iignatyev
parents:
diff
changeset
|
66 |
compilation = monitoringFactory.getCompilationMXBean(); |
cc29d7717e3a
8199375: [TESTBUG] Open source vm testbase monitoring tests
iignatyev
parents:
diff
changeset
|
67 |
} |
cc29d7717e3a
8199375: [TESTBUG] Open source vm testbase monitoring tests
iignatyev
parents:
diff
changeset
|
68 |
|
cc29d7717e3a
8199375: [TESTBUG] Open source vm testbase monitoring tests
iignatyev
parents:
diff
changeset
|
69 |
public boolean testCompilationTimeMonitoringSupported() { |
cc29d7717e3a
8199375: [TESTBUG] Open source vm testbase monitoring tests
iignatyev
parents:
diff
changeset
|
70 |
if (compilation == null) { |
cc29d7717e3a
8199375: [TESTBUG] Open source vm testbase monitoring tests
iignatyev
parents:
diff
changeset
|
71 |
// The JVM has no compilation system, for example the test is |
cc29d7717e3a
8199375: [TESTBUG] Open source vm testbase monitoring tests
iignatyev
parents:
diff
changeset
|
72 |
// invoked with -Xint option |
cc29d7717e3a
8199375: [TESTBUG] Open source vm testbase monitoring tests
iignatyev
parents:
diff
changeset
|
73 |
log.info("The JVM has no compilation system."); |
cc29d7717e3a
8199375: [TESTBUG] Open source vm testbase monitoring tests
iignatyev
parents:
diff
changeset
|
74 |
return false; |
cc29d7717e3a
8199375: [TESTBUG] Open source vm testbase monitoring tests
iignatyev
parents:
diff
changeset
|
75 |
} else if (!compilation.isCompilationTimeMonitoringSupported()) { |
cc29d7717e3a
8199375: [TESTBUG] Open source vm testbase monitoring tests
iignatyev
parents:
diff
changeset
|
76 |
// Check the method is... for the specified way of access to MBeans |
cc29d7717e3a
8199375: [TESTBUG] Open source vm testbase monitoring tests
iignatyev
parents:
diff
changeset
|
77 |
log.error("Monitoring of compilation time is not supported.\n"); |
cc29d7717e3a
8199375: [TESTBUG] Open source vm testbase monitoring tests
iignatyev
parents:
diff
changeset
|
78 |
setFailed(true); |
cc29d7717e3a
8199375: [TESTBUG] Open source vm testbase monitoring tests
iignatyev
parents:
diff
changeset
|
79 |
return false; |
cc29d7717e3a
8199375: [TESTBUG] Open source vm testbase monitoring tests
iignatyev
parents:
diff
changeset
|
80 |
} |
cc29d7717e3a
8199375: [TESTBUG] Open source vm testbase monitoring tests
iignatyev
parents:
diff
changeset
|
81 |
return true; |
cc29d7717e3a
8199375: [TESTBUG] Open source vm testbase monitoring tests
iignatyev
parents:
diff
changeset
|
82 |
} |
cc29d7717e3a
8199375: [TESTBUG] Open source vm testbase monitoring tests
iignatyev
parents:
diff
changeset
|
83 |
|
cc29d7717e3a
8199375: [TESTBUG] Open source vm testbase monitoring tests
iignatyev
parents:
diff
changeset
|
84 |
private void testCompilationTimeOne() { |
cc29d7717e3a
8199375: [TESTBUG] Open source vm testbase monitoring tests
iignatyev
parents:
diff
changeset
|
85 |
long sleepTime = LocalRandom.randomPauseTime(); |
cc29d7717e3a
8199375: [TESTBUG] Open source vm testbase monitoring tests
iignatyev
parents:
diff
changeset
|
86 |
long startTime = compilation.getTotalCompilationTime(); |
cc29d7717e3a
8199375: [TESTBUG] Open source vm testbase monitoring tests
iignatyev
parents:
diff
changeset
|
87 |
if (startTime < 0) |
cc29d7717e3a
8199375: [TESTBUG] Open source vm testbase monitoring tests
iignatyev
parents:
diff
changeset
|
88 |
throw new TestFailure("getTotalCompilationTime < 0: " + startTime); |
cc29d7717e3a
8199375: [TESTBUG] Open source vm testbase monitoring tests
iignatyev
parents:
diff
changeset
|
89 |
try { |
cc29d7717e3a
8199375: [TESTBUG] Open source vm testbase monitoring tests
iignatyev
parents:
diff
changeset
|
90 |
Thread.sleep(sleepTime); |
cc29d7717e3a
8199375: [TESTBUG] Open source vm testbase monitoring tests
iignatyev
parents:
diff
changeset
|
91 |
} catch (InterruptedException e) { |
cc29d7717e3a
8199375: [TESTBUG] Open source vm testbase monitoring tests
iignatyev
parents:
diff
changeset
|
92 |
throw new TestFailure("Sleep was interrupted."); |
cc29d7717e3a
8199375: [TESTBUG] Open source vm testbase monitoring tests
iignatyev
parents:
diff
changeset
|
93 |
} |
cc29d7717e3a
8199375: [TESTBUG] Open source vm testbase monitoring tests
iignatyev
parents:
diff
changeset
|
94 |
long finishTime = compilation.getTotalCompilationTime(); |
cc29d7717e3a
8199375: [TESTBUG] Open source vm testbase monitoring tests
iignatyev
parents:
diff
changeset
|
95 |
if (finishTime < 0) |
cc29d7717e3a
8199375: [TESTBUG] Open source vm testbase monitoring tests
iignatyev
parents:
diff
changeset
|
96 |
throw new TestFailure("getTotalCompilationTime < 0: " + finishTime); |
cc29d7717e3a
8199375: [TESTBUG] Open source vm testbase monitoring tests
iignatyev
parents:
diff
changeset
|
97 |
if (finishTime < startTime) |
cc29d7717e3a
8199375: [TESTBUG] Open source vm testbase monitoring tests
iignatyev
parents:
diff
changeset
|
98 |
throw new TestFailure("getTotalCompilationTime before sleep: " + startTime |
cc29d7717e3a
8199375: [TESTBUG] Open source vm testbase monitoring tests
iignatyev
parents:
diff
changeset
|
99 |
+ " > getTotalCompilationTime after sleep: " + finishTime); |
cc29d7717e3a
8199375: [TESTBUG] Open source vm testbase monitoring tests
iignatyev
parents:
diff
changeset
|
100 |
} |
cc29d7717e3a
8199375: [TESTBUG] Open source vm testbase monitoring tests
iignatyev
parents:
diff
changeset
|
101 |
|
cc29d7717e3a
8199375: [TESTBUG] Open source vm testbase monitoring tests
iignatyev
parents:
diff
changeset
|
102 |
public void testCompilationTime() { |
cc29d7717e3a
8199375: [TESTBUG] Open source vm testbase monitoring tests
iignatyev
parents:
diff
changeset
|
103 |
for (int i = 0; i < iterations; ++i) |
cc29d7717e3a
8199375: [TESTBUG] Open source vm testbase monitoring tests
iignatyev
parents:
diff
changeset
|
104 |
testCompilationTimeOne(); |
cc29d7717e3a
8199375: [TESTBUG] Open source vm testbase monitoring tests
iignatyev
parents:
diff
changeset
|
105 |
} |
cc29d7717e3a
8199375: [TESTBUG] Open source vm testbase monitoring tests
iignatyev
parents:
diff
changeset
|
106 |
|
cc29d7717e3a
8199375: [TESTBUG] Open source vm testbase monitoring tests
iignatyev
parents:
diff
changeset
|
107 |
public void run() { |
cc29d7717e3a
8199375: [TESTBUG] Open source vm testbase monitoring tests
iignatyev
parents:
diff
changeset
|
108 |
if (!testCompilationTimeMonitoringSupported()) |
cc29d7717e3a
8199375: [TESTBUG] Open source vm testbase monitoring tests
iignatyev
parents:
diff
changeset
|
109 |
return; |
cc29d7717e3a
8199375: [TESTBUG] Open source vm testbase monitoring tests
iignatyev
parents:
diff
changeset
|
110 |
testCompilationTime(); |
cc29d7717e3a
8199375: [TESTBUG] Open source vm testbase monitoring tests
iignatyev
parents:
diff
changeset
|
111 |
} |
cc29d7717e3a
8199375: [TESTBUG] Open source vm testbase monitoring tests
iignatyev
parents:
diff
changeset
|
112 |
|
cc29d7717e3a
8199375: [TESTBUG] Open source vm testbase monitoring tests
iignatyev
parents:
diff
changeset
|
113 |
public static void main(String[] args) { |
cc29d7717e3a
8199375: [TESTBUG] Open source vm testbase monitoring tests
iignatyev
parents:
diff
changeset
|
114 |
Monitoring.runTest(new comptimemon001(), args); |
cc29d7717e3a
8199375: [TESTBUG] Open source vm testbase monitoring tests
iignatyev
parents:
diff
changeset
|
115 |
} |
cc29d7717e3a
8199375: [TESTBUG] Open source vm testbase monitoring tests
iignatyev
parents:
diff
changeset
|
116 |
} |