1 /*
2 * Copyright (c) 1997, 2025, 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
813 // Check for single integer
814 bool is_con() const { return _lo == _hi; }
815 bool is_con(jint i) const { return is_con() && _lo == i; }
816 jint get_con() const { assert(is_con(), ""); return _lo; }
817 // Check if a jint/TypeInt is a subset of this TypeInt (i.e. all elements of the
818 // argument are also elements of this type)
819 bool contains(jint i) const;
820 bool contains(const TypeInt* t) const;
821
822 virtual bool is_finite() const; // Has a finite value
823
824 virtual const Type* xmeet(const Type* t) const;
825 virtual const Type* xdual() const; // Compute dual right now.
826 virtual const Type* widen(const Type* t, const Type* limit_type) const;
827 virtual const Type* narrow(const Type* t) const;
828
829 virtual jlong hi_as_long() const { return _hi; }
830 virtual jlong lo_as_long() const { return _lo; }
831
832 // Do not kill _widen bits.
833 // Convenience common pre-built types.
834 static const TypeInt* MAX;
835 static const TypeInt* MIN;
836 static const TypeInt* MINUS_1;
837 static const TypeInt* ZERO;
838 static const TypeInt* ONE;
839 static const TypeInt* BOOL;
840 static const TypeInt* CC;
841 static const TypeInt* CC_LT; // [-1] == MINUS_1
842 static const TypeInt* CC_GT; // [1] == ONE
843 static const TypeInt* CC_EQ; // [0] == ZERO
844 static const TypeInt* CC_NE; // [-1, 1]
845 static const TypeInt* CC_LE; // [-1,0]
846 static const TypeInt* CC_GE; // [0,1] == BOOL (!)
847 static const TypeInt* BYTE;
848 static const TypeInt* UBYTE;
849 static const TypeInt* CHAR;
850 static const TypeInt* SHORT;
851 static const TypeInt* NON_ZERO;
852 static const TypeInt* POS;
853 static const TypeInt* POS1;
854 static const TypeInt* INT;
855 static const TypeInt* SYMINT; // symmetric range [-max_jint..max_jint]
856 static const TypeInt* TYPE_DOMAIN; // alias for TypeInt::INT
857
858 static const TypeInt* as_self(const Type* t) { return t->is_int(); }
859 #ifndef PRODUCT
860 virtual void dump2(Dict& d, uint depth, outputStream* st) const;
861 void dump_verbose() const;
862 #endif
863 };
864
865 // Similar to TypeInt
866 class TypeLong : public TypeInteger {
867 private:
868 TypeLong(const TypeIntPrototype<jlong, julong>& t, int w, bool dual);
869 static const Type* make_or_top(const TypeIntPrototype<jlong, julong>& t, int widen, bool dual);
870
871 friend class TypeIntHelper;
872
873 protected:
874 // Do not kill _widen bits.
875 virtual const Type* filter_helper(const Type* kills, bool include_speculative) const;
876 public:
877 typedef jlong NativeType;
878 virtual bool eq( const Type *t ) const;
879 virtual uint hash() const; // Type specific hashing
880 virtual bool singleton(void) const; // TRUE if type is a singleton
881 virtual bool empty(void) const; // TRUE if type is vacuous
882 public:
883 // A value is in the set represented by this TypeLong if it satisfies all
884 // the below constraints, see contains(jlong)
885 const jlong _lo, _hi; // Lower bound, upper bound in the signed domain
886 const julong _ulo, _uhi; // Lower bound, upper bound in the unsigned domain
887 const KnownBits<julong> _bits;
888
889 static const TypeLong* make(jlong con);
890 // must always specify w
891 static const TypeLong* make(jlong lo, jlong hi, int widen);
892 static const Type* make_or_top(const TypeIntPrototype<jlong, julong>& t, int widen);
893
894 // Check for single integer
895 bool is_con() const { return _lo == _hi; }
896 bool is_con(jlong i) const { return is_con() && _lo == i; }
897 jlong get_con() const { assert(is_con(), "" ); return _lo; }
898 // Check if a jlong/TypeLong is a subset of this TypeLong (i.e. all elements of the
899 // argument are also elements of this type)
900 bool contains(jlong i) const;
901 bool contains(const TypeLong* t) const;
902
903 // Check for positive 32-bit value.
904 int is_positive_int() const { return _lo >= 0 && _hi <= (jlong)max_jint; }
905
906 virtual bool is_finite() const; // Has a finite value
907
908 virtual jlong hi_as_long() const { return _hi; }
909 virtual jlong lo_as_long() const { return _lo; }
910
911 virtual const Type* xmeet(const Type* t) const;
912 virtual const Type* xdual() const; // Compute dual right now.
913 virtual const Type* widen(const Type* t, const Type* limit_type) const;
914 virtual const Type* narrow(const Type* t) const;
915 // Convenience common pre-built types.
916 static const TypeLong* MAX;
917 static const TypeLong* MIN;
918 static const TypeLong* MINUS_1;
919 static const TypeLong* ZERO;
920 static const TypeLong* ONE;
921 static const TypeLong* NON_ZERO;
922 static const TypeLong* POS;
923 static const TypeLong* NEG;
924 static const TypeLong* LONG;
925 static const TypeLong* INT; // 32-bit subrange [min_jint..max_jint]
926 static const TypeLong* UINT; // 32-bit unsigned [0..max_juint]
927 static const TypeLong* TYPE_DOMAIN; // alias for TypeLong::LONG
928
929 // static convenience methods.
930 static const TypeLong* as_self(const Type* t) { return t->is_long(); }
931
932 #ifndef PRODUCT
933 virtual void dump2(Dict& d, uint, outputStream* st) const;// Specialized per-Type dumping
934 void dump_verbose() const;
935 #endif
936 };
937
938 //------------------------------TypeTuple--------------------------------------
939 // Class of Tuple Types, essentially type collections for function signatures
940 // and class layouts. It happens to also be a fast cache for the HotSpot
941 // signature types.
942 class TypeTuple : public Type {
943 TypeTuple( uint cnt, const Type **fields ) : Type(Tuple), _cnt(cnt), _fields(fields) { }
944
945 const uint _cnt; // Count of fields
946 const Type ** const _fields; // Array of field types
947
948 public:
949 virtual bool eq( const Type *t ) const;
950 virtual uint hash() const; // Type specific hashing
951 virtual bool singleton(void) const; // TRUE if type is a singleton
952 virtual bool empty(void) const; // TRUE if type is vacuous
953
954 // Accessors:
955 uint cnt() const { return _cnt; }
956 const Type* field_at(uint i) const {
957 assert(i < _cnt, "oob");
958 return _fields[i];
959 }
960 void set_field_at(uint i, const Type* t) {
961 assert(i < _cnt, "oob");
962 _fields[i] = t;
963 }
964
965 static const TypeTuple *make( uint cnt, const Type **fields );
966 static const TypeTuple *make_range(ciSignature *sig, InterfaceHandling interface_handling = ignore_interfaces);
967 static const TypeTuple *make_domain(ciInstanceKlass* recv, ciSignature *sig, InterfaceHandling interface_handling);
968
969 // Subroutine call type with space allocated for argument types
970 // Memory for Control, I_O, Memory, FramePtr, and ReturnAdr is allocated implicitly
971 static const Type **fields( uint arg_cnt );
972
973 virtual const Type *xmeet( const Type *t ) const;
974 virtual const Type *xdual() const; // Compute dual right now.
975 // Convenience common pre-built types.
976 static const TypeTuple *IFBOTH;
977 static const TypeTuple *IFFALSE;
978 static const TypeTuple *IFTRUE;
979 static const TypeTuple *IFNEITHER;
980 static const TypeTuple *LOOPBODY;
981 static const TypeTuple *MEMBAR;
982 static const TypeTuple *STORECONDITIONAL;
983 static const TypeTuple *START_I2C;
984 static const TypeTuple *INT_PAIR;
985 static const TypeTuple *LONG_PAIR;
986 static const TypeTuple *INT_CC_PAIR;
987 static const TypeTuple *LONG_CC_PAIR;
988 #ifndef PRODUCT
989 virtual void dump2( Dict &d, uint, outputStream *st ) const; // Specialized per-Type dumping
990 #endif
991 };
992
993 //------------------------------TypeAry----------------------------------------
994 // Class of Array Types
995 class TypeAry : public Type {
996 TypeAry(const Type* elem, const TypeInt* size, bool stable) : Type(Array),
997 _elem(elem), _size(size), _stable(stable) {}
998 public:
999 virtual bool eq( const Type *t ) const;
1000 virtual uint hash() const; // Type specific hashing
1001 virtual bool singleton(void) const; // TRUE if type is a singleton
1002 virtual bool empty(void) const; // TRUE if type is vacuous
1003
1004 private:
1005 const Type *_elem; // Element type of array
1006 const TypeInt *_size; // Elements in array
1007 const bool _stable; // Are elements @Stable?
1008 friend class TypeAryPtr;
1009
1010 public:
1011 static const TypeAry* make(const Type* elem, const TypeInt* size, bool stable = false);
1012
1013 virtual const Type *xmeet( const Type *t ) const;
1014 virtual const Type *xdual() const; // Compute dual right now.
1015 bool ary_must_be_exact() const; // true if arrays of such are never generic
1016 virtual const TypeAry* remove_speculative() const;
1017 virtual const Type* cleanup_speculative() const;
1018 #ifndef PRODUCT
1019 virtual void dump2( Dict &d, uint, outputStream *st ) const; // Specialized per-Type dumping
1020 #endif
1021 };
1022
1023 //------------------------------TypeVect---------------------------------------
1024 // Class of Vector Types
1025 class TypeVect : public Type {
1026 const BasicType _elem_bt; // Vector's element type
1027 const uint _length; // Elements in vector (power of 2)
1028
1029 protected:
1030 TypeVect(TYPES t, BasicType elem_bt, uint length) : Type(t),
1031 _elem_bt(elem_bt), _length(length) {}
1032
1033 public:
1034 BasicType element_basic_type() const { return _elem_bt; }
1035 uint length() const { return _length; }
1036 uint length_in_bytes() const {
1037 return _length * type2aelembytes(element_basic_type());
1038 }
1039
1040 virtual bool eq(const Type* t) const;
1041 virtual uint hash() const; // Type specific hashing
1042 virtual bool singleton(void) const; // TRUE if type is a singleton
1043 virtual bool empty(void) const; // TRUE if type is vacuous
1044
1045 static const TypeVect* make(const BasicType elem_bt, uint length, bool is_mask = false);
1046 static const TypeVect* makemask(const BasicType elem_bt, uint length);
1047
1048 virtual const Type* xmeet( const Type *t) const;
1049 virtual const Type* xdual() const; // Compute dual right now.
1050
1051 static const TypeVect* VECTA;
1052 static const TypeVect* VECTS;
1053 static const TypeVect* VECTD;
1054 static const TypeVect* VECTX;
1055 static const TypeVect* VECTY;
1056 static const TypeVect* VECTZ;
1057 static const TypeVect* VECTMASK;
1058
1059 #ifndef PRODUCT
1060 virtual void dump2(Dict& d, uint, outputStream* st) const; // Specialized per-Type dumping
1061 #endif
1062 };
1063
1064 class TypeVectA : public TypeVect {
1065 friend class TypeVect;
1066 TypeVectA(BasicType elem_bt, uint length) : TypeVect(VectorA, elem_bt, length) {}
1067 };
1068
1069 class TypeVectS : public TypeVect {
1070 friend class TypeVect;
1071 TypeVectS(BasicType elem_bt, uint length) : TypeVect(VectorS, elem_bt, length) {}
1072 };
1073
1074 class TypeVectD : public TypeVect {
1075 friend class TypeVect;
1076 TypeVectD(BasicType elem_bt, uint length) : TypeVect(VectorD, elem_bt, length) {}
1077 };
1078
1079 class TypeVectX : public TypeVect {
1080 friend class TypeVect;
1081 TypeVectX(BasicType elem_bt, uint length) : TypeVect(VectorX, elem_bt, length) {}
1082 };
1083
1084 class TypeVectY : public TypeVect {
1085 friend class TypeVect;
1086 TypeVectY(BasicType elem_bt, uint length) : TypeVect(VectorY, elem_bt, length) {}
1087 };
1088
1089 class TypeVectZ : public TypeVect {
1090 friend class TypeVect;
1091 TypeVectZ(BasicType elem_bt, uint length) : TypeVect(VectorZ, elem_bt, length) {}
1092 };
1093
1094 class TypeVectMask : public TypeVect {
1095 public:
1096 friend class TypeVect;
1097 TypeVectMask(BasicType elem_bt, uint length) : TypeVect(VectorMask, elem_bt, length) {}
1098 static const TypeVectMask* make(const BasicType elem_bt, uint length);
1099 };
1100
1101 // Set of implemented interfaces. Referenced from TypeOopPtr and TypeKlassPtr.
1102 class TypeInterfaces : public Type {
1103 private:
1104 GrowableArrayFromArray<ciInstanceKlass*> _interfaces;
1105 uint _hash;
1106 ciInstanceKlass* _exact_klass;
1107 DEBUG_ONLY(bool _initialized;)
1108
1109 void initialize();
1110
1111 void verify() const NOT_DEBUG_RETURN;
1112 void compute_hash();
1113 void compute_exact_klass();
1114
1115 TypeInterfaces(ciInstanceKlass** interfaces_base, int nb_interfaces);
1116
1117 NONCOPYABLE(TypeInterfaces);
1118 public:
1119 static const TypeInterfaces* make(GrowableArray<ciInstanceKlass*>* interfaces = nullptr);
1120 bool eq(const Type* other) const;
1121 bool eq(ciInstanceKlass* k) const;
1122 uint hash() const;
1123 const Type *xdual() const;
1124 void dump(outputStream* st) const;
1125 const TypeInterfaces* union_with(const TypeInterfaces* other) const;
1126 const TypeInterfaces* intersection_with(const TypeInterfaces* other) const;
1127 bool contains(const TypeInterfaces* other) const {
1128 return intersection_with(other)->eq(other);
1129 }
1130 bool empty() const { return _interfaces.length() == 0; }
1131
1132 ciInstanceKlass* exact_klass() const;
1133 void verify_is_loaded() const NOT_DEBUG_RETURN;
1134
1135 static int compare(ciInstanceKlass* const& k1, ciInstanceKlass* const& k2);
1136 static int compare(ciInstanceKlass** k1, ciInstanceKlass** k2);
1137
1138 const Type* xmeet(const Type* t) const;
1139
1140 bool singleton(void) const;
1141 bool has_non_array_interface() const;
1142 };
1143
1144 //------------------------------TypePtr----------------------------------------
1145 // Class of machine Pointer Types: raw data, instances or arrays.
1146 // If the _base enum is AnyPtr, then this refers to all of the above.
1147 // Otherwise the _base will indicate which subset of pointers is affected,
1148 // and the class will be inherited from.
1149 class TypePtr : public Type {
1150 friend class TypeNarrowPtr;
1151 friend class Type;
1152 protected:
1153 static const TypeInterfaces* interfaces(ciKlass*& k, bool klass, bool interface, bool array, InterfaceHandling interface_handling);
1154
1155 public:
1156 enum PTR { TopPTR, AnyNull, Constant, Null, NotNull, BotPTR, lastPTR };
1157 protected:
1158 TypePtr(TYPES t, PTR ptr, int offset,
1159 const TypePtr* speculative = nullptr,
1160 int inline_depth = InlineDepthBottom) :
1161 Type(t), _speculative(speculative), _inline_depth(inline_depth), _offset(offset),
1162 _ptr(ptr) {}
1163 static const PTR ptr_meet[lastPTR][lastPTR];
1164 static const PTR ptr_dual[lastPTR];
1165 static const char * const ptr_msg[lastPTR];
1166
1167 enum {
1168 InlineDepthBottom = INT_MAX,
1169 InlineDepthTop = -InlineDepthBottom
1170 };
1171
1172 // Extra type information profiling gave us. We propagate it the
1173 // same way the rest of the type info is propagated. If we want to
1174 // use it, then we have to emit a guard: this part of the type is
1175 // not something we know but something we speculate about the type.
1176 const TypePtr* _speculative;
1177 // For speculative types, we record at what inlining depth the
1178 // profiling point that provided the data is. We want to favor
1179 // profile data coming from outer scopes which are likely better for
1180 // the current compilation.
1181 int _inline_depth;
1182
1183 // utility methods to work on the speculative part of the type
1184 const TypePtr* dual_speculative() const;
1185 const TypePtr* xmeet_speculative(const TypePtr* other) const;
1186 bool eq_speculative(const TypePtr* other) const;
1187 int hash_speculative() const;
1188 const TypePtr* add_offset_speculative(intptr_t offset) const;
1189 const TypePtr* with_offset_speculative(intptr_t offset) const;
1190
1191 // utility methods to work on the inline depth of the type
1192 int dual_inline_depth() const;
1193 int meet_inline_depth(int depth) const;
1194
1195 #ifndef PRODUCT
1196 void dump_speculative(outputStream* st) const;
1197 void dump_inline_depth(outputStream* st) const;
1198 void dump_offset(outputStream* st) const;
1199 #endif
1200
1201 // TypeInstPtr (TypeAryPtr resp.) and TypeInstKlassPtr (TypeAryKlassPtr resp.) implement very similar meet logic.
1202 // The logic for meeting 2 instances (2 arrays resp.) is shared in the 2 utility methods below. However the logic for
1203 // the oop and klass versions can be slightly different and extra logic may have to be executed depending on what
1204 // exact case the meet falls into. The MeetResult struct is used by the utility methods to communicate what case was
1205 // encountered so the right logic specific to klasses or oops can be executed.,
1206 enum MeetResult {
1207 QUICK,
1208 UNLOADED,
1209 SUBTYPE,
1210 NOT_SUBTYPE,
1211 LCA
1212 };
1213 template<class T> static TypePtr::MeetResult meet_instptr(PTR& ptr, const TypeInterfaces*& interfaces, const T* this_type,
1214 const T* other_type, ciKlass*& res_klass, bool& res_xk);
1215
1216 template<class T> static MeetResult meet_aryptr(PTR& ptr, const Type*& elem, const T* this_ary, const T* other_ary,
1217 ciKlass*& res_klass, bool& res_xk);
1218
1219 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);
1220 template <class T1, class T2> static bool is_same_java_type_as_helper_for_instance(const T1* this_one, const T2* other);
1221 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);
1222 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);
1223 template <class T1, class T2> static bool is_same_java_type_as_helper_for_array(const T1* this_one, const T2* other);
1224 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);
1225 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);
1226 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);
1227 public:
1228 const int _offset; // Offset into oop, with TOP & BOT
1229 const PTR _ptr; // Pointer equivalence class
1230
1231 int offset() const { return _offset; }
1232 PTR ptr() const { return _ptr; }
1233
1234 static const TypePtr *make(TYPES t, PTR ptr, int offset,
1235 const TypePtr* speculative = nullptr,
1236 int inline_depth = InlineDepthBottom);
1237
1238 // Return a 'ptr' version of this type
1239 virtual const TypePtr* cast_to_ptr_type(PTR ptr) const;
1240
1241 virtual intptr_t get_con() const;
1242
1243 int xadd_offset( intptr_t offset ) const;
1244 virtual const TypePtr* add_offset(intptr_t offset) const;
1245 virtual const TypePtr* with_offset(intptr_t offset) const;
1246 virtual bool eq(const Type *t) const;
1247 virtual uint hash() const; // Type specific hashing
1248
1249 virtual bool singleton(void) const; // TRUE if type is a singleton
1250 virtual bool empty(void) const; // TRUE if type is vacuous
1251 virtual const Type *xmeet( const Type *t ) const;
1252 virtual const Type *xmeet_helper( const Type *t ) const;
1253 int meet_offset( int offset ) const;
1254 int dual_offset( ) const;
1255 virtual const Type *xdual() const; // Compute dual right now.
1256
1257 // meet, dual and join over pointer equivalence sets
1258 PTR meet_ptr( const PTR in_ptr ) const { return ptr_meet[in_ptr][ptr()]; }
1259 PTR dual_ptr() const { return ptr_dual[ptr()]; }
1260
1261 // This is textually confusing unless one recalls that
1262 // join(t) == dual()->meet(t->dual())->dual().
1263 PTR join_ptr( const PTR in_ptr ) const {
1264 return ptr_dual[ ptr_meet[ ptr_dual[in_ptr] ] [ dual_ptr() ] ];
1265 }
1266
1267 // Speculative type helper methods.
1268 virtual const TypePtr* speculative() const { return _speculative; }
1269 int inline_depth() const { return _inline_depth; }
1270 virtual ciKlass* speculative_type() const;
1271 virtual ciKlass* speculative_type_not_null() const;
1272 virtual bool speculative_maybe_null() const;
1273 virtual bool speculative_always_null() const;
1274 virtual const TypePtr* remove_speculative() const;
1275 virtual const Type* cleanup_speculative() const;
1276 virtual bool would_improve_type(ciKlass* exact_kls, int inline_depth) const;
1277 virtual bool would_improve_ptr(ProfilePtrKind maybe_null) const;
1278 virtual const TypePtr* with_inline_depth(int depth) const;
1279
1280 virtual bool maybe_null() const { return meet_ptr(Null) == ptr(); }
1281
1282 // Tests for relation to centerline of type lattice:
1283 static bool above_centerline(PTR ptr) { return (ptr <= AnyNull); }
1284 static bool below_centerline(PTR ptr) { return (ptr >= NotNull); }
1285 // Convenience common pre-built types.
1286 static const TypePtr *NULL_PTR;
1287 static const TypePtr *NOTNULL;
1288 static const TypePtr *BOTTOM;
1289 #ifndef PRODUCT
1290 virtual void dump2( Dict &d, uint depth, outputStream *st ) const;
1291 #endif
1292 };
1293
1294 //------------------------------TypeRawPtr-------------------------------------
1295 // Class of raw pointers, pointers to things other than Oops. Examples
1296 // include the stack pointer, top of heap, card-marking area, handles, etc.
1297 class TypeRawPtr : public TypePtr {
1298 protected:
1299 TypeRawPtr( PTR ptr, address bits ) : TypePtr(RawPtr,ptr,0), _bits(bits){}
1300 public:
1301 virtual bool eq( const Type *t ) const;
1302 virtual uint hash() const; // Type specific hashing
1303
1304 const address _bits; // Constant value, if applicable
1305
1306 static const TypeRawPtr *make( PTR ptr );
1307 static const TypeRawPtr *make( address bits );
1308
1309 // Return a 'ptr' version of this type
1310 virtual const TypeRawPtr* cast_to_ptr_type(PTR ptr) const;
1311
1312 virtual intptr_t get_con() const;
1313
1314 virtual const TypePtr* add_offset(intptr_t offset) const;
1315 virtual const TypeRawPtr* with_offset(intptr_t offset) const { ShouldNotReachHere(); return nullptr;}
1316
1317 virtual const Type *xmeet( const Type *t ) const;
1318 virtual const Type *xdual() const; // Compute dual right now.
1319 // Convenience common pre-built types.
1320 static const TypeRawPtr *BOTTOM;
1321 static const TypeRawPtr *NOTNULL;
1322 #ifndef PRODUCT
1323 virtual void dump2( Dict &d, uint depth, outputStream *st ) const;
1324 #endif
1325 };
1326
1327 //------------------------------TypeOopPtr-------------------------------------
1328 // Some kind of oop (Java pointer), either instance or array.
1329 class TypeOopPtr : public TypePtr {
1330 friend class TypeAry;
1331 friend class TypePtr;
1332 friend class TypeInstPtr;
1333 friend class TypeAryPtr;
1334 protected:
1335 TypeOopPtr(TYPES t, PTR ptr, ciKlass* k, const TypeInterfaces* interfaces, bool xk, ciObject* o, int offset, int instance_id,
1336 const TypePtr* speculative, int inline_depth);
1337 public:
1338 virtual bool eq( const Type *t ) const;
1339 virtual uint hash() const; // Type specific hashing
1340 virtual bool singleton(void) const; // TRUE if type is a singleton
1341 enum {
1342 InstanceTop = -1, // undefined instance
1343 InstanceBot = 0 // any possible instance
1344 };
1345 protected:
1346
1347 // Oop is null, unless this is a constant oop.
1348 ciObject* _const_oop; // Constant oop
1349 // If _klass is null, then so is _sig. This is an unloaded klass.
1350 ciKlass* _klass; // Klass object
1351
1352 const TypeInterfaces* _interfaces;
1353
1354 // Does the type exclude subclasses of the klass? (Inexact == polymorphic.)
1355 bool _klass_is_exact;
1356 bool _is_ptr_to_narrowoop;
1357 bool _is_ptr_to_narrowklass;
1358 bool _is_ptr_to_boxed_value;
1359
1360 // If not InstanceTop or InstanceBot, indicates that this is
1361 // a particular instance of this type which is distinct.
1362 // This is the node index of the allocation node creating this instance.
1363 int _instance_id;
1364
1365 static const TypeOopPtr* make_from_klass_common(ciKlass* klass, bool klass_change, bool try_for_exact, InterfaceHandling interface_handling);
1366
1367 int dual_instance_id() const;
1368 int meet_instance_id(int uid) const;
1369
1370 const TypeInterfaces* meet_interfaces(const TypeOopPtr* other) const;
1371
1372 // Do not allow interface-vs.-noninterface joins to collapse to top.
1373 virtual const Type *filter_helper(const Type *kills, bool include_speculative) const;
1374
1375 virtual ciKlass* exact_klass_helper() const { return nullptr; }
1376 virtual ciKlass* klass() const { return _klass; }
1377
1378 #ifndef PRODUCT
1379 void dump_instance_id(outputStream* st) const;
1380 #endif // PRODUCT
1381
1382 public:
1383
1384 bool is_java_subtype_of(const TypeOopPtr* other) const {
1385 return is_java_subtype_of_helper(other, klass_is_exact(), other->klass_is_exact());
1386 }
1387
1388 bool is_same_java_type_as(const TypePtr* other) const {
1389 return is_same_java_type_as_helper(other->is_oopptr());
1390 }
1391
1392 virtual bool is_same_java_type_as_helper(const TypeOopPtr* other) const {
1393 ShouldNotReachHere(); return false;
1394 }
1395
1396 bool maybe_java_subtype_of(const TypeOopPtr* other) const {
1397 return maybe_java_subtype_of_helper(other, klass_is_exact(), other->klass_is_exact());
1398 }
1399 virtual bool is_java_subtype_of_helper(const TypeOopPtr* other, bool this_exact, bool other_exact) const { ShouldNotReachHere(); return false; }
1400 virtual bool maybe_java_subtype_of_helper(const TypeOopPtr* other, bool this_exact, bool other_exact) const { ShouldNotReachHere(); return false; }
1401
1402
1403 // Creates a type given a klass. Correctly handles multi-dimensional arrays
1404 // Respects UseUniqueSubclasses.
1405 // If the klass is final, the resulting type will be exact.
1406 static const TypeOopPtr* make_from_klass(ciKlass* klass, InterfaceHandling interface_handling = ignore_interfaces) {
1407 return make_from_klass_common(klass, true, false, interface_handling);
1408 }
1409 // Same as before, but will produce an exact type, even if
1410 // the klass is not final, as long as it has exactly one implementation.
1411 static const TypeOopPtr* make_from_klass_unique(ciKlass* klass, InterfaceHandling interface_handling= ignore_interfaces) {
1412 return make_from_klass_common(klass, true, true, interface_handling);
1413 }
1414 // Same as before, but does not respects UseUniqueSubclasses.
1415 // Use this only for creating array element types.
1416 static const TypeOopPtr* make_from_klass_raw(ciKlass* klass, InterfaceHandling interface_handling = ignore_interfaces) {
1417 return make_from_klass_common(klass, false, false, interface_handling);
1418 }
1419 // Creates a singleton type given an object.
1420 // If the object cannot be rendered as a constant,
1421 // may return a non-singleton type.
1422 // If require_constant, produce a null if a singleton is not possible.
1423 static const TypeOopPtr* make_from_constant(ciObject* o,
1424 bool require_constant = false);
1425
1426 // Make a generic (unclassed) pointer to an oop.
1427 static const TypeOopPtr* make(PTR ptr, int offset, int instance_id,
1428 const TypePtr* speculative = nullptr,
1429 int inline_depth = InlineDepthBottom);
1430
1431 ciObject* const_oop() const { return _const_oop; }
1432 // Exact klass, possibly an interface or an array of interface
1433 ciKlass* exact_klass(bool maybe_null = false) const { assert(klass_is_exact(), ""); ciKlass* k = exact_klass_helper(); assert(k != nullptr || maybe_null, ""); return k; }
1434 ciKlass* unloaded_klass() const { assert(!is_loaded(), "only for unloaded types"); return klass(); }
1435
1436 virtual bool is_loaded() const { return klass()->is_loaded(); }
1437 virtual bool klass_is_exact() const { return _klass_is_exact; }
1438
1439 // Returns true if this pointer points at memory which contains a
1440 // compressed oop references.
1441 bool is_ptr_to_narrowoop_nv() const { return _is_ptr_to_narrowoop; }
1442 bool is_ptr_to_narrowklass_nv() const { return _is_ptr_to_narrowklass; }
1443 bool is_ptr_to_boxed_value() const { return _is_ptr_to_boxed_value; }
1444 bool is_known_instance() const { return _instance_id > 0; }
1445 int instance_id() const { return _instance_id; }
1446 bool is_known_instance_field() const { return is_known_instance() && _offset >= 0; }
1447
1448 virtual intptr_t get_con() const;
1449
1450 virtual const TypeOopPtr* cast_to_ptr_type(PTR ptr) const;
1451
1452 virtual const TypeOopPtr* cast_to_exactness(bool klass_is_exact) const;
1453
1454 virtual const TypeOopPtr *cast_to_instance_id(int instance_id) const;
1455
1456 // corresponding pointer to klass, for a given instance
1457 virtual const TypeKlassPtr* as_klass_type(bool try_for_exact = false) const;
1458
1459 virtual const TypeOopPtr* with_offset(intptr_t offset) const;
1460 virtual const TypePtr* add_offset(intptr_t offset) const;
1461
1462 // Speculative type helper methods.
1463 virtual const TypeOopPtr* remove_speculative() const;
1464 virtual const Type* cleanup_speculative() const;
1465 virtual bool would_improve_type(ciKlass* exact_kls, int inline_depth) const;
1466 virtual const TypePtr* with_inline_depth(int depth) const;
1467
1468 virtual const TypePtr* with_instance_id(int instance_id) const;
1469
1470 virtual const Type *xdual() const; // Compute dual right now.
1471 // the core of the computation of the meet for TypeOopPtr and for its subclasses
1472 virtual const Type *xmeet_helper(const Type *t) const;
1473
1474 // Convenience common pre-built type.
1475 static const TypeOopPtr *BOTTOM;
1476 #ifndef PRODUCT
1477 virtual void dump2( Dict &d, uint depth, outputStream *st ) const;
1478 #endif
1479 private:
1480 virtual bool is_meet_subtype_of(const TypePtr* other) const {
1481 return is_meet_subtype_of_helper(other->is_oopptr(), klass_is_exact(), other->is_oopptr()->klass_is_exact());
1482 }
1483
1484 virtual bool is_meet_subtype_of_helper(const TypeOopPtr* other, bool this_xk, bool other_xk) const {
1485 ShouldNotReachHere(); return false;
1486 }
1487
1488 virtual const TypeInterfaces* interfaces() const {
1489 return _interfaces;
1490 };
1491
1492 const TypeOopPtr* is_reference_type(const Type* other) const {
1493 return other->isa_oopptr();
1494 }
1495
1496 const TypeAryPtr* is_array_type(const TypeOopPtr* other) const {
1497 return other->isa_aryptr();
1498 }
1499
1500 const TypeInstPtr* is_instance_type(const TypeOopPtr* other) const {
1501 return other->isa_instptr();
1502 }
1503 };
1504
1505 //------------------------------TypeInstPtr------------------------------------
1506 // Class of Java object pointers, pointing either to non-array Java instances
1507 // or to a Klass* (including array klasses).
1508 class TypeInstPtr : public TypeOopPtr {
1509 TypeInstPtr(PTR ptr, ciKlass* k, const TypeInterfaces* interfaces, bool xk, ciObject* o, int off, int instance_id,
1510 const TypePtr* speculative, int inline_depth);
1511 virtual bool eq( const Type *t ) const;
1512 virtual uint hash() const; // Type specific hashing
1513
1514 ciKlass* exact_klass_helper() const;
1515
1516 public:
1517
1518 // Instance klass, ignoring any interface
1519 ciInstanceKlass* instance_klass() const {
1520 assert(!(klass()->is_loaded() && klass()->is_interface()), "");
1521 return klass()->as_instance_klass();
1522 }
1523
1524 bool is_same_java_type_as_helper(const TypeOopPtr* other) const;
1525 bool is_java_subtype_of_helper(const TypeOopPtr* other, bool this_exact, bool other_exact) const;
1526 bool maybe_java_subtype_of_helper(const TypeOopPtr* other, bool this_exact, bool other_exact) const;
1527
1528 // Make a pointer to a constant oop.
1529 static const TypeInstPtr *make(ciObject* o) {
1530 ciKlass* k = o->klass();
1531 const TypeInterfaces* interfaces = TypePtr::interfaces(k, true, false, false, ignore_interfaces);
1532 return make(TypePtr::Constant, k, interfaces, true, o, 0, InstanceBot);
1533 }
1534 // Make a pointer to a constant oop with offset.
1535 static const TypeInstPtr *make(ciObject* o, int offset) {
1536 ciKlass* k = o->klass();
1537 const TypeInterfaces* interfaces = TypePtr::interfaces(k, true, false, false, ignore_interfaces);
1538 return make(TypePtr::Constant, k, interfaces, true, o, offset, InstanceBot);
1539 }
1540
1541 // Make a pointer to some value of type klass.
1542 static const TypeInstPtr *make(PTR ptr, ciKlass* klass, InterfaceHandling interface_handling = ignore_interfaces) {
1543 const TypeInterfaces* interfaces = TypePtr::interfaces(klass, true, true, false, interface_handling);
1544 return make(ptr, klass, interfaces, false, nullptr, 0, InstanceBot);
1545 }
1546
1547 // Make a pointer to some non-polymorphic value of exactly type klass.
1548 static const TypeInstPtr *make_exact(PTR ptr, ciKlass* klass) {
1549 const TypeInterfaces* interfaces = TypePtr::interfaces(klass, true, false, false, ignore_interfaces);
1550 return make(ptr, klass, interfaces, true, nullptr, 0, InstanceBot);
1551 }
1552
1553 // Make a pointer to some value of type klass with offset.
1554 static const TypeInstPtr *make(PTR ptr, ciKlass* klass, int offset) {
1555 const TypeInterfaces* interfaces = TypePtr::interfaces(klass, true, false, false, ignore_interfaces);
1556 return make(ptr, klass, interfaces, false, nullptr, offset, InstanceBot);
1557 }
1558
1559 static const TypeInstPtr *make(PTR ptr, ciKlass* k, const TypeInterfaces* interfaces, bool xk, ciObject* o, int offset,
1560 int instance_id = InstanceBot,
1561 const TypePtr* speculative = nullptr,
1562 int inline_depth = InlineDepthBottom);
1563
1564 static const TypeInstPtr *make(PTR ptr, ciKlass* k, bool xk, ciObject* o, int offset, int instance_id = InstanceBot) {
1565 const TypeInterfaces* interfaces = TypePtr::interfaces(k, true, false, false, ignore_interfaces);
1566 return make(ptr, k, interfaces, xk, o, offset, instance_id);
1567 }
1568
1569 /** Create constant type for a constant boxed value */
1570 const Type* get_const_boxed_value() const;
1571
1572 // If this is a java.lang.Class constant, return the type for it or null.
1573 // Pass to Type::get_const_type to turn it to a type, which will usually
1574 // be a TypeInstPtr, but may also be a TypeInt::INT for int.class, etc.
1575 ciType* java_mirror_type() const;
1576
1577 virtual const TypeInstPtr* cast_to_ptr_type(PTR ptr) const;
1578
1579 virtual const TypeInstPtr* cast_to_exactness(bool klass_is_exact) const;
1580
1581 virtual const TypeInstPtr* cast_to_instance_id(int instance_id) const;
1582
1583 virtual const TypePtr* add_offset(intptr_t offset) const;
1584 virtual const TypeInstPtr* with_offset(intptr_t offset) const;
1585
1586 // Speculative type helper methods.
1587 virtual const TypeInstPtr* remove_speculative() const;
1588 const TypeInstPtr* with_speculative(const TypePtr* speculative) const;
1589 virtual const TypePtr* with_inline_depth(int depth) const;
1590 virtual const TypePtr* with_instance_id(int instance_id) const;
1591
1592 // the core of the computation of the meet of 2 types
1593 virtual const Type *xmeet_helper(const Type *t) const;
1594 virtual const TypeInstPtr *xmeet_unloaded(const TypeInstPtr *tinst, const TypeInterfaces* interfaces) const;
1595 virtual const Type *xdual() const; // Compute dual right now.
1596
1597 const TypeKlassPtr* as_klass_type(bool try_for_exact = false) const;
1598
1599 // Convenience common pre-built types.
1600 static const TypeInstPtr *NOTNULL;
1601 static const TypeInstPtr *BOTTOM;
1602 static const TypeInstPtr *MIRROR;
1603 static const TypeInstPtr *MARK;
1604 static const TypeInstPtr *KLASS;
1605 #ifndef PRODUCT
1606 virtual void dump2( Dict &d, uint depth, outputStream *st ) const; // Specialized per-Type dumping
1607 #endif
1608
1609 private:
1610 virtual bool is_meet_subtype_of_helper(const TypeOopPtr* other, bool this_xk, bool other_xk) const;
1611
1612 virtual bool is_meet_same_type_as(const TypePtr* other) const {
1613 return _klass->equals(other->is_instptr()->_klass) && _interfaces->eq(other->is_instptr()->_interfaces);
1614 }
1615
1616 };
1617
1618 //------------------------------TypeAryPtr-------------------------------------
1619 // Class of Java array pointers
1620 class TypeAryPtr : public TypeOopPtr {
1621 friend class Type;
1622 friend class TypePtr;
1623 friend class TypeInterfaces;
1624
1625 TypeAryPtr( PTR ptr, ciObject* o, const TypeAry *ary, ciKlass* k, bool xk,
1626 int offset, int instance_id, bool is_autobox_cache,
1627 const TypePtr* speculative, int inline_depth)
1628 : TypeOopPtr(AryPtr,ptr,k,_array_interfaces,xk,o,offset, instance_id, speculative, inline_depth),
1629 _ary(ary),
1630 _is_autobox_cache(is_autobox_cache)
1631 {
1632 int dummy;
1633 bool top_or_bottom = (base_element_type(dummy) == Type::TOP || base_element_type(dummy) == Type::BOTTOM);
1634
1635 if (UseCompressedOops && (elem()->make_oopptr() != nullptr && !top_or_bottom) &&
1636 _offset != 0 && _offset != arrayOopDesc::length_offset_in_bytes() &&
1637 _offset != Type::klass_offset()) {
1638 _is_ptr_to_narrowoop = true;
1639 }
1640
1641 }
1642 virtual bool eq( const Type *t ) const;
1643 virtual uint hash() const; // Type specific hashing
1644 const TypeAry *_ary; // Array we point into
1645 const bool _is_autobox_cache;
1646
1647 ciKlass* compute_klass() const;
1648
1649 // A pointer to delay allocation to Type::Initialize_shared()
1650
1651 static const TypeInterfaces* _array_interfaces;
1652 ciKlass* exact_klass_helper() const;
1653 // Only guaranteed non null for array of basic types
1654 ciKlass* klass() const;
1655
1656 public:
1657
1658 bool is_same_java_type_as_helper(const TypeOopPtr* other) const;
1659 bool is_java_subtype_of_helper(const TypeOopPtr* other, bool this_exact, bool other_exact) const;
1660 bool maybe_java_subtype_of_helper(const TypeOopPtr* other, bool this_exact, bool other_exact) const;
1661
1662 // returns base element type, an instance klass (and not interface) for object arrays
1663 const Type* base_element_type(int& dims) const;
1664
1665 // Accessors
1666 bool is_loaded() const { return (_ary->_elem->make_oopptr() ? _ary->_elem->make_oopptr()->is_loaded() : true); }
1667
1668 const TypeAry* ary() const { return _ary; }
1669 const Type* elem() const { return _ary->_elem; }
1670 const TypeInt* size() const { return _ary->_size; }
1671 bool is_stable() const { return _ary->_stable; }
1672
1673 bool is_autobox_cache() const { return _is_autobox_cache; }
1674
1675 static const TypeAryPtr *make(PTR ptr, const TypeAry *ary, ciKlass* k, bool xk, int offset,
1676 int instance_id = InstanceBot,
1677 const TypePtr* speculative = nullptr,
1678 int inline_depth = InlineDepthBottom);
1679 // Constant pointer to array
1680 static const TypeAryPtr *make(PTR ptr, ciObject* o, const TypeAry *ary, ciKlass* k, bool xk, int offset,
1681 int instance_id = InstanceBot,
1682 const TypePtr* speculative = nullptr,
1683 int inline_depth = InlineDepthBottom, bool is_autobox_cache = false);
1684
1685 // Return a 'ptr' version of this type
1686 virtual const TypeAryPtr* cast_to_ptr_type(PTR ptr) const;
1687
1688 virtual const TypeAryPtr* cast_to_exactness(bool klass_is_exact) const;
1689
1690 virtual const TypeAryPtr* cast_to_instance_id(int instance_id) const;
1691
1692 virtual const TypeAryPtr* cast_to_size(const TypeInt* size) const;
1693 virtual const TypeInt* narrow_size_type(const TypeInt* size) const;
1694
1695 virtual bool empty(void) const; // TRUE if type is vacuous
1696 virtual const TypePtr *add_offset( intptr_t offset ) const;
1697 virtual const TypeAryPtr *with_offset( intptr_t offset ) const;
1698 const TypeAryPtr* with_ary(const TypeAry* ary) const;
1699
1700 // Speculative type helper methods.
1701 virtual const TypeAryPtr* remove_speculative() const;
1702 virtual const TypePtr* with_inline_depth(int depth) const;
1703 virtual const TypePtr* with_instance_id(int instance_id) const;
1704
1705 // the core of the computation of the meet of 2 types
1706 virtual const Type *xmeet_helper(const Type *t) const;
1707 virtual const Type *xdual() const; // Compute dual right now.
1708
1709 const TypeAryPtr* cast_to_stable(bool stable, int stable_dimension = 1) const;
1710 int stable_dimension() const;
1711
1712 const TypeAryPtr* cast_to_autobox_cache() const;
1713
1714 static jint max_array_length(BasicType etype) ;
1715 virtual const TypeKlassPtr* as_klass_type(bool try_for_exact = false) const;
1716
1717 // Convenience common pre-built types.
1718 static const TypeAryPtr* BOTTOM;
1719 static const TypeAryPtr* RANGE;
1720 static const TypeAryPtr* OOPS;
1721 static const TypeAryPtr* NARROWOOPS;
1722 static const TypeAryPtr* BYTES;
1723 static const TypeAryPtr* SHORTS;
1724 static const TypeAryPtr* CHARS;
1725 static const TypeAryPtr* INTS;
1726 static const TypeAryPtr* LONGS;
1727 static const TypeAryPtr* FLOATS;
1728 static const TypeAryPtr* DOUBLES;
1729 // selects one of the above:
1730 static const TypeAryPtr *get_array_body_type(BasicType elem) {
1731 assert((uint)elem <= T_CONFLICT && _array_body_type[elem] != nullptr, "bad elem type");
1732 return _array_body_type[elem];
1733 }
1734 static const TypeAryPtr *_array_body_type[T_CONFLICT+1];
1735 // sharpen the type of an int which is used as an array size
1736 #ifndef PRODUCT
1737 virtual void dump2( Dict &d, uint depth, outputStream *st ) const; // Specialized per-Type dumping
1738 #endif
1739 private:
1740 virtual bool is_meet_subtype_of_helper(const TypeOopPtr* other, bool this_xk, bool other_xk) const;
1741 };
1742
1743 //------------------------------TypeMetadataPtr-------------------------------------
1744 // Some kind of metadata, either Method*, MethodData* or CPCacheOop
1745 class TypeMetadataPtr : public TypePtr {
1746 protected:
1747 TypeMetadataPtr(PTR ptr, ciMetadata* metadata, int offset);
1748 // Do not allow interface-vs.-noninterface joins to collapse to top.
1749 virtual const Type *filter_helper(const Type *kills, bool include_speculative) const;
1750 public:
1751 virtual bool eq( const Type *t ) const;
1752 virtual uint hash() const; // Type specific hashing
1753 virtual bool singleton(void) const; // TRUE if type is a singleton
1754
1755 private:
1756 ciMetadata* _metadata;
1757
1758 public:
1759 static const TypeMetadataPtr* make(PTR ptr, ciMetadata* m, int offset);
1760
1761 static const TypeMetadataPtr* make(ciMethod* m);
1762 static const TypeMetadataPtr* make(ciMethodData* m);
1763
1764 ciMetadata* metadata() const { return _metadata; }
1765
1766 virtual const TypeMetadataPtr* cast_to_ptr_type(PTR ptr) const;
1767
1768 virtual const TypePtr *add_offset( intptr_t offset ) const;
1769
1770 virtual const Type *xmeet( const Type *t ) const;
1771 virtual const Type *xdual() const; // Compute dual right now.
1772
1773 virtual intptr_t get_con() const;
1774
1775 // Convenience common pre-built types.
1776 static const TypeMetadataPtr *BOTTOM;
1777
1778 #ifndef PRODUCT
1779 virtual void dump2( Dict &d, uint depth, outputStream *st ) const;
1780 #endif
1781 };
1782
1783 //------------------------------TypeKlassPtr-----------------------------------
1784 // Class of Java Klass pointers
1785 class TypeKlassPtr : public TypePtr {
1786 friend class TypeInstKlassPtr;
1787 friend class TypeAryKlassPtr;
1788 friend class TypePtr;
1789 protected:
1790 TypeKlassPtr(TYPES t, PTR ptr, ciKlass* klass, const TypeInterfaces* interfaces, int offset);
1791
1792 virtual const Type *filter_helper(const Type *kills, bool include_speculative) const;
1793
1794 public:
1795 virtual bool eq( const Type *t ) const;
1796 virtual uint hash() const;
1797 virtual bool singleton(void) const; // TRUE if type is a singleton
1798
1799 protected:
1800
1801 ciKlass* _klass;
1802 const TypeInterfaces* _interfaces;
1803 const TypeInterfaces* meet_interfaces(const TypeKlassPtr* other) const;
1804 virtual bool must_be_exact() const { ShouldNotReachHere(); return false; }
1805 virtual ciKlass* exact_klass_helper() const;
1806 virtual ciKlass* klass() const { return _klass; }
1807
1808 public:
1809
1810 bool is_java_subtype_of(const TypeKlassPtr* other) const {
1811 return is_java_subtype_of_helper(other, klass_is_exact(), other->klass_is_exact());
1812 }
1813 bool is_same_java_type_as(const TypePtr* other) const {
1814 return is_same_java_type_as_helper(other->is_klassptr());
1815 }
1816
1817 bool maybe_java_subtype_of(const TypeKlassPtr* other) const {
1818 return maybe_java_subtype_of_helper(other, klass_is_exact(), other->klass_is_exact());
1819 }
1820 virtual bool is_same_java_type_as_helper(const TypeKlassPtr* other) const { ShouldNotReachHere(); return false; }
1821 virtual bool is_java_subtype_of_helper(const TypeKlassPtr* other, bool this_exact, bool other_exact) const { ShouldNotReachHere(); return false; }
1822 virtual bool maybe_java_subtype_of_helper(const TypeKlassPtr* other, bool this_exact, bool other_exact) const { ShouldNotReachHere(); return false; }
1823
1824 // Exact klass, possibly an interface or an array of interface
1825 ciKlass* exact_klass(bool maybe_null = false) const { assert(klass_is_exact(), ""); ciKlass* k = exact_klass_helper(); assert(k != nullptr || maybe_null, ""); return k; }
1826 virtual bool klass_is_exact() const { return _ptr == Constant; }
1827
1828 static const TypeKlassPtr* make(ciKlass* klass, InterfaceHandling interface_handling = ignore_interfaces);
1829 static const TypeKlassPtr *make(PTR ptr, ciKlass* klass, int offset, InterfaceHandling interface_handling = ignore_interfaces);
1830
1831 virtual bool is_loaded() const { return _klass->is_loaded(); }
1832
1833 virtual const TypeKlassPtr* cast_to_ptr_type(PTR ptr) const { ShouldNotReachHere(); return nullptr; }
1834
1835 virtual const TypeKlassPtr *cast_to_exactness(bool klass_is_exact) const { ShouldNotReachHere(); return nullptr; }
1836
1837 // corresponding pointer to instance, for a given class
1838 virtual const TypeOopPtr* as_instance_type(bool klass_change = true) const { ShouldNotReachHere(); return nullptr; }
1839
1840 virtual const TypePtr *add_offset( intptr_t offset ) const { ShouldNotReachHere(); return nullptr; }
1841 virtual const Type *xmeet( const Type *t ) const { ShouldNotReachHere(); return nullptr; }
1842 virtual const Type *xdual() const { ShouldNotReachHere(); return nullptr; }
1843
1844 virtual intptr_t get_con() const;
1845
1846 virtual const TypeKlassPtr* with_offset(intptr_t offset) const { ShouldNotReachHere(); return nullptr; }
1847
1848 virtual const TypeKlassPtr* try_improve() const { return this; }
1849
1850 private:
1851 virtual bool is_meet_subtype_of(const TypePtr* other) const {
1852 return is_meet_subtype_of_helper(other->is_klassptr(), klass_is_exact(), other->is_klassptr()->klass_is_exact());
1853 }
1854
1855 virtual bool is_meet_subtype_of_helper(const TypeKlassPtr* other, bool this_xk, bool other_xk) const {
1856 ShouldNotReachHere(); return false;
1857 }
1858
1859 virtual const TypeInterfaces* interfaces() const {
1860 return _interfaces;
1861 };
1862
1863 const TypeKlassPtr* is_reference_type(const Type* other) const {
1864 return other->isa_klassptr();
1865 }
1866
1867 const TypeAryKlassPtr* is_array_type(const TypeKlassPtr* other) const {
1868 return other->isa_aryklassptr();
1869 }
1870
1871 const TypeInstKlassPtr* is_instance_type(const TypeKlassPtr* other) const {
1872 return other->isa_instklassptr();
1873 }
1874 };
1875
1876 // Instance klass pointer, mirrors TypeInstPtr
1877 class TypeInstKlassPtr : public TypeKlassPtr {
1878
1879 TypeInstKlassPtr(PTR ptr, ciKlass* klass, const TypeInterfaces* interfaces, int offset)
1880 : TypeKlassPtr(InstKlassPtr, ptr, klass, interfaces, offset) {
1881 assert(klass->is_instance_klass() && (!klass->is_loaded() || !klass->is_interface()), "");
1882 }
1883
1884 virtual bool must_be_exact() const;
1885
1886 public:
1887 // Instance klass ignoring any interface
1888 ciInstanceKlass* instance_klass() const {
1889 assert(!klass()->is_interface(), "");
1890 return klass()->as_instance_klass();
1891 }
1892
1893 bool might_be_an_array() const;
1894
1895 bool is_same_java_type_as_helper(const TypeKlassPtr* other) const;
1896 bool is_java_subtype_of_helper(const TypeKlassPtr* other, bool this_exact, bool other_exact) const;
1897 bool maybe_java_subtype_of_helper(const TypeKlassPtr* other, bool this_exact, bool other_exact) const;
1898
1899 static const TypeInstKlassPtr *make(ciKlass* k, InterfaceHandling interface_handling) {
1900 const TypeInterfaces* interfaces = TypePtr::interfaces(k, true, true, false, interface_handling);
1901 return make(TypePtr::Constant, k, interfaces, 0);
1902 }
1903 static const TypeInstKlassPtr* make(PTR ptr, ciKlass* k, const TypeInterfaces* interfaces, int offset);
1904
1905 static const TypeInstKlassPtr* make(PTR ptr, ciKlass* k, int offset) {
1906 const TypeInterfaces* interfaces = TypePtr::interfaces(k, true, false, false, ignore_interfaces);
1907 return make(ptr, k, interfaces, offset);
1908 }
1909
1910 virtual const TypeInstKlassPtr* cast_to_ptr_type(PTR ptr) const;
1911
1912 virtual const TypeKlassPtr *cast_to_exactness(bool klass_is_exact) const;
1913
1914 // corresponding pointer to instance, for a given class
1915 virtual const TypeOopPtr* as_instance_type(bool klass_change = true) const;
1916 virtual uint hash() const;
1917 virtual bool eq(const Type *t) const;
1918
1919 virtual const TypePtr *add_offset( intptr_t offset ) const;
1920 virtual const Type *xmeet( const Type *t ) const;
1921 virtual const Type *xdual() const;
1922 virtual const TypeInstKlassPtr* with_offset(intptr_t offset) const;
1923
1924 virtual const TypeKlassPtr* try_improve() const;
1925
1926 // Convenience common pre-built types.
1927 static const TypeInstKlassPtr* OBJECT; // Not-null object klass or below
1928 static const TypeInstKlassPtr* OBJECT_OR_NULL; // Maybe-null version of same
1929
1930 #ifndef PRODUCT
1931 virtual void dump2(Dict& d, uint depth, outputStream* st) const;
1932 #endif // PRODUCT
1933
1934 private:
1935 virtual bool is_meet_subtype_of_helper(const TypeKlassPtr* other, bool this_xk, bool other_xk) const;
1936 };
1937
1938 // Array klass pointer, mirrors TypeAryPtr
1939 class TypeAryKlassPtr : public TypeKlassPtr {
1940 friend class TypeInstKlassPtr;
1941 friend class Type;
1942 friend class TypePtr;
1943
1944 const Type *_elem;
1945
1946 static const TypeInterfaces* _array_interfaces;
1947 TypeAryKlassPtr(PTR ptr, const Type *elem, ciKlass* klass, int offset)
1948 : TypeKlassPtr(AryKlassPtr, ptr, klass, _array_interfaces, offset), _elem(elem) {
1949 assert(klass == nullptr || klass->is_type_array_klass() || !klass->as_obj_array_klass()->base_element_klass()->is_interface(), "");
1950 }
1951
1952 virtual ciKlass* exact_klass_helper() const;
1953 // Only guaranteed non null for array of basic types
1954 virtual ciKlass* klass() const;
1955
1956 virtual bool must_be_exact() const;
1957
1958 public:
1959
1960 // returns base element type, an instance klass (and not interface) for object arrays
1961 const Type* base_element_type(int& dims) const;
1962
1963 static const TypeAryKlassPtr *make(PTR ptr, ciKlass* k, int offset, InterfaceHandling interface_handling);
1964
1965 bool is_same_java_type_as_helper(const TypeKlassPtr* other) const;
1966 bool is_java_subtype_of_helper(const TypeKlassPtr* other, bool this_exact, bool other_exact) const;
1967 bool maybe_java_subtype_of_helper(const TypeKlassPtr* other, bool this_exact, bool other_exact) const;
1968
1969 bool is_loaded() const { return (_elem->isa_klassptr() ? _elem->is_klassptr()->is_loaded() : true); }
1970
1971 static const TypeAryKlassPtr *make(PTR ptr, const Type *elem, ciKlass* k, int offset);
1972 static const TypeAryKlassPtr* make(ciKlass* klass, InterfaceHandling interface_handling);
1973
1974 const Type *elem() const { return _elem; }
1975
1976 virtual bool eq(const Type *t) const;
1977 virtual uint hash() const; // Type specific hashing
1978
1979 virtual const TypeAryKlassPtr* cast_to_ptr_type(PTR ptr) const;
1980
1981 virtual const TypeKlassPtr *cast_to_exactness(bool klass_is_exact) const;
1982
1983 // corresponding pointer to instance, for a given class
1984 virtual const TypeOopPtr* as_instance_type(bool klass_change = true) const;
1985
1986 virtual const TypePtr *add_offset( intptr_t offset ) const;
1987 virtual const Type *xmeet( const Type *t ) const;
1988 virtual const Type *xdual() const; // Compute dual right now.
1989
1990 virtual const TypeAryKlassPtr* with_offset(intptr_t offset) const;
1991
1992 virtual bool empty(void) const {
1993 return TypeKlassPtr::empty() || _elem->empty();
1994 }
1995
1996 #ifndef PRODUCT
1997 virtual void dump2( Dict &d, uint depth, outputStream *st ) const; // Specialized per-Type dumping
1998 #endif
1999 private:
2000 virtual bool is_meet_subtype_of_helper(const TypeKlassPtr* other, bool this_xk, bool other_xk) const;
2001 };
2002
2003 class TypeNarrowPtr : public Type {
2004 protected:
2005 const TypePtr* _ptrtype; // Could be TypePtr::NULL_PTR
2006
2007 TypeNarrowPtr(TYPES t, const TypePtr* ptrtype): Type(t),
2008 _ptrtype(ptrtype) {
2009 assert(ptrtype->offset() == 0 ||
2010 ptrtype->offset() == OffsetBot ||
2011 ptrtype->offset() == OffsetTop, "no real offsets");
2012 }
2013
2014 virtual const TypeNarrowPtr *isa_same_narrowptr(const Type *t) const = 0;
2015 virtual const TypeNarrowPtr *is_same_narrowptr(const Type *t) const = 0;
2016 virtual const TypeNarrowPtr *make_same_narrowptr(const TypePtr *t) const = 0;
2017 virtual const TypeNarrowPtr *make_hash_same_narrowptr(const TypePtr *t) const = 0;
2018 // Do not allow interface-vs.-noninterface joins to collapse to top.
2019 virtual const Type *filter_helper(const Type *kills, bool include_speculative) const;
2020 public:
2021 virtual bool eq( const Type *t ) const;
2022 virtual uint hash() const; // Type specific hashing
2023 virtual bool singleton(void) const; // TRUE if type is a singleton
2024
2025 virtual const Type *xmeet( const Type *t ) const;
2026 virtual const Type *xdual() const; // Compute dual right now.
2027
2028 virtual intptr_t get_con() const;
2029
2030 virtual bool empty(void) const; // TRUE if type is vacuous
2031
2032 // returns the equivalent ptr type for this compressed pointer
2033 const TypePtr *get_ptrtype() const {
2034 return _ptrtype;
2035 }
2036
2037 bool is_known_instance() const {
2038 return _ptrtype->is_known_instance();
2039 }
2040
2041 #ifndef PRODUCT
2042 virtual void dump2( Dict &d, uint depth, outputStream *st ) const;
2043 #endif
2044 };
2045
2046 //------------------------------TypeNarrowOop----------------------------------
2047 // A compressed reference to some kind of Oop. This type wraps around
2048 // a preexisting TypeOopPtr and forwards most of it's operations to
2049 // the underlying type. It's only real purpose is to track the
2050 // oopness of the compressed oop value when we expose the conversion
2051 // between the normal and the compressed form.
2052 class TypeNarrowOop : public TypeNarrowPtr {
2053 protected:
2054 TypeNarrowOop( const TypePtr* ptrtype): TypeNarrowPtr(NarrowOop, ptrtype) {
2055 }
2056
2057 virtual const TypeNarrowPtr *isa_same_narrowptr(const Type *t) const {
2058 return t->isa_narrowoop();
2059 }
2060
2061 virtual const TypeNarrowPtr *is_same_narrowptr(const Type *t) const {
2062 return t->is_narrowoop();
2063 }
2064
2065 virtual const TypeNarrowPtr *make_same_narrowptr(const TypePtr *t) const {
2066 return new TypeNarrowOop(t);
2067 }
2068
2069 virtual const TypeNarrowPtr *make_hash_same_narrowptr(const TypePtr *t) const {
2070 return (const TypeNarrowPtr*)((new TypeNarrowOop(t))->hashcons());
2071 }
2072
2073 public:
2074
2075 static const TypeNarrowOop *make( const TypePtr* type);
2076
2077 static const TypeNarrowOop* make_from_constant(ciObject* con, bool require_constant = false) {
2078 return make(TypeOopPtr::make_from_constant(con, require_constant));
2079 }
2080
2081 static const TypeNarrowOop *BOTTOM;
2082 static const TypeNarrowOop *NULL_PTR;
2083
2084 virtual const TypeNarrowOop* remove_speculative() const;
2085 virtual const Type* cleanup_speculative() const;
2086
2087 #ifndef PRODUCT
2088 virtual void dump2( Dict &d, uint depth, outputStream *st ) const;
2089 #endif
2090 };
2091
2092 //------------------------------TypeNarrowKlass----------------------------------
2093 // A compressed reference to klass pointer. This type wraps around a
2094 // preexisting TypeKlassPtr and forwards most of it's operations to
2095 // the underlying type.
2096 class TypeNarrowKlass : public TypeNarrowPtr {
2097 protected:
2098 TypeNarrowKlass( const TypePtr* ptrtype): TypeNarrowPtr(NarrowKlass, ptrtype) {
2099 }
2100
2101 virtual const TypeNarrowPtr *isa_same_narrowptr(const Type *t) const {
2102 return t->isa_narrowklass();
2103 }
2104
2105 virtual const TypeNarrowPtr *is_same_narrowptr(const Type *t) const {
2106 return t->is_narrowklass();
2107 }
2108
2109 virtual const TypeNarrowPtr *make_same_narrowptr(const TypePtr *t) const {
2110 return new TypeNarrowKlass(t);
2111 }
2112
2113 virtual const TypeNarrowPtr *make_hash_same_narrowptr(const TypePtr *t) const {
2114 return (const TypeNarrowPtr*)((new TypeNarrowKlass(t))->hashcons());
2115 }
2116
2117 public:
2118 static const TypeNarrowKlass *make( const TypePtr* type);
2119
2120 // static const TypeNarrowKlass *BOTTOM;
2121 static const TypeNarrowKlass *NULL_PTR;
2122
2123 #ifndef PRODUCT
2124 virtual void dump2( Dict &d, uint depth, outputStream *st ) const;
2125 #endif
2126 };
2127
2128 //------------------------------TypeFunc---------------------------------------
2129 // Class of Array Types
2130 class TypeFunc : public Type {
2131 TypeFunc( const TypeTuple *domain, const TypeTuple *range ) : Type(Function), _domain(domain), _range(range) {}
2132 virtual bool eq( const Type *t ) const;
2133 virtual uint hash() const; // Type specific hashing
2134 virtual bool singleton(void) const; // TRUE if type is a singleton
2135 virtual bool empty(void) const; // TRUE if type is vacuous
2136
2137 const TypeTuple* const _domain; // Domain of inputs
2138 const TypeTuple* const _range; // Range of results
2139
2140 public:
2141 // Constants are shared among ADLC and VM
2142 enum { Control = AdlcVMDeps::Control,
2143 I_O = AdlcVMDeps::I_O,
2144 Memory = AdlcVMDeps::Memory,
2145 FramePtr = AdlcVMDeps::FramePtr,
2146 ReturnAdr = AdlcVMDeps::ReturnAdr,
2147 Parms = AdlcVMDeps::Parms
2148 };
2149
2150
2151 // Accessors:
2152 const TypeTuple* domain() const { return _domain; }
2153 const TypeTuple* range() const { return _range; }
2154
2155 static const TypeFunc *make(ciMethod* method);
2156 static const TypeFunc *make(ciSignature signature, const Type* extra);
2157 static const TypeFunc *make(const TypeTuple* domain, const TypeTuple* range);
2158
2159 virtual const Type *xmeet( const Type *t ) const;
2160 virtual const Type *xdual() const; // Compute dual right now.
2161
2162 BasicType return_type() const;
2163
2164 #ifndef PRODUCT
2165 virtual void dump2( Dict &d, uint depth, outputStream *st ) const; // Specialized per-Type dumping
2166 #endif
2167 // Convenience common pre-built types.
2168 };
2169
2170 //------------------------------accessors--------------------------------------
2171 inline bool Type::is_ptr_to_narrowoop() const {
2172 #ifdef _LP64
2173 return (isa_oopptr() != nullptr && is_oopptr()->is_ptr_to_narrowoop_nv());
2174 #else
2175 return false;
2176 #endif
2177 }
2178
2179 inline bool Type::is_ptr_to_narrowklass() const {
2180 #ifdef _LP64
2181 return (isa_oopptr() != nullptr && is_oopptr()->is_ptr_to_narrowklass_nv());
2182 #else
2183 return false;
2184 #endif
2185 }
2186
2187 inline float Type::getf() const {
2188 assert( _base == FloatCon, "Not a FloatCon" );
2189 return ((TypeF*)this)->_f;
2190 }
2191
2192 inline short Type::geth() const {
2193 assert(_base == HalfFloatCon, "Not a HalfFloatCon");
2194 return ((TypeH*)this)->_f;
2195 }
2196
2197 inline double Type::getd() const {
2198 assert( _base == DoubleCon, "Not a DoubleCon" );
2199 return ((TypeD*)this)->_d;
2200 }
2201
2202 inline const TypeInteger *Type::is_integer(BasicType bt) const {
2203 assert((bt == T_INT && _base == Int) || (bt == T_LONG && _base == Long), "Not an Int");
2204 return (TypeInteger*)this;
2205 }
2206
2207 inline const TypeInteger *Type::isa_integer(BasicType bt) const {
2208 return (((bt == T_INT && _base == Int) || (bt == T_LONG && _base == Long)) ? (TypeInteger*)this : nullptr);
2209 }
2210
2211 inline const TypeInt *Type::is_int() const {
2212 assert( _base == Int, "Not an Int" );
2213 return (TypeInt*)this;
2214 }
2215
2216 inline const TypeInt *Type::isa_int() const {
2217 return ( _base == Int ? (TypeInt*)this : nullptr);
2218 }
2219
2220 inline const TypeLong *Type::is_long() const {
2221 assert( _base == Long, "Not a Long" );
2222 return (TypeLong*)this;
2223 }
2224
2225 inline const TypeLong *Type::isa_long() const {
2226 return ( _base == Long ? (TypeLong*)this : nullptr);
2227 }
2228
2229 inline const TypeH* Type::isa_half_float() const {
2230 return ((_base == HalfFloatTop ||
2231 _base == HalfFloatCon ||
2232 _base == HalfFloatBot) ? (TypeH*)this : nullptr);
2233 }
2234
2235 inline const TypeH* Type::is_half_float_constant() const {
2236 assert( _base == HalfFloatCon, "Not a HalfFloat" );
2237 return (TypeH*)this;
2238 }
2239
2240 inline const TypeH* Type::isa_half_float_constant() const {
2241 return (_base == HalfFloatCon ? (TypeH*)this : nullptr);
2242 }
2243
2244 inline const TypeF *Type::isa_float() const {
2245 return ((_base == FloatTop ||
2246 _base == FloatCon ||
2247 _base == FloatBot) ? (TypeF*)this : nullptr);
2248 }
2249
2250 inline const TypeF *Type::is_float_constant() const {
2251 assert( _base == FloatCon, "Not a Float" );
2252 return (TypeF*)this;
2253 }
2254
2255 inline const TypeF *Type::isa_float_constant() const {
2256 return ( _base == FloatCon ? (TypeF*)this : nullptr);
2257 }
2258
2259 inline const TypeD *Type::isa_double() const {
2260 return ((_base == DoubleTop ||
2261 _base == DoubleCon ||
2262 _base == DoubleBot) ? (TypeD*)this : nullptr);
2263 }
2264
2265 inline const TypeD *Type::is_double_constant() const {
2266 assert( _base == DoubleCon, "Not a Double" );
2267 return (TypeD*)this;
2268 }
2269
2270 inline const TypeD *Type::isa_double_constant() const {
2271 return ( _base == DoubleCon ? (TypeD*)this : nullptr);
2272 }
2273
2274 inline const TypeTuple *Type::is_tuple() const {
2275 assert( _base == Tuple, "Not a Tuple" );
2276 return (TypeTuple*)this;
2277 }
2278
2279 inline const TypeAry *Type::is_ary() const {
2280 assert( _base == Array , "Not an Array" );
2281 return (TypeAry*)this;
2282 }
2283
2284 inline const TypeAry *Type::isa_ary() const {
2285 return ((_base == Array) ? (TypeAry*)this : nullptr);
2286 }
2287
2288 inline const TypeVectMask *Type::is_vectmask() const {
2289 assert( _base == VectorMask, "Not a Vector Mask" );
2290 return (TypeVectMask*)this;
2291 }
2292
2293 inline const TypeVectMask *Type::isa_vectmask() const {
2294 return (_base == VectorMask) ? (TypeVectMask*)this : nullptr;
2295 }
2296
2297 inline const TypeVect *Type::is_vect() const {
2298 assert( _base >= VectorMask && _base <= VectorZ, "Not a Vector" );
2299 return (TypeVect*)this;
2300 }
2301
2302 inline const TypeVect *Type::isa_vect() const {
2303 return (_base >= VectorMask && _base <= VectorZ) ? (TypeVect*)this : nullptr;
2304 }
2305
2306 inline const TypePtr *Type::is_ptr() const {
2307 // AnyPtr is the first Ptr and KlassPtr the last, with no non-ptrs between.
2308 assert(_base >= AnyPtr && _base <= AryKlassPtr, "Not a pointer");
2309 return (TypePtr*)this;
2310 }
2311
2312 inline const TypePtr *Type::isa_ptr() const {
2313 // AnyPtr is the first Ptr and KlassPtr the last, with no non-ptrs between.
2314 return (_base >= AnyPtr && _base <= AryKlassPtr) ? (TypePtr*)this : nullptr;
2315 }
2316
2317 inline const TypeOopPtr *Type::is_oopptr() const {
2318 // OopPtr is the first and KlassPtr the last, with no non-oops between.
2319 assert(_base >= OopPtr && _base <= AryPtr, "Not a Java pointer" ) ;
2320 return (TypeOopPtr*)this;
2321 }
2322
2323 inline const TypeOopPtr *Type::isa_oopptr() const {
2324 // OopPtr is the first and KlassPtr the last, with no non-oops between.
2325 return (_base >= OopPtr && _base <= AryPtr) ? (TypeOopPtr*)this : nullptr;
2326 }
2327
2328 inline const TypeRawPtr *Type::isa_rawptr() const {
2329 return (_base == RawPtr) ? (TypeRawPtr*)this : nullptr;
2330 }
2331
2332 inline const TypeRawPtr *Type::is_rawptr() const {
2333 assert( _base == RawPtr, "Not a raw pointer" );
2334 return (TypeRawPtr*)this;
2335 }
2336
2337 inline const TypeInstPtr *Type::isa_instptr() const {
2338 return (_base == InstPtr) ? (TypeInstPtr*)this : nullptr;
2339 }
2340
2341 inline const TypeInstPtr *Type::is_instptr() const {
2342 assert( _base == InstPtr, "Not an object pointer" );
2343 return (TypeInstPtr*)this;
2344 }
2345
2346 inline const TypeAryPtr *Type::isa_aryptr() const {
2347 return (_base == AryPtr) ? (TypeAryPtr*)this : nullptr;
2348 }
2349
2350 inline const TypeAryPtr *Type::is_aryptr() const {
2351 assert( _base == AryPtr, "Not an array pointer" );
2352 return (TypeAryPtr*)this;
2353 }
2354
2355 inline const TypeNarrowOop *Type::is_narrowoop() const {
2356 // OopPtr is the first and KlassPtr the last, with no non-oops between.
2357 assert(_base == NarrowOop, "Not a narrow oop" ) ;
2358 return (TypeNarrowOop*)this;
2359 }
2360
2361 inline const TypeNarrowOop *Type::isa_narrowoop() const {
2362 // OopPtr is the first and KlassPtr the last, with no non-oops between.
2363 return (_base == NarrowOop) ? (TypeNarrowOop*)this : nullptr;
2364 }
2365
2366 inline const TypeNarrowKlass *Type::is_narrowklass() const {
2367 assert(_base == NarrowKlass, "Not a narrow oop" ) ;
2368 return (TypeNarrowKlass*)this;
2369 }
2370
2371 inline const TypeNarrowKlass *Type::isa_narrowklass() const {
2372 return (_base == NarrowKlass) ? (TypeNarrowKlass*)this : nullptr;
2373 }
2374
2375 inline const TypeMetadataPtr *Type::is_metadataptr() const {
2376 // MetadataPtr is the first and CPCachePtr the last
2377 assert(_base == MetadataPtr, "Not a metadata pointer" ) ;
2378 return (TypeMetadataPtr*)this;
2379 }
2380
2381 inline const TypeMetadataPtr *Type::isa_metadataptr() const {
2382 return (_base == MetadataPtr) ? (TypeMetadataPtr*)this : nullptr;
2383 }
2384
2385 inline const TypeKlassPtr *Type::isa_klassptr() const {
2386 return (_base >= KlassPtr && _base <= AryKlassPtr ) ? (TypeKlassPtr*)this : nullptr;
2387 }
2388
2389 inline const TypeKlassPtr *Type::is_klassptr() const {
2390 assert(_base >= KlassPtr && _base <= AryKlassPtr, "Not a klass pointer");
2391 return (TypeKlassPtr*)this;
2392 }
2393
2394 inline const TypeInstKlassPtr *Type::isa_instklassptr() const {
2395 return (_base == InstKlassPtr) ? (TypeInstKlassPtr*)this : nullptr;
2396 }
2397
2398 inline const TypeInstKlassPtr *Type::is_instklassptr() const {
2399 assert(_base == InstKlassPtr, "Not a klass pointer");
2400 return (TypeInstKlassPtr*)this;
2401 }
2402
2403 inline const TypeAryKlassPtr *Type::isa_aryklassptr() const {
2404 return (_base == AryKlassPtr) ? (TypeAryKlassPtr*)this : nullptr;
2405 }
2406
2407 inline const TypeAryKlassPtr *Type::is_aryklassptr() const {
2408 assert(_base == AryKlassPtr, "Not a klass pointer");
2409 return (TypeAryKlassPtr*)this;
2410 }
2411
2412 inline const TypePtr* Type::make_ptr() const {
2413 return (_base == NarrowOop) ? is_narrowoop()->get_ptrtype() :
2414 ((_base == NarrowKlass) ? is_narrowklass()->get_ptrtype() :
2415 isa_ptr());
2416 }
2417
2418 inline const TypeOopPtr* Type::make_oopptr() const {
2419 return (_base == NarrowOop) ? is_narrowoop()->get_ptrtype()->isa_oopptr() : isa_oopptr();
2420 }
2421
2422 inline const TypeNarrowOop* Type::make_narrowoop() const {
2423 return (_base == NarrowOop) ? is_narrowoop() :
2424 (isa_ptr() ? TypeNarrowOop::make(is_ptr()) : nullptr);
2425 }
2426
2427 inline const TypeNarrowKlass* Type::make_narrowklass() const {
2428 return (_base == NarrowKlass) ? is_narrowklass() :
2429 (isa_ptr() ? TypeNarrowKlass::make(is_ptr()) : nullptr);
2430 }
2431
2432 inline bool Type::is_floatingpoint() const {
2433 if( (_base == HalfFloatCon) || (_base == HalfFloatBot) ||
2434 (_base == FloatCon) || (_base == FloatBot) ||
2435 (_base == DoubleCon) || (_base == DoubleBot) )
2436 return true;
2437 return false;
2438 }
2439
2440 template <>
2441 inline const TypeInt* Type::cast<TypeInt>() const {
2442 return is_int();
2443 }
2444
2445 template <>
2446 inline const TypeLong* Type::cast<TypeLong>() const {
2447 return is_long();
2448 }
2449
2450 template <>
2451 inline const TypeInt* Type::try_cast<TypeInt>() const {
2452 return isa_int();
2453 }
2454
2455 template <>
2456 inline const TypeLong* Type::try_cast<TypeLong>() const {
2457 return isa_long();
2458 }
2459
2460 // ===============================================================
2461 // Things that need to be 64-bits in the 64-bit build but
2462 // 32-bits in the 32-bit build. Done this way to get full
2463 // optimization AND strong typing.
2464 #ifdef _LP64
2465
2466 // For type queries and asserts
2467 #define is_intptr_t is_long
2468 #define isa_intptr_t isa_long
2469 #define find_intptr_t_type find_long_type
2470 #define find_intptr_t_con find_long_con
2471 #define TypeX TypeLong
2472 #define Type_X Type::Long
2473 #define TypeX_X TypeLong::LONG
2474 #define TypeX_ZERO TypeLong::ZERO
2475 // For 'ideal_reg' machine registers
2476 #define Op_RegX Op_RegL
2477 // For phase->intcon variants
2478 #define MakeConX longcon
2479 #define ConXNode ConLNode
2480 // For array index arithmetic
2481 #define MulXNode MulLNode
2482 #define AndXNode AndLNode
2483 #define OrXNode OrLNode
2484 #define CmpXNode CmpLNode
2485 #define SubXNode SubLNode
2486 #define LShiftXNode LShiftLNode
2487 // For object size computation:
2488 #define AddXNode AddLNode
2489 #define RShiftXNode RShiftLNode
2490 // For card marks and hashcodes
2491 #define URShiftXNode URShiftLNode
2492 // For shenandoahSupport
2493 #define LoadXNode LoadLNode
2494 #define StoreXNode StoreLNode
2495 // Opcodes
2496 #define Op_LShiftX Op_LShiftL
2497 #define Op_AndX Op_AndL
2498 #define Op_AddX Op_AddL
2499 #define Op_SubX Op_SubL
2500 #define Op_XorX Op_XorL
2501 #define Op_URShiftX Op_URShiftL
2502 #define Op_LoadX Op_LoadL
2503 // conversions
2504 #define ConvI2X(x) ConvI2L(x)
2505 #define ConvL2X(x) (x)
2506 #define ConvX2I(x) ConvL2I(x)
2507 #define ConvX2L(x) (x)
2508 #define ConvX2UL(x) (x)
2509
2510 #else
2511
2512 // For type queries and asserts
2513 #define is_intptr_t is_int
2514 #define isa_intptr_t isa_int
2515 #define find_intptr_t_type find_int_type
2516 #define find_intptr_t_con find_int_con
2517 #define TypeX TypeInt
2518 #define Type_X Type::Int
2519 #define TypeX_X TypeInt::INT
2520 #define TypeX_ZERO TypeInt::ZERO
2521 // For 'ideal_reg' machine registers
2522 #define Op_RegX Op_RegI
2523 // For phase->intcon variants
2524 #define MakeConX intcon
2525 #define ConXNode ConINode
2526 // For array index arithmetic
2527 #define MulXNode MulINode
2528 #define AndXNode AndINode
2529 #define OrXNode OrINode
2530 #define CmpXNode CmpINode
2531 #define SubXNode SubINode
2532 #define LShiftXNode LShiftINode
2533 // For object size computation:
2534 #define AddXNode AddINode
2535 #define RShiftXNode RShiftINode
2536 // For card marks and hashcodes
2537 #define URShiftXNode URShiftINode
2538 // For shenandoahSupport
2539 #define LoadXNode LoadINode
2540 #define StoreXNode StoreINode
2541 // Opcodes
2542 #define Op_LShiftX Op_LShiftI
2543 #define Op_AndX Op_AndI
2544 #define Op_AddX Op_AddI
2545 #define Op_SubX Op_SubI
2546 #define Op_XorX Op_XorI
2547 #define Op_URShiftX Op_URShiftI
2548 #define Op_LoadX Op_LoadI
2549 // conversions
2550 #define ConvI2X(x) (x)
2551 #define ConvL2X(x) ConvL2I(x)
2552 #define ConvX2I(x) (x)
2553 #define ConvX2L(x) ConvI2L(x)
2554 #define ConvX2UL(x) ConvI2UL(x)
2555
2556 #endif
2557
2558 #endif // SHARE_OPTO_TYPE_HPP