< prev index next >

src/hotspot/share/utilities/globalDefinitions.cpp

Print this page

 99   static_assert( 1 == sizeof( jboolean),  "wrong size for basic type");
100   static_assert( 8 == sizeof( jlong),     "wrong size for basic type");
101   static_assert( 4 == sizeof( jfloat),    "wrong size for basic type");
102   static_assert( 8 == sizeof( jdouble),   "wrong size for basic type");
103   static_assert( 1 == sizeof( u1),        "wrong size for basic type");
104   static_assert( 2 == sizeof( u2),        "wrong size for basic type");
105   static_assert( 4 == sizeof( u4),        "wrong size for basic type");
106   static_assert(wordSize == BytesPerWord, "should be the same since they're used interchangeably");
107   static_assert(wordSize == HeapWordSize, "should be the same since they're also used interchangeably");
108 
109   assert(signature_constants_sane(), "");
110 
111   int num_type_chars = 0;
112   for (int i = 0; i < 99; i++) {
113     if (type2char((BasicType)i) != 0) {
114       assert(char2type(type2char((BasicType)i)) == i, "proper inverses");
115       assert(Signature::basic_type(type2char((BasicType)i)) == i, "proper inverses");
116       num_type_chars++;
117     }
118   }
119   assert(num_type_chars == 11, "must have tested the right number of mappings");
120   assert(char2type(0) == T_ILLEGAL, "correct illegality");
121 
122   {
123     for (int i = T_BOOLEAN; i <= T_CONFLICT; i++) {
124       BasicType vt = (BasicType)i;
125       BasicType ft = type2field[vt];
126       switch (vt) {
127       // the following types might plausibly show up in memory layouts:
128       case T_BOOLEAN:
129       case T_BYTE:
130       case T_CHAR:
131       case T_SHORT:
132       case T_INT:
133       case T_FLOAT:
134       case T_DOUBLE:
135       case T_LONG:
136       case T_OBJECT:
137       case T_ADDRESS:     // random raw pointer
138       case T_METADATA:    // metadata pointer
139       case T_NARROWOOP:   // compressed pointer

181     os::java_to_os_priority[10] = JavaPriority10_To_OSPriority;
182 
183   // Set the size of basic types here (after argument parsing but before
184   // stub generation).
185   if (UseCompressedOops) {
186     // Size info for oops within java objects is fixed
187     heapOopSize        = jintSize;
188     LogBytesPerHeapOop = LogBytesPerInt;
189     LogBitsPerHeapOop  = LogBitsPerInt;
190     BytesPerHeapOop    = BytesPerInt;
191     BitsPerHeapOop     = BitsPerInt;
192   } else {
193     heapOopSize        = oopSize;
194     LogBytesPerHeapOop = LogBytesPerWord;
195     LogBitsPerHeapOop  = LogBitsPerWord;
196     BytesPerHeapOop    = BytesPerWord;
197     BitsPerHeapOop     = BitsPerWord;
198   }
199   _type2aelembytes[T_OBJECT] = heapOopSize;
200   _type2aelembytes[T_ARRAY]  = heapOopSize;

201 }
202 
203 
204 // Map BasicType to signature character
205 char type2char_tab[T_CONFLICT+1] = {
206   0, 0, 0, 0,
207   JVM_SIGNATURE_BOOLEAN, JVM_SIGNATURE_CHAR,
208   JVM_SIGNATURE_FLOAT,   JVM_SIGNATURE_DOUBLE,
209   JVM_SIGNATURE_BYTE,    JVM_SIGNATURE_SHORT,
210   JVM_SIGNATURE_INT,     JVM_SIGNATURE_LONG,
211   JVM_SIGNATURE_CLASS,   JVM_SIGNATURE_ARRAY,
212   JVM_SIGNATURE_VOID,    0,
213   0, 0, 0, 0
214 };
215 
216 // Map BasicType to Java type name
217 const char* type2name_tab[T_CONFLICT+1] = {
218   nullptr, nullptr, nullptr, nullptr,
219   "boolean",
220   "char",
221   "float",
222   "double",
223   "byte",
224   "short",
225   "int",
226   "long",
227   "object",
228   "array",

229   "void",
230   "*address*",
231   "*narrowoop*",
232   "*metadata*",
233   "*narrowklass*",
234   "*conflict*"
235 };
236 const char* type2name(BasicType t) {
237   if (t < ARRAY_SIZE(type2name_tab)) {
238     return type2name_tab[t];
239   } else if (t == T_ILLEGAL) {
240     return "*illegal*";
241   } else {
242     fatal("invalid type %d", t);
243     return "invalid type";
244   }
245 }
246 
247 
248 
249 BasicType name2type(const char* name) {
250   for (int i = T_BOOLEAN; i <= T_VOID; i++) {
251     BasicType t = (BasicType)i;
252     if (type2name_tab[t] != nullptr && 0 == strcmp(type2name_tab[t], name))
253       return t;
254   }
255   return T_ILLEGAL;
256 }
257 
258 // Map BasicType to size in words
259 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};
260 
261 BasicType type2field[T_CONFLICT+1] = {
262   (BasicType)0,            // 0,
263   (BasicType)0,            // 1,
264   (BasicType)0,            // 2,
265   (BasicType)0,            // 3,
266   T_BOOLEAN,               // T_BOOLEAN  =  4,
267   T_CHAR,                  // T_CHAR     =  5,
268   T_FLOAT,                 // T_FLOAT    =  6,
269   T_DOUBLE,                // T_DOUBLE   =  7,
270   T_BYTE,                  // T_BYTE     =  8,
271   T_SHORT,                 // T_SHORT    =  9,
272   T_INT,                   // T_INT      = 10,
273   T_LONG,                  // T_LONG     = 11,
274   T_OBJECT,                // T_OBJECT   = 12,
275   T_OBJECT,                // T_ARRAY    = 13,
276   T_VOID,                  // T_VOID     = 14,
277   T_ADDRESS,               // T_ADDRESS  = 15,
278   T_NARROWOOP,             // T_NARROWOOP= 16,
279   T_METADATA,              // T_METADATA = 17,
280   T_NARROWKLASS,           // T_NARROWKLASS = 18,
281   T_CONFLICT               // T_CONFLICT = 19,

282 };
283 
284 
285 BasicType type2wfield[T_CONFLICT+1] = {
286   (BasicType)0,            // 0,
287   (BasicType)0,            // 1,
288   (BasicType)0,            // 2,
289   (BasicType)0,            // 3,
290   T_INT,     // T_BOOLEAN  =  4,
291   T_INT,     // T_CHAR     =  5,
292   T_FLOAT,   // T_FLOAT    =  6,
293   T_DOUBLE,  // T_DOUBLE   =  7,
294   T_INT,     // T_BYTE     =  8,
295   T_INT,     // T_SHORT    =  9,
296   T_INT,     // T_INT      = 10,
297   T_LONG,    // T_LONG     = 11,
298   T_OBJECT,  // T_OBJECT   = 12,
299   T_OBJECT,  // T_ARRAY    = 13,
300   T_VOID,    // T_VOID     = 14,
301   T_ADDRESS, // T_ADDRESS  = 15,
302   T_NARROWOOP, // T_NARROWOOP  = 16,
303   T_METADATA,  // T_METADATA   = 17,
304   T_NARROWKLASS, // T_NARROWKLASS  = 18,
305   T_CONFLICT // T_CONFLICT = 19,

306 };
307 
308 
309 int _type2aelembytes[T_CONFLICT+1] = {
310   0,                         // 0
311   0,                         // 1
312   0,                         // 2
313   0,                         // 3
314   T_BOOLEAN_aelem_bytes,     // T_BOOLEAN  =  4,
315   T_CHAR_aelem_bytes,        // T_CHAR     =  5,
316   T_FLOAT_aelem_bytes,       // T_FLOAT    =  6,
317   T_DOUBLE_aelem_bytes,      // T_DOUBLE   =  7,
318   T_BYTE_aelem_bytes,        // T_BYTE     =  8,
319   T_SHORT_aelem_bytes,       // T_SHORT    =  9,
320   T_INT_aelem_bytes,         // T_INT      = 10,
321   T_LONG_aelem_bytes,        // T_LONG     = 11,
322   T_OBJECT_aelem_bytes,      // T_OBJECT   = 12,
323   T_ARRAY_aelem_bytes,       // T_ARRAY    = 13,
324   0,                         // T_VOID     = 14,
325   T_OBJECT_aelem_bytes,      // T_ADDRESS  = 15,
326   T_NARROWOOP_aelem_bytes,   // T_NARROWOOP= 16,
327   T_OBJECT_aelem_bytes,      // T_METADATA = 17,
328   T_NARROWKLASS_aelem_bytes, // T_NARROWKLASS= 18,
329   0                          // T_CONFLICT = 19,

330 };
331 
332 #ifdef ASSERT
333 int type2aelembytes(BasicType t, bool allow_address) {
334   assert((allow_address || t != T_ADDRESS) && t <= T_CONFLICT, "unexpected basic type");
335   return _type2aelembytes[t];
336 }
337 #endif
338 
339 // Support for 64-bit integer arithmetic
340 
341 // The following code is mostly taken from JVM typedefs_md.h and system_md.c
342 
343 static const jlong high_bit   = (jlong)1 << (jlong)63;
344 static const jlong other_bits = ~high_bit;
345 
346 jlong float2long(jfloat f) {
347   jlong tmp = (jlong) f;
348   if (tmp != high_bit) {
349     return tmp;

 99   static_assert( 1 == sizeof( jboolean),  "wrong size for basic type");
100   static_assert( 8 == sizeof( jlong),     "wrong size for basic type");
101   static_assert( 4 == sizeof( jfloat),    "wrong size for basic type");
102   static_assert( 8 == sizeof( jdouble),   "wrong size for basic type");
103   static_assert( 1 == sizeof( u1),        "wrong size for basic type");
104   static_assert( 2 == sizeof( u2),        "wrong size for basic type");
105   static_assert( 4 == sizeof( u4),        "wrong size for basic type");
106   static_assert(wordSize == BytesPerWord, "should be the same since they're used interchangeably");
107   static_assert(wordSize == HeapWordSize, "should be the same since they're also used interchangeably");
108 
109   assert(signature_constants_sane(), "");
110 
111   int num_type_chars = 0;
112   for (int i = 0; i < 99; i++) {
113     if (type2char((BasicType)i) != 0) {
114       assert(char2type(type2char((BasicType)i)) == i, "proper inverses");
115       assert(Signature::basic_type(type2char((BasicType)i)) == i, "proper inverses");
116       num_type_chars++;
117     }
118   }
119   assert(num_type_chars == 12, "must have tested the right number of mappings");
120   assert(char2type(0) == T_ILLEGAL, "correct illegality");
121 
122   {
123     for (int i = T_BOOLEAN; i <= T_CONFLICT; i++) {
124       BasicType vt = (BasicType)i;
125       BasicType ft = type2field[vt];
126       switch (vt) {
127       // the following types might plausibly show up in memory layouts:
128       case T_BOOLEAN:
129       case T_BYTE:
130       case T_CHAR:
131       case T_SHORT:
132       case T_INT:
133       case T_FLOAT:
134       case T_DOUBLE:
135       case T_LONG:
136       case T_OBJECT:
137       case T_ADDRESS:     // random raw pointer
138       case T_METADATA:    // metadata pointer
139       case T_NARROWOOP:   // compressed pointer

181     os::java_to_os_priority[10] = JavaPriority10_To_OSPriority;
182 
183   // Set the size of basic types here (after argument parsing but before
184   // stub generation).
185   if (UseCompressedOops) {
186     // Size info for oops within java objects is fixed
187     heapOopSize        = jintSize;
188     LogBytesPerHeapOop = LogBytesPerInt;
189     LogBitsPerHeapOop  = LogBitsPerInt;
190     BytesPerHeapOop    = BytesPerInt;
191     BitsPerHeapOop     = BitsPerInt;
192   } else {
193     heapOopSize        = oopSize;
194     LogBytesPerHeapOop = LogBytesPerWord;
195     LogBitsPerHeapOop  = LogBitsPerWord;
196     BytesPerHeapOop    = BytesPerWord;
197     BitsPerHeapOop     = BitsPerWord;
198   }
199   _type2aelembytes[T_OBJECT] = heapOopSize;
200   _type2aelembytes[T_ARRAY]  = heapOopSize;
201   _type2aelembytes[T_PRIMITIVE_OBJECT]  = heapOopSize;
202 }
203 
204 
205 // Map BasicType to signature character
206 char type2char_tab[T_CONFLICT+1] = {
207   0, 0, 0, 0,
208   JVM_SIGNATURE_BOOLEAN, JVM_SIGNATURE_CHAR,
209   JVM_SIGNATURE_FLOAT,   JVM_SIGNATURE_DOUBLE,
210   JVM_SIGNATURE_BYTE,    JVM_SIGNATURE_SHORT,
211   JVM_SIGNATURE_INT,     JVM_SIGNATURE_LONG,
212   JVM_SIGNATURE_CLASS,   JVM_SIGNATURE_ARRAY,
213   JVM_SIGNATURE_PRIMITIVE_OBJECT, JVM_SIGNATURE_VOID,
214   0, 0, 0, 0, 0
215 };
216 
217 // Map BasicType to Java type name
218 const char* type2name_tab[T_CONFLICT+1] = {
219   nullptr, nullptr, nullptr, nullptr,
220   "boolean",
221   "char",
222   "float",
223   "double",
224   "byte",
225   "short",
226   "int",
227   "long",
228   "object",
229   "array",
230   "inline_type",
231   "void",
232   "*address*",
233   "*narrowoop*",
234   "*metadata*",
235   "*narrowklass*",
236   "*conflict*"
237 };
238 const char* type2name(BasicType t) {
239   if (t < ARRAY_SIZE(type2name_tab)) {
240     return type2name_tab[t];
241   } else if (t == T_ILLEGAL) {
242     return "*illegal*";
243   } else {
244     fatal("invalid type %d", t);
245     return "invalid type";
246   }
247 }
248 
249 
250 
251 BasicType name2type(const char* name) {
252   for (int i = T_BOOLEAN; i <= T_VOID; i++) {
253     BasicType t = (BasicType)i;
254     if (type2name_tab[t] != nullptr && 0 == strcmp(type2name_tab[t], name))
255       return t;
256   }
257   return T_ILLEGAL;
258 }
259 
260 // Map BasicType to size in words
261 int type2size[T_CONFLICT+1]={ -1, 0, 0, 0, 1, 1, 1, 2, 1, 1, 1, 2, 1, 1, 1, 0, 1, 1, 1, 1, -1};
262 
263 BasicType type2field[T_CONFLICT+1] = {
264   (BasicType)0,            // 0,
265   (BasicType)0,            // 1,
266   (BasicType)0,            // 2,
267   (BasicType)0,            // 3,
268   T_BOOLEAN,               // T_BOOLEAN  =  4,
269   T_CHAR,                  // T_CHAR     =  5,
270   T_FLOAT,                 // T_FLOAT    =  6,
271   T_DOUBLE,                // T_DOUBLE   =  7,
272   T_BYTE,                  // T_BYTE     =  8,
273   T_SHORT,                 // T_SHORT    =  9,
274   T_INT,                   // T_INT      = 10,
275   T_LONG,                  // T_LONG     = 11,
276   T_OBJECT,                // T_OBJECT   = 12,
277   T_OBJECT,                // T_ARRAY    = 13,
278   T_OBJECT,                // T_PRIMITIVE_OBJECT = 14,
279   T_VOID,                  // T_VOID     = 15,
280   T_ADDRESS,               // T_ADDRESS  = 16,
281   T_NARROWOOP,             // T_NARROWOOP= 17,
282   T_METADATA,              // T_METADATA = 18,
283   T_NARROWKLASS,           // T_NARROWKLASS = 19,
284   T_CONFLICT               // T_CONFLICT = 20
285 };
286 
287 
288 BasicType type2wfield[T_CONFLICT+1] = {
289   (BasicType)0,            // 0,
290   (BasicType)0,            // 1,
291   (BasicType)0,            // 2,
292   (BasicType)0,            // 3,
293   T_INT,     // T_BOOLEAN  =  4,
294   T_INT,     // T_CHAR     =  5,
295   T_FLOAT,   // T_FLOAT    =  6,
296   T_DOUBLE,  // T_DOUBLE   =  7,
297   T_INT,     // T_BYTE     =  8,
298   T_INT,     // T_SHORT    =  9,
299   T_INT,     // T_INT      = 10,
300   T_LONG,    // T_LONG     = 11,
301   T_OBJECT,  // T_OBJECT   = 12,
302   T_OBJECT,  // T_ARRAY    = 13,
303   T_OBJECT,  // T_PRIMITIVE_OBJECT = 14,
304   T_VOID,    // T_VOID     = 15,
305   T_ADDRESS, // T_ADDRESS  = 16,
306   T_NARROWOOP, // T_NARROWOOP  = 17,
307   T_METADATA,  // T_METADATA   = 18,
308   T_NARROWKLASS, // T_NARROWKLASS  = 19,
309   T_CONFLICT // T_CONFLICT = 20
310 };
311 
312 
313 int _type2aelembytes[T_CONFLICT+1] = {
314   0,                         // 0
315   0,                         // 1
316   0,                         // 2
317   0,                         // 3
318   T_BOOLEAN_aelem_bytes,     // T_BOOLEAN  =  4,
319   T_CHAR_aelem_bytes,        // T_CHAR     =  5,
320   T_FLOAT_aelem_bytes,       // T_FLOAT    =  6,
321   T_DOUBLE_aelem_bytes,      // T_DOUBLE   =  7,
322   T_BYTE_aelem_bytes,        // T_BYTE     =  8,
323   T_SHORT_aelem_bytes,       // T_SHORT    =  9,
324   T_INT_aelem_bytes,         // T_INT      = 10,
325   T_LONG_aelem_bytes,        // T_LONG     = 11,
326   T_OBJECT_aelem_bytes,      // T_OBJECT   = 12,
327   T_ARRAY_aelem_bytes,       // T_ARRAY    = 13,
328   T_PRIMITIVE_OBJECT_aelem_bytes, // T_PRIMITIVE_OBJECT = 14,
329   0,                         // T_VOID     = 15,
330   T_OBJECT_aelem_bytes,      // T_ADDRESS  = 16,
331   T_NARROWOOP_aelem_bytes,   // T_NARROWOOP= 17,
332   T_OBJECT_aelem_bytes,      // T_METADATA = 18,
333   T_NARROWKLASS_aelem_bytes, // T_NARROWKLASS= 19,
334   0                          // T_CONFLICT = 20
335 };
336 
337 #ifdef ASSERT
338 int type2aelembytes(BasicType t, bool allow_address) {
339   assert((allow_address || t != T_ADDRESS) && t <= T_CONFLICT, "unexpected basic type");
340   return _type2aelembytes[t];
341 }
342 #endif
343 
344 // Support for 64-bit integer arithmetic
345 
346 // The following code is mostly taken from JVM typedefs_md.h and system_md.c
347 
348 static const jlong high_bit   = (jlong)1 << (jlong)63;
349 static const jlong other_bits = ~high_bit;
350 
351 jlong float2long(jfloat f) {
352   jlong tmp = (jlong) f;
353   if (tmp != high_bit) {
354     return tmp;
< prev index next >