Wed, 03 Jul 2019 20:42:37 +0800
Merge
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 */
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/gcLocker.hpp"
33 #include "memory/oopFactory.hpp"
34 #include "memory/resourceArea.hpp"
35 #include "oops/instanceKlass.hpp"
36 #include "oops/instanceMirrorKlass.hpp"
37 #include "oops/objArrayKlass.hpp"
38 #include "oops/typeArrayKlass.hpp"
39 #include "opto/matcher.hpp"
40 #include "opto/node.hpp"
41 #include "opto/opcodes.hpp"
42 #include "opto/type.hpp"
44 PRAGMA_FORMAT_MUTE_WARNINGS_FOR_GCC
46 // Portions of code courtesy of Clifford Click
48 // Optimization - Graph Style
50 // Dictionary of types shared among compilations.
51 Dict* Type::_shared_type_dict = NULL;
53 // Array which maps compiler types to Basic Types
54 const Type::TypeInfo Type::_type_info[Type::lastype] = {
55 { Bad, T_ILLEGAL, "bad", false, Node::NotAMachineReg, relocInfo::none }, // Bad
56 { Control, T_ILLEGAL, "control", false, 0, relocInfo::none }, // Control
57 { Bottom, T_VOID, "top", false, 0, relocInfo::none }, // Top
58 { Bad, T_INT, "int:", false, Op_RegI, relocInfo::none }, // Int
59 { Bad, T_LONG, "long:", false, Op_RegL, relocInfo::none }, // Long
60 { Half, T_VOID, "half", false, 0, relocInfo::none }, // Half
61 { Bad, T_NARROWOOP, "narrowoop:", false, Op_RegN, relocInfo::none }, // NarrowOop
62 { Bad, T_NARROWKLASS,"narrowklass:", false, Op_RegN, relocInfo::none }, // NarrowKlass
63 { Bad, T_ILLEGAL, "tuple:", false, Node::NotAMachineReg, relocInfo::none }, // Tuple
64 { Bad, T_ARRAY, "array:", false, Node::NotAMachineReg, relocInfo::none }, // Array
66 #ifdef SPARC
67 { Bad, T_ILLEGAL, "vectors:", false, 0, relocInfo::none }, // VectorS
68 { Bad, T_ILLEGAL, "vectord:", false, Op_RegD, relocInfo::none }, // VectorD
69 { Bad, T_ILLEGAL, "vectorx:", false, 0, relocInfo::none }, // VectorX
70 { Bad, T_ILLEGAL, "vectory:", false, 0, relocInfo::none }, // VectorY
71 #elif defined(MIPS64)
72 { Bad, T_ILLEGAL, "vectors:", false, 0, relocInfo::none }, // VectorS
73 { Bad, T_ILLEGAL, "vectord:", false, Op_VecD, relocInfo::none }, // VectorD
74 { Bad, T_ILLEGAL, "vectorx:", false, 0, relocInfo::none }, // VectorX
75 { Bad, T_ILLEGAL, "vectory:", false, 0, relocInfo::none }, // VectorY
76 #elif defined(PPC64)
77 { Bad, T_ILLEGAL, "vectors:", false, 0, relocInfo::none }, // VectorS
78 { Bad, T_ILLEGAL, "vectord:", false, Op_RegL, relocInfo::none }, // VectorD
79 { Bad, T_ILLEGAL, "vectorx:", false, 0, relocInfo::none }, // VectorX
80 { Bad, T_ILLEGAL, "vectory:", false, 0, relocInfo::none }, // VectorY
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 #endif
87 { Bad, T_ADDRESS, "anyptr:", false, Op_RegP, relocInfo::none }, // AnyPtr
88 { Bad, T_ADDRESS, "rawptr:", false, Op_RegP, relocInfo::none }, // RawPtr
89 { Bad, T_OBJECT, "oop:", true, Op_RegP, relocInfo::oop_type }, // OopPtr
90 { Bad, T_OBJECT, "inst:", true, Op_RegP, relocInfo::oop_type }, // InstPtr
91 { Bad, T_OBJECT, "ary:", true, Op_RegP, relocInfo::oop_type }, // AryPtr
92 { Bad, T_METADATA, "metadata:", false, Op_RegP, relocInfo::metadata_type }, // MetadataPtr
93 { Bad, T_METADATA, "klass:", false, Op_RegP, relocInfo::metadata_type }, // KlassPtr
94 { Bad, T_OBJECT, "func", false, 0, relocInfo::none }, // Function
95 { Abio, T_ILLEGAL, "abIO", false, 0, relocInfo::none }, // Abio
96 { Return_Address, T_ADDRESS, "return_address",false, Op_RegP, relocInfo::none }, // Return_Address
97 { Memory, T_ILLEGAL, "memory", false, 0, relocInfo::none }, // Memory
98 { FloatBot, T_FLOAT, "float_top", false, Op_RegF, relocInfo::none }, // FloatTop
99 { FloatCon, T_FLOAT, "ftcon:", false, Op_RegF, relocInfo::none }, // FloatCon
100 { FloatTop, T_FLOAT, "float", false, Op_RegF, relocInfo::none }, // FloatBot
101 { DoubleBot, T_DOUBLE, "double_top", false, Op_RegD, relocInfo::none }, // DoubleTop
102 { DoubleCon, T_DOUBLE, "dblcon:", false, Op_RegD, relocInfo::none }, // DoubleCon
103 { DoubleTop, T_DOUBLE, "double", false, Op_RegD, relocInfo::none }, // DoubleBot
104 { Top, T_ILLEGAL, "bottom", false, 0, relocInfo::none } // Bottom
105 };
107 // Map ideal registers (machine types) to ideal types
108 const Type *Type::mreg2type[_last_machine_leaf];
110 // Map basic types to canonical Type* pointers.
111 const Type* Type:: _const_basic_type[T_CONFLICT+1];
113 // Map basic types to constant-zero Types.
114 const Type* Type:: _zero_type[T_CONFLICT+1];
116 // Map basic types to array-body alias types.
117 const TypeAryPtr* TypeAryPtr::_array_body_type[T_CONFLICT+1];
119 //=============================================================================
120 // Convenience common pre-built types.
121 const Type *Type::ABIO; // State-of-machine only
122 const Type *Type::BOTTOM; // All values
123 const Type *Type::CONTROL; // Control only
124 const Type *Type::DOUBLE; // All doubles
125 const Type *Type::FLOAT; // All floats
126 const Type *Type::HALF; // Placeholder half of doublewide type
127 const Type *Type::MEMORY; // Abstract store only
128 const Type *Type::RETURN_ADDRESS;
129 const Type *Type::TOP; // No values in set
131 //------------------------------get_const_type---------------------------
132 const Type* Type::get_const_type(ciType* type) {
133 if (type == NULL) {
134 return NULL;
135 } else if (type->is_primitive_type()) {
136 return get_const_basic_type(type->basic_type());
137 } else {
138 return TypeOopPtr::make_from_klass(type->as_klass());
139 }
140 }
142 //---------------------------array_element_basic_type---------------------------------
143 // Mapping to the array element's basic type.
144 BasicType Type::array_element_basic_type() const {
145 BasicType bt = basic_type();
146 if (bt == T_INT) {
147 if (this == TypeInt::INT) return T_INT;
148 if (this == TypeInt::CHAR) return T_CHAR;
149 if (this == TypeInt::BYTE) return T_BYTE;
150 if (this == TypeInt::BOOL) return T_BOOLEAN;
151 if (this == TypeInt::SHORT) return T_SHORT;
152 return T_VOID;
153 }
154 return bt;
155 }
157 // For two instance arrays of same dimension, return the base element types.
158 // Otherwise or if the arrays have different dimensions, return NULL.
159 void Type::get_arrays_base_elements(const Type *a1, const Type *a2,
160 const TypeInstPtr **e1, const TypeInstPtr **e2) {
162 if (e1) *e1 = NULL;
163 if (e2) *e2 = NULL;
164 const TypeAryPtr* a1tap = (a1 == NULL) ? NULL : a1->isa_aryptr();
165 const TypeAryPtr* a2tap = (a2 == NULL) ? NULL : a2->isa_aryptr();
167 if (a1tap != NULL && a2tap != NULL) {
168 // Handle multidimensional arrays
169 const TypePtr* a1tp = a1tap->elem()->make_ptr();
170 const TypePtr* a2tp = a2tap->elem()->make_ptr();
171 while (a1tp && a1tp->isa_aryptr() && a2tp && a2tp->isa_aryptr()) {
172 a1tap = a1tp->is_aryptr();
173 a2tap = a2tp->is_aryptr();
174 a1tp = a1tap->elem()->make_ptr();
175 a2tp = a2tap->elem()->make_ptr();
176 }
177 if (a1tp && a1tp->isa_instptr() && a2tp && a2tp->isa_instptr()) {
178 if (e1) *e1 = a1tp->is_instptr();
179 if (e2) *e2 = a2tp->is_instptr();
180 }
181 }
182 }
184 //---------------------------get_typeflow_type---------------------------------
185 // Import a type produced by ciTypeFlow.
186 const Type* Type::get_typeflow_type(ciType* type) {
187 switch (type->basic_type()) {
189 case ciTypeFlow::StateVector::T_BOTTOM:
190 assert(type == ciTypeFlow::StateVector::bottom_type(), "");
191 return Type::BOTTOM;
193 case ciTypeFlow::StateVector::T_TOP:
194 assert(type == ciTypeFlow::StateVector::top_type(), "");
195 return Type::TOP;
197 case ciTypeFlow::StateVector::T_NULL:
198 assert(type == ciTypeFlow::StateVector::null_type(), "");
199 return TypePtr::NULL_PTR;
201 case ciTypeFlow::StateVector::T_LONG2:
202 // The ciTypeFlow pass pushes a long, then the half.
203 // We do the same.
204 assert(type == ciTypeFlow::StateVector::long2_type(), "");
205 return TypeInt::TOP;
207 case ciTypeFlow::StateVector::T_DOUBLE2:
208 // The ciTypeFlow pass pushes double, then the half.
209 // Our convention is the same.
210 assert(type == ciTypeFlow::StateVector::double2_type(), "");
211 return Type::TOP;
213 case T_ADDRESS:
214 assert(type->is_return_address(), "");
215 return TypeRawPtr::make((address)(intptr_t)type->as_return_address()->bci());
217 default:
218 // make sure we did not mix up the cases:
219 assert(type != ciTypeFlow::StateVector::bottom_type(), "");
220 assert(type != ciTypeFlow::StateVector::top_type(), "");
221 assert(type != ciTypeFlow::StateVector::null_type(), "");
222 assert(type != ciTypeFlow::StateVector::long2_type(), "");
223 assert(type != ciTypeFlow::StateVector::double2_type(), "");
224 assert(!type->is_return_address(), "");
226 return Type::get_const_type(type);
227 }
228 }
231 //-----------------------make_from_constant------------------------------------
232 const Type* Type::make_from_constant(ciConstant constant,
233 bool require_constant, bool is_autobox_cache) {
234 switch (constant.basic_type()) {
235 case T_BOOLEAN: return TypeInt::make(constant.as_boolean());
236 case T_CHAR: return TypeInt::make(constant.as_char());
237 case T_BYTE: return TypeInt::make(constant.as_byte());
238 case T_SHORT: return TypeInt::make(constant.as_short());
239 case T_INT: return TypeInt::make(constant.as_int());
240 case T_LONG: return TypeLong::make(constant.as_long());
241 case T_FLOAT: return TypeF::make(constant.as_float());
242 case T_DOUBLE: return TypeD::make(constant.as_double());
243 case T_ARRAY:
244 case T_OBJECT:
245 {
246 // cases:
247 // can_be_constant = (oop not scavengable || ScavengeRootsInCode != 0)
248 // should_be_constant = (oop not scavengable || ScavengeRootsInCode >= 2)
249 // An oop is not scavengable if it is in the perm gen.
250 ciObject* oop_constant = constant.as_object();
251 if (oop_constant->is_null_object()) {
252 return Type::get_zero_type(T_OBJECT);
253 } else if (require_constant || oop_constant->should_be_constant()) {
254 return TypeOopPtr::make_from_constant(oop_constant, require_constant, is_autobox_cache);
255 }
256 }
257 }
258 // Fall through to failure
259 return NULL;
260 }
263 //------------------------------make-------------------------------------------
264 // Create a simple Type, with default empty symbol sets. Then hashcons it
265 // and look for an existing copy in the type dictionary.
266 const Type *Type::make( enum TYPES t ) {
267 return (new Type(t))->hashcons();
268 }
270 //------------------------------cmp--------------------------------------------
271 int Type::cmp( const Type *const t1, const Type *const t2 ) {
272 if( t1->_base != t2->_base )
273 return 1; // Missed badly
274 assert(t1 != t2 || t1->eq(t2), "eq must be reflexive");
275 return !t1->eq(t2); // Return ZERO if equal
276 }
278 const Type* Type::maybe_remove_speculative(bool include_speculative) const {
279 if (!include_speculative) {
280 return remove_speculative();
281 }
282 return this;
283 }
285 //------------------------------hash-------------------------------------------
286 int Type::uhash( const Type *const t ) {
287 return t->hash();
288 }
290 #define SMALLINT ((juint)3) // a value too insignificant to consider widening
292 //--------------------------Initialize_shared----------------------------------
293 void Type::Initialize_shared(Compile* current) {
294 // This method does not need to be locked because the first system
295 // compilations (stub compilations) occur serially. If they are
296 // changed to proceed in parallel, then this section will need
297 // locking.
299 Arena* save = current->type_arena();
300 Arena* shared_type_arena = new (mtCompiler)Arena(mtCompiler);
302 current->set_type_arena(shared_type_arena);
303 _shared_type_dict =
304 new (shared_type_arena) Dict( (CmpKey)Type::cmp, (Hash)Type::uhash,
305 shared_type_arena, 128 );
306 current->set_type_dict(_shared_type_dict);
308 // Make shared pre-built types.
309 CONTROL = make(Control); // Control only
310 TOP = make(Top); // No values in set
311 MEMORY = make(Memory); // Abstract store only
312 ABIO = make(Abio); // State-of-machine only
313 RETURN_ADDRESS=make(Return_Address);
314 FLOAT = make(FloatBot); // All floats
315 DOUBLE = make(DoubleBot); // All doubles
316 BOTTOM = make(Bottom); // Everything
317 HALF = make(Half); // Placeholder half of doublewide type
319 TypeF::ZERO = TypeF::make(0.0); // Float 0 (positive zero)
320 TypeF::ONE = TypeF::make(1.0); // Float 1
322 TypeD::ZERO = TypeD::make(0.0); // Double 0 (positive zero)
323 TypeD::ONE = TypeD::make(1.0); // Double 1
325 TypeInt::MINUS_1 = TypeInt::make(-1); // -1
326 TypeInt::ZERO = TypeInt::make( 0); // 0
327 TypeInt::ONE = TypeInt::make( 1); // 1
328 TypeInt::BOOL = TypeInt::make(0,1, WidenMin); // 0 or 1, FALSE or TRUE.
329 TypeInt::CC = TypeInt::make(-1, 1, WidenMin); // -1, 0 or 1, condition codes
330 TypeInt::CC_LT = TypeInt::make(-1,-1, WidenMin); // == TypeInt::MINUS_1
331 TypeInt::CC_GT = TypeInt::make( 1, 1, WidenMin); // == TypeInt::ONE
332 TypeInt::CC_EQ = TypeInt::make( 0, 0, WidenMin); // == TypeInt::ZERO
333 TypeInt::CC_LE = TypeInt::make(-1, 0, WidenMin);
334 TypeInt::CC_GE = TypeInt::make( 0, 1, WidenMin); // == TypeInt::BOOL
335 TypeInt::BYTE = TypeInt::make(-128,127, WidenMin); // Bytes
336 TypeInt::UBYTE = TypeInt::make(0, 255, WidenMin); // Unsigned Bytes
337 TypeInt::CHAR = TypeInt::make(0,65535, WidenMin); // Java chars
338 TypeInt::SHORT = TypeInt::make(-32768,32767, WidenMin); // Java shorts
339 TypeInt::POS = TypeInt::make(0,max_jint, WidenMin); // Non-neg values
340 TypeInt::POS1 = TypeInt::make(1,max_jint, WidenMin); // Positive values
341 TypeInt::INT = TypeInt::make(min_jint,max_jint, WidenMax); // 32-bit integers
342 TypeInt::SYMINT = TypeInt::make(-max_jint,max_jint,WidenMin); // symmetric range
343 TypeInt::TYPE_DOMAIN = TypeInt::INT;
344 // CmpL is overloaded both as the bytecode computation returning
345 // a trinary (-1,0,+1) integer result AND as an efficient long
346 // compare returning optimizer ideal-type flags.
347 assert( TypeInt::CC_LT == TypeInt::MINUS_1, "types must match for CmpL to work" );
348 assert( TypeInt::CC_GT == TypeInt::ONE, "types must match for CmpL to work" );
349 assert( TypeInt::CC_EQ == TypeInt::ZERO, "types must match for CmpL to work" );
350 assert( TypeInt::CC_GE == TypeInt::BOOL, "types must match for CmpL to work" );
351 assert( (juint)(TypeInt::CC->_hi - TypeInt::CC->_lo) <= SMALLINT, "CC is truly small");
353 TypeLong::MINUS_1 = TypeLong::make(-1); // -1
354 TypeLong::ZERO = TypeLong::make( 0); // 0
355 TypeLong::ONE = TypeLong::make( 1); // 1
356 TypeLong::POS = TypeLong::make(0,max_jlong, WidenMin); // Non-neg values
357 TypeLong::LONG = TypeLong::make(min_jlong,max_jlong,WidenMax); // 64-bit integers
358 TypeLong::INT = TypeLong::make((jlong)min_jint,(jlong)max_jint,WidenMin);
359 TypeLong::UINT = TypeLong::make(0,(jlong)max_juint,WidenMin);
360 TypeLong::TYPE_DOMAIN = TypeLong::LONG;
362 const Type **fboth =(const Type**)shared_type_arena->Amalloc_4(2*sizeof(Type*));
363 fboth[0] = Type::CONTROL;
364 fboth[1] = Type::CONTROL;
365 TypeTuple::IFBOTH = TypeTuple::make( 2, fboth );
367 const Type **ffalse =(const Type**)shared_type_arena->Amalloc_4(2*sizeof(Type*));
368 ffalse[0] = Type::CONTROL;
369 ffalse[1] = Type::TOP;
370 TypeTuple::IFFALSE = TypeTuple::make( 2, ffalse );
372 const Type **fneither =(const Type**)shared_type_arena->Amalloc_4(2*sizeof(Type*));
373 fneither[0] = Type::TOP;
374 fneither[1] = Type::TOP;
375 TypeTuple::IFNEITHER = TypeTuple::make( 2, fneither );
377 const Type **ftrue =(const Type**)shared_type_arena->Amalloc_4(2*sizeof(Type*));
378 ftrue[0] = Type::TOP;
379 ftrue[1] = Type::CONTROL;
380 TypeTuple::IFTRUE = TypeTuple::make( 2, ftrue );
382 const Type **floop =(const Type**)shared_type_arena->Amalloc_4(2*sizeof(Type*));
383 floop[0] = Type::CONTROL;
384 floop[1] = TypeInt::INT;
385 TypeTuple::LOOPBODY = TypeTuple::make( 2, floop );
387 TypePtr::NULL_PTR= TypePtr::make( AnyPtr, TypePtr::Null, 0 );
388 TypePtr::NOTNULL = TypePtr::make( AnyPtr, TypePtr::NotNull, OffsetBot );
389 TypePtr::BOTTOM = TypePtr::make( AnyPtr, TypePtr::BotPTR, OffsetBot );
391 TypeRawPtr::BOTTOM = TypeRawPtr::make( TypePtr::BotPTR );
392 TypeRawPtr::NOTNULL= TypeRawPtr::make( TypePtr::NotNull );
394 const Type **fmembar = TypeTuple::fields(0);
395 TypeTuple::MEMBAR = TypeTuple::make(TypeFunc::Parms+0, fmembar);
397 const Type **fsc = (const Type**)shared_type_arena->Amalloc_4(2*sizeof(Type*));
398 fsc[0] = TypeInt::CC;
399 fsc[1] = Type::MEMORY;
400 TypeTuple::STORECONDITIONAL = TypeTuple::make(2, fsc);
402 TypeInstPtr::NOTNULL = TypeInstPtr::make(TypePtr::NotNull, current->env()->Object_klass());
403 TypeInstPtr::BOTTOM = TypeInstPtr::make(TypePtr::BotPTR, current->env()->Object_klass());
404 TypeInstPtr::MIRROR = TypeInstPtr::make(TypePtr::NotNull, current->env()->Class_klass());
405 TypeInstPtr::MARK = TypeInstPtr::make(TypePtr::BotPTR, current->env()->Object_klass(),
406 false, 0, oopDesc::mark_offset_in_bytes());
407 TypeInstPtr::KLASS = TypeInstPtr::make(TypePtr::BotPTR, current->env()->Object_klass(),
408 false, 0, oopDesc::klass_offset_in_bytes());
409 TypeOopPtr::BOTTOM = TypeOopPtr::make(TypePtr::BotPTR, OffsetBot, TypeOopPtr::InstanceBot, NULL);
411 TypeMetadataPtr::BOTTOM = TypeMetadataPtr::make(TypePtr::BotPTR, NULL, OffsetBot);
413 TypeNarrowOop::NULL_PTR = TypeNarrowOop::make( TypePtr::NULL_PTR );
414 TypeNarrowOop::BOTTOM = TypeNarrowOop::make( TypeInstPtr::BOTTOM );
416 TypeNarrowKlass::NULL_PTR = TypeNarrowKlass::make( TypePtr::NULL_PTR );
418 mreg2type[Op_Node] = Type::BOTTOM;
419 mreg2type[Op_Set ] = 0;
420 mreg2type[Op_RegN] = TypeNarrowOop::BOTTOM;
421 mreg2type[Op_RegI] = TypeInt::INT;
422 mreg2type[Op_RegP] = TypePtr::BOTTOM;
423 mreg2type[Op_RegF] = Type::FLOAT;
424 mreg2type[Op_RegD] = Type::DOUBLE;
425 mreg2type[Op_RegL] = TypeLong::LONG;
426 mreg2type[Op_RegFlags] = TypeInt::CC;
428 TypeAryPtr::RANGE = TypeAryPtr::make( TypePtr::BotPTR, TypeAry::make(Type::BOTTOM,TypeInt::POS), NULL /* current->env()->Object_klass() */, false, arrayOopDesc::length_offset_in_bytes());
430 TypeAryPtr::NARROWOOPS = TypeAryPtr::make(TypePtr::BotPTR, TypeAry::make(TypeNarrowOop::BOTTOM, TypeInt::POS), NULL /*ciArrayKlass::make(o)*/, false, Type::OffsetBot);
432 #ifdef _LP64
433 if (UseCompressedOops) {
434 assert(TypeAryPtr::NARROWOOPS->is_ptr_to_narrowoop(), "array of narrow oops must be ptr to narrow oop");
435 TypeAryPtr::OOPS = TypeAryPtr::NARROWOOPS;
436 } else
437 #endif
438 {
439 // There is no shared klass for Object[]. See note in TypeAryPtr::klass().
440 TypeAryPtr::OOPS = TypeAryPtr::make(TypePtr::BotPTR, TypeAry::make(TypeInstPtr::BOTTOM,TypeInt::POS), NULL /*ciArrayKlass::make(o)*/, false, Type::OffsetBot);
441 }
442 TypeAryPtr::BYTES = TypeAryPtr::make(TypePtr::BotPTR, TypeAry::make(TypeInt::BYTE ,TypeInt::POS), ciTypeArrayKlass::make(T_BYTE), true, Type::OffsetBot);
443 TypeAryPtr::SHORTS = TypeAryPtr::make(TypePtr::BotPTR, TypeAry::make(TypeInt::SHORT ,TypeInt::POS), ciTypeArrayKlass::make(T_SHORT), true, Type::OffsetBot);
444 TypeAryPtr::CHARS = TypeAryPtr::make(TypePtr::BotPTR, TypeAry::make(TypeInt::CHAR ,TypeInt::POS), ciTypeArrayKlass::make(T_CHAR), true, Type::OffsetBot);
445 TypeAryPtr::INTS = TypeAryPtr::make(TypePtr::BotPTR, TypeAry::make(TypeInt::INT ,TypeInt::POS), ciTypeArrayKlass::make(T_INT), true, Type::OffsetBot);
446 TypeAryPtr::LONGS = TypeAryPtr::make(TypePtr::BotPTR, TypeAry::make(TypeLong::LONG ,TypeInt::POS), ciTypeArrayKlass::make(T_LONG), true, Type::OffsetBot);
447 TypeAryPtr::FLOATS = TypeAryPtr::make(TypePtr::BotPTR, TypeAry::make(Type::FLOAT ,TypeInt::POS), ciTypeArrayKlass::make(T_FLOAT), true, Type::OffsetBot);
448 TypeAryPtr::DOUBLES = TypeAryPtr::make(TypePtr::BotPTR, TypeAry::make(Type::DOUBLE ,TypeInt::POS), ciTypeArrayKlass::make(T_DOUBLE), true, Type::OffsetBot);
450 // Nobody should ask _array_body_type[T_NARROWOOP]. Use NULL as assert.
451 TypeAryPtr::_array_body_type[T_NARROWOOP] = NULL;
452 TypeAryPtr::_array_body_type[T_OBJECT] = TypeAryPtr::OOPS;
453 TypeAryPtr::_array_body_type[T_ARRAY] = TypeAryPtr::OOPS; // arrays are stored in oop arrays
454 TypeAryPtr::_array_body_type[T_BYTE] = TypeAryPtr::BYTES;
455 TypeAryPtr::_array_body_type[T_BOOLEAN] = TypeAryPtr::BYTES; // boolean[] is a byte array
456 TypeAryPtr::_array_body_type[T_SHORT] = TypeAryPtr::SHORTS;
457 TypeAryPtr::_array_body_type[T_CHAR] = TypeAryPtr::CHARS;
458 TypeAryPtr::_array_body_type[T_INT] = TypeAryPtr::INTS;
459 TypeAryPtr::_array_body_type[T_LONG] = TypeAryPtr::LONGS;
460 TypeAryPtr::_array_body_type[T_FLOAT] = TypeAryPtr::FLOATS;
461 TypeAryPtr::_array_body_type[T_DOUBLE] = TypeAryPtr::DOUBLES;
463 TypeKlassPtr::OBJECT = TypeKlassPtr::make( TypePtr::NotNull, current->env()->Object_klass(), 0 );
464 TypeKlassPtr::OBJECT_OR_NULL = TypeKlassPtr::make( TypePtr::BotPTR, current->env()->Object_klass(), 0 );
466 const Type **fi2c = TypeTuple::fields(2);
467 fi2c[TypeFunc::Parms+0] = TypeInstPtr::BOTTOM; // Method*
468 fi2c[TypeFunc::Parms+1] = TypeRawPtr::BOTTOM; // argument pointer
469 TypeTuple::START_I2C = TypeTuple::make(TypeFunc::Parms+2, fi2c);
471 const Type **intpair = TypeTuple::fields(2);
472 intpair[0] = TypeInt::INT;
473 intpair[1] = TypeInt::INT;
474 TypeTuple::INT_PAIR = TypeTuple::make(2, intpair);
476 const Type **longpair = TypeTuple::fields(2);
477 longpair[0] = TypeLong::LONG;
478 longpair[1] = TypeLong::LONG;
479 TypeTuple::LONG_PAIR = TypeTuple::make(2, longpair);
481 const Type **intccpair = TypeTuple::fields(2);
482 intccpair[0] = TypeInt::INT;
483 intccpair[1] = TypeInt::CC;
484 TypeTuple::INT_CC_PAIR = TypeTuple::make(2, intccpair);
486 const Type **longccpair = TypeTuple::fields(2);
487 longccpair[0] = TypeLong::LONG;
488 longccpair[1] = TypeInt::CC;
489 TypeTuple::LONG_CC_PAIR = TypeTuple::make(2, longccpair);
491 _const_basic_type[T_NARROWOOP] = TypeNarrowOop::BOTTOM;
492 _const_basic_type[T_NARROWKLASS] = Type::BOTTOM;
493 _const_basic_type[T_BOOLEAN] = TypeInt::BOOL;
494 _const_basic_type[T_CHAR] = TypeInt::CHAR;
495 _const_basic_type[T_BYTE] = TypeInt::BYTE;
496 _const_basic_type[T_SHORT] = TypeInt::SHORT;
497 _const_basic_type[T_INT] = TypeInt::INT;
498 _const_basic_type[T_LONG] = TypeLong::LONG;
499 _const_basic_type[T_FLOAT] = Type::FLOAT;
500 _const_basic_type[T_DOUBLE] = Type::DOUBLE;
501 _const_basic_type[T_OBJECT] = TypeInstPtr::BOTTOM;
502 _const_basic_type[T_ARRAY] = TypeInstPtr::BOTTOM; // there is no separate bottom for arrays
503 _const_basic_type[T_VOID] = TypePtr::NULL_PTR; // reflection represents void this way
504 _const_basic_type[T_ADDRESS] = TypeRawPtr::BOTTOM; // both interpreter return addresses & random raw ptrs
505 _const_basic_type[T_CONFLICT] = Type::BOTTOM; // why not?
507 _zero_type[T_NARROWOOP] = TypeNarrowOop::NULL_PTR;
508 _zero_type[T_NARROWKLASS] = TypeNarrowKlass::NULL_PTR;
509 _zero_type[T_BOOLEAN] = TypeInt::ZERO; // false == 0
510 _zero_type[T_CHAR] = TypeInt::ZERO; // '\0' == 0
511 _zero_type[T_BYTE] = TypeInt::ZERO; // 0x00 == 0
512 _zero_type[T_SHORT] = TypeInt::ZERO; // 0x0000 == 0
513 _zero_type[T_INT] = TypeInt::ZERO;
514 _zero_type[T_LONG] = TypeLong::ZERO;
515 _zero_type[T_FLOAT] = TypeF::ZERO;
516 _zero_type[T_DOUBLE] = TypeD::ZERO;
517 _zero_type[T_OBJECT] = TypePtr::NULL_PTR;
518 _zero_type[T_ARRAY] = TypePtr::NULL_PTR; // null array is null oop
519 _zero_type[T_ADDRESS] = TypePtr::NULL_PTR; // raw pointers use the same null
520 _zero_type[T_VOID] = Type::TOP; // the only void value is no value at all
522 // get_zero_type() should not happen for T_CONFLICT
523 _zero_type[T_CONFLICT]= NULL;
525 // Vector predefined types, it needs initialized _const_basic_type[].
526 if (Matcher::vector_size_supported(T_BYTE,4)) {
527 TypeVect::VECTS = TypeVect::make(T_BYTE,4);
528 }
529 if (Matcher::vector_size_supported(T_FLOAT,2)) {
530 TypeVect::VECTD = TypeVect::make(T_FLOAT,2);
531 }
532 if (Matcher::vector_size_supported(T_FLOAT,4)) {
533 TypeVect::VECTX = TypeVect::make(T_FLOAT,4);
534 }
535 if (Matcher::vector_size_supported(T_FLOAT,8)) {
536 TypeVect::VECTY = TypeVect::make(T_FLOAT,8);
537 }
538 mreg2type[Op_VecS] = TypeVect::VECTS;
539 mreg2type[Op_VecD] = TypeVect::VECTD;
540 mreg2type[Op_VecX] = TypeVect::VECTX;
541 mreg2type[Op_VecY] = TypeVect::VECTY;
543 // Restore working type arena.
544 current->set_type_arena(save);
545 current->set_type_dict(NULL);
546 }
548 //------------------------------Initialize-------------------------------------
549 void Type::Initialize(Compile* current) {
550 assert(current->type_arena() != NULL, "must have created type arena");
552 if (_shared_type_dict == NULL) {
553 Initialize_shared(current);
554 }
556 Arena* type_arena = current->type_arena();
558 // Create the hash-cons'ing dictionary with top-level storage allocation
559 Dict *tdic = new (type_arena) Dict( (CmpKey)Type::cmp,(Hash)Type::uhash, type_arena, 128 );
560 current->set_type_dict(tdic);
562 // Transfer the shared types.
563 DictI i(_shared_type_dict);
564 for( ; i.test(); ++i ) {
565 Type* t = (Type*)i._value;
566 tdic->Insert(t,t); // New Type, insert into Type table
567 }
568 }
570 //------------------------------hashcons---------------------------------------
571 // Do the hash-cons trick. If the Type already exists in the type table,
572 // delete the current Type and return the existing Type. Otherwise stick the
573 // current Type in the Type table.
574 const Type *Type::hashcons(void) {
575 debug_only(base()); // Check the assertion in Type::base().
576 // Look up the Type in the Type dictionary
577 Dict *tdic = type_dict();
578 Type* old = (Type*)(tdic->Insert(this, this, false));
579 if( old ) { // Pre-existing Type?
580 if( old != this ) // Yes, this guy is not the pre-existing?
581 delete this; // Yes, Nuke this guy
582 assert( old->_dual, "" );
583 return old; // Return pre-existing
584 }
586 // Every type has a dual (to make my lattice symmetric).
587 // Since we just discovered a new Type, compute its dual right now.
588 assert( !_dual, "" ); // No dual yet
589 _dual = xdual(); // Compute the dual
590 if( cmp(this,_dual)==0 ) { // Handle self-symmetric
591 _dual = this;
592 return this;
593 }
594 assert( !_dual->_dual, "" ); // No reverse dual yet
595 assert( !(*tdic)[_dual], "" ); // Dual not in type system either
596 // New Type, insert into Type table
597 tdic->Insert((void*)_dual,(void*)_dual);
598 ((Type*)_dual)->_dual = this; // Finish up being symmetric
599 #ifdef ASSERT
600 Type *dual_dual = (Type*)_dual->xdual();
601 assert( eq(dual_dual), "xdual(xdual()) should be identity" );
602 delete dual_dual;
603 #endif
604 return this; // Return new Type
605 }
607 //------------------------------eq---------------------------------------------
608 // Structural equality check for Type representations
609 bool Type::eq( const Type * ) const {
610 return true; // Nothing else can go wrong
611 }
613 //------------------------------hash-------------------------------------------
614 // Type-specific hashing function.
615 int Type::hash(void) const {
616 return _base;
617 }
619 //------------------------------is_finite--------------------------------------
620 // Has a finite value
621 bool Type::is_finite() const {
622 return false;
623 }
625 //------------------------------is_nan-----------------------------------------
626 // Is not a number (NaN)
627 bool Type::is_nan() const {
628 return false;
629 }
631 //----------------------interface_vs_oop---------------------------------------
632 #ifdef ASSERT
633 bool Type::interface_vs_oop_helper(const Type *t) const {
634 bool result = false;
636 const TypePtr* this_ptr = this->make_ptr(); // In case it is narrow_oop
637 const TypePtr* t_ptr = t->make_ptr();
638 if( this_ptr == NULL || t_ptr == NULL )
639 return result;
641 const TypeInstPtr* this_inst = this_ptr->isa_instptr();
642 const TypeInstPtr* t_inst = t_ptr->isa_instptr();
643 if( this_inst && this_inst->is_loaded() && t_inst && t_inst->is_loaded() ) {
644 bool this_interface = this_inst->klass()->is_interface();
645 bool t_interface = t_inst->klass()->is_interface();
646 result = this_interface ^ t_interface;
647 }
649 return result;
650 }
652 bool Type::interface_vs_oop(const Type *t) const {
653 if (interface_vs_oop_helper(t)) {
654 return true;
655 }
656 // Now check the speculative parts as well
657 const TypeOopPtr* this_spec = isa_oopptr() != NULL ? isa_oopptr()->speculative() : NULL;
658 const TypeOopPtr* t_spec = t->isa_oopptr() != NULL ? t->isa_oopptr()->speculative() : NULL;
659 if (this_spec != NULL && t_spec != NULL) {
660 if (this_spec->interface_vs_oop_helper(t_spec)) {
661 return true;
662 }
663 return false;
664 }
665 if (this_spec != NULL && this_spec->interface_vs_oop_helper(t)) {
666 return true;
667 }
668 if (t_spec != NULL && interface_vs_oop_helper(t_spec)) {
669 return true;
670 }
671 return false;
672 }
674 #endif
676 //------------------------------meet-------------------------------------------
677 // Compute the MEET of two types. NOT virtual. It enforces that meet is
678 // commutative and the lattice is symmetric.
679 const Type *Type::meet_helper(const Type *t, bool include_speculative) const {
680 if (isa_narrowoop() && t->isa_narrowoop()) {
681 const Type* result = make_ptr()->meet_helper(t->make_ptr(), include_speculative);
682 return result->make_narrowoop();
683 }
684 if (isa_narrowklass() && t->isa_narrowklass()) {
685 const Type* result = make_ptr()->meet_helper(t->make_ptr(), include_speculative);
686 return result->make_narrowklass();
687 }
689 const Type *this_t = maybe_remove_speculative(include_speculative);
690 t = t->maybe_remove_speculative(include_speculative);
692 const Type *mt = this_t->xmeet(t);
693 if (isa_narrowoop() || t->isa_narrowoop()) return mt;
694 if (isa_narrowklass() || t->isa_narrowklass()) return mt;
695 #ifdef ASSERT
696 assert(mt == t->xmeet(this_t), "meet not commutative");
697 const Type* dual_join = mt->_dual;
698 const Type *t2t = dual_join->xmeet(t->_dual);
699 const Type *t2this = dual_join->xmeet(this_t->_dual);
701 // Interface meet Oop is Not Symmetric:
702 // Interface:AnyNull meet Oop:AnyNull == Interface:AnyNull
703 // Interface:NotNull meet Oop:NotNull == java/lang/Object:NotNull
705 if( !interface_vs_oop(t) && (t2t != t->_dual || t2this != this_t->_dual) ) {
706 tty->print_cr("=== Meet Not Symmetric ===");
707 tty->print("t = "); t->dump(); tty->cr();
708 tty->print("this= "); this_t->dump(); tty->cr();
709 tty->print("mt=(t meet this)= "); mt->dump(); tty->cr();
711 tty->print("t_dual= "); t->_dual->dump(); tty->cr();
712 tty->print("this_dual= "); this_t->_dual->dump(); tty->cr();
713 tty->print("mt_dual= "); mt->_dual->dump(); tty->cr();
715 tty->print("mt_dual meet t_dual= "); t2t ->dump(); tty->cr();
716 tty->print("mt_dual meet this_dual= "); t2this ->dump(); tty->cr();
718 fatal("meet not symmetric" );
719 }
720 #endif
721 return mt;
722 }
724 //------------------------------xmeet------------------------------------------
725 // Compute the MEET of two types. It returns a new Type object.
726 const Type *Type::xmeet( const Type *t ) const {
727 // Perform a fast test for common case; meeting the same types together.
728 if( this == t ) return this; // Meeting same type-rep?
730 // Meeting TOP with anything?
731 if( _base == Top ) return t;
733 // Meeting BOTTOM with anything?
734 if( _base == Bottom ) return BOTTOM;
736 // Current "this->_base" is one of: Bad, Multi, Control, Top,
737 // Abio, Abstore, Floatxxx, Doublexxx, Bottom, lastype.
738 switch (t->base()) { // Switch on original type
740 // Cut in half the number of cases I must handle. Only need cases for when
741 // the given enum "t->type" is less than or equal to the local enum "type".
742 case FloatCon:
743 case DoubleCon:
744 case Int:
745 case Long:
746 return t->xmeet(this);
748 case OopPtr:
749 return t->xmeet(this);
751 case InstPtr:
752 return t->xmeet(this);
754 case MetadataPtr:
755 case KlassPtr:
756 return t->xmeet(this);
758 case AryPtr:
759 return t->xmeet(this);
761 case NarrowOop:
762 return t->xmeet(this);
764 case NarrowKlass:
765 return t->xmeet(this);
767 case Bad: // Type check
768 default: // Bogus type not in lattice
769 typerr(t);
770 return Type::BOTTOM;
772 case Bottom: // Ye Olde Default
773 return t;
775 case FloatTop:
776 if( _base == FloatTop ) return this;
777 case FloatBot: // Float
778 if( _base == FloatBot || _base == FloatTop ) return FLOAT;
779 if( _base == DoubleTop || _base == DoubleBot ) return Type::BOTTOM;
780 typerr(t);
781 return Type::BOTTOM;
783 case DoubleTop:
784 if( _base == DoubleTop ) return this;
785 case DoubleBot: // Double
786 if( _base == DoubleBot || _base == DoubleTop ) return DOUBLE;
787 if( _base == FloatTop || _base == FloatBot ) return Type::BOTTOM;
788 typerr(t);
789 return Type::BOTTOM;
791 // These next few cases must match exactly or it is a compile-time error.
792 case Control: // Control of code
793 case Abio: // State of world outside of program
794 case Memory:
795 if( _base == t->_base ) return this;
796 typerr(t);
797 return Type::BOTTOM;
799 case Top: // Top of the lattice
800 return this;
801 }
803 // The type is unchanged
804 return this;
805 }
807 //-----------------------------filter------------------------------------------
808 const Type *Type::filter_helper(const Type *kills, bool include_speculative) const {
809 const Type* ft = join_helper(kills, include_speculative);
810 if (ft->empty())
811 return Type::TOP; // Canonical empty value
812 return ft;
813 }
815 //------------------------------xdual------------------------------------------
816 // Compute dual right now.
817 const Type::TYPES Type::dual_type[Type::lastype] = {
818 Bad, // Bad
819 Control, // Control
820 Bottom, // Top
821 Bad, // Int - handled in v-call
822 Bad, // Long - handled in v-call
823 Half, // Half
824 Bad, // NarrowOop - handled in v-call
825 Bad, // NarrowKlass - handled in v-call
827 Bad, // Tuple - handled in v-call
828 Bad, // Array - handled in v-call
829 Bad, // VectorS - handled in v-call
830 Bad, // VectorD - handled in v-call
831 Bad, // VectorX - handled in v-call
832 Bad, // VectorY - handled in v-call
834 Bad, // AnyPtr - handled in v-call
835 Bad, // RawPtr - handled in v-call
836 Bad, // OopPtr - handled in v-call
837 Bad, // InstPtr - handled in v-call
838 Bad, // AryPtr - handled in v-call
840 Bad, // MetadataPtr - handled in v-call
841 Bad, // KlassPtr - handled in v-call
843 Bad, // Function - handled in v-call
844 Abio, // Abio
845 Return_Address,// Return_Address
846 Memory, // Memory
847 FloatBot, // FloatTop
848 FloatCon, // FloatCon
849 FloatTop, // FloatBot
850 DoubleBot, // DoubleTop
851 DoubleCon, // DoubleCon
852 DoubleTop, // DoubleBot
853 Top // Bottom
854 };
856 const Type *Type::xdual() const {
857 // Note: the base() accessor asserts the sanity of _base.
858 assert(_type_info[base()].dual_type != Bad, "implement with v-call");
859 return new Type(_type_info[_base].dual_type);
860 }
862 //------------------------------has_memory-------------------------------------
863 bool Type::has_memory() const {
864 Type::TYPES tx = base();
865 if (tx == Memory) return true;
866 if (tx == Tuple) {
867 const TypeTuple *t = is_tuple();
868 for (uint i=0; i < t->cnt(); i++) {
869 tx = t->field_at(i)->base();
870 if (tx == Memory) return true;
871 }
872 }
873 return false;
874 }
876 #ifndef PRODUCT
877 //------------------------------dump2------------------------------------------
878 void Type::dump2( Dict &d, uint depth, outputStream *st ) const {
879 st->print("%s", _type_info[_base].msg);
880 }
882 //------------------------------dump-------------------------------------------
883 void Type::dump_on(outputStream *st) const {
884 ResourceMark rm;
885 Dict d(cmpkey,hashkey); // Stop recursive type dumping
886 dump2(d,1, st);
887 if (is_ptr_to_narrowoop()) {
888 st->print(" [narrow]");
889 } else if (is_ptr_to_narrowklass()) {
890 st->print(" [narrowklass]");
891 }
892 }
894 //-----------------------------------------------------------------------------
895 const char* Type::str(const Type* t) {
896 stringStream ss;
897 t->dump_on(&ss);
898 return ss.as_string();
899 }
900 #endif
902 //------------------------------singleton--------------------------------------
903 // TRUE if Type is a singleton type, FALSE otherwise. Singletons are simple
904 // constants (Ldi nodes). Singletons are integer, float or double constants.
905 bool Type::singleton(void) const {
906 return _base == Top || _base == Half;
907 }
909 //------------------------------empty------------------------------------------
910 // TRUE if Type is a type with no values, FALSE otherwise.
911 bool Type::empty(void) const {
912 switch (_base) {
913 case DoubleTop:
914 case FloatTop:
915 case Top:
916 return true;
918 case Half:
919 case Abio:
920 case Return_Address:
921 case Memory:
922 case Bottom:
923 case FloatBot:
924 case DoubleBot:
925 return false; // never a singleton, therefore never empty
926 }
928 ShouldNotReachHere();
929 return false;
930 }
932 //------------------------------dump_stats-------------------------------------
933 // Dump collected statistics to stderr
934 #ifndef PRODUCT
935 void Type::dump_stats() {
936 tty->print("Types made: %d\n", type_dict()->Size());
937 }
938 #endif
940 //------------------------------typerr-----------------------------------------
941 void Type::typerr( const Type *t ) const {
942 #ifndef PRODUCT
943 tty->print("\nError mixing types: ");
944 dump();
945 tty->print(" and ");
946 t->dump();
947 tty->print("\n");
948 #endif
949 ShouldNotReachHere();
950 }
953 //=============================================================================
954 // Convenience common pre-built types.
955 const TypeF *TypeF::ZERO; // Floating point zero
956 const TypeF *TypeF::ONE; // Floating point one
958 //------------------------------make-------------------------------------------
959 // Create a float constant
960 const TypeF *TypeF::make(float f) {
961 return (TypeF*)(new TypeF(f))->hashcons();
962 }
964 //------------------------------meet-------------------------------------------
965 // Compute the MEET of two types. It returns a new Type object.
966 const Type *TypeF::xmeet( const Type *t ) const {
967 // Perform a fast test for common case; meeting the same types together.
968 if( this == t ) return this; // Meeting same type-rep?
970 // Current "this->_base" is FloatCon
971 switch (t->base()) { // Switch on original type
972 case AnyPtr: // Mixing with oops happens when javac
973 case RawPtr: // reuses local variables
974 case OopPtr:
975 case InstPtr:
976 case AryPtr:
977 case MetadataPtr:
978 case KlassPtr:
979 case NarrowOop:
980 case NarrowKlass:
981 case Int:
982 case Long:
983 case DoubleTop:
984 case DoubleCon:
985 case DoubleBot:
986 case Bottom: // Ye Olde Default
987 return Type::BOTTOM;
989 case FloatBot:
990 return t;
992 default: // All else is a mistake
993 typerr(t);
995 case FloatCon: // Float-constant vs Float-constant?
996 if( jint_cast(_f) != jint_cast(t->getf()) ) // unequal constants?
997 // must compare bitwise as positive zero, negative zero and NaN have
998 // all the same representation in C++
999 return FLOAT; // Return generic float
1000 // Equal constants
1001 case Top:
1002 case FloatTop:
1003 break; // Return the float constant
1004 }
1005 return this; // Return the float constant
1006 }
1008 //------------------------------xdual------------------------------------------
1009 // Dual: symmetric
1010 const Type *TypeF::xdual() const {
1011 return this;
1012 }
1014 //------------------------------eq---------------------------------------------
1015 // Structural equality check for Type representations
1016 bool TypeF::eq(const Type *t) const {
1017 // Bitwise comparison to distinguish between +/-0. These values must be treated
1018 // as different to be consistent with C1 and the interpreter.
1019 return (jint_cast(_f) == jint_cast(t->getf()));
1020 }
1022 //------------------------------hash-------------------------------------------
1023 // Type-specific hashing function.
1024 int TypeF::hash(void) const {
1025 return *(int*)(&_f);
1026 }
1028 //------------------------------is_finite--------------------------------------
1029 // Has a finite value
1030 bool TypeF::is_finite() const {
1031 return g_isfinite(getf()) != 0;
1032 }
1034 //------------------------------is_nan-----------------------------------------
1035 // Is not a number (NaN)
1036 bool TypeF::is_nan() const {
1037 return g_isnan(getf()) != 0;
1038 }
1040 //------------------------------dump2------------------------------------------
1041 // Dump float constant Type
1042 #ifndef PRODUCT
1043 void TypeF::dump2( Dict &d, uint depth, outputStream *st ) const {
1044 Type::dump2(d,depth, st);
1045 st->print("%f", _f);
1046 }
1047 #endif
1049 //------------------------------singleton--------------------------------------
1050 // TRUE if Type is a singleton type, FALSE otherwise. Singletons are simple
1051 // constants (Ldi nodes). Singletons are integer, float or double constants
1052 // or a single symbol.
1053 bool TypeF::singleton(void) const {
1054 return true; // Always a singleton
1055 }
1057 bool TypeF::empty(void) const {
1058 return false; // always exactly a singleton
1059 }
1061 //=============================================================================
1062 // Convenience common pre-built types.
1063 const TypeD *TypeD::ZERO; // Floating point zero
1064 const TypeD *TypeD::ONE; // Floating point one
1066 //------------------------------make-------------------------------------------
1067 const TypeD *TypeD::make(double d) {
1068 return (TypeD*)(new TypeD(d))->hashcons();
1069 }
1071 //------------------------------meet-------------------------------------------
1072 // Compute the MEET of two types. It returns a new Type object.
1073 const Type *TypeD::xmeet( const Type *t ) const {
1074 // Perform a fast test for common case; meeting the same types together.
1075 if( this == t ) return this; // Meeting same type-rep?
1077 // Current "this->_base" is DoubleCon
1078 switch (t->base()) { // Switch on original type
1079 case AnyPtr: // Mixing with oops happens when javac
1080 case RawPtr: // reuses local variables
1081 case OopPtr:
1082 case InstPtr:
1083 case AryPtr:
1084 case MetadataPtr:
1085 case KlassPtr:
1086 case NarrowOop:
1087 case NarrowKlass:
1088 case Int:
1089 case Long:
1090 case FloatTop:
1091 case FloatCon:
1092 case FloatBot:
1093 case Bottom: // Ye Olde Default
1094 return Type::BOTTOM;
1096 case DoubleBot:
1097 return t;
1099 default: // All else is a mistake
1100 typerr(t);
1102 case DoubleCon: // Double-constant vs Double-constant?
1103 if( jlong_cast(_d) != jlong_cast(t->getd()) ) // unequal constants? (see comment in TypeF::xmeet)
1104 return DOUBLE; // Return generic double
1105 case Top:
1106 case DoubleTop:
1107 break;
1108 }
1109 return this; // Return the double constant
1110 }
1112 //------------------------------xdual------------------------------------------
1113 // Dual: symmetric
1114 const Type *TypeD::xdual() const {
1115 return this;
1116 }
1118 //------------------------------eq---------------------------------------------
1119 // Structural equality check for Type representations
1120 bool TypeD::eq(const Type *t) const {
1121 // Bitwise comparison to distinguish between +/-0. These values must be treated
1122 // as different to be consistent with C1 and the interpreter.
1123 return (jlong_cast(_d) == jlong_cast(t->getd()));
1124 }
1126 //------------------------------hash-------------------------------------------
1127 // Type-specific hashing function.
1128 int TypeD::hash(void) const {
1129 return *(int*)(&_d);
1130 }
1132 //------------------------------is_finite--------------------------------------
1133 // Has a finite value
1134 bool TypeD::is_finite() const {
1135 return g_isfinite(getd()) != 0;
1136 }
1138 //------------------------------is_nan-----------------------------------------
1139 // Is not a number (NaN)
1140 bool TypeD::is_nan() const {
1141 return g_isnan(getd()) != 0;
1142 }
1144 //------------------------------dump2------------------------------------------
1145 // Dump double constant Type
1146 #ifndef PRODUCT
1147 void TypeD::dump2( Dict &d, uint depth, outputStream *st ) const {
1148 Type::dump2(d,depth,st);
1149 st->print("%f", _d);
1150 }
1151 #endif
1153 //------------------------------singleton--------------------------------------
1154 // TRUE if Type is a singleton type, FALSE otherwise. Singletons are simple
1155 // constants (Ldi nodes). Singletons are integer, float or double constants
1156 // or a single symbol.
1157 bool TypeD::singleton(void) const {
1158 return true; // Always a singleton
1159 }
1161 bool TypeD::empty(void) const {
1162 return false; // always exactly a singleton
1163 }
1165 //=============================================================================
1166 // Convience common pre-built types.
1167 const TypeInt *TypeInt::MINUS_1;// -1
1168 const TypeInt *TypeInt::ZERO; // 0
1169 const TypeInt *TypeInt::ONE; // 1
1170 const TypeInt *TypeInt::BOOL; // 0 or 1, FALSE or TRUE.
1171 const TypeInt *TypeInt::CC; // -1,0 or 1, condition codes
1172 const TypeInt *TypeInt::CC_LT; // [-1] == MINUS_1
1173 const TypeInt *TypeInt::CC_GT; // [1] == ONE
1174 const TypeInt *TypeInt::CC_EQ; // [0] == ZERO
1175 const TypeInt *TypeInt::CC_LE; // [-1,0]
1176 const TypeInt *TypeInt::CC_GE; // [0,1] == BOOL (!)
1177 const TypeInt *TypeInt::BYTE; // Bytes, -128 to 127
1178 const TypeInt *TypeInt::UBYTE; // Unsigned Bytes, 0 to 255
1179 const TypeInt *TypeInt::CHAR; // Java chars, 0-65535
1180 const TypeInt *TypeInt::SHORT; // Java shorts, -32768-32767
1181 const TypeInt *TypeInt::POS; // Positive 32-bit integers or zero
1182 const TypeInt *TypeInt::POS1; // Positive 32-bit integers
1183 const TypeInt *TypeInt::INT; // 32-bit integers
1184 const TypeInt *TypeInt::SYMINT; // symmetric range [-max_jint..max_jint]
1185 const TypeInt *TypeInt::TYPE_DOMAIN; // alias for TypeInt::INT
1187 //------------------------------TypeInt----------------------------------------
1188 TypeInt::TypeInt( jint lo, jint hi, int w ) : Type(Int), _lo(lo), _hi(hi), _widen(w) {
1189 }
1191 //------------------------------make-------------------------------------------
1192 const TypeInt *TypeInt::make( jint lo ) {
1193 return (TypeInt*)(new TypeInt(lo,lo,WidenMin))->hashcons();
1194 }
1196 static int normalize_int_widen( jint lo, jint hi, int w ) {
1197 // Certain normalizations keep us sane when comparing types.
1198 // The 'SMALLINT' covers constants and also CC and its relatives.
1199 if (lo <= hi) {
1200 if (((juint)hi - lo) <= SMALLINT) w = Type::WidenMin;
1201 if (((juint)hi - lo) >= max_juint) w = Type::WidenMax; // TypeInt::INT
1202 } else {
1203 if (((juint)lo - hi) <= SMALLINT) w = Type::WidenMin;
1204 if (((juint)lo - hi) >= max_juint) w = Type::WidenMin; // dual TypeInt::INT
1205 }
1206 return w;
1207 }
1209 const TypeInt *TypeInt::make( jint lo, jint hi, int w ) {
1210 w = normalize_int_widen(lo, hi, w);
1211 return (TypeInt*)(new TypeInt(lo,hi,w))->hashcons();
1212 }
1214 //------------------------------meet-------------------------------------------
1215 // Compute the MEET of two types. It returns a new Type representation object
1216 // with reference count equal to the number of Types pointing at it.
1217 // Caller should wrap a Types around it.
1218 const Type *TypeInt::xmeet( const Type *t ) const {
1219 // Perform a fast test for common case; meeting the same types together.
1220 if( this == t ) return this; // Meeting same type?
1222 // Currently "this->_base" is a TypeInt
1223 switch (t->base()) { // Switch on original type
1224 case AnyPtr: // Mixing with oops happens when javac
1225 case RawPtr: // reuses local variables
1226 case OopPtr:
1227 case InstPtr:
1228 case AryPtr:
1229 case MetadataPtr:
1230 case KlassPtr:
1231 case NarrowOop:
1232 case NarrowKlass:
1233 case Long:
1234 case FloatTop:
1235 case FloatCon:
1236 case FloatBot:
1237 case DoubleTop:
1238 case DoubleCon:
1239 case DoubleBot:
1240 case Bottom: // Ye Olde Default
1241 return Type::BOTTOM;
1242 default: // All else is a mistake
1243 typerr(t);
1244 case Top: // No change
1245 return this;
1246 case Int: // Int vs Int?
1247 break;
1248 }
1250 // Expand covered set
1251 const TypeInt *r = t->is_int();
1252 return make( MIN2(_lo,r->_lo), MAX2(_hi,r->_hi), MAX2(_widen,r->_widen) );
1253 }
1255 //------------------------------xdual------------------------------------------
1256 // Dual: reverse hi & lo; flip widen
1257 const Type *TypeInt::xdual() const {
1258 int w = normalize_int_widen(_hi,_lo, WidenMax-_widen);
1259 return new TypeInt(_hi,_lo,w);
1260 }
1262 //------------------------------widen------------------------------------------
1263 // Only happens for optimistic top-down optimizations.
1264 const Type *TypeInt::widen( const Type *old, const Type* limit ) const {
1265 // Coming from TOP or such; no widening
1266 if( old->base() != Int ) return this;
1267 const TypeInt *ot = old->is_int();
1269 // If new guy is equal to old guy, no widening
1270 if( _lo == ot->_lo && _hi == ot->_hi )
1271 return old;
1273 // If new guy contains old, then we widened
1274 if( _lo <= ot->_lo && _hi >= ot->_hi ) {
1275 // New contains old
1276 // If new guy is already wider than old, no widening
1277 if( _widen > ot->_widen ) return this;
1278 // If old guy was a constant, do not bother
1279 if (ot->_lo == ot->_hi) return this;
1280 // Now widen new guy.
1281 // Check for widening too far
1282 if (_widen == WidenMax) {
1283 int max = max_jint;
1284 int min = min_jint;
1285 if (limit->isa_int()) {
1286 max = limit->is_int()->_hi;
1287 min = limit->is_int()->_lo;
1288 }
1289 if (min < _lo && _hi < max) {
1290 // If neither endpoint is extremal yet, push out the endpoint
1291 // which is closer to its respective limit.
1292 if (_lo >= 0 || // easy common case
1293 (juint)(_lo - min) >= (juint)(max - _hi)) {
1294 // Try to widen to an unsigned range type of 31 bits:
1295 return make(_lo, max, WidenMax);
1296 } else {
1297 return make(min, _hi, WidenMax);
1298 }
1299 }
1300 return TypeInt::INT;
1301 }
1302 // Returned widened new guy
1303 return make(_lo,_hi,_widen+1);
1304 }
1306 // If old guy contains new, then we probably widened too far & dropped to
1307 // bottom. Return the wider fellow.
1308 if ( ot->_lo <= _lo && ot->_hi >= _hi )
1309 return old;
1311 //fatal("Integer value range is not subset");
1312 //return this;
1313 return TypeInt::INT;
1314 }
1316 //------------------------------narrow---------------------------------------
1317 // Only happens for pessimistic optimizations.
1318 const Type *TypeInt::narrow( const Type *old ) const {
1319 if (_lo >= _hi) return this; // already narrow enough
1320 if (old == NULL) return this;
1321 const TypeInt* ot = old->isa_int();
1322 if (ot == NULL) return this;
1323 jint olo = ot->_lo;
1324 jint ohi = ot->_hi;
1326 // If new guy is equal to old guy, no narrowing
1327 if (_lo == olo && _hi == ohi) return old;
1329 // If old guy was maximum range, allow the narrowing
1330 if (olo == min_jint && ohi == max_jint) return this;
1332 if (_lo < olo || _hi > ohi)
1333 return this; // doesn't narrow; pretty wierd
1335 // The new type narrows the old type, so look for a "death march".
1336 // See comments on PhaseTransform::saturate.
1337 juint nrange = (juint)_hi - _lo;
1338 juint orange = (juint)ohi - olo;
1339 if (nrange < max_juint - 1 && nrange > (orange >> 1) + (SMALLINT*2)) {
1340 // Use the new type only if the range shrinks a lot.
1341 // We do not want the optimizer computing 2^31 point by point.
1342 return old;
1343 }
1345 return this;
1346 }
1348 //-----------------------------filter------------------------------------------
1349 const Type *TypeInt::filter_helper(const Type *kills, bool include_speculative) const {
1350 const TypeInt* ft = join_helper(kills, include_speculative)->isa_int();
1351 if (ft == NULL || ft->empty())
1352 return Type::TOP; // Canonical empty value
1353 if (ft->_widen < this->_widen) {
1354 // Do not allow the value of kill->_widen to affect the outcome.
1355 // The widen bits must be allowed to run freely through the graph.
1356 ft = TypeInt::make(ft->_lo, ft->_hi, this->_widen);
1357 }
1358 return ft;
1359 }
1361 //------------------------------eq---------------------------------------------
1362 // Structural equality check for Type representations
1363 bool TypeInt::eq( const Type *t ) const {
1364 const TypeInt *r = t->is_int(); // Handy access
1365 return r->_lo == _lo && r->_hi == _hi && r->_widen == _widen;
1366 }
1368 //------------------------------hash-------------------------------------------
1369 // Type-specific hashing function.
1370 int TypeInt::hash(void) const {
1371 return java_add(java_add(_lo, _hi), java_add(_widen, (int)Type::Int));
1372 }
1374 //------------------------------is_finite--------------------------------------
1375 // Has a finite value
1376 bool TypeInt::is_finite() const {
1377 return true;
1378 }
1380 //------------------------------dump2------------------------------------------
1381 // Dump TypeInt
1382 #ifndef PRODUCT
1383 static const char* intname(char* buf, jint n) {
1384 if (n == min_jint)
1385 return "min";
1386 else if (n < min_jint + 10000)
1387 sprintf(buf, "min+" INT32_FORMAT, n - min_jint);
1388 else if (n == max_jint)
1389 return "max";
1390 else if (n > max_jint - 10000)
1391 sprintf(buf, "max-" INT32_FORMAT, max_jint - n);
1392 else
1393 sprintf(buf, INT32_FORMAT, n);
1394 return buf;
1395 }
1397 void TypeInt::dump2( Dict &d, uint depth, outputStream *st ) const {
1398 char buf[40], buf2[40];
1399 if (_lo == min_jint && _hi == max_jint)
1400 st->print("int");
1401 else if (is_con())
1402 st->print("int:%s", intname(buf, get_con()));
1403 else if (_lo == BOOL->_lo && _hi == BOOL->_hi)
1404 st->print("bool");
1405 else if (_lo == BYTE->_lo && _hi == BYTE->_hi)
1406 st->print("byte");
1407 else if (_lo == CHAR->_lo && _hi == CHAR->_hi)
1408 st->print("char");
1409 else if (_lo == SHORT->_lo && _hi == SHORT->_hi)
1410 st->print("short");
1411 else if (_hi == max_jint)
1412 st->print("int:>=%s", intname(buf, _lo));
1413 else if (_lo == min_jint)
1414 st->print("int:<=%s", intname(buf, _hi));
1415 else
1416 st->print("int:%s..%s", intname(buf, _lo), intname(buf2, _hi));
1418 if (_widen != 0 && this != TypeInt::INT)
1419 st->print(":%.*s", _widen, "wwww");
1420 }
1421 #endif
1423 //------------------------------singleton--------------------------------------
1424 // TRUE if Type is a singleton type, FALSE otherwise. Singletons are simple
1425 // constants.
1426 bool TypeInt::singleton(void) const {
1427 return _lo >= _hi;
1428 }
1430 bool TypeInt::empty(void) const {
1431 return _lo > _hi;
1432 }
1434 //=============================================================================
1435 // Convenience common pre-built types.
1436 const TypeLong *TypeLong::MINUS_1;// -1
1437 const TypeLong *TypeLong::ZERO; // 0
1438 const TypeLong *TypeLong::ONE; // 1
1439 const TypeLong *TypeLong::POS; // >=0
1440 const TypeLong *TypeLong::LONG; // 64-bit integers
1441 const TypeLong *TypeLong::INT; // 32-bit subrange
1442 const TypeLong *TypeLong::UINT; // 32-bit unsigned subrange
1443 const TypeLong *TypeLong::TYPE_DOMAIN; // alias for TypeLong::LONG
1445 //------------------------------TypeLong---------------------------------------
1446 TypeLong::TypeLong( jlong lo, jlong hi, int w ) : Type(Long), _lo(lo), _hi(hi), _widen(w) {
1447 }
1449 //------------------------------make-------------------------------------------
1450 const TypeLong *TypeLong::make( jlong lo ) {
1451 return (TypeLong*)(new TypeLong(lo,lo,WidenMin))->hashcons();
1452 }
1454 static int normalize_long_widen( jlong lo, jlong hi, int w ) {
1455 // Certain normalizations keep us sane when comparing types.
1456 // The 'SMALLINT' covers constants.
1457 if (lo <= hi) {
1458 if (((julong)hi - lo) <= SMALLINT) w = Type::WidenMin;
1459 if (((julong)hi - lo) >= max_julong) w = Type::WidenMax; // TypeLong::LONG
1460 } else {
1461 if (((julong)lo - hi) <= SMALLINT) w = Type::WidenMin;
1462 if (((julong)lo - hi) >= max_julong) w = Type::WidenMin; // dual TypeLong::LONG
1463 }
1464 return w;
1465 }
1467 const TypeLong *TypeLong::make( jlong lo, jlong hi, int w ) {
1468 w = normalize_long_widen(lo, hi, w);
1469 return (TypeLong*)(new TypeLong(lo,hi,w))->hashcons();
1470 }
1473 //------------------------------meet-------------------------------------------
1474 // Compute the MEET of two types. It returns a new Type representation object
1475 // with reference count equal to the number of Types pointing at it.
1476 // Caller should wrap a Types around it.
1477 const Type *TypeLong::xmeet( const Type *t ) const {
1478 // Perform a fast test for common case; meeting the same types together.
1479 if( this == t ) return this; // Meeting same type?
1481 // Currently "this->_base" is a TypeLong
1482 switch (t->base()) { // Switch on original type
1483 case AnyPtr: // Mixing with oops happens when javac
1484 case RawPtr: // reuses local variables
1485 case OopPtr:
1486 case InstPtr:
1487 case AryPtr:
1488 case MetadataPtr:
1489 case KlassPtr:
1490 case NarrowOop:
1491 case NarrowKlass:
1492 case Int:
1493 case FloatTop:
1494 case FloatCon:
1495 case FloatBot:
1496 case DoubleTop:
1497 case DoubleCon:
1498 case DoubleBot:
1499 case Bottom: // Ye Olde Default
1500 return Type::BOTTOM;
1501 default: // All else is a mistake
1502 typerr(t);
1503 case Top: // No change
1504 return this;
1505 case Long: // Long vs Long?
1506 break;
1507 }
1509 // Expand covered set
1510 const TypeLong *r = t->is_long(); // Turn into a TypeLong
1511 return make( MIN2(_lo,r->_lo), MAX2(_hi,r->_hi), MAX2(_widen,r->_widen) );
1512 }
1514 //------------------------------xdual------------------------------------------
1515 // Dual: reverse hi & lo; flip widen
1516 const Type *TypeLong::xdual() const {
1517 int w = normalize_long_widen(_hi,_lo, WidenMax-_widen);
1518 return new TypeLong(_hi,_lo,w);
1519 }
1521 //------------------------------widen------------------------------------------
1522 // Only happens for optimistic top-down optimizations.
1523 const Type *TypeLong::widen( const Type *old, const Type* limit ) const {
1524 // Coming from TOP or such; no widening
1525 if( old->base() != Long ) return this;
1526 const TypeLong *ot = old->is_long();
1528 // If new guy is equal to old guy, no widening
1529 if( _lo == ot->_lo && _hi == ot->_hi )
1530 return old;
1532 // If new guy contains old, then we widened
1533 if( _lo <= ot->_lo && _hi >= ot->_hi ) {
1534 // New contains old
1535 // If new guy is already wider than old, no widening
1536 if( _widen > ot->_widen ) return this;
1537 // If old guy was a constant, do not bother
1538 if (ot->_lo == ot->_hi) return this;
1539 // Now widen new guy.
1540 // Check for widening too far
1541 if (_widen == WidenMax) {
1542 jlong max = max_jlong;
1543 jlong min = min_jlong;
1544 if (limit->isa_long()) {
1545 max = limit->is_long()->_hi;
1546 min = limit->is_long()->_lo;
1547 }
1548 if (min < _lo && _hi < max) {
1549 // If neither endpoint is extremal yet, push out the endpoint
1550 // which is closer to its respective limit.
1551 if (_lo >= 0 || // easy common case
1552 ((julong)_lo - min) >= ((julong)max - _hi)) {
1553 // Try to widen to an unsigned range type of 32/63 bits:
1554 if (max >= max_juint && _hi < max_juint)
1555 return make(_lo, max_juint, WidenMax);
1556 else
1557 return make(_lo, max, WidenMax);
1558 } else {
1559 return make(min, _hi, WidenMax);
1560 }
1561 }
1562 return TypeLong::LONG;
1563 }
1564 // Returned widened new guy
1565 return make(_lo,_hi,_widen+1);
1566 }
1568 // If old guy contains new, then we probably widened too far & dropped to
1569 // bottom. Return the wider fellow.
1570 if ( ot->_lo <= _lo && ot->_hi >= _hi )
1571 return old;
1573 // fatal("Long value range is not subset");
1574 // return this;
1575 return TypeLong::LONG;
1576 }
1578 //------------------------------narrow----------------------------------------
1579 // Only happens for pessimistic optimizations.
1580 const Type *TypeLong::narrow( const Type *old ) const {
1581 if (_lo >= _hi) return this; // already narrow enough
1582 if (old == NULL) return this;
1583 const TypeLong* ot = old->isa_long();
1584 if (ot == NULL) return this;
1585 jlong olo = ot->_lo;
1586 jlong ohi = ot->_hi;
1588 // If new guy is equal to old guy, no narrowing
1589 if (_lo == olo && _hi == ohi) return old;
1591 // If old guy was maximum range, allow the narrowing
1592 if (olo == min_jlong && ohi == max_jlong) return this;
1594 if (_lo < olo || _hi > ohi)
1595 return this; // doesn't narrow; pretty wierd
1597 // The new type narrows the old type, so look for a "death march".
1598 // See comments on PhaseTransform::saturate.
1599 julong nrange = _hi - _lo;
1600 julong orange = ohi - olo;
1601 if (nrange < max_julong - 1 && nrange > (orange >> 1) + (SMALLINT*2)) {
1602 // Use the new type only if the range shrinks a lot.
1603 // We do not want the optimizer computing 2^31 point by point.
1604 return old;
1605 }
1607 return this;
1608 }
1610 //-----------------------------filter------------------------------------------
1611 const Type *TypeLong::filter_helper(const Type *kills, bool include_speculative) const {
1612 const TypeLong* ft = join_helper(kills, include_speculative)->isa_long();
1613 if (ft == NULL || ft->empty())
1614 return Type::TOP; // Canonical empty value
1615 if (ft->_widen < this->_widen) {
1616 // Do not allow the value of kill->_widen to affect the outcome.
1617 // The widen bits must be allowed to run freely through the graph.
1618 ft = TypeLong::make(ft->_lo, ft->_hi, this->_widen);
1619 }
1620 return ft;
1621 }
1623 //------------------------------eq---------------------------------------------
1624 // Structural equality check for Type representations
1625 bool TypeLong::eq( const Type *t ) const {
1626 const TypeLong *r = t->is_long(); // Handy access
1627 return r->_lo == _lo && r->_hi == _hi && r->_widen == _widen;
1628 }
1630 //------------------------------hash-------------------------------------------
1631 // Type-specific hashing function.
1632 int TypeLong::hash(void) const {
1633 return (int)(_lo+_hi+_widen+(int)Type::Long);
1634 }
1636 //------------------------------is_finite--------------------------------------
1637 // Has a finite value
1638 bool TypeLong::is_finite() const {
1639 return true;
1640 }
1642 //------------------------------dump2------------------------------------------
1643 // Dump TypeLong
1644 #ifndef PRODUCT
1645 static const char* longnamenear(jlong x, const char* xname, char* buf, jlong n) {
1646 if (n > x) {
1647 if (n >= x + 10000) return NULL;
1648 sprintf(buf, "%s+" JLONG_FORMAT, xname, n - x);
1649 } else if (n < x) {
1650 if (n <= x - 10000) return NULL;
1651 sprintf(buf, "%s-" JLONG_FORMAT, xname, x - n);
1652 } else {
1653 return xname;
1654 }
1655 return buf;
1656 }
1658 static const char* longname(char* buf, jlong n) {
1659 const char* str;
1660 if (n == min_jlong)
1661 return "min";
1662 else if (n < min_jlong + 10000)
1663 sprintf(buf, "min+" JLONG_FORMAT, n - min_jlong);
1664 else if (n == max_jlong)
1665 return "max";
1666 else if (n > max_jlong - 10000)
1667 sprintf(buf, "max-" JLONG_FORMAT, max_jlong - n);
1668 else if ((str = longnamenear(max_juint, "maxuint", buf, n)) != NULL)
1669 return str;
1670 else if ((str = longnamenear(max_jint, "maxint", buf, n)) != NULL)
1671 return str;
1672 else if ((str = longnamenear(min_jint, "minint", buf, n)) != NULL)
1673 return str;
1674 else
1675 sprintf(buf, JLONG_FORMAT, n);
1676 return buf;
1677 }
1679 void TypeLong::dump2( Dict &d, uint depth, outputStream *st ) const {
1680 char buf[80], buf2[80];
1681 if (_lo == min_jlong && _hi == max_jlong)
1682 st->print("long");
1683 else if (is_con())
1684 st->print("long:%s", longname(buf, get_con()));
1685 else if (_hi == max_jlong)
1686 st->print("long:>=%s", longname(buf, _lo));
1687 else if (_lo == min_jlong)
1688 st->print("long:<=%s", longname(buf, _hi));
1689 else
1690 st->print("long:%s..%s", longname(buf, _lo), longname(buf2, _hi));
1692 if (_widen != 0 && this != TypeLong::LONG)
1693 st->print(":%.*s", _widen, "wwww");
1694 }
1695 #endif
1697 //------------------------------singleton--------------------------------------
1698 // TRUE if Type is a singleton type, FALSE otherwise. Singletons are simple
1699 // constants
1700 bool TypeLong::singleton(void) const {
1701 return _lo >= _hi;
1702 }
1704 bool TypeLong::empty(void) const {
1705 return _lo > _hi;
1706 }
1708 //=============================================================================
1709 // Convenience common pre-built types.
1710 const TypeTuple *TypeTuple::IFBOTH; // Return both arms of IF as reachable
1711 const TypeTuple *TypeTuple::IFFALSE;
1712 const TypeTuple *TypeTuple::IFTRUE;
1713 const TypeTuple *TypeTuple::IFNEITHER;
1714 const TypeTuple *TypeTuple::LOOPBODY;
1715 const TypeTuple *TypeTuple::MEMBAR;
1716 const TypeTuple *TypeTuple::STORECONDITIONAL;
1717 const TypeTuple *TypeTuple::START_I2C;
1718 const TypeTuple *TypeTuple::INT_PAIR;
1719 const TypeTuple *TypeTuple::LONG_PAIR;
1720 const TypeTuple *TypeTuple::INT_CC_PAIR;
1721 const TypeTuple *TypeTuple::LONG_CC_PAIR;
1724 //------------------------------make-------------------------------------------
1725 // Make a TypeTuple from the range of a method signature
1726 const TypeTuple *TypeTuple::make_range(ciSignature* sig) {
1727 ciType* return_type = sig->return_type();
1728 uint total_fields = TypeFunc::Parms + return_type->size();
1729 const Type **field_array = fields(total_fields);
1730 switch (return_type->basic_type()) {
1731 case T_LONG:
1732 field_array[TypeFunc::Parms] = TypeLong::LONG;
1733 field_array[TypeFunc::Parms+1] = Type::HALF;
1734 break;
1735 case T_DOUBLE:
1736 field_array[TypeFunc::Parms] = Type::DOUBLE;
1737 field_array[TypeFunc::Parms+1] = Type::HALF;
1738 break;
1739 case T_OBJECT:
1740 case T_ARRAY:
1741 case T_BOOLEAN:
1742 case T_CHAR:
1743 case T_FLOAT:
1744 case T_BYTE:
1745 case T_SHORT:
1746 case T_INT:
1747 field_array[TypeFunc::Parms] = get_const_type(return_type);
1748 break;
1749 case T_VOID:
1750 break;
1751 default:
1752 ShouldNotReachHere();
1753 }
1754 return (TypeTuple*)(new TypeTuple(total_fields,field_array))->hashcons();
1755 }
1757 // Make a TypeTuple from the domain of a method signature
1758 const TypeTuple *TypeTuple::make_domain(ciInstanceKlass* recv, ciSignature* sig) {
1759 uint total_fields = TypeFunc::Parms + sig->size();
1761 uint pos = TypeFunc::Parms;
1762 const Type **field_array;
1763 if (recv != NULL) {
1764 total_fields++;
1765 field_array = fields(total_fields);
1766 // Use get_const_type here because it respects UseUniqueSubclasses:
1767 field_array[pos++] = get_const_type(recv)->join_speculative(TypePtr::NOTNULL);
1768 } else {
1769 field_array = fields(total_fields);
1770 }
1772 int i = 0;
1773 while (pos < total_fields) {
1774 ciType* type = sig->type_at(i);
1776 switch (type->basic_type()) {
1777 case T_LONG:
1778 field_array[pos++] = TypeLong::LONG;
1779 field_array[pos++] = Type::HALF;
1780 break;
1781 case T_DOUBLE:
1782 field_array[pos++] = Type::DOUBLE;
1783 field_array[pos++] = Type::HALF;
1784 break;
1785 case T_OBJECT:
1786 case T_ARRAY:
1787 case T_FLOAT:
1788 case T_INT:
1789 field_array[pos++] = get_const_type(type);
1790 break;
1791 case T_BOOLEAN:
1792 case T_CHAR:
1793 case T_BYTE:
1794 case T_SHORT:
1795 field_array[pos++] = TypeInt::INT;
1796 break;
1797 default:
1798 ShouldNotReachHere();
1799 }
1800 i++;
1801 }
1802 return (TypeTuple*)(new TypeTuple(total_fields,field_array))->hashcons();
1803 }
1805 const TypeTuple *TypeTuple::make( uint cnt, const Type **fields ) {
1806 return (TypeTuple*)(new TypeTuple(cnt,fields))->hashcons();
1807 }
1809 //------------------------------fields-----------------------------------------
1810 // Subroutine call type with space allocated for argument types
1811 const Type **TypeTuple::fields( uint arg_cnt ) {
1812 const Type **flds = (const Type **)(Compile::current()->type_arena()->Amalloc_4((TypeFunc::Parms+arg_cnt)*sizeof(Type*) ));
1813 flds[TypeFunc::Control ] = Type::CONTROL;
1814 flds[TypeFunc::I_O ] = Type::ABIO;
1815 flds[TypeFunc::Memory ] = Type::MEMORY;
1816 flds[TypeFunc::FramePtr ] = TypeRawPtr::BOTTOM;
1817 flds[TypeFunc::ReturnAdr] = Type::RETURN_ADDRESS;
1819 return flds;
1820 }
1822 //------------------------------meet-------------------------------------------
1823 // Compute the MEET of two types. It returns a new Type object.
1824 const Type *TypeTuple::xmeet( const Type *t ) const {
1825 // Perform a fast test for common case; meeting the same types together.
1826 if( this == t ) return this; // Meeting same type-rep?
1828 // Current "this->_base" is Tuple
1829 switch (t->base()) { // switch on original type
1831 case Bottom: // Ye Olde Default
1832 return t;
1834 default: // All else is a mistake
1835 typerr(t);
1837 case Tuple: { // Meeting 2 signatures?
1838 const TypeTuple *x = t->is_tuple();
1839 assert( _cnt == x->_cnt, "" );
1840 const Type **fields = (const Type **)(Compile::current()->type_arena()->Amalloc_4( _cnt*sizeof(Type*) ));
1841 for( uint i=0; i<_cnt; i++ )
1842 fields[i] = field_at(i)->xmeet( x->field_at(i) );
1843 return TypeTuple::make(_cnt,fields);
1844 }
1845 case Top:
1846 break;
1847 }
1848 return this; // Return the double constant
1849 }
1851 //------------------------------xdual------------------------------------------
1852 // Dual: compute field-by-field dual
1853 const Type *TypeTuple::xdual() const {
1854 const Type **fields = (const Type **)(Compile::current()->type_arena()->Amalloc_4( _cnt*sizeof(Type*) ));
1855 for( uint i=0; i<_cnt; i++ )
1856 fields[i] = _fields[i]->dual();
1857 return new TypeTuple(_cnt,fields);
1858 }
1860 //------------------------------eq---------------------------------------------
1861 // Structural equality check for Type representations
1862 bool TypeTuple::eq( const Type *t ) const {
1863 const TypeTuple *s = (const TypeTuple *)t;
1864 if (_cnt != s->_cnt) return false; // Unequal field counts
1865 for (uint i = 0; i < _cnt; i++)
1866 if (field_at(i) != s->field_at(i)) // POINTER COMPARE! NO RECURSION!
1867 return false; // Missed
1868 return true;
1869 }
1871 //------------------------------hash-------------------------------------------
1872 // Type-specific hashing function.
1873 int TypeTuple::hash(void) const {
1874 intptr_t sum = _cnt;
1875 for( uint i=0; i<_cnt; i++ )
1876 sum += (intptr_t)_fields[i]; // Hash on pointers directly
1877 return sum;
1878 }
1880 //------------------------------dump2------------------------------------------
1881 // Dump signature Type
1882 #ifndef PRODUCT
1883 void TypeTuple::dump2( Dict &d, uint depth, outputStream *st ) const {
1884 st->print("{");
1885 if( !depth || d[this] ) { // Check for recursive print
1886 st->print("...}");
1887 return;
1888 }
1889 d.Insert((void*)this, (void*)this); // Stop recursion
1890 if( _cnt ) {
1891 uint i;
1892 for( i=0; i<_cnt-1; i++ ) {
1893 st->print("%d:", i);
1894 _fields[i]->dump2(d, depth-1, st);
1895 st->print(", ");
1896 }
1897 st->print("%d:", i);
1898 _fields[i]->dump2(d, depth-1, st);
1899 }
1900 st->print("}");
1901 }
1902 #endif
1904 //------------------------------singleton--------------------------------------
1905 // TRUE if Type is a singleton type, FALSE otherwise. Singletons are simple
1906 // constants (Ldi nodes). Singletons are integer, float or double constants
1907 // or a single symbol.
1908 bool TypeTuple::singleton(void) const {
1909 return false; // Never a singleton
1910 }
1912 bool TypeTuple::empty(void) const {
1913 for( uint i=0; i<_cnt; i++ ) {
1914 if (_fields[i]->empty()) return true;
1915 }
1916 return false;
1917 }
1919 //=============================================================================
1920 // Convenience common pre-built types.
1922 inline const TypeInt* normalize_array_size(const TypeInt* size) {
1923 // Certain normalizations keep us sane when comparing types.
1924 // We do not want arrayOop variables to differ only by the wideness
1925 // of their index types. Pick minimum wideness, since that is the
1926 // forced wideness of small ranges anyway.
1927 if (size->_widen != Type::WidenMin)
1928 return TypeInt::make(size->_lo, size->_hi, Type::WidenMin);
1929 else
1930 return size;
1931 }
1933 //------------------------------make-------------------------------------------
1934 const TypeAry* TypeAry::make(const Type* elem, const TypeInt* size, bool stable) {
1935 if (UseCompressedOops && elem->isa_oopptr()) {
1936 elem = elem->make_narrowoop();
1937 }
1938 size = normalize_array_size(size);
1939 return (TypeAry*)(new TypeAry(elem,size,stable))->hashcons();
1940 }
1942 //------------------------------meet-------------------------------------------
1943 // Compute the MEET of two types. It returns a new Type object.
1944 const Type *TypeAry::xmeet( const Type *t ) const {
1945 // Perform a fast test for common case; meeting the same types together.
1946 if( this == t ) return this; // Meeting same type-rep?
1948 // Current "this->_base" is Ary
1949 switch (t->base()) { // switch on original type
1951 case Bottom: // Ye Olde Default
1952 return t;
1954 default: // All else is a mistake
1955 typerr(t);
1957 case Array: { // Meeting 2 arrays?
1958 const TypeAry *a = t->is_ary();
1959 return TypeAry::make(_elem->meet_speculative(a->_elem),
1960 _size->xmeet(a->_size)->is_int(),
1961 _stable & a->_stable);
1962 }
1963 case Top:
1964 break;
1965 }
1966 return this; // Return the double constant
1967 }
1969 //------------------------------xdual------------------------------------------
1970 // Dual: compute field-by-field dual
1971 const Type *TypeAry::xdual() const {
1972 const TypeInt* size_dual = _size->dual()->is_int();
1973 size_dual = normalize_array_size(size_dual);
1974 return new TypeAry(_elem->dual(), size_dual, !_stable);
1975 }
1977 //------------------------------eq---------------------------------------------
1978 // Structural equality check for Type representations
1979 bool TypeAry::eq( const Type *t ) const {
1980 const TypeAry *a = (const TypeAry*)t;
1981 return _elem == a->_elem &&
1982 _stable == a->_stable &&
1983 _size == a->_size;
1984 }
1986 //------------------------------hash-------------------------------------------
1987 // Type-specific hashing function.
1988 int TypeAry::hash(void) const {
1989 return (intptr_t)_elem + (intptr_t)_size + (_stable ? 43 : 0);
1990 }
1992 /**
1993 * Return same type without a speculative part in the element
1994 */
1995 const Type* TypeAry::remove_speculative() const {
1996 return make(_elem->remove_speculative(), _size, _stable);
1997 }
1999 //----------------------interface_vs_oop---------------------------------------
2000 #ifdef ASSERT
2001 bool TypeAry::interface_vs_oop(const Type *t) const {
2002 const TypeAry* t_ary = t->is_ary();
2003 if (t_ary) {
2004 const TypePtr* this_ptr = _elem->make_ptr(); // In case we have narrow_oops
2005 const TypePtr* t_ptr = t_ary->_elem->make_ptr();
2006 if(this_ptr != NULL && t_ptr != NULL) {
2007 return this_ptr->interface_vs_oop(t_ptr);
2008 }
2009 }
2010 return false;
2011 }
2012 #endif
2014 //------------------------------dump2------------------------------------------
2015 #ifndef PRODUCT
2016 void TypeAry::dump2( Dict &d, uint depth, outputStream *st ) const {
2017 if (_stable) st->print("stable:");
2018 _elem->dump2(d, depth, st);
2019 st->print("[");
2020 _size->dump2(d, depth, st);
2021 st->print("]");
2022 }
2023 #endif
2025 //------------------------------singleton--------------------------------------
2026 // TRUE if Type is a singleton type, FALSE otherwise. Singletons are simple
2027 // constants (Ldi nodes). Singletons are integer, float or double constants
2028 // or a single symbol.
2029 bool TypeAry::singleton(void) const {
2030 return false; // Never a singleton
2031 }
2033 bool TypeAry::empty(void) const {
2034 return _elem->empty() || _size->empty();
2035 }
2037 //--------------------------ary_must_be_exact----------------------------------
2038 bool TypeAry::ary_must_be_exact() const {
2039 if (!UseExactTypes) return false;
2040 // This logic looks at the element type of an array, and returns true
2041 // if the element type is either a primitive or a final instance class.
2042 // In such cases, an array built on this ary must have no subclasses.
2043 if (_elem == BOTTOM) return false; // general array not exact
2044 if (_elem == TOP ) return false; // inverted general array not exact
2045 const TypeOopPtr* toop = NULL;
2046 if (UseCompressedOops && _elem->isa_narrowoop()) {
2047 toop = _elem->make_ptr()->isa_oopptr();
2048 } else {
2049 toop = _elem->isa_oopptr();
2050 }
2051 if (!toop) return true; // a primitive type, like int
2052 ciKlass* tklass = toop->klass();
2053 if (tklass == NULL) return false; // unloaded class
2054 if (!tklass->is_loaded()) return false; // unloaded class
2055 const TypeInstPtr* tinst;
2056 if (_elem->isa_narrowoop())
2057 tinst = _elem->make_ptr()->isa_instptr();
2058 else
2059 tinst = _elem->isa_instptr();
2060 if (tinst)
2061 return tklass->as_instance_klass()->is_final();
2062 const TypeAryPtr* tap;
2063 if (_elem->isa_narrowoop())
2064 tap = _elem->make_ptr()->isa_aryptr();
2065 else
2066 tap = _elem->isa_aryptr();
2067 if (tap)
2068 return tap->ary()->ary_must_be_exact();
2069 return false;
2070 }
2072 //==============================TypeVect=======================================
2073 // Convenience common pre-built types.
2074 const TypeVect *TypeVect::VECTS = NULL; // 32-bit vectors
2075 const TypeVect *TypeVect::VECTD = NULL; // 64-bit vectors
2076 const TypeVect *TypeVect::VECTX = NULL; // 128-bit vectors
2077 const TypeVect *TypeVect::VECTY = NULL; // 256-bit vectors
2079 //------------------------------make-------------------------------------------
2080 const TypeVect* TypeVect::make(const Type *elem, uint length) {
2081 BasicType elem_bt = elem->array_element_basic_type();
2082 assert(is_java_primitive(elem_bt), "only primitive types in vector");
2083 assert(length > 1 && is_power_of_2(length), "vector length is power of 2");
2084 assert(Matcher::vector_size_supported(elem_bt, length), "length in range");
2085 int size = length * type2aelembytes(elem_bt);
2086 switch (Matcher::vector_ideal_reg(size)) {
2087 case Op_VecS:
2088 return (TypeVect*)(new TypeVectS(elem, length))->hashcons();
2089 case Op_RegL:
2090 case Op_VecD:
2091 case Op_RegD:
2092 return (TypeVect*)(new TypeVectD(elem, length))->hashcons();
2093 case Op_VecX:
2094 return (TypeVect*)(new TypeVectX(elem, length))->hashcons();
2095 case Op_VecY:
2096 return (TypeVect*)(new TypeVectY(elem, length))->hashcons();
2097 }
2098 ShouldNotReachHere();
2099 return NULL;
2100 }
2102 //------------------------------meet-------------------------------------------
2103 // Compute the MEET of two types. It returns a new Type object.
2104 const Type *TypeVect::xmeet( const Type *t ) const {
2105 // Perform a fast test for common case; meeting the same types together.
2106 if( this == t ) return this; // Meeting same type-rep?
2108 // Current "this->_base" is Vector
2109 switch (t->base()) { // switch on original type
2111 case Bottom: // Ye Olde Default
2112 return t;
2114 default: // All else is a mistake
2115 typerr(t);
2117 case VectorS:
2118 case VectorD:
2119 case VectorX:
2120 case VectorY: { // Meeting 2 vectors?
2121 const TypeVect* v = t->is_vect();
2122 assert( base() == v->base(), "");
2123 assert(length() == v->length(), "");
2124 assert(element_basic_type() == v->element_basic_type(), "");
2125 return TypeVect::make(_elem->xmeet(v->_elem), _length);
2126 }
2127 case Top:
2128 break;
2129 }
2130 return this;
2131 }
2133 //------------------------------xdual------------------------------------------
2134 // Dual: compute field-by-field dual
2135 const Type *TypeVect::xdual() const {
2136 return new TypeVect(base(), _elem->dual(), _length);
2137 }
2139 //------------------------------eq---------------------------------------------
2140 // Structural equality check for Type representations
2141 bool TypeVect::eq(const Type *t) const {
2142 const TypeVect *v = t->is_vect();
2143 return (_elem == v->_elem) && (_length == v->_length);
2144 }
2146 //------------------------------hash-------------------------------------------
2147 // Type-specific hashing function.
2148 int TypeVect::hash(void) const {
2149 return (intptr_t)_elem + (intptr_t)_length;
2150 }
2152 //------------------------------singleton--------------------------------------
2153 // TRUE if Type is a singleton type, FALSE otherwise. Singletons are simple
2154 // constants (Ldi nodes). Vector is singleton if all elements are the same
2155 // constant value (when vector is created with Replicate code).
2156 bool TypeVect::singleton(void) const {
2157 // There is no Con node for vectors yet.
2158 // return _elem->singleton();
2159 return false;
2160 }
2162 bool TypeVect::empty(void) const {
2163 return _elem->empty();
2164 }
2166 //------------------------------dump2------------------------------------------
2167 #ifndef PRODUCT
2168 void TypeVect::dump2(Dict &d, uint depth, outputStream *st) const {
2169 switch (base()) {
2170 case VectorS:
2171 st->print("vectors["); break;
2172 case VectorD:
2173 st->print("vectord["); break;
2174 case VectorX:
2175 st->print("vectorx["); break;
2176 case VectorY:
2177 st->print("vectory["); break;
2178 default:
2179 ShouldNotReachHere();
2180 }
2181 st->print("%d]:{", _length);
2182 _elem->dump2(d, depth, st);
2183 st->print("}");
2184 }
2185 #endif
2188 //=============================================================================
2189 // Convenience common pre-built types.
2190 const TypePtr *TypePtr::NULL_PTR;
2191 const TypePtr *TypePtr::NOTNULL;
2192 const TypePtr *TypePtr::BOTTOM;
2194 //------------------------------meet-------------------------------------------
2195 // Meet over the PTR enum
2196 const TypePtr::PTR TypePtr::ptr_meet[TypePtr::lastPTR][TypePtr::lastPTR] = {
2197 // TopPTR, AnyNull, Constant, Null, NotNull, BotPTR,
2198 { /* Top */ TopPTR, AnyNull, Constant, Null, NotNull, BotPTR,},
2199 { /* AnyNull */ AnyNull, AnyNull, Constant, BotPTR, NotNull, BotPTR,},
2200 { /* Constant*/ Constant, Constant, Constant, BotPTR, NotNull, BotPTR,},
2201 { /* Null */ Null, BotPTR, BotPTR, Null, BotPTR, BotPTR,},
2202 { /* NotNull */ NotNull, NotNull, NotNull, BotPTR, NotNull, BotPTR,},
2203 { /* BotPTR */ BotPTR, BotPTR, BotPTR, BotPTR, BotPTR, BotPTR,}
2204 };
2206 //------------------------------make-------------------------------------------
2207 const TypePtr *TypePtr::make( TYPES t, enum PTR ptr, int offset ) {
2208 return (TypePtr*)(new TypePtr(t,ptr,offset))->hashcons();
2209 }
2211 //------------------------------cast_to_ptr_type-------------------------------
2212 const Type *TypePtr::cast_to_ptr_type(PTR ptr) const {
2213 assert(_base == AnyPtr, "subclass must override cast_to_ptr_type");
2214 if( ptr == _ptr ) return this;
2215 return make(_base, ptr, _offset);
2216 }
2218 //------------------------------get_con----------------------------------------
2219 intptr_t TypePtr::get_con() const {
2220 assert( _ptr == Null, "" );
2221 return _offset;
2222 }
2224 //------------------------------meet-------------------------------------------
2225 // Compute the MEET of two types. It returns a new Type object.
2226 const Type *TypePtr::xmeet( const Type *t ) const {
2227 // Perform a fast test for common case; meeting the same types together.
2228 if( this == t ) return this; // Meeting same type-rep?
2230 // Current "this->_base" is AnyPtr
2231 switch (t->base()) { // switch on original type
2232 case Int: // Mixing ints & oops happens when javac
2233 case Long: // reuses local variables
2234 case FloatTop:
2235 case FloatCon:
2236 case FloatBot:
2237 case DoubleTop:
2238 case DoubleCon:
2239 case DoubleBot:
2240 case NarrowOop:
2241 case NarrowKlass:
2242 case Bottom: // Ye Olde Default
2243 return Type::BOTTOM;
2244 case Top:
2245 return this;
2247 case AnyPtr: { // Meeting to AnyPtrs
2248 const TypePtr *tp = t->is_ptr();
2249 return make( AnyPtr, meet_ptr(tp->ptr()), meet_offset(tp->offset()) );
2250 }
2251 case RawPtr: // For these, flip the call around to cut down
2252 case OopPtr:
2253 case InstPtr: // on the cases I have to handle.
2254 case AryPtr:
2255 case MetadataPtr:
2256 case KlassPtr:
2257 return t->xmeet(this); // Call in reverse direction
2258 default: // All else is a mistake
2259 typerr(t);
2261 }
2262 return this;
2263 }
2265 //------------------------------meet_offset------------------------------------
2266 int TypePtr::meet_offset( int offset ) const {
2267 // Either is 'TOP' offset? Return the other offset!
2268 if( _offset == OffsetTop ) return offset;
2269 if( offset == OffsetTop ) return _offset;
2270 // If either is different, return 'BOTTOM' offset
2271 if( _offset != offset ) return OffsetBot;
2272 return _offset;
2273 }
2275 //------------------------------dual_offset------------------------------------
2276 int TypePtr::dual_offset( ) const {
2277 if( _offset == OffsetTop ) return OffsetBot;// Map 'TOP' into 'BOTTOM'
2278 if( _offset == OffsetBot ) return OffsetTop;// Map 'BOTTOM' into 'TOP'
2279 return _offset; // Map everything else into self
2280 }
2282 //------------------------------xdual------------------------------------------
2283 // Dual: compute field-by-field dual
2284 const TypePtr::PTR TypePtr::ptr_dual[TypePtr::lastPTR] = {
2285 BotPTR, NotNull, Constant, Null, AnyNull, TopPTR
2286 };
2287 const Type *TypePtr::xdual() const {
2288 return new TypePtr( AnyPtr, dual_ptr(), dual_offset() );
2289 }
2291 //------------------------------xadd_offset------------------------------------
2292 int TypePtr::xadd_offset( intptr_t offset ) const {
2293 // Adding to 'TOP' offset? Return 'TOP'!
2294 if( _offset == OffsetTop || offset == OffsetTop ) return OffsetTop;
2295 // Adding to 'BOTTOM' offset? Return 'BOTTOM'!
2296 if( _offset == OffsetBot || offset == OffsetBot ) return OffsetBot;
2297 // Addition overflows or "accidentally" equals to OffsetTop? Return 'BOTTOM'!
2298 offset += (intptr_t)_offset;
2299 if (offset != (int)offset || offset == OffsetTop) return OffsetBot;
2301 // assert( _offset >= 0 && _offset+offset >= 0, "" );
2302 // It is possible to construct a negative offset during PhaseCCP
2304 return (int)offset; // Sum valid offsets
2305 }
2307 //------------------------------add_offset-------------------------------------
2308 const TypePtr *TypePtr::add_offset( intptr_t offset ) const {
2309 return make( AnyPtr, _ptr, xadd_offset(offset) );
2310 }
2312 //------------------------------eq---------------------------------------------
2313 // Structural equality check for Type representations
2314 bool TypePtr::eq( const Type *t ) const {
2315 const TypePtr *a = (const TypePtr*)t;
2316 return _ptr == a->ptr() && _offset == a->offset();
2317 }
2319 //------------------------------hash-------------------------------------------
2320 // Type-specific hashing function.
2321 int TypePtr::hash(void) const {
2322 return java_add(_ptr, _offset);
2323 }
2325 //------------------------------dump2------------------------------------------
2326 const char *const TypePtr::ptr_msg[TypePtr::lastPTR] = {
2327 "TopPTR","AnyNull","Constant","NULL","NotNull","BotPTR"
2328 };
2330 #ifndef PRODUCT
2331 void TypePtr::dump2( Dict &d, uint depth, outputStream *st ) const {
2332 if( _ptr == Null ) st->print("NULL");
2333 else st->print("%s *", ptr_msg[_ptr]);
2334 if( _offset == OffsetTop ) st->print("+top");
2335 else if( _offset == OffsetBot ) st->print("+bot");
2336 else if( _offset ) st->print("+%d", _offset);
2337 }
2338 #endif
2340 //------------------------------singleton--------------------------------------
2341 // TRUE if Type is a singleton type, FALSE otherwise. Singletons are simple
2342 // constants
2343 bool TypePtr::singleton(void) const {
2344 // TopPTR, Null, AnyNull, Constant are all singletons
2345 return (_offset != OffsetBot) && !below_centerline(_ptr);
2346 }
2348 bool TypePtr::empty(void) const {
2349 return (_offset == OffsetTop) || above_centerline(_ptr);
2350 }
2352 //=============================================================================
2353 // Convenience common pre-built types.
2354 const TypeRawPtr *TypeRawPtr::BOTTOM;
2355 const TypeRawPtr *TypeRawPtr::NOTNULL;
2357 //------------------------------make-------------------------------------------
2358 const TypeRawPtr *TypeRawPtr::make( enum PTR ptr ) {
2359 assert( ptr != Constant, "what is the constant?" );
2360 assert( ptr != Null, "Use TypePtr for NULL" );
2361 return (TypeRawPtr*)(new TypeRawPtr(ptr,0))->hashcons();
2362 }
2364 const TypeRawPtr *TypeRawPtr::make( address bits ) {
2365 assert( bits, "Use TypePtr for NULL" );
2366 return (TypeRawPtr*)(new TypeRawPtr(Constant,bits))->hashcons();
2367 }
2369 //------------------------------cast_to_ptr_type-------------------------------
2370 const Type *TypeRawPtr::cast_to_ptr_type(PTR ptr) const {
2371 assert( ptr != Constant, "what is the constant?" );
2372 assert( ptr != Null, "Use TypePtr for NULL" );
2373 assert( _bits==0, "Why cast a constant address?");
2374 if( ptr == _ptr ) return this;
2375 return make(ptr);
2376 }
2378 //------------------------------get_con----------------------------------------
2379 intptr_t TypeRawPtr::get_con() const {
2380 assert( _ptr == Null || _ptr == Constant, "" );
2381 return (intptr_t)_bits;
2382 }
2384 //------------------------------meet-------------------------------------------
2385 // Compute the MEET of two types. It returns a new Type object.
2386 const Type *TypeRawPtr::xmeet( const Type *t ) const {
2387 // Perform a fast test for common case; meeting the same types together.
2388 if( this == t ) return this; // Meeting same type-rep?
2390 // Current "this->_base" is RawPtr
2391 switch( t->base() ) { // switch on original type
2392 case Bottom: // Ye Olde Default
2393 return t;
2394 case Top:
2395 return this;
2396 case AnyPtr: // Meeting to AnyPtrs
2397 break;
2398 case RawPtr: { // might be top, bot, any/not or constant
2399 enum PTR tptr = t->is_ptr()->ptr();
2400 enum PTR ptr = meet_ptr( tptr );
2401 if( ptr == Constant ) { // Cannot be equal constants, so...
2402 if( tptr == Constant && _ptr != Constant) return t;
2403 if( _ptr == Constant && tptr != Constant) return this;
2404 ptr = NotNull; // Fall down in lattice
2405 }
2406 return make( ptr );
2407 }
2409 case OopPtr:
2410 case InstPtr:
2411 case AryPtr:
2412 case MetadataPtr:
2413 case KlassPtr:
2414 return TypePtr::BOTTOM; // Oop meet raw is not well defined
2415 default: // All else is a mistake
2416 typerr(t);
2417 }
2419 // Found an AnyPtr type vs self-RawPtr type
2420 const TypePtr *tp = t->is_ptr();
2421 switch (tp->ptr()) {
2422 case TypePtr::TopPTR: return this;
2423 case TypePtr::BotPTR: return t;
2424 case TypePtr::Null:
2425 if( _ptr == TypePtr::TopPTR ) return t;
2426 return TypeRawPtr::BOTTOM;
2427 case TypePtr::NotNull: return TypePtr::make( AnyPtr, meet_ptr(TypePtr::NotNull), tp->meet_offset(0) );
2428 case TypePtr::AnyNull:
2429 if( _ptr == TypePtr::Constant) return this;
2430 return make( meet_ptr(TypePtr::AnyNull) );
2431 default: ShouldNotReachHere();
2432 }
2433 return this;
2434 }
2436 //------------------------------xdual------------------------------------------
2437 // Dual: compute field-by-field dual
2438 const Type *TypeRawPtr::xdual() const {
2439 return new TypeRawPtr( dual_ptr(), _bits );
2440 }
2442 //------------------------------add_offset-------------------------------------
2443 const TypePtr *TypeRawPtr::add_offset( intptr_t offset ) const {
2444 if( offset == OffsetTop ) return BOTTOM; // Undefined offset-> undefined pointer
2445 if( offset == OffsetBot ) return BOTTOM; // Unknown offset-> unknown pointer
2446 if( offset == 0 ) return this; // No change
2447 switch (_ptr) {
2448 case TypePtr::TopPTR:
2449 case TypePtr::BotPTR:
2450 case TypePtr::NotNull:
2451 return this;
2452 case TypePtr::Null:
2453 case TypePtr::Constant: {
2454 address bits = _bits+offset;
2455 if ( bits == 0 ) return TypePtr::NULL_PTR;
2456 return make( bits );
2457 }
2458 default: ShouldNotReachHere();
2459 }
2460 return NULL; // Lint noise
2461 }
2463 //------------------------------eq---------------------------------------------
2464 // Structural equality check for Type representations
2465 bool TypeRawPtr::eq( const Type *t ) const {
2466 const TypeRawPtr *a = (const TypeRawPtr*)t;
2467 return _bits == a->_bits && TypePtr::eq(t);
2468 }
2470 //------------------------------hash-------------------------------------------
2471 // Type-specific hashing function.
2472 int TypeRawPtr::hash(void) const {
2473 return (intptr_t)_bits + TypePtr::hash();
2474 }
2476 //------------------------------dump2------------------------------------------
2477 #ifndef PRODUCT
2478 void TypeRawPtr::dump2( Dict &d, uint depth, outputStream *st ) const {
2479 if( _ptr == Constant )
2480 st->print(INTPTR_FORMAT, _bits);
2481 else
2482 st->print("rawptr:%s", ptr_msg[_ptr]);
2483 }
2484 #endif
2486 //=============================================================================
2487 // Convenience common pre-built type.
2488 const TypeOopPtr *TypeOopPtr::BOTTOM;
2490 //------------------------------TypeOopPtr-------------------------------------
2491 TypeOopPtr::TypeOopPtr(TYPES t, PTR ptr, ciKlass* k, bool xk, ciObject* o, int offset, int instance_id, const TypeOopPtr* speculative, int inline_depth)
2492 : TypePtr(t, ptr, offset),
2493 _const_oop(o), _klass(k),
2494 _klass_is_exact(xk),
2495 _is_ptr_to_narrowoop(false),
2496 _is_ptr_to_narrowklass(false),
2497 _is_ptr_to_boxed_value(false),
2498 _instance_id(instance_id),
2499 _speculative(speculative),
2500 _inline_depth(inline_depth){
2501 if (Compile::current()->eliminate_boxing() && (t == InstPtr) &&
2502 (offset > 0) && xk && (k != 0) && k->is_instance_klass()) {
2503 _is_ptr_to_boxed_value = k->as_instance_klass()->is_boxed_value_offset(offset);
2504 }
2505 #ifdef _LP64
2506 if (_offset != 0) {
2507 if (_offset == oopDesc::klass_offset_in_bytes()) {
2508 _is_ptr_to_narrowklass = UseCompressedClassPointers;
2509 } else if (klass() == NULL) {
2510 // Array with unknown body type
2511 assert(this->isa_aryptr(), "only arrays without klass");
2512 _is_ptr_to_narrowoop = UseCompressedOops;
2513 } else if (this->isa_aryptr()) {
2514 _is_ptr_to_narrowoop = (UseCompressedOops && klass()->is_obj_array_klass() &&
2515 _offset != arrayOopDesc::length_offset_in_bytes());
2516 } else if (klass()->is_instance_klass()) {
2517 ciInstanceKlass* ik = klass()->as_instance_klass();
2518 ciField* field = NULL;
2519 if (this->isa_klassptr()) {
2520 // Perm objects don't use compressed references
2521 } else if (_offset == OffsetBot || _offset == OffsetTop) {
2522 // unsafe access
2523 _is_ptr_to_narrowoop = UseCompressedOops;
2524 } else { // exclude unsafe ops
2525 assert(this->isa_instptr(), "must be an instance ptr.");
2527 if (klass() == ciEnv::current()->Class_klass() &&
2528 (_offset == java_lang_Class::klass_offset_in_bytes() ||
2529 _offset == java_lang_Class::array_klass_offset_in_bytes())) {
2530 // Special hidden fields from the Class.
2531 assert(this->isa_instptr(), "must be an instance ptr.");
2532 _is_ptr_to_narrowoop = false;
2533 } else if (klass() == ciEnv::current()->Class_klass() &&
2534 _offset >= InstanceMirrorKlass::offset_of_static_fields()) {
2535 // Static fields
2536 assert(o != NULL, "must be constant");
2537 ciInstanceKlass* k = o->as_instance()->java_lang_Class_klass()->as_instance_klass();
2538 ciField* field = k->get_field_by_offset(_offset, true);
2539 assert(field != NULL, "missing field");
2540 BasicType basic_elem_type = field->layout_type();
2541 _is_ptr_to_narrowoop = UseCompressedOops && (basic_elem_type == T_OBJECT ||
2542 basic_elem_type == T_ARRAY);
2543 } else {
2544 // Instance fields which contains a compressed oop references.
2545 field = ik->get_field_by_offset(_offset, false);
2546 if (field != NULL) {
2547 BasicType basic_elem_type = field->layout_type();
2548 _is_ptr_to_narrowoop = UseCompressedOops && (basic_elem_type == T_OBJECT ||
2549 basic_elem_type == T_ARRAY);
2550 } else if (klass()->equals(ciEnv::current()->Object_klass())) {
2551 // Compile::find_alias_type() cast exactness on all types to verify
2552 // that it does not affect alias type.
2553 _is_ptr_to_narrowoop = UseCompressedOops;
2554 } else {
2555 // Type for the copy start in LibraryCallKit::inline_native_clone().
2556 _is_ptr_to_narrowoop = UseCompressedOops;
2557 }
2558 }
2559 }
2560 }
2561 }
2562 #endif
2563 }
2565 //------------------------------make-------------------------------------------
2566 const TypeOopPtr *TypeOopPtr::make(PTR ptr,
2567 int offset, int instance_id, const TypeOopPtr* speculative, int inline_depth) {
2568 assert(ptr != Constant, "no constant generic pointers");
2569 ciKlass* k = Compile::current()->env()->Object_klass();
2570 bool xk = false;
2571 ciObject* o = NULL;
2572 return (TypeOopPtr*)(new TypeOopPtr(OopPtr, ptr, k, xk, o, offset, instance_id, speculative, inline_depth))->hashcons();
2573 }
2576 //------------------------------cast_to_ptr_type-------------------------------
2577 const Type *TypeOopPtr::cast_to_ptr_type(PTR ptr) const {
2578 assert(_base == OopPtr, "subclass must override cast_to_ptr_type");
2579 if( ptr == _ptr ) return this;
2580 return make(ptr, _offset, _instance_id, _speculative, _inline_depth);
2581 }
2583 //-----------------------------cast_to_instance_id----------------------------
2584 const TypeOopPtr *TypeOopPtr::cast_to_instance_id(int instance_id) const {
2585 // There are no instances of a general oop.
2586 // Return self unchanged.
2587 return this;
2588 }
2590 //-----------------------------cast_to_exactness-------------------------------
2591 const Type *TypeOopPtr::cast_to_exactness(bool klass_is_exact) const {
2592 // There is no such thing as an exact general oop.
2593 // Return self unchanged.
2594 return this;
2595 }
2598 //------------------------------as_klass_type----------------------------------
2599 // Return the klass type corresponding to this instance or array type.
2600 // It is the type that is loaded from an object of this type.
2601 const TypeKlassPtr* TypeOopPtr::as_klass_type() const {
2602 ciKlass* k = klass();
2603 bool xk = klass_is_exact();
2604 if (k == NULL)
2605 return TypeKlassPtr::OBJECT;
2606 else
2607 return TypeKlassPtr::make(xk? Constant: NotNull, k, 0);
2608 }
2610 const Type *TypeOopPtr::xmeet(const Type *t) const {
2611 const Type* res = xmeet_helper(t);
2612 if (res->isa_oopptr() == NULL) {
2613 return res;
2614 }
2616 const TypeOopPtr* res_oopptr = res->is_oopptr();
2617 if (res_oopptr->speculative() != NULL) {
2618 // type->speculative() == NULL means that speculation is no better
2619 // than type, i.e. type->speculative() == type. So there are 2
2620 // ways to represent the fact that we have no useful speculative
2621 // data and we should use a single one to be able to test for
2622 // equality between types. Check whether type->speculative() ==
2623 // type and set speculative to NULL if it is the case.
2624 if (res_oopptr->remove_speculative() == res_oopptr->speculative()) {
2625 return res_oopptr->remove_speculative();
2626 }
2627 }
2629 return res;
2630 }
2632 //------------------------------meet-------------------------------------------
2633 // Compute the MEET of two types. It returns a new Type object.
2634 const Type *TypeOopPtr::xmeet_helper(const Type *t) const {
2635 // Perform a fast test for common case; meeting the same types together.
2636 if( this == t ) return this; // Meeting same type-rep?
2638 // Current "this->_base" is OopPtr
2639 switch (t->base()) { // switch on original type
2641 case Int: // Mixing ints & oops happens when javac
2642 case Long: // reuses local variables
2643 case FloatTop:
2644 case FloatCon:
2645 case FloatBot:
2646 case DoubleTop:
2647 case DoubleCon:
2648 case DoubleBot:
2649 case NarrowOop:
2650 case NarrowKlass:
2651 case Bottom: // Ye Olde Default
2652 return Type::BOTTOM;
2653 case Top:
2654 return this;
2656 default: // All else is a mistake
2657 typerr(t);
2659 case RawPtr:
2660 case MetadataPtr:
2661 case KlassPtr:
2662 return TypePtr::BOTTOM; // Oop meet raw is not well defined
2664 case AnyPtr: {
2665 // Found an AnyPtr type vs self-OopPtr type
2666 const TypePtr *tp = t->is_ptr();
2667 int offset = meet_offset(tp->offset());
2668 PTR ptr = meet_ptr(tp->ptr());
2669 switch (tp->ptr()) {
2670 case Null:
2671 if (ptr == Null) return TypePtr::make(AnyPtr, ptr, offset);
2672 // else fall through:
2673 case TopPTR:
2674 case AnyNull: {
2675 int instance_id = meet_instance_id(InstanceTop);
2676 const TypeOopPtr* speculative = _speculative;
2677 return make(ptr, offset, instance_id, speculative, _inline_depth);
2678 }
2679 case BotPTR:
2680 case NotNull:
2681 return TypePtr::make(AnyPtr, ptr, offset);
2682 default: typerr(t);
2683 }
2684 }
2686 case OopPtr: { // Meeting to other OopPtrs
2687 const TypeOopPtr *tp = t->is_oopptr();
2688 int instance_id = meet_instance_id(tp->instance_id());
2689 const TypeOopPtr* speculative = xmeet_speculative(tp);
2690 int depth = meet_inline_depth(tp->inline_depth());
2691 return make(meet_ptr(tp->ptr()), meet_offset(tp->offset()), instance_id, speculative, depth);
2692 }
2694 case InstPtr: // For these, flip the call around to cut down
2695 case AryPtr:
2696 return t->xmeet(this); // Call in reverse direction
2698 } // End of switch
2699 return this; // Return the double constant
2700 }
2703 //------------------------------xdual------------------------------------------
2704 // Dual of a pure heap pointer. No relevant klass or oop information.
2705 const Type *TypeOopPtr::xdual() const {
2706 assert(klass() == Compile::current()->env()->Object_klass(), "no klasses here");
2707 assert(const_oop() == NULL, "no constants here");
2708 return new TypeOopPtr(_base, dual_ptr(), klass(), klass_is_exact(), const_oop(), dual_offset(), dual_instance_id(), dual_speculative(), dual_inline_depth());
2709 }
2711 //--------------------------make_from_klass_common-----------------------------
2712 // Computes the element-type given a klass.
2713 const TypeOopPtr* TypeOopPtr::make_from_klass_common(ciKlass *klass, bool klass_change, bool try_for_exact) {
2714 if (klass->is_instance_klass()) {
2715 Compile* C = Compile::current();
2716 Dependencies* deps = C->dependencies();
2717 assert((deps != NULL) == (C->method() != NULL && C->method()->code_size() > 0), "sanity");
2718 // Element is an instance
2719 bool klass_is_exact = false;
2720 if (klass->is_loaded()) {
2721 // Try to set klass_is_exact.
2722 ciInstanceKlass* ik = klass->as_instance_klass();
2723 klass_is_exact = ik->is_final();
2724 if (!klass_is_exact && klass_change
2725 && deps != NULL && UseUniqueSubclasses) {
2726 ciInstanceKlass* sub = ik->unique_concrete_subklass();
2727 if (sub != NULL) {
2728 deps->assert_abstract_with_unique_concrete_subtype(ik, sub);
2729 klass = ik = sub;
2730 klass_is_exact = sub->is_final();
2731 }
2732 }
2733 if (!klass_is_exact && try_for_exact
2734 && deps != NULL && UseExactTypes) {
2735 if (!ik->is_interface() && !ik->has_subklass()) {
2736 // Add a dependence; if concrete subclass added we need to recompile
2737 deps->assert_leaf_type(ik);
2738 klass_is_exact = true;
2739 }
2740 }
2741 }
2742 return TypeInstPtr::make(TypePtr::BotPTR, klass, klass_is_exact, NULL, 0);
2743 } else if (klass->is_obj_array_klass()) {
2744 // Element is an object array. Recursively call ourself.
2745 const TypeOopPtr *etype = TypeOopPtr::make_from_klass_common(klass->as_obj_array_klass()->element_klass(), false, try_for_exact);
2746 bool xk = etype->klass_is_exact();
2747 const TypeAry* arr0 = TypeAry::make(etype, TypeInt::POS);
2748 // We used to pass NotNull in here, asserting that the sub-arrays
2749 // are all not-null. This is not true in generally, as code can
2750 // slam NULLs down in the subarrays.
2751 const TypeAryPtr* arr = TypeAryPtr::make(TypePtr::BotPTR, arr0, klass, xk, 0);
2752 return arr;
2753 } else if (klass->is_type_array_klass()) {
2754 // Element is an typeArray
2755 const Type* etype = get_const_basic_type(klass->as_type_array_klass()->element_type());
2756 const TypeAry* arr0 = TypeAry::make(etype, TypeInt::POS);
2757 // We used to pass NotNull in here, asserting that the array pointer
2758 // is not-null. That was not true in general.
2759 const TypeAryPtr* arr = TypeAryPtr::make(TypePtr::BotPTR, arr0, klass, true, 0);
2760 return arr;
2761 } else {
2762 ShouldNotReachHere();
2763 return NULL;
2764 }
2765 }
2767 //------------------------------make_from_constant-----------------------------
2768 // Make a java pointer from an oop constant
2769 const TypeOopPtr* TypeOopPtr::make_from_constant(ciObject* o,
2770 bool require_constant,
2771 bool is_autobox_cache) {
2772 assert(!o->is_null_object(), "null object not yet handled here.");
2773 ciKlass* klass = o->klass();
2774 if (klass->is_instance_klass()) {
2775 // Element is an instance
2776 if (require_constant) {
2777 if (!o->can_be_constant()) return NULL;
2778 } else if (!o->should_be_constant()) {
2779 return TypeInstPtr::make(TypePtr::NotNull, klass, true, NULL, 0);
2780 }
2781 return TypeInstPtr::make(o);
2782 } else if (klass->is_obj_array_klass()) {
2783 // Element is an object array. Recursively call ourself.
2784 const TypeOopPtr *etype =
2785 TypeOopPtr::make_from_klass_raw(klass->as_obj_array_klass()->element_klass());
2786 if (is_autobox_cache) {
2787 // The pointers in the autobox arrays are always non-null.
2788 etype = etype->cast_to_ptr_type(TypePtr::NotNull)->is_oopptr();
2789 }
2790 const TypeAry* arr0 = TypeAry::make(etype, TypeInt::make(o->as_array()->length()));
2791 // We used to pass NotNull in here, asserting that the sub-arrays
2792 // are all not-null. This is not true in generally, as code can
2793 // slam NULLs down in the subarrays.
2794 if (require_constant) {
2795 if (!o->can_be_constant()) return NULL;
2796 } else if (!o->should_be_constant()) {
2797 return TypeAryPtr::make(TypePtr::NotNull, arr0, klass, true, 0);
2798 }
2799 const TypeAryPtr* arr = TypeAryPtr::make(TypePtr::Constant, o, arr0, klass, true, 0, InstanceBot, NULL, InlineDepthBottom, is_autobox_cache);
2800 return arr;
2801 } else if (klass->is_type_array_klass()) {
2802 // Element is an typeArray
2803 const Type* etype =
2804 (Type*)get_const_basic_type(klass->as_type_array_klass()->element_type());
2805 const TypeAry* arr0 = TypeAry::make(etype, TypeInt::make(o->as_array()->length()));
2806 // We used to pass NotNull in here, asserting that the array pointer
2807 // is not-null. That was not true in general.
2808 if (require_constant) {
2809 if (!o->can_be_constant()) return NULL;
2810 } else if (!o->should_be_constant()) {
2811 return TypeAryPtr::make(TypePtr::NotNull, arr0, klass, true, 0);
2812 }
2813 const TypeAryPtr* arr = TypeAryPtr::make(TypePtr::Constant, o, arr0, klass, true, 0);
2814 return arr;
2815 }
2817 fatal("unhandled object type");
2818 return NULL;
2819 }
2821 //------------------------------get_con----------------------------------------
2822 intptr_t TypeOopPtr::get_con() const {
2823 assert( _ptr == Null || _ptr == Constant, "" );
2824 assert( _offset >= 0, "" );
2826 if (_offset != 0) {
2827 // After being ported to the compiler interface, the compiler no longer
2828 // directly manipulates the addresses of oops. Rather, it only has a pointer
2829 // to a handle at compile time. This handle is embedded in the generated
2830 // code and dereferenced at the time the nmethod is made. Until that time,
2831 // it is not reasonable to do arithmetic with the addresses of oops (we don't
2832 // have access to the addresses!). This does not seem to currently happen,
2833 // but this assertion here is to help prevent its occurence.
2834 tty->print_cr("Found oop constant with non-zero offset");
2835 ShouldNotReachHere();
2836 }
2838 return (intptr_t)const_oop()->constant_encoding();
2839 }
2842 //-----------------------------filter------------------------------------------
2843 // Do not allow interface-vs.-noninterface joins to collapse to top.
2844 const Type *TypeOopPtr::filter_helper(const Type *kills, bool include_speculative) const {
2846 const Type* ft = join_helper(kills, include_speculative);
2847 const TypeInstPtr* ftip = ft->isa_instptr();
2848 const TypeInstPtr* ktip = kills->isa_instptr();
2850 if (ft->empty()) {
2851 // Check for evil case of 'this' being a class and 'kills' expecting an
2852 // interface. This can happen because the bytecodes do not contain
2853 // enough type info to distinguish a Java-level interface variable
2854 // from a Java-level object variable. If we meet 2 classes which
2855 // both implement interface I, but their meet is at 'j/l/O' which
2856 // doesn't implement I, we have no way to tell if the result should
2857 // be 'I' or 'j/l/O'. Thus we'll pick 'j/l/O'. If this then flows
2858 // into a Phi which "knows" it's an Interface type we'll have to
2859 // uplift the type.
2860 if (!empty()) {
2861 if (ktip != NULL && ktip->is_loaded() && ktip->klass()->is_interface()) {
2862 return kills; // Uplift to interface
2863 }
2864 // Also check for evil cases of 'this' being a class array
2865 // and 'kills' expecting an array of interfaces.
2866 Type::get_arrays_base_elements(ft, kills, NULL, &ktip);
2867 if (ktip != NULL && ktip->is_loaded() && ktip->klass()->is_interface()) {
2868 return kills; // Uplift to array of interface
2869 }
2870 }
2872 return Type::TOP; // Canonical empty value
2873 }
2875 // If we have an interface-typed Phi or cast and we narrow to a class type,
2876 // the join should report back the class. However, if we have a J/L/Object
2877 // class-typed Phi and an interface flows in, it's possible that the meet &
2878 // join report an interface back out. This isn't possible but happens
2879 // because the type system doesn't interact well with interfaces.
2880 if (ftip != NULL && ktip != NULL &&
2881 ftip->is_loaded() && ftip->klass()->is_interface() &&
2882 ktip->is_loaded() && !ktip->klass()->is_interface()) {
2883 // Happens in a CTW of rt.jar, 320-341, no extra flags
2884 assert(!ftip->klass_is_exact(), "interface could not be exact");
2885 return ktip->cast_to_ptr_type(ftip->ptr());
2886 }
2888 return ft;
2889 }
2891 //------------------------------eq---------------------------------------------
2892 // Structural equality check for Type representations
2893 bool TypeOopPtr::eq( const Type *t ) const {
2894 const TypeOopPtr *a = (const TypeOopPtr*)t;
2895 if (_klass_is_exact != a->_klass_is_exact ||
2896 _instance_id != a->_instance_id ||
2897 !eq_speculative(a) ||
2898 _inline_depth != a->_inline_depth) return false;
2899 ciObject* one = const_oop();
2900 ciObject* two = a->const_oop();
2901 if (one == NULL || two == NULL) {
2902 return (one == two) && TypePtr::eq(t);
2903 } else {
2904 return one->equals(two) && TypePtr::eq(t);
2905 }
2906 }
2908 //------------------------------hash-------------------------------------------
2909 // Type-specific hashing function.
2910 int TypeOopPtr::hash(void) const {
2911 return
2912 java_add(java_add(java_add(const_oop() ? const_oop()->hash() : 0, _klass_is_exact),
2913 java_add(_instance_id , hash_speculative())), java_add(_inline_depth , TypePtr::hash()));
2914 }
2916 //------------------------------dump2------------------------------------------
2917 #ifndef PRODUCT
2918 void TypeOopPtr::dump2( Dict &d, uint depth, outputStream *st ) const {
2919 st->print("oopptr:%s", ptr_msg[_ptr]);
2920 if( _klass_is_exact ) st->print(":exact");
2921 if( const_oop() ) st->print(INTPTR_FORMAT, const_oop());
2922 switch( _offset ) {
2923 case OffsetTop: st->print("+top"); break;
2924 case OffsetBot: st->print("+any"); break;
2925 case 0: break;
2926 default: st->print("+%d",_offset); break;
2927 }
2928 if (_instance_id == InstanceTop)
2929 st->print(",iid=top");
2930 else if (_instance_id != InstanceBot)
2931 st->print(",iid=%d",_instance_id);
2933 dump_inline_depth(st);
2934 dump_speculative(st);
2935 }
2937 /**
2938 *dump the speculative part of the type
2939 */
2940 void TypeOopPtr::dump_speculative(outputStream *st) const {
2941 if (_speculative != NULL) {
2942 st->print(" (speculative=");
2943 _speculative->dump_on(st);
2944 st->print(")");
2945 }
2946 }
2948 void TypeOopPtr::dump_inline_depth(outputStream *st) const {
2949 if (_inline_depth != InlineDepthBottom) {
2950 if (_inline_depth == InlineDepthTop) {
2951 st->print(" (inline_depth=InlineDepthTop)");
2952 } else {
2953 st->print(" (inline_depth=%d)", _inline_depth);
2954 }
2955 }
2956 }
2957 #endif
2959 //------------------------------singleton--------------------------------------
2960 // TRUE if Type is a singleton type, FALSE otherwise. Singletons are simple
2961 // constants
2962 bool TypeOopPtr::singleton(void) const {
2963 // detune optimizer to not generate constant oop + constant offset as a constant!
2964 // TopPTR, Null, AnyNull, Constant are all singletons
2965 return (_offset == 0) && !below_centerline(_ptr);
2966 }
2968 //------------------------------add_offset-------------------------------------
2969 const TypePtr *TypeOopPtr::add_offset(intptr_t offset) const {
2970 return make(_ptr, xadd_offset(offset), _instance_id, add_offset_speculative(offset), _inline_depth);
2971 }
2973 /**
2974 * Return same type without a speculative part
2975 */
2976 const Type* TypeOopPtr::remove_speculative() const {
2977 if (_speculative == NULL) {
2978 return this;
2979 }
2980 assert(_inline_depth == InlineDepthTop || _inline_depth == InlineDepthBottom, "non speculative type shouldn't have inline depth");
2981 return make(_ptr, _offset, _instance_id, NULL, _inline_depth);
2982 }
2984 /**
2985 * Return same type but with a different inline depth (used for speculation)
2986 *
2987 * @param depth depth to meet with
2988 */
2989 const TypeOopPtr* TypeOopPtr::with_inline_depth(int depth) const {
2990 if (!UseInlineDepthForSpeculativeTypes) {
2991 return this;
2992 }
2993 return make(_ptr, _offset, _instance_id, _speculative, depth);
2994 }
2996 /**
2997 * Check whether new profiling would improve speculative type
2998 *
2999 * @param exact_kls class from profiling
3000 * @param inline_depth inlining depth of profile point
3001 *
3002 * @return true if type profile is valuable
3003 */
3004 bool TypeOopPtr::would_improve_type(ciKlass* exact_kls, int inline_depth) const {
3005 // no way to improve an already exact type
3006 if (klass_is_exact()) {
3007 return false;
3008 }
3009 // no profiling?
3010 if (exact_kls == NULL) {
3011 return false;
3012 }
3013 // no speculative type or non exact speculative type?
3014 if (speculative_type() == NULL) {
3015 return true;
3016 }
3017 // If the node already has an exact speculative type keep it,
3018 // unless it was provided by profiling that is at a deeper
3019 // inlining level. Profiling at a higher inlining depth is
3020 // expected to be less accurate.
3021 if (_speculative->inline_depth() == InlineDepthBottom) {
3022 return false;
3023 }
3024 assert(_speculative->inline_depth() != InlineDepthTop, "can't do the comparison");
3025 return inline_depth < _speculative->inline_depth();
3026 }
3028 //------------------------------meet_instance_id--------------------------------
3029 int TypeOopPtr::meet_instance_id( int instance_id ) const {
3030 // Either is 'TOP' instance? Return the other instance!
3031 if( _instance_id == InstanceTop ) return instance_id;
3032 if( instance_id == InstanceTop ) return _instance_id;
3033 // If either is different, return 'BOTTOM' instance
3034 if( _instance_id != instance_id ) return InstanceBot;
3035 return _instance_id;
3036 }
3038 //------------------------------dual_instance_id--------------------------------
3039 int TypeOopPtr::dual_instance_id( ) const {
3040 if( _instance_id == InstanceTop ) return InstanceBot; // Map TOP into BOTTOM
3041 if( _instance_id == InstanceBot ) return InstanceTop; // Map BOTTOM into TOP
3042 return _instance_id; // Map everything else into self
3043 }
3045 /**
3046 * meet of the speculative parts of 2 types
3047 *
3048 * @param other type to meet with
3049 */
3050 const TypeOopPtr* TypeOopPtr::xmeet_speculative(const TypeOopPtr* other) const {
3051 bool this_has_spec = (_speculative != NULL);
3052 bool other_has_spec = (other->speculative() != NULL);
3054 if (!this_has_spec && !other_has_spec) {
3055 return NULL;
3056 }
3058 // If we are at a point where control flow meets and one branch has
3059 // a speculative type and the other has not, we meet the speculative
3060 // type of one branch with the actual type of the other. If the
3061 // actual type is exact and the speculative is as well, then the
3062 // result is a speculative type which is exact and we can continue
3063 // speculation further.
3064 const TypeOopPtr* this_spec = _speculative;
3065 const TypeOopPtr* other_spec = other->speculative();
3067 if (!this_has_spec) {
3068 this_spec = this;
3069 }
3071 if (!other_has_spec) {
3072 other_spec = other;
3073 }
3075 return this_spec->meet_speculative(other_spec)->is_oopptr();
3076 }
3078 /**
3079 * dual of the speculative part of the type
3080 */
3081 const TypeOopPtr* TypeOopPtr::dual_speculative() const {
3082 if (_speculative == NULL) {
3083 return NULL;
3084 }
3085 return _speculative->dual()->is_oopptr();
3086 }
3088 /**
3089 * add offset to the speculative part of the type
3090 *
3091 * @param offset offset to add
3092 */
3093 const TypeOopPtr* TypeOopPtr::add_offset_speculative(intptr_t offset) const {
3094 if (_speculative == NULL) {
3095 return NULL;
3096 }
3097 return _speculative->add_offset(offset)->is_oopptr();
3098 }
3100 /**
3101 * Are the speculative parts of 2 types equal?
3102 *
3103 * @param other type to compare this one to
3104 */
3105 bool TypeOopPtr::eq_speculative(const TypeOopPtr* other) const {
3106 if (_speculative == NULL || other->speculative() == NULL) {
3107 return _speculative == other->speculative();
3108 }
3110 if (_speculative->base() != other->speculative()->base()) {
3111 return false;
3112 }
3114 return _speculative->eq(other->speculative());
3115 }
3117 /**
3118 * Hash of the speculative part of the type
3119 */
3120 int TypeOopPtr::hash_speculative() const {
3121 if (_speculative == NULL) {
3122 return 0;
3123 }
3125 return _speculative->hash();
3126 }
3128 /**
3129 * dual of the inline depth for this type (used for speculation)
3130 */
3131 int TypeOopPtr::dual_inline_depth() const {
3132 return -inline_depth();
3133 }
3135 /**
3136 * meet of 2 inline depth (used for speculation)
3137 *
3138 * @param depth depth to meet with
3139 */
3140 int TypeOopPtr::meet_inline_depth(int depth) const {
3141 return MAX2(inline_depth(), depth);
3142 }
3144 //=============================================================================
3145 // Convenience common pre-built types.
3146 const TypeInstPtr *TypeInstPtr::NOTNULL;
3147 const TypeInstPtr *TypeInstPtr::BOTTOM;
3148 const TypeInstPtr *TypeInstPtr::MIRROR;
3149 const TypeInstPtr *TypeInstPtr::MARK;
3150 const TypeInstPtr *TypeInstPtr::KLASS;
3152 //------------------------------TypeInstPtr-------------------------------------
3153 TypeInstPtr::TypeInstPtr(PTR ptr, ciKlass* k, bool xk, ciObject* o, int off, int instance_id, const TypeOopPtr* speculative, int inline_depth)
3154 : TypeOopPtr(InstPtr, ptr, k, xk, o, off, instance_id, speculative, inline_depth), _name(k->name()) {
3155 assert(k != NULL &&
3156 (k->is_loaded() || o == NULL),
3157 "cannot have constants with non-loaded klass");
3158 };
3160 //------------------------------make-------------------------------------------
3161 const TypeInstPtr *TypeInstPtr::make(PTR ptr,
3162 ciKlass* k,
3163 bool xk,
3164 ciObject* o,
3165 int offset,
3166 int instance_id,
3167 const TypeOopPtr* speculative,
3168 int inline_depth) {
3169 assert( !k->is_loaded() || k->is_instance_klass(), "Must be for instance");
3170 // Either const_oop() is NULL or else ptr is Constant
3171 assert( (!o && ptr != Constant) || (o && ptr == Constant),
3172 "constant pointers must have a value supplied" );
3173 // Ptr is never Null
3174 assert( ptr != Null, "NULL pointers are not typed" );
3176 assert(instance_id <= 0 || xk || !UseExactTypes, "instances are always exactly typed");
3177 if (!UseExactTypes) xk = false;
3178 if (ptr == Constant) {
3179 // Note: This case includes meta-object constants, such as methods.
3180 xk = true;
3181 } else if (k->is_loaded()) {
3182 ciInstanceKlass* ik = k->as_instance_klass();
3183 if (!xk && ik->is_final()) xk = true; // no inexact final klass
3184 if (xk && ik->is_interface()) xk = false; // no exact interface
3185 }
3187 // Now hash this baby
3188 TypeInstPtr *result =
3189 (TypeInstPtr*)(new TypeInstPtr(ptr, k, xk, o ,offset, instance_id, speculative, inline_depth))->hashcons();
3191 return result;
3192 }
3194 /**
3195 * Create constant type for a constant boxed value
3196 */
3197 const Type* TypeInstPtr::get_const_boxed_value() const {
3198 assert(is_ptr_to_boxed_value(), "should be called only for boxed value");
3199 assert((const_oop() != NULL), "should be called only for constant object");
3200 ciConstant constant = const_oop()->as_instance()->field_value_by_offset(offset());
3201 BasicType bt = constant.basic_type();
3202 switch (bt) {
3203 case T_BOOLEAN: return TypeInt::make(constant.as_boolean());
3204 case T_INT: return TypeInt::make(constant.as_int());
3205 case T_CHAR: return TypeInt::make(constant.as_char());
3206 case T_BYTE: return TypeInt::make(constant.as_byte());
3207 case T_SHORT: return TypeInt::make(constant.as_short());
3208 case T_FLOAT: return TypeF::make(constant.as_float());
3209 case T_DOUBLE: return TypeD::make(constant.as_double());
3210 case T_LONG: return TypeLong::make(constant.as_long());
3211 default: break;
3212 }
3213 fatal(err_msg_res("Invalid boxed value type '%s'", type2name(bt)));
3214 return NULL;
3215 }
3217 //------------------------------cast_to_ptr_type-------------------------------
3218 const Type *TypeInstPtr::cast_to_ptr_type(PTR ptr) const {
3219 if( ptr == _ptr ) return this;
3220 // Reconstruct _sig info here since not a problem with later lazy
3221 // construction, _sig will show up on demand.
3222 return make(ptr, klass(), klass_is_exact(), const_oop(), _offset, _instance_id, _speculative, _inline_depth);
3223 }
3226 //-----------------------------cast_to_exactness-------------------------------
3227 const Type *TypeInstPtr::cast_to_exactness(bool klass_is_exact) const {
3228 if( klass_is_exact == _klass_is_exact ) return this;
3229 if (!UseExactTypes) return this;
3230 if (!_klass->is_loaded()) return this;
3231 ciInstanceKlass* ik = _klass->as_instance_klass();
3232 if( (ik->is_final() || _const_oop) ) return this; // cannot clear xk
3233 if( ik->is_interface() ) return this; // cannot set xk
3234 return make(ptr(), klass(), klass_is_exact, const_oop(), _offset, _instance_id, _speculative, _inline_depth);
3235 }
3237 //-----------------------------cast_to_instance_id----------------------------
3238 const TypeOopPtr *TypeInstPtr::cast_to_instance_id(int instance_id) const {
3239 if( instance_id == _instance_id ) return this;
3240 return make(_ptr, klass(), _klass_is_exact, const_oop(), _offset, instance_id, _speculative, _inline_depth);
3241 }
3243 //------------------------------xmeet_unloaded---------------------------------
3244 // Compute the MEET of two InstPtrs when at least one is unloaded.
3245 // Assume classes are different since called after check for same name/class-loader
3246 const TypeInstPtr *TypeInstPtr::xmeet_unloaded(const TypeInstPtr *tinst) const {
3247 int off = meet_offset(tinst->offset());
3248 PTR ptr = meet_ptr(tinst->ptr());
3249 int instance_id = meet_instance_id(tinst->instance_id());
3250 const TypeOopPtr* speculative = xmeet_speculative(tinst);
3251 int depth = meet_inline_depth(tinst->inline_depth());
3253 const TypeInstPtr *loaded = is_loaded() ? this : tinst;
3254 const TypeInstPtr *unloaded = is_loaded() ? tinst : this;
3255 if( loaded->klass()->equals(ciEnv::current()->Object_klass()) ) {
3256 //
3257 // Meet unloaded class with java/lang/Object
3258 //
3259 // Meet
3260 // | Unloaded Class
3261 // Object | TOP | AnyNull | Constant | NotNull | BOTTOM |
3262 // ===================================================================
3263 // TOP | ..........................Unloaded......................|
3264 // AnyNull | U-AN |................Unloaded......................|
3265 // Constant | ... O-NN .................................. | O-BOT |
3266 // NotNull | ... O-NN .................................. | O-BOT |
3267 // BOTTOM | ........................Object-BOTTOM ..................|
3268 //
3269 assert(loaded->ptr() != TypePtr::Null, "insanity check");
3270 //
3271 if( loaded->ptr() == TypePtr::TopPTR ) { return unloaded; }
3272 else if (loaded->ptr() == TypePtr::AnyNull) { return TypeInstPtr::make(ptr, unloaded->klass(), false, NULL, off, instance_id, speculative, depth); }
3273 else if (loaded->ptr() == TypePtr::BotPTR ) { return TypeInstPtr::BOTTOM; }
3274 else if (loaded->ptr() == TypePtr::Constant || loaded->ptr() == TypePtr::NotNull) {
3275 if (unloaded->ptr() == TypePtr::BotPTR ) { return TypeInstPtr::BOTTOM; }
3276 else { return TypeInstPtr::NOTNULL; }
3277 }
3278 else if( unloaded->ptr() == TypePtr::TopPTR ) { return unloaded; }
3280 return unloaded->cast_to_ptr_type(TypePtr::AnyNull)->is_instptr();
3281 }
3283 // Both are unloaded, not the same class, not Object
3284 // Or meet unloaded with a different loaded class, not java/lang/Object
3285 if( ptr != TypePtr::BotPTR ) {
3286 return TypeInstPtr::NOTNULL;
3287 }
3288 return TypeInstPtr::BOTTOM;
3289 }
3292 //------------------------------meet-------------------------------------------
3293 // Compute the MEET of two types. It returns a new Type object.
3294 const Type *TypeInstPtr::xmeet_helper(const Type *t) const {
3295 // Perform a fast test for common case; meeting the same types together.
3296 if( this == t ) return this; // Meeting same type-rep?
3298 // Current "this->_base" is Pointer
3299 switch (t->base()) { // switch on original type
3301 case Int: // Mixing ints & oops happens when javac
3302 case Long: // reuses local variables
3303 case FloatTop:
3304 case FloatCon:
3305 case FloatBot:
3306 case DoubleTop:
3307 case DoubleCon:
3308 case DoubleBot:
3309 case NarrowOop:
3310 case NarrowKlass:
3311 case Bottom: // Ye Olde Default
3312 return Type::BOTTOM;
3313 case Top:
3314 return this;
3316 default: // All else is a mistake
3317 typerr(t);
3319 case MetadataPtr:
3320 case KlassPtr:
3321 case RawPtr: return TypePtr::BOTTOM;
3323 case AryPtr: { // All arrays inherit from Object class
3324 const TypeAryPtr *tp = t->is_aryptr();
3325 int offset = meet_offset(tp->offset());
3326 PTR ptr = meet_ptr(tp->ptr());
3327 int instance_id = meet_instance_id(tp->instance_id());
3328 const TypeOopPtr* speculative = xmeet_speculative(tp);
3329 int depth = meet_inline_depth(tp->inline_depth());
3330 switch (ptr) {
3331 case TopPTR:
3332 case AnyNull: // Fall 'down' to dual of object klass
3333 // For instances when a subclass meets a superclass we fall
3334 // below the centerline when the superclass is exact. We need to
3335 // do the same here.
3336 if (klass()->equals(ciEnv::current()->Object_klass()) && !klass_is_exact()) {
3337 return TypeAryPtr::make(ptr, tp->ary(), tp->klass(), tp->klass_is_exact(), offset, instance_id, speculative, depth);
3338 } else {
3339 // cannot subclass, so the meet has to fall badly below the centerline
3340 ptr = NotNull;
3341 instance_id = InstanceBot;
3342 return TypeInstPtr::make( ptr, ciEnv::current()->Object_klass(), false, NULL, offset, instance_id, speculative, depth);
3343 }
3344 case Constant:
3345 case NotNull:
3346 case BotPTR: // Fall down to object klass
3347 // LCA is object_klass, but if we subclass from the top we can do better
3348 if( above_centerline(_ptr) ) { // if( _ptr == TopPTR || _ptr == AnyNull )
3349 // If 'this' (InstPtr) is above the centerline and it is Object class
3350 // then we can subclass in the Java class hierarchy.
3351 // For instances when a subclass meets a superclass we fall
3352 // below the centerline when the superclass is exact. We need
3353 // to do the same here.
3354 if (klass()->equals(ciEnv::current()->Object_klass()) && !klass_is_exact()) {
3355 // that is, tp's array type is a subtype of my klass
3356 return TypeAryPtr::make(ptr, (ptr == Constant ? tp->const_oop() : NULL),
3357 tp->ary(), tp->klass(), tp->klass_is_exact(), offset, instance_id, speculative, depth);
3358 }
3359 }
3360 // The other case cannot happen, since I cannot be a subtype of an array.
3361 // The meet falls down to Object class below centerline.
3362 if( ptr == Constant )
3363 ptr = NotNull;
3364 instance_id = InstanceBot;
3365 return make(ptr, ciEnv::current()->Object_klass(), false, NULL, offset, instance_id, speculative, depth);
3366 default: typerr(t);
3367 }
3368 }
3370 case OopPtr: { // Meeting to OopPtrs
3371 // Found a OopPtr type vs self-InstPtr type
3372 const TypeOopPtr *tp = t->is_oopptr();
3373 int offset = meet_offset(tp->offset());
3374 PTR ptr = meet_ptr(tp->ptr());
3375 switch (tp->ptr()) {
3376 case TopPTR:
3377 case AnyNull: {
3378 int instance_id = meet_instance_id(InstanceTop);
3379 const TypeOopPtr* speculative = xmeet_speculative(tp);
3380 int depth = meet_inline_depth(tp->inline_depth());
3381 return make(ptr, klass(), klass_is_exact(),
3382 (ptr == Constant ? const_oop() : NULL), offset, instance_id, speculative, depth);
3383 }
3384 case NotNull:
3385 case BotPTR: {
3386 int instance_id = meet_instance_id(tp->instance_id());
3387 const TypeOopPtr* speculative = xmeet_speculative(tp);
3388 int depth = meet_inline_depth(tp->inline_depth());
3389 return TypeOopPtr::make(ptr, offset, instance_id, speculative, depth);
3390 }
3391 default: typerr(t);
3392 }
3393 }
3395 case AnyPtr: { // Meeting to AnyPtrs
3396 // Found an AnyPtr type vs self-InstPtr type
3397 const TypePtr *tp = t->is_ptr();
3398 int offset = meet_offset(tp->offset());
3399 PTR ptr = meet_ptr(tp->ptr());
3400 switch (tp->ptr()) {
3401 case Null:
3402 if( ptr == Null ) return TypePtr::make(AnyPtr, ptr, offset);
3403 // else fall through to AnyNull
3404 case TopPTR:
3405 case AnyNull: {
3406 int instance_id = meet_instance_id(InstanceTop);
3407 const TypeOopPtr* speculative = _speculative;
3408 return make(ptr, klass(), klass_is_exact(),
3409 (ptr == Constant ? const_oop() : NULL), offset, instance_id, speculative, _inline_depth);
3410 }
3411 case NotNull:
3412 case BotPTR:
3413 return TypePtr::make(AnyPtr, ptr, offset);
3414 default: typerr(t);
3415 }
3416 }
3418 /*
3419 A-top }
3420 / | \ } Tops
3421 B-top A-any C-top }
3422 | / | \ | } Any-nulls
3423 B-any | C-any }
3424 | | |
3425 B-con A-con C-con } constants; not comparable across classes
3426 | | |
3427 B-not | C-not }
3428 | \ | / | } not-nulls
3429 B-bot A-not C-bot }
3430 \ | / } Bottoms
3431 A-bot }
3432 */
3434 case InstPtr: { // Meeting 2 Oops?
3435 // Found an InstPtr sub-type vs self-InstPtr type
3436 const TypeInstPtr *tinst = t->is_instptr();
3437 int off = meet_offset( tinst->offset() );
3438 PTR ptr = meet_ptr( tinst->ptr() );
3439 int instance_id = meet_instance_id(tinst->instance_id());
3440 const TypeOopPtr* speculative = xmeet_speculative(tinst);
3441 int depth = meet_inline_depth(tinst->inline_depth());
3443 // Check for easy case; klasses are equal (and perhaps not loaded!)
3444 // If we have constants, then we created oops so classes are loaded
3445 // and we can handle the constants further down. This case handles
3446 // both-not-loaded or both-loaded classes
3447 if (ptr != Constant && klass()->equals(tinst->klass()) && klass_is_exact() == tinst->klass_is_exact()) {
3448 return make(ptr, klass(), klass_is_exact(), NULL, off, instance_id, speculative, depth);
3449 }
3451 // Classes require inspection in the Java klass hierarchy. Must be loaded.
3452 ciKlass* tinst_klass = tinst->klass();
3453 ciKlass* this_klass = this->klass();
3454 bool tinst_xk = tinst->klass_is_exact();
3455 bool this_xk = this->klass_is_exact();
3456 if (!tinst_klass->is_loaded() || !this_klass->is_loaded() ) {
3457 // One of these classes has not been loaded
3458 const TypeInstPtr *unloaded_meet = xmeet_unloaded(tinst);
3459 #ifndef PRODUCT
3460 if( PrintOpto && Verbose ) {
3461 tty->print("meet of unloaded classes resulted in: "); unloaded_meet->dump(); tty->cr();
3462 tty->print(" this == "); this->dump(); tty->cr();
3463 tty->print(" tinst == "); tinst->dump(); tty->cr();
3464 }
3465 #endif
3466 return unloaded_meet;
3467 }
3469 // Handle mixing oops and interfaces first.
3470 if( this_klass->is_interface() && !(tinst_klass->is_interface() ||
3471 tinst_klass == ciEnv::current()->Object_klass())) {
3472 ciKlass *tmp = tinst_klass; // Swap interface around
3473 tinst_klass = this_klass;
3474 this_klass = tmp;
3475 bool tmp2 = tinst_xk;
3476 tinst_xk = this_xk;
3477 this_xk = tmp2;
3478 }
3479 if (tinst_klass->is_interface() &&
3480 !(this_klass->is_interface() ||
3481 // Treat java/lang/Object as an honorary interface,
3482 // because we need a bottom for the interface hierarchy.
3483 this_klass == ciEnv::current()->Object_klass())) {
3484 // Oop meets interface!
3486 // See if the oop subtypes (implements) interface.
3487 ciKlass *k;
3488 bool xk;
3489 if( this_klass->is_subtype_of( tinst_klass ) ) {
3490 // Oop indeed subtypes. Now keep oop or interface depending
3491 // on whether we are both above the centerline or either is
3492 // below the centerline. If we are on the centerline
3493 // (e.g., Constant vs. AnyNull interface), use the constant.
3494 k = below_centerline(ptr) ? tinst_klass : this_klass;
3495 // If we are keeping this_klass, keep its exactness too.
3496 xk = below_centerline(ptr) ? tinst_xk : this_xk;
3497 } else { // Does not implement, fall to Object
3498 // Oop does not implement interface, so mixing falls to Object
3499 // just like the verifier does (if both are above the
3500 // centerline fall to interface)
3501 k = above_centerline(ptr) ? tinst_klass : ciEnv::current()->Object_klass();
3502 xk = above_centerline(ptr) ? tinst_xk : false;
3503 // Watch out for Constant vs. AnyNull interface.
3504 if (ptr == Constant) ptr = NotNull; // forget it was a constant
3505 instance_id = InstanceBot;
3506 }
3507 ciObject* o = NULL; // the Constant value, if any
3508 if (ptr == Constant) {
3509 // Find out which constant.
3510 o = (this_klass == klass()) ? const_oop() : tinst->const_oop();
3511 }
3512 return make(ptr, k, xk, o, off, instance_id, speculative, depth);
3513 }
3515 // Either oop vs oop or interface vs interface or interface vs Object
3517 // !!! Here's how the symmetry requirement breaks down into invariants:
3518 // If we split one up & one down AND they subtype, take the down man.
3519 // If we split one up & one down AND they do NOT subtype, "fall hard".
3520 // If both are up and they subtype, take the subtype class.
3521 // If both are up and they do NOT subtype, "fall hard".
3522 // If both are down and they subtype, take the supertype class.
3523 // If both are down and they do NOT subtype, "fall hard".
3524 // Constants treated as down.
3526 // Now, reorder the above list; observe that both-down+subtype is also
3527 // "fall hard"; "fall hard" becomes the default case:
3528 // If we split one up & one down AND they subtype, take the down man.
3529 // If both are up and they subtype, take the subtype class.
3531 // If both are down and they subtype, "fall hard".
3532 // If both are down and they do NOT subtype, "fall hard".
3533 // If both are up and they do NOT subtype, "fall hard".
3534 // If we split one up & one down AND they do NOT subtype, "fall hard".
3536 // If a proper subtype is exact, and we return it, we return it exactly.
3537 // If a proper supertype is exact, there can be no subtyping relationship!
3538 // If both types are equal to the subtype, exactness is and-ed below the
3539 // centerline and or-ed above it. (N.B. Constants are always exact.)
3541 // Check for subtyping:
3542 ciKlass *subtype = NULL;
3543 bool subtype_exact = false;
3544 if( tinst_klass->equals(this_klass) ) {
3545 subtype = this_klass;
3546 subtype_exact = below_centerline(ptr) ? (this_xk & tinst_xk) : (this_xk | tinst_xk);
3547 } else if( !tinst_xk && this_klass->is_subtype_of( tinst_klass ) ) {
3548 subtype = this_klass; // Pick subtyping class
3549 subtype_exact = this_xk;
3550 } else if( !this_xk && tinst_klass->is_subtype_of( this_klass ) ) {
3551 subtype = tinst_klass; // Pick subtyping class
3552 subtype_exact = tinst_xk;
3553 }
3555 if( subtype ) {
3556 if( above_centerline(ptr) ) { // both are up?
3557 this_klass = tinst_klass = subtype;
3558 this_xk = tinst_xk = subtype_exact;
3559 } else if( above_centerline(this ->_ptr) && !above_centerline(tinst->_ptr) ) {
3560 this_klass = tinst_klass; // tinst is down; keep down man
3561 this_xk = tinst_xk;
3562 } else if( above_centerline(tinst->_ptr) && !above_centerline(this ->_ptr) ) {
3563 tinst_klass = this_klass; // this is down; keep down man
3564 tinst_xk = this_xk;
3565 } else {
3566 this_xk = subtype_exact; // either they are equal, or we'll do an LCA
3567 }
3568 }
3570 // Check for classes now being equal
3571 if (tinst_klass->equals(this_klass)) {
3572 // If the klasses are equal, the constants may still differ. Fall to
3573 // NotNull if they do (neither constant is NULL; that is a special case
3574 // handled elsewhere).
3575 ciObject* o = NULL; // Assume not constant when done
3576 ciObject* this_oop = const_oop();
3577 ciObject* tinst_oop = tinst->const_oop();
3578 if( ptr == Constant ) {
3579 if (this_oop != NULL && tinst_oop != NULL &&
3580 this_oop->equals(tinst_oop) )
3581 o = this_oop;
3582 else if (above_centerline(this ->_ptr))
3583 o = tinst_oop;
3584 else if (above_centerline(tinst ->_ptr))
3585 o = this_oop;
3586 else
3587 ptr = NotNull;
3588 }
3589 return make(ptr, this_klass, this_xk, o, off, instance_id, speculative, depth);
3590 } // Else classes are not equal
3592 // Since klasses are different, we require a LCA in the Java
3593 // class hierarchy - which means we have to fall to at least NotNull.
3594 if( ptr == TopPTR || ptr == AnyNull || ptr == Constant )
3595 ptr = NotNull;
3596 instance_id = InstanceBot;
3598 // Now we find the LCA of Java classes
3599 ciKlass* k = this_klass->least_common_ancestor(tinst_klass);
3600 return make(ptr, k, false, NULL, off, instance_id, speculative, depth);
3601 } // End of case InstPtr
3603 } // End of switch
3604 return this; // Return the double constant
3605 }
3608 //------------------------java_mirror_type--------------------------------------
3609 ciType* TypeInstPtr::java_mirror_type() const {
3610 // must be a singleton type
3611 if( const_oop() == NULL ) return NULL;
3613 // must be of type java.lang.Class
3614 if( klass() != ciEnv::current()->Class_klass() ) return NULL;
3616 return const_oop()->as_instance()->java_mirror_type();
3617 }
3620 //------------------------------xdual------------------------------------------
3621 // Dual: do NOT dual on klasses. This means I do NOT understand the Java
3622 // inheritance mechanism.
3623 const Type *TypeInstPtr::xdual() const {
3624 return new TypeInstPtr(dual_ptr(), klass(), klass_is_exact(), const_oop(), dual_offset(), dual_instance_id(), dual_speculative(), dual_inline_depth());
3625 }
3627 //------------------------------eq---------------------------------------------
3628 // Structural equality check for Type representations
3629 bool TypeInstPtr::eq( const Type *t ) const {
3630 const TypeInstPtr *p = t->is_instptr();
3631 return
3632 klass()->equals(p->klass()) &&
3633 TypeOopPtr::eq(p); // Check sub-type stuff
3634 }
3636 //------------------------------hash-------------------------------------------
3637 // Type-specific hashing function.
3638 int TypeInstPtr::hash(void) const {
3639 int hash = java_add(klass()->hash(), TypeOopPtr::hash());
3640 return hash;
3641 }
3643 //------------------------------dump2------------------------------------------
3644 // Dump oop Type
3645 #ifndef PRODUCT
3646 void TypeInstPtr::dump2( Dict &d, uint depth, outputStream *st ) const {
3647 // Print the name of the klass.
3648 klass()->print_name_on(st);
3650 switch( _ptr ) {
3651 case Constant:
3652 // TO DO: Make CI print the hex address of the underlying oop.
3653 if (WizardMode || Verbose) {
3654 const_oop()->print_oop(st);
3655 }
3656 case BotPTR:
3657 if (!WizardMode && !Verbose) {
3658 if( _klass_is_exact ) st->print(":exact");
3659 break;
3660 }
3661 case TopPTR:
3662 case AnyNull:
3663 case NotNull:
3664 st->print(":%s", ptr_msg[_ptr]);
3665 if( _klass_is_exact ) st->print(":exact");
3666 break;
3667 }
3669 if( _offset ) { // Dump offset, if any
3670 if( _offset == OffsetBot ) st->print("+any");
3671 else if( _offset == OffsetTop ) st->print("+unknown");
3672 else st->print("+%d", _offset);
3673 }
3675 st->print(" *");
3676 if (_instance_id == InstanceTop)
3677 st->print(",iid=top");
3678 else if (_instance_id != InstanceBot)
3679 st->print(",iid=%d",_instance_id);
3681 dump_inline_depth(st);
3682 dump_speculative(st);
3683 }
3684 #endif
3686 //------------------------------add_offset-------------------------------------
3687 const TypePtr *TypeInstPtr::add_offset(intptr_t offset) const {
3688 return make(_ptr, klass(), klass_is_exact(), const_oop(), xadd_offset(offset), _instance_id, add_offset_speculative(offset));
3689 }
3691 const Type *TypeInstPtr::remove_speculative() const {
3692 if (_speculative == NULL) {
3693 return this;
3694 }
3695 assert(_inline_depth == InlineDepthTop || _inline_depth == InlineDepthBottom, "non speculative type shouldn't have inline depth");
3696 return make(_ptr, klass(), klass_is_exact(), const_oop(), _offset, _instance_id, NULL, _inline_depth);
3697 }
3699 const TypeOopPtr *TypeInstPtr::with_inline_depth(int depth) const {
3700 if (!UseInlineDepthForSpeculativeTypes) {
3701 return this;
3702 }
3703 return make(_ptr, klass(), klass_is_exact(), const_oop(), _offset, _instance_id, _speculative, depth);
3704 }
3706 //=============================================================================
3707 // Convenience common pre-built types.
3708 const TypeAryPtr *TypeAryPtr::RANGE;
3709 const TypeAryPtr *TypeAryPtr::OOPS;
3710 const TypeAryPtr *TypeAryPtr::NARROWOOPS;
3711 const TypeAryPtr *TypeAryPtr::BYTES;
3712 const TypeAryPtr *TypeAryPtr::SHORTS;
3713 const TypeAryPtr *TypeAryPtr::CHARS;
3714 const TypeAryPtr *TypeAryPtr::INTS;
3715 const TypeAryPtr *TypeAryPtr::LONGS;
3716 const TypeAryPtr *TypeAryPtr::FLOATS;
3717 const TypeAryPtr *TypeAryPtr::DOUBLES;
3719 //------------------------------make-------------------------------------------
3720 const TypeAryPtr *TypeAryPtr::make(PTR ptr, const TypeAry *ary, ciKlass* k, bool xk, int offset, int instance_id, const TypeOopPtr* speculative, int inline_depth) {
3721 assert(!(k == NULL && ary->_elem->isa_int()),
3722 "integral arrays must be pre-equipped with a class");
3723 if (!xk) xk = ary->ary_must_be_exact();
3724 assert(instance_id <= 0 || xk || !UseExactTypes, "instances are always exactly typed");
3725 if (!UseExactTypes) xk = (ptr == Constant);
3726 return (TypeAryPtr*)(new TypeAryPtr(ptr, NULL, ary, k, xk, offset, instance_id, false, speculative, inline_depth))->hashcons();
3727 }
3729 //------------------------------make-------------------------------------------
3730 const TypeAryPtr *TypeAryPtr::make(PTR ptr, ciObject* o, const TypeAry *ary, ciKlass* k, bool xk, int offset, int instance_id, const TypeOopPtr* speculative, int inline_depth, bool is_autobox_cache) {
3731 assert(!(k == NULL && ary->_elem->isa_int()),
3732 "integral arrays must be pre-equipped with a class");
3733 assert( (ptr==Constant && o) || (ptr!=Constant && !o), "" );
3734 if (!xk) xk = (o != NULL) || ary->ary_must_be_exact();
3735 assert(instance_id <= 0 || xk || !UseExactTypes, "instances are always exactly typed");
3736 if (!UseExactTypes) xk = (ptr == Constant);
3737 return (TypeAryPtr*)(new TypeAryPtr(ptr, o, ary, k, xk, offset, instance_id, is_autobox_cache, speculative, inline_depth))->hashcons();
3738 }
3740 //------------------------------cast_to_ptr_type-------------------------------
3741 const Type *TypeAryPtr::cast_to_ptr_type(PTR ptr) const {
3742 if( ptr == _ptr ) return this;
3743 return make(ptr, const_oop(), _ary, klass(), klass_is_exact(), _offset, _instance_id, _speculative, _inline_depth);
3744 }
3747 //-----------------------------cast_to_exactness-------------------------------
3748 const Type *TypeAryPtr::cast_to_exactness(bool klass_is_exact) const {
3749 if( klass_is_exact == _klass_is_exact ) return this;
3750 if (!UseExactTypes) return this;
3751 if (_ary->ary_must_be_exact()) return this; // cannot clear xk
3752 return make(ptr(), const_oop(), _ary, klass(), klass_is_exact, _offset, _instance_id, _speculative, _inline_depth);
3753 }
3755 //-----------------------------cast_to_instance_id----------------------------
3756 const TypeOopPtr *TypeAryPtr::cast_to_instance_id(int instance_id) const {
3757 if( instance_id == _instance_id ) return this;
3758 return make(_ptr, const_oop(), _ary, klass(), _klass_is_exact, _offset, instance_id, _speculative, _inline_depth);
3759 }
3761 //-----------------------------narrow_size_type-------------------------------
3762 // Local cache for arrayOopDesc::max_array_length(etype),
3763 // which is kind of slow (and cached elsewhere by other users).
3764 static jint max_array_length_cache[T_CONFLICT+1];
3765 static jint max_array_length(BasicType etype) {
3766 jint& cache = max_array_length_cache[etype];
3767 jint res = cache;
3768 if (res == 0) {
3769 switch (etype) {
3770 case T_NARROWOOP:
3771 etype = T_OBJECT;
3772 break;
3773 case T_NARROWKLASS:
3774 case T_CONFLICT:
3775 case T_ILLEGAL:
3776 case T_VOID:
3777 etype = T_BYTE; // will produce conservatively high value
3778 }
3779 cache = res = arrayOopDesc::max_array_length(etype);
3780 }
3781 return res;
3782 }
3784 // Narrow the given size type to the index range for the given array base type.
3785 // Return NULL if the resulting int type becomes empty.
3786 const TypeInt* TypeAryPtr::narrow_size_type(const TypeInt* size) const {
3787 jint hi = size->_hi;
3788 jint lo = size->_lo;
3789 jint min_lo = 0;
3790 jint max_hi = max_array_length(elem()->basic_type());
3791 //if (index_not_size) --max_hi; // type of a valid array index, FTR
3792 bool chg = false;
3793 if (lo < min_lo) {
3794 lo = min_lo;
3795 if (size->is_con()) {
3796 hi = lo;
3797 }
3798 chg = true;
3799 }
3800 if (hi > max_hi) {
3801 hi = max_hi;
3802 if (size->is_con()) {
3803 lo = hi;
3804 }
3805 chg = true;
3806 }
3807 // Negative length arrays will produce weird intermediate dead fast-path code
3808 if (lo > hi)
3809 return TypeInt::ZERO;
3810 if (!chg)
3811 return size;
3812 return TypeInt::make(lo, hi, Type::WidenMin);
3813 }
3815 //-------------------------------cast_to_size----------------------------------
3816 const TypeAryPtr* TypeAryPtr::cast_to_size(const TypeInt* new_size) const {
3817 assert(new_size != NULL, "");
3818 new_size = narrow_size_type(new_size);
3819 if (new_size == size()) return this;
3820 const TypeAry* new_ary = TypeAry::make(elem(), new_size, is_stable());
3821 return make(ptr(), const_oop(), new_ary, klass(), klass_is_exact(), _offset, _instance_id, _speculative, _inline_depth);
3822 }
3825 //------------------------------cast_to_stable---------------------------------
3826 const TypeAryPtr* TypeAryPtr::cast_to_stable(bool stable, int stable_dimension) const {
3827 if (stable_dimension <= 0 || (stable_dimension == 1 && stable == this->is_stable()))
3828 return this;
3830 const Type* elem = this->elem();
3831 const TypePtr* elem_ptr = elem->make_ptr();
3833 if (stable_dimension > 1 && elem_ptr != NULL && elem_ptr->isa_aryptr()) {
3834 // If this is widened from a narrow oop, TypeAry::make will re-narrow it.
3835 elem = elem_ptr = elem_ptr->is_aryptr()->cast_to_stable(stable, stable_dimension - 1);
3836 }
3838 const TypeAry* new_ary = TypeAry::make(elem, size(), stable);
3840 return make(ptr(), const_oop(), new_ary, klass(), klass_is_exact(), _offset, _instance_id);
3841 }
3843 //-----------------------------stable_dimension--------------------------------
3844 int TypeAryPtr::stable_dimension() const {
3845 if (!is_stable()) return 0;
3846 int dim = 1;
3847 const TypePtr* elem_ptr = elem()->make_ptr();
3848 if (elem_ptr != NULL && elem_ptr->isa_aryptr())
3849 dim += elem_ptr->is_aryptr()->stable_dimension();
3850 return dim;
3851 }
3853 //------------------------------eq---------------------------------------------
3854 // Structural equality check for Type representations
3855 bool TypeAryPtr::eq( const Type *t ) const {
3856 const TypeAryPtr *p = t->is_aryptr();
3857 return
3858 _ary == p->_ary && // Check array
3859 TypeOopPtr::eq(p); // Check sub-parts
3860 }
3862 //------------------------------hash-------------------------------------------
3863 // Type-specific hashing function.
3864 int TypeAryPtr::hash(void) const {
3865 return (intptr_t)_ary + TypeOopPtr::hash();
3866 }
3868 //------------------------------meet-------------------------------------------
3869 // Compute the MEET of two types. It returns a new Type object.
3870 const Type *TypeAryPtr::xmeet_helper(const Type *t) const {
3871 // Perform a fast test for common case; meeting the same types together.
3872 if( this == t ) return this; // Meeting same type-rep?
3873 // Current "this->_base" is Pointer
3874 switch (t->base()) { // switch on original type
3876 // Mixing ints & oops happens when javac reuses local variables
3877 case Int:
3878 case Long:
3879 case FloatTop:
3880 case FloatCon:
3881 case FloatBot:
3882 case DoubleTop:
3883 case DoubleCon:
3884 case DoubleBot:
3885 case NarrowOop:
3886 case NarrowKlass:
3887 case Bottom: // Ye Olde Default
3888 return Type::BOTTOM;
3889 case Top:
3890 return this;
3892 default: // All else is a mistake
3893 typerr(t);
3895 case OopPtr: { // Meeting to OopPtrs
3896 // Found a OopPtr type vs self-AryPtr type
3897 const TypeOopPtr *tp = t->is_oopptr();
3898 int offset = meet_offset(tp->offset());
3899 PTR ptr = meet_ptr(tp->ptr());
3900 int depth = meet_inline_depth(tp->inline_depth());
3901 switch (tp->ptr()) {
3902 case TopPTR:
3903 case AnyNull: {
3904 int instance_id = meet_instance_id(InstanceTop);
3905 const TypeOopPtr* speculative = xmeet_speculative(tp);
3906 return make(ptr, (ptr == Constant ? const_oop() : NULL),
3907 _ary, _klass, _klass_is_exact, offset, instance_id, speculative, depth);
3908 }
3909 case BotPTR:
3910 case NotNull: {
3911 int instance_id = meet_instance_id(tp->instance_id());
3912 const TypeOopPtr* speculative = xmeet_speculative(tp);
3913 return TypeOopPtr::make(ptr, offset, instance_id, speculative, depth);
3914 }
3915 default: ShouldNotReachHere();
3916 }
3917 }
3919 case AnyPtr: { // Meeting two AnyPtrs
3920 // Found an AnyPtr type vs self-AryPtr type
3921 const TypePtr *tp = t->is_ptr();
3922 int offset = meet_offset(tp->offset());
3923 PTR ptr = meet_ptr(tp->ptr());
3924 switch (tp->ptr()) {
3925 case TopPTR:
3926 return this;
3927 case BotPTR:
3928 case NotNull:
3929 return TypePtr::make(AnyPtr, ptr, offset);
3930 case Null:
3931 if( ptr == Null ) return TypePtr::make(AnyPtr, ptr, offset);
3932 // else fall through to AnyNull
3933 case AnyNull: {
3934 int instance_id = meet_instance_id(InstanceTop);
3935 const TypeOopPtr* speculative = _speculative;
3936 return make(ptr, (ptr == Constant ? const_oop() : NULL),
3937 _ary, _klass, _klass_is_exact, offset, instance_id, speculative, _inline_depth);
3938 }
3939 default: ShouldNotReachHere();
3940 }
3941 }
3943 case MetadataPtr:
3944 case KlassPtr:
3945 case RawPtr: return TypePtr::BOTTOM;
3947 case AryPtr: { // Meeting 2 references?
3948 const TypeAryPtr *tap = t->is_aryptr();
3949 int off = meet_offset(tap->offset());
3950 const TypeAry *tary = _ary->meet_speculative(tap->_ary)->is_ary();
3951 PTR ptr = meet_ptr(tap->ptr());
3952 int instance_id = meet_instance_id(tap->instance_id());
3953 const TypeOopPtr* speculative = xmeet_speculative(tap);
3954 int depth = meet_inline_depth(tap->inline_depth());
3955 ciKlass* lazy_klass = NULL;
3956 if (tary->_elem->isa_int()) {
3957 // Integral array element types have irrelevant lattice relations.
3958 // It is the klass that determines array layout, not the element type.
3959 if (_klass == NULL)
3960 lazy_klass = tap->_klass;
3961 else if (tap->_klass == NULL || tap->_klass == _klass) {
3962 lazy_klass = _klass;
3963 } else {
3964 // Something like byte[int+] meets char[int+].
3965 // This must fall to bottom, not (int[-128..65535])[int+].
3966 instance_id = InstanceBot;
3967 tary = TypeAry::make(Type::BOTTOM, tary->_size, tary->_stable);
3968 }
3969 } else // Non integral arrays.
3970 // Must fall to bottom if exact klasses in upper lattice
3971 // are not equal or super klass is exact.
3972 if ((above_centerline(ptr) || ptr == Constant) && klass() != tap->klass() &&
3973 // meet with top[] and bottom[] are processed further down:
3974 tap->_klass != NULL && this->_klass != NULL &&
3975 // both are exact and not equal:
3976 ((tap->_klass_is_exact && this->_klass_is_exact) ||
3977 // 'tap' is exact and super or unrelated:
3978 (tap->_klass_is_exact && !tap->klass()->is_subtype_of(klass())) ||
3979 // 'this' is exact and super or unrelated:
3980 (this->_klass_is_exact && !klass()->is_subtype_of(tap->klass())))) {
3981 if (above_centerline(ptr)) {
3982 tary = TypeAry::make(Type::BOTTOM, tary->_size, tary->_stable);
3983 }
3984 return make(NotNull, NULL, tary, lazy_klass, false, off, InstanceBot);
3985 }
3987 bool xk = false;
3988 switch (tap->ptr()) {
3989 case AnyNull:
3990 case TopPTR:
3991 // Compute new klass on demand, do not use tap->_klass
3992 if (below_centerline(this->_ptr)) {
3993 xk = this->_klass_is_exact;
3994 } else {
3995 xk = (tap->_klass_is_exact | this->_klass_is_exact);
3996 }
3997 return make(ptr, const_oop(), tary, lazy_klass, xk, off, instance_id, speculative, depth);
3998 case Constant: {
3999 ciObject* o = const_oop();
4000 if( _ptr == Constant ) {
4001 if( tap->const_oop() != NULL && !o->equals(tap->const_oop()) ) {
4002 xk = (klass() == tap->klass());
4003 ptr = NotNull;
4004 o = NULL;
4005 instance_id = InstanceBot;
4006 } else {
4007 xk = true;
4008 }
4009 } else if(above_centerline(_ptr)) {
4010 o = tap->const_oop();
4011 xk = true;
4012 } else {
4013 // Only precise for identical arrays
4014 xk = this->_klass_is_exact && (klass() == tap->klass());
4015 }
4016 return TypeAryPtr::make(ptr, o, tary, lazy_klass, xk, off, instance_id, speculative, depth);
4017 }
4018 case NotNull:
4019 case BotPTR:
4020 // Compute new klass on demand, do not use tap->_klass
4021 if (above_centerline(this->_ptr))
4022 xk = tap->_klass_is_exact;
4023 else xk = (tap->_klass_is_exact & this->_klass_is_exact) &&
4024 (klass() == tap->klass()); // Only precise for identical arrays
4025 return TypeAryPtr::make(ptr, NULL, tary, lazy_klass, xk, off, instance_id, speculative, depth);
4026 default: ShouldNotReachHere();
4027 }
4028 }
4030 // All arrays inherit from Object class
4031 case InstPtr: {
4032 const TypeInstPtr *tp = t->is_instptr();
4033 int offset = meet_offset(tp->offset());
4034 PTR ptr = meet_ptr(tp->ptr());
4035 int instance_id = meet_instance_id(tp->instance_id());
4036 const TypeOopPtr* speculative = xmeet_speculative(tp);
4037 int depth = meet_inline_depth(tp->inline_depth());
4038 switch (ptr) {
4039 case TopPTR:
4040 case AnyNull: // Fall 'down' to dual of object klass
4041 // For instances when a subclass meets a superclass we fall
4042 // below the centerline when the superclass is exact. We need to
4043 // do the same here.
4044 if (tp->klass()->equals(ciEnv::current()->Object_klass()) && !tp->klass_is_exact()) {
4045 return TypeAryPtr::make(ptr, _ary, _klass, _klass_is_exact, offset, instance_id, speculative, depth);
4046 } else {
4047 // cannot subclass, so the meet has to fall badly below the centerline
4048 ptr = NotNull;
4049 instance_id = InstanceBot;
4050 return TypeInstPtr::make(ptr, ciEnv::current()->Object_klass(), false, NULL,offset, instance_id, speculative, depth);
4051 }
4052 case Constant:
4053 case NotNull:
4054 case BotPTR: // Fall down to object klass
4055 // LCA is object_klass, but if we subclass from the top we can do better
4056 if (above_centerline(tp->ptr())) {
4057 // If 'tp' is above the centerline and it is Object class
4058 // then we can subclass in the Java class hierarchy.
4059 // For instances when a subclass meets a superclass we fall
4060 // below the centerline when the superclass is exact. We need
4061 // to do the same here.
4062 if (tp->klass()->equals(ciEnv::current()->Object_klass()) && !tp->klass_is_exact()) {
4063 // that is, my array type is a subtype of 'tp' klass
4064 return make(ptr, (ptr == Constant ? const_oop() : NULL),
4065 _ary, _klass, _klass_is_exact, offset, instance_id, speculative, depth);
4066 }
4067 }
4068 // The other case cannot happen, since t cannot be a subtype of an array.
4069 // The meet falls down to Object class below centerline.
4070 if( ptr == Constant )
4071 ptr = NotNull;
4072 instance_id = InstanceBot;
4073 return TypeInstPtr::make(ptr, ciEnv::current()->Object_klass(), false, NULL,offset, instance_id, speculative, depth);
4074 default: typerr(t);
4075 }
4076 }
4077 }
4078 return this; // Lint noise
4079 }
4081 //------------------------------xdual------------------------------------------
4082 // Dual: compute field-by-field dual
4083 const Type *TypeAryPtr::xdual() const {
4084 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());
4085 }
4087 //----------------------interface_vs_oop---------------------------------------
4088 #ifdef ASSERT
4089 bool TypeAryPtr::interface_vs_oop(const Type *t) const {
4090 const TypeAryPtr* t_aryptr = t->isa_aryptr();
4091 if (t_aryptr) {
4092 return _ary->interface_vs_oop(t_aryptr->_ary);
4093 }
4094 return false;
4095 }
4096 #endif
4098 //------------------------------dump2------------------------------------------
4099 #ifndef PRODUCT
4100 void TypeAryPtr::dump2( Dict &d, uint depth, outputStream *st ) const {
4101 _ary->dump2(d,depth,st);
4102 switch( _ptr ) {
4103 case Constant:
4104 const_oop()->print(st);
4105 break;
4106 case BotPTR:
4107 if (!WizardMode && !Verbose) {
4108 if( _klass_is_exact ) st->print(":exact");
4109 break;
4110 }
4111 case TopPTR:
4112 case AnyNull:
4113 case NotNull:
4114 st->print(":%s", ptr_msg[_ptr]);
4115 if( _klass_is_exact ) st->print(":exact");
4116 break;
4117 }
4119 if( _offset != 0 ) {
4120 int header_size = objArrayOopDesc::header_size() * wordSize;
4121 if( _offset == OffsetTop ) st->print("+undefined");
4122 else if( _offset == OffsetBot ) st->print("+any");
4123 else if( _offset < header_size ) st->print("+%d", _offset);
4124 else {
4125 BasicType basic_elem_type = elem()->basic_type();
4126 int array_base = arrayOopDesc::base_offset_in_bytes(basic_elem_type);
4127 int elem_size = type2aelembytes(basic_elem_type);
4128 st->print("[%d]", (_offset - array_base)/elem_size);
4129 }
4130 }
4131 st->print(" *");
4132 if (_instance_id == InstanceTop)
4133 st->print(",iid=top");
4134 else if (_instance_id != InstanceBot)
4135 st->print(",iid=%d",_instance_id);
4137 dump_inline_depth(st);
4138 dump_speculative(st);
4139 }
4140 #endif
4142 bool TypeAryPtr::empty(void) const {
4143 if (_ary->empty()) return true;
4144 return TypeOopPtr::empty();
4145 }
4147 //------------------------------add_offset-------------------------------------
4148 const TypePtr *TypeAryPtr::add_offset(intptr_t offset) const {
4149 return make(_ptr, _const_oop, _ary, _klass, _klass_is_exact, xadd_offset(offset), _instance_id, add_offset_speculative(offset), _inline_depth);
4150 }
4152 const Type *TypeAryPtr::remove_speculative() const {
4153 if (_speculative == NULL) {
4154 return this;
4155 }
4156 assert(_inline_depth == InlineDepthTop || _inline_depth == InlineDepthBottom, "non speculative type shouldn't have inline depth");
4157 return make(_ptr, _const_oop, _ary->remove_speculative()->is_ary(), _klass, _klass_is_exact, _offset, _instance_id, NULL, _inline_depth);
4158 }
4160 const TypeOopPtr *TypeAryPtr::with_inline_depth(int depth) const {
4161 if (!UseInlineDepthForSpeculativeTypes) {
4162 return this;
4163 }
4164 return make(_ptr, _const_oop, _ary->remove_speculative()->is_ary(), _klass, _klass_is_exact, _offset, _instance_id, _speculative, depth);
4165 }
4167 //=============================================================================
4169 //------------------------------hash-------------------------------------------
4170 // Type-specific hashing function.
4171 int TypeNarrowPtr::hash(void) const {
4172 return _ptrtype->hash() + 7;
4173 }
4175 bool TypeNarrowPtr::singleton(void) const { // TRUE if type is a singleton
4176 return _ptrtype->singleton();
4177 }
4179 bool TypeNarrowPtr::empty(void) const {
4180 return _ptrtype->empty();
4181 }
4183 intptr_t TypeNarrowPtr::get_con() const {
4184 return _ptrtype->get_con();
4185 }
4187 bool TypeNarrowPtr::eq( const Type *t ) const {
4188 const TypeNarrowPtr* tc = isa_same_narrowptr(t);
4189 if (tc != NULL) {
4190 if (_ptrtype->base() != tc->_ptrtype->base()) {
4191 return false;
4192 }
4193 return tc->_ptrtype->eq(_ptrtype);
4194 }
4195 return false;
4196 }
4198 const Type *TypeNarrowPtr::xdual() const { // Compute dual right now.
4199 const TypePtr* odual = _ptrtype->dual()->is_ptr();
4200 return make_same_narrowptr(odual);
4201 }
4204 const Type *TypeNarrowPtr::filter_helper(const Type *kills, bool include_speculative) const {
4205 if (isa_same_narrowptr(kills)) {
4206 const Type* ft =_ptrtype->filter_helper(is_same_narrowptr(kills)->_ptrtype, include_speculative);
4207 if (ft->empty())
4208 return Type::TOP; // Canonical empty value
4209 if (ft->isa_ptr()) {
4210 return make_hash_same_narrowptr(ft->isa_ptr());
4211 }
4212 return ft;
4213 } else if (kills->isa_ptr()) {
4214 const Type* ft = _ptrtype->join_helper(kills, include_speculative);
4215 if (ft->empty())
4216 return Type::TOP; // Canonical empty value
4217 return ft;
4218 } else {
4219 return Type::TOP;
4220 }
4221 }
4223 //------------------------------xmeet------------------------------------------
4224 // Compute the MEET of two types. It returns a new Type object.
4225 const Type *TypeNarrowPtr::xmeet( const Type *t ) const {
4226 // Perform a fast test for common case; meeting the same types together.
4227 if( this == t ) return this; // Meeting same type-rep?
4229 if (t->base() == base()) {
4230 const Type* result = _ptrtype->xmeet(t->make_ptr());
4231 if (result->isa_ptr()) {
4232 return make_hash_same_narrowptr(result->is_ptr());
4233 }
4234 return result;
4235 }
4237 // Current "this->_base" is NarrowKlass or NarrowOop
4238 switch (t->base()) { // switch on original type
4240 case Int: // Mixing ints & oops happens when javac
4241 case Long: // reuses local variables
4242 case FloatTop:
4243 case FloatCon:
4244 case FloatBot:
4245 case DoubleTop:
4246 case DoubleCon:
4247 case DoubleBot:
4248 case AnyPtr:
4249 case RawPtr:
4250 case OopPtr:
4251 case InstPtr:
4252 case AryPtr:
4253 case MetadataPtr:
4254 case KlassPtr:
4255 case NarrowOop:
4256 case NarrowKlass:
4258 case Bottom: // Ye Olde Default
4259 return Type::BOTTOM;
4260 case Top:
4261 return this;
4263 default: // All else is a mistake
4264 typerr(t);
4266 } // End of switch
4268 return this;
4269 }
4271 #ifndef PRODUCT
4272 void TypeNarrowPtr::dump2( Dict & d, uint depth, outputStream *st ) const {
4273 _ptrtype->dump2(d, depth, st);
4274 }
4275 #endif
4277 const TypeNarrowOop *TypeNarrowOop::BOTTOM;
4278 const TypeNarrowOop *TypeNarrowOop::NULL_PTR;
4281 const TypeNarrowOop* TypeNarrowOop::make(const TypePtr* type) {
4282 return (const TypeNarrowOop*)(new TypeNarrowOop(type))->hashcons();
4283 }
4286 #ifndef PRODUCT
4287 void TypeNarrowOop::dump2( Dict & d, uint depth, outputStream *st ) const {
4288 st->print("narrowoop: ");
4289 TypeNarrowPtr::dump2(d, depth, st);
4290 }
4291 #endif
4293 const TypeNarrowKlass *TypeNarrowKlass::NULL_PTR;
4295 const TypeNarrowKlass* TypeNarrowKlass::make(const TypePtr* type) {
4296 return (const TypeNarrowKlass*)(new TypeNarrowKlass(type))->hashcons();
4297 }
4299 #ifndef PRODUCT
4300 void TypeNarrowKlass::dump2( Dict & d, uint depth, outputStream *st ) const {
4301 st->print("narrowklass: ");
4302 TypeNarrowPtr::dump2(d, depth, st);
4303 }
4304 #endif
4307 //------------------------------eq---------------------------------------------
4308 // Structural equality check for Type representations
4309 bool TypeMetadataPtr::eq( const Type *t ) const {
4310 const TypeMetadataPtr *a = (const TypeMetadataPtr*)t;
4311 ciMetadata* one = metadata();
4312 ciMetadata* two = a->metadata();
4313 if (one == NULL || two == NULL) {
4314 return (one == two) && TypePtr::eq(t);
4315 } else {
4316 return one->equals(two) && TypePtr::eq(t);
4317 }
4318 }
4320 //------------------------------hash-------------------------------------------
4321 // Type-specific hashing function.
4322 int TypeMetadataPtr::hash(void) const {
4323 return
4324 (metadata() ? metadata()->hash() : 0) +
4325 TypePtr::hash();
4326 }
4328 //------------------------------singleton--------------------------------------
4329 // TRUE if Type is a singleton type, FALSE otherwise. Singletons are simple
4330 // constants
4331 bool TypeMetadataPtr::singleton(void) const {
4332 // detune optimizer to not generate constant metadta + constant offset as a constant!
4333 // TopPTR, Null, AnyNull, Constant are all singletons
4334 return (_offset == 0) && !below_centerline(_ptr);
4335 }
4337 //------------------------------add_offset-------------------------------------
4338 const TypePtr *TypeMetadataPtr::add_offset( intptr_t offset ) const {
4339 return make( _ptr, _metadata, xadd_offset(offset));
4340 }
4342 //-----------------------------filter------------------------------------------
4343 // Do not allow interface-vs.-noninterface joins to collapse to top.
4344 const Type *TypeMetadataPtr::filter_helper(const Type *kills, bool include_speculative) const {
4345 const TypeMetadataPtr* ft = join_helper(kills, include_speculative)->isa_metadataptr();
4346 if (ft == NULL || ft->empty())
4347 return Type::TOP; // Canonical empty value
4348 return ft;
4349 }
4351 //------------------------------get_con----------------------------------------
4352 intptr_t TypeMetadataPtr::get_con() const {
4353 assert( _ptr == Null || _ptr == Constant, "" );
4354 assert( _offset >= 0, "" );
4356 if (_offset != 0) {
4357 // After being ported to the compiler interface, the compiler no longer
4358 // directly manipulates the addresses of oops. Rather, it only has a pointer
4359 // to a handle at compile time. This handle is embedded in the generated
4360 // code and dereferenced at the time the nmethod is made. Until that time,
4361 // it is not reasonable to do arithmetic with the addresses of oops (we don't
4362 // have access to the addresses!). This does not seem to currently happen,
4363 // but this assertion here is to help prevent its occurence.
4364 tty->print_cr("Found oop constant with non-zero offset");
4365 ShouldNotReachHere();
4366 }
4368 return (intptr_t)metadata()->constant_encoding();
4369 }
4371 //------------------------------cast_to_ptr_type-------------------------------
4372 const Type *TypeMetadataPtr::cast_to_ptr_type(PTR ptr) const {
4373 if( ptr == _ptr ) return this;
4374 return make(ptr, metadata(), _offset);
4375 }
4377 //------------------------------meet-------------------------------------------
4378 // Compute the MEET of two types. It returns a new Type object.
4379 const Type *TypeMetadataPtr::xmeet( const Type *t ) const {
4380 // Perform a fast test for common case; meeting the same types together.
4381 if( this == t ) return this; // Meeting same type-rep?
4383 // Current "this->_base" is OopPtr
4384 switch (t->base()) { // switch on original type
4386 case Int: // Mixing ints & oops happens when javac
4387 case Long: // reuses local variables
4388 case FloatTop:
4389 case FloatCon:
4390 case FloatBot:
4391 case DoubleTop:
4392 case DoubleCon:
4393 case DoubleBot:
4394 case NarrowOop:
4395 case NarrowKlass:
4396 case Bottom: // Ye Olde Default
4397 return Type::BOTTOM;
4398 case Top:
4399 return this;
4401 default: // All else is a mistake
4402 typerr(t);
4404 case AnyPtr: {
4405 // Found an AnyPtr type vs self-OopPtr type
4406 const TypePtr *tp = t->is_ptr();
4407 int offset = meet_offset(tp->offset());
4408 PTR ptr = meet_ptr(tp->ptr());
4409 switch (tp->ptr()) {
4410 case Null:
4411 if (ptr == Null) return TypePtr::make(AnyPtr, ptr, offset);
4412 // else fall through:
4413 case TopPTR:
4414 case AnyNull: {
4415 return make(ptr, _metadata, offset);
4416 }
4417 case BotPTR:
4418 case NotNull:
4419 return TypePtr::make(AnyPtr, ptr, offset);
4420 default: typerr(t);
4421 }
4422 }
4424 case RawPtr:
4425 case KlassPtr:
4426 case OopPtr:
4427 case InstPtr:
4428 case AryPtr:
4429 return TypePtr::BOTTOM; // Oop meet raw is not well defined
4431 case MetadataPtr: {
4432 const TypeMetadataPtr *tp = t->is_metadataptr();
4433 int offset = meet_offset(tp->offset());
4434 PTR tptr = tp->ptr();
4435 PTR ptr = meet_ptr(tptr);
4436 ciMetadata* md = (tptr == TopPTR) ? metadata() : tp->metadata();
4437 if (tptr == TopPTR || _ptr == TopPTR ||
4438 metadata()->equals(tp->metadata())) {
4439 return make(ptr, md, offset);
4440 }
4441 // metadata is different
4442 if( ptr == Constant ) { // Cannot be equal constants, so...
4443 if( tptr == Constant && _ptr != Constant) return t;
4444 if( _ptr == Constant && tptr != Constant) return this;
4445 ptr = NotNull; // Fall down in lattice
4446 }
4447 return make(ptr, NULL, offset);
4448 break;
4449 }
4450 } // End of switch
4451 return this; // Return the double constant
4452 }
4455 //------------------------------xdual------------------------------------------
4456 // Dual of a pure metadata pointer.
4457 const Type *TypeMetadataPtr::xdual() const {
4458 return new TypeMetadataPtr(dual_ptr(), metadata(), dual_offset());
4459 }
4461 //------------------------------dump2------------------------------------------
4462 #ifndef PRODUCT
4463 void TypeMetadataPtr::dump2( Dict &d, uint depth, outputStream *st ) const {
4464 st->print("metadataptr:%s", ptr_msg[_ptr]);
4465 if( metadata() ) st->print(INTPTR_FORMAT, metadata());
4466 switch( _offset ) {
4467 case OffsetTop: st->print("+top"); break;
4468 case OffsetBot: st->print("+any"); break;
4469 case 0: break;
4470 default: st->print("+%d",_offset); break;
4471 }
4472 }
4473 #endif
4476 //=============================================================================
4477 // Convenience common pre-built type.
4478 const TypeMetadataPtr *TypeMetadataPtr::BOTTOM;
4480 TypeMetadataPtr::TypeMetadataPtr(PTR ptr, ciMetadata* metadata, int offset):
4481 TypePtr(MetadataPtr, ptr, offset), _metadata(metadata) {
4482 }
4484 const TypeMetadataPtr* TypeMetadataPtr::make(ciMethod* m) {
4485 return make(Constant, m, 0);
4486 }
4487 const TypeMetadataPtr* TypeMetadataPtr::make(ciMethodData* m) {
4488 return make(Constant, m, 0);
4489 }
4491 //------------------------------make-------------------------------------------
4492 // Create a meta data constant
4493 const TypeMetadataPtr *TypeMetadataPtr::make(PTR ptr, ciMetadata* m, int offset) {
4494 assert(m == NULL || !m->is_klass(), "wrong type");
4495 return (TypeMetadataPtr*)(new TypeMetadataPtr(ptr, m, offset))->hashcons();
4496 }
4499 //=============================================================================
4500 // Convenience common pre-built types.
4502 // Not-null object klass or below
4503 const TypeKlassPtr *TypeKlassPtr::OBJECT;
4504 const TypeKlassPtr *TypeKlassPtr::OBJECT_OR_NULL;
4506 //------------------------------TypeKlassPtr-----------------------------------
4507 TypeKlassPtr::TypeKlassPtr( PTR ptr, ciKlass* klass, int offset )
4508 : TypePtr(KlassPtr, ptr, offset), _klass(klass), _klass_is_exact(ptr == Constant) {
4509 }
4511 //------------------------------make-------------------------------------------
4512 // ptr to klass 'k', if Constant, or possibly to a sub-klass if not a Constant
4513 const TypeKlassPtr *TypeKlassPtr::make( PTR ptr, ciKlass* k, int offset ) {
4514 assert( k != NULL, "Expect a non-NULL klass");
4515 assert(k->is_instance_klass() || k->is_array_klass(), "Incorrect type of klass oop");
4516 TypeKlassPtr *r =
4517 (TypeKlassPtr*)(new TypeKlassPtr(ptr, k, offset))->hashcons();
4519 return r;
4520 }
4522 //------------------------------eq---------------------------------------------
4523 // Structural equality check for Type representations
4524 bool TypeKlassPtr::eq( const Type *t ) const {
4525 const TypeKlassPtr *p = t->is_klassptr();
4526 return
4527 klass()->equals(p->klass()) &&
4528 TypePtr::eq(p);
4529 }
4531 //------------------------------hash-------------------------------------------
4532 // Type-specific hashing function.
4533 int TypeKlassPtr::hash(void) const {
4534 return java_add(klass()->hash(), TypePtr::hash());
4535 }
4537 //------------------------------singleton--------------------------------------
4538 // TRUE if Type is a singleton type, FALSE otherwise. Singletons are simple
4539 // constants
4540 bool TypeKlassPtr::singleton(void) const {
4541 // detune optimizer to not generate constant klass + constant offset as a constant!
4542 // TopPTR, Null, AnyNull, Constant are all singletons
4543 return (_offset == 0) && !below_centerline(_ptr);
4544 }
4546 // Do not allow interface-vs.-noninterface joins to collapse to top.
4547 const Type *TypeKlassPtr::filter_helper(const Type *kills, bool include_speculative) const {
4548 // logic here mirrors the one from TypeOopPtr::filter. See comments
4549 // there.
4550 const Type* ft = join_helper(kills, include_speculative);
4551 const TypeKlassPtr* ftkp = ft->isa_klassptr();
4552 const TypeKlassPtr* ktkp = kills->isa_klassptr();
4554 if (ft->empty()) {
4555 if (!empty() && ktkp != NULL && ktkp->klass()->is_loaded() && ktkp->klass()->is_interface())
4556 return kills; // Uplift to interface
4558 return Type::TOP; // Canonical empty value
4559 }
4561 // Interface klass type could be exact in opposite to interface type,
4562 // return it here instead of incorrect Constant ptr J/L/Object (6894807).
4563 if (ftkp != NULL && ktkp != NULL &&
4564 ftkp->is_loaded() && ftkp->klass()->is_interface() &&
4565 !ftkp->klass_is_exact() && // Keep exact interface klass
4566 ktkp->is_loaded() && !ktkp->klass()->is_interface()) {
4567 return ktkp->cast_to_ptr_type(ftkp->ptr());
4568 }
4570 return ft;
4571 }
4573 //----------------------compute_klass------------------------------------------
4574 // Compute the defining klass for this class
4575 ciKlass* TypeAryPtr::compute_klass(DEBUG_ONLY(bool verify)) const {
4576 // Compute _klass based on element type.
4577 ciKlass* k_ary = NULL;
4578 const TypeInstPtr *tinst;
4579 const TypeAryPtr *tary;
4580 const Type* el = elem();
4581 if (el->isa_narrowoop()) {
4582 el = el->make_ptr();
4583 }
4585 // Get element klass
4586 if ((tinst = el->isa_instptr()) != NULL) {
4587 // Compute array klass from element klass
4588 k_ary = ciObjArrayKlass::make(tinst->klass());
4589 } else if ((tary = el->isa_aryptr()) != NULL) {
4590 // Compute array klass from element klass
4591 ciKlass* k_elem = tary->klass();
4592 // If element type is something like bottom[], k_elem will be null.
4593 if (k_elem != NULL)
4594 k_ary = ciObjArrayKlass::make(k_elem);
4595 } else if ((el->base() == Type::Top) ||
4596 (el->base() == Type::Bottom)) {
4597 // element type of Bottom occurs from meet of basic type
4598 // and object; Top occurs when doing join on Bottom.
4599 // Leave k_ary at NULL.
4600 } else {
4601 // Cannot compute array klass directly from basic type,
4602 // since subtypes of TypeInt all have basic type T_INT.
4603 #ifdef ASSERT
4604 if (verify && el->isa_int()) {
4605 // Check simple cases when verifying klass.
4606 BasicType bt = T_ILLEGAL;
4607 if (el == TypeInt::BYTE) {
4608 bt = T_BYTE;
4609 } else if (el == TypeInt::SHORT) {
4610 bt = T_SHORT;
4611 } else if (el == TypeInt::CHAR) {
4612 bt = T_CHAR;
4613 } else if (el == TypeInt::INT) {
4614 bt = T_INT;
4615 } else {
4616 return _klass; // just return specified klass
4617 }
4618 return ciTypeArrayKlass::make(bt);
4619 }
4620 #endif
4621 assert(!el->isa_int(),
4622 "integral arrays must be pre-equipped with a class");
4623 // Compute array klass directly from basic type
4624 k_ary = ciTypeArrayKlass::make(el->basic_type());
4625 }
4626 return k_ary;
4627 }
4629 //------------------------------klass------------------------------------------
4630 // Return the defining klass for this class
4631 ciKlass* TypeAryPtr::klass() const {
4632 if( _klass ) return _klass; // Return cached value, if possible
4634 // Oops, need to compute _klass and cache it
4635 ciKlass* k_ary = compute_klass();
4637 if( this != TypeAryPtr::OOPS && this->dual() != TypeAryPtr::OOPS ) {
4638 // The _klass field acts as a cache of the underlying
4639 // ciKlass for this array type. In order to set the field,
4640 // we need to cast away const-ness.
4641 //
4642 // IMPORTANT NOTE: we *never* set the _klass field for the
4643 // type TypeAryPtr::OOPS. This Type is shared between all
4644 // active compilations. However, the ciKlass which represents
4645 // this Type is *not* shared between compilations, so caching
4646 // this value would result in fetching a dangling pointer.
4647 //
4648 // Recomputing the underlying ciKlass for each request is
4649 // a bit less efficient than caching, but calls to
4650 // TypeAryPtr::OOPS->klass() are not common enough to matter.
4651 ((TypeAryPtr*)this)->_klass = k_ary;
4652 if (UseCompressedOops && k_ary != NULL && k_ary->is_obj_array_klass() &&
4653 _offset != 0 && _offset != arrayOopDesc::length_offset_in_bytes()) {
4654 ((TypeAryPtr*)this)->_is_ptr_to_narrowoop = true;
4655 }
4656 }
4657 return k_ary;
4658 }
4661 //------------------------------add_offset-------------------------------------
4662 // Access internals of klass object
4663 const TypePtr *TypeKlassPtr::add_offset( intptr_t offset ) const {
4664 return make( _ptr, klass(), xadd_offset(offset) );
4665 }
4667 //------------------------------cast_to_ptr_type-------------------------------
4668 const Type *TypeKlassPtr::cast_to_ptr_type(PTR ptr) const {
4669 assert(_base == KlassPtr, "subclass must override cast_to_ptr_type");
4670 if( ptr == _ptr ) return this;
4671 return make(ptr, _klass, _offset);
4672 }
4675 //-----------------------------cast_to_exactness-------------------------------
4676 const Type *TypeKlassPtr::cast_to_exactness(bool klass_is_exact) const {
4677 if( klass_is_exact == _klass_is_exact ) return this;
4678 if (!UseExactTypes) return this;
4679 return make(klass_is_exact ? Constant : NotNull, _klass, _offset);
4680 }
4683 //-----------------------------as_instance_type--------------------------------
4684 // Corresponding type for an instance of the given class.
4685 // It will be NotNull, and exact if and only if the klass type is exact.
4686 const TypeOopPtr* TypeKlassPtr::as_instance_type() const {
4687 ciKlass* k = klass();
4688 bool xk = klass_is_exact();
4689 //return TypeInstPtr::make(TypePtr::NotNull, k, xk, NULL, 0);
4690 const TypeOopPtr* toop = TypeOopPtr::make_from_klass_raw(k);
4691 guarantee(toop != NULL, "need type for given klass");
4692 toop = toop->cast_to_ptr_type(TypePtr::NotNull)->is_oopptr();
4693 return toop->cast_to_exactness(xk)->is_oopptr();
4694 }
4697 //------------------------------xmeet------------------------------------------
4698 // Compute the MEET of two types, return a new Type object.
4699 const Type *TypeKlassPtr::xmeet( const Type *t ) const {
4700 // Perform a fast test for common case; meeting the same types together.
4701 if( this == t ) return this; // Meeting same type-rep?
4703 // Current "this->_base" is Pointer
4704 switch (t->base()) { // switch on original type
4706 case Int: // Mixing ints & oops happens when javac
4707 case Long: // reuses local variables
4708 case FloatTop:
4709 case FloatCon:
4710 case FloatBot:
4711 case DoubleTop:
4712 case DoubleCon:
4713 case DoubleBot:
4714 case NarrowOop:
4715 case NarrowKlass:
4716 case Bottom: // Ye Olde Default
4717 return Type::BOTTOM;
4718 case Top:
4719 return this;
4721 default: // All else is a mistake
4722 typerr(t);
4724 case AnyPtr: { // Meeting to AnyPtrs
4725 // Found an AnyPtr type vs self-KlassPtr type
4726 const TypePtr *tp = t->is_ptr();
4727 int offset = meet_offset(tp->offset());
4728 PTR ptr = meet_ptr(tp->ptr());
4729 switch (tp->ptr()) {
4730 case TopPTR:
4731 return this;
4732 case Null:
4733 if( ptr == Null ) return TypePtr::make( AnyPtr, ptr, offset );
4734 case AnyNull:
4735 return make( ptr, klass(), offset );
4736 case BotPTR:
4737 case NotNull:
4738 return TypePtr::make(AnyPtr, ptr, offset);
4739 default: typerr(t);
4740 }
4741 }
4743 case RawPtr:
4744 case MetadataPtr:
4745 case OopPtr:
4746 case AryPtr: // Meet with AryPtr
4747 case InstPtr: // Meet with InstPtr
4748 return TypePtr::BOTTOM;
4750 //
4751 // A-top }
4752 // / | \ } Tops
4753 // B-top A-any C-top }
4754 // | / | \ | } Any-nulls
4755 // B-any | C-any }
4756 // | | |
4757 // B-con A-con C-con } constants; not comparable across classes
4758 // | | |
4759 // B-not | C-not }
4760 // | \ | / | } not-nulls
4761 // B-bot A-not C-bot }
4762 // \ | / } Bottoms
4763 // A-bot }
4764 //
4766 case KlassPtr: { // Meet two KlassPtr types
4767 const TypeKlassPtr *tkls = t->is_klassptr();
4768 int off = meet_offset(tkls->offset());
4769 PTR ptr = meet_ptr(tkls->ptr());
4771 // Check for easy case; klasses are equal (and perhaps not loaded!)
4772 // If we have constants, then we created oops so classes are loaded
4773 // and we can handle the constants further down. This case handles
4774 // not-loaded classes
4775 if( ptr != Constant && tkls->klass()->equals(klass()) ) {
4776 return make( ptr, klass(), off );
4777 }
4779 // Classes require inspection in the Java klass hierarchy. Must be loaded.
4780 ciKlass* tkls_klass = tkls->klass();
4781 ciKlass* this_klass = this->klass();
4782 assert( tkls_klass->is_loaded(), "This class should have been loaded.");
4783 assert( this_klass->is_loaded(), "This class should have been loaded.");
4785 // If 'this' type is above the centerline and is a superclass of the
4786 // other, we can treat 'this' as having the same type as the other.
4787 if ((above_centerline(this->ptr())) &&
4788 tkls_klass->is_subtype_of(this_klass)) {
4789 this_klass = tkls_klass;
4790 }
4791 // If 'tinst' type is above the centerline and is a superclass of the
4792 // other, we can treat 'tinst' as having the same type as the other.
4793 if ((above_centerline(tkls->ptr())) &&
4794 this_klass->is_subtype_of(tkls_klass)) {
4795 tkls_klass = this_klass;
4796 }
4798 // Check for classes now being equal
4799 if (tkls_klass->equals(this_klass)) {
4800 // If the klasses are equal, the constants may still differ. Fall to
4801 // NotNull if they do (neither constant is NULL; that is a special case
4802 // handled elsewhere).
4803 if( ptr == Constant ) {
4804 if (this->_ptr == Constant && tkls->_ptr == Constant &&
4805 this->klass()->equals(tkls->klass()));
4806 else if (above_centerline(this->ptr()));
4807 else if (above_centerline(tkls->ptr()));
4808 else
4809 ptr = NotNull;
4810 }
4811 return make( ptr, this_klass, off );
4812 } // Else classes are not equal
4814 // Since klasses are different, we require the LCA in the Java
4815 // class hierarchy - which means we have to fall to at least NotNull.
4816 if( ptr == TopPTR || ptr == AnyNull || ptr == Constant )
4817 ptr = NotNull;
4818 // Now we find the LCA of Java classes
4819 ciKlass* k = this_klass->least_common_ancestor(tkls_klass);
4820 return make( ptr, k, off );
4821 } // End of case KlassPtr
4823 } // End of switch
4824 return this; // Return the double constant
4825 }
4827 //------------------------------xdual------------------------------------------
4828 // Dual: compute field-by-field dual
4829 const Type *TypeKlassPtr::xdual() const {
4830 return new TypeKlassPtr( dual_ptr(), klass(), dual_offset() );
4831 }
4833 //------------------------------get_con----------------------------------------
4834 intptr_t TypeKlassPtr::get_con() const {
4835 assert( _ptr == Null || _ptr == Constant, "" );
4836 assert( _offset >= 0, "" );
4838 if (_offset != 0) {
4839 // After being ported to the compiler interface, the compiler no longer
4840 // directly manipulates the addresses of oops. Rather, it only has a pointer
4841 // to a handle at compile time. This handle is embedded in the generated
4842 // code and dereferenced at the time the nmethod is made. Until that time,
4843 // it is not reasonable to do arithmetic with the addresses of oops (we don't
4844 // have access to the addresses!). This does not seem to currently happen,
4845 // but this assertion here is to help prevent its occurence.
4846 tty->print_cr("Found oop constant with non-zero offset");
4847 ShouldNotReachHere();
4848 }
4850 return (intptr_t)klass()->constant_encoding();
4851 }
4852 //------------------------------dump2------------------------------------------
4853 // Dump Klass Type
4854 #ifndef PRODUCT
4855 void TypeKlassPtr::dump2( Dict & d, uint depth, outputStream *st ) const {
4856 switch( _ptr ) {
4857 case Constant:
4858 st->print("precise ");
4859 case NotNull:
4860 {
4861 const char *name = klass()->name()->as_utf8();
4862 if( name ) {
4863 st->print("klass %s: " INTPTR_FORMAT, name, klass());
4864 } else {
4865 ShouldNotReachHere();
4866 }
4867 }
4868 case BotPTR:
4869 if( !WizardMode && !Verbose && !_klass_is_exact ) break;
4870 case TopPTR:
4871 case AnyNull:
4872 st->print(":%s", ptr_msg[_ptr]);
4873 if( _klass_is_exact ) st->print(":exact");
4874 break;
4875 }
4877 if( _offset ) { // Dump offset, if any
4878 if( _offset == OffsetBot ) { st->print("+any"); }
4879 else if( _offset == OffsetTop ) { st->print("+unknown"); }
4880 else { st->print("+%d", _offset); }
4881 }
4883 st->print(" *");
4884 }
4885 #endif
4889 //=============================================================================
4890 // Convenience common pre-built types.
4892 //------------------------------make-------------------------------------------
4893 const TypeFunc *TypeFunc::make( const TypeTuple *domain, const TypeTuple *range ) {
4894 return (TypeFunc*)(new TypeFunc(domain,range))->hashcons();
4895 }
4897 //------------------------------make-------------------------------------------
4898 const TypeFunc *TypeFunc::make(ciMethod* method) {
4899 Compile* C = Compile::current();
4900 const TypeFunc* tf = C->last_tf(method); // check cache
4901 if (tf != NULL) return tf; // The hit rate here is almost 50%.
4902 const TypeTuple *domain;
4903 if (method->is_static()) {
4904 domain = TypeTuple::make_domain(NULL, method->signature());
4905 } else {
4906 domain = TypeTuple::make_domain(method->holder(), method->signature());
4907 }
4908 const TypeTuple *range = TypeTuple::make_range(method->signature());
4909 tf = TypeFunc::make(domain, range);
4910 C->set_last_tf(method, tf); // fill cache
4911 return tf;
4912 }
4914 //------------------------------meet-------------------------------------------
4915 // Compute the MEET of two types. It returns a new Type object.
4916 const Type *TypeFunc::xmeet( const Type *t ) const {
4917 // Perform a fast test for common case; meeting the same types together.
4918 if( this == t ) return this; // Meeting same type-rep?
4920 // Current "this->_base" is Func
4921 switch (t->base()) { // switch on original type
4923 case Bottom: // Ye Olde Default
4924 return t;
4926 default: // All else is a mistake
4927 typerr(t);
4929 case Top:
4930 break;
4931 }
4932 return this; // Return the double constant
4933 }
4935 //------------------------------xdual------------------------------------------
4936 // Dual: compute field-by-field dual
4937 const Type *TypeFunc::xdual() const {
4938 return this;
4939 }
4941 //------------------------------eq---------------------------------------------
4942 // Structural equality check for Type representations
4943 bool TypeFunc::eq( const Type *t ) const {
4944 const TypeFunc *a = (const TypeFunc*)t;
4945 return _domain == a->_domain &&
4946 _range == a->_range;
4947 }
4949 //------------------------------hash-------------------------------------------
4950 // Type-specific hashing function.
4951 int TypeFunc::hash(void) const {
4952 return (intptr_t)_domain + (intptr_t)_range;
4953 }
4955 //------------------------------dump2------------------------------------------
4956 // Dump Function Type
4957 #ifndef PRODUCT
4958 void TypeFunc::dump2( Dict &d, uint depth, outputStream *st ) const {
4959 if( _range->_cnt <= Parms )
4960 st->print("void");
4961 else {
4962 uint i;
4963 for (i = Parms; i < _range->_cnt-1; i++) {
4964 _range->field_at(i)->dump2(d,depth,st);
4965 st->print("/");
4966 }
4967 _range->field_at(i)->dump2(d,depth,st);
4968 }
4969 st->print(" ");
4970 st->print("( ");
4971 if( !depth || d[this] ) { // Check for recursive dump
4972 st->print("...)");
4973 return;
4974 }
4975 d.Insert((void*)this,(void*)this); // Stop recursion
4976 if (Parms < _domain->_cnt)
4977 _domain->field_at(Parms)->dump2(d,depth-1,st);
4978 for (uint i = Parms+1; i < _domain->_cnt; i++) {
4979 st->print(", ");
4980 _domain->field_at(i)->dump2(d,depth-1,st);
4981 }
4982 st->print(" )");
4983 }
4984 #endif
4986 //------------------------------singleton--------------------------------------
4987 // TRUE if Type is a singleton type, FALSE otherwise. Singletons are simple
4988 // constants (Ldi nodes). Singletons are integer, float or double constants
4989 // or a single symbol.
4990 bool TypeFunc::singleton(void) const {
4991 return false; // Never a singleton
4992 }
4994 bool TypeFunc::empty(void) const {
4995 return false; // Never empty
4996 }
4999 BasicType TypeFunc::return_type() const{
5000 if (range()->cnt() == TypeFunc::Parms) {
5001 return T_VOID;
5002 }
5003 return range()->field_at(TypeFunc::Parms)->basic_type();
5004 }