/*
* 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 Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*
*/
#ifndef __STDC_FORMAT_MACROS
#define __STDC_FORMAT_MACROS
#endif
#ifdef TARGET_COMPILER_gcc
# include "utilities/globalDefinitions_gcc.hpp"
#endif
#ifdef TARGET_COMPILER_visCPP
# include "utilities/globalDefinitions_visCPP.hpp"
#endif
#ifdef TARGET_COMPILER_sparcWorks
# include "utilities/globalDefinitions_sparcWorks.hpp"
#endif
#include "utilities/macros.hpp"
// This file holds all globally used constants & types, class (forward)
// declarations and a few frequently used utility functions.
//----------------------------------------------------------------------------------------------------
// Constants
#ifdef _LP64
#else
#endif
extern int heapOopSize; // Oop within a java object
const int wordSize = sizeof(char*);
extern int LogBytesPerHeapOop; // Oop within a java object
extern int LogBitsPerHeapOop;
extern int BytesPerHeapOop;
extern int BitsPerHeapOop;
// Oop encoding heap max
extern uint64_t OopEncodingHeapMax;
// Size of a char[] needed to represent a jint as a string in decimal.
// In fact this should be
// log2_intptr(sizeof(class JavaThread)) - log2_intptr(64);
// see os::set_memory_serialize_page()
#ifdef _LP64
#else
#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.
#ifdef _LP64
#else
#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
#ifdef _LP64
if (s >= 10*G) {
return "G";
}
#endif
if (s >= 10*M) {
return "M";
} else if (s >= 10*K) {
return "K";
} else {
return "B";
}
}
template <class T>
inline T byte_size_in_proper_unit(T s) {
#ifdef _LP64
if (s >= 10*G) {
return (T)(s/G);
}
#endif
if (s >= 10*M) {
return (T)(s/M);
} else if (s >= 10*K) {
return (T)(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
//----------------------------------------------------------------------------------------------------
// 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.
extern int MinObjAlignment;
extern int MinObjAlignmentInBytes;
extern int MinObjAlignmentInBytesMask;
extern int LogMinObjAlignment;
extern int LogMinObjAlignmentInBytes;
// Machine dependent stuff
#ifdef TARGET_ARCH_x86
# include "globalDefinitions_x86.hpp"
#endif
#ifdef TARGET_ARCH_sparc
# include "globalDefinitions_sparc.hpp"
#endif
#ifdef TARGET_ARCH_zero
# include "globalDefinitions_zero.hpp"
#endif
#ifdef TARGET_ARCH_arm
# include "globalDefinitions_arm.hpp"
#endif
#ifdef TARGET_ARCH_ppc
# include "globalDefinitions_ppc.hpp"
#endif
// 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.
}
// The expected size in bytes of a cache line, used to pad data structures.
// Bytes needed to pad type to avoid cache-line sharing; alignment should be the
// expected cache line size (a power of two). The first addend avoids sharing
// when the start address is not a multiple of alignment; the second maintains
// alignment of starting addresses that happen to be a multiple.
// Templates to create a subclass padded to avoid cache line sharing. These are
// effective only when applied to derived-most (leaf) classes.
// When no args are passed to the base ctor.
class Padded: public T {
private:
};
// When either 0 or 1 args may be passed to the base ctor.
class Padded01: public T {
public:
Padded01(): T() { }
private:
};
//----------------------------------------------------------------------------------------------------
// 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 {
};
}
// these guys are processed exactly like T_INT in calling sequences:
}
}
// 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_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 {
#ifdef _LP64
#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.
#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).
};
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.
// 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 {
};
// Handy constants for deciding which compiler mode to use.
enum MethodCompilation {
};
// Enumeration to distinguish tiers of compilation
enum CompLevel {
#else
#endif
#if defined(TIERED)
#else
#endif
};
}
return comp_level == CompLevel_full_optimization;
}
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!)
// 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
// 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
}
// long version of is_power_of_2
}
//* largest i such that 2^i <= x
// A negative value of 'x' will return '31'
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
#ifdef ASSERT
#endif
return log2_intptr(x);
}
//* the argument must be exactly a power of 2
#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]);
}
}
}
return x & 0xffff;
}
return (x >> 16) & 0xffff;
}
}
// Printf-style formatters for fixed- and variable-width types as pointers and
// integers. These are derived from the definitions in inttypes.h. If the platform
// doesn't provide appropriate definitions, they should be provided in
// the compiler-specific definitions file (e.g., globalDefinitions_gcc.hpp)
// Format 32-bit quantities.
// Format 64-bit quantities.
// Format pointers which change size between 32- and 64-bit.
#ifdef _LP64
#else // !_LP64
#endif // _LP64
// Enable zap-a-lot if in debug version.
# ifdef ASSERT
# ifdef COMPILER2
# define ENABLE_ZAP_DEAD_LOCALS
#endif /* COMPILER2 */
# endif /* ASSERT */
#endif // SHARE_VM_UTILITIES_GLOBALDEFINITIONS_HPP