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