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