< prev index next >

src/share/vm/utilities/globalDefinitions.hpp

Print this page
rev 13109 : imported patch move_pns
rev 13110 : imported patch target_macros
rev 13111 : imported patch flip_depend


   8  *
   9  * This code is distributed in the hope that it will be useful, but WITHOUT
  10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  11  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  12  * version 2 for more details (a copy is included in the LICENSE file that
  13  * accompanied this code).
  14  *
  15  * You should have received a copy of the GNU General Public License version
  16  * 2 along with this work; if not, write to the Free Software Foundation,
  17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  18  *
  19  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  20  * or visit www.oracle.com if you need additional information or have any
  21  * questions.
  22  *
  23  */
  24 
  25 #ifndef SHARE_VM_UTILITIES_GLOBALDEFINITIONS_HPP
  26 #define SHARE_VM_UTILITIES_GLOBALDEFINITIONS_HPP
  27 
  28 #ifdef TARGET_COMPILER_gcc
  29 # include "utilities/globalDefinitions_gcc.hpp"
  30 #endif
  31 #ifdef TARGET_COMPILER_visCPP
  32 # include "utilities/globalDefinitions_visCPP.hpp"
  33 #endif
  34 #ifdef TARGET_COMPILER_sparcWorks
  35 # include "utilities/globalDefinitions_sparcWorks.hpp"
  36 #endif
  37 #ifdef TARGET_COMPILER_xlc
  38 # include "utilities/globalDefinitions_xlc.hpp"
  39 #endif
  40 


  41 #ifndef NOINLINE
  42 #define NOINLINE
  43 #endif
  44 #ifndef ALWAYSINLINE
  45 #define ALWAYSINLINE inline
  46 #endif
  47 #ifndef PRAGMA_DIAG_PUSH
  48 #define PRAGMA_DIAG_PUSH
  49 #endif
  50 #ifndef PRAGMA_DIAG_POP
  51 #define PRAGMA_DIAG_POP
  52 #endif
  53 #ifndef PRAGMA_FORMAT_NONLITERAL_IGNORED
  54 #define PRAGMA_FORMAT_NONLITERAL_IGNORED
  55 #endif
  56 #ifndef PRAGMA_FORMAT_IGNORED
  57 #define PRAGMA_FORMAT_IGNORED
  58 #endif
  59 #ifndef PRAGMA_FORMAT_NONLITERAL_IGNORED_INTERNAL
  60 #define PRAGMA_FORMAT_NONLITERAL_IGNORED_INTERNAL
  61 #endif
  62 #ifndef PRAGMA_FORMAT_NONLITERAL_IGNORED_EXTERNAL
  63 #define PRAGMA_FORMAT_NONLITERAL_IGNORED_EXTERNAL
















  64 #endif
  65 #ifndef ATTRIBUTE_PRINTF
  66 #define ATTRIBUTE_PRINTF(fmt, vargs)
  67 #endif
  68 #ifndef ATTRIBUTE_SCANF
  69 #define ATTRIBUTE_SCANF(fmt, vargs)
  70 #endif
  71 
  72 #include "utilities/macros.hpp"







  73 
  74 // This file holds all globally used constants & types, class (forward)
  75 // declarations and a few frequently used utility functions.











  76 
  77 //----------------------------------------------------------------------------------------------------
  78 // Constants
  79 
  80 const int LogBytesPerShort   = 1;
  81 const int LogBytesPerInt     = 2;
  82 #ifdef _LP64
  83 const int LogBytesPerWord    = 3;
  84 #else
  85 const int LogBytesPerWord    = 2;
  86 #endif
  87 const int LogBytesPerLong    = 3;
  88 
  89 const int BytesPerShort      = 1 << LogBytesPerShort;
  90 const int BytesPerInt        = 1 << LogBytesPerInt;
  91 const int BytesPerWord       = 1 << LogBytesPerWord;
  92 const int BytesPerLong       = 1 << LogBytesPerLong;
  93 
  94 const int LogBitsPerByte     = 3;
  95 const int LogBitsPerShort    = LogBitsPerByte + LogBytesPerShort;


 933 
 934 class CodeBlob;
 935 class  CompiledMethod;
 936 class   nmethod;
 937 class RuntimeBlob;
 938 class  OSRAdapter;
 939 class  I2CAdapter;
 940 class  C2IAdapter;
 941 class CompiledIC;
 942 class relocInfo;
 943 class ScopeDesc;
 944 class PcDesc;
 945 
 946 class Recompiler;
 947 class Recompilee;
 948 class RecompilationPolicy;
 949 class RFrame;
 950 class  CompiledRFrame;
 951 class  InterpretedRFrame;
 952 
 953 class frame;
 954 
 955 class vframe;
 956 class   javaVFrame;
 957 class     interpretedVFrame;
 958 class     compiledVFrame;
 959 class     deoptimizedVFrame;
 960 class   externalVFrame;
 961 class     entryVFrame;
 962 
 963 class RegisterMap;
 964 
 965 class Mutex;
 966 class Monitor;
 967 class BasicLock;
 968 class BasicObjectLock;
 969 
 970 class PeriodicTask;
 971 
 972 class JavaCallWrapper;
 973 
 974 class   oopDesc;


 995 
 996 class PrivilegedElement;
 997 class MonitorArray;
 998 
 999 class MonitorInfo;
