1241 // The goal of this code to avoid undefined or implementation-defined 1242 // behavior. The use of an lvalue to reference cast is explicitly 1243 // permitted by Lvalues and rvalues [basic.lval]. [Section 3.10 Para 1244 // 15 in C++03] 1245 #define JAVA_INTEGER_OP(OP, NAME, TYPE, UNSIGNED_TYPE) \ 1246 inline TYPE NAME (TYPE in1, TYPE in2) { \ 1247 UNSIGNED_TYPE ures = static_cast<UNSIGNED_TYPE>(in1); \ 1248 ures OP ## = static_cast<UNSIGNED_TYPE>(in2); \ 1249 return reinterpret_cast<TYPE&>(ures); \ 1250 } 1251 1252 JAVA_INTEGER_OP(+, java_add, jint, juint) 1253 JAVA_INTEGER_OP(-, java_subtract, jint, juint) 1254 JAVA_INTEGER_OP(*, java_multiply, jint, juint) 1255 JAVA_INTEGER_OP(+, java_add, jlong, julong) 1256 JAVA_INTEGER_OP(-, java_subtract, jlong, julong) 1257 JAVA_INTEGER_OP(*, java_multiply, jlong, julong) 1258 1259 #undef JAVA_INTEGER_OP 1260 1261 // Dereference vptr 1262 // All C++ compilers that we know of have the vtbl pointer in the first 1263 // word. If there are exceptions, this function needs to be made compiler 1264 // specific. 1265 static inline void* dereference_vptr(const void* addr) { 1266 return *(void**)addr; 1267 } 1268 1269 #endif // SHARE_VM_UTILITIES_GLOBALDEFINITIONS_HPP | 1241 // The goal of this code to avoid undefined or implementation-defined 1242 // behavior. The use of an lvalue to reference cast is explicitly 1243 // permitted by Lvalues and rvalues [basic.lval]. [Section 3.10 Para 1244 // 15 in C++03] 1245 #define JAVA_INTEGER_OP(OP, NAME, TYPE, UNSIGNED_TYPE) \ 1246 inline TYPE NAME (TYPE in1, TYPE in2) { \ 1247 UNSIGNED_TYPE ures = static_cast<UNSIGNED_TYPE>(in1); \ 1248 ures OP ## = static_cast<UNSIGNED_TYPE>(in2); \ 1249 return reinterpret_cast<TYPE&>(ures); \ 1250 } 1251 1252 JAVA_INTEGER_OP(+, java_add, jint, juint) 1253 JAVA_INTEGER_OP(-, java_subtract, jint, juint) 1254 JAVA_INTEGER_OP(*, java_multiply, jint, juint) 1255 JAVA_INTEGER_OP(+, java_add, jlong, julong) 1256 JAVA_INTEGER_OP(-, java_subtract, jlong, julong) 1257 JAVA_INTEGER_OP(*, java_multiply, jlong, julong) 1258 1259 #undef JAVA_INTEGER_OP 1260 1261 #ifdef _WINDOWS 1262 // Overloading to match (int, int) to (jint, jint) 1263 // because windows jint is type long 1264 inline jint java_add(int in1, int in2) { 1265 return java_add((jint)in1, (jint)in2); 1266 } 1267 #endif 1268 1269 // Dereference vptr 1270 // All C++ compilers that we know of have the vtbl pointer in the first 1271 // word. If there are exceptions, this function needs to be made compiler 1272 // specific. 1273 static inline void* dereference_vptr(const void* addr) { 1274 return *(void**)addr; 1275 } 1276 1277 #endif // SHARE_VM_UTILITIES_GLOBALDEFINITIONS_HPP |