< prev index next >

src/hotspot/share/utilities/globalDefinitions.cpp

Print this page

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

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

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

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

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

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

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

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

180     os::java_to_os_priority[10] = JavaPriority10_To_OSPriority;
181 
182   // Set the size of basic types here (after argument parsing but before
183   // stub generation).
184   if (UseCompressedOops) {
185     // Size info for oops within java objects is fixed
186     heapOopSize        = jintSize;
187     LogBytesPerHeapOop = LogBytesPerInt;
188     LogBitsPerHeapOop  = LogBitsPerInt;
189     BytesPerHeapOop    = BytesPerInt;
190     BitsPerHeapOop     = BitsPerInt;
191   } else {
192     heapOopSize        = oopSize;
193     LogBytesPerHeapOop = LogBytesPerWord;
194     LogBitsPerHeapOop  = LogBitsPerWord;
195     BytesPerHeapOop    = BytesPerWord;
196     BitsPerHeapOop     = BitsPerWord;
197   }
198   _type2aelembytes[T_OBJECT] = heapOopSize;
199   _type2aelembytes[T_ARRAY]  = heapOopSize;
200   _type2aelembytes[T_FLAT_ELEMENT]  = 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_FLAT_ELEMENT, JVM_SIGNATURE_VOID,
213   0, 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   "inline_type",
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, 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_OBJECT,                // T_PRIMITIVE_OBJECT = 14,
278   T_VOID,                  // T_VOID     = 15,
279   T_ADDRESS,               // T_ADDRESS  = 16,
280   T_NARROWOOP,             // T_NARROWOOP= 17,
281   T_METADATA,              // T_METADATA = 18,
282   T_NARROWKLASS,           // T_NARROWKLASS = 19,
283   T_CONFLICT               // T_CONFLICT = 20
284 };
285 
286 
287 BasicType type2wfield[T_CONFLICT+1] = {
288   (BasicType)0,            // 0,
289   (BasicType)0,            // 1,
290   (BasicType)0,            // 2,
291   (BasicType)0,            // 3,
292   T_INT,     // T_BOOLEAN  =  4,
293   T_INT,     // T_CHAR     =  5,
294   T_FLOAT,   // T_FLOAT    =  6,
295   T_DOUBLE,  // T_DOUBLE   =  7,
296   T_INT,     // T_BYTE     =  8,
297   T_INT,     // T_SHORT    =  9,
298   T_INT,     // T_INT      = 10,
299   T_LONG,    // T_LONG     = 11,
300   T_OBJECT,  // T_OBJECT   = 12,
301   T_OBJECT,  // T_ARRAY    = 13,
302   T_OBJECT,  // T_PRIMITIVE_OBJECT = 14,
303   T_VOID,    // T_VOID     = 15,
304   T_ADDRESS, // T_ADDRESS  = 16,
305   T_NARROWOOP, // T_NARROWOOP  = 17,
306   T_METADATA,  // T_METADATA   = 18,
307   T_NARROWKLASS, // T_NARROWKLASS  = 19,
308   T_CONFLICT // T_CONFLICT = 20
309 };
310 
311 
312 int _type2aelembytes[T_CONFLICT+1] = {
313   0,                         // 0
314   0,                         // 1
315   0,                         // 2
316   0,                         // 3
317   T_BOOLEAN_aelem_bytes,     // T_BOOLEAN  =  4,
318   T_CHAR_aelem_bytes,        // T_CHAR     =  5,
319   T_FLOAT_aelem_bytes,       // T_FLOAT    =  6,
320   T_DOUBLE_aelem_bytes,      // T_DOUBLE   =  7,
321   T_BYTE_aelem_bytes,        // T_BYTE     =  8,
322   T_SHORT_aelem_bytes,       // T_SHORT    =  9,
323   T_INT_aelem_bytes,         // T_INT      = 10,
324   T_LONG_aelem_bytes,        // T_LONG     = 11,
325   T_OBJECT_aelem_bytes,      // T_OBJECT   = 12,
326   T_ARRAY_aelem_bytes,       // T_ARRAY    = 13,
327   T_FLAT_ELEMENT_aelem_bytes, // T_PRIMITIVE_OBJECT = 14,
328   0,                         // T_VOID     = 15,
329   T_OBJECT_aelem_bytes,      // T_ADDRESS  = 16,
330   T_NARROWOOP_aelem_bytes,   // T_NARROWOOP= 17,
331   T_OBJECT_aelem_bytes,      // T_METADATA = 18,
332   T_NARROWKLASS_aelem_bytes, // T_NARROWKLASS= 19,
333   0                          // T_CONFLICT = 20
334 };
335 
336 #ifdef ASSERT
337 int type2aelembytes(BasicType t, bool allow_address) {
338   assert((allow_address || t != T_ADDRESS) && t <= T_CONFLICT, "unexpected basic type");
339   return _type2aelembytes[t];
340 }
341 #endif
342 
343 // Support for 64-bit integer arithmetic
344 
345 // The following code is mostly taken from JVM typedefs_md.h and system_md.c
346 
347 static const jlong high_bit   = (jlong)1 << (jlong)63;
348 static const jlong other_bits = ~high_bit;
349 
350 jlong float2long(jfloat f) {
351   jlong tmp = (jlong) f;
352   if (tmp != high_bit) {
353     return tmp;
< prev index next >