author | fzhinkin |
Fri, 26 Dec 2014 14:33:23 +0300 | |
changeset 28390 | 263a69157012 |
child 30604 | b8d532cb6420 |
permissions | -rw-r--r-- |
28390
263a69157012
8059623: JEP-JDK-8043304: Test task: command line options tests
fzhinkin
parents:
diff
changeset
|
1 |
/* |
263a69157012
8059623: JEP-JDK-8043304: Test task: command line options tests
fzhinkin
parents:
diff
changeset
|
2 |
* Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved. |
263a69157012
8059623: JEP-JDK-8043304: Test task: command line options tests
fzhinkin
parents:
diff
changeset
|
3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
263a69157012
8059623: JEP-JDK-8043304: Test task: command line options tests
fzhinkin
parents:
diff
changeset
|
4 |
* |
263a69157012
8059623: JEP-JDK-8043304: Test task: command line options tests
fzhinkin
parents:
diff
changeset
|
5 |
* This code is free software; you can redistribute it and/or modify it |
263a69157012
8059623: JEP-JDK-8043304: Test task: command line options tests
fzhinkin
parents:
diff
changeset
|
6 |
* under the terms of the GNU General Public License version 2 only, as |
263a69157012
8059623: JEP-JDK-8043304: Test task: command line options tests
fzhinkin
parents:
diff
changeset
|
7 |
* published by the Free Software Foundation. |
263a69157012
8059623: JEP-JDK-8043304: Test task: command line options tests
fzhinkin
parents:
diff
changeset
|
8 |
* |
263a69157012
8059623: JEP-JDK-8043304: Test task: command line options tests
fzhinkin
parents:
diff
changeset
|
9 |
* This code is distributed in the hope that it will be useful, but WITHOUT |
263a69157012
8059623: JEP-JDK-8043304: Test task: command line options tests
fzhinkin
parents:
diff
changeset
|
10 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
263a69157012
8059623: JEP-JDK-8043304: Test task: command line options tests
fzhinkin
parents:
diff
changeset
|
11 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
263a69157012
8059623: JEP-JDK-8043304: Test task: command line options tests
fzhinkin
parents:
diff
changeset
|
12 |
* version 2 for more details (a copy is included in the LICENSE file that |
263a69157012
8059623: JEP-JDK-8043304: Test task: command line options tests
fzhinkin
parents:
diff
changeset
|
13 |
* accompanied this code). |
263a69157012
8059623: JEP-JDK-8043304: Test task: command line options tests
fzhinkin
parents:
diff
changeset
|
14 |
* |
263a69157012
8059623: JEP-JDK-8043304: Test task: command line options tests
fzhinkin
parents:
diff
changeset
|
15 |
* You should have received a copy of the GNU General Public License version |
263a69157012
8059623: JEP-JDK-8043304: Test task: command line options tests
fzhinkin
parents:
diff
changeset
|
16 |
* 2 along with this work; if not, write to the Free Software Foundation, |
263a69157012
8059623: JEP-JDK-8043304: Test task: command line options tests
fzhinkin
parents:
diff
changeset
|
17 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
263a69157012
8059623: JEP-JDK-8043304: Test task: command line options tests
fzhinkin
parents:
diff
changeset
|
18 |
* |
263a69157012
8059623: JEP-JDK-8043304: Test task: command line options tests
fzhinkin
parents:
diff
changeset
|
19 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
263a69157012
8059623: JEP-JDK-8043304: Test task: command line options tests
fzhinkin
parents:
diff
changeset
|
20 |
* or visit www.oracle.com if you need additional information or have any |
263a69157012
8059623: JEP-JDK-8043304: Test task: command line options tests
fzhinkin
parents:
diff
changeset
|
21 |
* questions. |
263a69157012
8059623: JEP-JDK-8043304: Test task: command line options tests
fzhinkin
parents:
diff
changeset
|
22 |
*/ |
263a69157012
8059623: JEP-JDK-8043304: Test task: command line options tests
fzhinkin
parents:
diff
changeset
|
23 |
package codeheapsize; |
263a69157012
8059623: JEP-JDK-8043304: Test task: command line options tests
fzhinkin
parents:
diff
changeset
|
24 |
|
263a69157012
8059623: JEP-JDK-8043304: Test task: command line options tests
fzhinkin
parents:
diff
changeset
|
25 |
import common.CodeCacheCLITestCase; |
263a69157012
8059623: JEP-JDK-8043304: Test task: command line options tests
fzhinkin
parents:
diff
changeset
|
26 |
import common.CodeCacheOptions; |
263a69157012
8059623: JEP-JDK-8043304: Test task: command line options tests
fzhinkin
parents:
diff
changeset
|
27 |
import com.oracle.java.testlibrary.ExitCode; |
263a69157012
8059623: JEP-JDK-8043304: Test task: command line options tests
fzhinkin
parents:
diff
changeset
|
28 |
import com.oracle.java.testlibrary.Utils; |
263a69157012
8059623: JEP-JDK-8043304: Test task: command line options tests
fzhinkin
parents:
diff
changeset
|
29 |
import com.oracle.java.testlibrary.cli.CommandLineOptionTest; |
263a69157012
8059623: JEP-JDK-8043304: Test task: command line options tests
fzhinkin
parents:
diff
changeset
|
30 |
import sun.hotspot.code.BlobType; |
263a69157012
8059623: JEP-JDK-8043304: Test task: command line options tests
fzhinkin
parents:
diff
changeset
|
31 |
import java.util.Random; |
263a69157012
8059623: JEP-JDK-8043304: Test task: command line options tests
fzhinkin
parents:
diff
changeset
|
32 |
|
263a69157012
8059623: JEP-JDK-8043304: Test task: command line options tests
fzhinkin
parents:
diff
changeset
|
33 |
/** |
263a69157012
8059623: JEP-JDK-8043304: Test task: command line options tests
fzhinkin
parents:
diff
changeset
|
34 |
* Test case runner aimed to verify option's consistency. |
263a69157012
8059623: JEP-JDK-8043304: Test task: command line options tests
fzhinkin
parents:
diff
changeset
|
35 |
*/ |
263a69157012
8059623: JEP-JDK-8043304: Test task: command line options tests
fzhinkin
parents:
diff
changeset
|
36 |
public class JVMStartupRunner implements CodeCacheCLITestCase.Runner { |
263a69157012
8059623: JEP-JDK-8043304: Test task: command line options tests
fzhinkin
parents:
diff
changeset
|
37 |
private static final String INCONSISTENT_CH_SIZES_ERROR |
263a69157012
8059623: JEP-JDK-8043304: Test task: command line options tests
fzhinkin
parents:
diff
changeset
|
38 |
= "Invalid code heap sizes.*"; |
263a69157012
8059623: JEP-JDK-8043304: Test task: command line options tests
fzhinkin
parents:
diff
changeset
|
39 |
|
263a69157012
8059623: JEP-JDK-8043304: Test task: command line options tests
fzhinkin
parents:
diff
changeset
|
40 |
@Override |
263a69157012
8059623: JEP-JDK-8043304: Test task: command line options tests
fzhinkin
parents:
diff
changeset
|
41 |
public void run(CodeCacheCLITestCase.Description testCaseDescription, |
263a69157012
8059623: JEP-JDK-8043304: Test task: command line options tests
fzhinkin
parents:
diff
changeset
|
42 |
CodeCacheOptions options) throws Throwable { |
263a69157012
8059623: JEP-JDK-8043304: Test task: command line options tests
fzhinkin
parents:
diff
changeset
|
43 |
// Everything should be fine when |
263a69157012
8059623: JEP-JDK-8043304: Test task: command line options tests
fzhinkin
parents:
diff
changeset
|
44 |
// sum(all code heap sizes) == reserved CC size |
263a69157012
8059623: JEP-JDK-8043304: Test task: command line options tests
fzhinkin
parents:
diff
changeset
|
45 |
CommandLineOptionTest.verifySameJVMStartup(/* expected messages */ null, |
263a69157012
8059623: JEP-JDK-8043304: Test task: command line options tests
fzhinkin
parents:
diff
changeset
|
46 |
new String[]{ INCONSISTENT_CH_SIZES_ERROR }, |
263a69157012
8059623: JEP-JDK-8043304: Test task: command line options tests
fzhinkin
parents:
diff
changeset
|
47 |
"JVM startup should not fail with consistent code heap sizes", |
263a69157012
8059623: JEP-JDK-8043304: Test task: command line options tests
fzhinkin
parents:
diff
changeset
|
48 |
"JVM output should not contain warning about inconsistent code " |
263a69157012
8059623: JEP-JDK-8043304: Test task: command line options tests
fzhinkin
parents:
diff
changeset
|
49 |
+ "heap sizes", ExitCode.OK, options.prepareOptions()); |
263a69157012
8059623: JEP-JDK-8043304: Test task: command line options tests
fzhinkin
parents:
diff
changeset
|
50 |
|
263a69157012
8059623: JEP-JDK-8043304: Test task: command line options tests
fzhinkin
parents:
diff
changeset
|
51 |
verifySingleInconsistentValue(options); |
263a69157012
8059623: JEP-JDK-8043304: Test task: command line options tests
fzhinkin
parents:
diff
changeset
|
52 |
verifyAllInconsistentValues(options); |
263a69157012
8059623: JEP-JDK-8043304: Test task: command line options tests
fzhinkin
parents:
diff
changeset
|
53 |
} |
263a69157012
8059623: JEP-JDK-8043304: Test task: command line options tests
fzhinkin
parents:
diff
changeset
|
54 |
|
263a69157012
8059623: JEP-JDK-8043304: Test task: command line options tests
fzhinkin
parents:
diff
changeset
|
55 |
/** |
263a69157012
8059623: JEP-JDK-8043304: Test task: command line options tests
fzhinkin
parents:
diff
changeset
|
56 |
* Verifies that if at least one of three options will have value, such |
263a69157012
8059623: JEP-JDK-8043304: Test task: command line options tests
fzhinkin
parents:
diff
changeset
|
57 |
* that sum of all three values will be inconsistent, then JVM startup will |
263a69157012
8059623: JEP-JDK-8043304: Test task: command line options tests
fzhinkin
parents:
diff
changeset
|
58 |
* fail. |
263a69157012
8059623: JEP-JDK-8043304: Test task: command line options tests
fzhinkin
parents:
diff
changeset
|
59 |
*/ |
263a69157012
8059623: JEP-JDK-8043304: Test task: command line options tests
fzhinkin
parents:
diff
changeset
|
60 |
private static void verifySingleInconsistentValue(CodeCacheOptions options) |
263a69157012
8059623: JEP-JDK-8043304: Test task: command line options tests
fzhinkin
parents:
diff
changeset
|
61 |
throws Throwable { |
263a69157012
8059623: JEP-JDK-8043304: Test task: command line options tests
fzhinkin
parents:
diff
changeset
|
62 |
verifyHeapSizesSum(options.reserved, |
263a69157012
8059623: JEP-JDK-8043304: Test task: command line options tests
fzhinkin
parents:
diff
changeset
|
63 |
scaleCodeHeapSize(options.profiled), options.nonProfiled, |
263a69157012
8059623: JEP-JDK-8043304: Test task: command line options tests
fzhinkin
parents:
diff
changeset
|
64 |
options.nonNmethods); |
263a69157012
8059623: JEP-JDK-8043304: Test task: command line options tests
fzhinkin
parents:
diff
changeset
|
65 |
verifyHeapSizesSum(options.reserved, options.profiled, |
263a69157012
8059623: JEP-JDK-8043304: Test task: command line options tests
fzhinkin
parents:
diff
changeset
|
66 |
scaleCodeHeapSize(options.nonProfiled), options.nonNmethods); |
263a69157012
8059623: JEP-JDK-8043304: Test task: command line options tests
fzhinkin
parents:
diff
changeset
|
67 |
verifyHeapSizesSum(options.reserved, options.profiled, |
263a69157012
8059623: JEP-JDK-8043304: Test task: command line options tests
fzhinkin
parents:
diff
changeset
|
68 |
options.nonProfiled, scaleCodeHeapSize(options.nonNmethods)); |
263a69157012
8059623: JEP-JDK-8043304: Test task: command line options tests
fzhinkin
parents:
diff
changeset
|
69 |
} |
263a69157012
8059623: JEP-JDK-8043304: Test task: command line options tests
fzhinkin
parents:
diff
changeset
|
70 |
|
263a69157012
8059623: JEP-JDK-8043304: Test task: command line options tests
fzhinkin
parents:
diff
changeset
|
71 |
/** |
263a69157012
8059623: JEP-JDK-8043304: Test task: command line options tests
fzhinkin
parents:
diff
changeset
|
72 |
* Verifies that if all three options will have values such that their sum |
263a69157012
8059623: JEP-JDK-8043304: Test task: command line options tests
fzhinkin
parents:
diff
changeset
|
73 |
* is inconsistent with ReservedCodeCacheSize value, then JVM startup will |
263a69157012
8059623: JEP-JDK-8043304: Test task: command line options tests
fzhinkin
parents:
diff
changeset
|
74 |
* fail. |
263a69157012
8059623: JEP-JDK-8043304: Test task: command line options tests
fzhinkin
parents:
diff
changeset
|
75 |
*/ |
263a69157012
8059623: JEP-JDK-8043304: Test task: command line options tests
fzhinkin
parents:
diff
changeset
|
76 |
private static void verifyAllInconsistentValues(CodeCacheOptions options) |
263a69157012
8059623: JEP-JDK-8043304: Test task: command line options tests
fzhinkin
parents:
diff
changeset
|
77 |
throws Throwable { |
263a69157012
8059623: JEP-JDK-8043304: Test task: command line options tests
fzhinkin
parents:
diff
changeset
|
78 |
long profiled = options.profiled; |
263a69157012
8059623: JEP-JDK-8043304: Test task: command line options tests
fzhinkin
parents:
diff
changeset
|
79 |
long nonProfiled = options.nonProfiled; |
263a69157012
8059623: JEP-JDK-8043304: Test task: command line options tests
fzhinkin
parents:
diff
changeset
|
80 |
long nonNMethods = options.nonNmethods; |
263a69157012
8059623: JEP-JDK-8043304: Test task: command line options tests
fzhinkin
parents:
diff
changeset
|
81 |
|
263a69157012
8059623: JEP-JDK-8043304: Test task: command line options tests
fzhinkin
parents:
diff
changeset
|
82 |
while (options.reserved == profiled + nonProfiled + nonNMethods) { |
263a69157012
8059623: JEP-JDK-8043304: Test task: command line options tests
fzhinkin
parents:
diff
changeset
|
83 |
profiled = scaleCodeHeapSize(profiled); |
263a69157012
8059623: JEP-JDK-8043304: Test task: command line options tests
fzhinkin
parents:
diff
changeset
|
84 |
nonProfiled = scaleCodeHeapSize(nonProfiled); |
263a69157012
8059623: JEP-JDK-8043304: Test task: command line options tests
fzhinkin
parents:
diff
changeset
|
85 |
nonNMethods = scaleCodeHeapSize(nonNMethods); |
263a69157012
8059623: JEP-JDK-8043304: Test task: command line options tests
fzhinkin
parents:
diff
changeset
|
86 |
} |
263a69157012
8059623: JEP-JDK-8043304: Test task: command line options tests
fzhinkin
parents:
diff
changeset
|
87 |
|
263a69157012
8059623: JEP-JDK-8043304: Test task: command line options tests
fzhinkin
parents:
diff
changeset
|
88 |
verifyHeapSizesSum(options.reserved, profiled, nonProfiled, |
263a69157012
8059623: JEP-JDK-8043304: Test task: command line options tests
fzhinkin
parents:
diff
changeset
|
89 |
nonNMethods); |
263a69157012
8059623: JEP-JDK-8043304: Test task: command line options tests
fzhinkin
parents:
diff
changeset
|
90 |
} |
263a69157012
8059623: JEP-JDK-8043304: Test task: command line options tests
fzhinkin
parents:
diff
changeset
|
91 |
|
263a69157012
8059623: JEP-JDK-8043304: Test task: command line options tests
fzhinkin
parents:
diff
changeset
|
92 |
private static void verifyHeapSizesSum(long reserved, long profiled, |
263a69157012
8059623: JEP-JDK-8043304: Test task: command line options tests
fzhinkin
parents:
diff
changeset
|
93 |
long nonProfiled, long nonNmethods) throws Throwable { |
263a69157012
8059623: JEP-JDK-8043304: Test task: command line options tests
fzhinkin
parents:
diff
changeset
|
94 |
// JVM startup expected to fail when |
263a69157012
8059623: JEP-JDK-8043304: Test task: command line options tests
fzhinkin
parents:
diff
changeset
|
95 |
// sum(all code heap sizes) != reserved CC size |
263a69157012
8059623: JEP-JDK-8043304: Test task: command line options tests
fzhinkin
parents:
diff
changeset
|
96 |
CommandLineOptionTest.verifySameJVMStartup( |
263a69157012
8059623: JEP-JDK-8043304: Test task: command line options tests
fzhinkin
parents:
diff
changeset
|
97 |
new String[]{ INCONSISTENT_CH_SIZES_ERROR }, |
263a69157012
8059623: JEP-JDK-8043304: Test task: command line options tests
fzhinkin
parents:
diff
changeset
|
98 |
/* unexpected messages */ null, |
263a69157012
8059623: JEP-JDK-8043304: Test task: command line options tests
fzhinkin
parents:
diff
changeset
|
99 |
"JVM startup should fail with inconsistent code heap size.", |
263a69157012
8059623: JEP-JDK-8043304: Test task: command line options tests
fzhinkin
parents:
diff
changeset
|
100 |
"JVM output should contain appropriate error message of code " |
263a69157012
8059623: JEP-JDK-8043304: Test task: command line options tests
fzhinkin
parents:
diff
changeset
|
101 |
+ "heap sizes are inconsistent", |
263a69157012
8059623: JEP-JDK-8043304: Test task: command line options tests
fzhinkin
parents:
diff
changeset
|
102 |
ExitCode.FAIL, |
263a69157012
8059623: JEP-JDK-8043304: Test task: command line options tests
fzhinkin
parents:
diff
changeset
|
103 |
CommandLineOptionTest.prepareBooleanFlag( |
263a69157012
8059623: JEP-JDK-8043304: Test task: command line options tests
fzhinkin
parents:
diff
changeset
|
104 |
CodeCacheOptions.SEGMENTED_CODE_CACHE, true), |
263a69157012
8059623: JEP-JDK-8043304: Test task: command line options tests
fzhinkin
parents:
diff
changeset
|
105 |
CommandLineOptionTest.prepareNumericFlag( |
263a69157012
8059623: JEP-JDK-8043304: Test task: command line options tests
fzhinkin
parents:
diff
changeset
|
106 |
BlobType.All.sizeOptionName, reserved), |
263a69157012
8059623: JEP-JDK-8043304: Test task: command line options tests
fzhinkin
parents:
diff
changeset
|
107 |
CommandLineOptionTest.prepareNumericFlag( |
263a69157012
8059623: JEP-JDK-8043304: Test task: command line options tests
fzhinkin
parents:
diff
changeset
|
108 |
BlobType.MethodProfiled.sizeOptionName, profiled), |
263a69157012
8059623: JEP-JDK-8043304: Test task: command line options tests
fzhinkin
parents:
diff
changeset
|
109 |
CommandLineOptionTest.prepareNumericFlag( |
263a69157012
8059623: JEP-JDK-8043304: Test task: command line options tests
fzhinkin
parents:
diff
changeset
|
110 |
BlobType.MethodNonProfiled.sizeOptionName, nonProfiled), |
263a69157012
8059623: JEP-JDK-8043304: Test task: command line options tests
fzhinkin
parents:
diff
changeset
|
111 |
CommandLineOptionTest.prepareNumericFlag( |
263a69157012
8059623: JEP-JDK-8043304: Test task: command line options tests
fzhinkin
parents:
diff
changeset
|
112 |
BlobType.NonNMethod.sizeOptionName, nonNmethods)); |
263a69157012
8059623: JEP-JDK-8043304: Test task: command line options tests
fzhinkin
parents:
diff
changeset
|
113 |
} |
263a69157012
8059623: JEP-JDK-8043304: Test task: command line options tests
fzhinkin
parents:
diff
changeset
|
114 |
|
263a69157012
8059623: JEP-JDK-8043304: Test task: command line options tests
fzhinkin
parents:
diff
changeset
|
115 |
/** |
263a69157012
8059623: JEP-JDK-8043304: Test task: command line options tests
fzhinkin
parents:
diff
changeset
|
116 |
* Returns {@code unscaledSize} value scaled by a random factor from |
263a69157012
8059623: JEP-JDK-8043304: Test task: command line options tests
fzhinkin
parents:
diff
changeset
|
117 |
* range (1, 2). If {@code unscaledSize} is not 0, then this |
263a69157012
8059623: JEP-JDK-8043304: Test task: command line options tests
fzhinkin
parents:
diff
changeset
|
118 |
* method will return value that won't be equal to {@code unscaledSize}. |
263a69157012
8059623: JEP-JDK-8043304: Test task: command line options tests
fzhinkin
parents:
diff
changeset
|
119 |
* |
263a69157012
8059623: JEP-JDK-8043304: Test task: command line options tests
fzhinkin
parents:
diff
changeset
|
120 |
* @param unscaledSize The value to be scaled. |
263a69157012
8059623: JEP-JDK-8043304: Test task: command line options tests
fzhinkin
parents:
diff
changeset
|
121 |
* @return {@code unscaledSize} value scaled by a factor from range (1, 2). |
263a69157012
8059623: JEP-JDK-8043304: Test task: command line options tests
fzhinkin
parents:
diff
changeset
|
122 |
*/ |
263a69157012
8059623: JEP-JDK-8043304: Test task: command line options tests
fzhinkin
parents:
diff
changeset
|
123 |
private static long scaleCodeHeapSize(long unscaledSize) { |
263a69157012
8059623: JEP-JDK-8043304: Test task: command line options tests
fzhinkin
parents:
diff
changeset
|
124 |
Random random = Utils.getRandomInstance(); |
263a69157012
8059623: JEP-JDK-8043304: Test task: command line options tests
fzhinkin
parents:
diff
changeset
|
125 |
|
263a69157012
8059623: JEP-JDK-8043304: Test task: command line options tests
fzhinkin
parents:
diff
changeset
|
126 |
long scaledSize = unscaledSize; |
263a69157012
8059623: JEP-JDK-8043304: Test task: command line options tests
fzhinkin
parents:
diff
changeset
|
127 |
while (scaledSize == unscaledSize && unscaledSize != 0) { |
263a69157012
8059623: JEP-JDK-8043304: Test task: command line options tests
fzhinkin
parents:
diff
changeset
|
128 |
float scale = 1.0f + random.nextFloat(); |
263a69157012
8059623: JEP-JDK-8043304: Test task: command line options tests
fzhinkin
parents:
diff
changeset
|
129 |
scaledSize = (long) Math.ceil(scale * unscaledSize); |
263a69157012
8059623: JEP-JDK-8043304: Test task: command line options tests
fzhinkin
parents:
diff
changeset
|
130 |
} |
263a69157012
8059623: JEP-JDK-8043304: Test task: command line options tests
fzhinkin
parents:
diff
changeset
|
131 |
return scaledSize; |
263a69157012
8059623: JEP-JDK-8043304: Test task: command line options tests
fzhinkin
parents:
diff
changeset
|
132 |
} |
263a69157012
8059623: JEP-JDK-8043304: Test task: command line options tests
fzhinkin
parents:
diff
changeset
|
133 |
} |