globalDefinitions.hpp revision 1311
/*
* Copyright 1997-2009 Sun Microsystems, Inc. All Rights Reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
* CA 95054 USA or visit www.sun.com if you need additional information or
* have any questions.
*
*/
// This file holds all globally used constants & types, class (forward)
// declarations and a few frequently used utility functions.
//----------------------------------------------------------------------------------------------------
// Constants
const int LogBytesPerShort = 1;
const int LogBytesPerInt = 2;
#ifdef _LP64
const int LogBytesPerWord = 3;
#else
const int LogBytesPerWord = 2;
#endif
const int LogBytesPerLong = 3;
const int LogBitsPerByte = 3;
const int oopSize = sizeof(char*); // Full-width oop
extern int heapOopSize; // Oop within a java object
const int wordSize = sizeof(char*);
const int size_tSize = sizeof(size_t);
extern int LogBytesPerHeapOop; // Oop within a java object
extern int LogBitsPerHeapOop;
extern int BytesPerHeapOop;
extern int BitsPerHeapOop;
const int BitsPerJavaInteger = 32;
const int BitsPerJavaLong = 64;
// Size of a char[] needed to represent a jint as a string in decimal.
const int jintAsStringSize = 12;
// In fact this should be
// log2_intptr(sizeof(class JavaThread)) - log2_intptr(64);
// see os::set_memory_serialize_page()
#ifdef _LP64
const int SerializePageShiftCount = 4;
#else
const int SerializePageShiftCount = 3;
#endif
// An opaque struct of heap-word width, so that HeapWord* can be a generic
// pointer into the heap. We require that object sizes be measured in
// units of heap words, so that that
// HeapWord* hw;
// hw += oop(hw)->foo();
// works, where foo is a method (like size or scavenge) that returns the
// object size.
class HeapWord {
friend class VMStructs;
private:
char* i;
#ifndef PRODUCT
public:
char* value() { return i; }
#endif
};
// HeapWordSize must be 2^LogHeapWordSize.
const int HeapWordSize = sizeof(HeapWord);
#ifdef _LP64
const int LogHeapWordSize = 3;
#else
const int LogHeapWordSize = 2;
#endif
// The larger HeapWordSize for 64bit requires larger heaps
// for the same application running in 64bit. See bug 4967770.
// The minimum alignment to a heap word size is done. Other
// parts of the memory system may required additional alignment
// and are responsible for those alignments.
#ifdef _LP64
#else
#define ScaleForWordSize(x) (x)
#endif
// The minimum number of native machine words necessary to contain "byte_size"
// bytes.
}
const size_t K = 1024;
const size_t M = K*K;
const size_t G = M*K;
// Constants for converting from a base unit to milli-base units. For
// example from seconds to milliseconds and microseconds
inline const char* proper_unit_for_byte_size(size_t s) {
if (s >= 10*M) {
return "M";
} else if (s >= 10*K) {
return "K";
} else {
return "B";
}
}
if (s >= 10*M) {
return s/M;
} else if (s >= 10*K) {
return s/K;
} else {
return s;
}
}
//----------------------------------------------------------------------------------------------------
// VM type definitions
// intx and uintx are the 'extended' int and 'extended' unsigned int types;
// they are 32bit wide on a 32-bit platform, and 64bit wide on a 64bit platform.
// Table of values:
// sizeof intx 4 8
// min_intx 0x80000000 0x8000000000000000
// max_intx 0x7FFFFFFF 0x7FFFFFFFFFFFFFFF
// max_uintx 0xFFFFFFFF 0xFFFFFFFFFFFFFFFF
typedef unsigned int uint; NEEDS_CLEANUP
//----------------------------------------------------------------------------------------------------
// Java type definitions
// All kinds of 'plain' byte addresses
typedef signed char s_char;
typedef unsigned char u_char;
// except for some implementations of a C++
// linkage pointer to function. Should never
// need one of those to be placed in this
// type anyway.
// Utility functions to "portably" (?) bit twiddle pointers
// Where portable means keep ANSI C++ compilers quiet
// Pointer subtraction.
// The idea here is to avoid ptrdiff_t, which is signed and so doesn't have
// the range we might need to find differences from one end of the heap
// to the other.
// A typical use might be:
// if (pointer_delta(end(), top()) >= size) {
// // enough room for an object of size
// ...
// and then additions like
// ... top() + size ...
// are safe because we know that top() is at least size below end().
const void* right,
}
// A version specialized for HeapWord*'s.
}
//
// ANSI C++ does not allow casting from one pointer type to a function pointer
// directly without at best a warning. This macro accomplishes it silently
// In every case that is present at this point the value be cast is a pointer
// to a C linkage function. In somecase the type used for the cast reflects
// that linkage and a picky compiler would not complain. In other cases because
// there is no convenient place to place a typedef with extern C linkage (i.e
// a platform dependent header file) it doesn't. At this point no compiler seems
// picky enough to catch these instances (which are few). It is possible that
// using templates could fix these for all cases. This use of templates is likely
// so far from the middle of the road that it is likely to be problematic in
// many C++ compilers.
//
// Unsigned byte types for os and stream.hpp
// Unsigned one, two, four and eigth byte quantities used for describing
// the .class file format. See JVM book chapter 4.
//----------------------------------------------------------------------------------------------------
// JVM spec restrictions
//----------------------------------------------------------------------------------------------------
// HotSwap - for JVMTI aka Class File Replacement and PopFrame
//
// Determines whether on-the-fly class replacement and frame popping are enabled.
#define HOTSWAP
//----------------------------------------------------------------------------------------------------
// Object alignment, in units of HeapWords.
//
// Minimum is max(BytesPerLong, BytesPerDouble, BytesPerOop) / HeapWordSize, so jlong, jdouble and
// reference fields can be naturally aligned.
const int MinObjAlignment = HeapWordsPerLong;
const int LogMinObjAlignment = LogHeapWordsPerLong;
// Machine dependent stuff
#include "incls/_globalDefinitions_pd.hpp.incl"
// The byte alignment to be used by Arena::Amalloc. See bugid 4169348.
// Note: this value must be a power of 2
// Signed variants of alignment helpers. There are two versions of each, a macro
// for use in places like enum definitions that require compile-time constant
// expressions and a function for all other places so as to get type checking.
}
}
// Align objects by rounding up their size, in HeapWord units.
}
// Pad out certain offsets to jlong alignment, in HeapWord units.
}
}
//----------------------------------------------------------------------------------------------------
// Utility macros for compilers
// used to silence compiler warnings
//----------------------------------------------------------------------------------------------------
// Miscellaneous
// 6302670 Eliminate Hotspot __fabsf dependency
// All fabs() callers should call this function instead, which will implicitly
// convert the operand to double, avoiding a dependency on __fabsf which
// doesn't exist in early versions of Solaris 8.
}
// the fancy casts are a hopefully portable way
// to do unsigned 32 to 64 bit type conversion
return result;
}
union jlong_accessor {
};
void basic_types_init(); // cannot define here; uses assert
enum BasicType {
T_BOOLEAN = 4,
T_CHAR = 5,
T_FLOAT = 6,
T_DOUBLE = 7,
T_BYTE = 8,
T_SHORT = 9,
T_INT = 10,
T_LONG = 11,
T_OBJECT = 12,
T_ARRAY = 13,
T_VOID = 14,
T_ADDRESS = 15,
T_NARROWOOP= 16,
T_ILLEGAL = 99
};
inline bool is_java_primitive(BasicType t) {
}
inline bool is_subword_type(BasicType t) {
// these guys are processed exactly like T_INT in calling sequences:
}
inline bool is_signed_subword_type(BasicType t) {
}
// Convert a char from a classfile signature to a BasicType
switch( c ) {
case 'B': return T_BYTE;
case 'C': return T_CHAR;
case 'D': return T_DOUBLE;
case 'F': return T_FLOAT;
case 'I': return T_INT;
case 'J': return T_LONG;
case 'S': return T_SHORT;
case 'Z': return T_BOOLEAN;
case 'V': return T_VOID;
case 'L': return T_OBJECT;
case '[': return T_ARRAY;
}
return T_ILLEGAL;
}
inline const char* type2name(BasicType t) { return (uint)t < T_CONFLICT+1 ? type2name_tab[t] : NULL; }
// Auxilary math routines
// least common multiple
enum BasicTypeSize {
T_BOOLEAN_size = 1,
T_CHAR_size = 1,
T_FLOAT_size = 1,
T_DOUBLE_size = 2,
T_BYTE_size = 1,
T_SHORT_size = 1,
T_INT_size = 1,
T_LONG_size = 2,
T_OBJECT_size = 1,
T_ARRAY_size = 1,
T_NARROWOOP_size = 1,
T_VOID_size = 0
};
// maps a BasicType to its instance field storage type:
// all sub-word integral types are widened to T_INT
// size in bytes
enum ArrayElementSize {
T_CHAR_aelem_bytes = 2,
T_FLOAT_aelem_bytes = 4,
T_DOUBLE_aelem_bytes = 8,
T_BYTE_aelem_bytes = 1,
T_SHORT_aelem_bytes = 2,
T_INT_aelem_bytes = 4,
T_LONG_aelem_bytes = 8,
#ifdef _LP64
T_OBJECT_aelem_bytes = 8,
T_ARRAY_aelem_bytes = 8,
#else
T_OBJECT_aelem_bytes = 4,
T_ARRAY_aelem_bytes = 4,
#endif
};
extern int _type2aelembytes[T_CONFLICT+1]; // maps a BasicType to nof bytes used by its array element
#ifdef ASSERT
#else
#endif
// JavaValue serves as a container for arbitrary Java values.
class JavaValue {
public:
typedef union JavaCallValue {
jfloat f;
jdouble d;
jint i;
jlong l;
jobject h;
private:
public:
}
}
};
#define STACK_BIAS 0
// V9 Sparc CPU's running in 64 Bit mode use a stack bias of 7ff
// in order to extend the reach of the stack pointer.
#define STACK_BIAS 0x7ff
#endif
// TosState describes the top-of-stack state before and after the execution of
// a bytecode or method. The top-of-stack value may be cached in one or more CPU
// registers. The TosState corresponds to the 'machine represention' of this cached
// value. There's 4 states corresponding to the JAVA types int, long, float & double
// as well as a 5th state in case the top-of-stack value is actually on the top
// of stack (in memory) and thus not cached. The atos state corresponds to the itos
// state when it comes to machine representation but is used separately for (oop)
// type specific operations (e.g. verification code).
enum TosState { // describes the tos cache contents
btos = 0, // byte, bool tos cached
ilgl // illegal state: should not occur
};
switch (type) {
case T_ARRAY : // fall through
}
return ilgl;
}
switch (state) {
//case ztos: return T_BOOLEAN;//FIXME
}
return T_ILLEGAL;
}
// Helper function to convert BasicType info into TosState
// Note: Cannot define here as it uses global constant at the time being.
enum ReferenceType {
REF_NONE, // Regular class
REF_SOFT, // Subclass of java/lang/ref/SoftReference
REF_WEAK, // Subclass of java/lang/ref/WeakReference
REF_FINAL, // Subclass of java/lang/ref/FinalReference
REF_PHANTOM // Subclass of java/lang/ref/PhantomReference
};
// JavaThreadState keeps track of which part of the code a thread is executing in. This
// information is needed by the safepoint code.
//
// There are 4 essential states:
//
// _thread_new : Just started, but not executed init. code yet (most likely still in OS init code)
// _thread_in_native : In native code. This is a safepoint region, since all oops will be in jobject handles
// _thread_in_vm : Executing in the vm
// _thread_in_Java : Executing either interpreted or compiled Java code (or could be in a stub)
//
// Each state has an associated xxxx_trans state, which is an intermediate state used when a thread is in
// a transition from one state to another. These extra states makes it possible for the safepoint code to
// handle certain thread_states without having to suspend the thread - making the safepoint code faster.
//
// Given a state, the xxx_trans state can always be found by adding 1.
//
enum JavaThreadState {
_thread_uninitialized = 0, // should never happen (missing initialization)
};
// Handy constants for deciding which compiler mode to use.
enum MethodCompilation {
InvalidOSREntryBci = -2
};
// Enumeration to distinguish tiers of compilation
enum CompLevel {
CompLevel_none = 0,
#ifdef TIERED
#else
#endif // TIERED
};
inline bool is_tier1_compile(int comp_level) {
return comp_level == CompLevel_fast_compile;
}
inline bool is_tier2_compile(int comp_level) {
return comp_level == CompLevel_full_optimization;
}
inline bool is_highest_tier_compile(int comp_level) {
return comp_level == CompLevel_highest_tier;
}
//----------------------------------------------------------------------------------------------------
// 'Forward' declarations of frequently used classes
// (in order to reduce interface dependencies & reduce
// number of unnecessary compilations after changes)
class symbolTable;
class ClassFileStream;
class Event;
class Thread;
class VMThread;
class JavaThread;
class Threads;
class VM_Operation;
class VMOperationQueue;
class CodeBlob;
class nmethod;
class OSRAdapter;
class I2CAdapter;
class C2IAdapter;
class CompiledIC;
class relocInfo;
class ScopeDesc;
class PcDesc;
class Recompiler;
class Recompilee;
class RecompilationPolicy;
class RFrame;
class CompiledRFrame;
class InterpretedRFrame;
class frame;
class vframe;
class javaVFrame;
class interpretedVFrame;
class compiledVFrame;
class deoptimizedVFrame;
class externalVFrame;
class entryVFrame;
class RegisterMap;
class Mutex;
class Monitor;
class BasicLock;
class BasicObjectLock;
class PeriodicTask;
class JavaCallWrapper;
class oopDesc;
class NativeCall;
class zone;
class StubQueue;
class outputStream;
class ResourceArea;
class DebugInformationRecorder;
class ScopeValue;
class CompressedStream;
class DebugInfoReadStream;
class DebugInfoWriteStream;
class LocationValue;
class ConstantValue;
class IllegalValue;
class PrivilegedElement;
class MonitorArray;
class MonitorInfo;
class OffsetClosure;
class OopMapCache;
class InterpreterOopMap;
class OopMapCacheEntry;
class OSThread;
typedef int (*OSThreadStartFunc)(void*);
class Space;
class JavaValue;
class methodHandle;
class JavaCallArguments;
// Basic support for errors (general debug facilities not defined at this point fo the include phase)
extern void basic_fatal(const char* msg);
//----------------------------------------------------------------------------------------------------
// Special constants for debugging
const intptr_t badHeapOopVal = (intptr_t) CONST64(0x2BAD4B0BBAADBABE); // value used to zap heap after GC
const intptr_t badJNIHandleVal = (intptr_t) CONST64(0xFEFEFEFEFEFEFEFE); // value used to zap jni handle area
// (These must be implemented as #defines because C++ compilers are
// not obligated to inline non-integral constants!)
#define badHeapWord (::badHeapWordVal)
// Default TaskQueue size is 16K (32-bit) or 128K (64-bit)
//----------------------------------------------------------------------------------------------------
// Utility functions for bitfield manipulations
// get a word with the n.th or the right-most or left-most n bits set
// (note: #define used only so that they can be used in enum constant definitions)
// bit-operations using a mask m
// bit-operations using the n.th bit
// returns the bitfield of x starting at start_bit_no with length field_length (no sign-extension!)
}
//----------------------------------------------------------------------------------------------------
// Utility functions for integers
// evaluation of arguments.
#ifdef max
#endif
#ifdef min
#endif
#define max(a,b) Do_not_use_max_use_MAX2_instead
#define min(a,b) Do_not_use_min_use_MIN2_instead
// It is necessary to use templates here. Having normal overloaded
// functions does not work because it is necessary to provide both 32-
// and 64-bit overloaded functions, which does not work, and having
// explicitly-typed versions of these routines (i.e., MAX2I, MAX2L)
// will be even more error-prone than macros.
template<class T> inline T MAX2(T a, T b) { return (a > b) ? a : b; }
template<class T> inline T MIN2(T a, T b) { return (a < b) ? a : b; }
template<class T> inline T ABS(T x) { return (x > 0) ? x : -x; }
// true if x is a power of 2, false otherwise
inline bool is_power_of_2(intptr_t x) {
}
// long version of is_power_of_2
inline bool is_power_of_2_long(jlong x) {
}
//* largest i such that 2^i <= x
// A negative value of 'x' will return '31'
inline int log2_intptr(intptr_t x) {
int i = -1;
uintptr_t p = 1;
while (p != 0 && p <= (uintptr_t)x) {
// p = 2^(i+1) && p <= x (i.e., 2^(i+1) <= x)
i++; p *= 2;
}
// p = 2^(i+1) && x < p (i.e., 2^i <= x < 2^(i+1))
// (if p = 0 then overflow occurred and i = 31)
return i;
}
//* largest i such that 2^i <= x
// A negative value of 'x' will return '63'
int i = -1;
julong p = 1;
while (p != 0 && p <= (julong)x) {
// p = 2^(i+1) && p <= x (i.e., 2^(i+1) <= x)
i++; p *= 2;
}
// p = 2^(i+1) && x < p (i.e., 2^i <= x < 2^(i+1))
// (if p = 0 then overflow occurred and i = 63)
return i;
}
//* the argument must be exactly a power of 2
inline int exact_log2(intptr_t x) {
#ifdef ASSERT
#endif
return log2_intptr(x);
}
//* the argument must be exactly a power of 2
inline int exact_log2_long(jlong x) {
#ifdef ASSERT
#endif
return log2_long(x);
}
// returns integer round-up to the nearest multiple of s (s must be a power of two)
#ifdef ASSERT
#endif
const uintx m = s - 1;
return mask_bits(x + m, ~m);
}
// returns integer round-down to the nearest multiple of s (s must be a power of two)
#ifdef ASSERT
#endif
const uintx m = s - 1;
return mask_bits(x, ~m);
}
// "to" should be greater than "from."
}
//----------------------------------------------------------------------------------------------------
// Avoid non-portable casts with these routines (DEPRECATED)
// NOTE: USE Bytes class INSTEAD WHERE POSSIBLE
// Bytes is optimized machine-specifically and may be much faster then the portable routines below.
// Given sequence of four bytes, build into a 32-bit word
// following the conventions used in class files.
// On the 386, this could be realized with a simple address cast.
//
// This routine takes eight bytes:
}
// This routine takes four bytes:
}
// And this one works if the four bytes are contiguous in memory:
}
// Ditto for two-byte ints:
}
// And this one works if the two bytes are contiguous in memory:
return build_u2_from( p[0], p[1] );
}
// Ditto for floats:
return *(jfloat*)&u;
}
u4 u = build_u4_from( p );
return *(jfloat*)&u;
}
// now (64-bit) longs
}
}
// Doubles, too!
return *(jdouble*)&u;
}
jlong u = build_long_from( p );
return *(jdouble*)&u;
}
// Portable routines to go the other way:
}
explode_short_to( x, p[0], p[1]);
}
}
}
inline int extract_low_short_from_int(jint x) {
return x & 0xffff;
}
inline int extract_high_short_from_int(jint x) {
return (x >> 16) & 0xffff;
}
}
// Printf-style formatters for fixed- and variable-width types as pointers and
// integers.
//
// Each compiler-specific definitions file (e.g., globalDefinitions_gcc.hpp)
// must define the macro FORMAT64_MODIFIER, which is the modifier for '%x' or
// '%d' formats to indicate a 64-bit quantity; commonly "l" (in LP64) or "ll"
// (in ILP32).
// Format 32-bit quantities.
#define INT32_FORMAT "%d"
#define UINT32_FORMAT "%u"
#define PTR32_FORMAT "0x%08x"
// Format 64-bit quantities.
// Format macros that allow the field width to be specified. The width must be
// a string literal (e.g., "8") or a macro that evaluates to one.
#ifdef _LP64
#else
#endif // _LP64
// Format pointers and size_t (or size_t-like integer types) which change size
// between 32- and 64-bit. The pointer format theoretically should be "%p",
// however, it has different output on different platforms. On Windows, the data
// will be padded with zeros automatically. On Solaris, we can use "%016p" &
// "%08p" on 64 bit & 32 bit platforms to make the data padded with extra zeros.
// On Linux, "%016p" or "%08p" is not be allowed, at least on the latest GCC
// 4.3.2. So we have to use "%016x" or "%08x" to simulate the printing format.
// GCC 4.3.2, however requires the data to be converted to "intptr_t" when
// using "%x".
#ifdef _LP64
#define PTR_FORMAT PTR64_FORMAT
#define UINTX_FORMAT UINT64_FORMAT
#define INTX_FORMAT INT64_FORMAT
#define SIZE_FORMAT UINT64_FORMAT
#define SSIZE_FORMAT INT64_FORMAT
#else // !_LP64
#define PTR_FORMAT PTR32_FORMAT
#define UINTX_FORMAT UINT32_FORMAT
#define INTX_FORMAT INT32_FORMAT
#define SIZE_FORMAT UINT32_FORMAT
#define SSIZE_FORMAT INT32_FORMAT
#endif // _LP64
#define INTPTR_FORMAT PTR_FORMAT
// Enable zap-a-lot if in debug version.
# ifdef ASSERT
# ifdef COMPILER2
# define ENABLE_ZAP_DEAD_LOCALS
#endif /* COMPILER2 */
# endif /* ASSERT */