Path: blob/jdk8u272-b10-aarch32-20201026/hotspot/src/share/vm/utilities/globalDefinitions.hpp
83404 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#else147const int SerializePageShiftCount = 3;148#endif149150// An opaque struct of heap-word width, so that HeapWord* can be a generic151// pointer into the heap. We require that object sizes be measured in152// units of heap words, so that that153// HeapWord* hw;154// hw += oop(hw)->foo();155// works, where foo is a method (like size or scavenge) that returns the156// object size.157class HeapWord {158friend class VMStructs;159private:160char* i;161#ifndef PRODUCT162public:163char* value() { return i; }164#endif165};166167// Analogous opaque struct for metadata allocated from168// metaspaces.169class MetaWord {170friend class VMStructs;171private:172char* i;173};174175// HeapWordSize must be 2^LogHeapWordSize.176const int HeapWordSize = sizeof(HeapWord);177#ifdef _LP64178const int LogHeapWordSize = 3;179#else180const int LogHeapWordSize = 2;181#endif182const int HeapWordsPerLong = BytesPerLong / HeapWordSize;183const int LogHeapWordsPerLong = LogBytesPerLong - LogHeapWordSize;184185// The larger HeapWordSize for 64bit requires larger heaps186// for the same application running in 64bit. See bug 4967770.187// The minimum alignment to a heap word size is done. Other188// parts of the memory system may required additional alignment189// and are responsible for those alignments.190#ifdef _LP64191#define ScaleForWordSize(x) align_size_down_((x) * 13 / 10, HeapWordSize)192#else193#define ScaleForWordSize(x) (x)194#endif195196// The minimum number of native machine words necessary to contain "byte_size"197// bytes.198inline size_t heap_word_size(size_t byte_size) {199return (byte_size + (HeapWordSize-1)) >> LogHeapWordSize;200}201202203const size_t K = 1024;204const size_t M = K*K;205const size_t G = M*K;206const size_t HWperKB = K / sizeof(HeapWord);207208const jint min_jint = (jint)1 << (sizeof(jint)*BitsPerByte-1); // 0x80000000 == smallest jint209const jint max_jint = (juint)min_jint - 1; // 0x7FFFFFFF == largest jint210211// Constants for converting from a base unit to milli-base units. For212// example from seconds to milliseconds and microseconds213214const int MILLIUNITS = 1000; // milli units per base unit215const int MICROUNITS = 1000000; // micro units per base unit216const int NANOUNITS = 1000000000; // nano units per base unit217218const jlong NANOSECS_PER_SEC = CONST64(1000000000);219const jint NANOSECS_PER_MILLISEC = 1000000;220221// Proper units routines try to maintain at least three significant digits.222// In worst case, it would print five significant digits with lower prefix.223// G is close to MAX_SIZE on 32-bit platforms, so its product can easily overflow,224// and therefore we need to be careful.225226inline const char* proper_unit_for_byte_size(size_t s) {227#ifdef _LP64228if (s >= 100*G) {229return "G";230}231#endif232if (s >= 100*M) {233return "M";234} else if (s >= 100*K) {235return "K";236} else {237return "B";238}239}240241template <class T>242inline T byte_size_in_proper_unit(T s) {243#ifdef _LP64244if (s >= 100*G) {245return (T)(s/G);246}247#endif248if (s >= 100*M) {249return (T)(s/M);250} else if (s >= 100*K) {251return (T)(s/K);252} else {253return s;254}255}256257//----------------------------------------------------------------------------------------------------258// VM type definitions259260// intx and uintx are the 'extended' int and 'extended' unsigned int types;261// they are 32bit wide on a 32-bit platform, and 64bit wide on a 64bit platform.262263typedef intptr_t intx;264typedef uintptr_t uintx;265266const intx min_intx = (intx)1 << (sizeof(intx)*BitsPerByte-1);267const intx max_intx = (uintx)min_intx - 1;268const uintx max_uintx = (uintx)-1;269270// Table of values:271// sizeof intx 4 8272// min_intx 0x80000000 0x8000000000000000273// max_intx 0x7FFFFFFF 0x7FFFFFFFFFFFFFFF274// max_uintx 0xFFFFFFFF 0xFFFFFFFFFFFFFFFF275276typedef unsigned int uint; NEEDS_CLEANUP277278279//----------------------------------------------------------------------------------------------------280// Java type definitions281282// All kinds of 'plain' byte addresses283typedef signed char s_char;284typedef unsigned char u_char;285typedef u_char* address;286typedef uintptr_t address_word; // unsigned integer which will hold a pointer287// except for some implementations of a C++288// linkage pointer to function. Should never289// need one of those to be placed in this290// type anyway.291292// Utility functions to "portably" (?) bit twiddle pointers293// Where portable means keep ANSI C++ compilers quiet294295inline address set_address_bits(address x, int m) { return address(intptr_t(x) | m); }296inline address clear_address_bits(address x, int m) { return address(intptr_t(x) & ~m); }297298// Utility functions to "portably" make cast to/from function pointers.299300inline address_word mask_address_bits(address x, int m) { return address_word(x) & m; }301inline address_word castable_address(address x) { return address_word(x) ; }302inline address_word castable_address(void* x) { return address_word(x) ; }303304// Pointer subtraction.305// The idea here is to avoid ptrdiff_t, which is signed and so doesn't have306// the range we might need to find differences from one end of the heap307// to the other.308// A typical use might be:309// if (pointer_delta(end(), top()) >= size) {310// // enough room for an object of size311// ...312// and then additions like313// ... top() + size ...314// are safe because we know that top() is at least size below end().315inline size_t pointer_delta(const void* left,316const void* right,317size_t element_size) {318return (((uintptr_t) left) - ((uintptr_t) right)) / element_size;319}320// A version specialized for HeapWord*'s.321inline size_t pointer_delta(const HeapWord* left, const HeapWord* right) {322return pointer_delta(left, right, sizeof(HeapWord));323}324// A version specialized for MetaWord*'s.325inline size_t pointer_delta(const MetaWord* left, const MetaWord* right) {326return pointer_delta(left, right, sizeof(MetaWord));327}328329//330// ANSI C++ does not allow casting from one pointer type to a function pointer331// directly without at best a warning. This macro accomplishes it silently332// In every case that is present at this point the value be cast is a pointer333// to a C linkage function. In somecase the type used for the cast reflects334// that linkage and a picky compiler would not complain. In other cases because335// there is no convenient place to place a typedef with extern C linkage (i.e336// a platform dependent header file) it doesn't. At this point no compiler seems337// picky enough to catch these instances (which are few). It is possible that338// using templates could fix these for all cases. This use of templates is likely339// so far from the middle of the road that it is likely to be problematic in340// many C++ compilers.341//342#define CAST_TO_FN_PTR(func_type, value) (reinterpret_cast<func_type>(value))343#define CAST_FROM_FN_PTR(new_type, func_ptr) ((new_type)((address_word)(func_ptr)))344345// Unsigned byte types for os and stream.hpp346347// Unsigned one, two, four and eigth byte quantities used for describing348// the .class file format. See JVM book chapter 4.349350typedef jubyte u1;351typedef jushort u2;352typedef juint u4;353typedef julong u8;354355const jubyte max_jubyte = (jubyte)-1; // 0xFF largest jubyte356const jushort max_jushort = (jushort)-1; // 0xFFFF largest jushort357const juint max_juint = (juint)-1; // 0xFFFFFFFF largest juint358const julong max_julong = (julong)-1; // 0xFF....FF largest julong359360typedef jbyte s1;361typedef jshort s2;362typedef jint s4;363typedef jlong s8;364365//----------------------------------------------------------------------------------------------------366// JVM spec restrictions367368const int max_method_code_size = 64*K - 1; // JVM spec, 2nd ed. section 4.8.1 (p.134)369370// Default ProtectionDomainCacheSize values371372const int defaultProtectionDomainCacheSize = NOT_LP64(137) LP64_ONLY(2017);373374//----------------------------------------------------------------------------------------------------375// Default and minimum StringTableSize values376377const int defaultStringTableSize = NOT_LP64(1009) LP64_ONLY(60013);378const int minimumStringTableSize = 1009;379380const int defaultSymbolTableSize = 20011;381const int minimumSymbolTableSize = 1009;382383384//----------------------------------------------------------------------------------------------------385// HotSwap - for JVMTI aka Class File Replacement and PopFrame386//387// Determines whether on-the-fly class replacement and frame popping are enabled.388389#define HOTSWAP390391//----------------------------------------------------------------------------------------------------392// Object alignment, in units of HeapWords.393//394// Minimum is max(BytesPerLong, BytesPerDouble, BytesPerOop) / HeapWordSize, so jlong, jdouble and395// reference fields can be naturally aligned.396397extern int MinObjAlignment;398extern int MinObjAlignmentInBytes;399extern int MinObjAlignmentInBytesMask;400401extern int LogMinObjAlignment;402extern int LogMinObjAlignmentInBytes;403404const int LogKlassAlignmentInBytes = 3;405const int LogKlassAlignment = LogKlassAlignmentInBytes - LogHeapWordSize;406const int KlassAlignmentInBytes = 1 << LogKlassAlignmentInBytes;407const int KlassAlignment = KlassAlignmentInBytes / HeapWordSize;408409// Klass encoding metaspace max size410const uint64_t KlassEncodingMetaspaceMax = (uint64_t(max_juint) + 1) << LogKlassAlignmentInBytes;411412// Machine dependent stuff413414#if defined(X86) && defined(COMPILER2) && !defined(JAVASE_EMBEDDED)415// Include Restricted Transactional Memory lock eliding optimization416#define INCLUDE_RTM_OPT 1417#define RTM_OPT_ONLY(code) code418#else419#define INCLUDE_RTM_OPT 0420#define RTM_OPT_ONLY(code)421#endif422// States of Restricted Transactional Memory usage.423enum RTMState {424NoRTM = 0x2, // Don't use RTM425UseRTM = 0x1, // Use RTM426ProfileRTM = 0x0 // Use RTM with abort ratio calculation427};428429// The maximum size of the code cache. Can be overridden by targets.430#define CODE_CACHE_SIZE_LIMIT (2*G)431// Allow targets to reduce the default size of the code cache.432#define CODE_CACHE_DEFAULT_LIMIT CODE_CACHE_SIZE_LIMIT433434#ifdef TARGET_ARCH_x86435# include "globalDefinitions_x86.hpp"436#endif437#ifdef TARGET_ARCH_aarch64438# include "globalDefinitions_aarch64.hpp"439#endif440#ifdef TARGET_ARCH_sparc441# include "globalDefinitions_sparc.hpp"442#endif443#ifdef TARGET_ARCH_zero444# include "globalDefinitions_zero.hpp"445#endif446#ifdef TARGET_ARCH_arm447# include "globalDefinitions_arm.hpp"448#endif449#ifdef TARGET_ARCH_ppc450# include "globalDefinitions_ppc.hpp"451#endif452#ifdef TARGET_ARCH_aarch32453# include "globalDefinitions_aarch32.hpp"454#endif455456/*457* If a platform does not support native stack walking458* the platform specific globalDefinitions (above)459* can set PLATFORM_NATIVE_STACK_WALKING_SUPPORTED to 0460*/461#ifndef PLATFORM_NATIVE_STACK_WALKING_SUPPORTED462#define PLATFORM_NATIVE_STACK_WALKING_SUPPORTED 1463#endif464465// To assure the IRIW property on processors that are not multiple copy466// atomic, sync instructions must be issued between volatile reads to467// assure their ordering, instead of after volatile stores.468// (See "A Tutorial Introduction to the ARM and POWER Relaxed Memory Models"469// by Luc Maranget, Susmit Sarkar and Peter Sewell, INRIA/Cambridge)470#ifdef CPU_NOT_MULTIPLE_COPY_ATOMIC471const bool support_IRIW_for_not_multiple_copy_atomic_cpu = true;472#else473const bool support_IRIW_for_not_multiple_copy_atomic_cpu = false;474#endif475476// The byte alignment to be used by Arena::Amalloc. See bugid 4169348.477// Note: this value must be a power of 2478479#define ARENA_AMALLOC_ALIGNMENT (2*BytesPerWord)480481// Signed variants of alignment helpers. There are two versions of each, a macro482// for use in places like enum definitions that require compile-time constant483// expressions and a function for all other places so as to get type checking.484485#define align_size_up_(size, alignment) (((size) + ((alignment) - 1)) & ~((alignment) - 1))486487inline bool is_size_aligned(size_t size, size_t alignment) {488return align_size_up_(size, alignment) == size;489}490491inline bool is_ptr_aligned(void* ptr, size_t alignment) {492return align_size_up_((intptr_t)ptr, (intptr_t)alignment) == (intptr_t)ptr;493}494495inline intptr_t align_size_up(intptr_t size, intptr_t alignment) {496return align_size_up_(size, alignment);497}498499#define align_size_down_(size, alignment) ((size) & ~((alignment) - 1))500501inline intptr_t align_size_down(intptr_t size, intptr_t alignment) {502return align_size_down_(size, alignment);503}504505#define is_size_aligned_(size, alignment) ((size) == (align_size_up_(size, alignment)))506507inline void* align_ptr_up(void* ptr, size_t alignment) {508return (void*)align_size_up((intptr_t)ptr, (intptr_t)alignment);509}510511inline void* align_ptr_down(void* ptr, size_t alignment) {512return (void*)align_size_down((intptr_t)ptr, (intptr_t)alignment);513}514515// Align objects by rounding up their size, in HeapWord units.516517#define align_object_size_(size) align_size_up_(size, MinObjAlignment)518519inline intptr_t align_object_size(intptr_t size) {520return align_size_up(size, MinObjAlignment);521}522523inline bool is_object_aligned(intptr_t addr) {524return addr == align_object_size(addr);525}526527// Pad out certain offsets to jlong alignment, in HeapWord units.528529inline intptr_t align_object_offset(intptr_t offset) {530return align_size_up(offset, HeapWordsPerLong);531}532533inline void* align_pointer_up(const void* addr, size_t size) {534return (void*) align_size_up_((uintptr_t)addr, size);535}536537// Align down with a lower bound. If the aligning results in 0, return 'alignment'.538539inline size_t align_size_down_bounded(size_t size, size_t alignment) {540size_t aligned_size = align_size_down_(size, alignment);541return aligned_size > 0 ? aligned_size : alignment;542}543544// Clamp an address to be within a specific page545// 1. If addr is on the page it is returned as is546// 2. If addr is above the page_address the start of the *next* page will be returned547// 3. Otherwise, if addr is below the page_address the start of the page will be returned548inline address clamp_address_in_page(address addr, address page_address, intptr_t page_size) {549if (align_size_down(intptr_t(addr), page_size) == align_size_down(intptr_t(page_address), page_size)) {550// address is in the specified page, just return it as is551return addr;552} else if (addr > page_address) {553// address is above specified page, return start of next page554return (address)align_size_down(intptr_t(page_address), page_size) + page_size;555} else {556// address is below specified page, return start of page557return (address)align_size_down(intptr_t(page_address), page_size);558}559}560561562// The expected size in bytes of a cache line, used to pad data structures.563#define DEFAULT_CACHE_LINE_SIZE 64564565566//----------------------------------------------------------------------------------------------------567// Utility macros for compilers568// used to silence compiler warnings569570#define Unused_Variable(var) var571572573//----------------------------------------------------------------------------------------------------574// Miscellaneous575576// 6302670 Eliminate Hotspot __fabsf dependency577// All fabs() callers should call this function instead, which will implicitly578// convert the operand to double, avoiding a dependency on __fabsf which579// doesn't exist in early versions of Solaris 8.580inline double fabsd(double value) {581return fabs(value);582}583584//----------------------------------------------------------------------------------------------------585// Special casts586// Cast floats into same-size integers and vice-versa w/o changing bit-pattern587typedef union {588jfloat f;589jint i;590} FloatIntConv;591592typedef union {593jdouble d;594jlong l;595julong ul;596} DoubleLongConv;597598inline jint jint_cast (jfloat x) { return ((FloatIntConv*)&x)->i; }599inline jfloat jfloat_cast (jint x) { return ((FloatIntConv*)&x)->f; }600601inline jlong jlong_cast (jdouble x) { return ((DoubleLongConv*)&x)->l; }602inline julong julong_cast (jdouble x) { return ((DoubleLongConv*)&x)->ul; }603inline jdouble jdouble_cast (jlong x) { return ((DoubleLongConv*)&x)->d; }604605inline jint low (jlong value) { return jint(value); }606inline jint high(jlong value) { return jint(value >> 32); }607608// the fancy casts are a hopefully portable way609// to do unsigned 32 to 64 bit type conversion610inline void set_low (jlong* value, jint low ) { *value &= (jlong)0xffffffff << 32;611*value |= (jlong)(julong)(juint)low; }612613inline void set_high(jlong* value, jint high) { *value &= (jlong)(julong)(juint)0xffffffff;614*value |= (jlong)high << 32; }615616inline jlong jlong_from(jint h, jint l) {617jlong result = 0; // initialization to avoid warning618set_high(&result, h);619set_low(&result, l);620return result;621}622623union jlong_accessor {624jint words[2];625jlong long_value;626};627628void basic_types_init(); // cannot define here; uses assert629630631// NOTE: replicated in SA in vm/agent/sun/jvm/hotspot/runtime/BasicType.java632enum BasicType {633T_BOOLEAN = 4,634T_CHAR = 5,635T_FLOAT = 6,636T_DOUBLE = 7,637T_BYTE = 8,638T_SHORT = 9,639T_INT = 10,640T_LONG = 11,641T_OBJECT = 12,642T_ARRAY = 13,643T_VOID = 14,644T_ADDRESS = 15,645T_NARROWOOP = 16,646T_METADATA = 17,647T_NARROWKLASS = 18,648T_CONFLICT = 19, // for stack value type with conflicting contents649T_ILLEGAL = 99650};651652inline bool is_java_primitive(BasicType t) {653return T_BOOLEAN <= t && t <= T_LONG;654}655656inline bool is_subword_type(BasicType t) {657// these guys are processed exactly like T_INT in calling sequences:658return (t == T_BOOLEAN || t == T_CHAR || t == T_BYTE || t == T_SHORT);659}660661inline bool is_signed_subword_type(BasicType t) {662return (t == T_BYTE || t == T_SHORT);663}664665inline bool is_reference_type(BasicType t) {666return (t == T_OBJECT || t == T_ARRAY);667}668669// Convert a char from a classfile signature to a BasicType670inline BasicType char2type(char c) {671switch( c ) {672case 'B': return T_BYTE;673case 'C': return T_CHAR;674case 'D': return T_DOUBLE;675case 'F': return T_FLOAT;676case 'I': return T_INT;677case 'J': return T_LONG;678case 'S': return T_SHORT;679case 'Z': return T_BOOLEAN;680case 'V': return T_VOID;681case 'L': return T_OBJECT;682case '[': return T_ARRAY;683}684return T_ILLEGAL;685}686687extern char type2char_tab[T_CONFLICT+1]; // Map a BasicType to a jchar688inline char type2char(BasicType t) { return (uint)t < T_CONFLICT+1 ? type2char_tab[t] : 0; }689extern int type2size[T_CONFLICT+1]; // Map BasicType to result stack elements690extern const char* type2name_tab[T_CONFLICT+1]; // Map a BasicType to a jchar691inline const char* type2name(BasicType t) { return (uint)t < T_CONFLICT+1 ? type2name_tab[t] : NULL; }692extern BasicType name2type(const char* name);693694// Auxilary math routines695// least common multiple696extern size_t lcm(size_t a, size_t b);697698699// NOTE: replicated in SA in vm/agent/sun/jvm/hotspot/runtime/BasicType.java700enum BasicTypeSize {701T_BOOLEAN_size = 1,702T_CHAR_size = 1,703T_FLOAT_size = 1,704T_DOUBLE_size = 2,705T_BYTE_size = 1,706T_SHORT_size = 1,707T_INT_size = 1,708T_LONG_size = 2,709T_OBJECT_size = 1,710T_ARRAY_size = 1,711T_NARROWOOP_size = 1,712T_NARROWKLASS_size = 1,713T_VOID_size = 0714};715716717// maps a BasicType to its instance field storage type:718// all sub-word integral types are widened to T_INT719extern BasicType type2field[T_CONFLICT+1];720extern BasicType type2wfield[T_CONFLICT+1];721722723// size in bytes724enum ArrayElementSize {725T_BOOLEAN_aelem_bytes = 1,726T_CHAR_aelem_bytes = 2,727T_FLOAT_aelem_bytes = 4,728T_DOUBLE_aelem_bytes = 8,729T_BYTE_aelem_bytes = 1,730T_SHORT_aelem_bytes = 2,731T_INT_aelem_bytes = 4,732T_LONG_aelem_bytes = 8,733#ifdef _LP64734T_OBJECT_aelem_bytes = 8,735T_ARRAY_aelem_bytes = 8,736#else737T_OBJECT_aelem_bytes = 4,738T_ARRAY_aelem_bytes = 4,739#endif740T_NARROWOOP_aelem_bytes = 4,741T_NARROWKLASS_aelem_bytes = 4,742T_VOID_aelem_bytes = 0743};744745extern int _type2aelembytes[T_CONFLICT+1]; // maps a BasicType to nof bytes used by its array element746#ifdef ASSERT747extern int type2aelembytes(BasicType t, bool allow_address = false); // asserts748#else749inline int type2aelembytes(BasicType t, bool allow_address = false) { return _type2aelembytes[t]; }750#endif751752753// JavaValue serves as a container for arbitrary Java values.754755class JavaValue {756757public:758typedef union JavaCallValue {759jfloat f;760jdouble d;761jint i;762jlong l;763jobject h;764} JavaCallValue;765766private:767BasicType _type;768JavaCallValue _value;769770public:771JavaValue(BasicType t = T_ILLEGAL) { _type = t; }772773JavaValue(jfloat value) {774_type = T_FLOAT;775_value.f = value;776}777778JavaValue(jdouble value) {779_type = T_DOUBLE;780_value.d = value;781}782783jfloat get_jfloat() const { return _value.f; }784jdouble get_jdouble() const { return _value.d; }785jint get_jint() const { return _value.i; }786jlong get_jlong() const { return _value.l; }787jobject get_jobject() const { return _value.h; }788JavaCallValue* get_value_addr() { return &_value; }789BasicType get_type() const { return _type; }790791void set_jfloat(jfloat f) { _value.f = f;}792void set_jdouble(jdouble d) { _value.d = d;}793void set_jint(jint i) { _value.i = i;}794void set_jlong(jlong l) { _value.l = l;}795void set_jobject(jobject h) { _value.h = h;}796void set_type(BasicType t) { _type = t; }797798jboolean get_jboolean() const { return (jboolean) (_value.i);}799jbyte get_jbyte() const { return (jbyte) (_value.i);}800jchar get_jchar() const { return (jchar) (_value.i);}801jshort get_jshort() const { return (jshort) (_value.i);}802803};804805806#define STACK_BIAS 0807// V9 Sparc CPU's running in 64 Bit mode use a stack bias of 7ff808// in order to extend the reach of the stack pointer.809#if defined(SPARC) && defined(_LP64)810#undef STACK_BIAS811#define STACK_BIAS 0x7ff812#endif813814815// TosState describes the top-of-stack state before and after the execution of816// a bytecode or method. The top-of-stack value may be cached in one or more CPU817// registers. The TosState corresponds to the 'machine represention' of this cached818// value. There's 4 states corresponding to the JAVA types int, long, float & double819// as well as a 5th state in case the top-of-stack value is actually on the top820// of stack (in memory) and thus not cached. The atos state corresponds to the itos821// state when it comes to machine representation but is used separately for (oop)822// type specific operations (e.g. verification code).823824enum TosState { // describes the tos cache contents825btos = 0, // byte, bool tos cached826ztos = 1, // byte, bool tos cached827ctos = 2, // char tos cached828stos = 3, // short tos cached829itos = 4, // int tos cached830ltos = 5, // long tos cached831ftos = 6, // float tos cached832dtos = 7, // double tos cached833atos = 8, // object cached834vtos = 9, // tos not cached835number_of_states,836ilgl // illegal state: should not occur837};838839840inline TosState as_TosState(BasicType type) {841switch (type) {842case T_BYTE : return btos;843case T_BOOLEAN: return ztos;844case T_CHAR : return ctos;845case T_SHORT : return stos;846case T_INT : return itos;847case T_LONG : return ltos;848case T_FLOAT : return ftos;849case T_DOUBLE : return dtos;850case T_VOID : return vtos;851case T_ARRAY : // fall through852case T_OBJECT : return atos;853}854return ilgl;855}856857inline BasicType as_BasicType(TosState state) {858switch (state) {859case btos : return T_BYTE;860case ztos : return T_BOOLEAN;861case ctos : return T_CHAR;862case stos : return T_SHORT;863case itos : return T_INT;864case ltos : return T_LONG;865case ftos : return T_FLOAT;866case dtos : return T_DOUBLE;867case atos : return T_OBJECT;868case vtos : return T_VOID;869}870return T_ILLEGAL;871}872873874// Helper function to convert BasicType info into TosState875// Note: Cannot define here as it uses global constant at the time being.876TosState as_TosState(BasicType type);877878879// JavaThreadState keeps track of which part of the code a thread is executing in. This880// information is needed by the safepoint code.881//882// There are 4 essential states:883//884// _thread_new : Just started, but not executed init. code yet (most likely still in OS init code)885// _thread_in_native : In native code. This is a safepoint region, since all oops will be in jobject handles886// _thread_in_vm : Executing in the vm887// _thread_in_Java : Executing either interpreted or compiled Java code (or could be in a stub)888//889// Each state has an associated xxxx_trans state, which is an intermediate state used when a thread is in890// a transition from one state to another. These extra states makes it possible for the safepoint code to891// handle certain thread_states without having to suspend the thread - making the safepoint code faster.892//893// Given a state, the xxx_trans state can always be found by adding 1.894//895enum JavaThreadState {896_thread_uninitialized = 0, // should never happen (missing initialization)897_thread_new = 2, // just starting up, i.e., in process of being initialized898_thread_new_trans = 3, // corresponding transition state (not used, included for completness)899_thread_in_native = 4, // running in native code900_thread_in_native_trans = 5, // corresponding transition state901_thread_in_vm = 6, // running in VM902_thread_in_vm_trans = 7, // corresponding transition state903_thread_in_Java = 8, // running in Java or in stub code904_thread_in_Java_trans = 9, // corresponding transition state (not used, included for completness)905_thread_blocked = 10, // blocked in vm906_thread_blocked_trans = 11, // corresponding transition state907_thread_max_state = 12 // maximum thread state+1 - used for statistics allocation908};909910911// Handy constants for deciding which compiler mode to use.912enum MethodCompilation {913InvocationEntryBci = -1, // i.e., not a on-stack replacement compilation914InvalidOSREntryBci = -2915};916917// Enumeration to distinguish tiers of compilation918enum CompLevel {919CompLevel_any = -1,920CompLevel_all = -1,921CompLevel_none = 0, // Interpreter922CompLevel_simple = 1, // C1923CompLevel_limited_profile = 2, // C1, invocation & backedge counters924CompLevel_full_profile = 3, // C1, invocation & backedge counters + mdo925CompLevel_full_optimization = 4, // C2 or Shark926927#if defined(COMPILER2) || defined(SHARK)928CompLevel_highest_tier = CompLevel_full_optimization, // pure C2 and tiered929#elif defined(COMPILER1)930CompLevel_highest_tier = CompLevel_simple, // pure C1931#else932CompLevel_highest_tier = CompLevel_none,933#endif934935#if defined(TIERED)936CompLevel_initial_compile = CompLevel_full_profile // tiered937#elif defined(COMPILER1)938CompLevel_initial_compile = CompLevel_simple // pure C1939#elif defined(COMPILER2) || defined(SHARK)940CompLevel_initial_compile = CompLevel_full_optimization // pure C2941#else942CompLevel_initial_compile = CompLevel_none943#endif944};945946inline bool is_c1_compile(int comp_level) {947return comp_level > CompLevel_none && comp_level < CompLevel_full_optimization;948}949950inline bool is_c2_compile(int comp_level) {951return comp_level == CompLevel_full_optimization;952}953954inline bool is_highest_tier_compile(int comp_level) {955return comp_level == CompLevel_highest_tier;956}957958inline bool is_compile(int comp_level) {959return is_c1_compile(comp_level) || is_c2_compile(comp_level);960}961962//----------------------------------------------------------------------------------------------------963// 'Forward' declarations of frequently used classes964// (in order to reduce interface dependencies & reduce965// number of unnecessary compilations after changes)966967class symbolTable;968class ClassFileStream;969970class Event;971972class Thread;973class VMThread;974class JavaThread;975class Threads;976977class VM_Operation;978class VMOperationQueue;979980class CodeBlob;981class nmethod;982class OSRAdapter;983class I2CAdapter;984class C2IAdapter;985class CompiledIC;986class relocInfo;987class ScopeDesc;988class PcDesc;989990class Recompiler;991class Recompilee;992class RecompilationPolicy;993class RFrame;994class CompiledRFrame;995class InterpretedRFrame;996997class frame;998999class vframe;1000class javaVFrame;1001class interpretedVFrame;1002class compiledVFrame;1003class deoptimizedVFrame;1004class externalVFrame;1005class entryVFrame;10061007class RegisterMap;10081009class Mutex;1010class Monitor;1011class BasicLock;1012class BasicObjectLock;10131014class PeriodicTask;10151016class JavaCallWrapper;10171018class oopDesc;1019class metaDataOopDesc;10201021class NativeCall;10221023class zone;10241025class StubQueue;10261027class outputStream;10281029class ResourceArea;10301031class DebugInformationRecorder;1032class ScopeValue;1033class CompressedStream;1034class DebugInfoReadStream;1035class DebugInfoWriteStream;1036class LocationValue;1037class ConstantValue;1038class IllegalValue;10391040class PrivilegedElement;1041class MonitorArray;10421043class MonitorInfo;10441045class OffsetClosure;1046class OopMapCache;1047class InterpreterOopMap;1048class OopMapCacheEntry;1049class OSThread;10501051typedef int (*OSThreadStartFunc)(void*);10521053class Space;10541055class JavaValue;1056class methodHandle;1057class JavaCallArguments;10581059// Basic support for errors (general debug facilities not defined at this point fo the include phase)10601061extern void basic_fatal(const char* msg);106210631064//----------------------------------------------------------------------------------------------------1065// Special constants for debugging10661067const jint badInt = -3; // generic "bad int" value1068const intptr_t badAddressVal = -2; // generic "bad address" value1069const intptr_t badOopVal = -1; // generic "bad oop" value1070const intptr_t badHeapOopVal = (intptr_t) CONST64(0x2BAD4B0BBAADBABE); // value used to zap heap after GC1071const int badStackSegVal = 0xCA; // value used to zap stack segments1072const int badHandleValue = 0xBC; // value used to zap vm handle area1073const int badResourceValue = 0xAB; // value used to zap resource area1074const int freeBlockPad = 0xBA; // value used to pad freed blocks.1075const int uninitBlockPad = 0xF1; // value used to zap newly malloc'd blocks.1076const intptr_t badJNIHandleVal = (intptr_t) CONST64(0xFEFEFEFEFEFEFEFE); // value used to zap jni handle area1077const juint badHeapWordVal = 0xBAADBABE; // value used to zap heap after GC1078const juint badMetaWordVal = 0xBAADFADE; // value used to zap metadata heap after GC1079const int badCodeHeapNewVal= 0xCC; // value used to zap Code heap at allocation1080const int badCodeHeapFreeVal = 0xDD; // value used to zap Code heap at deallocation108110821083// (These must be implemented as #defines because C++ compilers are1084// not obligated to inline non-integral constants!)1085#define badAddress ((address)::badAddressVal)1086#define badOop (cast_to_oop(::badOopVal))1087#define badHeapWord (::badHeapWordVal)1088#define badJNIHandle (cast_to_oop(::badJNIHandleVal))10891090// Default TaskQueue size is 16K (32-bit) or 128K (64-bit)1091#define TASKQUEUE_SIZE (NOT_LP64(1<<14) LP64_ONLY(1<<17))10921093//----------------------------------------------------------------------------------------------------1094// Utility functions for bitfield manipulations10951096const intptr_t AllBits = ~0; // all bits set in a word1097const intptr_t NoBits = 0; // no bits set in a word1098const jlong NoLongBits = 0; // no bits set in a long1099const intptr_t OneBit = 1; // only right_most bit set in a word11001101// get a word with the n.th or the right-most or left-most n bits set1102// (note: #define used only so that they can be used in enum constant definitions)1103#define nth_bit(n) (n >= BitsPerWord ? 0 : OneBit << (n))1104#define right_n_bits(n) (nth_bit(n) - 1)1105#define left_n_bits(n) (right_n_bits(n) << (n >= BitsPerWord ? 0 : (BitsPerWord - n)))11061107// bit-operations using a mask m1108inline void set_bits (intptr_t& x, intptr_t m) { x |= m; }1109inline void clear_bits (intptr_t& x, intptr_t m) { x &= ~m; }1110inline intptr_t mask_bits (intptr_t x, intptr_t m) { return x & m; }1111inline jlong mask_long_bits (jlong x, jlong m) { return x & m; }1112inline bool mask_bits_are_true (intptr_t flags, intptr_t mask) { return (flags & mask) == mask; }11131114// bit-operations using the n.th bit1115inline void set_nth_bit(intptr_t& x, int n) { set_bits (x, nth_bit(n)); }1116inline void clear_nth_bit(intptr_t& x, int n) { clear_bits(x, nth_bit(n)); }1117inline bool is_set_nth_bit(intptr_t x, int n) { return mask_bits (x, nth_bit(n)) != NoBits; }11181119// returns the bitfield of x starting at start_bit_no with length field_length (no sign-extension!)1120inline intptr_t bitfield(intptr_t x, int start_bit_no, int field_length) {1121return mask_bits(x >> start_bit_no, right_n_bits(field_length));1122}112311241125//----------------------------------------------------------------------------------------------------1126// Utility functions for integers11271128// Avoid use of global min/max macros which may cause unwanted double1129// evaluation of arguments.1130#ifdef max1131#undef max1132#endif11331134#ifdef min1135#undef min1136#endif11371138#define max(a,b) Do_not_use_max_use_MAX2_instead1139#define min(a,b) Do_not_use_min_use_MIN2_instead11401141// It is necessary to use templates here. Having normal overloaded1142// functions does not work because it is necessary to provide both 32-1143// and 64-bit overloaded functions, which does not work, and having1144// explicitly-typed versions of these routines (i.e., MAX2I, MAX2L)1145// will be even more error-prone than macros.1146template<class T> inline T MAX2(T a, T b) { return (a > b) ? a : b; }1147template<class T> inline T MIN2(T a, T b) { return (a < b) ? a : b; }1148template<class T> inline T MAX3(T a, T b, T c) { return MAX2(MAX2(a, b), c); }1149template<class T> inline T MIN3(T a, T b, T c) { return MIN2(MIN2(a, b), c); }1150template<class T> inline T MAX4(T a, T b, T c, T d) { return MAX2(MAX3(a, b, c), d); }1151template<class T> inline T MIN4(T a, T b, T c, T d) { return MIN2(MIN3(a, b, c), d); }11521153template<class T> inline T ABS(T x) { return (x > 0) ? x : -x; }11541155// true if x is a power of 2, false otherwise1156inline bool is_power_of_2(intptr_t x) {1157return ((x != NoBits) && (mask_bits(x, x - 1) == NoBits));1158}11591160// long version of is_power_of_21161inline bool is_power_of_2_long(jlong x) {1162return ((x != NoLongBits) && (mask_long_bits(x, x - 1) == NoLongBits));1163}11641165//* largest i such that 2^i <= x1166// A negative value of 'x' will return '31'1167inline int log2_intptr(uintptr_t x) {1168int i = -1;1169uintptr_t p = 1;1170while (p != 0 && p <= x) {1171// p = 2^(i+1) && p <= x (i.e., 2^(i+1) <= x)1172i++; p *= 2;1173}1174// p = 2^(i+1) && x < p (i.e., 2^i <= x < 2^(i+1))1175// (if p = 0 then overflow occurred and i = 31)1176return i;1177}11781179//* largest i such that 2^i <= x1180inline int log2_long(julong x) {1181int i = -1;1182julong p = 1;1183while (p != 0 && p <= x) {1184// p = 2^(i+1) && p <= x (i.e., 2^(i+1) <= x)1185i++; p *= 2;1186}1187// p = 2^(i+1) && x < p (i.e., 2^i <= x < 2^(i+1))1188// (if p = 0 then overflow occurred and i = 63)1189return i;1190}11911192inline int log2_intptr(intptr_t x) {1193return log2_intptr((uintptr_t)x);1194}11951196inline int log2_int(int x) {1197return log2_intptr((uintptr_t)x);1198}11991200inline int log2_jint(jint x) {1201return log2_intptr((uintptr_t)x);1202}12031204inline int log2_uint(uint x) {1205return log2_intptr((uintptr_t)x);1206}12071208// A negative value of 'x' will return '63'1209inline int log2_jlong(jlong x) {1210return log2_long((julong)x);1211}12121213//* the argument must be exactly a power of 21214inline int exact_log2(intptr_t x) {1215#ifdef ASSERT1216if (!is_power_of_2(x)) basic_fatal("x must be a power of 2");1217#endif1218return log2_intptr(x);1219}12201221//* the argument must be exactly a power of 21222inline int exact_log2_long(jlong x) {1223#ifdef ASSERT1224if (!is_power_of_2_long(x)) basic_fatal("x must be a power of 2");1225#endif1226return log2_long(x);1227}122812291230// returns integer round-up to the nearest multiple of s (s must be a power of two)1231inline intptr_t round_to(intptr_t x, uintx s) {1232#ifdef ASSERT1233if (!is_power_of_2(s)) basic_fatal("s must be a power of 2");1234#endif1235const uintx m = s - 1;1236return mask_bits(x + m, ~m);1237}12381239// returns integer round-down to the nearest multiple of s (s must be a power of two)1240inline intptr_t round_down(intptr_t x, uintx s) {1241#ifdef ASSERT1242if (!is_power_of_2(s)) basic_fatal("s must be a power of 2");1243#endif1244const uintx m = s - 1;1245return mask_bits(x, ~m);1246}124712481249inline bool is_odd (intx x) { return x & 1; }1250inline bool is_even(intx x) { return !is_odd(x); }12511252// abs methods which cannot overflow and so are well-defined across1253// the entire domain of integer types.1254static inline unsigned int uabs(unsigned int n) {1255union {1256unsigned int result;1257int value;1258};1259result = n;1260if (value < 0) result = 0-result;1261return result;1262}1263static inline julong uabs(julong n) {1264union {1265julong result;1266jlong value;1267};1268result = n;1269if (value < 0) result = 0-result;1270return result;1271}1272static inline julong uabs(jlong n) { return uabs((julong)n); }1273static inline unsigned int uabs(int n) { return uabs((unsigned int)n); }12741275// "to" should be greater than "from."1276inline intx byte_size(void* from, void* to) {1277return (address)to - (address)from;1278}12791280//----------------------------------------------------------------------------------------------------1281// Avoid non-portable casts with these routines (DEPRECATED)12821283// NOTE: USE Bytes class INSTEAD WHERE POSSIBLE1284// Bytes is optimized machine-specifically and may be much faster then the portable routines below.12851286// Given sequence of four bytes, build into a 32-bit word1287// following the conventions used in class files.1288// On the 386, this could be realized with a simple address cast.1289//12901291// This routine takes eight bytes:1292inline u8 build_u8_from( u1 c1, u1 c2, u1 c3, u1 c4, u1 c5, u1 c6, u1 c7, u1 c8 ) {1293return (( u8(c1) << 56 ) & ( u8(0xff) << 56 ))1294| (( u8(c2) << 48 ) & ( u8(0xff) << 48 ))1295| (( u8(c3) << 40 ) & ( u8(0xff) << 40 ))1296| (( u8(c4) << 32 ) & ( u8(0xff) << 32 ))1297| (( u8(c5) << 24 ) & ( u8(0xff) << 24 ))1298| (( u8(c6) << 16 ) & ( u8(0xff) << 16 ))1299| (( u8(c7) << 8 ) & ( u8(0xff) << 8 ))1300| (( u8(c8) << 0 ) & ( u8(0xff) << 0 ));1301}13021303// This routine takes four bytes:1304inline u4 build_u4_from( u1 c1, u1 c2, u1 c3, u1 c4 ) {1305return (( u4(c1) << 24 ) & 0xff000000)1306| (( u4(c2) << 16 ) & 0x00ff0000)1307| (( u4(c3) << 8 ) & 0x0000ff00)1308| (( u4(c4) << 0 ) & 0x000000ff);1309}13101311// And this one works if the four bytes are contiguous in memory:1312inline u4 build_u4_from( u1* p ) {1313return build_u4_from( p[0], p[1], p[2], p[3] );1314}13151316// Ditto for two-byte ints:1317inline u2 build_u2_from( u1 c1, u1 c2 ) {1318return u2((( u2(c1) << 8 ) & 0xff00)1319| (( u2(c2) << 0 ) & 0x00ff));1320}13211322// And this one works if the two bytes are contiguous in memory:1323inline u2 build_u2_from( u1* p ) {1324return build_u2_from( p[0], p[1] );1325}13261327// Ditto for floats:1328inline jfloat build_float_from( u1 c1, u1 c2, u1 c3, u1 c4 ) {1329u4 u = build_u4_from( c1, c2, c3, c4 );1330return *(jfloat*)&u;1331}13321333inline jfloat build_float_from( u1* p ) {1334u4 u = build_u4_from( p );1335return *(jfloat*)&u;1336}133713381339// now (64-bit) longs13401341inline jlong build_long_from( u1 c1, u1 c2, u1 c3, u1 c4, u1 c5, u1 c6, u1 c7, u1 c8 ) {1342return (( jlong(c1) << 56 ) & ( jlong(0xff) << 56 ))1343| (( jlong(c2) << 48 ) & ( jlong(0xff) << 48 ))1344| (( jlong(c3) << 40 ) & ( jlong(0xff) << 40 ))1345| (( jlong(c4) << 32 ) & ( jlong(0xff) << 32 ))1346| (( jlong(c5) << 24 ) & ( jlong(0xff) << 24 ))1347| (( jlong(c6) << 16 ) & ( jlong(0xff) << 16 ))1348| (( jlong(c7) << 8 ) & ( jlong(0xff) << 8 ))1349| (( jlong(c8) << 0 ) & ( jlong(0xff) << 0 ));1350}13511352inline jlong build_long_from( u1* p ) {1353return build_long_from( p[0], p[1], p[2], p[3], p[4], p[5], p[6], p[7] );1354}135513561357// Doubles, too!1358inline jdouble build_double_from( u1 c1, u1 c2, u1 c3, u1 c4, u1 c5, u1 c6, u1 c7, u1 c8 ) {1359jlong u = build_long_from( c1, c2, c3, c4, c5, c6, c7, c8 );1360return *(jdouble*)&u;1361}13621363inline jdouble build_double_from( u1* p ) {1364jlong u = build_long_from( p );1365return *(jdouble*)&u;1366}136713681369// Portable routines to go the other way:13701371inline void explode_short_to( u2 x, u1& c1, u1& c2 ) {1372c1 = u1(x >> 8);1373c2 = u1(x);1374}13751376inline void explode_short_to( u2 x, u1* p ) {1377explode_short_to( x, p[0], p[1]);1378}13791380inline void explode_int_to( u4 x, u1& c1, u1& c2, u1& c3, u1& c4 ) {1381c1 = u1(x >> 24);1382c2 = u1(x >> 16);1383c3 = u1(x >> 8);1384c4 = u1(x);1385}13861387inline void explode_int_to( u4 x, u1* p ) {1388explode_int_to( x, p[0], p[1], p[2], p[3]);1389}139013911392// Pack and extract shorts to/from ints:13931394inline int extract_low_short_from_int(jint x) {1395return x & 0xffff;1396}13971398inline int extract_high_short_from_int(jint x) {1399return (x >> 16) & 0xffff;1400}14011402inline int build_int_from_shorts( jushort low, jushort high ) {1403return ((int)((unsigned int)high << 16) | (unsigned int)low);1404}14051406// Convert pointer to intptr_t, for use in printing pointers.1407inline intptr_t p2i(const void * p) {1408return (intptr_t) p;1409}14101411// Printf-style formatters for fixed- and variable-width types as pointers and1412// integers. These are derived from the definitions in inttypes.h. If the platform1413// doesn't provide appropriate definitions, they should be provided in1414// the compiler-specific definitions file (e.g., globalDefinitions_gcc.hpp)14151416#define BOOL_TO_STR(_b_) ((_b_) ? "true" : "false")14171418// Format 32-bit quantities.1419#define INT32_FORMAT "%" PRId321420#define UINT32_FORMAT "%" PRIu321421#define INT32_FORMAT_W(width) "%" #width PRId321422#define UINT32_FORMAT_W(width) "%" #width PRIu3214231424#define PTR32_FORMAT "0x%08" PRIx3214251426// Format 64-bit quantities.1427#define INT64_FORMAT "%" PRId641428#define UINT64_FORMAT "%" PRIu641429#define UINT64_FORMAT_X "%" PRIx641430#define INT64_FORMAT_W(width) "%" #width PRId641431#define UINT64_FORMAT_W(width) "%" #width PRIu6414321433#define PTR64_FORMAT "0x%016" PRIx6414341435// Format jlong, if necessary1436#ifndef JLONG_FORMAT1437#define JLONG_FORMAT INT64_FORMAT1438#endif1439#ifndef JULONG_FORMAT1440#define JULONG_FORMAT UINT64_FORMAT1441#endif14421443// Format pointers which change size between 32- and 64-bit.1444#ifdef _LP641445#define INTPTR_FORMAT "0x%016" PRIxPTR1446#define PTR_FORMAT "0x%016" PRIxPTR1447#else // !_LP641448#define INTPTR_FORMAT "0x%08" PRIxPTR1449#define PTR_FORMAT "0x%08" PRIxPTR1450#endif // _LP6414511452#define INTPTR_FORMAT_W(width) "%" #width PRIxPTR14531454#define SSIZE_FORMAT "%" PRIdPTR1455#define SIZE_FORMAT "%" PRIuPTR1456#define SIZE_FORMAT_HEX "0x%" PRIxPTR1457#define SSIZE_FORMAT_W(width) "%" #width PRIdPTR1458#define SIZE_FORMAT_W(width) "%" #width PRIuPTR1459#define SIZE_FORMAT_HEX_W(width) "0x%" #width PRIxPTR14601461#define INTX_FORMAT "%" PRIdPTR1462#define UINTX_FORMAT "%" PRIuPTR1463#define INTX_FORMAT_W(width) "%" #width PRIdPTR1464#define UINTX_FORMAT_W(width) "%" #width PRIuPTR146514661467// Enable zap-a-lot if in debug version.14681469# ifdef ASSERT1470# ifdef COMPILER21471# define ENABLE_ZAP_DEAD_LOCALS1472#endif /* COMPILER2 */1473# endif /* ASSERT */14741475#define ARRAY_SIZE(array) (sizeof(array)/sizeof((array)[0]))14761477//----------------------------------------------------------------------------------------------------1478// Sum and product which can never overflow: they wrap, just like the1479// Java operations. Note that we don't intend these to be used for1480// general-purpose arithmetic: their purpose is to emulate Java1481// operations.14821483// The goal of this code to avoid undefined or implementation-defined1484// behaviour. The use of an lvalue to reference cast is explicitly1485// permitted by Lvalues and rvalues [basic.lval]. [Section 3.10 Para1486// 15 in C++03]1487#define JAVA_INTEGER_OP(OP, NAME, TYPE, UNSIGNED_TYPE) \1488inline TYPE NAME (TYPE in1, TYPE in2) { \1489UNSIGNED_TYPE ures = static_cast<UNSIGNED_TYPE>(in1); \1490ures OP ## = static_cast<UNSIGNED_TYPE>(in2); \1491return reinterpret_cast<TYPE&>(ures); \1492}14931494JAVA_INTEGER_OP(+, java_add, jint, juint)1495JAVA_INTEGER_OP(-, java_subtract, jint, juint)1496JAVA_INTEGER_OP(*, java_multiply, jint, juint)1497JAVA_INTEGER_OP(+, java_add, jlong, julong)1498JAVA_INTEGER_OP(-, java_subtract, jlong, julong)1499JAVA_INTEGER_OP(*, java_multiply, jlong, julong)15001501#undef JAVA_INTEGER_OP15021503// Dereference vptr1504// All C++ compilers that we know of have the vtbl pointer in the first1505// word. If there are exceptions, this function needs to be made compiler1506// specific.1507static inline void* dereference_vptr(const void* addr) {1508return *(void**)addr;1509}15101511#ifndef PRODUCT15121513// For unit testing only1514class GlobalDefinitions {1515public:1516static void test_globals();1517static void test_proper_unit();1518};15191520#endif // PRODUCT15211522#endif // SHARE_VM_UTILITIES_GLOBALDEFINITIONS_HPP152315241525