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