globalDefinitions.hpp revision 513:2328d1d3f8cf
1190214Srpaulo/* 2190214Srpaulo * Copyright 1997-2008 Sun Microsystems, Inc. All Rights Reserved. 3190214Srpaulo * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4190214Srpaulo * 5190214Srpaulo * This code is free software; you can redistribute it and/or modify it 6190214Srpaulo * under the terms of the GNU General Public License version 2 only, as 7190214Srpaulo * published by the Free Software Foundation. 8190214Srpaulo * 9190214Srpaulo * This code is distributed in the hope that it will be useful, but WITHOUT 10190214Srpaulo * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 11190214Srpaulo * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 12190214Srpaulo * version 2 for more details (a copy is included in the LICENSE file that 13190214Srpaulo * accompanied this code). 14190214Srpaulo * 15190214Srpaulo * You should have received a copy of the GNU General Public License version 16190214Srpaulo * 2 along with this work; if not, write to the Free Software Foundation, 17190214Srpaulo * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 18190214Srpaulo * 19190214Srpaulo * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, 20190214Srpaulo * CA 95054 USA or visit www.sun.com if you need additional information or 21190214Srpaulo * have any questions. 22190214Srpaulo * 23190214Srpaulo */ 24190214Srpaulo 25190214Srpaulo// This file holds all globally used constants & types, class (forward) 26190214Srpaulo// declarations and a few frequently used utility functions. 27190214Srpaulo 28190214Srpaulo//---------------------------------------------------------------------------------------------------- 29190214Srpaulo// Constants 30190214Srpaulo 31190214Srpauloconst int LogBytesPerShort = 1; 32190214Srpauloconst int LogBytesPerInt = 2; 33190214Srpaulo#ifdef _LP64 34190214Srpauloconst int LogBytesPerWord = 3; 35190214Srpaulo#else 36190214Srpauloconst int LogBytesPerWord = 2; 37190214Srpaulo#endif 38190214Srpauloconst int LogBytesPerLong = 3; 39190214Srpaulo 40190214Srpauloconst int BytesPerShort = 1 << LogBytesPerShort; 41190214Srpauloconst int BytesPerInt = 1 << LogBytesPerInt; 42190214Srpauloconst int BytesPerWord = 1 << LogBytesPerWord; 43const int BytesPerLong = 1 << LogBytesPerLong; 44 45const int LogBitsPerByte = 3; 46const int LogBitsPerShort = LogBitsPerByte + LogBytesPerShort; 47const int LogBitsPerInt = LogBitsPerByte + LogBytesPerInt; 48const int LogBitsPerWord = LogBitsPerByte + LogBytesPerWord; 49const int LogBitsPerLong = LogBitsPerByte + LogBytesPerLong; 50 51const int BitsPerByte = 1 << LogBitsPerByte; 52const int BitsPerShort = 1 << LogBitsPerShort; 53const int BitsPerInt = 1 << LogBitsPerInt; 54const int BitsPerWord = 1 << LogBitsPerWord; 55const int BitsPerLong = 1 << LogBitsPerLong; 56 57const int WordAlignmentMask = (1 << LogBytesPerWord) - 1; 58const int LongAlignmentMask = (1 << LogBytesPerLong) - 1; 59 60const int WordsPerLong = 2; // Number of stack entries for longs 61 62const int oopSize = sizeof(char*); // Full-width oop 63extern int heapOopSize; // Oop within a java object 64const int wordSize = sizeof(char*); 65const int longSize = sizeof(jlong); 66const int jintSize = sizeof(jint); 67const int size_tSize = sizeof(size_t); 68 69const int BytesPerOop = BytesPerWord; // Full-width oop 70 71extern int LogBytesPerHeapOop; // Oop within a java object 72extern int LogBitsPerHeapOop; 73extern int BytesPerHeapOop; 74extern int BitsPerHeapOop; 75 76const int BitsPerJavaInteger = 32; 77const int BitsPerSize_t = size_tSize * BitsPerByte; 78 79// Size of a char[] needed to represent a jint as a string in decimal. 80const int jintAsStringSize = 12; 81 82// In fact this should be 83// log2_intptr(sizeof(class JavaThread)) - log2_intptr(64); 84// see os::set_memory_serialize_page() 85#ifdef _LP64 86const int SerializePageShiftCount = 4; 87#else 88const int SerializePageShiftCount = 3; 89#endif 90 91// An opaque struct of heap-word width, so that HeapWord* can be a generic 92// pointer into the heap. We require that object sizes be measured in 93// units of heap words, so that that 94// HeapWord* hw; 95// hw += oop(hw)->foo(); 96// works, where foo is a method (like size or scavenge) that returns the 97// object size. 98class HeapWord { 99 friend class VMStructs; 100 private: 101 char* i; 102#ifndef PRODUCT 103 public: 104 char* value() { return i; } 105#endif 106}; 107 108// HeapWordSize must be 2^LogHeapWordSize. 109const int HeapWordSize = sizeof(HeapWord); 110#ifdef _LP64 111const int LogHeapWordSize = 3; 112#else 113const int LogHeapWordSize = 2; 114#endif 115const int HeapWordsPerLong = BytesPerLong / HeapWordSize; 116const int LogHeapWordsPerLong = LogBytesPerLong - LogHeapWordSize; 117 118// The larger HeapWordSize for 64bit requires larger heaps 119// for the same application running in 64bit. See bug 4967770. 120// The minimum alignment to a heap word size is done. Other 121// parts of the memory system may required additional alignment 122// and are responsible for those alignments. 123#ifdef _LP64 124#define ScaleForWordSize(x) align_size_down_((x) * 13 / 10, HeapWordSize) 125#else 126#define ScaleForWordSize(x) (x) 127#endif 128 129// The minimum number of native machine words necessary to contain "byte_size" 130// bytes. 131inline size_t heap_word_size(size_t byte_size) { 132 return (byte_size + (HeapWordSize-1)) >> LogHeapWordSize; 133} 134 135 136const size_t K = 1024; 137const size_t M = K*K; 138const size_t G = M*K; 139const size_t HWperKB = K / sizeof(HeapWord); 140 141const jint min_jint = (jint)1 << (sizeof(jint)*BitsPerByte-1); // 0x80000000 == smallest jint 142const jint max_jint = (juint)min_jint - 1; // 0x7FFFFFFF == largest jint 143 144// Constants for converting from a base unit to milli-base units. For 145// example from seconds to milliseconds and microseconds 146 147const int MILLIUNITS = 1000; // milli units per base unit 148const int MICROUNITS = 1000000; // micro units per base unit 149const int NANOUNITS = 1000000000; // nano units per base unit 150 151inline const char* proper_unit_for_byte_size(size_t s) { 152 if (s >= 10*M) { 153 return "M"; 154 } else if (s >= 10*K) { 155 return "K"; 156 } else { 157 return "B"; 158 } 159} 160 161inline size_t byte_size_in_proper_unit(size_t s) { 162 if (s >= 10*M) { 163 return s/M; 164 } else if (s >= 10*K) { 165 return s/K; 166 } else { 167 return s; 168 } 169} 170 171 172//---------------------------------------------------------------------------------------------------- 173// VM type definitions 174 175// intx and uintx are the 'extended' int and 'extended' unsigned int types; 176// they are 32bit wide on a 32-bit platform, and 64bit wide on a 64bit platform. 177 178typedef intptr_t intx; 179typedef uintptr_t uintx; 180 181const intx min_intx = (intx)1 << (sizeof(intx)*BitsPerByte-1); 182const intx max_intx = (uintx)min_intx - 1; 183const uintx max_uintx = (uintx)-1; 184 185// Table of values: 186// sizeof intx 4 8 187// min_intx 0x80000000 0x8000000000000000 188// max_intx 0x7FFFFFFF 0x7FFFFFFFFFFFFFFF 189// max_uintx 0xFFFFFFFF 0xFFFFFFFFFFFFFFFF 190 191typedef unsigned int uint; NEEDS_CLEANUP 192 193 194//---------------------------------------------------------------------------------------------------- 195// Java type definitions 196 197// All kinds of 'plain' byte addresses 198typedef signed char s_char; 199typedef unsigned char u_char; 200typedef u_char* address; 201typedef uintptr_t address_word; // unsigned integer which will hold a pointer 202 // except for some implementations of a C++ 203 // linkage pointer to function. Should never 204 // need one of those to be placed in this 205 // type anyway. 206 207// Utility functions to "portably" (?) bit twiddle pointers 208// Where portable means keep ANSI C++ compilers quiet 209 210inline address set_address_bits(address x, int m) { return address(intptr_t(x) | m); } 211inline address clear_address_bits(address x, int m) { return address(intptr_t(x) & ~m); } 212 213// Utility functions to "portably" make cast to/from function pointers. 214 215inline address_word mask_address_bits(address x, int m) { return address_word(x) & m; } 216inline address_word castable_address(address x) { return address_word(x) ; } 217inline address_word castable_address(void* x) { return address_word(x) ; } 218 219// Pointer subtraction. 220// The idea here is to avoid ptrdiff_t, which is signed and so doesn't have 221// the range we might need to find differences from one end of the heap 222// to the other. 223// A typical use might be: 224// if (pointer_delta(end(), top()) >= size) { 225// // enough room for an object of size 226// ... 227// and then additions like 228// ... top() + size ... 229// are safe because we know that top() is at least size below end(). 230inline size_t pointer_delta(const void* left, 231 const void* right, 232 size_t element_size) { 233 return (((uintptr_t) left) - ((uintptr_t) right)) / element_size; 234} 235// A version specialized for HeapWord*'s. 236inline size_t pointer_delta(const HeapWord* left, const HeapWord* right) { 237 return pointer_delta(left, right, sizeof(HeapWord)); 238} 239 240// 241// ANSI C++ does not allow casting from one pointer type to a function pointer 242// directly without at best a warning. This macro accomplishes it silently 243// In every case that is present at this point the value be cast is a pointer 244// to a C linkage function. In somecase the type used for the cast reflects 245// that linkage and a picky compiler would not complain. In other cases because 246// there is no convenient place to place a typedef with extern C linkage (i.e 247// a platform dependent header file) it doesn't. At this point no compiler seems 248// picky enough to catch these instances (which are few). It is possible that 249// using templates could fix these for all cases. This use of templates is likely 250// so far from the middle of the road that it is likely to be problematic in 251// many C++ compilers. 252// 253#define CAST_TO_FN_PTR(func_type, value) ((func_type)(castable_address(value))) 254#define CAST_FROM_FN_PTR(new_type, func_ptr) ((new_type)((address_word)(func_ptr))) 255 256// Unsigned byte types for os and stream.hpp 257 258// Unsigned one, two, four and eigth byte quantities used for describing 259// the .class file format. See JVM book chapter 4. 260 261typedef jubyte u1; 262typedef jushort u2; 263typedef juint u4; 264typedef julong u8; 265 266const jubyte max_jubyte = (jubyte)-1; // 0xFF largest jubyte 267const jushort max_jushort = (jushort)-1; // 0xFFFF largest jushort 268const juint max_juint = (juint)-1; // 0xFFFFFFFF largest juint 269const julong max_julong = (julong)-1; // 0xFF....FF largest julong 270 271//---------------------------------------------------------------------------------------------------- 272// JVM spec restrictions 273 274const int max_method_code_size = 64*K - 1; // JVM spec, 2nd ed. section 4.8.1 (p.134) 275 276 277//---------------------------------------------------------------------------------------------------- 278// HotSwap - for JVMTI aka Class File Replacement and PopFrame 279// 280// Determines whether on-the-fly class replacement and frame popping are enabled. 281 282#define HOTSWAP 283 284//---------------------------------------------------------------------------------------------------- 285// Object alignment, in units of HeapWords. 286// 287// Minimum is max(BytesPerLong, BytesPerDouble, BytesPerOop) / HeapWordSize, so jlong, jdouble and 288// reference fields can be naturally aligned. 289 290const int MinObjAlignment = HeapWordsPerLong; 291const int MinObjAlignmentInBytes = MinObjAlignment * HeapWordSize; 292const int MinObjAlignmentInBytesMask = MinObjAlignmentInBytes - 1; 293 294const int LogMinObjAlignment = LogHeapWordsPerLong; 295const int LogMinObjAlignmentInBytes = LogMinObjAlignment + LogHeapWordSize; 296 297// Machine dependent stuff 298 299#include "incls/_globalDefinitions_pd.hpp.incl" 300 301// The byte alignment to be used by Arena::Amalloc. See bugid 4169348. 302// Note: this value must be a power of 2 303 304#define ARENA_AMALLOC_ALIGNMENT (2*BytesPerWord) 305 306// Signed variants of alignment helpers. There are two versions of each, a macro 307// for use in places like enum definitions that require compile-time constant 308// expressions and a function for all other places so as to get type checking. 309 310#define align_size_up_(size, alignment) (((size) + ((alignment) - 1)) & ~((alignment) - 1)) 311 312inline intptr_t align_size_up(intptr_t size, intptr_t alignment) { 313 return align_size_up_(size, alignment); 314} 315 316#define align_size_down_(size, alignment) ((size) & ~((alignment) - 1)) 317 318inline intptr_t align_size_down(intptr_t size, intptr_t alignment) { 319 return align_size_down_(size, alignment); 320} 321 322// Align objects by rounding up their size, in HeapWord units. 323 324#define align_object_size_(size) align_size_up_(size, MinObjAlignment) 325 326inline intptr_t align_object_size(intptr_t size) { 327 return align_size_up(size, MinObjAlignment); 328} 329 330// Pad out certain offsets to jlong alignment, in HeapWord units. 331 332#define align_object_offset_(offset) align_size_up_(offset, HeapWordsPerLong) 333 334inline intptr_t align_object_offset(intptr_t offset) { 335 return align_size_up(offset, HeapWordsPerLong); 336} 337 338inline bool is_object_aligned(intptr_t offset) { 339 return offset == align_object_offset(offset); 340} 341 342 343//---------------------------------------------------------------------------------------------------- 344// Utility macros for compilers 345// used to silence compiler warnings 346 347#define Unused_Variable(var) var 348 349 350//---------------------------------------------------------------------------------------------------- 351// Miscellaneous 352 353// 6302670 Eliminate Hotspot __fabsf dependency 354// All fabs() callers should call this function instead, which will implicitly 355// convert the operand to double, avoiding a dependency on __fabsf which 356// doesn't exist in early versions of Solaris 8. 357inline double fabsd(double value) { 358 return fabs(value); 359} 360 361inline jint low (jlong value) { return jint(value); } 362inline jint high(jlong value) { return jint(value >> 32); } 363 364// the fancy casts are a hopefully portable way 365// to do unsigned 32 to 64 bit type conversion 366inline void set_low (jlong* value, jint low ) { *value &= (jlong)0xffffffff << 32; 367 *value |= (jlong)(julong)(juint)low; } 368 369inline void set_high(jlong* value, jint high) { *value &= (jlong)(julong)(juint)0xffffffff; 370 *value |= (jlong)high << 32; } 371 372inline jlong jlong_from(jint h, jint l) { 373 jlong result = 0; // initialization to avoid warning 374 set_high(&result, h); 375 set_low(&result, l); 376 return result; 377} 378 379union jlong_accessor { 380 jint words[2]; 381 jlong long_value; 382}; 383 384void basic_types_init(); // cannot define here; uses assert 385 386 387// NOTE: replicated in SA in vm/agent/sun/jvm/hotspot/runtime/BasicType.java 388enum BasicType { 389 T_BOOLEAN = 4, 390 T_CHAR = 5, 391 T_FLOAT = 6, 392 T_DOUBLE = 7, 393 T_BYTE = 8, 394 T_SHORT = 9, 395 T_INT = 10, 396 T_LONG = 11, 397 T_OBJECT = 12, 398 T_ARRAY = 13, 399 T_VOID = 14, 400 T_ADDRESS = 15, 401 T_NARROWOOP= 16, 402 T_CONFLICT = 17, // for stack value type with conflicting contents 403 T_ILLEGAL = 99 404}; 405 406inline bool is_java_primitive(BasicType t) { 407 return T_BOOLEAN <= t && t <= T_LONG; 408} 409 410// Convert a char from a classfile signature to a BasicType 411inline BasicType char2type(char c) { 412 switch( c ) { 413 case 'B': return T_BYTE; 414 case 'C': return T_CHAR; 415 case 'D': return T_DOUBLE; 416 case 'F': return T_FLOAT; 417 case 'I': return T_INT; 418 case 'J': return T_LONG; 419 case 'S': return T_SHORT; 420 case 'Z': return T_BOOLEAN; 421 case 'V': return T_VOID; 422 case 'L': return T_OBJECT; 423 case '[': return T_ARRAY; 424 } 425 return T_ILLEGAL; 426} 427 428extern char type2char_tab[T_CONFLICT+1]; // Map a BasicType to a jchar 429inline char type2char(BasicType t) { return (uint)t < T_CONFLICT+1 ? type2char_tab[t] : 0; } 430extern int type2size[T_CONFLICT+1]; // Map BasicType to result stack elements 431extern const char* type2name_tab[T_CONFLICT+1]; // Map a BasicType to a jchar 432inline const char* type2name(BasicType t) { return (uint)t < T_CONFLICT+1 ? type2name_tab[t] : NULL; } 433extern BasicType name2type(const char* name); 434 435// Auxilary math routines 436// least common multiple 437extern size_t lcm(size_t a, size_t b); 438 439 440// NOTE: replicated in SA in vm/agent/sun/jvm/hotspot/runtime/BasicType.java 441enum BasicTypeSize { 442 T_BOOLEAN_size = 1, 443 T_CHAR_size = 1, 444 T_FLOAT_size = 1, 445 T_DOUBLE_size = 2, 446 T_BYTE_size = 1, 447 T_SHORT_size = 1, 448 T_INT_size = 1, 449 T_LONG_size = 2, 450 T_OBJECT_size = 1, 451 T_ARRAY_size = 1, 452 T_NARROWOOP_size = 1, 453 T_VOID_size = 0 454}; 455 456 457// maps a BasicType to its instance field storage type: 458// all sub-word integral types are widened to T_INT 459extern BasicType type2field[T_CONFLICT+1]; 460extern BasicType type2wfield[T_CONFLICT+1]; 461 462 463// size in bytes 464enum ArrayElementSize { 465 T_BOOLEAN_aelem_bytes = 1, 466 T_CHAR_aelem_bytes = 2, 467 T_FLOAT_aelem_bytes = 4, 468 T_DOUBLE_aelem_bytes = 8, 469 T_BYTE_aelem_bytes = 1, 470 T_SHORT_aelem_bytes = 2, 471 T_INT_aelem_bytes = 4, 472 T_LONG_aelem_bytes = 8, 473#ifdef _LP64 474 T_OBJECT_aelem_bytes = 8, 475 T_ARRAY_aelem_bytes = 8, 476#else 477 T_OBJECT_aelem_bytes = 4, 478 T_ARRAY_aelem_bytes = 4, 479#endif 480 T_NARROWOOP_aelem_bytes = 4, 481 T_VOID_aelem_bytes = 0 482}; 483 484extern int _type2aelembytes[T_CONFLICT+1]; // maps a BasicType to nof bytes used by its array element 485#ifdef ASSERT 486extern int type2aelembytes(BasicType t, bool allow_address = false); // asserts 487#else 488inline int type2aelembytes(BasicType t) { return _type2aelembytes[t]; } 489#endif 490 491 492// JavaValue serves as a container for arbitrary Java values. 493 494class JavaValue { 495 496 public: 497 typedef union JavaCallValue { 498 jfloat f; 499 jdouble d; 500 jint i; 501 jlong l; 502 jobject h; 503 } JavaCallValue; 504 505 private: 506 BasicType _type; 507 JavaCallValue _value; 508 509 public: 510 JavaValue(BasicType t = T_ILLEGAL) { _type = t; } 511 512 JavaValue(jfloat value) { 513 _type = T_FLOAT; 514 _value.f = value; 515 } 516 517 JavaValue(jdouble value) { 518 _type = T_DOUBLE; 519 _value.d = value; 520 } 521 522 jfloat get_jfloat() const { return _value.f; } 523 jdouble get_jdouble() const { return _value.d; } 524 jint get_jint() const { return _value.i; } 525 jlong get_jlong() const { return _value.l; } 526 jobject get_jobject() const { return _value.h; } 527 JavaCallValue* get_value_addr() { return &_value; } 528 BasicType get_type() const { return _type; } 529 530 void set_jfloat(jfloat f) { _value.f = f;} 531 void set_jdouble(jdouble d) { _value.d = d;} 532 void set_jint(jint i) { _value.i = i;} 533 void set_jlong(jlong l) { _value.l = l;} 534 void set_jobject(jobject h) { _value.h = h;} 535 void set_type(BasicType t) { _type = t; } 536 537 jboolean get_jboolean() const { return (jboolean) (_value.i);} 538 jbyte get_jbyte() const { return (jbyte) (_value.i);} 539 jchar get_jchar() const { return (jchar) (_value.i);} 540 jshort get_jshort() const { return (jshort) (_value.i);} 541 542}; 543 544 545#define STACK_BIAS 0 546// V9 Sparc CPU's running in 64 Bit mode use a stack bias of 7ff 547// in order to extend the reach of the stack pointer. 548#if defined(SPARC) && defined(_LP64) 549#undef STACK_BIAS 550#define STACK_BIAS 0x7ff 551#endif 552 553 554// TosState describes the top-of-stack state before and after the execution of 555// a bytecode or method. The top-of-stack value may be cached in one or more CPU 556// registers. The TosState corresponds to the 'machine represention' of this cached 557// value. There's 4 states corresponding to the JAVA types int, long, float & double 558// as well as a 5th state in case the top-of-stack value is actually on the top 559// of stack (in memory) and thus not cached. The atos state corresponds to the itos 560// state when it comes to machine representation but is used separately for (oop) 561// type specific operations (e.g. verification code). 562 563enum TosState { // describes the tos cache contents 564 btos = 0, // byte, bool tos cached 565 ctos = 1, // short, char tos cached 566 stos = 2, // short, char tos cached 567 itos = 3, // int tos cached 568 ltos = 4, // long tos cached 569 ftos = 5, // float tos cached 570 dtos = 6, // double tos cached 571 atos = 7, // object cached 572 vtos = 8, // tos not cached 573 number_of_states, 574 ilgl // illegal state: should not occur 575}; 576 577 578inline TosState as_TosState(BasicType type) { 579 switch (type) { 580 case T_BYTE : return btos; 581 case T_BOOLEAN: return btos; 582 case T_CHAR : return ctos; 583 case T_SHORT : return stos; 584 case T_INT : return itos; 585 case T_LONG : return ltos; 586 case T_FLOAT : return ftos; 587 case T_DOUBLE : return dtos; 588 case T_VOID : return vtos; 589 case T_ARRAY : // fall through 590 case T_OBJECT : return atos; 591 } 592 return ilgl; 593} 594 595 596// Helper function to convert BasicType info into TosState 597// Note: Cannot define here as it uses global constant at the time being. 598TosState as_TosState(BasicType type); 599 600 601// ReferenceType is used to distinguish between java/lang/ref/Reference subclasses 602 603enum ReferenceType { 604 REF_NONE, // Regular class 605 REF_OTHER, // Subclass of java/lang/ref/Reference, but not subclass of one of the classes below 606 REF_SOFT, // Subclass of java/lang/ref/SoftReference 607 REF_WEAK, // Subclass of java/lang/ref/WeakReference 608 REF_FINAL, // Subclass of java/lang/ref/FinalReference 609 REF_PHANTOM // Subclass of java/lang/ref/PhantomReference 610}; 611 612 613// JavaThreadState keeps track of which part of the code a thread is executing in. This 614// information is needed by the safepoint code. 615// 616// There are 4 essential states: 617// 618// _thread_new : Just started, but not executed init. code yet (most likely still in OS init code) 619// _thread_in_native : In native code. This is a safepoint region, since all oops will be in jobject handles 620// _thread_in_vm : Executing in the vm 621// _thread_in_Java : Executing either interpreted or compiled Java code (or could be in a stub) 622// 623// Each state has an associated xxxx_trans state, which is an intermediate state used when a thread is in 624// a transition from one state to another. These extra states makes it possible for the safepoint code to 625// handle certain thread_states without having to suspend the thread - making the safepoint code faster. 626// 627// Given a state, the xxx_trans state can always be found by adding 1. 628// 629enum JavaThreadState { 630 _thread_uninitialized = 0, // should never happen (missing initialization) 631 _thread_new = 2, // just starting up, i.e., in process of being initialized 632 _thread_new_trans = 3, // corresponding transition state (not used, included for completness) 633 _thread_in_native = 4, // running in native code 634 _thread_in_native_trans = 5, // corresponding transition state 635 _thread_in_vm = 6, // running in VM 636 _thread_in_vm_trans = 7, // corresponding transition state 637 _thread_in_Java = 8, // running in Java or in stub code 638 _thread_in_Java_trans = 9, // corresponding transition state (not used, included for completness) 639 _thread_blocked = 10, // blocked in vm 640 _thread_blocked_trans = 11, // corresponding transition state 641 _thread_max_state = 12 // maximum thread state+1 - used for statistics allocation 642}; 643 644 645// Handy constants for deciding which compiler mode to use. 646enum MethodCompilation { 647 InvocationEntryBci = -1, // i.e., not a on-stack replacement compilation 648 InvalidOSREntryBci = -2 649}; 650 651// Enumeration to distinguish tiers of compilation 652enum CompLevel { 653 CompLevel_none = 0, 654 CompLevel_fast_compile = 1, 655 CompLevel_full_optimization = 2, 656 657 CompLevel_highest_tier = CompLevel_full_optimization, 658#ifdef TIERED 659 CompLevel_initial_compile = CompLevel_fast_compile 660#else 661 CompLevel_initial_compile = CompLevel_full_optimization 662#endif // TIERED 663}; 664 665inline bool is_tier1_compile(int comp_level) { 666 return comp_level == CompLevel_fast_compile; 667} 668inline bool is_tier2_compile(int comp_level) { 669 return comp_level == CompLevel_full_optimization; 670} 671inline bool is_highest_tier_compile(int comp_level) { 672 return comp_level == CompLevel_highest_tier; 673} 674 675//---------------------------------------------------------------------------------------------------- 676// 'Forward' declarations of frequently used classes 677// (in order to reduce interface dependencies & reduce 678// number of unnecessary compilations after changes) 679 680class symbolTable; 681class ClassFileStream; 682 683class Event; 684 685class Thread; 686class VMThread; 687class JavaThread; 688class Threads; 689 690class VM_Operation; 691class VMOperationQueue; 692 693class CodeBlob; 694class nmethod; 695class OSRAdapter; 696class I2CAdapter; 697class C2IAdapter; 698class CompiledIC; 699class relocInfo; 700class ScopeDesc; 701class PcDesc; 702 703class Recompiler; 704class Recompilee; 705class RecompilationPolicy; 706class RFrame; 707class CompiledRFrame; 708class InterpretedRFrame; 709 710class frame; 711 712class vframe; 713class javaVFrame; 714class interpretedVFrame; 715class compiledVFrame; 716class deoptimizedVFrame; 717class externalVFrame; 718class entryVFrame; 719 720class RegisterMap; 721 722class Mutex; 723class Monitor; 724class BasicLock; 725class BasicObjectLock; 726 727class PeriodicTask; 728 729class JavaCallWrapper; 730 731class oopDesc; 732 733class NativeCall; 734 735class zone; 736 737class StubQueue; 738 739class outputStream; 740 741class ResourceArea; 742 743class DebugInformationRecorder; 744class ScopeValue; 745class CompressedStream; 746class DebugInfoReadStream; 747class DebugInfoWriteStream; 748class LocationValue; 749class ConstantValue; 750class IllegalValue; 751 752class PrivilegedElement; 753class MonitorArray; 754 755class MonitorInfo; 756 757class OffsetClosure; 758class OopMapCache; 759class InterpreterOopMap; 760class OopMapCacheEntry; 761class OSThread; 762 763typedef int (*OSThreadStartFunc)(void*); 764 765class Space; 766 767class JavaValue; 768class methodHandle; 769class JavaCallArguments; 770 771// Basic support for errors (general debug facilities not defined at this point fo the include phase) 772 773extern void basic_fatal(const char* msg); 774 775 776//---------------------------------------------------------------------------------------------------- 777// Special constants for debugging 778 779const jint badInt = -3; // generic "bad int" value 780const long badAddressVal = -2; // generic "bad address" value 781const long badOopVal = -1; // generic "bad oop" value 782const intptr_t badHeapOopVal = (intptr_t) CONST64(0x2BAD4B0BBAADBABE); // value used to zap heap after GC 783const int badHandleValue = 0xBC; // value used to zap vm handle area 784const int badResourceValue = 0xAB; // value used to zap resource area 785const int freeBlockPad = 0xBA; // value used to pad freed blocks. 786const int uninitBlockPad = 0xF1; // value used to zap newly malloc'd blocks. 787const intptr_t badJNIHandleVal = (intptr_t) CONST64(0xFEFEFEFEFEFEFEFE); // value used to zap jni handle area 788const juint badHeapWordVal = 0xBAADBABE; // value used to zap heap after GC 789const int badCodeHeapNewVal= 0xCC; // value used to zap Code heap at allocation 790const int badCodeHeapFreeVal = 0xDD; // value used to zap Code heap at deallocation 791 792 793// (These must be implemented as #defines because C++ compilers are 794// not obligated to inline non-integral constants!) 795#define badAddress ((address)::badAddressVal) 796#define badOop ((oop)::badOopVal) 797#define badHeapWord (::badHeapWordVal) 798#define badJNIHandle ((oop)::badJNIHandleVal) 799 800 801//---------------------------------------------------------------------------------------------------- 802// Utility functions for bitfield manipulations 803 804const intptr_t AllBits = ~0; // all bits set in a word 805const intptr_t NoBits = 0; // no bits set in a word 806const jlong NoLongBits = 0; // no bits set in a long 807const intptr_t OneBit = 1; // only right_most bit set in a word 808 809// get a word with the n.th or the right-most or left-most n bits set 810// (note: #define used only so that they can be used in enum constant definitions) 811#define nth_bit(n) (n >= BitsPerWord ? 0 : OneBit << (n)) 812#define right_n_bits(n) (nth_bit(n) - 1) 813#define left_n_bits(n) (right_n_bits(n) << (n >= BitsPerWord ? 0 : (BitsPerWord - n))) 814 815// bit-operations using a mask m 816inline void set_bits (intptr_t& x, intptr_t m) { x |= m; } 817inline void clear_bits (intptr_t& x, intptr_t m) { x &= ~m; } 818inline intptr_t mask_bits (intptr_t x, intptr_t m) { return x & m; } 819inline jlong mask_long_bits (jlong x, jlong m) { return x & m; } 820inline bool mask_bits_are_true (intptr_t flags, intptr_t mask) { return (flags & mask) == mask; } 821 822// bit-operations using the n.th bit 823inline void set_nth_bit(intptr_t& x, int n) { set_bits (x, nth_bit(n)); } 824inline void clear_nth_bit(intptr_t& x, int n) { clear_bits(x, nth_bit(n)); } 825inline bool is_set_nth_bit(intptr_t x, int n) { return mask_bits (x, nth_bit(n)) != NoBits; } 826 827// returns the bitfield of x starting at start_bit_no with length field_length (no sign-extension!) 828inline intptr_t bitfield(intptr_t x, int start_bit_no, int field_length) { 829 return mask_bits(x >> start_bit_no, right_n_bits(field_length)); 830} 831 832 833//---------------------------------------------------------------------------------------------------- 834// Utility functions for integers 835 836// Avoid use of global min/max macros which may cause unwanted double 837// evaluation of arguments. 838#ifdef max 839#undef max 840#endif 841 842#ifdef min 843#undef min 844#endif 845 846#define max(a,b) Do_not_use_max_use_MAX2_instead 847#define min(a,b) Do_not_use_min_use_MIN2_instead 848 849// It is necessary to use templates here. Having normal overloaded 850// functions does not work because it is necessary to provide both 32- 851// and 64-bit overloaded functions, which does not work, and having 852// explicitly-typed versions of these routines (i.e., MAX2I, MAX2L) 853// will be even more error-prone than macros. 854template<class T> inline T MAX2(T a, T b) { return (a > b) ? a : b; } 855template<class T> inline T MIN2(T a, T b) { return (a < b) ? a : b; } 856template<class T> inline T MAX3(T a, T b, T c) { return MAX2(MAX2(a, b), c); } 857template<class T> inline T MIN3(T a, T b, T c) { return MIN2(MIN2(a, b), c); } 858template<class T> inline T MAX4(T a, T b, T c, T d) { return MAX2(MAX3(a, b, c), d); } 859template<class T> inline T MIN4(T a, T b, T c, T d) { return MIN2(MIN3(a, b, c), d); } 860 861template<class T> inline T ABS(T x) { return (x > 0) ? x : -x; } 862 863// true if x is a power of 2, false otherwise 864inline bool is_power_of_2(intptr_t x) { 865 return ((x != NoBits) && (mask_bits(x, x - 1) == NoBits)); 866} 867 868// long version of is_power_of_2 869inline bool is_power_of_2_long(jlong x) { 870 return ((x != NoLongBits) && (mask_long_bits(x, x - 1) == NoLongBits)); 871} 872 873//* largest i such that 2^i <= x 874// A negative value of 'x' will return '31' 875inline int log2_intptr(intptr_t x) { 876 int i = -1; 877 uintptr_t p = 1; 878 while (p != 0 && p <= (uintptr_t)x) { 879 // p = 2^(i+1) && p <= x (i.e., 2^(i+1) <= x) 880 i++; p *= 2; 881 } 882 // p = 2^(i+1) && x < p (i.e., 2^i <= x < 2^(i+1)) 883 // (if p = 0 then overflow occured and i = 31) 884 return i; 885} 886 887//* largest i such that 2^i <= x 888// A negative value of 'x' will return '63' 889inline int log2_long(jlong x) { 890 int i = -1; 891 julong p = 1; 892 while (p != 0 && p <= (julong)x) { 893 // p = 2^(i+1) && p <= x (i.e., 2^(i+1) <= x) 894 i++; p *= 2; 895 } 896 // p = 2^(i+1) && x < p (i.e., 2^i <= x < 2^(i+1)) 897 // (if p = 0 then overflow occured and i = 63) 898 return i; 899} 900 901//* the argument must be exactly a power of 2 902inline int exact_log2(intptr_t x) { 903 #ifdef ASSERT 904 if (!is_power_of_2(x)) basic_fatal("x must be a power of 2"); 905 #endif 906 return log2_intptr(x); 907} 908 909 910// returns integer round-up to the nearest multiple of s (s must be a power of two) 911inline intptr_t round_to(intptr_t x, uintx s) { 912 #ifdef ASSERT 913 if (!is_power_of_2(s)) basic_fatal("s must be a power of 2"); 914 #endif 915 const uintx m = s - 1; 916 return mask_bits(x + m, ~m); 917} 918 919// returns integer round-down to the nearest multiple of s (s must be a power of two) 920inline intptr_t round_down(intptr_t x, uintx s) { 921 #ifdef ASSERT 922 if (!is_power_of_2(s)) basic_fatal("s must be a power of 2"); 923 #endif 924 const uintx m = s - 1; 925 return mask_bits(x, ~m); 926} 927 928 929inline bool is_odd (intx x) { return x & 1; } 930inline bool is_even(intx x) { return !is_odd(x); } 931 932// "to" should be greater than "from." 933inline intx byte_size(void* from, void* to) { 934 return (address)to - (address)from; 935} 936 937//---------------------------------------------------------------------------------------------------- 938// Avoid non-portable casts with these routines (DEPRECATED) 939 940// NOTE: USE Bytes class INSTEAD WHERE POSSIBLE 941// Bytes is optimized machine-specifically and may be much faster then the portable routines below. 942 943// Given sequence of four bytes, build into a 32-bit word 944// following the conventions used in class files. 945// On the 386, this could be realized with a simple address cast. 946// 947 948// This routine takes eight bytes: 949inline u8 build_u8_from( u1 c1, u1 c2, u1 c3, u1 c4, u1 c5, u1 c6, u1 c7, u1 c8 ) { 950 return ( u8(c1) << 56 ) & ( u8(0xff) << 56 ) 951 | ( u8(c2) << 48 ) & ( u8(0xff) << 48 ) 952 | ( u8(c3) << 40 ) & ( u8(0xff) << 40 ) 953 | ( u8(c4) << 32 ) & ( u8(0xff) << 32 ) 954 | ( u8(c5) << 24 ) & ( u8(0xff) << 24 ) 955 | ( u8(c6) << 16 ) & ( u8(0xff) << 16 ) 956 | ( u8(c7) << 8 ) & ( u8(0xff) << 8 ) 957 | ( u8(c8) << 0 ) & ( u8(0xff) << 0 ); 958} 959 960// This routine takes four bytes: 961inline u4 build_u4_from( u1 c1, u1 c2, u1 c3, u1 c4 ) { 962 return ( u4(c1) << 24 ) & 0xff000000 963 | ( u4(c2) << 16 ) & 0x00ff0000 964 | ( u4(c3) << 8 ) & 0x0000ff00 965 | ( u4(c4) << 0 ) & 0x000000ff; 966} 967 968// And this one works if the four bytes are contiguous in memory: 969inline u4 build_u4_from( u1* p ) { 970 return build_u4_from( p[0], p[1], p[2], p[3] ); 971} 972 973// Ditto for two-byte ints: 974inline u2 build_u2_from( u1 c1, u1 c2 ) { 975 return u2(( u2(c1) << 8 ) & 0xff00 976 | ( u2(c2) << 0 ) & 0x00ff); 977} 978 979// And this one works if the two bytes are contiguous in memory: 980inline u2 build_u2_from( u1* p ) { 981 return build_u2_from( p[0], p[1] ); 982} 983 984// Ditto for floats: 985inline jfloat build_float_from( u1 c1, u1 c2, u1 c3, u1 c4 ) { 986 u4 u = build_u4_from( c1, c2, c3, c4 ); 987 return *(jfloat*)&u; 988} 989 990inline jfloat build_float_from( u1* p ) { 991 u4 u = build_u4_from( p ); 992 return *(jfloat*)&u; 993} 994 995 996// now (64-bit) longs 997 998inline jlong build_long_from( u1 c1, u1 c2, u1 c3, u1 c4, u1 c5, u1 c6, u1 c7, u1 c8 ) { 999 return ( jlong(c1) << 56 ) & ( jlong(0xff) << 56 ) 1000 | ( jlong(c2) << 48 ) & ( jlong(0xff) << 48 ) 1001 | ( jlong(c3) << 40 ) & ( jlong(0xff) << 40 ) 1002 | ( jlong(c4) << 32 ) & ( jlong(0xff) << 32 ) 1003 | ( jlong(c5) << 24 ) & ( jlong(0xff) << 24 ) 1004 | ( jlong(c6) << 16 ) & ( jlong(0xff) << 16 ) 1005 | ( jlong(c7) << 8 ) & ( jlong(0xff) << 8 ) 1006 | ( jlong(c8) << 0 ) & ( jlong(0xff) << 0 ); 1007} 1008 1009inline jlong build_long_from( u1* p ) { 1010 return build_long_from( p[0], p[1], p[2], p[3], p[4], p[5], p[6], p[7] ); 1011} 1012 1013 1014// Doubles, too! 1015inline jdouble build_double_from( u1 c1, u1 c2, u1 c3, u1 c4, u1 c5, u1 c6, u1 c7, u1 c8 ) { 1016 jlong u = build_long_from( c1, c2, c3, c4, c5, c6, c7, c8 ); 1017 return *(jdouble*)&u; 1018} 1019 1020inline jdouble build_double_from( u1* p ) { 1021 jlong u = build_long_from( p ); 1022 return *(jdouble*)&u; 1023} 1024 1025 1026// Portable routines to go the other way: 1027 1028inline void explode_short_to( u2 x, u1& c1, u1& c2 ) { 1029 c1 = u1(x >> 8); 1030 c2 = u1(x); 1031} 1032 1033inline void explode_short_to( u2 x, u1* p ) { 1034 explode_short_to( x, p[0], p[1]); 1035} 1036 1037inline void explode_int_to( u4 x, u1& c1, u1& c2, u1& c3, u1& c4 ) { 1038 c1 = u1(x >> 24); 1039 c2 = u1(x >> 16); 1040 c3 = u1(x >> 8); 1041 c4 = u1(x); 1042} 1043 1044inline void explode_int_to( u4 x, u1* p ) { 1045 explode_int_to( x, p[0], p[1], p[2], p[3]); 1046} 1047 1048 1049// Pack and extract shorts to/from ints: 1050 1051inline int extract_low_short_from_int(jint x) { 1052 return x & 0xffff; 1053} 1054 1055inline int extract_high_short_from_int(jint x) { 1056 return (x >> 16) & 0xffff; 1057} 1058 1059inline int build_int_from_shorts( jushort low, jushort high ) { 1060 return ((int)((unsigned int)high << 16) | (unsigned int)low); 1061} 1062 1063// Printf-style formatters for fixed- and variable-width types as pointers and 1064// integers. 1065// 1066// Each compiler-specific definitions file (e.g., globalDefinitions_gcc.hpp) 1067// must define the macro FORMAT64_MODIFIER, which is the modifier for '%x' or 1068// '%d' formats to indicate a 64-bit quantity; commonly "l" (in LP64) or "ll" 1069// (in ILP32). 1070 1071// Format 32-bit quantities. 1072#define INT32_FORMAT "%d" 1073#define UINT32_FORMAT "%u" 1074#define INT32_FORMAT_W(width) "%" #width "d" 1075#define UINT32_FORMAT_W(width) "%" #width "u" 1076 1077#define PTR32_FORMAT "0x%08x" 1078 1079// Format 64-bit quantities. 1080#define INT64_FORMAT "%" FORMAT64_MODIFIER "d" 1081#define UINT64_FORMAT "%" FORMAT64_MODIFIER "u" 1082#define PTR64_FORMAT "0x%016" FORMAT64_MODIFIER "x" 1083 1084#define INT64_FORMAT_W(width) "%" #width FORMAT64_MODIFIER "d" 1085#define UINT64_FORMAT_W(width) "%" #width FORMAT64_MODIFIER "u" 1086 1087// Format macros that allow the field width to be specified. The width must be 1088// a string literal (e.g., "8") or a macro that evaluates to one. 1089#ifdef _LP64 1090#define UINTX_FORMAT_W(width) UINT64_FORMAT_W(width) 1091#define SSIZE_FORMAT_W(width) INT64_FORMAT_W(width) 1092#define SIZE_FORMAT_W(width) UINT64_FORMAT_W(width) 1093#else 1094#define UINTX_FORMAT_W(width) UINT32_FORMAT_W(width) 1095#define SSIZE_FORMAT_W(width) INT32_FORMAT_W(width) 1096#define SIZE_FORMAT_W(width) UINT32_FORMAT_W(width) 1097#endif // _LP64 1098 1099// Format pointers and size_t (or size_t-like integer types) which change size 1100// between 32- and 64-bit. The pointer format theoretically should be "%p", 1101// however, it has different output on different platforms. On Windows, the data 1102// will be padded with zeros automatically. On Solaris, we can use "%016p" & 1103// "%08p" on 64 bit & 32 bit platforms to make the data padded with extra zeros. 1104// On Linux, "%016p" or "%08p" is not be allowed, at least on the latest GCC 1105// 4.3.2. So we have to use "%016x" or "%08x" to simulate the printing format. 1106// GCC 4.3.2, however requires the data to be converted to "intptr_t" when 1107// using "%x". 1108#ifdef _LP64 1109#define PTR_FORMAT PTR64_FORMAT 1110#define UINTX_FORMAT UINT64_FORMAT 1111#define INTX_FORMAT INT64_FORMAT 1112#define SIZE_FORMAT UINT64_FORMAT 1113#define SSIZE_FORMAT INT64_FORMAT 1114#else // !_LP64 1115#define PTR_FORMAT PTR32_FORMAT 1116#define UINTX_FORMAT UINT32_FORMAT 1117#define INTX_FORMAT INT32_FORMAT 1118#define SIZE_FORMAT UINT32_FORMAT 1119#define SSIZE_FORMAT INT32_FORMAT 1120#endif // _LP64 1121 1122#define INTPTR_FORMAT PTR_FORMAT 1123 1124// Enable zap-a-lot if in debug version. 1125 1126# ifdef ASSERT 1127# ifdef COMPILER2 1128# define ENABLE_ZAP_DEAD_LOCALS 1129#endif /* COMPILER2 */ 1130# endif /* ASSERT */ 1131 1132#define ARRAY_SIZE(array) (sizeof(array)/sizeof((array)[0])) 1133