Wed, 02 Jul 2008 12:55:16 -0700
6719955: Update copyright year
Summary: Update copyright year for files that have been modified in 2008
Reviewed-by: ohair, tbell
1 /*
2 * Copyright 1997-2008 Sun Microsystems, Inc. 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 Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
20 * CA 95054 USA or visit www.sun.com if you need additional information or
21 * have any questions.
22 *
23 */
25 // Portions of code courtesy of Clifford Click
27 // Optimization - Graph Style
30 // This class defines a Type lattice. The lattice is used in the constant
31 // propagation algorithms, and for some type-checking of the iloc code.
32 // Basic types include RSD's (lower bound, upper bound, stride for integers),
33 // float & double precision constants, sets of data-labels and code-labels.
34 // The complete lattice is described below. Subtypes have no relationship to
35 // up or down in the lattice; that is entirely determined by the behavior of
36 // the MEET/JOIN functions.
38 class Dict;
39 class Type;
40 class TypeD;
41 class TypeF;
42 class TypeInt;
43 class TypeLong;
44 class TypeNarrowOop;
45 class TypeAry;
46 class TypeTuple;
47 class TypePtr;
48 class TypeRawPtr;
49 class TypeOopPtr;
50 class TypeInstPtr;
51 class TypeAryPtr;
52 class TypeKlassPtr;
54 //------------------------------Type-------------------------------------------
55 // Basic Type object, represents a set of primitive Values.
56 // Types are hash-cons'd into a private class dictionary, so only one of each
57 // different kind of Type exists. Types are never modified after creation, so
58 // all their interesting fields are constant.
59 class Type {
60 public:
61 enum TYPES {
62 Bad=0, // Type check
63 Control, // Control of code (not in lattice)
64 Top, // Top of the lattice
65 Int, // Integer range (lo-hi)
66 Long, // Long integer range (lo-hi)
67 Half, // Placeholder half of doubleword
68 NarrowOop, // Compressed oop pointer
70 Tuple, // Method signature or object layout
71 Array, // Array types
73 AnyPtr, // Any old raw, klass, inst, or array pointer
74 RawPtr, // Raw (non-oop) pointers
75 OopPtr, // Any and all Java heap entities
76 InstPtr, // Instance pointers (non-array objects)
77 AryPtr, // Array pointers
78 KlassPtr, // Klass pointers
79 // (Ptr order matters: See is_ptr, isa_ptr, is_oopptr, isa_oopptr.)
81 Function, // Function signature
82 Abio, // Abstract I/O
83 Return_Address, // Subroutine return address
84 Memory, // Abstract store
85 FloatTop, // No float value
86 FloatCon, // Floating point constant
87 FloatBot, // Any float value
88 DoubleTop, // No double value
89 DoubleCon, // Double precision constant
90 DoubleBot, // Any double value
91 Bottom, // Bottom of lattice
92 lastype // Bogus ending type (not in lattice)
93 };
95 // Signal values for offsets from a base pointer
96 enum OFFSET_SIGNALS {
97 OffsetTop = -2000000000, // undefined offset
98 OffsetBot = -2000000001 // any possible offset
99 };
101 // Min and max WIDEN values.
102 enum WIDEN {
103 WidenMin = 0,
104 WidenMax = 3
105 };
107 private:
108 // Dictionary of types shared among compilations.
109 static Dict* _shared_type_dict;
111 static int uhash( const Type *const t );
112 // Structural equality check. Assumes that cmp() has already compared
113 // the _base types and thus knows it can cast 't' appropriately.
114 virtual bool eq( const Type *t ) const;
116 // Top-level hash-table of types
117 static Dict *type_dict() {
118 return Compile::current()->type_dict();
119 }
121 // DUAL operation: reflect around lattice centerline. Used instead of
122 // join to ensure my lattice is symmetric up and down. Dual is computed
123 // lazily, on demand, and cached in _dual.
124 const Type *_dual; // Cached dual value
125 // Table for efficient dualing of base types
126 static const TYPES dual_type[lastype];
128 protected:
129 // Each class of type is also identified by its base.
130 const TYPES _base; // Enum of Types type
132 Type( TYPES t ) : _dual(NULL), _base(t) {} // Simple types
133 // ~Type(); // Use fast deallocation
134 const Type *hashcons(); // Hash-cons the type
136 public:
138 inline void* operator new( size_t x ) {
139 Compile* compile = Compile::current();
140 compile->set_type_last_size(x);
141 void *temp = compile->type_arena()->Amalloc_D(x);
142 compile->set_type_hwm(temp);
143 return temp;
144 }
145 inline void operator delete( void* ptr ) {
146 Compile* compile = Compile::current();
147 compile->type_arena()->Afree(ptr,compile->type_last_size());
148 }
150 // Initialize the type system for a particular compilation.
151 static void Initialize(Compile* compile);
153 // Initialize the types shared by all compilations.
154 static void Initialize_shared(Compile* compile);
156 TYPES base() const {
157 assert(_base > Bad && _base < lastype, "sanity");
158 return _base;
159 }
161 // Create a new hash-consd type
162 static const Type *make(enum TYPES);
163 // Test for equivalence of types
164 static int cmp( const Type *const t1, const Type *const t2 );
165 // Test for higher or equal in lattice
166 int higher_equal( const Type *t ) const { return !cmp(meet(t),t); }
168 // MEET operation; lower in lattice.
169 const Type *meet( const Type *t ) const;
170 // WIDEN: 'widens' for Ints and other range types
171 virtual const Type *widen( const Type *old ) const { return this; }
172 // NARROW: complement for widen, used by pessimistic phases
173 virtual const Type *narrow( const Type *old ) const { return this; }
175 // DUAL operation: reflect around lattice centerline. Used instead of
176 // join to ensure my lattice is symmetric up and down.
177 const Type *dual() const { return _dual; }
179 // Compute meet dependent on base type
180 virtual const Type *xmeet( const Type *t ) const;
181 virtual const Type *xdual() const; // Compute dual right now.
183 // JOIN operation; higher in lattice. Done by finding the dual of the
184 // meet of the dual of the 2 inputs.
185 const Type *join( const Type *t ) const {
186 return dual()->meet(t->dual())->dual(); }
188 // Modified version of JOIN adapted to the needs Node::Value.
189 // Normalizes all empty values to TOP. Does not kill _widen bits.
190 // Currently, it also works around limitations involving interface types.
191 virtual const Type *filter( const Type *kills ) const;
193 // Returns true if this pointer points at memory which contains a
194 // compressed oop references.
195 bool is_ptr_to_narrowoop() const;
197 // Convenience access
198 float getf() const;
199 double getd() const;
201 const TypeInt *is_int() const;
202 const TypeInt *isa_int() const; // Returns NULL if not an Int
203 const TypeLong *is_long() const;
204 const TypeLong *isa_long() const; // Returns NULL if not a Long
205 const TypeD *is_double_constant() const; // Asserts it is a DoubleCon
206 const TypeD *isa_double_constant() const; // Returns NULL if not a DoubleCon
207 const TypeF *is_float_constant() const; // Asserts it is a FloatCon
208 const TypeF *isa_float_constant() const; // Returns NULL if not a FloatCon
209 const TypeTuple *is_tuple() const; // Collection of fields, NOT a pointer
210 const TypeAry *is_ary() const; // Array, NOT array pointer
211 const TypePtr *is_ptr() const; // Asserts it is a ptr type
212 const TypePtr *isa_ptr() const; // Returns NULL if not ptr type
213 const TypeRawPtr *isa_rawptr() const; // NOT Java oop
214 const TypeRawPtr *is_rawptr() const; // Asserts is rawptr
215 const TypeNarrowOop *is_narrowoop() const; // Java-style GC'd pointer
216 const TypeNarrowOop *isa_narrowoop() const; // Returns NULL if not oop ptr type
217 const TypeOopPtr *isa_oopptr() const; // Returns NULL if not oop ptr type
218 const TypeOopPtr *is_oopptr() const; // Java-style GC'd pointer
219 const TypeKlassPtr *isa_klassptr() const; // Returns NULL if not KlassPtr
220 const TypeKlassPtr *is_klassptr() const; // assert if not KlassPtr
221 const TypeInstPtr *isa_instptr() const; // Returns NULL if not InstPtr
222 const TypeInstPtr *is_instptr() const; // Instance
223 const TypeAryPtr *isa_aryptr() const; // Returns NULL if not AryPtr
224 const TypeAryPtr *is_aryptr() const; // Array oop
225 virtual bool is_finite() const; // Has a finite value
226 virtual bool is_nan() const; // Is not a number (NaN)
228 // Special test for register pressure heuristic
229 bool is_floatingpoint() const; // True if Float or Double base type
231 // Do you have memory, directly or through a tuple?
232 bool has_memory( ) const;
234 // Are you a pointer type or not?
235 bool isa_oop_ptr() const;
237 // TRUE if type is a singleton
238 virtual bool singleton(void) const;
240 // TRUE if type is above the lattice centerline, and is therefore vacuous
241 virtual bool empty(void) const;
243 // Return a hash for this type. The hash function is public so ConNode
244 // (constants) can hash on their constant, which is represented by a Type.
245 virtual int hash() const;
247 // Map ideal registers (machine types) to ideal types
248 static const Type *mreg2type[];
250 // Printing, statistics
251 static const char * const msg[lastype]; // Printable strings
252 #ifndef PRODUCT
253 void dump_on(outputStream *st) const;
254 void dump() const {
255 dump_on(tty);
256 }
257 virtual void dump2( Dict &d, uint depth, outputStream *st ) const;
258 static void dump_stats();
259 static void verify_lastype(); // Check that arrays match type enum
260 #endif
261 void typerr(const Type *t) const; // Mixing types error
263 // Create basic type
264 static const Type* get_const_basic_type(BasicType type) {
265 assert((uint)type <= T_CONFLICT && _const_basic_type[type] != NULL, "bad type");
266 return _const_basic_type[type];
267 }
269 // Mapping to the array element's basic type.
270 BasicType array_element_basic_type() const;
272 // Create standard type for a ciType:
273 static const Type* get_const_type(ciType* type);
275 // Create standard zero value:
276 static const Type* get_zero_type(BasicType type) {
277 assert((uint)type <= T_CONFLICT && _zero_type[type] != NULL, "bad type");
278 return _zero_type[type];
279 }
281 // Report if this is a zero value (not top).
282 bool is_zero_type() const {
283 BasicType type = basic_type();
284 if (type == T_VOID || type >= T_CONFLICT)
285 return false;
286 else
287 return (this == _zero_type[type]);
288 }
290 // Convenience common pre-built types.
291 static const Type *ABIO;
292 static const Type *BOTTOM;
293 static const Type *CONTROL;
294 static const Type *DOUBLE;
295 static const Type *FLOAT;
296 static const Type *HALF;
297 static const Type *MEMORY;
298 static const Type *MULTI;
299 static const Type *RETURN_ADDRESS;
300 static const Type *TOP;
302 // Mapping from compiler type to VM BasicType
303 BasicType basic_type() const { return _basic_type[_base]; }
305 // Mapping from CI type system to compiler type:
306 static const Type* get_typeflow_type(ciType* type);
308 private:
309 // support arrays
310 static const BasicType _basic_type[];
311 static const Type* _zero_type[T_CONFLICT+1];
312 static const Type* _const_basic_type[T_CONFLICT+1];
313 };
315 //------------------------------TypeF------------------------------------------
316 // Class of Float-Constant Types.
317 class TypeF : public Type {
318 TypeF( float f ) : Type(FloatCon), _f(f) {};
319 public:
320 virtual bool eq( const Type *t ) const;
321 virtual int hash() const; // Type specific hashing
322 virtual bool singleton(void) const; // TRUE if type is a singleton
323 virtual bool empty(void) const; // TRUE if type is vacuous
324 public:
325 const float _f; // Float constant
327 static const TypeF *make(float f);
329 virtual bool is_finite() const; // Has a finite value
330 virtual bool is_nan() const; // Is not a number (NaN)
332 virtual const Type *xmeet( const Type *t ) const;
333 virtual const Type *xdual() const; // Compute dual right now.
334 // Convenience common pre-built types.
335 static const TypeF *ZERO; // positive zero only
336 static const TypeF *ONE;
337 #ifndef PRODUCT
338 virtual void dump2( Dict &d, uint depth, outputStream *st ) const;
339 #endif
340 };
342 //------------------------------TypeD------------------------------------------
343 // Class of Double-Constant Types.
344 class TypeD : public Type {
345 TypeD( double d ) : Type(DoubleCon), _d(d) {};
346 public:
347 virtual bool eq( const Type *t ) const;
348 virtual int hash() const; // Type specific hashing
349 virtual bool singleton(void) const; // TRUE if type is a singleton
350 virtual bool empty(void) const; // TRUE if type is vacuous
351 public:
352 const double _d; // Double constant
354 static const TypeD *make(double d);
356 virtual bool is_finite() const; // Has a finite value
357 virtual bool is_nan() const; // Is not a number (NaN)
359 virtual const Type *xmeet( const Type *t ) const;
360 virtual const Type *xdual() const; // Compute dual right now.
361 // Convenience common pre-built types.
362 static const TypeD *ZERO; // positive zero only
363 static const TypeD *ONE;
364 #ifndef PRODUCT
365 virtual void dump2( Dict &d, uint depth, outputStream *st ) const;
366 #endif
367 };
369 //------------------------------TypeInt----------------------------------------
370 // Class of integer ranges, the set of integers between a lower bound and an
371 // upper bound, inclusive.
372 class TypeInt : public Type {
373 TypeInt( jint lo, jint hi, int w );
374 public:
375 virtual bool eq( const Type *t ) const;
376 virtual int hash() const; // Type specific hashing
377 virtual bool singleton(void) const; // TRUE if type is a singleton
378 virtual bool empty(void) const; // TRUE if type is vacuous
379 public:
380 const jint _lo, _hi; // Lower bound, upper bound
381 const short _widen; // Limit on times we widen this sucker
383 static const TypeInt *make(jint lo);
384 // must always specify w
385 static const TypeInt *make(jint lo, jint hi, int w);
387 // Check for single integer
388 int is_con() const { return _lo==_hi; }
389 bool is_con(int i) const { return is_con() && _lo == i; }
390 jint get_con() const { assert( is_con(), "" ); return _lo; }
392 virtual bool is_finite() const; // Has a finite value
394 virtual const Type *xmeet( const Type *t ) const;
395 virtual const Type *xdual() const; // Compute dual right now.
396 virtual const Type *widen( const Type *t ) const;
397 virtual const Type *narrow( const Type *t ) const;
398 // Do not kill _widen bits.
399 virtual const Type *filter( const Type *kills ) const;
400 // Convenience common pre-built types.
401 static const TypeInt *MINUS_1;
402 static const TypeInt *ZERO;
403 static const TypeInt *ONE;
404 static const TypeInt *BOOL;
405 static const TypeInt *CC;
406 static const TypeInt *CC_LT; // [-1] == MINUS_1
407 static const TypeInt *CC_GT; // [1] == ONE
408 static const TypeInt *CC_EQ; // [0] == ZERO
409 static const TypeInt *CC_LE; // [-1,0]
410 static const TypeInt *CC_GE; // [0,1] == BOOL (!)
411 static const TypeInt *BYTE;
412 static const TypeInt *CHAR;
413 static const TypeInt *SHORT;
414 static const TypeInt *POS;
415 static const TypeInt *POS1;
416 static const TypeInt *INT;
417 static const TypeInt *SYMINT; // symmetric range [-max_jint..max_jint]
418 #ifndef PRODUCT
419 virtual void dump2( Dict &d, uint depth, outputStream *st ) const;
420 #endif
421 };
424 //------------------------------TypeLong---------------------------------------
425 // Class of long integer ranges, the set of integers between a lower bound and
426 // an upper bound, inclusive.
427 class TypeLong : public Type {
428 TypeLong( jlong lo, jlong hi, int w );
429 public:
430 virtual bool eq( const Type *t ) const;
431 virtual int hash() const; // Type specific hashing
432 virtual bool singleton(void) const; // TRUE if type is a singleton
433 virtual bool empty(void) const; // TRUE if type is vacuous
434 public:
435 const jlong _lo, _hi; // Lower bound, upper bound
436 const short _widen; // Limit on times we widen this sucker
438 static const TypeLong *make(jlong lo);
439 // must always specify w
440 static const TypeLong *make(jlong lo, jlong hi, int w);
442 // Check for single integer
443 int is_con() const { return _lo==_hi; }
444 bool is_con(int i) const { return is_con() && _lo == i; }
445 jlong get_con() const { assert( is_con(), "" ); return _lo; }
447 virtual bool is_finite() const; // Has a finite value
449 virtual const Type *xmeet( const Type *t ) const;
450 virtual const Type *xdual() const; // Compute dual right now.
451 virtual const Type *widen( const Type *t ) const;
452 virtual const Type *narrow( const Type *t ) const;
453 // Do not kill _widen bits.
454 virtual const Type *filter( const Type *kills ) const;
455 // Convenience common pre-built types.
456 static const TypeLong *MINUS_1;
457 static const TypeLong *ZERO;
458 static const TypeLong *ONE;
459 static const TypeLong *POS;
460 static const TypeLong *LONG;
461 static const TypeLong *INT; // 32-bit subrange [min_jint..max_jint]
462 static const TypeLong *UINT; // 32-bit unsigned [0..max_juint]
463 #ifndef PRODUCT
464 virtual void dump2( Dict &d, uint, outputStream *st ) const;// Specialized per-Type dumping
465 #endif
466 };
468 //------------------------------TypeTuple--------------------------------------
469 // Class of Tuple Types, essentially type collections for function signatures
470 // and class layouts. It happens to also be a fast cache for the HotSpot
471 // signature types.
472 class TypeTuple : public Type {
473 TypeTuple( uint cnt, const Type **fields ) : Type(Tuple), _cnt(cnt), _fields(fields) { }
474 public:
475 virtual bool eq( const Type *t ) const;
476 virtual int hash() const; // Type specific hashing
477 virtual bool singleton(void) const; // TRUE if type is a singleton
478 virtual bool empty(void) const; // TRUE if type is vacuous
480 public:
481 const uint _cnt; // Count of fields
482 const Type ** const _fields; // Array of field types
484 // Accessors:
485 uint cnt() const { return _cnt; }
486 const Type* field_at(uint i) const {
487 assert(i < _cnt, "oob");
488 return _fields[i];
489 }
490 void set_field_at(uint i, const Type* t) {
491 assert(i < _cnt, "oob");
492 _fields[i] = t;
493 }
495 static const TypeTuple *make( uint cnt, const Type **fields );
496 static const TypeTuple *make_range(ciSignature *sig);
497 static const TypeTuple *make_domain(ciInstanceKlass* recv, ciSignature *sig);
499 // Subroutine call type with space allocated for argument types
500 static const Type **fields( uint arg_cnt );
502 virtual const Type *xmeet( const Type *t ) const;
503 virtual const Type *xdual() const; // Compute dual right now.
504 // Convenience common pre-built types.
505 static const TypeTuple *IFBOTH;
506 static const TypeTuple *IFFALSE;
507 static const TypeTuple *IFTRUE;
508 static const TypeTuple *IFNEITHER;
509 static const TypeTuple *LOOPBODY;
510 static const TypeTuple *MEMBAR;
511 static const TypeTuple *STORECONDITIONAL;
512 static const TypeTuple *START_I2C;
513 static const TypeTuple *INT_PAIR;
514 static const TypeTuple *LONG_PAIR;
515 #ifndef PRODUCT
516 virtual void dump2( Dict &d, uint, outputStream *st ) const; // Specialized per-Type dumping
517 #endif
518 };
520 //------------------------------TypeAry----------------------------------------
521 // Class of Array Types
522 class TypeAry : public Type {
523 TypeAry( const Type *elem, const TypeInt *size) : Type(Array),
524 _elem(elem), _size(size) {}
525 public:
526 virtual bool eq( const Type *t ) const;
527 virtual int hash() const; // Type specific hashing
528 virtual bool singleton(void) const; // TRUE if type is a singleton
529 virtual bool empty(void) const; // TRUE if type is vacuous
531 private:
532 const Type *_elem; // Element type of array
533 const TypeInt *_size; // Elements in array
534 friend class TypeAryPtr;
536 public:
537 static const TypeAry *make( const Type *elem, const TypeInt *size);
539 virtual const Type *xmeet( const Type *t ) const;
540 virtual const Type *xdual() const; // Compute dual right now.
541 bool ary_must_be_exact() const; // true if arrays of such are never generic
542 #ifndef PRODUCT
543 virtual void dump2( Dict &d, uint, outputStream *st ) const; // Specialized per-Type dumping
544 #endif
545 };
547 //------------------------------TypePtr----------------------------------------
548 // Class of machine Pointer Types: raw data, instances or arrays.
549 // If the _base enum is AnyPtr, then this refers to all of the above.
550 // Otherwise the _base will indicate which subset of pointers is affected,
551 // and the class will be inherited from.
552 class TypePtr : public Type {
553 friend class TypeNarrowOop;
554 public:
555 enum PTR { TopPTR, AnyNull, Constant, Null, NotNull, BotPTR, lastPTR };
556 protected:
557 TypePtr( TYPES t, PTR ptr, int offset ) : Type(t), _ptr(ptr), _offset(offset) {}
558 virtual bool eq( const Type *t ) const;
559 virtual int hash() const; // Type specific hashing
560 static const PTR ptr_meet[lastPTR][lastPTR];
561 static const PTR ptr_dual[lastPTR];
562 static const char * const ptr_msg[lastPTR];
564 public:
565 const int _offset; // Offset into oop, with TOP & BOT
566 const PTR _ptr; // Pointer equivalence class
568 const int offset() const { return _offset; }
569 const PTR ptr() const { return _ptr; }
571 static const TypePtr *make( TYPES t, PTR ptr, int offset );
573 // Return a 'ptr' version of this type
574 virtual const Type *cast_to_ptr_type(PTR ptr) const;
576 virtual intptr_t get_con() const;
578 virtual const TypePtr *add_offset( int offset ) const;
580 virtual bool singleton(void) const; // TRUE if type is a singleton
581 virtual bool empty(void) const; // TRUE if type is vacuous
582 virtual const Type *xmeet( const Type *t ) const;
583 int meet_offset( int offset ) const;
584 int dual_offset( ) const;
585 virtual const Type *xdual() const; // Compute dual right now.
587 // meet, dual and join over pointer equivalence sets
588 PTR meet_ptr( const PTR in_ptr ) const { return ptr_meet[in_ptr][ptr()]; }
589 PTR dual_ptr() const { return ptr_dual[ptr()]; }
591 // This is textually confusing unless one recalls that
592 // join(t) == dual()->meet(t->dual())->dual().
593 PTR join_ptr( const PTR in_ptr ) const {
594 return ptr_dual[ ptr_meet[ ptr_dual[in_ptr] ] [ dual_ptr() ] ];
595 }
597 // Tests for relation to centerline of type lattice:
598 static bool above_centerline(PTR ptr) { return (ptr <= AnyNull); }
599 static bool below_centerline(PTR ptr) { return (ptr >= NotNull); }
600 // Convenience common pre-built types.
601 static const TypePtr *NULL_PTR;
602 static const TypePtr *NOTNULL;
603 static const TypePtr *BOTTOM;
604 #ifndef PRODUCT
605 virtual void dump2( Dict &d, uint depth, outputStream *st ) const;
606 #endif
607 };
609 //------------------------------TypeRawPtr-------------------------------------
610 // Class of raw pointers, pointers to things other than Oops. Examples
611 // include the stack pointer, top of heap, card-marking area, handles, etc.
612 class TypeRawPtr : public TypePtr {
613 protected:
614 TypeRawPtr( PTR ptr, address bits ) : TypePtr(RawPtr,ptr,0), _bits(bits){}
615 public:
616 virtual bool eq( const Type *t ) const;
617 virtual int hash() const; // Type specific hashing
619 const address _bits; // Constant value, if applicable
621 static const TypeRawPtr *make( PTR ptr );
622 static const TypeRawPtr *make( address bits );
624 // Return a 'ptr' version of this type
625 virtual const Type *cast_to_ptr_type(PTR ptr) const;
627 virtual intptr_t get_con() const;
629 virtual const TypePtr *add_offset( int offset ) const;
631 virtual const Type *xmeet( const Type *t ) const;
632 virtual const Type *xdual() const; // Compute dual right now.
633 // Convenience common pre-built types.
634 static const TypeRawPtr *BOTTOM;
635 static const TypeRawPtr *NOTNULL;
636 #ifndef PRODUCT
637 virtual void dump2( Dict &d, uint depth, outputStream *st ) const;
638 #endif
639 };
641 //------------------------------TypeOopPtr-------------------------------------
642 // Some kind of oop (Java pointer), either klass or instance or array.
643 class TypeOopPtr : public TypePtr {
644 protected:
645 TypeOopPtr( TYPES t, PTR ptr, ciKlass* k, bool xk, ciObject* o, int offset, int instance_id );
646 public:
647 virtual bool eq( const Type *t ) const;
648 virtual int hash() const; // Type specific hashing
649 virtual bool singleton(void) const; // TRUE if type is a singleton
650 enum {
651 UNKNOWN_INSTANCE = 0
652 };
653 protected:
655 int xadd_offset( int offset ) const;
656 // Oop is NULL, unless this is a constant oop.
657 ciObject* _const_oop; // Constant oop
658 // If _klass is NULL, then so is _sig. This is an unloaded klass.
659 ciKlass* _klass; // Klass object
660 // Does the type exclude subclasses of the klass? (Inexact == polymorphic.)
661 bool _klass_is_exact;
662 bool _is_ptr_to_narrowoop;
664 int _instance_id; // if not UNKNOWN_INSTANCE, indicates that this is a particular instance
665 // of this type which is distinct. This is the the node index of the
666 // node creating this instance
668 static const TypeOopPtr* make_from_klass_common(ciKlass* klass, bool klass_change, bool try_for_exact);
670 int dual_instance() const { return -_instance_id; }
671 int meet_instance(int uid) const;
673 public:
674 // Creates a type given a klass. Correctly handles multi-dimensional arrays
675 // Respects UseUniqueSubclasses.
676 // If the klass is final, the resulting type will be exact.
677 static const TypeOopPtr* make_from_klass(ciKlass* klass) {
678 return make_from_klass_common(klass, true, false);
679 }
680 // Same as before, but will produce an exact type, even if
681 // the klass is not final, as long as it has exactly one implementation.
682 static const TypeOopPtr* make_from_klass_unique(ciKlass* klass) {
683 return make_from_klass_common(klass, true, true);
684 }
685 // Same as before, but does not respects UseUniqueSubclasses.
686 // Use this only for creating array element types.
687 static const TypeOopPtr* make_from_klass_raw(ciKlass* klass) {
688 return make_from_klass_common(klass, false, false);
689 }
690 // Creates a singleton type given an object.
691 static const TypeOopPtr* make_from_constant(ciObject* o);
693 // Make a generic (unclassed) pointer to an oop.
694 static const TypeOopPtr* make(PTR ptr, int offset);
696 ciObject* const_oop() const { return _const_oop; }
697 virtual ciKlass* klass() const { return _klass; }
698 bool klass_is_exact() const { return _klass_is_exact; }
700 // Returns true if this pointer points at memory which contains a
701 // compressed oop references.
702 bool is_ptr_to_narrowoop_nv() const { return _is_ptr_to_narrowoop; }
704 bool is_instance() const { return _instance_id != UNKNOWN_INSTANCE; }
705 uint instance_id() const { return _instance_id; }
706 bool is_instance_field() const { return _instance_id != UNKNOWN_INSTANCE && _offset >= 0; }
708 virtual intptr_t get_con() const;
710 virtual const Type *cast_to_ptr_type(PTR ptr) const;
712 virtual const Type *cast_to_exactness(bool klass_is_exact) const;
714 virtual const TypeOopPtr *cast_to_instance(int instance_id) const;
716 // corresponding pointer to klass, for a given instance
717 const TypeKlassPtr* as_klass_type() const;
719 virtual const TypePtr *add_offset( int offset ) const;
721 // returns the equivalent compressed version of this pointer type
722 virtual const TypeNarrowOop* make_narrowoop() const;
724 virtual const Type *xmeet( const Type *t ) const;
725 virtual const Type *xdual() const; // Compute dual right now.
727 // Do not allow interface-vs.-noninterface joins to collapse to top.
728 virtual const Type *filter( const Type *kills ) const;
730 // Convenience common pre-built type.
731 static const TypeOopPtr *BOTTOM;
732 #ifndef PRODUCT
733 virtual void dump2( Dict &d, uint depth, outputStream *st ) const;
734 #endif
735 };
737 //------------------------------TypeInstPtr------------------------------------
738 // Class of Java object pointers, pointing either to non-array Java instances
739 // or to a klassOop (including array klasses).
740 class TypeInstPtr : public TypeOopPtr {
741 TypeInstPtr( PTR ptr, ciKlass* k, bool xk, ciObject* o, int offset, int instance_id );
742 virtual bool eq( const Type *t ) const;
743 virtual int hash() const; // Type specific hashing
745 ciSymbol* _name; // class name
747 public:
748 ciSymbol* name() const { return _name; }
750 bool is_loaded() const { return _klass->is_loaded(); }
752 // Make a pointer to a constant oop.
753 static const TypeInstPtr *make(ciObject* o) {
754 return make(TypePtr::Constant, o->klass(), true, o, 0);
755 }
757 // Make a pointer to a constant oop with offset.
758 static const TypeInstPtr *make(ciObject* o, int offset) {
759 return make(TypePtr::Constant, o->klass(), true, o, offset);
760 }
762 // Make a pointer to some value of type klass.
763 static const TypeInstPtr *make(PTR ptr, ciKlass* klass) {
764 return make(ptr, klass, false, NULL, 0);
765 }
767 // Make a pointer to some non-polymorphic value of exactly type klass.
768 static const TypeInstPtr *make_exact(PTR ptr, ciKlass* klass) {
769 return make(ptr, klass, true, NULL, 0);
770 }
772 // Make a pointer to some value of type klass with offset.
773 static const TypeInstPtr *make(PTR ptr, ciKlass* klass, int offset) {
774 return make(ptr, klass, false, NULL, offset);
775 }
777 // Make a pointer to an oop.
778 static const TypeInstPtr *make(PTR ptr, ciKlass* k, bool xk, ciObject* o, int offset, int instance_id = 0 );
780 // If this is a java.lang.Class constant, return the type for it or NULL.
781 // Pass to Type::get_const_type to turn it to a type, which will usually
782 // be a TypeInstPtr, but may also be a TypeInt::INT for int.class, etc.
783 ciType* java_mirror_type() const;
785 virtual const Type *cast_to_ptr_type(PTR ptr) const;
787 virtual const Type *cast_to_exactness(bool klass_is_exact) const;
789 virtual const TypeOopPtr *cast_to_instance(int instance_id) const;
791 virtual const TypePtr *add_offset( int offset ) const;
793 virtual const Type *xmeet( const Type *t ) const;
794 virtual const TypeInstPtr *xmeet_unloaded( const TypeInstPtr *t ) const;
795 virtual const Type *xdual() const; // Compute dual right now.
797 // Convenience common pre-built types.
798 static const TypeInstPtr *NOTNULL;
799 static const TypeInstPtr *BOTTOM;
800 static const TypeInstPtr *MIRROR;
801 static const TypeInstPtr *MARK;
802 static const TypeInstPtr *KLASS;
803 #ifndef PRODUCT
804 virtual void dump2( Dict &d, uint depth, outputStream *st ) const; // Specialized per-Type dumping
805 #endif
806 };
808 //------------------------------TypeAryPtr-------------------------------------
809 // Class of Java array pointers
810 class TypeAryPtr : public TypeOopPtr {
811 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) {};
812 virtual bool eq( const Type *t ) const;
813 virtual int hash() const; // Type specific hashing
814 const TypeAry *_ary; // Array we point into
816 public:
817 // Accessors
818 ciKlass* klass() const;
819 const TypeAry* ary() const { return _ary; }
820 const Type* elem() const { return _ary->_elem; }
821 const TypeInt* size() const { return _ary->_size; }
823 static const TypeAryPtr *make( PTR ptr, const TypeAry *ary, ciKlass* k, bool xk, int offset, int instance_id = 0);
824 // Constant pointer to array
825 static const TypeAryPtr *make( PTR ptr, ciObject* o, const TypeAry *ary, ciKlass* k, bool xk, int offset, int instance_id = 0);
827 // Convenience
828 static const TypeAryPtr *make(ciObject* o);
830 // Return a 'ptr' version of this type
831 virtual const Type *cast_to_ptr_type(PTR ptr) const;
833 virtual const Type *cast_to_exactness(bool klass_is_exact) const;
835 virtual const TypeOopPtr *cast_to_instance(int instance_id) const;
837 virtual const TypeAryPtr* cast_to_size(const TypeInt* size) const;
839 virtual bool empty(void) const; // TRUE if type is vacuous
840 virtual const TypePtr *add_offset( int offset ) const;
842 virtual const Type *xmeet( const Type *t ) const;
843 virtual const Type *xdual() const; // Compute dual right now.
845 // Convenience common pre-built types.
846 static const TypeAryPtr *RANGE;
847 static const TypeAryPtr *OOPS;
848 static const TypeAryPtr *NARROWOOPS;
849 static const TypeAryPtr *BYTES;
850 static const TypeAryPtr *SHORTS;
851 static const TypeAryPtr *CHARS;
852 static const TypeAryPtr *INTS;
853 static const TypeAryPtr *LONGS;
854 static const TypeAryPtr *FLOATS;
855 static const TypeAryPtr *DOUBLES;
856 // selects one of the above:
857 static const TypeAryPtr *get_array_body_type(BasicType elem) {
858 assert((uint)elem <= T_CONFLICT && _array_body_type[elem] != NULL, "bad elem type");
859 return _array_body_type[elem];
860 }
861 static const TypeAryPtr *_array_body_type[T_CONFLICT+1];
862 // sharpen the type of an int which is used as an array size
863 static const TypeInt* narrow_size_type(const TypeInt* size, BasicType elem);
864 #ifndef PRODUCT
865 virtual void dump2( Dict &d, uint depth, outputStream *st ) const; // Specialized per-Type dumping
866 #endif
867 };
869 //------------------------------TypeKlassPtr-----------------------------------
870 // Class of Java Klass pointers
871 class TypeKlassPtr : public TypeOopPtr {
872 TypeKlassPtr( PTR ptr, ciKlass* klass, int offset );
874 virtual bool eq( const Type *t ) const;
875 virtual int hash() const; // Type specific hashing
877 public:
878 ciSymbol* name() const { return _klass->name(); }
880 // ptr to klass 'k'
881 static const TypeKlassPtr *make( ciKlass* k ) { return make( TypePtr::Constant, k, 0); }
882 // ptr to klass 'k' with offset
883 static const TypeKlassPtr *make( ciKlass* k, int offset ) { return make( TypePtr::Constant, k, offset); }
884 // ptr to klass 'k' or sub-klass
885 static const TypeKlassPtr *make( PTR ptr, ciKlass* k, int offset);
887 virtual const Type *cast_to_ptr_type(PTR ptr) const;
889 virtual const Type *cast_to_exactness(bool klass_is_exact) const;
891 // corresponding pointer to instance, for a given class
892 const TypeOopPtr* as_instance_type() const;
894 virtual const TypePtr *add_offset( int offset ) const;
895 virtual const Type *xmeet( const Type *t ) const;
896 virtual const Type *xdual() const; // Compute dual right now.
898 // Convenience common pre-built types.
899 static const TypeKlassPtr* OBJECT; // Not-null object klass or below
900 static const TypeKlassPtr* OBJECT_OR_NULL; // Maybe-null version of same
901 #ifndef PRODUCT
902 virtual void dump2( Dict &d, uint depth, outputStream *st ) const; // Specialized per-Type dumping
903 #endif
904 };
906 //------------------------------TypeNarrowOop----------------------------------
907 // A compressed reference to some kind of Oop. This type wraps around
908 // a preexisting TypeOopPtr and forwards most of it's operations to
909 // the underlying type. It's only real purpose is to track the
910 // oopness of the compressed oop value when we expose the conversion
911 // between the normal and the compressed form.
912 class TypeNarrowOop : public Type {
913 protected:
914 const TypePtr* _ooptype;
916 TypeNarrowOop( const TypePtr* ooptype): Type(NarrowOop),
917 _ooptype(ooptype) {
918 assert(ooptype->offset() == 0 ||
919 ooptype->offset() == OffsetBot ||
920 ooptype->offset() == OffsetTop, "no real offsets");
921 }
922 public:
923 virtual bool eq( const Type *t ) const;
924 virtual int hash() const; // Type specific hashing
925 virtual bool singleton(void) const; // TRUE if type is a singleton
927 virtual const Type *xmeet( const Type *t ) const;
928 virtual const Type *xdual() const; // Compute dual right now.
930 virtual intptr_t get_con() const;
932 // Do not allow interface-vs.-noninterface joins to collapse to top.
933 virtual const Type *filter( const Type *kills ) const;
935 virtual bool empty(void) const; // TRUE if type is vacuous
937 static const TypeNarrowOop *make( const TypePtr* type);
939 static const TypeNarrowOop* make_from_constant(ciObject* con) {
940 return make(TypeOopPtr::make_from_constant(con));
941 }
943 // returns the equivalent oopptr type for this compressed pointer
944 virtual const TypePtr *make_oopptr() const {
945 return _ooptype;
946 }
948 static const TypeNarrowOop *BOTTOM;
949 static const TypeNarrowOop *NULL_PTR;
951 #ifndef PRODUCT
952 virtual void dump2( Dict &d, uint depth, outputStream *st ) const;
953 #endif
954 };
956 //------------------------------TypeFunc---------------------------------------
957 // Class of Array Types
958 class TypeFunc : public Type {
959 TypeFunc( const TypeTuple *domain, const TypeTuple *range ) : Type(Function), _domain(domain), _range(range) {}
960 virtual bool eq( const Type *t ) const;
961 virtual int hash() const; // Type specific hashing
962 virtual bool singleton(void) const; // TRUE if type is a singleton
963 virtual bool empty(void) const; // TRUE if type is vacuous
964 public:
965 // Constants are shared among ADLC and VM
966 enum { Control = AdlcVMDeps::Control,
967 I_O = AdlcVMDeps::I_O,
968 Memory = AdlcVMDeps::Memory,
969 FramePtr = AdlcVMDeps::FramePtr,
970 ReturnAdr = AdlcVMDeps::ReturnAdr,
971 Parms = AdlcVMDeps::Parms
972 };
974 const TypeTuple* const _domain; // Domain of inputs
975 const TypeTuple* const _range; // Range of results
977 // Accessors:
978 const TypeTuple* domain() const { return _domain; }
979 const TypeTuple* range() const { return _range; }
981 static const TypeFunc *make(ciMethod* method);
982 static const TypeFunc *make(ciSignature signature, const Type* extra);
983 static const TypeFunc *make(const TypeTuple* domain, const TypeTuple* range);
985 virtual const Type *xmeet( const Type *t ) const;
986 virtual const Type *xdual() const; // Compute dual right now.
988 BasicType return_type() const;
990 #ifndef PRODUCT
991 virtual void dump2( Dict &d, uint depth, outputStream *st ) const; // Specialized per-Type dumping
992 void print_flattened() const; // Print a 'flattened' signature
993 #endif
994 // Convenience common pre-built types.
995 };
997 //------------------------------accessors--------------------------------------
998 inline bool Type::is_ptr_to_narrowoop() const {
999 #ifdef _LP64
1000 return (isa_oopptr() != NULL && is_oopptr()->is_ptr_to_narrowoop_nv());
1001 #else
1002 return false;
1003 #endif
1004 }
1006 inline float Type::getf() const {
1007 assert( _base == FloatCon, "Not a FloatCon" );
1008 return ((TypeF*)this)->_f;
1009 }
1011 inline double Type::getd() const {
1012 assert( _base == DoubleCon, "Not a DoubleCon" );
1013 return ((TypeD*)this)->_d;
1014 }
1016 inline const TypeF *Type::is_float_constant() const {
1017 assert( _base == FloatCon, "Not a Float" );
1018 return (TypeF*)this;
1019 }
1021 inline const TypeF *Type::isa_float_constant() const {
1022 return ( _base == FloatCon ? (TypeF*)this : NULL);
1023 }
1025 inline const TypeD *Type::is_double_constant() const {
1026 assert( _base == DoubleCon, "Not a Double" );
1027 return (TypeD*)this;
1028 }
1030 inline const TypeD *Type::isa_double_constant() const {
1031 return ( _base == DoubleCon ? (TypeD*)this : NULL);
1032 }
1034 inline const TypeInt *Type::is_int() const {
1035 assert( _base == Int, "Not an Int" );
1036 return (TypeInt*)this;
1037 }
1039 inline const TypeInt *Type::isa_int() const {
1040 return ( _base == Int ? (TypeInt*)this : NULL);
1041 }
1043 inline const TypeLong *Type::is_long() const {
1044 assert( _base == Long, "Not a Long" );
1045 return (TypeLong*)this;
1046 }
1048 inline const TypeLong *Type::isa_long() const {
1049 return ( _base == Long ? (TypeLong*)this : NULL);
1050 }
1052 inline const TypeTuple *Type::is_tuple() const {
1053 assert( _base == Tuple, "Not a Tuple" );
1054 return (TypeTuple*)this;
1055 }
1057 inline const TypeAry *Type::is_ary() const {
1058 assert( _base == Array , "Not an Array" );
1059 return (TypeAry*)this;
1060 }
1062 inline const TypePtr *Type::is_ptr() const {
1063 // AnyPtr is the first Ptr and KlassPtr the last, with no non-ptrs between.
1064 assert(_base >= AnyPtr && _base <= KlassPtr, "Not a pointer");
1065 return (TypePtr*)this;
1066 }
1068 inline const TypePtr *Type::isa_ptr() const {
1069 // AnyPtr is the first Ptr and KlassPtr the last, with no non-ptrs between.
1070 return (_base >= AnyPtr && _base <= KlassPtr) ? (TypePtr*)this : NULL;
1071 }
1073 inline const TypeOopPtr *Type::is_oopptr() const {
1074 // OopPtr is the first and KlassPtr the last, with no non-oops between.
1075 assert(_base >= OopPtr && _base <= KlassPtr, "Not a Java pointer" ) ;
1076 return (TypeOopPtr*)this;
1077 }
1079 inline const TypeOopPtr *Type::isa_oopptr() const {
1080 // OopPtr is the first and KlassPtr the last, with no non-oops between.
1081 return (_base >= OopPtr && _base <= KlassPtr) ? (TypeOopPtr*)this : NULL;
1082 }
1084 inline const TypeRawPtr *Type::isa_rawptr() const {
1085 return (_base == RawPtr) ? (TypeRawPtr*)this : NULL;
1086 }
1088 inline const TypeRawPtr *Type::is_rawptr() const {
1089 assert( _base == RawPtr, "Not a raw pointer" );
1090 return (TypeRawPtr*)this;
1091 }
1093 inline const TypeInstPtr *Type::isa_instptr() const {
1094 return (_base == InstPtr) ? (TypeInstPtr*)this : NULL;
1095 }
1097 inline const TypeInstPtr *Type::is_instptr() const {
1098 assert( _base == InstPtr, "Not an object pointer" );
1099 return (TypeInstPtr*)this;
1100 }
1102 inline const TypeAryPtr *Type::isa_aryptr() const {
1103 return (_base == AryPtr) ? (TypeAryPtr*)this : NULL;
1104 }
1106 inline const TypeAryPtr *Type::is_aryptr() const {
1107 assert( _base == AryPtr, "Not an array pointer" );
1108 return (TypeAryPtr*)this;
1109 }
1111 inline const TypeNarrowOop *Type::is_narrowoop() const {
1112 // OopPtr is the first and KlassPtr the last, with no non-oops between.
1113 assert(_base == NarrowOop, "Not a narrow oop" ) ;
1114 return (TypeNarrowOop*)this;
1115 }
1117 inline const TypeNarrowOop *Type::isa_narrowoop() const {
1118 // OopPtr is the first and KlassPtr the last, with no non-oops between.
1119 return (_base == NarrowOop) ? (TypeNarrowOop*)this : NULL;
1120 }
1122 inline const TypeKlassPtr *Type::isa_klassptr() const {
1123 return (_base == KlassPtr) ? (TypeKlassPtr*)this : NULL;
1124 }
1126 inline const TypeKlassPtr *Type::is_klassptr() const {
1127 assert( _base == KlassPtr, "Not a klass pointer" );
1128 return (TypeKlassPtr*)this;
1129 }
1131 inline bool Type::is_floatingpoint() const {
1132 if( (_base == FloatCon) || (_base == FloatBot) ||
1133 (_base == DoubleCon) || (_base == DoubleBot) )
1134 return true;
1135 return false;
1136 }
1139 // ===============================================================
1140 // Things that need to be 64-bits in the 64-bit build but
1141 // 32-bits in the 32-bit build. Done this way to get full
1142 // optimization AND strong typing.
1143 #ifdef _LP64
1145 // For type queries and asserts
1146 #define is_intptr_t is_long
1147 #define isa_intptr_t isa_long
1148 #define find_intptr_t_type find_long_type
1149 #define find_intptr_t_con find_long_con
1150 #define TypeX TypeLong
1151 #define Type_X Type::Long
1152 #define TypeX_X TypeLong::LONG
1153 #define TypeX_ZERO TypeLong::ZERO
1154 // For 'ideal_reg' machine registers
1155 #define Op_RegX Op_RegL
1156 // For phase->intcon variants
1157 #define MakeConX longcon
1158 #define ConXNode ConLNode
1159 // For array index arithmetic
1160 #define MulXNode MulLNode
1161 #define AndXNode AndLNode
1162 #define OrXNode OrLNode
1163 #define CmpXNode CmpLNode
1164 #define SubXNode SubLNode
1165 #define LShiftXNode LShiftLNode
1166 // For object size computation:
1167 #define AddXNode AddLNode
1168 #define RShiftXNode RShiftLNode
1169 // For card marks and hashcodes
1170 #define URShiftXNode URShiftLNode
1171 // Opcodes
1172 #define Op_LShiftX Op_LShiftL
1173 #define Op_AndX Op_AndL
1174 #define Op_AddX Op_AddL
1175 #define Op_SubX Op_SubL
1176 // conversions
1177 #define ConvI2X(x) ConvI2L(x)
1178 #define ConvL2X(x) (x)
1179 #define ConvX2I(x) ConvL2I(x)
1180 #define ConvX2L(x) (x)
1182 #else
1184 // For type queries and asserts
1185 #define is_intptr_t is_int
1186 #define isa_intptr_t isa_int
1187 #define find_intptr_t_type find_int_type
1188 #define find_intptr_t_con find_int_con
1189 #define TypeX TypeInt
1190 #define Type_X Type::Int
1191 #define TypeX_X TypeInt::INT
1192 #define TypeX_ZERO TypeInt::ZERO
1193 // For 'ideal_reg' machine registers
1194 #define Op_RegX Op_RegI
1195 // For phase->intcon variants
1196 #define MakeConX intcon
1197 #define ConXNode ConINode
1198 // For array index arithmetic
1199 #define MulXNode MulINode
1200 #define AndXNode AndINode
1201 #define OrXNode OrINode
1202 #define CmpXNode CmpINode
1203 #define SubXNode SubINode
1204 #define LShiftXNode LShiftINode
1205 // For object size computation:
1206 #define AddXNode AddINode
1207 #define RShiftXNode RShiftINode
1208 // For card marks and hashcodes
1209 #define URShiftXNode URShiftINode
1210 // Opcodes
1211 #define Op_LShiftX Op_LShiftI
1212 #define Op_AndX Op_AndI
1213 #define Op_AddX Op_AddI
1214 #define Op_SubX Op_SubI
1215 // conversions
1216 #define ConvI2X(x) (x)
1217 #define ConvL2X(x) ConvL2I(x)
1218 #define ConvX2I(x) (x)
1219 #define ConvX2L(x) ConvI2L(x)
1221 #endif