Path: blob/aarch64-shenandoah-jdk8u272-b10/hotspot/src/share/vm/utilities/globalDefinitions.hpp
32285 views
/*1* Copyright (c) 1997, 2016, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation.7*8* This code is distributed in the hope that it will be useful, but WITHOUT9* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or10* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License11* version 2 for more details (a copy is included in the LICENSE file that12* accompanied this code).13*14* You should have received a copy of the GNU General Public License version15* 2 along with this work; if not, write to the Free Software Foundation,16* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.17*18* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA19* or visit www.oracle.com if you need additional information or have any20* questions.21*22*/2324#ifndef SHARE_VM_UTILITIES_GLOBALDEFINITIONS_HPP25#define SHARE_VM_UTILITIES_GLOBALDEFINITIONS_HPP2627#ifndef __STDC_FORMAT_MACROS28#define __STDC_FORMAT_MACROS29#endif3031#ifdef TARGET_COMPILER_gcc32# include "utilities/globalDefinitions_gcc.hpp"33#endif34#ifdef TARGET_COMPILER_visCPP35# include "utilities/globalDefinitions_visCPP.hpp"36#endif37#ifdef TARGET_COMPILER_sparcWorks38# include "utilities/globalDefinitions_sparcWorks.hpp"39#endif40#ifdef TARGET_COMPILER_xlc41# include "utilities/globalDefinitions_xlc.hpp"42#endif4344// Defaults for macros that might be defined per compiler.45#ifndef NOINLINE46#define NOINLINE47#endif48#ifndef ALWAYSINLINE49#define ALWAYSINLINE inline50#endif5152#ifndef PRAGMA_DIAG_PUSH53#define PRAGMA_DIAG_PUSH54#endif55#ifndef PRAGMA_DIAG_POP56#define PRAGMA_DIAG_POP57#endif58#ifndef PRAGMA_FORMAT_NONLITERAL_IGNORED59#define PRAGMA_FORMAT_NONLITERAL_IGNORED60#endif61#ifndef PRAGMA_FORMAT_IGNORED62#define PRAGMA_FORMAT_IGNORED63#endif64#ifndef PRAGMA_FORMAT_NONLITERAL_IGNORED_INTERNAL65#define PRAGMA_FORMAT_NONLITERAL_IGNORED_INTERNAL66#endif67#ifndef PRAGMA_FORMAT_NONLITERAL_IGNORED_EXTERNAL68#define PRAGMA_FORMAT_NONLITERAL_IGNORED_EXTERNAL69#endif70#ifndef PRAGMA_FORMAT_MUTE_WARNINGS_FOR_GCC71#define PRAGMA_FORMAT_MUTE_WARNINGS_FOR_GCC72#endif73#ifndef ATTRIBUTE_PRINTF74#define ATTRIBUTE_PRINTF(fmt, vargs)75#endif767778#include "utilities/macros.hpp"7980// This file holds all globally used constants & types, class (forward)81// declarations and a few frequently used utility functions.8283//----------------------------------------------------------------------------------------------------84// Constants8586const int LogBytesPerShort = 1;87const int LogBytesPerInt = 2;88#ifdef _LP6489const int LogBytesPerWord = 3;90#else91const int LogBytesPerWord = 2;92#endif93const int LogBytesPerLong = 3;9495const int BytesPerShort = 1 << LogBytesPerShort;96const int BytesPerInt = 1 << LogBytesPerInt;97const int BytesPerWord = 1 << LogBytesPerWord;98const int BytesPerLong = 1 << LogBytesPerLong;99100const int LogBitsPerByte = 3;101const int LogBitsPerShort = LogBitsPerByte + LogBytesPerShort;102const int LogBitsPerInt = LogBitsPerByte + LogBytesPerInt;103const int LogBitsPerWord = LogBitsPerByte + LogBytesPerWord;104const int LogBitsPerLong = LogBitsPerByte + LogBytesPerLong;105106const int BitsPerByte = 1 << LogBitsPerByte;107const int BitsPerShort = 1 << LogBitsPerShort;108const int BitsPerInt = 1 << LogBitsPerInt;109const int BitsPerWord = 1 << LogBitsPerWord;110const int BitsPerLong = 1 << LogBitsPerLong;111112const int WordAlignmentMask = (1 << LogBytesPerWord) - 1;113const int LongAlignmentMask = (1 << LogBytesPerLong) - 1;114115const int WordsPerLong = 2; // Number of stack entries for longs116117const int oopSize = sizeof(char*); // Full-width oop118extern int heapOopSize; // Oop within a java object119const int wordSize = sizeof(char*);120const int longSize = sizeof(jlong);121const int jintSize = sizeof(jint);122const int size_tSize = sizeof(size_t);123124const int BytesPerOop = BytesPerWord; // Full-width oop125126extern int LogBytesPerHeapOop; // Oop within a java object127extern int LogBitsPerHeapOop;128extern int BytesPerHeapOop;129extern int BitsPerHeapOop;130131// Oop encoding heap max132extern uint64_t OopEncodingHeapMax;133134const int BitsPerJavaInteger = 32;135const int BitsPerJavaLong = 64;136const int BitsPerSize_t = size_tSize * BitsPerByte;137138// Size of a char[] needed to represent a jint as a string in decimal.139const int jintAsStringSize = 12;140141// In fact this should be142// log2_intptr(sizeof(class JavaThread)) - log2_intptr(64);143// see os::set_memory_serialize_page()144#ifdef _LP64145const int SerializePageShiftCount = 4;146#else147#if INCLUDE_JFR && INCLUDE_ALL_GCS148// JavaThread already has quite a few Shenandoah fields. Adding many JFR fields149// trips sizeof(JavaThread) > 1024. Need to adjust it here.150const int SerializePageShiftCount = 4;151#else152const int SerializePageShiftCount = 3;153#endif154#endif155156// An opaque struct of heap-word width, so that HeapWord* can be a generic157// pointer into the heap. We require that object sizes be measured in158// units of heap words, so that that159// HeapWord* hw;160// hw += oop(hw)->foo();161// works, where foo is a method (like size or scavenge) that returns the162// object size.163class HeapWord {164friend class VMStructs;165private:166char* i;167#ifndef PRODUCT168public:169char* value() { return i; }170#endif171};172173// Analogous opaque struct for metadata allocated from174// metaspaces.175class MetaWord {176friend class VMStructs;177private:178char* i;179};180181// HeapWordSize must be 2^LogHeapWordSize.182const int HeapWordSize = sizeof(HeapWord);183#ifdef _LP64184const int LogHeapWordSize = 3;185#else186const int LogHeapWordSize = 2;187#endif188const int HeapWordsPerLong = BytesPerLong / HeapWordSize;189const int LogHeapWordsPerLong = LogBytesPerLong - LogHeapWordSize;190191// The larger HeapWordSize for 64bit requires larger heaps192// for the same application running in 64bit. See bug 4967770.193// The minimum alignment to a heap word size is done. Other194// parts of the memory system may required additional alignment195// and are responsible for those alignments.196#ifdef _LP64197#define ScaleForWordSize(x) align_size_down_((x) * 13 / 10, HeapWordSize)198#else199#define ScaleForWordSize(x) (x)200#endif201202// The minimum number of native machine words necessary to contain "byte_size"203// bytes.204inline size_t heap_word_size(size_t byte_size) {205return (byte_size + (HeapWordSize-1)) >> LogHeapWordSize;206}207208209const size_t K = 1024;210const size_t M = K*K;211const size_t G = M*K;212const size_t HWperKB = K / sizeof(HeapWord);213214const jint min_jint = (jint)1 << (sizeof(jint)*BitsPerByte-1); // 0x80000000 == smallest jint215const jint max_jint = (juint)min_jint - 1; // 0x7FFFFFFF == largest jint216217// Constants for converting from a base unit to milli-base units. For218// example from seconds to milliseconds and microseconds219220const int MILLIUNITS = 1000; // milli units per base unit221const int MICROUNITS = 1000000; // micro units per base unit222const int NANOUNITS = 1000000000; // nano units per base unit223224const jlong NANOSECS_PER_SEC = CONST64(1000000000);225const jint NANOSECS_PER_MILLISEC = 1000000;226227// Proper units routines try to maintain at least three significant digits.228// In worst case, it would print five significant digits with lower prefix.229// G is close to MAX_SIZE on 32-bit platforms, so its product can easily overflow,230// and therefore we need to be careful.231232inline const char* proper_unit_for_byte_size(size_t s) {233#ifdef _LP64234if (s >= 100*G) {235return "G";236}237#endif238if (s >= 100*M) {239return "M";240} else if (s >= 100*K) {241return "K";242} else {243return "B";244}245}246247template <class T>248inline T byte_size_in_proper_unit(T s) {249#ifdef _LP64250if (s >= 100*G) {251return (T)(s/G);252}253#endif254if (s >= 100*M) {255return (T)(s/M);256} else if (s >= 100*K) {257return (T)(s/K);258} else {259return s;260}261}262263//----------------------------------------------------------------------------------------------------264// VM type definitions265266// intx and uintx are the 'extended' int and 'extended' unsigned int types;267// they are 32bit wide on a 32-bit platform, and 64bit wide on a 64bit platform.268269typedef intptr_t intx;270typedef uintptr_t uintx;271272const intx min_intx = (intx)1 << (sizeof(intx)*BitsPerByte-1);273const intx max_intx = (uintx)min_intx - 1;274const uintx max_uintx = (uintx)-1;275276// Table of values:277// sizeof intx 4 8278// min_intx 0x80000000 0x8000000000000000279// max_intx 0x7FFFFFFF 0x7FFFFFFFFFFFFFFF280// max_uintx 0xFFFFFFFF 0xFFFFFFFFFFFFFFFF281282typedef unsigned int uint; NEEDS_CLEANUP283284285//----------------------------------------------------------------------------------------------------286// Java type definitions287288// All kinds of 'plain' byte addresses289typedef signed char s_char;290typedef unsigned char u_char;291typedef u_char* address;292typedef uintptr_t address_word; // unsigned integer which will hold a pointer293// except for some implementations of a C++294// linkage pointer to function. Should never295// need one of those to be placed in this296// type anyway.297298// Utility functions to "portably" (?) bit twiddle pointers299// Where portable means keep ANSI C++ compilers quiet300301inline address set_address_bits(address x, int m) { return address(intptr_t(x) | m); }302inline address clear_address_bits(address x, int m) { return address(intptr_t(x) & ~m); }303304// Utility functions to "portably" make cast to/from function pointers.305306inline address_word mask_address_bits(address x, int m) { return address_word(x) & m; }307inline address_word castable_address(address x) { return address_word(x) ; }308inline address_word castable_address(void* x) { return address_word(x) ; }309310// Pointer subtraction.311// The idea here is to avoid ptrdiff_t, which is signed and so doesn't have312// the range we might need to find differences from one end of the heap313// to the other.314// A typical use might be:315// if (pointer_delta(end(), top()) >= size) {316// // enough room for an object of size317// ...318// and then additions like319// ... top() + size ...320// are safe because we know that top() is at least size below end().321inline size_t pointer_delta(const void* left,322const void* right,323size_t element_size) {324return (((uintptr_t) left) - ((uintptr_t) right)) / element_size;325}326// A version specialized for HeapWord*'s.327inline size_t pointer_delta(const HeapWord* left, const HeapWord* right) {328return pointer_delta(left, right, sizeof(HeapWord));329}330// A version specialized for MetaWord*'s.331inline size_t pointer_delta(const MetaWord* left, const MetaWord* right) {332return pointer_delta(left, right, sizeof(MetaWord));333}334335//336// ANSI C++ does not allow casting from one pointer type to a function pointer337// directly without at best a warning. This macro accomplishes it silently338// In every case that is present at this point the value be cast is a pointer339// to a C linkage function. In somecase the type used for the cast reflects340// that linkage and a picky compiler would not complain. In other cases because341// there is no convenient place to place a typedef with extern C linkage (i.e342// a platform dependent header file) it doesn't. At this point no compiler seems343// picky enough to catch these instances (which are few). It is possible that344// using templates could fix these for all cases. This use of templates is likely345// so far from the middle of the road that it is likely to be problematic in346// many C++ compilers.347//348#define CAST_TO_FN_PTR(func_type, value) (reinterpret_cast<func_type>(value))349#define CAST_FROM_FN_PTR(new_type, func_ptr) ((new_type)((address_word)(func_ptr)))350351// Unsigned byte types for os and stream.hpp352353// Unsigned one, two, four and eigth byte quantities used for describing354// the .class file format. See JVM book chapter 4.355356typedef jubyte u1;357typedef jushort u2;358typedef juint u4;359typedef julong u8;360361const jubyte max_jubyte = (jubyte)-1; // 0xFF largest jubyte362const jushort max_jushort = (jushort)-1; // 0xFFFF largest jushort363const juint max_juint = (juint)-1; // 0xFFFFFFFF largest juint364const julong max_julong = (julong)-1; // 0xFF....FF largest julong365366typedef jbyte s1;367typedef jshort s2;368typedef jint s4;369typedef jlong s8;370371//----------------------------------------------------------------------------------------------------372// JVM spec restrictions373374const int max_method_code_size = 64*K - 1; // JVM spec, 2nd ed. section 4.8.1 (p.134)375376// Default ProtectionDomainCacheSize values377378const int defaultProtectionDomainCacheSize = NOT_LP64(137) LP64_ONLY(2017);379380//----------------------------------------------------------------------------------------------------381// Default and minimum StringTableSize values382383const int defaultStringTableSize = NOT_LP64(1009) LP64_ONLY(60013);384const int minimumStringTableSize = 1009;385386const int defaultSymbolTableSize = 20011;387const int minimumSymbolTableSize = 1009;388389390//----------------------------------------------------------------------------------------------------391// HotSwap - for JVMTI aka Class File Replacement and PopFrame392//393// Determines whether on-the-fly class replacement and frame popping are enabled.394395#define HOTSWAP396397//----------------------------------------------------------------------------------------------------398// Object alignment, in units of HeapWords.399//400// Minimum is max(BytesPerLong, BytesPerDouble, BytesPerOop) / HeapWordSize, so jlong, jdouble and401// reference fields can be naturally aligned.402403extern int MinObjAlignment;404extern int MinObjAlignmentInBytes;405extern int MinObjAlignmentInBytesMask;406407extern int LogMinObjAlignment;408extern int LogMinObjAlignmentInBytes;409410const int LogKlassAlignmentInBytes = 3;411const int LogKlassAlignment = LogKlassAlignmentInBytes - LogHeapWordSize;412const int KlassAlignmentInBytes = 1 << LogKlassAlignmentInBytes;413const int KlassAlignment = KlassAlignmentInBytes / HeapWordSize;414415// Klass encoding metaspace max size416const uint64_t KlassEncodingMetaspaceMax = (uint64_t(max_juint) + 1) << LogKlassAlignmentInBytes;417418// Machine dependent stuff419420#if defined(X86) && defined(COMPILER2) && !defined(JAVASE_EMBEDDED)421// Include Restricted Transactional Memory lock eliding optimization422#define INCLUDE_RTM_OPT 1423#define RTM_OPT_ONLY(code) code424#else425#define INCLUDE_RTM_OPT 0426#define RTM_OPT_ONLY(code)427#endif428// States of Restricted Transactional Memory usage.429enum RTMState {430NoRTM = 0x2, // Don't use RTM431UseRTM = 0x1, // Use RTM432ProfileRTM = 0x0 // Use RTM with abort ratio calculation433};434435// The maximum size of the code cache. Can be overridden by targets.436#define CODE_CACHE_SIZE_LIMIT (2*G)437// Allow targets to reduce the default size of the code cache.438#define CODE_CACHE_DEFAULT_LIMIT CODE_CACHE_SIZE_LIMIT439440#ifdef TARGET_ARCH_x86441# include "globalDefinitions_x86.hpp"442#endif443#ifdef TARGET_ARCH_aarch32444# include "globalDefinitions_aarch32.hpp"445#endif446#ifdef TARGET_ARCH_aarch64447# include "globalDefinitions_aarch64.hpp"448#endif449#ifdef TARGET_ARCH_sparc450# include "globalDefinitions_sparc.hpp"451#endif452#ifdef TARGET_ARCH_zero453# include "globalDefinitions_zero.hpp"454#endif455#ifdef TARGET_ARCH_arm456# include "globalDefinitions_arm.hpp"457#endif458#ifdef TARGET_ARCH_ppc459# include "globalDefinitions_ppc.hpp"460#endif461462/*463* If a platform does not support native stack walking464* the platform specific globalDefinitions (above)465* can set PLATFORM_NATIVE_STACK_WALKING_SUPPORTED to 0466*/467#ifndef PLATFORM_NATIVE_STACK_WALKING_SUPPORTED468#define PLATFORM_NATIVE_STACK_WALKING_SUPPORTED 1469#endif470471// To assure the IRIW property on processors that are not multiple copy472// atomic, sync instructions must be issued between volatile reads to473// assure their ordering, instead of after volatile stores.474// (See "A Tutorial Introduction to the ARM and POWER Relaxed Memory Models"475// by Luc Maranget, Susmit Sarkar and Peter Sewell, INRIA/Cambridge)476#ifdef CPU_NOT_MULTIPLE_COPY_ATOMIC477const bool support_IRIW_for_not_multiple_copy_atomic_cpu = true;478#else479const bool support_IRIW_for_not_multiple_copy_atomic_cpu = false;480#endif481482// The byte alignment to be used by Arena::Amalloc. See bugid 4169348.483// Note: this value must be a power of 2484485#define ARENA_AMALLOC_ALIGNMENT (2*BytesPerWord)486487// Signed variants of alignment helpers. There are two versions of each, a macro488// for use in places like enum definitions that require compile-time constant489// expressions and a function for all other places so as to get type checking.490491#define align_size_up_(size, alignment) (((size) + ((alignment) - 1)) & ~((alignment) - 1))492493inline bool is_size_aligned(size_t size, size_t alignment) {494return align_size_up_(size, alignment) == size;495}496497inline bool is_ptr_aligned(void* ptr, size_t alignment) {498return align_size_up_((intptr_t)ptr, (intptr_t)alignment) == (intptr_t)ptr;499}500501inline intptr_t align_size_up(intptr_t size, intptr_t alignment) {502return align_size_up_(size, alignment);503}504505#define align_size_down_(size, alignment) ((size) & ~((alignment) - 1))506507inline intptr_t align_size_down(intptr_t size, intptr_t alignment) {508return align_size_down_(size, alignment);509}510511#define is_size_aligned_(size, alignment) ((size) == (align_size_up_(size, alignment)))512513inline void* align_ptr_up(void* ptr, size_t alignment) {514return (void*)align_size_up((intptr_t)ptr, (intptr_t)alignment);515}516517inline void* align_ptr_down(void* ptr, size_t alignment) {518return (void*)align_size_down((intptr_t)ptr, (intptr_t)alignment);519}520521// Align objects by rounding up their size, in HeapWord units.522523#define align_object_size_(size) align_size_up_(size, MinObjAlignment)524525inline intptr_t align_object_size(intptr_t size) {526return align_size_up(size, MinObjAlignment);527}528529inline bool is_object_aligned(intptr_t addr) {530return addr == align_object_size(addr);531}532533// Pad out certain offsets to jlong alignment, in HeapWord units.534535inline intptr_t align_object_offset(intptr_t offset) {536return align_size_up(offset, HeapWordsPerLong);537}538539inline void* align_pointer_up(const void* addr, size_t size) {540return (void*) align_size_up_((uintptr_t)addr, size);541}542543// Align down with a lower bound. If the aligning results in 0, return 'alignment'.544545inline size_t align_size_down_bounded(size_t size, size_t alignment) {546size_t aligned_size = align_size_down_(size, alignment);547return aligned_size > 0 ? aligned_size : alignment;548}549550// Clamp an address to be within a specific page551// 1. If addr is on the page it is returned as is552// 2. If addr is above the page_address the start of the *next* page will be returned553// 3. Otherwise, if addr is below the page_address the start of the page will be returned554inline address clamp_address_in_page(address addr, address page_address, intptr_t page_size) {555if (align_size_down(intptr_t(addr), page_size) == align_size_down(intptr_t(page_address), page_size)) {556// address is in the specified page, just return it as is557return addr;558} else if (addr > page_address) {559// address is above specified page, return start of next page560return (address)align_size_down(intptr_t(page_address), page_size) + page_size;561} else {562// address is below specified page, return start of page563return (address)align_size_down(intptr_t(page_address), page_size);564}565}566567568// The expected size in bytes of a cache line, used to pad data structures.569#define DEFAULT_CACHE_LINE_SIZE 64570571572//----------------------------------------------------------------------------------------------------573// Utility macros for compilers574// used to silence compiler warnings575576#define Unused_Variable(var) var577578579//----------------------------------------------------------------------------------------------------580// Miscellaneous581582// 6302670 Eliminate Hotspot __fabsf dependency583// All fabs() callers should call this function instead, which will implicitly584// convert the operand to double, avoiding a dependency on __fabsf which585// doesn't exist in early versions of Solaris 8.586inline double fabsd(double value) {587return fabs(value);588}589590//----------------------------------------------------------------------------------------------------591// Special casts592// Cast floats into same-size integers and vice-versa w/o changing bit-pattern593typedef union {594jfloat f;595jint i;596} FloatIntConv;597598typedef union {599jdouble d;600jlong l;601julong ul;602} DoubleLongConv;603604inline jint jint_cast (jfloat x) { return ((FloatIntConv*)&x)->i; }605inline jfloat jfloat_cast (jint x) { return ((FloatIntConv*)&x)->f; }606607inline jlong jlong_cast (jdouble x) { return ((DoubleLongConv*)&x)->l; }608inline julong julong_cast (jdouble x) { return ((DoubleLongConv*)&x)->ul; }609inline jdouble jdouble_cast (jlong x) { return ((DoubleLongConv*)&x)->d; }610611inline jint low (jlong value) { return jint(value); }612inline jint high(jlong value) { return jint(value >> 32); }613614// the fancy casts are a hopefully portable way615// to do unsigned 32 to 64 bit type conversion616inline void set_low (jlong* value, jint low ) { *value &= (jlong)0xffffffff << 32;617*value |= (jlong)(julong)(juint)low; }618619inline void set_high(jlong* value, jint high) { *value &= (jlong)(julong)(juint)0xffffffff;620*value |= (jlong)high << 32; }621622inline jlong jlong_from(jint h, jint l) {623jlong result = 0; // initialization to avoid warning624set_high(&result, h);625set_low(&result, l);626return result;627}628629union jlong_accessor {630jint words[2];631jlong long_value;632};633634void basic_types_init(); // cannot define here; uses assert635636637// NOTE: replicated in SA in vm/agent/sun/jvm/hotspot/runtime/BasicType.java638enum BasicType {639T_BOOLEAN = 4,640T_CHAR = 5,641T_FLOAT = 6,642T_DOUBLE = 7,643T_BYTE = 8,644T_SHORT = 9,645T_INT = 10,646T_LONG = 11,647T_OBJECT = 12,648T_ARRAY = 13,649T_VOID = 14,650T_ADDRESS = 15,651T_NARROWOOP = 16,652T_METADATA = 17,653T_NARROWKLASS = 18,654T_CONFLICT = 19, // for stack value type with conflicting contents655T_ILLEGAL = 99656};657658inline bool is_java_primitive(BasicType t) {659return T_BOOLEAN <= t && t <= T_LONG;660}661662inline bool is_subword_type(BasicType t) {663// these guys are processed exactly like T_INT in calling sequences:664return (t == T_BOOLEAN || t == T_CHAR || t == T_BYTE || t == T_SHORT);665}666667inline bool is_signed_subword_type(BasicType t) {668return (t == T_BYTE || t == T_SHORT);669}670671inline bool is_reference_type(BasicType t) {672return (t == T_OBJECT || t == T_ARRAY);673}674675// Convert a char from a classfile signature to a BasicType676inline BasicType char2type(char c) {677switch( c ) {678case 'B': return T_BYTE;679case 'C': return T_CHAR;680case 'D': return T_DOUBLE;681case 'F': return T_FLOAT;682case 'I': return T_INT;683case 'J': return T_LONG;684case 'S': return T_SHORT;685case 'Z': return T_BOOLEAN;686case 'V': return T_VOID;687case 'L': return T_OBJECT;688case '[': return T_ARRAY;689}690return T_ILLEGAL;691}692693extern char type2char_tab[T_CONFLICT+1]; // Map a BasicType to a jchar694inline char type2char(BasicType t) { return (uint)t < T_CONFLICT+1 ? type2char_tab[t] : 0; }695extern int type2size[T_CONFLICT+1]; // Map BasicType to result stack elements696extern const char* type2name_tab[T_CONFLICT+1]; // Map a BasicType to a jchar697inline const char* type2name(BasicType t) { return (uint)t < T_CONFLICT+1 ? type2name_tab[t] : NULL; }698extern BasicType name2type(const char* name);699700// Auxilary math routines701// least common multiple702extern size_t lcm(size_t a, size_t b);703704705// NOTE: replicated in SA in vm/agent/sun/jvm/hotspot/runtime/BasicType.java706enum BasicTypeSize {707T_BOOLEAN_size = 1,708T_CHAR_size = 1,709T_FLOAT_size = 1,710T_DOUBLE_size = 2,711T_BYTE_size = 1,712T_SHORT_size = 1,713T_INT_size = 1,714T_LONG_size = 2,715T_OBJECT_size = 1,716T_ARRAY_size = 1,717T_NARROWOOP_size = 1,718T_NARROWKLASS_size = 1,719T_VOID_size = 0720};721722723// maps a BasicType to its instance field storage type:724// all sub-word integral types are widened to T_INT725extern BasicType type2field[T_CONFLICT+1];726extern BasicType type2wfield[T_CONFLICT+1];727728729// size in bytes730enum ArrayElementSize {731T_BOOLEAN_aelem_bytes = 1,732T_CHAR_aelem_bytes = 2,733T_FLOAT_aelem_bytes = 4,734T_DOUBLE_aelem_bytes = 8,735T_BYTE_aelem_bytes = 1,736T_SHORT_aelem_bytes = 2,737T_INT_aelem_bytes = 4,738T_LONG_aelem_bytes = 8,739#ifdef _LP64740T_OBJECT_aelem_bytes = 8,741T_ARRAY_aelem_bytes = 8,742#else743T_OBJECT_aelem_bytes = 4,744T_ARRAY_aelem_bytes = 4,745#endif746T_NARROWOOP_aelem_bytes = 4,747T_NARROWKLASS_aelem_bytes = 4,748T_VOID_aelem_bytes = 0749};750751extern int _type2aelembytes[T_CONFLICT+1]; // maps a BasicType to nof bytes used by its array element752#ifdef ASSERT753extern int type2aelembytes(BasicType t, bool allow_address = false); // asserts754#else755inline int type2aelembytes(BasicType t, bool allow_address = false) { return _type2aelembytes[t]; }756#endif757758759// JavaValue serves as a container for arbitrary Java values.760761class JavaValue {762763public:764typedef union JavaCallValue {765jfloat f;766jdouble d;767jint i;768jlong l;769jobject h;770} JavaCallValue;771772private:773BasicType _type;774JavaCallValue _value;775776public:777JavaValue(BasicType t = T_ILLEGAL) { _type = t; }778779JavaValue(jfloat value) {780_type = T_FLOAT;781_value.f = value;782}783784JavaValue(jdouble value) {785_type = T_DOUBLE;786_value.d = value;787}788789jfloat get_jfloat() const { return _value.f; }790jdouble get_jdouble() const { return _value.d; }791jint get_jint() const { return _value.i; }792jlong get_jlong() const { return _value.l; }793jobject get_jobject() const { return _value.h; }794JavaCallValue* get_value_addr() { return &_value; }795BasicType get_type() const { return _type; }796797void set_jfloat(jfloat f) { _value.f = f;}798void set_jdouble(jdouble d) { _value.d = d;}799void set_jint(jint i) { _value.i = i;}800void set_jlong(jlong l) { _value.l = l;}801void set_jobject(jobject h) { _value.h = h;}802void set_type(BasicType t) { _type = t; }803804jboolean get_jboolean() const { return (jboolean) (_value.i);}805jbyte get_jbyte() const { return (jbyte) (_value.i);}806jchar get_jchar() const { return (jchar) (_value.i);}807jshort get_jshort() const { return (jshort) (_value.i);}808809};810811812#define STACK_BIAS 0813// V9 Sparc CPU's running in 64 Bit mode use a stack bias of 7ff814// in order to extend the reach of the stack pointer.815#if defined(SPARC) && defined(_LP64)816#undef STACK_BIAS817#define STACK_BIAS 0x7ff818#endif819820821// TosState describes the top-of-stack state before and after the execution of822// a bytecode or method. The top-of-stack value may be cached in one or more CPU823// registers. The TosState corresponds to the 'machine represention' of this cached824// value. There's 4 states corresponding to the JAVA types int, long, float & double825// as well as a 5th state in case the top-of-stack value is actually on the top826// of stack (in memory) and thus not cached. The atos state corresponds to the itos827// state when it comes to machine representation but is used separately for (oop)828// type specific operations (e.g. verification code).829830enum TosState { // describes the tos cache contents831btos = 0, // byte, bool tos cached832ztos = 1, // byte, bool tos cached833ctos = 2, // char tos cached834stos = 3, // short tos cached835itos = 4, // int tos cached836ltos = 5, // long tos cached837ftos = 6, // float tos cached838dtos = 7, // double tos cached839atos = 8, // object cached840vtos = 9, // tos not cached841number_of_states,842ilgl // illegal state: should not occur843};844845846inline TosState as_TosState(BasicType type) {847switch (type) {848case T_BYTE : return btos;849case T_BOOLEAN: return ztos;850case T_CHAR : return ctos;851case T_SHORT : return stos;852case T_INT : return itos;853case T_LONG : return ltos;854case T_FLOAT : return ftos;855case T_DOUBLE : return dtos;856case T_VOID : return vtos;857case T_ARRAY : // fall through858case T_OBJECT : return atos;859}860return ilgl;861}862863inline BasicType as_BasicType(TosState state) {864switch (state) {865case btos : return T_BYTE;866case ztos : return T_BOOLEAN;867case ctos : return T_CHAR;868case stos : return T_SHORT;869case itos : return T_INT;870case ltos : return T_LONG;871case ftos : return T_FLOAT;872case dtos : return T_DOUBLE;873case atos : return T_OBJECT;874case vtos : return T_VOID;875}876return T_ILLEGAL;877}878879880// Helper function to convert BasicType info into TosState881// Note: Cannot define here as it uses global constant at the time being.882TosState as_TosState(BasicType type);883884885// JavaThreadState keeps track of which part of the code a thread is executing in. This886// information is needed by the safepoint code.887//888// There are 4 essential states:889//890// _thread_new : Just started, but not executed init. code yet (most likely still in OS init code)891// _thread_in_native : In native code. This is a safepoint region, since all oops will be in jobject handles892// _thread_in_vm : Executing in the vm893// _thread_in_Java : Executing either interpreted or compiled Java code (or could be in a stub)894//895// Each state has an associated xxxx_trans state, which is an intermediate state used when a thread is in896// a transition from one state to another. These extra states makes it possible for the safepoint code to897// handle certain thread_states without having to suspend the thread - making the safepoint code faster.898//899// Given a state, the xxx_trans state can always be found by adding 1.900//901enum JavaThreadState {902_thread_uninitialized = 0, // should never happen (missing initialization)903_thread_new = 2, // just starting up, i.e., in process of being initialized904_thread_new_trans = 3, // corresponding transition state (not used, included for completness)905_thread_in_native = 4, // running in native code906_thread_in_native_trans = 5, // corresponding transition state907_thread_in_vm = 6, // running in VM908_thread_in_vm_trans = 7, // corresponding transition state909_thread_in_Java = 8, // running in Java or in stub code910_thread_in_Java_trans = 9, // corresponding transition state (not used, included for completness)911_thread_blocked = 10, // blocked in vm912_thread_blocked_trans = 11, // corresponding transition state913_thread_max_state = 12 // maximum thread state+1 - used for statistics allocation914};915916917// Handy constants for deciding which compiler mode to use.918enum MethodCompilation {919InvocationEntryBci = -1, // i.e., not a on-stack replacement compilation920InvalidOSREntryBci = -2921};922923// Enumeration to distinguish tiers of compilation924enum CompLevel {925CompLevel_any = -1,926CompLevel_all = -1,927CompLevel_none = 0, // Interpreter928CompLevel_simple = 1, // C1929CompLevel_limited_profile = 2, // C1, invocation & backedge counters930CompLevel_full_profile = 3, // C1, invocation & backedge counters + mdo931CompLevel_full_optimization = 4, // C2 or Shark932933#if defined(COMPILER2) || defined(SHARK)934CompLevel_highest_tier = CompLevel_full_optimization, // pure C2 and tiered935#elif defined(COMPILER1)936CompLevel_highest_tier = CompLevel_simple, // pure C1937#else938CompLevel_highest_tier = CompLevel_none,939#endif940941#if defined(TIERED)942CompLevel_initial_compile = CompLevel_full_profile // tiered943#elif defined(COMPILER1)944CompLevel_initial_compile = CompLevel_simple // pure C1945#elif defined(COMPILER2) || defined(SHARK)946CompLevel_initial_compile = CompLevel_full_optimization // pure C2947#else948CompLevel_initial_compile = CompLevel_none949#endif950};951952inline bool is_c1_compile(int comp_level) {953return comp_level > CompLevel_none && comp_level < CompLevel_full_optimization;954}955956inline bool is_c2_compile(int comp_level) {957return comp_level == CompLevel_full_optimization;958}959960inline bool is_highest_tier_compile(int comp_level) {961return comp_level == CompLevel_highest_tier;962}963964inline bool is_compile(int comp_level) {965return is_c1_compile(comp_level) || is_c2_compile(comp_level);966}967968//----------------------------------------------------------------------------------------------------969// 'Forward' declarations of frequently used classes970// (in order to reduce interface dependencies & reduce971// number of unnecessary compilations after changes)972973class symbolTable;974class ClassFileStream;975976class Event;977978class Thread;979class VMThread;980class JavaThread;981class Threads;982983class VM_Operation;984class VMOperationQueue;985986class CodeBlob;987class nmethod;988class OSRAdapter;989class I2CAdapter;990class C2IAdapter;991class CompiledIC;992class relocInfo;993class ScopeDesc;994class PcDesc;995996class Recompiler;997class Recompilee;998class RecompilationPolicy;999class RFrame;1000class CompiledRFrame;1001class InterpretedRFrame;10021003class frame;10041005class vframe;1006class javaVFrame;1007class interpretedVFrame;1008class compiledVFrame;1009class deoptimizedVFrame;1010class externalVFrame;1011class entryVFrame;10121013class RegisterMap;10141015class Mutex;1016class Monitor;1017class BasicLock;1018class BasicObjectLock;10191020class PeriodicTask;10211022class JavaCallWrapper;10231024class oopDesc;1025class metaDataOopDesc;10261027class NativeCall;10281029class zone;10301031class StubQueue;10321033class outputStream;10341035class ResourceArea;10361037class DebugInformationRecorder;1038class ScopeValue;1039class CompressedStream;1040class DebugInfoReadStream;1041class DebugInfoWriteStream;1042class LocationValue;1043class ConstantValue;1044class IllegalValue;10451046class PrivilegedElement;1047class MonitorArray;10481049class MonitorInfo;10501051class OffsetClosure;1052class OopMapCache;1053class InterpreterOopMap;1054class OopMapCacheEntry;1055class OSThread;10561057typedef int (*OSThreadStartFunc)(void*);10581059class Space;10601061class JavaValue;1062class methodHandle;1063class JavaCallArguments;10641065// Basic support for errors (general debug facilities not defined at this point fo the include phase)10661067extern void basic_fatal(const char* msg);106810691070//----------------------------------------------------------------------------------------------------1071// Special constants for debugging10721073const jint badInt = -3; // generic "bad int" value1074const intptr_t badAddressVal = -2; // generic "bad address" value1075const intptr_t badOopVal = -1; // generic "bad oop" value1076const intptr_t badHeapOopVal = (intptr_t) CONST64(0x2BAD4B0BBAADBABE); // value used to zap heap after GC1077const int badStackSegVal = 0xCA; // value used to zap stack segments1078const int badHandleValue = 0xBC; // value used to zap vm handle area1079const int badResourceValue = 0xAB; // value used to zap resource area1080const int freeBlockPad = 0xBA; // value used to pad freed blocks.1081const int uninitBlockPad = 0xF1; // value used to zap newly malloc'd blocks.1082const intptr_t badJNIHandleVal = (intptr_t) CONST64(0xFEFEFEFEFEFEFEFE); // value used to zap jni handle area1083const juint badHeapWordVal = 0xBAADBABE; // value used to zap heap after GC1084const juint badMetaWordVal = 0xBAADFADE; // value used to zap metadata heap after GC1085const int badCodeHeapNewVal= 0xCC; // value used to zap Code heap at allocation1086const int badCodeHeapFreeVal = 0xDD; // value used to zap Code heap at deallocation108710881089// (These must be implemented as #defines because C++ compilers are1090// not obligated to inline non-integral constants!)1091#define badAddress ((address)::badAddressVal)1092#define badOop (cast_to_oop(::badOopVal))1093#define badHeapWord (::badHeapWordVal)1094#define badJNIHandle (cast_to_oop(::badJNIHandleVal))10951096// Default TaskQueue size is 16K (32-bit) or 128K (64-bit)1097#define TASKQUEUE_SIZE (NOT_LP64(1<<14) LP64_ONLY(1<<17))10981099//----------------------------------------------------------------------------------------------------1100// Utility functions for bitfield manipulations11011102const intptr_t AllBits = ~0; // all bits set in a word1103const intptr_t NoBits = 0; // no bits set in a word1104const jlong NoLongBits = 0; // no bits set in a long1105const intptr_t OneBit = 1; // only right_most bit set in a word11061107// get a word with the n.th or the right-most or left-most n bits set1108// (note: #define used only so that they can be used in enum constant definitions)1109#define nth_bit(n) (n >= BitsPerWord ? 0 : OneBit << (n))1110#define right_n_bits(n) (nth_bit(n) - 1)1111#define left_n_bits(n) (right_n_bits(n) << (n >= BitsPerWord ? 0 : (BitsPerWord - n)))11121113// bit-operations using a mask m1114inline void set_bits (intptr_t& x, intptr_t m) { x |= m; }1115inline void clear_bits (intptr_t& x, intptr_t m) { x &= ~m; }1116inline intptr_t mask_bits (intptr_t x, intptr_t m) { return x & m; }1117inline jlong mask_long_bits (jlong x, jlong m) { return x & m; }1118inline bool mask_bits_are_true (intptr_t flags, intptr_t mask) { return (flags & mask) == mask; }11191120// bit-operations using the n.th bit1121inline void set_nth_bit(intptr_t& x, int n) { set_bits (x, nth_bit(n)); }1122inline void clear_nth_bit(intptr_t& x, int n) { clear_bits(x, nth_bit(n)); }1123inline bool is_set_nth_bit(intptr_t x, int n) { return mask_bits (x, nth_bit(n)) != NoBits; }11241125// returns the bitfield of x starting at start_bit_no with length field_length (no sign-extension!)1126inline intptr_t bitfield(intptr_t x, int start_bit_no, int field_length) {1127return mask_bits(x >> start_bit_no, right_n_bits(field_length));1128}112911301131//----------------------------------------------------------------------------------------------------1132// Utility functions for integers11331134// Avoid use of global min/max macros which may cause unwanted double1135// evaluation of arguments.1136#ifdef max1137#undef max1138#endif11391140#ifdef min1141#undef min1142#endif11431144#define max(a,b) Do_not_use_max_use_MAX2_instead1145#define min(a,b) Do_not_use_min_use_MIN2_instead11461147// It is necessary to use templates here. Having normal overloaded1148// functions does not work because it is necessary to provide both 32-1149// and 64-bit overloaded functions, which does not work, and having1150// explicitly-typed versions of these routines (i.e., MAX2I, MAX2L)1151// will be even more error-prone than macros.1152template<class T> inline T MAX2(T a, T b) { return (a > b) ? a : b; }1153template<class T> inline T MIN2(T a, T b) { return (a < b) ? a : b; }1154template<class T> inline T MAX3(T a, T b, T c) { return MAX2(MAX2(a, b), c); }1155template<class T> inline T MIN3(T a, T b, T c) { return MIN2(MIN2(a, b), c); }1156template<class T> inline T MAX4(T a, T b, T c, T d) { return MAX2(MAX3(a, b, c), d); }1157template<class T> inline T MIN4(T a, T b, T c, T d) { return MIN2(MIN3(a, b, c), d); }11581159template<class T> inline T ABS(T x) { return (x > 0) ? x : -x; }11601161// true if x is a power of 2, false otherwise1162inline bool is_power_of_2(intptr_t x) {1163return ((x != NoBits) && (mask_bits(x, x - 1) == NoBits));1164}11651166// long version of is_power_of_21167inline bool is_power_of_2_long(jlong x) {1168return ((x != NoLongBits) && (mask_long_bits(x, x - 1) == NoLongBits));1169}11701171//* largest i such that 2^i <= x1172// A negative value of 'x' will return '31'1173inline int log2_intptr(uintptr_t x) {1174int i = -1;1175uintptr_t p = 1;1176while (p != 0 && p <= x) {1177// p = 2^(i+1) && p <= x (i.e., 2^(i+1) <= x)1178i++; p *= 2;1179}1180// p = 2^(i+1) && x < p (i.e., 2^i <= x < 2^(i+1))1181// (if p = 0 then overflow occurred and i = 31)1182return i;1183}11841185//* largest i such that 2^i <= x1186inline int log2_long(julong x) {1187int i = -1;1188julong p = 1;1189while (p != 0 && p <= x) {1190// p = 2^(i+1) && p <= x (i.e., 2^(i+1) <= x)1191i++; p *= 2;1192}1193// p = 2^(i+1) && x < p (i.e., 2^i <= x < 2^(i+1))1194// (if p = 0 then overflow occurred and i = 63)1195return i;1196}11971198inline int log2_intptr(intptr_t x) {1199return log2_intptr((uintptr_t)x);1200}12011202inline int log2_int(int x) {1203return log2_intptr((uintptr_t)x);1204}12051206inline int log2_jint(jint x) {1207return log2_intptr((uintptr_t)x);1208}12091210inline int log2_uint(uint x) {1211return log2_intptr((uintptr_t)x);1212}12131214// A negative value of 'x' will return '63'1215inline int log2_jlong(jlong x) {1216return log2_long((julong)x);1217}12181219//* the argument must be exactly a power of 21220inline int exact_log2(intptr_t x) {1221#ifdef ASSERT1222if (!is_power_of_2(x)) basic_fatal("x must be a power of 2");1223#endif1224return log2_intptr(x);1225}12261227//* the argument must be exactly a power of 21228inline int exact_log2_long(jlong x) {1229#ifdef ASSERT1230if (!is_power_of_2_long(x)) basic_fatal("x must be a power of 2");1231#endif1232return log2_long(x);1233}123412351236// returns integer round-up to the nearest multiple of s (s must be a power of two)1237inline intptr_t round_to(intptr_t x, uintx s) {1238#ifdef ASSERT1239if (!is_power_of_2(s)) basic_fatal("s must be a power of 2");1240#endif1241const uintx m = s - 1;1242return mask_bits(x + m, ~m);1243}12441245// returns integer round-down to the nearest multiple of s (s must be a power of two)1246inline intptr_t round_down(intptr_t x, uintx s) {1247#ifdef ASSERT1248if (!is_power_of_2(s)) basic_fatal("s must be a power of 2");1249#endif1250const uintx m = s - 1;1251return mask_bits(x, ~m);1252}125312541255inline bool is_odd (intx x) { return x & 1; }1256inline bool is_even(intx x) { return !is_odd(x); }12571258// abs methods which cannot overflow and so are well-defined across1259// the entire domain of integer types.1260static inline unsigned int uabs(unsigned int n) {1261union {1262unsigned int result;1263int value;1264};1265result = n;1266if (value < 0) result = 0-result;1267return result;1268}1269static inline julong uabs(julong n) {1270union {1271julong result;1272jlong value;1273};1274result = n;1275if (value < 0) result = 0-result;1276return result;1277}1278static inline julong uabs(jlong n) { return uabs((julong)n); }1279static inline unsigned int uabs(int n) { return uabs((unsigned int)n); }12801281// "to" should be greater than "from."1282inline intx byte_size(void* from, void* to) {1283return (address)to - (address)from;1284}12851286//----------------------------------------------------------------------------------------------------1287// Avoid non-portable casts with these routines (DEPRECATED)12881289// NOTE: USE Bytes class INSTEAD WHERE POSSIBLE1290// Bytes is optimized machine-specifically and may be much faster then the portable routines below.12911292// Given sequence of four bytes, build into a 32-bit word1293// following the conventions used in class files.1294// On the 386, this could be realized with a simple address cast.1295//12961297// This routine takes eight bytes:1298inline u8 build_u8_from( u1 c1, u1 c2, u1 c3, u1 c4, u1 c5, u1 c6, u1 c7, u1 c8 ) {1299return (( u8(c1) << 56 ) & ( u8(0xff) << 56 ))1300| (( u8(c2) << 48 ) & ( u8(0xff) << 48 ))1301| (( u8(c3) << 40 ) & ( u8(0xff) << 40 ))1302| (( u8(c4) << 32 ) & ( u8(0xff) << 32 ))1303| (( u8(c5) << 24 ) & ( u8(0xff) << 24 ))1304| (( u8(c6) << 16 ) & ( u8(0xff) << 16 ))1305| (( u8(c7) << 8 ) & ( u8(0xff) << 8 ))1306| (( u8(c8) << 0 ) & ( u8(0xff) << 0 ));1307}13081309// This routine takes four bytes:1310inline u4 build_u4_from( u1 c1, u1 c2, u1 c3, u1 c4 ) {1311return (( u4(c1) << 24 ) & 0xff000000)1312| (( u4(c2) << 16 ) & 0x00ff0000)1313| (( u4(c3) << 8 ) & 0x0000ff00)1314| (( u4(c4) << 0 ) & 0x000000ff);1315}13161317// And this one works if the four bytes are contiguous in memory:1318inline u4 build_u4_from( u1* p ) {1319return build_u4_from( p[0], p[1], p[2], p[3] );1320}13211322// Ditto for two-byte ints:1323inline u2 build_u2_from( u1 c1, u1 c2 ) {1324return u2((( u2(c1) << 8 ) & 0xff00)1325| (( u2(c2) << 0 ) & 0x00ff));1326}13271328// And this one works if the two bytes are contiguous in memory:1329inline u2 build_u2_from( u1* p ) {1330return build_u2_from( p[0], p[1] );1331}13321333// Ditto for floats:1334inline jfloat build_float_from( u1 c1, u1 c2, u1 c3, u1 c4 ) {1335u4 u = build_u4_from( c1, c2, c3, c4 );1336return *(jfloat*)&u;1337}13381339inline jfloat build_float_from( u1* p ) {1340u4 u = build_u4_from( p );1341return *(jfloat*)&u;1342}134313441345// now (64-bit) longs13461347inline jlong build_long_from( u1 c1, u1 c2, u1 c3, u1 c4, u1 c5, u1 c6, u1 c7, u1 c8 ) {1348return (( jlong(c1) << 56 ) & ( jlong(0xff) << 56 ))1349| (( jlong(c2) << 48 ) & ( jlong(0xff) << 48 ))1350| (( jlong(c3) << 40 ) & ( jlong(0xff) << 40 ))1351| (( jlong(c4) << 32 ) & ( jlong(0xff) << 32 ))1352| (( jlong(c5) << 24 ) & ( jlong(0xff) << 24 ))1353| (( jlong(c6) << 16 ) & ( jlong(0xff) << 16 ))1354| (( jlong(c7) << 8 ) & ( jlong(0xff) << 8 ))1355| (( jlong(c8) << 0 ) & ( jlong(0xff) << 0 ));1356}13571358inline jlong build_long_from( u1* p ) {1359return build_long_from( p[0], p[1], p[2], p[3], p[4], p[5], p[6], p[7] );1360}136113621363// Doubles, too!1364inline jdouble build_double_from( u1 c1, u1 c2, u1 c3, u1 c4, u1 c5, u1 c6, u1 c7, u1 c8 ) {1365jlong u = build_long_from( c1, c2, c3, c4, c5, c6, c7, c8 );1366return *(jdouble*)&u;1367}13681369inline jdouble build_double_from( u1* p ) {1370jlong u = build_long_from( p );1371return *(jdouble*)&u;1372}137313741375// Portable routines to go the other way:13761377inline void explode_short_to( u2 x, u1& c1, u1& c2 ) {1378c1 = u1(x >> 8);1379c2 = u1(x);1380}13811382inline void explode_short_to( u2 x, u1* p ) {1383explode_short_to( x, p[0], p[1]);1384}13851386inline void explode_int_to( u4 x, u1& c1, u1& c2, u1& c3, u1& c4 ) {1387c1 = u1(x >> 24);1388c2 = u1(x >> 16);1389c3 = u1(x >> 8);1390c4 = u1(x);1391}13921393inline void explode_int_to( u4 x, u1* p ) {1394explode_int_to( x, p[0], p[1], p[2], p[3]);1395}139613971398// Pack and extract shorts to/from ints:13991400inline int extract_low_short_from_int(jint x) {1401return x & 0xffff;1402}14031404inline int extract_high_short_from_int(jint x) {1405return (x >> 16) & 0xffff;1406}14071408inline int build_int_from_shorts( jushort low, jushort high ) {1409return ((int)((unsigned int)high << 16) | (unsigned int)low);1410}14111412// Convert pointer to intptr_t, for use in printing pointers.1413inline intptr_t p2i(const void * p) {1414return (intptr_t) p;1415}14161417// Printf-style formatters for fixed- and variable-width types as pointers and1418// integers. These are derived from the definitions in inttypes.h. If the platform1419// doesn't provide appropriate definitions, they should be provided in1420// the compiler-specific definitions file (e.g., globalDefinitions_gcc.hpp)14211422#define BOOL_TO_STR(_b_) ((_b_) ? "true" : "false")14231424// Format 32-bit quantities.1425#define INT32_FORMAT "%" PRId321426#define UINT32_FORMAT "%" PRIu321427#define INT32_FORMAT_W(width) "%" #width PRId321428#define UINT32_FORMAT_W(width) "%" #width PRIu3214291430#define PTR32_FORMAT "0x%08" PRIx3214311432// Format 64-bit quantities.1433#define INT64_FORMAT "%" PRId641434#define UINT64_FORMAT "%" PRIu641435#define UINT64_FORMAT_X "%" PRIx641436#define INT64_FORMAT_W(width) "%" #width PRId641437#define UINT64_FORMAT_W(width) "%" #width PRIu641438#define UINT64_FORMAT_X_W(width) "%" #width PRIx6414391440#define PTR64_FORMAT "0x%016" PRIx6414411442// Format jlong, if necessary1443#ifndef JLONG_FORMAT1444#define JLONG_FORMAT INT64_FORMAT1445#endif1446#ifndef JULONG_FORMAT1447#define JULONG_FORMAT UINT64_FORMAT1448#endif14491450// Format pointers which change size between 32- and 64-bit.1451#ifdef _LP641452#define INTPTR_FORMAT "0x%016" PRIxPTR1453#define PTR_FORMAT "0x%016" PRIxPTR1454#else // !_LP641455#define INTPTR_FORMAT "0x%08" PRIxPTR1456#define PTR_FORMAT "0x%08" PRIxPTR1457#endif // _LP6414581459#define INTPTR_FORMAT_W(width) "%" #width PRIxPTR14601461#define SSIZE_FORMAT "%" PRIdPTR1462#define SIZE_FORMAT "%" PRIuPTR1463#define SIZE_FORMAT_HEX "0x%" PRIxPTR1464#define SSIZE_FORMAT_W(width) "%" #width PRIdPTR1465#define SIZE_FORMAT_W(width) "%" #width PRIuPTR1466#define SIZE_FORMAT_HEX_W(width) "0x%" #width PRIxPTR14671468#define INTX_FORMAT "%" PRIdPTR1469#define UINTX_FORMAT "%" PRIuPTR1470#define INTX_FORMAT_W(width) "%" #width PRIdPTR1471#define UINTX_FORMAT_W(width) "%" #width PRIuPTR147214731474// Enable zap-a-lot if in debug version.14751476# ifdef ASSERT1477# ifdef COMPILER21478# define ENABLE_ZAP_DEAD_LOCALS1479#endif /* COMPILER2 */1480# endif /* ASSERT */14811482#define ARRAY_SIZE(array) (sizeof(array)/sizeof((array)[0]))14831484//----------------------------------------------------------------------------------------------------1485// Sum and product which can never overflow: they wrap, just like the1486// Java operations. Note that we don't intend these to be used for1487// general-purpose arithmetic: their purpose is to emulate Java1488// operations.14891490// The goal of this code to avoid undefined or implementation-defined1491// behaviour. The use of an lvalue to reference cast is explicitly1492// permitted by Lvalues and rvalues [basic.lval]. [Section 3.10 Para1493// 15 in C++03]1494#define JAVA_INTEGER_OP(OP, NAME, TYPE, UNSIGNED_TYPE) \1495inline TYPE NAME (TYPE in1, TYPE in2) { \1496UNSIGNED_TYPE ures = static_cast<UNSIGNED_TYPE>(in1); \1497ures OP ## = static_cast<UNSIGNED_TYPE>(in2); \1498return reinterpret_cast<TYPE&>(ures); \1499}15001501JAVA_INTEGER_OP(+, java_add, jint, juint)1502JAVA_INTEGER_OP(-, java_subtract, jint, juint)1503JAVA_INTEGER_OP(*, java_multiply, jint, juint)1504JAVA_INTEGER_OP(+, java_add, jlong, julong)1505JAVA_INTEGER_OP(-, java_subtract, jlong, julong)1506JAVA_INTEGER_OP(*, java_multiply, jlong, julong)15071508#undef JAVA_INTEGER_OP15091510// Dereference vptr1511// All C++ compilers that we know of have the vtbl pointer in the first1512// word. If there are exceptions, this function needs to be made compiler1513// specific.1514static inline void* dereference_vptr(const void* addr) {1515return *(void**)addr;1516}15171518#ifndef PRODUCT15191520// For unit testing only1521class GlobalDefinitions {1522public:1523static void test_globals();1524static void test_proper_unit();1525};15261527#endif // PRODUCT15281529#endif // SHARE_VM_UTILITIES_GLOBALDEFINITIONS_HPP153015311532