1000 
1001 class OffsetClosure;
1002 class OopMapCache;
1003 class InterpreterOopMap;
1004 class OopMapCacheEntry;
1005 class OSThread;
1006 
1007 typedef int (*OSThreadStartFunc)(void*);
1008 
1009 class Space;
1010 
1011 class JavaValue;
1012 class methodHandle;
1013 class JavaCallArguments;
1014 
1015 // Basic support for errors (general debug facilities not defined at this point fo the include phase)
1016 
1017 extern void basic_fatal(const char* msg);
1018 
1019 
1020 //----------------------------------------------------------------------------------------------------
1021 // Special constants for debugging
1022 
1023 const jint     badInt           = -3;                       // generic "bad int" value
1024 const long     badAddressVal    = -2;                       // generic "bad address" value
1025 const long     badOopVal        = -1;                       // generic "bad oop" value
1026 const intptr_t badHeapOopVal    = (intptr_t) CONST64(0x2BAD4B0BBAADBABE); // value used to zap heap after GC
1027 const int      badHandleValue   = 0xBC;                     // value used to zap vm handle area
1028 const int      badResourceValue = 0xAB;                     // value used to zap resource area
1029 const int      freeBlockPad     = 0xBA;                     // value used to pad freed blocks.
1030 const int      uninitBlockPad   = 0xF1;                     // value used to zap newly malloc'd blocks.
1031 const juint    uninitMetaWordVal= 0xf7f7f7f7;               // value used to zap newly allocated metachunk
1032 const intptr_t badJNIHandleVal  = (intptr_t) UCONST64(0xFEFEFEFEFEFEFEFE); // value used to zap jni handle area
1033 const juint    badHeapWordVal   = 0xBAADBABE;               // value used to zap heap after GC
1034 const juint    badMetaWordVal   = 0xBAADFADE;               // value used to zap metadata heap after GC
1035 const int      badCodeHeapNewVal= 0xCC;                     // value used to zap Code heap at allocation
1036 const int      badCodeHeapFreeVal = 0xDD;                   // value used to zap Code heap at deallocation
1037 
1038 
1039 // (These must be implemented as #defines because C++ compilers are


