< prev index next >

src/hotspot/share/utilities/globalDefinitions.cpp

Print this page

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

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

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

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, 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_VOID,                  // T_VOID     = 14,
280   T_ADDRESS,               // T_ADDRESS  = 15,
281   T_NARROWOOP,             // T_NARROWOOP= 16,
282   T_METADATA,              // T_METADATA = 17,
283   T_NARROWKLASS,           // T_NARROWKLASS = 18,
284   T_CONFLICT               // T_CONFLICT = 19,

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_VOID,    // T_VOID     = 14,
304   T_ADDRESS, // T_ADDRESS  = 15,
305   T_NARROWOOP, // T_NARROWOOP  = 16,
306   T_METADATA,  // T_METADATA   = 17,
307   T_NARROWKLASS, // T_NARROWKLASS  = 18,
308   T_CONFLICT // T_CONFLICT = 19,

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   0,                         // T_VOID     = 14,
328   T_OBJECT_aelem_bytes,      // T_ADDRESS  = 15,
329   T_NARROWOOP_aelem_bytes,   // T_NARROWOOP= 16,
330   T_OBJECT_aelem_bytes,      // T_METADATA = 17,
331   T_NARROWKLASS_aelem_bytes, // T_NARROWKLASS= 18,
332   0                          // T_CONFLICT = 19,

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

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

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