/* * Copyright (c) 1997, 2022, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it * 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. *
*/
// Defaults for macros that might be defined per compiler. #ifndef NOINLINE #define NOINLINE #endif #ifndef ALWAYSINLINE #define ALWAYSINLINE inline #endif
// These are #defines to selectively turn on/off the Print(Opto)Assembly // capabilities. Choices should be led by a tradeoff between // code size and improved supportability. // if PRINT_ASSEMBLY then PRINT_ABSTRACT_ASSEMBLY must be true as well // to have a fallback in case hsdis is not available. #ifdefined(PRODUCT) #define SUPPORT_ABSTRACT_ASSEMBLY #define SUPPORT_ASSEMBLY #undef SUPPORT_OPTO_ASSEMBLY // Can't activate. In PRODUCT, many dump methods are missing. #undef SUPPORT_DATA_STRUCTS // Of limited use. In PRODUCT, many print methods are empty. #else #define SUPPORT_ABSTRACT_ASSEMBLY #define SUPPORT_ASSEMBLY #define SUPPORT_OPTO_ASSEMBLY #define SUPPORT_DATA_STRUCTS #endif #ifdefined(SUPPORT_ASSEMBLY) && !defined(SUPPORT_ABSTRACT_ASSEMBLY) #define SUPPORT_ABSTRACT_ASSEMBLY #endif
// This file holds all globally used constants & types, class (forward) // declarations and a few frequently used utility functions.
// Declare the named class to be noncopyable. This macro must be followed by // a semi-colon. The macro provides deleted declarations for the class's copy // constructor and assignment operator. Because these operations are deleted, // they cannot be defined and potential callers will fail to compile. #define NONCOPYABLE(C) C(C const&) = delete; C& operator=(C const&) = delete/* next token must be ; */
//---------------------------------------------------------------------------------------------------- // 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)
// Guide to the suffixes used in the format specifiers for integers: // - print the decimal value: 745565 // _X - print as hexadecimal, without leading 0s: 0x12345 // _X_0 - print as hexadecimal, with leading 0s: 0x00012345 // _W(w) - prints w sized string with the given value right // adjusted. Use -w to print left adjusted. // // Note that the PTR format specifiers print using 0x with leading zeros, // just like the _X_0 version for integers.
//---------------------------------------------------------------------------------------------------- // Forbid the use of various C library functions. // Some of these have os:: replacements that should normally be used instead. // Others are considered security concerns, with preferred alternatives.
// Size of a char[] needed to represent a jint as a string in decimal. constint jintAsStringSize = 12;
// An opaque type, so that HeapWord* can be a generic pointer into the heap. // We require that object sizes be measured in units of heap words (e.g. // pointer-sized values), so that given HeapWord* hw, // hw += oop(hw)->foo(); // works, where foo is a method (like size or scavenge) that returns the // object size. class HeapWordImpl; // Opaque, never defined. typedef HeapWordImpl* HeapWord;
// Analogous opaque struct for metadata allocated from metaspaces. class MetaWordImpl; // Opaque, never defined. typedef MetaWordImpl* MetaWord;
const size_t K = 1024; const size_t M = K*K; const size_t G = M*K; const size_t HWperKB = K / sizeof(HeapWord);
// Constants for converting from a base unit to milli-base units. For // example from seconds to milliseconds and microseconds
constint MILLIUNITS = 1000; // milli units per base unit constint MICROUNITS = 1000000; // micro units per base unit constint NANOUNITS = 1000000000; // nano units per base unit constint NANOUNITS_PER_MILLIUNIT = NANOUNITS / MILLIUNITS;
// Proper units routines try to maintain at least three significant digits. // In worst case, it would print five significant digits with lower prefix. // G is close to MAX_SIZE on 32-bit platforms, so its product can easily overflow, // and therefore we need to be careful.
inlineconstchar* proper_unit_for_byte_size(size_t s) { #ifdef _LP64 if (s >= 100*G) { return"G";
} #endif if (s >= 100*M) { return"M";
} elseif (s >= 100*K) { return"K";
} else { return"B";
}
}
template <class T> inline T byte_size_in_proper_unit(T s) { #ifdef _LP64 if (s >= 100*G) { return (T)(s/G);
} #endif if (s >= 100*M) { return (T)(s/M);
} elseif (s >= 100*K) { return (T)(s/K);
} else { return s;
}
}
inlineconstchar* exact_unit_for_byte_size(size_t s) { #ifdef _LP64 if (s >= G && (s % G) == 0) { return"G";
} #endif if (s >= M && (s % M) == 0) { return"M";
} if (s >= K && (s % K) == 0) { return"K";
} return"B";
}
inline size_t byte_size_in_exact_unit(size_t s) { #ifdef _LP64 if (s >= G && (s % G) == 0) { return s / G;
} #endif if (s >= M && (s % M) == 0) { return s / M;
} if (s >= K && (s % K) == 0) { return s / K;
} 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.
//---------------------------------------------------------------------------------------------------- // Java type definitions
// All kinds of 'plain' byte addresses typedefsignedchar s_char; typedefunsignedchar u_char; typedef u_char* address; typedef uintptr_t address_word; // unsigned integer which will hold a pointer // 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
inline address set_address_bits(address x, int m) { return address(intptr_t(x) | m); } inline address clear_address_bits(address x, int m) { return address(intptr_t(x) & ~m); }
// Utility functions to "portably" make cast to/from function pointers.
inline address_word mask_address_bits(address x, int m) { return address_word(x) & m; } inline address_word castable_address(address x) { return address_word(x) ; } inline address_word castable_address(void* x) { return address_word(x) ; }
// 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(). inline size_t pointer_delta(constvolatilevoid* left, constvolatilevoid* right,
size_t element_size) {
assert(left >= right, "avoid underflow - left: " PTR_FORMAT " right: " PTR_FORMAT, p2i(left), p2i(right)); return (((uintptr_t) left) - ((uintptr_t) right)) / element_size;
}
// A version specialized for HeapWord*'s. inline size_t pointer_delta(const HeapWord* left, const HeapWord* right) { return pointer_delta(left, right, sizeof(HeapWord));
} // A version specialized for MetaWord*'s. inline size_t pointer_delta(const MetaWord* left, const MetaWord* right) { return pointer_delta(left, right, sizeof(MetaWord));
}
// // 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 some case 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. // #define CAST_TO_FN_PTR(func_type, value) (reinterpret_cast<func_type>(value)) #define CAST_FROM_FN_PTR(new_type, func_ptr) ((new_type)((address_word)(func_ptr)))
// In many places we've added C-style casts to silence compiler // warnings, for example when truncating a size_t to an int when we // know the size_t is a small struct. Such casts are risky because // they effectively disable useful compiler warnings. We can make our // lives safer with this function, which ensures that any cast is // reversible without loss of information. It doesn't check // everything: it isn't intended to make sure that pointer types are // compatible, for example. template <typename T2, typename T1>
T2 checked_cast(T1 thing) {
T2 result = static_cast<T2>(thing);
assert(static_cast<T1>(result) == thing, "must be"); return result;
}
// Need the correct linkage to call qsort without warnings extern"C" { typedefint (*_sort_Fn)(constvoid *, constvoid *);
}
// Unsigned byte types for os and stream.hpp
// Unsigned one, two, four and eight byte quantities used for describing // the .class file format. See JVM book chapter 4.
//---------------------------------------------------------------------------------------------------- // old CDS options externbool DumpSharedSpaces; externbool DynamicDumpSharedSpaces; externbool RequireSharedSpaces; extern"C" { // Make sure UseSharedSpaces is accessible to the serviceability agent. extern JNIEXPORT jboolean UseSharedSpaces;
}
//---------------------------------------------------------------------------------------------------- // Object alignment, in units of HeapWords. // // Minimum is max(BytesPerLong, BytesPerDouble, BytesPerOop) / HeapWordSize, so jlong, jdouble and // reference fields can be naturally aligned.
// Maximal size of heap where unscaled compression can be used. Also upper bound // for heap placement: 4GB. const uint64_t UnscaledOopHeapMax = (uint64_t(max_juint) + 1); // Maximal size of heap where compressed oops can be used. Also upper bound for heap // placement for zero based compression algorithm: UnscaledOopHeapMax << LogMinObjAlignmentInBytes. extern uint64_t OopEncodingHeapMax;
// Maximal size of compressed class space. Above this limit compression is not possible. // Also upper bound for placement of zero based class space. (Class space is further limited // to be < 3G, see arguments.cpp.) const uint64_t KlassEncodingMetaspaceMax = (uint64_t(max_juint) + 1) << LogKlassAlignmentInBytes;
// Machine dependent stuff
// The maximum size of the code cache. Can be overridden by targets. #define CODE_CACHE_SIZE_LIMIT (2*G) // Allow targets to reduce the default size of the code cache. #define CODE_CACHE_DEFAULT_LIMIT CODE_CACHE_SIZE_LIMIT
#include CPU_HEADER(globalDefinitions)
// To assure the IRIW property on processors that are not multiple copy // atomic, sync instructions must be issued between volatile reads to // assure their ordering, instead of after volatile stores. // (See "A Tutorial Introduction to the ARM and POWER Relaxed Memory Models" // by Luc Maranget, Susmit Sarkar and Peter Sewell, INRIA/Cambridge) #ifdef CPU_MULTI_COPY_ATOMIC // Not needed. constbool support_IRIW_for_not_multiple_copy_atomic_cpu = false; #else // From all non-multi-copy-atomic architectures, only PPC64 supports IRIW at the moment. // Final decision is subject to JEP 188: Java Memory Model Update. constbool support_IRIW_for_not_multiple_copy_atomic_cpu = PPC64_ONLY(true) NOT_PPC64(false); #endif
// The expected size in bytes of a cache line, used to pad data structures. #ifndef DEFAULT_CACHE_LINE_SIZE #define DEFAULT_CACHE_LINE_SIZE 64 #endif
//---------------------------------------------------------------------------------------------------- // 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. inlinedouble fabsd(double value) { return fabs(value);
}
// Returns numerator/denominator as percentage value from 0 to 100. If denominator // is zero, return 0.0. template<typename T> inlinedouble percent_of(T numerator, T denominator) { return denominator != 0 ? (double)numerator / denominator * 100.0 : 0.0;
}
//---------------------------------------------------------------------------------------------------- // Special casts // Cast floats into same-size integers and vice-versa w/o changing bit-pattern typedefunion {
jfloat f;
jint i;
} FloatIntConv;
// the fancy casts are a hopefully portable way // to do unsigned 32 to 64 bit type conversion inlinevoid set_low (jlong* value, jint low ) { *value &= (jlong)0xffffffff << 32;
*value |= (jlong)(julong)(juint)low; }
// NOTE: replicated in SA in vm/agent/sun/jvm/hotspot/runtime/BasicType.java enum BasicType { // The values T_BOOLEAN..T_LONG (4..11) are derived from the JVMS.
T_BOOLEAN = JVM_T_BOOLEAN,
T_CHAR = JVM_T_CHAR,
T_FLOAT = JVM_T_FLOAT,
T_DOUBLE = JVM_T_DOUBLE,
T_BYTE = JVM_T_BYTE,
T_SHORT = JVM_T_SHORT,
T_INT = JVM_T_INT,
T_LONG = JVM_T_LONG, // The remaining values are not part of any standard. // T_OBJECT and T_VOID denote two more semantic choices // for method return values. // T_OBJECT and T_ARRAY describe signature syntax. // T_ADDRESS, T_METADATA, T_NARROWOOP, T_NARROWKLASS describe // internal references within the JVM as if they were Java // types in their own right.
T_OBJECT = 12,
T_ARRAY = 13,
T_VOID = 14,
T_ADDRESS = 15,
T_NARROWOOP = 16,
T_METADATA = 17,
T_NARROWKLASS = 18,
T_CONFLICT = 19, // for stack value type with conflicting contents
T_ILLEGAL = 99
};
inlinebool is_java_type(BasicType t) { return T_BOOLEAN <= t && t <= T_VOID;
}
inlinebool is_java_primitive(BasicType t) { return T_BOOLEAN <= t && t <= T_LONG;
}
inlinebool is_subword_type(BasicType t) { // these guys are processed exactly like T_INT in calling sequences: return (t == T_BOOLEAN || t == T_CHAR || t == T_BYTE || t == T_SHORT);
}
externchar type2char_tab[T_CONFLICT+1]; // Map a BasicType to a jchar inlinechar type2char(BasicType t) { return (uint)t < T_CONFLICT+1 ? type2char_tab[t] : 0; } externint type2size[T_CONFLICT+1]; // Map BasicType to result stack elements externconstchar* type2name_tab[T_CONFLICT+1]; // Map a BasicType to a char* extern BasicType name2type(constchar* name);
// this works on valid parameter types but not T_VOID, T_CONFLICT, etc. inlineint parameter_type_word_count(BasicType t) { if (is_double_word_type(t)) return 2;
assert(is_java_primitive(t) || is_reference_type(t), "no goofy types here please");
assert(type2size[t] == 1, "must be"); return 1;
}
// maps a BasicType to its instance field storage type: // all sub-word integral types are widened to T_INT extern BasicType type2field[T_CONFLICT+1]; extern BasicType type2wfield[T_CONFLICT+1];
// 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 representation' 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
ztos = 1, // byte, bool tos cached
ctos = 2, // char tos cached
stos = 3, // short tos cached
itos = 4, // int tos cached
ltos = 5, // long tos cached
ftos = 6, // float tos cached
dtos = 7, // double tos cached
atos = 8, // object cached
vtos = 9, // tos not cached
number_of_states,
ilgl // illegal state: should not occur
};
inline TosState as_TosState(BasicType type) { switch (type) { case T_BYTE : return btos; case T_BOOLEAN: return ztos; case T_CHAR : return ctos; case T_SHORT : return stos; case T_INT : return itos; case T_LONG : return ltos; case T_FLOAT : return ftos; case T_DOUBLE : return dtos; case T_VOID : return vtos; case T_ARRAY : // fall through case T_OBJECT : return atos; default : return ilgl;
}
}
inline BasicType as_BasicType(TosState state) { switch (state) { case btos : return T_BYTE; case ztos : return T_BOOLEAN; case ctos : return T_CHAR; case stos : return T_SHORT; case itos : return T_INT; case ltos : return T_LONG; case ftos : return T_FLOAT; case dtos : return T_DOUBLE; case atos : return T_OBJECT; case vtos : return T_VOID; default : return T_ILLEGAL;
}
}
// Helper function to convert BasicType info into TosState // Note: Cannot define here as it uses global constant at the time being.
TosState as_TosState(BasicType type);
// 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 xxxx_trans state can always be found by adding 1. // enum JavaThreadState {
_thread_uninitialized = 0, // should never happen (missing initialization)
_thread_new = 2, // just starting up, i.e., in process of being initialized
_thread_new_trans = 3, // corresponding transition state (not used, included for completeness)
_thread_in_native = 4, // running in native code
_thread_in_native_trans = 5, // corresponding transition state
_thread_in_vm = 6, // running in VM
_thread_in_vm_trans = 7, // corresponding transition state
_thread_in_Java = 8, // running in Java or in stub code
_thread_in_Java_trans = 9, // corresponding transition state (not used, included for completeness)
_thread_blocked = 10, // blocked in vm
_thread_blocked_trans = 11, // corresponding transition state
_thread_max_state = 12 // maximum thread state+1 - used for statistics allocation
};
//---------------------------------------------------------------------------------------------------- // Special constants for debugging
const jint badInt = -3; // generic "bad int" value const intptr_t badAddressVal = -2; // generic "bad address" value const intptr_t badOopVal = -1; // generic "bad oop" value const intptr_t badHeapOopVal = (intptr_t) CONST64(0x2BAD4B0BBAADBABE); // value used to zap heap after GC constint badStackSegVal = 0xCA; // value used to zap stack segments constint badHandleValue = 0xBC; // value used to zap vm handle area constint badResourceValue = 0xAB; // value used to zap resource area constint freeBlockPad = 0xBA; // value used to pad freed blocks. constint uninitBlockPad = 0xF1; // value used to zap newly malloc'd blocks. const juint uninitMetaWordVal= 0xf7f7f7f7; // value used to zap newly allocated metachunk const juint badHeapWordVal = 0xBAADBABE; // value used to zap heap after GC const juint badMetaWordVal = 0xBAADFADE; // value used to zap metadata heap after GC constint badCodeHeapNewVal= 0xCC; // value used to zap Code heap at allocation constint badCodeHeapFreeVal = 0xDD; // value used to zap Code heap at deallocation
// (These must be implemented as #defines because C++ compilers are // not obligated to inline non-integral constants!) #define badAddress ((address)::badAddressVal) #define badOop (cast_to_oop(::badOopVal)) #define badHeapWord (::badHeapWordVal)
// Default TaskQueue size is 16K (32-bit) or 128K (64-bit) #define TASKQUEUE_SIZE (NOT_LP64(1<<14) LP64_ONLY(1<<17))
//---------------------------------------------------------------------------------------------------- // Utility functions for bitfield manipulations
const intptr_t AllBits = ~0; // all bits set in a word const intptr_t NoBits = 0; // no bits set in a word const jlong NoLongBits = 0; // no bits set in a long const intptr_t OneBit = 1; // only right_most bit set in a word
// 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) #define nth_bit(n) (((n) >= BitsPerWord) ? 0 : (OneBit << (n))) #define right_n_bits(n) (nth_bit(n) - 1)
// bit-operations using a mask m inlinevoid set_bits (intptr_t& x, intptr_t m) { x |= m; } inlinevoid clear_bits (intptr_t& x, intptr_t m) { x &= ~m; } inline intptr_t mask_bits (intptr_t x, intptr_t m) { return x & m; } inline jlong mask_long_bits (jlong x, jlong m) { return x & m; } inlinebool mask_bits_are_true (intptr_t flags, intptr_t mask) { return (flags & mask) == mask; }
// bit-operations using the n.th bit inlinevoid set_nth_bit(intptr_t& x, int n) { set_bits (x, nth_bit(n)); } inlinevoid clear_nth_bit(intptr_t& x, int n) { clear_bits(x, nth_bit(n)); } inlinebool is_set_nth_bit(intptr_t x, int n) { return mask_bits (x, nth_bit(n)) != NoBits; }
// returns the bitfield of x starting at start_bit_no with length field_length (no sign-extension!) inline intptr_t bitfield(intptr_t x, int start_bit_no, int field_length) { return mask_bits(x >> start_bit_no, right_n_bits(field_length));
}
//---------------------------------------------------------------------------------------------------- // Utility functions for integers
// Avoid use of global min/max macros which may cause unwanted double // evaluation of arguments. #ifdef max #undef max #endif
#ifdef min #undef 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> constexpr T MAX2(T a, T b) { return (a > b) ? a : b; } template<class T> constexpr T MIN2(T a, T b) { return (a < b) ? a : b; } template<class T> constexpr T MAX3(T a, T b, T c) { return MAX2(MAX2(a, b), c); } template<class T> constexpr T MIN3(T a, T b, T c) { return MIN2(MIN2(a, b), c); } template<class T> constexpr T MAX4(T a, T b, T c, T d) { return MAX2(MAX3(a, b, c), d); } template<class T> constexpr 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; }
// Return the given value clamped to the range [min ... max] template<typename T> inline T clamp(T value, T min, T max) {
assert(min <= max, "must be"); return MIN2(MAX2(value, min), max);
}
// swap a & b template<class T> staticvoid swap(T& a, T& b) {
T tmp = a;
a = b;
b = tmp;
}
// array_size_impl is a function that takes a reference to T[N] and // returns a reference to char[N]. It is not ODR-used, so not defined. template<typename T, size_t N> char (&array_size_impl(T (&)[N]))[N];
//---------------------------------------------------------------------------------------------------- // Sum and product which can never overflow: they wrap, just like the // Java operations. Note that we don't intend these to be used for // general-purpose arithmetic: their purpose is to emulate Java // operations.
// The goal of this code to avoid undefined or implementation-defined // behavior. The use of an lvalue to reference cast is explicitly // permitted by Lvalues and rvalues [basic.lval]. [Section 3.10 Para // 15 in C++03] #define JAVA_INTEGER_OP(OP, NAME, TYPE, UNSIGNED_TYPE) \ inline TYPE NAME (TYPE in1, TYPE in2) { \
UNSIGNED_TYPE ures = static_cast<UNSIGNED_TYPE>(in1); \
ures OP ## = static_cast<UNSIGNED_TYPE>(in2); \ returnreinterpret_cast<TYPE&>(ures); \
}
// Provide integer shift operations with Java semantics. No overflow // issues - left shifts simply discard shifted out bits. No undefined // behavior for large or negative shift quantities; instead the actual // shift distance is the argument modulo the lhs value's size in bits. // No undefined or implementation defined behavior for shifting negative // values; left shift discards bits, right shift sign extends. We use // the same safe conversion technique as above for java_add and friends. #define JAVA_INTEGER_SHIFT_OP(OP, NAME, TYPE, XTYPE) \ inline TYPE NAME (TYPE lhs, jint rhs) { \ const uint rhs_mask = (sizeof(TYPE) * 8) - 1; \
STATIC_ASSERT(rhs_mask == 31 || rhs_mask == 63); \
XTYPE xres = static_cast<XTYPE>(lhs); \
xres OP ## = (rhs & rhs_mask); \ returnreinterpret_cast<TYPE&>(xres); \
}
JAVA_INTEGER_SHIFT_OP(<<, java_shift_left, jint, juint)
JAVA_INTEGER_SHIFT_OP(<<, java_shift_left, jlong, julong) // For signed shift right, assume C++ implementation >> sign extends.
JAVA_INTEGER_SHIFT_OP(>>, java_shift_right, jint, jint)
JAVA_INTEGER_SHIFT_OP(>>, java_shift_right, jlong, jlong) // For >>> use C++ unsigned >>.
JAVA_INTEGER_SHIFT_OP(>>, java_shift_right_unsigned, jint, juint)
JAVA_INTEGER_SHIFT_OP(>>, java_shift_right_unsigned, jlong, julong)
#undef JAVA_INTEGER_SHIFT_OP
//---------------------------------------------------------------------------------------------------- // The goal of this code is to provide saturating operations for int/uint. // Checks overflow conditions and saturates the result to min_jint/max_jint. #define SATURATED_INTEGER_OP(OP, NAME, TYPE1, TYPE2) \ inlineint NAME (TYPE1 in1, TYPE2 in2) { \
jlong res = static_cast<jlong>(in1); \
res OP ## = static_cast<jlong>(in2); \ if (res > max_jint) { \
res = max_jint; \
} elseif (res < min_jint) { \
res = min_jint; \
} \ returnstatic_cast<int>(res); \
}
// Dereference vptr // All C++ compilers that we know of have the vtbl pointer in the first // word. If there are exceptions, this function needs to be made compiler // specific. staticinlinevoid* dereference_vptr(constvoid* addr) { return *(void**)addr;
}
//---------------------------------------------------------------------------------------------------- // String type aliases used by command line flag declarations and // processing utilities.
typedefconstchar* ccstr; typedefconstchar* ccstrlist; // represents string arguments which accumulate
//---------------------------------------------------------------------------------------------------- // Default hash/equals functions used by ResourceHashtable
template<typename K> unsigned primitive_hash(const K& k) { unsigned hash = (unsigned)((uintptr_t)k); return hash ^ (hash >> 3); // just in case we're dealing with aligned ptrs
}
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung ist noch experimentell.