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