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