1 /*
2 * Copyright (c) 1997, 2026, Oracle and/or its affiliates. All rights reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * This code is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation.
8 *
9 * This code is distributed in the hope that it will be useful, but WITHOUT
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
12 * version 2 for more details (a copy is included in the LICENSE file that
13 * accompanied this code).
14 *
15 * You should have received a copy of the GNU General Public License version
16 * 2 along with this work; if not, write to the Free Software Foundation,
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18 *
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20 * or visit www.oracle.com if you need additional information or have any
21 * questions.
22 *
23 */
24
25 #include "ci/ciMethodData.hpp"
26 #include "ci/ciTypeFlow.hpp"
27 #include "classfile/javaClasses.hpp"
28 #include "classfile/symbolTable.hpp"
29 #include "classfile/vmSymbols.hpp"
30 #include "compiler/compileLog.hpp"
31 #include "libadt/dict.hpp"
32 #include "memory/oopFactory.hpp"
33 #include "memory/resourceArea.hpp"
34 #include "oops/instanceKlass.hpp"
35 #include "oops/instanceMirrorKlass.hpp"
36 #include "oops/objArrayKlass.hpp"
37 #include "oops/typeArrayKlass.hpp"
38 #include "opto/arraycopynode.hpp"
39 #include "opto/callnode.hpp"
40 #include "opto/matcher.hpp"
41 #include "opto/node.hpp"
42 #include "opto/opcodes.hpp"
43 #include "opto/rangeinference.hpp"
44 #include "opto/runtime.hpp"
45 #include "opto/type.hpp"
46 #include "runtime/stubRoutines.hpp"
47 #include "utilities/checkedCast.hpp"
48 #include "utilities/debug.hpp"
49 #include "utilities/ostream.hpp"
50 #include "utilities/powerOfTwo.hpp"
51 #include "utilities/stringUtils.hpp"
52 #if INCLUDE_SHENANDOAHGC
53 #include "gc/shenandoah/c2/shenandoahBarrierSetC2.hpp"
54 #endif // INCLUDE_SHENANDOAHGC
55
56 // Portions of code courtesy of Clifford Click
57
58 // Optimization - Graph Style
59
60 // Dictionary of types shared among compilations.
61 Dict* Type::_shared_type_dict = nullptr;
62
63 // Array which maps compiler types to Basic Types
64 const Type::TypeInfo Type::_type_info[Type::lastype] = {
65 { Bad, T_ILLEGAL, "bad", false, Node::NotAMachineReg, relocInfo::none }, // Bad
66 { Control, T_ILLEGAL, "control", false, 0, relocInfo::none }, // Control
67 { Bottom, T_VOID, "top", false, 0, relocInfo::none }, // Top
68 { Bad, T_INT, "int:", false, Op_RegI, relocInfo::none }, // Int
69 { Bad, T_LONG, "long:", false, Op_RegL, relocInfo::none }, // Long
70 { Half, T_VOID, "half", false, 0, relocInfo::none }, // Half
71 { Bad, T_NARROWOOP, "narrowoop:", false, Op_RegN, relocInfo::none }, // NarrowOop
72 { Bad, T_NARROWKLASS,"narrowklass:", false, Op_RegN, relocInfo::none }, // NarrowKlass
73 { Bad, T_ILLEGAL, "tuple:", false, Node::NotAMachineReg, relocInfo::none }, // Tuple
74 { Bad, T_ARRAY, "array:", false, Node::NotAMachineReg, relocInfo::none }, // Array
75 { Bad, T_ARRAY, "interfaces:", false, Node::NotAMachineReg, relocInfo::none }, // Interfaces
76
77 #if defined(PPC64)
78 { Bad, T_ILLEGAL, "vectormask:", false, Op_RegVectMask, relocInfo::none }, // VectorMask.
79 { Bad, T_ILLEGAL, "vectora:", false, Op_VecA, relocInfo::none }, // VectorA.
80 { Bad, T_ILLEGAL, "vectors:", false, 0, relocInfo::none }, // VectorS
81 { Bad, T_ILLEGAL, "vectord:", false, Op_RegL, relocInfo::none }, // VectorD
82 { Bad, T_ILLEGAL, "vectorx:", false, Op_VecX, relocInfo::none }, // VectorX
83 { Bad, T_ILLEGAL, "vectory:", false, 0, relocInfo::none }, // VectorY
84 { Bad, T_ILLEGAL, "vectorz:", false, 0, relocInfo::none }, // VectorZ
85 #elif defined(S390)
86 { Bad, T_ILLEGAL, "vectormask:", false, Op_RegVectMask, relocInfo::none }, // VectorMask.
87 { Bad, T_ILLEGAL, "vectora:", false, Op_VecA, relocInfo::none }, // VectorA.
88 { Bad, T_ILLEGAL, "vectors:", false, 0, relocInfo::none }, // VectorS
89 { Bad, T_ILLEGAL, "vectord:", false, Op_RegL, relocInfo::none }, // VectorD
90 { Bad, T_ILLEGAL, "vectorx:", false, Op_VecX, relocInfo::none }, // VectorX
91 { Bad, T_ILLEGAL, "vectory:", false, 0, relocInfo::none }, // VectorY
92 { Bad, T_ILLEGAL, "vectorz:", false, 0, relocInfo::none }, // VectorZ
93 #else // all other
94 { Bad, T_ILLEGAL, "vectormask:", false, Op_RegVectMask, relocInfo::none }, // VectorMask.
95 { Bad, T_ILLEGAL, "vectora:", false, Op_VecA, relocInfo::none }, // VectorA.
96 { Bad, T_ILLEGAL, "vectors:", false, Op_VecS, relocInfo::none }, // VectorS
97 { Bad, T_ILLEGAL, "vectord:", false, Op_VecD, relocInfo::none }, // VectorD
98 { Bad, T_ILLEGAL, "vectorx:", false, Op_VecX, relocInfo::none }, // VectorX
99 { Bad, T_ILLEGAL, "vectory:", false, Op_VecY, relocInfo::none }, // VectorY
100 { Bad, T_ILLEGAL, "vectorz:", false, Op_VecZ, relocInfo::none }, // VectorZ
101 #endif
102 { Bad, T_ADDRESS, "anyptr:", false, Op_RegP, relocInfo::none }, // AnyPtr
103 { Bad, T_ADDRESS, "rawptr:", false, Op_RegP, relocInfo::external_word_type }, // RawPtr
104 { Bad, T_OBJECT, "oop:", true, Op_RegP, relocInfo::oop_type }, // OopPtr
105 { Bad, T_OBJECT, "inst:", true, Op_RegP, relocInfo::oop_type }, // InstPtr
106 { Bad, T_OBJECT, "ary:", true, Op_RegP, relocInfo::oop_type }, // AryPtr
107 { Bad, T_METADATA, "metadata:", false, Op_RegP, relocInfo::metadata_type }, // MetadataPtr
108 { Bad, T_METADATA, "klass:", false, Op_RegP, relocInfo::metadata_type }, // KlassPtr
109 { Bad, T_METADATA, "instklass:", false, Op_RegP, relocInfo::metadata_type }, // InstKlassPtr
110 { Bad, T_METADATA, "aryklass:", false, Op_RegP, relocInfo::metadata_type }, // AryKlassPtr
111 { Bad, T_OBJECT, "func", false, 0, relocInfo::none }, // Function
112 { Abio, T_ILLEGAL, "abIO", false, 0, relocInfo::none }, // Abio
113 { Return_Address, T_ADDRESS, "return_address",false, Op_RegP, relocInfo::none }, // Return_Address
114 { Memory, T_ILLEGAL, "memory", false, 0, relocInfo::none }, // Memory
115 { HalfFloatBot, T_SHORT, "halffloat_top", false, Op_RegF, relocInfo::none }, // HalfFloatTop
116 { HalfFloatCon, T_SHORT, "hfcon:", false, Op_RegF, relocInfo::none }, // HalfFloatCon
117 { HalfFloatTop, T_SHORT, "short", false, Op_RegF, relocInfo::none }, // HalfFloatBot
118 { FloatBot, T_FLOAT, "float_top", false, Op_RegF, relocInfo::none }, // FloatTop
119 { FloatCon, T_FLOAT, "ftcon:", false, Op_RegF, relocInfo::none }, // FloatCon
120 { FloatTop, T_FLOAT, "float", false, Op_RegF, relocInfo::none }, // FloatBot
121 { DoubleBot, T_DOUBLE, "double_top", false, Op_RegD, relocInfo::none }, // DoubleTop
122 { DoubleCon, T_DOUBLE, "dblcon:", false, Op_RegD, relocInfo::none }, // DoubleCon
123 { DoubleTop, T_DOUBLE, "double", false, Op_RegD, relocInfo::none }, // DoubleBot
124 { Top, T_ILLEGAL, "bottom", false, 0, relocInfo::none } // Bottom
125 };
126
127 // Map ideal registers (machine types) to ideal types
128 const Type *Type::mreg2type[_last_machine_leaf];
129
130 // Map basic types to canonical Type* pointers.
131 const Type* Type:: _const_basic_type[T_CONFLICT+1];
132
133 // Map basic types to constant-zero Types.
134 const Type* Type:: _zero_type[T_CONFLICT+1];
135
136 // Map basic types to array-body alias types.
137 const TypeAryPtr* TypeAryPtr::_array_body_type[T_CONFLICT+1];
138 const TypeInterfaces* TypeAryPtr::_array_interfaces = nullptr;
139 const TypeInterfaces* TypeAryKlassPtr::_array_interfaces = nullptr;
140
141 //=============================================================================
142 // Convenience common pre-built types.
143 const Type *Type::ABIO; // State-of-machine only
144 const Type *Type::BOTTOM; // All values
145 const Type *Type::CONTROL; // Control only
146 const Type *Type::DOUBLE; // All doubles
147 const Type *Type::HALF_FLOAT; // All half floats
148 const Type *Type::FLOAT; // All floats
149 const Type *Type::HALF; // Placeholder half of doublewide type
150 const Type *Type::MEMORY; // Abstract store only
151 const Type *Type::RETURN_ADDRESS;
152 const Type *Type::TOP; // No values in set
153
154 //------------------------------get_const_type---------------------------
155 const Type* Type::get_const_type(ciType* type, InterfaceHandling interface_handling) {
156 if (type == nullptr) {
157 return nullptr;
158 } else if (type->is_primitive_type()) {
159 return get_const_basic_type(type->basic_type());
160 } else {
161 return TypeOopPtr::make_from_klass(type->as_klass(), interface_handling);
162 }
163 }
164
165 //---------------------------array_element_basic_type---------------------------------
166 // Mapping to the array element's basic type.
167 BasicType Type::array_element_basic_type() const {
168 BasicType bt = basic_type();
169 if (bt == T_INT) {
170 if (this == TypeInt::INT) return T_INT;
171 if (this == TypeInt::CHAR) return T_CHAR;
172 if (this == TypeInt::BYTE) return T_BYTE;
173 if (this == TypeInt::BOOL) return T_BOOLEAN;
174 if (this == TypeInt::SHORT) return T_SHORT;
175 return T_VOID;
176 }
177 return bt;
178 }
179
180 // For two instance arrays of same dimension, return the base element types.
181 // Otherwise or if the arrays have different dimensions, return null.
182 void Type::get_arrays_base_elements(const Type *a1, const Type *a2,
183 const TypeInstPtr **e1, const TypeInstPtr **e2) {
184
185 if (e1) *e1 = nullptr;
186 if (e2) *e2 = nullptr;
187 const TypeAryPtr* a1tap = (a1 == nullptr) ? nullptr : a1->isa_aryptr();
188 const TypeAryPtr* a2tap = (a2 == nullptr) ? nullptr : a2->isa_aryptr();
189
190 if (a1tap != nullptr && a2tap != nullptr) {
191 // Handle multidimensional arrays
192 const TypePtr* a1tp = a1tap->elem()->make_ptr();
193 const TypePtr* a2tp = a2tap->elem()->make_ptr();
194 while (a1tp && a1tp->isa_aryptr() && a2tp && a2tp->isa_aryptr()) {
195 a1tap = a1tp->is_aryptr();
196 a2tap = a2tp->is_aryptr();
197 a1tp = a1tap->elem()->make_ptr();
198 a2tp = a2tap->elem()->make_ptr();
199 }
200 if (a1tp && a1tp->isa_instptr() && a2tp && a2tp->isa_instptr()) {
201 if (e1) *e1 = a1tp->is_instptr();
202 if (e2) *e2 = a2tp->is_instptr();
203 }
204 }
205 }
206
207 //---------------------------get_typeflow_type---------------------------------
208 // Import a type produced by ciTypeFlow.
209 const Type* Type::get_typeflow_type(ciType* type) {
210 switch (type->basic_type()) {
211
212 case ciTypeFlow::StateVector::T_BOTTOM:
213 assert(type == ciTypeFlow::StateVector::bottom_type(), "");
214 return Type::BOTTOM;
215
216 case ciTypeFlow::StateVector::T_TOP:
217 assert(type == ciTypeFlow::StateVector::top_type(), "");
218 return Type::TOP;
219
220 case ciTypeFlow::StateVector::T_NULL:
221 assert(type == ciTypeFlow::StateVector::null_type(), "");
222 return TypePtr::NULL_PTR;
223
224 case ciTypeFlow::StateVector::T_LONG2:
225 // The ciTypeFlow pass pushes a long, then the half.
226 // We do the same.
227 assert(type == ciTypeFlow::StateVector::long2_type(), "");
228 return TypeInt::TOP;
229
230 case ciTypeFlow::StateVector::T_DOUBLE2:
231 // The ciTypeFlow pass pushes double, then the half.
232 // Our convention is the same.
233 assert(type == ciTypeFlow::StateVector::double2_type(), "");
234 return Type::TOP;
235
236 case T_ADDRESS:
237 assert(type->is_return_address(), "");
238 return TypeRawPtr::make((address)(intptr_t)type->as_return_address()->bci());
239
240 default:
241 // make sure we did not mix up the cases:
242 assert(type != ciTypeFlow::StateVector::bottom_type(), "");
243 assert(type != ciTypeFlow::StateVector::top_type(), "");
244 assert(type != ciTypeFlow::StateVector::null_type(), "");
245 assert(type != ciTypeFlow::StateVector::long2_type(), "");
246 assert(type != ciTypeFlow::StateVector::double2_type(), "");
247 assert(!type->is_return_address(), "");
248
249 return Type::get_const_type(type);
250 }
251 }
252
253
254 //-----------------------make_from_constant------------------------------------
255 const Type* Type::make_from_constant(ciConstant constant, bool require_constant,
256 int stable_dimension, bool is_narrow_oop,
257 bool is_autobox_cache) {
258 switch (constant.basic_type()) {
259 case T_BOOLEAN: return TypeInt::make(constant.as_boolean());
260 case T_CHAR: return TypeInt::make(constant.as_char());
261 case T_BYTE: return TypeInt::make(constant.as_byte());
262 case T_SHORT: return TypeInt::make(constant.as_short());
263 case T_INT: return TypeInt::make(constant.as_int());
264 case T_LONG: return TypeLong::make(constant.as_long());
265 case T_FLOAT: return TypeF::make(constant.as_float());
266 case T_DOUBLE: return TypeD::make(constant.as_double());
267 case T_ARRAY:
268 case T_OBJECT: {
269 const Type* con_type = nullptr;
270 ciObject* oop_constant = constant.as_object();
271 if (oop_constant->is_null_object()) {
272 con_type = Type::get_zero_type(T_OBJECT);
273 } else {
274 guarantee(require_constant || oop_constant->should_be_constant(), "con_type must get computed");
275 con_type = TypeOopPtr::make_from_constant(oop_constant, require_constant);
276 if (Compile::current()->eliminate_boxing() && is_autobox_cache) {
277 con_type = con_type->is_aryptr()->cast_to_autobox_cache();
278 }
279 if (stable_dimension > 0) {
280 assert(FoldStableValues, "sanity");
281 assert(!con_type->is_zero_type(), "default value for stable field");
282 con_type = con_type->is_aryptr()->cast_to_stable(true, stable_dimension);
283 }
284 }
285 if (is_narrow_oop) {
286 con_type = con_type->make_narrowoop();
287 }
288 return con_type;
289 }
290 case T_ILLEGAL:
291 // Invalid ciConstant returned due to OutOfMemoryError in the CI
292 assert(Compile::current()->env()->failing(), "otherwise should not see this");
293 return nullptr;
294 default:
295 // Fall through to failure
296 return nullptr;
297 }
298 }
299
300 static ciConstant check_mismatched_access(ciConstant con, BasicType loadbt, bool is_unsigned) {
301 BasicType conbt = con.basic_type();
302 switch (conbt) {
303 case T_BOOLEAN: conbt = T_BYTE; break;
304 case T_ARRAY: conbt = T_OBJECT; break;
305 default: break;
306 }
307 switch (loadbt) {
308 case T_BOOLEAN: loadbt = T_BYTE; break;
309 case T_NARROWOOP: loadbt = T_OBJECT; break;
310 case T_ARRAY: loadbt = T_OBJECT; break;
311 case T_ADDRESS: loadbt = T_OBJECT; break;
312 default: break;
313 }
314 if (conbt == loadbt) {
315 if (is_unsigned && conbt == T_BYTE) {
316 // LoadB (T_BYTE) with a small mask (<=8-bit) is converted to LoadUB (T_BYTE).
317 return ciConstant(T_INT, con.as_int() & 0xFF);
318 } else {
319 return con;
320 }
321 }
322 if (conbt == T_SHORT && loadbt == T_CHAR) {
323 // LoadS (T_SHORT) with a small mask (<=16-bit) is converted to LoadUS (T_CHAR).
324 return ciConstant(T_INT, con.as_int() & 0xFFFF);
325 }
326 return ciConstant(); // T_ILLEGAL
327 }
328
329 // Try to constant-fold a stable array element.
330 const Type* Type::make_constant_from_array_element(ciArray* array, int off, int stable_dimension,
331 BasicType loadbt, bool is_unsigned_load) {
332 // Decode the results of GraphKit::array_element_address.
333 ciConstant element_value = array->element_value_by_offset(off);
334 if (element_value.basic_type() == T_ILLEGAL) {
335 return nullptr; // wrong offset
336 }
337 ciConstant con = check_mismatched_access(element_value, loadbt, is_unsigned_load);
338
339 assert(con.basic_type() != T_ILLEGAL, "elembt=%s; loadbt=%s; unsigned=%d",
340 type2name(element_value.basic_type()), type2name(loadbt), is_unsigned_load);
341
342 if (con.is_valid() && // not a mismatched access
343 !con.is_null_or_zero()) { // not a default value
344 bool is_narrow_oop = (loadbt == T_NARROWOOP);
345 return Type::make_from_constant(con, /*require_constant=*/true, stable_dimension, is_narrow_oop, /*is_autobox_cache=*/false);
346 }
347 return nullptr;
348 }
349
350 const Type* Type::make_constant_from_field(ciInstance* holder, int off, bool is_unsigned_load, BasicType loadbt) {
351 ciField* field;
352 ciType* type = holder->java_mirror_type();
353 if (type != nullptr && type->is_instance_klass() && off >= InstanceMirrorKlass::offset_of_static_fields()) {
354 // Static field
355 field = type->as_instance_klass()->get_field_by_offset(off, /*is_static=*/true);
356 } else {
357 // Instance field
358 field = holder->klass()->as_instance_klass()->get_field_by_offset(off, /*is_static=*/false);
359 }
360 if (field == nullptr) {
361 return nullptr; // Wrong offset
362 }
363 return Type::make_constant_from_field(field, holder, loadbt, is_unsigned_load);
364 }
365
366 const Type* Type::make_constant_from_field(ciField* field, ciInstance* holder,
367 BasicType loadbt, bool is_unsigned_load) {
368 if (!field->is_constant()) {
369 return nullptr; // Non-constant field
370 }
371 ciConstant field_value;
372 if (field->is_static()) {
373 // final static field
374 field_value = field->constant_value();
375 } else if (holder != nullptr) {
376 // final or stable non-static field
377 // Treat final non-static fields of trusted classes (classes in
378 // java.lang.invoke and sun.invoke packages and subpackages) as
379 // compile time constants.
380 field_value = field->constant_value_of(holder);
381 }
382 if (!field_value.is_valid()) {
383 return nullptr; // Not a constant
384 }
385
386 ciConstant con = check_mismatched_access(field_value, loadbt, is_unsigned_load);
387
388 assert(con.is_valid(), "elembt=%s; loadbt=%s; unsigned=%d",
389 type2name(field_value.basic_type()), type2name(loadbt), is_unsigned_load);
390
391 bool is_stable_array = FoldStableValues && field->is_stable() && field->type()->is_array_klass();
392 int stable_dimension = (is_stable_array ? field->type()->as_array_klass()->dimension() : 0);
393 bool is_narrow_oop = (loadbt == T_NARROWOOP);
394
395 const Type* con_type = make_from_constant(con, /*require_constant=*/ true,
396 stable_dimension, is_narrow_oop,
397 field->is_autobox_cache());
398 if (con_type != nullptr && field->is_call_site_target()) {
399 ciCallSite* call_site = holder->as_call_site();
400 if (!call_site->is_fully_initialized_constant_call_site()) {
401 ciMethodHandle* target = con.as_object()->as_method_handle();
402 Compile::current()->dependencies()->assert_call_site_target_value(call_site, target);
403 }
404 }
405 return con_type;
406 }
407
408 //------------------------------make-------------------------------------------
409 // Create a simple Type, with default empty symbol sets. Then hashcons it
410 // and look for an existing copy in the type dictionary.
411 const Type *Type::make( enum TYPES t ) {
412 return (new Type(t))->hashcons();
413 }
414
415 //------------------------------cmp--------------------------------------------
416 bool Type::equals(const Type* t1, const Type* t2) {
417 if (t1->_base != t2->_base) {
418 return false; // Missed badly
419 }
420
421 assert(t1 != t2 || t1->eq(t2), "eq must be reflexive");
422 return t1->eq(t2);
423 }
424
425 const Type* Type::maybe_remove_speculative(bool include_speculative) const {
426 if (!include_speculative) {
427 return remove_speculative();
428 }
429 return this;
430 }
431
432 //------------------------------hash-------------------------------------------
433 int Type::uhash( const Type *const t ) {
434 return (int)t->hash();
435 }
436
437 #define POSITIVE_INFINITE_F 0x7f800000 // hex representation for IEEE 754 single precision positive infinite
438 #define POSITIVE_INFINITE_D 0x7ff0000000000000 // hex representation for IEEE 754 double precision positive infinite
439
440 //--------------------------Initialize_shared----------------------------------
441 void Type::Initialize_shared(Compile* current) {
442 // This method does not need to be locked because the first system
443 // compilations (stub compilations) occur serially. If they are
444 // changed to proceed in parallel, then this section will need
445 // locking.
446
447 Arena* save = current->type_arena();
448 Arena* shared_type_arena = new (mtCompiler)Arena(mtCompiler, Arena::Tag::tag_type);
449
450 current->set_type_arena(shared_type_arena);
451
452 // Map the boolean result of Type::equals into a comparator result that CmpKey expects.
453 CmpKey type_cmp = [](const void* t1, const void* t2) -> int32_t {
454 return Type::equals((Type*) t1, (Type*) t2) ? 0 : 1;
455 };
456
457 _shared_type_dict = new (shared_type_arena) Dict(type_cmp, (Hash) Type::uhash, shared_type_arena, 128);
458 current->set_type_dict(_shared_type_dict);
459
460 // Make shared pre-built types.
461 CONTROL = make(Control); // Control only
462 TOP = make(Top); // No values in set
463 MEMORY = make(Memory); // Abstract store only
464 ABIO = make(Abio); // State-of-machine only
465 RETURN_ADDRESS=make(Return_Address);
466 FLOAT = make(FloatBot); // All floats
467 HALF_FLOAT = make(HalfFloatBot); // All half floats
468 DOUBLE = make(DoubleBot); // All doubles
469 BOTTOM = make(Bottom); // Everything
470 HALF = make(Half); // Placeholder half of doublewide type
471
472 TypeF::MAX = TypeF::make(max_jfloat); // Float MAX
473 TypeF::MIN = TypeF::make(min_jfloat); // Float MIN
474 TypeF::ZERO = TypeF::make(0.0); // Float 0 (positive zero)
475 TypeF::ONE = TypeF::make(1.0); // Float 1
476 TypeF::POS_INF = TypeF::make(jfloat_cast(POSITIVE_INFINITE_F));
477 TypeF::NEG_INF = TypeF::make(-jfloat_cast(POSITIVE_INFINITE_F));
478
479 TypeH::MAX = TypeH::make(max_jfloat16); // HalfFloat MAX
480 TypeH::MIN = TypeH::make(min_jfloat16); // HalfFloat MIN
481 TypeH::ZERO = TypeH::make((jshort)0); // HalfFloat 0 (positive zero)
482 TypeH::ONE = TypeH::make(one_jfloat16); // HalfFloat 1
483 TypeH::POS_INF = TypeH::make(pos_inf_jfloat16);
484 TypeH::NEG_INF = TypeH::make(neg_inf_jfloat16);
485
486 TypeD::MAX = TypeD::make(max_jdouble); // Double MAX
487 TypeD::MIN = TypeD::make(min_jdouble); // Double MIN
488 TypeD::ZERO = TypeD::make(0.0); // Double 0 (positive zero)
489 TypeD::ONE = TypeD::make(1.0); // Double 1
490 TypeD::POS_INF = TypeD::make(jdouble_cast(POSITIVE_INFINITE_D));
491 TypeD::NEG_INF = TypeD::make(-jdouble_cast(POSITIVE_INFINITE_D));
492
493 TypeInt::MAX = TypeInt::make(max_jint); // Int MAX
494 TypeInt::MIN = TypeInt::make(min_jint); // Int MIN
495 TypeInt::MINUS_1 = TypeInt::make(-1); // -1
496 TypeInt::ZERO = TypeInt::make( 0); // 0
497 TypeInt::ONE = TypeInt::make( 1); // 1
498 TypeInt::BOOL = TypeInt::make( 0, 1, WidenMin); // 0 or 1, FALSE or TRUE.
499 TypeInt::CC = TypeInt::make(-1, 1, WidenMin); // -1, 0 or 1, condition codes
500 TypeInt::CC_LT = TypeInt::make(-1,-1, WidenMin); // == TypeInt::MINUS_1
501 TypeInt::CC_GT = TypeInt::make( 1, 1, WidenMin); // == TypeInt::ONE
502 TypeInt::CC_EQ = TypeInt::make( 0, 0, WidenMin); // == TypeInt::ZERO
503 TypeInt::CC_NE = TypeInt::make_or_top(TypeIntPrototype<jint, juint>{{-1, 1}, {1, max_juint}, {0, 1}}, WidenMin)->is_int();
504 TypeInt::CC_LE = TypeInt::make(-1, 0, WidenMin);
505 TypeInt::CC_GE = TypeInt::make( 0, 1, WidenMin); // == TypeInt::BOOL
506 TypeInt::BYTE = TypeInt::make(-128, 127, WidenMin); // Bytes
507 TypeInt::UBYTE = TypeInt::make(0, 255, WidenMin); // Unsigned Bytes
508 TypeInt::CHAR = TypeInt::make(0, 65535, WidenMin); // Java chars
509 TypeInt::SHORT = TypeInt::make(-32768, 32767, WidenMin); // Java shorts
510 TypeInt::NON_ZERO = TypeInt::make_or_top(TypeIntPrototype<jint, juint>{{min_jint, max_jint}, {1, max_juint}, {0, 0}}, WidenMin)->is_int();
511 TypeInt::POS = TypeInt::make(0, max_jint, WidenMin); // Non-neg values
512 TypeInt::POS1 = TypeInt::make(1, max_jint, WidenMin); // Positive values
513 TypeInt::INT = TypeInt::make(min_jint, max_jint, WidenMax); // 32-bit integers
514 TypeInt::SYMINT = TypeInt::make(-max_jint, max_jint, WidenMin); // symmetric range
515 TypeInt::TYPE_DOMAIN = TypeInt::INT;
516 // CmpL is overloaded both as the bytecode computation returning
517 // a trinary (-1, 0, +1) integer result AND as an efficient long
518 // compare returning optimizer ideal-type flags.
519 assert(TypeInt::CC_LT == TypeInt::MINUS_1, "types must match for CmpL to work" );
520 assert(TypeInt::CC_GT == TypeInt::ONE, "types must match for CmpL to work" );
521 assert(TypeInt::CC_EQ == TypeInt::ZERO, "types must match for CmpL to work" );
522 assert(TypeInt::CC_GE == TypeInt::BOOL, "types must match for CmpL to work" );
523
524 TypeLong::MAX = TypeLong::make(max_jlong); // Long MAX
525 TypeLong::MIN = TypeLong::make(min_jlong); // Long MIN
526 TypeLong::MINUS_1 = TypeLong::make(-1); // -1
527 TypeLong::ZERO = TypeLong::make( 0); // 0
528 TypeLong::ONE = TypeLong::make( 1); // 1
529 TypeLong::NON_ZERO = TypeLong::make_or_top(TypeIntPrototype<jlong, julong>{{min_jlong, max_jlong}, {1, max_julong}, {0, 0}}, WidenMin)->is_long();
530 TypeLong::POS = TypeLong::make(0, max_jlong, WidenMin); // Non-neg values
531 TypeLong::NEG = TypeLong::make(min_jlong, -1, WidenMin);
532 TypeLong::LONG = TypeLong::make(min_jlong, max_jlong, WidenMax); // 64-bit integers
533 TypeLong::INT = TypeLong::make((jlong)min_jint, (jlong)max_jint,WidenMin);
534 TypeLong::UINT = TypeLong::make(0, (jlong)max_juint, WidenMin);
535 TypeLong::TYPE_DOMAIN = TypeLong::LONG;
536
537 const Type **fboth =(const Type**)shared_type_arena->AmallocWords(2*sizeof(Type*));
538 fboth[0] = Type::CONTROL;
539 fboth[1] = Type::CONTROL;
540 TypeTuple::IFBOTH = TypeTuple::make( 2, fboth );
541
542 const Type **ffalse =(const Type**)shared_type_arena->AmallocWords(2*sizeof(Type*));
543 ffalse[0] = Type::CONTROL;
544 ffalse[1] = Type::TOP;
545 TypeTuple::IFFALSE = TypeTuple::make( 2, ffalse );
546
547 const Type **fneither =(const Type**)shared_type_arena->AmallocWords(2*sizeof(Type*));
548 fneither[0] = Type::TOP;
549 fneither[1] = Type::TOP;
550 TypeTuple::IFNEITHER = TypeTuple::make( 2, fneither );
551
552 const Type **ftrue =(const Type**)shared_type_arena->AmallocWords(2*sizeof(Type*));
553 ftrue[0] = Type::TOP;
554 ftrue[1] = Type::CONTROL;
555 TypeTuple::IFTRUE = TypeTuple::make( 2, ftrue );
556
557 const Type **floop =(const Type**)shared_type_arena->AmallocWords(2*sizeof(Type*));
558 floop[0] = Type::CONTROL;
559 floop[1] = TypeInt::INT;
560 TypeTuple::LOOPBODY = TypeTuple::make( 2, floop );
561
562 TypePtr::NULL_PTR= TypePtr::make(AnyPtr, TypePtr::Null, 0);
563 TypePtr::NOTNULL = TypePtr::make(AnyPtr, TypePtr::NotNull, OffsetBot);
564 TypePtr::BOTTOM = TypePtr::make(AnyPtr, TypePtr::BotPTR, OffsetBot);
565
566 TypeRawPtr::BOTTOM = TypeRawPtr::make( TypePtr::BotPTR );
567 TypeRawPtr::NOTNULL= TypeRawPtr::make( TypePtr::NotNull );
568
569 const Type **fmembar = TypeTuple::fields(0);
570 TypeTuple::MEMBAR = TypeTuple::make(TypeFunc::Parms+0, fmembar);
571
572 const Type **fsc = (const Type**)shared_type_arena->AmallocWords(2*sizeof(Type*));
573 fsc[0] = TypeInt::CC;
574 fsc[1] = Type::MEMORY;
575 TypeTuple::STORECONDITIONAL = TypeTuple::make(2, fsc);
576
577 TypeInstPtr::NOTNULL = TypeInstPtr::make(TypePtr::NotNull, current->env()->Object_klass());
578 TypeInstPtr::BOTTOM = TypeInstPtr::make(TypePtr::BotPTR, current->env()->Object_klass());
579 TypeInstPtr::MIRROR = TypeInstPtr::make(TypePtr::NotNull, current->env()->Class_klass());
580 TypeInstPtr::MARK = TypeInstPtr::make(TypePtr::BotPTR, current->env()->Object_klass(),
581 false, nullptr, oopDesc::mark_offset_in_bytes());
582 TypeInstPtr::KLASS = TypeInstPtr::make(TypePtr::BotPTR, current->env()->Object_klass(),
583 false, nullptr, Type::klass_offset());
584 TypeOopPtr::BOTTOM = TypeOopPtr::make(TypePtr::BotPTR, OffsetBot, TypeOopPtr::InstanceBot);
585
586 TypeMetadataPtr::BOTTOM = TypeMetadataPtr::make(TypePtr::BotPTR, nullptr, OffsetBot);
587
588 TypeNarrowOop::NULL_PTR = TypeNarrowOop::make( TypePtr::NULL_PTR );
589 TypeNarrowOop::BOTTOM = TypeNarrowOop::make( TypeInstPtr::BOTTOM );
590
591 TypeNarrowKlass::NULL_PTR = TypeNarrowKlass::make( TypePtr::NULL_PTR );
592
593 mreg2type[Op_Node] = Type::BOTTOM;
594 mreg2type[Op_Set ] = nullptr;
595 mreg2type[Op_RegN] = TypeNarrowOop::BOTTOM;
596 mreg2type[Op_RegI] = TypeInt::INT;
597 mreg2type[Op_RegP] = TypePtr::BOTTOM;
598 mreg2type[Op_RegF] = Type::FLOAT;
599 mreg2type[Op_RegD] = Type::DOUBLE;
600 mreg2type[Op_RegL] = TypeLong::LONG;
601 mreg2type[Op_RegFlags] = TypeInt::CC;
602
603 GrowableArray<ciInstanceKlass*> array_interfaces;
604 array_interfaces.push(current->env()->Cloneable_klass());
605 array_interfaces.push(current->env()->Serializable_klass());
606 TypeAryPtr::_array_interfaces = TypeInterfaces::make(&array_interfaces);
607 TypeAryKlassPtr::_array_interfaces = TypeAryPtr::_array_interfaces;
608
609 TypeAryPtr::BOTTOM = TypeAryPtr::make(TypePtr::BotPTR, TypeAry::make(Type::BOTTOM, TypeInt::POS), nullptr, false, Type::OffsetBot);
610 TypeAryPtr::RANGE = TypeAryPtr::make( TypePtr::BotPTR, TypeAry::make(Type::BOTTOM,TypeInt::POS), nullptr /* current->env()->Object_klass() */, false, arrayOopDesc::length_offset_in_bytes());
611
612 TypeAryPtr::NARROWOOPS = TypeAryPtr::make(TypePtr::BotPTR, TypeAry::make(TypeNarrowOop::BOTTOM, TypeInt::POS), nullptr /*ciArrayKlass::make(o)*/, false, Type::OffsetBot);
613
614 #ifdef _LP64
615 if (UseCompressedOops) {
616 assert(TypeAryPtr::NARROWOOPS->is_ptr_to_narrowoop(), "array of narrow oops must be ptr to narrow oop");
617 TypeAryPtr::OOPS = TypeAryPtr::NARROWOOPS;
618 } else
619 #endif
620 {
621 // There is no shared klass for Object[]. See note in TypeAryPtr::klass().
622 TypeAryPtr::OOPS = TypeAryPtr::make(TypePtr::BotPTR, TypeAry::make(TypeInstPtr::BOTTOM,TypeInt::POS), nullptr /*ciArrayKlass::make(o)*/, false, Type::OffsetBot);
623 }
624 TypeAryPtr::BYTES = TypeAryPtr::make(TypePtr::BotPTR, TypeAry::make(TypeInt::BYTE ,TypeInt::POS), ciTypeArrayKlass::make(T_BYTE), true, Type::OffsetBot);
625 TypeAryPtr::SHORTS = TypeAryPtr::make(TypePtr::BotPTR, TypeAry::make(TypeInt::SHORT ,TypeInt::POS), ciTypeArrayKlass::make(T_SHORT), true, Type::OffsetBot);
626 TypeAryPtr::CHARS = TypeAryPtr::make(TypePtr::BotPTR, TypeAry::make(TypeInt::CHAR ,TypeInt::POS), ciTypeArrayKlass::make(T_CHAR), true, Type::OffsetBot);
627 TypeAryPtr::INTS = TypeAryPtr::make(TypePtr::BotPTR, TypeAry::make(TypeInt::INT ,TypeInt::POS), ciTypeArrayKlass::make(T_INT), true, Type::OffsetBot);
628 TypeAryPtr::LONGS = TypeAryPtr::make(TypePtr::BotPTR, TypeAry::make(TypeLong::LONG ,TypeInt::POS), ciTypeArrayKlass::make(T_LONG), true, Type::OffsetBot);
629 TypeAryPtr::FLOATS = TypeAryPtr::make(TypePtr::BotPTR, TypeAry::make(Type::FLOAT ,TypeInt::POS), ciTypeArrayKlass::make(T_FLOAT), true, Type::OffsetBot);
630 TypeAryPtr::DOUBLES = TypeAryPtr::make(TypePtr::BotPTR, TypeAry::make(Type::DOUBLE ,TypeInt::POS), ciTypeArrayKlass::make(T_DOUBLE), true, Type::OffsetBot);
631
632 // Nobody should ask _array_body_type[T_NARROWOOP]. Use null as assert.
633 TypeAryPtr::_array_body_type[T_NARROWOOP] = nullptr;
634 TypeAryPtr::_array_body_type[T_OBJECT] = TypeAryPtr::OOPS;
635 TypeAryPtr::_array_body_type[T_ARRAY] = TypeAryPtr::OOPS; // arrays are stored in oop arrays
636 TypeAryPtr::_array_body_type[T_BYTE] = TypeAryPtr::BYTES;
637 TypeAryPtr::_array_body_type[T_BOOLEAN] = TypeAryPtr::BYTES; // boolean[] is a byte array
638 TypeAryPtr::_array_body_type[T_SHORT] = TypeAryPtr::SHORTS;
639 TypeAryPtr::_array_body_type[T_CHAR] = TypeAryPtr::CHARS;
640 TypeAryPtr::_array_body_type[T_INT] = TypeAryPtr::INTS;
641 TypeAryPtr::_array_body_type[T_LONG] = TypeAryPtr::LONGS;
642 TypeAryPtr::_array_body_type[T_FLOAT] = TypeAryPtr::FLOATS;
643 TypeAryPtr::_array_body_type[T_DOUBLE] = TypeAryPtr::DOUBLES;
644
645 TypeInstKlassPtr::OBJECT = TypeInstKlassPtr::make(TypePtr::NotNull, current->env()->Object_klass(), 0);
646 TypeInstKlassPtr::OBJECT_OR_NULL = TypeInstKlassPtr::make(TypePtr::BotPTR, current->env()->Object_klass(), 0);
647
648 const Type **fi2c = TypeTuple::fields(2);
649 fi2c[TypeFunc::Parms+0] = TypeInstPtr::BOTTOM; // Method*
650 fi2c[TypeFunc::Parms+1] = TypeRawPtr::BOTTOM; // argument pointer
651 TypeTuple::START_I2C = TypeTuple::make(TypeFunc::Parms+2, fi2c);
652
653 const Type **intpair = TypeTuple::fields(2);
654 intpair[0] = TypeInt::INT;
655 intpair[1] = TypeInt::INT;
656 TypeTuple::INT_PAIR = TypeTuple::make(2, intpair);
657
658 const Type **longpair = TypeTuple::fields(2);
659 longpair[0] = TypeLong::LONG;
660 longpair[1] = TypeLong::LONG;
661 TypeTuple::LONG_PAIR = TypeTuple::make(2, longpair);
662
663 const Type **intccpair = TypeTuple::fields(2);
664 intccpair[0] = TypeInt::INT;
665 intccpair[1] = TypeInt::CC;
666 TypeTuple::INT_CC_PAIR = TypeTuple::make(2, intccpair);
667
668 const Type **longccpair = TypeTuple::fields(2);
669 longccpair[0] = TypeLong::LONG;
670 longccpair[1] = TypeInt::CC;
671 TypeTuple::LONG_CC_PAIR = TypeTuple::make(2, longccpair);
672
673 _const_basic_type[T_NARROWOOP] = TypeNarrowOop::BOTTOM;
674 _const_basic_type[T_NARROWKLASS] = Type::BOTTOM;
675 _const_basic_type[T_BOOLEAN] = TypeInt::BOOL;
676 _const_basic_type[T_CHAR] = TypeInt::CHAR;
677 _const_basic_type[T_BYTE] = TypeInt::BYTE;
678 _const_basic_type[T_SHORT] = TypeInt::SHORT;
679 _const_basic_type[T_INT] = TypeInt::INT;
680 _const_basic_type[T_LONG] = TypeLong::LONG;
681 _const_basic_type[T_FLOAT] = Type::FLOAT;
682 _const_basic_type[T_DOUBLE] = Type::DOUBLE;
683 _const_basic_type[T_OBJECT] = TypeInstPtr::BOTTOM;
684 _const_basic_type[T_ARRAY] = TypeInstPtr::BOTTOM; // there is no separate bottom for arrays
685 _const_basic_type[T_VOID] = TypePtr::NULL_PTR; // reflection represents void this way
686 _const_basic_type[T_ADDRESS] = TypeRawPtr::BOTTOM; // both interpreter return addresses & random raw ptrs
687 _const_basic_type[T_CONFLICT] = Type::BOTTOM; // why not?
688
689 _zero_type[T_NARROWOOP] = TypeNarrowOop::NULL_PTR;
690 _zero_type[T_NARROWKLASS] = TypeNarrowKlass::NULL_PTR;
691 _zero_type[T_BOOLEAN] = TypeInt::ZERO; // false == 0
692 _zero_type[T_CHAR] = TypeInt::ZERO; // '\0' == 0
693 _zero_type[T_BYTE] = TypeInt::ZERO; // 0x00 == 0
694 _zero_type[T_SHORT] = TypeInt::ZERO; // 0x0000 == 0
695 _zero_type[T_INT] = TypeInt::ZERO;
696 _zero_type[T_LONG] = TypeLong::ZERO;
697 _zero_type[T_FLOAT] = TypeF::ZERO;
698 _zero_type[T_DOUBLE] = TypeD::ZERO;
699 _zero_type[T_OBJECT] = TypePtr::NULL_PTR;
700 _zero_type[T_ARRAY] = TypePtr::NULL_PTR; // null array is null oop
701 _zero_type[T_ADDRESS] = TypePtr::NULL_PTR; // raw pointers use the same null
702 _zero_type[T_VOID] = Type::TOP; // the only void value is no value at all
703
704 // get_zero_type() should not happen for T_CONFLICT
705 _zero_type[T_CONFLICT]= nullptr;
706
707 TypeVect::VECTMASK = (TypeVect*)(new TypePVectMask(T_BOOLEAN, MaxVectorSize))->hashcons();
708 mreg2type[Op_RegVectMask] = TypeVect::VECTMASK;
709
710 if (Matcher::supports_scalable_vector()) {
711 TypeVect::VECTA = TypeVect::make(T_BYTE, Matcher::scalable_vector_reg_size(T_BYTE));
712 }
713
714 // Vector predefined types, it needs initialized _const_basic_type[].
715 if (Matcher::vector_size_supported(T_BYTE, 4)) {
716 TypeVect::VECTS = TypeVect::make(T_BYTE, 4);
717 }
718 if (Matcher::vector_size_supported(T_FLOAT, 2)) {
719 TypeVect::VECTD = TypeVect::make(T_FLOAT, 2);
720 }
721 if (Matcher::vector_size_supported(T_FLOAT, 4)) {
722 TypeVect::VECTX = TypeVect::make(T_FLOAT, 4);
723 }
724 if (Matcher::vector_size_supported(T_FLOAT, 8)) {
725 TypeVect::VECTY = TypeVect::make(T_FLOAT, 8);
726 }
727 if (Matcher::vector_size_supported(T_FLOAT, 16)) {
728 TypeVect::VECTZ = TypeVect::make(T_FLOAT, 16);
729 }
730
731 mreg2type[Op_VecA] = TypeVect::VECTA;
732 mreg2type[Op_VecS] = TypeVect::VECTS;
733 mreg2type[Op_VecD] = TypeVect::VECTD;
734 mreg2type[Op_VecX] = TypeVect::VECTX;
735 mreg2type[Op_VecY] = TypeVect::VECTY;
736 mreg2type[Op_VecZ] = TypeVect::VECTZ;
737
738 #if INCLUDE_SHENANDOAHGC
739 ShenandoahBarrierSetC2::init();
740 #endif //INCLUDE_SHENANDOAHGC
741
742 BarrierSetC2::make_clone_type();
743 LockNode::initialize_lock_Type();
744 ArrayCopyNode::initialize_arraycopy_Type();
745 OptoRuntime::initialize_types();
746
747 // Restore working type arena.
748 current->set_type_arena(save);
749 current->set_type_dict(nullptr);
750 }
751
752 //------------------------------Initialize-------------------------------------
753 void Type::Initialize(Compile* current) {
754 assert(current->type_arena() != nullptr, "must have created type arena");
755
756 if (_shared_type_dict == nullptr) {
757 Initialize_shared(current);
758 }
759
760 Arena* type_arena = current->type_arena();
761
762 // Create the hash-cons'ing dictionary with top-level storage allocation
763 Dict *tdic = new (type_arena) Dict(*_shared_type_dict, type_arena);
764 current->set_type_dict(tdic);
765 }
766
767 //------------------------------hashcons---------------------------------------
768 // Do the hash-cons trick. If the Type already exists in the type table,
769 // delete the current Type and return the existing Type. Otherwise stick the
770 // current Type in the Type table.
771 const Type *Type::hashcons(void) {
772 DEBUG_ONLY(base()); // Check the assertion in Type::base().
773 // Look up the Type in the Type dictionary
774 Dict *tdic = type_dict();
775 Type* old = (Type*)(tdic->Insert(this, this, false));
776 if( old ) { // Pre-existing Type?
777 if( old != this ) // Yes, this guy is not the pre-existing?
778 delete this; // Yes, Nuke this guy
779 assert( old->_dual, "" );
780 return old; // Return pre-existing
781 }
782
783 // Every type has a dual (to make my lattice symmetric).
784 // Since we just discovered a new Type, compute its dual right now.
785 assert( !_dual, "" ); // No dual yet
786 _dual = xdual(); // Compute the dual
787 if (equals(this, _dual)) { // Handle self-symmetric
788 if (_dual != this) {
789 delete _dual;
790 _dual = this;
791 }
792 return this;
793 }
794 assert( !_dual->_dual, "" ); // No reverse dual yet
795 assert( !(*tdic)[_dual], "" ); // Dual not in type system either
796 // New Type, insert into Type table
797 tdic->Insert((void*)_dual,(void*)_dual);
798 ((Type*)_dual)->_dual = this; // Finish up being symmetric
799 #ifdef ASSERT
800 Type *dual_dual = (Type*)_dual->xdual();
801 assert( eq(dual_dual), "xdual(xdual()) should be identity" );
802 delete dual_dual;
803 #endif
804 return this; // Return new Type
805 }
806
807 //------------------------------eq---------------------------------------------
808 // Structural equality check for Type representations
809 bool Type::eq( const Type * ) const {
810 return true; // Nothing else can go wrong
811 }
812
813 //------------------------------hash-------------------------------------------
814 // Type-specific hashing function.
815 uint Type::hash(void) const {
816 return _base;
817 }
818
819 //------------------------------is_finite--------------------------------------
820 // Has a finite value
821 bool Type::is_finite() const {
822 return false;
823 }
824
825 //------------------------------is_nan-----------------------------------------
826 // Is not a number (NaN)
827 bool Type::is_nan() const {
828 return false;
829 }
830
831 #ifdef ASSERT
832 class VerifyMeet;
833 class VerifyMeetResult : public ArenaObj {
834 friend class VerifyMeet;
835 friend class Type;
836 private:
837 class VerifyMeetResultEntry {
838 private:
839 const Type* _in1;
840 const Type* _in2;
841 const Type* _res;
842 public:
843 VerifyMeetResultEntry(const Type* in1, const Type* in2, const Type* res):
844 _in1(in1), _in2(in2), _res(res) {
845 }
846 VerifyMeetResultEntry():
847 _in1(nullptr), _in2(nullptr), _res(nullptr) {
848 }
849
850 bool operator==(const VerifyMeetResultEntry& rhs) const {
851 return _in1 == rhs._in1 &&
852 _in2 == rhs._in2 &&
853 _res == rhs._res;
854 }
855
856 bool operator!=(const VerifyMeetResultEntry& rhs) const {
857 return !(rhs == *this);
858 }
859
860 static int compare(const VerifyMeetResultEntry& v1, const VerifyMeetResultEntry& v2) {
861 if ((intptr_t) v1._in1 < (intptr_t) v2._in1) {
862 return -1;
863 } else if (v1._in1 == v2._in1) {
864 if ((intptr_t) v1._in2 < (intptr_t) v2._in2) {
865 return -1;
866 } else if (v1._in2 == v2._in2) {
867 assert(v1._res == v2._res || v1._res == nullptr || v2._res == nullptr, "same inputs should lead to same result");
868 return 0;
869 }
870 return 1;
871 }
872 return 1;
873 }
874 const Type* res() const { return _res; }
875 };
876 uint _depth;
877 GrowableArray<VerifyMeetResultEntry> _cache;
878
879 // With verification code, the meet of A and B causes the computation of:
880 // 1- meet(A, B)
881 // 2- meet(B, A)
882 // 3- meet(dual(meet(A, B)), dual(A))
883 // 4- meet(dual(meet(A, B)), dual(B))
884 // 5- meet(dual(A), dual(B))
885 // 6- meet(dual(B), dual(A))
886 // 7- meet(dual(meet(dual(A), dual(B))), A)
887 // 8- meet(dual(meet(dual(A), dual(B))), B)
888 //
889 // In addition the meet of A[] and B[] requires the computation of the meet of A and B.
890 //
891 // The meet of A[] and B[] triggers the computation of:
892 // 1- meet(A[], B[][)
893 // 1.1- meet(A, B)
894 // 1.2- meet(B, A)
895 // 1.3- meet(dual(meet(A, B)), dual(A))
896 // 1.4- meet(dual(meet(A, B)), dual(B))
897 // 1.5- meet(dual(A), dual(B))
898 // 1.6- meet(dual(B), dual(A))
899 // 1.7- meet(dual(meet(dual(A), dual(B))), A)
900 // 1.8- meet(dual(meet(dual(A), dual(B))), B)
901 // 2- meet(B[], A[])
902 // 2.1- meet(B, A) = 1.2
903 // 2.2- meet(A, B) = 1.1
904 // 2.3- meet(dual(meet(B, A)), dual(B)) = 1.4
905 // 2.4- meet(dual(meet(B, A)), dual(A)) = 1.3
906 // 2.5- meet(dual(B), dual(A)) = 1.6
907 // 2.6- meet(dual(A), dual(B)) = 1.5
908 // 2.7- meet(dual(meet(dual(B), dual(A))), B) = 1.8
909 // 2.8- meet(dual(meet(dual(B), dual(A))), B) = 1.7
910 // etc.
911 // The number of meet operations performed grows exponentially with the number of dimensions of the arrays but the number
912 // of different meet operations is linear in the number of dimensions. The function below caches meet results for the
913 // duration of the meet at the root of the recursive calls.
914 //
915 const Type* meet(const Type* t1, const Type* t2) {
916 bool found = false;
917 const VerifyMeetResultEntry meet(t1, t2, nullptr);
918 int pos = _cache.find_sorted<VerifyMeetResultEntry, VerifyMeetResultEntry::compare>(meet, found);
919 const Type* res = nullptr;
920 if (found) {
921 res = _cache.at(pos).res();
922 } else {
923 res = t1->xmeet(t2);
924 _cache.insert_sorted<VerifyMeetResultEntry::compare>(VerifyMeetResultEntry(t1, t2, res));
925 found = false;
926 _cache.find_sorted<VerifyMeetResultEntry, VerifyMeetResultEntry::compare>(meet, found);
927 assert(found, "should be in table after it's added");
928 }
929 return res;
930 }
931
932 void add(const Type* t1, const Type* t2, const Type* res) {
933 _cache.insert_sorted<VerifyMeetResultEntry::compare>(VerifyMeetResultEntry(t1, t2, res));
934 }
935
936 bool empty_cache() const {
937 return _cache.length() == 0;
938 }
939 public:
940 VerifyMeetResult(Compile* C) :
941 _depth(0), _cache(C->comp_arena(), 2, 0, VerifyMeetResultEntry()) {
942 }
943 };
944
945 void Type::assert_type_verify_empty() const {
946 assert(Compile::current()->_type_verify == nullptr || Compile::current()->_type_verify->empty_cache(), "cache should have been discarded");
947 }
948
949 class VerifyMeet {
950 private:
951 Compile* _C;
952 public:
953 VerifyMeet(Compile* C) : _C(C) {
954 if (C->_type_verify == nullptr) {
955 C->_type_verify = new (C->comp_arena())VerifyMeetResult(C);
956 }
957 _C->_type_verify->_depth++;
958 }
959
960 ~VerifyMeet() {
961 assert(_C->_type_verify->_depth != 0, "");
962 _C->_type_verify->_depth--;
963 if (_C->_type_verify->_depth == 0) {
964 _C->_type_verify->_cache.trunc_to(0);
965 }
966 }
967
968 const Type* meet(const Type* t1, const Type* t2) const {
969 return _C->_type_verify->meet(t1, t2);
970 }
971
972 void add(const Type* t1, const Type* t2, const Type* res) const {
973 _C->_type_verify->add(t1, t2, res);
974 }
975 };
976
977 void Type::check_symmetrical(const Type* t, const Type* mt, const VerifyMeet& verify) const {
978 Compile* C = Compile::current();
979 const Type* mt2 = verify.meet(t, this);
980 if (mt != mt2) {
981 tty->print_cr("=== Meet Not Commutative ===");
982 tty->print("t = "); t->dump(); tty->cr();
983 tty->print("this = "); dump(); tty->cr();
984 tty->print("t meet this = "); mt2->dump(); tty->cr();
985 tty->print("this meet t = "); mt->dump(); tty->cr();
986 fatal("meet not commutative");
987 }
988 const Type* dual_join = mt->_dual;
989 const Type* t2t = verify.meet(dual_join,t->_dual);
990 const Type* t2this = verify.meet(dual_join,this->_dual);
991
992 // Interface meet Oop is Not Symmetric:
993 // Interface:AnyNull meet Oop:AnyNull == Interface:AnyNull
994 // Interface:NotNull meet Oop:NotNull == java/lang/Object:NotNull
995
996 if (t2t != t->_dual || t2this != this->_dual) {
997 tty->print_cr("=== Meet Not Symmetric ===");
998 tty->print("t = "); t->dump(); tty->cr();
999 tty->print("this= "); dump(); tty->cr();
1000 tty->print("mt=(t meet this)= "); mt->dump(); tty->cr();
1001
1002 tty->print("t_dual= "); t->_dual->dump(); tty->cr();
1003 tty->print("this_dual= "); _dual->dump(); tty->cr();
1004 tty->print("mt_dual= "); mt->_dual->dump(); tty->cr();
1005
1006 tty->print("mt_dual meet t_dual= "); t2t ->dump(); tty->cr();
1007 tty->print("mt_dual meet this_dual= "); t2this ->dump(); tty->cr();
1008
1009 fatal("meet not symmetric");
1010 }
1011 }
1012 #endif
1013
1014 //------------------------------meet-------------------------------------------
1015 // Compute the MEET of two types. NOT virtual. It enforces that meet is
1016 // commutative and the lattice is symmetric.
1017 const Type *Type::meet_helper(const Type *t, bool include_speculative) const {
1018 if (isa_narrowoop() && t->isa_narrowoop()) {
1019 const Type* result = make_ptr()->meet_helper(t->make_ptr(), include_speculative);
1020 return result->make_narrowoop();
1021 }
1022 if (isa_narrowklass() && t->isa_narrowklass()) {
1023 const Type* result = make_ptr()->meet_helper(t->make_ptr(), include_speculative);
1024 return result->make_narrowklass();
1025 }
1026
1027 #ifdef ASSERT
1028 Compile* C = Compile::current();
1029 VerifyMeet verify(C);
1030 #endif
1031
1032 const Type *this_t = maybe_remove_speculative(include_speculative);
1033 t = t->maybe_remove_speculative(include_speculative);
1034
1035 const Type *mt = this_t->xmeet(t);
1036 #ifdef ASSERT
1037 verify.add(this_t, t, mt);
1038 if (isa_narrowoop() || t->isa_narrowoop()) {
1039 return mt;
1040 }
1041 if (isa_narrowklass() || t->isa_narrowklass()) {
1042 return mt;
1043 }
1044 this_t->check_symmetrical(t, mt, verify);
1045 const Type *mt_dual = verify.meet(this_t->_dual, t->_dual);
1046 this_t->_dual->check_symmetrical(t->_dual, mt_dual, verify);
1047 #endif
1048 return mt;
1049 }
1050
1051 //------------------------------xmeet------------------------------------------
1052 // Compute the MEET of two types. It returns a new Type object.
1053 const Type *Type::xmeet( const Type *t ) const {
1054 // Perform a fast test for common case; meeting the same types together.
1055 if( this == t ) return this; // Meeting same type-rep?
1056
1057 // Meeting TOP with anything?
1058 if( _base == Top ) return t;
1059
1060 // Meeting BOTTOM with anything?
1061 if( _base == Bottom ) return BOTTOM;
1062
1063 // Current "this->_base" is one of: Bad, Multi, Control, Top,
1064 // Abio, Abstore, Floatxxx, Doublexxx, Bottom, lastype.
1065 switch (t->base()) { // Switch on original type
1066
1067 // Cut in half the number of cases I must handle. Only need cases for when
1068 // the given enum "t->type" is less than or equal to the local enum "type".
1069 case HalfFloatCon:
1070 case FloatCon:
1071 case DoubleCon:
1072 case Int:
1073 case Long:
1074 return t->xmeet(this);
1075
1076 case OopPtr:
1077 return t->xmeet(this);
1078
1079 case InstPtr:
1080 return t->xmeet(this);
1081
1082 case MetadataPtr:
1083 case KlassPtr:
1084 case InstKlassPtr:
1085 case AryKlassPtr:
1086 return t->xmeet(this);
1087
1088 case AryPtr:
1089 return t->xmeet(this);
1090
1091 case NarrowOop:
1092 return t->xmeet(this);
1093
1094 case NarrowKlass:
1095 return t->xmeet(this);
1096
1097 case Bad: // Type check
1098 default: // Bogus type not in lattice
1099 typerr(t);
1100 return Type::BOTTOM;
1101
1102 case Bottom: // Ye Olde Default
1103 return t;
1104
1105 case HalfFloatTop:
1106 if (_base == HalfFloatTop) { return this; }
1107 case HalfFloatBot: // Half Float
1108 if (_base == HalfFloatBot || _base == HalfFloatTop) { return HALF_FLOAT; }
1109 if (_base == FloatBot || _base == FloatTop) { return Type::BOTTOM; }
1110 if (_base == DoubleTop || _base == DoubleBot) { return Type::BOTTOM; }
1111 typerr(t);
1112 return Type::BOTTOM;
1113
1114 case FloatTop:
1115 if (_base == FloatTop ) { return this; }
1116 case FloatBot: // Float
1117 if (_base == FloatBot || _base == FloatTop) { return FLOAT; }
1118 if (_base == HalfFloatTop || _base == HalfFloatBot) { return Type::BOTTOM; }
1119 if (_base == DoubleTop || _base == DoubleBot) { return Type::BOTTOM; }
1120 typerr(t);
1121 return Type::BOTTOM;
1122
1123 case DoubleTop:
1124 if (_base == DoubleTop) { return this; }
1125 case DoubleBot: // Double
1126 if (_base == DoubleBot || _base == DoubleTop) { return DOUBLE; }
1127 if (_base == HalfFloatTop || _base == HalfFloatBot) { return Type::BOTTOM; }
1128 if (_base == FloatTop || _base == FloatBot) { return Type::BOTTOM; }
1129 typerr(t);
1130 return Type::BOTTOM;
1131
1132 // These next few cases must match exactly or it is a compile-time error.
1133 case Control: // Control of code
1134 case Abio: // State of world outside of program
1135 case Memory:
1136 if (_base == t->_base) { return this; }
1137 typerr(t);
1138 return Type::BOTTOM;
1139
1140 case Top: // Top of the lattice
1141 return this;
1142 }
1143
1144 // The type is unchanged
1145 return this;
1146 }
1147
1148 //-----------------------------filter------------------------------------------
1149 const Type *Type::filter_helper(const Type *kills, bool include_speculative) const {
1150 const Type* ft = join_helper(kills, include_speculative);
1151 if (ft->empty())
1152 return Type::TOP; // Canonical empty value
1153 return ft;
1154 }
1155
1156 //------------------------------xdual------------------------------------------
1157 const Type *Type::xdual() const {
1158 // Note: the base() accessor asserts the sanity of _base.
1159 assert(_type_info[base()].dual_type != Bad, "implement with v-call");
1160 return new Type(_type_info[_base].dual_type);
1161 }
1162
1163 //------------------------------has_memory-------------------------------------
1164 bool Type::has_memory() const {
1165 Type::TYPES tx = base();
1166 if (tx == Memory) return true;
1167 if (tx == Tuple) {
1168 const TypeTuple *t = is_tuple();
1169 for (uint i=0; i < t->cnt(); i++) {
1170 tx = t->field_at(i)->base();
1171 if (tx == Memory) return true;
1172 }
1173 }
1174 return false;
1175 }
1176
1177 #ifndef PRODUCT
1178 //------------------------------dump2------------------------------------------
1179 void Type::dump2( Dict &d, uint depth, outputStream *st ) const {
1180 st->print("%s", _type_info[_base].msg);
1181 }
1182
1183 //------------------------------dump-------------------------------------------
1184 void Type::dump_on(outputStream *st) const {
1185 ResourceMark rm;
1186 Dict d(cmpkey,hashkey); // Stop recursive type dumping
1187 dump2(d,1, st);
1188 if (is_ptr_to_narrowoop()) {
1189 st->print(" [narrow]");
1190 } else if (is_ptr_to_narrowklass()) {
1191 st->print(" [narrowklass]");
1192 }
1193 }
1194
1195 //-----------------------------------------------------------------------------
1196 const char* Type::str(const Type* t) {
1197 stringStream ss;
1198 t->dump_on(&ss);
1199 return ss.as_string();
1200 }
1201 #endif
1202
1203 //------------------------------singleton--------------------------------------
1204 // TRUE if Type is a singleton type, FALSE otherwise. Singletons are simple
1205 // constants (Ldi nodes). Singletons are integer, float or double constants.
1206 bool Type::singleton(void) const {
1207 return _base == Top || _base == Half;
1208 }
1209
1210 //------------------------------empty------------------------------------------
1211 // TRUE if Type is a type with no values, FALSE otherwise.
1212 bool Type::empty(void) const {
1213 switch (_base) {
1214 case DoubleTop:
1215 case FloatTop:
1216 case HalfFloatTop:
1217 case Top:
1218 return true;
1219
1220 case Half:
1221 case Abio:
1222 case Return_Address:
1223 case Memory:
1224 case Bottom:
1225 case HalfFloatBot:
1226 case FloatBot:
1227 case DoubleBot:
1228 return false; // never a singleton, therefore never empty
1229
1230 default:
1231 ShouldNotReachHere();
1232 return false;
1233 }
1234 }
1235
1236 //------------------------------dump_stats-------------------------------------
1237 // Dump collected statistics to stderr
1238 #ifndef PRODUCT
1239 void Type::dump_stats() {
1240 tty->print("Types made: %d\n", type_dict()->Size());
1241 }
1242 #endif
1243
1244 //------------------------------category---------------------------------------
1245 #ifndef PRODUCT
1246 Type::Category Type::category() const {
1247 const TypeTuple* tuple;
1248 switch (base()) {
1249 case Type::Int:
1250 case Type::Long:
1251 case Type::Half:
1252 case Type::NarrowOop:
1253 case Type::NarrowKlass:
1254 case Type::Array:
1255 case Type::VectorA:
1256 case Type::VectorS:
1257 case Type::VectorD:
1258 case Type::VectorX:
1259 case Type::VectorY:
1260 case Type::VectorZ:
1261 case Type::VectorMask:
1262 case Type::AnyPtr:
1263 case Type::RawPtr:
1264 case Type::OopPtr:
1265 case Type::InstPtr:
1266 case Type::AryPtr:
1267 case Type::MetadataPtr:
1268 case Type::KlassPtr:
1269 case Type::InstKlassPtr:
1270 case Type::AryKlassPtr:
1271 case Type::Function:
1272 case Type::Return_Address:
1273 case Type::HalfFloatTop:
1274 case Type::HalfFloatCon:
1275 case Type::HalfFloatBot:
1276 case Type::FloatTop:
1277 case Type::FloatCon:
1278 case Type::FloatBot:
1279 case Type::DoubleTop:
1280 case Type::DoubleCon:
1281 case Type::DoubleBot:
1282 return Category::Data;
1283 case Type::Memory:
1284 return Category::Memory;
1285 case Type::Control:
1286 return Category::Control;
1287 case Type::Top:
1288 case Type::Abio:
1289 case Type::Bottom:
1290 return Category::Other;
1291 case Type::Bad:
1292 case Type::lastype:
1293 return Category::Undef;
1294 case Type::Tuple:
1295 // Recursive case. Return CatMixed if the tuple contains types of
1296 // different categories (e.g. CallStaticJavaNode's type), or the specific
1297 // category if all types are of the same category (e.g. IfNode's type).
1298 tuple = is_tuple();
1299 if (tuple->cnt() == 0) {
1300 return Category::Undef;
1301 } else {
1302 Category first = tuple->field_at(0)->category();
1303 for (uint i = 1; i < tuple->cnt(); i++) {
1304 if (tuple->field_at(i)->category() != first) {
1305 return Category::Mixed;
1306 }
1307 }
1308 return first;
1309 }
1310 default:
1311 assert(false, "unmatched base type: all base types must be categorized");
1312 }
1313 return Category::Undef;
1314 }
1315
1316 bool Type::has_category(Type::Category cat) const {
1317 if (category() == cat) {
1318 return true;
1319 }
1320 if (category() == Category::Mixed) {
1321 const TypeTuple* tuple = is_tuple();
1322 for (uint i = 0; i < tuple->cnt(); i++) {
1323 if (tuple->field_at(i)->has_category(cat)) {
1324 return true;
1325 }
1326 }
1327 }
1328 return false;
1329 }
1330 #endif
1331
1332 //------------------------------typerr-----------------------------------------
1333 void Type::typerr( const Type *t ) const {
1334 #ifndef PRODUCT
1335 tty->print("\nError mixing types: ");
1336 dump();
1337 tty->print(" and ");
1338 t->dump();
1339 tty->print("\n");
1340 #endif
1341 ShouldNotReachHere();
1342 }
1343
1344
1345 //=============================================================================
1346 // Convenience common pre-built types.
1347 const TypeF *TypeF::MAX; // Floating point max
1348 const TypeF *TypeF::MIN; // Floating point min
1349 const TypeF *TypeF::ZERO; // Floating point zero
1350 const TypeF *TypeF::ONE; // Floating point one
1351 const TypeF *TypeF::POS_INF; // Floating point positive infinity
1352 const TypeF *TypeF::NEG_INF; // Floating point negative infinity
1353
1354 //------------------------------make-------------------------------------------
1355 // Create a float constant
1356 const TypeF *TypeF::make(float f) {
1357 return (TypeF*)(new TypeF(f))->hashcons();
1358 }
1359
1360 //------------------------------meet-------------------------------------------
1361 // Compute the MEET of two types. It returns a new Type object.
1362 const Type *TypeF::xmeet( const Type *t ) const {
1363 // Perform a fast test for common case; meeting the same types together.
1364 if( this == t ) return this; // Meeting same type-rep?
1365
1366 // Current "this->_base" is FloatCon
1367 switch (t->base()) { // Switch on original type
1368 case AnyPtr: // Mixing with oops happens when javac
1369 case RawPtr: // reuses local variables
1370 case OopPtr:
1371 case InstPtr:
1372 case AryPtr:
1373 case MetadataPtr:
1374 case KlassPtr:
1375 case InstKlassPtr:
1376 case AryKlassPtr:
1377 case NarrowOop:
1378 case NarrowKlass:
1379 case Int:
1380 case Long:
1381 case HalfFloatTop:
1382 case HalfFloatCon:
1383 case HalfFloatBot:
1384 case DoubleTop:
1385 case DoubleCon:
1386 case DoubleBot:
1387 case Bottom: // Ye Olde Default
1388 return Type::BOTTOM;
1389
1390 case FloatBot:
1391 return t;
1392
1393 default: // All else is a mistake
1394 typerr(t);
1395
1396 case FloatCon: // Float-constant vs Float-constant?
1397 if( jint_cast(_f) != jint_cast(t->getf()) ) // unequal constants?
1398 // must compare bitwise as positive zero, negative zero and NaN have
1399 // all the same representation in C++
1400 return FLOAT; // Return generic float
1401 // Equal constants
1402 case Top:
1403 case FloatTop:
1404 break; // Return the float constant
1405 }
1406 return this; // Return the float constant
1407 }
1408
1409 //------------------------------xdual------------------------------------------
1410 // Dual: symmetric
1411 const Type *TypeF::xdual() const {
1412 return this;
1413 }
1414
1415 //------------------------------eq---------------------------------------------
1416 // Structural equality check for Type representations
1417 bool TypeF::eq(const Type *t) const {
1418 // Bitwise comparison to distinguish between +/-0. These values must be treated
1419 // as different to be consistent with C1 and the interpreter.
1420 return (jint_cast(_f) == jint_cast(t->getf()));
1421 }
1422
1423 //------------------------------hash-------------------------------------------
1424 // Type-specific hashing function.
1425 uint TypeF::hash(void) const {
1426 return *(uint*)(&_f);
1427 }
1428
1429 //------------------------------is_finite--------------------------------------
1430 // Has a finite value
1431 bool TypeF::is_finite() const {
1432 return g_isfinite(getf()) != 0;
1433 }
1434
1435 //------------------------------is_nan-----------------------------------------
1436 // Is not a number (NaN)
1437 bool TypeF::is_nan() const {
1438 return g_isnan(getf()) != 0;
1439 }
1440
1441 //------------------------------dump2------------------------------------------
1442 // Dump float constant Type
1443 #ifndef PRODUCT
1444 void TypeF::dump2( Dict &d, uint depth, outputStream *st ) const {
1445 Type::dump2(d,depth, st);
1446 st->print("%f", _f);
1447 }
1448 #endif
1449
1450 //------------------------------singleton--------------------------------------
1451 // TRUE if Type is a singleton type, FALSE otherwise. Singletons are simple
1452 // constants (Ldi nodes). Singletons are integer, float or double constants
1453 // or a single symbol.
1454 bool TypeF::singleton(void) const {
1455 return true; // Always a singleton
1456 }
1457
1458 bool TypeF::empty(void) const {
1459 return false; // always exactly a singleton
1460 }
1461
1462 //=============================================================================
1463 // Convenience common pre-built types.
1464 const TypeH* TypeH::MAX; // Half float max
1465 const TypeH* TypeH::MIN; // Half float min
1466 const TypeH* TypeH::ZERO; // Half float zero
1467 const TypeH* TypeH::ONE; // Half float one
1468 const TypeH* TypeH::POS_INF; // Half float positive infinity
1469 const TypeH* TypeH::NEG_INF; // Half float negative infinity
1470
1471 //------------------------------make-------------------------------------------
1472 // Create a halffloat constant
1473 const TypeH* TypeH::make(short f) {
1474 return (TypeH*)(new TypeH(f))->hashcons();
1475 }
1476
1477 const TypeH* TypeH::make(float f) {
1478 assert(StubRoutines::f2hf_adr() != nullptr, "");
1479 short hf = StubRoutines::f2hf(f);
1480 return (TypeH*)(new TypeH(hf))->hashcons();
1481 }
1482
1483 //------------------------------xmeet-------------------------------------------
1484 // Compute the MEET of two types. It returns a new Type object.
1485 const Type* TypeH::xmeet(const Type* t) const {
1486 // Perform a fast test for common case; meeting the same types together.
1487 if (this == t) return this; // Meeting same type-rep?
1488
1489 // Current "this->_base" is FloatCon
1490 switch (t->base()) { // Switch on original type
1491 case AnyPtr: // Mixing with oops happens when javac
1492 case RawPtr: // reuses local variables
1493 case OopPtr:
1494 case InstPtr:
1495 case AryPtr:
1496 case MetadataPtr:
1497 case KlassPtr:
1498 case InstKlassPtr:
1499 case AryKlassPtr:
1500 case NarrowOop:
1501 case NarrowKlass:
1502 case Int:
1503 case Long:
1504 case FloatTop:
1505 case FloatCon:
1506 case FloatBot:
1507 case DoubleTop:
1508 case DoubleCon:
1509 case DoubleBot:
1510 case Bottom: // Ye Olde Default
1511 return Type::BOTTOM;
1512
1513 case HalfFloatBot:
1514 return t;
1515
1516 default: // All else is a mistake
1517 typerr(t);
1518
1519 case HalfFloatCon: // Half float-constant vs Half float-constant?
1520 if (_f != t->geth()) { // unequal constants?
1521 // must compare bitwise as positive zero, negative zero and NaN have
1522 // all the same representation in C++
1523 return HALF_FLOAT; // Return generic float
1524 } // Equal constants
1525 case Top:
1526 case HalfFloatTop:
1527 break; // Return the Half float constant
1528 }
1529 return this; // Return the Half float constant
1530 }
1531
1532 //------------------------------xdual------------------------------------------
1533 // Dual: symmetric
1534 const Type* TypeH::xdual() const {
1535 return this;
1536 }
1537
1538 //------------------------------eq---------------------------------------------
1539 // Structural equality check for Type representations
1540 bool TypeH::eq(const Type* t) const {
1541 // Bitwise comparison to distinguish between +/-0. These values must be treated
1542 // as different to be consistent with C1 and the interpreter.
1543 return (_f == t->geth());
1544 }
1545
1546 //------------------------------hash-------------------------------------------
1547 // Type-specific hashing function.
1548 uint TypeH::hash(void) const {
1549 return *(jshort*)(&_f);
1550 }
1551
1552 //------------------------------is_finite--------------------------------------
1553 // Has a finite value
1554 bool TypeH::is_finite() const {
1555 assert(StubRoutines::hf2f_adr() != nullptr, "");
1556 float f = StubRoutines::hf2f(geth());
1557 return g_isfinite(f) != 0;
1558 }
1559
1560 float TypeH::getf() const {
1561 assert(StubRoutines::hf2f_adr() != nullptr, "");
1562 return StubRoutines::hf2f(geth());
1563 }
1564
1565 //------------------------------is_nan-----------------------------------------
1566 // Is not a number (NaN)
1567 bool TypeH::is_nan() const {
1568 assert(StubRoutines::hf2f_adr() != nullptr, "");
1569 float f = StubRoutines::hf2f(geth());
1570 return g_isnan(f) != 0;
1571 }
1572
1573 //------------------------------dump2------------------------------------------
1574 // Dump float constant Type
1575 #ifndef PRODUCT
1576 void TypeH::dump2(Dict &d, uint depth, outputStream* st) const {
1577 Type::dump2(d,depth, st);
1578 st->print("%f", getf());
1579 }
1580 #endif
1581
1582 //------------------------------singleton--------------------------------------
1583 // TRUE if Type is a singleton type, FALSE otherwise. Singletons are simple
1584 // constants (Ldi nodes). Singletons are integer, half float, float or double constants
1585 // or a single symbol.
1586 bool TypeH::singleton(void) const {
1587 return true; // Always a singleton
1588 }
1589
1590 bool TypeH::empty(void) const {
1591 return false; // always exactly a singleton
1592 }
1593
1594 //=============================================================================
1595 // Convenience common pre-built types.
1596 const TypeD *TypeD::MAX; // Floating point max
1597 const TypeD *TypeD::MIN; // Floating point min
1598 const TypeD *TypeD::ZERO; // Floating point zero
1599 const TypeD *TypeD::ONE; // Floating point one
1600 const TypeD *TypeD::POS_INF; // Floating point positive infinity
1601 const TypeD *TypeD::NEG_INF; // Floating point negative infinity
1602
1603 //------------------------------make-------------------------------------------
1604 const TypeD *TypeD::make(double d) {
1605 return (TypeD*)(new TypeD(d))->hashcons();
1606 }
1607
1608 //------------------------------meet-------------------------------------------
1609 // Compute the MEET of two types. It returns a new Type object.
1610 const Type *TypeD::xmeet( const Type *t ) const {
1611 // Perform a fast test for common case; meeting the same types together.
1612 if( this == t ) return this; // Meeting same type-rep?
1613
1614 // Current "this->_base" is DoubleCon
1615 switch (t->base()) { // Switch on original type
1616 case AnyPtr: // Mixing with oops happens when javac
1617 case RawPtr: // reuses local variables
1618 case OopPtr:
1619 case InstPtr:
1620 case AryPtr:
1621 case MetadataPtr:
1622 case KlassPtr:
1623 case InstKlassPtr:
1624 case AryKlassPtr:
1625 case NarrowOop:
1626 case NarrowKlass:
1627 case Int:
1628 case Long:
1629 case HalfFloatTop:
1630 case HalfFloatCon:
1631 case HalfFloatBot:
1632 case FloatTop:
1633 case FloatCon:
1634 case FloatBot:
1635 case Bottom: // Ye Olde Default
1636 return Type::BOTTOM;
1637
1638 case DoubleBot:
1639 return t;
1640
1641 default: // All else is a mistake
1642 typerr(t);
1643
1644 case DoubleCon: // Double-constant vs Double-constant?
1645 if( jlong_cast(_d) != jlong_cast(t->getd()) ) // unequal constants? (see comment in TypeF::xmeet)
1646 return DOUBLE; // Return generic double
1647 case Top:
1648 case DoubleTop:
1649 break;
1650 }
1651 return this; // Return the double constant
1652 }
1653
1654 //------------------------------xdual------------------------------------------
1655 // Dual: symmetric
1656 const Type *TypeD::xdual() const {
1657 return this;
1658 }
1659
1660 //------------------------------eq---------------------------------------------
1661 // Structural equality check for Type representations
1662 bool TypeD::eq(const Type *t) const {
1663 // Bitwise comparison to distinguish between +/-0. These values must be treated
1664 // as different to be consistent with C1 and the interpreter.
1665 return (jlong_cast(_d) == jlong_cast(t->getd()));
1666 }
1667
1668 //------------------------------hash-------------------------------------------
1669 // Type-specific hashing function.
1670 uint TypeD::hash(void) const {
1671 return *(uint*)(&_d);
1672 }
1673
1674 //------------------------------is_finite--------------------------------------
1675 // Has a finite value
1676 bool TypeD::is_finite() const {
1677 return g_isfinite(getd()) != 0;
1678 }
1679
1680 //------------------------------is_nan-----------------------------------------
1681 // Is not a number (NaN)
1682 bool TypeD::is_nan() const {
1683 return g_isnan(getd()) != 0;
1684 }
1685
1686 //------------------------------dump2------------------------------------------
1687 // Dump double constant Type
1688 #ifndef PRODUCT
1689 void TypeD::dump2( Dict &d, uint depth, outputStream *st ) const {
1690 Type::dump2(d,depth,st);
1691 st->print("%f", _d);
1692 }
1693 #endif
1694
1695 //------------------------------singleton--------------------------------------
1696 // TRUE if Type is a singleton type, FALSE otherwise. Singletons are simple
1697 // constants (Ldi nodes). Singletons are integer, float or double constants
1698 // or a single symbol.
1699 bool TypeD::singleton(void) const {
1700 return true; // Always a singleton
1701 }
1702
1703 bool TypeD::empty(void) const {
1704 return false; // always exactly a singleton
1705 }
1706
1707 const TypeInteger* TypeInteger::make(jlong lo, jlong hi, int w, BasicType bt) {
1708 if (bt == T_INT) {
1709 return TypeInt::make(checked_cast<jint>(lo), checked_cast<jint>(hi), w);
1710 }
1711 assert(bt == T_LONG, "basic type not an int or long");
1712 return TypeLong::make(lo, hi, w);
1713 }
1714
1715 const TypeInteger* TypeInteger::make(jlong con, BasicType bt) {
1716 return make(con, con, WidenMin, bt);
1717 }
1718
1719 jlong TypeInteger::get_con_as_long(BasicType bt) const {
1720 if (bt == T_INT) {
1721 return is_int()->get_con();
1722 }
1723 assert(bt == T_LONG, "basic type not an int or long");
1724 return is_long()->get_con();
1725 }
1726
1727 const TypeInteger* TypeInteger::bottom(BasicType bt) {
1728 if (bt == T_INT) {
1729 return TypeInt::INT;
1730 }
1731 assert(bt == T_LONG, "basic type not an int or long");
1732 return TypeLong::LONG;
1733 }
1734
1735 const TypeInteger* TypeInteger::zero(BasicType bt) {
1736 if (bt == T_INT) {
1737 return TypeInt::ZERO;
1738 }
1739 assert(bt == T_LONG, "basic type not an int or long");
1740 return TypeLong::ZERO;
1741 }
1742
1743 const TypeInteger* TypeInteger::one(BasicType bt) {
1744 if (bt == T_INT) {
1745 return TypeInt::ONE;
1746 }
1747 assert(bt == T_LONG, "basic type not an int or long");
1748 return TypeLong::ONE;
1749 }
1750
1751 const TypeInteger* TypeInteger::minus_1(BasicType bt) {
1752 if (bt == T_INT) {
1753 return TypeInt::MINUS_1;
1754 }
1755 assert(bt == T_LONG, "basic type not an int or long");
1756 return TypeLong::MINUS_1;
1757 }
1758
1759 //=============================================================================
1760 // Convenience common pre-built types.
1761 const TypeInt* TypeInt::MAX; // INT_MAX
1762 const TypeInt* TypeInt::MIN; // INT_MIN
1763 const TypeInt* TypeInt::MINUS_1;// -1
1764 const TypeInt* TypeInt::ZERO; // 0
1765 const TypeInt* TypeInt::ONE; // 1
1766 const TypeInt* TypeInt::BOOL; // 0 or 1, FALSE or TRUE.
1767 const TypeInt* TypeInt::CC; // -1,0 or 1, condition codes
1768 const TypeInt* TypeInt::CC_LT; // [-1] == MINUS_1
1769 const TypeInt* TypeInt::CC_GT; // [1] == ONE
1770 const TypeInt* TypeInt::CC_EQ; // [0] == ZERO
1771 const TypeInt* TypeInt::CC_NE;
1772 const TypeInt* TypeInt::CC_LE; // [-1,0]
1773 const TypeInt* TypeInt::CC_GE; // [0,1] == BOOL (!)
1774 const TypeInt* TypeInt::BYTE; // Bytes, -128 to 127
1775 const TypeInt* TypeInt::UBYTE; // Unsigned Bytes, 0 to 255
1776 const TypeInt* TypeInt::CHAR; // Java chars, 0-65535
1777 const TypeInt* TypeInt::SHORT; // Java shorts, -32768-32767
1778 const TypeInt* TypeInt::NON_ZERO;
1779 const TypeInt* TypeInt::POS; // Positive 32-bit integers or zero
1780 const TypeInt* TypeInt::POS1; // Positive 32-bit integers
1781 const TypeInt* TypeInt::INT; // 32-bit integers
1782 const TypeInt* TypeInt::SYMINT; // symmetric range [-max_jint..max_jint]
1783 const TypeInt* TypeInt::TYPE_DOMAIN; // alias for TypeInt::INT
1784
1785 TypeInt::TypeInt(const TypeIntPrototype<jint, juint>& t, int widen, bool dual)
1786 : TypeInteger(Int, t.normalize_widen(widen), dual), _lo(t._srange._lo), _hi(t._srange._hi),
1787 _ulo(t._urange._lo), _uhi(t._urange._hi), _bits(t._bits) {
1788 DEBUG_ONLY(t.verify_constraints());
1789 }
1790
1791 const Type* TypeInt::make_or_top(const TypeIntPrototype<jint, juint>& t, int widen, bool dual) {
1792 auto canonicalized_t = t.canonicalize_constraints();
1793 if (canonicalized_t.empty()) {
1794 return dual ? Type::BOTTOM : Type::TOP;
1795 }
1796 return (new TypeInt(canonicalized_t._data, widen, dual))->hashcons()->is_int();
1797 }
1798
1799 const TypeInt* TypeInt::make(jint con) {
1800 juint ucon = con;
1801 return (new TypeInt(TypeIntPrototype<jint, juint>{{con, con}, {ucon, ucon}, {~ucon, ucon}},
1802 WidenMin, false))->hashcons()->is_int();
1803 }
1804
1805 const TypeInt* TypeInt::make(jint lo, jint hi, int widen) {
1806 assert(lo <= hi, "must be legal bounds");
1807 return make_or_top(TypeIntPrototype<jint, juint>{{lo, hi}, {0, max_juint}, {0, 0}}, widen)->is_int();
1808 }
1809
1810 const Type* TypeInt::make_or_top(const TypeIntPrototype<jint, juint>& t, int widen) {
1811 return make_or_top(t, widen, false);
1812 }
1813
1814 bool TypeInt::contains(jint i) const {
1815 assert(!_is_dual, "dual types should only be used for join calculation");
1816 juint u = i;
1817 return i >= _lo && i <= _hi &&
1818 u >= _ulo && u <= _uhi &&
1819 _bits.is_satisfied_by(u);
1820 }
1821
1822 bool TypeInt::contains(const TypeInt* t) const {
1823 assert(!_is_dual && !t->_is_dual, "dual types should only be used for join calculation");
1824 return TypeIntHelper::int_type_is_subset(this, t);
1825 }
1826
1827 #ifdef ASSERT
1828 bool TypeInt::strictly_contains(const TypeInt* t) const {
1829 assert(!_is_dual && !t->_is_dual, "dual types should only be used for join calculation");
1830 return TypeIntHelper::int_type_is_subset(this, t) && !TypeIntHelper::int_type_is_equal(this, t);
1831 }
1832 #endif // ASSERT
1833
1834 const Type* TypeInt::xmeet(const Type* t) const {
1835 return TypeIntHelper::int_type_xmeet(this, t);
1836 }
1837
1838 const Type* TypeInt::xdual() const {
1839 return new TypeInt(TypeIntPrototype<jint, juint>{{_lo, _hi}, {_ulo, _uhi}, _bits},
1840 _widen, !_is_dual);
1841 }
1842
1843 const Type* TypeInt::widen(const Type* old, const Type* limit) const {
1844 assert(!_is_dual, "dual types should only be used for join calculation");
1845 return TypeIntHelper::int_type_widen(this, old->isa_int(), limit->isa_int());
1846 }
1847
1848 const Type* TypeInt::narrow(const Type* old) const {
1849 assert(!_is_dual, "dual types should only be used for join calculation");
1850 if (old == nullptr) {
1851 return this;
1852 }
1853
1854 return TypeIntHelper::int_type_narrow(this, old->isa_int());
1855 }
1856
1857 //-----------------------------filter------------------------------------------
1858 const Type* TypeInt::filter_helper(const Type* kills, bool include_speculative) const {
1859 assert(!_is_dual, "dual types should only be used for join calculation");
1860 const TypeInt* ft = join_helper(kills, include_speculative)->isa_int();
1861 if (ft == nullptr) {
1862 return Type::TOP; // Canonical empty value
1863 }
1864 assert(!ft->_is_dual, "dual types should only be used for join calculation");
1865 if (ft->_widen < this->_widen) {
1866 // Do not allow the value of kill->_widen to affect the outcome.
1867 // The widen bits must be allowed to run freely through the graph.
1868 return (new TypeInt(TypeIntPrototype<jint, juint>{{ft->_lo, ft->_hi}, {ft->_ulo, ft->_uhi}, ft->_bits},
1869 this->_widen, false))->hashcons();
1870 }
1871 return ft;
1872 }
1873
1874 //------------------------------eq---------------------------------------------
1875 // Structural equality check for Type representations
1876 bool TypeInt::eq(const Type* t) const {
1877 const TypeInt* r = t->is_int();
1878 return TypeIntHelper::int_type_is_equal(this, r) && _widen == r->_widen && _is_dual == r->_is_dual;
1879 }
1880
1881 //------------------------------hash-------------------------------------------
1882 // Type-specific hashing function.
1883 uint TypeInt::hash(void) const {
1884 return (uint)_lo + (uint)_hi + (uint)_ulo + (uint)_uhi +
1885 (uint)_bits._zeros + (uint)_bits._ones + (uint)_widen + (uint)_is_dual + (uint)Type::Int;
1886 }
1887
1888 //------------------------------is_finite--------------------------------------
1889 // Has a finite value
1890 bool TypeInt::is_finite() const {
1891 return true;
1892 }
1893
1894 //------------------------------singleton--------------------------------------
1895 // TRUE if Type is a singleton type, FALSE otherwise. Singletons are simple
1896 // constants.
1897 bool TypeInt::singleton(void) const {
1898 return _lo == _hi;
1899 }
1900
1901 bool TypeInt::empty(void) const {
1902 return false;
1903 }
1904
1905 //=============================================================================
1906 // Convenience common pre-built types.
1907 const TypeLong* TypeLong::MAX;
1908 const TypeLong* TypeLong::MIN;
1909 const TypeLong* TypeLong::MINUS_1;// -1
1910 const TypeLong* TypeLong::ZERO; // 0
1911 const TypeLong* TypeLong::ONE; // 1
1912 const TypeLong* TypeLong::NON_ZERO;
1913 const TypeLong* TypeLong::POS; // >=0
1914 const TypeLong* TypeLong::NEG;
1915 const TypeLong* TypeLong::LONG; // 64-bit integers
1916 const TypeLong* TypeLong::INT; // 32-bit subrange
1917 const TypeLong* TypeLong::UINT; // 32-bit unsigned subrange
1918 const TypeLong* TypeLong::TYPE_DOMAIN; // alias for TypeLong::LONG
1919
1920 TypeLong::TypeLong(const TypeIntPrototype<jlong, julong>& t, int widen, bool dual)
1921 : TypeInteger(Long, t.normalize_widen(widen), dual), _lo(t._srange._lo), _hi(t._srange._hi),
1922 _ulo(t._urange._lo), _uhi(t._urange._hi), _bits(t._bits) {
1923 DEBUG_ONLY(t.verify_constraints());
1924 }
1925
1926 const Type* TypeLong::make_or_top(const TypeIntPrototype<jlong, julong>& t, int widen, bool dual) {
1927 auto canonicalized_t = t.canonicalize_constraints();
1928 if (canonicalized_t.empty()) {
1929 return dual ? Type::BOTTOM : Type::TOP;
1930 }
1931 return (new TypeLong(canonicalized_t._data, widen, dual))->hashcons()->is_long();
1932 }
1933
1934 const TypeLong* TypeLong::make(jlong con) {
1935 julong ucon = con;
1936 return (new TypeLong(TypeIntPrototype<jlong, julong>{{con, con}, {ucon, ucon}, {~ucon, ucon}},
1937 WidenMin, false))->hashcons()->is_long();
1938 }
1939
1940 const TypeLong* TypeLong::make(jlong lo, jlong hi, int widen) {
1941 assert(lo <= hi, "must be legal bounds");
1942 return make_or_top(TypeIntPrototype<jlong, julong>{{lo, hi}, {0, max_julong}, {0, 0}}, widen)->is_long();
1943 }
1944
1945 const Type* TypeLong::make_or_top(const TypeIntPrototype<jlong, julong>& t, int widen) {
1946 return make_or_top(t, widen, false);
1947 }
1948
1949 bool TypeLong::contains(jlong i) const {
1950 assert(!_is_dual, "dual types should only be used for join calculation");
1951 julong u = i;
1952 return i >= _lo && i <= _hi &&
1953 u >= _ulo && u <= _uhi &&
1954 _bits.is_satisfied_by(u);
1955 }
1956
1957 bool TypeLong::contains(const TypeLong* t) const {
1958 assert(!_is_dual && !t->_is_dual, "dual types should only be used for join calculation");
1959 return TypeIntHelper::int_type_is_subset(this, t);
1960 }
1961
1962 #ifdef ASSERT
1963 bool TypeLong::strictly_contains(const TypeLong* t) const {
1964 assert(!_is_dual && !t->_is_dual, "dual types should only be used for join calculation");
1965 return TypeIntHelper::int_type_is_subset(this, t) && !TypeIntHelper::int_type_is_equal(this, t);
1966 }
1967 #endif // ASSERT
1968
1969 const Type* TypeLong::xmeet(const Type* t) const {
1970 return TypeIntHelper::int_type_xmeet(this, t);
1971 }
1972
1973 const Type* TypeLong::xdual() const {
1974 return new TypeLong(TypeIntPrototype<jlong, julong>{{_lo, _hi}, {_ulo, _uhi}, _bits},
1975 _widen, !_is_dual);
1976 }
1977
1978 const Type* TypeLong::widen(const Type* old, const Type* limit) const {
1979 assert(!_is_dual, "dual types should only be used for join calculation");
1980 return TypeIntHelper::int_type_widen(this, old->isa_long(), limit->isa_long());
1981 }
1982
1983 const Type* TypeLong::narrow(const Type* old) const {
1984 assert(!_is_dual, "dual types should only be used for join calculation");
1985 if (old == nullptr) {
1986 return this;
1987 }
1988
1989 return TypeIntHelper::int_type_narrow(this, old->isa_long());
1990 }
1991
1992 //-----------------------------filter------------------------------------------
1993 const Type* TypeLong::filter_helper(const Type* kills, bool include_speculative) const {
1994 assert(!_is_dual, "dual types should only be used for join calculation");
1995 const TypeLong* ft = join_helper(kills, include_speculative)->isa_long();
1996 if (ft == nullptr) {
1997 return Type::TOP; // Canonical empty value
1998 }
1999 assert(!ft->_is_dual, "dual types should only be used for join calculation");
2000 if (ft->_widen < this->_widen) {
2001 // Do not allow the value of kill->_widen to affect the outcome.
2002 // The widen bits must be allowed to run freely through the graph.
2003 return (new TypeLong(TypeIntPrototype<jlong, julong>{{ft->_lo, ft->_hi}, {ft->_ulo, ft->_uhi}, ft->_bits},
2004 this->_widen, false))->hashcons();
2005 }
2006 return ft;
2007 }
2008
2009 //------------------------------eq---------------------------------------------
2010 // Structural equality check for Type representations
2011 bool TypeLong::eq(const Type* t) const {
2012 const TypeLong* r = t->is_long();
2013 return TypeIntHelper::int_type_is_equal(this, r) && _widen == r->_widen && _is_dual == r->_is_dual;
2014 }
2015
2016 //------------------------------hash-------------------------------------------
2017 // Type-specific hashing function.
2018 uint TypeLong::hash(void) const {
2019 return (uint)_lo + (uint)_hi + (uint)_ulo + (uint)_uhi +
2020 (uint)_bits._zeros + (uint)_bits._ones + (uint)_widen + (uint)_is_dual + (uint)Type::Long;
2021 }
2022
2023 //------------------------------is_finite--------------------------------------
2024 // Has a finite value
2025 bool TypeLong::is_finite() const {
2026 return true;
2027 }
2028
2029 //------------------------------singleton--------------------------------------
2030 // TRUE if Type is a singleton type, FALSE otherwise. Singletons are simple
2031 // constants
2032 bool TypeLong::singleton(void) const {
2033 return _lo == _hi;
2034 }
2035
2036 bool TypeLong::empty(void) const {
2037 return false;
2038 }
2039
2040 //------------------------------dump2------------------------------------------
2041 #ifndef PRODUCT
2042 void TypeInt::dump2(Dict& d, uint depth, outputStream* st) const {
2043 TypeIntHelper::int_type_dump(this, st, false);
2044 }
2045
2046 void TypeInt::dump_verbose() const {
2047 TypeIntHelper::int_type_dump(this, tty, true);
2048 }
2049
2050 void TypeLong::dump2(Dict& d, uint depth, outputStream* st) const {
2051 TypeIntHelper::int_type_dump(this, st, false);
2052 }
2053
2054 void TypeLong::dump_verbose() const {
2055 TypeIntHelper::int_type_dump(this, tty, true);
2056 }
2057 #endif
2058
2059 //=============================================================================
2060 // Convenience common pre-built types.
2061 const TypeTuple *TypeTuple::IFBOTH; // Return both arms of IF as reachable
2062 const TypeTuple *TypeTuple::IFFALSE;
2063 const TypeTuple *TypeTuple::IFTRUE;
2064 const TypeTuple *TypeTuple::IFNEITHER;
2065 const TypeTuple *TypeTuple::LOOPBODY;
2066 const TypeTuple *TypeTuple::MEMBAR;
2067 const TypeTuple *TypeTuple::STORECONDITIONAL;
2068 const TypeTuple *TypeTuple::START_I2C;
2069 const TypeTuple *TypeTuple::INT_PAIR;
2070 const TypeTuple *TypeTuple::LONG_PAIR;
2071 const TypeTuple *TypeTuple::INT_CC_PAIR;
2072 const TypeTuple *TypeTuple::LONG_CC_PAIR;
2073
2074 //------------------------------make-------------------------------------------
2075 // Make a TypeTuple from the range of a method signature
2076 const TypeTuple *TypeTuple::make_range(ciSignature* sig, InterfaceHandling interface_handling) {
2077 ciType* return_type = sig->return_type();
2078 uint arg_cnt = return_type->size();
2079 const Type **field_array = fields(arg_cnt);
2080 switch (return_type->basic_type()) {
2081 case T_LONG:
2082 field_array[TypeFunc::Parms] = TypeLong::LONG;
2083 field_array[TypeFunc::Parms+1] = Type::HALF;
2084 break;
2085 case T_DOUBLE:
2086 field_array[TypeFunc::Parms] = Type::DOUBLE;
2087 field_array[TypeFunc::Parms+1] = Type::HALF;
2088 break;
2089 case T_OBJECT:
2090 case T_ARRAY:
2091 case T_BOOLEAN:
2092 case T_CHAR:
2093 case T_FLOAT:
2094 case T_BYTE:
2095 case T_SHORT:
2096 case T_INT:
2097 field_array[TypeFunc::Parms] = get_const_type(return_type, interface_handling);
2098 break;
2099 case T_VOID:
2100 break;
2101 default:
2102 ShouldNotReachHere();
2103 }
2104 return (TypeTuple*)(new TypeTuple(TypeFunc::Parms + arg_cnt, field_array))->hashcons();
2105 }
2106
2107 // Make a TypeTuple from the domain of a method signature
2108 const TypeTuple *TypeTuple::make_domain(ciInstanceKlass* recv, ciSignature* sig, InterfaceHandling interface_handling) {
2109 uint arg_cnt = sig->size();
2110
2111 uint pos = TypeFunc::Parms;
2112 const Type **field_array;
2113 if (recv != nullptr) {
2114 arg_cnt++;
2115 field_array = fields(arg_cnt);
2116 // Use get_const_type here because it respects UseUniqueSubclasses:
2117 field_array[pos++] = get_const_type(recv, interface_handling)->join_speculative(TypePtr::NOTNULL);
2118 } else {
2119 field_array = fields(arg_cnt);
2120 }
2121
2122 int i = 0;
2123 while (pos < TypeFunc::Parms + arg_cnt) {
2124 ciType* type = sig->type_at(i);
2125
2126 switch (type->basic_type()) {
2127 case T_LONG:
2128 field_array[pos++] = TypeLong::LONG;
2129 field_array[pos++] = Type::HALF;
2130 break;
2131 case T_DOUBLE:
2132 field_array[pos++] = Type::DOUBLE;
2133 field_array[pos++] = Type::HALF;
2134 break;
2135 case T_OBJECT:
2136 case T_ARRAY:
2137 case T_FLOAT:
2138 case T_INT:
2139 field_array[pos++] = get_const_type(type, interface_handling);
2140 break;
2141 case T_BOOLEAN:
2142 case T_CHAR:
2143 case T_BYTE:
2144 case T_SHORT:
2145 field_array[pos++] = TypeInt::INT;
2146 break;
2147 default:
2148 ShouldNotReachHere();
2149 }
2150 i++;
2151 }
2152
2153 return (TypeTuple*)(new TypeTuple(TypeFunc::Parms + arg_cnt, field_array))->hashcons();
2154 }
2155
2156 const TypeTuple *TypeTuple::make( uint cnt, const Type **fields ) {
2157 return (TypeTuple*)(new TypeTuple(cnt,fields))->hashcons();
2158 }
2159
2160 //------------------------------fields-----------------------------------------
2161 // Subroutine call type with space allocated for argument types
2162 // Memory for Control, I_O, Memory, FramePtr, and ReturnAdr is allocated implicitly
2163 const Type **TypeTuple::fields( uint arg_cnt ) {
2164 const Type **flds = (const Type **)(Compile::current()->type_arena()->AmallocWords((TypeFunc::Parms+arg_cnt)*sizeof(Type*) ));
2165 flds[TypeFunc::Control ] = Type::CONTROL;
2166 flds[TypeFunc::I_O ] = Type::ABIO;
2167 flds[TypeFunc::Memory ] = Type::MEMORY;
2168 flds[TypeFunc::FramePtr ] = TypeRawPtr::BOTTOM;
2169 flds[TypeFunc::ReturnAdr] = Type::RETURN_ADDRESS;
2170
2171 return flds;
2172 }
2173
2174 //------------------------------meet-------------------------------------------
2175 // Compute the MEET of two types. It returns a new Type object.
2176 const Type *TypeTuple::xmeet( const Type *t ) const {
2177 // Perform a fast test for common case; meeting the same types together.
2178 if( this == t ) return this; // Meeting same type-rep?
2179
2180 // Current "this->_base" is Tuple
2181 switch (t->base()) { // switch on original type
2182
2183 case Bottom: // Ye Olde Default
2184 return t;
2185
2186 default: // All else is a mistake
2187 typerr(t);
2188
2189 case Tuple: { // Meeting 2 signatures?
2190 const TypeTuple *x = t->is_tuple();
2191 assert( _cnt == x->_cnt, "" );
2192 const Type **fields = (const Type **)(Compile::current()->type_arena()->AmallocWords( _cnt*sizeof(Type*) ));
2193 for( uint i=0; i<_cnt; i++ )
2194 fields[i] = field_at(i)->xmeet( x->field_at(i) );
2195 return TypeTuple::make(_cnt,fields);
2196 }
2197 case Top:
2198 break;
2199 }
2200 return this; // Return the double constant
2201 }
2202
2203 //------------------------------xdual------------------------------------------
2204 // Dual: compute field-by-field dual
2205 const Type *TypeTuple::xdual() const {
2206 const Type **fields = (const Type **)(Compile::current()->type_arena()->AmallocWords( _cnt*sizeof(Type*) ));
2207 for( uint i=0; i<_cnt; i++ )
2208 fields[i] = _fields[i]->dual();
2209 return new TypeTuple(_cnt,fields);
2210 }
2211
2212 //------------------------------eq---------------------------------------------
2213 // Structural equality check for Type representations
2214 bool TypeTuple::eq( const Type *t ) const {
2215 const TypeTuple *s = (const TypeTuple *)t;
2216 if (_cnt != s->_cnt) return false; // Unequal field counts
2217 for (uint i = 0; i < _cnt; i++)
2218 if (field_at(i) != s->field_at(i)) // POINTER COMPARE! NO RECURSION!
2219 return false; // Missed
2220 return true;
2221 }
2222
2223 //------------------------------hash-------------------------------------------
2224 // Type-specific hashing function.
2225 uint TypeTuple::hash(void) const {
2226 uintptr_t sum = _cnt;
2227 for( uint i=0; i<_cnt; i++ )
2228 sum += (uintptr_t)_fields[i]; // Hash on pointers directly
2229 return (uint)sum;
2230 }
2231
2232 //------------------------------dump2------------------------------------------
2233 // Dump signature Type
2234 #ifndef PRODUCT
2235 void TypeTuple::dump2( Dict &d, uint depth, outputStream *st ) const {
2236 st->print("{");
2237 if( !depth || d[this] ) { // Check for recursive print
2238 st->print("...}");
2239 return;
2240 }
2241 d.Insert((void*)this, (void*)this); // Stop recursion
2242 if( _cnt ) {
2243 uint i;
2244 for( i=0; i<_cnt-1; i++ ) {
2245 st->print("%d:", i);
2246 _fields[i]->dump2(d, depth-1, st);
2247 st->print(", ");
2248 }
2249 st->print("%d:", i);
2250 _fields[i]->dump2(d, depth-1, st);
2251 }
2252 st->print("}");
2253 }
2254 #endif
2255
2256 //------------------------------singleton--------------------------------------
2257 // TRUE if Type is a singleton type, FALSE otherwise. Singletons are simple
2258 // constants (Ldi nodes). Singletons are integer, float or double constants
2259 // or a single symbol.
2260 bool TypeTuple::singleton(void) const {
2261 return false; // Never a singleton
2262 }
2263
2264 bool TypeTuple::empty(void) const {
2265 for( uint i=0; i<_cnt; i++ ) {
2266 if (_fields[i]->empty()) return true;
2267 }
2268 return false;
2269 }
2270
2271 //=============================================================================
2272 // Convenience common pre-built types.
2273
2274 inline const TypeInt* normalize_array_size(const TypeInt* size) {
2275 // Certain normalizations keep us sane when comparing types.
2276 // We do not want arrayOop variables to differ only by the wideness
2277 // of their index types. Pick minimum wideness, since that is the
2278 // forced wideness of small ranges anyway.
2279 if (size->_widen != Type::WidenMin)
2280 return TypeInt::make(size->_lo, size->_hi, Type::WidenMin);
2281 else
2282 return size;
2283 }
2284
2285 //------------------------------make-------------------------------------------
2286 const TypeAry* TypeAry::make(const Type* elem, const TypeInt* size, bool stable) {
2287 if (UseCompressedOops && elem->isa_oopptr()) {
2288 elem = elem->make_narrowoop();
2289 }
2290 size = normalize_array_size(size);
2291 return (TypeAry*)(new TypeAry(elem,size,stable))->hashcons();
2292 }
2293
2294 //------------------------------meet-------------------------------------------
2295 // Compute the MEET of two types. It returns a new Type object.
2296 const Type *TypeAry::xmeet( const Type *t ) const {
2297 // Perform a fast test for common case; meeting the same types together.
2298 if( this == t ) return this; // Meeting same type-rep?
2299
2300 // Current "this->_base" is Ary
2301 switch (t->base()) { // switch on original type
2302
2303 case Bottom: // Ye Olde Default
2304 return t;
2305
2306 default: // All else is a mistake
2307 typerr(t);
2308
2309 case Array: { // Meeting 2 arrays?
2310 const TypeAry* a = t->is_ary();
2311 const Type* size = _size->xmeet(a->_size);
2312 const TypeInt* isize = size->isa_int();
2313 if (isize == nullptr) {
2314 assert(size == Type::TOP || size == Type::BOTTOM, "");
2315 return size;
2316 }
2317 return TypeAry::make(_elem->meet_speculative(a->_elem),
2318 isize, _stable && a->_stable);
2319 }
2320 case Top:
2321 break;
2322 }
2323 return this; // Return the double constant
2324 }
2325
2326 //------------------------------xdual------------------------------------------
2327 // Dual: compute field-by-field dual
2328 const Type *TypeAry::xdual() const {
2329 const TypeInt* size_dual = _size->dual()->is_int();
2330 size_dual = normalize_array_size(size_dual);
2331 return new TypeAry(_elem->dual(), size_dual, !_stable);
2332 }
2333
2334 //------------------------------eq---------------------------------------------
2335 // Structural equality check for Type representations
2336 bool TypeAry::eq( const Type *t ) const {
2337 const TypeAry *a = (const TypeAry*)t;
2338 return _elem == a->_elem &&
2339 _stable == a->_stable &&
2340 _size == a->_size;
2341 }
2342
2343 //------------------------------hash-------------------------------------------
2344 // Type-specific hashing function.
2345 uint TypeAry::hash(void) const {
2346 return (uint)(uintptr_t)_elem + (uint)(uintptr_t)_size + (uint)(_stable ? 43 : 0);
2347 }
2348
2349 /**
2350 * Return same type without a speculative part in the element
2351 */
2352 const TypeAry* TypeAry::remove_speculative() const {
2353 return make(_elem->remove_speculative(), _size, _stable);
2354 }
2355
2356 /**
2357 * Return same type with cleaned up speculative part of element
2358 */
2359 const Type* TypeAry::cleanup_speculative() const {
2360 return make(_elem->cleanup_speculative(), _size, _stable);
2361 }
2362
2363 /**
2364 * Return same type but with a different inline depth (used for speculation)
2365 *
2366 * @param depth depth to meet with
2367 */
2368 const TypePtr* TypePtr::with_inline_depth(int depth) const {
2369 if (!UseInlineDepthForSpeculativeTypes) {
2370 return this;
2371 }
2372 return make(AnyPtr, _ptr, _offset, _speculative, depth);
2373 }
2374
2375 //------------------------------dump2------------------------------------------
2376 #ifndef PRODUCT
2377 void TypeAry::dump2( Dict &d, uint depth, outputStream *st ) const {
2378 if (_stable) st->print("stable:");
2379 _elem->dump2(d, depth, st);
2380 st->print("[");
2381 _size->dump2(d, depth, st);
2382 st->print("]");
2383 }
2384 #endif
2385
2386 //------------------------------singleton--------------------------------------
2387 // TRUE if Type is a singleton type, FALSE otherwise. Singletons are simple
2388 // constants (Ldi nodes). Singletons are integer, float or double constants
2389 // or a single symbol.
2390 bool TypeAry::singleton(void) const {
2391 return false; // Never a singleton
2392 }
2393
2394 bool TypeAry::empty(void) const {
2395 return _elem->empty() || _size->empty();
2396 }
2397
2398 //--------------------------ary_must_be_exact----------------------------------
2399 bool TypeAry::ary_must_be_exact() const {
2400 // This logic looks at the element type of an array, and returns true
2401 // if the element type is either a primitive or a final instance class.
2402 // In such cases, an array built on this ary must have no subclasses.
2403 if (_elem == BOTTOM) return false; // general array not exact
2404 if (_elem == TOP ) return false; // inverted general array not exact
2405 const TypeOopPtr* toop = nullptr;
2406 if (UseCompressedOops && _elem->isa_narrowoop()) {
2407 toop = _elem->make_ptr()->isa_oopptr();
2408 } else {
2409 toop = _elem->isa_oopptr();
2410 }
2411 if (!toop) return true; // a primitive type, like int
2412 if (!toop->is_loaded()) return false; // unloaded class
2413 const TypeInstPtr* tinst;
2414 if (_elem->isa_narrowoop())
2415 tinst = _elem->make_ptr()->isa_instptr();
2416 else
2417 tinst = _elem->isa_instptr();
2418 if (tinst)
2419 return tinst->instance_klass()->is_final();
2420 const TypeAryPtr* tap;
2421 if (_elem->isa_narrowoop())
2422 tap = _elem->make_ptr()->isa_aryptr();
2423 else
2424 tap = _elem->isa_aryptr();
2425 if (tap)
2426 return tap->ary()->ary_must_be_exact();
2427 return false;
2428 }
2429
2430 //==============================TypeVect=======================================
2431 // Convenience common pre-built types.
2432 const TypeVect* TypeVect::VECTA = nullptr; // vector length agnostic
2433 const TypeVect* TypeVect::VECTS = nullptr; // 32-bit vectors
2434 const TypeVect* TypeVect::VECTD = nullptr; // 64-bit vectors
2435 const TypeVect* TypeVect::VECTX = nullptr; // 128-bit vectors
2436 const TypeVect* TypeVect::VECTY = nullptr; // 256-bit vectors
2437 const TypeVect* TypeVect::VECTZ = nullptr; // 512-bit vectors
2438 const TypeVect* TypeVect::VECTMASK = nullptr; // predicate/mask vector
2439
2440 //------------------------------make-------------------------------------------
2441 const TypeVect* TypeVect::make(BasicType elem_bt, uint length, bool is_mask) {
2442 if (is_mask) {
2443 return makemask(elem_bt, length);
2444 }
2445 assert(is_java_primitive(elem_bt), "only primitive types in vector");
2446 assert(Matcher::vector_size_supported(elem_bt, length), "length in range");
2447 int size = length * type2aelembytes(elem_bt);
2448 switch (Matcher::vector_ideal_reg(size)) {
2449 case Op_VecA:
2450 return (TypeVect*)(new TypeVectA(elem_bt, length))->hashcons();
2451 case Op_VecS:
2452 return (TypeVect*)(new TypeVectS(elem_bt, length))->hashcons();
2453 case Op_RegL:
2454 case Op_VecD:
2455 case Op_RegD:
2456 return (TypeVect*)(new TypeVectD(elem_bt, length))->hashcons();
2457 case Op_VecX:
2458 return (TypeVect*)(new TypeVectX(elem_bt, length))->hashcons();
2459 case Op_VecY:
2460 return (TypeVect*)(new TypeVectY(elem_bt, length))->hashcons();
2461 case Op_VecZ:
2462 return (TypeVect*)(new TypeVectZ(elem_bt, length))->hashcons();
2463 }
2464 ShouldNotReachHere();
2465 return nullptr;
2466 }
2467
2468 // Create a vector mask type with the given element basic type and length.
2469 // - Returns "TypePVectMask" (PVectMask) for platforms that support the predicate
2470 // feature and it is implemented properly in the backend, allowing the mask to
2471 // be stored in a predicate/mask register.
2472 // - Returns a normal vector type "TypeVectA ~ TypeVectZ" (NVectMask) otherwise,
2473 // where the vector mask is stored in a vector register.
2474 const TypeVect* TypeVect::makemask(BasicType elem_bt, uint length) {
2475 if (Matcher::has_predicated_vectors() &&
2476 Matcher::match_rule_supported_vector_masked(Op_VectorLoadMask, length, elem_bt)) {
2477 return TypePVectMask::make(elem_bt, length);
2478 } else {
2479 return make(elem_bt, length);
2480 }
2481 }
2482
2483 //------------------------------meet-------------------------------------------
2484 // Compute the MEET of two types. Since each TypeVect is the only instance of
2485 // its species, meeting often returns itself
2486 const Type* TypeVect::xmeet(const Type* t) const {
2487 // Perform a fast test for common case; meeting the same types together.
2488 if (this == t) {
2489 return this;
2490 }
2491
2492 // Current "this->_base" is Vector
2493 switch (t->base()) { // switch on original type
2494
2495 case Bottom: // Ye Olde Default
2496 return t;
2497
2498 default: // All else is a mistake
2499 typerr(t);
2500 case VectorMask:
2501 case VectorA:
2502 case VectorS:
2503 case VectorD:
2504 case VectorX:
2505 case VectorY:
2506 case VectorZ: { // Meeting 2 vectors?
2507 const TypeVect* v = t->is_vect();
2508 assert(base() == v->base(), "");
2509 assert(length() == v->length(), "");
2510 assert(element_basic_type() == v->element_basic_type(), "");
2511 return this;
2512 }
2513 case Top:
2514 break;
2515 }
2516 return this;
2517 }
2518
2519 //------------------------------xdual------------------------------------------
2520 // Since each TypeVect is the only instance of its species, it is self-dual
2521 const Type* TypeVect::xdual() const {
2522 return this;
2523 }
2524
2525 //------------------------------eq---------------------------------------------
2526 // Structural equality check for Type representations
2527 bool TypeVect::eq(const Type* t) const {
2528 const TypeVect* v = t->is_vect();
2529 return (element_basic_type() == v->element_basic_type()) && (length() == v->length());
2530 }
2531
2532 //------------------------------hash-------------------------------------------
2533 // Type-specific hashing function.
2534 uint TypeVect::hash(void) const {
2535 return (uint)base() + (uint)(uintptr_t)_elem_bt + (uint)(uintptr_t)_length;
2536 }
2537
2538 //------------------------------singleton--------------------------------------
2539 // TRUE if Type is a singleton type, FALSE otherwise. Singletons are simple
2540 // constants (Ldi nodes). Vector is singleton if all elements are the same
2541 // constant value (when vector is created with Replicate code).
2542 bool TypeVect::singleton(void) const {
2543 // There is no Con node for vectors yet.
2544 // return _elem->singleton();
2545 return false;
2546 }
2547
2548 bool TypeVect::empty(void) const {
2549 return false;
2550 }
2551
2552 //------------------------------dump2------------------------------------------
2553 #ifndef PRODUCT
2554 void TypeVect::dump2(Dict& d, uint depth, outputStream* st) const {
2555 switch (base()) {
2556 case VectorA:
2557 st->print("vectora"); break;
2558 case VectorS:
2559 st->print("vectors"); break;
2560 case VectorD:
2561 st->print("vectord"); break;
2562 case VectorX:
2563 st->print("vectorx"); break;
2564 case VectorY:
2565 st->print("vectory"); break;
2566 case VectorZ:
2567 st->print("vectorz"); break;
2568 case VectorMask:
2569 st->print("vectormask"); break;
2570 default:
2571 ShouldNotReachHere();
2572 }
2573 st->print("<%c,%u>", type2char(element_basic_type()), length());
2574 }
2575 #endif
2576
2577 const TypePVectMask* TypePVectMask::make(const BasicType elem_bt, uint length) {
2578 return (TypePVectMask*) (new TypePVectMask(elem_bt, length))->hashcons();
2579 }
2580
2581 //=============================================================================
2582 // Convenience common pre-built types.
2583 const TypePtr *TypePtr::NULL_PTR;
2584 const TypePtr *TypePtr::NOTNULL;
2585 const TypePtr *TypePtr::BOTTOM;
2586
2587 //------------------------------meet-------------------------------------------
2588 // Meet over the PTR enum
2589 const TypePtr::PTR TypePtr::ptr_meet[TypePtr::lastPTR][TypePtr::lastPTR] = {
2590 // TopPTR, AnyNull, Constant, Null, NotNull, BotPTR,
2591 { /* Top */ TopPTR, AnyNull, Constant, Null, NotNull, BotPTR,},
2592 { /* AnyNull */ AnyNull, AnyNull, Constant, BotPTR, NotNull, BotPTR,},
2593 { /* Constant*/ Constant, Constant, Constant, BotPTR, NotNull, BotPTR,},
2594 { /* Null */ Null, BotPTR, BotPTR, Null, BotPTR, BotPTR,},
2595 { /* NotNull */ NotNull, NotNull, NotNull, BotPTR, NotNull, BotPTR,},
2596 { /* BotPTR */ BotPTR, BotPTR, BotPTR, BotPTR, BotPTR, BotPTR,}
2597 };
2598
2599 //------------------------------make-------------------------------------------
2600 const TypePtr *TypePtr::make(TYPES t, enum PTR ptr, int offset, const TypePtr* speculative, int inline_depth) {
2601 return (TypePtr*)(new TypePtr(t,ptr,offset, speculative, inline_depth))->hashcons();
2602 }
2603
2604 //------------------------------cast_to_ptr_type-------------------------------
2605 const TypePtr* TypePtr::cast_to_ptr_type(PTR ptr) const {
2606 assert(_base == AnyPtr, "subclass must override cast_to_ptr_type");
2607 if( ptr == _ptr ) return this;
2608 return make(_base, ptr, _offset, _speculative, _inline_depth);
2609 }
2610
2611 //------------------------------get_con----------------------------------------
2612 intptr_t TypePtr::get_con() const {
2613 assert( _ptr == Null, "" );
2614 return _offset;
2615 }
2616
2617 //------------------------------meet-------------------------------------------
2618 // Compute the MEET of two types. It returns a new Type object.
2619 const Type *TypePtr::xmeet(const Type *t) const {
2620 const Type* res = xmeet_helper(t);
2621 if (res->isa_ptr() == nullptr) {
2622 return res;
2623 }
2624
2625 const TypePtr* res_ptr = res->is_ptr();
2626 if (res_ptr->speculative() != nullptr) {
2627 // type->speculative() is null means that speculation is no better
2628 // than type, i.e. type->speculative() == type. So there are 2
2629 // ways to represent the fact that we have no useful speculative
2630 // data and we should use a single one to be able to test for
2631 // equality between types. Check whether type->speculative() ==
2632 // type and set speculative to null if it is the case.
2633 if (res_ptr->remove_speculative() == res_ptr->speculative()) {
2634 return res_ptr->remove_speculative();
2635 }
2636 }
2637
2638 return res;
2639 }
2640
2641 const Type *TypePtr::xmeet_helper(const Type *t) const {
2642 // Perform a fast test for common case; meeting the same types together.
2643 if( this == t ) return this; // Meeting same type-rep?
2644
2645 // Current "this->_base" is AnyPtr
2646 switch (t->base()) { // switch on original type
2647 case Int: // Mixing ints & oops happens when javac
2648 case Long: // reuses local variables
2649 case HalfFloatTop:
2650 case HalfFloatCon:
2651 case HalfFloatBot:
2652 case FloatTop:
2653 case FloatCon:
2654 case FloatBot:
2655 case DoubleTop:
2656 case DoubleCon:
2657 case DoubleBot:
2658 case NarrowOop:
2659 case NarrowKlass:
2660 case Bottom: // Ye Olde Default
2661 return Type::BOTTOM;
2662 case Top:
2663 return this;
2664
2665 case AnyPtr: { // Meeting to AnyPtrs
2666 const TypePtr *tp = t->is_ptr();
2667 const TypePtr* speculative = xmeet_speculative(tp);
2668 int depth = meet_inline_depth(tp->inline_depth());
2669 return make(AnyPtr, meet_ptr(tp->ptr()), meet_offset(tp->offset()), speculative, depth);
2670 }
2671 case RawPtr: // For these, flip the call around to cut down
2672 case OopPtr:
2673 case InstPtr: // on the cases I have to handle.
2674 case AryPtr:
2675 case MetadataPtr:
2676 case KlassPtr:
2677 case InstKlassPtr:
2678 case AryKlassPtr:
2679 return t->xmeet(this); // Call in reverse direction
2680 default: // All else is a mistake
2681 typerr(t);
2682
2683 }
2684 return this;
2685 }
2686
2687 //------------------------------meet_offset------------------------------------
2688 int TypePtr::meet_offset( int offset ) const {
2689 // Either is 'TOP' offset? Return the other offset!
2690 if( _offset == OffsetTop ) return offset;
2691 if( offset == OffsetTop ) return _offset;
2692 // If either is different, return 'BOTTOM' offset
2693 if( _offset != offset ) return OffsetBot;
2694 return _offset;
2695 }
2696
2697 //------------------------------dual_offset------------------------------------
2698 int TypePtr::dual_offset( ) const {
2699 if( _offset == OffsetTop ) return OffsetBot;// Map 'TOP' into 'BOTTOM'
2700 if( _offset == OffsetBot ) return OffsetTop;// Map 'BOTTOM' into 'TOP'
2701 return _offset; // Map everything else into self
2702 }
2703
2704 //------------------------------xdual------------------------------------------
2705 // Dual: compute field-by-field dual
2706 const TypePtr::PTR TypePtr::ptr_dual[TypePtr::lastPTR] = {
2707 BotPTR, NotNull, Constant, Null, AnyNull, TopPTR
2708 };
2709 const Type *TypePtr::xdual() const {
2710 return new TypePtr(AnyPtr, dual_ptr(), dual_offset(), dual_speculative(), dual_inline_depth());
2711 }
2712
2713 //------------------------------xadd_offset------------------------------------
2714 int TypePtr::xadd_offset( intptr_t offset ) const {
2715 // Adding to 'TOP' offset? Return 'TOP'!
2716 if( _offset == OffsetTop || offset == OffsetTop ) return OffsetTop;
2717 // Adding to 'BOTTOM' offset? Return 'BOTTOM'!
2718 if( _offset == OffsetBot || offset == OffsetBot ) return OffsetBot;
2719 // Addition overflows or "accidentally" equals to OffsetTop? Return 'BOTTOM'!
2720 offset += (intptr_t)_offset;
2721 if (offset != (int)offset || offset == OffsetTop) return OffsetBot;
2722
2723 // assert( _offset >= 0 && _offset+offset >= 0, "" );
2724 // It is possible to construct a negative offset during PhaseCCP
2725
2726 return (int)offset; // Sum valid offsets
2727 }
2728
2729 //------------------------------add_offset-------------------------------------
2730 const TypePtr *TypePtr::add_offset( intptr_t offset ) const {
2731 return make(AnyPtr, _ptr, xadd_offset(offset), _speculative, _inline_depth);
2732 }
2733
2734 const TypePtr *TypePtr::with_offset(intptr_t offset) const {
2735 return make(AnyPtr, _ptr, offset, _speculative, _inline_depth);
2736 }
2737
2738 //------------------------------eq---------------------------------------------
2739 // Structural equality check for Type representations
2740 bool TypePtr::eq( const Type *t ) const {
2741 const TypePtr *a = (const TypePtr*)t;
2742 return _ptr == a->ptr() && _offset == a->offset() && eq_speculative(a) && _inline_depth == a->_inline_depth;
2743 }
2744
2745 //------------------------------hash-------------------------------------------
2746 // Type-specific hashing function.
2747 uint TypePtr::hash(void) const {
2748 return (uint)_ptr + (uint)_offset + (uint)hash_speculative() + (uint)_inline_depth;
2749 }
2750
2751 /**
2752 * Return same type without a speculative part
2753 */
2754 const TypePtr* TypePtr::remove_speculative() const {
2755 if (_speculative == nullptr) {
2756 return this;
2757 }
2758 assert(_inline_depth == InlineDepthTop || _inline_depth == InlineDepthBottom, "non speculative type shouldn't have inline depth");
2759 return make(AnyPtr, _ptr, _offset, nullptr, _inline_depth);
2760 }
2761
2762 /**
2763 * Return same type but drop speculative part if we know we won't use
2764 * it
2765 */
2766 const Type* TypePtr::cleanup_speculative() const {
2767 if (speculative() == nullptr) {
2768 return this;
2769 }
2770 const Type* no_spec = remove_speculative();
2771 // If this is NULL_PTR then we don't need the speculative type
2772 // (with_inline_depth in case the current type inline depth is
2773 // InlineDepthTop)
2774 if (no_spec == NULL_PTR->with_inline_depth(inline_depth())) {
2775 return no_spec;
2776 }
2777 if (above_centerline(speculative()->ptr())) {
2778 return no_spec;
2779 }
2780 const TypeOopPtr* spec_oopptr = speculative()->isa_oopptr();
2781 // If the speculative may be null and is an inexact klass then it
2782 // doesn't help
2783 if (speculative() != TypePtr::NULL_PTR && speculative()->maybe_null() &&
2784 (spec_oopptr == nullptr || !spec_oopptr->klass_is_exact())) {
2785 return no_spec;
2786 }
2787 return this;
2788 }
2789
2790 /**
2791 * dual of the speculative part of the type
2792 */
2793 const TypePtr* TypePtr::dual_speculative() const {
2794 if (_speculative == nullptr) {
2795 return nullptr;
2796 }
2797 return _speculative->dual()->is_ptr();
2798 }
2799
2800 /**
2801 * meet of the speculative parts of 2 types
2802 *
2803 * @param other type to meet with
2804 */
2805 const TypePtr* TypePtr::xmeet_speculative(const TypePtr* other) const {
2806 bool this_has_spec = (_speculative != nullptr);
2807 bool other_has_spec = (other->speculative() != nullptr);
2808
2809 if (!this_has_spec && !other_has_spec) {
2810 return nullptr;
2811 }
2812
2813 // If we are at a point where control flow meets and one branch has
2814 // a speculative type and the other has not, we meet the speculative
2815 // type of one branch with the actual type of the other. If the
2816 // actual type is exact and the speculative is as well, then the
2817 // result is a speculative type which is exact and we can continue
2818 // speculation further.
2819 const TypePtr* this_spec = _speculative;
2820 const TypePtr* other_spec = other->speculative();
2821
2822 if (!this_has_spec) {
2823 this_spec = this;
2824 }
2825
2826 if (!other_has_spec) {
2827 other_spec = other;
2828 }
2829
2830 return this_spec->meet(other_spec)->is_ptr();
2831 }
2832
2833 /**
2834 * dual of the inline depth for this type (used for speculation)
2835 */
2836 int TypePtr::dual_inline_depth() const {
2837 return -inline_depth();
2838 }
2839
2840 /**
2841 * meet of 2 inline depths (used for speculation)
2842 *
2843 * @param depth depth to meet with
2844 */
2845 int TypePtr::meet_inline_depth(int depth) const {
2846 return MAX2(inline_depth(), depth);
2847 }
2848
2849 /**
2850 * Are the speculative parts of 2 types equal?
2851 *
2852 * @param other type to compare this one to
2853 */
2854 bool TypePtr::eq_speculative(const TypePtr* other) const {
2855 if (_speculative == nullptr || other->speculative() == nullptr) {
2856 return _speculative == other->speculative();
2857 }
2858
2859 if (_speculative->base() != other->speculative()->base()) {
2860 return false;
2861 }
2862
2863 return _speculative->eq(other->speculative());
2864 }
2865
2866 /**
2867 * Hash of the speculative part of the type
2868 */
2869 int TypePtr::hash_speculative() const {
2870 if (_speculative == nullptr) {
2871 return 0;
2872 }
2873
2874 return _speculative->hash();
2875 }
2876
2877 /**
2878 * add offset to the speculative part of the type
2879 *
2880 * @param offset offset to add
2881 */
2882 const TypePtr* TypePtr::add_offset_speculative(intptr_t offset) const {
2883 if (_speculative == nullptr) {
2884 return nullptr;
2885 }
2886 return _speculative->add_offset(offset)->is_ptr();
2887 }
2888
2889 const TypePtr* TypePtr::with_offset_speculative(intptr_t offset) const {
2890 if (_speculative == nullptr) {
2891 return nullptr;
2892 }
2893 return _speculative->with_offset(offset)->is_ptr();
2894 }
2895
2896 /**
2897 * return exact klass from the speculative type if there's one
2898 */
2899 ciKlass* TypePtr::speculative_type() const {
2900 if (_speculative != nullptr && _speculative->isa_oopptr()) {
2901 const TypeOopPtr* speculative = _speculative->join(this)->is_oopptr();
2902 if (speculative->klass_is_exact()) {
2903 return speculative->exact_klass();
2904 }
2905 }
2906 return nullptr;
2907 }
2908
2909 /**
2910 * return true if speculative type may be null
2911 */
2912 bool TypePtr::speculative_maybe_null() const {
2913 if (_speculative != nullptr) {
2914 const TypePtr* speculative = _speculative->join(this)->is_ptr();
2915 return speculative->maybe_null();
2916 }
2917 return true;
2918 }
2919
2920 bool TypePtr::speculative_always_null() const {
2921 if (_speculative != nullptr) {
2922 const TypePtr* speculative = _speculative->join(this)->is_ptr();
2923 return speculative == TypePtr::NULL_PTR;
2924 }
2925 return false;
2926 }
2927
2928 /**
2929 * Same as TypePtr::speculative_type() but return the klass only if
2930 * the speculative tells us is not null
2931 */
2932 ciKlass* TypePtr::speculative_type_not_null() const {
2933 if (speculative_maybe_null()) {
2934 return nullptr;
2935 }
2936 return speculative_type();
2937 }
2938
2939 /**
2940 * Check whether new profiling would improve speculative type
2941 *
2942 * @param exact_kls class from profiling
2943 * @param inline_depth inlining depth of profile point
2944 *
2945 * @return true if type profile is valuable
2946 */
2947 bool TypePtr::would_improve_type(ciKlass* exact_kls, int inline_depth) const {
2948 // no profiling?
2949 if (exact_kls == nullptr) {
2950 return false;
2951 }
2952 if (speculative() == TypePtr::NULL_PTR) {
2953 return false;
2954 }
2955 // no speculative type or non exact speculative type?
2956 if (speculative_type() == nullptr) {
2957 return true;
2958 }
2959 // If the node already has an exact speculative type keep it,
2960 // unless it was provided by profiling that is at a deeper
2961 // inlining level. Profiling at a higher inlining depth is
2962 // expected to be less accurate.
2963 if (_speculative->inline_depth() == InlineDepthBottom) {
2964 return false;
2965 }
2966 assert(_speculative->inline_depth() != InlineDepthTop, "can't do the comparison");
2967 return inline_depth < _speculative->inline_depth();
2968 }
2969
2970 /**
2971 * Check whether new profiling would improve ptr (= tells us it is non
2972 * null)
2973 *
2974 * @param ptr_kind always null or not null?
2975 *
2976 * @return true if ptr profile is valuable
2977 */
2978 bool TypePtr::would_improve_ptr(ProfilePtrKind ptr_kind) const {
2979 // profiling doesn't tell us anything useful
2980 if (ptr_kind != ProfileAlwaysNull && ptr_kind != ProfileNeverNull) {
2981 return false;
2982 }
2983 // We already know this is not null
2984 if (!this->maybe_null()) {
2985 return false;
2986 }
2987 // We already know the speculative type cannot be null
2988 if (!speculative_maybe_null()) {
2989 return false;
2990 }
2991 // We already know this is always null
2992 if (this == TypePtr::NULL_PTR) {
2993 return false;
2994 }
2995 // We already know the speculative type is always null
2996 if (speculative_always_null()) {
2997 return false;
2998 }
2999 if (ptr_kind == ProfileAlwaysNull && speculative() != nullptr && speculative()->isa_oopptr()) {
3000 return false;
3001 }
3002 return true;
3003 }
3004
3005 //------------------------------dump2------------------------------------------
3006 const char *const TypePtr::ptr_msg[TypePtr::lastPTR] = {
3007 "TopPTR","AnyNull","Constant","null","NotNull","BotPTR"
3008 };
3009
3010 #ifndef PRODUCT
3011 void TypePtr::dump2( Dict &d, uint depth, outputStream *st ) const {
3012 st->print("ptr:%s", ptr_msg[_ptr]);
3013 dump_offset(st);
3014 dump_inline_depth(st);
3015 dump_speculative(st);
3016 }
3017
3018 void TypePtr::dump_offset(outputStream* st) const {
3019 if (_offset == OffsetBot) {
3020 st->print("+bot");
3021 } else if (_offset == OffsetTop) {
3022 st->print("+top");
3023 } else {
3024 st->print("+%d", _offset);
3025 }
3026 }
3027
3028 /**
3029 *dump the speculative part of the type
3030 */
3031 void TypePtr::dump_speculative(outputStream *st) const {
3032 if (_speculative != nullptr) {
3033 st->print(" (speculative=");
3034 _speculative->dump_on(st);
3035 st->print(")");
3036 }
3037 }
3038
3039 /**
3040 *dump the inline depth of the type
3041 */
3042 void TypePtr::dump_inline_depth(outputStream *st) const {
3043 if (_inline_depth != InlineDepthBottom) {
3044 if (_inline_depth == InlineDepthTop) {
3045 st->print(" (inline_depth=InlineDepthTop)");
3046 } else {
3047 st->print(" (inline_depth=%d)", _inline_depth);
3048 }
3049 }
3050 }
3051 #endif
3052
3053 //------------------------------singleton--------------------------------------
3054 // TRUE if Type is a singleton type, FALSE otherwise. Singletons are simple
3055 // constants
3056 bool TypePtr::singleton(void) const {
3057 // TopPTR, Null, AnyNull, Constant are all singletons
3058 return (_offset != OffsetBot) && !below_centerline(_ptr);
3059 }
3060
3061 bool TypePtr::empty(void) const {
3062 return (_offset == OffsetTop) || above_centerline(_ptr);
3063 }
3064
3065 //=============================================================================
3066 // Convenience common pre-built types.
3067 const TypeRawPtr *TypeRawPtr::BOTTOM;
3068 const TypeRawPtr *TypeRawPtr::NOTNULL;
3069
3070 //------------------------------make-------------------------------------------
3071 const TypeRawPtr *TypeRawPtr::make( enum PTR ptr ) {
3072 assert( ptr != Constant, "what is the constant?" );
3073 assert( ptr != Null, "Use TypePtr for null" );
3074 return (TypeRawPtr*)(new TypeRawPtr(ptr,nullptr))->hashcons();
3075 }
3076
3077 const TypeRawPtr *TypeRawPtr::make(address bits) {
3078 assert(bits != nullptr, "Use TypePtr for null");
3079 return (TypeRawPtr*)(new TypeRawPtr(Constant,bits))->hashcons();
3080 }
3081
3082 //------------------------------cast_to_ptr_type-------------------------------
3083 const TypeRawPtr* TypeRawPtr::cast_to_ptr_type(PTR ptr) const {
3084 assert( ptr != Constant, "what is the constant?" );
3085 assert( ptr != Null, "Use TypePtr for null" );
3086 assert( _bits == nullptr, "Why cast a constant address?");
3087 if( ptr == _ptr ) return this;
3088 return make(ptr);
3089 }
3090
3091 //------------------------------get_con----------------------------------------
3092 intptr_t TypeRawPtr::get_con() const {
3093 assert( _ptr == Null || _ptr == Constant, "" );
3094 return (intptr_t)_bits;
3095 }
3096
3097 //------------------------------meet-------------------------------------------
3098 // Compute the MEET of two types. It returns a new Type object.
3099 const Type *TypeRawPtr::xmeet( const Type *t ) const {
3100 // Perform a fast test for common case; meeting the same types together.
3101 if( this == t ) return this; // Meeting same type-rep?
3102
3103 // Current "this->_base" is RawPtr
3104 switch( t->base() ) { // switch on original type
3105 case Bottom: // Ye Olde Default
3106 return t;
3107 case Top:
3108 return this;
3109 case AnyPtr: // Meeting to AnyPtrs
3110 break;
3111 case RawPtr: { // might be top, bot, any/not or constant
3112 enum PTR tptr = t->is_ptr()->ptr();
3113 enum PTR ptr = meet_ptr( tptr );
3114 if( ptr == Constant ) { // Cannot be equal constants, so...
3115 if( tptr == Constant && _ptr != Constant) return t;
3116 if( _ptr == Constant && tptr != Constant) return this;
3117 ptr = NotNull; // Fall down in lattice
3118 }
3119 return make( ptr );
3120 }
3121
3122 case OopPtr:
3123 case InstPtr:
3124 case AryPtr:
3125 case MetadataPtr:
3126 case KlassPtr:
3127 case InstKlassPtr:
3128 case AryKlassPtr:
3129 return TypePtr::BOTTOM; // Oop meet raw is not well defined
3130 default: // All else is a mistake
3131 typerr(t);
3132 }
3133
3134 // Found an AnyPtr type vs self-RawPtr type
3135 const TypePtr *tp = t->is_ptr();
3136 switch (tp->ptr()) {
3137 case TypePtr::TopPTR: return this;
3138 case TypePtr::BotPTR: return t;
3139 case TypePtr::Null:
3140 if( _ptr == TypePtr::TopPTR ) return t;
3141 return TypeRawPtr::BOTTOM;
3142 case TypePtr::NotNull: return TypePtr::make(AnyPtr, meet_ptr(TypePtr::NotNull), tp->meet_offset(0), tp->speculative(), tp->inline_depth());
3143 case TypePtr::AnyNull:
3144 if( _ptr == TypePtr::Constant) return this;
3145 return make( meet_ptr(TypePtr::AnyNull) );
3146 default: ShouldNotReachHere();
3147 }
3148 return this;
3149 }
3150
3151 //------------------------------xdual------------------------------------------
3152 // Dual: compute field-by-field dual
3153 const Type *TypeRawPtr::xdual() const {
3154 return new TypeRawPtr( dual_ptr(), _bits );
3155 }
3156
3157 //------------------------------add_offset-------------------------------------
3158 const TypePtr* TypeRawPtr::add_offset(intptr_t offset) const {
3159 if( offset == OffsetTop ) return BOTTOM; // Undefined offset-> undefined pointer
3160 if( offset == OffsetBot ) return BOTTOM; // Unknown offset-> unknown pointer
3161 if( offset == 0 ) return this; // No change
3162 switch (_ptr) {
3163 case TypePtr::TopPTR:
3164 case TypePtr::BotPTR:
3165 case TypePtr::NotNull:
3166 return this;
3167 case TypePtr::Constant: {
3168 uintptr_t bits = (uintptr_t)_bits;
3169 uintptr_t sum = bits + offset;
3170 if (( offset < 0 )
3171 ? ( sum > bits ) // Underflow?
3172 : ( sum < bits )) { // Overflow?
3173 return BOTTOM;
3174 } else if ( sum == 0 ) {
3175 return TypePtr::NULL_PTR;
3176 } else {
3177 return make( (address)sum );
3178 }
3179 }
3180 default: ShouldNotReachHere();
3181 }
3182 }
3183
3184 //------------------------------eq---------------------------------------------
3185 // Structural equality check for Type representations
3186 bool TypeRawPtr::eq( const Type *t ) const {
3187 const TypeRawPtr *a = (const TypeRawPtr*)t;
3188 return _bits == a->_bits && TypePtr::eq(t);
3189 }
3190
3191 //------------------------------hash-------------------------------------------
3192 // Type-specific hashing function.
3193 uint TypeRawPtr::hash(void) const {
3194 return (uint)(uintptr_t)_bits + (uint)TypePtr::hash();
3195 }
3196
3197 //------------------------------dump2------------------------------------------
3198 #ifndef PRODUCT
3199 void TypeRawPtr::dump2(Dict& d, uint depth, outputStream* st) const {
3200 if (_ptr == Constant) {
3201 st->print("rawptr:Constant:" INTPTR_FORMAT, p2i(_bits));
3202 } else {
3203 st->print("rawptr:%s", ptr_msg[_ptr]);
3204 }
3205 }
3206 #endif
3207
3208 //=============================================================================
3209 // Convenience common pre-built type.
3210 const TypeOopPtr *TypeOopPtr::BOTTOM;
3211
3212 TypeInterfaces::TypeInterfaces(ciInstanceKlass** interfaces_base, int nb_interfaces)
3213 : Type(Interfaces), _interfaces(interfaces_base, nb_interfaces),
3214 _hash(0), _exact_klass(nullptr) {
3215 _interfaces.sort(compare);
3216 initialize();
3217 }
3218
3219 const TypeInterfaces* TypeInterfaces::make(GrowableArray<ciInstanceKlass*>* interfaces) {
3220 // hashcons() can only delete the last thing that was allocated: to
3221 // make sure all memory for the newly created TypeInterfaces can be
3222 // freed if an identical one exists, allocate space for the array of
3223 // interfaces right after the TypeInterfaces object so that they
3224 // form a contiguous piece of memory.
3225 int nb_interfaces = interfaces == nullptr ? 0 : interfaces->length();
3226 size_t total_size = sizeof(TypeInterfaces) + nb_interfaces * sizeof(ciInstanceKlass*);
3227
3228 void* allocated_mem = operator new(total_size);
3229 ciInstanceKlass** interfaces_base = (ciInstanceKlass**)((char*)allocated_mem + sizeof(TypeInterfaces));
3230 for (int i = 0; i < nb_interfaces; ++i) {
3231 interfaces_base[i] = interfaces->at(i);
3232 }
3233 TypeInterfaces* result = ::new (allocated_mem) TypeInterfaces(interfaces_base, nb_interfaces);
3234 return (const TypeInterfaces*)result->hashcons();
3235 }
3236
3237 void TypeInterfaces::initialize() {
3238 compute_hash();
3239 compute_exact_klass();
3240 DEBUG_ONLY(_initialized = true;)
3241 }
3242
3243 int TypeInterfaces::compare(ciInstanceKlass* const& k1, ciInstanceKlass* const& k2) {
3244 if ((intptr_t)k1 < (intptr_t)k2) {
3245 return -1;
3246 } else if ((intptr_t)k1 > (intptr_t)k2) {
3247 return 1;
3248 }
3249 return 0;
3250 }
3251
3252 int TypeInterfaces::compare(ciInstanceKlass** k1, ciInstanceKlass** k2) {
3253 return compare(*k1, *k2);
3254 }
3255
3256 bool TypeInterfaces::eq(const Type* t) const {
3257 const TypeInterfaces* other = (const TypeInterfaces*)t;
3258 if (_interfaces.length() != other->_interfaces.length()) {
3259 return false;
3260 }
3261 for (int i = 0; i < _interfaces.length(); i++) {
3262 ciKlass* k1 = _interfaces.at(i);
3263 ciKlass* k2 = other->_interfaces.at(i);
3264 if (!k1->equals(k2)) {
3265 return false;
3266 }
3267 }
3268 return true;
3269 }
3270
3271 bool TypeInterfaces::eq(ciInstanceKlass* k) const {
3272 assert(k->is_loaded(), "should be loaded");
3273 GrowableArray<ciInstanceKlass *>* interfaces = k->transitive_interfaces();
3274 if (_interfaces.length() != interfaces->length()) {
3275 return false;
3276 }
3277 for (int i = 0; i < interfaces->length(); i++) {
3278 bool found = false;
3279 _interfaces.find_sorted<ciInstanceKlass*, compare>(interfaces->at(i), found);
3280 if (!found) {
3281 return false;
3282 }
3283 }
3284 return true;
3285 }
3286
3287
3288 uint TypeInterfaces::hash() const {
3289 assert(_initialized, "must be");
3290 return _hash;
3291 }
3292
3293 const Type* TypeInterfaces::xdual() const {
3294 return this;
3295 }
3296
3297 void TypeInterfaces::compute_hash() {
3298 uint hash = 0;
3299 for (int i = 0; i < _interfaces.length(); i++) {
3300 ciKlass* k = _interfaces.at(i);
3301 hash += k->hash();
3302 }
3303 _hash = hash;
3304 }
3305
3306 static int compare_interfaces(ciInstanceKlass** k1, ciInstanceKlass** k2) {
3307 return (int)((*k1)->ident() - (*k2)->ident());
3308 }
3309
3310 void TypeInterfaces::dump(outputStream* st) const {
3311 if (_interfaces.length() == 0) {
3312 return;
3313 }
3314 ResourceMark rm;
3315 st->print(" (");
3316 GrowableArray<ciInstanceKlass*> interfaces;
3317 interfaces.appendAll(&_interfaces);
3318 // Sort the interfaces so they are listed in the same order from one run to the other of the same compilation
3319 interfaces.sort(compare_interfaces);
3320 for (int i = 0; i < interfaces.length(); i++) {
3321 if (i > 0) {
3322 st->print(",");
3323 }
3324 ciKlass* k = interfaces.at(i);
3325 k->print_name_on(st);
3326 }
3327 st->print(")");
3328 }
3329
3330 #ifdef ASSERT
3331 void TypeInterfaces::verify() const {
3332 for (int i = 1; i < _interfaces.length(); i++) {
3333 ciInstanceKlass* k1 = _interfaces.at(i-1);
3334 ciInstanceKlass* k2 = _interfaces.at(i);
3335 assert(compare(k2, k1) > 0, "should be ordered");
3336 assert(k1 != k2, "no duplicate");
3337 }
3338 }
3339 #endif
3340
3341 const TypeInterfaces* TypeInterfaces::union_with(const TypeInterfaces* other) const {
3342 GrowableArray<ciInstanceKlass*> result_list;
3343 int i = 0;
3344 int j = 0;
3345 while (i < _interfaces.length() || j < other->_interfaces.length()) {
3346 while (i < _interfaces.length() &&
3347 (j >= other->_interfaces.length() ||
3348 compare(_interfaces.at(i), other->_interfaces.at(j)) < 0)) {
3349 result_list.push(_interfaces.at(i));
3350 i++;
3351 }
3352 while (j < other->_interfaces.length() &&
3353 (i >= _interfaces.length() ||
3354 compare(other->_interfaces.at(j), _interfaces.at(i)) < 0)) {
3355 result_list.push(other->_interfaces.at(j));
3356 j++;
3357 }
3358 if (i < _interfaces.length() &&
3359 j < other->_interfaces.length() &&
3360 _interfaces.at(i) == other->_interfaces.at(j)) {
3361 result_list.push(_interfaces.at(i));
3362 i++;
3363 j++;
3364 }
3365 }
3366 const TypeInterfaces* result = TypeInterfaces::make(&result_list);
3367 #ifdef ASSERT
3368 result->verify();
3369 for (int i = 0; i < _interfaces.length(); i++) {
3370 assert(result->_interfaces.contains(_interfaces.at(i)), "missing");
3371 }
3372 for (int i = 0; i < other->_interfaces.length(); i++) {
3373 assert(result->_interfaces.contains(other->_interfaces.at(i)), "missing");
3374 }
3375 for (int i = 0; i < result->_interfaces.length(); i++) {
3376 assert(_interfaces.contains(result->_interfaces.at(i)) || other->_interfaces.contains(result->_interfaces.at(i)), "missing");
3377 }
3378 #endif
3379 return result;
3380 }
3381
3382 const TypeInterfaces* TypeInterfaces::intersection_with(const TypeInterfaces* other) const {
3383 GrowableArray<ciInstanceKlass*> result_list;
3384 int i = 0;
3385 int j = 0;
3386 while (i < _interfaces.length() || j < other->_interfaces.length()) {
3387 while (i < _interfaces.length() &&
3388 (j >= other->_interfaces.length() ||
3389 compare(_interfaces.at(i), other->_interfaces.at(j)) < 0)) {
3390 i++;
3391 }
3392 while (j < other->_interfaces.length() &&
3393 (i >= _interfaces.length() ||
3394 compare(other->_interfaces.at(j), _interfaces.at(i)) < 0)) {
3395 j++;
3396 }
3397 if (i < _interfaces.length() &&
3398 j < other->_interfaces.length() &&
3399 _interfaces.at(i) == other->_interfaces.at(j)) {
3400 result_list.push(_interfaces.at(i));
3401 i++;
3402 j++;
3403 }
3404 }
3405 const TypeInterfaces* result = TypeInterfaces::make(&result_list);
3406 #ifdef ASSERT
3407 result->verify();
3408 for (int i = 0; i < _interfaces.length(); i++) {
3409 assert(!other->_interfaces.contains(_interfaces.at(i)) || result->_interfaces.contains(_interfaces.at(i)), "missing");
3410 }
3411 for (int i = 0; i < other->_interfaces.length(); i++) {
3412 assert(!_interfaces.contains(other->_interfaces.at(i)) || result->_interfaces.contains(other->_interfaces.at(i)), "missing");
3413 }
3414 for (int i = 0; i < result->_interfaces.length(); i++) {
3415 assert(_interfaces.contains(result->_interfaces.at(i)) && other->_interfaces.contains(result->_interfaces.at(i)), "missing");
3416 }
3417 #endif
3418 return result;
3419 }
3420
3421 // Is there a single ciKlass* that can represent the interface set?
3422 ciInstanceKlass* TypeInterfaces::exact_klass() const {
3423 assert(_initialized, "must be");
3424 return _exact_klass;
3425 }
3426
3427 void TypeInterfaces::compute_exact_klass() {
3428 if (_interfaces.length() == 0) {
3429 _exact_klass = nullptr;
3430 return;
3431 }
3432 ciInstanceKlass* res = nullptr;
3433 for (int i = 0; i < _interfaces.length(); i++) {
3434 ciInstanceKlass* interface = _interfaces.at(i);
3435 if (eq(interface)) {
3436 assert(res == nullptr, "");
3437 res = interface;
3438 }
3439 }
3440 _exact_klass = res;
3441 }
3442
3443 #ifdef ASSERT
3444 void TypeInterfaces::verify_is_loaded() const {
3445 for (int i = 0; i < _interfaces.length(); i++) {
3446 ciKlass* interface = _interfaces.at(i);
3447 assert(interface->is_loaded(), "Interface not loaded");
3448 }
3449 }
3450 #endif
3451
3452 // Can't be implemented because there's no way to know if the type is above or below the center line.
3453 const Type* TypeInterfaces::xmeet(const Type* t) const {
3454 ShouldNotReachHere();
3455 return Type::xmeet(t);
3456 }
3457
3458 bool TypeInterfaces::singleton(void) const {
3459 ShouldNotReachHere();
3460 return Type::singleton();
3461 }
3462
3463 bool TypeInterfaces::has_non_array_interface() const {
3464 assert(TypeAryPtr::_array_interfaces != nullptr, "How come Type::Initialize_shared wasn't called yet?");
3465
3466 return !TypeAryPtr::_array_interfaces->contains(this);
3467 }
3468
3469 //------------------------------TypeOopPtr-------------------------------------
3470 TypeOopPtr::TypeOopPtr(TYPES t, PTR ptr, ciKlass* k, const TypeInterfaces* interfaces, bool xk, ciObject* o, int offset,
3471 int instance_id, const TypePtr* speculative, int inline_depth)
3472 : TypePtr(t, ptr, offset, speculative, inline_depth),
3473 _const_oop(o), _klass(k),
3474 _interfaces(interfaces),
3475 _klass_is_exact(xk),
3476 _is_ptr_to_narrowoop(false),
3477 _is_ptr_to_narrowklass(false),
3478 _is_ptr_to_boxed_value(false),
3479 _instance_id(instance_id) {
3480 #ifdef ASSERT
3481 if (klass() != nullptr && klass()->is_loaded()) {
3482 interfaces->verify_is_loaded();
3483 }
3484 #endif
3485 if (Compile::current()->eliminate_boxing() && (t == InstPtr) &&
3486 (offset > 0) && xk && (k != nullptr) && k->is_instance_klass()) {
3487 _is_ptr_to_boxed_value = k->as_instance_klass()->is_boxed_value_offset(offset);
3488 }
3489 #ifdef _LP64
3490 if (_offset > 0 || _offset == Type::OffsetTop || _offset == Type::OffsetBot) {
3491 if (_offset == Type::klass_offset()) {
3492 _is_ptr_to_narrowklass = true;
3493 } else if (klass() == nullptr) {
3494 // Array with unknown body type
3495 assert(this->isa_aryptr(), "only arrays without klass");
3496 _is_ptr_to_narrowoop = UseCompressedOops;
3497 } else if (this->isa_aryptr()) {
3498 _is_ptr_to_narrowoop = (UseCompressedOops && klass()->is_obj_array_klass() &&
3499 _offset != arrayOopDesc::length_offset_in_bytes());
3500 } else if (klass()->is_instance_klass()) {
3501 ciInstanceKlass* ik = klass()->as_instance_klass();
3502 if (this->isa_klassptr()) {
3503 // Perm objects don't use compressed references
3504 } else if (_offset == OffsetBot || _offset == OffsetTop) {
3505 // unsafe access
3506 _is_ptr_to_narrowoop = UseCompressedOops;
3507 } else {
3508 assert(this->isa_instptr(), "must be an instance ptr.");
3509
3510 if (klass() == ciEnv::current()->Class_klass() &&
3511 (_offset == java_lang_Class::klass_offset() ||
3512 _offset == java_lang_Class::array_klass_offset())) {
3513 // Special hidden fields from the Class.
3514 assert(this->isa_instptr(), "must be an instance ptr.");
3515 _is_ptr_to_narrowoop = false;
3516 } else if (klass() == ciEnv::current()->Class_klass() &&
3517 _offset >= InstanceMirrorKlass::offset_of_static_fields()) {
3518 // Static fields
3519 BasicType basic_elem_type = T_ILLEGAL;
3520 if (const_oop() != nullptr) {
3521 ciInstanceKlass* k = const_oop()->as_instance()->java_lang_Class_klass()->as_instance_klass();
3522 basic_elem_type = k->get_field_type_by_offset(_offset, true);
3523 }
3524 if (basic_elem_type != T_ILLEGAL) {
3525 _is_ptr_to_narrowoop = UseCompressedOops && ::is_reference_type(basic_elem_type);
3526 } else {
3527 // unsafe access
3528 _is_ptr_to_narrowoop = UseCompressedOops;
3529 }
3530 } else {
3531 // Instance fields which contains a compressed oop references.
3532 BasicType basic_elem_type = ik->get_field_type_by_offset(_offset, false);
3533 if (basic_elem_type != T_ILLEGAL) {
3534 _is_ptr_to_narrowoop = UseCompressedOops && ::is_reference_type(basic_elem_type);
3535 } else if (klass()->equals(ciEnv::current()->Object_klass())) {
3536 // Compile::find_alias_type() cast exactness on all types to verify
3537 // that it does not affect alias type.
3538 _is_ptr_to_narrowoop = UseCompressedOops;
3539 } else {
3540 // Type for the copy start in LibraryCallKit::inline_native_clone().
3541 _is_ptr_to_narrowoop = UseCompressedOops;
3542 }
3543 }
3544 }
3545 }
3546 }
3547 #endif
3548 }
3549
3550 //------------------------------make-------------------------------------------
3551 const TypeOopPtr *TypeOopPtr::make(PTR ptr, int offset, int instance_id,
3552 const TypePtr* speculative, int inline_depth) {
3553 assert(ptr != Constant, "no constant generic pointers");
3554 ciKlass* k = Compile::current()->env()->Object_klass();
3555 bool xk = false;
3556 ciObject* o = nullptr;
3557 const TypeInterfaces* interfaces = TypeInterfaces::make();
3558 return (TypeOopPtr*)(new TypeOopPtr(OopPtr, ptr, k, interfaces, xk, o, offset, instance_id, speculative, inline_depth))->hashcons();
3559 }
3560
3561
3562 //------------------------------cast_to_ptr_type-------------------------------
3563 const TypeOopPtr* TypeOopPtr::cast_to_ptr_type(PTR ptr) const {
3564 assert(_base == OopPtr, "subclass must override cast_to_ptr_type");
3565 if( ptr == _ptr ) return this;
3566 return make(ptr, _offset, _instance_id, _speculative, _inline_depth);
3567 }
3568
3569 //-----------------------------cast_to_instance_id----------------------------
3570 const TypeOopPtr *TypeOopPtr::cast_to_instance_id(int instance_id) const {
3571 // There are no instances of a general oop.
3572 // Return self unchanged.
3573 return this;
3574 }
3575
3576 //-----------------------------cast_to_exactness-------------------------------
3577 const TypeOopPtr* TypeOopPtr::cast_to_exactness(bool klass_is_exact) const {
3578 // There is no such thing as an exact general oop.
3579 // Return self unchanged.
3580 return this;
3581 }
3582
3583
3584 //------------------------------as_klass_type----------------------------------
3585 // Return the klass type corresponding to this instance or array type.
3586 // It is the type that is loaded from an object of this type.
3587 const TypeKlassPtr* TypeOopPtr::as_klass_type(bool try_for_exact) const {
3588 ShouldNotReachHere();
3589 return nullptr;
3590 }
3591
3592 //------------------------------meet-------------------------------------------
3593 // Compute the MEET of two types. It returns a new Type object.
3594 const Type *TypeOopPtr::xmeet_helper(const Type *t) const {
3595 // Perform a fast test for common case; meeting the same types together.
3596 if( this == t ) return this; // Meeting same type-rep?
3597
3598 // Current "this->_base" is OopPtr
3599 switch (t->base()) { // switch on original type
3600
3601 case Int: // Mixing ints & oops happens when javac
3602 case Long: // reuses local variables
3603 case HalfFloatTop:
3604 case HalfFloatCon:
3605 case HalfFloatBot:
3606 case FloatTop:
3607 case FloatCon:
3608 case FloatBot:
3609 case DoubleTop:
3610 case DoubleCon:
3611 case DoubleBot:
3612 case NarrowOop:
3613 case NarrowKlass:
3614 case Bottom: // Ye Olde Default
3615 return Type::BOTTOM;
3616 case Top:
3617 return this;
3618
3619 default: // All else is a mistake
3620 typerr(t);
3621
3622 case RawPtr:
3623 case MetadataPtr:
3624 case KlassPtr:
3625 case InstKlassPtr:
3626 case AryKlassPtr:
3627 return TypePtr::BOTTOM; // Oop meet raw is not well defined
3628
3629 case AnyPtr: {
3630 // Found an AnyPtr type vs self-OopPtr type
3631 const TypePtr *tp = t->is_ptr();
3632 int offset = meet_offset(tp->offset());
3633 PTR ptr = meet_ptr(tp->ptr());
3634 const TypePtr* speculative = xmeet_speculative(tp);
3635 int depth = meet_inline_depth(tp->inline_depth());
3636 switch (tp->ptr()) {
3637 case Null:
3638 if (ptr == Null) return TypePtr::make(AnyPtr, ptr, offset, speculative, depth);
3639 // else fall through:
3640 case TopPTR:
3641 case AnyNull: {
3642 int instance_id = meet_instance_id(InstanceTop);
3643 return make(ptr, offset, instance_id, speculative, depth);
3644 }
3645 case BotPTR:
3646 case NotNull:
3647 return TypePtr::make(AnyPtr, ptr, offset, speculative, depth);
3648 default: typerr(t);
3649 }
3650 }
3651
3652 case OopPtr: { // Meeting to other OopPtrs
3653 const TypeOopPtr *tp = t->is_oopptr();
3654 int instance_id = meet_instance_id(tp->instance_id());
3655 const TypePtr* speculative = xmeet_speculative(tp);
3656 int depth = meet_inline_depth(tp->inline_depth());
3657 return make(meet_ptr(tp->ptr()), meet_offset(tp->offset()), instance_id, speculative, depth);
3658 }
3659
3660 case InstPtr: // For these, flip the call around to cut down
3661 case AryPtr:
3662 return t->xmeet(this); // Call in reverse direction
3663
3664 } // End of switch
3665 return this; // Return the double constant
3666 }
3667
3668
3669 //------------------------------xdual------------------------------------------
3670 // Dual of a pure heap pointer. No relevant klass or oop information.
3671 const Type *TypeOopPtr::xdual() const {
3672 assert(klass() == Compile::current()->env()->Object_klass(), "no klasses here");
3673 assert(const_oop() == nullptr, "no constants here");
3674 return new TypeOopPtr(_base, dual_ptr(), klass(), _interfaces, klass_is_exact(), const_oop(), dual_offset(), dual_instance_id(), dual_speculative(), dual_inline_depth());
3675 }
3676
3677 //--------------------------make_from_klass_common-----------------------------
3678 // Computes the element-type given a klass.
3679 const TypeOopPtr* TypeOopPtr::make_from_klass_common(ciKlass* klass, bool klass_change, bool try_for_exact, InterfaceHandling interface_handling) {
3680 if (klass->is_instance_klass()) {
3681 Compile* C = Compile::current();
3682 Dependencies* deps = C->dependencies();
3683 assert((deps != nullptr) == (C->method() != nullptr && C->method()->code_size() > 0), "sanity");
3684 // Element is an instance
3685 bool klass_is_exact = false;
3686 if (klass->is_loaded()) {
3687 // Try to set klass_is_exact.
3688 ciInstanceKlass* ik = klass->as_instance_klass();
3689 klass_is_exact = ik->is_final();
3690 if (!klass_is_exact && klass_change
3691 && deps != nullptr && UseUniqueSubclasses) {
3692 ciInstanceKlass* sub = ik->unique_concrete_subklass();
3693 if (sub != nullptr) {
3694 deps->assert_abstract_with_unique_concrete_subtype(ik, sub);
3695 klass = ik = sub;
3696 klass_is_exact = sub->is_final();
3697 }
3698 }
3699 if (!klass_is_exact && try_for_exact && deps != nullptr &&
3700 !ik->is_interface() && !ik->has_subklass()) {
3701 // Add a dependence; if concrete subclass added we need to recompile
3702 deps->assert_leaf_type(ik);
3703 klass_is_exact = true;
3704 }
3705 }
3706 const TypeInterfaces* interfaces = TypePtr::interfaces(klass, true, true, false, interface_handling);
3707 return TypeInstPtr::make(TypePtr::BotPTR, klass, interfaces, klass_is_exact, nullptr, 0);
3708 } else if (klass->is_obj_array_klass()) {
3709 // Element is an object array. Recursively call ourself.
3710 ciKlass* eklass = klass->as_obj_array_klass()->element_klass();
3711 const TypeOopPtr *etype = TypeOopPtr::make_from_klass_common(eklass, false, try_for_exact, interface_handling);
3712 bool xk = etype->klass_is_exact();
3713 const TypeAry* arr0 = TypeAry::make(etype, TypeInt::POS);
3714 // We used to pass NotNull in here, asserting that the sub-arrays
3715 // are all not-null. This is not true in generally, as code can
3716 // slam nulls down in the subarrays.
3717 const TypeAryPtr* arr = TypeAryPtr::make(TypePtr::BotPTR, arr0, nullptr, xk, 0);
3718 return arr;
3719 } else if (klass->is_type_array_klass()) {
3720 // Element is an typeArray
3721 const Type* etype = get_const_basic_type(klass->as_type_array_klass()->element_type());
3722 const TypeAry* arr0 = TypeAry::make(etype, TypeInt::POS);
3723 // We used to pass NotNull in here, asserting that the array pointer
3724 // is not-null. That was not true in general.
3725 const TypeAryPtr* arr = TypeAryPtr::make(TypePtr::BotPTR, arr0, klass, true, 0);
3726 return arr;
3727 } else {
3728 ShouldNotReachHere();
3729 return nullptr;
3730 }
3731 }
3732
3733 //------------------------------make_from_constant-----------------------------
3734 // Make a java pointer from an oop constant
3735 const TypeOopPtr* TypeOopPtr::make_from_constant(ciObject* o, bool require_constant) {
3736 assert(!o->is_null_object(), "null object not yet handled here.");
3737
3738 const bool make_constant = require_constant || o->should_be_constant();
3739
3740 ciKlass* klass = o->klass();
3741 if (klass->is_instance_klass()) {
3742 // Element is an instance
3743 if (make_constant) {
3744 return TypeInstPtr::make(o);
3745 } else {
3746 return TypeInstPtr::make(TypePtr::NotNull, klass, true, nullptr, 0);
3747 }
3748 } else if (klass->is_obj_array_klass()) {
3749 // Element is an object array. Recursively call ourself.
3750 const TypeOopPtr *etype =
3751 TypeOopPtr::make_from_klass_raw(klass->as_obj_array_klass()->element_klass(), trust_interfaces);
3752 const TypeAry* arr0 = TypeAry::make(etype, TypeInt::make(o->as_array()->length()));
3753 // We used to pass NotNull in here, asserting that the sub-arrays
3754 // are all not-null. This is not true in generally, as code can
3755 // slam nulls down in the subarrays.
3756 if (make_constant) {
3757 return TypeAryPtr::make(TypePtr::Constant, o, arr0, klass, true, 0);
3758 } else {
3759 return TypeAryPtr::make(TypePtr::NotNull, arr0, klass, true, 0);
3760 }
3761 } else if (klass->is_type_array_klass()) {
3762 // Element is an typeArray
3763 const Type* etype =
3764 (Type*)get_const_basic_type(klass->as_type_array_klass()->element_type());
3765 const TypeAry* arr0 = TypeAry::make(etype, TypeInt::make(o->as_array()->length()));
3766 // We used to pass NotNull in here, asserting that the array pointer
3767 // is not-null. That was not true in general.
3768 if (make_constant) {
3769 return TypeAryPtr::make(TypePtr::Constant, o, arr0, klass, true, 0);
3770 } else {
3771 return TypeAryPtr::make(TypePtr::NotNull, arr0, klass, true, 0);
3772 }
3773 }
3774
3775 fatal("unhandled object type");
3776 return nullptr;
3777 }
3778
3779 //------------------------------get_con----------------------------------------
3780 intptr_t TypeOopPtr::get_con() const {
3781 assert( _ptr == Null || _ptr == Constant, "" );
3782 assert( _offset >= 0, "" );
3783
3784 if (_offset != 0) {
3785 // After being ported to the compiler interface, the compiler no longer
3786 // directly manipulates the addresses of oops. Rather, it only has a pointer
3787 // to a handle at compile time. This handle is embedded in the generated
3788 // code and dereferenced at the time the nmethod is made. Until that time,
3789 // it is not reasonable to do arithmetic with the addresses of oops (we don't
3790 // have access to the addresses!). This does not seem to currently happen,
3791 // but this assertion here is to help prevent its occurrence.
3792 tty->print_cr("Found oop constant with non-zero offset");
3793 ShouldNotReachHere();
3794 }
3795
3796 return (intptr_t)const_oop()->constant_encoding();
3797 }
3798
3799
3800 //-----------------------------filter------------------------------------------
3801 // Do not allow interface-vs.-noninterface joins to collapse to top.
3802 const Type *TypeOopPtr::filter_helper(const Type *kills, bool include_speculative) const {
3803
3804 const Type* ft = join_helper(kills, include_speculative);
3805
3806 if (ft->empty()) {
3807 return Type::TOP; // Canonical empty value
3808 }
3809
3810 return ft;
3811 }
3812
3813 //------------------------------eq---------------------------------------------
3814 // Structural equality check for Type representations
3815 bool TypeOopPtr::eq( const Type *t ) const {
3816 const TypeOopPtr *a = (const TypeOopPtr*)t;
3817 if (_klass_is_exact != a->_klass_is_exact ||
3818 _instance_id != a->_instance_id) return false;
3819 ciObject* one = const_oop();
3820 ciObject* two = a->const_oop();
3821 if (one == nullptr || two == nullptr) {
3822 return (one == two) && TypePtr::eq(t);
3823 } else {
3824 return one->equals(two) && TypePtr::eq(t);
3825 }
3826 }
3827
3828 //------------------------------hash-------------------------------------------
3829 // Type-specific hashing function.
3830 uint TypeOopPtr::hash(void) const {
3831 return
3832 (uint)(const_oop() ? const_oop()->hash() : 0) +
3833 (uint)_klass_is_exact +
3834 (uint)_instance_id + TypePtr::hash();
3835 }
3836
3837 //------------------------------dump2------------------------------------------
3838 #ifndef PRODUCT
3839 void TypeOopPtr::dump2(Dict& d, uint depth, outputStream* st) const {
3840 st->print("oopptr:%s", ptr_msg[_ptr]);
3841 if (_klass_is_exact) {
3842 st->print(":exact");
3843 }
3844 if (const_oop() != nullptr) {
3845 st->print(":" INTPTR_FORMAT, p2i(const_oop()));
3846 }
3847 dump_offset(st);
3848 dump_instance_id(st);
3849 dump_inline_depth(st);
3850 dump_speculative(st);
3851 }
3852
3853 void TypeOopPtr::dump_instance_id(outputStream* st) const {
3854 if (_instance_id == InstanceTop) {
3855 st->print(",iid=top");
3856 } else if (_instance_id == InstanceBot) {
3857 st->print(",iid=bot");
3858 } else {
3859 st->print(",iid=%d", _instance_id);
3860 }
3861 }
3862 #endif
3863
3864 //------------------------------singleton--------------------------------------
3865 // TRUE if Type is a singleton type, FALSE otherwise. Singletons are simple
3866 // constants
3867 bool TypeOopPtr::singleton(void) const {
3868 // detune optimizer to not generate constant oop + constant offset as a constant!
3869 // TopPTR, Null, AnyNull, Constant are all singletons
3870 return (_offset == 0) && !below_centerline(_ptr);
3871 }
3872
3873 //------------------------------add_offset-------------------------------------
3874 const TypePtr* TypeOopPtr::add_offset(intptr_t offset) const {
3875 return make(_ptr, xadd_offset(offset), _instance_id, add_offset_speculative(offset), _inline_depth);
3876 }
3877
3878 const TypeOopPtr* TypeOopPtr::with_offset(intptr_t offset) const {
3879 return make(_ptr, offset, _instance_id, with_offset_speculative(offset), _inline_depth);
3880 }
3881
3882 /**
3883 * Return same type without a speculative part
3884 */
3885 const TypeOopPtr* TypeOopPtr::remove_speculative() const {
3886 if (_speculative == nullptr) {
3887 return this;
3888 }
3889 assert(_inline_depth == InlineDepthTop || _inline_depth == InlineDepthBottom, "non speculative type shouldn't have inline depth");
3890 return make(_ptr, _offset, _instance_id, nullptr, _inline_depth);
3891 }
3892
3893 /**
3894 * Return same type but drop speculative part if we know we won't use
3895 * it
3896 */
3897 const Type* TypeOopPtr::cleanup_speculative() const {
3898 // If the klass is exact and the ptr is not null then there's
3899 // nothing that the speculative type can help us with
3900 if (klass_is_exact() && !maybe_null()) {
3901 return remove_speculative();
3902 }
3903 return TypePtr::cleanup_speculative();
3904 }
3905
3906 /**
3907 * Return same type but with a different inline depth (used for speculation)
3908 *
3909 * @param depth depth to meet with
3910 */
3911 const TypePtr* TypeOopPtr::with_inline_depth(int depth) const {
3912 if (!UseInlineDepthForSpeculativeTypes) {
3913 return this;
3914 }
3915 return make(_ptr, _offset, _instance_id, _speculative, depth);
3916 }
3917
3918 //------------------------------with_instance_id--------------------------------
3919 const TypePtr* TypeOopPtr::with_instance_id(int instance_id) const {
3920 assert(_instance_id != -1, "should be known");
3921 return make(_ptr, _offset, instance_id, _speculative, _inline_depth);
3922 }
3923
3924 //------------------------------meet_instance_id--------------------------------
3925 int TypeOopPtr::meet_instance_id( int instance_id ) const {
3926 // Either is 'TOP' instance? Return the other instance!
3927 if( _instance_id == InstanceTop ) return instance_id;
3928 if( instance_id == InstanceTop ) return _instance_id;
3929 // If either is different, return 'BOTTOM' instance
3930 if( _instance_id != instance_id ) return InstanceBot;
3931 return _instance_id;
3932 }
3933
3934 //------------------------------dual_instance_id--------------------------------
3935 int TypeOopPtr::dual_instance_id( ) const {
3936 if( _instance_id == InstanceTop ) return InstanceBot; // Map TOP into BOTTOM
3937 if( _instance_id == InstanceBot ) return InstanceTop; // Map BOTTOM into TOP
3938 return _instance_id; // Map everything else into self
3939 }
3940
3941
3942 const TypeInterfaces* TypeOopPtr::meet_interfaces(const TypeOopPtr* other) const {
3943 if (above_centerline(_ptr) && above_centerline(other->_ptr)) {
3944 return _interfaces->union_with(other->_interfaces);
3945 } else if (above_centerline(_ptr) && !above_centerline(other->_ptr)) {
3946 return other->_interfaces;
3947 } else if (above_centerline(other->_ptr) && !above_centerline(_ptr)) {
3948 return _interfaces;
3949 }
3950 return _interfaces->intersection_with(other->_interfaces);
3951 }
3952
3953 /**
3954 * Check whether new profiling would improve speculative type
3955 *
3956 * @param exact_kls class from profiling
3957 * @param inline_depth inlining depth of profile point
3958 *
3959 * @return true if type profile is valuable
3960 */
3961 bool TypeOopPtr::would_improve_type(ciKlass* exact_kls, int inline_depth) const {
3962 // no way to improve an already exact type
3963 if (klass_is_exact()) {
3964 return false;
3965 }
3966 return TypePtr::would_improve_type(exact_kls, inline_depth);
3967 }
3968
3969 //=============================================================================
3970 // Convenience common pre-built types.
3971 const TypeInstPtr *TypeInstPtr::NOTNULL;
3972 const TypeInstPtr *TypeInstPtr::BOTTOM;
3973 const TypeInstPtr *TypeInstPtr::MIRROR;
3974 const TypeInstPtr *TypeInstPtr::MARK;
3975 const TypeInstPtr *TypeInstPtr::KLASS;
3976
3977 // Is there a single ciKlass* that can represent that type?
3978 ciKlass* TypeInstPtr::exact_klass_helper() const {
3979 if (_interfaces->empty()) {
3980 return _klass;
3981 }
3982 if (_klass != ciEnv::current()->Object_klass()) {
3983 if (_interfaces->eq(_klass->as_instance_klass())) {
3984 return _klass;
3985 }
3986 return nullptr;
3987 }
3988 return _interfaces->exact_klass();
3989 }
3990
3991 //------------------------------TypeInstPtr-------------------------------------
3992 TypeInstPtr::TypeInstPtr(PTR ptr, ciKlass* k, const TypeInterfaces* interfaces, bool xk, ciObject* o, int off,
3993 int instance_id, const TypePtr* speculative, int inline_depth)
3994 : TypeOopPtr(InstPtr, ptr, k, interfaces, xk, o, off, instance_id, speculative, inline_depth) {
3995 assert(k == nullptr || !k->is_loaded() || !k->is_interface(), "no interface here");
3996 assert(k != nullptr &&
3997 (k->is_loaded() || o == nullptr),
3998 "cannot have constants with non-loaded klass");
3999 };
4000
4001 //------------------------------make-------------------------------------------
4002 const TypeInstPtr *TypeInstPtr::make(PTR ptr,
4003 ciKlass* k,
4004 const TypeInterfaces* interfaces,
4005 bool xk,
4006 ciObject* o,
4007 int offset,
4008 int instance_id,
4009 const TypePtr* speculative,
4010 int inline_depth) {
4011 assert( !k->is_loaded() || k->is_instance_klass(), "Must be for instance");
4012 // Either const_oop() is null or else ptr is Constant
4013 assert( (!o && ptr != Constant) || (o && ptr == Constant),
4014 "constant pointers must have a value supplied" );
4015 // Ptr is never Null
4016 assert( ptr != Null, "null pointers are not typed" );
4017
4018 assert(instance_id <= 0 || xk, "instances are always exactly typed");
4019 if (ptr == Constant) {
4020 // Note: This case includes meta-object constants, such as methods.
4021 xk = true;
4022 } else if (k->is_loaded()) {
4023 ciInstanceKlass* ik = k->as_instance_klass();
4024 if (!xk && ik->is_final()) xk = true; // no inexact final klass
4025 assert(!ik->is_interface(), "no interface here");
4026 if (xk && ik->is_interface()) xk = false; // no exact interface
4027 }
4028
4029 // Now hash this baby
4030 TypeInstPtr *result =
4031 (TypeInstPtr*)(new TypeInstPtr(ptr, k, interfaces, xk, o ,offset, instance_id, speculative, inline_depth))->hashcons();
4032
4033 return result;
4034 }
4035
4036 const TypeInterfaces* TypePtr::interfaces(ciKlass*& k, bool klass, bool interface, bool array, InterfaceHandling interface_handling) {
4037 if (k->is_instance_klass()) {
4038 if (k->is_loaded()) {
4039 if (k->is_interface() && interface_handling == ignore_interfaces) {
4040 assert(interface, "no interface expected");
4041 k = ciEnv::current()->Object_klass();
4042 const TypeInterfaces* interfaces = TypeInterfaces::make();
4043 return interfaces;
4044 }
4045 GrowableArray<ciInstanceKlass *>* k_interfaces = k->as_instance_klass()->transitive_interfaces();
4046 const TypeInterfaces* interfaces = TypeInterfaces::make(k_interfaces);
4047 if (k->is_interface()) {
4048 assert(interface, "no interface expected");
4049 k = ciEnv::current()->Object_klass();
4050 } else {
4051 assert(klass, "no instance klass expected");
4052 }
4053 return interfaces;
4054 }
4055 const TypeInterfaces* interfaces = TypeInterfaces::make();
4056 return interfaces;
4057 }
4058 assert(array, "no array expected");
4059 assert(k->is_array_klass(), "Not an array?");
4060 ciType* e = k->as_array_klass()->base_element_type();
4061 if (e->is_loaded() && e->is_instance_klass() && e->as_instance_klass()->is_interface()) {
4062 if (interface_handling == ignore_interfaces) {
4063 k = ciObjArrayKlass::make(ciEnv::current()->Object_klass(), k->as_array_klass()->dimension());
4064 }
4065 }
4066 return TypeAryPtr::_array_interfaces;
4067 }
4068
4069 //------------------------------cast_to_ptr_type-------------------------------
4070 const TypeInstPtr* TypeInstPtr::cast_to_ptr_type(PTR ptr) const {
4071 if( ptr == _ptr ) return this;
4072 // Reconstruct _sig info here since not a problem with later lazy
4073 // construction, _sig will show up on demand.
4074 return make(ptr, klass(), _interfaces, klass_is_exact(), ptr == Constant ? const_oop() : nullptr, _offset, _instance_id, _speculative, _inline_depth);
4075 }
4076
4077
4078 //-----------------------------cast_to_exactness-------------------------------
4079 const TypeInstPtr* TypeInstPtr::cast_to_exactness(bool klass_is_exact) const {
4080 if( klass_is_exact == _klass_is_exact ) return this;
4081 if (!_klass->is_loaded()) return this;
4082 ciInstanceKlass* ik = _klass->as_instance_klass();
4083 if( (ik->is_final() || _const_oop) ) return this; // cannot clear xk
4084 assert(!ik->is_interface(), "no interface here");
4085 return make(ptr(), klass(), _interfaces, klass_is_exact, const_oop(), _offset, _instance_id, _speculative, _inline_depth);
4086 }
4087
4088 //-----------------------------cast_to_instance_id----------------------------
4089 const TypeInstPtr* TypeInstPtr::cast_to_instance_id(int instance_id) const {
4090 if( instance_id == _instance_id ) return this;
4091 return make(_ptr, klass(), _interfaces, _klass_is_exact, const_oop(), _offset, instance_id, _speculative, _inline_depth);
4092 }
4093
4094 //------------------------------xmeet_unloaded---------------------------------
4095 // Compute the MEET of two InstPtrs when at least one is unloaded.
4096 // Assume classes are different since called after check for same name/class-loader
4097 const TypeInstPtr *TypeInstPtr::xmeet_unloaded(const TypeInstPtr *tinst, const TypeInterfaces* interfaces) const {
4098 int off = meet_offset(tinst->offset());
4099 PTR ptr = meet_ptr(tinst->ptr());
4100 int instance_id = meet_instance_id(tinst->instance_id());
4101 const TypePtr* speculative = xmeet_speculative(tinst);
4102 int depth = meet_inline_depth(tinst->inline_depth());
4103
4104 const TypeInstPtr *loaded = is_loaded() ? this : tinst;
4105 const TypeInstPtr *unloaded = is_loaded() ? tinst : this;
4106 if( loaded->klass()->equals(ciEnv::current()->Object_klass()) ) {
4107 //
4108 // Meet unloaded class with java/lang/Object
4109 //
4110 // Meet
4111 // | Unloaded Class
4112 // Object | TOP | AnyNull | Constant | NotNull | BOTTOM |
4113 // ===================================================================
4114 // TOP | ..........................Unloaded......................|
4115 // AnyNull | U-AN |................Unloaded......................|
4116 // Constant | ... O-NN .................................. | O-BOT |
4117 // NotNull | ... O-NN .................................. | O-BOT |
4118 // BOTTOM | ........................Object-BOTTOM ..................|
4119 //
4120 assert(loaded->ptr() != TypePtr::Null, "insanity check");
4121 //
4122 if (loaded->ptr() == TypePtr::TopPTR) { return unloaded->with_speculative(speculative); }
4123 else if (loaded->ptr() == TypePtr::AnyNull) { return make(ptr, unloaded->klass(), interfaces, false, nullptr, off, instance_id, speculative, depth); }
4124 else if (loaded->ptr() == TypePtr::BotPTR) { return TypeInstPtr::BOTTOM->with_speculative(speculative); }
4125 else if (loaded->ptr() == TypePtr::Constant || loaded->ptr() == TypePtr::NotNull) {
4126 if (unloaded->ptr() == TypePtr::BotPTR) { return TypeInstPtr::BOTTOM->with_speculative(speculative); }
4127 else { return TypeInstPtr::NOTNULL->with_speculative(speculative); }
4128 }
4129 else if (unloaded->ptr() == TypePtr::TopPTR) { return unloaded->with_speculative(speculative); }
4130
4131 return unloaded->cast_to_ptr_type(TypePtr::AnyNull)->is_instptr()->with_speculative(speculative);
4132 }
4133
4134 // Both are unloaded, not the same class, not Object
4135 // Or meet unloaded with a different loaded class, not java/lang/Object
4136 if (ptr != TypePtr::BotPTR) {
4137 return TypeInstPtr::NOTNULL->with_speculative(speculative);
4138 }
4139 return TypeInstPtr::BOTTOM->with_speculative(speculative);
4140 }
4141
4142
4143 //------------------------------meet-------------------------------------------
4144 // Compute the MEET of two types. It returns a new Type object.
4145 const Type *TypeInstPtr::xmeet_helper(const Type *t) const {
4146 // Perform a fast test for common case; meeting the same types together.
4147 if( this == t ) return this; // Meeting same type-rep?
4148
4149 // Current "this->_base" is Pointer
4150 switch (t->base()) { // switch on original type
4151
4152 case Int: // Mixing ints & oops happens when javac
4153 case Long: // reuses local variables
4154 case HalfFloatTop:
4155 case HalfFloatCon:
4156 case HalfFloatBot:
4157 case FloatTop:
4158 case FloatCon:
4159 case FloatBot:
4160 case DoubleTop:
4161 case DoubleCon:
4162 case DoubleBot:
4163 case NarrowOop:
4164 case NarrowKlass:
4165 case Bottom: // Ye Olde Default
4166 return Type::BOTTOM;
4167 case Top:
4168 return this;
4169
4170 default: // All else is a mistake
4171 typerr(t);
4172
4173 case MetadataPtr:
4174 case KlassPtr:
4175 case InstKlassPtr:
4176 case AryKlassPtr:
4177 case RawPtr: return TypePtr::BOTTOM;
4178
4179 case AryPtr: { // All arrays inherit from Object class
4180 // Call in reverse direction to avoid duplication
4181 return t->is_aryptr()->xmeet_helper(this);
4182 }
4183
4184 case OopPtr: { // Meeting to OopPtrs
4185 // Found a OopPtr type vs self-InstPtr type
4186 const TypeOopPtr *tp = t->is_oopptr();
4187 int offset = meet_offset(tp->offset());
4188 PTR ptr = meet_ptr(tp->ptr());
4189 switch (tp->ptr()) {
4190 case TopPTR:
4191 case AnyNull: {
4192 int instance_id = meet_instance_id(InstanceTop);
4193 const TypePtr* speculative = xmeet_speculative(tp);
4194 int depth = meet_inline_depth(tp->inline_depth());
4195 return make(ptr, klass(), _interfaces, klass_is_exact(),
4196 (ptr == Constant ? const_oop() : nullptr), offset, instance_id, speculative, depth);
4197 }
4198 case NotNull:
4199 case BotPTR: {
4200 int instance_id = meet_instance_id(tp->instance_id());
4201 const TypePtr* speculative = xmeet_speculative(tp);
4202 int depth = meet_inline_depth(tp->inline_depth());
4203 return TypeOopPtr::make(ptr, offset, instance_id, speculative, depth);
4204 }
4205 default: typerr(t);
4206 }
4207 }
4208
4209 case AnyPtr: { // Meeting to AnyPtrs
4210 // Found an AnyPtr type vs self-InstPtr type
4211 const TypePtr *tp = t->is_ptr();
4212 int offset = meet_offset(tp->offset());
4213 PTR ptr = meet_ptr(tp->ptr());
4214 int instance_id = meet_instance_id(InstanceTop);
4215 const TypePtr* speculative = xmeet_speculative(tp);
4216 int depth = meet_inline_depth(tp->inline_depth());
4217 switch (tp->ptr()) {
4218 case Null:
4219 if( ptr == Null ) return TypePtr::make(AnyPtr, ptr, offset, speculative, depth);
4220 // else fall through to AnyNull
4221 case TopPTR:
4222 case AnyNull: {
4223 return make(ptr, klass(), _interfaces, klass_is_exact(),
4224 (ptr == Constant ? const_oop() : nullptr), offset, instance_id, speculative, depth);
4225 }
4226 case NotNull:
4227 case BotPTR:
4228 return TypePtr::make(AnyPtr, ptr, offset, speculative,depth);
4229 default: typerr(t);
4230 }
4231 }
4232
4233 /*
4234 A-top }
4235 / | \ } Tops
4236 B-top A-any C-top }
4237 | / | \ | } Any-nulls
4238 B-any | C-any }
4239 | | |
4240 B-con A-con C-con } constants; not comparable across classes
4241 | | |
4242 B-not | C-not }
4243 | \ | / | } not-nulls
4244 B-bot A-not C-bot }
4245 \ | / } Bottoms
4246 A-bot }
4247 */
4248
4249 case InstPtr: { // Meeting 2 Oops?
4250 // Found an InstPtr sub-type vs self-InstPtr type
4251 const TypeInstPtr *tinst = t->is_instptr();
4252 int off = meet_offset(tinst->offset());
4253 PTR ptr = meet_ptr(tinst->ptr());
4254 int instance_id = meet_instance_id(tinst->instance_id());
4255 const TypePtr* speculative = xmeet_speculative(tinst);
4256 int depth = meet_inline_depth(tinst->inline_depth());
4257 const TypeInterfaces* interfaces = meet_interfaces(tinst);
4258
4259 ciKlass* tinst_klass = tinst->klass();
4260 ciKlass* this_klass = klass();
4261
4262 ciKlass* res_klass = nullptr;
4263 bool res_xk = false;
4264 const Type* res;
4265 MeetResult kind = meet_instptr(ptr, interfaces, this, tinst, res_klass, res_xk);
4266
4267 if (kind == UNLOADED) {
4268 // One of these classes has not been loaded
4269 const TypeInstPtr* unloaded_meet = xmeet_unloaded(tinst, interfaces);
4270 #ifndef PRODUCT
4271 if (PrintOpto && Verbose) {
4272 tty->print("meet of unloaded classes resulted in: ");
4273 unloaded_meet->dump();
4274 tty->cr();
4275 tty->print(" this == ");
4276 dump();
4277 tty->cr();
4278 tty->print(" tinst == ");
4279 tinst->dump();
4280 tty->cr();
4281 }
4282 #endif
4283 res = unloaded_meet;
4284 } else {
4285 if (kind == NOT_SUBTYPE && instance_id > 0) {
4286 instance_id = InstanceBot;
4287 } else if (kind == LCA) {
4288 instance_id = InstanceBot;
4289 }
4290 ciObject* o = nullptr; // Assume not constant when done
4291 ciObject* this_oop = const_oop();
4292 ciObject* tinst_oop = tinst->const_oop();
4293 if (ptr == Constant) {
4294 if (this_oop != nullptr && tinst_oop != nullptr &&
4295 this_oop->equals(tinst_oop))
4296 o = this_oop;
4297 else if (above_centerline(_ptr)) {
4298 assert(!tinst_klass->is_interface(), "");
4299 o = tinst_oop;
4300 } else if (above_centerline(tinst->_ptr)) {
4301 assert(!this_klass->is_interface(), "");
4302 o = this_oop;
4303 } else
4304 ptr = NotNull;
4305 }
4306 res = make(ptr, res_klass, interfaces, res_xk, o, off, instance_id, speculative, depth);
4307 }
4308
4309 return res;
4310
4311 } // End of case InstPtr
4312
4313 } // End of switch
4314 return this; // Return the double constant
4315 }
4316
4317 template<class T> TypePtr::MeetResult TypePtr::meet_instptr(PTR& ptr, const TypeInterfaces*& interfaces, const T* this_type, const T* other_type,
4318 ciKlass*& res_klass, bool& res_xk) {
4319 ciKlass* this_klass = this_type->klass();
4320 ciKlass* other_klass = other_type->klass();
4321 bool this_xk = this_type->klass_is_exact();
4322 bool other_xk = other_type->klass_is_exact();
4323 PTR this_ptr = this_type->ptr();
4324 PTR other_ptr = other_type->ptr();
4325 const TypeInterfaces* this_interfaces = this_type->interfaces();
4326 const TypeInterfaces* other_interfaces = other_type->interfaces();
4327 // Check for easy case; klasses are equal (and perhaps not loaded!)
4328 // If we have constants, then we created oops so classes are loaded
4329 // and we can handle the constants further down. This case handles
4330 // both-not-loaded or both-loaded classes
4331 if (ptr != Constant && this_klass->equals(other_klass) && this_xk == other_xk) {
4332 res_klass = this_klass;
4333 res_xk = this_xk;
4334 return QUICK;
4335 }
4336
4337 // Classes require inspection in the Java klass hierarchy. Must be loaded.
4338 if (!other_klass->is_loaded() || !this_klass->is_loaded()) {
4339 return UNLOADED;
4340 }
4341
4342 // !!! Here's how the symmetry requirement breaks down into invariants:
4343 // If we split one up & one down AND they subtype, take the down man.
4344 // If we split one up & one down AND they do NOT subtype, "fall hard".
4345 // If both are up and they subtype, take the subtype class.
4346 // If both are up and they do NOT subtype, "fall hard".
4347 // If both are down and they subtype, take the supertype class.
4348 // If both are down and they do NOT subtype, "fall hard".
4349 // Constants treated as down.
4350
4351 // Now, reorder the above list; observe that both-down+subtype is also
4352 // "fall hard"; "fall hard" becomes the default case:
4353 // If we split one up & one down AND they subtype, take the down man.
4354 // If both are up and they subtype, take the subtype class.
4355
4356 // If both are down and they subtype, "fall hard".
4357 // If both are down and they do NOT subtype, "fall hard".
4358 // If both are up and they do NOT subtype, "fall hard".
4359 // If we split one up & one down AND they do NOT subtype, "fall hard".
4360
4361 // If a proper subtype is exact, and we return it, we return it exactly.
4362 // If a proper supertype is exact, there can be no subtyping relationship!
4363 // If both types are equal to the subtype, exactness is and-ed below the
4364 // centerline and or-ed above it. (N.B. Constants are always exact.)
4365
4366 // Check for subtyping:
4367 const T* subtype = nullptr;
4368 bool subtype_exact = false;
4369 if (this_type->is_same_java_type_as(other_type)) {
4370 subtype = this_type;
4371 subtype_exact = below_centerline(ptr) ? (this_xk && other_xk) : (this_xk || other_xk);
4372 } else if (!other_xk && this_type->is_meet_subtype_of(other_type)) {
4373 subtype = this_type; // Pick subtyping class
4374 subtype_exact = this_xk;
4375 } else if(!this_xk && other_type->is_meet_subtype_of(this_type)) {
4376 subtype = other_type; // Pick subtyping class
4377 subtype_exact = other_xk;
4378 }
4379
4380 if (subtype) {
4381 if (above_centerline(ptr)) { // both are up?
4382 this_type = other_type = subtype;
4383 this_xk = other_xk = subtype_exact;
4384 } else if (above_centerline(this_ptr) && !above_centerline(other_ptr)) {
4385 this_type = other_type; // tinst is down; keep down man
4386 this_xk = other_xk;
4387 } else if (above_centerline(other_ptr) && !above_centerline(this_ptr)) {
4388 other_type = this_type; // this is down; keep down man
4389 other_xk = this_xk;
4390 } else {
4391 this_xk = subtype_exact; // either they are equal, or we'll do an LCA
4392 }
4393 }
4394
4395 // Check for classes now being equal
4396 if (this_type->is_same_java_type_as(other_type)) {
4397 // If the klasses are equal, the constants may still differ. Fall to
4398 // NotNull if they do (neither constant is null; that is a special case
4399 // handled elsewhere).
4400 res_klass = this_type->klass();
4401 res_xk = this_xk;
4402 return SUBTYPE;
4403 } // Else classes are not equal
4404
4405 // Since klasses are different, we require a LCA in the Java
4406 // class hierarchy - which means we have to fall to at least NotNull.
4407 if (ptr == TopPTR || ptr == AnyNull || ptr == Constant) {
4408 ptr = NotNull;
4409 }
4410
4411 interfaces = this_interfaces->intersection_with(other_interfaces);
4412
4413 // Now we find the LCA of Java classes
4414 ciKlass* k = this_klass->least_common_ancestor(other_klass);
4415
4416 res_klass = k;
4417 res_xk = false;
4418
4419 return LCA;
4420 }
4421
4422 //------------------------java_mirror_type--------------------------------------
4423 ciType* TypeInstPtr::java_mirror_type() const {
4424 // must be a singleton type
4425 if( const_oop() == nullptr ) return nullptr;
4426
4427 // must be of type java.lang.Class
4428 if( klass() != ciEnv::current()->Class_klass() ) return nullptr;
4429
4430 return const_oop()->as_instance()->java_mirror_type();
4431 }
4432
4433
4434 //------------------------------xdual------------------------------------------
4435 // Dual: do NOT dual on klasses. This means I do NOT understand the Java
4436 // inheritance mechanism.
4437 const Type *TypeInstPtr::xdual() const {
4438 return new TypeInstPtr(dual_ptr(), klass(), _interfaces, klass_is_exact(), const_oop(), dual_offset(), dual_instance_id(), dual_speculative(), dual_inline_depth());
4439 }
4440
4441 //------------------------------eq---------------------------------------------
4442 // Structural equality check for Type representations
4443 bool TypeInstPtr::eq( const Type *t ) const {
4444 const TypeInstPtr *p = t->is_instptr();
4445 return
4446 klass()->equals(p->klass()) &&
4447 _interfaces->eq(p->_interfaces) &&
4448 TypeOopPtr::eq(p); // Check sub-type stuff
4449 }
4450
4451 //------------------------------hash-------------------------------------------
4452 // Type-specific hashing function.
4453 uint TypeInstPtr::hash(void) const {
4454 return klass()->hash() + TypeOopPtr::hash() + _interfaces->hash();
4455 }
4456
4457 bool TypeInstPtr::is_java_subtype_of_helper(const TypeOopPtr* other, bool this_exact, bool other_exact) const {
4458 return TypePtr::is_java_subtype_of_helper_for_instance(this, other, this_exact, other_exact);
4459 }
4460
4461
4462 bool TypeInstPtr::is_same_java_type_as_helper(const TypeOopPtr* other) const {
4463 return TypePtr::is_same_java_type_as_helper_for_instance(this, other);
4464 }
4465
4466 bool TypeInstPtr::maybe_java_subtype_of_helper(const TypeOopPtr* other, bool this_exact, bool other_exact) const {
4467 return TypePtr::maybe_java_subtype_of_helper_for_instance(this, other, this_exact, other_exact);
4468 }
4469
4470
4471 //------------------------------dump2------------------------------------------
4472 // Dump oop Type
4473 #ifndef PRODUCT
4474 void TypeInstPtr::dump2(Dict &d, uint depth, outputStream* st) const {
4475 // Print the name of the klass.
4476 st->print("instptr:");
4477 klass()->print_name_on(st);
4478 _interfaces->dump(st);
4479
4480 if (_ptr == Constant && (WizardMode || Verbose)) {
4481 ResourceMark rm;
4482 stringStream ss;
4483
4484 st->print(" ");
4485 const_oop()->print_oop(&ss);
4486 // 'const_oop->print_oop()' may emit newlines('\n') into ss.
4487 // suppress newlines from it so -XX:+Verbose -XX:+PrintIdeal dumps one-liner for each node.
4488 char* buf = ss.as_string(/* c_heap= */false);
4489 StringUtils::replace_no_expand(buf, "\n", "");
4490 st->print_raw(buf);
4491 }
4492
4493 st->print(":%s", ptr_msg[_ptr]);
4494 if (_klass_is_exact) {
4495 st->print(":exact");
4496 }
4497
4498 dump_offset(st);
4499 dump_instance_id(st);
4500 dump_inline_depth(st);
4501 dump_speculative(st);
4502 }
4503 #endif
4504
4505 //------------------------------add_offset-------------------------------------
4506 const TypePtr* TypeInstPtr::add_offset(intptr_t offset) const {
4507 return make(_ptr, klass(), _interfaces, klass_is_exact(), const_oop(), xadd_offset(offset),
4508 _instance_id, add_offset_speculative(offset), _inline_depth);
4509 }
4510
4511 const TypeInstPtr* TypeInstPtr::with_offset(intptr_t offset) const {
4512 return make(_ptr, klass(), _interfaces, klass_is_exact(), const_oop(), offset,
4513 _instance_id, with_offset_speculative(offset), _inline_depth);
4514 }
4515
4516 const TypeInstPtr* TypeInstPtr::remove_speculative() const {
4517 if (_speculative == nullptr) {
4518 return this;
4519 }
4520 assert(_inline_depth == InlineDepthTop || _inline_depth == InlineDepthBottom, "non speculative type shouldn't have inline depth");
4521 return make(_ptr, klass(), _interfaces, klass_is_exact(), const_oop(), _offset,
4522 _instance_id, nullptr, _inline_depth);
4523 }
4524
4525 const TypeInstPtr* TypeInstPtr::with_speculative(const TypePtr* speculative) const {
4526 return make(_ptr, klass(), _interfaces, klass_is_exact(), const_oop(), _offset, _instance_id, speculative, _inline_depth);
4527 }
4528
4529 const TypePtr* TypeInstPtr::with_inline_depth(int depth) const {
4530 if (!UseInlineDepthForSpeculativeTypes) {
4531 return this;
4532 }
4533 return make(_ptr, klass(), _interfaces, klass_is_exact(), const_oop(), _offset, _instance_id, _speculative, depth);
4534 }
4535
4536 const TypePtr* TypeInstPtr::with_instance_id(int instance_id) const {
4537 assert(is_known_instance(), "should be known");
4538 return make(_ptr, klass(), _interfaces, klass_is_exact(), const_oop(), _offset, instance_id, _speculative, _inline_depth);
4539 }
4540
4541 const TypeKlassPtr* TypeInstPtr::as_klass_type(bool try_for_exact) const {
4542 bool xk = klass_is_exact();
4543 ciInstanceKlass* ik = klass()->as_instance_klass();
4544 if (try_for_exact && !xk && !ik->has_subklass() && !ik->is_final()) {
4545 if (_interfaces->eq(ik)) {
4546 Compile* C = Compile::current();
4547 Dependencies* deps = C->dependencies();
4548 deps->assert_leaf_type(ik);
4549 xk = true;
4550 }
4551 }
4552 return TypeInstKlassPtr::make(xk ? TypePtr::Constant : TypePtr::NotNull, klass(), _interfaces, 0);
4553 }
4554
4555 template <class T1, class T2> bool TypePtr::is_meet_subtype_of_helper_for_instance(const T1* this_one, const T2* other, bool this_xk, bool other_xk) {
4556 static_assert(std::is_base_of<T2, T1>::value, "");
4557
4558 if (!this_one->is_instance_type(other)) {
4559 return false;
4560 }
4561
4562 if (other->klass() == ciEnv::current()->Object_klass() && other->_interfaces->empty()) {
4563 return true;
4564 }
4565
4566 return this_one->klass()->is_subtype_of(other->klass()) &&
4567 (!this_xk || this_one->_interfaces->contains(other->_interfaces));
4568 }
4569
4570
4571 bool TypeInstPtr::is_meet_subtype_of_helper(const TypeOopPtr *other, bool this_xk, bool other_xk) const {
4572 return TypePtr::is_meet_subtype_of_helper_for_instance(this, other, this_xk, other_xk);
4573 }
4574
4575 template <class T1, class T2> bool TypePtr::is_meet_subtype_of_helper_for_array(const T1* this_one, const T2* other, bool this_xk, bool other_xk) {
4576 static_assert(std::is_base_of<T2, T1>::value, "");
4577 if (other->klass() == ciEnv::current()->Object_klass() && other->_interfaces->empty()) {
4578 return true;
4579 }
4580
4581 if (this_one->is_instance_type(other)) {
4582 return other->klass() == ciEnv::current()->Object_klass() && this_one->_interfaces->contains(other->_interfaces);
4583 }
4584
4585 int dummy;
4586 bool this_top_or_bottom = (this_one->base_element_type(dummy) == Type::TOP || this_one->base_element_type(dummy) == Type::BOTTOM);
4587 if (this_top_or_bottom) {
4588 return false;
4589 }
4590
4591 const T1* other_ary = this_one->is_array_type(other);
4592 const TypePtr* other_elem = other_ary->elem()->make_ptr();
4593 const TypePtr* this_elem = this_one->elem()->make_ptr();
4594 if (other_elem != nullptr && this_elem != nullptr) {
4595 return this_one->is_reference_type(this_elem)->is_meet_subtype_of_helper(this_one->is_reference_type(other_elem), this_xk, other_xk);
4596 }
4597
4598 if (other_elem == nullptr && this_elem == nullptr) {
4599 return this_one->klass()->is_subtype_of(other->klass());
4600 }
4601
4602 return false;
4603 }
4604
4605 bool TypeAryPtr::is_meet_subtype_of_helper(const TypeOopPtr *other, bool this_xk, bool other_xk) const {
4606 return TypePtr::is_meet_subtype_of_helper_for_array(this, other, this_xk, other_xk);
4607 }
4608
4609 bool TypeInstKlassPtr::is_meet_subtype_of_helper(const TypeKlassPtr *other, bool this_xk, bool other_xk) const {
4610 return TypePtr::is_meet_subtype_of_helper_for_instance(this, other, this_xk, other_xk);
4611 }
4612
4613 bool TypeAryKlassPtr::is_meet_subtype_of_helper(const TypeKlassPtr *other, bool this_xk, bool other_xk) const {
4614 return TypePtr::is_meet_subtype_of_helper_for_array(this, other, this_xk, other_xk);
4615 }
4616
4617 //=============================================================================
4618 // Convenience common pre-built types.
4619 const TypeAryPtr* TypeAryPtr::BOTTOM;
4620 const TypeAryPtr* TypeAryPtr::RANGE;
4621 const TypeAryPtr* TypeAryPtr::OOPS;
4622 const TypeAryPtr* TypeAryPtr::NARROWOOPS;
4623 const TypeAryPtr* TypeAryPtr::BYTES;
4624 const TypeAryPtr* TypeAryPtr::SHORTS;
4625 const TypeAryPtr* TypeAryPtr::CHARS;
4626 const TypeAryPtr* TypeAryPtr::INTS;
4627 const TypeAryPtr* TypeAryPtr::LONGS;
4628 const TypeAryPtr* TypeAryPtr::FLOATS;
4629 const TypeAryPtr* TypeAryPtr::DOUBLES;
4630
4631 //------------------------------make-------------------------------------------
4632 const TypeAryPtr *TypeAryPtr::make(PTR ptr, const TypeAry *ary, ciKlass* k, bool xk, int offset,
4633 int instance_id, const TypePtr* speculative, int inline_depth) {
4634 assert(!(k == nullptr && ary->_elem->isa_int()),
4635 "integral arrays must be pre-equipped with a class");
4636 if (!xk) xk = ary->ary_must_be_exact();
4637 assert(instance_id <= 0 || xk, "instances are always exactly typed");
4638 if (k != nullptr && k->is_loaded() && k->is_obj_array_klass() &&
4639 k->as_obj_array_klass()->base_element_klass()->is_interface()) {
4640 k = nullptr;
4641 }
4642 return (TypeAryPtr*)(new TypeAryPtr(ptr, nullptr, ary, k, xk, offset, instance_id, false, speculative, inline_depth))->hashcons();
4643 }
4644
4645 //------------------------------make-------------------------------------------
4646 const TypeAryPtr *TypeAryPtr::make(PTR ptr, ciObject* o, const TypeAry *ary, ciKlass* k, bool xk, int offset,
4647 int instance_id, const TypePtr* speculative, int inline_depth,
4648 bool is_autobox_cache) {
4649 assert(!(k == nullptr && ary->_elem->isa_int()),
4650 "integral arrays must be pre-equipped with a class");
4651 assert( (ptr==Constant && o) || (ptr!=Constant && !o), "" );
4652 if (!xk) xk = (o != nullptr) || ary->ary_must_be_exact();
4653 assert(instance_id <= 0 || xk, "instances are always exactly typed");
4654 if (k != nullptr && k->is_loaded() && k->is_obj_array_klass() &&
4655 k->as_obj_array_klass()->base_element_klass()->is_interface()) {
4656 k = nullptr;
4657 }
4658 return (TypeAryPtr*)(new TypeAryPtr(ptr, o, ary, k, xk, offset, instance_id, is_autobox_cache, speculative, inline_depth))->hashcons();
4659 }
4660
4661 //------------------------------cast_to_ptr_type-------------------------------
4662 const TypeAryPtr* TypeAryPtr::cast_to_ptr_type(PTR ptr) const {
4663 if( ptr == _ptr ) return this;
4664 return make(ptr, ptr == Constant ? const_oop() : nullptr, _ary, klass(), klass_is_exact(), _offset, _instance_id, _speculative, _inline_depth);
4665 }
4666
4667
4668 //-----------------------------cast_to_exactness-------------------------------
4669 const TypeAryPtr* TypeAryPtr::cast_to_exactness(bool klass_is_exact) const {
4670 if( klass_is_exact == _klass_is_exact ) return this;
4671 if (_ary->ary_must_be_exact()) return this; // cannot clear xk
4672 return make(ptr(), const_oop(), _ary, klass(), klass_is_exact, _offset, _instance_id, _speculative, _inline_depth);
4673 }
4674
4675 //-----------------------------cast_to_instance_id----------------------------
4676 const TypeAryPtr* TypeAryPtr::cast_to_instance_id(int instance_id) const {
4677 if( instance_id == _instance_id ) return this;
4678 return make(_ptr, const_oop(), _ary, klass(), _klass_is_exact, _offset, instance_id, _speculative, _inline_depth);
4679 }
4680
4681
4682 //-----------------------------max_array_length-------------------------------
4683 // A wrapper around arrayOopDesc::max_array_length(etype) with some input normalization.
4684 jint TypeAryPtr::max_array_length(BasicType etype) {
4685 if (!is_java_primitive(etype) && !::is_reference_type(etype)) {
4686 if (etype == T_NARROWOOP) {
4687 etype = T_OBJECT;
4688 } else if (etype == T_ILLEGAL) { // bottom[]
4689 etype = T_BYTE; // will produce conservatively high value
4690 } else {
4691 fatal("not an element type: %s", type2name(etype));
4692 }
4693 }
4694 return arrayOopDesc::max_array_length(etype);
4695 }
4696
4697 //-----------------------------narrow_size_type-------------------------------
4698 // Narrow the given size type to the index range for the given array base type.
4699 // Return null if the resulting int type becomes empty.
4700 const TypeInt* TypeAryPtr::narrow_size_type(const TypeInt* size) const {
4701 jint hi = size->_hi;
4702 jint lo = size->_lo;
4703 jint min_lo = 0;
4704 jint max_hi = max_array_length(elem()->array_element_basic_type());
4705 //if (index_not_size) --max_hi; // type of a valid array index, FTR
4706 bool chg = false;
4707 if (lo < min_lo) {
4708 lo = min_lo;
4709 if (size->is_con()) {
4710 hi = lo;
4711 }
4712 chg = true;
4713 }
4714 if (hi > max_hi) {
4715 hi = max_hi;
4716 if (size->is_con()) {
4717 lo = hi;
4718 }
4719 chg = true;
4720 }
4721 // Negative length arrays will produce weird intermediate dead fast-path code
4722 if (lo > hi) {
4723 return TypeInt::ZERO;
4724 }
4725 if (!chg) {
4726 return size;
4727 }
4728 return TypeInt::make(lo, hi, Type::WidenMin);
4729 }
4730
4731 //-------------------------------cast_to_size----------------------------------
4732 const TypeAryPtr* TypeAryPtr::cast_to_size(const TypeInt* new_size) const {
4733 assert(new_size != nullptr, "");
4734 new_size = narrow_size_type(new_size);
4735 if (new_size == size()) return this;
4736 const TypeAry* new_ary = TypeAry::make(elem(), new_size, is_stable());
4737 return make(ptr(), const_oop(), new_ary, klass(), klass_is_exact(), _offset, _instance_id, _speculative, _inline_depth);
4738 }
4739
4740 //------------------------------cast_to_stable---------------------------------
4741 const TypeAryPtr* TypeAryPtr::cast_to_stable(bool stable, int stable_dimension) const {
4742 if (stable_dimension <= 0 || (stable_dimension == 1 && stable == this->is_stable()))
4743 return this;
4744
4745 const Type* elem = this->elem();
4746 const TypePtr* elem_ptr = elem->make_ptr();
4747
4748 if (stable_dimension > 1 && elem_ptr != nullptr && elem_ptr->isa_aryptr()) {
4749 // If this is widened from a narrow oop, TypeAry::make will re-narrow it.
4750 elem = elem_ptr = elem_ptr->is_aryptr()->cast_to_stable(stable, stable_dimension - 1);
4751 }
4752
4753 const TypeAry* new_ary = TypeAry::make(elem, size(), stable);
4754
4755 return make(ptr(), const_oop(), new_ary, klass(), klass_is_exact(), _offset, _instance_id, _speculative, _inline_depth);
4756 }
4757
4758 //-----------------------------stable_dimension--------------------------------
4759 int TypeAryPtr::stable_dimension() const {
4760 if (!is_stable()) return 0;
4761 int dim = 1;
4762 const TypePtr* elem_ptr = elem()->make_ptr();
4763 if (elem_ptr != nullptr && elem_ptr->isa_aryptr())
4764 dim += elem_ptr->is_aryptr()->stable_dimension();
4765 return dim;
4766 }
4767
4768 //----------------------cast_to_autobox_cache-----------------------------------
4769 const TypeAryPtr* TypeAryPtr::cast_to_autobox_cache() const {
4770 if (is_autobox_cache()) return this;
4771 const TypeOopPtr* etype = elem()->make_oopptr();
4772 if (etype == nullptr) return this;
4773 // The pointers in the autobox arrays are always non-null.
4774 etype = etype->cast_to_ptr_type(TypePtr::NotNull)->is_oopptr();
4775 const TypeAry* new_ary = TypeAry::make(etype, size(), is_stable());
4776 return make(ptr(), const_oop(), new_ary, klass(), klass_is_exact(), _offset, _instance_id, _speculative, _inline_depth, /*is_autobox_cache=*/true);
4777 }
4778
4779 //------------------------------eq---------------------------------------------
4780 // Structural equality check for Type representations
4781 bool TypeAryPtr::eq( const Type *t ) const {
4782 const TypeAryPtr *p = t->is_aryptr();
4783 return
4784 _ary == p->_ary && // Check array
4785 TypeOopPtr::eq(p); // Check sub-parts
4786 }
4787
4788 //------------------------------hash-------------------------------------------
4789 // Type-specific hashing function.
4790 uint TypeAryPtr::hash(void) const {
4791 return (uint)(uintptr_t)_ary + TypeOopPtr::hash();
4792 }
4793
4794 bool TypeAryPtr::is_java_subtype_of_helper(const TypeOopPtr* other, bool this_exact, bool other_exact) const {
4795 return TypePtr::is_java_subtype_of_helper_for_array(this, other, this_exact, other_exact);
4796 }
4797
4798 bool TypeAryPtr::is_same_java_type_as_helper(const TypeOopPtr* other) const {
4799 return TypePtr::is_same_java_type_as_helper_for_array(this, other);
4800 }
4801
4802 bool TypeAryPtr::maybe_java_subtype_of_helper(const TypeOopPtr* other, bool this_exact, bool other_exact) const {
4803 return TypePtr::maybe_java_subtype_of_helper_for_array(this, other, this_exact, other_exact);
4804 }
4805 //------------------------------meet-------------------------------------------
4806 // Compute the MEET of two types. It returns a new Type object.
4807 const Type *TypeAryPtr::xmeet_helper(const Type *t) const {
4808 // Perform a fast test for common case; meeting the same types together.
4809 if( this == t ) return this; // Meeting same type-rep?
4810 // Current "this->_base" is Pointer
4811 switch (t->base()) { // switch on original type
4812
4813 // Mixing ints & oops happens when javac reuses local variables
4814 case Int:
4815 case Long:
4816 case HalfFloatTop:
4817 case HalfFloatCon:
4818 case HalfFloatBot:
4819 case FloatTop:
4820 case FloatCon:
4821 case FloatBot:
4822 case DoubleTop:
4823 case DoubleCon:
4824 case DoubleBot:
4825 case NarrowOop:
4826 case NarrowKlass:
4827 case Bottom: // Ye Olde Default
4828 return Type::BOTTOM;
4829 case Top:
4830 return this;
4831
4832 default: // All else is a mistake
4833 typerr(t);
4834
4835 case OopPtr: { // Meeting to OopPtrs
4836 // Found a OopPtr type vs self-AryPtr type
4837 const TypeOopPtr *tp = t->is_oopptr();
4838 int offset = meet_offset(tp->offset());
4839 PTR ptr = meet_ptr(tp->ptr());
4840 int depth = meet_inline_depth(tp->inline_depth());
4841 const TypePtr* speculative = xmeet_speculative(tp);
4842 switch (tp->ptr()) {
4843 case TopPTR:
4844 case AnyNull: {
4845 int instance_id = meet_instance_id(InstanceTop);
4846 return make(ptr, (ptr == Constant ? const_oop() : nullptr),
4847 _ary, _klass, _klass_is_exact, offset, instance_id, speculative, depth);
4848 }
4849 case BotPTR:
4850 case NotNull: {
4851 int instance_id = meet_instance_id(tp->instance_id());
4852 return TypeOopPtr::make(ptr, offset, instance_id, speculative, depth);
4853 }
4854 default: ShouldNotReachHere();
4855 }
4856 }
4857
4858 case AnyPtr: { // Meeting two AnyPtrs
4859 // Found an AnyPtr type vs self-AryPtr type
4860 const TypePtr *tp = t->is_ptr();
4861 int offset = meet_offset(tp->offset());
4862 PTR ptr = meet_ptr(tp->ptr());
4863 const TypePtr* speculative = xmeet_speculative(tp);
4864 int depth = meet_inline_depth(tp->inline_depth());
4865 switch (tp->ptr()) {
4866 case TopPTR:
4867 return this;
4868 case BotPTR:
4869 case NotNull:
4870 return TypePtr::make(AnyPtr, ptr, offset, speculative, depth);
4871 case Null:
4872 if( ptr == Null ) return TypePtr::make(AnyPtr, ptr, offset, speculative, depth);
4873 // else fall through to AnyNull
4874 case AnyNull: {
4875 int instance_id = meet_instance_id(InstanceTop);
4876 return make(ptr, (ptr == Constant ? const_oop() : nullptr),
4877 _ary, _klass, _klass_is_exact, offset, instance_id, speculative, depth);
4878 }
4879 default: ShouldNotReachHere();
4880 }
4881 }
4882
4883 case MetadataPtr:
4884 case KlassPtr:
4885 case InstKlassPtr:
4886 case AryKlassPtr:
4887 case RawPtr: return TypePtr::BOTTOM;
4888
4889 case AryPtr: { // Meeting 2 references?
4890 const TypeAryPtr *tap = t->is_aryptr();
4891 int off = meet_offset(tap->offset());
4892 const Type* tm = _ary->meet_speculative(tap->_ary);
4893 const TypeAry* tary = tm->isa_ary();
4894 if (tary == nullptr) {
4895 assert(tm == Type::TOP || tm == Type::BOTTOM, "");
4896 return tm;
4897 }
4898 PTR ptr = meet_ptr(tap->ptr());
4899 int instance_id = meet_instance_id(tap->instance_id());
4900 const TypePtr* speculative = xmeet_speculative(tap);
4901 int depth = meet_inline_depth(tap->inline_depth());
4902
4903 ciKlass* res_klass = nullptr;
4904 bool res_xk = false;
4905 const Type* elem = tary->_elem;
4906 if (meet_aryptr(ptr, elem, this, tap, res_klass, res_xk) == NOT_SUBTYPE) {
4907 instance_id = InstanceBot;
4908 }
4909
4910 ciObject* o = nullptr; // Assume not constant when done
4911 ciObject* this_oop = const_oop();
4912 ciObject* tap_oop = tap->const_oop();
4913 if (ptr == Constant) {
4914 if (this_oop != nullptr && tap_oop != nullptr &&
4915 this_oop->equals(tap_oop)) {
4916 o = tap_oop;
4917 } else if (above_centerline(_ptr)) {
4918 o = tap_oop;
4919 } else if (above_centerline(tap->_ptr)) {
4920 o = this_oop;
4921 } else {
4922 ptr = NotNull;
4923 }
4924 }
4925 return make(ptr, o, TypeAry::make(elem, tary->_size, tary->_stable), res_klass, res_xk, off, instance_id, speculative, depth);
4926 }
4927
4928 // All arrays inherit from Object class
4929 case InstPtr: {
4930 const TypeInstPtr *tp = t->is_instptr();
4931 int offset = meet_offset(tp->offset());
4932 PTR ptr = meet_ptr(tp->ptr());
4933 int instance_id = meet_instance_id(tp->instance_id());
4934 const TypePtr* speculative = xmeet_speculative(tp);
4935 int depth = meet_inline_depth(tp->inline_depth());
4936 const TypeInterfaces* interfaces = meet_interfaces(tp);
4937 const TypeInterfaces* tp_interfaces = tp->_interfaces;
4938 const TypeInterfaces* this_interfaces = _interfaces;
4939
4940 switch (ptr) {
4941 case TopPTR:
4942 case AnyNull: // Fall 'down' to dual of object klass
4943 // For instances when a subclass meets a superclass we fall
4944 // below the centerline when the superclass is exact. We need to
4945 // do the same here.
4946 if (tp->klass()->equals(ciEnv::current()->Object_klass()) && this_interfaces->contains(tp_interfaces) && !tp->klass_is_exact()) {
4947 return TypeAryPtr::make(ptr, _ary, _klass, _klass_is_exact, offset, instance_id, speculative, depth);
4948 } else {
4949 // cannot subclass, so the meet has to fall badly below the centerline
4950 ptr = NotNull;
4951 instance_id = InstanceBot;
4952 interfaces = this_interfaces->intersection_with(tp_interfaces);
4953 return TypeInstPtr::make(ptr, ciEnv::current()->Object_klass(), interfaces, false, nullptr,offset, instance_id, speculative, depth);
4954 }
4955 case Constant:
4956 case NotNull:
4957 case BotPTR: // Fall down to object klass
4958 // LCA is object_klass, but if we subclass from the top we can do better
4959 if (above_centerline(tp->ptr())) {
4960 // If 'tp' is above the centerline and it is Object class
4961 // then we can subclass in the Java class hierarchy.
4962 // For instances when a subclass meets a superclass we fall
4963 // below the centerline when the superclass is exact. We need
4964 // to do the same here.
4965 if (tp->klass()->equals(ciEnv::current()->Object_klass()) && this_interfaces->contains(tp_interfaces) && !tp->klass_is_exact()) {
4966 // that is, my array type is a subtype of 'tp' klass
4967 return make(ptr, (ptr == Constant ? const_oop() : nullptr),
4968 _ary, _klass, _klass_is_exact, offset, instance_id, speculative, depth);
4969 }
4970 }
4971 // The other case cannot happen, since t cannot be a subtype of an array.
4972 // The meet falls down to Object class below centerline.
4973 if (ptr == Constant) {
4974 ptr = NotNull;
4975 }
4976 if (instance_id > 0) {
4977 instance_id = InstanceBot;
4978 }
4979 interfaces = this_interfaces->intersection_with(tp_interfaces);
4980 return TypeInstPtr::make(ptr, ciEnv::current()->Object_klass(), interfaces, false, nullptr, offset, instance_id, speculative, depth);
4981 default: typerr(t);
4982 }
4983 }
4984 }
4985 return this; // Lint noise
4986 }
4987
4988
4989 template<class T> TypePtr::MeetResult TypePtr::meet_aryptr(PTR& ptr, const Type*& elem, const T* this_ary,
4990 const T* other_ary, ciKlass*& res_klass, bool& res_xk) {
4991 int dummy;
4992 bool this_top_or_bottom = (this_ary->base_element_type(dummy) == Type::TOP || this_ary->base_element_type(dummy) == Type::BOTTOM);
4993 bool other_top_or_bottom = (other_ary->base_element_type(dummy) == Type::TOP || other_ary->base_element_type(dummy) == Type::BOTTOM);
4994 ciKlass* this_klass = this_ary->klass();
4995 ciKlass* other_klass = other_ary->klass();
4996 bool this_xk = this_ary->klass_is_exact();
4997 bool other_xk = other_ary->klass_is_exact();
4998 PTR this_ptr = this_ary->ptr();
4999 PTR other_ptr = other_ary->ptr();
5000 res_klass = nullptr;
5001 MeetResult result = SUBTYPE;
5002 if (elem->isa_int()) {
5003 // Integral array element types have irrelevant lattice relations.
5004 // It is the klass that determines array layout, not the element type.
5005 if (this_top_or_bottom)
5006 res_klass = other_klass;
5007 else if (other_top_or_bottom || other_klass == this_klass) {
5008 res_klass = this_klass;
5009 } else {
5010 // Something like byte[int+] meets char[int+].
5011 // This must fall to bottom, not (int[-128..65535])[int+].
5012 // instance_id = InstanceBot;
5013 elem = Type::BOTTOM;
5014 result = NOT_SUBTYPE;
5015 if (above_centerline(ptr) || ptr == Constant) {
5016 ptr = NotNull;
5017 res_xk = false;
5018 return NOT_SUBTYPE;
5019 }
5020 }
5021 } else {// Non integral arrays.
5022 // Must fall to bottom if exact klasses in upper lattice
5023 // are not equal or super klass is exact.
5024 if ((above_centerline(ptr) || ptr == Constant) && !this_ary->is_same_java_type_as(other_ary) &&
5025 // meet with top[] and bottom[] are processed further down:
5026 !this_top_or_bottom && !other_top_or_bottom &&
5027 // both are exact and not equal:
5028 ((other_xk && this_xk) ||
5029 // 'tap' is exact and super or unrelated:
5030 (other_xk && !other_ary->is_meet_subtype_of(this_ary)) ||
5031 // 'this' is exact and super or unrelated:
5032 (this_xk && !this_ary->is_meet_subtype_of(other_ary)))) {
5033 if (above_centerline(ptr) || (elem->make_ptr() && above_centerline(elem->make_ptr()->_ptr))) {
5034 elem = Type::BOTTOM;
5035 }
5036 ptr = NotNull;
5037 res_xk = false;
5038 return NOT_SUBTYPE;
5039 }
5040 }
5041
5042 res_xk = false;
5043 switch (other_ptr) {
5044 case AnyNull:
5045 case TopPTR:
5046 // Compute new klass on demand, do not use tap->_klass
5047 if (below_centerline(this_ptr)) {
5048 res_xk = this_xk;
5049 } else {
5050 res_xk = (other_xk || this_xk);
5051 }
5052 return result;
5053 case Constant: {
5054 if (this_ptr == Constant) {
5055 res_xk = true;
5056 } else if(above_centerline(this_ptr)) {
5057 res_xk = true;
5058 } else {
5059 // Only precise for identical arrays
5060 res_xk = this_xk && (this_ary->is_same_java_type_as(other_ary) || (this_top_or_bottom && other_top_or_bottom));
5061 }
5062 return result;
5063 }
5064 case NotNull:
5065 case BotPTR:
5066 // Compute new klass on demand, do not use tap->_klass
5067 if (above_centerline(this_ptr)) {
5068 res_xk = other_xk;
5069 } else {
5070 res_xk = (other_xk && this_xk) &&
5071 (this_ary->is_same_java_type_as(other_ary) || (this_top_or_bottom && other_top_or_bottom)); // Only precise for identical arrays
5072 }
5073 return result;
5074 default: {
5075 ShouldNotReachHere();
5076 return result;
5077 }
5078 }
5079 return result;
5080 }
5081
5082
5083 //------------------------------xdual------------------------------------------
5084 // Dual: compute field-by-field dual
5085 const Type *TypeAryPtr::xdual() const {
5086 return new TypeAryPtr(dual_ptr(), _const_oop, _ary->dual()->is_ary(),_klass, _klass_is_exact, dual_offset(), dual_instance_id(), is_autobox_cache(), dual_speculative(), dual_inline_depth());
5087 }
5088
5089 //------------------------------dump2------------------------------------------
5090 #ifndef PRODUCT
5091 void TypeAryPtr::dump2( Dict &d, uint depth, outputStream *st ) const {
5092 st->print("aryptr:");
5093 _ary->dump2(d, depth, st);
5094 _interfaces->dump(st);
5095
5096 if (_ptr == Constant) {
5097 const_oop()->print(st);
5098 }
5099
5100 st->print(":%s", ptr_msg[_ptr]);
5101 if (_klass_is_exact) {
5102 st->print(":exact");
5103 }
5104
5105 if( _offset != 0 ) {
5106 BasicType basic_elem_type = elem()->basic_type();
5107 int header_size = arrayOopDesc::base_offset_in_bytes(basic_elem_type);
5108 if( _offset == OffsetTop ) st->print("+undefined");
5109 else if( _offset == OffsetBot ) st->print("+any");
5110 else if( _offset < header_size ) st->print("+%d", _offset);
5111 else {
5112 if (basic_elem_type == T_ILLEGAL) {
5113 st->print("+any");
5114 } else {
5115 int elem_size = type2aelembytes(basic_elem_type);
5116 st->print("[%d]", (_offset - header_size)/elem_size);
5117 }
5118 }
5119 }
5120
5121 dump_instance_id(st);
5122 dump_inline_depth(st);
5123 dump_speculative(st);
5124 }
5125 #endif
5126
5127 bool TypeAryPtr::empty(void) const {
5128 if (_ary->empty()) return true;
5129 return TypeOopPtr::empty();
5130 }
5131
5132 //------------------------------add_offset-------------------------------------
5133 const TypePtr* TypeAryPtr::add_offset(intptr_t offset) const {
5134 return make(_ptr, _const_oop, _ary, _klass, _klass_is_exact, xadd_offset(offset), _instance_id, add_offset_speculative(offset), _inline_depth);
5135 }
5136
5137 const TypeAryPtr* TypeAryPtr::with_offset(intptr_t offset) const {
5138 return make(_ptr, _const_oop, _ary, _klass, _klass_is_exact, offset, _instance_id, with_offset_speculative(offset), _inline_depth);
5139 }
5140
5141 const TypeAryPtr* TypeAryPtr::with_ary(const TypeAry* ary) const {
5142 return make(_ptr, _const_oop, ary, _klass, _klass_is_exact, _offset, _instance_id, _speculative, _inline_depth);
5143 }
5144
5145 const TypeAryPtr* TypeAryPtr::remove_speculative() const {
5146 if (_speculative == nullptr) {
5147 return this;
5148 }
5149 assert(_inline_depth == InlineDepthTop || _inline_depth == InlineDepthBottom, "non speculative type shouldn't have inline depth");
5150 return make(_ptr, _const_oop, _ary->remove_speculative()->is_ary(), _klass, _klass_is_exact, _offset, _instance_id, nullptr, _inline_depth);
5151 }
5152
5153 const TypePtr* TypeAryPtr::with_inline_depth(int depth) const {
5154 if (!UseInlineDepthForSpeculativeTypes) {
5155 return this;
5156 }
5157 return make(_ptr, _const_oop, _ary->remove_speculative()->is_ary(), _klass, _klass_is_exact, _offset, _instance_id, _speculative, depth);
5158 }
5159
5160 const TypePtr* TypeAryPtr::with_instance_id(int instance_id) const {
5161 assert(is_known_instance(), "should be known");
5162 return make(_ptr, _const_oop, _ary->remove_speculative()->is_ary(), _klass, _klass_is_exact, _offset, instance_id, _speculative, _inline_depth);
5163 }
5164
5165 //=============================================================================
5166
5167 //------------------------------hash-------------------------------------------
5168 // Type-specific hashing function.
5169 uint TypeNarrowPtr::hash(void) const {
5170 return _ptrtype->hash() + 7;
5171 }
5172
5173 bool TypeNarrowPtr::singleton(void) const { // TRUE if type is a singleton
5174 return _ptrtype->singleton();
5175 }
5176
5177 bool TypeNarrowPtr::empty(void) const {
5178 return _ptrtype->empty();
5179 }
5180
5181 intptr_t TypeNarrowPtr::get_con() const {
5182 return _ptrtype->get_con();
5183 }
5184
5185 bool TypeNarrowPtr::eq( const Type *t ) const {
5186 const TypeNarrowPtr* tc = isa_same_narrowptr(t);
5187 if (tc != nullptr) {
5188 if (_ptrtype->base() != tc->_ptrtype->base()) {
5189 return false;
5190 }
5191 return tc->_ptrtype->eq(_ptrtype);
5192 }
5193 return false;
5194 }
5195
5196 const Type *TypeNarrowPtr::xdual() const { // Compute dual right now.
5197 const TypePtr* odual = _ptrtype->dual()->is_ptr();
5198 return make_same_narrowptr(odual);
5199 }
5200
5201
5202 const Type *TypeNarrowPtr::filter_helper(const Type *kills, bool include_speculative) const {
5203 if (isa_same_narrowptr(kills)) {
5204 const Type* ft =_ptrtype->filter_helper(is_same_narrowptr(kills)->_ptrtype, include_speculative);
5205 if (ft->empty())
5206 return Type::TOP; // Canonical empty value
5207 if (ft->isa_ptr()) {
5208 return make_hash_same_narrowptr(ft->isa_ptr());
5209 }
5210 return ft;
5211 } else if (kills->isa_ptr()) {
5212 const Type* ft = _ptrtype->join_helper(kills, include_speculative);
5213 if (ft->empty())
5214 return Type::TOP; // Canonical empty value
5215 return ft;
5216 } else {
5217 return Type::TOP;
5218 }
5219 }
5220
5221 //------------------------------xmeet------------------------------------------
5222 // Compute the MEET of two types. It returns a new Type object.
5223 const Type *TypeNarrowPtr::xmeet( const Type *t ) const {
5224 // Perform a fast test for common case; meeting the same types together.
5225 if( this == t ) return this; // Meeting same type-rep?
5226
5227 if (t->base() == base()) {
5228 const Type* result = _ptrtype->xmeet(t->make_ptr());
5229 if (result->isa_ptr()) {
5230 return make_hash_same_narrowptr(result->is_ptr());
5231 }
5232 return result;
5233 }
5234
5235 // Current "this->_base" is NarrowKlass or NarrowOop
5236 switch (t->base()) { // switch on original type
5237
5238 case Int: // Mixing ints & oops happens when javac
5239 case Long: // reuses local variables
5240 case HalfFloatTop:
5241 case HalfFloatCon:
5242 case HalfFloatBot:
5243 case FloatTop:
5244 case FloatCon:
5245 case FloatBot:
5246 case DoubleTop:
5247 case DoubleCon:
5248 case DoubleBot:
5249 case AnyPtr:
5250 case RawPtr:
5251 case OopPtr:
5252 case InstPtr:
5253 case AryPtr:
5254 case MetadataPtr:
5255 case KlassPtr:
5256 case InstKlassPtr:
5257 case AryKlassPtr:
5258 case NarrowOop:
5259 case NarrowKlass:
5260
5261 case Bottom: // Ye Olde Default
5262 return Type::BOTTOM;
5263 case Top:
5264 return this;
5265
5266 default: // All else is a mistake
5267 typerr(t);
5268
5269 } // End of switch
5270
5271 return this;
5272 }
5273
5274 #ifndef PRODUCT
5275 void TypeNarrowPtr::dump2( Dict & d, uint depth, outputStream *st ) const {
5276 _ptrtype->dump2(d, depth, st);
5277 }
5278 #endif
5279
5280 const TypeNarrowOop *TypeNarrowOop::BOTTOM;
5281 const TypeNarrowOop *TypeNarrowOop::NULL_PTR;
5282
5283
5284 const TypeNarrowOop* TypeNarrowOop::make(const TypePtr* type) {
5285 return (const TypeNarrowOop*)(new TypeNarrowOop(type))->hashcons();
5286 }
5287
5288 const TypeNarrowOop* TypeNarrowOop::remove_speculative() const {
5289 return make(_ptrtype->remove_speculative()->is_ptr());
5290 }
5291
5292 const Type* TypeNarrowOop::cleanup_speculative() const {
5293 return make(_ptrtype->cleanup_speculative()->is_ptr());
5294 }
5295
5296 #ifndef PRODUCT
5297 void TypeNarrowOop::dump2( Dict & d, uint depth, outputStream *st ) const {
5298 st->print("narrowoop: ");
5299 TypeNarrowPtr::dump2(d, depth, st);
5300 }
5301 #endif
5302
5303 const TypeNarrowKlass *TypeNarrowKlass::NULL_PTR;
5304
5305 const TypeNarrowKlass* TypeNarrowKlass::make(const TypePtr* type) {
5306 return (const TypeNarrowKlass*)(new TypeNarrowKlass(type))->hashcons();
5307 }
5308
5309 #ifndef PRODUCT
5310 void TypeNarrowKlass::dump2( Dict & d, uint depth, outputStream *st ) const {
5311 st->print("narrowklass: ");
5312 TypeNarrowPtr::dump2(d, depth, st);
5313 }
5314 #endif
5315
5316
5317 //------------------------------eq---------------------------------------------
5318 // Structural equality check for Type representations
5319 bool TypeMetadataPtr::eq( const Type *t ) const {
5320 const TypeMetadataPtr *a = (const TypeMetadataPtr*)t;
5321 ciMetadata* one = metadata();
5322 ciMetadata* two = a->metadata();
5323 if (one == nullptr || two == nullptr) {
5324 return (one == two) && TypePtr::eq(t);
5325 } else {
5326 return one->equals(two) && TypePtr::eq(t);
5327 }
5328 }
5329
5330 //------------------------------hash-------------------------------------------
5331 // Type-specific hashing function.
5332 uint TypeMetadataPtr::hash(void) const {
5333 return
5334 (metadata() ? metadata()->hash() : 0) +
5335 TypePtr::hash();
5336 }
5337
5338 //------------------------------singleton--------------------------------------
5339 // TRUE if Type is a singleton type, FALSE otherwise. Singletons are simple
5340 // constants
5341 bool TypeMetadataPtr::singleton(void) const {
5342 // detune optimizer to not generate constant metadata + constant offset as a constant!
5343 // TopPTR, Null, AnyNull, Constant are all singletons
5344 return (_offset == 0) && !below_centerline(_ptr);
5345 }
5346
5347 //------------------------------add_offset-------------------------------------
5348 const TypePtr* TypeMetadataPtr::add_offset( intptr_t offset ) const {
5349 return make( _ptr, _metadata, xadd_offset(offset));
5350 }
5351
5352 //-----------------------------filter------------------------------------------
5353 // Do not allow interface-vs.-noninterface joins to collapse to top.
5354 const Type *TypeMetadataPtr::filter_helper(const Type *kills, bool include_speculative) const {
5355 const TypeMetadataPtr* ft = join_helper(kills, include_speculative)->isa_metadataptr();
5356 if (ft == nullptr || ft->empty())
5357 return Type::TOP; // Canonical empty value
5358 return ft;
5359 }
5360
5361 //------------------------------get_con----------------------------------------
5362 intptr_t TypeMetadataPtr::get_con() const {
5363 assert( _ptr == Null || _ptr == Constant, "" );
5364 assert( _offset >= 0, "" );
5365
5366 if (_offset != 0) {
5367 // After being ported to the compiler interface, the compiler no longer
5368 // directly manipulates the addresses of oops. Rather, it only has a pointer
5369 // to a handle at compile time. This handle is embedded in the generated
5370 // code and dereferenced at the time the nmethod is made. Until that time,
5371 // it is not reasonable to do arithmetic with the addresses of oops (we don't
5372 // have access to the addresses!). This does not seem to currently happen,
5373 // but this assertion here is to help prevent its occurrence.
5374 tty->print_cr("Found oop constant with non-zero offset");
5375 ShouldNotReachHere();
5376 }
5377
5378 return (intptr_t)metadata()->constant_encoding();
5379 }
5380
5381 //------------------------------cast_to_ptr_type-------------------------------
5382 const TypeMetadataPtr* TypeMetadataPtr::cast_to_ptr_type(PTR ptr) const {
5383 if( ptr == _ptr ) return this;
5384 return make(ptr, metadata(), _offset);
5385 }
5386
5387 //------------------------------meet-------------------------------------------
5388 // Compute the MEET of two types. It returns a new Type object.
5389 const Type *TypeMetadataPtr::xmeet( const Type *t ) const {
5390 // Perform a fast test for common case; meeting the same types together.
5391 if( this == t ) return this; // Meeting same type-rep?
5392
5393 // Current "this->_base" is OopPtr
5394 switch (t->base()) { // switch on original type
5395
5396 case Int: // Mixing ints & oops happens when javac
5397 case Long: // reuses local variables
5398 case HalfFloatTop:
5399 case HalfFloatCon:
5400 case HalfFloatBot:
5401 case FloatTop:
5402 case FloatCon:
5403 case FloatBot:
5404 case DoubleTop:
5405 case DoubleCon:
5406 case DoubleBot:
5407 case NarrowOop:
5408 case NarrowKlass:
5409 case Bottom: // Ye Olde Default
5410 return Type::BOTTOM;
5411 case Top:
5412 return this;
5413
5414 default: // All else is a mistake
5415 typerr(t);
5416
5417 case AnyPtr: {
5418 // Found an AnyPtr type vs self-OopPtr type
5419 const TypePtr *tp = t->is_ptr();
5420 int offset = meet_offset(tp->offset());
5421 PTR ptr = meet_ptr(tp->ptr());
5422 switch (tp->ptr()) {
5423 case Null:
5424 if (ptr == Null) return TypePtr::make(AnyPtr, ptr, offset, tp->speculative(), tp->inline_depth());
5425 // else fall through:
5426 case TopPTR:
5427 case AnyNull: {
5428 return make(ptr, _metadata, offset);
5429 }
5430 case BotPTR:
5431 case NotNull:
5432 return TypePtr::make(AnyPtr, ptr, offset, tp->speculative(), tp->inline_depth());
5433 default: typerr(t);
5434 }
5435 }
5436
5437 case RawPtr:
5438 case KlassPtr:
5439 case InstKlassPtr:
5440 case AryKlassPtr:
5441 case OopPtr:
5442 case InstPtr:
5443 case AryPtr:
5444 return TypePtr::BOTTOM; // Oop meet raw is not well defined
5445
5446 case MetadataPtr: {
5447 const TypeMetadataPtr *tp = t->is_metadataptr();
5448 int offset = meet_offset(tp->offset());
5449 PTR tptr = tp->ptr();
5450 PTR ptr = meet_ptr(tptr);
5451 ciMetadata* md = (tptr == TopPTR) ? metadata() : tp->metadata();
5452 if (tptr == TopPTR || _ptr == TopPTR ||
5453 metadata()->equals(tp->metadata())) {
5454 return make(ptr, md, offset);
5455 }
5456 // metadata is different
5457 if( ptr == Constant ) { // Cannot be equal constants, so...
5458 if( tptr == Constant && _ptr != Constant) return t;
5459 if( _ptr == Constant && tptr != Constant) return this;
5460 ptr = NotNull; // Fall down in lattice
5461 }
5462 return make(ptr, nullptr, offset);
5463 break;
5464 }
5465 } // End of switch
5466 return this; // Return the double constant
5467 }
5468
5469
5470 //------------------------------xdual------------------------------------------
5471 // Dual of a pure metadata pointer.
5472 const Type *TypeMetadataPtr::xdual() const {
5473 return new TypeMetadataPtr(dual_ptr(), metadata(), dual_offset());
5474 }
5475
5476 //------------------------------dump2------------------------------------------
5477 #ifndef PRODUCT
5478 void TypeMetadataPtr::dump2( Dict &d, uint depth, outputStream *st ) const {
5479 st->print("metadataptr:%s", ptr_msg[_ptr]);
5480 if (metadata() != nullptr) {
5481 st->print(":" INTPTR_FORMAT, p2i(metadata()));
5482 }
5483 dump_offset(st);
5484 }
5485 #endif
5486
5487
5488 //=============================================================================
5489 // Convenience common pre-built type.
5490 const TypeMetadataPtr *TypeMetadataPtr::BOTTOM;
5491
5492 TypeMetadataPtr::TypeMetadataPtr(PTR ptr, ciMetadata* metadata, int offset):
5493 TypePtr(MetadataPtr, ptr, offset), _metadata(metadata) {
5494 }
5495
5496 const TypeMetadataPtr* TypeMetadataPtr::make(ciMethod* m) {
5497 return make(Constant, m, 0);
5498 }
5499 const TypeMetadataPtr* TypeMetadataPtr::make(ciMethodData* m) {
5500 return make(Constant, m, 0);
5501 }
5502
5503 //------------------------------make-------------------------------------------
5504 // Create a meta data constant
5505 const TypeMetadataPtr *TypeMetadataPtr::make(PTR ptr, ciMetadata* m, int offset) {
5506 assert(m == nullptr || !m->is_klass(), "wrong type");
5507 return (TypeMetadataPtr*)(new TypeMetadataPtr(ptr, m, offset))->hashcons();
5508 }
5509
5510
5511 const TypeKlassPtr* TypeAryPtr::as_klass_type(bool try_for_exact) const {
5512 const Type* elem = _ary->_elem;
5513 bool xk = klass_is_exact();
5514 if (elem->make_oopptr() != nullptr) {
5515 elem = elem->make_oopptr()->as_klass_type(try_for_exact);
5516 if (elem->is_klassptr()->klass_is_exact()) {
5517 xk = true;
5518 }
5519 }
5520 return TypeAryKlassPtr::make(xk ? TypePtr::Constant : TypePtr::NotNull, elem, klass(), 0);
5521 }
5522
5523 const TypeKlassPtr* TypeKlassPtr::make(ciKlass *klass, InterfaceHandling interface_handling) {
5524 if (klass->is_instance_klass()) {
5525 return TypeInstKlassPtr::make(klass, interface_handling);
5526 }
5527 return TypeAryKlassPtr::make(klass, interface_handling);
5528 }
5529
5530 const TypeKlassPtr* TypeKlassPtr::make(PTR ptr, ciKlass* klass, int offset, InterfaceHandling interface_handling) {
5531 if (klass->is_instance_klass()) {
5532 const TypeInterfaces* interfaces = TypePtr::interfaces(klass, true, true, false, interface_handling);
5533 return TypeInstKlassPtr::make(ptr, klass, interfaces, offset);
5534 }
5535 return TypeAryKlassPtr::make(ptr, klass, offset, interface_handling);
5536 }
5537
5538
5539 //------------------------------TypeKlassPtr-----------------------------------
5540 TypeKlassPtr::TypeKlassPtr(TYPES t, PTR ptr, ciKlass* klass, const TypeInterfaces* interfaces, int offset)
5541 : TypePtr(t, ptr, offset), _klass(klass), _interfaces(interfaces) {
5542 assert(klass == nullptr || !klass->is_loaded() || (klass->is_instance_klass() && !klass->is_interface()) ||
5543 klass->is_type_array_klass() || !klass->as_obj_array_klass()->base_element_klass()->is_interface(), "no interface here");
5544 }
5545
5546 // Is there a single ciKlass* that can represent that type?
5547 ciKlass* TypeKlassPtr::exact_klass_helper() const {
5548 assert(_klass->is_instance_klass() && !_klass->is_interface(), "No interface");
5549 if (_interfaces->empty()) {
5550 return _klass;
5551 }
5552 if (_klass != ciEnv::current()->Object_klass()) {
5553 if (_interfaces->eq(_klass->as_instance_klass())) {
5554 return _klass;
5555 }
5556 return nullptr;
5557 }
5558 return _interfaces->exact_klass();
5559 }
5560
5561 //------------------------------eq---------------------------------------------
5562 // Structural equality check for Type representations
5563 bool TypeKlassPtr::eq(const Type *t) const {
5564 const TypeKlassPtr *p = t->is_klassptr();
5565 return
5566 _interfaces->eq(p->_interfaces) &&
5567 TypePtr::eq(p);
5568 }
5569
5570 //------------------------------hash-------------------------------------------
5571 // Type-specific hashing function.
5572 uint TypeKlassPtr::hash(void) const {
5573 return TypePtr::hash() + _interfaces->hash();
5574 }
5575
5576 //------------------------------singleton--------------------------------------
5577 // TRUE if Type is a singleton type, FALSE otherwise. Singletons are simple
5578 // constants
5579 bool TypeKlassPtr::singleton(void) const {
5580 // detune optimizer to not generate constant klass + constant offset as a constant!
5581 // TopPTR, Null, AnyNull, Constant are all singletons
5582 return (_offset == 0) && !below_centerline(_ptr);
5583 }
5584
5585 // Do not allow interface-vs.-noninterface joins to collapse to top.
5586 const Type *TypeKlassPtr::filter_helper(const Type *kills, bool include_speculative) const {
5587 // logic here mirrors the one from TypeOopPtr::filter. See comments
5588 // there.
5589 const Type* ft = join_helper(kills, include_speculative);
5590
5591 if (ft->empty()) {
5592 return Type::TOP; // Canonical empty value
5593 }
5594
5595 return ft;
5596 }
5597
5598 const TypeInterfaces* TypeKlassPtr::meet_interfaces(const TypeKlassPtr* other) const {
5599 if (above_centerline(_ptr) && above_centerline(other->_ptr)) {
5600 return _interfaces->union_with(other->_interfaces);
5601 } else if (above_centerline(_ptr) && !above_centerline(other->_ptr)) {
5602 return other->_interfaces;
5603 } else if (above_centerline(other->_ptr) && !above_centerline(_ptr)) {
5604 return _interfaces;
5605 }
5606 return _interfaces->intersection_with(other->_interfaces);
5607 }
5608
5609 //------------------------------get_con----------------------------------------
5610 intptr_t TypeKlassPtr::get_con() const {
5611 assert( _ptr == Null || _ptr == Constant, "" );
5612 assert( _offset >= 0, "" );
5613
5614 if (_offset != 0) {
5615 // After being ported to the compiler interface, the compiler no longer
5616 // directly manipulates the addresses of oops. Rather, it only has a pointer
5617 // to a handle at compile time. This handle is embedded in the generated
5618 // code and dereferenced at the time the nmethod is made. Until that time,
5619 // it is not reasonable to do arithmetic with the addresses of oops (we don't
5620 // have access to the addresses!). This does not seem to currently happen,
5621 // but this assertion here is to help prevent its occurrence.
5622 tty->print_cr("Found oop constant with non-zero offset");
5623 ShouldNotReachHere();
5624 }
5625
5626 ciKlass* k = exact_klass();
5627
5628 return (intptr_t)k->constant_encoding();
5629 }
5630
5631 //=============================================================================
5632 // Convenience common pre-built types.
5633
5634 // Not-null object klass or below
5635 const TypeInstKlassPtr *TypeInstKlassPtr::OBJECT;
5636 const TypeInstKlassPtr *TypeInstKlassPtr::OBJECT_OR_NULL;
5637
5638 bool TypeInstKlassPtr::eq(const Type *t) const {
5639 const TypeKlassPtr *p = t->is_klassptr();
5640 return
5641 klass()->equals(p->klass()) &&
5642 TypeKlassPtr::eq(p);
5643 }
5644
5645 uint TypeInstKlassPtr::hash(void) const {
5646 return klass()->hash() + TypeKlassPtr::hash();
5647 }
5648
5649 const TypeInstKlassPtr *TypeInstKlassPtr::make(PTR ptr, ciKlass* k, const TypeInterfaces* interfaces, int offset) {
5650 TypeInstKlassPtr *r =
5651 (TypeInstKlassPtr*)(new TypeInstKlassPtr(ptr, k, interfaces, offset))->hashcons();
5652
5653 return r;
5654 }
5655
5656 //------------------------------add_offset-------------------------------------
5657 // Access internals of klass object
5658 const TypePtr* TypeInstKlassPtr::add_offset( intptr_t offset ) const {
5659 return make( _ptr, klass(), _interfaces, xadd_offset(offset) );
5660 }
5661
5662 const TypeInstKlassPtr* TypeInstKlassPtr::with_offset(intptr_t offset) const {
5663 return make(_ptr, klass(), _interfaces, offset);
5664 }
5665
5666 //------------------------------cast_to_ptr_type-------------------------------
5667 const TypeInstKlassPtr* TypeInstKlassPtr::cast_to_ptr_type(PTR ptr) const {
5668 assert(_base == InstKlassPtr, "subclass must override cast_to_ptr_type");
5669 if( ptr == _ptr ) return this;
5670 return make(ptr, _klass, _interfaces, _offset);
5671 }
5672
5673
5674 bool TypeInstKlassPtr::must_be_exact() const {
5675 if (!_klass->is_loaded()) return false;
5676 ciInstanceKlass* ik = _klass->as_instance_klass();
5677 if (ik->is_final()) return true; // cannot clear xk
5678 return false;
5679 }
5680
5681 //-----------------------------cast_to_exactness-------------------------------
5682 const TypeKlassPtr* TypeInstKlassPtr::cast_to_exactness(bool klass_is_exact) const {
5683 if (klass_is_exact == (_ptr == Constant)) return this;
5684 if (must_be_exact()) return this;
5685 ciKlass* k = klass();
5686 return make(klass_is_exact ? Constant : NotNull, k, _interfaces, _offset);
5687 }
5688
5689
5690 //-----------------------------as_instance_type--------------------------------
5691 // Corresponding type for an instance of the given class.
5692 // It will be NotNull, and exact if and only if the klass type is exact.
5693 const TypeOopPtr* TypeInstKlassPtr::as_instance_type(bool klass_change) const {
5694 ciKlass* k = klass();
5695 bool xk = klass_is_exact();
5696 Compile* C = Compile::current();
5697 Dependencies* deps = C->dependencies();
5698 assert((deps != nullptr) == (C->method() != nullptr && C->method()->code_size() > 0), "sanity");
5699 // Element is an instance
5700 bool klass_is_exact = false;
5701 const TypeInterfaces* interfaces = _interfaces;
5702 if (k->is_loaded()) {
5703 // Try to set klass_is_exact.
5704 ciInstanceKlass* ik = k->as_instance_klass();
5705 klass_is_exact = ik->is_final();
5706 if (!klass_is_exact && klass_change
5707 && deps != nullptr && UseUniqueSubclasses) {
5708 ciInstanceKlass* sub = ik->unique_concrete_subklass();
5709 if (sub != nullptr) {
5710 if (_interfaces->eq(sub)) {
5711 deps->assert_abstract_with_unique_concrete_subtype(ik, sub);
5712 k = ik = sub;
5713 xk = sub->is_final();
5714 }
5715 }
5716 }
5717 }
5718 return TypeInstPtr::make(TypePtr::BotPTR, k, interfaces, xk, nullptr, 0);
5719 }
5720
5721 //------------------------------xmeet------------------------------------------
5722 // Compute the MEET of two types, return a new Type object.
5723 const Type *TypeInstKlassPtr::xmeet( const Type *t ) const {
5724 // Perform a fast test for common case; meeting the same types together.
5725 if( this == t ) return this; // Meeting same type-rep?
5726
5727 // Current "this->_base" is Pointer
5728 switch (t->base()) { // switch on original type
5729
5730 case Int: // Mixing ints & oops happens when javac
5731 case Long: // reuses local variables
5732 case HalfFloatTop:
5733 case HalfFloatCon:
5734 case HalfFloatBot:
5735 case FloatTop:
5736 case FloatCon:
5737 case FloatBot:
5738 case DoubleTop:
5739 case DoubleCon:
5740 case DoubleBot:
5741 case NarrowOop:
5742 case NarrowKlass:
5743 case Bottom: // Ye Olde Default
5744 return Type::BOTTOM;
5745 case Top:
5746 return this;
5747
5748 default: // All else is a mistake
5749 typerr(t);
5750
5751 case AnyPtr: { // Meeting to AnyPtrs
5752 // Found an AnyPtr type vs self-KlassPtr type
5753 const TypePtr *tp = t->is_ptr();
5754 int offset = meet_offset(tp->offset());
5755 PTR ptr = meet_ptr(tp->ptr());
5756 switch (tp->ptr()) {
5757 case TopPTR:
5758 return this;
5759 case Null:
5760 if( ptr == Null ) return TypePtr::make(AnyPtr, ptr, offset, tp->speculative(), tp->inline_depth());
5761 case AnyNull:
5762 return make( ptr, klass(), _interfaces, offset );
5763 case BotPTR:
5764 case NotNull:
5765 return TypePtr::make(AnyPtr, ptr, offset, tp->speculative(), tp->inline_depth());
5766 default: typerr(t);
5767 }
5768 }
5769
5770 case RawPtr:
5771 case MetadataPtr:
5772 case OopPtr:
5773 case AryPtr: // Meet with AryPtr
5774 case InstPtr: // Meet with InstPtr
5775 return TypePtr::BOTTOM;
5776
5777 //
5778 // A-top }
5779 // / | \ } Tops
5780 // B-top A-any C-top }
5781 // | / | \ | } Any-nulls
5782 // B-any | C-any }
5783 // | | |
5784 // B-con A-con C-con } constants; not comparable across classes
5785 // | | |
5786 // B-not | C-not }
5787 // | \ | / | } not-nulls
5788 // B-bot A-not C-bot }
5789 // \ | / } Bottoms
5790 // A-bot }
5791 //
5792
5793 case InstKlassPtr: { // Meet two KlassPtr types
5794 const TypeInstKlassPtr *tkls = t->is_instklassptr();
5795 int off = meet_offset(tkls->offset());
5796 PTR ptr = meet_ptr(tkls->ptr());
5797 const TypeInterfaces* interfaces = meet_interfaces(tkls);
5798
5799 ciKlass* res_klass = nullptr;
5800 bool res_xk = false;
5801 switch(meet_instptr(ptr, interfaces, this, tkls, res_klass, res_xk)) {
5802 case UNLOADED:
5803 ShouldNotReachHere();
5804 case SUBTYPE:
5805 case NOT_SUBTYPE:
5806 case LCA:
5807 case QUICK: {
5808 assert(res_xk == (ptr == Constant), "");
5809 const Type* res = make(ptr, res_klass, interfaces, off);
5810 return res;
5811 }
5812 default:
5813 ShouldNotReachHere();
5814 }
5815 } // End of case KlassPtr
5816 case AryKlassPtr: { // All arrays inherit from Object class
5817 const TypeAryKlassPtr *tp = t->is_aryklassptr();
5818 int offset = meet_offset(tp->offset());
5819 PTR ptr = meet_ptr(tp->ptr());
5820 const TypeInterfaces* interfaces = meet_interfaces(tp);
5821 const TypeInterfaces* tp_interfaces = tp->_interfaces;
5822 const TypeInterfaces* this_interfaces = _interfaces;
5823
5824 switch (ptr) {
5825 case TopPTR:
5826 case AnyNull: // Fall 'down' to dual of object klass
5827 // For instances when a subclass meets a superclass we fall
5828 // below the centerline when the superclass is exact. We need to
5829 // do the same here.
5830 if (klass()->equals(ciEnv::current()->Object_klass()) && tp_interfaces->contains(this_interfaces) && !klass_is_exact()) {
5831 return TypeAryKlassPtr::make(ptr, tp->elem(), tp->klass(), offset);
5832 } else {
5833 // cannot subclass, so the meet has to fall badly below the centerline
5834 ptr = NotNull;
5835 interfaces = _interfaces->intersection_with(tp->_interfaces);
5836 return make(ptr, ciEnv::current()->Object_klass(), interfaces, offset);
5837 }
5838 case Constant:
5839 case NotNull:
5840 case BotPTR: // Fall down to object klass
5841 // LCA is object_klass, but if we subclass from the top we can do better
5842 if( above_centerline(_ptr) ) { // if( _ptr == TopPTR || _ptr == AnyNull )
5843 // If 'this' (InstPtr) is above the centerline and it is Object class
5844 // then we can subclass in the Java class hierarchy.
5845 // For instances when a subclass meets a superclass we fall
5846 // below the centerline when the superclass is exact. We need
5847 // to do the same here.
5848 if (klass()->equals(ciEnv::current()->Object_klass()) && tp_interfaces->contains(this_interfaces) && !klass_is_exact()) {
5849 // that is, tp's array type is a subtype of my klass
5850 return TypeAryKlassPtr::make(ptr,
5851 tp->elem(), tp->klass(), offset);
5852 }
5853 }
5854 // The other case cannot happen, since I cannot be a subtype of an array.
5855 // The meet falls down to Object class below centerline.
5856 if( ptr == Constant )
5857 ptr = NotNull;
5858 interfaces = this_interfaces->intersection_with(tp_interfaces);
5859 return make(ptr, ciEnv::current()->Object_klass(), interfaces, offset);
5860 default: typerr(t);
5861 }
5862 }
5863
5864 } // End of switch
5865 return this; // Return the double constant
5866 }
5867
5868 //------------------------------xdual------------------------------------------
5869 // Dual: compute field-by-field dual
5870 const Type *TypeInstKlassPtr::xdual() const {
5871 return new TypeInstKlassPtr(dual_ptr(), klass(), _interfaces, dual_offset());
5872 }
5873
5874 template <class T1, class T2> bool TypePtr::is_java_subtype_of_helper_for_instance(const T1* this_one, const T2* other, bool this_exact, bool other_exact) {
5875 static_assert(std::is_base_of<T2, T1>::value, "");
5876 if (!this_one->is_loaded() || !other->is_loaded()) {
5877 return false;
5878 }
5879 if (!this_one->is_instance_type(other)) {
5880 return false;
5881 }
5882
5883 if (!other_exact) {
5884 return false;
5885 }
5886
5887 if (other->klass()->equals(ciEnv::current()->Object_klass()) && other->_interfaces->empty()) {
5888 return true;
5889 }
5890
5891 return this_one->klass()->is_subtype_of(other->klass()) && this_one->_interfaces->contains(other->_interfaces);
5892 }
5893
5894 bool TypeInstKlassPtr::might_be_an_array() const {
5895 if (!instance_klass()->is_java_lang_Object()) {
5896 // TypeInstKlassPtr can be an array only if it is java.lang.Object: the only supertype of array types.
5897 return false;
5898 }
5899 if (interfaces()->has_non_array_interface()) {
5900 // Arrays only implement Cloneable and Serializable. If we see any other interface, [this] cannot be an array.
5901 return false;
5902 }
5903 // Cannot prove it's not an array.
5904 return true;
5905 }
5906
5907 bool TypeInstKlassPtr::is_java_subtype_of_helper(const TypeKlassPtr* other, bool this_exact, bool other_exact) const {
5908 return TypePtr::is_java_subtype_of_helper_for_instance(this, other, this_exact, other_exact);
5909 }
5910
5911 template <class T1, class T2> bool TypePtr::is_same_java_type_as_helper_for_instance(const T1* this_one, const T2* other) {
5912 static_assert(std::is_base_of<T2, T1>::value, "");
5913 if (!this_one->is_loaded() || !other->is_loaded()) {
5914 return false;
5915 }
5916 if (!this_one->is_instance_type(other)) {
5917 return false;
5918 }
5919 return this_one->klass()->equals(other->klass()) && this_one->_interfaces->eq(other->_interfaces);
5920 }
5921
5922 bool TypeInstKlassPtr::is_same_java_type_as_helper(const TypeKlassPtr* other) const {
5923 return TypePtr::is_same_java_type_as_helper_for_instance(this, other);
5924 }
5925
5926 template <class T1, class T2> bool TypePtr::maybe_java_subtype_of_helper_for_instance(const T1* this_one, const T2* other, bool this_exact, bool other_exact) {
5927 static_assert(std::is_base_of<T2, T1>::value, "");
5928 if (!this_one->is_loaded() || !other->is_loaded()) {
5929 return true;
5930 }
5931
5932 if (this_one->is_array_type(other)) {
5933 return !this_exact && this_one->klass()->equals(ciEnv::current()->Object_klass()) && other->_interfaces->contains(this_one->_interfaces);
5934 }
5935
5936 assert(this_one->is_instance_type(other), "unsupported");
5937
5938 if (this_exact && other_exact) {
5939 return this_one->is_java_subtype_of(other);
5940 }
5941
5942 if (!this_one->klass()->is_subtype_of(other->klass()) && !other->klass()->is_subtype_of(this_one->klass())) {
5943 return false;
5944 }
5945
5946 if (this_exact) {
5947 return this_one->klass()->is_subtype_of(other->klass()) && this_one->_interfaces->contains(other->_interfaces);
5948 }
5949
5950 return true;
5951 }
5952
5953 bool TypeInstKlassPtr::maybe_java_subtype_of_helper(const TypeKlassPtr* other, bool this_exact, bool other_exact) const {
5954 return TypePtr::maybe_java_subtype_of_helper_for_instance(this, other, this_exact, other_exact);
5955 }
5956
5957 const TypeKlassPtr* TypeInstKlassPtr::try_improve() const {
5958 if (!UseUniqueSubclasses) {
5959 return this;
5960 }
5961 ciKlass* k = klass();
5962 Compile* C = Compile::current();
5963 Dependencies* deps = C->dependencies();
5964 assert((deps != nullptr) == (C->method() != nullptr && C->method()->code_size() > 0), "sanity");
5965 const TypeInterfaces* interfaces = _interfaces;
5966 if (k->is_loaded()) {
5967 ciInstanceKlass* ik = k->as_instance_klass();
5968 bool klass_is_exact = ik->is_final();
5969 if (!klass_is_exact &&
5970 deps != nullptr) {
5971 ciInstanceKlass* sub = ik->unique_concrete_subklass();
5972 if (sub != nullptr) {
5973 if (_interfaces->eq(sub)) {
5974 deps->assert_abstract_with_unique_concrete_subtype(ik, sub);
5975 k = ik = sub;
5976 klass_is_exact = sub->is_final();
5977 return TypeKlassPtr::make(klass_is_exact ? Constant : _ptr, k, _offset);
5978 }
5979 }
5980 }
5981 }
5982 return this;
5983 }
5984
5985 #ifndef PRODUCT
5986 void TypeInstKlassPtr::dump2(Dict& d, uint depth, outputStream* st) const {
5987 st->print("instklassptr:");
5988 klass()->print_name_on(st);
5989 _interfaces->dump(st);
5990 st->print(":%s", ptr_msg[_ptr]);
5991 dump_offset(st);
5992 }
5993 #endif // PRODUCT
5994
5995 const TypeAryKlassPtr *TypeAryKlassPtr::make(PTR ptr, const Type* elem, ciKlass* k, int offset) {
5996 return (TypeAryKlassPtr*)(new TypeAryKlassPtr(ptr, elem, k, offset))->hashcons();
5997 }
5998
5999 const TypeAryKlassPtr *TypeAryKlassPtr::make(PTR ptr, ciKlass* k, int offset, InterfaceHandling interface_handling) {
6000 if (k->is_obj_array_klass()) {
6001 // Element is an object array. Recursively call ourself.
6002 ciKlass* eklass = k->as_obj_array_klass()->element_klass();
6003 const TypeKlassPtr *etype = TypeKlassPtr::make(eklass, interface_handling)->cast_to_exactness(false);
6004 return TypeAryKlassPtr::make(ptr, etype, nullptr, offset);
6005 } else if (k->is_type_array_klass()) {
6006 // Element is an typeArray
6007 const Type* etype = get_const_basic_type(k->as_type_array_klass()->element_type());
6008 return TypeAryKlassPtr::make(ptr, etype, k, offset);
6009 } else {
6010 ShouldNotReachHere();
6011 return nullptr;
6012 }
6013 }
6014
6015 const TypeAryKlassPtr* TypeAryKlassPtr::make(ciKlass* klass, InterfaceHandling interface_handling) {
6016 return TypeAryKlassPtr::make(Constant, klass, 0, interface_handling);
6017 }
6018
6019 //------------------------------eq---------------------------------------------
6020 // Structural equality check for Type representations
6021 bool TypeAryKlassPtr::eq(const Type *t) const {
6022 const TypeAryKlassPtr *p = t->is_aryklassptr();
6023 return
6024 _elem == p->_elem && // Check array
6025 TypeKlassPtr::eq(p); // Check sub-parts
6026 }
6027
6028 //------------------------------hash-------------------------------------------
6029 // Type-specific hashing function.
6030 uint TypeAryKlassPtr::hash(void) const {
6031 return (uint)(uintptr_t)_elem + TypeKlassPtr::hash();
6032 }
6033
6034 //----------------------compute_klass------------------------------------------
6035 // Compute the defining klass for this class
6036 ciKlass* TypeAryPtr::compute_klass() const {
6037 // Compute _klass based on element type.
6038 ciKlass* k_ary = nullptr;
6039 const TypeInstPtr *tinst;
6040 const TypeAryPtr *tary;
6041 const Type* el = elem();
6042 if (el->isa_narrowoop()) {
6043 el = el->make_ptr();
6044 }
6045
6046 // Get element klass
6047 if ((tinst = el->isa_instptr()) != nullptr) {
6048 // Leave k_ary at null.
6049 } else if ((tary = el->isa_aryptr()) != nullptr) {
6050 // Leave k_ary at null.
6051 } else if ((el->base() == Type::Top) ||
6052 (el->base() == Type::Bottom)) {
6053 // element type of Bottom occurs from meet of basic type
6054 // and object; Top occurs when doing join on Bottom.
6055 // Leave k_ary at null.
6056 } else {
6057 assert(!el->isa_int(), "integral arrays must be pre-equipped with a class");
6058 // Compute array klass directly from basic type
6059 k_ary = ciTypeArrayKlass::make(el->basic_type());
6060 }
6061 return k_ary;
6062 }
6063
6064 //------------------------------klass------------------------------------------
6065 // Return the defining klass for this class
6066 ciKlass* TypeAryPtr::klass() const {
6067 if( _klass ) return _klass; // Return cached value, if possible
6068
6069 // Oops, need to compute _klass and cache it
6070 ciKlass* k_ary = compute_klass();
6071
6072 if( this != TypeAryPtr::OOPS && this->dual() != TypeAryPtr::OOPS ) {
6073 // The _klass field acts as a cache of the underlying
6074 // ciKlass for this array type. In order to set the field,
6075 // we need to cast away const-ness.
6076 //
6077 // IMPORTANT NOTE: we *never* set the _klass field for the
6078 // type TypeAryPtr::OOPS. This Type is shared between all
6079 // active compilations. However, the ciKlass which represents
6080 // this Type is *not* shared between compilations, so caching
6081 // this value would result in fetching a dangling pointer.
6082 //
6083 // Recomputing the underlying ciKlass for each request is
6084 // a bit less efficient than caching, but calls to
6085 // TypeAryPtr::OOPS->klass() are not common enough to matter.
6086 ((TypeAryPtr*)this)->_klass = k_ary;
6087 }
6088 return k_ary;
6089 }
6090
6091 // Is there a single ciKlass* that can represent that type?
6092 ciKlass* TypeAryPtr::exact_klass_helper() const {
6093 if (_ary->_elem->make_ptr() && _ary->_elem->make_ptr()->isa_oopptr()) {
6094 ciKlass* k = _ary->_elem->make_ptr()->is_oopptr()->exact_klass_helper();
6095 if (k == nullptr) {
6096 return nullptr;
6097 }
6098 k = ciObjArrayKlass::make(k);
6099 return k;
6100 }
6101
6102 return klass();
6103 }
6104
6105 const Type* TypeAryPtr::base_element_type(int& dims) const {
6106 const Type* elem = this->elem();
6107 dims = 1;
6108 while (elem->make_ptr() && elem->make_ptr()->isa_aryptr()) {
6109 elem = elem->make_ptr()->is_aryptr()->elem();
6110 dims++;
6111 }
6112 return elem;
6113 }
6114
6115 //------------------------------add_offset-------------------------------------
6116 // Access internals of klass object
6117 const TypePtr* TypeAryKlassPtr::add_offset(intptr_t offset) const {
6118 return make(_ptr, elem(), klass(), xadd_offset(offset));
6119 }
6120
6121 const TypeAryKlassPtr* TypeAryKlassPtr::with_offset(intptr_t offset) const {
6122 return make(_ptr, elem(), klass(), offset);
6123 }
6124
6125 //------------------------------cast_to_ptr_type-------------------------------
6126 const TypeAryKlassPtr* TypeAryKlassPtr::cast_to_ptr_type(PTR ptr) const {
6127 assert(_base == AryKlassPtr, "subclass must override cast_to_ptr_type");
6128 if (ptr == _ptr) return this;
6129 return make(ptr, elem(), _klass, _offset);
6130 }
6131
6132 bool TypeAryKlassPtr::must_be_exact() const {
6133 if (_elem == Type::BOTTOM) return false;
6134 if (_elem == Type::TOP ) return false;
6135 const TypeKlassPtr* tk = _elem->isa_klassptr();
6136 if (!tk) return true; // a primitive type, like int
6137 return tk->must_be_exact();
6138 }
6139
6140
6141 //-----------------------------cast_to_exactness-------------------------------
6142 const TypeKlassPtr *TypeAryKlassPtr::cast_to_exactness(bool klass_is_exact) const {
6143 if (must_be_exact()) return this; // cannot clear xk
6144 ciKlass* k = _klass;
6145 const Type* elem = this->elem();
6146 if (elem->isa_klassptr() && !klass_is_exact) {
6147 elem = elem->is_klassptr()->cast_to_exactness(klass_is_exact);
6148 }
6149 return make(klass_is_exact ? Constant : NotNull, elem, k, _offset);
6150 }
6151
6152
6153 //-----------------------------as_instance_type--------------------------------
6154 // Corresponding type for an instance of the given class.
6155 // It will be NotNull, and exact if and only if the klass type is exact.
6156 const TypeOopPtr* TypeAryKlassPtr::as_instance_type(bool klass_change) const {
6157 ciKlass* k = klass();
6158 bool xk = klass_is_exact();
6159 const Type* el = nullptr;
6160 if (elem()->isa_klassptr()) {
6161 el = elem()->is_klassptr()->as_instance_type(false)->cast_to_exactness(false);
6162 k = nullptr;
6163 } else {
6164 el = elem();
6165 }
6166 return TypeAryPtr::make(TypePtr::BotPTR, TypeAry::make(el, TypeInt::POS), k, xk, 0);
6167 }
6168
6169
6170 //------------------------------xmeet------------------------------------------
6171 // Compute the MEET of two types, return a new Type object.
6172 const Type *TypeAryKlassPtr::xmeet( const Type *t ) const {
6173 // Perform a fast test for common case; meeting the same types together.
6174 if( this == t ) return this; // Meeting same type-rep?
6175
6176 // Current "this->_base" is Pointer
6177 switch (t->base()) { // switch on original type
6178
6179 case Int: // Mixing ints & oops happens when javac
6180 case Long: // reuses local variables
6181 case HalfFloatTop:
6182 case HalfFloatCon:
6183 case HalfFloatBot:
6184 case FloatTop:
6185 case FloatCon:
6186 case FloatBot:
6187 case DoubleTop:
6188 case DoubleCon:
6189 case DoubleBot:
6190 case NarrowOop:
6191 case NarrowKlass:
6192 case Bottom: // Ye Olde Default
6193 return Type::BOTTOM;
6194 case Top:
6195 return this;
6196
6197 default: // All else is a mistake
6198 typerr(t);
6199
6200 case AnyPtr: { // Meeting to AnyPtrs
6201 // Found an AnyPtr type vs self-KlassPtr type
6202 const TypePtr *tp = t->is_ptr();
6203 int offset = meet_offset(tp->offset());
6204 PTR ptr = meet_ptr(tp->ptr());
6205 switch (tp->ptr()) {
6206 case TopPTR:
6207 return this;
6208 case Null:
6209 if( ptr == Null ) return TypePtr::make(AnyPtr, ptr, offset, tp->speculative(), tp->inline_depth());
6210 case AnyNull:
6211 return make( ptr, _elem, klass(), offset );
6212 case BotPTR:
6213 case NotNull:
6214 return TypePtr::make(AnyPtr, ptr, offset, tp->speculative(), tp->inline_depth());
6215 default: typerr(t);
6216 }
6217 }
6218
6219 case RawPtr:
6220 case MetadataPtr:
6221 case OopPtr:
6222 case AryPtr: // Meet with AryPtr
6223 case InstPtr: // Meet with InstPtr
6224 return TypePtr::BOTTOM;
6225
6226 //
6227 // A-top }
6228 // / | \ } Tops
6229 // B-top A-any C-top }
6230 // | / | \ | } Any-nulls
6231 // B-any | C-any }
6232 // | | |
6233 // B-con A-con C-con } constants; not comparable across classes
6234 // | | |
6235 // B-not | C-not }
6236 // | \ | / | } not-nulls
6237 // B-bot A-not C-bot }
6238 // \ | / } Bottoms
6239 // A-bot }
6240 //
6241
6242 case AryKlassPtr: { // Meet two KlassPtr types
6243 const TypeAryKlassPtr *tap = t->is_aryklassptr();
6244 int off = meet_offset(tap->offset());
6245 const Type* elem = _elem->meet(tap->_elem);
6246
6247 PTR ptr = meet_ptr(tap->ptr());
6248 ciKlass* res_klass = nullptr;
6249 bool res_xk = false;
6250 meet_aryptr(ptr, elem, this, tap, res_klass, res_xk);
6251 assert(res_xk == (ptr == Constant), "");
6252 return make(ptr, elem, res_klass, off);
6253 } // End of case KlassPtr
6254 case InstKlassPtr: {
6255 const TypeInstKlassPtr *tp = t->is_instklassptr();
6256 int offset = meet_offset(tp->offset());
6257 PTR ptr = meet_ptr(tp->ptr());
6258 const TypeInterfaces* interfaces = meet_interfaces(tp);
6259 const TypeInterfaces* tp_interfaces = tp->_interfaces;
6260 const TypeInterfaces* this_interfaces = _interfaces;
6261
6262 switch (ptr) {
6263 case TopPTR:
6264 case AnyNull: // Fall 'down' to dual of object klass
6265 // For instances when a subclass meets a superclass we fall
6266 // below the centerline when the superclass is exact. We need to
6267 // do the same here.
6268 if (tp->klass()->equals(ciEnv::current()->Object_klass()) && this_interfaces->contains(tp_interfaces) &&
6269 !tp->klass_is_exact()) {
6270 return TypeAryKlassPtr::make(ptr, _elem, _klass, offset);
6271 } else {
6272 // cannot subclass, so the meet has to fall badly below the centerline
6273 ptr = NotNull;
6274 interfaces = this_interfaces->intersection_with(tp->_interfaces);
6275 return TypeInstKlassPtr::make(ptr, ciEnv::current()->Object_klass(), interfaces, offset);
6276 }
6277 case Constant:
6278 case NotNull:
6279 case BotPTR: // Fall down to object klass
6280 // LCA is object_klass, but if we subclass from the top we can do better
6281 if (above_centerline(tp->ptr())) {
6282 // If 'tp' is above the centerline and it is Object class
6283 // then we can subclass in the Java class hierarchy.
6284 // For instances when a subclass meets a superclass we fall
6285 // below the centerline when the superclass is exact. We need
6286 // to do the same here.
6287 if (tp->klass()->equals(ciEnv::current()->Object_klass()) && this_interfaces->contains(tp_interfaces) &&
6288 !tp->klass_is_exact()) {
6289 // that is, my array type is a subtype of 'tp' klass
6290 return make(ptr, _elem, _klass, offset);
6291 }
6292 }
6293 // The other case cannot happen, since t cannot be a subtype of an array.
6294 // The meet falls down to Object class below centerline.
6295 if (ptr == Constant)
6296 ptr = NotNull;
6297 interfaces = this_interfaces->intersection_with(tp_interfaces);
6298 return TypeInstKlassPtr::make(ptr, ciEnv::current()->Object_klass(), interfaces, offset);
6299 default: typerr(t);
6300 }
6301 }
6302
6303 } // End of switch
6304 return this; // Return the double constant
6305 }
6306
6307 template <class T1, class T2> bool TypePtr::is_java_subtype_of_helper_for_array(const T1* this_one, const T2* other, bool this_exact, bool other_exact) {
6308 static_assert(std::is_base_of<T2, T1>::value, "");
6309
6310 if (other->klass() == ciEnv::current()->Object_klass() && other->_interfaces->empty() && other_exact) {
6311 return true;
6312 }
6313
6314 int dummy;
6315 bool this_top_or_bottom = (this_one->base_element_type(dummy) == Type::TOP || this_one->base_element_type(dummy) == Type::BOTTOM);
6316
6317 if (!this_one->is_loaded() || !other->is_loaded() || this_top_or_bottom) {
6318 return false;
6319 }
6320
6321 if (this_one->is_instance_type(other)) {
6322 return other->klass() == ciEnv::current()->Object_klass() && this_one->_interfaces->contains(other->_interfaces) &&
6323 other_exact;
6324 }
6325
6326 assert(this_one->is_array_type(other), "");
6327 const T1* other_ary = this_one->is_array_type(other);
6328 bool other_top_or_bottom = (other_ary->base_element_type(dummy) == Type::TOP || other_ary->base_element_type(dummy) == Type::BOTTOM);
6329 if (other_top_or_bottom) {
6330 return false;
6331 }
6332
6333 const TypePtr* other_elem = other_ary->elem()->make_ptr();
6334 const TypePtr* this_elem = this_one->elem()->make_ptr();
6335 if (this_elem != nullptr && other_elem != nullptr) {
6336 return this_one->is_reference_type(this_elem)->is_java_subtype_of_helper(this_one->is_reference_type(other_elem), this_exact, other_exact);
6337 }
6338 if (this_elem == nullptr && other_elem == nullptr) {
6339 return this_one->klass()->is_subtype_of(other->klass());
6340 }
6341 return false;
6342 }
6343
6344 bool TypeAryKlassPtr::is_java_subtype_of_helper(const TypeKlassPtr* other, bool this_exact, bool other_exact) const {
6345 return TypePtr::is_java_subtype_of_helper_for_array(this, other, this_exact, other_exact);
6346 }
6347
6348 template <class T1, class T2> bool TypePtr::is_same_java_type_as_helper_for_array(const T1* this_one, const T2* other) {
6349 static_assert(std::is_base_of<T2, T1>::value, "");
6350
6351 int dummy;
6352 bool this_top_or_bottom = (this_one->base_element_type(dummy) == Type::TOP || this_one->base_element_type(dummy) == Type::BOTTOM);
6353
6354 if (!this_one->is_array_type(other) ||
6355 !this_one->is_loaded() || !other->is_loaded() || this_top_or_bottom) {
6356 return false;
6357 }
6358 const T1* other_ary = this_one->is_array_type(other);
6359 bool other_top_or_bottom = (other_ary->base_element_type(dummy) == Type::TOP || other_ary->base_element_type(dummy) == Type::BOTTOM);
6360
6361 if (other_top_or_bottom) {
6362 return false;
6363 }
6364
6365 const TypePtr* other_elem = other_ary->elem()->make_ptr();
6366 const TypePtr* this_elem = this_one->elem()->make_ptr();
6367 if (other_elem != nullptr && this_elem != nullptr) {
6368 return this_one->is_reference_type(this_elem)->is_same_java_type_as(this_one->is_reference_type(other_elem));
6369 }
6370 if (other_elem == nullptr && this_elem == nullptr) {
6371 return this_one->klass()->equals(other->klass());
6372 }
6373 return false;
6374 }
6375
6376 bool TypeAryKlassPtr::is_same_java_type_as_helper(const TypeKlassPtr* other) const {
6377 return TypePtr::is_same_java_type_as_helper_for_array(this, other);
6378 }
6379
6380 template <class T1, class T2> bool TypePtr::maybe_java_subtype_of_helper_for_array(const T1* this_one, const T2* other, bool this_exact, bool other_exact) {
6381 static_assert(std::is_base_of<T2, T1>::value, "");
6382 if (other->klass() == ciEnv::current()->Object_klass() && other->_interfaces->empty() && other_exact) {
6383 return true;
6384 }
6385 if (!this_one->is_loaded() || !other->is_loaded()) {
6386 return true;
6387 }
6388 if (this_one->is_instance_type(other)) {
6389 return other->klass()->equals(ciEnv::current()->Object_klass()) &&
6390 this_one->_interfaces->contains(other->_interfaces);
6391 }
6392
6393 int dummy;
6394 bool this_top_or_bottom = (this_one->base_element_type(dummy) == Type::TOP || this_one->base_element_type(dummy) == Type::BOTTOM);
6395 if (this_top_or_bottom) {
6396 return true;
6397 }
6398
6399 assert(this_one->is_array_type(other), "");
6400
6401 const T1* other_ary = this_one->is_array_type(other);
6402 bool other_top_or_bottom = (other_ary->base_element_type(dummy) == Type::TOP || other_ary->base_element_type(dummy) == Type::BOTTOM);
6403 if (other_top_or_bottom) {
6404 return true;
6405 }
6406 if (this_exact && other_exact) {
6407 return this_one->is_java_subtype_of(other);
6408 }
6409
6410 const TypePtr* this_elem = this_one->elem()->make_ptr();
6411 const TypePtr* other_elem = other_ary->elem()->make_ptr();
6412 if (other_elem != nullptr && this_elem != nullptr) {
6413 return this_one->is_reference_type(this_elem)->maybe_java_subtype_of_helper(this_one->is_reference_type(other_elem), this_exact, other_exact);
6414 }
6415 if (other_elem == nullptr && this_elem == nullptr) {
6416 return this_one->klass()->is_subtype_of(other->klass());
6417 }
6418 return false;
6419 }
6420
6421 bool TypeAryKlassPtr::maybe_java_subtype_of_helper(const TypeKlassPtr* other, bool this_exact, bool other_exact) const {
6422 return TypePtr::maybe_java_subtype_of_helper_for_array(this, other, this_exact, other_exact);
6423 }
6424
6425 //------------------------------xdual------------------------------------------
6426 // Dual: compute field-by-field dual
6427 const Type *TypeAryKlassPtr::xdual() const {
6428 return new TypeAryKlassPtr(dual_ptr(), elem()->dual(), klass(), dual_offset());
6429 }
6430
6431 // Is there a single ciKlass* that can represent that type?
6432 ciKlass* TypeAryKlassPtr::exact_klass_helper() const {
6433 if (elem()->isa_klassptr()) {
6434 ciKlass* k = elem()->is_klassptr()->exact_klass_helper();
6435 if (k == nullptr) {
6436 return nullptr;
6437 }
6438 k = ciObjArrayKlass::make(k);
6439 return k;
6440 }
6441
6442 return klass();
6443 }
6444
6445 ciKlass* TypeAryKlassPtr::klass() const {
6446 if (_klass != nullptr) {
6447 return _klass;
6448 }
6449 ciKlass* k = nullptr;
6450 if (elem()->isa_klassptr()) {
6451 // leave null
6452 } else if ((elem()->base() == Type::Top) ||
6453 (elem()->base() == Type::Bottom)) {
6454 } else {
6455 k = ciTypeArrayKlass::make(elem()->basic_type());
6456 ((TypeAryKlassPtr*)this)->_klass = k;
6457 }
6458 return k;
6459 }
6460
6461 //------------------------------dump2------------------------------------------
6462 // Dump Klass Type
6463 #ifndef PRODUCT
6464 void TypeAryKlassPtr::dump2( Dict & d, uint depth, outputStream *st ) const {
6465 st->print("aryklassptr:[");
6466 _elem->dump2(d, depth, st);
6467 _interfaces->dump(st);
6468 st->print(":%s", ptr_msg[_ptr]);
6469 dump_offset(st);
6470 }
6471 #endif
6472
6473 const Type* TypeAryKlassPtr::base_element_type(int& dims) const {
6474 const Type* elem = this->elem();
6475 dims = 1;
6476 while (elem->isa_aryklassptr()) {
6477 elem = elem->is_aryklassptr()->elem();
6478 dims++;
6479 }
6480 return elem;
6481 }
6482
6483 //=============================================================================
6484 // Convenience common pre-built types.
6485
6486 //------------------------------make-------------------------------------------
6487 const TypeFunc *TypeFunc::make( const TypeTuple *domain, const TypeTuple *range ) {
6488 return (TypeFunc*)(new TypeFunc(domain,range))->hashcons();
6489 }
6490
6491 //------------------------------make-------------------------------------------
6492 const TypeFunc *TypeFunc::make(ciMethod* method) {
6493 Compile* C = Compile::current();
6494 const TypeFunc* tf = C->last_tf(method); // check cache
6495 if (tf != nullptr) return tf; // The hit rate here is almost 50%.
6496 const TypeTuple *domain;
6497 if (method->is_static()) {
6498 domain = TypeTuple::make_domain(nullptr, method->signature(), ignore_interfaces);
6499 } else {
6500 domain = TypeTuple::make_domain(method->holder(), method->signature(), ignore_interfaces);
6501 }
6502 const TypeTuple *range = TypeTuple::make_range(method->signature(), ignore_interfaces);
6503 tf = TypeFunc::make(domain, range);
6504 C->set_last_tf(method, tf); // fill cache
6505 return tf;
6506 }
6507
6508 //------------------------------meet-------------------------------------------
6509 // Compute the MEET of two types. It returns a new Type object.
6510 const Type *TypeFunc::xmeet( const Type *t ) const {
6511 // Perform a fast test for common case; meeting the same types together.
6512 if( this == t ) return this; // Meeting same type-rep?
6513
6514 // Current "this->_base" is Func
6515 switch (t->base()) { // switch on original type
6516
6517 case Bottom: // Ye Olde Default
6518 return t;
6519
6520 default: // All else is a mistake
6521 typerr(t);
6522
6523 case Top:
6524 break;
6525 }
6526 return this; // Return the double constant
6527 }
6528
6529 //------------------------------xdual------------------------------------------
6530 // Dual: compute field-by-field dual
6531 const Type *TypeFunc::xdual() const {
6532 return this;
6533 }
6534
6535 //------------------------------eq---------------------------------------------
6536 // Structural equality check for Type representations
6537 bool TypeFunc::eq( const Type *t ) const {
6538 const TypeFunc *a = (const TypeFunc*)t;
6539 return _domain == a->_domain &&
6540 _range == a->_range;
6541 }
6542
6543 //------------------------------hash-------------------------------------------
6544 // Type-specific hashing function.
6545 uint TypeFunc::hash(void) const {
6546 return (uint)(uintptr_t)_domain + (uint)(uintptr_t)_range;
6547 }
6548
6549 //------------------------------dump2------------------------------------------
6550 // Dump Function Type
6551 #ifndef PRODUCT
6552 void TypeFunc::dump2( Dict &d, uint depth, outputStream *st ) const {
6553 if( _range->cnt() <= Parms )
6554 st->print("void");
6555 else {
6556 uint i;
6557 for (i = Parms; i < _range->cnt()-1; i++) {
6558 _range->field_at(i)->dump2(d,depth,st);
6559 st->print("/");
6560 }
6561 _range->field_at(i)->dump2(d,depth,st);
6562 }
6563 st->print(" ");
6564 st->print("( ");
6565 if( !depth || d[this] ) { // Check for recursive dump
6566 st->print("...)");
6567 return;
6568 }
6569 d.Insert((void*)this,(void*)this); // Stop recursion
6570 if (Parms < _domain->cnt())
6571 _domain->field_at(Parms)->dump2(d,depth-1,st);
6572 for (uint i = Parms+1; i < _domain->cnt(); i++) {
6573 st->print(", ");
6574 _domain->field_at(i)->dump2(d,depth-1,st);
6575 }
6576 st->print(" )");
6577 }
6578 #endif
6579
6580 //------------------------------singleton--------------------------------------
6581 // TRUE if Type is a singleton type, FALSE otherwise. Singletons are simple
6582 // constants (Ldi nodes). Singletons are integer, float or double constants
6583 // or a single symbol.
6584 bool TypeFunc::singleton(void) const {
6585 return false; // Never a singleton
6586 }
6587
6588 bool TypeFunc::empty(void) const {
6589 return false; // Never empty
6590 }
6591
6592
6593 BasicType TypeFunc::return_type() const{
6594 if (range()->cnt() == TypeFunc::Parms) {
6595 return T_VOID;
6596 }
6597 return range()->field_at(TypeFunc::Parms)->basic_type();
6598 }