Fri, 18 Oct 2013 10:41:56 +0200
8026844: Various Math functions needs intrinsification
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 #ifdef ASSERT
163 // One type is interface, the other is oop
164 virtual bool interface_vs_oop_helper(const Type *t) const;
165 #endif
167 protected:
168 // Each class of type is also identified by its base.
169 const TYPES _base; // Enum of Types type
171 Type( TYPES t ) : _dual(NULL), _base(t) {} // Simple types
172 // ~Type(); // Use fast deallocation
173 const Type *hashcons(); // Hash-cons the type
175 public:
177 inline void* operator new( size_t x ) throw() {
178 Compile* compile = Compile::current();
179 compile->set_type_last_size(x);
180 void *temp = compile->type_arena()->Amalloc_D(x);
181 compile->set_type_hwm(temp);
182 return temp;
183 }
184 inline void operator delete( void* ptr ) {
185 Compile* compile = Compile::current();
186 compile->type_arena()->Afree(ptr,compile->type_last_size());
187 }
189 // Initialize the type system for a particular compilation.
190 static void Initialize(Compile* compile);
192 // Initialize the types shared by all compilations.
193 static void Initialize_shared(Compile* compile);
195 TYPES base() const {
196 assert(_base > Bad && _base < lastype, "sanity");
197 return _base;
198 }
200 // Create a new hash-consd type
201 static const Type *make(enum TYPES);
202 // Test for equivalence of types
203 static int cmp( const Type *const t1, const Type *const t2 );
204 // Test for higher or equal in lattice
205 int higher_equal( const Type *t ) const { return !cmp(meet(t),t); }
207 // MEET operation; lower in lattice.
208 const Type *meet( const Type *t ) const;
209 // WIDEN: 'widens' for Ints and other range types
210 virtual const Type *widen( const Type *old, const Type* limit ) const { return this; }
211 // NARROW: complement for widen, used by pessimistic phases
212 virtual const Type *narrow( const Type *old ) const { return this; }
214 // DUAL operation: reflect around lattice centerline. Used instead of
215 // join to ensure my lattice is symmetric up and down.
216 const Type *dual() const { return _dual; }
218 // Compute meet dependent on base type
219 virtual const Type *xmeet( const Type *t ) const;
220 virtual const Type *xdual() const; // Compute dual right now.
222 // JOIN operation; higher in lattice. Done by finding the dual of the
223 // meet of the dual of the 2 inputs.
224 const Type *join( const Type *t ) const {
225 return dual()->meet(t->dual())->dual(); }
227 // Modified version of JOIN adapted to the needs Node::Value.
228 // Normalizes all empty values to TOP. Does not kill _widen bits.
229 // Currently, it also works around limitations involving interface types.
230 virtual const Type *filter( const Type *kills ) const;
232 #ifdef ASSERT
233 // One type is interface, the other is oop
234 virtual bool interface_vs_oop(const Type *t) const;
235 #endif
237 // Returns true if this pointer points at memory which contains a
238 // compressed oop references.
239 bool is_ptr_to_narrowoop() const;
240 bool is_ptr_to_narrowklass() const;
242 bool is_ptr_to_boxing_obj() const;
245 // Convenience access
246 float getf() const;
247 double getd() const;
249 const TypeInt *is_int() const;
250 const TypeInt *isa_int() const; // Returns NULL if not an Int
251 const TypeLong *is_long() const;
252 const TypeLong *isa_long() const; // Returns NULL if not a Long
253 const TypeD *isa_double() const; // Returns NULL if not a Double{Top,Con,Bot}
254 const TypeD *is_double_constant() const; // Asserts it is a DoubleCon
255 const TypeD *isa_double_constant() const; // Returns NULL if not a DoubleCon
256 const TypeF *isa_float() const; // Returns NULL if not a Float{Top,Con,Bot}
257 const TypeF *is_float_constant() const; // Asserts it is a FloatCon
258 const TypeF *isa_float_constant() const; // Returns NULL if not a FloatCon
259 const TypeTuple *is_tuple() const; // Collection of fields, NOT a pointer
260 const TypeAry *is_ary() const; // Array, NOT array pointer
261 const TypeVect *is_vect() const; // Vector
262 const TypeVect *isa_vect() const; // Returns NULL if not a Vector
263 const TypePtr *is_ptr() const; // Asserts it is a ptr type
264 const TypePtr *isa_ptr() const; // Returns NULL if not ptr type
265 const TypeRawPtr *isa_rawptr() const; // NOT Java oop
266 const TypeRawPtr *is_rawptr() const; // Asserts is rawptr
267 const TypeNarrowOop *is_narrowoop() const; // Java-style GC'd pointer
268 const TypeNarrowOop *isa_narrowoop() const; // Returns NULL if not oop ptr type
269 const TypeNarrowKlass *is_narrowklass() const; // compressed klass pointer
270 const TypeNarrowKlass *isa_narrowklass() const;// Returns NULL if not oop ptr type
271 const TypeOopPtr *isa_oopptr() const; // Returns NULL if not oop ptr type
272 const TypeOopPtr *is_oopptr() const; // Java-style GC'd pointer
273 const TypeInstPtr *isa_instptr() const; // Returns NULL if not InstPtr
274 const TypeInstPtr *is_instptr() const; // Instance
275 const TypeAryPtr *isa_aryptr() const; // Returns NULL if not AryPtr
276 const TypeAryPtr *is_aryptr() const; // Array oop
278 const TypeMetadataPtr *isa_metadataptr() const; // Returns NULL if not oop ptr type
279 const TypeMetadataPtr *is_metadataptr() const; // Java-style GC'd pointer
280 const TypeKlassPtr *isa_klassptr() const; // Returns NULL if not KlassPtr
281 const TypeKlassPtr *is_klassptr() const; // assert if not KlassPtr
283 virtual bool is_finite() const; // Has a finite value
284 virtual bool is_nan() const; // Is not a number (NaN)
286 // Returns this ptr type or the equivalent ptr type for this compressed pointer.
287 const TypePtr* make_ptr() const;
289 // Returns this oopptr type or the equivalent oopptr type for this compressed pointer.
290 // Asserts if the underlying type is not an oopptr or narrowoop.
291 const TypeOopPtr* make_oopptr() const;
293 // Returns this compressed pointer or the equivalent compressed version
294 // of this pointer type.
295 const TypeNarrowOop* make_narrowoop() const;
297 // Returns this compressed klass pointer or the equivalent
298 // compressed version of this pointer type.
299 const TypeNarrowKlass* make_narrowklass() const;
301 // Special test for register pressure heuristic
302 bool is_floatingpoint() const; // True if Float or Double base type
304 // Do you have memory, directly or through a tuple?
305 bool has_memory( ) const;
307 // TRUE if type is a singleton
308 virtual bool singleton(void) const;
310 // TRUE if type is above the lattice centerline, and is therefore vacuous
311 virtual bool empty(void) const;
313 // Return a hash for this type. The hash function is public so ConNode
314 // (constants) can hash on their constant, which is represented by a Type.
315 virtual int hash() const;
317 // Map ideal registers (machine types) to ideal types
318 static const Type *mreg2type[];
320 // Printing, statistics
321 #ifndef PRODUCT
322 void dump_on(outputStream *st) const;
323 void dump() const {
324 dump_on(tty);
325 }
326 virtual void dump2( Dict &d, uint depth, outputStream *st ) const;
327 static void dump_stats();
328 #endif
329 void typerr(const Type *t) const; // Mixing types error
331 // Create basic type
332 static const Type* get_const_basic_type(BasicType type) {
333 assert((uint)type <= T_CONFLICT && _const_basic_type[type] != NULL, "bad type");
334 return _const_basic_type[type];
335 }
337 // Mapping to the array element's basic type.
338 BasicType array_element_basic_type() const;
340 // Create standard type for a ciType:
341 static const Type* get_const_type(ciType* type);
343 // Create standard zero value:
344 static const Type* get_zero_type(BasicType type) {
345 assert((uint)type <= T_CONFLICT && _zero_type[type] != NULL, "bad type");
346 return _zero_type[type];
347 }
349 // Report if this is a zero value (not top).
350 bool is_zero_type() const {
351 BasicType type = basic_type();
352 if (type == T_VOID || type >= T_CONFLICT)
353 return false;
354 else
355 return (this == _zero_type[type]);
356 }
358 // Convenience common pre-built types.
359 static const Type *ABIO;
360 static const Type *BOTTOM;
361 static const Type *CONTROL;
362 static const Type *DOUBLE;
363 static const Type *FLOAT;
364 static const Type *HALF;
365 static const Type *MEMORY;
366 static const Type *MULTI;
367 static const Type *RETURN_ADDRESS;
368 static const Type *TOP;
370 // Mapping from compiler type to VM BasicType
371 BasicType basic_type() const { return _type_info[_base].basic_type; }
372 int ideal_reg() const { return _type_info[_base].ideal_reg; }
373 const char* msg() const { return _type_info[_base].msg; }
374 bool isa_oop_ptr() const { return _type_info[_base].isa_oop; }
375 relocInfo::relocType reloc() const { return _type_info[_base].reloc; }
377 // Mapping from CI type system to compiler type:
378 static const Type* get_typeflow_type(ciType* type);
380 static const Type* make_from_constant(ciConstant constant,
381 bool require_constant = false,
382 bool is_autobox_cache = false);
384 // Speculative type. See TypeInstPtr
385 virtual ciKlass* speculative_type() const { return NULL; }
387 private:
388 // support arrays
389 static const BasicType _basic_type[];
390 static const Type* _zero_type[T_CONFLICT+1];
391 static const Type* _const_basic_type[T_CONFLICT+1];
392 };
394 //------------------------------TypeF------------------------------------------
395 // Class of Float-Constant Types.
396 class TypeF : public Type {
397 TypeF( float f ) : Type(FloatCon), _f(f) {};
398 public:
399 virtual bool eq( const Type *t ) const;
400 virtual int hash() const; // Type specific hashing
401 virtual bool singleton(void) const; // TRUE if type is a singleton
402 virtual bool empty(void) const; // TRUE if type is vacuous
403 public:
404 const float _f; // Float constant
406 static const TypeF *make(float f);
408 virtual bool is_finite() const; // Has a finite value
409 virtual bool is_nan() const; // Is not a number (NaN)
411 virtual const Type *xmeet( const Type *t ) const;
412 virtual const Type *xdual() const; // Compute dual right now.
413 // Convenience common pre-built types.
414 static const TypeF *ZERO; // positive zero only
415 static const TypeF *ONE;
416 #ifndef PRODUCT
417 virtual void dump2( Dict &d, uint depth, outputStream *st ) const;
418 #endif
419 };
421 //------------------------------TypeD------------------------------------------
422 // Class of Double-Constant Types.
423 class TypeD : public Type {
424 TypeD( double d ) : Type(DoubleCon), _d(d) {};
425 public:
426 virtual bool eq( const Type *t ) const;
427 virtual int hash() const; // Type specific hashing
428 virtual bool singleton(void) const; // TRUE if type is a singleton
429 virtual bool empty(void) const; // TRUE if type is vacuous
430 public:
431 const double _d; // Double constant
433 static const TypeD *make(double d);
435 virtual bool is_finite() const; // Has a finite value
436 virtual bool is_nan() const; // Is not a number (NaN)
438 virtual const Type *xmeet( const Type *t ) const;
439 virtual const Type *xdual() const; // Compute dual right now.
440 // Convenience common pre-built types.
441 static const TypeD *ZERO; // positive zero only
442 static const TypeD *ONE;
443 #ifndef PRODUCT
444 virtual void dump2( Dict &d, uint depth, outputStream *st ) const;
445 #endif
446 };
448 //------------------------------TypeInt----------------------------------------
449 // Class of integer ranges, the set of integers between a lower bound and an
450 // upper bound, inclusive.
451 class TypeInt : public Type {
452 TypeInt( jint lo, jint hi, int w );
453 public:
454 virtual bool eq( const Type *t ) const;
455 virtual int hash() const; // Type specific hashing
456 virtual bool singleton(void) const; // TRUE if type is a singleton
457 virtual bool empty(void) const; // TRUE if type is vacuous
458 public:
459 const jint _lo, _hi; // Lower bound, upper bound
460 const short _widen; // Limit on times we widen this sucker
462 static const TypeInt *make(jint lo);
463 // must always specify w
464 static const TypeInt *make(jint lo, jint hi, int w);
466 // Check for single integer
467 int is_con() const { return _lo==_hi; }
468 bool is_con(int i) const { return is_con() && _lo == i; }
469 jint get_con() const { assert( is_con(), "" ); return _lo; }
471 virtual bool is_finite() const; // Has a finite value
473 virtual const Type *xmeet( const Type *t ) const;
474 virtual const Type *xdual() const; // Compute dual right now.
475 virtual const Type *widen( const Type *t, const Type* limit_type ) const;
476 virtual const Type *narrow( const Type *t ) const;
477 // Do not kill _widen bits.
478 virtual const Type *filter( const Type *kills ) const;
479 // Convenience common pre-built types.
480 static const TypeInt *MINUS_1;
481 static const TypeInt *ZERO;
482 static const TypeInt *ONE;
483 static const TypeInt *BOOL;
484 static const TypeInt *CC;
485 static const TypeInt *CC_LT; // [-1] == MINUS_1
486 static const TypeInt *CC_GT; // [1] == ONE
487 static const TypeInt *CC_EQ; // [0] == ZERO
488 static const TypeInt *CC_LE; // [-1,0]
489 static const TypeInt *CC_GE; // [0,1] == BOOL (!)
490 static const TypeInt *BYTE;
491 static const TypeInt *UBYTE;
492 static const TypeInt *CHAR;
493 static const TypeInt *SHORT;
494 static const TypeInt *POS;
495 static const TypeInt *POS1;
496 static const TypeInt *INT;
497 static const TypeInt *SYMINT; // symmetric range [-max_jint..max_jint]
498 #ifndef PRODUCT
499 virtual void dump2( Dict &d, uint depth, outputStream *st ) const;
500 #endif
501 };
504 //------------------------------TypeLong---------------------------------------
505 // Class of long integer ranges, the set of integers between a lower bound and
506 // an upper bound, inclusive.
507 class TypeLong : public Type {
508 TypeLong( jlong lo, jlong hi, int w );
509 public:
510 virtual bool eq( const Type *t ) const;
511 virtual int hash() const; // Type specific hashing
512 virtual bool singleton(void) const; // TRUE if type is a singleton
513 virtual bool empty(void) const; // TRUE if type is vacuous
514 public:
515 const jlong _lo, _hi; // Lower bound, upper bound
516 const short _widen; // Limit on times we widen this sucker
518 static const TypeLong *make(jlong lo);
519 // must always specify w
520 static const TypeLong *make(jlong lo, jlong hi, int w);
522 // Check for single integer
523 int is_con() const { return _lo==_hi; }
524 bool is_con(int i) const { return is_con() && _lo == i; }
525 jlong get_con() const { assert( is_con(), "" ); return _lo; }
527 virtual bool is_finite() const; // Has a finite value
529 virtual const Type *xmeet( const Type *t ) const;
530 virtual const Type *xdual() const; // Compute dual right now.
531 virtual const Type *widen( const Type *t, const Type* limit_type ) const;
532 virtual const Type *narrow( const Type *t ) const;
533 // Do not kill _widen bits.
534 virtual const Type *filter( const Type *kills ) const;
535 // Convenience common pre-built types.
536 static const TypeLong *MINUS_1;
537 static const TypeLong *ZERO;
538 static const TypeLong *ONE;
539 static const TypeLong *POS;
540 static const TypeLong *LONG;
541 static const TypeLong *INT; // 32-bit subrange [min_jint..max_jint]
542 static const TypeLong *UINT; // 32-bit unsigned [0..max_juint]
543 #ifndef PRODUCT
544 virtual void dump2( Dict &d, uint, outputStream *st ) const;// Specialized per-Type dumping
545 #endif
546 };
548 //------------------------------TypeTuple--------------------------------------
549 // Class of Tuple Types, essentially type collections for function signatures
550 // and class layouts. It happens to also be a fast cache for the HotSpot
551 // signature types.
552 class TypeTuple : public Type {
553 TypeTuple( uint cnt, const Type **fields ) : Type(Tuple), _cnt(cnt), _fields(fields) { }
554 public:
555 virtual bool eq( const Type *t ) const;
556 virtual int hash() const; // Type specific hashing
557 virtual bool singleton(void) const; // TRUE if type is a singleton
558 virtual bool empty(void) const; // TRUE if type is vacuous
560 public:
561 const uint _cnt; // Count of fields
562 const Type ** const _fields; // Array of field types
564 // Accessors:
565 uint cnt() const { return _cnt; }
566 const Type* field_at(uint i) const {
567 assert(i < _cnt, "oob");
568 return _fields[i];
569 }
570 void set_field_at(uint i, const Type* t) {
571 assert(i < _cnt, "oob");
572 _fields[i] = t;
573 }
575 static const TypeTuple *make( uint cnt, const Type **fields );
576 static const TypeTuple *make_range(ciSignature *sig);
577 static const TypeTuple *make_domain(ciInstanceKlass* recv, ciSignature *sig);
579 // Subroutine call type with space allocated for argument types
580 static const Type **fields( uint arg_cnt );
582 virtual const Type *xmeet( const Type *t ) const;
583 virtual const Type *xdual() const; // Compute dual right now.
584 // Convenience common pre-built types.
585 static const TypeTuple *IFBOTH;
586 static const TypeTuple *IFFALSE;
587 static const TypeTuple *IFTRUE;
588 static const TypeTuple *IFNEITHER;
589 static const TypeTuple *LOOPBODY;
590 static const TypeTuple *MEMBAR;
591 static const TypeTuple *STORECONDITIONAL;
592 static const TypeTuple *START_I2C;
593 static const TypeTuple *INT_PAIR;
594 static const TypeTuple *LONG_PAIR;
595 static const TypeTuple *INT_CC_PAIR;
596 static const TypeTuple *LONG_CC_PAIR;
597 #ifndef PRODUCT
598 virtual void dump2( Dict &d, uint, outputStream *st ) const; // Specialized per-Type dumping
599 #endif
600 };
602 //------------------------------TypeAry----------------------------------------
603 // Class of Array Types
604 class TypeAry : public Type {
605 TypeAry(const Type* elem, const TypeInt* size, bool stable) : Type(Array),
606 _elem(elem), _size(size), _stable(stable) {}
607 public:
608 virtual bool eq( const Type *t ) const;
609 virtual int hash() const; // Type specific hashing
610 virtual bool singleton(void) const; // TRUE if type is a singleton
611 virtual bool empty(void) const; // TRUE if type is vacuous
613 private:
614 const Type *_elem; // Element type of array
615 const TypeInt *_size; // Elements in array
616 const bool _stable; // Are elements @Stable?
617 friend class TypeAryPtr;
619 public:
620 static const TypeAry* make(const Type* elem, const TypeInt* size, bool stable = false);
622 virtual const Type *xmeet( const Type *t ) const;
623 virtual const Type *xdual() const; // Compute dual right now.
624 bool ary_must_be_exact() const; // true if arrays of such are never generic
625 #ifdef ASSERT
626 // One type is interface, the other is oop
627 virtual bool interface_vs_oop(const Type *t) const;
628 #endif
629 #ifndef PRODUCT
630 virtual void dump2( Dict &d, uint, outputStream *st ) const; // Specialized per-Type dumping
631 #endif
632 };
634 //------------------------------TypeVect---------------------------------------
635 // Class of Vector Types
636 class TypeVect : public Type {
637 const Type* _elem; // Vector's element type
638 const uint _length; // Elements in vector (power of 2)
640 protected:
641 TypeVect(TYPES t, const Type* elem, uint length) : Type(t),
642 _elem(elem), _length(length) {}
644 public:
645 const Type* element_type() const { return _elem; }
646 BasicType element_basic_type() const { return _elem->array_element_basic_type(); }
647 uint length() const { return _length; }
648 uint length_in_bytes() const {
649 return _length * type2aelembytes(element_basic_type());
650 }
652 virtual bool eq(const Type *t) const;
653 virtual int hash() const; // Type specific hashing
654 virtual bool singleton(void) const; // TRUE if type is a singleton
655 virtual bool empty(void) const; // TRUE if type is vacuous
657 static const TypeVect *make(const BasicType elem_bt, uint length) {
658 // Use bottom primitive type.
659 return make(get_const_basic_type(elem_bt), length);
660 }
661 // Used directly by Replicate nodes to construct singleton vector.
662 static const TypeVect *make(const Type* elem, uint length);
664 virtual const Type *xmeet( const Type *t) const;
665 virtual const Type *xdual() const; // Compute dual right now.
667 static const TypeVect *VECTS;
668 static const TypeVect *VECTD;
669 static const TypeVect *VECTX;
670 static const TypeVect *VECTY;
672 #ifndef PRODUCT
673 virtual void dump2(Dict &d, uint, outputStream *st) const; // Specialized per-Type dumping
674 #endif
675 };
677 class TypeVectS : public TypeVect {
678 friend class TypeVect;
679 TypeVectS(const Type* elem, uint length) : TypeVect(VectorS, elem, length) {}
680 };
682 class TypeVectD : public TypeVect {
683 friend class TypeVect;
684 TypeVectD(const Type* elem, uint length) : TypeVect(VectorD, elem, length) {}
685 };
687 class TypeVectX : public TypeVect {
688 friend class TypeVect;
689 TypeVectX(const Type* elem, uint length) : TypeVect(VectorX, elem, length) {}
690 };
692 class TypeVectY : public TypeVect {
693 friend class TypeVect;
694 TypeVectY(const Type* elem, uint length) : TypeVect(VectorY, elem, length) {}
695 };
697 //------------------------------TypePtr----------------------------------------
698 // Class of machine Pointer Types: raw data, instances or arrays.
699 // If the _base enum is AnyPtr, then this refers to all of the above.
700 // Otherwise the _base will indicate which subset of pointers is affected,
701 // and the class will be inherited from.
702 class TypePtr : public Type {
703 friend class TypeNarrowPtr;
704 public:
705 enum PTR { TopPTR, AnyNull, Constant, Null, NotNull, BotPTR, lastPTR };
706 protected:
707 TypePtr( TYPES t, PTR ptr, int offset ) : Type(t), _ptr(ptr), _offset(offset) {}
708 virtual bool eq( const Type *t ) const;
709 virtual int hash() const; // Type specific hashing
710 static const PTR ptr_meet[lastPTR][lastPTR];
711 static const PTR ptr_dual[lastPTR];
712 static const char * const ptr_msg[lastPTR];
714 public:
715 const int _offset; // Offset into oop, with TOP & BOT
716 const PTR _ptr; // Pointer equivalence class
718 const int offset() const { return _offset; }
719 const PTR ptr() const { return _ptr; }
721 static const TypePtr *make( TYPES t, PTR ptr, int offset );
723 // Return a 'ptr' version of this type
724 virtual const Type *cast_to_ptr_type(PTR ptr) const;
726 virtual intptr_t get_con() const;
728 int xadd_offset( intptr_t offset ) const;
729 virtual const TypePtr *add_offset( intptr_t offset ) const;
731 virtual bool singleton(void) const; // TRUE if type is a singleton
732 virtual bool empty(void) const; // TRUE if type is vacuous
733 virtual const Type *xmeet( const Type *t ) const;
734 int meet_offset( int offset ) const;
735 int dual_offset( ) const;
736 virtual const Type *xdual() const; // Compute dual right now.
738 // meet, dual and join over pointer equivalence sets
739 PTR meet_ptr( const PTR in_ptr ) const { return ptr_meet[in_ptr][ptr()]; }
740 PTR dual_ptr() const { return ptr_dual[ptr()]; }
742 // This is textually confusing unless one recalls that
743 // join(t) == dual()->meet(t->dual())->dual().
744 PTR join_ptr( const PTR in_ptr ) const {
745 return ptr_dual[ ptr_meet[ ptr_dual[in_ptr] ] [ dual_ptr() ] ];
746 }
748 // Tests for relation to centerline of type lattice:
749 static bool above_centerline(PTR ptr) { return (ptr <= AnyNull); }
750 static bool below_centerline(PTR ptr) { return (ptr >= NotNull); }
751 // Convenience common pre-built types.
752 static const TypePtr *NULL_PTR;
753 static const TypePtr *NOTNULL;
754 static const TypePtr *BOTTOM;
755 #ifndef PRODUCT
756 virtual void dump2( Dict &d, uint depth, outputStream *st ) const;
757 #endif
758 };
760 //------------------------------TypeRawPtr-------------------------------------
761 // Class of raw pointers, pointers to things other than Oops. Examples
762 // include the stack pointer, top of heap, card-marking area, handles, etc.
763 class TypeRawPtr : public TypePtr {
764 protected:
765 TypeRawPtr( PTR ptr, address bits ) : TypePtr(RawPtr,ptr,0), _bits(bits){}
766 public:
767 virtual bool eq( const Type *t ) const;
768 virtual int hash() const; // Type specific hashing
770 const address _bits; // Constant value, if applicable
772 static const TypeRawPtr *make( PTR ptr );
773 static const TypeRawPtr *make( address bits );
775 // Return a 'ptr' version of this type
776 virtual const Type *cast_to_ptr_type(PTR ptr) const;
778 virtual intptr_t get_con() const;
780 virtual const TypePtr *add_offset( intptr_t offset ) const;
782 virtual const Type *xmeet( const Type *t ) const;
783 virtual const Type *xdual() const; // Compute dual right now.
784 // Convenience common pre-built types.
785 static const TypeRawPtr *BOTTOM;
786 static const TypeRawPtr *NOTNULL;
787 #ifndef PRODUCT
788 virtual void dump2( Dict &d, uint depth, outputStream *st ) const;
789 #endif
790 };
792 //------------------------------TypeOopPtr-------------------------------------
793 // Some kind of oop (Java pointer), either klass or instance or array.
794 class TypeOopPtr : public TypePtr {
795 protected:
796 TypeOopPtr(TYPES t, PTR ptr, ciKlass* k, bool xk, ciObject* o, int offset, int instance_id, const TypeOopPtr* speculative);
797 public:
798 virtual bool eq( const Type *t ) const;
799 virtual int hash() const; // Type specific hashing
800 virtual bool singleton(void) const; // TRUE if type is a singleton
801 enum {
802 InstanceTop = -1, // undefined instance
803 InstanceBot = 0 // any possible instance
804 };
805 protected:
807 // Oop is NULL, unless this is a constant oop.
808 ciObject* _const_oop; // Constant oop
809 // If _klass is NULL, then so is _sig. This is an unloaded klass.
810 ciKlass* _klass; // Klass object
811 // Does the type exclude subclasses of the klass? (Inexact == polymorphic.)
812 bool _klass_is_exact;
813 bool _is_ptr_to_narrowoop;
814 bool _is_ptr_to_narrowklass;
815 bool _is_ptr_to_boxed_value;
817 // If not InstanceTop or InstanceBot, indicates that this is
818 // a particular instance of this type which is distinct.
819 // This is the the node index of the allocation node creating this instance.
820 int _instance_id;
822 // Extra type information profiling gave us. We propagate it the
823 // same way the rest of the type info is propagated. If we want to
824 // use it, then we have to emit a guard: this part of the type is
825 // not something we know but something we speculate about the type.
826 const TypeOopPtr* _speculative;
828 static const TypeOopPtr* make_from_klass_common(ciKlass* klass, bool klass_change, bool try_for_exact);
830 int dual_instance_id() const;
831 int meet_instance_id(int uid) const;
833 // utility methods to work on the speculative part of the type
834 const TypeOopPtr* dual_speculative() const;
835 const TypeOopPtr* meet_speculative(const TypeOopPtr* other) const;
836 bool eq_speculative(const TypeOopPtr* other) const;
837 int hash_speculative() const;
838 const TypeOopPtr* add_offset_speculative(intptr_t offset) const;
839 #ifndef PRODUCT
840 void dump_speculative(outputStream *st) const;
841 #endif
843 public:
844 // Creates a type given a klass. Correctly handles multi-dimensional arrays
845 // Respects UseUniqueSubclasses.
846 // If the klass is final, the resulting type will be exact.
847 static const TypeOopPtr* make_from_klass(ciKlass* klass) {
848 return make_from_klass_common(klass, true, false);
849 }
850 // Same as before, but will produce an exact type, even if
851 // the klass is not final, as long as it has exactly one implementation.
852 static const TypeOopPtr* make_from_klass_unique(ciKlass* klass) {
853 return make_from_klass_common(klass, true, true);
854 }
855 // Same as before, but does not respects UseUniqueSubclasses.
856 // Use this only for creating array element types.
857 static const TypeOopPtr* make_from_klass_raw(ciKlass* klass) {
858 return make_from_klass_common(klass, false, false);
859 }
860 // Creates a singleton type given an object.
861 // If the object cannot be rendered as a constant,
862 // may return a non-singleton type.
863 // If require_constant, produce a NULL if a singleton is not possible.
864 static const TypeOopPtr* make_from_constant(ciObject* o,
865 bool require_constant = false,
866 bool not_null_elements = false);
868 // Make a generic (unclassed) pointer to an oop.
869 static const TypeOopPtr* make(PTR ptr, int offset, int instance_id, const TypeOopPtr* speculative);
871 ciObject* const_oop() const { return _const_oop; }
872 virtual ciKlass* klass() const { return _klass; }
873 bool klass_is_exact() const { return _klass_is_exact; }
875 // Returns true if this pointer points at memory which contains a
876 // compressed oop references.
877 bool is_ptr_to_narrowoop_nv() const { return _is_ptr_to_narrowoop; }
878 bool is_ptr_to_narrowklass_nv() const { return _is_ptr_to_narrowklass; }
879 bool is_ptr_to_boxed_value() const { return _is_ptr_to_boxed_value; }
880 bool is_known_instance() const { return _instance_id > 0; }
881 int instance_id() const { return _instance_id; }
882 bool is_known_instance_field() const { return is_known_instance() && _offset >= 0; }
883 const TypeOopPtr* speculative() const { return _speculative; }
885 virtual intptr_t get_con() const;
887 virtual const Type *cast_to_ptr_type(PTR ptr) const;
889 virtual const Type *cast_to_exactness(bool klass_is_exact) const;
891 virtual const TypeOopPtr *cast_to_instance_id(int instance_id) const;
893 // corresponding pointer to klass, for a given instance
894 const TypeKlassPtr* as_klass_type() const;
896 virtual const TypePtr *add_offset( intptr_t offset ) const;
897 // Return same type without a speculative part
898 virtual const TypeOopPtr* remove_speculative() const;
900 virtual const Type *xmeet(const Type *t) const;
901 virtual const Type *xdual() const; // Compute dual right now.
902 // the core of the computation of the meet for TypeOopPtr and for its subclasses
903 virtual const Type *xmeet_helper(const Type *t) const;
905 // Do not allow interface-vs.-noninterface joins to collapse to top.
906 virtual const Type *filter( const Type *kills ) const;
908 // Convenience common pre-built type.
909 static const TypeOopPtr *BOTTOM;
910 #ifndef PRODUCT
911 virtual void dump2( Dict &d, uint depth, outputStream *st ) const;
912 #endif
914 // Return the speculative type if any
915 ciKlass* speculative_type() const {
916 if (_speculative != NULL) {
917 const TypeOopPtr* speculative = _speculative->join(this)->is_oopptr();
918 if (speculative->klass_is_exact()) {
919 return speculative->klass();
920 }
921 }
922 return NULL;
923 }
924 };
926 //------------------------------TypeInstPtr------------------------------------
927 // Class of Java object pointers, pointing either to non-array Java instances
928 // or to a Klass* (including array klasses).
929 class TypeInstPtr : public TypeOopPtr {
930 TypeInstPtr(PTR ptr, ciKlass* k, bool xk, ciObject* o, int offset, int instance_id, const TypeOopPtr* speculative);
931 virtual bool eq( const Type *t ) const;
932 virtual int hash() const; // Type specific hashing
934 ciSymbol* _name; // class name
936 public:
937 ciSymbol* name() const { return _name; }
939 bool is_loaded() const { return _klass->is_loaded(); }
941 // Make a pointer to a constant oop.
942 static const TypeInstPtr *make(ciObject* o) {
943 return make(TypePtr::Constant, o->klass(), true, o, 0, InstanceBot);
944 }
945 // Make a pointer to a constant oop with offset.
946 static const TypeInstPtr *make(ciObject* o, int offset) {
947 return make(TypePtr::Constant, o->klass(), true, o, offset, InstanceBot);
948 }
950 // Make a pointer to some value of type klass.
951 static const TypeInstPtr *make(PTR ptr, ciKlass* klass) {
952 return make(ptr, klass, false, NULL, 0, InstanceBot);
953 }
955 // Make a pointer to some non-polymorphic value of exactly type klass.
956 static const TypeInstPtr *make_exact(PTR ptr, ciKlass* klass) {
957 return make(ptr, klass, true, NULL, 0, InstanceBot);
958 }
960 // Make a pointer to some value of type klass with offset.
961 static const TypeInstPtr *make(PTR ptr, ciKlass* klass, int offset) {
962 return make(ptr, klass, false, NULL, offset, InstanceBot);
963 }
965 // Make a pointer to an oop.
966 static const TypeInstPtr *make(PTR ptr, ciKlass* k, bool xk, ciObject* o, int offset, int instance_id = InstanceBot, const TypeOopPtr* speculative = NULL);
968 /** Create constant type for a constant boxed value */
969 const Type* get_const_boxed_value() const;
971 // If this is a java.lang.Class constant, return the type for it or NULL.
972 // Pass to Type::get_const_type to turn it to a type, which will usually
973 // be a TypeInstPtr, but may also be a TypeInt::INT for int.class, etc.
974 ciType* java_mirror_type() const;
976 virtual const Type *cast_to_ptr_type(PTR ptr) const;
978 virtual const Type *cast_to_exactness(bool klass_is_exact) const;
980 virtual const TypeOopPtr *cast_to_instance_id(int instance_id) const;
982 virtual const TypePtr *add_offset( intptr_t offset ) const;
983 // Return same type without a speculative part
984 virtual const TypeOopPtr* remove_speculative() const;
986 // the core of the computation of the meet of 2 types
987 virtual const Type *xmeet_helper(const Type *t) const;
988 virtual const TypeInstPtr *xmeet_unloaded( const TypeInstPtr *t ) const;
989 virtual const Type *xdual() const; // Compute dual right now.
991 // Convenience common pre-built types.
992 static const TypeInstPtr *NOTNULL;
993 static const TypeInstPtr *BOTTOM;
994 static const TypeInstPtr *MIRROR;
995 static const TypeInstPtr *MARK;
996 static const TypeInstPtr *KLASS;
997 #ifndef PRODUCT
998 virtual void dump2( Dict &d, uint depth, outputStream *st ) const; // Specialized per-Type dumping
999 #endif
1000 };
1002 //------------------------------TypeAryPtr-------------------------------------
1003 // Class of Java array pointers
1004 class TypeAryPtr : public TypeOopPtr {
1005 TypeAryPtr( PTR ptr, ciObject* o, const TypeAry *ary, ciKlass* k, bool xk,
1006 int offset, int instance_id, bool is_autobox_cache, const TypeOopPtr* speculative)
1007 : TypeOopPtr(AryPtr,ptr,k,xk,o,offset, instance_id, speculative),
1008 _ary(ary),
1009 _is_autobox_cache(is_autobox_cache)
1010 {
1011 #ifdef ASSERT
1012 if (k != NULL) {
1013 // Verify that specified klass and TypeAryPtr::klass() follow the same rules.
1014 ciKlass* ck = compute_klass(true);
1015 if (k != ck) {
1016 this->dump(); tty->cr();
1017 tty->print(" k: ");
1018 k->print(); tty->cr();
1019 tty->print("ck: ");
1020 if (ck != NULL) ck->print();
1021 else tty->print("<NULL>");
1022 tty->cr();
1023 assert(false, "unexpected TypeAryPtr::_klass");
1024 }
1025 }
1026 #endif
1027 }
1028 virtual bool eq( const Type *t ) const;
1029 virtual int hash() const; // Type specific hashing
1030 const TypeAry *_ary; // Array we point into
1031 const bool _is_autobox_cache;
1033 ciKlass* compute_klass(DEBUG_ONLY(bool verify = false)) const;
1035 public:
1036 // Accessors
1037 ciKlass* klass() const;
1038 const TypeAry* ary() const { return _ary; }
1039 const Type* elem() const { return _ary->_elem; }
1040 const TypeInt* size() const { return _ary->_size; }
1041 bool is_stable() const { return _ary->_stable; }
1043 bool is_autobox_cache() const { return _is_autobox_cache; }
1045 static const TypeAryPtr *make( PTR ptr, const TypeAry *ary, ciKlass* k, bool xk, int offset, int instance_id = InstanceBot, const TypeOopPtr* speculative = NULL);
1046 // Constant pointer to array
1047 static const TypeAryPtr *make( PTR ptr, ciObject* o, const TypeAry *ary, ciKlass* k, bool xk, int offset, int instance_id = InstanceBot, const TypeOopPtr* speculative = NULL, bool is_autobox_cache = false);
1049 // Return a 'ptr' version of this type
1050 virtual const Type *cast_to_ptr_type(PTR ptr) const;
1052 virtual const Type *cast_to_exactness(bool klass_is_exact) const;
1054 virtual const TypeOopPtr *cast_to_instance_id(int instance_id) const;
1056 virtual const TypeAryPtr* cast_to_size(const TypeInt* size) const;
1057 virtual const TypeInt* narrow_size_type(const TypeInt* size) const;
1059 virtual bool empty(void) const; // TRUE if type is vacuous
1060 virtual const TypePtr *add_offset( intptr_t offset ) const;
1061 // Return same type without a speculative part
1062 virtual const TypeOopPtr* remove_speculative() const;
1064 // the core of the computation of the meet of 2 types
1065 virtual const Type *xmeet_helper(const Type *t) const;
1066 virtual const Type *xdual() const; // Compute dual right now.
1068 const TypeAryPtr* cast_to_stable(bool stable, int stable_dimension = 1) const;
1069 int stable_dimension() const;
1071 // Convenience common pre-built types.
1072 static const TypeAryPtr *RANGE;
1073 static const TypeAryPtr *OOPS;
1074 static const TypeAryPtr *NARROWOOPS;
1075 static const TypeAryPtr *BYTES;
1076 static const TypeAryPtr *SHORTS;
1077 static const TypeAryPtr *CHARS;
1078 static const TypeAryPtr *INTS;
1079 static const TypeAryPtr *LONGS;
1080 static const TypeAryPtr *FLOATS;
1081 static const TypeAryPtr *DOUBLES;
1082 // selects one of the above:
1083 static const TypeAryPtr *get_array_body_type(BasicType elem) {
1084 assert((uint)elem <= T_CONFLICT && _array_body_type[elem] != NULL, "bad elem type");
1085 return _array_body_type[elem];
1086 }
1087 static const TypeAryPtr *_array_body_type[T_CONFLICT+1];
1088 // sharpen the type of an int which is used as an array size
1089 #ifdef ASSERT
1090 // One type is interface, the other is oop
1091 virtual bool interface_vs_oop(const Type *t) const;
1092 #endif
1093 #ifndef PRODUCT
1094 virtual void dump2( Dict &d, uint depth, outputStream *st ) const; // Specialized per-Type dumping
1095 #endif
1096 };
1098 //------------------------------TypeMetadataPtr-------------------------------------
1099 // Some kind of metadata, either Method*, MethodData* or CPCacheOop
1100 class TypeMetadataPtr : public TypePtr {
1101 protected:
1102 TypeMetadataPtr(PTR ptr, ciMetadata* metadata, int offset);
1103 public:
1104 virtual bool eq( const Type *t ) const;
1105 virtual int hash() const; // Type specific hashing
1106 virtual bool singleton(void) const; // TRUE if type is a singleton
1108 private:
1109 ciMetadata* _metadata;
1111 public:
1112 static const TypeMetadataPtr* make(PTR ptr, ciMetadata* m, int offset);
1114 static const TypeMetadataPtr* make(ciMethod* m);
1115 static const TypeMetadataPtr* make(ciMethodData* m);
1117 ciMetadata* metadata() const { return _metadata; }
1119 virtual const Type *cast_to_ptr_type(PTR ptr) const;
1121 virtual const TypePtr *add_offset( intptr_t offset ) const;
1123 virtual const Type *xmeet( const Type *t ) const;
1124 virtual const Type *xdual() const; // Compute dual right now.
1126 virtual intptr_t get_con() const;
1128 // Do not allow interface-vs.-noninterface joins to collapse to top.
1129 virtual const Type *filter( const Type *kills ) const;
1131 // Convenience common pre-built types.
1132 static const TypeMetadataPtr *BOTTOM;
1134 #ifndef PRODUCT
1135 virtual void dump2( Dict &d, uint depth, outputStream *st ) const;
1136 #endif
1137 };
1139 //------------------------------TypeKlassPtr-----------------------------------
1140 // Class of Java Klass pointers
1141 class TypeKlassPtr : public TypePtr {
1142 TypeKlassPtr( PTR ptr, ciKlass* klass, int offset );
1144 public:
1145 virtual bool eq( const Type *t ) const;
1146 virtual int hash() const; // Type specific hashing
1147 virtual bool singleton(void) const; // TRUE if type is a singleton
1148 private:
1150 static const TypeKlassPtr* make_from_klass_common(ciKlass* klass, bool klass_change, bool try_for_exact);
1152 ciKlass* _klass;
1154 // Does the type exclude subclasses of the klass? (Inexact == polymorphic.)
1155 bool _klass_is_exact;
1157 public:
1158 ciSymbol* name() const { return klass()->name(); }
1160 ciKlass* klass() const { return _klass; }
1161 bool klass_is_exact() const { return _klass_is_exact; }
1163 bool is_loaded() const { return klass()->is_loaded(); }
1165 // Creates a type given a klass. Correctly handles multi-dimensional arrays
1166 // Respects UseUniqueSubclasses.
1167 // If the klass is final, the resulting type will be exact.
1168 static const TypeKlassPtr* make_from_klass(ciKlass* klass) {
1169 return make_from_klass_common(klass, true, false);
1170 }
1171 // Same as before, but will produce an exact type, even if
1172 // the klass is not final, as long as it has exactly one implementation.
1173 static const TypeKlassPtr* make_from_klass_unique(ciKlass* klass) {
1174 return make_from_klass_common(klass, true, true);
1175 }
1176 // Same as before, but does not respects UseUniqueSubclasses.
1177 // Use this only for creating array element types.
1178 static const TypeKlassPtr* make_from_klass_raw(ciKlass* klass) {
1179 return make_from_klass_common(klass, false, false);
1180 }
1182 // Make a generic (unclassed) pointer to metadata.
1183 static const TypeKlassPtr* make(PTR ptr, int offset);
1185 // ptr to klass 'k'
1186 static const TypeKlassPtr *make( ciKlass* k ) { return make( TypePtr::Constant, k, 0); }
1187 // ptr to klass 'k' with offset
1188 static const TypeKlassPtr *make( ciKlass* k, int offset ) { return make( TypePtr::Constant, k, offset); }
1189 // ptr to klass 'k' or sub-klass
1190 static const TypeKlassPtr *make( PTR ptr, ciKlass* k, int offset);
1192 virtual const Type *cast_to_ptr_type(PTR ptr) const;
1194 virtual const Type *cast_to_exactness(bool klass_is_exact) const;
1196 // corresponding pointer to instance, for a given class
1197 const TypeOopPtr* as_instance_type() const;
1199 virtual const TypePtr *add_offset( intptr_t offset ) const;
1200 virtual const Type *xmeet( const Type *t ) const;
1201 virtual const Type *xdual() const; // Compute dual right now.
1203 virtual intptr_t get_con() const;
1205 // Convenience common pre-built types.
1206 static const TypeKlassPtr* OBJECT; // Not-null object klass or below
1207 static const TypeKlassPtr* OBJECT_OR_NULL; // Maybe-null version of same
1208 #ifndef PRODUCT
1209 virtual void dump2( Dict &d, uint depth, outputStream *st ) const; // Specialized per-Type dumping
1210 #endif
1211 };
1213 class TypeNarrowPtr : public Type {
1214 protected:
1215 const TypePtr* _ptrtype; // Could be TypePtr::NULL_PTR
1217 TypeNarrowPtr(TYPES t, const TypePtr* ptrtype): _ptrtype(ptrtype),
1218 Type(t) {
1219 assert(ptrtype->offset() == 0 ||
1220 ptrtype->offset() == OffsetBot ||
1221 ptrtype->offset() == OffsetTop, "no real offsets");
1222 }
1224 virtual const TypeNarrowPtr *isa_same_narrowptr(const Type *t) const = 0;
1225 virtual const TypeNarrowPtr *is_same_narrowptr(const Type *t) const = 0;
1226 virtual const TypeNarrowPtr *make_same_narrowptr(const TypePtr *t) const = 0;
1227 virtual const TypeNarrowPtr *make_hash_same_narrowptr(const TypePtr *t) const = 0;
1228 public:
1229 virtual bool eq( const Type *t ) const;
1230 virtual int hash() const; // Type specific hashing
1231 virtual bool singleton(void) const; // TRUE if type is a singleton
1233 virtual const Type *xmeet( const Type *t ) const;
1234 virtual const Type *xdual() const; // Compute dual right now.
1236 virtual intptr_t get_con() const;
1238 // Do not allow interface-vs.-noninterface joins to collapse to top.
1239 virtual const Type *filter( const Type *kills ) const;
1241 virtual bool empty(void) const; // TRUE if type is vacuous
1243 // returns the equivalent ptr type for this compressed pointer
1244 const TypePtr *get_ptrtype() const {
1245 return _ptrtype;
1246 }
1248 #ifndef PRODUCT
1249 virtual void dump2( Dict &d, uint depth, outputStream *st ) const;
1250 #endif
1251 };
1253 //------------------------------TypeNarrowOop----------------------------------
1254 // A compressed reference to some kind of Oop. This type wraps around
1255 // a preexisting TypeOopPtr and forwards most of it's operations to
1256 // the underlying type. It's only real purpose is to track the
1257 // oopness of the compressed oop value when we expose the conversion
1258 // between the normal and the compressed form.
1259 class TypeNarrowOop : public TypeNarrowPtr {
1260 protected:
1261 TypeNarrowOop( const TypePtr* ptrtype): TypeNarrowPtr(NarrowOop, ptrtype) {
1262 }
1264 virtual const TypeNarrowPtr *isa_same_narrowptr(const Type *t) const {
1265 return t->isa_narrowoop();
1266 }
1268 virtual const TypeNarrowPtr *is_same_narrowptr(const Type *t) const {
1269 return t->is_narrowoop();
1270 }
1272 virtual const TypeNarrowPtr *make_same_narrowptr(const TypePtr *t) const {
1273 return new TypeNarrowOop(t);
1274 }
1276 virtual const TypeNarrowPtr *make_hash_same_narrowptr(const TypePtr *t) const {
1277 return (const TypeNarrowPtr*)((new TypeNarrowOop(t))->hashcons());
1278 }
1280 public:
1282 static const TypeNarrowOop *make( const TypePtr* type);
1284 static const TypeNarrowOop* make_from_constant(ciObject* con, bool require_constant = false) {
1285 return make(TypeOopPtr::make_from_constant(con, require_constant));
1286 }
1288 static const TypeNarrowOop *BOTTOM;
1289 static const TypeNarrowOop *NULL_PTR;
1291 #ifndef PRODUCT
1292 virtual void dump2( Dict &d, uint depth, outputStream *st ) const;
1293 #endif
1294 };
1296 //------------------------------TypeNarrowKlass----------------------------------
1297 // A compressed reference to klass pointer. This type wraps around a
1298 // preexisting TypeKlassPtr and forwards most of it's operations to
1299 // the underlying type.
1300 class TypeNarrowKlass : public TypeNarrowPtr {
1301 protected:
1302 TypeNarrowKlass( const TypePtr* ptrtype): TypeNarrowPtr(NarrowKlass, ptrtype) {
1303 }
1305 virtual const TypeNarrowPtr *isa_same_narrowptr(const Type *t) const {
1306 return t->isa_narrowklass();
1307 }
1309 virtual const TypeNarrowPtr *is_same_narrowptr(const Type *t) const {
1310 return t->is_narrowklass();
1311 }
1313 virtual const TypeNarrowPtr *make_same_narrowptr(const TypePtr *t) const {
1314 return new TypeNarrowKlass(t);
1315 }
1317 virtual const TypeNarrowPtr *make_hash_same_narrowptr(const TypePtr *t) const {
1318 return (const TypeNarrowPtr*)((new TypeNarrowKlass(t))->hashcons());
1319 }
1321 public:
1322 static const TypeNarrowKlass *make( const TypePtr* type);
1324 // static const TypeNarrowKlass *BOTTOM;
1325 static const TypeNarrowKlass *NULL_PTR;
1327 #ifndef PRODUCT
1328 virtual void dump2( Dict &d, uint depth, outputStream *st ) const;
1329 #endif
1330 };
1332 //------------------------------TypeFunc---------------------------------------
1333 // Class of Array Types
1334 class TypeFunc : public Type {
1335 TypeFunc( const TypeTuple *domain, const TypeTuple *range ) : Type(Function), _domain(domain), _range(range) {}
1336 virtual bool eq( const Type *t ) const;
1337 virtual int hash() const; // Type specific hashing
1338 virtual bool singleton(void) const; // TRUE if type is a singleton
1339 virtual bool empty(void) const; // TRUE if type is vacuous
1340 public:
1341 // Constants are shared among ADLC and VM
1342 enum { Control = AdlcVMDeps::Control,
1343 I_O = AdlcVMDeps::I_O,
1344 Memory = AdlcVMDeps::Memory,
1345 FramePtr = AdlcVMDeps::FramePtr,
1346 ReturnAdr = AdlcVMDeps::ReturnAdr,
1347 Parms = AdlcVMDeps::Parms
1348 };
1350 const TypeTuple* const _domain; // Domain of inputs
1351 const TypeTuple* const _range; // Range of results
1353 // Accessors:
1354 const TypeTuple* domain() const { return _domain; }
1355 const TypeTuple* range() const { return _range; }
1357 static const TypeFunc *make(ciMethod* method);
1358 static const TypeFunc *make(ciSignature signature, const Type* extra);
1359 static const TypeFunc *make(const TypeTuple* domain, const TypeTuple* range);
1361 virtual const Type *xmeet( const Type *t ) const;
1362 virtual const Type *xdual() const; // Compute dual right now.
1364 BasicType return_type() const;
1366 #ifndef PRODUCT
1367 virtual void dump2( Dict &d, uint depth, outputStream *st ) const; // Specialized per-Type dumping
1368 #endif
1369 // Convenience common pre-built types.
1370 };
1372 //------------------------------accessors--------------------------------------
1373 inline bool Type::is_ptr_to_narrowoop() const {
1374 #ifdef _LP64
1375 return (isa_oopptr() != NULL && is_oopptr()->is_ptr_to_narrowoop_nv());
1376 #else
1377 return false;
1378 #endif
1379 }
1381 inline bool Type::is_ptr_to_narrowklass() const {
1382 #ifdef _LP64
1383 return (isa_oopptr() != NULL && is_oopptr()->is_ptr_to_narrowklass_nv());
1384 #else
1385 return false;
1386 #endif
1387 }
1389 inline float Type::getf() const {
1390 assert( _base == FloatCon, "Not a FloatCon" );
1391 return ((TypeF*)this)->_f;
1392 }
1394 inline double Type::getd() const {
1395 assert( _base == DoubleCon, "Not a DoubleCon" );
1396 return ((TypeD*)this)->_d;
1397 }
1399 inline const TypeInt *Type::is_int() const {
1400 assert( _base == Int, "Not an Int" );
1401 return (TypeInt*)this;
1402 }
1404 inline const TypeInt *Type::isa_int() const {
1405 return ( _base == Int ? (TypeInt*)this : NULL);
1406 }
1408 inline const TypeLong *Type::is_long() const {
1409 assert( _base == Long, "Not a Long" );
1410 return (TypeLong*)this;
1411 }
1413 inline const TypeLong *Type::isa_long() const {
1414 return ( _base == Long ? (TypeLong*)this : NULL);
1415 }
1417 inline const TypeF *Type::isa_float() const {
1418 return ((_base == FloatTop ||
1419 _base == FloatCon ||
1420 _base == FloatBot) ? (TypeF*)this : NULL);
1421 }
1423 inline const TypeF *Type::is_float_constant() const {
1424 assert( _base == FloatCon, "Not a Float" );
1425 return (TypeF*)this;
1426 }
1428 inline const TypeF *Type::isa_float_constant() const {
1429 return ( _base == FloatCon ? (TypeF*)this : NULL);
1430 }
1432 inline const TypeD *Type::isa_double() const {
1433 return ((_base == DoubleTop ||
1434 _base == DoubleCon ||
1435 _base == DoubleBot) ? (TypeD*)this : NULL);
1436 }
1438 inline const TypeD *Type::is_double_constant() const {
1439 assert( _base == DoubleCon, "Not a Double" );
1440 return (TypeD*)this;
1441 }
1443 inline const TypeD *Type::isa_double_constant() const {
1444 return ( _base == DoubleCon ? (TypeD*)this : NULL);
1445 }
1447 inline const TypeTuple *Type::is_tuple() const {
1448 assert( _base == Tuple, "Not a Tuple" );
1449 return (TypeTuple*)this;
1450 }
1452 inline const TypeAry *Type::is_ary() const {
1453 assert( _base == Array , "Not an Array" );
1454 return (TypeAry*)this;
1455 }
1457 inline const TypeVect *Type::is_vect() const {
1458 assert( _base >= VectorS && _base <= VectorY, "Not a Vector" );
1459 return (TypeVect*)this;
1460 }
1462 inline const TypeVect *Type::isa_vect() const {
1463 return (_base >= VectorS && _base <= VectorY) ? (TypeVect*)this : NULL;
1464 }
1466 inline const TypePtr *Type::is_ptr() const {
1467 // AnyPtr is the first Ptr and KlassPtr the last, with no non-ptrs between.
1468 assert(_base >= AnyPtr && _base <= KlassPtr, "Not a pointer");
1469 return (TypePtr*)this;
1470 }
1472 inline const TypePtr *Type::isa_ptr() const {
1473 // AnyPtr is the first Ptr and KlassPtr the last, with no non-ptrs between.
1474 return (_base >= AnyPtr && _base <= KlassPtr) ? (TypePtr*)this : NULL;
1475 }
1477 inline const TypeOopPtr *Type::is_oopptr() const {
1478 // OopPtr is the first and KlassPtr the last, with no non-oops between.
1479 assert(_base >= OopPtr && _base <= AryPtr, "Not a Java pointer" ) ;
1480 return (TypeOopPtr*)this;
1481 }
1483 inline const TypeOopPtr *Type::isa_oopptr() const {
1484 // OopPtr is the first and KlassPtr the last, with no non-oops between.
1485 return (_base >= OopPtr && _base <= AryPtr) ? (TypeOopPtr*)this : NULL;
1486 }
1488 inline const TypeRawPtr *Type::isa_rawptr() const {
1489 return (_base == RawPtr) ? (TypeRawPtr*)this : NULL;
1490 }
1492 inline const TypeRawPtr *Type::is_rawptr() const {
1493 assert( _base == RawPtr, "Not a raw pointer" );
1494 return (TypeRawPtr*)this;
1495 }
1497 inline const TypeInstPtr *Type::isa_instptr() const {
1498 return (_base == InstPtr) ? (TypeInstPtr*)this : NULL;
1499 }
1501 inline const TypeInstPtr *Type::is_instptr() const {
1502 assert( _base == InstPtr, "Not an object pointer" );
1503 return (TypeInstPtr*)this;
1504 }
1506 inline const TypeAryPtr *Type::isa_aryptr() const {
1507 return (_base == AryPtr) ? (TypeAryPtr*)this : NULL;
1508 }
1510 inline const TypeAryPtr *Type::is_aryptr() const {
1511 assert( _base == AryPtr, "Not an array pointer" );
1512 return (TypeAryPtr*)this;
1513 }
1515 inline const TypeNarrowOop *Type::is_narrowoop() const {
1516 // OopPtr is the first and KlassPtr the last, with no non-oops between.
1517 assert(_base == NarrowOop, "Not a narrow oop" ) ;
1518 return (TypeNarrowOop*)this;
1519 }
1521 inline const TypeNarrowOop *Type::isa_narrowoop() const {
1522 // OopPtr is the first and KlassPtr the last, with no non-oops between.
1523 return (_base == NarrowOop) ? (TypeNarrowOop*)this : NULL;
1524 }
1526 inline const TypeNarrowKlass *Type::is_narrowklass() const {
1527 assert(_base == NarrowKlass, "Not a narrow oop" ) ;
1528 return (TypeNarrowKlass*)this;
1529 }
1531 inline const TypeNarrowKlass *Type::isa_narrowklass() const {
1532 return (_base == NarrowKlass) ? (TypeNarrowKlass*)this : NULL;
1533 }
1535 inline const TypeMetadataPtr *Type::is_metadataptr() const {
1536 // MetadataPtr is the first and CPCachePtr the last
1537 assert(_base == MetadataPtr, "Not a metadata pointer" ) ;
1538 return (TypeMetadataPtr*)this;
1539 }
1541 inline const TypeMetadataPtr *Type::isa_metadataptr() const {
1542 return (_base == MetadataPtr) ? (TypeMetadataPtr*)this : NULL;
1543 }
1545 inline const TypeKlassPtr *Type::isa_klassptr() const {
1546 return (_base == KlassPtr) ? (TypeKlassPtr*)this : NULL;
1547 }
1549 inline const TypeKlassPtr *Type::is_klassptr() const {
1550 assert( _base == KlassPtr, "Not a klass pointer" );
1551 return (TypeKlassPtr*)this;
1552 }
1554 inline const TypePtr* Type::make_ptr() const {
1555 return (_base == NarrowOop) ? is_narrowoop()->get_ptrtype() :
1556 ((_base == NarrowKlass) ? is_narrowklass()->get_ptrtype() :
1557 (isa_ptr() ? is_ptr() : NULL));
1558 }
1560 inline const TypeOopPtr* Type::make_oopptr() const {
1561 return (_base == NarrowOop) ? is_narrowoop()->get_ptrtype()->is_oopptr() : is_oopptr();
1562 }
1564 inline const TypeNarrowOop* Type::make_narrowoop() const {
1565 return (_base == NarrowOop) ? is_narrowoop() :
1566 (isa_ptr() ? TypeNarrowOop::make(is_ptr()) : NULL);
1567 }
1569 inline const TypeNarrowKlass* Type::make_narrowklass() const {
1570 return (_base == NarrowKlass) ? is_narrowklass() :
1571 (isa_ptr() ? TypeNarrowKlass::make(is_ptr()) : NULL);
1572 }
1574 inline bool Type::is_floatingpoint() const {
1575 if( (_base == FloatCon) || (_base == FloatBot) ||
1576 (_base == DoubleCon) || (_base == DoubleBot) )
1577 return true;
1578 return false;
1579 }
1581 inline bool Type::is_ptr_to_boxing_obj() const {
1582 const TypeInstPtr* tp = isa_instptr();
1583 return (tp != NULL) && (tp->offset() == 0) &&
1584 tp->klass()->is_instance_klass() &&
1585 tp->klass()->as_instance_klass()->is_box_klass();
1586 }
1589 // ===============================================================
1590 // Things that need to be 64-bits in the 64-bit build but
1591 // 32-bits in the 32-bit build. Done this way to get full
1592 // optimization AND strong typing.
1593 #ifdef _LP64
1595 // For type queries and asserts
1596 #define is_intptr_t is_long
1597 #define isa_intptr_t isa_long
1598 #define find_intptr_t_type find_long_type
1599 #define find_intptr_t_con find_long_con
1600 #define TypeX TypeLong
1601 #define Type_X Type::Long
1602 #define TypeX_X TypeLong::LONG
1603 #define TypeX_ZERO TypeLong::ZERO
1604 // For 'ideal_reg' machine registers
1605 #define Op_RegX Op_RegL
1606 // For phase->intcon variants
1607 #define MakeConX longcon
1608 #define ConXNode ConLNode
1609 // For array index arithmetic
1610 #define MulXNode MulLNode
1611 #define AndXNode AndLNode
1612 #define OrXNode OrLNode
1613 #define CmpXNode CmpLNode
1614 #define SubXNode SubLNode
1615 #define LShiftXNode LShiftLNode
1616 // For object size computation:
1617 #define AddXNode AddLNode
1618 #define RShiftXNode RShiftLNode
1619 // For card marks and hashcodes
1620 #define URShiftXNode URShiftLNode
1621 // UseOptoBiasInlining
1622 #define XorXNode XorLNode
1623 #define StoreXConditionalNode StoreLConditionalNode
1624 // Opcodes
1625 #define Op_LShiftX Op_LShiftL
1626 #define Op_AndX Op_AndL
1627 #define Op_AddX Op_AddL
1628 #define Op_SubX Op_SubL
1629 #define Op_XorX Op_XorL
1630 #define Op_URShiftX Op_URShiftL
1631 // conversions
1632 #define ConvI2X(x) ConvI2L(x)
1633 #define ConvL2X(x) (x)
1634 #define ConvX2I(x) ConvL2I(x)
1635 #define ConvX2L(x) (x)
1637 #else
1639 // For type queries and asserts
1640 #define is_intptr_t is_int
1641 #define isa_intptr_t isa_int
1642 #define find_intptr_t_type find_int_type
1643 #define find_intptr_t_con find_int_con
1644 #define TypeX TypeInt
1645 #define Type_X Type::Int
1646 #define TypeX_X TypeInt::INT
1647 #define TypeX_ZERO TypeInt::ZERO
1648 // For 'ideal_reg' machine registers
1649 #define Op_RegX Op_RegI
1650 // For phase->intcon variants
1651 #define MakeConX intcon
1652 #define ConXNode ConINode
1653 // For array index arithmetic
1654 #define MulXNode MulINode
1655 #define AndXNode AndINode
1656 #define OrXNode OrINode
1657 #define CmpXNode CmpINode
1658 #define SubXNode SubINode
1659 #define LShiftXNode LShiftINode
1660 // For object size computation:
1661 #define AddXNode AddINode
1662 #define RShiftXNode RShiftINode
1663 // For card marks and hashcodes
1664 #define URShiftXNode URShiftINode
1665 // UseOptoBiasInlining
1666 #define XorXNode XorINode
1667 #define StoreXConditionalNode StoreIConditionalNode
1668 // Opcodes
1669 #define Op_LShiftX Op_LShiftI
1670 #define Op_AndX Op_AndI
1671 #define Op_AddX Op_AddI
1672 #define Op_SubX Op_SubI
1673 #define Op_XorX Op_XorI
1674 #define Op_URShiftX Op_URShiftI
1675 // conversions
1676 #define ConvI2X(x) (x)
1677 #define ConvL2X(x) ConvL2I(x)
1678 #define ConvX2I(x) (x)
1679 #define ConvX2L(x) ConvI2L(x)
1681 #endif
1683 #endif // SHARE_VM_OPTO_TYPE_HPP