< 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

182     os::java_to_os_priority[10] = JavaPriority10_To_OSPriority;
183 
184   // Set the size of basic types here (after argument parsing but before
185   // stub generation).
186   if (UseCompressedOops) {
187     // Size info for oops within java objects is fixed
188     heapOopSize        = jintSize;
189     LogBytesPerHeapOop = LogBytesPerInt;
190     LogBitsPerHeapOop  = LogBitsPerInt;
191     BytesPerHeapOop    = BytesPerInt;
192     BitsPerHeapOop     = BitsPerInt;
193   } else {
194     heapOopSize        = oopSize;
195     LogBytesPerHeapOop = LogBytesPerWord;
196     LogBitsPerHeapOop  = LogBitsPerWord;
197     BytesPerHeapOop    = BytesPerWord;
198     BitsPerHeapOop     = BitsPerWord;
199   }
200   _type2aelembytes[T_OBJECT] = heapOopSize;
201   _type2aelembytes[T_ARRAY]  = 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_VOID,    0,
214   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   "void",
231   "*address*",
232   "*narrowoop*",
233   "*metadata*",
234   "*narrowklass*",
235   "*conflict*"
236 };
237 const char* type2name(BasicType t) {
238   if (t < ARRAY_SIZE(type2name_tab)) {
239     return type2name_tab[t];
240   } else if (t == T_ILLEGAL) {
241     return "*illegal*";
242   } else {
243     fatal("invalid type %d", t);
244     return "invalid type";
245   }
246 }
247 
248 
249 
250 BasicType name2type(const char* name) {
251   for (int i = T_BOOLEAN; i <= T_VOID; i++) {
252     BasicType t = (BasicType)i;
253     if (type2name_tab[t] != nullptr && 0 == strcmp(type2name_tab[t], name))
254       return t;
255   }
256   return T_ILLEGAL;
257 }
258 
259 // Map BasicType to size in words
260 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};
261 
262 BasicType type2field[T_CONFLICT+1] = {
263   (BasicType)0,            // 0,
264   (BasicType)0,            // 1,
265   (BasicType)0,            // 2,
266   (BasicType)0,            // 3,
267   T_BOOLEAN,               // T_BOOLEAN  =  4,
268   T_CHAR,                  // T_CHAR     =  5,
269   T_FLOAT,                 // T_FLOAT    =  6,
270   T_DOUBLE,                // T_DOUBLE   =  7,
271   T_BYTE,                  // T_BYTE     =  8,
272   T_SHORT,                 // T_SHORT    =  9,
273   T_INT,                   // T_INT      = 10,
274   T_LONG,                  // T_LONG     = 11,
275   T_OBJECT,                // T_OBJECT   = 12,
276   T_OBJECT,                // T_ARRAY    = 13,
277   T_VOID,                  // T_VOID     = 14,
278   T_ADDRESS,               // T_ADDRESS  = 15,
279   T_NARROWOOP,             // T_NARROWOOP= 16,
280   T_METADATA,              // T_METADATA = 17,
281   T_NARROWKLASS,           // T_NARROWKLASS = 18,
282   T_CONFLICT               // T_CONFLICT = 19,

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

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

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

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