Mon, 25 May 2020 14:24:27 +0800
8244407: JVM crashes after transformation in C2 IdealLoopTree::split_fall_in
Reviewed-by: thartmann, kvn, andrew
Contributed-by: zhouyong44@huawei.com
1 /*
2 * Copyright (c) 1997, 2018, 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_OPTO_TYPE_HPP
26 #define SHARE_VM_OPTO_TYPE_HPP
28 #include "libadt/port.hpp"
29 #include "opto/adlcVMDeps.hpp"
30 #include "runtime/handles.hpp"
32 // Portions of code courtesy of Clifford Click
34 // Optimization - Graph Style
37 // This class defines a Type lattice. The lattice is used in the constant
38 // propagation algorithms, and for some type-checking of the iloc code.
39 // Basic types include RSD's (lower bound, upper bound, stride for integers),
40 // float & double precision constants, sets of data-labels and code-labels.
41 // The complete lattice is described below. Subtypes have no relationship to
42 // up or down in the lattice; that is entirely determined by the behavior of
43 // the MEET/JOIN functions.
45 class Dict;
46 class Type;
47 class TypeD;
48 class TypeF;
49 class TypeInt;
50 class TypeLong;
51 class TypeNarrowPtr;
52 class TypeNarrowOop;
53 class TypeNarrowKlass;
54 class TypeAry;
55 class TypeTuple;
56 class TypeVect;
57 class TypeVectS;
58 class TypeVectD;
59 class TypeVectX;
60 class TypeVectY;
61 class TypePtr;
62 class TypeRawPtr;
63 class TypeOopPtr;
64 class TypeInstPtr;
65 class TypeAryPtr;
66 class TypeKlassPtr;
67 class TypeMetadataPtr;
69 //------------------------------Type-------------------------------------------
70 // Basic Type object, represents a set of primitive Values.
71 // Types are hash-cons'd into a private class dictionary, so only one of each
72 // different kind of Type exists. Types are never modified after creation, so
73 // all their interesting fields are constant.
74 class Type {
75 friend class VMStructs;
77 public:
78 enum TYPES {
79 Bad=0, // Type check
80 Control, // Control of code (not in lattice)
81 Top, // Top of the lattice
82 Int, // Integer range (lo-hi)
83 Long, // Long integer range (lo-hi)
84 Half, // Placeholder half of doubleword
85 NarrowOop, // Compressed oop pointer
86 NarrowKlass, // Compressed klass pointer
88 Tuple, // Method signature or object layout
89 Array, // Array types
90 VectorS, // 32bit Vector types
91 VectorD, // 64bit Vector types
92 VectorX, // 128bit Vector types
93 VectorY, // 256bit Vector types
95 AnyPtr, // Any old raw, klass, inst, or array pointer
96 RawPtr, // Raw (non-oop) pointers
97 OopPtr, // Any and all Java heap entities
98 InstPtr, // Instance pointers (non-array objects)
99 AryPtr, // Array pointers
100 // (Ptr order matters: See is_ptr, isa_ptr, is_oopptr, isa_oopptr.)
102 MetadataPtr, // Generic metadata
103 KlassPtr, // Klass pointers
105 Function, // Function signature
106 Abio, // Abstract I/O
107 Return_Address, // Subroutine return address
108 Memory, // Abstract store
109 FloatTop, // No float value
110 FloatCon, // Floating point constant
111 FloatBot, // Any float value
112 DoubleTop, // No double value
113 DoubleCon, // Double precision constant
114 DoubleBot, // Any double value
115 Bottom, // Bottom of lattice
116 lastype // Bogus ending type (not in lattice)
117 };
119 // Signal values for offsets from a base pointer
120 enum OFFSET_SIGNALS {
121 OffsetTop = -2000000000, // undefined offset
122 OffsetBot = -2000000001 // any possible offset
123 };
125 // Min and max WIDEN values.
126 enum WIDEN {
127 WidenMin = 0,
128 WidenMax = 3
129 };
131 private:
132 typedef struct {
133 TYPES dual_type;
134 BasicType basic_type;
135 const char* msg;
136 bool isa_oop;
137 uint ideal_reg;
138 relocInfo::relocType reloc;
139 } TypeInfo;
141 // Dictionary of types shared among compilations.
142 static Dict* _shared_type_dict;
143 static const TypeInfo _type_info[];
145 static int uhash( const Type *const t );
146 // Structural equality check. Assumes that cmp() has already compared
147 // the _base types and thus knows it can cast 't' appropriately.
148 virtual bool eq( const Type *t ) const;
150 // Top-level hash-table of types
151 static Dict *type_dict() {
152 return Compile::current()->type_dict();
153 }
155 // DUAL operation: reflect around lattice centerline. Used instead of
156 // join to ensure my lattice is symmetric up and down. Dual is computed
157 // lazily, on demand, and cached in _dual.
158 const Type *_dual; // Cached dual value
159 // Table for efficient dualing of base types
160 static const TYPES dual_type[lastype];
162 #ifdef ASSERT
163 // One type is interface, the other is oop
164 virtual bool interface_vs_oop_helper(const Type *t) const;
165 #endif
167 const Type *meet_helper(const Type *t, bool include_speculative) const;
169 protected:
170 // Each class of type is also identified by its base.
171 const TYPES _base; // Enum of Types type
173 Type( TYPES t ) : _dual(NULL), _base(t) {} // Simple types
174 // ~Type(); // Use fast deallocation
175 const Type *hashcons(); // Hash-cons the type
176 virtual const Type *filter_helper(const Type *kills, bool include_speculative) const;
177 const Type *join_helper(const Type *t, bool include_speculative) const {
178 return dual()->meet_helper(t->dual(), include_speculative)->dual();
179 }
181 public:
183 inline void* operator new( size_t x ) throw() {
184 Compile* compile = Compile::current();
185 compile->set_type_last_size(x);
186 void *temp = compile->type_arena()->Amalloc_D(x);
187 compile->set_type_hwm(temp);
188 return temp;
189 }
190 inline void operator delete( void* ptr ) {
191 Compile* compile = Compile::current();
192 compile->type_arena()->Afree(ptr,compile->type_last_size());
193 }
195 // Initialize the type system for a particular compilation.
196 static void Initialize(Compile* compile);
198 // Initialize the types shared by all compilations.
199 static void Initialize_shared(Compile* compile);
201 TYPES base() const {
202 assert(_base > Bad && _base < lastype, "sanity");
203 return _base;
204 }
206 // Create a new hash-consd type
207 static const Type *make(enum TYPES);
208 // Test for equivalence of types
209 static int cmp( const Type *const t1, const Type *const t2 );
210 // Test for higher or equal in lattice
211 // Variant that drops the speculative part of the types
212 bool higher_equal(const Type *t) const {
213 return !cmp(meet(t),t->remove_speculative());
214 }
215 // Variant that keeps the speculative part of the types
216 bool higher_equal_speculative(const Type *t) const {
217 return !cmp(meet_speculative(t),t);
218 }
220 // MEET operation; lower in lattice.
221 // Variant that drops the speculative part of the types
222 const Type *meet(const Type *t) const {
223 return meet_helper(t, false);
224 }
225 // Variant that keeps the speculative part of the types
226 const Type *meet_speculative(const Type *t) const {
227 return meet_helper(t, true);
228 }
229 // WIDEN: 'widens' for Ints and other range types
230 virtual const Type *widen( const Type *old, const Type* limit ) const { return this; }
231 // NARROW: complement for widen, used by pessimistic phases
232 virtual const Type *narrow( const Type *old ) const { return this; }
234 // DUAL operation: reflect around lattice centerline. Used instead of
235 // join to ensure my lattice is symmetric up and down.
236 const Type *dual() const { return _dual; }
238 // Compute meet dependent on base type
239 virtual const Type *xmeet( const Type *t ) const;
240 virtual const Type *xdual() const; // Compute dual right now.
242 // JOIN operation; higher in lattice. Done by finding the dual of the
243 // meet of the dual of the 2 inputs.
244 // Variant that drops the speculative part of the types
245 const Type *join(const Type *t) const {
246 return join_helper(t, false);
247 }
248 // Variant that keeps the speculative part of the types
249 const Type *join_speculative(const Type *t) const {
250 return join_helper(t, true);
251 }
253 // Modified version of JOIN adapted to the needs Node::Value.
254 // Normalizes all empty values to TOP. Does not kill _widen bits.
255 // Currently, it also works around limitations involving interface types.
256 // Variant that drops the speculative part of the types
257 const Type *filter(const Type *kills) const {
258 return filter_helper(kills, false);
259 }
260 // Variant that keeps the speculative part of the types
261 const Type *filter_speculative(const Type *kills) const {
262 return filter_helper(kills, true);
263 }
265 #ifdef ASSERT
266 // One type is interface, the other is oop
267 virtual bool interface_vs_oop(const Type *t) const;
268 #endif
270 // Returns true if this pointer points at memory which contains a
271 // compressed oop references.
272 bool is_ptr_to_narrowoop() const;
273 bool is_ptr_to_narrowklass() const;
275 bool is_ptr_to_boxing_obj() const;
278 // Convenience access
279 float getf() const;
280 double getd() const;
282 const TypeInt *is_int() const;
283 const TypeInt *isa_int() const; // Returns NULL if not an Int
284 const TypeLong *is_long() const;
285 const TypeLong *isa_long() const; // Returns NULL if not a Long
286 const TypeD *isa_double() const; // Returns NULL if not a Double{Top,Con,Bot}
287 const TypeD *is_double_constant() const; // Asserts it is a DoubleCon
288 const TypeD *isa_double_constant() const; // Returns NULL if not a DoubleCon
289 const TypeF *isa_float() const; // Returns NULL if not a Float{Top,Con,Bot}
290 const TypeF *is_float_constant() const; // Asserts it is a FloatCon
291 const TypeF *isa_float_constant() const; // Returns NULL if not a FloatCon
292 const TypeTuple *is_tuple() const; // Collection of fields, NOT a pointer
293 const TypeAry *is_ary() const; // Array, NOT array pointer
294 const TypeVect *is_vect() const; // Vector
295 const TypeVect *isa_vect() const; // Returns NULL if not a Vector
296 const TypePtr *is_ptr() const; // Asserts it is a ptr type
297 const TypePtr *isa_ptr() const; // Returns NULL if not ptr type
298 const TypeRawPtr *isa_rawptr() const; // NOT Java oop
299 const TypeRawPtr *is_rawptr() const; // Asserts is rawptr
300 const TypeNarrowOop *is_narrowoop() const; // Java-style GC'd pointer
301 const TypeNarrowOop *isa_narrowoop() const; // Returns NULL if not oop ptr type
302 const TypeNarrowKlass *is_narrowklass() const; // compressed klass pointer
303 const TypeNarrowKlass *isa_narrowklass() const;// Returns NULL if not oop ptr type
304 const TypeOopPtr *isa_oopptr() const; // Returns NULL if not oop ptr type
305 const TypeOopPtr *is_oopptr() const; // Java-style GC'd pointer
306 const TypeInstPtr *isa_instptr() const; // Returns NULL if not InstPtr
307 const TypeInstPtr *is_instptr() const; // Instance
308 const TypeAryPtr *isa_aryptr() const; // Returns NULL if not AryPtr
309 const TypeAryPtr *is_aryptr() const; // Array oop
311 const TypeMetadataPtr *isa_metadataptr() const; // Returns NULL if not oop ptr type
312 const TypeMetadataPtr *is_metadataptr() const; // Java-style GC'd pointer
313 const TypeKlassPtr *isa_klassptr() const; // Returns NULL if not KlassPtr
314 const TypeKlassPtr *is_klassptr() const; // assert if not KlassPtr
316 virtual bool is_finite() const; // Has a finite value
317 virtual bool is_nan() const; // Is not a number (NaN)
319 // Returns this ptr type or the equivalent ptr type for this compressed pointer.
320 const TypePtr* make_ptr() const;
322 // Returns this oopptr type or the equivalent oopptr type for this compressed pointer.
323 // Asserts if the underlying type is not an oopptr or narrowoop.
324 const TypeOopPtr* make_oopptr() const;
326 // Returns this compressed pointer or the equivalent compressed version
327 // of this pointer type.
328 const TypeNarrowOop* make_narrowoop() const;
330 // Returns this compressed klass pointer or the equivalent
331 // compressed version of this pointer type.
332 const TypeNarrowKlass* make_narrowklass() const;
334 // Special test for register pressure heuristic
335 bool is_floatingpoint() const; // True if Float or Double base type
337 // Do you have memory, directly or through a tuple?
338 bool has_memory( ) const;
340 // TRUE if type is a singleton
341 virtual bool singleton(void) const;
343 // TRUE if type is above the lattice centerline, and is therefore vacuous
344 virtual bool empty(void) const;
346 // Return a hash for this type. The hash function is public so ConNode
347 // (constants) can hash on their constant, which is represented by a Type.
348 virtual int hash() const;
350 // Map ideal registers (machine types) to ideal types
351 static const Type *mreg2type[];
353 // Printing, statistics
354 #ifndef PRODUCT
355 void dump_on(outputStream *st) const;
356 void dump() const {
357 dump_on(tty);
358 }
359 virtual void dump2( Dict &d, uint depth, outputStream *st ) const;
360 static void dump_stats();
362 static const char* str(const Type* t);
363 #endif
364 void typerr(const Type *t) const; // Mixing types error
366 // Create basic type
367 static const Type* get_const_basic_type(BasicType type) {
368 assert((uint)type <= T_CONFLICT && _const_basic_type[type] != NULL, "bad type");
369 return _const_basic_type[type];
370 }
372 // For two instance arrays of same dimension, return the base element types.
373 // Otherwise or if the arrays have different dimensions, return NULL.
374 static void get_arrays_base_elements(const Type *a1, const Type *a2,
375 const TypeInstPtr **e1, const TypeInstPtr **e2);
377 // Mapping to the array element's basic type.
378 BasicType array_element_basic_type() const;
380 // Create standard type for a ciType:
381 static const Type* get_const_type(ciType* type);
383 // Create standard zero value:
384 static const Type* get_zero_type(BasicType type) {
385 assert((uint)type <= T_CONFLICT && _zero_type[type] != NULL, "bad type");
386 return _zero_type[type];
387 }
389 // Report if this is a zero value (not top).
390 bool is_zero_type() const {
391 BasicType type = basic_type();
392 if (type == T_VOID || type >= T_CONFLICT)
393 return false;
394 else
395 return (this == _zero_type[type]);
396 }
398 // Convenience common pre-built types.
399 static const Type *ABIO;
400 static const Type *BOTTOM;
401 static const Type *CONTROL;
402 static const Type *DOUBLE;
403 static const Type *FLOAT;
404 static const Type *HALF;
405 static const Type *MEMORY;
406 static const Type *MULTI;
407 static const Type *RETURN_ADDRESS;
408 static const Type *TOP;
410 // Mapping from compiler type to VM BasicType
411 BasicType basic_type() const { return _type_info[_base].basic_type; }
412 uint ideal_reg() const { return _type_info[_base].ideal_reg; }
413 const char* msg() const { return _type_info[_base].msg; }
414 bool isa_oop_ptr() const { return _type_info[_base].isa_oop; }
415 relocInfo::relocType reloc() const { return _type_info[_base].reloc; }
417 // Mapping from CI type system to compiler type:
418 static const Type* get_typeflow_type(ciType* type);
420 static const Type* make_from_constant(ciConstant constant,
421 bool require_constant = false,
422 bool is_autobox_cache = false);
424 // Speculative type. See TypeInstPtr
425 virtual const TypeOopPtr* speculative() const { return NULL; }
426 virtual ciKlass* speculative_type() const { return NULL; }
427 const Type* maybe_remove_speculative(bool include_speculative) const;
428 virtual const Type* remove_speculative() const { return this; }
430 virtual bool would_improve_type(ciKlass* exact_kls, int inline_depth) const {
431 return exact_kls != NULL;
432 }
434 private:
435 // support arrays
436 static const Type* _zero_type[T_CONFLICT+1];
437 static const Type* _const_basic_type[T_CONFLICT+1];
438 };
440 //------------------------------TypeF------------------------------------------
441 // Class of Float-Constant Types.
442 class TypeF : public Type {
443 TypeF( float f ) : Type(FloatCon), _f(f) {};
444 public:
445 virtual bool eq( const Type *t ) const;
446 virtual int hash() const; // Type specific hashing
447 virtual bool singleton(void) const; // TRUE if type is a singleton
448 virtual bool empty(void) const; // TRUE if type is vacuous
449 public:
450 const float _f; // Float constant
452 static const TypeF *make(float f);
454 virtual bool is_finite() const; // Has a finite value
455 virtual bool is_nan() const; // Is not a number (NaN)
457 virtual const Type *xmeet( const Type *t ) const;
458 virtual const Type *xdual() const; // Compute dual right now.
459 // Convenience common pre-built types.
460 static const TypeF *ZERO; // positive zero only
461 static const TypeF *ONE;
462 #ifndef PRODUCT
463 virtual void dump2( Dict &d, uint depth, outputStream *st ) const;
464 #endif
465 };
467 //------------------------------TypeD------------------------------------------
468 // Class of Double-Constant Types.
469 class TypeD : public Type {
470 TypeD( double d ) : Type(DoubleCon), _d(d) {};
471 public:
472 virtual bool eq( const Type *t ) const;
473 virtual int hash() const; // Type specific hashing
474 virtual bool singleton(void) const; // TRUE if type is a singleton
475 virtual bool empty(void) const; // TRUE if type is vacuous
476 public:
477 const double _d; // Double constant
479 static const TypeD *make(double d);
481 virtual bool is_finite() const; // Has a finite value
482 virtual bool is_nan() const; // Is not a number (NaN)
484 virtual const Type *xmeet( const Type *t ) const;
485 virtual const Type *xdual() const; // Compute dual right now.
486 // Convenience common pre-built types.
487 static const TypeD *ZERO; // positive zero only
488 static const TypeD *ONE;
489 #ifndef PRODUCT
490 virtual void dump2( Dict &d, uint depth, outputStream *st ) const;
491 #endif
492 };
494 //------------------------------TypeInt----------------------------------------
495 // Class of integer ranges, the set of integers between a lower bound and an
496 // upper bound, inclusive.
497 class TypeInt : public Type {
498 TypeInt( jint lo, jint hi, int w );
499 protected:
500 virtual const Type *filter_helper(const Type *kills, bool include_speculative) const;
502 public:
503 typedef jint NativeType;
504 virtual bool eq( const Type *t ) const;
505 virtual int hash() const; // Type specific hashing
506 virtual bool singleton(void) const; // TRUE if type is a singleton
507 virtual bool empty(void) const; // TRUE if type is vacuous
508 const jint _lo, _hi; // Lower bound, upper bound
509 const short _widen; // Limit on times we widen this sucker
511 static const TypeInt *make(jint lo);
512 // must always specify w
513 static const TypeInt *make(jint lo, jint hi, int w);
515 // Check for single integer
516 int is_con() const { return _lo==_hi; }
517 bool is_con(int i) const { return is_con() && _lo == i; }
518 jint get_con() const { assert( is_con(), "" ); return _lo; }
520 virtual bool is_finite() const; // Has a finite value
522 virtual const Type *xmeet( const Type *t ) const;
523 virtual const Type *xdual() const; // Compute dual right now.
524 virtual const Type *widen( const Type *t, const Type* limit_type ) const;
525 virtual const Type *narrow( const Type *t ) const;
526 // Do not kill _widen bits.
527 // Convenience common pre-built types.
528 static const TypeInt *MINUS_1;
529 static const TypeInt *ZERO;
530 static const TypeInt *ONE;
531 static const TypeInt *BOOL;
532 static const TypeInt *CC;
533 static const TypeInt *CC_LT; // [-1] == MINUS_1
534 static const TypeInt *CC_GT; // [1] == ONE
535 static const TypeInt *CC_EQ; // [0] == ZERO
536 static const TypeInt *CC_LE; // [-1,0]
537 static const TypeInt *CC_GE; // [0,1] == BOOL (!)
538 static const TypeInt *BYTE;
539 static const TypeInt *UBYTE;
540 static const TypeInt *CHAR;
541 static const TypeInt *SHORT;
542 static const TypeInt *POS;
543 static const TypeInt *POS1;
544 static const TypeInt *INT;
545 static const TypeInt *SYMINT; // symmetric range [-max_jint..max_jint]
546 static const TypeInt *TYPE_DOMAIN; // alias for TypeInt::INT
548 static const TypeInt *as_self(const Type *t) { return t->is_int(); }
549 #ifndef PRODUCT
550 virtual void dump2( Dict &d, uint depth, outputStream *st ) const;
551 #endif
552 };
555 //------------------------------TypeLong---------------------------------------
556 // Class of long integer ranges, the set of integers between a lower bound and
557 // an upper bound, inclusive.
558 class TypeLong : public Type {
559 TypeLong( jlong lo, jlong hi, int w );
560 protected:
561 // Do not kill _widen bits.
562 virtual const Type *filter_helper(const Type *kills, bool include_speculative) const;
563 public:
564 typedef jlong NativeType;
565 virtual bool eq( const Type *t ) const;
566 virtual int hash() const; // Type specific hashing
567 virtual bool singleton(void) const; // TRUE if type is a singleton
568 virtual bool empty(void) const; // TRUE if type is vacuous
569 public:
570 const jlong _lo, _hi; // Lower bound, upper bound
571 const short _widen; // Limit on times we widen this sucker
573 static const TypeLong *make(jlong lo);
574 // must always specify w
575 static const TypeLong *make(jlong lo, jlong hi, int w);
577 // Check for single integer
578 int is_con() const { return _lo==_hi; }
579 bool is_con(int i) const { return is_con() && _lo == i; }
580 jlong get_con() const { assert( is_con(), "" ); return _lo; }
582 // Check for positive 32-bit value.
583 int is_positive_int() const { return _lo >= 0 && _hi <= (jlong)max_jint; }
585 virtual bool is_finite() const; // Has a finite value
588 virtual const Type *xmeet( const Type *t ) const;
589 virtual const Type *xdual() const; // Compute dual right now.
590 virtual const Type *widen( const Type *t, const Type* limit_type ) const;
591 virtual const Type *narrow( const Type *t ) const;
592 // Convenience common pre-built types.
593 static const TypeLong *MINUS_1;
594 static const TypeLong *ZERO;
595 static const TypeLong *ONE;
596 static const TypeLong *POS;
597 static const TypeLong *LONG;
598 static const TypeLong *INT; // 32-bit subrange [min_jint..max_jint]
599 static const TypeLong *UINT; // 32-bit unsigned [0..max_juint]
600 static const TypeLong *TYPE_DOMAIN; // alias for TypeLong::LONG
602 // static convenience methods.
603 static const TypeLong *as_self(const Type *t) { return t->is_long(); }
605 #ifndef PRODUCT
606 virtual void dump2( Dict &d, uint, outputStream *st ) const;// Specialized per-Type dumping
607 #endif
608 };
610 //------------------------------TypeTuple--------------------------------------
611 // Class of Tuple Types, essentially type collections for function signatures
612 // and class layouts. It happens to also be a fast cache for the HotSpot
613 // signature types.
614 class TypeTuple : public Type {
615 TypeTuple( uint cnt, const Type **fields ) : Type(Tuple), _cnt(cnt), _fields(fields) { }
616 public:
617 virtual bool eq( const Type *t ) const;
618 virtual int hash() const; // Type specific hashing
619 virtual bool singleton(void) const; // TRUE if type is a singleton
620 virtual bool empty(void) const; // TRUE if type is vacuous
622 public:
623 const uint _cnt; // Count of fields
624 const Type ** const _fields; // Array of field types
626 // Accessors:
627 uint cnt() const { return _cnt; }
628 const Type* field_at(uint i) const {
629 assert(i < _cnt, "oob");
630 return _fields[i];
631 }
632 void set_field_at(uint i, const Type* t) {
633 assert(i < _cnt, "oob");
634 _fields[i] = t;
635 }
637 static const TypeTuple *make( uint cnt, const Type **fields );
638 static const TypeTuple *make_range(ciSignature *sig);
639 static const TypeTuple *make_domain(ciInstanceKlass* recv, ciSignature *sig);
641 // Subroutine call type with space allocated for argument types
642 static const Type **fields( uint arg_cnt );
644 virtual const Type *xmeet( const Type *t ) const;
645 virtual const Type *xdual() const; // Compute dual right now.
646 // Convenience common pre-built types.
647 static const TypeTuple *IFBOTH;
648 static const TypeTuple *IFFALSE;
649 static const TypeTuple *IFTRUE;
650 static const TypeTuple *IFNEITHER;
651 static const TypeTuple *LOOPBODY;
652 static const TypeTuple *MEMBAR;
653 static const TypeTuple *STORECONDITIONAL;
654 static const TypeTuple *START_I2C;
655 static const TypeTuple *INT_PAIR;
656 static const TypeTuple *LONG_PAIR;
657 static const TypeTuple *INT_CC_PAIR;
658 static const TypeTuple *LONG_CC_PAIR;
659 #ifndef PRODUCT
660 virtual void dump2( Dict &d, uint, outputStream *st ) const; // Specialized per-Type dumping
661 #endif
662 };
664 //------------------------------TypeAry----------------------------------------
665 // Class of Array Types
666 class TypeAry : public Type {
667 TypeAry(const Type* elem, const TypeInt* size, bool stable) : Type(Array),
668 _elem(elem), _size(size), _stable(stable) {}
669 public:
670 virtual bool eq( const Type *t ) const;
671 virtual int hash() const; // Type specific hashing
672 virtual bool singleton(void) const; // TRUE if type is a singleton
673 virtual bool empty(void) const; // TRUE if type is vacuous
675 private:
676 const Type *_elem; // Element type of array
677 const TypeInt *_size; // Elements in array
678 const bool _stable; // Are elements @Stable?
679 friend class TypeAryPtr;
681 public:
682 static const TypeAry* make(const Type* elem, const TypeInt* size, bool stable = false);
684 virtual const Type *xmeet( const Type *t ) const;
685 virtual const Type *xdual() const; // Compute dual right now.
686 bool ary_must_be_exact() const; // true if arrays of such are never generic
687 virtual const Type* remove_speculative() const;
688 #ifdef ASSERT
689 // One type is interface, the other is oop
690 virtual bool interface_vs_oop(const Type *t) const;
691 #endif
692 #ifndef PRODUCT
693 virtual void dump2( Dict &d, uint, outputStream *st ) const; // Specialized per-Type dumping
694 #endif
695 };
697 //------------------------------TypeVect---------------------------------------
698 // Class of Vector Types
699 class TypeVect : public Type {
700 const Type* _elem; // Vector's element type
701 const uint _length; // Elements in vector (power of 2)
703 protected:
704 TypeVect(TYPES t, const Type* elem, uint length) : Type(t),
705 _elem(elem), _length(length) {}
707 public:
708 const Type* element_type() const { return _elem; }
709 BasicType element_basic_type() const { return _elem->array_element_basic_type(); }
710 uint length() const { return _length; }
711 uint length_in_bytes() const {
712 return _length * type2aelembytes(element_basic_type());
713 }
715 virtual bool eq(const Type *t) const;
716 virtual int hash() const; // Type specific hashing
717 virtual bool singleton(void) const; // TRUE if type is a singleton
718 virtual bool empty(void) const; // TRUE if type is vacuous
720 static const TypeVect *make(const BasicType elem_bt, uint length) {
721 // Use bottom primitive type.
722 return make(get_const_basic_type(elem_bt), length);
723 }
724 // Used directly by Replicate nodes to construct singleton vector.
725 static const TypeVect *make(const Type* elem, uint length);
727 virtual const Type *xmeet( const Type *t) const;
728 virtual const Type *xdual() const; // Compute dual right now.
730 static const TypeVect *VECTS;
731 static const TypeVect *VECTD;
732 static const TypeVect *VECTX;
733 static const TypeVect *VECTY;
735 #ifndef PRODUCT
736 virtual void dump2(Dict &d, uint, outputStream *st) const; // Specialized per-Type dumping
737 #endif
738 };
740 class TypeVectS : public TypeVect {
741 friend class TypeVect;
742 TypeVectS(const Type* elem, uint length) : TypeVect(VectorS, elem, length) {}
743 };
745 class TypeVectD : public TypeVect {
746 friend class TypeVect;
747 TypeVectD(const Type* elem, uint length) : TypeVect(VectorD, elem, length) {}
748 };
750 class TypeVectX : public TypeVect {
751 friend class TypeVect;
752 TypeVectX(const Type* elem, uint length) : TypeVect(VectorX, elem, length) {}
753 };
755 class TypeVectY : public TypeVect {
756 friend class TypeVect;
757 TypeVectY(const Type* elem, uint length) : TypeVect(VectorY, elem, length) {}
758 };
760 //------------------------------TypePtr----------------------------------------
761 // Class of machine Pointer Types: raw data, instances or arrays.
762 // If the _base enum is AnyPtr, then this refers to all of the above.
763 // Otherwise the _base will indicate which subset of pointers is affected,
764 // and the class will be inherited from.
765 class TypePtr : public Type {
766 friend class TypeNarrowPtr;
767 public:
768 enum PTR { TopPTR, AnyNull, Constant, Null, NotNull, BotPTR, lastPTR };
769 protected:
770 TypePtr( TYPES t, PTR ptr, int offset ) : Type(t), _ptr(ptr), _offset(offset) {}
771 virtual bool eq( const Type *t ) const;
772 virtual int hash() const; // Type specific hashing
773 static const PTR ptr_meet[lastPTR][lastPTR];
774 static const PTR ptr_dual[lastPTR];
775 static const char * const ptr_msg[lastPTR];
777 public:
778 const int _offset; // Offset into oop, with TOP & BOT
779 const PTR _ptr; // Pointer equivalence class
781 const int offset() const { return _offset; }
782 const PTR ptr() const { return _ptr; }
784 static const TypePtr *make( TYPES t, PTR ptr, int offset );
786 // Return a 'ptr' version of this type
787 virtual const Type *cast_to_ptr_type(PTR ptr) const;
789 virtual intptr_t get_con() const;
791 int xadd_offset( intptr_t offset ) const;
792 virtual const TypePtr *add_offset( intptr_t offset ) const;
794 virtual bool singleton(void) const; // TRUE if type is a singleton
795 virtual bool empty(void) const; // TRUE if type is vacuous
796 virtual const Type *xmeet( const Type *t ) const;
797 int meet_offset( int offset ) const;
798 int dual_offset( ) const;
799 virtual const Type *xdual() const; // Compute dual right now.
801 // meet, dual and join over pointer equivalence sets
802 PTR meet_ptr( const PTR in_ptr ) const { return ptr_meet[in_ptr][ptr()]; }
803 PTR dual_ptr() const { return ptr_dual[ptr()]; }
805 // This is textually confusing unless one recalls that
806 // join(t) == dual()->meet(t->dual())->dual().
807 PTR join_ptr( const PTR in_ptr ) const {
808 return ptr_dual[ ptr_meet[ ptr_dual[in_ptr] ] [ dual_ptr() ] ];
809 }
811 // Tests for relation to centerline of type lattice:
812 static bool above_centerline(PTR ptr) { return (ptr <= AnyNull); }
813 static bool below_centerline(PTR ptr) { return (ptr >= NotNull); }
814 // Convenience common pre-built types.
815 static const TypePtr *NULL_PTR;
816 static const TypePtr *NOTNULL;
817 static const TypePtr *BOTTOM;
818 #ifndef PRODUCT
819 virtual void dump2( Dict &d, uint depth, outputStream *st ) const;
820 #endif
821 };
823 //------------------------------TypeRawPtr-------------------------------------
824 // Class of raw pointers, pointers to things other than Oops. Examples
825 // include the stack pointer, top of heap, card-marking area, handles, etc.
826 class TypeRawPtr : public TypePtr {
827 protected:
828 TypeRawPtr( PTR ptr, address bits ) : TypePtr(RawPtr,ptr,0), _bits(bits){}
829 public:
830 virtual bool eq( const Type *t ) const;
831 virtual int hash() const; // Type specific hashing
833 const address _bits; // Constant value, if applicable
835 static const TypeRawPtr *make( PTR ptr );
836 static const TypeRawPtr *make( address bits );
838 // Return a 'ptr' version of this type
839 virtual const Type *cast_to_ptr_type(PTR ptr) const;
841 virtual intptr_t get_con() const;
843 virtual const TypePtr *add_offset( intptr_t offset ) const;
845 virtual const Type *xmeet( const Type *t ) const;
846 virtual const Type *xdual() const; // Compute dual right now.
847 // Convenience common pre-built types.
848 static const TypeRawPtr *BOTTOM;
849 static const TypeRawPtr *NOTNULL;
850 #ifndef PRODUCT
851 virtual void dump2( Dict &d, uint depth, outputStream *st ) const;
852 #endif
853 };
855 //------------------------------TypeOopPtr-------------------------------------
856 // Some kind of oop (Java pointer), either klass or instance or array.
857 class TypeOopPtr : public TypePtr {
858 protected:
859 TypeOopPtr(TYPES t, PTR ptr, ciKlass* k, bool xk, ciObject* o, int offset, int instance_id, const TypeOopPtr* speculative, int inline_depth);
860 public:
861 virtual bool eq( const Type *t ) const;
862 virtual int hash() const; // Type specific hashing
863 virtual bool singleton(void) const; // TRUE if type is a singleton
864 enum {
865 InstanceTop = -1, // undefined instance
866 InstanceBot = 0 // any possible instance
867 };
868 protected:
870 enum {
871 InlineDepthBottom = INT_MAX,
872 InlineDepthTop = -InlineDepthBottom
873 };
874 // Oop is NULL, unless this is a constant oop.
875 ciObject* _const_oop; // Constant oop
876 // If _klass is NULL, then so is _sig. This is an unloaded klass.
877 ciKlass* _klass; // Klass object
878 // Does the type exclude subclasses of the klass? (Inexact == polymorphic.)
879 bool _klass_is_exact;
880 bool _is_ptr_to_narrowoop;
881 bool _is_ptr_to_narrowklass;
882 bool _is_ptr_to_boxed_value;
884 // If not InstanceTop or InstanceBot, indicates that this is
885 // a particular instance of this type which is distinct.
886 // This is the node index of the allocation node creating this instance.
887 int _instance_id;
889 // Extra type information profiling gave us. We propagate it the
890 // same way the rest of the type info is propagated. If we want to
891 // use it, then we have to emit a guard: this part of the type is
892 // not something we know but something we speculate about the type.
893 const TypeOopPtr* _speculative;
894 // For speculative types, we record at what inlining depth the
895 // profiling point that provided the data is. We want to favor
896 // profile data coming from outer scopes which are likely better for
897 // the current compilation.
898 int _inline_depth;
900 static const TypeOopPtr* make_from_klass_common(ciKlass* klass, bool klass_change, bool try_for_exact);
902 int dual_instance_id() const;
903 int meet_instance_id(int uid) const;
905 // utility methods to work on the speculative part of the type
906 const TypeOopPtr* dual_speculative() const;
907 const TypeOopPtr* xmeet_speculative(const TypeOopPtr* other) const;
908 bool eq_speculative(const TypeOopPtr* other) const;
909 int hash_speculative() const;
910 const TypeOopPtr* add_offset_speculative(intptr_t offset) const;
911 #ifndef PRODUCT
912 void dump_speculative(outputStream *st) const;
913 #endif
914 // utility methods to work on the inline depth of the type
915 int dual_inline_depth() const;
916 int meet_inline_depth(int depth) const;
917 #ifndef PRODUCT
918 void dump_inline_depth(outputStream *st) const;
919 #endif
921 // Do not allow interface-vs.-noninterface joins to collapse to top.
922 virtual const Type *filter_helper(const Type *kills, bool include_speculative) const;
924 public:
925 // Creates a type given a klass. Correctly handles multi-dimensional arrays
926 // Respects UseUniqueSubclasses.
927 // If the klass is final, the resulting type will be exact.
928 static const TypeOopPtr* make_from_klass(ciKlass* klass) {
929 return make_from_klass_common(klass, true, false);
930 }
931 // Same as before, but will produce an exact type, even if
932 // the klass is not final, as long as it has exactly one implementation.
933 static const TypeOopPtr* make_from_klass_unique(ciKlass* klass) {
934 return make_from_klass_common(klass, true, true);
935 }
936 // Same as before, but does not respects UseUniqueSubclasses.
937 // Use this only for creating array element types.
938 static const TypeOopPtr* make_from_klass_raw(ciKlass* klass) {
939 return make_from_klass_common(klass, false, false);
940 }
941 // Creates a singleton type given an object.
942 // If the object cannot be rendered as a constant,
943 // may return a non-singleton type.
944 // If require_constant, produce a NULL if a singleton is not possible.
945 static const TypeOopPtr* make_from_constant(ciObject* o,
946 bool require_constant = false,
947 bool not_null_elements = false);
949 // Make a generic (unclassed) pointer to an oop.
950 static const TypeOopPtr* make(PTR ptr, int offset, int instance_id, const TypeOopPtr* speculative = NULL, int inline_depth = InlineDepthBottom);
952 ciObject* const_oop() const { return _const_oop; }
953 virtual ciKlass* klass() const { return _klass; }
954 bool klass_is_exact() const { return _klass_is_exact; }
956 // Returns true if this pointer points at memory which contains a
957 // compressed oop references.
958 bool is_ptr_to_narrowoop_nv() const { return _is_ptr_to_narrowoop; }
959 bool is_ptr_to_narrowklass_nv() const { return _is_ptr_to_narrowklass; }
960 bool is_ptr_to_boxed_value() const { return _is_ptr_to_boxed_value; }
961 bool is_known_instance() const { return _instance_id > 0; }
962 int instance_id() const { return _instance_id; }
963 bool is_known_instance_field() const { return is_known_instance() && _offset >= 0; }
964 virtual const TypeOopPtr* speculative() const { return _speculative; }
966 virtual intptr_t get_con() const;
968 virtual const Type *cast_to_ptr_type(PTR ptr) const;
970 virtual const Type *cast_to_exactness(bool klass_is_exact) const;
972 virtual const TypeOopPtr *cast_to_instance_id(int instance_id) const;
974 // corresponding pointer to klass, for a given instance
975 const TypeKlassPtr* as_klass_type() const;
977 virtual const TypePtr *add_offset( intptr_t offset ) const;
978 // Return same type without a speculative part
979 virtual const Type* remove_speculative() const;
981 virtual const Type *xmeet(const Type *t) const;
982 virtual const Type *xdual() const; // Compute dual right now.
983 // the core of the computation of the meet for TypeOopPtr and for its subclasses
984 virtual const Type *xmeet_helper(const Type *t) const;
986 // Convenience common pre-built type.
987 static const TypeOopPtr *BOTTOM;
988 #ifndef PRODUCT
989 virtual void dump2( Dict &d, uint depth, outputStream *st ) const;
990 #endif
992 // Return the speculative type if any
993 ciKlass* speculative_type() const {
994 if (_speculative != NULL) {
995 const TypeOopPtr* speculative = _speculative->join(this)->is_oopptr();
996 if (speculative->klass_is_exact()) {
997 return speculative->klass();
998 }
999 }
1000 return NULL;
1001 }
1002 int inline_depth() const {
1003 return _inline_depth;
1004 }
1005 virtual const TypeOopPtr* with_inline_depth(int depth) const;
1006 virtual bool would_improve_type(ciKlass* exact_kls, int inline_depth) const;
1007 };
1009 //------------------------------TypeInstPtr------------------------------------
1010 // Class of Java object pointers, pointing either to non-array Java instances
1011 // or to a Klass* (including array klasses).
1012 class TypeInstPtr : public TypeOopPtr {
1013 TypeInstPtr(PTR ptr, ciKlass* k, bool xk, ciObject* o, int offset, int instance_id, const TypeOopPtr* speculative, int inline_depth);
1014 virtual bool eq( const Type *t ) const;
1015 virtual int hash() const; // Type specific hashing
1017 ciSymbol* _name; // class name
1019 public:
1020 ciSymbol* name() const { return _name; }
1022 bool is_loaded() const { return _klass->is_loaded(); }
1024 // Make a pointer to a constant oop.
1025 static const TypeInstPtr *make(ciObject* o) {
1026 return make(TypePtr::Constant, o->klass(), true, o, 0, InstanceBot);
1027 }
1028 // Make a pointer to a constant oop with offset.
1029 static const TypeInstPtr *make(ciObject* o, int offset) {
1030 return make(TypePtr::Constant, o->klass(), true, o, offset, InstanceBot);
1031 }
1033 // Make a pointer to some value of type klass.
1034 static const TypeInstPtr *make(PTR ptr, ciKlass* klass) {
1035 return make(ptr, klass, false, NULL, 0, InstanceBot);
1036 }
1038 // Make a pointer to some non-polymorphic value of exactly type klass.
1039 static const TypeInstPtr *make_exact(PTR ptr, ciKlass* klass) {
1040 return make(ptr, klass, true, NULL, 0, InstanceBot);
1041 }
1043 // Make a pointer to some value of type klass with offset.
1044 static const TypeInstPtr *make(PTR ptr, ciKlass* klass, int offset) {
1045 return make(ptr, klass, false, NULL, offset, InstanceBot);
1046 }
1048 // Make a pointer to an oop.
1049 static const TypeInstPtr *make(PTR ptr, ciKlass* k, bool xk, ciObject* o, int offset, int instance_id = InstanceBot, const TypeOopPtr* speculative = NULL, int inline_depth = InlineDepthBottom);
1051 /** Create constant type for a constant boxed value */
1052 const Type* get_const_boxed_value() const;
1054 // If this is a java.lang.Class constant, return the type for it or NULL.
1055 // Pass to Type::get_const_type to turn it to a type, which will usually
1056 // be a TypeInstPtr, but may also be a TypeInt::INT for int.class, etc.
1057 ciType* java_mirror_type() const;
1059 virtual const Type *cast_to_ptr_type(PTR ptr) const;
1061 virtual const Type *cast_to_exactness(bool klass_is_exact) const;
1063 virtual const TypeOopPtr *cast_to_instance_id(int instance_id) const;
1065 virtual const TypePtr *add_offset( intptr_t offset ) const;
1066 // Return same type without a speculative part
1067 virtual const Type* remove_speculative() const;
1068 virtual const TypeOopPtr* with_inline_depth(int depth) const;
1070 // the core of the computation of the meet of 2 types
1071 virtual const Type *xmeet_helper(const Type *t) const;
1072 virtual const TypeInstPtr *xmeet_unloaded( const TypeInstPtr *t ) const;
1073 virtual const Type *xdual() const; // Compute dual right now.
1075 // Convenience common pre-built types.
1076 static const TypeInstPtr *NOTNULL;
1077 static const TypeInstPtr *BOTTOM;
1078 static const TypeInstPtr *MIRROR;
1079 static const TypeInstPtr *MARK;
1080 static const TypeInstPtr *KLASS;
1081 #ifndef PRODUCT
1082 virtual void dump2( Dict &d, uint depth, outputStream *st ) const; // Specialized per-Type dumping
1083 #endif
1084 };
1086 //------------------------------TypeAryPtr-------------------------------------
1087 // Class of Java array pointers
1088 class TypeAryPtr : public TypeOopPtr {
1089 TypeAryPtr( PTR ptr, ciObject* o, const TypeAry *ary, ciKlass* k, bool xk,
1090 int offset, int instance_id, bool is_autobox_cache, const TypeOopPtr* speculative, int inline_depth)
1091 : TypeOopPtr(AryPtr,ptr,k,xk,o,offset, instance_id, speculative, inline_depth),
1092 _ary(ary),
1093 _is_autobox_cache(is_autobox_cache)
1094 {
1095 #ifdef ASSERT
1096 if (k != NULL) {
1097 // Verify that specified klass and TypeAryPtr::klass() follow the same rules.
1098 ciKlass* ck = compute_klass(true);
1099 if (k != ck) {
1100 this->dump(); tty->cr();
1101 tty->print(" k: ");
1102 k->print(); tty->cr();
1103 tty->print("ck: ");
1104 if (ck != NULL) ck->print();
1105 else tty->print("<NULL>");
1106 tty->cr();
1107 assert(false, "unexpected TypeAryPtr::_klass");
1108 }
1109 }
1110 #endif
1111 }
1112 virtual bool eq( const Type *t ) const;
1113 virtual int hash() const; // Type specific hashing
1114 const TypeAry *_ary; // Array we point into
1115 const bool _is_autobox_cache;
1117 ciKlass* compute_klass(DEBUG_ONLY(bool verify = false)) const;
1119 public:
1120 // Accessors
1121 ciKlass* klass() const;
1122 const TypeAry* ary() const { return _ary; }
1123 const Type* elem() const { return _ary->_elem; }
1124 const TypeInt* size() const { return _ary->_size; }
1125 bool is_stable() const { return _ary->_stable; }
1127 bool is_autobox_cache() const { return _is_autobox_cache; }
1129 static const TypeAryPtr *make( PTR ptr, const TypeAry *ary, ciKlass* k, bool xk, int offset, int instance_id = InstanceBot, const TypeOopPtr* speculative = NULL, int inline_depth = InlineDepthBottom);
1130 // Constant pointer to array
1131 static const TypeAryPtr *make( PTR ptr, ciObject* o, const TypeAry *ary, ciKlass* k, bool xk, int offset, int instance_id = InstanceBot, const TypeOopPtr* speculative = NULL, int inline_depth = InlineDepthBottom, bool is_autobox_cache= false);
1133 // Return a 'ptr' version of this type
1134 virtual const Type *cast_to_ptr_type(PTR ptr) const;
1136 virtual const Type *cast_to_exactness(bool klass_is_exact) const;
1138 virtual const TypeOopPtr *cast_to_instance_id(int instance_id) const;
1140 virtual const TypeAryPtr* cast_to_size(const TypeInt* size) const;
1141 virtual const TypeInt* narrow_size_type(const TypeInt* size) const;
1143 virtual bool empty(void) const; // TRUE if type is vacuous
1144 virtual const TypePtr *add_offset( intptr_t offset ) const;
1145 // Return same type without a speculative part
1146 virtual const Type* remove_speculative() const;
1147 virtual const TypeOopPtr* with_inline_depth(int depth) const;
1149 // the core of the computation of the meet of 2 types
1150 virtual const Type *xmeet_helper(const Type *t) const;
1151 virtual const Type *xdual() const; // Compute dual right now.
1153 const TypeAryPtr* cast_to_stable(bool stable, int stable_dimension = 1) const;
1154 int stable_dimension() const;
1156 static jint max_array_length(BasicType etype) ;
1158 // Convenience common pre-built types.
1159 static const TypeAryPtr *RANGE;
1160 static const TypeAryPtr *OOPS;
1161 static const TypeAryPtr *NARROWOOPS;
1162 static const TypeAryPtr *BYTES;
1163 static const TypeAryPtr *SHORTS;
1164 static const TypeAryPtr *CHARS;
1165 static const TypeAryPtr *INTS;
1166 static const TypeAryPtr *LONGS;
1167 static const TypeAryPtr *FLOATS;
1168 static const TypeAryPtr *DOUBLES;
1169 // selects one of the above:
1170 static const TypeAryPtr *get_array_body_type(BasicType elem) {
1171 assert((uint)elem <= T_CONFLICT && _array_body_type[elem] != NULL, "bad elem type");
1172 return _array_body_type[elem];
1173 }
1174 static const TypeAryPtr *_array_body_type[T_CONFLICT+1];
1175 // sharpen the type of an int which is used as an array size
1176 #ifdef ASSERT
1177 // One type is interface, the other is oop
1178 virtual bool interface_vs_oop(const Type *t) const;
1179 #endif
1180 #ifndef PRODUCT
1181 virtual void dump2( Dict &d, uint depth, outputStream *st ) const; // Specialized per-Type dumping
1182 #endif
1183 };
1185 //------------------------------TypeMetadataPtr-------------------------------------
1186 // Some kind of metadata, either Method*, MethodData* or CPCacheOop
1187 class TypeMetadataPtr : public TypePtr {
1188 protected:
1189 TypeMetadataPtr(PTR ptr, ciMetadata* metadata, int offset);
1190 // Do not allow interface-vs.-noninterface joins to collapse to top.
1191 virtual const Type *filter_helper(const Type *kills, bool include_speculative) const;
1192 public:
1193 virtual bool eq( const Type *t ) const;
1194 virtual int hash() const; // Type specific hashing
1195 virtual bool singleton(void) const; // TRUE if type is a singleton
1197 private:
1198 ciMetadata* _metadata;
1200 public:
1201 static const TypeMetadataPtr* make(PTR ptr, ciMetadata* m, int offset);
1203 static const TypeMetadataPtr* make(ciMethod* m);
1204 static const TypeMetadataPtr* make(ciMethodData* m);
1206 ciMetadata* metadata() const { return _metadata; }
1208 virtual const Type *cast_to_ptr_type(PTR ptr) const;
1210 virtual const TypePtr *add_offset( intptr_t offset ) const;
1212 virtual const Type *xmeet( const Type *t ) const;
1213 virtual const Type *xdual() const; // Compute dual right now.
1215 virtual intptr_t get_con() const;
1217 // Convenience common pre-built types.
1218 static const TypeMetadataPtr *BOTTOM;
1220 #ifndef PRODUCT
1221 virtual void dump2( Dict &d, uint depth, outputStream *st ) const;
1222 #endif
1223 };
1225 //------------------------------TypeKlassPtr-----------------------------------
1226 // Class of Java Klass pointers
1227 class TypeKlassPtr : public TypePtr {
1228 TypeKlassPtr( PTR ptr, ciKlass* klass, int offset );
1230 protected:
1231 virtual const Type *filter_helper(const Type *kills, bool include_speculative) const;
1232 public:
1233 virtual bool eq( const Type *t ) const;
1234 virtual int hash() const; // Type specific hashing
1235 virtual bool singleton(void) const; // TRUE if type is a singleton
1236 private:
1238 static const TypeKlassPtr* make_from_klass_common(ciKlass* klass, bool klass_change, bool try_for_exact);
1240 ciKlass* _klass;
1242 // Does the type exclude subclasses of the klass? (Inexact == polymorphic.)
1243 bool _klass_is_exact;
1245 public:
1246 ciSymbol* name() const { return klass()->name(); }
1248 ciKlass* klass() const { return _klass; }
1249 bool klass_is_exact() const { return _klass_is_exact; }
1251 bool is_loaded() const { return klass()->is_loaded(); }
1253 // Creates a type given a klass. Correctly handles multi-dimensional arrays
1254 // Respects UseUniqueSubclasses.
1255 // If the klass is final, the resulting type will be exact.
1256 static const TypeKlassPtr* make_from_klass(ciKlass* klass) {
1257 return make_from_klass_common(klass, true, false);
1258 }
1259 // Same as before, but will produce an exact type, even if
1260 // the klass is not final, as long as it has exactly one implementation.
1261 static const TypeKlassPtr* make_from_klass_unique(ciKlass* klass) {
1262 return make_from_klass_common(klass, true, true);
1263 }
1264 // Same as before, but does not respects UseUniqueSubclasses.
1265 // Use this only for creating array element types.
1266 static const TypeKlassPtr* make_from_klass_raw(ciKlass* klass) {
1267 return make_from_klass_common(klass, false, false);
1268 }
1270 // Make a generic (unclassed) pointer to metadata.
1271 static const TypeKlassPtr* make(PTR ptr, int offset);
1273 // ptr to klass 'k'
1274 static const TypeKlassPtr *make( ciKlass* k ) { return make( TypePtr::Constant, k, 0); }
1275 // ptr to klass 'k' with offset
1276 static const TypeKlassPtr *make( ciKlass* k, int offset ) { return make( TypePtr::Constant, k, offset); }
1277 // ptr to klass 'k' or sub-klass
1278 static const TypeKlassPtr *make( PTR ptr, ciKlass* k, int offset);
1280 virtual const Type *cast_to_ptr_type(PTR ptr) const;
1282 virtual const Type *cast_to_exactness(bool klass_is_exact) const;
1284 // corresponding pointer to instance, for a given class
1285 const TypeOopPtr* as_instance_type() const;
1287 virtual const TypePtr *add_offset( intptr_t offset ) const;
1288 virtual const Type *xmeet( const Type *t ) const;
1289 virtual const Type *xdual() const; // Compute dual right now.
1291 virtual intptr_t get_con() const;
1293 // Convenience common pre-built types.
1294 static const TypeKlassPtr* OBJECT; // Not-null object klass or below
1295 static const TypeKlassPtr* OBJECT_OR_NULL; // Maybe-null version of same
1296 #ifndef PRODUCT
1297 virtual void dump2( Dict &d, uint depth, outputStream *st ) const; // Specialized per-Type dumping
1298 #endif
1299 };
1301 class TypeNarrowPtr : public Type {
1302 protected:
1303 const TypePtr* _ptrtype; // Could be TypePtr::NULL_PTR
1305 TypeNarrowPtr(TYPES t, const TypePtr* ptrtype): _ptrtype(ptrtype),
1306 Type(t) {
1307 assert(ptrtype->offset() == 0 ||
1308 ptrtype->offset() == OffsetBot ||
1309 ptrtype->offset() == OffsetTop, "no real offsets");
1310 }
1312 virtual const TypeNarrowPtr *isa_same_narrowptr(const Type *t) const = 0;
1313 virtual const TypeNarrowPtr *is_same_narrowptr(const Type *t) const = 0;
1314 virtual const TypeNarrowPtr *make_same_narrowptr(const TypePtr *t) const = 0;
1315 virtual const TypeNarrowPtr *make_hash_same_narrowptr(const TypePtr *t) const = 0;
1316 // Do not allow interface-vs.-noninterface joins to collapse to top.
1317 virtual const Type *filter_helper(const Type *kills, bool include_speculative) const;
1318 public:
1319 virtual bool eq( const Type *t ) const;
1320 virtual int hash() const; // Type specific hashing
1321 virtual bool singleton(void) const; // TRUE if type is a singleton
1323 virtual const Type *xmeet( const Type *t ) const;
1324 virtual const Type *xdual() const; // Compute dual right now.
1326 virtual intptr_t get_con() const;
1328 virtual bool empty(void) const; // TRUE if type is vacuous
1330 // returns the equivalent ptr type for this compressed pointer
1331 const TypePtr *get_ptrtype() const {
1332 return _ptrtype;
1333 }
1335 #ifndef PRODUCT
1336 virtual void dump2( Dict &d, uint depth, outputStream *st ) const;
1337 #endif
1338 };
1340 //------------------------------TypeNarrowOop----------------------------------
1341 // A compressed reference to some kind of Oop. This type wraps around
1342 // a preexisting TypeOopPtr and forwards most of it's operations to
1343 // the underlying type. It's only real purpose is to track the
1344 // oopness of the compressed oop value when we expose the conversion
1345 // between the normal and the compressed form.
1346 class TypeNarrowOop : public TypeNarrowPtr {
1347 protected:
1348 TypeNarrowOop( const TypePtr* ptrtype): TypeNarrowPtr(NarrowOop, ptrtype) {
1349 }
1351 virtual const TypeNarrowPtr *isa_same_narrowptr(const Type *t) const {
1352 return t->isa_narrowoop();
1353 }
1355 virtual const TypeNarrowPtr *is_same_narrowptr(const Type *t) const {
1356 return t->is_narrowoop();
1357 }
1359 virtual const TypeNarrowPtr *make_same_narrowptr(const TypePtr *t) const {
1360 return new TypeNarrowOop(t);
1361 }
1363 virtual const TypeNarrowPtr *make_hash_same_narrowptr(const TypePtr *t) const {
1364 return (const TypeNarrowPtr*)((new TypeNarrowOop(t))->hashcons());
1365 }
1367 public:
1369 static const TypeNarrowOop *make( const TypePtr* type);
1371 static const TypeNarrowOop* make_from_constant(ciObject* con, bool require_constant = false) {
1372 return make(TypeOopPtr::make_from_constant(con, require_constant));
1373 }
1375 static const TypeNarrowOop *BOTTOM;
1376 static const TypeNarrowOop *NULL_PTR;
1378 virtual const Type* remove_speculative() const {
1379 return make(_ptrtype->remove_speculative()->is_ptr());
1380 }
1382 #ifndef PRODUCT
1383 virtual void dump2( Dict &d, uint depth, outputStream *st ) const;
1384 #endif
1385 };
1387 //------------------------------TypeNarrowKlass----------------------------------
1388 // A compressed reference to klass pointer. This type wraps around a
1389 // preexisting TypeKlassPtr and forwards most of it's operations to
1390 // the underlying type.
1391 class TypeNarrowKlass : public TypeNarrowPtr {
1392 protected:
1393 TypeNarrowKlass( const TypePtr* ptrtype): TypeNarrowPtr(NarrowKlass, ptrtype) {
1394 }
1396 virtual const TypeNarrowPtr *isa_same_narrowptr(const Type *t) const {
1397 return t->isa_narrowklass();
1398 }
1400 virtual const TypeNarrowPtr *is_same_narrowptr(const Type *t) const {
1401 return t->is_narrowklass();
1402 }
1404 virtual const TypeNarrowPtr *make_same_narrowptr(const TypePtr *t) const {
1405 return new TypeNarrowKlass(t);
1406 }
1408 virtual const TypeNarrowPtr *make_hash_same_narrowptr(const TypePtr *t) const {
1409 return (const TypeNarrowPtr*)((new TypeNarrowKlass(t))->hashcons());
1410 }
1412 public:
1413 static const TypeNarrowKlass *make( const TypePtr* type);
1415 // static const TypeNarrowKlass *BOTTOM;
1416 static const TypeNarrowKlass *NULL_PTR;
1418 #ifndef PRODUCT
1419 virtual void dump2( Dict &d, uint depth, outputStream *st ) const;
1420 #endif
1421 };
1423 //------------------------------TypeFunc---------------------------------------
1424 // Class of Array Types
1425 class TypeFunc : public Type {
1426 TypeFunc( const TypeTuple *domain, const TypeTuple *range ) : Type(Function), _domain(domain), _range(range) {}
1427 virtual bool eq( const Type *t ) const;
1428 virtual int hash() const; // Type specific hashing
1429 virtual bool singleton(void) const; // TRUE if type is a singleton
1430 virtual bool empty(void) const; // TRUE if type is vacuous
1431 public:
1432 // Constants are shared among ADLC and VM
1433 enum { Control = AdlcVMDeps::Control,
1434 I_O = AdlcVMDeps::I_O,
1435 Memory = AdlcVMDeps::Memory,
1436 FramePtr = AdlcVMDeps::FramePtr,
1437 ReturnAdr = AdlcVMDeps::ReturnAdr,
1438 Parms = AdlcVMDeps::Parms
1439 };
1441 const TypeTuple* const _domain; // Domain of inputs
1442 const TypeTuple* const _range; // Range of results
1444 // Accessors:
1445 const TypeTuple* domain() const { return _domain; }
1446 const TypeTuple* range() const { return _range; }
1448 static const TypeFunc *make(ciMethod* method);
1449 static const TypeFunc *make(ciSignature signature, const Type* extra);
1450 static const TypeFunc *make(const TypeTuple* domain, const TypeTuple* range);
1452 virtual const Type *xmeet( const Type *t ) const;
1453 virtual const Type *xdual() const; // Compute dual right now.
1455 BasicType return_type() const;
1457 #ifndef PRODUCT
1458 virtual void dump2( Dict &d, uint depth, outputStream *st ) const; // Specialized per-Type dumping
1459 #endif
1460 // Convenience common pre-built types.
1461 };
1463 //------------------------------accessors--------------------------------------
1464 inline bool Type::is_ptr_to_narrowoop() const {
1465 #ifdef _LP64
1466 return (isa_oopptr() != NULL && is_oopptr()->is_ptr_to_narrowoop_nv());
1467 #else
1468 return false;
1469 #endif
1470 }
1472 inline bool Type::is_ptr_to_narrowklass() const {
1473 #ifdef _LP64
1474 return (isa_oopptr() != NULL && is_oopptr()->is_ptr_to_narrowklass_nv());
1475 #else
1476 return false;
1477 #endif
1478 }
1480 inline float Type::getf() const {
1481 assert( _base == FloatCon, "Not a FloatCon" );
1482 return ((TypeF*)this)->_f;
1483 }
1485 inline double Type::getd() const {
1486 assert( _base == DoubleCon, "Not a DoubleCon" );
1487 return ((TypeD*)this)->_d;
1488 }
1490 inline const TypeInt *Type::is_int() const {
1491 assert( _base == Int, "Not an Int" );
1492 return (TypeInt*)this;
1493 }
1495 inline const TypeInt *Type::isa_int() const {
1496 return ( _base == Int ? (TypeInt*)this : NULL);
1497 }
1499 inline const TypeLong *Type::is_long() const {
1500 assert( _base == Long, "Not a Long" );
1501 return (TypeLong*)this;
1502 }
1504 inline const TypeLong *Type::isa_long() const {
1505 return ( _base == Long ? (TypeLong*)this : NULL);
1506 }
1508 inline const TypeF *Type::isa_float() const {
1509 return ((_base == FloatTop ||
1510 _base == FloatCon ||
1511 _base == FloatBot) ? (TypeF*)this : NULL);
1512 }
1514 inline const TypeF *Type::is_float_constant() const {
1515 assert( _base == FloatCon, "Not a Float" );
1516 return (TypeF*)this;
1517 }
1519 inline const TypeF *Type::isa_float_constant() const {
1520 return ( _base == FloatCon ? (TypeF*)this : NULL);
1521 }
1523 inline const TypeD *Type::isa_double() const {
1524 return ((_base == DoubleTop ||
1525 _base == DoubleCon ||
1526 _base == DoubleBot) ? (TypeD*)this : NULL);
1527 }
1529 inline const TypeD *Type::is_double_constant() const {
1530 assert( _base == DoubleCon, "Not a Double" );
1531 return (TypeD*)this;
1532 }
1534 inline const TypeD *Type::isa_double_constant() const {
1535 return ( _base == DoubleCon ? (TypeD*)this : NULL);
1536 }
1538 inline const TypeTuple *Type::is_tuple() const {
1539 assert( _base == Tuple, "Not a Tuple" );
1540 return (TypeTuple*)this;
1541 }
1543 inline const TypeAry *Type::is_ary() const {
1544 assert( _base == Array , "Not an Array" );
1545 return (TypeAry*)this;
1546 }
1548 inline const TypeVect *Type::is_vect() const {
1549 assert( _base >= VectorS && _base <= VectorY, "Not a Vector" );
1550 return (TypeVect*)this;
1551 }
1553 inline const TypeVect *Type::isa_vect() const {
1554 return (_base >= VectorS && _base <= VectorY) ? (TypeVect*)this : NULL;
1555 }
1557 inline const TypePtr *Type::is_ptr() const {
1558 // AnyPtr is the first Ptr and KlassPtr the last, with no non-ptrs between.
1559 assert(_base >= AnyPtr && _base <= KlassPtr, "Not a pointer");
1560 return (TypePtr*)this;
1561 }
1563 inline const TypePtr *Type::isa_ptr() const {
1564 // AnyPtr is the first Ptr and KlassPtr the last, with no non-ptrs between.
1565 return (_base >= AnyPtr && _base <= KlassPtr) ? (TypePtr*)this : NULL;
1566 }
1568 inline const TypeOopPtr *Type::is_oopptr() const {
1569 // OopPtr is the first and KlassPtr the last, with no non-oops between.
1570 assert(_base >= OopPtr && _base <= AryPtr, "Not a Java pointer" ) ;
1571 return (TypeOopPtr*)this;
1572 }
1574 inline const TypeOopPtr *Type::isa_oopptr() const {
1575 // OopPtr is the first and KlassPtr the last, with no non-oops between.
1576 return (_base >= OopPtr && _base <= AryPtr) ? (TypeOopPtr*)this : NULL;
1577 }
1579 inline const TypeRawPtr *Type::isa_rawptr() const {
1580 return (_base == RawPtr) ? (TypeRawPtr*)this : NULL;
1581 }
1583 inline const TypeRawPtr *Type::is_rawptr() const {
1584 assert( _base == RawPtr, "Not a raw pointer" );
1585 return (TypeRawPtr*)this;
1586 }
1588 inline const TypeInstPtr *Type::isa_instptr() const {
1589 return (_base == InstPtr) ? (TypeInstPtr*)this : NULL;
1590 }
1592 inline const TypeInstPtr *Type::is_instptr() const {
1593 assert( _base == InstPtr, "Not an object pointer" );
1594 return (TypeInstPtr*)this;
1595 }
1597 inline const TypeAryPtr *Type::isa_aryptr() const {
1598 return (_base == AryPtr) ? (TypeAryPtr*)this : NULL;
1599 }
1601 inline const TypeAryPtr *Type::is_aryptr() const {
1602 assert( _base == AryPtr, "Not an array pointer" );
1603 return (TypeAryPtr*)this;
1604 }
1606 inline const TypeNarrowOop *Type::is_narrowoop() const {
1607 // OopPtr is the first and KlassPtr the last, with no non-oops between.
1608 assert(_base == NarrowOop, "Not a narrow oop" ) ;
1609 return (TypeNarrowOop*)this;
1610 }
1612 inline const TypeNarrowOop *Type::isa_narrowoop() const {
1613 // OopPtr is the first and KlassPtr the last, with no non-oops between.
1614 return (_base == NarrowOop) ? (TypeNarrowOop*)this : NULL;
1615 }
1617 inline const TypeNarrowKlass *Type::is_narrowklass() const {
1618 assert(_base == NarrowKlass, "Not a narrow oop" ) ;
1619 return (TypeNarrowKlass*)this;
1620 }
1622 inline const TypeNarrowKlass *Type::isa_narrowklass() const {
1623 return (_base == NarrowKlass) ? (TypeNarrowKlass*)this : NULL;
1624 }
1626 inline const TypeMetadataPtr *Type::is_metadataptr() const {
1627 // MetadataPtr is the first and CPCachePtr the last
1628 assert(_base == MetadataPtr, "Not a metadata pointer" ) ;
1629 return (TypeMetadataPtr*)this;
1630 }
1632 inline const TypeMetadataPtr *Type::isa_metadataptr() const {
1633 return (_base == MetadataPtr) ? (TypeMetadataPtr*)this : NULL;
1634 }
1636 inline const TypeKlassPtr *Type::isa_klassptr() const {
1637 return (_base == KlassPtr) ? (TypeKlassPtr*)this : NULL;
1638 }
1640 inline const TypeKlassPtr *Type::is_klassptr() const {
1641 assert( _base == KlassPtr, "Not a klass pointer" );
1642 return (TypeKlassPtr*)this;
1643 }
1645 inline const TypePtr* Type::make_ptr() const {
1646 return (_base == NarrowOop) ? is_narrowoop()->get_ptrtype() :
1647 ((_base == NarrowKlass) ? is_narrowklass()->get_ptrtype() :
1648 (isa_ptr() ? is_ptr() : NULL));
1649 }
1651 inline const TypeOopPtr* Type::make_oopptr() const {
1652 return (_base == NarrowOop) ? is_narrowoop()->get_ptrtype()->is_oopptr() : is_oopptr();
1653 }
1655 inline const TypeNarrowOop* Type::make_narrowoop() const {
1656 return (_base == NarrowOop) ? is_narrowoop() :
1657 (isa_ptr() ? TypeNarrowOop::make(is_ptr()) : NULL);
1658 }
1660 inline const TypeNarrowKlass* Type::make_narrowklass() const {
1661 return (_base == NarrowKlass) ? is_narrowklass() :
1662 (isa_ptr() ? TypeNarrowKlass::make(is_ptr()) : NULL);
1663 }
1665 inline bool Type::is_floatingpoint() const {
1666 if( (_base == FloatCon) || (_base == FloatBot) ||
1667 (_base == DoubleCon) || (_base == DoubleBot) )
1668 return true;
1669 return false;
1670 }
1672 inline bool Type::is_ptr_to_boxing_obj() const {
1673 const TypeInstPtr* tp = isa_instptr();
1674 return (tp != NULL) && (tp->offset() == 0) &&
1675 tp->klass()->is_instance_klass() &&
1676 tp->klass()->as_instance_klass()->is_box_klass();
1677 }
1680 // ===============================================================
1681 // Things that need to be 64-bits in the 64-bit build but
1682 // 32-bits in the 32-bit build. Done this way to get full
1683 // optimization AND strong typing.
1684 #ifdef _LP64
1686 // For type queries and asserts
1687 #define is_intptr_t is_long
1688 #define isa_intptr_t isa_long
1689 #define find_intptr_t_type find_long_type
1690 #define find_intptr_t_con find_long_con
1691 #define TypeX TypeLong
1692 #define Type_X Type::Long
1693 #define TypeX_X TypeLong::LONG
1694 #define TypeX_ZERO TypeLong::ZERO
1695 // For 'ideal_reg' machine registers
1696 #define Op_RegX Op_RegL
1697 // For phase->intcon variants
1698 #define MakeConX longcon
1699 #define ConXNode ConLNode
1700 // For array index arithmetic
1701 #define MulXNode MulLNode
1702 #define AndXNode AndLNode
1703 #define OrXNode OrLNode
1704 #define CmpXNode CmpLNode
1705 #define SubXNode SubLNode
1706 #define LShiftXNode LShiftLNode
1707 // For object size computation:
1708 #define AddXNode AddLNode
1709 #define RShiftXNode RShiftLNode
1710 // For card marks and hashcodes
1711 #define URShiftXNode URShiftLNode
1712 // UseOptoBiasInlining
1713 #define XorXNode XorLNode
1714 #define StoreXConditionalNode StoreLConditionalNode
1715 // Opcodes
1716 #define Op_LShiftX Op_LShiftL
1717 #define Op_AndX Op_AndL
1718 #define Op_AddX Op_AddL
1719 #define Op_SubX Op_SubL
1720 #define Op_XorX Op_XorL
1721 #define Op_URShiftX Op_URShiftL
1722 // conversions
1723 #define ConvI2X(x) ConvI2L(x)
1724 #define ConvL2X(x) (x)
1725 #define ConvX2I(x) ConvL2I(x)
1726 #define ConvX2L(x) (x)
1727 #define ConvX2UL(x) (x)
1729 #else
1731 // For type queries and asserts
1732 #define is_intptr_t is_int
1733 #define isa_intptr_t isa_int
1734 #define find_intptr_t_type find_int_type
1735 #define find_intptr_t_con find_int_con
1736 #define TypeX TypeInt
1737 #define Type_X Type::Int
1738 #define TypeX_X TypeInt::INT
1739 #define TypeX_ZERO TypeInt::ZERO
1740 // For 'ideal_reg' machine registers
1741 #define Op_RegX Op_RegI
1742 // For phase->intcon variants
1743 #define MakeConX intcon
1744 #define ConXNode ConINode
1745 // For array index arithmetic
1746 #define MulXNode MulINode
1747 #define AndXNode AndINode
1748 #define OrXNode OrINode
1749 #define CmpXNode CmpINode
1750 #define SubXNode SubINode
1751 #define LShiftXNode LShiftINode
1752 // For object size computation:
1753 #define AddXNode AddINode
1754 #define RShiftXNode RShiftINode
1755 // For card marks and hashcodes
1756 #define URShiftXNode URShiftINode
1757 // UseOptoBiasInlining
1758 #define XorXNode XorINode
1759 #define StoreXConditionalNode StoreIConditionalNode
1760 // Opcodes
1761 #define Op_LShiftX Op_LShiftI
1762 #define Op_AndX Op_AndI
1763 #define Op_AddX Op_AddI
1764 #define Op_SubX Op_SubI
1765 #define Op_XorX Op_XorI
1766 #define Op_URShiftX Op_URShiftI
1767 // conversions
1768 #define ConvI2X(x) (x)
1769 #define ConvL2X(x) ConvL2I(x)
1770 #define ConvX2I(x) (x)
1771 #define ConvX2L(x) ConvI2L(x)
1772 #define ConvX2UL(x) ConvI2UL(x)
1774 #endif
1776 #endif // SHARE_VM_OPTO_TYPE_HPP