Mercurial > hg > graal-compiler
annotate src/share/vm/utilities/globalDefinitions.hpp @ 196:d1605aabd0a1 jdk7-b30
6719955: Update copyright year
Summary: Update copyright year for files that have been modified in 2008
Reviewed-by: ohair, tbell
author | xdono |
---|---|
date | Wed, 02 Jul 2008 12:55:16 -0700 |
parents | f3de1255b035 |
children | 850fdf70db2b |
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 // This file holds all globally used constants & types, class (forward) | |
26 // declarations and a few frequently used utility functions. | |
27 | |
28 //---------------------------------------------------------------------------------------------------- | |
29 // Constants | |
30 | |
31 const int LogBytesPerShort = 1; | |
32 const int LogBytesPerInt = 2; | |
33 #ifdef _LP64 | |
34 const int LogBytesPerWord = 3; | |
35 #else | |
36 const int LogBytesPerWord = 2; | |
37 #endif | |
38 const int LogBytesPerLong = 3; | |
39 | |
40 const int BytesPerShort = 1 << LogBytesPerShort; | |
41 const int BytesPerInt = 1 << LogBytesPerInt; | |
42 const int BytesPerWord = 1 << LogBytesPerWord; | |
43 const int BytesPerLong = 1 << LogBytesPerLong; | |
44 | |
45 const int LogBitsPerByte = 3; | |
46 const int LogBitsPerShort = LogBitsPerByte + LogBytesPerShort; | |
47 const int LogBitsPerInt = LogBitsPerByte + LogBytesPerInt; | |
48 const int LogBitsPerWord = LogBitsPerByte + LogBytesPerWord; | |
49 const int LogBitsPerLong = LogBitsPerByte + LogBytesPerLong; | |
50 | |
51 const int BitsPerByte = 1 << LogBitsPerByte; | |
52 const int BitsPerShort = 1 << LogBitsPerShort; | |
53 const int BitsPerInt = 1 << LogBitsPerInt; | |
54 const int BitsPerWord = 1 << LogBitsPerWord; | |
55 const int BitsPerLong = 1 << LogBitsPerLong; | |
56 | |
57 const int WordAlignmentMask = (1 << LogBytesPerWord) - 1; | |
58 const int LongAlignmentMask = (1 << LogBytesPerLong) - 1; | |
59 | |
60 const int WordsPerLong = 2; // Number of stack entries for longs | |
61 | |
113
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
29
diff
changeset
|
62 const int oopSize = sizeof(char*); // Full-width oop |
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
29
diff
changeset
|
63 extern int heapOopSize; // Oop within a java object |
0 | 64 const int wordSize = sizeof(char*); |
65 const int longSize = sizeof(jlong); | |
66 const int jintSize = sizeof(jint); | |
67 const int size_tSize = sizeof(size_t); | |
68 | |
113
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
29
diff
changeset
|
69 const int BytesPerOop = BytesPerWord; // Full-width oop |
0 | 70 |
113
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
29
diff
changeset
|
71 extern int LogBytesPerHeapOop; // Oop within a java object |
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
29
diff
changeset
|
72 extern int LogBitsPerHeapOop; |
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
29
diff
changeset
|
73 extern int BytesPerHeapOop; |
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
29
diff
changeset
|
74 extern int BitsPerHeapOop; |
0 | 75 |
76 const int BitsPerJavaInteger = 32; | |
77 const int BitsPerSize_t = size_tSize * BitsPerByte; | |
78 | |
113
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
29
diff
changeset
|
79 // Size of a char[] needed to represent a jint as a string in decimal. |
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
29
diff
changeset
|
80 const int jintAsStringSize = 12; |
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
29
diff
changeset
|
81 |
0 | 82 // In fact this should be |
83 // log2_intptr(sizeof(class JavaThread)) - log2_intptr(64); | |
84 // see os::set_memory_serialize_page() | |
85 #ifdef _LP64 | |
86 const int SerializePageShiftCount = 4; | |
87 #else | |
88 const int SerializePageShiftCount = 3; | |
89 #endif | |
90 | |
91 // An opaque struct of heap-word width, so that HeapWord* can be a generic | |
92 // pointer into the heap. We require that object sizes be measured in | |
93 // units of heap words, so that that | |
94 // HeapWord* hw; | |
95 // hw += oop(hw)->foo(); | |
96 // works, where foo is a method (like size or scavenge) that returns the | |
97 // object size. | |
98 class HeapWord { | |
99 friend class VMStructs; | |
100 private: | |
101 char* i; | |
102 }; | |
103 | |
104 // HeapWordSize must be 2^LogHeapWordSize. | |
113
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
29
diff
changeset
|
105 const int HeapWordSize = sizeof(HeapWord); |
0 | 106 #ifdef _LP64 |
113
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
29
diff
changeset
|
107 const int LogHeapWordSize = 3; |
0 | 108 #else |
113
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
29
diff
changeset
|
109 const int LogHeapWordSize = 2; |
0 | 110 #endif |
113
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
29
diff
changeset
|
111 const int HeapWordsPerLong = BytesPerLong / HeapWordSize; |
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
29
diff
changeset
|
112 const int LogHeapWordsPerLong = LogBytesPerLong - LogHeapWordSize; |
0 | 113 |
114 // The larger HeapWordSize for 64bit requires larger heaps | |
115 // for the same application running in 64bit. See bug 4967770. | |
116 // The minimum alignment to a heap word size is done. Other | |
117 // parts of the memory system may required additional alignment | |
118 // and are responsible for those alignments. | |
119 #ifdef _LP64 | |
120 #define ScaleForWordSize(x) align_size_down_((x) * 13 / 10, HeapWordSize) | |
121 #else | |
122 #define ScaleForWordSize(x) (x) | |
123 #endif | |
124 | |
125 // The minimum number of native machine words necessary to contain "byte_size" | |
126 // bytes. | |
127 inline size_t heap_word_size(size_t byte_size) { | |
128 return (byte_size + (HeapWordSize-1)) >> LogHeapWordSize; | |
129 } | |
130 | |
131 | |
132 const size_t K = 1024; | |
133 const size_t M = K*K; | |
134 const size_t G = M*K; | |
135 const size_t HWperKB = K / sizeof(HeapWord); | |
136 | |
137 const jint min_jint = (jint)1 << (sizeof(jint)*BitsPerByte-1); // 0x80000000 == smallest jint | |
138 const jint max_jint = (juint)min_jint - 1; // 0x7FFFFFFF == largest jint | |
139 | |
140 // Constants for converting from a base unit to milli-base units. For | |
141 // example from seconds to milliseconds and microseconds | |
142 | |
143 const int MILLIUNITS = 1000; // milli units per base unit | |
144 const int MICROUNITS = 1000000; // micro units per base unit | |
145 const int NANOUNITS = 1000000000; // nano units per base unit | |
146 | |
147 inline const char* proper_unit_for_byte_size(size_t s) { | |
148 if (s >= 10*M) { | |
149 return "M"; | |
150 } else if (s >= 10*K) { | |
151 return "K"; | |
152 } else { | |
153 return "B"; | |
154 } | |
155 } | |
156 | |
157 inline size_t byte_size_in_proper_unit(size_t s) { | |
158 if (s >= 10*M) { | |
159 return s/M; | |
160 } else if (s >= 10*K) { | |
161 return s/K; | |
162 } else { | |
163 return s; | |
164 } | |
165 } | |
166 | |
167 | |
168 //---------------------------------------------------------------------------------------------------- | |
169 // VM type definitions | |
170 | |
171 // intx and uintx are the 'extended' int and 'extended' unsigned int types; | |
172 // they are 32bit wide on a 32-bit platform, and 64bit wide on a 64bit platform. | |
173 | |
174 typedef intptr_t intx; | |
175 typedef uintptr_t uintx; | |
176 | |
177 const intx min_intx = (intx)1 << (sizeof(intx)*BitsPerByte-1); | |
178 const intx max_intx = (uintx)min_intx - 1; | |
179 const uintx max_uintx = (uintx)-1; | |
180 | |
181 // Table of values: | |
182 // sizeof intx 4 8 | |
183 // min_intx 0x80000000 0x8000000000000000 | |
184 // max_intx 0x7FFFFFFF 0x7FFFFFFFFFFFFFFF | |
185 // max_uintx 0xFFFFFFFF 0xFFFFFFFFFFFFFFFF | |
186 | |
187 typedef unsigned int uint; NEEDS_CLEANUP | |
188 | |
189 | |
190 //---------------------------------------------------------------------------------------------------- | |
191 // Java type definitions | |
192 | |
193 // All kinds of 'plain' byte addresses | |
194 typedef signed char s_char; | |
195 typedef unsigned char u_char; | |
196 typedef u_char* address; | |
197 typedef uintptr_t address_word; // unsigned integer which will hold a pointer | |
198 // except for some implementations of a C++ | |
199 // linkage pointer to function. Should never | |
200 // need one of those to be placed in this | |
201 // type anyway. | |
202 | |
203 // Utility functions to "portably" (?) bit twiddle pointers | |
204 // Where portable means keep ANSI C++ compilers quiet | |
205 | |
206 inline address set_address_bits(address x, int m) { return address(intptr_t(x) | m); } | |
207 inline address clear_address_bits(address x, int m) { return address(intptr_t(x) & ~m); } | |
208 | |
209 // Utility functions to "portably" make cast to/from function pointers. | |
210 | |
211 inline address_word mask_address_bits(address x, int m) { return address_word(x) & m; } | |
212 inline address_word castable_address(address x) { return address_word(x) ; } | |
213 inline address_word castable_address(void* x) { return address_word(x) ; } | |
214 | |
215 // Pointer subtraction. | |
216 // The idea here is to avoid ptrdiff_t, which is signed and so doesn't have | |
217 // the range we might need to find differences from one end of the heap | |
218 // to the other. | |
219 // A typical use might be: | |
220 // if (pointer_delta(end(), top()) >= size) { | |
221 // // enough room for an object of size | |
222 // ... | |
223 // and then additions like | |
224 // ... top() + size ... | |
225 // are safe because we know that top() is at least size below end(). | |
226 inline size_t pointer_delta(const void* left, | |
227 const void* right, | |
228 size_t element_size) { | |
229 return (((uintptr_t) left) - ((uintptr_t) right)) / element_size; | |
230 } | |
231 // A version specialized for HeapWord*'s. | |
232 inline size_t pointer_delta(const HeapWord* left, const HeapWord* right) { | |
233 return pointer_delta(left, right, sizeof(HeapWord)); | |
234 } | |
235 | |
236 // | |
237 // ANSI C++ does not allow casting from one pointer type to a function pointer | |
238 // directly without at best a warning. This macro accomplishes it silently | |
239 // In every case that is present at this point the value be cast is a pointer | |
240 // to a C linkage function. In somecase the type used for the cast reflects | |
241 // that linkage and a picky compiler would not complain. In other cases because | |
242 // there is no convenient place to place a typedef with extern C linkage (i.e | |
243 // a platform dependent header file) it doesn't. At this point no compiler seems | |
244 // picky enough to catch these instances (which are few). It is possible that | |
245 // using templates could fix these for all cases. This use of templates is likely | |
246 // so far from the middle of the road that it is likely to be problematic in | |
247 // many C++ compilers. | |
248 // | |
249 #define CAST_TO_FN_PTR(func_type, value) ((func_type)(castable_address(value))) | |
250 #define CAST_FROM_FN_PTR(new_type, func_ptr) ((new_type)((address_word)(func_ptr))) | |
251 | |
252 // Unsigned byte types for os and stream.hpp | |
253 | |
254 // Unsigned one, two, four and eigth byte quantities used for describing | |
255 // the .class file format. See JVM book chapter 4. | |
256 | |
257 typedef jubyte u1; | |
258 typedef jushort u2; | |
259 typedef juint u4; | |
260 typedef julong u8; | |
261 | |
262 const jubyte max_jubyte = (jubyte)-1; // 0xFF largest jubyte | |
263 const jushort max_jushort = (jushort)-1; // 0xFFFF largest jushort | |
264 const juint max_juint = (juint)-1; // 0xFFFFFFFF largest juint | |
265 const julong max_julong = (julong)-1; // 0xFF....FF largest julong | |
266 | |
267 //---------------------------------------------------------------------------------------------------- | |
268 // JVM spec restrictions | |
269 | |
270 const int max_method_code_size = 64*K - 1; // JVM spec, 2nd ed. section 4.8.1 (p.134) | |
271 | |
272 | |
273 //---------------------------------------------------------------------------------------------------- | |
274 // HotSwap - for JVMTI aka Class File Replacement and PopFrame | |
275 // | |
276 // Determines whether on-the-fly class replacement and frame popping are enabled. | |
277 | |
278 #define HOTSWAP | |
279 | |
280 //---------------------------------------------------------------------------------------------------- | |
281 // Object alignment, in units of HeapWords. | |
282 // | |
283 // Minimum is max(BytesPerLong, BytesPerDouble, BytesPerOop) / HeapWordSize, so jlong, jdouble and | |
284 // reference fields can be naturally aligned. | |
285 | |
286 const int MinObjAlignment = HeapWordsPerLong; | |
287 const int MinObjAlignmentInBytes = MinObjAlignment * HeapWordSize; | |
288 const int MinObjAlignmentInBytesMask = MinObjAlignmentInBytes - 1; | |
289 | |
113
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
29
diff
changeset
|
290 const int LogMinObjAlignment = LogHeapWordsPerLong; |
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
29
diff
changeset
|
291 const int LogMinObjAlignmentInBytes = LogMinObjAlignment + LogHeapWordSize; |
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
29
diff
changeset
|
292 |
0 | 293 // Machine dependent stuff |
294 | |
295 #include "incls/_globalDefinitions_pd.hpp.incl" | |
296 | |
297 // The byte alignment to be used by Arena::Amalloc. See bugid 4169348. | |
298 // Note: this value must be a power of 2 | |
299 | |
300 #define ARENA_AMALLOC_ALIGNMENT (2*BytesPerWord) | |
301 | |
302 // Signed variants of alignment helpers. There are two versions of each, a macro | |
303 // for use in places like enum definitions that require compile-time constant | |
304 // expressions and a function for all other places so as to get type checking. | |
305 | |
306 #define align_size_up_(size, alignment) (((size) + ((alignment) - 1)) & ~((alignment) - 1)) | |
307 | |
308 inline intptr_t align_size_up(intptr_t size, intptr_t alignment) { | |
309 return align_size_up_(size, alignment); | |
310 } | |
311 | |
312 #define align_size_down_(size, alignment) ((size) & ~((alignment) - 1)) | |
313 | |
314 inline intptr_t align_size_down(intptr_t size, intptr_t alignment) { | |
315 return align_size_down_(size, alignment); | |
316 } | |
317 | |
318 // Align objects by rounding up their size, in HeapWord units. | |
319 | |
320 #define align_object_size_(size) align_size_up_(size, MinObjAlignment) | |
321 | |
322 inline intptr_t align_object_size(intptr_t size) { | |
323 return align_size_up(size, MinObjAlignment); | |
324 } | |
325 | |
326 // Pad out certain offsets to jlong alignment, in HeapWord units. | |
327 | |
328 #define align_object_offset_(offset) align_size_up_(offset, HeapWordsPerLong) | |
329 | |
330 inline intptr_t align_object_offset(intptr_t offset) { | |
331 return align_size_up(offset, HeapWordsPerLong); | |
332 } | |
333 | |
334 inline bool is_object_aligned(intptr_t offset) { | |
335 return offset == align_object_offset(offset); | |
336 } | |
337 | |
338 | |
339 //---------------------------------------------------------------------------------------------------- | |
340 // Utility macros for compilers | |
341 // used to silence compiler warnings | |
342 | |
343 #define Unused_Variable(var) var | |
344 | |
345 | |
346 //---------------------------------------------------------------------------------------------------- | |
347 // Miscellaneous | |
348 | |
349 // 6302670 Eliminate Hotspot __fabsf dependency | |
350 // All fabs() callers should call this function instead, which will implicitly | |
351 // convert the operand to double, avoiding a dependency on __fabsf which | |
352 // doesn't exist in early versions of Solaris 8. | |
353 inline double fabsd(double value) { | |
354 return fabs(value); | |
355 } | |
356 | |
357 inline jint low (jlong value) { return jint(value); } | |
358 inline jint high(jlong value) { return jint(value >> 32); } | |
359 | |
360 // the fancy casts are a hopefully portable way | |
361 // to do unsigned 32 to 64 bit type conversion | |
362 inline void set_low (jlong* value, jint low ) { *value &= (jlong)0xffffffff << 32; | |
363 *value |= (jlong)(julong)(juint)low; } | |
364 | |
365 inline void set_high(jlong* value, jint high) { *value &= (jlong)(julong)(juint)0xffffffff; | |
366 *value |= (jlong)high << 32; } | |
367 | |
368 inline jlong jlong_from(jint h, jint l) { | |
369 jlong result = 0; // initialization to avoid warning | |
370 set_high(&result, h); | |
371 set_low(&result, l); | |
372 return result; | |
373 } | |
374 | |
375 union jlong_accessor { | |
376 jint words[2]; | |
377 jlong long_value; | |
378 }; | |
379 | |
113
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
29
diff
changeset
|
380 void basic_types_init(); // cannot define here; uses assert |
0 | 381 |
382 | |
383 // NOTE: replicated in SA in vm/agent/sun/jvm/hotspot/runtime/BasicType.java | |
384 enum BasicType { | |
385 T_BOOLEAN = 4, | |
386 T_CHAR = 5, | |
387 T_FLOAT = 6, | |
388 T_DOUBLE = 7, | |
389 T_BYTE = 8, | |
390 T_SHORT = 9, | |
391 T_INT = 10, | |
392 T_LONG = 11, | |
393 T_OBJECT = 12, | |
394 T_ARRAY = 13, | |
395 T_VOID = 14, | |
396 T_ADDRESS = 15, | |
113
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
29
diff
changeset
|
397 T_NARROWOOP= 16, |
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
29
diff
changeset
|
398 T_CONFLICT = 17, // for stack value type with conflicting contents |
0 | 399 T_ILLEGAL = 99 |
400 }; | |
401 | |
29
d5fc211aea19
6633953: type2aelembytes{T_ADDRESS} should be 8 bytes in 64 bit VM
kvn
parents:
0
diff
changeset
|
402 inline bool is_java_primitive(BasicType t) { |
d5fc211aea19
6633953: type2aelembytes{T_ADDRESS} should be 8 bytes in 64 bit VM
kvn
parents:
0
diff
changeset
|
403 return T_BOOLEAN <= t && t <= T_LONG; |
d5fc211aea19
6633953: type2aelembytes{T_ADDRESS} should be 8 bytes in 64 bit VM
kvn
parents:
0
diff
changeset
|
404 } |
d5fc211aea19
6633953: type2aelembytes{T_ADDRESS} should be 8 bytes in 64 bit VM
kvn
parents:
0
diff
changeset
|
405 |
0 | 406 // Convert a char from a classfile signature to a BasicType |
407 inline BasicType char2type(char c) { | |
408 switch( c ) { | |
409 case 'B': return T_BYTE; | |
410 case 'C': return T_CHAR; | |
411 case 'D': return T_DOUBLE; | |
412 case 'F': return T_FLOAT; | |
413 case 'I': return T_INT; | |
414 case 'J': return T_LONG; | |
415 case 'S': return T_SHORT; | |
416 case 'Z': return T_BOOLEAN; | |
417 case 'V': return T_VOID; | |
418 case 'L': return T_OBJECT; | |
419 case '[': return T_ARRAY; | |
420 } | |
421 return T_ILLEGAL; | |
422 } | |
423 | |
424 extern char type2char_tab[T_CONFLICT+1]; // Map a BasicType to a jchar | |
425 inline char type2char(BasicType t) { return (uint)t < T_CONFLICT+1 ? type2char_tab[t] : 0; } | |
426 extern int type2size[T_CONFLICT+1]; // Map BasicType to result stack elements | |
427 extern const char* type2name_tab[T_CONFLICT+1]; // Map a BasicType to a jchar | |
428 inline const char* type2name(BasicType t) { return (uint)t < T_CONFLICT+1 ? type2name_tab[t] : NULL; } | |
429 extern BasicType name2type(const char* name); | |
430 | |
431 // Auxilary math routines | |
432 // least common multiple | |
433 extern size_t lcm(size_t a, size_t b); | |
434 | |
435 | |
436 // NOTE: replicated in SA in vm/agent/sun/jvm/hotspot/runtime/BasicType.java | |
437 enum BasicTypeSize { | |
438 T_BOOLEAN_size = 1, | |
439 T_CHAR_size = 1, | |
440 T_FLOAT_size = 1, | |
441 T_DOUBLE_size = 2, | |
442 T_BYTE_size = 1, | |
443 T_SHORT_size = 1, | |
444 T_INT_size = 1, | |
445 T_LONG_size = 2, | |
446 T_OBJECT_size = 1, | |
447 T_ARRAY_size = 1, | |
113
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
29
diff
changeset
|
448 T_NARROWOOP_size = 1, |
0 | 449 T_VOID_size = 0 |
450 }; | |
451 | |
452 | |
453 // maps a BasicType to its instance field storage type: | |
454 // all sub-word integral types are widened to T_INT | |
455 extern BasicType type2field[T_CONFLICT+1]; | |
456 extern BasicType type2wfield[T_CONFLICT+1]; | |
457 | |
458 | |
459 // size in bytes | |
460 enum ArrayElementSize { | |
461 T_BOOLEAN_aelem_bytes = 1, | |
462 T_CHAR_aelem_bytes = 2, | |
463 T_FLOAT_aelem_bytes = 4, | |
464 T_DOUBLE_aelem_bytes = 8, | |
465 T_BYTE_aelem_bytes = 1, | |
466 T_SHORT_aelem_bytes = 2, | |
467 T_INT_aelem_bytes = 4, | |
468 T_LONG_aelem_bytes = 8, | |
469 #ifdef _LP64 | |
470 T_OBJECT_aelem_bytes = 8, | |
471 T_ARRAY_aelem_bytes = 8, | |
472 #else | |
473 T_OBJECT_aelem_bytes = 4, | |
474 T_ARRAY_aelem_bytes = 4, | |
475 #endif | |
113
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
29
diff
changeset
|
476 T_NARROWOOP_aelem_bytes = 4, |
0 | 477 T_VOID_aelem_bytes = 0 |
478 }; | |
479 | |
29
d5fc211aea19
6633953: type2aelembytes{T_ADDRESS} should be 8 bytes in 64 bit VM
kvn
parents:
0
diff
changeset
|
480 extern int _type2aelembytes[T_CONFLICT+1]; // maps a BasicType to nof bytes used by its array element |
d5fc211aea19
6633953: type2aelembytes{T_ADDRESS} should be 8 bytes in 64 bit VM
kvn
parents:
0
diff
changeset
|
481 #ifdef ASSERT |
d5fc211aea19
6633953: type2aelembytes{T_ADDRESS} should be 8 bytes in 64 bit VM
kvn
parents:
0
diff
changeset
|
482 extern int type2aelembytes(BasicType t, bool allow_address = false); // asserts |
d5fc211aea19
6633953: type2aelembytes{T_ADDRESS} should be 8 bytes in 64 bit VM
kvn
parents:
0
diff
changeset
|
483 #else |
d5fc211aea19
6633953: type2aelembytes{T_ADDRESS} should be 8 bytes in 64 bit VM
kvn
parents:
0
diff
changeset
|
484 inline int type2aelembytes(BasicType t) { return _type2aelembytes[t]; } |
d5fc211aea19
6633953: type2aelembytes{T_ADDRESS} should be 8 bytes in 64 bit VM
kvn
parents:
0
diff
changeset
|
485 #endif |
0 | 486 |
487 | |
488 // JavaValue serves as a container for arbitrary Java values. | |
489 | |
490 class JavaValue { | |
491 | |
492 public: | |
493 typedef union JavaCallValue { | |
494 jfloat f; | |
495 jdouble d; | |
496 jint i; | |
497 jlong l; | |
498 jobject h; | |
499 } JavaCallValue; | |
500 | |
501 private: | |
502 BasicType _type; | |
503 JavaCallValue _value; | |
504 | |
505 public: | |
506 JavaValue(BasicType t = T_ILLEGAL) { _type = t; } | |
507 | |
508 JavaValue(jfloat value) { | |
509 _type = T_FLOAT; | |
510 _value.f = value; | |
511 } | |
512 | |
513 JavaValue(jdouble value) { | |
514 _type = T_DOUBLE; | |
515 _value.d = value; | |
516 } | |
517 | |
518 jfloat get_jfloat() const { return _value.f; } | |
519 jdouble get_jdouble() const { return _value.d; } | |
520 jint get_jint() const { return _value.i; } | |
521 jlong get_jlong() const { return _value.l; } | |
522 jobject get_jobject() const { return _value.h; } | |
523 JavaCallValue* get_value_addr() { return &_value; } | |
524 BasicType get_type() const { return _type; } | |
525 | |
526 void set_jfloat(jfloat f) { _value.f = f;} | |
527 void set_jdouble(jdouble d) { _value.d = d;} | |
528 void set_jint(jint i) { _value.i = i;} | |
529 void set_jlong(jlong l) { _value.l = l;} | |
530 void set_jobject(jobject h) { _value.h = h;} | |
531 void set_type(BasicType t) { _type = t; } | |
532 | |
533 jboolean get_jboolean() const { return (jboolean) (_value.i);} | |
534 jbyte get_jbyte() const { return (jbyte) (_value.i);} | |
535 jchar get_jchar() const { return (jchar) (_value.i);} | |
536 jshort get_jshort() const { return (jshort) (_value.i);} | |
537 | |
538 }; | |
539 | |
540 | |
541 #define STACK_BIAS 0 | |
542 // V9 Sparc CPU's running in 64 Bit mode use a stack bias of 7ff | |
543 // in order to extend the reach of the stack pointer. | |
544 #if defined(SPARC) && defined(_LP64) | |
545 #undef STACK_BIAS | |
546 #define STACK_BIAS 0x7ff | |
547 #endif | |
548 | |
549 | |
550 // TosState describes the top-of-stack state before and after the execution of | |
551 // a bytecode or method. The top-of-stack value may be cached in one or more CPU | |
552 // registers. The TosState corresponds to the 'machine represention' of this cached | |
553 // value. There's 4 states corresponding to the JAVA types int, long, float & double | |
554 // as well as a 5th state in case the top-of-stack value is actually on the top | |
555 // of stack (in memory) and thus not cached. The atos state corresponds to the itos | |
556 // state when it comes to machine representation but is used separately for (oop) | |
557 // type specific operations (e.g. verification code). | |
558 | |
559 enum TosState { // describes the tos cache contents | |
560 btos = 0, // byte, bool tos cached | |
561 ctos = 1, // short, char tos cached | |
562 stos = 2, // short, char tos cached | |
563 itos = 3, // int tos cached | |
564 ltos = 4, // long tos cached | |
565 ftos = 5, // float tos cached | |
566 dtos = 6, // double tos cached | |
567 atos = 7, // object cached | |
568 vtos = 8, // tos not cached | |
569 number_of_states, | |
570 ilgl // illegal state: should not occur | |
571 }; | |
572 | |
573 | |
574 inline TosState as_TosState(BasicType type) { | |
575 switch (type) { | |
576 case T_BYTE : return btos; | |
577 case T_BOOLEAN: return btos; | |
578 case T_CHAR : return ctos; | |
579 case T_SHORT : return stos; | |
580 case T_INT : return itos; | |
581 case T_LONG : return ltos; | |
582 case T_FLOAT : return ftos; | |
583 case T_DOUBLE : return dtos; | |
584 case T_VOID : return vtos; | |
585 case T_ARRAY : // fall through | |
586 case T_OBJECT : return atos; | |
587 } | |
588 return ilgl; | |
589 } | |
590 | |
591 | |
592 // Helper function to convert BasicType info into TosState | |
593 // Note: Cannot define here as it uses global constant at the time being. | |
594 TosState as_TosState(BasicType type); | |
595 | |
596 | |
597 // ReferenceType is used to distinguish between java/lang/ref/Reference subclasses | |
598 | |
599 enum ReferenceType { | |
600 REF_NONE, // Regular class | |
601 REF_OTHER, // Subclass of java/lang/ref/Reference, but not subclass of one of the classes below | |
602 REF_SOFT, // Subclass of java/lang/ref/SoftReference | |
603 REF_WEAK, // Subclass of java/lang/ref/WeakReference | |
604 REF_FINAL, // Subclass of java/lang/ref/FinalReference | |
605 REF_PHANTOM // Subclass of java/lang/ref/PhantomReference | |
606 }; | |
607 | |
608 | |
609 // JavaThreadState keeps track of which part of the code a thread is executing in. This | |
610 // information is needed by the safepoint code. | |
611 // | |
612 // There are 4 essential states: | |
613 // | |
614 // _thread_new : Just started, but not executed init. code yet (most likely still in OS init code) | |
615 // _thread_in_native : In native code. This is a safepoint region, since all oops will be in jobject handles | |
616 // _thread_in_vm : Executing in the vm | |
617 // _thread_in_Java : Executing either interpreted or compiled Java code (or could be in a stub) | |
618 // | |
619 // Each state has an associated xxxx_trans state, which is an intermediate state used when a thread is in | |
620 // a transition from one state to another. These extra states makes it possible for the safepoint code to | |
621 // handle certain thread_states without having to suspend the thread - making the safepoint code faster. | |
622 // | |
623 // Given a state, the xxx_trans state can always be found by adding 1. | |
624 // | |
625 enum JavaThreadState { | |
626 _thread_uninitialized = 0, // should never happen (missing initialization) | |
627 _thread_new = 2, // just starting up, i.e., in process of being initialized | |
628 _thread_new_trans = 3, // corresponding transition state (not used, included for completness) | |
629 _thread_in_native = 4, // running in native code | |
630 _thread_in_native_trans = 5, // corresponding transition state | |
631 _thread_in_vm = 6, // running in VM | |
632 _thread_in_vm_trans = 7, // corresponding transition state | |
633 _thread_in_Java = 8, // running in Java or in stub code | |
634 _thread_in_Java_trans = 9, // corresponding transition state (not used, included for completness) | |
635 _thread_blocked = 10, // blocked in vm | |
636 _thread_blocked_trans = 11, // corresponding transition state | |
637 _thread_max_state = 12 // maximum thread state+1 - used for statistics allocation | |
638 }; | |
639 | |
640 | |
641 // Handy constants for deciding which compiler mode to use. | |
642 enum MethodCompilation { | |
643 InvocationEntryBci = -1, // i.e., not a on-stack replacement compilation | |
644 InvalidOSREntryBci = -2 | |
645 }; | |
646 | |
647 // Enumeration to distinguish tiers of compilation | |
648 enum CompLevel { | |
649 CompLevel_none = 0, | |
650 CompLevel_fast_compile = 1, | |
651 CompLevel_full_optimization = 2, | |
652 | |
653 CompLevel_highest_tier = CompLevel_full_optimization, | |
654 #ifdef TIERED | |
655 CompLevel_initial_compile = CompLevel_fast_compile | |
656 #else | |
657 CompLevel_initial_compile = CompLevel_full_optimization | |
658 #endif // TIERED | |
659 }; | |
660 | |
661 inline bool is_tier1_compile(int comp_level) { | |
662 return comp_level == CompLevel_fast_compile; | |
663 } | |
664 inline bool is_tier2_compile(int comp_level) { | |
665 return comp_level == CompLevel_full_optimization; | |
666 } | |
667 inline bool is_highest_tier_compile(int comp_level) { | |
668 return comp_level == CompLevel_highest_tier; | |
669 } | |
670 | |
671 //---------------------------------------------------------------------------------------------------- | |
672 // 'Forward' declarations of frequently used classes | |
673 // (in order to reduce interface dependencies & reduce | |
674 // number of unnecessary compilations after changes) | |
675 | |
676 class symbolTable; | |
677 class ClassFileStream; | |
678 | |
679 class Event; | |
680 | |
681 class Thread; | |
682 class VMThread; | |
683 class JavaThread; | |
684 class Threads; | |
685 | |
686 class VM_Operation; | |
687 class VMOperationQueue; | |
688 | |
689 class CodeBlob; | |
690 class nmethod; | |
691 class OSRAdapter; | |
692 class I2CAdapter; | |
693 class C2IAdapter; | |
694 class CompiledIC; | |
695 class relocInfo; | |
696 class ScopeDesc; | |
697 class PcDesc; | |
698 | |
699 class Recompiler; | |
700 class Recompilee; | |
701 class RecompilationPolicy; | |
702 class RFrame; | |
703 class CompiledRFrame; | |
704 class InterpretedRFrame; | |
705 | |
706 class frame; | |
707 | |
708 class vframe; | |
709 class javaVFrame; | |
710 class interpretedVFrame; | |
711 class compiledVFrame; | |
712 class deoptimizedVFrame; | |
713 class externalVFrame; | |
714 class entryVFrame; | |
715 | |
716 class RegisterMap; | |
717 | |
718 class Mutex; | |
719 class Monitor; | |
720 class BasicLock; | |
721 class BasicObjectLock; | |
722 | |
723 class PeriodicTask; | |
724 | |
725 class JavaCallWrapper; | |
726 | |
727 class oopDesc; | |
728 | |
729 class NativeCall; | |
730 | |
731 class zone; | |
732 | |
733 class StubQueue; | |
734 | |
735 class outputStream; | |
736 | |
737 class ResourceArea; | |
738 | |
739 class DebugInformationRecorder; | |
740 class ScopeValue; | |
741 class CompressedStream; | |
742 class DebugInfoReadStream; | |
743 class DebugInfoWriteStream; | |
744 class LocationValue; | |
745 class ConstantValue; | |
746 class IllegalValue; | |
747 | |
748 class PrivilegedElement; | |
749 class MonitorArray; | |
750 | |
751 class MonitorInfo; | |
752 | |
753 class OffsetClosure; | |
754 class OopMapCache; | |
755 class InterpreterOopMap; | |
756 class OopMapCacheEntry; | |
757 class OSThread; | |
758 | |
759 typedef int (*OSThreadStartFunc)(void*); | |
760 | |
761 class Space; | |
762 | |
763 class JavaValue; | |
764 class methodHandle; | |
765 class JavaCallArguments; | |
766 | |
767 // Basic support for errors (general debug facilities not defined at this point fo the include phase) | |
768 | |
769 extern void basic_fatal(const char* msg); | |
770 | |
771 | |
772 //---------------------------------------------------------------------------------------------------- | |
773 // Special constants for debugging | |
774 | |
775 const jint badInt = -3; // generic "bad int" value | |
776 const long badAddressVal = -2; // generic "bad address" value | |
777 const long badOopVal = -1; // generic "bad oop" value | |
778 const intptr_t badHeapOopVal = (intptr_t) CONST64(0x2BAD4B0BBAADBABE); // value used to zap heap after GC | |
779 const int badHandleValue = 0xBC; // value used to zap vm handle area | |
780 const int badResourceValue = 0xAB; // value used to zap resource area | |
781 const int freeBlockPad = 0xBA; // value used to pad freed blocks. | |
782 const int uninitBlockPad = 0xF1; // value used to zap newly malloc'd blocks. | |
783 const intptr_t badJNIHandleVal = (intptr_t) CONST64(0xFEFEFEFEFEFEFEFE); // value used to zap jni handle area | |
784 const juint badHeapWordVal = 0xBAADBABE; // value used to zap heap after GC | |
785 const int badCodeHeapNewVal= 0xCC; // value used to zap Code heap at allocation | |
786 const int badCodeHeapFreeVal = 0xDD; // value used to zap Code heap at deallocation | |
787 | |
788 | |
789 // (These must be implemented as #defines because C++ compilers are | |
790 // not obligated to inline non-integral constants!) | |
791 #define badAddress ((address)::badAddressVal) | |
792 #define badOop ((oop)::badOopVal) | |
793 #define badHeapWord (::badHeapWordVal) | |
794 #define badJNIHandle ((oop)::badJNIHandleVal) | |
795 | |
796 | |
797 //---------------------------------------------------------------------------------------------------- | |
798 // Utility functions for bitfield manipulations | |
799 | |
800 const intptr_t AllBits = ~0; // all bits set in a word | |
801 const intptr_t NoBits = 0; // no bits set in a word | |
802 const jlong NoLongBits = 0; // no bits set in a long | |
803 const intptr_t OneBit = 1; // only right_most bit set in a word | |
804 | |
805 // get a word with the n.th or the right-most or left-most n bits set | |
806 // (note: #define used only so that they can be used in enum constant definitions) | |
807 #define nth_bit(n) (n >= BitsPerWord ? 0 : OneBit << (n)) | |
808 #define right_n_bits(n) (nth_bit(n) - 1) | |
809 #define left_n_bits(n) (right_n_bits(n) << (n >= BitsPerWord ? 0 : (BitsPerWord - n))) | |
810 | |
811 // bit-operations using a mask m | |
812 inline void set_bits (intptr_t& x, intptr_t m) { x |= m; } | |
813 inline void clear_bits (intptr_t& x, intptr_t m) { x &= ~m; } | |
814 inline intptr_t mask_bits (intptr_t x, intptr_t m) { return x & m; } | |
815 inline jlong mask_long_bits (jlong x, jlong m) { return x & m; } | |
816 inline bool mask_bits_are_true (intptr_t flags, intptr_t mask) { return (flags & mask) == mask; } | |
817 | |
818 // bit-operations using the n.th bit | |
819 inline void set_nth_bit(intptr_t& x, int n) { set_bits (x, nth_bit(n)); } | |
820 inline void clear_nth_bit(intptr_t& x, int n) { clear_bits(x, nth_bit(n)); } | |
821 inline bool is_set_nth_bit(intptr_t x, int n) { return mask_bits (x, nth_bit(n)) != NoBits; } | |
822 | |
823 // returns the bitfield of x starting at start_bit_no with length field_length (no sign-extension!) | |
824 inline intptr_t bitfield(intptr_t x, int start_bit_no, int field_length) { | |
825 return mask_bits(x >> start_bit_no, right_n_bits(field_length)); | |
826 } | |
827 | |
828 | |
829 //---------------------------------------------------------------------------------------------------- | |
830 // Utility functions for integers | |
831 | |
832 // Avoid use of global min/max macros which may cause unwanted double | |
833 // evaluation of arguments. | |
834 #ifdef max | |
835 #undef max | |
836 #endif | |
837 | |
838 #ifdef min | |
839 #undef min | |
840 #endif | |
841 | |
842 #define max(a,b) Do_not_use_max_use_MAX2_instead | |
843 #define min(a,b) Do_not_use_min_use_MIN2_instead | |
844 | |
845 // It is necessary to use templates here. Having normal overloaded | |
846 // functions does not work because it is necessary to provide both 32- | |
847 // and 64-bit overloaded functions, which does not work, and having | |
848 // explicitly-typed versions of these routines (i.e., MAX2I, MAX2L) | |
849 // will be even more error-prone than macros. | |
850 template<class T> inline T MAX2(T a, T b) { return (a > b) ? a : b; } | |
851 template<class T> inline T MIN2(T a, T b) { return (a < b) ? a : b; } | |
852 template<class T> inline T MAX3(T a, T b, T c) { return MAX2(MAX2(a, b), c); } | |
853 template<class T> inline T MIN3(T a, T b, T c) { return MIN2(MIN2(a, b), c); } | |
854 template<class T> inline T MAX4(T a, T b, T c, T d) { return MAX2(MAX3(a, b, c), d); } | |
855 template<class T> inline T MIN4(T a, T b, T c, T d) { return MIN2(MIN3(a, b, c), d); } | |
856 | |
857 template<class T> inline T ABS(T x) { return (x > 0) ? x : -x; } | |
858 | |
859 // true if x is a power of 2, false otherwise | |
860 inline bool is_power_of_2(intptr_t x) { | |
861 return ((x != NoBits) && (mask_bits(x, x - 1) == NoBits)); | |
862 } | |
863 | |
864 // long version of is_power_of_2 | |
865 inline bool is_power_of_2_long(jlong x) { | |
866 return ((x != NoLongBits) && (mask_long_bits(x, x - 1) == NoLongBits)); | |
867 } | |
868 | |
869 //* largest i such that 2^i <= x | |
870 // A negative value of 'x' will return '31' | |
871 inline int log2_intptr(intptr_t x) { | |
872 int i = -1; | |
873 uintptr_t p = 1; | |
874 while (p != 0 && p <= (uintptr_t)x) { | |
875 // p = 2^(i+1) && p <= x (i.e., 2^(i+1) <= x) | |
876 i++; p *= 2; | |
877 } | |
878 // p = 2^(i+1) && x < p (i.e., 2^i <= x < 2^(i+1)) | |
879 // (if p = 0 then overflow occured and i = 31) | |
880 return i; | |
881 } | |
882 | |
883 //* largest i such that 2^i <= x | |
884 // A negative value of 'x' will return '63' | |
885 inline int log2_long(jlong x) { | |
886 int i = -1; | |
887 julong p = 1; | |
888 while (p != 0 && p <= (julong)x) { | |
889 // p = 2^(i+1) && p <= x (i.e., 2^(i+1) <= x) | |
890 i++; p *= 2; | |
891 } | |
892 // p = 2^(i+1) && x < p (i.e., 2^i <= x < 2^(i+1)) | |
145 | 893 // (if p = 0 then overflow occured and i = 63) |
0 | 894 return i; |
895 } | |
896 | |
897 //* the argument must be exactly a power of 2 | |
898 inline int exact_log2(intptr_t x) { | |
899 #ifdef ASSERT | |
900 if (!is_power_of_2(x)) basic_fatal("x must be a power of 2"); | |
901 #endif | |
902 return log2_intptr(x); | |
903 } | |
904 | |
905 | |
906 // returns integer round-up to the nearest multiple of s (s must be a power of two) | |
907 inline intptr_t round_to(intptr_t x, uintx s) { | |
908 #ifdef ASSERT | |
909 if (!is_power_of_2(s)) basic_fatal("s must be a power of 2"); | |
910 #endif | |
911 const uintx m = s - 1; | |
912 return mask_bits(x + m, ~m); | |
913 } | |
914 | |
915 // returns integer round-down to the nearest multiple of s (s must be a power of two) | |
916 inline intptr_t round_down(intptr_t x, uintx s) { | |
917 #ifdef ASSERT | |
918 if (!is_power_of_2(s)) basic_fatal("s must be a power of 2"); | |
919 #endif | |
920 const uintx m = s - 1; | |
921 return mask_bits(x, ~m); | |
922 } | |
923 | |
924 | |
925 inline bool is_odd (intx x) { return x & 1; } | |
926 inline bool is_even(intx x) { return !is_odd(x); } | |
927 | |
928 // "to" should be greater than "from." | |
929 inline intx byte_size(void* from, void* to) { | |
930 return (address)to - (address)from; | |
931 } | |
932 | |
933 //---------------------------------------------------------------------------------------------------- | |
934 // Avoid non-portable casts with these routines (DEPRECATED) | |
935 | |
936 // NOTE: USE Bytes class INSTEAD WHERE POSSIBLE | |
937 // Bytes is optimized machine-specifically and may be much faster then the portable routines below. | |
938 | |
939 // Given sequence of four bytes, build into a 32-bit word | |
940 // following the conventions used in class files. | |
941 // On the 386, this could be realized with a simple address cast. | |
942 // | |
943 | |
944 // This routine takes eight bytes: | |
945 inline u8 build_u8_from( u1 c1, u1 c2, u1 c3, u1 c4, u1 c5, u1 c6, u1 c7, u1 c8 ) { | |
946 return ( u8(c1) << 56 ) & ( u8(0xff) << 56 ) | |
947 | ( u8(c2) << 48 ) & ( u8(0xff) << 48 ) | |
948 | ( u8(c3) << 40 ) & ( u8(0xff) << 40 ) | |
949 | ( u8(c4) << 32 ) & ( u8(0xff) << 32 ) | |
950 | ( u8(c5) << 24 ) & ( u8(0xff) << 24 ) | |
951 | ( u8(c6) << 16 ) & ( u8(0xff) << 16 ) | |
952 | ( u8(c7) << 8 ) & ( u8(0xff) << 8 ) | |
953 | ( u8(c8) << 0 ) & ( u8(0xff) << 0 ); | |
954 } | |
955 | |
956 // This routine takes four bytes: | |
957 inline u4 build_u4_from( u1 c1, u1 c2, u1 c3, u1 c4 ) { | |
958 return ( u4(c1) << 24 ) & 0xff000000 | |
959 | ( u4(c2) << 16 ) & 0x00ff0000 | |
960 | ( u4(c3) << 8 ) & 0x0000ff00 | |
961 | ( u4(c4) << 0 ) & 0x000000ff; | |
962 } | |
963 | |
964 // And this one works if the four bytes are contiguous in memory: | |
965 inline u4 build_u4_from( u1* p ) { | |
966 return build_u4_from( p[0], p[1], p[2], p[3] ); | |
967 } | |
968 | |
969 // Ditto for two-byte ints: | |
970 inline u2 build_u2_from( u1 c1, u1 c2 ) { | |
971 return u2(( u2(c1) << 8 ) & 0xff00 | |
972 | ( u2(c2) << 0 ) & 0x00ff); | |
973 } | |
974 | |
975 // And this one works if the two bytes are contiguous in memory: | |
976 inline u2 build_u2_from( u1* p ) { | |
977 return build_u2_from( p[0], p[1] ); | |
978 } | |
979 | |
980 // Ditto for floats: | |
981 inline jfloat build_float_from( u1 c1, u1 c2, u1 c3, u1 c4 ) { | |
982 u4 u = build_u4_from( c1, c2, c3, c4 ); | |
983 return *(jfloat*)&u; | |
984 } | |
985 | |
986 inline jfloat build_float_from( u1* p ) { | |
987 u4 u = build_u4_from( p ); | |
988 return *(jfloat*)&u; | |
989 } | |
990 | |
991 | |
992 // now (64-bit) longs | |
993 | |
994 inline jlong build_long_from( u1 c1, u1 c2, u1 c3, u1 c4, u1 c5, u1 c6, u1 c7, u1 c8 ) { | |
995 return ( jlong(c1) << 56 ) & ( jlong(0xff) << 56 ) | |
996 | ( jlong(c2) << 48 ) & ( jlong(0xff) << 48 ) | |
997 | ( jlong(c3) << 40 ) & ( jlong(0xff) << 40 ) | |
998 | ( jlong(c4) << 32 ) & ( jlong(0xff) << 32 ) | |
999 | ( jlong(c5) << 24 ) & ( jlong(0xff) << 24 ) | |
1000 | ( jlong(c6) << 16 ) & ( jlong(0xff) << 16 ) | |
1001 | ( jlong(c7) << 8 ) & ( jlong(0xff) << 8 ) | |
1002 | ( jlong(c8) << 0 ) & ( jlong(0xff) << 0 ); | |
1003 } | |
1004 | |
1005 inline jlong build_long_from( u1* p ) { | |
1006 return build_long_from( p[0], p[1], p[2], p[3], p[4], p[5], p[6], p[7] ); | |
1007 } | |
1008 | |
1009 | |
1010 // Doubles, too! | |
1011 inline jdouble build_double_from( u1 c1, u1 c2, u1 c3, u1 c4, u1 c5, u1 c6, u1 c7, u1 c8 ) { | |
1012 jlong u = build_long_from( c1, c2, c3, c4, c5, c6, c7, c8 ); | |
1013 return *(jdouble*)&u; | |
1014 } | |
1015 | |
1016 inline jdouble build_double_from( u1* p ) { | |
1017 jlong u = build_long_from( p ); | |
1018 return *(jdouble*)&u; | |
1019 } | |
1020 | |
1021 | |
1022 // Portable routines to go the other way: | |
1023 | |
1024 inline void explode_short_to( u2 x, u1& c1, u1& c2 ) { | |
1025 c1 = u1(x >> 8); | |
1026 c2 = u1(x); | |
1027 } | |
1028 | |
1029 inline void explode_short_to( u2 x, u1* p ) { | |
1030 explode_short_to( x, p[0], p[1]); | |
1031 } | |
1032 | |
1033 inline void explode_int_to( u4 x, u1& c1, u1& c2, u1& c3, u1& c4 ) { | |
1034 c1 = u1(x >> 24); | |
1035 c2 = u1(x >> 16); | |
1036 c3 = u1(x >> 8); | |
1037 c4 = u1(x); | |
1038 } | |
1039 | |
1040 inline void explode_int_to( u4 x, u1* p ) { | |
1041 explode_int_to( x, p[0], p[1], p[2], p[3]); | |
1042 } | |
1043 | |
1044 | |
1045 // Pack and extract shorts to/from ints: | |
1046 | |
1047 inline int extract_low_short_from_int(jint x) { | |
1048 return x & 0xffff; | |
1049 } | |
1050 | |
1051 inline int extract_high_short_from_int(jint x) { | |
1052 return (x >> 16) & 0xffff; | |
1053 } | |
1054 | |
1055 inline int build_int_from_shorts( jushort low, jushort high ) { | |
1056 return ((int)((unsigned int)high << 16) | (unsigned int)low); | |
1057 } | |
1058 | |
1059 // Printf-style formatters for fixed- and variable-width types as pointers and | |
1060 // integers. | |
1061 // | |
1062 // Each compiler-specific definitions file (e.g., globalDefinitions_gcc.hpp) | |
1063 // must define the macro FORMAT64_MODIFIER, which is the modifier for '%x' or | |
1064 // '%d' formats to indicate a 64-bit quantity; commonly "l" (in LP64) or "ll" | |
1065 // (in ILP32). | |
1066 | |
1067 // Format 32-bit quantities. | |
1068 #define INT32_FORMAT "%d" | |
1069 #define UINT32_FORMAT "%u" | |
1070 #define INT32_FORMAT_W(width) "%" #width "d" | |
1071 #define UINT32_FORMAT_W(width) "%" #width "u" | |
1072 | |
1073 #define PTR32_FORMAT "0x%08x" | |
1074 | |
1075 // Format 64-bit quantities. | |
1076 #define INT64_FORMAT "%" FORMAT64_MODIFIER "d" | |
1077 #define UINT64_FORMAT "%" FORMAT64_MODIFIER "u" | |
1078 #define PTR64_FORMAT "0x%016" FORMAT64_MODIFIER "x" | |
1079 | |
1080 #define INT64_FORMAT_W(width) "%" #width FORMAT64_MODIFIER "d" | |
1081 #define UINT64_FORMAT_W(width) "%" #width FORMAT64_MODIFIER "u" | |
1082 | |
1083 // Format macros that allow the field width to be specified. The width must be | |
1084 // a string literal (e.g., "8") or a macro that evaluates to one. | |
1085 #ifdef _LP64 | |
1086 #define SSIZE_FORMAT_W(width) INT64_FORMAT_W(width) | |
1087 #define SIZE_FORMAT_W(width) UINT64_FORMAT_W(width) | |
1088 #else | |
1089 #define SSIZE_FORMAT_W(width) INT32_FORMAT_W(width) | |
1090 #define SIZE_FORMAT_W(width) UINT32_FORMAT_W(width) | |
1091 #endif // _LP64 | |
1092 | |
1093 // Format pointers and size_t (or size_t-like integer types) which change size | |
1094 // between 32- and 64-bit. | |
1095 #ifdef _LP64 | |
1096 #define PTR_FORMAT PTR64_FORMAT | |
1097 #define UINTX_FORMAT UINT64_FORMAT | |
1098 #define INTX_FORMAT INT64_FORMAT | |
1099 #define SIZE_FORMAT UINT64_FORMAT | |
1100 #define SSIZE_FORMAT INT64_FORMAT | |
1101 #else // !_LP64 | |
1102 #define PTR_FORMAT PTR32_FORMAT | |
1103 #define UINTX_FORMAT UINT32_FORMAT | |
1104 #define INTX_FORMAT INT32_FORMAT | |
1105 #define SIZE_FORMAT UINT32_FORMAT | |
1106 #define SSIZE_FORMAT INT32_FORMAT | |
1107 #endif // _LP64 | |
1108 | |
1109 #define INTPTR_FORMAT PTR_FORMAT | |
1110 | |
1111 // Enable zap-a-lot if in debug version. | |
1112 | |
1113 # ifdef ASSERT | |
1114 # ifdef COMPILER2 | |
1115 # define ENABLE_ZAP_DEAD_LOCALS | |
1116 #endif /* COMPILER2 */ | |
1117 # endif /* ASSERT */ | |
1118 | |
1119 #define ARRAY_SIZE(array) (sizeof(array)/sizeof((array)[0])) |