globalDefinitions.hpp revision 1261
3853N/A * Copyright 1997-2009 Sun Microsystems, Inc. All Rights Reserved. 3853N/A * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 3853N/A * This code is free software; you can redistribute it and/or modify it 3853N/A * under the terms of the GNU General Public License version 2 only, as 3853N/A * published by the Free Software Foundation. 3853N/A * This code is distributed in the hope that it will be useful, but WITHOUT 3853N/A * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 3853N/A * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 3853N/A * version 2 for more details (a copy is included in the LICENSE file that 3853N/A * You should have received a copy of the GNU General Public License version 3853N/A * 2 along with this work; if not, write to the Free Software Foundation, 3853N/A * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 3853N/A * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, 3853N/A * CA 95054 USA or visit www.sun.com if you need additional information or 3853N/A// This file holds all globally used constants & types, class (forward) 3853N/A// declarations and a few frequently used utility functions. 3853N/A//---------------------------------------------------------------------------------------------------- // 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() // 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 // works, where foo is a method (like size or scavenge) that returns the char*
value() {
return i; }
// HeapWordSize must be 2^LogHeapWordSize. // 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. // The minimum number of native machine words necessary to contain "byte_size" // Constants for converting from a base unit to milli-base units. For // example from seconds to milliseconds and microseconds const int MILLIUNITS =
1000;
// milli units per base unit const int MICROUNITS =
1000000;
// micro units per base unit const int NANOUNITS =
1000000000;
// nano units per base unit //---------------------------------------------------------------------------------------------------- // 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. // min_intx 0x80000000 0x8000000000000000 // max_intx 0x7FFFFFFF 0x7FFFFFFFFFFFFFFF // max_uintx 0xFFFFFFFF 0xFFFFFFFFFFFFFFFF //---------------------------------------------------------------------------------------------------- // All kinds of 'plain' byte addresses // except for some implementations of a C++ // linkage pointer to function. Should never // need one of those to be placed in this // Utility functions to "portably" (?) bit twiddle pointers // Where portable means keep ANSI C++ compilers quiet // Utility functions to "portably" make cast to/from function pointers. // 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 // A typical use might be: // if (pointer_delta(end(), top()) >= size) { // // enough room for an object of size // and then additions like // are safe because we know that top() is at least size below end(). // 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 // Unsigned one, two, four and eigth byte quantities used for describing // the .class file format. See JVM book chapter 4. //---------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------- // HotSwap - for JVMTI aka Class File Replacement and PopFrame // Determines whether on-the-fly class replacement and frame popping are enabled. //---------------------------------------------------------------------------------------------------- // Object alignment, in units of HeapWords. // Minimum is max(BytesPerLong, BytesPerDouble, BytesPerOop) / HeapWordSize, so jlong, jdouble and // reference fields can be naturally aligned. // Machine dependent stuff // 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 //---------------------------------------------------------------------------------------------------- // 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 T_CONFLICT =
17,
// for stack value type with conflicting contents // these guys are processed exactly like T_INT in calling sequences: // Convert a char from a classfile signature to a BasicType // Auxilary math routines // maps a BasicType to its instance field storage type: // all sub-word integral types are widened to T_INT // JavaValue serves as a container for arbitrary Java values. // 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. // 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 ctos =
1,
// char tos cached stos =
2,
// short tos cached itos =
3,
// int tos cached ltos =
4,
// long tos cached ftos =
5,
// float tos cached dtos =
6,
// double tos cached atos =
7,
// object cached vtos =
8,
// tos not cached ilgl // illegal state: should not occur //case ztos: return T_BOOLEAN;//FIXME // 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. _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!) //---------------------------------------------------------------------------------------------------- // 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.