1 /*
2  * Copyright (c) 1997, 2018, Oracle and/or its affiliates. All rights reserved.
3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4  *
5  * This code is free software; you can redistribute it and/or modify it
6  * under the terms of the GNU General Public License version 2 only, as
7  * published by the Free Software Foundation.
8  *
9  * This code is distributed in the hope that it will be useful, but WITHOUT
10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
12  * version 2 for more details (a copy is included in the LICENSE file that
13  * accompanied this code).
14  *
15  * You should have received a copy of the GNU General Public License version
16  * 2 along with this work; if not, write to the Free Software Foundation,
17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18  *
19  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20  * or visit www.oracle.com if you need additional information or have any
21  * questions.
22  *
23  */
24 
25 #ifndef SHARE_VM_OPTO_TYPE_HPP
26 #define SHARE_VM_OPTO_TYPE_HPP
27 
28 #include "libadt/port.hpp"
29 #include "opto/adlcVMDeps.hpp"
30 #include "runtime/handles.hpp"
31 
32 // Portions of code courtesy of Clifford Click
33 
34 // Optimization - Graph Style
35 
36 
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.
44 
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;
68 
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;
76 
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
87 
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
94 
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.)
101 
102     MetadataPtr,                // Generic metadata
103     KlassPtr,                   // Klass pointers
104 
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   };
118 
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   };
124 
125   // Min and max WIDEN values.
126   enum WIDEN {
127     WidenMin = 0,
128     WidenMax = 3
129   };
130 
131 private:
132   typedef struct {
133     TYPES                dual_type;
134     BasicType            basic_type;
135     const char*          msg;
136     bool                 isa_oop;
137     uint                 ideal_reg;
138     relocInfo::relocType reloc;
139   } TypeInfo;
140 
141   // Dictionary of types shared among compilations.
142   static Dict* _shared_type_dict;
143   static const TypeInfo _type_info[];
144 
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;
149 
150   // Top-level hash-table of types
type_dict()151   static Dict *type_dict() {
152     return Compile::current()->type_dict();
153   }
154 
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];
161 
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
166 
167   const Type *meet_helper(const Type *t, bool include_speculative) const;
168   void check_symmetrical(const Type *t, const Type *mt) const;
169 
170 protected:
171   // Each class of type is also identified by its base.
172   const TYPES _base;            // Enum of Types type
173 
Type(TYPES t)174   Type( TYPES t ) : _dual(NULL),  _base(t) {} // Simple types
175   // ~Type();                   // Use fast deallocation
176   const Type *hashcons();       // Hash-cons the type
177   virtual const Type *filter_helper(const Type *kills, bool include_speculative) const;
join_helper(const Type * t,bool include_speculative) const178   const Type *join_helper(const Type *t, bool include_speculative) const {
179     return dual()->meet_helper(t->dual(), include_speculative)->dual();
180   }
181 
182 public:
183 
operator new(size_t x)184   inline void* operator new( size_t x ) throw() {
185     Compile* compile = Compile::current();
186     compile->set_type_last_size(x);
187     void *temp = compile->type_arena()->Amalloc_D(x);
188     compile->set_type_hwm(temp);
189     return temp;
190   }
operator delete(void * ptr)191   inline void operator delete( void* ptr ) {
192     Compile* compile = Compile::current();
193     compile->type_arena()->Afree(ptr,compile->type_last_size());
194   }
195 
196   // Initialize the type system for a particular compilation.
197   static void Initialize(Compile* compile);
198 
199   // Initialize the types shared by all compilations.
200   static void Initialize_shared(Compile* compile);
201 
base() const202   TYPES base() const {
203     assert(_base > Bad && _base < lastype, "sanity");
204     return _base;
205   }
206 
207   // Create a new hash-consd type
208   static const Type *make(enum TYPES);
209   // Test for equivalence of types
210   static int cmp( const Type *const t1, const Type *const t2 );
211   // Test for higher or equal in lattice
212   // Variant that drops the speculative part of the types
higher_equal(const Type * t) const213   bool higher_equal(const Type *t) const {
214     return !cmp(meet(t),t->remove_speculative());
215   }
216   // Variant that keeps the speculative part of the types
higher_equal_speculative(const Type * t) const217   bool higher_equal_speculative(const Type *t) const {
218     return !cmp(meet_speculative(t),t);
219   }
220 
221   // MEET operation; lower in lattice.
222   // Variant that drops the speculative part of the types
meet(const Type * t) const223   const Type *meet(const Type *t) const {
224     return meet_helper(t, false);
225   }
226   // Variant that keeps the speculative part of the types
meet_speculative(const Type * t) const227   const Type *meet_speculative(const Type *t) const {
228     return meet_helper(t, true);
229   }
230   // WIDEN: 'widens' for Ints and other range types
widen(const Type * old,const Type * limit) const231   virtual const Type *widen( const Type *old, const Type* limit ) const { return this; }
232   // NARROW: complement for widen, used by pessimistic phases
narrow(const Type * old) const233   virtual const Type *narrow( const Type *old ) const { return this; }
234 
235   // DUAL operation: reflect around lattice centerline.  Used instead of
236   // join to ensure my lattice is symmetric up and down.
dual() const237   const Type *dual() const { return _dual; }
238 
239   // Compute meet dependent on base type
240   virtual const Type *xmeet( const Type *t ) const;
241   virtual const Type *xdual() const;    // Compute dual right now.
242 
243   // JOIN operation; higher in lattice.  Done by finding the dual of the
244   // meet of the dual of the 2 inputs.
245   // Variant that drops the speculative part of the types
join(const Type * t) const246   const Type *join(const Type *t) const {
247     return join_helper(t, false);
248   }
249   // Variant that keeps the speculative part of the types
join_speculative(const Type * t) const250   const Type *join_speculative(const Type *t) const {
251     return join_helper(t, true);
252   }
253 
254   // Modified version of JOIN adapted to the needs Node::Value.
255   // Normalizes all empty values to TOP.  Does not kill _widen bits.
256   // Currently, it also works around limitations involving interface types.
257   // Variant that drops the speculative part of the types
filter(const Type * kills) const258   const Type *filter(const Type *kills) const {
259     return filter_helper(kills, false);
260   }
261   // Variant that keeps the speculative part of the types
filter_speculative(const Type * kills) const262   const Type *filter_speculative(const Type *kills) const {
263     return filter_helper(kills, true);
264   }
265 
266 #ifdef ASSERT
267   // One type is interface, the other is oop
268   virtual bool interface_vs_oop(const Type *t) const;
269 #endif
270 
271   // Returns true if this pointer points at memory which contains a
272   // compressed oop references.
273   bool is_ptr_to_narrowoop() const;
274   bool is_ptr_to_narrowklass() const;
275 
276   bool is_ptr_to_boxing_obj() const;
277 
278 
279   // Convenience access
280   float getf() const;
281   double getd() const;
282 
283   const TypeInt    *is_int() const;
284   const TypeInt    *isa_int() const;             // Returns NULL if not an Int
285   const TypeLong   *is_long() const;
286   const TypeLong   *isa_long() const;            // Returns NULL if not a Long
287   const TypeD      *isa_double() const;          // Returns NULL if not a Double{Top,Con,Bot}
288   const TypeD      *is_double_constant() const;  // Asserts it is a DoubleCon
289   const TypeD      *isa_double_constant() const; // Returns NULL if not a DoubleCon
290   const TypeF      *isa_float() const;           // Returns NULL if not a Float{Top,Con,Bot}
291   const TypeF      *is_float_constant() const;   // Asserts it is a FloatCon
292   const TypeF      *isa_float_constant() const;  // Returns NULL if not a FloatCon
293   const TypeTuple  *is_tuple() const;            // Collection of fields, NOT a pointer
294   const TypeAry    *is_ary() const;              // Array, NOT array pointer
295   const TypeVect   *is_vect() const;             // Vector
296   const TypeVect   *isa_vect() const;            // Returns NULL if not a Vector
297   const TypePtr    *is_ptr() const;              // Asserts it is a ptr type
298   const TypePtr    *isa_ptr() const;             // Returns NULL if not ptr type
299   const TypeRawPtr *isa_rawptr() const;          // NOT Java oop
300   const TypeRawPtr *is_rawptr() const;           // Asserts is rawptr
301   const TypeNarrowOop  *is_narrowoop() const;    // Java-style GC'd pointer
302   const TypeNarrowOop  *isa_narrowoop() const;   // Returns NULL if not oop ptr type
303   const TypeNarrowKlass *is_narrowklass() const; // compressed klass pointer
304   const TypeNarrowKlass *isa_narrowklass() const;// Returns NULL if not oop ptr type
305   const TypeOopPtr   *isa_oopptr() const;        // Returns NULL if not oop ptr type
306   const TypeOopPtr   *is_oopptr() const;         // Java-style GC'd pointer
307   const TypeInstPtr  *isa_instptr() const;       // Returns NULL if not InstPtr
308   const TypeInstPtr  *is_instptr() const;        // Instance
309   const TypeAryPtr   *isa_aryptr() const;        // Returns NULL if not AryPtr
310   const TypeAryPtr   *is_aryptr() const;         // Array oop
311 
312   const TypeMetadataPtr   *isa_metadataptr() const;   // Returns NULL if not oop ptr type
313   const TypeMetadataPtr   *is_metadataptr() const;    // Java-style GC'd pointer
314   const TypeKlassPtr      *isa_klassptr() const;      // Returns NULL if not KlassPtr
315   const TypeKlassPtr      *is_klassptr() const;       // assert if not KlassPtr
316 
317   virtual bool      is_finite() const;           // Has a finite value
318   virtual bool      is_nan()    const;           // Is not a number (NaN)
319 
320   // Returns this ptr type or the equivalent ptr type for this compressed pointer.
321   const TypePtr* make_ptr() const;
322 
323   // Returns this oopptr type or the equivalent oopptr type for this compressed pointer.
324   // Asserts if the underlying type is not an oopptr or narrowoop.
325   const TypeOopPtr* make_oopptr() const;
326 
327   // Returns this compressed pointer or the equivalent compressed version
328   // of this pointer type.
329   const TypeNarrowOop* make_narrowoop() const;
330 
331   // Returns this compressed klass pointer or the equivalent
332   // compressed version of this pointer type.
333   const TypeNarrowKlass* make_narrowklass() const;
334 
335   // Special test for register pressure heuristic
336   bool is_floatingpoint() const;        // True if Float or Double base type
337 
338   // Do you have memory, directly or through a tuple?
339   bool has_memory( ) const;
340 
341   // TRUE if type is a singleton
342   virtual bool singleton(void) const;
343 
344   // TRUE if type is above the lattice centerline, and is therefore vacuous
345   virtual bool empty(void) const;
346 
347   // Return a hash for this type.  The hash function is public so ConNode
348   // (constants) can hash on their constant, which is represented by a Type.
349   virtual int hash() const;
350 
351   // Map ideal registers (machine types) to ideal types
352   static const Type *mreg2type[];
353 
354   // Printing, statistics
355 #ifndef PRODUCT
356   void         dump_on(outputStream *st) const;
dump() const357   void         dump() const {
358     dump_on(tty);
359   }
360   virtual void dump2( Dict &d, uint depth, outputStream *st ) const;
361   static  void dump_stats();
362 
363   static const char* str(const Type* t);
364 #endif
365   void typerr(const Type *t) const; // Mixing types error
366 
367   // Create basic type
get_const_basic_type(BasicType type)368   static const Type* get_const_basic_type(BasicType type) {
369     assert((uint)type <= T_CONFLICT && _const_basic_type[type] != NULL, "bad type");
370     return _const_basic_type[type];
371   }
372 
373   // For two instance arrays of same dimension, return the base element types.
374   // Otherwise or if the arrays have different dimensions, return NULL.
375   static void get_arrays_base_elements(const Type *a1, const Type *a2,
376                                        const TypeInstPtr **e1, const TypeInstPtr **e2);
377 
378   // Mapping to the array element's basic type.
379   BasicType array_element_basic_type() const;
380 
381   // Create standard type for a ciType:
382   static const Type* get_const_type(ciType* type);
383 
384   // Create standard zero value:
get_zero_type(BasicType type)385   static const Type* get_zero_type(BasicType type) {
386     assert((uint)type <= T_CONFLICT && _zero_type[type] != NULL, "bad type");
387     return _zero_type[type];
388   }
389 
390   // Report if this is a zero value (not top).
is_zero_type() const391   bool is_zero_type() const {
392     BasicType type = basic_type();
393     if (type == T_VOID || type >= T_CONFLICT)
394       return false;
395     else
396       return (this == _zero_type[type]);
397   }
398 
399   // Convenience common pre-built types.
400   static const Type *ABIO;
401   static const Type *BOTTOM;
402   static const Type *CONTROL;
403   static const Type *DOUBLE;
404   static const Type *FLOAT;
405   static const Type *HALF;
406   static const Type *MEMORY;
407   static const Type *MULTI;
408   static const Type *RETURN_ADDRESS;
409   static const Type *TOP;
410 
411   // Mapping from compiler type to VM BasicType
basic_type() const412   BasicType basic_type() const       { return _type_info[_base].basic_type; }
ideal_reg() const413   uint ideal_reg() const             { return _type_info[_base].ideal_reg; }
msg() const414   const char* msg() const            { return _type_info[_base].msg; }
isa_oop_ptr() const415   bool isa_oop_ptr() const           { return _type_info[_base].isa_oop; }
reloc() const416   relocInfo::relocType reloc() const { return _type_info[_base].reloc; }
417 
418   // Mapping from CI type system to compiler type:
419   static const Type* get_typeflow_type(ciType* type);
420 
421   static const Type* make_from_constant(ciConstant constant,
422                                         bool require_constant = false,
423                                         bool is_autobox_cache = false);
424 
425   // Speculative type. See TypeInstPtr
speculative() const426   virtual const TypeOopPtr* speculative() const { return NULL; }
speculative_type() const427   virtual ciKlass* speculative_type() const { return NULL; }
428   const Type* maybe_remove_speculative(bool include_speculative) const;
remove_speculative() const429   virtual const Type* remove_speculative() const { return this; }
430 
would_improve_type(ciKlass * exact_kls,int inline_depth) const431   virtual bool would_improve_type(ciKlass* exact_kls, int inline_depth) const {
432     return exact_kls != NULL;
433   }
434 
435 private:
436   // support arrays
437   static const Type*        _zero_type[T_CONFLICT+1];
438   static const Type* _const_basic_type[T_CONFLICT+1];
439 };
440 
441 //------------------------------TypeF------------------------------------------
442 // Class of Float-Constant Types.
443 class TypeF : public Type {
TypeF(float f)444   TypeF( float f ) : Type(FloatCon), _f(f) {};
445 public:
446   virtual bool eq( const Type *t ) const;
447   virtual int  hash() const;             // Type specific hashing
448   virtual bool singleton(void) const;    // TRUE if type is a singleton
449   virtual bool empty(void) const;        // TRUE if type is vacuous
450 public:
451   const float _f;               // Float constant
452 
453   static const TypeF *make(float f);
454 
455   virtual bool        is_finite() const;  // Has a finite value
456   virtual bool        is_nan()    const;  // Is not a number (NaN)
457 
458   virtual const Type *xmeet( const Type *t ) const;
459   virtual const Type *xdual() const;    // Compute dual right now.
460   // Convenience common pre-built types.
461   static const TypeF *ZERO; // positive zero only
462   static const TypeF *ONE;
463 #ifndef PRODUCT
464   virtual void dump2( Dict &d, uint depth, outputStream *st ) const;
465 #endif
466 };
467 
468 //------------------------------TypeD------------------------------------------
469 // Class of Double-Constant Types.
470 class TypeD : public Type {
TypeD(double d)471   TypeD( double d ) : Type(DoubleCon), _d(d) {};
472 public:
473   virtual bool eq( const Type *t ) const;
474   virtual int  hash() const;             // Type specific hashing
475   virtual bool singleton(void) const;    // TRUE if type is a singleton
476   virtual bool empty(void) const;        // TRUE if type is vacuous
477 public:
478   const double _d;              // Double constant
479 
480   static const TypeD *make(double d);
481 
482   virtual bool        is_finite() const;  // Has a finite value
483   virtual bool        is_nan()    const;  // Is not a number (NaN)
484 
485   virtual const Type *xmeet( const Type *t ) const;
486   virtual const Type *xdual() const;    // Compute dual right now.
487   // Convenience common pre-built types.
488   static const TypeD *ZERO; // positive zero only
489   static const TypeD *ONE;
490 #ifndef PRODUCT
491   virtual void dump2( Dict &d, uint depth, outputStream *st ) const;
492 #endif
493 };
494 
495 //------------------------------TypeInt----------------------------------------
496 // Class of integer ranges, the set of integers between a lower bound and an
497 // upper bound, inclusive.
498 class TypeInt : public Type {
499   TypeInt( jint lo, jint hi, int w );
500 protected:
501   virtual const Type *filter_helper(const Type *kills, bool include_speculative) const;
502 
503 public:
504   typedef jint NativeType;
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   const jint _lo, _hi;          // Lower bound, upper bound
510   const short _widen;           // Limit on times we widen this sucker
511 
512   static const TypeInt *make(jint lo);
513   // must always specify w
514   static const TypeInt *make(jint lo, jint hi, int w);
515 
516   // Check for single integer
is_con() const517   int is_con() const { return _lo==_hi; }
is_con(int i) const518   bool is_con(int i) const { return is_con() && _lo == i; }
get_con() const519   jint get_con() const { assert( is_con(), "" );  return _lo; }
520 
521   virtual bool        is_finite() const;  // Has a finite value
522 
523   virtual const Type *xmeet( const Type *t ) const;
524   virtual const Type *xdual() const;    // Compute dual right now.
525   virtual const Type *widen( const Type *t, const Type* limit_type ) const;
526   virtual const Type *narrow( const Type *t ) const;
527   // Do not kill _widen bits.
528   // Convenience common pre-built types.
529   static const TypeInt *MINUS_1;
530   static const TypeInt *ZERO;
531   static const TypeInt *ONE;
532   static const TypeInt *BOOL;
533   static const TypeInt *CC;
534   static const TypeInt *CC_LT;  // [-1]  == MINUS_1
535   static const TypeInt *CC_GT;  // [1]   == ONE
536   static const TypeInt *CC_EQ;  // [0]   == ZERO
537   static const TypeInt *CC_LE;  // [-1,0]
538   static const TypeInt *CC_GE;  // [0,1] == BOOL (!)
539   static const TypeInt *BYTE;
540   static const TypeInt *UBYTE;
541   static const TypeInt *CHAR;
542   static const TypeInt *SHORT;
543   static const TypeInt *POS;
544   static const TypeInt *POS1;
545   static const TypeInt *INT;
546   static const TypeInt *SYMINT; // symmetric range [-max_jint..max_jint]
547   static const TypeInt *TYPE_DOMAIN; // alias for TypeInt::INT
548 
as_self(const Type * t)549   static const TypeInt *as_self(const Type *t) { return t->is_int(); }
550 #ifndef PRODUCT
551   virtual void dump2( Dict &d, uint depth, outputStream *st ) const;
552 #endif
553 };
554 
555 
556 //------------------------------TypeLong---------------------------------------
557 // Class of long integer ranges, the set of integers between a lower bound and
558 // an upper bound, inclusive.
559 class TypeLong : public Type {
560   TypeLong( jlong lo, jlong hi, int w );
561 protected:
562   // Do not kill _widen bits.
563   virtual const Type *filter_helper(const Type *kills, bool include_speculative) const;
564 public:
565   typedef jlong NativeType;
566   virtual bool eq( const Type *t ) const;
567   virtual int  hash() const;             // Type specific hashing
568   virtual bool singleton(void) const;    // TRUE if type is a singleton
569   virtual bool empty(void) const;        // TRUE if type is vacuous
570 public:
571   const jlong _lo, _hi;         // Lower bound, upper bound
572   const short _widen;           // Limit on times we widen this sucker
573 
574   static const TypeLong *make(jlong lo);
575   // must always specify w
576   static const TypeLong *make(jlong lo, jlong hi, int w);
577 
578   // Check for single integer
is_con() const579   int is_con() const { return _lo==_hi; }
is_con(int i) const580   bool is_con(int i) const { return is_con() && _lo == i; }
get_con() const581   jlong get_con() const { assert( is_con(), "" ); return _lo; }
582 
583   // Check for positive 32-bit value.
is_positive_int() const584   int is_positive_int() const { return _lo >= 0 && _hi <= (jlong)max_jint; }
585 
586   virtual bool        is_finite() const;  // Has a finite value
587 
588 
589   virtual const Type *xmeet( const Type *t ) const;
590   virtual const Type *xdual() const;    // Compute dual right now.
591   virtual const Type *widen( const Type *t, const Type* limit_type ) const;
592   virtual const Type *narrow( const Type *t ) const;
593   // Convenience common pre-built types.
594   static const TypeLong *MINUS_1;
595   static const TypeLong *ZERO;
596   static const TypeLong *ONE;
597   static const TypeLong *POS;
598   static const TypeLong *LONG;
599   static const TypeLong *INT;    // 32-bit subrange [min_jint..max_jint]
600   static const TypeLong *UINT;   // 32-bit unsigned [0..max_juint]
601   static const TypeLong *TYPE_DOMAIN; // alias for TypeLong::LONG
602 
603   // static convenience methods.
as_self(const Type * t)604   static const TypeLong *as_self(const Type *t) { return t->is_long(); }
605 
606 #ifndef PRODUCT
607   virtual void dump2( Dict &d, uint, outputStream *st  ) const;// Specialized per-Type dumping
608 #endif
609 };
610 
611 //------------------------------TypeTuple--------------------------------------
612 // Class of Tuple Types, essentially type collections for function signatures
613 // and class layouts.  It happens to also be a fast cache for the HotSpot
614 // signature types.
615 class TypeTuple : public Type {
TypeTuple(uint cnt,const Type ** fields)616   TypeTuple( uint cnt, const Type **fields ) : Type(Tuple), _cnt(cnt), _fields(fields) { }
617 public:
618   virtual bool eq( const Type *t ) const;
619   virtual int  hash() const;             // Type specific hashing
620   virtual bool singleton(void) const;    // TRUE if type is a singleton
621   virtual bool empty(void) const;        // TRUE if type is vacuous
622 
623 public:
624   const uint          _cnt;              // Count of fields
625   const Type ** const _fields;           // Array of field types
626 
627   // Accessors:
cnt() const628   uint cnt() const { return _cnt; }
field_at(uint i) const629   const Type* field_at(uint i) const {
630     assert(i < _cnt, "oob");
631     return _fields[i];
632   }
set_field_at(uint i,const Type * t)633   void set_field_at(uint i, const Type* t) {
634     assert(i < _cnt, "oob");
635     _fields[i] = t;
636   }
637 
638   static const TypeTuple *make( uint cnt, const Type **fields );
639   static const TypeTuple *make_range(ciSignature *sig);
640   static const TypeTuple *make_domain(ciInstanceKlass* recv, ciSignature *sig);
641 
642   // Subroutine call type with space allocated for argument types
643   static const Type **fields( uint arg_cnt );
644 
645   virtual const Type *xmeet( const Type *t ) const;
646   virtual const Type *xdual() const;    // Compute dual right now.
647   // Convenience common pre-built types.
648   static const TypeTuple *IFBOTH;
649   static const TypeTuple *IFFALSE;
650   static const TypeTuple *IFTRUE;
651   static const TypeTuple *IFNEITHER;
652   static const TypeTuple *LOOPBODY;
653   static const TypeTuple *MEMBAR;
654   static const TypeTuple *STORECONDITIONAL;
655   static const TypeTuple *START_I2C;
656   static const TypeTuple *INT_PAIR;
657   static const TypeTuple *LONG_PAIR;
658   static const TypeTuple *INT_CC_PAIR;
659   static const TypeTuple *LONG_CC_PAIR;
660 #ifndef PRODUCT
661   virtual void dump2( Dict &d, uint, outputStream *st  ) const; // Specialized per-Type dumping
662 #endif
663 };
664 
665 //------------------------------TypeAry----------------------------------------
666 // Class of Array Types
667 class TypeAry : public Type {
TypeAry(const Type * elem,const TypeInt * size,bool stable)668   TypeAry(const Type* elem, const TypeInt* size, bool stable) : Type(Array),
669       _elem(elem), _size(size), _stable(stable) {}
670 public:
671   virtual bool eq( const Type *t ) const;
672   virtual int  hash() const;             // Type specific hashing
673   virtual bool singleton(void) const;    // TRUE if type is a singleton
674   virtual bool empty(void) const;        // TRUE if type is vacuous
675 
676 private:
677   const Type *_elem;            // Element type of array
678   const TypeInt *_size;         // Elements in array
679   const bool _stable;           // Are elements @Stable?
680   friend class TypeAryPtr;
681 
682 public:
683   static const TypeAry* make(const Type* elem, const TypeInt* size, bool stable = false);
684 
685   virtual const Type *xmeet( const Type *t ) const;
686   virtual const Type *xdual() const;    // Compute dual right now.
687   bool ary_must_be_exact() const;  // true if arrays of such are never generic
688   virtual const Type* remove_speculative() const;
689 #ifdef ASSERT
690   // One type is interface, the other is oop
691   virtual bool interface_vs_oop(const Type *t) const;
692 #endif
693 #ifndef PRODUCT
694   virtual void dump2( Dict &d, uint, outputStream *st  ) const; // Specialized per-Type dumping
695 #endif
696 };
697 
698 //------------------------------TypeVect---------------------------------------
699 // Class of Vector Types
700 class TypeVect : public Type {
701   const Type*   _elem;  // Vector's element type
702   const uint  _length;  // Elements in vector (power of 2)
703 
704 protected:
TypeVect(TYPES t,const Type * elem,uint length)705   TypeVect(TYPES t, const Type* elem, uint length) : Type(t),
706     _elem(elem), _length(length) {}
707 
708 public:
element_type() const709   const Type* element_type() const { return _elem; }
element_basic_type() const710   BasicType element_basic_type() const { return _elem->array_element_basic_type(); }
length() const711   uint length() const { return _length; }
length_in_bytes() const712   uint length_in_bytes() const {
713    return _length * type2aelembytes(element_basic_type());
714   }
715 
716   virtual bool eq(const Type *t) const;
717   virtual int  hash() const;             // Type specific hashing
718   virtual bool singleton(void) const;    // TRUE if type is a singleton
719   virtual bool empty(void) const;        // TRUE if type is vacuous
720 
make(const BasicType elem_bt,uint length)721   static const TypeVect *make(const BasicType elem_bt, uint length) {
722     // Use bottom primitive type.
723     return make(get_const_basic_type(elem_bt), length);
724   }
725   // Used directly by Replicate nodes to construct singleton vector.
726   static const TypeVect *make(const Type* elem, uint length);
727 
728   virtual const Type *xmeet( const Type *t) const;
729   virtual const Type *xdual() const;     // Compute dual right now.
730 
731   static const TypeVect *VECTS;
732   static const TypeVect *VECTD;
733   static const TypeVect *VECTX;
734   static const TypeVect *VECTY;
735 
736 #ifndef PRODUCT
737   virtual void dump2(Dict &d, uint, outputStream *st) const; // Specialized per-Type dumping
738 #endif
739 };
740 
741 class TypeVectS : public TypeVect {
742   friend class TypeVect;
TypeVectS(const Type * elem,uint length)743   TypeVectS(const Type* elem, uint length) : TypeVect(VectorS, elem, length) {}
744 };
745 
746 class TypeVectD : public TypeVect {
747   friend class TypeVect;
TypeVectD(const Type * elem,uint length)748   TypeVectD(const Type* elem, uint length) : TypeVect(VectorD, elem, length) {}
749 };
750 
751 class TypeVectX : public TypeVect {
752   friend class TypeVect;
TypeVectX(const Type * elem,uint length)753   TypeVectX(const Type* elem, uint length) : TypeVect(VectorX, elem, length) {}
754 };
755 
756 class TypeVectY : public TypeVect {
757   friend class TypeVect;
TypeVectY(const Type * elem,uint length)758   TypeVectY(const Type* elem, uint length) : TypeVect(VectorY, elem, length) {}
759 };
760 
761 //------------------------------TypePtr----------------------------------------
762 // Class of machine Pointer Types: raw data, instances or arrays.
763 // If the _base enum is AnyPtr, then this refers to all of the above.
764 // Otherwise the _base will indicate which subset of pointers is affected,
765 // and the class will be inherited from.
766 class TypePtr : public Type {
767   friend class TypeNarrowPtr;
768 public:
769   enum PTR { TopPTR, AnyNull, Constant, Null, NotNull, BotPTR, lastPTR };
770 protected:
TypePtr(TYPES t,PTR ptr,int offset)771   TypePtr( TYPES t, PTR ptr, int offset ) : Type(t), _ptr(ptr), _offset(offset) {}
772   virtual bool eq( const Type *t ) const;
773   virtual int  hash() const;             // Type specific hashing
774   static const PTR ptr_meet[lastPTR][lastPTR];
775   static const PTR ptr_dual[lastPTR];
776   static const char * const ptr_msg[lastPTR];
777 
778 public:
779   const int _offset;            // Offset into oop, with TOP & BOT
780   const PTR _ptr;               // Pointer equivalence class
781 
offset() const782   const int offset() const { return _offset; }
ptr() const783   const PTR ptr()    const { return _ptr; }
784 
785   static const TypePtr *make( TYPES t, PTR ptr, int offset );
786 
787   // Return a 'ptr' version of this type
788   virtual const Type *cast_to_ptr_type(PTR ptr) const;
789 
790   virtual intptr_t get_con() const;
791 
792   int xadd_offset( intptr_t offset ) const;
793   virtual const TypePtr *add_offset( intptr_t offset ) const;
794 
795   virtual bool singleton(void) const;    // TRUE if type is a singleton
796   virtual bool empty(void) const;        // TRUE if type is vacuous
797   virtual const Type *xmeet( const Type *t ) const;
798   int meet_offset( int offset ) const;
799   int dual_offset( ) const;
800   virtual const Type *xdual() const;    // Compute dual right now.
801 
802   // meet, dual and join over pointer equivalence sets
meet_ptr(const PTR in_ptr) const803   PTR meet_ptr( const PTR in_ptr ) const { return ptr_meet[in_ptr][ptr()]; }
dual_ptr() const804   PTR dual_ptr()                   const { return ptr_dual[ptr()];      }
805 
806   // This is textually confusing unless one recalls that
807   // join(t) == dual()->meet(t->dual())->dual().
join_ptr(const PTR in_ptr) const808   PTR join_ptr( const PTR in_ptr ) const {
809     return ptr_dual[ ptr_meet[ ptr_dual[in_ptr] ] [ dual_ptr() ] ];
810   }
811 
812   // Tests for relation to centerline of type lattice:
above_centerline(PTR ptr)813   static bool above_centerline(PTR ptr) { return (ptr <= AnyNull); }
below_centerline(PTR ptr)814   static bool below_centerline(PTR ptr) { return (ptr >= NotNull); }
815   // Convenience common pre-built types.
816   static const TypePtr *NULL_PTR;
817   static const TypePtr *NOTNULL;
818   static const TypePtr *BOTTOM;
819 #ifndef PRODUCT
820   virtual void dump2( Dict &d, uint depth, outputStream *st  ) const;
821 #endif
822 };
823 
824 //------------------------------TypeRawPtr-------------------------------------
825 // Class of raw pointers, pointers to things other than Oops.  Examples
826 // include the stack pointer, top of heap, card-marking area, handles, etc.
827 class TypeRawPtr : public TypePtr {
828 protected:
TypeRawPtr(PTR ptr,address bits)829   TypeRawPtr( PTR ptr, address bits ) : TypePtr(RawPtr,ptr,0), _bits(bits){}
830 public:
831   virtual bool eq( const Type *t ) const;
832   virtual int  hash() const;     // Type specific hashing
833 
834   const address _bits;          // Constant value, if applicable
835 
836   static const TypeRawPtr *make( PTR ptr );
837   static const TypeRawPtr *make( address bits );
838 
839   // Return a 'ptr' version of this type
840   virtual const Type *cast_to_ptr_type(PTR ptr) const;
841 
842   virtual intptr_t get_con() const;
843 
844   virtual const TypePtr *add_offset( intptr_t offset ) const;
845 
846   virtual const Type *xmeet( const Type *t ) const;
847   virtual const Type *xdual() const;    // Compute dual right now.
848   // Convenience common pre-built types.
849   static const TypeRawPtr *BOTTOM;
850   static const TypeRawPtr *NOTNULL;
851 #ifndef PRODUCT
852   virtual void dump2( Dict &d, uint depth, outputStream *st  ) const;
853 #endif
854 };
855 
856 //------------------------------TypeOopPtr-------------------------------------
857 // Some kind of oop (Java pointer), either klass or instance or array.
858 class TypeOopPtr : public TypePtr {
859 protected:
860   TypeOopPtr(TYPES t, PTR ptr, ciKlass* k, bool xk, ciObject* o, int offset, int instance_id, const TypeOopPtr* speculative, int inline_depth);
861 public:
862   virtual bool eq( const Type *t ) const;
863   virtual int  hash() const;             // Type specific hashing
864   virtual bool singleton(void) const;    // TRUE if type is a singleton
865   enum {
866    InstanceTop = -1,   // undefined instance
867    InstanceBot = 0     // any possible instance
868   };
869 protected:
870 
871   enum {
872     InlineDepthBottom = INT_MAX,
873     InlineDepthTop = -InlineDepthBottom
874   };
875   // Oop is NULL, unless this is a constant oop.
876   ciObject*     _const_oop;   // Constant oop
877   // If _klass is NULL, then so is _sig.  This is an unloaded klass.
878   ciKlass*      _klass;       // Klass object
879   // Does the type exclude subclasses of the klass?  (Inexact == polymorphic.)
880   bool          _klass_is_exact;
881   bool          _is_ptr_to_narrowoop;
882   bool          _is_ptr_to_narrowklass;
883   bool          _is_ptr_to_boxed_value;
884 
885   // If not InstanceTop or InstanceBot, indicates that this is
886   // a particular instance of this type which is distinct.
887   // This is the node index of the allocation node creating this instance.
888   int           _instance_id;
889 
890   // Extra type information profiling gave us. We propagate it the
891   // same way the rest of the type info is propagated. If we want to
892   // use it, then we have to emit a guard: this part of the type is
893   // not something we know but something we speculate about the type.
894   const TypeOopPtr*   _speculative;
895   // For speculative types, we record at what inlining depth the
896   // profiling point that provided the data is. We want to favor
897   // profile data coming from outer scopes which are likely better for
898   // the current compilation.
899   int _inline_depth;
900 
901   static const TypeOopPtr* make_from_klass_common(ciKlass* klass, bool klass_change, bool try_for_exact);
902 
903   int dual_instance_id() const;
904   int meet_instance_id(int uid) const;
905 
906   // utility methods to work on the speculative part of the type
907   const TypeOopPtr* dual_speculative() const;
908   const TypeOopPtr* xmeet_speculative(const TypeOopPtr* other) const;
909   bool eq_speculative(const TypeOopPtr* other) const;
910   int hash_speculative() const;
911   const TypeOopPtr* add_offset_speculative(intptr_t offset) const;
912 #ifndef PRODUCT
913   void dump_speculative(outputStream *st) const;
914 #endif
915   // utility methods to work on the inline depth of the type
916   int dual_inline_depth() const;
917   int meet_inline_depth(int depth) const;
918 #ifndef PRODUCT
919   void dump_inline_depth(outputStream *st) const;
920 #endif
921 
922   // Do not allow interface-vs.-noninterface joins to collapse to top.
923   virtual const Type *filter_helper(const Type *kills, bool include_speculative) const;
924 
925 public:
926   // Creates a type given a klass. Correctly handles multi-dimensional arrays
927   // Respects UseUniqueSubclasses.
928   // If the klass is final, the resulting type will be exact.
make_from_klass(ciKlass * klass)929   static const TypeOopPtr* make_from_klass(ciKlass* klass) {
930     return make_from_klass_common(klass, true, false);
931   }
932   // Same as before, but will produce an exact type, even if
933   // the klass is not final, as long as it has exactly one implementation.
make_from_klass_unique(ciKlass * klass)934   static const TypeOopPtr* make_from_klass_unique(ciKlass* klass) {
935     return make_from_klass_common(klass, true, true);
936   }
937   // Same as before, but does not respects UseUniqueSubclasses.
938   // Use this only for creating array element types.
make_from_klass_raw(ciKlass * klass)939   static const TypeOopPtr* make_from_klass_raw(ciKlass* klass) {
940     return make_from_klass_common(klass, false, false);
941   }
942   // Creates a singleton type given an object.
943   // If the object cannot be rendered as a constant,
944   // may return a non-singleton type.
945   // If require_constant, produce a NULL if a singleton is not possible.
946   static const TypeOopPtr* make_from_constant(ciObject* o,
947                                               bool require_constant = false,
948                                               bool not_null_elements = false);
949 
950   // Make a generic (unclassed) pointer to an oop.
951   static const TypeOopPtr* make(PTR ptr, int offset, int instance_id, const TypeOopPtr* speculative = NULL, int inline_depth = InlineDepthBottom);
952 
const_oop() const953   ciObject* const_oop()    const { return _const_oop; }
klass() const954   virtual ciKlass* klass() const { return _klass;     }
klass_is_exact() const955   bool klass_is_exact()    const { return _klass_is_exact; }
956 
957   // Returns true if this pointer points at memory which contains a
958   // compressed oop references.
is_ptr_to_narrowoop_nv() const959   bool is_ptr_to_narrowoop_nv() const { return _is_ptr_to_narrowoop; }
is_ptr_to_narrowklass_nv() const960   bool is_ptr_to_narrowklass_nv() const { return _is_ptr_to_narrowklass; }
is_ptr_to_boxed_value() const961   bool is_ptr_to_boxed_value()   const { return _is_ptr_to_boxed_value; }
is_known_instance() const962   bool is_known_instance()       const { return _instance_id > 0; }
instance_id() const963   int  instance_id()             const { return _instance_id; }
is_known_instance_field() const964   bool is_known_instance_field() const { return is_known_instance() && _offset >= 0; }
speculative() const965   virtual const TypeOopPtr* speculative() const { return _speculative; }
966 
967   virtual intptr_t get_con() const;
968 
969   virtual const Type *cast_to_ptr_type(PTR ptr) const;
970 
971   virtual const Type *cast_to_exactness(bool klass_is_exact) const;
972 
973   virtual const TypeOopPtr *cast_to_instance_id(int instance_id) const;
974 
975   // corresponding pointer to klass, for a given instance
976   const TypeKlassPtr* as_klass_type() const;
977 
978   virtual const TypePtr *add_offset( intptr_t offset ) const;
979   // Return same type without a speculative part
980   virtual const Type* remove_speculative() const;
981 
982   virtual const Type *xmeet(const Type *t) const;
983   virtual const Type *xdual() const;    // Compute dual right now.
984   // the core of the computation of the meet for TypeOopPtr and for its subclasses
985   virtual const Type *xmeet_helper(const Type *t) const;
986 
987   // Convenience common pre-built type.
988   static const TypeOopPtr *BOTTOM;
989 #ifndef PRODUCT
990   virtual void dump2( Dict &d, uint depth, outputStream *st ) const;
991 #endif
992 
993   // Return the speculative type if any
speculative_type() const994   ciKlass* speculative_type() const {
995     if (_speculative != NULL) {
996       const TypeOopPtr* speculative = _speculative->join(this)->is_oopptr();
997       if (speculative->klass_is_exact()) {
998         return speculative->klass();
999       }
1000     }
1001     return NULL;
1002   }
inline_depth() const1003   int inline_depth() const {
1004     return _inline_depth;
1005   }
1006   virtual const TypeOopPtr* with_inline_depth(int depth) const;
1007   virtual bool would_improve_type(ciKlass* exact_kls, int inline_depth) const;
1008 };
1009 
1010 //------------------------------TypeInstPtr------------------------------------
1011 // Class of Java object pointers, pointing either to non-array Java instances
1012 // or to a Klass* (including array klasses).
1013 class TypeInstPtr : public TypeOopPtr {
1014   TypeInstPtr(PTR ptr, ciKlass* k, bool xk, ciObject* o, int offset, int instance_id, const TypeOopPtr* speculative, int inline_depth);
1015   virtual bool eq( const Type *t ) const;
1016   virtual int  hash() const;             // Type specific hashing
1017 
1018   ciSymbol*  _name;        // class name
1019 
1020  public:
name() const1021   ciSymbol* name()         const { return _name; }
1022 
is_loaded() const1023   bool  is_loaded() const { return _klass->is_loaded(); }
1024 
1025   // Make a pointer to a constant oop.
make(ciObject * o)1026   static const TypeInstPtr *make(ciObject* o) {
1027     return make(TypePtr::Constant, o->klass(), true, o, 0, InstanceBot);
1028   }
1029   // Make a pointer to a constant oop with offset.
make(ciObject * o,int offset)1030   static const TypeInstPtr *make(ciObject* o, int offset) {
1031     return make(TypePtr::Constant, o->klass(), true, o, offset, InstanceBot);
1032   }
1033 
1034   // Make a pointer to some value of type klass.
make(PTR ptr,ciKlass * klass)1035   static const TypeInstPtr *make(PTR ptr, ciKlass* klass) {
1036     return make(ptr, klass, false, NULL, 0, InstanceBot);
1037   }
1038 
1039   // Make a pointer to some non-polymorphic value of exactly type klass.
make_exact(PTR ptr,ciKlass * klass)1040   static const TypeInstPtr *make_exact(PTR ptr, ciKlass* klass) {
1041     return make(ptr, klass, true, NULL, 0, InstanceBot);
1042   }
1043 
1044   // Make a pointer to some value of type klass with offset.
make(PTR ptr,ciKlass * klass,int offset)1045   static const TypeInstPtr *make(PTR ptr, ciKlass* klass, int offset) {
1046     return make(ptr, klass, false, NULL, offset, InstanceBot);
1047   }
1048 
1049   // Make a pointer to an oop.
1050   static const TypeInstPtr *make(PTR ptr, ciKlass* k, bool xk, ciObject* o, int offset, int instance_id = InstanceBot, const TypeOopPtr* speculative = NULL, int inline_depth = InlineDepthBottom);
1051 
1052   /** Create constant type for a constant boxed value */
1053   const Type* get_const_boxed_value() const;
1054 
1055   // If this is a java.lang.Class constant, return the type for it or NULL.
1056   // Pass to Type::get_const_type to turn it to a type, which will usually
1057   // be a TypeInstPtr, but may also be a TypeInt::INT for int.class, etc.
1058   ciType* java_mirror_type() const;
1059 
1060   virtual const Type *cast_to_ptr_type(PTR ptr) const;
1061 
1062   virtual const Type *cast_to_exactness(bool klass_is_exact) const;
1063 
1064   virtual const TypeOopPtr *cast_to_instance_id(int instance_id) const;
1065 
1066   virtual const TypePtr *add_offset( intptr_t offset ) const;
1067   // Return same type without a speculative part
1068   virtual const Type* remove_speculative() const;
1069   virtual const TypeOopPtr* with_inline_depth(int depth) const;
1070 
1071   // the core of the computation of the meet of 2 types
1072   virtual const Type *xmeet_helper(const Type *t) const;
1073   virtual const TypeInstPtr *xmeet_unloaded( const TypeInstPtr *t ) const;
1074   virtual const Type *xdual() const;    // Compute dual right now.
1075 
1076   // Convenience common pre-built types.
1077   static const TypeInstPtr *NOTNULL;
1078   static const TypeInstPtr *BOTTOM;
1079   static const TypeInstPtr *MIRROR;
1080   static const TypeInstPtr *MARK;
1081   static const TypeInstPtr *KLASS;
1082 #ifndef PRODUCT
1083   virtual void dump2( Dict &d, uint depth, outputStream *st ) const; // Specialized per-Type dumping
1084 #endif
1085 };
1086 
1087 //------------------------------TypeAryPtr-------------------------------------
1088 // Class of Java array pointers
1089 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 TypeOopPtr * speculative,int inline_depth)1090   TypeAryPtr( PTR ptr, ciObject* o, const TypeAry *ary, ciKlass* k, bool xk,
1091               int offset, int instance_id, bool is_autobox_cache, const TypeOopPtr* speculative, int inline_depth)
1092     : TypeOopPtr(AryPtr,ptr,k,xk,o,offset, instance_id, speculative, inline_depth),
1093     _ary(ary),
1094     _is_autobox_cache(is_autobox_cache)
1095  {
1096 #ifdef ASSERT
1097     if (k != NULL) {
1098       // Verify that specified klass and TypeAryPtr::klass() follow the same rules.
1099       ciKlass* ck = compute_klass(true);
1100       if (k != ck) {
1101         this->dump(); tty->cr();
1102         tty->print(" k: ");
1103         k->print(); tty->cr();
1104         tty->print("ck: ");
1105         if (ck != NULL) ck->print();
1106         else tty->print("<NULL>");
1107         tty->cr();
1108         assert(false, "unexpected TypeAryPtr::_klass");
1109       }
1110     }
1111 #endif
1112   }
1113   virtual bool eq( const Type *t ) const;
1114   virtual int hash() const;     // Type specific hashing
1115   const TypeAry *_ary;          // Array we point into
1116   const bool     _is_autobox_cache;
1117 
1118   ciKlass* compute_klass(DEBUG_ONLY(bool verify = false)) const;
1119 
1120 public:
1121   // Accessors
1122   ciKlass* klass() const;
ary() const1123   const TypeAry* ary() const  { return _ary; }
elem() const1124   const Type*    elem() const { return _ary->_elem; }
size() const1125   const TypeInt* size() const { return _ary->_size; }
is_stable() const1126   bool      is_stable() const { return _ary->_stable; }
1127 
is_autobox_cache() const1128   bool is_autobox_cache() const { return _is_autobox_cache; }
1129 
1130   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);
1131   // Constant pointer to array
1132   static const TypeAryPtr *make( PTR ptr, ciObject* o, const TypeAry *ary, ciKlass* k, bool xk, int offset, int instance_id = InstanceBot, const TypeOopPtr* speculative = NULL, int inline_depth = InlineDepthBottom, bool is_autobox_cache= false);
1133 
1134   // Return a 'ptr' version of this type
1135   virtual const Type *cast_to_ptr_type(PTR ptr) const;
1136 
1137   virtual const Type *cast_to_exactness(bool klass_is_exact) const;
1138 
1139   virtual const TypeOopPtr *cast_to_instance_id(int instance_id) const;
1140 
1141   virtual const TypeAryPtr* cast_to_size(const TypeInt* size) const;
1142   virtual const TypeInt* narrow_size_type(const TypeInt* size) const;
1143 
1144   virtual bool empty(void) const;        // TRUE if type is vacuous
1145   virtual const TypePtr *add_offset( intptr_t offset ) const;
1146   // Return same type without a speculative part
1147   virtual const Type* remove_speculative() const;
1148   virtual const TypeOopPtr* with_inline_depth(int depth) const;
1149 
1150   // the core of the computation of the meet of 2 types
1151   virtual const Type *xmeet_helper(const Type *t) const;
1152   virtual const Type *xdual() const;    // Compute dual right now.
1153 
1154   const TypeAryPtr* cast_to_stable(bool stable, int stable_dimension = 1) const;
1155   int stable_dimension() const;
1156 
1157   static jint max_array_length(BasicType etype) ;
1158 
1159   // Convenience common pre-built types.
1160   static const TypeAryPtr *RANGE;
1161   static const TypeAryPtr *OOPS;
1162   static const TypeAryPtr *NARROWOOPS;
1163   static const TypeAryPtr *BYTES;
1164   static const TypeAryPtr *SHORTS;
1165   static const TypeAryPtr *CHARS;
1166   static const TypeAryPtr *INTS;
1167   static const TypeAryPtr *LONGS;
1168   static const TypeAryPtr *FLOATS;
1169   static const TypeAryPtr *DOUBLES;
1170   // selects one of the above:
get_array_body_type(BasicType elem)1171   static const TypeAryPtr *get_array_body_type(BasicType elem) {
1172     assert((uint)elem <= T_CONFLICT && _array_body_type[elem] != NULL, "bad elem type");
1173     return _array_body_type[elem];
1174   }
1175   static const TypeAryPtr *_array_body_type[T_CONFLICT+1];
1176   // sharpen the type of an int which is used as an array size
1177 #ifdef ASSERT
1178   // One type is interface, the other is oop
1179   virtual bool interface_vs_oop(const Type *t) const;
1180 #endif
1181 #ifndef PRODUCT
1182   virtual void dump2( Dict &d, uint depth, outputStream *st ) const; // Specialized per-Type dumping
1183 #endif
1184 };
1185 
1186 //------------------------------TypeMetadataPtr-------------------------------------
1187 // Some kind of metadata, either Method*, MethodData* or CPCacheOop
1188 class TypeMetadataPtr : public TypePtr {
1189 protected:
1190   TypeMetadataPtr(PTR ptr, ciMetadata* metadata, int offset);
1191   // Do not allow interface-vs.-noninterface joins to collapse to top.
1192   virtual const Type *filter_helper(const Type *kills, bool include_speculative) const;
1193 public:
1194   virtual bool eq( const Type *t ) const;
1195   virtual int  hash() const;             // Type specific hashing
1196   virtual bool singleton(void) const;    // TRUE if type is a singleton
1197 
1198 private:
1199   ciMetadata*   _metadata;
1200 
1201 public:
1202   static const TypeMetadataPtr* make(PTR ptr, ciMetadata* m, int offset);
1203 
1204   static const TypeMetadataPtr* make(ciMethod* m);
1205   static const TypeMetadataPtr* make(ciMethodData* m);
1206 
metadata() const1207   ciMetadata* metadata() const { return _metadata; }
1208 
1209   virtual const Type *cast_to_ptr_type(PTR ptr) const;
1210 
1211   virtual const TypePtr *add_offset( intptr_t offset ) const;
1212 
1213   virtual const Type *xmeet( const Type *t ) const;
1214   virtual const Type *xdual() const;    // Compute dual right now.
1215 
1216   virtual intptr_t get_con() const;
1217 
1218   // Convenience common pre-built types.
1219   static const TypeMetadataPtr *BOTTOM;
1220 
1221 #ifndef PRODUCT
1222   virtual void dump2( Dict &d, uint depth, outputStream *st ) const;
1223 #endif
1224 };
1225 
1226 //------------------------------TypeKlassPtr-----------------------------------
1227 // Class of Java Klass pointers
1228 class TypeKlassPtr : public TypePtr {
1229   TypeKlassPtr( PTR ptr, ciKlass* klass, int offset );
1230 
1231 protected:
1232   virtual const Type *filter_helper(const Type *kills, bool include_speculative) const;
1233  public:
1234   virtual bool eq( const Type *t ) const;
1235   virtual int hash() const;             // Type specific hashing
1236   virtual bool singleton(void) const;    // TRUE if type is a singleton
1237  private:
1238 
1239   static const TypeKlassPtr* make_from_klass_common(ciKlass* klass, bool klass_change, bool try_for_exact);
1240 
1241   ciKlass* _klass;
1242 
1243   // Does the type exclude subclasses of the klass?  (Inexact == polymorphic.)
1244   bool          _klass_is_exact;
1245 
1246 public:
name() const1247   ciSymbol* name()  const { return klass()->name(); }
1248 
klass() const1249   ciKlass* klass() const { return  _klass; }
klass_is_exact() const1250   bool klass_is_exact()    const { return _klass_is_exact; }
1251 
is_loaded() const1252   bool  is_loaded() const { return klass()->is_loaded(); }
1253 
1254   // Creates a type given a klass. Correctly handles multi-dimensional arrays
1255   // Respects UseUniqueSubclasses.
1256   // If the klass is final, the resulting type will be exact.
make_from_klass(ciKlass * klass)1257   static const TypeKlassPtr* make_from_klass(ciKlass* klass) {
1258     return make_from_klass_common(klass, true, false);
1259   }
1260   // Same as before, but will produce an exact type, even if
1261   // the klass is not final, as long as it has exactly one implementation.
make_from_klass_unique(ciKlass * klass)1262   static const TypeKlassPtr* make_from_klass_unique(ciKlass* klass) {
1263     return make_from_klass_common(klass, true, true);
1264   }
1265   // Same as before, but does not respects UseUniqueSubclasses.
1266   // Use this only for creating array element types.
make_from_klass_raw(ciKlass * klass)1267   static const TypeKlassPtr* make_from_klass_raw(ciKlass* klass) {
1268     return make_from_klass_common(klass, false, false);
1269   }
1270 
1271   // Make a generic (unclassed) pointer to metadata.
1272   static const TypeKlassPtr* make(PTR ptr, int offset);
1273 
1274   // ptr to klass 'k'
make(ciKlass * k)1275   static const TypeKlassPtr *make( ciKlass* k ) { return make( TypePtr::Constant, k, 0); }
1276   // ptr to klass 'k' with offset
make(ciKlass * k,int offset)1277   static const TypeKlassPtr *make( ciKlass* k, int offset ) { return make( TypePtr::Constant, k, offset); }
1278   // ptr to klass 'k' or sub-klass
1279   static const TypeKlassPtr *make( PTR ptr, ciKlass* k, int offset);
1280 
1281   virtual const Type *cast_to_ptr_type(PTR ptr) const;
1282 
1283   virtual const Type *cast_to_exactness(bool klass_is_exact) const;
1284 
1285   // corresponding pointer to instance, for a given class
1286   const TypeOopPtr* as_instance_type() const;
1287 
1288   virtual const TypePtr *add_offset( intptr_t offset ) const;
1289   virtual const Type    *xmeet( const Type *t ) const;
1290   virtual const Type    *xdual() const;      // Compute dual right now.
1291 
1292   virtual intptr_t get_con() const;
1293 
1294   // Convenience common pre-built types.
1295   static const TypeKlassPtr* OBJECT; // Not-null object klass or below
1296   static const TypeKlassPtr* OBJECT_OR_NULL; // Maybe-null version of same
1297 #ifndef PRODUCT
1298   virtual void dump2( Dict &d, uint depth, outputStream *st ) const; // Specialized per-Type dumping
1299 #endif
1300 };
1301 
1302 class TypeNarrowPtr : public Type {
1303 protected:
1304   const TypePtr* _ptrtype; // Could be TypePtr::NULL_PTR
1305 
TypeNarrowPtr(TYPES t,const TypePtr * ptrtype)1306   TypeNarrowPtr(TYPES t, const TypePtr* ptrtype): _ptrtype(ptrtype),
1307                                                   Type(t) {
1308     assert(ptrtype->offset() == 0 ||
1309            ptrtype->offset() == OffsetBot ||
1310            ptrtype->offset() == OffsetTop, "no real offsets");
1311   }
1312 
1313   virtual const TypeNarrowPtr *isa_same_narrowptr(const Type *t) const = 0;
1314   virtual const TypeNarrowPtr *is_same_narrowptr(const Type *t) const = 0;
1315   virtual const TypeNarrowPtr *make_same_narrowptr(const TypePtr *t) const = 0;
1316   virtual const TypeNarrowPtr *make_hash_same_narrowptr(const TypePtr *t) const = 0;
1317   // Do not allow interface-vs.-noninterface joins to collapse to top.
1318   virtual const Type *filter_helper(const Type *kills, bool include_speculative) const;
1319 public:
1320   virtual bool eq( const Type *t ) const;
1321   virtual int  hash() const;             // Type specific hashing
1322   virtual bool singleton(void) const;    // TRUE if type is a singleton
1323 
1324   virtual const Type *xmeet( const Type *t ) const;
1325   virtual const Type *xdual() const;    // Compute dual right now.
1326 
1327   virtual intptr_t get_con() const;
1328 
1329   virtual bool empty(void) const;        // TRUE if type is vacuous
1330 
1331   // returns the equivalent ptr type for this compressed pointer
get_ptrtype() const1332   const TypePtr *get_ptrtype() const {
1333     return _ptrtype;
1334   }
1335 
1336 #ifndef PRODUCT
1337   virtual void dump2( Dict &d, uint depth, outputStream *st ) const;
1338 #endif
1339 };
1340 
1341 //------------------------------TypeNarrowOop----------------------------------
1342 // A compressed reference to some kind of Oop.  This type wraps around
1343 // a preexisting TypeOopPtr and forwards most of it's operations to
1344 // the underlying type.  It's only real purpose is to track the
1345 // oopness of the compressed oop value when we expose the conversion
1346 // between the normal and the compressed form.
1347 class TypeNarrowOop : public TypeNarrowPtr {
1348 protected:
TypeNarrowOop(const TypePtr * ptrtype)1349   TypeNarrowOop( const TypePtr* ptrtype): TypeNarrowPtr(NarrowOop, ptrtype) {
1350   }
1351 
isa_same_narrowptr(const Type * t) const1352   virtual const TypeNarrowPtr *isa_same_narrowptr(const Type *t) const {
1353     return t->isa_narrowoop();
1354   }
1355 
is_same_narrowptr(const Type * t) const1356   virtual const TypeNarrowPtr *is_same_narrowptr(const Type *t) const {
1357     return t->is_narrowoop();
1358   }
1359 
make_same_narrowptr(const TypePtr * t) const1360   virtual const TypeNarrowPtr *make_same_narrowptr(const TypePtr *t) const {
1361     return new TypeNarrowOop(t);
1362   }
1363 
make_hash_same_narrowptr(const TypePtr * t) const1364   virtual const TypeNarrowPtr *make_hash_same_narrowptr(const TypePtr *t) const {
1365     return (const TypeNarrowPtr*)((new TypeNarrowOop(t))->hashcons());
1366   }
1367 
1368 public:
1369 
1370   static const TypeNarrowOop *make( const TypePtr* type);
1371 
make_from_constant(ciObject * con,bool require_constant=false)1372   static const TypeNarrowOop* make_from_constant(ciObject* con, bool require_constant = false) {
1373     return make(TypeOopPtr::make_from_constant(con, require_constant));
1374   }
1375 
1376   static const TypeNarrowOop *BOTTOM;
1377   static const TypeNarrowOop *NULL_PTR;
1378 
remove_speculative() const1379   virtual const Type* remove_speculative() const {
1380     return make(_ptrtype->remove_speculative()->is_ptr());
1381   }
1382 
1383 #ifndef PRODUCT
1384   virtual void dump2( Dict &d, uint depth, outputStream *st ) const;
1385 #endif
1386 };
1387 
1388 //------------------------------TypeNarrowKlass----------------------------------
1389 // A compressed reference to klass pointer.  This type wraps around a
1390 // preexisting TypeKlassPtr and forwards most of it's operations to
1391 // the underlying type.
1392 class TypeNarrowKlass : public TypeNarrowPtr {
1393 protected:
TypeNarrowKlass(const TypePtr * ptrtype)1394   TypeNarrowKlass( const TypePtr* ptrtype): TypeNarrowPtr(NarrowKlass, ptrtype) {
1395   }
1396 
isa_same_narrowptr(const Type * t) const1397   virtual const TypeNarrowPtr *isa_same_narrowptr(const Type *t) const {
1398     return t->isa_narrowklass();
1399   }
1400 
is_same_narrowptr(const Type * t) const1401   virtual const TypeNarrowPtr *is_same_narrowptr(const Type *t) const {
1402     return t->is_narrowklass();
1403   }
1404 
make_same_narrowptr(const TypePtr * t) const1405   virtual const TypeNarrowPtr *make_same_narrowptr(const TypePtr *t) const {
1406     return new TypeNarrowKlass(t);
1407   }
1408 
make_hash_same_narrowptr(const TypePtr * t) const1409   virtual const TypeNarrowPtr *make_hash_same_narrowptr(const TypePtr *t) const {
1410     return (const TypeNarrowPtr*)((new TypeNarrowKlass(t))->hashcons());
1411   }
1412 
1413 public:
1414   static const TypeNarrowKlass *make( const TypePtr* type);
1415 
1416   // static const TypeNarrowKlass *BOTTOM;
1417   static const TypeNarrowKlass *NULL_PTR;
1418 
1419 #ifndef PRODUCT
1420   virtual void dump2( Dict &d, uint depth, outputStream *st ) const;
1421 #endif
1422 };
1423 
1424 //------------------------------TypeFunc---------------------------------------
1425 // Class of Array Types
1426 class TypeFunc : public Type {
TypeFunc(const TypeTuple * domain,const TypeTuple * range)1427   TypeFunc( const TypeTuple *domain, const TypeTuple *range ) : Type(Function),  _domain(domain), _range(range) {}
1428   virtual bool eq( const Type *t ) const;
1429   virtual int  hash() const;             // Type specific hashing
1430   virtual bool singleton(void) const;    // TRUE if type is a singleton
1431   virtual bool empty(void) const;        // TRUE if type is vacuous
1432 public:
1433   // Constants are shared among ADLC and VM
1434   enum { Control    = AdlcVMDeps::Control,
1435          I_O        = AdlcVMDeps::I_O,
1436          Memory     = AdlcVMDeps::Memory,
1437          FramePtr   = AdlcVMDeps::FramePtr,
1438          ReturnAdr  = AdlcVMDeps::ReturnAdr,
1439          Parms      = AdlcVMDeps::Parms
1440   };
1441 
1442   const TypeTuple* const _domain;     // Domain of inputs
1443   const TypeTuple* const _range;      // Range of results
1444 
1445   // Accessors:
domain() const1446   const TypeTuple* domain() const { return _domain; }
range() const1447   const TypeTuple* range()  const { return _range; }
1448 
1449   static const TypeFunc *make(ciMethod* method);
1450   static const TypeFunc *make(ciSignature signature, const Type* extra);
1451   static const TypeFunc *make(const TypeTuple* domain, const TypeTuple* range);
1452 
1453   virtual const Type *xmeet( const Type *t ) const;
1454   virtual const Type *xdual() const;    // Compute dual right now.
1455 
1456   BasicType return_type() const;
1457 
1458 #ifndef PRODUCT
1459   virtual void dump2( Dict &d, uint depth, outputStream *st ) const; // Specialized per-Type dumping
1460 #endif
1461   // Convenience common pre-built types.
1462 };
1463 
1464 //------------------------------accessors--------------------------------------
is_ptr_to_narrowoop() const1465 inline bool Type::is_ptr_to_narrowoop() const {
1466 #ifdef _LP64
1467   return (isa_oopptr() != NULL && is_oopptr()->is_ptr_to_narrowoop_nv());
1468 #else
1469   return false;
1470 #endif
1471 }
1472 
is_ptr_to_narrowklass() const1473 inline bool Type::is_ptr_to_narrowklass() const {
1474 #ifdef _LP64
1475   return (isa_oopptr() != NULL && is_oopptr()->is_ptr_to_narrowklass_nv());
1476 #else
1477   return false;
1478 #endif
1479 }
1480 
getf() const1481 inline float Type::getf() const {
1482   assert( _base == FloatCon, "Not a FloatCon" );
1483   return ((TypeF*)this)->_f;
1484 }
1485 
getd() const1486 inline double Type::getd() const {
1487   assert( _base == DoubleCon, "Not a DoubleCon" );
1488   return ((TypeD*)this)->_d;
1489 }
1490 
is_int() const1491 inline const TypeInt *Type::is_int() const {
1492   assert( _base == Int, "Not an Int" );
1493   return (TypeInt*)this;
1494 }
1495 
isa_int() const1496 inline const TypeInt *Type::isa_int() const {
1497   return ( _base == Int ? (TypeInt*)this : NULL);
1498 }
1499 
is_long() const1500 inline const TypeLong *Type::is_long() const {
1501   assert( _base == Long, "Not a Long" );
1502   return (TypeLong*)this;
1503 }
1504 
isa_long() const1505 inline const TypeLong *Type::isa_long() const {
1506   return ( _base == Long ? (TypeLong*)this : NULL);
1507 }
1508 
isa_float() const1509 inline const TypeF *Type::isa_float() const {
1510   return ((_base == FloatTop ||
1511            _base == FloatCon ||
1512            _base == FloatBot) ? (TypeF*)this : NULL);
1513 }
1514 
is_float_constant() const1515 inline const TypeF *Type::is_float_constant() const {
1516   assert( _base == FloatCon, "Not a Float" );
1517   return (TypeF*)this;
1518 }
1519 
isa_float_constant() const1520 inline const TypeF *Type::isa_float_constant() const {
1521   return ( _base == FloatCon ? (TypeF*)this : NULL);
1522 }
1523 
isa_double() const1524 inline const TypeD *Type::isa_double() const {
1525   return ((_base == DoubleTop ||
1526            _base == DoubleCon ||
1527            _base == DoubleBot) ? (TypeD*)this : NULL);
1528 }
1529 
is_double_constant() const1530 inline const TypeD *Type::is_double_constant() const {
1531   assert( _base == DoubleCon, "Not a Double" );
1532   return (TypeD*)this;
1533 }
1534 
isa_double_constant() const1535 inline const TypeD *Type::isa_double_constant() const {
1536   return ( _base == DoubleCon ? (TypeD*)this : NULL);
1537 }
1538 
is_tuple() const1539 inline const TypeTuple *Type::is_tuple() const {
1540   assert( _base == Tuple, "Not a Tuple" );
1541   return (TypeTuple*)this;
1542 }
1543 
is_ary() const1544 inline const TypeAry *Type::is_ary() const {
1545   assert( _base == Array , "Not an Array" );
1546   return (TypeAry*)this;
1547 }
1548 
is_vect() const1549 inline const TypeVect *Type::is_vect() const {
1550   assert( _base >= VectorS && _base <= VectorY, "Not a Vector" );
1551   return (TypeVect*)this;
1552 }
1553 
isa_vect() const1554 inline const TypeVect *Type::isa_vect() const {
1555   return (_base >= VectorS && _base <= VectorY) ? (TypeVect*)this : NULL;
1556 }
1557 
is_ptr() const1558 inline const TypePtr *Type::is_ptr() const {
1559   // AnyPtr is the first Ptr and KlassPtr the last, with no non-ptrs between.
1560   assert(_base >= AnyPtr && _base <= KlassPtr, "Not a pointer");
1561   return (TypePtr*)this;
1562 }
1563 
isa_ptr() const1564 inline const TypePtr *Type::isa_ptr() const {
1565   // AnyPtr is the first Ptr and KlassPtr the last, with no non-ptrs between.
1566   return (_base >= AnyPtr && _base <= KlassPtr) ? (TypePtr*)this : NULL;
1567 }
1568 
is_oopptr() const1569 inline const TypeOopPtr *Type::is_oopptr() const {
1570   // OopPtr is the first and KlassPtr the last, with no non-oops between.
1571   assert(_base >= OopPtr && _base <= AryPtr, "Not a Java pointer" ) ;
1572   return (TypeOopPtr*)this;
1573 }
1574 
isa_oopptr() const1575 inline const TypeOopPtr *Type::isa_oopptr() const {
1576   // OopPtr is the first and KlassPtr the last, with no non-oops between.
1577   return (_base >= OopPtr && _base <= AryPtr) ? (TypeOopPtr*)this : NULL;
1578 }
1579 
isa_rawptr() const1580 inline const TypeRawPtr *Type::isa_rawptr() const {
1581   return (_base == RawPtr) ? (TypeRawPtr*)this : NULL;
1582 }
1583 
is_rawptr() const1584 inline const TypeRawPtr *Type::is_rawptr() const {
1585   assert( _base == RawPtr, "Not a raw pointer" );
1586   return (TypeRawPtr*)this;
1587 }
1588 
isa_instptr() const1589 inline const TypeInstPtr *Type::isa_instptr() const {
1590   return (_base == InstPtr) ? (TypeInstPtr*)this : NULL;
1591 }
1592 
is_instptr() const1593 inline const TypeInstPtr *Type::is_instptr() const {
1594   assert( _base == InstPtr, "Not an object pointer" );
1595   return (TypeInstPtr*)this;
1596 }
1597 
isa_aryptr() const1598 inline const TypeAryPtr *Type::isa_aryptr() const {
1599   return (_base == AryPtr) ? (TypeAryPtr*)this : NULL;
1600 }
1601 
is_aryptr() const1602 inline const TypeAryPtr *Type::is_aryptr() const {
1603   assert( _base == AryPtr, "Not an array pointer" );
1604   return (TypeAryPtr*)this;
1605 }
1606 
is_narrowoop() const1607 inline const TypeNarrowOop *Type::is_narrowoop() const {
1608   // OopPtr is the first and KlassPtr the last, with no non-oops between.
1609   assert(_base == NarrowOop, "Not a narrow oop" ) ;
1610   return (TypeNarrowOop*)this;
1611 }
1612 
isa_narrowoop() const1613 inline const TypeNarrowOop *Type::isa_narrowoop() const {
1614   // OopPtr is the first and KlassPtr the last, with no non-oops between.
1615   return (_base == NarrowOop) ? (TypeNarrowOop*)this : NULL;
1616 }
1617 
is_narrowklass() const1618 inline const TypeNarrowKlass *Type::is_narrowklass() const {
1619   assert(_base == NarrowKlass, "Not a narrow oop" ) ;
1620   return (TypeNarrowKlass*)this;
1621 }
1622 
isa_narrowklass() const1623 inline const TypeNarrowKlass *Type::isa_narrowklass() const {
1624   return (_base == NarrowKlass) ? (TypeNarrowKlass*)this : NULL;
1625 }
1626 
is_metadataptr() const1627 inline const TypeMetadataPtr *Type::is_metadataptr() const {
1628   // MetadataPtr is the first and CPCachePtr the last
1629   assert(_base == MetadataPtr, "Not a metadata pointer" ) ;
1630   return (TypeMetadataPtr*)this;
1631 }
1632 
isa_metadataptr() const1633 inline const TypeMetadataPtr *Type::isa_metadataptr() const {
1634   return (_base == MetadataPtr) ? (TypeMetadataPtr*)this : NULL;
1635 }
1636 
isa_klassptr() const1637 inline const TypeKlassPtr *Type::isa_klassptr() const {
1638   return (_base == KlassPtr) ? (TypeKlassPtr*)this : NULL;
1639 }
1640 
is_klassptr() const1641 inline const TypeKlassPtr *Type::is_klassptr() const {
1642   assert( _base == KlassPtr, "Not a klass pointer" );
1643   return (TypeKlassPtr*)this;
1644 }
1645 
make_ptr() const1646 inline const TypePtr* Type::make_ptr() const {
1647   return (_base == NarrowOop) ? is_narrowoop()->get_ptrtype() :
1648     ((_base == NarrowKlass) ? is_narrowklass()->get_ptrtype() :
1649      (isa_ptr() ? is_ptr() : NULL));
1650 }
1651 
make_oopptr() const1652 inline const TypeOopPtr* Type::make_oopptr() const {
1653   return (_base == NarrowOop) ? is_narrowoop()->get_ptrtype()->is_oopptr() : is_oopptr();
1654 }
1655 
make_narrowoop() const1656 inline const TypeNarrowOop* Type::make_narrowoop() const {
1657   return (_base == NarrowOop) ? is_narrowoop() :
1658                                 (isa_ptr() ? TypeNarrowOop::make(is_ptr()) : NULL);
1659 }
1660 
make_narrowklass() const1661 inline const TypeNarrowKlass* Type::make_narrowklass() const {
1662   return (_base == NarrowKlass) ? is_narrowklass() :
1663                                 (isa_ptr() ? TypeNarrowKlass::make(is_ptr()) : NULL);
1664 }
1665 
is_floatingpoint() const1666 inline bool Type::is_floatingpoint() const {
1667   if( (_base == FloatCon)  || (_base == FloatBot) ||
1668       (_base == DoubleCon) || (_base == DoubleBot) )
1669     return true;
1670   return false;
1671 }
1672 
is_ptr_to_boxing_obj() const1673 inline bool Type::is_ptr_to_boxing_obj() const {
1674   const TypeInstPtr* tp = isa_instptr();
1675   return (tp != NULL) && (tp->offset() == 0) &&
1676          tp->klass()->is_instance_klass()  &&
1677          tp->klass()->as_instance_klass()->is_box_klass();
1678 }
1679 
1680 
1681 // ===============================================================
1682 // Things that need to be 64-bits in the 64-bit build but
1683 // 32-bits in the 32-bit build.  Done this way to get full
1684 // optimization AND strong typing.
1685 #ifdef _LP64
1686 
1687 // For type queries and asserts
1688 #define is_intptr_t  is_long
1689 #define isa_intptr_t isa_long
1690 #define find_intptr_t_type find_long_type
1691 #define find_intptr_t_con  find_long_con
1692 #define TypeX        TypeLong
1693 #define Type_X       Type::Long
1694 #define TypeX_X      TypeLong::LONG
1695 #define TypeX_ZERO   TypeLong::ZERO
1696 // For 'ideal_reg' machine registers
1697 #define Op_RegX      Op_RegL
1698 // For phase->intcon variants
1699 #define MakeConX     longcon
1700 #define ConXNode     ConLNode
1701 // For array index arithmetic
1702 #define MulXNode     MulLNode
1703 #define AndXNode     AndLNode
1704 #define OrXNode      OrLNode
1705 #define CmpXNode     CmpLNode
1706 #define SubXNode     SubLNode
1707 #define LShiftXNode  LShiftLNode
1708 // For object size computation:
1709 #define AddXNode     AddLNode
1710 #define RShiftXNode  RShiftLNode
1711 // For card marks and hashcodes
1712 #define URShiftXNode URShiftLNode
1713 // UseOptoBiasInlining
1714 #define XorXNode     XorLNode
1715 #define StoreXConditionalNode StoreLConditionalNode
1716 // Opcodes
1717 #define Op_LShiftX   Op_LShiftL
1718 #define Op_AndX      Op_AndL
1719 #define Op_AddX      Op_AddL
1720 #define Op_SubX      Op_SubL
1721 #define Op_XorX      Op_XorL
1722 #define Op_URShiftX  Op_URShiftL
1723 // conversions
1724 #define ConvI2X(x)   ConvI2L(x)
1725 #define ConvL2X(x)   (x)
1726 #define ConvX2I(x)   ConvL2I(x)
1727 #define ConvX2L(x)   (x)
1728 #define ConvX2UL(x)  (x)
1729 
1730 #else
1731 
1732 // For type queries and asserts
1733 #define is_intptr_t  is_int
1734 #define isa_intptr_t isa_int
1735 #define find_intptr_t_type find_int_type
1736 #define find_intptr_t_con  find_int_con
1737 #define TypeX        TypeInt
1738 #define Type_X       Type::Int
1739 #define TypeX_X      TypeInt::INT
1740 #define TypeX_ZERO   TypeInt::ZERO
1741 // For 'ideal_reg' machine registers
1742 #define Op_RegX      Op_RegI
1743 // For phase->intcon variants
1744 #define MakeConX     intcon
1745 #define ConXNode     ConINode
1746 // For array index arithmetic
1747 #define MulXNode     MulINode
1748 #define AndXNode     AndINode
1749 #define OrXNode      OrINode
1750 #define CmpXNode     CmpINode
1751 #define SubXNode     SubINode
1752 #define LShiftXNode  LShiftINode
1753 // For object size computation:
1754 #define AddXNode     AddINode
1755 #define RShiftXNode  RShiftINode
1756 // For card marks and hashcodes
1757 #define URShiftXNode URShiftINode
1758 // UseOptoBiasInlining
1759 #define XorXNode     XorINode
1760 #define StoreXConditionalNode StoreIConditionalNode
1761 // Opcodes
1762 #define Op_LShiftX   Op_LShiftI
1763 #define Op_AndX      Op_AndI
1764 #define Op_AddX      Op_AddI
1765 #define Op_SubX      Op_SubI
1766 #define Op_XorX      Op_XorI
1767 #define Op_URShiftX  Op_URShiftI
1768 // conversions
1769 #define ConvI2X(x)   (x)
1770 #define ConvL2X(x)   ConvL2I(x)
1771 #define ConvX2I(x)   (x)
1772 #define ConvX2L(x)   ConvI2L(x)
1773 #define ConvX2UL(x)  ConvI2UL(x)
1774 
1775 #endif
1776 
1777 #endif // SHARE_VM_OPTO_TYPE_HPP
1778