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