annotate src/share/vm/opto/type.hpp @ 958:c7e94e8fff43

6880053: assert(alloc_obj->as_CheckCastPP()->type() != TypeInstPtr::NOTNULL) Summary: Removed second CheckCastPP and use MembarCPUOrder after arraycopy to cloned object. Reviewed-by: never
author kvn
date Thu, 10 Sep 2009 18:18:06 -0700
parents fc4be448891f
children 148e5441d916
rev   line source
duke@0 1 /*
twisti@624 2 * Copyright 1997-2009 Sun Microsystems, Inc. All Rights Reserved.
duke@0 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
duke@0 4 *
duke@0 5 * This code is free software; you can redistribute it and/or modify it
duke@0 6 * under the terms of the GNU General Public License version 2 only, as
duke@0 7 * published by the Free Software Foundation.
duke@0 8 *
duke@0 9 * This code is distributed in the hope that it will be useful, but WITHOUT
duke@0 10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
duke@0 11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
duke@0 12 * version 2 for more details (a copy is included in the LICENSE file that
duke@0 13 * accompanied this code).
duke@0 14 *
duke@0 15 * You should have received a copy of the GNU General Public License version
duke@0 16 * 2 along with this work; if not, write to the Free Software Foundation,
duke@0 17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
duke@0 18 *
duke@0 19 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
duke@0 20 * CA 95054 USA or visit www.sun.com if you need additional information or
duke@0 21 * have any questions.
duke@0 22 *
duke@0 23 */
duke@0 24
duke@0 25 // Portions of code courtesy of Clifford Click
duke@0 26
duke@0 27 // Optimization - Graph Style
duke@0 28
duke@0 29
duke@0 30 // This class defines a Type lattice. The lattice is used in the constant
duke@0 31 // propagation algorithms, and for some type-checking of the iloc code.
duke@0 32 // Basic types include RSD's (lower bound, upper bound, stride for integers),
duke@0 33 // float & double precision constants, sets of data-labels and code-labels.
duke@0 34 // The complete lattice is described below. Subtypes have no relationship to
duke@0 35 // up or down in the lattice; that is entirely determined by the behavior of
duke@0 36 // the MEET/JOIN functions.
duke@0 37
duke@0 38 class Dict;
duke@0 39 class Type;
duke@0 40 class TypeD;
duke@0 41 class TypeF;
duke@0 42 class TypeInt;
duke@0 43 class TypeLong;
coleenp@113 44 class TypeNarrowOop;
duke@0 45 class TypeAry;
duke@0 46 class TypeTuple;
duke@0 47 class TypePtr;
duke@0 48 class TypeRawPtr;
duke@0 49 class TypeOopPtr;
duke@0 50 class TypeInstPtr;
duke@0 51 class TypeAryPtr;
duke@0 52 class TypeKlassPtr;
duke@0 53
duke@0 54 //------------------------------Type-------------------------------------------
duke@0 55 // Basic Type object, represents a set of primitive Values.
duke@0 56 // Types are hash-cons'd into a private class dictionary, so only one of each
duke@0 57 // different kind of Type exists. Types are never modified after creation, so
duke@0 58 // all their interesting fields are constant.
duke@0 59 class Type {
duke@0 60 public:
duke@0 61 enum TYPES {
duke@0 62 Bad=0, // Type check
duke@0 63 Control, // Control of code (not in lattice)
duke@0 64 Top, // Top of the lattice
duke@0 65 Int, // Integer range (lo-hi)
duke@0 66 Long, // Long integer range (lo-hi)
duke@0 67 Half, // Placeholder half of doubleword
coleenp@113 68 NarrowOop, // Compressed oop pointer
duke@0 69
duke@0 70 Tuple, // Method signature or object layout
duke@0 71 Array, // Array types
duke@0 72
duke@0 73 AnyPtr, // Any old raw, klass, inst, or array pointer
duke@0 74 RawPtr, // Raw (non-oop) pointers
duke@0 75 OopPtr, // Any and all Java heap entities
duke@0 76 InstPtr, // Instance pointers (non-array objects)
duke@0 77 AryPtr, // Array pointers
duke@0 78 KlassPtr, // Klass pointers
duke@0 79 // (Ptr order matters: See is_ptr, isa_ptr, is_oopptr, isa_oopptr.)
duke@0 80
duke@0 81 Function, // Function signature
duke@0 82 Abio, // Abstract I/O
duke@0 83 Return_Address, // Subroutine return address
duke@0 84 Memory, // Abstract store
duke@0 85 FloatTop, // No float value
duke@0 86 FloatCon, // Floating point constant
duke@0 87 FloatBot, // Any float value
duke@0 88 DoubleTop, // No double value
duke@0 89 DoubleCon, // Double precision constant
duke@0 90 DoubleBot, // Any double value
duke@0 91 Bottom, // Bottom of lattice
duke@0 92 lastype // Bogus ending type (not in lattice)
duke@0 93 };
duke@0 94
duke@0 95 // Signal values for offsets from a base pointer
duke@0 96 enum OFFSET_SIGNALS {
duke@0 97 OffsetTop = -2000000000, // undefined offset
duke@0 98 OffsetBot = -2000000001 // any possible offset
duke@0 99 };
duke@0 100
duke@0 101 // Min and max WIDEN values.
duke@0 102 enum WIDEN {
duke@0 103 WidenMin = 0,
duke@0 104 WidenMax = 3
duke@0 105 };
duke@0 106
duke@0 107 private:
duke@0 108 // Dictionary of types shared among compilations.
duke@0 109 static Dict* _shared_type_dict;
duke@0 110
duke@0 111 static int uhash( const Type *const t );
duke@0 112 // Structural equality check. Assumes that cmp() has already compared
duke@0 113 // the _base types and thus knows it can cast 't' appropriately.
duke@0 114 virtual bool eq( const Type *t ) const;
duke@0 115
duke@0 116 // Top-level hash-table of types
duke@0 117 static Dict *type_dict() {
duke@0 118 return Compile::current()->type_dict();
duke@0 119 }
duke@0 120
duke@0 121 // DUAL operation: reflect around lattice centerline. Used instead of
duke@0 122 // join to ensure my lattice is symmetric up and down. Dual is computed
duke@0 123 // lazily, on demand, and cached in _dual.
duke@0 124 const Type *_dual; // Cached dual value
duke@0 125 // Table for efficient dualing of base types
duke@0 126 static const TYPES dual_type[lastype];
duke@0 127
duke@0 128 protected:
duke@0 129 // Each class of type is also identified by its base.
duke@0 130 const TYPES _base; // Enum of Types type
duke@0 131
duke@0 132 Type( TYPES t ) : _dual(NULL), _base(t) {} // Simple types
duke@0 133 // ~Type(); // Use fast deallocation
duke@0 134 const Type *hashcons(); // Hash-cons the type
duke@0 135
duke@0 136 public:
duke@0 137
duke@0 138 inline void* operator new( size_t x ) {
duke@0 139 Compile* compile = Compile::current();
duke@0 140 compile->set_type_last_size(x);
duke@0 141 void *temp = compile->type_arena()->Amalloc_D(x);
duke@0 142 compile->set_type_hwm(temp);
duke@0 143 return temp;
duke@0 144 }
duke@0 145 inline void operator delete( void* ptr ) {
duke@0 146 Compile* compile = Compile::current();
duke@0 147 compile->type_arena()->Afree(ptr,compile->type_last_size());
duke@0 148 }
duke@0 149
duke@0 150 // Initialize the type system for a particular compilation.
duke@0 151 static void Initialize(Compile* compile);
duke@0 152
duke@0 153 // Initialize the types shared by all compilations.
duke@0 154 static void Initialize_shared(Compile* compile);
duke@0 155
duke@0 156 TYPES base() const {
duke@0 157 assert(_base > Bad && _base < lastype, "sanity");
duke@0 158 return _base;
duke@0 159 }
duke@0 160
duke@0 161 // Create a new hash-consd type
duke@0 162 static const Type *make(enum TYPES);
duke@0 163 // Test for equivalence of types
duke@0 164 static int cmp( const Type *const t1, const Type *const t2 );
duke@0 165 // Test for higher or equal in lattice
duke@0 166 int higher_equal( const Type *t ) const { return !cmp(meet(t),t); }
duke@0 167
duke@0 168 // MEET operation; lower in lattice.
duke@0 169 const Type *meet( const Type *t ) const;
duke@0 170 // WIDEN: 'widens' for Ints and other range types
duke@0 171 virtual const Type *widen( const Type *old ) const { return this; }
duke@0 172 // NARROW: complement for widen, used by pessimistic phases
duke@0 173 virtual const Type *narrow( const Type *old ) const { return this; }
duke@0 174
duke@0 175 // DUAL operation: reflect around lattice centerline. Used instead of
duke@0 176 // join to ensure my lattice is symmetric up and down.
duke@0 177 const Type *dual() const { return _dual; }
duke@0 178
duke@0 179 // Compute meet dependent on base type
duke@0 180 virtual const Type *xmeet( const Type *t ) const;
duke@0 181 virtual const Type *xdual() const; // Compute dual right now.
duke@0 182
duke@0 183 // JOIN operation; higher in lattice. Done by finding the dual of the
duke@0 184 // meet of the dual of the 2 inputs.
duke@0 185 const Type *join( const Type *t ) const {
duke@0 186 return dual()->meet(t->dual())->dual(); }
duke@0 187
duke@0 188 // Modified version of JOIN adapted to the needs Node::Value.
duke@0 189 // Normalizes all empty values to TOP. Does not kill _widen bits.
duke@0 190 // Currently, it also works around limitations involving interface types.
duke@0 191 virtual const Type *filter( const Type *kills ) const;
duke@0 192
kvn@820 193 #ifdef ASSERT
kvn@820 194 // One type is interface, the other is oop
kvn@820 195 virtual bool interface_vs_oop(const Type *t) const;
kvn@820 196 #endif
kvn@820 197
coleenp@113 198 // Returns true if this pointer points at memory which contains a
kvn@163 199 // compressed oop references.
kvn@163 200 bool is_ptr_to_narrowoop() const;
coleenp@113 201
duke@0 202 // Convenience access
duke@0 203 float getf() const;
duke@0 204 double getd() const;
duke@0 205
duke@0 206 const TypeInt *is_int() const;
duke@0 207 const TypeInt *isa_int() const; // Returns NULL if not an Int
duke@0 208 const TypeLong *is_long() const;
duke@0 209 const TypeLong *isa_long() const; // Returns NULL if not a Long
duke@0 210 const TypeD *is_double_constant() const; // Asserts it is a DoubleCon
duke@0 211 const TypeD *isa_double_constant() const; // Returns NULL if not a DoubleCon
duke@0 212 const TypeF *is_float_constant() const; // Asserts it is a FloatCon
duke@0 213 const TypeF *isa_float_constant() const; // Returns NULL if not a FloatCon
duke@0 214 const TypeTuple *is_tuple() const; // Collection of fields, NOT a pointer
duke@0 215 const TypeAry *is_ary() const; // Array, NOT array pointer
duke@0 216 const TypePtr *is_ptr() const; // Asserts it is a ptr type
duke@0 217 const TypePtr *isa_ptr() const; // Returns NULL if not ptr type
coleenp@113 218 const TypeRawPtr *isa_rawptr() const; // NOT Java oop
coleenp@113 219 const TypeRawPtr *is_rawptr() const; // Asserts is rawptr
kvn@163 220 const TypeNarrowOop *is_narrowoop() const; // Java-style GC'd pointer
kvn@163 221 const TypeNarrowOop *isa_narrowoop() const; // Returns NULL if not oop ptr type
coleenp@113 222 const TypeOopPtr *isa_oopptr() const; // Returns NULL if not oop ptr type
coleenp@113 223 const TypeOopPtr *is_oopptr() const; // Java-style GC'd pointer
coleenp@113 224 const TypeKlassPtr *isa_klassptr() const; // Returns NULL if not KlassPtr
coleenp@113 225 const TypeKlassPtr *is_klassptr() const; // assert if not KlassPtr
coleenp@113 226 const TypeInstPtr *isa_instptr() const; // Returns NULL if not InstPtr
coleenp@113 227 const TypeInstPtr *is_instptr() const; // Instance
coleenp@113 228 const TypeAryPtr *isa_aryptr() const; // Returns NULL if not AryPtr
coleenp@113 229 const TypeAryPtr *is_aryptr() const; // Array oop
duke@0 230 virtual bool is_finite() const; // Has a finite value
duke@0 231 virtual bool is_nan() const; // Is not a number (NaN)
duke@0 232
kvn@221 233 // Returns this ptr type or the equivalent ptr type for this compressed pointer.
kvn@221 234 const TypePtr* make_ptr() const;
never@827 235
never@827 236 // Returns this oopptr type or the equivalent oopptr type for this compressed pointer.
never@827 237 // Asserts if the underlying type is not an oopptr or narrowoop.
never@827 238 const TypeOopPtr* make_oopptr() const;
never@827 239
kvn@221 240 // Returns this compressed pointer or the equivalent compressed version
kvn@221 241 // of this pointer type.
kvn@221 242 const TypeNarrowOop* make_narrowoop() const;
kvn@221 243
duke@0 244 // Special test for register pressure heuristic
duke@0 245 bool is_floatingpoint() const; // True if Float or Double base type
duke@0 246
duke@0 247 // Do you have memory, directly or through a tuple?
duke@0 248 bool has_memory( ) const;
duke@0 249
duke@0 250 // Are you a pointer type or not?
duke@0 251 bool isa_oop_ptr() const;
duke@0 252
duke@0 253 // TRUE if type is a singleton
duke@0 254 virtual bool singleton(void) const;
duke@0 255
duke@0 256 // TRUE if type is above the lattice centerline, and is therefore vacuous
duke@0 257 virtual bool empty(void) const;
duke@0 258
duke@0 259 // Return a hash for this type. The hash function is public so ConNode
duke@0 260 // (constants) can hash on their constant, which is represented by a Type.
duke@0 261 virtual int hash() const;
duke@0 262
duke@0 263 // Map ideal registers (machine types) to ideal types
duke@0 264 static const Type *mreg2type[];
duke@0 265
duke@0 266 // Printing, statistics
duke@0 267 static const char * const msg[lastype]; // Printable strings
duke@0 268 #ifndef PRODUCT
duke@0 269 void dump_on(outputStream *st) const;
duke@0 270 void dump() const {
duke@0 271 dump_on(tty);
duke@0 272 }
duke@0 273 virtual void dump2( Dict &d, uint depth, outputStream *st ) const;
duke@0 274 static void dump_stats();
duke@0 275 static void verify_lastype(); // Check that arrays match type enum
duke@0 276 #endif
duke@0 277 void typerr(const Type *t) const; // Mixing types error
duke@0 278
duke@0 279 // Create basic type
duke@0 280 static const Type* get_const_basic_type(BasicType type) {
duke@0 281 assert((uint)type <= T_CONFLICT && _const_basic_type[type] != NULL, "bad type");
duke@0 282 return _const_basic_type[type];
duke@0 283 }
duke@0 284
duke@0 285 // Mapping to the array element's basic type.
duke@0 286 BasicType array_element_basic_type() const;
duke@0 287
duke@0 288 // Create standard type for a ciType:
duke@0 289 static const Type* get_const_type(ciType* type);
duke@0 290
duke@0 291 // Create standard zero value:
duke@0 292 static const Type* get_zero_type(BasicType type) {
duke@0 293 assert((uint)type <= T_CONFLICT && _zero_type[type] != NULL, "bad type");
duke@0 294 return _zero_type[type];
duke@0 295 }
duke@0 296
duke@0 297 // Report if this is a zero value (not top).
duke@0 298 bool is_zero_type() const {
duke@0 299 BasicType type = basic_type();
duke@0 300 if (type == T_VOID || type >= T_CONFLICT)
duke@0 301 return false;
duke@0 302 else
duke@0 303 return (this == _zero_type[type]);
duke@0 304 }
duke@0 305
duke@0 306 // Convenience common pre-built types.
duke@0 307 static const Type *ABIO;
duke@0 308 static const Type *BOTTOM;
duke@0 309 static const Type *CONTROL;
duke@0 310 static const Type *DOUBLE;
duke@0 311 static const Type *FLOAT;
duke@0 312 static const Type *HALF;
duke@0 313 static const Type *MEMORY;
duke@0 314 static const Type *MULTI;
duke@0 315 static const Type *RETURN_ADDRESS;
duke@0 316 static const Type *TOP;
duke@0 317
duke@0 318 // Mapping from compiler type to VM BasicType
duke@0 319 BasicType basic_type() const { return _basic_type[_base]; }
duke@0 320
duke@0 321 // Mapping from CI type system to compiler type:
duke@0 322 static const Type* get_typeflow_type(ciType* type);
duke@0 323
duke@0 324 private:
duke@0 325 // support arrays
duke@0 326 static const BasicType _basic_type[];
duke@0 327 static const Type* _zero_type[T_CONFLICT+1];
duke@0 328 static const Type* _const_basic_type[T_CONFLICT+1];
duke@0 329 };
duke@0 330
duke@0 331 //------------------------------TypeF------------------------------------------
duke@0 332 // Class of Float-Constant Types.
duke@0 333 class TypeF : public Type {
duke@0 334 TypeF( float f ) : Type(FloatCon), _f(f) {};
duke@0 335 public:
duke@0 336 virtual bool eq( const Type *t ) const;
duke@0 337 virtual int hash() const; // Type specific hashing
duke@0 338 virtual bool singleton(void) const; // TRUE if type is a singleton
duke@0 339 virtual bool empty(void) const; // TRUE if type is vacuous
duke@0 340 public:
duke@0 341 const float _f; // Float constant
duke@0 342
duke@0 343 static const TypeF *make(float f);
duke@0 344
duke@0 345 virtual bool is_finite() const; // Has a finite value
duke@0 346 virtual bool is_nan() const; // Is not a number (NaN)
duke@0 347
duke@0 348 virtual const Type *xmeet( const Type *t ) const;
duke@0 349 virtual const Type *xdual() const; // Compute dual right now.
duke@0 350 // Convenience common pre-built types.
duke@0 351 static const TypeF *ZERO; // positive zero only
duke@0 352 static const TypeF *ONE;
duke@0 353 #ifndef PRODUCT
duke@0 354 virtual void dump2( Dict &d, uint depth, outputStream *st ) const;
duke@0 355 #endif
duke@0 356 };
duke@0 357
duke@0 358 //------------------------------TypeD------------------------------------------
duke@0 359 // Class of Double-Constant Types.
duke@0 360 class TypeD : public Type {
duke@0 361 TypeD( double d ) : Type(DoubleCon), _d(d) {};
duke@0 362 public:
duke@0 363 virtual bool eq( const Type *t ) const;
duke@0 364 virtual int hash() const; // Type specific hashing
duke@0 365 virtual bool singleton(void) const; // TRUE if type is a singleton
duke@0 366 virtual bool empty(void) const; // TRUE if type is vacuous
duke@0 367 public:
duke@0 368 const double _d; // Double constant
duke@0 369
duke@0 370 static const TypeD *make(double d);
duke@0 371
duke@0 372 virtual bool is_finite() const; // Has a finite value
duke@0 373 virtual bool is_nan() const; // Is not a number (NaN)
duke@0 374
duke@0 375 virtual const Type *xmeet( const Type *t ) const;
duke@0 376 virtual const Type *xdual() const; // Compute dual right now.
duke@0 377 // Convenience common pre-built types.
duke@0 378 static const TypeD *ZERO; // positive zero only
duke@0 379 static const TypeD *ONE;
duke@0 380 #ifndef PRODUCT
duke@0 381 virtual void dump2( Dict &d, uint depth, outputStream *st ) const;
duke@0 382 #endif
duke@0 383 };
duke@0 384
duke@0 385 //------------------------------TypeInt----------------------------------------
duke@0 386 // Class of integer ranges, the set of integers between a lower bound and an
duke@0 387 // upper bound, inclusive.
duke@0 388 class TypeInt : public Type {
duke@0 389 TypeInt( jint lo, jint hi, int w );
duke@0 390 public:
duke@0 391 virtual bool eq( const Type *t ) const;
duke@0 392 virtual int hash() const; // Type specific hashing
duke@0 393 virtual bool singleton(void) const; // TRUE if type is a singleton
duke@0 394 virtual bool empty(void) const; // TRUE if type is vacuous
duke@0 395 public:
duke@0 396 const jint _lo, _hi; // Lower bound, upper bound
duke@0 397 const short _widen; // Limit on times we widen this sucker
duke@0 398
duke@0 399 static const TypeInt *make(jint lo);
duke@0 400 // must always specify w
duke@0 401 static const TypeInt *make(jint lo, jint hi, int w);
duke@0 402
duke@0 403 // Check for single integer
duke@0 404 int is_con() const { return _lo==_hi; }
duke@0 405 bool is_con(int i) const { return is_con() && _lo == i; }
duke@0 406 jint get_con() const { assert( is_con(), "" ); return _lo; }
duke@0 407
duke@0 408 virtual bool is_finite() const; // Has a finite value
duke@0 409
duke@0 410 virtual const Type *xmeet( const Type *t ) const;
duke@0 411 virtual const Type *xdual() const; // Compute dual right now.
duke@0 412 virtual const Type *widen( const Type *t ) const;
duke@0 413 virtual const Type *narrow( const Type *t ) const;
duke@0 414 // Do not kill _widen bits.
duke@0 415 virtual const Type *filter( const Type *kills ) const;
duke@0 416 // Convenience common pre-built types.
duke@0 417 static const TypeInt *MINUS_1;
duke@0 418 static const TypeInt *ZERO;
duke@0 419 static const TypeInt *ONE;
duke@0 420 static const TypeInt *BOOL;
duke@0 421 static const TypeInt *CC;
duke@0 422 static const TypeInt *CC_LT; // [-1] == MINUS_1
duke@0 423 static const TypeInt *CC_GT; // [1] == ONE
duke@0 424 static const TypeInt *CC_EQ; // [0] == ZERO
duke@0 425 static const TypeInt *CC_LE; // [-1,0]
duke@0 426 static const TypeInt *CC_GE; // [0,1] == BOOL (!)
duke@0 427 static const TypeInt *BYTE;
twisti@624 428 static const TypeInt *UBYTE;
duke@0 429 static const TypeInt *CHAR;
duke@0 430 static const TypeInt *SHORT;
duke@0 431 static const TypeInt *POS;
duke@0 432 static const TypeInt *POS1;
duke@0 433 static const TypeInt *INT;
duke@0 434 static const TypeInt *SYMINT; // symmetric range [-max_jint..max_jint]
duke@0 435 #ifndef PRODUCT
duke@0 436 virtual void dump2( Dict &d, uint depth, outputStream *st ) const;
duke@0 437 #endif
duke@0 438 };
duke@0 439
duke@0 440
duke@0 441 //------------------------------TypeLong---------------------------------------
duke@0 442 // Class of long integer ranges, the set of integers between a lower bound and
duke@0 443 // an upper bound, inclusive.
duke@0 444 class TypeLong : public Type {
duke@0 445 TypeLong( jlong lo, jlong hi, int w );
duke@0 446 public:
duke@0 447 virtual bool eq( const Type *t ) const;
duke@0 448 virtual int hash() const; // Type specific hashing
duke@0 449 virtual bool singleton(void) const; // TRUE if type is a singleton
duke@0 450 virtual bool empty(void) const; // TRUE if type is vacuous
duke@0 451 public:
duke@0 452 const jlong _lo, _hi; // Lower bound, upper bound
duke@0 453 const short _widen; // Limit on times we widen this sucker
duke@0 454
duke@0 455 static const TypeLong *make(jlong lo);
duke@0 456 // must always specify w
duke@0 457 static const TypeLong *make(jlong lo, jlong hi, int w);
duke@0 458
duke@0 459 // Check for single integer
duke@0 460 int is_con() const { return _lo==_hi; }
rasbold@145 461 bool is_con(int i) const { return is_con() && _lo == i; }
duke@0 462 jlong get_con() const { assert( is_con(), "" ); return _lo; }
duke@0 463
duke@0 464 virtual bool is_finite() const; // Has a finite value
duke@0 465
duke@0 466 virtual const Type *xmeet( const Type *t ) const;
duke@0 467 virtual const Type *xdual() const; // Compute dual right now.
duke@0 468 virtual const Type *widen( const Type *t ) const;
duke@0 469 virtual const Type *narrow( const Type *t ) const;
duke@0 470 // Do not kill _widen bits.
duke@0 471 virtual const Type *filter( const Type *kills ) const;
duke@0 472 // Convenience common pre-built types.
duke@0 473 static const TypeLong *MINUS_1;
duke@0 474 static const TypeLong *ZERO;
duke@0 475 static const TypeLong *ONE;
duke@0 476 static const TypeLong *POS;
duke@0 477 static const TypeLong *LONG;
duke@0 478 static const TypeLong *INT; // 32-bit subrange [min_jint..max_jint]
duke@0 479 static const TypeLong *UINT; // 32-bit unsigned [0..max_juint]
duke@0 480 #ifndef PRODUCT
duke@0 481 virtual void dump2( Dict &d, uint, outputStream *st ) const;// Specialized per-Type dumping
duke@0 482 #endif
duke@0 483 };
duke@0 484
duke@0 485 //------------------------------TypeTuple--------------------------------------
duke@0 486 // Class of Tuple Types, essentially type collections for function signatures
duke@0 487 // and class layouts. It happens to also be a fast cache for the HotSpot
duke@0 488 // signature types.
duke@0 489 class TypeTuple : public Type {
duke@0 490 TypeTuple( uint cnt, const Type **fields ) : Type(Tuple), _cnt(cnt), _fields(fields) { }
duke@0 491 public:
duke@0 492 virtual bool eq( const Type *t ) const;
duke@0 493 virtual int hash() const; // Type specific hashing
duke@0 494 virtual bool singleton(void) const; // TRUE if type is a singleton
duke@0 495 virtual bool empty(void) const; // TRUE if type is vacuous
duke@0 496
duke@0 497 public:
duke@0 498 const uint _cnt; // Count of fields
duke@0 499 const Type ** const _fields; // Array of field types
duke@0 500
duke@0 501 // Accessors:
duke@0 502 uint cnt() const { return _cnt; }
duke@0 503 const Type* field_at(uint i) const {
duke@0 504 assert(i < _cnt, "oob");
duke@0 505 return _fields[i];
duke@0 506 }
duke@0 507 void set_field_at(uint i, const Type* t) {
duke@0 508 assert(i < _cnt, "oob");
duke@0 509 _fields[i] = t;
duke@0 510 }
duke@0 511
duke@0 512 static const TypeTuple *make( uint cnt, const Type **fields );
duke@0 513 static const TypeTuple *make_range(ciSignature *sig);
duke@0 514 static const TypeTuple *make_domain(ciInstanceKlass* recv, ciSignature *sig);
duke@0 515
duke@0 516 // Subroutine call type with space allocated for argument types
duke@0 517 static const Type **fields( uint arg_cnt );
duke@0 518
duke@0 519 virtual const Type *xmeet( const Type *t ) const;
duke@0 520 virtual const Type *xdual() const; // Compute dual right now.
duke@0 521 // Convenience common pre-built types.
duke@0 522 static const TypeTuple *IFBOTH;
duke@0 523 static const TypeTuple *IFFALSE;
duke@0 524 static const TypeTuple *IFTRUE;
duke@0 525 static const TypeTuple *IFNEITHER;
duke@0 526 static const TypeTuple *LOOPBODY;
duke@0 527 static const TypeTuple *MEMBAR;
duke@0 528 static const TypeTuple *STORECONDITIONAL;
duke@0 529 static const TypeTuple *START_I2C;
duke@0 530 static const TypeTuple *INT_PAIR;
duke@0 531 static const TypeTuple *LONG_PAIR;
duke@0 532 #ifndef PRODUCT
duke@0 533 virtual void dump2( Dict &d, uint, outputStream *st ) const; // Specialized per-Type dumping
duke@0 534 #endif
duke@0 535 };
duke@0 536
duke@0 537 //------------------------------TypeAry----------------------------------------
duke@0 538 // Class of Array Types
duke@0 539 class TypeAry : public Type {
duke@0 540 TypeAry( const Type *elem, const TypeInt *size) : Type(Array),
duke@0 541 _elem(elem), _size(size) {}
duke@0 542 public:
duke@0 543 virtual bool eq( const Type *t ) const;
duke@0 544 virtual int hash() const; // Type specific hashing
duke@0 545 virtual bool singleton(void) const; // TRUE if type is a singleton
duke@0 546 virtual bool empty(void) const; // TRUE if type is vacuous
duke@0 547
duke@0 548 private:
duke@0 549 const Type *_elem; // Element type of array
duke@0 550 const TypeInt *_size; // Elements in array
duke@0 551 friend class TypeAryPtr;
duke@0 552
duke@0 553 public:
duke@0 554 static const TypeAry *make( const Type *elem, const TypeInt *size);
duke@0 555
duke@0 556 virtual const Type *xmeet( const Type *t ) const;
duke@0 557 virtual const Type *xdual() const; // Compute dual right now.
duke@0 558 bool ary_must_be_exact() const; // true if arrays of such are never generic
kvn@820 559 #ifdef ASSERT
kvn@820 560 // One type is interface, the other is oop
kvn@820 561 virtual bool interface_vs_oop(const Type *t) const;
kvn@820 562 #endif
duke@0 563 #ifndef PRODUCT
duke@0 564 virtual void dump2( Dict &d, uint, outputStream *st ) const; // Specialized per-Type dumping
duke@0 565 #endif
duke@0 566 };
duke@0 567
duke@0 568 //------------------------------TypePtr----------------------------------------
duke@0 569 // Class of machine Pointer Types: raw data, instances or arrays.
duke@0 570 // If the _base enum is AnyPtr, then this refers to all of the above.
duke@0 571 // Otherwise the _base will indicate which subset of pointers is affected,
duke@0 572 // and the class will be inherited from.
duke@0 573 class TypePtr : public Type {
coleenp@113 574 friend class TypeNarrowOop;
duke@0 575 public:
duke@0 576 enum PTR { TopPTR, AnyNull, Constant, Null, NotNull, BotPTR, lastPTR };
duke@0 577 protected:
duke@0 578 TypePtr( TYPES t, PTR ptr, int offset ) : Type(t), _ptr(ptr), _offset(offset) {}
duke@0 579 virtual bool eq( const Type *t ) const;
duke@0 580 virtual int hash() const; // Type specific hashing
duke@0 581 static const PTR ptr_meet[lastPTR][lastPTR];
duke@0 582 static const PTR ptr_dual[lastPTR];
duke@0 583 static const char * const ptr_msg[lastPTR];
duke@0 584
duke@0 585 public:
duke@0 586 const int _offset; // Offset into oop, with TOP & BOT
duke@0 587 const PTR _ptr; // Pointer equivalence class
duke@0 588
duke@0 589 const int offset() const { return _offset; }
duke@0 590 const PTR ptr() const { return _ptr; }
duke@0 591
duke@0 592 static const TypePtr *make( TYPES t, PTR ptr, int offset );
duke@0 593
duke@0 594 // Return a 'ptr' version of this type
duke@0 595 virtual const Type *cast_to_ptr_type(PTR ptr) const;
duke@0 596
duke@0 597 virtual intptr_t get_con() const;
duke@0 598
kvn@306 599 int xadd_offset( intptr_t offset ) const;
kvn@306 600 virtual const TypePtr *add_offset( intptr_t offset ) const;
duke@0 601
duke@0 602 virtual bool singleton(void) const; // TRUE if type is a singleton
duke@0 603 virtual bool empty(void) const; // TRUE if type is vacuous
duke@0 604 virtual const Type *xmeet( const Type *t ) const;
duke@0 605 int meet_offset( int offset ) const;
duke@0 606 int dual_offset( ) const;
duke@0 607 virtual const Type *xdual() const; // Compute dual right now.
duke@0 608
duke@0 609 // meet, dual and join over pointer equivalence sets
duke@0 610 PTR meet_ptr( const PTR in_ptr ) const { return ptr_meet[in_ptr][ptr()]; }
duke@0 611 PTR dual_ptr() const { return ptr_dual[ptr()]; }
duke@0 612
duke@0 613 // This is textually confusing unless one recalls that
duke@0 614 // join(t) == dual()->meet(t->dual())->dual().
duke@0 615 PTR join_ptr( const PTR in_ptr ) const {
duke@0 616 return ptr_dual[ ptr_meet[ ptr_dual[in_ptr] ] [ dual_ptr() ] ];
duke@0 617 }
duke@0 618
duke@0 619 // Tests for relation to centerline of type lattice:
duke@0 620 static bool above_centerline(PTR ptr) { return (ptr <= AnyNull); }
duke@0 621 static bool below_centerline(PTR ptr) { return (ptr >= NotNull); }
duke@0 622 // Convenience common pre-built types.
duke@0 623 static const TypePtr *NULL_PTR;
duke@0 624 static const TypePtr *NOTNULL;
duke@0 625 static const TypePtr *BOTTOM;
duke@0 626 #ifndef PRODUCT
duke@0 627 virtual void dump2( Dict &d, uint depth, outputStream *st ) const;
duke@0 628 #endif
duke@0 629 };
duke@0 630
duke@0 631 //------------------------------TypeRawPtr-------------------------------------
duke@0 632 // Class of raw pointers, pointers to things other than Oops. Examples
duke@0 633 // include the stack pointer, top of heap, card-marking area, handles, etc.
duke@0 634 class TypeRawPtr : public TypePtr {
duke@0 635 protected:
duke@0 636 TypeRawPtr( PTR ptr, address bits ) : TypePtr(RawPtr,ptr,0), _bits(bits){}
duke@0 637 public:
duke@0 638 virtual bool eq( const Type *t ) const;
duke@0 639 virtual int hash() const; // Type specific hashing
duke@0 640
duke@0 641 const address _bits; // Constant value, if applicable
duke@0 642
duke@0 643 static const TypeRawPtr *make( PTR ptr );
duke@0 644 static const TypeRawPtr *make( address bits );
duke@0 645
duke@0 646 // Return a 'ptr' version of this type
duke@0 647 virtual const Type *cast_to_ptr_type(PTR ptr) const;
duke@0 648
duke@0 649 virtual intptr_t get_con() const;
duke@0 650
kvn@306 651 virtual const TypePtr *add_offset( intptr_t offset ) const;
duke@0 652
duke@0 653 virtual const Type *xmeet( const Type *t ) const;
duke@0 654 virtual const Type *xdual() const; // Compute dual right now.
duke@0 655 // Convenience common pre-built types.
duke@0 656 static const TypeRawPtr *BOTTOM;
duke@0 657 static const TypeRawPtr *NOTNULL;
duke@0 658 #ifndef PRODUCT
duke@0 659 virtual void dump2( Dict &d, uint depth, outputStream *st ) const;
duke@0 660 #endif
duke@0 661 };
duke@0 662
duke@0 663 //------------------------------TypeOopPtr-------------------------------------
duke@0 664 // Some kind of oop (Java pointer), either klass or instance or array.
duke@0 665 class TypeOopPtr : public TypePtr {
duke@0 666 protected:
kvn@163 667 TypeOopPtr( TYPES t, PTR ptr, ciKlass* k, bool xk, ciObject* o, int offset, int instance_id );
duke@0 668 public:
duke@0 669 virtual bool eq( const Type *t ) const;
duke@0 670 virtual int hash() const; // Type specific hashing
duke@0 671 virtual bool singleton(void) const; // TRUE if type is a singleton
duke@0 672 enum {
kvn@223 673 InstanceTop = -1, // undefined instance
kvn@223 674 InstanceBot = 0 // any possible instance
duke@0 675 };
duke@0 676 protected:
duke@0 677
duke@0 678 // Oop is NULL, unless this is a constant oop.
duke@0 679 ciObject* _const_oop; // Constant oop
duke@0 680 // If _klass is NULL, then so is _sig. This is an unloaded klass.
duke@0 681 ciKlass* _klass; // Klass object
duke@0 682 // Does the type exclude subclasses of the klass? (Inexact == polymorphic.)
duke@0 683 bool _klass_is_exact;
kvn@163 684 bool _is_ptr_to_narrowoop;
duke@0 685
kvn@223 686 // If not InstanceTop or InstanceBot, indicates that this is
kvn@223 687 // a particular instance of this type which is distinct.
kvn@223 688 // This is the the node index of the allocation node creating this instance.
kvn@223 689 int _instance_id;
duke@0 690
duke@0 691 static const TypeOopPtr* make_from_klass_common(ciKlass* klass, bool klass_change, bool try_for_exact);
duke@0 692
kvn@223 693 int dual_instance_id() const;
kvn@223 694 int meet_instance_id(int uid) const;
duke@0 695
duke@0 696 public:
duke@0 697 // Creates a type given a klass. Correctly handles multi-dimensional arrays
duke@0 698 // Respects UseUniqueSubclasses.
duke@0 699 // If the klass is final, the resulting type will be exact.
duke@0 700 static const TypeOopPtr* make_from_klass(ciKlass* klass) {
duke@0 701 return make_from_klass_common(klass, true, false);
duke@0 702 }
duke@0 703 // Same as before, but will produce an exact type, even if
duke@0 704 // the klass is not final, as long as it has exactly one implementation.
duke@0 705 static const TypeOopPtr* make_from_klass_unique(ciKlass* klass) {
duke@0 706 return make_from_klass_common(klass, true, true);
duke@0 707 }
duke@0 708 // Same as before, but does not respects UseUniqueSubclasses.
duke@0 709 // Use this only for creating array element types.
duke@0 710 static const TypeOopPtr* make_from_klass_raw(ciKlass* klass) {
duke@0 711 return make_from_klass_common(klass, false, false);
duke@0 712 }
duke@0 713 // Creates a singleton type given an object.
duke@0 714 static const TypeOopPtr* make_from_constant(ciObject* o);
duke@0 715
duke@0 716 // Make a generic (unclassed) pointer to an oop.
kvn@958 717 static const TypeOopPtr* make(PTR ptr, int offset, int instance_id = InstanceBot);
duke@0 718
duke@0 719 ciObject* const_oop() const { return _const_oop; }
duke@0 720 virtual ciKlass* klass() const { return _klass; }
duke@0 721 bool klass_is_exact() const { return _klass_is_exact; }
kvn@163 722
kvn@163 723 // Returns true if this pointer points at memory which contains a
kvn@163 724 // compressed oop references.
kvn@163 725 bool is_ptr_to_narrowoop_nv() const { return _is_ptr_to_narrowoop; }
kvn@163 726
kvn@223 727 bool is_known_instance() const { return _instance_id > 0; }
kvn@223 728 int instance_id() const { return _instance_id; }
kvn@223 729 bool is_known_instance_field() const { return is_known_instance() && _offset >= 0; }
duke@0 730
duke@0 731 virtual intptr_t get_con() const;
duke@0 732
duke@0 733 virtual const Type *cast_to_ptr_type(PTR ptr) const;
duke@0 734
duke@0 735 virtual const Type *cast_to_exactness(bool klass_is_exact) const;
duke@0 736
kvn@223 737 virtual const TypeOopPtr *cast_to_instance_id(int instance_id) const;
duke@0 738
duke@0 739 // corresponding pointer to klass, for a given instance
duke@0 740 const TypeKlassPtr* as_klass_type() const;
duke@0 741
kvn@306 742 virtual const TypePtr *add_offset( intptr_t offset ) const;
duke@0 743
duke@0 744 virtual const Type *xmeet( const Type *t ) const;
duke@0 745 virtual const Type *xdual() const; // Compute dual right now.
duke@0 746
duke@0 747 // Do not allow interface-vs.-noninterface joins to collapse to top.
duke@0 748 virtual const Type *filter( const Type *kills ) const;
duke@0 749
duke@0 750 // Convenience common pre-built type.
duke@0 751 static const TypeOopPtr *BOTTOM;
duke@0 752 #ifndef PRODUCT
duke@0 753 virtual void dump2( Dict &d, uint depth, outputStream *st ) const;
duke@0 754 #endif
duke@0 755 };
duke@0 756
duke@0 757 //------------------------------TypeInstPtr------------------------------------
duke@0 758 // Class of Java object pointers, pointing either to non-array Java instances
duke@0 759 // or to a klassOop (including array klasses).
duke@0 760 class TypeInstPtr : public TypeOopPtr {
duke@0 761 TypeInstPtr( PTR ptr, ciKlass* k, bool xk, ciObject* o, int offset, int instance_id );
duke@0 762 virtual bool eq( const Type *t ) const;
duke@0 763 virtual int hash() const; // Type specific hashing
duke@0 764
duke@0 765 ciSymbol* _name; // class name
duke@0 766
duke@0 767 public:
duke@0 768 ciSymbol* name() const { return _name; }
duke@0 769
duke@0 770 bool is_loaded() const { return _klass->is_loaded(); }
duke@0 771
duke@0 772 // Make a pointer to a constant oop.
duke@0 773 static const TypeInstPtr *make(ciObject* o) {
duke@0 774 return make(TypePtr::Constant, o->klass(), true, o, 0);
duke@0 775 }
duke@0 776
duke@0 777 // Make a pointer to a constant oop with offset.
duke@0 778 static const TypeInstPtr *make(ciObject* o, int offset) {
duke@0 779 return make(TypePtr::Constant, o->klass(), true, o, offset);
duke@0 780 }
duke@0 781
duke@0 782 // Make a pointer to some value of type klass.
duke@0 783 static const TypeInstPtr *make(PTR ptr, ciKlass* klass) {
duke@0 784 return make(ptr, klass, false, NULL, 0);
duke@0 785 }
duke@0 786
duke@0 787 // Make a pointer to some non-polymorphic value of exactly type klass.
duke@0 788 static const TypeInstPtr *make_exact(PTR ptr, ciKlass* klass) {
duke@0 789 return make(ptr, klass, true, NULL, 0);
duke@0 790 }
duke@0 791
duke@0 792 // Make a pointer to some value of type klass with offset.
duke@0 793 static const TypeInstPtr *make(PTR ptr, ciKlass* klass, int offset) {
duke@0 794 return make(ptr, klass, false, NULL, offset);
duke@0 795 }
duke@0 796
duke@0 797 // Make a pointer to an oop.
kvn@223 798 static const TypeInstPtr *make(PTR ptr, ciKlass* k, bool xk, ciObject* o, int offset, int instance_id = InstanceBot );
duke@0 799
duke@0 800 // If this is a java.lang.Class constant, return the type for it or NULL.
duke@0 801 // Pass to Type::get_const_type to turn it to a type, which will usually
duke@0 802 // be a TypeInstPtr, but may also be a TypeInt::INT for int.class, etc.
duke@0 803 ciType* java_mirror_type() const;
duke@0 804
duke@0 805 virtual const Type *cast_to_ptr_type(PTR ptr) const;
duke@0 806
duke@0 807 virtual const Type *cast_to_exactness(bool klass_is_exact) const;
duke@0 808
kvn@223 809 virtual const TypeOopPtr *cast_to_instance_id(int instance_id) const;
duke@0 810
kvn@306 811 virtual const TypePtr *add_offset( intptr_t offset ) const;
duke@0 812
duke@0 813 virtual const Type *xmeet( const Type *t ) const;
duke@0 814 virtual const TypeInstPtr *xmeet_unloaded( const TypeInstPtr *t ) const;
duke@0 815 virtual const Type *xdual() const; // Compute dual right now.
duke@0 816
duke@0 817 // Convenience common pre-built types.
duke@0 818 static const TypeInstPtr *NOTNULL;
duke@0 819 static const TypeInstPtr *BOTTOM;
duke@0 820 static const TypeInstPtr *MIRROR;
duke@0 821 static const TypeInstPtr *MARK;
duke@0 822 static const TypeInstPtr *KLASS;
duke@0 823 #ifndef PRODUCT
duke@0 824 virtual void dump2( Dict &d, uint depth, outputStream *st ) const; // Specialized per-Type dumping
duke@0 825 #endif
duke@0 826 };
duke@0 827
duke@0 828 //------------------------------TypeAryPtr-------------------------------------
duke@0 829 // Class of Java array pointers
duke@0 830 class TypeAryPtr : public TypeOopPtr {
duke@0 831 TypeAryPtr( PTR ptr, ciObject* o, const TypeAry *ary, ciKlass* k, bool xk, int offset, int instance_id ) : TypeOopPtr(AryPtr,ptr,k,xk,o,offset, instance_id), _ary(ary) {};
duke@0 832 virtual bool eq( const Type *t ) const;
duke@0 833 virtual int hash() const; // Type specific hashing
duke@0 834 const TypeAry *_ary; // Array we point into
duke@0 835
duke@0 836 public:
duke@0 837 // Accessors
duke@0 838 ciKlass* klass() const;
duke@0 839 const TypeAry* ary() const { return _ary; }
duke@0 840 const Type* elem() const { return _ary->_elem; }
duke@0 841 const TypeInt* size() const { return _ary->_size; }
duke@0 842
kvn@223 843 static const TypeAryPtr *make( PTR ptr, const TypeAry *ary, ciKlass* k, bool xk, int offset, int instance_id = InstanceBot);
duke@0 844 // Constant pointer to array
kvn@223 845 static const TypeAryPtr *make( PTR ptr, ciObject* o, const TypeAry *ary, ciKlass* k, bool xk, int offset, int instance_id = InstanceBot);
duke@0 846
duke@0 847 // Convenience
duke@0 848 static const TypeAryPtr *make(ciObject* o);
duke@0 849
duke@0 850 // Return a 'ptr' version of this type
duke@0 851 virtual const Type *cast_to_ptr_type(PTR ptr) const;
duke@0 852
duke@0 853 virtual const Type *cast_to_exactness(bool klass_is_exact) const;
duke@0 854
kvn@223 855 virtual const TypeOopPtr *cast_to_instance_id(int instance_id) const;
duke@0 856
duke@0 857 virtual const TypeAryPtr* cast_to_size(const TypeInt* size) const;
rasbold@366 858 virtual const TypeInt* narrow_size_type(const TypeInt* size) const;
duke@0 859
duke@0 860 virtual bool empty(void) const; // TRUE if type is vacuous
kvn@306 861 virtual const TypePtr *add_offset( intptr_t offset ) const;
duke@0 862
duke@0 863 virtual const Type *xmeet( const Type *t ) const;
duke@0 864 virtual const Type *xdual() const; // Compute dual right now.
duke@0 865
duke@0 866 // Convenience common pre-built types.
duke@0 867 static const TypeAryPtr *RANGE;
duke@0 868 static const TypeAryPtr *OOPS;
kvn@163 869 static const TypeAryPtr *NARROWOOPS;
duke@0 870 static const TypeAryPtr *BYTES;
duke@0 871 static const TypeAryPtr *SHORTS;
duke@0 872 static const TypeAryPtr *CHARS;
duke@0 873 static const TypeAryPtr *INTS;
duke@0 874 static const TypeAryPtr *LONGS;
duke@0 875 static const TypeAryPtr *FLOATS;
duke@0 876 static const TypeAryPtr *DOUBLES;
duke@0 877 // selects one of the above:
duke@0 878 static const TypeAryPtr *get_array_body_type(BasicType elem) {
duke@0 879 assert((uint)elem <= T_CONFLICT && _array_body_type[elem] != NULL, "bad elem type");
duke@0 880 return _array_body_type[elem];
duke@0 881 }
duke@0 882 static const TypeAryPtr *_array_body_type[T_CONFLICT+1];
duke@0 883 // sharpen the type of an int which is used as an array size
kvn@820 884 #ifdef ASSERT
kvn@820 885 // One type is interface, the other is oop
kvn@820 886 virtual bool interface_vs_oop(const Type *t) const;
kvn@820 887 #endif
duke@0 888 #ifndef PRODUCT
duke@0 889 virtual void dump2( Dict &d, uint depth, outputStream *st ) const; // Specialized per-Type dumping
duke@0 890 #endif
duke@0 891 };
duke@0 892
duke@0 893 //------------------------------TypeKlassPtr-----------------------------------
duke@0 894 // Class of Java Klass pointers
duke@0 895 class TypeKlassPtr : public TypeOopPtr {
duke@0 896 TypeKlassPtr( PTR ptr, ciKlass* klass, int offset );
duke@0 897
duke@0 898 virtual bool eq( const Type *t ) const;
duke@0 899 virtual int hash() const; // Type specific hashing
duke@0 900
duke@0 901 public:
duke@0 902 ciSymbol* name() const { return _klass->name(); }
duke@0 903
never@555 904 bool is_loaded() const { return _klass->is_loaded(); }
never@555 905
duke@0 906 // ptr to klass 'k'
duke@0 907 static const TypeKlassPtr *make( ciKlass* k ) { return make( TypePtr::Constant, k, 0); }
duke@0 908 // ptr to klass 'k' with offset
duke@0 909 static const TypeKlassPtr *make( ciKlass* k, int offset ) { return make( TypePtr::Constant, k, offset); }
duke@0 910 // ptr to klass 'k' or sub-klass
duke@0 911 static const TypeKlassPtr *make( PTR ptr, ciKlass* k, int offset);
duke@0 912
duke@0 913 virtual const Type *cast_to_ptr_type(PTR ptr) const;
duke@0 914
duke@0 915 virtual const Type *cast_to_exactness(bool klass_is_exact) const;
duke@0 916
duke@0 917 // corresponding pointer to instance, for a given class
duke@0 918 const TypeOopPtr* as_instance_type() const;
duke@0 919
kvn@306 920 virtual const TypePtr *add_offset( intptr_t offset ) const;
duke@0 921 virtual const Type *xmeet( const Type *t ) const;
duke@0 922 virtual const Type *xdual() const; // Compute dual right now.
duke@0 923
duke@0 924 // Convenience common pre-built types.
duke@0 925 static const TypeKlassPtr* OBJECT; // Not-null object klass or below
duke@0 926 static const TypeKlassPtr* OBJECT_OR_NULL; // Maybe-null version of same
duke@0 927 #ifndef PRODUCT
duke@0 928 virtual void dump2( Dict &d, uint depth, outputStream *st ) const; // Specialized per-Type dumping
duke@0 929 #endif
duke@0 930 };
duke@0 931
kvn@163 932 //------------------------------TypeNarrowOop----------------------------------
coleenp@113 933 // A compressed reference to some kind of Oop. This type wraps around
coleenp@113 934 // a preexisting TypeOopPtr and forwards most of it's operations to
coleenp@113 935 // the underlying type. It's only real purpose is to track the
coleenp@113 936 // oopness of the compressed oop value when we expose the conversion
coleenp@113 937 // between the normal and the compressed form.
coleenp@113 938 class TypeNarrowOop : public Type {
coleenp@113 939 protected:
never@827 940 const TypePtr* _ptrtype; // Could be TypePtr::NULL_PTR
coleenp@113 941
never@827 942 TypeNarrowOop( const TypePtr* ptrtype): Type(NarrowOop),
never@827 943 _ptrtype(ptrtype) {
never@827 944 assert(ptrtype->offset() == 0 ||
never@827 945 ptrtype->offset() == OffsetBot ||
never@827 946 ptrtype->offset() == OffsetTop, "no real offsets");
coleenp@113 947 }
coleenp@113 948 public:
coleenp@113 949 virtual bool eq( const Type *t ) const;
coleenp@113 950 virtual int hash() const; // Type specific hashing
coleenp@113 951 virtual bool singleton(void) const; // TRUE if type is a singleton
coleenp@113 952
coleenp@113 953 virtual const Type *xmeet( const Type *t ) const;
coleenp@113 954 virtual const Type *xdual() const; // Compute dual right now.
coleenp@113 955
coleenp@113 956 virtual intptr_t get_con() const;
coleenp@113 957
coleenp@113 958 // Do not allow interface-vs.-noninterface joins to collapse to top.
coleenp@113 959 virtual const Type *filter( const Type *kills ) const;
coleenp@113 960
coleenp@113 961 virtual bool empty(void) const; // TRUE if type is vacuous
coleenp@113 962
coleenp@113 963 static const TypeNarrowOop *make( const TypePtr* type);
coleenp@113 964
coleenp@113 965 static const TypeNarrowOop* make_from_constant(ciObject* con) {
coleenp@113 966 return make(TypeOopPtr::make_from_constant(con));
coleenp@113 967 }
coleenp@113 968
kvn@221 969 // returns the equivalent ptr type for this compressed pointer
never@827 970 const TypePtr *get_ptrtype() const {
never@827 971 return _ptrtype;
coleenp@113 972 }
coleenp@113 973
coleenp@113 974 static const TypeNarrowOop *BOTTOM;
coleenp@113 975 static const TypeNarrowOop *NULL_PTR;
coleenp@113 976
coleenp@113 977 #ifndef PRODUCT
coleenp@113 978 virtual void dump2( Dict &d, uint depth, outputStream *st ) const;
coleenp@113 979 #endif
coleenp@113 980 };
coleenp@113 981
duke@0 982 //------------------------------TypeFunc---------------------------------------
duke@0 983 // Class of Array Types
duke@0 984 class TypeFunc : public Type {
duke@0 985 TypeFunc( const TypeTuple *domain, const TypeTuple *range ) : Type(Function), _domain(domain), _range(range) {}
duke@0 986 virtual bool eq( const Type *t ) const;
duke@0 987 virtual int hash() const; // Type specific hashing
duke@0 988 virtual bool singleton(void) const; // TRUE if type is a singleton
duke@0 989 virtual bool empty(void) const; // TRUE if type is vacuous
duke@0 990 public:
duke@0 991 // Constants are shared among ADLC and VM
duke@0 992 enum { Control = AdlcVMDeps::Control,
duke@0 993 I_O = AdlcVMDeps::I_O,
duke@0 994 Memory = AdlcVMDeps::Memory,
duke@0 995 FramePtr = AdlcVMDeps::FramePtr,
duke@0 996 ReturnAdr = AdlcVMDeps::ReturnAdr,
duke@0 997 Parms = AdlcVMDeps::Parms
duke@0 998 };
duke@0 999
duke@0 1000 const TypeTuple* const _domain; // Domain of inputs
duke@0 1001 const TypeTuple* const _range; // Range of results
duke@0 1002
duke@0 1003 // Accessors:
duke@0 1004 const TypeTuple* domain() const { return _domain; }
duke@0 1005 const TypeTuple* range() const { return _range; }
duke@0 1006
duke@0 1007 static const TypeFunc *make(ciMethod* method);
duke@0 1008 static const TypeFunc *make(ciSignature signature, const Type* extra);
duke@0 1009 static const TypeFunc *make(const TypeTuple* domain, const TypeTuple* range);
duke@0 1010
duke@0 1011 virtual const Type *xmeet( const Type *t ) const;
duke@0 1012 virtual const Type *xdual() const; // Compute dual right now.
duke@0 1013
duke@0 1014 BasicType return_type() const;
duke@0 1015
duke@0 1016 #ifndef PRODUCT
duke@0 1017 virtual void dump2( Dict &d, uint depth, outputStream *st ) const; // Specialized per-Type dumping
duke@0 1018 void print_flattened() const; // Print a 'flattened' signature
duke@0 1019 #endif
duke@0 1020 // Convenience common pre-built types.
duke@0 1021 };
duke@0 1022
duke@0 1023 //------------------------------accessors--------------------------------------
kvn@163 1024 inline bool Type::is_ptr_to_narrowoop() const {
kvn@163 1025 #ifdef _LP64
kvn@163 1026 return (isa_oopptr() != NULL && is_oopptr()->is_ptr_to_narrowoop_nv());
kvn@163 1027 #else
kvn@163 1028 return false;
kvn@163 1029 #endif
kvn@163 1030 }
kvn@163 1031
duke@0 1032 inline float Type::getf() const {
duke@0 1033 assert( _base == FloatCon, "Not a FloatCon" );
duke@0 1034 return ((TypeF*)this)->_f;
duke@0 1035 }
duke@0 1036
duke@0 1037 inline double Type::getd() const {
duke@0 1038 assert( _base == DoubleCon, "Not a DoubleCon" );
duke@0 1039 return ((TypeD*)this)->_d;
duke@0 1040 }
duke@0 1041
duke@0 1042 inline const TypeF *Type::is_float_constant() const {
duke@0 1043 assert( _base == FloatCon, "Not a Float" );
duke@0 1044 return (TypeF*)this;
duke@0 1045 }
duke@0 1046
duke@0 1047 inline const TypeF *Type::isa_float_constant() const {
duke@0 1048 return ( _base == FloatCon ? (TypeF*)this : NULL);
duke@0 1049 }
duke@0 1050
duke@0 1051 inline const TypeD *Type::is_double_constant() const {
duke@0 1052 assert( _base == DoubleCon, "Not a Double" );
duke@0 1053 return (TypeD*)this;
duke@0 1054 }
duke@0 1055
duke@0 1056 inline const TypeD *Type::isa_double_constant() const {
duke@0 1057 return ( _base == DoubleCon ? (TypeD*)this : NULL);
duke@0 1058 }
duke@0 1059
duke@0 1060 inline const TypeInt *Type::is_int() const {
duke@0 1061 assert( _base == Int, "Not an Int" );
duke@0 1062 return (TypeInt*)this;
duke@0 1063 }
duke@0 1064
duke@0 1065 inline const TypeInt *Type::isa_int() const {
duke@0 1066 return ( _base == Int ? (TypeInt*)this : NULL);
duke@0 1067 }
duke@0 1068
duke@0 1069 inline const TypeLong *Type::is_long() const {
duke@0 1070 assert( _base == Long, "Not a Long" );
duke@0 1071 return (TypeLong*)this;
duke@0 1072 }
duke@0 1073
duke@0 1074 inline const TypeLong *Type::isa_long() const {
duke@0 1075 return ( _base == Long ? (TypeLong*)this : NULL);
duke@0 1076 }
duke@0 1077
duke@0 1078 inline const TypeTuple *Type::is_tuple() const {
duke@0 1079 assert( _base == Tuple, "Not a Tuple" );
duke@0 1080 return (TypeTuple*)this;
duke@0 1081 }
duke@0 1082
duke@0 1083 inline const TypeAry *Type::is_ary() const {
duke@0 1084 assert( _base == Array , "Not an Array" );
duke@0 1085 return (TypeAry*)this;
duke@0 1086 }
duke@0 1087
duke@0 1088 inline const TypePtr *Type::is_ptr() const {
duke@0 1089 // AnyPtr is the first Ptr and KlassPtr the last, with no non-ptrs between.
duke@0 1090 assert(_base >= AnyPtr && _base <= KlassPtr, "Not a pointer");
duke@0 1091 return (TypePtr*)this;
duke@0 1092 }
duke@0 1093
duke@0 1094 inline const TypePtr *Type::isa_ptr() const {
duke@0 1095 // AnyPtr is the first Ptr and KlassPtr the last, with no non-ptrs between.
duke@0 1096 return (_base >= AnyPtr && _base <= KlassPtr) ? (TypePtr*)this : NULL;
duke@0 1097 }
duke@0 1098
duke@0 1099 inline const TypeOopPtr *Type::is_oopptr() const {
duke@0 1100 // OopPtr is the first and KlassPtr the last, with no non-oops between.
duke@0 1101 assert(_base >= OopPtr && _base <= KlassPtr, "Not a Java pointer" ) ;
duke@0 1102 return (TypeOopPtr*)this;
duke@0 1103 }
duke@0 1104
duke@0 1105 inline const TypeOopPtr *Type::isa_oopptr() const {
duke@0 1106 // OopPtr is the first and KlassPtr the last, with no non-oops between.
duke@0 1107 return (_base >= OopPtr && _base <= KlassPtr) ? (TypeOopPtr*)this : NULL;
duke@0 1108 }
duke@0 1109
coleenp@113 1110 inline const TypeRawPtr *Type::isa_rawptr() const {
coleenp@113 1111 return (_base == RawPtr) ? (TypeRawPtr*)this : NULL;
coleenp@113 1112 }
coleenp@113 1113
duke@0 1114 inline const TypeRawPtr *Type::is_rawptr() const {
duke@0 1115 assert( _base == RawPtr, "Not a raw pointer" );
duke@0 1116 return (TypeRawPtr*)this;
duke@0 1117 }
duke@0 1118
duke@0 1119 inline const TypeInstPtr *Type::isa_instptr() const {
duke@0 1120 return (_base == InstPtr) ? (TypeInstPtr*)this : NULL;
duke@0 1121 }
duke@0 1122
duke@0 1123 inline const TypeInstPtr *Type::is_instptr() const {
duke@0 1124 assert( _base == InstPtr, "Not an object pointer" );
duke@0 1125 return (TypeInstPtr*)this;
duke@0 1126 }
duke@0 1127
duke@0 1128 inline const TypeAryPtr *Type::isa_aryptr() const {
duke@0 1129 return (_base == AryPtr) ? (TypeAryPtr*)this : NULL;
duke@0 1130 }
duke@0 1131
duke@0 1132 inline const TypeAryPtr *Type::is_aryptr() const {
duke@0 1133 assert( _base == AryPtr, "Not an array pointer" );
duke@0 1134 return (TypeAryPtr*)this;
duke@0 1135 }
duke@0 1136
coleenp@113 1137 inline const TypeNarrowOop *Type::is_narrowoop() const {
coleenp@113 1138 // OopPtr is the first and KlassPtr the last, with no non-oops between.
coleenp@113 1139 assert(_base == NarrowOop, "Not a narrow oop" ) ;
coleenp@113 1140 return (TypeNarrowOop*)this;
coleenp@113 1141 }
coleenp@113 1142
coleenp@113 1143 inline const TypeNarrowOop *Type::isa_narrowoop() const {
coleenp@113 1144 // OopPtr is the first and KlassPtr the last, with no non-oops between.
coleenp@113 1145 return (_base == NarrowOop) ? (TypeNarrowOop*)this : NULL;
coleenp@113 1146 }
coleenp@113 1147
duke@0 1148 inline const TypeKlassPtr *Type::isa_klassptr() const {
duke@0 1149 return (_base == KlassPtr) ? (TypeKlassPtr*)this : NULL;
duke@0 1150 }
duke@0 1151
duke@0 1152 inline const TypeKlassPtr *Type::is_klassptr() const {
duke@0 1153 assert( _base == KlassPtr, "Not a klass pointer" );
duke@0 1154 return (TypeKlassPtr*)this;
duke@0 1155 }
duke@0 1156
kvn@221 1157 inline const TypePtr* Type::make_ptr() const {
never@827 1158 return (_base == NarrowOop) ? is_narrowoop()->get_ptrtype() :
kvn@221 1159 (isa_ptr() ? is_ptr() : NULL);
kvn@221 1160 }
kvn@221 1161
never@827 1162 inline const TypeOopPtr* Type::make_oopptr() const {
never@827 1163 return (_base == NarrowOop) ? is_narrowoop()->get_ptrtype()->is_oopptr() : is_oopptr();
never@827 1164 }
never@827 1165
kvn@221 1166 inline const TypeNarrowOop* Type::make_narrowoop() const {
kvn@221 1167 return (_base == NarrowOop) ? is_narrowoop() :
kvn@221 1168 (isa_ptr() ? TypeNarrowOop::make(is_ptr()) : NULL);
kvn@221 1169 }
kvn@221 1170
duke@0 1171 inline bool Type::is_floatingpoint() const {
duke@0 1172 if( (_base == FloatCon) || (_base == FloatBot) ||
duke@0 1173 (_base == DoubleCon) || (_base == DoubleBot) )
duke@0 1174 return true;
duke@0 1175 return false;
duke@0 1176 }
duke@0 1177
duke@0 1178
duke@0 1179 // ===============================================================
duke@0 1180 // Things that need to be 64-bits in the 64-bit build but
duke@0 1181 // 32-bits in the 32-bit build. Done this way to get full
duke@0 1182 // optimization AND strong typing.
duke@0 1183 #ifdef _LP64
duke@0 1184
duke@0 1185 // For type queries and asserts
duke@0 1186 #define is_intptr_t is_long
duke@0 1187 #define isa_intptr_t isa_long
duke@0 1188 #define find_intptr_t_type find_long_type
duke@0 1189 #define find_intptr_t_con find_long_con
duke@0 1190 #define TypeX TypeLong
duke@0 1191 #define Type_X Type::Long
duke@0 1192 #define TypeX_X TypeLong::LONG
duke@0 1193 #define TypeX_ZERO TypeLong::ZERO
duke@0 1194 // For 'ideal_reg' machine registers
duke@0 1195 #define Op_RegX Op_RegL
duke@0 1196 // For phase->intcon variants
duke@0 1197 #define MakeConX longcon
duke@0 1198 #define ConXNode ConLNode
duke@0 1199 // For array index arithmetic
duke@0 1200 #define MulXNode MulLNode
duke@0 1201 #define AndXNode AndLNode
duke@0 1202 #define OrXNode OrLNode
duke@0 1203 #define CmpXNode CmpLNode
duke@0 1204 #define SubXNode SubLNode
duke@0 1205 #define LShiftXNode LShiftLNode
duke@0 1206 // For object size computation:
duke@0 1207 #define AddXNode AddLNode
never@17 1208 #define RShiftXNode RShiftLNode
duke@0 1209 // For card marks and hashcodes
duke@0 1210 #define URShiftXNode URShiftLNode
kvn@420 1211 // UseOptoBiasInlining
kvn@420 1212 #define XorXNode XorLNode
kvn@420 1213 #define StoreXConditionalNode StoreLConditionalNode
duke@0 1214 // Opcodes
duke@0 1215 #define Op_LShiftX Op_LShiftL
duke@0 1216 #define Op_AndX Op_AndL
duke@0 1217 #define Op_AddX Op_AddL
duke@0 1218 #define Op_SubX Op_SubL
kvn@851 1219 #define Op_XorX Op_XorL
kvn@851 1220 #define Op_URShiftX Op_URShiftL
duke@0 1221 // conversions
duke@0 1222 #define ConvI2X(x) ConvI2L(x)
duke@0 1223 #define ConvL2X(x) (x)
duke@0 1224 #define ConvX2I(x) ConvL2I(x)
duke@0 1225 #define ConvX2L(x) (x)
duke@0 1226
duke@0 1227 #else
duke@0 1228
duke@0 1229 // For type queries and asserts
duke@0 1230 #define is_intptr_t is_int
duke@0 1231 #define isa_intptr_t isa_int
duke@0 1232 #define find_intptr_t_type find_int_type
duke@0 1233 #define find_intptr_t_con find_int_con
duke@0 1234 #define TypeX TypeInt
duke@0 1235 #define Type_X Type::Int
duke@0 1236 #define TypeX_X TypeInt::INT
duke@0 1237 #define TypeX_ZERO TypeInt::ZERO
duke@0 1238 // For 'ideal_reg' machine registers
duke@0 1239 #define Op_RegX Op_RegI
duke@0 1240 // For phase->intcon variants
duke@0 1241 #define MakeConX intcon
duke@0 1242 #define ConXNode ConINode
duke@0 1243 // For array index arithmetic
duke@0 1244 #define MulXNode MulINode
duke@0 1245 #define AndXNode AndINode
duke@0 1246 #define OrXNode OrINode
duke@0 1247 #define CmpXNode CmpINode
duke@0 1248 #define SubXNode SubINode
duke@0 1249 #define LShiftXNode LShiftINode
duke@0 1250 // For object size computation:
duke@0 1251 #define AddXNode AddINode
never@17 1252 #define RShiftXNode RShiftINode
duke@0 1253 // For card marks and hashcodes
duke@0 1254 #define URShiftXNode URShiftINode
kvn@420 1255 // UseOptoBiasInlining
kvn@420 1256 #define XorXNode XorINode
kvn@420 1257 #define StoreXConditionalNode StoreIConditionalNode
duke@0 1258 // Opcodes
duke@0 1259 #define Op_LShiftX Op_LShiftI
duke@0 1260 #define Op_AndX Op_AndI
duke@0 1261 #define Op_AddX Op_AddI
duke@0 1262 #define Op_SubX Op_SubI
kvn@851 1263 #define Op_XorX Op_XorI
kvn@851 1264 #define Op_URShiftX Op_URShiftI
duke@0 1265 // conversions
duke@0 1266 #define ConvI2X(x) (x)
duke@0 1267 #define ConvL2X(x) ConvL2I(x)
duke@0 1268 #define ConvX2I(x) (x)
duke@0 1269 #define ConvX2L(x) ConvI2L(x)
duke@0 1270
duke@0 1271 #endif