src/share/vm/utilities/globalDefinitions.hpp

Wed, 27 Apr 2016 01:25:04 +0800

author
aoqi
date
Wed, 27 Apr 2016 01:25:04 +0800
changeset 0
f90c822e73f8
child 1
2d8a650513c2
permissions
-rw-r--r--

Initial load
http://hg.openjdk.java.net/jdk8u/jdk8u/hotspot/
changeset: 6782:28b50d07f6f8
tag: jdk8u25-b17

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

mercurial