1132   // If p = 0, overflow has occurred and i = 31 or i = 63 (depending on the machine word size).
1133   return i;
1134 }
1135 
1136 //* largest i such that 2^i <= x
1137 //  A negative value of 'x' will return '63'
1138 inline int log2_long(jlong x) {
1139   int i = -1;
1140   julong p =  1;
1141   while (p != 0 && p <= (julong)x) {
1142     // p = 2^(i+1) && p <= x (i.e., 2^(i+1) <= x)
1143     i++; p *= 2;
1144   }
1145   // p = 2^(i+1) && x < p (i.e., 2^i <= x < 2^(i+1))
1146   // (if p = 0 then overflow occurred and i = 63)
1147   return i;
1148 }
1149 
1150 //* the argument must be exactly a power of 2
1151 inline int exact_log2(intptr_t x) {
1152   #ifdef ASSERT
1153     if (!is_power_of_2(x)) basic_fatal("x must be a power of 2");
1154   #endif
1155   return log2_intptr(x);
1156 }
1157 
1158 //* the argument must be exactly a power of 2
1159 inline int exact_log2_long(jlong x) {
1160   #ifdef ASSERT
1161     if (!is_power_of_2_long(x)) basic_fatal("x must be a power of 2");
1162   #endif
1163   return log2_long(x);
1164 }
1165 
1166 
1167 // returns integer round-up to the nearest multiple of s (s must be a power of two)
1168 inline intptr_t round_to(intptr_t x, uintx s) {
1169   #ifdef ASSERT
1170     if (!is_power_of_2(s)) basic_fatal("s must be a power of 2");
1171   #endif
1172   const uintx m = s - 1;
1173   return mask_bits(x + m, ~m);
1174 }
1175 
1176 // returns integer round-down to the nearest multiple of s (s must be a power of two)
1177 inline intptr_t round_down(intptr_t x, uintx s) {
1178   #ifdef ASSERT
1179     if (!is_power_of_2(s)) basic_fatal("s must be a power of 2");
1180   #endif
1181   const uintx m = s - 1;
1182   return mask_bits(x, ~m);
1183 }
1184 
1185 
1186 inline bool is_odd (intx x) { return x & 1;      }
1187 inline bool is_even(intx x) { return !is_odd(x); }
1188 
1189 // "to" should be greater than "from."
1190 inline intx byte_size(void* from, void* to) {
1191   return (address)to - (address)from;
1192 }
1193 
1194 //----------------------------------------------------------------------------------------------------
1195 // Avoid non-portable casts with these routines (DEPRECATED)
1196 
1197 // NOTE: USE Bytes class INSTEAD WHERE POSSIBLE
1198 //       Bytes is optimized machine-specifically and may be much faster then the portable routines below.
1199 
1200 // Given sequence of four bytes, build into a 32-bit word


