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