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