1311 
1312 inline int extract_high_short_from_int(jint x) {
1313   return (x >> 16) & 0xffff;
1314 }
1315 
1316 inline int build_int_from_shorts( jushort low, jushort high ) {
1317   return ((int)((unsigned int)high << 16) | (unsigned int)low);
1318 }
1319 
1320 // Convert pointer to intptr_t, for use in printing pointers.
1321 inline intptr_t p2i(const void * p) {
1322   return (intptr_t) p;
1323 }
1324 
1325 // swap a & b
1326 template<class T> static void swap(T& a, T& b) {
1327   T tmp = a;
1328   a = b;
1329   b = tmp;
1330 }
1331 
1332 // Printf-style formatters for fixed- and variable-width types as pointers and
1333 // integers.  These are derived from the definitions in inttypes.h.  If the platform
1334 // doesn't provide appropriate definitions, they should be provided in
1335 // the compiler-specific definitions file (e.g., globalDefinitions_gcc.hpp)
1336 
1337 #define BOOL_TO_STR(_b_) ((_b_) ? "true" : "false")
1338 
1339 // Format 32-bit quantities.
1340 #define INT32_FORMAT           "%" PRId32
1341 #define UINT32_FORMAT          "%" PRIu32
1342 #define INT32_FORMAT_W(width)  "%" #width PRId32
1343 #define UINT32_FORMAT_W(width) "%" #width PRIu32
1344 
1345 #define PTR32_FORMAT           "0x%08" PRIx32
1346 #define PTR32_FORMAT_W(width)  "0x%" #width PRIx32
1347 
1348 // Format 64-bit quantities.
1349 #define INT64_FORMAT           "%" PRId64
1350 #define UINT64_FORMAT          "%" PRIu64
1351 #define UINT64_FORMAT_X        "%" PRIx64
1352 #define INT64_FORMAT_W(width)  "%" #width PRId64
1353 #define UINT64_FORMAT_W(width) "%" #width PRIu64
1354 
1355 #define PTR64_FORMAT           "0x%016" PRIx64
1356 
1357 // Format jlong, if necessary
1358 #ifndef JLONG_FORMAT
1359 #define JLONG_FORMAT           INT64_FORMAT
1360 #endif
1361 #ifndef JULONG_FORMAT
1362 #define JULONG_FORMAT          UINT64_FORMAT
1363 #endif
1364 #ifndef JULONG_FORMAT_X
1365 #define JULONG_FORMAT_X        UINT64_FORMAT_X
1366 #endif
1367 
1368 // Format pointers which change size between 32- and 64-bit.
1369 #ifdef  _LP64
1370 #define INTPTR_FORMAT "0x%016" PRIxPTR
1371 #define PTR_FORMAT    "0x%016" PRIxPTR
1372 #else   // !_LP64
1373 #define INTPTR_FORMAT "0x%08"  PRIxPTR
1374 #define PTR_FORMAT    "0x%08"  PRIxPTR
1375 #endif  // _LP64
1376 
1377 #define INTPTR_FORMAT_W(width)   "%" #width PRIxPTR
1378 
1379 #define SSIZE_FORMAT             "%"   PRIdPTR
1380 #define SIZE_FORMAT              "%"   PRIuPTR
1381 #define SIZE_FORMAT_HEX          "0x%" PRIxPTR
1382 #define SSIZE_FORMAT_W(width)    "%"   #width PRIdPTR
1383 #define SIZE_FORMAT_W(width)     "%"   #width PRIuPTR
1384 #define SIZE_FORMAT_HEX_W(width) "0x%" #width PRIxPTR
1385 
1386 #define INTX_FORMAT           "%" PRIdPTR
1387 #define UINTX_FORMAT          "%" PRIuPTR
1388 #define INTX_FORMAT_W(width)  "%" #width PRIdPTR
1389 #define UINTX_FORMAT_W(width) "%" #width PRIuPTR
1390 
1391 
1392 #define ARRAY_SIZE(array) (sizeof(array)/sizeof((array)[0]))
1393 
1394 //----------------------------------------------------------------------------------------------------
1395 // Sum and product which can never overflow: they wrap, just like the
1396 // Java operations.  Note that we don't intend these to be used for
1397 // general-purpose arithmetic: their purpose is to emulate Java
1398 // operations.
1399 
1400 // The goal of this code to avoid undefined or implementation-defined
1401 // behavior.  The use of an lvalue to reference cast is explicitly
1402 // permitted by Lvalues and rvalues [basic.lval].  [Section 3.10 Para
1403 // 15 in C++03]
1404 #define JAVA_INTEGER_OP(OP, NAME, TYPE, UNSIGNED_TYPE)  \
1405 inline TYPE NAME (TYPE in1, TYPE in2) {                 \
1406   UNSIGNED_TYPE ures = static_cast<UNSIGNED_TYPE>(in1); \
1407   ures OP ## = static_cast<UNSIGNED_TYPE>(in2);         \
1408   return reinterpret_cast<TYPE&>(ures);                 \
1409 }
1410 


   8  *
   9  * This code is distributed in the hope that it will be useful, but WITHOUT
  10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  11  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  12  * version 2 for more details (a copy is included in the LICENSE file that
  13  * accompanied this code).
  14  *
  15  * You should have received a copy of the GNU General Public License version
  16  * 2 along with this work; if not, write to the Free Software Foundation,
  17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  18  *
  19  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  20  * or visit www.oracle.com if you need additional information or have any
  21  * questions.
  22  *
  23  */
  24 
  25 #ifndef SHARE_VM_UTILITIES_GLOBALDEFINITIONS_HPP
  26 #define SHARE_VM_UTILITIES_GLOBALDEFINITIONS_HPP
  27 
  28 #include "utilities/macros.hpp"
  29 #include "utilities/compilerWarnings.hpp"
  30 #include "utilities/debug.hpp"









  31 
  32 #include TARGET_COMPILER_HEADER(utilities/globalDefinitions)
  33 // Defaults for macros that might be defined per compiler.
  34 #ifndef NOINLINE
  35 #define NOINLINE
  36 #endif
  37 #ifndef ALWAYSINLINE
  38 #define ALWAYSINLINE inline
  39 #endif
  40 
  41 // This file holds all globally used constants & types, class (forward)
  42 // declarations and a few frequently used utility functions.
  43 
  44 //----------------------------------------------------------------------------------------------------
  45 // Printf-style formatters for fixed- and variable-width types as pointers and
  46 // integers.  These are derived from the definitions in inttypes.h.  If the platform
  47 // doesn't provide appropriate definitions, they should be provided in
  48 // the compiler-specific definitions file (e.g., globalDefinitions_gcc.hpp)
  49 
  50 #define BOOL_TO_STR(_b_) ((_b_) ? "true" : "false")
  51 
  52 // Format 32-bit quantities.
  53 #define INT32_FORMAT           "%" PRId32
  54 #define UINT32_FORMAT          "%" PRIu32
  55 #define INT32_FORMAT_W(width)  "%" #width PRId32
  56 #define UINT32_FORMAT_W(width) "%" #width PRIu32
  57 
  58 #define PTR32_FORMAT           "0x%08" PRIx32
  59 #define PTR32_FORMAT_W(width)  "0x%" #width PRIx32
  60 
  61 // Format 64-bit quantities.
  62 #define INT64_FORMAT           "%" PRId64
  63 #define UINT64_FORMAT          "%" PRIu64
  64 #define UINT64_FORMAT_X        "%" PRIx64
  65 #define INT64_FORMAT_W(width)  "%" #width PRId64
  66 #define UINT64_FORMAT_W(width) "%" #width PRIu64
  67 
  68 #define PTR64_FORMAT           "0x%016" PRIx64
  69 
  70 // Format jlong, if necessary
  71 #ifndef JLONG_FORMAT
  72 #define JLONG_FORMAT           INT64_FORMAT
  73 #endif
  74 #ifndef JULONG_FORMAT
  75 #define JULONG_FORMAT          UINT64_FORMAT
  76 #endif
  77 #ifndef JULONG_FORMAT_X
  78 #define JULONG_FORMAT_X        UINT64_FORMAT_X
  79 #endif
  80 
  81 // Format pointers which change size between 32- and 64-bit.
  82 #ifdef  _LP64
  83 #define INTPTR_FORMAT "0x%016" PRIxPTR
  84 #define PTR_FORMAT    "0x%016" PRIxPTR
  85 #else   // !_LP64
  86 #define INTPTR_FORMAT "0x%08"  PRIxPTR
  87 #define PTR_FORMAT    "0x%08"  PRIxPTR
  88 #endif  // _LP64
  89 
  90 #define INTPTR_FORMAT_W(width)   "%" #width PRIxPTR
  91 
  92 #define SSIZE_FORMAT             "%"   PRIdPTR
  93 #define SIZE_FORMAT              "%"   PRIuPTR
  94 #define SIZE_FORMAT_HEX          "0x%" PRIxPTR
  95 #define SSIZE_FORMAT_W(width)    "%"   #width PRIdPTR
  96 #define SIZE_FORMAT_W(width)     "%"   #width PRIuPTR
  97 #define SIZE_FORMAT_HEX_W(width) "0x%" #width PRIxPTR
  98 
  99 #define INTX_FORMAT           "%" PRIdPTR
 100 #define UINTX_FORMAT          "%" PRIuPTR
 101 #define INTX_FORMAT_W(width)  "%" #width PRIdPTR
 102 #define UINTX_FORMAT_W(width) "%" #width PRIuPTR
 103 
 104 //----------------------------------------------------------------------------------------------------
 105 // Constants
 106 
 107 const int LogBytesPerShort   = 1;
 108 const int LogBytesPerInt     = 2;
 109 #ifdef _LP64
 110 const int LogBytesPerWord    = 3;
 111 #else
 112 const int LogBytesPerWord    = 2;
 113 #endif
 114 const int LogBytesPerLong    = 3;
 115 
 116 const int BytesPerShort      = 1 << LogBytesPerShort;
 117 const int BytesPerInt        = 1 << LogBytesPerInt;
 118 const int BytesPerWord       = 1 << LogBytesPerWord;
 119 const int BytesPerLong       = 1 << LogBytesPerLong;
 120 
 121 const int LogBitsPerByte     = 3;
 122 const int LogBitsPerShort    = LogBitsPerByte + LogBytesPerShort;


 960 
 961 class CodeBlob;
 962 class  CompiledMethod;
 963 class   nmethod;
 964 class RuntimeBlob;
 965 class  OSRAdapter;
 966 class  I2CAdapter;
 967 class  C2IAdapter;
 968 class CompiledIC;
 969 class relocInfo;
 970 class ScopeDesc;
 971 class PcDesc;
 972 
 973 class Recompiler;
 974 class Recompilee;
 975 class RecompilationPolicy;
 976 class RFrame;
 977 class  CompiledRFrame;
 978 class  InterpretedRFrame;
 979 


 980 class vframe;
 981 class   javaVFrame;
 982 class     interpretedVFrame;
 983 class     compiledVFrame;
 984 class     deoptimizedVFrame;
 985 class   externalVFrame;
 986 class     entryVFrame;
 987 
 988 class RegisterMap;
 989 
 990 class Mutex;
 991 class Monitor;
 992 class BasicLock;
 993 class BasicObjectLock;
 994 
 995 class PeriodicTask;
 996 
 997 class JavaCallWrapper;
 998 
 999 class   oopDesc;


