hotspot/src/share/vm/utilities/globalDefinitions.cpp
changeset 1 489c9b5090e2
child 202 dc13bf0e5d5d
equal deleted inserted replaced
0:fd16c54261b3 1:489c9b5090e2
       
     1 /*
       
     2  * Copyright 1997-2006 Sun Microsystems, Inc.  All Rights Reserved.
       
     3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
       
     4  *
       
     5  * This code is free software; you can redistribute it and/or modify it
       
     6  * under the terms of the GNU General Public License version 2 only, as
       
     7  * published by the Free Software Foundation.
       
     8  *
       
     9  * This code is distributed in the hope that it will be useful, but WITHOUT
       
    10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
       
    11  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
       
    12  * version 2 for more details (a copy is included in the LICENSE file that
       
    13  * accompanied this code).
       
    14  *
       
    15  * You should have received a copy of the GNU General Public License version
       
    16  * 2 along with this work; if not, write to the Free Software Foundation,
       
    17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
       
    18  *
       
    19  * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
       
    20  * CA 95054 USA or visit www.sun.com if you need additional information or
       
    21  * have any questions.
       
    22  *
       
    23  */
       
    24 
       
    25 # include "incls/_precompiled.incl"
       
    26 # include "incls/_globalDefinitions.cpp.incl"
       
    27 
       
    28 
       
    29 // Basic error support
       
    30 
       
    31 void basic_fatal(const char* msg) {
       
    32   fatal(msg);
       
    33 }
       
    34 
       
    35 
       
    36 // Something to help porters sleep at night
       
    37 
       
    38 void check_basic_types() {
       
    39 #ifdef ASSERT
       
    40 #ifdef _LP64
       
    41   assert(min_intx ==  (intx)CONST64(0x8000000000000000), "correct constant");
       
    42   assert(max_intx ==  CONST64(0x7FFFFFFFFFFFFFFF), "correct constant");
       
    43   assert(max_uintx == CONST64(0xFFFFFFFFFFFFFFFF), "correct constant");
       
    44   assert( 8 == sizeof( intx),      "wrong size for basic type");
       
    45   assert( 8 == sizeof( jobject),   "wrong size for basic type");
       
    46 #else
       
    47   assert(min_intx ==  (intx)0x80000000,  "correct constant");
       
    48   assert(max_intx ==  0x7FFFFFFF,  "correct constant");
       
    49   assert(max_uintx == 0xFFFFFFFF,  "correct constant");
       
    50   assert( 4 == sizeof( intx),      "wrong size for basic type");
       
    51   assert( 4 == sizeof( jobject),   "wrong size for basic type");
       
    52 #endif
       
    53   assert( (~max_juint) == 0,  "max_juint has all its bits");
       
    54   assert( (~max_uintx) == 0,  "max_uintx has all its bits");
       
    55   assert( (~max_julong) == 0, "max_julong has all its bits");
       
    56   assert( 1 == sizeof( jbyte),     "wrong size for basic type");
       
    57   assert( 2 == sizeof( jchar),     "wrong size for basic type");
       
    58   assert( 2 == sizeof( jshort),    "wrong size for basic type");
       
    59   assert( 4 == sizeof( juint),     "wrong size for basic type");
       
    60   assert( 4 == sizeof( jint),      "wrong size for basic type");
       
    61   assert( 1 == sizeof( jboolean),  "wrong size for basic type");
       
    62   assert( 8 == sizeof( jlong),     "wrong size for basic type");
       
    63   assert( 4 == sizeof( jfloat),    "wrong size for basic type");
       
    64   assert( 8 == sizeof( jdouble),   "wrong size for basic type");
       
    65   assert( 1 == sizeof( u1),        "wrong size for basic type");
       
    66   assert( 2 == sizeof( u2),        "wrong size for basic type");
       
    67   assert( 4 == sizeof( u4),        "wrong size for basic type");
       
    68 
       
    69   int num_type_chars = 0;
       
    70   for (int i = 0; i < 99; i++) {
       
    71     if (type2char((BasicType)i) != 0) {
       
    72       assert(char2type(type2char((BasicType)i)) == i, "proper inverses");
       
    73       num_type_chars++;
       
    74     }
       
    75   }
       
    76   assert(num_type_chars == 11, "must have tested the right number of mappings");
       
    77   assert(char2type(0) == T_ILLEGAL, "correct illegality");
       
    78 
       
    79   {
       
    80     for (int i = T_BOOLEAN; i <= T_CONFLICT; i++) {
       
    81       BasicType vt = (BasicType)i;
       
    82       BasicType ft = type2field[vt];
       
    83       switch (vt) {
       
    84       // the following types might plausibly show up in memory layouts:
       
    85       case T_BOOLEAN:
       
    86       case T_BYTE:
       
    87       case T_CHAR:
       
    88       case T_SHORT:
       
    89       case T_INT:
       
    90       case T_FLOAT:
       
    91       case T_DOUBLE:
       
    92       case T_LONG:
       
    93       case T_OBJECT:
       
    94       case T_ADDRESS:   // random raw pointer
       
    95       case T_CONFLICT:  // might as well support a bottom type
       
    96       case T_VOID:      // padding or other unaddressed word
       
    97         // layout type must map to itself
       
    98         assert(vt == ft, "");
       
    99         break;
       
   100       default:
       
   101         // non-layout type must map to a (different) layout type
       
   102         assert(vt != ft, "");
       
   103         assert(ft == type2field[ft], "");
       
   104       }
       
   105       // every type must map to same-sized layout type:
       
   106       assert(type2size[vt] == type2size[ft], "");
       
   107     }
       
   108   }
       
   109   // These are assumed, e.g., when filling HeapWords with juints.
       
   110   assert(is_power_of_2(sizeof(juint)), "juint must be power of 2");
       
   111   assert(is_power_of_2(HeapWordSize), "HeapWordSize must be power of 2");
       
   112   assert((size_t)HeapWordSize >= sizeof(juint),
       
   113          "HeapWord should be at least as large as juint");
       
   114   assert(sizeof(NULL) == sizeof(char*), "NULL must be same size as pointer");
       
   115 #endif
       
   116 
       
   117   if( JavaPriority1_To_OSPriority != -1 )
       
   118     os::java_to_os_priority[1] = JavaPriority1_To_OSPriority;
       
   119   if( JavaPriority2_To_OSPriority != -1 )
       
   120     os::java_to_os_priority[2] = JavaPriority2_To_OSPriority;
       
   121   if( JavaPriority3_To_OSPriority != -1 )
       
   122     os::java_to_os_priority[3] = JavaPriority3_To_OSPriority;
       
   123   if( JavaPriority4_To_OSPriority != -1 )
       
   124     os::java_to_os_priority[4] = JavaPriority4_To_OSPriority;
       
   125   if( JavaPriority5_To_OSPriority != -1 )
       
   126     os::java_to_os_priority[5] = JavaPriority5_To_OSPriority;
       
   127   if( JavaPriority6_To_OSPriority != -1 )
       
   128     os::java_to_os_priority[6] = JavaPriority6_To_OSPriority;
       
   129   if( JavaPriority7_To_OSPriority != -1 )
       
   130     os::java_to_os_priority[7] = JavaPriority7_To_OSPriority;
       
   131   if( JavaPriority8_To_OSPriority != -1 )
       
   132     os::java_to_os_priority[8] = JavaPriority8_To_OSPriority;
       
   133   if( JavaPriority9_To_OSPriority != -1 )
       
   134     os::java_to_os_priority[9] = JavaPriority9_To_OSPriority;
       
   135   if(JavaPriority10_To_OSPriority != -1 )
       
   136     os::java_to_os_priority[10] = JavaPriority10_To_OSPriority;
       
   137 }
       
   138 
       
   139 
       
   140 // Map BasicType to signature character
       
   141 char type2char_tab[T_CONFLICT+1]={ 0, 0, 0, 0, 'Z', 'C', 'F', 'D', 'B', 'S', 'I', 'J', 'L', '[', 'V', 0, 0};
       
   142 
       
   143 // Map BasicType to Java type name
       
   144 const char* type2name_tab[T_CONFLICT+1] = {
       
   145   NULL, NULL, NULL, NULL,
       
   146   "boolean",
       
   147   "char",
       
   148   "float",
       
   149   "double",
       
   150   "byte",
       
   151   "short",
       
   152   "int",
       
   153   "long",
       
   154   "object",
       
   155   "array",
       
   156   "void",
       
   157   "*address*",
       
   158   "*conflict*"
       
   159 };
       
   160 
       
   161 
       
   162 BasicType name2type(const char* name) {
       
   163   for (int i = T_BOOLEAN; i <= T_VOID; i++) {
       
   164     BasicType t = (BasicType)i;
       
   165     if (type2name_tab[t] != NULL && 0 == strcmp(type2name_tab[t], name))
       
   166       return t;
       
   167   }
       
   168   return T_ILLEGAL;
       
   169 }
       
   170 
       
   171 
       
   172 // Map BasicType to size in words
       
   173 int type2size[T_CONFLICT+1]={ -1, 0, 0, 0, 1, 1, 1, 2, 1, 1, 1, 2, 1, 1, 0, 1, -1};
       
   174 
       
   175 BasicType type2field[T_CONFLICT+1] = {
       
   176   (BasicType)0,            // 0,
       
   177   (BasicType)0,            // 1,
       
   178   (BasicType)0,            // 2,
       
   179   (BasicType)0,            // 3,
       
   180   T_BOOLEAN,               // T_BOOLEAN  =  4,
       
   181   T_CHAR,                  // T_CHAR     =  5,
       
   182   T_FLOAT,                 // T_FLOAT    =  6,
       
   183   T_DOUBLE,                // T_DOUBLE   =  7,
       
   184   T_BYTE,                  // T_BYTE     =  8,
       
   185   T_SHORT,                 // T_SHORT    =  9,
       
   186   T_INT,                   // T_INT      = 10,
       
   187   T_LONG,                  // T_LONG     = 11,
       
   188   T_OBJECT,                // T_OBJECT   = 12,
       
   189   T_OBJECT,                // T_ARRAY    = 13,
       
   190   T_VOID,                  // T_VOID     = 14,
       
   191   T_ADDRESS,               // T_ADDRESS  = 15,
       
   192   T_CONFLICT               // T_CONFLICT = 16,
       
   193 };
       
   194 
       
   195 
       
   196 BasicType type2wfield[T_CONFLICT+1] = {
       
   197   (BasicType)0,            // 0,
       
   198   (BasicType)0,            // 1,
       
   199   (BasicType)0,            // 2,
       
   200   (BasicType)0,            // 3,
       
   201   T_INT,     // T_BOOLEAN  =  4,
       
   202   T_INT,     // T_CHAR     =  5,
       
   203   T_FLOAT,   // T_FLOAT    =  6,
       
   204   T_DOUBLE,  // T_DOUBLE   =  7,
       
   205   T_INT,     // T_BYTE     =  8,
       
   206   T_INT,     // T_SHORT    =  9,
       
   207   T_INT,     // T_INT      = 10,
       
   208   T_LONG,    // T_LONG     = 11,
       
   209   T_OBJECT,  // T_OBJECT   = 12,
       
   210   T_OBJECT,  // T_ARRAY    = 13,
       
   211   T_VOID,    // T_VOID     = 14,
       
   212   T_ADDRESS, // T_ADDRESS  = 15,
       
   213   T_CONFLICT // T_CONFLICT = 16,
       
   214 };
       
   215 
       
   216 
       
   217 int type2aelembytes[T_CONFLICT+1] = {
       
   218   0,                      // 0
       
   219   0,                      // 1
       
   220   0,                      // 2
       
   221   0,                      // 3
       
   222   T_BOOLEAN_aelem_bytes,  // T_BOOLEAN  =  4,
       
   223   T_CHAR_aelem_bytes,     // T_CHAR     =  5,
       
   224   T_FLOAT_aelem_bytes,    // T_FLOAT    =  6,
       
   225   T_DOUBLE_aelem_bytes,   // T_DOUBLE   =  7,
       
   226   T_BYTE_aelem_bytes,     // T_BYTE     =  8,
       
   227   T_SHORT_aelem_bytes,    // T_SHORT    =  9,
       
   228   T_INT_aelem_bytes,      // T_INT      = 10,
       
   229   T_LONG_aelem_bytes,     // T_LONG     = 11,
       
   230   T_OBJECT_aelem_bytes,   // T_OBJECT   = 12,
       
   231   T_ARRAY_aelem_bytes,    // T_ARRAY    = 13,
       
   232   0,                      // T_VOID     = 14,
       
   233   T_INT_aelem_bytes,      // T_ADDRESS  = 15,
       
   234   0                       // T_CONFLICT = 16,
       
   235 };
       
   236 
       
   237 
       
   238 // Support for 64-bit integer arithmetic
       
   239 
       
   240 // The following code is mostly taken from JVM typedefs_md.h and system_md.c
       
   241 
       
   242 static const jlong  high_bit  = (jlong)1 << (jlong)63;
       
   243 static const jlong other_bits = ~high_bit;
       
   244 
       
   245 jlong float2long(jfloat f) {
       
   246   jlong tmp = (jlong) f;
       
   247   if (tmp != high_bit) {
       
   248     return tmp;
       
   249   } else {
       
   250     if (g_isnan((jdouble)f)) {
       
   251       return 0;
       
   252     }
       
   253     if (f < 0) {
       
   254       return high_bit;
       
   255     } else {
       
   256       return other_bits;
       
   257     }
       
   258   }
       
   259 }
       
   260 
       
   261 
       
   262 jlong double2long(jdouble f) {
       
   263   jlong tmp = (jlong) f;
       
   264   if (tmp != high_bit) {
       
   265     return tmp;
       
   266   } else {
       
   267     if (g_isnan(f)) {
       
   268       return 0;
       
   269     }
       
   270     if (f < 0) {
       
   271       return high_bit;
       
   272     } else {
       
   273       return other_bits;
       
   274     }
       
   275   }
       
   276 }
       
   277 
       
   278 // least common multiple
       
   279 size_t lcm(size_t a, size_t b) {
       
   280     size_t cur, div, next;
       
   281 
       
   282     cur = MAX2(a, b);
       
   283     div = MIN2(a, b);
       
   284 
       
   285     assert(div != 0, "lcm requires positive arguments");
       
   286 
       
   287 
       
   288     while ((next = cur % div) != 0) {
       
   289         cur = div; div = next;
       
   290     }
       
   291 
       
   292 
       
   293     julong result = julong(a) * b / div;
       
   294     assert(result <= (size_t)max_uintx, "Integer overflow in lcm");
       
   295 
       
   296     return size_t(result);
       
   297 }