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