src/share/vm/utilities/globalDefinitions.cpp

Tue, 24 Jul 2018 13:22:11 +0800

author
aoqi
date
Tue, 24 Jul 2018 13:22:11 +0800
changeset 9137
dc1769738300
parent 6876
710a3c8b516e
child 9703
2fdf635bcf28
permissions
-rw-r--r--

#7048 added Loongson release info to hs_err crash files

aoqi@0 1 /*
aoqi@0 2 * Copyright (c) 1997, 2013, 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 #include "precompiled.hpp"
aoqi@0 26 #include "runtime/os.hpp"
aoqi@0 27 #include "utilities/globalDefinitions.hpp"
aoqi@0 28 #include "utilities/top.hpp"
aoqi@0 29
aoqi@0 30 // Basic error support
aoqi@0 31
aoqi@0 32 // Info for oops within a java object. Defaults are zero so
aoqi@0 33 // things will break badly if incorrectly initialized.
aoqi@0 34 int heapOopSize = 0;
aoqi@0 35 int LogBytesPerHeapOop = 0;
aoqi@0 36 int LogBitsPerHeapOop = 0;
aoqi@0 37 int BytesPerHeapOop = 0;
aoqi@0 38 int BitsPerHeapOop = 0;
aoqi@0 39
aoqi@0 40 // Object alignment, in units of HeapWords.
aoqi@0 41 // Defaults are -1 so things will break badly if incorrectly initialized.
aoqi@0 42 int MinObjAlignment = -1;
aoqi@0 43 int MinObjAlignmentInBytes = -1;
aoqi@0 44 int MinObjAlignmentInBytesMask = 0;
aoqi@0 45
aoqi@0 46 int LogMinObjAlignment = -1;
aoqi@0 47 int LogMinObjAlignmentInBytes = -1;
aoqi@0 48
aoqi@0 49 // Oop encoding heap max
aoqi@0 50 uint64_t OopEncodingHeapMax = 0;
aoqi@0 51
aoqi@0 52 void basic_fatal(const char* msg) {
aoqi@0 53 fatal(msg);
aoqi@0 54 }
aoqi@0 55
aoqi@0 56 // Something to help porters sleep at night
aoqi@0 57
aoqi@0 58 void basic_types_init() {
aoqi@0 59 #ifdef ASSERT
aoqi@0 60 #ifdef _LP64
aoqi@0 61 assert(min_intx == (intx)CONST64(0x8000000000000000), "correct constant");
aoqi@0 62 assert(max_intx == CONST64(0x7FFFFFFFFFFFFFFF), "correct constant");
aoqi@0 63 assert(max_uintx == CONST64(0xFFFFFFFFFFFFFFFF), "correct constant");
aoqi@0 64 assert( 8 == sizeof( intx), "wrong size for basic type");
aoqi@0 65 assert( 8 == sizeof( jobject), "wrong size for basic type");
aoqi@0 66 #else
aoqi@0 67 assert(min_intx == (intx)0x80000000, "correct constant");
aoqi@0 68 assert(max_intx == 0x7FFFFFFF, "correct constant");
aoqi@0 69 assert(max_uintx == 0xFFFFFFFF, "correct constant");
aoqi@0 70 assert( 4 == sizeof( intx), "wrong size for basic type");
aoqi@0 71 assert( 4 == sizeof( jobject), "wrong size for basic type");
aoqi@0 72 #endif
aoqi@0 73 assert( (~max_juint) == 0, "max_juint has all its bits");
aoqi@0 74 assert( (~max_uintx) == 0, "max_uintx has all its bits");
aoqi@0 75 assert( (~max_julong) == 0, "max_julong has all its bits");
aoqi@0 76 assert( 1 == sizeof( jbyte), "wrong size for basic type");
aoqi@0 77 assert( 2 == sizeof( jchar), "wrong size for basic type");
aoqi@0 78 assert( 2 == sizeof( jshort), "wrong size for basic type");
aoqi@0 79 assert( 4 == sizeof( juint), "wrong size for basic type");
aoqi@0 80 assert( 4 == sizeof( jint), "wrong size for basic type");
aoqi@0 81 assert( 1 == sizeof( jboolean), "wrong size for basic type");
aoqi@0 82 assert( 8 == sizeof( jlong), "wrong size for basic type");
aoqi@0 83 assert( 4 == sizeof( jfloat), "wrong size for basic type");
aoqi@0 84 assert( 8 == sizeof( jdouble), "wrong size for basic type");
aoqi@0 85 assert( 1 == sizeof( u1), "wrong size for basic type");
aoqi@0 86 assert( 2 == sizeof( u2), "wrong size for basic type");
aoqi@0 87 assert( 4 == sizeof( u4), "wrong size for basic type");
aoqi@0 88
aoqi@0 89 int num_type_chars = 0;
aoqi@0 90 for (int i = 0; i < 99; i++) {
aoqi@0 91 if (type2char((BasicType)i) != 0) {
aoqi@0 92 assert(char2type(type2char((BasicType)i)) == i, "proper inverses");
aoqi@0 93 num_type_chars++;
aoqi@0 94 }
aoqi@0 95 }
aoqi@0 96 assert(num_type_chars == 11, "must have tested the right number of mappings");
aoqi@0 97 assert(char2type(0) == T_ILLEGAL, "correct illegality");
aoqi@0 98
aoqi@0 99 {
aoqi@0 100 for (int i = T_BOOLEAN; i <= T_CONFLICT; i++) {
aoqi@0 101 BasicType vt = (BasicType)i;
aoqi@0 102 BasicType ft = type2field[vt];
aoqi@0 103 switch (vt) {
aoqi@0 104 // the following types might plausibly show up in memory layouts:
aoqi@0 105 case T_BOOLEAN:
aoqi@0 106 case T_BYTE:
aoqi@0 107 case T_CHAR:
aoqi@0 108 case T_SHORT:
aoqi@0 109 case T_INT:
aoqi@0 110 case T_FLOAT:
aoqi@0 111 case T_DOUBLE:
aoqi@0 112 case T_LONG:
aoqi@0 113 case T_OBJECT:
aoqi@0 114 case T_ADDRESS: // random raw pointer
aoqi@0 115 case T_METADATA: // metadata pointer
aoqi@0 116 case T_NARROWOOP: // compressed pointer
aoqi@0 117 case T_NARROWKLASS: // compressed klass pointer
aoqi@0 118 case T_CONFLICT: // might as well support a bottom type
aoqi@0 119 case T_VOID: // padding or other unaddressed word
aoqi@0 120 // layout type must map to itself
aoqi@0 121 assert(vt == ft, "");
aoqi@0 122 break;
aoqi@0 123 default:
aoqi@0 124 // non-layout type must map to a (different) layout type
aoqi@0 125 assert(vt != ft, "");
aoqi@0 126 assert(ft == type2field[ft], "");
aoqi@0 127 }
aoqi@0 128 // every type must map to same-sized layout type:
aoqi@0 129 assert(type2size[vt] == type2size[ft], "");
aoqi@0 130 }
aoqi@0 131 }
aoqi@0 132 // These are assumed, e.g., when filling HeapWords with juints.
aoqi@0 133 assert(is_power_of_2(sizeof(juint)), "juint must be power of 2");
aoqi@0 134 assert(is_power_of_2(HeapWordSize), "HeapWordSize must be power of 2");
aoqi@0 135 assert((size_t)HeapWordSize >= sizeof(juint),
aoqi@0 136 "HeapWord should be at least as large as juint");
aoqi@0 137 assert(sizeof(NULL) == sizeof(char*), "NULL must be same size as pointer");
aoqi@0 138 #endif
aoqi@0 139
aoqi@0 140 if( JavaPriority1_To_OSPriority != -1 )
aoqi@0 141 os::java_to_os_priority[1] = JavaPriority1_To_OSPriority;
aoqi@0 142 if( JavaPriority2_To_OSPriority != -1 )
aoqi@0 143 os::java_to_os_priority[2] = JavaPriority2_To_OSPriority;
aoqi@0 144 if( JavaPriority3_To_OSPriority != -1 )
aoqi@0 145 os::java_to_os_priority[3] = JavaPriority3_To_OSPriority;
aoqi@0 146 if( JavaPriority4_To_OSPriority != -1 )
aoqi@0 147 os::java_to_os_priority[4] = JavaPriority4_To_OSPriority;
aoqi@0 148 if( JavaPriority5_To_OSPriority != -1 )
aoqi@0 149 os::java_to_os_priority[5] = JavaPriority5_To_OSPriority;
aoqi@0 150 if( JavaPriority6_To_OSPriority != -1 )
aoqi@0 151 os::java_to_os_priority[6] = JavaPriority6_To_OSPriority;
aoqi@0 152 if( JavaPriority7_To_OSPriority != -1 )
aoqi@0 153 os::java_to_os_priority[7] = JavaPriority7_To_OSPriority;
aoqi@0 154 if( JavaPriority8_To_OSPriority != -1 )
aoqi@0 155 os::java_to_os_priority[8] = JavaPriority8_To_OSPriority;
aoqi@0 156 if( JavaPriority9_To_OSPriority != -1 )
aoqi@0 157 os::java_to_os_priority[9] = JavaPriority9_To_OSPriority;
aoqi@0 158 if(JavaPriority10_To_OSPriority != -1 )
aoqi@0 159 os::java_to_os_priority[10] = JavaPriority10_To_OSPriority;
aoqi@0 160
aoqi@0 161 // Set the size of basic types here (after argument parsing but before
aoqi@0 162 // stub generation).
aoqi@0 163 if (UseCompressedOops) {
aoqi@0 164 // Size info for oops within java objects is fixed
aoqi@0 165 heapOopSize = jintSize;
aoqi@0 166 LogBytesPerHeapOop = LogBytesPerInt;
aoqi@0 167 LogBitsPerHeapOop = LogBitsPerInt;
aoqi@0 168 BytesPerHeapOop = BytesPerInt;
aoqi@0 169 BitsPerHeapOop = BitsPerInt;
aoqi@0 170 } else {
aoqi@0 171 heapOopSize = oopSize;
aoqi@0 172 LogBytesPerHeapOop = LogBytesPerWord;
aoqi@0 173 LogBitsPerHeapOop = LogBitsPerWord;
aoqi@0 174 BytesPerHeapOop = BytesPerWord;
aoqi@0 175 BitsPerHeapOop = BitsPerWord;
aoqi@0 176 }
aoqi@0 177 _type2aelembytes[T_OBJECT] = heapOopSize;
aoqi@0 178 _type2aelembytes[T_ARRAY] = heapOopSize;
aoqi@0 179 }
aoqi@0 180
aoqi@0 181
aoqi@0 182 // Map BasicType to signature character
aoqi@0 183 char type2char_tab[T_CONFLICT+1]={ 0, 0, 0, 0, 'Z', 'C', 'F', 'D', 'B', 'S', 'I', 'J', 'L', '[', 'V', 0, 0, 0, 0, 0};
aoqi@0 184
aoqi@0 185 // Map BasicType to Java type name
aoqi@0 186 const char* type2name_tab[T_CONFLICT+1] = {
aoqi@0 187 NULL, NULL, NULL, NULL,
aoqi@0 188 "boolean",
aoqi@0 189 "char",
aoqi@0 190 "float",
aoqi@0 191 "double",
aoqi@0 192 "byte",
aoqi@0 193 "short",
aoqi@0 194 "int",
aoqi@0 195 "long",
aoqi@0 196 "object",
aoqi@0 197 "array",
aoqi@0 198 "void",
aoqi@0 199 "*address*",
aoqi@0 200 "*narrowoop*",
aoqi@0 201 "*metadata*",
aoqi@0 202 "*narrowklass*",
aoqi@0 203 "*conflict*"
aoqi@0 204 };
aoqi@0 205
aoqi@0 206
aoqi@0 207 BasicType name2type(const char* name) {
aoqi@0 208 for (int i = T_BOOLEAN; i <= T_VOID; i++) {
aoqi@0 209 BasicType t = (BasicType)i;
aoqi@0 210 if (type2name_tab[t] != NULL && 0 == strcmp(type2name_tab[t], name))
aoqi@0 211 return t;
aoqi@0 212 }
aoqi@0 213 return T_ILLEGAL;
aoqi@0 214 }
aoqi@0 215
aoqi@0 216
aoqi@0 217 // Map BasicType to size in words
aoqi@0 218 int type2size[T_CONFLICT+1]={ -1, 0, 0, 0, 1, 1, 1, 2, 1, 1, 1, 2, 1, 1, 0, 1, 1, 1, 1, -1};
aoqi@0 219
aoqi@0 220 BasicType type2field[T_CONFLICT+1] = {
aoqi@0 221 (BasicType)0, // 0,
aoqi@0 222 (BasicType)0, // 1,
aoqi@0 223 (BasicType)0, // 2,
aoqi@0 224 (BasicType)0, // 3,
aoqi@0 225 T_BOOLEAN, // T_BOOLEAN = 4,
aoqi@0 226 T_CHAR, // T_CHAR = 5,
aoqi@0 227 T_FLOAT, // T_FLOAT = 6,
aoqi@0 228 T_DOUBLE, // T_DOUBLE = 7,
aoqi@0 229 T_BYTE, // T_BYTE = 8,
aoqi@0 230 T_SHORT, // T_SHORT = 9,
aoqi@0 231 T_INT, // T_INT = 10,
aoqi@0 232 T_LONG, // T_LONG = 11,
aoqi@0 233 T_OBJECT, // T_OBJECT = 12,
aoqi@0 234 T_OBJECT, // T_ARRAY = 13,
aoqi@0 235 T_VOID, // T_VOID = 14,
aoqi@0 236 T_ADDRESS, // T_ADDRESS = 15,
aoqi@0 237 T_NARROWOOP, // T_NARROWOOP= 16,
aoqi@0 238 T_METADATA, // T_METADATA = 17,
aoqi@0 239 T_NARROWKLASS, // T_NARROWKLASS = 18,
aoqi@0 240 T_CONFLICT // T_CONFLICT = 19,
aoqi@0 241 };
aoqi@0 242
aoqi@0 243
aoqi@0 244 BasicType type2wfield[T_CONFLICT+1] = {
aoqi@0 245 (BasicType)0, // 0,
aoqi@0 246 (BasicType)0, // 1,
aoqi@0 247 (BasicType)0, // 2,
aoqi@0 248 (BasicType)0, // 3,
aoqi@0 249 T_INT, // T_BOOLEAN = 4,
aoqi@0 250 T_INT, // T_CHAR = 5,
aoqi@0 251 T_FLOAT, // T_FLOAT = 6,
aoqi@0 252 T_DOUBLE, // T_DOUBLE = 7,
aoqi@0 253 T_INT, // T_BYTE = 8,
aoqi@0 254 T_INT, // T_SHORT = 9,
aoqi@0 255 T_INT, // T_INT = 10,
aoqi@0 256 T_LONG, // T_LONG = 11,
aoqi@0 257 T_OBJECT, // T_OBJECT = 12,
aoqi@0 258 T_OBJECT, // T_ARRAY = 13,
aoqi@0 259 T_VOID, // T_VOID = 14,
aoqi@0 260 T_ADDRESS, // T_ADDRESS = 15,
aoqi@0 261 T_NARROWOOP, // T_NARROWOOP = 16,
aoqi@0 262 T_METADATA, // T_METADATA = 17,
aoqi@0 263 T_NARROWKLASS, // T_NARROWKLASS = 18,
aoqi@0 264 T_CONFLICT // T_CONFLICT = 19,
aoqi@0 265 };
aoqi@0 266
aoqi@0 267
aoqi@0 268 int _type2aelembytes[T_CONFLICT+1] = {
aoqi@0 269 0, // 0
aoqi@0 270 0, // 1
aoqi@0 271 0, // 2
aoqi@0 272 0, // 3
aoqi@0 273 T_BOOLEAN_aelem_bytes, // T_BOOLEAN = 4,
aoqi@0 274 T_CHAR_aelem_bytes, // T_CHAR = 5,
aoqi@0 275 T_FLOAT_aelem_bytes, // T_FLOAT = 6,
aoqi@0 276 T_DOUBLE_aelem_bytes, // T_DOUBLE = 7,
aoqi@0 277 T_BYTE_aelem_bytes, // T_BYTE = 8,
aoqi@0 278 T_SHORT_aelem_bytes, // T_SHORT = 9,
aoqi@0 279 T_INT_aelem_bytes, // T_INT = 10,
aoqi@0 280 T_LONG_aelem_bytes, // T_LONG = 11,
aoqi@0 281 T_OBJECT_aelem_bytes, // T_OBJECT = 12,
aoqi@0 282 T_ARRAY_aelem_bytes, // T_ARRAY = 13,
aoqi@0 283 0, // T_VOID = 14,
aoqi@0 284 T_OBJECT_aelem_bytes, // T_ADDRESS = 15,
aoqi@0 285 T_NARROWOOP_aelem_bytes, // T_NARROWOOP= 16,
aoqi@0 286 T_OBJECT_aelem_bytes, // T_METADATA = 17,
aoqi@0 287 T_NARROWKLASS_aelem_bytes, // T_NARROWKLASS= 18,
aoqi@0 288 0 // T_CONFLICT = 19,
aoqi@0 289 };
aoqi@0 290
aoqi@0 291 #ifdef ASSERT
aoqi@0 292 int type2aelembytes(BasicType t, bool allow_address) {
aoqi@0 293 assert(allow_address || t != T_ADDRESS, " ");
aoqi@0 294 return _type2aelembytes[t];
aoqi@0 295 }
aoqi@0 296 #endif
aoqi@0 297
aoqi@0 298 // Support for 64-bit integer arithmetic
aoqi@0 299
aoqi@0 300 // The following code is mostly taken from JVM typedefs_md.h and system_md.c
aoqi@0 301
aoqi@0 302 static const jlong high_bit = (jlong)1 << (jlong)63;
aoqi@0 303 static const jlong other_bits = ~high_bit;
aoqi@0 304
aoqi@0 305 jlong float2long(jfloat f) {
aoqi@0 306 jlong tmp = (jlong) f;
aoqi@0 307 if (tmp != high_bit) {
aoqi@0 308 return tmp;
aoqi@0 309 } else {
aoqi@0 310 if (g_isnan((jdouble)f)) {
aoqi@0 311 return 0;
aoqi@0 312 }
aoqi@0 313 if (f < 0) {
aoqi@0 314 return high_bit;
aoqi@0 315 } else {
aoqi@0 316 return other_bits;
aoqi@0 317 }
aoqi@0 318 }
aoqi@0 319 }
aoqi@0 320
aoqi@0 321
aoqi@0 322 jlong double2long(jdouble f) {
aoqi@0 323 jlong tmp = (jlong) f;
aoqi@0 324 if (tmp != high_bit) {
aoqi@0 325 return tmp;
aoqi@0 326 } else {
aoqi@0 327 if (g_isnan(f)) {
aoqi@0 328 return 0;
aoqi@0 329 }
aoqi@0 330 if (f < 0) {
aoqi@0 331 return high_bit;
aoqi@0 332 } else {
aoqi@0 333 return other_bits;
aoqi@0 334 }
aoqi@0 335 }
aoqi@0 336 }
aoqi@0 337
aoqi@0 338 // least common multiple
aoqi@0 339 size_t lcm(size_t a, size_t b) {
aoqi@0 340 size_t cur, div, next;
aoqi@0 341
aoqi@0 342 cur = MAX2(a, b);
aoqi@0 343 div = MIN2(a, b);
aoqi@0 344
aoqi@0 345 assert(div != 0, "lcm requires positive arguments");
aoqi@0 346
aoqi@0 347
aoqi@0 348 while ((next = cur % div) != 0) {
aoqi@0 349 cur = div; div = next;
aoqi@0 350 }
aoqi@0 351
aoqi@0 352
aoqi@0 353 julong result = julong(a) * b / div;
aoqi@0 354 assert(result <= (size_t)max_uintx, "Integer overflow in lcm");
aoqi@0 355
aoqi@0 356 return size_t(result);
aoqi@0 357 }
aoqi@0 358
aoqi@0 359 #ifndef PRODUCT
aoqi@0 360
aoqi@0 361 void GlobalDefinitions::test_globals() {
aoqi@0 362 intptr_t page_sizes[] = { os::vm_page_size(), 4096, 8192, 65536, 2*1024*1024 };
aoqi@0 363 const int num_page_sizes = sizeof(page_sizes) / sizeof(page_sizes[0]);
aoqi@0 364
aoqi@0 365 for (int i = 0; i < num_page_sizes; i++) {
aoqi@0 366 intptr_t page_size = page_sizes[i];
aoqi@0 367
aoqi@0 368 address a_page = (address)(10*page_size);
aoqi@0 369
aoqi@0 370 // Check that address within page is returned as is
aoqi@0 371 assert(clamp_address_in_page(a_page, a_page, page_size) == a_page, "incorrect");
aoqi@0 372 assert(clamp_address_in_page(a_page + 128, a_page, page_size) == a_page + 128, "incorrect");
aoqi@0 373 assert(clamp_address_in_page(a_page + page_size - 1, a_page, page_size) == a_page + page_size - 1, "incorrect");
aoqi@0 374
aoqi@0 375 // Check that address above page returns start of next page
aoqi@0 376 assert(clamp_address_in_page(a_page + page_size, a_page, page_size) == a_page + page_size, "incorrect");
aoqi@0 377 assert(clamp_address_in_page(a_page + page_size + 1, a_page, page_size) == a_page + page_size, "incorrect");
aoqi@0 378 assert(clamp_address_in_page(a_page + page_size*5 + 1, a_page, page_size) == a_page + page_size, "incorrect");
aoqi@0 379
aoqi@0 380 // Check that address below page returns start of page
aoqi@0 381 assert(clamp_address_in_page(a_page - 1, a_page, page_size) == a_page, "incorrect");
aoqi@0 382 assert(clamp_address_in_page(a_page - 2*page_size - 1, a_page, page_size) == a_page, "incorrect");
aoqi@0 383 assert(clamp_address_in_page(a_page - 5*page_size - 1, a_page, page_size) == a_page, "incorrect");
aoqi@0 384 }
aoqi@0 385 }
aoqi@0 386
aoqi@0 387 #endif // PRODUCT

mercurial