1020 
1021 class PrivilegedElement;
1022 class MonitorArray;
1023 
1024 class MonitorInfo;
1025 
1026 class OffsetClosure;
1027 class OopMapCache;
1028 class InterpreterOopMap;
1029 class OopMapCacheEntry;
1030 class OSThread;
1031 
1032 typedef int (*OSThreadStartFunc)(void*);
1033 
1034 class Space;
1035 
1036 class JavaValue;
1037 class methodHandle;
1038 class JavaCallArguments;
1039 
1040 // Basic support for errors.

1041 extern void basic_fatal(const char* msg);
1042 

1043 //----------------------------------------------------------------------------------------------------
1044 // Special constants for debugging
1045 
1046 const jint     badInt           = -3;                       // generic "bad int" value
1047 const long     badAddressVal    = -2;                       // generic "bad address" value
1048 const long     badOopVal        = -1;                       // generic "bad oop" value
1049 const intptr_t badHeapOopVal    = (intptr_t) CONST64(0x2BAD4B0BBAADBABE); // value used to zap heap after GC
1050 const int      badHandleValue   = 0xBC;                     // value used to zap vm handle area
1051 const int      badResourceValue = 0xAB;                     // value used to zap resource area
1052 const int      freeBlockPad     = 0xBA;                     // value used to pad freed blocks.
1053 const int      uninitBlockPad   = 0xF1;                     // value used to zap newly malloc'd blocks.
1054 const juint    uninitMetaWordVal= 0xf7f7f7f7;               // value used to zap newly allocated metachunk
1055 const intptr_t badJNIHandleVal  = (intptr_t) UCONST64(0xFEFEFEFEFEFEFEFE); // value used to zap jni handle area
1056 const juint    badHeapWordVal   = 0xBAADBABE;               // value used to zap heap after GC
1057 const juint    badMetaWordVal   = 0xBAADFADE;               // value used to zap metadata heap after GC
1058 const int      badCodeHeapNewVal= 0xCC;                     // value used to zap Code heap at allocation
1059 const int      badCodeHeapFreeVal = 0xDD;                   // value used to zap Code heap at deallocation
1060 
1061 
1062 // (These must be implemented as #defines because C++ compilers are


