author | tpivovarova |
Sat, 19 Sep 2015 12:03:36 +0300 | |
changeset 33072 | 71f9b0782023 |
parent 31522 | 2d29f2e927fc |
child 40059 | c2304140ed64 |
permissions | -rw-r--r-- |
28384 | 1 |
/* |
30604
b8d532cb6420
8067013: Rename the com.oracle.java.testlibary package
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 |
||
31522
2d29f2e927fc
8129937: compiler/codecache/jmx/UsageThresholdIncreasedTest.java fails with "Usage threshold was hit"
thartmann
parents:
30604
diff
changeset
|
24 |
import jdk.test.lib.Asserts; |
30604
b8d532cb6420
8067013: Rename the com.oracle.java.testlibary package
ykantser
parents:
28384
diff
changeset
|
25 |
import jdk.test.lib.Utils; |
28384 | 26 |
import java.lang.management.MemoryPoolMXBean; |
27 |
import javax.management.Notification; |
|
28 |
import sun.hotspot.WhiteBox; |
|
29 |
import sun.hotspot.code.BlobType; |
|
30 |
import sun.hotspot.code.CodeBlob; |
|
31 |
||
32 |
public final class CodeCacheUtils { |
|
33 |
||
34 |
/** |
|
35 |
* Returns the value to be used for code heap allocation |
|
36 |
*/ |
|
37 |
public static final int ALLOCATION_SIZE |
|
38 |
= Integer.getInteger("codecache.allocation.size", 100); |
|
39 |
public static final WhiteBox WB = WhiteBox.getWhiteBox(); |
|
40 |
public static final long SEGMENT_SIZE |
|
41 |
= WhiteBox.getWhiteBox().getUintxVMFlag("CodeCacheSegmentSize"); |
|
42 |
public static final long MIN_BLOCK_LENGTH |
|
43 |
= WhiteBox.getWhiteBox().getUintxVMFlag("CodeCacheMinBlockLength"); |
|
44 |
public static final long MIN_ALLOCATION = SEGMENT_SIZE * MIN_BLOCK_LENGTH; |
|
45 |
||
46 |
private CodeCacheUtils() { |
|
47 |
// To prevent from instantiation |
|
48 |
} |
|
49 |
||
50 |
public static final void hitUsageThreshold(MemoryPoolMXBean bean, |
|
51 |
BlobType btype) { |
|
52 |
long initialSize = bean.getUsage().getUsed(); |
|
53 |
bean.setUsageThreshold(initialSize + 1); |
|
54 |
long usageThresholdCount = bean.getUsageThresholdCount(); |
|
55 |
long addr = WB.allocateCodeBlob(1, btype.id); |
|
56 |
WB.fullGC(); |
|
57 |
Utils.waitForCondition(() |
|
58 |
-> bean.getUsageThresholdCount() == usageThresholdCount + 1); |
|
59 |
WB.freeCodeBlob(addr); |
|
60 |
} |
|
61 |
||
62 |
public static final long getHeaderSize(BlobType btype) { |
|
63 |
long addr = WB.allocateCodeBlob(0, btype.id); |
|
64 |
int size = CodeBlob.getCodeBlob(addr).size; |
|
65 |
WB.freeCodeBlob(addr); |
|
66 |
return size; |
|
67 |
} |
|
68 |
||
69 |
public static String getPoolNameFromNotification( |
|
70 |
Notification notification) { |
|
71 |
return ((javax.management.openmbean.CompositeDataSupport) |
|
72 |
notification.getUserData()).get("poolName").toString(); |
|
73 |
} |
|
74 |
||
75 |
public static boolean isAvailableCodeHeapPoolName(String name) { |
|
76 |
return BlobType.getAvailable().stream() |
|
77 |
.map(BlobType::getMemoryPool) |
|
78 |
.map(MemoryPoolMXBean::getName) |
|
79 |
.filter(name::equals) |
|
80 |
.findAny().isPresent(); |
|
81 |
} |
|
82 |
||
83 |
/** |
|
31522
2d29f2e927fc
8129937: compiler/codecache/jmx/UsageThresholdIncreasedTest.java fails with "Usage threshold was hit"
thartmann
parents:
30604
diff
changeset
|
84 |
* Checks if the usage of the code heap corresponding to 'btype' can be |
2d29f2e927fc
8129937: compiler/codecache/jmx/UsageThresholdIncreasedTest.java fails with "Usage threshold was hit"
thartmann
parents:
30604
diff
changeset
|
85 |
* predicted at runtime if we disable compilation. The usage of the |
2d29f2e927fc
8129937: compiler/codecache/jmx/UsageThresholdIncreasedTest.java fails with "Usage threshold was hit"
thartmann
parents:
30604
diff
changeset
|
86 |
* 'NonNMethod' code heap can not be predicted because we generate adapters |
2d29f2e927fc
8129937: compiler/codecache/jmx/UsageThresholdIncreasedTest.java fails with "Usage threshold was hit"
thartmann
parents:
30604
diff
changeset
|
87 |
* and buffers at runtime. The 'MethodNonProfiled' code heap is also not |
2d29f2e927fc
8129937: compiler/codecache/jmx/UsageThresholdIncreasedTest.java fails with "Usage threshold was hit"
thartmann
parents:
30604
diff
changeset
|
88 |
* predictable because we may generate compiled versions of method handle |
2d29f2e927fc
8129937: compiler/codecache/jmx/UsageThresholdIncreasedTest.java fails with "Usage threshold was hit"
thartmann
parents:
30604
diff
changeset
|
89 |
* intrinsics while resolving methods at runtime. Same applies to 'All'. |
28384 | 90 |
* |
91 |
* @param btype BlobType to be checked |
|
92 |
* @return boolean value, true if respective code heap is predictable |
|
93 |
*/ |
|
94 |
public static boolean isCodeHeapPredictable(BlobType btype) { |
|
31522
2d29f2e927fc
8129937: compiler/codecache/jmx/UsageThresholdIncreasedTest.java fails with "Usage threshold was hit"
thartmann
parents:
30604
diff
changeset
|
95 |
return btype == BlobType.MethodProfiled; |
28384 | 96 |
} |
97 |
||
31522
2d29f2e927fc
8129937: compiler/codecache/jmx/UsageThresholdIncreasedTest.java fails with "Usage threshold was hit"
thartmann
parents:
30604
diff
changeset
|
98 |
/** |
2d29f2e927fc
8129937: compiler/codecache/jmx/UsageThresholdIncreasedTest.java fails with "Usage threshold was hit"
thartmann
parents:
30604
diff
changeset
|
99 |
* Verifies that 'newValue' is equal to 'oldValue' if usage of the |
2d29f2e927fc
8129937: compiler/codecache/jmx/UsageThresholdIncreasedTest.java fails with "Usage threshold was hit"
thartmann
parents:
30604
diff
changeset
|
100 |
* corresponding code heap is predictable. Checks the weaker condition |
2d29f2e927fc
8129937: compiler/codecache/jmx/UsageThresholdIncreasedTest.java fails with "Usage threshold was hit"
thartmann
parents:
30604
diff
changeset
|
101 |
* 'newValue >= oldValue' if usage is not predictable because intermediate |
2d29f2e927fc
8129937: compiler/codecache/jmx/UsageThresholdIncreasedTest.java fails with "Usage threshold was hit"
thartmann
parents:
30604
diff
changeset
|
102 |
* allocations may happen. |
2d29f2e927fc
8129937: compiler/codecache/jmx/UsageThresholdIncreasedTest.java fails with "Usage threshold was hit"
thartmann
parents:
30604
diff
changeset
|
103 |
* |
2d29f2e927fc
8129937: compiler/codecache/jmx/UsageThresholdIncreasedTest.java fails with "Usage threshold was hit"
thartmann
parents:
30604
diff
changeset
|
104 |
* @param btype BlobType of the code heap to be checked |
2d29f2e927fc
8129937: compiler/codecache/jmx/UsageThresholdIncreasedTest.java fails with "Usage threshold was hit"
thartmann
parents:
30604
diff
changeset
|
105 |
* @param newValue New value to be verified |
2d29f2e927fc
8129937: compiler/codecache/jmx/UsageThresholdIncreasedTest.java fails with "Usage threshold was hit"
thartmann
parents:
30604
diff
changeset
|
106 |
* @param oldValue Old value to be verified |
2d29f2e927fc
8129937: compiler/codecache/jmx/UsageThresholdIncreasedTest.java fails with "Usage threshold was hit"
thartmann
parents:
30604
diff
changeset
|
107 |
* @param msg Error message if verification fails |
2d29f2e927fc
8129937: compiler/codecache/jmx/UsageThresholdIncreasedTest.java fails with "Usage threshold was hit"
thartmann
parents:
30604
diff
changeset
|
108 |
*/ |
2d29f2e927fc
8129937: compiler/codecache/jmx/UsageThresholdIncreasedTest.java fails with "Usage threshold was hit"
thartmann
parents:
30604
diff
changeset
|
109 |
public static void assertEQorGTE(BlobType btype, long newValue, long oldValue, String msg) { |
2d29f2e927fc
8129937: compiler/codecache/jmx/UsageThresholdIncreasedTest.java fails with "Usage threshold was hit"
thartmann
parents:
30604
diff
changeset
|
110 |
if (CodeCacheUtils.isCodeHeapPredictable(btype)) { |
2d29f2e927fc
8129937: compiler/codecache/jmx/UsageThresholdIncreasedTest.java fails with "Usage threshold was hit"
thartmann
parents:
30604
diff
changeset
|
111 |
// Usage is predictable, check strong == condition |
2d29f2e927fc
8129937: compiler/codecache/jmx/UsageThresholdIncreasedTest.java fails with "Usage threshold was hit"
thartmann
parents:
30604
diff
changeset
|
112 |
Asserts.assertEQ(newValue, oldValue, msg); |
2d29f2e927fc
8129937: compiler/codecache/jmx/UsageThresholdIncreasedTest.java fails with "Usage threshold was hit"
thartmann
parents:
30604
diff
changeset
|
113 |
} else { |
2d29f2e927fc
8129937: compiler/codecache/jmx/UsageThresholdIncreasedTest.java fails with "Usage threshold was hit"
thartmann
parents:
30604
diff
changeset
|
114 |
// Usage is not predictable, check weaker >= condition |
2d29f2e927fc
8129937: compiler/codecache/jmx/UsageThresholdIncreasedTest.java fails with "Usage threshold was hit"
thartmann
parents:
30604
diff
changeset
|
115 |
Asserts.assertGTE(newValue, oldValue, msg); |
2d29f2e927fc
8129937: compiler/codecache/jmx/UsageThresholdIncreasedTest.java fails with "Usage threshold was hit"
thartmann
parents:
30604
diff
changeset
|
116 |
} |
2d29f2e927fc
8129937: compiler/codecache/jmx/UsageThresholdIncreasedTest.java fails with "Usage threshold was hit"
thartmann
parents:
30604
diff
changeset
|
117 |
} |
2d29f2e927fc
8129937: compiler/codecache/jmx/UsageThresholdIncreasedTest.java fails with "Usage threshold was hit"
thartmann
parents:
30604
diff
changeset
|
118 |
|
2d29f2e927fc
8129937: compiler/codecache/jmx/UsageThresholdIncreasedTest.java fails with "Usage threshold was hit"
thartmann
parents:
30604
diff
changeset
|
119 |
public static void disableCollectionUsageThresholds() { |
28384 | 120 |
BlobType.getAvailable().stream() |
121 |
.map(BlobType::getMemoryPool) |
|
122 |
.filter(MemoryPoolMXBean::isCollectionUsageThresholdSupported) |
|
123 |
.forEach(b -> b.setCollectionUsageThreshold(0L)); |
|
124 |
} |
|
125 |
} |