0N/A/*
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 *
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 *
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 *
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 *
1472N/A * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
1472N/A * or visit www.oracle.com if you need additional information or have any
1472N/A * questions.
0N/A *
0N/A */
0N/A
1879N/A#ifndef SHARE_VM_UTILITIES_GLOBALDEFINITIONS_HPP
1879N/A#define SHARE_VM_UTILITIES_GLOBALDEFINITIONS_HPP
1879N/A
2842N/A#ifndef __STDC_FORMAT_MACROS
2796N/A#define __STDC_FORMAT_MACROS
2842N/A#endif
2796N/A
1879N/A#ifdef TARGET_COMPILER_gcc
1879N/A# include "utilities/globalDefinitions_gcc.hpp"
1879N/A#endif
1879N/A#ifdef TARGET_COMPILER_visCPP
1879N/A# include "utilities/globalDefinitions_visCPP.hpp"
1879N/A#endif
1879N/A#ifdef TARGET_COMPILER_sparcWorks
1879N/A# include "utilities/globalDefinitions_sparcWorks.hpp"
1879N/A#endif
1879N/A
1879N/A#include "utilities/macros.hpp"
1879N/A
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/A//----------------------------------------------------------------------------------------------------
0N/A// Constants
0N/A
0N/Aconst int LogBytesPerShort = 1;
0N/Aconst int LogBytesPerInt = 2;
0N/A#ifdef _LP64
0N/Aconst int LogBytesPerWord = 3;
0N/A#else
0N/Aconst int LogBytesPerWord = 2;
0N/A#endif
0N/Aconst int LogBytesPerLong = 3;
0N/A
0N/Aconst int BytesPerShort = 1 << LogBytesPerShort;
0N/Aconst int BytesPerInt = 1 << LogBytesPerInt;
0N/Aconst int BytesPerWord = 1 << LogBytesPerWord;
0N/Aconst int BytesPerLong = 1 << LogBytesPerLong;
0N/A
0N/Aconst int LogBitsPerByte = 3;
0N/Aconst int LogBitsPerShort = LogBitsPerByte + LogBytesPerShort;
0N/Aconst int LogBitsPerInt = LogBitsPerByte + LogBytesPerInt;
0N/Aconst int LogBitsPerWord = LogBitsPerByte + LogBytesPerWord;
0N/Aconst int LogBitsPerLong = LogBitsPerByte + LogBytesPerLong;
0N/A
0N/Aconst int BitsPerByte = 1 << LogBitsPerByte;
0N/Aconst int BitsPerShort = 1 << LogBitsPerShort;
0N/Aconst int BitsPerInt = 1 << LogBitsPerInt;
0N/Aconst int BitsPerWord = 1 << LogBitsPerWord;
0N/Aconst int BitsPerLong = 1 << LogBitsPerLong;
0N/A
0N/Aconst int WordAlignmentMask = (1 << LogBytesPerWord) - 1;
0N/Aconst int LongAlignmentMask = (1 << LogBytesPerLong) - 1;
0N/A
0N/Aconst int WordsPerLong = 2; // Number of stack entries for longs
0N/A
113N/Aconst int oopSize = sizeof(char*); // Full-width oop
113N/Aextern int heapOopSize; // Oop within a java object
0N/Aconst int wordSize = sizeof(char*);
0N/Aconst int longSize = sizeof(jlong);
0N/Aconst int jintSize = sizeof(jint);
0N/Aconst int size_tSize = sizeof(size_t);
0N/A
113N/Aconst int BytesPerOop = BytesPerWord; // Full-width oop
0N/A
113N/Aextern int LogBytesPerHeapOop; // Oop within a java object
113N/Aextern int LogBitsPerHeapOop;
113N/Aextern int BytesPerHeapOop;
113N/Aextern int BitsPerHeapOop;
0N/A
1491N/A// Oop encoding heap max
1491N/Aextern uint64_t OopEncodingHeapMax;
1491N/A
0N/Aconst int BitsPerJavaInteger = 32;
559N/Aconst int BitsPerJavaLong = 64;
0N/Aconst int BitsPerSize_t = size_tSize * BitsPerByte;
0N/A
113N/A// Size of a char[] needed to represent a jint as a string in decimal.
113N/Aconst int jintAsStringSize = 12;
113N/A
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#ifdef _LP64
0N/Aconst int SerializePageShiftCount = 4;
0N/A#else
0N/Aconst int SerializePageShiftCount = 3;
0N/A#endif
0N/A
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// HeapWord* hw;
0N/A// hw += oop(hw)->foo();
0N/A// works, where foo is a method (like size or scavenge) that returns the
0N/A// object size.
0N/Aclass HeapWord {
0N/A friend class VMStructs;
263N/A private:
0N/A char* i;
361N/A#ifndef PRODUCT
263N/A public:
263N/A char* value() { return i; }
263N/A#endif
0N/A};
0N/A
0N/A// HeapWordSize must be 2^LogHeapWordSize.
113N/Aconst int HeapWordSize = sizeof(HeapWord);
0N/A#ifdef _LP64
113N/Aconst int LogHeapWordSize = 3;
0N/A#else
113N/Aconst int LogHeapWordSize = 2;
0N/A#endif
113N/Aconst int HeapWordsPerLong = BytesPerLong / HeapWordSize;
113N/Aconst int LogHeapWordsPerLong = LogBytesPerLong - LogHeapWordSize;
0N/A
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#ifdef _LP64
0N/A#define ScaleForWordSize(x) align_size_down_((x) * 13 / 10, HeapWordSize)
0N/A#else
0N/A#define ScaleForWordSize(x) (x)
0N/A#endif
0N/A
0N/A// The minimum number of native machine words necessary to contain "byte_size"
0N/A// bytes.
0N/Ainline size_t heap_word_size(size_t byte_size) {
0N/A return (byte_size + (HeapWordSize-1)) >> LogHeapWordSize;
0N/A}
0N/A
0N/A
0N/Aconst size_t K = 1024;
0N/Aconst size_t M = K*K;
0N/Aconst size_t G = M*K;
0N/Aconst size_t HWperKB = K / sizeof(HeapWord);
0N/A
0N/Aconst jint min_jint = (jint)1 << (sizeof(jint)*BitsPerByte-1); // 0x80000000 == smallest jint
0N/Aconst jint max_jint = (juint)min_jint - 1; // 0x7FFFFFFF == largest jint
0N/A
0N/A// Constants for converting from a base unit to milli-base units. For
0N/A// example from seconds to milliseconds and microseconds
0N/A
0N/Aconst int MILLIUNITS = 1000; // milli units per base unit
0N/Aconst int MICROUNITS = 1000000; // micro units per base unit
0N/Aconst int NANOUNITS = 1000000000; // nano units per base unit
0N/A
2988N/Aconst jlong NANOSECS_PER_SEC = CONST64(1000000000);
2988N/Aconst jint NANOSECS_PER_MILLISEC = 1000000;
2988N/A
0N/Ainline const char* proper_unit_for_byte_size(size_t s) {
3732N/A#ifdef _LP64
3732N/A if (s >= 10*G) {
3732N/A return "G";
3732N/A }
3732N/A#endif
0N/A if (s >= 10*M) {
0N/A return "M";
0N/A } else if (s >= 10*K) {
0N/A return "K";
0N/A } else {
0N/A return "B";
0N/A }
0N/A}
0N/A
3728N/Atemplate <class T>
3728N/Ainline T byte_size_in_proper_unit(T s) {
3732N/A#ifdef _LP64
3732N/A if (s >= 10*G) {
3732N/A return (T)(s/G);
3732N/A }
3732N/A#endif
0N/A if (s >= 10*M) {
3728N/A return (T)(s/M);
0N/A } else if (s >= 10*K) {
3728N/A return (T)(s/K);
0N/A } else {
0N/A return s;
0N/A }
0N/A}
0N/A
0N/A//----------------------------------------------------------------------------------------------------
0N/A// VM type definitions
0N/A
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
0N/Atypedef intptr_t intx;
0N/Atypedef uintptr_t uintx;
0N/A
0N/Aconst intx min_intx = (intx)1 << (sizeof(intx)*BitsPerByte-1);
0N/Aconst intx max_intx = (uintx)min_intx - 1;
0N/Aconst uintx max_uintx = (uintx)-1;
0N/A
0N/A// Table of values:
0N/A// sizeof intx 4 8
0N/A// min_intx 0x80000000 0x8000000000000000
0N/A// max_intx 0x7FFFFFFF 0x7FFFFFFFFFFFFFFF
0N/A// max_uintx 0xFFFFFFFF 0xFFFFFFFFFFFFFFFF
0N/A
0N/Atypedef unsigned int uint; NEEDS_CLEANUP
0N/A
0N/A
0N/A//----------------------------------------------------------------------------------------------------
0N/A// Java type definitions
0N/A
0N/A// All kinds of 'plain' byte addresses
0N/Atypedef signed char s_char;
0N/Atypedef unsigned char u_char;
0N/Atypedef u_char* address;
0N/Atypedef uintptr_t address_word; // unsigned integer which will hold a pointer
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 // type anyway.
0N/A
0N/A// Utility functions to "portably" (?) bit twiddle pointers
0N/A// Where portable means keep ANSI C++ compilers quiet
0N/A
0N/Ainline address set_address_bits(address x, int m) { return address(intptr_t(x) | m); }
0N/Ainline address clear_address_bits(address x, int m) { return address(intptr_t(x) & ~m); }
0N/A
0N/A// Utility functions to "portably" make cast to/from function pointers.
0N/A
0N/Ainline address_word mask_address_bits(address x, int m) { return address_word(x) & m; }
0N/Ainline address_word castable_address(address x) { return address_word(x) ; }
0N/Ainline address_word castable_address(void* x) { return address_word(x) ; }
0N/A
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// to the other.
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// ...
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/Ainline size_t pointer_delta(const void* left,
0N/A const void* right,
0N/A size_t element_size) {
0N/A return (((uintptr_t) left) - ((uintptr_t) right)) / element_size;
0N/A}
0N/A// A version specialized for HeapWord*'s.
0N/Ainline size_t pointer_delta(const HeapWord* left, const HeapWord* right) {
0N/A return pointer_delta(left, right, sizeof(HeapWord));
0N/A}
0N/A
0N/A//
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//
0N/A#define CAST_TO_FN_PTR(func_type, value) ((func_type)(castable_address(value)))
0N/A#define CAST_FROM_FN_PTR(new_type, func_ptr) ((new_type)((address_word)(func_ptr)))
0N/A
0N/A// Unsigned byte types for os and stream.hpp
0N/A
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/Atypedef jubyte u1;
0N/Atypedef jushort u2;
0N/Atypedef juint u4;
0N/Atypedef julong u8;
0N/A
0N/Aconst jubyte max_jubyte = (jubyte)-1; // 0xFF largest jubyte
0N/Aconst jushort max_jushort = (jushort)-1; // 0xFFFF largest jushort
0N/Aconst juint max_juint = (juint)-1; // 0xFFFFFFFF largest juint
0N/Aconst julong max_julong = (julong)-1; // 0xFF....FF largest julong
0N/A
3081N/Atypedef jbyte s1;
3081N/Atypedef jshort s2;
3081N/Atypedef jint s4;
3081N/Atypedef jlong s8;
3081N/A
0N/A//----------------------------------------------------------------------------------------------------
0N/A// JVM spec restrictions
0N/A
0N/Aconst int max_method_code_size = 64*K - 1; // JVM spec, 2nd ed. section 4.8.1 (p.134)
0N/A
0N/A
0N/A//----------------------------------------------------------------------------------------------------
0N/A// HotSwap - for JVMTI aka Class File Replacement and PopFrame
0N/A//
0N/A// Determines whether on-the-fly class replacement and frame popping are enabled.
0N/A
0N/A#define HOTSWAP
0N/A
0N/A//----------------------------------------------------------------------------------------------------
0N/A// Object alignment, in units of HeapWords.
0N/A//
0N/A// Minimum is max(BytesPerLong, BytesPerDouble, BytesPerOop) / HeapWordSize, so jlong, jdouble and
0N/A// reference fields can be naturally aligned.
0N/A
1491N/Aextern int MinObjAlignment;
1491N/Aextern int MinObjAlignmentInBytes;
1491N/Aextern int MinObjAlignmentInBytesMask;
0N/A
1491N/Aextern int LogMinObjAlignment;
1491N/Aextern int LogMinObjAlignmentInBytes;
113N/A
0N/A// Machine dependent stuff
0N/A
1879N/A#ifdef TARGET_ARCH_x86
1879N/A# include "globalDefinitions_x86.hpp"
1879N/A#endif
1879N/A#ifdef TARGET_ARCH_sparc
1879N/A# include "globalDefinitions_sparc.hpp"
1879N/A#endif
1879N/A#ifdef TARGET_ARCH_zero
1879N/A# include "globalDefinitions_zero.hpp"
1879N/A#endif
2073N/A#ifdef TARGET_ARCH_arm
2073N/A# include "globalDefinitions_arm.hpp"
2073N/A#endif
2073N/A#ifdef TARGET_ARCH_ppc
2073N/A# include "globalDefinitions_ppc.hpp"
2073N/A#endif
1879N/A
0N/A
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
0N/A#define ARENA_AMALLOC_ALIGNMENT (2*BytesPerWord)
0N/A
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
0N/A#define align_size_up_(size, alignment) (((size) + ((alignment) - 1)) & ~((alignment) - 1))
0N/A
0N/Ainline intptr_t align_size_up(intptr_t size, intptr_t alignment) {
0N/A return align_size_up_(size, alignment);
0N/A}
0N/A
0N/A#define align_size_down_(size, alignment) ((size) & ~((alignment) - 1))
0N/A
0N/Ainline intptr_t align_size_down(intptr_t size, intptr_t alignment) {
0N/A return align_size_down_(size, alignment);
0N/A}
0N/A
0N/A// Align objects by rounding up their size, in HeapWord units.
0N/A
0N/A#define align_object_size_(size) align_size_up_(size, MinObjAlignment)
0N/A
0N/Ainline intptr_t align_object_size(intptr_t size) {
0N/A return align_size_up(size, MinObjAlignment);
0N/A}
0N/A
1491N/Ainline bool is_object_aligned(intptr_t addr) {
1491N/A return addr == align_object_size(addr);
1491N/A}
0N/A
1491N/A// Pad out certain offsets to jlong alignment, in HeapWord units.
0N/A
0N/Ainline intptr_t align_object_offset(intptr_t offset) {
0N/A return align_size_up(offset, HeapWordsPerLong);
0N/A}
0N/A
1585N/A// The expected size in bytes of a cache line, used to pad data structures.
1585N/A#define DEFAULT_CACHE_LINE_SIZE 64
1585N/A
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#define PADDING_SIZE(type, alignment) \
1585N/A ((alignment) + align_size_up_(sizeof(type), alignment))
1585N/A
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
1585N/A// When no args are passed to the base ctor.
1585N/Atemplate <class T, size_t alignment = DEFAULT_CACHE_LINE_SIZE>
1585N/Aclass Padded: public T {
1585N/Aprivate:
1585N/A char _pad_buf_[PADDING_SIZE(T, alignment)];
1585N/A};
1585N/A
1585N/A// When either 0 or 1 args may be passed to the base ctor.
1585N/Atemplate <class T, typename Arg1T, size_t alignment = DEFAULT_CACHE_LINE_SIZE>
1585N/Aclass Padded01: public T {
1585N/Apublic:
1585N/A Padded01(): T() { }
1585N/A Padded01(Arg1T arg1): T(arg1) { }
1585N/Aprivate:
1585N/A char _pad_buf_[PADDING_SIZE(T, alignment)];
1585N/A};
0N/A
0N/A//----------------------------------------------------------------------------------------------------
0N/A// Utility macros for compilers
0N/A// used to silence compiler warnings
0N/A
0N/A#define Unused_Variable(var) var
0N/A
0N/A
0N/A//----------------------------------------------------------------------------------------------------
0N/A// Miscellaneous
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/Ainline double fabsd(double value) {
0N/A return fabs(value);
0N/A}
0N/A
0N/Ainline jint low (jlong value) { return jint(value); }
0N/Ainline jint high(jlong value) { return jint(value >> 32); }
0N/A
0N/A// the fancy casts are a hopefully portable way
0N/A// to do unsigned 32 to 64 bit type conversion
0N/Ainline void set_low (jlong* value, jint low ) { *value &= (jlong)0xffffffff << 32;
0N/A *value |= (jlong)(julong)(juint)low; }
0N/A
0N/Ainline void set_high(jlong* value, jint high) { *value &= (jlong)(julong)(juint)0xffffffff;
0N/A *value |= (jlong)high << 32; }
0N/A
0N/Ainline jlong jlong_from(jint h, jint l) {
0N/A jlong result = 0; // initialization to avoid warning
0N/A set_high(&result, h);
0N/A set_low(&result, l);
0N/A return result;
0N/A}
0N/A
0N/Aunion jlong_accessor {
0N/A jint words[2];
0N/A jlong long_value;
0N/A};
0N/A
113N/Avoid basic_types_init(); // cannot define here; uses assert
0N/A
0N/A
0N/A// NOTE: replicated in SA in vm/agent/sun/jvm/hotspot/runtime/BasicType.java
0N/Aenum BasicType {
0N/A T_BOOLEAN = 4,
0N/A T_CHAR = 5,
0N/A T_FLOAT = 6,
0N/A T_DOUBLE = 7,
0N/A T_BYTE = 8,
0N/A T_SHORT = 9,
0N/A T_INT = 10,
0N/A T_LONG = 11,
0N/A T_OBJECT = 12,
0N/A T_ARRAY = 13,
0N/A T_VOID = 14,
0N/A T_ADDRESS = 15,
113N/A T_NARROWOOP= 16,
113N/A T_CONFLICT = 17, // for stack value type with conflicting contents
0N/A T_ILLEGAL = 99
0N/A};
0N/A
29N/Ainline bool is_java_primitive(BasicType t) {
29N/A return T_BOOLEAN <= t && t <= T_LONG;
29N/A}
29N/A
710N/Ainline bool is_subword_type(BasicType t) {
710N/A // these guys are processed exactly like T_INT in calling sequences:
710N/A return (t == T_BOOLEAN || t == T_CHAR || t == T_BYTE || t == T_SHORT);
710N/A}
710N/A
710N/Ainline bool is_signed_subword_type(BasicType t) {
710N/A return (t == T_BYTE || t == T_SHORT);
710N/A}
710N/A
0N/A// Convert a char from a classfile signature to a BasicType
0N/Ainline BasicType char2type(char c) {
0N/A switch( c ) {
0N/A case 'B': return T_BYTE;
0N/A case 'C': return T_CHAR;
0N/A case 'D': return T_DOUBLE;
0N/A case 'F': return T_FLOAT;
0N/A case 'I': return T_INT;
0N/A case 'J': return T_LONG;
0N/A case 'S': return T_SHORT;
0N/A case 'Z': return T_BOOLEAN;
0N/A case 'V': return T_VOID;
0N/A case 'L': return T_OBJECT;
0N/A case '[': return T_ARRAY;
0N/A }
0N/A return T_ILLEGAL;
0N/A}
0N/A
0N/Aextern char type2char_tab[T_CONFLICT+1]; // Map a BasicType to a jchar
0N/Ainline char type2char(BasicType t) { return (uint)t < T_CONFLICT+1 ? type2char_tab[t] : 0; }
0N/Aextern int type2size[T_CONFLICT+1]; // Map BasicType to result stack elements
0N/Aextern const char* type2name_tab[T_CONFLICT+1]; // Map a BasicType to a jchar
0N/Ainline const char* type2name(BasicType t) { return (uint)t < T_CONFLICT+1 ? type2name_tab[t] : NULL; }
0N/Aextern BasicType name2type(const char* name);
0N/A
0N/A// Auxilary math routines
0N/A// least common multiple
0N/Aextern size_t lcm(size_t a, size_t b);
0N/A
0N/A
0N/A// NOTE: replicated in SA in vm/agent/sun/jvm/hotspot/runtime/BasicType.java
0N/Aenum BasicTypeSize {
0N/A T_BOOLEAN_size = 1,
0N/A T_CHAR_size = 1,
0N/A T_FLOAT_size = 1,
0N/A T_DOUBLE_size = 2,
0N/A T_BYTE_size = 1,
0N/A T_SHORT_size = 1,
0N/A T_INT_size = 1,
0N/A T_LONG_size = 2,
0N/A T_OBJECT_size = 1,
0N/A T_ARRAY_size = 1,
113N/A T_NARROWOOP_size = 1,
0N/A T_VOID_size = 0
0N/A};
0N/A
0N/A
0N/A// maps a BasicType to its instance field storage type:
0N/A// all sub-word integral types are widened to T_INT
0N/Aextern BasicType type2field[T_CONFLICT+1];
0N/Aextern BasicType type2wfield[T_CONFLICT+1];
0N/A
0N/A
0N/A// size in bytes
0N/Aenum ArrayElementSize {
0N/A T_BOOLEAN_aelem_bytes = 1,
0N/A T_CHAR_aelem_bytes = 2,
0N/A T_FLOAT_aelem_bytes = 4,
0N/A T_DOUBLE_aelem_bytes = 8,
0N/A T_BYTE_aelem_bytes = 1,
0N/A T_SHORT_aelem_bytes = 2,
0N/A T_INT_aelem_bytes = 4,
0N/A T_LONG_aelem_bytes = 8,
0N/A#ifdef _LP64
0N/A T_OBJECT_aelem_bytes = 8,
0N/A T_ARRAY_aelem_bytes = 8,
0N/A#else
0N/A T_OBJECT_aelem_bytes = 4,
0N/A T_ARRAY_aelem_bytes = 4,
0N/A#endif
113N/A T_NARROWOOP_aelem_bytes = 4,
0N/A T_VOID_aelem_bytes = 0
0N/A};
0N/A
29N/Aextern int _type2aelembytes[T_CONFLICT+1]; // maps a BasicType to nof bytes used by its array element
29N/A#ifdef ASSERT
29N/Aextern int type2aelembytes(BasicType t, bool allow_address = false); // asserts
29N/A#else
1683N/Ainline int type2aelembytes(BasicType t, bool allow_address = false) { return _type2aelembytes[t]; }
29N/A#endif
0N/A
0N/A
0N/A// JavaValue serves as a container for arbitrary Java values.
0N/A
0N/Aclass JavaValue {
0N/A
0N/A public:
0N/A typedef union JavaCallValue {
0N/A jfloat f;
0N/A jdouble d;
0N/A jint i;
0N/A jlong l;
0N/A jobject h;
0N/A } JavaCallValue;
0N/A
0N/A private:
0N/A BasicType _type;
0N/A JavaCallValue _value;
0N/A
0N/A public:
0N/A JavaValue(BasicType t = T_ILLEGAL) { _type = t; }
0N/A
0N/A JavaValue(jfloat value) {
0N/A _type = T_FLOAT;
0N/A _value.f = value;
0N/A }
0N/A
0N/A JavaValue(jdouble value) {
0N/A _type = T_DOUBLE;
0N/A _value.d = value;
0N/A }
0N/A
0N/A jfloat get_jfloat() const { return _value.f; }
0N/A jdouble get_jdouble() const { return _value.d; }
0N/A jint get_jint() const { return _value.i; }
0N/A jlong get_jlong() const { return _value.l; }
0N/A jobject get_jobject() const { return _value.h; }
0N/A JavaCallValue* get_value_addr() { return &_value; }
0N/A BasicType get_type() const { return _type; }
0N/A
0N/A void set_jfloat(jfloat f) { _value.f = f;}
0N/A void set_jdouble(jdouble d) { _value.d = d;}
0N/A void set_jint(jint i) { _value.i = i;}
0N/A void set_jlong(jlong l) { _value.l = l;}
0N/A void set_jobject(jobject h) { _value.h = h;}
0N/A void set_type(BasicType t) { _type = t; }
0N/A
0N/A jboolean get_jboolean() const { return (jboolean) (_value.i);}
0N/A jbyte get_jbyte() const { return (jbyte) (_value.i);}
0N/A jchar get_jchar() const { return (jchar) (_value.i);}
0N/A jshort get_jshort() const { return (jshort) (_value.i);}
0N/A
0N/A};
0N/A
0N/A
0N/A#define STACK_BIAS 0
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#if defined(SPARC) && defined(_LP64)
0N/A#undef STACK_BIAS
0N/A#define STACK_BIAS 0x7ff
0N/A#endif
0N/A
0N/A
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
0N/Aenum TosState { // describes the tos cache contents
0N/A btos = 0, // byte, bool tos cached
726N/A ctos = 1, // char tos cached
726N/A stos = 2, // short tos cached
0N/A itos = 3, // int tos cached
0N/A ltos = 4, // long tos cached
0N/A ftos = 5, // float tos cached
0N/A dtos = 6, // double tos cached
0N/A atos = 7, // object cached
0N/A vtos = 8, // tos not cached
0N/A number_of_states,
0N/A ilgl // illegal state: should not occur
0N/A};
0N/A
0N/A
0N/Ainline TosState as_TosState(BasicType type) {
0N/A switch (type) {
0N/A case T_BYTE : return btos;
726N/A case T_BOOLEAN: return btos; // FIXME: Add ztos
0N/A case T_CHAR : return ctos;
0N/A case T_SHORT : return stos;
0N/A case T_INT : return itos;
0N/A case T_LONG : return ltos;
0N/A case T_FLOAT : return ftos;
0N/A case T_DOUBLE : return dtos;
0N/A case T_VOID : return vtos;
0N/A case T_ARRAY : // fall through
0N/A case T_OBJECT : return atos;
0N/A }
0N/A return ilgl;
0N/A}
0N/A
726N/Ainline BasicType as_BasicType(TosState state) {
726N/A switch (state) {
726N/A //case ztos: return T_BOOLEAN;//FIXME
726N/A case btos : return T_BYTE;
726N/A case ctos : return T_CHAR;
726N/A case stos : return T_SHORT;
726N/A case itos : return T_INT;
726N/A case ltos : return T_LONG;
726N/A case ftos : return T_FLOAT;
726N/A case dtos : return T_DOUBLE;
726N/A case atos : return T_OBJECT;
726N/A case vtos : return T_VOID;
726N/A }
726N/A return T_ILLEGAL;
726N/A}
726N/A
0N/A
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/ATosState as_TosState(BasicType type);
0N/A
0N/A
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//
0N/A// There are 4 essential states:
0N/A//
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//
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//
0N/A// Given a state, the xxx_trans state can always be found by adding 1.
0N/A//
0N/Aenum JavaThreadState {
0N/A _thread_uninitialized = 0, // should never happen (missing initialization)
0N/A _thread_new = 2, // just starting up, i.e., in process of being initialized
0N/A _thread_new_trans = 3, // corresponding transition state (not used, included for completness)
0N/A _thread_in_native = 4, // running in native code
0N/A _thread_in_native_trans = 5, // corresponding transition state
0N/A _thread_in_vm = 6, // running in VM
0N/A _thread_in_vm_trans = 7, // corresponding transition state
0N/A _thread_in_Java = 8, // running in Java or in stub code
0N/A _thread_in_Java_trans = 9, // corresponding transition state (not used, included for completness)
0N/A _thread_blocked = 10, // blocked in vm
0N/A _thread_blocked_trans = 11, // corresponding transition state
0N/A _thread_max_state = 12 // maximum thread state+1 - used for statistics allocation
0N/A};
0N/A
0N/A
0N/A// Handy constants for deciding which compiler mode to use.
0N/Aenum MethodCompilation {
0N/A InvocationEntryBci = -1, // i.e., not a on-stack replacement compilation
0N/A InvalidOSREntryBci = -2
0N/A};
0N/A
0N/A// Enumeration to distinguish tiers of compilation
0N/Aenum CompLevel {
1703N/A CompLevel_any = -1,
1703N/A CompLevel_all = -1,
1703N/A CompLevel_none = 0, // Interpreter
1703N/A CompLevel_simple = 1, // C1
1703N/A CompLevel_limited_profile = 2, // C1, invocation & backedge counters
1703N/A CompLevel_full_profile = 3, // C1, invocation & backedge counters + mdo
2294N/A CompLevel_full_optimization = 4, // C2 or Shark
0N/A
2294N/A#if defined(COMPILER2) || defined(SHARK)
1703N/A CompLevel_highest_tier = CompLevel_full_optimization, // pure C2 and tiered
1703N/A#elif defined(COMPILER1)
1703N/A CompLevel_highest_tier = CompLevel_simple, // pure C1
0N/A#else
1703N/A CompLevel_highest_tier = CompLevel_none,
1703N/A#endif
1703N/A
1703N/A#if defined(TIERED)
1703N/A CompLevel_initial_compile = CompLevel_full_profile // tiered
1703N/A#elif defined(COMPILER1)
1703N/A CompLevel_initial_compile = CompLevel_simple // pure C1
2294N/A#elif defined(COMPILER2) || defined(SHARK)
1703N/A CompLevel_initial_compile = CompLevel_full_optimization // pure C2
1703N/A#else
1703N/A CompLevel_initial_compile = CompLevel_none
1703N/A#endif
0N/A};
0N/A
1703N/Ainline bool is_c1_compile(int comp_level) {
1703N/A return comp_level > CompLevel_none && comp_level < CompLevel_full_optimization;
0N/A}
1703N/A
1703N/Ainline bool is_c2_compile(int comp_level) {
0N/A return comp_level == CompLevel_full_optimization;
0N/A}
1703N/A
0N/Ainline bool is_highest_tier_compile(int comp_level) {
0N/A return comp_level == CompLevel_highest_tier;
0N/A}
0N/A
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
0N/Aclass symbolTable;
0N/Aclass ClassFileStream;
0N/A
0N/Aclass Event;
0N/A
0N/Aclass Thread;
0N/Aclass VMThread;
0N/Aclass JavaThread;
0N/Aclass Threads;
0N/A
0N/Aclass VM_Operation;
0N/Aclass VMOperationQueue;
0N/A
0N/Aclass CodeBlob;
0N/Aclass nmethod;
0N/Aclass OSRAdapter;
0N/Aclass I2CAdapter;
0N/Aclass C2IAdapter;
0N/Aclass CompiledIC;
0N/Aclass relocInfo;
0N/Aclass ScopeDesc;
0N/Aclass PcDesc;
0N/A
0N/Aclass Recompiler;
0N/Aclass Recompilee;
0N/Aclass RecompilationPolicy;
0N/Aclass RFrame;
0N/Aclass CompiledRFrame;
0N/Aclass InterpretedRFrame;
0N/A
0N/Aclass frame;
0N/A
0N/Aclass vframe;
0N/Aclass javaVFrame;
0N/Aclass interpretedVFrame;
0N/Aclass compiledVFrame;
0N/Aclass deoptimizedVFrame;
0N/Aclass externalVFrame;
0N/Aclass entryVFrame;
0N/A
0N/Aclass RegisterMap;
0N/A
0N/Aclass Mutex;
0N/Aclass Monitor;
0N/Aclass BasicLock;
0N/Aclass BasicObjectLock;
0N/A
0N/Aclass PeriodicTask;
0N/A
0N/Aclass JavaCallWrapper;
0N/A
0N/Aclass oopDesc;
0N/A
0N/Aclass NativeCall;
0N/A
0N/Aclass zone;
0N/A
0N/Aclass StubQueue;
0N/A
0N/Aclass outputStream;
0N/A
0N/Aclass ResourceArea;
0N/A
0N/Aclass DebugInformationRecorder;
0N/Aclass ScopeValue;
0N/Aclass CompressedStream;
0N/Aclass DebugInfoReadStream;
0N/Aclass DebugInfoWriteStream;
0N/Aclass LocationValue;
0N/Aclass ConstantValue;
0N/Aclass IllegalValue;
0N/A
0N/Aclass PrivilegedElement;
0N/Aclass MonitorArray;
0N/A
0N/Aclass MonitorInfo;
0N/A
0N/Aclass OffsetClosure;
0N/Aclass OopMapCache;
0N/Aclass InterpreterOopMap;
0N/Aclass OopMapCacheEntry;
0N/Aclass OSThread;
0N/A
0N/Atypedef int (*OSThreadStartFunc)(void*);
0N/A
0N/Aclass Space;
0N/A
0N/Aclass JavaValue;
0N/Aclass methodHandle;
0N/Aclass JavaCallArguments;
0N/A
0N/A// Basic support for errors (general debug facilities not defined at this point fo the include phase)
0N/A
0N/Aextern void basic_fatal(const char* msg);
0N/A
0N/A
0N/A//----------------------------------------------------------------------------------------------------
0N/A// Special constants for debugging
0N/A
0N/Aconst jint badInt = -3; // generic "bad int" value
0N/Aconst long badAddressVal = -2; // generic "bad address" value
0N/Aconst long badOopVal = -1; // generic "bad oop" value
0N/Aconst intptr_t badHeapOopVal = (intptr_t) CONST64(0x2BAD4B0BBAADBABE); // value used to zap heap after GC
0N/Aconst int badHandleValue = 0xBC; // value used to zap vm handle area
0N/Aconst int badResourceValue = 0xAB; // value used to zap resource area
0N/Aconst int freeBlockPad = 0xBA; // value used to pad freed blocks.
0N/Aconst int uninitBlockPad = 0xF1; // value used to zap newly malloc'd blocks.
0N/Aconst intptr_t badJNIHandleVal = (intptr_t) CONST64(0xFEFEFEFEFEFEFEFE); // value used to zap jni handle area
0N/Aconst juint badHeapWordVal = 0xBAADBABE; // value used to zap heap after GC
0N/Aconst int badCodeHeapNewVal= 0xCC; // value used to zap Code heap at allocation
0N/Aconst int badCodeHeapFreeVal = 0xDD; // value used to zap Code heap at deallocation
0N/A
0N/A
0N/A// (These must be implemented as #defines because C++ compilers are
0N/A// not obligated to inline non-integral constants!)
0N/A#define badAddress ((address)::badAddressVal)
0N/A#define badOop ((oop)::badOopVal)
0N/A#define badHeapWord (::badHeapWordVal)
0N/A#define badJNIHandle ((oop)::badJNIHandleVal)
0N/A
1311N/A// Default TaskQueue size is 16K (32-bit) or 128K (64-bit)
1311N/A#define TASKQUEUE_SIZE (NOT_LP64(1<<14) LP64_ONLY(1<<17))
0N/A
0N/A//----------------------------------------------------------------------------------------------------
0N/A// Utility functions for bitfield manipulations
0N/A
0N/Aconst intptr_t AllBits = ~0; // all bits set in a word
0N/Aconst intptr_t NoBits = 0; // no bits set in a word
0N/Aconst jlong NoLongBits = 0; // no bits set in a long
0N/Aconst intptr_t OneBit = 1; // only right_most bit set in a word
0N/A
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#define nth_bit(n) (n >= BitsPerWord ? 0 : OneBit << (n))
0N/A#define right_n_bits(n) (nth_bit(n) - 1)
0N/A#define left_n_bits(n) (right_n_bits(n) << (n >= BitsPerWord ? 0 : (BitsPerWord - n)))
0N/A
0N/A// bit-operations using a mask m
0N/Ainline void set_bits (intptr_t& x, intptr_t m) { x |= m; }
0N/Ainline void clear_bits (intptr_t& x, intptr_t m) { x &= ~m; }
0N/Ainline intptr_t mask_bits (intptr_t x, intptr_t m) { return x & m; }
0N/Ainline jlong mask_long_bits (jlong x, jlong m) { return x & m; }
0N/Ainline bool mask_bits_are_true (intptr_t flags, intptr_t mask) { return (flags & mask) == mask; }
0N/A
0N/A// bit-operations using the n.th bit
0N/Ainline void set_nth_bit(intptr_t& x, int n) { set_bits (x, nth_bit(n)); }
0N/Ainline void clear_nth_bit(intptr_t& x, int n) { clear_bits(x, nth_bit(n)); }
0N/Ainline bool is_set_nth_bit(intptr_t x, int n) { return mask_bits (x, nth_bit(n)) != NoBits; }
0N/A
0N/A// returns the bitfield of x starting at start_bit_no with length field_length (no sign-extension!)
0N/Ainline intptr_t bitfield(intptr_t x, int start_bit_no, int field_length) {
0N/A return mask_bits(x >> start_bit_no, right_n_bits(field_length));
0N/A}
0N/A
0N/A
0N/A//----------------------------------------------------------------------------------------------------
0N/A// Utility functions for integers
0N/A
0N/A// Avoid use of global min/max macros which may cause unwanted double
0N/A// evaluation of arguments.
0N/A#ifdef max
0N/A#undef max
0N/A#endif
0N/A
0N/A#ifdef min
0N/A#undef min
0N/A#endif
0N/A
0N/A#define max(a,b) Do_not_use_max_use_MAX2_instead
0N/A#define min(a,b) Do_not_use_min_use_MIN2_instead
0N/A
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/A
0N/Atemplate<class T> inline T ABS(T x) { return (x > 0) ? x : -x; }
0N/A
0N/A// true if x is a power of 2, false otherwise
0N/Ainline bool is_power_of_2(intptr_t x) {
0N/A return ((x != NoBits) && (mask_bits(x, x - 1) == NoBits));
0N/A}
0N/A
0N/A// long version of is_power_of_2
0N/Ainline bool is_power_of_2_long(jlong x) {
0N/A return ((x != NoLongBits) && (mask_long_bits(x, x - 1) == NoLongBits));
0N/A}
0N/A
0N/A//* largest i such that 2^i <= x
0N/A// A negative value of 'x' will return '31'
0N/Ainline int log2_intptr(intptr_t x) {
0N/A int i = -1;
0N/A uintptr_t p = 1;
0N/A while (p != 0 && p <= (uintptr_t)x) {
0N/A // p = 2^(i+1) && p <= x (i.e., 2^(i+1) <= x)
0N/A i++; p *= 2;
0N/A }
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 return i;
0N/A}
0N/A
0N/A//* largest i such that 2^i <= x
0N/A// A negative value of 'x' will return '63'
0N/Ainline int log2_long(jlong x) {
0N/A int i = -1;
0N/A julong p = 1;
0N/A while (p != 0 && p <= (julong)x) {
0N/A // p = 2^(i+1) && p <= x (i.e., 2^(i+1) <= x)
0N/A i++; p *= 2;
0N/A }
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 return i;
0N/A}
0N/A
0N/A//* the argument must be exactly a power of 2
0N/Ainline int exact_log2(intptr_t x) {
0N/A #ifdef ASSERT
0N/A if (!is_power_of_2(x)) basic_fatal("x must be a power of 2");
0N/A #endif
0N/A return log2_intptr(x);
0N/A}
0N/A
568N/A//* the argument must be exactly a power of 2
568N/Ainline int exact_log2_long(jlong x) {
568N/A #ifdef ASSERT
568N/A if (!is_power_of_2_long(x)) basic_fatal("x must be a power of 2");
568N/A #endif
568N/A return log2_long(x);
568N/A}
568N/A
0N/A
0N/A// returns integer round-up to the nearest multiple of s (s must be a power of two)
0N/Ainline intptr_t round_to(intptr_t x, uintx s) {
0N/A #ifdef ASSERT
0N/A if (!is_power_of_2(s)) basic_fatal("s must be a power of 2");
0N/A #endif
0N/A const uintx m = s - 1;
0N/A return mask_bits(x + m, ~m);
0N/A}
0N/A
0N/A// returns integer round-down to the nearest multiple of s (s must be a power of two)
0N/Ainline intptr_t round_down(intptr_t x, uintx s) {
0N/A #ifdef ASSERT
0N/A if (!is_power_of_2(s)) basic_fatal("s must be a power of 2");
0N/A #endif
0N/A const uintx m = s - 1;
0N/A return mask_bits(x, ~m);
0N/A}
0N/A
0N/A
0N/Ainline bool is_odd (intx x) { return x & 1; }
0N/Ainline bool is_even(intx x) { return !is_odd(x); }
0N/A
0N/A// "to" should be greater than "from."
0N/Ainline intx byte_size(void* from, void* to) {
0N/A return (address)to - (address)from;
0N/A}
0N/A
0N/A//----------------------------------------------------------------------------------------------------
0N/A// Avoid non-portable casts with these routines (DEPRECATED)
0N/A
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
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//
0N/A
0N/A// This routine takes eight bytes:
0N/Ainline u8 build_u8_from( u1 c1, u1 c2, u1 c3, u1 c4, u1 c5, u1 c6, u1 c7, u1 c8 ) {
1709N/A return (( u8(c1) << 56 ) & ( u8(0xff) << 56 ))
1709N/A | (( u8(c2) << 48 ) & ( u8(0xff) << 48 ))
1709N/A | (( u8(c3) << 40 ) & ( u8(0xff) << 40 ))
1709N/A | (( u8(c4) << 32 ) & ( u8(0xff) << 32 ))
1709N/A | (( u8(c5) << 24 ) & ( u8(0xff) << 24 ))
1709N/A | (( u8(c6) << 16 ) & ( u8(0xff) << 16 ))
1709N/A | (( u8(c7) << 8 ) & ( u8(0xff) << 8 ))
1709N/A | (( u8(c8) << 0 ) & ( u8(0xff) << 0 ));
0N/A}
0N/A
0N/A// This routine takes four bytes:
0N/Ainline u4 build_u4_from( u1 c1, u1 c2, u1 c3, u1 c4 ) {
1709N/A return (( u4(c1) << 24 ) & 0xff000000)
1709N/A | (( u4(c2) << 16 ) & 0x00ff0000)
1709N/A | (( u4(c3) << 8 ) & 0x0000ff00)
1709N/A | (( u4(c4) << 0 ) & 0x000000ff);
0N/A}
0N/A
0N/A// And this one works if the four bytes are contiguous in memory:
0N/Ainline u4 build_u4_from( u1* p ) {
0N/A return build_u4_from( p[0], p[1], p[2], p[3] );
0N/A}
0N/A
0N/A// Ditto for two-byte ints:
0N/Ainline u2 build_u2_from( u1 c1, u1 c2 ) {
1709N/A return u2((( u2(c1) << 8 ) & 0xff00)
1709N/A | (( u2(c2) << 0 ) & 0x00ff));
0N/A}
0N/A
0N/A// And this one works if the two bytes are contiguous in memory:
0N/Ainline u2 build_u2_from( u1* p ) {
0N/A return build_u2_from( p[0], p[1] );
0N/A}
0N/A
0N/A// Ditto for floats:
0N/Ainline jfloat build_float_from( u1 c1, u1 c2, u1 c3, u1 c4 ) {
0N/A u4 u = build_u4_from( c1, c2, c3, c4 );
0N/A return *(jfloat*)&u;
0N/A}
0N/A
0N/Ainline jfloat build_float_from( u1* p ) {
0N/A u4 u = build_u4_from( p );
0N/A return *(jfloat*)&u;
0N/A}
0N/A
0N/A
0N/A// now (64-bit) longs
0N/A
0N/Ainline jlong build_long_from( u1 c1, u1 c2, u1 c3, u1 c4, u1 c5, u1 c6, u1 c7, u1 c8 ) {
1709N/A return (( jlong(c1) << 56 ) & ( jlong(0xff) << 56 ))
1709N/A | (( jlong(c2) << 48 ) & ( jlong(0xff) << 48 ))
1709N/A | (( jlong(c3) << 40 ) & ( jlong(0xff) << 40 ))
1709N/A | (( jlong(c4) << 32 ) & ( jlong(0xff) << 32 ))
1709N/A | (( jlong(c5) << 24 ) & ( jlong(0xff) << 24 ))
1709N/A | (( jlong(c6) << 16 ) & ( jlong(0xff) << 16 ))
1709N/A | (( jlong(c7) << 8 ) & ( jlong(0xff) << 8 ))
1709N/A | (( jlong(c8) << 0 ) & ( jlong(0xff) << 0 ));
0N/A}
0N/A
0N/Ainline jlong build_long_from( u1* p ) {
0N/A return build_long_from( p[0], p[1], p[2], p[3], p[4], p[5], p[6], p[7] );
0N/A}
0N/A
0N/A
0N/A// Doubles, too!
0N/Ainline jdouble build_double_from( u1 c1, u1 c2, u1 c3, u1 c4, u1 c5, u1 c6, u1 c7, u1 c8 ) {
0N/A jlong u = build_long_from( c1, c2, c3, c4, c5, c6, c7, c8 );
0N/A return *(jdouble*)&u;
0N/A}
0N/A
0N/Ainline jdouble build_double_from( u1* p ) {
0N/A jlong u = build_long_from( p );
0N/A return *(jdouble*)&u;
0N/A}
0N/A
0N/A
0N/A// Portable routines to go the other way:
0N/A
0N/Ainline void explode_short_to( u2 x, u1& c1, u1& c2 ) {
0N/A c1 = u1(x >> 8);
0N/A c2 = u1(x);
0N/A}
0N/A
0N/Ainline void explode_short_to( u2 x, u1* p ) {
0N/A explode_short_to( x, p[0], p[1]);
0N/A}
0N/A
0N/Ainline void explode_int_to( u4 x, u1& c1, u1& c2, u1& c3, u1& c4 ) {
0N/A c1 = u1(x >> 24);
0N/A c2 = u1(x >> 16);
0N/A c3 = u1(x >> 8);
0N/A c4 = u1(x);
0N/A}
0N/A
0N/Ainline void explode_int_to( u4 x, u1* p ) {
0N/A explode_int_to( x, p[0], p[1], p[2], p[3]);
0N/A}
0N/A
0N/A
0N/A// Pack and extract shorts to/from ints:
0N/A
0N/Ainline int extract_low_short_from_int(jint x) {
0N/A return x & 0xffff;
0N/A}
0N/A
0N/Ainline int extract_high_short_from_int(jint x) {
0N/A return (x >> 16) & 0xffff;
0N/A}
0N/A
0N/Ainline int build_int_from_shorts( jushort low, jushort high ) {
0N/A return ((int)((unsigned int)high << 16) | (unsigned int)low);
0N/A}
0N/A
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
2796N/A// the compiler-specific definitions file (e.g., globalDefinitions_gcc.hpp)
0N/A
2208N/A#define BOOL_TO_STR(_b_) ((_b_) ? "true" : "false")
2037N/A
0N/A// Format 32-bit quantities.
2796N/A#define INT32_FORMAT "%" PRId32
2796N/A#define UINT32_FORMAT "%" PRIu32
2796N/A#define INT32_FORMAT_W(width) "%" #width PRId32
2796N/A#define UINT32_FORMAT_W(width) "%" #width PRIu32
0N/A
2796N/A#define PTR32_FORMAT "0x%08" PRIx32
0N/A
0N/A// Format 64-bit quantities.
2796N/A#define INT64_FORMAT "%" PRId64
2796N/A#define UINT64_FORMAT "%" PRIu64
2796N/A#define INT64_FORMAT_W(width) "%" #width PRId64
2796N/A#define UINT64_FORMAT_W(width) "%" #width PRIu64
0N/A
2796N/A#define PTR64_FORMAT "0x%016" PRIx64
0N/A
2796N/A// Format pointers which change size between 32- and 64-bit.
0N/A#ifdef _LP64
2796N/A#define INTPTR_FORMAT "0x%016" PRIxPTR
2796N/A#define PTR_FORMAT "0x%016" PRIxPTR
0N/A#else // !_LP64
2796N/A#define INTPTR_FORMAT "0x%08" PRIxPTR
2796N/A#define PTR_FORMAT "0x%08" PRIxPTR
0N/A#endif // _LP64
0N/A
2796N/A#define SSIZE_FORMAT "%" PRIdPTR
2796N/A#define SIZE_FORMAT "%" PRIuPTR
2796N/A#define SSIZE_FORMAT_W(width) "%" #width PRIdPTR
2796N/A#define SIZE_FORMAT_W(width) "%" #width PRIuPTR
2796N/A
2796N/A#define INTX_FORMAT "%" PRIdPTR
2796N/A#define UINTX_FORMAT "%" PRIuPTR
2796N/A#define INTX_FORMAT_W(width) "%" #width PRIdPTR
2796N/A#define UINTX_FORMAT_W(width) "%" #width PRIuPTR
2796N/A
0N/A
0N/A// Enable zap-a-lot if in debug version.
0N/A
0N/A# ifdef ASSERT
0N/A# ifdef COMPILER2
0N/A# define ENABLE_ZAP_DEAD_LOCALS
0N/A#endif /* COMPILER2 */
0N/A# endif /* ASSERT */
0N/A
0N/A#define ARRAY_SIZE(array) (sizeof(array)/sizeof((array)[0]))
1879N/A
1879N/A#endif // SHARE_VM_UTILITIES_GLOBALDEFINITIONS_HPP