< prev index next >

src/hotspot/share/utilities/globalDefinitions.hpp

Print this page




1068 // The goal of this code to avoid undefined or implementation-defined
1069 // behavior.  The use of an lvalue to reference cast is explicitly
1070 // permitted by Lvalues and rvalues [basic.lval].  [Section 3.10 Para
1071 // 15 in C++03]
1072 #define JAVA_INTEGER_OP(OP, NAME, TYPE, UNSIGNED_TYPE)  \
1073 inline TYPE NAME (TYPE in1, TYPE in2) {                 \
1074   UNSIGNED_TYPE ures = static_cast<UNSIGNED_TYPE>(in1); \
1075   ures OP ## = static_cast<UNSIGNED_TYPE>(in2);         \
1076   return reinterpret_cast<TYPE&>(ures);                 \
1077 }
1078 
1079 JAVA_INTEGER_OP(+, java_add, jint, juint)
1080 JAVA_INTEGER_OP(-, java_subtract, jint, juint)
1081 JAVA_INTEGER_OP(*, java_multiply, jint, juint)
1082 JAVA_INTEGER_OP(+, java_add, jlong, julong)
1083 JAVA_INTEGER_OP(-, java_subtract, jlong, julong)
1084 JAVA_INTEGER_OP(*, java_multiply, jlong, julong)
1085 
1086 #undef JAVA_INTEGER_OP
1087 
1088 //----------------------------------------------------------------------------------------------------
1089 // The goal of this code is to provide saturating operations for int/uint.
1090 // Checks overflow conditions and saturates the result to min_jint/max_jint.
1091 #define SATURATED_INTEGER_OP(OP, NAME, TYPE1, TYPE2) \
1092 inline int NAME (TYPE1 in1, TYPE2 in2) {             \
1093   jlong res = static_cast<jlong>(in1);               \
1094   res OP ## = static_cast<jlong>(in2);               \
1095   if (res > max_jint) {                              \
1096     res = max_jint;                                  \
1097   } else if (res < min_jint) {                       \
1098     res = min_jint;                                  \
1099   }                                                  \
1100   return static_cast<int>(res);                      \
1101 }
1102 
1103 SATURATED_INTEGER_OP(+, saturated_add, int, int)
1104 SATURATED_INTEGER_OP(+, saturated_add, int, uint)
1105 SATURATED_INTEGER_OP(+, saturated_add, uint, int)
1106 SATURATED_INTEGER_OP(+, saturated_add, uint, uint)
1107 
1108 #undef SATURATED_INTEGER_OP
1109 
1110 // Dereference vptr
1111 // All C++ compilers that we know of have the vtbl pointer in the first
1112 // word.  If there are exceptions, this function needs to be made compiler
1113 // specific.
1114 static inline void* dereference_vptr(const void* addr) {
1115   return *(void**)addr;
1116 }
1117 
1118 //----------------------------------------------------------------------------------------------------
1119 // String type aliases used by command line flag declarations and
1120 // processing utilities.
1121 
1122 typedef const char* ccstr;
1123 typedef const char* ccstrlist;   // represents string arguments which accumulate
1124 
1125 //----------------------------------------------------------------------------------------------------
1126 // Default hash/equals functions used by ResourceHashtable and KVHashtable
1127 
1128 template<typename K> unsigned primitive_hash(const K& k) {
1129   unsigned hash = (unsigned)((uintptr_t)k);


1068 // The goal of this code to avoid undefined or implementation-defined
1069 // behavior.  The use of an lvalue to reference cast is explicitly
1070 // permitted by Lvalues and rvalues [basic.lval].  [Section 3.10 Para
1071 // 15 in C++03]
1072 #define JAVA_INTEGER_OP(OP, NAME, TYPE, UNSIGNED_TYPE)  \
1073 inline TYPE NAME (TYPE in1, TYPE in2) {                 \
1074   UNSIGNED_TYPE ures = static_cast<UNSIGNED_TYPE>(in1); \
1075   ures OP ## = static_cast<UNSIGNED_TYPE>(in2);         \
1076   return reinterpret_cast<TYPE&>(ures);                 \
1077 }
1078 
1079 JAVA_INTEGER_OP(+, java_add, jint, juint)
1080 JAVA_INTEGER_OP(-, java_subtract, jint, juint)
1081 JAVA_INTEGER_OP(*, java_multiply, jint, juint)
1082 JAVA_INTEGER_OP(+, java_add, jlong, julong)
1083 JAVA_INTEGER_OP(-, java_subtract, jlong, julong)
1084 JAVA_INTEGER_OP(*, java_multiply, jlong, julong)
1085 
1086 #undef JAVA_INTEGER_OP
1087 






















1088 // Dereference vptr
1089 // All C++ compilers that we know of have the vtbl pointer in the first
1090 // word.  If there are exceptions, this function needs to be made compiler
1091 // specific.
1092 static inline void* dereference_vptr(const void* addr) {
1093   return *(void**)addr;
1094 }
1095 
1096 //----------------------------------------------------------------------------------------------------
1097 // String type aliases used by command line flag declarations and
1098 // processing utilities.
1099 
1100 typedef const char* ccstr;
1101 typedef const char* ccstrlist;   // represents string arguments which accumulate
1102 
1103 //----------------------------------------------------------------------------------------------------
1104 // Default hash/equals functions used by ResourceHashtable and KVHashtable
1105 
1106 template<typename K> unsigned primitive_hash(const K& k) {
1107   unsigned hash = (unsigned)((uintptr_t)k);
< prev index next >