globalDefinitions.hpp revision 1709
2362N/A * Copyright (c) 1997, 2010, Oracle and/or its affiliates. All rights reserved. 0N/A * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 0N/A * This code is free software; you can redistribute it and/or modify it 0N/A * under the terms of the GNU General Public License version 2 only, as 2362N/A * published by the Free Software Foundation. 2362N/A * This code is distributed in the hope that it will be useful, but WITHOUT 0N/A * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 0N/A * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 0N/A * version 2 for more details (a copy is included in the LICENSE file that 0N/A * accompanied this code). 0N/A * You should have received a copy of the GNU General Public License version 0N/A * 2 along with this work; if not, write to the Free Software Foundation, 0N/A * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 0N/A * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 0N/A// This file holds all globally used constants & types, class (forward) 0N/A// declarations and a few frequently used utility functions. 0N/A//---------------------------------------------------------------------------------------------------- 0N/Aconst int oopSize =
sizeof(
char*);
// Full-width oop 0N/A// Oop encoding heap max 0N/A// Size of a char[] needed to represent a jint as a string in decimal. 0N/A// In fact this should be 0N/A// log2_intptr(sizeof(class JavaThread)) - log2_intptr(64); 0N/A// see os::set_memory_serialize_page() 0N/A// An opaque struct of heap-word width, so that HeapWord* can be a generic 0N/A// pointer into the heap. We require that object sizes be measured in 0N/A// units of heap words, so that that 0N/A// hw += oop(hw)->foo(); 0N/A// works, where foo is a method (like size or scavenge) that returns the 0N/A// HeapWordSize must be 2^LogHeapWordSize. 0N/A// The larger HeapWordSize for 64bit requires larger heaps 0N/A// for the same application running in 64bit. See bug 4967770. 0N/A// The minimum alignment to a heap word size is done. Other 0N/A// parts of the memory system may required additional alignment 0N/A// and are responsible for those alignments. 0N/A// The minimum number of native machine words necessary to contain "byte_size" 0N/A// Constants for converting from a base unit to milli-base units. For 0N/A// example from seconds to milliseconds and microseconds 0N/Aconst int NANOUNITS =
1000000000;
// nano units per base unit 0N/A }
else if (s >=
10*K) {
0N/A }
else if (s >=
10*K) {
0N/A//---------------------------------------------------------------------------------------------------- 0N/A// VM type definitions 0N/A// intx and uintx are the 'extended' int and 'extended' unsigned int types; 0N/A// they are 32bit wide on a 32-bit platform, and 64bit wide on a 64bit platform. 0N/A// min_intx 0x80000000 0x8000000000000000 0N/A// max_intx 0x7FFFFFFF 0x7FFFFFFFFFFFFFFF 0N/A// max_uintx 0xFFFFFFFF 0xFFFFFFFFFFFFFFFF 0N/A//---------------------------------------------------------------------------------------------------- 0N/A// Java type definitions 0N/A// All kinds of 'plain' byte addresses 0N/A // except for some implementations of a C++ 0N/A // linkage pointer to function. Should never 0N/A // need one of those to be placed in this 0N/A// Utility functions to "portably" (?) bit twiddle pointers 0N/A// Where portable means keep ANSI C++ compilers quiet 0N/A// Utility functions to "portably" make cast to/from function pointers. 0N/A// Pointer subtraction. 0N/A// The idea here is to avoid ptrdiff_t, which is signed and so doesn't have 0N/A// the range we might need to find differences from one end of the heap 0N/A// A typical use might be: 0N/A// if (pointer_delta(end(), top()) >= size) { 0N/A// // enough room for an object of size 0N/A// and then additions like 0N/A// ... top() + size ... 0N/A// are safe because we know that top() is at least size below end(). 0N/A// A version specialized for HeapWord*'s. 0N/A// ANSI C++ does not allow casting from one pointer type to a function pointer 0N/A// directly without at best a warning. This macro accomplishes it silently 0N/A// In every case that is present at this point the value be cast is a pointer 0N/A// to a C linkage function. In somecase the type used for the cast reflects 0N/A// that linkage and a picky compiler would not complain. In other cases because 0N/A// there is no convenient place to place a typedef with extern C linkage (i.e 0N/A// a platform dependent header file) it doesn't. At this point no compiler seems 0N/A// picky enough to catch these instances (which are few). It is possible that 0N/A// using templates could fix these for all cases. This use of templates is likely 0N/A// so far from the middle of the road that it is likely to be problematic in 0N/A// many C++ compilers. 0N/A// Unsigned one, two, four and eigth byte quantities used for describing 0N/A// the .class file format. See JVM book chapter 4. 0N/A//---------------------------------------------------------------------------------------------------- 0N/A// JVM spec restrictions 0N/A//---------------------------------------------------------------------------------------------------- 0N/A// HotSwap - for JVMTI aka Class File Replacement and PopFrame 0N/A// Determines whether on-the-fly class replacement and frame popping are enabled. 0N/A//---------------------------------------------------------------------------------------------------- 0N/A// Object alignment, in units of HeapWords. 0N/A// Minimum is max(BytesPerLong, BytesPerDouble, BytesPerOop) / HeapWordSize, so jlong, jdouble and 0N/A// reference fields can be naturally aligned. 0N/A// Machine dependent stuff 0N/A// The byte alignment to be used by Arena::Amalloc. See bugid 4169348. 0N/A// Note: this value must be a power of 2 0N/A// Signed variants of alignment helpers. There are two versions of each, a macro 0N/A// for use in places like enum definitions that require compile-time constant 0N/A// expressions and a function for all other places so as to get type checking. 0N/A// Align objects by rounding up their size, in HeapWord units. 0N/A// Pad out certain offsets to jlong alignment, in HeapWord units. 0N/A// The expected size in bytes of a cache line, used to pad data structures. 0N/A// Bytes needed to pad type to avoid cache-line sharing; alignment should be the 0N/A// expected cache line size (a power of two). The first addend avoids sharing 0N/A// when the start address is not a multiple of alignment; the second maintains 0N/A// alignment of starting addresses that happen to be a multiple. 0N/A// Templates to create a subclass padded to avoid cache line sharing. These are 0N/A// effective only when applied to derived-most (leaf) classes. 0N/A// When no args are passed to the base ctor. 0N/A// When either 0 or 1 args may be passed to the base ctor. 0N/A//---------------------------------------------------------------------------------------------------- 0N/A// Utility macros for compilers 0N/A// used to silence compiler warnings 0N/A//---------------------------------------------------------------------------------------------------- 0N/A// 6302670 Eliminate Hotspot __fabsf dependency 0N/A// All fabs() callers should call this function instead, which will implicitly 0N/A// convert the operand to double, avoiding a dependency on __fabsf which 0N/A// doesn't exist in early versions of Solaris 8. 0N/A// the fancy casts are a hopefully portable way 0N/A// to do unsigned 32 to 64 bit type conversion 0N/A T_CONFLICT =
17,
// for stack value type with conflicting contents 0N/A // these guys are processed exactly like T_INT in calling sequences: 0N/A// Convert a char from a classfile signature to a BasicType 0N/A// Auxilary math routines 0N/A// least common multiple 0N/A// maps a BasicType to its instance field storage type: 0N/A// all sub-word integral types are widened to T_INT 0N/A// JavaValue serves as a container for arbitrary Java values. 0N/A// V9 Sparc CPU's running in 64 Bit mode use a stack bias of 7ff 0N/A// in order to extend the reach of the stack pointer. 0N/A// TosState describes the top-of-stack state before and after the execution of 0N/A// a bytecode or method. The top-of-stack value may be cached in one or more CPU 0N/A// registers. The TosState corresponds to the 'machine represention' of this cached 0N/A// value. There's 4 states corresponding to the JAVA types int, long, float & double 0N/A// as well as a 5th state in case the top-of-stack value is actually on the top 0N/A// of stack (in memory) and thus not cached. The atos state corresponds to the itos 0N/A// state when it comes to machine representation but is used separately for (oop) 0N/A// type specific operations (e.g. verification code). 0N/A ilgl // illegal state: should not occur 0N/A //case ztos: return T_BOOLEAN;//FIXME 0N/A// Helper function to convert BasicType info into TosState 0N/A// 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. _thread_new =
2,
// just starting up, i.e., in process of being initialized _thread_new_trans =
3,
// corresponding transition state (not used, included for completness) // Handy constants for deciding which compiler mode to use. // Enumeration to distinguish tiers of compilation //---------------------------------------------------------------------------------------------------- // 'Forward' declarations of frequently used classes // (in order to reduce interface dependencies & reduce // number of unnecessary compilations after changes) // Basic support for errors (general debug facilities not defined at this point fo the include phase) //---------------------------------------------------------------------------------------------------- // Special constants for debugging const jint badInt = -
3;
// generic "bad int" value const long badOopVal = -
1;
// generic "bad oop" value const int freeBlockPad =
0xBA;
// value used to pad freed blocks. const int uninitBlockPad =
0xF1;
// value used to zap newly malloc'd blocks. // (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 // Avoid use of global min/max macros which may cause unwanted double // evaluation of arguments. // 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
MAX3(T a, T b, T c) {
return MAX2(
MAX2(a, b), c); }
template<
class T>
inline T
MIN3(T a, T b, T c) {
return MIN2(
MIN2(a, b), c); }
template<
class T>
inline T
MAX4(T a, T b, T c, T d) {
return MAX2(
MAX3(a, b, c), d); }
template<
class T>
inline T
MIN4(T a, T b, T c, T d) {
return MIN2(
MIN3(a, b, c), d); }
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' // p = 2^(i+1) && p <= x (i.e., 2^(i+1) <= x) // p = 2^(i+1) && x < p (i.e., 2^i <= x < 2^(i+1)) // (if p = 0 then overflow occurred and i = 31) //* largest i such that 2^i <= x // A negative value of 'x' will return '63' while (p != 0 && p <= (
julong)x) {
// p = 2^(i+1) && p <= x (i.e., 2^(i+1) <= x) // p = 2^(i+1) && x < p (i.e., 2^i <= x < 2^(i+1)) // (if p = 0 then overflow occurred and i = 63) //* the argument must be exactly a power of 2 //* the argument must be exactly a power of 2 // returns integer round-up to the nearest multiple of s (s must be a power of two) // returns integer round-down to the nearest multiple of s (s must be a power of two) // "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: return ((
u8(
c1) <<
56 ) & (
u8(
0xff) <<
56 ))
| ((
u8(
c2) <<
48 ) & (
u8(
0xff) <<
48 ))
| ((
u8(
c3) <<
40 ) & (
u8(
0xff) <<
40 ))
| ((
u8(
c4) <<
32 ) & (
u8(
0xff) <<
32 ))
| ((
u8(
c5) <<
24 ) & (
u8(
0xff) <<
24 ))
| ((
u8(
c6) <<
16 ) & (
u8(
0xff) <<
16 ))
| ((
u8(
c7) <<
8 ) & (
u8(
0xff) <<
8 ))
| ((
u8(
c8) << 0 ) & (
u8(
0xff) << 0 ));
// This routine takes four bytes: return ((
u4(
c1) <<
24 ) &
0xff000000)
| ((
u4(
c2) <<
16 ) &
0x00ff0000)
| ((
u4(
c3) <<
8 ) &
0x0000ff00)
| ((
u4(
c4) << 0 ) &
0x000000ff);
// And this one works if the four bytes are contiguous in memory: // Ditto for two-byte ints: return u2(((
u2(
c1) <<
8 ) &
0xff00)
| ((
u2(
c2) << 0 ) &
0x00ff));
// And this one works if the two bytes are contiguous in memory: // Portable routines to go the other way: // Pack and extract shorts to/from ints: return (x >>
16) &
0xffff;
return ((
int)((
unsigned int)
high <<
16) | (
unsigned int)
low);
// Printf-style formatters for fixed- and variable-width types as pointers and // 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" // Format 32-bit quantities. // 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. // 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 // Enable zap-a-lot if in debug version.