Fri, 28 Oct 2016 22:36:23 +0000
8038348: Instance field load is replaced by wrong data Phi
Summary: Store additional information in PhiNodes corresponding to known instance field values to avoid incorrect reusage.
Reviewed-by: kvn, thartmann
1 /*
2 * Copyright (c) 1997, 2013, 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 const TYPES dual_type;
134 const BasicType basic_type;
135 const char* msg;
136 const bool isa_oop;
137 const int ideal_reg;
138 const relocInfo::relocType reloc;
139 } TypeInfo;
141 // Dictionary of types shared among compilations.
142 static Dict* _shared_type_dict;
143 static 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 int 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 int 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();
361 #endif
362 void typerr(const Type *t) const; // Mixing types error
364 // Create basic type
365 static const Type* get_const_basic_type(BasicType type) {
366 assert((uint)type <= T_CONFLICT && _const_basic_type[type] != NULL, "bad type");
367 return _const_basic_type[type];
368 }
370 // For two instance arrays of same dimension, return the base element types.
371 // Otherwise or if the arrays have different dimensions, return NULL.
372 static void get_arrays_base_elements(const Type *a1, const Type *a2,
373 const TypeInstPtr **e1, const TypeInstPtr **e2);
375 // Mapping to the array element's basic type.
376 BasicType array_element_basic_type() const;
378 // Create standard type for a ciType:
379 static const Type* get_const_type(ciType* type);
381 // Create standard zero value:
382 static const Type* get_zero_type(BasicType type) {
383 assert((uint)type <= T_CONFLICT && _zero_type[type] != NULL, "bad type");
384 return _zero_type[type];
385 }
387 // Report if this is a zero value (not top).
388 bool is_zero_type() const {
389 BasicType type = basic_type();
390 if (type == T_VOID || type >= T_CONFLICT)
391 return false;
392 else
393 return (this == _zero_type[type]);
394 }
396 // Convenience common pre-built types.
397 static const Type *ABIO;
398 static const Type *BOTTOM;
399 static const Type *CONTROL;
400 static const Type *DOUBLE;
401 static const Type *FLOAT;
402 static const Type *HALF;
403 static const Type *MEMORY;
404 static const Type *MULTI;
405 static const Type *RETURN_ADDRESS;
406 static const Type *TOP;
408 // Mapping from compiler type to VM BasicType
409 BasicType basic_type() const { return _type_info[_base].basic_type; }
410 int ideal_reg() const { return _type_info[_base].ideal_reg; }
411 const char* msg() const { return _type_info[_base].msg; }
412 bool isa_oop_ptr() const { return _type_info[_base].isa_oop; }
413 relocInfo::relocType reloc() const { return _type_info[_base].reloc; }
415 // Mapping from CI type system to compiler type:
416 static const Type* get_typeflow_type(ciType* type);
418 static const Type* make_from_constant(ciConstant constant,
419 bool require_constant = false,
420 bool is_autobox_cache = false);
422 // Speculative type. See TypeInstPtr
423 virtual const TypeOopPtr* speculative() const { return NULL; }
424 virtual ciKlass* speculative_type() const { return NULL; }
425 const Type* maybe_remove_speculative(bool include_speculative) const;
426 virtual const Type* remove_speculative() const { return this; }
428 virtual bool would_improve_type(ciKlass* exact_kls, int inline_depth) const {
429 return exact_kls != NULL;
430 }
432 private:
433 // support arrays
434 static const BasicType _basic_type[];
435 static const Type* _zero_type[T_CONFLICT+1];
436 static const Type* _const_basic_type[T_CONFLICT+1];
437 };
439 //------------------------------TypeF------------------------------------------
440 // Class of Float-Constant Types.
441 class TypeF : public Type {
442 TypeF( float f ) : Type(FloatCon), _f(f) {};
443 public:
444 virtual bool eq( const Type *t ) const;
445 virtual int hash() const; // Type specific hashing
446 virtual bool singleton(void) const; // TRUE if type is a singleton
447 virtual bool empty(void) const; // TRUE if type is vacuous
448 public:
449 const float _f; // Float constant
451 static const TypeF *make(float f);
453 virtual bool is_finite() const; // Has a finite value
454 virtual bool is_nan() const; // Is not a number (NaN)
456 virtual const Type *xmeet( const Type *t ) const;
457 virtual const Type *xdual() const; // Compute dual right now.
458 // Convenience common pre-built types.
459 static const TypeF *ZERO; // positive zero only
460 static const TypeF *ONE;
461 #ifndef PRODUCT
462 virtual void dump2( Dict &d, uint depth, outputStream *st ) const;
463 #endif
464 };
466 //------------------------------TypeD------------------------------------------
467 // Class of Double-Constant Types.
468 class TypeD : public Type {
469 TypeD( double d ) : Type(DoubleCon), _d(d) {};
470 public:
471 virtual bool eq( const Type *t ) const;
472 virtual int hash() const; // Type specific hashing
473 virtual bool singleton(void) const; // TRUE if type is a singleton
474 virtual bool empty(void) const; // TRUE if type is vacuous
475 public:
476 const double _d; // Double constant
478 static const TypeD *make(double d);
480 virtual bool is_finite() const; // Has a finite value
481 virtual bool is_nan() const; // Is not a number (NaN)
483 virtual const Type *xmeet( const Type *t ) const;
484 virtual const Type *xdual() const; // Compute dual right now.
485 // Convenience common pre-built types.
486 static const TypeD *ZERO; // positive zero only
487 static const TypeD *ONE;
488 #ifndef PRODUCT
489 virtual void dump2( Dict &d, uint depth, outputStream *st ) const;
490 #endif
491 };
493 //------------------------------TypeInt----------------------------------------
494 // Class of integer ranges, the set of integers between a lower bound and an
495 // upper bound, inclusive.
496 class TypeInt : public Type {
497 TypeInt( jint lo, jint hi, int w );
498 protected:
499 virtual const Type *filter_helper(const Type *kills, bool include_speculative) const;
501 public:
502 typedef jint NativeType;
503 virtual bool eq( const Type *t ) const;
504 virtual int hash() const; // Type specific hashing
505 virtual bool singleton(void) const; // TRUE if type is a singleton
506 virtual bool empty(void) const; // TRUE if type is vacuous
507 const jint _lo, _hi; // Lower bound, upper bound
508 const short _widen; // Limit on times we widen this sucker
510 static const TypeInt *make(jint lo);
511 // must always specify w
512 static const TypeInt *make(jint lo, jint hi, int w);
514 // Check for single integer
515 int is_con() const { return _lo==_hi; }
516 bool is_con(int i) const { return is_con() && _lo == i; }
517 jint get_con() const { assert( is_con(), "" ); return _lo; }
519 virtual bool is_finite() const; // Has a finite value
521 virtual const Type *xmeet( const Type *t ) const;
522 virtual const Type *xdual() const; // Compute dual right now.
523 virtual const Type *widen( const Type *t, const Type* limit_type ) const;
524 virtual const Type *narrow( const Type *t ) const;
525 // Do not kill _widen bits.
526 // Convenience common pre-built types.
527 static const TypeInt *MINUS_1;
528 static const TypeInt *ZERO;
529 static const TypeInt *ONE;
530 static const TypeInt *BOOL;
531 static const TypeInt *CC;
532 static const TypeInt *CC_LT; // [-1] == MINUS_1
533 static const TypeInt *CC_GT; // [1] == ONE
534 static const TypeInt *CC_EQ; // [0] == ZERO
535 static const TypeInt *CC_LE; // [-1,0]
536 static const TypeInt *CC_GE; // [0,1] == BOOL (!)
537 static const TypeInt *BYTE;
538 static const TypeInt *UBYTE;
539 static const TypeInt *CHAR;
540 static const TypeInt *SHORT;
541 static const TypeInt *POS;
542 static const TypeInt *POS1;
543 static const TypeInt *INT;
544 static const TypeInt *SYMINT; // symmetric range [-max_jint..max_jint]
545 static const TypeInt *TYPE_DOMAIN; // alias for TypeInt::INT
547 static const TypeInt *as_self(const Type *t) { return t->is_int(); }
548 #ifndef PRODUCT
549 virtual void dump2( Dict &d, uint depth, outputStream *st ) const;
550 #endif
551 };
554 //------------------------------TypeLong---------------------------------------
555 // Class of long integer ranges, the set of integers between a lower bound and
556 // an upper bound, inclusive.
557 class TypeLong : public Type {
558 TypeLong( jlong lo, jlong hi, int w );
559 protected:
560 // Do not kill _widen bits.
561 virtual const Type *filter_helper(const Type *kills, bool include_speculative) const;
562 public:
563 typedef jlong NativeType;
564 virtual bool eq( const Type *t ) const;
565 virtual int hash() const; // Type specific hashing
566 virtual bool singleton(void) const; // TRUE if type is a singleton
567 virtual bool empty(void) const; // TRUE if type is vacuous
568 public:
569 const jlong _lo, _hi; // Lower bound, upper bound
570 const short _widen; // Limit on times we widen this sucker
572 static const TypeLong *make(jlong lo);
573 // must always specify w
574 static const TypeLong *make(jlong lo, jlong hi, int w);
576 // Check for single integer
577 int is_con() const { return _lo==_hi; }
578 bool is_con(int i) const { return is_con() && _lo == i; }
579 jlong get_con() const { assert( is_con(), "" ); return _lo; }
581 // Check for positive 32-bit value.
582 int is_positive_int() const { return _lo >= 0 && _hi <= (jlong)max_jint; }
584 virtual bool is_finite() const; // Has a finite value
587 virtual const Type *xmeet( const Type *t ) const;
588 virtual const Type *xdual() const; // Compute dual right now.
589 virtual const Type *widen( const Type *t, const Type* limit_type ) const;
590 virtual const Type *narrow( const Type *t ) const;
591 // Convenience common pre-built types.
592 static const TypeLong *MINUS_1;
593 static const TypeLong *ZERO;
594 static const TypeLong *ONE;
595 static const TypeLong *POS;
596 static const TypeLong *LONG;
597 static const TypeLong *INT; // 32-bit subrange [min_jint..max_jint]
598 static const TypeLong *UINT; // 32-bit unsigned [0..max_juint]
599 static const TypeLong *TYPE_DOMAIN; // alias for TypeLong::LONG
601 // static convenience methods.
602 static const TypeLong *as_self(const Type *t) { return t->is_long(); }
604 #ifndef PRODUCT
605 virtual void dump2( Dict &d, uint, outputStream *st ) const;// Specialized per-Type dumping
606 #endif
607 };
609 //------------------------------TypeTuple--------------------------------------
610 // Class of Tuple Types, essentially type collections for function signatures
611 // and class layouts. It happens to also be a fast cache for the HotSpot
612 // signature types.
613 class TypeTuple : public Type {
614 TypeTuple( uint cnt, const Type **fields ) : Type(Tuple), _cnt(cnt), _fields(fields) { }
615 public:
616 virtual bool eq( const Type *t ) const;
617 virtual int hash() const; // Type specific hashing
618 virtual bool singleton(void) const; // TRUE if type is a singleton
619 virtual bool empty(void) const; // TRUE if type is vacuous
621 public:
622 const uint _cnt; // Count of fields
623 const Type ** const _fields; // Array of field types
625 // Accessors:
626 uint cnt() const { return _cnt; }
627 const Type* field_at(uint i) const {
628 assert(i < _cnt, "oob");
629 return _fields[i];
630 }
631 void set_field_at(uint i, const Type* t) {
632 assert(i < _cnt, "oob");
633 _fields[i] = t;
634 }
636 static const TypeTuple *make( uint cnt, const Type **fields );
637 static const TypeTuple *make_range(ciSignature *sig);
638 static const TypeTuple *make_domain(ciInstanceKlass* recv, ciSignature *sig);
640 // Subroutine call type with space allocated for argument types
641 static const Type **fields( uint arg_cnt );
643 virtual const Type *xmeet( const Type *t ) const;
644 virtual const Type *xdual() const; // Compute dual right now.
645 // Convenience common pre-built types.
646 static const TypeTuple *IFBOTH;
647 static const TypeTuple *IFFALSE;
648 static const TypeTuple *IFTRUE;
649 static const TypeTuple *IFNEITHER;
650 static const TypeTuple *LOOPBODY;
651 static const TypeTuple *MEMBAR;
652 static const TypeTuple *STORECONDITIONAL;
653 static const TypeTuple *START_I2C;
654 static const TypeTuple *INT_PAIR;
655 static const TypeTuple *LONG_PAIR;
656 static const TypeTuple *INT_CC_PAIR;
657 static const TypeTuple *LONG_CC_PAIR;
658 #ifndef PRODUCT
659 virtual void dump2( Dict &d, uint, outputStream *st ) const; // Specialized per-Type dumping
660 #endif
661 };
663 //------------------------------TypeAry----------------------------------------
664 // Class of Array Types
665 class TypeAry : public Type {
666 TypeAry(const Type* elem, const TypeInt* size, bool stable) : Type(Array),
667 _elem(elem), _size(size), _stable(stable) {}
668 public:
669 virtual bool eq( const Type *t ) const;
670 virtual int hash() const; // Type specific hashing
671 virtual bool singleton(void) const; // TRUE if type is a singleton
672 virtual bool empty(void) const; // TRUE if type is vacuous
674 private:
675 const Type *_elem; // Element type of array
676 const TypeInt *_size; // Elements in array
677 const bool _stable; // Are elements @Stable?
678 friend class TypeAryPtr;
680 public:
681 static const TypeAry* make(const Type* elem, const TypeInt* size, bool stable = false);
683 virtual const Type *xmeet( const Type *t ) const;
684 virtual const Type *xdual() const; // Compute dual right now.
685 bool ary_must_be_exact() const; // true if arrays of such are never generic
686 virtual const Type* remove_speculative() const;
687 #ifdef ASSERT
688 // One type is interface, the other is oop
689 virtual bool interface_vs_oop(const Type *t) const;
690 #endif
691 #ifndef PRODUCT
692 virtual void dump2( Dict &d, uint, outputStream *st ) const; // Specialized per-Type dumping
693 #endif
694 };
696 //------------------------------TypeVect---------------------------------------
697 // Class of Vector Types
698 class TypeVect : public Type {
699 const Type* _elem; // Vector's element type
700 const uint _length; // Elements in vector (power of 2)
702 protected:
703 TypeVect(TYPES t, const Type* elem, uint length) : Type(t),
704 _elem(elem), _length(length) {}
706 public:
707 const Type* element_type() const { return _elem; }
708 BasicType element_basic_type() const { return _elem->array_element_basic_type(); }
709 uint length() const { return _length; }
710 uint length_in_bytes() const {
711 return _length * type2aelembytes(element_basic_type());
712 }
714 virtual bool eq(const Type *t) const;
715 virtual int hash() const; // Type specific hashing
716 virtual bool singleton(void) const; // TRUE if type is a singleton
717 virtual bool empty(void) const; // TRUE if type is vacuous
719 static const TypeVect *make(const BasicType elem_bt, uint length) {
720 // Use bottom primitive type.
721 return make(get_const_basic_type(elem_bt), length);
722 }
723 // Used directly by Replicate nodes to construct singleton vector.
724 static const TypeVect *make(const Type* elem, uint length);
726 virtual const Type *xmeet( const Type *t) const;
727 virtual const Type *xdual() const; // Compute dual right now.
729 static const TypeVect *VECTS;
730 static const TypeVect *VECTD;
731 static const TypeVect *VECTX;
732 static const TypeVect *VECTY;
734 #ifndef PRODUCT
735 virtual void dump2(Dict &d, uint, outputStream *st) const; // Specialized per-Type dumping
736 #endif
737 };
739 class TypeVectS : public TypeVect {
740 friend class TypeVect;
741 TypeVectS(const Type* elem, uint length) : TypeVect(VectorS, elem, length) {}
742 };
744 class TypeVectD : public TypeVect {
745 friend class TypeVect;
746 TypeVectD(const Type* elem, uint length) : TypeVect(VectorD, elem, length) {}
747 };
749 class TypeVectX : public TypeVect {
750 friend class TypeVect;
751 TypeVectX(const Type* elem, uint length) : TypeVect(VectorX, elem, length) {}
752 };
754 class TypeVectY : public TypeVect {
755 friend class TypeVect;
756 TypeVectY(const Type* elem, uint length) : TypeVect(VectorY, elem, length) {}
757 };
759 //------------------------------TypePtr----------------------------------------
760 // Class of machine Pointer Types: raw data, instances or arrays.
761 // If the _base enum is AnyPtr, then this refers to all of the above.
762 // Otherwise the _base will indicate which subset of pointers is affected,
763 // and the class will be inherited from.
764 class TypePtr : public Type {
765 friend class TypeNarrowPtr;
766 public:
767 enum PTR { TopPTR, AnyNull, Constant, Null, NotNull, BotPTR, lastPTR };
768 protected:
769 TypePtr( TYPES t, PTR ptr, int offset ) : Type(t), _ptr(ptr), _offset(offset) {}
770 virtual bool eq( const Type *t ) const;
771 virtual int hash() const; // Type specific hashing
772 static const PTR ptr_meet[lastPTR][lastPTR];
773 static const PTR ptr_dual[lastPTR];
774 static const char * const ptr_msg[lastPTR];
776 public:
777 const int _offset; // Offset into oop, with TOP & BOT
778 const PTR _ptr; // Pointer equivalence class
780 const int offset() const { return _offset; }
781 const PTR ptr() const { return _ptr; }
783 static const TypePtr *make( TYPES t, PTR ptr, int offset );
785 // Return a 'ptr' version of this type
786 virtual const Type *cast_to_ptr_type(PTR ptr) const;
788 virtual intptr_t get_con() const;
790 int xadd_offset( intptr_t offset ) const;
791 virtual const TypePtr *add_offset( intptr_t offset ) const;
793 virtual bool singleton(void) const; // TRUE if type is a singleton
794 virtual bool empty(void) const; // TRUE if type is vacuous
795 virtual const Type *xmeet( const Type *t ) const;
796 int meet_offset( int offset ) const;
797 int dual_offset( ) const;
798 virtual const Type *xdual() const; // Compute dual right now.
800 // meet, dual and join over pointer equivalence sets
801 PTR meet_ptr( const PTR in_ptr ) const { return ptr_meet[in_ptr][ptr()]; }
802 PTR dual_ptr() const { return ptr_dual[ptr()]; }
804 // This is textually confusing unless one recalls that
805 // join(t) == dual()->meet(t->dual())->dual().
806 PTR join_ptr( const PTR in_ptr ) const {
807 return ptr_dual[ ptr_meet[ ptr_dual[in_ptr] ] [ dual_ptr() ] ];
808 }
810 // Tests for relation to centerline of type lattice:
811 static bool above_centerline(PTR ptr) { return (ptr <= AnyNull); }
812 static bool below_centerline(PTR ptr) { return (ptr >= NotNull); }
813 // Convenience common pre-built types.
814 static const TypePtr *NULL_PTR;
815 static const TypePtr *NOTNULL;
816 static const TypePtr *BOTTOM;
817 #ifndef PRODUCT
818 virtual void dump2( Dict &d, uint depth, outputStream *st ) const;
819 #endif
820 };
822 //------------------------------TypeRawPtr-------------------------------------
823 // Class of raw pointers, pointers to things other than Oops. Examples
824 // include the stack pointer, top of heap, card-marking area, handles, etc.
825 class TypeRawPtr : public TypePtr {
826 protected:
827 TypeRawPtr( PTR ptr, address bits ) : TypePtr(RawPtr,ptr,0), _bits(bits){}
828 public:
829 virtual bool eq( const Type *t ) const;
830 virtual int hash() const; // Type specific hashing
832 const address _bits; // Constant value, if applicable
834 static const TypeRawPtr *make( PTR ptr );
835 static const TypeRawPtr *make( address bits );
837 // Return a 'ptr' version of this type
838 virtual const Type *cast_to_ptr_type(PTR ptr) const;
840 virtual intptr_t get_con() const;
842 virtual const TypePtr *add_offset( intptr_t offset ) const;
844 virtual const Type *xmeet( const Type *t ) const;
845 virtual const Type *xdual() const; // Compute dual right now.
846 // Convenience common pre-built types.
847 static const TypeRawPtr *BOTTOM;
848 static const TypeRawPtr *NOTNULL;
849 #ifndef PRODUCT
850 virtual void dump2( Dict &d, uint depth, outputStream *st ) const;
851 #endif
852 };
854 //------------------------------TypeOopPtr-------------------------------------
855 // Some kind of oop (Java pointer), either klass or instance or array.
856 class TypeOopPtr : public TypePtr {
857 protected:
858 TypeOopPtr(TYPES t, PTR ptr, ciKlass* k, bool xk, ciObject* o, int offset, int instance_id, const TypeOopPtr* speculative, int inline_depth);
859 public:
860 virtual bool eq( const Type *t ) const;
861 virtual int hash() const; // Type specific hashing
862 virtual bool singleton(void) const; // TRUE if type is a singleton
863 enum {
864 InstanceTop = -1, // undefined instance
865 InstanceBot = 0 // any possible instance
866 };
867 protected:
869 enum {
870 InlineDepthBottom = INT_MAX,
871 InlineDepthTop = -InlineDepthBottom
872 };
873 // Oop is NULL, unless this is a constant oop.
874 ciObject* _const_oop; // Constant oop
875 // If _klass is NULL, then so is _sig. This is an unloaded klass.
876 ciKlass* _klass; // Klass object
877 // Does the type exclude subclasses of the klass? (Inexact == polymorphic.)
878 bool _klass_is_exact;
879 bool _is_ptr_to_narrowoop;
880 bool _is_ptr_to_narrowklass;
881 bool _is_ptr_to_boxed_value;
883 // If not InstanceTop or InstanceBot, indicates that this is
884 // a particular instance of this type which is distinct.
885 // This is the node index of the allocation node creating this instance.
886 int _instance_id;
888 // Extra type information profiling gave us. We propagate it the
889 // same way the rest of the type info is propagated. If we want to
890 // use it, then we have to emit a guard: this part of the type is
891 // not something we know but something we speculate about the type.
892 const TypeOopPtr* _speculative;
893 // For speculative types, we record at what inlining depth the
894 // profiling point that provided the data is. We want to favor
895 // profile data coming from outer scopes which are likely better for
896 // the current compilation.
897 int _inline_depth;
899 static const TypeOopPtr* make_from_klass_common(ciKlass* klass, bool klass_change, bool try_for_exact);
901 int dual_instance_id() const;
902 int meet_instance_id(int uid) const;
904 // utility methods to work on the speculative part of the type
905 const TypeOopPtr* dual_speculative() const;
906 const TypeOopPtr* xmeet_speculative(const TypeOopPtr* other) const;
907 bool eq_speculative(const TypeOopPtr* other) const;
908 int hash_speculative() const;
909 const TypeOopPtr* add_offset_speculative(intptr_t offset) const;
910 #ifndef PRODUCT
911 void dump_speculative(outputStream *st) const;
912 #endif
913 // utility methods to work on the inline depth of the type
914 int dual_inline_depth() const;
915 int meet_inline_depth(int depth) const;
916 #ifndef PRODUCT
917 void dump_inline_depth(outputStream *st) const;
918 #endif
920 // Do not allow interface-vs.-noninterface joins to collapse to top.
921 virtual const Type *filter_helper(const Type *kills, bool include_speculative) const;
923 public:
924 // Creates a type given a klass. Correctly handles multi-dimensional arrays
925 // Respects UseUniqueSubclasses.
926 // If the klass is final, the resulting type will be exact.
927 static const TypeOopPtr* make_from_klass(ciKlass* klass) {
928 return make_from_klass_common(klass, true, false);
929 }
930 // Same as before, but will produce an exact type, even if
931 // the klass is not final, as long as it has exactly one implementation.
932 static const TypeOopPtr* make_from_klass_unique(ciKlass* klass) {
933 return make_from_klass_common(klass, true, true);
934 }
935 // Same as before, but does not respects UseUniqueSubclasses.
936 // Use this only for creating array element types.
937 static const TypeOopPtr* make_from_klass_raw(ciKlass* klass) {
938 return make_from_klass_common(klass, false, false);
939 }
940 // Creates a singleton type given an object.
941 // If the object cannot be rendered as a constant,
942 // may return a non-singleton type.
943 // If require_constant, produce a NULL if a singleton is not possible.
944 static const TypeOopPtr* make_from_constant(ciObject* o,
945 bool require_constant = false,
946 bool not_null_elements = false);
948 // Make a generic (unclassed) pointer to an oop.
949 static const TypeOopPtr* make(PTR ptr, int offset, int instance_id, const TypeOopPtr* speculative = NULL, int inline_depth = InlineDepthBottom);
951 ciObject* const_oop() const { return _const_oop; }
952 virtual ciKlass* klass() const { return _klass; }
953 bool klass_is_exact() const { return _klass_is_exact; }
955 // Returns true if this pointer points at memory which contains a
956 // compressed oop references.
957 bool is_ptr_to_narrowoop_nv() const { return _is_ptr_to_narrowoop; }
958 bool is_ptr_to_narrowklass_nv() const { return _is_ptr_to_narrowklass; }
959 bool is_ptr_to_boxed_value() const { return _is_ptr_to_boxed_value; }
960 bool is_known_instance() const { return _instance_id > 0; }
961 int instance_id() const { return _instance_id; }
962 bool is_known_instance_field() const { return is_known_instance() && _offset >= 0; }
963 virtual const TypeOopPtr* speculative() const { return _speculative; }
965 virtual intptr_t get_con() const;
967 virtual const Type *cast_to_ptr_type(PTR ptr) const;
969 virtual const Type *cast_to_exactness(bool klass_is_exact) const;
971 virtual const TypeOopPtr *cast_to_instance_id(int instance_id) const;
973 // corresponding pointer to klass, for a given instance
974 const TypeKlassPtr* as_klass_type() const;
976 virtual const TypePtr *add_offset( intptr_t offset ) const;
977 // Return same type without a speculative part
978 virtual const Type* remove_speculative() const;
980 virtual const Type *xmeet(const Type *t) const;
981 virtual const Type *xdual() const; // Compute dual right now.
982 // the core of the computation of the meet for TypeOopPtr and for its subclasses
983 virtual const Type *xmeet_helper(const Type *t) const;
985 // Convenience common pre-built type.
986 static const TypeOopPtr *BOTTOM;
987 #ifndef PRODUCT
988 virtual void dump2( Dict &d, uint depth, outputStream *st ) const;
989 #endif
991 // Return the speculative type if any
992 ciKlass* speculative_type() const {
993 if (_speculative != NULL) {
994 const TypeOopPtr* speculative = _speculative->join(this)->is_oopptr();
995 if (speculative->klass_is_exact()) {
996 return speculative->klass();
997 }
998 }
999 return NULL;
1000 }
1001 int inline_depth() const {
1002 return _inline_depth;
1003 }
1004 virtual const TypeOopPtr* with_inline_depth(int depth) const;
1005 virtual bool would_improve_type(ciKlass* exact_kls, int inline_depth) const;
1006 };
1008 //------------------------------TypeInstPtr------------------------------------
1009 // Class of Java object pointers, pointing either to non-array Java instances
1010 // or to a Klass* (including array klasses).
1011 class TypeInstPtr : public TypeOopPtr {
1012 TypeInstPtr(PTR ptr, ciKlass* k, bool xk, ciObject* o, int offset, int instance_id, const TypeOopPtr* speculative, int inline_depth);
1013 virtual bool eq( const Type *t ) const;
1014 virtual int hash() const; // Type specific hashing
1016 ciSymbol* _name; // class name
1018 public:
1019 ciSymbol* name() const { return _name; }
1021 bool is_loaded() const { return _klass->is_loaded(); }
1023 // Make a pointer to a constant oop.
1024 static const TypeInstPtr *make(ciObject* o) {
1025 return make(TypePtr::Constant, o->klass(), true, o, 0, InstanceBot);
1026 }
1027 // Make a pointer to a constant oop with offset.
1028 static const TypeInstPtr *make(ciObject* o, int offset) {
1029 return make(TypePtr::Constant, o->klass(), true, o, offset, InstanceBot);
1030 }
1032 // Make a pointer to some value of type klass.
1033 static const TypeInstPtr *make(PTR ptr, ciKlass* klass) {
1034 return make(ptr, klass, false, NULL, 0, InstanceBot);
1035 }
1037 // Make a pointer to some non-polymorphic value of exactly type klass.
1038 static const TypeInstPtr *make_exact(PTR ptr, ciKlass* klass) {
1039 return make(ptr, klass, true, NULL, 0, InstanceBot);
1040 }
1042 // Make a pointer to some value of type klass with offset.
1043 static const TypeInstPtr *make(PTR ptr, ciKlass* klass, int offset) {
1044 return make(ptr, klass, false, NULL, offset, InstanceBot);
1045 }
1047 // Make a pointer to an oop.
1048 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);
1050 /** Create constant type for a constant boxed value */
1051 const Type* get_const_boxed_value() const;
1053 // If this is a java.lang.Class constant, return the type for it or NULL.
1054 // Pass to Type::get_const_type to turn it to a type, which will usually
1055 // be a TypeInstPtr, but may also be a TypeInt::INT for int.class, etc.
1056 ciType* java_mirror_type() const;
1058 virtual const Type *cast_to_ptr_type(PTR ptr) const;
1060 virtual const Type *cast_to_exactness(bool klass_is_exact) const;
1062 virtual const TypeOopPtr *cast_to_instance_id(int instance_id) const;
1064 virtual const TypePtr *add_offset( intptr_t offset ) const;
1065 // Return same type without a speculative part
1066 virtual const Type* remove_speculative() const;
1067 virtual const TypeOopPtr* with_inline_depth(int depth) const;
1069 // the core of the computation of the meet of 2 types
1070 virtual const Type *xmeet_helper(const Type *t) const;
1071 virtual const TypeInstPtr *xmeet_unloaded( const TypeInstPtr *t ) const;
1072 virtual const Type *xdual() const; // Compute dual right now.
1074 // Convenience common pre-built types.
1075 static const TypeInstPtr *NOTNULL;
1076 static const TypeInstPtr *BOTTOM;
1077 static const TypeInstPtr *MIRROR;
1078 static const TypeInstPtr *MARK;
1079 static const TypeInstPtr *KLASS;
1080 #ifndef PRODUCT
1081 virtual void dump2( Dict &d, uint depth, outputStream *st ) const; // Specialized per-Type dumping
1082 #endif
1083 };
1085 //------------------------------TypeAryPtr-------------------------------------
1086 // Class of Java array pointers
1087 class TypeAryPtr : public TypeOopPtr {
1088 TypeAryPtr( PTR ptr, ciObject* o, const TypeAry *ary, ciKlass* k, bool xk,
1089 int offset, int instance_id, bool is_autobox_cache, const TypeOopPtr* speculative, int inline_depth)
1090 : TypeOopPtr(AryPtr,ptr,k,xk,o,offset, instance_id, speculative, inline_depth),
1091 _ary(ary),
1092 _is_autobox_cache(is_autobox_cache)
1093 {
1094 #ifdef ASSERT
1095 if (k != NULL) {
1096 // Verify that specified klass and TypeAryPtr::klass() follow the same rules.
1097 ciKlass* ck = compute_klass(true);
1098 if (k != ck) {
1099 this->dump(); tty->cr();
1100 tty->print(" k: ");
1101 k->print(); tty->cr();
1102 tty->print("ck: ");
1103 if (ck != NULL) ck->print();
1104 else tty->print("<NULL>");
1105 tty->cr();
1106 assert(false, "unexpected TypeAryPtr::_klass");
1107 }
1108 }
1109 #endif
1110 }
1111 virtual bool eq( const Type *t ) const;
1112 virtual int hash() const; // Type specific hashing
1113 const TypeAry *_ary; // Array we point into
1114 const bool _is_autobox_cache;
1116 ciKlass* compute_klass(DEBUG_ONLY(bool verify = false)) const;
1118 public:
1119 // Accessors
1120 ciKlass* klass() const;
1121 const TypeAry* ary() const { return _ary; }
1122 const Type* elem() const { return _ary->_elem; }
1123 const TypeInt* size() const { return _ary->_size; }
1124 bool is_stable() const { return _ary->_stable; }
1126 bool is_autobox_cache() const { return _is_autobox_cache; }
1128 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);
1129 // Constant pointer to array
1130 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);
1132 // Return a 'ptr' version of this type
1133 virtual const Type *cast_to_ptr_type(PTR ptr) const;
1135 virtual const Type *cast_to_exactness(bool klass_is_exact) const;
1137 virtual const TypeOopPtr *cast_to_instance_id(int instance_id) const;
1139 virtual const TypeAryPtr* cast_to_size(const TypeInt* size) const;
1140 virtual const TypeInt* narrow_size_type(const TypeInt* size) const;
1142 virtual bool empty(void) const; // TRUE if type is vacuous
1143 virtual const TypePtr *add_offset( intptr_t offset ) const;
1144 // Return same type without a speculative part
1145 virtual const Type* remove_speculative() const;
1146 virtual const TypeOopPtr* with_inline_depth(int depth) const;
1148 // the core of the computation of the meet of 2 types
1149 virtual const Type *xmeet_helper(const Type *t) const;
1150 virtual const Type *xdual() const; // Compute dual right now.
1152 const TypeAryPtr* cast_to_stable(bool stable, int stable_dimension = 1) const;
1153 int stable_dimension() const;
1155 // Convenience common pre-built types.
1156 static const TypeAryPtr *RANGE;
1157 static const TypeAryPtr *OOPS;
1158 static const TypeAryPtr *NARROWOOPS;
1159 static const TypeAryPtr *BYTES;
1160 static const TypeAryPtr *SHORTS;
1161 static const TypeAryPtr *CHARS;
1162 static const TypeAryPtr *INTS;
1163 static const TypeAryPtr *LONGS;
1164 static const TypeAryPtr *FLOATS;
1165 static const TypeAryPtr *DOUBLES;
1166 // selects one of the above:
1167 static const TypeAryPtr *get_array_body_type(BasicType elem) {
1168 assert((uint)elem <= T_CONFLICT && _array_body_type[elem] != NULL, "bad elem type");
1169 return _array_body_type[elem];
1170 }
1171 static const TypeAryPtr *_array_body_type[T_CONFLICT+1];
1172 // sharpen the type of an int which is used as an array size
1173 #ifdef ASSERT
1174 // One type is interface, the other is oop
1175 virtual bool interface_vs_oop(const Type *t) const;
1176 #endif
1177 #ifndef PRODUCT
1178 virtual void dump2( Dict &d, uint depth, outputStream *st ) const; // Specialized per-Type dumping
1179 #endif
1180 };
1182 //------------------------------TypeMetadataPtr-------------------------------------
1183 // Some kind of metadata, either Method*, MethodData* or CPCacheOop
1184 class TypeMetadataPtr : public TypePtr {
1185 protected:
1186 TypeMetadataPtr(PTR ptr, ciMetadata* metadata, int offset);
1187 // Do not allow interface-vs.-noninterface joins to collapse to top.
1188 virtual const Type *filter_helper(const Type *kills, bool include_speculative) const;
1189 public:
1190 virtual bool eq( const Type *t ) const;
1191 virtual int hash() const; // Type specific hashing
1192 virtual bool singleton(void) const; // TRUE if type is a singleton
1194 private:
1195 ciMetadata* _metadata;
1197 public:
1198 static const TypeMetadataPtr* make(PTR ptr, ciMetadata* m, int offset);
1200 static const TypeMetadataPtr* make(ciMethod* m);
1201 static const TypeMetadataPtr* make(ciMethodData* m);
1203 ciMetadata* metadata() const { return _metadata; }
1205 virtual const Type *cast_to_ptr_type(PTR ptr) const;
1207 virtual const TypePtr *add_offset( intptr_t offset ) const;
1209 virtual const Type *xmeet( const Type *t ) const;
1210 virtual const Type *xdual() const; // Compute dual right now.
1212 virtual intptr_t get_con() const;
1214 // Convenience common pre-built types.
1215 static const TypeMetadataPtr *BOTTOM;
1217 #ifndef PRODUCT
1218 virtual void dump2( Dict &d, uint depth, outputStream *st ) const;
1219 #endif
1220 };
1222 //------------------------------TypeKlassPtr-----------------------------------
1223 // Class of Java Klass pointers
1224 class TypeKlassPtr : public TypePtr {
1225 TypeKlassPtr( PTR ptr, ciKlass* klass, int offset );
1227 protected:
1228 virtual const Type *filter_helper(const Type *kills, bool include_speculative) const;
1229 public:
1230 virtual bool eq( const Type *t ) const;
1231 virtual int hash() const; // Type specific hashing
1232 virtual bool singleton(void) const; // TRUE if type is a singleton
1233 private:
1235 static const TypeKlassPtr* make_from_klass_common(ciKlass* klass, bool klass_change, bool try_for_exact);
1237 ciKlass* _klass;
1239 // Does the type exclude subclasses of the klass? (Inexact == polymorphic.)
1240 bool _klass_is_exact;
1242 public:
1243 ciSymbol* name() const { return klass()->name(); }
1245 ciKlass* klass() const { return _klass; }
1246 bool klass_is_exact() const { return _klass_is_exact; }
1248 bool is_loaded() const { return klass()->is_loaded(); }
1250 // Creates a type given a klass. Correctly handles multi-dimensional arrays
1251 // Respects UseUniqueSubclasses.
1252 // If the klass is final, the resulting type will be exact.
1253 static const TypeKlassPtr* make_from_klass(ciKlass* klass) {
1254 return make_from_klass_common(klass, true, false);
1255 }
1256 // Same as before, but will produce an exact type, even if
1257 // the klass is not final, as long as it has exactly one implementation.
1258 static const TypeKlassPtr* make_from_klass_unique(ciKlass* klass) {
1259 return make_from_klass_common(klass, true, true);
1260 }
1261 // Same as before, but does not respects UseUniqueSubclasses.
1262 // Use this only for creating array element types.
1263 static const TypeKlassPtr* make_from_klass_raw(ciKlass* klass) {
1264 return make_from_klass_common(klass, false, false);
1265 }
1267 // Make a generic (unclassed) pointer to metadata.
1268 static const TypeKlassPtr* make(PTR ptr, int offset);
1270 // ptr to klass 'k'
1271 static const TypeKlassPtr *make( ciKlass* k ) { return make( TypePtr::Constant, k, 0); }
1272 // ptr to klass 'k' with offset
1273 static const TypeKlassPtr *make( ciKlass* k, int offset ) { return make( TypePtr::Constant, k, offset); }
1274 // ptr to klass 'k' or sub-klass
1275 static const TypeKlassPtr *make( PTR ptr, ciKlass* k, int offset);
1277 virtual const Type *cast_to_ptr_type(PTR ptr) const;
1279 virtual const Type *cast_to_exactness(bool klass_is_exact) const;
1281 // corresponding pointer to instance, for a given class
1282 const TypeOopPtr* as_instance_type() const;
1284 virtual const TypePtr *add_offset( intptr_t offset ) const;
1285 virtual const Type *xmeet( const Type *t ) const;
1286 virtual const Type *xdual() const; // Compute dual right now.
1288 virtual intptr_t get_con() const;
1290 // Convenience common pre-built types.
1291 static const TypeKlassPtr* OBJECT; // Not-null object klass or below
1292 static const TypeKlassPtr* OBJECT_OR_NULL; // Maybe-null version of same
1293 #ifndef PRODUCT
1294 virtual void dump2( Dict &d, uint depth, outputStream *st ) const; // Specialized per-Type dumping
1295 #endif
1296 };
1298 class TypeNarrowPtr : public Type {
1299 protected:
1300 const TypePtr* _ptrtype; // Could be TypePtr::NULL_PTR
1302 TypeNarrowPtr(TYPES t, const TypePtr* ptrtype): _ptrtype(ptrtype),
1303 Type(t) {
1304 assert(ptrtype->offset() == 0 ||
1305 ptrtype->offset() == OffsetBot ||
1306 ptrtype->offset() == OffsetTop, "no real offsets");
1307 }
1309 virtual const TypeNarrowPtr *isa_same_narrowptr(const Type *t) const = 0;
1310 virtual const TypeNarrowPtr *is_same_narrowptr(const Type *t) const = 0;
1311 virtual const TypeNarrowPtr *make_same_narrowptr(const TypePtr *t) const = 0;
1312 virtual const TypeNarrowPtr *make_hash_same_narrowptr(const TypePtr *t) const = 0;
1313 // Do not allow interface-vs.-noninterface joins to collapse to top.
1314 virtual const Type *filter_helper(const Type *kills, bool include_speculative) const;
1315 public:
1316 virtual bool eq( const Type *t ) const;
1317 virtual int hash() const; // Type specific hashing
1318 virtual bool singleton(void) const; // TRUE if type is a singleton
1320 virtual const Type *xmeet( const Type *t ) const;
1321 virtual const Type *xdual() const; // Compute dual right now.
1323 virtual intptr_t get_con() const;
1325 virtual bool empty(void) const; // TRUE if type is vacuous
1327 // returns the equivalent ptr type for this compressed pointer
1328 const TypePtr *get_ptrtype() const {
1329 return _ptrtype;
1330 }
1332 #ifndef PRODUCT
1333 virtual void dump2( Dict &d, uint depth, outputStream *st ) const;
1334 #endif
1335 };
1337 //------------------------------TypeNarrowOop----------------------------------
1338 // A compressed reference to some kind of Oop. This type wraps around
1339 // a preexisting TypeOopPtr and forwards most of it's operations to
1340 // the underlying type. It's only real purpose is to track the
1341 // oopness of the compressed oop value when we expose the conversion
1342 // between the normal and the compressed form.
1343 class TypeNarrowOop : public TypeNarrowPtr {
1344 protected:
1345 TypeNarrowOop( const TypePtr* ptrtype): TypeNarrowPtr(NarrowOop, ptrtype) {
1346 }
1348 virtual const TypeNarrowPtr *isa_same_narrowptr(const Type *t) const {
1349 return t->isa_narrowoop();
1350 }
1352 virtual const TypeNarrowPtr *is_same_narrowptr(const Type *t) const {
1353 return t->is_narrowoop();
1354 }
1356 virtual const TypeNarrowPtr *make_same_narrowptr(const TypePtr *t) const {
1357 return new TypeNarrowOop(t);
1358 }
1360 virtual const TypeNarrowPtr *make_hash_same_narrowptr(const TypePtr *t) const {
1361 return (const TypeNarrowPtr*)((new TypeNarrowOop(t))->hashcons());
1362 }
1364 public:
1366 static const TypeNarrowOop *make( const TypePtr* type);
1368 static const TypeNarrowOop* make_from_constant(ciObject* con, bool require_constant = false) {
1369 return make(TypeOopPtr::make_from_constant(con, require_constant));
1370 }
1372 static const TypeNarrowOop *BOTTOM;
1373 static const TypeNarrowOop *NULL_PTR;
1375 virtual const Type* remove_speculative() const {
1376 return make(_ptrtype->remove_speculative()->is_ptr());
1377 }
1379 #ifndef PRODUCT
1380 virtual void dump2( Dict &d, uint depth, outputStream *st ) const;
1381 #endif
1382 };
1384 //------------------------------TypeNarrowKlass----------------------------------
1385 // A compressed reference to klass pointer. This type wraps around a
1386 // preexisting TypeKlassPtr and forwards most of it's operations to
1387 // the underlying type.
1388 class TypeNarrowKlass : public TypeNarrowPtr {
1389 protected:
1390 TypeNarrowKlass( const TypePtr* ptrtype): TypeNarrowPtr(NarrowKlass, ptrtype) {
1391 }
1393 virtual const TypeNarrowPtr *isa_same_narrowptr(const Type *t) const {
1394 return t->isa_narrowklass();
1395 }
1397 virtual const TypeNarrowPtr *is_same_narrowptr(const Type *t) const {
1398 return t->is_narrowklass();
1399 }
1401 virtual const TypeNarrowPtr *make_same_narrowptr(const TypePtr *t) const {
1402 return new TypeNarrowKlass(t);
1403 }
1405 virtual const TypeNarrowPtr *make_hash_same_narrowptr(const TypePtr *t) const {
1406 return (const TypeNarrowPtr*)((new TypeNarrowKlass(t))->hashcons());
1407 }
1409 public:
1410 static const TypeNarrowKlass *make( const TypePtr* type);
1412 // static const TypeNarrowKlass *BOTTOM;
1413 static const TypeNarrowKlass *NULL_PTR;
1415 #ifndef PRODUCT
1416 virtual void dump2( Dict &d, uint depth, outputStream *st ) const;
1417 #endif
1418 };
1420 //------------------------------TypeFunc---------------------------------------
1421 // Class of Array Types
1422 class TypeFunc : public Type {
1423 TypeFunc( const TypeTuple *domain, const TypeTuple *range ) : Type(Function), _domain(domain), _range(range) {}
1424 virtual bool eq( const Type *t ) const;
1425 virtual int hash() const; // Type specific hashing
1426 virtual bool singleton(void) const; // TRUE if type is a singleton
1427 virtual bool empty(void) const; // TRUE if type is vacuous
1428 public:
1429 // Constants are shared among ADLC and VM
1430 enum { Control = AdlcVMDeps::Control,
1431 I_O = AdlcVMDeps::I_O,
1432 Memory = AdlcVMDeps::Memory,
1433 FramePtr = AdlcVMDeps::FramePtr,
1434 ReturnAdr = AdlcVMDeps::ReturnAdr,
1435 Parms = AdlcVMDeps::Parms
1436 };
1438 const TypeTuple* const _domain; // Domain of inputs
1439 const TypeTuple* const _range; // Range of results
1441 // Accessors:
1442 const TypeTuple* domain() const { return _domain; }
1443 const TypeTuple* range() const { return _range; }
1445 static const TypeFunc *make(ciMethod* method);
1446 static const TypeFunc *make(ciSignature signature, const Type* extra);
1447 static const TypeFunc *make(const TypeTuple* domain, const TypeTuple* range);
1449 virtual const Type *xmeet( const Type *t ) const;
1450 virtual const Type *xdual() const; // Compute dual right now.
1452 BasicType return_type() const;
1454 #ifndef PRODUCT
1455 virtual void dump2( Dict &d, uint depth, outputStream *st ) const; // Specialized per-Type dumping
1456 #endif
1457 // Convenience common pre-built types.
1458 };
1460 //------------------------------accessors--------------------------------------
1461 inline bool Type::is_ptr_to_narrowoop() const {
1462 #ifdef _LP64
1463 return (isa_oopptr() != NULL && is_oopptr()->is_ptr_to_narrowoop_nv());
1464 #else
1465 return false;
1466 #endif
1467 }
1469 inline bool Type::is_ptr_to_narrowklass() const {
1470 #ifdef _LP64
1471 return (isa_oopptr() != NULL && is_oopptr()->is_ptr_to_narrowklass_nv());
1472 #else
1473 return false;
1474 #endif
1475 }
1477 inline float Type::getf() const {
1478 assert( _base == FloatCon, "Not a FloatCon" );
1479 return ((TypeF*)this)->_f;
1480 }
1482 inline double Type::getd() const {
1483 assert( _base == DoubleCon, "Not a DoubleCon" );
1484 return ((TypeD*)this)->_d;
1485 }
1487 inline const TypeInt *Type::is_int() const {
1488 assert( _base == Int, "Not an Int" );
1489 return (TypeInt*)this;
1490 }
1492 inline const TypeInt *Type::isa_int() const {
1493 return ( _base == Int ? (TypeInt*)this : NULL);
1494 }
1496 inline const TypeLong *Type::is_long() const {
1497 assert( _base == Long, "Not a Long" );
1498 return (TypeLong*)this;
1499 }
1501 inline const TypeLong *Type::isa_long() const {
1502 return ( _base == Long ? (TypeLong*)this : NULL);
1503 }
1505 inline const TypeF *Type::isa_float() const {
1506 return ((_base == FloatTop ||
1507 _base == FloatCon ||
1508 _base == FloatBot) ? (TypeF*)this : NULL);
1509 }
1511 inline const TypeF *Type::is_float_constant() const {
1512 assert( _base == FloatCon, "Not a Float" );
1513 return (TypeF*)this;
1514 }
1516 inline const TypeF *Type::isa_float_constant() const {
1517 return ( _base == FloatCon ? (TypeF*)this : NULL);
1518 }
1520 inline const TypeD *Type::isa_double() const {
1521 return ((_base == DoubleTop ||
1522 _base == DoubleCon ||
1523 _base == DoubleBot) ? (TypeD*)this : NULL);
1524 }
1526 inline const TypeD *Type::is_double_constant() const {
1527 assert( _base == DoubleCon, "Not a Double" );
1528 return (TypeD*)this;
1529 }
1531 inline const TypeD *Type::isa_double_constant() const {
1532 return ( _base == DoubleCon ? (TypeD*)this : NULL);
1533 }
1535 inline const TypeTuple *Type::is_tuple() const {
1536 assert( _base == Tuple, "Not a Tuple" );
1537 return (TypeTuple*)this;
1538 }
1540 inline const TypeAry *Type::is_ary() const {
1541 assert( _base == Array , "Not an Array" );
1542 return (TypeAry*)this;
1543 }
1545 inline const TypeVect *Type::is_vect() const {
1546 assert( _base >= VectorS && _base <= VectorY, "Not a Vector" );
1547 return (TypeVect*)this;
1548 }
1550 inline const TypeVect *Type::isa_vect() const {
1551 return (_base >= VectorS && _base <= VectorY) ? (TypeVect*)this : NULL;
1552 }
1554 inline const TypePtr *Type::is_ptr() const {
1555 // AnyPtr is the first Ptr and KlassPtr the last, with no non-ptrs between.
1556 assert(_base >= AnyPtr && _base <= KlassPtr, "Not a pointer");
1557 return (TypePtr*)this;
1558 }
1560 inline const TypePtr *Type::isa_ptr() const {
1561 // AnyPtr is the first Ptr and KlassPtr the last, with no non-ptrs between.
1562 return (_base >= AnyPtr && _base <= KlassPtr) ? (TypePtr*)this : NULL;
1563 }
1565 inline const TypeOopPtr *Type::is_oopptr() const {
1566 // OopPtr is the first and KlassPtr the last, with no non-oops between.
1567 assert(_base >= OopPtr && _base <= AryPtr, "Not a Java pointer" ) ;
1568 return (TypeOopPtr*)this;
1569 }
1571 inline const TypeOopPtr *Type::isa_oopptr() const {
1572 // OopPtr is the first and KlassPtr the last, with no non-oops between.
1573 return (_base >= OopPtr && _base <= AryPtr) ? (TypeOopPtr*)this : NULL;
1574 }
1576 inline const TypeRawPtr *Type::isa_rawptr() const {
1577 return (_base == RawPtr) ? (TypeRawPtr*)this : NULL;
1578 }
1580 inline const TypeRawPtr *Type::is_rawptr() const {
1581 assert( _base == RawPtr, "Not a raw pointer" );
1582 return (TypeRawPtr*)this;
1583 }
1585 inline const TypeInstPtr *Type::isa_instptr() const {
1586 return (_base == InstPtr) ? (TypeInstPtr*)this : NULL;
1587 }
1589 inline const TypeInstPtr *Type::is_instptr() const {
1590 assert( _base == InstPtr, "Not an object pointer" );
1591 return (TypeInstPtr*)this;
1592 }
1594 inline const TypeAryPtr *Type::isa_aryptr() const {
1595 return (_base == AryPtr) ? (TypeAryPtr*)this : NULL;
1596 }
1598 inline const TypeAryPtr *Type::is_aryptr() const {
1599 assert( _base == AryPtr, "Not an array pointer" );
1600 return (TypeAryPtr*)this;
1601 }
1603 inline const TypeNarrowOop *Type::is_narrowoop() const {
1604 // OopPtr is the first and KlassPtr the last, with no non-oops between.
1605 assert(_base == NarrowOop, "Not a narrow oop" ) ;
1606 return (TypeNarrowOop*)this;
1607 }
1609 inline const TypeNarrowOop *Type::isa_narrowoop() const {
1610 // OopPtr is the first and KlassPtr the last, with no non-oops between.
1611 return (_base == NarrowOop) ? (TypeNarrowOop*)this : NULL;
1612 }
1614 inline const TypeNarrowKlass *Type::is_narrowklass() const {
1615 assert(_base == NarrowKlass, "Not a narrow oop" ) ;
1616 return (TypeNarrowKlass*)this;
1617 }
1619 inline const TypeNarrowKlass *Type::isa_narrowklass() const {
1620 return (_base == NarrowKlass) ? (TypeNarrowKlass*)this : NULL;
1621 }
1623 inline const TypeMetadataPtr *Type::is_metadataptr() const {
1624 // MetadataPtr is the first and CPCachePtr the last
1625 assert(_base == MetadataPtr, "Not a metadata pointer" ) ;
1626 return (TypeMetadataPtr*)this;
1627 }
1629 inline const TypeMetadataPtr *Type::isa_metadataptr() const {
1630 return (_base == MetadataPtr) ? (TypeMetadataPtr*)this : NULL;
1631 }
1633 inline const TypeKlassPtr *Type::isa_klassptr() const {
1634 return (_base == KlassPtr) ? (TypeKlassPtr*)this : NULL;
1635 }
1637 inline const TypeKlassPtr *Type::is_klassptr() const {
1638 assert( _base == KlassPtr, "Not a klass pointer" );
1639 return (TypeKlassPtr*)this;
1640 }
1642 inline const TypePtr* Type::make_ptr() const {
1643 return (_base == NarrowOop) ? is_narrowoop()->get_ptrtype() :
1644 ((_base == NarrowKlass) ? is_narrowklass()->get_ptrtype() :
1645 (isa_ptr() ? is_ptr() : NULL));
1646 }
1648 inline const TypeOopPtr* Type::make_oopptr() const {
1649 return (_base == NarrowOop) ? is_narrowoop()->get_ptrtype()->is_oopptr() : is_oopptr();
1650 }
1652 inline const TypeNarrowOop* Type::make_narrowoop() const {
1653 return (_base == NarrowOop) ? is_narrowoop() :
1654 (isa_ptr() ? TypeNarrowOop::make(is_ptr()) : NULL);
1655 }
1657 inline const TypeNarrowKlass* Type::make_narrowklass() const {
1658 return (_base == NarrowKlass) ? is_narrowklass() :
1659 (isa_ptr() ? TypeNarrowKlass::make(is_ptr()) : NULL);
1660 }
1662 inline bool Type::is_floatingpoint() const {
1663 if( (_base == FloatCon) || (_base == FloatBot) ||
1664 (_base == DoubleCon) || (_base == DoubleBot) )
1665 return true;
1666 return false;
1667 }
1669 inline bool Type::is_ptr_to_boxing_obj() const {
1670 const TypeInstPtr* tp = isa_instptr();
1671 return (tp != NULL) && (tp->offset() == 0) &&
1672 tp->klass()->is_instance_klass() &&
1673 tp->klass()->as_instance_klass()->is_box_klass();
1674 }
1677 // ===============================================================
1678 // Things that need to be 64-bits in the 64-bit build but
1679 // 32-bits in the 32-bit build. Done this way to get full
1680 // optimization AND strong typing.
1681 #ifdef _LP64
1683 // For type queries and asserts
1684 #define is_intptr_t is_long
1685 #define isa_intptr_t isa_long
1686 #define find_intptr_t_type find_long_type
1687 #define find_intptr_t_con find_long_con
1688 #define TypeX TypeLong
1689 #define Type_X Type::Long
1690 #define TypeX_X TypeLong::LONG
1691 #define TypeX_ZERO TypeLong::ZERO
1692 // For 'ideal_reg' machine registers
1693 #define Op_RegX Op_RegL
1694 // For phase->intcon variants
1695 #define MakeConX longcon
1696 #define ConXNode ConLNode
1697 // For array index arithmetic
1698 #define MulXNode MulLNode
1699 #define AndXNode AndLNode
1700 #define OrXNode OrLNode
1701 #define CmpXNode CmpLNode
1702 #define SubXNode SubLNode
1703 #define LShiftXNode LShiftLNode
1704 // For object size computation:
1705 #define AddXNode AddLNode
1706 #define RShiftXNode RShiftLNode
1707 // For card marks and hashcodes
1708 #define URShiftXNode URShiftLNode
1709 // UseOptoBiasInlining
1710 #define XorXNode XorLNode
1711 #define StoreXConditionalNode StoreLConditionalNode
1712 // Opcodes
1713 #define Op_LShiftX Op_LShiftL
1714 #define Op_AndX Op_AndL
1715 #define Op_AddX Op_AddL
1716 #define Op_SubX Op_SubL
1717 #define Op_XorX Op_XorL
1718 #define Op_URShiftX Op_URShiftL
1719 // conversions
1720 #define ConvI2X(x) ConvI2L(x)
1721 #define ConvL2X(x) (x)
1722 #define ConvX2I(x) ConvL2I(x)
1723 #define ConvX2L(x) (x)
1724 #define ConvX2UL(x) (x)
1726 #else
1728 // For type queries and asserts
1729 #define is_intptr_t is_int
1730 #define isa_intptr_t isa_int
1731 #define find_intptr_t_type find_int_type
1732 #define find_intptr_t_con find_int_con
1733 #define TypeX TypeInt
1734 #define Type_X Type::Int
1735 #define TypeX_X TypeInt::INT
1736 #define TypeX_ZERO TypeInt::ZERO
1737 // For 'ideal_reg' machine registers
1738 #define Op_RegX Op_RegI
1739 // For phase->intcon variants
1740 #define MakeConX intcon
1741 #define ConXNode ConINode
1742 // For array index arithmetic
1743 #define MulXNode MulINode
1744 #define AndXNode AndINode
1745 #define OrXNode OrINode
1746 #define CmpXNode CmpINode
1747 #define SubXNode SubINode
1748 #define LShiftXNode LShiftINode
1749 // For object size computation:
1750 #define AddXNode AddINode
1751 #define RShiftXNode RShiftINode
1752 // For card marks and hashcodes
1753 #define URShiftXNode URShiftINode
1754 // UseOptoBiasInlining
1755 #define XorXNode XorINode
1756 #define StoreXConditionalNode StoreIConditionalNode
1757 // Opcodes
1758 #define Op_LShiftX Op_LShiftI
1759 #define Op_AndX Op_AndI
1760 #define Op_AddX Op_AddI
1761 #define Op_SubX Op_SubI
1762 #define Op_XorX Op_XorI
1763 #define Op_URShiftX Op_URShiftI
1764 // conversions
1765 #define ConvI2X(x) (x)
1766 #define ConvL2X(x) ConvL2I(x)
1767 #define ConvX2I(x) (x)
1768 #define ConvX2L(x) ConvI2L(x)
1769 #define ConvX2UL(x) ConvI2UL(x)
1771 #endif
1773 #endif // SHARE_VM_OPTO_TYPE_HPP