1155   // If p = 0, overflow has occurred and i = 31 or i = 63 (depending on the machine word size).
1156   return i;
1157 }
1158 
1159 //* largest i such that 2^i <= x
1160 //  A negative value of 'x' will return '63'
1161 inline int log2_long(jlong x) {
1162   int i = -1;
1163   julong p =  1;
1164   while (p != 0 && p <= (julong)x) {
1165     // p = 2^(i+1) && p <= x (i.e., 2^(i+1) <= x)
1166     i++; p *= 2;
1167   }
1168   // p = 2^(i+1) && x < p (i.e., 2^i <= x < 2^(i+1))
1169   // (if p = 0 then overflow occurred and i = 63)
1170   return i;
1171 }
1172 
1173 //* the argument must be exactly a power of 2
1174 inline int exact_log2(intptr_t x) {
1175   assert(is_power_of_2(x), "x must be a power of 2: " INTPTR_FORMAT, x);


1176   return log2_intptr(x);
1177 }
1178 
1179 //* the argument must be exactly a power of 2
1180 inline int exact_log2_long(jlong x) {
1181   assert(is_power_of_2_long(x), "x must be a power of 2: " JLONG_FORMAT, x);


1182   return log2_long(x);
1183 }
1184 
1185 
1186 // returns integer round-up to the nearest multiple of s (s must be a power of two)
1187 inline intptr_t round_to(intptr_t x, uintx s) {
1188   assert(is_power_of_2(s), "s must be a power of 2: " UINTX_FORMAT, s);


1189   const uintx m = s - 1;
1190   return mask_bits(x + m, ~m);
1191 }
1192 
1193 // returns integer round-down to the nearest multiple of s (s must be a power of two)
1194 inline intptr_t round_down(intptr_t x, uintx s) {
1195   assert(is_power_of_2(s), "s must be a power of 2: " UINTX_FORMAT, s);


1196   const uintx m = s - 1;
1197   return mask_bits(x, ~m);
1198 }
1199 
1200 
1201 inline bool is_odd (intx x) { return x & 1;      }
1202 inline bool is_even(intx x) { return !is_odd(x); }
1203 
1204 // "to" should be greater than "from."
1205 inline intx byte_size(void* from, void* to) {
1206   return (address)to - (address)from;
1207 }
1208 
1209 //----------------------------------------------------------------------------------------------------
1210 // Avoid non-portable casts with these routines (DEPRECATED)
1211 
1212 // NOTE: USE Bytes class INSTEAD WHERE POSSIBLE
1213 //       Bytes is optimized machine-specifically and may be much faster then the portable routines below.
1214 
1215 // Given sequence of four bytes, build into a 32-bit word


