|
33 | 33 | * @library /test/lib
|
34 | 34 | * @compile -XDallowWithFieldOperator InlineTypeDensity.java
|
35 | 35 | * @run driver ClassFileInstaller sun.hotspot.WhiteBox
|
36 |
| - * @run main/othervm -Xint -XX:FlatArrayElementMaxSize=-1 |
| 36 | + * @run main/othervm -Xint -XX:FlatArrayElementMaxSize=-1 -XX:+UseCompressedOops |
| 37 | + * -Xbootclasspath/a:. -XX:+UnlockDiagnosticVMOptions |
| 38 | + * -XX:+WhiteBoxAPI InlineTypeDensity |
| 39 | + * @run main/othervm -Xint -XX:FlatArrayElementMaxSize=-1 -XX:-UseCompressedOops |
37 | 40 | * -Xbootclasspath/a:. -XX:+UnlockDiagnosticVMOptions
|
38 | 41 | * -XX:+WhiteBoxAPI InlineTypeDensity
|
39 | 42 | * @run main/othervm -Xcomp -XX:FlatArrayElementMaxSize=-1
|
|
47 | 50 | public class InlineTypeDensity {
|
48 | 51 |
|
49 | 52 | private static final WhiteBox WHITE_BOX = WhiteBox.getWhiteBox();
|
| 53 | + private static final boolean VM_FLAG_FORCENONTEARABLE = WHITE_BOX.getStringVMFlag("ForceNonTearable").equals("*"); |
50 | 54 |
|
51 | 55 | public InlineTypeDensity() {
|
52 | 56 | if (WHITE_BOX.getIntxVMFlag("FlatArrayElementMaxSize") != -1) {
|
@@ -229,8 +233,82 @@ public void ensureArraySizeWin() {
|
229 | 233 | Asserts.assertLessThan(flatArraySize, objectArraySize, "Flat array accounts for more heap than object array + elements !");
|
230 | 234 | }
|
231 | 235 |
|
| 236 | + static inline class MyByte { byte v = 0; } |
| 237 | + static inline class MyShort { short v = 0; } |
| 238 | + static inline class MyInt { int v = 0; } |
| 239 | + static inline class MyLong { long v = 0; } |
| 240 | + |
| 241 | + void assertArraySameSize(Object a, Object b, int nofElements) { |
| 242 | + long aSize = WHITE_BOX.getObjectSize(a); |
| 243 | + long bSize = WHITE_BOX.getObjectSize(b); |
| 244 | + Asserts.assertEquals(aSize, bSize, |
| 245 | + a + "(" + aSize + " bytes) not equivalent size " + |
| 246 | + b + "(" + bSize + " bytes)" + |
| 247 | + (nofElements >= 0 ? " (array of " + nofElements + " elements)" : "")); |
| 248 | + } |
| 249 | + |
| 250 | + void testByteArraySizesSame(int[] testSizes) { |
| 251 | + for (int testSize : testSizes) { |
| 252 | + byte[] ba = new byte[testSize]; |
| 253 | + MyByte[] mba = new MyByte[testSize]; |
| 254 | + assertArraySameSize(ba, mba, testSize); |
| 255 | + } |
| 256 | + } |
| 257 | + |
| 258 | + void testShortArraySizesSame(int[] testSizes) { |
| 259 | + for (int testSize : testSizes) { |
| 260 | + short[] sa = new short[testSize]; |
| 261 | + MyShort[] msa = new MyShort[testSize]; |
| 262 | + assertArraySameSize(sa, msa, testSize); |
| 263 | + } |
| 264 | + } |
| 265 | + |
| 266 | + void testIntArraySizesSame(int[] testSizes) { |
| 267 | + for (int testSize : testSizes) { |
| 268 | + int[] ia = new int[testSize]; |
| 269 | + MyInt[] mia = new MyInt[testSize]; |
| 270 | + assertArraySameSize(ia, mia, testSize); |
| 271 | + } |
| 272 | + } |
| 273 | + |
| 274 | + void testLongArraySizesSame(int[] testSizes) { |
| 275 | + for (int testSize : testSizes) { |
| 276 | + long[] la = new long[testSize]; |
| 277 | + MyLong[] mla = new MyLong[testSize]; |
| 278 | + assertArraySameSize(la, mla, testSize); |
| 279 | + } |
| 280 | + } |
| 281 | + |
| 282 | + public void testPrimitiveArraySizesSame() { |
| 283 | + int[] testSizes = new int[] { 0, 1, 2, 3, 4, 7, 10, 257 }; |
| 284 | + testByteArraySizesSame(testSizes); |
| 285 | + testShortArraySizesSame(testSizes); |
| 286 | + testIntArraySizesSame(testSizes); |
| 287 | + testLongArraySizesSame(testSizes); |
| 288 | + } |
| 289 | + |
| 290 | + static inline class bbValue { byte b = 0; byte b2 = 0;} |
| 291 | + static inline class bsValue { byte b = 0; short s = 0;} |
| 292 | + static inline class siValue { short s = 0; int i = 0;} |
| 293 | + static inline class ssiValue { short s = 0; short s2 = 0; int i = 0;} |
| 294 | + static inline class blValue { byte b = 0; long l = 0; } |
| 295 | + |
| 296 | + // Expect aligned array addressing to nearest pow2 |
| 297 | + void testAlignedSize() { |
| 298 | + int testSize = 10; |
| 299 | + if (!VM_FLAG_FORCENONTEARABLE) { |
| 300 | + assertArraySameSize(new short[testSize], new bbValue[testSize], testSize); |
| 301 | + assertArraySameSize(new long[testSize], new siValue[testSize], testSize); |
| 302 | + assertArraySameSize(new long[testSize], new ssiValue[testSize], testSize); |
| 303 | + assertArraySameSize(new long[testSize*2], new blValue[testSize], testSize); |
| 304 | + } |
| 305 | + assertArraySameSize(new int[testSize], new bsValue[testSize], testSize); |
| 306 | + } |
| 307 | + |
232 | 308 | public void test() {
|
233 | 309 | ensureArraySizeWin();
|
| 310 | + testPrimitiveArraySizesSame(); |
| 311 | + testAlignedSize(); |
234 | 312 | }
|
235 | 313 |
|
236 | 314 | public static void main(String[] args) {
|
|
0 commit comments