1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/src/share/vm/utilities/globalDefinitions.cpp Sat Dec 01 00:00:00 2007 +0000 1.3 @@ -0,0 +1,297 @@ 1.4 +/* 1.5 + * Copyright 1997-2006 Sun Microsystems, Inc. All Rights Reserved. 1.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 1.7 + * 1.8 + * This code is free software; you can redistribute it and/or modify it 1.9 + * under the terms of the GNU General Public License version 2 only, as 1.10 + * published by the Free Software Foundation. 1.11 + * 1.12 + * This code is distributed in the hope that it will be useful, but WITHOUT 1.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 1.14 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 1.15 + * version 2 for more details (a copy is included in the LICENSE file that 1.16 + * accompanied this code). 1.17 + * 1.18 + * You should have received a copy of the GNU General Public License version 1.19 + * 2 along with this work; if not, write to the Free Software Foundation, 1.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 1.21 + * 1.22 + * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, 1.23 + * CA 95054 USA or visit www.sun.com if you need additional information or 1.24 + * have any questions. 1.25 + * 1.26 + */ 1.27 + 1.28 +# include "incls/_precompiled.incl" 1.29 +# include "incls/_globalDefinitions.cpp.incl" 1.30 + 1.31 + 1.32 +// Basic error support 1.33 + 1.34 +void basic_fatal(const char* msg) { 1.35 + fatal(msg); 1.36 +} 1.37 + 1.38 + 1.39 +// Something to help porters sleep at night 1.40 + 1.41 +void check_basic_types() { 1.42 +#ifdef ASSERT 1.43 +#ifdef _LP64 1.44 + assert(min_intx == (intx)CONST64(0x8000000000000000), "correct constant"); 1.45 + assert(max_intx == CONST64(0x7FFFFFFFFFFFFFFF), "correct constant"); 1.46 + assert(max_uintx == CONST64(0xFFFFFFFFFFFFFFFF), "correct constant"); 1.47 + assert( 8 == sizeof( intx), "wrong size for basic type"); 1.48 + assert( 8 == sizeof( jobject), "wrong size for basic type"); 1.49 +#else 1.50 + assert(min_intx == (intx)0x80000000, "correct constant"); 1.51 + assert(max_intx == 0x7FFFFFFF, "correct constant"); 1.52 + assert(max_uintx == 0xFFFFFFFF, "correct constant"); 1.53 + assert( 4 == sizeof( intx), "wrong size for basic type"); 1.54 + assert( 4 == sizeof( jobject), "wrong size for basic type"); 1.55 +#endif 1.56 + assert( (~max_juint) == 0, "max_juint has all its bits"); 1.57 + assert( (~max_uintx) == 0, "max_uintx has all its bits"); 1.58 + assert( (~max_julong) == 0, "max_julong has all its bits"); 1.59 + assert( 1 == sizeof( jbyte), "wrong size for basic type"); 1.60 + assert( 2 == sizeof( jchar), "wrong size for basic type"); 1.61 + assert( 2 == sizeof( jshort), "wrong size for basic type"); 1.62 + assert( 4 == sizeof( juint), "wrong size for basic type"); 1.63 + assert( 4 == sizeof( jint), "wrong size for basic type"); 1.64 + assert( 1 == sizeof( jboolean), "wrong size for basic type"); 1.65 + assert( 8 == sizeof( jlong), "wrong size for basic type"); 1.66 + assert( 4 == sizeof( jfloat), "wrong size for basic type"); 1.67 + assert( 8 == sizeof( jdouble), "wrong size for basic type"); 1.68 + assert( 1 == sizeof( u1), "wrong size for basic type"); 1.69 + assert( 2 == sizeof( u2), "wrong size for basic type"); 1.70 + assert( 4 == sizeof( u4), "wrong size for basic type"); 1.71 + 1.72 + int num_type_chars = 0; 1.73 + for (int i = 0; i < 99; i++) { 1.74 + if (type2char((BasicType)i) != 0) { 1.75 + assert(char2type(type2char((BasicType)i)) == i, "proper inverses"); 1.76 + num_type_chars++; 1.77 + } 1.78 + } 1.79 + assert(num_type_chars == 11, "must have tested the right number of mappings"); 1.80 + assert(char2type(0) == T_ILLEGAL, "correct illegality"); 1.81 + 1.82 + { 1.83 + for (int i = T_BOOLEAN; i <= T_CONFLICT; i++) { 1.84 + BasicType vt = (BasicType)i; 1.85 + BasicType ft = type2field[vt]; 1.86 + switch (vt) { 1.87 + // the following types might plausibly show up in memory layouts: 1.88 + case T_BOOLEAN: 1.89 + case T_BYTE: 1.90 + case T_CHAR: 1.91 + case T_SHORT: 1.92 + case T_INT: 1.93 + case T_FLOAT: 1.94 + case T_DOUBLE: 1.95 + case T_LONG: 1.96 + case T_OBJECT: 1.97 + case T_ADDRESS: // random raw pointer 1.98 + case T_CONFLICT: // might as well support a bottom type 1.99 + case T_VOID: // padding or other unaddressed word 1.100 + // layout type must map to itself 1.101 + assert(vt == ft, ""); 1.102 + break; 1.103 + default: 1.104 + // non-layout type must map to a (different) layout type 1.105 + assert(vt != ft, ""); 1.106 + assert(ft == type2field[ft], ""); 1.107 + } 1.108 + // every type must map to same-sized layout type: 1.109 + assert(type2size[vt] == type2size[ft], ""); 1.110 + } 1.111 + } 1.112 + // These are assumed, e.g., when filling HeapWords with juints. 1.113 + assert(is_power_of_2(sizeof(juint)), "juint must be power of 2"); 1.114 + assert(is_power_of_2(HeapWordSize), "HeapWordSize must be power of 2"); 1.115 + assert((size_t)HeapWordSize >= sizeof(juint), 1.116 + "HeapWord should be at least as large as juint"); 1.117 + assert(sizeof(NULL) == sizeof(char*), "NULL must be same size as pointer"); 1.118 +#endif 1.119 + 1.120 + if( JavaPriority1_To_OSPriority != -1 ) 1.121 + os::java_to_os_priority[1] = JavaPriority1_To_OSPriority; 1.122 + if( JavaPriority2_To_OSPriority != -1 ) 1.123 + os::java_to_os_priority[2] = JavaPriority2_To_OSPriority; 1.124 + if( JavaPriority3_To_OSPriority != -1 ) 1.125 + os::java_to_os_priority[3] = JavaPriority3_To_OSPriority; 1.126 + if( JavaPriority4_To_OSPriority != -1 ) 1.127 + os::java_to_os_priority[4] = JavaPriority4_To_OSPriority; 1.128 + if( JavaPriority5_To_OSPriority != -1 ) 1.129 + os::java_to_os_priority[5] = JavaPriority5_To_OSPriority; 1.130 + if( JavaPriority6_To_OSPriority != -1 ) 1.131 + os::java_to_os_priority[6] = JavaPriority6_To_OSPriority; 1.132 + if( JavaPriority7_To_OSPriority != -1 ) 1.133 + os::java_to_os_priority[7] = JavaPriority7_To_OSPriority; 1.134 + if( JavaPriority8_To_OSPriority != -1 ) 1.135 + os::java_to_os_priority[8] = JavaPriority8_To_OSPriority; 1.136 + if( JavaPriority9_To_OSPriority != -1 ) 1.137 + os::java_to_os_priority[9] = JavaPriority9_To_OSPriority; 1.138 + if(JavaPriority10_To_OSPriority != -1 ) 1.139 + os::java_to_os_priority[10] = JavaPriority10_To_OSPriority; 1.140 +} 1.141 + 1.142 + 1.143 +// Map BasicType to signature character 1.144 +char type2char_tab[T_CONFLICT+1]={ 0, 0, 0, 0, 'Z', 'C', 'F', 'D', 'B', 'S', 'I', 'J', 'L', '[', 'V', 0, 0}; 1.145 + 1.146 +// Map BasicType to Java type name 1.147 +const char* type2name_tab[T_CONFLICT+1] = { 1.148 + NULL, NULL, NULL, NULL, 1.149 + "boolean", 1.150 + "char", 1.151 + "float", 1.152 + "double", 1.153 + "byte", 1.154 + "short", 1.155 + "int", 1.156 + "long", 1.157 + "object", 1.158 + "array", 1.159 + "void", 1.160 + "*address*", 1.161 + "*conflict*" 1.162 +}; 1.163 + 1.164 + 1.165 +BasicType name2type(const char* name) { 1.166 + for (int i = T_BOOLEAN; i <= T_VOID; i++) { 1.167 + BasicType t = (BasicType)i; 1.168 + if (type2name_tab[t] != NULL && 0 == strcmp(type2name_tab[t], name)) 1.169 + return t; 1.170 + } 1.171 + return T_ILLEGAL; 1.172 +} 1.173 + 1.174 + 1.175 +// Map BasicType to size in words 1.176 +int type2size[T_CONFLICT+1]={ -1, 0, 0, 0, 1, 1, 1, 2, 1, 1, 1, 2, 1, 1, 0, 1, -1}; 1.177 + 1.178 +BasicType type2field[T_CONFLICT+1] = { 1.179 + (BasicType)0, // 0, 1.180 + (BasicType)0, // 1, 1.181 + (BasicType)0, // 2, 1.182 + (BasicType)0, // 3, 1.183 + T_BOOLEAN, // T_BOOLEAN = 4, 1.184 + T_CHAR, // T_CHAR = 5, 1.185 + T_FLOAT, // T_FLOAT = 6, 1.186 + T_DOUBLE, // T_DOUBLE = 7, 1.187 + T_BYTE, // T_BYTE = 8, 1.188 + T_SHORT, // T_SHORT = 9, 1.189 + T_INT, // T_INT = 10, 1.190 + T_LONG, // T_LONG = 11, 1.191 + T_OBJECT, // T_OBJECT = 12, 1.192 + T_OBJECT, // T_ARRAY = 13, 1.193 + T_VOID, // T_VOID = 14, 1.194 + T_ADDRESS, // T_ADDRESS = 15, 1.195 + T_CONFLICT // T_CONFLICT = 16, 1.196 +}; 1.197 + 1.198 + 1.199 +BasicType type2wfield[T_CONFLICT+1] = { 1.200 + (BasicType)0, // 0, 1.201 + (BasicType)0, // 1, 1.202 + (BasicType)0, // 2, 1.203 + (BasicType)0, // 3, 1.204 + T_INT, // T_BOOLEAN = 4, 1.205 + T_INT, // T_CHAR = 5, 1.206 + T_FLOAT, // T_FLOAT = 6, 1.207 + T_DOUBLE, // T_DOUBLE = 7, 1.208 + T_INT, // T_BYTE = 8, 1.209 + T_INT, // T_SHORT = 9, 1.210 + T_INT, // T_INT = 10, 1.211 + T_LONG, // T_LONG = 11, 1.212 + T_OBJECT, // T_OBJECT = 12, 1.213 + T_OBJECT, // T_ARRAY = 13, 1.214 + T_VOID, // T_VOID = 14, 1.215 + T_ADDRESS, // T_ADDRESS = 15, 1.216 + T_CONFLICT // T_CONFLICT = 16, 1.217 +}; 1.218 + 1.219 + 1.220 +int type2aelembytes[T_CONFLICT+1] = { 1.221 + 0, // 0 1.222 + 0, // 1 1.223 + 0, // 2 1.224 + 0, // 3 1.225 + T_BOOLEAN_aelem_bytes, // T_BOOLEAN = 4, 1.226 + T_CHAR_aelem_bytes, // T_CHAR = 5, 1.227 + T_FLOAT_aelem_bytes, // T_FLOAT = 6, 1.228 + T_DOUBLE_aelem_bytes, // T_DOUBLE = 7, 1.229 + T_BYTE_aelem_bytes, // T_BYTE = 8, 1.230 + T_SHORT_aelem_bytes, // T_SHORT = 9, 1.231 + T_INT_aelem_bytes, // T_INT = 10, 1.232 + T_LONG_aelem_bytes, // T_LONG = 11, 1.233 + T_OBJECT_aelem_bytes, // T_OBJECT = 12, 1.234 + T_ARRAY_aelem_bytes, // T_ARRAY = 13, 1.235 + 0, // T_VOID = 14, 1.236 + T_INT_aelem_bytes, // T_ADDRESS = 15, 1.237 + 0 // T_CONFLICT = 16, 1.238 +}; 1.239 + 1.240 + 1.241 +// Support for 64-bit integer arithmetic 1.242 + 1.243 +// The following code is mostly taken from JVM typedefs_md.h and system_md.c 1.244 + 1.245 +static const jlong high_bit = (jlong)1 << (jlong)63; 1.246 +static const jlong other_bits = ~high_bit; 1.247 + 1.248 +jlong float2long(jfloat f) { 1.249 + jlong tmp = (jlong) f; 1.250 + if (tmp != high_bit) { 1.251 + return tmp; 1.252 + } else { 1.253 + if (g_isnan((jdouble)f)) { 1.254 + return 0; 1.255 + } 1.256 + if (f < 0) { 1.257 + return high_bit; 1.258 + } else { 1.259 + return other_bits; 1.260 + } 1.261 + } 1.262 +} 1.263 + 1.264 + 1.265 +jlong double2long(jdouble f) { 1.266 + jlong tmp = (jlong) f; 1.267 + if (tmp != high_bit) { 1.268 + return tmp; 1.269 + } else { 1.270 + if (g_isnan(f)) { 1.271 + return 0; 1.272 + } 1.273 + if (f < 0) { 1.274 + return high_bit; 1.275 + } else { 1.276 + return other_bits; 1.277 + } 1.278 + } 1.279 +} 1.280 + 1.281 +// least common multiple 1.282 +size_t lcm(size_t a, size_t b) { 1.283 + size_t cur, div, next; 1.284 + 1.285 + cur = MAX2(a, b); 1.286 + div = MIN2(a, b); 1.287 + 1.288 + assert(div != 0, "lcm requires positive arguments"); 1.289 + 1.290 + 1.291 + while ((next = cur % div) != 0) { 1.292 + cur = div; div = next; 1.293 + } 1.294 + 1.295 + 1.296 + julong result = julong(a) * b / div; 1.297 + assert(result <= (size_t)max_uintx, "Integer overflow in lcm"); 1.298 + 1.299 + return size_t(result); 1.300 +}