src/share/vm/opto/type.hpp

Wed, 27 Nov 2013 16:16:21 -0800

author
goetz
date
Wed, 27 Nov 2013 16:16:21 -0800
changeset 6490
41b780b43b74
parent 6487
15120a36272d
child 6507
752ba2e5f6d0
permissions
-rw-r--r--

8029015: PPC64 (part 216): opto: trap based null and range checks
Summary: On PPC64 use tdi instruction that does a compare and raises SIGTRAP for NULL and range checks.
Reviewed-by: kvn

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

mercurial