src/share/vm/opto/type.hpp

Sun, 11 Sep 2011 14:48:24 -0700

author
never
date
Sun, 11 Sep 2011 14:48:24 -0700
changeset 3138
f6f3bb0ee072
parent 2708
1d1603768966
child 3882
8c92982cbbc4
permissions
-rw-r--r--

7088955: add C2 IR support to the SA
Reviewed-by: kvn

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

mercurial