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