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