Wed, 14 Oct 2020 17:44:48 +0800
Merge
1 /*
2 * Copyright (c) 1997, 2016, Oracle and/or its affiliates. All rights reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * This code is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation.
8 *
9 * This code is distributed in the hope that it will be useful, but WITHOUT
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
12 * version 2 for more details (a copy is included in the LICENSE file that
13 * accompanied this code).
14 *
15 * You should have received a copy of the GNU General Public License version
16 * 2 along with this work; if not, write to the Free Software Foundation,
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18 *
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20 * or visit www.oracle.com if you need additional information or have any
21 * questions.
22 *
23 */
25 /*
26 * This file has been modified by Loongson Technology in 2015. These
27 * modifications are Copyright (c) 2015 Loongson Technology, and are made
28 * available on the same license terms set forth above.
29 */
31 #ifndef SHARE_VM_UTILITIES_GLOBALDEFINITIONS_HPP
32 #define SHARE_VM_UTILITIES_GLOBALDEFINITIONS_HPP
34 #ifndef __STDC_FORMAT_MACROS
35 #define __STDC_FORMAT_MACROS
36 #endif
38 #ifdef TARGET_COMPILER_gcc
39 # include "utilities/globalDefinitions_gcc.hpp"
40 #endif
41 #ifdef TARGET_COMPILER_visCPP
42 # include "utilities/globalDefinitions_visCPP.hpp"
43 #endif
44 #ifdef TARGET_COMPILER_sparcWorks
45 # include "utilities/globalDefinitions_sparcWorks.hpp"
46 #endif
47 #ifdef TARGET_COMPILER_xlc
48 # include "utilities/globalDefinitions_xlc.hpp"
49 #endif
51 // Defaults for macros that might be defined per compiler.
52 #ifndef NOINLINE
53 #define NOINLINE
54 #endif
55 #ifndef ALWAYSINLINE
56 #define ALWAYSINLINE inline
57 #endif
59 #ifndef PRAGMA_DIAG_PUSH
60 #define PRAGMA_DIAG_PUSH
61 #endif
62 #ifndef PRAGMA_DIAG_POP
63 #define PRAGMA_DIAG_POP
64 #endif
65 #ifndef PRAGMA_FORMAT_NONLITERAL_IGNORED
66 #define PRAGMA_FORMAT_NONLITERAL_IGNORED
67 #endif
68 #ifndef PRAGMA_FORMAT_IGNORED
69 #define PRAGMA_FORMAT_IGNORED
70 #endif
71 #ifndef PRAGMA_FORMAT_NONLITERAL_IGNORED_INTERNAL
72 #define PRAGMA_FORMAT_NONLITERAL_IGNORED_INTERNAL
73 #endif
74 #ifndef PRAGMA_FORMAT_NONLITERAL_IGNORED_EXTERNAL
75 #define PRAGMA_FORMAT_NONLITERAL_IGNORED_EXTERNAL
76 #endif
77 #ifndef PRAGMA_FORMAT_MUTE_WARNINGS_FOR_GCC
78 #define PRAGMA_FORMAT_MUTE_WARNINGS_FOR_GCC
79 #endif
80 #ifndef ATTRIBUTE_PRINTF
81 #define ATTRIBUTE_PRINTF(fmt, vargs)
82 #endif
85 #include "utilities/macros.hpp"
87 // This file holds all globally used constants & types, class (forward)
88 // declarations and a few frequently used utility functions.
90 //----------------------------------------------------------------------------------------------------
91 // Constants
93 const int LogBytesPerShort = 1;
94 const int LogBytesPerInt = 2;
95 #ifdef _LP64
96 const int LogBytesPerWord = 3;
97 #else
98 const int LogBytesPerWord = 2;
99 #endif
100 const int LogBytesPerLong = 3;
102 const int BytesPerShort = 1 << LogBytesPerShort;
103 const int BytesPerInt = 1 << LogBytesPerInt;
104 const int BytesPerWord = 1 << LogBytesPerWord;
105 const int BytesPerLong = 1 << LogBytesPerLong;
107 const int LogBitsPerByte = 3;
108 const int LogBitsPerShort = LogBitsPerByte + LogBytesPerShort;
109 const int LogBitsPerInt = LogBitsPerByte + LogBytesPerInt;
110 const int LogBitsPerWord = LogBitsPerByte + LogBytesPerWord;
111 const int LogBitsPerLong = LogBitsPerByte + LogBytesPerLong;
113 const int BitsPerByte = 1 << LogBitsPerByte;
114 const int BitsPerShort = 1 << LogBitsPerShort;
115 const int BitsPerInt = 1 << LogBitsPerInt;
116 const int BitsPerWord = 1 << LogBitsPerWord;
117 const int BitsPerLong = 1 << LogBitsPerLong;
119 const int WordAlignmentMask = (1 << LogBytesPerWord) - 1;
120 const int LongAlignmentMask = (1 << LogBytesPerLong) - 1;
122 const int WordsPerLong = 2; // Number of stack entries for longs
124 const int oopSize = sizeof(char*); // Full-width oop
125 extern int heapOopSize; // Oop within a java object
126 const int wordSize = sizeof(char*);
127 const int longSize = sizeof(jlong);
128 const int jintSize = sizeof(jint);
129 const int size_tSize = sizeof(size_t);
131 const int BytesPerOop = BytesPerWord; // Full-width oop
133 extern int LogBytesPerHeapOop; // Oop within a java object
134 extern int LogBitsPerHeapOop;
135 extern int BytesPerHeapOop;
136 extern int BitsPerHeapOop;
138 // Oop encoding heap max
139 extern uint64_t OopEncodingHeapMax;
141 const int BitsPerJavaInteger = 32;
142 const int BitsPerJavaLong = 64;
143 const int BitsPerSize_t = size_tSize * BitsPerByte;
145 // Size of a char[] needed to represent a jint as a string in decimal.
146 const int jintAsStringSize = 12;
148 // In fact this should be
149 // log2_intptr(sizeof(class JavaThread)) - log2_intptr(64);
150 // see os::set_memory_serialize_page()
151 #ifdef _LP64
152 const int SerializePageShiftCount = 4;
153 #else
154 const int SerializePageShiftCount = 3;
155 #endif
157 // An opaque struct of heap-word width, so that HeapWord* can be a generic
158 // pointer into the heap. We require that object sizes be measured in
159 // units of heap words, so that that
160 // HeapWord* hw;
161 // hw += oop(hw)->foo();
162 // works, where foo is a method (like size or scavenge) that returns the
163 // object size.
164 class HeapWord {
165 friend class VMStructs;
166 private:
167 char* i;
168 #ifndef PRODUCT
169 public:
170 char* value() { return i; }
171 #endif
172 };
174 // Analogous opaque struct for metadata allocated from
175 // metaspaces.
176 class MetaWord {
177 friend class VMStructs;
178 private:
179 char* i;
180 };
182 // HeapWordSize must be 2^LogHeapWordSize.
183 const int HeapWordSize = sizeof(HeapWord);
184 #ifdef _LP64
185 const int LogHeapWordSize = 3;
186 #else
187 const int LogHeapWordSize = 2;
188 #endif
189 const int HeapWordsPerLong = BytesPerLong / HeapWordSize;
190 const int LogHeapWordsPerLong = LogBytesPerLong - LogHeapWordSize;
192 // The larger HeapWordSize for 64bit requires larger heaps
193 // for the same application running in 64bit. See bug 4967770.
194 // The minimum alignment to a heap word size is done. Other
195 // parts of the memory system may required additional alignment
196 // and are responsible for those alignments.
197 #ifdef _LP64
198 #define ScaleForWordSize(x) align_size_down_((x) * 13 / 10, HeapWordSize)
199 #else
200 #define ScaleForWordSize(x) (x)
201 #endif
203 // The minimum number of native machine words necessary to contain "byte_size"
204 // bytes.
205 inline size_t heap_word_size(size_t byte_size) {
206 return (byte_size + (HeapWordSize-1)) >> LogHeapWordSize;
207 }
210 const size_t K = 1024;
211 const size_t M = K*K;
212 const size_t G = M*K;
213 const size_t HWperKB = K / sizeof(HeapWord);
215 const jint min_jint = (jint)1 << (sizeof(jint)*BitsPerByte-1); // 0x80000000 == smallest jint
216 const jint max_jint = (juint)min_jint - 1; // 0x7FFFFFFF == largest jint
218 // Constants for converting from a base unit to milli-base units. For
219 // example from seconds to milliseconds and microseconds
221 const int MILLIUNITS = 1000; // milli units per base unit
222 const int MICROUNITS = 1000000; // micro units per base unit
223 const int NANOUNITS = 1000000000; // nano units per base unit
225 const jlong NANOSECS_PER_SEC = CONST64(1000000000);
226 const jint NANOSECS_PER_MILLISEC = 1000000;
228 // Proper units routines try to maintain at least three significant digits.
229 // In worst case, it would print five significant digits with lower prefix.
230 // G is close to MAX_SIZE on 32-bit platforms, so its product can easily overflow,
231 // and therefore we need to be careful.
233 inline const char* proper_unit_for_byte_size(size_t s) {
234 #ifdef _LP64
235 if (s >= 100*G) {
236 return "G";
237 }
238 #endif
239 if (s >= 100*M) {
240 return "M";
241 } else if (s >= 100*K) {
242 return "K";
243 } else {
244 return "B";
245 }
246 }
248 template <class T>
249 inline T byte_size_in_proper_unit(T s) {
250 #ifdef _LP64
251 if (s >= 100*G) {
252 return (T)(s/G);
253 }
254 #endif
255 if (s >= 100*M) {
256 return (T)(s/M);
257 } else if (s >= 100*K) {
258 return (T)(s/K);
259 } else {
260 return s;
261 }
262 }
264 //----------------------------------------------------------------------------------------------------
265 // VM type definitions
267 // intx and uintx are the 'extended' int and 'extended' unsigned int types;
268 // they are 32bit wide on a 32-bit platform, and 64bit wide on a 64bit platform.
270 typedef intptr_t intx;
271 typedef uintptr_t uintx;
273 const intx min_intx = (intx)1 << (sizeof(intx)*BitsPerByte-1);
274 const intx max_intx = (uintx)min_intx - 1;
275 const uintx max_uintx = (uintx)-1;
277 // Table of values:
278 // sizeof intx 4 8
279 // min_intx 0x80000000 0x8000000000000000
280 // max_intx 0x7FFFFFFF 0x7FFFFFFFFFFFFFFF
281 // max_uintx 0xFFFFFFFF 0xFFFFFFFFFFFFFFFF
283 typedef unsigned int uint; NEEDS_CLEANUP
286 //----------------------------------------------------------------------------------------------------
287 // Java type definitions
289 // All kinds of 'plain' byte addresses
290 typedef signed char s_char;
291 typedef unsigned char u_char;
292 typedef u_char* address;
293 typedef uintptr_t address_word; // unsigned integer which will hold a pointer
294 // except for some implementations of a C++
295 // linkage pointer to function. Should never
296 // need one of those to be placed in this
297 // type anyway.
299 // Utility functions to "portably" (?) bit twiddle pointers
300 // Where portable means keep ANSI C++ compilers quiet
302 inline address set_address_bits(address x, int m) { return address(intptr_t(x) | m); }
303 inline address clear_address_bits(address x, int m) { return address(intptr_t(x) & ~m); }
305 // Utility functions to "portably" make cast to/from function pointers.
307 inline address_word mask_address_bits(address x, int m) { return address_word(x) & m; }
308 inline address_word castable_address(address x) { return address_word(x) ; }
309 inline address_word castable_address(void* x) { return address_word(x) ; }
311 // Pointer subtraction.
312 // The idea here is to avoid ptrdiff_t, which is signed and so doesn't have
313 // the range we might need to find differences from one end of the heap
314 // to the other.
315 // A typical use might be:
316 // if (pointer_delta(end(), top()) >= size) {
317 // // enough room for an object of size
318 // ...
319 // and then additions like
320 // ... top() + size ...
321 // are safe because we know that top() is at least size below end().
322 inline size_t pointer_delta(const void* left,
323 const void* right,
324 size_t element_size) {
325 return (((uintptr_t) left) - ((uintptr_t) right)) / element_size;
326 }
327 // A version specialized for HeapWord*'s.
328 inline size_t pointer_delta(const HeapWord* left, const HeapWord* right) {
329 return pointer_delta(left, right, sizeof(HeapWord));
330 }
331 // A version specialized for MetaWord*'s.
332 inline size_t pointer_delta(const MetaWord* left, const MetaWord* right) {
333 return pointer_delta(left, right, sizeof(MetaWord));
334 }
336 //
337 // ANSI C++ does not allow casting from one pointer type to a function pointer
338 // directly without at best a warning. This macro accomplishes it silently
339 // In every case that is present at this point the value be cast is a pointer
340 // to a C linkage function. In somecase the type used for the cast reflects
341 // that linkage and a picky compiler would not complain. In other cases because
342 // there is no convenient place to place a typedef with extern C linkage (i.e
343 // a platform dependent header file) it doesn't. At this point no compiler seems
344 // picky enough to catch these instances (which are few). It is possible that
345 // using templates could fix these for all cases. This use of templates is likely
346 // so far from the middle of the road that it is likely to be problematic in
347 // many C++ compilers.
348 //
349 #define CAST_TO_FN_PTR(func_type, value) (reinterpret_cast<func_type>(value))
350 #define CAST_FROM_FN_PTR(new_type, func_ptr) ((new_type)((address_word)(func_ptr)))
352 // Unsigned byte types for os and stream.hpp
354 // Unsigned one, two, four and eigth byte quantities used for describing
355 // the .class file format. See JVM book chapter 4.
357 typedef jubyte u1;
358 typedef jushort u2;
359 typedef juint u4;
360 typedef julong u8;
362 const jubyte max_jubyte = (jubyte)-1; // 0xFF largest jubyte
363 const jushort max_jushort = (jushort)-1; // 0xFFFF largest jushort
364 const juint max_juint = (juint)-1; // 0xFFFFFFFF largest juint
365 const julong max_julong = (julong)-1; // 0xFF....FF largest julong
367 typedef jbyte s1;
368 typedef jshort s2;
369 typedef jint s4;
370 typedef jlong s8;
372 //----------------------------------------------------------------------------------------------------
373 // JVM spec restrictions
375 const int max_method_code_size = 64*K - 1; // JVM spec, 2nd ed. section 4.8.1 (p.134)
377 // Default ProtectionDomainCacheSize values
379 const int defaultProtectionDomainCacheSize = NOT_LP64(137) LP64_ONLY(2017);
381 //----------------------------------------------------------------------------------------------------
382 // Default and minimum StringTableSize values
384 const int defaultStringTableSize = NOT_LP64(1009) LP64_ONLY(60013);
385 const int minimumStringTableSize = 1009;
387 const int defaultSymbolTableSize = 20011;
388 const int minimumSymbolTableSize = 1009;
391 //----------------------------------------------------------------------------------------------------
392 // HotSwap - for JVMTI aka Class File Replacement and PopFrame
393 //
394 // Determines whether on-the-fly class replacement and frame popping are enabled.
396 #define HOTSWAP
398 //----------------------------------------------------------------------------------------------------
399 // Object alignment, in units of HeapWords.
400 //
401 // Minimum is max(BytesPerLong, BytesPerDouble, BytesPerOop) / HeapWordSize, so jlong, jdouble and
402 // reference fields can be naturally aligned.
404 extern int MinObjAlignment;
405 extern int MinObjAlignmentInBytes;
406 extern int MinObjAlignmentInBytesMask;
408 extern int LogMinObjAlignment;
409 extern int LogMinObjAlignmentInBytes;
411 const int LogKlassAlignmentInBytes = 3;
412 const int LogKlassAlignment = LogKlassAlignmentInBytes - LogHeapWordSize;
413 const int KlassAlignmentInBytes = 1 << LogKlassAlignmentInBytes;
414 const int KlassAlignment = KlassAlignmentInBytes / HeapWordSize;
416 // Klass encoding metaspace max size
417 const uint64_t KlassEncodingMetaspaceMax = (uint64_t(max_juint) + 1) << LogKlassAlignmentInBytes;
419 // Machine dependent stuff
421 #if defined(X86) && defined(COMPILER2) && !defined(JAVASE_EMBEDDED)
422 // Include Restricted Transactional Memory lock eliding optimization
423 #define INCLUDE_RTM_OPT 1
424 #define RTM_OPT_ONLY(code) code
425 #else
426 #define INCLUDE_RTM_OPT 0
427 #define RTM_OPT_ONLY(code)
428 #endif
429 // States of Restricted Transactional Memory usage.
430 enum RTMState {
431 NoRTM = 0x2, // Don't use RTM
432 UseRTM = 0x1, // Use RTM
433 ProfileRTM = 0x0 // Use RTM with abort ratio calculation
434 };
436 #ifdef TARGET_ARCH_x86
437 # include "globalDefinitions_x86.hpp"
438 #endif
439 #ifdef TARGET_ARCH_sparc
440 # include "globalDefinitions_sparc.hpp"
441 #endif
442 #ifdef TARGET_ARCH_zero
443 # include "globalDefinitions_zero.hpp"
444 #endif
445 #ifdef TARGET_ARCH_arm
446 # include "globalDefinitions_arm.hpp"
447 #endif
448 #ifdef TARGET_ARCH_ppc
449 # include "globalDefinitions_ppc.hpp"
450 #endif
451 #ifdef TARGET_ARCH_mips
452 # include "globalDefinitions_mips.hpp"
453 #endif
455 /*
456 * If a platform does not support native stack walking
457 * the platform specific globalDefinitions (above)
458 * can set PLATFORM_NATIVE_STACK_WALKING_SUPPORTED to 0
459 */
460 #ifndef PLATFORM_NATIVE_STACK_WALKING_SUPPORTED
461 #define PLATFORM_NATIVE_STACK_WALKING_SUPPORTED 1
462 #endif
464 // To assure the IRIW property on processors that are not multiple copy
465 // atomic, sync instructions must be issued between volatile reads to
466 // assure their ordering, instead of after volatile stores.
467 // (See "A Tutorial Introduction to the ARM and POWER Relaxed Memory Models"
468 // by Luc Maranget, Susmit Sarkar and Peter Sewell, INRIA/Cambridge)
469 #ifdef CPU_NOT_MULTIPLE_COPY_ATOMIC
470 const bool support_IRIW_for_not_multiple_copy_atomic_cpu = true;
471 #else
472 const bool support_IRIW_for_not_multiple_copy_atomic_cpu = false;
473 #endif
475 // The byte alignment to be used by Arena::Amalloc. See bugid 4169348.
476 // Note: this value must be a power of 2
478 #define ARENA_AMALLOC_ALIGNMENT (2*BytesPerWord)
480 // Signed variants of alignment helpers. There are two versions of each, a macro
481 // for use in places like enum definitions that require compile-time constant
482 // expressions and a function for all other places so as to get type checking.
484 #define align_size_up_(size, alignment) (((size) + ((alignment) - 1)) & ~((alignment) - 1))
486 inline bool is_size_aligned(size_t size, size_t alignment) {
487 return align_size_up_(size, alignment) == size;
488 }
490 inline bool is_ptr_aligned(void* ptr, size_t alignment) {
491 return align_size_up_((intptr_t)ptr, (intptr_t)alignment) == (intptr_t)ptr;
492 }
494 inline intptr_t align_size_up(intptr_t size, intptr_t alignment) {
495 return align_size_up_(size, alignment);
496 }
498 #define align_size_down_(size, alignment) ((size) & ~((alignment) - 1))
500 inline intptr_t align_size_down(intptr_t size, intptr_t alignment) {
501 return align_size_down_(size, alignment);
502 }
504 #define is_size_aligned_(size, alignment) ((size) == (align_size_up_(size, alignment)))
506 inline void* align_ptr_up(void* ptr, size_t alignment) {
507 return (void*)align_size_up((intptr_t)ptr, (intptr_t)alignment);
508 }
510 inline void* align_ptr_down(void* ptr, size_t alignment) {
511 return (void*)align_size_down((intptr_t)ptr, (intptr_t)alignment);
512 }
514 // Align objects by rounding up their size, in HeapWord units.
516 #define align_object_size_(size) align_size_up_(size, MinObjAlignment)
518 inline intptr_t align_object_size(intptr_t size) {
519 return align_size_up(size, MinObjAlignment);
520 }
522 inline bool is_object_aligned(intptr_t addr) {
523 return addr == align_object_size(addr);
524 }
526 // Pad out certain offsets to jlong alignment, in HeapWord units.
528 inline intptr_t align_object_offset(intptr_t offset) {
529 return align_size_up(offset, HeapWordsPerLong);
530 }
532 inline void* align_pointer_up(const void* addr, size_t size) {
533 return (void*) align_size_up_((uintptr_t)addr, size);
534 }
536 // Align down with a lower bound. If the aligning results in 0, return 'alignment'.
538 inline size_t align_size_down_bounded(size_t size, size_t alignment) {
539 size_t aligned_size = align_size_down_(size, alignment);
540 return aligned_size > 0 ? aligned_size : alignment;
541 }
543 // Clamp an address to be within a specific page
544 // 1. If addr is on the page it is returned as is
545 // 2. If addr is above the page_address the start of the *next* page will be returned
546 // 3. Otherwise, if addr is below the page_address the start of the page will be returned
547 inline address clamp_address_in_page(address addr, address page_address, intptr_t page_size) {
548 if (align_size_down(intptr_t(addr), page_size) == align_size_down(intptr_t(page_address), page_size)) {
549 // address is in the specified page, just return it as is
550 return addr;
551 } else if (addr > page_address) {
552 // address is above specified page, return start of next page
553 return (address)align_size_down(intptr_t(page_address), page_size) + page_size;
554 } else {
555 // address is below specified page, return start of page
556 return (address)align_size_down(intptr_t(page_address), page_size);
557 }
558 }
561 // The expected size in bytes of a cache line, used to pad data structures.
562 #define DEFAULT_CACHE_LINE_SIZE 64
565 //----------------------------------------------------------------------------------------------------
566 // Utility macros for compilers
567 // used to silence compiler warnings
569 #define Unused_Variable(var) var
572 //----------------------------------------------------------------------------------------------------
573 // Miscellaneous
575 // 6302670 Eliminate Hotspot __fabsf dependency
576 // All fabs() callers should call this function instead, which will implicitly
577 // convert the operand to double, avoiding a dependency on __fabsf which
578 // doesn't exist in early versions of Solaris 8.
579 inline double fabsd(double value) {
580 return fabs(value);
581 }
583 //----------------------------------------------------------------------------------------------------
584 // Special casts
585 // Cast floats into same-size integers and vice-versa w/o changing bit-pattern
586 typedef union {
587 jfloat f;
588 jint i;
589 } FloatIntConv;
591 typedef union {
592 jdouble d;
593 jlong l;
594 julong ul;
595 } DoubleLongConv;
597 inline jint jint_cast (jfloat x) { return ((FloatIntConv*)&x)->i; }
598 inline jfloat jfloat_cast (jint x) { return ((FloatIntConv*)&x)->f; }
600 inline jlong jlong_cast (jdouble x) { return ((DoubleLongConv*)&x)->l; }
601 inline julong julong_cast (jdouble x) { return ((DoubleLongConv*)&x)->ul; }
602 inline jdouble jdouble_cast (jlong x) { return ((DoubleLongConv*)&x)->d; }
604 inline jint low (jlong value) { return jint(value); }
605 inline jint high(jlong value) { return jint(value >> 32); }
607 // the fancy casts are a hopefully portable way
608 // to do unsigned 32 to 64 bit type conversion
609 inline void set_low (jlong* value, jint low ) { *value &= (jlong)0xffffffff << 32;
610 *value |= (jlong)(julong)(juint)low; }
612 inline void set_high(jlong* value, jint high) { *value &= (jlong)(julong)(juint)0xffffffff;
613 *value |= (jlong)high << 32; }
615 inline jlong jlong_from(jint h, jint l) {
616 jlong result = 0; // initialization to avoid warning
617 set_high(&result, h);
618 set_low(&result, l);
619 return result;
620 }
622 union jlong_accessor {
623 jint words[2];
624 jlong long_value;
625 };
627 void basic_types_init(); // cannot define here; uses assert
630 // NOTE: replicated in SA in vm/agent/sun/jvm/hotspot/runtime/BasicType.java
631 enum BasicType {
632 T_BOOLEAN = 4,
633 T_CHAR = 5,
634 T_FLOAT = 6,
635 T_DOUBLE = 7,
636 T_BYTE = 8,
637 T_SHORT = 9,
638 T_INT = 10,
639 T_LONG = 11,
640 T_OBJECT = 12,
641 T_ARRAY = 13,
642 T_VOID = 14,
643 T_ADDRESS = 15,
644 T_NARROWOOP = 16,
645 T_METADATA = 17,
646 T_NARROWKLASS = 18,
647 T_CONFLICT = 19, // for stack value type with conflicting contents
648 T_ILLEGAL = 99
649 };
651 inline bool is_java_primitive(BasicType t) {
652 return T_BOOLEAN <= t && t <= T_LONG;
653 }
655 inline bool is_subword_type(BasicType t) {
656 // these guys are processed exactly like T_INT in calling sequences:
657 return (t == T_BOOLEAN || t == T_CHAR || t == T_BYTE || t == T_SHORT);
658 }
660 inline bool is_signed_subword_type(BasicType t) {
661 return (t == T_BYTE || t == T_SHORT);
662 }
664 inline bool is_reference_type(BasicType t) {
665 return (t == T_OBJECT || t == T_ARRAY);
666 }
668 // Convert a char from a classfile signature to a BasicType
669 inline BasicType char2type(char c) {
670 switch( c ) {
671 case 'B': return T_BYTE;
672 case 'C': return T_CHAR;
673 case 'D': return T_DOUBLE;
674 case 'F': return T_FLOAT;
675 case 'I': return T_INT;
676 case 'J': return T_LONG;
677 case 'S': return T_SHORT;
678 case 'Z': return T_BOOLEAN;
679 case 'V': return T_VOID;
680 case 'L': return T_OBJECT;
681 case '[': return T_ARRAY;
682 }
683 return T_ILLEGAL;
684 }
686 extern char type2char_tab[T_CONFLICT+1]; // Map a BasicType to a jchar
687 inline char type2char(BasicType t) { return (uint)t < T_CONFLICT+1 ? type2char_tab[t] : 0; }
688 extern int type2size[T_CONFLICT+1]; // Map BasicType to result stack elements
689 extern const char* type2name_tab[T_CONFLICT+1]; // Map a BasicType to a jchar
690 inline const char* type2name(BasicType t) { return (uint)t < T_CONFLICT+1 ? type2name_tab[t] : NULL; }
691 extern BasicType name2type(const char* name);
693 // Auxilary math routines
694 // least common multiple
695 extern size_t lcm(size_t a, size_t b);
698 // NOTE: replicated in SA in vm/agent/sun/jvm/hotspot/runtime/BasicType.java
699 enum BasicTypeSize {
700 T_BOOLEAN_size = 1,
701 T_CHAR_size = 1,
702 T_FLOAT_size = 1,
703 T_DOUBLE_size = 2,
704 T_BYTE_size = 1,
705 T_SHORT_size = 1,
706 T_INT_size = 1,
707 T_LONG_size = 2,
708 T_OBJECT_size = 1,
709 T_ARRAY_size = 1,
710 T_NARROWOOP_size = 1,
711 T_NARROWKLASS_size = 1,
712 T_VOID_size = 0
713 };
716 // maps a BasicType to its instance field storage type:
717 // all sub-word integral types are widened to T_INT
718 extern BasicType type2field[T_CONFLICT+1];
719 extern BasicType type2wfield[T_CONFLICT+1];
722 // size in bytes
723 enum ArrayElementSize {
724 T_BOOLEAN_aelem_bytes = 1,
725 T_CHAR_aelem_bytes = 2,
726 T_FLOAT_aelem_bytes = 4,
727 T_DOUBLE_aelem_bytes = 8,
728 T_BYTE_aelem_bytes = 1,
729 T_SHORT_aelem_bytes = 2,
730 T_INT_aelem_bytes = 4,
731 T_LONG_aelem_bytes = 8,
732 #ifdef _LP64
733 T_OBJECT_aelem_bytes = 8,
734 T_ARRAY_aelem_bytes = 8,
735 #else
736 T_OBJECT_aelem_bytes = 4,
737 T_ARRAY_aelem_bytes = 4,
738 #endif
739 T_NARROWOOP_aelem_bytes = 4,
740 T_NARROWKLASS_aelem_bytes = 4,
741 T_VOID_aelem_bytes = 0
742 };
744 extern int _type2aelembytes[T_CONFLICT+1]; // maps a BasicType to nof bytes used by its array element
745 #ifdef ASSERT
746 extern int type2aelembytes(BasicType t, bool allow_address = false); // asserts
747 #else
748 inline int type2aelembytes(BasicType t, bool allow_address = false) { return _type2aelembytes[t]; }
749 #endif
752 // JavaValue serves as a container for arbitrary Java values.
754 class JavaValue {
756 public:
757 typedef union JavaCallValue {
758 jfloat f;
759 jdouble d;
760 jint i;
761 jlong l;
762 jobject h;
763 } JavaCallValue;
765 private:
766 BasicType _type;
767 JavaCallValue _value;
769 public:
770 JavaValue(BasicType t = T_ILLEGAL) { _type = t; }
772 JavaValue(jfloat value) {
773 _type = T_FLOAT;
774 _value.f = value;
775 }
777 JavaValue(jdouble value) {
778 _type = T_DOUBLE;
779 _value.d = value;
780 }
782 jfloat get_jfloat() const { return _value.f; }
783 jdouble get_jdouble() const { return _value.d; }
784 jint get_jint() const { return _value.i; }
785 jlong get_jlong() const { return _value.l; }
786 jobject get_jobject() const { return _value.h; }
787 JavaCallValue* get_value_addr() { return &_value; }
788 BasicType get_type() const { return _type; }
790 void set_jfloat(jfloat f) { _value.f = f;}
791 void set_jdouble(jdouble d) { _value.d = d;}
792 void set_jint(jint i) { _value.i = i;}
793 void set_jlong(jlong l) { _value.l = l;}
794 void set_jobject(jobject h) { _value.h = h;}
795 void set_type(BasicType t) { _type = t; }
797 jboolean get_jboolean() const { return (jboolean) (_value.i);}
798 jbyte get_jbyte() const { return (jbyte) (_value.i);}
799 jchar get_jchar() const { return (jchar) (_value.i);}
800 jshort get_jshort() const { return (jshort) (_value.i);}
802 };
805 #define STACK_BIAS 0
806 // V9 Sparc CPU's running in 64 Bit mode use a stack bias of 7ff
807 // in order to extend the reach of the stack pointer.
808 #if defined(SPARC) && defined(_LP64)
809 #undef STACK_BIAS
810 #define STACK_BIAS 0x7ff
811 #endif
814 // TosState describes the top-of-stack state before and after the execution of
815 // a bytecode or method. The top-of-stack value may be cached in one or more CPU
816 // registers. The TosState corresponds to the 'machine represention' of this cached
817 // value. There's 4 states corresponding to the JAVA types int, long, float & double
818 // as well as a 5th state in case the top-of-stack value is actually on the top
819 // of stack (in memory) and thus not cached. The atos state corresponds to the itos
820 // state when it comes to machine representation but is used separately for (oop)
821 // type specific operations (e.g. verification code).
823 enum TosState { // describes the tos cache contents
824 btos = 0, // byte, bool tos cached
825 ztos = 1, // byte, bool tos cached
826 ctos = 2, // char tos cached
827 stos = 3, // short tos cached
828 itos = 4, // int tos cached
829 ltos = 5, // long tos cached
830 ftos = 6, // float tos cached
831 dtos = 7, // double tos cached
832 atos = 8, // object cached
833 vtos = 9, // tos not cached
834 number_of_states,
835 ilgl // illegal state: should not occur
836 };
839 inline TosState as_TosState(BasicType type) {
840 switch (type) {
841 case T_BYTE : return btos;
842 case T_BOOLEAN: return ztos;
843 case T_CHAR : return ctos;
844 case T_SHORT : return stos;
845 case T_INT : return itos;
846 case T_LONG : return ltos;
847 case T_FLOAT : return ftos;
848 case T_DOUBLE : return dtos;
849 case T_VOID : return vtos;
850 case T_ARRAY : // fall through
851 case T_OBJECT : return atos;
852 }
853 return ilgl;
854 }
856 inline BasicType as_BasicType(TosState state) {
857 switch (state) {
858 case btos : return T_BYTE;
859 case ztos : return T_BOOLEAN;
860 case ctos : return T_CHAR;
861 case stos : return T_SHORT;
862 case itos : return T_INT;
863 case ltos : return T_LONG;
864 case ftos : return T_FLOAT;
865 case dtos : return T_DOUBLE;
866 case atos : return T_OBJECT;
867 case vtos : return T_VOID;
868 }
869 return T_ILLEGAL;
870 }
873 // Helper function to convert BasicType info into TosState
874 // Note: Cannot define here as it uses global constant at the time being.
875 TosState as_TosState(BasicType type);
878 // JavaThreadState keeps track of which part of the code a thread is executing in. This
879 // information is needed by the safepoint code.
880 //
881 // There are 4 essential states:
882 //
883 // _thread_new : Just started, but not executed init. code yet (most likely still in OS init code)
884 // _thread_in_native : In native code. This is a safepoint region, since all oops will be in jobject handles
885 // _thread_in_vm : Executing in the vm
886 // _thread_in_Java : Executing either interpreted or compiled Java code (or could be in a stub)
887 //
888 // Each state has an associated xxxx_trans state, which is an intermediate state used when a thread is in
889 // a transition from one state to another. These extra states makes it possible for the safepoint code to
890 // handle certain thread_states without having to suspend the thread - making the safepoint code faster.
891 //
892 // Given a state, the xxx_trans state can always be found by adding 1.
893 //
894 enum JavaThreadState {
895 _thread_uninitialized = 0, // should never happen (missing initialization)
896 _thread_new = 2, // just starting up, i.e., in process of being initialized
897 _thread_new_trans = 3, // corresponding transition state (not used, included for completness)
898 _thread_in_native = 4, // running in native code
899 _thread_in_native_trans = 5, // corresponding transition state
900 _thread_in_vm = 6, // running in VM
901 _thread_in_vm_trans = 7, // corresponding transition state
902 _thread_in_Java = 8, // running in Java or in stub code
903 _thread_in_Java_trans = 9, // corresponding transition state (not used, included for completness)
904 _thread_blocked = 10, // blocked in vm
905 _thread_blocked_trans = 11, // corresponding transition state
906 _thread_max_state = 12 // maximum thread state+1 - used for statistics allocation
907 };
910 // Handy constants for deciding which compiler mode to use.
911 enum MethodCompilation {
912 InvocationEntryBci = -1, // i.e., not a on-stack replacement compilation
913 InvalidOSREntryBci = -2
914 };
916 // Enumeration to distinguish tiers of compilation
917 enum CompLevel {
918 CompLevel_any = -1,
919 CompLevel_all = -1,
920 CompLevel_none = 0, // Interpreter
921 CompLevel_simple = 1, // C1
922 CompLevel_limited_profile = 2, // C1, invocation & backedge counters
923 CompLevel_full_profile = 3, // C1, invocation & backedge counters + mdo
924 CompLevel_full_optimization = 4, // C2 or Shark
926 #if defined(COMPILER2) || defined(SHARK)
927 CompLevel_highest_tier = CompLevel_full_optimization, // pure C2 and tiered
928 #elif defined(COMPILER1)
929 CompLevel_highest_tier = CompLevel_simple, // pure C1
930 #else
931 CompLevel_highest_tier = CompLevel_none,
932 #endif
934 #if defined(TIERED)
935 CompLevel_initial_compile = CompLevel_full_profile // tiered
936 #elif defined(COMPILER1)
937 CompLevel_initial_compile = CompLevel_simple // pure C1
938 #elif defined(COMPILER2) || defined(SHARK)
939 CompLevel_initial_compile = CompLevel_full_optimization // pure C2
940 #else
941 CompLevel_initial_compile = CompLevel_none
942 #endif
943 };
945 inline bool is_c1_compile(int comp_level) {
946 return comp_level > CompLevel_none && comp_level < CompLevel_full_optimization;
947 }
949 inline bool is_c2_compile(int comp_level) {
950 return comp_level == CompLevel_full_optimization;
951 }
953 inline bool is_highest_tier_compile(int comp_level) {
954 return comp_level == CompLevel_highest_tier;
955 }
957 inline bool is_compile(int comp_level) {
958 return is_c1_compile(comp_level) || is_c2_compile(comp_level);
959 }
961 //----------------------------------------------------------------------------------------------------
962 // 'Forward' declarations of frequently used classes
963 // (in order to reduce interface dependencies & reduce
964 // number of unnecessary compilations after changes)
966 class symbolTable;
967 class ClassFileStream;
969 class Event;
971 class Thread;
972 class VMThread;
973 class JavaThread;
974 class Threads;
976 class VM_Operation;
977 class VMOperationQueue;
979 class CodeBlob;
980 class nmethod;
981 class OSRAdapter;
982 class I2CAdapter;
983 class C2IAdapter;
984 class CompiledIC;
985 class relocInfo;
986 class ScopeDesc;
987 class PcDesc;
989 class Recompiler;
990 class Recompilee;
991 class RecompilationPolicy;
992 class RFrame;
993 class CompiledRFrame;
994 class InterpretedRFrame;
996 class frame;
998 class vframe;
999 class javaVFrame;
1000 class interpretedVFrame;
1001 class compiledVFrame;
1002 class deoptimizedVFrame;
1003 class externalVFrame;
1004 class entryVFrame;
1006 class RegisterMap;
1008 class Mutex;
1009 class Monitor;
1010 class BasicLock;
1011 class BasicObjectLock;
1013 class PeriodicTask;
1015 class JavaCallWrapper;
1017 class oopDesc;
1018 class metaDataOopDesc;
1020 class NativeCall;
1022 class zone;
1024 class StubQueue;
1026 class outputStream;
1028 class ResourceArea;
1030 class DebugInformationRecorder;
1031 class ScopeValue;
1032 class CompressedStream;
1033 class DebugInfoReadStream;
1034 class DebugInfoWriteStream;
1035 class LocationValue;
1036 class ConstantValue;
1037 class IllegalValue;
1039 class PrivilegedElement;
1040 class MonitorArray;
1042 class MonitorInfo;
1044 class OffsetClosure;
1045 class OopMapCache;
1046 class InterpreterOopMap;
1047 class OopMapCacheEntry;
1048 class OSThread;
1050 typedef int (*OSThreadStartFunc)(void*);
1052 class Space;
1054 class JavaValue;
1055 class methodHandle;
1056 class JavaCallArguments;
1058 // Basic support for errors (general debug facilities not defined at this point fo the include phase)
1060 extern void basic_fatal(const char* msg);
1063 //----------------------------------------------------------------------------------------------------
1064 // Special constants for debugging
1066 const jint badInt = -3; // generic "bad int" value
1067 const intptr_t badAddressVal = -2; // generic "bad address" value
1068 const intptr_t badOopVal = -1; // generic "bad oop" value
1069 const intptr_t badHeapOopVal = (intptr_t) CONST64(0x2BAD4B0BBAADBABE); // value used to zap heap after GC
1070 const int badHandleValue = 0xBC; // value used to zap vm handle area
1071 const int badResourceValue = 0xAB; // value used to zap resource area
1072 const int freeBlockPad = 0xBA; // value used to pad freed blocks.
1073 const int uninitBlockPad = 0xF1; // value used to zap newly malloc'd blocks.
1074 const intptr_t badJNIHandleVal = (intptr_t) CONST64(0xFEFEFEFEFEFEFEFE); // value used to zap jni handle area
1075 const juint badHeapWordVal = 0xBAADBABE; // value used to zap heap after GC
1076 const juint badMetaWordVal = 0xBAADFADE; // value used to zap metadata heap after GC
1077 const int badCodeHeapNewVal= 0xCC; // value used to zap Code heap at allocation
1078 const int badCodeHeapFreeVal = 0xDD; // value used to zap Code heap at deallocation
1081 // (These must be implemented as #defines because C++ compilers are
1082 // not obligated to inline non-integral constants!)
1083 #define badAddress ((address)::badAddressVal)
1084 #define badOop (cast_to_oop(::badOopVal))
1085 #define badHeapWord (::badHeapWordVal)
1086 #define badJNIHandle (cast_to_oop(::badJNIHandleVal))
1088 // Default TaskQueue size is 16K (32-bit) or 128K (64-bit)
1089 #define TASKQUEUE_SIZE (NOT_LP64(1<<14) LP64_ONLY(1<<17))
1091 //----------------------------------------------------------------------------------------------------
1092 // Utility functions for bitfield manipulations
1094 const intptr_t AllBits = ~0; // all bits set in a word
1095 const intptr_t NoBits = 0; // no bits set in a word
1096 const jlong NoLongBits = 0; // no bits set in a long
1097 const intptr_t OneBit = 1; // only right_most bit set in a word
1099 // get a word with the n.th or the right-most or left-most n bits set
1100 // (note: #define used only so that they can be used in enum constant definitions)
1101 #define nth_bit(n) (n >= BitsPerWord ? 0 : OneBit << (n))
1102 #define right_n_bits(n) (nth_bit(n) - 1)
1103 #define left_n_bits(n) (right_n_bits(n) << (n >= BitsPerWord ? 0 : (BitsPerWord - n)))
1105 // bit-operations using a mask m
1106 inline void set_bits (intptr_t& x, intptr_t m) { x |= m; }
1107 inline void clear_bits (intptr_t& x, intptr_t m) { x &= ~m; }
1108 inline intptr_t mask_bits (intptr_t x, intptr_t m) { return x & m; }
1109 inline jlong mask_long_bits (jlong x, jlong m) { return x & m; }
1110 inline bool mask_bits_are_true (intptr_t flags, intptr_t mask) { return (flags & mask) == mask; }
1112 // bit-operations using the n.th bit
1113 inline void set_nth_bit(intptr_t& x, int n) { set_bits (x, nth_bit(n)); }
1114 inline void clear_nth_bit(intptr_t& x, int n) { clear_bits(x, nth_bit(n)); }
1115 inline bool is_set_nth_bit(intptr_t x, int n) { return mask_bits (x, nth_bit(n)) != NoBits; }
1117 // returns the bitfield of x starting at start_bit_no with length field_length (no sign-extension!)
1118 inline intptr_t bitfield(intptr_t x, int start_bit_no, int field_length) {
1119 return mask_bits(x >> start_bit_no, right_n_bits(field_length));
1120 }
1123 //----------------------------------------------------------------------------------------------------
1124 // Utility functions for integers
1126 // Avoid use of global min/max macros which may cause unwanted double
1127 // evaluation of arguments.
1128 #ifdef max
1129 #undef max
1130 #endif
1132 #ifdef min
1133 #undef min
1134 #endif
1136 #define max(a,b) Do_not_use_max_use_MAX2_instead
1137 #define min(a,b) Do_not_use_min_use_MIN2_instead
1139 // It is necessary to use templates here. Having normal overloaded
1140 // functions does not work because it is necessary to provide both 32-
1141 // and 64-bit overloaded functions, which does not work, and having
1142 // explicitly-typed versions of these routines (i.e., MAX2I, MAX2L)
1143 // will be even more error-prone than macros.
1144 template<class T> inline T MAX2(T a, T b) { return (a > b) ? a : b; }
1145 template<class T> inline T MIN2(T a, T b) { return (a < b) ? a : b; }
1146 template<class T> inline T MAX3(T a, T b, T c) { return MAX2(MAX2(a, b), c); }
1147 template<class T> inline T MIN3(T a, T b, T c) { return MIN2(MIN2(a, b), c); }
1148 template<class T> inline T MAX4(T a, T b, T c, T d) { return MAX2(MAX3(a, b, c), d); }
1149 template<class T> inline T MIN4(T a, T b, T c, T d) { return MIN2(MIN3(a, b, c), d); }
1151 template<class T> inline T ABS(T x) { return (x > 0) ? x : -x; }
1153 // true if x is a power of 2, false otherwise
1154 inline bool is_power_of_2(intptr_t x) {
1155 return ((x != NoBits) && (mask_bits(x, x - 1) == NoBits));
1156 }
1158 // long version of is_power_of_2
1159 inline bool is_power_of_2_long(jlong x) {
1160 return ((x != NoLongBits) && (mask_long_bits(x, x - 1) == NoLongBits));
1161 }
1163 //* largest i such that 2^i <= x
1164 // A negative value of 'x' will return '31'
1165 inline int log2_intptr(uintptr_t x) {
1166 int i = -1;
1167 uintptr_t p = 1;
1168 while (p != 0 && p <= x) {
1169 // p = 2^(i+1) && p <= x (i.e., 2^(i+1) <= x)
1170 i++; p *= 2;
1171 }
1172 // p = 2^(i+1) && x < p (i.e., 2^i <= x < 2^(i+1))
1173 // (if p = 0 then overflow occurred and i = 31)
1174 return i;
1175 }
1177 //* largest i such that 2^i <= x
1178 inline int log2_long(julong x) {
1179 int i = -1;
1180 julong p = 1;
1181 while (p != 0 && p <= x) {
1182 // p = 2^(i+1) && p <= x (i.e., 2^(i+1) <= x)
1183 i++; p *= 2;
1184 }
1185 // p = 2^(i+1) && x < p (i.e., 2^i <= x < 2^(i+1))
1186 // (if p = 0 then overflow occurred and i = 63)
1187 return i;
1188 }
1190 inline int log2_intptr(intptr_t x) {
1191 return log2_intptr((uintptr_t)x);
1192 }
1194 inline int log2_int(int x) {
1195 return log2_intptr((uintptr_t)x);
1196 }
1198 inline int log2_jint(jint x) {
1199 return log2_intptr((uintptr_t)x);
1200 }
1202 inline int log2_uint(uint x) {
1203 return log2_intptr((uintptr_t)x);
1204 }
1206 // A negative value of 'x' will return '63'
1207 inline int log2_jlong(jlong x) {
1208 return log2_long((julong)x);
1209 }
1211 //* the argument must be exactly a power of 2
1212 inline int exact_log2(intptr_t x) {
1213 #ifdef ASSERT
1214 if (!is_power_of_2(x)) basic_fatal("x must be a power of 2");
1215 #endif
1216 return log2_intptr(x);
1217 }
1219 //* the argument must be exactly a power of 2
1220 inline int exact_log2_long(jlong x) {
1221 #ifdef ASSERT
1222 if (!is_power_of_2_long(x)) basic_fatal("x must be a power of 2");
1223 #endif
1224 return log2_long(x);
1225 }
1228 // returns integer round-up to the nearest multiple of s (s must be a power of two)
1229 inline intptr_t round_to(intptr_t x, uintx s) {
1230 #ifdef ASSERT
1231 if (!is_power_of_2(s)) basic_fatal("s must be a power of 2");
1232 #endif
1233 const uintx m = s - 1;
1234 return mask_bits(x + m, ~m);
1235 }
1237 // returns integer round-down to the nearest multiple of s (s must be a power of two)
1238 inline intptr_t round_down(intptr_t x, uintx s) {
1239 #ifdef ASSERT
1240 if (!is_power_of_2(s)) basic_fatal("s must be a power of 2");
1241 #endif
1242 const uintx m = s - 1;
1243 return mask_bits(x, ~m);
1244 }
1247 inline bool is_odd (intx x) { return x & 1; }
1248 inline bool is_even(intx x) { return !is_odd(x); }
1250 // abs methods which cannot overflow and so are well-defined across
1251 // the entire domain of integer types.
1252 static inline unsigned int uabs(unsigned int n) {
1253 union {
1254 unsigned int result;
1255 int value;
1256 };
1257 result = n;
1258 if (value < 0) result = 0-result;
1259 return result;
1260 }
1261 static inline julong uabs(julong n) {
1262 union {
1263 julong result;
1264 jlong value;
1265 };
1266 result = n;
1267 if (value < 0) result = 0-result;
1268 return result;
1269 }
1270 static inline julong uabs(jlong n) { return uabs((julong)n); }
1271 static inline unsigned int uabs(int n) { return uabs((unsigned int)n); }
1273 // "to" should be greater than "from."
1274 inline intx byte_size(void* from, void* to) {
1275 return (address)to - (address)from;
1276 }
1278 //----------------------------------------------------------------------------------------------------
1279 // Avoid non-portable casts with these routines (DEPRECATED)
1281 // NOTE: USE Bytes class INSTEAD WHERE POSSIBLE
1282 // Bytes is optimized machine-specifically and may be much faster then the portable routines below.
1284 // Given sequence of four bytes, build into a 32-bit word
1285 // following the conventions used in class files.
1286 // On the 386, this could be realized with a simple address cast.
1287 //
1289 // This routine takes eight bytes:
1290 inline u8 build_u8_from( u1 c1, u1 c2, u1 c3, u1 c4, u1 c5, u1 c6, u1 c7, u1 c8 ) {
1291 return (( u8(c1) << 56 ) & ( u8(0xff) << 56 ))
1292 | (( u8(c2) << 48 ) & ( u8(0xff) << 48 ))
1293 | (( u8(c3) << 40 ) & ( u8(0xff) << 40 ))
1294 | (( u8(c4) << 32 ) & ( u8(0xff) << 32 ))
1295 | (( u8(c5) << 24 ) & ( u8(0xff) << 24 ))
1296 | (( u8(c6) << 16 ) & ( u8(0xff) << 16 ))
1297 | (( u8(c7) << 8 ) & ( u8(0xff) << 8 ))
1298 | (( u8(c8) << 0 ) & ( u8(0xff) << 0 ));
1299 }
1301 // This routine takes four bytes:
1302 inline u4 build_u4_from( u1 c1, u1 c2, u1 c3, u1 c4 ) {
1303 return (( u4(c1) << 24 ) & 0xff000000)
1304 | (( u4(c2) << 16 ) & 0x00ff0000)
1305 | (( u4(c3) << 8 ) & 0x0000ff00)
1306 | (( u4(c4) << 0 ) & 0x000000ff);
1307 }
1309 // And this one works if the four bytes are contiguous in memory:
1310 inline u4 build_u4_from( u1* p ) {
1311 return build_u4_from( p[0], p[1], p[2], p[3] );
1312 }
1314 // Ditto for two-byte ints:
1315 inline u2 build_u2_from( u1 c1, u1 c2 ) {
1316 return u2((( u2(c1) << 8 ) & 0xff00)
1317 | (( u2(c2) << 0 ) & 0x00ff));
1318 }
1320 // And this one works if the two bytes are contiguous in memory:
1321 inline u2 build_u2_from( u1* p ) {
1322 return build_u2_from( p[0], p[1] );
1323 }
1325 // Ditto for floats:
1326 inline jfloat build_float_from( u1 c1, u1 c2, u1 c3, u1 c4 ) {
1327 u4 u = build_u4_from( c1, c2, c3, c4 );
1328 return *(jfloat*)&u;
1329 }
1331 inline jfloat build_float_from( u1* p ) {
1332 u4 u = build_u4_from( p );
1333 return *(jfloat*)&u;
1334 }
1337 // now (64-bit) longs
1339 inline jlong build_long_from( u1 c1, u1 c2, u1 c3, u1 c4, u1 c5, u1 c6, u1 c7, u1 c8 ) {
1340 return (( jlong(c1) << 56 ) & ( jlong(0xff) << 56 ))
1341 | (( jlong(c2) << 48 ) & ( jlong(0xff) << 48 ))
1342 | (( jlong(c3) << 40 ) & ( jlong(0xff) << 40 ))
1343 | (( jlong(c4) << 32 ) & ( jlong(0xff) << 32 ))
1344 | (( jlong(c5) << 24 ) & ( jlong(0xff) << 24 ))
1345 | (( jlong(c6) << 16 ) & ( jlong(0xff) << 16 ))
1346 | (( jlong(c7) << 8 ) & ( jlong(0xff) << 8 ))
1347 | (( jlong(c8) << 0 ) & ( jlong(0xff) << 0 ));
1348 }
1350 inline jlong build_long_from( u1* p ) {
1351 return build_long_from( p[0], p[1], p[2], p[3], p[4], p[5], p[6], p[7] );
1352 }
1355 // Doubles, too!
1356 inline jdouble build_double_from( u1 c1, u1 c2, u1 c3, u1 c4, u1 c5, u1 c6, u1 c7, u1 c8 ) {
1357 jlong u = build_long_from( c1, c2, c3, c4, c5, c6, c7, c8 );
1358 return *(jdouble*)&u;
1359 }
1361 inline jdouble build_double_from( u1* p ) {
1362 jlong u = build_long_from( p );
1363 return *(jdouble*)&u;
1364 }
1367 // Portable routines to go the other way:
1369 inline void explode_short_to( u2 x, u1& c1, u1& c2 ) {
1370 c1 = u1(x >> 8);
1371 c2 = u1(x);
1372 }
1374 inline void explode_short_to( u2 x, u1* p ) {
1375 explode_short_to( x, p[0], p[1]);
1376 }
1378 inline void explode_int_to( u4 x, u1& c1, u1& c2, u1& c3, u1& c4 ) {
1379 c1 = u1(x >> 24);
1380 c2 = u1(x >> 16);
1381 c3 = u1(x >> 8);
1382 c4 = u1(x);
1383 }
1385 inline void explode_int_to( u4 x, u1* p ) {
1386 explode_int_to( x, p[0], p[1], p[2], p[3]);
1387 }
1390 // Pack and extract shorts to/from ints:
1392 inline int extract_low_short_from_int(jint x) {
1393 return x & 0xffff;
1394 }
1396 inline int extract_high_short_from_int(jint x) {
1397 return (x >> 16) & 0xffff;
1398 }
1400 inline int build_int_from_shorts( jushort low, jushort high ) {
1401 return ((int)((unsigned int)high << 16) | (unsigned int)low);
1402 }
1404 // Convert pointer to intptr_t, for use in printing pointers.
1405 inline intptr_t p2i(const void * p) {
1406 return (intptr_t) p;
1407 }
1409 // Printf-style formatters for fixed- and variable-width types as pointers and
1410 // integers. These are derived from the definitions in inttypes.h. If the platform
1411 // doesn't provide appropriate definitions, they should be provided in
1412 // the compiler-specific definitions file (e.g., globalDefinitions_gcc.hpp)
1414 #define BOOL_TO_STR(_b_) ((_b_) ? "true" : "false")
1416 // Format 32-bit quantities.
1417 #define INT32_FORMAT "%" PRId32
1418 #define UINT32_FORMAT "%" PRIu32
1419 #define INT32_FORMAT_W(width) "%" #width PRId32
1420 #define UINT32_FORMAT_W(width) "%" #width PRIu32
1422 #define PTR32_FORMAT "0x%08" PRIx32
1424 // Format 64-bit quantities.
1425 #define INT64_FORMAT "%" PRId64
1426 #define UINT64_FORMAT "%" PRIu64
1427 #define UINT64_FORMAT_X "%" PRIx64
1428 #define INT64_FORMAT_W(width) "%" #width PRId64
1429 #define UINT64_FORMAT_W(width) "%" #width PRIu64
1431 #define PTR64_FORMAT "0x%016" PRIx64
1433 // Format jlong, if necessary
1434 #ifndef JLONG_FORMAT
1435 #define JLONG_FORMAT INT64_FORMAT
1436 #endif
1437 #ifndef JULONG_FORMAT
1438 #define JULONG_FORMAT UINT64_FORMAT
1439 #endif
1441 // Format pointers which change size between 32- and 64-bit.
1442 #ifdef _LP64
1443 #define INTPTR_FORMAT "0x%016" PRIxPTR
1444 #define PTR_FORMAT "0x%016" PRIxPTR
1445 #else // !_LP64
1446 #define INTPTR_FORMAT "0x%08" PRIxPTR
1447 #define PTR_FORMAT "0x%08" PRIxPTR
1448 #endif // _LP64
1450 #define INTPTR_FORMAT_W(width) "%" #width PRIxPTR
1452 #define SSIZE_FORMAT "%" PRIdPTR
1453 #define SIZE_FORMAT "%" PRIuPTR
1454 #define SIZE_FORMAT_HEX "0x%" PRIxPTR
1455 #define SSIZE_FORMAT_W(width) "%" #width PRIdPTR
1456 #define SIZE_FORMAT_W(width) "%" #width PRIuPTR
1457 #define SIZE_FORMAT_HEX_W(width) "0x%" #width PRIxPTR
1459 #define INTX_FORMAT "%" PRIdPTR
1460 #define UINTX_FORMAT "%" PRIuPTR
1461 #define INTX_FORMAT_W(width) "%" #width PRIdPTR
1462 #define UINTX_FORMAT_W(width) "%" #width PRIuPTR
1465 // Enable zap-a-lot if in debug version.
1467 # ifdef ASSERT
1468 # ifdef COMPILER2
1469 # define ENABLE_ZAP_DEAD_LOCALS
1470 #endif /* COMPILER2 */
1471 # endif /* ASSERT */
1473 #define ARRAY_SIZE(array) (sizeof(array)/sizeof((array)[0]))
1475 //----------------------------------------------------------------------------------------------------
1476 // Sum and product which can never overflow: they wrap, just like the
1477 // Java operations. Note that we don't intend these to be used for
1478 // general-purpose arithmetic: their purpose is to emulate Java
1479 // operations.
1481 // The goal of this code to avoid undefined or implementation-defined
1482 // behaviour. The use of an lvalue to reference cast is explicitly
1483 // permitted by Lvalues and rvalues [basic.lval]. [Section 3.10 Para
1484 // 15 in C++03]
1485 #define JAVA_INTEGER_OP(OP, NAME, TYPE, UNSIGNED_TYPE) \
1486 inline TYPE NAME (TYPE in1, TYPE in2) { \
1487 UNSIGNED_TYPE ures = static_cast<UNSIGNED_TYPE>(in1); \
1488 ures OP ## = static_cast<UNSIGNED_TYPE>(in2); \
1489 return reinterpret_cast<TYPE&>(ures); \
1490 }
1492 JAVA_INTEGER_OP(+, java_add, jint, juint)
1493 JAVA_INTEGER_OP(-, java_subtract, jint, juint)
1494 JAVA_INTEGER_OP(*, java_multiply, jint, juint)
1495 JAVA_INTEGER_OP(+, java_add, jlong, julong)
1496 JAVA_INTEGER_OP(-, java_subtract, jlong, julong)
1497 JAVA_INTEGER_OP(*, java_multiply, jlong, julong)
1499 #undef JAVA_INTEGER_OP
1501 // Dereference vptr
1502 // All C++ compilers that we know of have the vtbl pointer in the first
1503 // word. If there are exceptions, this function needs to be made compiler
1504 // specific.
1505 static inline void* dereference_vptr(const void* addr) {
1506 return *(void**)addr;
1507 }
1509 #ifndef PRODUCT
1511 // For unit testing only
1512 class GlobalDefinitions {
1513 public:
1514 static void test_globals();
1515 static void test_proper_unit();
1516 };
1518 #endif // PRODUCT
1520 #endif // SHARE_VM_UTILITIES_GLOBALDEFINITIONS_HPP