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 */ 24 25 #ifndef SHARE_VM_OPTO_TYPE_HPP 26 #define SHARE_VM_OPTO_TYPE_HPP 27 28 #include "libadt/port.hpp" 29 #include "opto/adlcVMDeps.hpp" 30 #include "runtime/handles.hpp" 31 32 // Portions of code courtesy of Clifford Click 33 34 // Optimization - Graph Style 35 36 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. 44 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; 68 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; 76 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 87 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 94 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.) 101 102 MetadataPtr, // Generic metadata 103 KlassPtr, // Klass pointers 104 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 }; 118 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 }; 124 125 // Min and max WIDEN values. 126 enum WIDEN { 127 WidenMin = 0, 128 WidenMax = 3 129 }; 130 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; 140 141 // Dictionary of types shared among compilations. 142 static Dict* _shared_type_dict; 143 static TypeInfo _type_info[]; 144 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; 149 150 // Top-level hash-table of types 151 static Dict *type_dict() { 152 return Compile::current()->type_dict(); 153 } 154 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]; 161 162 protected: 163 // Each class of type is also identified by its base. 164 const TYPES _base; // Enum of Types type 165 166 Type( TYPES t ) : _dual(NULL), _base(t) {} // Simple types 167 // ~Type(); // Use fast deallocation 168 const Type *hashcons(); // Hash-cons the type 169 170 public: 171 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 } 183 184 // Initialize the type system for a particular compilation. 185 static void Initialize(Compile* compile); 186 187 // Initialize the types shared by all compilations. 188 static void Initialize_shared(Compile* compile); 189 190 TYPES base() const { 191 assert(_base > Bad && _base < lastype, "sanity"); 192 return _base; 193 } 194 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); } 201 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; } 208 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; } 212 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. 216 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(); } 221 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; 226 227 #ifdef ASSERT 228 // One type is interface, the other is oop 229 virtual bool interface_vs_oop(const Type *t) const; 230 #endif 231 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; 236 237 bool is_ptr_to_boxing_obj() const; 238 239 240 // Convenience access 241 float getf() const; 242 double getd() const; 243 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 272 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 277 278 virtual bool is_finite() const; // Has a finite value 279 virtual bool is_nan() const; // Is not a number (NaN) 280 281 // Returns this ptr type or the equivalent ptr type for this compressed pointer. 282 const TypePtr* make_ptr() const; 283 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; 287 288 // Returns this compressed pointer or the equivalent compressed version 289 // of this pointer type. 290 const TypeNarrowOop* make_narrowoop() const; 291 292 // Returns this compressed klass pointer or the equivalent 293 // compressed version of this pointer type. 294 const TypeNarrowKlass* make_narrowklass() const; 295 296 // Special test for register pressure heuristic 297 bool is_floatingpoint() const; // True if Float or Double base type 298 299 // Do you have memory, directly or through a tuple? 300 bool has_memory( ) const; 301 302 // TRUE if type is a singleton 303 virtual bool singleton(void) const; 304 305 // TRUE if type is above the lattice centerline, and is therefore vacuous 306 virtual bool empty(void) const; 307 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; 311 312 // Map ideal registers (machine types) to ideal types 313 static const Type *mreg2type[]; 314 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 325 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 } 331 332 // Mapping to the array element's basic type. 333 BasicType array_element_basic_type() const; 334 335 // Create standard type for a ciType: 336 static const Type* get_const_type(ciType* type); 337 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 } 343 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 } 352 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; 364 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; } 371 372 // Mapping from CI type system to compiler type: 373 static const Type* get_typeflow_type(ciType* type); 374 375 static const Type* make_from_constant(ciConstant constant, 376 bool require_constant = false, 377 bool is_autobox_cache = false); 378 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 }; 385 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 397 398 static const TypeF *make(float f); 399 400 virtual bool is_finite() const; // Has a finite value 401 virtual bool is_nan() const; // Is not a number (NaN) 402 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 }; 412 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 424 425 static const TypeD *make(double d); 426 427 virtual bool is_finite() const; // Has a finite value 428 virtual bool is_nan() const; // Is not a number (NaN) 429 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 }; 439 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 453 454 static const TypeInt *make(jint lo); 455 // must always specify w 456 static const TypeInt *make(jint lo, jint hi, int w); 457 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; } 462 463 virtual bool is_finite() const; // Has a finite value 464 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 }; 494 495 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 509 510 static const TypeLong *make(jlong lo); 511 // must always specify w 512 static const TypeLong *make(jlong lo, jlong hi, int w); 513 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; } 518 519 virtual bool is_finite() const; // Has a finite value 520 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 }; 539 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 551 552 public: 553 const uint _cnt; // Count of fields 554 const Type ** const _fields; // Array of field types 555 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 } 566 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); 570 571 // Subroutine call type with space allocated for argument types 572 static const Type **fields( uint arg_cnt ); 573 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 static const TypeTuple *LONG_CC_PAIR; 589 #ifndef PRODUCT 590 virtual void dump2( Dict &d, uint, outputStream *st ) const; // Specialized per-Type dumping 591 #endif 592 }; 593 594 //------------------------------TypeAry---------------------------------------- 595 // Class of Array Types 596 class TypeAry : public Type { 597 TypeAry(const Type* elem, const TypeInt* size, bool stable) : Type(Array), 598 _elem(elem), _size(size), _stable(stable) {} 599 public: 600 virtual bool eq( const Type *t ) const; 601 virtual int hash() const; // Type specific hashing 602 virtual bool singleton(void) const; // TRUE if type is a singleton 603 virtual bool empty(void) const; // TRUE if type is vacuous 604 605 private: 606 const Type *_elem; // Element type of array 607 const TypeInt *_size; // Elements in array 608 const bool _stable; // Are elements @Stable? 609 friend class TypeAryPtr; 610 611 public: 612 static const TypeAry* make(const Type* elem, const TypeInt* size, bool stable = false); 613 614 virtual const Type *xmeet( const Type *t ) const; 615 virtual const Type *xdual() const; // Compute dual right now. 616 bool ary_must_be_exact() const; // true if arrays of such are never generic 617 #ifdef ASSERT 618 // One type is interface, the other is oop 619 virtual bool interface_vs_oop(const Type *t) const; 620 #endif 621 #ifndef PRODUCT 622 virtual void dump2( Dict &d, uint, outputStream *st ) const; // Specialized per-Type dumping 623 #endif 624 }; 625 626 //------------------------------TypeVect--------------------------------------- 627 // Class of Vector Types 628 class TypeVect : public Type { 629 const Type* _elem; // Vector's element type 630 const uint _length; // Elements in vector (power of 2) 631 632 protected: 633 TypeVect(TYPES t, const Type* elem, uint length) : Type(t), 634 _elem(elem), _length(length) {} 635 636 public: 637 const Type* element_type() const { return _elem; } 638 BasicType element_basic_type() const { return _elem->array_element_basic_type(); } 639 uint length() const { return _length; } 640 uint length_in_bytes() const { 641 return _length * type2aelembytes(element_basic_type()); 642 } 643 644 virtual bool eq(const Type *t) const; 645 virtual int hash() const; // Type specific hashing 646 virtual bool singleton(void) const; // TRUE if type is a singleton 647 virtual bool empty(void) const; // TRUE if type is vacuous 648 649 static const TypeVect *make(const BasicType elem_bt, uint length) { 650 // Use bottom primitive type. 651 return make(get_const_basic_type(elem_bt), length); 652 } 653 // Used directly by Replicate nodes to construct singleton vector. 654 static const TypeVect *make(const Type* elem, uint length); 655 656 virtual const Type *xmeet( const Type *t) const; 657 virtual const Type *xdual() const; // Compute dual right now. 658 659 static const TypeVect *VECTS; 660 static const TypeVect *VECTD; 661 static const TypeVect *VECTX; 662 static const TypeVect *VECTY; 663 664 #ifndef PRODUCT 665 virtual void dump2(Dict &d, uint, outputStream *st) const; // Specialized per-Type dumping 666 #endif 667 }; 668 669 class TypeVectS : public TypeVect { 670 friend class TypeVect; 671 TypeVectS(const Type* elem, uint length) : TypeVect(VectorS, elem, length) {} 672 }; 673 674 class TypeVectD : public TypeVect { 675 friend class TypeVect; 676 TypeVectD(const Type* elem, uint length) : TypeVect(VectorD, elem, length) {} 677 }; 678 679 class TypeVectX : public TypeVect { 680 friend class TypeVect; 681 TypeVectX(const Type* elem, uint length) : TypeVect(VectorX, elem, length) {} 682 }; 683 684 class TypeVectY : public TypeVect { 685 friend class TypeVect; 686 TypeVectY(const Type* elem, uint length) : TypeVect(VectorY, elem, length) {} 687 }; 688 689 //------------------------------TypePtr---------------------------------------- 690 // Class of machine Pointer Types: raw data, instances or arrays. 691 // If the _base enum is AnyPtr, then this refers to all of the above. 692 // Otherwise the _base will indicate which subset of pointers is affected, 693 // and the class will be inherited from. 694 class TypePtr : public Type { 695 friend class TypeNarrowPtr; 696 public: 697 enum PTR { TopPTR, AnyNull, Constant, Null, NotNull, BotPTR, lastPTR }; 698 protected: 699 TypePtr( TYPES t, PTR ptr, int offset ) : Type(t), _ptr(ptr), _offset(offset) {} 700 virtual bool eq( const Type *t ) const; 701 virtual int hash() const; // Type specific hashing 702 static const PTR ptr_meet[lastPTR][lastPTR]; 703 static const PTR ptr_dual[lastPTR]; 704 static const char * const ptr_msg[lastPTR]; 705 706 public: 707 const int _offset; // Offset into oop, with TOP & BOT 708 const PTR _ptr; // Pointer equivalence class 709 710 const int offset() const { return _offset; } 711 const PTR ptr() const { return _ptr; } 712 713 static const TypePtr *make( TYPES t, PTR ptr, int offset ); 714 715 // Return a 'ptr' version of this type 716 virtual const Type *cast_to_ptr_type(PTR ptr) const; 717 718 virtual intptr_t get_con() const; 719 720 int xadd_offset( intptr_t offset ) const; 721 virtual const TypePtr *add_offset( intptr_t offset ) const; 722 723 virtual bool singleton(void) const; // TRUE if type is a singleton 724 virtual bool empty(void) const; // TRUE if type is vacuous 725 virtual const Type *xmeet( const Type *t ) const; 726 int meet_offset( int offset ) const; 727 int dual_offset( ) const; 728 virtual const Type *xdual() const; // Compute dual right now. 729 730 // meet, dual and join over pointer equivalence sets 731 PTR meet_ptr( const PTR in_ptr ) const { return ptr_meet[in_ptr][ptr()]; } 732 PTR dual_ptr() const { return ptr_dual[ptr()]; } 733 734 // This is textually confusing unless one recalls that 735 // join(t) == dual()->meet(t->dual())->dual(). 736 PTR join_ptr( const PTR in_ptr ) const { 737 return ptr_dual[ ptr_meet[ ptr_dual[in_ptr] ] [ dual_ptr() ] ]; 738 } 739 740 // Tests for relation to centerline of type lattice: 741 static bool above_centerline(PTR ptr) { return (ptr <= AnyNull); } 742 static bool below_centerline(PTR ptr) { return (ptr >= NotNull); } 743 // Convenience common pre-built types. 744 static const TypePtr *NULL_PTR; 745 static const TypePtr *NOTNULL; 746 static const TypePtr *BOTTOM; 747 #ifndef PRODUCT 748 virtual void dump2( Dict &d, uint depth, outputStream *st ) const; 749 #endif 750 }; 751 752 //------------------------------TypeRawPtr------------------------------------- 753 // Class of raw pointers, pointers to things other than Oops. Examples 754 // include the stack pointer, top of heap, card-marking area, handles, etc. 755 class TypeRawPtr : public TypePtr { 756 protected: 757 TypeRawPtr( PTR ptr, address bits ) : TypePtr(RawPtr,ptr,0), _bits(bits){} 758 public: 759 virtual bool eq( const Type *t ) const; 760 virtual int hash() const; // Type specific hashing 761 762 const address _bits; // Constant value, if applicable 763 764 static const TypeRawPtr *make( PTR ptr ); 765 static const TypeRawPtr *make( address bits ); 766 767 // Return a 'ptr' version of this type 768 virtual const Type *cast_to_ptr_type(PTR ptr) const; 769 770 virtual intptr_t get_con() const; 771 772 virtual const TypePtr *add_offset( intptr_t offset ) const; 773 774 virtual const Type *xmeet( const Type *t ) const; 775 virtual const Type *xdual() const; // Compute dual right now. 776 // Convenience common pre-built types. 777 static const TypeRawPtr *BOTTOM; 778 static const TypeRawPtr *NOTNULL; 779 #ifndef PRODUCT 780 virtual void dump2( Dict &d, uint depth, outputStream *st ) const; 781 #endif 782 }; 783 784 //------------------------------TypeOopPtr------------------------------------- 785 // Some kind of oop (Java pointer), either klass or instance or array. 786 class TypeOopPtr : public TypePtr { 787 protected: 788 TypeOopPtr( TYPES t, PTR ptr, ciKlass* k, bool xk, ciObject* o, int offset, int instance_id ); 789 public: 790 virtual bool eq( const Type *t ) const; 791 virtual int hash() const; // Type specific hashing 792 virtual bool singleton(void) const; // TRUE if type is a singleton 793 enum { 794 InstanceTop = -1, // undefined instance 795 InstanceBot = 0 // any possible instance 796 }; 797 protected: 798 799 // Oop is NULL, unless this is a constant oop. 800 ciObject* _const_oop; // Constant oop 801 // If _klass is NULL, then so is _sig. This is an unloaded klass. 802 ciKlass* _klass; // Klass object 803 // Does the type exclude subclasses of the klass? (Inexact == polymorphic.) 804 bool _klass_is_exact; 805 bool _is_ptr_to_narrowoop; 806 bool _is_ptr_to_narrowklass; 807 bool _is_ptr_to_boxed_value; 808 809 // If not InstanceTop or InstanceBot, indicates that this is 810 // a particular instance of this type which is distinct. 811 // This is the the node index of the allocation node creating this instance. 812 int _instance_id; 813 814 static const TypeOopPtr* make_from_klass_common(ciKlass* klass, bool klass_change, bool try_for_exact); 815 816 int dual_instance_id() const; 817 int meet_instance_id(int uid) const; 818 819 public: 820 // Creates a type given a klass. Correctly handles multi-dimensional arrays 821 // Respects UseUniqueSubclasses. 822 // If the klass is final, the resulting type will be exact. 823 static const TypeOopPtr* make_from_klass(ciKlass* klass) { 824 return make_from_klass_common(klass, true, false); 825 } 826 // Same as before, but will produce an exact type, even if 827 // the klass is not final, as long as it has exactly one implementation. 828 static const TypeOopPtr* make_from_klass_unique(ciKlass* klass) { 829 return make_from_klass_common(klass, true, true); 830 } 831 // Same as before, but does not respects UseUniqueSubclasses. 832 // Use this only for creating array element types. 833 static const TypeOopPtr* make_from_klass_raw(ciKlass* klass) { 834 return make_from_klass_common(klass, false, false); 835 } 836 // Creates a singleton type given an object. 837 // If the object cannot be rendered as a constant, 838 // may return a non-singleton type. 839 // If require_constant, produce a NULL if a singleton is not possible. 840 static const TypeOopPtr* make_from_constant(ciObject* o, 841 bool require_constant = false, 842 bool not_null_elements = false); 843 844 // Make a generic (unclassed) pointer to an oop. 845 static const TypeOopPtr* make(PTR ptr, int offset, int instance_id); 846 847 ciObject* const_oop() const { return _const_oop; } 848 virtual ciKlass* klass() const { return _klass; } 849 bool klass_is_exact() const { return _klass_is_exact; } 850 851 // Returns true if this pointer points at memory which contains a 852 // compressed oop references. 853 bool is_ptr_to_narrowoop_nv() const { return _is_ptr_to_narrowoop; } 854 bool is_ptr_to_narrowklass_nv() const { return _is_ptr_to_narrowklass; } 855 bool is_ptr_to_boxed_value() const { return _is_ptr_to_boxed_value; } 856 bool is_known_instance() const { return _instance_id > 0; } 857 int instance_id() const { return _instance_id; } 858 bool is_known_instance_field() const { return is_known_instance() && _offset >= 0; } 859 860 virtual intptr_t get_con() const; 861 862 virtual const Type *cast_to_ptr_type(PTR ptr) const; 863 864 virtual const Type *cast_to_exactness(bool klass_is_exact) const; 865 866 virtual const TypeOopPtr *cast_to_instance_id(int instance_id) const; 867 868 // corresponding pointer to klass, for a given instance 869 const TypeKlassPtr* as_klass_type() const; 870 871 virtual const TypePtr *add_offset( intptr_t offset ) const; 872 873 virtual const Type *xmeet( const Type *t ) const; 874 virtual const Type *xdual() const; // Compute dual right now. 875 876 // Do not allow interface-vs.-noninterface joins to collapse to top. 877 virtual const Type *filter( const Type *kills ) const; 878 879 // Convenience common pre-built type. 880 static const TypeOopPtr *BOTTOM; 881 #ifndef PRODUCT 882 virtual void dump2( Dict &d, uint depth, outputStream *st ) const; 883 #endif 884 }; 885 886 //------------------------------TypeInstPtr------------------------------------ 887 // Class of Java object pointers, pointing either to non-array Java instances 888 // or to a Klass* (including array klasses). 889 class TypeInstPtr : public TypeOopPtr { 890 TypeInstPtr( PTR ptr, ciKlass* k, bool xk, ciObject* o, int offset, int instance_id ); 891 virtual bool eq( const Type *t ) const; 892 virtual int hash() const; // Type specific hashing 893 894 ciSymbol* _name; // class name 895 896 public: 897 ciSymbol* name() const { return _name; } 898 899 bool is_loaded() const { return _klass->is_loaded(); } 900 901 // Make a pointer to a constant oop. 902 static const TypeInstPtr *make(ciObject* o) { 903 return make(TypePtr::Constant, o->klass(), true, o, 0); 904 } 905 // Make a pointer to a constant oop with offset. 906 static const TypeInstPtr *make(ciObject* o, int offset) { 907 return make(TypePtr::Constant, o->klass(), true, o, offset); 908 } 909 910 // Make a pointer to some value of type klass. 911 static const TypeInstPtr *make(PTR ptr, ciKlass* klass) { 912 return make(ptr, klass, false, NULL, 0); 913 } 914 915 // Make a pointer to some non-polymorphic value of exactly type klass. 916 static const TypeInstPtr *make_exact(PTR ptr, ciKlass* klass) { 917 return make(ptr, klass, true, NULL, 0); 918 } 919 920 // Make a pointer to some value of type klass with offset. 921 static const TypeInstPtr *make(PTR ptr, ciKlass* klass, int offset) { 922 return make(ptr, klass, false, NULL, offset); 923 } 924 925 // Make a pointer to an oop. 926 static const TypeInstPtr *make(PTR ptr, ciKlass* k, bool xk, ciObject* o, int offset, int instance_id = InstanceBot ); 927 928 /** Create constant type for a constant boxed value */ 929 const Type* get_const_boxed_value() const; 930 931 // If this is a java.lang.Class constant, return the type for it or NULL. 932 // Pass to Type::get_const_type to turn it to a type, which will usually 933 // be a TypeInstPtr, but may also be a TypeInt::INT for int.class, etc. 934 ciType* java_mirror_type() const; 935 936 virtual const Type *cast_to_ptr_type(PTR ptr) const; 937 938 virtual const Type *cast_to_exactness(bool klass_is_exact) const; 939 940 virtual const TypeOopPtr *cast_to_instance_id(int instance_id) const; 941 942 virtual const TypePtr *add_offset( intptr_t offset ) const; 943 944 virtual const Type *xmeet( const Type *t ) const; 945 virtual const TypeInstPtr *xmeet_unloaded( const TypeInstPtr *t ) const; 946 virtual const Type *xdual() const; // Compute dual right now. 947 948 // Convenience common pre-built types. 949 static const TypeInstPtr *NOTNULL; 950 static const TypeInstPtr *BOTTOM; 951 static const TypeInstPtr *MIRROR; 952 static const TypeInstPtr *MARK; 953 static const TypeInstPtr *KLASS; 954 #ifndef PRODUCT 955 virtual void dump2( Dict &d, uint depth, outputStream *st ) const; // Specialized per-Type dumping 956 #endif 957 }; 958 959 //------------------------------TypeAryPtr------------------------------------- 960 // Class of Java array pointers 961 class TypeAryPtr : public TypeOopPtr { 962 TypeAryPtr( PTR ptr, ciObject* o, const TypeAry *ary, ciKlass* k, bool xk, 963 int offset, int instance_id, bool is_autobox_cache ) 964 : TypeOopPtr(AryPtr,ptr,k,xk,o,offset, instance_id), 965 _ary(ary), 966 _is_autobox_cache(is_autobox_cache) 967 { 968 #ifdef ASSERT 969 if (k != NULL) { 970 // Verify that specified klass and TypeAryPtr::klass() follow the same rules. 971 ciKlass* ck = compute_klass(true); 972 if (k != ck) { 973 this->dump(); tty->cr(); 974 tty->print(" k: "); 975 k->print(); tty->cr(); 976 tty->print("ck: "); 977 if (ck != NULL) ck->print(); 978 else tty->print("<NULL>"); 979 tty->cr(); 980 assert(false, "unexpected TypeAryPtr::_klass"); 981 } 982 } 983 #endif 984 } 985 virtual bool eq( const Type *t ) const; 986 virtual int hash() const; // Type specific hashing 987 const TypeAry *_ary; // Array we point into 988 const bool _is_autobox_cache; 989 990 ciKlass* compute_klass(DEBUG_ONLY(bool verify = false)) const; 991 992 public: 993 // Accessors 994 ciKlass* klass() const; 995 const TypeAry* ary() const { return _ary; } 996 const Type* elem() const { return _ary->_elem; } 997 const TypeInt* size() const { return _ary->_size; } 998 bool is_stable() const { return _ary->_stable; } 999 1000 bool is_autobox_cache() const { return _is_autobox_cache; } 1001 1002 static const TypeAryPtr *make( PTR ptr, const TypeAry *ary, ciKlass* k, bool xk, int offset, int instance_id = InstanceBot); 1003 // Constant pointer to array 1004 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 1006 // Return a 'ptr' version of this type 1007 virtual const Type *cast_to_ptr_type(PTR ptr) const; 1008 1009 virtual const Type *cast_to_exactness(bool klass_is_exact) const; 1010 1011 virtual const TypeOopPtr *cast_to_instance_id(int instance_id) const; 1012 1013 virtual const TypeAryPtr* cast_to_size(const TypeInt* size) const; 1014 virtual const TypeInt* narrow_size_type(const TypeInt* size) const; 1015 1016 virtual bool empty(void) const; // TRUE if type is vacuous 1017 virtual const TypePtr *add_offset( intptr_t offset ) const; 1018 1019 virtual const Type *xmeet( const Type *t ) const; 1020 virtual const Type *xdual() const; // Compute dual right now. 1021 1022 const TypeAryPtr* cast_to_stable(bool stable, int stable_dimension = 1) const; 1023 int stable_dimension() const; 1024 1025 // Convenience common pre-built types. 1026 static const TypeAryPtr *RANGE; 1027 static const TypeAryPtr *OOPS; 1028 static const TypeAryPtr *NARROWOOPS; 1029 static const TypeAryPtr *BYTES; 1030 static const TypeAryPtr *SHORTS; 1031 static const TypeAryPtr *CHARS; 1032 static const TypeAryPtr *INTS; 1033 static const TypeAryPtr *LONGS; 1034 static const TypeAryPtr *FLOATS; 1035 static const TypeAryPtr *DOUBLES; 1036 // selects one of the above: 1037 static const TypeAryPtr *get_array_body_type(BasicType elem) { 1038 assert((uint)elem <= T_CONFLICT && _array_body_type[elem] != NULL, "bad elem type"); 1039 return _array_body_type[elem]; 1040 } 1041 static const TypeAryPtr *_array_body_type[T_CONFLICT+1]; 1042 // sharpen the type of an int which is used as an array size 1043 #ifdef ASSERT 1044 // One type is interface, the other is oop 1045 virtual bool interface_vs_oop(const Type *t) const; 1046 #endif 1047 #ifndef PRODUCT 1048 virtual void dump2( Dict &d, uint depth, outputStream *st ) const; // Specialized per-Type dumping 1049 #endif 1050 }; 1051 1052 //------------------------------TypeMetadataPtr------------------------------------- 1053 // Some kind of metadata, either Method*, MethodData* or CPCacheOop 1054 class TypeMetadataPtr : public TypePtr { 1055 protected: 1056 TypeMetadataPtr(PTR ptr, ciMetadata* metadata, int offset); 1057 public: 1058 virtual bool eq( const Type *t ) const; 1059 virtual int hash() const; // Type specific hashing 1060 virtual bool singleton(void) const; // TRUE if type is a singleton 1061 1062 private: 1063 ciMetadata* _metadata; 1064 1065 public: 1066 static const TypeMetadataPtr* make(PTR ptr, ciMetadata* m, int offset); 1067 1068 static const TypeMetadataPtr* make(ciMethod* m); 1069 static const TypeMetadataPtr* make(ciMethodData* m); 1070 1071 ciMetadata* metadata() const { return _metadata; } 1072 1073 virtual const Type *cast_to_ptr_type(PTR ptr) const; 1074 1075 virtual const TypePtr *add_offset( intptr_t offset ) const; 1076 1077 virtual const Type *xmeet( const Type *t ) const; 1078 virtual const Type *xdual() const; // Compute dual right now. 1079 1080 virtual intptr_t get_con() const; 1081 1082 // Do not allow interface-vs.-noninterface joins to collapse to top. 1083 virtual const Type *filter( const Type *kills ) const; 1084 1085 // Convenience common pre-built types. 1086 static const TypeMetadataPtr *BOTTOM; 1087 1088 #ifndef PRODUCT 1089 virtual void dump2( Dict &d, uint depth, outputStream *st ) const; 1090 #endif 1091 }; 1092 1093 //------------------------------TypeKlassPtr----------------------------------- 1094 // Class of Java Klass pointers 1095 class TypeKlassPtr : public TypePtr { 1096 TypeKlassPtr( PTR ptr, ciKlass* klass, int offset ); 1097 1098 public: 1099 virtual bool eq( const Type *t ) const; 1100 virtual int hash() const; // Type specific hashing 1101 virtual bool singleton(void) const; // TRUE if type is a singleton 1102 private: 1103 1104 static const TypeKlassPtr* make_from_klass_common(ciKlass* klass, bool klass_change, bool try_for_exact); 1105 1106 ciKlass* _klass; 1107 1108 // Does the type exclude subclasses of the klass? (Inexact == polymorphic.) 1109 bool _klass_is_exact; 1110 1111 public: 1112 ciSymbol* name() const { return klass()->name(); } 1113 1114 ciKlass* klass() const { return _klass; } 1115 bool klass_is_exact() const { return _klass_is_exact; } 1116 1117 bool is_loaded() const { return klass()->is_loaded(); } 1118 1119 // Creates a type given a klass. Correctly handles multi-dimensional arrays 1120 // Respects UseUniqueSubclasses. 1121 // If the klass is final, the resulting type will be exact. 1122 static const TypeKlassPtr* make_from_klass(ciKlass* klass) { 1123 return make_from_klass_common(klass, true, false); 1124 } 1125 // Same as before, but will produce an exact type, even if 1126 // the klass is not final, as long as it has exactly one implementation. 1127 static const TypeKlassPtr* make_from_klass_unique(ciKlass* klass) { 1128 return make_from_klass_common(klass, true, true); 1129 } 1130 // Same as before, but does not respects UseUniqueSubclasses. 1131 // Use this only for creating array element types. 1132 static const TypeKlassPtr* make_from_klass_raw(ciKlass* klass) { 1133 return make_from_klass_common(klass, false, false); 1134 } 1135 1136 // Make a generic (unclassed) pointer to metadata. 1137 static const TypeKlassPtr* make(PTR ptr, int offset); 1138 1139 // ptr to klass 'k' 1140 static const TypeKlassPtr *make( ciKlass* k ) { return make( TypePtr::Constant, k, 0); } 1141 // ptr to klass 'k' with offset 1142 static const TypeKlassPtr *make( ciKlass* k, int offset ) { return make( TypePtr::Constant, k, offset); } 1143 // ptr to klass 'k' or sub-klass 1144 static const TypeKlassPtr *make( PTR ptr, ciKlass* k, int offset); 1145 1146 virtual const Type *cast_to_ptr_type(PTR ptr) const; 1147 1148 virtual const Type *cast_to_exactness(bool klass_is_exact) const; 1149 1150 // corresponding pointer to instance, for a given class 1151 const TypeOopPtr* as_instance_type() const; 1152 1153 virtual const TypePtr *add_offset( intptr_t offset ) const; 1154 virtual const Type *xmeet( const Type *t ) const; 1155 virtual const Type *xdual() const; // Compute dual right now. 1156 1157 virtual intptr_t get_con() const; 1158 1159 // Convenience common pre-built types. 1160 static const TypeKlassPtr* OBJECT; // Not-null object klass or below 1161 static const TypeKlassPtr* OBJECT_OR_NULL; // Maybe-null version of same 1162 #ifndef PRODUCT 1163 virtual void dump2( Dict &d, uint depth, outputStream *st ) const; // Specialized per-Type dumping 1164 #endif 1165 }; 1166 1167 class TypeNarrowPtr : public Type { 1168 protected: 1169 const TypePtr* _ptrtype; // Could be TypePtr::NULL_PTR 1170 1171 TypeNarrowPtr(TYPES t, const TypePtr* ptrtype): _ptrtype(ptrtype), 1172 Type(t) { 1173 assert(ptrtype->offset() == 0 || 1174 ptrtype->offset() == OffsetBot || 1175 ptrtype->offset() == OffsetTop, "no real offsets"); 1176 } 1177 1178 virtual const TypeNarrowPtr *isa_same_narrowptr(const Type *t) const = 0; 1179 virtual const TypeNarrowPtr *is_same_narrowptr(const Type *t) const = 0; 1180 virtual const TypeNarrowPtr *make_same_narrowptr(const TypePtr *t) const = 0; 1181 virtual const TypeNarrowPtr *make_hash_same_narrowptr(const TypePtr *t) const = 0; 1182 public: 1183 virtual bool eq( const Type *t ) const; 1184 virtual int hash() const; // Type specific hashing 1185 virtual bool singleton(void) const; // TRUE if type is a singleton 1186 1187 virtual const Type *xmeet( const Type *t ) const; 1188 virtual const Type *xdual() const; // Compute dual right now. 1189 1190 virtual intptr_t get_con() const; 1191 1192 // Do not allow interface-vs.-noninterface joins to collapse to top. 1193 virtual const Type *filter( const Type *kills ) const; 1194 1195 virtual bool empty(void) const; // TRUE if type is vacuous 1196 1197 // returns the equivalent ptr type for this compressed pointer 1198 const TypePtr *get_ptrtype() const { 1199 return _ptrtype; 1200 } 1201 1202 #ifndef PRODUCT 1203 virtual void dump2( Dict &d, uint depth, outputStream *st ) const; 1204 #endif 1205 }; 1206 1207 //------------------------------TypeNarrowOop---------------------------------- 1208 // A compressed reference to some kind of Oop. This type wraps around 1209 // a preexisting TypeOopPtr and forwards most of it's operations to 1210 // the underlying type. It's only real purpose is to track the 1211 // oopness of the compressed oop value when we expose the conversion 1212 // between the normal and the compressed form. 1213 class TypeNarrowOop : public TypeNarrowPtr { 1214 protected: 1215 TypeNarrowOop( const TypePtr* ptrtype): TypeNarrowPtr(NarrowOop, ptrtype) { 1216 } 1217 1218 virtual const TypeNarrowPtr *isa_same_narrowptr(const Type *t) const { 1219 return t->isa_narrowoop(); 1220 } 1221 1222 virtual const TypeNarrowPtr *is_same_narrowptr(const Type *t) const { 1223 return t->is_narrowoop(); 1224 } 1225 1226 virtual const TypeNarrowPtr *make_same_narrowptr(const TypePtr *t) const { 1227 return new TypeNarrowOop(t); 1228 } 1229 1230 virtual const TypeNarrowPtr *make_hash_same_narrowptr(const TypePtr *t) const { 1231 return (const TypeNarrowPtr*)((new TypeNarrowOop(t))->hashcons()); 1232 } 1233 1234 public: 1235 1236 static const TypeNarrowOop *make( const TypePtr* type); 1237 1238 static const TypeNarrowOop* make_from_constant(ciObject* con, bool require_constant = false) { 1239 return make(TypeOopPtr::make_from_constant(con, require_constant)); 1240 } 1241 1242 static const TypeNarrowOop *BOTTOM; 1243 static const TypeNarrowOop *NULL_PTR; 1244 1245 #ifndef PRODUCT 1246 virtual void dump2( Dict &d, uint depth, outputStream *st ) const; 1247 #endif 1248 }; 1249 1250 //------------------------------TypeNarrowKlass---------------------------------- 1251 // A compressed reference to klass pointer. This type wraps around a 1252 // preexisting TypeKlassPtr and forwards most of it's operations to 1253 // the underlying type. 1254 class TypeNarrowKlass : public TypeNarrowPtr { 1255 protected: 1256 TypeNarrowKlass( const TypePtr* ptrtype): TypeNarrowPtr(NarrowKlass, ptrtype) { 1257 } 1258 1259 virtual const TypeNarrowPtr *isa_same_narrowptr(const Type *t) const { 1260 return t->isa_narrowklass(); 1261 } 1262 1263 virtual const TypeNarrowPtr *is_same_narrowptr(const Type *t) const { 1264 return t->is_narrowklass(); 1265 } 1266 1267 virtual const TypeNarrowPtr *make_same_narrowptr(const TypePtr *t) const { 1268 return new TypeNarrowKlass(t); 1269 } 1270 1271 virtual const TypeNarrowPtr *make_hash_same_narrowptr(const TypePtr *t) const { 1272 return (const TypeNarrowPtr*)((new TypeNarrowKlass(t))->hashcons()); 1273 } 1274 1275 public: 1276 static const TypeNarrowKlass *make( const TypePtr* type); 1277 1278 // static const TypeNarrowKlass *BOTTOM; 1279 static const TypeNarrowKlass *NULL_PTR; 1280 1281 #ifndef PRODUCT 1282 virtual void dump2( Dict &d, uint depth, outputStream *st ) const; 1283 #endif 1284 }; 1285 1286 //------------------------------TypeFunc--------------------------------------- 1287 // Class of Array Types 1288 class TypeFunc : public Type { 1289 TypeFunc( const TypeTuple *domain, const TypeTuple *range ) : Type(Function), _domain(domain), _range(range) {} 1290 virtual bool eq( const Type *t ) const; 1291 virtual int hash() const; // Type specific hashing 1292 virtual bool singleton(void) const; // TRUE if type is a singleton 1293 virtual bool empty(void) const; // TRUE if type is vacuous 1294 public: 1295 // Constants are shared among ADLC and VM 1296 enum { Control = AdlcVMDeps::Control, 1297 I_O = AdlcVMDeps::I_O, 1298 Memory = AdlcVMDeps::Memory, 1299 FramePtr = AdlcVMDeps::FramePtr, 1300 ReturnAdr = AdlcVMDeps::ReturnAdr, 1301 Parms = AdlcVMDeps::Parms 1302 }; 1303 1304 const TypeTuple* const _domain; // Domain of inputs 1305 const TypeTuple* const _range; // Range of results 1306 1307 // Accessors: 1308 const TypeTuple* domain() const { return _domain; } 1309 const TypeTuple* range() const { return _range; } 1310 1311 static const TypeFunc *make(ciMethod* method); 1312 static const TypeFunc *make(ciSignature signature, const Type* extra); 1313 static const TypeFunc *make(const TypeTuple* domain, const TypeTuple* range); 1314 1315 virtual const Type *xmeet( const Type *t ) const; 1316 virtual const Type *xdual() const; // Compute dual right now. 1317 1318 BasicType return_type() const; 1319 1320 #ifndef PRODUCT 1321 virtual void dump2( Dict &d, uint depth, outputStream *st ) const; // Specialized per-Type dumping 1322 #endif 1323 // Convenience common pre-built types. 1324 }; 1325 1326 //------------------------------accessors-------------------------------------- 1327 inline bool Type::is_ptr_to_narrowoop() const { 1328 #ifdef _LP64 1329 return (isa_oopptr() != NULL && is_oopptr()->is_ptr_to_narrowoop_nv()); 1330 #else 1331 return false; 1332 #endif 1333 } 1334 1335 inline bool Type::is_ptr_to_narrowklass() const { 1336 #ifdef _LP64 1337 return (isa_oopptr() != NULL && is_oopptr()->is_ptr_to_narrowklass_nv()); 1338 #else 1339 return false; 1340 #endif 1341 } 1342 1343 inline float Type::getf() const { 1344 assert( _base == FloatCon, "Not a FloatCon" ); 1345 return ((TypeF*)this)->_f; 1346 } 1347 1348 inline double Type::getd() const { 1349 assert( _base == DoubleCon, "Not a DoubleCon" ); 1350 return ((TypeD*)this)->_d; 1351 } 1352 1353 inline const TypeInt *Type::is_int() const { 1354 assert( _base == Int, "Not an Int" ); 1355 return (TypeInt*)this; 1356 } 1357 1358 inline const TypeInt *Type::isa_int() const { 1359 return ( _base == Int ? (TypeInt*)this : NULL); 1360 } 1361 1362 inline const TypeLong *Type::is_long() const { 1363 assert( _base == Long, "Not a Long" ); 1364 return (TypeLong*)this; 1365 } 1366 1367 inline const TypeLong *Type::isa_long() const { 1368 return ( _base == Long ? (TypeLong*)this : NULL); 1369 } 1370 1371 inline const TypeF *Type::isa_float() const { 1372 return ((_base == FloatTop || 1373 _base == FloatCon || 1374 _base == FloatBot) ? (TypeF*)this : NULL); 1375 } 1376 1377 inline const TypeF *Type::is_float_constant() const { 1378 assert( _base == FloatCon, "Not a Float" ); 1379 return (TypeF*)this; 1380 } 1381 1382 inline const TypeF *Type::isa_float_constant() const { 1383 return ( _base == FloatCon ? (TypeF*)this : NULL); 1384 } 1385 1386 inline const TypeD *Type::isa_double() const { 1387 return ((_base == DoubleTop || 1388 _base == DoubleCon || 1389 _base == DoubleBot) ? (TypeD*)this : NULL); 1390 } 1391 1392 inline const TypeD *Type::is_double_constant() const { 1393 assert( _base == DoubleCon, "Not a Double" ); 1394 return (TypeD*)this; 1395 } 1396 1397 inline const TypeD *Type::isa_double_constant() const { 1398 return ( _base == DoubleCon ? (TypeD*)this : NULL); 1399 } 1400 1401 inline const TypeTuple *Type::is_tuple() const { 1402 assert( _base == Tuple, "Not a Tuple" ); 1403 return (TypeTuple*)this; 1404 } 1405 1406 inline const TypeAry *Type::is_ary() const { 1407 assert( _base == Array , "Not an Array" ); 1408 return (TypeAry*)this; 1409 } 1410 1411 inline const TypeVect *Type::is_vect() const { 1412 assert( _base >= VectorS && _base <= VectorY, "Not a Vector" ); 1413 return (TypeVect*)this; 1414 } 1415 1416 inline const TypeVect *Type::isa_vect() const { 1417 return (_base >= VectorS && _base <= VectorY) ? (TypeVect*)this : NULL; 1418 } 1419 1420 inline const TypePtr *Type::is_ptr() const { 1421 // AnyPtr is the first Ptr and KlassPtr the last, with no non-ptrs between. 1422 assert(_base >= AnyPtr && _base <= KlassPtr, "Not a pointer"); 1423 return (TypePtr*)this; 1424 } 1425 1426 inline const TypePtr *Type::isa_ptr() const { 1427 // AnyPtr is the first Ptr and KlassPtr the last, with no non-ptrs between. 1428 return (_base >= AnyPtr && _base <= KlassPtr) ? (TypePtr*)this : NULL; 1429 } 1430 1431 inline const TypeOopPtr *Type::is_oopptr() const { 1432 // OopPtr is the first and KlassPtr the last, with no non-oops between. 1433 assert(_base >= OopPtr && _base <= AryPtr, "Not a Java pointer" ) ; 1434 return (TypeOopPtr*)this; 1435 } 1436 1437 inline const TypeOopPtr *Type::isa_oopptr() const { 1438 // OopPtr is the first and KlassPtr the last, with no non-oops between. 1439 return (_base >= OopPtr && _base <= AryPtr) ? (TypeOopPtr*)this : NULL; 1440 } 1441 1442 inline const TypeRawPtr *Type::isa_rawptr() const { 1443 return (_base == RawPtr) ? (TypeRawPtr*)this : NULL; 1444 } 1445 1446 inline const TypeRawPtr *Type::is_rawptr() const { 1447 assert( _base == RawPtr, "Not a raw pointer" ); 1448 return (TypeRawPtr*)this; 1449 } 1450 1451 inline const TypeInstPtr *Type::isa_instptr() const { 1452 return (_base == InstPtr) ? (TypeInstPtr*)this : NULL; 1453 } 1454 1455 inline const TypeInstPtr *Type::is_instptr() const { 1456 assert( _base == InstPtr, "Not an object pointer" ); 1457 return (TypeInstPtr*)this; 1458 } 1459 1460 inline const TypeAryPtr *Type::isa_aryptr() const { 1461 return (_base == AryPtr) ? (TypeAryPtr*)this : NULL; 1462 } 1463 1464 inline const TypeAryPtr *Type::is_aryptr() const { 1465 assert( _base == AryPtr, "Not an array pointer" ); 1466 return (TypeAryPtr*)this; 1467 } 1468 1469 inline const TypeNarrowOop *Type::is_narrowoop() const { 1470 // OopPtr is the first and KlassPtr the last, with no non-oops between. 1471 assert(_base == NarrowOop, "Not a narrow oop" ) ; 1472 return (TypeNarrowOop*)this; 1473 } 1474 1475 inline const TypeNarrowOop *Type::isa_narrowoop() const { 1476 // OopPtr is the first and KlassPtr the last, with no non-oops between. 1477 return (_base == NarrowOop) ? (TypeNarrowOop*)this : NULL; 1478 } 1479 1480 inline const TypeNarrowKlass *Type::is_narrowklass() const { 1481 assert(_base == NarrowKlass, "Not a narrow oop" ) ; 1482 return (TypeNarrowKlass*)this; 1483 } 1484 1485 inline const TypeNarrowKlass *Type::isa_narrowklass() const { 1486 return (_base == NarrowKlass) ? (TypeNarrowKlass*)this : NULL; 1487 } 1488 1489 inline const TypeMetadataPtr *Type::is_metadataptr() const { 1490 // MetadataPtr is the first and CPCachePtr the last 1491 assert(_base == MetadataPtr, "Not a metadata pointer" ) ; 1492 return (TypeMetadataPtr*)this; 1493 } 1494 1495 inline const TypeMetadataPtr *Type::isa_metadataptr() const { 1496 return (_base == MetadataPtr) ? (TypeMetadataPtr*)this : NULL; 1497 } 1498 1499 inline const TypeKlassPtr *Type::isa_klassptr() const { 1500 return (_base == KlassPtr) ? (TypeKlassPtr*)this : NULL; 1501 } 1502 1503 inline const TypeKlassPtr *Type::is_klassptr() const { 1504 assert( _base == KlassPtr, "Not a klass pointer" ); 1505 return (TypeKlassPtr*)this; 1506 } 1507 1508 inline const TypePtr* Type::make_ptr() const { 1509 return (_base == NarrowOop) ? is_narrowoop()->get_ptrtype() : 1510 ((_base == NarrowKlass) ? is_narrowklass()->get_ptrtype() : 1511 (isa_ptr() ? is_ptr() : NULL)); 1512 } 1513 1514 inline const TypeOopPtr* Type::make_oopptr() const { 1515 return (_base == NarrowOop) ? is_narrowoop()->get_ptrtype()->is_oopptr() : is_oopptr(); 1516 } 1517 1518 inline const TypeNarrowOop* Type::make_narrowoop() const { 1519 return (_base == NarrowOop) ? is_narrowoop() : 1520 (isa_ptr() ? TypeNarrowOop::make(is_ptr()) : NULL); 1521 } 1522 1523 inline const TypeNarrowKlass* Type::make_narrowklass() const { 1524 return (_base == NarrowKlass) ? is_narrowklass() : 1525 (isa_ptr() ? TypeNarrowKlass::make(is_ptr()) : NULL); 1526 } 1527 1528 inline bool Type::is_floatingpoint() const { 1529 if( (_base == FloatCon) || (_base == FloatBot) || 1530 (_base == DoubleCon) || (_base == DoubleBot) ) 1531 return true; 1532 return false; 1533 } 1534 1535 inline bool Type::is_ptr_to_boxing_obj() const { 1536 const TypeInstPtr* tp = isa_instptr(); 1537 return (tp != NULL) && (tp->offset() == 0) && 1538 tp->klass()->is_instance_klass() && 1539 tp->klass()->as_instance_klass()->is_box_klass(); 1540 } 1541 1542 1543 // =============================================================== 1544 // Things that need to be 64-bits in the 64-bit build but 1545 // 32-bits in the 32-bit build. Done this way to get full 1546 // optimization AND strong typing. 1547 #ifdef _LP64 1548 1549 // For type queries and asserts 1550 #define is_intptr_t is_long 1551 #define isa_intptr_t isa_long 1552 #define find_intptr_t_type find_long_type 1553 #define find_intptr_t_con find_long_con 1554 #define TypeX TypeLong 1555 #define Type_X Type::Long 1556 #define TypeX_X TypeLong::LONG 1557 #define TypeX_ZERO TypeLong::ZERO 1558 // For 'ideal_reg' machine registers 1559 #define Op_RegX Op_RegL 1560 // For phase->intcon variants 1561 #define MakeConX longcon 1562 #define ConXNode ConLNode 1563 // For array index arithmetic 1564 #define MulXNode MulLNode 1565 #define AndXNode AndLNode 1566 #define OrXNode OrLNode 1567 #define CmpXNode CmpLNode 1568 #define SubXNode SubLNode 1569 #define LShiftXNode LShiftLNode 1570 // For object size computation: 1571 #define AddXNode AddLNode 1572 #define RShiftXNode RShiftLNode 1573 // For card marks and hashcodes 1574 #define URShiftXNode URShiftLNode 1575 // UseOptoBiasInlining 1576 #define XorXNode XorLNode 1577 #define StoreXConditionalNode StoreLConditionalNode 1578 // Opcodes 1579 #define Op_LShiftX Op_LShiftL 1580 #define Op_AndX Op_AndL 1581 #define Op_AddX Op_AddL 1582 #define Op_SubX Op_SubL 1583 #define Op_XorX Op_XorL 1584 #define Op_URShiftX Op_URShiftL 1585 // conversions 1586 #define ConvI2X(x) ConvI2L(x) 1587 #define ConvL2X(x) (x) 1588 #define ConvX2I(x) ConvL2I(x) 1589 #define ConvX2L(x) (x) 1590 1591 #else 1592 1593 // For type queries and asserts 1594 #define is_intptr_t is_int 1595 #define isa_intptr_t isa_int 1596 #define find_intptr_t_type find_int_type 1597 #define find_intptr_t_con find_int_con 1598 #define TypeX TypeInt 1599 #define Type_X Type::Int 1600 #define TypeX_X TypeInt::INT 1601 #define TypeX_ZERO TypeInt::ZERO 1602 // For 'ideal_reg' machine registers 1603 #define Op_RegX Op_RegI 1604 // For phase->intcon variants 1605 #define MakeConX intcon 1606 #define ConXNode ConINode 1607 // For array index arithmetic 1608 #define MulXNode MulINode 1609 #define AndXNode AndINode 1610 #define OrXNode OrINode 1611 #define CmpXNode CmpINode 1612 #define SubXNode SubINode 1613 #define LShiftXNode LShiftINode 1614 // For object size computation: 1615 #define AddXNode AddINode 1616 #define RShiftXNode RShiftINode 1617 // For card marks and hashcodes 1618 #define URShiftXNode URShiftINode 1619 // UseOptoBiasInlining 1620 #define XorXNode XorINode 1621 #define StoreXConditionalNode StoreIConditionalNode 1622 // Opcodes 1623 #define Op_LShiftX Op_LShiftI 1624 #define Op_AndX Op_AndI 1625 #define Op_AddX Op_AddI 1626 #define Op_SubX Op_SubI 1627 #define Op_XorX Op_XorI 1628 #define Op_URShiftX Op_URShiftI 1629 // conversions 1630 #define ConvI2X(x) (x) 1631 #define ConvL2X(x) ConvL2I(x) 1632 #define ConvX2I(x) (x) 1633 #define ConvX2L(x) ConvI2L(x) 1634 1635 #endif 1636 1637 #endif // SHARE_VM_OPTO_TYPE_HPP