Mercurial > hg > graal-compiler
annotate src/share/vm/utilities/globalDefinitions.cpp @ 1458:dc114f680d9c
Merge.
author | Doug Simon <doug.simon@oracle.com> |
---|---|
date | Sat, 13 Nov 2010 08:15:52 +0100 |
parents | d1605aabd0a1 |
children | c18cbe5936b8 2d127394260e |
rev | line source |
---|---|
0 | 1 /* |
196 | 2 * Copyright 1997-2008 Sun Microsystems, Inc. All Rights Reserved. |
0 | 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 Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, | |
20 * CA 95054 USA or visit www.sun.com if you need additional information or | |
21 * have any questions. | |
22 * | |
23 */ | |
24 | |
25 # include "incls/_precompiled.incl" | |
26 # include "incls/_globalDefinitions.cpp.incl" | |
113
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
29
diff
changeset
|
27 // Basic error support |
0 | 28 |
113
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
29
diff
changeset
|
29 // Info for oops within a java object. Defaults are zero so |
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
29
diff
changeset
|
30 // things will break badly if incorrectly initialized. |
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
29
diff
changeset
|
31 int heapOopSize = 0; |
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
29
diff
changeset
|
32 int LogBytesPerHeapOop = 0; |
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
29
diff
changeset
|
33 int LogBitsPerHeapOop = 0; |
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
29
diff
changeset
|
34 int BytesPerHeapOop = 0; |
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
29
diff
changeset
|
35 int BitsPerHeapOop = 0; |
0 | 36 |
37 void basic_fatal(const char* msg) { | |
38 fatal(msg); | |
39 } | |
40 | |
41 // Something to help porters sleep at night | |
42 | |
113
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
29
diff
changeset
|
43 void basic_types_init() { |
0 | 44 #ifdef ASSERT |
45 #ifdef _LP64 | |
46 assert(min_intx == (intx)CONST64(0x8000000000000000), "correct constant"); | |
47 assert(max_intx == CONST64(0x7FFFFFFFFFFFFFFF), "correct constant"); | |
48 assert(max_uintx == CONST64(0xFFFFFFFFFFFFFFFF), "correct constant"); | |
49 assert( 8 == sizeof( intx), "wrong size for basic type"); | |
50 assert( 8 == sizeof( jobject), "wrong size for basic type"); | |
51 #else | |
52 assert(min_intx == (intx)0x80000000, "correct constant"); | |
53 assert(max_intx == 0x7FFFFFFF, "correct constant"); | |
54 assert(max_uintx == 0xFFFFFFFF, "correct constant"); | |
55 assert( 4 == sizeof( intx), "wrong size for basic type"); | |
56 assert( 4 == sizeof( jobject), "wrong size for basic type"); | |
57 #endif | |
58 assert( (~max_juint) == 0, "max_juint has all its bits"); | |
59 assert( (~max_uintx) == 0, "max_uintx has all its bits"); | |
60 assert( (~max_julong) == 0, "max_julong has all its bits"); | |
61 assert( 1 == sizeof( jbyte), "wrong size for basic type"); | |
62 assert( 2 == sizeof( jchar), "wrong size for basic type"); | |
63 assert( 2 == sizeof( jshort), "wrong size for basic type"); | |
64 assert( 4 == sizeof( juint), "wrong size for basic type"); | |
65 assert( 4 == sizeof( jint), "wrong size for basic type"); | |
66 assert( 1 == sizeof( jboolean), "wrong size for basic type"); | |
67 assert( 8 == sizeof( jlong), "wrong size for basic type"); | |
68 assert( 4 == sizeof( jfloat), "wrong size for basic type"); | |
69 assert( 8 == sizeof( jdouble), "wrong size for basic type"); | |
70 assert( 1 == sizeof( u1), "wrong size for basic type"); | |
71 assert( 2 == sizeof( u2), "wrong size for basic type"); | |
72 assert( 4 == sizeof( u4), "wrong size for basic type"); | |
73 | |
74 int num_type_chars = 0; | |
75 for (int i = 0; i < 99; i++) { | |
76 if (type2char((BasicType)i) != 0) { | |
77 assert(char2type(type2char((BasicType)i)) == i, "proper inverses"); | |
78 num_type_chars++; | |
79 } | |
80 } | |
81 assert(num_type_chars == 11, "must have tested the right number of mappings"); | |
82 assert(char2type(0) == T_ILLEGAL, "correct illegality"); | |
83 | |
84 { | |
85 for (int i = T_BOOLEAN; i <= T_CONFLICT; i++) { | |
86 BasicType vt = (BasicType)i; | |
87 BasicType ft = type2field[vt]; | |
88 switch (vt) { | |
89 // the following types might plausibly show up in memory layouts: | |
90 case T_BOOLEAN: | |
91 case T_BYTE: | |
92 case T_CHAR: | |
93 case T_SHORT: | |
94 case T_INT: | |
95 case T_FLOAT: | |
96 case T_DOUBLE: | |
97 case T_LONG: | |
98 case T_OBJECT: | |
99 case T_ADDRESS: // random raw pointer | |
113
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
29
diff
changeset
|
100 case T_NARROWOOP: // compressed pointer |
0 | 101 case T_CONFLICT: // might as well support a bottom type |
102 case T_VOID: // padding or other unaddressed word | |
103 // layout type must map to itself | |
104 assert(vt == ft, ""); | |
105 break; | |
106 default: | |
107 // non-layout type must map to a (different) layout type | |
108 assert(vt != ft, ""); | |
109 assert(ft == type2field[ft], ""); | |
110 } | |
111 // every type must map to same-sized layout type: | |
112 assert(type2size[vt] == type2size[ft], ""); | |
113 } | |
114 } | |
115 // These are assumed, e.g., when filling HeapWords with juints. | |
116 assert(is_power_of_2(sizeof(juint)), "juint must be power of 2"); | |
117 assert(is_power_of_2(HeapWordSize), "HeapWordSize must be power of 2"); | |
118 assert((size_t)HeapWordSize >= sizeof(juint), | |
119 "HeapWord should be at least as large as juint"); | |
120 assert(sizeof(NULL) == sizeof(char*), "NULL must be same size as pointer"); | |
121 #endif | |
122 | |
123 if( JavaPriority1_To_OSPriority != -1 ) | |
124 os::java_to_os_priority[1] = JavaPriority1_To_OSPriority; | |
125 if( JavaPriority2_To_OSPriority != -1 ) | |
126 os::java_to_os_priority[2] = JavaPriority2_To_OSPriority; | |
127 if( JavaPriority3_To_OSPriority != -1 ) | |
128 os::java_to_os_priority[3] = JavaPriority3_To_OSPriority; | |
129 if( JavaPriority4_To_OSPriority != -1 ) | |
130 os::java_to_os_priority[4] = JavaPriority4_To_OSPriority; | |
131 if( JavaPriority5_To_OSPriority != -1 ) | |
132 os::java_to_os_priority[5] = JavaPriority5_To_OSPriority; | |
133 if( JavaPriority6_To_OSPriority != -1 ) | |
134 os::java_to_os_priority[6] = JavaPriority6_To_OSPriority; | |
135 if( JavaPriority7_To_OSPriority != -1 ) | |
136 os::java_to_os_priority[7] = JavaPriority7_To_OSPriority; | |
137 if( JavaPriority8_To_OSPriority != -1 ) | |
138 os::java_to_os_priority[8] = JavaPriority8_To_OSPriority; | |
139 if( JavaPriority9_To_OSPriority != -1 ) | |
140 os::java_to_os_priority[9] = JavaPriority9_To_OSPriority; | |
141 if(JavaPriority10_To_OSPriority != -1 ) | |
142 os::java_to_os_priority[10] = JavaPriority10_To_OSPriority; | |
113
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
29
diff
changeset
|
143 |
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
29
diff
changeset
|
144 // Set the size of basic types here (after argument parsing but before |
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
29
diff
changeset
|
145 // stub generation). |
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
29
diff
changeset
|
146 if (UseCompressedOops) { |
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
29
diff
changeset
|
147 // Size info for oops within java objects is fixed |
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
29
diff
changeset
|
148 heapOopSize = jintSize; |
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
29
diff
changeset
|
149 LogBytesPerHeapOop = LogBytesPerInt; |
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
29
diff
changeset
|
150 LogBitsPerHeapOop = LogBitsPerInt; |
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
29
diff
changeset
|
151 BytesPerHeapOop = BytesPerInt; |
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
29
diff
changeset
|
152 BitsPerHeapOop = BitsPerInt; |
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
29
diff
changeset
|
153 } else { |
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
29
diff
changeset
|
154 heapOopSize = oopSize; |
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
29
diff
changeset
|
155 LogBytesPerHeapOop = LogBytesPerWord; |
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
29
diff
changeset
|
156 LogBitsPerHeapOop = LogBitsPerWord; |
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
29
diff
changeset
|
157 BytesPerHeapOop = BytesPerWord; |
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
29
diff
changeset
|
158 BitsPerHeapOop = BitsPerWord; |
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
29
diff
changeset
|
159 } |
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
29
diff
changeset
|
160 _type2aelembytes[T_OBJECT] = heapOopSize; |
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
29
diff
changeset
|
161 _type2aelembytes[T_ARRAY] = heapOopSize; |
0 | 162 } |
163 | |
164 | |
165 // Map BasicType to signature character | |
113
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
29
diff
changeset
|
166 char type2char_tab[T_CONFLICT+1]={ 0, 0, 0, 0, 'Z', 'C', 'F', 'D', 'B', 'S', 'I', 'J', 'L', '[', 'V', 0, 0, 0}; |
0 | 167 |
168 // Map BasicType to Java type name | |
169 const char* type2name_tab[T_CONFLICT+1] = { | |
170 NULL, NULL, NULL, NULL, | |
171 "boolean", | |
172 "char", | |
173 "float", | |
174 "double", | |
175 "byte", | |
176 "short", | |
177 "int", | |
178 "long", | |
179 "object", | |
180 "array", | |
181 "void", | |
182 "*address*", | |
113
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
29
diff
changeset
|
183 "*narrowoop*", |
0 | 184 "*conflict*" |
185 }; | |
186 | |
187 | |
188 BasicType name2type(const char* name) { | |
189 for (int i = T_BOOLEAN; i <= T_VOID; i++) { | |
190 BasicType t = (BasicType)i; | |
191 if (type2name_tab[t] != NULL && 0 == strcmp(type2name_tab[t], name)) | |
192 return t; | |
193 } | |
194 return T_ILLEGAL; | |
195 } | |
196 | |
197 | |
198 // Map BasicType to size in words | |
113
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
29
diff
changeset
|
199 int type2size[T_CONFLICT+1]={ -1, 0, 0, 0, 1, 1, 1, 2, 1, 1, 1, 2, 1, 1, 0, 1, 1, -1}; |
0 | 200 |
201 BasicType type2field[T_CONFLICT+1] = { | |
202 (BasicType)0, // 0, | |
203 (BasicType)0, // 1, | |
204 (BasicType)0, // 2, | |
205 (BasicType)0, // 3, | |
206 T_BOOLEAN, // T_BOOLEAN = 4, | |
207 T_CHAR, // T_CHAR = 5, | |
208 T_FLOAT, // T_FLOAT = 6, | |
209 T_DOUBLE, // T_DOUBLE = 7, | |
210 T_BYTE, // T_BYTE = 8, | |
211 T_SHORT, // T_SHORT = 9, | |
212 T_INT, // T_INT = 10, | |
213 T_LONG, // T_LONG = 11, | |
214 T_OBJECT, // T_OBJECT = 12, | |
215 T_OBJECT, // T_ARRAY = 13, | |
216 T_VOID, // T_VOID = 14, | |
217 T_ADDRESS, // T_ADDRESS = 15, | |
113
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
29
diff
changeset
|
218 T_NARROWOOP, // T_NARROWOOP= 16, |
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
29
diff
changeset
|
219 T_CONFLICT // T_CONFLICT = 17, |
0 | 220 }; |
221 | |
222 | |
223 BasicType type2wfield[T_CONFLICT+1] = { | |
224 (BasicType)0, // 0, | |
225 (BasicType)0, // 1, | |
226 (BasicType)0, // 2, | |
227 (BasicType)0, // 3, | |
228 T_INT, // T_BOOLEAN = 4, | |
229 T_INT, // T_CHAR = 5, | |
230 T_FLOAT, // T_FLOAT = 6, | |
231 T_DOUBLE, // T_DOUBLE = 7, | |
232 T_INT, // T_BYTE = 8, | |
233 T_INT, // T_SHORT = 9, | |
234 T_INT, // T_INT = 10, | |
235 T_LONG, // T_LONG = 11, | |
236 T_OBJECT, // T_OBJECT = 12, | |
237 T_OBJECT, // T_ARRAY = 13, | |
238 T_VOID, // T_VOID = 14, | |
239 T_ADDRESS, // T_ADDRESS = 15, | |
113
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
29
diff
changeset
|
240 T_NARROWOOP, // T_NARROWOOP = 16, |
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
29
diff
changeset
|
241 T_CONFLICT // T_CONFLICT = 17, |
0 | 242 }; |
243 | |
244 | |
29
d5fc211aea19
6633953: type2aelembytes{T_ADDRESS} should be 8 bytes in 64 bit VM
kvn
parents:
0
diff
changeset
|
245 int _type2aelembytes[T_CONFLICT+1] = { |
0 | 246 0, // 0 |
247 0, // 1 | |
248 0, // 2 | |
249 0, // 3 | |
250 T_BOOLEAN_aelem_bytes, // T_BOOLEAN = 4, | |
251 T_CHAR_aelem_bytes, // T_CHAR = 5, | |
252 T_FLOAT_aelem_bytes, // T_FLOAT = 6, | |
253 T_DOUBLE_aelem_bytes, // T_DOUBLE = 7, | |
254 T_BYTE_aelem_bytes, // T_BYTE = 8, | |
255 T_SHORT_aelem_bytes, // T_SHORT = 9, | |
256 T_INT_aelem_bytes, // T_INT = 10, | |
257 T_LONG_aelem_bytes, // T_LONG = 11, | |
258 T_OBJECT_aelem_bytes, // T_OBJECT = 12, | |
259 T_ARRAY_aelem_bytes, // T_ARRAY = 13, | |
260 0, // T_VOID = 14, | |
29
d5fc211aea19
6633953: type2aelembytes{T_ADDRESS} should be 8 bytes in 64 bit VM
kvn
parents:
0
diff
changeset
|
261 T_OBJECT_aelem_bytes, // T_ADDRESS = 15, |
113
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
29
diff
changeset
|
262 T_NARROWOOP_aelem_bytes,// T_NARROWOOP= 16, |
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
29
diff
changeset
|
263 0 // T_CONFLICT = 17, |
0 | 264 }; |
265 | |
29
d5fc211aea19
6633953: type2aelembytes{T_ADDRESS} should be 8 bytes in 64 bit VM
kvn
parents:
0
diff
changeset
|
266 #ifdef ASSERT |
d5fc211aea19
6633953: type2aelembytes{T_ADDRESS} should be 8 bytes in 64 bit VM
kvn
parents:
0
diff
changeset
|
267 int type2aelembytes(BasicType t, bool allow_address) { |
d5fc211aea19
6633953: type2aelembytes{T_ADDRESS} should be 8 bytes in 64 bit VM
kvn
parents:
0
diff
changeset
|
268 assert(allow_address || t != T_ADDRESS, " "); |
d5fc211aea19
6633953: type2aelembytes{T_ADDRESS} should be 8 bytes in 64 bit VM
kvn
parents:
0
diff
changeset
|
269 return _type2aelembytes[t]; |
d5fc211aea19
6633953: type2aelembytes{T_ADDRESS} should be 8 bytes in 64 bit VM
kvn
parents:
0
diff
changeset
|
270 } |
d5fc211aea19
6633953: type2aelembytes{T_ADDRESS} should be 8 bytes in 64 bit VM
kvn
parents:
0
diff
changeset
|
271 #endif |
0 | 272 |
273 // Support for 64-bit integer arithmetic | |
274 | |
275 // The following code is mostly taken from JVM typedefs_md.h and system_md.c | |
276 | |
113
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
29
diff
changeset
|
277 static const jlong high_bit = (jlong)1 << (jlong)63; |
0 | 278 static const jlong other_bits = ~high_bit; |
279 | |
280 jlong float2long(jfloat f) { | |
281 jlong tmp = (jlong) f; | |
282 if (tmp != high_bit) { | |
283 return tmp; | |
284 } else { | |
285 if (g_isnan((jdouble)f)) { | |
286 return 0; | |
287 } | |
288 if (f < 0) { | |
289 return high_bit; | |
290 } else { | |
291 return other_bits; | |
292 } | |
293 } | |
294 } | |
295 | |
296 | |
297 jlong double2long(jdouble f) { | |
298 jlong tmp = (jlong) f; | |
299 if (tmp != high_bit) { | |
300 return tmp; | |
301 } else { | |
302 if (g_isnan(f)) { | |
303 return 0; | |
304 } | |
305 if (f < 0) { | |
306 return high_bit; | |
307 } else { | |
308 return other_bits; | |
309 } | |
310 } | |
311 } | |
312 | |
313 // least common multiple | |
314 size_t lcm(size_t a, size_t b) { | |
315 size_t cur, div, next; | |
316 | |
317 cur = MAX2(a, b); | |
318 div = MIN2(a, b); | |
319 | |
320 assert(div != 0, "lcm requires positive arguments"); | |
321 | |
322 | |
323 while ((next = cur % div) != 0) { | |
324 cur = div; div = next; | |
325 } | |
326 | |
327 | |
328 julong result = julong(a) * b / div; | |
329 assert(result <= (size_t)max_uintx, "Integer overflow in lcm"); | |
330 | |
331 return size_t(result); | |
332 } |