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