globalDefinitions.cpp revision 1491
0N/A/*
196N/A * Copyright 1997-2008 Sun Microsystems, Inc. All Rights Reserved.
0N/A * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
0N/A *
0N/A * This code is free software; you can redistribute it and/or modify it
0N/A * under the terms of the GNU General Public License version 2 only, as
0N/A * published by the Free Software Foundation.
0N/A *
0N/A * This code is distributed in the hope that it will be useful, but WITHOUT
0N/A * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
0N/A * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
0N/A * version 2 for more details (a copy is included in the LICENSE file that
0N/A * accompanied this code).
0N/A *
0N/A * You should have received a copy of the GNU General Public License version
0N/A * 2 along with this work; if not, write to the Free Software Foundation,
0N/A * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
0N/A *
0N/A * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
0N/A * CA 95054 USA or visit www.sun.com if you need additional information or
0N/A * have any questions.
0N/A *
0N/A */
0N/A
0N/A# include "incls/_precompiled.incl"
0N/A# include "incls/_globalDefinitions.cpp.incl"
113N/A// Basic error support
0N/A
113N/A// Info for oops within a java object. Defaults are zero so
113N/A// things will break badly if incorrectly initialized.
113N/Aint heapOopSize = 0;
113N/Aint LogBytesPerHeapOop = 0;
113N/Aint LogBitsPerHeapOop = 0;
113N/Aint BytesPerHeapOop = 0;
113N/Aint BitsPerHeapOop = 0;
0N/A
1491N/A// Object alignment, in units of HeapWords.
1491N/A// Defaults are -1 so things will break badly if incorrectly initialized.
1491N/Aint MinObjAlignment = -1;
1491N/Aint MinObjAlignmentInBytes = -1;
1491N/Aint MinObjAlignmentInBytesMask = 0;
1491N/A
1491N/Aint LogMinObjAlignment = -1;
1491N/Aint LogMinObjAlignmentInBytes = -1;
1491N/A
1491N/A// Oop encoding heap max
1491N/Auint64_t OopEncodingHeapMax = 0;
1491N/A
0N/Avoid basic_fatal(const char* msg) {
0N/A fatal(msg);
0N/A}
0N/A
0N/A// Something to help porters sleep at night
0N/A
113N/Avoid basic_types_init() {
0N/A#ifdef ASSERT
0N/A#ifdef _LP64
0N/A assert(min_intx == (intx)CONST64(0x8000000000000000), "correct constant");
0N/A assert(max_intx == CONST64(0x7FFFFFFFFFFFFFFF), "correct constant");
0N/A assert(max_uintx == CONST64(0xFFFFFFFFFFFFFFFF), "correct constant");
0N/A assert( 8 == sizeof( intx), "wrong size for basic type");
0N/A assert( 8 == sizeof( jobject), "wrong size for basic type");
0N/A#else
0N/A assert(min_intx == (intx)0x80000000, "correct constant");
0N/A assert(max_intx == 0x7FFFFFFF, "correct constant");
0N/A assert(max_uintx == 0xFFFFFFFF, "correct constant");
0N/A assert( 4 == sizeof( intx), "wrong size for basic type");
0N/A assert( 4 == sizeof( jobject), "wrong size for basic type");
0N/A#endif
0N/A assert( (~max_juint) == 0, "max_juint has all its bits");
0N/A assert( (~max_uintx) == 0, "max_uintx has all its bits");
0N/A assert( (~max_julong) == 0, "max_julong has all its bits");
0N/A assert( 1 == sizeof( jbyte), "wrong size for basic type");
0N/A assert( 2 == sizeof( jchar), "wrong size for basic type");
0N/A assert( 2 == sizeof( jshort), "wrong size for basic type");
0N/A assert( 4 == sizeof( juint), "wrong size for basic type");
0N/A assert( 4 == sizeof( jint), "wrong size for basic type");
0N/A assert( 1 == sizeof( jboolean), "wrong size for basic type");
0N/A assert( 8 == sizeof( jlong), "wrong size for basic type");
0N/A assert( 4 == sizeof( jfloat), "wrong size for basic type");
0N/A assert( 8 == sizeof( jdouble), "wrong size for basic type");
0N/A assert( 1 == sizeof( u1), "wrong size for basic type");
0N/A assert( 2 == sizeof( u2), "wrong size for basic type");
0N/A assert( 4 == sizeof( u4), "wrong size for basic type");
0N/A
0N/A int num_type_chars = 0;
0N/A for (int i = 0; i < 99; i++) {
0N/A if (type2char((BasicType)i) != 0) {
0N/A assert(char2type(type2char((BasicType)i)) == i, "proper inverses");
0N/A num_type_chars++;
0N/A }
0N/A }
0N/A assert(num_type_chars == 11, "must have tested the right number of mappings");
0N/A assert(char2type(0) == T_ILLEGAL, "correct illegality");
0N/A
0N/A {
0N/A for (int i = T_BOOLEAN; i <= T_CONFLICT; i++) {
0N/A BasicType vt = (BasicType)i;
0N/A BasicType ft = type2field[vt];
0N/A switch (vt) {
0N/A // the following types might plausibly show up in memory layouts:
0N/A case T_BOOLEAN:
0N/A case T_BYTE:
0N/A case T_CHAR:
0N/A case T_SHORT:
0N/A case T_INT:
0N/A case T_FLOAT:
0N/A case T_DOUBLE:
0N/A case T_LONG:
0N/A case T_OBJECT:
0N/A case T_ADDRESS: // random raw pointer
113N/A case T_NARROWOOP: // compressed pointer
0N/A case T_CONFLICT: // might as well support a bottom type
0N/A case T_VOID: // padding or other unaddressed word
0N/A // layout type must map to itself
0N/A assert(vt == ft, "");
0N/A break;
0N/A default:
0N/A // non-layout type must map to a (different) layout type
0N/A assert(vt != ft, "");
0N/A assert(ft == type2field[ft], "");
0N/A }
0N/A // every type must map to same-sized layout type:
0N/A assert(type2size[vt] == type2size[ft], "");
0N/A }
0N/A }
0N/A // These are assumed, e.g., when filling HeapWords with juints.
0N/A assert(is_power_of_2(sizeof(juint)), "juint must be power of 2");
0N/A assert(is_power_of_2(HeapWordSize), "HeapWordSize must be power of 2");
0N/A assert((size_t)HeapWordSize >= sizeof(juint),
0N/A "HeapWord should be at least as large as juint");
0N/A assert(sizeof(NULL) == sizeof(char*), "NULL must be same size as pointer");
0N/A#endif
0N/A
0N/A if( JavaPriority1_To_OSPriority != -1 )
0N/A os::java_to_os_priority[1] = JavaPriority1_To_OSPriority;
0N/A if( JavaPriority2_To_OSPriority != -1 )
0N/A os::java_to_os_priority[2] = JavaPriority2_To_OSPriority;
0N/A if( JavaPriority3_To_OSPriority != -1 )
0N/A os::java_to_os_priority[3] = JavaPriority3_To_OSPriority;
0N/A if( JavaPriority4_To_OSPriority != -1 )
0N/A os::java_to_os_priority[4] = JavaPriority4_To_OSPriority;
0N/A if( JavaPriority5_To_OSPriority != -1 )
0N/A os::java_to_os_priority[5] = JavaPriority5_To_OSPriority;
0N/A if( JavaPriority6_To_OSPriority != -1 )
0N/A os::java_to_os_priority[6] = JavaPriority6_To_OSPriority;
0N/A if( JavaPriority7_To_OSPriority != -1 )
0N/A os::java_to_os_priority[7] = JavaPriority7_To_OSPriority;
0N/A if( JavaPriority8_To_OSPriority != -1 )
0N/A os::java_to_os_priority[8] = JavaPriority8_To_OSPriority;
0N/A if( JavaPriority9_To_OSPriority != -1 )
0N/A os::java_to_os_priority[9] = JavaPriority9_To_OSPriority;
0N/A if(JavaPriority10_To_OSPriority != -1 )
0N/A os::java_to_os_priority[10] = JavaPriority10_To_OSPriority;
113N/A
113N/A // Set the size of basic types here (after argument parsing but before
113N/A // stub generation).
113N/A if (UseCompressedOops) {
113N/A // Size info for oops within java objects is fixed
113N/A heapOopSize = jintSize;
113N/A LogBytesPerHeapOop = LogBytesPerInt;
113N/A LogBitsPerHeapOop = LogBitsPerInt;
113N/A BytesPerHeapOop = BytesPerInt;
113N/A BitsPerHeapOop = BitsPerInt;
113N/A } else {
113N/A heapOopSize = oopSize;
113N/A LogBytesPerHeapOop = LogBytesPerWord;
113N/A LogBitsPerHeapOop = LogBitsPerWord;
113N/A BytesPerHeapOop = BytesPerWord;
113N/A BitsPerHeapOop = BitsPerWord;
113N/A }
113N/A _type2aelembytes[T_OBJECT] = heapOopSize;
113N/A _type2aelembytes[T_ARRAY] = heapOopSize;
0N/A}
0N/A
0N/A
0N/A// Map BasicType to signature character
113N/Achar type2char_tab[T_CONFLICT+1]={ 0, 0, 0, 0, 'Z', 'C', 'F', 'D', 'B', 'S', 'I', 'J', 'L', '[', 'V', 0, 0, 0};
0N/A
0N/A// Map BasicType to Java type name
0N/Aconst char* type2name_tab[T_CONFLICT+1] = {
0N/A NULL, NULL, NULL, NULL,
0N/A "boolean",
0N/A "char",
0N/A "float",
0N/A "double",
0N/A "byte",
0N/A "short",
0N/A "int",
0N/A "long",
0N/A "object",
0N/A "array",
0N/A "void",
0N/A "*address*",
113N/A "*narrowoop*",
0N/A "*conflict*"
0N/A};
0N/A
0N/A
0N/ABasicType name2type(const char* name) {
0N/A for (int i = T_BOOLEAN; i <= T_VOID; i++) {
0N/A BasicType t = (BasicType)i;
0N/A if (type2name_tab[t] != NULL && 0 == strcmp(type2name_tab[t], name))
0N/A return t;
0N/A }
0N/A return T_ILLEGAL;
0N/A}
0N/A
0N/A
0N/A// Map BasicType to size in words
113N/Aint type2size[T_CONFLICT+1]={ -1, 0, 0, 0, 1, 1, 1, 2, 1, 1, 1, 2, 1, 1, 0, 1, 1, -1};
0N/A
0N/ABasicType type2field[T_CONFLICT+1] = {
0N/A (BasicType)0, // 0,
0N/A (BasicType)0, // 1,
0N/A (BasicType)0, // 2,
0N/A (BasicType)0, // 3,
0N/A T_BOOLEAN, // T_BOOLEAN = 4,
0N/A T_CHAR, // T_CHAR = 5,
0N/A T_FLOAT, // T_FLOAT = 6,
0N/A T_DOUBLE, // T_DOUBLE = 7,
0N/A T_BYTE, // T_BYTE = 8,
0N/A T_SHORT, // T_SHORT = 9,
0N/A T_INT, // T_INT = 10,
0N/A T_LONG, // T_LONG = 11,
0N/A T_OBJECT, // T_OBJECT = 12,
0N/A T_OBJECT, // T_ARRAY = 13,
0N/A T_VOID, // T_VOID = 14,
0N/A T_ADDRESS, // T_ADDRESS = 15,
113N/A T_NARROWOOP, // T_NARROWOOP= 16,
113N/A T_CONFLICT // T_CONFLICT = 17,
0N/A};
0N/A
0N/A
0N/ABasicType type2wfield[T_CONFLICT+1] = {
0N/A (BasicType)0, // 0,
0N/A (BasicType)0, // 1,
0N/A (BasicType)0, // 2,
0N/A (BasicType)0, // 3,
0N/A T_INT, // T_BOOLEAN = 4,
0N/A T_INT, // T_CHAR = 5,
0N/A T_FLOAT, // T_FLOAT = 6,
0N/A T_DOUBLE, // T_DOUBLE = 7,
0N/A T_INT, // T_BYTE = 8,
0N/A T_INT, // T_SHORT = 9,
0N/A T_INT, // T_INT = 10,
0N/A T_LONG, // T_LONG = 11,
0N/A T_OBJECT, // T_OBJECT = 12,
0N/A T_OBJECT, // T_ARRAY = 13,
0N/A T_VOID, // T_VOID = 14,
0N/A T_ADDRESS, // T_ADDRESS = 15,
113N/A T_NARROWOOP, // T_NARROWOOP = 16,
113N/A T_CONFLICT // T_CONFLICT = 17,
0N/A};
0N/A
0N/A
29N/Aint _type2aelembytes[T_CONFLICT+1] = {
0N/A 0, // 0
0N/A 0, // 1
0N/A 0, // 2
0N/A 0, // 3
0N/A T_BOOLEAN_aelem_bytes, // T_BOOLEAN = 4,
0N/A T_CHAR_aelem_bytes, // T_CHAR = 5,
0N/A T_FLOAT_aelem_bytes, // T_FLOAT = 6,
0N/A T_DOUBLE_aelem_bytes, // T_DOUBLE = 7,
0N/A T_BYTE_aelem_bytes, // T_BYTE = 8,
0N/A T_SHORT_aelem_bytes, // T_SHORT = 9,
0N/A T_INT_aelem_bytes, // T_INT = 10,
0N/A T_LONG_aelem_bytes, // T_LONG = 11,
0N/A T_OBJECT_aelem_bytes, // T_OBJECT = 12,
0N/A T_ARRAY_aelem_bytes, // T_ARRAY = 13,
0N/A 0, // T_VOID = 14,
29N/A T_OBJECT_aelem_bytes, // T_ADDRESS = 15,
113N/A T_NARROWOOP_aelem_bytes,// T_NARROWOOP= 16,
113N/A 0 // T_CONFLICT = 17,
0N/A};
0N/A
29N/A#ifdef ASSERT
29N/Aint type2aelembytes(BasicType t, bool allow_address) {
29N/A assert(allow_address || t != T_ADDRESS, " ");
29N/A return _type2aelembytes[t];
29N/A}
29N/A#endif
0N/A
0N/A// Support for 64-bit integer arithmetic
0N/A
0N/A// The following code is mostly taken from JVM typedefs_md.h and system_md.c
0N/A
113N/Astatic const jlong high_bit = (jlong)1 << (jlong)63;
0N/Astatic const jlong other_bits = ~high_bit;
0N/A
0N/Ajlong float2long(jfloat f) {
0N/A jlong tmp = (jlong) f;
0N/A if (tmp != high_bit) {
0N/A return tmp;
0N/A } else {
0N/A if (g_isnan((jdouble)f)) {
0N/A return 0;
0N/A }
0N/A if (f < 0) {
0N/A return high_bit;
0N/A } else {
0N/A return other_bits;
0N/A }
0N/A }
0N/A}
0N/A
0N/A
0N/Ajlong double2long(jdouble f) {
0N/A jlong tmp = (jlong) f;
0N/A if (tmp != high_bit) {
0N/A return tmp;
0N/A } else {
0N/A if (g_isnan(f)) {
0N/A return 0;
0N/A }
0N/A if (f < 0) {
0N/A return high_bit;
0N/A } else {
0N/A return other_bits;
0N/A }
0N/A }
0N/A}
0N/A
0N/A// least common multiple
0N/Asize_t lcm(size_t a, size_t b) {
0N/A size_t cur, div, next;
0N/A
0N/A cur = MAX2(a, b);
0N/A div = MIN2(a, b);
0N/A
0N/A assert(div != 0, "lcm requires positive arguments");
0N/A
0N/A
0N/A while ((next = cur % div) != 0) {
0N/A cur = div; div = next;
0N/A }
0N/A
0N/A
0N/A julong result = julong(a) * b / div;
0N/A assert(result <= (size_t)max_uintx, "Integer overflow in lcm");
0N/A
0N/A return size_t(result);
0N/A}