author | gziemski |
Tue, 21 Nov 2017 10:21:24 -0600 | |
changeset 48013 | 2098785677fb |
parent 47774 | 69c081ca110a |
child 48018 | 8bab1e50a28a |
permissions | -rw-r--r-- |
47774 | 1 |
/* |
2 |
* Copyright (c) 2017, Oracle and/or its affiliates. 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 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 8184765 |
|
27 |
* @summary make sure the SystemDictionary gets resized when load factor is too high |
|
28 |
* @library /test/lib |
|
29 |
* @modules java.base/jdk.internal.misc |
|
30 |
* java.management |
|
31 |
* @compile TriggerResize.java |
|
48013
2098785677fb
8191580: open/test/hotspot/jtreg/runtime/LoadClass/TestResize fails on product build
gziemski
parents:
47774
diff
changeset
|
32 |
* @requires (vm.debug == true) |
47774 | 33 |
* @run driver TestResize |
34 |
*/ |
|
35 |
||
36 |
import java.lang.ProcessBuilder; |
|
37 |
import java.lang.Process; |
|
38 |
import jdk.test.lib.process.ProcessTools; |
|
39 |
import java.io.BufferedReader; |
|
40 |
import java.io.InputStreamReader; |
|
41 |
import java.util.Scanner; |
|
42 |
||
43 |
public class TestResize { |
|
44 |
||
45 |
static double MAX_LOAD_FACTOR = 5.0; // see _resize_load_trigger in dictionary.cpp |
|
46 |
||
47 |
static int getInt(String string) { |
|
48 |
int start = 0; |
|
49 |
for (int i = 0; i < string.length(); i++) { |
|
50 |
if (!Character.isDigit(string.charAt(i))) { |
|
51 |
start++; |
|
52 |
} else { |
|
53 |
break; |
|
54 |
} |
|
55 |
} |
|
56 |
int end = start; |
|
57 |
for (int i = end; i < string.length(); i++) { |
|
58 |
if (Character.isDigit(string.charAt(i))) { |
|
59 |
end++; |
|
60 |
} else { |
|
61 |
break; |
|
62 |
} |
|
63 |
} |
|
64 |
return Integer.parseInt(string.substring(start, end)); |
|
65 |
} |
|
66 |
||
67 |
static void analyzeOutputOn(ProcessBuilder pb) throws Exception { |
|
68 |
pb.redirectErrorStream(true); |
|
69 |
Process process = pb.start(); |
|
70 |
BufferedReader rd = new BufferedReader(new InputStreamReader(process.getInputStream())); |
|
71 |
String line = rd.readLine(); |
|
72 |
while (line != null) { |
|
73 |
if (line.startsWith("Java dictionary (")) { |
|
74 |
// ex. "Java dictionary (table_size=107, classes=6)" |
|
75 |
// ex. "Java dictionary (table_size=20201, classes=50002)" |
|
76 |
Scanner scanner = new Scanner(line); |
|
77 |
scanner.next(); |
|
78 |
scanner.next(); |
|
79 |
int table_size = getInt(scanner.next()); |
|
80 |
int classes = getInt(scanner.next()); |
|
81 |
scanner.close(); |
|
82 |
||
83 |
double loadFactor = (double)classes / (double)table_size; |
|
84 |
if (loadFactor > MAX_LOAD_FACTOR) { |
|
85 |
throw new RuntimeException("Load factor too high, expected MAX "+MAX_LOAD_FACTOR+", got "+loadFactor); |
|
86 |
} else { |
|
87 |
System.out.println("PASS table_size:"+table_size+", classes:"+classes+" OK"); |
|
88 |
} |
|
89 |
} |
|
90 |
line = rd.readLine(); |
|
91 |
} |
|
92 |
int retval = process.waitFor(); |
|
93 |
if (retval != 0) { |
|
94 |
throw new RuntimeException("Error: test returned non-zero value"); |
|
95 |
} |
|
96 |
} |
|
97 |
||
98 |
public static void main(String[] args) throws Exception { |
|
48013
2098785677fb
8191580: open/test/hotspot/jtreg/runtime/LoadClass/TestResize fails on product build
gziemski
parents:
47774
diff
changeset
|
99 |
if (Platform.isDebugBuild()) { |
2098785677fb
8191580: open/test/hotspot/jtreg/runtime/LoadClass/TestResize fails on product build
gziemski
parents:
47774
diff
changeset
|
100 |
ProcessBuilder pb = ProcessTools.createJavaProcessBuilder("-XX:+PrintSystemDictionaryAtExit", |
2098785677fb
8191580: open/test/hotspot/jtreg/runtime/LoadClass/TestResize fails on product build
gziemski
parents:
47774
diff
changeset
|
101 |
"TriggerResize", |
2098785677fb
8191580: open/test/hotspot/jtreg/runtime/LoadClass/TestResize fails on product build
gziemski
parents:
47774
diff
changeset
|
102 |
"50000"); |
2098785677fb
8191580: open/test/hotspot/jtreg/runtime/LoadClass/TestResize fails on product build
gziemski
parents:
47774
diff
changeset
|
103 |
analyzeOutputOn(pb); |
2098785677fb
8191580: open/test/hotspot/jtreg/runtime/LoadClass/TestResize fails on product build
gziemski
parents:
47774
diff
changeset
|
104 |
} |
47774 | 105 |
} |
106 |
} |