Mercurial > hg > truffle
annotate test/gc/survivorAlignment/SurvivorAlignmentTestMain.java @ 21543:93c50cefb9e8
moved GraalInternalError to com.oracle.jvmci.common and renamed it to JVMCIError (JBS:GRAAL-53)
author | Doug Simon <doug.simon@oracle.com> |
---|---|
date | Mon, 25 May 2015 23:30:34 +0200 |
parents | 4b7c96fba3d8 |
children |
rev | line source |
---|---|
20717
4b7c96fba3d8
8037968: Add tests on alignment of objects copied to survivor space
fzhinkin
parents:
diff
changeset
|
1 /* |
4b7c96fba3d8
8037968: Add tests on alignment of objects copied to survivor space
fzhinkin
parents:
diff
changeset
|
2 * Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved. |
4b7c96fba3d8
8037968: Add tests on alignment of objects copied to survivor space
fzhinkin
parents:
diff
changeset
|
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
4b7c96fba3d8
8037968: Add tests on alignment of objects copied to survivor space
fzhinkin
parents:
diff
changeset
|
4 * |
4b7c96fba3d8
8037968: Add tests on alignment of objects copied to survivor space
fzhinkin
parents:
diff
changeset
|
5 * This code is free software; you can redistribute it and/or modify it |
4b7c96fba3d8
8037968: Add tests on alignment of objects copied to survivor space
fzhinkin
parents:
diff
changeset
|
6 * under the terms of the GNU General Public License version 2 only, as |
4b7c96fba3d8
8037968: Add tests on alignment of objects copied to survivor space
fzhinkin
parents:
diff
changeset
|
7 * published by the Free Software Foundation. |
4b7c96fba3d8
8037968: Add tests on alignment of objects copied to survivor space
fzhinkin
parents:
diff
changeset
|
8 * |
4b7c96fba3d8
8037968: Add tests on alignment of objects copied to survivor space
fzhinkin
parents:
diff
changeset
|
9 * This code is distributed in the hope that it will be useful, but WITHOUT |
4b7c96fba3d8
8037968: Add tests on alignment of objects copied to survivor space
fzhinkin
parents:
diff
changeset
|
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
4b7c96fba3d8
8037968: Add tests on alignment of objects copied to survivor space
fzhinkin
parents:
diff
changeset
|
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
4b7c96fba3d8
8037968: Add tests on alignment of objects copied to survivor space
fzhinkin
parents:
diff
changeset
|
12 * version 2 for more details (a copy is included in the LICENSE file that |
4b7c96fba3d8
8037968: Add tests on alignment of objects copied to survivor space
fzhinkin
parents:
diff
changeset
|
13 * accompanied this code). |
4b7c96fba3d8
8037968: Add tests on alignment of objects copied to survivor space
fzhinkin
parents:
diff
changeset
|
14 * |
4b7c96fba3d8
8037968: Add tests on alignment of objects copied to survivor space
fzhinkin
parents:
diff
changeset
|
15 * You should have received a copy of the GNU General Public License version |
4b7c96fba3d8
8037968: Add tests on alignment of objects copied to survivor space
fzhinkin
parents:
diff
changeset
|
16 * 2 along with this work; if not, write to the Free Software Foundation, |
4b7c96fba3d8
8037968: Add tests on alignment of objects copied to survivor space
fzhinkin
parents:
diff
changeset
|
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
4b7c96fba3d8
8037968: Add tests on alignment of objects copied to survivor space
fzhinkin
parents:
diff
changeset
|
18 * |
4b7c96fba3d8
8037968: Add tests on alignment of objects copied to survivor space
fzhinkin
parents:
diff
changeset
|
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
4b7c96fba3d8
8037968: Add tests on alignment of objects copied to survivor space
fzhinkin
parents:
diff
changeset
|
20 * or visit www.oracle.com if you need additional information or have any |
4b7c96fba3d8
8037968: Add tests on alignment of objects copied to survivor space
fzhinkin
parents:
diff
changeset
|
21 * questions. |
4b7c96fba3d8
8037968: Add tests on alignment of objects copied to survivor space
fzhinkin
parents:
diff
changeset
|
22 */ |
4b7c96fba3d8
8037968: Add tests on alignment of objects copied to survivor space
fzhinkin
parents:
diff
changeset
|
23 |
4b7c96fba3d8
8037968: Add tests on alignment of objects copied to survivor space
fzhinkin
parents:
diff
changeset
|
24 import java.lang.management.ManagementFactory; |
4b7c96fba3d8
8037968: Add tests on alignment of objects copied to survivor space
fzhinkin
parents:
diff
changeset
|
25 import java.lang.management.MemoryPoolMXBean; |
4b7c96fba3d8
8037968: Add tests on alignment of objects copied to survivor space
fzhinkin
parents:
diff
changeset
|
26 import java.util.Objects; |
4b7c96fba3d8
8037968: Add tests on alignment of objects copied to survivor space
fzhinkin
parents:
diff
changeset
|
27 import java.util.Optional; |
4b7c96fba3d8
8037968: Add tests on alignment of objects copied to survivor space
fzhinkin
parents:
diff
changeset
|
28 import java.util.regex.Matcher; |
4b7c96fba3d8
8037968: Add tests on alignment of objects copied to survivor space
fzhinkin
parents:
diff
changeset
|
29 import java.util.regex.Pattern; |
4b7c96fba3d8
8037968: Add tests on alignment of objects copied to survivor space
fzhinkin
parents:
diff
changeset
|
30 |
4b7c96fba3d8
8037968: Add tests on alignment of objects copied to survivor space
fzhinkin
parents:
diff
changeset
|
31 import com.oracle.java.testlibrary.Asserts; |
4b7c96fba3d8
8037968: Add tests on alignment of objects copied to survivor space
fzhinkin
parents:
diff
changeset
|
32 import com.sun.management.ThreadMXBean; |
4b7c96fba3d8
8037968: Add tests on alignment of objects copied to survivor space
fzhinkin
parents:
diff
changeset
|
33 import sun.hotspot.WhiteBox; |
4b7c96fba3d8
8037968: Add tests on alignment of objects copied to survivor space
fzhinkin
parents:
diff
changeset
|
34 import sun.misc.Unsafe; |
4b7c96fba3d8
8037968: Add tests on alignment of objects copied to survivor space
fzhinkin
parents:
diff
changeset
|
35 |
4b7c96fba3d8
8037968: Add tests on alignment of objects copied to survivor space
fzhinkin
parents:
diff
changeset
|
36 /** |
4b7c96fba3d8
8037968: Add tests on alignment of objects copied to survivor space
fzhinkin
parents:
diff
changeset
|
37 * Main class for tests on {@code SurvivorAlignmentInBytes} option. |
4b7c96fba3d8
8037968: Add tests on alignment of objects copied to survivor space
fzhinkin
parents:
diff
changeset
|
38 * |
4b7c96fba3d8
8037968: Add tests on alignment of objects copied to survivor space
fzhinkin
parents:
diff
changeset
|
39 * Typical usage is to obtain instance using fromArgs method, allocate objects |
4b7c96fba3d8
8037968: Add tests on alignment of objects copied to survivor space
fzhinkin
parents:
diff
changeset
|
40 * and verify that actual memory usage in tested heap space is close to |
4b7c96fba3d8
8037968: Add tests on alignment of objects copied to survivor space
fzhinkin
parents:
diff
changeset
|
41 * expected. |
4b7c96fba3d8
8037968: Add tests on alignment of objects copied to survivor space
fzhinkin
parents:
diff
changeset
|
42 */ |
4b7c96fba3d8
8037968: Add tests on alignment of objects copied to survivor space
fzhinkin
parents:
diff
changeset
|
43 public class SurvivorAlignmentTestMain { |
4b7c96fba3d8
8037968: Add tests on alignment of objects copied to survivor space
fzhinkin
parents:
diff
changeset
|
44 enum HeapSpace { |
4b7c96fba3d8
8037968: Add tests on alignment of objects copied to survivor space
fzhinkin
parents:
diff
changeset
|
45 EDEN, |
4b7c96fba3d8
8037968: Add tests on alignment of objects copied to survivor space
fzhinkin
parents:
diff
changeset
|
46 SURVIVOR, |
4b7c96fba3d8
8037968: Add tests on alignment of objects copied to survivor space
fzhinkin
parents:
diff
changeset
|
47 TENURED |
4b7c96fba3d8
8037968: Add tests on alignment of objects copied to survivor space
fzhinkin
parents:
diff
changeset
|
48 } |
4b7c96fba3d8
8037968: Add tests on alignment of objects copied to survivor space
fzhinkin
parents:
diff
changeset
|
49 |
4b7c96fba3d8
8037968: Add tests on alignment of objects copied to survivor space
fzhinkin
parents:
diff
changeset
|
50 public static final WhiteBox WHITE_BOX = WhiteBox.getWhiteBox(); |
4b7c96fba3d8
8037968: Add tests on alignment of objects copied to survivor space
fzhinkin
parents:
diff
changeset
|
51 |
4b7c96fba3d8
8037968: Add tests on alignment of objects copied to survivor space
fzhinkin
parents:
diff
changeset
|
52 public static final long MAX_TENURING_THRESHOLD = Optional.ofNullable( |
4b7c96fba3d8
8037968: Add tests on alignment of objects copied to survivor space
fzhinkin
parents:
diff
changeset
|
53 SurvivorAlignmentTestMain.WHITE_BOX.getIntxVMFlag( |
4b7c96fba3d8
8037968: Add tests on alignment of objects copied to survivor space
fzhinkin
parents:
diff
changeset
|
54 "MaxTenuringThreshold")).orElse(15L); |
4b7c96fba3d8
8037968: Add tests on alignment of objects copied to survivor space
fzhinkin
parents:
diff
changeset
|
55 |
4b7c96fba3d8
8037968: Add tests on alignment of objects copied to survivor space
fzhinkin
parents:
diff
changeset
|
56 /** |
4b7c96fba3d8
8037968: Add tests on alignment of objects copied to survivor space
fzhinkin
parents:
diff
changeset
|
57 * Regexp used to parse memory size params, like 2G, 34m or 15k. |
4b7c96fba3d8
8037968: Add tests on alignment of objects copied to survivor space
fzhinkin
parents:
diff
changeset
|
58 */ |
4b7c96fba3d8
8037968: Add tests on alignment of objects copied to survivor space
fzhinkin
parents:
diff
changeset
|
59 private static final Pattern SIZE_REGEX |
4b7c96fba3d8
8037968: Add tests on alignment of objects copied to survivor space
fzhinkin
parents:
diff
changeset
|
60 = Pattern.compile("(?<size>[0-9]+)(?<multiplier>[GMKgmk])?"); |
4b7c96fba3d8
8037968: Add tests on alignment of objects copied to survivor space
fzhinkin
parents:
diff
changeset
|
61 |
4b7c96fba3d8
8037968: Add tests on alignment of objects copied to survivor space
fzhinkin
parents:
diff
changeset
|
62 // Names of different heap spaces. |
4b7c96fba3d8
8037968: Add tests on alignment of objects copied to survivor space
fzhinkin
parents:
diff
changeset
|
63 private static final String DEF_NEW_EDEN = "Eden Space"; |
4b7c96fba3d8
8037968: Add tests on alignment of objects copied to survivor space
fzhinkin
parents:
diff
changeset
|
64 private static final String DEF_NEW_SURVIVOR = "Survivor Space"; |
4b7c96fba3d8
8037968: Add tests on alignment of objects copied to survivor space
fzhinkin
parents:
diff
changeset
|
65 private static final String PAR_NEW_EDEN = "Par Eden Space"; |
4b7c96fba3d8
8037968: Add tests on alignment of objects copied to survivor space
fzhinkin
parents:
diff
changeset
|
66 private static final String PAR_NEW_SURVIVOR = "Par Survivor Space"; |
4b7c96fba3d8
8037968: Add tests on alignment of objects copied to survivor space
fzhinkin
parents:
diff
changeset
|
67 private static final String PS_EDEN = "PS Eden Space"; |
4b7c96fba3d8
8037968: Add tests on alignment of objects copied to survivor space
fzhinkin
parents:
diff
changeset
|
68 private static final String PS_SURVIVOR = "PS Survivor Space"; |
4b7c96fba3d8
8037968: Add tests on alignment of objects copied to survivor space
fzhinkin
parents:
diff
changeset
|
69 private static final String G1_EDEN = "G1 Eden Space"; |
4b7c96fba3d8
8037968: Add tests on alignment of objects copied to survivor space
fzhinkin
parents:
diff
changeset
|
70 private static final String G1_SURVIVOR = "G1 Survivor Space"; |
4b7c96fba3d8
8037968: Add tests on alignment of objects copied to survivor space
fzhinkin
parents:
diff
changeset
|
71 private static final String SERIAL_TENURED = "Tenured Gen"; |
4b7c96fba3d8
8037968: Add tests on alignment of objects copied to survivor space
fzhinkin
parents:
diff
changeset
|
72 private static final String CMS_TENURED = "CMS Old Gen"; |
4b7c96fba3d8
8037968: Add tests on alignment of objects copied to survivor space
fzhinkin
parents:
diff
changeset
|
73 private static final String PS_TENURED = "PS Old Gen"; |
4b7c96fba3d8
8037968: Add tests on alignment of objects copied to survivor space
fzhinkin
parents:
diff
changeset
|
74 private static final String G1_TENURED = "G1 Old Gen"; |
4b7c96fba3d8
8037968: Add tests on alignment of objects copied to survivor space
fzhinkin
parents:
diff
changeset
|
75 |
4b7c96fba3d8
8037968: Add tests on alignment of objects copied to survivor space
fzhinkin
parents:
diff
changeset
|
76 private static final long G1_HEAP_REGION_SIZE = Optional.ofNullable( |
4b7c96fba3d8
8037968: Add tests on alignment of objects copied to survivor space
fzhinkin
parents:
diff
changeset
|
77 SurvivorAlignmentTestMain.WHITE_BOX.getUintxVMFlag( |
4b7c96fba3d8
8037968: Add tests on alignment of objects copied to survivor space
fzhinkin
parents:
diff
changeset
|
78 "G1HeapRegionSize")).orElse(-1L); |
4b7c96fba3d8
8037968: Add tests on alignment of objects copied to survivor space
fzhinkin
parents:
diff
changeset
|
79 |
4b7c96fba3d8
8037968: Add tests on alignment of objects copied to survivor space
fzhinkin
parents:
diff
changeset
|
80 /** |
4b7c96fba3d8
8037968: Add tests on alignment of objects copied to survivor space
fzhinkin
parents:
diff
changeset
|
81 * Min size of free chunk in CMS generation. |
4b7c96fba3d8
8037968: Add tests on alignment of objects copied to survivor space
fzhinkin
parents:
diff
changeset
|
82 * An object allocated in CMS generation will at least occupy this amount |
4b7c96fba3d8
8037968: Add tests on alignment of objects copied to survivor space
fzhinkin
parents:
diff
changeset
|
83 * of bytes. |
4b7c96fba3d8
8037968: Add tests on alignment of objects copied to survivor space
fzhinkin
parents:
diff
changeset
|
84 */ |
4b7c96fba3d8
8037968: Add tests on alignment of objects copied to survivor space
fzhinkin
parents:
diff
changeset
|
85 private static final long CMS_MIN_FREE_CHUNK_SIZE |
4b7c96fba3d8
8037968: Add tests on alignment of objects copied to survivor space
fzhinkin
parents:
diff
changeset
|
86 = 3L * Unsafe.ADDRESS_SIZE; |
4b7c96fba3d8
8037968: Add tests on alignment of objects copied to survivor space
fzhinkin
parents:
diff
changeset
|
87 |
4b7c96fba3d8
8037968: Add tests on alignment of objects copied to survivor space
fzhinkin
parents:
diff
changeset
|
88 private static final AlignmentHelper EDEN_SPACE_HELPER; |
4b7c96fba3d8
8037968: Add tests on alignment of objects copied to survivor space
fzhinkin
parents:
diff
changeset
|
89 private static final AlignmentHelper SURVIVOR_SPACE_HELPER; |
4b7c96fba3d8
8037968: Add tests on alignment of objects copied to survivor space
fzhinkin
parents:
diff
changeset
|
90 private static final AlignmentHelper TENURED_SPACE_HELPER; |
4b7c96fba3d8
8037968: Add tests on alignment of objects copied to survivor space
fzhinkin
parents:
diff
changeset
|
91 /** |
4b7c96fba3d8
8037968: Add tests on alignment of objects copied to survivor space
fzhinkin
parents:
diff
changeset
|
92 * Amount of memory that should be filled during a test run. |
4b7c96fba3d8
8037968: Add tests on alignment of objects copied to survivor space
fzhinkin
parents:
diff
changeset
|
93 */ |
4b7c96fba3d8
8037968: Add tests on alignment of objects copied to survivor space
fzhinkin
parents:
diff
changeset
|
94 private final long memoryToFill; |
4b7c96fba3d8
8037968: Add tests on alignment of objects copied to survivor space
fzhinkin
parents:
diff
changeset
|
95 /** |
4b7c96fba3d8
8037968: Add tests on alignment of objects copied to survivor space
fzhinkin
parents:
diff
changeset
|
96 * The size of an objects that will be allocated during a test run. |
4b7c96fba3d8
8037968: Add tests on alignment of objects copied to survivor space
fzhinkin
parents:
diff
changeset
|
97 */ |
4b7c96fba3d8
8037968: Add tests on alignment of objects copied to survivor space
fzhinkin
parents:
diff
changeset
|
98 private final long objectSize; |
4b7c96fba3d8
8037968: Add tests on alignment of objects copied to survivor space
fzhinkin
parents:
diff
changeset
|
99 /** |
4b7c96fba3d8
8037968: Add tests on alignment of objects copied to survivor space
fzhinkin
parents:
diff
changeset
|
100 * Amount of memory that will be actually occupied by an object in eden |
4b7c96fba3d8
8037968: Add tests on alignment of objects copied to survivor space
fzhinkin
parents:
diff
changeset
|
101 * space. |
4b7c96fba3d8
8037968: Add tests on alignment of objects copied to survivor space
fzhinkin
parents:
diff
changeset
|
102 */ |
4b7c96fba3d8
8037968: Add tests on alignment of objects copied to survivor space
fzhinkin
parents:
diff
changeset
|
103 private final long actualObjectSize; |
4b7c96fba3d8
8037968: Add tests on alignment of objects copied to survivor space
fzhinkin
parents:
diff
changeset
|
104 /** |
4b7c96fba3d8
8037968: Add tests on alignment of objects copied to survivor space
fzhinkin
parents:
diff
changeset
|
105 * Storage for allocated objects. |
4b7c96fba3d8
8037968: Add tests on alignment of objects copied to survivor space
fzhinkin
parents:
diff
changeset
|
106 */ |
4b7c96fba3d8
8037968: Add tests on alignment of objects copied to survivor space
fzhinkin
parents:
diff
changeset
|
107 private final Object[] garbage; |
4b7c96fba3d8
8037968: Add tests on alignment of objects copied to survivor space
fzhinkin
parents:
diff
changeset
|
108 /** |
4b7c96fba3d8
8037968: Add tests on alignment of objects copied to survivor space
fzhinkin
parents:
diff
changeset
|
109 * Heap space whose memory usage is a subject of assertions during the test |
4b7c96fba3d8
8037968: Add tests on alignment of objects copied to survivor space
fzhinkin
parents:
diff
changeset
|
110 * run. |
4b7c96fba3d8
8037968: Add tests on alignment of objects copied to survivor space
fzhinkin
parents:
diff
changeset
|
111 */ |
4b7c96fba3d8
8037968: Add tests on alignment of objects copied to survivor space
fzhinkin
parents:
diff
changeset
|
112 private final HeapSpace testedSpace; |
4b7c96fba3d8
8037968: Add tests on alignment of objects copied to survivor space
fzhinkin
parents:
diff
changeset
|
113 |
4b7c96fba3d8
8037968: Add tests on alignment of objects copied to survivor space
fzhinkin
parents:
diff
changeset
|
114 private long[] baselinedThreadMemoryUsage = null; |
4b7c96fba3d8
8037968: Add tests on alignment of objects copied to survivor space
fzhinkin
parents:
diff
changeset
|
115 private long[] threadIds = null; |
4b7c96fba3d8
8037968: Add tests on alignment of objects copied to survivor space
fzhinkin
parents:
diff
changeset
|
116 |
4b7c96fba3d8
8037968: Add tests on alignment of objects copied to survivor space
fzhinkin
parents:
diff
changeset
|
117 /** |
4b7c96fba3d8
8037968: Add tests on alignment of objects copied to survivor space
fzhinkin
parents:
diff
changeset
|
118 * Initialize {@code EDEN_SPACE_HELPER}, {@code SURVIVOR_SPACE_HELPER} and |
4b7c96fba3d8
8037968: Add tests on alignment of objects copied to survivor space
fzhinkin
parents:
diff
changeset
|
119 * {@code TENURED_SPACE_HELPER} to represent heap spaces in use. |
4b7c96fba3d8
8037968: Add tests on alignment of objects copied to survivor space
fzhinkin
parents:
diff
changeset
|
120 * |
4b7c96fba3d8
8037968: Add tests on alignment of objects copied to survivor space
fzhinkin
parents:
diff
changeset
|
121 * Note that regardless to GC object's alignment in survivor space is |
4b7c96fba3d8
8037968: Add tests on alignment of objects copied to survivor space
fzhinkin
parents:
diff
changeset
|
122 * expected to be equal to {@code SurvivorAlignmentInBytes} value and |
4b7c96fba3d8
8037968: Add tests on alignment of objects copied to survivor space
fzhinkin
parents:
diff
changeset
|
123 * alignment in other spaces is expected to be equal to |
4b7c96fba3d8
8037968: Add tests on alignment of objects copied to survivor space
fzhinkin
parents:
diff
changeset
|
124 * {@code ObjectAlignmentInBytes} value. |
4b7c96fba3d8
8037968: Add tests on alignment of objects copied to survivor space
fzhinkin
parents:
diff
changeset
|
125 * |
4b7c96fba3d8
8037968: Add tests on alignment of objects copied to survivor space
fzhinkin
parents:
diff
changeset
|
126 * In CMS generation we can't allocate less then {@code MinFreeChunk} value, |
4b7c96fba3d8
8037968: Add tests on alignment of objects copied to survivor space
fzhinkin
parents:
diff
changeset
|
127 * for other CGs we expect that object of size {@code MIN_OBJECT_SIZE} |
4b7c96fba3d8
8037968: Add tests on alignment of objects copied to survivor space
fzhinkin
parents:
diff
changeset
|
128 * could be allocated as it is (of course, its size could be aligned |
4b7c96fba3d8
8037968: Add tests on alignment of objects copied to survivor space
fzhinkin
parents:
diff
changeset
|
129 * according to alignment value used in a particular space). |
4b7c96fba3d8
8037968: Add tests on alignment of objects copied to survivor space
fzhinkin
parents:
diff
changeset
|
130 * |
4b7c96fba3d8
8037968: Add tests on alignment of objects copied to survivor space
fzhinkin
parents:
diff
changeset
|
131 * For G1 GC MXBeans could report memory usage only with region size |
4b7c96fba3d8
8037968: Add tests on alignment of objects copied to survivor space
fzhinkin
parents:
diff
changeset
|
132 * precision (if an object allocated in some G1 heap region, then all region |
4b7c96fba3d8
8037968: Add tests on alignment of objects copied to survivor space
fzhinkin
parents:
diff
changeset
|
133 * will claimed as used), so for G1's spaces precision is equal to |
4b7c96fba3d8
8037968: Add tests on alignment of objects copied to survivor space
fzhinkin
parents:
diff
changeset
|
134 * {@code G1HeapRegionSize} value. |
4b7c96fba3d8
8037968: Add tests on alignment of objects copied to survivor space
fzhinkin
parents:
diff
changeset
|
135 */ |
4b7c96fba3d8
8037968: Add tests on alignment of objects copied to survivor space
fzhinkin
parents:
diff
changeset
|
136 static { |
4b7c96fba3d8
8037968: Add tests on alignment of objects copied to survivor space
fzhinkin
parents:
diff
changeset
|
137 AlignmentHelper edenHelper = null; |
4b7c96fba3d8
8037968: Add tests on alignment of objects copied to survivor space
fzhinkin
parents:
diff
changeset
|
138 AlignmentHelper survivorHelper = null; |
4b7c96fba3d8
8037968: Add tests on alignment of objects copied to survivor space
fzhinkin
parents:
diff
changeset
|
139 AlignmentHelper tenuredHelper = null; |
4b7c96fba3d8
8037968: Add tests on alignment of objects copied to survivor space
fzhinkin
parents:
diff
changeset
|
140 for (MemoryPoolMXBean pool : ManagementFactory.getMemoryPoolMXBeans()) { |
4b7c96fba3d8
8037968: Add tests on alignment of objects copied to survivor space
fzhinkin
parents:
diff
changeset
|
141 switch (pool.getName()) { |
4b7c96fba3d8
8037968: Add tests on alignment of objects copied to survivor space
fzhinkin
parents:
diff
changeset
|
142 case SurvivorAlignmentTestMain.DEF_NEW_EDEN: |
4b7c96fba3d8
8037968: Add tests on alignment of objects copied to survivor space
fzhinkin
parents:
diff
changeset
|
143 case SurvivorAlignmentTestMain.PAR_NEW_EDEN: |
4b7c96fba3d8
8037968: Add tests on alignment of objects copied to survivor space
fzhinkin
parents:
diff
changeset
|
144 case SurvivorAlignmentTestMain.PS_EDEN: |
4b7c96fba3d8
8037968: Add tests on alignment of objects copied to survivor space
fzhinkin
parents:
diff
changeset
|
145 Asserts.assertNull(edenHelper, |
4b7c96fba3d8
8037968: Add tests on alignment of objects copied to survivor space
fzhinkin
parents:
diff
changeset
|
146 "Only one bean for eden space is expected."); |
4b7c96fba3d8
8037968: Add tests on alignment of objects copied to survivor space
fzhinkin
parents:
diff
changeset
|
147 edenHelper = new AlignmentHelper( |
4b7c96fba3d8
8037968: Add tests on alignment of objects copied to survivor space
fzhinkin
parents:
diff
changeset
|
148 AlignmentHelper.OBJECT_ALIGNMENT_IN_BYTES, |
4b7c96fba3d8
8037968: Add tests on alignment of objects copied to survivor space
fzhinkin
parents:
diff
changeset
|
149 AlignmentHelper.OBJECT_ALIGNMENT_IN_BYTES, |
4b7c96fba3d8
8037968: Add tests on alignment of objects copied to survivor space
fzhinkin
parents:
diff
changeset
|
150 AlignmentHelper.MIN_OBJECT_SIZE, pool); |
4b7c96fba3d8
8037968: Add tests on alignment of objects copied to survivor space
fzhinkin
parents:
diff
changeset
|
151 break; |
4b7c96fba3d8
8037968: Add tests on alignment of objects copied to survivor space
fzhinkin
parents:
diff
changeset
|
152 case SurvivorAlignmentTestMain.G1_EDEN: |
4b7c96fba3d8
8037968: Add tests on alignment of objects copied to survivor space
fzhinkin
parents:
diff
changeset
|
153 Asserts.assertNull(edenHelper, |
4b7c96fba3d8
8037968: Add tests on alignment of objects copied to survivor space
fzhinkin
parents:
diff
changeset
|
154 "Only one bean for eden space is expected."); |
4b7c96fba3d8
8037968: Add tests on alignment of objects copied to survivor space
fzhinkin
parents:
diff
changeset
|
155 edenHelper = new AlignmentHelper( |
4b7c96fba3d8
8037968: Add tests on alignment of objects copied to survivor space
fzhinkin
parents:
diff
changeset
|
156 SurvivorAlignmentTestMain.G1_HEAP_REGION_SIZE, |
4b7c96fba3d8
8037968: Add tests on alignment of objects copied to survivor space
fzhinkin
parents:
diff
changeset
|
157 AlignmentHelper.OBJECT_ALIGNMENT_IN_BYTES, |
4b7c96fba3d8
8037968: Add tests on alignment of objects copied to survivor space
fzhinkin
parents:
diff
changeset
|
158 AlignmentHelper.MIN_OBJECT_SIZE, pool); |
4b7c96fba3d8
8037968: Add tests on alignment of objects copied to survivor space
fzhinkin
parents:
diff
changeset
|
159 break; |
4b7c96fba3d8
8037968: Add tests on alignment of objects copied to survivor space
fzhinkin
parents:
diff
changeset
|
160 case SurvivorAlignmentTestMain.DEF_NEW_SURVIVOR: |
4b7c96fba3d8
8037968: Add tests on alignment of objects copied to survivor space
fzhinkin
parents:
diff
changeset
|
161 case SurvivorAlignmentTestMain.PAR_NEW_SURVIVOR: |
4b7c96fba3d8
8037968: Add tests on alignment of objects copied to survivor space
fzhinkin
parents:
diff
changeset
|
162 case SurvivorAlignmentTestMain.PS_SURVIVOR: |
4b7c96fba3d8
8037968: Add tests on alignment of objects copied to survivor space
fzhinkin
parents:
diff
changeset
|
163 Asserts.assertNull(survivorHelper, |
4b7c96fba3d8
8037968: Add tests on alignment of objects copied to survivor space
fzhinkin
parents:
diff
changeset
|
164 "Only one bean for survivor space is expected."); |
4b7c96fba3d8
8037968: Add tests on alignment of objects copied to survivor space
fzhinkin
parents:
diff
changeset
|
165 survivorHelper = new AlignmentHelper( |
4b7c96fba3d8
8037968: Add tests on alignment of objects copied to survivor space
fzhinkin
parents:
diff
changeset
|
166 AlignmentHelper.OBJECT_ALIGNMENT_IN_BYTES, |
4b7c96fba3d8
8037968: Add tests on alignment of objects copied to survivor space
fzhinkin
parents:
diff
changeset
|
167 AlignmentHelper.SURVIVOR_ALIGNMENT_IN_BYTES, |
4b7c96fba3d8
8037968: Add tests on alignment of objects copied to survivor space
fzhinkin
parents:
diff
changeset
|
168 AlignmentHelper.MIN_OBJECT_SIZE, pool); |
4b7c96fba3d8
8037968: Add tests on alignment of objects copied to survivor space
fzhinkin
parents:
diff
changeset
|
169 break; |
4b7c96fba3d8
8037968: Add tests on alignment of objects copied to survivor space
fzhinkin
parents:
diff
changeset
|
170 case SurvivorAlignmentTestMain.G1_SURVIVOR: |
4b7c96fba3d8
8037968: Add tests on alignment of objects copied to survivor space
fzhinkin
parents:
diff
changeset
|
171 Asserts.assertNull(survivorHelper, |
4b7c96fba3d8
8037968: Add tests on alignment of objects copied to survivor space
fzhinkin
parents:
diff
changeset
|
172 "Only one bean for survivor space is expected."); |
4b7c96fba3d8
8037968: Add tests on alignment of objects copied to survivor space
fzhinkin
parents:
diff
changeset
|
173 survivorHelper = new AlignmentHelper( |
4b7c96fba3d8
8037968: Add tests on alignment of objects copied to survivor space
fzhinkin
parents:
diff
changeset
|
174 SurvivorAlignmentTestMain.G1_HEAP_REGION_SIZE, |
4b7c96fba3d8
8037968: Add tests on alignment of objects copied to survivor space
fzhinkin
parents:
diff
changeset
|
175 AlignmentHelper.SURVIVOR_ALIGNMENT_IN_BYTES, |
4b7c96fba3d8
8037968: Add tests on alignment of objects copied to survivor space
fzhinkin
parents:
diff
changeset
|
176 AlignmentHelper.MIN_OBJECT_SIZE, pool); |
4b7c96fba3d8
8037968: Add tests on alignment of objects copied to survivor space
fzhinkin
parents:
diff
changeset
|
177 break; |
4b7c96fba3d8
8037968: Add tests on alignment of objects copied to survivor space
fzhinkin
parents:
diff
changeset
|
178 case SurvivorAlignmentTestMain.SERIAL_TENURED: |
4b7c96fba3d8
8037968: Add tests on alignment of objects copied to survivor space
fzhinkin
parents:
diff
changeset
|
179 case SurvivorAlignmentTestMain.PS_TENURED: |
4b7c96fba3d8
8037968: Add tests on alignment of objects copied to survivor space
fzhinkin
parents:
diff
changeset
|
180 case SurvivorAlignmentTestMain.G1_TENURED: |
4b7c96fba3d8
8037968: Add tests on alignment of objects copied to survivor space
fzhinkin
parents:
diff
changeset
|
181 Asserts.assertNull(tenuredHelper, |
4b7c96fba3d8
8037968: Add tests on alignment of objects copied to survivor space
fzhinkin
parents:
diff
changeset
|
182 "Only one bean for tenured space is expected."); |
4b7c96fba3d8
8037968: Add tests on alignment of objects copied to survivor space
fzhinkin
parents:
diff
changeset
|
183 tenuredHelper = new AlignmentHelper( |
4b7c96fba3d8
8037968: Add tests on alignment of objects copied to survivor space
fzhinkin
parents:
diff
changeset
|
184 AlignmentHelper.OBJECT_ALIGNMENT_IN_BYTES, |
4b7c96fba3d8
8037968: Add tests on alignment of objects copied to survivor space
fzhinkin
parents:
diff
changeset
|
185 AlignmentHelper.OBJECT_ALIGNMENT_IN_BYTES, |
4b7c96fba3d8
8037968: Add tests on alignment of objects copied to survivor space
fzhinkin
parents:
diff
changeset
|
186 AlignmentHelper.MIN_OBJECT_SIZE, pool); |
4b7c96fba3d8
8037968: Add tests on alignment of objects copied to survivor space
fzhinkin
parents:
diff
changeset
|
187 break; |
4b7c96fba3d8
8037968: Add tests on alignment of objects copied to survivor space
fzhinkin
parents:
diff
changeset
|
188 case SurvivorAlignmentTestMain.CMS_TENURED: |
4b7c96fba3d8
8037968: Add tests on alignment of objects copied to survivor space
fzhinkin
parents:
diff
changeset
|
189 Asserts.assertNull(tenuredHelper, |
4b7c96fba3d8
8037968: Add tests on alignment of objects copied to survivor space
fzhinkin
parents:
diff
changeset
|
190 "Only one bean for tenured space is expected."); |
4b7c96fba3d8
8037968: Add tests on alignment of objects copied to survivor space
fzhinkin
parents:
diff
changeset
|
191 tenuredHelper = new AlignmentHelper( |
4b7c96fba3d8
8037968: Add tests on alignment of objects copied to survivor space
fzhinkin
parents:
diff
changeset
|
192 AlignmentHelper.OBJECT_ALIGNMENT_IN_BYTES, |
4b7c96fba3d8
8037968: Add tests on alignment of objects copied to survivor space
fzhinkin
parents:
diff
changeset
|
193 AlignmentHelper.OBJECT_ALIGNMENT_IN_BYTES, |
4b7c96fba3d8
8037968: Add tests on alignment of objects copied to survivor space
fzhinkin
parents:
diff
changeset
|
194 SurvivorAlignmentTestMain.CMS_MIN_FREE_CHUNK_SIZE, |
4b7c96fba3d8
8037968: Add tests on alignment of objects copied to survivor space
fzhinkin
parents:
diff
changeset
|
195 pool); |
4b7c96fba3d8
8037968: Add tests on alignment of objects copied to survivor space
fzhinkin
parents:
diff
changeset
|
196 break; |
4b7c96fba3d8
8037968: Add tests on alignment of objects copied to survivor space
fzhinkin
parents:
diff
changeset
|
197 } |
4b7c96fba3d8
8037968: Add tests on alignment of objects copied to survivor space
fzhinkin
parents:
diff
changeset
|
198 } |
4b7c96fba3d8
8037968: Add tests on alignment of objects copied to survivor space
fzhinkin
parents:
diff
changeset
|
199 EDEN_SPACE_HELPER = Objects.requireNonNull(edenHelper, |
4b7c96fba3d8
8037968: Add tests on alignment of objects copied to survivor space
fzhinkin
parents:
diff
changeset
|
200 "AlignmentHelper for eden space should be initialized."); |
4b7c96fba3d8
8037968: Add tests on alignment of objects copied to survivor space
fzhinkin
parents:
diff
changeset
|
201 SURVIVOR_SPACE_HELPER = Objects.requireNonNull(survivorHelper, |
4b7c96fba3d8
8037968: Add tests on alignment of objects copied to survivor space
fzhinkin
parents:
diff
changeset
|
202 "AlignmentHelper for survivor space should be initialized."); |
4b7c96fba3d8
8037968: Add tests on alignment of objects copied to survivor space
fzhinkin
parents:
diff
changeset
|
203 TENURED_SPACE_HELPER = Objects.requireNonNull(tenuredHelper, |
4b7c96fba3d8
8037968: Add tests on alignment of objects copied to survivor space
fzhinkin
parents:
diff
changeset
|
204 "AlignmentHelper for tenured space should be initialized."); |
4b7c96fba3d8
8037968: Add tests on alignment of objects copied to survivor space
fzhinkin
parents:
diff
changeset
|
205 } |
4b7c96fba3d8
8037968: Add tests on alignment of objects copied to survivor space
fzhinkin
parents:
diff
changeset
|
206 /** |
4b7c96fba3d8
8037968: Add tests on alignment of objects copied to survivor space
fzhinkin
parents:
diff
changeset
|
207 * Returns an SurvivorAlignmentTestMain instance constructed using CLI |
4b7c96fba3d8
8037968: Add tests on alignment of objects copied to survivor space
fzhinkin
parents:
diff
changeset
|
208 * options. |
4b7c96fba3d8
8037968: Add tests on alignment of objects copied to survivor space
fzhinkin
parents:
diff
changeset
|
209 * |
4b7c96fba3d8
8037968: Add tests on alignment of objects copied to survivor space
fzhinkin
parents:
diff
changeset
|
210 * Following options are expected: |
4b7c96fba3d8
8037968: Add tests on alignment of objects copied to survivor space
fzhinkin
parents:
diff
changeset
|
211 * <ul> |
4b7c96fba3d8
8037968: Add tests on alignment of objects copied to survivor space
fzhinkin
parents:
diff
changeset
|
212 * <li>memoryToFill</li> |
4b7c96fba3d8
8037968: Add tests on alignment of objects copied to survivor space
fzhinkin
parents:
diff
changeset
|
213 * <li>objectSize</li> |
4b7c96fba3d8
8037968: Add tests on alignment of objects copied to survivor space
fzhinkin
parents:
diff
changeset
|
214 * </ul> |
4b7c96fba3d8
8037968: Add tests on alignment of objects copied to survivor space
fzhinkin
parents:
diff
changeset
|
215 * |
4b7c96fba3d8
8037968: Add tests on alignment of objects copied to survivor space
fzhinkin
parents:
diff
changeset
|
216 * Both argument may contain multiplier suffix k, m or g. |
4b7c96fba3d8
8037968: Add tests on alignment of objects copied to survivor space
fzhinkin
parents:
diff
changeset
|
217 */ |
4b7c96fba3d8
8037968: Add tests on alignment of objects copied to survivor space
fzhinkin
parents:
diff
changeset
|
218 public static SurvivorAlignmentTestMain fromArgs(String[] args) { |
4b7c96fba3d8
8037968: Add tests on alignment of objects copied to survivor space
fzhinkin
parents:
diff
changeset
|
219 Asserts.assertEQ(args.length, 3, "Expected three arguments: " |
4b7c96fba3d8
8037968: Add tests on alignment of objects copied to survivor space
fzhinkin
parents:
diff
changeset
|
220 + "memory size, object size and tested heap space name."); |
4b7c96fba3d8
8037968: Add tests on alignment of objects copied to survivor space
fzhinkin
parents:
diff
changeset
|
221 |
4b7c96fba3d8
8037968: Add tests on alignment of objects copied to survivor space
fzhinkin
parents:
diff
changeset
|
222 long memoryToFill = parseSize(args[0]); |
4b7c96fba3d8
8037968: Add tests on alignment of objects copied to survivor space
fzhinkin
parents:
diff
changeset
|
223 long objectSize = Math.max(parseSize(args[1]), |
4b7c96fba3d8
8037968: Add tests on alignment of objects copied to survivor space
fzhinkin
parents:
diff
changeset
|
224 AlignmentHelper.MIN_ARRAY_SIZE); |
4b7c96fba3d8
8037968: Add tests on alignment of objects copied to survivor space
fzhinkin
parents:
diff
changeset
|
225 HeapSpace testedSpace = HeapSpace.valueOf(args[2]); |
4b7c96fba3d8
8037968: Add tests on alignment of objects copied to survivor space
fzhinkin
parents:
diff
changeset
|
226 |
4b7c96fba3d8
8037968: Add tests on alignment of objects copied to survivor space
fzhinkin
parents:
diff
changeset
|
227 return new SurvivorAlignmentTestMain(memoryToFill, objectSize, |
4b7c96fba3d8
8037968: Add tests on alignment of objects copied to survivor space
fzhinkin
parents:
diff
changeset
|
228 testedSpace); |
4b7c96fba3d8
8037968: Add tests on alignment of objects copied to survivor space
fzhinkin
parents:
diff
changeset
|
229 } |
4b7c96fba3d8
8037968: Add tests on alignment of objects copied to survivor space
fzhinkin
parents:
diff
changeset
|
230 |
4b7c96fba3d8
8037968: Add tests on alignment of objects copied to survivor space
fzhinkin
parents:
diff
changeset
|
231 /** |
4b7c96fba3d8
8037968: Add tests on alignment of objects copied to survivor space
fzhinkin
parents:
diff
changeset
|
232 * Returns a value parsed from a string with format |
4b7c96fba3d8
8037968: Add tests on alignment of objects copied to survivor space
fzhinkin
parents:
diff
changeset
|
233 * <integer><multiplier>. |
4b7c96fba3d8
8037968: Add tests on alignment of objects copied to survivor space
fzhinkin
parents:
diff
changeset
|
234 */ |
4b7c96fba3d8
8037968: Add tests on alignment of objects copied to survivor space
fzhinkin
parents:
diff
changeset
|
235 private static long parseSize(String sizeString) { |
4b7c96fba3d8
8037968: Add tests on alignment of objects copied to survivor space
fzhinkin
parents:
diff
changeset
|
236 Matcher matcher = SIZE_REGEX.matcher(sizeString); |
4b7c96fba3d8
8037968: Add tests on alignment of objects copied to survivor space
fzhinkin
parents:
diff
changeset
|
237 Asserts.assertTrue(matcher.matches(), |
4b7c96fba3d8
8037968: Add tests on alignment of objects copied to survivor space
fzhinkin
parents:
diff
changeset
|
238 "sizeString should have following format \"[0-9]+([MBK])?\""); |
4b7c96fba3d8
8037968: Add tests on alignment of objects copied to survivor space
fzhinkin
parents:
diff
changeset
|
239 long size = Long.valueOf(matcher.group("size")); |
4b7c96fba3d8
8037968: Add tests on alignment of objects copied to survivor space
fzhinkin
parents:
diff
changeset
|
240 |
4b7c96fba3d8
8037968: Add tests on alignment of objects copied to survivor space
fzhinkin
parents:
diff
changeset
|
241 if (matcher.group("multiplier") != null) { |
4b7c96fba3d8
8037968: Add tests on alignment of objects copied to survivor space
fzhinkin
parents:
diff
changeset
|
242 long K = 1024L; |
4b7c96fba3d8
8037968: Add tests on alignment of objects copied to survivor space
fzhinkin
parents:
diff
changeset
|
243 // fall through multipliers |
4b7c96fba3d8
8037968: Add tests on alignment of objects copied to survivor space
fzhinkin
parents:
diff
changeset
|
244 switch (matcher.group("multiplier").toLowerCase()) { |
4b7c96fba3d8
8037968: Add tests on alignment of objects copied to survivor space
fzhinkin
parents:
diff
changeset
|
245 case "g": |
4b7c96fba3d8
8037968: Add tests on alignment of objects copied to survivor space
fzhinkin
parents:
diff
changeset
|
246 size *= K; |
4b7c96fba3d8
8037968: Add tests on alignment of objects copied to survivor space
fzhinkin
parents:
diff
changeset
|
247 case "m": |
4b7c96fba3d8
8037968: Add tests on alignment of objects copied to survivor space
fzhinkin
parents:
diff
changeset
|
248 size *= K; |
4b7c96fba3d8
8037968: Add tests on alignment of objects copied to survivor space
fzhinkin
parents:
diff
changeset
|
249 case "k": |
4b7c96fba3d8
8037968: Add tests on alignment of objects copied to survivor space
fzhinkin
parents:
diff
changeset
|
250 size *= K; |
4b7c96fba3d8
8037968: Add tests on alignment of objects copied to survivor space
fzhinkin
parents:
diff
changeset
|
251 } |
4b7c96fba3d8
8037968: Add tests on alignment of objects copied to survivor space
fzhinkin
parents:
diff
changeset
|
252 } |
4b7c96fba3d8
8037968: Add tests on alignment of objects copied to survivor space
fzhinkin
parents:
diff
changeset
|
253 return size; |
4b7c96fba3d8
8037968: Add tests on alignment of objects copied to survivor space
fzhinkin
parents:
diff
changeset
|
254 } |
4b7c96fba3d8
8037968: Add tests on alignment of objects copied to survivor space
fzhinkin
parents:
diff
changeset
|
255 |
4b7c96fba3d8
8037968: Add tests on alignment of objects copied to survivor space
fzhinkin
parents:
diff
changeset
|
256 private SurvivorAlignmentTestMain(long memoryToFill, long objectSize, |
4b7c96fba3d8
8037968: Add tests on alignment of objects copied to survivor space
fzhinkin
parents:
diff
changeset
|
257 HeapSpace testedSpace) { |
4b7c96fba3d8
8037968: Add tests on alignment of objects copied to survivor space
fzhinkin
parents:
diff
changeset
|
258 this.objectSize = objectSize; |
4b7c96fba3d8
8037968: Add tests on alignment of objects copied to survivor space
fzhinkin
parents:
diff
changeset
|
259 this.memoryToFill = memoryToFill; |
4b7c96fba3d8
8037968: Add tests on alignment of objects copied to survivor space
fzhinkin
parents:
diff
changeset
|
260 this.testedSpace = testedSpace; |
4b7c96fba3d8
8037968: Add tests on alignment of objects copied to survivor space
fzhinkin
parents:
diff
changeset
|
261 |
4b7c96fba3d8
8037968: Add tests on alignment of objects copied to survivor space
fzhinkin
parents:
diff
changeset
|
262 AlignmentHelper helper = SurvivorAlignmentTestMain.EDEN_SPACE_HELPER; |
4b7c96fba3d8
8037968: Add tests on alignment of objects copied to survivor space
fzhinkin
parents:
diff
changeset
|
263 |
4b7c96fba3d8
8037968: Add tests on alignment of objects copied to survivor space
fzhinkin
parents:
diff
changeset
|
264 this.actualObjectSize = helper.getObjectSizeInThisSpace( |
4b7c96fba3d8
8037968: Add tests on alignment of objects copied to survivor space
fzhinkin
parents:
diff
changeset
|
265 this.objectSize); |
4b7c96fba3d8
8037968: Add tests on alignment of objects copied to survivor space
fzhinkin
parents:
diff
changeset
|
266 int arrayLength = helper.getObjectsCount(memoryToFill, this.objectSize); |
4b7c96fba3d8
8037968: Add tests on alignment of objects copied to survivor space
fzhinkin
parents:
diff
changeset
|
267 garbage = new Object[arrayLength]; |
4b7c96fba3d8
8037968: Add tests on alignment of objects copied to survivor space
fzhinkin
parents:
diff
changeset
|
268 } |
4b7c96fba3d8
8037968: Add tests on alignment of objects copied to survivor space
fzhinkin
parents:
diff
changeset
|
269 |
4b7c96fba3d8
8037968: Add tests on alignment of objects copied to survivor space
fzhinkin
parents:
diff
changeset
|
270 /** |
4b7c96fba3d8
8037968: Add tests on alignment of objects copied to survivor space
fzhinkin
parents:
diff
changeset
|
271 * Allocate byte arrays to fill {@code memoryToFill} memory. |
4b7c96fba3d8
8037968: Add tests on alignment of objects copied to survivor space
fzhinkin
parents:
diff
changeset
|
272 */ |
4b7c96fba3d8
8037968: Add tests on alignment of objects copied to survivor space
fzhinkin
parents:
diff
changeset
|
273 public void allocate() { |
4b7c96fba3d8
8037968: Add tests on alignment of objects copied to survivor space
fzhinkin
parents:
diff
changeset
|
274 int byteArrayLength = Math.max((int) (objectSize |
4b7c96fba3d8
8037968: Add tests on alignment of objects copied to survivor space
fzhinkin
parents:
diff
changeset
|
275 - Unsafe.ARRAY_BYTE_BASE_OFFSET), 0); |
4b7c96fba3d8
8037968: Add tests on alignment of objects copied to survivor space
fzhinkin
parents:
diff
changeset
|
276 |
4b7c96fba3d8
8037968: Add tests on alignment of objects copied to survivor space
fzhinkin
parents:
diff
changeset
|
277 for (int i = 0; i < garbage.length; i++) { |
4b7c96fba3d8
8037968: Add tests on alignment of objects copied to survivor space
fzhinkin
parents:
diff
changeset
|
278 garbage[i] = new byte[byteArrayLength]; |
4b7c96fba3d8
8037968: Add tests on alignment of objects copied to survivor space
fzhinkin
parents:
diff
changeset
|
279 } |
4b7c96fba3d8
8037968: Add tests on alignment of objects copied to survivor space
fzhinkin
parents:
diff
changeset
|
280 } |
4b7c96fba3d8
8037968: Add tests on alignment of objects copied to survivor space
fzhinkin
parents:
diff
changeset
|
281 |
4b7c96fba3d8
8037968: Add tests on alignment of objects copied to survivor space
fzhinkin
parents:
diff
changeset
|
282 /** |
4b7c96fba3d8
8037968: Add tests on alignment of objects copied to survivor space
fzhinkin
parents:
diff
changeset
|
283 * Release memory occupied after {@code allocate} call. |
4b7c96fba3d8
8037968: Add tests on alignment of objects copied to survivor space
fzhinkin
parents:
diff
changeset
|
284 */ |
4b7c96fba3d8
8037968: Add tests on alignment of objects copied to survivor space
fzhinkin
parents:
diff
changeset
|
285 public void release() { |
4b7c96fba3d8
8037968: Add tests on alignment of objects copied to survivor space
fzhinkin
parents:
diff
changeset
|
286 for (int i = 0; i < garbage.length; i++) { |
4b7c96fba3d8
8037968: Add tests on alignment of objects copied to survivor space
fzhinkin
parents:
diff
changeset
|
287 garbage[i] = null; |
4b7c96fba3d8
8037968: Add tests on alignment of objects copied to survivor space
fzhinkin
parents:
diff
changeset
|
288 } |
4b7c96fba3d8
8037968: Add tests on alignment of objects copied to survivor space
fzhinkin
parents:
diff
changeset
|
289 } |
4b7c96fba3d8
8037968: Add tests on alignment of objects copied to survivor space
fzhinkin
parents:
diff
changeset
|
290 |
4b7c96fba3d8
8037968: Add tests on alignment of objects copied to survivor space
fzhinkin
parents:
diff
changeset
|
291 /** |
4b7c96fba3d8
8037968: Add tests on alignment of objects copied to survivor space
fzhinkin
parents:
diff
changeset
|
292 * Returns expected amount of memory occupied in a {@code heapSpace} by |
4b7c96fba3d8
8037968: Add tests on alignment of objects copied to survivor space
fzhinkin
parents:
diff
changeset
|
293 * objects referenced from {@code garbage} array. |
4b7c96fba3d8
8037968: Add tests on alignment of objects copied to survivor space
fzhinkin
parents:
diff
changeset
|
294 */ |
4b7c96fba3d8
8037968: Add tests on alignment of objects copied to survivor space
fzhinkin
parents:
diff
changeset
|
295 public long getExpectedMemoryUsage() { |
4b7c96fba3d8
8037968: Add tests on alignment of objects copied to survivor space
fzhinkin
parents:
diff
changeset
|
296 AlignmentHelper alignmentHelper = getAlignmentHelper(testedSpace); |
4b7c96fba3d8
8037968: Add tests on alignment of objects copied to survivor space
fzhinkin
parents:
diff
changeset
|
297 return alignmentHelper.getExpectedMemoryUsage(objectSize, |
4b7c96fba3d8
8037968: Add tests on alignment of objects copied to survivor space
fzhinkin
parents:
diff
changeset
|
298 garbage.length); |
4b7c96fba3d8
8037968: Add tests on alignment of objects copied to survivor space
fzhinkin
parents:
diff
changeset
|
299 } |
4b7c96fba3d8
8037968: Add tests on alignment of objects copied to survivor space
fzhinkin
parents:
diff
changeset
|
300 |
4b7c96fba3d8
8037968: Add tests on alignment of objects copied to survivor space
fzhinkin
parents:
diff
changeset
|
301 /** |
4b7c96fba3d8
8037968: Add tests on alignment of objects copied to survivor space
fzhinkin
parents:
diff
changeset
|
302 * Verifies that memory usage in a {@code heapSpace} deviates from |
4b7c96fba3d8
8037968: Add tests on alignment of objects copied to survivor space
fzhinkin
parents:
diff
changeset
|
303 * {@code expectedUsage} for no more than {@code MAX_RELATIVE_DEVIATION}. |
4b7c96fba3d8
8037968: Add tests on alignment of objects copied to survivor space
fzhinkin
parents:
diff
changeset
|
304 */ |
4b7c96fba3d8
8037968: Add tests on alignment of objects copied to survivor space
fzhinkin
parents:
diff
changeset
|
305 public void verifyMemoryUsage(long expectedUsage) { |
4b7c96fba3d8
8037968: Add tests on alignment of objects copied to survivor space
fzhinkin
parents:
diff
changeset
|
306 AlignmentHelper alignmentHelper = getAlignmentHelper(testedSpace); |
4b7c96fba3d8
8037968: Add tests on alignment of objects copied to survivor space
fzhinkin
parents:
diff
changeset
|
307 |
4b7c96fba3d8
8037968: Add tests on alignment of objects copied to survivor space
fzhinkin
parents:
diff
changeset
|
308 long actualMemoryUsage = alignmentHelper.getActualMemoryUsage(); |
4b7c96fba3d8
8037968: Add tests on alignment of objects copied to survivor space
fzhinkin
parents:
diff
changeset
|
309 boolean otherThreadsAllocatedMemory = areOtherThreadsAllocatedMemory(); |
4b7c96fba3d8
8037968: Add tests on alignment of objects copied to survivor space
fzhinkin
parents:
diff
changeset
|
310 |
4b7c96fba3d8
8037968: Add tests on alignment of objects copied to survivor space
fzhinkin
parents:
diff
changeset
|
311 long memoryUsageDiff = Math.abs(actualMemoryUsage - expectedUsage); |
4b7c96fba3d8
8037968: Add tests on alignment of objects copied to survivor space
fzhinkin
parents:
diff
changeset
|
312 long maxAllowedUsageDiff |
4b7c96fba3d8
8037968: Add tests on alignment of objects copied to survivor space
fzhinkin
parents:
diff
changeset
|
313 = alignmentHelper.getAllowedMemoryUsageDeviation(expectedUsage); |
4b7c96fba3d8
8037968: Add tests on alignment of objects copied to survivor space
fzhinkin
parents:
diff
changeset
|
314 |
4b7c96fba3d8
8037968: Add tests on alignment of objects copied to survivor space
fzhinkin
parents:
diff
changeset
|
315 System.out.println("Verifying memory usage in space: " + testedSpace); |
4b7c96fba3d8
8037968: Add tests on alignment of objects copied to survivor space
fzhinkin
parents:
diff
changeset
|
316 System.out.println("Allocated objects count: " + garbage.length); |
4b7c96fba3d8
8037968: Add tests on alignment of objects copied to survivor space
fzhinkin
parents:
diff
changeset
|
317 System.out.println("Desired object size: " + objectSize); |
4b7c96fba3d8
8037968: Add tests on alignment of objects copied to survivor space
fzhinkin
parents:
diff
changeset
|
318 System.out.println("Actual object size: " + actualObjectSize); |
4b7c96fba3d8
8037968: Add tests on alignment of objects copied to survivor space
fzhinkin
parents:
diff
changeset
|
319 System.out.println("Expected object size in space: " |
4b7c96fba3d8
8037968: Add tests on alignment of objects copied to survivor space
fzhinkin
parents:
diff
changeset
|
320 + alignmentHelper.getObjectSizeInThisSpace(objectSize)); |
4b7c96fba3d8
8037968: Add tests on alignment of objects copied to survivor space
fzhinkin
parents:
diff
changeset
|
321 System.out.println("Expected memory usage: " + expectedUsage); |
4b7c96fba3d8
8037968: Add tests on alignment of objects copied to survivor space
fzhinkin
parents:
diff
changeset
|
322 System.out.println("Actual memory usage: " + actualMemoryUsage); |
4b7c96fba3d8
8037968: Add tests on alignment of objects copied to survivor space
fzhinkin
parents:
diff
changeset
|
323 System.out.println("Memory usage diff: " + memoryUsageDiff); |
4b7c96fba3d8
8037968: Add tests on alignment of objects copied to survivor space
fzhinkin
parents:
diff
changeset
|
324 System.out.println("Max allowed usage diff: " + maxAllowedUsageDiff); |
4b7c96fba3d8
8037968: Add tests on alignment of objects copied to survivor space
fzhinkin
parents:
diff
changeset
|
325 |
4b7c96fba3d8
8037968: Add tests on alignment of objects copied to survivor space
fzhinkin
parents:
diff
changeset
|
326 if (memoryUsageDiff > maxAllowedUsageDiff |
4b7c96fba3d8
8037968: Add tests on alignment of objects copied to survivor space
fzhinkin
parents:
diff
changeset
|
327 && otherThreadsAllocatedMemory) { |
4b7c96fba3d8
8037968: Add tests on alignment of objects copied to survivor space
fzhinkin
parents:
diff
changeset
|
328 System.out.println("Memory usage diff is incorrect, but it seems " |
4b7c96fba3d8
8037968: Add tests on alignment of objects copied to survivor space
fzhinkin
parents:
diff
changeset
|
329 + "like someone else allocated objects"); |
4b7c96fba3d8
8037968: Add tests on alignment of objects copied to survivor space
fzhinkin
parents:
diff
changeset
|
330 return; |
4b7c96fba3d8
8037968: Add tests on alignment of objects copied to survivor space
fzhinkin
parents:
diff
changeset
|
331 } |
4b7c96fba3d8
8037968: Add tests on alignment of objects copied to survivor space
fzhinkin
parents:
diff
changeset
|
332 |
4b7c96fba3d8
8037968: Add tests on alignment of objects copied to survivor space
fzhinkin
parents:
diff
changeset
|
333 Asserts.assertLTE(memoryUsageDiff, maxAllowedUsageDiff, |
4b7c96fba3d8
8037968: Add tests on alignment of objects copied to survivor space
fzhinkin
parents:
diff
changeset
|
334 "Actual memory usage should not deviate from expected for " + |
4b7c96fba3d8
8037968: Add tests on alignment of objects copied to survivor space
fzhinkin
parents:
diff
changeset
|
335 "more then " + maxAllowedUsageDiff); |
4b7c96fba3d8
8037968: Add tests on alignment of objects copied to survivor space
fzhinkin
parents:
diff
changeset
|
336 } |
4b7c96fba3d8
8037968: Add tests on alignment of objects copied to survivor space
fzhinkin
parents:
diff
changeset
|
337 |
4b7c96fba3d8
8037968: Add tests on alignment of objects copied to survivor space
fzhinkin
parents:
diff
changeset
|
338 /** |
4b7c96fba3d8
8037968: Add tests on alignment of objects copied to survivor space
fzhinkin
parents:
diff
changeset
|
339 * Baselines amount of memory allocated by each thread. |
4b7c96fba3d8
8037968: Add tests on alignment of objects copied to survivor space
fzhinkin
parents:
diff
changeset
|
340 */ |
4b7c96fba3d8
8037968: Add tests on alignment of objects copied to survivor space
fzhinkin
parents:
diff
changeset
|
341 public void baselineMemoryAllocation() { |
4b7c96fba3d8
8037968: Add tests on alignment of objects copied to survivor space
fzhinkin
parents:
diff
changeset
|
342 ThreadMXBean bean = (ThreadMXBean) ManagementFactory.getThreadMXBean(); |
4b7c96fba3d8
8037968: Add tests on alignment of objects copied to survivor space
fzhinkin
parents:
diff
changeset
|
343 threadIds = bean.getAllThreadIds(); |
4b7c96fba3d8
8037968: Add tests on alignment of objects copied to survivor space
fzhinkin
parents:
diff
changeset
|
344 baselinedThreadMemoryUsage = bean.getThreadAllocatedBytes(threadIds); |
4b7c96fba3d8
8037968: Add tests on alignment of objects copied to survivor space
fzhinkin
parents:
diff
changeset
|
345 } |
4b7c96fba3d8
8037968: Add tests on alignment of objects copied to survivor space
fzhinkin
parents:
diff
changeset
|
346 |
4b7c96fba3d8
8037968: Add tests on alignment of objects copied to survivor space
fzhinkin
parents:
diff
changeset
|
347 /** |
4b7c96fba3d8
8037968: Add tests on alignment of objects copied to survivor space
fzhinkin
parents:
diff
changeset
|
348 * Checks if threads other then the current thread were allocating objects |
4b7c96fba3d8
8037968: Add tests on alignment of objects copied to survivor space
fzhinkin
parents:
diff
changeset
|
349 * after baselinedThreadMemoryUsage call. |
4b7c96fba3d8
8037968: Add tests on alignment of objects copied to survivor space
fzhinkin
parents:
diff
changeset
|
350 * |
4b7c96fba3d8
8037968: Add tests on alignment of objects copied to survivor space
fzhinkin
parents:
diff
changeset
|
351 * If baselinedThreadMemoryUsage was not called, then this method will return |
4b7c96fba3d8
8037968: Add tests on alignment of objects copied to survivor space
fzhinkin
parents:
diff
changeset
|
352 * {@code false}. |
4b7c96fba3d8
8037968: Add tests on alignment of objects copied to survivor space
fzhinkin
parents:
diff
changeset
|
353 */ |
4b7c96fba3d8
8037968: Add tests on alignment of objects copied to survivor space
fzhinkin
parents:
diff
changeset
|
354 public boolean areOtherThreadsAllocatedMemory() { |
4b7c96fba3d8
8037968: Add tests on alignment of objects copied to survivor space
fzhinkin
parents:
diff
changeset
|
355 if (baselinedThreadMemoryUsage == null) { |
4b7c96fba3d8
8037968: Add tests on alignment of objects copied to survivor space
fzhinkin
parents:
diff
changeset
|
356 return false; |
4b7c96fba3d8
8037968: Add tests on alignment of objects copied to survivor space
fzhinkin
parents:
diff
changeset
|
357 } |
4b7c96fba3d8
8037968: Add tests on alignment of objects copied to survivor space
fzhinkin
parents:
diff
changeset
|
358 |
4b7c96fba3d8
8037968: Add tests on alignment of objects copied to survivor space
fzhinkin
parents:
diff
changeset
|
359 ThreadMXBean bean = (ThreadMXBean) ManagementFactory.getThreadMXBean(); |
4b7c96fba3d8
8037968: Add tests on alignment of objects copied to survivor space
fzhinkin
parents:
diff
changeset
|
360 long currentMemoryAllocation[] |
4b7c96fba3d8
8037968: Add tests on alignment of objects copied to survivor space
fzhinkin
parents:
diff
changeset
|
361 = bean.getThreadAllocatedBytes(threadIds); |
4b7c96fba3d8
8037968: Add tests on alignment of objects copied to survivor space
fzhinkin
parents:
diff
changeset
|
362 boolean otherThreadsAllocatedMemory = false; |
4b7c96fba3d8
8037968: Add tests on alignment of objects copied to survivor space
fzhinkin
parents:
diff
changeset
|
363 |
4b7c96fba3d8
8037968: Add tests on alignment of objects copied to survivor space
fzhinkin
parents:
diff
changeset
|
364 System.out.println("Verifying amount of memory allocated by threads:"); |
4b7c96fba3d8
8037968: Add tests on alignment of objects copied to survivor space
fzhinkin
parents:
diff
changeset
|
365 for (int i = 0; i < threadIds.length; i++) { |
4b7c96fba3d8
8037968: Add tests on alignment of objects copied to survivor space
fzhinkin
parents:
diff
changeset
|
366 System.out.format("Thread %d%nbaseline allocation: %d" |
4b7c96fba3d8
8037968: Add tests on alignment of objects copied to survivor space
fzhinkin
parents:
diff
changeset
|
367 + "%ncurrent allocation:%d%n", threadIds[i], |
4b7c96fba3d8
8037968: Add tests on alignment of objects copied to survivor space
fzhinkin
parents:
diff
changeset
|
368 baselinedThreadMemoryUsage[i], currentMemoryAllocation[i]); |
4b7c96fba3d8
8037968: Add tests on alignment of objects copied to survivor space
fzhinkin
parents:
diff
changeset
|
369 System.out.println(bean.getThreadInfo(threadIds[i])); |
4b7c96fba3d8
8037968: Add tests on alignment of objects copied to survivor space
fzhinkin
parents:
diff
changeset
|
370 |
4b7c96fba3d8
8037968: Add tests on alignment of objects copied to survivor space
fzhinkin
parents:
diff
changeset
|
371 long bytesAllocated = Math.abs(currentMemoryAllocation[i] |
4b7c96fba3d8
8037968: Add tests on alignment of objects copied to survivor space
fzhinkin
parents:
diff
changeset
|
372 - baselinedThreadMemoryUsage[i]); |
4b7c96fba3d8
8037968: Add tests on alignment of objects copied to survivor space
fzhinkin
parents:
diff
changeset
|
373 if (bytesAllocated > 0 |
4b7c96fba3d8
8037968: Add tests on alignment of objects copied to survivor space
fzhinkin
parents:
diff
changeset
|
374 && threadIds[i] != Thread.currentThread().getId()) { |
4b7c96fba3d8
8037968: Add tests on alignment of objects copied to survivor space
fzhinkin
parents:
diff
changeset
|
375 otherThreadsAllocatedMemory = true; |
4b7c96fba3d8
8037968: Add tests on alignment of objects copied to survivor space
fzhinkin
parents:
diff
changeset
|
376 } |
4b7c96fba3d8
8037968: Add tests on alignment of objects copied to survivor space
fzhinkin
parents:
diff
changeset
|
377 } |
4b7c96fba3d8
8037968: Add tests on alignment of objects copied to survivor space
fzhinkin
parents:
diff
changeset
|
378 |
4b7c96fba3d8
8037968: Add tests on alignment of objects copied to survivor space
fzhinkin
parents:
diff
changeset
|
379 return otherThreadsAllocatedMemory; |
4b7c96fba3d8
8037968: Add tests on alignment of objects copied to survivor space
fzhinkin
parents:
diff
changeset
|
380 } |
4b7c96fba3d8
8037968: Add tests on alignment of objects copied to survivor space
fzhinkin
parents:
diff
changeset
|
381 |
4b7c96fba3d8
8037968: Add tests on alignment of objects copied to survivor space
fzhinkin
parents:
diff
changeset
|
382 @Override |
4b7c96fba3d8
8037968: Add tests on alignment of objects copied to survivor space
fzhinkin
parents:
diff
changeset
|
383 public String toString() { |
4b7c96fba3d8
8037968: Add tests on alignment of objects copied to survivor space
fzhinkin
parents:
diff
changeset
|
384 StringBuilder builder = new StringBuilder(); |
4b7c96fba3d8
8037968: Add tests on alignment of objects copied to survivor space
fzhinkin
parents:
diff
changeset
|
385 |
4b7c96fba3d8
8037968: Add tests on alignment of objects copied to survivor space
fzhinkin
parents:
diff
changeset
|
386 builder.append(String.format("SurvivorAlignmentTestMain info:%n")); |
4b7c96fba3d8
8037968: Add tests on alignment of objects copied to survivor space
fzhinkin
parents:
diff
changeset
|
387 builder.append(String.format("Desired object size: %d%n", objectSize)); |
4b7c96fba3d8
8037968: Add tests on alignment of objects copied to survivor space
fzhinkin
parents:
diff
changeset
|
388 builder.append(String.format("Memory to fill: %d%n", memoryToFill)); |
4b7c96fba3d8
8037968: Add tests on alignment of objects copied to survivor space
fzhinkin
parents:
diff
changeset
|
389 builder.append(String.format("Objects to be allocated: %d%n", |
4b7c96fba3d8
8037968: Add tests on alignment of objects copied to survivor space
fzhinkin
parents:
diff
changeset
|
390 garbage.length)); |
4b7c96fba3d8
8037968: Add tests on alignment of objects copied to survivor space
fzhinkin
parents:
diff
changeset
|
391 |
4b7c96fba3d8
8037968: Add tests on alignment of objects copied to survivor space
fzhinkin
parents:
diff
changeset
|
392 builder.append(String.format("Alignment helpers to be used: %n")); |
4b7c96fba3d8
8037968: Add tests on alignment of objects copied to survivor space
fzhinkin
parents:
diff
changeset
|
393 for (HeapSpace heapSpace: HeapSpace.values()) { |
4b7c96fba3d8
8037968: Add tests on alignment of objects copied to survivor space
fzhinkin
parents:
diff
changeset
|
394 builder.append(String.format("For space %s:%n%s%n", heapSpace, |
4b7c96fba3d8
8037968: Add tests on alignment of objects copied to survivor space
fzhinkin
parents:
diff
changeset
|
395 getAlignmentHelper(heapSpace))); |
4b7c96fba3d8
8037968: Add tests on alignment of objects copied to survivor space
fzhinkin
parents:
diff
changeset
|
396 } |
4b7c96fba3d8
8037968: Add tests on alignment of objects copied to survivor space
fzhinkin
parents:
diff
changeset
|
397 |
4b7c96fba3d8
8037968: Add tests on alignment of objects copied to survivor space
fzhinkin
parents:
diff
changeset
|
398 return builder.toString(); |
4b7c96fba3d8
8037968: Add tests on alignment of objects copied to survivor space
fzhinkin
parents:
diff
changeset
|
399 } |
4b7c96fba3d8
8037968: Add tests on alignment of objects copied to survivor space
fzhinkin
parents:
diff
changeset
|
400 |
4b7c96fba3d8
8037968: Add tests on alignment of objects copied to survivor space
fzhinkin
parents:
diff
changeset
|
401 /** |
4b7c96fba3d8
8037968: Add tests on alignment of objects copied to survivor space
fzhinkin
parents:
diff
changeset
|
402 * Returns {@code AlignmentHelper} for a space {@code heapSpace}. |
4b7c96fba3d8
8037968: Add tests on alignment of objects copied to survivor space
fzhinkin
parents:
diff
changeset
|
403 */ |
4b7c96fba3d8
8037968: Add tests on alignment of objects copied to survivor space
fzhinkin
parents:
diff
changeset
|
404 public static AlignmentHelper getAlignmentHelper(HeapSpace heapSpace) { |
4b7c96fba3d8
8037968: Add tests on alignment of objects copied to survivor space
fzhinkin
parents:
diff
changeset
|
405 switch (heapSpace) { |
4b7c96fba3d8
8037968: Add tests on alignment of objects copied to survivor space
fzhinkin
parents:
diff
changeset
|
406 case EDEN: |
4b7c96fba3d8
8037968: Add tests on alignment of objects copied to survivor space
fzhinkin
parents:
diff
changeset
|
407 return SurvivorAlignmentTestMain.EDEN_SPACE_HELPER; |
4b7c96fba3d8
8037968: Add tests on alignment of objects copied to survivor space
fzhinkin
parents:
diff
changeset
|
408 case SURVIVOR: |
4b7c96fba3d8
8037968: Add tests on alignment of objects copied to survivor space
fzhinkin
parents:
diff
changeset
|
409 return SurvivorAlignmentTestMain.SURVIVOR_SPACE_HELPER; |
4b7c96fba3d8
8037968: Add tests on alignment of objects copied to survivor space
fzhinkin
parents:
diff
changeset
|
410 case TENURED: |
4b7c96fba3d8
8037968: Add tests on alignment of objects copied to survivor space
fzhinkin
parents:
diff
changeset
|
411 return SurvivorAlignmentTestMain.TENURED_SPACE_HELPER; |
4b7c96fba3d8
8037968: Add tests on alignment of objects copied to survivor space
fzhinkin
parents:
diff
changeset
|
412 default: |
4b7c96fba3d8
8037968: Add tests on alignment of objects copied to survivor space
fzhinkin
parents:
diff
changeset
|
413 throw new Error("Unexpected heap space: " + heapSpace); |
4b7c96fba3d8
8037968: Add tests on alignment of objects copied to survivor space
fzhinkin
parents:
diff
changeset
|
414 } |
4b7c96fba3d8
8037968: Add tests on alignment of objects copied to survivor space
fzhinkin
parents:
diff
changeset
|
415 } |
4b7c96fba3d8
8037968: Add tests on alignment of objects copied to survivor space
fzhinkin
parents:
diff
changeset
|
416 } |