Fri, 18 Oct 2013 10:50:17 +0200
8022783: Nashorn test fails with: assert(!def_outside->member(r))
Summary: Enables private copies of inputs for recent spill copies as well
Reviewed-by: kvn, twisti
1 /*
2 * Copyright (c) 1997, 2013, Oracle and/or its affiliates. All rights reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * This code is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation.
8 *
9 * This code is distributed in the hope that it will be useful, but WITHOUT
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
12 * version 2 for more details (a copy is included in the LICENSE file that
13 * accompanied this code).
14 *
15 * You should have received a copy of the GNU General Public License version
16 * 2 along with this work; if not, write to the Free Software Foundation,
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18 *
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20 * or visit www.oracle.com if you need additional information or have any
21 * questions.
22 *
23 */
25 #ifndef SHARE_VM_OPTO_TYPE_HPP
26 #define SHARE_VM_OPTO_TYPE_HPP
28 #include "libadt/port.hpp"
29 #include "opto/adlcVMDeps.hpp"
30 #include "runtime/handles.hpp"
32 // Portions of code courtesy of Clifford Click
34 // Optimization - Graph Style
37 // This class defines a Type lattice. The lattice is used in the constant
38 // propagation algorithms, and for some type-checking of the iloc code.
39 // Basic types include RSD's (lower bound, upper bound, stride for integers),
40 // float & double precision constants, sets of data-labels and code-labels.
41 // The complete lattice is described below. Subtypes have no relationship to
42 // up or down in the lattice; that is entirely determined by the behavior of
43 // the MEET/JOIN functions.
45 class Dict;
46 class Type;
47 class TypeD;
48 class TypeF;
49 class TypeInt;
50 class TypeLong;
51 class TypeNarrowPtr;
52 class TypeNarrowOop;
53 class TypeNarrowKlass;
54 class TypeAry;
55 class TypeTuple;
56 class TypeVect;
57 class TypeVectS;
58 class TypeVectD;
59 class TypeVectX;
60 class TypeVectY;
61 class TypePtr;
62 class TypeRawPtr;
63 class TypeOopPtr;
64 class TypeInstPtr;
65 class TypeAryPtr;
66 class TypeKlassPtr;
67 class TypeMetadataPtr;
69 //------------------------------Type-------------------------------------------
70 // Basic Type object, represents a set of primitive Values.
71 // Types are hash-cons'd into a private class dictionary, so only one of each
72 // different kind of Type exists. Types are never modified after creation, so
73 // all their interesting fields are constant.
74 class Type {
75 friend class VMStructs;
77 public:
78 enum TYPES {
79 Bad=0, // Type check
80 Control, // Control of code (not in lattice)
81 Top, // Top of the lattice
82 Int, // Integer range (lo-hi)
83 Long, // Long integer range (lo-hi)
84 Half, // Placeholder half of doubleword
85 NarrowOop, // Compressed oop pointer
86 NarrowKlass, // Compressed klass pointer
88 Tuple, // Method signature or object layout
89 Array, // Array types
90 VectorS, // 32bit Vector types
91 VectorD, // 64bit Vector types
92 VectorX, // 128bit Vector types
93 VectorY, // 256bit Vector types
95 AnyPtr, // Any old raw, klass, inst, or array pointer
96 RawPtr, // Raw (non-oop) pointers
97 OopPtr, // Any and all Java heap entities
98 InstPtr, // Instance pointers (non-array objects)
99 AryPtr, // Array pointers
100 // (Ptr order matters: See is_ptr, isa_ptr, is_oopptr, isa_oopptr.)
102 MetadataPtr, // Generic metadata
103 KlassPtr, // Klass pointers
105 Function, // Function signature
106 Abio, // Abstract I/O
107 Return_Address, // Subroutine return address
108 Memory, // Abstract store
109 FloatTop, // No float value
110 FloatCon, // Floating point constant
111 FloatBot, // Any float value
112 DoubleTop, // No double value
113 DoubleCon, // Double precision constant
114 DoubleBot, // Any double value
115 Bottom, // Bottom of lattice
116 lastype // Bogus ending type (not in lattice)
117 };
119 // Signal values for offsets from a base pointer
120 enum OFFSET_SIGNALS {
121 OffsetTop = -2000000000, // undefined offset
122 OffsetBot = -2000000001 // any possible offset
123 };
125 // Min and max WIDEN values.
126 enum WIDEN {
127 WidenMin = 0,
128 WidenMax = 3
129 };
131 private:
132 typedef struct {
133 const TYPES dual_type;
134 const BasicType basic_type;
135 const char* msg;
136 const bool isa_oop;
137 const int ideal_reg;
138 const relocInfo::relocType reloc;
139 } TypeInfo;
141 // Dictionary of types shared among compilations.
142 static Dict* _shared_type_dict;
143 static TypeInfo _type_info[];
145 static int uhash( const Type *const t );
146 // Structural equality check. Assumes that cmp() has already compared
147 // the _base types and thus knows it can cast 't' appropriately.
148 virtual bool eq( const Type *t ) const;
150 // Top-level hash-table of types
151 static Dict *type_dict() {
152 return Compile::current()->type_dict();
153 }
155 // DUAL operation: reflect around lattice centerline. Used instead of
156 // join to ensure my lattice is symmetric up and down. Dual is computed
157 // lazily, on demand, and cached in _dual.
158 const Type *_dual; // Cached dual value
159 // Table for efficient dualing of base types
160 static const TYPES dual_type[lastype];
162 protected:
163 // Each class of type is also identified by its base.
164 const TYPES _base; // Enum of Types type
166 Type( TYPES t ) : _dual(NULL), _base(t) {} // Simple types
167 // ~Type(); // Use fast deallocation
168 const Type *hashcons(); // Hash-cons the type
170 public:
172 inline void* operator new( size_t x ) throw() {
173 Compile* compile = Compile::current();
174 compile->set_type_last_size(x);
175 void *temp = compile->type_arena()->Amalloc_D(x);
176 compile->set_type_hwm(temp);
177 return temp;
178 }
179 inline void operator delete( void* ptr ) {
180 Compile* compile = Compile::current();
181 compile->type_arena()->Afree(ptr,compile->type_last_size());
182 }
184 // Initialize the type system for a particular compilation.
185 static void Initialize(Compile* compile);
187 // Initialize the types shared by all compilations.
188 static void Initialize_shared(Compile* compile);
190 TYPES base() const {
191 assert(_base > Bad && _base < lastype, "sanity");
192 return _base;
193 }
195 // Create a new hash-consd type
196 static const Type *make(enum TYPES);
197 // Test for equivalence of types
198 static int cmp( const Type *const t1, const Type *const t2 );
199 // Test for higher or equal in lattice
200 int higher_equal( const Type *t ) const { return !cmp(meet(t),t); }
202 // MEET operation; lower in lattice.
203 const Type *meet( const Type *t ) const;
204 // WIDEN: 'widens' for Ints and other range types
205 virtual const Type *widen( const Type *old, const Type* limit ) const { return this; }
206 // NARROW: complement for widen, used by pessimistic phases
207 virtual const Type *narrow( const Type *old ) const { return this; }
209 // DUAL operation: reflect around lattice centerline. Used instead of
210 // join to ensure my lattice is symmetric up and down.
211 const Type *dual() const { return _dual; }
213 // Compute meet dependent on base type
214 virtual const Type *xmeet( const Type *t ) const;
215 virtual const Type *xdual() const; // Compute dual right now.
217 // JOIN operation; higher in lattice. Done by finding the dual of the
218 // meet of the dual of the 2 inputs.
219 const Type *join( const Type *t ) const {
220 return dual()->meet(t->dual())->dual(); }
222 // Modified version of JOIN adapted to the needs Node::Value.
223 // Normalizes all empty values to TOP. Does not kill _widen bits.
224 // Currently, it also works around limitations involving interface types.
225 virtual const Type *filter( const Type *kills ) const;
227 #ifdef ASSERT
228 // One type is interface, the other is oop
229 virtual bool interface_vs_oop(const Type *t) const;
230 #endif
232 // Returns true if this pointer points at memory which contains a
233 // compressed oop references.
234 bool is_ptr_to_narrowoop() const;
235 bool is_ptr_to_narrowklass() const;
237 bool is_ptr_to_boxing_obj() const;
240 // Convenience access
241 float getf() const;
242 double getd() const;
244 const TypeInt *is_int() const;
245 const TypeInt *isa_int() const; // Returns NULL if not an Int
246 const TypeLong *is_long() const;
247 const TypeLong *isa_long() const; // Returns NULL if not a Long
248 const TypeD *isa_double() const; // Returns NULL if not a Double{Top,Con,Bot}
249 const TypeD *is_double_constant() const; // Asserts it is a DoubleCon
250 const TypeD *isa_double_constant() const; // Returns NULL if not a DoubleCon
251 const TypeF *isa_float() const; // Returns NULL if not a Float{Top,Con,Bot}
252 const TypeF *is_float_constant() const; // Asserts it is a FloatCon
253 const TypeF *isa_float_constant() const; // Returns NULL if not a FloatCon
254 const TypeTuple *is_tuple() const; // Collection of fields, NOT a pointer
255 const TypeAry *is_ary() const; // Array, NOT array pointer
256 const TypeVect *is_vect() const; // Vector
257 const TypeVect *isa_vect() const; // Returns NULL if not a Vector
258 const TypePtr *is_ptr() const; // Asserts it is a ptr type
259 const TypePtr *isa_ptr() const; // Returns NULL if not ptr type
260 const TypeRawPtr *isa_rawptr() const; // NOT Java oop
261 const TypeRawPtr *is_rawptr() const; // Asserts is rawptr
262 const TypeNarrowOop *is_narrowoop() const; // Java-style GC'd pointer
263 const TypeNarrowOop *isa_narrowoop() const; // Returns NULL if not oop ptr type
264 const TypeNarrowKlass *is_narrowklass() const; // compressed klass pointer
265 const TypeNarrowKlass *isa_narrowklass() const;// Returns NULL if not oop ptr type
266 const TypeOopPtr *isa_oopptr() const; // Returns NULL if not oop ptr type
267 const TypeOopPtr *is_oopptr() const; // Java-style GC'd pointer
268 const TypeInstPtr *isa_instptr() const; // Returns NULL if not InstPtr
269 const TypeInstPtr *is_instptr() const; // Instance
270 const TypeAryPtr *isa_aryptr() const; // Returns NULL if not AryPtr
271 const TypeAryPtr *is_aryptr() const; // Array oop
273 const TypeMetadataPtr *isa_metadataptr() const; // Returns NULL if not oop ptr type
274 const TypeMetadataPtr *is_metadataptr() const; // Java-style GC'd pointer
275 const TypeKlassPtr *isa_klassptr() const; // Returns NULL if not KlassPtr
276 const TypeKlassPtr *is_klassptr() const; // assert if not KlassPtr
278 virtual bool is_finite() const; // Has a finite value
279 virtual bool is_nan() const; // Is not a number (NaN)
281 // Returns this ptr type or the equivalent ptr type for this compressed pointer.
282 const TypePtr* make_ptr() const;
284 // Returns this oopptr type or the equivalent oopptr type for this compressed pointer.
285 // Asserts if the underlying type is not an oopptr or narrowoop.
286 const TypeOopPtr* make_oopptr() const;
288 // Returns this compressed pointer or the equivalent compressed version
289 // of this pointer type.
290 const TypeNarrowOop* make_narrowoop() const;
292 // Returns this compressed klass pointer or the equivalent
293 // compressed version of this pointer type.
294 const TypeNarrowKlass* make_narrowklass() const;
296 // Special test for register pressure heuristic
297 bool is_floatingpoint() const; // True if Float or Double base type
299 // Do you have memory, directly or through a tuple?
300 bool has_memory( ) const;
302 // TRUE if type is a singleton
303 virtual bool singleton(void) const;
305 // TRUE if type is above the lattice centerline, and is therefore vacuous
306 virtual bool empty(void) const;
308 // Return a hash for this type. The hash function is public so ConNode
309 // (constants) can hash on their constant, which is represented by a Type.
310 virtual int hash() const;
312 // Map ideal registers (machine types) to ideal types
313 static const Type *mreg2type[];
315 // Printing, statistics
316 #ifndef PRODUCT
317 void dump_on(outputStream *st) const;
318 void dump() const {
319 dump_on(tty);
320 }
321 virtual void dump2( Dict &d, uint depth, outputStream *st ) const;
322 static void dump_stats();
323 #endif
324 void typerr(const Type *t) const; // Mixing types error
326 // Create basic type
327 static const Type* get_const_basic_type(BasicType type) {
328 assert((uint)type <= T_CONFLICT && _const_basic_type[type] != NULL, "bad type");
329 return _const_basic_type[type];
330 }
332 // Mapping to the array element's basic type.
333 BasicType array_element_basic_type() const;
335 // Create standard type for a ciType:
336 static const Type* get_const_type(ciType* type);
338 // Create standard zero value:
339 static const Type* get_zero_type(BasicType type) {
340 assert((uint)type <= T_CONFLICT && _zero_type[type] != NULL, "bad type");
341 return _zero_type[type];
342 }
344 // Report if this is a zero value (not top).
345 bool is_zero_type() const {
346 BasicType type = basic_type();
347 if (type == T_VOID || type >= T_CONFLICT)
348 return false;
349 else
350 return (this == _zero_type[type]);
351 }
353 // Convenience common pre-built types.
354 static const Type *ABIO;
355 static const Type *BOTTOM;
356 static const Type *CONTROL;
357 static const Type *DOUBLE;
358 static const Type *FLOAT;
359 static const Type *HALF;
360 static const Type *MEMORY;
361 static const Type *MULTI;
362 static const Type *RETURN_ADDRESS;
363 static const Type *TOP;
365 // Mapping from compiler type to VM BasicType
366 BasicType basic_type() const { return _type_info[_base].basic_type; }
367 int ideal_reg() const { return _type_info[_base].ideal_reg; }
368 const char* msg() const { return _type_info[_base].msg; }
369 bool isa_oop_ptr() const { return _type_info[_base].isa_oop; }
370 relocInfo::relocType reloc() const { return _type_info[_base].reloc; }
372 // Mapping from CI type system to compiler type:
373 static const Type* get_typeflow_type(ciType* type);
375 static const Type* make_from_constant(ciConstant constant,
376 bool require_constant = false,
377 bool is_autobox_cache = false);
379 private:
380 // support arrays
381 static const BasicType _basic_type[];
382 static const Type* _zero_type[T_CONFLICT+1];
383 static const Type* _const_basic_type[T_CONFLICT+1];
384 };
386 //------------------------------TypeF------------------------------------------
387 // Class of Float-Constant Types.
388 class TypeF : public Type {
389 TypeF( float f ) : Type(FloatCon), _f(f) {};
390 public:
391 virtual bool eq( const Type *t ) const;
392 virtual int hash() const; // Type specific hashing
393 virtual bool singleton(void) const; // TRUE if type is a singleton
394 virtual bool empty(void) const; // TRUE if type is vacuous
395 public:
396 const float _f; // Float constant
398 static const TypeF *make(float f);
400 virtual bool is_finite() const; // Has a finite value
401 virtual bool is_nan() const; // Is not a number (NaN)
403 virtual const Type *xmeet( const Type *t ) const;
404 virtual const Type *xdual() const; // Compute dual right now.
405 // Convenience common pre-built types.
406 static const TypeF *ZERO; // positive zero only
407 static const TypeF *ONE;
408 #ifndef PRODUCT
409 virtual void dump2( Dict &d, uint depth, outputStream *st ) const;
410 #endif
411 };
413 //------------------------------TypeD------------------------------------------
414 // Class of Double-Constant Types.
415 class TypeD : public Type {
416 TypeD( double d ) : Type(DoubleCon), _d(d) {};
417 public:
418 virtual bool eq( const Type *t ) const;
419 virtual int hash() const; // Type specific hashing
420 virtual bool singleton(void) const; // TRUE if type is a singleton
421 virtual bool empty(void) const; // TRUE if type is vacuous
422 public:
423 const double _d; // Double constant
425 static const TypeD *make(double d);
427 virtual bool is_finite() const; // Has a finite value
428 virtual bool is_nan() const; // Is not a number (NaN)
430 virtual const Type *xmeet( const Type *t ) const;
431 virtual const Type *xdual() const; // Compute dual right now.
432 // Convenience common pre-built types.
433 static const TypeD *ZERO; // positive zero only
434 static const TypeD *ONE;
435 #ifndef PRODUCT
436 virtual void dump2( Dict &d, uint depth, outputStream *st ) const;
437 #endif
438 };
440 //------------------------------TypeInt----------------------------------------
441 // Class of integer ranges, the set of integers between a lower bound and an
442 // upper bound, inclusive.
443 class TypeInt : public Type {
444 TypeInt( jint lo, jint hi, int w );
445 public:
446 virtual bool eq( const Type *t ) const;
447 virtual int hash() const; // Type specific hashing
448 virtual bool singleton(void) const; // TRUE if type is a singleton
449 virtual bool empty(void) const; // TRUE if type is vacuous
450 public:
451 const jint _lo, _hi; // Lower bound, upper bound
452 const short _widen; // Limit on times we widen this sucker
454 static const TypeInt *make(jint lo);
455 // must always specify w
456 static const TypeInt *make(jint lo, jint hi, int w);
458 // Check for single integer
459 int is_con() const { return _lo==_hi; }
460 bool is_con(int i) const { return is_con() && _lo == i; }
461 jint get_con() const { assert( is_con(), "" ); return _lo; }
463 virtual bool is_finite() const; // Has a finite value
465 virtual const Type *xmeet( const Type *t ) const;
466 virtual const Type *xdual() const; // Compute dual right now.
467 virtual const Type *widen( const Type *t, const Type* limit_type ) const;
468 virtual const Type *narrow( const Type *t ) const;
469 // Do not kill _widen bits.
470 virtual const Type *filter( const Type *kills ) const;
471 // Convenience common pre-built types.
472 static const TypeInt *MINUS_1;
473 static const TypeInt *ZERO;
474 static const TypeInt *ONE;
475 static const TypeInt *BOOL;
476 static const TypeInt *CC;
477 static const TypeInt *CC_LT; // [-1] == MINUS_1
478 static const TypeInt *CC_GT; // [1] == ONE
479 static const TypeInt *CC_EQ; // [0] == ZERO
480 static const TypeInt *CC_LE; // [-1,0]
481 static const TypeInt *CC_GE; // [0,1] == BOOL (!)
482 static const TypeInt *BYTE;
483 static const TypeInt *UBYTE;
484 static const TypeInt *CHAR;
485 static const TypeInt *SHORT;
486 static const TypeInt *POS;
487 static const TypeInt *POS1;
488 static const TypeInt *INT;
489 static const TypeInt *SYMINT; // symmetric range [-max_jint..max_jint]
490 #ifndef PRODUCT
491 virtual void dump2( Dict &d, uint depth, outputStream *st ) const;
492 #endif
493 };
496 //------------------------------TypeLong---------------------------------------
497 // Class of long integer ranges, the set of integers between a lower bound and
498 // an upper bound, inclusive.
499 class TypeLong : public Type {
500 TypeLong( jlong lo, jlong hi, int w );
501 public:
502 virtual bool eq( const Type *t ) const;
503 virtual int hash() const; // Type specific hashing
504 virtual bool singleton(void) const; // TRUE if type is a singleton
505 virtual bool empty(void) const; // TRUE if type is vacuous
506 public:
507 const jlong _lo, _hi; // Lower bound, upper bound
508 const short _widen; // Limit on times we widen this sucker
510 static const TypeLong *make(jlong lo);
511 // must always specify w
512 static const TypeLong *make(jlong lo, jlong hi, int w);
514 // Check for single integer
515 int is_con() const { return _lo==_hi; }
516 bool is_con(int i) const { return is_con() && _lo == i; }
517 jlong get_con() const { assert( is_con(), "" ); return _lo; }
519 virtual bool is_finite() const; // Has a finite value
521 virtual const Type *xmeet( const Type *t ) const;
522 virtual const Type *xdual() const; // Compute dual right now.
523 virtual const Type *widen( const Type *t, const Type* limit_type ) const;
524 virtual const Type *narrow( const Type *t ) const;
525 // Do not kill _widen bits.
526 virtual const Type *filter( const Type *kills ) const;
527 // Convenience common pre-built types.
528 static const TypeLong *MINUS_1;
529 static const TypeLong *ZERO;
530 static const TypeLong *ONE;
531 static const TypeLong *POS;
532 static const TypeLong *LONG;
533 static const TypeLong *INT; // 32-bit subrange [min_jint..max_jint]
534 static const TypeLong *UINT; // 32-bit unsigned [0..max_juint]
535 #ifndef PRODUCT
536 virtual void dump2( Dict &d, uint, outputStream *st ) const;// Specialized per-Type dumping
537 #endif
538 };
540 //------------------------------TypeTuple--------------------------------------
541 // Class of Tuple Types, essentially type collections for function signatures
542 // and class layouts. It happens to also be a fast cache for the HotSpot
543 // signature types.
544 class TypeTuple : public Type {
545 TypeTuple( uint cnt, const Type **fields ) : Type(Tuple), _cnt(cnt), _fields(fields) { }
546 public:
547 virtual bool eq( const Type *t ) const;
548 virtual int hash() const; // Type specific hashing
549 virtual bool singleton(void) const; // TRUE if type is a singleton
550 virtual bool empty(void) const; // TRUE if type is vacuous
552 public:
553 const uint _cnt; // Count of fields
554 const Type ** const _fields; // Array of field types
556 // Accessors:
557 uint cnt() const { return _cnt; }
558 const Type* field_at(uint i) const {
559 assert(i < _cnt, "oob");
560 return _fields[i];
561 }
562 void set_field_at(uint i, const Type* t) {
563 assert(i < _cnt, "oob");
564 _fields[i] = t;
565 }
567 static const TypeTuple *make( uint cnt, const Type **fields );
568 static const TypeTuple *make_range(ciSignature *sig);
569 static const TypeTuple *make_domain(ciInstanceKlass* recv, ciSignature *sig);
571 // Subroutine call type with space allocated for argument types
572 static const Type **fields( uint arg_cnt );
574 virtual const Type *xmeet( const Type *t ) const;
575 virtual const Type *xdual() const; // Compute dual right now.
576 // Convenience common pre-built types.
577 static const TypeTuple *IFBOTH;
578 static const TypeTuple *IFFALSE;
579 static const TypeTuple *IFTRUE;
580 static const TypeTuple *IFNEITHER;
581 static const TypeTuple *LOOPBODY;
582 static const TypeTuple *MEMBAR;
583 static const TypeTuple *STORECONDITIONAL;
584 static const TypeTuple *START_I2C;
585 static const TypeTuple *INT_PAIR;
586 static const TypeTuple *LONG_PAIR;
587 static const TypeTuple *INT_CC_PAIR;
588 #ifndef PRODUCT
589 virtual void dump2( Dict &d, uint, outputStream *st ) const; // Specialized per-Type dumping
590 #endif
591 };
593 //------------------------------TypeAry----------------------------------------
594 // Class of Array Types
595 class TypeAry : public Type {
596 TypeAry(const Type* elem, const TypeInt* size, bool stable) : Type(Array),
597 _elem(elem), _size(size), _stable(stable) {}
598 public:
599 virtual bool eq( const Type *t ) const;
600 virtual int hash() const; // Type specific hashing
601 virtual bool singleton(void) const; // TRUE if type is a singleton
602 virtual bool empty(void) const; // TRUE if type is vacuous
604 private:
605 const Type *_elem; // Element type of array
606 const TypeInt *_size; // Elements in array
607 const bool _stable; // Are elements @Stable?
608 friend class TypeAryPtr;
610 public:
611 static const TypeAry* make(const Type* elem, const TypeInt* size, bool stable = false);
613 virtual const Type *xmeet( const Type *t ) const;
614 virtual const Type *xdual() const; // Compute dual right now.
615 bool ary_must_be_exact() const; // true if arrays of such are never generic
616 #ifdef ASSERT
617 // One type is interface, the other is oop
618 virtual bool interface_vs_oop(const Type *t) const;
619 #endif
620 #ifndef PRODUCT
621 virtual void dump2( Dict &d, uint, outputStream *st ) const; // Specialized per-Type dumping
622 #endif
623 };
625 //------------------------------TypeVect---------------------------------------
626 // Class of Vector Types
627 class TypeVect : public Type {
628 const Type* _elem; // Vector's element type
629 const uint _length; // Elements in vector (power of 2)
631 protected:
632 TypeVect(TYPES t, const Type* elem, uint length) : Type(t),
633 _elem(elem), _length(length) {}
635 public:
636 const Type* element_type() const { return _elem; }
637 BasicType element_basic_type() const { return _elem->array_element_basic_type(); }
638 uint length() const { return _length; }
639 uint length_in_bytes() const {
640 return _length * type2aelembytes(element_basic_type());
641 }
643 virtual bool eq(const Type *t) const;
644 virtual int hash() const; // Type specific hashing
645 virtual bool singleton(void) const; // TRUE if type is a singleton
646 virtual bool empty(void) const; // TRUE if type is vacuous
648 static const TypeVect *make(const BasicType elem_bt, uint length) {
649 // Use bottom primitive type.
650 return make(get_const_basic_type(elem_bt), length);
651 }
652 // Used directly by Replicate nodes to construct singleton vector.
653 static const TypeVect *make(const Type* elem, uint length);
655 virtual const Type *xmeet( const Type *t) const;
656 virtual const Type *xdual() const; // Compute dual right now.
658 static const TypeVect *VECTS;
659 static const TypeVect *VECTD;
660 static const TypeVect *VECTX;
661 static const TypeVect *VECTY;
663 #ifndef PRODUCT
664 virtual void dump2(Dict &d, uint, outputStream *st) const; // Specialized per-Type dumping
665 #endif
666 };
668 class TypeVectS : public TypeVect {
669 friend class TypeVect;
670 TypeVectS(const Type* elem, uint length) : TypeVect(VectorS, elem, length) {}
671 };
673 class TypeVectD : public TypeVect {
674 friend class TypeVect;
675 TypeVectD(const Type* elem, uint length) : TypeVect(VectorD, elem, length) {}
676 };
678 class TypeVectX : public TypeVect {
679 friend class TypeVect;
680 TypeVectX(const Type* elem, uint length) : TypeVect(VectorX, elem, length) {}
681 };
683 class TypeVectY : public TypeVect {
684 friend class TypeVect;
685 TypeVectY(const Type* elem, uint length) : TypeVect(VectorY, elem, length) {}
686 };
688 //------------------------------TypePtr----------------------------------------
689 // Class of machine Pointer Types: raw data, instances or arrays.
690 // If the _base enum is AnyPtr, then this refers to all of the above.
691 // Otherwise the _base will indicate which subset of pointers is affected,
692 // and the class will be inherited from.
693 class TypePtr : public Type {
694 friend class TypeNarrowPtr;
695 public:
696 enum PTR { TopPTR, AnyNull, Constant, Null, NotNull, BotPTR, lastPTR };
697 protected:
698 TypePtr( TYPES t, PTR ptr, int offset ) : Type(t), _ptr(ptr), _offset(offset) {}
699 virtual bool eq( const Type *t ) const;
700 virtual int hash() const; // Type specific hashing
701 static const PTR ptr_meet[lastPTR][lastPTR];
702 static const PTR ptr_dual[lastPTR];
703 static const char * const ptr_msg[lastPTR];
705 public:
706 const int _offset; // Offset into oop, with TOP & BOT
707 const PTR _ptr; // Pointer equivalence class
709 const int offset() const { return _offset; }
710 const PTR ptr() const { return _ptr; }
712 static const TypePtr *make( TYPES t, PTR ptr, int offset );
714 // Return a 'ptr' version of this type
715 virtual const Type *cast_to_ptr_type(PTR ptr) const;
717 virtual intptr_t get_con() const;
719 int xadd_offset( intptr_t offset ) const;
720 virtual const TypePtr *add_offset( intptr_t offset ) const;
722 virtual bool singleton(void) const; // TRUE if type is a singleton
723 virtual bool empty(void) const; // TRUE if type is vacuous
724 virtual const Type *xmeet( const Type *t ) const;
725 int meet_offset( int offset ) const;
726 int dual_offset( ) const;
727 virtual const Type *xdual() const; // Compute dual right now.
729 // meet, dual and join over pointer equivalence sets
730 PTR meet_ptr( const PTR in_ptr ) const { return ptr_meet[in_ptr][ptr()]; }
731 PTR dual_ptr() const { return ptr_dual[ptr()]; }
733 // This is textually confusing unless one recalls that
734 // join(t) == dual()->meet(t->dual())->dual().
735 PTR join_ptr( const PTR in_ptr ) const {
736 return ptr_dual[ ptr_meet[ ptr_dual[in_ptr] ] [ dual_ptr() ] ];
737 }
739 // Tests for relation to centerline of type lattice:
740 static bool above_centerline(PTR ptr) { return (ptr <= AnyNull); }
741 static bool below_centerline(PTR ptr) { return (ptr >= NotNull); }
742 // Convenience common pre-built types.
743 static const TypePtr *NULL_PTR;
744 static const TypePtr *NOTNULL;
745 static const TypePtr *BOTTOM;
746 #ifndef PRODUCT
747 virtual void dump2( Dict &d, uint depth, outputStream *st ) const;
748 #endif
749 };
751 //------------------------------TypeRawPtr-------------------------------------
752 // Class of raw pointers, pointers to things other than Oops. Examples
753 // include the stack pointer, top of heap, card-marking area, handles, etc.
754 class TypeRawPtr : public TypePtr {
755 protected:
756 TypeRawPtr( PTR ptr, address bits ) : TypePtr(RawPtr,ptr,0), _bits(bits){}
757 public:
758 virtual bool eq( const Type *t ) const;
759 virtual int hash() const; // Type specific hashing
761 const address _bits; // Constant value, if applicable
763 static const TypeRawPtr *make( PTR ptr );
764 static const TypeRawPtr *make( address bits );
766 // Return a 'ptr' version of this type
767 virtual const Type *cast_to_ptr_type(PTR ptr) const;
769 virtual intptr_t get_con() const;
771 virtual const TypePtr *add_offset( intptr_t offset ) const;
773 virtual const Type *xmeet( const Type *t ) const;
774 virtual const Type *xdual() const; // Compute dual right now.
775 // Convenience common pre-built types.
776 static const TypeRawPtr *BOTTOM;
777 static const TypeRawPtr *NOTNULL;
778 #ifndef PRODUCT
779 virtual void dump2( Dict &d, uint depth, outputStream *st ) const;
780 #endif
781 };
783 //------------------------------TypeOopPtr-------------------------------------
784 // Some kind of oop (Java pointer), either klass or instance or array.
785 class TypeOopPtr : public TypePtr {
786 protected:
787 TypeOopPtr( TYPES t, PTR ptr, ciKlass* k, bool xk, ciObject* o, int offset, int instance_id );
788 public:
789 virtual bool eq( const Type *t ) const;
790 virtual int hash() const; // Type specific hashing
791 virtual bool singleton(void) const; // TRUE if type is a singleton
792 enum {
793 InstanceTop = -1, // undefined instance
794 InstanceBot = 0 // any possible instance
795 };
796 protected:
798 // Oop is NULL, unless this is a constant oop.
799 ciObject* _const_oop; // Constant oop
800 // If _klass is NULL, then so is _sig. This is an unloaded klass.
801 ciKlass* _klass; // Klass object
802 // Does the type exclude subclasses of the klass? (Inexact == polymorphic.)
803 bool _klass_is_exact;
804 bool _is_ptr_to_narrowoop;
805 bool _is_ptr_to_narrowklass;
806 bool _is_ptr_to_boxed_value;
808 // If not InstanceTop or InstanceBot, indicates that this is
809 // a particular instance of this type which is distinct.
810 // This is the the node index of the allocation node creating this instance.
811 int _instance_id;
813 static const TypeOopPtr* make_from_klass_common(ciKlass* klass, bool klass_change, bool try_for_exact);
815 int dual_instance_id() const;
816 int meet_instance_id(int uid) const;
818 public:
819 // Creates a type given a klass. Correctly handles multi-dimensional arrays
820 // Respects UseUniqueSubclasses.
821 // If the klass is final, the resulting type will be exact.
822 static const TypeOopPtr* make_from_klass(ciKlass* klass) {
823 return make_from_klass_common(klass, true, false);
824 }
825 // Same as before, but will produce an exact type, even if
826 // the klass is not final, as long as it has exactly one implementation.
827 static const TypeOopPtr* make_from_klass_unique(ciKlass* klass) {
828 return make_from_klass_common(klass, true, true);
829 }
830 // Same as before, but does not respects UseUniqueSubclasses.
831 // Use this only for creating array element types.
832 static const TypeOopPtr* make_from_klass_raw(ciKlass* klass) {
833 return make_from_klass_common(klass, false, false);
834 }
835 // Creates a singleton type given an object.
836 // If the object cannot be rendered as a constant,
837 // may return a non-singleton type.
838 // If require_constant, produce a NULL if a singleton is not possible.
839 static const TypeOopPtr* make_from_constant(ciObject* o,
840 bool require_constant = false,
841 bool not_null_elements = false);
843 // Make a generic (unclassed) pointer to an oop.
844 static const TypeOopPtr* make(PTR ptr, int offset, int instance_id);
846 ciObject* const_oop() const { return _const_oop; }
847 virtual ciKlass* klass() const { return _klass; }
848 bool klass_is_exact() const { return _klass_is_exact; }
850 // Returns true if this pointer points at memory which contains a
851 // compressed oop references.
852 bool is_ptr_to_narrowoop_nv() const { return _is_ptr_to_narrowoop; }
853 bool is_ptr_to_narrowklass_nv() const { return _is_ptr_to_narrowklass; }
854 bool is_ptr_to_boxed_value() const { return _is_ptr_to_boxed_value; }
855 bool is_known_instance() const { return _instance_id > 0; }
856 int instance_id() const { return _instance_id; }
857 bool is_known_instance_field() const { return is_known_instance() && _offset >= 0; }
859 virtual intptr_t get_con() const;
861 virtual const Type *cast_to_ptr_type(PTR ptr) const;
863 virtual const Type *cast_to_exactness(bool klass_is_exact) const;
865 virtual const TypeOopPtr *cast_to_instance_id(int instance_id) const;
867 // corresponding pointer to klass, for a given instance
868 const TypeKlassPtr* as_klass_type() const;
870 virtual const TypePtr *add_offset( intptr_t offset ) const;
872 virtual const Type *xmeet( const Type *t ) const;
873 virtual const Type *xdual() const; // Compute dual right now.
875 // Do not allow interface-vs.-noninterface joins to collapse to top.
876 virtual const Type *filter( const Type *kills ) const;
878 // Convenience common pre-built type.
879 static const TypeOopPtr *BOTTOM;
880 #ifndef PRODUCT
881 virtual void dump2( Dict &d, uint depth, outputStream *st ) const;
882 #endif
883 };
885 //------------------------------TypeInstPtr------------------------------------
886 // Class of Java object pointers, pointing either to non-array Java instances
887 // or to a Klass* (including array klasses).
888 class TypeInstPtr : public TypeOopPtr {
889 TypeInstPtr( PTR ptr, ciKlass* k, bool xk, ciObject* o, int offset, int instance_id );
890 virtual bool eq( const Type *t ) const;
891 virtual int hash() const; // Type specific hashing
893 ciSymbol* _name; // class name
895 public:
896 ciSymbol* name() const { return _name; }
898 bool is_loaded() const { return _klass->is_loaded(); }
900 // Make a pointer to a constant oop.
901 static const TypeInstPtr *make(ciObject* o) {
902 return make(TypePtr::Constant, o->klass(), true, o, 0);
903 }
904 // Make a pointer to a constant oop with offset.
905 static const TypeInstPtr *make(ciObject* o, int offset) {
906 return make(TypePtr::Constant, o->klass(), true, o, offset);
907 }
909 // Make a pointer to some value of type klass.
910 static const TypeInstPtr *make(PTR ptr, ciKlass* klass) {
911 return make(ptr, klass, false, NULL, 0);
912 }
914 // Make a pointer to some non-polymorphic value of exactly type klass.
915 static const TypeInstPtr *make_exact(PTR ptr, ciKlass* klass) {
916 return make(ptr, klass, true, NULL, 0);
917 }
919 // Make a pointer to some value of type klass with offset.
920 static const TypeInstPtr *make(PTR ptr, ciKlass* klass, int offset) {
921 return make(ptr, klass, false, NULL, offset);
922 }
924 // Make a pointer to an oop.
925 static const TypeInstPtr *make(PTR ptr, ciKlass* k, bool xk, ciObject* o, int offset, int instance_id = InstanceBot );
927 /** Create constant type for a constant boxed value */
928 const Type* get_const_boxed_value() const;
930 // If this is a java.lang.Class constant, return the type for it or NULL.
931 // Pass to Type::get_const_type to turn it to a type, which will usually
932 // be a TypeInstPtr, but may also be a TypeInt::INT for int.class, etc.
933 ciType* java_mirror_type() const;
935 virtual const Type *cast_to_ptr_type(PTR ptr) const;
937 virtual const Type *cast_to_exactness(bool klass_is_exact) const;
939 virtual const TypeOopPtr *cast_to_instance_id(int instance_id) const;
941 virtual const TypePtr *add_offset( intptr_t offset ) const;
943 virtual const Type *xmeet( const Type *t ) const;
944 virtual const TypeInstPtr *xmeet_unloaded( const TypeInstPtr *t ) const;
945 virtual const Type *xdual() const; // Compute dual right now.
947 // Convenience common pre-built types.
948 static const TypeInstPtr *NOTNULL;
949 static const TypeInstPtr *BOTTOM;
950 static const TypeInstPtr *MIRROR;
951 static const TypeInstPtr *MARK;
952 static const TypeInstPtr *KLASS;
953 #ifndef PRODUCT
954 virtual void dump2( Dict &d, uint depth, outputStream *st ) const; // Specialized per-Type dumping
955 #endif
956 };
958 //------------------------------TypeAryPtr-------------------------------------
959 // Class of Java array pointers
960 class TypeAryPtr : public TypeOopPtr {
961 TypeAryPtr( PTR ptr, ciObject* o, const TypeAry *ary, ciKlass* k, bool xk,
962 int offset, int instance_id, bool is_autobox_cache )
963 : TypeOopPtr(AryPtr,ptr,k,xk,o,offset, instance_id),
964 _ary(ary),
965 _is_autobox_cache(is_autobox_cache)
966 {
967 #ifdef ASSERT
968 if (k != NULL) {
969 // Verify that specified klass and TypeAryPtr::klass() follow the same rules.
970 ciKlass* ck = compute_klass(true);
971 if (k != ck) {
972 this->dump(); tty->cr();
973 tty->print(" k: ");
974 k->print(); tty->cr();
975 tty->print("ck: ");
976 if (ck != NULL) ck->print();
977 else tty->print("<NULL>");
978 tty->cr();
979 assert(false, "unexpected TypeAryPtr::_klass");
980 }
981 }
982 #endif
983 }
984 virtual bool eq( const Type *t ) const;
985 virtual int hash() const; // Type specific hashing
986 const TypeAry *_ary; // Array we point into
987 const bool _is_autobox_cache;
989 ciKlass* compute_klass(DEBUG_ONLY(bool verify = false)) const;
991 public:
992 // Accessors
993 ciKlass* klass() const;
994 const TypeAry* ary() const { return _ary; }
995 const Type* elem() const { return _ary->_elem; }
996 const TypeInt* size() const { return _ary->_size; }
997 bool is_stable() const { return _ary->_stable; }
999 bool is_autobox_cache() const { return _is_autobox_cache; }
1001 static const TypeAryPtr *make( PTR ptr, const TypeAry *ary, ciKlass* k, bool xk, int offset, int instance_id = InstanceBot);
1002 // Constant pointer to array
1003 static const TypeAryPtr *make( PTR ptr, ciObject* o, const TypeAry *ary, ciKlass* k, bool xk, int offset, int instance_id = InstanceBot, bool is_autobox_cache = false);
1005 // Return a 'ptr' version of this type
1006 virtual const Type *cast_to_ptr_type(PTR ptr) const;
1008 virtual const Type *cast_to_exactness(bool klass_is_exact) const;
1010 virtual const TypeOopPtr *cast_to_instance_id(int instance_id) const;
1012 virtual const TypeAryPtr* cast_to_size(const TypeInt* size) const;
1013 virtual const TypeInt* narrow_size_type(const TypeInt* size) const;
1015 virtual bool empty(void) const; // TRUE if type is vacuous
1016 virtual const TypePtr *add_offset( intptr_t offset ) const;
1018 virtual const Type *xmeet( const Type *t ) const;
1019 virtual const Type *xdual() const; // Compute dual right now.
1021 const TypeAryPtr* cast_to_stable(bool stable, int stable_dimension = 1) const;
1022 int stable_dimension() const;
1024 // Convenience common pre-built types.
1025 static const TypeAryPtr *RANGE;
1026 static const TypeAryPtr *OOPS;
1027 static const TypeAryPtr *NARROWOOPS;
1028 static const TypeAryPtr *BYTES;
1029 static const TypeAryPtr *SHORTS;
1030 static const TypeAryPtr *CHARS;
1031 static const TypeAryPtr *INTS;
1032 static const TypeAryPtr *LONGS;
1033 static const TypeAryPtr *FLOATS;
1034 static const TypeAryPtr *DOUBLES;
1035 // selects one of the above:
1036 static const TypeAryPtr *get_array_body_type(BasicType elem) {
1037 assert((uint)elem <= T_CONFLICT && _array_body_type[elem] != NULL, "bad elem type");
1038 return _array_body_type[elem];
1039 }
1040 static const TypeAryPtr *_array_body_type[T_CONFLICT+1];
1041 // sharpen the type of an int which is used as an array size
1042 #ifdef ASSERT
1043 // One type is interface, the other is oop
1044 virtual bool interface_vs_oop(const Type *t) const;
1045 #endif
1046 #ifndef PRODUCT
1047 virtual void dump2( Dict &d, uint depth, outputStream *st ) const; // Specialized per-Type dumping
1048 #endif
1049 };
1051 //------------------------------TypeMetadataPtr-------------------------------------
1052 // Some kind of metadata, either Method*, MethodData* or CPCacheOop
1053 class TypeMetadataPtr : public TypePtr {
1054 protected:
1055 TypeMetadataPtr(PTR ptr, ciMetadata* metadata, int offset);
1056 public:
1057 virtual bool eq( const Type *t ) const;
1058 virtual int hash() const; // Type specific hashing
1059 virtual bool singleton(void) const; // TRUE if type is a singleton
1061 private:
1062 ciMetadata* _metadata;
1064 public:
1065 static const TypeMetadataPtr* make(PTR ptr, ciMetadata* m, int offset);
1067 static const TypeMetadataPtr* make(ciMethod* m);
1068 static const TypeMetadataPtr* make(ciMethodData* m);
1070 ciMetadata* metadata() const { return _metadata; }
1072 virtual const Type *cast_to_ptr_type(PTR ptr) const;
1074 virtual const TypePtr *add_offset( intptr_t offset ) const;
1076 virtual const Type *xmeet( const Type *t ) const;
1077 virtual const Type *xdual() const; // Compute dual right now.
1079 virtual intptr_t get_con() const;
1081 // Do not allow interface-vs.-noninterface joins to collapse to top.
1082 virtual const Type *filter( const Type *kills ) const;
1084 // Convenience common pre-built types.
1085 static const TypeMetadataPtr *BOTTOM;
1087 #ifndef PRODUCT
1088 virtual void dump2( Dict &d, uint depth, outputStream *st ) const;
1089 #endif
1090 };
1092 //------------------------------TypeKlassPtr-----------------------------------
1093 // Class of Java Klass pointers
1094 class TypeKlassPtr : public TypePtr {
1095 TypeKlassPtr( PTR ptr, ciKlass* klass, int offset );
1097 public:
1098 virtual bool eq( const Type *t ) const;
1099 virtual int hash() const; // Type specific hashing
1100 virtual bool singleton(void) const; // TRUE if type is a singleton
1101 private:
1103 static const TypeKlassPtr* make_from_klass_common(ciKlass* klass, bool klass_change, bool try_for_exact);
1105 ciKlass* _klass;
1107 // Does the type exclude subclasses of the klass? (Inexact == polymorphic.)
1108 bool _klass_is_exact;
1110 public:
1111 ciSymbol* name() const { return klass()->name(); }
1113 ciKlass* klass() const { return _klass; }
1114 bool klass_is_exact() const { return _klass_is_exact; }
1116 bool is_loaded() const { return klass()->is_loaded(); }
1118 // Creates a type given a klass. Correctly handles multi-dimensional arrays
1119 // Respects UseUniqueSubclasses.
1120 // If the klass is final, the resulting type will be exact.
1121 static const TypeKlassPtr* make_from_klass(ciKlass* klass) {
1122 return make_from_klass_common(klass, true, false);
1123 }
1124 // Same as before, but will produce an exact type, even if
1125 // the klass is not final, as long as it has exactly one implementation.
1126 static const TypeKlassPtr* make_from_klass_unique(ciKlass* klass) {
1127 return make_from_klass_common(klass, true, true);
1128 }
1129 // Same as before, but does not respects UseUniqueSubclasses.
1130 // Use this only for creating array element types.
1131 static const TypeKlassPtr* make_from_klass_raw(ciKlass* klass) {
1132 return make_from_klass_common(klass, false, false);
1133 }
1135 // Make a generic (unclassed) pointer to metadata.
1136 static const TypeKlassPtr* make(PTR ptr, int offset);
1138 // ptr to klass 'k'
1139 static const TypeKlassPtr *make( ciKlass* k ) { return make( TypePtr::Constant, k, 0); }
1140 // ptr to klass 'k' with offset
1141 static const TypeKlassPtr *make( ciKlass* k, int offset ) { return make( TypePtr::Constant, k, offset); }
1142 // ptr to klass 'k' or sub-klass
1143 static const TypeKlassPtr *make( PTR ptr, ciKlass* k, int offset);
1145 virtual const Type *cast_to_ptr_type(PTR ptr) const;
1147 virtual const Type *cast_to_exactness(bool klass_is_exact) const;
1149 // corresponding pointer to instance, for a given class
1150 const TypeOopPtr* as_instance_type() const;
1152 virtual const TypePtr *add_offset( intptr_t offset ) const;
1153 virtual const Type *xmeet( const Type *t ) const;
1154 virtual const Type *xdual() const; // Compute dual right now.
1156 virtual intptr_t get_con() const;
1158 // Convenience common pre-built types.
1159 static const TypeKlassPtr* OBJECT; // Not-null object klass or below
1160 static const TypeKlassPtr* OBJECT_OR_NULL; // Maybe-null version of same
1161 #ifndef PRODUCT
1162 virtual void dump2( Dict &d, uint depth, outputStream *st ) const; // Specialized per-Type dumping
1163 #endif
1164 };
1166 class TypeNarrowPtr : public Type {
1167 protected:
1168 const TypePtr* _ptrtype; // Could be TypePtr::NULL_PTR
1170 TypeNarrowPtr(TYPES t, const TypePtr* ptrtype): _ptrtype(ptrtype),
1171 Type(t) {
1172 assert(ptrtype->offset() == 0 ||
1173 ptrtype->offset() == OffsetBot ||
1174 ptrtype->offset() == OffsetTop, "no real offsets");
1175 }
1177 virtual const TypeNarrowPtr *isa_same_narrowptr(const Type *t) const = 0;
1178 virtual const TypeNarrowPtr *is_same_narrowptr(const Type *t) const = 0;
1179 virtual const TypeNarrowPtr *make_same_narrowptr(const TypePtr *t) const = 0;
1180 virtual const TypeNarrowPtr *make_hash_same_narrowptr(const TypePtr *t) const = 0;
1181 public:
1182 virtual bool eq( const Type *t ) const;
1183 virtual int hash() const; // Type specific hashing
1184 virtual bool singleton(void) const; // TRUE if type is a singleton
1186 virtual const Type *xmeet( const Type *t ) const;
1187 virtual const Type *xdual() const; // Compute dual right now.
1189 virtual intptr_t get_con() const;
1191 // Do not allow interface-vs.-noninterface joins to collapse to top.
1192 virtual const Type *filter( const Type *kills ) const;
1194 virtual bool empty(void) const; // TRUE if type is vacuous
1196 // returns the equivalent ptr type for this compressed pointer
1197 const TypePtr *get_ptrtype() const {
1198 return _ptrtype;
1199 }
1201 #ifndef PRODUCT
1202 virtual void dump2( Dict &d, uint depth, outputStream *st ) const;
1203 #endif
1204 };
1206 //------------------------------TypeNarrowOop----------------------------------
1207 // A compressed reference to some kind of Oop. This type wraps around
1208 // a preexisting TypeOopPtr and forwards most of it's operations to
1209 // the underlying type. It's only real purpose is to track the
1210 // oopness of the compressed oop value when we expose the conversion
1211 // between the normal and the compressed form.
1212 class TypeNarrowOop : public TypeNarrowPtr {
1213 protected:
1214 TypeNarrowOop( const TypePtr* ptrtype): TypeNarrowPtr(NarrowOop, ptrtype) {
1215 }
1217 virtual const TypeNarrowPtr *isa_same_narrowptr(const Type *t) const {
1218 return t->isa_narrowoop();
1219 }
1221 virtual const TypeNarrowPtr *is_same_narrowptr(const Type *t) const {
1222 return t->is_narrowoop();
1223 }
1225 virtual const TypeNarrowPtr *make_same_narrowptr(const TypePtr *t) const {
1226 return new TypeNarrowOop(t);
1227 }
1229 virtual const TypeNarrowPtr *make_hash_same_narrowptr(const TypePtr *t) const {
1230 return (const TypeNarrowPtr*)((new TypeNarrowOop(t))->hashcons());
1231 }
1233 public:
1235 static const TypeNarrowOop *make( const TypePtr* type);
1237 static const TypeNarrowOop* make_from_constant(ciObject* con, bool require_constant = false) {
1238 return make(TypeOopPtr::make_from_constant(con, require_constant));
1239 }
1241 static const TypeNarrowOop *BOTTOM;
1242 static const TypeNarrowOop *NULL_PTR;
1244 #ifndef PRODUCT
1245 virtual void dump2( Dict &d, uint depth, outputStream *st ) const;
1246 #endif
1247 };
1249 //------------------------------TypeNarrowKlass----------------------------------
1250 // A compressed reference to klass pointer. This type wraps around a
1251 // preexisting TypeKlassPtr and forwards most of it's operations to
1252 // the underlying type.
1253 class TypeNarrowKlass : public TypeNarrowPtr {
1254 protected:
1255 TypeNarrowKlass( const TypePtr* ptrtype): TypeNarrowPtr(NarrowKlass, ptrtype) {
1256 }
1258 virtual const TypeNarrowPtr *isa_same_narrowptr(const Type *t) const {
1259 return t->isa_narrowklass();
1260 }
1262 virtual const TypeNarrowPtr *is_same_narrowptr(const Type *t) const {
1263 return t->is_narrowklass();
1264 }
1266 virtual const TypeNarrowPtr *make_same_narrowptr(const TypePtr *t) const {
1267 return new TypeNarrowKlass(t);
1268 }
1270 virtual const TypeNarrowPtr *make_hash_same_narrowptr(const TypePtr *t) const {
1271 return (const TypeNarrowPtr*)((new TypeNarrowKlass(t))->hashcons());
1272 }
1274 public:
1275 static const TypeNarrowKlass *make( const TypePtr* type);
1277 // static const TypeNarrowKlass *BOTTOM;
1278 static const TypeNarrowKlass *NULL_PTR;
1280 #ifndef PRODUCT
1281 virtual void dump2( Dict &d, uint depth, outputStream *st ) const;
1282 #endif
1283 };
1285 //------------------------------TypeFunc---------------------------------------
1286 // Class of Array Types
1287 class TypeFunc : public Type {
1288 TypeFunc( const TypeTuple *domain, const TypeTuple *range ) : Type(Function), _domain(domain), _range(range) {}
1289 virtual bool eq( const Type *t ) const;
1290 virtual int hash() const; // Type specific hashing
1291 virtual bool singleton(void) const; // TRUE if type is a singleton
1292 virtual bool empty(void) const; // TRUE if type is vacuous
1293 public:
1294 // Constants are shared among ADLC and VM
1295 enum { Control = AdlcVMDeps::Control,
1296 I_O = AdlcVMDeps::I_O,
1297 Memory = AdlcVMDeps::Memory,
1298 FramePtr = AdlcVMDeps::FramePtr,
1299 ReturnAdr = AdlcVMDeps::ReturnAdr,
1300 Parms = AdlcVMDeps::Parms
1301 };
1303 const TypeTuple* const _domain; // Domain of inputs
1304 const TypeTuple* const _range; // Range of results
1306 // Accessors:
1307 const TypeTuple* domain() const { return _domain; }
1308 const TypeTuple* range() const { return _range; }
1310 static const TypeFunc *make(ciMethod* method);
1311 static const TypeFunc *make(ciSignature signature, const Type* extra);
1312 static const TypeFunc *make(const TypeTuple* domain, const TypeTuple* range);
1314 virtual const Type *xmeet( const Type *t ) const;
1315 virtual const Type *xdual() const; // Compute dual right now.
1317 BasicType return_type() const;
1319 #ifndef PRODUCT
1320 virtual void dump2( Dict &d, uint depth, outputStream *st ) const; // Specialized per-Type dumping
1321 #endif
1322 // Convenience common pre-built types.
1323 };
1325 //------------------------------accessors--------------------------------------
1326 inline bool Type::is_ptr_to_narrowoop() const {
1327 #ifdef _LP64
1328 return (isa_oopptr() != NULL && is_oopptr()->is_ptr_to_narrowoop_nv());
1329 #else
1330 return false;
1331 #endif
1332 }
1334 inline bool Type::is_ptr_to_narrowklass() const {
1335 #ifdef _LP64
1336 return (isa_oopptr() != NULL && is_oopptr()->is_ptr_to_narrowklass_nv());
1337 #else
1338 return false;
1339 #endif
1340 }
1342 inline float Type::getf() const {
1343 assert( _base == FloatCon, "Not a FloatCon" );
1344 return ((TypeF*)this)->_f;
1345 }
1347 inline double Type::getd() const {
1348 assert( _base == DoubleCon, "Not a DoubleCon" );
1349 return ((TypeD*)this)->_d;
1350 }
1352 inline const TypeInt *Type::is_int() const {
1353 assert( _base == Int, "Not an Int" );
1354 return (TypeInt*)this;
1355 }
1357 inline const TypeInt *Type::isa_int() const {
1358 return ( _base == Int ? (TypeInt*)this : NULL);
1359 }
1361 inline const TypeLong *Type::is_long() const {
1362 assert( _base == Long, "Not a Long" );
1363 return (TypeLong*)this;
1364 }
1366 inline const TypeLong *Type::isa_long() const {
1367 return ( _base == Long ? (TypeLong*)this : NULL);
1368 }
1370 inline const TypeF *Type::isa_float() const {
1371 return ((_base == FloatTop ||
1372 _base == FloatCon ||
1373 _base == FloatBot) ? (TypeF*)this : NULL);
1374 }
1376 inline const TypeF *Type::is_float_constant() const {
1377 assert( _base == FloatCon, "Not a Float" );
1378 return (TypeF*)this;
1379 }
1381 inline const TypeF *Type::isa_float_constant() const {
1382 return ( _base == FloatCon ? (TypeF*)this : NULL);
1383 }
1385 inline const TypeD *Type::isa_double() const {
1386 return ((_base == DoubleTop ||
1387 _base == DoubleCon ||
1388 _base == DoubleBot) ? (TypeD*)this : NULL);
1389 }
1391 inline const TypeD *Type::is_double_constant() const {
1392 assert( _base == DoubleCon, "Not a Double" );
1393 return (TypeD*)this;
1394 }
1396 inline const TypeD *Type::isa_double_constant() const {
1397 return ( _base == DoubleCon ? (TypeD*)this : NULL);
1398 }
1400 inline const TypeTuple *Type::is_tuple() const {
1401 assert( _base == Tuple, "Not a Tuple" );
1402 return (TypeTuple*)this;
1403 }
1405 inline const TypeAry *Type::is_ary() const {
1406 assert( _base == Array , "Not an Array" );
1407 return (TypeAry*)this;
1408 }
1410 inline const TypeVect *Type::is_vect() const {
1411 assert( _base >= VectorS && _base <= VectorY, "Not a Vector" );
1412 return (TypeVect*)this;
1413 }
1415 inline const TypeVect *Type::isa_vect() const {
1416 return (_base >= VectorS && _base <= VectorY) ? (TypeVect*)this : NULL;
1417 }
1419 inline const TypePtr *Type::is_ptr() const {
1420 // AnyPtr is the first Ptr and KlassPtr the last, with no non-ptrs between.
1421 assert(_base >= AnyPtr && _base <= KlassPtr, "Not a pointer");
1422 return (TypePtr*)this;
1423 }
1425 inline const TypePtr *Type::isa_ptr() const {
1426 // AnyPtr is the first Ptr and KlassPtr the last, with no non-ptrs between.
1427 return (_base >= AnyPtr && _base <= KlassPtr) ? (TypePtr*)this : NULL;
1428 }
1430 inline const TypeOopPtr *Type::is_oopptr() const {
1431 // OopPtr is the first and KlassPtr the last, with no non-oops between.
1432 assert(_base >= OopPtr && _base <= AryPtr, "Not a Java pointer" ) ;
1433 return (TypeOopPtr*)this;
1434 }
1436 inline const TypeOopPtr *Type::isa_oopptr() const {
1437 // OopPtr is the first and KlassPtr the last, with no non-oops between.
1438 return (_base >= OopPtr && _base <= AryPtr) ? (TypeOopPtr*)this : NULL;
1439 }
1441 inline const TypeRawPtr *Type::isa_rawptr() const {
1442 return (_base == RawPtr) ? (TypeRawPtr*)this : NULL;
1443 }
1445 inline const TypeRawPtr *Type::is_rawptr() const {
1446 assert( _base == RawPtr, "Not a raw pointer" );
1447 return (TypeRawPtr*)this;
1448 }
1450 inline const TypeInstPtr *Type::isa_instptr() const {
1451 return (_base == InstPtr) ? (TypeInstPtr*)this : NULL;
1452 }
1454 inline const TypeInstPtr *Type::is_instptr() const {
1455 assert( _base == InstPtr, "Not an object pointer" );
1456 return (TypeInstPtr*)this;
1457 }
1459 inline const TypeAryPtr *Type::isa_aryptr() const {
1460 return (_base == AryPtr) ? (TypeAryPtr*)this : NULL;
1461 }
1463 inline const TypeAryPtr *Type::is_aryptr() const {
1464 assert( _base == AryPtr, "Not an array pointer" );
1465 return (TypeAryPtr*)this;
1466 }
1468 inline const TypeNarrowOop *Type::is_narrowoop() const {
1469 // OopPtr is the first and KlassPtr the last, with no non-oops between.
1470 assert(_base == NarrowOop, "Not a narrow oop" ) ;
1471 return (TypeNarrowOop*)this;
1472 }
1474 inline const TypeNarrowOop *Type::isa_narrowoop() const {
1475 // OopPtr is the first and KlassPtr the last, with no non-oops between.
1476 return (_base == NarrowOop) ? (TypeNarrowOop*)this : NULL;
1477 }
1479 inline const TypeNarrowKlass *Type::is_narrowklass() const {
1480 assert(_base == NarrowKlass, "Not a narrow oop" ) ;
1481 return (TypeNarrowKlass*)this;
1482 }
1484 inline const TypeNarrowKlass *Type::isa_narrowklass() const {
1485 return (_base == NarrowKlass) ? (TypeNarrowKlass*)this : NULL;
1486 }
1488 inline const TypeMetadataPtr *Type::is_metadataptr() const {
1489 // MetadataPtr is the first and CPCachePtr the last
1490 assert(_base == MetadataPtr, "Not a metadata pointer" ) ;
1491 return (TypeMetadataPtr*)this;
1492 }
1494 inline const TypeMetadataPtr *Type::isa_metadataptr() const {
1495 return (_base == MetadataPtr) ? (TypeMetadataPtr*)this : NULL;
1496 }
1498 inline const TypeKlassPtr *Type::isa_klassptr() const {
1499 return (_base == KlassPtr) ? (TypeKlassPtr*)this : NULL;
1500 }
1502 inline const TypeKlassPtr *Type::is_klassptr() const {
1503 assert( _base == KlassPtr, "Not a klass pointer" );
1504 return (TypeKlassPtr*)this;
1505 }
1507 inline const TypePtr* Type::make_ptr() const {
1508 return (_base == NarrowOop) ? is_narrowoop()->get_ptrtype() :
1509 ((_base == NarrowKlass) ? is_narrowklass()->get_ptrtype() :
1510 (isa_ptr() ? is_ptr() : NULL));
1511 }
1513 inline const TypeOopPtr* Type::make_oopptr() const {
1514 return (_base == NarrowOop) ? is_narrowoop()->get_ptrtype()->is_oopptr() : is_oopptr();
1515 }
1517 inline const TypeNarrowOop* Type::make_narrowoop() const {
1518 return (_base == NarrowOop) ? is_narrowoop() :
1519 (isa_ptr() ? TypeNarrowOop::make(is_ptr()) : NULL);
1520 }
1522 inline const TypeNarrowKlass* Type::make_narrowklass() const {
1523 return (_base == NarrowKlass) ? is_narrowklass() :
1524 (isa_ptr() ? TypeNarrowKlass::make(is_ptr()) : NULL);
1525 }
1527 inline bool Type::is_floatingpoint() const {
1528 if( (_base == FloatCon) || (_base == FloatBot) ||
1529 (_base == DoubleCon) || (_base == DoubleBot) )
1530 return true;
1531 return false;
1532 }
1534 inline bool Type::is_ptr_to_boxing_obj() const {
1535 const TypeInstPtr* tp = isa_instptr();
1536 return (tp != NULL) && (tp->offset() == 0) &&
1537 tp->klass()->is_instance_klass() &&
1538 tp->klass()->as_instance_klass()->is_box_klass();
1539 }
1542 // ===============================================================
1543 // Things that need to be 64-bits in the 64-bit build but
1544 // 32-bits in the 32-bit build. Done this way to get full
1545 // optimization AND strong typing.
1546 #ifdef _LP64
1548 // For type queries and asserts
1549 #define is_intptr_t is_long
1550 #define isa_intptr_t isa_long
1551 #define find_intptr_t_type find_long_type
1552 #define find_intptr_t_con find_long_con
1553 #define TypeX TypeLong
1554 #define Type_X Type::Long
1555 #define TypeX_X TypeLong::LONG
1556 #define TypeX_ZERO TypeLong::ZERO
1557 // For 'ideal_reg' machine registers
1558 #define Op_RegX Op_RegL
1559 // For phase->intcon variants
1560 #define MakeConX longcon
1561 #define ConXNode ConLNode
1562 // For array index arithmetic
1563 #define MulXNode MulLNode
1564 #define AndXNode AndLNode
1565 #define OrXNode OrLNode
1566 #define CmpXNode CmpLNode
1567 #define SubXNode SubLNode
1568 #define LShiftXNode LShiftLNode
1569 // For object size computation:
1570 #define AddXNode AddLNode
1571 #define RShiftXNode RShiftLNode
1572 // For card marks and hashcodes
1573 #define URShiftXNode URShiftLNode
1574 // UseOptoBiasInlining
1575 #define XorXNode XorLNode
1576 #define StoreXConditionalNode StoreLConditionalNode
1577 // Opcodes
1578 #define Op_LShiftX Op_LShiftL
1579 #define Op_AndX Op_AndL
1580 #define Op_AddX Op_AddL
1581 #define Op_SubX Op_SubL
1582 #define Op_XorX Op_XorL
1583 #define Op_URShiftX Op_URShiftL
1584 // conversions
1585 #define ConvI2X(x) ConvI2L(x)
1586 #define ConvL2X(x) (x)
1587 #define ConvX2I(x) ConvL2I(x)
1588 #define ConvX2L(x) (x)
1590 #else
1592 // For type queries and asserts
1593 #define is_intptr_t is_int
1594 #define isa_intptr_t isa_int
1595 #define find_intptr_t_type find_int_type
1596 #define find_intptr_t_con find_int_con
1597 #define TypeX TypeInt
1598 #define Type_X Type::Int
1599 #define TypeX_X TypeInt::INT
1600 #define TypeX_ZERO TypeInt::ZERO
1601 // For 'ideal_reg' machine registers
1602 #define Op_RegX Op_RegI
1603 // For phase->intcon variants
1604 #define MakeConX intcon
1605 #define ConXNode ConINode
1606 // For array index arithmetic
1607 #define MulXNode MulINode
1608 #define AndXNode AndINode
1609 #define OrXNode OrINode
1610 #define CmpXNode CmpINode
1611 #define SubXNode SubINode
1612 #define LShiftXNode LShiftINode
1613 // For object size computation:
1614 #define AddXNode AddINode
1615 #define RShiftXNode RShiftINode
1616 // For card marks and hashcodes
1617 #define URShiftXNode URShiftINode
1618 // UseOptoBiasInlining
1619 #define XorXNode XorINode
1620 #define StoreXConditionalNode StoreIConditionalNode
1621 // Opcodes
1622 #define Op_LShiftX Op_LShiftI
1623 #define Op_AndX Op_AndI
1624 #define Op_AddX Op_AddI
1625 #define Op_SubX Op_SubI
1626 #define Op_XorX Op_XorI
1627 #define Op_URShiftX Op_URShiftI
1628 // conversions
1629 #define ConvI2X(x) (x)
1630 #define ConvL2X(x) ConvL2I(x)
1631 #define ConvX2I(x) (x)
1632 #define ConvX2L(x) ConvI2L(x)
1634 #endif
1636 #endif // SHARE_VM_OPTO_TYPE_HPP