1 /*
2 * Copyright (c) 1997, 2020, 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 "precompiled.hpp"
26 #include "ci/ciMethodData.hpp"
27 #include "ci/ciTypeFlow.hpp"
28 #include "classfile/javaClasses.hpp"
29 #include "classfile/symbolTable.hpp"
30 #include "compiler/compileLog.hpp"
31 #include "libadt/dict.hpp"
32 #include "memory/oopFactory.hpp"
33 #include "memory/resourceArea.hpp"
34 #include "oops/instanceKlass.hpp"
35 #include "oops/instanceMirrorKlass.hpp"
36 #include "oops/objArrayKlass.hpp"
37 #include "oops/typeArrayKlass.hpp"
38 #include "opto/matcher.hpp"
39 #include "opto/node.hpp"
40 #include "opto/opcodes.hpp"
41 #include "opto/type.hpp"
42 #include "utilities/powerOfTwo.hpp"
43
44 // Portions of code courtesy of Clifford Click
45
46 // Optimization - Graph Style
47
48 // Dictionary of types shared among compilations.
49 Dict* Type::_shared_type_dict = NULL;
50
51 // Array which maps compiler types to Basic Types
52 const Type::TypeInfo Type::_type_info[Type::lastype] = {
53 { Bad, T_ILLEGAL, "bad", false, Node::NotAMachineReg, relocInfo::none }, // Bad
54 { Control, T_ILLEGAL, "control", false, 0, relocInfo::none }, // Control
55 { Bottom, T_VOID, "top", false, 0, relocInfo::none }, // Top
56 { Bad, T_INT, "int:", false, Op_RegI, relocInfo::none }, // Int
57 { Bad, T_LONG, "long:", false, Op_RegL, relocInfo::none }, // Long
58 { Half, T_VOID, "half", false, 0, relocInfo::none }, // Half
59 { Bad, T_NARROWOOP, "narrowoop:", false, Op_RegN, relocInfo::none }, // NarrowOop
60 { Bad, T_NARROWKLASS,"narrowklass:", false, Op_RegN, relocInfo::none }, // NarrowKlass
61 { Bad, T_ILLEGAL, "tuple:", false, Node::NotAMachineReg, relocInfo::none }, // Tuple
62 { Bad, T_ARRAY, "array:", false, Node::NotAMachineReg, relocInfo::none }, // Array
63
64 #if defined(PPC64)
65 { Bad, T_ILLEGAL, "vectora:", false, Op_VecA, relocInfo::none }, // VectorA.
66 { Bad, T_ILLEGAL, "vectors:", false, 0, relocInfo::none }, // VectorS
67 { Bad, T_ILLEGAL, "vectord:", false, Op_RegL, relocInfo::none }, // VectorD
68 { Bad, T_ILLEGAL, "vectorx:", false, Op_VecX, relocInfo::none }, // VectorX
69 { Bad, T_ILLEGAL, "vectory:", false, 0, relocInfo::none }, // VectorY
70 { Bad, T_ILLEGAL, "vectorz:", false, 0, relocInfo::none }, // VectorZ
71 #elif defined(S390)
72 { Bad, T_ILLEGAL, "vectora:", false, Op_VecA, relocInfo::none }, // VectorA.
73 { Bad, T_ILLEGAL, "vectors:", false, 0, relocInfo::none }, // VectorS
74 { Bad, T_ILLEGAL, "vectord:", false, Op_RegL, relocInfo::none }, // VectorD
75 { Bad, T_ILLEGAL, "vectorx:", false, 0, relocInfo::none }, // VectorX
76 { Bad, T_ILLEGAL, "vectory:", false, 0, relocInfo::none }, // VectorY
77 { Bad, T_ILLEGAL, "vectorz:", false, 0, relocInfo::none }, // VectorZ
78 #else // all other
79 { Bad, T_ILLEGAL, "vectora:", false, Op_VecA, relocInfo::none }, // VectorA.
80 { Bad, T_ILLEGAL, "vectors:", false, Op_VecS, relocInfo::none }, // VectorS
81 { Bad, T_ILLEGAL, "vectord:", false, Op_VecD, relocInfo::none }, // VectorD
82 { Bad, T_ILLEGAL, "vectorx:", false, Op_VecX, relocInfo::none }, // VectorX
83 { Bad, T_ILLEGAL, "vectory:", false, Op_VecY, relocInfo::none }, // VectorY
84 { Bad, T_ILLEGAL, "vectorz:", false, Op_VecZ, relocInfo::none }, // VectorZ
85 #endif
86 { Bad, T_ADDRESS, "anyptr:", false, Op_RegP, relocInfo::none }, // AnyPtr
87 { Bad, T_ADDRESS, "rawptr:", false, Op_RegP, relocInfo::none }, // RawPtr
88 { Bad, T_OBJECT, "oop:", true, Op_RegP, relocInfo::oop_type }, // OopPtr
89 { Bad, T_OBJECT, "inst:", true, Op_RegP, relocInfo::oop_type }, // InstPtr
90 { Bad, T_OBJECT, "ary:", true, Op_RegP, relocInfo::oop_type }, // AryPtr
91 { Bad, T_METADATA, "metadata:", false, Op_RegP, relocInfo::metadata_type }, // MetadataPtr
92 { Bad, T_METADATA, "klass:", false, Op_RegP, relocInfo::metadata_type }, // KlassPtr
93 { Bad, T_OBJECT, "func", false, 0, relocInfo::none }, // Function
94 { Abio, T_ILLEGAL, "abIO", false, 0, relocInfo::none }, // Abio
95 { Return_Address, T_ADDRESS, "return_address",false, Op_RegP, relocInfo::none }, // Return_Address
96 { Memory, T_ILLEGAL, "memory", false, 0, relocInfo::none }, // Memory
97 { FloatBot, T_FLOAT, "float_top", false, Op_RegF, relocInfo::none }, // FloatTop
98 { FloatCon, T_FLOAT, "ftcon:", false, Op_RegF, relocInfo::none }, // FloatCon
99 { FloatTop, T_FLOAT, "float", false, Op_RegF, relocInfo::none }, // FloatBot
100 { DoubleBot, T_DOUBLE, "double_top", false, Op_RegD, relocInfo::none }, // DoubleTop
101 { DoubleCon, T_DOUBLE, "dblcon:", false, Op_RegD, relocInfo::none }, // DoubleCon
102 { DoubleTop, T_DOUBLE, "double", false, Op_RegD, relocInfo::none }, // DoubleBot
103 { Top, T_ILLEGAL, "bottom", false, 0, relocInfo::none } // Bottom
104 };
105
106 // Map ideal registers (machine types) to ideal types
107 const Type *Type::mreg2type[_last_machine_leaf];
108
109 // Map basic types to canonical Type* pointers.
110 const Type* Type:: _const_basic_type[T_CONFLICT+1];
111
112 // Map basic types to constant-zero Types.
113 const Type* Type:: _zero_type[T_CONFLICT+1];
114
115 // Map basic types to array-body alias types.
116 const TypeAryPtr* TypeAryPtr::_array_body_type[T_CONFLICT+1];
117
118 //=============================================================================
119 // Convenience common pre-built types.
120 const Type *Type::ABIO; // State-of-machine only
121 const Type *Type::BOTTOM; // All values
122 const Type *Type::CONTROL; // Control only
123 const Type *Type::DOUBLE; // All doubles
124 const Type *Type::FLOAT; // All floats
125 const Type *Type::HALF; // Placeholder half of doublewide type
126 const Type *Type::MEMORY; // Abstract store only
127 const Type *Type::RETURN_ADDRESS;
128 const Type *Type::TOP; // No values in set
129
130 //------------------------------get_const_type---------------------------
get_const_type(ciType * type)131 const Type* Type::get_const_type(ciType* type) {
132 if (type == NULL) {
133 return NULL;
134 } else if (type->is_primitive_type()) {
135 return get_const_basic_type(type->basic_type());
136 } else {
137 return TypeOopPtr::make_from_klass(type->as_klass());
138 }
139 }
140
141 //---------------------------array_element_basic_type---------------------------------
142 // Mapping to the array element's basic type.
array_element_basic_type() const143 BasicType Type::array_element_basic_type() const {
144 BasicType bt = basic_type();
145 if (bt == T_INT) {
146 if (this == TypeInt::INT) return T_INT;
147 if (this == TypeInt::CHAR) return T_CHAR;
148 if (this == TypeInt::BYTE) return T_BYTE;
149 if (this == TypeInt::BOOL) return T_BOOLEAN;
150 if (this == TypeInt::SHORT) return T_SHORT;
151 return T_VOID;
152 }
153 return bt;
154 }
155
156 // For two instance arrays of same dimension, return the base element types.
157 // Otherwise or if the arrays have different dimensions, return NULL.
get_arrays_base_elements(const Type * a1,const Type * a2,const TypeInstPtr ** e1,const TypeInstPtr ** e2)158 void Type::get_arrays_base_elements(const Type *a1, const Type *a2,
159 const TypeInstPtr **e1, const TypeInstPtr **e2) {
160
161 if (e1) *e1 = NULL;
162 if (e2) *e2 = NULL;
163 const TypeAryPtr* a1tap = (a1 == NULL) ? NULL : a1->isa_aryptr();
164 const TypeAryPtr* a2tap = (a2 == NULL) ? NULL : a2->isa_aryptr();
165
166 if (a1tap != NULL && a2tap != NULL) {
167 // Handle multidimensional arrays
168 const TypePtr* a1tp = a1tap->elem()->make_ptr();
169 const TypePtr* a2tp = a2tap->elem()->make_ptr();
170 while (a1tp && a1tp->isa_aryptr() && a2tp && a2tp->isa_aryptr()) {
171 a1tap = a1tp->is_aryptr();
172 a2tap = a2tp->is_aryptr();
173 a1tp = a1tap->elem()->make_ptr();
174 a2tp = a2tap->elem()->make_ptr();
175 }
176 if (a1tp && a1tp->isa_instptr() && a2tp && a2tp->isa_instptr()) {
177 if (e1) *e1 = a1tp->is_instptr();
178 if (e2) *e2 = a2tp->is_instptr();
179 }
180 }
181 }
182
183 //---------------------------get_typeflow_type---------------------------------
184 // Import a type produced by ciTypeFlow.
get_typeflow_type(ciType * type)185 const Type* Type::get_typeflow_type(ciType* type) {
186 switch (type->basic_type()) {
187
188 case ciTypeFlow::StateVector::T_BOTTOM:
189 assert(type == ciTypeFlow::StateVector::bottom_type(), "");
190 return Type::BOTTOM;
191
192 case ciTypeFlow::StateVector::T_TOP:
193 assert(type == ciTypeFlow::StateVector::top_type(), "");
194 return Type::TOP;
195
196 case ciTypeFlow::StateVector::T_NULL:
197 assert(type == ciTypeFlow::StateVector::null_type(), "");
198 return TypePtr::NULL_PTR;
199
200 case ciTypeFlow::StateVector::T_LONG2:
201 // The ciTypeFlow pass pushes a long, then the half.
202 // We do the same.
203 assert(type == ciTypeFlow::StateVector::long2_type(), "");
204 return TypeInt::TOP;
205
206 case ciTypeFlow::StateVector::T_DOUBLE2:
207 // The ciTypeFlow pass pushes double, then the half.
208 // Our convention is the same.
209 assert(type == ciTypeFlow::StateVector::double2_type(), "");
210 return Type::TOP;
211
212 case T_ADDRESS:
213 assert(type->is_return_address(), "");
214 return TypeRawPtr::make((address)(intptr_t)type->as_return_address()->bci());
215
216 default:
217 // make sure we did not mix up the cases:
218 assert(type != ciTypeFlow::StateVector::bottom_type(), "");
219 assert(type != ciTypeFlow::StateVector::top_type(), "");
220 assert(type != ciTypeFlow::StateVector::null_type(), "");
221 assert(type != ciTypeFlow::StateVector::long2_type(), "");
222 assert(type != ciTypeFlow::StateVector::double2_type(), "");
223 assert(!type->is_return_address(), "");
224
225 return Type::get_const_type(type);
226 }
227 }
228
229
230 //-----------------------make_from_constant------------------------------------
make_from_constant(ciConstant constant,bool require_constant,int stable_dimension,bool is_narrow_oop,bool is_autobox_cache)231 const Type* Type::make_from_constant(ciConstant constant, bool require_constant,
232 int stable_dimension, bool is_narrow_oop,
233 bool is_autobox_cache) {
234 switch (constant.basic_type()) {
235 case T_BOOLEAN: return TypeInt::make(constant.as_boolean());
236 case T_CHAR: return TypeInt::make(constant.as_char());
237 case T_BYTE: return TypeInt::make(constant.as_byte());
238 case T_SHORT: return TypeInt::make(constant.as_short());
239 case T_INT: return TypeInt::make(constant.as_int());
240 case T_LONG: return TypeLong::make(constant.as_long());
241 case T_FLOAT: return TypeF::make(constant.as_float());
242 case T_DOUBLE: return TypeD::make(constant.as_double());
243 case T_ARRAY:
244 case T_OBJECT: {
245 const Type* con_type = NULL;
246 ciObject* oop_constant = constant.as_object();
247 if (oop_constant->is_null_object()) {
248 con_type = Type::get_zero_type(T_OBJECT);
249 } else {
250 guarantee(require_constant || oop_constant->should_be_constant(), "con_type must get computed");
251 con_type = TypeOopPtr::make_from_constant(oop_constant, require_constant);
252 if (Compile::current()->eliminate_boxing() && is_autobox_cache) {
253 con_type = con_type->is_aryptr()->cast_to_autobox_cache();
254 }
255 if (stable_dimension > 0) {
256 assert(FoldStableValues, "sanity");
257 assert(!con_type->is_zero_type(), "default value for stable field");
258 con_type = con_type->is_aryptr()->cast_to_stable(true, stable_dimension);
259 }
260 }
261 if (is_narrow_oop) {
262 con_type = con_type->make_narrowoop();
263 }
264 return con_type;
265 }
266 case T_ILLEGAL:
267 // Invalid ciConstant returned due to OutOfMemoryError in the CI
268 assert(Compile::current()->env()->failing(), "otherwise should not see this");
269 return NULL;
270 default:
271 // Fall through to failure
272 return NULL;
273 }
274 }
275
check_mismatched_access(ciConstant con,BasicType loadbt,bool is_unsigned)276 static ciConstant check_mismatched_access(ciConstant con, BasicType loadbt, bool is_unsigned) {
277 BasicType conbt = con.basic_type();
278 switch (conbt) {
279 case T_BOOLEAN: conbt = T_BYTE; break;
280 case T_ARRAY: conbt = T_OBJECT; break;
281 default: break;
282 }
283 switch (loadbt) {
284 case T_BOOLEAN: loadbt = T_BYTE; break;
285 case T_NARROWOOP: loadbt = T_OBJECT; break;
286 case T_ARRAY: loadbt = T_OBJECT; break;
287 case T_ADDRESS: loadbt = T_OBJECT; break;
288 default: break;
289 }
290 if (conbt == loadbt) {
291 if (is_unsigned && conbt == T_BYTE) {
292 // LoadB (T_BYTE) with a small mask (<=8-bit) is converted to LoadUB (T_BYTE).
293 return ciConstant(T_INT, con.as_int() & 0xFF);
294 } else {
295 return con;
296 }
297 }
298 if (conbt == T_SHORT && loadbt == T_CHAR) {
299 // LoadS (T_SHORT) with a small mask (<=16-bit) is converted to LoadUS (T_CHAR).
300 return ciConstant(T_INT, con.as_int() & 0xFFFF);
301 }
302 return ciConstant(); // T_ILLEGAL
303 }
304
305 // Try to constant-fold a stable array element.
make_constant_from_array_element(ciArray * array,int off,int stable_dimension,BasicType loadbt,bool is_unsigned_load)306 const Type* Type::make_constant_from_array_element(ciArray* array, int off, int stable_dimension,
307 BasicType loadbt, bool is_unsigned_load) {
308 // Decode the results of GraphKit::array_element_address.
309 ciConstant element_value = array->element_value_by_offset(off);
310 if (element_value.basic_type() == T_ILLEGAL) {
311 return NULL; // wrong offset
312 }
313 ciConstant con = check_mismatched_access(element_value, loadbt, is_unsigned_load);
314
315 assert(con.basic_type() != T_ILLEGAL, "elembt=%s; loadbt=%s; unsigned=%d",
316 type2name(element_value.basic_type()), type2name(loadbt), is_unsigned_load);
317
318 if (con.is_valid() && // not a mismatched access
319 !con.is_null_or_zero()) { // not a default value
320 bool is_narrow_oop = (loadbt == T_NARROWOOP);
321 return Type::make_from_constant(con, /*require_constant=*/true, stable_dimension, is_narrow_oop, /*is_autobox_cache=*/false);
322 }
323 return NULL;
324 }
325
make_constant_from_field(ciInstance * holder,int off,bool is_unsigned_load,BasicType loadbt)326 const Type* Type::make_constant_from_field(ciInstance* holder, int off, bool is_unsigned_load, BasicType loadbt) {
327 ciField* field;
328 ciType* type = holder->java_mirror_type();
329 if (type != NULL && type->is_instance_klass() && off >= InstanceMirrorKlass::offset_of_static_fields()) {
330 // Static field
331 field = type->as_instance_klass()->get_field_by_offset(off, /*is_static=*/true);
332 } else {
333 // Instance field
334 field = holder->klass()->as_instance_klass()->get_field_by_offset(off, /*is_static=*/false);
335 }
336 if (field == NULL) {
337 return NULL; // Wrong offset
338 }
339 return Type::make_constant_from_field(field, holder, loadbt, is_unsigned_load);
340 }
341
make_constant_from_field(ciField * field,ciInstance * holder,BasicType loadbt,bool is_unsigned_load)342 const Type* Type::make_constant_from_field(ciField* field, ciInstance* holder,
343 BasicType loadbt, bool is_unsigned_load) {
344 if (!field->is_constant()) {
345 return NULL; // Non-constant field
346 }
347 ciConstant field_value;
348 if (field->is_static()) {
349 // final static field
350 field_value = field->constant_value();
351 } else if (holder != NULL) {
352 // final or stable non-static field
353 // Treat final non-static fields of trusted classes (classes in
354 // java.lang.invoke and sun.invoke packages and subpackages) as
355 // compile time constants.
356 field_value = field->constant_value_of(holder);
357 }
358 if (!field_value.is_valid()) {
359 return NULL; // Not a constant
360 }
361
362 ciConstant con = check_mismatched_access(field_value, loadbt, is_unsigned_load);
363
364 assert(con.is_valid(), "elembt=%s; loadbt=%s; unsigned=%d",
365 type2name(field_value.basic_type()), type2name(loadbt), is_unsigned_load);
366
367 bool is_stable_array = FoldStableValues && field->is_stable() && field->type()->is_array_klass();
368 int stable_dimension = (is_stable_array ? field->type()->as_array_klass()->dimension() : 0);
369 bool is_narrow_oop = (loadbt == T_NARROWOOP);
370
371 const Type* con_type = make_from_constant(con, /*require_constant=*/ true,
372 stable_dimension, is_narrow_oop,
373 field->is_autobox_cache());
374 if (con_type != NULL && field->is_call_site_target()) {
375 ciCallSite* call_site = holder->as_call_site();
376 if (!call_site->is_fully_initialized_constant_call_site()) {
377 ciMethodHandle* target = con.as_object()->as_method_handle();
378 Compile::current()->dependencies()->assert_call_site_target_value(call_site, target);
379 }
380 }
381 return con_type;
382 }
383
384 //------------------------------make-------------------------------------------
385 // Create a simple Type, with default empty symbol sets. Then hashcons it
386 // and look for an existing copy in the type dictionary.
make(enum TYPES t)387 const Type *Type::make( enum TYPES t ) {
388 return (new Type(t))->hashcons();
389 }
390
391 //------------------------------cmp--------------------------------------------
cmp(const Type * const t1,const Type * const t2)392 int Type::cmp( const Type *const t1, const Type *const t2 ) {
393 if( t1->_base != t2->_base )
394 return 1; // Missed badly
395 assert(t1 != t2 || t1->eq(t2), "eq must be reflexive");
396 return !t1->eq(t2); // Return ZERO if equal
397 }
398
maybe_remove_speculative(bool include_speculative) const399 const Type* Type::maybe_remove_speculative(bool include_speculative) const {
400 if (!include_speculative) {
401 return remove_speculative();
402 }
403 return this;
404 }
405
406 //------------------------------hash-------------------------------------------
uhash(const Type * const t)407 int Type::uhash( const Type *const t ) {
408 return t->hash();
409 }
410
411 #define SMALLINT ((juint)3) // a value too insignificant to consider widening
412 #define POSITIVE_INFINITE_F 0x7f800000 // hex representation for IEEE 754 single precision positive infinite
413 #define POSITIVE_INFINITE_D 0x7ff0000000000000 // hex representation for IEEE 754 double precision positive infinite
414
415 //--------------------------Initialize_shared----------------------------------
Initialize_shared(Compile * current)416 void Type::Initialize_shared(Compile* current) {
417 // This method does not need to be locked because the first system
418 // compilations (stub compilations) occur serially. If they are
419 // changed to proceed in parallel, then this section will need
420 // locking.
421
422 Arena* save = current->type_arena();
423 Arena* shared_type_arena = new (mtCompiler)Arena(mtCompiler);
424
425 current->set_type_arena(shared_type_arena);
426 _shared_type_dict =
427 new (shared_type_arena) Dict( (CmpKey)Type::cmp, (Hash)Type::uhash,
428 shared_type_arena, 128 );
429 current->set_type_dict(_shared_type_dict);
430
431 // Make shared pre-built types.
432 CONTROL = make(Control); // Control only
433 TOP = make(Top); // No values in set
434 MEMORY = make(Memory); // Abstract store only
435 ABIO = make(Abio); // State-of-machine only
436 RETURN_ADDRESS=make(Return_Address);
437 FLOAT = make(FloatBot); // All floats
438 DOUBLE = make(DoubleBot); // All doubles
439 BOTTOM = make(Bottom); // Everything
440 HALF = make(Half); // Placeholder half of doublewide type
441
442 TypeF::MAX = TypeF::make(max_jfloat); // Float MAX
443 TypeF::MIN = TypeF::make(min_jfloat); // Float MIN
444 TypeF::ZERO = TypeF::make(0.0); // Float 0 (positive zero)
445 TypeF::ONE = TypeF::make(1.0); // Float 1
446 TypeF::POS_INF = TypeF::make(jfloat_cast(POSITIVE_INFINITE_F));
447 TypeF::NEG_INF = TypeF::make(-jfloat_cast(POSITIVE_INFINITE_F));
448
449 TypeD::MAX = TypeD::make(max_jdouble); // Double MAX
450 TypeD::MIN = TypeD::make(min_jdouble); // Double MIN
451 TypeD::ZERO = TypeD::make(0.0); // Double 0 (positive zero)
452 TypeD::ONE = TypeD::make(1.0); // Double 1
453 TypeD::POS_INF = TypeD::make(jdouble_cast(POSITIVE_INFINITE_D));
454 TypeD::NEG_INF = TypeD::make(-jdouble_cast(POSITIVE_INFINITE_D));
455
456 TypeInt::MAX = TypeInt::make(max_jint); // Int MAX
457 TypeInt::MIN = TypeInt::make(min_jint); // Int MIN
458 TypeInt::MINUS_1 = TypeInt::make(-1); // -1
459 TypeInt::ZERO = TypeInt::make( 0); // 0
460 TypeInt::ONE = TypeInt::make( 1); // 1
461 TypeInt::BOOL = TypeInt::make(0,1, WidenMin); // 0 or 1, FALSE or TRUE.
462 TypeInt::CC = TypeInt::make(-1, 1, WidenMin); // -1, 0 or 1, condition codes
463 TypeInt::CC_LT = TypeInt::make(-1,-1, WidenMin); // == TypeInt::MINUS_1
464 TypeInt::CC_GT = TypeInt::make( 1, 1, WidenMin); // == TypeInt::ONE
465 TypeInt::CC_EQ = TypeInt::make( 0, 0, WidenMin); // == TypeInt::ZERO
466 TypeInt::CC_LE = TypeInt::make(-1, 0, WidenMin);
467 TypeInt::CC_GE = TypeInt::make( 0, 1, WidenMin); // == TypeInt::BOOL
468 TypeInt::BYTE = TypeInt::make(-128,127, WidenMin); // Bytes
469 TypeInt::UBYTE = TypeInt::make(0, 255, WidenMin); // Unsigned Bytes
470 TypeInt::CHAR = TypeInt::make(0,65535, WidenMin); // Java chars
471 TypeInt::SHORT = TypeInt::make(-32768,32767, WidenMin); // Java shorts
472 TypeInt::POS = TypeInt::make(0,max_jint, WidenMin); // Non-neg values
473 TypeInt::POS1 = TypeInt::make(1,max_jint, WidenMin); // Positive values
474 TypeInt::INT = TypeInt::make(min_jint,max_jint, WidenMax); // 32-bit integers
475 TypeInt::SYMINT = TypeInt::make(-max_jint,max_jint,WidenMin); // symmetric range
476 TypeInt::TYPE_DOMAIN = TypeInt::INT;
477 // CmpL is overloaded both as the bytecode computation returning
478 // a trinary (-1,0,+1) integer result AND as an efficient long
479 // compare returning optimizer ideal-type flags.
480 assert( TypeInt::CC_LT == TypeInt::MINUS_1, "types must match for CmpL to work" );
481 assert( TypeInt::CC_GT == TypeInt::ONE, "types must match for CmpL to work" );
482 assert( TypeInt::CC_EQ == TypeInt::ZERO, "types must match for CmpL to work" );
483 assert( TypeInt::CC_GE == TypeInt::BOOL, "types must match for CmpL to work" );
484 assert( (juint)(TypeInt::CC->_hi - TypeInt::CC->_lo) <= SMALLINT, "CC is truly small");
485
486 TypeLong::MAX = TypeLong::make(max_jlong); // Long MAX
487 TypeLong::MIN = TypeLong::make(min_jlong); // Long MIN
488 TypeLong::MINUS_1 = TypeLong::make(-1); // -1
489 TypeLong::ZERO = TypeLong::make( 0); // 0
490 TypeLong::ONE = TypeLong::make( 1); // 1
491 TypeLong::POS = TypeLong::make(0,max_jlong, WidenMin); // Non-neg values
492 TypeLong::LONG = TypeLong::make(min_jlong,max_jlong,WidenMax); // 64-bit integers
493 TypeLong::INT = TypeLong::make((jlong)min_jint,(jlong)max_jint,WidenMin);
494 TypeLong::UINT = TypeLong::make(0,(jlong)max_juint,WidenMin);
495 TypeLong::TYPE_DOMAIN = TypeLong::LONG;
496
497 const Type **fboth =(const Type**)shared_type_arena->Amalloc_4(2*sizeof(Type*));
498 fboth[0] = Type::CONTROL;
499 fboth[1] = Type::CONTROL;
500 TypeTuple::IFBOTH = TypeTuple::make( 2, fboth );
501
502 const Type **ffalse =(const Type**)shared_type_arena->Amalloc_4(2*sizeof(Type*));
503 ffalse[0] = Type::CONTROL;
504 ffalse[1] = Type::TOP;
505 TypeTuple::IFFALSE = TypeTuple::make( 2, ffalse );
506
507 const Type **fneither =(const Type**)shared_type_arena->Amalloc_4(2*sizeof(Type*));
508 fneither[0] = Type::TOP;
509 fneither[1] = Type::TOP;
510 TypeTuple::IFNEITHER = TypeTuple::make( 2, fneither );
511
512 const Type **ftrue =(const Type**)shared_type_arena->Amalloc_4(2*sizeof(Type*));
513 ftrue[0] = Type::TOP;
514 ftrue[1] = Type::CONTROL;
515 TypeTuple::IFTRUE = TypeTuple::make( 2, ftrue );
516
517 const Type **floop =(const Type**)shared_type_arena->Amalloc_4(2*sizeof(Type*));
518 floop[0] = Type::CONTROL;
519 floop[1] = TypeInt::INT;
520 TypeTuple::LOOPBODY = TypeTuple::make( 2, floop );
521
522 TypePtr::NULL_PTR= TypePtr::make(AnyPtr, TypePtr::Null, 0);
523 TypePtr::NOTNULL = TypePtr::make(AnyPtr, TypePtr::NotNull, OffsetBot);
524 TypePtr::BOTTOM = TypePtr::make(AnyPtr, TypePtr::BotPTR, OffsetBot);
525
526 TypeRawPtr::BOTTOM = TypeRawPtr::make( TypePtr::BotPTR );
527 TypeRawPtr::NOTNULL= TypeRawPtr::make( TypePtr::NotNull );
528
529 const Type **fmembar = TypeTuple::fields(0);
530 TypeTuple::MEMBAR = TypeTuple::make(TypeFunc::Parms+0, fmembar);
531
532 const Type **fsc = (const Type**)shared_type_arena->Amalloc_4(2*sizeof(Type*));
533 fsc[0] = TypeInt::CC;
534 fsc[1] = Type::MEMORY;
535 TypeTuple::STORECONDITIONAL = TypeTuple::make(2, fsc);
536
537 TypeInstPtr::NOTNULL = TypeInstPtr::make(TypePtr::NotNull, current->env()->Object_klass());
538 TypeInstPtr::BOTTOM = TypeInstPtr::make(TypePtr::BotPTR, current->env()->Object_klass());
539 TypeInstPtr::MIRROR = TypeInstPtr::make(TypePtr::NotNull, current->env()->Class_klass());
540 TypeInstPtr::MARK = TypeInstPtr::make(TypePtr::BotPTR, current->env()->Object_klass(),
541 false, 0, oopDesc::mark_offset_in_bytes());
542 TypeInstPtr::KLASS = TypeInstPtr::make(TypePtr::BotPTR, current->env()->Object_klass(),
543 false, 0, oopDesc::klass_offset_in_bytes());
544 TypeOopPtr::BOTTOM = TypeOopPtr::make(TypePtr::BotPTR, OffsetBot, TypeOopPtr::InstanceBot);
545
546 TypeMetadataPtr::BOTTOM = TypeMetadataPtr::make(TypePtr::BotPTR, NULL, OffsetBot);
547
548 TypeNarrowOop::NULL_PTR = TypeNarrowOop::make( TypePtr::NULL_PTR );
549 TypeNarrowOop::BOTTOM = TypeNarrowOop::make( TypeInstPtr::BOTTOM );
550
551 TypeNarrowKlass::NULL_PTR = TypeNarrowKlass::make( TypePtr::NULL_PTR );
552
553 mreg2type[Op_Node] = Type::BOTTOM;
554 mreg2type[Op_Set ] = 0;
555 mreg2type[Op_RegN] = TypeNarrowOop::BOTTOM;
556 mreg2type[Op_RegI] = TypeInt::INT;
557 mreg2type[Op_RegP] = TypePtr::BOTTOM;
558 mreg2type[Op_RegF] = Type::FLOAT;
559 mreg2type[Op_RegD] = Type::DOUBLE;
560 mreg2type[Op_RegL] = TypeLong::LONG;
561 mreg2type[Op_RegFlags] = TypeInt::CC;
562
563 TypeAryPtr::RANGE = TypeAryPtr::make( TypePtr::BotPTR, TypeAry::make(Type::BOTTOM,TypeInt::POS), NULL /* current->env()->Object_klass() */, false, arrayOopDesc::length_offset_in_bytes());
564
565 TypeAryPtr::NARROWOOPS = TypeAryPtr::make(TypePtr::BotPTR, TypeAry::make(TypeNarrowOop::BOTTOM, TypeInt::POS), NULL /*ciArrayKlass::make(o)*/, false, Type::OffsetBot);
566
567 #ifdef _LP64
568 if (UseCompressedOops) {
569 assert(TypeAryPtr::NARROWOOPS->is_ptr_to_narrowoop(), "array of narrow oops must be ptr to narrow oop");
570 TypeAryPtr::OOPS = TypeAryPtr::NARROWOOPS;
571 } else
572 #endif
573 {
574 // There is no shared klass for Object[]. See note in TypeAryPtr::klass().
575 TypeAryPtr::OOPS = TypeAryPtr::make(TypePtr::BotPTR, TypeAry::make(TypeInstPtr::BOTTOM,TypeInt::POS), NULL /*ciArrayKlass::make(o)*/, false, Type::OffsetBot);
576 }
577 TypeAryPtr::BYTES = TypeAryPtr::make(TypePtr::BotPTR, TypeAry::make(TypeInt::BYTE ,TypeInt::POS), ciTypeArrayKlass::make(T_BYTE), true, Type::OffsetBot);
578 TypeAryPtr::SHORTS = TypeAryPtr::make(TypePtr::BotPTR, TypeAry::make(TypeInt::SHORT ,TypeInt::POS), ciTypeArrayKlass::make(T_SHORT), true, Type::OffsetBot);
579 TypeAryPtr::CHARS = TypeAryPtr::make(TypePtr::BotPTR, TypeAry::make(TypeInt::CHAR ,TypeInt::POS), ciTypeArrayKlass::make(T_CHAR), true, Type::OffsetBot);
580 TypeAryPtr::INTS = TypeAryPtr::make(TypePtr::BotPTR, TypeAry::make(TypeInt::INT ,TypeInt::POS), ciTypeArrayKlass::make(T_INT), true, Type::OffsetBot);
581 TypeAryPtr::LONGS = TypeAryPtr::make(TypePtr::BotPTR, TypeAry::make(TypeLong::LONG ,TypeInt::POS), ciTypeArrayKlass::make(T_LONG), true, Type::OffsetBot);
582 TypeAryPtr::FLOATS = TypeAryPtr::make(TypePtr::BotPTR, TypeAry::make(Type::FLOAT ,TypeInt::POS), ciTypeArrayKlass::make(T_FLOAT), true, Type::OffsetBot);
583 TypeAryPtr::DOUBLES = TypeAryPtr::make(TypePtr::BotPTR, TypeAry::make(Type::DOUBLE ,TypeInt::POS), ciTypeArrayKlass::make(T_DOUBLE), true, Type::OffsetBot);
584
585 // Nobody should ask _array_body_type[T_NARROWOOP]. Use NULL as assert.
586 TypeAryPtr::_array_body_type[T_NARROWOOP] = NULL;
587 TypeAryPtr::_array_body_type[T_OBJECT] = TypeAryPtr::OOPS;
588 TypeAryPtr::_array_body_type[T_ARRAY] = TypeAryPtr::OOPS; // arrays are stored in oop arrays
589 TypeAryPtr::_array_body_type[T_BYTE] = TypeAryPtr::BYTES;
590 TypeAryPtr::_array_body_type[T_BOOLEAN] = TypeAryPtr::BYTES; // boolean[] is a byte array
591 TypeAryPtr::_array_body_type[T_SHORT] = TypeAryPtr::SHORTS;
592 TypeAryPtr::_array_body_type[T_CHAR] = TypeAryPtr::CHARS;
593 TypeAryPtr::_array_body_type[T_INT] = TypeAryPtr::INTS;
594 TypeAryPtr::_array_body_type[T_LONG] = TypeAryPtr::LONGS;
595 TypeAryPtr::_array_body_type[T_FLOAT] = TypeAryPtr::FLOATS;
596 TypeAryPtr::_array_body_type[T_DOUBLE] = TypeAryPtr::DOUBLES;
597
598 TypeKlassPtr::OBJECT = TypeKlassPtr::make( TypePtr::NotNull, current->env()->Object_klass(), 0 );
599 TypeKlassPtr::OBJECT_OR_NULL = TypeKlassPtr::make( TypePtr::BotPTR, current->env()->Object_klass(), 0 );
600
601 const Type **fi2c = TypeTuple::fields(2);
602 fi2c[TypeFunc::Parms+0] = TypeInstPtr::BOTTOM; // Method*
603 fi2c[TypeFunc::Parms+1] = TypeRawPtr::BOTTOM; // argument pointer
604 TypeTuple::START_I2C = TypeTuple::make(TypeFunc::Parms+2, fi2c);
605
606 const Type **intpair = TypeTuple::fields(2);
607 intpair[0] = TypeInt::INT;
608 intpair[1] = TypeInt::INT;
609 TypeTuple::INT_PAIR = TypeTuple::make(2, intpair);
610
611 const Type **longpair = TypeTuple::fields(2);
612 longpair[0] = TypeLong::LONG;
613 longpair[1] = TypeLong::LONG;
614 TypeTuple::LONG_PAIR = TypeTuple::make(2, longpair);
615
616 const Type **intccpair = TypeTuple::fields(2);
617 intccpair[0] = TypeInt::INT;
618 intccpair[1] = TypeInt::CC;
619 TypeTuple::INT_CC_PAIR = TypeTuple::make(2, intccpair);
620
621 const Type **longccpair = TypeTuple::fields(2);
622 longccpair[0] = TypeLong::LONG;
623 longccpair[1] = TypeInt::CC;
624 TypeTuple::LONG_CC_PAIR = TypeTuple::make(2, longccpair);
625
626 _const_basic_type[T_NARROWOOP] = TypeNarrowOop::BOTTOM;
627 _const_basic_type[T_NARROWKLASS] = Type::BOTTOM;
628 _const_basic_type[T_BOOLEAN] = TypeInt::BOOL;
629 _const_basic_type[T_CHAR] = TypeInt::CHAR;
630 _const_basic_type[T_BYTE] = TypeInt::BYTE;
631 _const_basic_type[T_SHORT] = TypeInt::SHORT;
632 _const_basic_type[T_INT] = TypeInt::INT;
633 _const_basic_type[T_LONG] = TypeLong::LONG;
634 _const_basic_type[T_FLOAT] = Type::FLOAT;
635 _const_basic_type[T_DOUBLE] = Type::DOUBLE;
636 _const_basic_type[T_OBJECT] = TypeInstPtr::BOTTOM;
637 _const_basic_type[T_ARRAY] = TypeInstPtr::BOTTOM; // there is no separate bottom for arrays
638 _const_basic_type[T_VOID] = TypePtr::NULL_PTR; // reflection represents void this way
639 _const_basic_type[T_ADDRESS] = TypeRawPtr::BOTTOM; // both interpreter return addresses & random raw ptrs
640 _const_basic_type[T_CONFLICT] = Type::BOTTOM; // why not?
641
642 _zero_type[T_NARROWOOP] = TypeNarrowOop::NULL_PTR;
643 _zero_type[T_NARROWKLASS] = TypeNarrowKlass::NULL_PTR;
644 _zero_type[T_BOOLEAN] = TypeInt::ZERO; // false == 0
645 _zero_type[T_CHAR] = TypeInt::ZERO; // '\0' == 0
646 _zero_type[T_BYTE] = TypeInt::ZERO; // 0x00 == 0
647 _zero_type[T_SHORT] = TypeInt::ZERO; // 0x0000 == 0
648 _zero_type[T_INT] = TypeInt::ZERO;
649 _zero_type[T_LONG] = TypeLong::ZERO;
650 _zero_type[T_FLOAT] = TypeF::ZERO;
651 _zero_type[T_DOUBLE] = TypeD::ZERO;
652 _zero_type[T_OBJECT] = TypePtr::NULL_PTR;
653 _zero_type[T_ARRAY] = TypePtr::NULL_PTR; // null array is null oop
654 _zero_type[T_ADDRESS] = TypePtr::NULL_PTR; // raw pointers use the same null
655 _zero_type[T_VOID] = Type::TOP; // the only void value is no value at all
656
657 // get_zero_type() should not happen for T_CONFLICT
658 _zero_type[T_CONFLICT]= NULL;
659
660 if (Matcher::supports_scalable_vector()) {
661 TypeVect::VECTA = TypeVect::make(T_BYTE, Matcher::scalable_vector_reg_size(T_BYTE));
662 }
663
664 // Vector predefined types, it needs initialized _const_basic_type[].
665 if (Matcher::vector_size_supported(T_BYTE,4)) {
666 TypeVect::VECTS = TypeVect::make(T_BYTE,4);
667 }
668 if (Matcher::vector_size_supported(T_FLOAT,2)) {
669 TypeVect::VECTD = TypeVect::make(T_FLOAT,2);
670 }
671 if (Matcher::vector_size_supported(T_FLOAT,4)) {
672 TypeVect::VECTX = TypeVect::make(T_FLOAT,4);
673 }
674 if (Matcher::vector_size_supported(T_FLOAT,8)) {
675 TypeVect::VECTY = TypeVect::make(T_FLOAT,8);
676 }
677 if (Matcher::vector_size_supported(T_FLOAT,16)) {
678 TypeVect::VECTZ = TypeVect::make(T_FLOAT,16);
679 }
680
681 mreg2type[Op_VecA] = TypeVect::VECTA;
682 mreg2type[Op_VecS] = TypeVect::VECTS;
683 mreg2type[Op_VecD] = TypeVect::VECTD;
684 mreg2type[Op_VecX] = TypeVect::VECTX;
685 mreg2type[Op_VecY] = TypeVect::VECTY;
686 mreg2type[Op_VecZ] = TypeVect::VECTZ;
687
688 // Restore working type arena.
689 current->set_type_arena(save);
690 current->set_type_dict(NULL);
691 }
692
693 //------------------------------Initialize-------------------------------------
Initialize(Compile * current)694 void Type::Initialize(Compile* current) {
695 assert(current->type_arena() != NULL, "must have created type arena");
696
697 if (_shared_type_dict == NULL) {
698 Initialize_shared(current);
699 }
700
701 Arena* type_arena = current->type_arena();
702
703 // Create the hash-cons'ing dictionary with top-level storage allocation
704 Dict *tdic = new (type_arena) Dict(*_shared_type_dict, type_arena);
705 current->set_type_dict(tdic);
706 }
707
708 //------------------------------hashcons---------------------------------------
709 // Do the hash-cons trick. If the Type already exists in the type table,
710 // delete the current Type and return the existing Type. Otherwise stick the
711 // current Type in the Type table.
hashcons(void)712 const Type *Type::hashcons(void) {
713 debug_only(base()); // Check the assertion in Type::base().
714 // Look up the Type in the Type dictionary
715 Dict *tdic = type_dict();
716 Type* old = (Type*)(tdic->Insert(this, this, false));
717 if( old ) { // Pre-existing Type?
718 if( old != this ) // Yes, this guy is not the pre-existing?
719 delete this; // Yes, Nuke this guy
720 assert( old->_dual, "" );
721 return old; // Return pre-existing
722 }
723
724 // Every type has a dual (to make my lattice symmetric).
725 // Since we just discovered a new Type, compute its dual right now.
726 assert( !_dual, "" ); // No dual yet
727 _dual = xdual(); // Compute the dual
728 if (cmp(this, _dual) == 0) { // Handle self-symmetric
729 if (_dual != this) {
730 delete _dual;
731 _dual = this;
732 }
733 return this;
734 }
735 assert( !_dual->_dual, "" ); // No reverse dual yet
736 assert( !(*tdic)[_dual], "" ); // Dual not in type system either
737 // New Type, insert into Type table
738 tdic->Insert((void*)_dual,(void*)_dual);
739 ((Type*)_dual)->_dual = this; // Finish up being symmetric
740 #ifdef ASSERT
741 Type *dual_dual = (Type*)_dual->xdual();
742 assert( eq(dual_dual), "xdual(xdual()) should be identity" );
743 delete dual_dual;
744 #endif
745 return this; // Return new Type
746 }
747
748 //------------------------------eq---------------------------------------------
749 // Structural equality check for Type representations
eq(const Type *) const750 bool Type::eq( const Type * ) const {
751 return true; // Nothing else can go wrong
752 }
753
754 //------------------------------hash-------------------------------------------
755 // Type-specific hashing function.
hash(void) const756 int Type::hash(void) const {
757 return _base;
758 }
759
760 //------------------------------is_finite--------------------------------------
761 // Has a finite value
is_finite() const762 bool Type::is_finite() const {
763 return false;
764 }
765
766 //------------------------------is_nan-----------------------------------------
767 // Is not a number (NaN)
is_nan() const768 bool Type::is_nan() const {
769 return false;
770 }
771
772 //----------------------interface_vs_oop---------------------------------------
773 #ifdef ASSERT
interface_vs_oop_helper(const Type * t) const774 bool Type::interface_vs_oop_helper(const Type *t) const {
775 bool result = false;
776
777 const TypePtr* this_ptr = this->make_ptr(); // In case it is narrow_oop
778 const TypePtr* t_ptr = t->make_ptr();
779 if( this_ptr == NULL || t_ptr == NULL )
780 return result;
781
782 const TypeInstPtr* this_inst = this_ptr->isa_instptr();
783 const TypeInstPtr* t_inst = t_ptr->isa_instptr();
784 if( this_inst && this_inst->is_loaded() && t_inst && t_inst->is_loaded() ) {
785 bool this_interface = this_inst->klass()->is_interface();
786 bool t_interface = t_inst->klass()->is_interface();
787 result = this_interface ^ t_interface;
788 }
789
790 return result;
791 }
792
interface_vs_oop(const Type * t) const793 bool Type::interface_vs_oop(const Type *t) const {
794 if (interface_vs_oop_helper(t)) {
795 return true;
796 }
797 // Now check the speculative parts as well
798 const TypePtr* this_spec = isa_ptr() != NULL ? is_ptr()->speculative() : NULL;
799 const TypePtr* t_spec = t->isa_ptr() != NULL ? t->is_ptr()->speculative() : NULL;
800 if (this_spec != NULL && t_spec != NULL) {
801 if (this_spec->interface_vs_oop_helper(t_spec)) {
802 return true;
803 }
804 return false;
805 }
806 if (this_spec != NULL && this_spec->interface_vs_oop_helper(t)) {
807 return true;
808 }
809 if (t_spec != NULL && interface_vs_oop_helper(t_spec)) {
810 return true;
811 }
812 return false;
813 }
814
815 #endif
816
check_symmetrical(const Type * t,const Type * mt) const817 void Type::check_symmetrical(const Type* t, const Type* mt) const {
818 #ifdef ASSERT
819 const Type* mt2 = t->xmeet(this);
820 if (mt != mt2) {
821 tty->print_cr("=== Meet Not Commutative ===");
822 tty->print("t = "); t->dump(); tty->cr();
823 tty->print("this = "); dump(); tty->cr();
824 tty->print("t meet this = "); mt2->dump(); tty->cr();
825 tty->print("this meet t = "); mt->dump(); tty->cr();
826 fatal("meet not commutative");
827 }
828 const Type* dual_join = mt->_dual;
829 const Type* t2t = dual_join->xmeet(t->_dual);
830 const Type* t2this = dual_join->xmeet(this->_dual);
831
832 // Interface meet Oop is Not Symmetric:
833 // Interface:AnyNull meet Oop:AnyNull == Interface:AnyNull
834 // Interface:NotNull meet Oop:NotNull == java/lang/Object:NotNull
835
836 if (!interface_vs_oop(t) && (t2t != t->_dual || t2this != this->_dual)) {
837 tty->print_cr("=== Meet Not Symmetric ===");
838 tty->print("t = "); t->dump(); tty->cr();
839 tty->print("this= "); dump(); tty->cr();
840 tty->print("mt=(t meet this)= "); mt->dump(); tty->cr();
841
842 tty->print("t_dual= "); t->_dual->dump(); tty->cr();
843 tty->print("this_dual= "); _dual->dump(); tty->cr();
844 tty->print("mt_dual= "); mt->_dual->dump(); tty->cr();
845
846 tty->print("mt_dual meet t_dual= "); t2t ->dump(); tty->cr();
847 tty->print("mt_dual meet this_dual= "); t2this ->dump(); tty->cr();
848
849 fatal("meet not symmetric");
850 }
851 #endif
852 }
853
854 //------------------------------meet-------------------------------------------
855 // Compute the MEET of two types. NOT virtual. It enforces that meet is
856 // commutative and the lattice is symmetric.
meet_helper(const Type * t,bool include_speculative) const857 const Type *Type::meet_helper(const Type *t, bool include_speculative) const {
858 if (isa_narrowoop() && t->isa_narrowoop()) {
859 const Type* result = make_ptr()->meet_helper(t->make_ptr(), include_speculative);
860 return result->make_narrowoop();
861 }
862 if (isa_narrowklass() && t->isa_narrowklass()) {
863 const Type* result = make_ptr()->meet_helper(t->make_ptr(), include_speculative);
864 return result->make_narrowklass();
865 }
866
867 const Type *this_t = maybe_remove_speculative(include_speculative);
868 t = t->maybe_remove_speculative(include_speculative);
869
870 const Type *mt = this_t->xmeet(t);
871 #ifdef ASSERT
872 if (isa_narrowoop() || t->isa_narrowoop()) return mt;
873 if (isa_narrowklass() || t->isa_narrowklass()) return mt;
874 Compile* C = Compile::current();
875 if (!C->_type_verify_symmetry) {
876 return mt;
877 }
878 this_t->check_symmetrical(t, mt);
879 // In the case of an array, computing the meet above, caused the
880 // computation of the meet of the elements which at verification
881 // time caused the computation of the meet of the dual of the
882 // elements. Computing the meet of the dual of the arrays here
883 // causes the meet of the dual of the elements to be computed which
884 // would cause the meet of the dual of the dual of the elements,
885 // that is the meet of the elements already computed above to be
886 // computed. Avoid redundant computations by requesting no
887 // verification.
888 C->_type_verify_symmetry = false;
889 const Type *mt_dual = this_t->_dual->xmeet(t->_dual);
890 this_t->_dual->check_symmetrical(t->_dual, mt_dual);
891 assert(!C->_type_verify_symmetry, "shouldn't have changed");
892 C->_type_verify_symmetry = true;
893 #endif
894 return mt;
895 }
896
897 //------------------------------xmeet------------------------------------------
898 // Compute the MEET of two types. It returns a new Type object.
xmeet(const Type * t) const899 const Type *Type::xmeet( const Type *t ) const {
900 // Perform a fast test for common case; meeting the same types together.
901 if( this == t ) return this; // Meeting same type-rep?
902
903 // Meeting TOP with anything?
904 if( _base == Top ) return t;
905
906 // Meeting BOTTOM with anything?
907 if( _base == Bottom ) return BOTTOM;
908
909 // Current "this->_base" is one of: Bad, Multi, Control, Top,
910 // Abio, Abstore, Floatxxx, Doublexxx, Bottom, lastype.
911 switch (t->base()) { // Switch on original type
912
913 // Cut in half the number of cases I must handle. Only need cases for when
914 // the given enum "t->type" is less than or equal to the local enum "type".
915 case FloatCon:
916 case DoubleCon:
917 case Int:
918 case Long:
919 return t->xmeet(this);
920
921 case OopPtr:
922 return t->xmeet(this);
923
924 case InstPtr:
925 return t->xmeet(this);
926
927 case MetadataPtr:
928 case KlassPtr:
929 return t->xmeet(this);
930
931 case AryPtr:
932 return t->xmeet(this);
933
934 case NarrowOop:
935 return t->xmeet(this);
936
937 case NarrowKlass:
938 return t->xmeet(this);
939
940 case Bad: // Type check
941 default: // Bogus type not in lattice
942 typerr(t);
943 return Type::BOTTOM;
944
945 case Bottom: // Ye Olde Default
946 return t;
947
948 case FloatTop:
949 if( _base == FloatTop ) return this;
950 case FloatBot: // Float
951 if( _base == FloatBot || _base == FloatTop ) return FLOAT;
952 if( _base == DoubleTop || _base == DoubleBot ) return Type::BOTTOM;
953 typerr(t);
954 return Type::BOTTOM;
955
956 case DoubleTop:
957 if( _base == DoubleTop ) return this;
958 case DoubleBot: // Double
959 if( _base == DoubleBot || _base == DoubleTop ) return DOUBLE;
960 if( _base == FloatTop || _base == FloatBot ) return Type::BOTTOM;
961 typerr(t);
962 return Type::BOTTOM;
963
964 // These next few cases must match exactly or it is a compile-time error.
965 case Control: // Control of code
966 case Abio: // State of world outside of program
967 case Memory:
968 if( _base == t->_base ) return this;
969 typerr(t);
970 return Type::BOTTOM;
971
972 case Top: // Top of the lattice
973 return this;
974 }
975
976 // The type is unchanged
977 return this;
978 }
979
980 //-----------------------------filter------------------------------------------
filter_helper(const Type * kills,bool include_speculative) const981 const Type *Type::filter_helper(const Type *kills, bool include_speculative) const {
982 const Type* ft = join_helper(kills, include_speculative);
983 if (ft->empty())
984 return Type::TOP; // Canonical empty value
985 return ft;
986 }
987
988 //------------------------------xdual------------------------------------------
989 // Compute dual right now.
990 const Type::TYPES Type::dual_type[Type::lastype] = {
991 Bad, // Bad
992 Control, // Control
993 Bottom, // Top
994 Bad, // Int - handled in v-call
995 Bad, // Long - handled in v-call
996 Half, // Half
997 Bad, // NarrowOop - handled in v-call
998 Bad, // NarrowKlass - handled in v-call
999
1000 Bad, // Tuple - handled in v-call
1001 Bad, // Array - handled in v-call
1002 Bad, // VectorA - handled in v-call
1003 Bad, // VectorS - handled in v-call
1004 Bad, // VectorD - handled in v-call
1005 Bad, // VectorX - handled in v-call
1006 Bad, // VectorY - handled in v-call
1007 Bad, // VectorZ - handled in v-call
1008
1009 Bad, // AnyPtr - handled in v-call
1010 Bad, // RawPtr - handled in v-call
1011 Bad, // OopPtr - handled in v-call
1012 Bad, // InstPtr - handled in v-call
1013 Bad, // AryPtr - handled in v-call
1014
1015 Bad, // MetadataPtr - handled in v-call
1016 Bad, // KlassPtr - handled in v-call
1017
1018 Bad, // Function - handled in v-call
1019 Abio, // Abio
1020 Return_Address,// Return_Address
1021 Memory, // Memory
1022 FloatBot, // FloatTop
1023 FloatCon, // FloatCon
1024 FloatTop, // FloatBot
1025 DoubleBot, // DoubleTop
1026 DoubleCon, // DoubleCon
1027 DoubleTop, // DoubleBot
1028 Top // Bottom
1029 };
1030
xdual() const1031 const Type *Type::xdual() const {
1032 // Note: the base() accessor asserts the sanity of _base.
1033 assert(_type_info[base()].dual_type != Bad, "implement with v-call");
1034 return new Type(_type_info[_base].dual_type);
1035 }
1036
1037 //------------------------------has_memory-------------------------------------
has_memory() const1038 bool Type::has_memory() const {
1039 Type::TYPES tx = base();
1040 if (tx == Memory) return true;
1041 if (tx == Tuple) {
1042 const TypeTuple *t = is_tuple();
1043 for (uint i=0; i < t->cnt(); i++) {
1044 tx = t->field_at(i)->base();
1045 if (tx == Memory) return true;
1046 }
1047 }
1048 return false;
1049 }
1050
1051 #ifndef PRODUCT
1052 //------------------------------dump2------------------------------------------
dump2(Dict & d,uint depth,outputStream * st) const1053 void Type::dump2( Dict &d, uint depth, outputStream *st ) const {
1054 st->print("%s", _type_info[_base].msg);
1055 }
1056
1057 //------------------------------dump-------------------------------------------
dump_on(outputStream * st) const1058 void Type::dump_on(outputStream *st) const {
1059 ResourceMark rm;
1060 Dict d(cmpkey,hashkey); // Stop recursive type dumping
1061 dump2(d,1, st);
1062 if (is_ptr_to_narrowoop()) {
1063 st->print(" [narrow]");
1064 } else if (is_ptr_to_narrowklass()) {
1065 st->print(" [narrowklass]");
1066 }
1067 }
1068
1069 //-----------------------------------------------------------------------------
str(const Type * t)1070 const char* Type::str(const Type* t) {
1071 stringStream ss;
1072 t->dump_on(&ss);
1073 return ss.as_string();
1074 }
1075 #endif
1076
1077 //------------------------------singleton--------------------------------------
1078 // TRUE if Type is a singleton type, FALSE otherwise. Singletons are simple
1079 // constants (Ldi nodes). Singletons are integer, float or double constants.
singleton(void) const1080 bool Type::singleton(void) const {
1081 return _base == Top || _base == Half;
1082 }
1083
1084 //------------------------------empty------------------------------------------
1085 // TRUE if Type is a type with no values, FALSE otherwise.
empty(void) const1086 bool Type::empty(void) const {
1087 switch (_base) {
1088 case DoubleTop:
1089 case FloatTop:
1090 case Top:
1091 return true;
1092
1093 case Half:
1094 case Abio:
1095 case Return_Address:
1096 case Memory:
1097 case Bottom:
1098 case FloatBot:
1099 case DoubleBot:
1100 return false; // never a singleton, therefore never empty
1101
1102 default:
1103 ShouldNotReachHere();
1104 return false;
1105 }
1106 }
1107
1108 //------------------------------dump_stats-------------------------------------
1109 // Dump collected statistics to stderr
1110 #ifndef PRODUCT
dump_stats()1111 void Type::dump_stats() {
1112 tty->print("Types made: %d\n", type_dict()->Size());
1113 }
1114 #endif
1115
1116 //------------------------------typerr-----------------------------------------
typerr(const Type * t) const1117 void Type::typerr( const Type *t ) const {
1118 #ifndef PRODUCT
1119 tty->print("\nError mixing types: ");
1120 dump();
1121 tty->print(" and ");
1122 t->dump();
1123 tty->print("\n");
1124 #endif
1125 ShouldNotReachHere();
1126 }
1127
1128
1129 //=============================================================================
1130 // Convenience common pre-built types.
1131 const TypeF *TypeF::MAX; // Floating point max
1132 const TypeF *TypeF::MIN; // Floating point min
1133 const TypeF *TypeF::ZERO; // Floating point zero
1134 const TypeF *TypeF::ONE; // Floating point one
1135 const TypeF *TypeF::POS_INF; // Floating point positive infinity
1136 const TypeF *TypeF::NEG_INF; // Floating point negative infinity
1137
1138 //------------------------------make-------------------------------------------
1139 // Create a float constant
make(float f)1140 const TypeF *TypeF::make(float f) {
1141 return (TypeF*)(new TypeF(f))->hashcons();
1142 }
1143
1144 //------------------------------meet-------------------------------------------
1145 // Compute the MEET of two types. It returns a new Type object.
xmeet(const Type * t) const1146 const Type *TypeF::xmeet( const Type *t ) const {
1147 // Perform a fast test for common case; meeting the same types together.
1148 if( this == t ) return this; // Meeting same type-rep?
1149
1150 // Current "this->_base" is FloatCon
1151 switch (t->base()) { // Switch on original type
1152 case AnyPtr: // Mixing with oops happens when javac
1153 case RawPtr: // reuses local variables
1154 case OopPtr:
1155 case InstPtr:
1156 case AryPtr:
1157 case MetadataPtr:
1158 case KlassPtr:
1159 case NarrowOop:
1160 case NarrowKlass:
1161 case Int:
1162 case Long:
1163 case DoubleTop:
1164 case DoubleCon:
1165 case DoubleBot:
1166 case Bottom: // Ye Olde Default
1167 return Type::BOTTOM;
1168
1169 case FloatBot:
1170 return t;
1171
1172 default: // All else is a mistake
1173 typerr(t);
1174
1175 case FloatCon: // Float-constant vs Float-constant?
1176 if( jint_cast(_f) != jint_cast(t->getf()) ) // unequal constants?
1177 // must compare bitwise as positive zero, negative zero and NaN have
1178 // all the same representation in C++
1179 return FLOAT; // Return generic float
1180 // Equal constants
1181 case Top:
1182 case FloatTop:
1183 break; // Return the float constant
1184 }
1185 return this; // Return the float constant
1186 }
1187
1188 //------------------------------xdual------------------------------------------
1189 // Dual: symmetric
xdual() const1190 const Type *TypeF::xdual() const {
1191 return this;
1192 }
1193
1194 //------------------------------eq---------------------------------------------
1195 // Structural equality check for Type representations
eq(const Type * t) const1196 bool TypeF::eq(const Type *t) const {
1197 // Bitwise comparison to distinguish between +/-0. These values must be treated
1198 // as different to be consistent with C1 and the interpreter.
1199 return (jint_cast(_f) == jint_cast(t->getf()));
1200 }
1201
1202 //------------------------------hash-------------------------------------------
1203 // Type-specific hashing function.
hash(void) const1204 int TypeF::hash(void) const {
1205 return *(int*)(&_f);
1206 }
1207
1208 //------------------------------is_finite--------------------------------------
1209 // Has a finite value
is_finite() const1210 bool TypeF::is_finite() const {
1211 return g_isfinite(getf()) != 0;
1212 }
1213
1214 //------------------------------is_nan-----------------------------------------
1215 // Is not a number (NaN)
is_nan() const1216 bool TypeF::is_nan() const {
1217 return g_isnan(getf()) != 0;
1218 }
1219
1220 //------------------------------dump2------------------------------------------
1221 // Dump float constant Type
1222 #ifndef PRODUCT
dump2(Dict & d,uint depth,outputStream * st) const1223 void TypeF::dump2( Dict &d, uint depth, outputStream *st ) const {
1224 Type::dump2(d,depth, st);
1225 st->print("%f", _f);
1226 }
1227 #endif
1228
1229 //------------------------------singleton--------------------------------------
1230 // TRUE if Type is a singleton type, FALSE otherwise. Singletons are simple
1231 // constants (Ldi nodes). Singletons are integer, float or double constants
1232 // or a single symbol.
singleton(void) const1233 bool TypeF::singleton(void) const {
1234 return true; // Always a singleton
1235 }
1236
empty(void) const1237 bool TypeF::empty(void) const {
1238 return false; // always exactly a singleton
1239 }
1240
1241 //=============================================================================
1242 // Convenience common pre-built types.
1243 const TypeD *TypeD::MAX; // Floating point max
1244 const TypeD *TypeD::MIN; // Floating point min
1245 const TypeD *TypeD::ZERO; // Floating point zero
1246 const TypeD *TypeD::ONE; // Floating point one
1247 const TypeD *TypeD::POS_INF; // Floating point positive infinity
1248 const TypeD *TypeD::NEG_INF; // Floating point negative infinity
1249
1250 //------------------------------make-------------------------------------------
make(double d)1251 const TypeD *TypeD::make(double d) {
1252 return (TypeD*)(new TypeD(d))->hashcons();
1253 }
1254
1255 //------------------------------meet-------------------------------------------
1256 // Compute the MEET of two types. It returns a new Type object.
xmeet(const Type * t) const1257 const Type *TypeD::xmeet( const Type *t ) const {
1258 // Perform a fast test for common case; meeting the same types together.
1259 if( this == t ) return this; // Meeting same type-rep?
1260
1261 // Current "this->_base" is DoubleCon
1262 switch (t->base()) { // Switch on original type
1263 case AnyPtr: // Mixing with oops happens when javac
1264 case RawPtr: // reuses local variables
1265 case OopPtr:
1266 case InstPtr:
1267 case AryPtr:
1268 case MetadataPtr:
1269 case KlassPtr:
1270 case NarrowOop:
1271 case NarrowKlass:
1272 case Int:
1273 case Long:
1274 case FloatTop:
1275 case FloatCon:
1276 case FloatBot:
1277 case Bottom: // Ye Olde Default
1278 return Type::BOTTOM;
1279
1280 case DoubleBot:
1281 return t;
1282
1283 default: // All else is a mistake
1284 typerr(t);
1285
1286 case DoubleCon: // Double-constant vs Double-constant?
1287 if( jlong_cast(_d) != jlong_cast(t->getd()) ) // unequal constants? (see comment in TypeF::xmeet)
1288 return DOUBLE; // Return generic double
1289 case Top:
1290 case DoubleTop:
1291 break;
1292 }
1293 return this; // Return the double constant
1294 }
1295
1296 //------------------------------xdual------------------------------------------
1297 // Dual: symmetric
xdual() const1298 const Type *TypeD::xdual() const {
1299 return this;
1300 }
1301
1302 //------------------------------eq---------------------------------------------
1303 // Structural equality check for Type representations
eq(const Type * t) const1304 bool TypeD::eq(const Type *t) const {
1305 // Bitwise comparison to distinguish between +/-0. These values must be treated
1306 // as different to be consistent with C1 and the interpreter.
1307 return (jlong_cast(_d) == jlong_cast(t->getd()));
1308 }
1309
1310 //------------------------------hash-------------------------------------------
1311 // Type-specific hashing function.
hash(void) const1312 int TypeD::hash(void) const {
1313 return *(int*)(&_d);
1314 }
1315
1316 //------------------------------is_finite--------------------------------------
1317 // Has a finite value
is_finite() const1318 bool TypeD::is_finite() const {
1319 return g_isfinite(getd()) != 0;
1320 }
1321
1322 //------------------------------is_nan-----------------------------------------
1323 // Is not a number (NaN)
is_nan() const1324 bool TypeD::is_nan() const {
1325 return g_isnan(getd()) != 0;
1326 }
1327
1328 //------------------------------dump2------------------------------------------
1329 // Dump double constant Type
1330 #ifndef PRODUCT
dump2(Dict & d,uint depth,outputStream * st) const1331 void TypeD::dump2( Dict &d, uint depth, outputStream *st ) const {
1332 Type::dump2(d,depth,st);
1333 st->print("%f", _d);
1334 }
1335 #endif
1336
1337 //------------------------------singleton--------------------------------------
1338 // TRUE if Type is a singleton type, FALSE otherwise. Singletons are simple
1339 // constants (Ldi nodes). Singletons are integer, float or double constants
1340 // or a single symbol.
singleton(void) const1341 bool TypeD::singleton(void) const {
1342 return true; // Always a singleton
1343 }
1344
empty(void) const1345 bool TypeD::empty(void) const {
1346 return false; // always exactly a singleton
1347 }
1348
make(jlong lo,jlong hi,int w,BasicType bt)1349 const TypeInteger* TypeInteger::make(jlong lo, jlong hi, int w, BasicType bt) {
1350 if (bt == T_INT) {
1351 return TypeInt::make(checked_cast<jint>(lo), checked_cast<jint>(hi), w);
1352 }
1353 assert(bt == T_LONG, "basic type not an int or long");
1354 return TypeLong::make(lo, hi, w);
1355 }
1356
get_con_as_long(BasicType bt) const1357 jlong TypeInteger::get_con_as_long(BasicType bt) const {
1358 if (bt == T_INT) {
1359 return is_int()->get_con();
1360 }
1361 assert(bt == T_LONG, "basic type not an int or long");
1362 return is_long()->get_con();
1363 }
1364
bottom(BasicType bt)1365 const TypeInteger* TypeInteger::bottom(BasicType bt) {
1366 if (bt == T_INT) {
1367 return TypeInt::INT;
1368 }
1369 assert(bt == T_LONG, "basic type not an int or long");
1370 return TypeLong::LONG;
1371 }
1372
1373 //=============================================================================
1374 // Convience common pre-built types.
1375 const TypeInt *TypeInt::MAX; // INT_MAX
1376 const TypeInt *TypeInt::MIN; // INT_MIN
1377 const TypeInt *TypeInt::MINUS_1;// -1
1378 const TypeInt *TypeInt::ZERO; // 0
1379 const TypeInt *TypeInt::ONE; // 1
1380 const TypeInt *TypeInt::BOOL; // 0 or 1, FALSE or TRUE.
1381 const TypeInt *TypeInt::CC; // -1,0 or 1, condition codes
1382 const TypeInt *TypeInt::CC_LT; // [-1] == MINUS_1
1383 const TypeInt *TypeInt::CC_GT; // [1] == ONE
1384 const TypeInt *TypeInt::CC_EQ; // [0] == ZERO
1385 const TypeInt *TypeInt::CC_LE; // [-1,0]
1386 const TypeInt *TypeInt::CC_GE; // [0,1] == BOOL (!)
1387 const TypeInt *TypeInt::BYTE; // Bytes, -128 to 127
1388 const TypeInt *TypeInt::UBYTE; // Unsigned Bytes, 0 to 255
1389 const TypeInt *TypeInt::CHAR; // Java chars, 0-65535
1390 const TypeInt *TypeInt::SHORT; // Java shorts, -32768-32767
1391 const TypeInt *TypeInt::POS; // Positive 32-bit integers or zero
1392 const TypeInt *TypeInt::POS1; // Positive 32-bit integers
1393 const TypeInt *TypeInt::INT; // 32-bit integers
1394 const TypeInt *TypeInt::SYMINT; // symmetric range [-max_jint..max_jint]
1395 const TypeInt *TypeInt::TYPE_DOMAIN; // alias for TypeInt::INT
1396
1397 //------------------------------TypeInt----------------------------------------
TypeInt(jint lo,jint hi,int w)1398 TypeInt::TypeInt( jint lo, jint hi, int w ) : TypeInteger(Int), _lo(lo), _hi(hi), _widen(w) {
1399 }
1400
1401 //------------------------------make-------------------------------------------
make(jint lo)1402 const TypeInt *TypeInt::make( jint lo ) {
1403 return (TypeInt*)(new TypeInt(lo,lo,WidenMin))->hashcons();
1404 }
1405
normalize_int_widen(jint lo,jint hi,int w)1406 static int normalize_int_widen( jint lo, jint hi, int w ) {
1407 // Certain normalizations keep us sane when comparing types.
1408 // The 'SMALLINT' covers constants and also CC and its relatives.
1409 if (lo <= hi) {
1410 if (((juint)hi - lo) <= SMALLINT) w = Type::WidenMin;
1411 if (((juint)hi - lo) >= max_juint) w = Type::WidenMax; // TypeInt::INT
1412 } else {
1413 if (((juint)lo - hi) <= SMALLINT) w = Type::WidenMin;
1414 if (((juint)lo - hi) >= max_juint) w = Type::WidenMin; // dual TypeInt::INT
1415 }
1416 return w;
1417 }
1418
make(jint lo,jint hi,int w)1419 const TypeInt *TypeInt::make( jint lo, jint hi, int w ) {
1420 w = normalize_int_widen(lo, hi, w);
1421 return (TypeInt*)(new TypeInt(lo,hi,w))->hashcons();
1422 }
1423
1424 //------------------------------meet-------------------------------------------
1425 // Compute the MEET of two types. It returns a new Type representation object
1426 // with reference count equal to the number of Types pointing at it.
1427 // Caller should wrap a Types around it.
xmeet(const Type * t) const1428 const Type *TypeInt::xmeet( const Type *t ) const {
1429 // Perform a fast test for common case; meeting the same types together.
1430 if( this == t ) return this; // Meeting same type?
1431
1432 // Currently "this->_base" is a TypeInt
1433 switch (t->base()) { // Switch on original type
1434 case AnyPtr: // Mixing with oops happens when javac
1435 case RawPtr: // reuses local variables
1436 case OopPtr:
1437 case InstPtr:
1438 case AryPtr:
1439 case MetadataPtr:
1440 case KlassPtr:
1441 case NarrowOop:
1442 case NarrowKlass:
1443 case Long:
1444 case FloatTop:
1445 case FloatCon:
1446 case FloatBot:
1447 case DoubleTop:
1448 case DoubleCon:
1449 case DoubleBot:
1450 case Bottom: // Ye Olde Default
1451 return Type::BOTTOM;
1452 default: // All else is a mistake
1453 typerr(t);
1454 case Top: // No change
1455 return this;
1456 case Int: // Int vs Int?
1457 break;
1458 }
1459
1460 // Expand covered set
1461 const TypeInt *r = t->is_int();
1462 return make( MIN2(_lo,r->_lo), MAX2(_hi,r->_hi), MAX2(_widen,r->_widen) );
1463 }
1464
1465 //------------------------------xdual------------------------------------------
1466 // Dual: reverse hi & lo; flip widen
xdual() const1467 const Type *TypeInt::xdual() const {
1468 int w = normalize_int_widen(_hi,_lo, WidenMax-_widen);
1469 return new TypeInt(_hi,_lo,w);
1470 }
1471
1472 //------------------------------widen------------------------------------------
1473 // Only happens for optimistic top-down optimizations.
widen(const Type * old,const Type * limit) const1474 const Type *TypeInt::widen( const Type *old, const Type* limit ) const {
1475 // Coming from TOP or such; no widening
1476 if( old->base() != Int ) return this;
1477 const TypeInt *ot = old->is_int();
1478
1479 // If new guy is equal to old guy, no widening
1480 if( _lo == ot->_lo && _hi == ot->_hi )
1481 return old;
1482
1483 // If new guy contains old, then we widened
1484 if( _lo <= ot->_lo && _hi >= ot->_hi ) {
1485 // New contains old
1486 // If new guy is already wider than old, no widening
1487 if( _widen > ot->_widen ) return this;
1488 // If old guy was a constant, do not bother
1489 if (ot->_lo == ot->_hi) return this;
1490 // Now widen new guy.
1491 // Check for widening too far
1492 if (_widen == WidenMax) {
1493 int max = max_jint;
1494 int min = min_jint;
1495 if (limit->isa_int()) {
1496 max = limit->is_int()->_hi;
1497 min = limit->is_int()->_lo;
1498 }
1499 if (min < _lo && _hi < max) {
1500 // If neither endpoint is extremal yet, push out the endpoint
1501 // which is closer to its respective limit.
1502 if (_lo >= 0 || // easy common case
1503 (juint)(_lo - min) >= (juint)(max - _hi)) {
1504 // Try to widen to an unsigned range type of 31 bits:
1505 return make(_lo, max, WidenMax);
1506 } else {
1507 return make(min, _hi, WidenMax);
1508 }
1509 }
1510 return TypeInt::INT;
1511 }
1512 // Returned widened new guy
1513 return make(_lo,_hi,_widen+1);
1514 }
1515
1516 // If old guy contains new, then we probably widened too far & dropped to
1517 // bottom. Return the wider fellow.
1518 if ( ot->_lo <= _lo && ot->_hi >= _hi )
1519 return old;
1520
1521 //fatal("Integer value range is not subset");
1522 //return this;
1523 return TypeInt::INT;
1524 }
1525
1526 //------------------------------narrow---------------------------------------
1527 // Only happens for pessimistic optimizations.
narrow(const Type * old) const1528 const Type *TypeInt::narrow( const Type *old ) const {
1529 if (_lo >= _hi) return this; // already narrow enough
1530 if (old == NULL) return this;
1531 const TypeInt* ot = old->isa_int();
1532 if (ot == NULL) return this;
1533 jint olo = ot->_lo;
1534 jint ohi = ot->_hi;
1535
1536 // If new guy is equal to old guy, no narrowing
1537 if (_lo == olo && _hi == ohi) return old;
1538
1539 // If old guy was maximum range, allow the narrowing
1540 if (olo == min_jint && ohi == max_jint) return this;
1541
1542 if (_lo < olo || _hi > ohi)
1543 return this; // doesn't narrow; pretty wierd
1544
1545 // The new type narrows the old type, so look for a "death march".
1546 // See comments on PhaseTransform::saturate.
1547 juint nrange = (juint)_hi - _lo;
1548 juint orange = (juint)ohi - olo;
1549 if (nrange < max_juint - 1 && nrange > (orange >> 1) + (SMALLINT*2)) {
1550 // Use the new type only if the range shrinks a lot.
1551 // We do not want the optimizer computing 2^31 point by point.
1552 return old;
1553 }
1554
1555 return this;
1556 }
1557
1558 //-----------------------------filter------------------------------------------
filter_helper(const Type * kills,bool include_speculative) const1559 const Type *TypeInt::filter_helper(const Type *kills, bool include_speculative) const {
1560 const TypeInt* ft = join_helper(kills, include_speculative)->isa_int();
1561 if (ft == NULL || ft->empty())
1562 return Type::TOP; // Canonical empty value
1563 if (ft->_widen < this->_widen) {
1564 // Do not allow the value of kill->_widen to affect the outcome.
1565 // The widen bits must be allowed to run freely through the graph.
1566 ft = TypeInt::make(ft->_lo, ft->_hi, this->_widen);
1567 }
1568 return ft;
1569 }
1570
1571 //------------------------------eq---------------------------------------------
1572 // Structural equality check for Type representations
eq(const Type * t) const1573 bool TypeInt::eq( const Type *t ) const {
1574 const TypeInt *r = t->is_int(); // Handy access
1575 return r->_lo == _lo && r->_hi == _hi && r->_widen == _widen;
1576 }
1577
1578 //------------------------------hash-------------------------------------------
1579 // Type-specific hashing function.
hash(void) const1580 int TypeInt::hash(void) const {
1581 return java_add(java_add(_lo, _hi), java_add((jint)_widen, (jint)Type::Int));
1582 }
1583
1584 //------------------------------is_finite--------------------------------------
1585 // Has a finite value
is_finite() const1586 bool TypeInt::is_finite() const {
1587 return true;
1588 }
1589
1590 //------------------------------dump2------------------------------------------
1591 // Dump TypeInt
1592 #ifndef PRODUCT
intname(char * buf,jint n)1593 static const char* intname(char* buf, jint n) {
1594 if (n == min_jint)
1595 return "min";
1596 else if (n < min_jint + 10000)
1597 sprintf(buf, "min+" INT32_FORMAT, n - min_jint);
1598 else if (n == max_jint)
1599 return "max";
1600 else if (n > max_jint - 10000)
1601 sprintf(buf, "max-" INT32_FORMAT, max_jint - n);
1602 else
1603 sprintf(buf, INT32_FORMAT, n);
1604 return buf;
1605 }
1606
dump2(Dict & d,uint depth,outputStream * st) const1607 void TypeInt::dump2( Dict &d, uint depth, outputStream *st ) const {
1608 char buf[40], buf2[40];
1609 if (_lo == min_jint && _hi == max_jint)
1610 st->print("int");
1611 else if (is_con())
1612 st->print("int:%s", intname(buf, get_con()));
1613 else if (_lo == BOOL->_lo && _hi == BOOL->_hi)
1614 st->print("bool");
1615 else if (_lo == BYTE->_lo && _hi == BYTE->_hi)
1616 st->print("byte");
1617 else if (_lo == CHAR->_lo && _hi == CHAR->_hi)
1618 st->print("char");
1619 else if (_lo == SHORT->_lo && _hi == SHORT->_hi)
1620 st->print("short");
1621 else if (_hi == max_jint)
1622 st->print("int:>=%s", intname(buf, _lo));
1623 else if (_lo == min_jint)
1624 st->print("int:<=%s", intname(buf, _hi));
1625 else
1626 st->print("int:%s..%s", intname(buf, _lo), intname(buf2, _hi));
1627
1628 if (_widen != 0 && this != TypeInt::INT)
1629 st->print(":%.*s", _widen, "wwww");
1630 }
1631 #endif
1632
1633 //------------------------------singleton--------------------------------------
1634 // TRUE if Type is a singleton type, FALSE otherwise. Singletons are simple
1635 // constants.
singleton(void) const1636 bool TypeInt::singleton(void) const {
1637 return _lo >= _hi;
1638 }
1639
empty(void) const1640 bool TypeInt::empty(void) const {
1641 return _lo > _hi;
1642 }
1643
1644 //=============================================================================
1645 // Convenience common pre-built types.
1646 const TypeLong *TypeLong::MAX;
1647 const TypeLong *TypeLong::MIN;
1648 const TypeLong *TypeLong::MINUS_1;// -1
1649 const TypeLong *TypeLong::ZERO; // 0
1650 const TypeLong *TypeLong::ONE; // 1
1651 const TypeLong *TypeLong::POS; // >=0
1652 const TypeLong *TypeLong::LONG; // 64-bit integers
1653 const TypeLong *TypeLong::INT; // 32-bit subrange
1654 const TypeLong *TypeLong::UINT; // 32-bit unsigned subrange
1655 const TypeLong *TypeLong::TYPE_DOMAIN; // alias for TypeLong::LONG
1656
1657 //------------------------------TypeLong---------------------------------------
TypeLong(jlong lo,jlong hi,int w)1658 TypeLong::TypeLong(jlong lo, jlong hi, int w) : TypeInteger(Long), _lo(lo), _hi(hi), _widen(w) {
1659 }
1660
1661 //------------------------------make-------------------------------------------
make(jlong lo)1662 const TypeLong *TypeLong::make( jlong lo ) {
1663 return (TypeLong*)(new TypeLong(lo,lo,WidenMin))->hashcons();
1664 }
1665
normalize_long_widen(jlong lo,jlong hi,int w)1666 static int normalize_long_widen( jlong lo, jlong hi, int w ) {
1667 // Certain normalizations keep us sane when comparing types.
1668 // The 'SMALLINT' covers constants.
1669 if (lo <= hi) {
1670 if (((julong)hi - lo) <= SMALLINT) w = Type::WidenMin;
1671 if (((julong)hi - lo) >= max_julong) w = Type::WidenMax; // TypeLong::LONG
1672 } else {
1673 if (((julong)lo - hi) <= SMALLINT) w = Type::WidenMin;
1674 if (((julong)lo - hi) >= max_julong) w = Type::WidenMin; // dual TypeLong::LONG
1675 }
1676 return w;
1677 }
1678
make(jlong lo,jlong hi,int w)1679 const TypeLong *TypeLong::make( jlong lo, jlong hi, int w ) {
1680 w = normalize_long_widen(lo, hi, w);
1681 return (TypeLong*)(new TypeLong(lo,hi,w))->hashcons();
1682 }
1683
1684
1685 //------------------------------meet-------------------------------------------
1686 // Compute the MEET of two types. It returns a new Type representation object
1687 // with reference count equal to the number of Types pointing at it.
1688 // Caller should wrap a Types around it.
xmeet(const Type * t) const1689 const Type *TypeLong::xmeet( const Type *t ) const {
1690 // Perform a fast test for common case; meeting the same types together.
1691 if( this == t ) return this; // Meeting same type?
1692
1693 // Currently "this->_base" is a TypeLong
1694 switch (t->base()) { // Switch on original type
1695 case AnyPtr: // Mixing with oops happens when javac
1696 case RawPtr: // reuses local variables
1697 case OopPtr:
1698 case InstPtr:
1699 case AryPtr:
1700 case MetadataPtr:
1701 case KlassPtr:
1702 case NarrowOop:
1703 case NarrowKlass:
1704 case Int:
1705 case FloatTop:
1706 case FloatCon:
1707 case FloatBot:
1708 case DoubleTop:
1709 case DoubleCon:
1710 case DoubleBot:
1711 case Bottom: // Ye Olde Default
1712 return Type::BOTTOM;
1713 default: // All else is a mistake
1714 typerr(t);
1715 case Top: // No change
1716 return this;
1717 case Long: // Long vs Long?
1718 break;
1719 }
1720
1721 // Expand covered set
1722 const TypeLong *r = t->is_long(); // Turn into a TypeLong
1723 return make( MIN2(_lo,r->_lo), MAX2(_hi,r->_hi), MAX2(_widen,r->_widen) );
1724 }
1725
1726 //------------------------------xdual------------------------------------------
1727 // Dual: reverse hi & lo; flip widen
xdual() const1728 const Type *TypeLong::xdual() const {
1729 int w = normalize_long_widen(_hi,_lo, WidenMax-_widen);
1730 return new TypeLong(_hi,_lo,w);
1731 }
1732
1733 //------------------------------widen------------------------------------------
1734 // Only happens for optimistic top-down optimizations.
widen(const Type * old,const Type * limit) const1735 const Type *TypeLong::widen( const Type *old, const Type* limit ) const {
1736 // Coming from TOP or such; no widening
1737 if( old->base() != Long ) return this;
1738 const TypeLong *ot = old->is_long();
1739
1740 // If new guy is equal to old guy, no widening
1741 if( _lo == ot->_lo && _hi == ot->_hi )
1742 return old;
1743
1744 // If new guy contains old, then we widened
1745 if( _lo <= ot->_lo && _hi >= ot->_hi ) {
1746 // New contains old
1747 // If new guy is already wider than old, no widening
1748 if( _widen > ot->_widen ) return this;
1749 // If old guy was a constant, do not bother
1750 if (ot->_lo == ot->_hi) return this;
1751 // Now widen new guy.
1752 // Check for widening too far
1753 if (_widen == WidenMax) {
1754 jlong max = max_jlong;
1755 jlong min = min_jlong;
1756 if (limit->isa_long()) {
1757 max = limit->is_long()->_hi;
1758 min = limit->is_long()->_lo;
1759 }
1760 if (min < _lo && _hi < max) {
1761 // If neither endpoint is extremal yet, push out the endpoint
1762 // which is closer to its respective limit.
1763 if (_lo >= 0 || // easy common case
1764 ((julong)_lo - min) >= ((julong)max - _hi)) {
1765 // Try to widen to an unsigned range type of 32/63 bits:
1766 if (max >= max_juint && _hi < max_juint)
1767 return make(_lo, max_juint, WidenMax);
1768 else
1769 return make(_lo, max, WidenMax);
1770 } else {
1771 return make(min, _hi, WidenMax);
1772 }
1773 }
1774 return TypeLong::LONG;
1775 }
1776 // Returned widened new guy
1777 return make(_lo,_hi,_widen+1);
1778 }
1779
1780 // If old guy contains new, then we probably widened too far & dropped to
1781 // bottom. Return the wider fellow.
1782 if ( ot->_lo <= _lo && ot->_hi >= _hi )
1783 return old;
1784
1785 // fatal("Long value range is not subset");
1786 // return this;
1787 return TypeLong::LONG;
1788 }
1789
1790 //------------------------------narrow----------------------------------------
1791 // Only happens for pessimistic optimizations.
narrow(const Type * old) const1792 const Type *TypeLong::narrow( const Type *old ) const {
1793 if (_lo >= _hi) return this; // already narrow enough
1794 if (old == NULL) return this;
1795 const TypeLong* ot = old->isa_long();
1796 if (ot == NULL) return this;
1797 jlong olo = ot->_lo;
1798 jlong ohi = ot->_hi;
1799
1800 // If new guy is equal to old guy, no narrowing
1801 if (_lo == olo && _hi == ohi) return old;
1802
1803 // If old guy was maximum range, allow the narrowing
1804 if (olo == min_jlong && ohi == max_jlong) return this;
1805
1806 if (_lo < olo || _hi > ohi)
1807 return this; // doesn't narrow; pretty wierd
1808
1809 // The new type narrows the old type, so look for a "death march".
1810 // See comments on PhaseTransform::saturate.
1811 julong nrange = _hi - _lo;
1812 julong orange = ohi - olo;
1813 if (nrange < max_julong - 1 && nrange > (orange >> 1) + (SMALLINT*2)) {
1814 // Use the new type only if the range shrinks a lot.
1815 // We do not want the optimizer computing 2^31 point by point.
1816 return old;
1817 }
1818
1819 return this;
1820 }
1821
1822 //-----------------------------filter------------------------------------------
filter_helper(const Type * kills,bool include_speculative) const1823 const Type *TypeLong::filter_helper(const Type *kills, bool include_speculative) const {
1824 const TypeLong* ft = join_helper(kills, include_speculative)->isa_long();
1825 if (ft == NULL || ft->empty())
1826 return Type::TOP; // Canonical empty value
1827 if (ft->_widen < this->_widen) {
1828 // Do not allow the value of kill->_widen to affect the outcome.
1829 // The widen bits must be allowed to run freely through the graph.
1830 ft = TypeLong::make(ft->_lo, ft->_hi, this->_widen);
1831 }
1832 return ft;
1833 }
1834
1835 //------------------------------eq---------------------------------------------
1836 // Structural equality check for Type representations
eq(const Type * t) const1837 bool TypeLong::eq( const Type *t ) const {
1838 const TypeLong *r = t->is_long(); // Handy access
1839 return r->_lo == _lo && r->_hi == _hi && r->_widen == _widen;
1840 }
1841
1842 //------------------------------hash-------------------------------------------
1843 // Type-specific hashing function.
hash(void) const1844 int TypeLong::hash(void) const {
1845 return (int)(_lo+_hi+_widen+(int)Type::Long);
1846 }
1847
1848 //------------------------------is_finite--------------------------------------
1849 // Has a finite value
is_finite() const1850 bool TypeLong::is_finite() const {
1851 return true;
1852 }
1853
1854 //------------------------------dump2------------------------------------------
1855 // Dump TypeLong
1856 #ifndef PRODUCT
longnamenear(jlong x,const char * xname,char * buf,jlong n)1857 static const char* longnamenear(jlong x, const char* xname, char* buf, jlong n) {
1858 if (n > x) {
1859 if (n >= x + 10000) return NULL;
1860 sprintf(buf, "%s+" JLONG_FORMAT, xname, n - x);
1861 } else if (n < x) {
1862 if (n <= x - 10000) return NULL;
1863 sprintf(buf, "%s-" JLONG_FORMAT, xname, x - n);
1864 } else {
1865 return xname;
1866 }
1867 return buf;
1868 }
1869
longname(char * buf,jlong n)1870 static const char* longname(char* buf, jlong n) {
1871 const char* str;
1872 if (n == min_jlong)
1873 return "min";
1874 else if (n < min_jlong + 10000)
1875 sprintf(buf, "min+" JLONG_FORMAT, n - min_jlong);
1876 else if (n == max_jlong)
1877 return "max";
1878 else if (n > max_jlong - 10000)
1879 sprintf(buf, "max-" JLONG_FORMAT, max_jlong - n);
1880 else if ((str = longnamenear(max_juint, "maxuint", buf, n)) != NULL)
1881 return str;
1882 else if ((str = longnamenear(max_jint, "maxint", buf, n)) != NULL)
1883 return str;
1884 else if ((str = longnamenear(min_jint, "minint", buf, n)) != NULL)
1885 return str;
1886 else
1887 sprintf(buf, JLONG_FORMAT, n);
1888 return buf;
1889 }
1890
dump2(Dict & d,uint depth,outputStream * st) const1891 void TypeLong::dump2( Dict &d, uint depth, outputStream *st ) const {
1892 char buf[80], buf2[80];
1893 if (_lo == min_jlong && _hi == max_jlong)
1894 st->print("long");
1895 else if (is_con())
1896 st->print("long:%s", longname(buf, get_con()));
1897 else if (_hi == max_jlong)
1898 st->print("long:>=%s", longname(buf, _lo));
1899 else if (_lo == min_jlong)
1900 st->print("long:<=%s", longname(buf, _hi));
1901 else
1902 st->print("long:%s..%s", longname(buf, _lo), longname(buf2, _hi));
1903
1904 if (_widen != 0 && this != TypeLong::LONG)
1905 st->print(":%.*s", _widen, "wwww");
1906 }
1907 #endif
1908
1909 //------------------------------singleton--------------------------------------
1910 // TRUE if Type is a singleton type, FALSE otherwise. Singletons are simple
1911 // constants
singleton(void) const1912 bool TypeLong::singleton(void) const {
1913 return _lo >= _hi;
1914 }
1915
empty(void) const1916 bool TypeLong::empty(void) const {
1917 return _lo > _hi;
1918 }
1919
1920 //=============================================================================
1921 // Convenience common pre-built types.
1922 const TypeTuple *TypeTuple::IFBOTH; // Return both arms of IF as reachable
1923 const TypeTuple *TypeTuple::IFFALSE;
1924 const TypeTuple *TypeTuple::IFTRUE;
1925 const TypeTuple *TypeTuple::IFNEITHER;
1926 const TypeTuple *TypeTuple::LOOPBODY;
1927 const TypeTuple *TypeTuple::MEMBAR;
1928 const TypeTuple *TypeTuple::STORECONDITIONAL;
1929 const TypeTuple *TypeTuple::START_I2C;
1930 const TypeTuple *TypeTuple::INT_PAIR;
1931 const TypeTuple *TypeTuple::LONG_PAIR;
1932 const TypeTuple *TypeTuple::INT_CC_PAIR;
1933 const TypeTuple *TypeTuple::LONG_CC_PAIR;
1934
1935 //------------------------------make-------------------------------------------
1936 // Make a TypeTuple from the range of a method signature
make_range(ciSignature * sig)1937 const TypeTuple *TypeTuple::make_range(ciSignature* sig) {
1938 ciType* return_type = sig->return_type();
1939 uint arg_cnt = return_type->size();
1940 const Type **field_array = fields(arg_cnt);
1941 switch (return_type->basic_type()) {
1942 case T_LONG:
1943 field_array[TypeFunc::Parms] = TypeLong::LONG;
1944 field_array[TypeFunc::Parms+1] = Type::HALF;
1945 break;
1946 case T_DOUBLE:
1947 field_array[TypeFunc::Parms] = Type::DOUBLE;
1948 field_array[TypeFunc::Parms+1] = Type::HALF;
1949 break;
1950 case T_OBJECT:
1951 case T_ARRAY:
1952 case T_BOOLEAN:
1953 case T_CHAR:
1954 case T_FLOAT:
1955 case T_BYTE:
1956 case T_SHORT:
1957 case T_INT:
1958 field_array[TypeFunc::Parms] = get_const_type(return_type);
1959 break;
1960 case T_VOID:
1961 break;
1962 default:
1963 ShouldNotReachHere();
1964 }
1965 return (TypeTuple*)(new TypeTuple(TypeFunc::Parms + arg_cnt, field_array))->hashcons();
1966 }
1967
1968 // Make a TypeTuple from the domain of a method signature
make_domain(ciInstanceKlass * recv,ciSignature * sig)1969 const TypeTuple *TypeTuple::make_domain(ciInstanceKlass* recv, ciSignature* sig) {
1970 uint arg_cnt = sig->size();
1971
1972 uint pos = TypeFunc::Parms;
1973 const Type **field_array;
1974 if (recv != NULL) {
1975 arg_cnt++;
1976 field_array = fields(arg_cnt);
1977 // Use get_const_type here because it respects UseUniqueSubclasses:
1978 field_array[pos++] = get_const_type(recv)->join_speculative(TypePtr::NOTNULL);
1979 } else {
1980 field_array = fields(arg_cnt);
1981 }
1982
1983 int i = 0;
1984 while (pos < TypeFunc::Parms + arg_cnt) {
1985 ciType* type = sig->type_at(i);
1986
1987 switch (type->basic_type()) {
1988 case T_LONG:
1989 field_array[pos++] = TypeLong::LONG;
1990 field_array[pos++] = Type::HALF;
1991 break;
1992 case T_DOUBLE:
1993 field_array[pos++] = Type::DOUBLE;
1994 field_array[pos++] = Type::HALF;
1995 break;
1996 case T_OBJECT:
1997 case T_ARRAY:
1998 case T_FLOAT:
1999 case T_INT:
2000 field_array[pos++] = get_const_type(type);
2001 break;
2002 case T_BOOLEAN:
2003 case T_CHAR:
2004 case T_BYTE:
2005 case T_SHORT:
2006 field_array[pos++] = TypeInt::INT;
2007 break;
2008 default:
2009 ShouldNotReachHere();
2010 }
2011 i++;
2012 }
2013
2014 return (TypeTuple*)(new TypeTuple(TypeFunc::Parms + arg_cnt, field_array))->hashcons();
2015 }
2016
make(uint cnt,const Type ** fields)2017 const TypeTuple *TypeTuple::make( uint cnt, const Type **fields ) {
2018 return (TypeTuple*)(new TypeTuple(cnt,fields))->hashcons();
2019 }
2020
2021 //------------------------------fields-----------------------------------------
2022 // Subroutine call type with space allocated for argument types
2023 // Memory for Control, I_O, Memory, FramePtr, and ReturnAdr is allocated implicitly
fields(uint arg_cnt)2024 const Type **TypeTuple::fields( uint arg_cnt ) {
2025 const Type **flds = (const Type **)(Compile::current()->type_arena()->Amalloc_4((TypeFunc::Parms+arg_cnt)*sizeof(Type*) ));
2026 flds[TypeFunc::Control ] = Type::CONTROL;
2027 flds[TypeFunc::I_O ] = Type::ABIO;
2028 flds[TypeFunc::Memory ] = Type::MEMORY;
2029 flds[TypeFunc::FramePtr ] = TypeRawPtr::BOTTOM;
2030 flds[TypeFunc::ReturnAdr] = Type::RETURN_ADDRESS;
2031
2032 return flds;
2033 }
2034
2035 //------------------------------meet-------------------------------------------
2036 // Compute the MEET of two types. It returns a new Type object.
xmeet(const Type * t) const2037 const Type *TypeTuple::xmeet( const Type *t ) const {
2038 // Perform a fast test for common case; meeting the same types together.
2039 if( this == t ) return this; // Meeting same type-rep?
2040
2041 // Current "this->_base" is Tuple
2042 switch (t->base()) { // switch on original type
2043
2044 case Bottom: // Ye Olde Default
2045 return t;
2046
2047 default: // All else is a mistake
2048 typerr(t);
2049
2050 case Tuple: { // Meeting 2 signatures?
2051 const TypeTuple *x = t->is_tuple();
2052 assert( _cnt == x->_cnt, "" );
2053 const Type **fields = (const Type **)(Compile::current()->type_arena()->Amalloc_4( _cnt*sizeof(Type*) ));
2054 for( uint i=0; i<_cnt; i++ )
2055 fields[i] = field_at(i)->xmeet( x->field_at(i) );
2056 return TypeTuple::make(_cnt,fields);
2057 }
2058 case Top:
2059 break;
2060 }
2061 return this; // Return the double constant
2062 }
2063
2064 //------------------------------xdual------------------------------------------
2065 // Dual: compute field-by-field dual
xdual() const2066 const Type *TypeTuple::xdual() const {
2067 const Type **fields = (const Type **)(Compile::current()->type_arena()->Amalloc_4( _cnt*sizeof(Type*) ));
2068 for( uint i=0; i<_cnt; i++ )
2069 fields[i] = _fields[i]->dual();
2070 return new TypeTuple(_cnt,fields);
2071 }
2072
2073 //------------------------------eq---------------------------------------------
2074 // Structural equality check for Type representations
eq(const Type * t) const2075 bool TypeTuple::eq( const Type *t ) const {
2076 const TypeTuple *s = (const TypeTuple *)t;
2077 if (_cnt != s->_cnt) return false; // Unequal field counts
2078 for (uint i = 0; i < _cnt; i++)
2079 if (field_at(i) != s->field_at(i)) // POINTER COMPARE! NO RECURSION!
2080 return false; // Missed
2081 return true;
2082 }
2083
2084 //------------------------------hash-------------------------------------------
2085 // Type-specific hashing function.
hash(void) const2086 int TypeTuple::hash(void) const {
2087 intptr_t sum = _cnt;
2088 for( uint i=0; i<_cnt; i++ )
2089 sum += (intptr_t)_fields[i]; // Hash on pointers directly
2090 return sum;
2091 }
2092
2093 //------------------------------dump2------------------------------------------
2094 // Dump signature Type
2095 #ifndef PRODUCT
dump2(Dict & d,uint depth,outputStream * st) const2096 void TypeTuple::dump2( Dict &d, uint depth, outputStream *st ) const {
2097 st->print("{");
2098 if( !depth || d[this] ) { // Check for recursive print
2099 st->print("...}");
2100 return;
2101 }
2102 d.Insert((void*)this, (void*)this); // Stop recursion
2103 if( _cnt ) {
2104 uint i;
2105 for( i=0; i<_cnt-1; i++ ) {
2106 st->print("%d:", i);
2107 _fields[i]->dump2(d, depth-1, st);
2108 st->print(", ");
2109 }
2110 st->print("%d:", i);
2111 _fields[i]->dump2(d, depth-1, st);
2112 }
2113 st->print("}");
2114 }
2115 #endif
2116
2117 //------------------------------singleton--------------------------------------
2118 // TRUE if Type is a singleton type, FALSE otherwise. Singletons are simple
2119 // constants (Ldi nodes). Singletons are integer, float or double constants
2120 // or a single symbol.
singleton(void) const2121 bool TypeTuple::singleton(void) const {
2122 return false; // Never a singleton
2123 }
2124
empty(void) const2125 bool TypeTuple::empty(void) const {
2126 for( uint i=0; i<_cnt; i++ ) {
2127 if (_fields[i]->empty()) return true;
2128 }
2129 return false;
2130 }
2131
2132 //=============================================================================
2133 // Convenience common pre-built types.
2134
normalize_array_size(const TypeInt * size)2135 inline const TypeInt* normalize_array_size(const TypeInt* size) {
2136 // Certain normalizations keep us sane when comparing types.
2137 // We do not want arrayOop variables to differ only by the wideness
2138 // of their index types. Pick minimum wideness, since that is the
2139 // forced wideness of small ranges anyway.
2140 if (size->_widen != Type::WidenMin)
2141 return TypeInt::make(size->_lo, size->_hi, Type::WidenMin);
2142 else
2143 return size;
2144 }
2145
2146 //------------------------------make-------------------------------------------
make(const Type * elem,const TypeInt * size,bool stable)2147 const TypeAry* TypeAry::make(const Type* elem, const TypeInt* size, bool stable) {
2148 if (UseCompressedOops && elem->isa_oopptr()) {
2149 elem = elem->make_narrowoop();
2150 }
2151 size = normalize_array_size(size);
2152 return (TypeAry*)(new TypeAry(elem,size,stable))->hashcons();
2153 }
2154
2155 //------------------------------meet-------------------------------------------
2156 // Compute the MEET of two types. It returns a new Type object.
xmeet(const Type * t) const2157 const Type *TypeAry::xmeet( const Type *t ) const {
2158 // Perform a fast test for common case; meeting the same types together.
2159 if( this == t ) return this; // Meeting same type-rep?
2160
2161 // Current "this->_base" is Ary
2162 switch (t->base()) { // switch on original type
2163
2164 case Bottom: // Ye Olde Default
2165 return t;
2166
2167 default: // All else is a mistake
2168 typerr(t);
2169
2170 case Array: { // Meeting 2 arrays?
2171 const TypeAry *a = t->is_ary();
2172 return TypeAry::make(_elem->meet_speculative(a->_elem),
2173 _size->xmeet(a->_size)->is_int(),
2174 _stable && a->_stable);
2175 }
2176 case Top:
2177 break;
2178 }
2179 return this; // Return the double constant
2180 }
2181
2182 //------------------------------xdual------------------------------------------
2183 // Dual: compute field-by-field dual
xdual() const2184 const Type *TypeAry::xdual() const {
2185 const TypeInt* size_dual = _size->dual()->is_int();
2186 size_dual = normalize_array_size(size_dual);
2187 return new TypeAry(_elem->dual(), size_dual, !_stable);
2188 }
2189
2190 //------------------------------eq---------------------------------------------
2191 // Structural equality check for Type representations
eq(const Type * t) const2192 bool TypeAry::eq( const Type *t ) const {
2193 const TypeAry *a = (const TypeAry*)t;
2194 return _elem == a->_elem &&
2195 _stable == a->_stable &&
2196 _size == a->_size;
2197 }
2198
2199 //------------------------------hash-------------------------------------------
2200 // Type-specific hashing function.
hash(void) const2201 int TypeAry::hash(void) const {
2202 return (intptr_t)_elem + (intptr_t)_size + (_stable ? 43 : 0);
2203 }
2204
2205 /**
2206 * Return same type without a speculative part in the element
2207 */
remove_speculative() const2208 const Type* TypeAry::remove_speculative() const {
2209 return make(_elem->remove_speculative(), _size, _stable);
2210 }
2211
2212 /**
2213 * Return same type with cleaned up speculative part of element
2214 */
cleanup_speculative() const2215 const Type* TypeAry::cleanup_speculative() const {
2216 return make(_elem->cleanup_speculative(), _size, _stable);
2217 }
2218
2219 /**
2220 * Return same type but with a different inline depth (used for speculation)
2221 *
2222 * @param depth depth to meet with
2223 */
with_inline_depth(int depth) const2224 const TypePtr* TypePtr::with_inline_depth(int depth) const {
2225 if (!UseInlineDepthForSpeculativeTypes) {
2226 return this;
2227 }
2228 return make(AnyPtr, _ptr, _offset, _speculative, depth);
2229 }
2230
2231 //----------------------interface_vs_oop---------------------------------------
2232 #ifdef ASSERT
interface_vs_oop(const Type * t) const2233 bool TypeAry::interface_vs_oop(const Type *t) const {
2234 const TypeAry* t_ary = t->is_ary();
2235 if (t_ary) {
2236 const TypePtr* this_ptr = _elem->make_ptr(); // In case we have narrow_oops
2237 const TypePtr* t_ptr = t_ary->_elem->make_ptr();
2238 if(this_ptr != NULL && t_ptr != NULL) {
2239 return this_ptr->interface_vs_oop(t_ptr);
2240 }
2241 }
2242 return false;
2243 }
2244 #endif
2245
2246 //------------------------------dump2------------------------------------------
2247 #ifndef PRODUCT
dump2(Dict & d,uint depth,outputStream * st) const2248 void TypeAry::dump2( Dict &d, uint depth, outputStream *st ) const {
2249 if (_stable) st->print("stable:");
2250 _elem->dump2(d, depth, st);
2251 st->print("[");
2252 _size->dump2(d, depth, st);
2253 st->print("]");
2254 }
2255 #endif
2256
2257 //------------------------------singleton--------------------------------------
2258 // TRUE if Type is a singleton type, FALSE otherwise. Singletons are simple
2259 // constants (Ldi nodes). Singletons are integer, float or double constants
2260 // or a single symbol.
singleton(void) const2261 bool TypeAry::singleton(void) const {
2262 return false; // Never a singleton
2263 }
2264
empty(void) const2265 bool TypeAry::empty(void) const {
2266 return _elem->empty() || _size->empty();
2267 }
2268
2269 //--------------------------ary_must_be_exact----------------------------------
ary_must_be_exact() const2270 bool TypeAry::ary_must_be_exact() const {
2271 // This logic looks at the element type of an array, and returns true
2272 // if the element type is either a primitive or a final instance class.
2273 // In such cases, an array built on this ary must have no subclasses.
2274 if (_elem == BOTTOM) return false; // general array not exact
2275 if (_elem == TOP ) return false; // inverted general array not exact
2276 const TypeOopPtr* toop = NULL;
2277 if (UseCompressedOops && _elem->isa_narrowoop()) {
2278 toop = _elem->make_ptr()->isa_oopptr();
2279 } else {
2280 toop = _elem->isa_oopptr();
2281 }
2282 if (!toop) return true; // a primitive type, like int
2283 ciKlass* tklass = toop->klass();
2284 if (tklass == NULL) return false; // unloaded class
2285 if (!tklass->is_loaded()) return false; // unloaded class
2286 const TypeInstPtr* tinst;
2287 if (_elem->isa_narrowoop())
2288 tinst = _elem->make_ptr()->isa_instptr();
2289 else
2290 tinst = _elem->isa_instptr();
2291 if (tinst)
2292 return tklass->as_instance_klass()->is_final();
2293 const TypeAryPtr* tap;
2294 if (_elem->isa_narrowoop())
2295 tap = _elem->make_ptr()->isa_aryptr();
2296 else
2297 tap = _elem->isa_aryptr();
2298 if (tap)
2299 return tap->ary()->ary_must_be_exact();
2300 return false;
2301 }
2302
2303 //==============================TypeVect=======================================
2304 // Convenience common pre-built types.
2305 const TypeVect *TypeVect::VECTA = NULL; // vector length agnostic
2306 const TypeVect *TypeVect::VECTS = NULL; // 32-bit vectors
2307 const TypeVect *TypeVect::VECTD = NULL; // 64-bit vectors
2308 const TypeVect *TypeVect::VECTX = NULL; // 128-bit vectors
2309 const TypeVect *TypeVect::VECTY = NULL; // 256-bit vectors
2310 const TypeVect *TypeVect::VECTZ = NULL; // 512-bit vectors
2311
2312 //------------------------------make-------------------------------------------
make(const Type * elem,uint length)2313 const TypeVect* TypeVect::make(const Type *elem, uint length) {
2314 BasicType elem_bt = elem->array_element_basic_type();
2315 assert(is_java_primitive(elem_bt), "only primitive types in vector");
2316 assert(Matcher::vector_size_supported(elem_bt, length), "length in range");
2317 int size = length * type2aelembytes(elem_bt);
2318 switch (Matcher::vector_ideal_reg(size)) {
2319 case Op_VecA:
2320 return (TypeVect*)(new TypeVectA(elem, length))->hashcons();
2321 case Op_VecS:
2322 return (TypeVect*)(new TypeVectS(elem, length))->hashcons();
2323 case Op_RegL:
2324 case Op_VecD:
2325 case Op_RegD:
2326 return (TypeVect*)(new TypeVectD(elem, length))->hashcons();
2327 case Op_VecX:
2328 return (TypeVect*)(new TypeVectX(elem, length))->hashcons();
2329 case Op_VecY:
2330 return (TypeVect*)(new TypeVectY(elem, length))->hashcons();
2331 case Op_VecZ:
2332 return (TypeVect*)(new TypeVectZ(elem, length))->hashcons();
2333 }
2334 ShouldNotReachHere();
2335 return NULL;
2336 }
2337
2338 //------------------------------meet-------------------------------------------
2339 // Compute the MEET of two types. It returns a new Type object.
xmeet(const Type * t) const2340 const Type *TypeVect::xmeet( const Type *t ) const {
2341 // Perform a fast test for common case; meeting the same types together.
2342 if( this == t ) return this; // Meeting same type-rep?
2343
2344 // Current "this->_base" is Vector
2345 switch (t->base()) { // switch on original type
2346
2347 case Bottom: // Ye Olde Default
2348 return t;
2349
2350 default: // All else is a mistake
2351 typerr(t);
2352 case VectorA:
2353 case VectorS:
2354 case VectorD:
2355 case VectorX:
2356 case VectorY:
2357 case VectorZ: { // Meeting 2 vectors?
2358 const TypeVect* v = t->is_vect();
2359 assert( base() == v->base(), "");
2360 assert(length() == v->length(), "");
2361 assert(element_basic_type() == v->element_basic_type(), "");
2362 return TypeVect::make(_elem->xmeet(v->_elem), _length);
2363 }
2364 case Top:
2365 break;
2366 }
2367 return this;
2368 }
2369
2370 //------------------------------xdual------------------------------------------
2371 // Dual: compute field-by-field dual
xdual() const2372 const Type *TypeVect::xdual() const {
2373 return new TypeVect(base(), _elem->dual(), _length);
2374 }
2375
2376 //------------------------------eq---------------------------------------------
2377 // Structural equality check for Type representations
eq(const Type * t) const2378 bool TypeVect::eq(const Type *t) const {
2379 const TypeVect *v = t->is_vect();
2380 return (_elem == v->_elem) && (_length == v->_length);
2381 }
2382
2383 //------------------------------hash-------------------------------------------
2384 // Type-specific hashing function.
hash(void) const2385 int TypeVect::hash(void) const {
2386 return (intptr_t)_elem + (intptr_t)_length;
2387 }
2388
2389 //------------------------------singleton--------------------------------------
2390 // TRUE if Type is a singleton type, FALSE otherwise. Singletons are simple
2391 // constants (Ldi nodes). Vector is singleton if all elements are the same
2392 // constant value (when vector is created with Replicate code).
singleton(void) const2393 bool TypeVect::singleton(void) const {
2394 // There is no Con node for vectors yet.
2395 // return _elem->singleton();
2396 return false;
2397 }
2398
empty(void) const2399 bool TypeVect::empty(void) const {
2400 return _elem->empty();
2401 }
2402
2403 //------------------------------dump2------------------------------------------
2404 #ifndef PRODUCT
dump2(Dict & d,uint depth,outputStream * st) const2405 void TypeVect::dump2(Dict &d, uint depth, outputStream *st) const {
2406 switch (base()) {
2407 case VectorA:
2408 st->print("vectora["); break;
2409 case VectorS:
2410 st->print("vectors["); break;
2411 case VectorD:
2412 st->print("vectord["); break;
2413 case VectorX:
2414 st->print("vectorx["); break;
2415 case VectorY:
2416 st->print("vectory["); break;
2417 case VectorZ:
2418 st->print("vectorz["); break;
2419 default:
2420 ShouldNotReachHere();
2421 }
2422 st->print("%d]:{", _length);
2423 _elem->dump2(d, depth, st);
2424 st->print("}");
2425 }
2426 #endif
2427
2428
2429 //=============================================================================
2430 // Convenience common pre-built types.
2431 const TypePtr *TypePtr::NULL_PTR;
2432 const TypePtr *TypePtr::NOTNULL;
2433 const TypePtr *TypePtr::BOTTOM;
2434
2435 //------------------------------meet-------------------------------------------
2436 // Meet over the PTR enum
2437 const TypePtr::PTR TypePtr::ptr_meet[TypePtr::lastPTR][TypePtr::lastPTR] = {
2438 // TopPTR, AnyNull, Constant, Null, NotNull, BotPTR,
2439 { /* Top */ TopPTR, AnyNull, Constant, Null, NotNull, BotPTR,},
2440 { /* AnyNull */ AnyNull, AnyNull, Constant, BotPTR, NotNull, BotPTR,},
2441 { /* Constant*/ Constant, Constant, Constant, BotPTR, NotNull, BotPTR,},
2442 { /* Null */ Null, BotPTR, BotPTR, Null, BotPTR, BotPTR,},
2443 { /* NotNull */ NotNull, NotNull, NotNull, BotPTR, NotNull, BotPTR,},
2444 { /* BotPTR */ BotPTR, BotPTR, BotPTR, BotPTR, BotPTR, BotPTR,}
2445 };
2446
2447 //------------------------------make-------------------------------------------
make(TYPES t,enum PTR ptr,int offset,const TypePtr * speculative,int inline_depth)2448 const TypePtr *TypePtr::make(TYPES t, enum PTR ptr, int offset, const TypePtr* speculative, int inline_depth) {
2449 return (TypePtr*)(new TypePtr(t,ptr,offset, speculative, inline_depth))->hashcons();
2450 }
2451
2452 //------------------------------cast_to_ptr_type-------------------------------
cast_to_ptr_type(PTR ptr) const2453 const Type *TypePtr::cast_to_ptr_type(PTR ptr) const {
2454 assert(_base == AnyPtr, "subclass must override cast_to_ptr_type");
2455 if( ptr == _ptr ) return this;
2456 return make(_base, ptr, _offset, _speculative, _inline_depth);
2457 }
2458
2459 //------------------------------get_con----------------------------------------
get_con() const2460 intptr_t TypePtr::get_con() const {
2461 assert( _ptr == Null, "" );
2462 return _offset;
2463 }
2464
2465 //------------------------------meet-------------------------------------------
2466 // Compute the MEET of two types. It returns a new Type object.
xmeet(const Type * t) const2467 const Type *TypePtr::xmeet(const Type *t) const {
2468 const Type* res = xmeet_helper(t);
2469 if (res->isa_ptr() == NULL) {
2470 return res;
2471 }
2472
2473 const TypePtr* res_ptr = res->is_ptr();
2474 if (res_ptr->speculative() != NULL) {
2475 // type->speculative() == NULL means that speculation is no better
2476 // than type, i.e. type->speculative() == type. So there are 2
2477 // ways to represent the fact that we have no useful speculative
2478 // data and we should use a single one to be able to test for
2479 // equality between types. Check whether type->speculative() ==
2480 // type and set speculative to NULL if it is the case.
2481 if (res_ptr->remove_speculative() == res_ptr->speculative()) {
2482 return res_ptr->remove_speculative();
2483 }
2484 }
2485
2486 return res;
2487 }
2488
xmeet_helper(const Type * t) const2489 const Type *TypePtr::xmeet_helper(const Type *t) const {
2490 // Perform a fast test for common case; meeting the same types together.
2491 if( this == t ) return this; // Meeting same type-rep?
2492
2493 // Current "this->_base" is AnyPtr
2494 switch (t->base()) { // switch on original type
2495 case Int: // Mixing ints & oops happens when javac
2496 case Long: // reuses local variables
2497 case FloatTop:
2498 case FloatCon:
2499 case FloatBot:
2500 case DoubleTop:
2501 case DoubleCon:
2502 case DoubleBot:
2503 case NarrowOop:
2504 case NarrowKlass:
2505 case Bottom: // Ye Olde Default
2506 return Type::BOTTOM;
2507 case Top:
2508 return this;
2509
2510 case AnyPtr: { // Meeting to AnyPtrs
2511 const TypePtr *tp = t->is_ptr();
2512 const TypePtr* speculative = xmeet_speculative(tp);
2513 int depth = meet_inline_depth(tp->inline_depth());
2514 return make(AnyPtr, meet_ptr(tp->ptr()), meet_offset(tp->offset()), speculative, depth);
2515 }
2516 case RawPtr: // For these, flip the call around to cut down
2517 case OopPtr:
2518 case InstPtr: // on the cases I have to handle.
2519 case AryPtr:
2520 case MetadataPtr:
2521 case KlassPtr:
2522 return t->xmeet(this); // Call in reverse direction
2523 default: // All else is a mistake
2524 typerr(t);
2525
2526 }
2527 return this;
2528 }
2529
2530 //------------------------------meet_offset------------------------------------
meet_offset(int offset) const2531 int TypePtr::meet_offset( int offset ) const {
2532 // Either is 'TOP' offset? Return the other offset!
2533 if( _offset == OffsetTop ) return offset;
2534 if( offset == OffsetTop ) return _offset;
2535 // If either is different, return 'BOTTOM' offset
2536 if( _offset != offset ) return OffsetBot;
2537 return _offset;
2538 }
2539
2540 //------------------------------dual_offset------------------------------------
dual_offset() const2541 int TypePtr::dual_offset( ) const {
2542 if( _offset == OffsetTop ) return OffsetBot;// Map 'TOP' into 'BOTTOM'
2543 if( _offset == OffsetBot ) return OffsetTop;// Map 'BOTTOM' into 'TOP'
2544 return _offset; // Map everything else into self
2545 }
2546
2547 //------------------------------xdual------------------------------------------
2548 // Dual: compute field-by-field dual
2549 const TypePtr::PTR TypePtr::ptr_dual[TypePtr::lastPTR] = {
2550 BotPTR, NotNull, Constant, Null, AnyNull, TopPTR
2551 };
xdual() const2552 const Type *TypePtr::xdual() const {
2553 return new TypePtr(AnyPtr, dual_ptr(), dual_offset(), dual_speculative(), dual_inline_depth());
2554 }
2555
2556 //------------------------------xadd_offset------------------------------------
xadd_offset(intptr_t offset) const2557 int TypePtr::xadd_offset( intptr_t offset ) const {
2558 // Adding to 'TOP' offset? Return 'TOP'!
2559 if( _offset == OffsetTop || offset == OffsetTop ) return OffsetTop;
2560 // Adding to 'BOTTOM' offset? Return 'BOTTOM'!
2561 if( _offset == OffsetBot || offset == OffsetBot ) return OffsetBot;
2562 // Addition overflows or "accidentally" equals to OffsetTop? Return 'BOTTOM'!
2563 offset += (intptr_t)_offset;
2564 if (offset != (int)offset || offset == OffsetTop) return OffsetBot;
2565
2566 // assert( _offset >= 0 && _offset+offset >= 0, "" );
2567 // It is possible to construct a negative offset during PhaseCCP
2568
2569 return (int)offset; // Sum valid offsets
2570 }
2571
2572 //------------------------------add_offset-------------------------------------
add_offset(intptr_t offset) const2573 const TypePtr *TypePtr::add_offset( intptr_t offset ) const {
2574 return make(AnyPtr, _ptr, xadd_offset(offset), _speculative, _inline_depth);
2575 }
2576
2577 //------------------------------eq---------------------------------------------
2578 // Structural equality check for Type representations
eq(const Type * t) const2579 bool TypePtr::eq( const Type *t ) const {
2580 const TypePtr *a = (const TypePtr*)t;
2581 return _ptr == a->ptr() && _offset == a->offset() && eq_speculative(a) && _inline_depth == a->_inline_depth;
2582 }
2583
2584 //------------------------------hash-------------------------------------------
2585 // Type-specific hashing function.
hash(void) const2586 int TypePtr::hash(void) const {
2587 return java_add(java_add((jint)_ptr, (jint)_offset), java_add((jint)hash_speculative(), (jint)_inline_depth));
2588 ;
2589 }
2590
2591 /**
2592 * Return same type without a speculative part
2593 */
remove_speculative() const2594 const Type* TypePtr::remove_speculative() const {
2595 if (_speculative == NULL) {
2596 return this;
2597 }
2598 assert(_inline_depth == InlineDepthTop || _inline_depth == InlineDepthBottom, "non speculative type shouldn't have inline depth");
2599 return make(AnyPtr, _ptr, _offset, NULL, _inline_depth);
2600 }
2601
2602 /**
2603 * Return same type but drop speculative part if we know we won't use
2604 * it
2605 */
cleanup_speculative() const2606 const Type* TypePtr::cleanup_speculative() const {
2607 if (speculative() == NULL) {
2608 return this;
2609 }
2610 const Type* no_spec = remove_speculative();
2611 // If this is NULL_PTR then we don't need the speculative type
2612 // (with_inline_depth in case the current type inline depth is
2613 // InlineDepthTop)
2614 if (no_spec == NULL_PTR->with_inline_depth(inline_depth())) {
2615 return no_spec;
2616 }
2617 if (above_centerline(speculative()->ptr())) {
2618 return no_spec;
2619 }
2620 const TypeOopPtr* spec_oopptr = speculative()->isa_oopptr();
2621 // If the speculative may be null and is an inexact klass then it
2622 // doesn't help
2623 if (speculative() != TypePtr::NULL_PTR && speculative()->maybe_null() &&
2624 (spec_oopptr == NULL || !spec_oopptr->klass_is_exact())) {
2625 return no_spec;
2626 }
2627 return this;
2628 }
2629
2630 /**
2631 * dual of the speculative part of the type
2632 */
dual_speculative() const2633 const TypePtr* TypePtr::dual_speculative() const {
2634 if (_speculative == NULL) {
2635 return NULL;
2636 }
2637 return _speculative->dual()->is_ptr();
2638 }
2639
2640 /**
2641 * meet of the speculative parts of 2 types
2642 *
2643 * @param other type to meet with
2644 */
xmeet_speculative(const TypePtr * other) const2645 const TypePtr* TypePtr::xmeet_speculative(const TypePtr* other) const {
2646 bool this_has_spec = (_speculative != NULL);
2647 bool other_has_spec = (other->speculative() != NULL);
2648
2649 if (!this_has_spec && !other_has_spec) {
2650 return NULL;
2651 }
2652
2653 // If we are at a point where control flow meets and one branch has
2654 // a speculative type and the other has not, we meet the speculative
2655 // type of one branch with the actual type of the other. If the
2656 // actual type is exact and the speculative is as well, then the
2657 // result is a speculative type which is exact and we can continue
2658 // speculation further.
2659 const TypePtr* this_spec = _speculative;
2660 const TypePtr* other_spec = other->speculative();
2661
2662 if (!this_has_spec) {
2663 this_spec = this;
2664 }
2665
2666 if (!other_has_spec) {
2667 other_spec = other;
2668 }
2669
2670 return this_spec->meet(other_spec)->is_ptr();
2671 }
2672
2673 /**
2674 * dual of the inline depth for this type (used for speculation)
2675 */
dual_inline_depth() const2676 int TypePtr::dual_inline_depth() const {
2677 return -inline_depth();
2678 }
2679
2680 /**
2681 * meet of 2 inline depths (used for speculation)
2682 *
2683 * @param depth depth to meet with
2684 */
meet_inline_depth(int depth) const2685 int TypePtr::meet_inline_depth(int depth) const {
2686 return MAX2(inline_depth(), depth);
2687 }
2688
2689 /**
2690 * Are the speculative parts of 2 types equal?
2691 *
2692 * @param other type to compare this one to
2693 */
eq_speculative(const TypePtr * other) const2694 bool TypePtr::eq_speculative(const TypePtr* other) const {
2695 if (_speculative == NULL || other->speculative() == NULL) {
2696 return _speculative == other->speculative();
2697 }
2698
2699 if (_speculative->base() != other->speculative()->base()) {
2700 return false;
2701 }
2702
2703 return _speculative->eq(other->speculative());
2704 }
2705
2706 /**
2707 * Hash of the speculative part of the type
2708 */
hash_speculative() const2709 int TypePtr::hash_speculative() const {
2710 if (_speculative == NULL) {
2711 return 0;
2712 }
2713
2714 return _speculative->hash();
2715 }
2716
2717 /**
2718 * add offset to the speculative part of the type
2719 *
2720 * @param offset offset to add
2721 */
add_offset_speculative(intptr_t offset) const2722 const TypePtr* TypePtr::add_offset_speculative(intptr_t offset) const {
2723 if (_speculative == NULL) {
2724 return NULL;
2725 }
2726 return _speculative->add_offset(offset)->is_ptr();
2727 }
2728
2729 /**
2730 * return exact klass from the speculative type if there's one
2731 */
speculative_type() const2732 ciKlass* TypePtr::speculative_type() const {
2733 if (_speculative != NULL && _speculative->isa_oopptr()) {
2734 const TypeOopPtr* speculative = _speculative->join(this)->is_oopptr();
2735 if (speculative->klass_is_exact()) {
2736 return speculative->klass();
2737 }
2738 }
2739 return NULL;
2740 }
2741
2742 /**
2743 * return true if speculative type may be null
2744 */
speculative_maybe_null() const2745 bool TypePtr::speculative_maybe_null() const {
2746 if (_speculative != NULL) {
2747 const TypePtr* speculative = _speculative->join(this)->is_ptr();
2748 return speculative->maybe_null();
2749 }
2750 return true;
2751 }
2752
speculative_always_null() const2753 bool TypePtr::speculative_always_null() const {
2754 if (_speculative != NULL) {
2755 const TypePtr* speculative = _speculative->join(this)->is_ptr();
2756 return speculative == TypePtr::NULL_PTR;
2757 }
2758 return false;
2759 }
2760
2761 /**
2762 * Same as TypePtr::speculative_type() but return the klass only if
2763 * the speculative tells us is not null
2764 */
speculative_type_not_null() const2765 ciKlass* TypePtr::speculative_type_not_null() const {
2766 if (speculative_maybe_null()) {
2767 return NULL;
2768 }
2769 return speculative_type();
2770 }
2771
2772 /**
2773 * Check whether new profiling would improve speculative type
2774 *
2775 * @param exact_kls class from profiling
2776 * @param inline_depth inlining depth of profile point
2777 *
2778 * @return true if type profile is valuable
2779 */
would_improve_type(ciKlass * exact_kls,int inline_depth) const2780 bool TypePtr::would_improve_type(ciKlass* exact_kls, int inline_depth) const {
2781 // no profiling?
2782 if (exact_kls == NULL) {
2783 return false;
2784 }
2785 if (speculative() == TypePtr::NULL_PTR) {
2786 return false;
2787 }
2788 // no speculative type or non exact speculative type?
2789 if (speculative_type() == NULL) {
2790 return true;
2791 }
2792 // If the node already has an exact speculative type keep it,
2793 // unless it was provided by profiling that is at a deeper
2794 // inlining level. Profiling at a higher inlining depth is
2795 // expected to be less accurate.
2796 if (_speculative->inline_depth() == InlineDepthBottom) {
2797 return false;
2798 }
2799 assert(_speculative->inline_depth() != InlineDepthTop, "can't do the comparison");
2800 return inline_depth < _speculative->inline_depth();
2801 }
2802
2803 /**
2804 * Check whether new profiling would improve ptr (= tells us it is non
2805 * null)
2806 *
2807 * @param ptr_kind always null or not null?
2808 *
2809 * @return true if ptr profile is valuable
2810 */
would_improve_ptr(ProfilePtrKind ptr_kind) const2811 bool TypePtr::would_improve_ptr(ProfilePtrKind ptr_kind) const {
2812 // profiling doesn't tell us anything useful
2813 if (ptr_kind != ProfileAlwaysNull && ptr_kind != ProfileNeverNull) {
2814 return false;
2815 }
2816 // We already know this is not null
2817 if (!this->maybe_null()) {
2818 return false;
2819 }
2820 // We already know the speculative type cannot be null
2821 if (!speculative_maybe_null()) {
2822 return false;
2823 }
2824 // We already know this is always null
2825 if (this == TypePtr::NULL_PTR) {
2826 return false;
2827 }
2828 // We already know the speculative type is always null
2829 if (speculative_always_null()) {
2830 return false;
2831 }
2832 if (ptr_kind == ProfileAlwaysNull && speculative() != NULL && speculative()->isa_oopptr()) {
2833 return false;
2834 }
2835 return true;
2836 }
2837
2838 //------------------------------dump2------------------------------------------
2839 const char *const TypePtr::ptr_msg[TypePtr::lastPTR] = {
2840 "TopPTR","AnyNull","Constant","NULL","NotNull","BotPTR"
2841 };
2842
2843 #ifndef PRODUCT
dump2(Dict & d,uint depth,outputStream * st) const2844 void TypePtr::dump2( Dict &d, uint depth, outputStream *st ) const {
2845 if( _ptr == Null ) st->print("NULL");
2846 else st->print("%s *", ptr_msg[_ptr]);
2847 if( _offset == OffsetTop ) st->print("+top");
2848 else if( _offset == OffsetBot ) st->print("+bot");
2849 else if( _offset ) st->print("+%d", _offset);
2850 dump_inline_depth(st);
2851 dump_speculative(st);
2852 }
2853
2854 /**
2855 *dump the speculative part of the type
2856 */
dump_speculative(outputStream * st) const2857 void TypePtr::dump_speculative(outputStream *st) const {
2858 if (_speculative != NULL) {
2859 st->print(" (speculative=");
2860 _speculative->dump_on(st);
2861 st->print(")");
2862 }
2863 }
2864
2865 /**
2866 *dump the inline depth of the type
2867 */
dump_inline_depth(outputStream * st) const2868 void TypePtr::dump_inline_depth(outputStream *st) const {
2869 if (_inline_depth != InlineDepthBottom) {
2870 if (_inline_depth == InlineDepthTop) {
2871 st->print(" (inline_depth=InlineDepthTop)");
2872 } else {
2873 st->print(" (inline_depth=%d)", _inline_depth);
2874 }
2875 }
2876 }
2877 #endif
2878
2879 //------------------------------singleton--------------------------------------
2880 // TRUE if Type is a singleton type, FALSE otherwise. Singletons are simple
2881 // constants
singleton(void) const2882 bool TypePtr::singleton(void) const {
2883 // TopPTR, Null, AnyNull, Constant are all singletons
2884 return (_offset != OffsetBot) && !below_centerline(_ptr);
2885 }
2886
empty(void) const2887 bool TypePtr::empty(void) const {
2888 return (_offset == OffsetTop) || above_centerline(_ptr);
2889 }
2890
2891 //=============================================================================
2892 // Convenience common pre-built types.
2893 const TypeRawPtr *TypeRawPtr::BOTTOM;
2894 const TypeRawPtr *TypeRawPtr::NOTNULL;
2895
2896 //------------------------------make-------------------------------------------
make(enum PTR ptr)2897 const TypeRawPtr *TypeRawPtr::make( enum PTR ptr ) {
2898 assert( ptr != Constant, "what is the constant?" );
2899 assert( ptr != Null, "Use TypePtr for NULL" );
2900 return (TypeRawPtr*)(new TypeRawPtr(ptr,0))->hashcons();
2901 }
2902
make(address bits)2903 const TypeRawPtr *TypeRawPtr::make( address bits ) {
2904 assert( bits, "Use TypePtr for NULL" );
2905 return (TypeRawPtr*)(new TypeRawPtr(Constant,bits))->hashcons();
2906 }
2907
2908 //------------------------------cast_to_ptr_type-------------------------------
cast_to_ptr_type(PTR ptr) const2909 const Type *TypeRawPtr::cast_to_ptr_type(PTR ptr) const {
2910 assert( ptr != Constant, "what is the constant?" );
2911 assert( ptr != Null, "Use TypePtr for NULL" );
2912 assert( _bits==0, "Why cast a constant address?");
2913 if( ptr == _ptr ) return this;
2914 return make(ptr);
2915 }
2916
2917 //------------------------------get_con----------------------------------------
get_con() const2918 intptr_t TypeRawPtr::get_con() const {
2919 assert( _ptr == Null || _ptr == Constant, "" );
2920 return (intptr_t)_bits;
2921 }
2922
2923 //------------------------------meet-------------------------------------------
2924 // Compute the MEET of two types. It returns a new Type object.
xmeet(const Type * t) const2925 const Type *TypeRawPtr::xmeet( const Type *t ) const {
2926 // Perform a fast test for common case; meeting the same types together.
2927 if( this == t ) return this; // Meeting same type-rep?
2928
2929 // Current "this->_base" is RawPtr
2930 switch( t->base() ) { // switch on original type
2931 case Bottom: // Ye Olde Default
2932 return t;
2933 case Top:
2934 return this;
2935 case AnyPtr: // Meeting to AnyPtrs
2936 break;
2937 case RawPtr: { // might be top, bot, any/not or constant
2938 enum PTR tptr = t->is_ptr()->ptr();
2939 enum PTR ptr = meet_ptr( tptr );
2940 if( ptr == Constant ) { // Cannot be equal constants, so...
2941 if( tptr == Constant && _ptr != Constant) return t;
2942 if( _ptr == Constant && tptr != Constant) return this;
2943 ptr = NotNull; // Fall down in lattice
2944 }
2945 return make( ptr );
2946 }
2947
2948 case OopPtr:
2949 case InstPtr:
2950 case AryPtr:
2951 case MetadataPtr:
2952 case KlassPtr:
2953 return TypePtr::BOTTOM; // Oop meet raw is not well defined
2954 default: // All else is a mistake
2955 typerr(t);
2956 }
2957
2958 // Found an AnyPtr type vs self-RawPtr type
2959 const TypePtr *tp = t->is_ptr();
2960 switch (tp->ptr()) {
2961 case TypePtr::TopPTR: return this;
2962 case TypePtr::BotPTR: return t;
2963 case TypePtr::Null:
2964 if( _ptr == TypePtr::TopPTR ) return t;
2965 return TypeRawPtr::BOTTOM;
2966 case TypePtr::NotNull: return TypePtr::make(AnyPtr, meet_ptr(TypePtr::NotNull), tp->meet_offset(0), tp->speculative(), tp->inline_depth());
2967 case TypePtr::AnyNull:
2968 if( _ptr == TypePtr::Constant) return this;
2969 return make( meet_ptr(TypePtr::AnyNull) );
2970 default: ShouldNotReachHere();
2971 }
2972 return this;
2973 }
2974
2975 //------------------------------xdual------------------------------------------
2976 // Dual: compute field-by-field dual
xdual() const2977 const Type *TypeRawPtr::xdual() const {
2978 return new TypeRawPtr( dual_ptr(), _bits );
2979 }
2980
2981 //------------------------------add_offset-------------------------------------
add_offset(intptr_t offset) const2982 const TypePtr *TypeRawPtr::add_offset( intptr_t offset ) const {
2983 if( offset == OffsetTop ) return BOTTOM; // Undefined offset-> undefined pointer
2984 if( offset == OffsetBot ) return BOTTOM; // Unknown offset-> unknown pointer
2985 if( offset == 0 ) return this; // No change
2986 switch (_ptr) {
2987 case TypePtr::TopPTR:
2988 case TypePtr::BotPTR:
2989 case TypePtr::NotNull:
2990 return this;
2991 case TypePtr::Null:
2992 case TypePtr::Constant: {
2993 address bits = _bits+offset;
2994 if ( bits == 0 ) return TypePtr::NULL_PTR;
2995 return make( bits );
2996 }
2997 default: ShouldNotReachHere();
2998 }
2999 return NULL; // Lint noise
3000 }
3001
3002 //------------------------------eq---------------------------------------------
3003 // Structural equality check for Type representations
eq(const Type * t) const3004 bool TypeRawPtr::eq( const Type *t ) const {
3005 const TypeRawPtr *a = (const TypeRawPtr*)t;
3006 return _bits == a->_bits && TypePtr::eq(t);
3007 }
3008
3009 //------------------------------hash-------------------------------------------
3010 // Type-specific hashing function.
hash(void) const3011 int TypeRawPtr::hash(void) const {
3012 return (intptr_t)_bits + TypePtr::hash();
3013 }
3014
3015 //------------------------------dump2------------------------------------------
3016 #ifndef PRODUCT
dump2(Dict & d,uint depth,outputStream * st) const3017 void TypeRawPtr::dump2( Dict &d, uint depth, outputStream *st ) const {
3018 if( _ptr == Constant )
3019 st->print(INTPTR_FORMAT, p2i(_bits));
3020 else
3021 st->print("rawptr:%s", ptr_msg[_ptr]);
3022 }
3023 #endif
3024
3025 //=============================================================================
3026 // Convenience common pre-built type.
3027 const TypeOopPtr *TypeOopPtr::BOTTOM;
3028
3029 //------------------------------TypeOopPtr-------------------------------------
TypeOopPtr(TYPES t,PTR ptr,ciKlass * k,bool xk,ciObject * o,int offset,int instance_id,const TypePtr * speculative,int inline_depth)3030 TypeOopPtr::TypeOopPtr(TYPES t, PTR ptr, ciKlass* k, bool xk, ciObject* o, int offset,
3031 int instance_id, const TypePtr* speculative, int inline_depth)
3032 : TypePtr(t, ptr, offset, speculative, inline_depth),
3033 _const_oop(o), _klass(k),
3034 _klass_is_exact(xk),
3035 _is_ptr_to_narrowoop(false),
3036 _is_ptr_to_narrowklass(false),
3037 _is_ptr_to_boxed_value(false),
3038 _instance_id(instance_id) {
3039 if (Compile::current()->eliminate_boxing() && (t == InstPtr) &&
3040 (offset > 0) && xk && (k != 0) && k->is_instance_klass()) {
3041 _is_ptr_to_boxed_value = k->as_instance_klass()->is_boxed_value_offset(offset);
3042 }
3043 #ifdef _LP64
3044 if (_offset > 0 || _offset == Type::OffsetTop || _offset == Type::OffsetBot) {
3045 if (_offset == oopDesc::klass_offset_in_bytes()) {
3046 _is_ptr_to_narrowklass = UseCompressedClassPointers;
3047 } else if (klass() == NULL) {
3048 // Array with unknown body type
3049 assert(this->isa_aryptr(), "only arrays without klass");
3050 _is_ptr_to_narrowoop = UseCompressedOops;
3051 } else if (this->isa_aryptr()) {
3052 _is_ptr_to_narrowoop = (UseCompressedOops && klass()->is_obj_array_klass() &&
3053 _offset != arrayOopDesc::length_offset_in_bytes());
3054 } else if (klass()->is_instance_klass()) {
3055 ciInstanceKlass* ik = klass()->as_instance_klass();
3056 ciField* field = NULL;
3057 if (this->isa_klassptr()) {
3058 // Perm objects don't use compressed references
3059 } else if (_offset == OffsetBot || _offset == OffsetTop) {
3060 // unsafe access
3061 _is_ptr_to_narrowoop = UseCompressedOops;
3062 } else {
3063 assert(this->isa_instptr(), "must be an instance ptr.");
3064
3065 if (klass() == ciEnv::current()->Class_klass() &&
3066 (_offset == java_lang_Class::klass_offset() ||
3067 _offset == java_lang_Class::array_klass_offset())) {
3068 // Special hidden fields from the Class.
3069 assert(this->isa_instptr(), "must be an instance ptr.");
3070 _is_ptr_to_narrowoop = false;
3071 } else if (klass() == ciEnv::current()->Class_klass() &&
3072 _offset >= InstanceMirrorKlass::offset_of_static_fields()) {
3073 // Static fields
3074 ciField* field = NULL;
3075 if (const_oop() != NULL) {
3076 ciInstanceKlass* k = const_oop()->as_instance()->java_lang_Class_klass()->as_instance_klass();
3077 field = k->get_field_by_offset(_offset, true);
3078 }
3079 if (field != NULL) {
3080 BasicType basic_elem_type = field->layout_type();
3081 _is_ptr_to_narrowoop = UseCompressedOops && is_reference_type(basic_elem_type);
3082 } else {
3083 // unsafe access
3084 _is_ptr_to_narrowoop = UseCompressedOops;
3085 }
3086 } else {
3087 // Instance fields which contains a compressed oop references.
3088 field = ik->get_field_by_offset(_offset, false);
3089 if (field != NULL) {
3090 BasicType basic_elem_type = field->layout_type();
3091 _is_ptr_to_narrowoop = UseCompressedOops && is_reference_type(basic_elem_type);
3092 } else if (klass()->equals(ciEnv::current()->Object_klass())) {
3093 // Compile::find_alias_type() cast exactness on all types to verify
3094 // that it does not affect alias type.
3095 _is_ptr_to_narrowoop = UseCompressedOops;
3096 } else {
3097 // Type for the copy start in LibraryCallKit::inline_native_clone().
3098 _is_ptr_to_narrowoop = UseCompressedOops;
3099 }
3100 }
3101 }
3102 }
3103 }
3104 #endif
3105 }
3106
3107 //------------------------------make-------------------------------------------
make(PTR ptr,int offset,int instance_id,const TypePtr * speculative,int inline_depth)3108 const TypeOopPtr *TypeOopPtr::make(PTR ptr, int offset, int instance_id,
3109 const TypePtr* speculative, int inline_depth) {
3110 assert(ptr != Constant, "no constant generic pointers");
3111 ciKlass* k = Compile::current()->env()->Object_klass();
3112 bool xk = false;
3113 ciObject* o = NULL;
3114 return (TypeOopPtr*)(new TypeOopPtr(OopPtr, ptr, k, xk, o, offset, instance_id, speculative, inline_depth))->hashcons();
3115 }
3116
3117
3118 //------------------------------cast_to_ptr_type-------------------------------
cast_to_ptr_type(PTR ptr) const3119 const Type *TypeOopPtr::cast_to_ptr_type(PTR ptr) const {
3120 assert(_base == OopPtr, "subclass must override cast_to_ptr_type");
3121 if( ptr == _ptr ) return this;
3122 return make(ptr, _offset, _instance_id, _speculative, _inline_depth);
3123 }
3124
3125 //-----------------------------cast_to_instance_id----------------------------
cast_to_instance_id(int instance_id) const3126 const TypeOopPtr *TypeOopPtr::cast_to_instance_id(int instance_id) const {
3127 // There are no instances of a general oop.
3128 // Return self unchanged.
3129 return this;
3130 }
3131
3132 //-----------------------------cast_to_exactness-------------------------------
cast_to_exactness(bool klass_is_exact) const3133 const Type *TypeOopPtr::cast_to_exactness(bool klass_is_exact) const {
3134 // There is no such thing as an exact general oop.
3135 // Return self unchanged.
3136 return this;
3137 }
3138
3139
3140 //------------------------------as_klass_type----------------------------------
3141 // Return the klass type corresponding to this instance or array type.
3142 // It is the type that is loaded from an object of this type.
as_klass_type() const3143 const TypeKlassPtr* TypeOopPtr::as_klass_type() const {
3144 ciKlass* k = klass();
3145 bool xk = klass_is_exact();
3146 if (k == NULL)
3147 return TypeKlassPtr::OBJECT;
3148 else
3149 return TypeKlassPtr::make(xk? Constant: NotNull, k, 0);
3150 }
3151
3152 //------------------------------meet-------------------------------------------
3153 // Compute the MEET of two types. It returns a new Type object.
xmeet_helper(const Type * t) const3154 const Type *TypeOopPtr::xmeet_helper(const Type *t) const {
3155 // Perform a fast test for common case; meeting the same types together.
3156 if( this == t ) return this; // Meeting same type-rep?
3157
3158 // Current "this->_base" is OopPtr
3159 switch (t->base()) { // switch on original type
3160
3161 case Int: // Mixing ints & oops happens when javac
3162 case Long: // reuses local variables
3163 case FloatTop:
3164 case FloatCon:
3165 case FloatBot:
3166 case DoubleTop:
3167 case DoubleCon:
3168 case DoubleBot:
3169 case NarrowOop:
3170 case NarrowKlass:
3171 case Bottom: // Ye Olde Default
3172 return Type::BOTTOM;
3173 case Top:
3174 return this;
3175
3176 default: // All else is a mistake
3177 typerr(t);
3178
3179 case RawPtr:
3180 case MetadataPtr:
3181 case KlassPtr:
3182 return TypePtr::BOTTOM; // Oop meet raw is not well defined
3183
3184 case AnyPtr: {
3185 // Found an AnyPtr type vs self-OopPtr type
3186 const TypePtr *tp = t->is_ptr();
3187 int offset = meet_offset(tp->offset());
3188 PTR ptr = meet_ptr(tp->ptr());
3189 const TypePtr* speculative = xmeet_speculative(tp);
3190 int depth = meet_inline_depth(tp->inline_depth());
3191 switch (tp->ptr()) {
3192 case Null:
3193 if (ptr == Null) return TypePtr::make(AnyPtr, ptr, offset, speculative, depth);
3194 // else fall through:
3195 case TopPTR:
3196 case AnyNull: {
3197 int instance_id = meet_instance_id(InstanceTop);
3198 return make(ptr, offset, instance_id, speculative, depth);
3199 }
3200 case BotPTR:
3201 case NotNull:
3202 return TypePtr::make(AnyPtr, ptr, offset, speculative, depth);
3203 default: typerr(t);
3204 }
3205 }
3206
3207 case OopPtr: { // Meeting to other OopPtrs
3208 const TypeOopPtr *tp = t->is_oopptr();
3209 int instance_id = meet_instance_id(tp->instance_id());
3210 const TypePtr* speculative = xmeet_speculative(tp);
3211 int depth = meet_inline_depth(tp->inline_depth());
3212 return make(meet_ptr(tp->ptr()), meet_offset(tp->offset()), instance_id, speculative, depth);
3213 }
3214
3215 case InstPtr: // For these, flip the call around to cut down
3216 case AryPtr:
3217 return t->xmeet(this); // Call in reverse direction
3218
3219 } // End of switch
3220 return this; // Return the double constant
3221 }
3222
3223
3224 //------------------------------xdual------------------------------------------
3225 // Dual of a pure heap pointer. No relevant klass or oop information.
xdual() const3226 const Type *TypeOopPtr::xdual() const {
3227 assert(klass() == Compile::current()->env()->Object_klass(), "no klasses here");
3228 assert(const_oop() == NULL, "no constants here");
3229 return new TypeOopPtr(_base, dual_ptr(), klass(), klass_is_exact(), const_oop(), dual_offset(), dual_instance_id(), dual_speculative(), dual_inline_depth());
3230 }
3231
3232 //--------------------------make_from_klass_common-----------------------------
3233 // Computes the element-type given a klass.
make_from_klass_common(ciKlass * klass,bool klass_change,bool try_for_exact)3234 const TypeOopPtr* TypeOopPtr::make_from_klass_common(ciKlass *klass, bool klass_change, bool try_for_exact) {
3235 if (klass->is_instance_klass()) {
3236 Compile* C = Compile::current();
3237 Dependencies* deps = C->dependencies();
3238 assert((deps != NULL) == (C->method() != NULL && C->method()->code_size() > 0), "sanity");
3239 // Element is an instance
3240 bool klass_is_exact = false;
3241 if (klass->is_loaded()) {
3242 // Try to set klass_is_exact.
3243 ciInstanceKlass* ik = klass->as_instance_klass();
3244 klass_is_exact = ik->is_final();
3245 if (!klass_is_exact && klass_change
3246 && deps != NULL && UseUniqueSubclasses) {
3247 ciInstanceKlass* sub = ik->unique_concrete_subklass();
3248 if (sub != NULL) {
3249 deps->assert_abstract_with_unique_concrete_subtype(ik, sub);
3250 klass = ik = sub;
3251 klass_is_exact = sub->is_final();
3252 }
3253 }
3254 if (!klass_is_exact && try_for_exact && deps != NULL &&
3255 !ik->is_interface() && !ik->has_subklass()) {
3256 // Add a dependence; if concrete subclass added we need to recompile
3257 deps->assert_leaf_type(ik);
3258 klass_is_exact = true;
3259 }
3260 }
3261 return TypeInstPtr::make(TypePtr::BotPTR, klass, klass_is_exact, NULL, 0);
3262 } else if (klass->is_obj_array_klass()) {
3263 // Element is an object array. Recursively call ourself.
3264 const TypeOopPtr *etype = TypeOopPtr::make_from_klass_common(klass->as_obj_array_klass()->element_klass(), false, try_for_exact);
3265 bool xk = etype->klass_is_exact();
3266 const TypeAry* arr0 = TypeAry::make(etype, TypeInt::POS);
3267 // We used to pass NotNull in here, asserting that the sub-arrays
3268 // are all not-null. This is not true in generally, as code can
3269 // slam NULLs down in the subarrays.
3270 const TypeAryPtr* arr = TypeAryPtr::make(TypePtr::BotPTR, arr0, klass, xk, 0);
3271 return arr;
3272 } else if (klass->is_type_array_klass()) {
3273 // Element is an typeArray
3274 const Type* etype = get_const_basic_type(klass->as_type_array_klass()->element_type());
3275 const TypeAry* arr0 = TypeAry::make(etype, TypeInt::POS);
3276 // We used to pass NotNull in here, asserting that the array pointer
3277 // is not-null. That was not true in general.
3278 const TypeAryPtr* arr = TypeAryPtr::make(TypePtr::BotPTR, arr0, klass, true, 0);
3279 return arr;
3280 } else {
3281 ShouldNotReachHere();
3282 return NULL;
3283 }
3284 }
3285
3286 //------------------------------make_from_constant-----------------------------
3287 // Make a java pointer from an oop constant
make_from_constant(ciObject * o,bool require_constant)3288 const TypeOopPtr* TypeOopPtr::make_from_constant(ciObject* o, bool require_constant) {
3289 assert(!o->is_null_object(), "null object not yet handled here.");
3290
3291 const bool make_constant = require_constant || o->should_be_constant();
3292
3293 ciKlass* klass = o->klass();
3294 if (klass->is_instance_klass()) {
3295 // Element is an instance
3296 if (make_constant) {
3297 return TypeInstPtr::make(o);
3298 } else {
3299 return TypeInstPtr::make(TypePtr::NotNull, klass, true, NULL, 0);
3300 }
3301 } else if (klass->is_obj_array_klass()) {
3302 // Element is an object array. Recursively call ourself.
3303 const TypeOopPtr *etype =
3304 TypeOopPtr::make_from_klass_raw(klass->as_obj_array_klass()->element_klass());
3305 const TypeAry* arr0 = TypeAry::make(etype, TypeInt::make(o->as_array()->length()));
3306 // We used to pass NotNull in here, asserting that the sub-arrays
3307 // are all not-null. This is not true in generally, as code can
3308 // slam NULLs down in the subarrays.
3309 if (make_constant) {
3310 return TypeAryPtr::make(TypePtr::Constant, o, arr0, klass, true, 0);
3311 } else {
3312 return TypeAryPtr::make(TypePtr::NotNull, arr0, klass, true, 0);
3313 }
3314 } else if (klass->is_type_array_klass()) {
3315 // Element is an typeArray
3316 const Type* etype =
3317 (Type*)get_const_basic_type(klass->as_type_array_klass()->element_type());
3318 const TypeAry* arr0 = TypeAry::make(etype, TypeInt::make(o->as_array()->length()));
3319 // We used to pass NotNull in here, asserting that the array pointer
3320 // is not-null. That was not true in general.
3321 if (make_constant) {
3322 return TypeAryPtr::make(TypePtr::Constant, o, arr0, klass, true, 0);
3323 } else {
3324 return TypeAryPtr::make(TypePtr::NotNull, arr0, klass, true, 0);
3325 }
3326 }
3327
3328 fatal("unhandled object type");
3329 return NULL;
3330 }
3331
3332 //------------------------------get_con----------------------------------------
get_con() const3333 intptr_t TypeOopPtr::get_con() const {
3334 assert( _ptr == Null || _ptr == Constant, "" );
3335 assert( _offset >= 0, "" );
3336
3337 if (_offset != 0) {
3338 // After being ported to the compiler interface, the compiler no longer
3339 // directly manipulates the addresses of oops. Rather, it only has a pointer
3340 // to a handle at compile time. This handle is embedded in the generated
3341 // code and dereferenced at the time the nmethod is made. Until that time,
3342 // it is not reasonable to do arithmetic with the addresses of oops (we don't
3343 // have access to the addresses!). This does not seem to currently happen,
3344 // but this assertion here is to help prevent its occurence.
3345 tty->print_cr("Found oop constant with non-zero offset");
3346 ShouldNotReachHere();
3347 }
3348
3349 return (intptr_t)const_oop()->constant_encoding();
3350 }
3351
3352
3353 //-----------------------------filter------------------------------------------
3354 // Do not allow interface-vs.-noninterface joins to collapse to top.
filter_helper(const Type * kills,bool include_speculative) const3355 const Type *TypeOopPtr::filter_helper(const Type *kills, bool include_speculative) const {
3356
3357 const Type* ft = join_helper(kills, include_speculative);
3358 const TypeInstPtr* ftip = ft->isa_instptr();
3359 const TypeInstPtr* ktip = kills->isa_instptr();
3360
3361 if (ft->empty()) {
3362 // Check for evil case of 'this' being a class and 'kills' expecting an
3363 // interface. This can happen because the bytecodes do not contain
3364 // enough type info to distinguish a Java-level interface variable
3365 // from a Java-level object variable. If we meet 2 classes which
3366 // both implement interface I, but their meet is at 'j/l/O' which
3367 // doesn't implement I, we have no way to tell if the result should
3368 // be 'I' or 'j/l/O'. Thus we'll pick 'j/l/O'. If this then flows
3369 // into a Phi which "knows" it's an Interface type we'll have to
3370 // uplift the type.
3371 if (!empty()) {
3372 if (ktip != NULL && ktip->is_loaded() && ktip->klass()->is_interface()) {
3373 return kills; // Uplift to interface
3374 }
3375 // Also check for evil cases of 'this' being a class array
3376 // and 'kills' expecting an array of interfaces.
3377 Type::get_arrays_base_elements(ft, kills, NULL, &ktip);
3378 if (ktip != NULL && ktip->is_loaded() && ktip->klass()->is_interface()) {
3379 return kills; // Uplift to array of interface
3380 }
3381 }
3382
3383 return Type::TOP; // Canonical empty value
3384 }
3385
3386 // If we have an interface-typed Phi or cast and we narrow to a class type,
3387 // the join should report back the class. However, if we have a J/L/Object
3388 // class-typed Phi and an interface flows in, it's possible that the meet &
3389 // join report an interface back out. This isn't possible but happens
3390 // because the type system doesn't interact well with interfaces.
3391 if (ftip != NULL && ktip != NULL &&
3392 ftip->is_loaded() && ftip->klass()->is_interface() &&
3393 ktip->is_loaded() && !ktip->klass()->is_interface()) {
3394 assert(!ftip->klass_is_exact(), "interface could not be exact");
3395 return ktip->cast_to_ptr_type(ftip->ptr());
3396 }
3397
3398 return ft;
3399 }
3400
3401 //------------------------------eq---------------------------------------------
3402 // Structural equality check for Type representations
eq(const Type * t) const3403 bool TypeOopPtr::eq( const Type *t ) const {
3404 const TypeOopPtr *a = (const TypeOopPtr*)t;
3405 if (_klass_is_exact != a->_klass_is_exact ||
3406 _instance_id != a->_instance_id) return false;
3407 ciObject* one = const_oop();
3408 ciObject* two = a->const_oop();
3409 if (one == NULL || two == NULL) {
3410 return (one == two) && TypePtr::eq(t);
3411 } else {
3412 return one->equals(two) && TypePtr::eq(t);
3413 }
3414 }
3415
3416 //------------------------------hash-------------------------------------------
3417 // Type-specific hashing function.
hash(void) const3418 int TypeOopPtr::hash(void) const {
3419 return
3420 java_add(java_add((jint)(const_oop() ? const_oop()->hash() : 0), (jint)_klass_is_exact),
3421 java_add((jint)_instance_id, (jint)TypePtr::hash()));
3422 }
3423
3424 //------------------------------dump2------------------------------------------
3425 #ifndef PRODUCT
dump2(Dict & d,uint depth,outputStream * st) const3426 void TypeOopPtr::dump2( Dict &d, uint depth, outputStream *st ) const {
3427 st->print("oopptr:%s", ptr_msg[_ptr]);
3428 if( _klass_is_exact ) st->print(":exact");
3429 if( const_oop() ) st->print(INTPTR_FORMAT, p2i(const_oop()));
3430 switch( _offset ) {
3431 case OffsetTop: st->print("+top"); break;
3432 case OffsetBot: st->print("+any"); break;
3433 case 0: break;
3434 default: st->print("+%d",_offset); break;
3435 }
3436 if (_instance_id == InstanceTop)
3437 st->print(",iid=top");
3438 else if (_instance_id != InstanceBot)
3439 st->print(",iid=%d",_instance_id);
3440
3441 dump_inline_depth(st);
3442 dump_speculative(st);
3443 }
3444 #endif
3445
3446 //------------------------------singleton--------------------------------------
3447 // TRUE if Type is a singleton type, FALSE otherwise. Singletons are simple
3448 // constants
singleton(void) const3449 bool TypeOopPtr::singleton(void) const {
3450 // detune optimizer to not generate constant oop + constant offset as a constant!
3451 // TopPTR, Null, AnyNull, Constant are all singletons
3452 return (_offset == 0) && !below_centerline(_ptr);
3453 }
3454
3455 //------------------------------add_offset-------------------------------------
add_offset(intptr_t offset) const3456 const TypePtr *TypeOopPtr::add_offset(intptr_t offset) const {
3457 return make(_ptr, xadd_offset(offset), _instance_id, add_offset_speculative(offset), _inline_depth);
3458 }
3459
3460 /**
3461 * Return same type without a speculative part
3462 */
remove_speculative() const3463 const Type* TypeOopPtr::remove_speculative() const {
3464 if (_speculative == NULL) {
3465 return this;
3466 }
3467 assert(_inline_depth == InlineDepthTop || _inline_depth == InlineDepthBottom, "non speculative type shouldn't have inline depth");
3468 return make(_ptr, _offset, _instance_id, NULL, _inline_depth);
3469 }
3470
3471 /**
3472 * Return same type but drop speculative part if we know we won't use
3473 * it
3474 */
cleanup_speculative() const3475 const Type* TypeOopPtr::cleanup_speculative() const {
3476 // If the klass is exact and the ptr is not null then there's
3477 // nothing that the speculative type can help us with
3478 if (klass_is_exact() && !maybe_null()) {
3479 return remove_speculative();
3480 }
3481 return TypePtr::cleanup_speculative();
3482 }
3483
3484 /**
3485 * Return same type but with a different inline depth (used for speculation)
3486 *
3487 * @param depth depth to meet with
3488 */
with_inline_depth(int depth) const3489 const TypePtr* TypeOopPtr::with_inline_depth(int depth) const {
3490 if (!UseInlineDepthForSpeculativeTypes) {
3491 return this;
3492 }
3493 return make(_ptr, _offset, _instance_id, _speculative, depth);
3494 }
3495
3496 //------------------------------with_instance_id--------------------------------
with_instance_id(int instance_id) const3497 const TypePtr* TypeOopPtr::with_instance_id(int instance_id) const {
3498 assert(_instance_id != -1, "should be known");
3499 return make(_ptr, _offset, instance_id, _speculative, _inline_depth);
3500 }
3501
3502 //------------------------------meet_instance_id--------------------------------
meet_instance_id(int instance_id) const3503 int TypeOopPtr::meet_instance_id( int instance_id ) const {
3504 // Either is 'TOP' instance? Return the other instance!
3505 if( _instance_id == InstanceTop ) return instance_id;
3506 if( instance_id == InstanceTop ) return _instance_id;
3507 // If either is different, return 'BOTTOM' instance
3508 if( _instance_id != instance_id ) return InstanceBot;
3509 return _instance_id;
3510 }
3511
3512 //------------------------------dual_instance_id--------------------------------
dual_instance_id() const3513 int TypeOopPtr::dual_instance_id( ) const {
3514 if( _instance_id == InstanceTop ) return InstanceBot; // Map TOP into BOTTOM
3515 if( _instance_id == InstanceBot ) return InstanceTop; // Map BOTTOM into TOP
3516 return _instance_id; // Map everything else into self
3517 }
3518
3519 /**
3520 * Check whether new profiling would improve speculative type
3521 *
3522 * @param exact_kls class from profiling
3523 * @param inline_depth inlining depth of profile point
3524 *
3525 * @return true if type profile is valuable
3526 */
would_improve_type(ciKlass * exact_kls,int inline_depth) const3527 bool TypeOopPtr::would_improve_type(ciKlass* exact_kls, int inline_depth) const {
3528 // no way to improve an already exact type
3529 if (klass_is_exact()) {
3530 return false;
3531 }
3532 return TypePtr::would_improve_type(exact_kls, inline_depth);
3533 }
3534
3535 //=============================================================================
3536 // Convenience common pre-built types.
3537 const TypeInstPtr *TypeInstPtr::NOTNULL;
3538 const TypeInstPtr *TypeInstPtr::BOTTOM;
3539 const TypeInstPtr *TypeInstPtr::MIRROR;
3540 const TypeInstPtr *TypeInstPtr::MARK;
3541 const TypeInstPtr *TypeInstPtr::KLASS;
3542
3543 //------------------------------TypeInstPtr-------------------------------------
TypeInstPtr(PTR ptr,ciKlass * k,bool xk,ciObject * o,int off,int instance_id,const TypePtr * speculative,int inline_depth)3544 TypeInstPtr::TypeInstPtr(PTR ptr, ciKlass* k, bool xk, ciObject* o, int off,
3545 int instance_id, const TypePtr* speculative, int inline_depth)
3546 : TypeOopPtr(InstPtr, ptr, k, xk, o, off, instance_id, speculative, inline_depth),
3547 _name(k->name()) {
3548 assert(k != NULL &&
3549 (k->is_loaded() || o == NULL),
3550 "cannot have constants with non-loaded klass");
3551 };
3552
3553 //------------------------------make-------------------------------------------
make(PTR ptr,ciKlass * k,bool xk,ciObject * o,int offset,int instance_id,const TypePtr * speculative,int inline_depth)3554 const TypeInstPtr *TypeInstPtr::make(PTR ptr,
3555 ciKlass* k,
3556 bool xk,
3557 ciObject* o,
3558 int offset,
3559 int instance_id,
3560 const TypePtr* speculative,
3561 int inline_depth) {
3562 assert( !k->is_loaded() || k->is_instance_klass(), "Must be for instance");
3563 // Either const_oop() is NULL or else ptr is Constant
3564 assert( (!o && ptr != Constant) || (o && ptr == Constant),
3565 "constant pointers must have a value supplied" );
3566 // Ptr is never Null
3567 assert( ptr != Null, "NULL pointers are not typed" );
3568
3569 assert(instance_id <= 0 || xk, "instances are always exactly typed");
3570 if (ptr == Constant) {
3571 // Note: This case includes meta-object constants, such as methods.
3572 xk = true;
3573 } else if (k->is_loaded()) {
3574 ciInstanceKlass* ik = k->as_instance_klass();
3575 if (!xk && ik->is_final()) xk = true; // no inexact final klass
3576 if (xk && ik->is_interface()) xk = false; // no exact interface
3577 }
3578
3579 // Now hash this baby
3580 TypeInstPtr *result =
3581 (TypeInstPtr*)(new TypeInstPtr(ptr, k, xk, o ,offset, instance_id, speculative, inline_depth))->hashcons();
3582
3583 return result;
3584 }
3585
3586 /**
3587 * Create constant type for a constant boxed value
3588 */
get_const_boxed_value() const3589 const Type* TypeInstPtr::get_const_boxed_value() const {
3590 assert(is_ptr_to_boxed_value(), "should be called only for boxed value");
3591 assert((const_oop() != NULL), "should be called only for constant object");
3592 ciConstant constant = const_oop()->as_instance()->field_value_by_offset(offset());
3593 BasicType bt = constant.basic_type();
3594 switch (bt) {
3595 case T_BOOLEAN: return TypeInt::make(constant.as_boolean());
3596 case T_INT: return TypeInt::make(constant.as_int());
3597 case T_CHAR: return TypeInt::make(constant.as_char());
3598 case T_BYTE: return TypeInt::make(constant.as_byte());
3599 case T_SHORT: return TypeInt::make(constant.as_short());
3600 case T_FLOAT: return TypeF::make(constant.as_float());
3601 case T_DOUBLE: return TypeD::make(constant.as_double());
3602 case T_LONG: return TypeLong::make(constant.as_long());
3603 default: break;
3604 }
3605 fatal("Invalid boxed value type '%s'", type2name(bt));
3606 return NULL;
3607 }
3608
3609 //------------------------------cast_to_ptr_type-------------------------------
cast_to_ptr_type(PTR ptr) const3610 const Type *TypeInstPtr::cast_to_ptr_type(PTR ptr) const {
3611 if( ptr == _ptr ) return this;
3612 // Reconstruct _sig info here since not a problem with later lazy
3613 // construction, _sig will show up on demand.
3614 return make(ptr, klass(), klass_is_exact(), const_oop(), _offset, _instance_id, _speculative, _inline_depth);
3615 }
3616
3617
3618 //-----------------------------cast_to_exactness-------------------------------
cast_to_exactness(bool klass_is_exact) const3619 const Type *TypeInstPtr::cast_to_exactness(bool klass_is_exact) const {
3620 if( klass_is_exact == _klass_is_exact ) return this;
3621 if (!_klass->is_loaded()) return this;
3622 ciInstanceKlass* ik = _klass->as_instance_klass();
3623 if( (ik->is_final() || _const_oop) ) return this; // cannot clear xk
3624 if( ik->is_interface() ) return this; // cannot set xk
3625 return make(ptr(), klass(), klass_is_exact, const_oop(), _offset, _instance_id, _speculative, _inline_depth);
3626 }
3627
3628 //-----------------------------cast_to_instance_id----------------------------
cast_to_instance_id(int instance_id) const3629 const TypeOopPtr *TypeInstPtr::cast_to_instance_id(int instance_id) const {
3630 if( instance_id == _instance_id ) return this;
3631 return make(_ptr, klass(), _klass_is_exact, const_oop(), _offset, instance_id, _speculative, _inline_depth);
3632 }
3633
3634 //------------------------------xmeet_unloaded---------------------------------
3635 // Compute the MEET of two InstPtrs when at least one is unloaded.
3636 // Assume classes are different since called after check for same name/class-loader
xmeet_unloaded(const TypeInstPtr * tinst) const3637 const TypeInstPtr *TypeInstPtr::xmeet_unloaded(const TypeInstPtr *tinst) const {
3638 int off = meet_offset(tinst->offset());
3639 PTR ptr = meet_ptr(tinst->ptr());
3640 int instance_id = meet_instance_id(tinst->instance_id());
3641 const TypePtr* speculative = xmeet_speculative(tinst);
3642 int depth = meet_inline_depth(tinst->inline_depth());
3643
3644 const TypeInstPtr *loaded = is_loaded() ? this : tinst;
3645 const TypeInstPtr *unloaded = is_loaded() ? tinst : this;
3646 if( loaded->klass()->equals(ciEnv::current()->Object_klass()) ) {
3647 //
3648 // Meet unloaded class with java/lang/Object
3649 //
3650 // Meet
3651 // | Unloaded Class
3652 // Object | TOP | AnyNull | Constant | NotNull | BOTTOM |
3653 // ===================================================================
3654 // TOP | ..........................Unloaded......................|
3655 // AnyNull | U-AN |................Unloaded......................|
3656 // Constant | ... O-NN .................................. | O-BOT |
3657 // NotNull | ... O-NN .................................. | O-BOT |
3658 // BOTTOM | ........................Object-BOTTOM ..................|
3659 //
3660 assert(loaded->ptr() != TypePtr::Null, "insanity check");
3661 //
3662 if( loaded->ptr() == TypePtr::TopPTR ) { return unloaded; }
3663 else if (loaded->ptr() == TypePtr::AnyNull) { return TypeInstPtr::make(ptr, unloaded->klass(), false, NULL, off, instance_id, speculative, depth); }
3664 else if (loaded->ptr() == TypePtr::BotPTR ) { return TypeInstPtr::BOTTOM; }
3665 else if (loaded->ptr() == TypePtr::Constant || loaded->ptr() == TypePtr::NotNull) {
3666 if (unloaded->ptr() == TypePtr::BotPTR ) { return TypeInstPtr::BOTTOM; }
3667 else { return TypeInstPtr::NOTNULL; }
3668 }
3669 else if( unloaded->ptr() == TypePtr::TopPTR ) { return unloaded; }
3670
3671 return unloaded->cast_to_ptr_type(TypePtr::AnyNull)->is_instptr();
3672 }
3673
3674 // Both are unloaded, not the same class, not Object
3675 // Or meet unloaded with a different loaded class, not java/lang/Object
3676 if( ptr != TypePtr::BotPTR ) {
3677 return TypeInstPtr::NOTNULL;
3678 }
3679 return TypeInstPtr::BOTTOM;
3680 }
3681
3682
3683 //------------------------------meet-------------------------------------------
3684 // Compute the MEET of two types. It returns a new Type object.
xmeet_helper(const Type * t) const3685 const Type *TypeInstPtr::xmeet_helper(const Type *t) const {
3686 // Perform a fast test for common case; meeting the same types together.
3687 if( this == t ) return this; // Meeting same type-rep?
3688
3689 // Current "this->_base" is Pointer
3690 switch (t->base()) { // switch on original type
3691
3692 case Int: // Mixing ints & oops happens when javac
3693 case Long: // reuses local variables
3694 case FloatTop:
3695 case FloatCon:
3696 case FloatBot:
3697 case DoubleTop:
3698 case DoubleCon:
3699 case DoubleBot:
3700 case NarrowOop:
3701 case NarrowKlass:
3702 case Bottom: // Ye Olde Default
3703 return Type::BOTTOM;
3704 case Top:
3705 return this;
3706
3707 default: // All else is a mistake
3708 typerr(t);
3709
3710 case MetadataPtr:
3711 case KlassPtr:
3712 case RawPtr: return TypePtr::BOTTOM;
3713
3714 case AryPtr: { // All arrays inherit from Object class
3715 const TypeAryPtr *tp = t->is_aryptr();
3716 int offset = meet_offset(tp->offset());
3717 PTR ptr = meet_ptr(tp->ptr());
3718 int instance_id = meet_instance_id(tp->instance_id());
3719 const TypePtr* speculative = xmeet_speculative(tp);
3720 int depth = meet_inline_depth(tp->inline_depth());
3721 switch (ptr) {
3722 case TopPTR:
3723 case AnyNull: // Fall 'down' to dual of object klass
3724 // For instances when a subclass meets a superclass we fall
3725 // below the centerline when the superclass is exact. We need to
3726 // do the same here.
3727 if (klass()->equals(ciEnv::current()->Object_klass()) && !klass_is_exact()) {
3728 return TypeAryPtr::make(ptr, tp->ary(), tp->klass(), tp->klass_is_exact(), offset, instance_id, speculative, depth);
3729 } else {
3730 // cannot subclass, so the meet has to fall badly below the centerline
3731 ptr = NotNull;
3732 instance_id = InstanceBot;
3733 return TypeInstPtr::make( ptr, ciEnv::current()->Object_klass(), false, NULL, offset, instance_id, speculative, depth);
3734 }
3735 case Constant:
3736 case NotNull:
3737 case BotPTR: // Fall down to object klass
3738 // LCA is object_klass, but if we subclass from the top we can do better
3739 if( above_centerline(_ptr) ) { // if( _ptr == TopPTR || _ptr == AnyNull )
3740 // If 'this' (InstPtr) is above the centerline and it is Object class
3741 // then we can subclass in the Java class hierarchy.
3742 // For instances when a subclass meets a superclass we fall
3743 // below the centerline when the superclass is exact. We need
3744 // to do the same here.
3745 if (klass()->equals(ciEnv::current()->Object_klass()) && !klass_is_exact()) {
3746 // that is, tp's array type is a subtype of my klass
3747 return TypeAryPtr::make(ptr, (ptr == Constant ? tp->const_oop() : NULL),
3748 tp->ary(), tp->klass(), tp->klass_is_exact(), offset, instance_id, speculative, depth);
3749 }
3750 }
3751 // The other case cannot happen, since I cannot be a subtype of an array.
3752 // The meet falls down to Object class below centerline.
3753 if( ptr == Constant )
3754 ptr = NotNull;
3755 instance_id = InstanceBot;
3756 return make(ptr, ciEnv::current()->Object_klass(), false, NULL, offset, instance_id, speculative, depth);
3757 default: typerr(t);
3758 }
3759 }
3760
3761 case OopPtr: { // Meeting to OopPtrs
3762 // Found a OopPtr type vs self-InstPtr type
3763 const TypeOopPtr *tp = t->is_oopptr();
3764 int offset = meet_offset(tp->offset());
3765 PTR ptr = meet_ptr(tp->ptr());
3766 switch (tp->ptr()) {
3767 case TopPTR:
3768 case AnyNull: {
3769 int instance_id = meet_instance_id(InstanceTop);
3770 const TypePtr* speculative = xmeet_speculative(tp);
3771 int depth = meet_inline_depth(tp->inline_depth());
3772 return make(ptr, klass(), klass_is_exact(),
3773 (ptr == Constant ? const_oop() : NULL), offset, instance_id, speculative, depth);
3774 }
3775 case NotNull:
3776 case BotPTR: {
3777 int instance_id = meet_instance_id(tp->instance_id());
3778 const TypePtr* speculative = xmeet_speculative(tp);
3779 int depth = meet_inline_depth(tp->inline_depth());
3780 return TypeOopPtr::make(ptr, offset, instance_id, speculative, depth);
3781 }
3782 default: typerr(t);
3783 }
3784 }
3785
3786 case AnyPtr: { // Meeting to AnyPtrs
3787 // Found an AnyPtr type vs self-InstPtr type
3788 const TypePtr *tp = t->is_ptr();
3789 int offset = meet_offset(tp->offset());
3790 PTR ptr = meet_ptr(tp->ptr());
3791 int instance_id = meet_instance_id(InstanceTop);
3792 const TypePtr* speculative = xmeet_speculative(tp);
3793 int depth = meet_inline_depth(tp->inline_depth());
3794 switch (tp->ptr()) {
3795 case Null:
3796 if( ptr == Null ) return TypePtr::make(AnyPtr, ptr, offset, speculative, depth);
3797 // else fall through to AnyNull
3798 case TopPTR:
3799 case AnyNull: {
3800 return make(ptr, klass(), klass_is_exact(),
3801 (ptr == Constant ? const_oop() : NULL), offset, instance_id, speculative, depth);
3802 }
3803 case NotNull:
3804 case BotPTR:
3805 return TypePtr::make(AnyPtr, ptr, offset, speculative,depth);
3806 default: typerr(t);
3807 }
3808 }
3809
3810 /*
3811 A-top }
3812 / | \ } Tops
3813 B-top A-any C-top }
3814 | / | \ | } Any-nulls
3815 B-any | C-any }
3816 | | |
3817 B-con A-con C-con } constants; not comparable across classes
3818 | | |
3819 B-not | C-not }
3820 | \ | / | } not-nulls
3821 B-bot A-not C-bot }
3822 \ | / } Bottoms
3823 A-bot }
3824 */
3825
3826 case InstPtr: { // Meeting 2 Oops?
3827 // Found an InstPtr sub-type vs self-InstPtr type
3828 const TypeInstPtr *tinst = t->is_instptr();
3829 int off = meet_offset( tinst->offset() );
3830 PTR ptr = meet_ptr( tinst->ptr() );
3831 int instance_id = meet_instance_id(tinst->instance_id());
3832 const TypePtr* speculative = xmeet_speculative(tinst);
3833 int depth = meet_inline_depth(tinst->inline_depth());
3834
3835 // Check for easy case; klasses are equal (and perhaps not loaded!)
3836 // If we have constants, then we created oops so classes are loaded
3837 // and we can handle the constants further down. This case handles
3838 // both-not-loaded or both-loaded classes
3839 if (ptr != Constant && klass()->equals(tinst->klass()) && klass_is_exact() == tinst->klass_is_exact()) {
3840 return make(ptr, klass(), klass_is_exact(), NULL, off, instance_id, speculative, depth);
3841 }
3842
3843 // Classes require inspection in the Java klass hierarchy. Must be loaded.
3844 ciKlass* tinst_klass = tinst->klass();
3845 ciKlass* this_klass = this->klass();
3846 bool tinst_xk = tinst->klass_is_exact();
3847 bool this_xk = this->klass_is_exact();
3848 if (!tinst_klass->is_loaded() || !this_klass->is_loaded() ) {
3849 // One of these classes has not been loaded
3850 const TypeInstPtr *unloaded_meet = xmeet_unloaded(tinst);
3851 #ifndef PRODUCT
3852 if( PrintOpto && Verbose ) {
3853 tty->print("meet of unloaded classes resulted in: "); unloaded_meet->dump(); tty->cr();
3854 tty->print(" this == "); this->dump(); tty->cr();
3855 tty->print(" tinst == "); tinst->dump(); tty->cr();
3856 }
3857 #endif
3858 return unloaded_meet;
3859 }
3860
3861 // Handle mixing oops and interfaces first.
3862 if( this_klass->is_interface() && !(tinst_klass->is_interface() ||
3863 tinst_klass == ciEnv::current()->Object_klass())) {
3864 ciKlass *tmp = tinst_klass; // Swap interface around
3865 tinst_klass = this_klass;
3866 this_klass = tmp;
3867 bool tmp2 = tinst_xk;
3868 tinst_xk = this_xk;
3869 this_xk = tmp2;
3870 }
3871 if (tinst_klass->is_interface() &&
3872 !(this_klass->is_interface() ||
3873 // Treat java/lang/Object as an honorary interface,
3874 // because we need a bottom for the interface hierarchy.
3875 this_klass == ciEnv::current()->Object_klass())) {
3876 // Oop meets interface!
3877
3878 // See if the oop subtypes (implements) interface.
3879 ciKlass *k;
3880 bool xk;
3881 if( this_klass->is_subtype_of( tinst_klass ) ) {
3882 // Oop indeed subtypes. Now keep oop or interface depending
3883 // on whether we are both above the centerline or either is
3884 // below the centerline. If we are on the centerline
3885 // (e.g., Constant vs. AnyNull interface), use the constant.
3886 k = below_centerline(ptr) ? tinst_klass : this_klass;
3887 // If we are keeping this_klass, keep its exactness too.
3888 xk = below_centerline(ptr) ? tinst_xk : this_xk;
3889 } else { // Does not implement, fall to Object
3890 // Oop does not implement interface, so mixing falls to Object
3891 // just like the verifier does (if both are above the
3892 // centerline fall to interface)
3893 k = above_centerline(ptr) ? tinst_klass : ciEnv::current()->Object_klass();
3894 xk = above_centerline(ptr) ? tinst_xk : false;
3895 // Watch out for Constant vs. AnyNull interface.
3896 if (ptr == Constant) ptr = NotNull; // forget it was a constant
3897 instance_id = InstanceBot;
3898 }
3899 ciObject* o = NULL; // the Constant value, if any
3900 if (ptr == Constant) {
3901 // Find out which constant.
3902 o = (this_klass == klass()) ? const_oop() : tinst->const_oop();
3903 }
3904 return make(ptr, k, xk, o, off, instance_id, speculative, depth);
3905 }
3906
3907 // Either oop vs oop or interface vs interface or interface vs Object
3908
3909 // !!! Here's how the symmetry requirement breaks down into invariants:
3910 // If we split one up & one down AND they subtype, take the down man.
3911 // If we split one up & one down AND they do NOT subtype, "fall hard".
3912 // If both are up and they subtype, take the subtype class.
3913 // If both are up and they do NOT subtype, "fall hard".
3914 // If both are down and they subtype, take the supertype class.
3915 // If both are down and they do NOT subtype, "fall hard".
3916 // Constants treated as down.
3917
3918 // Now, reorder the above list; observe that both-down+subtype is also
3919 // "fall hard"; "fall hard" becomes the default case:
3920 // If we split one up & one down AND they subtype, take the down man.
3921 // If both are up and they subtype, take the subtype class.
3922
3923 // If both are down and they subtype, "fall hard".
3924 // If both are down and they do NOT subtype, "fall hard".
3925 // If both are up and they do NOT subtype, "fall hard".
3926 // If we split one up & one down AND they do NOT subtype, "fall hard".
3927
3928 // If a proper subtype is exact, and we return it, we return it exactly.
3929 // If a proper supertype is exact, there can be no subtyping relationship!
3930 // If both types are equal to the subtype, exactness is and-ed below the
3931 // centerline and or-ed above it. (N.B. Constants are always exact.)
3932
3933 // Check for subtyping:
3934 ciKlass *subtype = NULL;
3935 bool subtype_exact = false;
3936 if( tinst_klass->equals(this_klass) ) {
3937 subtype = this_klass;
3938 subtype_exact = below_centerline(ptr) ? (this_xk && tinst_xk) : (this_xk || tinst_xk);
3939 } else if( !tinst_xk && this_klass->is_subtype_of( tinst_klass ) ) {
3940 subtype = this_klass; // Pick subtyping class
3941 subtype_exact = this_xk;
3942 } else if( !this_xk && tinst_klass->is_subtype_of( this_klass ) ) {
3943 subtype = tinst_klass; // Pick subtyping class
3944 subtype_exact = tinst_xk;
3945 }
3946
3947 if( subtype ) {
3948 if( above_centerline(ptr) ) { // both are up?
3949 this_klass = tinst_klass = subtype;
3950 this_xk = tinst_xk = subtype_exact;
3951 } else if( above_centerline(this ->_ptr) && !above_centerline(tinst->_ptr) ) {
3952 this_klass = tinst_klass; // tinst is down; keep down man
3953 this_xk = tinst_xk;
3954 } else if( above_centerline(tinst->_ptr) && !above_centerline(this ->_ptr) ) {
3955 tinst_klass = this_klass; // this is down; keep down man
3956 tinst_xk = this_xk;
3957 } else {
3958 this_xk = subtype_exact; // either they are equal, or we'll do an LCA
3959 }
3960 }
3961
3962 // Check for classes now being equal
3963 if (tinst_klass->equals(this_klass)) {
3964 // If the klasses are equal, the constants may still differ. Fall to
3965 // NotNull if they do (neither constant is NULL; that is a special case
3966 // handled elsewhere).
3967 ciObject* o = NULL; // Assume not constant when done
3968 ciObject* this_oop = const_oop();
3969 ciObject* tinst_oop = tinst->const_oop();
3970 if( ptr == Constant ) {
3971 if (this_oop != NULL && tinst_oop != NULL &&
3972 this_oop->equals(tinst_oop) )
3973 o = this_oop;
3974 else if (above_centerline(this ->_ptr))
3975 o = tinst_oop;
3976 else if (above_centerline(tinst ->_ptr))
3977 o = this_oop;
3978 else
3979 ptr = NotNull;
3980 }
3981 return make(ptr, this_klass, this_xk, o, off, instance_id, speculative, depth);
3982 } // Else classes are not equal
3983
3984 // Since klasses are different, we require a LCA in the Java
3985 // class hierarchy - which means we have to fall to at least NotNull.
3986 if( ptr == TopPTR || ptr == AnyNull || ptr == Constant )
3987 ptr = NotNull;
3988
3989 instance_id = InstanceBot;
3990
3991 // Now we find the LCA of Java classes
3992 ciKlass* k = this_klass->least_common_ancestor(tinst_klass);
3993 return make(ptr, k, false, NULL, off, instance_id, speculative, depth);
3994 } // End of case InstPtr
3995
3996 } // End of switch
3997 return this; // Return the double constant
3998 }
3999
4000
4001 //------------------------java_mirror_type--------------------------------------
java_mirror_type() const4002 ciType* TypeInstPtr::java_mirror_type() const {
4003 // must be a singleton type
4004 if( const_oop() == NULL ) return NULL;
4005
4006 // must be of type java.lang.Class
4007 if( klass() != ciEnv::current()->Class_klass() ) return NULL;
4008
4009 return const_oop()->as_instance()->java_mirror_type();
4010 }
4011
4012
4013 //------------------------------xdual------------------------------------------
4014 // Dual: do NOT dual on klasses. This means I do NOT understand the Java
4015 // inheritance mechanism.
xdual() const4016 const Type *TypeInstPtr::xdual() const {
4017 return new TypeInstPtr(dual_ptr(), klass(), klass_is_exact(), const_oop(), dual_offset(), dual_instance_id(), dual_speculative(), dual_inline_depth());
4018 }
4019
4020 //------------------------------eq---------------------------------------------
4021 // Structural equality check for Type representations
eq(const Type * t) const4022 bool TypeInstPtr::eq( const Type *t ) const {
4023 const TypeInstPtr *p = t->is_instptr();
4024 return
4025 klass()->equals(p->klass()) &&
4026 TypeOopPtr::eq(p); // Check sub-type stuff
4027 }
4028
4029 //------------------------------hash-------------------------------------------
4030 // Type-specific hashing function.
hash(void) const4031 int TypeInstPtr::hash(void) const {
4032 int hash = java_add((jint)klass()->hash(), (jint)TypeOopPtr::hash());
4033 return hash;
4034 }
4035
4036 //------------------------------dump2------------------------------------------
4037 // Dump oop Type
4038 #ifndef PRODUCT
dump2(Dict & d,uint depth,outputStream * st) const4039 void TypeInstPtr::dump2( Dict &d, uint depth, outputStream *st ) const {
4040 // Print the name of the klass.
4041 klass()->print_name_on(st);
4042
4043 switch( _ptr ) {
4044 case Constant:
4045 // TO DO: Make CI print the hex address of the underlying oop.
4046 if (WizardMode || Verbose) {
4047 const_oop()->print_oop(st);
4048 }
4049 case BotPTR:
4050 if (!WizardMode && !Verbose) {
4051 if( _klass_is_exact ) st->print(":exact");
4052 break;
4053 }
4054 case TopPTR:
4055 case AnyNull:
4056 case NotNull:
4057 st->print(":%s", ptr_msg[_ptr]);
4058 if( _klass_is_exact ) st->print(":exact");
4059 break;
4060 default:
4061 break;
4062 }
4063
4064 if( _offset ) { // Dump offset, if any
4065 if( _offset == OffsetBot ) st->print("+any");
4066 else if( _offset == OffsetTop ) st->print("+unknown");
4067 else st->print("+%d", _offset);
4068 }
4069
4070 st->print(" *");
4071 if (_instance_id == InstanceTop)
4072 st->print(",iid=top");
4073 else if (_instance_id != InstanceBot)
4074 st->print(",iid=%d",_instance_id);
4075
4076 dump_inline_depth(st);
4077 dump_speculative(st);
4078 }
4079 #endif
4080
4081 //------------------------------add_offset-------------------------------------
add_offset(intptr_t offset) const4082 const TypePtr *TypeInstPtr::add_offset(intptr_t offset) const {
4083 return make(_ptr, klass(), klass_is_exact(), const_oop(), xadd_offset(offset),
4084 _instance_id, add_offset_speculative(offset), _inline_depth);
4085 }
4086
remove_speculative() const4087 const Type *TypeInstPtr::remove_speculative() const {
4088 if (_speculative == NULL) {
4089 return this;
4090 }
4091 assert(_inline_depth == InlineDepthTop || _inline_depth == InlineDepthBottom, "non speculative type shouldn't have inline depth");
4092 return make(_ptr, klass(), klass_is_exact(), const_oop(), _offset,
4093 _instance_id, NULL, _inline_depth);
4094 }
4095
with_inline_depth(int depth) const4096 const TypePtr *TypeInstPtr::with_inline_depth(int depth) const {
4097 if (!UseInlineDepthForSpeculativeTypes) {
4098 return this;
4099 }
4100 return make(_ptr, klass(), klass_is_exact(), const_oop(), _offset, _instance_id, _speculative, depth);
4101 }
4102
with_instance_id(int instance_id) const4103 const TypePtr *TypeInstPtr::with_instance_id(int instance_id) const {
4104 assert(is_known_instance(), "should be known");
4105 return make(_ptr, klass(), klass_is_exact(), const_oop(), _offset, instance_id, _speculative, _inline_depth);
4106 }
4107
4108 //=============================================================================
4109 // Convenience common pre-built types.
4110 const TypeAryPtr *TypeAryPtr::RANGE;
4111 const TypeAryPtr *TypeAryPtr::OOPS;
4112 const TypeAryPtr *TypeAryPtr::NARROWOOPS;
4113 const TypeAryPtr *TypeAryPtr::BYTES;
4114 const TypeAryPtr *TypeAryPtr::SHORTS;
4115 const TypeAryPtr *TypeAryPtr::CHARS;
4116 const TypeAryPtr *TypeAryPtr::INTS;
4117 const TypeAryPtr *TypeAryPtr::LONGS;
4118 const TypeAryPtr *TypeAryPtr::FLOATS;
4119 const TypeAryPtr *TypeAryPtr::DOUBLES;
4120
4121 //------------------------------make-------------------------------------------
make(PTR ptr,const TypeAry * ary,ciKlass * k,bool xk,int offset,int instance_id,const TypePtr * speculative,int inline_depth)4122 const TypeAryPtr *TypeAryPtr::make(PTR ptr, const TypeAry *ary, ciKlass* k, bool xk, int offset,
4123 int instance_id, const TypePtr* speculative, int inline_depth) {
4124 assert(!(k == NULL && ary->_elem->isa_int()),
4125 "integral arrays must be pre-equipped with a class");
4126 if (!xk) xk = ary->ary_must_be_exact();
4127 assert(instance_id <= 0 || xk, "instances are always exactly typed");
4128 return (TypeAryPtr*)(new TypeAryPtr(ptr, NULL, ary, k, xk, offset, instance_id, false, speculative, inline_depth))->hashcons();
4129 }
4130
4131 //------------------------------make-------------------------------------------
make(PTR ptr,ciObject * o,const TypeAry * ary,ciKlass * k,bool xk,int offset,int instance_id,const TypePtr * speculative,int inline_depth,bool is_autobox_cache)4132 const TypeAryPtr *TypeAryPtr::make(PTR ptr, ciObject* o, const TypeAry *ary, ciKlass* k, bool xk, int offset,
4133 int instance_id, const TypePtr* speculative, int inline_depth,
4134 bool is_autobox_cache) {
4135 assert(!(k == NULL && ary->_elem->isa_int()),
4136 "integral arrays must be pre-equipped with a class");
4137 assert( (ptr==Constant && o) || (ptr!=Constant && !o), "" );
4138 if (!xk) xk = (o != NULL) || ary->ary_must_be_exact();
4139 assert(instance_id <= 0 || xk, "instances are always exactly typed");
4140 return (TypeAryPtr*)(new TypeAryPtr(ptr, o, ary, k, xk, offset, instance_id, is_autobox_cache, speculative, inline_depth))->hashcons();
4141 }
4142
4143 //------------------------------cast_to_ptr_type-------------------------------
cast_to_ptr_type(PTR ptr) const4144 const Type *TypeAryPtr::cast_to_ptr_type(PTR ptr) const {
4145 if( ptr == _ptr ) return this;
4146 return make(ptr, const_oop(), _ary, klass(), klass_is_exact(), _offset, _instance_id, _speculative, _inline_depth);
4147 }
4148
4149
4150 //-----------------------------cast_to_exactness-------------------------------
cast_to_exactness(bool klass_is_exact) const4151 const Type *TypeAryPtr::cast_to_exactness(bool klass_is_exact) const {
4152 if( klass_is_exact == _klass_is_exact ) return this;
4153 if (_ary->ary_must_be_exact()) return this; // cannot clear xk
4154 return make(ptr(), const_oop(), _ary, klass(), klass_is_exact, _offset, _instance_id, _speculative, _inline_depth);
4155 }
4156
4157 //-----------------------------cast_to_instance_id----------------------------
cast_to_instance_id(int instance_id) const4158 const TypeOopPtr *TypeAryPtr::cast_to_instance_id(int instance_id) const {
4159 if( instance_id == _instance_id ) return this;
4160 return make(_ptr, const_oop(), _ary, klass(), _klass_is_exact, _offset, instance_id, _speculative, _inline_depth);
4161 }
4162
4163
4164 //-----------------------------max_array_length-------------------------------
4165 // A wrapper around arrayOopDesc::max_array_length(etype) with some input normalization.
max_array_length(BasicType etype)4166 jint TypeAryPtr::max_array_length(BasicType etype) {
4167 if (!is_java_primitive(etype) && !is_reference_type(etype)) {
4168 if (etype == T_NARROWOOP) {
4169 etype = T_OBJECT;
4170 } else if (etype == T_ILLEGAL) { // bottom[]
4171 etype = T_BYTE; // will produce conservatively high value
4172 } else {
4173 fatal("not an element type: %s", type2name(etype));
4174 }
4175 }
4176 return arrayOopDesc::max_array_length(etype);
4177 }
4178
4179 //-----------------------------narrow_size_type-------------------------------
4180 // Narrow the given size type to the index range for the given array base type.
4181 // Return NULL if the resulting int type becomes empty.
narrow_size_type(const TypeInt * size) const4182 const TypeInt* TypeAryPtr::narrow_size_type(const TypeInt* size) const {
4183 jint hi = size->_hi;
4184 jint lo = size->_lo;
4185 jint min_lo = 0;
4186 jint max_hi = max_array_length(elem()->basic_type());
4187 //if (index_not_size) --max_hi; // type of a valid array index, FTR
4188 bool chg = false;
4189 if (lo < min_lo) {
4190 lo = min_lo;
4191 if (size->is_con()) {
4192 hi = lo;
4193 }
4194 chg = true;
4195 }
4196 if (hi > max_hi) {
4197 hi = max_hi;
4198 if (size->is_con()) {
4199 lo = hi;
4200 }
4201 chg = true;
4202 }
4203 // Negative length arrays will produce weird intermediate dead fast-path code
4204 if (lo > hi)
4205 return TypeInt::ZERO;
4206 if (!chg)
4207 return size;
4208 return TypeInt::make(lo, hi, Type::WidenMin);
4209 }
4210
4211 //-------------------------------cast_to_size----------------------------------
cast_to_size(const TypeInt * new_size) const4212 const TypeAryPtr* TypeAryPtr::cast_to_size(const TypeInt* new_size) const {
4213 assert(new_size != NULL, "");
4214 new_size = narrow_size_type(new_size);
4215 if (new_size == size()) return this;
4216 const TypeAry* new_ary = TypeAry::make(elem(), new_size, is_stable());
4217 return make(ptr(), const_oop(), new_ary, klass(), klass_is_exact(), _offset, _instance_id, _speculative, _inline_depth);
4218 }
4219
4220 //------------------------------cast_to_stable---------------------------------
cast_to_stable(bool stable,int stable_dimension) const4221 const TypeAryPtr* TypeAryPtr::cast_to_stable(bool stable, int stable_dimension) const {
4222 if (stable_dimension <= 0 || (stable_dimension == 1 && stable == this->is_stable()))
4223 return this;
4224
4225 const Type* elem = this->elem();
4226 const TypePtr* elem_ptr = elem->make_ptr();
4227
4228 if (stable_dimension > 1 && elem_ptr != NULL && elem_ptr->isa_aryptr()) {
4229 // If this is widened from a narrow oop, TypeAry::make will re-narrow it.
4230 elem = elem_ptr = elem_ptr->is_aryptr()->cast_to_stable(stable, stable_dimension - 1);
4231 }
4232
4233 const TypeAry* new_ary = TypeAry::make(elem, size(), stable);
4234
4235 return make(ptr(), const_oop(), new_ary, klass(), klass_is_exact(), _offset, _instance_id, _speculative, _inline_depth);
4236 }
4237
4238 //-----------------------------stable_dimension--------------------------------
stable_dimension() const4239 int TypeAryPtr::stable_dimension() const {
4240 if (!is_stable()) return 0;
4241 int dim = 1;
4242 const TypePtr* elem_ptr = elem()->make_ptr();
4243 if (elem_ptr != NULL && elem_ptr->isa_aryptr())
4244 dim += elem_ptr->is_aryptr()->stable_dimension();
4245 return dim;
4246 }
4247
4248 //----------------------cast_to_autobox_cache-----------------------------------
cast_to_autobox_cache() const4249 const TypeAryPtr* TypeAryPtr::cast_to_autobox_cache() const {
4250 if (is_autobox_cache()) return this;
4251 const TypeOopPtr* etype = elem()->make_oopptr();
4252 if (etype == NULL) return this;
4253 // The pointers in the autobox arrays are always non-null.
4254 etype = etype->cast_to_ptr_type(TypePtr::NotNull)->is_oopptr();
4255 const TypeAry* new_ary = TypeAry::make(etype, size(), is_stable());
4256 return make(ptr(), const_oop(), new_ary, klass(), klass_is_exact(), _offset, _instance_id, _speculative, _inline_depth, /*is_autobox_cache=*/true);
4257 }
4258
4259 //------------------------------eq---------------------------------------------
4260 // Structural equality check for Type representations
eq(const Type * t) const4261 bool TypeAryPtr::eq( const Type *t ) const {
4262 const TypeAryPtr *p = t->is_aryptr();
4263 return
4264 _ary == p->_ary && // Check array
4265 TypeOopPtr::eq(p); // Check sub-parts
4266 }
4267
4268 //------------------------------hash-------------------------------------------
4269 // Type-specific hashing function.
hash(void) const4270 int TypeAryPtr::hash(void) const {
4271 return (intptr_t)_ary + TypeOopPtr::hash();
4272 }
4273
4274 //------------------------------meet-------------------------------------------
4275 // Compute the MEET of two types. It returns a new Type object.
xmeet_helper(const Type * t) const4276 const Type *TypeAryPtr::xmeet_helper(const Type *t) const {
4277 // Perform a fast test for common case; meeting the same types together.
4278 if( this == t ) return this; // Meeting same type-rep?
4279 // Current "this->_base" is Pointer
4280 switch (t->base()) { // switch on original type
4281
4282 // Mixing ints & oops happens when javac reuses local variables
4283 case Int:
4284 case Long:
4285 case FloatTop:
4286 case FloatCon:
4287 case FloatBot:
4288 case DoubleTop:
4289 case DoubleCon:
4290 case DoubleBot:
4291 case NarrowOop:
4292 case NarrowKlass:
4293 case Bottom: // Ye Olde Default
4294 return Type::BOTTOM;
4295 case Top:
4296 return this;
4297
4298 default: // All else is a mistake
4299 typerr(t);
4300
4301 case OopPtr: { // Meeting to OopPtrs
4302 // Found a OopPtr type vs self-AryPtr type
4303 const TypeOopPtr *tp = t->is_oopptr();
4304 int offset = meet_offset(tp->offset());
4305 PTR ptr = meet_ptr(tp->ptr());
4306 int depth = meet_inline_depth(tp->inline_depth());
4307 const TypePtr* speculative = xmeet_speculative(tp);
4308 switch (tp->ptr()) {
4309 case TopPTR:
4310 case AnyNull: {
4311 int instance_id = meet_instance_id(InstanceTop);
4312 return make(ptr, (ptr == Constant ? const_oop() : NULL),
4313 _ary, _klass, _klass_is_exact, offset, instance_id, speculative, depth);
4314 }
4315 case BotPTR:
4316 case NotNull: {
4317 int instance_id = meet_instance_id(tp->instance_id());
4318 return TypeOopPtr::make(ptr, offset, instance_id, speculative, depth);
4319 }
4320 default: ShouldNotReachHere();
4321 }
4322 }
4323
4324 case AnyPtr: { // Meeting two AnyPtrs
4325 // Found an AnyPtr type vs self-AryPtr type
4326 const TypePtr *tp = t->is_ptr();
4327 int offset = meet_offset(tp->offset());
4328 PTR ptr = meet_ptr(tp->ptr());
4329 const TypePtr* speculative = xmeet_speculative(tp);
4330 int depth = meet_inline_depth(tp->inline_depth());
4331 switch (tp->ptr()) {
4332 case TopPTR:
4333 return this;
4334 case BotPTR:
4335 case NotNull:
4336 return TypePtr::make(AnyPtr, ptr, offset, speculative, depth);
4337 case Null:
4338 if( ptr == Null ) return TypePtr::make(AnyPtr, ptr, offset, speculative, depth);
4339 // else fall through to AnyNull
4340 case AnyNull: {
4341 int instance_id = meet_instance_id(InstanceTop);
4342 return make(ptr, (ptr == Constant ? const_oop() : NULL),
4343 _ary, _klass, _klass_is_exact, offset, instance_id, speculative, depth);
4344 }
4345 default: ShouldNotReachHere();
4346 }
4347 }
4348
4349 case MetadataPtr:
4350 case KlassPtr:
4351 case RawPtr: return TypePtr::BOTTOM;
4352
4353 case AryPtr: { // Meeting 2 references?
4354 const TypeAryPtr *tap = t->is_aryptr();
4355 int off = meet_offset(tap->offset());
4356 const TypeAry *tary = _ary->meet_speculative(tap->_ary)->is_ary();
4357 PTR ptr = meet_ptr(tap->ptr());
4358 int instance_id = meet_instance_id(tap->instance_id());
4359 const TypePtr* speculative = xmeet_speculative(tap);
4360 int depth = meet_inline_depth(tap->inline_depth());
4361 ciKlass* lazy_klass = NULL;
4362 if (tary->_elem->isa_int()) {
4363 // Integral array element types have irrelevant lattice relations.
4364 // It is the klass that determines array layout, not the element type.
4365 if (_klass == NULL)
4366 lazy_klass = tap->_klass;
4367 else if (tap->_klass == NULL || tap->_klass == _klass) {
4368 lazy_klass = _klass;
4369 } else {
4370 // Something like byte[int+] meets char[int+].
4371 // This must fall to bottom, not (int[-128..65535])[int+].
4372 instance_id = InstanceBot;
4373 tary = TypeAry::make(Type::BOTTOM, tary->_size, tary->_stable);
4374 }
4375 } else // Non integral arrays.
4376 // Must fall to bottom if exact klasses in upper lattice
4377 // are not equal or super klass is exact.
4378 if ((above_centerline(ptr) || ptr == Constant) && klass() != tap->klass() &&
4379 // meet with top[] and bottom[] are processed further down:
4380 tap->_klass != NULL && this->_klass != NULL &&
4381 // both are exact and not equal:
4382 ((tap->_klass_is_exact && this->_klass_is_exact) ||
4383 // 'tap' is exact and super or unrelated:
4384 (tap->_klass_is_exact && !tap->klass()->is_subtype_of(klass())) ||
4385 // 'this' is exact and super or unrelated:
4386 (this->_klass_is_exact && !klass()->is_subtype_of(tap->klass())))) {
4387 if (above_centerline(ptr) || (tary->_elem->make_ptr() && above_centerline(tary->_elem->make_ptr()->_ptr))) {
4388 tary = TypeAry::make(Type::BOTTOM, tary->_size, tary->_stable);
4389 }
4390 return make(NotNull, NULL, tary, lazy_klass, false, off, InstanceBot, speculative, depth);
4391 }
4392
4393 bool xk = false;
4394 switch (tap->ptr()) {
4395 case AnyNull:
4396 case TopPTR:
4397 // Compute new klass on demand, do not use tap->_klass
4398 if (below_centerline(this->_ptr)) {
4399 xk = this->_klass_is_exact;
4400 } else {
4401 xk = (tap->_klass_is_exact || this->_klass_is_exact);
4402 }
4403 return make(ptr, const_oop(), tary, lazy_klass, xk, off, instance_id, speculative, depth);
4404 case Constant: {
4405 ciObject* o = const_oop();
4406 if( _ptr == Constant ) {
4407 if( tap->const_oop() != NULL && !o->equals(tap->const_oop()) ) {
4408 xk = (klass() == tap->klass());
4409 ptr = NotNull;
4410 o = NULL;
4411 instance_id = InstanceBot;
4412 } else {
4413 xk = true;
4414 }
4415 } else if(above_centerline(_ptr)) {
4416 o = tap->const_oop();
4417 xk = true;
4418 } else {
4419 // Only precise for identical arrays
4420 xk = this->_klass_is_exact && (klass() == tap->klass());
4421 }
4422 return TypeAryPtr::make(ptr, o, tary, lazy_klass, xk, off, instance_id, speculative, depth);
4423 }
4424 case NotNull:
4425 case BotPTR:
4426 // Compute new klass on demand, do not use tap->_klass
4427 if (above_centerline(this->_ptr))
4428 xk = tap->_klass_is_exact;
4429 else xk = (tap->_klass_is_exact & this->_klass_is_exact) &&
4430 (klass() == tap->klass()); // Only precise for identical arrays
4431 return TypeAryPtr::make(ptr, NULL, tary, lazy_klass, xk, off, instance_id, speculative, depth);
4432 default: ShouldNotReachHere();
4433 }
4434 }
4435
4436 // All arrays inherit from Object class
4437 case InstPtr: {
4438 const TypeInstPtr *tp = t->is_instptr();
4439 int offset = meet_offset(tp->offset());
4440 PTR ptr = meet_ptr(tp->ptr());
4441 int instance_id = meet_instance_id(tp->instance_id());
4442 const TypePtr* speculative = xmeet_speculative(tp);
4443 int depth = meet_inline_depth(tp->inline_depth());
4444 switch (ptr) {
4445 case TopPTR:
4446 case AnyNull: // Fall 'down' to dual of object klass
4447 // For instances when a subclass meets a superclass we fall
4448 // below the centerline when the superclass is exact. We need to
4449 // do the same here.
4450 if (tp->klass()->equals(ciEnv::current()->Object_klass()) && !tp->klass_is_exact()) {
4451 return TypeAryPtr::make(ptr, _ary, _klass, _klass_is_exact, offset, instance_id, speculative, depth);
4452 } else {
4453 // cannot subclass, so the meet has to fall badly below the centerline
4454 ptr = NotNull;
4455 instance_id = InstanceBot;
4456 return TypeInstPtr::make(ptr, ciEnv::current()->Object_klass(), false, NULL,offset, instance_id, speculative, depth);
4457 }
4458 case Constant:
4459 case NotNull:
4460 case BotPTR: // Fall down to object klass
4461 // LCA is object_klass, but if we subclass from the top we can do better
4462 if (above_centerline(tp->ptr())) {
4463 // If 'tp' is above the centerline and it is Object class
4464 // then we can subclass in the Java class hierarchy.
4465 // For instances when a subclass meets a superclass we fall
4466 // below the centerline when the superclass is exact. We need
4467 // to do the same here.
4468 if (tp->klass()->equals(ciEnv::current()->Object_klass()) && !tp->klass_is_exact()) {
4469 // that is, my array type is a subtype of 'tp' klass
4470 return make(ptr, (ptr == Constant ? const_oop() : NULL),
4471 _ary, _klass, _klass_is_exact, offset, instance_id, speculative, depth);
4472 }
4473 }
4474 // The other case cannot happen, since t cannot be a subtype of an array.
4475 // The meet falls down to Object class below centerline.
4476 if( ptr == Constant )
4477 ptr = NotNull;
4478 instance_id = InstanceBot;
4479 return TypeInstPtr::make(ptr, ciEnv::current()->Object_klass(), false, NULL,offset, instance_id, speculative, depth);
4480 default: typerr(t);
4481 }
4482 }
4483 }
4484 return this; // Lint noise
4485 }
4486
4487 //------------------------------xdual------------------------------------------
4488 // Dual: compute field-by-field dual
xdual() const4489 const Type *TypeAryPtr::xdual() const {
4490 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());
4491 }
4492
4493 //----------------------interface_vs_oop---------------------------------------
4494 #ifdef ASSERT
interface_vs_oop(const Type * t) const4495 bool TypeAryPtr::interface_vs_oop(const Type *t) const {
4496 const TypeAryPtr* t_aryptr = t->isa_aryptr();
4497 if (t_aryptr) {
4498 return _ary->interface_vs_oop(t_aryptr->_ary);
4499 }
4500 return false;
4501 }
4502 #endif
4503
4504 //------------------------------dump2------------------------------------------
4505 #ifndef PRODUCT
dump2(Dict & d,uint depth,outputStream * st) const4506 void TypeAryPtr::dump2( Dict &d, uint depth, outputStream *st ) const {
4507 _ary->dump2(d,depth,st);
4508 switch( _ptr ) {
4509 case Constant:
4510 const_oop()->print(st);
4511 break;
4512 case BotPTR:
4513 if (!WizardMode && !Verbose) {
4514 if( _klass_is_exact ) st->print(":exact");
4515 break;
4516 }
4517 case TopPTR:
4518 case AnyNull:
4519 case NotNull:
4520 st->print(":%s", ptr_msg[_ptr]);
4521 if( _klass_is_exact ) st->print(":exact");
4522 break;
4523 default:
4524 break;
4525 }
4526
4527 if( _offset != 0 ) {
4528 int header_size = objArrayOopDesc::header_size() * wordSize;
4529 if( _offset == OffsetTop ) st->print("+undefined");
4530 else if( _offset == OffsetBot ) st->print("+any");
4531 else if( _offset < header_size ) st->print("+%d", _offset);
4532 else {
4533 BasicType basic_elem_type = elem()->basic_type();
4534 int array_base = arrayOopDesc::base_offset_in_bytes(basic_elem_type);
4535 int elem_size = type2aelembytes(basic_elem_type);
4536 st->print("[%d]", (_offset - array_base)/elem_size);
4537 }
4538 }
4539 st->print(" *");
4540 if (_instance_id == InstanceTop)
4541 st->print(",iid=top");
4542 else if (_instance_id != InstanceBot)
4543 st->print(",iid=%d",_instance_id);
4544
4545 dump_inline_depth(st);
4546 dump_speculative(st);
4547 }
4548 #endif
4549
empty(void) const4550 bool TypeAryPtr::empty(void) const {
4551 if (_ary->empty()) return true;
4552 return TypeOopPtr::empty();
4553 }
4554
4555 //------------------------------add_offset-------------------------------------
add_offset(intptr_t offset) const4556 const TypePtr *TypeAryPtr::add_offset(intptr_t offset) const {
4557 return make(_ptr, _const_oop, _ary, _klass, _klass_is_exact, xadd_offset(offset), _instance_id, add_offset_speculative(offset), _inline_depth);
4558 }
4559
remove_speculative() const4560 const Type *TypeAryPtr::remove_speculative() const {
4561 if (_speculative == NULL) {
4562 return this;
4563 }
4564 assert(_inline_depth == InlineDepthTop || _inline_depth == InlineDepthBottom, "non speculative type shouldn't have inline depth");
4565 return make(_ptr, _const_oop, _ary->remove_speculative()->is_ary(), _klass, _klass_is_exact, _offset, _instance_id, NULL, _inline_depth);
4566 }
4567
with_inline_depth(int depth) const4568 const TypePtr *TypeAryPtr::with_inline_depth(int depth) const {
4569 if (!UseInlineDepthForSpeculativeTypes) {
4570 return this;
4571 }
4572 return make(_ptr, _const_oop, _ary->remove_speculative()->is_ary(), _klass, _klass_is_exact, _offset, _instance_id, _speculative, depth);
4573 }
4574
with_instance_id(int instance_id) const4575 const TypePtr *TypeAryPtr::with_instance_id(int instance_id) const {
4576 assert(is_known_instance(), "should be known");
4577 return make(_ptr, _const_oop, _ary->remove_speculative()->is_ary(), _klass, _klass_is_exact, _offset, instance_id, _speculative, _inline_depth);
4578 }
4579
4580 //=============================================================================
4581
4582 //------------------------------hash-------------------------------------------
4583 // Type-specific hashing function.
hash(void) const4584 int TypeNarrowPtr::hash(void) const {
4585 return _ptrtype->hash() + 7;
4586 }
4587
singleton(void) const4588 bool TypeNarrowPtr::singleton(void) const { // TRUE if type is a singleton
4589 return _ptrtype->singleton();
4590 }
4591
empty(void) const4592 bool TypeNarrowPtr::empty(void) const {
4593 return _ptrtype->empty();
4594 }
4595
get_con() const4596 intptr_t TypeNarrowPtr::get_con() const {
4597 return _ptrtype->get_con();
4598 }
4599
eq(const Type * t) const4600 bool TypeNarrowPtr::eq( const Type *t ) const {
4601 const TypeNarrowPtr* tc = isa_same_narrowptr(t);
4602 if (tc != NULL) {
4603 if (_ptrtype->base() != tc->_ptrtype->base()) {
4604 return false;
4605 }
4606 return tc->_ptrtype->eq(_ptrtype);
4607 }
4608 return false;
4609 }
4610
xdual() const4611 const Type *TypeNarrowPtr::xdual() const { // Compute dual right now.
4612 const TypePtr* odual = _ptrtype->dual()->is_ptr();
4613 return make_same_narrowptr(odual);
4614 }
4615
4616
filter_helper(const Type * kills,bool include_speculative) const4617 const Type *TypeNarrowPtr::filter_helper(const Type *kills, bool include_speculative) const {
4618 if (isa_same_narrowptr(kills)) {
4619 const Type* ft =_ptrtype->filter_helper(is_same_narrowptr(kills)->_ptrtype, include_speculative);
4620 if (ft->empty())
4621 return Type::TOP; // Canonical empty value
4622 if (ft->isa_ptr()) {
4623 return make_hash_same_narrowptr(ft->isa_ptr());
4624 }
4625 return ft;
4626 } else if (kills->isa_ptr()) {
4627 const Type* ft = _ptrtype->join_helper(kills, include_speculative);
4628 if (ft->empty())
4629 return Type::TOP; // Canonical empty value
4630 return ft;
4631 } else {
4632 return Type::TOP;
4633 }
4634 }
4635
4636 //------------------------------xmeet------------------------------------------
4637 // Compute the MEET of two types. It returns a new Type object.
xmeet(const Type * t) const4638 const Type *TypeNarrowPtr::xmeet( const Type *t ) const {
4639 // Perform a fast test for common case; meeting the same types together.
4640 if( this == t ) return this; // Meeting same type-rep?
4641
4642 if (t->base() == base()) {
4643 const Type* result = _ptrtype->xmeet(t->make_ptr());
4644 if (result->isa_ptr()) {
4645 return make_hash_same_narrowptr(result->is_ptr());
4646 }
4647 return result;
4648 }
4649
4650 // Current "this->_base" is NarrowKlass or NarrowOop
4651 switch (t->base()) { // switch on original type
4652
4653 case Int: // Mixing ints & oops happens when javac
4654 case Long: // reuses local variables
4655 case FloatTop:
4656 case FloatCon:
4657 case FloatBot:
4658 case DoubleTop:
4659 case DoubleCon:
4660 case DoubleBot:
4661 case AnyPtr:
4662 case RawPtr:
4663 case OopPtr:
4664 case InstPtr:
4665 case AryPtr:
4666 case MetadataPtr:
4667 case KlassPtr:
4668 case NarrowOop:
4669 case NarrowKlass:
4670
4671 case Bottom: // Ye Olde Default
4672 return Type::BOTTOM;
4673 case Top:
4674 return this;
4675
4676 default: // All else is a mistake
4677 typerr(t);
4678
4679 } // End of switch
4680
4681 return this;
4682 }
4683
4684 #ifndef PRODUCT
dump2(Dict & d,uint depth,outputStream * st) const4685 void TypeNarrowPtr::dump2( Dict & d, uint depth, outputStream *st ) const {
4686 _ptrtype->dump2(d, depth, st);
4687 }
4688 #endif
4689
4690 const TypeNarrowOop *TypeNarrowOop::BOTTOM;
4691 const TypeNarrowOop *TypeNarrowOop::NULL_PTR;
4692
4693
make(const TypePtr * type)4694 const TypeNarrowOop* TypeNarrowOop::make(const TypePtr* type) {
4695 return (const TypeNarrowOop*)(new TypeNarrowOop(type))->hashcons();
4696 }
4697
remove_speculative() const4698 const Type* TypeNarrowOop::remove_speculative() const {
4699 return make(_ptrtype->remove_speculative()->is_ptr());
4700 }
4701
cleanup_speculative() const4702 const Type* TypeNarrowOop::cleanup_speculative() const {
4703 return make(_ptrtype->cleanup_speculative()->is_ptr());
4704 }
4705
4706 #ifndef PRODUCT
dump2(Dict & d,uint depth,outputStream * st) const4707 void TypeNarrowOop::dump2( Dict & d, uint depth, outputStream *st ) const {
4708 st->print("narrowoop: ");
4709 TypeNarrowPtr::dump2(d, depth, st);
4710 }
4711 #endif
4712
4713 const TypeNarrowKlass *TypeNarrowKlass::NULL_PTR;
4714
make(const TypePtr * type)4715 const TypeNarrowKlass* TypeNarrowKlass::make(const TypePtr* type) {
4716 return (const TypeNarrowKlass*)(new TypeNarrowKlass(type))->hashcons();
4717 }
4718
4719 #ifndef PRODUCT
dump2(Dict & d,uint depth,outputStream * st) const4720 void TypeNarrowKlass::dump2( Dict & d, uint depth, outputStream *st ) const {
4721 st->print("narrowklass: ");
4722 TypeNarrowPtr::dump2(d, depth, st);
4723 }
4724 #endif
4725
4726
4727 //------------------------------eq---------------------------------------------
4728 // Structural equality check for Type representations
eq(const Type * t) const4729 bool TypeMetadataPtr::eq( const Type *t ) const {
4730 const TypeMetadataPtr *a = (const TypeMetadataPtr*)t;
4731 ciMetadata* one = metadata();
4732 ciMetadata* two = a->metadata();
4733 if (one == NULL || two == NULL) {
4734 return (one == two) && TypePtr::eq(t);
4735 } else {
4736 return one->equals(two) && TypePtr::eq(t);
4737 }
4738 }
4739
4740 //------------------------------hash-------------------------------------------
4741 // Type-specific hashing function.
hash(void) const4742 int TypeMetadataPtr::hash(void) const {
4743 return
4744 (metadata() ? metadata()->hash() : 0) +
4745 TypePtr::hash();
4746 }
4747
4748 //------------------------------singleton--------------------------------------
4749 // TRUE if Type is a singleton type, FALSE otherwise. Singletons are simple
4750 // constants
singleton(void) const4751 bool TypeMetadataPtr::singleton(void) const {
4752 // detune optimizer to not generate constant metadata + constant offset as a constant!
4753 // TopPTR, Null, AnyNull, Constant are all singletons
4754 return (_offset == 0) && !below_centerline(_ptr);
4755 }
4756
4757 //------------------------------add_offset-------------------------------------
add_offset(intptr_t offset) const4758 const TypePtr *TypeMetadataPtr::add_offset( intptr_t offset ) const {
4759 return make( _ptr, _metadata, xadd_offset(offset));
4760 }
4761
4762 //-----------------------------filter------------------------------------------
4763 // Do not allow interface-vs.-noninterface joins to collapse to top.
filter_helper(const Type * kills,bool include_speculative) const4764 const Type *TypeMetadataPtr::filter_helper(const Type *kills, bool include_speculative) const {
4765 const TypeMetadataPtr* ft = join_helper(kills, include_speculative)->isa_metadataptr();
4766 if (ft == NULL || ft->empty())
4767 return Type::TOP; // Canonical empty value
4768 return ft;
4769 }
4770
4771 //------------------------------get_con----------------------------------------
get_con() const4772 intptr_t TypeMetadataPtr::get_con() const {
4773 assert( _ptr == Null || _ptr == Constant, "" );
4774 assert( _offset >= 0, "" );
4775
4776 if (_offset != 0) {
4777 // After being ported to the compiler interface, the compiler no longer
4778 // directly manipulates the addresses of oops. Rather, it only has a pointer
4779 // to a handle at compile time. This handle is embedded in the generated
4780 // code and dereferenced at the time the nmethod is made. Until that time,
4781 // it is not reasonable to do arithmetic with the addresses of oops (we don't
4782 // have access to the addresses!). This does not seem to currently happen,
4783 // but this assertion here is to help prevent its occurence.
4784 tty->print_cr("Found oop constant with non-zero offset");
4785 ShouldNotReachHere();
4786 }
4787
4788 return (intptr_t)metadata()->constant_encoding();
4789 }
4790
4791 //------------------------------cast_to_ptr_type-------------------------------
cast_to_ptr_type(PTR ptr) const4792 const Type *TypeMetadataPtr::cast_to_ptr_type(PTR ptr) const {
4793 if( ptr == _ptr ) return this;
4794 return make(ptr, metadata(), _offset);
4795 }
4796
4797 //------------------------------meet-------------------------------------------
4798 // Compute the MEET of two types. It returns a new Type object.
xmeet(const Type * t) const4799 const Type *TypeMetadataPtr::xmeet( const Type *t ) const {
4800 // Perform a fast test for common case; meeting the same types together.
4801 if( this == t ) return this; // Meeting same type-rep?
4802
4803 // Current "this->_base" is OopPtr
4804 switch (t->base()) { // switch on original type
4805
4806 case Int: // Mixing ints & oops happens when javac
4807 case Long: // reuses local variables
4808 case FloatTop:
4809 case FloatCon:
4810 case FloatBot:
4811 case DoubleTop:
4812 case DoubleCon:
4813 case DoubleBot:
4814 case NarrowOop:
4815 case NarrowKlass:
4816 case Bottom: // Ye Olde Default
4817 return Type::BOTTOM;
4818 case Top:
4819 return this;
4820
4821 default: // All else is a mistake
4822 typerr(t);
4823
4824 case AnyPtr: {
4825 // Found an AnyPtr type vs self-OopPtr type
4826 const TypePtr *tp = t->is_ptr();
4827 int offset = meet_offset(tp->offset());
4828 PTR ptr = meet_ptr(tp->ptr());
4829 switch (tp->ptr()) {
4830 case Null:
4831 if (ptr == Null) return TypePtr::make(AnyPtr, ptr, offset, tp->speculative(), tp->inline_depth());
4832 // else fall through:
4833 case TopPTR:
4834 case AnyNull: {
4835 return make(ptr, _metadata, offset);
4836 }
4837 case BotPTR:
4838 case NotNull:
4839 return TypePtr::make(AnyPtr, ptr, offset, tp->speculative(), tp->inline_depth());
4840 default: typerr(t);
4841 }
4842 }
4843
4844 case RawPtr:
4845 case KlassPtr:
4846 case OopPtr:
4847 case InstPtr:
4848 case AryPtr:
4849 return TypePtr::BOTTOM; // Oop meet raw is not well defined
4850
4851 case MetadataPtr: {
4852 const TypeMetadataPtr *tp = t->is_metadataptr();
4853 int offset = meet_offset(tp->offset());
4854 PTR tptr = tp->ptr();
4855 PTR ptr = meet_ptr(tptr);
4856 ciMetadata* md = (tptr == TopPTR) ? metadata() : tp->metadata();
4857 if (tptr == TopPTR || _ptr == TopPTR ||
4858 metadata()->equals(tp->metadata())) {
4859 return make(ptr, md, offset);
4860 }
4861 // metadata is different
4862 if( ptr == Constant ) { // Cannot be equal constants, so...
4863 if( tptr == Constant && _ptr != Constant) return t;
4864 if( _ptr == Constant && tptr != Constant) return this;
4865 ptr = NotNull; // Fall down in lattice
4866 }
4867 return make(ptr, NULL, offset);
4868 break;
4869 }
4870 } // End of switch
4871 return this; // Return the double constant
4872 }
4873
4874
4875 //------------------------------xdual------------------------------------------
4876 // Dual of a pure metadata pointer.
xdual() const4877 const Type *TypeMetadataPtr::xdual() const {
4878 return new TypeMetadataPtr(dual_ptr(), metadata(), dual_offset());
4879 }
4880
4881 //------------------------------dump2------------------------------------------
4882 #ifndef PRODUCT
dump2(Dict & d,uint depth,outputStream * st) const4883 void TypeMetadataPtr::dump2( Dict &d, uint depth, outputStream *st ) const {
4884 st->print("metadataptr:%s", ptr_msg[_ptr]);
4885 if( metadata() ) st->print(INTPTR_FORMAT, p2i(metadata()));
4886 switch( _offset ) {
4887 case OffsetTop: st->print("+top"); break;
4888 case OffsetBot: st->print("+any"); break;
4889 case 0: break;
4890 default: st->print("+%d",_offset); break;
4891 }
4892 }
4893 #endif
4894
4895
4896 //=============================================================================
4897 // Convenience common pre-built type.
4898 const TypeMetadataPtr *TypeMetadataPtr::BOTTOM;
4899
TypeMetadataPtr(PTR ptr,ciMetadata * metadata,int offset)4900 TypeMetadataPtr::TypeMetadataPtr(PTR ptr, ciMetadata* metadata, int offset):
4901 TypePtr(MetadataPtr, ptr, offset), _metadata(metadata) {
4902 }
4903
make(ciMethod * m)4904 const TypeMetadataPtr* TypeMetadataPtr::make(ciMethod* m) {
4905 return make(Constant, m, 0);
4906 }
make(ciMethodData * m)4907 const TypeMetadataPtr* TypeMetadataPtr::make(ciMethodData* m) {
4908 return make(Constant, m, 0);
4909 }
4910
4911 //------------------------------make-------------------------------------------
4912 // Create a meta data constant
make(PTR ptr,ciMetadata * m,int offset)4913 const TypeMetadataPtr *TypeMetadataPtr::make(PTR ptr, ciMetadata* m, int offset) {
4914 assert(m == NULL || !m->is_klass(), "wrong type");
4915 return (TypeMetadataPtr*)(new TypeMetadataPtr(ptr, m, offset))->hashcons();
4916 }
4917
4918
4919 //=============================================================================
4920 // Convenience common pre-built types.
4921
4922 // Not-null object klass or below
4923 const TypeKlassPtr *TypeKlassPtr::OBJECT;
4924 const TypeKlassPtr *TypeKlassPtr::OBJECT_OR_NULL;
4925
4926 //------------------------------TypeKlassPtr-----------------------------------
TypeKlassPtr(PTR ptr,ciKlass * klass,int offset)4927 TypeKlassPtr::TypeKlassPtr( PTR ptr, ciKlass* klass, int offset )
4928 : TypePtr(KlassPtr, ptr, offset), _klass(klass), _klass_is_exact(ptr == Constant) {
4929 }
4930
4931 //------------------------------make-------------------------------------------
4932 // ptr to klass 'k', if Constant, or possibly to a sub-klass if not a Constant
make(PTR ptr,ciKlass * k,int offset)4933 const TypeKlassPtr *TypeKlassPtr::make( PTR ptr, ciKlass* k, int offset ) {
4934 assert( k != NULL, "Expect a non-NULL klass");
4935 assert(k->is_instance_klass() || k->is_array_klass(), "Incorrect type of klass oop");
4936 TypeKlassPtr *r =
4937 (TypeKlassPtr*)(new TypeKlassPtr(ptr, k, offset))->hashcons();
4938
4939 return r;
4940 }
4941
4942 //------------------------------eq---------------------------------------------
4943 // Structural equality check for Type representations
eq(const Type * t) const4944 bool TypeKlassPtr::eq( const Type *t ) const {
4945 const TypeKlassPtr *p = t->is_klassptr();
4946 return
4947 klass()->equals(p->klass()) &&
4948 TypePtr::eq(p);
4949 }
4950
4951 //------------------------------hash-------------------------------------------
4952 // Type-specific hashing function.
hash(void) const4953 int TypeKlassPtr::hash(void) const {
4954 return java_add((jint)klass()->hash(), (jint)TypePtr::hash());
4955 }
4956
4957 //------------------------------singleton--------------------------------------
4958 // TRUE if Type is a singleton type, FALSE otherwise. Singletons are simple
4959 // constants
singleton(void) const4960 bool TypeKlassPtr::singleton(void) const {
4961 // detune optimizer to not generate constant klass + constant offset as a constant!
4962 // TopPTR, Null, AnyNull, Constant are all singletons
4963 return (_offset == 0) && !below_centerline(_ptr);
4964 }
4965
4966 // Do not allow interface-vs.-noninterface joins to collapse to top.
filter_helper(const Type * kills,bool include_speculative) const4967 const Type *TypeKlassPtr::filter_helper(const Type *kills, bool include_speculative) const {
4968 // logic here mirrors the one from TypeOopPtr::filter. See comments
4969 // there.
4970 const Type* ft = join_helper(kills, include_speculative);
4971 const TypeKlassPtr* ftkp = ft->isa_klassptr();
4972 const TypeKlassPtr* ktkp = kills->isa_klassptr();
4973
4974 if (ft->empty()) {
4975 if (!empty() && ktkp != NULL && ktkp->klass()->is_loaded() && ktkp->klass()->is_interface())
4976 return kills; // Uplift to interface
4977
4978 return Type::TOP; // Canonical empty value
4979 }
4980
4981 // Interface klass type could be exact in opposite to interface type,
4982 // return it here instead of incorrect Constant ptr J/L/Object (6894807).
4983 if (ftkp != NULL && ktkp != NULL &&
4984 ftkp->is_loaded() && ftkp->klass()->is_interface() &&
4985 !ftkp->klass_is_exact() && // Keep exact interface klass
4986 ktkp->is_loaded() && !ktkp->klass()->is_interface()) {
4987 return ktkp->cast_to_ptr_type(ftkp->ptr());
4988 }
4989
4990 return ft;
4991 }
4992
4993 //----------------------compute_klass------------------------------------------
4994 // Compute the defining klass for this class
compute_klass(DEBUG_ONLY (bool verify)) const4995 ciKlass* TypeAryPtr::compute_klass(DEBUG_ONLY(bool verify)) const {
4996 // Compute _klass based on element type.
4997 ciKlass* k_ary = NULL;
4998 const TypeInstPtr *tinst;
4999 const TypeAryPtr *tary;
5000 const Type* el = elem();
5001 if (el->isa_narrowoop()) {
5002 el = el->make_ptr();
5003 }
5004
5005 // Get element klass
5006 if ((tinst = el->isa_instptr()) != NULL) {
5007 // Compute array klass from element klass
5008 k_ary = ciObjArrayKlass::make(tinst->klass());
5009 } else if ((tary = el->isa_aryptr()) != NULL) {
5010 // Compute array klass from element klass
5011 ciKlass* k_elem = tary->klass();
5012 // If element type is something like bottom[], k_elem will be null.
5013 if (k_elem != NULL)
5014 k_ary = ciObjArrayKlass::make(k_elem);
5015 } else if ((el->base() == Type::Top) ||
5016 (el->base() == Type::Bottom)) {
5017 // element type of Bottom occurs from meet of basic type
5018 // and object; Top occurs when doing join on Bottom.
5019 // Leave k_ary at NULL.
5020 } else {
5021 // Cannot compute array klass directly from basic type,
5022 // since subtypes of TypeInt all have basic type T_INT.
5023 #ifdef ASSERT
5024 if (verify && el->isa_int()) {
5025 // Check simple cases when verifying klass.
5026 BasicType bt = T_ILLEGAL;
5027 if (el == TypeInt::BYTE) {
5028 bt = T_BYTE;
5029 } else if (el == TypeInt::SHORT) {
5030 bt = T_SHORT;
5031 } else if (el == TypeInt::CHAR) {
5032 bt = T_CHAR;
5033 } else if (el == TypeInt::INT) {
5034 bt = T_INT;
5035 } else {
5036 return _klass; // just return specified klass
5037 }
5038 return ciTypeArrayKlass::make(bt);
5039 }
5040 #endif
5041 assert(!el->isa_int(),
5042 "integral arrays must be pre-equipped with a class");
5043 // Compute array klass directly from basic type
5044 k_ary = ciTypeArrayKlass::make(el->basic_type());
5045 }
5046 return k_ary;
5047 }
5048
5049 //------------------------------klass------------------------------------------
5050 // Return the defining klass for this class
klass() const5051 ciKlass* TypeAryPtr::klass() const {
5052 if( _klass ) return _klass; // Return cached value, if possible
5053
5054 // Oops, need to compute _klass and cache it
5055 ciKlass* k_ary = compute_klass();
5056
5057 if( this != TypeAryPtr::OOPS && this->dual() != TypeAryPtr::OOPS ) {
5058 // The _klass field acts as a cache of the underlying
5059 // ciKlass for this array type. In order to set the field,
5060 // we need to cast away const-ness.
5061 //
5062 // IMPORTANT NOTE: we *never* set the _klass field for the
5063 // type TypeAryPtr::OOPS. This Type is shared between all
5064 // active compilations. However, the ciKlass which represents
5065 // this Type is *not* shared between compilations, so caching
5066 // this value would result in fetching a dangling pointer.
5067 //
5068 // Recomputing the underlying ciKlass for each request is
5069 // a bit less efficient than caching, but calls to
5070 // TypeAryPtr::OOPS->klass() are not common enough to matter.
5071 ((TypeAryPtr*)this)->_klass = k_ary;
5072 if (UseCompressedOops && k_ary != NULL && k_ary->is_obj_array_klass() &&
5073 _offset != 0 && _offset != arrayOopDesc::length_offset_in_bytes()) {
5074 ((TypeAryPtr*)this)->_is_ptr_to_narrowoop = true;
5075 }
5076 }
5077 return k_ary;
5078 }
5079
5080
5081 //------------------------------add_offset-------------------------------------
5082 // Access internals of klass object
add_offset(intptr_t offset) const5083 const TypePtr *TypeKlassPtr::add_offset( intptr_t offset ) const {
5084 return make( _ptr, klass(), xadd_offset(offset) );
5085 }
5086
5087 //------------------------------cast_to_ptr_type-------------------------------
cast_to_ptr_type(PTR ptr) const5088 const Type *TypeKlassPtr::cast_to_ptr_type(PTR ptr) const {
5089 assert(_base == KlassPtr, "subclass must override cast_to_ptr_type");
5090 if( ptr == _ptr ) return this;
5091 return make(ptr, _klass, _offset);
5092 }
5093
5094
5095 //-----------------------------cast_to_exactness-------------------------------
cast_to_exactness(bool klass_is_exact) const5096 const Type *TypeKlassPtr::cast_to_exactness(bool klass_is_exact) const {
5097 if( klass_is_exact == _klass_is_exact ) return this;
5098 return make(klass_is_exact ? Constant : NotNull, _klass, _offset);
5099 }
5100
5101
5102 //-----------------------------as_instance_type--------------------------------
5103 // Corresponding type for an instance of the given class.
5104 // It will be NotNull, and exact if and only if the klass type is exact.
as_instance_type() const5105 const TypeOopPtr* TypeKlassPtr::as_instance_type() const {
5106 ciKlass* k = klass();
5107 bool xk = klass_is_exact();
5108 //return TypeInstPtr::make(TypePtr::NotNull, k, xk, NULL, 0);
5109 const TypeOopPtr* toop = TypeOopPtr::make_from_klass_raw(k);
5110 guarantee(toop != NULL, "need type for given klass");
5111 toop = toop->cast_to_ptr_type(TypePtr::NotNull)->is_oopptr();
5112 return toop->cast_to_exactness(xk)->is_oopptr();
5113 }
5114
5115
5116 //------------------------------xmeet------------------------------------------
5117 // Compute the MEET of two types, return a new Type object.
xmeet(const Type * t) const5118 const Type *TypeKlassPtr::xmeet( const Type *t ) const {
5119 // Perform a fast test for common case; meeting the same types together.
5120 if( this == t ) return this; // Meeting same type-rep?
5121
5122 // Current "this->_base" is Pointer
5123 switch (t->base()) { // switch on original type
5124
5125 case Int: // Mixing ints & oops happens when javac
5126 case Long: // reuses local variables
5127 case FloatTop:
5128 case FloatCon:
5129 case FloatBot:
5130 case DoubleTop:
5131 case DoubleCon:
5132 case DoubleBot:
5133 case NarrowOop:
5134 case NarrowKlass:
5135 case Bottom: // Ye Olde Default
5136 return Type::BOTTOM;
5137 case Top:
5138 return this;
5139
5140 default: // All else is a mistake
5141 typerr(t);
5142
5143 case AnyPtr: { // Meeting to AnyPtrs
5144 // Found an AnyPtr type vs self-KlassPtr type
5145 const TypePtr *tp = t->is_ptr();
5146 int offset = meet_offset(tp->offset());
5147 PTR ptr = meet_ptr(tp->ptr());
5148 switch (tp->ptr()) {
5149 case TopPTR:
5150 return this;
5151 case Null:
5152 if( ptr == Null ) return TypePtr::make(AnyPtr, ptr, offset, tp->speculative(), tp->inline_depth());
5153 case AnyNull:
5154 return make( ptr, klass(), offset );
5155 case BotPTR:
5156 case NotNull:
5157 return TypePtr::make(AnyPtr, ptr, offset, tp->speculative(), tp->inline_depth());
5158 default: typerr(t);
5159 }
5160 }
5161
5162 case RawPtr:
5163 case MetadataPtr:
5164 case OopPtr:
5165 case AryPtr: // Meet with AryPtr
5166 case InstPtr: // Meet with InstPtr
5167 return TypePtr::BOTTOM;
5168
5169 //
5170 // A-top }
5171 // / | \ } Tops
5172 // B-top A-any C-top }
5173 // | / | \ | } Any-nulls
5174 // B-any | C-any }
5175 // | | |
5176 // B-con A-con C-con } constants; not comparable across classes
5177 // | | |
5178 // B-not | C-not }
5179 // | \ | / | } not-nulls
5180 // B-bot A-not C-bot }
5181 // \ | / } Bottoms
5182 // A-bot }
5183 //
5184
5185 case KlassPtr: { // Meet two KlassPtr types
5186 const TypeKlassPtr *tkls = t->is_klassptr();
5187 int off = meet_offset(tkls->offset());
5188 PTR ptr = meet_ptr(tkls->ptr());
5189
5190 // Check for easy case; klasses are equal (and perhaps not loaded!)
5191 // If we have constants, then we created oops so classes are loaded
5192 // and we can handle the constants further down. This case handles
5193 // not-loaded classes
5194 if( ptr != Constant && tkls->klass()->equals(klass()) ) {
5195 return make( ptr, klass(), off );
5196 }
5197
5198 // Classes require inspection in the Java klass hierarchy. Must be loaded.
5199 ciKlass* tkls_klass = tkls->klass();
5200 ciKlass* this_klass = this->klass();
5201 assert( tkls_klass->is_loaded(), "This class should have been loaded.");
5202 assert( this_klass->is_loaded(), "This class should have been loaded.");
5203
5204 // If 'this' type is above the centerline and is a superclass of the
5205 // other, we can treat 'this' as having the same type as the other.
5206 if ((above_centerline(this->ptr())) &&
5207 tkls_klass->is_subtype_of(this_klass)) {
5208 this_klass = tkls_klass;
5209 }
5210 // If 'tinst' type is above the centerline and is a superclass of the
5211 // other, we can treat 'tinst' as having the same type as the other.
5212 if ((above_centerline(tkls->ptr())) &&
5213 this_klass->is_subtype_of(tkls_klass)) {
5214 tkls_klass = this_klass;
5215 }
5216
5217 // Check for classes now being equal
5218 if (tkls_klass->equals(this_klass)) {
5219 // If the klasses are equal, the constants may still differ. Fall to
5220 // NotNull if they do (neither constant is NULL; that is a special case
5221 // handled elsewhere).
5222 if( ptr == Constant ) {
5223 if (this->_ptr == Constant && tkls->_ptr == Constant &&
5224 this->klass()->equals(tkls->klass()));
5225 else if (above_centerline(this->ptr()));
5226 else if (above_centerline(tkls->ptr()));
5227 else
5228 ptr = NotNull;
5229 }
5230 return make( ptr, this_klass, off );
5231 } // Else classes are not equal
5232
5233 // Since klasses are different, we require the LCA in the Java
5234 // class hierarchy - which means we have to fall to at least NotNull.
5235 if( ptr == TopPTR || ptr == AnyNull || ptr == Constant )
5236 ptr = NotNull;
5237 // Now we find the LCA of Java classes
5238 ciKlass* k = this_klass->least_common_ancestor(tkls_klass);
5239 return make( ptr, k, off );
5240 } // End of case KlassPtr
5241
5242 } // End of switch
5243 return this; // Return the double constant
5244 }
5245
5246 //------------------------------xdual------------------------------------------
5247 // Dual: compute field-by-field dual
xdual() const5248 const Type *TypeKlassPtr::xdual() const {
5249 return new TypeKlassPtr( dual_ptr(), klass(), dual_offset() );
5250 }
5251
5252 //------------------------------get_con----------------------------------------
get_con() const5253 intptr_t TypeKlassPtr::get_con() const {
5254 assert( _ptr == Null || _ptr == Constant, "" );
5255 assert( _offset >= 0, "" );
5256
5257 if (_offset != 0) {
5258 // After being ported to the compiler interface, the compiler no longer
5259 // directly manipulates the addresses of oops. Rather, it only has a pointer
5260 // to a handle at compile time. This handle is embedded in the generated
5261 // code and dereferenced at the time the nmethod is made. Until that time,
5262 // it is not reasonable to do arithmetic with the addresses of oops (we don't
5263 // have access to the addresses!). This does not seem to currently happen,
5264 // but this assertion here is to help prevent its occurence.
5265 tty->print_cr("Found oop constant with non-zero offset");
5266 ShouldNotReachHere();
5267 }
5268
5269 return (intptr_t)klass()->constant_encoding();
5270 }
5271 //------------------------------dump2------------------------------------------
5272 // Dump Klass Type
5273 #ifndef PRODUCT
dump2(Dict & d,uint depth,outputStream * st) const5274 void TypeKlassPtr::dump2( Dict & d, uint depth, outputStream *st ) const {
5275 switch( _ptr ) {
5276 case Constant:
5277 st->print("precise ");
5278 case NotNull:
5279 {
5280 const char *name = klass()->name()->as_utf8();
5281 if( name ) {
5282 st->print("klass %s: " INTPTR_FORMAT, name, p2i(klass()));
5283 } else {
5284 ShouldNotReachHere();
5285 }
5286 }
5287 case BotPTR:
5288 if( !WizardMode && !Verbose && !_klass_is_exact ) break;
5289 case TopPTR:
5290 case AnyNull:
5291 st->print(":%s", ptr_msg[_ptr]);
5292 if( _klass_is_exact ) st->print(":exact");
5293 break;
5294 default:
5295 break;
5296 }
5297
5298 if( _offset ) { // Dump offset, if any
5299 if( _offset == OffsetBot ) { st->print("+any"); }
5300 else if( _offset == OffsetTop ) { st->print("+unknown"); }
5301 else { st->print("+%d", _offset); }
5302 }
5303
5304 st->print(" *");
5305 }
5306 #endif
5307
5308
5309
5310 //=============================================================================
5311 // Convenience common pre-built types.
5312
5313 //------------------------------make-------------------------------------------
make(const TypeTuple * domain,const TypeTuple * range)5314 const TypeFunc *TypeFunc::make( const TypeTuple *domain, const TypeTuple *range ) {
5315 return (TypeFunc*)(new TypeFunc(domain,range))->hashcons();
5316 }
5317
5318 //------------------------------make-------------------------------------------
make(ciMethod * method)5319 const TypeFunc *TypeFunc::make(ciMethod* method) {
5320 Compile* C = Compile::current();
5321 const TypeFunc* tf = C->last_tf(method); // check cache
5322 if (tf != NULL) return tf; // The hit rate here is almost 50%.
5323 const TypeTuple *domain;
5324 if (method->is_static()) {
5325 domain = TypeTuple::make_domain(NULL, method->signature());
5326 } else {
5327 domain = TypeTuple::make_domain(method->holder(), method->signature());
5328 }
5329 const TypeTuple *range = TypeTuple::make_range(method->signature());
5330 tf = TypeFunc::make(domain, range);
5331 C->set_last_tf(method, tf); // fill cache
5332 return tf;
5333 }
5334
5335 //------------------------------meet-------------------------------------------
5336 // Compute the MEET of two types. It returns a new Type object.
xmeet(const Type * t) const5337 const Type *TypeFunc::xmeet( const Type *t ) const {
5338 // Perform a fast test for common case; meeting the same types together.
5339 if( this == t ) return this; // Meeting same type-rep?
5340
5341 // Current "this->_base" is Func
5342 switch (t->base()) { // switch on original type
5343
5344 case Bottom: // Ye Olde Default
5345 return t;
5346
5347 default: // All else is a mistake
5348 typerr(t);
5349
5350 case Top:
5351 break;
5352 }
5353 return this; // Return the double constant
5354 }
5355
5356 //------------------------------xdual------------------------------------------
5357 // Dual: compute field-by-field dual
xdual() const5358 const Type *TypeFunc::xdual() const {
5359 return this;
5360 }
5361
5362 //------------------------------eq---------------------------------------------
5363 // Structural equality check for Type representations
eq(const Type * t) const5364 bool TypeFunc::eq( const Type *t ) const {
5365 const TypeFunc *a = (const TypeFunc*)t;
5366 return _domain == a->_domain &&
5367 _range == a->_range;
5368 }
5369
5370 //------------------------------hash-------------------------------------------
5371 // Type-specific hashing function.
hash(void) const5372 int TypeFunc::hash(void) const {
5373 return (intptr_t)_domain + (intptr_t)_range;
5374 }
5375
5376 //------------------------------dump2------------------------------------------
5377 // Dump Function Type
5378 #ifndef PRODUCT
dump2(Dict & d,uint depth,outputStream * st) const5379 void TypeFunc::dump2( Dict &d, uint depth, outputStream *st ) const {
5380 if( _range->cnt() <= Parms )
5381 st->print("void");
5382 else {
5383 uint i;
5384 for (i = Parms; i < _range->cnt()-1; i++) {
5385 _range->field_at(i)->dump2(d,depth,st);
5386 st->print("/");
5387 }
5388 _range->field_at(i)->dump2(d,depth,st);
5389 }
5390 st->print(" ");
5391 st->print("( ");
5392 if( !depth || d[this] ) { // Check for recursive dump
5393 st->print("...)");
5394 return;
5395 }
5396 d.Insert((void*)this,(void*)this); // Stop recursion
5397 if (Parms < _domain->cnt())
5398 _domain->field_at(Parms)->dump2(d,depth-1,st);
5399 for (uint i = Parms+1; i < _domain->cnt(); i++) {
5400 st->print(", ");
5401 _domain->field_at(i)->dump2(d,depth-1,st);
5402 }
5403 st->print(" )");
5404 }
5405 #endif
5406
5407 //------------------------------singleton--------------------------------------
5408 // TRUE if Type is a singleton type, FALSE otherwise. Singletons are simple
5409 // constants (Ldi nodes). Singletons are integer, float or double constants
5410 // or a single symbol.
singleton(void) const5411 bool TypeFunc::singleton(void) const {
5412 return false; // Never a singleton
5413 }
5414
empty(void) const5415 bool TypeFunc::empty(void) const {
5416 return false; // Never empty
5417 }
5418
5419
return_type() const5420 BasicType TypeFunc::return_type() const{
5421 if (range()->cnt() == TypeFunc::Parms) {
5422 return T_VOID;
5423 }
5424 return range()->field_at(TypeFunc::Parms)->basic_type();
5425 }
5426