src/share/vm/utilities/globalDefinitions.hpp

changeset 9610
f43f77de876a
parent 9325
6ab57fe8b51f
child 9613
67aa2bb0d84e
     1.1 --- a/src/share/vm/utilities/globalDefinitions.hpp	Wed Jan 30 17:32:47 2019 +0000
     1.2 +++ b/src/share/vm/utilities/globalDefinitions.hpp	Fri Feb 01 10:47:30 2019 +0100
     1.3 @@ -1403,6 +1403,32 @@
     1.4  
     1.5  #define ARRAY_SIZE(array) (sizeof(array)/sizeof((array)[0]))
     1.6  
     1.7 +//----------------------------------------------------------------------------------------------------
     1.8 +// Sum and product which can never overflow: they wrap, just like the
     1.9 +// Java operations.  Note that we don't intend these to be used for
    1.10 +// general-purpose arithmetic: their purpose is to emulate Java
    1.11 +// operations.
    1.12 +
    1.13 +// The goal of this code to avoid undefined or implementation-defined
    1.14 +// behaviour.  The use of an lvalue to reference cast is explicitly
    1.15 +// permitted by Lvalues and rvalues [basic.lval].  [Section 3.10 Para
    1.16 +// 15 in C++03]
    1.17 +#define JAVA_INTEGER_OP(OP, NAME, TYPE, UNSIGNED_TYPE)  \
    1.18 +inline TYPE NAME (TYPE in1, TYPE in2) {                 \
    1.19 +  UNSIGNED_TYPE ures = static_cast<UNSIGNED_TYPE>(in1); \
    1.20 +  ures OP ## = static_cast<UNSIGNED_TYPE>(in2);         \
    1.21 +  return reinterpret_cast<TYPE&>(ures);                 \
    1.22 +}
    1.23 +
    1.24 +JAVA_INTEGER_OP(+, java_add, jint, juint)
    1.25 +JAVA_INTEGER_OP(-, java_subtract, jint, juint)
    1.26 +JAVA_INTEGER_OP(*, java_multiply, jint, juint)
    1.27 +JAVA_INTEGER_OP(+, java_add, jlong, julong)
    1.28 +JAVA_INTEGER_OP(-, java_subtract, jlong, julong)
    1.29 +JAVA_INTEGER_OP(*, java_multiply, jlong, julong)
    1.30 +
    1.31 +#undef JAVA_INTEGER_OP
    1.32 +
    1.33  // Dereference vptr
    1.34  // All C++ compilers that we know of have the vtbl pointer in the first
    1.35  // word.  If there are exceptions, this function needs to be made compiler

mercurial