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