Thu, 20 Mar 2008 15:11:44 -0700
6674600: (Escape Analysis) Optimize memory graph for instance's fields
Summary: EA gives opportunite to do more aggressive memory optimizations.
Reviewed-by: never, jrose
1 /*
2 * Copyright 1997-2007 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 TypeAry;
45 class TypeTuple;
46 class TypePtr;
47 class TypeRawPtr;
48 class TypeOopPtr;
49 class TypeInstPtr;
50 class TypeAryPtr;
51 class TypeKlassPtr;
53 //------------------------------Type-------------------------------------------
54 // Basic Type object, represents a set of primitive Values.
55 // Types are hash-cons'd into a private class dictionary, so only one of each
56 // different kind of Type exists. Types are never modified after creation, so
57 // all their interesting fields are constant.
58 class Type {
59 public:
60 enum TYPES {
61 Bad=0, // Type check
62 Control, // Control of code (not in lattice)
63 Top, // Top of the lattice
64 Int, // Integer range (lo-hi)
65 Long, // Long integer range (lo-hi)
66 Half, // Placeholder half of doubleword
68 Tuple, // Method signature or object layout
69 Array, // Array types
71 AnyPtr, // Any old raw, klass, inst, or array pointer
72 RawPtr, // Raw (non-oop) pointers
73 OopPtr, // Any and all Java heap entities
74 InstPtr, // Instance pointers (non-array objects)
75 AryPtr, // Array pointers
76 KlassPtr, // Klass pointers
77 // (Ptr order matters: See is_ptr, isa_ptr, is_oopptr, isa_oopptr.)
79 Function, // Function signature
80 Abio, // Abstract I/O
81 Return_Address, // Subroutine return address
82 Memory, // Abstract store
83 FloatTop, // No float value
84 FloatCon, // Floating point constant
85 FloatBot, // Any float value
86 DoubleTop, // No double value
87 DoubleCon, // Double precision constant
88 DoubleBot, // Any double value
89 Bottom, // Bottom of lattice
90 lastype // Bogus ending type (not in lattice)
91 };
93 // Signal values for offsets from a base pointer
94 enum OFFSET_SIGNALS {
95 OffsetTop = -2000000000, // undefined offset
96 OffsetBot = -2000000001 // any possible offset
97 };
99 // Min and max WIDEN values.
100 enum WIDEN {
101 WidenMin = 0,
102 WidenMax = 3
103 };
105 private:
106 // Dictionary of types shared among compilations.
107 static Dict* _shared_type_dict;
109 static int uhash( const Type *const t );
110 // Structural equality check. Assumes that cmp() has already compared
111 // the _base types and thus knows it can cast 't' appropriately.
112 virtual bool eq( const Type *t ) const;
114 // Top-level hash-table of types
115 static Dict *type_dict() {
116 return Compile::current()->type_dict();
117 }
119 // DUAL operation: reflect around lattice centerline. Used instead of
120 // join to ensure my lattice is symmetric up and down. Dual is computed
121 // lazily, on demand, and cached in _dual.
122 const Type *_dual; // Cached dual value
123 // Table for efficient dualing of base types
124 static const TYPES dual_type[lastype];
126 protected:
127 // Each class of type is also identified by its base.
128 const TYPES _base; // Enum of Types type
130 Type( TYPES t ) : _dual(NULL), _base(t) {} // Simple types
131 // ~Type(); // Use fast deallocation
132 const Type *hashcons(); // Hash-cons the type
134 public:
136 inline void* operator new( size_t x ) {
137 Compile* compile = Compile::current();
138 compile->set_type_last_size(x);
139 void *temp = compile->type_arena()->Amalloc_D(x);
140 compile->set_type_hwm(temp);
141 return temp;
142 }
143 inline void operator delete( void* ptr ) {
144 Compile* compile = Compile::current();
145 compile->type_arena()->Afree(ptr,compile->type_last_size());
146 }
148 // Initialize the type system for a particular compilation.
149 static void Initialize(Compile* compile);
151 // Initialize the types shared by all compilations.
152 static void Initialize_shared(Compile* compile);
154 TYPES base() const {
155 assert(_base > Bad && _base < lastype, "sanity");
156 return _base;
157 }
159 // Create a new hash-consd type
160 static const Type *make(enum TYPES);
161 // Test for equivalence of types
162 static int cmp( const Type *const t1, const Type *const t2 );
163 // Test for higher or equal in lattice
164 int higher_equal( const Type *t ) const { return !cmp(meet(t),t); }
166 // MEET operation; lower in lattice.
167 const Type *meet( const Type *t ) const;
168 // WIDEN: 'widens' for Ints and other range types
169 virtual const Type *widen( const Type *old ) const { return this; }
170 // NARROW: complement for widen, used by pessimistic phases
171 virtual const Type *narrow( const Type *old ) const { return this; }
173 // DUAL operation: reflect around lattice centerline. Used instead of
174 // join to ensure my lattice is symmetric up and down.
175 const Type *dual() const { return _dual; }
177 // Compute meet dependent on base type
178 virtual const Type *xmeet( const Type *t ) const;
179 virtual const Type *xdual() const; // Compute dual right now.
181 // JOIN operation; higher in lattice. Done by finding the dual of the
182 // meet of the dual of the 2 inputs.
183 const Type *join( const Type *t ) const {
184 return dual()->meet(t->dual())->dual(); }
186 // Modified version of JOIN adapted to the needs Node::Value.
187 // Normalizes all empty values to TOP. Does not kill _widen bits.
188 // Currently, it also works around limitations involving interface types.
189 virtual const Type *filter( const Type *kills ) const;
191 // Convenience access
192 float getf() const;
193 double getd() const;
195 const TypeInt *is_int() const;
196 const TypeInt *isa_int() const; // Returns NULL if not an Int
197 const TypeLong *is_long() const;
198 const TypeLong *isa_long() const; // Returns NULL if not a Long
199 const TypeD *is_double_constant() const; // Asserts it is a DoubleCon
200 const TypeD *isa_double_constant() const; // Returns NULL if not a DoubleCon
201 const TypeF *is_float_constant() const; // Asserts it is a FloatCon
202 const TypeF *isa_float_constant() const; // Returns NULL if not a FloatCon
203 const TypeTuple *is_tuple() const; // Collection of fields, NOT a pointer
204 const TypeAry *is_ary() const; // Array, NOT array pointer
205 const TypePtr *is_ptr() const; // Asserts it is a ptr type
206 const TypePtr *isa_ptr() const; // Returns NULL if not ptr type
207 const TypeRawPtr *is_rawptr() const; // NOT Java oop
208 const TypeOopPtr *isa_oopptr() const; // Returns NULL if not ptr type
209 const TypeKlassPtr *isa_klassptr() const; // Returns NULL if not KlassPtr
210 const TypeKlassPtr *is_klassptr() const; // assert if not KlassPtr
211 const TypeOopPtr *is_oopptr() const; // Java-style GC'd pointer
212 const TypeInstPtr *isa_instptr() const; // Returns NULL if not InstPtr
213 const TypeInstPtr *is_instptr() const; // Instance
214 const TypeAryPtr *isa_aryptr() const; // Returns NULL if not AryPtr
215 const TypeAryPtr *is_aryptr() const; // Array oop
216 virtual bool is_finite() const; // Has a finite value
217 virtual bool is_nan() const; // Is not a number (NaN)
219 // Special test for register pressure heuristic
220 bool is_floatingpoint() const; // True if Float or Double base type
222 // Do you have memory, directly or through a tuple?
223 bool has_memory( ) const;
225 // Are you a pointer type or not?
226 bool isa_oop_ptr() const;
228 // TRUE if type is a singleton
229 virtual bool singleton(void) const;
231 // TRUE if type is above the lattice centerline, and is therefore vacuous
232 virtual bool empty(void) const;
234 // Return a hash for this type. The hash function is public so ConNode
235 // (constants) can hash on their constant, which is represented by a Type.
236 virtual int hash() const;
238 // Map ideal registers (machine types) to ideal types
239 static const Type *mreg2type[];
241 // Printing, statistics
242 static const char * const msg[lastype]; // Printable strings
243 #ifndef PRODUCT
244 void dump_on(outputStream *st) const;
245 void dump() const {
246 dump_on(tty);
247 }
248 virtual void dump2( Dict &d, uint depth, outputStream *st ) const;
249 static void dump_stats();
250 static void verify_lastype(); // Check that arrays match type enum
251 #endif
252 void typerr(const Type *t) const; // Mixing types error
254 // Create basic type
255 static const Type* get_const_basic_type(BasicType type) {
256 assert((uint)type <= T_CONFLICT && _const_basic_type[type] != NULL, "bad type");
257 return _const_basic_type[type];
258 }
260 // Mapping to the array element's basic type.
261 BasicType array_element_basic_type() const;
263 // Create standard type for a ciType:
264 static const Type* get_const_type(ciType* type);
266 // Create standard zero value:
267 static const Type* get_zero_type(BasicType type) {
268 assert((uint)type <= T_CONFLICT && _zero_type[type] != NULL, "bad type");
269 return _zero_type[type];
270 }
272 // Report if this is a zero value (not top).
273 bool is_zero_type() const {
274 BasicType type = basic_type();
275 if (type == T_VOID || type >= T_CONFLICT)
276 return false;
277 else
278 return (this == _zero_type[type]);
279 }
281 // Convenience common pre-built types.
282 static const Type *ABIO;
283 static const Type *BOTTOM;
284 static const Type *CONTROL;
285 static const Type *DOUBLE;
286 static const Type *FLOAT;
287 static const Type *HALF;
288 static const Type *MEMORY;
289 static const Type *MULTI;
290 static const Type *RETURN_ADDRESS;
291 static const Type *TOP;
293 // Mapping from compiler type to VM BasicType
294 BasicType basic_type() const { return _basic_type[_base]; }
296 // Mapping from CI type system to compiler type:
297 static const Type* get_typeflow_type(ciType* type);
299 private:
300 // support arrays
301 static const BasicType _basic_type[];
302 static const Type* _zero_type[T_CONFLICT+1];
303 static const Type* _const_basic_type[T_CONFLICT+1];
304 };
306 //------------------------------TypeF------------------------------------------
307 // Class of Float-Constant Types.
308 class TypeF : public Type {
309 TypeF( float f ) : Type(FloatCon), _f(f) {};
310 public:
311 virtual bool eq( const Type *t ) const;
312 virtual int hash() const; // Type specific hashing
313 virtual bool singleton(void) const; // TRUE if type is a singleton
314 virtual bool empty(void) const; // TRUE if type is vacuous
315 public:
316 const float _f; // Float constant
318 static const TypeF *make(float f);
320 virtual bool is_finite() const; // Has a finite value
321 virtual bool is_nan() const; // Is not a number (NaN)
323 virtual const Type *xmeet( const Type *t ) const;
324 virtual const Type *xdual() const; // Compute dual right now.
325 // Convenience common pre-built types.
326 static const TypeF *ZERO; // positive zero only
327 static const TypeF *ONE;
328 #ifndef PRODUCT
329 virtual void dump2( Dict &d, uint depth, outputStream *st ) const;
330 #endif
331 };
333 //------------------------------TypeD------------------------------------------
334 // Class of Double-Constant Types.
335 class TypeD : public Type {
336 TypeD( double d ) : Type(DoubleCon), _d(d) {};
337 public:
338 virtual bool eq( const Type *t ) const;
339 virtual int hash() const; // Type specific hashing
340 virtual bool singleton(void) const; // TRUE if type is a singleton
341 virtual bool empty(void) const; // TRUE if type is vacuous
342 public:
343 const double _d; // Double constant
345 static const TypeD *make(double d);
347 virtual bool is_finite() const; // Has a finite value
348 virtual bool is_nan() const; // Is not a number (NaN)
350 virtual const Type *xmeet( const Type *t ) const;
351 virtual const Type *xdual() const; // Compute dual right now.
352 // Convenience common pre-built types.
353 static const TypeD *ZERO; // positive zero only
354 static const TypeD *ONE;
355 #ifndef PRODUCT
356 virtual void dump2( Dict &d, uint depth, outputStream *st ) const;
357 #endif
358 };
360 //------------------------------TypeInt----------------------------------------
361 // Class of integer ranges, the set of integers between a lower bound and an
362 // upper bound, inclusive.
363 class TypeInt : public Type {
364 TypeInt( jint lo, jint hi, int w );
365 public:
366 virtual bool eq( const Type *t ) const;
367 virtual int hash() const; // Type specific hashing
368 virtual bool singleton(void) const; // TRUE if type is a singleton
369 virtual bool empty(void) const; // TRUE if type is vacuous
370 public:
371 const jint _lo, _hi; // Lower bound, upper bound
372 const short _widen; // Limit on times we widen this sucker
374 static const TypeInt *make(jint lo);
375 // must always specify w
376 static const TypeInt *make(jint lo, jint hi, int w);
378 // Check for single integer
379 int is_con() const { return _lo==_hi; }
380 bool is_con(int i) const { return is_con() && _lo == i; }
381 jint get_con() const { assert( is_con(), "" ); return _lo; }
383 virtual bool is_finite() const; // Has a finite value
385 virtual const Type *xmeet( const Type *t ) const;
386 virtual const Type *xdual() const; // Compute dual right now.
387 virtual const Type *widen( const Type *t ) const;
388 virtual const Type *narrow( const Type *t ) const;
389 // Do not kill _widen bits.
390 virtual const Type *filter( const Type *kills ) const;
391 // Convenience common pre-built types.
392 static const TypeInt *MINUS_1;
393 static const TypeInt *ZERO;
394 static const TypeInt *ONE;
395 static const TypeInt *BOOL;
396 static const TypeInt *CC;
397 static const TypeInt *CC_LT; // [-1] == MINUS_1
398 static const TypeInt *CC_GT; // [1] == ONE
399 static const TypeInt *CC_EQ; // [0] == ZERO
400 static const TypeInt *CC_LE; // [-1,0]
401 static const TypeInt *CC_GE; // [0,1] == BOOL (!)
402 static const TypeInt *BYTE;
403 static const TypeInt *CHAR;
404 static const TypeInt *SHORT;
405 static const TypeInt *POS;
406 static const TypeInt *POS1;
407 static const TypeInt *INT;
408 static const TypeInt *SYMINT; // symmetric range [-max_jint..max_jint]
409 #ifndef PRODUCT
410 virtual void dump2( Dict &d, uint depth, outputStream *st ) const;
411 #endif
412 };
415 //------------------------------TypeLong---------------------------------------
416 // Class of long integer ranges, the set of integers between a lower bound and
417 // an upper bound, inclusive.
418 class TypeLong : public Type {
419 TypeLong( jlong lo, jlong hi, int w );
420 public:
421 virtual bool eq( const Type *t ) const;
422 virtual int hash() const; // Type specific hashing
423 virtual bool singleton(void) const; // TRUE if type is a singleton
424 virtual bool empty(void) const; // TRUE if type is vacuous
425 public:
426 const jlong _lo, _hi; // Lower bound, upper bound
427 const short _widen; // Limit on times we widen this sucker
429 static const TypeLong *make(jlong lo);
430 // must always specify w
431 static const TypeLong *make(jlong lo, jlong hi, int w);
433 // Check for single integer
434 int is_con() const { return _lo==_hi; }
435 jlong get_con() const { assert( is_con(), "" ); return _lo; }
437 virtual bool is_finite() const; // Has a finite value
439 virtual const Type *xmeet( const Type *t ) const;
440 virtual const Type *xdual() const; // Compute dual right now.
441 virtual const Type *widen( const Type *t ) const;
442 virtual const Type *narrow( const Type *t ) const;
443 // Do not kill _widen bits.
444 virtual const Type *filter( const Type *kills ) const;
445 // Convenience common pre-built types.
446 static const TypeLong *MINUS_1;
447 static const TypeLong *ZERO;
448 static const TypeLong *ONE;
449 static const TypeLong *POS;
450 static const TypeLong *LONG;
451 static const TypeLong *INT; // 32-bit subrange [min_jint..max_jint]
452 static const TypeLong *UINT; // 32-bit unsigned [0..max_juint]
453 #ifndef PRODUCT
454 virtual void dump2( Dict &d, uint, outputStream *st ) const;// Specialized per-Type dumping
455 #endif
456 };
458 //------------------------------TypeTuple--------------------------------------
459 // Class of Tuple Types, essentially type collections for function signatures
460 // and class layouts. It happens to also be a fast cache for the HotSpot
461 // signature types.
462 class TypeTuple : public Type {
463 TypeTuple( uint cnt, const Type **fields ) : Type(Tuple), _cnt(cnt), _fields(fields) { }
464 public:
465 virtual bool eq( const Type *t ) const;
466 virtual int hash() const; // Type specific hashing
467 virtual bool singleton(void) const; // TRUE if type is a singleton
468 virtual bool empty(void) const; // TRUE if type is vacuous
470 public:
471 const uint _cnt; // Count of fields
472 const Type ** const _fields; // Array of field types
474 // Accessors:
475 uint cnt() const { return _cnt; }
476 const Type* field_at(uint i) const {
477 assert(i < _cnt, "oob");
478 return _fields[i];
479 }
480 void set_field_at(uint i, const Type* t) {
481 assert(i < _cnt, "oob");
482 _fields[i] = t;
483 }
485 static const TypeTuple *make( uint cnt, const Type **fields );
486 static const TypeTuple *make_range(ciSignature *sig);
487 static const TypeTuple *make_domain(ciInstanceKlass* recv, ciSignature *sig);
489 // Subroutine call type with space allocated for argument types
490 static const Type **fields( uint arg_cnt );
492 virtual const Type *xmeet( const Type *t ) const;
493 virtual const Type *xdual() const; // Compute dual right now.
494 // Convenience common pre-built types.
495 static const TypeTuple *IFBOTH;
496 static const TypeTuple *IFFALSE;
497 static const TypeTuple *IFTRUE;
498 static const TypeTuple *IFNEITHER;
499 static const TypeTuple *LOOPBODY;
500 static const TypeTuple *MEMBAR;
501 static const TypeTuple *STORECONDITIONAL;
502 static const TypeTuple *START_I2C;
503 static const TypeTuple *INT_PAIR;
504 static const TypeTuple *LONG_PAIR;
505 #ifndef PRODUCT
506 virtual void dump2( Dict &d, uint, outputStream *st ) const; // Specialized per-Type dumping
507 #endif
508 };
510 //------------------------------TypeAry----------------------------------------
511 // Class of Array Types
512 class TypeAry : public Type {
513 TypeAry( const Type *elem, const TypeInt *size) : Type(Array),
514 _elem(elem), _size(size) {}
515 public:
516 virtual bool eq( const Type *t ) const;
517 virtual int hash() const; // Type specific hashing
518 virtual bool singleton(void) const; // TRUE if type is a singleton
519 virtual bool empty(void) const; // TRUE if type is vacuous
521 private:
522 const Type *_elem; // Element type of array
523 const TypeInt *_size; // Elements in array
524 friend class TypeAryPtr;
526 public:
527 static const TypeAry *make( const Type *elem, const TypeInt *size);
529 virtual const Type *xmeet( const Type *t ) const;
530 virtual const Type *xdual() const; // Compute dual right now.
531 bool ary_must_be_exact() const; // true if arrays of such are never generic
532 #ifndef PRODUCT
533 virtual void dump2( Dict &d, uint, outputStream *st ) const; // Specialized per-Type dumping
534 #endif
535 };
537 //------------------------------TypePtr----------------------------------------
538 // Class of machine Pointer Types: raw data, instances or arrays.
539 // If the _base enum is AnyPtr, then this refers to all of the above.
540 // Otherwise the _base will indicate which subset of pointers is affected,
541 // and the class will be inherited from.
542 class TypePtr : public Type {
543 public:
544 enum PTR { TopPTR, AnyNull, Constant, Null, NotNull, BotPTR, lastPTR };
545 protected:
546 TypePtr( TYPES t, PTR ptr, int offset ) : Type(t), _ptr(ptr), _offset(offset) {}
547 virtual bool eq( const Type *t ) const;
548 virtual int hash() const; // Type specific hashing
549 static const PTR ptr_meet[lastPTR][lastPTR];
550 static const PTR ptr_dual[lastPTR];
551 static const char * const ptr_msg[lastPTR];
553 public:
554 const int _offset; // Offset into oop, with TOP & BOT
555 const PTR _ptr; // Pointer equivalence class
557 const int offset() const { return _offset; }
558 const PTR ptr() const { return _ptr; }
560 static const TypePtr *make( TYPES t, PTR ptr, int offset );
562 // Return a 'ptr' version of this type
563 virtual const Type *cast_to_ptr_type(PTR ptr) const;
565 virtual intptr_t get_con() const;
567 virtual const TypePtr *add_offset( int offset ) const;
569 virtual bool singleton(void) const; // TRUE if type is a singleton
570 virtual bool empty(void) const; // TRUE if type is vacuous
571 virtual const Type *xmeet( const Type *t ) const;
572 int meet_offset( int offset ) const;
573 int dual_offset( ) const;
574 virtual const Type *xdual() const; // Compute dual right now.
576 // meet, dual and join over pointer equivalence sets
577 PTR meet_ptr( const PTR in_ptr ) const { return ptr_meet[in_ptr][ptr()]; }
578 PTR dual_ptr() const { return ptr_dual[ptr()]; }
580 // This is textually confusing unless one recalls that
581 // join(t) == dual()->meet(t->dual())->dual().
582 PTR join_ptr( const PTR in_ptr ) const {
583 return ptr_dual[ ptr_meet[ ptr_dual[in_ptr] ] [ dual_ptr() ] ];
584 }
586 // Tests for relation to centerline of type lattice:
587 static bool above_centerline(PTR ptr) { return (ptr <= AnyNull); }
588 static bool below_centerline(PTR ptr) { return (ptr >= NotNull); }
589 // Convenience common pre-built types.
590 static const TypePtr *NULL_PTR;
591 static const TypePtr *NOTNULL;
592 static const TypePtr *BOTTOM;
593 #ifndef PRODUCT
594 virtual void dump2( Dict &d, uint depth, outputStream *st ) const;
595 #endif
596 };
598 //------------------------------TypeRawPtr-------------------------------------
599 // Class of raw pointers, pointers to things other than Oops. Examples
600 // include the stack pointer, top of heap, card-marking area, handles, etc.
601 class TypeRawPtr : public TypePtr {
602 protected:
603 TypeRawPtr( PTR ptr, address bits ) : TypePtr(RawPtr,ptr,0), _bits(bits){}
604 public:
605 virtual bool eq( const Type *t ) const;
606 virtual int hash() const; // Type specific hashing
608 const address _bits; // Constant value, if applicable
610 static const TypeRawPtr *make( PTR ptr );
611 static const TypeRawPtr *make( address bits );
613 // Return a 'ptr' version of this type
614 virtual const Type *cast_to_ptr_type(PTR ptr) const;
616 virtual intptr_t get_con() const;
618 virtual const TypePtr *add_offset( int offset ) const;
620 virtual const Type *xmeet( const Type *t ) const;
621 virtual const Type *xdual() const; // Compute dual right now.
622 // Convenience common pre-built types.
623 static const TypeRawPtr *BOTTOM;
624 static const TypeRawPtr *NOTNULL;
625 #ifndef PRODUCT
626 virtual void dump2( Dict &d, uint depth, outputStream *st ) const;
627 #endif
628 };
630 //------------------------------TypeOopPtr-------------------------------------
631 // Some kind of oop (Java pointer), either klass or instance or array.
632 class TypeOopPtr : public TypePtr {
633 protected:
634 TypeOopPtr( TYPES t, PTR ptr, ciKlass* k, bool xk, ciObject* o, int offset, int instance_id ) : TypePtr(t, ptr, offset), _const_oop(o), _klass(k), _klass_is_exact(xk), _instance_id(instance_id) { }
635 public:
636 virtual bool eq( const Type *t ) const;
637 virtual int hash() const; // Type specific hashing
638 virtual bool singleton(void) const; // TRUE if type is a singleton
639 enum {
640 UNKNOWN_INSTANCE = 0
641 };
642 protected:
644 int xadd_offset( int offset ) const;
645 // Oop is NULL, unless this is a constant oop.
646 ciObject* _const_oop; // Constant oop
647 // If _klass is NULL, then so is _sig. This is an unloaded klass.
648 ciKlass* _klass; // Klass object
649 // Does the type exclude subclasses of the klass? (Inexact == polymorphic.)
650 bool _klass_is_exact;
652 int _instance_id; // if not UNKNOWN_INSTANCE, indicates that this is a particular instance
653 // of this type which is distinct. This is the the node index of the
654 // node creating this instance
656 static const TypeOopPtr* make_from_klass_common(ciKlass* klass, bool klass_change, bool try_for_exact);
658 int dual_instance() const { return -_instance_id; }
659 int meet_instance(int uid) const;
661 public:
662 // Creates a type given a klass. Correctly handles multi-dimensional arrays
663 // Respects UseUniqueSubclasses.
664 // If the klass is final, the resulting type will be exact.
665 static const TypeOopPtr* make_from_klass(ciKlass* klass) {
666 return make_from_klass_common(klass, true, false);
667 }
668 // Same as before, but will produce an exact type, even if
669 // the klass is not final, as long as it has exactly one implementation.
670 static const TypeOopPtr* make_from_klass_unique(ciKlass* klass) {
671 return make_from_klass_common(klass, true, true);
672 }
673 // Same as before, but does not respects UseUniqueSubclasses.
674 // Use this only for creating array element types.
675 static const TypeOopPtr* make_from_klass_raw(ciKlass* klass) {
676 return make_from_klass_common(klass, false, false);
677 }
678 // Creates a singleton type given an object.
679 static const TypeOopPtr* make_from_constant(ciObject* o);
681 // Make a generic (unclassed) pointer to an oop.
682 static const TypeOopPtr* make(PTR ptr, int offset);
684 ciObject* const_oop() const { return _const_oop; }
685 virtual ciKlass* klass() const { return _klass; }
686 bool klass_is_exact() const { return _klass_is_exact; }
687 bool is_instance() const { return _instance_id != UNKNOWN_INSTANCE; }
688 uint instance_id() const { return _instance_id; }
689 bool is_instance_field() const { return _instance_id != UNKNOWN_INSTANCE && _offset >= 0; }
691 virtual intptr_t get_con() const;
693 virtual const Type *cast_to_ptr_type(PTR ptr) const;
695 virtual const Type *cast_to_exactness(bool klass_is_exact) const;
697 virtual const TypeOopPtr *cast_to_instance(int instance_id) const;
699 // corresponding pointer to klass, for a given instance
700 const TypeKlassPtr* as_klass_type() const;
702 virtual const TypePtr *add_offset( int offset ) const;
704 virtual const Type *xmeet( const Type *t ) const;
705 virtual const Type *xdual() const; // Compute dual right now.
707 // Do not allow interface-vs.-noninterface joins to collapse to top.
708 virtual const Type *filter( const Type *kills ) const;
710 // Convenience common pre-built type.
711 static const TypeOopPtr *BOTTOM;
712 #ifndef PRODUCT
713 virtual void dump2( Dict &d, uint depth, outputStream *st ) const;
714 #endif
715 };
717 //------------------------------TypeInstPtr------------------------------------
718 // Class of Java object pointers, pointing either to non-array Java instances
719 // or to a klassOop (including array klasses).
720 class TypeInstPtr : public TypeOopPtr {
721 TypeInstPtr( PTR ptr, ciKlass* k, bool xk, ciObject* o, int offset, int instance_id );
722 virtual bool eq( const Type *t ) const;
723 virtual int hash() const; // Type specific hashing
725 ciSymbol* _name; // class name
727 public:
728 ciSymbol* name() const { return _name; }
730 bool is_loaded() const { return _klass->is_loaded(); }
732 // Make a pointer to a constant oop.
733 static const TypeInstPtr *make(ciObject* o) {
734 return make(TypePtr::Constant, o->klass(), true, o, 0);
735 }
737 // Make a pointer to a constant oop with offset.
738 static const TypeInstPtr *make(ciObject* o, int offset) {
739 return make(TypePtr::Constant, o->klass(), true, o, offset);
740 }
742 // Make a pointer to some value of type klass.
743 static const TypeInstPtr *make(PTR ptr, ciKlass* klass) {
744 return make(ptr, klass, false, NULL, 0);
745 }
747 // Make a pointer to some non-polymorphic value of exactly type klass.
748 static const TypeInstPtr *make_exact(PTR ptr, ciKlass* klass) {
749 return make(ptr, klass, true, NULL, 0);
750 }
752 // Make a pointer to some value of type klass with offset.
753 static const TypeInstPtr *make(PTR ptr, ciKlass* klass, int offset) {
754 return make(ptr, klass, false, NULL, offset);
755 }
757 // Make a pointer to an oop.
758 static const TypeInstPtr *make(PTR ptr, ciKlass* k, bool xk, ciObject* o, int offset, int instance_id = 0 );
760 // If this is a java.lang.Class constant, return the type for it or NULL.
761 // Pass to Type::get_const_type to turn it to a type, which will usually
762 // be a TypeInstPtr, but may also be a TypeInt::INT for int.class, etc.
763 ciType* java_mirror_type() const;
765 virtual const Type *cast_to_ptr_type(PTR ptr) const;
767 virtual const Type *cast_to_exactness(bool klass_is_exact) const;
769 virtual const TypeOopPtr *cast_to_instance(int instance_id) const;
771 virtual const TypePtr *add_offset( int offset ) const;
773 virtual const Type *xmeet( const Type *t ) const;
774 virtual const TypeInstPtr *xmeet_unloaded( const TypeInstPtr *t ) const;
775 virtual const Type *xdual() const; // Compute dual right now.
777 // Convenience common pre-built types.
778 static const TypeInstPtr *NOTNULL;
779 static const TypeInstPtr *BOTTOM;
780 static const TypeInstPtr *MIRROR;
781 static const TypeInstPtr *MARK;
782 static const TypeInstPtr *KLASS;
783 #ifndef PRODUCT
784 virtual void dump2( Dict &d, uint depth, outputStream *st ) const; // Specialized per-Type dumping
785 #endif
786 };
788 //------------------------------TypeAryPtr-------------------------------------
789 // Class of Java array pointers
790 class TypeAryPtr : public TypeOopPtr {
791 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) {};
792 virtual bool eq( const Type *t ) const;
793 virtual int hash() const; // Type specific hashing
794 const TypeAry *_ary; // Array we point into
796 public:
797 // Accessors
798 ciKlass* klass() const;
799 const TypeAry* ary() const { return _ary; }
800 const Type* elem() const { return _ary->_elem; }
801 const TypeInt* size() const { return _ary->_size; }
803 static const TypeAryPtr *make( PTR ptr, const TypeAry *ary, ciKlass* k, bool xk, int offset, int instance_id = 0);
804 // Constant pointer to array
805 static const TypeAryPtr *make( PTR ptr, ciObject* o, const TypeAry *ary, ciKlass* k, bool xk, int offset, int instance_id = 0);
807 // Convenience
808 static const TypeAryPtr *make(ciObject* o);
810 // Return a 'ptr' version of this type
811 virtual const Type *cast_to_ptr_type(PTR ptr) const;
813 virtual const Type *cast_to_exactness(bool klass_is_exact) const;
815 virtual const TypeOopPtr *cast_to_instance(int instance_id) const;
817 virtual const TypeAryPtr* cast_to_size(const TypeInt* size) const;
819 virtual bool empty(void) const; // TRUE if type is vacuous
820 virtual const TypePtr *add_offset( int offset ) const;
822 virtual const Type *xmeet( const Type *t ) const;
823 virtual const Type *xdual() const; // Compute dual right now.
825 // Convenience common pre-built types.
826 static const TypeAryPtr *RANGE;
827 static const TypeAryPtr *OOPS;
828 static const TypeAryPtr *BYTES;
829 static const TypeAryPtr *SHORTS;
830 static const TypeAryPtr *CHARS;
831 static const TypeAryPtr *INTS;
832 static const TypeAryPtr *LONGS;
833 static const TypeAryPtr *FLOATS;
834 static const TypeAryPtr *DOUBLES;
835 // selects one of the above:
836 static const TypeAryPtr *get_array_body_type(BasicType elem) {
837 assert((uint)elem <= T_CONFLICT && _array_body_type[elem] != NULL, "bad elem type");
838 return _array_body_type[elem];
839 }
840 static const TypeAryPtr *_array_body_type[T_CONFLICT+1];
841 // sharpen the type of an int which is used as an array size
842 static const TypeInt* narrow_size_type(const TypeInt* size, BasicType elem);
843 #ifndef PRODUCT
844 virtual void dump2( Dict &d, uint depth, outputStream *st ) const; // Specialized per-Type dumping
845 #endif
846 };
848 //------------------------------TypeKlassPtr-----------------------------------
849 // Class of Java Klass pointers
850 class TypeKlassPtr : public TypeOopPtr {
851 TypeKlassPtr( PTR ptr, ciKlass* klass, int offset );
853 virtual bool eq( const Type *t ) const;
854 virtual int hash() const; // Type specific hashing
856 public:
857 ciSymbol* name() const { return _klass->name(); }
859 // ptr to klass 'k'
860 static const TypeKlassPtr *make( ciKlass* k ) { return make( TypePtr::Constant, k, 0); }
861 // ptr to klass 'k' with offset
862 static const TypeKlassPtr *make( ciKlass* k, int offset ) { return make( TypePtr::Constant, k, offset); }
863 // ptr to klass 'k' or sub-klass
864 static const TypeKlassPtr *make( PTR ptr, ciKlass* k, int offset);
866 virtual const Type *cast_to_ptr_type(PTR ptr) const;
868 virtual const Type *cast_to_exactness(bool klass_is_exact) const;
870 // corresponding pointer to instance, for a given class
871 const TypeOopPtr* as_instance_type() const;
873 virtual const TypePtr *add_offset( int offset ) const;
874 virtual const Type *xmeet( const Type *t ) const;
875 virtual const Type *xdual() const; // Compute dual right now.
877 // Convenience common pre-built types.
878 static const TypeKlassPtr* OBJECT; // Not-null object klass or below
879 static const TypeKlassPtr* OBJECT_OR_NULL; // Maybe-null version of same
880 #ifndef PRODUCT
881 virtual void dump2( Dict &d, uint depth, outputStream *st ) const; // Specialized per-Type dumping
882 #endif
883 };
885 //------------------------------TypeFunc---------------------------------------
886 // Class of Array Types
887 class TypeFunc : public Type {
888 TypeFunc( const TypeTuple *domain, const TypeTuple *range ) : Type(Function), _domain(domain), _range(range) {}
889 virtual bool eq( const Type *t ) const;
890 virtual int hash() const; // Type specific hashing
891 virtual bool singleton(void) const; // TRUE if type is a singleton
892 virtual bool empty(void) const; // TRUE if type is vacuous
893 public:
894 // Constants are shared among ADLC and VM
895 enum { Control = AdlcVMDeps::Control,
896 I_O = AdlcVMDeps::I_O,
897 Memory = AdlcVMDeps::Memory,
898 FramePtr = AdlcVMDeps::FramePtr,
899 ReturnAdr = AdlcVMDeps::ReturnAdr,
900 Parms = AdlcVMDeps::Parms
901 };
903 const TypeTuple* const _domain; // Domain of inputs
904 const TypeTuple* const _range; // Range of results
906 // Accessors:
907 const TypeTuple* domain() const { return _domain; }
908 const TypeTuple* range() const { return _range; }
910 static const TypeFunc *make(ciMethod* method);
911 static const TypeFunc *make(ciSignature signature, const Type* extra);
912 static const TypeFunc *make(const TypeTuple* domain, const TypeTuple* range);
914 virtual const Type *xmeet( const Type *t ) const;
915 virtual const Type *xdual() const; // Compute dual right now.
917 BasicType return_type() const;
919 #ifndef PRODUCT
920 virtual void dump2( Dict &d, uint depth, outputStream *st ) const; // Specialized per-Type dumping
921 void print_flattened() const; // Print a 'flattened' signature
922 #endif
923 // Convenience common pre-built types.
924 };
926 //------------------------------accessors--------------------------------------
927 inline float Type::getf() const {
928 assert( _base == FloatCon, "Not a FloatCon" );
929 return ((TypeF*)this)->_f;
930 }
932 inline double Type::getd() const {
933 assert( _base == DoubleCon, "Not a DoubleCon" );
934 return ((TypeD*)this)->_d;
935 }
937 inline const TypeF *Type::is_float_constant() const {
938 assert( _base == FloatCon, "Not a Float" );
939 return (TypeF*)this;
940 }
942 inline const TypeF *Type::isa_float_constant() const {
943 return ( _base == FloatCon ? (TypeF*)this : NULL);
944 }
946 inline const TypeD *Type::is_double_constant() const {
947 assert( _base == DoubleCon, "Not a Double" );
948 return (TypeD*)this;
949 }
951 inline const TypeD *Type::isa_double_constant() const {
952 return ( _base == DoubleCon ? (TypeD*)this : NULL);
953 }
955 inline const TypeInt *Type::is_int() const {
956 assert( _base == Int, "Not an Int" );
957 return (TypeInt*)this;
958 }
960 inline const TypeInt *Type::isa_int() const {
961 return ( _base == Int ? (TypeInt*)this : NULL);
962 }
964 inline const TypeLong *Type::is_long() const {
965 assert( _base == Long, "Not a Long" );
966 return (TypeLong*)this;
967 }
969 inline const TypeLong *Type::isa_long() const {
970 return ( _base == Long ? (TypeLong*)this : NULL);
971 }
973 inline const TypeTuple *Type::is_tuple() const {
974 assert( _base == Tuple, "Not a Tuple" );
975 return (TypeTuple*)this;
976 }
978 inline const TypeAry *Type::is_ary() const {
979 assert( _base == Array , "Not an Array" );
980 return (TypeAry*)this;
981 }
983 inline const TypePtr *Type::is_ptr() const {
984 // AnyPtr is the first Ptr and KlassPtr the last, with no non-ptrs between.
985 assert(_base >= AnyPtr && _base <= KlassPtr, "Not a pointer");
986 return (TypePtr*)this;
987 }
989 inline const TypePtr *Type::isa_ptr() const {
990 // AnyPtr is the first Ptr and KlassPtr the last, with no non-ptrs between.
991 return (_base >= AnyPtr && _base <= KlassPtr) ? (TypePtr*)this : NULL;
992 }
994 inline const TypeOopPtr *Type::is_oopptr() const {
995 // OopPtr is the first and KlassPtr the last, with no non-oops between.
996 assert(_base >= OopPtr && _base <= KlassPtr, "Not a Java pointer" ) ;
997 return (TypeOopPtr*)this;
998 }
1000 inline const TypeOopPtr *Type::isa_oopptr() const {
1001 // OopPtr is the first and KlassPtr the last, with no non-oops between.
1002 return (_base >= OopPtr && _base <= KlassPtr) ? (TypeOopPtr*)this : NULL;
1003 }
1005 inline const TypeRawPtr *Type::is_rawptr() const {
1006 assert( _base == RawPtr, "Not a raw pointer" );
1007 return (TypeRawPtr*)this;
1008 }
1010 inline const TypeInstPtr *Type::isa_instptr() const {
1011 return (_base == InstPtr) ? (TypeInstPtr*)this : NULL;
1012 }
1014 inline const TypeInstPtr *Type::is_instptr() const {
1015 assert( _base == InstPtr, "Not an object pointer" );
1016 return (TypeInstPtr*)this;
1017 }
1019 inline const TypeAryPtr *Type::isa_aryptr() const {
1020 return (_base == AryPtr) ? (TypeAryPtr*)this : NULL;
1021 }
1023 inline const TypeAryPtr *Type::is_aryptr() const {
1024 assert( _base == AryPtr, "Not an array pointer" );
1025 return (TypeAryPtr*)this;
1026 }
1028 inline const TypeKlassPtr *Type::isa_klassptr() const {
1029 return (_base == KlassPtr) ? (TypeKlassPtr*)this : NULL;
1030 }
1032 inline const TypeKlassPtr *Type::is_klassptr() const {
1033 assert( _base == KlassPtr, "Not a klass pointer" );
1034 return (TypeKlassPtr*)this;
1035 }
1037 inline bool Type::is_floatingpoint() const {
1038 if( (_base == FloatCon) || (_base == FloatBot) ||
1039 (_base == DoubleCon) || (_base == DoubleBot) )
1040 return true;
1041 return false;
1042 }
1045 // ===============================================================
1046 // Things that need to be 64-bits in the 64-bit build but
1047 // 32-bits in the 32-bit build. Done this way to get full
1048 // optimization AND strong typing.
1049 #ifdef _LP64
1051 // For type queries and asserts
1052 #define is_intptr_t is_long
1053 #define isa_intptr_t isa_long
1054 #define find_intptr_t_type find_long_type
1055 #define find_intptr_t_con find_long_con
1056 #define TypeX TypeLong
1057 #define Type_X Type::Long
1058 #define TypeX_X TypeLong::LONG
1059 #define TypeX_ZERO TypeLong::ZERO
1060 // For 'ideal_reg' machine registers
1061 #define Op_RegX Op_RegL
1062 // For phase->intcon variants
1063 #define MakeConX longcon
1064 #define ConXNode ConLNode
1065 // For array index arithmetic
1066 #define MulXNode MulLNode
1067 #define AndXNode AndLNode
1068 #define OrXNode OrLNode
1069 #define CmpXNode CmpLNode
1070 #define SubXNode SubLNode
1071 #define LShiftXNode LShiftLNode
1072 // For object size computation:
1073 #define AddXNode AddLNode
1074 #define RShiftXNode RShiftLNode
1075 // For card marks and hashcodes
1076 #define URShiftXNode URShiftLNode
1077 // Opcodes
1078 #define Op_LShiftX Op_LShiftL
1079 #define Op_AndX Op_AndL
1080 #define Op_AddX Op_AddL
1081 #define Op_SubX Op_SubL
1082 // conversions
1083 #define ConvI2X(x) ConvI2L(x)
1084 #define ConvL2X(x) (x)
1085 #define ConvX2I(x) ConvL2I(x)
1086 #define ConvX2L(x) (x)
1088 #else
1090 // For type queries and asserts
1091 #define is_intptr_t is_int
1092 #define isa_intptr_t isa_int
1093 #define find_intptr_t_type find_int_type
1094 #define find_intptr_t_con find_int_con
1095 #define TypeX TypeInt
1096 #define Type_X Type::Int
1097 #define TypeX_X TypeInt::INT
1098 #define TypeX_ZERO TypeInt::ZERO
1099 // For 'ideal_reg' machine registers
1100 #define Op_RegX Op_RegI
1101 // For phase->intcon variants
1102 #define MakeConX intcon
1103 #define ConXNode ConINode
1104 // For array index arithmetic
1105 #define MulXNode MulINode
1106 #define AndXNode AndINode
1107 #define OrXNode OrINode
1108 #define CmpXNode CmpINode
1109 #define SubXNode SubINode
1110 #define LShiftXNode LShiftINode
1111 // For object size computation:
1112 #define AddXNode AddINode
1113 #define RShiftXNode RShiftINode
1114 // For card marks and hashcodes
1115 #define URShiftXNode URShiftINode
1116 // Opcodes
1117 #define Op_LShiftX Op_LShiftI
1118 #define Op_AndX Op_AndI
1119 #define Op_AddX Op_AddI
1120 #define Op_SubX Op_SubI
1121 // conversions
1122 #define ConvI2X(x) (x)
1123 #define ConvL2X(x) ConvL2I(x)
1124 #define ConvX2I(x) (x)
1125 #define ConvX2L(x) ConvI2L(x)
1127 #endif