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 8350865 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 Type* TypeInt::make_or_top(const TypeIntPrototype<jint, juint>& t, int widen) {
1921 return make_or_top(t, widen, false);
1922 }
1923
1924 bool TypeInt::contains(jint i) const {
1925 assert(!_is_dual, "dual types should only be used for join calculation");
1926 juint u = i;
1927 return i >= _lo && i <= _hi &&
1928 u >= _ulo && u <= _uhi &&
1929 _bits.is_satisfied_by(u);
1930 }
1931
1932 bool TypeInt::contains(const TypeInt* t) const {
1933 assert(!_is_dual && !t->_is_dual, "dual types should only be used for join calculation");
1934 return TypeIntHelper::int_type_is_subset(this, t);
1935 }
1936
1937 #ifdef ASSERT
1938 bool TypeInt::strictly_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) && !TypeIntHelper::int_type_is_equal(this, t);
1941 }
1942 #endif // ASSERT
1943
1944 const Type* TypeInt::xmeet(const Type* t) const {
1945 return TypeIntHelper::int_type_xmeet(this, t);
1946 }
1947
1948 const Type* TypeInt::xdual() const {
1949 return new TypeInt(TypeIntPrototype<jint, juint>{{_lo, _hi}, {_ulo, _uhi}, _bits},
1950 _widen, !_is_dual);
1951 }
1952
1953 const Type* TypeInt::widen(const Type* old, const Type* limit) const {
1954 assert(!_is_dual, "dual types should only be used for join calculation");
1955 return TypeIntHelper::int_type_widen(this, old->isa_int(), limit->isa_int());
1956 }
1957
1958 const Type* TypeInt::narrow(const Type* old) const {
1959 assert(!_is_dual, "dual types should only be used for join calculation");
1960 if (old == nullptr) {
1961 return this;
1962 }
1963
1964 return TypeIntHelper::int_type_narrow(this, old->isa_int());
1965 }
1966
1967 //-----------------------------filter------------------------------------------
1968 const Type* TypeInt::filter_helper(const Type* kills, bool include_speculative) const {
1969 assert(!_is_dual, "dual types should only be used for join calculation");
1970 const TypeInt* ft = join_helper(kills, include_speculative)->isa_int();
1971 if (ft == nullptr) {
1972 return Type::TOP; // Canonical empty value
1973 }
1974 assert(!ft->_is_dual, "dual types should only be used for join calculation");
1975 if (ft->_widen < this->_widen) {
1976 // Do not allow the value of kill->_widen to affect the outcome.
1977 // The widen bits must be allowed to run freely through the graph.
1978 return (new TypeInt(TypeIntPrototype<jint, juint>{{ft->_lo, ft->_hi}, {ft->_ulo, ft->_uhi}, ft->_bits},
1979 this->_widen, false))->hashcons();
1980 }
1981 return ft;
1982 }
1983
1984 //------------------------------eq---------------------------------------------
1985 // Structural equality check for Type representations
1986 bool TypeInt::eq(const Type* t) const {
1987 const TypeInt* r = t->is_int();
1988 return TypeIntHelper::int_type_is_equal(this, r) && _widen == r->_widen && _is_dual == r->_is_dual;
1989 }
1990
1991 //------------------------------hash-------------------------------------------
1992 // Type-specific hashing function.
1993 uint TypeInt::hash(void) const {
1994 return (uint)_lo + (uint)_hi + (uint)_ulo + (uint)_uhi +
1995 (uint)_bits._zeros + (uint)_bits._ones + (uint)_widen + (uint)_is_dual + (uint)Type::Int;
1996 }
1997
1998 //------------------------------is_finite--------------------------------------
1999 // Has a finite value
2000 bool TypeInt::is_finite() const {
2001 return true;
2002 }
2003
2004 //------------------------------singleton--------------------------------------
2005 // TRUE if Type is a singleton type, FALSE otherwise. Singletons are simple
2006 // constants.
2007 bool TypeInt::singleton(void) const {
2008 return _lo == _hi;
2009 }
2010
2011 bool TypeInt::empty(void) const {
2012 return false;
2013 }
2014
2015 //=============================================================================
2016 // Convenience common pre-built types.
2017 const TypeLong* TypeLong::MAX;
2018 const TypeLong* TypeLong::MIN;
2019 const TypeLong* TypeLong::MINUS_1;// -1
2020 const TypeLong* TypeLong::ZERO; // 0
2021 const TypeLong* TypeLong::ONE; // 1
2022 const TypeLong* TypeLong::NON_ZERO;
2023 const TypeLong* TypeLong::POS; // >=0
2024 const TypeLong* TypeLong::NEG;
2025 const TypeLong* TypeLong::LONG; // 64-bit integers
2026 const TypeLong* TypeLong::INT; // 32-bit subrange
2027 const TypeLong* TypeLong::UINT; // 32-bit unsigned subrange
2028 const TypeLong* TypeLong::TYPE_DOMAIN; // alias for TypeLong::LONG
2029
2030 TypeLong::TypeLong(const TypeIntPrototype<jlong, julong>& t, int widen, bool dual)
2031 : TypeInteger(Long, t.normalize_widen(widen), dual), _lo(t._srange._lo), _hi(t._srange._hi),
2032 _ulo(t._urange._lo), _uhi(t._urange._hi), _bits(t._bits) {
2033 DEBUG_ONLY(t.verify_constraints());
2034 }
2035
2036 const Type* TypeLong::make_or_top(const TypeIntPrototype<jlong, julong>& t, int widen, bool dual) {
2037 auto canonicalized_t = t.canonicalize_constraints();
2038 if (canonicalized_t.empty()) {
2039 return dual ? Type::BOTTOM : Type::TOP;
2040 }
2041 return (new TypeLong(canonicalized_t._data, widen, dual))->hashcons()->is_long();
2042 }
2043
2044 const TypeLong* TypeLong::make(jlong con) {
2045 julong ucon = con;
2046 return (new TypeLong(TypeIntPrototype<jlong, julong>{{con, con}, {ucon, ucon}, {~ucon, ucon}},
2047 WidenMin, false))->hashcons()->is_long();
2048 }
2049
2050 const TypeLong* TypeLong::make(jlong lo, jlong hi, int widen) {
2051 assert(lo <= hi, "must be legal bounds");
2052 return make_or_top(TypeIntPrototype<jlong, julong>{{lo, hi}, {0, max_julong}, {0, 0}}, widen)->is_long();
2053 }
2054
2055 const Type* TypeLong::make_or_top(const TypeIntPrototype<jlong, julong>& t, int widen) {
2056 return make_or_top(t, widen, false);
2057 }
2058
2059 bool TypeLong::contains(jlong i) const {
2060 assert(!_is_dual, "dual types should only be used for join calculation");
2061 julong u = i;
2062 return i >= _lo && i <= _hi &&
2063 u >= _ulo && u <= _uhi &&
2064 _bits.is_satisfied_by(u);
2065 }
2066
2067 bool TypeLong::contains(const TypeLong* t) const {
2068 assert(!_is_dual && !t->_is_dual, "dual types should only be used for join calculation");
2069 return TypeIntHelper::int_type_is_subset(this, t);
2070 }
2071
2072 #ifdef ASSERT
2073 bool TypeLong::strictly_contains(const TypeLong* t) const {
2074 assert(!_is_dual && !t->_is_dual, "dual types should only be used for join calculation");
2075 return TypeIntHelper::int_type_is_subset(this, t) && !TypeIntHelper::int_type_is_equal(this, t);
2076 }
2077 #endif // ASSERT
2078
2079 const Type* TypeLong::xmeet(const Type* t) const {
2080 return TypeIntHelper::int_type_xmeet(this, t);
2081 }
2082
2083 const Type* TypeLong::xdual() const {
2084 return new TypeLong(TypeIntPrototype<jlong, julong>{{_lo, _hi}, {_ulo, _uhi}, _bits},
2085 _widen, !_is_dual);
2086 }
2087
2088 const Type* TypeLong::widen(const Type* old, const Type* limit) const {
2089 assert(!_is_dual, "dual types should only be used for join calculation");
2090 return TypeIntHelper::int_type_widen(this, old->isa_long(), limit->isa_long());
2091 }
2092
2093 const Type* TypeLong::narrow(const Type* old) const {
2094 assert(!_is_dual, "dual types should only be used for join calculation");
2095 if (old == nullptr) {
2096 return this;
2097 }
2098
2099 return TypeIntHelper::int_type_narrow(this, old->isa_long());
2100 }
2101
2102 //-----------------------------filter------------------------------------------
2103 const Type* TypeLong::filter_helper(const Type* kills, bool include_speculative) const {
2104 assert(!_is_dual, "dual types should only be used for join calculation");
2105 const TypeLong* ft = join_helper(kills, include_speculative)->isa_long();
2106 if (ft == nullptr) {
2107 return Type::TOP; // Canonical empty value
2108 }
2109 assert(!ft->_is_dual, "dual types should only be used for join calculation");
2110 if (ft->_widen < this->_widen) {
2111 // Do not allow the value of kill->_widen to affect the outcome.
2112 // The widen bits must be allowed to run freely through the graph.
2113 return (new TypeLong(TypeIntPrototype<jlong, julong>{{ft->_lo, ft->_hi}, {ft->_ulo, ft->_uhi}, ft->_bits},
2114 this->_widen, false))->hashcons();
2115 }
2116 return ft;
2117 }
2118
2119 //------------------------------eq---------------------------------------------
2120 // Structural equality check for Type representations
2121 bool TypeLong::eq(const Type* t) const {
2122 const TypeLong* r = t->is_long();
2123 return TypeIntHelper::int_type_is_equal(this, r) && _widen == r->_widen && _is_dual == r->_is_dual;
2124 }
2125
2126 //------------------------------hash-------------------------------------------
2127 // Type-specific hashing function.
2128 uint TypeLong::hash(void) const {
2129 return (uint)_lo + (uint)_hi + (uint)_ulo + (uint)_uhi +
2130 (uint)_bits._zeros + (uint)_bits._ones + (uint)_widen + (uint)_is_dual + (uint)Type::Long;
2131 }
2132
2133 //------------------------------is_finite--------------------------------------
2134 // Has a finite value
2135 bool TypeLong::is_finite() const {
2136 return true;
2137 }
2138
2139 //------------------------------singleton--------------------------------------
2140 // TRUE if Type is a singleton type, FALSE otherwise. Singletons are simple
2141 // constants
2142 bool TypeLong::singleton(void) const {
2143 return _lo == _hi;
2144 }
2145
2146 bool TypeLong::empty(void) const {
2147 return false;
2148 }
2149
2150 //------------------------------dump2------------------------------------------
2151 #ifndef PRODUCT
2152 void TypeInt::dump2(Dict& d, uint depth, outputStream* st) const {
2153 TypeIntHelper::int_type_dump(this, st, false);
2154 }
2155
2156 void TypeInt::dump_verbose() const {
2157 TypeIntHelper::int_type_dump(this, tty, true);
2158 }
2159
2160 void TypeLong::dump2(Dict& d, uint depth, outputStream* st) const {
2161 TypeIntHelper::int_type_dump(this, st, false);
2162 }
2163
2164 void TypeLong::dump_verbose() const {
2165 TypeIntHelper::int_type_dump(this, tty, true);
2166 }
2167 #endif
2168
2169 //=============================================================================
2170 // Convenience common pre-built types.
2171 const TypeTuple *TypeTuple::IFBOTH; // Return both arms of IF as reachable
2172 const TypeTuple *TypeTuple::IFFALSE;
2173 const TypeTuple *TypeTuple::IFTRUE;
2174 const TypeTuple *TypeTuple::IFNEITHER;
2175 const TypeTuple *TypeTuple::LOOPBODY;
2176 const TypeTuple *TypeTuple::MEMBAR;
2177 const TypeTuple *TypeTuple::STORECONDITIONAL;
2178 const TypeTuple *TypeTuple::START_I2C;
2179 const TypeTuple *TypeTuple::INT_PAIR;
2180 const TypeTuple *TypeTuple::LONG_PAIR;
2181 const TypeTuple *TypeTuple::INT_CC_PAIR;
2182 const TypeTuple *TypeTuple::LONG_CC_PAIR;
2183
2184 static void collect_inline_fields(ciInlineKlass* vk, const Type** field_array, uint& pos) {
2185 for (int i = 0; i < vk->nof_declared_nonstatic_fields(); i++) {
2186 ciField* field = vk->declared_nonstatic_field_at(i);
2187 if (field->is_flat()) {
2188 collect_inline_fields(field->type()->as_inline_klass(), field_array, pos);
2189 if (!field->is_null_free()) {
2190 // Use T_INT instead of T_BOOLEAN here because the upper bits can contain garbage if the holder
2191 // is null and C2 will only zero them for T_INT assuming that T_BOOLEAN is already canonicalized.
2192 field_array[pos++] = Type::get_const_basic_type(T_INT);
2193 }
2194 } else {
2195 BasicType bt = field->type()->basic_type();
2196 const Type* ft = Type::get_const_type(field->type());
2197 field_array[pos++] = ft;
2198 if (type2size[bt] == 2) {
2199 field_array[pos++] = Type::HALF;
2200 }
2201 }
2202 }
2203 }
2204
2205 //------------------------------make-------------------------------------------
2206 // Make a TypeTuple from the range of a method signature
2207 const TypeTuple* TypeTuple::make_range(ciSignature* sig, InterfaceHandling interface_handling, bool ret_vt_fields, bool is_call) {
2208 ciType* return_type = sig->return_type();
2209 uint arg_cnt = return_type->size();
2210 if (ret_vt_fields) {
2211 arg_cnt = return_type->as_inline_klass()->inline_arg_slots() + 1;
2212 if (is_call) {
2213 // InlineTypeNode::NullMarker field returned by scalarized calls
2214 arg_cnt++;
2215 }
2216 }
2217 const Type **field_array = fields(arg_cnt);
2218 switch (return_type->basic_type()) {
2219 case T_LONG:
2220 field_array[TypeFunc::Parms] = TypeLong::LONG;
2221 field_array[TypeFunc::Parms+1] = Type::HALF;
2222 break;
2223 case T_DOUBLE:
2224 field_array[TypeFunc::Parms] = Type::DOUBLE;
2225 field_array[TypeFunc::Parms+1] = Type::HALF;
2226 break;
2227 case T_OBJECT:
2228 if (ret_vt_fields) {
2229 uint pos = TypeFunc::Parms;
2230 field_array[pos++] = get_const_type(return_type); // Oop might be null when returning as fields
2231 collect_inline_fields(return_type->as_inline_klass(), field_array, pos);
2232 if (is_call) {
2233 // InlineTypeNode::NullMarker field returned by scalarized calls
2234 field_array[pos++] = get_const_basic_type(T_BOOLEAN);
2235 }
2236 assert(pos == (TypeFunc::Parms + arg_cnt), "out of bounds");
2237 break;
2238 } else {
2239 field_array[TypeFunc::Parms] = get_const_type(return_type, interface_handling)->join_speculative(TypePtr::BOTTOM);
2240 }
2241 break;
2242 case T_ARRAY:
2243 case T_BOOLEAN:
2244 case T_CHAR:
2245 case T_FLOAT:
2246 case T_BYTE:
2247 case T_SHORT:
2248 case T_INT:
2249 field_array[TypeFunc::Parms] = get_const_type(return_type, interface_handling);
2250 break;
2251 case T_VOID:
2252 break;
2253 default:
2254 ShouldNotReachHere();
2255 }
2256 return (TypeTuple*)(new TypeTuple(TypeFunc::Parms + arg_cnt, field_array))->hashcons();
2257 }
2258
2259 // Make a TypeTuple from the domain of a method signature
2260 const TypeTuple *TypeTuple::make_domain(ciMethod* method, InterfaceHandling interface_handling, bool vt_fields_as_args) {
2261 ciSignature* sig = method->signature();
2262 uint arg_cnt = sig->size() + (method->is_static() ? 0 : 1);
2263 if (vt_fields_as_args) {
2264 arg_cnt = 0;
2265 assert(method->get_sig_cc() != nullptr, "Should have scalarized signature");
2266 for (ExtendedSignature sig_cc = ExtendedSignature(method->get_sig_cc(), SigEntryFilter()); !sig_cc.at_end(); ++sig_cc) {
2267 arg_cnt += type2size[(*sig_cc)._bt];
2268 }
2269 }
2270
2271 uint pos = TypeFunc::Parms;
2272 const Type** field_array = fields(arg_cnt);
2273 if (!method->is_static()) {
2274 ciInstanceKlass* recv = method->holder();
2275 if (vt_fields_as_args && recv->is_inlinetype() && recv->as_inline_klass()->can_be_passed_as_fields() && method->is_scalarized_arg(0)) {
2276 field_array[pos++] = get_const_type(recv, interface_handling); // buffer argument
2277 collect_inline_fields(recv->as_inline_klass(), field_array, pos);
2278 } else {
2279 field_array[pos++] = get_const_type(recv, interface_handling)->join_speculative(TypePtr::NOTNULL);
2280 }
2281 }
2282
2283 int i = 0;
2284 while (pos < TypeFunc::Parms + arg_cnt) {
2285 ciType* type = sig->type_at(i);
2286 BasicType bt = type->basic_type();
2287
2288 switch (bt) {
2289 case T_LONG:
2290 field_array[pos++] = TypeLong::LONG;
2291 field_array[pos++] = Type::HALF;
2292 break;
2293 case T_DOUBLE:
2294 field_array[pos++] = Type::DOUBLE;
2295 field_array[pos++] = Type::HALF;
2296 break;
2297 case T_OBJECT:
2298 if (type->is_inlinetype() && vt_fields_as_args && method->is_scalarized_arg(i + (method->is_static() ? 0 : 1))) {
2299 field_array[pos++] = get_const_type(type, interface_handling); // buffer argument
2300 // InlineTypeNode::NullMarker field used for null checking
2301 field_array[pos++] = get_const_basic_type(T_BOOLEAN);
2302 collect_inline_fields(type->as_inline_klass(), field_array, pos);
2303 } else {
2304 field_array[pos++] = get_const_type(type, interface_handling);
2305 }
2306 break;
2307 case T_ARRAY:
2308 case T_FLOAT:
2309 case T_INT:
2310 field_array[pos++] = get_const_type(type, interface_handling);
2311 break;
2312 case T_BOOLEAN:
2313 case T_CHAR:
2314 case T_BYTE:
2315 case T_SHORT:
2316 field_array[pos++] = TypeInt::INT;
2317 break;
2318 default:
2319 ShouldNotReachHere();
2320 }
2321 i++;
2322 }
2323 assert(pos == TypeFunc::Parms + arg_cnt, "wrong number of arguments");
2324
2325 return (TypeTuple*)(new TypeTuple(TypeFunc::Parms + arg_cnt, field_array))->hashcons();
2326 }
2327
2328 const TypeTuple *TypeTuple::make( uint cnt, const Type **fields ) {
2329 return (TypeTuple*)(new TypeTuple(cnt,fields))->hashcons();
2330 }
2331
2332 //------------------------------fields-----------------------------------------
2333 // Subroutine call type with space allocated for argument types
2334 // Memory for Control, I_O, Memory, FramePtr, and ReturnAdr is allocated implicitly
2335 const Type **TypeTuple::fields( uint arg_cnt ) {
2336 const Type **flds = (const Type **)(Compile::current()->type_arena()->AmallocWords((TypeFunc::Parms+arg_cnt)*sizeof(Type*) ));
2337 flds[TypeFunc::Control ] = Type::CONTROL;
2338 flds[TypeFunc::I_O ] = Type::ABIO;
2339 flds[TypeFunc::Memory ] = Type::MEMORY;
2340 flds[TypeFunc::FramePtr ] = TypeRawPtr::BOTTOM;
2341 flds[TypeFunc::ReturnAdr] = Type::RETURN_ADDRESS;
2342
2343 return flds;
2344 }
2345
2346 //------------------------------meet-------------------------------------------
2347 // Compute the MEET of two types. It returns a new Type object.
2348 const Type *TypeTuple::xmeet( const Type *t ) const {
2349 // Perform a fast test for common case; meeting the same types together.
2350 if( this == t ) return this; // Meeting same type-rep?
2351
2352 // Current "this->_base" is Tuple
2353 switch (t->base()) { // switch on original type
2354
2355 case Bottom: // Ye Olde Default
2356 return t;
2357
2358 default: // All else is a mistake
2359 typerr(t);
2360
2361 case Tuple: { // Meeting 2 signatures?
2362 const TypeTuple *x = t->is_tuple();
2363 assert( _cnt == x->_cnt, "" );
2364 const Type **fields = (const Type **)(Compile::current()->type_arena()->AmallocWords( _cnt*sizeof(Type*) ));
2365 for( uint i=0; i<_cnt; i++ )
2366 fields[i] = field_at(i)->xmeet( x->field_at(i) );
2367 return TypeTuple::make(_cnt,fields);
2368 }
2369 case Top:
2370 break;
2371 }
2372 return this; // Return the double constant
2373 }
2374
2375 //------------------------------xdual------------------------------------------
2376 // Dual: compute field-by-field dual
2377 const Type *TypeTuple::xdual() const {
2378 const Type **fields = (const Type **)(Compile::current()->type_arena()->AmallocWords( _cnt*sizeof(Type*) ));
2379 for( uint i=0; i<_cnt; i++ )
2380 fields[i] = _fields[i]->dual();
2381 return new TypeTuple(_cnt,fields);
2382 }
2383
2384 //------------------------------eq---------------------------------------------
2385 // Structural equality check for Type representations
2386 bool TypeTuple::eq( const Type *t ) const {
2387 const TypeTuple *s = (const TypeTuple *)t;
2388 if (_cnt != s->_cnt) return false; // Unequal field counts
2389 for (uint i = 0; i < _cnt; i++)
2390 if (field_at(i) != s->field_at(i)) // POINTER COMPARE! NO RECURSION!
2391 return false; // Missed
2392 return true;
2393 }
2394
2395 //------------------------------hash-------------------------------------------
2396 // Type-specific hashing function.
2397 uint TypeTuple::hash(void) const {
2398 uintptr_t sum = _cnt;
2399 for( uint i=0; i<_cnt; i++ )
2400 sum += (uintptr_t)_fields[i]; // Hash on pointers directly
2401 return (uint)sum;
2402 }
2403
2404 //------------------------------dump2------------------------------------------
2405 // Dump signature Type
2406 #ifndef PRODUCT
2407 void TypeTuple::dump2( Dict &d, uint depth, outputStream *st ) const {
2408 st->print("{");
2409 if( !depth || d[this] ) { // Check for recursive print
2410 st->print("...}");
2411 return;
2412 }
2413 d.Insert((void*)this, (void*)this); // Stop recursion
2414 if( _cnt ) {
2415 uint i;
2416 for( i=0; i<_cnt-1; i++ ) {
2417 st->print("%d:", i);
2418 _fields[i]->dump2(d, depth-1, st);
2419 st->print(", ");
2420 }
2421 st->print("%d:", i);
2422 _fields[i]->dump2(d, depth-1, st);
2423 }
2424 st->print("}");
2425 }
2426 #endif
2427
2428 //------------------------------singleton--------------------------------------
2429 // TRUE if Type is a singleton type, FALSE otherwise. Singletons are simple
2430 // constants (Ldi nodes). Singletons are integer, float or double constants
2431 // or a single symbol.
2432 bool TypeTuple::singleton(void) const {
2433 return false; // Never a singleton
2434 }
2435
2436 bool TypeTuple::empty(void) const {
2437 for( uint i=0; i<_cnt; i++ ) {
2438 if (_fields[i]->empty()) return true;
2439 }
2440 return false;
2441 }
2442
2443 //=============================================================================
2444 // Convenience common pre-built types.
2445
2446 inline const TypeInt* normalize_array_size(const TypeInt* size) {
2447 // Certain normalizations keep us sane when comparing types.
2448 // We do not want arrayOop variables to differ only by the wideness
2449 // of their index types. Pick minimum wideness, since that is the
2450 // forced wideness of small ranges anyway.
2451 if (size->_widen != Type::WidenMin)
2452 return TypeInt::make(size->_lo, size->_hi, Type::WidenMin);
2453 else
2454 return size;
2455 }
2456
2457 //------------------------------make-------------------------------------------
2458 const TypeAry* TypeAry::make(const Type* elem, const TypeInt* size, bool stable,
2459 bool flat, bool not_flat, bool not_null_free, bool atomic) {
2460 if (UseCompressedOops && elem->isa_oopptr()) {
2461 elem = elem->make_narrowoop();
2462 }
2463 size = normalize_array_size(size);
2464 return (TypeAry*)(new TypeAry(elem, size, stable, flat, not_flat, not_null_free, atomic))->hashcons();
2465 }
2466
2467 //------------------------------meet-------------------------------------------
2468 // Compute the MEET of two types. It returns a new Type object.
2469 const Type *TypeAry::xmeet( const Type *t ) const {
2470 // Perform a fast test for common case; meeting the same types together.
2471 if( this == t ) return this; // Meeting same type-rep?
2472
2473 // Current "this->_base" is Ary
2474 switch (t->base()) { // switch on original type
2475
2476 case Bottom: // Ye Olde Default
2477 return t;
2478
2479 default: // All else is a mistake
2480 typerr(t);
2481
2482 case Array: { // Meeting 2 arrays?
2483 const TypeAry* a = t->is_ary();
2484 const Type* size = _size->xmeet(a->_size);
2485 const TypeInt* isize = size->isa_int();
2486 if (isize == nullptr) {
2487 assert(size == Type::TOP || size == Type::BOTTOM, "");
2488 return size;
2489 }
2490 return TypeAry::make(_elem->meet_speculative(a->_elem),
2491 isize, _stable && a->_stable,
2492 _flat && a->_flat,
2493 _not_flat && a->_not_flat,
2494 _not_null_free && a->_not_null_free,
2495 _atomic && a->_atomic);
2496 }
2497 case Top:
2498 break;
2499 }
2500 return this; // Return the double constant
2501 }
2502
2503 //------------------------------xdual------------------------------------------
2504 // Dual: compute field-by-field dual
2505 const Type *TypeAry::xdual() const {
2506 const TypeInt* size_dual = _size->dual()->is_int();
2507 size_dual = normalize_array_size(size_dual);
2508 return new TypeAry(_elem->dual(), size_dual, !_stable, !_flat, !_not_flat, !_not_null_free, !_atomic);
2509 }
2510
2511 //------------------------------eq---------------------------------------------
2512 // Structural equality check for Type representations
2513 bool TypeAry::eq( const Type *t ) const {
2514 const TypeAry *a = (const TypeAry*)t;
2515 return _elem == a->_elem &&
2516 _stable == a->_stable &&
2517 _size == a->_size &&
2518 _flat == a->_flat &&
2519 _not_flat == a->_not_flat &&
2520 _not_null_free == a->_not_null_free &&
2521 _atomic == a->_atomic;
2522
2523 }
2524
2525 //------------------------------hash-------------------------------------------
2526 // Type-specific hashing function.
2527 uint TypeAry::hash(void) const {
2528 return (uint)(uintptr_t)_elem + (uint)(uintptr_t)_size + (uint)(_stable ? 43 : 0) +
2529 (uint)(_flat ? 44 : 0) + (uint)(_not_flat ? 45 : 0) + (uint)(_not_null_free ? 46 : 0) + (uint)(_atomic ? 47 : 0);
2530 }
2531
2532 /**
2533 * Return same type without a speculative part in the element
2534 */
2535 const TypeAry* TypeAry::remove_speculative() const {
2536 return make(_elem->remove_speculative(), _size, _stable, _flat, _not_flat, _not_null_free, _atomic);
2537 }
2538
2539 /**
2540 * Return same type with cleaned up speculative part of element
2541 */
2542 const Type* TypeAry::cleanup_speculative() const {
2543 return make(_elem->cleanup_speculative(), _size, _stable, _flat, _not_flat, _not_null_free, _atomic);
2544 }
2545
2546 /**
2547 * Return same type but with a different inline depth (used for speculation)
2548 *
2549 * @param depth depth to meet with
2550 */
2551 const TypePtr* TypePtr::with_inline_depth(int depth) const {
2552 if (!UseInlineDepthForSpeculativeTypes) {
2553 return this;
2554 }
2555 return make(AnyPtr, _ptr, _offset, _speculative, depth, _reloc);
2556 }
2557
2558 //------------------------------dump2------------------------------------------
2559 #ifndef PRODUCT
2560 void TypeAry::dump2( Dict &d, uint depth, outputStream *st ) const {
2561 if (_stable) st->print("stable:");
2562 if (_flat) st->print("flat:");
2563 if (Verbose) {
2564 if (_not_flat) st->print("not flat:");
2565 if (_not_null_free) st->print("not null free:");
2566 }
2567 if (_atomic) st->print("atomic:");
2568 _elem->dump2(d, depth, st);
2569 st->print("[");
2570 _size->dump2(d, depth, st);
2571 st->print("]");
2572 }
2573 #endif
2574
2575 //------------------------------singleton--------------------------------------
2576 // TRUE if Type is a singleton type, FALSE otherwise. Singletons are simple
2577 // constants (Ldi nodes). Singletons are integer, float or double constants
2578 // or a single symbol.
2579 bool TypeAry::singleton(void) const {
2580 return false; // Never a singleton
2581 }
2582
2583 bool TypeAry::empty(void) const {
2584 assert(!_size->empty(), "TypeInt is never empty");
2585 // TODO 8385426 This should be simplified at construction time once we get rid of dual
2586 // Doing it with the dual-based join is annoying. TypeAry::empty tests whether the
2587 // element type is empty. When computing the dual of an array that can be flat or not,
2588 // we will get an element type that is empty, and doesn't need more. We even shouldn't
2589 // do more otherwise, we can't make the dual involutive. But if we compute the
2590 // intersection of a flat and a non-flat array, we could change the element type to an
2591 // empty type to reduce the abstract value. And we must be careful not to do that in
2592 // the dual world.
2593 return _elem->empty() || (_flat && _not_flat);
2594 }
2595
2596 //--------------------------ary_must_be_exact----------------------------------
2597 bool TypeAry::ary_must_be_exact() const {
2598 // This logic looks at the element type of an array, and returns true
2599 // if the element type is either a primitive or a final instance class.
2600 // In such cases, an array built on this ary must have no subclasses.
2601 if (_elem == BOTTOM) return false; // general array not exact
2602 if (_elem == TOP ) return false; // inverted general array not exact
2603 const TypeOopPtr* toop = nullptr;
2604 if (UseCompressedOops && _elem->isa_narrowoop()) {
2605 toop = _elem->make_ptr()->isa_oopptr();
2606 } else {
2607 toop = _elem->isa_oopptr();
2608 }
2609 if (!toop) return true; // a primitive type, like int
2610 if (!toop->is_loaded()) return false; // unloaded class
2611 const TypeInstPtr* tinst;
2612 if (_elem->isa_narrowoop())
2613 tinst = _elem->make_ptr()->isa_instptr();
2614 else
2615 tinst = _elem->isa_instptr();
2616 if (tinst) {
2617 if (tinst->instance_klass()->is_final()) {
2618 // Even though MyValue is final, [LMyValue is only exact if the array
2619 // is (not) null-free due to null-free [LMyValue <: null-able [LMyValue.
2620 // TODO 8350865 If we know that the array can't be null-free, it's allowed to be exact, right?
2621 // If so, we should add '&& !_not_null_free'
2622 if (tinst->is_inlinetypeptr() && (tinst->ptr() != TypePtr::NotNull)) {
2623 return false;
2624 }
2625 return true;
2626 }
2627 return false;
2628 }
2629 const TypeAryPtr* tap;
2630 if (_elem->isa_narrowoop())
2631 tap = _elem->make_ptr()->isa_aryptr();
2632 else
2633 tap = _elem->isa_aryptr();
2634 if (tap)
2635 return tap->ary()->ary_must_be_exact();
2636 return false;
2637 }
2638
2639 //==============================TypeVect=======================================
2640 // Convenience common pre-built types.
2641 const TypeVect* TypeVect::VECTA = nullptr; // vector length agnostic
2642 const TypeVect* TypeVect::VECTS = nullptr; // 32-bit vectors
2643 const TypeVect* TypeVect::VECTD = nullptr; // 64-bit vectors
2644 const TypeVect* TypeVect::VECTX = nullptr; // 128-bit vectors
2645 const TypeVect* TypeVect::VECTY = nullptr; // 256-bit vectors
2646 const TypeVect* TypeVect::VECTZ = nullptr; // 512-bit vectors
2647 const TypeVect* TypeVect::VECTMASK = nullptr; // predicate/mask vector
2648
2649 //------------------------------make-------------------------------------------
2650 const TypeVect* TypeVect::make(BasicType elem_bt, uint length, bool is_mask) {
2651 if (is_mask) {
2652 return makemask(elem_bt, length);
2653 }
2654 assert(is_java_primitive(elem_bt), "only primitive types in vector");
2655 assert(Matcher::vector_size_supported(elem_bt, length), "length in range");
2656 int size = length * type2aelembytes(elem_bt);
2657 switch (Matcher::vector_ideal_reg(size)) {
2658 case Op_VecA:
2659 return (TypeVect*)(new TypeVectA(elem_bt, length))->hashcons();
2660 case Op_VecS:
2661 return (TypeVect*)(new TypeVectS(elem_bt, length))->hashcons();
2662 case Op_RegL:
2663 case Op_VecD:
2664 case Op_RegD:
2665 return (TypeVect*)(new TypeVectD(elem_bt, length))->hashcons();
2666 case Op_VecX:
2667 return (TypeVect*)(new TypeVectX(elem_bt, length))->hashcons();
2668 case Op_VecY:
2669 return (TypeVect*)(new TypeVectY(elem_bt, length))->hashcons();
2670 case Op_VecZ:
2671 return (TypeVect*)(new TypeVectZ(elem_bt, length))->hashcons();
2672 }
2673 ShouldNotReachHere();
2674 return nullptr;
2675 }
2676
2677 // Create a vector mask type with the given element basic type and length.
2678 // - Returns "TypePVectMask" (PVectMask) for platforms that support the predicate
2679 // feature and it is implemented properly in the backend, allowing the mask to
2680 // be stored in a predicate/mask register.
2681 // - Returns a normal vector type "TypeVectA ~ TypeVectZ" (NVectMask) otherwise,
2682 // where the vector mask is stored in a vector register.
2683 const TypeVect* TypeVect::makemask(BasicType elem_bt, uint length) {
2684 if (Matcher::has_predicated_vectors() &&
2685 Matcher::match_rule_supported_vector_masked(Op_VectorLoadMask, length, elem_bt)) {
2686 return TypePVectMask::make(elem_bt, length);
2687 } else {
2688 return make(elem_bt, length);
2689 }
2690 }
2691
2692 //------------------------------meet-------------------------------------------
2693 // Compute the MEET of two types. Since each TypeVect is the only instance of
2694 // its species, meeting often returns itself
2695 const Type* TypeVect::xmeet(const Type* t) const {
2696 // Perform a fast test for common case; meeting the same types together.
2697 if (this == t) {
2698 return this;
2699 }
2700
2701 // Current "this->_base" is Vector
2702 switch (t->base()) { // switch on original type
2703
2704 case Bottom: // Ye Olde Default
2705 return t;
2706
2707 default: // All else is a mistake
2708 typerr(t);
2709 case VectorMask:
2710 case VectorA:
2711 case VectorS:
2712 case VectorD:
2713 case VectorX:
2714 case VectorY:
2715 case VectorZ: { // Meeting 2 vectors?
2716 const TypeVect* v = t->is_vect();
2717 assert(base() == v->base(), "");
2718 assert(length() == v->length(), "");
2719 assert(element_basic_type() == v->element_basic_type(), "");
2720 return this;
2721 }
2722 case Top:
2723 break;
2724 }
2725 return this;
2726 }
2727
2728 //------------------------------xdual------------------------------------------
2729 // Since each TypeVect is the only instance of its species, it is self-dual
2730 const Type* TypeVect::xdual() const {
2731 return this;
2732 }
2733
2734 //------------------------------eq---------------------------------------------
2735 // Structural equality check for Type representations
2736 bool TypeVect::eq(const Type* t) const {
2737 const TypeVect* v = t->is_vect();
2738 return (element_basic_type() == v->element_basic_type()) && (length() == v->length());
2739 }
2740
2741 //------------------------------hash-------------------------------------------
2742 // Type-specific hashing function.
2743 uint TypeVect::hash(void) const {
2744 return (uint)base() + (uint)(uintptr_t)_elem_bt + (uint)(uintptr_t)_length;
2745 }
2746
2747 //------------------------------singleton--------------------------------------
2748 // TRUE if Type is a singleton type, FALSE otherwise. Singletons are simple
2749 // constants (Ldi nodes). Vector is singleton if all elements are the same
2750 // constant value (when vector is created with Replicate code).
2751 bool TypeVect::singleton(void) const {
2752 // There is no Con node for vectors yet.
2753 // return _elem->singleton();
2754 return false;
2755 }
2756
2757 bool TypeVect::empty(void) const {
2758 return false;
2759 }
2760
2761 //------------------------------dump2------------------------------------------
2762 #ifndef PRODUCT
2763 void TypeVect::dump2(Dict& d, uint depth, outputStream* st) const {
2764 switch (base()) {
2765 case VectorA:
2766 st->print("vectora"); break;
2767 case VectorS:
2768 st->print("vectors"); break;
2769 case VectorD:
2770 st->print("vectord"); break;
2771 case VectorX:
2772 st->print("vectorx"); break;
2773 case VectorY:
2774 st->print("vectory"); break;
2775 case VectorZ:
2776 st->print("vectorz"); break;
2777 case VectorMask:
2778 st->print("vectormask"); break;
2779 default:
2780 ShouldNotReachHere();
2781 }
2782 st->print("<%c,%u>", type2char(element_basic_type()), length());
2783 }
2784 #endif
2785
2786 const TypePVectMask* TypePVectMask::make(const BasicType elem_bt, uint length) {
2787 return (TypePVectMask*) (new TypePVectMask(elem_bt, length))->hashcons();
2788 }
2789
2790 //=============================================================================
2791 // Convenience common pre-built types.
2792 const TypePtr *TypePtr::NULL_PTR;
2793 const TypePtr *TypePtr::NOTNULL;
2794 const TypePtr *TypePtr::BOTTOM;
2795
2796 //------------------------------meet-------------------------------------------
2797 // Meet over the PTR enum
2798 const TypePtr::PTR TypePtr::ptr_meet[TypePtr::lastPTR][TypePtr::lastPTR] = {
2799 // TopPTR, AnyNull, Constant, Null, NotNull, BotPTR,
2800 { /* Top */ TopPTR, AnyNull, Constant, Null, NotNull, BotPTR,},
2801 { /* AnyNull */ AnyNull, AnyNull, Constant, BotPTR, NotNull, BotPTR,},
2802 { /* Constant*/ Constant, Constant, Constant, BotPTR, NotNull, BotPTR,},
2803 { /* Null */ Null, BotPTR, BotPTR, Null, BotPTR, BotPTR,},
2804 { /* NotNull */ NotNull, NotNull, NotNull, BotPTR, NotNull, BotPTR,},
2805 { /* BotPTR */ BotPTR, BotPTR, BotPTR, BotPTR, BotPTR, BotPTR,}
2806 };
2807
2808 //------------------------------make-------------------------------------------
2809 const TypePtr* TypePtr::make(TYPES t, enum PTR ptr, Offset offset,
2810 const TypePtr* speculative, int inline_depth,
2811 relocInfo::relocType reloc) {
2812 return (TypePtr*)(new TypePtr(t, ptr, offset, reloc, speculative, inline_depth))->hashcons();
2813 }
2814
2815 //------------------------------cast_to_ptr_type-------------------------------
2816 const TypePtr* TypePtr::cast_to_ptr_type(PTR ptr) const {
2817 assert(_base == AnyPtr, "subclass must override cast_to_ptr_type");
2818 if( ptr == _ptr ) return this;
2819 return make(_base, ptr, _offset, _speculative, _inline_depth, _reloc);
2820 }
2821
2822 //------------------------------get_con----------------------------------------
2823 intptr_t TypePtr::get_con() const {
2824 assert( _ptr == Null, "" );
2825 return offset();
2826 }
2827
2828 //------------------------------meet-------------------------------------------
2829 // Compute the MEET of two types. It returns a new Type object.
2830 const Type *TypePtr::xmeet(const Type *t) const {
2831 const Type* res = xmeet_helper(t);
2832 if (res->isa_ptr() == nullptr) {
2833 return res;
2834 }
2835
2836 const TypePtr* res_ptr = res->is_ptr();
2837 if (res_ptr->speculative() != nullptr) {
2838 // type->speculative() is null means that speculation is no better
2839 // than type, i.e. type->speculative() == type. So there are 2
2840 // ways to represent the fact that we have no useful speculative
2841 // data and we should use a single one to be able to test for
2842 // equality between types. Check whether type->speculative() ==
2843 // type and set speculative to null if it is the case.
2844 if (res_ptr->remove_speculative() == res_ptr->speculative()) {
2845 return res_ptr->remove_speculative();
2846 }
2847 }
2848
2849 return res;
2850 }
2851
2852 const Type *TypePtr::xmeet_helper(const Type *t) const {
2853 // Perform a fast test for common case; meeting the same types together.
2854 if( this == t ) return this; // Meeting same type-rep?
2855
2856 // Current "this->_base" is AnyPtr
2857 switch (t->base()) { // switch on original type
2858 case Int: // Mixing ints & oops happens when javac
2859 case Long: // reuses local variables
2860 case HalfFloatTop:
2861 case HalfFloatCon:
2862 case HalfFloatBot:
2863 case FloatTop:
2864 case FloatCon:
2865 case FloatBot:
2866 case DoubleTop:
2867 case DoubleCon:
2868 case DoubleBot:
2869 case NarrowOop:
2870 case NarrowKlass:
2871 case Bottom: // Ye Olde Default
2872 return Type::BOTTOM;
2873 case Top:
2874 return this;
2875
2876 case AnyPtr: { // Meeting to AnyPtrs
2877 const TypePtr *tp = t->is_ptr();
2878 const TypePtr* speculative = xmeet_speculative(tp);
2879 int depth = meet_inline_depth(tp->inline_depth());
2880 return make(AnyPtr, meet_ptr(tp->ptr()), meet_offset(tp->offset()), speculative, depth);
2881 }
2882 case RawPtr: // For these, flip the call around to cut down
2883 case OopPtr:
2884 case InstPtr: // on the cases I have to handle.
2885 case AryPtr:
2886 case MetadataPtr:
2887 case KlassPtr:
2888 case InstKlassPtr:
2889 case AryKlassPtr:
2890 return t->xmeet(this); // Call in reverse direction
2891 default: // All else is a mistake
2892 typerr(t);
2893
2894 }
2895 return this;
2896 }
2897
2898 //------------------------------meet_offset------------------------------------
2899 Type::Offset TypePtr::meet_offset(int offset) const {
2900 return _offset.meet(Offset(offset));
2901 }
2902
2903 //------------------------------dual_offset------------------------------------
2904 Type::Offset TypePtr::dual_offset() const {
2905 return _offset.dual();
2906 }
2907
2908 //------------------------------xdual------------------------------------------
2909 // Dual: compute field-by-field dual
2910 const TypePtr::PTR TypePtr::ptr_dual[TypePtr::lastPTR] = {
2911 BotPTR, NotNull, Constant, Null, AnyNull, TopPTR
2912 };
2913
2914 const TypePtr::FlatInArray TypePtr::flat_in_array_dual[Uninitialized] = {
2915 /* TopFlat -> */ MaybeFlat,
2916 /* Flat -> */ NotFlat,
2917 /* NotFlat -> */ Flat,
2918 /* MaybeFlat -> */ TopFlat
2919 };
2920
2921 const char* const TypePtr::flat_in_array_msg[Uninitialized] = {
2922 "TOP flat in array", "flat in array", "not flat in array", "maybe flat in array"
2923 };
2924
2925 const Type *TypePtr::xdual() const {
2926 return new TypePtr(AnyPtr, dual_ptr(), dual_offset(), relocInfo::none, dual_speculative(), dual_inline_depth());
2927 }
2928
2929 //------------------------------xadd_offset------------------------------------
2930 Type::Offset TypePtr::xadd_offset(intptr_t offset) const {
2931 return _offset.add(offset);
2932 }
2933
2934 //------------------------------add_offset-------------------------------------
2935 const TypePtr *TypePtr::add_offset( intptr_t offset ) const {
2936 return make(AnyPtr, _ptr, xadd_offset(offset), _speculative, _inline_depth, _reloc);
2937 }
2938
2939 const TypePtr *TypePtr::with_offset(intptr_t offset) const {
2940 return make(AnyPtr, _ptr, Offset(offset), _speculative, _inline_depth, _reloc);
2941 }
2942
2943 //------------------------------eq---------------------------------------------
2944 // Structural equality check for Type representations
2945 bool TypePtr::eq( const Type *t ) const {
2946 const TypePtr *a = (const TypePtr*)t;
2947 return _ptr == a->ptr() && offset() == a->offset() && _reloc == a->reloc() &&
2948 eq_speculative(a) && _inline_depth == a->_inline_depth;
2949 }
2950
2951 //------------------------------hash-------------------------------------------
2952 // Type-specific hashing function.
2953 uint TypePtr::hash(void) const {
2954 return (uint)_ptr + (uint)offset() + (uint)_reloc + (uint)hash_speculative() + (uint)_inline_depth;
2955 }
2956
2957 /**
2958 * Return same type without a speculative part
2959 */
2960 const TypePtr* TypePtr::remove_speculative() const {
2961 if (_speculative == nullptr) {
2962 return this;
2963 }
2964 assert(_inline_depth == InlineDepthTop || _inline_depth == InlineDepthBottom, "non speculative type shouldn't have inline depth");
2965 return make(AnyPtr, _ptr, _offset, nullptr, _inline_depth, _reloc);
2966 }
2967
2968 /**
2969 * Return same type but drop speculative part if we know we won't use
2970 * it
2971 */
2972 const Type* TypePtr::cleanup_speculative() const {
2973 if (speculative() == nullptr) {
2974 return this;
2975 }
2976 const Type* no_spec = remove_speculative();
2977 // If this is NULL_PTR then we don't need the speculative type
2978 // (with_inline_depth in case the current type inline depth is
2979 // InlineDepthTop)
2980 if (no_spec == NULL_PTR->with_inline_depth(inline_depth())) {
2981 return no_spec;
2982 }
2983 if (above_centerline(speculative()->ptr())) {
2984 return no_spec;
2985 }
2986 const TypeOopPtr* spec_oopptr = speculative()->isa_oopptr();
2987 // If the speculative may be null and is an inexact klass then it
2988 // doesn't help
2989 if (speculative() != TypePtr::NULL_PTR && speculative()->maybe_null() &&
2990 (spec_oopptr == nullptr || !spec_oopptr->klass_is_exact())) {
2991 return no_spec;
2992 }
2993 return this;
2994 }
2995
2996 /**
2997 * dual of the speculative part of the type
2998 */
2999 const TypePtr* TypePtr::dual_speculative() const {
3000 if (_speculative == nullptr) {
3001 return nullptr;
3002 }
3003 return _speculative->dual()->is_ptr();
3004 }
3005
3006 /**
3007 * meet of the speculative parts of 2 types
3008 *
3009 * @param other type to meet with
3010 */
3011 const TypePtr* TypePtr::xmeet_speculative(const TypePtr* other) const {
3012 bool this_has_spec = (_speculative != nullptr);
3013 bool other_has_spec = (other->speculative() != nullptr);
3014
3015 if (!this_has_spec && !other_has_spec) {
3016 return nullptr;
3017 }
3018
3019 // If we are at a point where control flow meets and one branch has
3020 // a speculative type and the other has not, we meet the speculative
3021 // type of one branch with the actual type of the other. If the
3022 // actual type is exact and the speculative is as well, then the
3023 // result is a speculative type which is exact and we can continue
3024 // speculation further.
3025 const TypePtr* this_spec = _speculative;
3026 const TypePtr* other_spec = other->speculative();
3027
3028 if (!this_has_spec) {
3029 this_spec = this;
3030 }
3031
3032 if (!other_has_spec) {
3033 other_spec = other;
3034 }
3035
3036 return this_spec->meet(other_spec)->is_ptr();
3037 }
3038
3039 /**
3040 * dual of the inline depth for this type (used for speculation)
3041 */
3042 int TypePtr::dual_inline_depth() const {
3043 return -inline_depth();
3044 }
3045
3046 /**
3047 * meet of 2 inline depths (used for speculation)
3048 *
3049 * @param depth depth to meet with
3050 */
3051 int TypePtr::meet_inline_depth(int depth) const {
3052 return MAX2(inline_depth(), depth);
3053 }
3054
3055 /**
3056 * Are the speculative parts of 2 types equal?
3057 *
3058 * @param other type to compare this one to
3059 */
3060 bool TypePtr::eq_speculative(const TypePtr* other) const {
3061 if (_speculative == nullptr || other->speculative() == nullptr) {
3062 return _speculative == other->speculative();
3063 }
3064
3065 if (_speculative->base() != other->speculative()->base()) {
3066 return false;
3067 }
3068
3069 return _speculative->eq(other->speculative());
3070 }
3071
3072 /**
3073 * Hash of the speculative part of the type
3074 */
3075 int TypePtr::hash_speculative() const {
3076 if (_speculative == nullptr) {
3077 return 0;
3078 }
3079
3080 return _speculative->hash();
3081 }
3082
3083 /**
3084 * add offset to the speculative part of the type
3085 *
3086 * @param offset offset to add
3087 */
3088 const TypePtr* TypePtr::add_offset_speculative(intptr_t offset) const {
3089 if (_speculative == nullptr) {
3090 return nullptr;
3091 }
3092 return _speculative->add_offset(offset)->is_ptr();
3093 }
3094
3095 const TypePtr* TypePtr::with_offset_speculative(intptr_t offset) const {
3096 if (_speculative == nullptr) {
3097 return nullptr;
3098 }
3099 return _speculative->with_offset(offset)->is_ptr();
3100 }
3101
3102 /**
3103 * return exact klass from the speculative type if there's one
3104 */
3105 ciKlass* TypePtr::speculative_type() const {
3106 if (_speculative != nullptr && _speculative->isa_oopptr()) {
3107 const TypeOopPtr* speculative = _speculative->join(this)->is_oopptr();
3108 if (speculative->klass_is_exact()) {
3109 return speculative->exact_klass();
3110 }
3111 }
3112 return nullptr;
3113 }
3114
3115 /**
3116 * return true if speculative type may be null
3117 */
3118 bool TypePtr::speculative_maybe_null() const {
3119 if (_speculative != nullptr) {
3120 const TypePtr* speculative = _speculative->join(this)->is_ptr();
3121 return speculative->maybe_null();
3122 }
3123 return true;
3124 }
3125
3126 bool TypePtr::speculative_always_null() const {
3127 if (_speculative != nullptr) {
3128 const TypePtr* speculative = _speculative->join(this)->is_ptr();
3129 return speculative == TypePtr::NULL_PTR;
3130 }
3131 return false;
3132 }
3133
3134 /**
3135 * Same as TypePtr::speculative_type() but return the klass only if
3136 * the speculative tells us is not null
3137 */
3138 ciKlass* TypePtr::speculative_type_not_null() const {
3139 if (speculative_maybe_null()) {
3140 return nullptr;
3141 }
3142 return speculative_type();
3143 }
3144
3145 /**
3146 * Check whether new profiling would improve speculative type
3147 *
3148 * @param exact_kls class from profiling
3149 * @param inline_depth inlining depth of profile point
3150 *
3151 * @return true if type profile is valuable
3152 */
3153 bool TypePtr::would_improve_type(ciKlass* exact_kls, int inline_depth) const {
3154 // no profiling?
3155 if (exact_kls == nullptr) {
3156 return false;
3157 }
3158 if (speculative() == TypePtr::NULL_PTR) {
3159 return false;
3160 }
3161 // no speculative type or non exact speculative type?
3162 if (speculative_type() == nullptr) {
3163 return true;
3164 }
3165 // If the node already has an exact speculative type keep it,
3166 // unless it was provided by profiling that is at a deeper
3167 // inlining level. Profiling at a higher inlining depth is
3168 // expected to be less accurate.
3169 if (_speculative->inline_depth() == InlineDepthBottom) {
3170 return false;
3171 }
3172 assert(_speculative->inline_depth() != InlineDepthTop, "can't do the comparison");
3173 return inline_depth < _speculative->inline_depth();
3174 }
3175
3176 /**
3177 * Check whether new profiling would improve ptr (= tells us it is non
3178 * null)
3179 *
3180 * @param ptr_kind always null or not null?
3181 *
3182 * @return true if ptr profile is valuable
3183 */
3184 bool TypePtr::would_improve_ptr(ProfilePtrKind ptr_kind) const {
3185 // profiling doesn't tell us anything useful
3186 if (ptr_kind != ProfileAlwaysNull && ptr_kind != ProfileNeverNull) {
3187 return false;
3188 }
3189 // We already know this is not null
3190 if (!this->maybe_null()) {
3191 return false;
3192 }
3193 // We already know the speculative type cannot be null
3194 if (!speculative_maybe_null()) {
3195 return false;
3196 }
3197 // We already know this is always null
3198 if (this == TypePtr::NULL_PTR) {
3199 return false;
3200 }
3201 // We already know the speculative type is always null
3202 if (speculative_always_null()) {
3203 return false;
3204 }
3205 if (ptr_kind == ProfileAlwaysNull && speculative() != nullptr && speculative()->isa_oopptr()) {
3206 return false;
3207 }
3208 return true;
3209 }
3210
3211 TypePtr::FlatInArray TypePtr::compute_flat_in_array(ciInstanceKlass* instance_klass, bool is_exact) {
3212 if (!instance_klass->can_be_inline_klass(is_exact)) {
3213 // Definitely not a value class and thus never flat in an array.
3214 return NotFlat;
3215 }
3216 if (instance_klass->is_inlinetype() && instance_klass->as_inline_klass()->is_always_flat_in_array()) {
3217 return Flat;
3218 }
3219 // We don't know.
3220 return MaybeFlat;
3221 }
3222
3223 // Compute flat in array property if we don't know anything about it (i.e. old_flat_in_array == MaybeFlat).
3224 TypePtr::FlatInArray TypePtr::compute_flat_in_array_if_unknown(ciInstanceKlass* instance_klass, bool is_exact,
3225 FlatInArray old_flat_in_array) {
3226 // It is tempting to add verification code that "NotFlat == no value class" and "Flat == value class".
3227 // However, with type speculation, we could get contradicting flat in array properties that propagate through the
3228 // graph. We could try to stop the introduction of contradicting speculative types in terms of their flat in array
3229 // property. But this is hard because it is sometimes only recognized further down in the graph. Thus, we let an
3230 // inconsistent flat in array property propagating through the graph. This could lead to fold an actual live path
3231 // away. But in this case, the speculated type is wrong and we would trap earlier.
3232 if (old_flat_in_array == MaybeFlat) {
3233 return compute_flat_in_array(instance_klass, is_exact);
3234 }
3235 return old_flat_in_array;
3236 }
3237
3238 //------------------------------dump2------------------------------------------
3239 const char *const TypePtr::ptr_msg[TypePtr::lastPTR] = {
3240 "TopPTR","AnyNull","Constant","null","NotNull","BotPTR"
3241 };
3242
3243 #ifndef PRODUCT
3244 void TypePtr::dump2( Dict &d, uint depth, outputStream *st ) const {
3245 st->print("ptr:%s", ptr_msg[_ptr]);
3246 dump_offset(st);
3247 dump_inline_depth(st);
3248 dump_speculative(st);
3249 }
3250
3251 void TypePtr::dump_offset(outputStream* st) const {
3252 _offset.dump2(st);
3253 }
3254
3255 /**
3256 *dump the speculative part of the type
3257 */
3258 void TypePtr::dump_speculative(outputStream *st) const {
3259 if (_speculative != nullptr) {
3260 st->print(" (speculative=");
3261 _speculative->dump_on(st);
3262 st->print(")");
3263 }
3264 }
3265
3266 /**
3267 *dump the inline depth of the type
3268 */
3269 void TypePtr::dump_inline_depth(outputStream *st) const {
3270 if (_inline_depth != InlineDepthBottom) {
3271 if (_inline_depth == InlineDepthTop) {
3272 st->print(" (inline_depth=InlineDepthTop)");
3273 } else {
3274 st->print(" (inline_depth=%d)", _inline_depth);
3275 }
3276 }
3277 }
3278
3279 void TypePtr::dump_flat_in_array(FlatInArray flat_in_array, outputStream* st) {
3280 switch (flat_in_array) {
3281 case MaybeFlat:
3282 case NotFlat:
3283 if (!Verbose) {
3284 break;
3285 }
3286 case TopFlat:
3287 case Flat:
3288 st->print(" (%s)", flat_in_array_msg[flat_in_array]);
3289 break;
3290 default:
3291 ShouldNotReachHere();
3292 }
3293 }
3294 #endif
3295
3296 //------------------------------singleton--------------------------------------
3297 // TRUE if Type is a singleton type, FALSE otherwise. Singletons are simple
3298 // constants
3299 bool TypePtr::singleton(void) const {
3300 // TopPTR, Null, AnyNull, Constant are all singletons
3301 return (_offset != Offset::bottom) && !below_centerline(_ptr);
3302 }
3303
3304 bool TypePtr::empty(void) const {
3305 return (_offset == Offset::top) || above_centerline(_ptr);
3306 }
3307
3308 //=============================================================================
3309 // Convenience common pre-built types.
3310 const TypeRawPtr *TypeRawPtr::BOTTOM;
3311 const TypeRawPtr *TypeRawPtr::NOTNULL;
3312
3313 //------------------------------make-------------------------------------------
3314 const TypeRawPtr *TypeRawPtr::make( enum PTR ptr ) {
3315 assert( ptr != Constant, "what is the constant?" );
3316 assert( ptr != Null, "Use TypePtr for null" );
3317 return (TypeRawPtr*)(new TypeRawPtr(ptr, nullptr, relocInfo::none))->hashcons();
3318 }
3319
3320 const TypeRawPtr* TypeRawPtr::make(address bits, relocInfo::relocType reloc) {
3321 assert(bits != nullptr, "Use TypePtr for null");
3322 return (TypeRawPtr*)(new TypeRawPtr(Constant, bits, reloc))->hashcons();
3323 }
3324
3325 //------------------------------cast_to_ptr_type-------------------------------
3326 const TypeRawPtr* TypeRawPtr::cast_to_ptr_type(PTR ptr) const {
3327 assert( ptr != Constant, "what is the constant?" );
3328 assert( ptr != Null, "Use TypePtr for null" );
3329 assert( _bits == nullptr, "Why cast a constant address?");
3330 if( ptr == _ptr ) return this;
3331 return make(ptr);
3332 }
3333
3334 //------------------------------get_con----------------------------------------
3335 intptr_t TypeRawPtr::get_con() const {
3336 assert( _ptr == Null || _ptr == Constant, "" );
3337 return (intptr_t)_bits;
3338 }
3339
3340 //------------------------------meet-------------------------------------------
3341 // Compute the MEET of two types. It returns a new Type object.
3342 const Type *TypeRawPtr::xmeet( const Type *t ) const {
3343 // Perform a fast test for common case; meeting the same types together.
3344 if( this == t ) return this; // Meeting same type-rep?
3345
3346 // Current "this->_base" is RawPtr
3347 switch( t->base() ) { // switch on original type
3348 case Bottom: // Ye Olde Default
3349 return t;
3350 case Top:
3351 return this;
3352 case AnyPtr: // Meeting to AnyPtrs
3353 break;
3354 case RawPtr: { // might be top, bot, any/not or constant
3355 enum PTR tptr = t->is_ptr()->ptr();
3356 enum PTR ptr = meet_ptr( tptr );
3357 if( ptr == Constant ) { // Cannot be equal constants, so...
3358 if( tptr == Constant && _ptr != Constant) return t;
3359 if( _ptr == Constant && tptr != Constant) return this;
3360 ptr = NotNull; // Fall down in lattice
3361 }
3362 return make( ptr );
3363 }
3364
3365 case OopPtr:
3366 case InstPtr:
3367 case AryPtr:
3368 case MetadataPtr:
3369 case KlassPtr:
3370 case InstKlassPtr:
3371 case AryKlassPtr:
3372 return TypePtr::BOTTOM; // Oop meet raw is not well defined
3373 default: // All else is a mistake
3374 typerr(t);
3375 }
3376
3377 // Found an AnyPtr type vs self-RawPtr type
3378 const TypePtr *tp = t->is_ptr();
3379 switch (tp->ptr()) {
3380 case TypePtr::TopPTR: return this;
3381 case TypePtr::BotPTR: return t;
3382 case TypePtr::Null:
3383 if( _ptr == TypePtr::TopPTR ) return t;
3384 return TypeRawPtr::BOTTOM;
3385 case TypePtr::NotNull: return TypePtr::make(AnyPtr, meet_ptr(TypePtr::NotNull), tp->meet_offset(0), tp->speculative(), tp->inline_depth());
3386 case TypePtr::AnyNull:
3387 if( _ptr == TypePtr::Constant) return this;
3388 return make( meet_ptr(TypePtr::AnyNull) );
3389 default: ShouldNotReachHere();
3390 }
3391 return this;
3392 }
3393
3394 //------------------------------xdual------------------------------------------
3395 // Dual: compute field-by-field dual
3396 const Type *TypeRawPtr::xdual() const {
3397 return new TypeRawPtr(dual_ptr(), _bits, _reloc);
3398 }
3399
3400 //------------------------------add_offset-------------------------------------
3401 const TypePtr* TypeRawPtr::add_offset(intptr_t offset) const {
3402 if( offset == OffsetTop ) return BOTTOM; // Undefined offset-> undefined pointer
3403 if( offset == OffsetBot ) return BOTTOM; // Unknown offset-> unknown pointer
3404 if( offset == 0 ) return this; // No change
3405 switch (_ptr) {
3406 case TypePtr::TopPTR:
3407 case TypePtr::BotPTR:
3408 case TypePtr::NotNull:
3409 return this;
3410 case TypePtr::Constant: {
3411 uintptr_t bits = (uintptr_t)_bits;
3412 uintptr_t sum = bits + offset;
3413 if (( offset < 0 )
3414 ? ( sum > bits ) // Underflow?
3415 : ( sum < bits )) { // Overflow?
3416 return BOTTOM;
3417 } else if ( sum == 0 ) {
3418 return TypePtr::NULL_PTR;
3419 } else {
3420 return make((address)sum, _reloc);
3421 }
3422 }
3423 default: ShouldNotReachHere();
3424 }
3425 }
3426
3427 //------------------------------eq---------------------------------------------
3428 // Structural equality check for Type representations
3429 bool TypeRawPtr::eq( const Type *t ) const {
3430 const TypeRawPtr *a = (const TypeRawPtr*)t;
3431 return _bits == a->_bits && TypePtr::eq(t);
3432 }
3433
3434 //------------------------------hash-------------------------------------------
3435 // Type-specific hashing function.
3436 uint TypeRawPtr::hash(void) const {
3437 return (uint)(uintptr_t)_bits + (uint)TypePtr::hash();
3438 }
3439
3440 //------------------------------dump2------------------------------------------
3441 #ifndef PRODUCT
3442 void TypeRawPtr::dump2(Dict& d, uint depth, outputStream* st) const {
3443 if (_ptr == Constant) {
3444 st->print("rawptr:Constant:" INTPTR_FORMAT, p2i(_bits));
3445 } else {
3446 st->print("rawptr:%s", ptr_msg[_ptr]);
3447 }
3448 }
3449 #endif
3450
3451 //=============================================================================
3452 // Convenience common pre-built type.
3453 const TypeOopPtr *TypeOopPtr::BOTTOM;
3454
3455 TypeInterfaces::TypeInterfaces(ciInstanceKlass** interfaces_base, int nb_interfaces)
3456 : Type(Interfaces), _interfaces(interfaces_base, nb_interfaces),
3457 _hash(0), _exact_klass(nullptr) {
3458 _interfaces.sort(compare);
3459 initialize();
3460 }
3461
3462 const TypeInterfaces* TypeInterfaces::make(GrowableArray<ciInstanceKlass*>* interfaces) {
3463 // hashcons() can only delete the last thing that was allocated: to
3464 // make sure all memory for the newly created TypeInterfaces can be
3465 // freed if an identical one exists, allocate space for the array of
3466 // interfaces right after the TypeInterfaces object so that they
3467 // form a contiguous piece of memory.
3468 int nb_interfaces = interfaces == nullptr ? 0 : interfaces->length();
3469 size_t total_size = sizeof(TypeInterfaces) + nb_interfaces * sizeof(ciInstanceKlass*);
3470
3471 void* allocated_mem = operator new(total_size);
3472 ciInstanceKlass** interfaces_base = (ciInstanceKlass**)((char*)allocated_mem + sizeof(TypeInterfaces));
3473 for (int i = 0; i < nb_interfaces; ++i) {
3474 interfaces_base[i] = interfaces->at(i);
3475 }
3476 TypeInterfaces* result = ::new (allocated_mem) TypeInterfaces(interfaces_base, nb_interfaces);
3477 return (const TypeInterfaces*)result->hashcons();
3478 }
3479
3480 void TypeInterfaces::initialize() {
3481 compute_hash();
3482 compute_exact_klass();
3483 DEBUG_ONLY(_initialized = true;)
3484 }
3485
3486 int TypeInterfaces::compare(ciInstanceKlass* const& k1, ciInstanceKlass* const& k2) {
3487 if ((intptr_t)k1 < (intptr_t)k2) {
3488 return -1;
3489 } else if ((intptr_t)k1 > (intptr_t)k2) {
3490 return 1;
3491 }
3492 return 0;
3493 }
3494
3495 int TypeInterfaces::compare(ciInstanceKlass** k1, ciInstanceKlass** k2) {
3496 return compare(*k1, *k2);
3497 }
3498
3499 bool TypeInterfaces::eq(const Type* t) const {
3500 const TypeInterfaces* other = (const TypeInterfaces*)t;
3501 if (_interfaces.length() != other->_interfaces.length()) {
3502 return false;
3503 }
3504 for (int i = 0; i < _interfaces.length(); i++) {
3505 ciKlass* k1 = _interfaces.at(i);
3506 ciKlass* k2 = other->_interfaces.at(i);
3507 if (!k1->equals(k2)) {
3508 return false;
3509 }
3510 }
3511 return true;
3512 }
3513
3514 bool TypeInterfaces::eq(ciInstanceKlass* k) const {
3515 assert(k->is_loaded(), "should be loaded");
3516 GrowableArray<ciInstanceKlass *>* interfaces = k->transitive_interfaces();
3517 if (_interfaces.length() != interfaces->length()) {
3518 return false;
3519 }
3520 for (int i = 0; i < interfaces->length(); i++) {
3521 bool found = false;
3522 _interfaces.find_sorted<ciInstanceKlass*, compare>(interfaces->at(i), found);
3523 if (!found) {
3524 return false;
3525 }
3526 }
3527 return true;
3528 }
3529
3530 // Check whether an instance of type k will satisfy this
3531 bool TypeInterfaces::is_subset(ciInstanceKlass* k) const {
3532 assert(k->is_loaded(), "should be loaded");
3533 GrowableArray<ciInstanceKlass*>* k_interfaces = k->transitive_interfaces();
3534 for (int i = 0; i < _interfaces.length(); i++) {
3535 if (!k_interfaces->contains(_interfaces.at(i))) {
3536 return false;
3537 }
3538 }
3539 return true;
3540 }
3541
3542 uint TypeInterfaces::hash() const {
3543 assert(_initialized, "must be");
3544 return _hash;
3545 }
3546
3547 const Type* TypeInterfaces::xdual() const {
3548 return this;
3549 }
3550
3551 void TypeInterfaces::compute_hash() {
3552 uint hash = 0;
3553 for (int i = 0; i < _interfaces.length(); i++) {
3554 ciKlass* k = _interfaces.at(i);
3555 hash += k->hash();
3556 }
3557 _hash = hash;
3558 }
3559
3560 static int compare_interfaces(ciInstanceKlass** k1, ciInstanceKlass** k2) {
3561 return (int)((*k1)->ident() - (*k2)->ident());
3562 }
3563
3564 void TypeInterfaces::dump(outputStream* st) const {
3565 if (_interfaces.length() == 0) {
3566 return;
3567 }
3568 ResourceMark rm;
3569 st->print(" (");
3570 GrowableArray<ciInstanceKlass*> interfaces;
3571 interfaces.appendAll(&_interfaces);
3572 // Sort the interfaces so they are listed in the same order from one run to the other of the same compilation
3573 interfaces.sort(compare_interfaces);
3574 for (int i = 0; i < interfaces.length(); i++) {
3575 if (i > 0) {
3576 st->print(",");
3577 }
3578 ciKlass* k = interfaces.at(i);
3579 k->print_name_on(st);
3580 }
3581 st->print(")");
3582 }
3583
3584 #ifdef ASSERT
3585 void TypeInterfaces::verify() const {
3586 for (int i = 1; i < _interfaces.length(); i++) {
3587 ciInstanceKlass* k1 = _interfaces.at(i-1);
3588 ciInstanceKlass* k2 = _interfaces.at(i);
3589 assert(compare(k2, k1) > 0, "should be ordered");
3590 assert(k1 != k2, "no duplicate");
3591 }
3592 }
3593 #endif
3594
3595 const TypeInterfaces* TypeInterfaces::union_with(const TypeInterfaces* other) const {
3596 GrowableArray<ciInstanceKlass*> result_list;
3597 int i = 0;
3598 int j = 0;
3599 while (i < _interfaces.length() || j < other->_interfaces.length()) {
3600 while (i < _interfaces.length() &&
3601 (j >= other->_interfaces.length() ||
3602 compare(_interfaces.at(i), other->_interfaces.at(j)) < 0)) {
3603 result_list.push(_interfaces.at(i));
3604 i++;
3605 }
3606 while (j < other->_interfaces.length() &&
3607 (i >= _interfaces.length() ||
3608 compare(other->_interfaces.at(j), _interfaces.at(i)) < 0)) {
3609 result_list.push(other->_interfaces.at(j));
3610 j++;
3611 }
3612 if (i < _interfaces.length() &&
3613 j < other->_interfaces.length() &&
3614 _interfaces.at(i) == other->_interfaces.at(j)) {
3615 result_list.push(_interfaces.at(i));
3616 i++;
3617 j++;
3618 }
3619 }
3620 const TypeInterfaces* result = TypeInterfaces::make(&result_list);
3621 #ifdef ASSERT
3622 result->verify();
3623 for (int i = 0; i < _interfaces.length(); i++) {
3624 assert(result->_interfaces.contains(_interfaces.at(i)), "missing");
3625 }
3626 for (int i = 0; i < other->_interfaces.length(); i++) {
3627 assert(result->_interfaces.contains(other->_interfaces.at(i)), "missing");
3628 }
3629 for (int i = 0; i < result->_interfaces.length(); i++) {
3630 assert(_interfaces.contains(result->_interfaces.at(i)) || other->_interfaces.contains(result->_interfaces.at(i)), "missing");
3631 }
3632 #endif
3633 return result;
3634 }
3635
3636 const TypeInterfaces* TypeInterfaces::intersection_with(const TypeInterfaces* other) const {
3637 GrowableArray<ciInstanceKlass*> result_list;
3638 int i = 0;
3639 int j = 0;
3640 while (i < _interfaces.length() || j < other->_interfaces.length()) {
3641 while (i < _interfaces.length() &&
3642 (j >= other->_interfaces.length() ||
3643 compare(_interfaces.at(i), other->_interfaces.at(j)) < 0)) {
3644 i++;
3645 }
3646 while (j < other->_interfaces.length() &&
3647 (i >= _interfaces.length() ||
3648 compare(other->_interfaces.at(j), _interfaces.at(i)) < 0)) {
3649 j++;
3650 }
3651 if (i < _interfaces.length() &&
3652 j < other->_interfaces.length() &&
3653 _interfaces.at(i) == other->_interfaces.at(j)) {
3654 result_list.push(_interfaces.at(i));
3655 i++;
3656 j++;
3657 }
3658 }
3659 const TypeInterfaces* result = TypeInterfaces::make(&result_list);
3660 #ifdef ASSERT
3661 result->verify();
3662 for (int i = 0; i < _interfaces.length(); i++) {
3663 assert(!other->_interfaces.contains(_interfaces.at(i)) || result->_interfaces.contains(_interfaces.at(i)), "missing");
3664 }
3665 for (int i = 0; i < other->_interfaces.length(); i++) {
3666 assert(!_interfaces.contains(other->_interfaces.at(i)) || result->_interfaces.contains(other->_interfaces.at(i)), "missing");
3667 }
3668 for (int i = 0; i < result->_interfaces.length(); i++) {
3669 assert(_interfaces.contains(result->_interfaces.at(i)) && other->_interfaces.contains(result->_interfaces.at(i)), "missing");
3670 }
3671 #endif
3672 return result;
3673 }
3674
3675 // Is there a single ciKlass* that can represent the interface set?
3676 ciInstanceKlass* TypeInterfaces::exact_klass() const {
3677 assert(_initialized, "must be");
3678 return _exact_klass;
3679 }
3680
3681 void TypeInterfaces::compute_exact_klass() {
3682 if (_interfaces.length() == 0) {
3683 _exact_klass = nullptr;
3684 return;
3685 }
3686 ciInstanceKlass* res = nullptr;
3687 for (int i = 0; i < _interfaces.length(); i++) {
3688 ciInstanceKlass* interface = _interfaces.at(i);
3689 if (eq(interface)) {
3690 assert(res == nullptr, "");
3691 res = interface;
3692 }
3693 }
3694 _exact_klass = res;
3695 }
3696
3697 #ifdef ASSERT
3698 void TypeInterfaces::verify_is_loaded() const {
3699 for (int i = 0; i < _interfaces.length(); i++) {
3700 ciKlass* interface = _interfaces.at(i);
3701 assert(interface->is_loaded(), "Interface not loaded");
3702 }
3703 }
3704 #endif
3705
3706 // Can't be implemented because there's no way to know if the type is above or below the center line.
3707 const Type* TypeInterfaces::xmeet(const Type* t) const {
3708 ShouldNotReachHere();
3709 return Type::xmeet(t);
3710 }
3711
3712 bool TypeInterfaces::singleton(void) const {
3713 ShouldNotReachHere();
3714 return Type::singleton();
3715 }
3716
3717 bool TypeInterfaces::has_non_array_interface() const {
3718 assert(TypeAryPtr::_array_interfaces != nullptr, "How come Type::Initialize_shared wasn't called yet?");
3719
3720 return !TypeAryPtr::_array_interfaces->contains(this);
3721 }
3722
3723 //------------------------------TypeOopPtr-------------------------------------
3724 TypeOopPtr::TypeOopPtr(TYPES t, PTR ptr, ciKlass* k, const TypeInterfaces* interfaces, bool xk, ciObject* o, Offset offset, Offset field_offset,
3725 int instance_id, const TypePtr* speculative, int inline_depth)
3726 : TypePtr(t, ptr, offset, relocInfo::oop_type, speculative, inline_depth),
3727 _const_oop(o), _klass(k),
3728 _interfaces(interfaces),
3729 _klass_is_exact(xk),
3730 _is_ptr_to_narrowoop(false),
3731 _is_ptr_to_narrowklass(false),
3732 _is_ptr_to_boxed_value(false),
3733 _is_ptr_to_strict_final_field(false),
3734 _instance_id(instance_id) {
3735 #ifdef ASSERT
3736 if (klass() != nullptr && klass()->is_loaded()) {
3737 interfaces->verify_is_loaded();
3738 }
3739 #endif
3740 if (Compile::current()->eliminate_boxing() && (t == InstPtr) &&
3741 (offset.get() > 0) && xk && (k != nullptr) && k->is_instance_klass()) {
3742 _is_ptr_to_boxed_value = k->as_instance_klass()->is_boxed_value_offset(offset.get());
3743 _is_ptr_to_strict_final_field = _is_ptr_to_boxed_value;
3744 }
3745
3746 if (klass() != nullptr && klass()->is_instance_klass() && klass()->is_loaded() &&
3747 this->offset() != Type::OffsetBot && this->offset() != Type::OffsetTop) {
3748 ciField* field = klass()->as_instance_klass()->get_field_by_offset(this->offset(), false);
3749 if (field != nullptr && field->is_strict() && field->is_final()) {
3750 _is_ptr_to_strict_final_field = true;
3751 }
3752 }
3753
3754 #ifdef _LP64
3755 if (this->offset() > 0 || this->offset() == Type::OffsetTop || this->offset() == Type::OffsetBot) {
3756 if (this->offset() == oopDesc::klass_offset_in_bytes()) {
3757 _is_ptr_to_narrowklass = true;
3758 } else if (klass() == nullptr) {
3759 // Array with unknown body type
3760 assert(this->isa_aryptr(), "only arrays without klass");
3761 _is_ptr_to_narrowoop = UseCompressedOops;
3762 } else if (UseCompressedOops && this->isa_aryptr() && this->offset() != arrayOopDesc::length_offset_in_bytes()) {
3763 if (klass()->is_flat_array_klass() && field_offset != Offset::top && field_offset != Offset::bottom) {
3764 // Check if the field of the inline type array element contains oops
3765 ciInlineKlass* vk = klass()->as_flat_array_klass()->element_klass()->as_inline_klass();
3766 int foffset = field_offset.get() + vk->payload_offset();
3767 BasicType field_bt;
3768 ciField* field = vk->get_field_by_offset(foffset, false);
3769 if (field != nullptr) {
3770 field_bt = field->layout_type();
3771 } else {
3772 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);
3773 field_bt = T_BOOLEAN;
3774 }
3775 _is_ptr_to_narrowoop = ::is_reference_type(field_bt);
3776 } else if (klass()->is_obj_array_klass()) {
3777 _is_ptr_to_narrowoop = true;
3778 }
3779 } else if (klass()->is_instance_klass()) {
3780 if (this->isa_klassptr()) {
3781 // Perm objects don't use compressed references
3782 } else if (_offset == Offset::bottom || _offset == Offset::top) {
3783 // unsafe access
3784 _is_ptr_to_narrowoop = UseCompressedOops;
3785 } else {
3786 assert(this->isa_instptr(), "must be an instance ptr.");
3787 if (klass() == ciEnv::current()->Class_klass() &&
3788 (this->offset() == java_lang_Class::klass_offset() ||
3789 this->offset() == java_lang_Class::array_klass_offset())) {
3790 // Special hidden fields from the Class.
3791 assert(this->isa_instptr(), "must be an instance ptr.");
3792 _is_ptr_to_narrowoop = false;
3793 } else if (klass() == ciEnv::current()->Class_klass() &&
3794 this->offset() >= InstanceMirrorKlass::offset_of_static_fields()) {
3795 // Static fields
3796 BasicType basic_elem_type = T_ILLEGAL;
3797 if (const_oop() != nullptr) {
3798 ciInstanceKlass* k = const_oop()->as_instance()->java_lang_Class_klass()->as_instance_klass();
3799 basic_elem_type = k->get_field_type_by_offset(this->offset(), true);
3800 }
3801 if (basic_elem_type != T_ILLEGAL) {
3802 _is_ptr_to_narrowoop = UseCompressedOops && ::is_reference_type(basic_elem_type);
3803 } else {
3804 // unsafe access
3805 _is_ptr_to_narrowoop = UseCompressedOops;
3806 }
3807 } else {
3808 // Instance fields which contains a compressed oop references.
3809 ciInstanceKlass* ik = klass()->as_instance_klass();
3810 BasicType basic_elem_type = ik->get_field_type_by_offset(this->offset(), false);
3811 if (basic_elem_type != T_ILLEGAL) {
3812 _is_ptr_to_narrowoop = UseCompressedOops && ::is_reference_type(basic_elem_type);
3813 } else if (klass()->equals(ciEnv::current()->Object_klass())) {
3814 // Compile::find_alias_type() cast exactness on all types to verify
3815 // that it does not affect alias type.
3816 _is_ptr_to_narrowoop = UseCompressedOops;
3817 } else {
3818 // Type for the copy start in LibraryCallKit::inline_native_clone().
3819 _is_ptr_to_narrowoop = UseCompressedOops;
3820 }
3821 }
3822 }
3823 }
3824 }
3825 #endif // _LP64
3826 }
3827
3828 //------------------------------make-------------------------------------------
3829 const TypeOopPtr *TypeOopPtr::make(PTR ptr, Offset offset, int instance_id,
3830 const TypePtr* speculative, int inline_depth) {
3831 assert(ptr != Constant, "no constant generic pointers");
3832 ciKlass* k = Compile::current()->env()->Object_klass();
3833 bool xk = false;
3834 ciObject* o = nullptr;
3835 const TypeInterfaces* interfaces = TypeInterfaces::make();
3836 return (TypeOopPtr*)(new TypeOopPtr(OopPtr, ptr, k, interfaces, xk, o, offset, Offset::bottom, instance_id, speculative, inline_depth))->hashcons();
3837 }
3838
3839
3840 //------------------------------cast_to_ptr_type-------------------------------
3841 const TypeOopPtr* TypeOopPtr::cast_to_ptr_type(PTR ptr) const {
3842 assert(_base == OopPtr, "subclass must override cast_to_ptr_type");
3843 if( ptr == _ptr ) return this;
3844 return make(ptr, _offset, _instance_id, _speculative, _inline_depth);
3845 }
3846
3847 //-----------------------------cast_to_instance_id----------------------------
3848 const TypeOopPtr *TypeOopPtr::cast_to_instance_id(int instance_id) const {
3849 // There are no instances of a general oop.
3850 // Return self unchanged.
3851 return this;
3852 }
3853
3854 //-----------------------------cast_to_exactness-------------------------------
3855 const TypeOopPtr* TypeOopPtr::cast_to_exactness(bool klass_is_exact) const {
3856 // There is no such thing as an exact general oop.
3857 // Return self unchanged.
3858 return this;
3859 }
3860
3861 //------------------------------as_klass_type----------------------------------
3862 // Return the klass type corresponding to this instance or array type.
3863 // It is the type that is loaded from an object of this type.
3864 const TypeKlassPtr* TypeOopPtr::as_klass_type(bool try_for_exact) const {
3865 ShouldNotReachHere();
3866 return nullptr;
3867 }
3868
3869 //------------------------------meet-------------------------------------------
3870 // Compute the MEET of two types. It returns a new Type object.
3871 const Type *TypeOopPtr::xmeet_helper(const Type *t) const {
3872 // Perform a fast test for common case; meeting the same types together.
3873 if( this == t ) return this; // Meeting same type-rep?
3874
3875 // Current "this->_base" is OopPtr
3876 switch (t->base()) { // switch on original type
3877
3878 case Int: // Mixing ints & oops happens when javac
3879 case Long: // reuses local variables
3880 case HalfFloatTop:
3881 case HalfFloatCon:
3882 case HalfFloatBot:
3883 case FloatTop:
3884 case FloatCon:
3885 case FloatBot:
3886 case DoubleTop:
3887 case DoubleCon:
3888 case DoubleBot:
3889 case NarrowOop:
3890 case NarrowKlass:
3891 case Bottom: // Ye Olde Default
3892 return Type::BOTTOM;
3893 case Top:
3894 return this;
3895
3896 default: // All else is a mistake
3897 typerr(t);
3898
3899 case RawPtr:
3900 case MetadataPtr:
3901 case KlassPtr:
3902 case InstKlassPtr:
3903 case AryKlassPtr:
3904 return TypePtr::BOTTOM; // Oop meet raw is not well defined
3905
3906 case AnyPtr: {
3907 // Found an AnyPtr type vs self-OopPtr type
3908 const TypePtr *tp = t->is_ptr();
3909 Offset offset = meet_offset(tp->offset());
3910 PTR ptr = meet_ptr(tp->ptr());
3911 const TypePtr* speculative = xmeet_speculative(tp);
3912 int depth = meet_inline_depth(tp->inline_depth());
3913 switch (tp->ptr()) {
3914 case Null:
3915 if (ptr == Null) return TypePtr::make(AnyPtr, ptr, offset, speculative, depth);
3916 // else fall through:
3917 case TopPTR:
3918 case AnyNull: {
3919 int instance_id = meet_instance_id(InstanceTop);
3920 return make(ptr, offset, instance_id, speculative, depth);
3921 }
3922 case BotPTR:
3923 case NotNull:
3924 return TypePtr::make(AnyPtr, ptr, offset, speculative, depth);
3925 default: typerr(t);
3926 }
3927 }
3928
3929 case OopPtr: { // Meeting to other OopPtrs
3930 const TypeOopPtr *tp = t->is_oopptr();
3931 int instance_id = meet_instance_id(tp->instance_id());
3932 const TypePtr* speculative = xmeet_speculative(tp);
3933 int depth = meet_inline_depth(tp->inline_depth());
3934 return make(meet_ptr(tp->ptr()), meet_offset(tp->offset()), instance_id, speculative, depth);
3935 }
3936
3937 case InstPtr: // For these, flip the call around to cut down
3938 case AryPtr:
3939 return t->xmeet(this); // Call in reverse direction
3940
3941 } // End of switch
3942 return this; // Return the double constant
3943 }
3944
3945
3946 //------------------------------xdual------------------------------------------
3947 // Dual of a pure heap pointer. No relevant klass or oop information.
3948 const Type *TypeOopPtr::xdual() const {
3949 assert(klass() == Compile::current()->env()->Object_klass(), "no klasses here");
3950 assert(const_oop() == nullptr, "no constants here");
3951 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());
3952 }
3953
3954 //--------------------------make_from_klass_common-----------------------------
3955 // Computes the element-type given a klass.
3956 const TypeOopPtr* TypeOopPtr::make_from_klass_common(ciKlass *klass, bool klass_change, bool try_for_exact, InterfaceHandling interface_handling) {
3957 if (klass->is_instance_klass() || klass->is_inlinetype()) {
3958 Compile* C = Compile::current();
3959 Dependencies* deps = C->dependencies();
3960 assert((deps != nullptr) == (C->method() != nullptr && C->method()->code_size() > 0), "sanity");
3961 // Element is an instance
3962 bool klass_is_exact = false;
3963 ciInstanceKlass* ik = klass->as_instance_klass();
3964 if (klass->is_loaded()) {
3965 // Try to set klass_is_exact.
3966 klass_is_exact = ik->is_final();
3967 if (!klass_is_exact && klass_change
3968 && deps != nullptr && UseUniqueSubclasses) {
3969 ciInstanceKlass* sub = ik->unique_concrete_subklass();
3970 if (sub != nullptr) {
3971 deps->assert_abstract_with_unique_concrete_subtype(ik, sub);
3972 klass = ik = sub;
3973 klass_is_exact = sub->is_final();
3974 }
3975 }
3976 if (!klass_is_exact && try_for_exact && deps != nullptr &&
3977 !ik->is_interface() && !ik->has_subklass()) {
3978 // Add a dependence; if concrete subclass added we need to recompile
3979 deps->assert_leaf_type(ik);
3980 klass_is_exact = true;
3981 }
3982 }
3983 FlatInArray flat_in_array = compute_flat_in_array(ik, klass_is_exact);
3984 const TypeInterfaces* interfaces = TypePtr::interfaces(klass, true, true, false, interface_handling);
3985 return TypeInstPtr::make(TypePtr::BotPTR, klass, interfaces, klass_is_exact, nullptr, Offset(0), flat_in_array);
3986 } else if (klass->is_obj_array_klass()) {
3987 // Element is an object or inline type array. Recursively call ourself.
3988 ciObjArrayKlass* array_klass = klass->as_obj_array_klass();
3989 const TypeOopPtr* etype = TypeOopPtr::make_from_klass_common(array_klass->element_klass(), /* klass_change= */ false, try_for_exact, interface_handling);
3990 bool xk = array_klass->is_loaded() && array_klass->is_refined();
3991
3992 // Determine null-free/flat properties
3993 bool flat;
3994 bool not_flat;
3995 bool not_null_free;
3996 bool atomic;
3997 if (xk) {
3998 flat = array_klass->is_flat_array_klass();
3999 not_flat = !flat;
4000 bool is_null_free = array_klass->is_elem_null_free();
4001 not_null_free = !is_null_free;
4002 atomic = array_klass->is_elem_atomic();
4003
4004 if (is_null_free) {
4005 etype = etype->join_speculative(NOTNULL)->is_oopptr();
4006 }
4007 } else {
4008 const TypeOopPtr* exact_etype = etype;
4009 if (etype->can_be_inline_type()) {
4010 // Use exact type if element can be an inline type
4011 exact_etype = TypeOopPtr::make_from_klass_common(klass->as_array_klass()->element_klass(), /* klass_change= */ true, /* try_for_exact= */ true, interface_handling);
4012 }
4013
4014 flat = false;
4015 bool not_inline = !exact_etype->can_be_inline_type();
4016 not_null_free = not_inline;
4017 not_flat = !UseArrayFlattening || not_inline || (exact_etype->is_inlinetypeptr() && !exact_etype->inline_klass()->maybe_flat_in_array());
4018 atomic = not_flat;
4019 }
4020
4021 const TypeAry* arr0 = TypeAry::make(etype, TypeInt::POS, /* stable= */ false, flat, not_flat, not_null_free, atomic);
4022 // We used to pass NotNull in here, asserting that the sub-arrays
4023 // are all not-null. This is not true in generally, as code can
4024 // slam nullptrs down in the subarrays.
4025 const TypeAryPtr* arr = TypeAryPtr::make(TypePtr::BotPTR, arr0, nullptr, xk, Offset(0));
4026 return arr;
4027 } else if (klass->is_type_array_klass()) {
4028 // Element is an typeArray
4029 const Type* etype = get_const_basic_type(klass->as_type_array_klass()->element_type());
4030 const TypeAry* arr0 = TypeAry::make(etype, TypeInt::POS,
4031 /* stable= */ false, /* flat= */ false, /* not_flat= */ true, /* not_null_free= */ true, true);
4032 // We used to pass NotNull in here, asserting that the array pointer
4033 // is not-null. That was not true in general.
4034 const TypeAryPtr* arr = TypeAryPtr::make(TypePtr::BotPTR, arr0, klass, true, Offset(0));
4035 return arr;
4036 } else {
4037 ShouldNotReachHere();
4038 return nullptr;
4039 }
4040 }
4041
4042 //------------------------------make_from_constant-----------------------------
4043 // Make a java pointer from an oop constant
4044 const TypeOopPtr* TypeOopPtr::make_from_constant(ciObject* o, bool require_constant) {
4045 assert(!o->is_null_object(), "null object not yet handled here.");
4046
4047 const bool make_constant = require_constant || o->should_be_constant();
4048
4049 ciKlass* klass = o->klass();
4050 if (klass->is_instance_klass() || klass->is_inlinetype()) {
4051 // Element is an instance or inline type
4052 if (make_constant) {
4053 return TypeInstPtr::make(o);
4054 } else {
4055 return TypeInstPtr::make(TypePtr::NotNull, klass, true, nullptr, Offset(0));
4056 }
4057 } else if (klass->is_obj_array_klass()) {
4058 // Element is an object array. Recursively call ourself.
4059 const TypeOopPtr* etype = TypeOopPtr::make_from_klass_raw(klass->as_array_klass()->element_klass(), trust_interfaces);
4060 bool is_flat = o->as_array()->is_flat();
4061 bool is_null_free = o->as_array()->is_null_free();
4062 if (is_null_free) {
4063 etype = etype->join_speculative(TypePtr::NOTNULL)->is_oopptr();
4064 }
4065 bool is_atomic = o->as_array()->is_atomic();
4066 const TypeAry* arr0 = TypeAry::make(etype, TypeInt::make(o->as_array()->length()), /* stable= */ false, /* flat= */ is_flat,
4067 /* not_flat= */ !is_flat, /* not_null_free= */ !is_null_free, /* atomic= */ is_atomic);
4068 // We used to pass NotNull in here, asserting that the sub-arrays
4069 // are all not-null. This is not true in generally, as code can
4070 // slam nulls down in the subarrays.
4071 if (make_constant) {
4072 return TypeAryPtr::make(TypePtr::Constant, o, arr0, klass, true, Offset(0));
4073 } else {
4074 return TypeAryPtr::make(TypePtr::NotNull, arr0, klass, true, Offset(0));
4075 }
4076 } else if (klass->is_type_array_klass()) {
4077 // Element is an typeArray
4078 const Type* etype = (Type*)get_const_basic_type(klass->as_type_array_klass()->element_type());
4079 const TypeAry* arr0 = TypeAry::make(etype, TypeInt::make(o->as_array()->length()), /* stable= */ false, /* flat= */ false,
4080 /* not_flat= */ true, /* not_null_free= */ true, true);
4081 // We used to pass NotNull in here, asserting that the array pointer
4082 // is not-null. That was not true in general.
4083 if (make_constant) {
4084 return TypeAryPtr::make(TypePtr::Constant, o, arr0, klass, true, Offset(0));
4085 } else {
4086 return TypeAryPtr::make(TypePtr::NotNull, arr0, klass, true, Offset(0));
4087 }
4088 }
4089
4090 fatal("unhandled object type");
4091 return nullptr;
4092 }
4093
4094 //------------------------------get_con----------------------------------------
4095 intptr_t TypeOopPtr::get_con() const {
4096 assert( _ptr == Null || _ptr == Constant, "" );
4097 assert(offset() >= 0, "");
4098
4099 if (offset() != 0) {
4100 // After being ported to the compiler interface, the compiler no longer
4101 // directly manipulates the addresses of oops. Rather, it only has a pointer
4102 // to a handle at compile time. This handle is embedded in the generated
4103 // code and dereferenced at the time the nmethod is made. Until that time,
4104 // it is not reasonable to do arithmetic with the addresses of oops (we don't
4105 // have access to the addresses!). This does not seem to currently happen,
4106 // but this assertion here is to help prevent its occurrence.
4107 tty->print_cr("Found oop constant with non-zero offset");
4108 ShouldNotReachHere();
4109 }
4110
4111 return (intptr_t)const_oop()->constant_encoding();
4112 }
4113
4114
4115 //-----------------------------filter------------------------------------------
4116 // Do not allow interface-vs.-noninterface joins to collapse to top.
4117 const Type *TypeOopPtr::filter_helper(const Type *kills, bool include_speculative) const {
4118
4119 const Type* ft = join_helper(kills, include_speculative);
4120
4121 if (ft->empty()) {
4122 return Type::TOP; // Canonical empty value
4123 }
4124
4125 return ft;
4126 }
4127
4128 //------------------------------eq---------------------------------------------
4129 // Structural equality check for Type representations
4130 bool TypeOopPtr::eq( const Type *t ) const {
4131 const TypeOopPtr *a = (const TypeOopPtr*)t;
4132 if (_klass_is_exact != a->_klass_is_exact ||
4133 _instance_id != a->_instance_id) return false;
4134 ciObject* one = const_oop();
4135 ciObject* two = a->const_oop();
4136 if (one == nullptr || two == nullptr) {
4137 return (one == two) && TypePtr::eq(t);
4138 } else {
4139 return one->equals(two) && TypePtr::eq(t);
4140 }
4141 }
4142
4143 //------------------------------hash-------------------------------------------
4144 // Type-specific hashing function.
4145 uint TypeOopPtr::hash(void) const {
4146 return
4147 (uint)(const_oop() ? const_oop()->hash() : 0) +
4148 (uint)_klass_is_exact +
4149 (uint)_instance_id + TypePtr::hash();
4150 }
4151
4152 //------------------------------dump2------------------------------------------
4153 #ifndef PRODUCT
4154 void TypeOopPtr::dump2(Dict& d, uint depth, outputStream* st) const {
4155 st->print("oopptr:%s", ptr_msg[_ptr]);
4156 if (_klass_is_exact) {
4157 st->print(":exact");
4158 }
4159 if (const_oop() != nullptr) {
4160 st->print(":" INTPTR_FORMAT, p2i(const_oop()));
4161 }
4162 dump_offset(st);
4163 dump_instance_id(st);
4164 dump_inline_depth(st);
4165 dump_speculative(st);
4166 }
4167
4168 void TypeOopPtr::dump_instance_id(outputStream* st) const {
4169 if (_instance_id == InstanceTop) {
4170 st->print(",iid=top");
4171 } else if (_instance_id == InstanceBot) {
4172 st->print(",iid=bot");
4173 } else {
4174 st->print(",iid=%d", _instance_id);
4175 }
4176 }
4177 #endif
4178
4179 //------------------------------singleton--------------------------------------
4180 // TRUE if Type is a singleton type, FALSE otherwise. Singletons are simple
4181 // constants
4182 bool TypeOopPtr::singleton(void) const {
4183 // detune optimizer to not generate constant oop + constant offset as a constant!
4184 // TopPTR, Null, AnyNull, Constant are all singletons
4185 return (offset() == 0) && !below_centerline(_ptr);
4186 }
4187
4188 //------------------------------add_offset-------------------------------------
4189 const TypePtr* TypeOopPtr::add_offset(intptr_t offset) const {
4190 return make(_ptr, xadd_offset(offset), _instance_id, add_offset_speculative(offset), _inline_depth);
4191 }
4192
4193 const TypeOopPtr* TypeOopPtr::with_offset(intptr_t offset) const {
4194 return make(_ptr, Offset(offset), _instance_id, with_offset_speculative(offset), _inline_depth);
4195 }
4196
4197 /**
4198 * Return same type without a speculative part
4199 */
4200 const TypeOopPtr* TypeOopPtr::remove_speculative() const {
4201 if (_speculative == nullptr) {
4202 return this;
4203 }
4204 assert(_inline_depth == InlineDepthTop || _inline_depth == InlineDepthBottom, "non speculative type shouldn't have inline depth");
4205 return make(_ptr, _offset, _instance_id, nullptr, _inline_depth);
4206 }
4207
4208 /**
4209 * Return same type but drop speculative part if we know we won't use
4210 * it
4211 */
4212 const Type* TypeOopPtr::cleanup_speculative() const {
4213 // If the klass is exact and the ptr is not null then there's
4214 // nothing that the speculative type can help us with
4215 if (klass_is_exact() && !maybe_null()) {
4216 return remove_speculative();
4217 }
4218 return TypePtr::cleanup_speculative();
4219 }
4220
4221 /**
4222 * Return same type but with a different inline depth (used for speculation)
4223 *
4224 * @param depth depth to meet with
4225 */
4226 const TypePtr* TypeOopPtr::with_inline_depth(int depth) const {
4227 if (!UseInlineDepthForSpeculativeTypes) {
4228 return this;
4229 }
4230 return make(_ptr, _offset, _instance_id, _speculative, depth);
4231 }
4232
4233 //------------------------------with_instance_id--------------------------------
4234 const TypePtr* TypeOopPtr::with_instance_id(int instance_id) const {
4235 assert(_instance_id != -1, "should be known");
4236 return make(_ptr, _offset, instance_id, _speculative, _inline_depth);
4237 }
4238
4239 //------------------------------meet_instance_id--------------------------------
4240 int TypeOopPtr::meet_instance_id( int instance_id ) const {
4241 // Either is 'TOP' instance? Return the other instance!
4242 if( _instance_id == InstanceTop ) return instance_id;
4243 if( instance_id == InstanceTop ) return _instance_id;
4244 // If either is different, return 'BOTTOM' instance
4245 if( _instance_id != instance_id ) return InstanceBot;
4246 return _instance_id;
4247 }
4248
4249 //------------------------------dual_instance_id--------------------------------
4250 int TypeOopPtr::dual_instance_id( ) const {
4251 if( _instance_id == InstanceTop ) return InstanceBot; // Map TOP into BOTTOM
4252 if( _instance_id == InstanceBot ) return InstanceTop; // Map BOTTOM into TOP
4253 return _instance_id; // Map everything else into self
4254 }
4255
4256
4257 const TypeInterfaces* TypeOopPtr::meet_interfaces(const TypeOopPtr* other) const {
4258 if (above_centerline(_ptr) && above_centerline(other->_ptr)) {
4259 return _interfaces->union_with(other->_interfaces);
4260 } else if (above_centerline(_ptr) && !above_centerline(other->_ptr)) {
4261 return other->_interfaces;
4262 } else if (above_centerline(other->_ptr) && !above_centerline(_ptr)) {
4263 return _interfaces;
4264 }
4265 return _interfaces->intersection_with(other->_interfaces);
4266 }
4267
4268 /**
4269 * Check whether new profiling would improve speculative type
4270 *
4271 * @param exact_kls class from profiling
4272 * @param inline_depth inlining depth of profile point
4273 *
4274 * @return true if type profile is valuable
4275 */
4276 bool TypeOopPtr::would_improve_type(ciKlass* exact_kls, int inline_depth) const {
4277 // no way to improve an already exact type
4278 if (klass_is_exact()) {
4279 return false;
4280 }
4281 return TypePtr::would_improve_type(exact_kls, inline_depth);
4282 }
4283
4284 //=============================================================================
4285 // Convenience common pre-built types.
4286 const TypeInstPtr *TypeInstPtr::NOTNULL;
4287 const TypeInstPtr *TypeInstPtr::BOTTOM;
4288 const TypeInstPtr *TypeInstPtr::MIRROR;
4289 const TypeInstPtr *TypeInstPtr::MARK;
4290 const TypeInstPtr *TypeInstPtr::KLASS;
4291
4292 // Is there a single ciKlass* that can represent that type?
4293 ciKlass* TypeInstPtr::exact_klass_helper() const {
4294 if (_interfaces->empty()) {
4295 return _klass;
4296 }
4297 if (_klass != ciEnv::current()->Object_klass()) {
4298 if (_interfaces->eq(_klass->as_instance_klass())) {
4299 return _klass;
4300 }
4301 return nullptr;
4302 }
4303 return _interfaces->exact_klass();
4304 }
4305
4306 //------------------------------TypeInstPtr-------------------------------------
4307 TypeInstPtr::TypeInstPtr(PTR ptr, ciKlass* k, const TypeInterfaces* interfaces, bool xk, ciObject* o, Offset off,
4308 FlatInArray flat_in_array, int instance_id, const TypePtr* speculative, int inline_depth)
4309 : TypeOopPtr(InstPtr, ptr, k, interfaces, xk, o, off, Offset::bottom, instance_id, speculative, inline_depth),
4310 _flat_in_array(flat_in_array) {
4311
4312 assert(flat_in_array != Uninitialized, "must be set now");
4313 assert(k == nullptr || !k->is_loaded() || !k->is_interface(), "no interface here");
4314 assert(k != nullptr &&
4315 (k->is_loaded() || o == nullptr),
4316 "cannot have constants with non-loaded klass");
4317 };
4318
4319 //------------------------------make-------------------------------------------
4320 const TypeInstPtr *TypeInstPtr::make(PTR ptr,
4321 ciKlass* k,
4322 const TypeInterfaces* interfaces,
4323 bool xk,
4324 ciObject* o,
4325 Offset offset,
4326 FlatInArray flat_in_array,
4327 int instance_id,
4328 const TypePtr* speculative,
4329 int inline_depth) {
4330 assert( !k->is_loaded() || k->is_instance_klass(), "Must be for instance");
4331 // Either const_oop() is null or else ptr is Constant
4332 assert( (!o && ptr != Constant) || (o && ptr == Constant),
4333 "constant pointers must have a value supplied" );
4334 // Ptr is never Null
4335 assert( ptr != Null, "null pointers are not typed" );
4336
4337 assert(instance_id <= 0 || xk, "instances are always exactly typed");
4338 ciInstanceKlass* ik = k->as_instance_klass();
4339 if (ptr == Constant) {
4340 // Note: This case includes meta-object constants, such as methods.
4341 xk = true;
4342 } else if (k->is_loaded()) {
4343 if (!xk && ik->is_final()) xk = true; // no inexact final klass
4344 assert(!ik->is_interface(), "no interface here");
4345 if (xk && ik->is_interface()) xk = false; // no exact interface
4346 }
4347
4348 if (flat_in_array == Uninitialized) {
4349 flat_in_array = compute_flat_in_array(ik, xk);
4350 }
4351 // Now hash this baby
4352 TypeInstPtr *result =
4353 (TypeInstPtr*)(new TypeInstPtr(ptr, k, interfaces, xk, o, offset, flat_in_array, instance_id, speculative, inline_depth))->hashcons();
4354
4355 return result;
4356 }
4357
4358 const TypeInterfaces* TypePtr::interfaces(ciKlass*& k, bool klass, bool interface, bool array, InterfaceHandling interface_handling) {
4359 if (k->is_instance_klass()) {
4360 if (k->is_loaded()) {
4361 if (k->is_interface() && interface_handling == ignore_interfaces) {
4362 assert(interface, "no interface expected");
4363 k = ciEnv::current()->Object_klass();
4364 const TypeInterfaces* interfaces = TypeInterfaces::make();
4365 return interfaces;
4366 }
4367 GrowableArray<ciInstanceKlass *>* k_interfaces = k->as_instance_klass()->transitive_interfaces();
4368 const TypeInterfaces* interfaces = TypeInterfaces::make(k_interfaces);
4369 if (k->is_interface()) {
4370 assert(interface, "no interface expected");
4371 k = ciEnv::current()->Object_klass();
4372 } else {
4373 assert(klass, "no instance klass expected");
4374 }
4375 return interfaces;
4376 }
4377 const TypeInterfaces* interfaces = TypeInterfaces::make();
4378 return interfaces;
4379 }
4380 assert(array, "no array expected");
4381 assert(k->is_array_klass(), "Not an array?");
4382 ciType* e = k->as_array_klass()->base_element_type();
4383 if (e->is_loaded() && e->is_instance_klass() && e->as_instance_klass()->is_interface()) {
4384 if (interface_handling == ignore_interfaces) {
4385 k = ciObjArrayKlass::make(ciEnv::current()->Object_klass(), k->as_array_klass()->dimension());
4386 }
4387 }
4388 return TypeAryPtr::_array_interfaces;
4389 }
4390
4391 //------------------------------cast_to_ptr_type-------------------------------
4392 const TypeInstPtr* TypeInstPtr::cast_to_ptr_type(PTR ptr) const {
4393 if( ptr == _ptr ) return this;
4394 // Reconstruct _sig info here since not a problem with later lazy
4395 // construction, _sig will show up on demand.
4396 return make(ptr, klass(), _interfaces, klass_is_exact(), ptr == Constant ? const_oop() : nullptr, _offset, _flat_in_array, _instance_id, _speculative, _inline_depth);
4397 }
4398
4399
4400 //-----------------------------cast_to_exactness-------------------------------
4401 const TypeInstPtr* TypeInstPtr::cast_to_exactness(bool klass_is_exact) const {
4402 if( klass_is_exact == _klass_is_exact ) return this;
4403 if (!_klass->is_loaded()) return this;
4404 ciInstanceKlass* ik = _klass->as_instance_klass();
4405 if( (ik->is_final() || _const_oop) ) return this; // cannot clear xk
4406 assert(!ik->is_interface(), "no interface here");
4407 FlatInArray flat_in_array = compute_flat_in_array(ik, klass_is_exact);
4408 return make(ptr(), klass(), _interfaces, klass_is_exact, const_oop(), _offset, flat_in_array, _instance_id, _speculative, _inline_depth);
4409 }
4410
4411 //-----------------------------cast_to_instance_id----------------------------
4412 const TypeInstPtr* TypeInstPtr::cast_to_instance_id(int instance_id) const {
4413 if( instance_id == _instance_id ) return this;
4414 return make(_ptr, klass(), _interfaces, _klass_is_exact, const_oop(), _offset, _flat_in_array, instance_id, _speculative, _inline_depth);
4415 }
4416
4417 //------------------------------xmeet_unloaded---------------------------------
4418 // Compute the MEET of two InstPtrs when at least one is unloaded.
4419 // Assume classes are different since called after check for same name/class-loader
4420 const TypeInstPtr *TypeInstPtr::xmeet_unloaded(const TypeInstPtr *tinst, const TypeInterfaces* interfaces) const {
4421 Offset off = meet_offset(tinst->offset());
4422 PTR ptr = meet_ptr(tinst->ptr());
4423 int instance_id = meet_instance_id(tinst->instance_id());
4424 const TypePtr* speculative = xmeet_speculative(tinst);
4425 int depth = meet_inline_depth(tinst->inline_depth());
4426
4427 const TypeInstPtr *loaded = is_loaded() ? this : tinst;
4428 const TypeInstPtr *unloaded = is_loaded() ? tinst : this;
4429 if( loaded->klass()->equals(ciEnv::current()->Object_klass()) ) {
4430 //
4431 // Meet unloaded class with java/lang/Object
4432 //
4433 // Meet
4434 // | Unloaded Class
4435 // Object | TOP | AnyNull | Constant | NotNull | BOTTOM |
4436 // ===================================================================
4437 // TOP | ..........................Unloaded......................|
4438 // AnyNull | U-AN |................Unloaded......................|
4439 // Constant | ... O-NN .................................. | O-BOT |
4440 // NotNull | ... O-NN .................................. | O-BOT |
4441 // BOTTOM | ........................Object-BOTTOM ..................|
4442 //
4443 assert(loaded->ptr() != TypePtr::Null, "insanity check");
4444 //
4445 if (loaded->ptr() == TypePtr::TopPTR) { return unloaded->with_speculative(speculative); }
4446 else if (loaded->ptr() == TypePtr::AnyNull) {
4447 FlatInArray flat_in_array = meet_flat_in_array(_flat_in_array, tinst->flat_in_array());
4448 return make(ptr, unloaded->klass(), interfaces, false, nullptr, off, flat_in_array, instance_id,
4449 speculative, depth);
4450 }
4451 else if (loaded->ptr() == TypePtr::BotPTR) { return TypeInstPtr::BOTTOM->with_speculative(speculative); }
4452 else if (loaded->ptr() == TypePtr::Constant || loaded->ptr() == TypePtr::NotNull) {
4453 if (unloaded->ptr() == TypePtr::BotPTR) { return TypeInstPtr::BOTTOM->with_speculative(speculative); }
4454 else { return TypeInstPtr::NOTNULL->with_speculative(speculative); }
4455 }
4456 else if (unloaded->ptr() == TypePtr::TopPTR) { return unloaded->with_speculative(speculative); }
4457
4458 return unloaded->cast_to_ptr_type(TypePtr::AnyNull)->is_instptr()->with_speculative(speculative);
4459 }
4460
4461 // Both are unloaded, not the same class, not Object
4462 // Or meet unloaded with a different loaded class, not java/lang/Object
4463 if (ptr != TypePtr::BotPTR) {
4464 return TypeInstPtr::NOTNULL->with_speculative(speculative);
4465 }
4466 return TypeInstPtr::BOTTOM->with_speculative(speculative);
4467 }
4468
4469
4470 //------------------------------meet-------------------------------------------
4471 // Compute the MEET of two types. It returns a new Type object.
4472 const Type *TypeInstPtr::xmeet_helper(const Type *t) const {
4473 // Perform a fast test for common case; meeting the same types together.
4474 if( this == t ) return this; // Meeting same type-rep?
4475
4476 // Current "this->_base" is Pointer
4477 switch (t->base()) { // switch on original type
4478
4479 case Int: // Mixing ints & oops happens when javac
4480 case Long: // reuses local variables
4481 case HalfFloatTop:
4482 case HalfFloatCon:
4483 case HalfFloatBot:
4484 case FloatTop:
4485 case FloatCon:
4486 case FloatBot:
4487 case DoubleTop:
4488 case DoubleCon:
4489 case DoubleBot:
4490 case NarrowOop:
4491 case NarrowKlass:
4492 case Bottom: // Ye Olde Default
4493 return Type::BOTTOM;
4494 case Top:
4495 return this;
4496
4497 default: // All else is a mistake
4498 typerr(t);
4499
4500 case MetadataPtr:
4501 case KlassPtr:
4502 case InstKlassPtr:
4503 case AryKlassPtr:
4504 case RawPtr: return TypePtr::BOTTOM;
4505
4506 case AryPtr: { // All arrays inherit from Object class
4507 // Call in reverse direction to avoid duplication
4508 return t->is_aryptr()->xmeet_helper(this);
4509 }
4510
4511 case OopPtr: { // Meeting to OopPtrs
4512 // Found a OopPtr type vs self-InstPtr type
4513 const TypeOopPtr *tp = t->is_oopptr();
4514 Offset offset = meet_offset(tp->offset());
4515 PTR ptr = meet_ptr(tp->ptr());
4516 switch (tp->ptr()) {
4517 case TopPTR:
4518 case AnyNull: {
4519 int instance_id = meet_instance_id(InstanceTop);
4520 const TypePtr* speculative = xmeet_speculative(tp);
4521 int depth = meet_inline_depth(tp->inline_depth());
4522 return make(ptr, klass(), _interfaces, klass_is_exact(),
4523 (ptr == Constant ? const_oop() : nullptr), offset, flat_in_array(), instance_id, speculative, depth);
4524 }
4525 case NotNull:
4526 case BotPTR: {
4527 int instance_id = meet_instance_id(tp->instance_id());
4528 const TypePtr* speculative = xmeet_speculative(tp);
4529 int depth = meet_inline_depth(tp->inline_depth());
4530 return TypeOopPtr::make(ptr, offset, instance_id, speculative, depth);
4531 }
4532 default: typerr(t);
4533 }
4534 }
4535
4536 case AnyPtr: { // Meeting to AnyPtrs
4537 // Found an AnyPtr type vs self-InstPtr type
4538 const TypePtr *tp = t->is_ptr();
4539 Offset offset = meet_offset(tp->offset());
4540 PTR ptr = meet_ptr(tp->ptr());
4541 int instance_id = meet_instance_id(InstanceTop);
4542 const TypePtr* speculative = xmeet_speculative(tp);
4543 int depth = meet_inline_depth(tp->inline_depth());
4544 switch (tp->ptr()) {
4545 case Null:
4546 if( ptr == Null ) return TypePtr::make(AnyPtr, ptr, offset, speculative, depth);
4547 // else fall through to AnyNull
4548 case TopPTR:
4549 case AnyNull: {
4550 return make(ptr, klass(), _interfaces, klass_is_exact(),
4551 (ptr == Constant ? const_oop() : nullptr), offset, flat_in_array(), instance_id, speculative, depth);
4552 }
4553 case NotNull:
4554 case BotPTR:
4555 return TypePtr::make(AnyPtr, ptr, offset, speculative,depth);
4556 default: typerr(t);
4557 }
4558 }
4559
4560 /*
4561 A-top }
4562 / | \ } Tops
4563 B-top A-any C-top }
4564 | / | \ | } Any-nulls
4565 B-any | C-any }
4566 | | |
4567 B-con A-con C-con } constants; not comparable across classes
4568 | | |
4569 B-not | C-not }
4570 | \ | / | } not-nulls
4571 B-bot A-not C-bot }
4572 \ | / } Bottoms
4573 A-bot }
4574 */
4575
4576 case InstPtr: { // Meeting 2 Oops?
4577 // Found an InstPtr sub-type vs self-InstPtr type
4578 const TypeInstPtr *tinst = t->is_instptr();
4579 Offset off = meet_offset(tinst->offset());
4580 PTR ptr = meet_ptr(tinst->ptr());
4581 int instance_id = meet_instance_id(tinst->instance_id());
4582 const TypePtr* speculative = xmeet_speculative(tinst);
4583 int depth = meet_inline_depth(tinst->inline_depth());
4584 const TypeInterfaces* interfaces = meet_interfaces(tinst);
4585
4586 ciKlass* tinst_klass = tinst->klass();
4587 ciKlass* this_klass = klass();
4588
4589 ciKlass* res_klass = nullptr;
4590 bool res_xk = false;
4591 const Type* res;
4592 MeetResult kind = meet_instptr(ptr, interfaces, this, tinst, res_klass, res_xk);
4593
4594 if (kind == UNLOADED) {
4595 // One of these classes has not been loaded
4596 const TypeInstPtr* unloaded_meet = xmeet_unloaded(tinst, interfaces);
4597 #ifndef PRODUCT
4598 if (PrintOpto && Verbose) {
4599 tty->print("meet of unloaded classes resulted in: ");
4600 unloaded_meet->dump();
4601 tty->cr();
4602 tty->print(" this == ");
4603 dump();
4604 tty->cr();
4605 tty->print(" tinst == ");
4606 tinst->dump();
4607 tty->cr();
4608 }
4609 #endif
4610 res = unloaded_meet;
4611 } else {
4612 FlatInArray flat_in_array = meet_flat_in_array(_flat_in_array, tinst->flat_in_array());
4613 if (kind == NOT_SUBTYPE && instance_id > 0) {
4614 instance_id = InstanceBot;
4615 } else if (kind == LCA) {
4616 instance_id = InstanceBot;
4617 }
4618 ciObject* o = nullptr; // Assume not constant when done
4619 ciObject* this_oop = const_oop();
4620 ciObject* tinst_oop = tinst->const_oop();
4621 if (ptr == Constant) {
4622 if (this_oop != nullptr && tinst_oop != nullptr &&
4623 this_oop->equals(tinst_oop))
4624 o = this_oop;
4625 else if (above_centerline(_ptr)) {
4626 assert(!tinst_klass->is_interface(), "");
4627 o = tinst_oop;
4628 } else if (above_centerline(tinst->_ptr)) {
4629 assert(!this_klass->is_interface(), "");
4630 o = this_oop;
4631 } else
4632 ptr = NotNull;
4633 }
4634 res = make(ptr, res_klass, interfaces, res_xk, o, off, flat_in_array, instance_id, speculative, depth);
4635 }
4636
4637 return res;
4638
4639 } // End of case InstPtr
4640
4641 } // End of switch
4642 return this; // Return the double constant
4643 }
4644
4645 template<class T> TypePtr::MeetResult TypePtr::meet_instptr(PTR& ptr, const TypeInterfaces*& interfaces, const T* this_type, const T* other_type,
4646 ciKlass*& res_klass, bool& res_xk) {
4647 ciKlass* this_klass = this_type->klass();
4648 ciKlass* other_klass = other_type->klass();
4649
4650 bool this_xk = this_type->klass_is_exact();
4651 bool other_xk = other_type->klass_is_exact();
4652 PTR this_ptr = this_type->ptr();
4653 PTR other_ptr = other_type->ptr();
4654 const TypeInterfaces* this_interfaces = this_type->interfaces();
4655 const TypeInterfaces* other_interfaces = other_type->interfaces();
4656 // Check for easy case; klasses are equal (and perhaps not loaded!)
4657 // If we have constants, then we created oops so classes are loaded
4658 // and we can handle the constants further down. This case handles
4659 // both-not-loaded or both-loaded classes
4660 if (ptr != Constant && this_klass->equals(other_klass) && this_xk == other_xk) {
4661 res_klass = this_klass;
4662 res_xk = this_xk;
4663 return QUICK;
4664 }
4665
4666 // Classes require inspection in the Java klass hierarchy. Must be loaded.
4667 if (!other_klass->is_loaded() || !this_klass->is_loaded()) {
4668 return UNLOADED;
4669 }
4670
4671 // !!! Here's how the symmetry requirement breaks down into invariants:
4672 // If we split one up & one down AND they subtype, take the down man.
4673 // If we split one up & one down AND they do NOT subtype, "fall hard".
4674 // If both are up and they subtype, take the subtype class.
4675 // If both are up and they do NOT subtype, "fall hard".
4676 // If both are down and they subtype, take the supertype class.
4677 // If both are down and they do NOT subtype, "fall hard".
4678 // Constants treated as down.
4679
4680 // Now, reorder the above list; observe that both-down+subtype is also
4681 // "fall hard"; "fall hard" becomes the default case:
4682 // If we split one up & one down AND they subtype, take the down man.
4683 // If both are up and they subtype, take the subtype class.
4684
4685 // If both are down and they subtype, "fall hard".
4686 // If both are down and they do NOT subtype, "fall hard".
4687 // If both are up and they do NOT subtype, "fall hard".
4688 // If we split one up & one down AND they do NOT subtype, "fall hard".
4689
4690 // If a proper subtype is exact, and we return it, we return it exactly.
4691 // If a proper supertype is exact, there can be no subtyping relationship!
4692 // If both types are equal to the subtype, exactness is and-ed below the
4693 // centerline and or-ed above it. (N.B. Constants are always exact.)
4694
4695 const T* subtype = nullptr;
4696 bool subtype_exact = false;
4697 if (this_type->is_same_java_type_as(other_type)) {
4698 // Same klass
4699 subtype = this_type;
4700 subtype_exact = below_centerline(ptr) ? (this_xk && other_xk) : (this_xk || other_xk);
4701 } else if (!other_xk && this_type->is_meet_subtype_of(other_type)) {
4702 subtype = this_type; // Pick subtyping class
4703 subtype_exact = this_xk;
4704 } else if (!this_xk && other_type->is_meet_subtype_of(this_type)) {
4705 subtype = other_type; // Pick subtyping class
4706 subtype_exact = other_xk;
4707 }
4708
4709 if (subtype != nullptr) {
4710 if (above_centerline(ptr)) {
4711 // Both types are empty.
4712 this_type = other_type = subtype;
4713 this_xk = other_xk = subtype_exact;
4714 } else if (above_centerline(this_ptr) && !above_centerline(other_ptr)) {
4715 // this_type is empty while other_type is not. Take other_type.
4716 this_type = other_type;
4717 this_xk = other_xk;
4718 } else if (above_centerline(other_ptr) && !above_centerline(this_ptr)) {
4719 // other_type is empty while this_type is not. Take this_type.
4720 other_type = this_type; // this is down; keep down man
4721 } else {
4722 // this_type and other_type are both non-empty.
4723 this_xk = subtype_exact; // either they are equal, or we'll do an LCA
4724 }
4725 }
4726
4727 // Check for classes now being equal
4728 if (this_type->is_same_java_type_as(other_type)) {
4729 // If the klasses are equal, the constants may still differ. Fall to
4730 // NotNull if they do (neither constant is null; that is a special case
4731 // handled elsewhere).
4732 res_klass = this_type->klass();
4733 res_xk = this_xk;
4734 return SUBTYPE;
4735 } // Else classes are not equal
4736
4737 // Since klasses are different, we require a LCA in the Java
4738 // class hierarchy - which means we have to fall to at least NotNull.
4739 if (ptr == TopPTR || ptr == AnyNull || ptr == Constant) {
4740 ptr = NotNull;
4741 }
4742
4743 interfaces = this_interfaces->intersection_with(other_interfaces);
4744
4745 // Now we find the LCA of Java classes
4746 ciKlass* k = this_klass->least_common_ancestor(other_klass);
4747
4748 res_klass = k;
4749 res_xk = false;
4750 return LCA;
4751 }
4752
4753 // Top-Flat Flat Not-Flat Maybe-Flat
4754 // -------------------------------------------------------------
4755 // Top-Flat Top-Flat Flat Not-Flat Maybe-Flat
4756 // Flat Flat Flat Maybe-Flat Maybe-Flat
4757 // Not-Flat Not-Flat Maybe-Flat Not-Flat Maybe-Flat
4758 // Maybe-Flat Maybe-Flat Maybe-Flat Maybe-Flat Maybe-flat
4759 TypePtr::FlatInArray TypePtr::meet_flat_in_array(const FlatInArray left, const FlatInArray right) {
4760 if (left == TopFlat) {
4761 return right;
4762 }
4763 if (right == TopFlat) {
4764 return left;
4765 }
4766 if (left == MaybeFlat || right == MaybeFlat) {
4767 return MaybeFlat;
4768 }
4769
4770 switch (left) {
4771 case Flat:
4772 if (right == Flat) {
4773 return Flat;
4774 }
4775 return MaybeFlat;
4776 case NotFlat:
4777 if (right == NotFlat) {
4778 return NotFlat;
4779 }
4780 return MaybeFlat;
4781 default:
4782 ShouldNotReachHere();
4783 return Uninitialized;
4784 }
4785 }
4786
4787 //------------------------java_mirror_type--------------------------------------
4788 ciType* TypeInstPtr::java_mirror_type() const {
4789 // must be a singleton type
4790 if( const_oop() == nullptr ) return nullptr;
4791
4792 // must be of type java.lang.Class
4793 if( klass() != ciEnv::current()->Class_klass() ) return nullptr;
4794 return const_oop()->as_instance()->java_mirror_type();
4795 }
4796
4797
4798 //------------------------------xdual------------------------------------------
4799 // Dual: do NOT dual on klasses. This means I do NOT understand the Java
4800 // inheritance mechanism.
4801 const Type* TypeInstPtr::xdual() const {
4802 return new TypeInstPtr(dual_ptr(), klass(), _interfaces, klass_is_exact(), const_oop(), dual_offset(),
4803 dual_flat_in_array(), dual_instance_id(), dual_speculative(), dual_inline_depth());
4804 }
4805
4806 //------------------------------eq---------------------------------------------
4807 // Structural equality check for Type representations
4808 bool TypeInstPtr::eq( const Type *t ) const {
4809 const TypeInstPtr *p = t->is_instptr();
4810 return
4811 klass()->equals(p->klass()) &&
4812 _flat_in_array == p->_flat_in_array &&
4813 _interfaces->eq(p->_interfaces) &&
4814 TypeOopPtr::eq(p); // Check sub-type stuff
4815 }
4816
4817 //------------------------------hash-------------------------------------------
4818 // Type-specific hashing function.
4819 uint TypeInstPtr::hash() const {
4820 return klass()->hash() + TypeOopPtr::hash() + _interfaces->hash() + static_cast<uint>(_flat_in_array);
4821 }
4822
4823 bool TypeInstPtr::is_java_subtype_of_helper(const TypeOopPtr* other, bool this_exact, bool other_exact) const {
4824 return TypePtr::is_java_subtype_of_helper_for_instance(this, other, this_exact, other_exact);
4825 }
4826
4827
4828 bool TypeInstPtr::is_same_java_type_as_helper(const TypeOopPtr* other) const {
4829 return TypePtr::is_same_java_type_as_helper_for_instance(this, other);
4830 }
4831
4832 bool TypeInstPtr::maybe_java_subtype_of_helper(const TypeOopPtr* other, bool this_exact, bool other_exact) const {
4833 return TypePtr::maybe_java_subtype_of_helper_for_instance(this, other, this_exact, other_exact);
4834 }
4835
4836
4837 //------------------------------dump2------------------------------------------
4838 // Dump oop Type
4839 #ifndef PRODUCT
4840 void TypeInstPtr::dump2(Dict &d, uint depth, outputStream* st) const {
4841 // Print the name of the klass.
4842 st->print("instptr:");
4843 klass()->print_name_on(st);
4844 _interfaces->dump(st);
4845
4846 if (_ptr == Constant && (WizardMode || Verbose)) {
4847 ResourceMark rm;
4848 stringStream ss;
4849
4850 st->print(" ");
4851 const_oop()->print_oop(&ss);
4852 // 'const_oop->print_oop()' may emit newlines('\n') into ss.
4853 // suppress newlines from it so -XX:+Verbose -XX:+PrintIdeal dumps one-liner for each node.
4854 char* buf = ss.as_string(/* c_heap= */false);
4855 StringUtils::replace_no_expand(buf, "\n", "");
4856 st->print_raw(buf);
4857 }
4858
4859 st->print(":%s", ptr_msg[_ptr]);
4860 if (_klass_is_exact) {
4861 st->print(":exact");
4862 }
4863
4864 st->print(" *");
4865
4866 dump_offset(st);
4867 dump_instance_id(st);
4868 dump_inline_depth(st);
4869 dump_speculative(st);
4870 dump_flat_in_array(_flat_in_array, st);
4871 }
4872 #endif
4873
4874 bool TypeInstPtr::empty() const {
4875 if (_flat_in_array == TopFlat) {
4876 return true;
4877 }
4878 return TypeOopPtr::empty();
4879 }
4880
4881 //------------------------------add_offset-------------------------------------
4882 const TypePtr* TypeInstPtr::add_offset(intptr_t offset) const {
4883 return make(_ptr, klass(), _interfaces, klass_is_exact(), const_oop(), xadd_offset(offset), _flat_in_array,
4884 _instance_id, add_offset_speculative(offset), _inline_depth);
4885 }
4886
4887 const TypeInstPtr* TypeInstPtr::with_offset(intptr_t offset) const {
4888 return make(_ptr, klass(), _interfaces, klass_is_exact(), const_oop(), Offset(offset), _flat_in_array,
4889 _instance_id, with_offset_speculative(offset), _inline_depth);
4890 }
4891
4892 const TypeInstPtr* TypeInstPtr::remove_speculative() const {
4893 if (_speculative == nullptr) {
4894 return this;
4895 }
4896 assert(_inline_depth == InlineDepthTop || _inline_depth == InlineDepthBottom, "non speculative type shouldn't have inline depth");
4897 return make(_ptr, klass(), _interfaces, klass_is_exact(), const_oop(), _offset, _flat_in_array,
4898 _instance_id, nullptr, _inline_depth);
4899 }
4900
4901 const TypeInstPtr* TypeInstPtr::with_speculative(const TypePtr* speculative) const {
4902 return make(_ptr, klass(), _interfaces, klass_is_exact(), const_oop(), _offset, _flat_in_array, _instance_id, speculative, _inline_depth);
4903 }
4904
4905 const TypePtr* TypeInstPtr::with_inline_depth(int depth) const {
4906 if (!UseInlineDepthForSpeculativeTypes) {
4907 return this;
4908 }
4909 return make(_ptr, klass(), _interfaces, klass_is_exact(), const_oop(), _offset, _flat_in_array, _instance_id, _speculative, depth);
4910 }
4911
4912 const TypePtr* TypeInstPtr::with_instance_id(int instance_id) const {
4913 assert(is_known_instance(), "should be known");
4914 return make(_ptr, klass(), _interfaces, klass_is_exact(), const_oop(), _offset, _flat_in_array, instance_id, _speculative, _inline_depth);
4915 }
4916
4917 const TypeInstPtr *TypeInstPtr::cast_to_flat_in_array() const {
4918 return make(_ptr, klass(), _interfaces, klass_is_exact(), const_oop(), _offset, Flat, _instance_id, _speculative, _inline_depth);
4919 }
4920
4921 const TypeInstPtr *TypeInstPtr::cast_to_maybe_flat_in_array() const {
4922 return make(_ptr, klass(), _interfaces, klass_is_exact(), const_oop(), _offset, MaybeFlat, _instance_id, _speculative, _inline_depth);
4923 }
4924
4925 const TypeKlassPtr* TypeInstPtr::as_klass_type(bool try_for_exact) const {
4926 bool xk = klass_is_exact();
4927 ciInstanceKlass* ik = klass()->as_instance_klass();
4928 if (try_for_exact && !xk && !ik->has_subklass() && !ik->is_final()) {
4929 if (_interfaces->eq(ik)) {
4930 Compile* C = Compile::current();
4931 Dependencies* deps = C->dependencies();
4932 deps->assert_leaf_type(ik);
4933 xk = true;
4934 }
4935 }
4936 FlatInArray flat_in_array = compute_flat_in_array_if_unknown(ik, xk, _flat_in_array);
4937 return TypeInstKlassPtr::make(xk ? TypePtr::Constant : TypePtr::NotNull, klass(), _interfaces, Offset(0), flat_in_array);
4938 }
4939
4940 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) {
4941 static_assert(std::is_base_of<T2, T1>::value, "");
4942
4943 if (!this_one->is_instance_type(other)) {
4944 return false;
4945 }
4946
4947 if (other->klass() == ciEnv::current()->Object_klass() && other->_interfaces->empty()) {
4948 return true;
4949 }
4950
4951 return this_one->klass()->is_subtype_of(other->klass()) &&
4952 (!this_xk || this_one->_interfaces->contains(other->_interfaces));
4953 }
4954
4955
4956 bool TypeInstPtr::is_meet_subtype_of_helper(const TypeOopPtr *other, bool this_xk, bool other_xk) const {
4957 return TypePtr::is_meet_subtype_of_helper_for_instance(this, other, this_xk, other_xk);
4958 }
4959
4960 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) {
4961 static_assert(std::is_base_of<T2, T1>::value, "");
4962 if (other->klass() == ciEnv::current()->Object_klass() && other->_interfaces->empty()) {
4963 return true;
4964 }
4965
4966 if (this_one->is_instance_type(other)) {
4967 return other->klass() == ciEnv::current()->Object_klass() && this_one->_interfaces->contains(other->_interfaces);
4968 }
4969
4970 int dummy;
4971 bool this_top_or_bottom = (this_one->base_element_type(dummy) == Type::TOP || this_one->base_element_type(dummy) == Type::BOTTOM);
4972 if (this_top_or_bottom) {
4973 return false;
4974 }
4975
4976 const T1* other_ary = this_one->is_array_type(other);
4977 const TypePtr* other_elem = other_ary->elem()->make_ptr();
4978 const TypePtr* this_elem = this_one->elem()->make_ptr();
4979 if (other_elem != nullptr && this_elem != nullptr) {
4980 return this_one->is_reference_type(this_elem)->is_meet_subtype_of_helper(this_one->is_reference_type(other_elem), this_xk, other_xk);
4981 }
4982 if (other_elem == nullptr && this_elem == nullptr) {
4983 return this_one->klass()->is_subtype_of(other->klass());
4984 }
4985
4986 return false;
4987 }
4988
4989 bool TypeAryPtr::is_meet_subtype_of_helper(const TypeOopPtr *other, bool this_xk, bool other_xk) const {
4990 return TypePtr::is_meet_subtype_of_helper_for_array(this, other, this_xk, other_xk);
4991 }
4992
4993 bool TypeInstKlassPtr::is_meet_subtype_of_helper(const TypeKlassPtr *other, bool this_xk, bool other_xk) const {
4994 return TypePtr::is_meet_subtype_of_helper_for_instance(this, other, this_xk, other_xk);
4995 }
4996
4997 bool TypeAryKlassPtr::is_meet_subtype_of_helper(const TypeKlassPtr *other, bool this_xk, bool other_xk) const {
4998 return TypePtr::is_meet_subtype_of_helper_for_array(this, other, this_xk, other_xk);
4999 }
5000
5001 //=============================================================================
5002 // Convenience common pre-built types.
5003 const TypeAryPtr* TypeAryPtr::BOTTOM;
5004 const TypeAryPtr *TypeAryPtr::RANGE;
5005 const TypeAryPtr *TypeAryPtr::OOPS;
5006 const TypeAryPtr *TypeAryPtr::NARROWOOPS;
5007 const TypeAryPtr *TypeAryPtr::BYTES;
5008 const TypeAryPtr *TypeAryPtr::SHORTS;
5009 const TypeAryPtr *TypeAryPtr::CHARS;
5010 const TypeAryPtr *TypeAryPtr::INTS;
5011 const TypeAryPtr *TypeAryPtr::LONGS;
5012 const TypeAryPtr *TypeAryPtr::FLOATS;
5013 const TypeAryPtr *TypeAryPtr::DOUBLES;
5014 const TypeAryPtr *TypeAryPtr::INLINES;
5015
5016 //------------------------------make-------------------------------------------
5017 const TypeAryPtr* TypeAryPtr::make(PTR ptr, const TypeAry *ary, ciKlass* k, bool xk, Offset offset, Offset field_offset,
5018 int instance_id, const TypePtr* speculative, int inline_depth) {
5019 assert(!(k == nullptr && ary->_elem->isa_int()),
5020 "integral arrays must be pre-equipped with a class");
5021 if (!xk) xk = ary->ary_must_be_exact();
5022 assert(instance_id <= 0 || xk, "instances are always exactly typed");
5023 if (k != nullptr && k->is_loaded() && k->is_obj_array_klass() &&
5024 k->as_obj_array_klass()->base_element_klass()->is_interface()) {
5025 k = nullptr;
5026 }
5027 return (TypeAryPtr*)(new TypeAryPtr(ptr, nullptr, ary, k, xk, offset, field_offset, instance_id, false, speculative, inline_depth))->hashcons();
5028 }
5029
5030 //------------------------------make-------------------------------------------
5031 const TypeAryPtr* TypeAryPtr::make(PTR ptr, ciObject* o, const TypeAry *ary, ciKlass* k, bool xk, Offset offset, Offset field_offset,
5032 int instance_id, const TypePtr* speculative, int inline_depth,
5033 bool is_autobox_cache) {
5034 assert(!(k == nullptr && ary->_elem->isa_int()),
5035 "integral arrays must be pre-equipped with a class");
5036 assert( (ptr==Constant && o) || (ptr!=Constant && !o), "" );
5037 if (!xk) xk = (o != nullptr) || ary->ary_must_be_exact();
5038 assert(instance_id <= 0 || xk, "instances are always exactly typed");
5039 if (k != nullptr && k->is_loaded() && k->is_obj_array_klass() &&
5040 k->as_obj_array_klass()->base_element_klass()->is_interface()) {
5041 k = nullptr;
5042 }
5043 return (TypeAryPtr*)(new TypeAryPtr(ptr, o, ary, k, xk, offset, field_offset, instance_id, is_autobox_cache, speculative, inline_depth))->hashcons();
5044 }
5045
5046 //------------------------------cast_to_ptr_type-------------------------------
5047 const TypeAryPtr* TypeAryPtr::cast_to_ptr_type(PTR ptr) const {
5048 if( ptr == _ptr ) return this;
5049 return make(ptr, ptr == Constant ? const_oop() : nullptr, _ary, klass(), klass_is_exact(), _offset, _field_offset, _instance_id, _speculative, _inline_depth, _is_autobox_cache);
5050 }
5051
5052
5053 //-----------------------------cast_to_exactness-------------------------------
5054 const TypeAryPtr* TypeAryPtr::cast_to_exactness(bool klass_is_exact) const {
5055 if( klass_is_exact == _klass_is_exact ) return this;
5056 if (_ary->ary_must_be_exact()) return this; // cannot clear xk
5057 return make(ptr(), const_oop(), _ary, klass(), klass_is_exact, _offset, _field_offset, _instance_id, _speculative, _inline_depth, _is_autobox_cache);
5058 }
5059
5060 //-----------------------------cast_to_instance_id----------------------------
5061 const TypeAryPtr* TypeAryPtr::cast_to_instance_id(int instance_id) const {
5062 if( instance_id == _instance_id ) return this;
5063 return make(_ptr, const_oop(), _ary, klass(), _klass_is_exact, _offset, _field_offset, instance_id, _speculative, _inline_depth, _is_autobox_cache);
5064 }
5065
5066
5067 //-----------------------------max_array_length-------------------------------
5068 // A wrapper around arrayOopDesc::max_array_length(etype) with some input normalization.
5069 jint TypeAryPtr::max_array_length(BasicType etype) {
5070 if (!is_java_primitive(etype) && !::is_reference_type(etype)) {
5071 if (etype == T_NARROWOOP) {
5072 etype = T_OBJECT;
5073 } else if (etype == T_ILLEGAL) { // bottom[]
5074 etype = T_BYTE; // will produce conservatively high value
5075 } else {
5076 fatal("not an element type: %s", type2name(etype));
5077 }
5078 }
5079 return arrayOopDesc::max_array_length(etype);
5080 }
5081
5082 //-----------------------------narrow_size_type-------------------------------
5083 // Narrow the given size type to the index range for the given array base type.
5084 // Return null if the resulting int type becomes empty.
5085 const TypeInt* TypeAryPtr::narrow_size_type(const TypeInt* size) const {
5086 jint hi = size->_hi;
5087 jint lo = size->_lo;
5088 jint min_lo = 0;
5089 jint max_hi = max_array_length(elem()->array_element_basic_type());
5090 //if (index_not_size) --max_hi; // type of a valid array index, FTR
5091 bool chg = false;
5092 if (lo < min_lo) {
5093 lo = min_lo;
5094 if (size->is_con()) {
5095 hi = lo;
5096 }
5097 chg = true;
5098 }
5099 if (hi > max_hi) {
5100 hi = max_hi;
5101 if (size->is_con()) {
5102 lo = hi;
5103 }
5104 chg = true;
5105 }
5106 // Negative length arrays will produce weird intermediate dead fast-path code
5107 if (lo > hi) {
5108 return TypeInt::ZERO;
5109 }
5110 if (!chg) {
5111 return size;
5112 }
5113 return TypeInt::make(lo, hi, Type::WidenMin);
5114 }
5115
5116 //-------------------------------cast_to_size----------------------------------
5117 const TypeAryPtr* TypeAryPtr::cast_to_size(const TypeInt* new_size) const {
5118 assert(new_size != nullptr, "");
5119 new_size = narrow_size_type(new_size);
5120 if (new_size == size()) return this;
5121 const TypeAry* new_ary = TypeAry::make(elem(), new_size, is_stable(), is_flat(), is_not_flat(), is_not_null_free(), is_atomic());
5122 return make(ptr(), const_oop(), new_ary, klass(), klass_is_exact(), _offset, _field_offset, _instance_id, _speculative, _inline_depth, _is_autobox_cache);
5123 }
5124
5125 const TypeAryPtr* TypeAryPtr::cast_to_flat(bool flat) const {
5126 if (flat == is_flat()) {
5127 return this;
5128 }
5129 assert(!flat || !is_not_flat(), "inconsistency");
5130 const TypeAry* new_ary = TypeAry::make(elem(), size(), is_stable(), flat, is_not_flat(), is_not_null_free(), is_atomic());
5131 const TypeAryPtr* res = make(ptr(), const_oop(), new_ary, klass(), klass_is_exact(), _offset, _field_offset, _instance_id, _speculative, _inline_depth, _is_autobox_cache);
5132 if (res->speculative() == res->remove_speculative()) {
5133 return res->remove_speculative();
5134 }
5135 return res;
5136 }
5137
5138 //-------------------------------cast_to_not_flat------------------------------
5139 const TypeAryPtr* TypeAryPtr::cast_to_not_flat(bool not_flat) const {
5140 if (not_flat == is_not_flat()) {
5141 return this;
5142 }
5143 assert(!not_flat || !is_flat(), "inconsistency");
5144 const TypeAry* new_ary = TypeAry::make(elem(), size(), is_stable(), is_flat(), not_flat, is_not_null_free(), is_atomic());
5145 const TypeAryPtr* res = make(ptr(), const_oop(), new_ary, klass(), klass_is_exact(), _offset, _field_offset, _instance_id, _speculative, _inline_depth, _is_autobox_cache);
5146 // We keep the speculative part if it contains information about flat-/nullability.
5147 // Make sure it's removed if it's not better than the non-speculative type anymore.
5148 if (res->speculative() == res->remove_speculative()) {
5149 return res->remove_speculative();
5150 }
5151 return res;
5152 }
5153
5154 const TypeAryPtr* TypeAryPtr::cast_to_null_free(bool null_free) const {
5155 if (null_free == is_null_free()) {
5156 return this;
5157 }
5158 assert(!null_free || !is_not_null_free(), "inconsistency");
5159 const Type* elem = this->elem();
5160 const Type* new_elem = elem->make_ptr();
5161 if (null_free) {
5162 new_elem = new_elem->join_speculative(TypePtr::NOTNULL);
5163 } else {
5164 new_elem = new_elem->meet_speculative(TypePtr::NULL_PTR);
5165 }
5166 new_elem = elem->isa_narrowoop() ? new_elem->make_narrowoop() : new_elem;
5167 const TypeAry* new_ary = TypeAry::make(new_elem, size(), is_stable(), is_flat(), is_not_flat(), is_not_null_free(), is_atomic());
5168 const TypeAryPtr* res = make(ptr(), const_oop(), new_ary, klass(), klass_is_exact(), _offset, _field_offset, _instance_id, _speculative, _inline_depth, _is_autobox_cache);
5169 if (res->speculative() == res->remove_speculative()) {
5170 return res->remove_speculative();
5171 }
5172 assert(res->speculative() == nullptr || res->speculative()->with_inline_depth(res->inline_depth())->higher_equal(res->remove_speculative()),
5173 "speculative type must not be narrower than non-speculative type");
5174 return res;
5175 }
5176
5177 //-------------------------------cast_to_not_null_free-------------------------
5178 const TypeAryPtr* TypeAryPtr::cast_to_not_null_free(bool not_null_free) const {
5179 if (not_null_free == is_not_null_free()) {
5180 return this;
5181 }
5182 assert(!not_null_free || !is_null_free(), "inconsistency");
5183 const TypeAry* new_ary = TypeAry::make(elem(), size(), is_stable(), is_flat(), is_not_flat(), not_null_free, is_atomic());
5184 const TypePtr* new_spec = _speculative;
5185 if (new_spec != nullptr) {
5186 // Could be 'null free' from profiling, which would contradict the cast.
5187 new_spec = new_spec->is_aryptr()->cast_to_null_free(false)->cast_to_not_null_free();
5188 }
5189 const TypeAryPtr* res = make(ptr(), const_oop(), new_ary, klass(), klass_is_exact(), _offset, _field_offset,
5190 _instance_id, new_spec, _inline_depth, _is_autobox_cache);
5191 // We keep the speculative part if it contains information about flat-/nullability.
5192 // Make sure it's removed if it's not better than the non-speculative type anymore.
5193 if (res->speculative() == res->remove_speculative()) {
5194 return res->remove_speculative();
5195 }
5196 assert(res->speculative() == nullptr || res->speculative()->with_inline_depth(res->inline_depth())->higher_equal(res->remove_speculative()),
5197 "speculative type must not be narrower than non-speculative type");
5198 return res;
5199 }
5200
5201 //---------------------------------update_properties---------------------------
5202 const TypeAryPtr* TypeAryPtr::update_properties(const TypeAryPtr* from) const {
5203 if ((from->is_flat() && is_not_flat()) ||
5204 (from->is_not_flat() && is_flat()) ||
5205 (from->is_null_free() && is_not_null_free()) ||
5206 (from->is_not_null_free() && is_null_free())) {
5207 return nullptr; // Inconsistent properties
5208 }
5209 const TypeAryPtr* res = this;
5210 if (from->is_not_null_free()) {
5211 res = res->cast_to_not_null_free();
5212 }
5213 if (from->is_not_flat()) {
5214 res = res->cast_to_not_flat();
5215 }
5216 return res;
5217 }
5218
5219 jint TypeAryPtr::flat_layout_helper() const {
5220 return exact_klass()->as_flat_array_klass()->layout_helper();
5221 }
5222
5223 int TypeAryPtr::flat_elem_size() const {
5224 return exact_klass()->as_flat_array_klass()->element_byte_size();
5225 }
5226
5227 int TypeAryPtr::flat_log_elem_size() const {
5228 return exact_klass()->as_flat_array_klass()->log2_element_size();
5229 }
5230
5231 //------------------------------cast_to_stable---------------------------------
5232 const TypeAryPtr* TypeAryPtr::cast_to_stable(bool stable, int stable_dimension) const {
5233 if (stable_dimension <= 0 || (stable_dimension == 1 && stable == this->is_stable()))
5234 return this;
5235
5236 const Type* elem = this->elem();
5237 const TypePtr* elem_ptr = elem->make_ptr();
5238
5239 if (stable_dimension > 1 && elem_ptr != nullptr && elem_ptr->isa_aryptr()) {
5240 // If this is widened from a narrow oop, TypeAry::make will re-narrow it.
5241 elem = elem_ptr = elem_ptr->is_aryptr()->cast_to_stable(stable, stable_dimension - 1);
5242 }
5243
5244 const TypeAry* new_ary = TypeAry::make(elem, size(), stable, is_flat(), is_not_flat(), is_not_null_free(), is_atomic());
5245
5246 return make(ptr(), const_oop(), new_ary, klass(), klass_is_exact(), _offset, _field_offset, _instance_id, _speculative, _inline_depth, _is_autobox_cache);
5247 }
5248
5249 //-----------------------------stable_dimension--------------------------------
5250 int TypeAryPtr::stable_dimension() const {
5251 if (!is_stable()) return 0;
5252 int dim = 1;
5253 const TypePtr* elem_ptr = elem()->make_ptr();
5254 if (elem_ptr != nullptr && elem_ptr->isa_aryptr())
5255 dim += elem_ptr->is_aryptr()->stable_dimension();
5256 return dim;
5257 }
5258
5259 //----------------------cast_to_autobox_cache-----------------------------------
5260 const TypeAryPtr* TypeAryPtr::cast_to_autobox_cache() const {
5261 if (is_autobox_cache()) return this;
5262 const TypeOopPtr* etype = elem()->make_oopptr();
5263 if (etype == nullptr) return this;
5264 // The pointers in the autobox arrays are always non-null.
5265 etype = etype->cast_to_ptr_type(TypePtr::NotNull)->is_oopptr();
5266 const TypeAry* new_ary = TypeAry::make(etype, size(), is_stable(), is_flat(), is_not_flat(), is_not_null_free(), is_atomic());
5267 return make(ptr(), const_oop(), new_ary, klass(), klass_is_exact(), _offset, _field_offset, _instance_id, _speculative, _inline_depth, /*is_autobox_cache=*/true);
5268 }
5269
5270 //------------------------------eq---------------------------------------------
5271 // Structural equality check for Type representations
5272 bool TypeAryPtr::eq( const Type *t ) const {
5273 const TypeAryPtr *p = t->is_aryptr();
5274 return
5275 _ary == p->_ary && // Check array
5276 TypeOopPtr::eq(p) &&// Check sub-parts
5277 _field_offset == p->_field_offset;
5278 }
5279
5280 //------------------------------hash-------------------------------------------
5281 // Type-specific hashing function.
5282 uint TypeAryPtr::hash(void) const {
5283 return (uint)(uintptr_t)_ary + TypeOopPtr::hash() + _field_offset.get();
5284 }
5285
5286 bool TypeAryPtr::is_java_subtype_of_helper(const TypeOopPtr* other, bool this_exact, bool other_exact) const {
5287 return TypePtr::is_java_subtype_of_helper_for_array(this, other, this_exact, other_exact);
5288 }
5289
5290 bool TypeAryPtr::is_same_java_type_as_helper(const TypeOopPtr* other) const {
5291 return TypePtr::is_same_java_type_as_helper_for_array(this, other);
5292 }
5293
5294 bool TypeAryPtr::maybe_java_subtype_of_helper(const TypeOopPtr* other, bool this_exact, bool other_exact) const {
5295 return TypePtr::maybe_java_subtype_of_helper_for_array(this, other, this_exact, other_exact);
5296 }
5297 //------------------------------meet-------------------------------------------
5298 // Compute the MEET of two types. It returns a new Type object.
5299 const Type *TypeAryPtr::xmeet_helper(const Type *t) const {
5300 // Perform a fast test for common case; meeting the same types together.
5301 if( this == t ) return this; // Meeting same type-rep?
5302 // Current "this->_base" is Pointer
5303 switch (t->base()) { // switch on original type
5304
5305 // Mixing ints & oops happens when javac reuses local variables
5306 case Int:
5307 case Long:
5308 case HalfFloatTop:
5309 case HalfFloatCon:
5310 case HalfFloatBot:
5311 case FloatTop:
5312 case FloatCon:
5313 case FloatBot:
5314 case DoubleTop:
5315 case DoubleCon:
5316 case DoubleBot:
5317 case NarrowOop:
5318 case NarrowKlass:
5319 case Bottom: // Ye Olde Default
5320 return Type::BOTTOM;
5321 case Top:
5322 return this;
5323
5324 default: // All else is a mistake
5325 typerr(t);
5326
5327 case OopPtr: { // Meeting to OopPtrs
5328 // Found a OopPtr type vs self-AryPtr type
5329 const TypeOopPtr *tp = t->is_oopptr();
5330 Offset offset = meet_offset(tp->offset());
5331 PTR ptr = meet_ptr(tp->ptr());
5332 int depth = meet_inline_depth(tp->inline_depth());
5333 const TypePtr* speculative = xmeet_speculative(tp);
5334 switch (tp->ptr()) {
5335 case TopPTR:
5336 case AnyNull: {
5337 int instance_id = meet_instance_id(InstanceTop);
5338 return make(ptr, (ptr == Constant ? const_oop() : nullptr),
5339 _ary, _klass, _klass_is_exact, offset, _field_offset, instance_id, speculative, depth);
5340 }
5341 case BotPTR:
5342 case NotNull: {
5343 int instance_id = meet_instance_id(tp->instance_id());
5344 return TypeOopPtr::make(ptr, offset, instance_id, speculative, depth);
5345 }
5346 default: ShouldNotReachHere();
5347 }
5348 }
5349
5350 case AnyPtr: { // Meeting two AnyPtrs
5351 // Found an AnyPtr type vs self-AryPtr type
5352 const TypePtr *tp = t->is_ptr();
5353 Offset offset = meet_offset(tp->offset());
5354 PTR ptr = meet_ptr(tp->ptr());
5355 const TypePtr* speculative = xmeet_speculative(tp);
5356 int depth = meet_inline_depth(tp->inline_depth());
5357 switch (tp->ptr()) {
5358 case TopPTR:
5359 return this;
5360 case BotPTR:
5361 case NotNull:
5362 return TypePtr::make(AnyPtr, ptr, offset, speculative, depth);
5363 case Null:
5364 if( ptr == Null ) return TypePtr::make(AnyPtr, ptr, offset, speculative, depth);
5365 // else fall through to AnyNull
5366 case AnyNull: {
5367 int instance_id = meet_instance_id(InstanceTop);
5368 return make(ptr, (ptr == Constant ? const_oop() : nullptr),
5369 _ary, _klass, _klass_is_exact, offset, _field_offset, instance_id, speculative, depth);
5370 }
5371 default: ShouldNotReachHere();
5372 }
5373 }
5374
5375 case MetadataPtr:
5376 case KlassPtr:
5377 case InstKlassPtr:
5378 case AryKlassPtr:
5379 case RawPtr: return TypePtr::BOTTOM;
5380
5381 case AryPtr: { // Meeting 2 references?
5382 const TypeAryPtr *tap = t->is_aryptr();
5383 Offset off = meet_offset(tap->offset());
5384 Offset field_off = meet_field_offset(tap->field_offset());
5385 const Type* tm = _ary->meet_speculative(tap->_ary);
5386 const TypeAry* tary = tm->isa_ary();
5387 if (tary == nullptr) {
5388 assert(tm == Type::TOP || tm == Type::BOTTOM, "");
5389 return tm;
5390 }
5391 PTR ptr = meet_ptr(tap->ptr());
5392 int instance_id = meet_instance_id(tap->instance_id());
5393 const TypePtr* speculative = xmeet_speculative(tap);
5394 int depth = meet_inline_depth(tap->inline_depth());
5395
5396 ciKlass* res_klass = nullptr;
5397 bool res_xk = false;
5398 bool res_flat = false;
5399 bool res_not_flat = false;
5400 bool res_not_null_free = false;
5401 bool res_atomic = false;
5402 const Type* elem = tary->_elem;
5403 if (meet_aryptr(ptr, elem, this, tap, res_klass, res_xk, res_flat, res_not_flat, res_not_null_free, res_atomic) == NOT_SUBTYPE) {
5404 instance_id = InstanceBot;
5405 } else if (this->is_flat() != tap->is_flat()) {
5406 // Meeting flat inline type array with non-flat array. Adjust (field) offset accordingly.
5407 if (tary->_flat) {
5408 // Result is in a flat representation
5409 off = Offset(is_flat() ? offset() : tap->offset());
5410 field_off = is_flat() ? field_offset() : tap->field_offset();
5411 } else if (below_centerline(ptr)) {
5412 // Result is in a non-flat representation
5413 off = Offset(flat_offset()).meet(Offset(tap->flat_offset()));
5414 field_off = (field_off == Offset::top) ? Offset::top : Offset::bottom;
5415 } else if (flat_offset() == tap->flat_offset()) {
5416 off = Offset(!is_flat() ? offset() : tap->offset());
5417 field_off = !is_flat() ? field_offset() : tap->field_offset();
5418 }
5419 }
5420
5421 ciObject* o = nullptr; // Assume not constant when done
5422 ciObject* this_oop = const_oop();
5423 ciObject* tap_oop = tap->const_oop();
5424 if (ptr == Constant) {
5425 if (this_oop != nullptr && tap_oop != nullptr &&
5426 this_oop->equals(tap_oop)) {
5427 o = tap_oop;
5428 } else if (above_centerline(_ptr)) {
5429 o = tap_oop;
5430 } else if (above_centerline(tap->_ptr)) {
5431 o = this_oop;
5432 } else {
5433 ptr = NotNull;
5434 }
5435 }
5436 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);
5437 }
5438
5439 // All arrays inherit from Object class
5440 case InstPtr: {
5441 const TypeInstPtr *tp = t->is_instptr();
5442 Offset offset = meet_offset(tp->offset());
5443 PTR ptr = meet_ptr(tp->ptr());
5444 int instance_id = meet_instance_id(tp->instance_id());
5445 const TypePtr* speculative = xmeet_speculative(tp);
5446 int depth = meet_inline_depth(tp->inline_depth());
5447 const TypeInterfaces* interfaces = meet_interfaces(tp);
5448 const TypeInterfaces* tp_interfaces = tp->_interfaces;
5449 const TypeInterfaces* this_interfaces = _interfaces;
5450
5451 switch (ptr) {
5452 case TopPTR:
5453 case AnyNull: // Fall 'down' to dual of object klass
5454 // For instances when a subclass meets a superclass we fall
5455 // below the centerline when the superclass is exact. We need to
5456 // do the same here.
5457 //
5458 // Flat in array:
5459 // We do
5460 // dual(TypeAryPtr) MEET dual(TypeInstPtr)
5461 // If TypeInstPtr is anything else than Object, then the result of the meet is bottom Object (i.e. we could have
5462 // instances or arrays).
5463 // If TypeInstPtr is an Object and either
5464 // - exact
5465 // - inexact AND flat in array == dual(not flat in array) (i.e. not an array type)
5466 // then the result of the meet is bottom Object (i.e. we could have instances or arrays).
5467 // Otherwise, we meet two array pointers and create a new TypeAryPtr.
5468 if (tp->klass()->equals(ciEnv::current()->Object_klass()) && this_interfaces->contains(tp_interfaces) &&
5469 !tp->klass_is_exact() && !tp->is_not_flat_in_array()) {
5470 return TypeAryPtr::make(ptr, _ary, _klass, _klass_is_exact, offset, _field_offset, instance_id, speculative, depth);
5471 } else {
5472 // cannot subclass, so the meet has to fall badly below the centerline
5473 ptr = NotNull;
5474 instance_id = InstanceBot;
5475 interfaces = this_interfaces->intersection_with(tp_interfaces);
5476 FlatInArray flat_in_array = meet_flat_in_array(NotFlat, tp->flat_in_array());
5477 return TypeInstPtr::make(ptr, ciEnv::current()->Object_klass(), interfaces, false, nullptr, offset, flat_in_array, instance_id, speculative, depth);
5478 }
5479 case Constant:
5480 case NotNull:
5481 case BotPTR: { // Fall down to object klass
5482 // LCA is object_klass, but if we subclass from the top we can do better
5483 if (above_centerline(tp->ptr())) {
5484 // If 'tp' is above the centerline and it is Object class
5485 // then we can subclass in the Java class hierarchy.
5486 // For instances when a subclass meets a superclass we fall
5487 // below the centerline when the superclass is exact. We need
5488 // to do the same here.
5489
5490 // Flat in array: We do TypeAryPtr MEET dual(TypeInstPtr), same applies as above in TopPTR/AnyNull case.
5491 if (tp->klass()->equals(ciEnv::current()->Object_klass()) && this_interfaces->contains(tp_interfaces) &&
5492 !tp->klass_is_exact() && !tp->is_not_flat_in_array()) {
5493 // that is, my array type is a subtype of 'tp' klass
5494 return make(ptr, (ptr == Constant ? const_oop() : nullptr),
5495 _ary, _klass, _klass_is_exact, offset, _field_offset, instance_id, speculative, depth);
5496 }
5497 }
5498 // The other case cannot happen, since t cannot be a subtype of an array.
5499 // The meet falls down to Object class below centerline.
5500 if (ptr == Constant) {
5501 ptr = NotNull;
5502 }
5503 if (instance_id > 0) {
5504 instance_id = InstanceBot;
5505 }
5506
5507 FlatInArray flat_in_array = meet_flat_in_array(NotFlat, tp->flat_in_array());
5508 interfaces = this_interfaces->intersection_with(tp_interfaces);
5509 return TypeInstPtr::make(ptr, ciEnv::current()->Object_klass(), interfaces, false, nullptr, offset,
5510 flat_in_array, instance_id, speculative, depth);
5511 }
5512 default: typerr(t);
5513 }
5514 }
5515 }
5516 return this; // Lint noise
5517 }
5518
5519
5520 template<class T> TypePtr::MeetResult TypePtr::meet_aryptr(PTR& ptr, const Type*& elem, const T* this_ary, const T* other_ary,
5521 ciKlass*& res_klass, bool& res_xk, bool &res_flat, bool& res_not_flat, bool& res_not_null_free, bool &res_atomic) {
5522 int dummy;
5523 bool this_top_or_bottom = (this_ary->base_element_type(dummy) == Type::TOP || this_ary->base_element_type(dummy) == Type::BOTTOM);
5524 bool other_top_or_bottom = (other_ary->base_element_type(dummy) == Type::TOP || other_ary->base_element_type(dummy) == Type::BOTTOM);
5525 ciKlass* this_klass = this_ary->klass();
5526 ciKlass* other_klass = other_ary->klass();
5527 bool this_xk = this_ary->klass_is_exact();
5528 bool other_xk = other_ary->klass_is_exact();
5529 PTR this_ptr = this_ary->ptr();
5530 PTR other_ptr = other_ary->ptr();
5531 bool this_flat = this_ary->is_flat();
5532 bool this_not_flat = this_ary->is_not_flat();
5533 bool other_flat = other_ary->is_flat();
5534 bool other_not_flat = other_ary->is_not_flat();
5535 bool this_not_null_free = this_ary->is_not_null_free();
5536 bool other_not_null_free = other_ary->is_not_null_free();
5537 bool this_atomic = this_ary->is_atomic();
5538 bool other_atomic = other_ary->is_atomic();
5539 const bool same_nullness = this_ary->is_null_free() == other_ary->is_null_free();
5540 res_klass = nullptr;
5541 MeetResult result = SUBTYPE;
5542 res_flat = this_flat && other_flat;
5543 bool res_null_free = this_ary->is_null_free() && other_ary->is_null_free();
5544 res_not_flat = this_not_flat && other_not_flat;
5545 res_not_null_free = this_not_null_free && other_not_null_free;
5546 res_atomic = this_atomic && other_atomic;
5547
5548 if (elem->isa_int()) {
5549 // Integral array element types have irrelevant lattice relations.
5550 // It is the klass that determines array layout, not the element type.
5551 if (this_top_or_bottom) {
5552 res_klass = other_klass;
5553 } else if (other_top_or_bottom || other_klass == this_klass) {
5554 res_klass = this_klass;
5555 } else {
5556 // Something like byte[int+] meets char[int+].
5557 // This must fall to bottom, not (int[-128..65535])[int+].
5558 // instance_id = InstanceBot;
5559 elem = Type::BOTTOM;
5560 result = NOT_SUBTYPE;
5561 if (above_centerline(ptr) || ptr == Constant) {
5562 ptr = NotNull;
5563 res_xk = false;
5564 return NOT_SUBTYPE;
5565 }
5566 }
5567 } else {// Non integral arrays.
5568 // Must fall to bottom if exact klasses in upper lattice
5569 // are not equal or super klass is exact.
5570 if ((above_centerline(ptr) || ptr == Constant) && !this_ary->is_same_java_type_as(other_ary) &&
5571 // meet with top[] and bottom[] are processed further down:
5572 !this_top_or_bottom && !other_top_or_bottom &&
5573 // both are exact and not equal:
5574 ((other_xk && this_xk) ||
5575 // 'tap' is exact and super or unrelated:
5576 (other_xk && !other_ary->is_meet_subtype_of(this_ary)) ||
5577 // 'this' is exact and super or unrelated:
5578 (this_xk && !this_ary->is_meet_subtype_of(other_ary)))) {
5579 if (above_centerline(ptr) || (elem->make_ptr() && above_centerline(elem->make_ptr()->_ptr))) {
5580 elem = Type::BOTTOM;
5581 }
5582 ptr = NotNull;
5583 res_xk = false;
5584 return NOT_SUBTYPE;
5585 }
5586 }
5587
5588 res_xk = false;
5589 switch (other_ptr) {
5590 case AnyNull:
5591 case TopPTR:
5592 // Compute new klass on demand, do not use tap->_klass
5593 if (below_centerline(this_ptr)) {
5594 res_xk = this_xk;
5595 if (this_ary->is_flat()) {
5596 elem = this_ary->elem();
5597 }
5598 } else {
5599 res_xk = (other_xk || this_xk);
5600 }
5601 break;
5602 case Constant: {
5603 if (this_ptr == Constant && same_nullness) {
5604 // Only exact if same nullness since:
5605 // null-free [LMyValue <: nullable [LMyValue.
5606 res_xk = true;
5607 } else if (above_centerline(this_ptr)) {
5608 res_xk = true;
5609 } else {
5610 // Only precise for identical arrays
5611 res_xk = this_xk && (this_ary->is_same_java_type_as(other_ary) || (this_top_or_bottom && other_top_or_bottom));
5612 // Even though MyValue is final, [LMyValue is only exact if the array
5613 // is (not) null-free due to null-free [LMyValue <: null-able [LMyValue.
5614 if (res_xk && !res_null_free && !res_not_null_free) {
5615 ptr = NotNull;
5616 res_xk = false;
5617 }
5618 }
5619 break;
5620 }
5621 case NotNull:
5622 case BotPTR:
5623 // Compute new klass on demand, do not use tap->_klass
5624 if (above_centerline(this_ptr)) {
5625 res_xk = other_xk;
5626 if (other_ary->is_flat()) {
5627 elem = other_ary->elem();
5628 }
5629 } else {
5630 res_xk = (other_xk && this_xk) &&
5631 (this_ary->is_same_java_type_as(other_ary) || (this_top_or_bottom && other_top_or_bottom)); // Only precise for identical arrays
5632 // Even though MyValue is final, [LMyValue is only exact if the array
5633 // is (not) null-free due to null-free [LMyValue <: null-able [LMyValue.
5634 if (res_xk && !res_null_free && !res_not_null_free) {
5635 ptr = NotNull;
5636 res_xk = false;
5637 }
5638 }
5639 break;
5640 default: {
5641 ShouldNotReachHere();
5642 return result;
5643 }
5644 }
5645 return result;
5646 }
5647
5648
5649 //------------------------------xdual------------------------------------------
5650 // Dual: compute field-by-field dual
5651 const Type *TypeAryPtr::xdual() const {
5652 bool xk = _klass_is_exact;
5653 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());
5654 }
5655
5656 Type::Offset TypeAryPtr::meet_field_offset(const Type::Offset offset) const {
5657 return _field_offset.meet(offset);
5658 }
5659
5660 //------------------------------dual_offset------------------------------------
5661 Type::Offset TypeAryPtr::dual_field_offset() const {
5662 return _field_offset.dual();
5663 }
5664
5665 //------------------------------dump2------------------------------------------
5666 #ifndef PRODUCT
5667 void TypeAryPtr::dump2( Dict &d, uint depth, outputStream *st ) const {
5668 st->print("aryptr:");
5669 _ary->dump2(d, depth, st);
5670 _interfaces->dump(st);
5671
5672 if (_ptr == Constant) {
5673 const_oop()->print(st);
5674 }
5675
5676 st->print(":%s", ptr_msg[_ptr]);
5677 if (_klass_is_exact) {
5678 st->print(":exact");
5679 }
5680
5681 if (is_flat()) {
5682 st->print(":flat");
5683 st->print("(");
5684 _field_offset.dump2(st);
5685 st->print(")");
5686 } else if (is_not_flat()) {
5687 st->print(":not_flat");
5688 }
5689 if (is_null_free()) {
5690 st->print(":null free");
5691 }
5692 if (is_atomic()) {
5693 st->print(":atomic");
5694 }
5695 if (Verbose) {
5696 if (is_not_flat()) {
5697 st->print(":not flat");
5698 }
5699 if (is_not_null_free()) {
5700 st->print(":nullable");
5701 }
5702 }
5703 if (offset() != 0) {
5704 BasicType basic_elem_type = elem()->basic_type();
5705 int header_size = arrayOopDesc::base_offset_in_bytes(basic_elem_type);
5706 if( _offset == Offset::top ) st->print("+undefined");
5707 else if( _offset == Offset::bottom ) st->print("+any");
5708 else if( offset() < header_size ) st->print("+%d", offset());
5709 else {
5710 if (basic_elem_type == T_ILLEGAL) {
5711 st->print("+any");
5712 } else {
5713 int elem_size = type2aelembytes(basic_elem_type);
5714 st->print("[%d]", (offset() - header_size)/elem_size);
5715 }
5716 }
5717 }
5718
5719 dump_instance_id(st);
5720 dump_inline_depth(st);
5721 dump_speculative(st);
5722 }
5723 #endif
5724
5725 bool TypeAryPtr::empty(void) const {
5726 if (_ary->empty()) {
5727 return true;
5728 }
5729
5730 // Reference array is always possible. Only flat array with non-flattenable content can be an issue.
5731 if (const TypeOopPtr* elem_ptr = elem()->make_oopptr(); _ary->_flat && elem_ptr != nullptr && elem_ptr->is_inlinetypeptr()) {
5732 auto impossible_layout_with_null_freeness = [this](bool null_free, bool atomic) -> bool {
5733 ArrayDescription description = elem()->inline_klass()->array_description_of_array_properties(ArrayProperties::Default().with_null_restricted(null_free).with_non_atomic(!atomic));
5734 return !LayoutKindHelper::is_flat(description._layout_kind); // We get a contradiction between _ary->_flat and array_layout_selection
5735 };
5736 auto impossible_layout = [&](bool atomic) -> bool {
5737 if (is_null_free()) {
5738 // Surely null-free
5739 if (impossible_layout_with_null_freeness(true, atomic)) {
5740 return true;
5741 }
5742 } else if (is_not_null_free()) {
5743 // Surely nullable
5744 if (impossible_layout_with_null_freeness(false, atomic)) {
5745 return true;
5746 }
5747 } else {
5748 // Not sure...
5749 if (impossible_layout_with_null_freeness(false, atomic) && impossible_layout_with_null_freeness(true, atomic)) {
5750 return true;
5751 }
5752 }
5753 return false;
5754 };
5755 if (_ary->_atomic) {
5756 // Surely atomic
5757 if (impossible_layout(true)) {
5758 return true;
5759 }
5760 } else if (klass_is_exact()) {
5761 // Surely non-atomic
5762 if (impossible_layout(false)) {
5763 return true;
5764 }
5765 } else {
5766 // Not sure...
5767 if (impossible_layout(true) && impossible_layout(false)) {
5768 return true;
5769 }
5770 }
5771 }
5772
5773 return TypeOopPtr::empty();
5774 }
5775
5776 //------------------------------add_offset-------------------------------------
5777 const TypePtr* TypeAryPtr::add_offset(intptr_t offset) const {
5778 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);
5779 }
5780
5781 const TypeAryPtr* TypeAryPtr::with_offset(intptr_t offset) const {
5782 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);
5783 }
5784
5785 const TypeAryPtr* TypeAryPtr::with_ary(const TypeAry* ary) const {
5786 return make(_ptr, _const_oop, ary, _klass, _klass_is_exact, _offset, _field_offset, _instance_id, _speculative, _inline_depth, _is_autobox_cache);
5787 }
5788
5789 const TypeAryPtr* TypeAryPtr::remove_speculative() const {
5790 if (_speculative == nullptr) {
5791 return this;
5792 }
5793 assert(_inline_depth == InlineDepthTop || _inline_depth == InlineDepthBottom, "non speculative type shouldn't have inline depth");
5794 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);
5795 }
5796
5797 const Type* TypeAryPtr::cleanup_speculative() const {
5798 if (speculative() == nullptr) {
5799 return this;
5800 }
5801 // Keep speculative part if it contains information about flat-/nullability
5802 const TypeAryPtr* spec_aryptr = speculative()->isa_aryptr();
5803 if (spec_aryptr != nullptr && !above_centerline(spec_aryptr->ptr()) &&
5804 (spec_aryptr->is_not_flat() || spec_aryptr->is_not_null_free())) {
5805 return this;
5806 }
5807 return TypeOopPtr::cleanup_speculative();
5808 }
5809
5810 const TypePtr* TypeAryPtr::with_inline_depth(int depth) const {
5811 if (!UseInlineDepthForSpeculativeTypes) {
5812 return this;
5813 }
5814 return make(_ptr, _const_oop, _ary->remove_speculative()->is_ary(), _klass, _klass_is_exact, _offset, _field_offset, _instance_id, _speculative, depth, _is_autobox_cache);
5815 }
5816
5817 const TypeAryPtr* TypeAryPtr::with_field_offset(int offset) const {
5818 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);
5819 }
5820
5821 const TypePtr* TypeAryPtr::add_field_offset_and_offset(intptr_t offset) const {
5822 if (!is_flat() || !klass_is_exact() || offset == OffsetBot || offset == OffsetTop) {
5823 return add_offset(offset);
5824 }
5825
5826 // Handle flat concrete value class array with known 'offset' which could refer to an actual field in the flat storage.
5827 int adj = 0;
5828 if (_offset != Offset::bottom && _offset != Offset::top) {
5829 adj = _offset.get();
5830 offset += _offset.get();
5831 }
5832 uint header = arrayOopDesc::base_offset_in_bytes(T_FLAT_ELEMENT);
5833 if (_field_offset != Offset::bottom && _field_offset != Offset::top) {
5834 offset += _field_offset.get();
5835 if (_offset == Offset::bottom || _offset == Offset::top) {
5836 offset += header;
5837 }
5838 }
5839 if (elem()->make_oopptr()->is_inlinetypeptr() && (offset >= (intptr_t)header || offset < 0)) {
5840 // Try to get the field of the inline type array element we are pointing to
5841 ciInlineKlass* vk = elem()->inline_klass();
5842 int shift = flat_log_elem_size();
5843 int mask = (1 << shift) - 1;
5844 int field_offset = static_cast<int>((offset - header) & mask);
5845 ciField* field = vk->get_field_by_offset(field_offset + vk->payload_offset(), false);
5846 if (field != nullptr || field_offset == vk->null_marker_offset_in_payload()) {
5847 return with_field_offset(field_offset)->add_offset(offset - field_offset - adj);
5848 }
5849 }
5850 return add_offset(offset - adj);
5851 }
5852
5853 // Return offset incremented by field_offset for flat inline type arrays
5854 int TypeAryPtr::flat_offset() const {
5855 int offset = _offset.get();
5856 if (offset != OffsetBot && offset != OffsetTop &&
5857 _field_offset != Offset::bottom && _field_offset != Offset::top) {
5858 offset += _field_offset.get();
5859 }
5860 return offset;
5861 }
5862
5863 const TypePtr* TypeAryPtr::with_instance_id(int instance_id) const {
5864 assert(is_known_instance(), "should be known");
5865 return make(_ptr, _const_oop, _ary->remove_speculative()->is_ary(), _klass, _klass_is_exact, _offset, _field_offset, instance_id, _speculative, _inline_depth);
5866 }
5867
5868 //=============================================================================
5869
5870
5871 //------------------------------hash-------------------------------------------
5872 // Type-specific hashing function.
5873 uint TypeNarrowPtr::hash(void) const {
5874 return _ptrtype->hash() + 7;
5875 }
5876
5877 bool TypeNarrowPtr::singleton(void) const { // TRUE if type is a singleton
5878 return _ptrtype->singleton();
5879 }
5880
5881 bool TypeNarrowPtr::empty(void) const {
5882 return _ptrtype->empty();
5883 }
5884
5885 intptr_t TypeNarrowPtr::get_con() const {
5886 return _ptrtype->get_con();
5887 }
5888
5889 bool TypeNarrowPtr::eq( const Type *t ) const {
5890 const TypeNarrowPtr* tc = isa_same_narrowptr(t);
5891 if (tc != nullptr) {
5892 if (_ptrtype->base() != tc->_ptrtype->base()) {
5893 return false;
5894 }
5895 return tc->_ptrtype->eq(_ptrtype);
5896 }
5897 return false;
5898 }
5899
5900 const Type *TypeNarrowPtr::xdual() const { // Compute dual right now.
5901 const TypePtr* odual = _ptrtype->dual()->is_ptr();
5902 return make_same_narrowptr(odual);
5903 }
5904
5905
5906 const Type *TypeNarrowPtr::filter_helper(const Type *kills, bool include_speculative) const {
5907 if (isa_same_narrowptr(kills)) {
5908 const Type* ft =_ptrtype->filter_helper(is_same_narrowptr(kills)->_ptrtype, include_speculative);
5909 if (ft->empty())
5910 return Type::TOP; // Canonical empty value
5911 if (ft->isa_ptr()) {
5912 return make_hash_same_narrowptr(ft->isa_ptr());
5913 }
5914 return ft;
5915 } else if (kills->isa_ptr()) {
5916 const Type* ft = _ptrtype->join_helper(kills, include_speculative);
5917 if (ft->empty())
5918 return Type::TOP; // Canonical empty value
5919 return ft;
5920 } else {
5921 return Type::TOP;
5922 }
5923 }
5924
5925 //------------------------------xmeet------------------------------------------
5926 // Compute the MEET of two types. It returns a new Type object.
5927 const Type *TypeNarrowPtr::xmeet( const Type *t ) const {
5928 // Perform a fast test for common case; meeting the same types together.
5929 if( this == t ) return this; // Meeting same type-rep?
5930
5931 if (t->base() == base()) {
5932 const Type* result = _ptrtype->xmeet(t->make_ptr());
5933 if (result->isa_ptr()) {
5934 return make_hash_same_narrowptr(result->is_ptr());
5935 }
5936 return result;
5937 }
5938
5939 // Current "this->_base" is NarrowKlass or NarrowOop
5940 switch (t->base()) { // switch on original type
5941
5942 case Int: // Mixing ints & oops happens when javac
5943 case Long: // reuses local variables
5944 case HalfFloatTop:
5945 case HalfFloatCon:
5946 case HalfFloatBot:
5947 case FloatTop:
5948 case FloatCon:
5949 case FloatBot:
5950 case DoubleTop:
5951 case DoubleCon:
5952 case DoubleBot:
5953 case AnyPtr:
5954 case RawPtr:
5955 case OopPtr:
5956 case InstPtr:
5957 case AryPtr:
5958 case MetadataPtr:
5959 case KlassPtr:
5960 case InstKlassPtr:
5961 case AryKlassPtr:
5962 case NarrowOop:
5963 case NarrowKlass:
5964 case Bottom: // Ye Olde Default
5965 return Type::BOTTOM;
5966 case Top:
5967 return this;
5968
5969 default: // All else is a mistake
5970 typerr(t);
5971
5972 } // End of switch
5973
5974 return this;
5975 }
5976
5977 #ifndef PRODUCT
5978 void TypeNarrowPtr::dump2( Dict & d, uint depth, outputStream *st ) const {
5979 _ptrtype->dump2(d, depth, st);
5980 }
5981 #endif
5982
5983 const TypeNarrowOop *TypeNarrowOop::BOTTOM;
5984 const TypeNarrowOop *TypeNarrowOop::NULL_PTR;
5985
5986
5987 const TypeNarrowOop* TypeNarrowOop::make(const TypePtr* type) {
5988 return (const TypeNarrowOop*)(new TypeNarrowOop(type))->hashcons();
5989 }
5990
5991 const TypeNarrowOop* TypeNarrowOop::remove_speculative() const {
5992 return make(_ptrtype->remove_speculative()->is_ptr());
5993 }
5994
5995 const Type* TypeNarrowOop::cleanup_speculative() const {
5996 return make(_ptrtype->cleanup_speculative()->is_ptr());
5997 }
5998
5999 #ifndef PRODUCT
6000 void TypeNarrowOop::dump2( Dict & d, uint depth, outputStream *st ) const {
6001 st->print("narrowoop: ");
6002 TypeNarrowPtr::dump2(d, depth, st);
6003 }
6004 #endif
6005
6006 const TypeNarrowKlass *TypeNarrowKlass::NULL_PTR;
6007
6008 const TypeNarrowKlass* TypeNarrowKlass::make(const TypePtr* type) {
6009 return (const TypeNarrowKlass*)(new TypeNarrowKlass(type))->hashcons();
6010 }
6011
6012 #ifndef PRODUCT
6013 void TypeNarrowKlass::dump2( Dict & d, uint depth, outputStream *st ) const {
6014 st->print("narrowklass: ");
6015 TypeNarrowPtr::dump2(d, depth, st);
6016 }
6017 #endif
6018
6019
6020 //------------------------------eq---------------------------------------------
6021 // Structural equality check for Type representations
6022 bool TypeMetadataPtr::eq( const Type *t ) const {
6023 const TypeMetadataPtr *a = (const TypeMetadataPtr*)t;
6024 ciMetadata* one = metadata();
6025 ciMetadata* two = a->metadata();
6026 if (one == nullptr || two == nullptr) {
6027 return (one == two) && TypePtr::eq(t);
6028 } else {
6029 return one->equals(two) && TypePtr::eq(t);
6030 }
6031 }
6032
6033 //------------------------------hash-------------------------------------------
6034 // Type-specific hashing function.
6035 uint TypeMetadataPtr::hash(void) const {
6036 return
6037 (metadata() ? metadata()->hash() : 0) +
6038 TypePtr::hash();
6039 }
6040
6041 //------------------------------singleton--------------------------------------
6042 // TRUE if Type is a singleton type, FALSE otherwise. Singletons are simple
6043 // constants
6044 bool TypeMetadataPtr::singleton(void) const {
6045 // detune optimizer to not generate constant metadata + constant offset as a constant!
6046 // TopPTR, Null, AnyNull, Constant are all singletons
6047 return (offset() == 0) && !below_centerline(_ptr);
6048 }
6049
6050 //------------------------------add_offset-------------------------------------
6051 const TypePtr* TypeMetadataPtr::add_offset( intptr_t offset ) const {
6052 return make( _ptr, _metadata, xadd_offset(offset));
6053 }
6054
6055 //-----------------------------filter------------------------------------------
6056 // Do not allow interface-vs.-noninterface joins to collapse to top.
6057 const Type *TypeMetadataPtr::filter_helper(const Type *kills, bool include_speculative) const {
6058 const TypeMetadataPtr* ft = join_helper(kills, include_speculative)->isa_metadataptr();
6059 if (ft == nullptr || ft->empty())
6060 return Type::TOP; // Canonical empty value
6061 return ft;
6062 }
6063
6064 //------------------------------get_con----------------------------------------
6065 intptr_t TypeMetadataPtr::get_con() const {
6066 assert( _ptr == Null || _ptr == Constant, "" );
6067 assert(offset() >= 0, "");
6068
6069 if (offset() != 0) {
6070 // After being ported to the compiler interface, the compiler no longer
6071 // directly manipulates the addresses of oops. Rather, it only has a pointer
6072 // to a handle at compile time. This handle is embedded in the generated
6073 // code and dereferenced at the time the nmethod is made. Until that time,
6074 // it is not reasonable to do arithmetic with the addresses of oops (we don't
6075 // have access to the addresses!). This does not seem to currently happen,
6076 // but this assertion here is to help prevent its occurrence.
6077 tty->print_cr("Found oop constant with non-zero offset");
6078 ShouldNotReachHere();
6079 }
6080
6081 return (intptr_t)metadata()->constant_encoding();
6082 }
6083
6084 //------------------------------cast_to_ptr_type-------------------------------
6085 const TypeMetadataPtr* TypeMetadataPtr::cast_to_ptr_type(PTR ptr) const {
6086 if( ptr == _ptr ) return this;
6087 return make(ptr, metadata(), _offset);
6088 }
6089
6090 //------------------------------meet-------------------------------------------
6091 // Compute the MEET of two types. It returns a new Type object.
6092 const Type *TypeMetadataPtr::xmeet( const Type *t ) const {
6093 // Perform a fast test for common case; meeting the same types together.
6094 if( this == t ) return this; // Meeting same type-rep?
6095
6096 // Current "this->_base" is OopPtr
6097 switch (t->base()) { // switch on original type
6098
6099 case Int: // Mixing ints & oops happens when javac
6100 case Long: // reuses local variables
6101 case HalfFloatTop:
6102 case HalfFloatCon:
6103 case HalfFloatBot:
6104 case FloatTop:
6105 case FloatCon:
6106 case FloatBot:
6107 case DoubleTop:
6108 case DoubleCon:
6109 case DoubleBot:
6110 case NarrowOop:
6111 case NarrowKlass:
6112 case Bottom: // Ye Olde Default
6113 return Type::BOTTOM;
6114 case Top:
6115 return this;
6116
6117 default: // All else is a mistake
6118 typerr(t);
6119
6120 case AnyPtr: {
6121 // Found an AnyPtr type vs self-OopPtr type
6122 const TypePtr *tp = t->is_ptr();
6123 Offset offset = meet_offset(tp->offset());
6124 PTR ptr = meet_ptr(tp->ptr());
6125 switch (tp->ptr()) {
6126 case Null:
6127 if (ptr == Null) return TypePtr::make(AnyPtr, ptr, offset, tp->speculative(), tp->inline_depth());
6128 // else fall through:
6129 case TopPTR:
6130 case AnyNull: {
6131 return make(ptr, _metadata, offset);
6132 }
6133 case BotPTR:
6134 case NotNull:
6135 return TypePtr::make(AnyPtr, ptr, offset, tp->speculative(), tp->inline_depth());
6136 default: typerr(t);
6137 }
6138 }
6139
6140 case RawPtr:
6141 case KlassPtr:
6142 case InstKlassPtr:
6143 case AryKlassPtr:
6144 case OopPtr:
6145 case InstPtr:
6146 case AryPtr:
6147 return TypePtr::BOTTOM; // Oop meet raw is not well defined
6148
6149 case MetadataPtr: {
6150 const TypeMetadataPtr *tp = t->is_metadataptr();
6151 Offset offset = meet_offset(tp->offset());
6152 PTR tptr = tp->ptr();
6153 PTR ptr = meet_ptr(tptr);
6154 ciMetadata* md = (tptr == TopPTR) ? metadata() : tp->metadata();
6155 if (tptr == TopPTR || _ptr == TopPTR ||
6156 metadata()->equals(tp->metadata())) {
6157 return make(ptr, md, offset);
6158 }
6159 // metadata is different
6160 if( ptr == Constant ) { // Cannot be equal constants, so...
6161 if( tptr == Constant && _ptr != Constant) return t;
6162 if( _ptr == Constant && tptr != Constant) return this;
6163 ptr = NotNull; // Fall down in lattice
6164 }
6165 return make(ptr, nullptr, offset);
6166 break;
6167 }
6168 } // End of switch
6169 return this; // Return the double constant
6170 }
6171
6172
6173 //------------------------------xdual------------------------------------------
6174 // Dual of a pure metadata pointer.
6175 const Type *TypeMetadataPtr::xdual() const {
6176 return new TypeMetadataPtr(dual_ptr(), metadata(), dual_offset());
6177 }
6178
6179 //------------------------------dump2------------------------------------------
6180 #ifndef PRODUCT
6181 void TypeMetadataPtr::dump2( Dict &d, uint depth, outputStream *st ) const {
6182 st->print("metadataptr:%s", ptr_msg[_ptr]);
6183 if (metadata() != nullptr) {
6184 st->print(":" INTPTR_FORMAT, p2i(metadata()));
6185 }
6186 dump_offset(st);
6187 }
6188 #endif
6189
6190
6191 //=============================================================================
6192 // Convenience common pre-built type.
6193 const TypeMetadataPtr *TypeMetadataPtr::BOTTOM;
6194
6195 TypeMetadataPtr::TypeMetadataPtr(PTR ptr, ciMetadata* metadata, Offset offset):
6196 TypePtr(MetadataPtr, ptr, offset, relocInfo::metadata_type), _metadata(metadata) {
6197 }
6198
6199 const TypeMetadataPtr* TypeMetadataPtr::make(ciMethod* m) {
6200 return make(Constant, m, Offset(0));
6201 }
6202 const TypeMetadataPtr* TypeMetadataPtr::make(ciMethodData* m) {
6203 return make(Constant, m, Offset(0));
6204 }
6205
6206 //------------------------------make-------------------------------------------
6207 // Create a meta data constant
6208 const TypeMetadataPtr* TypeMetadataPtr::make(PTR ptr, ciMetadata* m, Offset offset) {
6209 assert(m == nullptr || !m->is_klass(), "wrong type");
6210 return (TypeMetadataPtr*)(new TypeMetadataPtr(ptr, m, offset))->hashcons();
6211 }
6212
6213
6214 const TypeKlassPtr* TypeAryPtr::as_klass_type(bool try_for_exact) const {
6215 const Type* elem = _ary->_elem;
6216 bool xk = klass_is_exact();
6217 bool is_refined = false;
6218 if (elem->make_oopptr() != nullptr) {
6219 is_refined = true;
6220 elem = elem->make_oopptr()->as_klass_type(try_for_exact);
6221 if (elem->isa_aryklassptr()) {
6222 const TypeAryKlassPtr* elem_klass = elem->is_aryklassptr();
6223 if (elem_klass->is_refined_type()) {
6224 elem = elem_klass->cast_to_non_refined();
6225 }
6226 } else {
6227 const TypeInstKlassPtr* elem_klass = elem->is_instklassptr();
6228 if (try_for_exact && !xk && elem_klass->klass_is_exact() &&
6229 !elem_klass->exact_klass()->as_instance_klass()->can_be_inline_klass()) {
6230 xk = true;
6231 }
6232 }
6233 }
6234 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);
6235 }
6236
6237 const TypeKlassPtr* TypeKlassPtr::make(ciKlass* klass, InterfaceHandling interface_handling) {
6238 if (klass->is_instance_klass()) {
6239 return TypeInstKlassPtr::make(klass, interface_handling);
6240 }
6241 return TypeAryKlassPtr::make(klass, interface_handling);
6242 }
6243
6244 TypeKlassPtr::TypeKlassPtr(TYPES t, PTR ptr, ciKlass* klass, const TypeInterfaces* interfaces, Offset offset)
6245 : TypePtr(t, ptr, offset, relocInfo::metadata_type), _klass(klass), _interfaces(interfaces) {
6246 assert(klass == nullptr || !klass->is_loaded() || (klass->is_instance_klass() && !klass->is_interface()) ||
6247 klass->is_type_array_klass() || klass->is_flat_array_klass() || !klass->as_obj_array_klass()->base_element_klass()->is_interface(), "no interface here");
6248 }
6249
6250 // Is there a single ciKlass* that can represent that type?
6251 ciKlass* TypeKlassPtr::exact_klass_helper() const {
6252 assert(_klass->is_instance_klass() && !_klass->is_interface(), "No interface");
6253 if (_interfaces->empty()) {
6254 return _klass;
6255 }
6256 if (_klass != ciEnv::current()->Object_klass()) {
6257 if (_interfaces->eq(_klass->as_instance_klass())) {
6258 return _klass;
6259 }
6260 return nullptr;
6261 }
6262 return _interfaces->exact_klass();
6263 }
6264
6265 //------------------------------eq---------------------------------------------
6266 // Structural equality check for Type representations
6267 bool TypeKlassPtr::eq(const Type *t) const {
6268 const TypeKlassPtr *p = t->is_klassptr();
6269 return
6270 _interfaces->eq(p->_interfaces) &&
6271 TypePtr::eq(p);
6272 }
6273
6274 //------------------------------hash-------------------------------------------
6275 // Type-specific hashing function.
6276 uint TypeKlassPtr::hash(void) const {
6277 return TypePtr::hash() + _interfaces->hash();
6278 }
6279
6280 //------------------------------singleton--------------------------------------
6281 // TRUE if Type is a singleton type, FALSE otherwise. Singletons are simple
6282 // constants
6283 bool TypeKlassPtr::singleton(void) const {
6284 // detune optimizer to not generate constant klass + constant offset as a constant!
6285 // TopPTR, Null, AnyNull, Constant are all singletons
6286 return (offset() == 0) && !below_centerline(_ptr);
6287 }
6288
6289 // Do not allow interface-vs.-noninterface joins to collapse to top.
6290 const Type *TypeKlassPtr::filter_helper(const Type *kills, bool include_speculative) const {
6291 // logic here mirrors the one from TypeOopPtr::filter. See comments
6292 // there.
6293 const Type* ft = join_helper(kills, include_speculative);
6294
6295 if (ft->empty()) {
6296 return Type::TOP; // Canonical empty value
6297 }
6298
6299 return ft;
6300 }
6301
6302 const TypeInterfaces* TypeKlassPtr::meet_interfaces(const TypeKlassPtr* other) const {
6303 if (above_centerline(_ptr) && above_centerline(other->_ptr)) {
6304 return _interfaces->union_with(other->_interfaces);
6305 } else if (above_centerline(_ptr) && !above_centerline(other->_ptr)) {
6306 return other->_interfaces;
6307 } else if (above_centerline(other->_ptr) && !above_centerline(_ptr)) {
6308 return _interfaces;
6309 }
6310 return _interfaces->intersection_with(other->_interfaces);
6311 }
6312
6313 //------------------------------get_con----------------------------------------
6314 intptr_t TypeKlassPtr::get_con() const {
6315 assert( _ptr == Null || _ptr == Constant, "" );
6316 assert( offset() >= 0, "" );
6317
6318 if (offset() != 0) {
6319 // After being ported to the compiler interface, the compiler no longer
6320 // directly manipulates the addresses of oops. Rather, it only has a pointer
6321 // to a handle at compile time. This handle is embedded in the generated
6322 // code and dereferenced at the time the nmethod is made. Until that time,
6323 // it is not reasonable to do arithmetic with the addresses of oops (we don't
6324 // have access to the addresses!). This does not seem to currently happen,
6325 // but this assertion here is to help prevent its occurrence.
6326 tty->print_cr("Found oop constant with non-zero offset");
6327 ShouldNotReachHere();
6328 }
6329
6330 ciKlass* k = exact_klass();
6331
6332 return (intptr_t)k->constant_encoding();
6333 }
6334
6335 //=============================================================================
6336 // Convenience common pre-built types.
6337
6338 // Not-null object klass or below
6339 const TypeInstKlassPtr *TypeInstKlassPtr::OBJECT;
6340 const TypeInstKlassPtr *TypeInstKlassPtr::OBJECT_OR_NULL;
6341
6342 bool TypeInstKlassPtr::eq(const Type *t) const {
6343 const TypeInstKlassPtr* p = t->is_instklassptr();
6344 return
6345 klass()->equals(p->klass()) &&
6346 _flat_in_array == p->_flat_in_array &&
6347 TypeKlassPtr::eq(p);
6348 }
6349
6350 uint TypeInstKlassPtr::hash() const {
6351 return klass()->hash() + TypeKlassPtr::hash() + static_cast<uint>(_flat_in_array);
6352 }
6353
6354 const TypeInstKlassPtr *TypeInstKlassPtr::make(PTR ptr, ciKlass* k, const TypeInterfaces* interfaces, Offset offset, FlatInArray flat_in_array) {
6355 if (flat_in_array == Uninitialized) {
6356 flat_in_array = compute_flat_in_array(k->as_instance_klass(), ptr == Constant);
6357 }
6358 TypeInstKlassPtr *r =
6359 (TypeInstKlassPtr*)(new TypeInstKlassPtr(ptr, k, interfaces, offset, flat_in_array))->hashcons();
6360
6361 return r;
6362 }
6363
6364 bool TypeInstKlassPtr::empty() const {
6365 if (_flat_in_array == TopFlat) {
6366 return true;
6367 }
6368 return TypeKlassPtr::empty();
6369 }
6370
6371 //------------------------------add_offset-------------------------------------
6372 // Access internals of klass object
6373 const TypePtr *TypeInstKlassPtr::add_offset( intptr_t offset ) const {
6374 return make(_ptr, klass(), _interfaces, xadd_offset(offset), _flat_in_array);
6375 }
6376
6377 const TypeInstKlassPtr* TypeInstKlassPtr::with_offset(intptr_t offset) const {
6378 return make(_ptr, klass(), _interfaces, Offset(offset), _flat_in_array);
6379 }
6380
6381 //------------------------------cast_to_ptr_type-------------------------------
6382 const TypeInstKlassPtr* TypeInstKlassPtr::cast_to_ptr_type(PTR ptr) const {
6383 assert(_base == InstKlassPtr, "subclass must override cast_to_ptr_type");
6384 if( ptr == _ptr ) return this;
6385 return make(ptr, _klass, _interfaces, _offset, _flat_in_array);
6386 }
6387
6388
6389 bool TypeInstKlassPtr::must_be_exact() const {
6390 if (!_klass->is_loaded()) return false;
6391 ciInstanceKlass* ik = _klass->as_instance_klass();
6392 if (ik->is_final()) return true; // cannot clear xk
6393 return false;
6394 }
6395
6396 //-----------------------------cast_to_exactness-------------------------------
6397 const TypeKlassPtr* TypeInstKlassPtr::cast_to_exactness(bool klass_is_exact) const {
6398 if (klass_is_exact == (_ptr == Constant)) return this;
6399 if (must_be_exact()) return this;
6400 ciKlass* k = klass();
6401 FlatInArray flat_in_array = compute_flat_in_array(k->as_instance_klass(), klass_is_exact);
6402 return make(klass_is_exact ? Constant : NotNull, k, _interfaces, _offset, flat_in_array);
6403 }
6404
6405
6406 //-----------------------------as_instance_type--------------------------------
6407 // Corresponding type for an instance of the given class.
6408 // It will be NotNull, and exact if and only if the klass type is exact.
6409 const TypeOopPtr* TypeInstKlassPtr::as_instance_type(bool klass_change) const {
6410 ciKlass* k = klass();
6411 bool xk = klass_is_exact();
6412 Compile* C = Compile::current();
6413 Dependencies* deps = C->dependencies();
6414 assert((deps != nullptr) == (C->method() != nullptr && C->method()->code_size() > 0), "sanity");
6415 // Element is an instance
6416 bool klass_is_exact = false;
6417 const TypeInterfaces* interfaces = _interfaces;
6418 ciInstanceKlass* ik = k->as_instance_klass();
6419 if (k->is_loaded()) {
6420 // Try to set klass_is_exact.
6421 klass_is_exact = ik->is_final();
6422 if (!klass_is_exact && klass_change
6423 && deps != nullptr && UseUniqueSubclasses) {
6424 ciInstanceKlass* sub = ik->unique_concrete_subklass();
6425 if (sub != nullptr) {
6426 if (_interfaces->eq(sub)) {
6427 deps->assert_abstract_with_unique_concrete_subtype(ik, sub);
6428 k = ik = sub;
6429 xk = sub->is_final();
6430 }
6431 }
6432 }
6433 }
6434
6435 FlatInArray flat_in_array = compute_flat_in_array_if_unknown(ik, xk, _flat_in_array);
6436 return TypeInstPtr::make(TypePtr::BotPTR, k, interfaces, xk, nullptr, Offset(0), flat_in_array);
6437 }
6438
6439 //------------------------------xmeet------------------------------------------
6440 // Compute the MEET of two types, return a new Type object.
6441 const Type *TypeInstKlassPtr::xmeet( const Type *t ) const {
6442 // Perform a fast test for common case; meeting the same types together.
6443 if( this == t ) return this; // Meeting same type-rep?
6444
6445 // Current "this->_base" is Pointer
6446 switch (t->base()) { // switch on original type
6447
6448 case Int: // Mixing ints & oops happens when javac
6449 case Long: // reuses local variables
6450 case HalfFloatTop:
6451 case HalfFloatCon:
6452 case HalfFloatBot:
6453 case FloatTop:
6454 case FloatCon:
6455 case FloatBot:
6456 case DoubleTop:
6457 case DoubleCon:
6458 case DoubleBot:
6459 case NarrowOop:
6460 case NarrowKlass:
6461 case Bottom: // Ye Olde Default
6462 return Type::BOTTOM;
6463 case Top:
6464 return this;
6465
6466 default: // All else is a mistake
6467 typerr(t);
6468
6469 case AnyPtr: { // Meeting to AnyPtrs
6470 // Found an AnyPtr type vs self-KlassPtr type
6471 const TypePtr *tp = t->is_ptr();
6472 Offset offset = meet_offset(tp->offset());
6473 PTR ptr = meet_ptr(tp->ptr());
6474 switch (tp->ptr()) {
6475 case TopPTR:
6476 return this;
6477 case Null:
6478 if( ptr == Null ) return TypePtr::make(AnyPtr, ptr, offset, tp->speculative(), tp->inline_depth());
6479 case AnyNull:
6480 return make(ptr, klass(), _interfaces, offset, _flat_in_array);
6481 case BotPTR:
6482 case NotNull:
6483 return TypePtr::make(AnyPtr, ptr, offset, tp->speculative(), tp->inline_depth());
6484 default: typerr(t);
6485 }
6486 }
6487
6488 case RawPtr:
6489 case MetadataPtr:
6490 case OopPtr:
6491 case AryPtr: // Meet with AryPtr
6492 case InstPtr: // Meet with InstPtr
6493 return TypePtr::BOTTOM;
6494
6495 //
6496 // A-top }
6497 // / | \ } Tops
6498 // B-top A-any C-top }
6499 // | / | \ | } Any-nulls
6500 // B-any | C-any }
6501 // | | |
6502 // B-con A-con C-con } constants; not comparable across classes
6503 // | | |
6504 // B-not | C-not }
6505 // | \ | / | } not-nulls
6506 // B-bot A-not C-bot }
6507 // \ | / } Bottoms
6508 // A-bot }
6509 //
6510
6511 case InstKlassPtr: { // Meet two KlassPtr types
6512 const TypeInstKlassPtr *tkls = t->is_instklassptr();
6513 Offset off = meet_offset(tkls->offset());
6514 PTR ptr = meet_ptr(tkls->ptr());
6515 const TypeInterfaces* interfaces = meet_interfaces(tkls);
6516
6517 ciKlass* res_klass = nullptr;
6518 bool res_xk = false;
6519 const FlatInArray flat_in_array = meet_flat_in_array(_flat_in_array, tkls->flat_in_array());
6520 switch (meet_instptr(ptr, interfaces, this, tkls, res_klass, res_xk)) {
6521 case UNLOADED:
6522 ShouldNotReachHere();
6523 case SUBTYPE:
6524 case NOT_SUBTYPE:
6525 case LCA:
6526 case QUICK: {
6527 assert(res_xk == (ptr == Constant), "");
6528 const Type* res = make(ptr, res_klass, interfaces, off, flat_in_array);
6529 return res;
6530 }
6531 default:
6532 ShouldNotReachHere();
6533 }
6534 } // End of case KlassPtr
6535 case AryKlassPtr: { // All arrays inherit from Object class
6536 const TypeAryKlassPtr *tp = t->is_aryklassptr();
6537 Offset offset = meet_offset(tp->offset());
6538 PTR ptr = meet_ptr(tp->ptr());
6539 const TypeInterfaces* interfaces = meet_interfaces(tp);
6540 const TypeInterfaces* tp_interfaces = tp->_interfaces;
6541 const TypeInterfaces* this_interfaces = _interfaces;
6542
6543 switch (ptr) {
6544 case TopPTR:
6545 case AnyNull: // Fall 'down' to dual of object klass
6546 // For instances when a subclass meets a superclass we fall
6547 // below the centerline when the superclass is exact. We need to
6548 // do the same here.
6549 //
6550 // Flat in array: See explanation for meet with TypeInstPtr in TypeAryPtr::xmeet_helper().
6551 if (klass()->equals(ciEnv::current()->Object_klass()) && tp_interfaces->contains(this_interfaces) &&
6552 !klass_is_exact() && !is_not_flat_in_array()) {
6553 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());
6554 } else {
6555 // cannot subclass, so the meet has to fall badly below the centerline
6556 ptr = NotNull;
6557 interfaces = _interfaces->intersection_with(tp->_interfaces);
6558 FlatInArray flat_in_array = meet_flat_in_array(_flat_in_array, NotFlat);
6559 return make(ptr, ciEnv::current()->Object_klass(), interfaces, offset, flat_in_array);
6560 }
6561 case Constant:
6562 case NotNull:
6563 case BotPTR: { // Fall down to object klass
6564 // LCA is object_klass, but if we subclass from the top we can do better
6565 if( above_centerline(_ptr) ) { // if( _ptr == TopPTR || _ptr == AnyNull )
6566 // If 'this' (InstPtr) is above the centerline and it is Object class
6567 // then we can subclass in the Java class hierarchy.
6568 // For instances when a subclass meets a superclass we fall
6569 // below the centerline when the superclass is exact. We need
6570 // to do the same here.
6571 //
6572 // Flat in array: See explanation for meet with TypeInstPtr in TypeAryPtr::xmeet_helper().
6573 if (klass()->equals(ciEnv::current()->Object_klass()) && tp_interfaces->contains(this_interfaces) &&
6574 !klass_is_exact() && !is_not_flat_in_array()) {
6575 // that is, tp's array type is a subtype of my klass
6576 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());
6577 }
6578 }
6579 // The other case cannot happen, since I cannot be a subtype of an array.
6580 // The meet falls down to Object class below centerline.
6581 if( ptr == Constant )
6582 ptr = NotNull;
6583 interfaces = this_interfaces->intersection_with(tp_interfaces);
6584 FlatInArray flat_in_array = meet_flat_in_array(_flat_in_array, NotFlat);
6585 return make(ptr, ciEnv::current()->Object_klass(), interfaces, offset, flat_in_array);
6586 }
6587 default: typerr(t);
6588 }
6589 }
6590
6591 } // End of switch
6592 return this; // Return the double constant
6593 }
6594
6595 //------------------------------xdual------------------------------------------
6596 // Dual: compute field-by-field dual
6597 const Type* TypeInstKlassPtr::xdual() const {
6598 return new TypeInstKlassPtr(dual_ptr(), klass(), _interfaces, dual_offset(), dual_flat_in_array());
6599 }
6600
6601 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) {
6602 static_assert(std::is_base_of<T2, T1>::value, "");
6603 if (!this_one->is_loaded() || !other->is_loaded()) {
6604 return false;
6605 }
6606 if (!this_one->is_instance_type(other)) {
6607 return false;
6608 }
6609
6610 if (!other_exact) {
6611 return false;
6612 }
6613
6614 if (other->klass()->equals(ciEnv::current()->Object_klass()) && other->_interfaces->empty()) {
6615 return true;
6616 }
6617
6618 return this_one->klass()->is_subtype_of(other->klass()) && this_one->_interfaces->contains(other->_interfaces);
6619 }
6620
6621 bool TypeInstKlassPtr::might_be_an_array() const {
6622 if (!instance_klass()->is_java_lang_Object()) {
6623 // TypeInstKlassPtr can be an array only if it is java.lang.Object: the only supertype of array types.
6624 return false;
6625 }
6626 if (interfaces()->has_non_array_interface()) {
6627 // Arrays only implement Cloneable and Serializable. If we see any other interface, [this] cannot be an array.
6628 return false;
6629 }
6630 // Cannot prove it's not an array.
6631 return true;
6632 }
6633
6634 bool TypeInstKlassPtr::is_java_subtype_of_helper(const TypeKlassPtr* other, bool this_exact, bool other_exact) const {
6635 return TypePtr::is_java_subtype_of_helper_for_instance(this, other, this_exact, other_exact);
6636 }
6637
6638 template <class T1, class T2> bool TypePtr::is_same_java_type_as_helper_for_instance(const T1* this_one, const T2* other) {
6639 static_assert(std::is_base_of<T2, T1>::value, "");
6640 if (!this_one->is_loaded() || !other->is_loaded()) {
6641 return false;
6642 }
6643 if (!this_one->is_instance_type(other)) {
6644 return false;
6645 }
6646 return this_one->klass()->equals(other->klass()) && this_one->_interfaces->eq(other->_interfaces);
6647 }
6648
6649 bool TypeInstKlassPtr::is_same_java_type_as_helper(const TypeKlassPtr* other) const {
6650 return TypePtr::is_same_java_type_as_helper_for_instance(this, other);
6651 }
6652
6653 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) {
6654 static_assert(std::is_base_of<T2, T1>::value, "");
6655 if (!this_one->is_loaded() || !other->is_loaded()) {
6656 return true;
6657 }
6658
6659 if (this_one->is_array_type(other)) {
6660 return !this_exact && this_one->klass()->equals(ciEnv::current()->Object_klass()) && other->_interfaces->contains(this_one->_interfaces);
6661 }
6662
6663 assert(this_one->is_instance_type(other), "unsupported");
6664
6665 if (this_exact && other_exact) {
6666 return this_one->is_java_subtype_of(other);
6667 }
6668
6669 if (!this_one->klass()->is_subtype_of(other->klass()) && !other->klass()->is_subtype_of(this_one->klass())) {
6670 return false;
6671 }
6672
6673 if (this_exact) {
6674 return this_one->klass()->is_subtype_of(other->klass()) && this_one->_interfaces->contains(other->_interfaces);
6675 }
6676
6677 return true;
6678 }
6679
6680 bool TypeInstKlassPtr::maybe_java_subtype_of_helper(const TypeKlassPtr* other, bool this_exact, bool other_exact) const {
6681 return TypePtr::maybe_java_subtype_of_helper_for_instance(this, other, this_exact, other_exact);
6682 }
6683
6684 const TypeKlassPtr* TypeInstKlassPtr::try_improve() const {
6685 if (!UseUniqueSubclasses) {
6686 return this;
6687 }
6688 ciKlass* k = klass();
6689 Compile* C = Compile::current();
6690 Dependencies* deps = C->dependencies();
6691 assert((deps != nullptr) == (C->method() != nullptr && C->method()->code_size() > 0), "sanity");
6692 if (k->is_loaded()) {
6693 ciInstanceKlass* ik = k->as_instance_klass();
6694 if (deps != nullptr) {
6695 ciInstanceKlass* sub = ik->unique_concrete_subklass();
6696 if (sub != nullptr) {
6697 bool improve_to_exact = sub->is_final() && _ptr == NotNull;
6698 const TypeInstKlassPtr* improved = TypeInstKlassPtr::make(improve_to_exact ? Constant : _ptr, sub, _offset);
6699 if (_interfaces->is_subset(sub)) {
6700 deps->assert_abstract_with_unique_concrete_subtype(ik, sub);
6701 return improved;
6702 }
6703 }
6704 }
6705 }
6706 return this;
6707 }
6708
6709 bool TypeInstKlassPtr::can_be_inline_array() const {
6710 return _klass->equals(ciEnv::current()->Object_klass()) && TypeAryKlassPtr::_array_interfaces->contains(_interfaces);
6711 }
6712
6713 #ifndef PRODUCT
6714 void TypeInstKlassPtr::dump2(Dict& d, uint depth, outputStream* st) const {
6715 st->print("instklassptr:");
6716 klass()->print_name_on(st);
6717 _interfaces->dump(st);
6718 st->print(":%s", ptr_msg[_ptr]);
6719 dump_offset(st);
6720 dump_flat_in_array(_flat_in_array, st);
6721 }
6722 #endif // PRODUCT
6723
6724 bool TypeAryKlassPtr::can_be_inline_array() const {
6725 return _elem->isa_instklassptr() && _elem->is_instklassptr()->_klass->can_be_inline_klass();
6726 }
6727
6728 bool TypeInstPtr::can_be_inline_array() const {
6729 return _klass->equals(ciEnv::current()->Object_klass()) && TypeAryPtr::_array_interfaces->contains(_interfaces);
6730 }
6731
6732 bool TypeAryPtr::can_be_inline_array() const {
6733 return elem()->make_ptr() && elem()->make_ptr()->isa_instptr() && elem()->make_ptr()->is_instptr()->_klass->can_be_inline_klass();
6734 }
6735
6736 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) {
6737 return (TypeAryKlassPtr*)(new TypeAryKlassPtr(ptr, elem, k, offset, not_flat, not_null_free, flat, null_free, atomic, refined_type))->hashcons();
6738 }
6739
6740 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) {
6741 const Type* etype;
6742 if (k->is_obj_array_klass()) {
6743 // Element is an object array. Recursively call ourself.
6744 ciKlass* eklass = k->as_obj_array_klass()->element_klass();
6745 etype = TypeKlassPtr::make(eklass, interface_handling)->cast_to_exactness(false);
6746 k = nullptr;
6747 } else if (k->is_type_array_klass()) {
6748 // Element is an typeArray
6749 etype = get_const_basic_type(k->as_type_array_klass()->element_type());
6750 } else {
6751 ShouldNotReachHere();
6752 }
6753
6754 return TypeAryKlassPtr::make(ptr, etype, k, offset, not_flat, not_null_free, flat, null_free, atomic, refined_type);
6755 }
6756
6757 const TypeAryKlassPtr* TypeAryKlassPtr::make(ciKlass* klass, InterfaceHandling interface_handling) {
6758 ciArrayKlass* k = klass->as_array_klass();
6759 if (k->is_refined()) {
6760 return TypeAryKlassPtr::make(Constant, k, Offset(0), interface_handling, !k->is_flat_array_klass(), !k->is_elem_null_free(),
6761 k->is_flat_array_klass(), k->is_elem_null_free(), k->is_elem_atomic(), true);
6762 } else {
6763 // Use the default combination to canonicalize all non-refined klass pointers
6764 return TypeAryKlassPtr::make(Constant, k, Offset(0), interface_handling, true, true, false, false, true, false);
6765 }
6766 }
6767
6768 const TypeAryKlassPtr* TypeAryKlassPtr::cast_to_non_refined() const {
6769 assert(is_refined_type(), "must be a refined type");
6770 PTR ptr = _ptr;
6771 // There can be multiple refined array types corresponding to a single unrefined type
6772 if (ptr == NotNull && elem()->is_klassptr()->klass_is_exact()) {
6773 ptr = Constant;
6774 }
6775 return make(ptr, elem(), nullptr, _offset, true, true, false, false, true, false);
6776 }
6777
6778 // Get the (non-)refined array klass ptr
6779 const TypeAryKlassPtr* TypeAryKlassPtr::cast_to_refined_array_klass_ptr(bool refined) const {
6780 if ((refined == is_refined_type()) || !klass_is_exact() || !exact_klass()->is_obj_array_klass()) {
6781 return this;
6782 }
6783 ciArrayKlass* k = exact_klass()->as_array_klass();
6784 k = ciObjArrayKlass::make(k->element_klass(), refined);
6785 return make(k, trust_interfaces);
6786 }
6787
6788 //------------------------------eq---------------------------------------------
6789 // Structural equality check for Type representations
6790 bool TypeAryKlassPtr::eq(const Type *t) const {
6791 const TypeAryKlassPtr *p = t->is_aryklassptr();
6792 return
6793 _elem == p->_elem && // Check array
6794 _flat == p->_flat &&
6795 _not_flat == p->_not_flat &&
6796 _null_free == p->_null_free &&
6797 _not_null_free == p->_not_null_free &&
6798 _atomic == p->_atomic &&
6799 _refined_type == p->_refined_type &&
6800 TypeKlassPtr::eq(p); // Check sub-parts
6801 }
6802
6803 //------------------------------hash-------------------------------------------
6804 // Type-specific hashing function.
6805 uint TypeAryKlassPtr::hash(void) const {
6806 return (uint)(uintptr_t)_elem + TypeKlassPtr::hash() + (uint)(_not_flat ? 43 : 0) +
6807 (uint)(_not_null_free ? 44 : 0) + (uint)(_flat ? 45 : 0) + (uint)(_null_free ? 46 : 0) + (uint)(_atomic ? 47 : 0) + (uint)(_refined_type ? 48 : 0);
6808 }
6809
6810 //----------------------compute_klass------------------------------------------
6811 // Compute the defining klass for this class
6812 ciKlass* TypeAryPtr::compute_klass() const {
6813 // Compute _klass based on element type.
6814 ciKlass* k_ary = nullptr;
6815 const TypeInstPtr *tinst;
6816 const TypeAryPtr *tary;
6817 const Type* el = elem();
6818 if (el->isa_narrowoop()) {
6819 el = el->make_ptr();
6820 }
6821
6822 // Get element klass
6823 if ((tinst = el->isa_instptr()) != nullptr) {
6824 // Leave k_ary at nullptr.
6825 } else if ((tary = el->isa_aryptr()) != nullptr) {
6826 // Leave k_ary at nullptr.
6827 } else if ((el->base() == Type::Top) ||
6828 (el->base() == Type::Bottom)) {
6829 // element type of Bottom occurs from meet of basic type
6830 // and object; Top occurs when doing join on Bottom.
6831 // Leave k_ary at null.
6832 } else {
6833 assert(!el->isa_int(), "integral arrays must be pre-equipped with a class");
6834 // Compute array klass directly from basic type
6835 k_ary = ciTypeArrayKlass::make(el->basic_type());
6836 }
6837 return k_ary;
6838 }
6839
6840 //------------------------------klass------------------------------------------
6841 // Return the defining klass for this class
6842 ciKlass* TypeAryPtr::klass() const {
6843 if( _klass ) return _klass; // Return cached value, if possible
6844
6845 // Oops, need to compute _klass and cache it
6846 ciKlass* k_ary = compute_klass();
6847
6848 if( this != TypeAryPtr::OOPS && this->dual() != TypeAryPtr::OOPS ) {
6849 // The _klass field acts as a cache of the underlying
6850 // ciKlass for this array type. In order to set the field,
6851 // we need to cast away const-ness.
6852 //
6853 // IMPORTANT NOTE: we *never* set the _klass field for the
6854 // type TypeAryPtr::OOPS. This Type is shared between all
6855 // active compilations. However, the ciKlass which represents
6856 // this Type is *not* shared between compilations, so caching
6857 // this value would result in fetching a dangling pointer.
6858 //
6859 // Recomputing the underlying ciKlass for each request is
6860 // a bit less efficient than caching, but calls to
6861 // TypeAryPtr::OOPS->klass() are not common enough to matter.
6862 ((TypeAryPtr*)this)->_klass = k_ary;
6863 }
6864 return k_ary;
6865 }
6866
6867 // Is there a single ciKlass* that can represent that type?
6868 ciKlass* TypeAryPtr::exact_klass_helper() const {
6869 if (_ary->_elem->make_ptr() && _ary->_elem->make_ptr()->isa_oopptr()) {
6870 ciKlass* k = _ary->_elem->make_ptr()->is_oopptr()->exact_klass_helper();
6871 if (k == nullptr) {
6872 return nullptr;
6873 }
6874 if (k->is_array_klass() && k->as_array_klass()->is_refined()) {
6875 // We have no mechanism to create an array of refined arrays
6876 k = ciObjArrayKlass::make(k->as_array_klass()->element_klass(), false);
6877 }
6878 if (klass_is_exact()) {
6879 return ciObjArrayKlass::make(k, true, is_null_free(), is_atomic());
6880 } else {
6881 // We may reach here if called recursively, must be an unrefined type then
6882 return ciObjArrayKlass::make(k, false);
6883 }
6884 }
6885
6886 return klass();
6887 }
6888
6889 const Type* TypeAryPtr::base_element_type(int& dims) const {
6890 const Type* elem = this->elem();
6891 dims = 1;
6892 while (elem->make_ptr() && elem->make_ptr()->isa_aryptr()) {
6893 elem = elem->make_ptr()->is_aryptr()->elem();
6894 dims++;
6895 }
6896 return elem;
6897 }
6898
6899 //------------------------------add_offset-------------------------------------
6900 // Access internals of klass object
6901 const TypePtr* TypeAryKlassPtr::add_offset(intptr_t offset) const {
6902 return make(_ptr, elem(), klass(), xadd_offset(offset), is_not_flat(), is_not_null_free(), _flat, _null_free, _atomic, _refined_type);
6903 }
6904
6905 const TypeAryKlassPtr* TypeAryKlassPtr::with_offset(intptr_t offset) const {
6906 return make(_ptr, elem(), klass(), Offset(offset), is_not_flat(), is_not_null_free(), _flat, _null_free, _atomic, _refined_type);
6907 }
6908
6909 //------------------------------cast_to_ptr_type-------------------------------
6910 const TypeAryKlassPtr* TypeAryKlassPtr::cast_to_ptr_type(PTR ptr) const {
6911 assert(_base == AryKlassPtr, "subclass must override cast_to_ptr_type");
6912 if (ptr == _ptr) return this;
6913 return make(ptr, elem(), _klass, _offset, is_not_flat(), is_not_null_free(), _flat, _null_free, _atomic, _refined_type);
6914 }
6915
6916 bool TypeAryKlassPtr::must_be_exact() const {
6917 assert(klass_is_exact(), "precondition");
6918 if (_elem == Type::BOTTOM || _elem == Type::TOP) {
6919 return false;
6920 }
6921 const TypeKlassPtr* elem = _elem->isa_klassptr();
6922 if (elem == nullptr) {
6923 // primitive arrays
6924 return true;
6925 }
6926
6927 // refined types are final
6928 return _refined_type;
6929 }
6930
6931 //-----------------------------cast_to_exactness-------------------------------
6932 const TypeKlassPtr *TypeAryKlassPtr::cast_to_exactness(bool klass_is_exact) const {
6933 if (klass_is_exact == this->klass_is_exact()) {
6934 return this;
6935 }
6936 if (!klass_is_exact && must_be_exact()) {
6937 return this;
6938 }
6939 const Type* elem = this->elem();
6940 if (elem->isa_klassptr() && !klass_is_exact) {
6941 elem = elem->is_klassptr()->cast_to_exactness(klass_is_exact);
6942 }
6943
6944 if (klass_is_exact) {
6945 // cast_to_exactness(true) really means get the LCA of all values represented by this
6946 // TypeAryKlassPtr. As a result, it must be an unrefined klass pointer.
6947 return make(Constant, elem, nullptr, _offset, true, true, false, false, true, false);
6948 } else {
6949 // cast_to_exactness(false) means get the TypeAryKlassPtr representing all values that subtype
6950 // this value
6951 bool not_inline = !_elem->isa_instklassptr() || !_elem->is_instklassptr()->instance_klass()->can_be_inline_klass();
6952 bool not_flat = !UseArrayFlattening || not_inline ||
6953 (_elem->isa_instklassptr() && _elem->is_instklassptr()->instance_klass()->is_inlinetype() && !_elem->is_instklassptr()->instance_klass()->maybe_flat_in_array());
6954 bool not_null_free = not_inline;
6955 bool atomic = not_flat;
6956 return make(NotNull, elem, nullptr, _offset, not_flat, not_null_free, false, false, atomic, false);
6957 }
6958 }
6959
6960 //-----------------------------as_instance_type--------------------------------
6961 // Corresponding type for an instance of the given class.
6962 // It will be NotNull, and exact if and only if the klass type is exact.
6963 const TypeOopPtr* TypeAryKlassPtr::as_instance_type(bool klass_change) const {
6964 ciKlass* k = klass();
6965 bool xk = klass_is_exact();
6966 const Type* el = nullptr;
6967 if (elem()->isa_klassptr()) {
6968 el = elem()->is_klassptr()->as_instance_type(false)->cast_to_exactness(false);
6969 k = nullptr;
6970 } else {
6971 el = elem();
6972 }
6973 bool null_free = _null_free;
6974 if (null_free && el->isa_ptr()) {
6975 el = el->is_ptr()->join_speculative(TypePtr::NOTNULL);
6976 }
6977 return TypeAryPtr::make(TypePtr::BotPTR, TypeAry::make(el, TypeInt::POS, false, is_flat(), is_not_flat(), is_not_null_free(), is_atomic()), k, xk, Offset(0));
6978 }
6979
6980
6981 //------------------------------xmeet------------------------------------------
6982 // Compute the MEET of two types, return a new Type object.
6983 const Type *TypeAryKlassPtr::xmeet( const Type *t ) const {
6984 // Perform a fast test for common case; meeting the same types together.
6985 if( this == t ) return this; // Meeting same type-rep?
6986
6987 // Current "this->_base" is Pointer
6988 switch (t->base()) { // switch on original type
6989
6990 case Int: // Mixing ints & oops happens when javac
6991 case Long: // reuses local variables
6992 case HalfFloatTop:
6993 case HalfFloatCon:
6994 case HalfFloatBot:
6995 case FloatTop:
6996 case FloatCon:
6997 case FloatBot:
6998 case DoubleTop:
6999 case DoubleCon:
7000 case DoubleBot:
7001 case NarrowOop:
7002 case NarrowKlass:
7003 case Bottom: // Ye Olde Default
7004 return Type::BOTTOM;
7005 case Top:
7006 return this;
7007
7008 default: // All else is a mistake
7009 typerr(t);
7010
7011 case AnyPtr: { // Meeting to AnyPtrs
7012 // Found an AnyPtr type vs self-KlassPtr type
7013 const TypePtr *tp = t->is_ptr();
7014 Offset offset = meet_offset(tp->offset());
7015 PTR ptr = meet_ptr(tp->ptr());
7016 switch (tp->ptr()) {
7017 case TopPTR:
7018 return this;
7019 case Null:
7020 if( ptr == Null ) return TypePtr::make(AnyPtr, ptr, offset, tp->speculative(), tp->inline_depth());
7021 case AnyNull:
7022 return make(ptr, _elem, klass(), offset, is_not_flat(), is_not_null_free(), is_flat(), is_null_free(), is_atomic(), is_refined_type());
7023 case BotPTR:
7024 case NotNull:
7025 return TypePtr::make(AnyPtr, ptr, offset, tp->speculative(), tp->inline_depth());
7026 default: typerr(t);
7027 }
7028 }
7029
7030 case RawPtr:
7031 case MetadataPtr:
7032 case OopPtr:
7033 case AryPtr: // Meet with AryPtr
7034 case InstPtr: // Meet with InstPtr
7035 return TypePtr::BOTTOM;
7036
7037 //
7038 // A-top }
7039 // / | \ } Tops
7040 // B-top A-any C-top }
7041 // | / | \ | } Any-nulls
7042 // B-any | C-any }
7043 // | | |
7044 // B-con A-con C-con } constants; not comparable across classes
7045 // | | |
7046 // B-not | C-not }
7047 // | \ | / | } not-nulls
7048 // B-bot A-not C-bot }
7049 // \ | / } Bottoms
7050 // A-bot }
7051 //
7052
7053 case AryKlassPtr: { // Meet two KlassPtr types
7054 const TypeAryKlassPtr *tap = t->is_aryklassptr();
7055 Offset off = meet_offset(tap->offset());
7056 const Type* elem = _elem->meet(tap->_elem);
7057 PTR ptr = meet_ptr(tap->ptr());
7058 ciKlass* res_klass = nullptr;
7059 bool res_xk = false;
7060 bool res_flat = false;
7061 bool res_not_flat = false;
7062 bool res_not_null_free = false;
7063 bool res_atomic = false;
7064 MeetResult res = meet_aryptr(ptr, elem, this, tap,
7065 res_klass, res_xk, res_flat, res_not_flat, res_not_null_free, res_atomic);
7066 assert(res_xk == (ptr == Constant), "");
7067 bool flat = meet_flat(tap->_flat);
7068 bool null_free = meet_null_free(tap->_null_free);
7069 bool atomic = meet_atomic(tap->_atomic);
7070 bool refined_type = _refined_type && tap->_refined_type;
7071 if (res == NOT_SUBTYPE) {
7072 flat = false;
7073 null_free = false;
7074 atomic = false;
7075 refined_type = false;
7076 } else if (res == SUBTYPE) {
7077 if (above_centerline(tap->ptr()) && !above_centerline(this->ptr())) {
7078 flat = _flat;
7079 null_free = _null_free;
7080 atomic = _atomic;
7081 refined_type = _refined_type;
7082 } else if (above_centerline(this->ptr()) && !above_centerline(tap->ptr())) {
7083 flat = tap->_flat;
7084 null_free = tap->_null_free;
7085 atomic = tap->_atomic;
7086 refined_type = tap->_refined_type;
7087 } else if (above_centerline(this->ptr()) && above_centerline(tap->ptr())) {
7088 flat = _flat || tap->_flat;
7089 null_free = _null_free || tap->_null_free;
7090 atomic = _atomic || tap->_atomic;
7091 refined_type = _refined_type || tap->_refined_type;
7092 } else if (res_xk && _refined_type != tap->_refined_type) {
7093 // This can happen if the phi emitted by LibraryCallKit::load_default_refined_array_klass/load_non_refined_array_klass
7094 // is processed before the typeArray guard is folded. Both inputs are constant but the input corresponding to the
7095 // typeArray will go away. Don't constant fold it yet but wait for the control input to collapse.
7096 ptr = PTR::NotNull;
7097 }
7098 }
7099 return make(ptr, elem, res_klass, off, res_not_flat, res_not_null_free, flat, null_free, atomic, refined_type);
7100 } // End of case KlassPtr
7101 case InstKlassPtr: {
7102 const TypeInstKlassPtr *tp = t->is_instklassptr();
7103 Offset offset = meet_offset(tp->offset());
7104 PTR ptr = meet_ptr(tp->ptr());
7105 const TypeInterfaces* interfaces = meet_interfaces(tp);
7106 const TypeInterfaces* tp_interfaces = tp->_interfaces;
7107 const TypeInterfaces* this_interfaces = _interfaces;
7108
7109 switch (ptr) {
7110 case TopPTR:
7111 case AnyNull: // Fall 'down' to dual of object klass
7112 // For instances when a subclass meets a superclass we fall
7113 // below the centerline when the superclass is exact. We need to
7114 // do the same here.
7115 //
7116 // Flat in array: See explanation for meet with TypeInstPtr in TypeAryPtr::xmeet_helper().
7117 if (tp->klass()->equals(ciEnv::current()->Object_klass()) && this_interfaces->contains(tp_interfaces) &&
7118 !tp->klass_is_exact() && !tp->is_not_flat_in_array()) {
7119 return TypeAryKlassPtr::make(ptr, _elem, _klass, offset, is_not_flat(), is_not_null_free(), is_flat(), is_null_free(), is_atomic(), is_refined_type());
7120 } else {
7121 // cannot subclass, so the meet has to fall badly below the centerline
7122 ptr = NotNull;
7123 interfaces = this_interfaces->intersection_with(tp->_interfaces);
7124 FlatInArray flat_in_array = meet_flat_in_array(NotFlat, tp->flat_in_array());
7125 return TypeInstKlassPtr::make(ptr, ciEnv::current()->Object_klass(), interfaces, offset, flat_in_array);
7126 }
7127 case Constant:
7128 case NotNull:
7129 case BotPTR: { // Fall down to object klass
7130 // LCA is object_klass, but if we subclass from the top we can do better
7131 if (above_centerline(tp->ptr())) {
7132 // If 'tp' is above the centerline and it is Object class
7133 // then we can subclass in the Java class hierarchy.
7134 // For instances when a subclass meets a superclass we fall
7135 // below the centerline when the superclass is exact. We need
7136 // to do the same here.
7137 //
7138 // Flat in array: See explanation for meet with TypeInstPtr in TypeAryPtr::xmeet_helper().
7139 if (tp->klass()->equals(ciEnv::current()->Object_klass()) && this_interfaces->contains(tp_interfaces) &&
7140 !tp->klass_is_exact() && !tp->is_not_flat_in_array()) {
7141 // that is, my array type is a subtype of 'tp' klass
7142 return make(ptr, _elem, _klass, offset, is_not_flat(), is_not_null_free(), is_flat(), is_null_free(), is_atomic(), is_refined_type());
7143 }
7144 }
7145 // The other case cannot happen, since t cannot be a subtype of an array.
7146 // The meet falls down to Object class below centerline.
7147 if (ptr == Constant)
7148 ptr = NotNull;
7149 interfaces = this_interfaces->intersection_with(tp_interfaces);
7150 FlatInArray flat_in_array = meet_flat_in_array(NotFlat, tp->flat_in_array());
7151 return TypeInstKlassPtr::make(ptr, ciEnv::current()->Object_klass(), interfaces, offset, flat_in_array);
7152 }
7153 default: typerr(t);
7154 }
7155 }
7156
7157 } // End of switch
7158 return this; // Return the double constant
7159 }
7160
7161 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) {
7162 static_assert(std::is_base_of<T2, T1>::value, "");
7163
7164 if (other->klass() == ciEnv::current()->Object_klass() && other->_interfaces->empty() && other_exact) {
7165 return true;
7166 }
7167
7168 int dummy;
7169 bool this_top_or_bottom = (this_one->base_element_type(dummy) == Type::TOP || this_one->base_element_type(dummy) == Type::BOTTOM);
7170
7171 if (!this_one->is_loaded() || !other->is_loaded() || this_top_or_bottom) {
7172 return false;
7173 }
7174
7175 if (this_one->is_instance_type(other)) {
7176 return other->klass() == ciEnv::current()->Object_klass() && this_one->_interfaces->contains(other->_interfaces) &&
7177 other_exact;
7178 }
7179
7180 assert(this_one->is_array_type(other), "");
7181 const T1* other_ary = this_one->is_array_type(other);
7182 bool other_top_or_bottom = (other_ary->base_element_type(dummy) == Type::TOP || other_ary->base_element_type(dummy) == Type::BOTTOM);
7183 if (other_top_or_bottom) {
7184 return false;
7185 }
7186
7187 const TypePtr* other_elem = other_ary->elem()->make_ptr();
7188 const TypePtr* this_elem = this_one->elem()->make_ptr();
7189 if (this_elem != nullptr && other_elem != nullptr) {
7190 if (other->is_null_free() && !this_one->is_null_free()) {
7191 return false; // A nullable array can't be a subtype of a null-free array
7192 }
7193 return this_one->is_reference_type(this_elem)->is_java_subtype_of_helper(this_one->is_reference_type(other_elem), this_exact, other_exact);
7194 }
7195 if (this_elem == nullptr && other_elem == nullptr) {
7196 return this_one->klass()->is_subtype_of(other->klass());
7197 }
7198 return false;
7199 }
7200
7201 bool TypeAryKlassPtr::is_java_subtype_of_helper(const TypeKlassPtr* other, bool this_exact, bool other_exact) const {
7202 return TypePtr::is_java_subtype_of_helper_for_array(this, other, this_exact, other_exact);
7203 }
7204
7205 template <class T1, class T2> bool TypePtr::is_same_java_type_as_helper_for_array(const T1* this_one, const T2* other) {
7206 static_assert(std::is_base_of<T2, T1>::value, "");
7207
7208 int dummy;
7209 bool this_top_or_bottom = (this_one->base_element_type(dummy) == Type::TOP || this_one->base_element_type(dummy) == Type::BOTTOM);
7210
7211 if (!this_one->is_array_type(other) ||
7212 !this_one->is_loaded() || !other->is_loaded() || this_top_or_bottom) {
7213 return false;
7214 }
7215 const T1* other_ary = this_one->is_array_type(other);
7216 bool other_top_or_bottom = (other_ary->base_element_type(dummy) == Type::TOP || other_ary->base_element_type(dummy) == Type::BOTTOM);
7217
7218 if (other_top_or_bottom) {
7219 return false;
7220 }
7221
7222 const TypePtr* other_elem = other_ary->elem()->make_ptr();
7223 const TypePtr* this_elem = this_one->elem()->make_ptr();
7224 if (other_elem != nullptr && this_elem != nullptr) {
7225 return this_one->is_reference_type(this_elem)->is_same_java_type_as(this_one->is_reference_type(other_elem));
7226 }
7227 if (other_elem == nullptr && this_elem == nullptr) {
7228 return this_one->klass()->equals(other->klass());
7229 }
7230 return false;
7231 }
7232
7233 bool TypeAryKlassPtr::is_same_java_type_as_helper(const TypeKlassPtr* other) const {
7234 return TypePtr::is_same_java_type_as_helper_for_array(this, other);
7235 }
7236
7237 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) {
7238 static_assert(std::is_base_of<T2, T1>::value, "");
7239 if (other->klass() == ciEnv::current()->Object_klass() && other->_interfaces->empty() && other_exact) {
7240 return true;
7241 }
7242 if (!this_one->is_loaded() || !other->is_loaded()) {
7243 return true;
7244 }
7245 if (this_one->is_instance_type(other)) {
7246 return other->klass()->equals(ciEnv::current()->Object_klass()) &&
7247 this_one->_interfaces->contains(other->_interfaces);
7248 }
7249
7250 int dummy;
7251 bool this_top_or_bottom = (this_one->base_element_type(dummy) == Type::TOP || this_one->base_element_type(dummy) == Type::BOTTOM);
7252 if (this_top_or_bottom) {
7253 return true;
7254 }
7255
7256 assert(this_one->is_array_type(other), "");
7257
7258 const T1* other_ary = this_one->is_array_type(other);
7259 bool other_top_or_bottom = (other_ary->base_element_type(dummy) == Type::TOP || other_ary->base_element_type(dummy) == Type::BOTTOM);
7260 if (other_top_or_bottom) {
7261 return true;
7262 }
7263 if (this_exact && other_exact) {
7264 return this_one->is_java_subtype_of(other);
7265 }
7266
7267 const TypePtr* this_elem = this_one->elem()->make_ptr();
7268 const TypePtr* other_elem = other_ary->elem()->make_ptr();
7269 if (other_elem != nullptr && this_elem != nullptr) {
7270 return this_one->is_reference_type(this_elem)->maybe_java_subtype_of_helper(this_one->is_reference_type(other_elem), this_exact, other_exact);
7271 }
7272 if (other_elem == nullptr && this_elem == nullptr) {
7273 return this_one->klass()->is_subtype_of(other->klass());
7274 }
7275 return false;
7276 }
7277
7278 bool TypeAryKlassPtr::maybe_java_subtype_of_helper(const TypeKlassPtr* other, bool this_exact, bool other_exact) const {
7279 return TypePtr::maybe_java_subtype_of_helper_for_array(this, other, this_exact, other_exact);
7280 }
7281
7282 //------------------------------xdual------------------------------------------
7283 // Dual: compute field-by-field dual
7284 const Type *TypeAryKlassPtr::xdual() const {
7285 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);
7286 }
7287
7288 // Is there a single ciKlass* that can represent that type?
7289 ciKlass* TypeAryKlassPtr::exact_klass_helper() const {
7290 if (elem()->isa_klassptr()) {
7291 ciKlass* k = elem()->is_klassptr()->exact_klass_helper();
7292 if (k == nullptr) {
7293 return nullptr;
7294 }
7295 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());
7296 k = ciArrayKlass::make(k, is_null_free(), is_atomic(), _refined_type);
7297 return k;
7298 }
7299
7300 return klass();
7301 }
7302
7303 ciKlass* TypeAryKlassPtr::klass() const {
7304 if (_klass != nullptr) {
7305 return _klass;
7306 }
7307 ciKlass* k = nullptr;
7308 if (elem()->isa_klassptr()) {
7309 // leave null
7310 } else if ((elem()->base() == Type::Top) ||
7311 (elem()->base() == Type::Bottom)) {
7312 } else {
7313 k = ciTypeArrayKlass::make(elem()->basic_type());
7314 ((TypeAryKlassPtr*)this)->_klass = k;
7315 }
7316 return k;
7317 }
7318
7319 //------------------------------dump2------------------------------------------
7320 // Dump Klass Type
7321 #ifndef PRODUCT
7322 void TypeAryKlassPtr::dump2( Dict & d, uint depth, outputStream *st ) const {
7323 st->print("aryklassptr:[");
7324 _elem->dump2(d, depth, st);
7325 _interfaces->dump(st);
7326 st->print(":%s", ptr_msg[_ptr]);
7327 if (_flat) st->print(":flat");
7328 if (_null_free) st->print(":null free");
7329 if (_atomic) st->print(":atomic");
7330 if (_refined_type) st->print(":refined_type");
7331 if (Verbose) {
7332 if (_not_flat) st->print(":not flat");
7333 if (_not_null_free) st->print(":nullable");
7334 }
7335 dump_offset(st);
7336 }
7337 #endif
7338
7339 const Type* TypeAryKlassPtr::base_element_type(int& dims) const {
7340 const Type* elem = this->elem();
7341 dims = 1;
7342 while (elem->isa_aryklassptr()) {
7343 elem = elem->is_aryklassptr()->elem();
7344 dims++;
7345 }
7346 return elem;
7347 }
7348
7349 //=============================================================================
7350 // Convenience common pre-built types.
7351
7352 //------------------------------make-------------------------------------------
7353 const TypeFunc *TypeFunc::make(const TypeTuple *domain_sig, const TypeTuple* domain_cc,
7354 const TypeTuple* range_sig, const TypeTuple* range_cc,
7355 bool scalarized_return) {
7356 return (TypeFunc*)(new TypeFunc(domain_sig, domain_cc, range_sig, range_cc, scalarized_return))->hashcons();
7357 }
7358
7359 const TypeFunc *TypeFunc::make(const TypeTuple *domain, const TypeTuple *range) {
7360 return make(domain, domain, range, range);
7361 }
7362
7363 //------------------------------osr_domain-----------------------------
7364 const TypeTuple* osr_domain() {
7365 const Type **fields = TypeTuple::fields(2);
7366 fields[TypeFunc::Parms+0] = TypeRawPtr::BOTTOM; // address of osr buffer
7367 return TypeTuple::make(TypeFunc::Parms+1, fields);
7368 }
7369
7370 // Build a TypeFunc with both the Java-signature view ('sig') and the actual calling-
7371 // convention view ('cc') of inline types. In the signature, an inline type is a single
7372 // oop slot. In the scalarized calling convention, it is expanded to its field
7373 // values (plus null marker and optional oop to the heap buffer).
7374 // The 'is_call' argument distinguishes between the return signature of a method at calls
7375 // vs. at compilation of that method because at calls we return an additional null marker field.
7376 // For OSR and mismatching calls, we fall back to the non-scalarized argument view.
7377 const TypeFunc* TypeFunc::make(ciMethod* method, bool is_call, bool is_osr_compilation) {
7378 Compile* C = Compile::current();
7379 const TypeFunc* tf = nullptr;
7380 // Inline types are not passed/returned by reference, instead each field of
7381 // the inline type is passed/returned as an argument. We maintain two views of
7382 // the argument/return list here: one based on the signature (with an inline
7383 // type argument/return as a single slot), one based on the actual calling
7384 // convention (with an inline type argument/return as a list of its fields).
7385 bool has_scalar_args = method->has_scalarized_args() && !is_osr_compilation;
7386 // Fall back to the non-scalarized calling convention when compiling a call via a mismatching method
7387 if (is_call && method->mismatch()) {
7388 has_scalar_args = false;
7389 }
7390 ciSignature* sig = method->signature();
7391 bool has_scalar_ret = !method->is_native() && sig->return_type()->is_inlinetype() && sig->return_type()->as_inline_klass()->can_be_returned_as_fields();
7392 // Don't cache on scalarized return because the range depends on 'is_call'
7393 if (!is_osr_compilation && !has_scalar_ret) {
7394 tf = C->last_tf(method); // check cache
7395 if (tf != nullptr) return tf; // The hit rate here is almost 50%.
7396 }
7397 const TypeTuple* domain_sig = is_osr_compilation ? osr_domain() : TypeTuple::make_domain(method, ignore_interfaces, false);
7398 const TypeTuple* domain_cc = has_scalar_args ? TypeTuple::make_domain(method, ignore_interfaces, true) : domain_sig;
7399 const TypeTuple* range_sig = TypeTuple::make_range(sig, ignore_interfaces);
7400 const TypeTuple* range_cc = has_scalar_ret ? TypeTuple::make_range(sig, ignore_interfaces, true, is_call) : range_sig;
7401 tf = TypeFunc::make(domain_sig, domain_cc, range_sig, range_cc, has_scalar_ret);
7402 if (!is_osr_compilation && !has_scalar_ret) {
7403 C->set_last_tf(method, tf); // fill cache
7404 }
7405 return tf;
7406 }
7407
7408 //------------------------------meet-------------------------------------------
7409 // Compute the MEET of two types. It returns a new Type object.
7410 const Type *TypeFunc::xmeet( const Type *t ) const {
7411 // Perform a fast test for common case; meeting the same types together.
7412 if( this == t ) return this; // Meeting same type-rep?
7413
7414 // Current "this->_base" is Func
7415 switch (t->base()) { // switch on original type
7416
7417 case Bottom: // Ye Olde Default
7418 return t;
7419
7420 default: // All else is a mistake
7421 typerr(t);
7422
7423 case Top:
7424 break;
7425 }
7426 return this; // Return the double constant
7427 }
7428
7429 //------------------------------xdual------------------------------------------
7430 // Dual: compute field-by-field dual
7431 const Type *TypeFunc::xdual() const {
7432 return this;
7433 }
7434
7435 //------------------------------eq---------------------------------------------
7436 // Structural equality check for Type representations
7437 bool TypeFunc::eq( const Type *t ) const {
7438 const TypeFunc *a = (const TypeFunc*)t;
7439 return _domain_sig == a->_domain_sig &&
7440 _domain_cc == a->_domain_cc &&
7441 _range_sig == a->_range_sig &&
7442 _range_cc == a->_range_cc &&
7443 _scalarized_return == a->_scalarized_return;
7444 }
7445
7446 //------------------------------hash-------------------------------------------
7447 // Type-specific hashing function.
7448 uint TypeFunc::hash(void) const {
7449 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;
7450 }
7451
7452 //------------------------------dump2------------------------------------------
7453 // Dump Function Type
7454 #ifndef PRODUCT
7455 void TypeFunc::dump2( Dict &d, uint depth, outputStream *st ) const {
7456 if( _range_sig->cnt() <= Parms )
7457 st->print("void");
7458 else {
7459 uint i;
7460 for (i = Parms; i < _range_sig->cnt()-1; i++) {
7461 _range_sig->field_at(i)->dump2(d,depth,st);
7462 st->print("/");
7463 }
7464 _range_sig->field_at(i)->dump2(d,depth,st);
7465 }
7466 st->print(" ");
7467 st->print("( ");
7468 if( !depth || d[this] ) { // Check for recursive dump
7469 st->print("...)");
7470 return;
7471 }
7472 d.Insert((void*)this,(void*)this); // Stop recursion
7473 if (Parms < _domain_sig->cnt())
7474 _domain_sig->field_at(Parms)->dump2(d,depth-1,st);
7475 for (uint i = Parms+1; i < _domain_sig->cnt(); i++) {
7476 st->print(", ");
7477 _domain_sig->field_at(i)->dump2(d,depth-1,st);
7478 }
7479 st->print(" )");
7480 }
7481 #endif
7482
7483 //------------------------------singleton--------------------------------------
7484 // TRUE if Type is a singleton type, FALSE otherwise. Singletons are simple
7485 // constants (Ldi nodes). Singletons are integer, float or double constants
7486 // or a single symbol.
7487 bool TypeFunc::singleton(void) const {
7488 return false; // Never a singleton
7489 }
7490
7491 bool TypeFunc::empty(void) const {
7492 return false; // Never empty
7493 }
7494
7495
7496 BasicType TypeFunc::return_type() const{
7497 if (range_sig()->cnt() == TypeFunc::Parms) {
7498 return T_VOID;
7499 }
7500 return range_sig()->field_at(TypeFunc::Parms)->basic_type();
7501 }