type.hpp revision 1472:c18cbe5936b8
1215911Sjfv/*
2215911Sjfv * Copyright (c) 1997, 2009, Oracle and/or its affiliates. All rights reserved.
3315333Serj * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4215911Sjfv *
5315333Serj * This code is free software; you can redistribute it and/or modify it
6315333Serj * under the terms of the GNU General Public License version 2 only, as
7215911Sjfv * published by the Free Software Foundation.
8315333Serj *
9315333Serj * This code is distributed in the hope that it will be useful, but WITHOUT
10215911Sjfv * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11315333Serj * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
12315333Serj * version 2 for more details (a copy is included in the LICENSE file that
13315333Serj * accompanied this code).
14215911Sjfv *
15315333Serj * You should have received a copy of the GNU General Public License version
16315333Serj * 2 along with this work; if not, write to the Free Software Foundation,
17315333Serj * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18215911Sjfv *
19315333Serj * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20215911Sjfv * or visit www.oracle.com if you need additional information or have any
21315333Serj * questions.
22315333Serj *
23315333Serj */
24315333Serj
25315333Serj// Portions of code courtesy of Clifford Click
26315333Serj
27315333Serj// Optimization - Graph Style
28315333Serj
29215911Sjfv
30215911Sjfv// This class defines a Type lattice.  The lattice is used in the constant
31215911Sjfv// propagation algorithms, and for some type-checking of the iloc code.
32215911Sjfv// Basic types include RSD's (lower bound, upper bound, stride for integers),
33215911Sjfv// float & double precision constants, sets of data-labels and code-labels.
34215911Sjfv// The complete lattice is described below.  Subtypes have no relationship to
35215911Sjfv// up or down in the lattice; that is entirely determined by the behavior of
36215911Sjfv// the MEET/JOIN functions.
37215911Sjfv
38215911Sjfvclass Dict;
39215911Sjfvclass Type;
40215911Sjfvclass   TypeD;
41215911Sjfvclass   TypeF;
42215911Sjfvclass   TypeInt;
43215911Sjfvclass   TypeLong;
44215911Sjfvclass   TypeNarrowOop;
45215911Sjfvclass   TypeAry;
46215911Sjfvclass   TypeTuple;
47215911Sjfvclass   TypePtr;
48215911Sjfvclass     TypeRawPtr;
49215911Sjfvclass     TypeOopPtr;
50215911Sjfvclass       TypeInstPtr;
51215911Sjfvclass       TypeAryPtr;
52215911Sjfvclass       TypeKlassPtr;
53215911Sjfv
54215911Sjfv//------------------------------Type-------------------------------------------
55215911Sjfv// Basic Type object, represents a set of primitive Values.
56215911Sjfv// Types are hash-cons'd into a private class dictionary, so only one of each
57215911Sjfv// different kind of Type exists.  Types are never modified after creation, so
58215911Sjfv// all their interesting fields are constant.
59215911Sjfvclass Type {
60215911Sjfvpublic:
61215911Sjfv  enum TYPES {
62215911Sjfv    Bad=0,                      // Type check
63215911Sjfv    Control,                    // Control of code (not in lattice)
64215911Sjfv    Top,                        // Top of the lattice
65215911Sjfv    Int,                        // Integer range (lo-hi)
66215911Sjfv    Long,                       // Long integer range (lo-hi)
67215911Sjfv    Half,                       // Placeholder half of doubleword
68215911Sjfv    NarrowOop,                  // Compressed oop pointer
69215911Sjfv
70215911Sjfv    Tuple,                      // Method signature or object layout
71215911Sjfv    Array,                      // Array types
72215911Sjfv
73215911Sjfv    AnyPtr,                     // Any old raw, klass, inst, or array pointer
74215911Sjfv    RawPtr,                     // Raw (non-oop) pointers
75215911Sjfv    OopPtr,                     // Any and all Java heap entities
76215911Sjfv    InstPtr,                    // Instance pointers (non-array objects)
77215911Sjfv    AryPtr,                     // Array pointers
78215911Sjfv    KlassPtr,                   // Klass pointers
79215911Sjfv    // (Ptr order matters:  See is_ptr, isa_ptr, is_oopptr, isa_oopptr.)
80283620Serj
81215911Sjfv    Function,                   // Function signature
82283620Serj    Abio,                       // Abstract I/O
83283620Serj    Return_Address,             // Subroutine return address
84283620Serj    Memory,                     // Abstract store
85215911Sjfv    FloatTop,                   // No float value
86215911Sjfv    FloatCon,                   // Floating point constant
87215911Sjfv    FloatBot,                   // Any float value
88215911Sjfv    DoubleTop,                  // No double value
89215911Sjfv    DoubleCon,                  // Double precision constant
90215911Sjfv    DoubleBot,                  // Any double value
91215911Sjfv    Bottom,                     // Bottom of lattice
92215911Sjfv    lastype                     // Bogus ending type (not in lattice)
93215911Sjfv  };
94215911Sjfv
95215911Sjfv  // Signal values for offsets from a base pointer
96215911Sjfv  enum OFFSET_SIGNALS {
97215911Sjfv    OffsetTop = -2000000000,    // undefined offset
98215911Sjfv    OffsetBot = -2000000001     // any possible offset
99215911Sjfv  };
100215911Sjfv
101215911Sjfv  // Min and max WIDEN values.
102215911Sjfv  enum WIDEN {
103215911Sjfv    WidenMin = 0,
104215911Sjfv    WidenMax = 3
105215911Sjfv  };
106215911Sjfv
107215911Sjfvprivate:
108215911Sjfv  // Dictionary of types shared among compilations.
109215911Sjfv  static Dict* _shared_type_dict;
110215911Sjfv
111215911Sjfv  static int uhash( const Type *const t );
112215911Sjfv  // Structural equality check.  Assumes that cmp() has already compared
113215911Sjfv  // the _base types and thus knows it can cast 't' appropriately.
114215911Sjfv  virtual bool eq( const Type *t ) const;
115215911Sjfv
116215911Sjfv  // Top-level hash-table of types
117215911Sjfv  static Dict *type_dict() {
118215911Sjfv    return Compile::current()->type_dict();
119215911Sjfv  }
120215911Sjfv
121215911Sjfv  // DUAL operation: reflect around lattice centerline.  Used instead of
122215911Sjfv  // join to ensure my lattice is symmetric up and down.  Dual is computed
123215911Sjfv  // lazily, on demand, and cached in _dual.
124215911Sjfv  const Type *_dual;            // Cached dual value
125215911Sjfv  // Table for efficient dualing of base types
126215911Sjfv  static const TYPES dual_type[lastype];
127215911Sjfv
128215911Sjfvprotected:
129215911Sjfv  // Each class of type is also identified by its base.
130215911Sjfv  const TYPES _base;            // Enum of Types type
131215911Sjfv
132215911Sjfv  Type( TYPES t ) : _dual(NULL),  _base(t) {} // Simple types
133215911Sjfv  // ~Type();                   // Use fast deallocation
134215911Sjfv  const Type *hashcons();       // Hash-cons the type
135215911Sjfv
136215911Sjfvpublic:
137215911Sjfv
138215911Sjfv  inline void* operator new( size_t x ) {
139215911Sjfv    Compile* compile = Compile::current();
140215911Sjfv    compile->set_type_last_size(x);
141215911Sjfv    void *temp = compile->type_arena()->Amalloc_D(x);
142215911Sjfv    compile->set_type_hwm(temp);
143215911Sjfv    return temp;
144215911Sjfv  }
145215911Sjfv  inline void operator delete( void* ptr ) {
146215911Sjfv    Compile* compile = Compile::current();
147215911Sjfv    compile->type_arena()->Afree(ptr,compile->type_last_size());
148215911Sjfv  }
149215911Sjfv
150215911Sjfv  // Initialize the type system for a particular compilation.
151215911Sjfv  static void Initialize(Compile* compile);
152215911Sjfv
153215911Sjfv  // Initialize the types shared by all compilations.
154215911Sjfv  static void Initialize_shared(Compile* compile);
155215911Sjfv
156215911Sjfv  TYPES base() const {
157215911Sjfv    assert(_base > Bad && _base < lastype, "sanity");
158215911Sjfv    return _base;
159215911Sjfv  }
160215911Sjfv
161215911Sjfv  // Create a new hash-consd type
162215911Sjfv  static const Type *make(enum TYPES);
163215911Sjfv  // Test for equivalence of types
164215911Sjfv  static int cmp( const Type *const t1, const Type *const t2 );
165215911Sjfv  // Test for higher or equal in lattice
166215911Sjfv  int higher_equal( const Type *t ) const { return !cmp(meet(t),t); }
167215911Sjfv
168215911Sjfv  // MEET operation; lower in lattice.
169215911Sjfv  const Type *meet( const Type *t ) const;
170215911Sjfv  // WIDEN: 'widens' for Ints and other range types
171215911Sjfv  virtual const Type *widen( const Type *old, const Type* limit ) const { return this; }
172215911Sjfv  // NARROW: complement for widen, used by pessimistic phases
173215911Sjfv  virtual const Type *narrow( const Type *old ) const { return this; }
174283620Serj
175283620Serj  // DUAL operation: reflect around lattice centerline.  Used instead of
176283620Serj  // join to ensure my lattice is symmetric up and down.
177283620Serj  const Type *dual() const { return _dual; }
178215911Sjfv
179215911Sjfv  // Compute meet dependent on base type
180215911Sjfv  virtual const Type *xmeet( const Type *t ) const;
181215911Sjfv  virtual const Type *xdual() const;    // Compute dual right now.
182215911Sjfv
183215911Sjfv  // JOIN operation; higher in lattice.  Done by finding the dual of the
184215911Sjfv  // meet of the dual of the 2 inputs.
185215911Sjfv  const Type *join( const Type *t ) const {
186215911Sjfv    return dual()->meet(t->dual())->dual(); }
187215911Sjfv
188215911Sjfv  // Modified version of JOIN adapted to the needs Node::Value.
189215911Sjfv  // Normalizes all empty values to TOP.  Does not kill _widen bits.
190215911Sjfv  // Currently, it also works around limitations involving interface types.
191215911Sjfv  virtual const Type *filter( const Type *kills ) const;
192215911Sjfv
193215911Sjfv#ifdef ASSERT
194215911Sjfv  // One type is interface, the other is oop
195215911Sjfv  virtual bool interface_vs_oop(const Type *t) const;
196215911Sjfv#endif
197215911Sjfv
198215911Sjfv  // Returns true if this pointer points at memory which contains a
199215911Sjfv  // compressed oop references.
200215911Sjfv  bool is_ptr_to_narrowoop() const;
201215911Sjfv
202215911Sjfv  // Convenience access
203215911Sjfv  float getf() const;
204215911Sjfv  double getd() const;
205215911Sjfv
206283620Serj  const TypeInt    *is_int() const;
207283620Serj  const TypeInt    *isa_int() const;             // Returns NULL if not an Int
208283620Serj  const TypeLong   *is_long() const;
209283620Serj  const TypeLong   *isa_long() const;            // Returns NULL if not a Long
210215911Sjfv  const TypeD      *is_double_constant() const;  // Asserts it is a DoubleCon
211215911Sjfv  const TypeD      *isa_double_constant() const; // Returns NULL if not a DoubleCon
212215911Sjfv  const TypeF      *is_float_constant() const;   // Asserts it is a FloatCon
213215911Sjfv  const TypeF      *isa_float_constant() const;  // Returns NULL if not a FloatCon
214215911Sjfv  const TypeTuple  *is_tuple() const;            // Collection of fields, NOT a pointer
215215911Sjfv  const TypeAry    *is_ary() const;              // Array, NOT array pointer
216215911Sjfv  const TypePtr    *is_ptr() const;              // Asserts it is a ptr type
217215911Sjfv  const TypePtr    *isa_ptr() const;             // Returns NULL if not ptr type
218215911Sjfv  const TypeRawPtr *isa_rawptr() const;          // NOT Java oop
219215911Sjfv  const TypeRawPtr *is_rawptr() const;           // Asserts is rawptr
220215911Sjfv  const TypeNarrowOop  *is_narrowoop() const;    // Java-style GC'd pointer
221215911Sjfv  const TypeNarrowOop  *isa_narrowoop() const;   // Returns NULL if not oop ptr type
222215911Sjfv  const TypeOopPtr   *isa_oopptr() const;        // Returns NULL if not oop ptr type
223215911Sjfv  const TypeOopPtr   *is_oopptr() const;         // Java-style GC'd pointer
224215911Sjfv  const TypeKlassPtr *isa_klassptr() const;      // Returns NULL if not KlassPtr
225215911Sjfv  const TypeKlassPtr *is_klassptr() const;       // assert if not KlassPtr
226215911Sjfv  const TypeInstPtr  *isa_instptr() const;       // Returns NULL if not InstPtr
227215911Sjfv  const TypeInstPtr  *is_instptr() const;        // Instance
228215911Sjfv  const TypeAryPtr   *isa_aryptr() const;        // Returns NULL if not AryPtr
229215911Sjfv  const TypeAryPtr   *is_aryptr() const;         // Array oop
230215911Sjfv  virtual bool      is_finite() const;           // Has a finite value
231215911Sjfv  virtual bool      is_nan()    const;           // Is not a number (NaN)
232215911Sjfv
233215911Sjfv  // Returns this ptr type or the equivalent ptr type for this compressed pointer.
234215911Sjfv  const TypePtr* make_ptr() const;
235215911Sjfv
236215911Sjfv  // Returns this oopptr type or the equivalent oopptr type for this compressed pointer.
237215911Sjfv  // Asserts if the underlying type is not an oopptr or narrowoop.
238215911Sjfv  const TypeOopPtr* make_oopptr() const;
239215911Sjfv
240215911Sjfv  // Returns this compressed pointer or the equivalent compressed version
241215911Sjfv  // of this pointer type.
242215911Sjfv  const TypeNarrowOop* make_narrowoop() const;
243215911Sjfv
244215911Sjfv  // Special test for register pressure heuristic
245215911Sjfv  bool is_floatingpoint() const;        // True if Float or Double base type
246215911Sjfv
247215911Sjfv  // Do you have memory, directly or through a tuple?
248215911Sjfv  bool has_memory( ) const;
249215911Sjfv
250215911Sjfv  // Are you a pointer type or not?
251215911Sjfv  bool isa_oop_ptr() const;
252215911Sjfv
253215911Sjfv  // TRUE if type is a singleton
254230775Sjfv  virtual bool singleton(void) const;
255215911Sjfv
256215911Sjfv  // TRUE if type is above the lattice centerline, and is therefore vacuous
257215911Sjfv  virtual bool empty(void) const;
258215911Sjfv
259215911Sjfv  // Return a hash for this type.  The hash function is public so ConNode
260215911Sjfv  // (constants) can hash on their constant, which is represented by a Type.
261215911Sjfv  virtual int hash() const;
262215911Sjfv
263215911Sjfv  // Map ideal registers (machine types) to ideal types
264215911Sjfv  static const Type *mreg2type[];
265215911Sjfv
266215911Sjfv  // Printing, statistics
267215911Sjfv  static const char * const msg[lastype]; // Printable strings
268215911Sjfv#ifndef PRODUCT
269215911Sjfv  void         dump_on(outputStream *st) const;
270215911Sjfv  void         dump() const {
271215911Sjfv    dump_on(tty);
272215911Sjfv  }
273215911Sjfv  virtual void dump2( Dict &d, uint depth, outputStream *st ) const;
274215911Sjfv  static  void dump_stats();
275215911Sjfv  static  void verify_lastype();          // Check that arrays match type enum
276215911Sjfv#endif
277215911Sjfv  void typerr(const Type *t) const; // Mixing types error
278215911Sjfv
279215911Sjfv  // Create basic type
280215911Sjfv  static const Type* get_const_basic_type(BasicType type) {
281215911Sjfv    assert((uint)type <= T_CONFLICT && _const_basic_type[type] != NULL, "bad type");
282215911Sjfv    return _const_basic_type[type];
283215911Sjfv  }
284215911Sjfv
285215911Sjfv  // Mapping to the array element's basic type.
286215911Sjfv  BasicType array_element_basic_type() const;
287215911Sjfv
288215911Sjfv  // Create standard type for a ciType:
289215911Sjfv  static const Type* get_const_type(ciType* type);
290215911Sjfv
291215911Sjfv  // Create standard zero value:
292215911Sjfv  static const Type* get_zero_type(BasicType type) {
293215911Sjfv    assert((uint)type <= T_CONFLICT && _zero_type[type] != NULL, "bad type");
294215911Sjfv    return _zero_type[type];
295215911Sjfv  }
296215911Sjfv
297215911Sjfv  // Report if this is a zero value (not top).
298215911Sjfv  bool is_zero_type() const {
299215911Sjfv    BasicType type = basic_type();
300215911Sjfv    if (type == T_VOID || type >= T_CONFLICT)
301215911Sjfv      return false;
302215911Sjfv    else
303215911Sjfv      return (this == _zero_type[type]);
304215911Sjfv  }
305215911Sjfv
306215911Sjfv  // Convenience common pre-built types.
307215911Sjfv  static const Type *ABIO;
308215911Sjfv  static const Type *BOTTOM;
309215911Sjfv  static const Type *CONTROL;
310215911Sjfv  static const Type *DOUBLE;
311215911Sjfv  static const Type *FLOAT;
312215911Sjfv  static const Type *HALF;
313215911Sjfv  static const Type *MEMORY;
314215911Sjfv  static const Type *MULTI;
315215911Sjfv  static const Type *RETURN_ADDRESS;
316215911Sjfv  static const Type *TOP;
317215911Sjfv
318215911Sjfv  // Mapping from compiler type to VM BasicType
319215911Sjfv  BasicType basic_type() const { return _basic_type[_base]; }
320215911Sjfv
321215911Sjfv  // Mapping from CI type system to compiler type:
322215911Sjfv  static const Type* get_typeflow_type(ciType* type);
323215911Sjfv
324215911Sjfvprivate:
325215911Sjfv  // support arrays
326215911Sjfv  static const BasicType _basic_type[];
327215911Sjfv  static const Type*        _zero_type[T_CONFLICT+1];
328215911Sjfv  static const Type* _const_basic_type[T_CONFLICT+1];
329215911Sjfv};
330215911Sjfv
331215911Sjfv//------------------------------TypeF------------------------------------------
332215911Sjfv// Class of Float-Constant Types.
333215911Sjfvclass TypeF : public Type {
334215911Sjfv  TypeF( float f ) : Type(FloatCon), _f(f) {};
335215911Sjfvpublic:
336215911Sjfv  virtual bool eq( const Type *t ) const;
337215911Sjfv  virtual int  hash() const;             // Type specific hashing
338230775Sjfv  virtual bool singleton(void) const;    // TRUE if type is a singleton
339215911Sjfv  virtual bool empty(void) const;        // TRUE if type is vacuous
340215911Sjfvpublic:
341215911Sjfv  const float _f;               // Float constant
342215911Sjfv
343215911Sjfv  static const TypeF *make(float f);
344215911Sjfv
345215911Sjfv  virtual bool        is_finite() const;  // Has a finite value
346215911Sjfv  virtual bool        is_nan()    const;  // Is not a number (NaN)
347215911Sjfv
348215911Sjfv  virtual const Type *xmeet( const Type *t ) const;
349215911Sjfv  virtual const Type *xdual() const;    // Compute dual right now.
350215911Sjfv  // Convenience common pre-built types.
351215911Sjfv  static const TypeF *ZERO; // positive zero only
352215911Sjfv  static const TypeF *ONE;
353215911Sjfv#ifndef PRODUCT
354215911Sjfv  virtual void dump2( Dict &d, uint depth, outputStream *st ) const;
355215911Sjfv#endif
356215911Sjfv};
357215911Sjfv
358215911Sjfv//------------------------------TypeD------------------------------------------
359215911Sjfv// Class of Double-Constant Types.
360230775Sjfvclass TypeD : public Type {
361215911Sjfv  TypeD( double d ) : Type(DoubleCon), _d(d) {};
362215911Sjfvpublic:
363215911Sjfv  virtual bool eq( const Type *t ) const;
364215911Sjfv  virtual int  hash() const;             // Type specific hashing
365215911Sjfv  virtual bool singleton(void) const;    // TRUE if type is a singleton
366215911Sjfv  virtual bool empty(void) const;        // TRUE if type is vacuous
367215911Sjfvpublic:
368215911Sjfv  const double _d;              // Double constant
369215911Sjfv
370215911Sjfv  static const TypeD *make(double d);
371215911Sjfv
372215911Sjfv  virtual bool        is_finite() const;  // Has a finite value
373215911Sjfv  virtual bool        is_nan()    const;  // Is not a number (NaN)
374215911Sjfv
375215911Sjfv  virtual const Type *xmeet( const Type *t ) const;
376215911Sjfv  virtual const Type *xdual() const;    // Compute dual right now.
377215911Sjfv  // Convenience common pre-built types.
378215911Sjfv  static const TypeD *ZERO; // positive zero only
379215911Sjfv  static const TypeD *ONE;
380215911Sjfv#ifndef PRODUCT
381215911Sjfv  virtual void dump2( Dict &d, uint depth, outputStream *st ) const;
382230775Sjfv#endif
383215911Sjfv};
384215911Sjfv
385215911Sjfv//------------------------------TypeInt----------------------------------------
386230775Sjfv// Class of integer ranges, the set of integers between a lower bound and an
387215911Sjfv// upper bound, inclusive.
388215911Sjfvclass TypeInt : public Type {
389215911Sjfv  TypeInt( jint lo, jint hi, int w );
390215911Sjfvpublic:
391215911Sjfv  virtual bool eq( const Type *t ) const;
392215911Sjfv  virtual int  hash() const;             // Type specific hashing
393215911Sjfv  virtual bool singleton(void) const;    // TRUE if type is a singleton
394215911Sjfv  virtual bool empty(void) const;        // TRUE if type is vacuous
395215911Sjfvpublic:
396215911Sjfv  const jint _lo, _hi;          // Lower bound, upper bound
397215911Sjfv  const short _widen;           // Limit on times we widen this sucker
398215911Sjfv
399215911Sjfv  static const TypeInt *make(jint lo);
400215911Sjfv  // must always specify w
401215911Sjfv  static const TypeInt *make(jint lo, jint hi, int w);
402215911Sjfv
403215911Sjfv  // Check for single integer
404215911Sjfv  int is_con() const { return _lo==_hi; }
405215911Sjfv  bool is_con(int i) const { return is_con() && _lo == i; }
406215911Sjfv  jint get_con() const { assert( is_con(), "" );  return _lo; }
407215911Sjfv
408215911Sjfv  virtual bool        is_finite() const;  // Has a finite value
409215911Sjfv
410215911Sjfv  virtual const Type *xmeet( const Type *t ) const;
411215911Sjfv  virtual const Type *xdual() const;    // Compute dual right now.
412215911Sjfv  virtual const Type *widen( const Type *t, const Type* limit_type ) const;
413215911Sjfv  virtual const Type *narrow( const Type *t ) const;
414215911Sjfv  // Do not kill _widen bits.
415215911Sjfv  virtual const Type *filter( const Type *kills ) const;
416215911Sjfv  // Convenience common pre-built types.
417215911Sjfv  static const TypeInt *MINUS_1;
418215911Sjfv  static const TypeInt *ZERO;
419215911Sjfv  static const TypeInt *ONE;
420215911Sjfv  static const TypeInt *BOOL;
421215911Sjfv  static const TypeInt *CC;
422215911Sjfv  static const TypeInt *CC_LT;  // [-1]  == MINUS_1
423215911Sjfv  static const TypeInt *CC_GT;  // [1]   == ONE
424215911Sjfv  static const TypeInt *CC_EQ;  // [0]   == ZERO
425215911Sjfv  static const TypeInt *CC_LE;  // [-1,0]
426230775Sjfv  static const TypeInt *CC_GE;  // [0,1] == BOOL (!)
427215911Sjfv  static const TypeInt *BYTE;
428215911Sjfv  static const TypeInt *UBYTE;
429215911Sjfv  static const TypeInt *CHAR;
430215911Sjfv  static const TypeInt *SHORT;
431230775Sjfv  static const TypeInt *POS;
432215911Sjfv  static const TypeInt *POS1;
433215911Sjfv  static const TypeInt *INT;
434215911Sjfv  static const TypeInt *SYMINT; // symmetric range [-max_jint..max_jint]
435215911Sjfv#ifndef PRODUCT
436215911Sjfv  virtual void dump2( Dict &d, uint depth, outputStream *st ) const;
437215911Sjfv#endif
438215911Sjfv};
439215911Sjfv
440215911Sjfv
441215911Sjfv//------------------------------TypeLong---------------------------------------
442215911Sjfv// Class of long integer ranges, the set of integers between a lower bound and
443215911Sjfv// an upper bound, inclusive.
444215911Sjfvclass TypeLong : public Type {
445215911Sjfv  TypeLong( jlong lo, jlong hi, int w );
446215911Sjfvpublic:
447215911Sjfv  virtual bool eq( const Type *t ) const;
448215911Sjfv  virtual int  hash() const;             // Type specific hashing
449215911Sjfv  virtual bool singleton(void) const;    // TRUE if type is a singleton
450215911Sjfv  virtual bool empty(void) const;        // TRUE if type is vacuous
451215911Sjfvpublic:
452215911Sjfv  const jlong _lo, _hi;         // Lower bound, upper bound
453215911Sjfv  const short _widen;           // Limit on times we widen this sucker
454215911Sjfv
455215911Sjfv  static const TypeLong *make(jlong lo);
456215911Sjfv  // must always specify w
457215911Sjfv  static const TypeLong *make(jlong lo, jlong hi, int w);
458215911Sjfv
459215911Sjfv  // Check for single integer
460215911Sjfv  int is_con() const { return _lo==_hi; }
461215911Sjfv  bool is_con(int i) const { return is_con() && _lo == i; }
462215911Sjfv  jlong get_con() const { assert( is_con(), "" ); return _lo; }
463215911Sjfv
464215911Sjfv  virtual bool        is_finite() const;  // Has a finite value
465215911Sjfv
466215911Sjfv  virtual const Type *xmeet( const Type *t ) const;
467215911Sjfv  virtual const Type *xdual() const;    // Compute dual right now.
468230775Sjfv  virtual const Type *widen( const Type *t, const Type* limit_type ) const;
469215911Sjfv  virtual const Type *narrow( const Type *t ) const;
470215911Sjfv  // Do not kill _widen bits.
471215911Sjfv  virtual const Type *filter( const Type *kills ) const;
472215911Sjfv  // Convenience common pre-built types.
473215911Sjfv  static const TypeLong *MINUS_1;
474230775Sjfv  static const TypeLong *ZERO;
475215911Sjfv  static const TypeLong *ONE;
476215911Sjfv  static const TypeLong *POS;
477215911Sjfv  static const TypeLong *LONG;
478215911Sjfv  static const TypeLong *INT;    // 32-bit subrange [min_jint..max_jint]
479215911Sjfv  static const TypeLong *UINT;   // 32-bit unsigned [0..max_juint]
480215911Sjfv#ifndef PRODUCT
481215911Sjfv  virtual void dump2( Dict &d, uint, outputStream *st  ) const;// Specialized per-Type dumping
482215911Sjfv#endif
483215911Sjfv};
484215911Sjfv
485215911Sjfv//------------------------------TypeTuple--------------------------------------
486215911Sjfv// Class of Tuple Types, essentially type collections for function signatures
487215911Sjfv// and class layouts.  It happens to also be a fast cache for the HotSpot
488215911Sjfv// signature types.
489215911Sjfvclass TypeTuple : public Type {
490215911Sjfv  TypeTuple( uint cnt, const Type **fields ) : Type(Tuple), _cnt(cnt), _fields(fields) { }
491215911Sjfvpublic:
492215911Sjfv  virtual bool eq( const Type *t ) const;
493215911Sjfv  virtual int  hash() const;             // Type specific hashing
494215911Sjfv  virtual bool singleton(void) const;    // TRUE if type is a singleton
495215911Sjfv  virtual bool empty(void) const;        // TRUE if type is vacuous
496215911Sjfv
497215911Sjfvpublic:
498215911Sjfv  const uint          _cnt;              // Count of fields
499215911Sjfv  const Type ** const _fields;           // Array of field types
500215911Sjfv
501215911Sjfv  // Accessors:
502215911Sjfv  uint cnt() const { return _cnt; }
503215911Sjfv  const Type* field_at(uint i) const {
504215911Sjfv    assert(i < _cnt, "oob");
505215911Sjfv    return _fields[i];
506215911Sjfv  }
507215911Sjfv  void set_field_at(uint i, const Type* t) {
508215911Sjfv    assert(i < _cnt, "oob");
509215911Sjfv    _fields[i] = t;
510215911Sjfv  }
511215911Sjfv
512215911Sjfv  static const TypeTuple *make( uint cnt, const Type **fields );
513215911Sjfv  static const TypeTuple *make_range(ciSignature *sig);
514215911Sjfv  static const TypeTuple *make_domain(ciInstanceKlass* recv, ciSignature *sig);
515215911Sjfv
516215911Sjfv  // Subroutine call type with space allocated for argument types
517215911Sjfv  static const Type **fields( uint arg_cnt );
518215911Sjfv
519215911Sjfv  virtual const Type *xmeet( const Type *t ) const;
520215911Sjfv  virtual const Type *xdual() const;    // Compute dual right now.
521215911Sjfv  // Convenience common pre-built types.
522215911Sjfv  static const TypeTuple *IFBOTH;
523215911Sjfv  static const TypeTuple *IFFALSE;
524215911Sjfv  static const TypeTuple *IFTRUE;
525215911Sjfv  static const TypeTuple *IFNEITHER;
526215911Sjfv  static const TypeTuple *LOOPBODY;
527215911Sjfv  static const TypeTuple *MEMBAR;
528215911Sjfv  static const TypeTuple *STORECONDITIONAL;
529215911Sjfv  static const TypeTuple *START_I2C;
530215911Sjfv  static const TypeTuple *INT_PAIR;
531215911Sjfv  static const TypeTuple *LONG_PAIR;
532215911Sjfv#ifndef PRODUCT
533215911Sjfv  virtual void dump2( Dict &d, uint, outputStream *st  ) const; // Specialized per-Type dumping
534215911Sjfv#endif
535215911Sjfv};
536215911Sjfv
537215911Sjfv//------------------------------TypeAry----------------------------------------
538215911Sjfv// Class of Array Types
539215911Sjfvclass TypeAry : public Type {
540215911Sjfv  TypeAry( const Type *elem, const TypeInt *size) : Type(Array),
541215911Sjfv    _elem(elem), _size(size) {}
542215911Sjfvpublic:
543215911Sjfv  virtual bool eq( const Type *t ) const;
544215911Sjfv  virtual int  hash() const;             // Type specific hashing
545215911Sjfv  virtual bool singleton(void) const;    // TRUE if type is a singleton
546215911Sjfv  virtual bool empty(void) const;        // TRUE if type is vacuous
547215911Sjfv
548215911Sjfvprivate:
549215911Sjfv  const Type *_elem;            // Element type of array
550215911Sjfv  const TypeInt *_size;         // Elements in array
551215911Sjfv  friend class TypeAryPtr;
552215911Sjfv
553215911Sjfvpublic:
554215911Sjfv  static const TypeAry *make(  const Type *elem, const TypeInt *size);
555215911Sjfv
556230775Sjfv  virtual const Type *xmeet( const Type *t ) const;
557215911Sjfv  virtual const Type *xdual() const;    // Compute dual right now.
558215911Sjfv  bool ary_must_be_exact() const;  // true if arrays of such are never generic
559215911Sjfv#ifdef ASSERT
560215911Sjfv  // One type is interface, the other is oop
561215911Sjfv  virtual bool interface_vs_oop(const Type *t) const;
562215911Sjfv#endif
563215911Sjfv#ifndef PRODUCT
564215911Sjfv  virtual void dump2( Dict &d, uint, outputStream *st  ) const; // Specialized per-Type dumping
565215911Sjfv#endif
566215911Sjfv};
567215911Sjfv
568215911Sjfv//------------------------------TypePtr----------------------------------------
569215911Sjfv// Class of machine Pointer Types: raw data, instances or arrays.
570215911Sjfv// If the _base enum is AnyPtr, then this refers to all of the above.
571215911Sjfv// Otherwise the _base will indicate which subset of pointers is affected,
572215911Sjfv// and the class will be inherited from.
573215911Sjfvclass TypePtr : public Type {
574215911Sjfv  friend class TypeNarrowOop;
575215911Sjfvpublic:
576215911Sjfv  enum PTR { TopPTR, AnyNull, Constant, Null, NotNull, BotPTR, lastPTR };
577215911Sjfvprotected:
578215911Sjfv  TypePtr( TYPES t, PTR ptr, int offset ) : Type(t), _ptr(ptr), _offset(offset) {}
579215911Sjfv  virtual bool eq( const Type *t ) const;
580230775Sjfv  virtual int  hash() const;             // Type specific hashing
581215911Sjfv  static const PTR ptr_meet[lastPTR][lastPTR];
582215911Sjfv  static const PTR ptr_dual[lastPTR];
583215911Sjfv  static const char * const ptr_msg[lastPTR];
584215911Sjfv
585215911Sjfvpublic:
586215911Sjfv  const int _offset;            // Offset into oop, with TOP & BOT
587215911Sjfv  const PTR _ptr;               // Pointer equivalence class
588215911Sjfv
589215911Sjfv  const int offset() const { return _offset; }
590215911Sjfv  const PTR ptr()    const { return _ptr; }
591215911Sjfv
592215911Sjfv  static const TypePtr *make( TYPES t, PTR ptr, int offset );
593215911Sjfv
594215911Sjfv  // Return a 'ptr' version of this type
595215911Sjfv  virtual const Type *cast_to_ptr_type(PTR ptr) const;
596215911Sjfv
597215911Sjfv  virtual intptr_t get_con() const;
598215911Sjfv
599215911Sjfv  int xadd_offset( intptr_t offset ) const;
600215911Sjfv  virtual const TypePtr *add_offset( intptr_t offset ) const;
601215911Sjfv
602215911Sjfv  virtual bool singleton(void) const;    // TRUE if type is a singleton
603215911Sjfv  virtual bool empty(void) const;        // TRUE if type is vacuous
604217593Sjfv  virtual const Type *xmeet( const Type *t ) const;
605217593Sjfv  int meet_offset( int offset ) const;
606215911Sjfv  int dual_offset( ) const;
607217593Sjfv  virtual const Type *xdual() const;    // Compute dual right now.
608283620Serj
609283620Serj  // meet, dual and join over pointer equivalence sets
610315333Serj  PTR meet_ptr( const PTR in_ptr ) const { return ptr_meet[in_ptr][ptr()]; }
611230775Sjfv  PTR dual_ptr()                   const { return ptr_dual[ptr()];      }
612230775Sjfv
613230775Sjfv  // This is textually confusing unless one recalls that
614217593Sjfv  // join(t) == dual()->meet(t->dual())->dual().
615217593Sjfv  PTR join_ptr( const PTR in_ptr ) const {
616217593Sjfv    return ptr_dual[ ptr_meet[ ptr_dual[in_ptr] ] [ dual_ptr() ] ];
617215911Sjfv  }
618215911Sjfv
619215911Sjfv  // Tests for relation to centerline of type lattice:
620215911Sjfv  static bool above_centerline(PTR ptr) { return (ptr <= AnyNull); }
621215911Sjfv  static bool below_centerline(PTR ptr) { return (ptr >= NotNull); }
622215911Sjfv  // Convenience common pre-built types.
623215911Sjfv  static const TypePtr *NULL_PTR;
624215911Sjfv  static const TypePtr *NOTNULL;
625215911Sjfv  static const TypePtr *BOTTOM;
626215911Sjfv#ifndef PRODUCT
627215911Sjfv  virtual void dump2( Dict &d, uint depth, outputStream *st  ) const;
628215911Sjfv#endif
629215911Sjfv};
630215911Sjfv
631215911Sjfv//------------------------------TypeRawPtr-------------------------------------
632215911Sjfv// Class of raw pointers, pointers to things other than Oops.  Examples
633215911Sjfv// include the stack pointer, top of heap, card-marking area, handles, etc.
634215911Sjfvclass TypeRawPtr : public TypePtr {
635215911Sjfvprotected:
636215911Sjfv  TypeRawPtr( PTR ptr, address bits ) : TypePtr(RawPtr,ptr,0), _bits(bits){}
637215911Sjfvpublic:
638215911Sjfv  virtual bool eq( const Type *t ) const;
639215911Sjfv  virtual int  hash() const;     // Type specific hashing
640215911Sjfv
641215911Sjfv  const address _bits;          // Constant value, if applicable
642215911Sjfv
643215911Sjfv  static const TypeRawPtr *make( PTR ptr );
644215911Sjfv  static const TypeRawPtr *make( address bits );
645215911Sjfv
646215911Sjfv  // Return a 'ptr' version of this type
647215911Sjfv  virtual const Type *cast_to_ptr_type(PTR ptr) const;
648283620Serj
649283620Serj  virtual intptr_t get_con() const;
650283620Serj
651215911Sjfv  virtual const TypePtr *add_offset( intptr_t offset ) const;
652283620Serj
653215911Sjfv  virtual const Type *xmeet( const Type *t ) const;
654215911Sjfv  virtual const Type *xdual() const;    // Compute dual right now.
655215911Sjfv  // Convenience common pre-built types.
656215911Sjfv  static const TypeRawPtr *BOTTOM;
657215911Sjfv  static const TypeRawPtr *NOTNULL;
658215911Sjfv#ifndef PRODUCT
659215911Sjfv  virtual void dump2( Dict &d, uint depth, outputStream *st  ) const;
660215911Sjfv#endif
661215911Sjfv};
662215911Sjfv
663215911Sjfv//------------------------------TypeOopPtr-------------------------------------
664215911Sjfv// Some kind of oop (Java pointer), either klass or instance or array.
665215911Sjfvclass TypeOopPtr : public TypePtr {
666230775Sjfvprotected:
667215911Sjfv  TypeOopPtr( TYPES t, PTR ptr, ciKlass* k, bool xk, ciObject* o, int offset, int instance_id );
668215911Sjfvpublic:
669215911Sjfv  virtual bool eq( const Type *t ) const;
670215911Sjfv  virtual int  hash() const;             // Type specific hashing
671215911Sjfv  virtual bool singleton(void) const;    // TRUE if type is a singleton
672215911Sjfv  enum {
673215911Sjfv   InstanceTop = -1,   // undefined instance
674215911Sjfv   InstanceBot = 0     // any possible instance
675215911Sjfv  };
676215911Sjfvprotected:
677215911Sjfv
678215911Sjfv  // Oop is NULL, unless this is a constant oop.
679215911Sjfv  ciObject*     _const_oop;   // Constant oop
680215911Sjfv  // If _klass is NULL, then so is _sig.  This is an unloaded klass.
681215911Sjfv  ciKlass*      _klass;       // Klass object
682215911Sjfv  // Does the type exclude subclasses of the klass?  (Inexact == polymorphic.)
683215911Sjfv  bool          _klass_is_exact;
684215911Sjfv  bool          _is_ptr_to_narrowoop;
685215911Sjfv
686215911Sjfv  // If not InstanceTop or InstanceBot, indicates that this is
687215911Sjfv  // a particular instance of this type which is distinct.
688215911Sjfv  // This is the the node index of the allocation node creating this instance.
689215911Sjfv  int           _instance_id;
690215911Sjfv
691215911Sjfv  static const TypeOopPtr* make_from_klass_common(ciKlass* klass, bool klass_change, bool try_for_exact);
692215911Sjfv
693215911Sjfv  int dual_instance_id() const;
694215911Sjfv  int meet_instance_id(int uid) const;
695215911Sjfv
696215911Sjfvpublic:
697215911Sjfv  // Creates a type given a klass. Correctly handles multi-dimensional arrays
698215911Sjfv  // Respects UseUniqueSubclasses.
699215911Sjfv  // If the klass is final, the resulting type will be exact.
700215911Sjfv  static const TypeOopPtr* make_from_klass(ciKlass* klass) {
701215911Sjfv    return make_from_klass_common(klass, true, false);
702215911Sjfv  }
703215911Sjfv  // Same as before, but will produce an exact type, even if
704215911Sjfv  // the klass is not final, as long as it has exactly one implementation.
705215911Sjfv  static const TypeOopPtr* make_from_klass_unique(ciKlass* klass) {
706215911Sjfv    return make_from_klass_common(klass, true, true);
707215911Sjfv  }
708215911Sjfv  // Same as before, but does not respects UseUniqueSubclasses.
709230775Sjfv  // Use this only for creating array element types.
710215911Sjfv  static const TypeOopPtr* make_from_klass_raw(ciKlass* klass) {
711215911Sjfv    return make_from_klass_common(klass, false, false);
712215911Sjfv  }
713215911Sjfv  // Creates a singleton type given an object.
714215911Sjfv  // If the object cannot be rendered as a constant,
715215911Sjfv  // may return a non-singleton type.
716215911Sjfv  // If require_constant, produce a NULL if a singleton is not possible.
717215911Sjfv  static const TypeOopPtr* make_from_constant(ciObject* o, bool require_constant = false);
718215911Sjfv
719215911Sjfv  // Make a generic (unclassed) pointer to an oop.
720215911Sjfv  static const TypeOopPtr* make(PTR ptr, int offset, int instance_id);
721215911Sjfv
722215911Sjfv  ciObject* const_oop()    const { return _const_oop; }
723215911Sjfv  virtual ciKlass* klass() const { return _klass;     }
724215911Sjfv  bool klass_is_exact()    const { return _klass_is_exact; }
725215911Sjfv
726215911Sjfv  // Returns true if this pointer points at memory which contains a
727215911Sjfv  // compressed oop references.
728215911Sjfv  bool is_ptr_to_narrowoop_nv() const { return _is_ptr_to_narrowoop; }
729215911Sjfv
730215911Sjfv  bool is_known_instance()       const { return _instance_id > 0; }
731215911Sjfv  int  instance_id()             const { return _instance_id; }
732215911Sjfv  bool is_known_instance_field() const { return is_known_instance() && _offset >= 0; }
733215911Sjfv
734215911Sjfv  virtual intptr_t get_con() const;
735215911Sjfv
736215911Sjfv  virtual const Type *cast_to_ptr_type(PTR ptr) const;
737215911Sjfv
738215911Sjfv  virtual const Type *cast_to_exactness(bool klass_is_exact) const;
739215911Sjfv
740215911Sjfv  virtual const TypeOopPtr *cast_to_instance_id(int instance_id) const;
741215911Sjfv
742215911Sjfv  // corresponding pointer to klass, for a given instance
743215911Sjfv  const TypeKlassPtr* as_klass_type() const;
744215911Sjfv
745230775Sjfv  virtual const TypePtr *add_offset( intptr_t offset ) const;
746283620Serj
747283620Serj  virtual const Type *xmeet( const Type *t ) const;
748315333Serj  virtual const Type *xdual() const;    // Compute dual right now.
749230775Sjfv
750215911Sjfv  // Do not allow interface-vs.-noninterface joins to collapse to top.
751215911Sjfv  virtual const Type *filter( const Type *kills ) const;
752215911Sjfv
753215911Sjfv  // Convenience common pre-built type.
754215911Sjfv  static const TypeOopPtr *BOTTOM;
755215911Sjfv#ifndef PRODUCT
756215911Sjfv  virtual void dump2( Dict &d, uint depth, outputStream *st ) const;
757215911Sjfv#endif
758215911Sjfv};
759215911Sjfv
760215911Sjfv//------------------------------TypeInstPtr------------------------------------
761215911Sjfv// Class of Java object pointers, pointing either to non-array Java instances
762215911Sjfv// or to a klassOop (including array klasses).
763215911Sjfvclass TypeInstPtr : public TypeOopPtr {
764215911Sjfv  TypeInstPtr( PTR ptr, ciKlass* k, bool xk, ciObject* o, int offset, int instance_id );
765215911Sjfv  virtual bool eq( const Type *t ) const;
766215911Sjfv  virtual int  hash() const;             // Type specific hashing
767215911Sjfv
768215911Sjfv  ciSymbol*  _name;        // class name
769215911Sjfv
770215911Sjfv public:
771  ciSymbol* name()         const { return _name; }
772
773  bool  is_loaded() const { return _klass->is_loaded(); }
774
775  // Make a pointer to a constant oop.
776  static const TypeInstPtr *make(ciObject* o) {
777    return make(TypePtr::Constant, o->klass(), true, o, 0);
778  }
779
780  // Make a pointer to a constant oop with offset.
781  static const TypeInstPtr *make(ciObject* o, int offset) {
782    return make(TypePtr::Constant, o->klass(), true, o, offset);
783  }
784
785  // Make a pointer to some value of type klass.
786  static const TypeInstPtr *make(PTR ptr, ciKlass* klass) {
787    return make(ptr, klass, false, NULL, 0);
788  }
789
790  // Make a pointer to some non-polymorphic value of exactly type klass.
791  static const TypeInstPtr *make_exact(PTR ptr, ciKlass* klass) {
792    return make(ptr, klass, true, NULL, 0);
793  }
794
795  // Make a pointer to some value of type klass with offset.
796  static const TypeInstPtr *make(PTR ptr, ciKlass* klass, int offset) {
797    return make(ptr, klass, false, NULL, offset);
798  }
799
800  // Make a pointer to an oop.
801  static const TypeInstPtr *make(PTR ptr, ciKlass* k, bool xk, ciObject* o, int offset, int instance_id = InstanceBot );
802
803  // If this is a java.lang.Class constant, return the type for it or NULL.
804  // Pass to Type::get_const_type to turn it to a type, which will usually
805  // be a TypeInstPtr, but may also be a TypeInt::INT for int.class, etc.
806  ciType* java_mirror_type() const;
807
808  virtual const Type *cast_to_ptr_type(PTR ptr) const;
809
810  virtual const Type *cast_to_exactness(bool klass_is_exact) const;
811
812  virtual const TypeOopPtr *cast_to_instance_id(int instance_id) const;
813
814  virtual const TypePtr *add_offset( intptr_t offset ) const;
815
816  virtual const Type *xmeet( const Type *t ) const;
817  virtual const TypeInstPtr *xmeet_unloaded( const TypeInstPtr *t ) const;
818  virtual const Type *xdual() const;    // Compute dual right now.
819
820  // Convenience common pre-built types.
821  static const TypeInstPtr *NOTNULL;
822  static const TypeInstPtr *BOTTOM;
823  static const TypeInstPtr *MIRROR;
824  static const TypeInstPtr *MARK;
825  static const TypeInstPtr *KLASS;
826#ifndef PRODUCT
827  virtual void dump2( Dict &d, uint depth, outputStream *st ) const; // Specialized per-Type dumping
828#endif
829};
830
831//------------------------------TypeAryPtr-------------------------------------
832// Class of Java array pointers
833class TypeAryPtr : public TypeOopPtr {
834  TypeAryPtr( PTR ptr, ciObject* o, const TypeAry *ary, ciKlass* k, bool xk, int offset, int instance_id ) : TypeOopPtr(AryPtr,ptr,k,xk,o,offset, instance_id), _ary(ary) {};
835  virtual bool eq( const Type *t ) const;
836  virtual int hash() const;     // Type specific hashing
837  const TypeAry *_ary;          // Array we point into
838
839public:
840  // Accessors
841  ciKlass* klass() const;
842  const TypeAry* ary() const  { return _ary; }
843  const Type*    elem() const { return _ary->_elem; }
844  const TypeInt* size() const { return _ary->_size; }
845
846  static const TypeAryPtr *make( PTR ptr, const TypeAry *ary, ciKlass* k, bool xk, int offset, int instance_id = InstanceBot);
847  // Constant pointer to array
848  static const TypeAryPtr *make( PTR ptr, ciObject* o, const TypeAry *ary, ciKlass* k, bool xk, int offset, int instance_id = InstanceBot);
849
850  // Return a 'ptr' version of this type
851  virtual const Type *cast_to_ptr_type(PTR ptr) const;
852
853  virtual const Type *cast_to_exactness(bool klass_is_exact) const;
854
855  virtual const TypeOopPtr *cast_to_instance_id(int instance_id) const;
856
857  virtual const TypeAryPtr* cast_to_size(const TypeInt* size) const;
858  virtual const TypeInt* narrow_size_type(const TypeInt* size) const;
859
860  virtual bool empty(void) const;        // TRUE if type is vacuous
861  virtual const TypePtr *add_offset( intptr_t offset ) const;
862
863  virtual const Type *xmeet( const Type *t ) const;
864  virtual const Type *xdual() const;    // Compute dual right now.
865
866  // Convenience common pre-built types.
867  static const TypeAryPtr *RANGE;
868  static const TypeAryPtr *OOPS;
869  static const TypeAryPtr *NARROWOOPS;
870  static const TypeAryPtr *BYTES;
871  static const TypeAryPtr *SHORTS;
872  static const TypeAryPtr *CHARS;
873  static const TypeAryPtr *INTS;
874  static const TypeAryPtr *LONGS;
875  static const TypeAryPtr *FLOATS;
876  static const TypeAryPtr *DOUBLES;
877  // selects one of the above:
878  static const TypeAryPtr *get_array_body_type(BasicType elem) {
879    assert((uint)elem <= T_CONFLICT && _array_body_type[elem] != NULL, "bad elem type");
880    return _array_body_type[elem];
881  }
882  static const TypeAryPtr *_array_body_type[T_CONFLICT+1];
883  // sharpen the type of an int which is used as an array size
884#ifdef ASSERT
885  // One type is interface, the other is oop
886  virtual bool interface_vs_oop(const Type *t) const;
887#endif
888#ifndef PRODUCT
889  virtual void dump2( Dict &d, uint depth, outputStream *st ) const; // Specialized per-Type dumping
890#endif
891};
892
893//------------------------------TypeKlassPtr-----------------------------------
894// Class of Java Klass pointers
895class TypeKlassPtr : public TypeOopPtr {
896  TypeKlassPtr( PTR ptr, ciKlass* klass, int offset );
897
898  virtual bool eq( const Type *t ) const;
899  virtual int hash() const;             // Type specific hashing
900
901public:
902  ciSymbol* name()  const { return _klass->name(); }
903
904  bool  is_loaded() const { return _klass->is_loaded(); }
905
906  // ptr to klass 'k'
907  static const TypeKlassPtr *make( ciKlass* k ) { return make( TypePtr::Constant, k, 0); }
908  // ptr to klass 'k' with offset
909  static const TypeKlassPtr *make( ciKlass* k, int offset ) { return make( TypePtr::Constant, k, offset); }
910  // ptr to klass 'k' or sub-klass
911  static const TypeKlassPtr *make( PTR ptr, ciKlass* k, int offset);
912
913  virtual const Type *cast_to_ptr_type(PTR ptr) const;
914
915  virtual const Type *cast_to_exactness(bool klass_is_exact) const;
916
917  // corresponding pointer to instance, for a given class
918  const TypeOopPtr* as_instance_type() const;
919
920  virtual const TypePtr *add_offset( intptr_t offset ) const;
921  virtual const Type    *xmeet( const Type *t ) const;
922  virtual const Type    *xdual() const;      // Compute dual right now.
923
924  // Convenience common pre-built types.
925  static const TypeKlassPtr* OBJECT; // Not-null object klass or below
926  static const TypeKlassPtr* OBJECT_OR_NULL; // Maybe-null version of same
927#ifndef PRODUCT
928  virtual void dump2( Dict &d, uint depth, outputStream *st ) const; // Specialized per-Type dumping
929#endif
930};
931
932//------------------------------TypeNarrowOop----------------------------------
933// A compressed reference to some kind of Oop.  This type wraps around
934// a preexisting TypeOopPtr and forwards most of it's operations to
935// the underlying type.  It's only real purpose is to track the
936// oopness of the compressed oop value when we expose the conversion
937// between the normal and the compressed form.
938class TypeNarrowOop : public Type {
939protected:
940  const TypePtr* _ptrtype; // Could be TypePtr::NULL_PTR
941
942  TypeNarrowOop( const TypePtr* ptrtype): Type(NarrowOop),
943    _ptrtype(ptrtype) {
944    assert(ptrtype->offset() == 0 ||
945           ptrtype->offset() == OffsetBot ||
946           ptrtype->offset() == OffsetTop, "no real offsets");
947  }
948public:
949  virtual bool eq( const Type *t ) const;
950  virtual int  hash() const;             // Type specific hashing
951  virtual bool singleton(void) const;    // TRUE if type is a singleton
952
953  virtual const Type *xmeet( const Type *t ) const;
954  virtual const Type *xdual() const;    // Compute dual right now.
955
956  virtual intptr_t get_con() const;
957
958  // Do not allow interface-vs.-noninterface joins to collapse to top.
959  virtual const Type *filter( const Type *kills ) const;
960
961  virtual bool empty(void) const;        // TRUE if type is vacuous
962
963  static const TypeNarrowOop *make( const TypePtr* type);
964
965  static const TypeNarrowOop* make_from_constant(ciObject* con) {
966    return make(TypeOopPtr::make_from_constant(con));
967  }
968
969  // returns the equivalent ptr type for this compressed pointer
970  const TypePtr *get_ptrtype() const {
971    return _ptrtype;
972  }
973
974  static const TypeNarrowOop *BOTTOM;
975  static const TypeNarrowOop *NULL_PTR;
976
977#ifndef PRODUCT
978  virtual void dump2( Dict &d, uint depth, outputStream *st ) const;
979#endif
980};
981
982//------------------------------TypeFunc---------------------------------------
983// Class of Array Types
984class TypeFunc : public Type {
985  TypeFunc( const TypeTuple *domain, const TypeTuple *range ) : Type(Function),  _domain(domain), _range(range) {}
986  virtual bool eq( const Type *t ) const;
987  virtual int  hash() const;             // Type specific hashing
988  virtual bool singleton(void) const;    // TRUE if type is a singleton
989  virtual bool empty(void) const;        // TRUE if type is vacuous
990public:
991  // Constants are shared among ADLC and VM
992  enum { Control    = AdlcVMDeps::Control,
993         I_O        = AdlcVMDeps::I_O,
994         Memory     = AdlcVMDeps::Memory,
995         FramePtr   = AdlcVMDeps::FramePtr,
996         ReturnAdr  = AdlcVMDeps::ReturnAdr,
997         Parms      = AdlcVMDeps::Parms
998  };
999
1000  const TypeTuple* const _domain;     // Domain of inputs
1001  const TypeTuple* const _range;      // Range of results
1002
1003  // Accessors:
1004  const TypeTuple* domain() const { return _domain; }
1005  const TypeTuple* range()  const { return _range; }
1006
1007  static const TypeFunc *make(ciMethod* method);
1008  static const TypeFunc *make(ciSignature signature, const Type* extra);
1009  static const TypeFunc *make(const TypeTuple* domain, const TypeTuple* range);
1010
1011  virtual const Type *xmeet( const Type *t ) const;
1012  virtual const Type *xdual() const;    // Compute dual right now.
1013
1014  BasicType return_type() const;
1015
1016#ifndef PRODUCT
1017  virtual void dump2( Dict &d, uint depth, outputStream *st ) const; // Specialized per-Type dumping
1018  void print_flattened() const; // Print a 'flattened' signature
1019#endif
1020  // Convenience common pre-built types.
1021};
1022
1023//------------------------------accessors--------------------------------------
1024inline bool Type::is_ptr_to_narrowoop() const {
1025#ifdef _LP64
1026  return (isa_oopptr() != NULL && is_oopptr()->is_ptr_to_narrowoop_nv());
1027#else
1028  return false;
1029#endif
1030}
1031
1032inline float Type::getf() const {
1033  assert( _base == FloatCon, "Not a FloatCon" );
1034  return ((TypeF*)this)->_f;
1035}
1036
1037inline double Type::getd() const {
1038  assert( _base == DoubleCon, "Not a DoubleCon" );
1039  return ((TypeD*)this)->_d;
1040}
1041
1042inline const TypeF *Type::is_float_constant() const {
1043  assert( _base == FloatCon, "Not a Float" );
1044  return (TypeF*)this;
1045}
1046
1047inline const TypeF *Type::isa_float_constant() const {
1048  return ( _base == FloatCon ? (TypeF*)this : NULL);
1049}
1050
1051inline const TypeD *Type::is_double_constant() const {
1052  assert( _base == DoubleCon, "Not a Double" );
1053  return (TypeD*)this;
1054}
1055
1056inline const TypeD *Type::isa_double_constant() const {
1057  return ( _base == DoubleCon ? (TypeD*)this : NULL);
1058}
1059
1060inline const TypeInt *Type::is_int() const {
1061  assert( _base == Int, "Not an Int" );
1062  return (TypeInt*)this;
1063}
1064
1065inline const TypeInt *Type::isa_int() const {
1066  return ( _base == Int ? (TypeInt*)this : NULL);
1067}
1068
1069inline const TypeLong *Type::is_long() const {
1070  assert( _base == Long, "Not a Long" );
1071  return (TypeLong*)this;
1072}
1073
1074inline const TypeLong *Type::isa_long() const {
1075  return ( _base == Long ? (TypeLong*)this : NULL);
1076}
1077
1078inline const TypeTuple *Type::is_tuple() const {
1079  assert( _base == Tuple, "Not a Tuple" );
1080  return (TypeTuple*)this;
1081}
1082
1083inline const TypeAry *Type::is_ary() const {
1084  assert( _base == Array , "Not an Array" );
1085  return (TypeAry*)this;
1086}
1087
1088inline const TypePtr *Type::is_ptr() const {
1089  // AnyPtr is the first Ptr and KlassPtr the last, with no non-ptrs between.
1090  assert(_base >= AnyPtr && _base <= KlassPtr, "Not a pointer");
1091  return (TypePtr*)this;
1092}
1093
1094inline const TypePtr *Type::isa_ptr() const {
1095  // AnyPtr is the first Ptr and KlassPtr the last, with no non-ptrs between.
1096  return (_base >= AnyPtr && _base <= KlassPtr) ? (TypePtr*)this : NULL;
1097}
1098
1099inline const TypeOopPtr *Type::is_oopptr() const {
1100  // OopPtr is the first and KlassPtr the last, with no non-oops between.
1101  assert(_base >= OopPtr && _base <= KlassPtr, "Not a Java pointer" ) ;
1102  return (TypeOopPtr*)this;
1103}
1104
1105inline const TypeOopPtr *Type::isa_oopptr() const {
1106  // OopPtr is the first and KlassPtr the last, with no non-oops between.
1107  return (_base >= OopPtr && _base <= KlassPtr) ? (TypeOopPtr*)this : NULL;
1108}
1109
1110inline const TypeRawPtr *Type::isa_rawptr() const {
1111  return (_base == RawPtr) ? (TypeRawPtr*)this : NULL;
1112}
1113
1114inline const TypeRawPtr *Type::is_rawptr() const {
1115  assert( _base == RawPtr, "Not a raw pointer" );
1116  return (TypeRawPtr*)this;
1117}
1118
1119inline const TypeInstPtr *Type::isa_instptr() const {
1120  return (_base == InstPtr) ? (TypeInstPtr*)this : NULL;
1121}
1122
1123inline const TypeInstPtr *Type::is_instptr() const {
1124  assert( _base == InstPtr, "Not an object pointer" );
1125  return (TypeInstPtr*)this;
1126}
1127
1128inline const TypeAryPtr *Type::isa_aryptr() const {
1129  return (_base == AryPtr) ? (TypeAryPtr*)this : NULL;
1130}
1131
1132inline const TypeAryPtr *Type::is_aryptr() const {
1133  assert( _base == AryPtr, "Not an array pointer" );
1134  return (TypeAryPtr*)this;
1135}
1136
1137inline const TypeNarrowOop *Type::is_narrowoop() const {
1138  // OopPtr is the first and KlassPtr the last, with no non-oops between.
1139  assert(_base == NarrowOop, "Not a narrow oop" ) ;
1140  return (TypeNarrowOop*)this;
1141}
1142
1143inline const TypeNarrowOop *Type::isa_narrowoop() const {
1144  // OopPtr is the first and KlassPtr the last, with no non-oops between.
1145  return (_base == NarrowOop) ? (TypeNarrowOop*)this : NULL;
1146}
1147
1148inline const TypeKlassPtr *Type::isa_klassptr() const {
1149  return (_base == KlassPtr) ? (TypeKlassPtr*)this : NULL;
1150}
1151
1152inline const TypeKlassPtr *Type::is_klassptr() const {
1153  assert( _base == KlassPtr, "Not a klass pointer" );
1154  return (TypeKlassPtr*)this;
1155}
1156
1157inline const TypePtr* Type::make_ptr() const {
1158  return (_base == NarrowOop) ? is_narrowoop()->get_ptrtype() :
1159                                (isa_ptr() ? is_ptr() : NULL);
1160}
1161
1162inline const TypeOopPtr* Type::make_oopptr() const {
1163  return (_base == NarrowOop) ? is_narrowoop()->get_ptrtype()->is_oopptr() : is_oopptr();
1164}
1165
1166inline const TypeNarrowOop* Type::make_narrowoop() const {
1167  return (_base == NarrowOop) ? is_narrowoop() :
1168                                (isa_ptr() ? TypeNarrowOop::make(is_ptr()) : NULL);
1169}
1170
1171inline bool Type::is_floatingpoint() const {
1172  if( (_base == FloatCon)  || (_base == FloatBot) ||
1173      (_base == DoubleCon) || (_base == DoubleBot) )
1174    return true;
1175  return false;
1176}
1177
1178
1179// ===============================================================
1180// Things that need to be 64-bits in the 64-bit build but
1181// 32-bits in the 32-bit build.  Done this way to get full
1182// optimization AND strong typing.
1183#ifdef _LP64
1184
1185// For type queries and asserts
1186#define is_intptr_t  is_long
1187#define isa_intptr_t isa_long
1188#define find_intptr_t_type find_long_type
1189#define find_intptr_t_con  find_long_con
1190#define TypeX        TypeLong
1191#define Type_X       Type::Long
1192#define TypeX_X      TypeLong::LONG
1193#define TypeX_ZERO   TypeLong::ZERO
1194// For 'ideal_reg' machine registers
1195#define Op_RegX      Op_RegL
1196// For phase->intcon variants
1197#define MakeConX     longcon
1198#define ConXNode     ConLNode
1199// For array index arithmetic
1200#define MulXNode     MulLNode
1201#define AndXNode     AndLNode
1202#define OrXNode      OrLNode
1203#define CmpXNode     CmpLNode
1204#define SubXNode     SubLNode
1205#define LShiftXNode  LShiftLNode
1206// For object size computation:
1207#define AddXNode     AddLNode
1208#define RShiftXNode  RShiftLNode
1209// For card marks and hashcodes
1210#define URShiftXNode URShiftLNode
1211// UseOptoBiasInlining
1212#define XorXNode     XorLNode
1213#define StoreXConditionalNode StoreLConditionalNode
1214// Opcodes
1215#define Op_LShiftX   Op_LShiftL
1216#define Op_AndX      Op_AndL
1217#define Op_AddX      Op_AddL
1218#define Op_SubX      Op_SubL
1219#define Op_XorX      Op_XorL
1220#define Op_URShiftX  Op_URShiftL
1221// conversions
1222#define ConvI2X(x)   ConvI2L(x)
1223#define ConvL2X(x)   (x)
1224#define ConvX2I(x)   ConvL2I(x)
1225#define ConvX2L(x)   (x)
1226
1227#else
1228
1229// For type queries and asserts
1230#define is_intptr_t  is_int
1231#define isa_intptr_t isa_int
1232#define find_intptr_t_type find_int_type
1233#define find_intptr_t_con  find_int_con
1234#define TypeX        TypeInt
1235#define Type_X       Type::Int
1236#define TypeX_X      TypeInt::INT
1237#define TypeX_ZERO   TypeInt::ZERO
1238// For 'ideal_reg' machine registers
1239#define Op_RegX      Op_RegI
1240// For phase->intcon variants
1241#define MakeConX     intcon
1242#define ConXNode     ConINode
1243// For array index arithmetic
1244#define MulXNode     MulINode
1245#define AndXNode     AndINode
1246#define OrXNode      OrINode
1247#define CmpXNode     CmpINode
1248#define SubXNode     SubINode
1249#define LShiftXNode  LShiftINode
1250// For object size computation:
1251#define AddXNode     AddINode
1252#define RShiftXNode  RShiftINode
1253// For card marks and hashcodes
1254#define URShiftXNode URShiftINode
1255// UseOptoBiasInlining
1256#define XorXNode     XorINode
1257#define StoreXConditionalNode StoreIConditionalNode
1258// Opcodes
1259#define Op_LShiftX   Op_LShiftI
1260#define Op_AndX      Op_AndI
1261#define Op_AddX      Op_AddI
1262#define Op_SubX      Op_SubI
1263#define Op_XorX      Op_XorI
1264#define Op_URShiftX  Op_URShiftI
1265// conversions
1266#define ConvI2X(x)   (x)
1267#define ConvL2X(x)   ConvL2I(x)
1268#define ConvX2I(x)   (x)
1269#define ConvX2L(x)   ConvI2L(x)
1270
1271#endif
1272