1 /*
2 * Copyright (c) 1997, 2026, Oracle and/or its affiliates. All rights reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * This code is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation.
8 *
9 * This code is distributed in the hope that it will be useful, but WITHOUT
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
12 * version 2 for more details (a copy is included in the LICENSE file that
13 * accompanied this code).
14 *
15 * You should have received a copy of the GNU General Public License version
16 * 2 along with this work; if not, write to the Free Software Foundation,
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18 *
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20 * or visit www.oracle.com if you need additional information or have any
21 * questions.
22 *
23 */
24
25 #ifndef SHARE_OPTO_TYPE_HPP
26 #define SHARE_OPTO_TYPE_HPP
27
28 #include "opto/adlcVMDeps.hpp"
29 #include "opto/compile.hpp"
30 #include "opto/rangeinference.hpp"
31 #include "runtime/handles.hpp"
32
33 // Portions of code courtesy of Clifford Click
34
35 // Optimization - Graph Style
36
37
38 // This class defines a Type lattice. The lattice is used in the constant
39 // propagation algorithms, and for some type-checking of the iloc code.
40 // Basic types include RSD's (lower bound, upper bound, stride for integers),
41 // float & double precision constants, sets of data-labels and code-labels.
42 // The complete lattice is described below. Subtypes have no relationship to
43 // up or down in the lattice; that is entirely determined by the behavior of
44 // the MEET/JOIN functions.
45
46 class Dict;
47 class Type;
48 class TypeD;
49 class TypeF;
50 class TypeH;
51 class TypeInteger;
52 class TypeInt;
53 class TypeLong;
54 class TypeNarrowPtr;
55 class TypeNarrowOop;
56 class TypeNarrowKlass;
57 class TypeAry;
58 class TypeTuple;
59 class TypeVect;
60 class TypeVectA;
61 class TypeVectS;
62 class TypeVectD;
63 class TypeVectX;
64 class TypeVectY;
65 class TypeVectZ;
66 class TypeVectMask;
67 class TypePtr;
68 class TypeRawPtr;
69 class TypeOopPtr;
70 class TypeInstPtr;
71 class TypeAryPtr;
72 class TypeKlassPtr;
73 class TypeInstKlassPtr;
74 class TypeAryKlassPtr;
75 class TypeMetadataPtr;
76 class VerifyMeet;
77
78 template <class T, class U>
79 class TypeIntPrototype;
80
81 //------------------------------Type-------------------------------------------
82 // Basic Type object, represents a set of primitive Values.
83 // Types are hash-cons'd into a private class dictionary, so only one of each
84 // different kind of Type exists. Types are never modified after creation, so
85 // all their interesting fields are constant.
86 class Type {
87
88 public:
89 enum TYPES {
90 Bad=0, // Type check
91 Control, // Control of code (not in lattice)
92 Top, // Top of the lattice
93 Int, // Integer range (lo-hi)
94 Long, // Long integer range (lo-hi)
95 Half, // Placeholder half of doubleword
96 NarrowOop, // Compressed oop pointer
97 NarrowKlass, // Compressed klass pointer
98
99 Tuple, // Method signature or object layout
100 Array, // Array types
101
102 Interfaces, // Set of implemented interfaces for oop types
103
104 VectorMask, // Vector predicate/mask type
105 VectorA, // (Scalable) Vector types for vector length agnostic
106 VectorS, // 32bit Vector types
107 VectorD, // 64bit Vector types
108 VectorX, // 128bit Vector types
109 VectorY, // 256bit Vector types
110 VectorZ, // 512bit Vector types
111
112 AnyPtr, // Any old raw, klass, inst, or array pointer
113 RawPtr, // Raw (non-oop) pointers
114 OopPtr, // Any and all Java heap entities
115 InstPtr, // Instance pointers (non-array objects)
116 AryPtr, // Array pointers
117 // (Ptr order matters: See is_ptr, isa_ptr, is_oopptr, isa_oopptr.)
118
119 MetadataPtr, // Generic metadata
120 KlassPtr, // Klass pointers
121 InstKlassPtr,
122 AryKlassPtr,
123
124 Function, // Function signature
125 Abio, // Abstract I/O
126 Return_Address, // Subroutine return address
127 Memory, // Abstract store
128 HalfFloatTop, // No float value
129 HalfFloatCon, // Floating point constant
130 HalfFloatBot, // Any float value
131 FloatTop, // No float value
132 FloatCon, // Floating point constant
133 FloatBot, // Any float value
134 DoubleTop, // No double value
135 DoubleCon, // Double precision constant
136 DoubleBot, // Any double value
137 Bottom, // Bottom of lattice
138 lastype // Bogus ending type (not in lattice)
139 };
140
141 // Signal values for offsets from a base pointer
142 enum OFFSET_SIGNALS {
143 OffsetTop = -2000000000, // undefined offset
144 OffsetBot = -2000000001 // any possible offset
145 };
146
147 // Min and max WIDEN values.
148 enum WIDEN {
149 WidenMin = 0,
150 WidenMax = 3
151 };
152
153 private:
154 typedef struct {
155 TYPES dual_type;
156 BasicType basic_type;
157 const char* msg;
158 bool isa_oop;
159 uint ideal_reg;
160 relocInfo::relocType reloc;
161 } TypeInfo;
162
163 // Dictionary of types shared among compilations.
164 static Dict* _shared_type_dict;
165 static const TypeInfo _type_info[];
166
167 static int uhash( const Type *const t );
168 // Structural equality check. Assumes that equals() has already compared
169 // the _base types and thus knows it can cast 't' appropriately.
170 virtual bool eq( const Type *t ) const;
171
172 // Top-level hash-table of types
173 static Dict *type_dict() {
174 return Compile::current()->type_dict();
175 }
176
177 // DUAL operation: reflect around lattice centerline. Used instead of
178 // join to ensure my lattice is symmetric up and down. Dual is computed
179 // lazily, on demand, and cached in _dual.
180 const Type *_dual; // Cached dual value
181
182
183 const Type *meet_helper(const Type *t, bool include_speculative) const;
184 void check_symmetrical(const Type* t, const Type* mt, const VerifyMeet& verify) const NOT_DEBUG_RETURN;
185
186 protected:
187 // Each class of type is also identified by its base.
188 const TYPES _base; // Enum of Types type
189
190 Type( TYPES t ) : _dual(nullptr), _base(t) {} // Simple types
191 // ~Type(); // Use fast deallocation
192 const Type *hashcons(); // Hash-cons the type
193 virtual const Type *filter_helper(const Type *kills, bool include_speculative) const;
194 const Type *join_helper(const Type *t, bool include_speculative) const {
195 assert_type_verify_empty();
196 return dual()->meet_helper(t->dual(), include_speculative)->dual();
197 }
198
199 void assert_type_verify_empty() const NOT_DEBUG_RETURN;
200
201 public:
202
203 // This is used as a marker to identify narrow Klass* loads, which
204 // are really extracted from the mark-word, but we still want to
205 // distinguish it.
206 static int klass_offset() {
207 if (UseCompactObjectHeaders) {
208 return 1;
209 } else {
210 return oopDesc::klass_offset_in_bytes();
211 }
212 }
213
214 inline void* operator new( size_t x ) throw() {
215 Compile* compile = Compile::current();
216 compile->set_type_last_size(x);
217 return compile->type_arena()->AmallocWords(x);
218 }
219 inline void operator delete( void* ptr ) {
220 Compile* compile = Compile::current();
221 compile->type_arena()->Afree(ptr,compile->type_last_size());
222 }
223
224 // Initialize the type system for a particular compilation.
225 static void Initialize(Compile* compile);
226
227 // Initialize the types shared by all compilations.
228 static void Initialize_shared(Compile* compile);
229
230 TYPES base() const {
231 assert(_base > Bad && _base < lastype, "sanity");
232 return _base;
233 }
234
235 // Create a new hash-consd type
236 static const Type *make(enum TYPES);
237 // Test for equivalence of types
238 static bool equals(const Type* t1, const Type* t2);
239 // Test for higher or equal in lattice
240 // Variant that drops the speculative part of the types
241 bool higher_equal(const Type* t) const {
242 return equals(meet(t), t->remove_speculative());
243 }
244 // Variant that keeps the speculative part of the types
245 bool higher_equal_speculative(const Type* t) const {
246 return equals(meet_speculative(t), t);
247 }
248
249 // MEET operation; lower in lattice.
250 // Variant that drops the speculative part of the types
251 const Type *meet(const Type *t) const {
252 return meet_helper(t, false);
253 }
254 // Variant that keeps the speculative part of the types
255 const Type *meet_speculative(const Type *t) const {
256 return meet_helper(t, true)->cleanup_speculative();
257 }
258 // WIDEN: 'widens' for Ints and other range types
259 virtual const Type *widen( const Type *old, const Type* limit ) const { return this; }
260 // NARROW: complement for widen, used by pessimistic phases
261 virtual const Type *narrow( const Type *old ) const { return this; }
262
263 // DUAL operation: reflect around lattice centerline. Used instead of
264 // join to ensure my lattice is symmetric up and down.
265 const Type *dual() const { return _dual; }
266
267 // Compute meet dependent on base type
268 virtual const Type *xmeet( const Type *t ) const;
269 virtual const Type *xdual() const; // Compute dual right now.
270
271 // JOIN operation; higher in lattice. Done by finding the dual of the
272 // meet of the dual of the 2 inputs.
273 // Variant that drops the speculative part of the types
274 const Type *join(const Type *t) const {
275 return join_helper(t, false);
276 }
277 // Variant that keeps the speculative part of the types
278 const Type *join_speculative(const Type *t) const {
279 return join_helper(t, true)->cleanup_speculative();
280 }
281
282 // Modified version of JOIN adapted to the needs Node::Value.
283 // Normalizes all empty values to TOP. Does not kill _widen bits.
284 // Variant that drops the speculative part of the types
285 const Type *filter(const Type *kills) const {
286 return filter_helper(kills, false);
287 }
288 // Variant that keeps the speculative part of the types
289 const Type *filter_speculative(const Type *kills) const {
290 return filter_helper(kills, true)->cleanup_speculative();
291 }
292
293 // Returns true if this pointer points at memory which contains a
294 // compressed oop references.
295 bool is_ptr_to_narrowoop() const;
296 bool is_ptr_to_narrowklass() const;
297
298 // Convenience access
299 short geth() const;
300 virtual float getf() const;
301 double getd() const;
302
303 // This has the same semantics as std::dynamic_cast<TypeClass*>(this)
304 template <typename TypeClass>
305 const TypeClass* try_cast() const;
306
307 const TypeInt *is_int() const;
308 const TypeInt *isa_int() const; // Returns null if not an Int
309 const TypeInteger* is_integer(BasicType bt) const;
310 const TypeInteger* isa_integer(BasicType bt) const;
311 const TypeLong *is_long() const;
312 const TypeLong *isa_long() const; // Returns null if not a Long
313 const TypeD *isa_double() const; // Returns null if not a Double{Top,Con,Bot}
314 const TypeD *is_double_constant() const; // Asserts it is a DoubleCon
315 const TypeD *isa_double_constant() const; // Returns null if not a DoubleCon
316 const TypeH *isa_half_float() const; // Returns null if not a HalfFloat{Top,Con,Bot}
317 const TypeH *is_half_float_constant() const; // Asserts it is a HalfFloatCon
318 const TypeH *isa_half_float_constant() const; // Returns null if not a HalfFloatCon
319 const TypeF *isa_float() const; // Returns null if not a Float{Top,Con,Bot}
320 const TypeF *is_float_constant() const; // Asserts it is a FloatCon
321 const TypeF *isa_float_constant() const; // Returns null if not a FloatCon
322 const TypeTuple *is_tuple() const; // Collection of fields, NOT a pointer
323 const TypeAry *is_ary() const; // Array, NOT array pointer
324 const TypeAry *isa_ary() const; // Returns null of not ary
325 const TypeVect *is_vect() const; // Vector
326 const TypeVect *isa_vect() const; // Returns null if not a Vector
327 const TypeVectMask *is_vectmask() const; // Predicate/Mask Vector
328 const TypeVectMask *isa_vectmask() const; // Returns null if not a Vector Predicate/Mask
329 const TypePtr *is_ptr() const; // Asserts it is a ptr type
330 const TypePtr *isa_ptr() const; // Returns null if not ptr type
331 const TypeRawPtr *isa_rawptr() const; // NOT Java oop
332 const TypeRawPtr *is_rawptr() const; // Asserts is rawptr
333 const TypeNarrowOop *is_narrowoop() const; // Java-style GC'd pointer
334 const TypeNarrowOop *isa_narrowoop() const; // Returns null if not oop ptr type
335 const TypeNarrowKlass *is_narrowklass() const; // compressed klass pointer
336 const TypeNarrowKlass *isa_narrowklass() const;// Returns null if not oop ptr type
337 const TypeOopPtr *isa_oopptr() const; // Returns null if not oop ptr type
338 const TypeOopPtr *is_oopptr() const; // Java-style GC'd pointer
339 const TypeInstPtr *isa_instptr() const; // Returns null if not InstPtr
340 const TypeInstPtr *is_instptr() const; // Instance
341 const TypeAryPtr *isa_aryptr() const; // Returns null if not AryPtr
342 const TypeAryPtr *is_aryptr() const; // Array oop
343
344 template <typename TypeClass>
345 const TypeClass* cast() const;
346
347 const TypeMetadataPtr *isa_metadataptr() const; // Returns null if not oop ptr type
348 const TypeMetadataPtr *is_metadataptr() const; // Java-style GC'd pointer
349 const TypeKlassPtr *isa_klassptr() const; // Returns null if not KlassPtr
350 const TypeKlassPtr *is_klassptr() const; // assert if not KlassPtr
351 const TypeInstKlassPtr *isa_instklassptr() const; // Returns null if not IntKlassPtr
352 const TypeInstKlassPtr *is_instklassptr() const; // assert if not IntKlassPtr
353 const TypeAryKlassPtr *isa_aryklassptr() const; // Returns null if not AryKlassPtr
354 const TypeAryKlassPtr *is_aryklassptr() const; // assert if not AryKlassPtr
355
356 virtual bool is_finite() const; // Has a finite value
357 virtual bool is_nan() const; // Is not a number (NaN)
358
359 // Returns this ptr type or the equivalent ptr type for this compressed pointer.
360 const TypePtr* make_ptr() const;
361
362 // Returns this oopptr type or the equivalent oopptr type for this compressed pointer.
363 // Asserts if the underlying type is not an oopptr or narrowoop.
364 const TypeOopPtr* make_oopptr() const;
365
366 // Returns this compressed pointer or the equivalent compressed version
367 // of this pointer type.
368 const TypeNarrowOop* make_narrowoop() const;
369
370 // Returns this compressed klass pointer or the equivalent
371 // compressed version of this pointer type.
372 const TypeNarrowKlass* make_narrowklass() const;
373
374 // Special test for register pressure heuristic
375 bool is_floatingpoint() const; // True if Float or Double base type
376
377 // Do you have memory, directly or through a tuple?
378 bool has_memory( ) const;
379
380 // TRUE if type is a singleton
381 virtual bool singleton(void) const;
382
383 // TRUE if type is above the lattice centerline, and is therefore vacuous
384 virtual bool empty(void) const;
385
386 // Return a hash for this type. The hash function is public so ConNode
387 // (constants) can hash on their constant, which is represented by a Type.
388 virtual uint hash() const;
389
390 // Map ideal registers (machine types) to ideal types
391 static const Type *mreg2type[];
392
393 // Printing, statistics
394 #ifndef PRODUCT
395 void dump_on(outputStream *st) const;
396 void dump() const {
397 dump_on(tty);
398 }
399 virtual void dump2( Dict &d, uint depth, outputStream *st ) const;
400 static void dump_stats();
401 // Groups of types, for debugging and visualization only.
402 enum class Category {
403 Data,
404 Memory,
405 Mixed, // Tuples with types of different categories.
406 Control,
407 Other, // {Type::Top, Type::Abio, Type::Bottom}.
408 Undef // {Type::Bad, Type::lastype}, for completeness.
409 };
410 // Return the category of this type.
411 Category category() const;
412 // Check recursively in tuples.
413 bool has_category(Category cat) const;
414
415 static const char* str(const Type* t);
416 #endif // !PRODUCT
417 void typerr(const Type *t) const; // Mixing types error
418
419 // Create basic type
420 static const Type* get_const_basic_type(BasicType type) {
421 assert((uint)type <= T_CONFLICT && _const_basic_type[type] != nullptr, "bad type");
422 return _const_basic_type[type];
423 }
424
425 // For two instance arrays of same dimension, return the base element types.
426 // Otherwise or if the arrays have different dimensions, return null.
427 static void get_arrays_base_elements(const Type *a1, const Type *a2,
428 const TypeInstPtr **e1, const TypeInstPtr **e2);
429
430 // Mapping to the array element's basic type.
431 BasicType array_element_basic_type() const;
432
433 enum InterfaceHandling {
434 trust_interfaces,
435 ignore_interfaces
436 };
437 // Create standard type for a ciType:
438 static const Type* get_const_type(ciType* type, InterfaceHandling interface_handling = ignore_interfaces);
439
440 // Create standard zero value:
441 static const Type* get_zero_type(BasicType type) {
442 assert((uint)type <= T_CONFLICT && _zero_type[type] != nullptr, "bad type");
443 return _zero_type[type];
444 }
445
446 // Report if this is a zero value (not top).
447 bool is_zero_type() const {
448 BasicType type = basic_type();
449 if (type == T_VOID || type >= T_CONFLICT)
450 return false;
451 else
452 return (this == _zero_type[type]);
453 }
454
455 // Convenience common pre-built types.
456 static const Type *ABIO;
457 static const Type *BOTTOM;
458 static const Type *CONTROL;
459 static const Type *DOUBLE;
460 static const Type *FLOAT;
461 static const Type *HALF_FLOAT;
462 static const Type *HALF;
463 static const Type *MEMORY;
464 static const Type *MULTI;
465 static const Type *RETURN_ADDRESS;
466 static const Type *TOP;
467
468 // Mapping from compiler type to VM BasicType
469 BasicType basic_type() const { return _type_info[_base].basic_type; }
470 uint ideal_reg() const { return _type_info[_base].ideal_reg; }
471 const char* msg() const { return _type_info[_base].msg; }
472 bool isa_oop_ptr() const { return _type_info[_base].isa_oop; }
473 relocInfo::relocType reloc() const { return _type_info[_base].reloc; }
474
475 // Mapping from CI type system to compiler type:
476 static const Type* get_typeflow_type(ciType* type);
477
478 static const Type* make_from_constant(ciConstant constant,
479 bool require_constant = false,
480 int stable_dimension = 0,
481 bool is_narrow = false,
482 bool is_autobox_cache = false);
483
484 static const Type* make_constant_from_field(ciInstance* holder,
485 int off,
486 bool is_unsigned_load,
487 BasicType loadbt);
488
489 static const Type* make_constant_from_field(ciField* field,
490 ciInstance* holder,
491 BasicType loadbt,
492 bool is_unsigned_load);
493
494 static const Type* make_constant_from_array_element(ciArray* array,
495 int off,
496 int stable_dimension,
497 BasicType loadbt,
498 bool is_unsigned_load);
499
500 // Speculative type helper methods. See TypePtr.
501 virtual const TypePtr* speculative() const { return nullptr; }
502 virtual ciKlass* speculative_type() const { return nullptr; }
503 virtual ciKlass* speculative_type_not_null() const { return nullptr; }
504 virtual bool speculative_maybe_null() const { return true; }
505 virtual bool speculative_always_null() const { return true; }
506 virtual const Type* remove_speculative() const { return this; }
507 virtual const Type* cleanup_speculative() const { return this; }
508 virtual bool would_improve_type(ciKlass* exact_kls, int inline_depth) const { return exact_kls != nullptr; }
509 virtual bool would_improve_ptr(ProfilePtrKind ptr_kind) const { return ptr_kind == ProfileAlwaysNull || ptr_kind == ProfileNeverNull; }
510 const Type* maybe_remove_speculative(bool include_speculative) const;
511
512 virtual bool maybe_null() const { return true; }
513 virtual bool is_known_instance() const { return false; }
514
515 private:
516 // support arrays
517 static const Type* _zero_type[T_CONFLICT+1];
518 static const Type* _const_basic_type[T_CONFLICT+1];
519 };
520
521 //------------------------------TypeF------------------------------------------
522 // Class of Float-Constant Types.
523 class TypeF : public Type {
524 TypeF( float f ) : Type(FloatCon), _f(f) {};
525 public:
526 virtual bool eq( const Type *t ) const;
527 virtual uint hash() const; // Type specific hashing
528 virtual bool singleton(void) const; // TRUE if type is a singleton
529 virtual bool empty(void) const; // TRUE if type is vacuous
530 public:
531 const float _f; // Float constant
532
533 static const TypeF *make(float f);
534
535 virtual bool is_finite() const; // Has a finite value
536 virtual bool is_nan() const; // Is not a number (NaN)
537
538 virtual const Type *xmeet( const Type *t ) const;
539 virtual const Type *xdual() const; // Compute dual right now.
540 // Convenience common pre-built types.
541 static const TypeF *MAX;
542 static const TypeF *MIN;
543 static const TypeF *ZERO; // positive zero only
544 static const TypeF *ONE;
545 static const TypeF *POS_INF;
546 static const TypeF *NEG_INF;
547 #ifndef PRODUCT
548 virtual void dump2( Dict &d, uint depth, outputStream *st ) const;
549 #endif
550 };
551
552 // Class of Half Float-Constant Types.
553 class TypeH : public Type {
554 TypeH(short f) : Type(HalfFloatCon), _f(f) {};
555 public:
556 virtual bool eq(const Type* t) const;
557 virtual uint hash() const; // Type specific hashing
558 virtual bool singleton(void) const; // TRUE if type is a singleton
559 virtual bool empty(void) const; // TRUE if type is vacuous
560 public:
561 const short _f; // Half Float constant
562
563 static const TypeH* make(float f);
564 static const TypeH* make(short f);
565
566 virtual bool is_finite() const; // Has a finite value
567 virtual bool is_nan() const; // Is not a number (NaN)
568
569 virtual float getf() const;
570 virtual const Type* xmeet(const Type* t) const;
571 virtual const Type* xdual() const; // Compute dual right now.
572 // Convenience common pre-built types.
573 static const TypeH* MAX;
574 static const TypeH* MIN;
575 static const TypeH* ZERO; // positive zero only
576 static const TypeH* ONE;
577 static const TypeH* POS_INF;
578 static const TypeH* NEG_INF;
579 #ifndef PRODUCT
580 virtual void dump2(Dict &d, uint depth, outputStream* st) const;
581 #endif
582 };
583
584 //------------------------------TypeD------------------------------------------
585 // Class of Double-Constant Types.
586 class TypeD : public Type {
587 TypeD( double d ) : Type(DoubleCon), _d(d) {};
588 public:
589 virtual bool eq( const Type *t ) const;
590 virtual uint hash() const; // Type specific hashing
591 virtual bool singleton(void) const; // TRUE if type is a singleton
592 virtual bool empty(void) const; // TRUE if type is vacuous
593 public:
594 const double _d; // Double constant
595
596 static const TypeD *make(double d);
597
598 virtual bool is_finite() const; // Has a finite value
599 virtual bool is_nan() const; // Is not a number (NaN)
600
601 virtual const Type *xmeet( const Type *t ) const;
602 virtual const Type *xdual() const; // Compute dual right now.
603 // Convenience common pre-built types.
604 static const TypeD *MAX;
605 static const TypeD *MIN;
606 static const TypeD *ZERO; // positive zero only
607 static const TypeD *ONE;
608 static const TypeD *POS_INF;
609 static const TypeD *NEG_INF;
610 #ifndef PRODUCT
611 virtual void dump2( Dict &d, uint depth, outputStream *st ) const;
612 #endif
613 };
614
615 class TypeInteger : public Type {
616 protected:
617 TypeInteger(TYPES t, int w, bool dual) : Type(t), _is_dual(dual), _widen(w) {}
618
619 // Denote that a set is a dual set.
620 // Dual sets are only used to compute the join of 2 sets, and not used
621 // outside.
622 const bool _is_dual;
623
624 public:
625 const short _widen; // Limit on times we widen this sucker
626
627 virtual jlong hi_as_long() const = 0;
628 virtual jlong lo_as_long() const = 0;
629 jlong get_con_as_long(BasicType bt) const;
630 bool is_con() const { return lo_as_long() == hi_as_long(); }
631 virtual short widen_limit() const { return _widen; }
632
633 static const TypeInteger* make(jlong lo, jlong hi, int w, BasicType bt);
634 static const TypeInteger* make(jlong con, BasicType bt);
635
636 static const TypeInteger* bottom(BasicType type);
637 static const TypeInteger* zero(BasicType type);
638 static const TypeInteger* one(BasicType type);
639 static const TypeInteger* minus_1(BasicType type);
640 };
641
642 /**
643 * Definition:
644 *
645 * A TypeInt represents a set of non-empty jint values. A jint v is an element
646 * of a TypeInt iff:
647 *
648 * v >= _lo && v <= _hi &&
649 * juint(v) >= _ulo && juint(v) <= _uhi &&
650 * _bits.is_satisfied_by(v)
651 *
652 * Multiple sets of parameters can represent the same set.
653 * E.g: consider 2 TypeInt t1, t2
654 *
655 * t1._lo = 2, t1._hi = 7, t1._ulo = 0, t1._uhi = 5, t1._bits._zeros = 0x00000000, t1._bits._ones = 0x1
656 * t2._lo = 3, t2._hi = 5, t2._ulo = 3, t2._uhi = 5, t2._bits._zeros = 0xFFFFFFF8, t2._bits._ones = 0x1
657 *
658 * Then, t1 and t2 both represent the set {3, 5}. We can also see that the
659 * constraints of t2 are the tightest possible. I.e there exists no TypeInt t3
660 * which also represents {3, 5} such that any of these would be true:
661 *
662 * 1) t3._lo > t2._lo
663 * 2) t3._hi < t2._hi
664 * 3) t3._ulo > t2._ulo
665 * 4) t3._uhi < t2._uhi
666 * 5) (t3._bits._zeros &~ t2._bis._zeros) != 0
667 * 6) (t3._bits._ones &~ t2._bits._ones) != 0
668 *
669 * The 5-th condition mean that the subtraction of the bitsets represented by
670 * t3._bits._zeros and t2._bits._zeros is not empty, which means that the
671 * bits in t3._bits._zeros is not a subset of those in t2._bits._zeros, the
672 * same applies to _bits._ones
673 *
674 * To simplify reasoning about the types in optimizations, we canonicalize
675 * every TypeInt to its tightest form, already at construction. E.g a TypeInt
676 * t with t._lo < 0 will definitely contain negative values. It also makes it
677 * trivial to determine if a TypeInt instance is a subset of another.
678 *
679 * Lemmas:
680 *
681 * 1. Since every TypeInt instance is non-empty and canonicalized, all the
682 * bounds must also be elements of such TypeInt. Or else, we can tighten the
683 * bounds by narrowing it by one, which contradicts the assumption of the
684 * TypeInt being canonical.
685 *
686 * 2.
687 * 2.1. _lo <= jint(_ulo)
688 * 2.2. _lo <= _hi
689 * 2.3. _lo <= jint(_uhi)
690 * 2.4. _ulo <= juint(_lo)
691 * 2.5. _ulo <= juint(_hi)
692 * 2.6. _ulo <= _uhi
693 * 2.7. _hi >= _lo
694 * 2.8. _hi >= jint(_ulo)
695 * 2.9. _hi >= jint(_uhi)
696 * 2.10. _uhi >= juint(_lo)
697 * 2.11. _uhi >= _ulo
698 * 2.12. _uhi >= juint(_hi)
699 *
700 * Proof of lemma 2:
701 *
702 * 2.1. _lo <= jint(_ulo):
703 * According the lemma 1, _ulo is an element of the TypeInt, so in the
704 * signed domain, it must not be less than the smallest element of that
705 * TypeInt, which is _lo. Which means that _lo <= _ulo in the signed
706 * domain, or in a more programmatical way, _lo <= jint(_ulo).
707 * 2.2. _lo <= _hi:
708 * According the lemma 1, _hi is an element of the TypeInt, so in the
709 * signed domain, it must not be less than the smallest element of that
710 * TypeInt, which is _lo. Which means that _lo <= _hi.
711 *
712 * The other inequalities can be proved in a similar manner.
713 *
714 * 3. Given 2 jint values x, y where either both >= 0 or both < 0. Then:
715 *
716 * x <= y iff juint(x) <= juint(y)
717 * I.e. x <= y in the signed domain iff x <= y in the unsigned domain
718 *
719 * 4. Either _lo == jint(_ulo) and _hi == jint(_uhi), or each element of a
720 * TypeInt lies in either interval [_lo, jint(_uhi)] or [jint(_ulo), _hi]
721 * (note that these intervals are disjoint in this case).
722 *
723 * Proof of lemma 4:
724 *
725 * For a TypeInt t, there are 3 possible cases:
726 *
727 * a. t._lo >= 0, we have:
728 *
729 * 0 <= t_lo <= jint(t._ulo) (lemma 2.1)
730 * juint(t._lo) <= juint(jint(t._ulo)) (lemma 3)
731 * == t._ulo (juint(jint(v)) == v with juint v)
732 * <= juint(t._lo) (lemma 2.4)
733 *
734 * Which means that t._lo == jint(t._ulo).
735 *
736 * Furthermore,
737 *
738 * 0 <= t._lo <= t._hi (lemma 2.2)
739 * 0 <= t._lo <= jint(t._uhi) (lemma 2.3)
740 * t._hi >= jint(t._uhi) (lemma 2.9)
741 *
742 * juint(t._hi) >= juint(jint(t._uhi)) (lemma 3)
743 * == t._uhi (juint(jint(v)) == v with juint v)
744 * >= juint(t._hi) (lemma 2.12)
745 *
746 * Which means that t._hi == jint(t._uhi).
747 * In this case, t._lo == jint(t._ulo) and t._hi == jint(t._uhi)
748 *
749 * b. t._hi < 0. Similarly, we can conclude that:
750 * t._lo == jint(t._ulo) and t._hi == jint(t._uhi)
751 *
752 * c. t._lo < 0, t._hi >= 0.
753 *
754 * Since t._ulo <= juint(t._hi) (lemma 2.5), we must have jint(t._ulo) >= 0
755 * because all negative values is larger than all non-negative values in the
756 * unsigned domain.
757 *
758 * Since t._uhi >= juint(t._lo) (lemma 2.10), we must have jint(t._uhi) < 0
759 * similar to the reasoning above.
760 *
761 * In this case, each element of t belongs to either [t._lo, jint(t._uhi)] or
762 * [jint(t._ulo), t._hi].
763 *
764 * Below is an illustration of the TypeInt in this case, the intervals that
765 * the elements can be in are marked using the = symbol. Note how the
766 * negative range in the signed domain wrap around in the unsigned domain.
767 *
768 * Signed:
769 * -----lo=========uhi---------0--------ulo==========hi-----
770 * Unsigned:
771 * 0--------ulo==========hi----------lo=========uhi---------
772 *
773 * This property is useful for our analysis of TypeInt values. Additionally,
774 * it can be seen that _lo and jint(_uhi) are both < 0 or both >= 0, and the
775 * same applies to jint(_ulo) and _hi.
776 *
777 * We call [_lo, jint(_uhi)] and [jint(_ulo), _hi] "simple intervals". Then,
778 * a TypeInt consists of 2 simple intervals, each of which has its bounds
779 * being both >= 0 or both < 0. If both simple intervals lie in the same half
780 * of the integer domain, they must be the same (i.e _lo == jint(_ulo) and
781 * _hi == jint(_uhi)). Otherwise, [_lo, jint(_uhi)] must lie in the negative
782 * half and [jint(_ulo), _hi] must lie in the non-negative half of the signed
783 * domain (equivalently, [_lo, jint(_uhi)] must lie in the upper half and
784 * [jint(_ulo), _hi] must lie in the lower half of the unsigned domain).
785 */
786 class TypeInt : public TypeInteger {
787 private:
788 TypeInt(const TypeIntPrototype<jint, juint>& t, int w, bool dual);
789 static const Type* make_or_top(const TypeIntPrototype<jint, juint>& t, int widen, bool dual);
790
791 friend class TypeIntHelper;
792
793 protected:
794 virtual const Type* filter_helper(const Type* kills, bool include_speculative) const;
795
796 public:
797 typedef jint NativeType;
798 virtual bool eq(const Type* t) const;
799 virtual uint hash() const; // Type specific hashing
800 virtual bool singleton(void) const; // TRUE if type is a singleton
801 virtual bool empty(void) const; // TRUE if type is vacuous
802 // A value is in the set represented by this TypeInt if it satisfies all
803 // the below constraints, see contains(jint)
804 const jint _lo, _hi; // Lower bound, upper bound in the signed domain
805 const juint _ulo, _uhi; // Lower bound, upper bound in the unsigned domain
806 const KnownBits<juint> _bits;
807
808 static const TypeInt* make(jint con);
809 // must always specify w
810 static const TypeInt* make(jint lo, jint hi, int widen);
811 static const Type* make_or_top(const TypeIntPrototype<jint, juint>& t, int widen);
812 static const TypeInt* make(const TypeIntPrototype<jint, juint>& t, int widen) { return make_or_top(t, widen)->is_int(); }
813 static const TypeInt* make(const TypeIntMirror<jint, juint>& t, int widen) {
814 return (new TypeInt(TypeIntPrototype<jint, juint>{{t._lo, t._hi}, {t._ulo, t._uhi}, t._bits}, widen, false))->hashcons()->is_int();
815 }
816
817 // Check for single integer
818 bool is_con() const { return _lo == _hi; }
819 bool is_con(jint i) const { return is_con() && _lo == i; }
820 jint get_con() const { assert(is_con(), ""); return _lo; }
821 // Check if a jint/TypeInt is a subset of this TypeInt (i.e. all elements of the
822 // argument are also elements of this type)
823 bool contains(jint i) const;
824 bool contains(const TypeInt* t) const;
825
826 #ifdef ASSERT
827 // Check whether t is a proper subset (i.e. a subset that is not equal to the superset) of this
828 bool strictly_contains(const TypeInt* t) const;
829 #endif // ASSERT
830
831 virtual bool is_finite() const; // Has a finite value
832
833 virtual const Type* xmeet(const Type* t) const;
834 virtual const Type* xdual() const; // Compute dual right now.
835 virtual const Type* widen(const Type* t, const Type* limit_type) const;
836 virtual const Type* narrow(const Type* t) const;
837
838 virtual jlong hi_as_long() const { return _hi; }
839 virtual jlong lo_as_long() const { return _lo; }
840
841 // Do not kill _widen bits.
842 // Convenience common pre-built types.
843 static const TypeInt* MAX;
844 static const TypeInt* MIN;
845 static const TypeInt* MINUS_1;
846 static const TypeInt* ZERO;
847 static const TypeInt* ONE;
848 static const TypeInt* BOOL;
849 static const TypeInt* CC;
850 static const TypeInt* CC_LT; // [-1] == MINUS_1
851 static const TypeInt* CC_GT; // [1] == ONE
852 static const TypeInt* CC_EQ; // [0] == ZERO
853 static const TypeInt* CC_NE; // [-1, 1]
854 static const TypeInt* CC_LE; // [-1,0]
855 static const TypeInt* CC_GE; // [0,1] == BOOL (!)
856 static const TypeInt* BYTE;
857 static const TypeInt* UBYTE;
858 static const TypeInt* CHAR;
859 static const TypeInt* SHORT;
860 static const TypeInt* NON_ZERO;
861 static const TypeInt* POS;
862 static const TypeInt* POS1;
863 static const TypeInt* INT;
864 static const TypeInt* SYMINT; // symmetric range [-max_jint..max_jint]
865 static const TypeInt* TYPE_DOMAIN; // alias for TypeInt::INT
866
867 static const TypeInt* as_self(const Type* t) { return t->is_int(); }
868 #ifndef PRODUCT
869 virtual void dump2(Dict& d, uint depth, outputStream* st) const;
870 void dump_verbose() const;
871 #endif
872 };
873
874 // Similar to TypeInt
875 class TypeLong : public TypeInteger {
876 private:
877 TypeLong(const TypeIntPrototype<jlong, julong>& t, int w, bool dual);
878 static const Type* make_or_top(const TypeIntPrototype<jlong, julong>& t, int widen, bool dual);
879
880 friend class TypeIntHelper;
881
882 protected:
883 // Do not kill _widen bits.
884 virtual const Type* filter_helper(const Type* kills, bool include_speculative) const;
885 public:
886 typedef jlong NativeType;
887 virtual bool eq( const Type *t ) const;
888 virtual uint hash() const; // Type specific hashing
889 virtual bool singleton(void) const; // TRUE if type is a singleton
890 virtual bool empty(void) const; // TRUE if type is vacuous
891 public:
892 // A value is in the set represented by this TypeLong if it satisfies all
893 // the below constraints, see contains(jlong)
894 const jlong _lo, _hi; // Lower bound, upper bound in the signed domain
895 const julong _ulo, _uhi; // Lower bound, upper bound in the unsigned domain
896 const KnownBits<julong> _bits;
897
898 static const TypeLong* make(jlong con);
899 // must always specify w
900 static const TypeLong* make(jlong lo, jlong hi, int widen);
901 static const Type* make_or_top(const TypeIntPrototype<jlong, julong>& t, int widen);
902 static const TypeLong* make(const TypeIntPrototype<jlong, julong>& t, int widen) { return make_or_top(t, widen)->is_long(); }
903 static const TypeLong* make(const TypeIntMirror<jlong, julong>& t, int widen) {
904 return (new TypeLong(TypeIntPrototype<jlong, julong>{{t._lo, t._hi}, {t._ulo, t._uhi}, t._bits}, widen, false))->hashcons()->is_long();
905 }
906
907 // Check for single integer
908 bool is_con() const { return _lo == _hi; }
909 bool is_con(jlong i) const { return is_con() && _lo == i; }
910 jlong get_con() const { assert(is_con(), "" ); return _lo; }
911 // Check if a jlong/TypeLong is a subset of this TypeLong (i.e. all elements of the
912 // argument are also elements of this type)
913 bool contains(jlong i) const;
914 bool contains(const TypeLong* t) const;
915
916 #ifdef ASSERT
917 // Check whether t is a proper subset (i.e. a subset that is not equal to the superset) of this
918 bool strictly_contains(const TypeLong* t) const;
919 #endif // ASSERT
920
921 // Check for positive 32-bit value.
922 int is_positive_int() const { return _lo >= 0 && _hi <= (jlong)max_jint; }
923
924 virtual bool is_finite() const; // Has a finite value
925
926 virtual jlong hi_as_long() const { return _hi; }
927 virtual jlong lo_as_long() const { return _lo; }
928
929 virtual const Type* xmeet(const Type* t) const;
930 virtual const Type* xdual() const; // Compute dual right now.
931 virtual const Type* widen(const Type* t, const Type* limit_type) const;
932 virtual const Type* narrow(const Type* t) const;
933 // Convenience common pre-built types.
934 static const TypeLong* MAX;
935 static const TypeLong* MIN;
936 static const TypeLong* MINUS_1;
937 static const TypeLong* ZERO;
938 static const TypeLong* ONE;
939 static const TypeLong* NON_ZERO;
940 static const TypeLong* POS;
941 static const TypeLong* NEG;
942 static const TypeLong* LONG;
943 static const TypeLong* INT; // 32-bit subrange [min_jint..max_jint]
944 static const TypeLong* UINT; // 32-bit unsigned [0..max_juint]
945 static const TypeLong* TYPE_DOMAIN; // alias for TypeLong::LONG
946
947 // static convenience methods.
948 static const TypeLong* as_self(const Type* t) { return t->is_long(); }
949
950 #ifndef PRODUCT
951 virtual void dump2(Dict& d, uint, outputStream* st) const;// Specialized per-Type dumping
952 void dump_verbose() const;
953 #endif
954 };
955
956 //------------------------------TypeTuple--------------------------------------
957 // Class of Tuple Types, essentially type collections for function signatures
958 // and class layouts. It happens to also be a fast cache for the HotSpot
959 // signature types.
960 class TypeTuple : public Type {
961 TypeTuple( uint cnt, const Type **fields ) : Type(Tuple), _cnt(cnt), _fields(fields) { }
962
963 const uint _cnt; // Count of fields
964 const Type ** const _fields; // Array of field types
965
966 public:
967 virtual bool eq( const Type *t ) const;
968 virtual uint hash() const; // Type specific hashing
969 virtual bool singleton(void) const; // TRUE if type is a singleton
970 virtual bool empty(void) const; // TRUE if type is vacuous
971
972 // Accessors:
973 uint cnt() const { return _cnt; }
974 const Type* field_at(uint i) const {
975 assert(i < _cnt, "oob");
976 return _fields[i];
977 }
978 void set_field_at(uint i, const Type* t) {
979 assert(i < _cnt, "oob");
980 _fields[i] = t;
981 }
982
983 static const TypeTuple *make( uint cnt, const Type **fields );
984 static const TypeTuple *make_range(ciSignature *sig, InterfaceHandling interface_handling = ignore_interfaces);
985 static const TypeTuple *make_domain(ciInstanceKlass* recv, ciSignature *sig, InterfaceHandling interface_handling);
986
987 // Subroutine call type with space allocated for argument types
988 // Memory for Control, I_O, Memory, FramePtr, and ReturnAdr is allocated implicitly
989 static const Type **fields( uint arg_cnt );
990
991 virtual const Type *xmeet( const Type *t ) const;
992 virtual const Type *xdual() const; // Compute dual right now.
993 // Convenience common pre-built types.
994 static const TypeTuple *IFBOTH;
995 static const TypeTuple *IFFALSE;
996 static const TypeTuple *IFTRUE;
997 static const TypeTuple *IFNEITHER;
998 static const TypeTuple *LOOPBODY;
999 static const TypeTuple *MEMBAR;
1000 static const TypeTuple *STORECONDITIONAL;
1001 static const TypeTuple *START_I2C;
1002 static const TypeTuple *INT_PAIR;
1003 static const TypeTuple *LONG_PAIR;
1004 static const TypeTuple *INT_CC_PAIR;
1005 static const TypeTuple *LONG_CC_PAIR;
1006 #ifndef PRODUCT
1007 virtual void dump2( Dict &d, uint, outputStream *st ) const; // Specialized per-Type dumping
1008 #endif
1009 };
1010
1011 //------------------------------TypeAry----------------------------------------
1012 // Class of Array Types
1013 class TypeAry : public Type {
1014 TypeAry(const Type* elem, const TypeInt* size, bool stable) : Type(Array),
1015 _elem(elem), _size(size), _stable(stable) {}
1016 public:
1017 virtual bool eq( const Type *t ) const;
1018 virtual uint hash() const; // Type specific hashing
1019 virtual bool singleton(void) const; // TRUE if type is a singleton
1020 virtual bool empty(void) const; // TRUE if type is vacuous
1021
1022 private:
1023 const Type *_elem; // Element type of array
1024 const TypeInt *_size; // Elements in array
1025 const bool _stable; // Are elements @Stable?
1026 friend class TypeAryPtr;
1027
1028 public:
1029 static const TypeAry* make(const Type* elem, const TypeInt* size, bool stable = false);
1030
1031 virtual const Type *xmeet( const Type *t ) const;
1032 virtual const Type *xdual() const; // Compute dual right now.
1033 bool ary_must_be_exact() const; // true if arrays of such are never generic
1034 virtual const TypeAry* remove_speculative() const;
1035 virtual const Type* cleanup_speculative() const;
1036 #ifndef PRODUCT
1037 virtual void dump2( Dict &d, uint, outputStream *st ) const; // Specialized per-Type dumping
1038 #endif
1039 };
1040
1041 //------------------------------TypeVect---------------------------------------
1042 // Basic class of vector (mask) types.
1043 class TypeVect : public Type {
1044 const BasicType _elem_bt; // Vector's element type
1045 const uint _length; // Elements in vector (power of 2)
1046
1047 protected:
1048 TypeVect(TYPES t, BasicType elem_bt, uint length) : Type(t),
1049 _elem_bt(elem_bt), _length(length) {}
1050
1051 public:
1052 BasicType element_basic_type() const { return _elem_bt; }
1053 uint length() const { return _length; }
1054 uint length_in_bytes() const {
1055 return _length * type2aelembytes(element_basic_type());
1056 }
1057
1058 virtual bool eq(const Type* t) const;
1059 virtual uint hash() const; // Type specific hashing
1060 virtual bool singleton(void) const; // TRUE if type is a singleton
1061 virtual bool empty(void) const; // TRUE if type is vacuous
1062
1063 static const TypeVect* make(const BasicType elem_bt, uint length, bool is_mask = false);
1064 static const TypeVect* makemask(const BasicType elem_bt, uint length);
1065
1066 virtual const Type* xmeet( const Type *t) const;
1067 virtual const Type* xdual() const; // Compute dual right now.
1068
1069 static const TypeVect* VECTA;
1070 static const TypeVect* VECTS;
1071 static const TypeVect* VECTD;
1072 static const TypeVect* VECTX;
1073 static const TypeVect* VECTY;
1074 static const TypeVect* VECTZ;
1075 static const TypeVect* VECTMASK;
1076
1077 #ifndef PRODUCT
1078 virtual void dump2(Dict& d, uint, outputStream* st) const; // Specialized per-Type dumping
1079 #endif
1080 };
1081
1082 // TypeVect subclasses representing vectors or vector masks with "BVectMask" or "NVectMask"
1083 // layout (see vectornode.hpp for detailed notes on vector mask representations), mapped
1084 // to vector registers and distinguished by vector register size:
1085 //
1086 // - TypeVectA: Scalable vector type (variable size, e.g., AArch64 SVE, RISC-V RVV)
1087 // - TypeVectS: 32-bit vector type
1088 // - TypeVectD: 64-bit vector type
1089 // - TypeVectX: 128-bit vector type
1090 // - TypeVectY: 256-bit vector type
1091 // - TypeVectZ: 512-bit vector type
1092 class TypeVectA : public TypeVect {
1093 friend class TypeVect;
1094 TypeVectA(BasicType elem_bt, uint length) : TypeVect(VectorA, elem_bt, length) {}
1095 };
1096
1097 class TypeVectS : public TypeVect {
1098 friend class TypeVect;
1099 TypeVectS(BasicType elem_bt, uint length) : TypeVect(VectorS, elem_bt, length) {}
1100 };
1101
1102 class TypeVectD : public TypeVect {
1103 friend class TypeVect;
1104 TypeVectD(BasicType elem_bt, uint length) : TypeVect(VectorD, elem_bt, length) {}
1105 };
1106
1107 class TypeVectX : public TypeVect {
1108 friend class TypeVect;
1109 TypeVectX(BasicType elem_bt, uint length) : TypeVect(VectorX, elem_bt, length) {}
1110 };
1111
1112 class TypeVectY : public TypeVect {
1113 friend class TypeVect;
1114 TypeVectY(BasicType elem_bt, uint length) : TypeVect(VectorY, elem_bt, length) {}
1115 };
1116
1117 class TypeVectZ : public TypeVect {
1118 friend class TypeVect;
1119 TypeVectZ(BasicType elem_bt, uint length) : TypeVect(VectorZ, elem_bt, length) {}
1120 };
1121
1122 // Class of TypeVectMask, representing vector masks with "PVectMask" layout (see
1123 // vectornode.hpp for detailed notes on vector mask representations), mapped to
1124 // dedicated hardware predicate/mask registers.
1125 class TypeVectMask : public TypeVect {
1126 public:
1127 friend class TypeVect;
1128 TypeVectMask(BasicType elem_bt, uint length) : TypeVect(VectorMask, elem_bt, length) {}
1129 static const TypeVectMask* make(const BasicType elem_bt, uint length);
1130 };
1131
1132 // Set of implemented interfaces. Referenced from TypeOopPtr and TypeKlassPtr.
1133 class TypeInterfaces : public Type {
1134 private:
1135 GrowableArrayFromArray<ciInstanceKlass*> _interfaces;
1136 uint _hash;
1137 ciInstanceKlass* _exact_klass;
1138 DEBUG_ONLY(bool _initialized;)
1139
1140 void initialize();
1141
1142 void verify() const NOT_DEBUG_RETURN;
1143 void compute_hash();
1144 void compute_exact_klass();
1145
1146 TypeInterfaces(ciInstanceKlass** interfaces_base, int nb_interfaces);
1147
1148 NONCOPYABLE(TypeInterfaces);
1149 public:
1150 static const TypeInterfaces* make(GrowableArray<ciInstanceKlass*>* interfaces = nullptr);
1151 bool eq(const Type* other) const;
1152 bool eq(ciInstanceKlass* k) const;
1153 uint hash() const;
1154 const Type *xdual() const;
1155 void dump(outputStream* st) const;
1156 const TypeInterfaces* union_with(const TypeInterfaces* other) const;
1157 const TypeInterfaces* intersection_with(const TypeInterfaces* other) const;
1158 bool contains(const TypeInterfaces* other) const {
1159 return intersection_with(other)->eq(other);
1160 }
1161 bool empty() const { return _interfaces.length() == 0; }
1162
1163 ciInstanceKlass* exact_klass() const;
1164 void verify_is_loaded() const NOT_DEBUG_RETURN;
1165
1166 static int compare(ciInstanceKlass* const& k1, ciInstanceKlass* const& k2);
1167 static int compare(ciInstanceKlass** k1, ciInstanceKlass** k2);
1168
1169 const Type* xmeet(const Type* t) const;
1170
1171 bool singleton(void) const;
1172 bool has_non_array_interface() const;
1173 };
1174
1175 //------------------------------TypePtr----------------------------------------
1176 // Class of machine Pointer Types: raw data, instances or arrays.
1177 // If the _base enum is AnyPtr, then this refers to all of the above.
1178 // Otherwise the _base will indicate which subset of pointers is affected,
1179 // and the class will be inherited from.
1180 class TypePtr : public Type {
1181 friend class TypeNarrowPtr;
1182 friend class Type;
1183 protected:
1184 static const TypeInterfaces* interfaces(ciKlass*& k, bool klass, bool interface, bool array, InterfaceHandling interface_handling);
1185
1186 public:
1187 enum PTR { TopPTR, AnyNull, Constant, Null, NotNull, BotPTR, lastPTR };
1188 protected:
1189 TypePtr(TYPES t, PTR ptr, int offset,
1190 const TypePtr* speculative = nullptr,
1191 int inline_depth = InlineDepthBottom) :
1192 Type(t), _speculative(speculative), _inline_depth(inline_depth), _offset(offset),
1193 _ptr(ptr) {}
1194 static const PTR ptr_meet[lastPTR][lastPTR];
1195 static const PTR ptr_dual[lastPTR];
1196 static const char * const ptr_msg[lastPTR];
1197
1198 enum {
1199 InlineDepthBottom = INT_MAX,
1200 InlineDepthTop = -InlineDepthBottom
1201 };
1202
1203 // Extra type information profiling gave us. We propagate it the
1204 // same way the rest of the type info is propagated. If we want to
1205 // use it, then we have to emit a guard: this part of the type is
1206 // not something we know but something we speculate about the type.
1207 const TypePtr* _speculative;
1208 // For speculative types, we record at what inlining depth the
1209 // profiling point that provided the data is. We want to favor
1210 // profile data coming from outer scopes which are likely better for
1211 // the current compilation.
1212 int _inline_depth;
1213
1214 // utility methods to work on the speculative part of the type
1215 const TypePtr* dual_speculative() const;
1216 const TypePtr* xmeet_speculative(const TypePtr* other) const;
1217 bool eq_speculative(const TypePtr* other) const;
1218 int hash_speculative() const;
1219 const TypePtr* add_offset_speculative(intptr_t offset) const;
1220 const TypePtr* with_offset_speculative(intptr_t offset) const;
1221
1222 // utility methods to work on the inline depth of the type
1223 int dual_inline_depth() const;
1224 int meet_inline_depth(int depth) const;
1225
1226 #ifndef PRODUCT
1227 void dump_speculative(outputStream* st) const;
1228 void dump_inline_depth(outputStream* st) const;
1229 void dump_offset(outputStream* st) const;
1230 #endif
1231
1232 // TypeInstPtr (TypeAryPtr resp.) and TypeInstKlassPtr (TypeAryKlassPtr resp.) implement very similar meet logic.
1233 // The logic for meeting 2 instances (2 arrays resp.) is shared in the 2 utility methods below. However the logic for
1234 // the oop and klass versions can be slightly different and extra logic may have to be executed depending on what
1235 // exact case the meet falls into. The MeetResult struct is used by the utility methods to communicate what case was
1236 // encountered so the right logic specific to klasses or oops can be executed.,
1237 enum MeetResult {
1238 QUICK,
1239 UNLOADED,
1240 SUBTYPE,
1241 NOT_SUBTYPE,
1242 LCA
1243 };
1244 template<class T> static TypePtr::MeetResult meet_instptr(PTR& ptr, const TypeInterfaces*& interfaces, const T* this_type,
1245 const T* other_type, ciKlass*& res_klass, bool& res_xk);
1246
1247 template<class T> static MeetResult meet_aryptr(PTR& ptr, const Type*& elem, const T* this_ary, const T* other_ary,
1248 ciKlass*& res_klass, bool& res_xk);
1249
1250 template <class T1, class T2> static bool is_java_subtype_of_helper_for_instance(const T1* this_one, const T2* other, bool this_exact, bool other_exact);
1251 template <class T1, class T2> static bool is_same_java_type_as_helper_for_instance(const T1* this_one, const T2* other);
1252 template <class T1, class T2> static bool maybe_java_subtype_of_helper_for_instance(const T1* this_one, const T2* other, bool this_exact, bool other_exact);
1253 template <class T1, class T2> static bool is_java_subtype_of_helper_for_array(const T1* this_one, const T2* other, bool this_exact, bool other_exact);
1254 template <class T1, class T2> static bool is_same_java_type_as_helper_for_array(const T1* this_one, const T2* other);
1255 template <class T1, class T2> static bool maybe_java_subtype_of_helper_for_array(const T1* this_one, const T2* other, bool this_exact, bool other_exact);
1256 template <class T1, class T2> static bool is_meet_subtype_of_helper_for_instance(const T1* this_one, const T2* other, bool this_xk, bool other_xk);
1257 template <class T1, class T2> static bool is_meet_subtype_of_helper_for_array(const T1* this_one, const T2* other, bool this_xk, bool other_xk);
1258 public:
1259 const int _offset; // Offset into oop, with TOP & BOT
1260 const PTR _ptr; // Pointer equivalence class
1261
1262 int offset() const { return _offset; }
1263 PTR ptr() const { return _ptr; }
1264
1265 static const TypePtr *make(TYPES t, PTR ptr, int offset,
1266 const TypePtr* speculative = nullptr,
1267 int inline_depth = InlineDepthBottom);
1268
1269 // Return a 'ptr' version of this type
1270 virtual const TypePtr* cast_to_ptr_type(PTR ptr) const;
1271
1272 virtual intptr_t get_con() const;
1273
1274 int xadd_offset( intptr_t offset ) const;
1275 virtual const TypePtr* add_offset(intptr_t offset) const;
1276 virtual const TypePtr* with_offset(intptr_t offset) const;
1277 virtual bool eq(const Type *t) const;
1278 virtual uint hash() const; // Type specific hashing
1279
1280 virtual bool singleton(void) const; // TRUE if type is a singleton
1281 virtual bool empty(void) const; // TRUE if type is vacuous
1282 virtual const Type *xmeet( const Type *t ) const;
1283 virtual const Type *xmeet_helper( const Type *t ) const;
1284 int meet_offset( int offset ) const;
1285 int dual_offset( ) const;
1286 virtual const Type *xdual() const; // Compute dual right now.
1287
1288 // meet, dual and join over pointer equivalence sets
1289 PTR meet_ptr( const PTR in_ptr ) const { return ptr_meet[in_ptr][ptr()]; }
1290 PTR dual_ptr() const { return ptr_dual[ptr()]; }
1291
1292 // This is textually confusing unless one recalls that
1293 // join(t) == dual()->meet(t->dual())->dual().
1294 PTR join_ptr( const PTR in_ptr ) const {
1295 return ptr_dual[ ptr_meet[ ptr_dual[in_ptr] ] [ dual_ptr() ] ];
1296 }
1297
1298 // Speculative type helper methods.
1299 virtual const TypePtr* speculative() const { return _speculative; }
1300 int inline_depth() const { return _inline_depth; }
1301 virtual ciKlass* speculative_type() const;
1302 virtual ciKlass* speculative_type_not_null() const;
1303 virtual bool speculative_maybe_null() const;
1304 virtual bool speculative_always_null() const;
1305 virtual const TypePtr* remove_speculative() const;
1306 virtual const Type* cleanup_speculative() const;
1307 virtual bool would_improve_type(ciKlass* exact_kls, int inline_depth) const;
1308 virtual bool would_improve_ptr(ProfilePtrKind maybe_null) const;
1309 virtual const TypePtr* with_inline_depth(int depth) const;
1310
1311 virtual bool maybe_null() const { return meet_ptr(Null) == ptr(); }
1312
1313 // Tests for relation to centerline of type lattice:
1314 static bool above_centerline(PTR ptr) { return (ptr <= AnyNull); }
1315 static bool below_centerline(PTR ptr) { return (ptr >= NotNull); }
1316 // Convenience common pre-built types.
1317 static const TypePtr *NULL_PTR;
1318 static const TypePtr *NOTNULL;
1319 static const TypePtr *BOTTOM;
1320 #ifndef PRODUCT
1321 virtual void dump2( Dict &d, uint depth, outputStream *st ) const;
1322 #endif
1323 };
1324
1325 //------------------------------TypeRawPtr-------------------------------------
1326 // Class of raw pointers, pointers to things other than Oops. Examples
1327 // include the stack pointer, top of heap, card-marking area, handles, etc.
1328 class TypeRawPtr : public TypePtr {
1329 protected:
1330 TypeRawPtr( PTR ptr, address bits ) : TypePtr(RawPtr,ptr,0), _bits(bits){}
1331 public:
1332 virtual bool eq( const Type *t ) const;
1333 virtual uint hash() const; // Type specific hashing
1334
1335 const address _bits; // Constant value, if applicable
1336
1337 static const TypeRawPtr *make( PTR ptr );
1338 static const TypeRawPtr *make( address bits );
1339
1340 // Return a 'ptr' version of this type
1341 virtual const TypeRawPtr* cast_to_ptr_type(PTR ptr) const;
1342
1343 virtual intptr_t get_con() const;
1344
1345 virtual const TypePtr* add_offset(intptr_t offset) const;
1346 virtual const TypeRawPtr* with_offset(intptr_t offset) const { ShouldNotReachHere(); return nullptr;}
1347
1348 virtual const Type *xmeet( const Type *t ) const;
1349 virtual const Type *xdual() const; // Compute dual right now.
1350 // Convenience common pre-built types.
1351 static const TypeRawPtr *BOTTOM;
1352 static const TypeRawPtr *NOTNULL;
1353 #ifndef PRODUCT
1354 virtual void dump2( Dict &d, uint depth, outputStream *st ) const;
1355 #endif
1356 };
1357
1358 //------------------------------TypeOopPtr-------------------------------------
1359 // Some kind of oop (Java pointer), either instance or array.
1360 class TypeOopPtr : public TypePtr {
1361 friend class TypeAry;
1362 friend class TypePtr;
1363 friend class TypeInstPtr;
1364 friend class TypeAryPtr;
1365 protected:
1366 TypeOopPtr(TYPES t, PTR ptr, ciKlass* k, const TypeInterfaces* interfaces, bool xk, ciObject* o, int offset, int instance_id,
1367 const TypePtr* speculative, int inline_depth);
1368 public:
1369 virtual bool eq( const Type *t ) const;
1370 virtual uint hash() const; // Type specific hashing
1371 virtual bool singleton(void) const; // TRUE if type is a singleton
1372 enum {
1373 InstanceTop = -1, // undefined instance
1374 InstanceBot = 0 // any possible instance
1375 };
1376 protected:
1377
1378 // Oop is null, unless this is a constant oop.
1379 ciObject* _const_oop; // Constant oop
1380 // If _klass is null, then so is _sig. This is an unloaded klass.
1381 ciKlass* _klass; // Klass object
1382
1383 const TypeInterfaces* _interfaces;
1384
1385 // Does the type exclude subclasses of the klass? (Inexact == polymorphic.)
1386 bool _klass_is_exact;
1387 bool _is_ptr_to_narrowoop;
1388 bool _is_ptr_to_narrowklass;
1389 bool _is_ptr_to_boxed_value;
1390
1391 // If not InstanceTop or InstanceBot, indicates that this is
1392 // a particular instance of this type which is distinct.
1393 // This is the node index of the allocation node creating this instance.
1394 int _instance_id;
1395
1396 static const TypeOopPtr* make_from_klass_common(ciKlass* klass, bool klass_change, bool try_for_exact, InterfaceHandling interface_handling);
1397
1398 int dual_instance_id() const;
1399 int meet_instance_id(int uid) const;
1400
1401 const TypeInterfaces* meet_interfaces(const TypeOopPtr* other) const;
1402
1403 // Do not allow interface-vs.-noninterface joins to collapse to top.
1404 virtual const Type *filter_helper(const Type *kills, bool include_speculative) const;
1405
1406 virtual ciKlass* exact_klass_helper() const { return nullptr; }
1407 virtual ciKlass* klass() const { return _klass; }
1408
1409 #ifndef PRODUCT
1410 void dump_instance_id(outputStream* st) const;
1411 #endif // PRODUCT
1412
1413 public:
1414
1415 bool is_java_subtype_of(const TypeOopPtr* other) const {
1416 return is_java_subtype_of_helper(other, klass_is_exact(), other->klass_is_exact());
1417 }
1418
1419 bool is_same_java_type_as(const TypePtr* other) const {
1420 return is_same_java_type_as_helper(other->is_oopptr());
1421 }
1422
1423 virtual bool is_same_java_type_as_helper(const TypeOopPtr* other) const {
1424 ShouldNotReachHere(); return false;
1425 }
1426
1427 bool maybe_java_subtype_of(const TypeOopPtr* other) const {
1428 return maybe_java_subtype_of_helper(other, klass_is_exact(), other->klass_is_exact());
1429 }
1430 virtual bool is_java_subtype_of_helper(const TypeOopPtr* other, bool this_exact, bool other_exact) const { ShouldNotReachHere(); return false; }
1431 virtual bool maybe_java_subtype_of_helper(const TypeOopPtr* other, bool this_exact, bool other_exact) const { ShouldNotReachHere(); return false; }
1432
1433
1434 // Creates a type given a klass. Correctly handles multi-dimensional arrays
1435 // Respects UseUniqueSubclasses.
1436 // If the klass is final, the resulting type will be exact.
1437 static const TypeOopPtr* make_from_klass(ciKlass* klass, InterfaceHandling interface_handling = ignore_interfaces) {
1438 return make_from_klass_common(klass, true, false, interface_handling);
1439 }
1440 // Same as before, but will produce an exact type, even if
1441 // the klass is not final, as long as it has exactly one implementation.
1442 static const TypeOopPtr* make_from_klass_unique(ciKlass* klass, InterfaceHandling interface_handling= ignore_interfaces) {
1443 return make_from_klass_common(klass, true, true, interface_handling);
1444 }
1445 // Same as before, but does not respects UseUniqueSubclasses.
1446 // Use this only for creating array element types.
1447 static const TypeOopPtr* make_from_klass_raw(ciKlass* klass, InterfaceHandling interface_handling = ignore_interfaces) {
1448 return make_from_klass_common(klass, false, false, interface_handling);
1449 }
1450 // Creates a singleton type given an object.
1451 // If the object cannot be rendered as a constant,
1452 // may return a non-singleton type.
1453 // If require_constant, produce a null if a singleton is not possible.
1454 static const TypeOopPtr* make_from_constant(ciObject* o,
1455 bool require_constant = false);
1456
1457 // Make a generic (unclassed) pointer to an oop.
1458 static const TypeOopPtr* make(PTR ptr, int offset, int instance_id,
1459 const TypePtr* speculative = nullptr,
1460 int inline_depth = InlineDepthBottom);
1461
1462 ciObject* const_oop() const { return _const_oop; }
1463 // Exact klass, possibly an interface or an array of interface
1464 ciKlass* exact_klass(bool maybe_null = false) const { assert(klass_is_exact(), ""); ciKlass* k = exact_klass_helper(); assert(k != nullptr || maybe_null, ""); return k; }
1465 ciKlass* unloaded_klass() const { assert(!is_loaded(), "only for unloaded types"); return klass(); }
1466
1467 virtual bool is_loaded() const { return klass()->is_loaded(); }
1468 virtual bool klass_is_exact() const { return _klass_is_exact; }
1469
1470 // Returns true if this pointer points at memory which contains a
1471 // compressed oop references.
1472 bool is_ptr_to_narrowoop_nv() const { return _is_ptr_to_narrowoop; }
1473 bool is_ptr_to_narrowklass_nv() const { return _is_ptr_to_narrowklass; }
1474 bool is_ptr_to_boxed_value() const { return _is_ptr_to_boxed_value; }
1475 bool is_known_instance() const { return _instance_id > 0; }
1476 int instance_id() const { return _instance_id; }
1477 bool is_known_instance_field() const { return is_known_instance() && _offset >= 0; }
1478
1479 virtual intptr_t get_con() const;
1480
1481 virtual const TypeOopPtr* cast_to_ptr_type(PTR ptr) const;
1482
1483 virtual const TypeOopPtr* cast_to_exactness(bool klass_is_exact) const;
1484
1485 virtual const TypeOopPtr *cast_to_instance_id(int instance_id) const;
1486
1487 // corresponding pointer to klass, for a given instance
1488 virtual const TypeKlassPtr* as_klass_type(bool try_for_exact = false) const;
1489
1490 virtual const TypeOopPtr* with_offset(intptr_t offset) const;
1491 virtual const TypePtr* add_offset(intptr_t offset) const;
1492
1493 // Speculative type helper methods.
1494 virtual const TypeOopPtr* remove_speculative() const;
1495 virtual const Type* cleanup_speculative() const;
1496 virtual bool would_improve_type(ciKlass* exact_kls, int inline_depth) const;
1497 virtual const TypePtr* with_inline_depth(int depth) const;
1498
1499 virtual const TypePtr* with_instance_id(int instance_id) const;
1500
1501 virtual const Type *xdual() const; // Compute dual right now.
1502 // the core of the computation of the meet for TypeOopPtr and for its subclasses
1503 virtual const Type *xmeet_helper(const Type *t) const;
1504
1505 // Convenience common pre-built type.
1506 static const TypeOopPtr *BOTTOM;
1507 #ifndef PRODUCT
1508 virtual void dump2( Dict &d, uint depth, outputStream *st ) const;
1509 #endif
1510 private:
1511 virtual bool is_meet_subtype_of(const TypePtr* other) const {
1512 return is_meet_subtype_of_helper(other->is_oopptr(), klass_is_exact(), other->is_oopptr()->klass_is_exact());
1513 }
1514
1515 virtual bool is_meet_subtype_of_helper(const TypeOopPtr* other, bool this_xk, bool other_xk) const {
1516 ShouldNotReachHere(); return false;
1517 }
1518
1519 virtual const TypeInterfaces* interfaces() const {
1520 return _interfaces;
1521 };
1522
1523 const TypeOopPtr* is_reference_type(const Type* other) const {
1524 return other->isa_oopptr();
1525 }
1526
1527 const TypeAryPtr* is_array_type(const TypeOopPtr* other) const {
1528 return other->isa_aryptr();
1529 }
1530
1531 const TypeInstPtr* is_instance_type(const TypeOopPtr* other) const {
1532 return other->isa_instptr();
1533 }
1534 };
1535
1536 //------------------------------TypeInstPtr------------------------------------
1537 // Class of Java object pointers, pointing either to non-array Java instances
1538 // or to a Klass* (including array klasses).
1539 class TypeInstPtr : public TypeOopPtr {
1540 TypeInstPtr(PTR ptr, ciKlass* k, const TypeInterfaces* interfaces, bool xk, ciObject* o, int off, int instance_id,
1541 const TypePtr* speculative, int inline_depth);
1542 virtual bool eq( const Type *t ) const;
1543 virtual uint hash() const; // Type specific hashing
1544
1545 ciKlass* exact_klass_helper() const;
1546
1547 public:
1548
1549 // Instance klass, ignoring any interface
1550 ciInstanceKlass* instance_klass() const {
1551 assert(!(klass()->is_loaded() && klass()->is_interface()), "");
1552 return klass()->as_instance_klass();
1553 }
1554
1555 bool is_same_java_type_as_helper(const TypeOopPtr* other) const;
1556 bool is_java_subtype_of_helper(const TypeOopPtr* other, bool this_exact, bool other_exact) const;
1557 bool maybe_java_subtype_of_helper(const TypeOopPtr* other, bool this_exact, bool other_exact) const;
1558
1559 // Make a pointer to a constant oop.
1560 static const TypeInstPtr *make(ciObject* o) {
1561 ciKlass* k = o->klass();
1562 const TypeInterfaces* interfaces = TypePtr::interfaces(k, true, false, false, ignore_interfaces);
1563 return make(TypePtr::Constant, k, interfaces, true, o, 0, InstanceBot);
1564 }
1565 // Make a pointer to a constant oop with offset.
1566 static const TypeInstPtr *make(ciObject* o, int offset) {
1567 ciKlass* k = o->klass();
1568 const TypeInterfaces* interfaces = TypePtr::interfaces(k, true, false, false, ignore_interfaces);
1569 return make(TypePtr::Constant, k, interfaces, true, o, offset, InstanceBot);
1570 }
1571
1572 // Make a pointer to some value of type klass.
1573 static const TypeInstPtr *make(PTR ptr, ciKlass* klass, InterfaceHandling interface_handling = ignore_interfaces) {
1574 const TypeInterfaces* interfaces = TypePtr::interfaces(klass, true, true, false, interface_handling);
1575 return make(ptr, klass, interfaces, false, nullptr, 0, InstanceBot);
1576 }
1577
1578 // Make a pointer to some non-polymorphic value of exactly type klass.
1579 static const TypeInstPtr *make_exact(PTR ptr, ciKlass* klass) {
1580 const TypeInterfaces* interfaces = TypePtr::interfaces(klass, true, false, false, ignore_interfaces);
1581 return make(ptr, klass, interfaces, true, nullptr, 0, InstanceBot);
1582 }
1583
1584 // Make a pointer to some value of type klass with offset.
1585 static const TypeInstPtr *make(PTR ptr, ciKlass* klass, int offset) {
1586 const TypeInterfaces* interfaces = TypePtr::interfaces(klass, true, false, false, ignore_interfaces);
1587 return make(ptr, klass, interfaces, false, nullptr, offset, InstanceBot);
1588 }
1589
1590 static const TypeInstPtr *make(PTR ptr, ciKlass* k, const TypeInterfaces* interfaces, bool xk, ciObject* o, int offset,
1591 int instance_id = InstanceBot,
1592 const TypePtr* speculative = nullptr,
1593 int inline_depth = InlineDepthBottom);
1594
1595 static const TypeInstPtr *make(PTR ptr, ciKlass* k, bool xk, ciObject* o, int offset, int instance_id = InstanceBot) {
1596 const TypeInterfaces* interfaces = TypePtr::interfaces(k, true, false, false, ignore_interfaces);
1597 return make(ptr, k, interfaces, xk, o, offset, instance_id);
1598 }
1599
1600 /** Create constant type for a constant boxed value */
1601 const Type* get_const_boxed_value() const;
1602
1603 // If this is a java.lang.Class constant, return the type for it or null.
1604 // Pass to Type::get_const_type to turn it to a type, which will usually
1605 // be a TypeInstPtr, but may also be a TypeInt::INT for int.class, etc.
1606 ciType* java_mirror_type() const;
1607
1608 virtual const TypeInstPtr* cast_to_ptr_type(PTR ptr) const;
1609
1610 virtual const TypeInstPtr* cast_to_exactness(bool klass_is_exact) const;
1611
1612 virtual const TypeInstPtr* cast_to_instance_id(int instance_id) const;
1613
1614 virtual const TypePtr* add_offset(intptr_t offset) const;
1615 virtual const TypeInstPtr* with_offset(intptr_t offset) const;
1616
1617 // Speculative type helper methods.
1618 virtual const TypeInstPtr* remove_speculative() const;
1619 const TypeInstPtr* with_speculative(const TypePtr* speculative) const;
1620 virtual const TypePtr* with_inline_depth(int depth) const;
1621 virtual const TypePtr* with_instance_id(int instance_id) const;
1622
1623 // the core of the computation of the meet of 2 types
1624 virtual const Type *xmeet_helper(const Type *t) const;
1625 virtual const TypeInstPtr *xmeet_unloaded(const TypeInstPtr *tinst, const TypeInterfaces* interfaces) const;
1626 virtual const Type *xdual() const; // Compute dual right now.
1627
1628 const TypeKlassPtr* as_klass_type(bool try_for_exact = false) const;
1629
1630 // Convenience common pre-built types.
1631 static const TypeInstPtr *NOTNULL;
1632 static const TypeInstPtr *BOTTOM;
1633 static const TypeInstPtr *MIRROR;
1634 static const TypeInstPtr *MARK;
1635 static const TypeInstPtr *KLASS;
1636 #ifndef PRODUCT
1637 virtual void dump2( Dict &d, uint depth, outputStream *st ) const; // Specialized per-Type dumping
1638 #endif
1639
1640 private:
1641 virtual bool is_meet_subtype_of_helper(const TypeOopPtr* other, bool this_xk, bool other_xk) const;
1642
1643 virtual bool is_meet_same_type_as(const TypePtr* other) const {
1644 return _klass->equals(other->is_instptr()->_klass) && _interfaces->eq(other->is_instptr()->_interfaces);
1645 }
1646
1647 };
1648
1649 //------------------------------TypeAryPtr-------------------------------------
1650 // Class of Java array pointers
1651 class TypeAryPtr : public TypeOopPtr {
1652 friend class Type;
1653 friend class TypePtr;
1654 friend class TypeInterfaces;
1655
1656 TypeAryPtr( PTR ptr, ciObject* o, const TypeAry *ary, ciKlass* k, bool xk,
1657 int offset, int instance_id, bool is_autobox_cache,
1658 const TypePtr* speculative, int inline_depth)
1659 : TypeOopPtr(AryPtr,ptr,k,_array_interfaces,xk,o,offset, instance_id, speculative, inline_depth),
1660 _ary(ary),
1661 _is_autobox_cache(is_autobox_cache)
1662 {
1663 int dummy;
1664 bool top_or_bottom = (base_element_type(dummy) == Type::TOP || base_element_type(dummy) == Type::BOTTOM);
1665
1666 if (UseCompressedOops && (elem()->make_oopptr() != nullptr && !top_or_bottom) &&
1667 _offset != 0 && _offset != arrayOopDesc::length_offset_in_bytes() &&
1668 _offset != Type::klass_offset()) {
1669 _is_ptr_to_narrowoop = true;
1670 }
1671
1672 }
1673 virtual bool eq( const Type *t ) const;
1674 virtual uint hash() const; // Type specific hashing
1675 const TypeAry *_ary; // Array we point into
1676 const bool _is_autobox_cache;
1677
1678 ciKlass* compute_klass() const;
1679
1680 // A pointer to delay allocation to Type::Initialize_shared()
1681
1682 static const TypeInterfaces* _array_interfaces;
1683 ciKlass* exact_klass_helper() const;
1684 // Only guaranteed non null for array of basic types
1685 ciKlass* klass() const;
1686
1687 public:
1688
1689 bool is_same_java_type_as_helper(const TypeOopPtr* other) const;
1690 bool is_java_subtype_of_helper(const TypeOopPtr* other, bool this_exact, bool other_exact) const;
1691 bool maybe_java_subtype_of_helper(const TypeOopPtr* other, bool this_exact, bool other_exact) const;
1692
1693 // returns base element type, an instance klass (and not interface) for object arrays
1694 const Type* base_element_type(int& dims) const;
1695
1696 // Accessors
1697 bool is_loaded() const { return (_ary->_elem->make_oopptr() ? _ary->_elem->make_oopptr()->is_loaded() : true); }
1698
1699 const TypeAry* ary() const { return _ary; }
1700 const Type* elem() const { return _ary->_elem; }
1701 const TypeInt* size() const { return _ary->_size; }
1702 bool is_stable() const { return _ary->_stable; }
1703
1704 bool is_autobox_cache() const { return _is_autobox_cache; }
1705
1706 static const TypeAryPtr *make(PTR ptr, const TypeAry *ary, ciKlass* k, bool xk, int offset,
1707 int instance_id = InstanceBot,
1708 const TypePtr* speculative = nullptr,
1709 int inline_depth = InlineDepthBottom);
1710 // Constant pointer to array
1711 static const TypeAryPtr *make(PTR ptr, ciObject* o, const TypeAry *ary, ciKlass* k, bool xk, int offset,
1712 int instance_id = InstanceBot,
1713 const TypePtr* speculative = nullptr,
1714 int inline_depth = InlineDepthBottom, bool is_autobox_cache = false);
1715
1716 // Return a 'ptr' version of this type
1717 virtual const TypeAryPtr* cast_to_ptr_type(PTR ptr) const;
1718
1719 virtual const TypeAryPtr* cast_to_exactness(bool klass_is_exact) const;
1720
1721 virtual const TypeAryPtr* cast_to_instance_id(int instance_id) const;
1722
1723 virtual const TypeAryPtr* cast_to_size(const TypeInt* size) const;
1724 virtual const TypeInt* narrow_size_type(const TypeInt* size) const;
1725
1726 virtual bool empty(void) const; // TRUE if type is vacuous
1727 virtual const TypePtr *add_offset( intptr_t offset ) const;
1728 virtual const TypeAryPtr *with_offset( intptr_t offset ) const;
1729 const TypeAryPtr* with_ary(const TypeAry* ary) const;
1730
1731 // Speculative type helper methods.
1732 virtual const TypeAryPtr* remove_speculative() const;
1733 virtual const TypePtr* with_inline_depth(int depth) const;
1734 virtual const TypePtr* with_instance_id(int instance_id) const;
1735
1736 // the core of the computation of the meet of 2 types
1737 virtual const Type *xmeet_helper(const Type *t) const;
1738 virtual const Type *xdual() const; // Compute dual right now.
1739
1740 const TypeAryPtr* cast_to_stable(bool stable, int stable_dimension = 1) const;
1741 int stable_dimension() const;
1742
1743 const TypeAryPtr* cast_to_autobox_cache() const;
1744
1745 static jint max_array_length(BasicType etype) ;
1746 virtual const TypeKlassPtr* as_klass_type(bool try_for_exact = false) const;
1747
1748 // Convenience common pre-built types.
1749 static const TypeAryPtr* BOTTOM;
1750 static const TypeAryPtr* RANGE;
1751 static const TypeAryPtr* OOPS;
1752 static const TypeAryPtr* NARROWOOPS;
1753 static const TypeAryPtr* BYTES;
1754 static const TypeAryPtr* SHORTS;
1755 static const TypeAryPtr* CHARS;
1756 static const TypeAryPtr* INTS;
1757 static const TypeAryPtr* LONGS;
1758 static const TypeAryPtr* FLOATS;
1759 static const TypeAryPtr* DOUBLES;
1760 // selects one of the above:
1761 static const TypeAryPtr *get_array_body_type(BasicType elem) {
1762 assert((uint)elem <= T_CONFLICT && _array_body_type[elem] != nullptr, "bad elem type");
1763 return _array_body_type[elem];
1764 }
1765 static const TypeAryPtr *_array_body_type[T_CONFLICT+1];
1766 // sharpen the type of an int which is used as an array size
1767 #ifndef PRODUCT
1768 virtual void dump2( Dict &d, uint depth, outputStream *st ) const; // Specialized per-Type dumping
1769 #endif
1770 private:
1771 virtual bool is_meet_subtype_of_helper(const TypeOopPtr* other, bool this_xk, bool other_xk) const;
1772 };
1773
1774 //------------------------------TypeMetadataPtr-------------------------------------
1775 // Some kind of metadata, either Method*, MethodData* or CPCacheOop
1776 class TypeMetadataPtr : public TypePtr {
1777 protected:
1778 TypeMetadataPtr(PTR ptr, ciMetadata* metadata, int offset);
1779 // Do not allow interface-vs.-noninterface joins to collapse to top.
1780 virtual const Type *filter_helper(const Type *kills, bool include_speculative) const;
1781 public:
1782 virtual bool eq( const Type *t ) const;
1783 virtual uint hash() const; // Type specific hashing
1784 virtual bool singleton(void) const; // TRUE if type is a singleton
1785
1786 private:
1787 ciMetadata* _metadata;
1788
1789 public:
1790 static const TypeMetadataPtr* make(PTR ptr, ciMetadata* m, int offset);
1791
1792 static const TypeMetadataPtr* make(ciMethod* m);
1793 static const TypeMetadataPtr* make(ciMethodData* m);
1794
1795 ciMetadata* metadata() const { return _metadata; }
1796
1797 virtual const TypeMetadataPtr* cast_to_ptr_type(PTR ptr) const;
1798
1799 virtual const TypePtr *add_offset( intptr_t offset ) const;
1800
1801 virtual const Type *xmeet( const Type *t ) const;
1802 virtual const Type *xdual() const; // Compute dual right now.
1803
1804 virtual intptr_t get_con() const;
1805
1806 // Convenience common pre-built types.
1807 static const TypeMetadataPtr *BOTTOM;
1808
1809 #ifndef PRODUCT
1810 virtual void dump2( Dict &d, uint depth, outputStream *st ) const;
1811 #endif
1812 };
1813
1814 //------------------------------TypeKlassPtr-----------------------------------
1815 // Class of Java Klass pointers
1816 class TypeKlassPtr : public TypePtr {
1817 friend class TypeInstKlassPtr;
1818 friend class TypeAryKlassPtr;
1819 friend class TypePtr;
1820 protected:
1821 TypeKlassPtr(TYPES t, PTR ptr, ciKlass* klass, const TypeInterfaces* interfaces, int offset);
1822
1823 virtual const Type *filter_helper(const Type *kills, bool include_speculative) const;
1824
1825 public:
1826 virtual bool eq( const Type *t ) const;
1827 virtual uint hash() const;
1828 virtual bool singleton(void) const; // TRUE if type is a singleton
1829
1830 protected:
1831
1832 ciKlass* _klass;
1833 const TypeInterfaces* _interfaces;
1834 const TypeInterfaces* meet_interfaces(const TypeKlassPtr* other) const;
1835 virtual bool must_be_exact() const { ShouldNotReachHere(); return false; }
1836 virtual ciKlass* exact_klass_helper() const;
1837 virtual ciKlass* klass() const { return _klass; }
1838
1839 public:
1840
1841 bool is_java_subtype_of(const TypeKlassPtr* other) const {
1842 return is_java_subtype_of_helper(other, klass_is_exact(), other->klass_is_exact());
1843 }
1844 bool is_same_java_type_as(const TypePtr* other) const {
1845 return is_same_java_type_as_helper(other->is_klassptr());
1846 }
1847
1848 bool maybe_java_subtype_of(const TypeKlassPtr* other) const {
1849 return maybe_java_subtype_of_helper(other, klass_is_exact(), other->klass_is_exact());
1850 }
1851 virtual bool is_same_java_type_as_helper(const TypeKlassPtr* other) const { ShouldNotReachHere(); return false; }
1852 virtual bool is_java_subtype_of_helper(const TypeKlassPtr* other, bool this_exact, bool other_exact) const { ShouldNotReachHere(); return false; }
1853 virtual bool maybe_java_subtype_of_helper(const TypeKlassPtr* other, bool this_exact, bool other_exact) const { ShouldNotReachHere(); return false; }
1854
1855 // Exact klass, possibly an interface or an array of interface
1856 ciKlass* exact_klass(bool maybe_null = false) const { assert(klass_is_exact(), ""); ciKlass* k = exact_klass_helper(); assert(k != nullptr || maybe_null, ""); return k; }
1857 virtual bool klass_is_exact() const { return _ptr == Constant; }
1858
1859 static const TypeKlassPtr* make(ciKlass* klass, InterfaceHandling interface_handling = ignore_interfaces);
1860 static const TypeKlassPtr *make(PTR ptr, ciKlass* klass, int offset, InterfaceHandling interface_handling = ignore_interfaces);
1861
1862 virtual bool is_loaded() const { return _klass->is_loaded(); }
1863
1864 virtual const TypeKlassPtr* cast_to_ptr_type(PTR ptr) const { ShouldNotReachHere(); return nullptr; }
1865
1866 virtual const TypeKlassPtr *cast_to_exactness(bool klass_is_exact) const { ShouldNotReachHere(); return nullptr; }
1867
1868 // corresponding pointer to instance, for a given class
1869 virtual const TypeOopPtr* as_instance_type(bool klass_change = true) const { ShouldNotReachHere(); return nullptr; }
1870
1871 virtual const TypePtr *add_offset( intptr_t offset ) const { ShouldNotReachHere(); return nullptr; }
1872 virtual const Type *xmeet( const Type *t ) const { ShouldNotReachHere(); return nullptr; }
1873 virtual const Type *xdual() const { ShouldNotReachHere(); return nullptr; }
1874
1875 virtual intptr_t get_con() const;
1876
1877 virtual const TypeKlassPtr* with_offset(intptr_t offset) const { ShouldNotReachHere(); return nullptr; }
1878
1879 virtual const TypeKlassPtr* try_improve() const { return this; }
1880
1881 private:
1882 virtual bool is_meet_subtype_of(const TypePtr* other) const {
1883 return is_meet_subtype_of_helper(other->is_klassptr(), klass_is_exact(), other->is_klassptr()->klass_is_exact());
1884 }
1885
1886 virtual bool is_meet_subtype_of_helper(const TypeKlassPtr* other, bool this_xk, bool other_xk) const {
1887 ShouldNotReachHere(); return false;
1888 }
1889
1890 virtual const TypeInterfaces* interfaces() const {
1891 return _interfaces;
1892 };
1893
1894 const TypeKlassPtr* is_reference_type(const Type* other) const {
1895 return other->isa_klassptr();
1896 }
1897
1898 const TypeAryKlassPtr* is_array_type(const TypeKlassPtr* other) const {
1899 return other->isa_aryklassptr();
1900 }
1901
1902 const TypeInstKlassPtr* is_instance_type(const TypeKlassPtr* other) const {
1903 return other->isa_instklassptr();
1904 }
1905 };
1906
1907 // Instance klass pointer, mirrors TypeInstPtr
1908 class TypeInstKlassPtr : public TypeKlassPtr {
1909
1910 TypeInstKlassPtr(PTR ptr, ciKlass* klass, const TypeInterfaces* interfaces, int offset)
1911 : TypeKlassPtr(InstKlassPtr, ptr, klass, interfaces, offset) {
1912 assert(klass->is_instance_klass() && (!klass->is_loaded() || !klass->is_interface()), "");
1913 }
1914
1915 virtual bool must_be_exact() const;
1916
1917 public:
1918 // Instance klass ignoring any interface
1919 ciInstanceKlass* instance_klass() const {
1920 assert(!klass()->is_interface(), "");
1921 return klass()->as_instance_klass();
1922 }
1923
1924 bool might_be_an_array() const;
1925
1926 bool is_same_java_type_as_helper(const TypeKlassPtr* other) const;
1927 bool is_java_subtype_of_helper(const TypeKlassPtr* other, bool this_exact, bool other_exact) const;
1928 bool maybe_java_subtype_of_helper(const TypeKlassPtr* other, bool this_exact, bool other_exact) const;
1929
1930 static const TypeInstKlassPtr *make(ciKlass* k, InterfaceHandling interface_handling) {
1931 const TypeInterfaces* interfaces = TypePtr::interfaces(k, true, true, false, interface_handling);
1932 return make(TypePtr::Constant, k, interfaces, 0);
1933 }
1934 static const TypeInstKlassPtr* make(PTR ptr, ciKlass* k, const TypeInterfaces* interfaces, int offset);
1935
1936 static const TypeInstKlassPtr* make(PTR ptr, ciKlass* k, int offset) {
1937 const TypeInterfaces* interfaces = TypePtr::interfaces(k, true, false, false, ignore_interfaces);
1938 return make(ptr, k, interfaces, offset);
1939 }
1940
1941 virtual const TypeInstKlassPtr* cast_to_ptr_type(PTR ptr) const;
1942
1943 virtual const TypeKlassPtr *cast_to_exactness(bool klass_is_exact) const;
1944
1945 // corresponding pointer to instance, for a given class
1946 virtual const TypeOopPtr* as_instance_type(bool klass_change = true) const;
1947 virtual uint hash() const;
1948 virtual bool eq(const Type *t) const;
1949
1950 virtual const TypePtr *add_offset( intptr_t offset ) const;
1951 virtual const Type *xmeet( const Type *t ) const;
1952 virtual const Type *xdual() const;
1953 virtual const TypeInstKlassPtr* with_offset(intptr_t offset) const;
1954
1955 virtual const TypeKlassPtr* try_improve() const;
1956
1957 // Convenience common pre-built types.
1958 static const TypeInstKlassPtr* OBJECT; // Not-null object klass or below
1959 static const TypeInstKlassPtr* OBJECT_OR_NULL; // Maybe-null version of same
1960
1961 #ifndef PRODUCT
1962 virtual void dump2(Dict& d, uint depth, outputStream* st) const;
1963 #endif // PRODUCT
1964
1965 private:
1966 virtual bool is_meet_subtype_of_helper(const TypeKlassPtr* other, bool this_xk, bool other_xk) const;
1967 };
1968
1969 // Array klass pointer, mirrors TypeAryPtr
1970 class TypeAryKlassPtr : public TypeKlassPtr {
1971 friend class TypeInstKlassPtr;
1972 friend class Type;
1973 friend class TypePtr;
1974
1975 const Type *_elem;
1976
1977 static const TypeInterfaces* _array_interfaces;
1978 TypeAryKlassPtr(PTR ptr, const Type *elem, ciKlass* klass, int offset)
1979 : TypeKlassPtr(AryKlassPtr, ptr, klass, _array_interfaces, offset), _elem(elem) {
1980 assert(klass == nullptr || klass->is_type_array_klass() || !klass->as_obj_array_klass()->base_element_klass()->is_interface(), "");
1981 }
1982
1983 virtual ciKlass* exact_klass_helper() const;
1984 // Only guaranteed non null for array of basic types
1985 virtual ciKlass* klass() const;
1986
1987 virtual bool must_be_exact() const;
1988
1989 public:
1990
1991 // returns base element type, an instance klass (and not interface) for object arrays
1992 const Type* base_element_type(int& dims) const;
1993
1994 static const TypeAryKlassPtr *make(PTR ptr, ciKlass* k, int offset, InterfaceHandling interface_handling);
1995
1996 bool is_same_java_type_as_helper(const TypeKlassPtr* other) const;
1997 bool is_java_subtype_of_helper(const TypeKlassPtr* other, bool this_exact, bool other_exact) const;
1998 bool maybe_java_subtype_of_helper(const TypeKlassPtr* other, bool this_exact, bool other_exact) const;
1999
2000 bool is_loaded() const { return (_elem->isa_klassptr() ? _elem->is_klassptr()->is_loaded() : true); }
2001
2002 static const TypeAryKlassPtr *make(PTR ptr, const Type *elem, ciKlass* k, int offset);
2003 static const TypeAryKlassPtr* make(ciKlass* klass, InterfaceHandling interface_handling);
2004
2005 const Type *elem() const { return _elem; }
2006
2007 virtual bool eq(const Type *t) const;
2008 virtual uint hash() const; // Type specific hashing
2009
2010 virtual const TypeAryKlassPtr* cast_to_ptr_type(PTR ptr) const;
2011
2012 virtual const TypeKlassPtr *cast_to_exactness(bool klass_is_exact) const;
2013
2014 // corresponding pointer to instance, for a given class
2015 virtual const TypeOopPtr* as_instance_type(bool klass_change = true) const;
2016
2017 virtual const TypePtr *add_offset( intptr_t offset ) const;
2018 virtual const Type *xmeet( const Type *t ) const;
2019 virtual const Type *xdual() const; // Compute dual right now.
2020
2021 virtual const TypeAryKlassPtr* with_offset(intptr_t offset) const;
2022
2023 virtual bool empty(void) const {
2024 return TypeKlassPtr::empty() || _elem->empty();
2025 }
2026
2027 #ifndef PRODUCT
2028 virtual void dump2( Dict &d, uint depth, outputStream *st ) const; // Specialized per-Type dumping
2029 #endif
2030 private:
2031 virtual bool is_meet_subtype_of_helper(const TypeKlassPtr* other, bool this_xk, bool other_xk) const;
2032 };
2033
2034 class TypeNarrowPtr : public Type {
2035 protected:
2036 const TypePtr* _ptrtype; // Could be TypePtr::NULL_PTR
2037
2038 TypeNarrowPtr(TYPES t, const TypePtr* ptrtype): Type(t),
2039 _ptrtype(ptrtype) {
2040 assert(ptrtype->offset() == 0 ||
2041 ptrtype->offset() == OffsetBot ||
2042 ptrtype->offset() == OffsetTop, "no real offsets");
2043 }
2044
2045 virtual const TypeNarrowPtr *isa_same_narrowptr(const Type *t) const = 0;
2046 virtual const TypeNarrowPtr *is_same_narrowptr(const Type *t) const = 0;
2047 virtual const TypeNarrowPtr *make_same_narrowptr(const TypePtr *t) const = 0;
2048 virtual const TypeNarrowPtr *make_hash_same_narrowptr(const TypePtr *t) const = 0;
2049 // Do not allow interface-vs.-noninterface joins to collapse to top.
2050 virtual const Type *filter_helper(const Type *kills, bool include_speculative) const;
2051 public:
2052 virtual bool eq( const Type *t ) const;
2053 virtual uint hash() const; // Type specific hashing
2054 virtual bool singleton(void) const; // TRUE if type is a singleton
2055
2056 virtual const Type *xmeet( const Type *t ) const;
2057 virtual const Type *xdual() const; // Compute dual right now.
2058
2059 virtual intptr_t get_con() const;
2060
2061 virtual bool empty(void) const; // TRUE if type is vacuous
2062
2063 // returns the equivalent ptr type for this compressed pointer
2064 const TypePtr *get_ptrtype() const {
2065 return _ptrtype;
2066 }
2067
2068 bool is_known_instance() const {
2069 return _ptrtype->is_known_instance();
2070 }
2071
2072 #ifndef PRODUCT
2073 virtual void dump2( Dict &d, uint depth, outputStream *st ) const;
2074 #endif
2075 };
2076
2077 //------------------------------TypeNarrowOop----------------------------------
2078 // A compressed reference to some kind of Oop. This type wraps around
2079 // a preexisting TypeOopPtr and forwards most of it's operations to
2080 // the underlying type. It's only real purpose is to track the
2081 // oopness of the compressed oop value when we expose the conversion
2082 // between the normal and the compressed form.
2083 class TypeNarrowOop : public TypeNarrowPtr {
2084 protected:
2085 TypeNarrowOop( const TypePtr* ptrtype): TypeNarrowPtr(NarrowOop, ptrtype) {
2086 }
2087
2088 virtual const TypeNarrowPtr *isa_same_narrowptr(const Type *t) const {
2089 return t->isa_narrowoop();
2090 }
2091
2092 virtual const TypeNarrowPtr *is_same_narrowptr(const Type *t) const {
2093 return t->is_narrowoop();
2094 }
2095
2096 virtual const TypeNarrowPtr *make_same_narrowptr(const TypePtr *t) const {
2097 return new TypeNarrowOop(t);
2098 }
2099
2100 virtual const TypeNarrowPtr *make_hash_same_narrowptr(const TypePtr *t) const {
2101 return (const TypeNarrowPtr*)((new TypeNarrowOop(t))->hashcons());
2102 }
2103
2104 public:
2105
2106 static const TypeNarrowOop *make( const TypePtr* type);
2107
2108 static const TypeNarrowOop* make_from_constant(ciObject* con, bool require_constant = false) {
2109 return make(TypeOopPtr::make_from_constant(con, require_constant));
2110 }
2111
2112 static const TypeNarrowOop *BOTTOM;
2113 static const TypeNarrowOop *NULL_PTR;
2114
2115 virtual const TypeNarrowOop* remove_speculative() const;
2116 virtual const Type* cleanup_speculative() const;
2117
2118 #ifndef PRODUCT
2119 virtual void dump2( Dict &d, uint depth, outputStream *st ) const;
2120 #endif
2121 };
2122
2123 //------------------------------TypeNarrowKlass----------------------------------
2124 // A compressed reference to klass pointer. This type wraps around a
2125 // preexisting TypeKlassPtr and forwards most of it's operations to
2126 // the underlying type.
2127 class TypeNarrowKlass : public TypeNarrowPtr {
2128 protected:
2129 TypeNarrowKlass( const TypePtr* ptrtype): TypeNarrowPtr(NarrowKlass, ptrtype) {
2130 }
2131
2132 virtual const TypeNarrowPtr *isa_same_narrowptr(const Type *t) const {
2133 return t->isa_narrowklass();
2134 }
2135
2136 virtual const TypeNarrowPtr *is_same_narrowptr(const Type *t) const {
2137 return t->is_narrowklass();
2138 }
2139
2140 virtual const TypeNarrowPtr *make_same_narrowptr(const TypePtr *t) const {
2141 return new TypeNarrowKlass(t);
2142 }
2143
2144 virtual const TypeNarrowPtr *make_hash_same_narrowptr(const TypePtr *t) const {
2145 return (const TypeNarrowPtr*)((new TypeNarrowKlass(t))->hashcons());
2146 }
2147
2148 public:
2149 static const TypeNarrowKlass *make( const TypePtr* type);
2150
2151 // static const TypeNarrowKlass *BOTTOM;
2152 static const TypeNarrowKlass *NULL_PTR;
2153
2154 #ifndef PRODUCT
2155 virtual void dump2( Dict &d, uint depth, outputStream *st ) const;
2156 #endif
2157 };
2158
2159 //------------------------------TypeFunc---------------------------------------
2160 // Class of Array Types
2161 class TypeFunc : public Type {
2162 TypeFunc( const TypeTuple *domain, const TypeTuple *range ) : Type(Function), _domain(domain), _range(range) {}
2163 virtual bool eq( const Type *t ) const;
2164 virtual uint hash() const; // Type specific hashing
2165 virtual bool singleton(void) const; // TRUE if type is a singleton
2166 virtual bool empty(void) const; // TRUE if type is vacuous
2167
2168 const TypeTuple* const _domain; // Domain of inputs
2169 const TypeTuple* const _range; // Range of results
2170
2171 public:
2172 // Constants are shared among ADLC and VM
2173 enum { Control = AdlcVMDeps::Control,
2174 I_O = AdlcVMDeps::I_O,
2175 Memory = AdlcVMDeps::Memory,
2176 FramePtr = AdlcVMDeps::FramePtr,
2177 ReturnAdr = AdlcVMDeps::ReturnAdr,
2178 Parms = AdlcVMDeps::Parms
2179 };
2180
2181
2182 // Accessors:
2183 const TypeTuple* domain() const { return _domain; }
2184 const TypeTuple* range() const { return _range; }
2185
2186 static const TypeFunc *make(ciMethod* method);
2187 static const TypeFunc *make(ciSignature signature, const Type* extra);
2188 static const TypeFunc *make(const TypeTuple* domain, const TypeTuple* range);
2189
2190 virtual const Type *xmeet( const Type *t ) const;
2191 virtual const Type *xdual() const; // Compute dual right now.
2192
2193 BasicType return_type() const;
2194
2195 #ifndef PRODUCT
2196 virtual void dump2( Dict &d, uint depth, outputStream *st ) const; // Specialized per-Type dumping
2197 #endif
2198 // Convenience common pre-built types.
2199 };
2200
2201 //------------------------------accessors--------------------------------------
2202 inline bool Type::is_ptr_to_narrowoop() const {
2203 #ifdef _LP64
2204 return (isa_oopptr() != nullptr && is_oopptr()->is_ptr_to_narrowoop_nv());
2205 #else
2206 return false;
2207 #endif
2208 }
2209
2210 inline bool Type::is_ptr_to_narrowklass() const {
2211 #ifdef _LP64
2212 return (isa_oopptr() != nullptr && is_oopptr()->is_ptr_to_narrowklass_nv());
2213 #else
2214 return false;
2215 #endif
2216 }
2217
2218 inline float Type::getf() const {
2219 assert( _base == FloatCon, "Not a FloatCon" );
2220 return ((TypeF*)this)->_f;
2221 }
2222
2223 inline short Type::geth() const {
2224 assert(_base == HalfFloatCon, "Not a HalfFloatCon");
2225 return ((TypeH*)this)->_f;
2226 }
2227
2228 inline double Type::getd() const {
2229 assert( _base == DoubleCon, "Not a DoubleCon" );
2230 return ((TypeD*)this)->_d;
2231 }
2232
2233 inline const TypeInteger *Type::is_integer(BasicType bt) const {
2234 assert((bt == T_INT && _base == Int) || (bt == T_LONG && _base == Long), "Not an Int");
2235 return (TypeInteger*)this;
2236 }
2237
2238 inline const TypeInteger *Type::isa_integer(BasicType bt) const {
2239 return (((bt == T_INT && _base == Int) || (bt == T_LONG && _base == Long)) ? (TypeInteger*)this : nullptr);
2240 }
2241
2242 inline const TypeInt *Type::is_int() const {
2243 assert( _base == Int, "Not an Int" );
2244 return (TypeInt*)this;
2245 }
2246
2247 inline const TypeInt *Type::isa_int() const {
2248 return ( _base == Int ? (TypeInt*)this : nullptr);
2249 }
2250
2251 inline const TypeLong *Type::is_long() const {
2252 assert( _base == Long, "Not a Long" );
2253 return (TypeLong*)this;
2254 }
2255
2256 inline const TypeLong *Type::isa_long() const {
2257 return ( _base == Long ? (TypeLong*)this : nullptr);
2258 }
2259
2260 inline const TypeH* Type::isa_half_float() const {
2261 return ((_base == HalfFloatTop ||
2262 _base == HalfFloatCon ||
2263 _base == HalfFloatBot) ? (TypeH*)this : nullptr);
2264 }
2265
2266 inline const TypeH* Type::is_half_float_constant() const {
2267 assert( _base == HalfFloatCon, "Not a HalfFloat" );
2268 return (TypeH*)this;
2269 }
2270
2271 inline const TypeH* Type::isa_half_float_constant() const {
2272 return (_base == HalfFloatCon ? (TypeH*)this : nullptr);
2273 }
2274
2275 inline const TypeF *Type::isa_float() const {
2276 return ((_base == FloatTop ||
2277 _base == FloatCon ||
2278 _base == FloatBot) ? (TypeF*)this : nullptr);
2279 }
2280
2281 inline const TypeF *Type::is_float_constant() const {
2282 assert( _base == FloatCon, "Not a Float" );
2283 return (TypeF*)this;
2284 }
2285
2286 inline const TypeF *Type::isa_float_constant() const {
2287 return ( _base == FloatCon ? (TypeF*)this : nullptr);
2288 }
2289
2290 inline const TypeD *Type::isa_double() const {
2291 return ((_base == DoubleTop ||
2292 _base == DoubleCon ||
2293 _base == DoubleBot) ? (TypeD*)this : nullptr);
2294 }
2295
2296 inline const TypeD *Type::is_double_constant() const {
2297 assert( _base == DoubleCon, "Not a Double" );
2298 return (TypeD*)this;
2299 }
2300
2301 inline const TypeD *Type::isa_double_constant() const {
2302 return ( _base == DoubleCon ? (TypeD*)this : nullptr);
2303 }
2304
2305 inline const TypeTuple *Type::is_tuple() const {
2306 assert( _base == Tuple, "Not a Tuple" );
2307 return (TypeTuple*)this;
2308 }
2309
2310 inline const TypeAry *Type::is_ary() const {
2311 assert( _base == Array , "Not an Array" );
2312 return (TypeAry*)this;
2313 }
2314
2315 inline const TypeAry *Type::isa_ary() const {
2316 return ((_base == Array) ? (TypeAry*)this : nullptr);
2317 }
2318
2319 inline const TypeVectMask *Type::is_vectmask() const {
2320 assert( _base == VectorMask, "Not a Vector Mask" );
2321 return (TypeVectMask*)this;
2322 }
2323
2324 inline const TypeVectMask *Type::isa_vectmask() const {
2325 return (_base == VectorMask) ? (TypeVectMask*)this : nullptr;
2326 }
2327
2328 inline const TypeVect *Type::is_vect() const {
2329 assert( _base >= VectorMask && _base <= VectorZ, "Not a Vector" );
2330 return (TypeVect*)this;
2331 }
2332
2333 inline const TypeVect *Type::isa_vect() const {
2334 return (_base >= VectorMask && _base <= VectorZ) ? (TypeVect*)this : nullptr;
2335 }
2336
2337 inline const TypePtr *Type::is_ptr() const {
2338 // AnyPtr is the first Ptr and KlassPtr the last, with no non-ptrs between.
2339 assert(_base >= AnyPtr && _base <= AryKlassPtr, "Not a pointer");
2340 return (TypePtr*)this;
2341 }
2342
2343 inline const TypePtr *Type::isa_ptr() const {
2344 // AnyPtr is the first Ptr and KlassPtr the last, with no non-ptrs between.
2345 return (_base >= AnyPtr && _base <= AryKlassPtr) ? (TypePtr*)this : nullptr;
2346 }
2347
2348 inline const TypeOopPtr *Type::is_oopptr() const {
2349 // OopPtr is the first and KlassPtr the last, with no non-oops between.
2350 assert(_base >= OopPtr && _base <= AryPtr, "Not a Java pointer" ) ;
2351 return (TypeOopPtr*)this;
2352 }
2353
2354 inline const TypeOopPtr *Type::isa_oopptr() const {
2355 // OopPtr is the first and KlassPtr the last, with no non-oops between.
2356 return (_base >= OopPtr && _base <= AryPtr) ? (TypeOopPtr*)this : nullptr;
2357 }
2358
2359 inline const TypeRawPtr *Type::isa_rawptr() const {
2360 return (_base == RawPtr) ? (TypeRawPtr*)this : nullptr;
2361 }
2362
2363 inline const TypeRawPtr *Type::is_rawptr() const {
2364 assert( _base == RawPtr, "Not a raw pointer" );
2365 return (TypeRawPtr*)this;
2366 }
2367
2368 inline const TypeInstPtr *Type::isa_instptr() const {
2369 return (_base == InstPtr) ? (TypeInstPtr*)this : nullptr;
2370 }
2371
2372 inline const TypeInstPtr *Type::is_instptr() const {
2373 assert( _base == InstPtr, "Not an object pointer" );
2374 return (TypeInstPtr*)this;
2375 }
2376
2377 inline const TypeAryPtr *Type::isa_aryptr() const {
2378 return (_base == AryPtr) ? (TypeAryPtr*)this : nullptr;
2379 }
2380
2381 inline const TypeAryPtr *Type::is_aryptr() const {
2382 assert( _base == AryPtr, "Not an array pointer" );
2383 return (TypeAryPtr*)this;
2384 }
2385
2386 inline const TypeNarrowOop *Type::is_narrowoop() const {
2387 // OopPtr is the first and KlassPtr the last, with no non-oops between.
2388 assert(_base == NarrowOop, "Not a narrow oop" ) ;
2389 return (TypeNarrowOop*)this;
2390 }
2391
2392 inline const TypeNarrowOop *Type::isa_narrowoop() const {
2393 // OopPtr is the first and KlassPtr the last, with no non-oops between.
2394 return (_base == NarrowOop) ? (TypeNarrowOop*)this : nullptr;
2395 }
2396
2397 inline const TypeNarrowKlass *Type::is_narrowklass() const {
2398 assert(_base == NarrowKlass, "Not a narrow oop" ) ;
2399 return (TypeNarrowKlass*)this;
2400 }
2401
2402 inline const TypeNarrowKlass *Type::isa_narrowklass() const {
2403 return (_base == NarrowKlass) ? (TypeNarrowKlass*)this : nullptr;
2404 }
2405
2406 inline const TypeMetadataPtr *Type::is_metadataptr() const {
2407 // MetadataPtr is the first and CPCachePtr the last
2408 assert(_base == MetadataPtr, "Not a metadata pointer" ) ;
2409 return (TypeMetadataPtr*)this;
2410 }
2411
2412 inline const TypeMetadataPtr *Type::isa_metadataptr() const {
2413 return (_base == MetadataPtr) ? (TypeMetadataPtr*)this : nullptr;
2414 }
2415
2416 inline const TypeKlassPtr *Type::isa_klassptr() const {
2417 return (_base >= KlassPtr && _base <= AryKlassPtr ) ? (TypeKlassPtr*)this : nullptr;
2418 }
2419
2420 inline const TypeKlassPtr *Type::is_klassptr() const {
2421 assert(_base >= KlassPtr && _base <= AryKlassPtr, "Not a klass pointer");
2422 return (TypeKlassPtr*)this;
2423 }
2424
2425 inline const TypeInstKlassPtr *Type::isa_instklassptr() const {
2426 return (_base == InstKlassPtr) ? (TypeInstKlassPtr*)this : nullptr;
2427 }
2428
2429 inline const TypeInstKlassPtr *Type::is_instklassptr() const {
2430 assert(_base == InstKlassPtr, "Not a klass pointer");
2431 return (TypeInstKlassPtr*)this;
2432 }
2433
2434 inline const TypeAryKlassPtr *Type::isa_aryklassptr() const {
2435 return (_base == AryKlassPtr) ? (TypeAryKlassPtr*)this : nullptr;
2436 }
2437
2438 inline const TypeAryKlassPtr *Type::is_aryklassptr() const {
2439 assert(_base == AryKlassPtr, "Not a klass pointer");
2440 return (TypeAryKlassPtr*)this;
2441 }
2442
2443 inline const TypePtr* Type::make_ptr() const {
2444 return (_base == NarrowOop) ? is_narrowoop()->get_ptrtype() :
2445 ((_base == NarrowKlass) ? is_narrowklass()->get_ptrtype() :
2446 isa_ptr());
2447 }
2448
2449 inline const TypeOopPtr* Type::make_oopptr() const {
2450 return (_base == NarrowOop) ? is_narrowoop()->get_ptrtype()->isa_oopptr() : isa_oopptr();
2451 }
2452
2453 inline const TypeNarrowOop* Type::make_narrowoop() const {
2454 return (_base == NarrowOop) ? is_narrowoop() :
2455 (isa_ptr() ? TypeNarrowOop::make(is_ptr()) : nullptr);
2456 }
2457
2458 inline const TypeNarrowKlass* Type::make_narrowklass() const {
2459 return (_base == NarrowKlass) ? is_narrowklass() :
2460 (isa_ptr() ? TypeNarrowKlass::make(is_ptr()) : nullptr);
2461 }
2462
2463 inline bool Type::is_floatingpoint() const {
2464 if( (_base == HalfFloatCon) || (_base == HalfFloatBot) ||
2465 (_base == FloatCon) || (_base == FloatBot) ||
2466 (_base == DoubleCon) || (_base == DoubleBot) )
2467 return true;
2468 return false;
2469 }
2470
2471 template <>
2472 inline const TypeInt* Type::cast<TypeInt>() const {
2473 return is_int();
2474 }
2475
2476 template <>
2477 inline const TypeLong* Type::cast<TypeLong>() const {
2478 return is_long();
2479 }
2480
2481 template <>
2482 inline const TypeInt* Type::try_cast<TypeInt>() const {
2483 return isa_int();
2484 }
2485
2486 template <>
2487 inline const TypeLong* Type::try_cast<TypeLong>() const {
2488 return isa_long();
2489 }
2490
2491 // ===============================================================
2492 // Things that need to be 64-bits in the 64-bit build but
2493 // 32-bits in the 32-bit build. Done this way to get full
2494 // optimization AND strong typing.
2495 #ifdef _LP64
2496
2497 // For type queries and asserts
2498 #define is_intptr_t is_long
2499 #define isa_intptr_t isa_long
2500 #define find_intptr_t_type find_long_type
2501 #define find_intptr_t_con find_long_con
2502 #define TypeX TypeLong
2503 #define Type_X Type::Long
2504 #define TypeX_X TypeLong::LONG
2505 #define TypeX_ZERO TypeLong::ZERO
2506 // For 'ideal_reg' machine registers
2507 #define Op_RegX Op_RegL
2508 // For phase->intcon variants
2509 #define MakeConX longcon
2510 #define ConXNode ConLNode
2511 // For array index arithmetic
2512 #define MulXNode MulLNode
2513 #define AndXNode AndLNode
2514 #define OrXNode OrLNode
2515 #define CmpXNode CmpLNode
2516 #define SubXNode SubLNode
2517 #define LShiftXNode LShiftLNode
2518 // For object size computation:
2519 #define AddXNode AddLNode
2520 #define RShiftXNode RShiftLNode
2521 // For card marks and hashcodes
2522 #define URShiftXNode URShiftLNode
2523 // For shenandoahSupport
2524 #define LoadXNode LoadLNode
2525 #define StoreXNode StoreLNode
2526 // Opcodes
2527 #define Op_LShiftX Op_LShiftL
2528 #define Op_AndX Op_AndL
2529 #define Op_AddX Op_AddL
2530 #define Op_SubX Op_SubL
2531 #define Op_XorX Op_XorL
2532 #define Op_URShiftX Op_URShiftL
2533 #define Op_LoadX Op_LoadL
2534 // conversions
2535 #define ConvI2X(x) ConvI2L(x)
2536 #define ConvL2X(x) (x)
2537 #define ConvX2I(x) ConvL2I(x)
2538 #define ConvX2L(x) (x)
2539 #define ConvX2UL(x) (x)
2540
2541 #else
2542
2543 // For type queries and asserts
2544 #define is_intptr_t is_int
2545 #define isa_intptr_t isa_int
2546 #define find_intptr_t_type find_int_type
2547 #define find_intptr_t_con find_int_con
2548 #define TypeX TypeInt
2549 #define Type_X Type::Int
2550 #define TypeX_X TypeInt::INT
2551 #define TypeX_ZERO TypeInt::ZERO
2552 // For 'ideal_reg' machine registers
2553 #define Op_RegX Op_RegI
2554 // For phase->intcon variants
2555 #define MakeConX intcon
2556 #define ConXNode ConINode
2557 // For array index arithmetic
2558 #define MulXNode MulINode
2559 #define AndXNode AndINode
2560 #define OrXNode OrINode
2561 #define CmpXNode CmpINode
2562 #define SubXNode SubINode
2563 #define LShiftXNode LShiftINode
2564 // For object size computation:
2565 #define AddXNode AddINode
2566 #define RShiftXNode RShiftINode
2567 // For card marks and hashcodes
2568 #define URShiftXNode URShiftINode
2569 // For shenandoahSupport
2570 #define LoadXNode LoadINode
2571 #define StoreXNode StoreINode
2572 // Opcodes
2573 #define Op_LShiftX Op_LShiftI
2574 #define Op_AndX Op_AndI
2575 #define Op_AddX Op_AddI
2576 #define Op_SubX Op_SubI
2577 #define Op_XorX Op_XorI
2578 #define Op_URShiftX Op_URShiftI
2579 #define Op_LoadX Op_LoadI
2580 // conversions
2581 #define ConvI2X(x) (x)
2582 #define ConvL2X(x) ConvL2I(x)
2583 #define ConvX2I(x) (x)
2584 #define ConvX2L(x) ConvI2L(x)
2585 #define ConvX2UL(x) ConvI2UL(x)
2586
2587 #endif
2588
2589 #endif // SHARE_OPTO_TYPE_HPP