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