1326 
1327 inline int extract_high_short_from_int(jint x) {
1328   return (x >> 16) & 0xffff;
1329 }
1330 
1331 inline int build_int_from_shorts( jushort low, jushort high ) {
1332   return ((int)((unsigned int)high << 16) | (unsigned int)low);
1333 }
1334 
1335 // Convert pointer to intptr_t, for use in printing pointers.
1336 inline intptr_t p2i(const void * p) {
1337   return (intptr_t) p;
1338 }
1339 
1340 // swap a & b
1341 template<class T> static void swap(T& a, T& b) {
1342   T tmp = a;
1343   a = b;
1344   b = tmp;
1345 }




























































1346 
1347 #define ARRAY_SIZE(array) (sizeof(array)/sizeof((array)[0]))
1348 
1349 //----------------------------------------------------------------------------------------------------
1350 // Sum and product which can never overflow: they wrap, just like the
1351 // Java operations.  Note that we don't intend these to be used for
1352 // general-purpose arithmetic: their purpose is to emulate Java
1353 // operations.
1354 
1355 // The goal of this code to avoid undefined or implementation-defined
1356 // behavior.  The use of an lvalue to reference cast is explicitly
1357 // permitted by Lvalues and rvalues [basic.lval].  [Section 3.10 Para
1358 // 15 in C++03]
1359 #define JAVA_INTEGER_OP(OP, NAME, TYPE, UNSIGNED_TYPE)  \
1360 inline TYPE NAME (TYPE in1, TYPE in2) {                 \
1361   UNSIGNED_TYPE ures = static_cast<UNSIGNED_TYPE>(in1); \
1362   ures OP ## = static_cast<UNSIGNED_TYPE>(in2);         \
1363   return reinterpret_cast<TYPE&>(ures);                 \
1364 }
1365 
< prev index next >