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