author | tpivovarova |
Sat, 19 Sep 2015 12:03:36 +0300 | |
changeset 33072 | 71f9b0782023 |
parent 31522 | 2d29f2e927fc |
child 33730 | 30e064828045 |
permissions | -rw-r--r-- |
28384 | 1 |
/* |
29678
dd2f3932c21e
8075586: Add @modules as needed to the open hotspot tests
ykantser
parents:
28384
diff
changeset
|
2 |
* Copyright (c) 2014, 2015, Oracle and/or its affiliates. All rights reserved. |
28384 | 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 |
||
30604
b8d532cb6420
8067013: Rename the com.oracle.java.testlibary package
ykantser
parents:
29678
diff
changeset
|
24 |
import jdk.test.lib.Asserts; |
28384 | 25 |
import java.lang.management.MemoryPoolMXBean; |
26 |
import java.util.HashMap; |
|
27 |
import java.util.Map; |
|
28 |
import sun.hotspot.code.BlobType; |
|
29 |
||
30 |
/* |
|
31 |
* @test GetUsageTest |
|
32 |
* @library /testlibrary /../../test/lib |
|
29678
dd2f3932c21e
8075586: Add @modules as needed to the open hotspot tests
ykantser
parents:
28384
diff
changeset
|
33 |
* @modules java.base/sun.misc |
dd2f3932c21e
8075586: Add @modules as needed to the open hotspot tests
ykantser
parents:
28384
diff
changeset
|
34 |
* java.management |
28384 | 35 |
* @build GetUsageTest |
36 |
* @run main ClassFileInstaller sun.hotspot.WhiteBox |
|
37 |
* sun.hotspot.WhiteBox$WhiteBoxPermission |
|
38 |
* @run main/othervm -Xbootclasspath/a:. -XX:CompileCommand=compileonly,null::* |
|
39 |
* -XX:-UseCodeCacheFlushing -XX:-MethodFlushing -XX:+SegmentedCodeCache |
|
40 |
* -XX:+UnlockDiagnosticVMOptions -XX:+WhiteBoxAPI GetUsageTest |
|
41 |
* @summary testing of getUsage() for segmented code cache |
|
42 |
*/ |
|
43 |
public class GetUsageTest { |
|
44 |
||
45 |
private final BlobType btype; |
|
46 |
private final int allocateSize; |
|
47 |
||
48 |
public GetUsageTest(BlobType btype, int allocSize) { |
|
49 |
this.btype = btype; |
|
50 |
this.allocateSize = allocSize; |
|
51 |
} |
|
52 |
||
53 |
public static void main(String[] args) throws Exception { |
|
54 |
for (BlobType btype : BlobType.getAvailable()) { |
|
31522
2d29f2e927fc
8129937: compiler/codecache/jmx/UsageThresholdIncreasedTest.java fails with "Usage threshold was hit"
thartmann
parents:
30604
diff
changeset
|
55 |
for (int allocSize = 10; allocSize < 100000; allocSize *= 10) { |
2d29f2e927fc
8129937: compiler/codecache/jmx/UsageThresholdIncreasedTest.java fails with "Usage threshold was hit"
thartmann
parents:
30604
diff
changeset
|
56 |
new GetUsageTest(btype, allocSize).runTest(); |
28384 | 57 |
} |
58 |
} |
|
59 |
} |
|
60 |
||
61 |
protected final Map<MemoryPoolMXBean, Long> getBeanUsages() { |
|
62 |
Map<MemoryPoolMXBean, Long> beanUsages = new HashMap<>(); |
|
63 |
for (BlobType bt : BlobType.getAvailable()) { |
|
64 |
beanUsages.put(bt.getMemoryPool(), |
|
65 |
bt.getMemoryPool().getUsage().getUsed()); |
|
66 |
} |
|
67 |
return beanUsages; |
|
68 |
} |
|
69 |
||
70 |
protected void runTest() { |
|
71 |
MemoryPoolMXBean[] predictableBeans = BlobType.getAvailable().stream() |
|
72 |
.filter(CodeCacheUtils::isCodeHeapPredictable) |
|
73 |
.map(BlobType::getMemoryPool) |
|
74 |
.toArray(MemoryPoolMXBean[]::new); |
|
75 |
Map<MemoryPoolMXBean, Long> initial = getBeanUsages(); |
|
76 |
long addr = 0; |
|
77 |
try { |
|
78 |
addr = CodeCacheUtils.WB.allocateCodeBlob(allocateSize, btype.id); |
|
79 |
Map<MemoryPoolMXBean, Long> current = getBeanUsages(); |
|
80 |
long blockCount = Math.floorDiv(allocateSize |
|
81 |
+ CodeCacheUtils.getHeaderSize(btype) |
|
82 |
+ CodeCacheUtils.SEGMENT_SIZE - 1, CodeCacheUtils.SEGMENT_SIZE); |
|
83 |
long usageUpperEstimate = Math.max(blockCount, |
|
84 |
CodeCacheUtils.MIN_BLOCK_LENGTH) * CodeCacheUtils.SEGMENT_SIZE; |
|
85 |
for (MemoryPoolMXBean entry : predictableBeans) { |
|
86 |
long diff = current.get(entry) - initial.get(entry); |
|
87 |
if (entry.equals(btype.getMemoryPool())) { |
|
31522
2d29f2e927fc
8129937: compiler/codecache/jmx/UsageThresholdIncreasedTest.java fails with "Usage threshold was hit"
thartmann
parents:
30604
diff
changeset
|
88 |
if (CodeCacheUtils.isCodeHeapPredictable(btype)) { |
2d29f2e927fc
8129937: compiler/codecache/jmx/UsageThresholdIncreasedTest.java fails with "Usage threshold was hit"
thartmann
parents:
30604
diff
changeset
|
89 |
Asserts.assertFalse(diff <= 0L || diff > usageUpperEstimate, |
2d29f2e927fc
8129937: compiler/codecache/jmx/UsageThresholdIncreasedTest.java fails with "Usage threshold was hit"
thartmann
parents:
30604
diff
changeset
|
90 |
String.format("Pool %s usage increase was reported " |
2d29f2e927fc
8129937: compiler/codecache/jmx/UsageThresholdIncreasedTest.java fails with "Usage threshold was hit"
thartmann
parents:
30604
diff
changeset
|
91 |
+ "unexpectedly as increased by %d using " |
2d29f2e927fc
8129937: compiler/codecache/jmx/UsageThresholdIncreasedTest.java fails with "Usage threshold was hit"
thartmann
parents:
30604
diff
changeset
|
92 |
+ "allocation size %d", entry.getName(), |
2d29f2e927fc
8129937: compiler/codecache/jmx/UsageThresholdIncreasedTest.java fails with "Usage threshold was hit"
thartmann
parents:
30604
diff
changeset
|
93 |
diff, allocateSize)); |
2d29f2e927fc
8129937: compiler/codecache/jmx/UsageThresholdIncreasedTest.java fails with "Usage threshold was hit"
thartmann
parents:
30604
diff
changeset
|
94 |
} |
28384 | 95 |
} else { |
31522
2d29f2e927fc
8129937: compiler/codecache/jmx/UsageThresholdIncreasedTest.java fails with "Usage threshold was hit"
thartmann
parents:
30604
diff
changeset
|
96 |
CodeCacheUtils.assertEQorGTE(btype, diff, 0L, |
28384 | 97 |
String.format("Pool %s usage changed unexpectedly while" |
98 |
+ " trying to increase: %s using allocation " |
|
99 |
+ "size %d", entry.getName(), |
|
100 |
btype.getMemoryPool().getName(), allocateSize)); |
|
101 |
} |
|
102 |
} |
|
103 |
} finally { |
|
104 |
if (addr != 0) { |
|
105 |
CodeCacheUtils.WB.freeCodeBlob(addr); |
|
106 |
} |
|
107 |
} |
|
108 |
System.out.printf("INFO: Scenario finished successfully for %s%n", |
|
109 |
btype.getMemoryPool().getName()); |
|
110 |
} |
|
111 |
} |