globalDefinitions.hpp revision 3728
3728N/A * Copyright (c) 1997, 2012, 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 0N/A * published by the Free Software Foundation. 0N/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. 1472N/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//---------------------------------------------------------------------------------------------------- 113N/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. 1491N/A// Pad out certain offsets to jlong alignment, in HeapWord units. 1585N/A// The expected size in bytes of a cache line, used to pad data structures. 1585N/A// Bytes needed to pad type to avoid cache-line sharing; alignment should be the 1585N/A// expected cache line size (a power of two). The first addend avoids sharing 1585N/A// when the start address is not a multiple of alignment; the second maintains 1585N/A// alignment of starting addresses that happen to be a multiple. 1585N/A// Templates to create a subclass padded to avoid cache line sharing. These are 1585N/A// effective only when applied to derived-most (leaf) classes. 1585N/A// When no args are passed to the base ctor. 1585N/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 710N/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 726N/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. 0N/A// JavaThreadState keeps track of which part of the code a thread is executing in. This 0N/A// information is needed by the safepoint code. 0N/A// There are 4 essential states: 0N/A// _thread_new : Just started, but not executed init. code yet (most likely still in OS init code) 0N/A// _thread_in_native : In native code. This is a safepoint region, since all oops will be in jobject handles 0N/A// _thread_in_vm : Executing in the vm 0N/A// _thread_in_Java : Executing either interpreted or compiled Java code (or could be in a stub) 0N/A// Each state has an associated xxxx_trans state, which is an intermediate state used when a thread is in 0N/A// a transition from one state to another. These extra states makes it possible for the safepoint code to 0N/A// handle certain thread_states without having to suspend the thread - making the safepoint code faster. 0N/A// Given a state, the xxx_trans state can always be found by adding 1. 0N/A _thread_new =
2,
// just starting up, i.e., in process of being initialized 0N/A// Handy constants for deciding which compiler mode to use. 0N/A// Enumeration to distinguish tiers of compilation 0N/A//---------------------------------------------------------------------------------------------------- 0N/A// 'Forward' declarations of frequently used classes 0N/A// (in order to reduce interface dependencies & reduce 0N/A// number of unnecessary compilations after changes) 0N/A// Basic support for errors (general debug facilities not defined at this point fo the include phase) 0N/A//---------------------------------------------------------------------------------------------------- 0N/A// Special constants for debugging 0N/A// (These must be implemented as #defines because C++ compilers are 0N/A// not obligated to inline non-integral constants!) 1311N/A// Default TaskQueue size is 16K (32-bit) or 128K (64-bit) 0N/A//---------------------------------------------------------------------------------------------------- 0N/A// Utility functions for bitfield manipulations 0N/A// get a word with the n.th or the right-most or left-most n bits set 0N/A// (note: #define used only so that they can be used in enum constant definitions) 0N/A// bit-operations using a mask m 0N/A// bit-operations using the n.th bit 0N/A// returns the bitfield of x starting at start_bit_no with length field_length (no sign-extension!) 0N/A//---------------------------------------------------------------------------------------------------- 0N/A// Utility functions for integers 0N/A// Avoid use of global min/max macros which may cause unwanted double 0N/A// evaluation of arguments. 0N/A// It is necessary to use templates here. Having normal overloaded 0N/A// functions does not work because it is necessary to provide both 32- 0N/A// and 64-bit overloaded functions, which does not work, and having 0N/A// explicitly-typed versions of these routines (i.e., MAX2I, MAX2L) 0N/A// will be even more error-prone than macros. 0N/Atemplate<
class T>
inline T
MAX2(T a, T b) {
return (a > b) ? a : b; }
0N/Atemplate<
class T>
inline T
MIN2(T a, T b) {
return (a < b) ? a : b; }
0N/Atemplate<
class T>
inline T
MAX3(T a, T b, T c) {
return MAX2(
MAX2(a, b), c); }
0N/Atemplate<
class T>
inline T
MIN3(T a, T b, T c) {
return MIN2(
MIN2(a, b), c); }
0N/Atemplate<
class T>
inline T
MAX4(T a, T b, T c, T d) {
return MAX2(
MAX3(a, b, c), d); }
0N/Atemplate<
class T>
inline T
MIN4(T a, T b, T c, T d) {
return MIN2(
MIN3(a, b, c), d); }
0N/Atemplate<
class T>
inline T
ABS(T x) {
return (x > 0) ? x : -x; }
0N/A// true if x is a power of 2, false otherwise 0N/A// long version of is_power_of_2 0N/A//* largest i such that 2^i <= x 0N/A// A negative value of 'x' will return '31' 0N/A // p = 2^(i+1) && p <= x (i.e., 2^(i+1) <= x) 0N/A // p = 2^(i+1) && x < p (i.e., 2^i <= x < 2^(i+1)) 605N/A // (if p = 0 then overflow occurred and i = 31) 0N/A//* largest i such that 2^i <= x 0N/A// A negative value of 'x' will return '63' 0N/A // p = 2^(i+1) && p <= x (i.e., 2^(i+1) <= x) 0N/A // p = 2^(i+1) && x < p (i.e., 2^i <= x < 2^(i+1)) 605N/A // (if p = 0 then overflow occurred and i = 63) 0N/A//* the argument must be exactly a power of 2 568N/A//* the argument must be exactly a power of 2 0N/A// returns integer round-up to the nearest multiple of s (s must be a power of two) 0N/A// returns integer round-down to the nearest multiple of s (s must be a power of two) 0N/A// "to" should be greater than "from." 0N/A//---------------------------------------------------------------------------------------------------- 0N/A// Avoid non-portable casts with these routines (DEPRECATED) 0N/A// NOTE: USE Bytes class INSTEAD WHERE POSSIBLE 0N/A// Bytes is optimized machine-specifically and may be much faster then the portable routines below. 0N/A// Given sequence of four bytes, build into a 32-bit word 0N/A// following the conventions used in class files. 0N/A// On the 386, this could be realized with a simple address cast. 0N/A// This routine takes eight bytes: 0N/A// This routine takes four bytes: 0N/A// And this one works if the four bytes are contiguous in memory: 0N/A// Ditto for two-byte ints: 0N/A// And this one works if the two bytes are contiguous in memory: 0N/A// now (64-bit) longs 0N/A// Portable routines to go the other way: 0N/A return (x >>
16) &
0xffff;
0N/A return ((
int)((
unsigned int)
high <<
16) | (
unsigned int)
low);
0N/A// Printf-style formatters for fixed- and variable-width types as pointers and 2796N/A// integers. These are derived from the definitions in inttypes.h. If the platform 2796N/A// doesn't provide appropriate definitions, they should be provided in 0N/A// Format 32-bit quantities. 0N/A// Format 64-bit quantities. 2796N/A// Format pointers which change size between 32- and 64-bit. 0N/A// Enable zap-a-lot if in debug version. 0N/A#
endif /* COMPILER2 */ 1879N/A#
endif // SHARE_VM_UTILITIES_GLOBALDEFINITIONS_HPP