1 /*
2  * Copyright (c) 1997, 2020, 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  */
24 
25 #ifndef SHARE_OPTO_TYPE_HPP
26 #define SHARE_OPTO_TYPE_HPP
27 
28 #include "opto/adlcVMDeps.hpp"
29 #include "runtime/handles.hpp"
30 
31 // Portions of code courtesy of Clifford Click
32 
33 // Optimization - Graph Style
34 
35 
36 // This class defines a Type lattice.  The lattice is used in the constant
37 // propagation algorithms, and for some type-checking of the iloc code.
38 // Basic types include RSD's (lower bound, upper bound, stride for integers),
39 // float & double precision constants, sets of data-labels and code-labels.
40 // The complete lattice is described below.  Subtypes have no relationship to
41 // up or down in the lattice; that is entirely determined by the behavior of
42 // the MEET/JOIN functions.
43 
44 class Dict;
45 class Type;
46 class   TypeD;
47 class   TypeF;
48 class   TypeInteger;
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     TypeVectA;
58 class     TypeVectS;
59 class     TypeVectD;
60 class     TypeVectX;
61 class     TypeVectY;
62 class     TypeVectZ;
63 class   TypePtr;
64 class     TypeRawPtr;
65 class     TypeOopPtr;
66 class       TypeInstPtr;
67 class       TypeAryPtr;
68 class     TypeKlassPtr;
69 class     TypeMetadataPtr;
70 
71 //------------------------------Type-------------------------------------------
72 // Basic Type object, represents a set of primitive Values.
73 // Types are hash-cons'd into a private class dictionary, so only one of each
74 // different kind of Type exists.  Types are never modified after creation, so
75 // all their interesting fields are constant.
76 class Type {
77   friend class VMStructs;
78 
79 public:
80   enum TYPES {
81     Bad=0,                      // Type check
82     Control,                    // Control of code (not in lattice)
83     Top,                        // Top of the lattice
84     Int,                        // Integer range (lo-hi)
85     Long,                       // Long integer range (lo-hi)
86     Half,                       // Placeholder half of doubleword
87     NarrowOop,                  // Compressed oop pointer
88     NarrowKlass,                // Compressed klass pointer
89 
90     Tuple,                      // Method signature or object layout
91     Array,                      // Array types
92     VectorA,                    // (Scalable) Vector types for vector length agnostic
93     VectorS,                    //  32bit Vector types
94     VectorD,                    //  64bit Vector types
95     VectorX,                    // 128bit Vector types
96     VectorY,                    // 256bit Vector types
97     VectorZ,                    // 512bit Vector types
98 
99     AnyPtr,                     // Any old raw, klass, inst, or array pointer
100     RawPtr,                     // Raw (non-oop) pointers
101     OopPtr,                     // Any and all Java heap entities
102     InstPtr,                    // Instance pointers (non-array objects)
103     AryPtr,                     // Array pointers
104     // (Ptr order matters:  See is_ptr, isa_ptr, is_oopptr, isa_oopptr.)
105 
106     MetadataPtr,                // Generic metadata
107     KlassPtr,                   // Klass pointers
108 
109     Function,                   // Function signature
110     Abio,                       // Abstract I/O
111     Return_Address,             // Subroutine return address
112     Memory,                     // Abstract store
113     FloatTop,                   // No float value
114     FloatCon,                   // Floating point constant
115     FloatBot,                   // Any float value
116     DoubleTop,                  // No double value
117     DoubleCon,                  // Double precision constant
118     DoubleBot,                  // Any double value
119     Bottom,                     // Bottom of lattice
120     lastype                     // Bogus ending type (not in lattice)
121   };
122 
123   // Signal values for offsets from a base pointer
124   enum OFFSET_SIGNALS {
125     OffsetTop = -2000000000,    // undefined offset
126     OffsetBot = -2000000001     // any possible offset
127   };
128 
129   // Min and max WIDEN values.
130   enum WIDEN {
131     WidenMin = 0,
132     WidenMax = 3
133   };
134 
135 private:
136   typedef struct {
137     TYPES                dual_type;
138     BasicType            basic_type;
139     const char*          msg;
140     bool                 isa_oop;
141     uint                 ideal_reg;
142     relocInfo::relocType reloc;
143   } TypeInfo;
144 
145   // Dictionary of types shared among compilations.
146   static Dict* _shared_type_dict;
147   static const TypeInfo _type_info[];
148 
149   static int uhash( const Type *const t );
150   // Structural equality check.  Assumes that cmp() has already compared
151   // the _base types and thus knows it can cast 't' appropriately.
152   virtual bool eq( const Type *t ) const;
153 
154   // Top-level hash-table of types
type_dict()155   static Dict *type_dict() {
156     return Compile::current()->type_dict();
157   }
158 
159   // DUAL operation: reflect around lattice centerline.  Used instead of
160   // join to ensure my lattice is symmetric up and down.  Dual is computed
161   // lazily, on demand, and cached in _dual.
162   const Type *_dual;            // Cached dual value
163   // Table for efficient dualing of base types
164   static const TYPES dual_type[lastype];
165 
166 #ifdef ASSERT
167   // One type is interface, the other is oop
168   virtual bool interface_vs_oop_helper(const Type *t) const;
169 #endif
170 
171   const Type *meet_helper(const Type *t, bool include_speculative) const;
172   void check_symmetrical(const Type *t, const Type *mt) const;
173 
174 protected:
175   // Each class of type is also identified by its base.
176   const TYPES _base;            // Enum of Types type
177 
Type(TYPES t)178   Type( TYPES t ) : _dual(NULL),  _base(t) {} // Simple types
179   // ~Type();                   // Use fast deallocation
180   const Type *hashcons();       // Hash-cons the type
181   virtual const Type *filter_helper(const Type *kills, bool include_speculative) const;
join_helper(const Type * t,bool include_speculative) const182   const Type *join_helper(const Type *t, bool include_speculative) const {
183     return dual()->meet_helper(t->dual(), include_speculative)->dual();
184   }
185 
186 public:
187 
operator new(size_t x)188   inline void* operator new( size_t x ) throw() {
189     Compile* compile = Compile::current();
190     compile->set_type_last_size(x);
191     return compile->type_arena()->Amalloc_D(x);
192   }
operator delete(void * ptr)193   inline void operator delete( void* ptr ) {
194     Compile* compile = Compile::current();
195     compile->type_arena()->Afree(ptr,compile->type_last_size());
196   }
197 
198   // Initialize the type system for a particular compilation.
199   static void Initialize(Compile* compile);
200 
201   // Initialize the types shared by all compilations.
202   static void Initialize_shared(Compile* compile);
203 
base() const204   TYPES base() const {
205     assert(_base > Bad && _base < lastype, "sanity");
206     return _base;
207   }
208 
209   // Create a new hash-consd type
210   static const Type *make(enum TYPES);
211   // Test for equivalence of types
212   static int cmp( const Type *const t1, const Type *const t2 );
213   // Test for higher or equal in lattice
214   // Variant that drops the speculative part of the types
higher_equal(const Type * t) const215   bool higher_equal(const Type *t) const {
216     return !cmp(meet(t),t->remove_speculative());
217   }
218   // Variant that keeps the speculative part of the types
higher_equal_speculative(const Type * t) const219   bool higher_equal_speculative(const Type *t) const {
220     return !cmp(meet_speculative(t),t);
221   }
222 
223   // MEET operation; lower in lattice.
224   // Variant that drops the speculative part of the types
meet(const Type * t) const225   const Type *meet(const Type *t) const {
226     return meet_helper(t, false);
227   }
228   // Variant that keeps the speculative part of the types
meet_speculative(const Type * t) const229   const Type *meet_speculative(const Type *t) const {
230     return meet_helper(t, true)->cleanup_speculative();
231   }
232   // WIDEN: 'widens' for Ints and other range types
widen(const Type * old,const Type * limit) const233   virtual const Type *widen( const Type *old, const Type* limit ) const { return this; }
234   // NARROW: complement for widen, used by pessimistic phases
narrow(const Type * old) const235   virtual const Type *narrow( const Type *old ) const { return this; }
236 
237   // DUAL operation: reflect around lattice centerline.  Used instead of
238   // join to ensure my lattice is symmetric up and down.
dual() const239   const Type *dual() const { return _dual; }
240 
241   // Compute meet dependent on base type
242   virtual const Type *xmeet( const Type *t ) const;
243   virtual const Type *xdual() const;    // Compute dual right now.
244 
245   // JOIN operation; higher in lattice.  Done by finding the dual of the
246   // meet of the dual of the 2 inputs.
247   // Variant that drops the speculative part of the types
join(const Type * t) const248   const Type *join(const Type *t) const {
249     return join_helper(t, false);
250   }
251   // Variant that keeps the speculative part of the types
join_speculative(const Type * t) const252   const Type *join_speculative(const Type *t) const {
253     return join_helper(t, true)->cleanup_speculative();
254   }
255 
256   // Modified version of JOIN adapted to the needs Node::Value.
257   // Normalizes all empty values to TOP.  Does not kill _widen bits.
258   // Currently, it also works around limitations involving interface types.
259   // Variant that drops the speculative part of the types
filter(const Type * kills) const260   const Type *filter(const Type *kills) const {
261     return filter_helper(kills, false);
262   }
263   // Variant that keeps the speculative part of the types
filter_speculative(const Type * kills) const264   const Type *filter_speculative(const Type *kills) const {
265     return filter_helper(kills, true)->cleanup_speculative();
266   }
267 
268 #ifdef ASSERT
269   // One type is interface, the other is oop
270   virtual bool interface_vs_oop(const Type *t) const;
271 #endif
272 
273   // Returns true if this pointer points at memory which contains a
274   // compressed oop references.
275   bool is_ptr_to_narrowoop() const;
276   bool is_ptr_to_narrowklass() const;
277 
278   bool is_ptr_to_boxing_obj() const;
279 
280 
281   // Convenience access
282   float getf() const;
283   double getd() const;
284 
285   const TypeInt    *is_int() const;
286   const TypeInt    *isa_int() const;             // Returns NULL if not an Int
287   const TypeInteger* is_integer(BasicType bt) const;
288   const TypeInteger* isa_integer(BasicType bt) const;
289   const TypeLong   *is_long() const;
290   const TypeLong   *isa_long() const;            // Returns NULL if not a Long
291   const TypeD      *isa_double() const;          // Returns NULL if not a Double{Top,Con,Bot}
292   const TypeD      *is_double_constant() const;  // Asserts it is a DoubleCon
293   const TypeD      *isa_double_constant() const; // Returns NULL if not a DoubleCon
294   const TypeF      *isa_float() const;           // Returns NULL if not a Float{Top,Con,Bot}
295   const TypeF      *is_float_constant() const;   // Asserts it is a FloatCon
296   const TypeF      *isa_float_constant() const;  // Returns NULL if not a FloatCon
297   const TypeTuple  *is_tuple() const;            // Collection of fields, NOT a pointer
298   const TypeAry    *is_ary() const;              // Array, NOT array pointer
299   const TypeAry    *isa_ary() const;             // Returns NULL of not ary
300   const TypeVect   *is_vect() const;             // Vector
301   const TypeVect   *isa_vect() const;            // Returns NULL if not a Vector
302   const TypePtr    *is_ptr() const;              // Asserts it is a ptr type
303   const TypePtr    *isa_ptr() const;             // Returns NULL if not ptr type
304   const TypeRawPtr *isa_rawptr() const;          // NOT Java oop
305   const TypeRawPtr *is_rawptr() const;           // Asserts is rawptr
306   const TypeNarrowOop  *is_narrowoop() const;    // Java-style GC'd pointer
307   const TypeNarrowOop  *isa_narrowoop() const;   // Returns NULL if not oop ptr type
308   const TypeNarrowKlass *is_narrowklass() const; // compressed klass pointer
309   const TypeNarrowKlass *isa_narrowklass() const;// Returns NULL if not oop ptr type
310   const TypeOopPtr   *isa_oopptr() const;        // Returns NULL if not oop ptr type
311   const TypeOopPtr   *is_oopptr() const;         // Java-style GC'd pointer
312   const TypeInstPtr  *isa_instptr() const;       // Returns NULL if not InstPtr
313   const TypeInstPtr  *is_instptr() const;        // Instance
314   const TypeAryPtr   *isa_aryptr() const;        // Returns NULL if not AryPtr
315   const TypeAryPtr   *is_aryptr() const;         // Array oop
316 
317   const TypeMetadataPtr   *isa_metadataptr() const;   // Returns NULL if not oop ptr type
318   const TypeMetadataPtr   *is_metadataptr() const;    // Java-style GC'd pointer
319   const TypeKlassPtr      *isa_klassptr() const;      // Returns NULL if not KlassPtr
320   const TypeKlassPtr      *is_klassptr() const;       // assert if not KlassPtr
321 
322   virtual bool      is_finite() const;           // Has a finite value
323   virtual bool      is_nan()    const;           // Is not a number (NaN)
324 
325   // Returns this ptr type or the equivalent ptr type for this compressed pointer.
326   const TypePtr* make_ptr() const;
327 
328   // Returns this oopptr type or the equivalent oopptr type for this compressed pointer.
329   // Asserts if the underlying type is not an oopptr or narrowoop.
330   const TypeOopPtr* make_oopptr() const;
331 
332   // Returns this compressed pointer or the equivalent compressed version
333   // of this pointer type.
334   const TypeNarrowOop* make_narrowoop() const;
335 
336   // Returns this compressed klass pointer or the equivalent
337   // compressed version of this pointer type.
338   const TypeNarrowKlass* make_narrowklass() const;
339 
340   // Special test for register pressure heuristic
341   bool is_floatingpoint() const;        // True if Float or Double base type
342 
343   // Do you have memory, directly or through a tuple?
344   bool has_memory( ) const;
345 
346   // TRUE if type is a singleton
347   virtual bool singleton(void) const;
348 
349   // TRUE if type is above the lattice centerline, and is therefore vacuous
350   virtual bool empty(void) const;
351 
352   // Return a hash for this type.  The hash function is public so ConNode
353   // (constants) can hash on their constant, which is represented by a Type.
354   virtual int hash() const;
355 
356   // Map ideal registers (machine types) to ideal types
357   static const Type *mreg2type[];
358 
359   // Printing, statistics
360 #ifndef PRODUCT
361   void         dump_on(outputStream *st) const;
dump() const362   void         dump() const {
363     dump_on(tty);
364   }
365   virtual void dump2( Dict &d, uint depth, outputStream *st ) const;
366   static  void dump_stats();
367 
368   static const char* str(const Type* t);
369 #endif
370   void typerr(const Type *t) const; // Mixing types error
371 
372   // Create basic type
get_const_basic_type(BasicType type)373   static const Type* get_const_basic_type(BasicType type) {
374     assert((uint)type <= T_CONFLICT && _const_basic_type[type] != NULL, "bad type");
375     return _const_basic_type[type];
376   }
377 
378   // For two instance arrays of same dimension, return the base element types.
379   // Otherwise or if the arrays have different dimensions, return NULL.
380   static void get_arrays_base_elements(const Type *a1, const Type *a2,
381                                        const TypeInstPtr **e1, const TypeInstPtr **e2);
382 
383   // Mapping to the array element's basic type.
384   BasicType array_element_basic_type() const;
385 
386   // Create standard type for a ciType:
387   static const Type* get_const_type(ciType* type);
388 
389   // Create standard zero value:
get_zero_type(BasicType type)390   static const Type* get_zero_type(BasicType type) {
391     assert((uint)type <= T_CONFLICT && _zero_type[type] != NULL, "bad type");
392     return _zero_type[type];
393   }
394 
395   // Report if this is a zero value (not top).
is_zero_type() const396   bool is_zero_type() const {
397     BasicType type = basic_type();
398     if (type == T_VOID || type >= T_CONFLICT)
399       return false;
400     else
401       return (this == _zero_type[type]);
402   }
403 
404   // Convenience common pre-built types.
405   static const Type *ABIO;
406   static const Type *BOTTOM;
407   static const Type *CONTROL;
408   static const Type *DOUBLE;
409   static const Type *FLOAT;
410   static const Type *HALF;
411   static const Type *MEMORY;
412   static const Type *MULTI;
413   static const Type *RETURN_ADDRESS;
414   static const Type *TOP;
415 
416   // Mapping from compiler type to VM BasicType
basic_type() const417   BasicType basic_type() const       { return _type_info[_base].basic_type; }
ideal_reg() const418   uint ideal_reg() const             { return _type_info[_base].ideal_reg; }
msg() const419   const char* msg() const            { return _type_info[_base].msg; }
isa_oop_ptr() const420   bool isa_oop_ptr() const           { return _type_info[_base].isa_oop; }
reloc() const421   relocInfo::relocType reloc() const { return _type_info[_base].reloc; }
422 
423   // Mapping from CI type system to compiler type:
424   static const Type* get_typeflow_type(ciType* type);
425 
426   static const Type* make_from_constant(ciConstant constant,
427                                         bool require_constant = false,
428                                         int stable_dimension = 0,
429                                         bool is_narrow = false,
430                                         bool is_autobox_cache = false);
431 
432   static const Type* make_constant_from_field(ciInstance* holder,
433                                               int off,
434                                               bool is_unsigned_load,
435                                               BasicType loadbt);
436 
437   static const Type* make_constant_from_field(ciField* field,
438                                               ciInstance* holder,
439                                               BasicType loadbt,
440                                               bool is_unsigned_load);
441 
442   static const Type* make_constant_from_array_element(ciArray* array,
443                                                       int off,
444                                                       int stable_dimension,
445                                                       BasicType loadbt,
446                                                       bool is_unsigned_load);
447 
448   // Speculative type helper methods. See TypePtr.
speculative() const449   virtual const TypePtr* speculative() const                                  { return NULL; }
speculative_type() const450   virtual ciKlass* speculative_type() const                                   { return NULL; }
speculative_type_not_null() const451   virtual ciKlass* speculative_type_not_null() const                          { return NULL; }
speculative_maybe_null() const452   virtual bool speculative_maybe_null() const                                 { return true; }
speculative_always_null() const453   virtual bool speculative_always_null() const                                { return true; }
remove_speculative() const454   virtual const Type* remove_speculative() const                              { return this; }
cleanup_speculative() const455   virtual const Type* cleanup_speculative() const                             { return this; }
would_improve_type(ciKlass * exact_kls,int inline_depth) const456   virtual bool would_improve_type(ciKlass* exact_kls, int inline_depth) const { return exact_kls != NULL; }
would_improve_ptr(ProfilePtrKind ptr_kind) const457   virtual bool would_improve_ptr(ProfilePtrKind ptr_kind) const { return ptr_kind == ProfileAlwaysNull || ptr_kind == ProfileNeverNull; }
458   const Type* maybe_remove_speculative(bool include_speculative) const;
459 
maybe_null() const460   virtual bool maybe_null() const { return true; }
is_known_instance() const461   virtual bool is_known_instance() const { return false; }
462 
463 private:
464   // support arrays
465   static const Type*        _zero_type[T_CONFLICT+1];
466   static const Type* _const_basic_type[T_CONFLICT+1];
467 };
468 
469 //------------------------------TypeF------------------------------------------
470 // Class of Float-Constant Types.
471 class TypeF : public Type {
TypeF(float f)472   TypeF( float f ) : Type(FloatCon), _f(f) {};
473 public:
474   virtual bool eq( const Type *t ) const;
475   virtual int  hash() const;             // Type specific hashing
476   virtual bool singleton(void) const;    // TRUE if type is a singleton
477   virtual bool empty(void) const;        // TRUE if type is vacuous
478 public:
479   const float _f;               // Float constant
480 
481   static const TypeF *make(float f);
482 
483   virtual bool        is_finite() const;  // Has a finite value
484   virtual bool        is_nan()    const;  // Is not a number (NaN)
485 
486   virtual const Type *xmeet( const Type *t ) const;
487   virtual const Type *xdual() const;    // Compute dual right now.
488   // Convenience common pre-built types.
489   static const TypeF *MAX;
490   static const TypeF *MIN;
491   static const TypeF *ZERO; // positive zero only
492   static const TypeF *ONE;
493   static const TypeF *POS_INF;
494   static const TypeF *NEG_INF;
495 #ifndef PRODUCT
496   virtual void dump2( Dict &d, uint depth, outputStream *st ) const;
497 #endif
498 };
499 
500 //------------------------------TypeD------------------------------------------
501 // Class of Double-Constant Types.
502 class TypeD : public Type {
TypeD(double d)503   TypeD( double d ) : Type(DoubleCon), _d(d) {};
504 public:
505   virtual bool eq( const Type *t ) const;
506   virtual int  hash() const;             // Type specific hashing
507   virtual bool singleton(void) const;    // TRUE if type is a singleton
508   virtual bool empty(void) const;        // TRUE if type is vacuous
509 public:
510   const double _d;              // Double constant
511 
512   static const TypeD *make(double d);
513 
514   virtual bool        is_finite() const;  // Has a finite value
515   virtual bool        is_nan()    const;  // Is not a number (NaN)
516 
517   virtual const Type *xmeet( const Type *t ) const;
518   virtual const Type *xdual() const;    // Compute dual right now.
519   // Convenience common pre-built types.
520   static const TypeD *MAX;
521   static const TypeD *MIN;
522   static const TypeD *ZERO; // positive zero only
523   static const TypeD *ONE;
524   static const TypeD *POS_INF;
525   static const TypeD *NEG_INF;
526 #ifndef PRODUCT
527   virtual void dump2( Dict &d, uint depth, outputStream *st ) const;
528 #endif
529 };
530 
531 class TypeInteger : public Type {
532 protected:
TypeInteger(TYPES t)533   TypeInteger(TYPES t) : Type(t) {}
534 
535 public:
536   virtual jlong hi_as_long() const = 0;
537   virtual jlong lo_as_long() const = 0;
538   jlong get_con_as_long(BasicType bt) const;
539 
540   static const TypeInteger* make(jlong lo, jlong hi, int w, BasicType bt);
541 
542   static const TypeInteger* bottom(BasicType type);
543 };
544 
545 
546 
547 //------------------------------TypeInt----------------------------------------
548 // Class of integer ranges, the set of integers between a lower bound and an
549 // upper bound, inclusive.
550 class TypeInt : public TypeInteger {
551   TypeInt( jint lo, jint hi, int w );
552 protected:
553   virtual const Type *filter_helper(const Type *kills, bool include_speculative) const;
554 
555 public:
556   typedef jint NativeType;
557   virtual bool eq( const Type *t ) const;
558   virtual int  hash() const;             // Type specific hashing
559   virtual bool singleton(void) const;    // TRUE if type is a singleton
560   virtual bool empty(void) const;        // TRUE if type is vacuous
561   const jint _lo, _hi;          // Lower bound, upper bound
562   const short _widen;           // Limit on times we widen this sucker
563 
564   static const TypeInt *make(jint lo);
565   // must always specify w
566   static const TypeInt *make(jint lo, jint hi, int w);
567 
568   // Check for single integer
is_con() const569   int is_con() const { return _lo==_hi; }
is_con(int i) const570   bool is_con(int i) const { return is_con() && _lo == i; }
get_con() const571   jint get_con() const { assert( is_con(), "" );  return _lo; }
572 
573   virtual bool        is_finite() const;  // Has a finite value
574 
575   virtual const Type *xmeet( const Type *t ) const;
576   virtual const Type *xdual() const;    // Compute dual right now.
577   virtual const Type *widen( const Type *t, const Type* limit_type ) const;
578   virtual const Type *narrow( const Type *t ) const;
579 
hi_as_long() const580   virtual jlong hi_as_long() const { return _hi; }
lo_as_long() const581   virtual jlong lo_as_long() const { return _lo; }
582 
583   // Do not kill _widen bits.
584   // Convenience common pre-built types.
585   static const TypeInt *MAX;
586   static const TypeInt *MIN;
587   static const TypeInt *MINUS_1;
588   static const TypeInt *ZERO;
589   static const TypeInt *ONE;
590   static const TypeInt *BOOL;
591   static const TypeInt *CC;
592   static const TypeInt *CC_LT;  // [-1]  == MINUS_1
593   static const TypeInt *CC_GT;  // [1]   == ONE
594   static const TypeInt *CC_EQ;  // [0]   == ZERO
595   static const TypeInt *CC_LE;  // [-1,0]
596   static const TypeInt *CC_GE;  // [0,1] == BOOL (!)
597   static const TypeInt *BYTE;
598   static const TypeInt *UBYTE;
599   static const TypeInt *CHAR;
600   static const TypeInt *SHORT;
601   static const TypeInt *POS;
602   static const TypeInt *POS1;
603   static const TypeInt *INT;
604   static const TypeInt *SYMINT; // symmetric range [-max_jint..max_jint]
605   static const TypeInt *TYPE_DOMAIN; // alias for TypeInt::INT
606 
as_self(const Type * t)607   static const TypeInt *as_self(const Type *t) { return t->is_int(); }
608 #ifndef PRODUCT
609   virtual void dump2( Dict &d, uint depth, outputStream *st ) const;
610 #endif
611 };
612 
613 
614 //------------------------------TypeLong---------------------------------------
615 // Class of long integer ranges, the set of integers between a lower bound and
616 // an upper bound, inclusive.
617 class TypeLong : public TypeInteger {
618   TypeLong( jlong lo, jlong hi, int w );
619 protected:
620   // Do not kill _widen bits.
621   virtual const Type *filter_helper(const Type *kills, bool include_speculative) const;
622 public:
623   typedef jlong NativeType;
624   virtual bool eq( const Type *t ) const;
625   virtual int  hash() const;             // Type specific hashing
626   virtual bool singleton(void) const;    // TRUE if type is a singleton
627   virtual bool empty(void) const;        // TRUE if type is vacuous
628 public:
629   const jlong _lo, _hi;         // Lower bound, upper bound
630   const short _widen;           // Limit on times we widen this sucker
631 
632   static const TypeLong *make(jlong lo);
633   // must always specify w
634   static const TypeLong *make(jlong lo, jlong hi, int w);
635 
636   // Check for single integer
is_con() const637   int is_con() const { return _lo==_hi; }
is_con(int i) const638   bool is_con(int i) const { return is_con() && _lo == i; }
get_con() const639   jlong get_con() const { assert( is_con(), "" ); return _lo; }
640 
641   // Check for positive 32-bit value.
is_positive_int() const642   int is_positive_int() const { return _lo >= 0 && _hi <= (jlong)max_jint; }
643 
644   virtual bool        is_finite() const;  // Has a finite value
645 
hi_as_long() const646   virtual jlong hi_as_long() const { return _hi; }
lo_as_long() const647   virtual jlong lo_as_long() const { return _lo; }
648 
649   virtual const Type *xmeet( const Type *t ) const;
650   virtual const Type *xdual() const;    // Compute dual right now.
651   virtual const Type *widen( const Type *t, const Type* limit_type ) const;
652   virtual const Type *narrow( const Type *t ) const;
653   // Convenience common pre-built types.
654   static const TypeLong *MAX;
655   static const TypeLong *MIN;
656   static const TypeLong *MINUS_1;
657   static const TypeLong *ZERO;
658   static const TypeLong *ONE;
659   static const TypeLong *POS;
660   static const TypeLong *LONG;
661   static const TypeLong *INT;    // 32-bit subrange [min_jint..max_jint]
662   static const TypeLong *UINT;   // 32-bit unsigned [0..max_juint]
663   static const TypeLong *TYPE_DOMAIN; // alias for TypeLong::LONG
664 
665   // static convenience methods.
as_self(const Type * t)666   static const TypeLong *as_self(const Type *t) { return t->is_long(); }
667 
668 #ifndef PRODUCT
669   virtual void dump2( Dict &d, uint, outputStream *st  ) const;// Specialized per-Type dumping
670 #endif
671 };
672 
673 //------------------------------TypeTuple--------------------------------------
674 // Class of Tuple Types, essentially type collections for function signatures
675 // and class layouts.  It happens to also be a fast cache for the HotSpot
676 // signature types.
677 class TypeTuple : public Type {
TypeTuple(uint cnt,const Type ** fields)678   TypeTuple( uint cnt, const Type **fields ) : Type(Tuple), _cnt(cnt), _fields(fields) { }
679 
680   const uint          _cnt;              // Count of fields
681   const Type ** const _fields;           // Array of field types
682 
683 public:
684   virtual bool eq( const Type *t ) const;
685   virtual int  hash() const;             // Type specific hashing
686   virtual bool singleton(void) const;    // TRUE if type is a singleton
687   virtual bool empty(void) const;        // TRUE if type is vacuous
688 
689   // Accessors:
cnt() const690   uint cnt() const { return _cnt; }
field_at(uint i) const691   const Type* field_at(uint i) const {
692     assert(i < _cnt, "oob");
693     return _fields[i];
694   }
set_field_at(uint i,const Type * t)695   void set_field_at(uint i, const Type* t) {
696     assert(i < _cnt, "oob");
697     _fields[i] = t;
698   }
699 
700   static const TypeTuple *make( uint cnt, const Type **fields );
701   static const TypeTuple *make_range(ciSignature *sig);
702   static const TypeTuple *make_domain(ciInstanceKlass* recv, ciSignature *sig);
703 
704   // Subroutine call type with space allocated for argument types
705   // Memory for Control, I_O, Memory, FramePtr, and ReturnAdr is allocated implicitly
706   static const Type **fields( uint arg_cnt );
707 
708   virtual const Type *xmeet( const Type *t ) const;
709   virtual const Type *xdual() const;    // Compute dual right now.
710   // Convenience common pre-built types.
711   static const TypeTuple *IFBOTH;
712   static const TypeTuple *IFFALSE;
713   static const TypeTuple *IFTRUE;
714   static const TypeTuple *IFNEITHER;
715   static const TypeTuple *LOOPBODY;
716   static const TypeTuple *MEMBAR;
717   static const TypeTuple *STORECONDITIONAL;
718   static const TypeTuple *START_I2C;
719   static const TypeTuple *INT_PAIR;
720   static const TypeTuple *LONG_PAIR;
721   static const TypeTuple *INT_CC_PAIR;
722   static const TypeTuple *LONG_CC_PAIR;
723 #ifndef PRODUCT
724   virtual void dump2( Dict &d, uint, outputStream *st  ) const; // Specialized per-Type dumping
725 #endif
726 };
727 
728 //------------------------------TypeAry----------------------------------------
729 // Class of Array Types
730 class TypeAry : public Type {
TypeAry(const Type * elem,const TypeInt * size,bool stable)731   TypeAry(const Type* elem, const TypeInt* size, bool stable) : Type(Array),
732       _elem(elem), _size(size), _stable(stable) {}
733 public:
734   virtual bool eq( const Type *t ) const;
735   virtual int  hash() const;             // Type specific hashing
736   virtual bool singleton(void) const;    // TRUE if type is a singleton
737   virtual bool empty(void) const;        // TRUE if type is vacuous
738 
739 private:
740   const Type *_elem;            // Element type of array
741   const TypeInt *_size;         // Elements in array
742   const bool _stable;           // Are elements @Stable?
743   friend class TypeAryPtr;
744 
745 public:
746   static const TypeAry* make(const Type* elem, const TypeInt* size, bool stable = false);
747 
748   virtual const Type *xmeet( const Type *t ) const;
749   virtual const Type *xdual() const;    // Compute dual right now.
750   bool ary_must_be_exact() const;  // true if arrays of such are never generic
751   virtual const Type* remove_speculative() const;
752   virtual const Type* cleanup_speculative() const;
753 #ifdef ASSERT
754   // One type is interface, the other is oop
755   virtual bool interface_vs_oop(const Type *t) const;
756 #endif
757 #ifndef PRODUCT
758   virtual void dump2( Dict &d, uint, outputStream *st  ) const; // Specialized per-Type dumping
759 #endif
760 };
761 
762 //------------------------------TypeVect---------------------------------------
763 // Class of Vector Types
764 class TypeVect : public Type {
765   const Type*   _elem;  // Vector's element type
766   const uint  _length;  // Elements in vector (power of 2)
767 
768 protected:
TypeVect(TYPES t,const Type * elem,uint length)769   TypeVect(TYPES t, const Type* elem, uint length) : Type(t),
770     _elem(elem), _length(length) {}
771 
772 public:
element_type() const773   const Type* element_type() const { return _elem; }
element_basic_type() const774   BasicType element_basic_type() const { return _elem->array_element_basic_type(); }
length() const775   uint length() const { return _length; }
length_in_bytes() const776   uint length_in_bytes() const {
777    return _length * type2aelembytes(element_basic_type());
778   }
779 
780   virtual bool eq(const Type *t) const;
781   virtual int  hash() const;             // Type specific hashing
782   virtual bool singleton(void) const;    // TRUE if type is a singleton
783   virtual bool empty(void) const;        // TRUE if type is vacuous
784 
make(const BasicType elem_bt,uint length)785   static const TypeVect *make(const BasicType elem_bt, uint length) {
786     // Use bottom primitive type.
787     return make(get_const_basic_type(elem_bt), length);
788   }
789   // Used directly by Replicate nodes to construct singleton vector.
790   static const TypeVect *make(const Type* elem, uint length);
791 
792   virtual const Type *xmeet( const Type *t) const;
793   virtual const Type *xdual() const;     // Compute dual right now.
794 
795   static const TypeVect *VECTA;
796   static const TypeVect *VECTS;
797   static const TypeVect *VECTD;
798   static const TypeVect *VECTX;
799   static const TypeVect *VECTY;
800   static const TypeVect *VECTZ;
801 
802 #ifndef PRODUCT
803   virtual void dump2(Dict &d, uint, outputStream *st) const; // Specialized per-Type dumping
804 #endif
805 };
806 
807 class TypeVectA : public TypeVect {
808   friend class TypeVect;
TypeVectA(const Type * elem,uint length)809   TypeVectA(const Type* elem, uint length) : TypeVect(VectorA, elem, length) {}
810 };
811 
812 class TypeVectS : public TypeVect {
813   friend class TypeVect;
TypeVectS(const Type * elem,uint length)814   TypeVectS(const Type* elem, uint length) : TypeVect(VectorS, elem, length) {}
815 };
816 
817 class TypeVectD : public TypeVect {
818   friend class TypeVect;
TypeVectD(const Type * elem,uint length)819   TypeVectD(const Type* elem, uint length) : TypeVect(VectorD, elem, length) {}
820 };
821 
822 class TypeVectX : public TypeVect {
823   friend class TypeVect;
TypeVectX(const Type * elem,uint length)824   TypeVectX(const Type* elem, uint length) : TypeVect(VectorX, elem, length) {}
825 };
826 
827 class TypeVectY : public TypeVect {
828   friend class TypeVect;
TypeVectY(const Type * elem,uint length)829   TypeVectY(const Type* elem, uint length) : TypeVect(VectorY, elem, length) {}
830 };
831 
832 class TypeVectZ : public TypeVect {
833   friend class TypeVect;
TypeVectZ(const Type * elem,uint length)834   TypeVectZ(const Type* elem, uint length) : TypeVect(VectorZ, elem, length) {}
835 };
836 
837 //------------------------------TypePtr----------------------------------------
838 // Class of machine Pointer Types: raw data, instances or arrays.
839 // If the _base enum is AnyPtr, then this refers to all of the above.
840 // Otherwise the _base will indicate which subset of pointers is affected,
841 // and the class will be inherited from.
842 class TypePtr : public Type {
843   friend class TypeNarrowPtr;
844 public:
845   enum PTR { TopPTR, AnyNull, Constant, Null, NotNull, BotPTR, lastPTR };
846 protected:
TypePtr(TYPES t,PTR ptr,int offset,const TypePtr * speculative=NULL,int inline_depth=InlineDepthBottom)847   TypePtr(TYPES t, PTR ptr, int offset,
848           const TypePtr* speculative = NULL,
849           int inline_depth = InlineDepthBottom) :
850     Type(t), _speculative(speculative), _inline_depth(inline_depth), _offset(offset),
851     _ptr(ptr) {}
852   static const PTR ptr_meet[lastPTR][lastPTR];
853   static const PTR ptr_dual[lastPTR];
854   static const char * const ptr_msg[lastPTR];
855 
856   enum {
857     InlineDepthBottom = INT_MAX,
858     InlineDepthTop = -InlineDepthBottom
859   };
860 
861   // Extra type information profiling gave us. We propagate it the
862   // same way the rest of the type info is propagated. If we want to
863   // use it, then we have to emit a guard: this part of the type is
864   // not something we know but something we speculate about the type.
865   const TypePtr*   _speculative;
866   // For speculative types, we record at what inlining depth the
867   // profiling point that provided the data is. We want to favor
868   // profile data coming from outer scopes which are likely better for
869   // the current compilation.
870   int _inline_depth;
871 
872   // utility methods to work on the speculative part of the type
873   const TypePtr* dual_speculative() const;
874   const TypePtr* xmeet_speculative(const TypePtr* other) const;
875   bool eq_speculative(const TypePtr* other) const;
876   int hash_speculative() const;
877   const TypePtr* add_offset_speculative(intptr_t offset) const;
878 #ifndef PRODUCT
879   void dump_speculative(outputStream *st) const;
880 #endif
881 
882   // utility methods to work on the inline depth of the type
883   int dual_inline_depth() const;
884   int meet_inline_depth(int depth) const;
885 #ifndef PRODUCT
886   void dump_inline_depth(outputStream *st) const;
887 #endif
888 
889 public:
890   const int _offset;            // Offset into oop, with TOP & BOT
891   const PTR _ptr;               // Pointer equivalence class
892 
offset() const893   const int offset() const { return _offset; }
ptr() const894   const PTR ptr()    const { return _ptr; }
895 
896   static const TypePtr *make(TYPES t, PTR ptr, int offset,
897                              const TypePtr* speculative = NULL,
898                              int inline_depth = InlineDepthBottom);
899 
900   // Return a 'ptr' version of this type
901   virtual const Type *cast_to_ptr_type(PTR ptr) const;
902 
903   virtual intptr_t get_con() const;
904 
905   int xadd_offset( intptr_t offset ) const;
906   virtual const TypePtr *add_offset( intptr_t offset ) const;
907   virtual bool eq(const Type *t) const;
908   virtual int  hash() const;             // Type specific hashing
909 
910   virtual bool singleton(void) const;    // TRUE if type is a singleton
911   virtual bool empty(void) const;        // TRUE if type is vacuous
912   virtual const Type *xmeet( const Type *t ) const;
913   virtual const Type *xmeet_helper( const Type *t ) const;
914   int meet_offset( int offset ) const;
915   int dual_offset( ) const;
916   virtual const Type *xdual() const;    // Compute dual right now.
917 
918   // meet, dual and join over pointer equivalence sets
meet_ptr(const PTR in_ptr) const919   PTR meet_ptr( const PTR in_ptr ) const { return ptr_meet[in_ptr][ptr()]; }
dual_ptr() const920   PTR dual_ptr()                   const { return ptr_dual[ptr()];      }
921 
922   // This is textually confusing unless one recalls that
923   // join(t) == dual()->meet(t->dual())->dual().
join_ptr(const PTR in_ptr) const924   PTR join_ptr( const PTR in_ptr ) const {
925     return ptr_dual[ ptr_meet[ ptr_dual[in_ptr] ] [ dual_ptr() ] ];
926   }
927 
928   // Speculative type helper methods.
speculative() const929   virtual const TypePtr* speculative() const { return _speculative; }
inline_depth() const930   int inline_depth() const                   { return _inline_depth; }
931   virtual ciKlass* speculative_type() const;
932   virtual ciKlass* speculative_type_not_null() const;
933   virtual bool speculative_maybe_null() const;
934   virtual bool speculative_always_null() const;
935   virtual const Type* remove_speculative() const;
936   virtual const Type* cleanup_speculative() const;
937   virtual bool would_improve_type(ciKlass* exact_kls, int inline_depth) const;
938   virtual bool would_improve_ptr(ProfilePtrKind maybe_null) const;
939   virtual const TypePtr* with_inline_depth(int depth) const;
940 
maybe_null() const941   virtual bool maybe_null() const { return meet_ptr(Null) == ptr(); }
942 
943   // Tests for relation to centerline of type lattice:
above_centerline(PTR ptr)944   static bool above_centerline(PTR ptr) { return (ptr <= AnyNull); }
below_centerline(PTR ptr)945   static bool below_centerline(PTR ptr) { return (ptr >= NotNull); }
946   // Convenience common pre-built types.
947   static const TypePtr *NULL_PTR;
948   static const TypePtr *NOTNULL;
949   static const TypePtr *BOTTOM;
950 #ifndef PRODUCT
951   virtual void dump2( Dict &d, uint depth, outputStream *st  ) const;
952 #endif
953 };
954 
955 //------------------------------TypeRawPtr-------------------------------------
956 // Class of raw pointers, pointers to things other than Oops.  Examples
957 // include the stack pointer, top of heap, card-marking area, handles, etc.
958 class TypeRawPtr : public TypePtr {
959 protected:
TypeRawPtr(PTR ptr,address bits)960   TypeRawPtr( PTR ptr, address bits ) : TypePtr(RawPtr,ptr,0), _bits(bits){}
961 public:
962   virtual bool eq( const Type *t ) const;
963   virtual int  hash() const;     // Type specific hashing
964 
965   const address _bits;          // Constant value, if applicable
966 
967   static const TypeRawPtr *make( PTR ptr );
968   static const TypeRawPtr *make( address bits );
969 
970   // Return a 'ptr' version of this type
971   virtual const Type *cast_to_ptr_type(PTR ptr) const;
972 
973   virtual intptr_t get_con() const;
974 
975   virtual const TypePtr *add_offset( intptr_t offset ) const;
976 
977   virtual const Type *xmeet( const Type *t ) const;
978   virtual const Type *xdual() const;    // Compute dual right now.
979   // Convenience common pre-built types.
980   static const TypeRawPtr *BOTTOM;
981   static const TypeRawPtr *NOTNULL;
982 #ifndef PRODUCT
983   virtual void dump2( Dict &d, uint depth, outputStream *st  ) const;
984 #endif
985 };
986 
987 //------------------------------TypeOopPtr-------------------------------------
988 // Some kind of oop (Java pointer), either instance or array.
989 class TypeOopPtr : public TypePtr {
990 protected:
991   TypeOopPtr(TYPES t, PTR ptr, ciKlass* k, bool xk, ciObject* o, int offset, int instance_id,
992              const TypePtr* speculative, int inline_depth);
993 public:
994   virtual bool eq( const Type *t ) const;
995   virtual int  hash() const;             // Type specific hashing
996   virtual bool singleton(void) const;    // TRUE if type is a singleton
997   enum {
998    InstanceTop = -1,   // undefined instance
999    InstanceBot = 0     // any possible instance
1000   };
1001 protected:
1002 
1003   // Oop is NULL, unless this is a constant oop.
1004   ciObject*     _const_oop;   // Constant oop
1005   // If _klass is NULL, then so is _sig.  This is an unloaded klass.
1006   ciKlass*      _klass;       // Klass object
1007   // Does the type exclude subclasses of the klass?  (Inexact == polymorphic.)
1008   bool          _klass_is_exact;
1009   bool          _is_ptr_to_narrowoop;
1010   bool          _is_ptr_to_narrowklass;
1011   bool          _is_ptr_to_boxed_value;
1012 
1013   // If not InstanceTop or InstanceBot, indicates that this is
1014   // a particular instance of this type which is distinct.
1015   // This is the node index of the allocation node creating this instance.
1016   int           _instance_id;
1017 
1018   static const TypeOopPtr* make_from_klass_common(ciKlass* klass, bool klass_change, bool try_for_exact);
1019 
1020   int dual_instance_id() const;
1021   int meet_instance_id(int uid) const;
1022 
1023   // Do not allow interface-vs.-noninterface joins to collapse to top.
1024   virtual const Type *filter_helper(const Type *kills, bool include_speculative) const;
1025 
1026 public:
1027   // Creates a type given a klass. Correctly handles multi-dimensional arrays
1028   // Respects UseUniqueSubclasses.
1029   // If the klass is final, the resulting type will be exact.
make_from_klass(ciKlass * klass)1030   static const TypeOopPtr* make_from_klass(ciKlass* klass) {
1031     return make_from_klass_common(klass, true, false);
1032   }
1033   // Same as before, but will produce an exact type, even if
1034   // the klass is not final, as long as it has exactly one implementation.
make_from_klass_unique(ciKlass * klass)1035   static const TypeOopPtr* make_from_klass_unique(ciKlass* klass) {
1036     return make_from_klass_common(klass, true, true);
1037   }
1038   // Same as before, but does not respects UseUniqueSubclasses.
1039   // Use this only for creating array element types.
make_from_klass_raw(ciKlass * klass)1040   static const TypeOopPtr* make_from_klass_raw(ciKlass* klass) {
1041     return make_from_klass_common(klass, false, false);
1042   }
1043   // Creates a singleton type given an object.
1044   // If the object cannot be rendered as a constant,
1045   // may return a non-singleton type.
1046   // If require_constant, produce a NULL if a singleton is not possible.
1047   static const TypeOopPtr* make_from_constant(ciObject* o,
1048                                               bool require_constant = false);
1049 
1050   // Make a generic (unclassed) pointer to an oop.
1051   static const TypeOopPtr* make(PTR ptr, int offset, int instance_id,
1052                                 const TypePtr* speculative = NULL,
1053                                 int inline_depth = InlineDepthBottom);
1054 
const_oop() const1055   ciObject* const_oop()    const { return _const_oop; }
klass() const1056   virtual ciKlass* klass() const { return _klass;     }
klass_is_exact() const1057   bool klass_is_exact()    const { return _klass_is_exact; }
1058 
1059   // Returns true if this pointer points at memory which contains a
1060   // compressed oop references.
is_ptr_to_narrowoop_nv() const1061   bool is_ptr_to_narrowoop_nv() const { return _is_ptr_to_narrowoop; }
is_ptr_to_narrowklass_nv() const1062   bool is_ptr_to_narrowklass_nv() const { return _is_ptr_to_narrowklass; }
is_ptr_to_boxed_value() const1063   bool is_ptr_to_boxed_value()   const { return _is_ptr_to_boxed_value; }
is_known_instance() const1064   bool is_known_instance()       const { return _instance_id > 0; }
instance_id() const1065   int  instance_id()             const { return _instance_id; }
is_known_instance_field() const1066   bool is_known_instance_field() const { return is_known_instance() && _offset >= 0; }
1067 
1068   virtual intptr_t get_con() const;
1069 
1070   virtual const Type *cast_to_ptr_type(PTR ptr) const;
1071 
1072   virtual const Type *cast_to_exactness(bool klass_is_exact) const;
1073 
1074   virtual const TypeOopPtr *cast_to_instance_id(int instance_id) const;
1075 
1076   // corresponding pointer to klass, for a given instance
1077   const TypeKlassPtr* as_klass_type() const;
1078 
1079   virtual const TypePtr *add_offset( intptr_t offset ) const;
1080 
1081   // Speculative type helper methods.
1082   virtual const Type* remove_speculative() const;
1083   virtual const Type* cleanup_speculative() const;
1084   virtual bool would_improve_type(ciKlass* exact_kls, int inline_depth) const;
1085   virtual const TypePtr* with_inline_depth(int depth) const;
1086 
1087   virtual const TypePtr* with_instance_id(int instance_id) const;
1088 
1089   virtual const Type *xdual() const;    // Compute dual right now.
1090   // the core of the computation of the meet for TypeOopPtr and for its subclasses
1091   virtual const Type *xmeet_helper(const Type *t) const;
1092 
1093   // Convenience common pre-built type.
1094   static const TypeOopPtr *BOTTOM;
1095 #ifndef PRODUCT
1096   virtual void dump2( Dict &d, uint depth, outputStream *st ) const;
1097 #endif
1098 };
1099 
1100 //------------------------------TypeInstPtr------------------------------------
1101 // Class of Java object pointers, pointing either to non-array Java instances
1102 // or to a Klass* (including array klasses).
1103 class TypeInstPtr : public TypeOopPtr {
1104   TypeInstPtr(PTR ptr, ciKlass* k, bool xk, ciObject* o, int offset, int instance_id,
1105               const TypePtr* speculative, int inline_depth);
1106   virtual bool eq( const Type *t ) const;
1107   virtual int  hash() const;             // Type specific hashing
1108 
1109   ciSymbol*  _name;        // class name
1110 
1111  public:
name() const1112   ciSymbol* name()         const { return _name; }
1113 
is_loaded() const1114   bool  is_loaded() const { return _klass->is_loaded(); }
1115 
1116   // Make a pointer to a constant oop.
make(ciObject * o)1117   static const TypeInstPtr *make(ciObject* o) {
1118     return make(TypePtr::Constant, o->klass(), true, o, 0, InstanceBot);
1119   }
1120   // Make a pointer to a constant oop with offset.
make(ciObject * o,int offset)1121   static const TypeInstPtr *make(ciObject* o, int offset) {
1122     return make(TypePtr::Constant, o->klass(), true, o, offset, InstanceBot);
1123   }
1124 
1125   // Make a pointer to some value of type klass.
make(PTR ptr,ciKlass * klass)1126   static const TypeInstPtr *make(PTR ptr, ciKlass* klass) {
1127     return make(ptr, klass, false, NULL, 0, InstanceBot);
1128   }
1129 
1130   // Make a pointer to some non-polymorphic value of exactly type klass.
make_exact(PTR ptr,ciKlass * klass)1131   static const TypeInstPtr *make_exact(PTR ptr, ciKlass* klass) {
1132     return make(ptr, klass, true, NULL, 0, InstanceBot);
1133   }
1134 
1135   // Make a pointer to some value of type klass with offset.
make(PTR ptr,ciKlass * klass,int offset)1136   static const TypeInstPtr *make(PTR ptr, ciKlass* klass, int offset) {
1137     return make(ptr, klass, false, NULL, offset, InstanceBot);
1138   }
1139 
1140   // Make a pointer to an oop.
1141   static const TypeInstPtr *make(PTR ptr, ciKlass* k, bool xk, ciObject* o, int offset,
1142                                  int instance_id = InstanceBot,
1143                                  const TypePtr* speculative = NULL,
1144                                  int inline_depth = InlineDepthBottom);
1145 
1146   /** Create constant type for a constant boxed value */
1147   const Type* get_const_boxed_value() const;
1148 
1149   // If this is a java.lang.Class constant, return the type for it or NULL.
1150   // Pass to Type::get_const_type to turn it to a type, which will usually
1151   // be a TypeInstPtr, but may also be a TypeInt::INT for int.class, etc.
1152   ciType* java_mirror_type() const;
1153 
1154   virtual const Type *cast_to_ptr_type(PTR ptr) const;
1155 
1156   virtual const Type *cast_to_exactness(bool klass_is_exact) const;
1157 
1158   virtual const TypeOopPtr *cast_to_instance_id(int instance_id) const;
1159 
1160   virtual const TypePtr *add_offset( intptr_t offset ) const;
1161 
1162   // Speculative type helper methods.
1163   virtual const Type* remove_speculative() const;
1164   virtual const TypePtr* with_inline_depth(int depth) const;
1165   virtual const TypePtr* with_instance_id(int instance_id) const;
1166 
1167   // the core of the computation of the meet of 2 types
1168   virtual const Type *xmeet_helper(const Type *t) const;
1169   virtual const TypeInstPtr *xmeet_unloaded( const TypeInstPtr *t ) const;
1170   virtual const Type *xdual() const;    // Compute dual right now.
1171 
1172   // Convenience common pre-built types.
1173   static const TypeInstPtr *NOTNULL;
1174   static const TypeInstPtr *BOTTOM;
1175   static const TypeInstPtr *MIRROR;
1176   static const TypeInstPtr *MARK;
1177   static const TypeInstPtr *KLASS;
1178 #ifndef PRODUCT
1179   virtual void dump2( Dict &d, uint depth, outputStream *st ) const; // Specialized per-Type dumping
1180 #endif
1181 };
1182 
1183 //------------------------------TypeAryPtr-------------------------------------
1184 // Class of Java array pointers
1185 class TypeAryPtr : public TypeOopPtr {
TypeAryPtr(PTR ptr,ciObject * o,const TypeAry * ary,ciKlass * k,bool xk,int offset,int instance_id,bool is_autobox_cache,const TypePtr * speculative,int inline_depth)1186   TypeAryPtr( PTR ptr, ciObject* o, const TypeAry *ary, ciKlass* k, bool xk,
1187               int offset, int instance_id, bool is_autobox_cache,
1188               const TypePtr* speculative, int inline_depth)
1189     : TypeOopPtr(AryPtr,ptr,k,xk,o,offset, instance_id, speculative, inline_depth),
1190     _ary(ary),
1191     _is_autobox_cache(is_autobox_cache)
1192  {
1193 #ifdef ASSERT
1194     if (k != NULL) {
1195       // Verify that specified klass and TypeAryPtr::klass() follow the same rules.
1196       ciKlass* ck = compute_klass(true);
1197       if (k != ck) {
1198         this->dump(); tty->cr();
1199         tty->print(" k: ");
1200         k->print(); tty->cr();
1201         tty->print("ck: ");
1202         if (ck != NULL) ck->print();
1203         else tty->print("<NULL>");
1204         tty->cr();
1205         assert(false, "unexpected TypeAryPtr::_klass");
1206       }
1207     }
1208 #endif
1209   }
1210   virtual bool eq( const Type *t ) const;
1211   virtual int hash() const;     // Type specific hashing
1212   const TypeAry *_ary;          // Array we point into
1213   const bool     _is_autobox_cache;
1214 
1215   ciKlass* compute_klass(DEBUG_ONLY(bool verify = false)) const;
1216 
1217 public:
1218   // Accessors
1219   ciKlass* klass() const;
ary() const1220   const TypeAry* ary() const  { return _ary; }
elem() const1221   const Type*    elem() const { return _ary->_elem; }
size() const1222   const TypeInt* size() const { return _ary->_size; }
is_stable() const1223   bool      is_stable() const { return _ary->_stable; }
1224 
is_autobox_cache() const1225   bool is_autobox_cache() const { return _is_autobox_cache; }
1226 
1227   static const TypeAryPtr *make(PTR ptr, const TypeAry *ary, ciKlass* k, bool xk, int offset,
1228                                 int instance_id = InstanceBot,
1229                                 const TypePtr* speculative = NULL,
1230                                 int inline_depth = InlineDepthBottom);
1231   // Constant pointer to array
1232   static const TypeAryPtr *make(PTR ptr, ciObject* o, const TypeAry *ary, ciKlass* k, bool xk, int offset,
1233                                 int instance_id = InstanceBot,
1234                                 const TypePtr* speculative = NULL,
1235                                 int inline_depth = InlineDepthBottom, bool is_autobox_cache = false);
1236 
1237   // Return a 'ptr' version of this type
1238   virtual const Type *cast_to_ptr_type(PTR ptr) const;
1239 
1240   virtual const Type *cast_to_exactness(bool klass_is_exact) const;
1241 
1242   virtual const TypeOopPtr *cast_to_instance_id(int instance_id) const;
1243 
1244   virtual const TypeAryPtr* cast_to_size(const TypeInt* size) const;
1245   virtual const TypeInt* narrow_size_type(const TypeInt* size) const;
1246 
1247   virtual bool empty(void) const;        // TRUE if type is vacuous
1248   virtual const TypePtr *add_offset( intptr_t offset ) const;
1249 
1250   // Speculative type helper methods.
1251   virtual const Type* remove_speculative() const;
1252   virtual const TypePtr* with_inline_depth(int depth) const;
1253   virtual const TypePtr* with_instance_id(int instance_id) const;
1254 
1255   // the core of the computation of the meet of 2 types
1256   virtual const Type *xmeet_helper(const Type *t) const;
1257   virtual const Type *xdual() const;    // Compute dual right now.
1258 
1259   const TypeAryPtr* cast_to_stable(bool stable, int stable_dimension = 1) const;
1260   int stable_dimension() const;
1261 
1262   const TypeAryPtr* cast_to_autobox_cache() const;
1263 
1264   static jint max_array_length(BasicType etype) ;
1265 
1266   // Convenience common pre-built types.
1267   static const TypeAryPtr *RANGE;
1268   static const TypeAryPtr *OOPS;
1269   static const TypeAryPtr *NARROWOOPS;
1270   static const TypeAryPtr *BYTES;
1271   static const TypeAryPtr *SHORTS;
1272   static const TypeAryPtr *CHARS;
1273   static const TypeAryPtr *INTS;
1274   static const TypeAryPtr *LONGS;
1275   static const TypeAryPtr *FLOATS;
1276   static const TypeAryPtr *DOUBLES;
1277   // selects one of the above:
get_array_body_type(BasicType elem)1278   static const TypeAryPtr *get_array_body_type(BasicType elem) {
1279     assert((uint)elem <= T_CONFLICT && _array_body_type[elem] != NULL, "bad elem type");
1280     return _array_body_type[elem];
1281   }
1282   static const TypeAryPtr *_array_body_type[T_CONFLICT+1];
1283   // sharpen the type of an int which is used as an array size
1284 #ifdef ASSERT
1285   // One type is interface, the other is oop
1286   virtual bool interface_vs_oop(const Type *t) const;
1287 #endif
1288 #ifndef PRODUCT
1289   virtual void dump2( Dict &d, uint depth, outputStream *st ) const; // Specialized per-Type dumping
1290 #endif
1291 };
1292 
1293 //------------------------------TypeMetadataPtr-------------------------------------
1294 // Some kind of metadata, either Method*, MethodData* or CPCacheOop
1295 class TypeMetadataPtr : public TypePtr {
1296 protected:
1297   TypeMetadataPtr(PTR ptr, ciMetadata* metadata, int offset);
1298   // Do not allow interface-vs.-noninterface joins to collapse to top.
1299   virtual const Type *filter_helper(const Type *kills, bool include_speculative) const;
1300 public:
1301   virtual bool eq( const Type *t ) const;
1302   virtual int  hash() const;             // Type specific hashing
1303   virtual bool singleton(void) const;    // TRUE if type is a singleton
1304 
1305 private:
1306   ciMetadata*   _metadata;
1307 
1308 public:
1309   static const TypeMetadataPtr* make(PTR ptr, ciMetadata* m, int offset);
1310 
1311   static const TypeMetadataPtr* make(ciMethod* m);
1312   static const TypeMetadataPtr* make(ciMethodData* m);
1313 
metadata() const1314   ciMetadata* metadata() const { return _metadata; }
1315 
1316   virtual const Type *cast_to_ptr_type(PTR ptr) const;
1317 
1318   virtual const TypePtr *add_offset( intptr_t offset ) const;
1319 
1320   virtual const Type *xmeet( const Type *t ) const;
1321   virtual const Type *xdual() const;    // Compute dual right now.
1322 
1323   virtual intptr_t get_con() const;
1324 
1325   // Convenience common pre-built types.
1326   static const TypeMetadataPtr *BOTTOM;
1327 
1328 #ifndef PRODUCT
1329   virtual void dump2( Dict &d, uint depth, outputStream *st ) const;
1330 #endif
1331 };
1332 
1333 //------------------------------TypeKlassPtr-----------------------------------
1334 // Class of Java Klass pointers
1335 class TypeKlassPtr : public TypePtr {
1336   TypeKlassPtr( PTR ptr, ciKlass* klass, int offset );
1337 
1338 protected:
1339   virtual const Type *filter_helper(const Type *kills, bool include_speculative) const;
1340  public:
1341   virtual bool eq( const Type *t ) const;
1342   virtual int hash() const;             // Type specific hashing
1343   virtual bool singleton(void) const;    // TRUE if type is a singleton
1344  private:
1345 
1346   static const TypeKlassPtr* make_from_klass_common(ciKlass* klass, bool klass_change, bool try_for_exact);
1347 
1348   ciKlass* _klass;
1349 
1350   // Does the type exclude subclasses of the klass?  (Inexact == polymorphic.)
1351   bool          _klass_is_exact;
1352 
1353 public:
name() const1354   ciSymbol* name()  const { return klass()->name(); }
1355 
klass() const1356   ciKlass* klass() const { return  _klass; }
klass_is_exact() const1357   bool klass_is_exact()    const { return _klass_is_exact; }
1358 
is_loaded() const1359   bool  is_loaded() const { return klass()->is_loaded(); }
1360 
1361   // Creates a type given a klass. Correctly handles multi-dimensional arrays
1362   // Respects UseUniqueSubclasses.
1363   // If the klass is final, the resulting type will be exact.
make_from_klass(ciKlass * klass)1364   static const TypeKlassPtr* make_from_klass(ciKlass* klass) {
1365     return make_from_klass_common(klass, true, false);
1366   }
1367   // Same as before, but will produce an exact type, even if
1368   // the klass is not final, as long as it has exactly one implementation.
make_from_klass_unique(ciKlass * klass)1369   static const TypeKlassPtr* make_from_klass_unique(ciKlass* klass) {
1370     return make_from_klass_common(klass, true, true);
1371   }
1372   // Same as before, but does not respects UseUniqueSubclasses.
1373   // Use this only for creating array element types.
make_from_klass_raw(ciKlass * klass)1374   static const TypeKlassPtr* make_from_klass_raw(ciKlass* klass) {
1375     return make_from_klass_common(klass, false, false);
1376   }
1377 
1378   // Make a generic (unclassed) pointer to metadata.
1379   static const TypeKlassPtr* make(PTR ptr, int offset);
1380 
1381   // ptr to klass 'k'
make(ciKlass * k)1382   static const TypeKlassPtr *make( ciKlass* k ) { return make( TypePtr::Constant, k, 0); }
1383   // ptr to klass 'k' with offset
make(ciKlass * k,int offset)1384   static const TypeKlassPtr *make( ciKlass* k, int offset ) { return make( TypePtr::Constant, k, offset); }
1385   // ptr to klass 'k' or sub-klass
1386   static const TypeKlassPtr *make( PTR ptr, ciKlass* k, int offset);
1387 
1388   virtual const Type *cast_to_ptr_type(PTR ptr) const;
1389 
1390   virtual const Type *cast_to_exactness(bool klass_is_exact) const;
1391 
1392   // corresponding pointer to instance, for a given class
1393   const TypeOopPtr* as_instance_type() const;
1394 
1395   virtual const TypePtr *add_offset( intptr_t offset ) const;
1396   virtual const Type    *xmeet( const Type *t ) const;
1397   virtual const Type    *xdual() const;      // Compute dual right now.
1398 
1399   virtual intptr_t get_con() const;
1400 
1401   // Convenience common pre-built types.
1402   static const TypeKlassPtr* OBJECT; // Not-null object klass or below
1403   static const TypeKlassPtr* OBJECT_OR_NULL; // Maybe-null version of same
1404 #ifndef PRODUCT
1405   virtual void dump2( Dict &d, uint depth, outputStream *st ) const; // Specialized per-Type dumping
1406 #endif
1407 };
1408 
1409 class TypeNarrowPtr : public Type {
1410 protected:
1411   const TypePtr* _ptrtype; // Could be TypePtr::NULL_PTR
1412 
TypeNarrowPtr(TYPES t,const TypePtr * ptrtype)1413   TypeNarrowPtr(TYPES t, const TypePtr* ptrtype): Type(t),
1414                                                   _ptrtype(ptrtype) {
1415     assert(ptrtype->offset() == 0 ||
1416            ptrtype->offset() == OffsetBot ||
1417            ptrtype->offset() == OffsetTop, "no real offsets");
1418   }
1419 
1420   virtual const TypeNarrowPtr *isa_same_narrowptr(const Type *t) const = 0;
1421   virtual const TypeNarrowPtr *is_same_narrowptr(const Type *t) const = 0;
1422   virtual const TypeNarrowPtr *make_same_narrowptr(const TypePtr *t) const = 0;
1423   virtual const TypeNarrowPtr *make_hash_same_narrowptr(const TypePtr *t) const = 0;
1424   // Do not allow interface-vs.-noninterface joins to collapse to top.
1425   virtual const Type *filter_helper(const Type *kills, bool include_speculative) const;
1426 public:
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 
1431   virtual const Type *xmeet( const Type *t ) const;
1432   virtual const Type *xdual() const;    // Compute dual right now.
1433 
1434   virtual intptr_t get_con() const;
1435 
1436   virtual bool empty(void) const;        // TRUE if type is vacuous
1437 
1438   // returns the equivalent ptr type for this compressed pointer
get_ptrtype() const1439   const TypePtr *get_ptrtype() const {
1440     return _ptrtype;
1441   }
1442 
is_known_instance() const1443   bool is_known_instance() const {
1444     return _ptrtype->is_known_instance();
1445   }
1446 
1447 #ifndef PRODUCT
1448   virtual void dump2( Dict &d, uint depth, outputStream *st ) const;
1449 #endif
1450 };
1451 
1452 //------------------------------TypeNarrowOop----------------------------------
1453 // A compressed reference to some kind of Oop.  This type wraps around
1454 // a preexisting TypeOopPtr and forwards most of it's operations to
1455 // the underlying type.  It's only real purpose is to track the
1456 // oopness of the compressed oop value when we expose the conversion
1457 // between the normal and the compressed form.
1458 class TypeNarrowOop : public TypeNarrowPtr {
1459 protected:
TypeNarrowOop(const TypePtr * ptrtype)1460   TypeNarrowOop( const TypePtr* ptrtype): TypeNarrowPtr(NarrowOop, ptrtype) {
1461   }
1462 
isa_same_narrowptr(const Type * t) const1463   virtual const TypeNarrowPtr *isa_same_narrowptr(const Type *t) const {
1464     return t->isa_narrowoop();
1465   }
1466 
is_same_narrowptr(const Type * t) const1467   virtual const TypeNarrowPtr *is_same_narrowptr(const Type *t) const {
1468     return t->is_narrowoop();
1469   }
1470 
make_same_narrowptr(const TypePtr * t) const1471   virtual const TypeNarrowPtr *make_same_narrowptr(const TypePtr *t) const {
1472     return new TypeNarrowOop(t);
1473   }
1474 
make_hash_same_narrowptr(const TypePtr * t) const1475   virtual const TypeNarrowPtr *make_hash_same_narrowptr(const TypePtr *t) const {
1476     return (const TypeNarrowPtr*)((new TypeNarrowOop(t))->hashcons());
1477   }
1478 
1479 public:
1480 
1481   static const TypeNarrowOop *make( const TypePtr* type);
1482 
make_from_constant(ciObject * con,bool require_constant=false)1483   static const TypeNarrowOop* make_from_constant(ciObject* con, bool require_constant = false) {
1484     return make(TypeOopPtr::make_from_constant(con, require_constant));
1485   }
1486 
1487   static const TypeNarrowOop *BOTTOM;
1488   static const TypeNarrowOop *NULL_PTR;
1489 
1490   virtual const Type* remove_speculative() const;
1491   virtual const Type* cleanup_speculative() const;
1492 
1493 #ifndef PRODUCT
1494   virtual void dump2( Dict &d, uint depth, outputStream *st ) const;
1495 #endif
1496 };
1497 
1498 //------------------------------TypeNarrowKlass----------------------------------
1499 // A compressed reference to klass pointer.  This type wraps around a
1500 // preexisting TypeKlassPtr and forwards most of it's operations to
1501 // the underlying type.
1502 class TypeNarrowKlass : public TypeNarrowPtr {
1503 protected:
TypeNarrowKlass(const TypePtr * ptrtype)1504   TypeNarrowKlass( const TypePtr* ptrtype): TypeNarrowPtr(NarrowKlass, ptrtype) {
1505   }
1506 
isa_same_narrowptr(const Type * t) const1507   virtual const TypeNarrowPtr *isa_same_narrowptr(const Type *t) const {
1508     return t->isa_narrowklass();
1509   }
1510 
is_same_narrowptr(const Type * t) const1511   virtual const TypeNarrowPtr *is_same_narrowptr(const Type *t) const {
1512     return t->is_narrowklass();
1513   }
1514 
make_same_narrowptr(const TypePtr * t) const1515   virtual const TypeNarrowPtr *make_same_narrowptr(const TypePtr *t) const {
1516     return new TypeNarrowKlass(t);
1517   }
1518 
make_hash_same_narrowptr(const TypePtr * t) const1519   virtual const TypeNarrowPtr *make_hash_same_narrowptr(const TypePtr *t) const {
1520     return (const TypeNarrowPtr*)((new TypeNarrowKlass(t))->hashcons());
1521   }
1522 
1523 public:
1524   static const TypeNarrowKlass *make( const TypePtr* type);
1525 
1526   // static const TypeNarrowKlass *BOTTOM;
1527   static const TypeNarrowKlass *NULL_PTR;
1528 
1529 #ifndef PRODUCT
1530   virtual void dump2( Dict &d, uint depth, outputStream *st ) const;
1531 #endif
1532 };
1533 
1534 //------------------------------TypeFunc---------------------------------------
1535 // Class of Array Types
1536 class TypeFunc : public Type {
TypeFunc(const TypeTuple * domain,const TypeTuple * range)1537   TypeFunc( const TypeTuple *domain, const TypeTuple *range ) : Type(Function),  _domain(domain), _range(range) {}
1538   virtual bool eq( const Type *t ) const;
1539   virtual int  hash() const;             // Type specific hashing
1540   virtual bool singleton(void) const;    // TRUE if type is a singleton
1541   virtual bool empty(void) const;        // TRUE if type is vacuous
1542 
1543   const TypeTuple* const _domain;     // Domain of inputs
1544   const TypeTuple* const _range;      // Range of results
1545 
1546 public:
1547   // Constants are shared among ADLC and VM
1548   enum { Control    = AdlcVMDeps::Control,
1549          I_O        = AdlcVMDeps::I_O,
1550          Memory     = AdlcVMDeps::Memory,
1551          FramePtr   = AdlcVMDeps::FramePtr,
1552          ReturnAdr  = AdlcVMDeps::ReturnAdr,
1553          Parms      = AdlcVMDeps::Parms
1554   };
1555 
1556 
1557   // Accessors:
domain() const1558   const TypeTuple* domain() const { return _domain; }
range() const1559   const TypeTuple* range()  const { return _range; }
1560 
1561   static const TypeFunc *make(ciMethod* method);
1562   static const TypeFunc *make(ciSignature signature, const Type* extra);
1563   static const TypeFunc *make(const TypeTuple* domain, const TypeTuple* range);
1564 
1565   virtual const Type *xmeet( const Type *t ) const;
1566   virtual const Type *xdual() const;    // Compute dual right now.
1567 
1568   BasicType return_type() const;
1569 
1570 #ifndef PRODUCT
1571   virtual void dump2( Dict &d, uint depth, outputStream *st ) const; // Specialized per-Type dumping
1572 #endif
1573   // Convenience common pre-built types.
1574 };
1575 
1576 //------------------------------accessors--------------------------------------
is_ptr_to_narrowoop() const1577 inline bool Type::is_ptr_to_narrowoop() const {
1578 #ifdef _LP64
1579   return (isa_oopptr() != NULL && is_oopptr()->is_ptr_to_narrowoop_nv());
1580 #else
1581   return false;
1582 #endif
1583 }
1584 
is_ptr_to_narrowklass() const1585 inline bool Type::is_ptr_to_narrowklass() const {
1586 #ifdef _LP64
1587   return (isa_oopptr() != NULL && is_oopptr()->is_ptr_to_narrowklass_nv());
1588 #else
1589   return false;
1590 #endif
1591 }
1592 
getf() const1593 inline float Type::getf() const {
1594   assert( _base == FloatCon, "Not a FloatCon" );
1595   return ((TypeF*)this)->_f;
1596 }
1597 
getd() const1598 inline double Type::getd() const {
1599   assert( _base == DoubleCon, "Not a DoubleCon" );
1600   return ((TypeD*)this)->_d;
1601 }
1602 
is_integer(BasicType bt) const1603 inline const TypeInteger *Type::is_integer(BasicType bt) const {
1604   assert((bt == T_INT && _base == Int) || (bt == T_LONG && _base == Long), "Not an Int");
1605   return (TypeInteger*)this;
1606 }
1607 
isa_integer(BasicType bt) const1608 inline const TypeInteger *Type::isa_integer(BasicType bt) const {
1609   return (((bt == T_INT && _base == Int) || (bt == T_LONG && _base == Long)) ? (TypeInteger*)this : NULL);
1610 }
1611 
is_int() const1612 inline const TypeInt *Type::is_int() const {
1613   assert( _base == Int, "Not an Int" );
1614   return (TypeInt*)this;
1615 }
1616 
isa_int() const1617 inline const TypeInt *Type::isa_int() const {
1618   return ( _base == Int ? (TypeInt*)this : NULL);
1619 }
1620 
is_long() const1621 inline const TypeLong *Type::is_long() const {
1622   assert( _base == Long, "Not a Long" );
1623   return (TypeLong*)this;
1624 }
1625 
isa_long() const1626 inline const TypeLong *Type::isa_long() const {
1627   return ( _base == Long ? (TypeLong*)this : NULL);
1628 }
1629 
isa_float() const1630 inline const TypeF *Type::isa_float() const {
1631   return ((_base == FloatTop ||
1632            _base == FloatCon ||
1633            _base == FloatBot) ? (TypeF*)this : NULL);
1634 }
1635 
is_float_constant() const1636 inline const TypeF *Type::is_float_constant() const {
1637   assert( _base == FloatCon, "Not a Float" );
1638   return (TypeF*)this;
1639 }
1640 
isa_float_constant() const1641 inline const TypeF *Type::isa_float_constant() const {
1642   return ( _base == FloatCon ? (TypeF*)this : NULL);
1643 }
1644 
isa_double() const1645 inline const TypeD *Type::isa_double() const {
1646   return ((_base == DoubleTop ||
1647            _base == DoubleCon ||
1648            _base == DoubleBot) ? (TypeD*)this : NULL);
1649 }
1650 
is_double_constant() const1651 inline const TypeD *Type::is_double_constant() const {
1652   assert( _base == DoubleCon, "Not a Double" );
1653   return (TypeD*)this;
1654 }
1655 
isa_double_constant() const1656 inline const TypeD *Type::isa_double_constant() const {
1657   return ( _base == DoubleCon ? (TypeD*)this : NULL);
1658 }
1659 
is_tuple() const1660 inline const TypeTuple *Type::is_tuple() const {
1661   assert( _base == Tuple, "Not a Tuple" );
1662   return (TypeTuple*)this;
1663 }
1664 
is_ary() const1665 inline const TypeAry *Type::is_ary() const {
1666   assert( _base == Array , "Not an Array" );
1667   return (TypeAry*)this;
1668 }
1669 
isa_ary() const1670 inline const TypeAry *Type::isa_ary() const {
1671   return ((_base == Array) ? (TypeAry*)this : NULL);
1672 }
1673 
is_vect() const1674 inline const TypeVect *Type::is_vect() const {
1675   assert( _base >= VectorA && _base <= VectorZ, "Not a Vector" );
1676   return (TypeVect*)this;
1677 }
1678 
isa_vect() const1679 inline const TypeVect *Type::isa_vect() const {
1680   return (_base >= VectorA && _base <= VectorZ) ? (TypeVect*)this : NULL;
1681 }
1682 
is_ptr() const1683 inline const TypePtr *Type::is_ptr() const {
1684   // AnyPtr is the first Ptr and KlassPtr the last, with no non-ptrs between.
1685   assert(_base >= AnyPtr && _base <= KlassPtr, "Not a pointer");
1686   return (TypePtr*)this;
1687 }
1688 
isa_ptr() const1689 inline const TypePtr *Type::isa_ptr() const {
1690   // AnyPtr is the first Ptr and KlassPtr the last, with no non-ptrs between.
1691   return (_base >= AnyPtr && _base <= KlassPtr) ? (TypePtr*)this : NULL;
1692 }
1693 
is_oopptr() const1694 inline const TypeOopPtr *Type::is_oopptr() const {
1695   // OopPtr is the first and KlassPtr the last, with no non-oops between.
1696   assert(_base >= OopPtr && _base <= AryPtr, "Not a Java pointer" ) ;
1697   return (TypeOopPtr*)this;
1698 }
1699 
isa_oopptr() const1700 inline const TypeOopPtr *Type::isa_oopptr() const {
1701   // OopPtr is the first and KlassPtr the last, with no non-oops between.
1702   return (_base >= OopPtr && _base <= AryPtr) ? (TypeOopPtr*)this : NULL;
1703 }
1704 
isa_rawptr() const1705 inline const TypeRawPtr *Type::isa_rawptr() const {
1706   return (_base == RawPtr) ? (TypeRawPtr*)this : NULL;
1707 }
1708 
is_rawptr() const1709 inline const TypeRawPtr *Type::is_rawptr() const {
1710   assert( _base == RawPtr, "Not a raw pointer" );
1711   return (TypeRawPtr*)this;
1712 }
1713 
isa_instptr() const1714 inline const TypeInstPtr *Type::isa_instptr() const {
1715   return (_base == InstPtr) ? (TypeInstPtr*)this : NULL;
1716 }
1717 
is_instptr() const1718 inline const TypeInstPtr *Type::is_instptr() const {
1719   assert( _base == InstPtr, "Not an object pointer" );
1720   return (TypeInstPtr*)this;
1721 }
1722 
isa_aryptr() const1723 inline const TypeAryPtr *Type::isa_aryptr() const {
1724   return (_base == AryPtr) ? (TypeAryPtr*)this : NULL;
1725 }
1726 
is_aryptr() const1727 inline const TypeAryPtr *Type::is_aryptr() const {
1728   assert( _base == AryPtr, "Not an array pointer" );
1729   return (TypeAryPtr*)this;
1730 }
1731 
is_narrowoop() const1732 inline const TypeNarrowOop *Type::is_narrowoop() const {
1733   // OopPtr is the first and KlassPtr the last, with no non-oops between.
1734   assert(_base == NarrowOop, "Not a narrow oop" ) ;
1735   return (TypeNarrowOop*)this;
1736 }
1737 
isa_narrowoop() const1738 inline const TypeNarrowOop *Type::isa_narrowoop() const {
1739   // OopPtr is the first and KlassPtr the last, with no non-oops between.
1740   return (_base == NarrowOop) ? (TypeNarrowOop*)this : NULL;
1741 }
1742 
is_narrowklass() const1743 inline const TypeNarrowKlass *Type::is_narrowklass() const {
1744   assert(_base == NarrowKlass, "Not a narrow oop" ) ;
1745   return (TypeNarrowKlass*)this;
1746 }
1747 
isa_narrowklass() const1748 inline const TypeNarrowKlass *Type::isa_narrowklass() const {
1749   return (_base == NarrowKlass) ? (TypeNarrowKlass*)this : NULL;
1750 }
1751 
is_metadataptr() const1752 inline const TypeMetadataPtr *Type::is_metadataptr() const {
1753   // MetadataPtr is the first and CPCachePtr the last
1754   assert(_base == MetadataPtr, "Not a metadata pointer" ) ;
1755   return (TypeMetadataPtr*)this;
1756 }
1757 
isa_metadataptr() const1758 inline const TypeMetadataPtr *Type::isa_metadataptr() const {
1759   return (_base == MetadataPtr) ? (TypeMetadataPtr*)this : NULL;
1760 }
1761 
isa_klassptr() const1762 inline const TypeKlassPtr *Type::isa_klassptr() const {
1763   return (_base == KlassPtr) ? (TypeKlassPtr*)this : NULL;
1764 }
1765 
is_klassptr() const1766 inline const TypeKlassPtr *Type::is_klassptr() const {
1767   assert( _base == KlassPtr, "Not a klass pointer" );
1768   return (TypeKlassPtr*)this;
1769 }
1770 
make_ptr() const1771 inline const TypePtr* Type::make_ptr() const {
1772   return (_base == NarrowOop) ? is_narrowoop()->get_ptrtype() :
1773                               ((_base == NarrowKlass) ? is_narrowklass()->get_ptrtype() :
1774                                                        isa_ptr());
1775 }
1776 
make_oopptr() const1777 inline const TypeOopPtr* Type::make_oopptr() const {
1778   return (_base == NarrowOop) ? is_narrowoop()->get_ptrtype()->isa_oopptr() : isa_oopptr();
1779 }
1780 
make_narrowoop() const1781 inline const TypeNarrowOop* Type::make_narrowoop() const {
1782   return (_base == NarrowOop) ? is_narrowoop() :
1783                                 (isa_ptr() ? TypeNarrowOop::make(is_ptr()) : NULL);
1784 }
1785 
make_narrowklass() const1786 inline const TypeNarrowKlass* Type::make_narrowklass() const {
1787   return (_base == NarrowKlass) ? is_narrowklass() :
1788                                   (isa_ptr() ? TypeNarrowKlass::make(is_ptr()) : NULL);
1789 }
1790 
is_floatingpoint() const1791 inline bool Type::is_floatingpoint() const {
1792   if( (_base == FloatCon)  || (_base == FloatBot) ||
1793       (_base == DoubleCon) || (_base == DoubleBot) )
1794     return true;
1795   return false;
1796 }
1797 
is_ptr_to_boxing_obj() const1798 inline bool Type::is_ptr_to_boxing_obj() const {
1799   const TypeInstPtr* tp = isa_instptr();
1800   return (tp != NULL) && (tp->offset() == 0) &&
1801          tp->klass()->is_instance_klass()  &&
1802          tp->klass()->as_instance_klass()->is_box_klass();
1803 }
1804 
1805 
1806 // ===============================================================
1807 // Things that need to be 64-bits in the 64-bit build but
1808 // 32-bits in the 32-bit build.  Done this way to get full
1809 // optimization AND strong typing.
1810 #ifdef _LP64
1811 
1812 // For type queries and asserts
1813 #define is_intptr_t  is_long
1814 #define isa_intptr_t isa_long
1815 #define find_intptr_t_type find_long_type
1816 #define find_intptr_t_con  find_long_con
1817 #define TypeX        TypeLong
1818 #define Type_X       Type::Long
1819 #define TypeX_X      TypeLong::LONG
1820 #define TypeX_ZERO   TypeLong::ZERO
1821 // For 'ideal_reg' machine registers
1822 #define Op_RegX      Op_RegL
1823 // For phase->intcon variants
1824 #define MakeConX     longcon
1825 #define ConXNode     ConLNode
1826 // For array index arithmetic
1827 #define MulXNode     MulLNode
1828 #define AndXNode     AndLNode
1829 #define OrXNode      OrLNode
1830 #define CmpXNode     CmpLNode
1831 #define SubXNode     SubLNode
1832 #define LShiftXNode  LShiftLNode
1833 // For object size computation:
1834 #define AddXNode     AddLNode
1835 #define RShiftXNode  RShiftLNode
1836 // For card marks and hashcodes
1837 #define URShiftXNode URShiftLNode
1838 // UseOptoBiasInlining
1839 #define XorXNode     XorLNode
1840 #define StoreXConditionalNode StoreLConditionalNode
1841 #define LoadXNode    LoadLNode
1842 #define StoreXNode   StoreLNode
1843 // Opcodes
1844 #define Op_LShiftX   Op_LShiftL
1845 #define Op_AndX      Op_AndL
1846 #define Op_AddX      Op_AddL
1847 #define Op_SubX      Op_SubL
1848 #define Op_XorX      Op_XorL
1849 #define Op_URShiftX  Op_URShiftL
1850 #define Op_LoadX     Op_LoadL
1851 // conversions
1852 #define ConvI2X(x)   ConvI2L(x)
1853 #define ConvL2X(x)   (x)
1854 #define ConvX2I(x)   ConvL2I(x)
1855 #define ConvX2L(x)   (x)
1856 #define ConvX2UL(x)  (x)
1857 
1858 #else
1859 
1860 // For type queries and asserts
1861 #define is_intptr_t  is_int
1862 #define isa_intptr_t isa_int
1863 #define find_intptr_t_type find_int_type
1864 #define find_intptr_t_con  find_int_con
1865 #define TypeX        TypeInt
1866 #define Type_X       Type::Int
1867 #define TypeX_X      TypeInt::INT
1868 #define TypeX_ZERO   TypeInt::ZERO
1869 // For 'ideal_reg' machine registers
1870 #define Op_RegX      Op_RegI
1871 // For phase->intcon variants
1872 #define MakeConX     intcon
1873 #define ConXNode     ConINode
1874 // For array index arithmetic
1875 #define MulXNode     MulINode
1876 #define AndXNode     AndINode
1877 #define OrXNode      OrINode
1878 #define CmpXNode     CmpINode
1879 #define SubXNode     SubINode
1880 #define LShiftXNode  LShiftINode
1881 // For object size computation:
1882 #define AddXNode     AddINode
1883 #define RShiftXNode  RShiftINode
1884 // For card marks and hashcodes
1885 #define URShiftXNode URShiftINode
1886 // UseOptoBiasInlining
1887 #define XorXNode     XorINode
1888 #define StoreXConditionalNode StoreIConditionalNode
1889 #define LoadXNode    LoadINode
1890 #define StoreXNode   StoreINode
1891 // Opcodes
1892 #define Op_LShiftX   Op_LShiftI
1893 #define Op_AndX      Op_AndI
1894 #define Op_AddX      Op_AddI
1895 #define Op_SubX      Op_SubI
1896 #define Op_XorX      Op_XorI
1897 #define Op_URShiftX  Op_URShiftI
1898 #define Op_LoadX     Op_LoadI
1899 // conversions
1900 #define ConvI2X(x)   (x)
1901 #define ConvL2X(x)   ConvL2I(x)
1902 #define ConvX2I(x)   (x)
1903 #define ConvX2L(x)   ConvI2L(x)
1904 #define ConvX2UL(x)  ConvI2UL(x)
1905 
1906 #endif
1907 
1908 #endif // SHARE_OPTO_TYPE_HPP
1909