Mon, 28 Jul 2008 17:12:52 -0700
6726999: nsk/stress/jck12a/jck12a010 assert(n != null,"Bad immediate dominator info.")
Summary: Escape Analysis fixes.
Reviewed-by: never, rasbold
1 /*
2 * Copyright 1997-2008 Sun Microsystems, Inc. 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 Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
20 * CA 95054 USA or visit www.sun.com if you need additional information or
21 * have any questions.
22 *
23 */
25 // Portions of code courtesy of Clifford Click
27 // Optimization - Graph Style
29 #include "incls/_precompiled.incl"
30 #include "incls/_type.cpp.incl"
32 // Dictionary of types shared among compilations.
33 Dict* Type::_shared_type_dict = NULL;
35 // Array which maps compiler types to Basic Types
36 const BasicType Type::_basic_type[Type::lastype] = {
37 T_ILLEGAL, // Bad
38 T_ILLEGAL, // Control
39 T_VOID, // Top
40 T_INT, // Int
41 T_LONG, // Long
42 T_VOID, // Half
43 T_NARROWOOP, // NarrowOop
45 T_ILLEGAL, // Tuple
46 T_ARRAY, // Array
48 T_ADDRESS, // AnyPtr // shows up in factory methods for NULL_PTR
49 T_ADDRESS, // RawPtr
50 T_OBJECT, // OopPtr
51 T_OBJECT, // InstPtr
52 T_OBJECT, // AryPtr
53 T_OBJECT, // KlassPtr
55 T_OBJECT, // Function
56 T_ILLEGAL, // Abio
57 T_ADDRESS, // Return_Address
58 T_ILLEGAL, // Memory
59 T_FLOAT, // FloatTop
60 T_FLOAT, // FloatCon
61 T_FLOAT, // FloatBot
62 T_DOUBLE, // DoubleTop
63 T_DOUBLE, // DoubleCon
64 T_DOUBLE, // DoubleBot
65 T_ILLEGAL, // Bottom
66 };
68 // Map ideal registers (machine types) to ideal types
69 const Type *Type::mreg2type[_last_machine_leaf];
71 // Map basic types to canonical Type* pointers.
72 const Type* Type:: _const_basic_type[T_CONFLICT+1];
74 // Map basic types to constant-zero Types.
75 const Type* Type:: _zero_type[T_CONFLICT+1];
77 // Map basic types to array-body alias types.
78 const TypeAryPtr* TypeAryPtr::_array_body_type[T_CONFLICT+1];
80 //=============================================================================
81 // Convenience common pre-built types.
82 const Type *Type::ABIO; // State-of-machine only
83 const Type *Type::BOTTOM; // All values
84 const Type *Type::CONTROL; // Control only
85 const Type *Type::DOUBLE; // All doubles
86 const Type *Type::FLOAT; // All floats
87 const Type *Type::HALF; // Placeholder half of doublewide type
88 const Type *Type::MEMORY; // Abstract store only
89 const Type *Type::RETURN_ADDRESS;
90 const Type *Type::TOP; // No values in set
92 //------------------------------get_const_type---------------------------
93 const Type* Type::get_const_type(ciType* type) {
94 if (type == NULL) {
95 return NULL;
96 } else if (type->is_primitive_type()) {
97 return get_const_basic_type(type->basic_type());
98 } else {
99 return TypeOopPtr::make_from_klass(type->as_klass());
100 }
101 }
103 //---------------------------array_element_basic_type---------------------------------
104 // Mapping to the array element's basic type.
105 BasicType Type::array_element_basic_type() const {
106 BasicType bt = basic_type();
107 if (bt == T_INT) {
108 if (this == TypeInt::INT) return T_INT;
109 if (this == TypeInt::CHAR) return T_CHAR;
110 if (this == TypeInt::BYTE) return T_BYTE;
111 if (this == TypeInt::BOOL) return T_BOOLEAN;
112 if (this == TypeInt::SHORT) return T_SHORT;
113 return T_VOID;
114 }
115 return bt;
116 }
118 //---------------------------get_typeflow_type---------------------------------
119 // Import a type produced by ciTypeFlow.
120 const Type* Type::get_typeflow_type(ciType* type) {
121 switch (type->basic_type()) {
123 case ciTypeFlow::StateVector::T_BOTTOM:
124 assert(type == ciTypeFlow::StateVector::bottom_type(), "");
125 return Type::BOTTOM;
127 case ciTypeFlow::StateVector::T_TOP:
128 assert(type == ciTypeFlow::StateVector::top_type(), "");
129 return Type::TOP;
131 case ciTypeFlow::StateVector::T_NULL:
132 assert(type == ciTypeFlow::StateVector::null_type(), "");
133 return TypePtr::NULL_PTR;
135 case ciTypeFlow::StateVector::T_LONG2:
136 // The ciTypeFlow pass pushes a long, then the half.
137 // We do the same.
138 assert(type == ciTypeFlow::StateVector::long2_type(), "");
139 return TypeInt::TOP;
141 case ciTypeFlow::StateVector::T_DOUBLE2:
142 // The ciTypeFlow pass pushes double, then the half.
143 // Our convention is the same.
144 assert(type == ciTypeFlow::StateVector::double2_type(), "");
145 return Type::TOP;
147 case T_ADDRESS:
148 assert(type->is_return_address(), "");
149 return TypeRawPtr::make((address)(intptr_t)type->as_return_address()->bci());
151 default:
152 // make sure we did not mix up the cases:
153 assert(type != ciTypeFlow::StateVector::bottom_type(), "");
154 assert(type != ciTypeFlow::StateVector::top_type(), "");
155 assert(type != ciTypeFlow::StateVector::null_type(), "");
156 assert(type != ciTypeFlow::StateVector::long2_type(), "");
157 assert(type != ciTypeFlow::StateVector::double2_type(), "");
158 assert(!type->is_return_address(), "");
160 return Type::get_const_type(type);
161 }
162 }
165 //------------------------------make-------------------------------------------
166 // Create a simple Type, with default empty symbol sets. Then hashcons it
167 // and look for an existing copy in the type dictionary.
168 const Type *Type::make( enum TYPES t ) {
169 return (new Type(t))->hashcons();
170 }
172 //------------------------------cmp--------------------------------------------
173 int Type::cmp( const Type *const t1, const Type *const t2 ) {
174 if( t1->_base != t2->_base )
175 return 1; // Missed badly
176 assert(t1 != t2 || t1->eq(t2), "eq must be reflexive");
177 return !t1->eq(t2); // Return ZERO if equal
178 }
180 //------------------------------hash-------------------------------------------
181 int Type::uhash( const Type *const t ) {
182 return t->hash();
183 }
185 //--------------------------Initialize_shared----------------------------------
186 void Type::Initialize_shared(Compile* current) {
187 // This method does not need to be locked because the first system
188 // compilations (stub compilations) occur serially. If they are
189 // changed to proceed in parallel, then this section will need
190 // locking.
192 Arena* save = current->type_arena();
193 Arena* shared_type_arena = new Arena();
195 current->set_type_arena(shared_type_arena);
196 _shared_type_dict =
197 new (shared_type_arena) Dict( (CmpKey)Type::cmp, (Hash)Type::uhash,
198 shared_type_arena, 128 );
199 current->set_type_dict(_shared_type_dict);
201 // Make shared pre-built types.
202 CONTROL = make(Control); // Control only
203 TOP = make(Top); // No values in set
204 MEMORY = make(Memory); // Abstract store only
205 ABIO = make(Abio); // State-of-machine only
206 RETURN_ADDRESS=make(Return_Address);
207 FLOAT = make(FloatBot); // All floats
208 DOUBLE = make(DoubleBot); // All doubles
209 BOTTOM = make(Bottom); // Everything
210 HALF = make(Half); // Placeholder half of doublewide type
212 TypeF::ZERO = TypeF::make(0.0); // Float 0 (positive zero)
213 TypeF::ONE = TypeF::make(1.0); // Float 1
215 TypeD::ZERO = TypeD::make(0.0); // Double 0 (positive zero)
216 TypeD::ONE = TypeD::make(1.0); // Double 1
218 TypeInt::MINUS_1 = TypeInt::make(-1); // -1
219 TypeInt::ZERO = TypeInt::make( 0); // 0
220 TypeInt::ONE = TypeInt::make( 1); // 1
221 TypeInt::BOOL = TypeInt::make(0,1, WidenMin); // 0 or 1, FALSE or TRUE.
222 TypeInt::CC = TypeInt::make(-1, 1, WidenMin); // -1, 0 or 1, condition codes
223 TypeInt::CC_LT = TypeInt::make(-1,-1, WidenMin); // == TypeInt::MINUS_1
224 TypeInt::CC_GT = TypeInt::make( 1, 1, WidenMin); // == TypeInt::ONE
225 TypeInt::CC_EQ = TypeInt::make( 0, 0, WidenMin); // == TypeInt::ZERO
226 TypeInt::CC_LE = TypeInt::make(-1, 0, WidenMin);
227 TypeInt::CC_GE = TypeInt::make( 0, 1, WidenMin); // == TypeInt::BOOL
228 TypeInt::BYTE = TypeInt::make(-128,127, WidenMin); // Bytes
229 TypeInt::CHAR = TypeInt::make(0,65535, WidenMin); // Java chars
230 TypeInt::SHORT = TypeInt::make(-32768,32767, WidenMin); // Java shorts
231 TypeInt::POS = TypeInt::make(0,max_jint, WidenMin); // Non-neg values
232 TypeInt::POS1 = TypeInt::make(1,max_jint, WidenMin); // Positive values
233 TypeInt::INT = TypeInt::make(min_jint,max_jint, WidenMax); // 32-bit integers
234 TypeInt::SYMINT = TypeInt::make(-max_jint,max_jint,WidenMin); // symmetric range
235 // CmpL is overloaded both as the bytecode computation returning
236 // a trinary (-1,0,+1) integer result AND as an efficient long
237 // compare returning optimizer ideal-type flags.
238 assert( TypeInt::CC_LT == TypeInt::MINUS_1, "types must match for CmpL to work" );
239 assert( TypeInt::CC_GT == TypeInt::ONE, "types must match for CmpL to work" );
240 assert( TypeInt::CC_EQ == TypeInt::ZERO, "types must match for CmpL to work" );
241 assert( TypeInt::CC_GE == TypeInt::BOOL, "types must match for CmpL to work" );
243 TypeLong::MINUS_1 = TypeLong::make(-1); // -1
244 TypeLong::ZERO = TypeLong::make( 0); // 0
245 TypeLong::ONE = TypeLong::make( 1); // 1
246 TypeLong::POS = TypeLong::make(0,max_jlong, WidenMin); // Non-neg values
247 TypeLong::LONG = TypeLong::make(min_jlong,max_jlong,WidenMax); // 64-bit integers
248 TypeLong::INT = TypeLong::make((jlong)min_jint,(jlong)max_jint,WidenMin);
249 TypeLong::UINT = TypeLong::make(0,(jlong)max_juint,WidenMin);
251 const Type **fboth =(const Type**)shared_type_arena->Amalloc_4(2*sizeof(Type*));
252 fboth[0] = Type::CONTROL;
253 fboth[1] = Type::CONTROL;
254 TypeTuple::IFBOTH = TypeTuple::make( 2, fboth );
256 const Type **ffalse =(const Type**)shared_type_arena->Amalloc_4(2*sizeof(Type*));
257 ffalse[0] = Type::CONTROL;
258 ffalse[1] = Type::TOP;
259 TypeTuple::IFFALSE = TypeTuple::make( 2, ffalse );
261 const Type **fneither =(const Type**)shared_type_arena->Amalloc_4(2*sizeof(Type*));
262 fneither[0] = Type::TOP;
263 fneither[1] = Type::TOP;
264 TypeTuple::IFNEITHER = TypeTuple::make( 2, fneither );
266 const Type **ftrue =(const Type**)shared_type_arena->Amalloc_4(2*sizeof(Type*));
267 ftrue[0] = Type::TOP;
268 ftrue[1] = Type::CONTROL;
269 TypeTuple::IFTRUE = TypeTuple::make( 2, ftrue );
271 const Type **floop =(const Type**)shared_type_arena->Amalloc_4(2*sizeof(Type*));
272 floop[0] = Type::CONTROL;
273 floop[1] = TypeInt::INT;
274 TypeTuple::LOOPBODY = TypeTuple::make( 2, floop );
276 TypePtr::NULL_PTR= TypePtr::make( AnyPtr, TypePtr::Null, 0 );
277 TypePtr::NOTNULL = TypePtr::make( AnyPtr, TypePtr::NotNull, OffsetBot );
278 TypePtr::BOTTOM = TypePtr::make( AnyPtr, TypePtr::BotPTR, OffsetBot );
280 TypeRawPtr::BOTTOM = TypeRawPtr::make( TypePtr::BotPTR );
281 TypeRawPtr::NOTNULL= TypeRawPtr::make( TypePtr::NotNull );
283 const Type **fmembar = TypeTuple::fields(0);
284 TypeTuple::MEMBAR = TypeTuple::make(TypeFunc::Parms+0, fmembar);
286 const Type **fsc = (const Type**)shared_type_arena->Amalloc_4(2*sizeof(Type*));
287 fsc[0] = TypeInt::CC;
288 fsc[1] = Type::MEMORY;
289 TypeTuple::STORECONDITIONAL = TypeTuple::make(2, fsc);
291 TypeInstPtr::NOTNULL = TypeInstPtr::make(TypePtr::NotNull, current->env()->Object_klass());
292 TypeInstPtr::BOTTOM = TypeInstPtr::make(TypePtr::BotPTR, current->env()->Object_klass());
293 TypeInstPtr::MIRROR = TypeInstPtr::make(TypePtr::NotNull, current->env()->Class_klass());
294 TypeInstPtr::MARK = TypeInstPtr::make(TypePtr::BotPTR, current->env()->Object_klass(),
295 false, 0, oopDesc::mark_offset_in_bytes());
296 TypeInstPtr::KLASS = TypeInstPtr::make(TypePtr::BotPTR, current->env()->Object_klass(),
297 false, 0, oopDesc::klass_offset_in_bytes());
298 TypeOopPtr::BOTTOM = TypeOopPtr::make(TypePtr::BotPTR, OffsetBot);
300 TypeNarrowOop::NULL_PTR = TypeNarrowOop::make( TypePtr::NULL_PTR );
301 TypeNarrowOop::BOTTOM = TypeNarrowOop::make( TypeInstPtr::BOTTOM );
303 mreg2type[Op_Node] = Type::BOTTOM;
304 mreg2type[Op_Set ] = 0;
305 mreg2type[Op_RegN] = TypeNarrowOop::BOTTOM;
306 mreg2type[Op_RegI] = TypeInt::INT;
307 mreg2type[Op_RegP] = TypePtr::BOTTOM;
308 mreg2type[Op_RegF] = Type::FLOAT;
309 mreg2type[Op_RegD] = Type::DOUBLE;
310 mreg2type[Op_RegL] = TypeLong::LONG;
311 mreg2type[Op_RegFlags] = TypeInt::CC;
313 TypeAryPtr::RANGE = TypeAryPtr::make( TypePtr::BotPTR, TypeAry::make(Type::BOTTOM,TypeInt::POS), current->env()->Object_klass(), false, arrayOopDesc::length_offset_in_bytes());
315 TypeAryPtr::NARROWOOPS = TypeAryPtr::make(TypePtr::BotPTR, TypeAry::make(TypeNarrowOop::BOTTOM, TypeInt::POS), NULL /*ciArrayKlass::make(o)*/, false, Type::OffsetBot);
317 #ifdef _LP64
318 if (UseCompressedOops) {
319 TypeAryPtr::OOPS = TypeAryPtr::NARROWOOPS;
320 } else
321 #endif
322 {
323 // There is no shared klass for Object[]. See note in TypeAryPtr::klass().
324 TypeAryPtr::OOPS = TypeAryPtr::make(TypePtr::BotPTR, TypeAry::make(TypeInstPtr::BOTTOM,TypeInt::POS), NULL /*ciArrayKlass::make(o)*/, false, Type::OffsetBot);
325 }
326 TypeAryPtr::BYTES = TypeAryPtr::make(TypePtr::BotPTR, TypeAry::make(TypeInt::BYTE ,TypeInt::POS), ciTypeArrayKlass::make(T_BYTE), true, Type::OffsetBot);
327 TypeAryPtr::SHORTS = TypeAryPtr::make(TypePtr::BotPTR, TypeAry::make(TypeInt::SHORT ,TypeInt::POS), ciTypeArrayKlass::make(T_SHORT), true, Type::OffsetBot);
328 TypeAryPtr::CHARS = TypeAryPtr::make(TypePtr::BotPTR, TypeAry::make(TypeInt::CHAR ,TypeInt::POS), ciTypeArrayKlass::make(T_CHAR), true, Type::OffsetBot);
329 TypeAryPtr::INTS = TypeAryPtr::make(TypePtr::BotPTR, TypeAry::make(TypeInt::INT ,TypeInt::POS), ciTypeArrayKlass::make(T_INT), true, Type::OffsetBot);
330 TypeAryPtr::LONGS = TypeAryPtr::make(TypePtr::BotPTR, TypeAry::make(TypeLong::LONG ,TypeInt::POS), ciTypeArrayKlass::make(T_LONG), true, Type::OffsetBot);
331 TypeAryPtr::FLOATS = TypeAryPtr::make(TypePtr::BotPTR, TypeAry::make(Type::FLOAT ,TypeInt::POS), ciTypeArrayKlass::make(T_FLOAT), true, Type::OffsetBot);
332 TypeAryPtr::DOUBLES = TypeAryPtr::make(TypePtr::BotPTR, TypeAry::make(Type::DOUBLE ,TypeInt::POS), ciTypeArrayKlass::make(T_DOUBLE), true, Type::OffsetBot);
334 // Nobody should ask _array_body_type[T_NARROWOOP]. Use NULL as assert.
335 TypeAryPtr::_array_body_type[T_NARROWOOP] = NULL;
336 TypeAryPtr::_array_body_type[T_OBJECT] = TypeAryPtr::OOPS;
337 TypeAryPtr::_array_body_type[T_ARRAY] = TypeAryPtr::OOPS; // arrays are stored in oop arrays
338 TypeAryPtr::_array_body_type[T_BYTE] = TypeAryPtr::BYTES;
339 TypeAryPtr::_array_body_type[T_BOOLEAN] = TypeAryPtr::BYTES; // boolean[] is a byte array
340 TypeAryPtr::_array_body_type[T_SHORT] = TypeAryPtr::SHORTS;
341 TypeAryPtr::_array_body_type[T_CHAR] = TypeAryPtr::CHARS;
342 TypeAryPtr::_array_body_type[T_INT] = TypeAryPtr::INTS;
343 TypeAryPtr::_array_body_type[T_LONG] = TypeAryPtr::LONGS;
344 TypeAryPtr::_array_body_type[T_FLOAT] = TypeAryPtr::FLOATS;
345 TypeAryPtr::_array_body_type[T_DOUBLE] = TypeAryPtr::DOUBLES;
347 TypeKlassPtr::OBJECT = TypeKlassPtr::make( TypePtr::NotNull, current->env()->Object_klass(), 0 );
348 TypeKlassPtr::OBJECT_OR_NULL = TypeKlassPtr::make( TypePtr::BotPTR, current->env()->Object_klass(), 0 );
350 const Type **fi2c = TypeTuple::fields(2);
351 fi2c[TypeFunc::Parms+0] = TypeInstPtr::BOTTOM; // methodOop
352 fi2c[TypeFunc::Parms+1] = TypeRawPtr::BOTTOM; // argument pointer
353 TypeTuple::START_I2C = TypeTuple::make(TypeFunc::Parms+2, fi2c);
355 const Type **intpair = TypeTuple::fields(2);
356 intpair[0] = TypeInt::INT;
357 intpair[1] = TypeInt::INT;
358 TypeTuple::INT_PAIR = TypeTuple::make(2, intpair);
360 const Type **longpair = TypeTuple::fields(2);
361 longpair[0] = TypeLong::LONG;
362 longpair[1] = TypeLong::LONG;
363 TypeTuple::LONG_PAIR = TypeTuple::make(2, longpair);
365 _const_basic_type[T_NARROWOOP] = TypeNarrowOop::BOTTOM;
366 _const_basic_type[T_BOOLEAN] = TypeInt::BOOL;
367 _const_basic_type[T_CHAR] = TypeInt::CHAR;
368 _const_basic_type[T_BYTE] = TypeInt::BYTE;
369 _const_basic_type[T_SHORT] = TypeInt::SHORT;
370 _const_basic_type[T_INT] = TypeInt::INT;
371 _const_basic_type[T_LONG] = TypeLong::LONG;
372 _const_basic_type[T_FLOAT] = Type::FLOAT;
373 _const_basic_type[T_DOUBLE] = Type::DOUBLE;
374 _const_basic_type[T_OBJECT] = TypeInstPtr::BOTTOM;
375 _const_basic_type[T_ARRAY] = TypeInstPtr::BOTTOM; // there is no separate bottom for arrays
376 _const_basic_type[T_VOID] = TypePtr::NULL_PTR; // reflection represents void this way
377 _const_basic_type[T_ADDRESS] = TypeRawPtr::BOTTOM; // both interpreter return addresses & random raw ptrs
378 _const_basic_type[T_CONFLICT]= Type::BOTTOM; // why not?
380 _zero_type[T_NARROWOOP] = TypeNarrowOop::NULL_PTR;
381 _zero_type[T_BOOLEAN] = TypeInt::ZERO; // false == 0
382 _zero_type[T_CHAR] = TypeInt::ZERO; // '\0' == 0
383 _zero_type[T_BYTE] = TypeInt::ZERO; // 0x00 == 0
384 _zero_type[T_SHORT] = TypeInt::ZERO; // 0x0000 == 0
385 _zero_type[T_INT] = TypeInt::ZERO;
386 _zero_type[T_LONG] = TypeLong::ZERO;
387 _zero_type[T_FLOAT] = TypeF::ZERO;
388 _zero_type[T_DOUBLE] = TypeD::ZERO;
389 _zero_type[T_OBJECT] = TypePtr::NULL_PTR;
390 _zero_type[T_ARRAY] = TypePtr::NULL_PTR; // null array is null oop
391 _zero_type[T_ADDRESS] = TypePtr::NULL_PTR; // raw pointers use the same null
392 _zero_type[T_VOID] = Type::TOP; // the only void value is no value at all
394 // get_zero_type() should not happen for T_CONFLICT
395 _zero_type[T_CONFLICT]= NULL;
397 // Restore working type arena.
398 current->set_type_arena(save);
399 current->set_type_dict(NULL);
400 }
402 //------------------------------Initialize-------------------------------------
403 void Type::Initialize(Compile* current) {
404 assert(current->type_arena() != NULL, "must have created type arena");
406 if (_shared_type_dict == NULL) {
407 Initialize_shared(current);
408 }
410 Arena* type_arena = current->type_arena();
412 // Create the hash-cons'ing dictionary with top-level storage allocation
413 Dict *tdic = new (type_arena) Dict( (CmpKey)Type::cmp,(Hash)Type::uhash, type_arena, 128 );
414 current->set_type_dict(tdic);
416 // Transfer the shared types.
417 DictI i(_shared_type_dict);
418 for( ; i.test(); ++i ) {
419 Type* t = (Type*)i._value;
420 tdic->Insert(t,t); // New Type, insert into Type table
421 }
423 #ifdef ASSERT
424 verify_lastype();
425 #endif
426 }
428 //------------------------------hashcons---------------------------------------
429 // Do the hash-cons trick. If the Type already exists in the type table,
430 // delete the current Type and return the existing Type. Otherwise stick the
431 // current Type in the Type table.
432 const Type *Type::hashcons(void) {
433 debug_only(base()); // Check the assertion in Type::base().
434 // Look up the Type in the Type dictionary
435 Dict *tdic = type_dict();
436 Type* old = (Type*)(tdic->Insert(this, this, false));
437 if( old ) { // Pre-existing Type?
438 if( old != this ) // Yes, this guy is not the pre-existing?
439 delete this; // Yes, Nuke this guy
440 assert( old->_dual, "" );
441 return old; // Return pre-existing
442 }
444 // Every type has a dual (to make my lattice symmetric).
445 // Since we just discovered a new Type, compute its dual right now.
446 assert( !_dual, "" ); // No dual yet
447 _dual = xdual(); // Compute the dual
448 if( cmp(this,_dual)==0 ) { // Handle self-symmetric
449 _dual = this;
450 return this;
451 }
452 assert( !_dual->_dual, "" ); // No reverse dual yet
453 assert( !(*tdic)[_dual], "" ); // Dual not in type system either
454 // New Type, insert into Type table
455 tdic->Insert((void*)_dual,(void*)_dual);
456 ((Type*)_dual)->_dual = this; // Finish up being symmetric
457 #ifdef ASSERT
458 Type *dual_dual = (Type*)_dual->xdual();
459 assert( eq(dual_dual), "xdual(xdual()) should be identity" );
460 delete dual_dual;
461 #endif
462 return this; // Return new Type
463 }
465 //------------------------------eq---------------------------------------------
466 // Structural equality check for Type representations
467 bool Type::eq( const Type * ) const {
468 return true; // Nothing else can go wrong
469 }
471 //------------------------------hash-------------------------------------------
472 // Type-specific hashing function.
473 int Type::hash(void) const {
474 return _base;
475 }
477 //------------------------------is_finite--------------------------------------
478 // Has a finite value
479 bool Type::is_finite() const {
480 return false;
481 }
483 //------------------------------is_nan-----------------------------------------
484 // Is not a number (NaN)
485 bool Type::is_nan() const {
486 return false;
487 }
489 //------------------------------meet-------------------------------------------
490 // Compute the MEET of two types. NOT virtual. It enforces that meet is
491 // commutative and the lattice is symmetric.
492 const Type *Type::meet( const Type *t ) const {
493 if (isa_narrowoop() && t->isa_narrowoop()) {
494 const Type* result = make_ptr()->meet(t->make_ptr());
495 return result->make_narrowoop();
496 }
498 const Type *mt = xmeet(t);
499 if (isa_narrowoop() || t->isa_narrowoop()) return mt;
500 #ifdef ASSERT
501 assert( mt == t->xmeet(this), "meet not commutative" );
502 const Type* dual_join = mt->_dual;
503 const Type *t2t = dual_join->xmeet(t->_dual);
504 const Type *t2this = dual_join->xmeet( _dual);
506 // Interface meet Oop is Not Symmetric:
507 // Interface:AnyNull meet Oop:AnyNull == Interface:AnyNull
508 // Interface:NotNull meet Oop:NotNull == java/lang/Object:NotNull
509 const TypeInstPtr* this_inst = this->isa_instptr();
510 const TypeInstPtr* t_inst = t->isa_instptr();
511 bool interface_vs_oop = false;
512 if( this_inst && this_inst->is_loaded() && t_inst && t_inst->is_loaded() ) {
513 bool this_interface = this_inst->klass()->is_interface();
514 bool t_interface = t_inst->klass()->is_interface();
515 interface_vs_oop = this_interface ^ t_interface;
516 }
518 if( !interface_vs_oop && (t2t != t->_dual || t2this != _dual) ) {
519 tty->print_cr("=== Meet Not Symmetric ===");
520 tty->print("t = "); t->dump(); tty->cr();
521 tty->print("this= "); dump(); tty->cr();
522 tty->print("mt=(t meet this)= "); mt->dump(); tty->cr();
524 tty->print("t_dual= "); t->_dual->dump(); tty->cr();
525 tty->print("this_dual= "); _dual->dump(); tty->cr();
526 tty->print("mt_dual= "); mt->_dual->dump(); tty->cr();
528 tty->print("mt_dual meet t_dual= "); t2t ->dump(); tty->cr();
529 tty->print("mt_dual meet this_dual= "); t2this ->dump(); tty->cr();
531 fatal("meet not symmetric" );
532 }
533 #endif
534 return mt;
535 }
537 //------------------------------xmeet------------------------------------------
538 // Compute the MEET of two types. It returns a new Type object.
539 const Type *Type::xmeet( const Type *t ) const {
540 // Perform a fast test for common case; meeting the same types together.
541 if( this == t ) return this; // Meeting same type-rep?
543 // Meeting TOP with anything?
544 if( _base == Top ) return t;
546 // Meeting BOTTOM with anything?
547 if( _base == Bottom ) return BOTTOM;
549 // Current "this->_base" is one of: Bad, Multi, Control, Top,
550 // Abio, Abstore, Floatxxx, Doublexxx, Bottom, lastype.
551 switch (t->base()) { // Switch on original type
553 // Cut in half the number of cases I must handle. Only need cases for when
554 // the given enum "t->type" is less than or equal to the local enum "type".
555 case FloatCon:
556 case DoubleCon:
557 case Int:
558 case Long:
559 return t->xmeet(this);
561 case OopPtr:
562 return t->xmeet(this);
564 case InstPtr:
565 return t->xmeet(this);
567 case KlassPtr:
568 return t->xmeet(this);
570 case AryPtr:
571 return t->xmeet(this);
573 case NarrowOop:
574 return t->xmeet(this);
576 case Bad: // Type check
577 default: // Bogus type not in lattice
578 typerr(t);
579 return Type::BOTTOM;
581 case Bottom: // Ye Olde Default
582 return t;
584 case FloatTop:
585 if( _base == FloatTop ) return this;
586 case FloatBot: // Float
587 if( _base == FloatBot || _base == FloatTop ) return FLOAT;
588 if( _base == DoubleTop || _base == DoubleBot ) return Type::BOTTOM;
589 typerr(t);
590 return Type::BOTTOM;
592 case DoubleTop:
593 if( _base == DoubleTop ) return this;
594 case DoubleBot: // Double
595 if( _base == DoubleBot || _base == DoubleTop ) return DOUBLE;
596 if( _base == FloatTop || _base == FloatBot ) return Type::BOTTOM;
597 typerr(t);
598 return Type::BOTTOM;
600 // These next few cases must match exactly or it is a compile-time error.
601 case Control: // Control of code
602 case Abio: // State of world outside of program
603 case Memory:
604 if( _base == t->_base ) return this;
605 typerr(t);
606 return Type::BOTTOM;
608 case Top: // Top of the lattice
609 return this;
610 }
612 // The type is unchanged
613 return this;
614 }
616 //-----------------------------filter------------------------------------------
617 const Type *Type::filter( const Type *kills ) const {
618 const Type* ft = join(kills);
619 if (ft->empty())
620 return Type::TOP; // Canonical empty value
621 return ft;
622 }
624 //------------------------------xdual------------------------------------------
625 // Compute dual right now.
626 const Type::TYPES Type::dual_type[Type::lastype] = {
627 Bad, // Bad
628 Control, // Control
629 Bottom, // Top
630 Bad, // Int - handled in v-call
631 Bad, // Long - handled in v-call
632 Half, // Half
633 Bad, // NarrowOop - handled in v-call
635 Bad, // Tuple - handled in v-call
636 Bad, // Array - handled in v-call
638 Bad, // AnyPtr - handled in v-call
639 Bad, // RawPtr - handled in v-call
640 Bad, // OopPtr - handled in v-call
641 Bad, // InstPtr - handled in v-call
642 Bad, // AryPtr - handled in v-call
643 Bad, // KlassPtr - handled in v-call
645 Bad, // Function - handled in v-call
646 Abio, // Abio
647 Return_Address,// Return_Address
648 Memory, // Memory
649 FloatBot, // FloatTop
650 FloatCon, // FloatCon
651 FloatTop, // FloatBot
652 DoubleBot, // DoubleTop
653 DoubleCon, // DoubleCon
654 DoubleTop, // DoubleBot
655 Top // Bottom
656 };
658 const Type *Type::xdual() const {
659 // Note: the base() accessor asserts the sanity of _base.
660 assert(dual_type[base()] != Bad, "implement with v-call");
661 return new Type(dual_type[_base]);
662 }
664 //------------------------------has_memory-------------------------------------
665 bool Type::has_memory() const {
666 Type::TYPES tx = base();
667 if (tx == Memory) return true;
668 if (tx == Tuple) {
669 const TypeTuple *t = is_tuple();
670 for (uint i=0; i < t->cnt(); i++) {
671 tx = t->field_at(i)->base();
672 if (tx == Memory) return true;
673 }
674 }
675 return false;
676 }
678 #ifndef PRODUCT
679 //------------------------------dump2------------------------------------------
680 void Type::dump2( Dict &d, uint depth, outputStream *st ) const {
681 st->print(msg[_base]);
682 }
684 //------------------------------dump-------------------------------------------
685 void Type::dump_on(outputStream *st) const {
686 ResourceMark rm;
687 Dict d(cmpkey,hashkey); // Stop recursive type dumping
688 dump2(d,1, st);
689 if (is_ptr_to_narrowoop()) {
690 st->print(" [narrow]");
691 }
692 }
694 //------------------------------data-------------------------------------------
695 const char * const Type::msg[Type::lastype] = {
696 "bad","control","top","int:","long:","half", "narrowoop:",
697 "tuple:", "aryptr",
698 "anyptr:", "rawptr:", "java:", "inst:", "ary:", "klass:",
699 "func", "abIO", "return_address", "memory",
700 "float_top", "ftcon:", "float",
701 "double_top", "dblcon:", "double",
702 "bottom"
703 };
704 #endif
706 //------------------------------singleton--------------------------------------
707 // TRUE if Type is a singleton type, FALSE otherwise. Singletons are simple
708 // constants (Ldi nodes). Singletons are integer, float or double constants.
709 bool Type::singleton(void) const {
710 return _base == Top || _base == Half;
711 }
713 //------------------------------empty------------------------------------------
714 // TRUE if Type is a type with no values, FALSE otherwise.
715 bool Type::empty(void) const {
716 switch (_base) {
717 case DoubleTop:
718 case FloatTop:
719 case Top:
720 return true;
722 case Half:
723 case Abio:
724 case Return_Address:
725 case Memory:
726 case Bottom:
727 case FloatBot:
728 case DoubleBot:
729 return false; // never a singleton, therefore never empty
730 }
732 ShouldNotReachHere();
733 return false;
734 }
736 //------------------------------dump_stats-------------------------------------
737 // Dump collected statistics to stderr
738 #ifndef PRODUCT
739 void Type::dump_stats() {
740 tty->print("Types made: %d\n", type_dict()->Size());
741 }
742 #endif
744 //------------------------------typerr-----------------------------------------
745 void Type::typerr( const Type *t ) const {
746 #ifndef PRODUCT
747 tty->print("\nError mixing types: ");
748 dump();
749 tty->print(" and ");
750 t->dump();
751 tty->print("\n");
752 #endif
753 ShouldNotReachHere();
754 }
756 //------------------------------isa_oop_ptr------------------------------------
757 // Return true if type is an oop pointer type. False for raw pointers.
758 static char isa_oop_ptr_tbl[Type::lastype] = {
759 0,0,0,0,0,0,0/*narrowoop*/,0/*tuple*/, 0/*ary*/,
760 0/*anyptr*/,0/*rawptr*/,1/*OopPtr*/,1/*InstPtr*/,1/*AryPtr*/,1/*KlassPtr*/,
761 0/*func*/,0,0/*return_address*/,0,
762 /*floats*/0,0,0, /*doubles*/0,0,0,
763 0
764 };
765 bool Type::isa_oop_ptr() const {
766 return isa_oop_ptr_tbl[_base] != 0;
767 }
769 //------------------------------dump_stats-------------------------------------
770 // // Check that arrays match type enum
771 #ifndef PRODUCT
772 void Type::verify_lastype() {
773 // Check that arrays match enumeration
774 assert( Type::dual_type [Type::lastype - 1] == Type::Top, "did not update array");
775 assert( strcmp(Type::msg [Type::lastype - 1],"bottom") == 0, "did not update array");
776 // assert( PhiNode::tbl [Type::lastype - 1] == NULL, "did not update array");
777 assert( Matcher::base2reg[Type::lastype - 1] == 0, "did not update array");
778 assert( isa_oop_ptr_tbl [Type::lastype - 1] == (char)0, "did not update array");
779 }
780 #endif
782 //=============================================================================
783 // Convenience common pre-built types.
784 const TypeF *TypeF::ZERO; // Floating point zero
785 const TypeF *TypeF::ONE; // Floating point one
787 //------------------------------make-------------------------------------------
788 // Create a float constant
789 const TypeF *TypeF::make(float f) {
790 return (TypeF*)(new TypeF(f))->hashcons();
791 }
793 //------------------------------meet-------------------------------------------
794 // Compute the MEET of two types. It returns a new Type object.
795 const Type *TypeF::xmeet( const Type *t ) const {
796 // Perform a fast test for common case; meeting the same types together.
797 if( this == t ) return this; // Meeting same type-rep?
799 // Current "this->_base" is FloatCon
800 switch (t->base()) { // Switch on original type
801 case AnyPtr: // Mixing with oops happens when javac
802 case RawPtr: // reuses local variables
803 case OopPtr:
804 case InstPtr:
805 case KlassPtr:
806 case AryPtr:
807 case Int:
808 case Long:
809 case DoubleTop:
810 case DoubleCon:
811 case DoubleBot:
812 case Bottom: // Ye Olde Default
813 return Type::BOTTOM;
815 case FloatBot:
816 return t;
818 default: // All else is a mistake
819 typerr(t);
821 case FloatCon: // Float-constant vs Float-constant?
822 if( jint_cast(_f) != jint_cast(t->getf()) ) // unequal constants?
823 // must compare bitwise as positive zero, negative zero and NaN have
824 // all the same representation in C++
825 return FLOAT; // Return generic float
826 // Equal constants
827 case Top:
828 case FloatTop:
829 break; // Return the float constant
830 }
831 return this; // Return the float constant
832 }
834 //------------------------------xdual------------------------------------------
835 // Dual: symmetric
836 const Type *TypeF::xdual() const {
837 return this;
838 }
840 //------------------------------eq---------------------------------------------
841 // Structural equality check for Type representations
842 bool TypeF::eq( const Type *t ) const {
843 if( g_isnan(_f) ||
844 g_isnan(t->getf()) ) {
845 // One or both are NANs. If both are NANs return true, else false.
846 return (g_isnan(_f) && g_isnan(t->getf()));
847 }
848 if (_f == t->getf()) {
849 // (NaN is impossible at this point, since it is not equal even to itself)
850 if (_f == 0.0) {
851 // difference between positive and negative zero
852 if (jint_cast(_f) != jint_cast(t->getf())) return false;
853 }
854 return true;
855 }
856 return false;
857 }
859 //------------------------------hash-------------------------------------------
860 // Type-specific hashing function.
861 int TypeF::hash(void) const {
862 return *(int*)(&_f);
863 }
865 //------------------------------is_finite--------------------------------------
866 // Has a finite value
867 bool TypeF::is_finite() const {
868 return g_isfinite(getf()) != 0;
869 }
871 //------------------------------is_nan-----------------------------------------
872 // Is not a number (NaN)
873 bool TypeF::is_nan() const {
874 return g_isnan(getf()) != 0;
875 }
877 //------------------------------dump2------------------------------------------
878 // Dump float constant Type
879 #ifndef PRODUCT
880 void TypeF::dump2( Dict &d, uint depth, outputStream *st ) const {
881 Type::dump2(d,depth, st);
882 st->print("%f", _f);
883 }
884 #endif
886 //------------------------------singleton--------------------------------------
887 // TRUE if Type is a singleton type, FALSE otherwise. Singletons are simple
888 // constants (Ldi nodes). Singletons are integer, float or double constants
889 // or a single symbol.
890 bool TypeF::singleton(void) const {
891 return true; // Always a singleton
892 }
894 bool TypeF::empty(void) const {
895 return false; // always exactly a singleton
896 }
898 //=============================================================================
899 // Convenience common pre-built types.
900 const TypeD *TypeD::ZERO; // Floating point zero
901 const TypeD *TypeD::ONE; // Floating point one
903 //------------------------------make-------------------------------------------
904 const TypeD *TypeD::make(double d) {
905 return (TypeD*)(new TypeD(d))->hashcons();
906 }
908 //------------------------------meet-------------------------------------------
909 // Compute the MEET of two types. It returns a new Type object.
910 const Type *TypeD::xmeet( const Type *t ) const {
911 // Perform a fast test for common case; meeting the same types together.
912 if( this == t ) return this; // Meeting same type-rep?
914 // Current "this->_base" is DoubleCon
915 switch (t->base()) { // Switch on original type
916 case AnyPtr: // Mixing with oops happens when javac
917 case RawPtr: // reuses local variables
918 case OopPtr:
919 case InstPtr:
920 case KlassPtr:
921 case AryPtr:
922 case NarrowOop:
923 case Int:
924 case Long:
925 case FloatTop:
926 case FloatCon:
927 case FloatBot:
928 case Bottom: // Ye Olde Default
929 return Type::BOTTOM;
931 case DoubleBot:
932 return t;
934 default: // All else is a mistake
935 typerr(t);
937 case DoubleCon: // Double-constant vs Double-constant?
938 if( jlong_cast(_d) != jlong_cast(t->getd()) ) // unequal constants? (see comment in TypeF::xmeet)
939 return DOUBLE; // Return generic double
940 case Top:
941 case DoubleTop:
942 break;
943 }
944 return this; // Return the double constant
945 }
947 //------------------------------xdual------------------------------------------
948 // Dual: symmetric
949 const Type *TypeD::xdual() const {
950 return this;
951 }
953 //------------------------------eq---------------------------------------------
954 // Structural equality check for Type representations
955 bool TypeD::eq( const Type *t ) const {
956 if( g_isnan(_d) ||
957 g_isnan(t->getd()) ) {
958 // One or both are NANs. If both are NANs return true, else false.
959 return (g_isnan(_d) && g_isnan(t->getd()));
960 }
961 if (_d == t->getd()) {
962 // (NaN is impossible at this point, since it is not equal even to itself)
963 if (_d == 0.0) {
964 // difference between positive and negative zero
965 if (jlong_cast(_d) != jlong_cast(t->getd())) return false;
966 }
967 return true;
968 }
969 return false;
970 }
972 //------------------------------hash-------------------------------------------
973 // Type-specific hashing function.
974 int TypeD::hash(void) const {
975 return *(int*)(&_d);
976 }
978 //------------------------------is_finite--------------------------------------
979 // Has a finite value
980 bool TypeD::is_finite() const {
981 return g_isfinite(getd()) != 0;
982 }
984 //------------------------------is_nan-----------------------------------------
985 // Is not a number (NaN)
986 bool TypeD::is_nan() const {
987 return g_isnan(getd()) != 0;
988 }
990 //------------------------------dump2------------------------------------------
991 // Dump double constant Type
992 #ifndef PRODUCT
993 void TypeD::dump2( Dict &d, uint depth, outputStream *st ) const {
994 Type::dump2(d,depth,st);
995 st->print("%f", _d);
996 }
997 #endif
999 //------------------------------singleton--------------------------------------
1000 // TRUE if Type is a singleton type, FALSE otherwise. Singletons are simple
1001 // constants (Ldi nodes). Singletons are integer, float or double constants
1002 // or a single symbol.
1003 bool TypeD::singleton(void) const {
1004 return true; // Always a singleton
1005 }
1007 bool TypeD::empty(void) const {
1008 return false; // always exactly a singleton
1009 }
1011 //=============================================================================
1012 // Convience common pre-built types.
1013 const TypeInt *TypeInt::MINUS_1;// -1
1014 const TypeInt *TypeInt::ZERO; // 0
1015 const TypeInt *TypeInt::ONE; // 1
1016 const TypeInt *TypeInt::BOOL; // 0 or 1, FALSE or TRUE.
1017 const TypeInt *TypeInt::CC; // -1,0 or 1, condition codes
1018 const TypeInt *TypeInt::CC_LT; // [-1] == MINUS_1
1019 const TypeInt *TypeInt::CC_GT; // [1] == ONE
1020 const TypeInt *TypeInt::CC_EQ; // [0] == ZERO
1021 const TypeInt *TypeInt::CC_LE; // [-1,0]
1022 const TypeInt *TypeInt::CC_GE; // [0,1] == BOOL (!)
1023 const TypeInt *TypeInt::BYTE; // Bytes, -128 to 127
1024 const TypeInt *TypeInt::CHAR; // Java chars, 0-65535
1025 const TypeInt *TypeInt::SHORT; // Java shorts, -32768-32767
1026 const TypeInt *TypeInt::POS; // Positive 32-bit integers or zero
1027 const TypeInt *TypeInt::POS1; // Positive 32-bit integers
1028 const TypeInt *TypeInt::INT; // 32-bit integers
1029 const TypeInt *TypeInt::SYMINT; // symmetric range [-max_jint..max_jint]
1031 //------------------------------TypeInt----------------------------------------
1032 TypeInt::TypeInt( jint lo, jint hi, int w ) : Type(Int), _lo(lo), _hi(hi), _widen(w) {
1033 }
1035 //------------------------------make-------------------------------------------
1036 const TypeInt *TypeInt::make( jint lo ) {
1037 return (TypeInt*)(new TypeInt(lo,lo,WidenMin))->hashcons();
1038 }
1040 #define SMALLINT ((juint)3) // a value too insignificant to consider widening
1042 const TypeInt *TypeInt::make( jint lo, jint hi, int w ) {
1043 // Certain normalizations keep us sane when comparing types.
1044 // The 'SMALLINT' covers constants and also CC and its relatives.
1045 assert(CC == NULL || (juint)(CC->_hi - CC->_lo) <= SMALLINT, "CC is truly small");
1046 if (lo <= hi) {
1047 if ((juint)(hi - lo) <= SMALLINT) w = Type::WidenMin;
1048 if ((juint)(hi - lo) >= max_juint) w = Type::WidenMax; // plain int
1049 }
1050 return (TypeInt*)(new TypeInt(lo,hi,w))->hashcons();
1051 }
1053 //------------------------------meet-------------------------------------------
1054 // Compute the MEET of two types. It returns a new Type representation object
1055 // with reference count equal to the number of Types pointing at it.
1056 // Caller should wrap a Types around it.
1057 const Type *TypeInt::xmeet( const Type *t ) const {
1058 // Perform a fast test for common case; meeting the same types together.
1059 if( this == t ) return this; // Meeting same type?
1061 // Currently "this->_base" is a TypeInt
1062 switch (t->base()) { // Switch on original type
1063 case AnyPtr: // Mixing with oops happens when javac
1064 case RawPtr: // reuses local variables
1065 case OopPtr:
1066 case InstPtr:
1067 case KlassPtr:
1068 case AryPtr:
1069 case NarrowOop:
1070 case Long:
1071 case FloatTop:
1072 case FloatCon:
1073 case FloatBot:
1074 case DoubleTop:
1075 case DoubleCon:
1076 case DoubleBot:
1077 case Bottom: // Ye Olde Default
1078 return Type::BOTTOM;
1079 default: // All else is a mistake
1080 typerr(t);
1081 case Top: // No change
1082 return this;
1083 case Int: // Int vs Int?
1084 break;
1085 }
1087 // Expand covered set
1088 const TypeInt *r = t->is_int();
1089 // (Avoid TypeInt::make, to avoid the argument normalizations it enforces.)
1090 return (new TypeInt( MIN2(_lo,r->_lo), MAX2(_hi,r->_hi), MAX2(_widen,r->_widen) ))->hashcons();
1091 }
1093 //------------------------------xdual------------------------------------------
1094 // Dual: reverse hi & lo; flip widen
1095 const Type *TypeInt::xdual() const {
1096 return new TypeInt(_hi,_lo,WidenMax-_widen);
1097 }
1099 //------------------------------widen------------------------------------------
1100 // Only happens for optimistic top-down optimizations.
1101 const Type *TypeInt::widen( const Type *old ) const {
1102 // Coming from TOP or such; no widening
1103 if( old->base() != Int ) return this;
1104 const TypeInt *ot = old->is_int();
1106 // If new guy is equal to old guy, no widening
1107 if( _lo == ot->_lo && _hi == ot->_hi )
1108 return old;
1110 // If new guy contains old, then we widened
1111 if( _lo <= ot->_lo && _hi >= ot->_hi ) {
1112 // New contains old
1113 // If new guy is already wider than old, no widening
1114 if( _widen > ot->_widen ) return this;
1115 // If old guy was a constant, do not bother
1116 if (ot->_lo == ot->_hi) return this;
1117 // Now widen new guy.
1118 // Check for widening too far
1119 if (_widen == WidenMax) {
1120 if (min_jint < _lo && _hi < max_jint) {
1121 // If neither endpoint is extremal yet, push out the endpoint
1122 // which is closer to its respective limit.
1123 if (_lo >= 0 || // easy common case
1124 (juint)(_lo - min_jint) >= (juint)(max_jint - _hi)) {
1125 // Try to widen to an unsigned range type of 31 bits:
1126 return make(_lo, max_jint, WidenMax);
1127 } else {
1128 return make(min_jint, _hi, WidenMax);
1129 }
1130 }
1131 return TypeInt::INT;
1132 }
1133 // Returned widened new guy
1134 return make(_lo,_hi,_widen+1);
1135 }
1137 // If old guy contains new, then we probably widened too far & dropped to
1138 // bottom. Return the wider fellow.
1139 if ( ot->_lo <= _lo && ot->_hi >= _hi )
1140 return old;
1142 //fatal("Integer value range is not subset");
1143 //return this;
1144 return TypeInt::INT;
1145 }
1147 //------------------------------narrow---------------------------------------
1148 // Only happens for pessimistic optimizations.
1149 const Type *TypeInt::narrow( const Type *old ) const {
1150 if (_lo >= _hi) return this; // already narrow enough
1151 if (old == NULL) return this;
1152 const TypeInt* ot = old->isa_int();
1153 if (ot == NULL) return this;
1154 jint olo = ot->_lo;
1155 jint ohi = ot->_hi;
1157 // If new guy is equal to old guy, no narrowing
1158 if (_lo == olo && _hi == ohi) return old;
1160 // If old guy was maximum range, allow the narrowing
1161 if (olo == min_jint && ohi == max_jint) return this;
1163 if (_lo < olo || _hi > ohi)
1164 return this; // doesn't narrow; pretty wierd
1166 // The new type narrows the old type, so look for a "death march".
1167 // See comments on PhaseTransform::saturate.
1168 juint nrange = _hi - _lo;
1169 juint orange = ohi - olo;
1170 if (nrange < max_juint - 1 && nrange > (orange >> 1) + (SMALLINT*2)) {
1171 // Use the new type only if the range shrinks a lot.
1172 // We do not want the optimizer computing 2^31 point by point.
1173 return old;
1174 }
1176 return this;
1177 }
1179 //-----------------------------filter------------------------------------------
1180 const Type *TypeInt::filter( const Type *kills ) const {
1181 const TypeInt* ft = join(kills)->isa_int();
1182 if (ft == NULL || ft->_lo > ft->_hi)
1183 return Type::TOP; // Canonical empty value
1184 if (ft->_widen < this->_widen) {
1185 // Do not allow the value of kill->_widen to affect the outcome.
1186 // The widen bits must be allowed to run freely through the graph.
1187 ft = TypeInt::make(ft->_lo, ft->_hi, this->_widen);
1188 }
1189 return ft;
1190 }
1192 //------------------------------eq---------------------------------------------
1193 // Structural equality check for Type representations
1194 bool TypeInt::eq( const Type *t ) const {
1195 const TypeInt *r = t->is_int(); // Handy access
1196 return r->_lo == _lo && r->_hi == _hi && r->_widen == _widen;
1197 }
1199 //------------------------------hash-------------------------------------------
1200 // Type-specific hashing function.
1201 int TypeInt::hash(void) const {
1202 return _lo+_hi+_widen+(int)Type::Int;
1203 }
1205 //------------------------------is_finite--------------------------------------
1206 // Has a finite value
1207 bool TypeInt::is_finite() const {
1208 return true;
1209 }
1211 //------------------------------dump2------------------------------------------
1212 // Dump TypeInt
1213 #ifndef PRODUCT
1214 static const char* intname(char* buf, jint n) {
1215 if (n == min_jint)
1216 return "min";
1217 else if (n < min_jint + 10000)
1218 sprintf(buf, "min+" INT32_FORMAT, n - min_jint);
1219 else if (n == max_jint)
1220 return "max";
1221 else if (n > max_jint - 10000)
1222 sprintf(buf, "max-" INT32_FORMAT, max_jint - n);
1223 else
1224 sprintf(buf, INT32_FORMAT, n);
1225 return buf;
1226 }
1228 void TypeInt::dump2( Dict &d, uint depth, outputStream *st ) const {
1229 char buf[40], buf2[40];
1230 if (_lo == min_jint && _hi == max_jint)
1231 st->print("int");
1232 else if (is_con())
1233 st->print("int:%s", intname(buf, get_con()));
1234 else if (_lo == BOOL->_lo && _hi == BOOL->_hi)
1235 st->print("bool");
1236 else if (_lo == BYTE->_lo && _hi == BYTE->_hi)
1237 st->print("byte");
1238 else if (_lo == CHAR->_lo && _hi == CHAR->_hi)
1239 st->print("char");
1240 else if (_lo == SHORT->_lo && _hi == SHORT->_hi)
1241 st->print("short");
1242 else if (_hi == max_jint)
1243 st->print("int:>=%s", intname(buf, _lo));
1244 else if (_lo == min_jint)
1245 st->print("int:<=%s", intname(buf, _hi));
1246 else
1247 st->print("int:%s..%s", intname(buf, _lo), intname(buf2, _hi));
1249 if (_widen != 0 && this != TypeInt::INT)
1250 st->print(":%.*s", _widen, "wwww");
1251 }
1252 #endif
1254 //------------------------------singleton--------------------------------------
1255 // TRUE if Type is a singleton type, FALSE otherwise. Singletons are simple
1256 // constants.
1257 bool TypeInt::singleton(void) const {
1258 return _lo >= _hi;
1259 }
1261 bool TypeInt::empty(void) const {
1262 return _lo > _hi;
1263 }
1265 //=============================================================================
1266 // Convenience common pre-built types.
1267 const TypeLong *TypeLong::MINUS_1;// -1
1268 const TypeLong *TypeLong::ZERO; // 0
1269 const TypeLong *TypeLong::ONE; // 1
1270 const TypeLong *TypeLong::POS; // >=0
1271 const TypeLong *TypeLong::LONG; // 64-bit integers
1272 const TypeLong *TypeLong::INT; // 32-bit subrange
1273 const TypeLong *TypeLong::UINT; // 32-bit unsigned subrange
1275 //------------------------------TypeLong---------------------------------------
1276 TypeLong::TypeLong( jlong lo, jlong hi, int w ) : Type(Long), _lo(lo), _hi(hi), _widen(w) {
1277 }
1279 //------------------------------make-------------------------------------------
1280 const TypeLong *TypeLong::make( jlong lo ) {
1281 return (TypeLong*)(new TypeLong(lo,lo,WidenMin))->hashcons();
1282 }
1284 const TypeLong *TypeLong::make( jlong lo, jlong hi, int w ) {
1285 // Certain normalizations keep us sane when comparing types.
1286 // The '1' covers constants.
1287 if (lo <= hi) {
1288 if ((julong)(hi - lo) <= SMALLINT) w = Type::WidenMin;
1289 if ((julong)(hi - lo) >= max_julong) w = Type::WidenMax; // plain long
1290 }
1291 return (TypeLong*)(new TypeLong(lo,hi,w))->hashcons();
1292 }
1295 //------------------------------meet-------------------------------------------
1296 // Compute the MEET of two types. It returns a new Type representation object
1297 // with reference count equal to the number of Types pointing at it.
1298 // Caller should wrap a Types around it.
1299 const Type *TypeLong::xmeet( const Type *t ) const {
1300 // Perform a fast test for common case; meeting the same types together.
1301 if( this == t ) return this; // Meeting same type?
1303 // Currently "this->_base" is a TypeLong
1304 switch (t->base()) { // Switch on original type
1305 case AnyPtr: // Mixing with oops happens when javac
1306 case RawPtr: // reuses local variables
1307 case OopPtr:
1308 case InstPtr:
1309 case KlassPtr:
1310 case AryPtr:
1311 case NarrowOop:
1312 case Int:
1313 case FloatTop:
1314 case FloatCon:
1315 case FloatBot:
1316 case DoubleTop:
1317 case DoubleCon:
1318 case DoubleBot:
1319 case Bottom: // Ye Olde Default
1320 return Type::BOTTOM;
1321 default: // All else is a mistake
1322 typerr(t);
1323 case Top: // No change
1324 return this;
1325 case Long: // Long vs Long?
1326 break;
1327 }
1329 // Expand covered set
1330 const TypeLong *r = t->is_long(); // Turn into a TypeLong
1331 // (Avoid TypeLong::make, to avoid the argument normalizations it enforces.)
1332 return (new TypeLong( MIN2(_lo,r->_lo), MAX2(_hi,r->_hi), MAX2(_widen,r->_widen) ))->hashcons();
1333 }
1335 //------------------------------xdual------------------------------------------
1336 // Dual: reverse hi & lo; flip widen
1337 const Type *TypeLong::xdual() const {
1338 return new TypeLong(_hi,_lo,WidenMax-_widen);
1339 }
1341 //------------------------------widen------------------------------------------
1342 // Only happens for optimistic top-down optimizations.
1343 const Type *TypeLong::widen( const Type *old ) const {
1344 // Coming from TOP or such; no widening
1345 if( old->base() != Long ) return this;
1346 const TypeLong *ot = old->is_long();
1348 // If new guy is equal to old guy, no widening
1349 if( _lo == ot->_lo && _hi == ot->_hi )
1350 return old;
1352 // If new guy contains old, then we widened
1353 if( _lo <= ot->_lo && _hi >= ot->_hi ) {
1354 // New contains old
1355 // If new guy is already wider than old, no widening
1356 if( _widen > ot->_widen ) return this;
1357 // If old guy was a constant, do not bother
1358 if (ot->_lo == ot->_hi) return this;
1359 // Now widen new guy.
1360 // Check for widening too far
1361 if (_widen == WidenMax) {
1362 if (min_jlong < _lo && _hi < max_jlong) {
1363 // If neither endpoint is extremal yet, push out the endpoint
1364 // which is closer to its respective limit.
1365 if (_lo >= 0 || // easy common case
1366 (julong)(_lo - min_jlong) >= (julong)(max_jlong - _hi)) {
1367 // Try to widen to an unsigned range type of 32/63 bits:
1368 if (_hi < max_juint)
1369 return make(_lo, max_juint, WidenMax);
1370 else
1371 return make(_lo, max_jlong, WidenMax);
1372 } else {
1373 return make(min_jlong, _hi, WidenMax);
1374 }
1375 }
1376 return TypeLong::LONG;
1377 }
1378 // Returned widened new guy
1379 return make(_lo,_hi,_widen+1);
1380 }
1382 // If old guy contains new, then we probably widened too far & dropped to
1383 // bottom. Return the wider fellow.
1384 if ( ot->_lo <= _lo && ot->_hi >= _hi )
1385 return old;
1387 // fatal("Long value range is not subset");
1388 // return this;
1389 return TypeLong::LONG;
1390 }
1392 //------------------------------narrow----------------------------------------
1393 // Only happens for pessimistic optimizations.
1394 const Type *TypeLong::narrow( const Type *old ) const {
1395 if (_lo >= _hi) return this; // already narrow enough
1396 if (old == NULL) return this;
1397 const TypeLong* ot = old->isa_long();
1398 if (ot == NULL) return this;
1399 jlong olo = ot->_lo;
1400 jlong ohi = ot->_hi;
1402 // If new guy is equal to old guy, no narrowing
1403 if (_lo == olo && _hi == ohi) return old;
1405 // If old guy was maximum range, allow the narrowing
1406 if (olo == min_jlong && ohi == max_jlong) return this;
1408 if (_lo < olo || _hi > ohi)
1409 return this; // doesn't narrow; pretty wierd
1411 // The new type narrows the old type, so look for a "death march".
1412 // See comments on PhaseTransform::saturate.
1413 julong nrange = _hi - _lo;
1414 julong orange = ohi - olo;
1415 if (nrange < max_julong - 1 && nrange > (orange >> 1) + (SMALLINT*2)) {
1416 // Use the new type only if the range shrinks a lot.
1417 // We do not want the optimizer computing 2^31 point by point.
1418 return old;
1419 }
1421 return this;
1422 }
1424 //-----------------------------filter------------------------------------------
1425 const Type *TypeLong::filter( const Type *kills ) const {
1426 const TypeLong* ft = join(kills)->isa_long();
1427 if (ft == NULL || ft->_lo > ft->_hi)
1428 return Type::TOP; // Canonical empty value
1429 if (ft->_widen < this->_widen) {
1430 // Do not allow the value of kill->_widen to affect the outcome.
1431 // The widen bits must be allowed to run freely through the graph.
1432 ft = TypeLong::make(ft->_lo, ft->_hi, this->_widen);
1433 }
1434 return ft;
1435 }
1437 //------------------------------eq---------------------------------------------
1438 // Structural equality check for Type representations
1439 bool TypeLong::eq( const Type *t ) const {
1440 const TypeLong *r = t->is_long(); // Handy access
1441 return r->_lo == _lo && r->_hi == _hi && r->_widen == _widen;
1442 }
1444 //------------------------------hash-------------------------------------------
1445 // Type-specific hashing function.
1446 int TypeLong::hash(void) const {
1447 return (int)(_lo+_hi+_widen+(int)Type::Long);
1448 }
1450 //------------------------------is_finite--------------------------------------
1451 // Has a finite value
1452 bool TypeLong::is_finite() const {
1453 return true;
1454 }
1456 //------------------------------dump2------------------------------------------
1457 // Dump TypeLong
1458 #ifndef PRODUCT
1459 static const char* longnamenear(jlong x, const char* xname, char* buf, jlong n) {
1460 if (n > x) {
1461 if (n >= x + 10000) return NULL;
1462 sprintf(buf, "%s+" INT64_FORMAT, xname, n - x);
1463 } else if (n < x) {
1464 if (n <= x - 10000) return NULL;
1465 sprintf(buf, "%s-" INT64_FORMAT, xname, x - n);
1466 } else {
1467 return xname;
1468 }
1469 return buf;
1470 }
1472 static const char* longname(char* buf, jlong n) {
1473 const char* str;
1474 if (n == min_jlong)
1475 return "min";
1476 else if (n < min_jlong + 10000)
1477 sprintf(buf, "min+" INT64_FORMAT, n - min_jlong);
1478 else if (n == max_jlong)
1479 return "max";
1480 else if (n > max_jlong - 10000)
1481 sprintf(buf, "max-" INT64_FORMAT, max_jlong - n);
1482 else if ((str = longnamenear(max_juint, "maxuint", buf, n)) != NULL)
1483 return str;
1484 else if ((str = longnamenear(max_jint, "maxint", buf, n)) != NULL)
1485 return str;
1486 else if ((str = longnamenear(min_jint, "minint", buf, n)) != NULL)
1487 return str;
1488 else
1489 sprintf(buf, INT64_FORMAT, n);
1490 return buf;
1491 }
1493 void TypeLong::dump2( Dict &d, uint depth, outputStream *st ) const {
1494 char buf[80], buf2[80];
1495 if (_lo == min_jlong && _hi == max_jlong)
1496 st->print("long");
1497 else if (is_con())
1498 st->print("long:%s", longname(buf, get_con()));
1499 else if (_hi == max_jlong)
1500 st->print("long:>=%s", longname(buf, _lo));
1501 else if (_lo == min_jlong)
1502 st->print("long:<=%s", longname(buf, _hi));
1503 else
1504 st->print("long:%s..%s", longname(buf, _lo), longname(buf2, _hi));
1506 if (_widen != 0 && this != TypeLong::LONG)
1507 st->print(":%.*s", _widen, "wwww");
1508 }
1509 #endif
1511 //------------------------------singleton--------------------------------------
1512 // TRUE if Type is a singleton type, FALSE otherwise. Singletons are simple
1513 // constants
1514 bool TypeLong::singleton(void) const {
1515 return _lo >= _hi;
1516 }
1518 bool TypeLong::empty(void) const {
1519 return _lo > _hi;
1520 }
1522 //=============================================================================
1523 // Convenience common pre-built types.
1524 const TypeTuple *TypeTuple::IFBOTH; // Return both arms of IF as reachable
1525 const TypeTuple *TypeTuple::IFFALSE;
1526 const TypeTuple *TypeTuple::IFTRUE;
1527 const TypeTuple *TypeTuple::IFNEITHER;
1528 const TypeTuple *TypeTuple::LOOPBODY;
1529 const TypeTuple *TypeTuple::MEMBAR;
1530 const TypeTuple *TypeTuple::STORECONDITIONAL;
1531 const TypeTuple *TypeTuple::START_I2C;
1532 const TypeTuple *TypeTuple::INT_PAIR;
1533 const TypeTuple *TypeTuple::LONG_PAIR;
1536 //------------------------------make-------------------------------------------
1537 // Make a TypeTuple from the range of a method signature
1538 const TypeTuple *TypeTuple::make_range(ciSignature* sig) {
1539 ciType* return_type = sig->return_type();
1540 uint total_fields = TypeFunc::Parms + return_type->size();
1541 const Type **field_array = fields(total_fields);
1542 switch (return_type->basic_type()) {
1543 case T_LONG:
1544 field_array[TypeFunc::Parms] = TypeLong::LONG;
1545 field_array[TypeFunc::Parms+1] = Type::HALF;
1546 break;
1547 case T_DOUBLE:
1548 field_array[TypeFunc::Parms] = Type::DOUBLE;
1549 field_array[TypeFunc::Parms+1] = Type::HALF;
1550 break;
1551 case T_OBJECT:
1552 case T_ARRAY:
1553 case T_BOOLEAN:
1554 case T_CHAR:
1555 case T_FLOAT:
1556 case T_BYTE:
1557 case T_SHORT:
1558 case T_INT:
1559 field_array[TypeFunc::Parms] = get_const_type(return_type);
1560 break;
1561 case T_VOID:
1562 break;
1563 default:
1564 ShouldNotReachHere();
1565 }
1566 return (TypeTuple*)(new TypeTuple(total_fields,field_array))->hashcons();
1567 }
1569 // Make a TypeTuple from the domain of a method signature
1570 const TypeTuple *TypeTuple::make_domain(ciInstanceKlass* recv, ciSignature* sig) {
1571 uint total_fields = TypeFunc::Parms + sig->size();
1573 uint pos = TypeFunc::Parms;
1574 const Type **field_array;
1575 if (recv != NULL) {
1576 total_fields++;
1577 field_array = fields(total_fields);
1578 // Use get_const_type here because it respects UseUniqueSubclasses:
1579 field_array[pos++] = get_const_type(recv)->join(TypePtr::NOTNULL);
1580 } else {
1581 field_array = fields(total_fields);
1582 }
1584 int i = 0;
1585 while (pos < total_fields) {
1586 ciType* type = sig->type_at(i);
1588 switch (type->basic_type()) {
1589 case T_LONG:
1590 field_array[pos++] = TypeLong::LONG;
1591 field_array[pos++] = Type::HALF;
1592 break;
1593 case T_DOUBLE:
1594 field_array[pos++] = Type::DOUBLE;
1595 field_array[pos++] = Type::HALF;
1596 break;
1597 case T_OBJECT:
1598 case T_ARRAY:
1599 case T_BOOLEAN:
1600 case T_CHAR:
1601 case T_FLOAT:
1602 case T_BYTE:
1603 case T_SHORT:
1604 case T_INT:
1605 field_array[pos++] = get_const_type(type);
1606 break;
1607 default:
1608 ShouldNotReachHere();
1609 }
1610 i++;
1611 }
1612 return (TypeTuple*)(new TypeTuple(total_fields,field_array))->hashcons();
1613 }
1615 const TypeTuple *TypeTuple::make( uint cnt, const Type **fields ) {
1616 return (TypeTuple*)(new TypeTuple(cnt,fields))->hashcons();
1617 }
1619 //------------------------------fields-----------------------------------------
1620 // Subroutine call type with space allocated for argument types
1621 const Type **TypeTuple::fields( uint arg_cnt ) {
1622 const Type **flds = (const Type **)(Compile::current()->type_arena()->Amalloc_4((TypeFunc::Parms+arg_cnt)*sizeof(Type*) ));
1623 flds[TypeFunc::Control ] = Type::CONTROL;
1624 flds[TypeFunc::I_O ] = Type::ABIO;
1625 flds[TypeFunc::Memory ] = Type::MEMORY;
1626 flds[TypeFunc::FramePtr ] = TypeRawPtr::BOTTOM;
1627 flds[TypeFunc::ReturnAdr] = Type::RETURN_ADDRESS;
1629 return flds;
1630 }
1632 //------------------------------meet-------------------------------------------
1633 // Compute the MEET of two types. It returns a new Type object.
1634 const Type *TypeTuple::xmeet( const Type *t ) const {
1635 // Perform a fast test for common case; meeting the same types together.
1636 if( this == t ) return this; // Meeting same type-rep?
1638 // Current "this->_base" is Tuple
1639 switch (t->base()) { // switch on original type
1641 case Bottom: // Ye Olde Default
1642 return t;
1644 default: // All else is a mistake
1645 typerr(t);
1647 case Tuple: { // Meeting 2 signatures?
1648 const TypeTuple *x = t->is_tuple();
1649 assert( _cnt == x->_cnt, "" );
1650 const Type **fields = (const Type **)(Compile::current()->type_arena()->Amalloc_4( _cnt*sizeof(Type*) ));
1651 for( uint i=0; i<_cnt; i++ )
1652 fields[i] = field_at(i)->xmeet( x->field_at(i) );
1653 return TypeTuple::make(_cnt,fields);
1654 }
1655 case Top:
1656 break;
1657 }
1658 return this; // Return the double constant
1659 }
1661 //------------------------------xdual------------------------------------------
1662 // Dual: compute field-by-field dual
1663 const Type *TypeTuple::xdual() const {
1664 const Type **fields = (const Type **)(Compile::current()->type_arena()->Amalloc_4( _cnt*sizeof(Type*) ));
1665 for( uint i=0; i<_cnt; i++ )
1666 fields[i] = _fields[i]->dual();
1667 return new TypeTuple(_cnt,fields);
1668 }
1670 //------------------------------eq---------------------------------------------
1671 // Structural equality check for Type representations
1672 bool TypeTuple::eq( const Type *t ) const {
1673 const TypeTuple *s = (const TypeTuple *)t;
1674 if (_cnt != s->_cnt) return false; // Unequal field counts
1675 for (uint i = 0; i < _cnt; i++)
1676 if (field_at(i) != s->field_at(i)) // POINTER COMPARE! NO RECURSION!
1677 return false; // Missed
1678 return true;
1679 }
1681 //------------------------------hash-------------------------------------------
1682 // Type-specific hashing function.
1683 int TypeTuple::hash(void) const {
1684 intptr_t sum = _cnt;
1685 for( uint i=0; i<_cnt; i++ )
1686 sum += (intptr_t)_fields[i]; // Hash on pointers directly
1687 return sum;
1688 }
1690 //------------------------------dump2------------------------------------------
1691 // Dump signature Type
1692 #ifndef PRODUCT
1693 void TypeTuple::dump2( Dict &d, uint depth, outputStream *st ) const {
1694 st->print("{");
1695 if( !depth || d[this] ) { // Check for recursive print
1696 st->print("...}");
1697 return;
1698 }
1699 d.Insert((void*)this, (void*)this); // Stop recursion
1700 if( _cnt ) {
1701 uint i;
1702 for( i=0; i<_cnt-1; i++ ) {
1703 st->print("%d:", i);
1704 _fields[i]->dump2(d, depth-1, st);
1705 st->print(", ");
1706 }
1707 st->print("%d:", i);
1708 _fields[i]->dump2(d, depth-1, st);
1709 }
1710 st->print("}");
1711 }
1712 #endif
1714 //------------------------------singleton--------------------------------------
1715 // TRUE if Type is a singleton type, FALSE otherwise. Singletons are simple
1716 // constants (Ldi nodes). Singletons are integer, float or double constants
1717 // or a single symbol.
1718 bool TypeTuple::singleton(void) const {
1719 return false; // Never a singleton
1720 }
1722 bool TypeTuple::empty(void) const {
1723 for( uint i=0; i<_cnt; i++ ) {
1724 if (_fields[i]->empty()) return true;
1725 }
1726 return false;
1727 }
1729 //=============================================================================
1730 // Convenience common pre-built types.
1732 inline const TypeInt* normalize_array_size(const TypeInt* size) {
1733 // Certain normalizations keep us sane when comparing types.
1734 // We do not want arrayOop variables to differ only by the wideness
1735 // of their index types. Pick minimum wideness, since that is the
1736 // forced wideness of small ranges anyway.
1737 if (size->_widen != Type::WidenMin)
1738 return TypeInt::make(size->_lo, size->_hi, Type::WidenMin);
1739 else
1740 return size;
1741 }
1743 //------------------------------make-------------------------------------------
1744 const TypeAry *TypeAry::make( const Type *elem, const TypeInt *size) {
1745 if (UseCompressedOops && elem->isa_oopptr()) {
1746 elem = elem->make_narrowoop();
1747 }
1748 size = normalize_array_size(size);
1749 return (TypeAry*)(new TypeAry(elem,size))->hashcons();
1750 }
1752 //------------------------------meet-------------------------------------------
1753 // Compute the MEET of two types. It returns a new Type object.
1754 const Type *TypeAry::xmeet( const Type *t ) const {
1755 // Perform a fast test for common case; meeting the same types together.
1756 if( this == t ) return this; // Meeting same type-rep?
1758 // Current "this->_base" is Ary
1759 switch (t->base()) { // switch on original type
1761 case Bottom: // Ye Olde Default
1762 return t;
1764 default: // All else is a mistake
1765 typerr(t);
1767 case Array: { // Meeting 2 arrays?
1768 const TypeAry *a = t->is_ary();
1769 return TypeAry::make(_elem->meet(a->_elem),
1770 _size->xmeet(a->_size)->is_int());
1771 }
1772 case Top:
1773 break;
1774 }
1775 return this; // Return the double constant
1776 }
1778 //------------------------------xdual------------------------------------------
1779 // Dual: compute field-by-field dual
1780 const Type *TypeAry::xdual() const {
1781 const TypeInt* size_dual = _size->dual()->is_int();
1782 size_dual = normalize_array_size(size_dual);
1783 return new TypeAry( _elem->dual(), size_dual);
1784 }
1786 //------------------------------eq---------------------------------------------
1787 // Structural equality check for Type representations
1788 bool TypeAry::eq( const Type *t ) const {
1789 const TypeAry *a = (const TypeAry*)t;
1790 return _elem == a->_elem &&
1791 _size == a->_size;
1792 }
1794 //------------------------------hash-------------------------------------------
1795 // Type-specific hashing function.
1796 int TypeAry::hash(void) const {
1797 return (intptr_t)_elem + (intptr_t)_size;
1798 }
1800 //------------------------------dump2------------------------------------------
1801 #ifndef PRODUCT
1802 void TypeAry::dump2( Dict &d, uint depth, outputStream *st ) const {
1803 _elem->dump2(d, depth, st);
1804 st->print("[");
1805 _size->dump2(d, depth, st);
1806 st->print("]");
1807 }
1808 #endif
1810 //------------------------------singleton--------------------------------------
1811 // TRUE if Type is a singleton type, FALSE otherwise. Singletons are simple
1812 // constants (Ldi nodes). Singletons are integer, float or double constants
1813 // or a single symbol.
1814 bool TypeAry::singleton(void) const {
1815 return false; // Never a singleton
1816 }
1818 bool TypeAry::empty(void) const {
1819 return _elem->empty() || _size->empty();
1820 }
1822 //--------------------------ary_must_be_exact----------------------------------
1823 bool TypeAry::ary_must_be_exact() const {
1824 if (!UseExactTypes) return false;
1825 // This logic looks at the element type of an array, and returns true
1826 // if the element type is either a primitive or a final instance class.
1827 // In such cases, an array built on this ary must have no subclasses.
1828 if (_elem == BOTTOM) return false; // general array not exact
1829 if (_elem == TOP ) return false; // inverted general array not exact
1830 const TypeOopPtr* toop = NULL;
1831 if (UseCompressedOops && _elem->isa_narrowoop()) {
1832 toop = _elem->make_ptr()->isa_oopptr();
1833 } else {
1834 toop = _elem->isa_oopptr();
1835 }
1836 if (!toop) return true; // a primitive type, like int
1837 ciKlass* tklass = toop->klass();
1838 if (tklass == NULL) return false; // unloaded class
1839 if (!tklass->is_loaded()) return false; // unloaded class
1840 const TypeInstPtr* tinst;
1841 if (_elem->isa_narrowoop())
1842 tinst = _elem->make_ptr()->isa_instptr();
1843 else
1844 tinst = _elem->isa_instptr();
1845 if (tinst)
1846 return tklass->as_instance_klass()->is_final();
1847 const TypeAryPtr* tap;
1848 if (_elem->isa_narrowoop())
1849 tap = _elem->make_ptr()->isa_aryptr();
1850 else
1851 tap = _elem->isa_aryptr();
1852 if (tap)
1853 return tap->ary()->ary_must_be_exact();
1854 return false;
1855 }
1857 //=============================================================================
1858 // Convenience common pre-built types.
1859 const TypePtr *TypePtr::NULL_PTR;
1860 const TypePtr *TypePtr::NOTNULL;
1861 const TypePtr *TypePtr::BOTTOM;
1863 //------------------------------meet-------------------------------------------
1864 // Meet over the PTR enum
1865 const TypePtr::PTR TypePtr::ptr_meet[TypePtr::lastPTR][TypePtr::lastPTR] = {
1866 // TopPTR, AnyNull, Constant, Null, NotNull, BotPTR,
1867 { /* Top */ TopPTR, AnyNull, Constant, Null, NotNull, BotPTR,},
1868 { /* AnyNull */ AnyNull, AnyNull, Constant, BotPTR, NotNull, BotPTR,},
1869 { /* Constant*/ Constant, Constant, Constant, BotPTR, NotNull, BotPTR,},
1870 { /* Null */ Null, BotPTR, BotPTR, Null, BotPTR, BotPTR,},
1871 { /* NotNull */ NotNull, NotNull, NotNull, BotPTR, NotNull, BotPTR,},
1872 { /* BotPTR */ BotPTR, BotPTR, BotPTR, BotPTR, BotPTR, BotPTR,}
1873 };
1875 //------------------------------make-------------------------------------------
1876 const TypePtr *TypePtr::make( TYPES t, enum PTR ptr, int offset ) {
1877 return (TypePtr*)(new TypePtr(t,ptr,offset))->hashcons();
1878 }
1880 //------------------------------cast_to_ptr_type-------------------------------
1881 const Type *TypePtr::cast_to_ptr_type(PTR ptr) const {
1882 assert(_base == AnyPtr, "subclass must override cast_to_ptr_type");
1883 if( ptr == _ptr ) return this;
1884 return make(_base, ptr, _offset);
1885 }
1887 //------------------------------get_con----------------------------------------
1888 intptr_t TypePtr::get_con() const {
1889 assert( _ptr == Null, "" );
1890 return _offset;
1891 }
1893 //------------------------------meet-------------------------------------------
1894 // Compute the MEET of two types. It returns a new Type object.
1895 const Type *TypePtr::xmeet( const Type *t ) const {
1896 // Perform a fast test for common case; meeting the same types together.
1897 if( this == t ) return this; // Meeting same type-rep?
1899 // Current "this->_base" is AnyPtr
1900 switch (t->base()) { // switch on original type
1901 case Int: // Mixing ints & oops happens when javac
1902 case Long: // reuses local variables
1903 case FloatTop:
1904 case FloatCon:
1905 case FloatBot:
1906 case DoubleTop:
1907 case DoubleCon:
1908 case DoubleBot:
1909 case NarrowOop:
1910 case Bottom: // Ye Olde Default
1911 return Type::BOTTOM;
1912 case Top:
1913 return this;
1915 case AnyPtr: { // Meeting to AnyPtrs
1916 const TypePtr *tp = t->is_ptr();
1917 return make( AnyPtr, meet_ptr(tp->ptr()), meet_offset(tp->offset()) );
1918 }
1919 case RawPtr: // For these, flip the call around to cut down
1920 case OopPtr:
1921 case InstPtr: // on the cases I have to handle.
1922 case KlassPtr:
1923 case AryPtr:
1924 return t->xmeet(this); // Call in reverse direction
1925 default: // All else is a mistake
1926 typerr(t);
1928 }
1929 return this;
1930 }
1932 //------------------------------meet_offset------------------------------------
1933 int TypePtr::meet_offset( int offset ) const {
1934 // Either is 'TOP' offset? Return the other offset!
1935 if( _offset == OffsetTop ) return offset;
1936 if( offset == OffsetTop ) return _offset;
1937 // If either is different, return 'BOTTOM' offset
1938 if( _offset != offset ) return OffsetBot;
1939 return _offset;
1940 }
1942 //------------------------------dual_offset------------------------------------
1943 int TypePtr::dual_offset( ) const {
1944 if( _offset == OffsetTop ) return OffsetBot;// Map 'TOP' into 'BOTTOM'
1945 if( _offset == OffsetBot ) return OffsetTop;// Map 'BOTTOM' into 'TOP'
1946 return _offset; // Map everything else into self
1947 }
1949 //------------------------------xdual------------------------------------------
1950 // Dual: compute field-by-field dual
1951 const TypePtr::PTR TypePtr::ptr_dual[TypePtr::lastPTR] = {
1952 BotPTR, NotNull, Constant, Null, AnyNull, TopPTR
1953 };
1954 const Type *TypePtr::xdual() const {
1955 return new TypePtr( AnyPtr, dual_ptr(), dual_offset() );
1956 }
1958 //------------------------------add_offset-------------------------------------
1959 const TypePtr *TypePtr::add_offset( int offset ) const {
1960 if( offset == 0 ) return this; // No change
1961 if( _offset == OffsetBot ) return this;
1962 if( offset == OffsetBot ) offset = OffsetBot;
1963 else if( _offset == OffsetTop || offset == OffsetTop ) offset = OffsetTop;
1964 else offset += _offset;
1965 return make( AnyPtr, _ptr, offset );
1966 }
1968 //------------------------------eq---------------------------------------------
1969 // Structural equality check for Type representations
1970 bool TypePtr::eq( const Type *t ) const {
1971 const TypePtr *a = (const TypePtr*)t;
1972 return _ptr == a->ptr() && _offset == a->offset();
1973 }
1975 //------------------------------hash-------------------------------------------
1976 // Type-specific hashing function.
1977 int TypePtr::hash(void) const {
1978 return _ptr + _offset;
1979 }
1981 //------------------------------dump2------------------------------------------
1982 const char *const TypePtr::ptr_msg[TypePtr::lastPTR] = {
1983 "TopPTR","AnyNull","Constant","NULL","NotNull","BotPTR"
1984 };
1986 #ifndef PRODUCT
1987 void TypePtr::dump2( Dict &d, uint depth, outputStream *st ) const {
1988 if( _ptr == Null ) st->print("NULL");
1989 else st->print("%s *", ptr_msg[_ptr]);
1990 if( _offset == OffsetTop ) st->print("+top");
1991 else if( _offset == OffsetBot ) st->print("+bot");
1992 else if( _offset ) st->print("+%d", _offset);
1993 }
1994 #endif
1996 //------------------------------singleton--------------------------------------
1997 // TRUE if Type is a singleton type, FALSE otherwise. Singletons are simple
1998 // constants
1999 bool TypePtr::singleton(void) const {
2000 // TopPTR, Null, AnyNull, Constant are all singletons
2001 return (_offset != OffsetBot) && !below_centerline(_ptr);
2002 }
2004 bool TypePtr::empty(void) const {
2005 return (_offset == OffsetTop) || above_centerline(_ptr);
2006 }
2008 //=============================================================================
2009 // Convenience common pre-built types.
2010 const TypeRawPtr *TypeRawPtr::BOTTOM;
2011 const TypeRawPtr *TypeRawPtr::NOTNULL;
2013 //------------------------------make-------------------------------------------
2014 const TypeRawPtr *TypeRawPtr::make( enum PTR ptr ) {
2015 assert( ptr != Constant, "what is the constant?" );
2016 assert( ptr != Null, "Use TypePtr for NULL" );
2017 return (TypeRawPtr*)(new TypeRawPtr(ptr,0))->hashcons();
2018 }
2020 const TypeRawPtr *TypeRawPtr::make( address bits ) {
2021 assert( bits, "Use TypePtr for NULL" );
2022 return (TypeRawPtr*)(new TypeRawPtr(Constant,bits))->hashcons();
2023 }
2025 //------------------------------cast_to_ptr_type-------------------------------
2026 const Type *TypeRawPtr::cast_to_ptr_type(PTR ptr) const {
2027 assert( ptr != Constant, "what is the constant?" );
2028 assert( ptr != Null, "Use TypePtr for NULL" );
2029 assert( _bits==0, "Why cast a constant address?");
2030 if( ptr == _ptr ) return this;
2031 return make(ptr);
2032 }
2034 //------------------------------get_con----------------------------------------
2035 intptr_t TypeRawPtr::get_con() const {
2036 assert( _ptr == Null || _ptr == Constant, "" );
2037 return (intptr_t)_bits;
2038 }
2040 //------------------------------meet-------------------------------------------
2041 // Compute the MEET of two types. It returns a new Type object.
2042 const Type *TypeRawPtr::xmeet( const Type *t ) const {
2043 // Perform a fast test for common case; meeting the same types together.
2044 if( this == t ) return this; // Meeting same type-rep?
2046 // Current "this->_base" is RawPtr
2047 switch( t->base() ) { // switch on original type
2048 case Bottom: // Ye Olde Default
2049 return t;
2050 case Top:
2051 return this;
2052 case AnyPtr: // Meeting to AnyPtrs
2053 break;
2054 case RawPtr: { // might be top, bot, any/not or constant
2055 enum PTR tptr = t->is_ptr()->ptr();
2056 enum PTR ptr = meet_ptr( tptr );
2057 if( ptr == Constant ) { // Cannot be equal constants, so...
2058 if( tptr == Constant && _ptr != Constant) return t;
2059 if( _ptr == Constant && tptr != Constant) return this;
2060 ptr = NotNull; // Fall down in lattice
2061 }
2062 return make( ptr );
2063 }
2065 case OopPtr:
2066 case InstPtr:
2067 case KlassPtr:
2068 case AryPtr:
2069 return TypePtr::BOTTOM; // Oop meet raw is not well defined
2070 default: // All else is a mistake
2071 typerr(t);
2072 }
2074 // Found an AnyPtr type vs self-RawPtr type
2075 const TypePtr *tp = t->is_ptr();
2076 switch (tp->ptr()) {
2077 case TypePtr::TopPTR: return this;
2078 case TypePtr::BotPTR: return t;
2079 case TypePtr::Null:
2080 if( _ptr == TypePtr::TopPTR ) return t;
2081 return TypeRawPtr::BOTTOM;
2082 case TypePtr::NotNull: return TypePtr::make( AnyPtr, meet_ptr(TypePtr::NotNull), tp->meet_offset(0) );
2083 case TypePtr::AnyNull:
2084 if( _ptr == TypePtr::Constant) return this;
2085 return make( meet_ptr(TypePtr::AnyNull) );
2086 default: ShouldNotReachHere();
2087 }
2088 return this;
2089 }
2091 //------------------------------xdual------------------------------------------
2092 // Dual: compute field-by-field dual
2093 const Type *TypeRawPtr::xdual() const {
2094 return new TypeRawPtr( dual_ptr(), _bits );
2095 }
2097 //------------------------------add_offset-------------------------------------
2098 const TypePtr *TypeRawPtr::add_offset( int offset ) const {
2099 if( offset == OffsetTop ) return BOTTOM; // Undefined offset-> undefined pointer
2100 if( offset == OffsetBot ) return BOTTOM; // Unknown offset-> unknown pointer
2101 if( offset == 0 ) return this; // No change
2102 switch (_ptr) {
2103 case TypePtr::TopPTR:
2104 case TypePtr::BotPTR:
2105 case TypePtr::NotNull:
2106 return this;
2107 case TypePtr::Null:
2108 case TypePtr::Constant:
2109 return make( _bits+offset );
2110 default: ShouldNotReachHere();
2111 }
2112 return NULL; // Lint noise
2113 }
2115 //------------------------------eq---------------------------------------------
2116 // Structural equality check for Type representations
2117 bool TypeRawPtr::eq( const Type *t ) const {
2118 const TypeRawPtr *a = (const TypeRawPtr*)t;
2119 return _bits == a->_bits && TypePtr::eq(t);
2120 }
2122 //------------------------------hash-------------------------------------------
2123 // Type-specific hashing function.
2124 int TypeRawPtr::hash(void) const {
2125 return (intptr_t)_bits + TypePtr::hash();
2126 }
2128 //------------------------------dump2------------------------------------------
2129 #ifndef PRODUCT
2130 void TypeRawPtr::dump2( Dict &d, uint depth, outputStream *st ) const {
2131 if( _ptr == Constant )
2132 st->print(INTPTR_FORMAT, _bits);
2133 else
2134 st->print("rawptr:%s", ptr_msg[_ptr]);
2135 }
2136 #endif
2138 //=============================================================================
2139 // Convenience common pre-built type.
2140 const TypeOopPtr *TypeOopPtr::BOTTOM;
2142 //------------------------------TypeOopPtr-------------------------------------
2143 TypeOopPtr::TypeOopPtr( TYPES t, PTR ptr, ciKlass* k, bool xk, ciObject* o, int offset, int instance_id )
2144 : TypePtr(t, ptr, offset),
2145 _const_oop(o), _klass(k),
2146 _klass_is_exact(xk),
2147 _is_ptr_to_narrowoop(false),
2148 _instance_id(instance_id) {
2149 #ifdef _LP64
2150 if (UseCompressedOops && _offset != 0) {
2151 if (klass() == NULL) {
2152 assert(this->isa_aryptr(), "only arrays without klass");
2153 _is_ptr_to_narrowoop = true;
2154 } else if (_offset == oopDesc::klass_offset_in_bytes()) {
2155 _is_ptr_to_narrowoop = true;
2156 } else if (this->isa_aryptr()) {
2157 _is_ptr_to_narrowoop = (klass()->is_obj_array_klass() &&
2158 _offset != arrayOopDesc::length_offset_in_bytes());
2159 } else if (klass() == ciEnv::current()->Class_klass() &&
2160 (_offset == java_lang_Class::klass_offset_in_bytes() ||
2161 _offset == java_lang_Class::array_klass_offset_in_bytes())) {
2162 // Special hidden fields from the Class.
2163 assert(this->isa_instptr(), "must be an instance ptr.");
2164 _is_ptr_to_narrowoop = true;
2165 } else if (klass()->is_instance_klass()) {
2166 ciInstanceKlass* ik = klass()->as_instance_klass();
2167 ciField* field = NULL;
2168 if (this->isa_klassptr()) {
2169 // Perm objects don't use compressed references, except for
2170 // static fields which are currently compressed.
2171 field = ik->get_field_by_offset(_offset, true);
2172 if (field != NULL) {
2173 BasicType basic_elem_type = field->layout_type();
2174 _is_ptr_to_narrowoop = (basic_elem_type == T_OBJECT ||
2175 basic_elem_type == T_ARRAY);
2176 }
2177 } else if (_offset == OffsetBot || _offset == OffsetTop) {
2178 // unsafe access
2179 _is_ptr_to_narrowoop = true;
2180 } else { // exclude unsafe ops
2181 assert(this->isa_instptr(), "must be an instance ptr.");
2182 // Field which contains a compressed oop references.
2183 field = ik->get_field_by_offset(_offset, false);
2184 if (field != NULL) {
2185 BasicType basic_elem_type = field->layout_type();
2186 _is_ptr_to_narrowoop = (basic_elem_type == T_OBJECT ||
2187 basic_elem_type == T_ARRAY);
2188 } else if (klass()->equals(ciEnv::current()->Object_klass())) {
2189 // Compile::find_alias_type() cast exactness on all types to verify
2190 // that it does not affect alias type.
2191 _is_ptr_to_narrowoop = true;
2192 } else {
2193 // Type for the copy start in LibraryCallKit::inline_native_clone().
2194 assert(!klass_is_exact(), "only non-exact klass");
2195 _is_ptr_to_narrowoop = true;
2196 }
2197 }
2198 }
2199 }
2200 #endif
2201 }
2203 //------------------------------make-------------------------------------------
2204 const TypeOopPtr *TypeOopPtr::make(PTR ptr,
2205 int offset) {
2206 assert(ptr != Constant, "no constant generic pointers");
2207 ciKlass* k = ciKlassKlass::make();
2208 bool xk = false;
2209 ciObject* o = NULL;
2210 return (TypeOopPtr*)(new TypeOopPtr(OopPtr, ptr, k, xk, o, offset, InstanceBot))->hashcons();
2211 }
2214 //------------------------------cast_to_ptr_type-------------------------------
2215 const Type *TypeOopPtr::cast_to_ptr_type(PTR ptr) const {
2216 assert(_base == OopPtr, "subclass must override cast_to_ptr_type");
2217 if( ptr == _ptr ) return this;
2218 return make(ptr, _offset);
2219 }
2221 //-----------------------------cast_to_instance_id----------------------------
2222 const TypeOopPtr *TypeOopPtr::cast_to_instance_id(int instance_id) const {
2223 // There are no instances of a general oop.
2224 // Return self unchanged.
2225 return this;
2226 }
2228 //-----------------------------cast_to_exactness-------------------------------
2229 const Type *TypeOopPtr::cast_to_exactness(bool klass_is_exact) const {
2230 // There is no such thing as an exact general oop.
2231 // Return self unchanged.
2232 return this;
2233 }
2236 //------------------------------as_klass_type----------------------------------
2237 // Return the klass type corresponding to this instance or array type.
2238 // It is the type that is loaded from an object of this type.
2239 const TypeKlassPtr* TypeOopPtr::as_klass_type() const {
2240 ciKlass* k = klass();
2241 bool xk = klass_is_exact();
2242 if (k == NULL || !k->is_java_klass())
2243 return TypeKlassPtr::OBJECT;
2244 else
2245 return TypeKlassPtr::make(xk? Constant: NotNull, k, 0);
2246 }
2249 //------------------------------meet-------------------------------------------
2250 // Compute the MEET of two types. It returns a new Type object.
2251 const Type *TypeOopPtr::xmeet( const Type *t ) const {
2252 // Perform a fast test for common case; meeting the same types together.
2253 if( this == t ) return this; // Meeting same type-rep?
2255 // Current "this->_base" is OopPtr
2256 switch (t->base()) { // switch on original type
2258 case Int: // Mixing ints & oops happens when javac
2259 case Long: // reuses local variables
2260 case FloatTop:
2261 case FloatCon:
2262 case FloatBot:
2263 case DoubleTop:
2264 case DoubleCon:
2265 case DoubleBot:
2266 case Bottom: // Ye Olde Default
2267 return Type::BOTTOM;
2268 case Top:
2269 return this;
2271 default: // All else is a mistake
2272 typerr(t);
2274 case RawPtr:
2275 return TypePtr::BOTTOM; // Oop meet raw is not well defined
2277 case AnyPtr: {
2278 // Found an AnyPtr type vs self-OopPtr type
2279 const TypePtr *tp = t->is_ptr();
2280 int offset = meet_offset(tp->offset());
2281 PTR ptr = meet_ptr(tp->ptr());
2282 switch (tp->ptr()) {
2283 case Null:
2284 if (ptr == Null) return TypePtr::make(AnyPtr, ptr, offset);
2285 // else fall through:
2286 case TopPTR:
2287 case AnyNull:
2288 return make(ptr, offset);
2289 case BotPTR:
2290 case NotNull:
2291 return TypePtr::make(AnyPtr, ptr, offset);
2292 default: typerr(t);
2293 }
2294 }
2296 case OopPtr: { // Meeting to other OopPtrs
2297 const TypeOopPtr *tp = t->is_oopptr();
2298 return make( meet_ptr(tp->ptr()), meet_offset(tp->offset()) );
2299 }
2301 case InstPtr: // For these, flip the call around to cut down
2302 case KlassPtr: // on the cases I have to handle.
2303 case AryPtr:
2304 return t->xmeet(this); // Call in reverse direction
2306 } // End of switch
2307 return this; // Return the double constant
2308 }
2311 //------------------------------xdual------------------------------------------
2312 // Dual of a pure heap pointer. No relevant klass or oop information.
2313 const Type *TypeOopPtr::xdual() const {
2314 assert(klass() == ciKlassKlass::make(), "no klasses here");
2315 assert(const_oop() == NULL, "no constants here");
2316 return new TypeOopPtr(_base, dual_ptr(), klass(), klass_is_exact(), const_oop(), dual_offset(), dual_instance_id() );
2317 }
2319 //--------------------------make_from_klass_common-----------------------------
2320 // Computes the element-type given a klass.
2321 const TypeOopPtr* TypeOopPtr::make_from_klass_common(ciKlass *klass, bool klass_change, bool try_for_exact) {
2322 assert(klass->is_java_klass(), "must be java language klass");
2323 if (klass->is_instance_klass()) {
2324 Compile* C = Compile::current();
2325 Dependencies* deps = C->dependencies();
2326 assert((deps != NULL) == (C->method() != NULL && C->method()->code_size() > 0), "sanity");
2327 // Element is an instance
2328 bool klass_is_exact = false;
2329 if (klass->is_loaded()) {
2330 // Try to set klass_is_exact.
2331 ciInstanceKlass* ik = klass->as_instance_klass();
2332 klass_is_exact = ik->is_final();
2333 if (!klass_is_exact && klass_change
2334 && deps != NULL && UseUniqueSubclasses) {
2335 ciInstanceKlass* sub = ik->unique_concrete_subklass();
2336 if (sub != NULL) {
2337 deps->assert_abstract_with_unique_concrete_subtype(ik, sub);
2338 klass = ik = sub;
2339 klass_is_exact = sub->is_final();
2340 }
2341 }
2342 if (!klass_is_exact && try_for_exact
2343 && deps != NULL && UseExactTypes) {
2344 if (!ik->is_interface() && !ik->has_subklass()) {
2345 // Add a dependence; if concrete subclass added we need to recompile
2346 deps->assert_leaf_type(ik);
2347 klass_is_exact = true;
2348 }
2349 }
2350 }
2351 return TypeInstPtr::make(TypePtr::BotPTR, klass, klass_is_exact, NULL, 0);
2352 } else if (klass->is_obj_array_klass()) {
2353 // Element is an object array. Recursively call ourself.
2354 const TypeOopPtr *etype = TypeOopPtr::make_from_klass_common(klass->as_obj_array_klass()->element_klass(), false, try_for_exact);
2355 bool xk = etype->klass_is_exact();
2356 const TypeAry* arr0 = TypeAry::make(etype, TypeInt::POS);
2357 // We used to pass NotNull in here, asserting that the sub-arrays
2358 // are all not-null. This is not true in generally, as code can
2359 // slam NULLs down in the subarrays.
2360 const TypeAryPtr* arr = TypeAryPtr::make(TypePtr::BotPTR, arr0, klass, xk, 0);
2361 return arr;
2362 } else if (klass->is_type_array_klass()) {
2363 // Element is an typeArray
2364 const Type* etype = get_const_basic_type(klass->as_type_array_klass()->element_type());
2365 const TypeAry* arr0 = TypeAry::make(etype, TypeInt::POS);
2366 // We used to pass NotNull in here, asserting that the array pointer
2367 // is not-null. That was not true in general.
2368 const TypeAryPtr* arr = TypeAryPtr::make(TypePtr::BotPTR, arr0, klass, true, 0);
2369 return arr;
2370 } else {
2371 ShouldNotReachHere();
2372 return NULL;
2373 }
2374 }
2376 //------------------------------make_from_constant-----------------------------
2377 // Make a java pointer from an oop constant
2378 const TypeOopPtr* TypeOopPtr::make_from_constant(ciObject* o) {
2379 if (o->is_method_data() || o->is_method()) {
2380 // Treat much like a typeArray of bytes, like below, but fake the type...
2381 assert(o->has_encoding(), "must be a perm space object");
2382 const Type* etype = (Type*)get_const_basic_type(T_BYTE);
2383 const TypeAry* arr0 = TypeAry::make(etype, TypeInt::POS);
2384 ciKlass *klass = ciTypeArrayKlass::make((BasicType) T_BYTE);
2385 assert(o->has_encoding(), "method data oops should be tenured");
2386 const TypeAryPtr* arr = TypeAryPtr::make(TypePtr::Constant, o, arr0, klass, true, 0);
2387 return arr;
2388 } else {
2389 assert(o->is_java_object(), "must be java language object");
2390 assert(!o->is_null_object(), "null object not yet handled here.");
2391 ciKlass *klass = o->klass();
2392 if (klass->is_instance_klass()) {
2393 // Element is an instance
2394 if (!o->has_encoding()) { // not a perm-space constant
2395 // %%% remove this restriction by rewriting non-perm ConPNodes in a later phase
2396 return TypeInstPtr::make(TypePtr::NotNull, klass, true, NULL, 0);
2397 }
2398 return TypeInstPtr::make(o);
2399 } else if (klass->is_obj_array_klass()) {
2400 // Element is an object array. Recursively call ourself.
2401 const Type *etype =
2402 TypeOopPtr::make_from_klass_raw(klass->as_obj_array_klass()->element_klass());
2403 const TypeAry* arr0 = TypeAry::make(etype, TypeInt::make(o->as_array()->length()));
2404 // We used to pass NotNull in here, asserting that the sub-arrays
2405 // are all not-null. This is not true in generally, as code can
2406 // slam NULLs down in the subarrays.
2407 if (!o->has_encoding()) { // not a perm-space constant
2408 // %%% remove this restriction by rewriting non-perm ConPNodes in a later phase
2409 return TypeAryPtr::make(TypePtr::NotNull, arr0, klass, true, 0);
2410 }
2411 const TypeAryPtr* arr = TypeAryPtr::make(TypePtr::Constant, o, arr0, klass, true, 0);
2412 return arr;
2413 } else if (klass->is_type_array_klass()) {
2414 // Element is an typeArray
2415 const Type* etype =
2416 (Type*)get_const_basic_type(klass->as_type_array_klass()->element_type());
2417 const TypeAry* arr0 = TypeAry::make(etype, TypeInt::make(o->as_array()->length()));
2418 // We used to pass NotNull in here, asserting that the array pointer
2419 // is not-null. That was not true in general.
2420 if (!o->has_encoding()) { // not a perm-space constant
2421 // %%% remove this restriction by rewriting non-perm ConPNodes in a later phase
2422 return TypeAryPtr::make(TypePtr::NotNull, arr0, klass, true, 0);
2423 }
2424 const TypeAryPtr* arr = TypeAryPtr::make(TypePtr::Constant, o, arr0, klass, true, 0);
2425 return arr;
2426 }
2427 }
2429 ShouldNotReachHere();
2430 return NULL;
2431 }
2433 //------------------------------get_con----------------------------------------
2434 intptr_t TypeOopPtr::get_con() const {
2435 assert( _ptr == Null || _ptr == Constant, "" );
2436 assert( _offset >= 0, "" );
2438 if (_offset != 0) {
2439 // After being ported to the compiler interface, the compiler no longer
2440 // directly manipulates the addresses of oops. Rather, it only has a pointer
2441 // to a handle at compile time. This handle is embedded in the generated
2442 // code and dereferenced at the time the nmethod is made. Until that time,
2443 // it is not reasonable to do arithmetic with the addresses of oops (we don't
2444 // have access to the addresses!). This does not seem to currently happen,
2445 // but this assertion here is to help prevent its occurrance.
2446 tty->print_cr("Found oop constant with non-zero offset");
2447 ShouldNotReachHere();
2448 }
2450 return (intptr_t)const_oop()->encoding();
2451 }
2454 //-----------------------------filter------------------------------------------
2455 // Do not allow interface-vs.-noninterface joins to collapse to top.
2456 const Type *TypeOopPtr::filter( const Type *kills ) const {
2458 const Type* ft = join(kills);
2459 const TypeInstPtr* ftip = ft->isa_instptr();
2460 const TypeInstPtr* ktip = kills->isa_instptr();
2462 if (ft->empty()) {
2463 // Check for evil case of 'this' being a class and 'kills' expecting an
2464 // interface. This can happen because the bytecodes do not contain
2465 // enough type info to distinguish a Java-level interface variable
2466 // from a Java-level object variable. If we meet 2 classes which
2467 // both implement interface I, but their meet is at 'j/l/O' which
2468 // doesn't implement I, we have no way to tell if the result should
2469 // be 'I' or 'j/l/O'. Thus we'll pick 'j/l/O'. If this then flows
2470 // into a Phi which "knows" it's an Interface type we'll have to
2471 // uplift the type.
2472 if (!empty() && ktip != NULL && ktip->is_loaded() && ktip->klass()->is_interface())
2473 return kills; // Uplift to interface
2475 return Type::TOP; // Canonical empty value
2476 }
2478 // If we have an interface-typed Phi or cast and we narrow to a class type,
2479 // the join should report back the class. However, if we have a J/L/Object
2480 // class-typed Phi and an interface flows in, it's possible that the meet &
2481 // join report an interface back out. This isn't possible but happens
2482 // because the type system doesn't interact well with interfaces.
2483 if (ftip != NULL && ktip != NULL &&
2484 ftip->is_loaded() && ftip->klass()->is_interface() &&
2485 ktip->is_loaded() && !ktip->klass()->is_interface()) {
2486 // Happens in a CTW of rt.jar, 320-341, no extra flags
2487 return ktip->cast_to_ptr_type(ftip->ptr());
2488 }
2490 return ft;
2491 }
2493 //------------------------------eq---------------------------------------------
2494 // Structural equality check for Type representations
2495 bool TypeOopPtr::eq( const Type *t ) const {
2496 const TypeOopPtr *a = (const TypeOopPtr*)t;
2497 if (_klass_is_exact != a->_klass_is_exact ||
2498 _instance_id != a->_instance_id) return false;
2499 ciObject* one = const_oop();
2500 ciObject* two = a->const_oop();
2501 if (one == NULL || two == NULL) {
2502 return (one == two) && TypePtr::eq(t);
2503 } else {
2504 return one->equals(two) && TypePtr::eq(t);
2505 }
2506 }
2508 //------------------------------hash-------------------------------------------
2509 // Type-specific hashing function.
2510 int TypeOopPtr::hash(void) const {
2511 return
2512 (const_oop() ? const_oop()->hash() : 0) +
2513 _klass_is_exact +
2514 _instance_id +
2515 TypePtr::hash();
2516 }
2518 //------------------------------dump2------------------------------------------
2519 #ifndef PRODUCT
2520 void TypeOopPtr::dump2( Dict &d, uint depth, outputStream *st ) const {
2521 st->print("oopptr:%s", ptr_msg[_ptr]);
2522 if( _klass_is_exact ) st->print(":exact");
2523 if( const_oop() ) st->print(INTPTR_FORMAT, const_oop());
2524 switch( _offset ) {
2525 case OffsetTop: st->print("+top"); break;
2526 case OffsetBot: st->print("+any"); break;
2527 case 0: break;
2528 default: st->print("+%d",_offset); break;
2529 }
2530 if (_instance_id == InstanceTop)
2531 st->print(",iid=top");
2532 else if (_instance_id != InstanceBot)
2533 st->print(",iid=%d",_instance_id);
2534 }
2535 #endif
2537 //------------------------------singleton--------------------------------------
2538 // TRUE if Type is a singleton type, FALSE otherwise. Singletons are simple
2539 // constants
2540 bool TypeOopPtr::singleton(void) const {
2541 // detune optimizer to not generate constant oop + constant offset as a constant!
2542 // TopPTR, Null, AnyNull, Constant are all singletons
2543 return (_offset == 0) && !below_centerline(_ptr);
2544 }
2546 //------------------------------xadd_offset------------------------------------
2547 int TypeOopPtr::xadd_offset( int offset ) const {
2548 // Adding to 'TOP' offset? Return 'TOP'!
2549 if( _offset == OffsetTop || offset == OffsetTop ) return OffsetTop;
2550 // Adding to 'BOTTOM' offset? Return 'BOTTOM'!
2551 if( _offset == OffsetBot || offset == OffsetBot ) return OffsetBot;
2553 // assert( _offset >= 0 && _offset+offset >= 0, "" );
2554 // It is possible to construct a negative offset during PhaseCCP
2556 return _offset+offset; // Sum valid offsets
2557 }
2559 //------------------------------add_offset-------------------------------------
2560 const TypePtr *TypeOopPtr::add_offset( int offset ) const {
2561 return make( _ptr, xadd_offset(offset) );
2562 }
2564 //------------------------------meet_instance_id--------------------------------
2565 int TypeOopPtr::meet_instance_id( int instance_id ) const {
2566 // Either is 'TOP' instance? Return the other instance!
2567 if( _instance_id == InstanceTop ) return instance_id;
2568 if( instance_id == InstanceTop ) return _instance_id;
2569 // If either is different, return 'BOTTOM' instance
2570 if( _instance_id != instance_id ) return InstanceBot;
2571 return _instance_id;
2572 }
2574 //------------------------------dual_instance_id--------------------------------
2575 int TypeOopPtr::dual_instance_id( ) const {
2576 if( _instance_id == InstanceTop ) return InstanceBot; // Map TOP into BOTTOM
2577 if( _instance_id == InstanceBot ) return InstanceTop; // Map BOTTOM into TOP
2578 return _instance_id; // Map everything else into self
2579 }
2582 //=============================================================================
2583 // Convenience common pre-built types.
2584 const TypeInstPtr *TypeInstPtr::NOTNULL;
2585 const TypeInstPtr *TypeInstPtr::BOTTOM;
2586 const TypeInstPtr *TypeInstPtr::MIRROR;
2587 const TypeInstPtr *TypeInstPtr::MARK;
2588 const TypeInstPtr *TypeInstPtr::KLASS;
2590 //------------------------------TypeInstPtr-------------------------------------
2591 TypeInstPtr::TypeInstPtr(PTR ptr, ciKlass* k, bool xk, ciObject* o, int off, int instance_id)
2592 : TypeOopPtr(InstPtr, ptr, k, xk, o, off, instance_id), _name(k->name()) {
2593 assert(k != NULL &&
2594 (k->is_loaded() || o == NULL),
2595 "cannot have constants with non-loaded klass");
2596 };
2598 //------------------------------make-------------------------------------------
2599 const TypeInstPtr *TypeInstPtr::make(PTR ptr,
2600 ciKlass* k,
2601 bool xk,
2602 ciObject* o,
2603 int offset,
2604 int instance_id) {
2605 assert( !k->is_loaded() || k->is_instance_klass() ||
2606 k->is_method_klass(), "Must be for instance or method");
2607 // Either const_oop() is NULL or else ptr is Constant
2608 assert( (!o && ptr != Constant) || (o && ptr == Constant),
2609 "constant pointers must have a value supplied" );
2610 // Ptr is never Null
2611 assert( ptr != Null, "NULL pointers are not typed" );
2613 assert(instance_id <= 0 || xk || !UseExactTypes, "instances are always exactly typed");
2614 if (!UseExactTypes) xk = false;
2615 if (ptr == Constant) {
2616 // Note: This case includes meta-object constants, such as methods.
2617 xk = true;
2618 } else if (k->is_loaded()) {
2619 ciInstanceKlass* ik = k->as_instance_klass();
2620 if (!xk && ik->is_final()) xk = true; // no inexact final klass
2621 if (xk && ik->is_interface()) xk = false; // no exact interface
2622 }
2624 // Now hash this baby
2625 TypeInstPtr *result =
2626 (TypeInstPtr*)(new TypeInstPtr(ptr, k, xk, o ,offset, instance_id))->hashcons();
2628 return result;
2629 }
2632 //------------------------------cast_to_ptr_type-------------------------------
2633 const Type *TypeInstPtr::cast_to_ptr_type(PTR ptr) const {
2634 if( ptr == _ptr ) return this;
2635 // Reconstruct _sig info here since not a problem with later lazy
2636 // construction, _sig will show up on demand.
2637 return make(ptr, klass(), klass_is_exact(), const_oop(), _offset, _instance_id);
2638 }
2641 //-----------------------------cast_to_exactness-------------------------------
2642 const Type *TypeInstPtr::cast_to_exactness(bool klass_is_exact) const {
2643 if( klass_is_exact == _klass_is_exact ) return this;
2644 if (!UseExactTypes) return this;
2645 if (!_klass->is_loaded()) return this;
2646 ciInstanceKlass* ik = _klass->as_instance_klass();
2647 if( (ik->is_final() || _const_oop) ) return this; // cannot clear xk
2648 if( ik->is_interface() ) return this; // cannot set xk
2649 return make(ptr(), klass(), klass_is_exact, const_oop(), _offset, _instance_id);
2650 }
2652 //-----------------------------cast_to_instance_id----------------------------
2653 const TypeOopPtr *TypeInstPtr::cast_to_instance_id(int instance_id) const {
2654 if( instance_id == _instance_id ) return this;
2655 return make(_ptr, klass(), _klass_is_exact, const_oop(), _offset, instance_id);
2656 }
2658 //------------------------------xmeet_unloaded---------------------------------
2659 // Compute the MEET of two InstPtrs when at least one is unloaded.
2660 // Assume classes are different since called after check for same name/class-loader
2661 const TypeInstPtr *TypeInstPtr::xmeet_unloaded(const TypeInstPtr *tinst) const {
2662 int off = meet_offset(tinst->offset());
2663 PTR ptr = meet_ptr(tinst->ptr());
2665 const TypeInstPtr *loaded = is_loaded() ? this : tinst;
2666 const TypeInstPtr *unloaded = is_loaded() ? tinst : this;
2667 if( loaded->klass()->equals(ciEnv::current()->Object_klass()) ) {
2668 //
2669 // Meet unloaded class with java/lang/Object
2670 //
2671 // Meet
2672 // | Unloaded Class
2673 // Object | TOP | AnyNull | Constant | NotNull | BOTTOM |
2674 // ===================================================================
2675 // TOP | ..........................Unloaded......................|
2676 // AnyNull | U-AN |................Unloaded......................|
2677 // Constant | ... O-NN .................................. | O-BOT |
2678 // NotNull | ... O-NN .................................. | O-BOT |
2679 // BOTTOM | ........................Object-BOTTOM ..................|
2680 //
2681 assert(loaded->ptr() != TypePtr::Null, "insanity check");
2682 //
2683 if( loaded->ptr() == TypePtr::TopPTR ) { return unloaded; }
2684 else if (loaded->ptr() == TypePtr::AnyNull) { return TypeInstPtr::make( ptr, unloaded->klass() ); }
2685 else if (loaded->ptr() == TypePtr::BotPTR ) { return TypeInstPtr::BOTTOM; }
2686 else if (loaded->ptr() == TypePtr::Constant || loaded->ptr() == TypePtr::NotNull) {
2687 if (unloaded->ptr() == TypePtr::BotPTR ) { return TypeInstPtr::BOTTOM; }
2688 else { return TypeInstPtr::NOTNULL; }
2689 }
2690 else if( unloaded->ptr() == TypePtr::TopPTR ) { return unloaded; }
2692 return unloaded->cast_to_ptr_type(TypePtr::AnyNull)->is_instptr();
2693 }
2695 // Both are unloaded, not the same class, not Object
2696 // Or meet unloaded with a different loaded class, not java/lang/Object
2697 if( ptr != TypePtr::BotPTR ) {
2698 return TypeInstPtr::NOTNULL;
2699 }
2700 return TypeInstPtr::BOTTOM;
2701 }
2704 //------------------------------meet-------------------------------------------
2705 // Compute the MEET of two types. It returns a new Type object.
2706 const Type *TypeInstPtr::xmeet( const Type *t ) const {
2707 // Perform a fast test for common case; meeting the same types together.
2708 if( this == t ) return this; // Meeting same type-rep?
2710 // Current "this->_base" is Pointer
2711 switch (t->base()) { // switch on original type
2713 case Int: // Mixing ints & oops happens when javac
2714 case Long: // reuses local variables
2715 case FloatTop:
2716 case FloatCon:
2717 case FloatBot:
2718 case DoubleTop:
2719 case DoubleCon:
2720 case DoubleBot:
2721 case NarrowOop:
2722 case Bottom: // Ye Olde Default
2723 return Type::BOTTOM;
2724 case Top:
2725 return this;
2727 default: // All else is a mistake
2728 typerr(t);
2730 case RawPtr: return TypePtr::BOTTOM;
2732 case AryPtr: { // All arrays inherit from Object class
2733 const TypeAryPtr *tp = t->is_aryptr();
2734 int offset = meet_offset(tp->offset());
2735 PTR ptr = meet_ptr(tp->ptr());
2736 int instance_id = meet_instance_id(tp->instance_id());
2737 switch (ptr) {
2738 case TopPTR:
2739 case AnyNull: // Fall 'down' to dual of object klass
2740 if (klass()->equals(ciEnv::current()->Object_klass())) {
2741 return TypeAryPtr::make(ptr, tp->ary(), tp->klass(), tp->klass_is_exact(), offset, instance_id);
2742 } else {
2743 // cannot subclass, so the meet has to fall badly below the centerline
2744 ptr = NotNull;
2745 instance_id = InstanceBot;
2746 return TypeInstPtr::make( ptr, ciEnv::current()->Object_klass(), false, NULL, offset, instance_id);
2747 }
2748 case Constant:
2749 case NotNull:
2750 case BotPTR: // Fall down to object klass
2751 // LCA is object_klass, but if we subclass from the top we can do better
2752 if( above_centerline(_ptr) ) { // if( _ptr == TopPTR || _ptr == AnyNull )
2753 // If 'this' (InstPtr) is above the centerline and it is Object class
2754 // then we can subclass in the Java class heirarchy.
2755 if (klass()->equals(ciEnv::current()->Object_klass())) {
2756 // that is, tp's array type is a subtype of my klass
2757 return TypeAryPtr::make(ptr, tp->ary(), tp->klass(), tp->klass_is_exact(), offset, instance_id);
2758 }
2759 }
2760 // The other case cannot happen, since I cannot be a subtype of an array.
2761 // The meet falls down to Object class below centerline.
2762 if( ptr == Constant )
2763 ptr = NotNull;
2764 instance_id = InstanceBot;
2765 return make( ptr, ciEnv::current()->Object_klass(), false, NULL, offset, instance_id );
2766 default: typerr(t);
2767 }
2768 }
2770 case OopPtr: { // Meeting to OopPtrs
2771 // Found a OopPtr type vs self-InstPtr type
2772 const TypePtr *tp = t->is_oopptr();
2773 int offset = meet_offset(tp->offset());
2774 PTR ptr = meet_ptr(tp->ptr());
2775 switch (tp->ptr()) {
2776 case TopPTR:
2777 case AnyNull: {
2778 int instance_id = meet_instance_id(InstanceTop);
2779 return make(ptr, klass(), klass_is_exact(),
2780 (ptr == Constant ? const_oop() : NULL), offset, instance_id);
2781 }
2782 case NotNull:
2783 case BotPTR:
2784 return TypeOopPtr::make(ptr, offset);
2785 default: typerr(t);
2786 }
2787 }
2789 case AnyPtr: { // Meeting to AnyPtrs
2790 // Found an AnyPtr type vs self-InstPtr type
2791 const TypePtr *tp = t->is_ptr();
2792 int offset = meet_offset(tp->offset());
2793 PTR ptr = meet_ptr(tp->ptr());
2794 switch (tp->ptr()) {
2795 case Null:
2796 if( ptr == Null ) return TypePtr::make( AnyPtr, ptr, offset );
2797 // else fall through to AnyNull
2798 case TopPTR:
2799 case AnyNull: {
2800 int instance_id = meet_instance_id(InstanceTop);
2801 return make( ptr, klass(), klass_is_exact(),
2802 (ptr == Constant ? const_oop() : NULL), offset, instance_id);
2803 }
2804 case NotNull:
2805 case BotPTR:
2806 return TypePtr::make( AnyPtr, ptr, offset );
2807 default: typerr(t);
2808 }
2809 }
2811 /*
2812 A-top }
2813 / | \ } Tops
2814 B-top A-any C-top }
2815 | / | \ | } Any-nulls
2816 B-any | C-any }
2817 | | |
2818 B-con A-con C-con } constants; not comparable across classes
2819 | | |
2820 B-not | C-not }
2821 | \ | / | } not-nulls
2822 B-bot A-not C-bot }
2823 \ | / } Bottoms
2824 A-bot }
2825 */
2827 case InstPtr: { // Meeting 2 Oops?
2828 // Found an InstPtr sub-type vs self-InstPtr type
2829 const TypeInstPtr *tinst = t->is_instptr();
2830 int off = meet_offset( tinst->offset() );
2831 PTR ptr = meet_ptr( tinst->ptr() );
2832 int instance_id = meet_instance_id(tinst->instance_id());
2834 // Check for easy case; klasses are equal (and perhaps not loaded!)
2835 // If we have constants, then we created oops so classes are loaded
2836 // and we can handle the constants further down. This case handles
2837 // both-not-loaded or both-loaded classes
2838 if (ptr != Constant && klass()->equals(tinst->klass()) && klass_is_exact() == tinst->klass_is_exact()) {
2839 return make( ptr, klass(), klass_is_exact(), NULL, off, instance_id );
2840 }
2842 // Classes require inspection in the Java klass hierarchy. Must be loaded.
2843 ciKlass* tinst_klass = tinst->klass();
2844 ciKlass* this_klass = this->klass();
2845 bool tinst_xk = tinst->klass_is_exact();
2846 bool this_xk = this->klass_is_exact();
2847 if (!tinst_klass->is_loaded() || !this_klass->is_loaded() ) {
2848 // One of these classes has not been loaded
2849 const TypeInstPtr *unloaded_meet = xmeet_unloaded(tinst);
2850 #ifndef PRODUCT
2851 if( PrintOpto && Verbose ) {
2852 tty->print("meet of unloaded classes resulted in: "); unloaded_meet->dump(); tty->cr();
2853 tty->print(" this == "); this->dump(); tty->cr();
2854 tty->print(" tinst == "); tinst->dump(); tty->cr();
2855 }
2856 #endif
2857 return unloaded_meet;
2858 }
2860 // Handle mixing oops and interfaces first.
2861 if( this_klass->is_interface() && !tinst_klass->is_interface() ) {
2862 ciKlass *tmp = tinst_klass; // Swap interface around
2863 tinst_klass = this_klass;
2864 this_klass = tmp;
2865 bool tmp2 = tinst_xk;
2866 tinst_xk = this_xk;
2867 this_xk = tmp2;
2868 }
2869 if (tinst_klass->is_interface() &&
2870 !(this_klass->is_interface() ||
2871 // Treat java/lang/Object as an honorary interface,
2872 // because we need a bottom for the interface hierarchy.
2873 this_klass == ciEnv::current()->Object_klass())) {
2874 // Oop meets interface!
2876 // See if the oop subtypes (implements) interface.
2877 ciKlass *k;
2878 bool xk;
2879 if( this_klass->is_subtype_of( tinst_klass ) ) {
2880 // Oop indeed subtypes. Now keep oop or interface depending
2881 // on whether we are both above the centerline or either is
2882 // below the centerline. If we are on the centerline
2883 // (e.g., Constant vs. AnyNull interface), use the constant.
2884 k = below_centerline(ptr) ? tinst_klass : this_klass;
2885 // If we are keeping this_klass, keep its exactness too.
2886 xk = below_centerline(ptr) ? tinst_xk : this_xk;
2887 } else { // Does not implement, fall to Object
2888 // Oop does not implement interface, so mixing falls to Object
2889 // just like the verifier does (if both are above the
2890 // centerline fall to interface)
2891 k = above_centerline(ptr) ? tinst_klass : ciEnv::current()->Object_klass();
2892 xk = above_centerline(ptr) ? tinst_xk : false;
2893 // Watch out for Constant vs. AnyNull interface.
2894 if (ptr == Constant) ptr = NotNull; // forget it was a constant
2895 instance_id = InstanceBot;
2896 }
2897 ciObject* o = NULL; // the Constant value, if any
2898 if (ptr == Constant) {
2899 // Find out which constant.
2900 o = (this_klass == klass()) ? const_oop() : tinst->const_oop();
2901 }
2902 return make( ptr, k, xk, o, off, instance_id );
2903 }
2905 // Either oop vs oop or interface vs interface or interface vs Object
2907 // !!! Here's how the symmetry requirement breaks down into invariants:
2908 // If we split one up & one down AND they subtype, take the down man.
2909 // If we split one up & one down AND they do NOT subtype, "fall hard".
2910 // If both are up and they subtype, take the subtype class.
2911 // If both are up and they do NOT subtype, "fall hard".
2912 // If both are down and they subtype, take the supertype class.
2913 // If both are down and they do NOT subtype, "fall hard".
2914 // Constants treated as down.
2916 // Now, reorder the above list; observe that both-down+subtype is also
2917 // "fall hard"; "fall hard" becomes the default case:
2918 // If we split one up & one down AND they subtype, take the down man.
2919 // If both are up and they subtype, take the subtype class.
2921 // If both are down and they subtype, "fall hard".
2922 // If both are down and they do NOT subtype, "fall hard".
2923 // If both are up and they do NOT subtype, "fall hard".
2924 // If we split one up & one down AND they do NOT subtype, "fall hard".
2926 // If a proper subtype is exact, and we return it, we return it exactly.
2927 // If a proper supertype is exact, there can be no subtyping relationship!
2928 // If both types are equal to the subtype, exactness is and-ed below the
2929 // centerline and or-ed above it. (N.B. Constants are always exact.)
2931 // Check for subtyping:
2932 ciKlass *subtype = NULL;
2933 bool subtype_exact = false;
2934 if( tinst_klass->equals(this_klass) ) {
2935 subtype = this_klass;
2936 subtype_exact = below_centerline(ptr) ? (this_xk & tinst_xk) : (this_xk | tinst_xk);
2937 } else if( !tinst_xk && this_klass->is_subtype_of( tinst_klass ) ) {
2938 subtype = this_klass; // Pick subtyping class
2939 subtype_exact = this_xk;
2940 } else if( !this_xk && tinst_klass->is_subtype_of( this_klass ) ) {
2941 subtype = tinst_klass; // Pick subtyping class
2942 subtype_exact = tinst_xk;
2943 }
2945 if( subtype ) {
2946 if( above_centerline(ptr) ) { // both are up?
2947 this_klass = tinst_klass = subtype;
2948 this_xk = tinst_xk = subtype_exact;
2949 } else if( above_centerline(this ->_ptr) && !above_centerline(tinst->_ptr) ) {
2950 this_klass = tinst_klass; // tinst is down; keep down man
2951 this_xk = tinst_xk;
2952 } else if( above_centerline(tinst->_ptr) && !above_centerline(this ->_ptr) ) {
2953 tinst_klass = this_klass; // this is down; keep down man
2954 tinst_xk = this_xk;
2955 } else {
2956 this_xk = subtype_exact; // either they are equal, or we'll do an LCA
2957 }
2958 }
2960 // Check for classes now being equal
2961 if (tinst_klass->equals(this_klass)) {
2962 // If the klasses are equal, the constants may still differ. Fall to
2963 // NotNull if they do (neither constant is NULL; that is a special case
2964 // handled elsewhere).
2965 ciObject* o = NULL; // Assume not constant when done
2966 ciObject* this_oop = const_oop();
2967 ciObject* tinst_oop = tinst->const_oop();
2968 if( ptr == Constant ) {
2969 if (this_oop != NULL && tinst_oop != NULL &&
2970 this_oop->equals(tinst_oop) )
2971 o = this_oop;
2972 else if (above_centerline(this ->_ptr))
2973 o = tinst_oop;
2974 else if (above_centerline(tinst ->_ptr))
2975 o = this_oop;
2976 else
2977 ptr = NotNull;
2978 }
2979 return make( ptr, this_klass, this_xk, o, off, instance_id );
2980 } // Else classes are not equal
2982 // Since klasses are different, we require a LCA in the Java
2983 // class hierarchy - which means we have to fall to at least NotNull.
2984 if( ptr == TopPTR || ptr == AnyNull || ptr == Constant )
2985 ptr = NotNull;
2986 instance_id = InstanceBot;
2988 // Now we find the LCA of Java classes
2989 ciKlass* k = this_klass->least_common_ancestor(tinst_klass);
2990 return make( ptr, k, false, NULL, off, instance_id );
2991 } // End of case InstPtr
2993 case KlassPtr:
2994 return TypeInstPtr::BOTTOM;
2996 } // End of switch
2997 return this; // Return the double constant
2998 }
3001 //------------------------java_mirror_type--------------------------------------
3002 ciType* TypeInstPtr::java_mirror_type() const {
3003 // must be a singleton type
3004 if( const_oop() == NULL ) return NULL;
3006 // must be of type java.lang.Class
3007 if( klass() != ciEnv::current()->Class_klass() ) return NULL;
3009 return const_oop()->as_instance()->java_mirror_type();
3010 }
3013 //------------------------------xdual------------------------------------------
3014 // Dual: do NOT dual on klasses. This means I do NOT understand the Java
3015 // inheritence mechanism.
3016 const Type *TypeInstPtr::xdual() const {
3017 return new TypeInstPtr( dual_ptr(), klass(), klass_is_exact(), const_oop(), dual_offset(), dual_instance_id() );
3018 }
3020 //------------------------------eq---------------------------------------------
3021 // Structural equality check for Type representations
3022 bool TypeInstPtr::eq( const Type *t ) const {
3023 const TypeInstPtr *p = t->is_instptr();
3024 return
3025 klass()->equals(p->klass()) &&
3026 TypeOopPtr::eq(p); // Check sub-type stuff
3027 }
3029 //------------------------------hash-------------------------------------------
3030 // Type-specific hashing function.
3031 int TypeInstPtr::hash(void) const {
3032 int hash = klass()->hash() + TypeOopPtr::hash();
3033 return hash;
3034 }
3036 //------------------------------dump2------------------------------------------
3037 // Dump oop Type
3038 #ifndef PRODUCT
3039 void TypeInstPtr::dump2( Dict &d, uint depth, outputStream *st ) const {
3040 // Print the name of the klass.
3041 klass()->print_name_on(st);
3043 switch( _ptr ) {
3044 case Constant:
3045 // TO DO: Make CI print the hex address of the underlying oop.
3046 if (WizardMode || Verbose) {
3047 const_oop()->print_oop(st);
3048 }
3049 case BotPTR:
3050 if (!WizardMode && !Verbose) {
3051 if( _klass_is_exact ) st->print(":exact");
3052 break;
3053 }
3054 case TopPTR:
3055 case AnyNull:
3056 case NotNull:
3057 st->print(":%s", ptr_msg[_ptr]);
3058 if( _klass_is_exact ) st->print(":exact");
3059 break;
3060 }
3062 if( _offset ) { // Dump offset, if any
3063 if( _offset == OffsetBot ) st->print("+any");
3064 else if( _offset == OffsetTop ) st->print("+unknown");
3065 else st->print("+%d", _offset);
3066 }
3068 st->print(" *");
3069 if (_instance_id == InstanceTop)
3070 st->print(",iid=top");
3071 else if (_instance_id != InstanceBot)
3072 st->print(",iid=%d",_instance_id);
3073 }
3074 #endif
3076 //------------------------------add_offset-------------------------------------
3077 const TypePtr *TypeInstPtr::add_offset( int offset ) const {
3078 return make( _ptr, klass(), klass_is_exact(), const_oop(), xadd_offset(offset), _instance_id );
3079 }
3081 //=============================================================================
3082 // Convenience common pre-built types.
3083 const TypeAryPtr *TypeAryPtr::RANGE;
3084 const TypeAryPtr *TypeAryPtr::OOPS;
3085 const TypeAryPtr *TypeAryPtr::NARROWOOPS;
3086 const TypeAryPtr *TypeAryPtr::BYTES;
3087 const TypeAryPtr *TypeAryPtr::SHORTS;
3088 const TypeAryPtr *TypeAryPtr::CHARS;
3089 const TypeAryPtr *TypeAryPtr::INTS;
3090 const TypeAryPtr *TypeAryPtr::LONGS;
3091 const TypeAryPtr *TypeAryPtr::FLOATS;
3092 const TypeAryPtr *TypeAryPtr::DOUBLES;
3094 //------------------------------make-------------------------------------------
3095 const TypeAryPtr *TypeAryPtr::make( PTR ptr, const TypeAry *ary, ciKlass* k, bool xk, int offset, int instance_id ) {
3096 assert(!(k == NULL && ary->_elem->isa_int()),
3097 "integral arrays must be pre-equipped with a class");
3098 if (!xk) xk = ary->ary_must_be_exact();
3099 assert(instance_id <= 0 || xk || !UseExactTypes, "instances are always exactly typed");
3100 if (!UseExactTypes) xk = (ptr == Constant);
3101 return (TypeAryPtr*)(new TypeAryPtr(ptr, NULL, ary, k, xk, offset, instance_id))->hashcons();
3102 }
3104 //------------------------------make-------------------------------------------
3105 const TypeAryPtr *TypeAryPtr::make( PTR ptr, ciObject* o, const TypeAry *ary, ciKlass* k, bool xk, int offset, int instance_id ) {
3106 assert(!(k == NULL && ary->_elem->isa_int()),
3107 "integral arrays must be pre-equipped with a class");
3108 assert( (ptr==Constant && o) || (ptr!=Constant && !o), "" );
3109 if (!xk) xk = (o != NULL) || ary->ary_must_be_exact();
3110 assert(instance_id <= 0 || xk || !UseExactTypes, "instances are always exactly typed");
3111 if (!UseExactTypes) xk = (ptr == Constant);
3112 return (TypeAryPtr*)(new TypeAryPtr(ptr, o, ary, k, xk, offset, instance_id))->hashcons();
3113 }
3115 //------------------------------cast_to_ptr_type-------------------------------
3116 const Type *TypeAryPtr::cast_to_ptr_type(PTR ptr) const {
3117 if( ptr == _ptr ) return this;
3118 return make(ptr, const_oop(), _ary, klass(), klass_is_exact(), _offset, _instance_id);
3119 }
3122 //-----------------------------cast_to_exactness-------------------------------
3123 const Type *TypeAryPtr::cast_to_exactness(bool klass_is_exact) const {
3124 if( klass_is_exact == _klass_is_exact ) return this;
3125 if (!UseExactTypes) return this;
3126 if (_ary->ary_must_be_exact()) return this; // cannot clear xk
3127 return make(ptr(), const_oop(), _ary, klass(), klass_is_exact, _offset, _instance_id);
3128 }
3130 //-----------------------------cast_to_instance_id----------------------------
3131 const TypeOopPtr *TypeAryPtr::cast_to_instance_id(int instance_id) const {
3132 if( instance_id == _instance_id ) return this;
3133 return make(_ptr, const_oop(), _ary, klass(), _klass_is_exact, _offset, instance_id);
3134 }
3136 //-----------------------------narrow_size_type-------------------------------
3137 // Local cache for arrayOopDesc::max_array_length(etype),
3138 // which is kind of slow (and cached elsewhere by other users).
3139 static jint max_array_length_cache[T_CONFLICT+1];
3140 static jint max_array_length(BasicType etype) {
3141 jint& cache = max_array_length_cache[etype];
3142 jint res = cache;
3143 if (res == 0) {
3144 switch (etype) {
3145 case T_NARROWOOP:
3146 etype = T_OBJECT;
3147 break;
3148 case T_CONFLICT:
3149 case T_ILLEGAL:
3150 case T_VOID:
3151 etype = T_BYTE; // will produce conservatively high value
3152 }
3153 cache = res = arrayOopDesc::max_array_length(etype);
3154 }
3155 return res;
3156 }
3158 // Narrow the given size type to the index range for the given array base type.
3159 // Return NULL if the resulting int type becomes empty.
3160 const TypeInt* TypeAryPtr::narrow_size_type(const TypeInt* size, BasicType elem) {
3161 jint hi = size->_hi;
3162 jint lo = size->_lo;
3163 jint min_lo = 0;
3164 jint max_hi = max_array_length(elem);
3165 //if (index_not_size) --max_hi; // type of a valid array index, FTR
3166 bool chg = false;
3167 if (lo < min_lo) { lo = min_lo; chg = true; }
3168 if (hi > max_hi) { hi = max_hi; chg = true; }
3169 if (lo > hi)
3170 return NULL;
3171 if (!chg)
3172 return size;
3173 return TypeInt::make(lo, hi, Type::WidenMin);
3174 }
3176 //-------------------------------cast_to_size----------------------------------
3177 const TypeAryPtr* TypeAryPtr::cast_to_size(const TypeInt* new_size) const {
3178 assert(new_size != NULL, "");
3179 new_size = narrow_size_type(new_size, elem()->basic_type());
3180 if (new_size == NULL) // Negative length arrays will produce weird
3181 new_size = TypeInt::ZERO; // intermediate dead fast-path goo
3182 if (new_size == size()) return this;
3183 const TypeAry* new_ary = TypeAry::make(elem(), new_size);
3184 return make(ptr(), const_oop(), new_ary, klass(), klass_is_exact(), _offset, _instance_id);
3185 }
3188 //------------------------------eq---------------------------------------------
3189 // Structural equality check for Type representations
3190 bool TypeAryPtr::eq( const Type *t ) const {
3191 const TypeAryPtr *p = t->is_aryptr();
3192 return
3193 _ary == p->_ary && // Check array
3194 TypeOopPtr::eq(p); // Check sub-parts
3195 }
3197 //------------------------------hash-------------------------------------------
3198 // Type-specific hashing function.
3199 int TypeAryPtr::hash(void) const {
3200 return (intptr_t)_ary + TypeOopPtr::hash();
3201 }
3203 //------------------------------meet-------------------------------------------
3204 // Compute the MEET of two types. It returns a new Type object.
3205 const Type *TypeAryPtr::xmeet( const Type *t ) const {
3206 // Perform a fast test for common case; meeting the same types together.
3207 if( this == t ) return this; // Meeting same type-rep?
3208 // Current "this->_base" is Pointer
3209 switch (t->base()) { // switch on original type
3211 // Mixing ints & oops happens when javac reuses local variables
3212 case Int:
3213 case Long:
3214 case FloatTop:
3215 case FloatCon:
3216 case FloatBot:
3217 case DoubleTop:
3218 case DoubleCon:
3219 case DoubleBot:
3220 case NarrowOop:
3221 case Bottom: // Ye Olde Default
3222 return Type::BOTTOM;
3223 case Top:
3224 return this;
3226 default: // All else is a mistake
3227 typerr(t);
3229 case OopPtr: { // Meeting to OopPtrs
3230 // Found a OopPtr type vs self-AryPtr type
3231 const TypePtr *tp = t->is_oopptr();
3232 int offset = meet_offset(tp->offset());
3233 PTR ptr = meet_ptr(tp->ptr());
3234 switch (tp->ptr()) {
3235 case TopPTR:
3236 case AnyNull: {
3237 int instance_id = meet_instance_id(InstanceTop);
3238 return make(ptr, (ptr == Constant ? const_oop() : NULL),
3239 _ary, _klass, _klass_is_exact, offset, instance_id);
3240 }
3241 case BotPTR:
3242 case NotNull:
3243 return TypeOopPtr::make(ptr, offset);
3244 default: ShouldNotReachHere();
3245 }
3246 }
3248 case AnyPtr: { // Meeting two AnyPtrs
3249 // Found an AnyPtr type vs self-AryPtr type
3250 const TypePtr *tp = t->is_ptr();
3251 int offset = meet_offset(tp->offset());
3252 PTR ptr = meet_ptr(tp->ptr());
3253 switch (tp->ptr()) {
3254 case TopPTR:
3255 return this;
3256 case BotPTR:
3257 case NotNull:
3258 return TypePtr::make(AnyPtr, ptr, offset);
3259 case Null:
3260 if( ptr == Null ) return TypePtr::make(AnyPtr, ptr, offset);
3261 // else fall through to AnyNull
3262 case AnyNull: {
3263 int instance_id = meet_instance_id(InstanceTop);
3264 return make( ptr, (ptr == Constant ? const_oop() : NULL),
3265 _ary, _klass, _klass_is_exact, offset, instance_id);
3266 }
3267 default: ShouldNotReachHere();
3268 }
3269 }
3271 case RawPtr: return TypePtr::BOTTOM;
3273 case AryPtr: { // Meeting 2 references?
3274 const TypeAryPtr *tap = t->is_aryptr();
3275 int off = meet_offset(tap->offset());
3276 const TypeAry *tary = _ary->meet(tap->_ary)->is_ary();
3277 PTR ptr = meet_ptr(tap->ptr());
3278 int instance_id = meet_instance_id(tap->instance_id());
3279 ciKlass* lazy_klass = NULL;
3280 if (tary->_elem->isa_int()) {
3281 // Integral array element types have irrelevant lattice relations.
3282 // It is the klass that determines array layout, not the element type.
3283 if (_klass == NULL)
3284 lazy_klass = tap->_klass;
3285 else if (tap->_klass == NULL || tap->_klass == _klass) {
3286 lazy_klass = _klass;
3287 } else {
3288 // Something like byte[int+] meets char[int+].
3289 // This must fall to bottom, not (int[-128..65535])[int+].
3290 instance_id = InstanceBot;
3291 tary = TypeAry::make(Type::BOTTOM, tary->_size);
3292 }
3293 }
3294 bool xk;
3295 switch (tap->ptr()) {
3296 case AnyNull:
3297 case TopPTR:
3298 // Compute new klass on demand, do not use tap->_klass
3299 xk = (tap->_klass_is_exact | this->_klass_is_exact);
3300 return make( ptr, const_oop(), tary, lazy_klass, xk, off, instance_id );
3301 case Constant: {
3302 ciObject* o = const_oop();
3303 if( _ptr == Constant ) {
3304 if( tap->const_oop() != NULL && !o->equals(tap->const_oop()) ) {
3305 ptr = NotNull;
3306 o = NULL;
3307 instance_id = InstanceBot;
3308 }
3309 } else if( above_centerline(_ptr) ) {
3310 o = tap->const_oop();
3311 }
3312 xk = true;
3313 return TypeAryPtr::make( ptr, o, tary, tap->_klass, xk, off, instance_id );
3314 }
3315 case NotNull:
3316 case BotPTR:
3317 // Compute new klass on demand, do not use tap->_klass
3318 if (above_centerline(this->_ptr))
3319 xk = tap->_klass_is_exact;
3320 else if (above_centerline(tap->_ptr))
3321 xk = this->_klass_is_exact;
3322 else xk = (tap->_klass_is_exact & this->_klass_is_exact) &&
3323 (klass() == tap->klass()); // Only precise for identical arrays
3324 return TypeAryPtr::make( ptr, NULL, tary, lazy_klass, xk, off, instance_id );
3325 default: ShouldNotReachHere();
3326 }
3327 }
3329 // All arrays inherit from Object class
3330 case InstPtr: {
3331 const TypeInstPtr *tp = t->is_instptr();
3332 int offset = meet_offset(tp->offset());
3333 PTR ptr = meet_ptr(tp->ptr());
3334 int instance_id = meet_instance_id(tp->instance_id());
3335 switch (ptr) {
3336 case TopPTR:
3337 case AnyNull: // Fall 'down' to dual of object klass
3338 if( tp->klass()->equals(ciEnv::current()->Object_klass()) ) {
3339 return TypeAryPtr::make( ptr, _ary, _klass, _klass_is_exact, offset, instance_id );
3340 } else {
3341 // cannot subclass, so the meet has to fall badly below the centerline
3342 ptr = NotNull;
3343 instance_id = InstanceBot;
3344 return TypeInstPtr::make( ptr, ciEnv::current()->Object_klass(), false, NULL,offset, instance_id);
3345 }
3346 case Constant:
3347 case NotNull:
3348 case BotPTR: // Fall down to object klass
3349 // LCA is object_klass, but if we subclass from the top we can do better
3350 if (above_centerline(tp->ptr())) {
3351 // If 'tp' is above the centerline and it is Object class
3352 // then we can subclass in the Java class heirarchy.
3353 if( tp->klass()->equals(ciEnv::current()->Object_klass()) ) {
3354 // that is, my array type is a subtype of 'tp' klass
3355 return make( ptr, _ary, _klass, _klass_is_exact, offset, instance_id );
3356 }
3357 }
3358 // The other case cannot happen, since t cannot be a subtype of an array.
3359 // The meet falls down to Object class below centerline.
3360 if( ptr == Constant )
3361 ptr = NotNull;
3362 instance_id = InstanceBot;
3363 return TypeInstPtr::make( ptr, ciEnv::current()->Object_klass(), false, NULL,offset, instance_id);
3364 default: typerr(t);
3365 }
3366 }
3368 case KlassPtr:
3369 return TypeInstPtr::BOTTOM;
3371 }
3372 return this; // Lint noise
3373 }
3375 //------------------------------xdual------------------------------------------
3376 // Dual: compute field-by-field dual
3377 const Type *TypeAryPtr::xdual() const {
3378 return new TypeAryPtr( dual_ptr(), _const_oop, _ary->dual()->is_ary(),_klass, _klass_is_exact, dual_offset(), dual_instance_id() );
3379 }
3381 //------------------------------dump2------------------------------------------
3382 #ifndef PRODUCT
3383 void TypeAryPtr::dump2( Dict &d, uint depth, outputStream *st ) const {
3384 _ary->dump2(d,depth,st);
3385 switch( _ptr ) {
3386 case Constant:
3387 const_oop()->print(st);
3388 break;
3389 case BotPTR:
3390 if (!WizardMode && !Verbose) {
3391 if( _klass_is_exact ) st->print(":exact");
3392 break;
3393 }
3394 case TopPTR:
3395 case AnyNull:
3396 case NotNull:
3397 st->print(":%s", ptr_msg[_ptr]);
3398 if( _klass_is_exact ) st->print(":exact");
3399 break;
3400 }
3402 if( _offset != 0 ) {
3403 int header_size = objArrayOopDesc::header_size() * wordSize;
3404 if( _offset == OffsetTop ) st->print("+undefined");
3405 else if( _offset == OffsetBot ) st->print("+any");
3406 else if( _offset < header_size ) st->print("+%d", _offset);
3407 else {
3408 BasicType basic_elem_type = elem()->basic_type();
3409 int array_base = arrayOopDesc::base_offset_in_bytes(basic_elem_type);
3410 int elem_size = type2aelembytes(basic_elem_type);
3411 st->print("[%d]", (_offset - array_base)/elem_size);
3412 }
3413 }
3414 st->print(" *");
3415 if (_instance_id == InstanceTop)
3416 st->print(",iid=top");
3417 else if (_instance_id != InstanceBot)
3418 st->print(",iid=%d",_instance_id);
3419 }
3420 #endif
3422 bool TypeAryPtr::empty(void) const {
3423 if (_ary->empty()) return true;
3424 return TypeOopPtr::empty();
3425 }
3427 //------------------------------add_offset-------------------------------------
3428 const TypePtr *TypeAryPtr::add_offset( int offset ) const {
3429 return make( _ptr, _const_oop, _ary, _klass, _klass_is_exact, xadd_offset(offset), _instance_id );
3430 }
3433 //=============================================================================
3434 const TypeNarrowOop *TypeNarrowOop::BOTTOM;
3435 const TypeNarrowOop *TypeNarrowOop::NULL_PTR;
3438 const TypeNarrowOop* TypeNarrowOop::make(const TypePtr* type) {
3439 return (const TypeNarrowOop*)(new TypeNarrowOop(type))->hashcons();
3440 }
3442 //------------------------------hash-------------------------------------------
3443 // Type-specific hashing function.
3444 int TypeNarrowOop::hash(void) const {
3445 return _ooptype->hash() + 7;
3446 }
3449 bool TypeNarrowOop::eq( const Type *t ) const {
3450 const TypeNarrowOop* tc = t->isa_narrowoop();
3451 if (tc != NULL) {
3452 if (_ooptype->base() != tc->_ooptype->base()) {
3453 return false;
3454 }
3455 return tc->_ooptype->eq(_ooptype);
3456 }
3457 return false;
3458 }
3460 bool TypeNarrowOop::singleton(void) const { // TRUE if type is a singleton
3461 return _ooptype->singleton();
3462 }
3464 bool TypeNarrowOop::empty(void) const {
3465 return _ooptype->empty();
3466 }
3468 //------------------------------meet-------------------------------------------
3469 // Compute the MEET of two types. It returns a new Type object.
3470 const Type *TypeNarrowOop::xmeet( const Type *t ) const {
3471 // Perform a fast test for common case; meeting the same types together.
3472 if( this == t ) return this; // Meeting same type-rep?
3475 // Current "this->_base" is OopPtr
3476 switch (t->base()) { // switch on original type
3478 case Int: // Mixing ints & oops happens when javac
3479 case Long: // reuses local variables
3480 case FloatTop:
3481 case FloatCon:
3482 case FloatBot:
3483 case DoubleTop:
3484 case DoubleCon:
3485 case DoubleBot:
3486 case Bottom: // Ye Olde Default
3487 return Type::BOTTOM;
3488 case Top:
3489 return this;
3491 case NarrowOop: {
3492 const Type* result = _ooptype->xmeet(t->make_ptr());
3493 if (result->isa_ptr()) {
3494 return TypeNarrowOop::make(result->is_ptr());
3495 }
3496 return result;
3497 }
3499 default: // All else is a mistake
3500 typerr(t);
3502 case RawPtr:
3503 case AnyPtr:
3504 case OopPtr:
3505 case InstPtr:
3506 case KlassPtr:
3507 case AryPtr:
3508 typerr(t);
3509 return Type::BOTTOM;
3511 } // End of switch
3512 }
3514 const Type *TypeNarrowOop::xdual() const { // Compute dual right now.
3515 const TypePtr* odual = _ooptype->dual()->is_ptr();
3516 return new TypeNarrowOop(odual);
3517 }
3519 const Type *TypeNarrowOop::filter( const Type *kills ) const {
3520 if (kills->isa_narrowoop()) {
3521 const Type* ft =_ooptype->filter(kills->is_narrowoop()->_ooptype);
3522 if (ft->empty())
3523 return Type::TOP; // Canonical empty value
3524 if (ft->isa_ptr()) {
3525 return make(ft->isa_ptr());
3526 }
3527 return ft;
3528 } else if (kills->isa_ptr()) {
3529 const Type* ft = _ooptype->join(kills);
3530 if (ft->empty())
3531 return Type::TOP; // Canonical empty value
3532 return ft;
3533 } else {
3534 return Type::TOP;
3535 }
3536 }
3539 intptr_t TypeNarrowOop::get_con() const {
3540 return _ooptype->get_con();
3541 }
3543 #ifndef PRODUCT
3544 void TypeNarrowOop::dump2( Dict & d, uint depth, outputStream *st ) const {
3545 tty->print("narrowoop: ");
3546 _ooptype->dump2(d, depth, st);
3547 }
3548 #endif
3551 //=============================================================================
3552 // Convenience common pre-built types.
3554 // Not-null object klass or below
3555 const TypeKlassPtr *TypeKlassPtr::OBJECT;
3556 const TypeKlassPtr *TypeKlassPtr::OBJECT_OR_NULL;
3558 //------------------------------TypeKlasPtr------------------------------------
3559 TypeKlassPtr::TypeKlassPtr( PTR ptr, ciKlass* klass, int offset )
3560 : TypeOopPtr(KlassPtr, ptr, klass, (ptr==Constant), (ptr==Constant ? klass : NULL), offset, 0) {
3561 }
3563 //------------------------------make-------------------------------------------
3564 // ptr to klass 'k', if Constant, or possibly to a sub-klass if not a Constant
3565 const TypeKlassPtr *TypeKlassPtr::make( PTR ptr, ciKlass* k, int offset ) {
3566 assert( k != NULL, "Expect a non-NULL klass");
3567 assert(k->is_instance_klass() || k->is_array_klass() ||
3568 k->is_method_klass(), "Incorrect type of klass oop");
3569 TypeKlassPtr *r =
3570 (TypeKlassPtr*)(new TypeKlassPtr(ptr, k, offset))->hashcons();
3572 return r;
3573 }
3575 //------------------------------eq---------------------------------------------
3576 // Structural equality check for Type representations
3577 bool TypeKlassPtr::eq( const Type *t ) const {
3578 const TypeKlassPtr *p = t->is_klassptr();
3579 return
3580 klass()->equals(p->klass()) &&
3581 TypeOopPtr::eq(p);
3582 }
3584 //------------------------------hash-------------------------------------------
3585 // Type-specific hashing function.
3586 int TypeKlassPtr::hash(void) const {
3587 return klass()->hash() + TypeOopPtr::hash();
3588 }
3591 //------------------------------klass------------------------------------------
3592 // Return the defining klass for this class
3593 ciKlass* TypeAryPtr::klass() const {
3594 if( _klass ) return _klass; // Return cached value, if possible
3596 // Oops, need to compute _klass and cache it
3597 ciKlass* k_ary = NULL;
3598 const TypeInstPtr *tinst;
3599 const TypeAryPtr *tary;
3600 const Type* el = elem();
3601 if (el->isa_narrowoop()) {
3602 el = el->make_ptr();
3603 }
3605 // Get element klass
3606 if ((tinst = el->isa_instptr()) != NULL) {
3607 // Compute array klass from element klass
3608 k_ary = ciObjArrayKlass::make(tinst->klass());
3609 } else if ((tary = el->isa_aryptr()) != NULL) {
3610 // Compute array klass from element klass
3611 ciKlass* k_elem = tary->klass();
3612 // If element type is something like bottom[], k_elem will be null.
3613 if (k_elem != NULL)
3614 k_ary = ciObjArrayKlass::make(k_elem);
3615 } else if ((el->base() == Type::Top) ||
3616 (el->base() == Type::Bottom)) {
3617 // element type of Bottom occurs from meet of basic type
3618 // and object; Top occurs when doing join on Bottom.
3619 // Leave k_ary at NULL.
3620 } else {
3621 // Cannot compute array klass directly from basic type,
3622 // since subtypes of TypeInt all have basic type T_INT.
3623 assert(!el->isa_int(),
3624 "integral arrays must be pre-equipped with a class");
3625 // Compute array klass directly from basic type
3626 k_ary = ciTypeArrayKlass::make(el->basic_type());
3627 }
3629 if( this != TypeAryPtr::OOPS ) {
3630 // The _klass field acts as a cache of the underlying
3631 // ciKlass for this array type. In order to set the field,
3632 // we need to cast away const-ness.
3633 //
3634 // IMPORTANT NOTE: we *never* set the _klass field for the
3635 // type TypeAryPtr::OOPS. This Type is shared between all
3636 // active compilations. However, the ciKlass which represents
3637 // this Type is *not* shared between compilations, so caching
3638 // this value would result in fetching a dangling pointer.
3639 //
3640 // Recomputing the underlying ciKlass for each request is
3641 // a bit less efficient than caching, but calls to
3642 // TypeAryPtr::OOPS->klass() are not common enough to matter.
3643 ((TypeAryPtr*)this)->_klass = k_ary;
3644 if (UseCompressedOops && k_ary != NULL && k_ary->is_obj_array_klass() &&
3645 _offset != 0 && _offset != arrayOopDesc::length_offset_in_bytes()) {
3646 ((TypeAryPtr*)this)->_is_ptr_to_narrowoop = true;
3647 }
3648 }
3649 return k_ary;
3650 }
3653 //------------------------------add_offset-------------------------------------
3654 // Access internals of klass object
3655 const TypePtr *TypeKlassPtr::add_offset( int offset ) const {
3656 return make( _ptr, klass(), xadd_offset(offset) );
3657 }
3659 //------------------------------cast_to_ptr_type-------------------------------
3660 const Type *TypeKlassPtr::cast_to_ptr_type(PTR ptr) const {
3661 assert(_base == OopPtr, "subclass must override cast_to_ptr_type");
3662 if( ptr == _ptr ) return this;
3663 return make(ptr, _klass, _offset);
3664 }
3667 //-----------------------------cast_to_exactness-------------------------------
3668 const Type *TypeKlassPtr::cast_to_exactness(bool klass_is_exact) const {
3669 if( klass_is_exact == _klass_is_exact ) return this;
3670 if (!UseExactTypes) return this;
3671 return make(klass_is_exact ? Constant : NotNull, _klass, _offset);
3672 }
3675 //-----------------------------as_instance_type--------------------------------
3676 // Corresponding type for an instance of the given class.
3677 // It will be NotNull, and exact if and only if the klass type is exact.
3678 const TypeOopPtr* TypeKlassPtr::as_instance_type() const {
3679 ciKlass* k = klass();
3680 bool xk = klass_is_exact();
3681 //return TypeInstPtr::make(TypePtr::NotNull, k, xk, NULL, 0);
3682 const TypeOopPtr* toop = TypeOopPtr::make_from_klass_raw(k);
3683 toop = toop->cast_to_ptr_type(TypePtr::NotNull)->is_oopptr();
3684 return toop->cast_to_exactness(xk)->is_oopptr();
3685 }
3688 //------------------------------xmeet------------------------------------------
3689 // Compute the MEET of two types, return a new Type object.
3690 const Type *TypeKlassPtr::xmeet( const Type *t ) const {
3691 // Perform a fast test for common case; meeting the same types together.
3692 if( this == t ) return this; // Meeting same type-rep?
3694 // Current "this->_base" is Pointer
3695 switch (t->base()) { // switch on original type
3697 case Int: // Mixing ints & oops happens when javac
3698 case Long: // reuses local variables
3699 case FloatTop:
3700 case FloatCon:
3701 case FloatBot:
3702 case DoubleTop:
3703 case DoubleCon:
3704 case DoubleBot:
3705 case Bottom: // Ye Olde Default
3706 return Type::BOTTOM;
3707 case Top:
3708 return this;
3710 default: // All else is a mistake
3711 typerr(t);
3713 case RawPtr: return TypePtr::BOTTOM;
3715 case OopPtr: { // Meeting to OopPtrs
3716 // Found a OopPtr type vs self-KlassPtr type
3717 const TypePtr *tp = t->is_oopptr();
3718 int offset = meet_offset(tp->offset());
3719 PTR ptr = meet_ptr(tp->ptr());
3720 switch (tp->ptr()) {
3721 case TopPTR:
3722 case AnyNull:
3723 return make(ptr, klass(), offset);
3724 case BotPTR:
3725 case NotNull:
3726 return TypePtr::make(AnyPtr, ptr, offset);
3727 default: typerr(t);
3728 }
3729 }
3731 case AnyPtr: { // Meeting to AnyPtrs
3732 // Found an AnyPtr type vs self-KlassPtr type
3733 const TypePtr *tp = t->is_ptr();
3734 int offset = meet_offset(tp->offset());
3735 PTR ptr = meet_ptr(tp->ptr());
3736 switch (tp->ptr()) {
3737 case TopPTR:
3738 return this;
3739 case Null:
3740 if( ptr == Null ) return TypePtr::make( AnyPtr, ptr, offset );
3741 case AnyNull:
3742 return make( ptr, klass(), offset );
3743 case BotPTR:
3744 case NotNull:
3745 return TypePtr::make(AnyPtr, ptr, offset);
3746 default: typerr(t);
3747 }
3748 }
3750 case AryPtr: // Meet with AryPtr
3751 case InstPtr: // Meet with InstPtr
3752 return TypeInstPtr::BOTTOM;
3754 //
3755 // A-top }
3756 // / | \ } Tops
3757 // B-top A-any C-top }
3758 // | / | \ | } Any-nulls
3759 // B-any | C-any }
3760 // | | |
3761 // B-con A-con C-con } constants; not comparable across classes
3762 // | | |
3763 // B-not | C-not }
3764 // | \ | / | } not-nulls
3765 // B-bot A-not C-bot }
3766 // \ | / } Bottoms
3767 // A-bot }
3768 //
3770 case KlassPtr: { // Meet two KlassPtr types
3771 const TypeKlassPtr *tkls = t->is_klassptr();
3772 int off = meet_offset(tkls->offset());
3773 PTR ptr = meet_ptr(tkls->ptr());
3775 // Check for easy case; klasses are equal (and perhaps not loaded!)
3776 // If we have constants, then we created oops so classes are loaded
3777 // and we can handle the constants further down. This case handles
3778 // not-loaded classes
3779 if( ptr != Constant && tkls->klass()->equals(klass()) ) {
3780 return make( ptr, klass(), off );
3781 }
3783 // Classes require inspection in the Java klass hierarchy. Must be loaded.
3784 ciKlass* tkls_klass = tkls->klass();
3785 ciKlass* this_klass = this->klass();
3786 assert( tkls_klass->is_loaded(), "This class should have been loaded.");
3787 assert( this_klass->is_loaded(), "This class should have been loaded.");
3789 // If 'this' type is above the centerline and is a superclass of the
3790 // other, we can treat 'this' as having the same type as the other.
3791 if ((above_centerline(this->ptr())) &&
3792 tkls_klass->is_subtype_of(this_klass)) {
3793 this_klass = tkls_klass;
3794 }
3795 // If 'tinst' type is above the centerline and is a superclass of the
3796 // other, we can treat 'tinst' as having the same type as the other.
3797 if ((above_centerline(tkls->ptr())) &&
3798 this_klass->is_subtype_of(tkls_klass)) {
3799 tkls_klass = this_klass;
3800 }
3802 // Check for classes now being equal
3803 if (tkls_klass->equals(this_klass)) {
3804 // If the klasses are equal, the constants may still differ. Fall to
3805 // NotNull if they do (neither constant is NULL; that is a special case
3806 // handled elsewhere).
3807 ciObject* o = NULL; // Assume not constant when done
3808 ciObject* this_oop = const_oop();
3809 ciObject* tkls_oop = tkls->const_oop();
3810 if( ptr == Constant ) {
3811 if (this_oop != NULL && tkls_oop != NULL &&
3812 this_oop->equals(tkls_oop) )
3813 o = this_oop;
3814 else if (above_centerline(this->ptr()))
3815 o = tkls_oop;
3816 else if (above_centerline(tkls->ptr()))
3817 o = this_oop;
3818 else
3819 ptr = NotNull;
3820 }
3821 return make( ptr, this_klass, off );
3822 } // Else classes are not equal
3824 // Since klasses are different, we require the LCA in the Java
3825 // class hierarchy - which means we have to fall to at least NotNull.
3826 if( ptr == TopPTR || ptr == AnyNull || ptr == Constant )
3827 ptr = NotNull;
3828 // Now we find the LCA of Java classes
3829 ciKlass* k = this_klass->least_common_ancestor(tkls_klass);
3830 return make( ptr, k, off );
3831 } // End of case KlassPtr
3833 } // End of switch
3834 return this; // Return the double constant
3835 }
3837 //------------------------------xdual------------------------------------------
3838 // Dual: compute field-by-field dual
3839 const Type *TypeKlassPtr::xdual() const {
3840 return new TypeKlassPtr( dual_ptr(), klass(), dual_offset() );
3841 }
3843 //------------------------------dump2------------------------------------------
3844 // Dump Klass Type
3845 #ifndef PRODUCT
3846 void TypeKlassPtr::dump2( Dict & d, uint depth, outputStream *st ) const {
3847 switch( _ptr ) {
3848 case Constant:
3849 st->print("precise ");
3850 case NotNull:
3851 {
3852 const char *name = klass()->name()->as_utf8();
3853 if( name ) {
3854 st->print("klass %s: " INTPTR_FORMAT, name, klass());
3855 } else {
3856 ShouldNotReachHere();
3857 }
3858 }
3859 case BotPTR:
3860 if( !WizardMode && !Verbose && !_klass_is_exact ) break;
3861 case TopPTR:
3862 case AnyNull:
3863 st->print(":%s", ptr_msg[_ptr]);
3864 if( _klass_is_exact ) st->print(":exact");
3865 break;
3866 }
3868 if( _offset ) { // Dump offset, if any
3869 if( _offset == OffsetBot ) { st->print("+any"); }
3870 else if( _offset == OffsetTop ) { st->print("+unknown"); }
3871 else { st->print("+%d", _offset); }
3872 }
3874 st->print(" *");
3875 }
3876 #endif
3880 //=============================================================================
3881 // Convenience common pre-built types.
3883 //------------------------------make-------------------------------------------
3884 const TypeFunc *TypeFunc::make( const TypeTuple *domain, const TypeTuple *range ) {
3885 return (TypeFunc*)(new TypeFunc(domain,range))->hashcons();
3886 }
3888 //------------------------------make-------------------------------------------
3889 const TypeFunc *TypeFunc::make(ciMethod* method) {
3890 Compile* C = Compile::current();
3891 const TypeFunc* tf = C->last_tf(method); // check cache
3892 if (tf != NULL) return tf; // The hit rate here is almost 50%.
3893 const TypeTuple *domain;
3894 if (method->flags().is_static()) {
3895 domain = TypeTuple::make_domain(NULL, method->signature());
3896 } else {
3897 domain = TypeTuple::make_domain(method->holder(), method->signature());
3898 }
3899 const TypeTuple *range = TypeTuple::make_range(method->signature());
3900 tf = TypeFunc::make(domain, range);
3901 C->set_last_tf(method, tf); // fill cache
3902 return tf;
3903 }
3905 //------------------------------meet-------------------------------------------
3906 // Compute the MEET of two types. It returns a new Type object.
3907 const Type *TypeFunc::xmeet( const Type *t ) const {
3908 // Perform a fast test for common case; meeting the same types together.
3909 if( this == t ) return this; // Meeting same type-rep?
3911 // Current "this->_base" is Func
3912 switch (t->base()) { // switch on original type
3914 case Bottom: // Ye Olde Default
3915 return t;
3917 default: // All else is a mistake
3918 typerr(t);
3920 case Top:
3921 break;
3922 }
3923 return this; // Return the double constant
3924 }
3926 //------------------------------xdual------------------------------------------
3927 // Dual: compute field-by-field dual
3928 const Type *TypeFunc::xdual() const {
3929 return this;
3930 }
3932 //------------------------------eq---------------------------------------------
3933 // Structural equality check for Type representations
3934 bool TypeFunc::eq( const Type *t ) const {
3935 const TypeFunc *a = (const TypeFunc*)t;
3936 return _domain == a->_domain &&
3937 _range == a->_range;
3938 }
3940 //------------------------------hash-------------------------------------------
3941 // Type-specific hashing function.
3942 int TypeFunc::hash(void) const {
3943 return (intptr_t)_domain + (intptr_t)_range;
3944 }
3946 //------------------------------dump2------------------------------------------
3947 // Dump Function Type
3948 #ifndef PRODUCT
3949 void TypeFunc::dump2( Dict &d, uint depth, outputStream *st ) const {
3950 if( _range->_cnt <= Parms )
3951 st->print("void");
3952 else {
3953 uint i;
3954 for (i = Parms; i < _range->_cnt-1; i++) {
3955 _range->field_at(i)->dump2(d,depth,st);
3956 st->print("/");
3957 }
3958 _range->field_at(i)->dump2(d,depth,st);
3959 }
3960 st->print(" ");
3961 st->print("( ");
3962 if( !depth || d[this] ) { // Check for recursive dump
3963 st->print("...)");
3964 return;
3965 }
3966 d.Insert((void*)this,(void*)this); // Stop recursion
3967 if (Parms < _domain->_cnt)
3968 _domain->field_at(Parms)->dump2(d,depth-1,st);
3969 for (uint i = Parms+1; i < _domain->_cnt; i++) {
3970 st->print(", ");
3971 _domain->field_at(i)->dump2(d,depth-1,st);
3972 }
3973 st->print(" )");
3974 }
3976 //------------------------------print_flattened--------------------------------
3977 // Print a 'flattened' signature
3978 static const char * const flat_type_msg[Type::lastype] = {
3979 "bad","control","top","int","long","_", "narrowoop",
3980 "tuple:", "array:",
3981 "ptr", "rawptr", "ptr", "ptr", "ptr", "ptr",
3982 "func", "abIO", "return_address", "mem",
3983 "float_top", "ftcon:", "flt",
3984 "double_top", "dblcon:", "dbl",
3985 "bottom"
3986 };
3988 void TypeFunc::print_flattened() const {
3989 if( _range->_cnt <= Parms )
3990 tty->print("void");
3991 else {
3992 uint i;
3993 for (i = Parms; i < _range->_cnt-1; i++)
3994 tty->print("%s/",flat_type_msg[_range->field_at(i)->base()]);
3995 tty->print("%s",flat_type_msg[_range->field_at(i)->base()]);
3996 }
3997 tty->print(" ( ");
3998 if (Parms < _domain->_cnt)
3999 tty->print("%s",flat_type_msg[_domain->field_at(Parms)->base()]);
4000 for (uint i = Parms+1; i < _domain->_cnt; i++)
4001 tty->print(", %s",flat_type_msg[_domain->field_at(i)->base()]);
4002 tty->print(" )");
4003 }
4004 #endif
4006 //------------------------------singleton--------------------------------------
4007 // TRUE if Type is a singleton type, FALSE otherwise. Singletons are simple
4008 // constants (Ldi nodes). Singletons are integer, float or double constants
4009 // or a single symbol.
4010 bool TypeFunc::singleton(void) const {
4011 return false; // Never a singleton
4012 }
4014 bool TypeFunc::empty(void) const {
4015 return false; // Never empty
4016 }
4019 BasicType TypeFunc::return_type() const{
4020 if (range()->cnt() == TypeFunc::Parms) {
4021 return T_VOID;
4022 }
4023 return range()->field_at(TypeFunc::Parms)->basic_type();
4024 }