Wed, 11 Jan 2012 17:34:02 -0500
7115199: Add event tracing hooks and Java Flight Recorder infrastructure
Summary: Added a nop tracing infrastructure, JFR makefile changes and other infrastructure used only by JFR.
Reviewed-by: acorn, sspitsyn
Contributed-by: markus.gronlund@oracle.com
1 /*
2 * Copyright (c) 1997, 2011, Oracle and/or its affiliates. All rights reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * This code is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation.
8 *
9 * This code is distributed in the hope that it will be useful, but WITHOUT
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
12 * version 2 for more details (a copy is included in the LICENSE file that
13 * accompanied this code).
14 *
15 * You should have received a copy of the GNU General Public License version
16 * 2 along with this work; if not, write to the Free Software Foundation,
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18 *
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20 * or visit www.oracle.com if you need additional information or have any
21 * questions.
22 *
23 */
25 #ifndef SHARE_VM_UTILITIES_GLOBALDEFINITIONS_HPP
26 #define SHARE_VM_UTILITIES_GLOBALDEFINITIONS_HPP
28 #ifndef __STDC_FORMAT_MACROS
29 #define __STDC_FORMAT_MACROS
30 #endif
32 #ifdef TARGET_COMPILER_gcc
33 # include "utilities/globalDefinitions_gcc.hpp"
34 #endif
35 #ifdef TARGET_COMPILER_visCPP
36 # include "utilities/globalDefinitions_visCPP.hpp"
37 #endif
38 #ifdef TARGET_COMPILER_sparcWorks
39 # include "utilities/globalDefinitions_sparcWorks.hpp"
40 #endif
42 #include "utilities/macros.hpp"
44 // This file holds all globally used constants & types, class (forward)
45 // declarations and a few frequently used utility functions.
47 //----------------------------------------------------------------------------------------------------
48 // Constants
50 const int LogBytesPerShort = 1;
51 const int LogBytesPerInt = 2;
52 #ifdef _LP64
53 const int LogBytesPerWord = 3;
54 #else
55 const int LogBytesPerWord = 2;
56 #endif
57 const int LogBytesPerLong = 3;
59 const int BytesPerShort = 1 << LogBytesPerShort;
60 const int BytesPerInt = 1 << LogBytesPerInt;
61 const int BytesPerWord = 1 << LogBytesPerWord;
62 const int BytesPerLong = 1 << LogBytesPerLong;
64 const int LogBitsPerByte = 3;
65 const int LogBitsPerShort = LogBitsPerByte + LogBytesPerShort;
66 const int LogBitsPerInt = LogBitsPerByte + LogBytesPerInt;
67 const int LogBitsPerWord = LogBitsPerByte + LogBytesPerWord;
68 const int LogBitsPerLong = LogBitsPerByte + LogBytesPerLong;
70 const int BitsPerByte = 1 << LogBitsPerByte;
71 const int BitsPerShort = 1 << LogBitsPerShort;
72 const int BitsPerInt = 1 << LogBitsPerInt;
73 const int BitsPerWord = 1 << LogBitsPerWord;
74 const int BitsPerLong = 1 << LogBitsPerLong;
76 const int WordAlignmentMask = (1 << LogBytesPerWord) - 1;
77 const int LongAlignmentMask = (1 << LogBytesPerLong) - 1;
79 const int WordsPerLong = 2; // Number of stack entries for longs
81 const int oopSize = sizeof(char*); // Full-width oop
82 extern int heapOopSize; // Oop within a java object
83 const int wordSize = sizeof(char*);
84 const int longSize = sizeof(jlong);
85 const int jintSize = sizeof(jint);
86 const int size_tSize = sizeof(size_t);
88 const int BytesPerOop = BytesPerWord; // Full-width oop
90 extern int LogBytesPerHeapOop; // Oop within a java object
91 extern int LogBitsPerHeapOop;
92 extern int BytesPerHeapOop;
93 extern int BitsPerHeapOop;
95 // Oop encoding heap max
96 extern uint64_t OopEncodingHeapMax;
98 const int BitsPerJavaInteger = 32;
99 const int BitsPerJavaLong = 64;
100 const int BitsPerSize_t = size_tSize * BitsPerByte;
102 // Size of a char[] needed to represent a jint as a string in decimal.
103 const int jintAsStringSize = 12;
105 // In fact this should be
106 // log2_intptr(sizeof(class JavaThread)) - log2_intptr(64);
107 // see os::set_memory_serialize_page()
108 #ifdef _LP64
109 const int SerializePageShiftCount = 4;
110 #else
111 const int SerializePageShiftCount = 3;
112 #endif
114 // An opaque struct of heap-word width, so that HeapWord* can be a generic
115 // pointer into the heap. We require that object sizes be measured in
116 // units of heap words, so that that
117 // HeapWord* hw;
118 // hw += oop(hw)->foo();
119 // works, where foo is a method (like size or scavenge) that returns the
120 // object size.
121 class HeapWord {
122 friend class VMStructs;
123 private:
124 char* i;
125 #ifndef PRODUCT
126 public:
127 char* value() { return i; }
128 #endif
129 };
131 // HeapWordSize must be 2^LogHeapWordSize.
132 const int HeapWordSize = sizeof(HeapWord);
133 #ifdef _LP64
134 const int LogHeapWordSize = 3;
135 #else
136 const int LogHeapWordSize = 2;
137 #endif
138 const int HeapWordsPerLong = BytesPerLong / HeapWordSize;
139 const int LogHeapWordsPerLong = LogBytesPerLong - LogHeapWordSize;
141 // The larger HeapWordSize for 64bit requires larger heaps
142 // for the same application running in 64bit. See bug 4967770.
143 // The minimum alignment to a heap word size is done. Other
144 // parts of the memory system may required additional alignment
145 // and are responsible for those alignments.
146 #ifdef _LP64
147 #define ScaleForWordSize(x) align_size_down_((x) * 13 / 10, HeapWordSize)
148 #else
149 #define ScaleForWordSize(x) (x)
150 #endif
152 // The minimum number of native machine words necessary to contain "byte_size"
153 // bytes.
154 inline size_t heap_word_size(size_t byte_size) {
155 return (byte_size + (HeapWordSize-1)) >> LogHeapWordSize;
156 }
159 const size_t K = 1024;
160 const size_t M = K*K;
161 const size_t G = M*K;
162 const size_t HWperKB = K / sizeof(HeapWord);
164 const size_t LOG_K = 10;
165 const size_t LOG_M = 2 * LOG_K;
166 const size_t LOG_G = 2 * LOG_M;
168 const jint min_jint = (jint)1 << (sizeof(jint)*BitsPerByte-1); // 0x80000000 == smallest jint
169 const jint max_jint = (juint)min_jint - 1; // 0x7FFFFFFF == largest jint
171 // Constants for converting from a base unit to milli-base units. For
172 // example from seconds to milliseconds and microseconds
174 const int MILLIUNITS = 1000; // milli units per base unit
175 const int MICROUNITS = 1000000; // micro units per base unit
176 const int NANOUNITS = 1000000000; // nano units per base unit
178 const jlong NANOSECS_PER_SEC = CONST64(1000000000);
179 const jint NANOSECS_PER_MILLISEC = 1000000;
181 inline const char* proper_unit_for_byte_size(size_t s) {
182 if (s >= 10*M) {
183 return "M";
184 } else if (s >= 10*K) {
185 return "K";
186 } else {
187 return "B";
188 }
189 }
191 inline size_t byte_size_in_proper_unit(size_t s) {
192 if (s >= 10*M) {
193 return s/M;
194 } else if (s >= 10*K) {
195 return s/K;
196 } else {
197 return s;
198 }
199 }
202 //----------------------------------------------------------------------------------------------------
203 // VM type definitions
205 // intx and uintx are the 'extended' int and 'extended' unsigned int types;
206 // they are 32bit wide on a 32-bit platform, and 64bit wide on a 64bit platform.
208 typedef intptr_t intx;
209 typedef uintptr_t uintx;
211 const intx min_intx = (intx)1 << (sizeof(intx)*BitsPerByte-1);
212 const intx max_intx = (uintx)min_intx - 1;
213 const uintx max_uintx = (uintx)-1;
215 // Table of values:
216 // sizeof intx 4 8
217 // min_intx 0x80000000 0x8000000000000000
218 // max_intx 0x7FFFFFFF 0x7FFFFFFFFFFFFFFF
219 // max_uintx 0xFFFFFFFF 0xFFFFFFFFFFFFFFFF
221 typedef unsigned int uint; NEEDS_CLEANUP
224 //----------------------------------------------------------------------------------------------------
225 // Java type definitions
227 // All kinds of 'plain' byte addresses
228 typedef signed char s_char;
229 typedef unsigned char u_char;
230 typedef u_char* address;
231 typedef uintptr_t address_word; // unsigned integer which will hold a pointer
232 // except for some implementations of a C++
233 // linkage pointer to function. Should never
234 // need one of those to be placed in this
235 // type anyway.
237 // Utility functions to "portably" (?) bit twiddle pointers
238 // Where portable means keep ANSI C++ compilers quiet
240 inline address set_address_bits(address x, int m) { return address(intptr_t(x) | m); }
241 inline address clear_address_bits(address x, int m) { return address(intptr_t(x) & ~m); }
243 // Utility functions to "portably" make cast to/from function pointers.
245 inline address_word mask_address_bits(address x, int m) { return address_word(x) & m; }
246 inline address_word castable_address(address x) { return address_word(x) ; }
247 inline address_word castable_address(void* x) { return address_word(x) ; }
249 // Pointer subtraction.
250 // The idea here is to avoid ptrdiff_t, which is signed and so doesn't have
251 // the range we might need to find differences from one end of the heap
252 // to the other.
253 // A typical use might be:
254 // if (pointer_delta(end(), top()) >= size) {
255 // // enough room for an object of size
256 // ...
257 // and then additions like
258 // ... top() + size ...
259 // are safe because we know that top() is at least size below end().
260 inline size_t pointer_delta(const void* left,
261 const void* right,
262 size_t element_size) {
263 return (((uintptr_t) left) - ((uintptr_t) right)) / element_size;
264 }
265 // A version specialized for HeapWord*'s.
266 inline size_t pointer_delta(const HeapWord* left, const HeapWord* right) {
267 return pointer_delta(left, right, sizeof(HeapWord));
268 }
270 //
271 // ANSI C++ does not allow casting from one pointer type to a function pointer
272 // directly without at best a warning. This macro accomplishes it silently
273 // In every case that is present at this point the value be cast is a pointer
274 // to a C linkage function. In somecase the type used for the cast reflects
275 // that linkage and a picky compiler would not complain. In other cases because
276 // there is no convenient place to place a typedef with extern C linkage (i.e
277 // a platform dependent header file) it doesn't. At this point no compiler seems
278 // picky enough to catch these instances (which are few). It is possible that
279 // using templates could fix these for all cases. This use of templates is likely
280 // so far from the middle of the road that it is likely to be problematic in
281 // many C++ compilers.
282 //
283 #define CAST_TO_FN_PTR(func_type, value) ((func_type)(castable_address(value)))
284 #define CAST_FROM_FN_PTR(new_type, func_ptr) ((new_type)((address_word)(func_ptr)))
286 // Unsigned byte types for os and stream.hpp
288 // Unsigned one, two, four and eigth byte quantities used for describing
289 // the .class file format. See JVM book chapter 4.
291 typedef jubyte u1;
292 typedef jushort u2;
293 typedef juint u4;
294 typedef julong u8;
296 const jubyte max_jubyte = (jubyte)-1; // 0xFF largest jubyte
297 const jushort max_jushort = (jushort)-1; // 0xFFFF largest jushort
298 const juint max_juint = (juint)-1; // 0xFFFFFFFF largest juint
299 const julong max_julong = (julong)-1; // 0xFF....FF largest julong
301 typedef jbyte s1;
302 typedef jshort s2;
303 typedef jint s4;
304 typedef jlong s8;
306 //----------------------------------------------------------------------------------------------------
307 // JVM spec restrictions
309 const int max_method_code_size = 64*K - 1; // JVM spec, 2nd ed. section 4.8.1 (p.134)
312 //----------------------------------------------------------------------------------------------------
313 // HotSwap - for JVMTI aka Class File Replacement and PopFrame
314 //
315 // Determines whether on-the-fly class replacement and frame popping are enabled.
317 #define HOTSWAP
319 //----------------------------------------------------------------------------------------------------
320 // Object alignment, in units of HeapWords.
321 //
322 // Minimum is max(BytesPerLong, BytesPerDouble, BytesPerOop) / HeapWordSize, so jlong, jdouble and
323 // reference fields can be naturally aligned.
325 extern int MinObjAlignment;
326 extern int MinObjAlignmentInBytes;
327 extern int MinObjAlignmentInBytesMask;
329 extern int LogMinObjAlignment;
330 extern int LogMinObjAlignmentInBytes;
332 // Machine dependent stuff
334 #ifdef TARGET_ARCH_x86
335 # include "globalDefinitions_x86.hpp"
336 #endif
337 #ifdef TARGET_ARCH_sparc
338 # include "globalDefinitions_sparc.hpp"
339 #endif
340 #ifdef TARGET_ARCH_zero
341 # include "globalDefinitions_zero.hpp"
342 #endif
343 #ifdef TARGET_ARCH_arm
344 # include "globalDefinitions_arm.hpp"
345 #endif
346 #ifdef TARGET_ARCH_ppc
347 # include "globalDefinitions_ppc.hpp"
348 #endif
351 // The byte alignment to be used by Arena::Amalloc. See bugid 4169348.
352 // Note: this value must be a power of 2
354 #define ARENA_AMALLOC_ALIGNMENT (2*BytesPerWord)
356 // Signed variants of alignment helpers. There are two versions of each, a macro
357 // for use in places like enum definitions that require compile-time constant
358 // expressions and a function for all other places so as to get type checking.
360 #define align_size_up_(size, alignment) (((size) + ((alignment) - 1)) & ~((alignment) - 1))
362 inline intptr_t align_size_up(intptr_t size, intptr_t alignment) {
363 return align_size_up_(size, alignment);
364 }
366 #define align_size_down_(size, alignment) ((size) & ~((alignment) - 1))
368 inline intptr_t align_size_down(intptr_t size, intptr_t alignment) {
369 return align_size_down_(size, alignment);
370 }
372 // Align objects by rounding up their size, in HeapWord units.
374 #define align_object_size_(size) align_size_up_(size, MinObjAlignment)
376 inline intptr_t align_object_size(intptr_t size) {
377 return align_size_up(size, MinObjAlignment);
378 }
380 inline bool is_object_aligned(intptr_t addr) {
381 return addr == align_object_size(addr);
382 }
384 // Pad out certain offsets to jlong alignment, in HeapWord units.
386 inline intptr_t align_object_offset(intptr_t offset) {
387 return align_size_up(offset, HeapWordsPerLong);
388 }
390 // The expected size in bytes of a cache line, used to pad data structures.
391 #define DEFAULT_CACHE_LINE_SIZE 64
393 // Bytes needed to pad type to avoid cache-line sharing; alignment should be the
394 // expected cache line size (a power of two). The first addend avoids sharing
395 // when the start address is not a multiple of alignment; the second maintains
396 // alignment of starting addresses that happen to be a multiple.
397 #define PADDING_SIZE(type, alignment) \
398 ((alignment) + align_size_up_(sizeof(type), alignment))
400 // Templates to create a subclass padded to avoid cache line sharing. These are
401 // effective only when applied to derived-most (leaf) classes.
403 // When no args are passed to the base ctor.
404 template <class T, size_t alignment = DEFAULT_CACHE_LINE_SIZE>
405 class Padded: public T {
406 private:
407 char _pad_buf_[PADDING_SIZE(T, alignment)];
408 };
410 // When either 0 or 1 args may be passed to the base ctor.
411 template <class T, typename Arg1T, size_t alignment = DEFAULT_CACHE_LINE_SIZE>
412 class Padded01: public T {
413 public:
414 Padded01(): T() { }
415 Padded01(Arg1T arg1): T(arg1) { }
416 private:
417 char _pad_buf_[PADDING_SIZE(T, alignment)];
418 };
420 //----------------------------------------------------------------------------------------------------
421 // Utility macros for compilers
422 // used to silence compiler warnings
424 #define Unused_Variable(var) var
427 //----------------------------------------------------------------------------------------------------
428 // Miscellaneous
430 // 6302670 Eliminate Hotspot __fabsf dependency
431 // All fabs() callers should call this function instead, which will implicitly
432 // convert the operand to double, avoiding a dependency on __fabsf which
433 // doesn't exist in early versions of Solaris 8.
434 inline double fabsd(double value) {
435 return fabs(value);
436 }
438 inline jint low (jlong value) { return jint(value); }
439 inline jint high(jlong value) { return jint(value >> 32); }
441 // the fancy casts are a hopefully portable way
442 // to do unsigned 32 to 64 bit type conversion
443 inline void set_low (jlong* value, jint low ) { *value &= (jlong)0xffffffff << 32;
444 *value |= (jlong)(julong)(juint)low; }
446 inline void set_high(jlong* value, jint high) { *value &= (jlong)(julong)(juint)0xffffffff;
447 *value |= (jlong)high << 32; }
449 inline jlong jlong_from(jint h, jint l) {
450 jlong result = 0; // initialization to avoid warning
451 set_high(&result, h);
452 set_low(&result, l);
453 return result;
454 }
456 union jlong_accessor {
457 jint words[2];
458 jlong long_value;
459 };
461 void basic_types_init(); // cannot define here; uses assert
464 // NOTE: replicated in SA in vm/agent/sun/jvm/hotspot/runtime/BasicType.java
465 enum BasicType {
466 T_BOOLEAN = 4,
467 T_CHAR = 5,
468 T_FLOAT = 6,
469 T_DOUBLE = 7,
470 T_BYTE = 8,
471 T_SHORT = 9,
472 T_INT = 10,
473 T_LONG = 11,
474 T_OBJECT = 12,
475 T_ARRAY = 13,
476 T_VOID = 14,
477 T_ADDRESS = 15,
478 T_NARROWOOP= 16,
479 T_CONFLICT = 17, // for stack value type with conflicting contents
480 T_ILLEGAL = 99
481 };
483 inline bool is_java_primitive(BasicType t) {
484 return T_BOOLEAN <= t && t <= T_LONG;
485 }
487 inline bool is_subword_type(BasicType t) {
488 // these guys are processed exactly like T_INT in calling sequences:
489 return (t == T_BOOLEAN || t == T_CHAR || t == T_BYTE || t == T_SHORT);
490 }
492 inline bool is_signed_subword_type(BasicType t) {
493 return (t == T_BYTE || t == T_SHORT);
494 }
496 // Convert a char from a classfile signature to a BasicType
497 inline BasicType char2type(char c) {
498 switch( c ) {
499 case 'B': return T_BYTE;
500 case 'C': return T_CHAR;
501 case 'D': return T_DOUBLE;
502 case 'F': return T_FLOAT;
503 case 'I': return T_INT;
504 case 'J': return T_LONG;
505 case 'S': return T_SHORT;
506 case 'Z': return T_BOOLEAN;
507 case 'V': return T_VOID;
508 case 'L': return T_OBJECT;
509 case '[': return T_ARRAY;
510 }
511 return T_ILLEGAL;
512 }
514 extern char type2char_tab[T_CONFLICT+1]; // Map a BasicType to a jchar
515 inline char type2char(BasicType t) { return (uint)t < T_CONFLICT+1 ? type2char_tab[t] : 0; }
516 extern int type2size[T_CONFLICT+1]; // Map BasicType to result stack elements
517 extern const char* type2name_tab[T_CONFLICT+1]; // Map a BasicType to a jchar
518 inline const char* type2name(BasicType t) { return (uint)t < T_CONFLICT+1 ? type2name_tab[t] : NULL; }
519 extern BasicType name2type(const char* name);
521 // Auxilary math routines
522 // least common multiple
523 extern size_t lcm(size_t a, size_t b);
526 // NOTE: replicated in SA in vm/agent/sun/jvm/hotspot/runtime/BasicType.java
527 enum BasicTypeSize {
528 T_BOOLEAN_size = 1,
529 T_CHAR_size = 1,
530 T_FLOAT_size = 1,
531 T_DOUBLE_size = 2,
532 T_BYTE_size = 1,
533 T_SHORT_size = 1,
534 T_INT_size = 1,
535 T_LONG_size = 2,
536 T_OBJECT_size = 1,
537 T_ARRAY_size = 1,
538 T_NARROWOOP_size = 1,
539 T_VOID_size = 0
540 };
543 // maps a BasicType to its instance field storage type:
544 // all sub-word integral types are widened to T_INT
545 extern BasicType type2field[T_CONFLICT+1];
546 extern BasicType type2wfield[T_CONFLICT+1];
549 // size in bytes
550 enum ArrayElementSize {
551 T_BOOLEAN_aelem_bytes = 1,
552 T_CHAR_aelem_bytes = 2,
553 T_FLOAT_aelem_bytes = 4,
554 T_DOUBLE_aelem_bytes = 8,
555 T_BYTE_aelem_bytes = 1,
556 T_SHORT_aelem_bytes = 2,
557 T_INT_aelem_bytes = 4,
558 T_LONG_aelem_bytes = 8,
559 #ifdef _LP64
560 T_OBJECT_aelem_bytes = 8,
561 T_ARRAY_aelem_bytes = 8,
562 #else
563 T_OBJECT_aelem_bytes = 4,
564 T_ARRAY_aelem_bytes = 4,
565 #endif
566 T_NARROWOOP_aelem_bytes = 4,
567 T_VOID_aelem_bytes = 0
568 };
570 extern int _type2aelembytes[T_CONFLICT+1]; // maps a BasicType to nof bytes used by its array element
571 #ifdef ASSERT
572 extern int type2aelembytes(BasicType t, bool allow_address = false); // asserts
573 #else
574 inline int type2aelembytes(BasicType t, bool allow_address = false) { return _type2aelembytes[t]; }
575 #endif
578 // JavaValue serves as a container for arbitrary Java values.
580 class JavaValue {
582 public:
583 typedef union JavaCallValue {
584 jfloat f;
585 jdouble d;
586 jint i;
587 jlong l;
588 jobject h;
589 } JavaCallValue;
591 private:
592 BasicType _type;
593 JavaCallValue _value;
595 public:
596 JavaValue(BasicType t = T_ILLEGAL) { _type = t; }
598 JavaValue(jfloat value) {
599 _type = T_FLOAT;
600 _value.f = value;
601 }
603 JavaValue(jdouble value) {
604 _type = T_DOUBLE;
605 _value.d = value;
606 }
608 jfloat get_jfloat() const { return _value.f; }
609 jdouble get_jdouble() const { return _value.d; }
610 jint get_jint() const { return _value.i; }
611 jlong get_jlong() const { return _value.l; }
612 jobject get_jobject() const { return _value.h; }
613 JavaCallValue* get_value_addr() { return &_value; }
614 BasicType get_type() const { return _type; }
616 void set_jfloat(jfloat f) { _value.f = f;}
617 void set_jdouble(jdouble d) { _value.d = d;}
618 void set_jint(jint i) { _value.i = i;}
619 void set_jlong(jlong l) { _value.l = l;}
620 void set_jobject(jobject h) { _value.h = h;}
621 void set_type(BasicType t) { _type = t; }
623 jboolean get_jboolean() const { return (jboolean) (_value.i);}
624 jbyte get_jbyte() const { return (jbyte) (_value.i);}
625 jchar get_jchar() const { return (jchar) (_value.i);}
626 jshort get_jshort() const { return (jshort) (_value.i);}
628 };
631 #define STACK_BIAS 0
632 // V9 Sparc CPU's running in 64 Bit mode use a stack bias of 7ff
633 // in order to extend the reach of the stack pointer.
634 #if defined(SPARC) && defined(_LP64)
635 #undef STACK_BIAS
636 #define STACK_BIAS 0x7ff
637 #endif
640 // TosState describes the top-of-stack state before and after the execution of
641 // a bytecode or method. The top-of-stack value may be cached in one or more CPU
642 // registers. The TosState corresponds to the 'machine represention' of this cached
643 // value. There's 4 states corresponding to the JAVA types int, long, float & double
644 // as well as a 5th state in case the top-of-stack value is actually on the top
645 // of stack (in memory) and thus not cached. The atos state corresponds to the itos
646 // state when it comes to machine representation but is used separately for (oop)
647 // type specific operations (e.g. verification code).
649 enum TosState { // describes the tos cache contents
650 btos = 0, // byte, bool tos cached
651 ctos = 1, // char tos cached
652 stos = 2, // short tos cached
653 itos = 3, // int tos cached
654 ltos = 4, // long tos cached
655 ftos = 5, // float tos cached
656 dtos = 6, // double tos cached
657 atos = 7, // object cached
658 vtos = 8, // tos not cached
659 number_of_states,
660 ilgl // illegal state: should not occur
661 };
664 inline TosState as_TosState(BasicType type) {
665 switch (type) {
666 case T_BYTE : return btos;
667 case T_BOOLEAN: return btos; // FIXME: Add ztos
668 case T_CHAR : return ctos;
669 case T_SHORT : return stos;
670 case T_INT : return itos;
671 case T_LONG : return ltos;
672 case T_FLOAT : return ftos;
673 case T_DOUBLE : return dtos;
674 case T_VOID : return vtos;
675 case T_ARRAY : // fall through
676 case T_OBJECT : return atos;
677 }
678 return ilgl;
679 }
681 inline BasicType as_BasicType(TosState state) {
682 switch (state) {
683 //case ztos: return T_BOOLEAN;//FIXME
684 case btos : return T_BYTE;
685 case ctos : return T_CHAR;
686 case stos : return T_SHORT;
687 case itos : return T_INT;
688 case ltos : return T_LONG;
689 case ftos : return T_FLOAT;
690 case dtos : return T_DOUBLE;
691 case atos : return T_OBJECT;
692 case vtos : return T_VOID;
693 }
694 return T_ILLEGAL;
695 }
698 // Helper function to convert BasicType info into TosState
699 // Note: Cannot define here as it uses global constant at the time being.
700 TosState as_TosState(BasicType type);
703 // ReferenceType is used to distinguish between java/lang/ref/Reference subclasses
705 enum ReferenceType {
706 REF_NONE, // Regular class
707 REF_OTHER, // Subclass of java/lang/ref/Reference, but not subclass of one of the classes below
708 REF_SOFT, // Subclass of java/lang/ref/SoftReference
709 REF_WEAK, // Subclass of java/lang/ref/WeakReference
710 REF_FINAL, // Subclass of java/lang/ref/FinalReference
711 REF_PHANTOM // Subclass of java/lang/ref/PhantomReference
712 };
715 // JavaThreadState keeps track of which part of the code a thread is executing in. This
716 // information is needed by the safepoint code.
717 //
718 // There are 4 essential states:
719 //
720 // _thread_new : Just started, but not executed init. code yet (most likely still in OS init code)
721 // _thread_in_native : In native code. This is a safepoint region, since all oops will be in jobject handles
722 // _thread_in_vm : Executing in the vm
723 // _thread_in_Java : Executing either interpreted or compiled Java code (or could be in a stub)
724 //
725 // Each state has an associated xxxx_trans state, which is an intermediate state used when a thread is in
726 // a transition from one state to another. These extra states makes it possible for the safepoint code to
727 // handle certain thread_states without having to suspend the thread - making the safepoint code faster.
728 //
729 // Given a state, the xxx_trans state can always be found by adding 1.
730 //
731 enum JavaThreadState {
732 _thread_uninitialized = 0, // should never happen (missing initialization)
733 _thread_new = 2, // just starting up, i.e., in process of being initialized
734 _thread_new_trans = 3, // corresponding transition state (not used, included for completness)
735 _thread_in_native = 4, // running in native code
736 _thread_in_native_trans = 5, // corresponding transition state
737 _thread_in_vm = 6, // running in VM
738 _thread_in_vm_trans = 7, // corresponding transition state
739 _thread_in_Java = 8, // running in Java or in stub code
740 _thread_in_Java_trans = 9, // corresponding transition state (not used, included for completness)
741 _thread_blocked = 10, // blocked in vm
742 _thread_blocked_trans = 11, // corresponding transition state
743 _thread_max_state = 12 // maximum thread state+1 - used for statistics allocation
744 };
747 // Handy constants for deciding which compiler mode to use.
748 enum MethodCompilation {
749 InvocationEntryBci = -1, // i.e., not a on-stack replacement compilation
750 InvalidOSREntryBci = -2
751 };
753 // Enumeration to distinguish tiers of compilation
754 enum CompLevel {
755 CompLevel_any = -1,
756 CompLevel_all = -1,
757 CompLevel_none = 0, // Interpreter
758 CompLevel_simple = 1, // C1
759 CompLevel_limited_profile = 2, // C1, invocation & backedge counters
760 CompLevel_full_profile = 3, // C1, invocation & backedge counters + mdo
761 CompLevel_full_optimization = 4, // C2 or Shark
763 #if defined(COMPILER2) || defined(SHARK)
764 CompLevel_highest_tier = CompLevel_full_optimization, // pure C2 and tiered
765 #elif defined(COMPILER1)
766 CompLevel_highest_tier = CompLevel_simple, // pure C1
767 #else
768 CompLevel_highest_tier = CompLevel_none,
769 #endif
771 #if defined(TIERED)
772 CompLevel_initial_compile = CompLevel_full_profile // tiered
773 #elif defined(COMPILER1)
774 CompLevel_initial_compile = CompLevel_simple // pure C1
775 #elif defined(COMPILER2) || defined(SHARK)
776 CompLevel_initial_compile = CompLevel_full_optimization // pure C2
777 #else
778 CompLevel_initial_compile = CompLevel_none
779 #endif
780 };
782 inline bool is_c1_compile(int comp_level) {
783 return comp_level > CompLevel_none && comp_level < CompLevel_full_optimization;
784 }
786 inline bool is_c2_compile(int comp_level) {
787 return comp_level == CompLevel_full_optimization;
788 }
790 inline bool is_highest_tier_compile(int comp_level) {
791 return comp_level == CompLevel_highest_tier;
792 }
794 //----------------------------------------------------------------------------------------------------
795 // 'Forward' declarations of frequently used classes
796 // (in order to reduce interface dependencies & reduce
797 // number of unnecessary compilations after changes)
799 class symbolTable;
800 class ClassFileStream;
802 class Event;
804 class Thread;
805 class VMThread;
806 class JavaThread;
807 class Threads;
809 class VM_Operation;
810 class VMOperationQueue;
812 class CodeBlob;
813 class nmethod;
814 class OSRAdapter;
815 class I2CAdapter;
816 class C2IAdapter;
817 class CompiledIC;
818 class relocInfo;
819 class ScopeDesc;
820 class PcDesc;
822 class Recompiler;
823 class Recompilee;
824 class RecompilationPolicy;
825 class RFrame;
826 class CompiledRFrame;
827 class InterpretedRFrame;
829 class frame;
831 class vframe;
832 class javaVFrame;
833 class interpretedVFrame;
834 class compiledVFrame;
835 class deoptimizedVFrame;
836 class externalVFrame;
837 class entryVFrame;
839 class RegisterMap;
841 class Mutex;
842 class Monitor;
843 class BasicLock;
844 class BasicObjectLock;
846 class PeriodicTask;
848 class JavaCallWrapper;
850 class oopDesc;
852 class NativeCall;
854 class zone;
856 class StubQueue;
858 class outputStream;
860 class ResourceArea;
862 class DebugInformationRecorder;
863 class ScopeValue;
864 class CompressedStream;
865 class DebugInfoReadStream;
866 class DebugInfoWriteStream;
867 class LocationValue;
868 class ConstantValue;
869 class IllegalValue;
871 class PrivilegedElement;
872 class MonitorArray;
874 class MonitorInfo;
876 class OffsetClosure;
877 class OopMapCache;
878 class InterpreterOopMap;
879 class OopMapCacheEntry;
880 class OSThread;
882 typedef int (*OSThreadStartFunc)(void*);
884 class Space;
886 class JavaValue;
887 class methodHandle;
888 class JavaCallArguments;
890 // Basic support for errors (general debug facilities not defined at this point fo the include phase)
892 extern void basic_fatal(const char* msg);
895 //----------------------------------------------------------------------------------------------------
896 // Special constants for debugging
898 const jint badInt = -3; // generic "bad int" value
899 const long badAddressVal = -2; // generic "bad address" value
900 const long badOopVal = -1; // generic "bad oop" value
901 const intptr_t badHeapOopVal = (intptr_t) CONST64(0x2BAD4B0BBAADBABE); // value used to zap heap after GC
902 const int badHandleValue = 0xBC; // value used to zap vm handle area
903 const int badResourceValue = 0xAB; // value used to zap resource area
904 const int freeBlockPad = 0xBA; // value used to pad freed blocks.
905 const int uninitBlockPad = 0xF1; // value used to zap newly malloc'd blocks.
906 const intptr_t badJNIHandleVal = (intptr_t) CONST64(0xFEFEFEFEFEFEFEFE); // value used to zap jni handle area
907 const juint badHeapWordVal = 0xBAADBABE; // value used to zap heap after GC
908 const int badCodeHeapNewVal= 0xCC; // value used to zap Code heap at allocation
909 const int badCodeHeapFreeVal = 0xDD; // value used to zap Code heap at deallocation
912 // (These must be implemented as #defines because C++ compilers are
913 // not obligated to inline non-integral constants!)
914 #define badAddress ((address)::badAddressVal)
915 #define badOop ((oop)::badOopVal)
916 #define badHeapWord (::badHeapWordVal)
917 #define badJNIHandle ((oop)::badJNIHandleVal)
919 // Default TaskQueue size is 16K (32-bit) or 128K (64-bit)
920 #define TASKQUEUE_SIZE (NOT_LP64(1<<14) LP64_ONLY(1<<17))
922 //----------------------------------------------------------------------------------------------------
923 // Utility functions for bitfield manipulations
925 const intptr_t AllBits = ~0; // all bits set in a word
926 const intptr_t NoBits = 0; // no bits set in a word
927 const jlong NoLongBits = 0; // no bits set in a long
928 const intptr_t OneBit = 1; // only right_most bit set in a word
930 // get a word with the n.th or the right-most or left-most n bits set
931 // (note: #define used only so that they can be used in enum constant definitions)
932 #define nth_bit(n) (n >= BitsPerWord ? 0 : OneBit << (n))
933 #define right_n_bits(n) (nth_bit(n) - 1)
934 #define left_n_bits(n) (right_n_bits(n) << (n >= BitsPerWord ? 0 : (BitsPerWord - n)))
936 // bit-operations using a mask m
937 inline void set_bits (intptr_t& x, intptr_t m) { x |= m; }
938 inline void clear_bits (intptr_t& x, intptr_t m) { x &= ~m; }
939 inline intptr_t mask_bits (intptr_t x, intptr_t m) { return x & m; }
940 inline jlong mask_long_bits (jlong x, jlong m) { return x & m; }
941 inline bool mask_bits_are_true (intptr_t flags, intptr_t mask) { return (flags & mask) == mask; }
943 // bit-operations using the n.th bit
944 inline void set_nth_bit(intptr_t& x, int n) { set_bits (x, nth_bit(n)); }
945 inline void clear_nth_bit(intptr_t& x, int n) { clear_bits(x, nth_bit(n)); }
946 inline bool is_set_nth_bit(intptr_t x, int n) { return mask_bits (x, nth_bit(n)) != NoBits; }
948 // returns the bitfield of x starting at start_bit_no with length field_length (no sign-extension!)
949 inline intptr_t bitfield(intptr_t x, int start_bit_no, int field_length) {
950 return mask_bits(x >> start_bit_no, right_n_bits(field_length));
951 }
954 //----------------------------------------------------------------------------------------------------
955 // Utility functions for integers
957 // Avoid use of global min/max macros which may cause unwanted double
958 // evaluation of arguments.
959 #ifdef max
960 #undef max
961 #endif
963 #ifdef min
964 #undef min
965 #endif
967 #define max(a,b) Do_not_use_max_use_MAX2_instead
968 #define min(a,b) Do_not_use_min_use_MIN2_instead
970 // It is necessary to use templates here. Having normal overloaded
971 // functions does not work because it is necessary to provide both 32-
972 // and 64-bit overloaded functions, which does not work, and having
973 // explicitly-typed versions of these routines (i.e., MAX2I, MAX2L)
974 // will be even more error-prone than macros.
975 template<class T> inline T MAX2(T a, T b) { return (a > b) ? a : b; }
976 template<class T> inline T MIN2(T a, T b) { return (a < b) ? a : b; }
977 template<class T> inline T MAX3(T a, T b, T c) { return MAX2(MAX2(a, b), c); }
978 template<class T> inline T MIN3(T a, T b, T c) { return MIN2(MIN2(a, b), c); }
979 template<class T> inline T MAX4(T a, T b, T c, T d) { return MAX2(MAX3(a, b, c), d); }
980 template<class T> inline T MIN4(T a, T b, T c, T d) { return MIN2(MIN3(a, b, c), d); }
982 template<class T> inline T ABS(T x) { return (x > 0) ? x : -x; }
984 // true if x is a power of 2, false otherwise
985 inline bool is_power_of_2(intptr_t x) {
986 return ((x != NoBits) && (mask_bits(x, x - 1) == NoBits));
987 }
989 // long version of is_power_of_2
990 inline bool is_power_of_2_long(jlong x) {
991 return ((x != NoLongBits) && (mask_long_bits(x, x - 1) == NoLongBits));
992 }
994 //* largest i such that 2^i <= x
995 // A negative value of 'x' will return '31'
996 inline int log2_intptr(intptr_t x) {
997 int i = -1;
998 uintptr_t p = 1;
999 while (p != 0 && p <= (uintptr_t)x) {
1000 // p = 2^(i+1) && p <= x (i.e., 2^(i+1) <= x)
1001 i++; p *= 2;
1002 }
1003 // p = 2^(i+1) && x < p (i.e., 2^i <= x < 2^(i+1))
1004 // (if p = 0 then overflow occurred and i = 31)
1005 return i;
1006 }
1008 //* largest i such that 2^i <= x
1009 // A negative value of 'x' will return '63'
1010 inline int log2_long(jlong x) {
1011 int i = -1;
1012 julong p = 1;
1013 while (p != 0 && p <= (julong)x) {
1014 // p = 2^(i+1) && p <= x (i.e., 2^(i+1) <= x)
1015 i++; p *= 2;
1016 }
1017 // p = 2^(i+1) && x < p (i.e., 2^i <= x < 2^(i+1))
1018 // (if p = 0 then overflow occurred and i = 63)
1019 return i;
1020 }
1022 //* the argument must be exactly a power of 2
1023 inline int exact_log2(intptr_t x) {
1024 #ifdef ASSERT
1025 if (!is_power_of_2(x)) basic_fatal("x must be a power of 2");
1026 #endif
1027 return log2_intptr(x);
1028 }
1030 //* the argument must be exactly a power of 2
1031 inline int exact_log2_long(jlong x) {
1032 #ifdef ASSERT
1033 if (!is_power_of_2_long(x)) basic_fatal("x must be a power of 2");
1034 #endif
1035 return log2_long(x);
1036 }
1039 // returns integer round-up to the nearest multiple of s (s must be a power of two)
1040 inline intptr_t round_to(intptr_t x, uintx s) {
1041 #ifdef ASSERT
1042 if (!is_power_of_2(s)) basic_fatal("s must be a power of 2");
1043 #endif
1044 const uintx m = s - 1;
1045 return mask_bits(x + m, ~m);
1046 }
1048 // returns integer round-down to the nearest multiple of s (s must be a power of two)
1049 inline intptr_t round_down(intptr_t x, uintx s) {
1050 #ifdef ASSERT
1051 if (!is_power_of_2(s)) basic_fatal("s must be a power of 2");
1052 #endif
1053 const uintx m = s - 1;
1054 return mask_bits(x, ~m);
1055 }
1058 inline bool is_odd (intx x) { return x & 1; }
1059 inline bool is_even(intx x) { return !is_odd(x); }
1061 // "to" should be greater than "from."
1062 inline intx byte_size(void* from, void* to) {
1063 return (address)to - (address)from;
1064 }
1066 //----------------------------------------------------------------------------------------------------
1067 // Avoid non-portable casts with these routines (DEPRECATED)
1069 // NOTE: USE Bytes class INSTEAD WHERE POSSIBLE
1070 // Bytes is optimized machine-specifically and may be much faster then the portable routines below.
1072 // Given sequence of four bytes, build into a 32-bit word
1073 // following the conventions used in class files.
1074 // On the 386, this could be realized with a simple address cast.
1075 //
1077 // This routine takes eight bytes:
1078 inline u8 build_u8_from( u1 c1, u1 c2, u1 c3, u1 c4, u1 c5, u1 c6, u1 c7, u1 c8 ) {
1079 return (( u8(c1) << 56 ) & ( u8(0xff) << 56 ))
1080 | (( u8(c2) << 48 ) & ( u8(0xff) << 48 ))
1081 | (( u8(c3) << 40 ) & ( u8(0xff) << 40 ))
1082 | (( u8(c4) << 32 ) & ( u8(0xff) << 32 ))
1083 | (( u8(c5) << 24 ) & ( u8(0xff) << 24 ))
1084 | (( u8(c6) << 16 ) & ( u8(0xff) << 16 ))
1085 | (( u8(c7) << 8 ) & ( u8(0xff) << 8 ))
1086 | (( u8(c8) << 0 ) & ( u8(0xff) << 0 ));
1087 }
1089 // This routine takes four bytes:
1090 inline u4 build_u4_from( u1 c1, u1 c2, u1 c3, u1 c4 ) {
1091 return (( u4(c1) << 24 ) & 0xff000000)
1092 | (( u4(c2) << 16 ) & 0x00ff0000)
1093 | (( u4(c3) << 8 ) & 0x0000ff00)
1094 | (( u4(c4) << 0 ) & 0x000000ff);
1095 }
1097 // And this one works if the four bytes are contiguous in memory:
1098 inline u4 build_u4_from( u1* p ) {
1099 return build_u4_from( p[0], p[1], p[2], p[3] );
1100 }
1102 // Ditto for two-byte ints:
1103 inline u2 build_u2_from( u1 c1, u1 c2 ) {
1104 return u2((( u2(c1) << 8 ) & 0xff00)
1105 | (( u2(c2) << 0 ) & 0x00ff));
1106 }
1108 // And this one works if the two bytes are contiguous in memory:
1109 inline u2 build_u2_from( u1* p ) {
1110 return build_u2_from( p[0], p[1] );
1111 }
1113 // Ditto for floats:
1114 inline jfloat build_float_from( u1 c1, u1 c2, u1 c3, u1 c4 ) {
1115 u4 u = build_u4_from( c1, c2, c3, c4 );
1116 return *(jfloat*)&u;
1117 }
1119 inline jfloat build_float_from( u1* p ) {
1120 u4 u = build_u4_from( p );
1121 return *(jfloat*)&u;
1122 }
1125 // now (64-bit) longs
1127 inline jlong build_long_from( u1 c1, u1 c2, u1 c3, u1 c4, u1 c5, u1 c6, u1 c7, u1 c8 ) {
1128 return (( jlong(c1) << 56 ) & ( jlong(0xff) << 56 ))
1129 | (( jlong(c2) << 48 ) & ( jlong(0xff) << 48 ))
1130 | (( jlong(c3) << 40 ) & ( jlong(0xff) << 40 ))
1131 | (( jlong(c4) << 32 ) & ( jlong(0xff) << 32 ))
1132 | (( jlong(c5) << 24 ) & ( jlong(0xff) << 24 ))
1133 | (( jlong(c6) << 16 ) & ( jlong(0xff) << 16 ))
1134 | (( jlong(c7) << 8 ) & ( jlong(0xff) << 8 ))
1135 | (( jlong(c8) << 0 ) & ( jlong(0xff) << 0 ));
1136 }
1138 inline jlong build_long_from( u1* p ) {
1139 return build_long_from( p[0], p[1], p[2], p[3], p[4], p[5], p[6], p[7] );
1140 }
1143 // Doubles, too!
1144 inline jdouble build_double_from( u1 c1, u1 c2, u1 c3, u1 c4, u1 c5, u1 c6, u1 c7, u1 c8 ) {
1145 jlong u = build_long_from( c1, c2, c3, c4, c5, c6, c7, c8 );
1146 return *(jdouble*)&u;
1147 }
1149 inline jdouble build_double_from( u1* p ) {
1150 jlong u = build_long_from( p );
1151 return *(jdouble*)&u;
1152 }
1155 // Portable routines to go the other way:
1157 inline void explode_short_to( u2 x, u1& c1, u1& c2 ) {
1158 c1 = u1(x >> 8);
1159 c2 = u1(x);
1160 }
1162 inline void explode_short_to( u2 x, u1* p ) {
1163 explode_short_to( x, p[0], p[1]);
1164 }
1166 inline void explode_int_to( u4 x, u1& c1, u1& c2, u1& c3, u1& c4 ) {
1167 c1 = u1(x >> 24);
1168 c2 = u1(x >> 16);
1169 c3 = u1(x >> 8);
1170 c4 = u1(x);
1171 }
1173 inline void explode_int_to( u4 x, u1* p ) {
1174 explode_int_to( x, p[0], p[1], p[2], p[3]);
1175 }
1178 // Pack and extract shorts to/from ints:
1180 inline int extract_low_short_from_int(jint x) {
1181 return x & 0xffff;
1182 }
1184 inline int extract_high_short_from_int(jint x) {
1185 return (x >> 16) & 0xffff;
1186 }
1188 inline int build_int_from_shorts( jushort low, jushort high ) {
1189 return ((int)((unsigned int)high << 16) | (unsigned int)low);
1190 }
1192 // Printf-style formatters for fixed- and variable-width types as pointers and
1193 // integers. These are derived from the definitions in inttypes.h. If the platform
1194 // doesn't provide appropriate definitions, they should be provided in
1195 // the compiler-specific definitions file (e.g., globalDefinitions_gcc.hpp)
1197 #define BOOL_TO_STR(_b_) ((_b_) ? "true" : "false")
1199 // Format 32-bit quantities.
1200 #define INT32_FORMAT "%" PRId32
1201 #define UINT32_FORMAT "%" PRIu32
1202 #define INT32_FORMAT_W(width) "%" #width PRId32
1203 #define UINT32_FORMAT_W(width) "%" #width PRIu32
1205 #define PTR32_FORMAT "0x%08" PRIx32
1207 // Format 64-bit quantities.
1208 #define INT64_FORMAT "%" PRId64
1209 #define UINT64_FORMAT "%" PRIu64
1210 #define INT64_FORMAT_W(width) "%" #width PRId64
1211 #define UINT64_FORMAT_W(width) "%" #width PRIu64
1213 #define PTR64_FORMAT "0x%016" PRIx64
1215 // Format pointers which change size between 32- and 64-bit.
1216 #ifdef _LP64
1217 #define INTPTR_FORMAT "0x%016" PRIxPTR
1218 #define PTR_FORMAT "0x%016" PRIxPTR
1219 #else // !_LP64
1220 #define INTPTR_FORMAT "0x%08" PRIxPTR
1221 #define PTR_FORMAT "0x%08" PRIxPTR
1222 #endif // _LP64
1224 #define SSIZE_FORMAT "%" PRIdPTR
1225 #define SIZE_FORMAT "%" PRIuPTR
1226 #define SSIZE_FORMAT_W(width) "%" #width PRIdPTR
1227 #define SIZE_FORMAT_W(width) "%" #width PRIuPTR
1229 #define INTX_FORMAT "%" PRIdPTR
1230 #define UINTX_FORMAT "%" PRIuPTR
1231 #define INTX_FORMAT_W(width) "%" #width PRIdPTR
1232 #define UINTX_FORMAT_W(width) "%" #width PRIuPTR
1235 // Enable zap-a-lot if in debug version.
1237 # ifdef ASSERT
1238 # ifdef COMPILER2
1239 # define ENABLE_ZAP_DEAD_LOCALS
1240 #endif /* COMPILER2 */
1241 # endif /* ASSERT */
1243 #define ARRAY_SIZE(array) (sizeof(array)/sizeof((array)[0]))
1245 #endif // SHARE_VM_UTILITIES_GLOBALDEFINITIONS_HPP