1 /* 2 * Copyright (c) 1997, 2022, 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_OPTO_TYPE_HPP 26 #define SHARE_OPTO_TYPE_HPP 27 28 #include "ci/ciInlineKlass.hpp" 29 #include "opto/adlcVMDeps.hpp" 30 #include "runtime/handles.hpp" 31 #include "runtime/sharedRuntime.hpp" 32 33 // Portions of code courtesy of Clifford Click 34 35 // Optimization - Graph Style 36 37 38 // This class defines a Type lattice. The lattice is used in the constant 39 // propagation algorithms, and for some type-checking of the iloc code. 40 // Basic types include RSD's (lower bound, upper bound, stride for integers), 41 // float & double precision constants, sets of data-labels and code-labels. 42 // The complete lattice is described below. Subtypes have no relationship to 43 // up or down in the lattice; that is entirely determined by the behavior of 44 // the MEET/JOIN functions. 45 46 class Dict; 47 class Type; 48 class TypeD; 49 class TypeF; 50 class TypeInteger; 51 class TypeInt; 52 class TypeLong; 53 class TypeNarrowPtr; 54 class TypeNarrowOop; 55 class TypeNarrowKlass; 56 class TypeAry; 57 class TypeTuple; 58 class TypeVect; 59 class TypeVectA; 60 class TypeVectS; 61 class TypeVectD; 62 class TypeVectX; 63 class TypeVectY; 64 class TypeVectZ; 65 class TypeVectMask; 66 class TypePtr; 67 class TypeRawPtr; 68 class TypeOopPtr; 69 class TypeInstPtr; 70 class TypeAryPtr; 71 class TypeKlassPtr; 72 class TypeInstKlassPtr; 73 class TypeAryKlassPtr; 74 class TypeMetadataPtr; 75 76 //------------------------------Type------------------------------------------- 77 // Basic Type object, represents a set of primitive Values. 78 // Types are hash-cons'd into a private class dictionary, so only one of each 79 // different kind of Type exists. Types are never modified after creation, so 80 // all their interesting fields are constant. 81 class Type { 82 friend class VMStructs; 83 84 public: 85 enum TYPES { 86 Bad=0, // Type check 87 Control, // Control of code (not in lattice) 88 Top, // Top of the lattice 89 Int, // Integer range (lo-hi) 90 Long, // Long integer range (lo-hi) 91 Half, // Placeholder half of doubleword 92 NarrowOop, // Compressed oop pointer 93 NarrowKlass, // Compressed klass pointer 94 95 Tuple, // Method signature or object layout 96 Array, // Array types 97 98 VectorMask, // Vector predicate/mask type 99 VectorA, // (Scalable) Vector types for vector length agnostic 100 VectorS, // 32bit Vector types 101 VectorD, // 64bit Vector types 102 VectorX, // 128bit Vector types 103 VectorY, // 256bit Vector types 104 VectorZ, // 512bit Vector types 105 106 AnyPtr, // Any old raw, klass, inst, or array pointer 107 RawPtr, // Raw (non-oop) pointers 108 OopPtr, // Any and all Java heap entities 109 InstPtr, // Instance pointers (non-array objects) 110 AryPtr, // Array pointers 111 // (Ptr order matters: See is_ptr, isa_ptr, is_oopptr, isa_oopptr.) 112 113 MetadataPtr, // Generic metadata 114 KlassPtr, // Klass pointers 115 InstKlassPtr, 116 AryKlassPtr, 117 118 Function, // Function signature 119 Abio, // Abstract I/O 120 Return_Address, // Subroutine return address 121 Memory, // Abstract store 122 FloatTop, // No float value 123 FloatCon, // Floating point constant 124 FloatBot, // Any float value 125 DoubleTop, // No double value 126 DoubleCon, // Double precision constant 127 DoubleBot, // Any double value 128 Bottom, // Bottom of lattice 129 lastype // Bogus ending type (not in lattice) 130 }; 131 132 // Signal values for offsets from a base pointer 133 enum OFFSET_SIGNALS { 134 OffsetTop = -2000000000, // undefined offset 135 OffsetBot = -2000000001 // any possible offset 136 }; 137 138 class Offset { 139 private: 140 int _offset; 141 142 public: 143 explicit Offset(int offset) : _offset(offset) {} 144 145 const Offset meet(const Offset other) const; 146 const Offset dual() const; 147 const Offset add(intptr_t offset) const; 148 bool operator==(const Offset& other) const { 149 return _offset == other._offset; 150 } 151 bool operator!=(const Offset& other) const { 152 return _offset != other._offset; 153 } 154 int get() const { return _offset; } 155 156 void dump2(outputStream *st) const; 157 158 static const Offset top; 159 static const Offset bottom; 160 }; 161 162 // Min and max WIDEN values. 163 enum WIDEN { 164 WidenMin = 0, 165 WidenMax = 3 166 }; 167 168 private: 169 typedef struct { 170 TYPES dual_type; 171 BasicType basic_type; 172 const char* msg; 173 bool isa_oop; 174 uint ideal_reg; 175 relocInfo::relocType reloc; 176 } TypeInfo; 177 178 // Dictionary of types shared among compilations. 179 static Dict* _shared_type_dict; 180 static const TypeInfo _type_info[]; 181 182 static int uhash( const Type *const t ); 183 // Structural equality check. Assumes that cmp() has already compared 184 // the _base types and thus knows it can cast 't' appropriately. 185 virtual bool eq( const Type *t ) const; 186 187 // Top-level hash-table of types 188 static Dict *type_dict() { 189 return Compile::current()->type_dict(); 190 } 191 192 // DUAL operation: reflect around lattice centerline. Used instead of 193 // join to ensure my lattice is symmetric up and down. Dual is computed 194 // lazily, on demand, and cached in _dual. 195 const Type *_dual; // Cached dual value 196 197 198 const Type *meet_helper(const Type *t, bool include_speculative) const; 199 void check_symmetrical(const Type *t, const Type *mt) const; 200 201 protected: 202 // Each class of type is also identified by its base. 203 const TYPES _base; // Enum of Types type 204 205 Type( TYPES t ) : _dual(NULL), _base(t) {} // Simple types 206 // ~Type(); // Use fast deallocation 207 const Type *hashcons(); // Hash-cons the type 208 virtual const Type *filter_helper(const Type *kills, bool include_speculative) const; 209 const Type *join_helper(const Type *t, bool include_speculative) const { 210 return dual()->meet_helper(t->dual(), include_speculative)->dual(); 211 } 212 213 public: 214 215 inline void* operator new( size_t x ) throw() { 216 Compile* compile = Compile::current(); 217 compile->set_type_last_size(x); 218 return compile->type_arena()->AmallocWords(x); 219 } 220 inline void operator delete( void* ptr ) { 221 Compile* compile = Compile::current(); 222 compile->type_arena()->Afree(ptr,compile->type_last_size()); 223 } 224 225 // Initialize the type system for a particular compilation. 226 static void Initialize(Compile* compile); 227 228 // Initialize the types shared by all compilations. 229 static void Initialize_shared(Compile* compile); 230 231 TYPES base() const { 232 assert(_base > Bad && _base < lastype, "sanity"); 233 return _base; 234 } 235 236 // Create a new hash-consd type 237 static const Type *make(enum TYPES); 238 // Test for equivalence of types 239 static int cmp( const Type *const t1, const Type *const t2 ); 240 // Test for higher or equal in lattice 241 // Variant that drops the speculative part of the types 242 bool higher_equal(const Type *t) const { 243 return !cmp(meet(t),t->remove_speculative()); 244 } 245 // Variant that keeps the speculative part of the types 246 bool higher_equal_speculative(const Type *t) const { 247 return !cmp(meet_speculative(t),t); 248 } 249 250 // MEET operation; lower in lattice. 251 // Variant that drops the speculative part of the types 252 const Type *meet(const Type *t) const { 253 return meet_helper(t, false); 254 } 255 // Variant that keeps the speculative part of the types 256 const Type *meet_speculative(const Type *t) const { 257 return meet_helper(t, true)->cleanup_speculative(); 258 } 259 // WIDEN: 'widens' for Ints and other range types 260 virtual const Type *widen( const Type *old, const Type* limit ) const { return this; } 261 // NARROW: complement for widen, used by pessimistic phases 262 virtual const Type *narrow( const Type *old ) const { return this; } 263 264 // DUAL operation: reflect around lattice centerline. Used instead of 265 // join to ensure my lattice is symmetric up and down. 266 const Type *dual() const { return _dual; } 267 268 // Compute meet dependent on base type 269 virtual const Type *xmeet( const Type *t ) const; 270 virtual const Type *xdual() const; // Compute dual right now. 271 272 // JOIN operation; higher in lattice. Done by finding the dual of the 273 // meet of the dual of the 2 inputs. 274 // Variant that drops the speculative part of the types 275 const Type *join(const Type *t) const { 276 return join_helper(t, false); 277 } 278 // Variant that keeps the speculative part of the types 279 const Type *join_speculative(const Type *t) const { 280 return join_helper(t, true)->cleanup_speculative(); 281 } 282 283 // Modified version of JOIN adapted to the needs Node::Value. 284 // Normalizes all empty values to TOP. Does not kill _widen bits. 285 // Variant that drops the speculative part of the types 286 const Type *filter(const Type *kills) const { 287 return filter_helper(kills, false); 288 } 289 // Variant that keeps the speculative part of the types 290 const Type *filter_speculative(const Type *kills) const { 291 return filter_helper(kills, true)->cleanup_speculative(); 292 } 293 294 // Returns true if this pointer points at memory which contains a 295 // compressed oop references. 296 bool is_ptr_to_narrowoop() const; 297 bool is_ptr_to_narrowklass() const; 298 299 // Convenience access 300 float getf() const; 301 double getd() const; 302 303 const TypeInt *is_int() const; 304 const TypeInt *isa_int() const; // Returns NULL if not an Int 305 const TypeInteger* is_integer(BasicType bt) const; 306 const TypeInteger* isa_integer(BasicType bt) const; 307 const TypeLong *is_long() const; 308 const TypeLong *isa_long() const; // Returns NULL if not a Long 309 const TypeD *isa_double() const; // Returns NULL if not a Double{Top,Con,Bot} 310 const TypeD *is_double_constant() const; // Asserts it is a DoubleCon 311 const TypeD *isa_double_constant() const; // Returns NULL if not a DoubleCon 312 const TypeF *isa_float() const; // Returns NULL if not a Float{Top,Con,Bot} 313 const TypeF *is_float_constant() const; // Asserts it is a FloatCon 314 const TypeF *isa_float_constant() const; // Returns NULL if not a FloatCon 315 const TypeTuple *is_tuple() const; // Collection of fields, NOT a pointer 316 const TypeAry *is_ary() const; // Array, NOT array pointer 317 const TypeAry *isa_ary() const; // Returns NULL of not ary 318 const TypeVect *is_vect() const; // Vector 319 const TypeVect *isa_vect() const; // Returns NULL if not a Vector 320 const TypeVectMask *is_vectmask() const; // Predicate/Mask Vector 321 const TypeVectMask *isa_vectmask() const; // Returns NULL if not a Vector Predicate/Mask 322 const TypePtr *is_ptr() const; // Asserts it is a ptr type 323 const TypePtr *isa_ptr() const; // Returns NULL if not ptr type 324 const TypeRawPtr *isa_rawptr() const; // NOT Java oop 325 const TypeRawPtr *is_rawptr() const; // Asserts is rawptr 326 const TypeNarrowOop *is_narrowoop() const; // Java-style GC'd pointer 327 const TypeNarrowOop *isa_narrowoop() const; // Returns NULL if not oop ptr type 328 const TypeNarrowKlass *is_narrowklass() const; // compressed klass pointer 329 const TypeNarrowKlass *isa_narrowklass() const;// Returns NULL if not oop ptr type 330 const TypeOopPtr *isa_oopptr() const; // Returns NULL if not oop ptr type 331 const TypeOopPtr *is_oopptr() const; // Java-style GC'd pointer 332 const TypeInstPtr *isa_instptr() const; // Returns NULL if not InstPtr 333 const TypeInstPtr *is_instptr() const; // Instance 334 const TypeAryPtr *isa_aryptr() const; // Returns NULL if not AryPtr 335 const TypeAryPtr *is_aryptr() const; // Array oop 336 337 const TypeMetadataPtr *isa_metadataptr() const; // Returns NULL if not oop ptr type 338 const TypeMetadataPtr *is_metadataptr() const; // Java-style GC'd pointer 339 const TypeKlassPtr *isa_klassptr() const; // Returns NULL if not KlassPtr 340 const TypeKlassPtr *is_klassptr() const; // assert if not KlassPtr 341 const TypeInstKlassPtr *isa_instklassptr() const; // Returns NULL if not IntKlassPtr 342 const TypeInstKlassPtr *is_instklassptr() const; // assert if not IntKlassPtr 343 const TypeAryKlassPtr *isa_aryklassptr() const; // Returns NULL if not AryKlassPtr 344 const TypeAryKlassPtr *is_aryklassptr() const; // assert if not AryKlassPtr 345 346 virtual bool is_finite() const; // Has a finite value 347 virtual bool is_nan() const; // Is not a number (NaN) 348 349 bool is_inlinetypeptr() const; 350 virtual ciInlineKlass* inline_klass() const; 351 352 // Returns this ptr type or the equivalent ptr type for this compressed pointer. 353 const TypePtr* make_ptr() const; 354 355 // Returns this oopptr type or the equivalent oopptr type for this compressed pointer. 356 // Asserts if the underlying type is not an oopptr or narrowoop. 357 const TypeOopPtr* make_oopptr() const; 358 359 // Returns this compressed pointer or the equivalent compressed version 360 // of this pointer type. 361 const TypeNarrowOop* make_narrowoop() const; 362 363 // Returns this compressed klass pointer or the equivalent 364 // compressed version of this pointer type. 365 const TypeNarrowKlass* make_narrowklass() const; 366 367 // Special test for register pressure heuristic 368 bool is_floatingpoint() const; // True if Float or Double base type 369 370 // Do you have memory, directly or through a tuple? 371 bool has_memory( ) const; 372 373 // TRUE if type is a singleton 374 virtual bool singleton(void) const; 375 376 // TRUE if type is above the lattice centerline, and is therefore vacuous 377 virtual bool empty(void) const; 378 379 // Return a hash for this type. The hash function is public so ConNode 380 // (constants) can hash on their constant, which is represented by a Type. 381 virtual int hash() const; 382 383 // Map ideal registers (machine types) to ideal types 384 static const Type *mreg2type[]; 385 386 // Printing, statistics 387 #ifndef PRODUCT 388 void dump_on(outputStream *st) const; 389 void dump() const { 390 dump_on(tty); 391 } 392 virtual void dump2( Dict &d, uint depth, outputStream *st ) const; 393 static void dump_stats(); 394 // Groups of types, for debugging and visualization only. 395 enum class Category { 396 Data, 397 Memory, 398 Mixed, // Tuples with types of different categories. 399 Control, 400 Other, // {Type::Top, Type::Abio, Type::Bottom}. 401 Undef // {Type::Bad, Type::lastype}, for completeness. 402 }; 403 // Return the category of this type. 404 Category category() const; 405 // Check recursively in tuples. 406 bool has_category(Category cat) const; 407 408 static const char* str(const Type* t); 409 #endif // !PRODUCT 410 void typerr(const Type *t) const; // Mixing types error 411 412 // Create basic type 413 static const Type* get_const_basic_type(BasicType type) { 414 assert((uint)type <= T_CONFLICT && _const_basic_type[type] != NULL, "bad type"); 415 return _const_basic_type[type]; 416 } 417 418 // For two instance arrays of same dimension, return the base element types. 419 // Otherwise or if the arrays have different dimensions, return NULL. 420 static void get_arrays_base_elements(const Type *a1, const Type *a2, 421 const TypeInstPtr **e1, const TypeInstPtr **e2); 422 423 // Mapping to the array element's basic type. 424 BasicType array_element_basic_type() const; 425 426 enum InterfaceHandling { 427 trust_interfaces, 428 ignore_interfaces 429 }; 430 // Create standard type for a ciType: 431 static const Type* get_const_type(ciType* type, InterfaceHandling interface_handling = ignore_interfaces); 432 433 // Create standard zero value: 434 static const Type* get_zero_type(BasicType type) { 435 assert((uint)type <= T_CONFLICT && _zero_type[type] != NULL, "bad type"); 436 return _zero_type[type]; 437 } 438 439 // Report if this is a zero value (not top). 440 bool is_zero_type() const { 441 BasicType type = basic_type(); 442 if (type == T_VOID || type >= T_CONFLICT) 443 return false; 444 else 445 return (this == _zero_type[type]); 446 } 447 448 // Convenience common pre-built types. 449 static const Type *ABIO; 450 static const Type *BOTTOM; 451 static const Type *CONTROL; 452 static const Type *DOUBLE; 453 static const Type *FLOAT; 454 static const Type *HALF; 455 static const Type *MEMORY; 456 static const Type *MULTI; 457 static const Type *RETURN_ADDRESS; 458 static const Type *TOP; 459 460 // Mapping from compiler type to VM BasicType 461 BasicType basic_type() const { return _type_info[_base].basic_type; } 462 uint ideal_reg() const { return _type_info[_base].ideal_reg; } 463 const char* msg() const { return _type_info[_base].msg; } 464 bool isa_oop_ptr() const { return _type_info[_base].isa_oop; } 465 relocInfo::relocType reloc() const { return _type_info[_base].reloc; } 466 467 // Mapping from CI type system to compiler type: 468 static const Type* get_typeflow_type(ciType* type); 469 470 static const Type* make_from_constant(ciConstant constant, 471 bool require_constant = false, 472 int stable_dimension = 0, 473 bool is_narrow = false, 474 bool is_autobox_cache = false); 475 476 static const Type* make_constant_from_field(ciInstance* holder, 477 int off, 478 bool is_unsigned_load, 479 BasicType loadbt); 480 481 static const Type* make_constant_from_field(ciField* field, 482 ciInstance* holder, 483 BasicType loadbt, 484 bool is_unsigned_load); 485 486 static const Type* make_constant_from_array_element(ciArray* array, 487 int off, 488 int stable_dimension, 489 BasicType loadbt, 490 bool is_unsigned_load); 491 492 // Speculative type helper methods. See TypePtr. 493 virtual const TypePtr* speculative() const { return NULL; } 494 virtual ciKlass* speculative_type() const { return NULL; } 495 virtual ciKlass* speculative_type_not_null() const { return NULL; } 496 virtual bool speculative_maybe_null() const { return true; } 497 virtual bool speculative_always_null() const { return true; } 498 virtual const Type* remove_speculative() const { return this; } 499 virtual const Type* cleanup_speculative() const { return this; } 500 virtual bool would_improve_type(ciKlass* exact_kls, int inline_depth) const { return exact_kls != NULL; } 501 virtual bool would_improve_ptr(ProfilePtrKind ptr_kind) const { return ptr_kind == ProfileAlwaysNull || ptr_kind == ProfileNeverNull; } 502 const Type* maybe_remove_speculative(bool include_speculative) const; 503 504 virtual bool maybe_null() const { return true; } 505 virtual bool is_known_instance() const { return false; } 506 507 private: 508 // support arrays 509 static const Type* _zero_type[T_CONFLICT+1]; 510 static const Type* _const_basic_type[T_CONFLICT+1]; 511 }; 512 513 //------------------------------TypeF------------------------------------------ 514 // Class of Float-Constant Types. 515 class TypeF : public Type { 516 TypeF( float f ) : Type(FloatCon), _f(f) {}; 517 public: 518 virtual bool eq( const Type *t ) const; 519 virtual int hash() const; // Type specific hashing 520 virtual bool singleton(void) const; // TRUE if type is a singleton 521 virtual bool empty(void) const; // TRUE if type is vacuous 522 public: 523 const float _f; // Float constant 524 525 static const TypeF *make(float f); 526 527 virtual bool is_finite() const; // Has a finite value 528 virtual bool is_nan() const; // Is not a number (NaN) 529 530 virtual const Type *xmeet( const Type *t ) const; 531 virtual const Type *xdual() const; // Compute dual right now. 532 // Convenience common pre-built types. 533 static const TypeF *MAX; 534 static const TypeF *MIN; 535 static const TypeF *ZERO; // positive zero only 536 static const TypeF *ONE; 537 static const TypeF *POS_INF; 538 static const TypeF *NEG_INF; 539 #ifndef PRODUCT 540 virtual void dump2( Dict &d, uint depth, outputStream *st ) const; 541 #endif 542 }; 543 544 //------------------------------TypeD------------------------------------------ 545 // Class of Double-Constant Types. 546 class TypeD : public Type { 547 TypeD( double d ) : Type(DoubleCon), _d(d) {}; 548 public: 549 virtual bool eq( const Type *t ) const; 550 virtual int hash() const; // Type specific hashing 551 virtual bool singleton(void) const; // TRUE if type is a singleton 552 virtual bool empty(void) const; // TRUE if type is vacuous 553 public: 554 const double _d; // Double constant 555 556 static const TypeD *make(double d); 557 558 virtual bool is_finite() const; // Has a finite value 559 virtual bool is_nan() const; // Is not a number (NaN) 560 561 virtual const Type *xmeet( const Type *t ) const; 562 virtual const Type *xdual() const; // Compute dual right now. 563 // Convenience common pre-built types. 564 static const TypeD *MAX; 565 static const TypeD *MIN; 566 static const TypeD *ZERO; // positive zero only 567 static const TypeD *ONE; 568 static const TypeD *POS_INF; 569 static const TypeD *NEG_INF; 570 #ifndef PRODUCT 571 virtual void dump2( Dict &d, uint depth, outputStream *st ) const; 572 #endif 573 }; 574 575 class TypeInteger : public Type { 576 protected: 577 TypeInteger(TYPES t, int w) : Type(t), _widen(w) {} 578 579 public: 580 const short _widen; // Limit on times we widen this sucker 581 582 virtual jlong hi_as_long() const = 0; 583 virtual jlong lo_as_long() const = 0; 584 jlong get_con_as_long(BasicType bt) const; 585 bool is_con() const { return lo_as_long() == hi_as_long(); } 586 virtual short widen_limit() const { return _widen; } 587 588 static const TypeInteger* make(jlong lo, jlong hi, int w, BasicType bt); 589 590 static const TypeInteger* bottom(BasicType type); 591 static const TypeInteger* zero(BasicType type); 592 static const TypeInteger* one(BasicType type); 593 static const TypeInteger* minus_1(BasicType type); 594 }; 595 596 597 598 //------------------------------TypeInt---------------------------------------- 599 // Class of integer ranges, the set of integers between a lower bound and an 600 // upper bound, inclusive. 601 class TypeInt : public TypeInteger { 602 TypeInt( jint lo, jint hi, int w ); 603 protected: 604 virtual const Type *filter_helper(const Type *kills, bool include_speculative) const; 605 606 public: 607 typedef jint NativeType; 608 virtual bool eq( const Type *t ) const; 609 virtual int hash() const; // Type specific hashing 610 virtual bool singleton(void) const; // TRUE if type is a singleton 611 virtual bool empty(void) const; // TRUE if type is vacuous 612 const jint _lo, _hi; // Lower bound, upper bound 613 614 static const TypeInt *make(jint lo); 615 // must always specify w 616 static const TypeInt *make(jint lo, jint hi, int w); 617 618 // Check for single integer 619 bool is_con() const { return _lo==_hi; } 620 bool is_con(jint i) const { return is_con() && _lo == i; } 621 jint get_con() const { assert(is_con(), "" ); return _lo; } 622 623 virtual bool is_finite() const; // Has a finite value 624 625 virtual const Type *xmeet( const Type *t ) const; 626 virtual const Type *xdual() const; // Compute dual right now. 627 virtual const Type *widen( const Type *t, const Type* limit_type ) const; 628 virtual const Type *narrow( const Type *t ) const; 629 630 virtual jlong hi_as_long() const { return _hi; } 631 virtual jlong lo_as_long() const { return _lo; } 632 633 // Do not kill _widen bits. 634 // Convenience common pre-built types. 635 static const TypeInt *MAX; 636 static const TypeInt *MIN; 637 static const TypeInt *MINUS_1; 638 static const TypeInt *ZERO; 639 static const TypeInt *ONE; 640 static const TypeInt *BOOL; 641 static const TypeInt *CC; 642 static const TypeInt *CC_LT; // [-1] == MINUS_1 643 static const TypeInt *CC_GT; // [1] == ONE 644 static const TypeInt *CC_EQ; // [0] == ZERO 645 static const TypeInt *CC_LE; // [-1,0] 646 static const TypeInt *CC_GE; // [0,1] == BOOL (!) 647 static const TypeInt *BYTE; 648 static const TypeInt *UBYTE; 649 static const TypeInt *CHAR; 650 static const TypeInt *SHORT; 651 static const TypeInt *POS; 652 static const TypeInt *POS1; 653 static const TypeInt *INT; 654 static const TypeInt *SYMINT; // symmetric range [-max_jint..max_jint] 655 static const TypeInt *TYPE_DOMAIN; // alias for TypeInt::INT 656 657 static const TypeInt *as_self(const Type *t) { return t->is_int(); } 658 #ifndef PRODUCT 659 virtual void dump2( Dict &d, uint depth, outputStream *st ) const; 660 #endif 661 }; 662 663 664 //------------------------------TypeLong--------------------------------------- 665 // Class of long integer ranges, the set of integers between a lower bound and 666 // an upper bound, inclusive. 667 class TypeLong : public TypeInteger { 668 TypeLong( jlong lo, jlong hi, int w ); 669 protected: 670 // Do not kill _widen bits. 671 virtual const Type *filter_helper(const Type *kills, bool include_speculative) const; 672 public: 673 typedef jlong NativeType; 674 virtual bool eq( const Type *t ) const; 675 virtual int hash() const; // Type specific hashing 676 virtual bool singleton(void) const; // TRUE if type is a singleton 677 virtual bool empty(void) const; // TRUE if type is vacuous 678 public: 679 const jlong _lo, _hi; // Lower bound, upper bound 680 681 static const TypeLong *make(jlong lo); 682 // must always specify w 683 static const TypeLong *make(jlong lo, jlong hi, int w); 684 685 // Check for single integer 686 bool is_con() const { return _lo==_hi; } 687 bool is_con(jlong i) const { return is_con() && _lo == i; } 688 jlong get_con() const { assert(is_con(), "" ); return _lo; } 689 690 // Check for positive 32-bit value. 691 int is_positive_int() const { return _lo >= 0 && _hi <= (jlong)max_jint; } 692 693 virtual bool is_finite() const; // Has a finite value 694 695 virtual jlong hi_as_long() const { return _hi; } 696 virtual jlong lo_as_long() const { return _lo; } 697 698 virtual const Type *xmeet( const Type *t ) const; 699 virtual const Type *xdual() const; // Compute dual right now. 700 virtual const Type *widen( const Type *t, const Type* limit_type ) const; 701 virtual const Type *narrow( const Type *t ) const; 702 // Convenience common pre-built types. 703 static const TypeLong *MAX; 704 static const TypeLong *MIN; 705 static const TypeLong *MINUS_1; 706 static const TypeLong *ZERO; 707 static const TypeLong *ONE; 708 static const TypeLong *POS; 709 static const TypeLong *LONG; 710 static const TypeLong *INT; // 32-bit subrange [min_jint..max_jint] 711 static const TypeLong *UINT; // 32-bit unsigned [0..max_juint] 712 static const TypeLong *TYPE_DOMAIN; // alias for TypeLong::LONG 713 714 // static convenience methods. 715 static const TypeLong *as_self(const Type *t) { return t->is_long(); } 716 717 #ifndef PRODUCT 718 virtual void dump2( Dict &d, uint, outputStream *st ) const;// Specialized per-Type dumping 719 #endif 720 }; 721 722 //------------------------------TypeTuple-------------------------------------- 723 // Class of Tuple Types, essentially type collections for function signatures 724 // and class layouts. It happens to also be a fast cache for the HotSpot 725 // signature types. 726 class TypeTuple : public Type { 727 TypeTuple( uint cnt, const Type **fields ) : Type(Tuple), _cnt(cnt), _fields(fields) { } 728 729 const uint _cnt; // Count of fields 730 const Type ** const _fields; // Array of field types 731 732 public: 733 virtual bool eq( const Type *t ) const; 734 virtual int hash() const; // Type specific hashing 735 virtual bool singleton(void) const; // TRUE if type is a singleton 736 virtual bool empty(void) const; // TRUE if type is vacuous 737 738 // Accessors: 739 uint cnt() const { return _cnt; } 740 const Type* field_at(uint i) const { 741 assert(i < _cnt, "oob"); 742 return _fields[i]; 743 } 744 void set_field_at(uint i, const Type* t) { 745 assert(i < _cnt, "oob"); 746 _fields[i] = t; 747 } 748 749 static const TypeTuple *make( uint cnt, const Type **fields ); 750 static const TypeTuple *make_range(ciSignature* sig, InterfaceHandling interface_handling = ignore_interfaces, bool ret_vt_fields = false); 751 static const TypeTuple *make_domain(ciMethod* method, InterfaceHandling interface_handling, bool vt_fields_as_args = false); 752 753 // Subroutine call type with space allocated for argument types 754 // Memory for Control, I_O, Memory, FramePtr, and ReturnAdr is allocated implicitly 755 static const Type **fields( uint arg_cnt ); 756 757 virtual const Type *xmeet( const Type *t ) const; 758 virtual const Type *xdual() const; // Compute dual right now. 759 // Convenience common pre-built types. 760 static const TypeTuple *IFBOTH; 761 static const TypeTuple *IFFALSE; 762 static const TypeTuple *IFTRUE; 763 static const TypeTuple *IFNEITHER; 764 static const TypeTuple *LOOPBODY; 765 static const TypeTuple *MEMBAR; 766 static const TypeTuple *STORECONDITIONAL; 767 static const TypeTuple *START_I2C; 768 static const TypeTuple *INT_PAIR; 769 static const TypeTuple *LONG_PAIR; 770 static const TypeTuple *INT_CC_PAIR; 771 static const TypeTuple *LONG_CC_PAIR; 772 #ifndef PRODUCT 773 virtual void dump2( Dict &d, uint, outputStream *st ) const; // Specialized per-Type dumping 774 #endif 775 }; 776 777 //------------------------------TypeAry---------------------------------------- 778 // Class of Array Types 779 class TypeAry : public Type { 780 TypeAry(const Type* elem, const TypeInt* size, bool stable, bool flat, bool not_flat, bool not_null_free) : Type(Array), 781 _elem(elem), _size(size), _stable(stable), _flat(flat), _not_flat(not_flat), _not_null_free(not_null_free) {} 782 public: 783 virtual bool eq( const Type *t ) const; 784 virtual int hash() const; // Type specific hashing 785 virtual bool singleton(void) const; // TRUE if type is a singleton 786 virtual bool empty(void) const; // TRUE if type is vacuous 787 788 private: 789 const Type *_elem; // Element type of array 790 const TypeInt *_size; // Elements in array 791 const bool _stable; // Are elements @Stable? 792 793 // Inline type array properties 794 const bool _flat; // Array is flattened 795 const bool _not_flat; // Array is never flattened 796 const bool _not_null_free; // Array is never null-free 797 798 friend class TypeAryPtr; 799 800 public: 801 static const TypeAry* make(const Type* elem, const TypeInt* size, bool stable = false, 802 bool flat = false, bool not_flat = false, bool not_null_free = false); 803 804 virtual const Type *xmeet( const Type *t ) const; 805 virtual const Type *xdual() const; // Compute dual right now. 806 bool ary_must_be_exact() const; // true if arrays of such are never generic 807 virtual const TypeAry* remove_speculative() const; 808 virtual const Type* cleanup_speculative() const; 809 #ifndef PRODUCT 810 virtual void dump2( Dict &d, uint, outputStream *st ) const; // Specialized per-Type dumping 811 #endif 812 }; 813 814 //------------------------------TypeVect--------------------------------------- 815 // Class of Vector Types 816 class TypeVect : public Type { 817 const Type* _elem; // Vector's element type 818 const uint _length; // Elements in vector (power of 2) 819 820 protected: 821 TypeVect(TYPES t, const Type* elem, uint length) : Type(t), 822 _elem(elem), _length(length) {} 823 824 public: 825 const Type* element_type() const { return _elem; } 826 BasicType element_basic_type() const { return _elem->array_element_basic_type(); } 827 uint length() const { return _length; } 828 uint length_in_bytes() const { 829 return _length * type2aelembytes(element_basic_type()); 830 } 831 832 virtual bool eq(const Type *t) const; 833 virtual int hash() const; // Type specific hashing 834 virtual bool singleton(void) const; // TRUE if type is a singleton 835 virtual bool empty(void) const; // TRUE if type is vacuous 836 837 static const TypeVect *make(const BasicType elem_bt, uint length, bool is_mask = false) { 838 // Use bottom primitive type. 839 return make(get_const_basic_type(elem_bt), length, is_mask); 840 } 841 // Used directly by Replicate nodes to construct singleton vector. 842 static const TypeVect *make(const Type* elem, uint length, bool is_mask = false); 843 844 static const TypeVect *makemask(const BasicType elem_bt, uint length) { 845 // Use bottom primitive type. 846 return makemask(get_const_basic_type(elem_bt), length); 847 } 848 static const TypeVect *makemask(const Type* elem, uint length); 849 850 851 virtual const Type *xmeet( const Type *t) const; 852 virtual const Type *xdual() const; // Compute dual right now. 853 854 static const TypeVect *VECTA; 855 static const TypeVect *VECTS; 856 static const TypeVect *VECTD; 857 static const TypeVect *VECTX; 858 static const TypeVect *VECTY; 859 static const TypeVect *VECTZ; 860 static const TypeVect *VECTMASK; 861 862 #ifndef PRODUCT 863 virtual void dump2(Dict &d, uint, outputStream *st) const; // Specialized per-Type dumping 864 #endif 865 }; 866 867 class TypeVectA : public TypeVect { 868 friend class TypeVect; 869 TypeVectA(const Type* elem, uint length) : TypeVect(VectorA, elem, length) {} 870 }; 871 872 class TypeVectS : public TypeVect { 873 friend class TypeVect; 874 TypeVectS(const Type* elem, uint length) : TypeVect(VectorS, elem, length) {} 875 }; 876 877 class TypeVectD : public TypeVect { 878 friend class TypeVect; 879 TypeVectD(const Type* elem, uint length) : TypeVect(VectorD, elem, length) {} 880 }; 881 882 class TypeVectX : public TypeVect { 883 friend class TypeVect; 884 TypeVectX(const Type* elem, uint length) : TypeVect(VectorX, elem, length) {} 885 }; 886 887 class TypeVectY : public TypeVect { 888 friend class TypeVect; 889 TypeVectY(const Type* elem, uint length) : TypeVect(VectorY, elem, length) {} 890 }; 891 892 class TypeVectZ : public TypeVect { 893 friend class TypeVect; 894 TypeVectZ(const Type* elem, uint length) : TypeVect(VectorZ, elem, length) {} 895 }; 896 897 class TypeVectMask : public TypeVect { 898 public: 899 friend class TypeVect; 900 TypeVectMask(const Type* elem, uint length) : TypeVect(VectorMask, elem, length) {} 901 virtual bool eq(const Type *t) const; 902 virtual const Type *xdual() const; 903 static const TypeVectMask* make(const BasicType elem_bt, uint length); 904 static const TypeVectMask* make(const Type* elem, uint length); 905 }; 906 907 //------------------------------TypePtr---------------------------------------- 908 // Class of machine Pointer Types: raw data, instances or arrays. 909 // If the _base enum is AnyPtr, then this refers to all of the above. 910 // Otherwise the _base will indicate which subset of pointers is affected, 911 // and the class will be inherited from. 912 class TypePtr : public Type { 913 friend class TypeNarrowPtr; 914 friend class Type; 915 protected: 916 class InterfaceSet { 917 private: 918 GrowableArray<ciKlass*> _list; 919 void raw_add(ciKlass* interface); 920 void add(ciKlass* interface); 921 void verify() const; 922 int _hash_computed:1; 923 int _exact_klass_computed:1; 924 int _is_loaded_computed:1; 925 int _hash; 926 ciKlass* _exact_klass; 927 bool _is_loaded; 928 void compute_hash(); 929 void compute_exact_klass(); 930 public: 931 InterfaceSet(); 932 InterfaceSet(GrowableArray<ciInstanceKlass*>* interfaces); 933 bool eq(const InterfaceSet& other) const; 934 int hash() const; 935 void dump(outputStream *st) const; 936 InterfaceSet union_with(const InterfaceSet& other) const; 937 InterfaceSet intersection_with(const InterfaceSet& other) const; 938 bool contains(const InterfaceSet& other) const { 939 return intersection_with(other).eq(other); 940 } 941 bool empty() const { return _list.length() == 0; } 942 943 inline void* operator new(size_t x) throw() { 944 Compile* compile = Compile::current(); 945 return compile->type_arena()->AmallocWords(x); 946 } 947 inline void operator delete( void* ptr ) { 948 ShouldNotReachHere(); 949 } 950 ciKlass* exact_klass() const; 951 bool is_loaded() const; 952 953 static int compare(ciKlass* const &, ciKlass* const & k2); 954 955 void compute_is_loaded(); 956 }; 957 958 static InterfaceSet interfaces(ciKlass*& k, bool klass, bool interface, bool array, InterfaceHandling interface_handling); 959 960 public: 961 enum PTR { TopPTR, AnyNull, Constant, Null, NotNull, BotPTR, lastPTR }; 962 protected: 963 TypePtr(TYPES t, PTR ptr, Offset offset, 964 const TypePtr* speculative = NULL, 965 int inline_depth = InlineDepthBottom) : 966 Type(t), _speculative(speculative), _inline_depth(inline_depth), _offset(offset), 967 _ptr(ptr) {} 968 static const PTR ptr_meet[lastPTR][lastPTR]; 969 static const PTR ptr_dual[lastPTR]; 970 static const char * const ptr_msg[lastPTR]; 971 972 enum { 973 InlineDepthBottom = INT_MAX, 974 InlineDepthTop = -InlineDepthBottom 975 }; 976 977 // Extra type information profiling gave us. We propagate it the 978 // same way the rest of the type info is propagated. If we want to 979 // use it, then we have to emit a guard: this part of the type is 980 // not something we know but something we speculate about the type. 981 const TypePtr* _speculative; 982 // For speculative types, we record at what inlining depth the 983 // profiling point that provided the data is. We want to favor 984 // profile data coming from outer scopes which are likely better for 985 // the current compilation. 986 int _inline_depth; 987 988 // utility methods to work on the speculative part of the type 989 const TypePtr* dual_speculative() const; 990 const TypePtr* xmeet_speculative(const TypePtr* other) const; 991 bool eq_speculative(const TypePtr* other) const; 992 int hash_speculative() const; 993 const TypePtr* add_offset_speculative(intptr_t offset) const; 994 const TypePtr* with_offset_speculative(intptr_t offset) const; 995 #ifndef PRODUCT 996 void dump_speculative(outputStream *st) const; 997 #endif 998 999 // utility methods to work on the inline depth of the type 1000 int dual_inline_depth() const; 1001 int meet_inline_depth(int depth) const; 1002 #ifndef PRODUCT 1003 void dump_inline_depth(outputStream *st) const; 1004 #endif 1005 1006 // TypeInstPtr (TypeAryPtr resp.) and TypeInstKlassPtr (TypeAryKlassPtr resp.) implement very similar meet logic. 1007 // The logic for meeting 2 instances (2 arrays resp.) is shared in the 2 utility methods below. However the logic for 1008 // the oop and klass versions can be slightly different and extra logic may have to be executed depending on what 1009 // exact case the meet falls into. The MeetResult struct is used by the utility methods to communicate what case was 1010 // encountered so the right logic specific to klasses or oops can be executed., 1011 enum MeetResult { 1012 QUICK, 1013 UNLOADED, 1014 SUBTYPE, 1015 NOT_SUBTYPE, 1016 LCA 1017 }; 1018 template<class T> static TypePtr::MeetResult meet_instptr(PTR& ptr, InterfaceSet& interfaces, const T* this_type, const T* other_type, 1019 ciKlass*& res_klass, bool& res_xk, bool& res_flatten_array); 1020 1021 template<class T> static MeetResult meet_aryptr(PTR& ptr, const Type*& elem, const T* this_ary, const T* other_ary, 1022 ciKlass*& res_klass, bool& res_xk, bool &res_flat, bool &res_not_flat, bool &res_not_null_free); 1023 1024 template <class T1, class T2> static bool is_java_subtype_of_helper_for_instance(const T1* this_one, const T2* other, bool this_exact, bool other_exact); 1025 template <class T1, class T2> static bool is_same_java_type_as_helper_for_instance(const T1* this_one, const T2* other); 1026 template <class T1, class T2> static bool maybe_java_subtype_of_helper_for_instance(const T1* this_one, const T2* other, bool this_exact, bool other_exact); 1027 template <class T1, class T2> static bool is_java_subtype_of_helper_for_array(const T1* this_one, const T2* other, bool this_exact, bool other_exact); 1028 template <class T1, class T2> static bool is_same_java_type_as_helper_for_array(const T1* this_one, const T2* other); 1029 template <class T1, class T2> static bool maybe_java_subtype_of_helper_for_array(const T1* this_one, const T2* other, bool this_exact, bool other_exact); 1030 template <class T1, class T2> static bool is_meet_subtype_of_helper_for_instance(const T1* this_one, const T2* other, bool this_xk, bool other_xk); 1031 template <class T1, class T2> static bool is_meet_subtype_of_helper_for_array(const T1* this_one, const T2* other, bool this_xk, bool other_xk); 1032 public: 1033 const Offset _offset; // Offset into oop, with TOP & BOT 1034 const PTR _ptr; // Pointer equivalence class 1035 1036 const int offset() const { return _offset.get(); } 1037 const PTR ptr() const { return _ptr; } 1038 1039 static const TypePtr* make(TYPES t, PTR ptr, Offset offset, 1040 const TypePtr* speculative = NULL, 1041 int inline_depth = InlineDepthBottom); 1042 1043 // Return a 'ptr' version of this type 1044 virtual const TypePtr* cast_to_ptr_type(PTR ptr) const; 1045 1046 virtual intptr_t get_con() const; 1047 1048 Type::Offset xadd_offset(intptr_t offset) const; 1049 virtual const TypePtr* add_offset(intptr_t offset) const; 1050 virtual const TypePtr* with_offset(intptr_t offset) const; 1051 virtual const int flattened_offset() const { return offset(); } 1052 virtual bool eq(const Type *t) const; 1053 virtual int hash() const; // Type specific hashing 1054 1055 virtual bool singleton(void) const; // TRUE if type is a singleton 1056 virtual bool empty(void) const; // TRUE if type is vacuous 1057 virtual const Type *xmeet( const Type *t ) const; 1058 virtual const Type *xmeet_helper( const Type *t ) const; 1059 Offset meet_offset(int offset) const; 1060 Offset dual_offset() const; 1061 virtual const Type *xdual() const; // Compute dual right now. 1062 1063 // meet, dual and join over pointer equivalence sets 1064 PTR meet_ptr( const PTR in_ptr ) const { return ptr_meet[in_ptr][ptr()]; } 1065 PTR dual_ptr() const { return ptr_dual[ptr()]; } 1066 1067 // This is textually confusing unless one recalls that 1068 // join(t) == dual()->meet(t->dual())->dual(). 1069 PTR join_ptr( const PTR in_ptr ) const { 1070 return ptr_dual[ ptr_meet[ ptr_dual[in_ptr] ] [ dual_ptr() ] ]; 1071 } 1072 1073 // Speculative type helper methods. 1074 virtual const TypePtr* speculative() const { return _speculative; } 1075 int inline_depth() const { return _inline_depth; } 1076 virtual ciKlass* speculative_type() const; 1077 virtual ciKlass* speculative_type_not_null() const; 1078 virtual bool speculative_maybe_null() const; 1079 virtual bool speculative_always_null() const; 1080 virtual const TypePtr* remove_speculative() const; 1081 virtual const Type* cleanup_speculative() const; 1082 virtual bool would_improve_type(ciKlass* exact_kls, int inline_depth) const; 1083 virtual bool would_improve_ptr(ProfilePtrKind maybe_null) const; 1084 virtual const TypePtr* with_inline_depth(int depth) const; 1085 1086 virtual bool maybe_null() const { return meet_ptr(Null) == ptr(); } 1087 1088 virtual bool can_be_inline_type() const { return false; } 1089 virtual bool flatten_array() const { return false; } 1090 virtual bool not_flatten_array() const { return false; } 1091 virtual bool is_flat() const { return false; } 1092 virtual bool is_not_flat() const { return false; } 1093 virtual bool is_null_free() const { return false; } 1094 virtual bool is_not_null_free() const { return false; } 1095 1096 // Tests for relation to centerline of type lattice: 1097 static bool above_centerline(PTR ptr) { return (ptr <= AnyNull); } 1098 static bool below_centerline(PTR ptr) { return (ptr >= NotNull); } 1099 // Convenience common pre-built types. 1100 static const TypePtr *NULL_PTR; 1101 static const TypePtr *NOTNULL; 1102 static const TypePtr *BOTTOM; 1103 #ifndef PRODUCT 1104 virtual void dump2( Dict &d, uint depth, outputStream *st ) const; 1105 #endif 1106 }; 1107 1108 //------------------------------TypeRawPtr------------------------------------- 1109 // Class of raw pointers, pointers to things other than Oops. Examples 1110 // include the stack pointer, top of heap, card-marking area, handles, etc. 1111 class TypeRawPtr : public TypePtr { 1112 protected: 1113 TypeRawPtr(PTR ptr, address bits) : TypePtr(RawPtr,ptr,Offset(0)), _bits(bits){} 1114 public: 1115 virtual bool eq( const Type *t ) const; 1116 virtual int hash() const; // Type specific hashing 1117 1118 const address _bits; // Constant value, if applicable 1119 1120 static const TypeRawPtr *make( PTR ptr ); 1121 static const TypeRawPtr *make( address bits ); 1122 1123 // Return a 'ptr' version of this type 1124 virtual const TypeRawPtr* cast_to_ptr_type(PTR ptr) const; 1125 1126 virtual intptr_t get_con() const; 1127 1128 virtual const TypePtr* add_offset(intptr_t offset) const; 1129 virtual const TypeRawPtr* with_offset(intptr_t offset) const { ShouldNotReachHere(); return NULL;} 1130 1131 virtual const Type *xmeet( const Type *t ) const; 1132 virtual const Type *xdual() const; // Compute dual right now. 1133 // Convenience common pre-built types. 1134 static const TypeRawPtr *BOTTOM; 1135 static const TypeRawPtr *NOTNULL; 1136 #ifndef PRODUCT 1137 virtual void dump2( Dict &d, uint depth, outputStream *st ) const; 1138 #endif 1139 }; 1140 1141 //------------------------------TypeOopPtr------------------------------------- 1142 // Some kind of oop (Java pointer), either instance or array. 1143 class TypeOopPtr : public TypePtr { 1144 friend class TypeAry; 1145 friend class TypePtr; 1146 friend class TypeInstPtr; 1147 friend class TypeAryPtr; 1148 protected: 1149 TypeOopPtr(TYPES t, PTR ptr, ciKlass* k, const InterfaceSet& interfaces,bool xk, ciObject* o, Offset offset, Offset field_offset, 1150 int instance_id, const TypePtr* speculative, int inline_depth); 1151 public: 1152 virtual bool eq( const Type *t ) const; 1153 virtual int hash() const; // Type specific hashing 1154 virtual bool singleton(void) const; // TRUE if type is a singleton 1155 enum { 1156 InstanceTop = -1, // undefined instance 1157 InstanceBot = 0 // any possible instance 1158 }; 1159 protected: 1160 1161 // Oop is NULL, unless this is a constant oop. 1162 ciObject* _const_oop; // Constant oop 1163 // If _klass is NULL, then so is _sig. This is an unloaded klass. 1164 ciKlass* _klass; // Klass object 1165 1166 const InterfaceSet _interfaces; 1167 1168 // Does the type exclude subclasses of the klass? (Inexact == polymorphic.) 1169 bool _klass_is_exact; 1170 bool _is_ptr_to_narrowoop; 1171 bool _is_ptr_to_narrowklass; 1172 bool _is_ptr_to_boxed_value; 1173 1174 // If not InstanceTop or InstanceBot, indicates that this is 1175 // a particular instance of this type which is distinct. 1176 // This is the node index of the allocation node creating this instance. 1177 int _instance_id; 1178 1179 static const TypeOopPtr* make_from_klass_common(ciKlass* klass, bool klass_change, bool try_for_exact, InterfaceHandling interface_handling); 1180 1181 int dual_instance_id() const; 1182 int meet_instance_id(int uid) const; 1183 1184 InterfaceSet meet_interfaces(const TypeOopPtr* other) const; 1185 1186 // Do not allow interface-vs.-noninterface joins to collapse to top. 1187 virtual const Type *filter_helper(const Type *kills, bool include_speculative) const; 1188 1189 virtual ciKlass* exact_klass_helper() const { return NULL; } 1190 virtual ciKlass* klass() const { return _klass; } 1191 1192 public: 1193 1194 bool is_java_subtype_of(const TypeOopPtr* other) const { 1195 return is_java_subtype_of_helper(other, klass_is_exact(), other->klass_is_exact()); 1196 } 1197 1198 bool is_same_java_type_as(const TypePtr* other) const { 1199 return is_same_java_type_as_helper(other->is_oopptr()); 1200 } 1201 1202 virtual bool is_same_java_type_as_helper(const TypeOopPtr* other) const { 1203 ShouldNotReachHere(); return false; 1204 } 1205 1206 bool maybe_java_subtype_of(const TypeOopPtr* other) const { 1207 return maybe_java_subtype_of_helper(other, klass_is_exact(), other->klass_is_exact()); 1208 } 1209 virtual bool is_java_subtype_of_helper(const TypeOopPtr* other, bool this_exact, bool other_exact) const { ShouldNotReachHere(); return false; } 1210 virtual bool maybe_java_subtype_of_helper(const TypeOopPtr* other, bool this_exact, bool other_exact) const { ShouldNotReachHere(); return false; } 1211 1212 1213 // Creates a type given a klass. Correctly handles multi-dimensional arrays 1214 // Respects UseUniqueSubclasses. 1215 // If the klass is final, the resulting type will be exact. 1216 static const TypeOopPtr* make_from_klass(ciKlass* klass, InterfaceHandling interface_handling = ignore_interfaces) { 1217 return make_from_klass_common(klass, true, false, interface_handling); 1218 } 1219 // Same as before, but will produce an exact type, even if 1220 // the klass is not final, as long as it has exactly one implementation. 1221 static const TypeOopPtr* make_from_klass_unique(ciKlass* klass, InterfaceHandling interface_handling= ignore_interfaces) { 1222 return make_from_klass_common(klass, true, true, interface_handling); 1223 } 1224 // Same as before, but does not respects UseUniqueSubclasses. 1225 // Use this only for creating array element types. 1226 static const TypeOopPtr* make_from_klass_raw(ciKlass* klass, InterfaceHandling interface_handling = ignore_interfaces) { 1227 return make_from_klass_common(klass, false, false, interface_handling); 1228 } 1229 // Creates a singleton type given an object. 1230 // If the object cannot be rendered as a constant, 1231 // may return a non-singleton type. 1232 // If require_constant, produce a NULL if a singleton is not possible. 1233 static const TypeOopPtr* make_from_constant(ciObject* o, 1234 bool require_constant = false); 1235 1236 // Make a generic (unclassed) pointer to an oop. 1237 static const TypeOopPtr* make(PTR ptr, Offset offset, int instance_id, 1238 const TypePtr* speculative = NULL, 1239 int inline_depth = InlineDepthBottom); 1240 1241 ciObject* const_oop() const { return _const_oop; } 1242 // Exact klass, possibly an interface or an array of interface 1243 ciKlass* exact_klass(bool maybe_null = false) const { assert(klass_is_exact(), ""); ciKlass* k = exact_klass_helper(); assert(k != NULL || maybe_null, ""); return k; } 1244 ciKlass* unloaded_klass() const { assert(!is_loaded(), "only for unloaded types"); return klass(); } 1245 1246 virtual bool is_loaded() const { return klass()->is_loaded() && _interfaces.is_loaded(); } 1247 virtual bool klass_is_exact() const { return _klass_is_exact; } 1248 1249 // Returns true if this pointer points at memory which contains a 1250 // compressed oop references. 1251 bool is_ptr_to_narrowoop_nv() const { return _is_ptr_to_narrowoop; } 1252 bool is_ptr_to_narrowklass_nv() const { return _is_ptr_to_narrowklass; } 1253 bool is_ptr_to_boxed_value() const { return _is_ptr_to_boxed_value; } 1254 bool is_known_instance() const { return _instance_id > 0; } 1255 int instance_id() const { return _instance_id; } 1256 bool is_known_instance_field() const { return is_known_instance() && _offset.get() >= 0; } 1257 1258 virtual bool can_be_inline_type() const { return (_klass == NULL || _klass->can_be_inline_klass(_klass_is_exact)); } 1259 virtual bool can_be_inline_array() const { ShouldNotReachHere(); return false; } 1260 1261 virtual intptr_t get_con() const; 1262 1263 virtual const TypeOopPtr* cast_to_ptr_type(PTR ptr) const; 1264 1265 virtual const TypeOopPtr* cast_to_exactness(bool klass_is_exact) const; 1266 1267 virtual const TypeOopPtr *cast_to_instance_id(int instance_id) const; 1268 1269 // corresponding pointer to klass, for a given instance 1270 virtual const TypeKlassPtr* as_klass_type(bool try_for_exact = false) const; 1271 1272 virtual const TypeOopPtr* with_offset(intptr_t offset) const; 1273 virtual const TypePtr* add_offset(intptr_t offset) const; 1274 1275 // Speculative type helper methods. 1276 virtual const TypeOopPtr* remove_speculative() const; 1277 virtual const Type* cleanup_speculative() const; 1278 virtual bool would_improve_type(ciKlass* exact_kls, int inline_depth) const; 1279 virtual const TypePtr* with_inline_depth(int depth) const; 1280 1281 virtual const TypePtr* with_instance_id(int instance_id) const; 1282 1283 virtual const Type *xdual() const; // Compute dual right now. 1284 // the core of the computation of the meet for TypeOopPtr and for its subclasses 1285 virtual const Type *xmeet_helper(const Type *t) const; 1286 1287 // Convenience common pre-built type. 1288 static const TypeOopPtr *BOTTOM; 1289 #ifndef PRODUCT 1290 virtual void dump2( Dict &d, uint depth, outputStream *st ) const; 1291 #endif 1292 private: 1293 virtual bool is_meet_subtype_of(const TypePtr* other) const { 1294 return is_meet_subtype_of_helper(other->is_oopptr(), klass_is_exact(), other->is_oopptr()->klass_is_exact()); 1295 } 1296 1297 virtual bool is_meet_subtype_of_helper(const TypeOopPtr* other, bool this_xk, bool other_xk) const { 1298 ShouldNotReachHere(); return false; 1299 } 1300 1301 virtual const InterfaceSet interfaces() const { 1302 return _interfaces; 1303 }; 1304 1305 const TypeOopPtr* is_reference_type(const Type* other) const { 1306 return other->isa_oopptr(); 1307 } 1308 1309 const TypeAryPtr* is_array_type(const TypeOopPtr* other) const { 1310 return other->isa_aryptr(); 1311 } 1312 1313 const TypeInstPtr* is_instance_type(const TypeOopPtr* other) const { 1314 return other->isa_instptr(); 1315 } 1316 }; 1317 1318 //------------------------------TypeInstPtr------------------------------------ 1319 // Class of Java object pointers, pointing either to non-array Java instances 1320 // or to a Klass* (including array klasses). 1321 class TypeInstPtr : public TypeOopPtr { 1322 TypeInstPtr(PTR ptr, ciKlass* k, const InterfaceSet& interfaces, bool xk, ciObject* o, Offset offset, 1323 bool flatten_array, int instance_id, const TypePtr* speculative, 1324 int inline_depth); 1325 virtual bool eq( const Type *t ) const; 1326 virtual int hash() const; // Type specific hashing 1327 1328 bool _flatten_array; // Type is flat in arrays 1329 ciKlass* exact_klass_helper() const; 1330 1331 public: 1332 1333 // Instance klass, ignoring any interface 1334 ciInstanceKlass* instance_klass() const { 1335 assert(!(klass()->is_loaded() && klass()->is_interface()), ""); 1336 return klass()->as_instance_klass(); 1337 } 1338 1339 bool is_same_java_type_as_helper(const TypeOopPtr* other) const; 1340 bool is_java_subtype_of_helper(const TypeOopPtr* other, bool this_exact, bool other_exact) const; 1341 bool maybe_java_subtype_of_helper(const TypeOopPtr* other, bool this_exact, bool other_exact) const; 1342 1343 // Make a pointer to a constant oop. 1344 static const TypeInstPtr *make(ciObject* o) { 1345 ciKlass* k = o->klass(); 1346 const TypePtr::InterfaceSet interfaces = TypePtr::interfaces(k, true, false, false, ignore_interfaces); 1347 return make(TypePtr::Constant, k, interfaces, true, o, Offset(0)); 1348 } 1349 // Make a pointer to a constant oop with offset. 1350 static const TypeInstPtr *make(ciObject* o, Offset offset) { 1351 ciKlass* k = o->klass(); 1352 const TypePtr::InterfaceSet interfaces = TypePtr::interfaces(k, true, false, false, ignore_interfaces); 1353 return make(TypePtr::Constant, k, interfaces, true, o, offset); 1354 } 1355 1356 // Make a pointer to some value of type klass. 1357 static const TypeInstPtr *make(PTR ptr, ciKlass* klass, InterfaceHandling interface_handling = ignore_interfaces) { 1358 const TypePtr::InterfaceSet interfaces = TypePtr::interfaces(klass, true, true, false, interface_handling); 1359 return make(ptr, klass, interfaces, false, NULL, Offset(0)); 1360 } 1361 1362 // Make a pointer to some non-polymorphic value of exactly type klass. 1363 static const TypeInstPtr *make_exact(PTR ptr, ciKlass* klass) { 1364 const TypePtr::InterfaceSet interfaces = TypePtr::interfaces(klass, true, false, false, ignore_interfaces); 1365 return make(ptr, klass, interfaces, true, NULL, Offset(0)); 1366 } 1367 1368 // Make a pointer to some value of type klass with offset. 1369 static const TypeInstPtr *make(PTR ptr, ciKlass* klass, Offset offset) { 1370 const TypePtr::InterfaceSet interfaces = TypePtr::interfaces(klass, true, false, false, ignore_interfaces); 1371 return make(ptr, klass, interfaces, false, NULL, offset); 1372 } 1373 1374 // Make a pointer to an oop. 1375 static const TypeInstPtr* make(PTR ptr, ciKlass* k, const InterfaceSet& interfaces, bool xk, ciObject* o, Offset offset, 1376 bool flatten_array = false, 1377 int instance_id = InstanceBot, 1378 const TypePtr* speculative = NULL, 1379 int inline_depth = InlineDepthBottom); 1380 1381 static const TypeInstPtr *make(PTR ptr, ciKlass* k, bool xk, ciObject* o, Offset offset, int instance_id = InstanceBot) { 1382 const TypePtr::InterfaceSet interfaces = TypePtr::interfaces(k, true, false, false, ignore_interfaces); 1383 return make(ptr, k, interfaces, xk, o, offset, false, instance_id); 1384 } 1385 1386 /** Create constant type for a constant boxed value */ 1387 const Type* get_const_boxed_value() const; 1388 1389 // If this is a java.lang.Class constant, return the type for it or NULL. 1390 // Pass to Type::get_const_type to turn it to a type, which will usually 1391 // be a TypeInstPtr, but may also be a TypeInt::INT for int.class, etc. 1392 ciType* java_mirror_type(bool* is_val_mirror = NULL) const; 1393 1394 virtual const TypeInstPtr* cast_to_ptr_type(PTR ptr) const; 1395 1396 virtual const TypeInstPtr* cast_to_exactness(bool klass_is_exact) const; 1397 1398 virtual const TypeInstPtr* cast_to_instance_id(int instance_id) const; 1399 1400 virtual const TypePtr* add_offset(intptr_t offset) const; 1401 virtual const TypeInstPtr* with_offset(intptr_t offset) const; 1402 1403 // Speculative type helper methods. 1404 virtual const TypeInstPtr* remove_speculative() const; 1405 virtual const TypePtr* with_inline_depth(int depth) const; 1406 virtual const TypePtr* with_instance_id(int instance_id) const; 1407 1408 virtual const TypeInstPtr* cast_to_flatten_array() const; 1409 virtual bool flatten_array() const { return _flatten_array; } 1410 virtual bool not_flatten_array() const { return !can_be_inline_type() || (_klass->is_inlinetype() && !flatten_array()); } 1411 1412 // the core of the computation of the meet of 2 types 1413 virtual const Type *xmeet_helper(const Type *t) const; 1414 virtual const TypeInstPtr *xmeet_unloaded(const TypeInstPtr *t, const InterfaceSet& interfaces) const; 1415 virtual const Type *xdual() const; // Compute dual right now. 1416 1417 const TypeKlassPtr* as_klass_type(bool try_for_exact = false) const; 1418 1419 virtual bool can_be_inline_array() const; 1420 1421 // Convenience common pre-built types. 1422 static const TypeInstPtr *NOTNULL; 1423 static const TypeInstPtr *BOTTOM; 1424 static const TypeInstPtr *MIRROR; 1425 static const TypeInstPtr *MARK; 1426 static const TypeInstPtr *KLASS; 1427 #ifndef PRODUCT 1428 virtual void dump2( Dict &d, uint depth, outputStream *st ) const; // Specialized per-Type dumping 1429 #endif 1430 1431 private: 1432 virtual bool is_meet_subtype_of_helper(const TypeOopPtr* other, bool this_xk, bool other_xk) const; 1433 1434 virtual bool is_meet_same_type_as(const TypePtr* other) const { 1435 return _klass->equals(other->is_instptr()->_klass) && _interfaces.eq(other->is_instptr()->_interfaces); 1436 } 1437 1438 }; 1439 1440 //------------------------------TypeAryPtr------------------------------------- 1441 // Class of Java array pointers 1442 class TypeAryPtr : public TypeOopPtr { 1443 friend class Type; 1444 friend class TypePtr; 1445 friend class TypeInstPtr; 1446 1447 TypeAryPtr(PTR ptr, ciObject* o, const TypeAry *ary, ciKlass* k, bool xk, 1448 Offset offset, Offset field_offset, int instance_id, bool is_autobox_cache, 1449 const TypePtr* speculative, int inline_depth) 1450 : TypeOopPtr(AryPtr, ptr, k, *_array_interfaces, xk, o, offset, field_offset, instance_id, speculative, inline_depth), 1451 _ary(ary), 1452 _is_autobox_cache(is_autobox_cache), 1453 _field_offset(field_offset) 1454 { 1455 int dummy; 1456 bool top_or_bottom = (base_element_type(dummy) == Type::TOP || base_element_type(dummy) == Type::BOTTOM); 1457 1458 if (UseCompressedOops && (elem()->make_oopptr() != NULL && !top_or_bottom) && 1459 _offset.get() != 0 && _offset.get() != arrayOopDesc::length_offset_in_bytes() && 1460 _offset.get() != arrayOopDesc::klass_offset_in_bytes()) { 1461 _is_ptr_to_narrowoop = true; 1462 } 1463 1464 } 1465 virtual bool eq( const Type *t ) const; 1466 virtual int hash() const; // Type specific hashing 1467 const TypeAry *_ary; // Array we point into 1468 const bool _is_autobox_cache; 1469 // For flattened inline type arrays, each field of the inline type in 1470 // the array has its own memory slice so we need to keep track of 1471 // which field is accessed 1472 const Offset _field_offset; 1473 Offset meet_field_offset(const Type::Offset offset) const; 1474 Offset dual_field_offset() const; 1475 1476 ciKlass* compute_klass(DEBUG_ONLY(bool verify = false)) const; 1477 1478 // A pointer to delay allocation to Type::Initialize_shared() 1479 1480 static const InterfaceSet* _array_interfaces; 1481 ciKlass* exact_klass_helper() const; 1482 // Only guaranteed non null for array of basic types 1483 ciKlass* klass() const; 1484 1485 public: 1486 1487 bool is_same_java_type_as_helper(const TypeOopPtr* other) const; 1488 bool is_java_subtype_of_helper(const TypeOopPtr* other, bool this_exact, bool other_exact) const; 1489 bool maybe_java_subtype_of_helper(const TypeOopPtr* other, bool this_exact, bool other_exact) const; 1490 1491 // returns base element type, an instance klass (and not interface) for object arrays 1492 const Type* base_element_type(int& dims) const; 1493 1494 // Accessors 1495 bool is_loaded() const { return (_ary->_elem->make_oopptr() ? _ary->_elem->make_oopptr()->is_loaded() : true); } 1496 1497 const TypeAry* ary() const { return _ary; } 1498 const Type* elem() const { return _ary->_elem; } 1499 const TypeInt* size() const { return _ary->_size; } 1500 bool is_stable() const { return _ary->_stable; } 1501 1502 // Inline type array properties 1503 bool is_flat() const { return _ary->_flat; } 1504 bool is_not_flat() const { return _ary->_not_flat; } 1505 bool is_null_free() const { return is_flat() || (_ary->_elem->make_ptr() != NULL && _ary->_elem->make_ptr()->is_inlinetypeptr() && (_ary->_elem->make_ptr()->ptr() == NotNull || _ary->_elem->make_ptr()->ptr() == AnyNull)); } 1506 bool is_not_null_free() const { return _ary->_not_null_free; } 1507 1508 bool is_autobox_cache() const { return _is_autobox_cache; } 1509 1510 static const TypeAryPtr* make(PTR ptr, const TypeAry *ary, ciKlass* k, bool xk, Offset offset, 1511 Offset field_offset = Offset::bottom, 1512 int instance_id = InstanceBot, 1513 const TypePtr* speculative = NULL, 1514 int inline_depth = InlineDepthBottom); 1515 // Constant pointer to array 1516 static const TypeAryPtr* make(PTR ptr, ciObject* o, const TypeAry *ary, ciKlass* k, bool xk, Offset offset, 1517 Offset field_offset = Offset::bottom, 1518 int instance_id = InstanceBot, 1519 const TypePtr* speculative = NULL, 1520 int inline_depth = InlineDepthBottom, 1521 bool is_autobox_cache = false); 1522 1523 // Return a 'ptr' version of this type 1524 virtual const TypeAryPtr* cast_to_ptr_type(PTR ptr) const; 1525 1526 virtual const TypeAryPtr* cast_to_exactness(bool klass_is_exact) const; 1527 1528 virtual const TypeAryPtr* cast_to_instance_id(int instance_id) const; 1529 1530 virtual const TypeAryPtr* cast_to_size(const TypeInt* size) const; 1531 virtual const TypeInt* narrow_size_type(const TypeInt* size) const; 1532 1533 virtual bool empty(void) const; // TRUE if type is vacuous 1534 virtual const TypePtr *add_offset( intptr_t offset ) const; 1535 virtual const TypeAryPtr *with_offset( intptr_t offset ) const; 1536 const TypeAryPtr* with_ary(const TypeAry* ary) const; 1537 1538 // Speculative type helper methods. 1539 virtual const TypeAryPtr* remove_speculative() const; 1540 virtual const Type* cleanup_speculative() const; 1541 virtual const TypePtr* with_inline_depth(int depth) const; 1542 virtual const TypePtr* with_instance_id(int instance_id) const; 1543 1544 // the core of the computation of the meet of 2 types 1545 virtual const Type *xmeet_helper(const Type *t) const; 1546 virtual const Type *xdual() const; // Compute dual right now. 1547 1548 // Inline type array properties 1549 const TypeAryPtr* cast_to_not_flat(bool not_flat = true) const; 1550 const TypeAryPtr* cast_to_not_null_free(bool not_null_free = true) const; 1551 const TypeAryPtr* update_properties(const TypeAryPtr* new_type) const; 1552 jint flat_layout_helper() const; 1553 int flat_elem_size() const; 1554 int flat_log_elem_size() const; 1555 1556 const TypeAryPtr* cast_to_stable(bool stable, int stable_dimension = 1) const; 1557 int stable_dimension() const; 1558 1559 const TypeAryPtr* cast_to_autobox_cache() const; 1560 1561 static jint max_array_length(BasicType etype); 1562 1563 const int flattened_offset() const; 1564 const Offset field_offset() const { return _field_offset; } 1565 const TypeAryPtr* with_field_offset(int offset) const; 1566 const TypePtr* add_field_offset_and_offset(intptr_t offset) const; 1567 1568 virtual bool can_be_inline_type() const { return false; } 1569 virtual const TypeKlassPtr* as_klass_type(bool try_for_exact = false) const; 1570 1571 virtual bool can_be_inline_array() const; 1572 1573 // Convenience common pre-built types. 1574 static const TypeAryPtr *RANGE; 1575 static const TypeAryPtr *OOPS; 1576 static const TypeAryPtr *NARROWOOPS; 1577 static const TypeAryPtr *BYTES; 1578 static const TypeAryPtr *SHORTS; 1579 static const TypeAryPtr *CHARS; 1580 static const TypeAryPtr *INTS; 1581 static const TypeAryPtr *LONGS; 1582 static const TypeAryPtr *FLOATS; 1583 static const TypeAryPtr *DOUBLES; 1584 static const TypeAryPtr *INLINES; 1585 // selects one of the above: 1586 static const TypeAryPtr *get_array_body_type(BasicType elem) { 1587 assert((uint)elem <= T_CONFLICT && _array_body_type[elem] != NULL, "bad elem type"); 1588 return _array_body_type[elem]; 1589 } 1590 static const TypeAryPtr *_array_body_type[T_CONFLICT+1]; 1591 // sharpen the type of an int which is used as an array size 1592 #ifndef PRODUCT 1593 virtual void dump2( Dict &d, uint depth, outputStream *st ) const; // Specialized per-Type dumping 1594 #endif 1595 private: 1596 virtual bool is_meet_subtype_of_helper(const TypeOopPtr* other, bool this_xk, bool other_xk) const; 1597 }; 1598 1599 //------------------------------TypeMetadataPtr------------------------------------- 1600 // Some kind of metadata, either Method*, MethodData* or CPCacheOop 1601 class TypeMetadataPtr : public TypePtr { 1602 protected: 1603 TypeMetadataPtr(PTR ptr, ciMetadata* metadata, Offset offset); 1604 // Do not allow interface-vs.-noninterface joins to collapse to top. 1605 virtual const Type *filter_helper(const Type *kills, bool include_speculative) const; 1606 public: 1607 virtual bool eq( const Type *t ) const; 1608 virtual int hash() const; // Type specific hashing 1609 virtual bool singleton(void) const; // TRUE if type is a singleton 1610 1611 private: 1612 ciMetadata* _metadata; 1613 1614 public: 1615 static const TypeMetadataPtr* make(PTR ptr, ciMetadata* m, Offset offset); 1616 1617 static const TypeMetadataPtr* make(ciMethod* m); 1618 static const TypeMetadataPtr* make(ciMethodData* m); 1619 1620 ciMetadata* metadata() const { return _metadata; } 1621 1622 virtual const TypeMetadataPtr* cast_to_ptr_type(PTR ptr) const; 1623 1624 virtual const TypePtr *add_offset( intptr_t offset ) const; 1625 1626 virtual const Type *xmeet( const Type *t ) const; 1627 virtual const Type *xdual() const; // Compute dual right now. 1628 1629 virtual intptr_t get_con() const; 1630 1631 // Convenience common pre-built types. 1632 static const TypeMetadataPtr *BOTTOM; 1633 1634 #ifndef PRODUCT 1635 virtual void dump2( Dict &d, uint depth, outputStream *st ) const; 1636 #endif 1637 }; 1638 1639 //------------------------------TypeKlassPtr----------------------------------- 1640 // Class of Java Klass pointers 1641 class TypeKlassPtr : public TypePtr { 1642 friend class TypeInstKlassPtr; 1643 friend class TypeAryKlassPtr; 1644 friend class TypePtr; 1645 protected: 1646 TypeKlassPtr(TYPES t, PTR ptr, ciKlass* klass, const InterfaceSet& interfaces, Offset offset); 1647 1648 virtual const Type *filter_helper(const Type *kills, bool include_speculative) const; 1649 1650 public: 1651 virtual bool eq( const Type *t ) const; 1652 virtual int hash() const; 1653 virtual bool singleton(void) const; // TRUE if type is a singleton 1654 1655 protected: 1656 1657 ciKlass* _klass; 1658 const InterfaceSet _interfaces; 1659 InterfaceSet meet_interfaces(const TypeKlassPtr* other) const; 1660 virtual bool must_be_exact() const { ShouldNotReachHere(); return false; } 1661 virtual ciKlass* exact_klass_helper() const; 1662 virtual ciKlass* klass() const { return _klass; } 1663 1664 public: 1665 1666 bool is_java_subtype_of(const TypeKlassPtr* other) const { 1667 return is_java_subtype_of_helper(other, klass_is_exact(), other->klass_is_exact()); 1668 } 1669 bool is_same_java_type_as(const TypePtr* other) const { 1670 return is_same_java_type_as_helper(other->is_klassptr()); 1671 } 1672 1673 bool maybe_java_subtype_of(const TypeKlassPtr* other) const { 1674 return maybe_java_subtype_of_helper(other, klass_is_exact(), other->klass_is_exact()); 1675 } 1676 virtual bool is_same_java_type_as_helper(const TypeKlassPtr* other) const { ShouldNotReachHere(); return false; } 1677 virtual bool is_java_subtype_of_helper(const TypeKlassPtr* other, bool this_exact, bool other_exact) const { ShouldNotReachHere(); return false; } 1678 virtual bool maybe_java_subtype_of_helper(const TypeKlassPtr* other, bool this_exact, bool other_exact) const { ShouldNotReachHere(); return false; } 1679 1680 // Exact klass, possibly an interface or an array of interface 1681 ciKlass* exact_klass(bool maybe_null = false) const { assert(klass_is_exact(), ""); ciKlass* k = exact_klass_helper(); assert(k != NULL || maybe_null, ""); return k; } 1682 virtual bool klass_is_exact() const { return _ptr == Constant; } 1683 1684 static const TypeKlassPtr* make(ciKlass* klass, InterfaceHandling interface_handling = ignore_interfaces); 1685 static const TypeKlassPtr *make(PTR ptr, ciKlass* klass, Offset offset, InterfaceHandling interface_handling = ignore_interfaces); 1686 1687 virtual bool is_loaded() const { return _klass->is_loaded(); } 1688 1689 virtual const TypeKlassPtr* cast_to_ptr_type(PTR ptr) const { ShouldNotReachHere(); return NULL; } 1690 1691 virtual const TypeKlassPtr *cast_to_exactness(bool klass_is_exact) const { ShouldNotReachHere(); return NULL; } 1692 1693 // corresponding pointer to instance, for a given class 1694 virtual const TypeOopPtr* as_instance_type(bool klass_change = true) const { ShouldNotReachHere(); return NULL; } 1695 1696 virtual const TypePtr *add_offset( intptr_t offset ) const { ShouldNotReachHere(); return NULL; } 1697 virtual const Type *xmeet( const Type *t ) const { ShouldNotReachHere(); return NULL; } 1698 virtual const Type *xdual() const { ShouldNotReachHere(); return NULL; } 1699 1700 virtual intptr_t get_con() const; 1701 1702 virtual const TypeKlassPtr* with_offset(intptr_t offset) const { ShouldNotReachHere(); return NULL; } 1703 1704 virtual bool can_be_inline_array() const { ShouldNotReachHere(); return false; } 1705 virtual const TypeKlassPtr* try_improve() const { return this; } 1706 1707 #ifndef PRODUCT 1708 virtual void dump2( Dict &d, uint depth, outputStream *st ) const; // Specialized per-Type dumping 1709 #endif 1710 private: 1711 virtual bool is_meet_subtype_of(const TypePtr* other) const { 1712 return is_meet_subtype_of_helper(other->is_klassptr(), klass_is_exact(), other->is_klassptr()->klass_is_exact()); 1713 } 1714 1715 virtual bool is_meet_subtype_of_helper(const TypeKlassPtr* other, bool this_xk, bool other_xk) const { 1716 ShouldNotReachHere(); return false; 1717 } 1718 1719 virtual const InterfaceSet interfaces() const { 1720 return _interfaces; 1721 }; 1722 1723 const TypeKlassPtr* is_reference_type(const Type* other) const { 1724 return other->isa_klassptr(); 1725 } 1726 1727 const TypeAryKlassPtr* is_array_type(const TypeKlassPtr* other) const { 1728 return other->isa_aryklassptr(); 1729 } 1730 1731 const TypeInstKlassPtr* is_instance_type(const TypeKlassPtr* other) const { 1732 return other->isa_instklassptr(); 1733 } 1734 }; 1735 1736 // Instance klass pointer, mirrors TypeInstPtr 1737 class TypeInstKlassPtr : public TypeKlassPtr { 1738 1739 TypeInstKlassPtr(PTR ptr, ciKlass* klass, const InterfaceSet& interfaces, Offset offset, bool flatten_array) 1740 : TypeKlassPtr(InstKlassPtr, ptr, klass, interfaces, offset), _flatten_array(flatten_array) { 1741 assert(klass->is_instance_klass() && (!klass->is_loaded() || !klass->is_interface()), ""); 1742 } 1743 1744 virtual bool must_be_exact() const; 1745 1746 const bool _flatten_array; // Type is flat in arrays 1747 1748 public: 1749 // Instance klass ignoring any interface 1750 ciInstanceKlass* instance_klass() const { 1751 assert(!klass()->is_interface(), ""); 1752 return klass()->as_instance_klass(); 1753 } 1754 1755 bool is_same_java_type_as_helper(const TypeKlassPtr* other) const; 1756 bool is_java_subtype_of_helper(const TypeKlassPtr* other, bool this_exact, bool other_exact) const; 1757 bool maybe_java_subtype_of_helper(const TypeKlassPtr* other, bool this_exact, bool other_exact) const; 1758 1759 virtual bool can_be_inline_type() const { return (_klass == NULL || _klass->can_be_inline_klass(klass_is_exact())); } 1760 1761 static const TypeInstKlassPtr *make(ciKlass* k, InterfaceHandling interface_handling) { 1762 InterfaceSet interfaces = TypePtr::interfaces(k, true, true, false, interface_handling); 1763 return make(TypePtr::Constant, k, interfaces, Offset(0)); 1764 } 1765 static const TypeInstKlassPtr* make(PTR ptr, ciKlass* k, const InterfaceSet& interfaces, Offset offset, bool flatten_array = false); 1766 1767 static const TypeInstKlassPtr* make(PTR ptr, ciKlass* k, Offset offset) { 1768 const TypePtr::InterfaceSet interfaces = TypePtr::interfaces(k, true, false, false, ignore_interfaces); 1769 return make(ptr, k, interfaces, offset); 1770 } 1771 1772 virtual const TypeInstKlassPtr* cast_to_ptr_type(PTR ptr) const; 1773 1774 virtual const TypeKlassPtr *cast_to_exactness(bool klass_is_exact) const; 1775 1776 // corresponding pointer to instance, for a given class 1777 virtual const TypeOopPtr* as_instance_type(bool klass_change = true) const; 1778 virtual int hash() const; 1779 virtual bool eq(const Type *t) const; 1780 1781 virtual const TypePtr *add_offset( intptr_t offset ) const; 1782 virtual const Type *xmeet( const Type *t ) const; 1783 virtual const Type *xdual() const; 1784 virtual const TypeInstKlassPtr* with_offset(intptr_t offset) const; 1785 1786 virtual const TypeKlassPtr* try_improve() const; 1787 1788 virtual bool flatten_array() const { return _flatten_array; } 1789 virtual bool not_flatten_array() const { return !_klass->can_be_inline_klass() || (_klass->is_inlinetype() && !flatten_array()); } 1790 1791 virtual bool can_be_inline_array() const; 1792 1793 // Convenience common pre-built types. 1794 static const TypeInstKlassPtr* OBJECT; // Not-null object klass or below 1795 static const TypeInstKlassPtr* OBJECT_OR_NULL; // Maybe-null version of same 1796 private: 1797 virtual bool is_meet_subtype_of_helper(const TypeKlassPtr* other, bool this_xk, bool other_xk) const; 1798 }; 1799 1800 // Array klass pointer, mirrors TypeAryPtr 1801 class TypeAryKlassPtr : public TypeKlassPtr { 1802 friend class TypeInstKlassPtr; 1803 friend class Type; 1804 friend class TypePtr; 1805 1806 const Type *_elem; 1807 const bool _not_flat; // Array is never flattened 1808 const bool _not_null_free; // Array is never null-free 1809 const bool _null_free; 1810 1811 static const InterfaceSet* _array_interfaces; 1812 TypeAryKlassPtr(PTR ptr, const Type *elem, ciKlass* klass, Offset offset, bool not_flat, int not_null_free, bool null_free) 1813 : TypeKlassPtr(AryKlassPtr, ptr, klass, *_array_interfaces, offset), _elem(elem), _not_flat(not_flat), _not_null_free(not_null_free), _null_free(null_free) { 1814 assert(klass == NULL || klass->is_type_array_klass() || klass->is_flat_array_klass() || !klass->as_obj_array_klass()->base_element_klass()->is_interface(), ""); 1815 } 1816 1817 virtual ciKlass* exact_klass_helper() const; 1818 // Only guaranteed non null for array of basic types 1819 virtual ciKlass* klass() const; 1820 1821 virtual bool must_be_exact() const; 1822 1823 bool dual_null_free() const { 1824 return _null_free; 1825 } 1826 1827 bool meet_null_free(bool other) const { 1828 return _null_free && other; 1829 } 1830 1831 public: 1832 1833 // returns base element type, an instance klass (and not interface) for object arrays 1834 const Type* base_element_type(int& dims) const; 1835 1836 static const TypeAryKlassPtr* make(PTR ptr, ciKlass* k, Offset offset, InterfaceHandling interface_handling, bool not_flat, bool not_null_free, bool null_free); 1837 1838 bool is_same_java_type_as_helper(const TypeKlassPtr* other) const; 1839 bool is_java_subtype_of_helper(const TypeKlassPtr* other, bool this_exact, bool other_exact) const; 1840 bool maybe_java_subtype_of_helper(const TypeKlassPtr* other, bool this_exact, bool other_exact) const; 1841 1842 bool is_loaded() const { return (_elem->isa_klassptr() ? _elem->is_klassptr()->is_loaded() : true); } 1843 1844 static const TypeAryKlassPtr* make(PTR ptr, const Type* elem, ciKlass* k, Offset offset, bool not_flat, bool not_null_free, bool null_free); 1845 static const TypeAryKlassPtr* make(PTR ptr, ciKlass* k, Offset offset, InterfaceHandling interface_handling); 1846 static const TypeAryKlassPtr* make(ciKlass* klass, InterfaceHandling interface_handling); 1847 1848 const Type *elem() const { return _elem; } 1849 1850 virtual bool eq(const Type *t) const; 1851 virtual int hash() const; // Type specific hashing 1852 1853 virtual const TypeAryKlassPtr* cast_to_ptr_type(PTR ptr) const; 1854 1855 virtual const TypeKlassPtr *cast_to_exactness(bool klass_is_exact) const; 1856 1857 // corresponding pointer to instance, for a given class 1858 virtual const TypeOopPtr* as_instance_type(bool klass_change = true) const; 1859 1860 virtual const TypePtr *add_offset( intptr_t offset ) const; 1861 virtual const Type *xmeet( const Type *t ) const; 1862 virtual const Type *xdual() const; // Compute dual right now. 1863 1864 virtual const TypeAryKlassPtr* with_offset(intptr_t offset) const; 1865 1866 virtual bool empty(void) const { 1867 return TypeKlassPtr::empty() || _elem->empty(); 1868 } 1869 1870 bool is_flat() const { return klass() != NULL && klass()->is_flat_array_klass(); } 1871 bool is_not_flat() const { return _not_flat; } 1872 bool is_null_free() const { return _null_free; } 1873 bool is_not_null_free() const { return _not_null_free; } 1874 virtual bool can_be_inline_array() const; 1875 1876 #ifndef PRODUCT 1877 virtual void dump2( Dict &d, uint depth, outputStream *st ) const; // Specialized per-Type dumping 1878 #endif 1879 private: 1880 virtual bool is_meet_subtype_of_helper(const TypeKlassPtr* other, bool this_xk, bool other_xk) const; 1881 }; 1882 1883 class TypeNarrowPtr : public Type { 1884 protected: 1885 const TypePtr* _ptrtype; // Could be TypePtr::NULL_PTR 1886 1887 TypeNarrowPtr(TYPES t, const TypePtr* ptrtype): Type(t), 1888 _ptrtype(ptrtype) { 1889 assert(ptrtype->offset() == 0 || 1890 ptrtype->offset() == OffsetBot || 1891 ptrtype->offset() == OffsetTop, "no real offsets"); 1892 } 1893 1894 virtual const TypeNarrowPtr *isa_same_narrowptr(const Type *t) const = 0; 1895 virtual const TypeNarrowPtr *is_same_narrowptr(const Type *t) const = 0; 1896 virtual const TypeNarrowPtr *make_same_narrowptr(const TypePtr *t) const = 0; 1897 virtual const TypeNarrowPtr *make_hash_same_narrowptr(const TypePtr *t) const = 0; 1898 // Do not allow interface-vs.-noninterface joins to collapse to top. 1899 virtual const Type *filter_helper(const Type *kills, bool include_speculative) const; 1900 public: 1901 virtual bool eq( const Type *t ) const; 1902 virtual int hash() const; // Type specific hashing 1903 virtual bool singleton(void) const; // TRUE if type is a singleton 1904 1905 virtual const Type *xmeet( const Type *t ) const; 1906 virtual const Type *xdual() const; // Compute dual right now. 1907 1908 virtual intptr_t get_con() const; 1909 1910 virtual bool empty(void) const; // TRUE if type is vacuous 1911 1912 // returns the equivalent ptr type for this compressed pointer 1913 const TypePtr *get_ptrtype() const { 1914 return _ptrtype; 1915 } 1916 1917 bool is_known_instance() const { 1918 return _ptrtype->is_known_instance(); 1919 } 1920 1921 #ifndef PRODUCT 1922 virtual void dump2( Dict &d, uint depth, outputStream *st ) const; 1923 #endif 1924 }; 1925 1926 //------------------------------TypeNarrowOop---------------------------------- 1927 // A compressed reference to some kind of Oop. This type wraps around 1928 // a preexisting TypeOopPtr and forwards most of it's operations to 1929 // the underlying type. It's only real purpose is to track the 1930 // oopness of the compressed oop value when we expose the conversion 1931 // between the normal and the compressed form. 1932 class TypeNarrowOop : public TypeNarrowPtr { 1933 protected: 1934 TypeNarrowOop( const TypePtr* ptrtype): TypeNarrowPtr(NarrowOop, ptrtype) { 1935 } 1936 1937 virtual const TypeNarrowPtr *isa_same_narrowptr(const Type *t) const { 1938 return t->isa_narrowoop(); 1939 } 1940 1941 virtual const TypeNarrowPtr *is_same_narrowptr(const Type *t) const { 1942 return t->is_narrowoop(); 1943 } 1944 1945 virtual const TypeNarrowPtr *make_same_narrowptr(const TypePtr *t) const { 1946 return new TypeNarrowOop(t); 1947 } 1948 1949 virtual const TypeNarrowPtr *make_hash_same_narrowptr(const TypePtr *t) const { 1950 return (const TypeNarrowPtr*)((new TypeNarrowOop(t))->hashcons()); 1951 } 1952 1953 public: 1954 1955 static const TypeNarrowOop *make( const TypePtr* type); 1956 1957 static const TypeNarrowOop* make_from_constant(ciObject* con, bool require_constant = false) { 1958 return make(TypeOopPtr::make_from_constant(con, require_constant)); 1959 } 1960 1961 static const TypeNarrowOop *BOTTOM; 1962 static const TypeNarrowOop *NULL_PTR; 1963 1964 virtual const TypeNarrowOop* remove_speculative() const; 1965 virtual const Type* cleanup_speculative() const; 1966 1967 #ifndef PRODUCT 1968 virtual void dump2( Dict &d, uint depth, outputStream *st ) const; 1969 #endif 1970 }; 1971 1972 //------------------------------TypeNarrowKlass---------------------------------- 1973 // A compressed reference to klass pointer. This type wraps around a 1974 // preexisting TypeKlassPtr and forwards most of it's operations to 1975 // the underlying type. 1976 class TypeNarrowKlass : public TypeNarrowPtr { 1977 protected: 1978 TypeNarrowKlass( const TypePtr* ptrtype): TypeNarrowPtr(NarrowKlass, ptrtype) { 1979 } 1980 1981 virtual const TypeNarrowPtr *isa_same_narrowptr(const Type *t) const { 1982 return t->isa_narrowklass(); 1983 } 1984 1985 virtual const TypeNarrowPtr *is_same_narrowptr(const Type *t) const { 1986 return t->is_narrowklass(); 1987 } 1988 1989 virtual const TypeNarrowPtr *make_same_narrowptr(const TypePtr *t) const { 1990 return new TypeNarrowKlass(t); 1991 } 1992 1993 virtual const TypeNarrowPtr *make_hash_same_narrowptr(const TypePtr *t) const { 1994 return (const TypeNarrowPtr*)((new TypeNarrowKlass(t))->hashcons()); 1995 } 1996 1997 public: 1998 static const TypeNarrowKlass *make( const TypePtr* type); 1999 2000 // static const TypeNarrowKlass *BOTTOM; 2001 static const TypeNarrowKlass *NULL_PTR; 2002 2003 #ifndef PRODUCT 2004 virtual void dump2( Dict &d, uint depth, outputStream *st ) const; 2005 #endif 2006 }; 2007 2008 //------------------------------TypeFunc--------------------------------------- 2009 // Class of Array Types 2010 class TypeFunc : public Type { 2011 TypeFunc(const TypeTuple *domain_sig, const TypeTuple *domain_cc, const TypeTuple *range_sig, const TypeTuple *range_cc) 2012 : Type(Function), _domain_sig(domain_sig), _domain_cc(domain_cc), _range_sig(range_sig), _range_cc(range_cc) {} 2013 virtual bool eq( const Type *t ) const; 2014 virtual int hash() const; // Type specific hashing 2015 virtual bool singleton(void) const; // TRUE if type is a singleton 2016 virtual bool empty(void) const; // TRUE if type is vacuous 2017 2018 // Domains of inputs: inline type arguments are not passed by 2019 // reference, instead each field of the inline type is passed as an 2020 // argument. We maintain 2 views of the argument list here: one 2021 // based on the signature (with an inline type argument as a single 2022 // slot), one based on the actual calling convention (with a value 2023 // type argument as a list of its fields). 2024 const TypeTuple* const _domain_sig; 2025 const TypeTuple* const _domain_cc; 2026 // Range of results. Similar to domains: an inline type result can be 2027 // returned in registers in which case range_cc lists all fields and 2028 // is the actual calling convention. 2029 const TypeTuple* const _range_sig; 2030 const TypeTuple* const _range_cc; 2031 2032 public: 2033 // Constants are shared among ADLC and VM 2034 enum { Control = AdlcVMDeps::Control, 2035 I_O = AdlcVMDeps::I_O, 2036 Memory = AdlcVMDeps::Memory, 2037 FramePtr = AdlcVMDeps::FramePtr, 2038 ReturnAdr = AdlcVMDeps::ReturnAdr, 2039 Parms = AdlcVMDeps::Parms 2040 }; 2041 2042 2043 // Accessors: 2044 const TypeTuple* domain_sig() const { return _domain_sig; } 2045 const TypeTuple* domain_cc() const { return _domain_cc; } 2046 const TypeTuple* range_sig() const { return _range_sig; } 2047 const TypeTuple* range_cc() const { return _range_cc; } 2048 2049 static const TypeFunc* make(ciMethod* method, bool is_osr_compilation = false); 2050 static const TypeFunc *make(const TypeTuple* domain_sig, const TypeTuple* domain_cc, 2051 const TypeTuple* range_sig, const TypeTuple* range_cc); 2052 static const TypeFunc *make(const TypeTuple* domain, const TypeTuple* range); 2053 2054 virtual const Type *xmeet( const Type *t ) const; 2055 virtual const Type *xdual() const; // Compute dual right now. 2056 2057 BasicType return_type() const; 2058 2059 bool returns_inline_type_as_fields() const { return range_sig() != range_cc(); } 2060 2061 #ifndef PRODUCT 2062 virtual void dump2( Dict &d, uint depth, outputStream *st ) const; // Specialized per-Type dumping 2063 #endif 2064 // Convenience common pre-built types. 2065 }; 2066 2067 //------------------------------accessors-------------------------------------- 2068 inline bool Type::is_ptr_to_narrowoop() const { 2069 #ifdef _LP64 2070 return (isa_oopptr() != NULL && is_oopptr()->is_ptr_to_narrowoop_nv()); 2071 #else 2072 return false; 2073 #endif 2074 } 2075 2076 inline bool Type::is_ptr_to_narrowklass() const { 2077 #ifdef _LP64 2078 return (isa_oopptr() != NULL && is_oopptr()->is_ptr_to_narrowklass_nv()); 2079 #else 2080 return false; 2081 #endif 2082 } 2083 2084 inline float Type::getf() const { 2085 assert( _base == FloatCon, "Not a FloatCon" ); 2086 return ((TypeF*)this)->_f; 2087 } 2088 2089 inline double Type::getd() const { 2090 assert( _base == DoubleCon, "Not a DoubleCon" ); 2091 return ((TypeD*)this)->_d; 2092 } 2093 2094 inline const TypeInteger *Type::is_integer(BasicType bt) const { 2095 assert((bt == T_INT && _base == Int) || (bt == T_LONG && _base == Long), "Not an Int"); 2096 return (TypeInteger*)this; 2097 } 2098 2099 inline const TypeInteger *Type::isa_integer(BasicType bt) const { 2100 return (((bt == T_INT && _base == Int) || (bt == T_LONG && _base == Long)) ? (TypeInteger*)this : NULL); 2101 } 2102 2103 inline const TypeInt *Type::is_int() const { 2104 assert( _base == Int, "Not an Int" ); 2105 return (TypeInt*)this; 2106 } 2107 2108 inline const TypeInt *Type::isa_int() const { 2109 return ( _base == Int ? (TypeInt*)this : NULL); 2110 } 2111 2112 inline const TypeLong *Type::is_long() const { 2113 assert( _base == Long, "Not a Long" ); 2114 return (TypeLong*)this; 2115 } 2116 2117 inline const TypeLong *Type::isa_long() const { 2118 return ( _base == Long ? (TypeLong*)this : NULL); 2119 } 2120 2121 inline const TypeF *Type::isa_float() const { 2122 return ((_base == FloatTop || 2123 _base == FloatCon || 2124 _base == FloatBot) ? (TypeF*)this : NULL); 2125 } 2126 2127 inline const TypeF *Type::is_float_constant() const { 2128 assert( _base == FloatCon, "Not a Float" ); 2129 return (TypeF*)this; 2130 } 2131 2132 inline const TypeF *Type::isa_float_constant() const { 2133 return ( _base == FloatCon ? (TypeF*)this : NULL); 2134 } 2135 2136 inline const TypeD *Type::isa_double() const { 2137 return ((_base == DoubleTop || 2138 _base == DoubleCon || 2139 _base == DoubleBot) ? (TypeD*)this : NULL); 2140 } 2141 2142 inline const TypeD *Type::is_double_constant() const { 2143 assert( _base == DoubleCon, "Not a Double" ); 2144 return (TypeD*)this; 2145 } 2146 2147 inline const TypeD *Type::isa_double_constant() const { 2148 return ( _base == DoubleCon ? (TypeD*)this : NULL); 2149 } 2150 2151 inline const TypeTuple *Type::is_tuple() const { 2152 assert( _base == Tuple, "Not a Tuple" ); 2153 return (TypeTuple*)this; 2154 } 2155 2156 inline const TypeAry *Type::is_ary() const { 2157 assert( _base == Array , "Not an Array" ); 2158 return (TypeAry*)this; 2159 } 2160 2161 inline const TypeAry *Type::isa_ary() const { 2162 return ((_base == Array) ? (TypeAry*)this : NULL); 2163 } 2164 2165 inline const TypeVectMask *Type::is_vectmask() const { 2166 assert( _base == VectorMask, "Not a Vector Mask" ); 2167 return (TypeVectMask*)this; 2168 } 2169 2170 inline const TypeVectMask *Type::isa_vectmask() const { 2171 return (_base == VectorMask) ? (TypeVectMask*)this : NULL; 2172 } 2173 2174 inline const TypeVect *Type::is_vect() const { 2175 assert( _base >= VectorMask && _base <= VectorZ, "Not a Vector" ); 2176 return (TypeVect*)this; 2177 } 2178 2179 inline const TypeVect *Type::isa_vect() const { 2180 return (_base >= VectorMask && _base <= VectorZ) ? (TypeVect*)this : NULL; 2181 } 2182 2183 inline const TypePtr *Type::is_ptr() const { 2184 // AnyPtr is the first Ptr and KlassPtr the last, with no non-ptrs between. 2185 assert(_base >= AnyPtr && _base <= AryKlassPtr, "Not a pointer"); 2186 return (TypePtr*)this; 2187 } 2188 2189 inline const TypePtr *Type::isa_ptr() const { 2190 // AnyPtr is the first Ptr and KlassPtr the last, with no non-ptrs between. 2191 return (_base >= AnyPtr && _base <= AryKlassPtr) ? (TypePtr*)this : NULL; 2192 } 2193 2194 inline const TypeOopPtr *Type::is_oopptr() const { 2195 // OopPtr is the first and KlassPtr the last, with no non-oops between. 2196 assert(_base >= OopPtr && _base <= AryPtr, "Not a Java pointer" ) ; 2197 return (TypeOopPtr*)this; 2198 } 2199 2200 inline const TypeOopPtr *Type::isa_oopptr() const { 2201 // OopPtr is the first and KlassPtr the last, with no non-oops between. 2202 return (_base >= OopPtr && _base <= AryPtr) ? (TypeOopPtr*)this : NULL; 2203 } 2204 2205 inline const TypeRawPtr *Type::isa_rawptr() const { 2206 return (_base == RawPtr) ? (TypeRawPtr*)this : NULL; 2207 } 2208 2209 inline const TypeRawPtr *Type::is_rawptr() const { 2210 assert( _base == RawPtr, "Not a raw pointer" ); 2211 return (TypeRawPtr*)this; 2212 } 2213 2214 inline const TypeInstPtr *Type::isa_instptr() const { 2215 return (_base == InstPtr) ? (TypeInstPtr*)this : NULL; 2216 } 2217 2218 inline const TypeInstPtr *Type::is_instptr() const { 2219 assert( _base == InstPtr, "Not an object pointer" ); 2220 return (TypeInstPtr*)this; 2221 } 2222 2223 inline const TypeAryPtr *Type::isa_aryptr() const { 2224 return (_base == AryPtr) ? (TypeAryPtr*)this : NULL; 2225 } 2226 2227 inline const TypeAryPtr *Type::is_aryptr() const { 2228 assert( _base == AryPtr, "Not an array pointer" ); 2229 return (TypeAryPtr*)this; 2230 } 2231 2232 inline const TypeNarrowOop *Type::is_narrowoop() const { 2233 // OopPtr is the first and KlassPtr the last, with no non-oops between. 2234 assert(_base == NarrowOop, "Not a narrow oop" ) ; 2235 return (TypeNarrowOop*)this; 2236 } 2237 2238 inline const TypeNarrowOop *Type::isa_narrowoop() const { 2239 // OopPtr is the first and KlassPtr the last, with no non-oops between. 2240 return (_base == NarrowOop) ? (TypeNarrowOop*)this : NULL; 2241 } 2242 2243 inline const TypeNarrowKlass *Type::is_narrowklass() const { 2244 assert(_base == NarrowKlass, "Not a narrow oop" ) ; 2245 return (TypeNarrowKlass*)this; 2246 } 2247 2248 inline const TypeNarrowKlass *Type::isa_narrowklass() const { 2249 return (_base == NarrowKlass) ? (TypeNarrowKlass*)this : NULL; 2250 } 2251 2252 inline const TypeMetadataPtr *Type::is_metadataptr() const { 2253 // MetadataPtr is the first and CPCachePtr the last 2254 assert(_base == MetadataPtr, "Not a metadata pointer" ) ; 2255 return (TypeMetadataPtr*)this; 2256 } 2257 2258 inline const TypeMetadataPtr *Type::isa_metadataptr() const { 2259 return (_base == MetadataPtr) ? (TypeMetadataPtr*)this : NULL; 2260 } 2261 2262 inline const TypeKlassPtr *Type::isa_klassptr() const { 2263 return (_base >= KlassPtr && _base <= AryKlassPtr ) ? (TypeKlassPtr*)this : NULL; 2264 } 2265 2266 inline const TypeKlassPtr *Type::is_klassptr() const { 2267 assert(_base >= KlassPtr && _base <= AryKlassPtr, "Not a klass pointer"); 2268 return (TypeKlassPtr*)this; 2269 } 2270 2271 inline const TypeInstKlassPtr *Type::isa_instklassptr() const { 2272 return (_base == InstKlassPtr) ? (TypeInstKlassPtr*)this : NULL; 2273 } 2274 2275 inline const TypeInstKlassPtr *Type::is_instklassptr() const { 2276 assert(_base == InstKlassPtr, "Not a klass pointer"); 2277 return (TypeInstKlassPtr*)this; 2278 } 2279 2280 inline const TypeAryKlassPtr *Type::isa_aryklassptr() const { 2281 return (_base == AryKlassPtr) ? (TypeAryKlassPtr*)this : NULL; 2282 } 2283 2284 inline const TypeAryKlassPtr *Type::is_aryklassptr() const { 2285 assert(_base == AryKlassPtr, "Not a klass pointer"); 2286 return (TypeAryKlassPtr*)this; 2287 } 2288 2289 inline const TypePtr* Type::make_ptr() const { 2290 return (_base == NarrowOop) ? is_narrowoop()->get_ptrtype() : 2291 ((_base == NarrowKlass) ? is_narrowklass()->get_ptrtype() : 2292 isa_ptr()); 2293 } 2294 2295 inline const TypeOopPtr* Type::make_oopptr() const { 2296 return (_base == NarrowOop) ? is_narrowoop()->get_ptrtype()->isa_oopptr() : isa_oopptr(); 2297 } 2298 2299 inline const TypeNarrowOop* Type::make_narrowoop() const { 2300 return (_base == NarrowOop) ? is_narrowoop() : 2301 (isa_ptr() ? TypeNarrowOop::make(is_ptr()) : NULL); 2302 } 2303 2304 inline const TypeNarrowKlass* Type::make_narrowklass() const { 2305 return (_base == NarrowKlass) ? is_narrowklass() : 2306 (isa_ptr() ? TypeNarrowKlass::make(is_ptr()) : NULL); 2307 } 2308 2309 inline bool Type::is_floatingpoint() const { 2310 if( (_base == FloatCon) || (_base == FloatBot) || 2311 (_base == DoubleCon) || (_base == DoubleBot) ) 2312 return true; 2313 return false; 2314 } 2315 2316 inline bool Type::is_inlinetypeptr() const { 2317 return isa_instptr() != NULL && is_instptr()->instance_klass()->is_inlinetype(); 2318 } 2319 2320 inline ciInlineKlass* Type::inline_klass() const { 2321 return make_ptr()->is_instptr()->instance_klass()->as_inline_klass(); 2322 } 2323 2324 2325 // =============================================================== 2326 // Things that need to be 64-bits in the 64-bit build but 2327 // 32-bits in the 32-bit build. Done this way to get full 2328 // optimization AND strong typing. 2329 #ifdef _LP64 2330 2331 // For type queries and asserts 2332 #define is_intptr_t is_long 2333 #define isa_intptr_t isa_long 2334 #define find_intptr_t_type find_long_type 2335 #define find_intptr_t_con find_long_con 2336 #define TypeX TypeLong 2337 #define Type_X Type::Long 2338 #define TypeX_X TypeLong::LONG 2339 #define TypeX_ZERO TypeLong::ZERO 2340 // For 'ideal_reg' machine registers 2341 #define Op_RegX Op_RegL 2342 // For phase->intcon variants 2343 #define MakeConX longcon 2344 #define ConXNode ConLNode 2345 // For array index arithmetic 2346 #define MulXNode MulLNode 2347 #define AndXNode AndLNode 2348 #define OrXNode OrLNode 2349 #define CmpXNode CmpLNode 2350 #define CmpUXNode CmpULNode 2351 #define SubXNode SubLNode 2352 #define LShiftXNode LShiftLNode 2353 // For object size computation: 2354 #define AddXNode AddLNode 2355 #define RShiftXNode RShiftLNode 2356 // For card marks and hashcodes 2357 #define URShiftXNode URShiftLNode 2358 // For shenandoahSupport 2359 #define LoadXNode LoadLNode 2360 #define StoreXNode StoreLNode 2361 // Opcodes 2362 #define Op_LShiftX Op_LShiftL 2363 #define Op_AndX Op_AndL 2364 #define Op_AddX Op_AddL 2365 #define Op_SubX Op_SubL 2366 #define Op_XorX Op_XorL 2367 #define Op_URShiftX Op_URShiftL 2368 #define Op_LoadX Op_LoadL 2369 #define Op_StoreX Op_StoreL 2370 // conversions 2371 #define ConvI2X(x) ConvI2L(x) 2372 #define ConvL2X(x) (x) 2373 #define ConvX2I(x) ConvL2I(x) 2374 #define ConvX2L(x) (x) 2375 #define ConvX2UL(x) (x) 2376 2377 #else 2378 2379 // For type queries and asserts 2380 #define is_intptr_t is_int 2381 #define isa_intptr_t isa_int 2382 #define find_intptr_t_type find_int_type 2383 #define find_intptr_t_con find_int_con 2384 #define TypeX TypeInt 2385 #define Type_X Type::Int 2386 #define TypeX_X TypeInt::INT 2387 #define TypeX_ZERO TypeInt::ZERO 2388 // For 'ideal_reg' machine registers 2389 #define Op_RegX Op_RegI 2390 // For phase->intcon variants 2391 #define MakeConX intcon 2392 #define ConXNode ConINode 2393 // For array index arithmetic 2394 #define MulXNode MulINode 2395 #define AndXNode AndINode 2396 #define OrXNode OrINode 2397 #define CmpXNode CmpINode 2398 #define CmpUXNode CmpUNode 2399 #define SubXNode SubINode 2400 #define LShiftXNode LShiftINode 2401 // For object size computation: 2402 #define AddXNode AddINode 2403 #define RShiftXNode RShiftINode 2404 // For card marks and hashcodes 2405 #define URShiftXNode URShiftINode 2406 // For shenandoahSupport 2407 #define LoadXNode LoadINode 2408 #define StoreXNode StoreINode 2409 // Opcodes 2410 #define Op_LShiftX Op_LShiftI 2411 #define Op_AndX Op_AndI 2412 #define Op_AddX Op_AddI 2413 #define Op_SubX Op_SubI 2414 #define Op_XorX Op_XorI 2415 #define Op_URShiftX Op_URShiftI 2416 #define Op_LoadX Op_LoadI 2417 #define Op_StoreX Op_StoreI 2418 // conversions 2419 #define ConvI2X(x) (x) 2420 #define ConvL2X(x) ConvL2I(x) 2421 #define ConvX2I(x) (x) 2422 #define ConvX2L(x) ConvI2L(x) 2423 #define ConvX2UL(x) ConvI2UL(x) 2424 2425 #endif 2426 2427 #endif // SHARE_OPTO_TYPE_HPP