Tue, 15 Sep 2009 21:53:47 -0700
6863023: need non-perm oops in code cache for JSR 292
Summary: Make a special root-list for those few nmethods which might contain non-perm oops.
Reviewed-by: twisti, kvn, never, jmasa, ysr
1 /*
2 * Copyright 1997-2009 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::UBYTE = TypeInt::make(0, 255, WidenMin); // Unsigned Bytes
230 TypeInt::CHAR = TypeInt::make(0,65535, WidenMin); // Java chars
231 TypeInt::SHORT = TypeInt::make(-32768,32767, WidenMin); // Java shorts
232 TypeInt::POS = TypeInt::make(0,max_jint, WidenMin); // Non-neg values
233 TypeInt::POS1 = TypeInt::make(1,max_jint, WidenMin); // Positive values
234 TypeInt::INT = TypeInt::make(min_jint,max_jint, WidenMax); // 32-bit integers
235 TypeInt::SYMINT = TypeInt::make(-max_jint,max_jint,WidenMin); // symmetric range
236 // CmpL is overloaded both as the bytecode computation returning
237 // a trinary (-1,0,+1) integer result AND as an efficient long
238 // compare returning optimizer ideal-type flags.
239 assert( TypeInt::CC_LT == TypeInt::MINUS_1, "types must match for CmpL to work" );
240 assert( TypeInt::CC_GT == TypeInt::ONE, "types must match for CmpL to work" );
241 assert( TypeInt::CC_EQ == TypeInt::ZERO, "types must match for CmpL to work" );
242 assert( TypeInt::CC_GE == TypeInt::BOOL, "types must match for CmpL to work" );
244 TypeLong::MINUS_1 = TypeLong::make(-1); // -1
245 TypeLong::ZERO = TypeLong::make( 0); // 0
246 TypeLong::ONE = TypeLong::make( 1); // 1
247 TypeLong::POS = TypeLong::make(0,max_jlong, WidenMin); // Non-neg values
248 TypeLong::LONG = TypeLong::make(min_jlong,max_jlong,WidenMax); // 64-bit integers
249 TypeLong::INT = TypeLong::make((jlong)min_jint,(jlong)max_jint,WidenMin);
250 TypeLong::UINT = TypeLong::make(0,(jlong)max_juint,WidenMin);
252 const Type **fboth =(const Type**)shared_type_arena->Amalloc_4(2*sizeof(Type*));
253 fboth[0] = Type::CONTROL;
254 fboth[1] = Type::CONTROL;
255 TypeTuple::IFBOTH = TypeTuple::make( 2, fboth );
257 const Type **ffalse =(const Type**)shared_type_arena->Amalloc_4(2*sizeof(Type*));
258 ffalse[0] = Type::CONTROL;
259 ffalse[1] = Type::TOP;
260 TypeTuple::IFFALSE = TypeTuple::make( 2, ffalse );
262 const Type **fneither =(const Type**)shared_type_arena->Amalloc_4(2*sizeof(Type*));
263 fneither[0] = Type::TOP;
264 fneither[1] = Type::TOP;
265 TypeTuple::IFNEITHER = TypeTuple::make( 2, fneither );
267 const Type **ftrue =(const Type**)shared_type_arena->Amalloc_4(2*sizeof(Type*));
268 ftrue[0] = Type::TOP;
269 ftrue[1] = Type::CONTROL;
270 TypeTuple::IFTRUE = TypeTuple::make( 2, ftrue );
272 const Type **floop =(const Type**)shared_type_arena->Amalloc_4(2*sizeof(Type*));
273 floop[0] = Type::CONTROL;
274 floop[1] = TypeInt::INT;
275 TypeTuple::LOOPBODY = TypeTuple::make( 2, floop );
277 TypePtr::NULL_PTR= TypePtr::make( AnyPtr, TypePtr::Null, 0 );
278 TypePtr::NOTNULL = TypePtr::make( AnyPtr, TypePtr::NotNull, OffsetBot );
279 TypePtr::BOTTOM = TypePtr::make( AnyPtr, TypePtr::BotPTR, OffsetBot );
281 TypeRawPtr::BOTTOM = TypeRawPtr::make( TypePtr::BotPTR );
282 TypeRawPtr::NOTNULL= TypeRawPtr::make( TypePtr::NotNull );
284 const Type **fmembar = TypeTuple::fields(0);
285 TypeTuple::MEMBAR = TypeTuple::make(TypeFunc::Parms+0, fmembar);
287 const Type **fsc = (const Type**)shared_type_arena->Amalloc_4(2*sizeof(Type*));
288 fsc[0] = TypeInt::CC;
289 fsc[1] = Type::MEMORY;
290 TypeTuple::STORECONDITIONAL = TypeTuple::make(2, fsc);
292 TypeInstPtr::NOTNULL = TypeInstPtr::make(TypePtr::NotNull, current->env()->Object_klass());
293 TypeInstPtr::BOTTOM = TypeInstPtr::make(TypePtr::BotPTR, current->env()->Object_klass());
294 TypeInstPtr::MIRROR = TypeInstPtr::make(TypePtr::NotNull, current->env()->Class_klass());
295 TypeInstPtr::MARK = TypeInstPtr::make(TypePtr::BotPTR, current->env()->Object_klass(),
296 false, 0, oopDesc::mark_offset_in_bytes());
297 TypeInstPtr::KLASS = TypeInstPtr::make(TypePtr::BotPTR, current->env()->Object_klass(),
298 false, 0, oopDesc::klass_offset_in_bytes());
299 TypeOopPtr::BOTTOM = TypeOopPtr::make(TypePtr::BotPTR, OffsetBot);
301 TypeNarrowOop::NULL_PTR = TypeNarrowOop::make( TypePtr::NULL_PTR );
302 TypeNarrowOop::BOTTOM = TypeNarrowOop::make( TypeInstPtr::BOTTOM );
304 mreg2type[Op_Node] = Type::BOTTOM;
305 mreg2type[Op_Set ] = 0;
306 mreg2type[Op_RegN] = TypeNarrowOop::BOTTOM;
307 mreg2type[Op_RegI] = TypeInt::INT;
308 mreg2type[Op_RegP] = TypePtr::BOTTOM;
309 mreg2type[Op_RegF] = Type::FLOAT;
310 mreg2type[Op_RegD] = Type::DOUBLE;
311 mreg2type[Op_RegL] = TypeLong::LONG;
312 mreg2type[Op_RegFlags] = TypeInt::CC;
314 TypeAryPtr::RANGE = TypeAryPtr::make( TypePtr::BotPTR, TypeAry::make(Type::BOTTOM,TypeInt::POS), current->env()->Object_klass(), false, arrayOopDesc::length_offset_in_bytes());
316 TypeAryPtr::NARROWOOPS = TypeAryPtr::make(TypePtr::BotPTR, TypeAry::make(TypeNarrowOop::BOTTOM, TypeInt::POS), NULL /*ciArrayKlass::make(o)*/, false, Type::OffsetBot);
318 #ifdef _LP64
319 if (UseCompressedOops) {
320 TypeAryPtr::OOPS = TypeAryPtr::NARROWOOPS;
321 } else
322 #endif
323 {
324 // There is no shared klass for Object[]. See note in TypeAryPtr::klass().
325 TypeAryPtr::OOPS = TypeAryPtr::make(TypePtr::BotPTR, TypeAry::make(TypeInstPtr::BOTTOM,TypeInt::POS), NULL /*ciArrayKlass::make(o)*/, false, Type::OffsetBot);
326 }
327 TypeAryPtr::BYTES = TypeAryPtr::make(TypePtr::BotPTR, TypeAry::make(TypeInt::BYTE ,TypeInt::POS), ciTypeArrayKlass::make(T_BYTE), true, Type::OffsetBot);
328 TypeAryPtr::SHORTS = TypeAryPtr::make(TypePtr::BotPTR, TypeAry::make(TypeInt::SHORT ,TypeInt::POS), ciTypeArrayKlass::make(T_SHORT), true, Type::OffsetBot);
329 TypeAryPtr::CHARS = TypeAryPtr::make(TypePtr::BotPTR, TypeAry::make(TypeInt::CHAR ,TypeInt::POS), ciTypeArrayKlass::make(T_CHAR), true, Type::OffsetBot);
330 TypeAryPtr::INTS = TypeAryPtr::make(TypePtr::BotPTR, TypeAry::make(TypeInt::INT ,TypeInt::POS), ciTypeArrayKlass::make(T_INT), true, Type::OffsetBot);
331 TypeAryPtr::LONGS = TypeAryPtr::make(TypePtr::BotPTR, TypeAry::make(TypeLong::LONG ,TypeInt::POS), ciTypeArrayKlass::make(T_LONG), true, Type::OffsetBot);
332 TypeAryPtr::FLOATS = TypeAryPtr::make(TypePtr::BotPTR, TypeAry::make(Type::FLOAT ,TypeInt::POS), ciTypeArrayKlass::make(T_FLOAT), true, Type::OffsetBot);
333 TypeAryPtr::DOUBLES = TypeAryPtr::make(TypePtr::BotPTR, TypeAry::make(Type::DOUBLE ,TypeInt::POS), ciTypeArrayKlass::make(T_DOUBLE), true, Type::OffsetBot);
335 // Nobody should ask _array_body_type[T_NARROWOOP]. Use NULL as assert.
336 TypeAryPtr::_array_body_type[T_NARROWOOP] = NULL;
337 TypeAryPtr::_array_body_type[T_OBJECT] = TypeAryPtr::OOPS;
338 TypeAryPtr::_array_body_type[T_ARRAY] = TypeAryPtr::OOPS; // arrays are stored in oop arrays
339 TypeAryPtr::_array_body_type[T_BYTE] = TypeAryPtr::BYTES;
340 TypeAryPtr::_array_body_type[T_BOOLEAN] = TypeAryPtr::BYTES; // boolean[] is a byte array
341 TypeAryPtr::_array_body_type[T_SHORT] = TypeAryPtr::SHORTS;
342 TypeAryPtr::_array_body_type[T_CHAR] = TypeAryPtr::CHARS;
343 TypeAryPtr::_array_body_type[T_INT] = TypeAryPtr::INTS;
344 TypeAryPtr::_array_body_type[T_LONG] = TypeAryPtr::LONGS;
345 TypeAryPtr::_array_body_type[T_FLOAT] = TypeAryPtr::FLOATS;
346 TypeAryPtr::_array_body_type[T_DOUBLE] = TypeAryPtr::DOUBLES;
348 TypeKlassPtr::OBJECT = TypeKlassPtr::make( TypePtr::NotNull, current->env()->Object_klass(), 0 );
349 TypeKlassPtr::OBJECT_OR_NULL = TypeKlassPtr::make( TypePtr::BotPTR, current->env()->Object_klass(), 0 );
351 const Type **fi2c = TypeTuple::fields(2);
352 fi2c[TypeFunc::Parms+0] = TypeInstPtr::BOTTOM; // methodOop
353 fi2c[TypeFunc::Parms+1] = TypeRawPtr::BOTTOM; // argument pointer
354 TypeTuple::START_I2C = TypeTuple::make(TypeFunc::Parms+2, fi2c);
356 const Type **intpair = TypeTuple::fields(2);
357 intpair[0] = TypeInt::INT;
358 intpair[1] = TypeInt::INT;
359 TypeTuple::INT_PAIR = TypeTuple::make(2, intpair);
361 const Type **longpair = TypeTuple::fields(2);
362 longpair[0] = TypeLong::LONG;
363 longpair[1] = TypeLong::LONG;
364 TypeTuple::LONG_PAIR = TypeTuple::make(2, longpair);
366 _const_basic_type[T_NARROWOOP] = TypeNarrowOop::BOTTOM;
367 _const_basic_type[T_BOOLEAN] = TypeInt::BOOL;
368 _const_basic_type[T_CHAR] = TypeInt::CHAR;
369 _const_basic_type[T_BYTE] = TypeInt::BYTE;
370 _const_basic_type[T_SHORT] = TypeInt::SHORT;
371 _const_basic_type[T_INT] = TypeInt::INT;
372 _const_basic_type[T_LONG] = TypeLong::LONG;
373 _const_basic_type[T_FLOAT] = Type::FLOAT;
374 _const_basic_type[T_DOUBLE] = Type::DOUBLE;
375 _const_basic_type[T_OBJECT] = TypeInstPtr::BOTTOM;
376 _const_basic_type[T_ARRAY] = TypeInstPtr::BOTTOM; // there is no separate bottom for arrays
377 _const_basic_type[T_VOID] = TypePtr::NULL_PTR; // reflection represents void this way
378 _const_basic_type[T_ADDRESS] = TypeRawPtr::BOTTOM; // both interpreter return addresses & random raw ptrs
379 _const_basic_type[T_CONFLICT]= Type::BOTTOM; // why not?
381 _zero_type[T_NARROWOOP] = TypeNarrowOop::NULL_PTR;
382 _zero_type[T_BOOLEAN] = TypeInt::ZERO; // false == 0
383 _zero_type[T_CHAR] = TypeInt::ZERO; // '\0' == 0
384 _zero_type[T_BYTE] = TypeInt::ZERO; // 0x00 == 0
385 _zero_type[T_SHORT] = TypeInt::ZERO; // 0x0000 == 0
386 _zero_type[T_INT] = TypeInt::ZERO;
387 _zero_type[T_LONG] = TypeLong::ZERO;
388 _zero_type[T_FLOAT] = TypeF::ZERO;
389 _zero_type[T_DOUBLE] = TypeD::ZERO;
390 _zero_type[T_OBJECT] = TypePtr::NULL_PTR;
391 _zero_type[T_ARRAY] = TypePtr::NULL_PTR; // null array is null oop
392 _zero_type[T_ADDRESS] = TypePtr::NULL_PTR; // raw pointers use the same null
393 _zero_type[T_VOID] = Type::TOP; // the only void value is no value at all
395 // get_zero_type() should not happen for T_CONFLICT
396 _zero_type[T_CONFLICT]= NULL;
398 // Restore working type arena.
399 current->set_type_arena(save);
400 current->set_type_dict(NULL);
401 }
403 //------------------------------Initialize-------------------------------------
404 void Type::Initialize(Compile* current) {
405 assert(current->type_arena() != NULL, "must have created type arena");
407 if (_shared_type_dict == NULL) {
408 Initialize_shared(current);
409 }
411 Arena* type_arena = current->type_arena();
413 // Create the hash-cons'ing dictionary with top-level storage allocation
414 Dict *tdic = new (type_arena) Dict( (CmpKey)Type::cmp,(Hash)Type::uhash, type_arena, 128 );
415 current->set_type_dict(tdic);
417 // Transfer the shared types.
418 DictI i(_shared_type_dict);
419 for( ; i.test(); ++i ) {
420 Type* t = (Type*)i._value;
421 tdic->Insert(t,t); // New Type, insert into Type table
422 }
424 #ifdef ASSERT
425 verify_lastype();
426 #endif
427 }
429 //------------------------------hashcons---------------------------------------
430 // Do the hash-cons trick. If the Type already exists in the type table,
431 // delete the current Type and return the existing Type. Otherwise stick the
432 // current Type in the Type table.
433 const Type *Type::hashcons(void) {
434 debug_only(base()); // Check the assertion in Type::base().
435 // Look up the Type in the Type dictionary
436 Dict *tdic = type_dict();
437 Type* old = (Type*)(tdic->Insert(this, this, false));
438 if( old ) { // Pre-existing Type?
439 if( old != this ) // Yes, this guy is not the pre-existing?
440 delete this; // Yes, Nuke this guy
441 assert( old->_dual, "" );
442 return old; // Return pre-existing
443 }
445 // Every type has a dual (to make my lattice symmetric).
446 // Since we just discovered a new Type, compute its dual right now.
447 assert( !_dual, "" ); // No dual yet
448 _dual = xdual(); // Compute the dual
449 if( cmp(this,_dual)==0 ) { // Handle self-symmetric
450 _dual = this;
451 return this;
452 }
453 assert( !_dual->_dual, "" ); // No reverse dual yet
454 assert( !(*tdic)[_dual], "" ); // Dual not in type system either
455 // New Type, insert into Type table
456 tdic->Insert((void*)_dual,(void*)_dual);
457 ((Type*)_dual)->_dual = this; // Finish up being symmetric
458 #ifdef ASSERT
459 Type *dual_dual = (Type*)_dual->xdual();
460 assert( eq(dual_dual), "xdual(xdual()) should be identity" );
461 delete dual_dual;
462 #endif
463 return this; // Return new Type
464 }
466 //------------------------------eq---------------------------------------------
467 // Structural equality check for Type representations
468 bool Type::eq( const Type * ) const {
469 return true; // Nothing else can go wrong
470 }
472 //------------------------------hash-------------------------------------------
473 // Type-specific hashing function.
474 int Type::hash(void) const {
475 return _base;
476 }
478 //------------------------------is_finite--------------------------------------
479 // Has a finite value
480 bool Type::is_finite() const {
481 return false;
482 }
484 //------------------------------is_nan-----------------------------------------
485 // Is not a number (NaN)
486 bool Type::is_nan() const {
487 return false;
488 }
490 //----------------------interface_vs_oop---------------------------------------
491 #ifdef ASSERT
492 bool Type::interface_vs_oop(const Type *t) const {
493 bool result = false;
495 const TypeInstPtr* this_inst = this->isa_instptr();
496 const TypeInstPtr* t_inst = t->isa_instptr();
497 if( this_inst && this_inst->is_loaded() && t_inst && t_inst->is_loaded() ) {
498 bool this_interface = this_inst->klass()->is_interface();
499 bool t_interface = t_inst->klass()->is_interface();
500 result = this_interface ^ t_interface;
501 }
503 return result;
504 }
505 #endif
507 //------------------------------meet-------------------------------------------
508 // Compute the MEET of two types. NOT virtual. It enforces that meet is
509 // commutative and the lattice is symmetric.
510 const Type *Type::meet( const Type *t ) const {
511 if (isa_narrowoop() && t->isa_narrowoop()) {
512 const Type* result = make_ptr()->meet(t->make_ptr());
513 return result->make_narrowoop();
514 }
516 const Type *mt = xmeet(t);
517 if (isa_narrowoop() || t->isa_narrowoop()) return mt;
518 #ifdef ASSERT
519 assert( mt == t->xmeet(this), "meet not commutative" );
520 const Type* dual_join = mt->_dual;
521 const Type *t2t = dual_join->xmeet(t->_dual);
522 const Type *t2this = dual_join->xmeet( _dual);
524 // Interface meet Oop is Not Symmetric:
525 // Interface:AnyNull meet Oop:AnyNull == Interface:AnyNull
526 // Interface:NotNull meet Oop:NotNull == java/lang/Object:NotNull
528 if( !interface_vs_oop(t) && (t2t != t->_dual || t2this != _dual) ) {
529 tty->print_cr("=== Meet Not Symmetric ===");
530 tty->print("t = "); t->dump(); tty->cr();
531 tty->print("this= "); dump(); tty->cr();
532 tty->print("mt=(t meet this)= "); mt->dump(); tty->cr();
534 tty->print("t_dual= "); t->_dual->dump(); tty->cr();
535 tty->print("this_dual= "); _dual->dump(); tty->cr();
536 tty->print("mt_dual= "); mt->_dual->dump(); tty->cr();
538 tty->print("mt_dual meet t_dual= "); t2t ->dump(); tty->cr();
539 tty->print("mt_dual meet this_dual= "); t2this ->dump(); tty->cr();
541 fatal("meet not symmetric" );
542 }
543 #endif
544 return mt;
545 }
547 //------------------------------xmeet------------------------------------------
548 // Compute the MEET of two types. It returns a new Type object.
549 const Type *Type::xmeet( const Type *t ) const {
550 // Perform a fast test for common case; meeting the same types together.
551 if( this == t ) return this; // Meeting same type-rep?
553 // Meeting TOP with anything?
554 if( _base == Top ) return t;
556 // Meeting BOTTOM with anything?
557 if( _base == Bottom ) return BOTTOM;
559 // Current "this->_base" is one of: Bad, Multi, Control, Top,
560 // Abio, Abstore, Floatxxx, Doublexxx, Bottom, lastype.
561 switch (t->base()) { // Switch on original type
563 // Cut in half the number of cases I must handle. Only need cases for when
564 // the given enum "t->type" is less than or equal to the local enum "type".
565 case FloatCon:
566 case DoubleCon:
567 case Int:
568 case Long:
569 return t->xmeet(this);
571 case OopPtr:
572 return t->xmeet(this);
574 case InstPtr:
575 return t->xmeet(this);
577 case KlassPtr:
578 return t->xmeet(this);
580 case AryPtr:
581 return t->xmeet(this);
583 case NarrowOop:
584 return t->xmeet(this);
586 case Bad: // Type check
587 default: // Bogus type not in lattice
588 typerr(t);
589 return Type::BOTTOM;
591 case Bottom: // Ye Olde Default
592 return t;
594 case FloatTop:
595 if( _base == FloatTop ) return this;
596 case FloatBot: // Float
597 if( _base == FloatBot || _base == FloatTop ) return FLOAT;
598 if( _base == DoubleTop || _base == DoubleBot ) return Type::BOTTOM;
599 typerr(t);
600 return Type::BOTTOM;
602 case DoubleTop:
603 if( _base == DoubleTop ) return this;
604 case DoubleBot: // Double
605 if( _base == DoubleBot || _base == DoubleTop ) return DOUBLE;
606 if( _base == FloatTop || _base == FloatBot ) return Type::BOTTOM;
607 typerr(t);
608 return Type::BOTTOM;
610 // These next few cases must match exactly or it is a compile-time error.
611 case Control: // Control of code
612 case Abio: // State of world outside of program
613 case Memory:
614 if( _base == t->_base ) return this;
615 typerr(t);
616 return Type::BOTTOM;
618 case Top: // Top of the lattice
619 return this;
620 }
622 // The type is unchanged
623 return this;
624 }
626 //-----------------------------filter------------------------------------------
627 const Type *Type::filter( const Type *kills ) const {
628 const Type* ft = join(kills);
629 if (ft->empty())
630 return Type::TOP; // Canonical empty value
631 return ft;
632 }
634 //------------------------------xdual------------------------------------------
635 // Compute dual right now.
636 const Type::TYPES Type::dual_type[Type::lastype] = {
637 Bad, // Bad
638 Control, // Control
639 Bottom, // Top
640 Bad, // Int - handled in v-call
641 Bad, // Long - handled in v-call
642 Half, // Half
643 Bad, // NarrowOop - handled in v-call
645 Bad, // Tuple - handled in v-call
646 Bad, // Array - handled in v-call
648 Bad, // AnyPtr - handled in v-call
649 Bad, // RawPtr - handled in v-call
650 Bad, // OopPtr - handled in v-call
651 Bad, // InstPtr - handled in v-call
652 Bad, // AryPtr - handled in v-call
653 Bad, // KlassPtr - handled in v-call
655 Bad, // Function - handled in v-call
656 Abio, // Abio
657 Return_Address,// Return_Address
658 Memory, // Memory
659 FloatBot, // FloatTop
660 FloatCon, // FloatCon
661 FloatTop, // FloatBot
662 DoubleBot, // DoubleTop
663 DoubleCon, // DoubleCon
664 DoubleTop, // DoubleBot
665 Top // Bottom
666 };
668 const Type *Type::xdual() const {
669 // Note: the base() accessor asserts the sanity of _base.
670 assert(dual_type[base()] != Bad, "implement with v-call");
671 return new Type(dual_type[_base]);
672 }
674 //------------------------------has_memory-------------------------------------
675 bool Type::has_memory() const {
676 Type::TYPES tx = base();
677 if (tx == Memory) return true;
678 if (tx == Tuple) {
679 const TypeTuple *t = is_tuple();
680 for (uint i=0; i < t->cnt(); i++) {
681 tx = t->field_at(i)->base();
682 if (tx == Memory) return true;
683 }
684 }
685 return false;
686 }
688 #ifndef PRODUCT
689 //------------------------------dump2------------------------------------------
690 void Type::dump2( Dict &d, uint depth, outputStream *st ) const {
691 st->print(msg[_base]);
692 }
694 //------------------------------dump-------------------------------------------
695 void Type::dump_on(outputStream *st) const {
696 ResourceMark rm;
697 Dict d(cmpkey,hashkey); // Stop recursive type dumping
698 dump2(d,1, st);
699 if (is_ptr_to_narrowoop()) {
700 st->print(" [narrow]");
701 }
702 }
704 //------------------------------data-------------------------------------------
705 const char * const Type::msg[Type::lastype] = {
706 "bad","control","top","int:","long:","half", "narrowoop:",
707 "tuple:", "aryptr",
708 "anyptr:", "rawptr:", "java:", "inst:", "ary:", "klass:",
709 "func", "abIO", "return_address", "memory",
710 "float_top", "ftcon:", "float",
711 "double_top", "dblcon:", "double",
712 "bottom"
713 };
714 #endif
716 //------------------------------singleton--------------------------------------
717 // TRUE if Type is a singleton type, FALSE otherwise. Singletons are simple
718 // constants (Ldi nodes). Singletons are integer, float or double constants.
719 bool Type::singleton(void) const {
720 return _base == Top || _base == Half;
721 }
723 //------------------------------empty------------------------------------------
724 // TRUE if Type is a type with no values, FALSE otherwise.
725 bool Type::empty(void) const {
726 switch (_base) {
727 case DoubleTop:
728 case FloatTop:
729 case Top:
730 return true;
732 case Half:
733 case Abio:
734 case Return_Address:
735 case Memory:
736 case Bottom:
737 case FloatBot:
738 case DoubleBot:
739 return false; // never a singleton, therefore never empty
740 }
742 ShouldNotReachHere();
743 return false;
744 }
746 //------------------------------dump_stats-------------------------------------
747 // Dump collected statistics to stderr
748 #ifndef PRODUCT
749 void Type::dump_stats() {
750 tty->print("Types made: %d\n", type_dict()->Size());
751 }
752 #endif
754 //------------------------------typerr-----------------------------------------
755 void Type::typerr( const Type *t ) const {
756 #ifndef PRODUCT
757 tty->print("\nError mixing types: ");
758 dump();
759 tty->print(" and ");
760 t->dump();
761 tty->print("\n");
762 #endif
763 ShouldNotReachHere();
764 }
766 //------------------------------isa_oop_ptr------------------------------------
767 // Return true if type is an oop pointer type. False for raw pointers.
768 static char isa_oop_ptr_tbl[Type::lastype] = {
769 0,0,0,0,0,0,0/*narrowoop*/,0/*tuple*/, 0/*ary*/,
770 0/*anyptr*/,0/*rawptr*/,1/*OopPtr*/,1/*InstPtr*/,1/*AryPtr*/,1/*KlassPtr*/,
771 0/*func*/,0,0/*return_address*/,0,
772 /*floats*/0,0,0, /*doubles*/0,0,0,
773 0
774 };
775 bool Type::isa_oop_ptr() const {
776 return isa_oop_ptr_tbl[_base] != 0;
777 }
779 //------------------------------dump_stats-------------------------------------
780 // // Check that arrays match type enum
781 #ifndef PRODUCT
782 void Type::verify_lastype() {
783 // Check that arrays match enumeration
784 assert( Type::dual_type [Type::lastype - 1] == Type::Top, "did not update array");
785 assert( strcmp(Type::msg [Type::lastype - 1],"bottom") == 0, "did not update array");
786 // assert( PhiNode::tbl [Type::lastype - 1] == NULL, "did not update array");
787 assert( Matcher::base2reg[Type::lastype - 1] == 0, "did not update array");
788 assert( isa_oop_ptr_tbl [Type::lastype - 1] == (char)0, "did not update array");
789 }
790 #endif
792 //=============================================================================
793 // Convenience common pre-built types.
794 const TypeF *TypeF::ZERO; // Floating point zero
795 const TypeF *TypeF::ONE; // Floating point one
797 //------------------------------make-------------------------------------------
798 // Create a float constant
799 const TypeF *TypeF::make(float f) {
800 return (TypeF*)(new TypeF(f))->hashcons();
801 }
803 //------------------------------meet-------------------------------------------
804 // Compute the MEET of two types. It returns a new Type object.
805 const Type *TypeF::xmeet( const Type *t ) const {
806 // Perform a fast test for common case; meeting the same types together.
807 if( this == t ) return this; // Meeting same type-rep?
809 // Current "this->_base" is FloatCon
810 switch (t->base()) { // Switch on original type
811 case AnyPtr: // Mixing with oops happens when javac
812 case RawPtr: // reuses local variables
813 case OopPtr:
814 case InstPtr:
815 case KlassPtr:
816 case AryPtr:
817 case NarrowOop:
818 case Int:
819 case Long:
820 case DoubleTop:
821 case DoubleCon:
822 case DoubleBot:
823 case Bottom: // Ye Olde Default
824 return Type::BOTTOM;
826 case FloatBot:
827 return t;
829 default: // All else is a mistake
830 typerr(t);
832 case FloatCon: // Float-constant vs Float-constant?
833 if( jint_cast(_f) != jint_cast(t->getf()) ) // unequal constants?
834 // must compare bitwise as positive zero, negative zero and NaN have
835 // all the same representation in C++
836 return FLOAT; // Return generic float
837 // Equal constants
838 case Top:
839 case FloatTop:
840 break; // Return the float constant
841 }
842 return this; // Return the float constant
843 }
845 //------------------------------xdual------------------------------------------
846 // Dual: symmetric
847 const Type *TypeF::xdual() const {
848 return this;
849 }
851 //------------------------------eq---------------------------------------------
852 // Structural equality check for Type representations
853 bool TypeF::eq( const Type *t ) const {
854 if( g_isnan(_f) ||
855 g_isnan(t->getf()) ) {
856 // One or both are NANs. If both are NANs return true, else false.
857 return (g_isnan(_f) && g_isnan(t->getf()));
858 }
859 if (_f == t->getf()) {
860 // (NaN is impossible at this point, since it is not equal even to itself)
861 if (_f == 0.0) {
862 // difference between positive and negative zero
863 if (jint_cast(_f) != jint_cast(t->getf())) return false;
864 }
865 return true;
866 }
867 return false;
868 }
870 //------------------------------hash-------------------------------------------
871 // Type-specific hashing function.
872 int TypeF::hash(void) const {
873 return *(int*)(&_f);
874 }
876 //------------------------------is_finite--------------------------------------
877 // Has a finite value
878 bool TypeF::is_finite() const {
879 return g_isfinite(getf()) != 0;
880 }
882 //------------------------------is_nan-----------------------------------------
883 // Is not a number (NaN)
884 bool TypeF::is_nan() const {
885 return g_isnan(getf()) != 0;
886 }
888 //------------------------------dump2------------------------------------------
889 // Dump float constant Type
890 #ifndef PRODUCT
891 void TypeF::dump2( Dict &d, uint depth, outputStream *st ) const {
892 Type::dump2(d,depth, st);
893 st->print("%f", _f);
894 }
895 #endif
897 //------------------------------singleton--------------------------------------
898 // TRUE if Type is a singleton type, FALSE otherwise. Singletons are simple
899 // constants (Ldi nodes). Singletons are integer, float or double constants
900 // or a single symbol.
901 bool TypeF::singleton(void) const {
902 return true; // Always a singleton
903 }
905 bool TypeF::empty(void) const {
906 return false; // always exactly a singleton
907 }
909 //=============================================================================
910 // Convenience common pre-built types.
911 const TypeD *TypeD::ZERO; // Floating point zero
912 const TypeD *TypeD::ONE; // Floating point one
914 //------------------------------make-------------------------------------------
915 const TypeD *TypeD::make(double d) {
916 return (TypeD*)(new TypeD(d))->hashcons();
917 }
919 //------------------------------meet-------------------------------------------
920 // Compute the MEET of two types. It returns a new Type object.
921 const Type *TypeD::xmeet( const Type *t ) const {
922 // Perform a fast test for common case; meeting the same types together.
923 if( this == t ) return this; // Meeting same type-rep?
925 // Current "this->_base" is DoubleCon
926 switch (t->base()) { // Switch on original type
927 case AnyPtr: // Mixing with oops happens when javac
928 case RawPtr: // reuses local variables
929 case OopPtr:
930 case InstPtr:
931 case KlassPtr:
932 case AryPtr:
933 case NarrowOop:
934 case Int:
935 case Long:
936 case FloatTop:
937 case FloatCon:
938 case FloatBot:
939 case Bottom: // Ye Olde Default
940 return Type::BOTTOM;
942 case DoubleBot:
943 return t;
945 default: // All else is a mistake
946 typerr(t);
948 case DoubleCon: // Double-constant vs Double-constant?
949 if( jlong_cast(_d) != jlong_cast(t->getd()) ) // unequal constants? (see comment in TypeF::xmeet)
950 return DOUBLE; // Return generic double
951 case Top:
952 case DoubleTop:
953 break;
954 }
955 return this; // Return the double constant
956 }
958 //------------------------------xdual------------------------------------------
959 // Dual: symmetric
960 const Type *TypeD::xdual() const {
961 return this;
962 }
964 //------------------------------eq---------------------------------------------
965 // Structural equality check for Type representations
966 bool TypeD::eq( const Type *t ) const {
967 if( g_isnan(_d) ||
968 g_isnan(t->getd()) ) {
969 // One or both are NANs. If both are NANs return true, else false.
970 return (g_isnan(_d) && g_isnan(t->getd()));
971 }
972 if (_d == t->getd()) {
973 // (NaN is impossible at this point, since it is not equal even to itself)
974 if (_d == 0.0) {
975 // difference between positive and negative zero
976 if (jlong_cast(_d) != jlong_cast(t->getd())) return false;
977 }
978 return true;
979 }
980 return false;
981 }
983 //------------------------------hash-------------------------------------------
984 // Type-specific hashing function.
985 int TypeD::hash(void) const {
986 return *(int*)(&_d);
987 }
989 //------------------------------is_finite--------------------------------------
990 // Has a finite value
991 bool TypeD::is_finite() const {
992 return g_isfinite(getd()) != 0;
993 }
995 //------------------------------is_nan-----------------------------------------
996 // Is not a number (NaN)
997 bool TypeD::is_nan() const {
998 return g_isnan(getd()) != 0;
999 }
1001 //------------------------------dump2------------------------------------------
1002 // Dump double constant Type
1003 #ifndef PRODUCT
1004 void TypeD::dump2( Dict &d, uint depth, outputStream *st ) const {
1005 Type::dump2(d,depth,st);
1006 st->print("%f", _d);
1007 }
1008 #endif
1010 //------------------------------singleton--------------------------------------
1011 // TRUE if Type is a singleton type, FALSE otherwise. Singletons are simple
1012 // constants (Ldi nodes). Singletons are integer, float or double constants
1013 // or a single symbol.
1014 bool TypeD::singleton(void) const {
1015 return true; // Always a singleton
1016 }
1018 bool TypeD::empty(void) const {
1019 return false; // always exactly a singleton
1020 }
1022 //=============================================================================
1023 // Convience common pre-built types.
1024 const TypeInt *TypeInt::MINUS_1;// -1
1025 const TypeInt *TypeInt::ZERO; // 0
1026 const TypeInt *TypeInt::ONE; // 1
1027 const TypeInt *TypeInt::BOOL; // 0 or 1, FALSE or TRUE.
1028 const TypeInt *TypeInt::CC; // -1,0 or 1, condition codes
1029 const TypeInt *TypeInt::CC_LT; // [-1] == MINUS_1
1030 const TypeInt *TypeInt::CC_GT; // [1] == ONE
1031 const TypeInt *TypeInt::CC_EQ; // [0] == ZERO
1032 const TypeInt *TypeInt::CC_LE; // [-1,0]
1033 const TypeInt *TypeInt::CC_GE; // [0,1] == BOOL (!)
1034 const TypeInt *TypeInt::BYTE; // Bytes, -128 to 127
1035 const TypeInt *TypeInt::UBYTE; // Unsigned Bytes, 0 to 255
1036 const TypeInt *TypeInt::CHAR; // Java chars, 0-65535
1037 const TypeInt *TypeInt::SHORT; // Java shorts, -32768-32767
1038 const TypeInt *TypeInt::POS; // Positive 32-bit integers or zero
1039 const TypeInt *TypeInt::POS1; // Positive 32-bit integers
1040 const TypeInt *TypeInt::INT; // 32-bit integers
1041 const TypeInt *TypeInt::SYMINT; // symmetric range [-max_jint..max_jint]
1043 //------------------------------TypeInt----------------------------------------
1044 TypeInt::TypeInt( jint lo, jint hi, int w ) : Type(Int), _lo(lo), _hi(hi), _widen(w) {
1045 }
1047 //------------------------------make-------------------------------------------
1048 const TypeInt *TypeInt::make( jint lo ) {
1049 return (TypeInt*)(new TypeInt(lo,lo,WidenMin))->hashcons();
1050 }
1052 #define SMALLINT ((juint)3) // a value too insignificant to consider widening
1054 const TypeInt *TypeInt::make( jint lo, jint hi, int w ) {
1055 // Certain normalizations keep us sane when comparing types.
1056 // The 'SMALLINT' covers constants and also CC and its relatives.
1057 assert(CC == NULL || (juint)(CC->_hi - CC->_lo) <= SMALLINT, "CC is truly small");
1058 if (lo <= hi) {
1059 if ((juint)(hi - lo) <= SMALLINT) w = Type::WidenMin;
1060 if ((juint)(hi - lo) >= max_juint) w = Type::WidenMax; // plain int
1061 }
1062 return (TypeInt*)(new TypeInt(lo,hi,w))->hashcons();
1063 }
1065 //------------------------------meet-------------------------------------------
1066 // Compute the MEET of two types. It returns a new Type representation object
1067 // with reference count equal to the number of Types pointing at it.
1068 // Caller should wrap a Types around it.
1069 const Type *TypeInt::xmeet( const Type *t ) const {
1070 // Perform a fast test for common case; meeting the same types together.
1071 if( this == t ) return this; // Meeting same type?
1073 // Currently "this->_base" is a TypeInt
1074 switch (t->base()) { // Switch on original type
1075 case AnyPtr: // Mixing with oops happens when javac
1076 case RawPtr: // reuses local variables
1077 case OopPtr:
1078 case InstPtr:
1079 case KlassPtr:
1080 case AryPtr:
1081 case NarrowOop:
1082 case Long:
1083 case FloatTop:
1084 case FloatCon:
1085 case FloatBot:
1086 case DoubleTop:
1087 case DoubleCon:
1088 case DoubleBot:
1089 case Bottom: // Ye Olde Default
1090 return Type::BOTTOM;
1091 default: // All else is a mistake
1092 typerr(t);
1093 case Top: // No change
1094 return this;
1095 case Int: // Int vs Int?
1096 break;
1097 }
1099 // Expand covered set
1100 const TypeInt *r = t->is_int();
1101 // (Avoid TypeInt::make, to avoid the argument normalizations it enforces.)
1102 return (new TypeInt( MIN2(_lo,r->_lo), MAX2(_hi,r->_hi), MAX2(_widen,r->_widen) ))->hashcons();
1103 }
1105 //------------------------------xdual------------------------------------------
1106 // Dual: reverse hi & lo; flip widen
1107 const Type *TypeInt::xdual() const {
1108 return new TypeInt(_hi,_lo,WidenMax-_widen);
1109 }
1111 //------------------------------widen------------------------------------------
1112 // Only happens for optimistic top-down optimizations.
1113 const Type *TypeInt::widen( const Type *old ) const {
1114 // Coming from TOP or such; no widening
1115 if( old->base() != Int ) return this;
1116 const TypeInt *ot = old->is_int();
1118 // If new guy is equal to old guy, no widening
1119 if( _lo == ot->_lo && _hi == ot->_hi )
1120 return old;
1122 // If new guy contains old, then we widened
1123 if( _lo <= ot->_lo && _hi >= ot->_hi ) {
1124 // New contains old
1125 // If new guy is already wider than old, no widening
1126 if( _widen > ot->_widen ) return this;
1127 // If old guy was a constant, do not bother
1128 if (ot->_lo == ot->_hi) return this;
1129 // Now widen new guy.
1130 // Check for widening too far
1131 if (_widen == WidenMax) {
1132 if (min_jint < _lo && _hi < max_jint) {
1133 // If neither endpoint is extremal yet, push out the endpoint
1134 // which is closer to its respective limit.
1135 if (_lo >= 0 || // easy common case
1136 (juint)(_lo - min_jint) >= (juint)(max_jint - _hi)) {
1137 // Try to widen to an unsigned range type of 31 bits:
1138 return make(_lo, max_jint, WidenMax);
1139 } else {
1140 return make(min_jint, _hi, WidenMax);
1141 }
1142 }
1143 return TypeInt::INT;
1144 }
1145 // Returned widened new guy
1146 return make(_lo,_hi,_widen+1);
1147 }
1149 // If old guy contains new, then we probably widened too far & dropped to
1150 // bottom. Return the wider fellow.
1151 if ( ot->_lo <= _lo && ot->_hi >= _hi )
1152 return old;
1154 //fatal("Integer value range is not subset");
1155 //return this;
1156 return TypeInt::INT;
1157 }
1159 //------------------------------narrow---------------------------------------
1160 // Only happens for pessimistic optimizations.
1161 const Type *TypeInt::narrow( const Type *old ) const {
1162 if (_lo >= _hi) return this; // already narrow enough
1163 if (old == NULL) return this;
1164 const TypeInt* ot = old->isa_int();
1165 if (ot == NULL) return this;
1166 jint olo = ot->_lo;
1167 jint ohi = ot->_hi;
1169 // If new guy is equal to old guy, no narrowing
1170 if (_lo == olo && _hi == ohi) return old;
1172 // If old guy was maximum range, allow the narrowing
1173 if (olo == min_jint && ohi == max_jint) return this;
1175 if (_lo < olo || _hi > ohi)
1176 return this; // doesn't narrow; pretty wierd
1178 // The new type narrows the old type, so look for a "death march".
1179 // See comments on PhaseTransform::saturate.
1180 juint nrange = _hi - _lo;
1181 juint orange = ohi - olo;
1182 if (nrange < max_juint - 1 && nrange > (orange >> 1) + (SMALLINT*2)) {
1183 // Use the new type only if the range shrinks a lot.
1184 // We do not want the optimizer computing 2^31 point by point.
1185 return old;
1186 }
1188 return this;
1189 }
1191 //-----------------------------filter------------------------------------------
1192 const Type *TypeInt::filter( const Type *kills ) const {
1193 const TypeInt* ft = join(kills)->isa_int();
1194 if (ft == NULL || ft->_lo > ft->_hi)
1195 return Type::TOP; // Canonical empty value
1196 if (ft->_widen < this->_widen) {
1197 // Do not allow the value of kill->_widen to affect the outcome.
1198 // The widen bits must be allowed to run freely through the graph.
1199 ft = TypeInt::make(ft->_lo, ft->_hi, this->_widen);
1200 }
1201 return ft;
1202 }
1204 //------------------------------eq---------------------------------------------
1205 // Structural equality check for Type representations
1206 bool TypeInt::eq( const Type *t ) const {
1207 const TypeInt *r = t->is_int(); // Handy access
1208 return r->_lo == _lo && r->_hi == _hi && r->_widen == _widen;
1209 }
1211 //------------------------------hash-------------------------------------------
1212 // Type-specific hashing function.
1213 int TypeInt::hash(void) const {
1214 return _lo+_hi+_widen+(int)Type::Int;
1215 }
1217 //------------------------------is_finite--------------------------------------
1218 // Has a finite value
1219 bool TypeInt::is_finite() const {
1220 return true;
1221 }
1223 //------------------------------dump2------------------------------------------
1224 // Dump TypeInt
1225 #ifndef PRODUCT
1226 static const char* intname(char* buf, jint n) {
1227 if (n == min_jint)
1228 return "min";
1229 else if (n < min_jint + 10000)
1230 sprintf(buf, "min+" INT32_FORMAT, n - min_jint);
1231 else if (n == max_jint)
1232 return "max";
1233 else if (n > max_jint - 10000)
1234 sprintf(buf, "max-" INT32_FORMAT, max_jint - n);
1235 else
1236 sprintf(buf, INT32_FORMAT, n);
1237 return buf;
1238 }
1240 void TypeInt::dump2( Dict &d, uint depth, outputStream *st ) const {
1241 char buf[40], buf2[40];
1242 if (_lo == min_jint && _hi == max_jint)
1243 st->print("int");
1244 else if (is_con())
1245 st->print("int:%s", intname(buf, get_con()));
1246 else if (_lo == BOOL->_lo && _hi == BOOL->_hi)
1247 st->print("bool");
1248 else if (_lo == BYTE->_lo && _hi == BYTE->_hi)
1249 st->print("byte");
1250 else if (_lo == CHAR->_lo && _hi == CHAR->_hi)
1251 st->print("char");
1252 else if (_lo == SHORT->_lo && _hi == SHORT->_hi)
1253 st->print("short");
1254 else if (_hi == max_jint)
1255 st->print("int:>=%s", intname(buf, _lo));
1256 else if (_lo == min_jint)
1257 st->print("int:<=%s", intname(buf, _hi));
1258 else
1259 st->print("int:%s..%s", intname(buf, _lo), intname(buf2, _hi));
1261 if (_widen != 0 && this != TypeInt::INT)
1262 st->print(":%.*s", _widen, "wwww");
1263 }
1264 #endif
1266 //------------------------------singleton--------------------------------------
1267 // TRUE if Type is a singleton type, FALSE otherwise. Singletons are simple
1268 // constants.
1269 bool TypeInt::singleton(void) const {
1270 return _lo >= _hi;
1271 }
1273 bool TypeInt::empty(void) const {
1274 return _lo > _hi;
1275 }
1277 //=============================================================================
1278 // Convenience common pre-built types.
1279 const TypeLong *TypeLong::MINUS_1;// -1
1280 const TypeLong *TypeLong::ZERO; // 0
1281 const TypeLong *TypeLong::ONE; // 1
1282 const TypeLong *TypeLong::POS; // >=0
1283 const TypeLong *TypeLong::LONG; // 64-bit integers
1284 const TypeLong *TypeLong::INT; // 32-bit subrange
1285 const TypeLong *TypeLong::UINT; // 32-bit unsigned subrange
1287 //------------------------------TypeLong---------------------------------------
1288 TypeLong::TypeLong( jlong lo, jlong hi, int w ) : Type(Long), _lo(lo), _hi(hi), _widen(w) {
1289 }
1291 //------------------------------make-------------------------------------------
1292 const TypeLong *TypeLong::make( jlong lo ) {
1293 return (TypeLong*)(new TypeLong(lo,lo,WidenMin))->hashcons();
1294 }
1296 const TypeLong *TypeLong::make( jlong lo, jlong hi, int w ) {
1297 // Certain normalizations keep us sane when comparing types.
1298 // The '1' covers constants.
1299 if (lo <= hi) {
1300 if ((julong)(hi - lo) <= SMALLINT) w = Type::WidenMin;
1301 if ((julong)(hi - lo) >= max_julong) w = Type::WidenMax; // plain long
1302 }
1303 return (TypeLong*)(new TypeLong(lo,hi,w))->hashcons();
1304 }
1307 //------------------------------meet-------------------------------------------
1308 // Compute the MEET of two types. It returns a new Type representation object
1309 // with reference count equal to the number of Types pointing at it.
1310 // Caller should wrap a Types around it.
1311 const Type *TypeLong::xmeet( const Type *t ) const {
1312 // Perform a fast test for common case; meeting the same types together.
1313 if( this == t ) return this; // Meeting same type?
1315 // Currently "this->_base" is a TypeLong
1316 switch (t->base()) { // Switch on original type
1317 case AnyPtr: // Mixing with oops happens when javac
1318 case RawPtr: // reuses local variables
1319 case OopPtr:
1320 case InstPtr:
1321 case KlassPtr:
1322 case AryPtr:
1323 case NarrowOop:
1324 case Int:
1325 case FloatTop:
1326 case FloatCon:
1327 case FloatBot:
1328 case DoubleTop:
1329 case DoubleCon:
1330 case DoubleBot:
1331 case Bottom: // Ye Olde Default
1332 return Type::BOTTOM;
1333 default: // All else is a mistake
1334 typerr(t);
1335 case Top: // No change
1336 return this;
1337 case Long: // Long vs Long?
1338 break;
1339 }
1341 // Expand covered set
1342 const TypeLong *r = t->is_long(); // Turn into a TypeLong
1343 // (Avoid TypeLong::make, to avoid the argument normalizations it enforces.)
1344 return (new TypeLong( MIN2(_lo,r->_lo), MAX2(_hi,r->_hi), MAX2(_widen,r->_widen) ))->hashcons();
1345 }
1347 //------------------------------xdual------------------------------------------
1348 // Dual: reverse hi & lo; flip widen
1349 const Type *TypeLong::xdual() const {
1350 return new TypeLong(_hi,_lo,WidenMax-_widen);
1351 }
1353 //------------------------------widen------------------------------------------
1354 // Only happens for optimistic top-down optimizations.
1355 const Type *TypeLong::widen( const Type *old ) const {
1356 // Coming from TOP or such; no widening
1357 if( old->base() != Long ) return this;
1358 const TypeLong *ot = old->is_long();
1360 // If new guy is equal to old guy, no widening
1361 if( _lo == ot->_lo && _hi == ot->_hi )
1362 return old;
1364 // If new guy contains old, then we widened
1365 if( _lo <= ot->_lo && _hi >= ot->_hi ) {
1366 // New contains old
1367 // If new guy is already wider than old, no widening
1368 if( _widen > ot->_widen ) return this;
1369 // If old guy was a constant, do not bother
1370 if (ot->_lo == ot->_hi) return this;
1371 // Now widen new guy.
1372 // Check for widening too far
1373 if (_widen == WidenMax) {
1374 if (min_jlong < _lo && _hi < max_jlong) {
1375 // If neither endpoint is extremal yet, push out the endpoint
1376 // which is closer to its respective limit.
1377 if (_lo >= 0 || // easy common case
1378 (julong)(_lo - min_jlong) >= (julong)(max_jlong - _hi)) {
1379 // Try to widen to an unsigned range type of 32/63 bits:
1380 if (_hi < max_juint)
1381 return make(_lo, max_juint, WidenMax);
1382 else
1383 return make(_lo, max_jlong, WidenMax);
1384 } else {
1385 return make(min_jlong, _hi, WidenMax);
1386 }
1387 }
1388 return TypeLong::LONG;
1389 }
1390 // Returned widened new guy
1391 return make(_lo,_hi,_widen+1);
1392 }
1394 // If old guy contains new, then we probably widened too far & dropped to
1395 // bottom. Return the wider fellow.
1396 if ( ot->_lo <= _lo && ot->_hi >= _hi )
1397 return old;
1399 // fatal("Long value range is not subset");
1400 // return this;
1401 return TypeLong::LONG;
1402 }
1404 //------------------------------narrow----------------------------------------
1405 // Only happens for pessimistic optimizations.
1406 const Type *TypeLong::narrow( const Type *old ) const {
1407 if (_lo >= _hi) return this; // already narrow enough
1408 if (old == NULL) return this;
1409 const TypeLong* ot = old->isa_long();
1410 if (ot == NULL) return this;
1411 jlong olo = ot->_lo;
1412 jlong ohi = ot->_hi;
1414 // If new guy is equal to old guy, no narrowing
1415 if (_lo == olo && _hi == ohi) return old;
1417 // If old guy was maximum range, allow the narrowing
1418 if (olo == min_jlong && ohi == max_jlong) return this;
1420 if (_lo < olo || _hi > ohi)
1421 return this; // doesn't narrow; pretty wierd
1423 // The new type narrows the old type, so look for a "death march".
1424 // See comments on PhaseTransform::saturate.
1425 julong nrange = _hi - _lo;
1426 julong orange = ohi - olo;
1427 if (nrange < max_julong - 1 && nrange > (orange >> 1) + (SMALLINT*2)) {
1428 // Use the new type only if the range shrinks a lot.
1429 // We do not want the optimizer computing 2^31 point by point.
1430 return old;
1431 }
1433 return this;
1434 }
1436 //-----------------------------filter------------------------------------------
1437 const Type *TypeLong::filter( const Type *kills ) const {
1438 const TypeLong* ft = join(kills)->isa_long();
1439 if (ft == NULL || ft->_lo > ft->_hi)
1440 return Type::TOP; // Canonical empty value
1441 if (ft->_widen < this->_widen) {
1442 // Do not allow the value of kill->_widen to affect the outcome.
1443 // The widen bits must be allowed to run freely through the graph.
1444 ft = TypeLong::make(ft->_lo, ft->_hi, this->_widen);
1445 }
1446 return ft;
1447 }
1449 //------------------------------eq---------------------------------------------
1450 // Structural equality check for Type representations
1451 bool TypeLong::eq( const Type *t ) const {
1452 const TypeLong *r = t->is_long(); // Handy access
1453 return r->_lo == _lo && r->_hi == _hi && r->_widen == _widen;
1454 }
1456 //------------------------------hash-------------------------------------------
1457 // Type-specific hashing function.
1458 int TypeLong::hash(void) const {
1459 return (int)(_lo+_hi+_widen+(int)Type::Long);
1460 }
1462 //------------------------------is_finite--------------------------------------
1463 // Has a finite value
1464 bool TypeLong::is_finite() const {
1465 return true;
1466 }
1468 //------------------------------dump2------------------------------------------
1469 // Dump TypeLong
1470 #ifndef PRODUCT
1471 static const char* longnamenear(jlong x, const char* xname, char* buf, jlong n) {
1472 if (n > x) {
1473 if (n >= x + 10000) return NULL;
1474 sprintf(buf, "%s+" INT64_FORMAT, xname, n - x);
1475 } else if (n < x) {
1476 if (n <= x - 10000) return NULL;
1477 sprintf(buf, "%s-" INT64_FORMAT, xname, x - n);
1478 } else {
1479 return xname;
1480 }
1481 return buf;
1482 }
1484 static const char* longname(char* buf, jlong n) {
1485 const char* str;
1486 if (n == min_jlong)
1487 return "min";
1488 else if (n < min_jlong + 10000)
1489 sprintf(buf, "min+" INT64_FORMAT, n - min_jlong);
1490 else if (n == max_jlong)
1491 return "max";
1492 else if (n > max_jlong - 10000)
1493 sprintf(buf, "max-" INT64_FORMAT, max_jlong - n);
1494 else if ((str = longnamenear(max_juint, "maxuint", buf, n)) != NULL)
1495 return str;
1496 else if ((str = longnamenear(max_jint, "maxint", buf, n)) != NULL)
1497 return str;
1498 else if ((str = longnamenear(min_jint, "minint", buf, n)) != NULL)
1499 return str;
1500 else
1501 sprintf(buf, INT64_FORMAT, n);
1502 return buf;
1503 }
1505 void TypeLong::dump2( Dict &d, uint depth, outputStream *st ) const {
1506 char buf[80], buf2[80];
1507 if (_lo == min_jlong && _hi == max_jlong)
1508 st->print("long");
1509 else if (is_con())
1510 st->print("long:%s", longname(buf, get_con()));
1511 else if (_hi == max_jlong)
1512 st->print("long:>=%s", longname(buf, _lo));
1513 else if (_lo == min_jlong)
1514 st->print("long:<=%s", longname(buf, _hi));
1515 else
1516 st->print("long:%s..%s", longname(buf, _lo), longname(buf2, _hi));
1518 if (_widen != 0 && this != TypeLong::LONG)
1519 st->print(":%.*s", _widen, "wwww");
1520 }
1521 #endif
1523 //------------------------------singleton--------------------------------------
1524 // TRUE if Type is a singleton type, FALSE otherwise. Singletons are simple
1525 // constants
1526 bool TypeLong::singleton(void) const {
1527 return _lo >= _hi;
1528 }
1530 bool TypeLong::empty(void) const {
1531 return _lo > _hi;
1532 }
1534 //=============================================================================
1535 // Convenience common pre-built types.
1536 const TypeTuple *TypeTuple::IFBOTH; // Return both arms of IF as reachable
1537 const TypeTuple *TypeTuple::IFFALSE;
1538 const TypeTuple *TypeTuple::IFTRUE;
1539 const TypeTuple *TypeTuple::IFNEITHER;
1540 const TypeTuple *TypeTuple::LOOPBODY;
1541 const TypeTuple *TypeTuple::MEMBAR;
1542 const TypeTuple *TypeTuple::STORECONDITIONAL;
1543 const TypeTuple *TypeTuple::START_I2C;
1544 const TypeTuple *TypeTuple::INT_PAIR;
1545 const TypeTuple *TypeTuple::LONG_PAIR;
1548 //------------------------------make-------------------------------------------
1549 // Make a TypeTuple from the range of a method signature
1550 const TypeTuple *TypeTuple::make_range(ciSignature* sig) {
1551 ciType* return_type = sig->return_type();
1552 uint total_fields = TypeFunc::Parms + return_type->size();
1553 const Type **field_array = fields(total_fields);
1554 switch (return_type->basic_type()) {
1555 case T_LONG:
1556 field_array[TypeFunc::Parms] = TypeLong::LONG;
1557 field_array[TypeFunc::Parms+1] = Type::HALF;
1558 break;
1559 case T_DOUBLE:
1560 field_array[TypeFunc::Parms] = Type::DOUBLE;
1561 field_array[TypeFunc::Parms+1] = Type::HALF;
1562 break;
1563 case T_OBJECT:
1564 case T_ARRAY:
1565 case T_BOOLEAN:
1566 case T_CHAR:
1567 case T_FLOAT:
1568 case T_BYTE:
1569 case T_SHORT:
1570 case T_INT:
1571 field_array[TypeFunc::Parms] = get_const_type(return_type);
1572 break;
1573 case T_VOID:
1574 break;
1575 default:
1576 ShouldNotReachHere();
1577 }
1578 return (TypeTuple*)(new TypeTuple(total_fields,field_array))->hashcons();
1579 }
1581 // Make a TypeTuple from the domain of a method signature
1582 const TypeTuple *TypeTuple::make_domain(ciInstanceKlass* recv, ciSignature* sig) {
1583 uint total_fields = TypeFunc::Parms + sig->size();
1585 uint pos = TypeFunc::Parms;
1586 const Type **field_array;
1587 if (recv != NULL) {
1588 total_fields++;
1589 field_array = fields(total_fields);
1590 // Use get_const_type here because it respects UseUniqueSubclasses:
1591 field_array[pos++] = get_const_type(recv)->join(TypePtr::NOTNULL);
1592 } else {
1593 field_array = fields(total_fields);
1594 }
1596 int i = 0;
1597 while (pos < total_fields) {
1598 ciType* type = sig->type_at(i);
1600 switch (type->basic_type()) {
1601 case T_LONG:
1602 field_array[pos++] = TypeLong::LONG;
1603 field_array[pos++] = Type::HALF;
1604 break;
1605 case T_DOUBLE:
1606 field_array[pos++] = Type::DOUBLE;
1607 field_array[pos++] = Type::HALF;
1608 break;
1609 case T_OBJECT:
1610 case T_ARRAY:
1611 case T_BOOLEAN:
1612 case T_CHAR:
1613 case T_FLOAT:
1614 case T_BYTE:
1615 case T_SHORT:
1616 case T_INT:
1617 field_array[pos++] = get_const_type(type);
1618 break;
1619 default:
1620 ShouldNotReachHere();
1621 }
1622 i++;
1623 }
1624 return (TypeTuple*)(new TypeTuple(total_fields,field_array))->hashcons();
1625 }
1627 const TypeTuple *TypeTuple::make( uint cnt, const Type **fields ) {
1628 return (TypeTuple*)(new TypeTuple(cnt,fields))->hashcons();
1629 }
1631 //------------------------------fields-----------------------------------------
1632 // Subroutine call type with space allocated for argument types
1633 const Type **TypeTuple::fields( uint arg_cnt ) {
1634 const Type **flds = (const Type **)(Compile::current()->type_arena()->Amalloc_4((TypeFunc::Parms+arg_cnt)*sizeof(Type*) ));
1635 flds[TypeFunc::Control ] = Type::CONTROL;
1636 flds[TypeFunc::I_O ] = Type::ABIO;
1637 flds[TypeFunc::Memory ] = Type::MEMORY;
1638 flds[TypeFunc::FramePtr ] = TypeRawPtr::BOTTOM;
1639 flds[TypeFunc::ReturnAdr] = Type::RETURN_ADDRESS;
1641 return flds;
1642 }
1644 //------------------------------meet-------------------------------------------
1645 // Compute the MEET of two types. It returns a new Type object.
1646 const Type *TypeTuple::xmeet( const Type *t ) const {
1647 // Perform a fast test for common case; meeting the same types together.
1648 if( this == t ) return this; // Meeting same type-rep?
1650 // Current "this->_base" is Tuple
1651 switch (t->base()) { // switch on original type
1653 case Bottom: // Ye Olde Default
1654 return t;
1656 default: // All else is a mistake
1657 typerr(t);
1659 case Tuple: { // Meeting 2 signatures?
1660 const TypeTuple *x = t->is_tuple();
1661 assert( _cnt == x->_cnt, "" );
1662 const Type **fields = (const Type **)(Compile::current()->type_arena()->Amalloc_4( _cnt*sizeof(Type*) ));
1663 for( uint i=0; i<_cnt; i++ )
1664 fields[i] = field_at(i)->xmeet( x->field_at(i) );
1665 return TypeTuple::make(_cnt,fields);
1666 }
1667 case Top:
1668 break;
1669 }
1670 return this; // Return the double constant
1671 }
1673 //------------------------------xdual------------------------------------------
1674 // Dual: compute field-by-field dual
1675 const Type *TypeTuple::xdual() const {
1676 const Type **fields = (const Type **)(Compile::current()->type_arena()->Amalloc_4( _cnt*sizeof(Type*) ));
1677 for( uint i=0; i<_cnt; i++ )
1678 fields[i] = _fields[i]->dual();
1679 return new TypeTuple(_cnt,fields);
1680 }
1682 //------------------------------eq---------------------------------------------
1683 // Structural equality check for Type representations
1684 bool TypeTuple::eq( const Type *t ) const {
1685 const TypeTuple *s = (const TypeTuple *)t;
1686 if (_cnt != s->_cnt) return false; // Unequal field counts
1687 for (uint i = 0; i < _cnt; i++)
1688 if (field_at(i) != s->field_at(i)) // POINTER COMPARE! NO RECURSION!
1689 return false; // Missed
1690 return true;
1691 }
1693 //------------------------------hash-------------------------------------------
1694 // Type-specific hashing function.
1695 int TypeTuple::hash(void) const {
1696 intptr_t sum = _cnt;
1697 for( uint i=0; i<_cnt; i++ )
1698 sum += (intptr_t)_fields[i]; // Hash on pointers directly
1699 return sum;
1700 }
1702 //------------------------------dump2------------------------------------------
1703 // Dump signature Type
1704 #ifndef PRODUCT
1705 void TypeTuple::dump2( Dict &d, uint depth, outputStream *st ) const {
1706 st->print("{");
1707 if( !depth || d[this] ) { // Check for recursive print
1708 st->print("...}");
1709 return;
1710 }
1711 d.Insert((void*)this, (void*)this); // Stop recursion
1712 if( _cnt ) {
1713 uint i;
1714 for( i=0; i<_cnt-1; i++ ) {
1715 st->print("%d:", i);
1716 _fields[i]->dump2(d, depth-1, st);
1717 st->print(", ");
1718 }
1719 st->print("%d:", i);
1720 _fields[i]->dump2(d, depth-1, st);
1721 }
1722 st->print("}");
1723 }
1724 #endif
1726 //------------------------------singleton--------------------------------------
1727 // TRUE if Type is a singleton type, FALSE otherwise. Singletons are simple
1728 // constants (Ldi nodes). Singletons are integer, float or double constants
1729 // or a single symbol.
1730 bool TypeTuple::singleton(void) const {
1731 return false; // Never a singleton
1732 }
1734 bool TypeTuple::empty(void) const {
1735 for( uint i=0; i<_cnt; i++ ) {
1736 if (_fields[i]->empty()) return true;
1737 }
1738 return false;
1739 }
1741 //=============================================================================
1742 // Convenience common pre-built types.
1744 inline const TypeInt* normalize_array_size(const TypeInt* size) {
1745 // Certain normalizations keep us sane when comparing types.
1746 // We do not want arrayOop variables to differ only by the wideness
1747 // of their index types. Pick minimum wideness, since that is the
1748 // forced wideness of small ranges anyway.
1749 if (size->_widen != Type::WidenMin)
1750 return TypeInt::make(size->_lo, size->_hi, Type::WidenMin);
1751 else
1752 return size;
1753 }
1755 //------------------------------make-------------------------------------------
1756 const TypeAry *TypeAry::make( const Type *elem, const TypeInt *size) {
1757 if (UseCompressedOops && elem->isa_oopptr()) {
1758 elem = elem->make_narrowoop();
1759 }
1760 size = normalize_array_size(size);
1761 return (TypeAry*)(new TypeAry(elem,size))->hashcons();
1762 }
1764 //------------------------------meet-------------------------------------------
1765 // Compute the MEET of two types. It returns a new Type object.
1766 const Type *TypeAry::xmeet( const Type *t ) const {
1767 // Perform a fast test for common case; meeting the same types together.
1768 if( this == t ) return this; // Meeting same type-rep?
1770 // Current "this->_base" is Ary
1771 switch (t->base()) { // switch on original type
1773 case Bottom: // Ye Olde Default
1774 return t;
1776 default: // All else is a mistake
1777 typerr(t);
1779 case Array: { // Meeting 2 arrays?
1780 const TypeAry *a = t->is_ary();
1781 return TypeAry::make(_elem->meet(a->_elem),
1782 _size->xmeet(a->_size)->is_int());
1783 }
1784 case Top:
1785 break;
1786 }
1787 return this; // Return the double constant
1788 }
1790 //------------------------------xdual------------------------------------------
1791 // Dual: compute field-by-field dual
1792 const Type *TypeAry::xdual() const {
1793 const TypeInt* size_dual = _size->dual()->is_int();
1794 size_dual = normalize_array_size(size_dual);
1795 return new TypeAry( _elem->dual(), size_dual);
1796 }
1798 //------------------------------eq---------------------------------------------
1799 // Structural equality check for Type representations
1800 bool TypeAry::eq( const Type *t ) const {
1801 const TypeAry *a = (const TypeAry*)t;
1802 return _elem == a->_elem &&
1803 _size == a->_size;
1804 }
1806 //------------------------------hash-------------------------------------------
1807 // Type-specific hashing function.
1808 int TypeAry::hash(void) const {
1809 return (intptr_t)_elem + (intptr_t)_size;
1810 }
1812 //----------------------interface_vs_oop---------------------------------------
1813 #ifdef ASSERT
1814 bool TypeAry::interface_vs_oop(const Type *t) const {
1815 const TypeAry* t_ary = t->is_ary();
1816 if (t_ary) {
1817 return _elem->interface_vs_oop(t_ary->_elem);
1818 }
1819 return false;
1820 }
1821 #endif
1823 //------------------------------dump2------------------------------------------
1824 #ifndef PRODUCT
1825 void TypeAry::dump2( Dict &d, uint depth, outputStream *st ) const {
1826 _elem->dump2(d, depth, st);
1827 st->print("[");
1828 _size->dump2(d, depth, st);
1829 st->print("]");
1830 }
1831 #endif
1833 //------------------------------singleton--------------------------------------
1834 // TRUE if Type is a singleton type, FALSE otherwise. Singletons are simple
1835 // constants (Ldi nodes). Singletons are integer, float or double constants
1836 // or a single symbol.
1837 bool TypeAry::singleton(void) const {
1838 return false; // Never a singleton
1839 }
1841 bool TypeAry::empty(void) const {
1842 return _elem->empty() || _size->empty();
1843 }
1845 //--------------------------ary_must_be_exact----------------------------------
1846 bool TypeAry::ary_must_be_exact() const {
1847 if (!UseExactTypes) return false;
1848 // This logic looks at the element type of an array, and returns true
1849 // if the element type is either a primitive or a final instance class.
1850 // In such cases, an array built on this ary must have no subclasses.
1851 if (_elem == BOTTOM) return false; // general array not exact
1852 if (_elem == TOP ) return false; // inverted general array not exact
1853 const TypeOopPtr* toop = NULL;
1854 if (UseCompressedOops && _elem->isa_narrowoop()) {
1855 toop = _elem->make_ptr()->isa_oopptr();
1856 } else {
1857 toop = _elem->isa_oopptr();
1858 }
1859 if (!toop) return true; // a primitive type, like int
1860 ciKlass* tklass = toop->klass();
1861 if (tklass == NULL) return false; // unloaded class
1862 if (!tklass->is_loaded()) return false; // unloaded class
1863 const TypeInstPtr* tinst;
1864 if (_elem->isa_narrowoop())
1865 tinst = _elem->make_ptr()->isa_instptr();
1866 else
1867 tinst = _elem->isa_instptr();
1868 if (tinst)
1869 return tklass->as_instance_klass()->is_final();
1870 const TypeAryPtr* tap;
1871 if (_elem->isa_narrowoop())
1872 tap = _elem->make_ptr()->isa_aryptr();
1873 else
1874 tap = _elem->isa_aryptr();
1875 if (tap)
1876 return tap->ary()->ary_must_be_exact();
1877 return false;
1878 }
1880 //=============================================================================
1881 // Convenience common pre-built types.
1882 const TypePtr *TypePtr::NULL_PTR;
1883 const TypePtr *TypePtr::NOTNULL;
1884 const TypePtr *TypePtr::BOTTOM;
1886 //------------------------------meet-------------------------------------------
1887 // Meet over the PTR enum
1888 const TypePtr::PTR TypePtr::ptr_meet[TypePtr::lastPTR][TypePtr::lastPTR] = {
1889 // TopPTR, AnyNull, Constant, Null, NotNull, BotPTR,
1890 { /* Top */ TopPTR, AnyNull, Constant, Null, NotNull, BotPTR,},
1891 { /* AnyNull */ AnyNull, AnyNull, Constant, BotPTR, NotNull, BotPTR,},
1892 { /* Constant*/ Constant, Constant, Constant, BotPTR, NotNull, BotPTR,},
1893 { /* Null */ Null, BotPTR, BotPTR, Null, BotPTR, BotPTR,},
1894 { /* NotNull */ NotNull, NotNull, NotNull, BotPTR, NotNull, BotPTR,},
1895 { /* BotPTR */ BotPTR, BotPTR, BotPTR, BotPTR, BotPTR, BotPTR,}
1896 };
1898 //------------------------------make-------------------------------------------
1899 const TypePtr *TypePtr::make( TYPES t, enum PTR ptr, int offset ) {
1900 return (TypePtr*)(new TypePtr(t,ptr,offset))->hashcons();
1901 }
1903 //------------------------------cast_to_ptr_type-------------------------------
1904 const Type *TypePtr::cast_to_ptr_type(PTR ptr) const {
1905 assert(_base == AnyPtr, "subclass must override cast_to_ptr_type");
1906 if( ptr == _ptr ) return this;
1907 return make(_base, ptr, _offset);
1908 }
1910 //------------------------------get_con----------------------------------------
1911 intptr_t TypePtr::get_con() const {
1912 assert( _ptr == Null, "" );
1913 return _offset;
1914 }
1916 //------------------------------meet-------------------------------------------
1917 // Compute the MEET of two types. It returns a new Type object.
1918 const Type *TypePtr::xmeet( const Type *t ) const {
1919 // Perform a fast test for common case; meeting the same types together.
1920 if( this == t ) return this; // Meeting same type-rep?
1922 // Current "this->_base" is AnyPtr
1923 switch (t->base()) { // switch on original type
1924 case Int: // Mixing ints & oops happens when javac
1925 case Long: // reuses local variables
1926 case FloatTop:
1927 case FloatCon:
1928 case FloatBot:
1929 case DoubleTop:
1930 case DoubleCon:
1931 case DoubleBot:
1932 case NarrowOop:
1933 case Bottom: // Ye Olde Default
1934 return Type::BOTTOM;
1935 case Top:
1936 return this;
1938 case AnyPtr: { // Meeting to AnyPtrs
1939 const TypePtr *tp = t->is_ptr();
1940 return make( AnyPtr, meet_ptr(tp->ptr()), meet_offset(tp->offset()) );
1941 }
1942 case RawPtr: // For these, flip the call around to cut down
1943 case OopPtr:
1944 case InstPtr: // on the cases I have to handle.
1945 case KlassPtr:
1946 case AryPtr:
1947 return t->xmeet(this); // Call in reverse direction
1948 default: // All else is a mistake
1949 typerr(t);
1951 }
1952 return this;
1953 }
1955 //------------------------------meet_offset------------------------------------
1956 int TypePtr::meet_offset( int offset ) const {
1957 // Either is 'TOP' offset? Return the other offset!
1958 if( _offset == OffsetTop ) return offset;
1959 if( offset == OffsetTop ) return _offset;
1960 // If either is different, return 'BOTTOM' offset
1961 if( _offset != offset ) return OffsetBot;
1962 return _offset;
1963 }
1965 //------------------------------dual_offset------------------------------------
1966 int TypePtr::dual_offset( ) const {
1967 if( _offset == OffsetTop ) return OffsetBot;// Map 'TOP' into 'BOTTOM'
1968 if( _offset == OffsetBot ) return OffsetTop;// Map 'BOTTOM' into 'TOP'
1969 return _offset; // Map everything else into self
1970 }
1972 //------------------------------xdual------------------------------------------
1973 // Dual: compute field-by-field dual
1974 const TypePtr::PTR TypePtr::ptr_dual[TypePtr::lastPTR] = {
1975 BotPTR, NotNull, Constant, Null, AnyNull, TopPTR
1976 };
1977 const Type *TypePtr::xdual() const {
1978 return new TypePtr( AnyPtr, dual_ptr(), dual_offset() );
1979 }
1981 //------------------------------xadd_offset------------------------------------
1982 int TypePtr::xadd_offset( intptr_t offset ) const {
1983 // Adding to 'TOP' offset? Return 'TOP'!
1984 if( _offset == OffsetTop || offset == OffsetTop ) return OffsetTop;
1985 // Adding to 'BOTTOM' offset? Return 'BOTTOM'!
1986 if( _offset == OffsetBot || offset == OffsetBot ) return OffsetBot;
1987 // Addition overflows or "accidentally" equals to OffsetTop? Return 'BOTTOM'!
1988 offset += (intptr_t)_offset;
1989 if (offset != (int)offset || offset == OffsetTop) return OffsetBot;
1991 // assert( _offset >= 0 && _offset+offset >= 0, "" );
1992 // It is possible to construct a negative offset during PhaseCCP
1994 return (int)offset; // Sum valid offsets
1995 }
1997 //------------------------------add_offset-------------------------------------
1998 const TypePtr *TypePtr::add_offset( intptr_t offset ) const {
1999 return make( AnyPtr, _ptr, xadd_offset(offset) );
2000 }
2002 //------------------------------eq---------------------------------------------
2003 // Structural equality check for Type representations
2004 bool TypePtr::eq( const Type *t ) const {
2005 const TypePtr *a = (const TypePtr*)t;
2006 return _ptr == a->ptr() && _offset == a->offset();
2007 }
2009 //------------------------------hash-------------------------------------------
2010 // Type-specific hashing function.
2011 int TypePtr::hash(void) const {
2012 return _ptr + _offset;
2013 }
2015 //------------------------------dump2------------------------------------------
2016 const char *const TypePtr::ptr_msg[TypePtr::lastPTR] = {
2017 "TopPTR","AnyNull","Constant","NULL","NotNull","BotPTR"
2018 };
2020 #ifndef PRODUCT
2021 void TypePtr::dump2( Dict &d, uint depth, outputStream *st ) const {
2022 if( _ptr == Null ) st->print("NULL");
2023 else st->print("%s *", ptr_msg[_ptr]);
2024 if( _offset == OffsetTop ) st->print("+top");
2025 else if( _offset == OffsetBot ) st->print("+bot");
2026 else if( _offset ) st->print("+%d", _offset);
2027 }
2028 #endif
2030 //------------------------------singleton--------------------------------------
2031 // TRUE if Type is a singleton type, FALSE otherwise. Singletons are simple
2032 // constants
2033 bool TypePtr::singleton(void) const {
2034 // TopPTR, Null, AnyNull, Constant are all singletons
2035 return (_offset != OffsetBot) && !below_centerline(_ptr);
2036 }
2038 bool TypePtr::empty(void) const {
2039 return (_offset == OffsetTop) || above_centerline(_ptr);
2040 }
2042 //=============================================================================
2043 // Convenience common pre-built types.
2044 const TypeRawPtr *TypeRawPtr::BOTTOM;
2045 const TypeRawPtr *TypeRawPtr::NOTNULL;
2047 //------------------------------make-------------------------------------------
2048 const TypeRawPtr *TypeRawPtr::make( enum PTR ptr ) {
2049 assert( ptr != Constant, "what is the constant?" );
2050 assert( ptr != Null, "Use TypePtr for NULL" );
2051 return (TypeRawPtr*)(new TypeRawPtr(ptr,0))->hashcons();
2052 }
2054 const TypeRawPtr *TypeRawPtr::make( address bits ) {
2055 assert( bits, "Use TypePtr for NULL" );
2056 return (TypeRawPtr*)(new TypeRawPtr(Constant,bits))->hashcons();
2057 }
2059 //------------------------------cast_to_ptr_type-------------------------------
2060 const Type *TypeRawPtr::cast_to_ptr_type(PTR ptr) const {
2061 assert( ptr != Constant, "what is the constant?" );
2062 assert( ptr != Null, "Use TypePtr for NULL" );
2063 assert( _bits==0, "Why cast a constant address?");
2064 if( ptr == _ptr ) return this;
2065 return make(ptr);
2066 }
2068 //------------------------------get_con----------------------------------------
2069 intptr_t TypeRawPtr::get_con() const {
2070 assert( _ptr == Null || _ptr == Constant, "" );
2071 return (intptr_t)_bits;
2072 }
2074 //------------------------------meet-------------------------------------------
2075 // Compute the MEET of two types. It returns a new Type object.
2076 const Type *TypeRawPtr::xmeet( const Type *t ) const {
2077 // Perform a fast test for common case; meeting the same types together.
2078 if( this == t ) return this; // Meeting same type-rep?
2080 // Current "this->_base" is RawPtr
2081 switch( t->base() ) { // switch on original type
2082 case Bottom: // Ye Olde Default
2083 return t;
2084 case Top:
2085 return this;
2086 case AnyPtr: // Meeting to AnyPtrs
2087 break;
2088 case RawPtr: { // might be top, bot, any/not or constant
2089 enum PTR tptr = t->is_ptr()->ptr();
2090 enum PTR ptr = meet_ptr( tptr );
2091 if( ptr == Constant ) { // Cannot be equal constants, so...
2092 if( tptr == Constant && _ptr != Constant) return t;
2093 if( _ptr == Constant && tptr != Constant) return this;
2094 ptr = NotNull; // Fall down in lattice
2095 }
2096 return make( ptr );
2097 }
2099 case OopPtr:
2100 case InstPtr:
2101 case KlassPtr:
2102 case AryPtr:
2103 return TypePtr::BOTTOM; // Oop meet raw is not well defined
2104 default: // All else is a mistake
2105 typerr(t);
2106 }
2108 // Found an AnyPtr type vs self-RawPtr type
2109 const TypePtr *tp = t->is_ptr();
2110 switch (tp->ptr()) {
2111 case TypePtr::TopPTR: return this;
2112 case TypePtr::BotPTR: return t;
2113 case TypePtr::Null:
2114 if( _ptr == TypePtr::TopPTR ) return t;
2115 return TypeRawPtr::BOTTOM;
2116 case TypePtr::NotNull: return TypePtr::make( AnyPtr, meet_ptr(TypePtr::NotNull), tp->meet_offset(0) );
2117 case TypePtr::AnyNull:
2118 if( _ptr == TypePtr::Constant) return this;
2119 return make( meet_ptr(TypePtr::AnyNull) );
2120 default: ShouldNotReachHere();
2121 }
2122 return this;
2123 }
2125 //------------------------------xdual------------------------------------------
2126 // Dual: compute field-by-field dual
2127 const Type *TypeRawPtr::xdual() const {
2128 return new TypeRawPtr( dual_ptr(), _bits );
2129 }
2131 //------------------------------add_offset-------------------------------------
2132 const TypePtr *TypeRawPtr::add_offset( intptr_t offset ) const {
2133 if( offset == OffsetTop ) return BOTTOM; // Undefined offset-> undefined pointer
2134 if( offset == OffsetBot ) return BOTTOM; // Unknown offset-> unknown pointer
2135 if( offset == 0 ) return this; // No change
2136 switch (_ptr) {
2137 case TypePtr::TopPTR:
2138 case TypePtr::BotPTR:
2139 case TypePtr::NotNull:
2140 return this;
2141 case TypePtr::Null:
2142 case TypePtr::Constant:
2143 return make( _bits+offset );
2144 default: ShouldNotReachHere();
2145 }
2146 return NULL; // Lint noise
2147 }
2149 //------------------------------eq---------------------------------------------
2150 // Structural equality check for Type representations
2151 bool TypeRawPtr::eq( const Type *t ) const {
2152 const TypeRawPtr *a = (const TypeRawPtr*)t;
2153 return _bits == a->_bits && TypePtr::eq(t);
2154 }
2156 //------------------------------hash-------------------------------------------
2157 // Type-specific hashing function.
2158 int TypeRawPtr::hash(void) const {
2159 return (intptr_t)_bits + TypePtr::hash();
2160 }
2162 //------------------------------dump2------------------------------------------
2163 #ifndef PRODUCT
2164 void TypeRawPtr::dump2( Dict &d, uint depth, outputStream *st ) const {
2165 if( _ptr == Constant )
2166 st->print(INTPTR_FORMAT, _bits);
2167 else
2168 st->print("rawptr:%s", ptr_msg[_ptr]);
2169 }
2170 #endif
2172 //=============================================================================
2173 // Convenience common pre-built type.
2174 const TypeOopPtr *TypeOopPtr::BOTTOM;
2176 //------------------------------TypeOopPtr-------------------------------------
2177 TypeOopPtr::TypeOopPtr( TYPES t, PTR ptr, ciKlass* k, bool xk, ciObject* o, int offset, int instance_id )
2178 : TypePtr(t, ptr, offset),
2179 _const_oop(o), _klass(k),
2180 _klass_is_exact(xk),
2181 _is_ptr_to_narrowoop(false),
2182 _instance_id(instance_id) {
2183 #ifdef _LP64
2184 if (UseCompressedOops && _offset != 0) {
2185 if (klass() == NULL) {
2186 assert(this->isa_aryptr(), "only arrays without klass");
2187 _is_ptr_to_narrowoop = true;
2188 } else if (_offset == oopDesc::klass_offset_in_bytes()) {
2189 _is_ptr_to_narrowoop = true;
2190 } else if (this->isa_aryptr()) {
2191 _is_ptr_to_narrowoop = (klass()->is_obj_array_klass() &&
2192 _offset != arrayOopDesc::length_offset_in_bytes());
2193 } else if (klass() == ciEnv::current()->Class_klass() &&
2194 (_offset == java_lang_Class::klass_offset_in_bytes() ||
2195 _offset == java_lang_Class::array_klass_offset_in_bytes())) {
2196 // Special hidden fields from the Class.
2197 assert(this->isa_instptr(), "must be an instance ptr.");
2198 _is_ptr_to_narrowoop = true;
2199 } else if (klass()->is_instance_klass()) {
2200 ciInstanceKlass* ik = klass()->as_instance_klass();
2201 ciField* field = NULL;
2202 if (this->isa_klassptr()) {
2203 // Perm objects don't use compressed references, except for
2204 // static fields which are currently compressed.
2205 field = ik->get_field_by_offset(_offset, true);
2206 if (field != NULL) {
2207 BasicType basic_elem_type = field->layout_type();
2208 _is_ptr_to_narrowoop = (basic_elem_type == T_OBJECT ||
2209 basic_elem_type == T_ARRAY);
2210 }
2211 } else if (_offset == OffsetBot || _offset == OffsetTop) {
2212 // unsafe access
2213 _is_ptr_to_narrowoop = true;
2214 } else { // exclude unsafe ops
2215 assert(this->isa_instptr(), "must be an instance ptr.");
2216 // Field which contains a compressed oop references.
2217 field = ik->get_field_by_offset(_offset, false);
2218 if (field != NULL) {
2219 BasicType basic_elem_type = field->layout_type();
2220 _is_ptr_to_narrowoop = (basic_elem_type == T_OBJECT ||
2221 basic_elem_type == T_ARRAY);
2222 } else if (klass()->equals(ciEnv::current()->Object_klass())) {
2223 // Compile::find_alias_type() cast exactness on all types to verify
2224 // that it does not affect alias type.
2225 _is_ptr_to_narrowoop = true;
2226 } else {
2227 // Type for the copy start in LibraryCallKit::inline_native_clone().
2228 assert(!klass_is_exact(), "only non-exact klass");
2229 _is_ptr_to_narrowoop = true;
2230 }
2231 }
2232 }
2233 }
2234 #endif
2235 }
2237 //------------------------------make-------------------------------------------
2238 const TypeOopPtr *TypeOopPtr::make(PTR ptr,
2239 int offset, int instance_id) {
2240 assert(ptr != Constant, "no constant generic pointers");
2241 ciKlass* k = ciKlassKlass::make();
2242 bool xk = false;
2243 ciObject* o = NULL;
2244 return (TypeOopPtr*)(new TypeOopPtr(OopPtr, ptr, k, xk, o, offset, instance_id))->hashcons();
2245 }
2248 //------------------------------cast_to_ptr_type-------------------------------
2249 const Type *TypeOopPtr::cast_to_ptr_type(PTR ptr) const {
2250 assert(_base == OopPtr, "subclass must override cast_to_ptr_type");
2251 if( ptr == _ptr ) return this;
2252 return make(ptr, _offset);
2253 }
2255 //-----------------------------cast_to_instance_id----------------------------
2256 const TypeOopPtr *TypeOopPtr::cast_to_instance_id(int instance_id) const {
2257 // There are no instances of a general oop.
2258 // Return self unchanged.
2259 return this;
2260 }
2262 //-----------------------------cast_to_exactness-------------------------------
2263 const Type *TypeOopPtr::cast_to_exactness(bool klass_is_exact) const {
2264 // There is no such thing as an exact general oop.
2265 // Return self unchanged.
2266 return this;
2267 }
2270 //------------------------------as_klass_type----------------------------------
2271 // Return the klass type corresponding to this instance or array type.
2272 // It is the type that is loaded from an object of this type.
2273 const TypeKlassPtr* TypeOopPtr::as_klass_type() const {
2274 ciKlass* k = klass();
2275 bool xk = klass_is_exact();
2276 if (k == NULL || !k->is_java_klass())
2277 return TypeKlassPtr::OBJECT;
2278 else
2279 return TypeKlassPtr::make(xk? Constant: NotNull, k, 0);
2280 }
2283 //------------------------------meet-------------------------------------------
2284 // Compute the MEET of two types. It returns a new Type object.
2285 const Type *TypeOopPtr::xmeet( const Type *t ) const {
2286 // Perform a fast test for common case; meeting the same types together.
2287 if( this == t ) return this; // Meeting same type-rep?
2289 // Current "this->_base" is OopPtr
2290 switch (t->base()) { // switch on original type
2292 case Int: // Mixing ints & oops happens when javac
2293 case Long: // reuses local variables
2294 case FloatTop:
2295 case FloatCon:
2296 case FloatBot:
2297 case DoubleTop:
2298 case DoubleCon:
2299 case DoubleBot:
2300 case NarrowOop:
2301 case Bottom: // Ye Olde Default
2302 return Type::BOTTOM;
2303 case Top:
2304 return this;
2306 default: // All else is a mistake
2307 typerr(t);
2309 case RawPtr:
2310 return TypePtr::BOTTOM; // Oop meet raw is not well defined
2312 case AnyPtr: {
2313 // Found an AnyPtr type vs self-OopPtr type
2314 const TypePtr *tp = t->is_ptr();
2315 int offset = meet_offset(tp->offset());
2316 PTR ptr = meet_ptr(tp->ptr());
2317 switch (tp->ptr()) {
2318 case Null:
2319 if (ptr == Null) return TypePtr::make(AnyPtr, ptr, offset);
2320 // else fall through:
2321 case TopPTR:
2322 case AnyNull:
2323 return make(ptr, offset);
2324 case BotPTR:
2325 case NotNull:
2326 return TypePtr::make(AnyPtr, ptr, offset);
2327 default: typerr(t);
2328 }
2329 }
2331 case OopPtr: { // Meeting to other OopPtrs
2332 const TypeOopPtr *tp = t->is_oopptr();
2333 int instance_id = meet_instance_id(tp->instance_id());
2334 return make( meet_ptr(tp->ptr()), meet_offset(tp->offset()), instance_id );
2335 }
2337 case InstPtr: // For these, flip the call around to cut down
2338 case KlassPtr: // on the cases I have to handle.
2339 case AryPtr:
2340 return t->xmeet(this); // Call in reverse direction
2342 } // End of switch
2343 return this; // Return the double constant
2344 }
2347 //------------------------------xdual------------------------------------------
2348 // Dual of a pure heap pointer. No relevant klass or oop information.
2349 const Type *TypeOopPtr::xdual() const {
2350 assert(klass() == ciKlassKlass::make(), "no klasses here");
2351 assert(const_oop() == NULL, "no constants here");
2352 return new TypeOopPtr(_base, dual_ptr(), klass(), klass_is_exact(), const_oop(), dual_offset(), dual_instance_id() );
2353 }
2355 //--------------------------make_from_klass_common-----------------------------
2356 // Computes the element-type given a klass.
2357 const TypeOopPtr* TypeOopPtr::make_from_klass_common(ciKlass *klass, bool klass_change, bool try_for_exact) {
2358 assert(klass->is_java_klass(), "must be java language klass");
2359 if (klass->is_instance_klass()) {
2360 Compile* C = Compile::current();
2361 Dependencies* deps = C->dependencies();
2362 assert((deps != NULL) == (C->method() != NULL && C->method()->code_size() > 0), "sanity");
2363 // Element is an instance
2364 bool klass_is_exact = false;
2365 if (klass->is_loaded()) {
2366 // Try to set klass_is_exact.
2367 ciInstanceKlass* ik = klass->as_instance_klass();
2368 klass_is_exact = ik->is_final();
2369 if (!klass_is_exact && klass_change
2370 && deps != NULL && UseUniqueSubclasses) {
2371 ciInstanceKlass* sub = ik->unique_concrete_subklass();
2372 if (sub != NULL) {
2373 deps->assert_abstract_with_unique_concrete_subtype(ik, sub);
2374 klass = ik = sub;
2375 klass_is_exact = sub->is_final();
2376 }
2377 }
2378 if (!klass_is_exact && try_for_exact
2379 && deps != NULL && UseExactTypes) {
2380 if (!ik->is_interface() && !ik->has_subklass()) {
2381 // Add a dependence; if concrete subclass added we need to recompile
2382 deps->assert_leaf_type(ik);
2383 klass_is_exact = true;
2384 }
2385 }
2386 }
2387 return TypeInstPtr::make(TypePtr::BotPTR, klass, klass_is_exact, NULL, 0);
2388 } else if (klass->is_obj_array_klass()) {
2389 // Element is an object array. Recursively call ourself.
2390 const TypeOopPtr *etype = TypeOopPtr::make_from_klass_common(klass->as_obj_array_klass()->element_klass(), false, try_for_exact);
2391 bool xk = etype->klass_is_exact();
2392 const TypeAry* arr0 = TypeAry::make(etype, TypeInt::POS);
2393 // We used to pass NotNull in here, asserting that the sub-arrays
2394 // are all not-null. This is not true in generally, as code can
2395 // slam NULLs down in the subarrays.
2396 const TypeAryPtr* arr = TypeAryPtr::make(TypePtr::BotPTR, arr0, klass, xk, 0);
2397 return arr;
2398 } else if (klass->is_type_array_klass()) {
2399 // Element is an typeArray
2400 const Type* etype = get_const_basic_type(klass->as_type_array_klass()->element_type());
2401 const TypeAry* arr0 = TypeAry::make(etype, TypeInt::POS);
2402 // We used to pass NotNull in here, asserting that the array pointer
2403 // is not-null. That was not true in general.
2404 const TypeAryPtr* arr = TypeAryPtr::make(TypePtr::BotPTR, arr0, klass, true, 0);
2405 return arr;
2406 } else {
2407 ShouldNotReachHere();
2408 return NULL;
2409 }
2410 }
2412 //------------------------------make_from_constant-----------------------------
2413 // Make a java pointer from an oop constant
2414 const TypeOopPtr* TypeOopPtr::make_from_constant(ciObject* o, bool require_constant) {
2415 if (o->is_method_data() || o->is_method()) {
2416 // Treat much like a typeArray of bytes, like below, but fake the type...
2417 const Type* etype = (Type*)get_const_basic_type(T_BYTE);
2418 const TypeAry* arr0 = TypeAry::make(etype, TypeInt::POS);
2419 ciKlass *klass = ciTypeArrayKlass::make((BasicType) T_BYTE);
2420 assert(o->can_be_constant(), "method data oops should be tenured");
2421 const TypeAryPtr* arr = TypeAryPtr::make(TypePtr::Constant, o, arr0, klass, true, 0);
2422 return arr;
2423 } else {
2424 assert(o->is_java_object(), "must be java language object");
2425 assert(!o->is_null_object(), "null object not yet handled here.");
2426 ciKlass *klass = o->klass();
2427 if (klass->is_instance_klass()) {
2428 // Element is an instance
2429 if (require_constant) {
2430 if (!o->can_be_constant()) return NULL;
2431 } else if (!o->should_be_constant()) {
2432 return TypeInstPtr::make(TypePtr::NotNull, klass, true, NULL, 0);
2433 }
2434 return TypeInstPtr::make(o);
2435 } else if (klass->is_obj_array_klass()) {
2436 // Element is an object array. Recursively call ourself.
2437 const Type *etype =
2438 TypeOopPtr::make_from_klass_raw(klass->as_obj_array_klass()->element_klass());
2439 const TypeAry* arr0 = TypeAry::make(etype, TypeInt::make(o->as_array()->length()));
2440 // We used to pass NotNull in here, asserting that the sub-arrays
2441 // are all not-null. This is not true in generally, as code can
2442 // slam NULLs down in the subarrays.
2443 if (require_constant) {
2444 if (!o->can_be_constant()) return NULL;
2445 } else if (!o->should_be_constant()) {
2446 return TypeAryPtr::make(TypePtr::NotNull, arr0, klass, true, 0);
2447 }
2448 const TypeAryPtr* arr = TypeAryPtr::make(TypePtr::Constant, o, arr0, klass, true, 0);
2449 return arr;
2450 } else if (klass->is_type_array_klass()) {
2451 // Element is an typeArray
2452 const Type* etype =
2453 (Type*)get_const_basic_type(klass->as_type_array_klass()->element_type());
2454 const TypeAry* arr0 = TypeAry::make(etype, TypeInt::make(o->as_array()->length()));
2455 // We used to pass NotNull in here, asserting that the array pointer
2456 // is not-null. That was not true in general.
2457 if (require_constant) {
2458 if (!o->can_be_constant()) return NULL;
2459 } else if (!o->should_be_constant()) {
2460 return TypeAryPtr::make(TypePtr::NotNull, arr0, klass, true, 0);
2461 }
2462 const TypeAryPtr* arr = TypeAryPtr::make(TypePtr::Constant, o, arr0, klass, true, 0);
2463 return arr;
2464 }
2465 }
2467 ShouldNotReachHere();
2468 return NULL;
2469 }
2471 //------------------------------get_con----------------------------------------
2472 intptr_t TypeOopPtr::get_con() const {
2473 assert( _ptr == Null || _ptr == Constant, "" );
2474 assert( _offset >= 0, "" );
2476 if (_offset != 0) {
2477 // After being ported to the compiler interface, the compiler no longer
2478 // directly manipulates the addresses of oops. Rather, it only has a pointer
2479 // to a handle at compile time. This handle is embedded in the generated
2480 // code and dereferenced at the time the nmethod is made. Until that time,
2481 // it is not reasonable to do arithmetic with the addresses of oops (we don't
2482 // have access to the addresses!). This does not seem to currently happen,
2483 // but this assertion here is to help prevent its occurence.
2484 tty->print_cr("Found oop constant with non-zero offset");
2485 ShouldNotReachHere();
2486 }
2488 return (intptr_t)const_oop()->constant_encoding();
2489 }
2492 //-----------------------------filter------------------------------------------
2493 // Do not allow interface-vs.-noninterface joins to collapse to top.
2494 const Type *TypeOopPtr::filter( const Type *kills ) const {
2496 const Type* ft = join(kills);
2497 const TypeInstPtr* ftip = ft->isa_instptr();
2498 const TypeInstPtr* ktip = kills->isa_instptr();
2499 const TypeKlassPtr* ftkp = ft->isa_klassptr();
2500 const TypeKlassPtr* ktkp = kills->isa_klassptr();
2502 if (ft->empty()) {
2503 // Check for evil case of 'this' being a class and 'kills' expecting an
2504 // interface. This can happen because the bytecodes do not contain
2505 // enough type info to distinguish a Java-level interface variable
2506 // from a Java-level object variable. If we meet 2 classes which
2507 // both implement interface I, but their meet is at 'j/l/O' which
2508 // doesn't implement I, we have no way to tell if the result should
2509 // be 'I' or 'j/l/O'. Thus we'll pick 'j/l/O'. If this then flows
2510 // into a Phi which "knows" it's an Interface type we'll have to
2511 // uplift the type.
2512 if (!empty() && ktip != NULL && ktip->is_loaded() && ktip->klass()->is_interface())
2513 return kills; // Uplift to interface
2514 if (!empty() && ktkp != NULL && ktkp->klass()->is_loaded() && ktkp->klass()->is_interface())
2515 return kills; // Uplift to interface
2517 return Type::TOP; // Canonical empty value
2518 }
2520 // If we have an interface-typed Phi or cast and we narrow to a class type,
2521 // the join should report back the class. However, if we have a J/L/Object
2522 // class-typed Phi and an interface flows in, it's possible that the meet &
2523 // join report an interface back out. This isn't possible but happens
2524 // because the type system doesn't interact well with interfaces.
2525 if (ftip != NULL && ktip != NULL &&
2526 ftip->is_loaded() && ftip->klass()->is_interface() &&
2527 ktip->is_loaded() && !ktip->klass()->is_interface()) {
2528 // Happens in a CTW of rt.jar, 320-341, no extra flags
2529 return ktip->cast_to_ptr_type(ftip->ptr());
2530 }
2531 if (ftkp != NULL && ktkp != NULL &&
2532 ftkp->is_loaded() && ftkp->klass()->is_interface() &&
2533 ktkp->is_loaded() && !ktkp->klass()->is_interface()) {
2534 // Happens in a CTW of rt.jar, 320-341, no extra flags
2535 return ktkp->cast_to_ptr_type(ftkp->ptr());
2536 }
2538 return ft;
2539 }
2541 //------------------------------eq---------------------------------------------
2542 // Structural equality check for Type representations
2543 bool TypeOopPtr::eq( const Type *t ) const {
2544 const TypeOopPtr *a = (const TypeOopPtr*)t;
2545 if (_klass_is_exact != a->_klass_is_exact ||
2546 _instance_id != a->_instance_id) return false;
2547 ciObject* one = const_oop();
2548 ciObject* two = a->const_oop();
2549 if (one == NULL || two == NULL) {
2550 return (one == two) && TypePtr::eq(t);
2551 } else {
2552 return one->equals(two) && TypePtr::eq(t);
2553 }
2554 }
2556 //------------------------------hash-------------------------------------------
2557 // Type-specific hashing function.
2558 int TypeOopPtr::hash(void) const {
2559 return
2560 (const_oop() ? const_oop()->hash() : 0) +
2561 _klass_is_exact +
2562 _instance_id +
2563 TypePtr::hash();
2564 }
2566 //------------------------------dump2------------------------------------------
2567 #ifndef PRODUCT
2568 void TypeOopPtr::dump2( Dict &d, uint depth, outputStream *st ) const {
2569 st->print("oopptr:%s", ptr_msg[_ptr]);
2570 if( _klass_is_exact ) st->print(":exact");
2571 if( const_oop() ) st->print(INTPTR_FORMAT, const_oop());
2572 switch( _offset ) {
2573 case OffsetTop: st->print("+top"); break;
2574 case OffsetBot: st->print("+any"); break;
2575 case 0: break;
2576 default: st->print("+%d",_offset); break;
2577 }
2578 if (_instance_id == InstanceTop)
2579 st->print(",iid=top");
2580 else if (_instance_id != InstanceBot)
2581 st->print(",iid=%d",_instance_id);
2582 }
2583 #endif
2585 //------------------------------singleton--------------------------------------
2586 // TRUE if Type is a singleton type, FALSE otherwise. Singletons are simple
2587 // constants
2588 bool TypeOopPtr::singleton(void) const {
2589 // detune optimizer to not generate constant oop + constant offset as a constant!
2590 // TopPTR, Null, AnyNull, Constant are all singletons
2591 return (_offset == 0) && !below_centerline(_ptr);
2592 }
2594 //------------------------------add_offset-------------------------------------
2595 const TypePtr *TypeOopPtr::add_offset( intptr_t offset ) const {
2596 return make( _ptr, xadd_offset(offset) );
2597 }
2599 //------------------------------meet_instance_id--------------------------------
2600 int TypeOopPtr::meet_instance_id( int instance_id ) const {
2601 // Either is 'TOP' instance? Return the other instance!
2602 if( _instance_id == InstanceTop ) return instance_id;
2603 if( instance_id == InstanceTop ) return _instance_id;
2604 // If either is different, return 'BOTTOM' instance
2605 if( _instance_id != instance_id ) return InstanceBot;
2606 return _instance_id;
2607 }
2609 //------------------------------dual_instance_id--------------------------------
2610 int TypeOopPtr::dual_instance_id( ) const {
2611 if( _instance_id == InstanceTop ) return InstanceBot; // Map TOP into BOTTOM
2612 if( _instance_id == InstanceBot ) return InstanceTop; // Map BOTTOM into TOP
2613 return _instance_id; // Map everything else into self
2614 }
2617 //=============================================================================
2618 // Convenience common pre-built types.
2619 const TypeInstPtr *TypeInstPtr::NOTNULL;
2620 const TypeInstPtr *TypeInstPtr::BOTTOM;
2621 const TypeInstPtr *TypeInstPtr::MIRROR;
2622 const TypeInstPtr *TypeInstPtr::MARK;
2623 const TypeInstPtr *TypeInstPtr::KLASS;
2625 //------------------------------TypeInstPtr-------------------------------------
2626 TypeInstPtr::TypeInstPtr(PTR ptr, ciKlass* k, bool xk, ciObject* o, int off, int instance_id)
2627 : TypeOopPtr(InstPtr, ptr, k, xk, o, off, instance_id), _name(k->name()) {
2628 assert(k != NULL &&
2629 (k->is_loaded() || o == NULL),
2630 "cannot have constants with non-loaded klass");
2631 };
2633 //------------------------------make-------------------------------------------
2634 const TypeInstPtr *TypeInstPtr::make(PTR ptr,
2635 ciKlass* k,
2636 bool xk,
2637 ciObject* o,
2638 int offset,
2639 int instance_id) {
2640 assert( !k->is_loaded() || k->is_instance_klass() ||
2641 k->is_method_klass(), "Must be for instance or method");
2642 // Either const_oop() is NULL or else ptr is Constant
2643 assert( (!o && ptr != Constant) || (o && ptr == Constant),
2644 "constant pointers must have a value supplied" );
2645 // Ptr is never Null
2646 assert( ptr != Null, "NULL pointers are not typed" );
2648 assert(instance_id <= 0 || xk || !UseExactTypes, "instances are always exactly typed");
2649 if (!UseExactTypes) xk = false;
2650 if (ptr == Constant) {
2651 // Note: This case includes meta-object constants, such as methods.
2652 xk = true;
2653 } else if (k->is_loaded()) {
2654 ciInstanceKlass* ik = k->as_instance_klass();
2655 if (!xk && ik->is_final()) xk = true; // no inexact final klass
2656 if (xk && ik->is_interface()) xk = false; // no exact interface
2657 }
2659 // Now hash this baby
2660 TypeInstPtr *result =
2661 (TypeInstPtr*)(new TypeInstPtr(ptr, k, xk, o ,offset, instance_id))->hashcons();
2663 return result;
2664 }
2667 //------------------------------cast_to_ptr_type-------------------------------
2668 const Type *TypeInstPtr::cast_to_ptr_type(PTR ptr) const {
2669 if( ptr == _ptr ) return this;
2670 // Reconstruct _sig info here since not a problem with later lazy
2671 // construction, _sig will show up on demand.
2672 return make(ptr, klass(), klass_is_exact(), const_oop(), _offset, _instance_id);
2673 }
2676 //-----------------------------cast_to_exactness-------------------------------
2677 const Type *TypeInstPtr::cast_to_exactness(bool klass_is_exact) const {
2678 if( klass_is_exact == _klass_is_exact ) return this;
2679 if (!UseExactTypes) return this;
2680 if (!_klass->is_loaded()) return this;
2681 ciInstanceKlass* ik = _klass->as_instance_klass();
2682 if( (ik->is_final() || _const_oop) ) return this; // cannot clear xk
2683 if( ik->is_interface() ) return this; // cannot set xk
2684 return make(ptr(), klass(), klass_is_exact, const_oop(), _offset, _instance_id);
2685 }
2687 //-----------------------------cast_to_instance_id----------------------------
2688 const TypeOopPtr *TypeInstPtr::cast_to_instance_id(int instance_id) const {
2689 if( instance_id == _instance_id ) return this;
2690 return make(_ptr, klass(), _klass_is_exact, const_oop(), _offset, instance_id);
2691 }
2693 //------------------------------xmeet_unloaded---------------------------------
2694 // Compute the MEET of two InstPtrs when at least one is unloaded.
2695 // Assume classes are different since called after check for same name/class-loader
2696 const TypeInstPtr *TypeInstPtr::xmeet_unloaded(const TypeInstPtr *tinst) const {
2697 int off = meet_offset(tinst->offset());
2698 PTR ptr = meet_ptr(tinst->ptr());
2700 const TypeInstPtr *loaded = is_loaded() ? this : tinst;
2701 const TypeInstPtr *unloaded = is_loaded() ? tinst : this;
2702 if( loaded->klass()->equals(ciEnv::current()->Object_klass()) ) {
2703 //
2704 // Meet unloaded class with java/lang/Object
2705 //
2706 // Meet
2707 // | Unloaded Class
2708 // Object | TOP | AnyNull | Constant | NotNull | BOTTOM |
2709 // ===================================================================
2710 // TOP | ..........................Unloaded......................|
2711 // AnyNull | U-AN |................Unloaded......................|
2712 // Constant | ... O-NN .................................. | O-BOT |
2713 // NotNull | ... O-NN .................................. | O-BOT |
2714 // BOTTOM | ........................Object-BOTTOM ..................|
2715 //
2716 assert(loaded->ptr() != TypePtr::Null, "insanity check");
2717 //
2718 if( loaded->ptr() == TypePtr::TopPTR ) { return unloaded; }
2719 else if (loaded->ptr() == TypePtr::AnyNull) { return TypeInstPtr::make( ptr, unloaded->klass() ); }
2720 else if (loaded->ptr() == TypePtr::BotPTR ) { return TypeInstPtr::BOTTOM; }
2721 else if (loaded->ptr() == TypePtr::Constant || loaded->ptr() == TypePtr::NotNull) {
2722 if (unloaded->ptr() == TypePtr::BotPTR ) { return TypeInstPtr::BOTTOM; }
2723 else { return TypeInstPtr::NOTNULL; }
2724 }
2725 else if( unloaded->ptr() == TypePtr::TopPTR ) { return unloaded; }
2727 return unloaded->cast_to_ptr_type(TypePtr::AnyNull)->is_instptr();
2728 }
2730 // Both are unloaded, not the same class, not Object
2731 // Or meet unloaded with a different loaded class, not java/lang/Object
2732 if( ptr != TypePtr::BotPTR ) {
2733 return TypeInstPtr::NOTNULL;
2734 }
2735 return TypeInstPtr::BOTTOM;
2736 }
2739 //------------------------------meet-------------------------------------------
2740 // Compute the MEET of two types. It returns a new Type object.
2741 const Type *TypeInstPtr::xmeet( const Type *t ) const {
2742 // Perform a fast test for common case; meeting the same types together.
2743 if( this == t ) return this; // Meeting same type-rep?
2745 // Current "this->_base" is Pointer
2746 switch (t->base()) { // switch on original type
2748 case Int: // Mixing ints & oops happens when javac
2749 case Long: // reuses local variables
2750 case FloatTop:
2751 case FloatCon:
2752 case FloatBot:
2753 case DoubleTop:
2754 case DoubleCon:
2755 case DoubleBot:
2756 case NarrowOop:
2757 case Bottom: // Ye Olde Default
2758 return Type::BOTTOM;
2759 case Top:
2760 return this;
2762 default: // All else is a mistake
2763 typerr(t);
2765 case RawPtr: return TypePtr::BOTTOM;
2767 case AryPtr: { // All arrays inherit from Object class
2768 const TypeAryPtr *tp = t->is_aryptr();
2769 int offset = meet_offset(tp->offset());
2770 PTR ptr = meet_ptr(tp->ptr());
2771 int instance_id = meet_instance_id(tp->instance_id());
2772 switch (ptr) {
2773 case TopPTR:
2774 case AnyNull: // Fall 'down' to dual of object klass
2775 if (klass()->equals(ciEnv::current()->Object_klass())) {
2776 return TypeAryPtr::make(ptr, tp->ary(), tp->klass(), tp->klass_is_exact(), offset, instance_id);
2777 } else {
2778 // cannot subclass, so the meet has to fall badly below the centerline
2779 ptr = NotNull;
2780 instance_id = InstanceBot;
2781 return TypeInstPtr::make( ptr, ciEnv::current()->Object_klass(), false, NULL, offset, instance_id);
2782 }
2783 case Constant:
2784 case NotNull:
2785 case BotPTR: // Fall down to object klass
2786 // LCA is object_klass, but if we subclass from the top we can do better
2787 if( above_centerline(_ptr) ) { // if( _ptr == TopPTR || _ptr == AnyNull )
2788 // If 'this' (InstPtr) is above the centerline and it is Object class
2789 // then we can subclass in the Java class hierarchy.
2790 if (klass()->equals(ciEnv::current()->Object_klass())) {
2791 // that is, tp's array type is a subtype of my klass
2792 return TypeAryPtr::make(ptr, tp->ary(), tp->klass(), tp->klass_is_exact(), offset, instance_id);
2793 }
2794 }
2795 // The other case cannot happen, since I cannot be a subtype of an array.
2796 // The meet falls down to Object class below centerline.
2797 if( ptr == Constant )
2798 ptr = NotNull;
2799 instance_id = InstanceBot;
2800 return make( ptr, ciEnv::current()->Object_klass(), false, NULL, offset, instance_id );
2801 default: typerr(t);
2802 }
2803 }
2805 case OopPtr: { // Meeting to OopPtrs
2806 // Found a OopPtr type vs self-InstPtr type
2807 const TypeOopPtr *tp = t->is_oopptr();
2808 int offset = meet_offset(tp->offset());
2809 PTR ptr = meet_ptr(tp->ptr());
2810 switch (tp->ptr()) {
2811 case TopPTR:
2812 case AnyNull: {
2813 int instance_id = meet_instance_id(InstanceTop);
2814 return make(ptr, klass(), klass_is_exact(),
2815 (ptr == Constant ? const_oop() : NULL), offset, instance_id);
2816 }
2817 case NotNull:
2818 case BotPTR: {
2819 int instance_id = meet_instance_id(tp->instance_id());
2820 return TypeOopPtr::make(ptr, offset, instance_id);
2821 }
2822 default: typerr(t);
2823 }
2824 }
2826 case AnyPtr: { // Meeting to AnyPtrs
2827 // Found an AnyPtr type vs self-InstPtr type
2828 const TypePtr *tp = t->is_ptr();
2829 int offset = meet_offset(tp->offset());
2830 PTR ptr = meet_ptr(tp->ptr());
2831 switch (tp->ptr()) {
2832 case Null:
2833 if( ptr == Null ) return TypePtr::make( AnyPtr, ptr, offset );
2834 // else fall through to AnyNull
2835 case TopPTR:
2836 case AnyNull: {
2837 int instance_id = meet_instance_id(InstanceTop);
2838 return make( ptr, klass(), klass_is_exact(),
2839 (ptr == Constant ? const_oop() : NULL), offset, instance_id);
2840 }
2841 case NotNull:
2842 case BotPTR:
2843 return TypePtr::make( AnyPtr, ptr, offset );
2844 default: typerr(t);
2845 }
2846 }
2848 /*
2849 A-top }
2850 / | \ } Tops
2851 B-top A-any C-top }
2852 | / | \ | } Any-nulls
2853 B-any | C-any }
2854 | | |
2855 B-con A-con C-con } constants; not comparable across classes
2856 | | |
2857 B-not | C-not }
2858 | \ | / | } not-nulls
2859 B-bot A-not C-bot }
2860 \ | / } Bottoms
2861 A-bot }
2862 */
2864 case InstPtr: { // Meeting 2 Oops?
2865 // Found an InstPtr sub-type vs self-InstPtr type
2866 const TypeInstPtr *tinst = t->is_instptr();
2867 int off = meet_offset( tinst->offset() );
2868 PTR ptr = meet_ptr( tinst->ptr() );
2869 int instance_id = meet_instance_id(tinst->instance_id());
2871 // Check for easy case; klasses are equal (and perhaps not loaded!)
2872 // If we have constants, then we created oops so classes are loaded
2873 // and we can handle the constants further down. This case handles
2874 // both-not-loaded or both-loaded classes
2875 if (ptr != Constant && klass()->equals(tinst->klass()) && klass_is_exact() == tinst->klass_is_exact()) {
2876 return make( ptr, klass(), klass_is_exact(), NULL, off, instance_id );
2877 }
2879 // Classes require inspection in the Java klass hierarchy. Must be loaded.
2880 ciKlass* tinst_klass = tinst->klass();
2881 ciKlass* this_klass = this->klass();
2882 bool tinst_xk = tinst->klass_is_exact();
2883 bool this_xk = this->klass_is_exact();
2884 if (!tinst_klass->is_loaded() || !this_klass->is_loaded() ) {
2885 // One of these classes has not been loaded
2886 const TypeInstPtr *unloaded_meet = xmeet_unloaded(tinst);
2887 #ifndef PRODUCT
2888 if( PrintOpto && Verbose ) {
2889 tty->print("meet of unloaded classes resulted in: "); unloaded_meet->dump(); tty->cr();
2890 tty->print(" this == "); this->dump(); tty->cr();
2891 tty->print(" tinst == "); tinst->dump(); tty->cr();
2892 }
2893 #endif
2894 return unloaded_meet;
2895 }
2897 // Handle mixing oops and interfaces first.
2898 if( this_klass->is_interface() && !tinst_klass->is_interface() ) {
2899 ciKlass *tmp = tinst_klass; // Swap interface around
2900 tinst_klass = this_klass;
2901 this_klass = tmp;
2902 bool tmp2 = tinst_xk;
2903 tinst_xk = this_xk;
2904 this_xk = tmp2;
2905 }
2906 if (tinst_klass->is_interface() &&
2907 !(this_klass->is_interface() ||
2908 // Treat java/lang/Object as an honorary interface,
2909 // because we need a bottom for the interface hierarchy.
2910 this_klass == ciEnv::current()->Object_klass())) {
2911 // Oop meets interface!
2913 // See if the oop subtypes (implements) interface.
2914 ciKlass *k;
2915 bool xk;
2916 if( this_klass->is_subtype_of( tinst_klass ) ) {
2917 // Oop indeed subtypes. Now keep oop or interface depending
2918 // on whether we are both above the centerline or either is
2919 // below the centerline. If we are on the centerline
2920 // (e.g., Constant vs. AnyNull interface), use the constant.
2921 k = below_centerline(ptr) ? tinst_klass : this_klass;
2922 // If we are keeping this_klass, keep its exactness too.
2923 xk = below_centerline(ptr) ? tinst_xk : this_xk;
2924 } else { // Does not implement, fall to Object
2925 // Oop does not implement interface, so mixing falls to Object
2926 // just like the verifier does (if both are above the
2927 // centerline fall to interface)
2928 k = above_centerline(ptr) ? tinst_klass : ciEnv::current()->Object_klass();
2929 xk = above_centerline(ptr) ? tinst_xk : false;
2930 // Watch out for Constant vs. AnyNull interface.
2931 if (ptr == Constant) ptr = NotNull; // forget it was a constant
2932 instance_id = InstanceBot;
2933 }
2934 ciObject* o = NULL; // the Constant value, if any
2935 if (ptr == Constant) {
2936 // Find out which constant.
2937 o = (this_klass == klass()) ? const_oop() : tinst->const_oop();
2938 }
2939 return make( ptr, k, xk, o, off, instance_id );
2940 }
2942 // Either oop vs oop or interface vs interface or interface vs Object
2944 // !!! Here's how the symmetry requirement breaks down into invariants:
2945 // If we split one up & one down AND they subtype, take the down man.
2946 // If we split one up & one down AND they do NOT subtype, "fall hard".
2947 // If both are up and they subtype, take the subtype class.
2948 // If both are up and they do NOT subtype, "fall hard".
2949 // If both are down and they subtype, take the supertype class.
2950 // If both are down and they do NOT subtype, "fall hard".
2951 // Constants treated as down.
2953 // Now, reorder the above list; observe that both-down+subtype is also
2954 // "fall hard"; "fall hard" becomes the default case:
2955 // If we split one up & one down AND they subtype, take the down man.
2956 // If both are up and they subtype, take the subtype class.
2958 // If both are down and they subtype, "fall hard".
2959 // If both are down and they do NOT subtype, "fall hard".
2960 // If both are up and they do NOT subtype, "fall hard".
2961 // If we split one up & one down AND they do NOT subtype, "fall hard".
2963 // If a proper subtype is exact, and we return it, we return it exactly.
2964 // If a proper supertype is exact, there can be no subtyping relationship!
2965 // If both types are equal to the subtype, exactness is and-ed below the
2966 // centerline and or-ed above it. (N.B. Constants are always exact.)
2968 // Check for subtyping:
2969 ciKlass *subtype = NULL;
2970 bool subtype_exact = false;
2971 if( tinst_klass->equals(this_klass) ) {
2972 subtype = this_klass;
2973 subtype_exact = below_centerline(ptr) ? (this_xk & tinst_xk) : (this_xk | tinst_xk);
2974 } else if( !tinst_xk && this_klass->is_subtype_of( tinst_klass ) ) {
2975 subtype = this_klass; // Pick subtyping class
2976 subtype_exact = this_xk;
2977 } else if( !this_xk && tinst_klass->is_subtype_of( this_klass ) ) {
2978 subtype = tinst_klass; // Pick subtyping class
2979 subtype_exact = tinst_xk;
2980 }
2982 if( subtype ) {
2983 if( above_centerline(ptr) ) { // both are up?
2984 this_klass = tinst_klass = subtype;
2985 this_xk = tinst_xk = subtype_exact;
2986 } else if( above_centerline(this ->_ptr) && !above_centerline(tinst->_ptr) ) {
2987 this_klass = tinst_klass; // tinst is down; keep down man
2988 this_xk = tinst_xk;
2989 } else if( above_centerline(tinst->_ptr) && !above_centerline(this ->_ptr) ) {
2990 tinst_klass = this_klass; // this is down; keep down man
2991 tinst_xk = this_xk;
2992 } else {
2993 this_xk = subtype_exact; // either they are equal, or we'll do an LCA
2994 }
2995 }
2997 // Check for classes now being equal
2998 if (tinst_klass->equals(this_klass)) {
2999 // If the klasses are equal, the constants may still differ. Fall to
3000 // NotNull if they do (neither constant is NULL; that is a special case
3001 // handled elsewhere).
3002 ciObject* o = NULL; // Assume not constant when done
3003 ciObject* this_oop = const_oop();
3004 ciObject* tinst_oop = tinst->const_oop();
3005 if( ptr == Constant ) {
3006 if (this_oop != NULL && tinst_oop != NULL &&
3007 this_oop->equals(tinst_oop) )
3008 o = this_oop;
3009 else if (above_centerline(this ->_ptr))
3010 o = tinst_oop;
3011 else if (above_centerline(tinst ->_ptr))
3012 o = this_oop;
3013 else
3014 ptr = NotNull;
3015 }
3016 return make( ptr, this_klass, this_xk, o, off, instance_id );
3017 } // Else classes are not equal
3019 // Since klasses are different, we require a LCA in the Java
3020 // class hierarchy - which means we have to fall to at least NotNull.
3021 if( ptr == TopPTR || ptr == AnyNull || ptr == Constant )
3022 ptr = NotNull;
3023 instance_id = InstanceBot;
3025 // Now we find the LCA of Java classes
3026 ciKlass* k = this_klass->least_common_ancestor(tinst_klass);
3027 return make( ptr, k, false, NULL, off, instance_id );
3028 } // End of case InstPtr
3030 case KlassPtr:
3031 return TypeInstPtr::BOTTOM;
3033 } // End of switch
3034 return this; // Return the double constant
3035 }
3038 //------------------------java_mirror_type--------------------------------------
3039 ciType* TypeInstPtr::java_mirror_type() const {
3040 // must be a singleton type
3041 if( const_oop() == NULL ) return NULL;
3043 // must be of type java.lang.Class
3044 if( klass() != ciEnv::current()->Class_klass() ) return NULL;
3046 return const_oop()->as_instance()->java_mirror_type();
3047 }
3050 //------------------------------xdual------------------------------------------
3051 // Dual: do NOT dual on klasses. This means I do NOT understand the Java
3052 // inheritance mechanism.
3053 const Type *TypeInstPtr::xdual() const {
3054 return new TypeInstPtr( dual_ptr(), klass(), klass_is_exact(), const_oop(), dual_offset(), dual_instance_id() );
3055 }
3057 //------------------------------eq---------------------------------------------
3058 // Structural equality check for Type representations
3059 bool TypeInstPtr::eq( const Type *t ) const {
3060 const TypeInstPtr *p = t->is_instptr();
3061 return
3062 klass()->equals(p->klass()) &&
3063 TypeOopPtr::eq(p); // Check sub-type stuff
3064 }
3066 //------------------------------hash-------------------------------------------
3067 // Type-specific hashing function.
3068 int TypeInstPtr::hash(void) const {
3069 int hash = klass()->hash() + TypeOopPtr::hash();
3070 return hash;
3071 }
3073 //------------------------------dump2------------------------------------------
3074 // Dump oop Type
3075 #ifndef PRODUCT
3076 void TypeInstPtr::dump2( Dict &d, uint depth, outputStream *st ) const {
3077 // Print the name of the klass.
3078 klass()->print_name_on(st);
3080 switch( _ptr ) {
3081 case Constant:
3082 // TO DO: Make CI print the hex address of the underlying oop.
3083 if (WizardMode || Verbose) {
3084 const_oop()->print_oop(st);
3085 }
3086 case BotPTR:
3087 if (!WizardMode && !Verbose) {
3088 if( _klass_is_exact ) st->print(":exact");
3089 break;
3090 }
3091 case TopPTR:
3092 case AnyNull:
3093 case NotNull:
3094 st->print(":%s", ptr_msg[_ptr]);
3095 if( _klass_is_exact ) st->print(":exact");
3096 break;
3097 }
3099 if( _offset ) { // Dump offset, if any
3100 if( _offset == OffsetBot ) st->print("+any");
3101 else if( _offset == OffsetTop ) st->print("+unknown");
3102 else st->print("+%d", _offset);
3103 }
3105 st->print(" *");
3106 if (_instance_id == InstanceTop)
3107 st->print(",iid=top");
3108 else if (_instance_id != InstanceBot)
3109 st->print(",iid=%d",_instance_id);
3110 }
3111 #endif
3113 //------------------------------add_offset-------------------------------------
3114 const TypePtr *TypeInstPtr::add_offset( intptr_t offset ) const {
3115 return make( _ptr, klass(), klass_is_exact(), const_oop(), xadd_offset(offset), _instance_id );
3116 }
3118 //=============================================================================
3119 // Convenience common pre-built types.
3120 const TypeAryPtr *TypeAryPtr::RANGE;
3121 const TypeAryPtr *TypeAryPtr::OOPS;
3122 const TypeAryPtr *TypeAryPtr::NARROWOOPS;
3123 const TypeAryPtr *TypeAryPtr::BYTES;
3124 const TypeAryPtr *TypeAryPtr::SHORTS;
3125 const TypeAryPtr *TypeAryPtr::CHARS;
3126 const TypeAryPtr *TypeAryPtr::INTS;
3127 const TypeAryPtr *TypeAryPtr::LONGS;
3128 const TypeAryPtr *TypeAryPtr::FLOATS;
3129 const TypeAryPtr *TypeAryPtr::DOUBLES;
3131 //------------------------------make-------------------------------------------
3132 const TypeAryPtr *TypeAryPtr::make( PTR ptr, const TypeAry *ary, ciKlass* k, bool xk, int offset, int instance_id ) {
3133 assert(!(k == NULL && ary->_elem->isa_int()),
3134 "integral arrays must be pre-equipped with a class");
3135 if (!xk) xk = ary->ary_must_be_exact();
3136 assert(instance_id <= 0 || xk || !UseExactTypes, "instances are always exactly typed");
3137 if (!UseExactTypes) xk = (ptr == Constant);
3138 return (TypeAryPtr*)(new TypeAryPtr(ptr, NULL, ary, k, xk, offset, instance_id))->hashcons();
3139 }
3141 //------------------------------make-------------------------------------------
3142 const TypeAryPtr *TypeAryPtr::make( PTR ptr, ciObject* o, const TypeAry *ary, ciKlass* k, bool xk, int offset, int instance_id ) {
3143 assert(!(k == NULL && ary->_elem->isa_int()),
3144 "integral arrays must be pre-equipped with a class");
3145 assert( (ptr==Constant && o) || (ptr!=Constant && !o), "" );
3146 if (!xk) xk = (o != NULL) || ary->ary_must_be_exact();
3147 assert(instance_id <= 0 || xk || !UseExactTypes, "instances are always exactly typed");
3148 if (!UseExactTypes) xk = (ptr == Constant);
3149 return (TypeAryPtr*)(new TypeAryPtr(ptr, o, ary, k, xk, offset, instance_id))->hashcons();
3150 }
3152 //------------------------------cast_to_ptr_type-------------------------------
3153 const Type *TypeAryPtr::cast_to_ptr_type(PTR ptr) const {
3154 if( ptr == _ptr ) return this;
3155 return make(ptr, const_oop(), _ary, klass(), klass_is_exact(), _offset, _instance_id);
3156 }
3159 //-----------------------------cast_to_exactness-------------------------------
3160 const Type *TypeAryPtr::cast_to_exactness(bool klass_is_exact) const {
3161 if( klass_is_exact == _klass_is_exact ) return this;
3162 if (!UseExactTypes) return this;
3163 if (_ary->ary_must_be_exact()) return this; // cannot clear xk
3164 return make(ptr(), const_oop(), _ary, klass(), klass_is_exact, _offset, _instance_id);
3165 }
3167 //-----------------------------cast_to_instance_id----------------------------
3168 const TypeOopPtr *TypeAryPtr::cast_to_instance_id(int instance_id) const {
3169 if( instance_id == _instance_id ) return this;
3170 return make(_ptr, const_oop(), _ary, klass(), _klass_is_exact, _offset, instance_id);
3171 }
3173 //-----------------------------narrow_size_type-------------------------------
3174 // Local cache for arrayOopDesc::max_array_length(etype),
3175 // which is kind of slow (and cached elsewhere by other users).
3176 static jint max_array_length_cache[T_CONFLICT+1];
3177 static jint max_array_length(BasicType etype) {
3178 jint& cache = max_array_length_cache[etype];
3179 jint res = cache;
3180 if (res == 0) {
3181 switch (etype) {
3182 case T_NARROWOOP:
3183 etype = T_OBJECT;
3184 break;
3185 case T_CONFLICT:
3186 case T_ILLEGAL:
3187 case T_VOID:
3188 etype = T_BYTE; // will produce conservatively high value
3189 }
3190 cache = res = arrayOopDesc::max_array_length(etype);
3191 }
3192 return res;
3193 }
3195 // Narrow the given size type to the index range for the given array base type.
3196 // Return NULL if the resulting int type becomes empty.
3197 const TypeInt* TypeAryPtr::narrow_size_type(const TypeInt* size) const {
3198 jint hi = size->_hi;
3199 jint lo = size->_lo;
3200 jint min_lo = 0;
3201 jint max_hi = max_array_length(elem()->basic_type());
3202 //if (index_not_size) --max_hi; // type of a valid array index, FTR
3203 bool chg = false;
3204 if (lo < min_lo) { lo = min_lo; chg = true; }
3205 if (hi > max_hi) { hi = max_hi; chg = true; }
3206 // Negative length arrays will produce weird intermediate dead fast-path code
3207 if (lo > hi)
3208 return TypeInt::ZERO;
3209 if (!chg)
3210 return size;
3211 return TypeInt::make(lo, hi, Type::WidenMin);
3212 }
3214 //-------------------------------cast_to_size----------------------------------
3215 const TypeAryPtr* TypeAryPtr::cast_to_size(const TypeInt* new_size) const {
3216 assert(new_size != NULL, "");
3217 new_size = narrow_size_type(new_size);
3218 if (new_size == size()) return this;
3219 const TypeAry* new_ary = TypeAry::make(elem(), new_size);
3220 return make(ptr(), const_oop(), new_ary, klass(), klass_is_exact(), _offset, _instance_id);
3221 }
3224 //------------------------------eq---------------------------------------------
3225 // Structural equality check for Type representations
3226 bool TypeAryPtr::eq( const Type *t ) const {
3227 const TypeAryPtr *p = t->is_aryptr();
3228 return
3229 _ary == p->_ary && // Check array
3230 TypeOopPtr::eq(p); // Check sub-parts
3231 }
3233 //------------------------------hash-------------------------------------------
3234 // Type-specific hashing function.
3235 int TypeAryPtr::hash(void) const {
3236 return (intptr_t)_ary + TypeOopPtr::hash();
3237 }
3239 //------------------------------meet-------------------------------------------
3240 // Compute the MEET of two types. It returns a new Type object.
3241 const Type *TypeAryPtr::xmeet( const Type *t ) const {
3242 // Perform a fast test for common case; meeting the same types together.
3243 if( this == t ) return this; // Meeting same type-rep?
3244 // Current "this->_base" is Pointer
3245 switch (t->base()) { // switch on original type
3247 // Mixing ints & oops happens when javac reuses local variables
3248 case Int:
3249 case Long:
3250 case FloatTop:
3251 case FloatCon:
3252 case FloatBot:
3253 case DoubleTop:
3254 case DoubleCon:
3255 case DoubleBot:
3256 case NarrowOop:
3257 case Bottom: // Ye Olde Default
3258 return Type::BOTTOM;
3259 case Top:
3260 return this;
3262 default: // All else is a mistake
3263 typerr(t);
3265 case OopPtr: { // Meeting to OopPtrs
3266 // Found a OopPtr type vs self-AryPtr type
3267 const TypeOopPtr *tp = t->is_oopptr();
3268 int offset = meet_offset(tp->offset());
3269 PTR ptr = meet_ptr(tp->ptr());
3270 switch (tp->ptr()) {
3271 case TopPTR:
3272 case AnyNull: {
3273 int instance_id = meet_instance_id(InstanceTop);
3274 return make(ptr, (ptr == Constant ? const_oop() : NULL),
3275 _ary, _klass, _klass_is_exact, offset, instance_id);
3276 }
3277 case BotPTR:
3278 case NotNull: {
3279 int instance_id = meet_instance_id(tp->instance_id());
3280 return TypeOopPtr::make(ptr, offset, instance_id);
3281 }
3282 default: ShouldNotReachHere();
3283 }
3284 }
3286 case AnyPtr: { // Meeting two AnyPtrs
3287 // Found an AnyPtr type vs self-AryPtr type
3288 const TypePtr *tp = t->is_ptr();
3289 int offset = meet_offset(tp->offset());
3290 PTR ptr = meet_ptr(tp->ptr());
3291 switch (tp->ptr()) {
3292 case TopPTR:
3293 return this;
3294 case BotPTR:
3295 case NotNull:
3296 return TypePtr::make(AnyPtr, ptr, offset);
3297 case Null:
3298 if( ptr == Null ) return TypePtr::make(AnyPtr, ptr, offset);
3299 // else fall through to AnyNull
3300 case AnyNull: {
3301 int instance_id = meet_instance_id(InstanceTop);
3302 return make( ptr, (ptr == Constant ? const_oop() : NULL),
3303 _ary, _klass, _klass_is_exact, offset, instance_id);
3304 }
3305 default: ShouldNotReachHere();
3306 }
3307 }
3309 case RawPtr: return TypePtr::BOTTOM;
3311 case AryPtr: { // Meeting 2 references?
3312 const TypeAryPtr *tap = t->is_aryptr();
3313 int off = meet_offset(tap->offset());
3314 const TypeAry *tary = _ary->meet(tap->_ary)->is_ary();
3315 PTR ptr = meet_ptr(tap->ptr());
3316 int instance_id = meet_instance_id(tap->instance_id());
3317 ciKlass* lazy_klass = NULL;
3318 if (tary->_elem->isa_int()) {
3319 // Integral array element types have irrelevant lattice relations.
3320 // It is the klass that determines array layout, not the element type.
3321 if (_klass == NULL)
3322 lazy_klass = tap->_klass;
3323 else if (tap->_klass == NULL || tap->_klass == _klass) {
3324 lazy_klass = _klass;
3325 } else {
3326 // Something like byte[int+] meets char[int+].
3327 // This must fall to bottom, not (int[-128..65535])[int+].
3328 instance_id = InstanceBot;
3329 tary = TypeAry::make(Type::BOTTOM, tary->_size);
3330 }
3331 }
3332 bool xk;
3333 switch (tap->ptr()) {
3334 case AnyNull:
3335 case TopPTR:
3336 // Compute new klass on demand, do not use tap->_klass
3337 xk = (tap->_klass_is_exact | this->_klass_is_exact);
3338 return make( ptr, const_oop(), tary, lazy_klass, xk, off, instance_id );
3339 case Constant: {
3340 ciObject* o = const_oop();
3341 if( _ptr == Constant ) {
3342 if( tap->const_oop() != NULL && !o->equals(tap->const_oop()) ) {
3343 xk = (klass() == tap->klass());
3344 ptr = NotNull;
3345 o = NULL;
3346 instance_id = InstanceBot;
3347 } else {
3348 xk = true;
3349 }
3350 } else if( above_centerline(_ptr) ) {
3351 o = tap->const_oop();
3352 xk = true;
3353 } else {
3354 xk = this->_klass_is_exact;
3355 }
3356 return TypeAryPtr::make( ptr, o, tary, tap->_klass, xk, off, instance_id );
3357 }
3358 case NotNull:
3359 case BotPTR:
3360 // Compute new klass on demand, do not use tap->_klass
3361 if (above_centerline(this->_ptr))
3362 xk = tap->_klass_is_exact;
3363 else if (above_centerline(tap->_ptr))
3364 xk = this->_klass_is_exact;
3365 else xk = (tap->_klass_is_exact & this->_klass_is_exact) &&
3366 (klass() == tap->klass()); // Only precise for identical arrays
3367 return TypeAryPtr::make( ptr, NULL, tary, lazy_klass, xk, off, instance_id );
3368 default: ShouldNotReachHere();
3369 }
3370 }
3372 // All arrays inherit from Object class
3373 case InstPtr: {
3374 const TypeInstPtr *tp = t->is_instptr();
3375 int offset = meet_offset(tp->offset());
3376 PTR ptr = meet_ptr(tp->ptr());
3377 int instance_id = meet_instance_id(tp->instance_id());
3378 switch (ptr) {
3379 case TopPTR:
3380 case AnyNull: // Fall 'down' to dual of object klass
3381 if( tp->klass()->equals(ciEnv::current()->Object_klass()) ) {
3382 return TypeAryPtr::make( ptr, _ary, _klass, _klass_is_exact, offset, instance_id );
3383 } else {
3384 // cannot subclass, so the meet has to fall badly below the centerline
3385 ptr = NotNull;
3386 instance_id = InstanceBot;
3387 return TypeInstPtr::make( ptr, ciEnv::current()->Object_klass(), false, NULL,offset, instance_id);
3388 }
3389 case Constant:
3390 case NotNull:
3391 case BotPTR: // Fall down to object klass
3392 // LCA is object_klass, but if we subclass from the top we can do better
3393 if (above_centerline(tp->ptr())) {
3394 // If 'tp' is above the centerline and it is Object class
3395 // then we can subclass in the Java class hierarchy.
3396 if( tp->klass()->equals(ciEnv::current()->Object_klass()) ) {
3397 // that is, my array type is a subtype of 'tp' klass
3398 return make( ptr, _ary, _klass, _klass_is_exact, offset, instance_id );
3399 }
3400 }
3401 // The other case cannot happen, since t cannot be a subtype of an array.
3402 // The meet falls down to Object class below centerline.
3403 if( ptr == Constant )
3404 ptr = NotNull;
3405 instance_id = InstanceBot;
3406 return TypeInstPtr::make( ptr, ciEnv::current()->Object_klass(), false, NULL,offset, instance_id);
3407 default: typerr(t);
3408 }
3409 }
3411 case KlassPtr:
3412 return TypeInstPtr::BOTTOM;
3414 }
3415 return this; // Lint noise
3416 }
3418 //------------------------------xdual------------------------------------------
3419 // Dual: compute field-by-field dual
3420 const Type *TypeAryPtr::xdual() const {
3421 return new TypeAryPtr( dual_ptr(), _const_oop, _ary->dual()->is_ary(),_klass, _klass_is_exact, dual_offset(), dual_instance_id() );
3422 }
3424 //----------------------interface_vs_oop---------------------------------------
3425 #ifdef ASSERT
3426 bool TypeAryPtr::interface_vs_oop(const Type *t) const {
3427 const TypeAryPtr* t_aryptr = t->isa_aryptr();
3428 if (t_aryptr) {
3429 return _ary->interface_vs_oop(t_aryptr->_ary);
3430 }
3431 return false;
3432 }
3433 #endif
3435 //------------------------------dump2------------------------------------------
3436 #ifndef PRODUCT
3437 void TypeAryPtr::dump2( Dict &d, uint depth, outputStream *st ) const {
3438 _ary->dump2(d,depth,st);
3439 switch( _ptr ) {
3440 case Constant:
3441 const_oop()->print(st);
3442 break;
3443 case BotPTR:
3444 if (!WizardMode && !Verbose) {
3445 if( _klass_is_exact ) st->print(":exact");
3446 break;
3447 }
3448 case TopPTR:
3449 case AnyNull:
3450 case NotNull:
3451 st->print(":%s", ptr_msg[_ptr]);
3452 if( _klass_is_exact ) st->print(":exact");
3453 break;
3454 }
3456 if( _offset != 0 ) {
3457 int header_size = objArrayOopDesc::header_size() * wordSize;
3458 if( _offset == OffsetTop ) st->print("+undefined");
3459 else if( _offset == OffsetBot ) st->print("+any");
3460 else if( _offset < header_size ) st->print("+%d", _offset);
3461 else {
3462 BasicType basic_elem_type = elem()->basic_type();
3463 int array_base = arrayOopDesc::base_offset_in_bytes(basic_elem_type);
3464 int elem_size = type2aelembytes(basic_elem_type);
3465 st->print("[%d]", (_offset - array_base)/elem_size);
3466 }
3467 }
3468 st->print(" *");
3469 if (_instance_id == InstanceTop)
3470 st->print(",iid=top");
3471 else if (_instance_id != InstanceBot)
3472 st->print(",iid=%d",_instance_id);
3473 }
3474 #endif
3476 bool TypeAryPtr::empty(void) const {
3477 if (_ary->empty()) return true;
3478 return TypeOopPtr::empty();
3479 }
3481 //------------------------------add_offset-------------------------------------
3482 const TypePtr *TypeAryPtr::add_offset( intptr_t offset ) const {
3483 return make( _ptr, _const_oop, _ary, _klass, _klass_is_exact, xadd_offset(offset), _instance_id );
3484 }
3487 //=============================================================================
3488 const TypeNarrowOop *TypeNarrowOop::BOTTOM;
3489 const TypeNarrowOop *TypeNarrowOop::NULL_PTR;
3492 const TypeNarrowOop* TypeNarrowOop::make(const TypePtr* type) {
3493 return (const TypeNarrowOop*)(new TypeNarrowOop(type))->hashcons();
3494 }
3496 //------------------------------hash-------------------------------------------
3497 // Type-specific hashing function.
3498 int TypeNarrowOop::hash(void) const {
3499 return _ptrtype->hash() + 7;
3500 }
3503 bool TypeNarrowOop::eq( const Type *t ) const {
3504 const TypeNarrowOop* tc = t->isa_narrowoop();
3505 if (tc != NULL) {
3506 if (_ptrtype->base() != tc->_ptrtype->base()) {
3507 return false;
3508 }
3509 return tc->_ptrtype->eq(_ptrtype);
3510 }
3511 return false;
3512 }
3514 bool TypeNarrowOop::singleton(void) const { // TRUE if type is a singleton
3515 return _ptrtype->singleton();
3516 }
3518 bool TypeNarrowOop::empty(void) const {
3519 return _ptrtype->empty();
3520 }
3522 //------------------------------xmeet------------------------------------------
3523 // Compute the MEET of two types. It returns a new Type object.
3524 const Type *TypeNarrowOop::xmeet( const Type *t ) const {
3525 // Perform a fast test for common case; meeting the same types together.
3526 if( this == t ) return this; // Meeting same type-rep?
3529 // Current "this->_base" is OopPtr
3530 switch (t->base()) { // switch on original type
3532 case Int: // Mixing ints & oops happens when javac
3533 case Long: // reuses local variables
3534 case FloatTop:
3535 case FloatCon:
3536 case FloatBot:
3537 case DoubleTop:
3538 case DoubleCon:
3539 case DoubleBot:
3540 case AnyPtr:
3541 case RawPtr:
3542 case OopPtr:
3543 case InstPtr:
3544 case KlassPtr:
3545 case AryPtr:
3547 case Bottom: // Ye Olde Default
3548 return Type::BOTTOM;
3549 case Top:
3550 return this;
3552 case NarrowOop: {
3553 const Type* result = _ptrtype->xmeet(t->make_ptr());
3554 if (result->isa_ptr()) {
3555 return TypeNarrowOop::make(result->is_ptr());
3556 }
3557 return result;
3558 }
3560 default: // All else is a mistake
3561 typerr(t);
3563 } // End of switch
3565 return this;
3566 }
3568 const Type *TypeNarrowOop::xdual() const { // Compute dual right now.
3569 const TypePtr* odual = _ptrtype->dual()->is_ptr();
3570 return new TypeNarrowOop(odual);
3571 }
3573 const Type *TypeNarrowOop::filter( const Type *kills ) const {
3574 if (kills->isa_narrowoop()) {
3575 const Type* ft =_ptrtype->filter(kills->is_narrowoop()->_ptrtype);
3576 if (ft->empty())
3577 return Type::TOP; // Canonical empty value
3578 if (ft->isa_ptr()) {
3579 return make(ft->isa_ptr());
3580 }
3581 return ft;
3582 } else if (kills->isa_ptr()) {
3583 const Type* ft = _ptrtype->join(kills);
3584 if (ft->empty())
3585 return Type::TOP; // Canonical empty value
3586 return ft;
3587 } else {
3588 return Type::TOP;
3589 }
3590 }
3593 intptr_t TypeNarrowOop::get_con() const {
3594 return _ptrtype->get_con();
3595 }
3597 #ifndef PRODUCT
3598 void TypeNarrowOop::dump2( Dict & d, uint depth, outputStream *st ) const {
3599 st->print("narrowoop: ");
3600 _ptrtype->dump2(d, depth, st);
3601 }
3602 #endif
3605 //=============================================================================
3606 // Convenience common pre-built types.
3608 // Not-null object klass or below
3609 const TypeKlassPtr *TypeKlassPtr::OBJECT;
3610 const TypeKlassPtr *TypeKlassPtr::OBJECT_OR_NULL;
3612 //------------------------------TypeKlasPtr------------------------------------
3613 TypeKlassPtr::TypeKlassPtr( PTR ptr, ciKlass* klass, int offset )
3614 : TypeOopPtr(KlassPtr, ptr, klass, (ptr==Constant), (ptr==Constant ? klass : NULL), offset, 0) {
3615 }
3617 //------------------------------make-------------------------------------------
3618 // ptr to klass 'k', if Constant, or possibly to a sub-klass if not a Constant
3619 const TypeKlassPtr *TypeKlassPtr::make( PTR ptr, ciKlass* k, int offset ) {
3620 assert( k != NULL, "Expect a non-NULL klass");
3621 assert(k->is_instance_klass() || k->is_array_klass() ||
3622 k->is_method_klass(), "Incorrect type of klass oop");
3623 TypeKlassPtr *r =
3624 (TypeKlassPtr*)(new TypeKlassPtr(ptr, k, offset))->hashcons();
3626 return r;
3627 }
3629 //------------------------------eq---------------------------------------------
3630 // Structural equality check for Type representations
3631 bool TypeKlassPtr::eq( const Type *t ) const {
3632 const TypeKlassPtr *p = t->is_klassptr();
3633 return
3634 klass()->equals(p->klass()) &&
3635 TypeOopPtr::eq(p);
3636 }
3638 //------------------------------hash-------------------------------------------
3639 // Type-specific hashing function.
3640 int TypeKlassPtr::hash(void) const {
3641 return klass()->hash() + TypeOopPtr::hash();
3642 }
3645 //------------------------------klass------------------------------------------
3646 // Return the defining klass for this class
3647 ciKlass* TypeAryPtr::klass() const {
3648 if( _klass ) return _klass; // Return cached value, if possible
3650 // Oops, need to compute _klass and cache it
3651 ciKlass* k_ary = NULL;
3652 const TypeInstPtr *tinst;
3653 const TypeAryPtr *tary;
3654 const Type* el = elem();
3655 if (el->isa_narrowoop()) {
3656 el = el->make_ptr();
3657 }
3659 // Get element klass
3660 if ((tinst = el->isa_instptr()) != NULL) {
3661 // Compute array klass from element klass
3662 k_ary = ciObjArrayKlass::make(tinst->klass());
3663 } else if ((tary = el->isa_aryptr()) != NULL) {
3664 // Compute array klass from element klass
3665 ciKlass* k_elem = tary->klass();
3666 // If element type is something like bottom[], k_elem will be null.
3667 if (k_elem != NULL)
3668 k_ary = ciObjArrayKlass::make(k_elem);
3669 } else if ((el->base() == Type::Top) ||
3670 (el->base() == Type::Bottom)) {
3671 // element type of Bottom occurs from meet of basic type
3672 // and object; Top occurs when doing join on Bottom.
3673 // Leave k_ary at NULL.
3674 } else {
3675 // Cannot compute array klass directly from basic type,
3676 // since subtypes of TypeInt all have basic type T_INT.
3677 assert(!el->isa_int(),
3678 "integral arrays must be pre-equipped with a class");
3679 // Compute array klass directly from basic type
3680 k_ary = ciTypeArrayKlass::make(el->basic_type());
3681 }
3683 if( this != TypeAryPtr::OOPS ) {
3684 // The _klass field acts as a cache of the underlying
3685 // ciKlass for this array type. In order to set the field,
3686 // we need to cast away const-ness.
3687 //
3688 // IMPORTANT NOTE: we *never* set the _klass field for the
3689 // type TypeAryPtr::OOPS. This Type is shared between all
3690 // active compilations. However, the ciKlass which represents
3691 // this Type is *not* shared between compilations, so caching
3692 // this value would result in fetching a dangling pointer.
3693 //
3694 // Recomputing the underlying ciKlass for each request is
3695 // a bit less efficient than caching, but calls to
3696 // TypeAryPtr::OOPS->klass() are not common enough to matter.
3697 ((TypeAryPtr*)this)->_klass = k_ary;
3698 if (UseCompressedOops && k_ary != NULL && k_ary->is_obj_array_klass() &&
3699 _offset != 0 && _offset != arrayOopDesc::length_offset_in_bytes()) {
3700 ((TypeAryPtr*)this)->_is_ptr_to_narrowoop = true;
3701 }
3702 }
3703 return k_ary;
3704 }
3707 //------------------------------add_offset-------------------------------------
3708 // Access internals of klass object
3709 const TypePtr *TypeKlassPtr::add_offset( intptr_t offset ) const {
3710 return make( _ptr, klass(), xadd_offset(offset) );
3711 }
3713 //------------------------------cast_to_ptr_type-------------------------------
3714 const Type *TypeKlassPtr::cast_to_ptr_type(PTR ptr) const {
3715 assert(_base == KlassPtr, "subclass must override cast_to_ptr_type");
3716 if( ptr == _ptr ) return this;
3717 return make(ptr, _klass, _offset);
3718 }
3721 //-----------------------------cast_to_exactness-------------------------------
3722 const Type *TypeKlassPtr::cast_to_exactness(bool klass_is_exact) const {
3723 if( klass_is_exact == _klass_is_exact ) return this;
3724 if (!UseExactTypes) return this;
3725 return make(klass_is_exact ? Constant : NotNull, _klass, _offset);
3726 }
3729 //-----------------------------as_instance_type--------------------------------
3730 // Corresponding type for an instance of the given class.
3731 // It will be NotNull, and exact if and only if the klass type is exact.
3732 const TypeOopPtr* TypeKlassPtr::as_instance_type() const {
3733 ciKlass* k = klass();
3734 bool xk = klass_is_exact();
3735 //return TypeInstPtr::make(TypePtr::NotNull, k, xk, NULL, 0);
3736 const TypeOopPtr* toop = TypeOopPtr::make_from_klass_raw(k);
3737 toop = toop->cast_to_ptr_type(TypePtr::NotNull)->is_oopptr();
3738 return toop->cast_to_exactness(xk)->is_oopptr();
3739 }
3742 //------------------------------xmeet------------------------------------------
3743 // Compute the MEET of two types, return a new Type object.
3744 const Type *TypeKlassPtr::xmeet( const Type *t ) const {
3745 // Perform a fast test for common case; meeting the same types together.
3746 if( this == t ) return this; // Meeting same type-rep?
3748 // Current "this->_base" is Pointer
3749 switch (t->base()) { // switch on original type
3751 case Int: // Mixing ints & oops happens when javac
3752 case Long: // reuses local variables
3753 case FloatTop:
3754 case FloatCon:
3755 case FloatBot:
3756 case DoubleTop:
3757 case DoubleCon:
3758 case DoubleBot:
3759 case NarrowOop:
3760 case Bottom: // Ye Olde Default
3761 return Type::BOTTOM;
3762 case Top:
3763 return this;
3765 default: // All else is a mistake
3766 typerr(t);
3768 case RawPtr: return TypePtr::BOTTOM;
3770 case OopPtr: { // Meeting to OopPtrs
3771 // Found a OopPtr type vs self-KlassPtr type
3772 const TypePtr *tp = t->is_oopptr();
3773 int offset = meet_offset(tp->offset());
3774 PTR ptr = meet_ptr(tp->ptr());
3775 switch (tp->ptr()) {
3776 case TopPTR:
3777 case AnyNull:
3778 return make(ptr, klass(), offset);
3779 case BotPTR:
3780 case NotNull:
3781 return TypePtr::make(AnyPtr, ptr, offset);
3782 default: typerr(t);
3783 }
3784 }
3786 case AnyPtr: { // Meeting to AnyPtrs
3787 // Found an AnyPtr type vs self-KlassPtr type
3788 const TypePtr *tp = t->is_ptr();
3789 int offset = meet_offset(tp->offset());
3790 PTR ptr = meet_ptr(tp->ptr());
3791 switch (tp->ptr()) {
3792 case TopPTR:
3793 return this;
3794 case Null:
3795 if( ptr == Null ) return TypePtr::make( AnyPtr, ptr, offset );
3796 case AnyNull:
3797 return make( ptr, klass(), offset );
3798 case BotPTR:
3799 case NotNull:
3800 return TypePtr::make(AnyPtr, ptr, offset);
3801 default: typerr(t);
3802 }
3803 }
3805 case AryPtr: // Meet with AryPtr
3806 case InstPtr: // Meet with InstPtr
3807 return TypeInstPtr::BOTTOM;
3809 //
3810 // A-top }
3811 // / | \ } Tops
3812 // B-top A-any C-top }
3813 // | / | \ | } Any-nulls
3814 // B-any | C-any }
3815 // | | |
3816 // B-con A-con C-con } constants; not comparable across classes
3817 // | | |
3818 // B-not | C-not }
3819 // | \ | / | } not-nulls
3820 // B-bot A-not C-bot }
3821 // \ | / } Bottoms
3822 // A-bot }
3823 //
3825 case KlassPtr: { // Meet two KlassPtr types
3826 const TypeKlassPtr *tkls = t->is_klassptr();
3827 int off = meet_offset(tkls->offset());
3828 PTR ptr = meet_ptr(tkls->ptr());
3830 // Check for easy case; klasses are equal (and perhaps not loaded!)
3831 // If we have constants, then we created oops so classes are loaded
3832 // and we can handle the constants further down. This case handles
3833 // not-loaded classes
3834 if( ptr != Constant && tkls->klass()->equals(klass()) ) {
3835 return make( ptr, klass(), off );
3836 }
3838 // Classes require inspection in the Java klass hierarchy. Must be loaded.
3839 ciKlass* tkls_klass = tkls->klass();
3840 ciKlass* this_klass = this->klass();
3841 assert( tkls_klass->is_loaded(), "This class should have been loaded.");
3842 assert( this_klass->is_loaded(), "This class should have been loaded.");
3844 // If 'this' type is above the centerline and is a superclass of the
3845 // other, we can treat 'this' as having the same type as the other.
3846 if ((above_centerline(this->ptr())) &&
3847 tkls_klass->is_subtype_of(this_klass)) {
3848 this_klass = tkls_klass;
3849 }
3850 // If 'tinst' type is above the centerline and is a superclass of the
3851 // other, we can treat 'tinst' as having the same type as the other.
3852 if ((above_centerline(tkls->ptr())) &&
3853 this_klass->is_subtype_of(tkls_klass)) {
3854 tkls_klass = this_klass;
3855 }
3857 // Check for classes now being equal
3858 if (tkls_klass->equals(this_klass)) {
3859 // If the klasses are equal, the constants may still differ. Fall to
3860 // NotNull if they do (neither constant is NULL; that is a special case
3861 // handled elsewhere).
3862 ciObject* o = NULL; // Assume not constant when done
3863 ciObject* this_oop = const_oop();
3864 ciObject* tkls_oop = tkls->const_oop();
3865 if( ptr == Constant ) {
3866 if (this_oop != NULL && tkls_oop != NULL &&
3867 this_oop->equals(tkls_oop) )
3868 o = this_oop;
3869 else if (above_centerline(this->ptr()))
3870 o = tkls_oop;
3871 else if (above_centerline(tkls->ptr()))
3872 o = this_oop;
3873 else
3874 ptr = NotNull;
3875 }
3876 return make( ptr, this_klass, off );
3877 } // Else classes are not equal
3879 // Since klasses are different, we require the LCA in the Java
3880 // class hierarchy - which means we have to fall to at least NotNull.
3881 if( ptr == TopPTR || ptr == AnyNull || ptr == Constant )
3882 ptr = NotNull;
3883 // Now we find the LCA of Java classes
3884 ciKlass* k = this_klass->least_common_ancestor(tkls_klass);
3885 return make( ptr, k, off );
3886 } // End of case KlassPtr
3888 } // End of switch
3889 return this; // Return the double constant
3890 }
3892 //------------------------------xdual------------------------------------------
3893 // Dual: compute field-by-field dual
3894 const Type *TypeKlassPtr::xdual() const {
3895 return new TypeKlassPtr( dual_ptr(), klass(), dual_offset() );
3896 }
3898 //------------------------------dump2------------------------------------------
3899 // Dump Klass Type
3900 #ifndef PRODUCT
3901 void TypeKlassPtr::dump2( Dict & d, uint depth, outputStream *st ) const {
3902 switch( _ptr ) {
3903 case Constant:
3904 st->print("precise ");
3905 case NotNull:
3906 {
3907 const char *name = klass()->name()->as_utf8();
3908 if( name ) {
3909 st->print("klass %s: " INTPTR_FORMAT, name, klass());
3910 } else {
3911 ShouldNotReachHere();
3912 }
3913 }
3914 case BotPTR:
3915 if( !WizardMode && !Verbose && !_klass_is_exact ) break;
3916 case TopPTR:
3917 case AnyNull:
3918 st->print(":%s", ptr_msg[_ptr]);
3919 if( _klass_is_exact ) st->print(":exact");
3920 break;
3921 }
3923 if( _offset ) { // Dump offset, if any
3924 if( _offset == OffsetBot ) { st->print("+any"); }
3925 else if( _offset == OffsetTop ) { st->print("+unknown"); }
3926 else { st->print("+%d", _offset); }
3927 }
3929 st->print(" *");
3930 }
3931 #endif
3935 //=============================================================================
3936 // Convenience common pre-built types.
3938 //------------------------------make-------------------------------------------
3939 const TypeFunc *TypeFunc::make( const TypeTuple *domain, const TypeTuple *range ) {
3940 return (TypeFunc*)(new TypeFunc(domain,range))->hashcons();
3941 }
3943 //------------------------------make-------------------------------------------
3944 const TypeFunc *TypeFunc::make(ciMethod* method) {
3945 Compile* C = Compile::current();
3946 const TypeFunc* tf = C->last_tf(method); // check cache
3947 if (tf != NULL) return tf; // The hit rate here is almost 50%.
3948 const TypeTuple *domain;
3949 if (method->flags().is_static()) {
3950 domain = TypeTuple::make_domain(NULL, method->signature());
3951 } else {
3952 domain = TypeTuple::make_domain(method->holder(), method->signature());
3953 }
3954 const TypeTuple *range = TypeTuple::make_range(method->signature());
3955 tf = TypeFunc::make(domain, range);
3956 C->set_last_tf(method, tf); // fill cache
3957 return tf;
3958 }
3960 //------------------------------meet-------------------------------------------
3961 // Compute the MEET of two types. It returns a new Type object.
3962 const Type *TypeFunc::xmeet( const Type *t ) const {
3963 // Perform a fast test for common case; meeting the same types together.
3964 if( this == t ) return this; // Meeting same type-rep?
3966 // Current "this->_base" is Func
3967 switch (t->base()) { // switch on original type
3969 case Bottom: // Ye Olde Default
3970 return t;
3972 default: // All else is a mistake
3973 typerr(t);
3975 case Top:
3976 break;
3977 }
3978 return this; // Return the double constant
3979 }
3981 //------------------------------xdual------------------------------------------
3982 // Dual: compute field-by-field dual
3983 const Type *TypeFunc::xdual() const {
3984 return this;
3985 }
3987 //------------------------------eq---------------------------------------------
3988 // Structural equality check for Type representations
3989 bool TypeFunc::eq( const Type *t ) const {
3990 const TypeFunc *a = (const TypeFunc*)t;
3991 return _domain == a->_domain &&
3992 _range == a->_range;
3993 }
3995 //------------------------------hash-------------------------------------------
3996 // Type-specific hashing function.
3997 int TypeFunc::hash(void) const {
3998 return (intptr_t)_domain + (intptr_t)_range;
3999 }
4001 //------------------------------dump2------------------------------------------
4002 // Dump Function Type
4003 #ifndef PRODUCT
4004 void TypeFunc::dump2( Dict &d, uint depth, outputStream *st ) const {
4005 if( _range->_cnt <= Parms )
4006 st->print("void");
4007 else {
4008 uint i;
4009 for (i = Parms; i < _range->_cnt-1; i++) {
4010 _range->field_at(i)->dump2(d,depth,st);
4011 st->print("/");
4012 }
4013 _range->field_at(i)->dump2(d,depth,st);
4014 }
4015 st->print(" ");
4016 st->print("( ");
4017 if( !depth || d[this] ) { // Check for recursive dump
4018 st->print("...)");
4019 return;
4020 }
4021 d.Insert((void*)this,(void*)this); // Stop recursion
4022 if (Parms < _domain->_cnt)
4023 _domain->field_at(Parms)->dump2(d,depth-1,st);
4024 for (uint i = Parms+1; i < _domain->_cnt; i++) {
4025 st->print(", ");
4026 _domain->field_at(i)->dump2(d,depth-1,st);
4027 }
4028 st->print(" )");
4029 }
4031 //------------------------------print_flattened--------------------------------
4032 // Print a 'flattened' signature
4033 static const char * const flat_type_msg[Type::lastype] = {
4034 "bad","control","top","int","long","_", "narrowoop",
4035 "tuple:", "array:",
4036 "ptr", "rawptr", "ptr", "ptr", "ptr", "ptr",
4037 "func", "abIO", "return_address", "mem",
4038 "float_top", "ftcon:", "flt",
4039 "double_top", "dblcon:", "dbl",
4040 "bottom"
4041 };
4043 void TypeFunc::print_flattened() const {
4044 if( _range->_cnt <= Parms )
4045 tty->print("void");
4046 else {
4047 uint i;
4048 for (i = Parms; i < _range->_cnt-1; i++)
4049 tty->print("%s/",flat_type_msg[_range->field_at(i)->base()]);
4050 tty->print("%s",flat_type_msg[_range->field_at(i)->base()]);
4051 }
4052 tty->print(" ( ");
4053 if (Parms < _domain->_cnt)
4054 tty->print("%s",flat_type_msg[_domain->field_at(Parms)->base()]);
4055 for (uint i = Parms+1; i < _domain->_cnt; i++)
4056 tty->print(", %s",flat_type_msg[_domain->field_at(i)->base()]);
4057 tty->print(" )");
4058 }
4059 #endif
4061 //------------------------------singleton--------------------------------------
4062 // TRUE if Type is a singleton type, FALSE otherwise. Singletons are simple
4063 // constants (Ldi nodes). Singletons are integer, float or double constants
4064 // or a single symbol.
4065 bool TypeFunc::singleton(void) const {
4066 return false; // Never a singleton
4067 }
4069 bool TypeFunc::empty(void) const {
4070 return false; // Never empty
4071 }
4074 BasicType TypeFunc::return_type() const{
4075 if (range()->cnt() == TypeFunc::Parms) {
4076 return T_VOID;
4077 }
4078 return range()->field_at(TypeFunc::Parms)->basic_type();
4079 }