Wed, 13 Apr 2011 14:33:03 -0700
6988308: assert((cnt > 0.0f) && (prob > 0.0f)) failed: Bad frequency assignment in if
Summary: Make sure cnt doesn't become negative and integer overflow doesn't happen.
Reviewed-by: kvn, twisti
1 /*
2 * Copyright (c) 1997, 2011, Oracle and/or its affiliates. All rights reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * This code is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation.
8 *
9 * This code is distributed in the hope that it will be useful, but WITHOUT
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
12 * version 2 for more details (a copy is included in the LICENSE file that
13 * accompanied this code).
14 *
15 * You should have received a copy of the GNU General Public License version
16 * 2 along with this work; if not, write to the Free Software Foundation,
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18 *
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20 * or visit www.oracle.com if you need additional information or have any
21 * questions.
22 *
23 */
25 #include "precompiled.hpp"
26 #include "ci/ciTypeFlow.hpp"
27 #include "classfile/symbolTable.hpp"
28 #include "classfile/systemDictionary.hpp"
29 #include "compiler/compileLog.hpp"
30 #include "libadt/dict.hpp"
31 #include "memory/gcLocker.hpp"
32 #include "memory/oopFactory.hpp"
33 #include "memory/resourceArea.hpp"
34 #include "oops/instanceKlass.hpp"
35 #include "oops/instanceMirrorKlass.hpp"
36 #include "oops/klassKlass.hpp"
37 #include "oops/objArrayKlass.hpp"
38 #include "oops/typeArrayKlass.hpp"
39 #include "opto/matcher.hpp"
40 #include "opto/node.hpp"
41 #include "opto/opcodes.hpp"
42 #include "opto/type.hpp"
44 // Portions of code courtesy of Clifford Click
46 // Optimization - Graph Style
48 // Dictionary of types shared among compilations.
49 Dict* Type::_shared_type_dict = NULL;
51 // Array which maps compiler types to Basic Types
52 const BasicType Type::_basic_type[Type::lastype] = {
53 T_ILLEGAL, // Bad
54 T_ILLEGAL, // Control
55 T_VOID, // Top
56 T_INT, // Int
57 T_LONG, // Long
58 T_VOID, // Half
59 T_NARROWOOP, // NarrowOop
61 T_ILLEGAL, // Tuple
62 T_ARRAY, // Array
64 T_ADDRESS, // AnyPtr // shows up in factory methods for NULL_PTR
65 T_ADDRESS, // RawPtr
66 T_OBJECT, // OopPtr
67 T_OBJECT, // InstPtr
68 T_OBJECT, // AryPtr
69 T_OBJECT, // KlassPtr
71 T_OBJECT, // Function
72 T_ILLEGAL, // Abio
73 T_ADDRESS, // Return_Address
74 T_ILLEGAL, // Memory
75 T_FLOAT, // FloatTop
76 T_FLOAT, // FloatCon
77 T_FLOAT, // FloatBot
78 T_DOUBLE, // DoubleTop
79 T_DOUBLE, // DoubleCon
80 T_DOUBLE, // DoubleBot
81 T_ILLEGAL, // Bottom
82 };
84 // Map ideal registers (machine types) to ideal types
85 const Type *Type::mreg2type[_last_machine_leaf];
87 // Map basic types to canonical Type* pointers.
88 const Type* Type:: _const_basic_type[T_CONFLICT+1];
90 // Map basic types to constant-zero Types.
91 const Type* Type:: _zero_type[T_CONFLICT+1];
93 // Map basic types to array-body alias types.
94 const TypeAryPtr* TypeAryPtr::_array_body_type[T_CONFLICT+1];
96 //=============================================================================
97 // Convenience common pre-built types.
98 const Type *Type::ABIO; // State-of-machine only
99 const Type *Type::BOTTOM; // All values
100 const Type *Type::CONTROL; // Control only
101 const Type *Type::DOUBLE; // All doubles
102 const Type *Type::FLOAT; // All floats
103 const Type *Type::HALF; // Placeholder half of doublewide type
104 const Type *Type::MEMORY; // Abstract store only
105 const Type *Type::RETURN_ADDRESS;
106 const Type *Type::TOP; // No values in set
108 //------------------------------get_const_type---------------------------
109 const Type* Type::get_const_type(ciType* type) {
110 if (type == NULL) {
111 return NULL;
112 } else if (type->is_primitive_type()) {
113 return get_const_basic_type(type->basic_type());
114 } else {
115 return TypeOopPtr::make_from_klass(type->as_klass());
116 }
117 }
119 //---------------------------array_element_basic_type---------------------------------
120 // Mapping to the array element's basic type.
121 BasicType Type::array_element_basic_type() const {
122 BasicType bt = basic_type();
123 if (bt == T_INT) {
124 if (this == TypeInt::INT) return T_INT;
125 if (this == TypeInt::CHAR) return T_CHAR;
126 if (this == TypeInt::BYTE) return T_BYTE;
127 if (this == TypeInt::BOOL) return T_BOOLEAN;
128 if (this == TypeInt::SHORT) return T_SHORT;
129 return T_VOID;
130 }
131 return bt;
132 }
134 //---------------------------get_typeflow_type---------------------------------
135 // Import a type produced by ciTypeFlow.
136 const Type* Type::get_typeflow_type(ciType* type) {
137 switch (type->basic_type()) {
139 case ciTypeFlow::StateVector::T_BOTTOM:
140 assert(type == ciTypeFlow::StateVector::bottom_type(), "");
141 return Type::BOTTOM;
143 case ciTypeFlow::StateVector::T_TOP:
144 assert(type == ciTypeFlow::StateVector::top_type(), "");
145 return Type::TOP;
147 case ciTypeFlow::StateVector::T_NULL:
148 assert(type == ciTypeFlow::StateVector::null_type(), "");
149 return TypePtr::NULL_PTR;
151 case ciTypeFlow::StateVector::T_LONG2:
152 // The ciTypeFlow pass pushes a long, then the half.
153 // We do the same.
154 assert(type == ciTypeFlow::StateVector::long2_type(), "");
155 return TypeInt::TOP;
157 case ciTypeFlow::StateVector::T_DOUBLE2:
158 // The ciTypeFlow pass pushes double, then the half.
159 // Our convention is the same.
160 assert(type == ciTypeFlow::StateVector::double2_type(), "");
161 return Type::TOP;
163 case T_ADDRESS:
164 assert(type->is_return_address(), "");
165 return TypeRawPtr::make((address)(intptr_t)type->as_return_address()->bci());
167 default:
168 // make sure we did not mix up the cases:
169 assert(type != ciTypeFlow::StateVector::bottom_type(), "");
170 assert(type != ciTypeFlow::StateVector::top_type(), "");
171 assert(type != ciTypeFlow::StateVector::null_type(), "");
172 assert(type != ciTypeFlow::StateVector::long2_type(), "");
173 assert(type != ciTypeFlow::StateVector::double2_type(), "");
174 assert(!type->is_return_address(), "");
176 return Type::get_const_type(type);
177 }
178 }
181 //------------------------------make-------------------------------------------
182 // Create a simple Type, with default empty symbol sets. Then hashcons it
183 // and look for an existing copy in the type dictionary.
184 const Type *Type::make( enum TYPES t ) {
185 return (new Type(t))->hashcons();
186 }
188 //------------------------------cmp--------------------------------------------
189 int Type::cmp( const Type *const t1, const Type *const t2 ) {
190 if( t1->_base != t2->_base )
191 return 1; // Missed badly
192 assert(t1 != t2 || t1->eq(t2), "eq must be reflexive");
193 return !t1->eq(t2); // Return ZERO if equal
194 }
196 //------------------------------hash-------------------------------------------
197 int Type::uhash( const Type *const t ) {
198 return t->hash();
199 }
201 #define SMALLINT ((juint)3) // a value too insignificant to consider widening
203 //--------------------------Initialize_shared----------------------------------
204 void Type::Initialize_shared(Compile* current) {
205 // This method does not need to be locked because the first system
206 // compilations (stub compilations) occur serially. If they are
207 // changed to proceed in parallel, then this section will need
208 // locking.
210 Arena* save = current->type_arena();
211 Arena* shared_type_arena = new Arena();
213 current->set_type_arena(shared_type_arena);
214 _shared_type_dict =
215 new (shared_type_arena) Dict( (CmpKey)Type::cmp, (Hash)Type::uhash,
216 shared_type_arena, 128 );
217 current->set_type_dict(_shared_type_dict);
219 // Make shared pre-built types.
220 CONTROL = make(Control); // Control only
221 TOP = make(Top); // No values in set
222 MEMORY = make(Memory); // Abstract store only
223 ABIO = make(Abio); // State-of-machine only
224 RETURN_ADDRESS=make(Return_Address);
225 FLOAT = make(FloatBot); // All floats
226 DOUBLE = make(DoubleBot); // All doubles
227 BOTTOM = make(Bottom); // Everything
228 HALF = make(Half); // Placeholder half of doublewide type
230 TypeF::ZERO = TypeF::make(0.0); // Float 0 (positive zero)
231 TypeF::ONE = TypeF::make(1.0); // Float 1
233 TypeD::ZERO = TypeD::make(0.0); // Double 0 (positive zero)
234 TypeD::ONE = TypeD::make(1.0); // Double 1
236 TypeInt::MINUS_1 = TypeInt::make(-1); // -1
237 TypeInt::ZERO = TypeInt::make( 0); // 0
238 TypeInt::ONE = TypeInt::make( 1); // 1
239 TypeInt::BOOL = TypeInt::make(0,1, WidenMin); // 0 or 1, FALSE or TRUE.
240 TypeInt::CC = TypeInt::make(-1, 1, WidenMin); // -1, 0 or 1, condition codes
241 TypeInt::CC_LT = TypeInt::make(-1,-1, WidenMin); // == TypeInt::MINUS_1
242 TypeInt::CC_GT = TypeInt::make( 1, 1, WidenMin); // == TypeInt::ONE
243 TypeInt::CC_EQ = TypeInt::make( 0, 0, WidenMin); // == TypeInt::ZERO
244 TypeInt::CC_LE = TypeInt::make(-1, 0, WidenMin);
245 TypeInt::CC_GE = TypeInt::make( 0, 1, WidenMin); // == TypeInt::BOOL
246 TypeInt::BYTE = TypeInt::make(-128,127, WidenMin); // Bytes
247 TypeInt::UBYTE = TypeInt::make(0, 255, WidenMin); // Unsigned Bytes
248 TypeInt::CHAR = TypeInt::make(0,65535, WidenMin); // Java chars
249 TypeInt::SHORT = TypeInt::make(-32768,32767, WidenMin); // Java shorts
250 TypeInt::POS = TypeInt::make(0,max_jint, WidenMin); // Non-neg values
251 TypeInt::POS1 = TypeInt::make(1,max_jint, WidenMin); // Positive values
252 TypeInt::INT = TypeInt::make(min_jint,max_jint, WidenMax); // 32-bit integers
253 TypeInt::SYMINT = TypeInt::make(-max_jint,max_jint,WidenMin); // symmetric range
254 // CmpL is overloaded both as the bytecode computation returning
255 // a trinary (-1,0,+1) integer result AND as an efficient long
256 // compare returning optimizer ideal-type flags.
257 assert( TypeInt::CC_LT == TypeInt::MINUS_1, "types must match for CmpL to work" );
258 assert( TypeInt::CC_GT == TypeInt::ONE, "types must match for CmpL to work" );
259 assert( TypeInt::CC_EQ == TypeInt::ZERO, "types must match for CmpL to work" );
260 assert( TypeInt::CC_GE == TypeInt::BOOL, "types must match for CmpL to work" );
261 assert( (juint)(TypeInt::CC->_hi - TypeInt::CC->_lo) <= SMALLINT, "CC is truly small");
263 TypeLong::MINUS_1 = TypeLong::make(-1); // -1
264 TypeLong::ZERO = TypeLong::make( 0); // 0
265 TypeLong::ONE = TypeLong::make( 1); // 1
266 TypeLong::POS = TypeLong::make(0,max_jlong, WidenMin); // Non-neg values
267 TypeLong::LONG = TypeLong::make(min_jlong,max_jlong,WidenMax); // 64-bit integers
268 TypeLong::INT = TypeLong::make((jlong)min_jint,(jlong)max_jint,WidenMin);
269 TypeLong::UINT = TypeLong::make(0,(jlong)max_juint,WidenMin);
271 const Type **fboth =(const Type**)shared_type_arena->Amalloc_4(2*sizeof(Type*));
272 fboth[0] = Type::CONTROL;
273 fboth[1] = Type::CONTROL;
274 TypeTuple::IFBOTH = TypeTuple::make( 2, fboth );
276 const Type **ffalse =(const Type**)shared_type_arena->Amalloc_4(2*sizeof(Type*));
277 ffalse[0] = Type::CONTROL;
278 ffalse[1] = Type::TOP;
279 TypeTuple::IFFALSE = TypeTuple::make( 2, ffalse );
281 const Type **fneither =(const Type**)shared_type_arena->Amalloc_4(2*sizeof(Type*));
282 fneither[0] = Type::TOP;
283 fneither[1] = Type::TOP;
284 TypeTuple::IFNEITHER = TypeTuple::make( 2, fneither );
286 const Type **ftrue =(const Type**)shared_type_arena->Amalloc_4(2*sizeof(Type*));
287 ftrue[0] = Type::TOP;
288 ftrue[1] = Type::CONTROL;
289 TypeTuple::IFTRUE = TypeTuple::make( 2, ftrue );
291 const Type **floop =(const Type**)shared_type_arena->Amalloc_4(2*sizeof(Type*));
292 floop[0] = Type::CONTROL;
293 floop[1] = TypeInt::INT;
294 TypeTuple::LOOPBODY = TypeTuple::make( 2, floop );
296 TypePtr::NULL_PTR= TypePtr::make( AnyPtr, TypePtr::Null, 0 );
297 TypePtr::NOTNULL = TypePtr::make( AnyPtr, TypePtr::NotNull, OffsetBot );
298 TypePtr::BOTTOM = TypePtr::make( AnyPtr, TypePtr::BotPTR, OffsetBot );
300 TypeRawPtr::BOTTOM = TypeRawPtr::make( TypePtr::BotPTR );
301 TypeRawPtr::NOTNULL= TypeRawPtr::make( TypePtr::NotNull );
303 const Type **fmembar = TypeTuple::fields(0);
304 TypeTuple::MEMBAR = TypeTuple::make(TypeFunc::Parms+0, fmembar);
306 const Type **fsc = (const Type**)shared_type_arena->Amalloc_4(2*sizeof(Type*));
307 fsc[0] = TypeInt::CC;
308 fsc[1] = Type::MEMORY;
309 TypeTuple::STORECONDITIONAL = TypeTuple::make(2, fsc);
311 TypeInstPtr::NOTNULL = TypeInstPtr::make(TypePtr::NotNull, current->env()->Object_klass());
312 TypeInstPtr::BOTTOM = TypeInstPtr::make(TypePtr::BotPTR, current->env()->Object_klass());
313 TypeInstPtr::MIRROR = TypeInstPtr::make(TypePtr::NotNull, current->env()->Class_klass());
314 TypeInstPtr::MARK = TypeInstPtr::make(TypePtr::BotPTR, current->env()->Object_klass(),
315 false, 0, oopDesc::mark_offset_in_bytes());
316 TypeInstPtr::KLASS = TypeInstPtr::make(TypePtr::BotPTR, current->env()->Object_klass(),
317 false, 0, oopDesc::klass_offset_in_bytes());
318 TypeOopPtr::BOTTOM = TypeOopPtr::make(TypePtr::BotPTR, OffsetBot, TypeOopPtr::InstanceBot);
320 TypeNarrowOop::NULL_PTR = TypeNarrowOop::make( TypePtr::NULL_PTR );
321 TypeNarrowOop::BOTTOM = TypeNarrowOop::make( TypeInstPtr::BOTTOM );
323 mreg2type[Op_Node] = Type::BOTTOM;
324 mreg2type[Op_Set ] = 0;
325 mreg2type[Op_RegN] = TypeNarrowOop::BOTTOM;
326 mreg2type[Op_RegI] = TypeInt::INT;
327 mreg2type[Op_RegP] = TypePtr::BOTTOM;
328 mreg2type[Op_RegF] = Type::FLOAT;
329 mreg2type[Op_RegD] = Type::DOUBLE;
330 mreg2type[Op_RegL] = TypeLong::LONG;
331 mreg2type[Op_RegFlags] = TypeInt::CC;
333 TypeAryPtr::RANGE = TypeAryPtr::make( TypePtr::BotPTR, TypeAry::make(Type::BOTTOM,TypeInt::POS), NULL /* current->env()->Object_klass() */, false, arrayOopDesc::length_offset_in_bytes());
335 TypeAryPtr::NARROWOOPS = TypeAryPtr::make(TypePtr::BotPTR, TypeAry::make(TypeNarrowOop::BOTTOM, TypeInt::POS), NULL /*ciArrayKlass::make(o)*/, false, Type::OffsetBot);
337 #ifdef _LP64
338 if (UseCompressedOops) {
339 TypeAryPtr::OOPS = TypeAryPtr::NARROWOOPS;
340 } else
341 #endif
342 {
343 // There is no shared klass for Object[]. See note in TypeAryPtr::klass().
344 TypeAryPtr::OOPS = TypeAryPtr::make(TypePtr::BotPTR, TypeAry::make(TypeInstPtr::BOTTOM,TypeInt::POS), NULL /*ciArrayKlass::make(o)*/, false, Type::OffsetBot);
345 }
346 TypeAryPtr::BYTES = TypeAryPtr::make(TypePtr::BotPTR, TypeAry::make(TypeInt::BYTE ,TypeInt::POS), ciTypeArrayKlass::make(T_BYTE), true, Type::OffsetBot);
347 TypeAryPtr::SHORTS = TypeAryPtr::make(TypePtr::BotPTR, TypeAry::make(TypeInt::SHORT ,TypeInt::POS), ciTypeArrayKlass::make(T_SHORT), true, Type::OffsetBot);
348 TypeAryPtr::CHARS = TypeAryPtr::make(TypePtr::BotPTR, TypeAry::make(TypeInt::CHAR ,TypeInt::POS), ciTypeArrayKlass::make(T_CHAR), true, Type::OffsetBot);
349 TypeAryPtr::INTS = TypeAryPtr::make(TypePtr::BotPTR, TypeAry::make(TypeInt::INT ,TypeInt::POS), ciTypeArrayKlass::make(T_INT), true, Type::OffsetBot);
350 TypeAryPtr::LONGS = TypeAryPtr::make(TypePtr::BotPTR, TypeAry::make(TypeLong::LONG ,TypeInt::POS), ciTypeArrayKlass::make(T_LONG), true, Type::OffsetBot);
351 TypeAryPtr::FLOATS = TypeAryPtr::make(TypePtr::BotPTR, TypeAry::make(Type::FLOAT ,TypeInt::POS), ciTypeArrayKlass::make(T_FLOAT), true, Type::OffsetBot);
352 TypeAryPtr::DOUBLES = TypeAryPtr::make(TypePtr::BotPTR, TypeAry::make(Type::DOUBLE ,TypeInt::POS), ciTypeArrayKlass::make(T_DOUBLE), true, Type::OffsetBot);
354 // Nobody should ask _array_body_type[T_NARROWOOP]. Use NULL as assert.
355 TypeAryPtr::_array_body_type[T_NARROWOOP] = NULL;
356 TypeAryPtr::_array_body_type[T_OBJECT] = TypeAryPtr::OOPS;
357 TypeAryPtr::_array_body_type[T_ARRAY] = TypeAryPtr::OOPS; // arrays are stored in oop arrays
358 TypeAryPtr::_array_body_type[T_BYTE] = TypeAryPtr::BYTES;
359 TypeAryPtr::_array_body_type[T_BOOLEAN] = TypeAryPtr::BYTES; // boolean[] is a byte array
360 TypeAryPtr::_array_body_type[T_SHORT] = TypeAryPtr::SHORTS;
361 TypeAryPtr::_array_body_type[T_CHAR] = TypeAryPtr::CHARS;
362 TypeAryPtr::_array_body_type[T_INT] = TypeAryPtr::INTS;
363 TypeAryPtr::_array_body_type[T_LONG] = TypeAryPtr::LONGS;
364 TypeAryPtr::_array_body_type[T_FLOAT] = TypeAryPtr::FLOATS;
365 TypeAryPtr::_array_body_type[T_DOUBLE] = TypeAryPtr::DOUBLES;
367 TypeKlassPtr::OBJECT = TypeKlassPtr::make( TypePtr::NotNull, current->env()->Object_klass(), 0 );
368 TypeKlassPtr::OBJECT_OR_NULL = TypeKlassPtr::make( TypePtr::BotPTR, current->env()->Object_klass(), 0 );
370 const Type **fi2c = TypeTuple::fields(2);
371 fi2c[TypeFunc::Parms+0] = TypeInstPtr::BOTTOM; // methodOop
372 fi2c[TypeFunc::Parms+1] = TypeRawPtr::BOTTOM; // argument pointer
373 TypeTuple::START_I2C = TypeTuple::make(TypeFunc::Parms+2, fi2c);
375 const Type **intpair = TypeTuple::fields(2);
376 intpair[0] = TypeInt::INT;
377 intpair[1] = TypeInt::INT;
378 TypeTuple::INT_PAIR = TypeTuple::make(2, intpair);
380 const Type **longpair = TypeTuple::fields(2);
381 longpair[0] = TypeLong::LONG;
382 longpair[1] = TypeLong::LONG;
383 TypeTuple::LONG_PAIR = TypeTuple::make(2, longpair);
385 _const_basic_type[T_NARROWOOP] = TypeNarrowOop::BOTTOM;
386 _const_basic_type[T_BOOLEAN] = TypeInt::BOOL;
387 _const_basic_type[T_CHAR] = TypeInt::CHAR;
388 _const_basic_type[T_BYTE] = TypeInt::BYTE;
389 _const_basic_type[T_SHORT] = TypeInt::SHORT;
390 _const_basic_type[T_INT] = TypeInt::INT;
391 _const_basic_type[T_LONG] = TypeLong::LONG;
392 _const_basic_type[T_FLOAT] = Type::FLOAT;
393 _const_basic_type[T_DOUBLE] = Type::DOUBLE;
394 _const_basic_type[T_OBJECT] = TypeInstPtr::BOTTOM;
395 _const_basic_type[T_ARRAY] = TypeInstPtr::BOTTOM; // there is no separate bottom for arrays
396 _const_basic_type[T_VOID] = TypePtr::NULL_PTR; // reflection represents void this way
397 _const_basic_type[T_ADDRESS] = TypeRawPtr::BOTTOM; // both interpreter return addresses & random raw ptrs
398 _const_basic_type[T_CONFLICT]= Type::BOTTOM; // why not?
400 _zero_type[T_NARROWOOP] = TypeNarrowOop::NULL_PTR;
401 _zero_type[T_BOOLEAN] = TypeInt::ZERO; // false == 0
402 _zero_type[T_CHAR] = TypeInt::ZERO; // '\0' == 0
403 _zero_type[T_BYTE] = TypeInt::ZERO; // 0x00 == 0
404 _zero_type[T_SHORT] = TypeInt::ZERO; // 0x0000 == 0
405 _zero_type[T_INT] = TypeInt::ZERO;
406 _zero_type[T_LONG] = TypeLong::ZERO;
407 _zero_type[T_FLOAT] = TypeF::ZERO;
408 _zero_type[T_DOUBLE] = TypeD::ZERO;
409 _zero_type[T_OBJECT] = TypePtr::NULL_PTR;
410 _zero_type[T_ARRAY] = TypePtr::NULL_PTR; // null array is null oop
411 _zero_type[T_ADDRESS] = TypePtr::NULL_PTR; // raw pointers use the same null
412 _zero_type[T_VOID] = Type::TOP; // the only void value is no value at all
414 // get_zero_type() should not happen for T_CONFLICT
415 _zero_type[T_CONFLICT]= NULL;
417 // Restore working type arena.
418 current->set_type_arena(save);
419 current->set_type_dict(NULL);
420 }
422 //------------------------------Initialize-------------------------------------
423 void Type::Initialize(Compile* current) {
424 assert(current->type_arena() != NULL, "must have created type arena");
426 if (_shared_type_dict == NULL) {
427 Initialize_shared(current);
428 }
430 Arena* type_arena = current->type_arena();
432 // Create the hash-cons'ing dictionary with top-level storage allocation
433 Dict *tdic = new (type_arena) Dict( (CmpKey)Type::cmp,(Hash)Type::uhash, type_arena, 128 );
434 current->set_type_dict(tdic);
436 // Transfer the shared types.
437 DictI i(_shared_type_dict);
438 for( ; i.test(); ++i ) {
439 Type* t = (Type*)i._value;
440 tdic->Insert(t,t); // New Type, insert into Type table
441 }
443 #ifdef ASSERT
444 verify_lastype();
445 #endif
446 }
448 //------------------------------hashcons---------------------------------------
449 // Do the hash-cons trick. If the Type already exists in the type table,
450 // delete the current Type and return the existing Type. Otherwise stick the
451 // current Type in the Type table.
452 const Type *Type::hashcons(void) {
453 debug_only(base()); // Check the assertion in Type::base().
454 // Look up the Type in the Type dictionary
455 Dict *tdic = type_dict();
456 Type* old = (Type*)(tdic->Insert(this, this, false));
457 if( old ) { // Pre-existing Type?
458 if( old != this ) // Yes, this guy is not the pre-existing?
459 delete this; // Yes, Nuke this guy
460 assert( old->_dual, "" );
461 return old; // Return pre-existing
462 }
464 // Every type has a dual (to make my lattice symmetric).
465 // Since we just discovered a new Type, compute its dual right now.
466 assert( !_dual, "" ); // No dual yet
467 _dual = xdual(); // Compute the dual
468 if( cmp(this,_dual)==0 ) { // Handle self-symmetric
469 _dual = this;
470 return this;
471 }
472 assert( !_dual->_dual, "" ); // No reverse dual yet
473 assert( !(*tdic)[_dual], "" ); // Dual not in type system either
474 // New Type, insert into Type table
475 tdic->Insert((void*)_dual,(void*)_dual);
476 ((Type*)_dual)->_dual = this; // Finish up being symmetric
477 #ifdef ASSERT
478 Type *dual_dual = (Type*)_dual->xdual();
479 assert( eq(dual_dual), "xdual(xdual()) should be identity" );
480 delete dual_dual;
481 #endif
482 return this; // Return new Type
483 }
485 //------------------------------eq---------------------------------------------
486 // Structural equality check for Type representations
487 bool Type::eq( const Type * ) const {
488 return true; // Nothing else can go wrong
489 }
491 //------------------------------hash-------------------------------------------
492 // Type-specific hashing function.
493 int Type::hash(void) const {
494 return _base;
495 }
497 //------------------------------is_finite--------------------------------------
498 // Has a finite value
499 bool Type::is_finite() const {
500 return false;
501 }
503 //------------------------------is_nan-----------------------------------------
504 // Is not a number (NaN)
505 bool Type::is_nan() const {
506 return false;
507 }
509 //----------------------interface_vs_oop---------------------------------------
510 #ifdef ASSERT
511 bool Type::interface_vs_oop(const Type *t) const {
512 bool result = false;
514 const TypePtr* this_ptr = this->make_ptr(); // In case it is narrow_oop
515 const TypePtr* t_ptr = t->make_ptr();
516 if( this_ptr == NULL || t_ptr == NULL )
517 return result;
519 const TypeInstPtr* this_inst = this_ptr->isa_instptr();
520 const TypeInstPtr* t_inst = t_ptr->isa_instptr();
521 if( this_inst && this_inst->is_loaded() && t_inst && t_inst->is_loaded() ) {
522 bool this_interface = this_inst->klass()->is_interface();
523 bool t_interface = t_inst->klass()->is_interface();
524 result = this_interface ^ t_interface;
525 }
527 return result;
528 }
529 #endif
531 //------------------------------meet-------------------------------------------
532 // Compute the MEET of two types. NOT virtual. It enforces that meet is
533 // commutative and the lattice is symmetric.
534 const Type *Type::meet( const Type *t ) const {
535 if (isa_narrowoop() && t->isa_narrowoop()) {
536 const Type* result = make_ptr()->meet(t->make_ptr());
537 return result->make_narrowoop();
538 }
540 const Type *mt = xmeet(t);
541 if (isa_narrowoop() || t->isa_narrowoop()) return mt;
542 #ifdef ASSERT
543 assert( mt == t->xmeet(this), "meet not commutative" );
544 const Type* dual_join = mt->_dual;
545 const Type *t2t = dual_join->xmeet(t->_dual);
546 const Type *t2this = dual_join->xmeet( _dual);
548 // Interface meet Oop is Not Symmetric:
549 // Interface:AnyNull meet Oop:AnyNull == Interface:AnyNull
550 // Interface:NotNull meet Oop:NotNull == java/lang/Object:NotNull
552 if( !interface_vs_oop(t) && (t2t != t->_dual || t2this != _dual) ) {
553 tty->print_cr("=== Meet Not Symmetric ===");
554 tty->print("t = "); t->dump(); tty->cr();
555 tty->print("this= "); dump(); tty->cr();
556 tty->print("mt=(t meet this)= "); mt->dump(); tty->cr();
558 tty->print("t_dual= "); t->_dual->dump(); tty->cr();
559 tty->print("this_dual= "); _dual->dump(); tty->cr();
560 tty->print("mt_dual= "); mt->_dual->dump(); tty->cr();
562 tty->print("mt_dual meet t_dual= "); t2t ->dump(); tty->cr();
563 tty->print("mt_dual meet this_dual= "); t2this ->dump(); tty->cr();
565 fatal("meet not symmetric" );
566 }
567 #endif
568 return mt;
569 }
571 //------------------------------xmeet------------------------------------------
572 // Compute the MEET of two types. It returns a new Type object.
573 const Type *Type::xmeet( const Type *t ) const {
574 // Perform a fast test for common case; meeting the same types together.
575 if( this == t ) return this; // Meeting same type-rep?
577 // Meeting TOP with anything?
578 if( _base == Top ) return t;
580 // Meeting BOTTOM with anything?
581 if( _base == Bottom ) return BOTTOM;
583 // Current "this->_base" is one of: Bad, Multi, Control, Top,
584 // Abio, Abstore, Floatxxx, Doublexxx, Bottom, lastype.
585 switch (t->base()) { // Switch on original type
587 // Cut in half the number of cases I must handle. Only need cases for when
588 // the given enum "t->type" is less than or equal to the local enum "type".
589 case FloatCon:
590 case DoubleCon:
591 case Int:
592 case Long:
593 return t->xmeet(this);
595 case OopPtr:
596 return t->xmeet(this);
598 case InstPtr:
599 return t->xmeet(this);
601 case KlassPtr:
602 return t->xmeet(this);
604 case AryPtr:
605 return t->xmeet(this);
607 case NarrowOop:
608 return t->xmeet(this);
610 case Bad: // Type check
611 default: // Bogus type not in lattice
612 typerr(t);
613 return Type::BOTTOM;
615 case Bottom: // Ye Olde Default
616 return t;
618 case FloatTop:
619 if( _base == FloatTop ) return this;
620 case FloatBot: // Float
621 if( _base == FloatBot || _base == FloatTop ) return FLOAT;
622 if( _base == DoubleTop || _base == DoubleBot ) return Type::BOTTOM;
623 typerr(t);
624 return Type::BOTTOM;
626 case DoubleTop:
627 if( _base == DoubleTop ) return this;
628 case DoubleBot: // Double
629 if( _base == DoubleBot || _base == DoubleTop ) return DOUBLE;
630 if( _base == FloatTop || _base == FloatBot ) return Type::BOTTOM;
631 typerr(t);
632 return Type::BOTTOM;
634 // These next few cases must match exactly or it is a compile-time error.
635 case Control: // Control of code
636 case Abio: // State of world outside of program
637 case Memory:
638 if( _base == t->_base ) return this;
639 typerr(t);
640 return Type::BOTTOM;
642 case Top: // Top of the lattice
643 return this;
644 }
646 // The type is unchanged
647 return this;
648 }
650 //-----------------------------filter------------------------------------------
651 const Type *Type::filter( const Type *kills ) const {
652 const Type* ft = join(kills);
653 if (ft->empty())
654 return Type::TOP; // Canonical empty value
655 return ft;
656 }
658 //------------------------------xdual------------------------------------------
659 // Compute dual right now.
660 const Type::TYPES Type::dual_type[Type::lastype] = {
661 Bad, // Bad
662 Control, // Control
663 Bottom, // Top
664 Bad, // Int - handled in v-call
665 Bad, // Long - handled in v-call
666 Half, // Half
667 Bad, // NarrowOop - handled in v-call
669 Bad, // Tuple - handled in v-call
670 Bad, // Array - handled in v-call
672 Bad, // AnyPtr - handled in v-call
673 Bad, // RawPtr - handled in v-call
674 Bad, // OopPtr - handled in v-call
675 Bad, // InstPtr - handled in v-call
676 Bad, // AryPtr - handled in v-call
677 Bad, // KlassPtr - handled in v-call
679 Bad, // Function - handled in v-call
680 Abio, // Abio
681 Return_Address,// Return_Address
682 Memory, // Memory
683 FloatBot, // FloatTop
684 FloatCon, // FloatCon
685 FloatTop, // FloatBot
686 DoubleBot, // DoubleTop
687 DoubleCon, // DoubleCon
688 DoubleTop, // DoubleBot
689 Top // Bottom
690 };
692 const Type *Type::xdual() const {
693 // Note: the base() accessor asserts the sanity of _base.
694 assert(dual_type[base()] != Bad, "implement with v-call");
695 return new Type(dual_type[_base]);
696 }
698 //------------------------------has_memory-------------------------------------
699 bool Type::has_memory() const {
700 Type::TYPES tx = base();
701 if (tx == Memory) return true;
702 if (tx == Tuple) {
703 const TypeTuple *t = is_tuple();
704 for (uint i=0; i < t->cnt(); i++) {
705 tx = t->field_at(i)->base();
706 if (tx == Memory) return true;
707 }
708 }
709 return false;
710 }
712 #ifndef PRODUCT
713 //------------------------------dump2------------------------------------------
714 void Type::dump2( Dict &d, uint depth, outputStream *st ) const {
715 st->print(msg[_base]);
716 }
718 //------------------------------dump-------------------------------------------
719 void Type::dump_on(outputStream *st) const {
720 ResourceMark rm;
721 Dict d(cmpkey,hashkey); // Stop recursive type dumping
722 dump2(d,1, st);
723 if (is_ptr_to_narrowoop()) {
724 st->print(" [narrow]");
725 }
726 }
728 //------------------------------data-------------------------------------------
729 const char * const Type::msg[Type::lastype] = {
730 "bad","control","top","int:","long:","half", "narrowoop:",
731 "tuple:", "aryptr",
732 "anyptr:", "rawptr:", "java:", "inst:", "ary:", "klass:",
733 "func", "abIO", "return_address", "memory",
734 "float_top", "ftcon:", "float",
735 "double_top", "dblcon:", "double",
736 "bottom"
737 };
738 #endif
740 //------------------------------singleton--------------------------------------
741 // TRUE if Type is a singleton type, FALSE otherwise. Singletons are simple
742 // constants (Ldi nodes). Singletons are integer, float or double constants.
743 bool Type::singleton(void) const {
744 return _base == Top || _base == Half;
745 }
747 //------------------------------empty------------------------------------------
748 // TRUE if Type is a type with no values, FALSE otherwise.
749 bool Type::empty(void) const {
750 switch (_base) {
751 case DoubleTop:
752 case FloatTop:
753 case Top:
754 return true;
756 case Half:
757 case Abio:
758 case Return_Address:
759 case Memory:
760 case Bottom:
761 case FloatBot:
762 case DoubleBot:
763 return false; // never a singleton, therefore never empty
764 }
766 ShouldNotReachHere();
767 return false;
768 }
770 //------------------------------dump_stats-------------------------------------
771 // Dump collected statistics to stderr
772 #ifndef PRODUCT
773 void Type::dump_stats() {
774 tty->print("Types made: %d\n", type_dict()->Size());
775 }
776 #endif
778 //------------------------------typerr-----------------------------------------
779 void Type::typerr( const Type *t ) const {
780 #ifndef PRODUCT
781 tty->print("\nError mixing types: ");
782 dump();
783 tty->print(" and ");
784 t->dump();
785 tty->print("\n");
786 #endif
787 ShouldNotReachHere();
788 }
790 //------------------------------isa_oop_ptr------------------------------------
791 // Return true if type is an oop pointer type. False for raw pointers.
792 static char isa_oop_ptr_tbl[Type::lastype] = {
793 0,0,0,0,0,0,0/*narrowoop*/,0/*tuple*/, 0/*ary*/,
794 0/*anyptr*/,0/*rawptr*/,1/*OopPtr*/,1/*InstPtr*/,1/*AryPtr*/,1/*KlassPtr*/,
795 0/*func*/,0,0/*return_address*/,0,
796 /*floats*/0,0,0, /*doubles*/0,0,0,
797 0
798 };
799 bool Type::isa_oop_ptr() const {
800 return isa_oop_ptr_tbl[_base] != 0;
801 }
803 //------------------------------dump_stats-------------------------------------
804 // // Check that arrays match type enum
805 #ifndef PRODUCT
806 void Type::verify_lastype() {
807 // Check that arrays match enumeration
808 assert( Type::dual_type [Type::lastype - 1] == Type::Top, "did not update array");
809 assert( strcmp(Type::msg [Type::lastype - 1],"bottom") == 0, "did not update array");
810 // assert( PhiNode::tbl [Type::lastype - 1] == NULL, "did not update array");
811 assert( Matcher::base2reg[Type::lastype - 1] == 0, "did not update array");
812 assert( isa_oop_ptr_tbl [Type::lastype - 1] == (char)0, "did not update array");
813 }
814 #endif
816 //=============================================================================
817 // Convenience common pre-built types.
818 const TypeF *TypeF::ZERO; // Floating point zero
819 const TypeF *TypeF::ONE; // Floating point one
821 //------------------------------make-------------------------------------------
822 // Create a float constant
823 const TypeF *TypeF::make(float f) {
824 return (TypeF*)(new TypeF(f))->hashcons();
825 }
827 //------------------------------meet-------------------------------------------
828 // Compute the MEET of two types. It returns a new Type object.
829 const Type *TypeF::xmeet( const Type *t ) const {
830 // Perform a fast test for common case; meeting the same types together.
831 if( this == t ) return this; // Meeting same type-rep?
833 // Current "this->_base" is FloatCon
834 switch (t->base()) { // Switch on original type
835 case AnyPtr: // Mixing with oops happens when javac
836 case RawPtr: // reuses local variables
837 case OopPtr:
838 case InstPtr:
839 case KlassPtr:
840 case AryPtr:
841 case NarrowOop:
842 case Int:
843 case Long:
844 case DoubleTop:
845 case DoubleCon:
846 case DoubleBot:
847 case Bottom: // Ye Olde Default
848 return Type::BOTTOM;
850 case FloatBot:
851 return t;
853 default: // All else is a mistake
854 typerr(t);
856 case FloatCon: // Float-constant vs Float-constant?
857 if( jint_cast(_f) != jint_cast(t->getf()) ) // unequal constants?
858 // must compare bitwise as positive zero, negative zero and NaN have
859 // all the same representation in C++
860 return FLOAT; // Return generic float
861 // Equal constants
862 case Top:
863 case FloatTop:
864 break; // Return the float constant
865 }
866 return this; // Return the float constant
867 }
869 //------------------------------xdual------------------------------------------
870 // Dual: symmetric
871 const Type *TypeF::xdual() const {
872 return this;
873 }
875 //------------------------------eq---------------------------------------------
876 // Structural equality check for Type representations
877 bool TypeF::eq( const Type *t ) const {
878 if( g_isnan(_f) ||
879 g_isnan(t->getf()) ) {
880 // One or both are NANs. If both are NANs return true, else false.
881 return (g_isnan(_f) && g_isnan(t->getf()));
882 }
883 if (_f == t->getf()) {
884 // (NaN is impossible at this point, since it is not equal even to itself)
885 if (_f == 0.0) {
886 // difference between positive and negative zero
887 if (jint_cast(_f) != jint_cast(t->getf())) return false;
888 }
889 return true;
890 }
891 return false;
892 }
894 //------------------------------hash-------------------------------------------
895 // Type-specific hashing function.
896 int TypeF::hash(void) const {
897 return *(int*)(&_f);
898 }
900 //------------------------------is_finite--------------------------------------
901 // Has a finite value
902 bool TypeF::is_finite() const {
903 return g_isfinite(getf()) != 0;
904 }
906 //------------------------------is_nan-----------------------------------------
907 // Is not a number (NaN)
908 bool TypeF::is_nan() const {
909 return g_isnan(getf()) != 0;
910 }
912 //------------------------------dump2------------------------------------------
913 // Dump float constant Type
914 #ifndef PRODUCT
915 void TypeF::dump2( Dict &d, uint depth, outputStream *st ) const {
916 Type::dump2(d,depth, st);
917 st->print("%f", _f);
918 }
919 #endif
921 //------------------------------singleton--------------------------------------
922 // TRUE if Type is a singleton type, FALSE otherwise. Singletons are simple
923 // constants (Ldi nodes). Singletons are integer, float or double constants
924 // or a single symbol.
925 bool TypeF::singleton(void) const {
926 return true; // Always a singleton
927 }
929 bool TypeF::empty(void) const {
930 return false; // always exactly a singleton
931 }
933 //=============================================================================
934 // Convenience common pre-built types.
935 const TypeD *TypeD::ZERO; // Floating point zero
936 const TypeD *TypeD::ONE; // Floating point one
938 //------------------------------make-------------------------------------------
939 const TypeD *TypeD::make(double d) {
940 return (TypeD*)(new TypeD(d))->hashcons();
941 }
943 //------------------------------meet-------------------------------------------
944 // Compute the MEET of two types. It returns a new Type object.
945 const Type *TypeD::xmeet( const Type *t ) const {
946 // Perform a fast test for common case; meeting the same types together.
947 if( this == t ) return this; // Meeting same type-rep?
949 // Current "this->_base" is DoubleCon
950 switch (t->base()) { // Switch on original type
951 case AnyPtr: // Mixing with oops happens when javac
952 case RawPtr: // reuses local variables
953 case OopPtr:
954 case InstPtr:
955 case KlassPtr:
956 case AryPtr:
957 case NarrowOop:
958 case Int:
959 case Long:
960 case FloatTop:
961 case FloatCon:
962 case FloatBot:
963 case Bottom: // Ye Olde Default
964 return Type::BOTTOM;
966 case DoubleBot:
967 return t;
969 default: // All else is a mistake
970 typerr(t);
972 case DoubleCon: // Double-constant vs Double-constant?
973 if( jlong_cast(_d) != jlong_cast(t->getd()) ) // unequal constants? (see comment in TypeF::xmeet)
974 return DOUBLE; // Return generic double
975 case Top:
976 case DoubleTop:
977 break;
978 }
979 return this; // Return the double constant
980 }
982 //------------------------------xdual------------------------------------------
983 // Dual: symmetric
984 const Type *TypeD::xdual() const {
985 return this;
986 }
988 //------------------------------eq---------------------------------------------
989 // Structural equality check for Type representations
990 bool TypeD::eq( const Type *t ) const {
991 if( g_isnan(_d) ||
992 g_isnan(t->getd()) ) {
993 // One or both are NANs. If both are NANs return true, else false.
994 return (g_isnan(_d) && g_isnan(t->getd()));
995 }
996 if (_d == t->getd()) {
997 // (NaN is impossible at this point, since it is not equal even to itself)
998 if (_d == 0.0) {
999 // difference between positive and negative zero
1000 if (jlong_cast(_d) != jlong_cast(t->getd())) return false;
1001 }
1002 return true;
1003 }
1004 return false;
1005 }
1007 //------------------------------hash-------------------------------------------
1008 // Type-specific hashing function.
1009 int TypeD::hash(void) const {
1010 return *(int*)(&_d);
1011 }
1013 //------------------------------is_finite--------------------------------------
1014 // Has a finite value
1015 bool TypeD::is_finite() const {
1016 return g_isfinite(getd()) != 0;
1017 }
1019 //------------------------------is_nan-----------------------------------------
1020 // Is not a number (NaN)
1021 bool TypeD::is_nan() const {
1022 return g_isnan(getd()) != 0;
1023 }
1025 //------------------------------dump2------------------------------------------
1026 // Dump double constant Type
1027 #ifndef PRODUCT
1028 void TypeD::dump2( Dict &d, uint depth, outputStream *st ) const {
1029 Type::dump2(d,depth,st);
1030 st->print("%f", _d);
1031 }
1032 #endif
1034 //------------------------------singleton--------------------------------------
1035 // TRUE if Type is a singleton type, FALSE otherwise. Singletons are simple
1036 // constants (Ldi nodes). Singletons are integer, float or double constants
1037 // or a single symbol.
1038 bool TypeD::singleton(void) const {
1039 return true; // Always a singleton
1040 }
1042 bool TypeD::empty(void) const {
1043 return false; // always exactly a singleton
1044 }
1046 //=============================================================================
1047 // Convience common pre-built types.
1048 const TypeInt *TypeInt::MINUS_1;// -1
1049 const TypeInt *TypeInt::ZERO; // 0
1050 const TypeInt *TypeInt::ONE; // 1
1051 const TypeInt *TypeInt::BOOL; // 0 or 1, FALSE or TRUE.
1052 const TypeInt *TypeInt::CC; // -1,0 or 1, condition codes
1053 const TypeInt *TypeInt::CC_LT; // [-1] == MINUS_1
1054 const TypeInt *TypeInt::CC_GT; // [1] == ONE
1055 const TypeInt *TypeInt::CC_EQ; // [0] == ZERO
1056 const TypeInt *TypeInt::CC_LE; // [-1,0]
1057 const TypeInt *TypeInt::CC_GE; // [0,1] == BOOL (!)
1058 const TypeInt *TypeInt::BYTE; // Bytes, -128 to 127
1059 const TypeInt *TypeInt::UBYTE; // Unsigned Bytes, 0 to 255
1060 const TypeInt *TypeInt::CHAR; // Java chars, 0-65535
1061 const TypeInt *TypeInt::SHORT; // Java shorts, -32768-32767
1062 const TypeInt *TypeInt::POS; // Positive 32-bit integers or zero
1063 const TypeInt *TypeInt::POS1; // Positive 32-bit integers
1064 const TypeInt *TypeInt::INT; // 32-bit integers
1065 const TypeInt *TypeInt::SYMINT; // symmetric range [-max_jint..max_jint]
1067 //------------------------------TypeInt----------------------------------------
1068 TypeInt::TypeInt( jint lo, jint hi, int w ) : Type(Int), _lo(lo), _hi(hi), _widen(w) {
1069 }
1071 //------------------------------make-------------------------------------------
1072 const TypeInt *TypeInt::make( jint lo ) {
1073 return (TypeInt*)(new TypeInt(lo,lo,WidenMin))->hashcons();
1074 }
1076 static int normalize_int_widen( jint lo, jint hi, int w ) {
1077 // Certain normalizations keep us sane when comparing types.
1078 // The 'SMALLINT' covers constants and also CC and its relatives.
1079 if (lo <= hi) {
1080 if ((juint)(hi - lo) <= SMALLINT) w = Type::WidenMin;
1081 if ((juint)(hi - lo) >= max_juint) w = Type::WidenMax; // TypeInt::INT
1082 } else {
1083 if ((juint)(lo - hi) <= SMALLINT) w = Type::WidenMin;
1084 if ((juint)(lo - hi) >= max_juint) w = Type::WidenMin; // dual TypeInt::INT
1085 }
1086 return w;
1087 }
1089 const TypeInt *TypeInt::make( jint lo, jint hi, int w ) {
1090 w = normalize_int_widen(lo, hi, w);
1091 return (TypeInt*)(new TypeInt(lo,hi,w))->hashcons();
1092 }
1094 //------------------------------meet-------------------------------------------
1095 // Compute the MEET of two types. It returns a new Type representation object
1096 // with reference count equal to the number of Types pointing at it.
1097 // Caller should wrap a Types around it.
1098 const Type *TypeInt::xmeet( const Type *t ) const {
1099 // Perform a fast test for common case; meeting the same types together.
1100 if( this == t ) return this; // Meeting same type?
1102 // Currently "this->_base" is a TypeInt
1103 switch (t->base()) { // Switch on original type
1104 case AnyPtr: // Mixing with oops happens when javac
1105 case RawPtr: // reuses local variables
1106 case OopPtr:
1107 case InstPtr:
1108 case KlassPtr:
1109 case AryPtr:
1110 case NarrowOop:
1111 case Long:
1112 case FloatTop:
1113 case FloatCon:
1114 case FloatBot:
1115 case DoubleTop:
1116 case DoubleCon:
1117 case DoubleBot:
1118 case Bottom: // Ye Olde Default
1119 return Type::BOTTOM;
1120 default: // All else is a mistake
1121 typerr(t);
1122 case Top: // No change
1123 return this;
1124 case Int: // Int vs Int?
1125 break;
1126 }
1128 // Expand covered set
1129 const TypeInt *r = t->is_int();
1130 return make( MIN2(_lo,r->_lo), MAX2(_hi,r->_hi), MAX2(_widen,r->_widen) );
1131 }
1133 //------------------------------xdual------------------------------------------
1134 // Dual: reverse hi & lo; flip widen
1135 const Type *TypeInt::xdual() const {
1136 int w = normalize_int_widen(_hi,_lo, WidenMax-_widen);
1137 return new TypeInt(_hi,_lo,w);
1138 }
1140 //------------------------------widen------------------------------------------
1141 // Only happens for optimistic top-down optimizations.
1142 const Type *TypeInt::widen( const Type *old, const Type* limit ) const {
1143 // Coming from TOP or such; no widening
1144 if( old->base() != Int ) return this;
1145 const TypeInt *ot = old->is_int();
1147 // If new guy is equal to old guy, no widening
1148 if( _lo == ot->_lo && _hi == ot->_hi )
1149 return old;
1151 // If new guy contains old, then we widened
1152 if( _lo <= ot->_lo && _hi >= ot->_hi ) {
1153 // New contains old
1154 // If new guy is already wider than old, no widening
1155 if( _widen > ot->_widen ) return this;
1156 // If old guy was a constant, do not bother
1157 if (ot->_lo == ot->_hi) return this;
1158 // Now widen new guy.
1159 // Check for widening too far
1160 if (_widen == WidenMax) {
1161 int max = max_jint;
1162 int min = min_jint;
1163 if (limit->isa_int()) {
1164 max = limit->is_int()->_hi;
1165 min = limit->is_int()->_lo;
1166 }
1167 if (min < _lo && _hi < max) {
1168 // If neither endpoint is extremal yet, push out the endpoint
1169 // which is closer to its respective limit.
1170 if (_lo >= 0 || // easy common case
1171 (juint)(_lo - min) >= (juint)(max - _hi)) {
1172 // Try to widen to an unsigned range type of 31 bits:
1173 return make(_lo, max, WidenMax);
1174 } else {
1175 return make(min, _hi, WidenMax);
1176 }
1177 }
1178 return TypeInt::INT;
1179 }
1180 // Returned widened new guy
1181 return make(_lo,_hi,_widen+1);
1182 }
1184 // If old guy contains new, then we probably widened too far & dropped to
1185 // bottom. Return the wider fellow.
1186 if ( ot->_lo <= _lo && ot->_hi >= _hi )
1187 return old;
1189 //fatal("Integer value range is not subset");
1190 //return this;
1191 return TypeInt::INT;
1192 }
1194 //------------------------------narrow---------------------------------------
1195 // Only happens for pessimistic optimizations.
1196 const Type *TypeInt::narrow( const Type *old ) const {
1197 if (_lo >= _hi) return this; // already narrow enough
1198 if (old == NULL) return this;
1199 const TypeInt* ot = old->isa_int();
1200 if (ot == NULL) return this;
1201 jint olo = ot->_lo;
1202 jint ohi = ot->_hi;
1204 // If new guy is equal to old guy, no narrowing
1205 if (_lo == olo && _hi == ohi) return old;
1207 // If old guy was maximum range, allow the narrowing
1208 if (olo == min_jint && ohi == max_jint) return this;
1210 if (_lo < olo || _hi > ohi)
1211 return this; // doesn't narrow; pretty wierd
1213 // The new type narrows the old type, so look for a "death march".
1214 // See comments on PhaseTransform::saturate.
1215 juint nrange = _hi - _lo;
1216 juint orange = ohi - olo;
1217 if (nrange < max_juint - 1 && nrange > (orange >> 1) + (SMALLINT*2)) {
1218 // Use the new type only if the range shrinks a lot.
1219 // We do not want the optimizer computing 2^31 point by point.
1220 return old;
1221 }
1223 return this;
1224 }
1226 //-----------------------------filter------------------------------------------
1227 const Type *TypeInt::filter( const Type *kills ) const {
1228 const TypeInt* ft = join(kills)->isa_int();
1229 if (ft == NULL || ft->empty())
1230 return Type::TOP; // Canonical empty value
1231 if (ft->_widen < this->_widen) {
1232 // Do not allow the value of kill->_widen to affect the outcome.
1233 // The widen bits must be allowed to run freely through the graph.
1234 ft = TypeInt::make(ft->_lo, ft->_hi, this->_widen);
1235 }
1236 return ft;
1237 }
1239 //------------------------------eq---------------------------------------------
1240 // Structural equality check for Type representations
1241 bool TypeInt::eq( const Type *t ) const {
1242 const TypeInt *r = t->is_int(); // Handy access
1243 return r->_lo == _lo && r->_hi == _hi && r->_widen == _widen;
1244 }
1246 //------------------------------hash-------------------------------------------
1247 // Type-specific hashing function.
1248 int TypeInt::hash(void) const {
1249 return _lo+_hi+_widen+(int)Type::Int;
1250 }
1252 //------------------------------is_finite--------------------------------------
1253 // Has a finite value
1254 bool TypeInt::is_finite() const {
1255 return true;
1256 }
1258 //------------------------------dump2------------------------------------------
1259 // Dump TypeInt
1260 #ifndef PRODUCT
1261 static const char* intname(char* buf, jint n) {
1262 if (n == min_jint)
1263 return "min";
1264 else if (n < min_jint + 10000)
1265 sprintf(buf, "min+" INT32_FORMAT, n - min_jint);
1266 else if (n == max_jint)
1267 return "max";
1268 else if (n > max_jint - 10000)
1269 sprintf(buf, "max-" INT32_FORMAT, max_jint - n);
1270 else
1271 sprintf(buf, INT32_FORMAT, n);
1272 return buf;
1273 }
1275 void TypeInt::dump2( Dict &d, uint depth, outputStream *st ) const {
1276 char buf[40], buf2[40];
1277 if (_lo == min_jint && _hi == max_jint)
1278 st->print("int");
1279 else if (is_con())
1280 st->print("int:%s", intname(buf, get_con()));
1281 else if (_lo == BOOL->_lo && _hi == BOOL->_hi)
1282 st->print("bool");
1283 else if (_lo == BYTE->_lo && _hi == BYTE->_hi)
1284 st->print("byte");
1285 else if (_lo == CHAR->_lo && _hi == CHAR->_hi)
1286 st->print("char");
1287 else if (_lo == SHORT->_lo && _hi == SHORT->_hi)
1288 st->print("short");
1289 else if (_hi == max_jint)
1290 st->print("int:>=%s", intname(buf, _lo));
1291 else if (_lo == min_jint)
1292 st->print("int:<=%s", intname(buf, _hi));
1293 else
1294 st->print("int:%s..%s", intname(buf, _lo), intname(buf2, _hi));
1296 if (_widen != 0 && this != TypeInt::INT)
1297 st->print(":%.*s", _widen, "wwww");
1298 }
1299 #endif
1301 //------------------------------singleton--------------------------------------
1302 // TRUE if Type is a singleton type, FALSE otherwise. Singletons are simple
1303 // constants.
1304 bool TypeInt::singleton(void) const {
1305 return _lo >= _hi;
1306 }
1308 bool TypeInt::empty(void) const {
1309 return _lo > _hi;
1310 }
1312 //=============================================================================
1313 // Convenience common pre-built types.
1314 const TypeLong *TypeLong::MINUS_1;// -1
1315 const TypeLong *TypeLong::ZERO; // 0
1316 const TypeLong *TypeLong::ONE; // 1
1317 const TypeLong *TypeLong::POS; // >=0
1318 const TypeLong *TypeLong::LONG; // 64-bit integers
1319 const TypeLong *TypeLong::INT; // 32-bit subrange
1320 const TypeLong *TypeLong::UINT; // 32-bit unsigned subrange
1322 //------------------------------TypeLong---------------------------------------
1323 TypeLong::TypeLong( jlong lo, jlong hi, int w ) : Type(Long), _lo(lo), _hi(hi), _widen(w) {
1324 }
1326 //------------------------------make-------------------------------------------
1327 const TypeLong *TypeLong::make( jlong lo ) {
1328 return (TypeLong*)(new TypeLong(lo,lo,WidenMin))->hashcons();
1329 }
1331 static int normalize_long_widen( jlong lo, jlong hi, int w ) {
1332 // Certain normalizations keep us sane when comparing types.
1333 // The 'SMALLINT' covers constants.
1334 if (lo <= hi) {
1335 if ((julong)(hi - lo) <= SMALLINT) w = Type::WidenMin;
1336 if ((julong)(hi - lo) >= max_julong) w = Type::WidenMax; // TypeLong::LONG
1337 } else {
1338 if ((julong)(lo - hi) <= SMALLINT) w = Type::WidenMin;
1339 if ((julong)(lo - hi) >= max_julong) w = Type::WidenMin; // dual TypeLong::LONG
1340 }
1341 return w;
1342 }
1344 const TypeLong *TypeLong::make( jlong lo, jlong hi, int w ) {
1345 w = normalize_long_widen(lo, hi, w);
1346 return (TypeLong*)(new TypeLong(lo,hi,w))->hashcons();
1347 }
1350 //------------------------------meet-------------------------------------------
1351 // Compute the MEET of two types. It returns a new Type representation object
1352 // with reference count equal to the number of Types pointing at it.
1353 // Caller should wrap a Types around it.
1354 const Type *TypeLong::xmeet( const Type *t ) const {
1355 // Perform a fast test for common case; meeting the same types together.
1356 if( this == t ) return this; // Meeting same type?
1358 // Currently "this->_base" is a TypeLong
1359 switch (t->base()) { // Switch on original type
1360 case AnyPtr: // Mixing with oops happens when javac
1361 case RawPtr: // reuses local variables
1362 case OopPtr:
1363 case InstPtr:
1364 case KlassPtr:
1365 case AryPtr:
1366 case NarrowOop:
1367 case Int:
1368 case FloatTop:
1369 case FloatCon:
1370 case FloatBot:
1371 case DoubleTop:
1372 case DoubleCon:
1373 case DoubleBot:
1374 case Bottom: // Ye Olde Default
1375 return Type::BOTTOM;
1376 default: // All else is a mistake
1377 typerr(t);
1378 case Top: // No change
1379 return this;
1380 case Long: // Long vs Long?
1381 break;
1382 }
1384 // Expand covered set
1385 const TypeLong *r = t->is_long(); // Turn into a TypeLong
1386 return make( MIN2(_lo,r->_lo), MAX2(_hi,r->_hi), MAX2(_widen,r->_widen) );
1387 }
1389 //------------------------------xdual------------------------------------------
1390 // Dual: reverse hi & lo; flip widen
1391 const Type *TypeLong::xdual() const {
1392 int w = normalize_long_widen(_hi,_lo, WidenMax-_widen);
1393 return new TypeLong(_hi,_lo,w);
1394 }
1396 //------------------------------widen------------------------------------------
1397 // Only happens for optimistic top-down optimizations.
1398 const Type *TypeLong::widen( const Type *old, const Type* limit ) const {
1399 // Coming from TOP or such; no widening
1400 if( old->base() != Long ) return this;
1401 const TypeLong *ot = old->is_long();
1403 // If new guy is equal to old guy, no widening
1404 if( _lo == ot->_lo && _hi == ot->_hi )
1405 return old;
1407 // If new guy contains old, then we widened
1408 if( _lo <= ot->_lo && _hi >= ot->_hi ) {
1409 // New contains old
1410 // If new guy is already wider than old, no widening
1411 if( _widen > ot->_widen ) return this;
1412 // If old guy was a constant, do not bother
1413 if (ot->_lo == ot->_hi) return this;
1414 // Now widen new guy.
1415 // Check for widening too far
1416 if (_widen == WidenMax) {
1417 jlong max = max_jlong;
1418 jlong min = min_jlong;
1419 if (limit->isa_long()) {
1420 max = limit->is_long()->_hi;
1421 min = limit->is_long()->_lo;
1422 }
1423 if (min < _lo && _hi < max) {
1424 // If neither endpoint is extremal yet, push out the endpoint
1425 // which is closer to its respective limit.
1426 if (_lo >= 0 || // easy common case
1427 (julong)(_lo - min) >= (julong)(max - _hi)) {
1428 // Try to widen to an unsigned range type of 32/63 bits:
1429 if (max >= max_juint && _hi < max_juint)
1430 return make(_lo, max_juint, WidenMax);
1431 else
1432 return make(_lo, max, WidenMax);
1433 } else {
1434 return make(min, _hi, WidenMax);
1435 }
1436 }
1437 return TypeLong::LONG;
1438 }
1439 // Returned widened new guy
1440 return make(_lo,_hi,_widen+1);
1441 }
1443 // If old guy contains new, then we probably widened too far & dropped to
1444 // bottom. Return the wider fellow.
1445 if ( ot->_lo <= _lo && ot->_hi >= _hi )
1446 return old;
1448 // fatal("Long value range is not subset");
1449 // return this;
1450 return TypeLong::LONG;
1451 }
1453 //------------------------------narrow----------------------------------------
1454 // Only happens for pessimistic optimizations.
1455 const Type *TypeLong::narrow( const Type *old ) const {
1456 if (_lo >= _hi) return this; // already narrow enough
1457 if (old == NULL) return this;
1458 const TypeLong* ot = old->isa_long();
1459 if (ot == NULL) return this;
1460 jlong olo = ot->_lo;
1461 jlong ohi = ot->_hi;
1463 // If new guy is equal to old guy, no narrowing
1464 if (_lo == olo && _hi == ohi) return old;
1466 // If old guy was maximum range, allow the narrowing
1467 if (olo == min_jlong && ohi == max_jlong) return this;
1469 if (_lo < olo || _hi > ohi)
1470 return this; // doesn't narrow; pretty wierd
1472 // The new type narrows the old type, so look for a "death march".
1473 // See comments on PhaseTransform::saturate.
1474 julong nrange = _hi - _lo;
1475 julong orange = ohi - olo;
1476 if (nrange < max_julong - 1 && nrange > (orange >> 1) + (SMALLINT*2)) {
1477 // Use the new type only if the range shrinks a lot.
1478 // We do not want the optimizer computing 2^31 point by point.
1479 return old;
1480 }
1482 return this;
1483 }
1485 //-----------------------------filter------------------------------------------
1486 const Type *TypeLong::filter( const Type *kills ) const {
1487 const TypeLong* ft = join(kills)->isa_long();
1488 if (ft == NULL || ft->empty())
1489 return Type::TOP; // Canonical empty value
1490 if (ft->_widen < this->_widen) {
1491 // Do not allow the value of kill->_widen to affect the outcome.
1492 // The widen bits must be allowed to run freely through the graph.
1493 ft = TypeLong::make(ft->_lo, ft->_hi, this->_widen);
1494 }
1495 return ft;
1496 }
1498 //------------------------------eq---------------------------------------------
1499 // Structural equality check for Type representations
1500 bool TypeLong::eq( const Type *t ) const {
1501 const TypeLong *r = t->is_long(); // Handy access
1502 return r->_lo == _lo && r->_hi == _hi && r->_widen == _widen;
1503 }
1505 //------------------------------hash-------------------------------------------
1506 // Type-specific hashing function.
1507 int TypeLong::hash(void) const {
1508 return (int)(_lo+_hi+_widen+(int)Type::Long);
1509 }
1511 //------------------------------is_finite--------------------------------------
1512 // Has a finite value
1513 bool TypeLong::is_finite() const {
1514 return true;
1515 }
1517 //------------------------------dump2------------------------------------------
1518 // Dump TypeLong
1519 #ifndef PRODUCT
1520 static const char* longnamenear(jlong x, const char* xname, char* buf, jlong n) {
1521 if (n > x) {
1522 if (n >= x + 10000) return NULL;
1523 sprintf(buf, "%s+" INT64_FORMAT, xname, n - x);
1524 } else if (n < x) {
1525 if (n <= x - 10000) return NULL;
1526 sprintf(buf, "%s-" INT64_FORMAT, xname, x - n);
1527 } else {
1528 return xname;
1529 }
1530 return buf;
1531 }
1533 static const char* longname(char* buf, jlong n) {
1534 const char* str;
1535 if (n == min_jlong)
1536 return "min";
1537 else if (n < min_jlong + 10000)
1538 sprintf(buf, "min+" INT64_FORMAT, n - min_jlong);
1539 else if (n == max_jlong)
1540 return "max";
1541 else if (n > max_jlong - 10000)
1542 sprintf(buf, "max-" INT64_FORMAT, max_jlong - n);
1543 else if ((str = longnamenear(max_juint, "maxuint", buf, n)) != NULL)
1544 return str;
1545 else if ((str = longnamenear(max_jint, "maxint", buf, n)) != NULL)
1546 return str;
1547 else if ((str = longnamenear(min_jint, "minint", buf, n)) != NULL)
1548 return str;
1549 else
1550 sprintf(buf, INT64_FORMAT, n);
1551 return buf;
1552 }
1554 void TypeLong::dump2( Dict &d, uint depth, outputStream *st ) const {
1555 char buf[80], buf2[80];
1556 if (_lo == min_jlong && _hi == max_jlong)
1557 st->print("long");
1558 else if (is_con())
1559 st->print("long:%s", longname(buf, get_con()));
1560 else if (_hi == max_jlong)
1561 st->print("long:>=%s", longname(buf, _lo));
1562 else if (_lo == min_jlong)
1563 st->print("long:<=%s", longname(buf, _hi));
1564 else
1565 st->print("long:%s..%s", longname(buf, _lo), longname(buf2, _hi));
1567 if (_widen != 0 && this != TypeLong::LONG)
1568 st->print(":%.*s", _widen, "wwww");
1569 }
1570 #endif
1572 //------------------------------singleton--------------------------------------
1573 // TRUE if Type is a singleton type, FALSE otherwise. Singletons are simple
1574 // constants
1575 bool TypeLong::singleton(void) const {
1576 return _lo >= _hi;
1577 }
1579 bool TypeLong::empty(void) const {
1580 return _lo > _hi;
1581 }
1583 //=============================================================================
1584 // Convenience common pre-built types.
1585 const TypeTuple *TypeTuple::IFBOTH; // Return both arms of IF as reachable
1586 const TypeTuple *TypeTuple::IFFALSE;
1587 const TypeTuple *TypeTuple::IFTRUE;
1588 const TypeTuple *TypeTuple::IFNEITHER;
1589 const TypeTuple *TypeTuple::LOOPBODY;
1590 const TypeTuple *TypeTuple::MEMBAR;
1591 const TypeTuple *TypeTuple::STORECONDITIONAL;
1592 const TypeTuple *TypeTuple::START_I2C;
1593 const TypeTuple *TypeTuple::INT_PAIR;
1594 const TypeTuple *TypeTuple::LONG_PAIR;
1597 //------------------------------make-------------------------------------------
1598 // Make a TypeTuple from the range of a method signature
1599 const TypeTuple *TypeTuple::make_range(ciSignature* sig) {
1600 ciType* return_type = sig->return_type();
1601 uint total_fields = TypeFunc::Parms + return_type->size();
1602 const Type **field_array = fields(total_fields);
1603 switch (return_type->basic_type()) {
1604 case T_LONG:
1605 field_array[TypeFunc::Parms] = TypeLong::LONG;
1606 field_array[TypeFunc::Parms+1] = Type::HALF;
1607 break;
1608 case T_DOUBLE:
1609 field_array[TypeFunc::Parms] = Type::DOUBLE;
1610 field_array[TypeFunc::Parms+1] = Type::HALF;
1611 break;
1612 case T_OBJECT:
1613 case T_ARRAY:
1614 case T_BOOLEAN:
1615 case T_CHAR:
1616 case T_FLOAT:
1617 case T_BYTE:
1618 case T_SHORT:
1619 case T_INT:
1620 field_array[TypeFunc::Parms] = get_const_type(return_type);
1621 break;
1622 case T_VOID:
1623 break;
1624 default:
1625 ShouldNotReachHere();
1626 }
1627 return (TypeTuple*)(new TypeTuple(total_fields,field_array))->hashcons();
1628 }
1630 // Make a TypeTuple from the domain of a method signature
1631 const TypeTuple *TypeTuple::make_domain(ciInstanceKlass* recv, ciSignature* sig) {
1632 uint total_fields = TypeFunc::Parms + sig->size();
1634 uint pos = TypeFunc::Parms;
1635 const Type **field_array;
1636 if (recv != NULL) {
1637 total_fields++;
1638 field_array = fields(total_fields);
1639 // Use get_const_type here because it respects UseUniqueSubclasses:
1640 field_array[pos++] = get_const_type(recv)->join(TypePtr::NOTNULL);
1641 } else {
1642 field_array = fields(total_fields);
1643 }
1645 int i = 0;
1646 while (pos < total_fields) {
1647 ciType* type = sig->type_at(i);
1649 switch (type->basic_type()) {
1650 case T_LONG:
1651 field_array[pos++] = TypeLong::LONG;
1652 field_array[pos++] = Type::HALF;
1653 break;
1654 case T_DOUBLE:
1655 field_array[pos++] = Type::DOUBLE;
1656 field_array[pos++] = Type::HALF;
1657 break;
1658 case T_OBJECT:
1659 case T_ARRAY:
1660 case T_BOOLEAN:
1661 case T_CHAR:
1662 case T_FLOAT:
1663 case T_BYTE:
1664 case T_SHORT:
1665 case T_INT:
1666 field_array[pos++] = get_const_type(type);
1667 break;
1668 default:
1669 ShouldNotReachHere();
1670 }
1671 i++;
1672 }
1673 return (TypeTuple*)(new TypeTuple(total_fields,field_array))->hashcons();
1674 }
1676 const TypeTuple *TypeTuple::make( uint cnt, const Type **fields ) {
1677 return (TypeTuple*)(new TypeTuple(cnt,fields))->hashcons();
1678 }
1680 //------------------------------fields-----------------------------------------
1681 // Subroutine call type with space allocated for argument types
1682 const Type **TypeTuple::fields( uint arg_cnt ) {
1683 const Type **flds = (const Type **)(Compile::current()->type_arena()->Amalloc_4((TypeFunc::Parms+arg_cnt)*sizeof(Type*) ));
1684 flds[TypeFunc::Control ] = Type::CONTROL;
1685 flds[TypeFunc::I_O ] = Type::ABIO;
1686 flds[TypeFunc::Memory ] = Type::MEMORY;
1687 flds[TypeFunc::FramePtr ] = TypeRawPtr::BOTTOM;
1688 flds[TypeFunc::ReturnAdr] = Type::RETURN_ADDRESS;
1690 return flds;
1691 }
1693 //------------------------------meet-------------------------------------------
1694 // Compute the MEET of two types. It returns a new Type object.
1695 const Type *TypeTuple::xmeet( const Type *t ) const {
1696 // Perform a fast test for common case; meeting the same types together.
1697 if( this == t ) return this; // Meeting same type-rep?
1699 // Current "this->_base" is Tuple
1700 switch (t->base()) { // switch on original type
1702 case Bottom: // Ye Olde Default
1703 return t;
1705 default: // All else is a mistake
1706 typerr(t);
1708 case Tuple: { // Meeting 2 signatures?
1709 const TypeTuple *x = t->is_tuple();
1710 assert( _cnt == x->_cnt, "" );
1711 const Type **fields = (const Type **)(Compile::current()->type_arena()->Amalloc_4( _cnt*sizeof(Type*) ));
1712 for( uint i=0; i<_cnt; i++ )
1713 fields[i] = field_at(i)->xmeet( x->field_at(i) );
1714 return TypeTuple::make(_cnt,fields);
1715 }
1716 case Top:
1717 break;
1718 }
1719 return this; // Return the double constant
1720 }
1722 //------------------------------xdual------------------------------------------
1723 // Dual: compute field-by-field dual
1724 const Type *TypeTuple::xdual() const {
1725 const Type **fields = (const Type **)(Compile::current()->type_arena()->Amalloc_4( _cnt*sizeof(Type*) ));
1726 for( uint i=0; i<_cnt; i++ )
1727 fields[i] = _fields[i]->dual();
1728 return new TypeTuple(_cnt,fields);
1729 }
1731 //------------------------------eq---------------------------------------------
1732 // Structural equality check for Type representations
1733 bool TypeTuple::eq( const Type *t ) const {
1734 const TypeTuple *s = (const TypeTuple *)t;
1735 if (_cnt != s->_cnt) return false; // Unequal field counts
1736 for (uint i = 0; i < _cnt; i++)
1737 if (field_at(i) != s->field_at(i)) // POINTER COMPARE! NO RECURSION!
1738 return false; // Missed
1739 return true;
1740 }
1742 //------------------------------hash-------------------------------------------
1743 // Type-specific hashing function.
1744 int TypeTuple::hash(void) const {
1745 intptr_t sum = _cnt;
1746 for( uint i=0; i<_cnt; i++ )
1747 sum += (intptr_t)_fields[i]; // Hash on pointers directly
1748 return sum;
1749 }
1751 //------------------------------dump2------------------------------------------
1752 // Dump signature Type
1753 #ifndef PRODUCT
1754 void TypeTuple::dump2( Dict &d, uint depth, outputStream *st ) const {
1755 st->print("{");
1756 if( !depth || d[this] ) { // Check for recursive print
1757 st->print("...}");
1758 return;
1759 }
1760 d.Insert((void*)this, (void*)this); // Stop recursion
1761 if( _cnt ) {
1762 uint i;
1763 for( i=0; i<_cnt-1; i++ ) {
1764 st->print("%d:", i);
1765 _fields[i]->dump2(d, depth-1, st);
1766 st->print(", ");
1767 }
1768 st->print("%d:", i);
1769 _fields[i]->dump2(d, depth-1, st);
1770 }
1771 st->print("}");
1772 }
1773 #endif
1775 //------------------------------singleton--------------------------------------
1776 // TRUE if Type is a singleton type, FALSE otherwise. Singletons are simple
1777 // constants (Ldi nodes). Singletons are integer, float or double constants
1778 // or a single symbol.
1779 bool TypeTuple::singleton(void) const {
1780 return false; // Never a singleton
1781 }
1783 bool TypeTuple::empty(void) const {
1784 for( uint i=0; i<_cnt; i++ ) {
1785 if (_fields[i]->empty()) return true;
1786 }
1787 return false;
1788 }
1790 //=============================================================================
1791 // Convenience common pre-built types.
1793 inline const TypeInt* normalize_array_size(const TypeInt* size) {
1794 // Certain normalizations keep us sane when comparing types.
1795 // We do not want arrayOop variables to differ only by the wideness
1796 // of their index types. Pick minimum wideness, since that is the
1797 // forced wideness of small ranges anyway.
1798 if (size->_widen != Type::WidenMin)
1799 return TypeInt::make(size->_lo, size->_hi, Type::WidenMin);
1800 else
1801 return size;
1802 }
1804 //------------------------------make-------------------------------------------
1805 const TypeAry *TypeAry::make( const Type *elem, const TypeInt *size) {
1806 if (UseCompressedOops && elem->isa_oopptr()) {
1807 elem = elem->make_narrowoop();
1808 }
1809 size = normalize_array_size(size);
1810 return (TypeAry*)(new TypeAry(elem,size))->hashcons();
1811 }
1813 //------------------------------meet-------------------------------------------
1814 // Compute the MEET of two types. It returns a new Type object.
1815 const Type *TypeAry::xmeet( const Type *t ) const {
1816 // Perform a fast test for common case; meeting the same types together.
1817 if( this == t ) return this; // Meeting same type-rep?
1819 // Current "this->_base" is Ary
1820 switch (t->base()) { // switch on original type
1822 case Bottom: // Ye Olde Default
1823 return t;
1825 default: // All else is a mistake
1826 typerr(t);
1828 case Array: { // Meeting 2 arrays?
1829 const TypeAry *a = t->is_ary();
1830 return TypeAry::make(_elem->meet(a->_elem),
1831 _size->xmeet(a->_size)->is_int());
1832 }
1833 case Top:
1834 break;
1835 }
1836 return this; // Return the double constant
1837 }
1839 //------------------------------xdual------------------------------------------
1840 // Dual: compute field-by-field dual
1841 const Type *TypeAry::xdual() const {
1842 const TypeInt* size_dual = _size->dual()->is_int();
1843 size_dual = normalize_array_size(size_dual);
1844 return new TypeAry( _elem->dual(), size_dual);
1845 }
1847 //------------------------------eq---------------------------------------------
1848 // Structural equality check for Type representations
1849 bool TypeAry::eq( const Type *t ) const {
1850 const TypeAry *a = (const TypeAry*)t;
1851 return _elem == a->_elem &&
1852 _size == a->_size;
1853 }
1855 //------------------------------hash-------------------------------------------
1856 // Type-specific hashing function.
1857 int TypeAry::hash(void) const {
1858 return (intptr_t)_elem + (intptr_t)_size;
1859 }
1861 //----------------------interface_vs_oop---------------------------------------
1862 #ifdef ASSERT
1863 bool TypeAry::interface_vs_oop(const Type *t) const {
1864 const TypeAry* t_ary = t->is_ary();
1865 if (t_ary) {
1866 return _elem->interface_vs_oop(t_ary->_elem);
1867 }
1868 return false;
1869 }
1870 #endif
1872 //------------------------------dump2------------------------------------------
1873 #ifndef PRODUCT
1874 void TypeAry::dump2( Dict &d, uint depth, outputStream *st ) const {
1875 _elem->dump2(d, depth, st);
1876 st->print("[");
1877 _size->dump2(d, depth, st);
1878 st->print("]");
1879 }
1880 #endif
1882 //------------------------------singleton--------------------------------------
1883 // TRUE if Type is a singleton type, FALSE otherwise. Singletons are simple
1884 // constants (Ldi nodes). Singletons are integer, float or double constants
1885 // or a single symbol.
1886 bool TypeAry::singleton(void) const {
1887 return false; // Never a singleton
1888 }
1890 bool TypeAry::empty(void) const {
1891 return _elem->empty() || _size->empty();
1892 }
1894 //--------------------------ary_must_be_exact----------------------------------
1895 bool TypeAry::ary_must_be_exact() const {
1896 if (!UseExactTypes) return false;
1897 // This logic looks at the element type of an array, and returns true
1898 // if the element type is either a primitive or a final instance class.
1899 // In such cases, an array built on this ary must have no subclasses.
1900 if (_elem == BOTTOM) return false; // general array not exact
1901 if (_elem == TOP ) return false; // inverted general array not exact
1902 const TypeOopPtr* toop = NULL;
1903 if (UseCompressedOops && _elem->isa_narrowoop()) {
1904 toop = _elem->make_ptr()->isa_oopptr();
1905 } else {
1906 toop = _elem->isa_oopptr();
1907 }
1908 if (!toop) return true; // a primitive type, like int
1909 ciKlass* tklass = toop->klass();
1910 if (tklass == NULL) return false; // unloaded class
1911 if (!tklass->is_loaded()) return false; // unloaded class
1912 const TypeInstPtr* tinst;
1913 if (_elem->isa_narrowoop())
1914 tinst = _elem->make_ptr()->isa_instptr();
1915 else
1916 tinst = _elem->isa_instptr();
1917 if (tinst)
1918 return tklass->as_instance_klass()->is_final();
1919 const TypeAryPtr* tap;
1920 if (_elem->isa_narrowoop())
1921 tap = _elem->make_ptr()->isa_aryptr();
1922 else
1923 tap = _elem->isa_aryptr();
1924 if (tap)
1925 return tap->ary()->ary_must_be_exact();
1926 return false;
1927 }
1929 //=============================================================================
1930 // Convenience common pre-built types.
1931 const TypePtr *TypePtr::NULL_PTR;
1932 const TypePtr *TypePtr::NOTNULL;
1933 const TypePtr *TypePtr::BOTTOM;
1935 //------------------------------meet-------------------------------------------
1936 // Meet over the PTR enum
1937 const TypePtr::PTR TypePtr::ptr_meet[TypePtr::lastPTR][TypePtr::lastPTR] = {
1938 // TopPTR, AnyNull, Constant, Null, NotNull, BotPTR,
1939 { /* Top */ TopPTR, AnyNull, Constant, Null, NotNull, BotPTR,},
1940 { /* AnyNull */ AnyNull, AnyNull, Constant, BotPTR, NotNull, BotPTR,},
1941 { /* Constant*/ Constant, Constant, Constant, BotPTR, NotNull, BotPTR,},
1942 { /* Null */ Null, BotPTR, BotPTR, Null, BotPTR, BotPTR,},
1943 { /* NotNull */ NotNull, NotNull, NotNull, BotPTR, NotNull, BotPTR,},
1944 { /* BotPTR */ BotPTR, BotPTR, BotPTR, BotPTR, BotPTR, BotPTR,}
1945 };
1947 //------------------------------make-------------------------------------------
1948 const TypePtr *TypePtr::make( TYPES t, enum PTR ptr, int offset ) {
1949 return (TypePtr*)(new TypePtr(t,ptr,offset))->hashcons();
1950 }
1952 //------------------------------cast_to_ptr_type-------------------------------
1953 const Type *TypePtr::cast_to_ptr_type(PTR ptr) const {
1954 assert(_base == AnyPtr, "subclass must override cast_to_ptr_type");
1955 if( ptr == _ptr ) return this;
1956 return make(_base, ptr, _offset);
1957 }
1959 //------------------------------get_con----------------------------------------
1960 intptr_t TypePtr::get_con() const {
1961 assert( _ptr == Null, "" );
1962 return _offset;
1963 }
1965 //------------------------------meet-------------------------------------------
1966 // Compute the MEET of two types. It returns a new Type object.
1967 const Type *TypePtr::xmeet( const Type *t ) const {
1968 // Perform a fast test for common case; meeting the same types together.
1969 if( this == t ) return this; // Meeting same type-rep?
1971 // Current "this->_base" is AnyPtr
1972 switch (t->base()) { // switch on original type
1973 case Int: // Mixing ints & oops happens when javac
1974 case Long: // reuses local variables
1975 case FloatTop:
1976 case FloatCon:
1977 case FloatBot:
1978 case DoubleTop:
1979 case DoubleCon:
1980 case DoubleBot:
1981 case NarrowOop:
1982 case Bottom: // Ye Olde Default
1983 return Type::BOTTOM;
1984 case Top:
1985 return this;
1987 case AnyPtr: { // Meeting to AnyPtrs
1988 const TypePtr *tp = t->is_ptr();
1989 return make( AnyPtr, meet_ptr(tp->ptr()), meet_offset(tp->offset()) );
1990 }
1991 case RawPtr: // For these, flip the call around to cut down
1992 case OopPtr:
1993 case InstPtr: // on the cases I have to handle.
1994 case KlassPtr:
1995 case AryPtr:
1996 return t->xmeet(this); // Call in reverse direction
1997 default: // All else is a mistake
1998 typerr(t);
2000 }
2001 return this;
2002 }
2004 //------------------------------meet_offset------------------------------------
2005 int TypePtr::meet_offset( int offset ) const {
2006 // Either is 'TOP' offset? Return the other offset!
2007 if( _offset == OffsetTop ) return offset;
2008 if( offset == OffsetTop ) return _offset;
2009 // If either is different, return 'BOTTOM' offset
2010 if( _offset != offset ) return OffsetBot;
2011 return _offset;
2012 }
2014 //------------------------------dual_offset------------------------------------
2015 int TypePtr::dual_offset( ) const {
2016 if( _offset == OffsetTop ) return OffsetBot;// Map 'TOP' into 'BOTTOM'
2017 if( _offset == OffsetBot ) return OffsetTop;// Map 'BOTTOM' into 'TOP'
2018 return _offset; // Map everything else into self
2019 }
2021 //------------------------------xdual------------------------------------------
2022 // Dual: compute field-by-field dual
2023 const TypePtr::PTR TypePtr::ptr_dual[TypePtr::lastPTR] = {
2024 BotPTR, NotNull, Constant, Null, AnyNull, TopPTR
2025 };
2026 const Type *TypePtr::xdual() const {
2027 return new TypePtr( AnyPtr, dual_ptr(), dual_offset() );
2028 }
2030 //------------------------------xadd_offset------------------------------------
2031 int TypePtr::xadd_offset( intptr_t offset ) const {
2032 // Adding to 'TOP' offset? Return 'TOP'!
2033 if( _offset == OffsetTop || offset == OffsetTop ) return OffsetTop;
2034 // Adding to 'BOTTOM' offset? Return 'BOTTOM'!
2035 if( _offset == OffsetBot || offset == OffsetBot ) return OffsetBot;
2036 // Addition overflows or "accidentally" equals to OffsetTop? Return 'BOTTOM'!
2037 offset += (intptr_t)_offset;
2038 if (offset != (int)offset || offset == OffsetTop) return OffsetBot;
2040 // assert( _offset >= 0 && _offset+offset >= 0, "" );
2041 // It is possible to construct a negative offset during PhaseCCP
2043 return (int)offset; // Sum valid offsets
2044 }
2046 //------------------------------add_offset-------------------------------------
2047 const TypePtr *TypePtr::add_offset( intptr_t offset ) const {
2048 return make( AnyPtr, _ptr, xadd_offset(offset) );
2049 }
2051 //------------------------------eq---------------------------------------------
2052 // Structural equality check for Type representations
2053 bool TypePtr::eq( const Type *t ) const {
2054 const TypePtr *a = (const TypePtr*)t;
2055 return _ptr == a->ptr() && _offset == a->offset();
2056 }
2058 //------------------------------hash-------------------------------------------
2059 // Type-specific hashing function.
2060 int TypePtr::hash(void) const {
2061 return _ptr + _offset;
2062 }
2064 //------------------------------dump2------------------------------------------
2065 const char *const TypePtr::ptr_msg[TypePtr::lastPTR] = {
2066 "TopPTR","AnyNull","Constant","NULL","NotNull","BotPTR"
2067 };
2069 #ifndef PRODUCT
2070 void TypePtr::dump2( Dict &d, uint depth, outputStream *st ) const {
2071 if( _ptr == Null ) st->print("NULL");
2072 else st->print("%s *", ptr_msg[_ptr]);
2073 if( _offset == OffsetTop ) st->print("+top");
2074 else if( _offset == OffsetBot ) st->print("+bot");
2075 else if( _offset ) st->print("+%d", _offset);
2076 }
2077 #endif
2079 //------------------------------singleton--------------------------------------
2080 // TRUE if Type is a singleton type, FALSE otherwise. Singletons are simple
2081 // constants
2082 bool TypePtr::singleton(void) const {
2083 // TopPTR, Null, AnyNull, Constant are all singletons
2084 return (_offset != OffsetBot) && !below_centerline(_ptr);
2085 }
2087 bool TypePtr::empty(void) const {
2088 return (_offset == OffsetTop) || above_centerline(_ptr);
2089 }
2091 //=============================================================================
2092 // Convenience common pre-built types.
2093 const TypeRawPtr *TypeRawPtr::BOTTOM;
2094 const TypeRawPtr *TypeRawPtr::NOTNULL;
2096 //------------------------------make-------------------------------------------
2097 const TypeRawPtr *TypeRawPtr::make( enum PTR ptr ) {
2098 assert( ptr != Constant, "what is the constant?" );
2099 assert( ptr != Null, "Use TypePtr for NULL" );
2100 return (TypeRawPtr*)(new TypeRawPtr(ptr,0))->hashcons();
2101 }
2103 const TypeRawPtr *TypeRawPtr::make( address bits ) {
2104 assert( bits, "Use TypePtr for NULL" );
2105 return (TypeRawPtr*)(new TypeRawPtr(Constant,bits))->hashcons();
2106 }
2108 //------------------------------cast_to_ptr_type-------------------------------
2109 const Type *TypeRawPtr::cast_to_ptr_type(PTR ptr) const {
2110 assert( ptr != Constant, "what is the constant?" );
2111 assert( ptr != Null, "Use TypePtr for NULL" );
2112 assert( _bits==0, "Why cast a constant address?");
2113 if( ptr == _ptr ) return this;
2114 return make(ptr);
2115 }
2117 //------------------------------get_con----------------------------------------
2118 intptr_t TypeRawPtr::get_con() const {
2119 assert( _ptr == Null || _ptr == Constant, "" );
2120 return (intptr_t)_bits;
2121 }
2123 //------------------------------meet-------------------------------------------
2124 // Compute the MEET of two types. It returns a new Type object.
2125 const Type *TypeRawPtr::xmeet( const Type *t ) const {
2126 // Perform a fast test for common case; meeting the same types together.
2127 if( this == t ) return this; // Meeting same type-rep?
2129 // Current "this->_base" is RawPtr
2130 switch( t->base() ) { // switch on original type
2131 case Bottom: // Ye Olde Default
2132 return t;
2133 case Top:
2134 return this;
2135 case AnyPtr: // Meeting to AnyPtrs
2136 break;
2137 case RawPtr: { // might be top, bot, any/not or constant
2138 enum PTR tptr = t->is_ptr()->ptr();
2139 enum PTR ptr = meet_ptr( tptr );
2140 if( ptr == Constant ) { // Cannot be equal constants, so...
2141 if( tptr == Constant && _ptr != Constant) return t;
2142 if( _ptr == Constant && tptr != Constant) return this;
2143 ptr = NotNull; // Fall down in lattice
2144 }
2145 return make( ptr );
2146 }
2148 case OopPtr:
2149 case InstPtr:
2150 case KlassPtr:
2151 case AryPtr:
2152 return TypePtr::BOTTOM; // Oop meet raw is not well defined
2153 default: // All else is a mistake
2154 typerr(t);
2155 }
2157 // Found an AnyPtr type vs self-RawPtr type
2158 const TypePtr *tp = t->is_ptr();
2159 switch (tp->ptr()) {
2160 case TypePtr::TopPTR: return this;
2161 case TypePtr::BotPTR: return t;
2162 case TypePtr::Null:
2163 if( _ptr == TypePtr::TopPTR ) return t;
2164 return TypeRawPtr::BOTTOM;
2165 case TypePtr::NotNull: return TypePtr::make( AnyPtr, meet_ptr(TypePtr::NotNull), tp->meet_offset(0) );
2166 case TypePtr::AnyNull:
2167 if( _ptr == TypePtr::Constant) return this;
2168 return make( meet_ptr(TypePtr::AnyNull) );
2169 default: ShouldNotReachHere();
2170 }
2171 return this;
2172 }
2174 //------------------------------xdual------------------------------------------
2175 // Dual: compute field-by-field dual
2176 const Type *TypeRawPtr::xdual() const {
2177 return new TypeRawPtr( dual_ptr(), _bits );
2178 }
2180 //------------------------------add_offset-------------------------------------
2181 const TypePtr *TypeRawPtr::add_offset( intptr_t offset ) const {
2182 if( offset == OffsetTop ) return BOTTOM; // Undefined offset-> undefined pointer
2183 if( offset == OffsetBot ) return BOTTOM; // Unknown offset-> unknown pointer
2184 if( offset == 0 ) return this; // No change
2185 switch (_ptr) {
2186 case TypePtr::TopPTR:
2187 case TypePtr::BotPTR:
2188 case TypePtr::NotNull:
2189 return this;
2190 case TypePtr::Null:
2191 case TypePtr::Constant: {
2192 address bits = _bits+offset;
2193 if ( bits == 0 ) return TypePtr::NULL_PTR;
2194 return make( bits );
2195 }
2196 default: ShouldNotReachHere();
2197 }
2198 return NULL; // Lint noise
2199 }
2201 //------------------------------eq---------------------------------------------
2202 // Structural equality check for Type representations
2203 bool TypeRawPtr::eq( const Type *t ) const {
2204 const TypeRawPtr *a = (const TypeRawPtr*)t;
2205 return _bits == a->_bits && TypePtr::eq(t);
2206 }
2208 //------------------------------hash-------------------------------------------
2209 // Type-specific hashing function.
2210 int TypeRawPtr::hash(void) const {
2211 return (intptr_t)_bits + TypePtr::hash();
2212 }
2214 //------------------------------dump2------------------------------------------
2215 #ifndef PRODUCT
2216 void TypeRawPtr::dump2( Dict &d, uint depth, outputStream *st ) const {
2217 if( _ptr == Constant )
2218 st->print(INTPTR_FORMAT, _bits);
2219 else
2220 st->print("rawptr:%s", ptr_msg[_ptr]);
2221 }
2222 #endif
2224 //=============================================================================
2225 // Convenience common pre-built type.
2226 const TypeOopPtr *TypeOopPtr::BOTTOM;
2228 //------------------------------TypeOopPtr-------------------------------------
2229 TypeOopPtr::TypeOopPtr( TYPES t, PTR ptr, ciKlass* k, bool xk, ciObject* o, int offset, int instance_id )
2230 : TypePtr(t, ptr, offset),
2231 _const_oop(o), _klass(k),
2232 _klass_is_exact(xk),
2233 _is_ptr_to_narrowoop(false),
2234 _instance_id(instance_id) {
2235 #ifdef _LP64
2236 if (UseCompressedOops && _offset != 0) {
2237 if (klass() == NULL) {
2238 assert(this->isa_aryptr(), "only arrays without klass");
2239 _is_ptr_to_narrowoop = true;
2240 } else if (_offset == oopDesc::klass_offset_in_bytes()) {
2241 _is_ptr_to_narrowoop = true;
2242 } else if (this->isa_aryptr()) {
2243 _is_ptr_to_narrowoop = (klass()->is_obj_array_klass() &&
2244 _offset != arrayOopDesc::length_offset_in_bytes());
2245 } else if (klass()->is_instance_klass()) {
2246 ciInstanceKlass* ik = klass()->as_instance_klass();
2247 ciField* field = NULL;
2248 if (this->isa_klassptr()) {
2249 // Perm objects don't use compressed references
2250 } else if (_offset == OffsetBot || _offset == OffsetTop) {
2251 // unsafe access
2252 _is_ptr_to_narrowoop = true;
2253 } else { // exclude unsafe ops
2254 assert(this->isa_instptr(), "must be an instance ptr.");
2256 if (klass() == ciEnv::current()->Class_klass() &&
2257 (_offset == java_lang_Class::klass_offset_in_bytes() ||
2258 _offset == java_lang_Class::array_klass_offset_in_bytes())) {
2259 // Special hidden fields from the Class.
2260 assert(this->isa_instptr(), "must be an instance ptr.");
2261 _is_ptr_to_narrowoop = true;
2262 } else if (klass() == ciEnv::current()->Class_klass() &&
2263 _offset >= instanceMirrorKlass::offset_of_static_fields()) {
2264 // Static fields
2265 assert(o != NULL, "must be constant");
2266 ciInstanceKlass* k = o->as_instance()->java_lang_Class_klass()->as_instance_klass();
2267 ciField* field = k->get_field_by_offset(_offset, true);
2268 assert(field != NULL, "missing field");
2269 BasicType basic_elem_type = field->layout_type();
2270 _is_ptr_to_narrowoop = (basic_elem_type == T_OBJECT ||
2271 basic_elem_type == T_ARRAY);
2272 } else {
2273 // Instance fields which contains a compressed oop references.
2274 field = ik->get_field_by_offset(_offset, false);
2275 if (field != NULL) {
2276 BasicType basic_elem_type = field->layout_type();
2277 _is_ptr_to_narrowoop = (basic_elem_type == T_OBJECT ||
2278 basic_elem_type == T_ARRAY);
2279 } else if (klass()->equals(ciEnv::current()->Object_klass())) {
2280 // Compile::find_alias_type() cast exactness on all types to verify
2281 // that it does not affect alias type.
2282 _is_ptr_to_narrowoop = true;
2283 } else {
2284 // Type for the copy start in LibraryCallKit::inline_native_clone().
2285 assert(!klass_is_exact(), "only non-exact klass");
2286 _is_ptr_to_narrowoop = true;
2287 }
2288 }
2289 }
2290 }
2291 }
2292 #endif
2293 }
2295 //------------------------------make-------------------------------------------
2296 const TypeOopPtr *TypeOopPtr::make(PTR ptr,
2297 int offset, int instance_id) {
2298 assert(ptr != Constant, "no constant generic pointers");
2299 ciKlass* k = ciKlassKlass::make();
2300 bool xk = false;
2301 ciObject* o = NULL;
2302 return (TypeOopPtr*)(new TypeOopPtr(OopPtr, ptr, k, xk, o, offset, instance_id))->hashcons();
2303 }
2306 //------------------------------cast_to_ptr_type-------------------------------
2307 const Type *TypeOopPtr::cast_to_ptr_type(PTR ptr) const {
2308 assert(_base == OopPtr, "subclass must override cast_to_ptr_type");
2309 if( ptr == _ptr ) return this;
2310 return make(ptr, _offset, _instance_id);
2311 }
2313 //-----------------------------cast_to_instance_id----------------------------
2314 const TypeOopPtr *TypeOopPtr::cast_to_instance_id(int instance_id) const {
2315 // There are no instances of a general oop.
2316 // Return self unchanged.
2317 return this;
2318 }
2320 //-----------------------------cast_to_exactness-------------------------------
2321 const Type *TypeOopPtr::cast_to_exactness(bool klass_is_exact) const {
2322 // There is no such thing as an exact general oop.
2323 // Return self unchanged.
2324 return this;
2325 }
2328 //------------------------------as_klass_type----------------------------------
2329 // Return the klass type corresponding to this instance or array type.
2330 // It is the type that is loaded from an object of this type.
2331 const TypeKlassPtr* TypeOopPtr::as_klass_type() const {
2332 ciKlass* k = klass();
2333 bool xk = klass_is_exact();
2334 if (k == NULL || !k->is_java_klass())
2335 return TypeKlassPtr::OBJECT;
2336 else
2337 return TypeKlassPtr::make(xk? Constant: NotNull, k, 0);
2338 }
2341 //------------------------------meet-------------------------------------------
2342 // Compute the MEET of two types. It returns a new Type object.
2343 const Type *TypeOopPtr::xmeet( const Type *t ) const {
2344 // Perform a fast test for common case; meeting the same types together.
2345 if( this == t ) return this; // Meeting same type-rep?
2347 // Current "this->_base" is OopPtr
2348 switch (t->base()) { // switch on original type
2350 case Int: // Mixing ints & oops happens when javac
2351 case Long: // reuses local variables
2352 case FloatTop:
2353 case FloatCon:
2354 case FloatBot:
2355 case DoubleTop:
2356 case DoubleCon:
2357 case DoubleBot:
2358 case NarrowOop:
2359 case Bottom: // Ye Olde Default
2360 return Type::BOTTOM;
2361 case Top:
2362 return this;
2364 default: // All else is a mistake
2365 typerr(t);
2367 case RawPtr:
2368 return TypePtr::BOTTOM; // Oop meet raw is not well defined
2370 case AnyPtr: {
2371 // Found an AnyPtr type vs self-OopPtr type
2372 const TypePtr *tp = t->is_ptr();
2373 int offset = meet_offset(tp->offset());
2374 PTR ptr = meet_ptr(tp->ptr());
2375 switch (tp->ptr()) {
2376 case Null:
2377 if (ptr == Null) return TypePtr::make(AnyPtr, ptr, offset);
2378 // else fall through:
2379 case TopPTR:
2380 case AnyNull: {
2381 int instance_id = meet_instance_id(InstanceTop);
2382 return make(ptr, offset, instance_id);
2383 }
2384 case BotPTR:
2385 case NotNull:
2386 return TypePtr::make(AnyPtr, ptr, offset);
2387 default: typerr(t);
2388 }
2389 }
2391 case OopPtr: { // Meeting to other OopPtrs
2392 const TypeOopPtr *tp = t->is_oopptr();
2393 int instance_id = meet_instance_id(tp->instance_id());
2394 return make( meet_ptr(tp->ptr()), meet_offset(tp->offset()), instance_id );
2395 }
2397 case InstPtr: // For these, flip the call around to cut down
2398 case KlassPtr: // on the cases I have to handle.
2399 case AryPtr:
2400 return t->xmeet(this); // Call in reverse direction
2402 } // End of switch
2403 return this; // Return the double constant
2404 }
2407 //------------------------------xdual------------------------------------------
2408 // Dual of a pure heap pointer. No relevant klass or oop information.
2409 const Type *TypeOopPtr::xdual() const {
2410 assert(klass() == ciKlassKlass::make(), "no klasses here");
2411 assert(const_oop() == NULL, "no constants here");
2412 return new TypeOopPtr(_base, dual_ptr(), klass(), klass_is_exact(), const_oop(), dual_offset(), dual_instance_id() );
2413 }
2415 //--------------------------make_from_klass_common-----------------------------
2416 // Computes the element-type given a klass.
2417 const TypeOopPtr* TypeOopPtr::make_from_klass_common(ciKlass *klass, bool klass_change, bool try_for_exact) {
2418 assert(klass->is_java_klass(), "must be java language klass");
2419 if (klass->is_instance_klass()) {
2420 Compile* C = Compile::current();
2421 Dependencies* deps = C->dependencies();
2422 assert((deps != NULL) == (C->method() != NULL && C->method()->code_size() > 0), "sanity");
2423 // Element is an instance
2424 bool klass_is_exact = false;
2425 if (klass->is_loaded()) {
2426 // Try to set klass_is_exact.
2427 ciInstanceKlass* ik = klass->as_instance_klass();
2428 klass_is_exact = ik->is_final();
2429 if (!klass_is_exact && klass_change
2430 && deps != NULL && UseUniqueSubclasses) {
2431 ciInstanceKlass* sub = ik->unique_concrete_subklass();
2432 if (sub != NULL) {
2433 deps->assert_abstract_with_unique_concrete_subtype(ik, sub);
2434 klass = ik = sub;
2435 klass_is_exact = sub->is_final();
2436 }
2437 }
2438 if (!klass_is_exact && try_for_exact
2439 && deps != NULL && UseExactTypes) {
2440 if (!ik->is_interface() && !ik->has_subklass()) {
2441 // Add a dependence; if concrete subclass added we need to recompile
2442 deps->assert_leaf_type(ik);
2443 klass_is_exact = true;
2444 }
2445 }
2446 }
2447 return TypeInstPtr::make(TypePtr::BotPTR, klass, klass_is_exact, NULL, 0);
2448 } else if (klass->is_obj_array_klass()) {
2449 // Element is an object array. Recursively call ourself.
2450 const TypeOopPtr *etype = TypeOopPtr::make_from_klass_common(klass->as_obj_array_klass()->element_klass(), false, try_for_exact);
2451 bool xk = etype->klass_is_exact();
2452 const TypeAry* arr0 = TypeAry::make(etype, TypeInt::POS);
2453 // We used to pass NotNull in here, asserting that the sub-arrays
2454 // are all not-null. This is not true in generally, as code can
2455 // slam NULLs down in the subarrays.
2456 const TypeAryPtr* arr = TypeAryPtr::make(TypePtr::BotPTR, arr0, klass, xk, 0);
2457 return arr;
2458 } else if (klass->is_type_array_klass()) {
2459 // Element is an typeArray
2460 const Type* etype = get_const_basic_type(klass->as_type_array_klass()->element_type());
2461 const TypeAry* arr0 = TypeAry::make(etype, TypeInt::POS);
2462 // We used to pass NotNull in here, asserting that the array pointer
2463 // is not-null. That was not true in general.
2464 const TypeAryPtr* arr = TypeAryPtr::make(TypePtr::BotPTR, arr0, klass, true, 0);
2465 return arr;
2466 } else {
2467 ShouldNotReachHere();
2468 return NULL;
2469 }
2470 }
2472 //------------------------------make_from_constant-----------------------------
2473 // Make a java pointer from an oop constant
2474 const TypeOopPtr* TypeOopPtr::make_from_constant(ciObject* o, bool require_constant) {
2475 if (o->is_method_data() || o->is_method() || o->is_cpcache()) {
2476 // Treat much like a typeArray of bytes, like below, but fake the type...
2477 const Type* etype = (Type*)get_const_basic_type(T_BYTE);
2478 const TypeAry* arr0 = TypeAry::make(etype, TypeInt::POS);
2479 ciKlass *klass = ciTypeArrayKlass::make((BasicType) T_BYTE);
2480 assert(o->can_be_constant(), "method data oops should be tenured");
2481 const TypeAryPtr* arr = TypeAryPtr::make(TypePtr::Constant, o, arr0, klass, true, 0);
2482 return arr;
2483 } else {
2484 assert(o->is_java_object(), "must be java language object");
2485 assert(!o->is_null_object(), "null object not yet handled here.");
2486 ciKlass *klass = o->klass();
2487 if (klass->is_instance_klass()) {
2488 // Element is an instance
2489 if (require_constant) {
2490 if (!o->can_be_constant()) return NULL;
2491 } else if (!o->should_be_constant()) {
2492 return TypeInstPtr::make(TypePtr::NotNull, klass, true, NULL, 0);
2493 }
2494 return TypeInstPtr::make(o);
2495 } else if (klass->is_obj_array_klass()) {
2496 // Element is an object array. Recursively call ourself.
2497 const Type *etype =
2498 TypeOopPtr::make_from_klass_raw(klass->as_obj_array_klass()->element_klass());
2499 const TypeAry* arr0 = TypeAry::make(etype, TypeInt::make(o->as_array()->length()));
2500 // We used to pass NotNull in here, asserting that the sub-arrays
2501 // are all not-null. This is not true in generally, as code can
2502 // slam NULLs down in the subarrays.
2503 if (require_constant) {
2504 if (!o->can_be_constant()) return NULL;
2505 } else if (!o->should_be_constant()) {
2506 return TypeAryPtr::make(TypePtr::NotNull, arr0, klass, true, 0);
2507 }
2508 const TypeAryPtr* arr = TypeAryPtr::make(TypePtr::Constant, o, arr0, klass, true, 0);
2509 return arr;
2510 } else if (klass->is_type_array_klass()) {
2511 // Element is an typeArray
2512 const Type* etype =
2513 (Type*)get_const_basic_type(klass->as_type_array_klass()->element_type());
2514 const TypeAry* arr0 = TypeAry::make(etype, TypeInt::make(o->as_array()->length()));
2515 // We used to pass NotNull in here, asserting that the array pointer
2516 // is not-null. That was not true in general.
2517 if (require_constant) {
2518 if (!o->can_be_constant()) return NULL;
2519 } else if (!o->should_be_constant()) {
2520 return TypeAryPtr::make(TypePtr::NotNull, arr0, klass, true, 0);
2521 }
2522 const TypeAryPtr* arr = TypeAryPtr::make(TypePtr::Constant, o, arr0, klass, true, 0);
2523 return arr;
2524 }
2525 }
2527 ShouldNotReachHere();
2528 return NULL;
2529 }
2531 //------------------------------get_con----------------------------------------
2532 intptr_t TypeOopPtr::get_con() const {
2533 assert( _ptr == Null || _ptr == Constant, "" );
2534 assert( _offset >= 0, "" );
2536 if (_offset != 0) {
2537 // After being ported to the compiler interface, the compiler no longer
2538 // directly manipulates the addresses of oops. Rather, it only has a pointer
2539 // to a handle at compile time. This handle is embedded in the generated
2540 // code and dereferenced at the time the nmethod is made. Until that time,
2541 // it is not reasonable to do arithmetic with the addresses of oops (we don't
2542 // have access to the addresses!). This does not seem to currently happen,
2543 // but this assertion here is to help prevent its occurence.
2544 tty->print_cr("Found oop constant with non-zero offset");
2545 ShouldNotReachHere();
2546 }
2548 return (intptr_t)const_oop()->constant_encoding();
2549 }
2552 //-----------------------------filter------------------------------------------
2553 // Do not allow interface-vs.-noninterface joins to collapse to top.
2554 const Type *TypeOopPtr::filter( const Type *kills ) const {
2556 const Type* ft = join(kills);
2557 const TypeInstPtr* ftip = ft->isa_instptr();
2558 const TypeInstPtr* ktip = kills->isa_instptr();
2559 const TypeKlassPtr* ftkp = ft->isa_klassptr();
2560 const TypeKlassPtr* ktkp = kills->isa_klassptr();
2562 if (ft->empty()) {
2563 // Check for evil case of 'this' being a class and 'kills' expecting an
2564 // interface. This can happen because the bytecodes do not contain
2565 // enough type info to distinguish a Java-level interface variable
2566 // from a Java-level object variable. If we meet 2 classes which
2567 // both implement interface I, but their meet is at 'j/l/O' which
2568 // doesn't implement I, we have no way to tell if the result should
2569 // be 'I' or 'j/l/O'. Thus we'll pick 'j/l/O'. If this then flows
2570 // into a Phi which "knows" it's an Interface type we'll have to
2571 // uplift the type.
2572 if (!empty() && ktip != NULL && ktip->is_loaded() && ktip->klass()->is_interface())
2573 return kills; // Uplift to interface
2574 if (!empty() && ktkp != NULL && ktkp->klass()->is_loaded() && ktkp->klass()->is_interface())
2575 return kills; // Uplift to interface
2577 return Type::TOP; // Canonical empty value
2578 }
2580 // If we have an interface-typed Phi or cast and we narrow to a class type,
2581 // the join should report back the class. However, if we have a J/L/Object
2582 // class-typed Phi and an interface flows in, it's possible that the meet &
2583 // join report an interface back out. This isn't possible but happens
2584 // because the type system doesn't interact well with interfaces.
2585 if (ftip != NULL && ktip != NULL &&
2586 ftip->is_loaded() && ftip->klass()->is_interface() &&
2587 ktip->is_loaded() && !ktip->klass()->is_interface()) {
2588 // Happens in a CTW of rt.jar, 320-341, no extra flags
2589 assert(!ftip->klass_is_exact(), "interface could not be exact");
2590 return ktip->cast_to_ptr_type(ftip->ptr());
2591 }
2592 // Interface klass type could be exact in opposite to interface type,
2593 // return it here instead of incorrect Constant ptr J/L/Object (6894807).
2594 if (ftkp != NULL && ktkp != NULL &&
2595 ftkp->is_loaded() && ftkp->klass()->is_interface() &&
2596 !ftkp->klass_is_exact() && // Keep exact interface klass
2597 ktkp->is_loaded() && !ktkp->klass()->is_interface()) {
2598 return ktkp->cast_to_ptr_type(ftkp->ptr());
2599 }
2601 return ft;
2602 }
2604 //------------------------------eq---------------------------------------------
2605 // Structural equality check for Type representations
2606 bool TypeOopPtr::eq( const Type *t ) const {
2607 const TypeOopPtr *a = (const TypeOopPtr*)t;
2608 if (_klass_is_exact != a->_klass_is_exact ||
2609 _instance_id != a->_instance_id) return false;
2610 ciObject* one = const_oop();
2611 ciObject* two = a->const_oop();
2612 if (one == NULL || two == NULL) {
2613 return (one == two) && TypePtr::eq(t);
2614 } else {
2615 return one->equals(two) && TypePtr::eq(t);
2616 }
2617 }
2619 //------------------------------hash-------------------------------------------
2620 // Type-specific hashing function.
2621 int TypeOopPtr::hash(void) const {
2622 return
2623 (const_oop() ? const_oop()->hash() : 0) +
2624 _klass_is_exact +
2625 _instance_id +
2626 TypePtr::hash();
2627 }
2629 //------------------------------dump2------------------------------------------
2630 #ifndef PRODUCT
2631 void TypeOopPtr::dump2( Dict &d, uint depth, outputStream *st ) const {
2632 st->print("oopptr:%s", ptr_msg[_ptr]);
2633 if( _klass_is_exact ) st->print(":exact");
2634 if( const_oop() ) st->print(INTPTR_FORMAT, const_oop());
2635 switch( _offset ) {
2636 case OffsetTop: st->print("+top"); break;
2637 case OffsetBot: st->print("+any"); break;
2638 case 0: break;
2639 default: st->print("+%d",_offset); break;
2640 }
2641 if (_instance_id == InstanceTop)
2642 st->print(",iid=top");
2643 else if (_instance_id != InstanceBot)
2644 st->print(",iid=%d",_instance_id);
2645 }
2646 #endif
2648 //------------------------------singleton--------------------------------------
2649 // TRUE if Type is a singleton type, FALSE otherwise. Singletons are simple
2650 // constants
2651 bool TypeOopPtr::singleton(void) const {
2652 // detune optimizer to not generate constant oop + constant offset as a constant!
2653 // TopPTR, Null, AnyNull, Constant are all singletons
2654 return (_offset == 0) && !below_centerline(_ptr);
2655 }
2657 //------------------------------add_offset-------------------------------------
2658 const TypePtr *TypeOopPtr::add_offset( intptr_t offset ) const {
2659 return make( _ptr, xadd_offset(offset), _instance_id);
2660 }
2662 //------------------------------meet_instance_id--------------------------------
2663 int TypeOopPtr::meet_instance_id( int instance_id ) const {
2664 // Either is 'TOP' instance? Return the other instance!
2665 if( _instance_id == InstanceTop ) return instance_id;
2666 if( instance_id == InstanceTop ) return _instance_id;
2667 // If either is different, return 'BOTTOM' instance
2668 if( _instance_id != instance_id ) return InstanceBot;
2669 return _instance_id;
2670 }
2672 //------------------------------dual_instance_id--------------------------------
2673 int TypeOopPtr::dual_instance_id( ) const {
2674 if( _instance_id == InstanceTop ) return InstanceBot; // Map TOP into BOTTOM
2675 if( _instance_id == InstanceBot ) return InstanceTop; // Map BOTTOM into TOP
2676 return _instance_id; // Map everything else into self
2677 }
2680 //=============================================================================
2681 // Convenience common pre-built types.
2682 const TypeInstPtr *TypeInstPtr::NOTNULL;
2683 const TypeInstPtr *TypeInstPtr::BOTTOM;
2684 const TypeInstPtr *TypeInstPtr::MIRROR;
2685 const TypeInstPtr *TypeInstPtr::MARK;
2686 const TypeInstPtr *TypeInstPtr::KLASS;
2688 //------------------------------TypeInstPtr-------------------------------------
2689 TypeInstPtr::TypeInstPtr(PTR ptr, ciKlass* k, bool xk, ciObject* o, int off, int instance_id)
2690 : TypeOopPtr(InstPtr, ptr, k, xk, o, off, instance_id), _name(k->name()) {
2691 assert(k != NULL &&
2692 (k->is_loaded() || o == NULL),
2693 "cannot have constants with non-loaded klass");
2694 };
2696 //------------------------------make-------------------------------------------
2697 const TypeInstPtr *TypeInstPtr::make(PTR ptr,
2698 ciKlass* k,
2699 bool xk,
2700 ciObject* o,
2701 int offset,
2702 int instance_id) {
2703 assert( !k->is_loaded() || k->is_instance_klass() ||
2704 k->is_method_klass(), "Must be for instance or method");
2705 // Either const_oop() is NULL or else ptr is Constant
2706 assert( (!o && ptr != Constant) || (o && ptr == Constant),
2707 "constant pointers must have a value supplied" );
2708 // Ptr is never Null
2709 assert( ptr != Null, "NULL pointers are not typed" );
2711 assert(instance_id <= 0 || xk || !UseExactTypes, "instances are always exactly typed");
2712 if (!UseExactTypes) xk = false;
2713 if (ptr == Constant) {
2714 // Note: This case includes meta-object constants, such as methods.
2715 xk = true;
2716 } else if (k->is_loaded()) {
2717 ciInstanceKlass* ik = k->as_instance_klass();
2718 if (!xk && ik->is_final()) xk = true; // no inexact final klass
2719 if (xk && ik->is_interface()) xk = false; // no exact interface
2720 }
2722 // Now hash this baby
2723 TypeInstPtr *result =
2724 (TypeInstPtr*)(new TypeInstPtr(ptr, k, xk, o ,offset, instance_id))->hashcons();
2726 return result;
2727 }
2730 //------------------------------cast_to_ptr_type-------------------------------
2731 const Type *TypeInstPtr::cast_to_ptr_type(PTR ptr) const {
2732 if( ptr == _ptr ) return this;
2733 // Reconstruct _sig info here since not a problem with later lazy
2734 // construction, _sig will show up on demand.
2735 return make(ptr, klass(), klass_is_exact(), const_oop(), _offset, _instance_id);
2736 }
2739 //-----------------------------cast_to_exactness-------------------------------
2740 const Type *TypeInstPtr::cast_to_exactness(bool klass_is_exact) const {
2741 if( klass_is_exact == _klass_is_exact ) return this;
2742 if (!UseExactTypes) return this;
2743 if (!_klass->is_loaded()) return this;
2744 ciInstanceKlass* ik = _klass->as_instance_klass();
2745 if( (ik->is_final() || _const_oop) ) return this; // cannot clear xk
2746 if( ik->is_interface() ) return this; // cannot set xk
2747 return make(ptr(), klass(), klass_is_exact, const_oop(), _offset, _instance_id);
2748 }
2750 //-----------------------------cast_to_instance_id----------------------------
2751 const TypeOopPtr *TypeInstPtr::cast_to_instance_id(int instance_id) const {
2752 if( instance_id == _instance_id ) return this;
2753 return make(_ptr, klass(), _klass_is_exact, const_oop(), _offset, instance_id);
2754 }
2756 //------------------------------xmeet_unloaded---------------------------------
2757 // Compute the MEET of two InstPtrs when at least one is unloaded.
2758 // Assume classes are different since called after check for same name/class-loader
2759 const TypeInstPtr *TypeInstPtr::xmeet_unloaded(const TypeInstPtr *tinst) const {
2760 int off = meet_offset(tinst->offset());
2761 PTR ptr = meet_ptr(tinst->ptr());
2762 int instance_id = meet_instance_id(tinst->instance_id());
2764 const TypeInstPtr *loaded = is_loaded() ? this : tinst;
2765 const TypeInstPtr *unloaded = is_loaded() ? tinst : this;
2766 if( loaded->klass()->equals(ciEnv::current()->Object_klass()) ) {
2767 //
2768 // Meet unloaded class with java/lang/Object
2769 //
2770 // Meet
2771 // | Unloaded Class
2772 // Object | TOP | AnyNull | Constant | NotNull | BOTTOM |
2773 // ===================================================================
2774 // TOP | ..........................Unloaded......................|
2775 // AnyNull | U-AN |................Unloaded......................|
2776 // Constant | ... O-NN .................................. | O-BOT |
2777 // NotNull | ... O-NN .................................. | O-BOT |
2778 // BOTTOM | ........................Object-BOTTOM ..................|
2779 //
2780 assert(loaded->ptr() != TypePtr::Null, "insanity check");
2781 //
2782 if( loaded->ptr() == TypePtr::TopPTR ) { return unloaded; }
2783 else if (loaded->ptr() == TypePtr::AnyNull) { return TypeInstPtr::make( ptr, unloaded->klass(), false, NULL, off, instance_id ); }
2784 else if (loaded->ptr() == TypePtr::BotPTR ) { return TypeInstPtr::BOTTOM; }
2785 else if (loaded->ptr() == TypePtr::Constant || loaded->ptr() == TypePtr::NotNull) {
2786 if (unloaded->ptr() == TypePtr::BotPTR ) { return TypeInstPtr::BOTTOM; }
2787 else { return TypeInstPtr::NOTNULL; }
2788 }
2789 else if( unloaded->ptr() == TypePtr::TopPTR ) { return unloaded; }
2791 return unloaded->cast_to_ptr_type(TypePtr::AnyNull)->is_instptr();
2792 }
2794 // Both are unloaded, not the same class, not Object
2795 // Or meet unloaded with a different loaded class, not java/lang/Object
2796 if( ptr != TypePtr::BotPTR ) {
2797 return TypeInstPtr::NOTNULL;
2798 }
2799 return TypeInstPtr::BOTTOM;
2800 }
2803 //------------------------------meet-------------------------------------------
2804 // Compute the MEET of two types. It returns a new Type object.
2805 const Type *TypeInstPtr::xmeet( const Type *t ) const {
2806 // Perform a fast test for common case; meeting the same types together.
2807 if( this == t ) return this; // Meeting same type-rep?
2809 // Current "this->_base" is Pointer
2810 switch (t->base()) { // switch on original type
2812 case Int: // Mixing ints & oops happens when javac
2813 case Long: // reuses local variables
2814 case FloatTop:
2815 case FloatCon:
2816 case FloatBot:
2817 case DoubleTop:
2818 case DoubleCon:
2819 case DoubleBot:
2820 case NarrowOop:
2821 case Bottom: // Ye Olde Default
2822 return Type::BOTTOM;
2823 case Top:
2824 return this;
2826 default: // All else is a mistake
2827 typerr(t);
2829 case RawPtr: return TypePtr::BOTTOM;
2831 case AryPtr: { // All arrays inherit from Object class
2832 const TypeAryPtr *tp = t->is_aryptr();
2833 int offset = meet_offset(tp->offset());
2834 PTR ptr = meet_ptr(tp->ptr());
2835 int instance_id = meet_instance_id(tp->instance_id());
2836 switch (ptr) {
2837 case TopPTR:
2838 case AnyNull: // Fall 'down' to dual of object klass
2839 if (klass()->equals(ciEnv::current()->Object_klass())) {
2840 return TypeAryPtr::make(ptr, tp->ary(), tp->klass(), tp->klass_is_exact(), offset, instance_id);
2841 } else {
2842 // cannot subclass, so the meet has to fall badly below the centerline
2843 ptr = NotNull;
2844 instance_id = InstanceBot;
2845 return TypeInstPtr::make( ptr, ciEnv::current()->Object_klass(), false, NULL, offset, instance_id);
2846 }
2847 case Constant:
2848 case NotNull:
2849 case BotPTR: // Fall down to object klass
2850 // LCA is object_klass, but if we subclass from the top we can do better
2851 if( above_centerline(_ptr) ) { // if( _ptr == TopPTR || _ptr == AnyNull )
2852 // If 'this' (InstPtr) is above the centerline and it is Object class
2853 // then we can subclass in the Java class hierarchy.
2854 if (klass()->equals(ciEnv::current()->Object_klass())) {
2855 // that is, tp's array type is a subtype of my klass
2856 return TypeAryPtr::make(ptr, (ptr == Constant ? tp->const_oop() : NULL),
2857 tp->ary(), tp->klass(), tp->klass_is_exact(), offset, instance_id);
2858 }
2859 }
2860 // The other case cannot happen, since I cannot be a subtype of an array.
2861 // The meet falls down to Object class below centerline.
2862 if( ptr == Constant )
2863 ptr = NotNull;
2864 instance_id = InstanceBot;
2865 return make( ptr, ciEnv::current()->Object_klass(), false, NULL, offset, instance_id );
2866 default: typerr(t);
2867 }
2868 }
2870 case OopPtr: { // Meeting to OopPtrs
2871 // Found a OopPtr type vs self-InstPtr type
2872 const TypeOopPtr *tp = t->is_oopptr();
2873 int offset = meet_offset(tp->offset());
2874 PTR ptr = meet_ptr(tp->ptr());
2875 switch (tp->ptr()) {
2876 case TopPTR:
2877 case AnyNull: {
2878 int instance_id = meet_instance_id(InstanceTop);
2879 return make(ptr, klass(), klass_is_exact(),
2880 (ptr == Constant ? const_oop() : NULL), offset, instance_id);
2881 }
2882 case NotNull:
2883 case BotPTR: {
2884 int instance_id = meet_instance_id(tp->instance_id());
2885 return TypeOopPtr::make(ptr, offset, instance_id);
2886 }
2887 default: typerr(t);
2888 }
2889 }
2891 case AnyPtr: { // Meeting to AnyPtrs
2892 // Found an AnyPtr type vs self-InstPtr type
2893 const TypePtr *tp = t->is_ptr();
2894 int offset = meet_offset(tp->offset());
2895 PTR ptr = meet_ptr(tp->ptr());
2896 switch (tp->ptr()) {
2897 case Null:
2898 if( ptr == Null ) return TypePtr::make( AnyPtr, ptr, offset );
2899 // else fall through to AnyNull
2900 case TopPTR:
2901 case AnyNull: {
2902 int instance_id = meet_instance_id(InstanceTop);
2903 return make( ptr, klass(), klass_is_exact(),
2904 (ptr == Constant ? const_oop() : NULL), offset, instance_id);
2905 }
2906 case NotNull:
2907 case BotPTR:
2908 return TypePtr::make( AnyPtr, ptr, offset );
2909 default: typerr(t);
2910 }
2911 }
2913 /*
2914 A-top }
2915 / | \ } Tops
2916 B-top A-any C-top }
2917 | / | \ | } Any-nulls
2918 B-any | C-any }
2919 | | |
2920 B-con A-con C-con } constants; not comparable across classes
2921 | | |
2922 B-not | C-not }
2923 | \ | / | } not-nulls
2924 B-bot A-not C-bot }
2925 \ | / } Bottoms
2926 A-bot }
2927 */
2929 case InstPtr: { // Meeting 2 Oops?
2930 // Found an InstPtr sub-type vs self-InstPtr type
2931 const TypeInstPtr *tinst = t->is_instptr();
2932 int off = meet_offset( tinst->offset() );
2933 PTR ptr = meet_ptr( tinst->ptr() );
2934 int instance_id = meet_instance_id(tinst->instance_id());
2936 // Check for easy case; klasses are equal (and perhaps not loaded!)
2937 // If we have constants, then we created oops so classes are loaded
2938 // and we can handle the constants further down. This case handles
2939 // both-not-loaded or both-loaded classes
2940 if (ptr != Constant && klass()->equals(tinst->klass()) && klass_is_exact() == tinst->klass_is_exact()) {
2941 return make( ptr, klass(), klass_is_exact(), NULL, off, instance_id );
2942 }
2944 // Classes require inspection in the Java klass hierarchy. Must be loaded.
2945 ciKlass* tinst_klass = tinst->klass();
2946 ciKlass* this_klass = this->klass();
2947 bool tinst_xk = tinst->klass_is_exact();
2948 bool this_xk = this->klass_is_exact();
2949 if (!tinst_klass->is_loaded() || !this_klass->is_loaded() ) {
2950 // One of these classes has not been loaded
2951 const TypeInstPtr *unloaded_meet = xmeet_unloaded(tinst);
2952 #ifndef PRODUCT
2953 if( PrintOpto && Verbose ) {
2954 tty->print("meet of unloaded classes resulted in: "); unloaded_meet->dump(); tty->cr();
2955 tty->print(" this == "); this->dump(); tty->cr();
2956 tty->print(" tinst == "); tinst->dump(); tty->cr();
2957 }
2958 #endif
2959 return unloaded_meet;
2960 }
2962 // Handle mixing oops and interfaces first.
2963 if( this_klass->is_interface() && !tinst_klass->is_interface() ) {
2964 ciKlass *tmp = tinst_klass; // Swap interface around
2965 tinst_klass = this_klass;
2966 this_klass = tmp;
2967 bool tmp2 = tinst_xk;
2968 tinst_xk = this_xk;
2969 this_xk = tmp2;
2970 }
2971 if (tinst_klass->is_interface() &&
2972 !(this_klass->is_interface() ||
2973 // Treat java/lang/Object as an honorary interface,
2974 // because we need a bottom for the interface hierarchy.
2975 this_klass == ciEnv::current()->Object_klass())) {
2976 // Oop meets interface!
2978 // See if the oop subtypes (implements) interface.
2979 ciKlass *k;
2980 bool xk;
2981 if( this_klass->is_subtype_of( tinst_klass ) ) {
2982 // Oop indeed subtypes. Now keep oop or interface depending
2983 // on whether we are both above the centerline or either is
2984 // below the centerline. If we are on the centerline
2985 // (e.g., Constant vs. AnyNull interface), use the constant.
2986 k = below_centerline(ptr) ? tinst_klass : this_klass;
2987 // If we are keeping this_klass, keep its exactness too.
2988 xk = below_centerline(ptr) ? tinst_xk : this_xk;
2989 } else { // Does not implement, fall to Object
2990 // Oop does not implement interface, so mixing falls to Object
2991 // just like the verifier does (if both are above the
2992 // centerline fall to interface)
2993 k = above_centerline(ptr) ? tinst_klass : ciEnv::current()->Object_klass();
2994 xk = above_centerline(ptr) ? tinst_xk : false;
2995 // Watch out for Constant vs. AnyNull interface.
2996 if (ptr == Constant) ptr = NotNull; // forget it was a constant
2997 instance_id = InstanceBot;
2998 }
2999 ciObject* o = NULL; // the Constant value, if any
3000 if (ptr == Constant) {
3001 // Find out which constant.
3002 o = (this_klass == klass()) ? const_oop() : tinst->const_oop();
3003 }
3004 return make( ptr, k, xk, o, off, instance_id );
3005 }
3007 // Either oop vs oop or interface vs interface or interface vs Object
3009 // !!! Here's how the symmetry requirement breaks down into invariants:
3010 // If we split one up & one down AND they subtype, take the down man.
3011 // If we split one up & one down AND they do NOT subtype, "fall hard".
3012 // If both are up and they subtype, take the subtype class.
3013 // If both are up and they do NOT subtype, "fall hard".
3014 // If both are down and they subtype, take the supertype class.
3015 // If both are down and they do NOT subtype, "fall hard".
3016 // Constants treated as down.
3018 // Now, reorder the above list; observe that both-down+subtype is also
3019 // "fall hard"; "fall hard" becomes the default case:
3020 // If we split one up & one down AND they subtype, take the down man.
3021 // If both are up and they subtype, take the subtype class.
3023 // If both are down and they subtype, "fall hard".
3024 // If both are down and they do NOT subtype, "fall hard".
3025 // If both are up and they do NOT subtype, "fall hard".
3026 // If we split one up & one down AND they do NOT subtype, "fall hard".
3028 // If a proper subtype is exact, and we return it, we return it exactly.
3029 // If a proper supertype is exact, there can be no subtyping relationship!
3030 // If both types are equal to the subtype, exactness is and-ed below the
3031 // centerline and or-ed above it. (N.B. Constants are always exact.)
3033 // Check for subtyping:
3034 ciKlass *subtype = NULL;
3035 bool subtype_exact = false;
3036 if( tinst_klass->equals(this_klass) ) {
3037 subtype = this_klass;
3038 subtype_exact = below_centerline(ptr) ? (this_xk & tinst_xk) : (this_xk | tinst_xk);
3039 } else if( !tinst_xk && this_klass->is_subtype_of( tinst_klass ) ) {
3040 subtype = this_klass; // Pick subtyping class
3041 subtype_exact = this_xk;
3042 } else if( !this_xk && tinst_klass->is_subtype_of( this_klass ) ) {
3043 subtype = tinst_klass; // Pick subtyping class
3044 subtype_exact = tinst_xk;
3045 }
3047 if( subtype ) {
3048 if( above_centerline(ptr) ) { // both are up?
3049 this_klass = tinst_klass = subtype;
3050 this_xk = tinst_xk = subtype_exact;
3051 } else if( above_centerline(this ->_ptr) && !above_centerline(tinst->_ptr) ) {
3052 this_klass = tinst_klass; // tinst is down; keep down man
3053 this_xk = tinst_xk;
3054 } else if( above_centerline(tinst->_ptr) && !above_centerline(this ->_ptr) ) {
3055 tinst_klass = this_klass; // this is down; keep down man
3056 tinst_xk = this_xk;
3057 } else {
3058 this_xk = subtype_exact; // either they are equal, or we'll do an LCA
3059 }
3060 }
3062 // Check for classes now being equal
3063 if (tinst_klass->equals(this_klass)) {
3064 // If the klasses are equal, the constants may still differ. Fall to
3065 // NotNull if they do (neither constant is NULL; that is a special case
3066 // handled elsewhere).
3067 ciObject* o = NULL; // Assume not constant when done
3068 ciObject* this_oop = const_oop();
3069 ciObject* tinst_oop = tinst->const_oop();
3070 if( ptr == Constant ) {
3071 if (this_oop != NULL && tinst_oop != NULL &&
3072 this_oop->equals(tinst_oop) )
3073 o = this_oop;
3074 else if (above_centerline(this ->_ptr))
3075 o = tinst_oop;
3076 else if (above_centerline(tinst ->_ptr))
3077 o = this_oop;
3078 else
3079 ptr = NotNull;
3080 }
3081 return make( ptr, this_klass, this_xk, o, off, instance_id );
3082 } // Else classes are not equal
3084 // Since klasses are different, we require a LCA in the Java
3085 // class hierarchy - which means we have to fall to at least NotNull.
3086 if( ptr == TopPTR || ptr == AnyNull || ptr == Constant )
3087 ptr = NotNull;
3088 instance_id = InstanceBot;
3090 // Now we find the LCA of Java classes
3091 ciKlass* k = this_klass->least_common_ancestor(tinst_klass);
3092 return make( ptr, k, false, NULL, off, instance_id );
3093 } // End of case InstPtr
3095 case KlassPtr:
3096 return TypeInstPtr::BOTTOM;
3098 } // End of switch
3099 return this; // Return the double constant
3100 }
3103 //------------------------java_mirror_type--------------------------------------
3104 ciType* TypeInstPtr::java_mirror_type() const {
3105 // must be a singleton type
3106 if( const_oop() == NULL ) return NULL;
3108 // must be of type java.lang.Class
3109 if( klass() != ciEnv::current()->Class_klass() ) return NULL;
3111 return const_oop()->as_instance()->java_mirror_type();
3112 }
3115 //------------------------------xdual------------------------------------------
3116 // Dual: do NOT dual on klasses. This means I do NOT understand the Java
3117 // inheritance mechanism.
3118 const Type *TypeInstPtr::xdual() const {
3119 return new TypeInstPtr( dual_ptr(), klass(), klass_is_exact(), const_oop(), dual_offset(), dual_instance_id() );
3120 }
3122 //------------------------------eq---------------------------------------------
3123 // Structural equality check for Type representations
3124 bool TypeInstPtr::eq( const Type *t ) const {
3125 const TypeInstPtr *p = t->is_instptr();
3126 return
3127 klass()->equals(p->klass()) &&
3128 TypeOopPtr::eq(p); // Check sub-type stuff
3129 }
3131 //------------------------------hash-------------------------------------------
3132 // Type-specific hashing function.
3133 int TypeInstPtr::hash(void) const {
3134 int hash = klass()->hash() + TypeOopPtr::hash();
3135 return hash;
3136 }
3138 //------------------------------dump2------------------------------------------
3139 // Dump oop Type
3140 #ifndef PRODUCT
3141 void TypeInstPtr::dump2( Dict &d, uint depth, outputStream *st ) const {
3142 // Print the name of the klass.
3143 klass()->print_name_on(st);
3145 switch( _ptr ) {
3146 case Constant:
3147 // TO DO: Make CI print the hex address of the underlying oop.
3148 if (WizardMode || Verbose) {
3149 const_oop()->print_oop(st);
3150 }
3151 case BotPTR:
3152 if (!WizardMode && !Verbose) {
3153 if( _klass_is_exact ) st->print(":exact");
3154 break;
3155 }
3156 case TopPTR:
3157 case AnyNull:
3158 case NotNull:
3159 st->print(":%s", ptr_msg[_ptr]);
3160 if( _klass_is_exact ) st->print(":exact");
3161 break;
3162 }
3164 if( _offset ) { // Dump offset, if any
3165 if( _offset == OffsetBot ) st->print("+any");
3166 else if( _offset == OffsetTop ) st->print("+unknown");
3167 else st->print("+%d", _offset);
3168 }
3170 st->print(" *");
3171 if (_instance_id == InstanceTop)
3172 st->print(",iid=top");
3173 else if (_instance_id != InstanceBot)
3174 st->print(",iid=%d",_instance_id);
3175 }
3176 #endif
3178 //------------------------------add_offset-------------------------------------
3179 const TypePtr *TypeInstPtr::add_offset( intptr_t offset ) const {
3180 return make( _ptr, klass(), klass_is_exact(), const_oop(), xadd_offset(offset), _instance_id );
3181 }
3183 //=============================================================================
3184 // Convenience common pre-built types.
3185 const TypeAryPtr *TypeAryPtr::RANGE;
3186 const TypeAryPtr *TypeAryPtr::OOPS;
3187 const TypeAryPtr *TypeAryPtr::NARROWOOPS;
3188 const TypeAryPtr *TypeAryPtr::BYTES;
3189 const TypeAryPtr *TypeAryPtr::SHORTS;
3190 const TypeAryPtr *TypeAryPtr::CHARS;
3191 const TypeAryPtr *TypeAryPtr::INTS;
3192 const TypeAryPtr *TypeAryPtr::LONGS;
3193 const TypeAryPtr *TypeAryPtr::FLOATS;
3194 const TypeAryPtr *TypeAryPtr::DOUBLES;
3196 //------------------------------make-------------------------------------------
3197 const TypeAryPtr *TypeAryPtr::make( PTR ptr, const TypeAry *ary, ciKlass* k, bool xk, int offset, int instance_id ) {
3198 assert(!(k == NULL && ary->_elem->isa_int()),
3199 "integral arrays must be pre-equipped with a class");
3200 if (!xk) xk = ary->ary_must_be_exact();
3201 assert(instance_id <= 0 || xk || !UseExactTypes, "instances are always exactly typed");
3202 if (!UseExactTypes) xk = (ptr == Constant);
3203 return (TypeAryPtr*)(new TypeAryPtr(ptr, NULL, ary, k, xk, offset, instance_id))->hashcons();
3204 }
3206 //------------------------------make-------------------------------------------
3207 const TypeAryPtr *TypeAryPtr::make( PTR ptr, ciObject* o, const TypeAry *ary, ciKlass* k, bool xk, int offset, int instance_id ) {
3208 assert(!(k == NULL && ary->_elem->isa_int()),
3209 "integral arrays must be pre-equipped with a class");
3210 assert( (ptr==Constant && o) || (ptr!=Constant && !o), "" );
3211 if (!xk) xk = (o != NULL) || ary->ary_must_be_exact();
3212 assert(instance_id <= 0 || xk || !UseExactTypes, "instances are always exactly typed");
3213 if (!UseExactTypes) xk = (ptr == Constant);
3214 return (TypeAryPtr*)(new TypeAryPtr(ptr, o, ary, k, xk, offset, instance_id))->hashcons();
3215 }
3217 //------------------------------cast_to_ptr_type-------------------------------
3218 const Type *TypeAryPtr::cast_to_ptr_type(PTR ptr) const {
3219 if( ptr == _ptr ) return this;
3220 return make(ptr, const_oop(), _ary, klass(), klass_is_exact(), _offset, _instance_id);
3221 }
3224 //-----------------------------cast_to_exactness-------------------------------
3225 const Type *TypeAryPtr::cast_to_exactness(bool klass_is_exact) const {
3226 if( klass_is_exact == _klass_is_exact ) return this;
3227 if (!UseExactTypes) return this;
3228 if (_ary->ary_must_be_exact()) return this; // cannot clear xk
3229 return make(ptr(), const_oop(), _ary, klass(), klass_is_exact, _offset, _instance_id);
3230 }
3232 //-----------------------------cast_to_instance_id----------------------------
3233 const TypeOopPtr *TypeAryPtr::cast_to_instance_id(int instance_id) const {
3234 if( instance_id == _instance_id ) return this;
3235 return make(_ptr, const_oop(), _ary, klass(), _klass_is_exact, _offset, instance_id);
3236 }
3238 //-----------------------------narrow_size_type-------------------------------
3239 // Local cache for arrayOopDesc::max_array_length(etype),
3240 // which is kind of slow (and cached elsewhere by other users).
3241 static jint max_array_length_cache[T_CONFLICT+1];
3242 static jint max_array_length(BasicType etype) {
3243 jint& cache = max_array_length_cache[etype];
3244 jint res = cache;
3245 if (res == 0) {
3246 switch (etype) {
3247 case T_NARROWOOP:
3248 etype = T_OBJECT;
3249 break;
3250 case T_CONFLICT:
3251 case T_ILLEGAL:
3252 case T_VOID:
3253 etype = T_BYTE; // will produce conservatively high value
3254 }
3255 cache = res = arrayOopDesc::max_array_length(etype);
3256 }
3257 return res;
3258 }
3260 // Narrow the given size type to the index range for the given array base type.
3261 // Return NULL if the resulting int type becomes empty.
3262 const TypeInt* TypeAryPtr::narrow_size_type(const TypeInt* size) const {
3263 jint hi = size->_hi;
3264 jint lo = size->_lo;
3265 jint min_lo = 0;
3266 jint max_hi = max_array_length(elem()->basic_type());
3267 //if (index_not_size) --max_hi; // type of a valid array index, FTR
3268 bool chg = false;
3269 if (lo < min_lo) { lo = min_lo; chg = true; }
3270 if (hi > max_hi) { hi = max_hi; chg = true; }
3271 // Negative length arrays will produce weird intermediate dead fast-path code
3272 if (lo > hi)
3273 return TypeInt::ZERO;
3274 if (!chg)
3275 return size;
3276 return TypeInt::make(lo, hi, Type::WidenMin);
3277 }
3279 //-------------------------------cast_to_size----------------------------------
3280 const TypeAryPtr* TypeAryPtr::cast_to_size(const TypeInt* new_size) const {
3281 assert(new_size != NULL, "");
3282 new_size = narrow_size_type(new_size);
3283 if (new_size == size()) return this;
3284 const TypeAry* new_ary = TypeAry::make(elem(), new_size);
3285 return make(ptr(), const_oop(), new_ary, klass(), klass_is_exact(), _offset, _instance_id);
3286 }
3289 //------------------------------eq---------------------------------------------
3290 // Structural equality check for Type representations
3291 bool TypeAryPtr::eq( const Type *t ) const {
3292 const TypeAryPtr *p = t->is_aryptr();
3293 return
3294 _ary == p->_ary && // Check array
3295 TypeOopPtr::eq(p); // Check sub-parts
3296 }
3298 //------------------------------hash-------------------------------------------
3299 // Type-specific hashing function.
3300 int TypeAryPtr::hash(void) const {
3301 return (intptr_t)_ary + TypeOopPtr::hash();
3302 }
3304 //------------------------------meet-------------------------------------------
3305 // Compute the MEET of two types. It returns a new Type object.
3306 const Type *TypeAryPtr::xmeet( const Type *t ) const {
3307 // Perform a fast test for common case; meeting the same types together.
3308 if( this == t ) return this; // Meeting same type-rep?
3309 // Current "this->_base" is Pointer
3310 switch (t->base()) { // switch on original type
3312 // Mixing ints & oops happens when javac reuses local variables
3313 case Int:
3314 case Long:
3315 case FloatTop:
3316 case FloatCon:
3317 case FloatBot:
3318 case DoubleTop:
3319 case DoubleCon:
3320 case DoubleBot:
3321 case NarrowOop:
3322 case Bottom: // Ye Olde Default
3323 return Type::BOTTOM;
3324 case Top:
3325 return this;
3327 default: // All else is a mistake
3328 typerr(t);
3330 case OopPtr: { // Meeting to OopPtrs
3331 // Found a OopPtr type vs self-AryPtr type
3332 const TypeOopPtr *tp = t->is_oopptr();
3333 int offset = meet_offset(tp->offset());
3334 PTR ptr = meet_ptr(tp->ptr());
3335 switch (tp->ptr()) {
3336 case TopPTR:
3337 case AnyNull: {
3338 int instance_id = meet_instance_id(InstanceTop);
3339 return make(ptr, (ptr == Constant ? const_oop() : NULL),
3340 _ary, _klass, _klass_is_exact, offset, instance_id);
3341 }
3342 case BotPTR:
3343 case NotNull: {
3344 int instance_id = meet_instance_id(tp->instance_id());
3345 return TypeOopPtr::make(ptr, offset, instance_id);
3346 }
3347 default: ShouldNotReachHere();
3348 }
3349 }
3351 case AnyPtr: { // Meeting two AnyPtrs
3352 // Found an AnyPtr type vs self-AryPtr type
3353 const TypePtr *tp = t->is_ptr();
3354 int offset = meet_offset(tp->offset());
3355 PTR ptr = meet_ptr(tp->ptr());
3356 switch (tp->ptr()) {
3357 case TopPTR:
3358 return this;
3359 case BotPTR:
3360 case NotNull:
3361 return TypePtr::make(AnyPtr, ptr, offset);
3362 case Null:
3363 if( ptr == Null ) return TypePtr::make(AnyPtr, ptr, offset);
3364 // else fall through to AnyNull
3365 case AnyNull: {
3366 int instance_id = meet_instance_id(InstanceTop);
3367 return make( ptr, (ptr == Constant ? const_oop() : NULL),
3368 _ary, _klass, _klass_is_exact, offset, instance_id);
3369 }
3370 default: ShouldNotReachHere();
3371 }
3372 }
3374 case RawPtr: return TypePtr::BOTTOM;
3376 case AryPtr: { // Meeting 2 references?
3377 const TypeAryPtr *tap = t->is_aryptr();
3378 int off = meet_offset(tap->offset());
3379 const TypeAry *tary = _ary->meet(tap->_ary)->is_ary();
3380 PTR ptr = meet_ptr(tap->ptr());
3381 int instance_id = meet_instance_id(tap->instance_id());
3382 ciKlass* lazy_klass = NULL;
3383 if (tary->_elem->isa_int()) {
3384 // Integral array element types have irrelevant lattice relations.
3385 // It is the klass that determines array layout, not the element type.
3386 if (_klass == NULL)
3387 lazy_klass = tap->_klass;
3388 else if (tap->_klass == NULL || tap->_klass == _klass) {
3389 lazy_klass = _klass;
3390 } else {
3391 // Something like byte[int+] meets char[int+].
3392 // This must fall to bottom, not (int[-128..65535])[int+].
3393 instance_id = InstanceBot;
3394 tary = TypeAry::make(Type::BOTTOM, tary->_size);
3395 }
3396 } else // Non integral arrays.
3397 // Must fall to bottom if exact klasses in upper lattice
3398 // are not equal or super klass is exact.
3399 if ( above_centerline(ptr) && klass() != tap->klass() &&
3400 // meet with top[] and bottom[] are processed further down:
3401 tap ->_klass != NULL && this->_klass != NULL &&
3402 // both are exact and not equal:
3403 ((tap ->_klass_is_exact && this->_klass_is_exact) ||
3404 // 'tap' is exact and super or unrelated:
3405 (tap ->_klass_is_exact && !tap->klass()->is_subtype_of(klass())) ||
3406 // 'this' is exact and super or unrelated:
3407 (this->_klass_is_exact && !klass()->is_subtype_of(tap->klass())))) {
3408 tary = TypeAry::make(Type::BOTTOM, tary->_size);
3409 return make( NotNull, NULL, tary, lazy_klass, false, off, InstanceBot );
3410 }
3412 bool xk = false;
3413 switch (tap->ptr()) {
3414 case AnyNull:
3415 case TopPTR:
3416 // Compute new klass on demand, do not use tap->_klass
3417 xk = (tap->_klass_is_exact | this->_klass_is_exact);
3418 return make( ptr, const_oop(), tary, lazy_klass, xk, off, instance_id );
3419 case Constant: {
3420 ciObject* o = const_oop();
3421 if( _ptr == Constant ) {
3422 if( tap->const_oop() != NULL && !o->equals(tap->const_oop()) ) {
3423 xk = (klass() == tap->klass());
3424 ptr = NotNull;
3425 o = NULL;
3426 instance_id = InstanceBot;
3427 } else {
3428 xk = true;
3429 }
3430 } else if( above_centerline(_ptr) ) {
3431 o = tap->const_oop();
3432 xk = true;
3433 } else {
3434 // Only precise for identical arrays
3435 xk = this->_klass_is_exact && (klass() == tap->klass());
3436 }
3437 return TypeAryPtr::make( ptr, o, tary, lazy_klass, xk, off, instance_id );
3438 }
3439 case NotNull:
3440 case BotPTR:
3441 // Compute new klass on demand, do not use tap->_klass
3442 if (above_centerline(this->_ptr))
3443 xk = tap->_klass_is_exact;
3444 else if (above_centerline(tap->_ptr))
3445 xk = this->_klass_is_exact;
3446 else xk = (tap->_klass_is_exact & this->_klass_is_exact) &&
3447 (klass() == tap->klass()); // Only precise for identical arrays
3448 return TypeAryPtr::make( ptr, NULL, tary, lazy_klass, xk, off, instance_id );
3449 default: ShouldNotReachHere();
3450 }
3451 }
3453 // All arrays inherit from Object class
3454 case InstPtr: {
3455 const TypeInstPtr *tp = t->is_instptr();
3456 int offset = meet_offset(tp->offset());
3457 PTR ptr = meet_ptr(tp->ptr());
3458 int instance_id = meet_instance_id(tp->instance_id());
3459 switch (ptr) {
3460 case TopPTR:
3461 case AnyNull: // Fall 'down' to dual of object klass
3462 if( tp->klass()->equals(ciEnv::current()->Object_klass()) ) {
3463 return TypeAryPtr::make( ptr, _ary, _klass, _klass_is_exact, offset, instance_id );
3464 } else {
3465 // cannot subclass, so the meet has to fall badly below the centerline
3466 ptr = NotNull;
3467 instance_id = InstanceBot;
3468 return TypeInstPtr::make( ptr, ciEnv::current()->Object_klass(), false, NULL,offset, instance_id);
3469 }
3470 case Constant:
3471 case NotNull:
3472 case BotPTR: // Fall down to object klass
3473 // LCA is object_klass, but if we subclass from the top we can do better
3474 if (above_centerline(tp->ptr())) {
3475 // If 'tp' is above the centerline and it is Object class
3476 // then we can subclass in the Java class hierarchy.
3477 if( tp->klass()->equals(ciEnv::current()->Object_klass()) ) {
3478 // that is, my array type is a subtype of 'tp' klass
3479 return make( ptr, (ptr == Constant ? const_oop() : NULL),
3480 _ary, _klass, _klass_is_exact, offset, instance_id );
3481 }
3482 }
3483 // The other case cannot happen, since t cannot be a subtype of an array.
3484 // The meet falls down to Object class below centerline.
3485 if( ptr == Constant )
3486 ptr = NotNull;
3487 instance_id = InstanceBot;
3488 return TypeInstPtr::make( ptr, ciEnv::current()->Object_klass(), false, NULL,offset, instance_id);
3489 default: typerr(t);
3490 }
3491 }
3493 case KlassPtr:
3494 return TypeInstPtr::BOTTOM;
3496 }
3497 return this; // Lint noise
3498 }
3500 //------------------------------xdual------------------------------------------
3501 // Dual: compute field-by-field dual
3502 const Type *TypeAryPtr::xdual() const {
3503 return new TypeAryPtr( dual_ptr(), _const_oop, _ary->dual()->is_ary(),_klass, _klass_is_exact, dual_offset(), dual_instance_id() );
3504 }
3506 //----------------------interface_vs_oop---------------------------------------
3507 #ifdef ASSERT
3508 bool TypeAryPtr::interface_vs_oop(const Type *t) const {
3509 const TypeAryPtr* t_aryptr = t->isa_aryptr();
3510 if (t_aryptr) {
3511 return _ary->interface_vs_oop(t_aryptr->_ary);
3512 }
3513 return false;
3514 }
3515 #endif
3517 //------------------------------dump2------------------------------------------
3518 #ifndef PRODUCT
3519 void TypeAryPtr::dump2( Dict &d, uint depth, outputStream *st ) const {
3520 _ary->dump2(d,depth,st);
3521 switch( _ptr ) {
3522 case Constant:
3523 const_oop()->print(st);
3524 break;
3525 case BotPTR:
3526 if (!WizardMode && !Verbose) {
3527 if( _klass_is_exact ) st->print(":exact");
3528 break;
3529 }
3530 case TopPTR:
3531 case AnyNull:
3532 case NotNull:
3533 st->print(":%s", ptr_msg[_ptr]);
3534 if( _klass_is_exact ) st->print(":exact");
3535 break;
3536 }
3538 if( _offset != 0 ) {
3539 int header_size = objArrayOopDesc::header_size() * wordSize;
3540 if( _offset == OffsetTop ) st->print("+undefined");
3541 else if( _offset == OffsetBot ) st->print("+any");
3542 else if( _offset < header_size ) st->print("+%d", _offset);
3543 else {
3544 BasicType basic_elem_type = elem()->basic_type();
3545 int array_base = arrayOopDesc::base_offset_in_bytes(basic_elem_type);
3546 int elem_size = type2aelembytes(basic_elem_type);
3547 st->print("[%d]", (_offset - array_base)/elem_size);
3548 }
3549 }
3550 st->print(" *");
3551 if (_instance_id == InstanceTop)
3552 st->print(",iid=top");
3553 else if (_instance_id != InstanceBot)
3554 st->print(",iid=%d",_instance_id);
3555 }
3556 #endif
3558 bool TypeAryPtr::empty(void) const {
3559 if (_ary->empty()) return true;
3560 return TypeOopPtr::empty();
3561 }
3563 //------------------------------add_offset-------------------------------------
3564 const TypePtr *TypeAryPtr::add_offset( intptr_t offset ) const {
3565 return make( _ptr, _const_oop, _ary, _klass, _klass_is_exact, xadd_offset(offset), _instance_id );
3566 }
3569 //=============================================================================
3570 const TypeNarrowOop *TypeNarrowOop::BOTTOM;
3571 const TypeNarrowOop *TypeNarrowOop::NULL_PTR;
3574 const TypeNarrowOop* TypeNarrowOop::make(const TypePtr* type) {
3575 return (const TypeNarrowOop*)(new TypeNarrowOop(type))->hashcons();
3576 }
3578 //------------------------------hash-------------------------------------------
3579 // Type-specific hashing function.
3580 int TypeNarrowOop::hash(void) const {
3581 return _ptrtype->hash() + 7;
3582 }
3585 bool TypeNarrowOop::eq( const Type *t ) const {
3586 const TypeNarrowOop* tc = t->isa_narrowoop();
3587 if (tc != NULL) {
3588 if (_ptrtype->base() != tc->_ptrtype->base()) {
3589 return false;
3590 }
3591 return tc->_ptrtype->eq(_ptrtype);
3592 }
3593 return false;
3594 }
3596 bool TypeNarrowOop::singleton(void) const { // TRUE if type is a singleton
3597 return _ptrtype->singleton();
3598 }
3600 bool TypeNarrowOop::empty(void) const {
3601 return _ptrtype->empty();
3602 }
3604 //------------------------------xmeet------------------------------------------
3605 // Compute the MEET of two types. It returns a new Type object.
3606 const Type *TypeNarrowOop::xmeet( const Type *t ) const {
3607 // Perform a fast test for common case; meeting the same types together.
3608 if( this == t ) return this; // Meeting same type-rep?
3611 // Current "this->_base" is OopPtr
3612 switch (t->base()) { // switch on original type
3614 case Int: // Mixing ints & oops happens when javac
3615 case Long: // reuses local variables
3616 case FloatTop:
3617 case FloatCon:
3618 case FloatBot:
3619 case DoubleTop:
3620 case DoubleCon:
3621 case DoubleBot:
3622 case AnyPtr:
3623 case RawPtr:
3624 case OopPtr:
3625 case InstPtr:
3626 case KlassPtr:
3627 case AryPtr:
3629 case Bottom: // Ye Olde Default
3630 return Type::BOTTOM;
3631 case Top:
3632 return this;
3634 case NarrowOop: {
3635 const Type* result = _ptrtype->xmeet(t->make_ptr());
3636 if (result->isa_ptr()) {
3637 return TypeNarrowOop::make(result->is_ptr());
3638 }
3639 return result;
3640 }
3642 default: // All else is a mistake
3643 typerr(t);
3645 } // End of switch
3647 return this;
3648 }
3650 const Type *TypeNarrowOop::xdual() const { // Compute dual right now.
3651 const TypePtr* odual = _ptrtype->dual()->is_ptr();
3652 return new TypeNarrowOop(odual);
3653 }
3655 const Type *TypeNarrowOop::filter( const Type *kills ) const {
3656 if (kills->isa_narrowoop()) {
3657 const Type* ft =_ptrtype->filter(kills->is_narrowoop()->_ptrtype);
3658 if (ft->empty())
3659 return Type::TOP; // Canonical empty value
3660 if (ft->isa_ptr()) {
3661 return make(ft->isa_ptr());
3662 }
3663 return ft;
3664 } else if (kills->isa_ptr()) {
3665 const Type* ft = _ptrtype->join(kills);
3666 if (ft->empty())
3667 return Type::TOP; // Canonical empty value
3668 return ft;
3669 } else {
3670 return Type::TOP;
3671 }
3672 }
3675 intptr_t TypeNarrowOop::get_con() const {
3676 return _ptrtype->get_con();
3677 }
3679 #ifndef PRODUCT
3680 void TypeNarrowOop::dump2( Dict & d, uint depth, outputStream *st ) const {
3681 st->print("narrowoop: ");
3682 _ptrtype->dump2(d, depth, st);
3683 }
3684 #endif
3687 //=============================================================================
3688 // Convenience common pre-built types.
3690 // Not-null object klass or below
3691 const TypeKlassPtr *TypeKlassPtr::OBJECT;
3692 const TypeKlassPtr *TypeKlassPtr::OBJECT_OR_NULL;
3694 //------------------------------TypeKlasPtr------------------------------------
3695 TypeKlassPtr::TypeKlassPtr( PTR ptr, ciKlass* klass, int offset )
3696 : TypeOopPtr(KlassPtr, ptr, klass, (ptr==Constant), (ptr==Constant ? klass : NULL), offset, 0) {
3697 }
3699 //------------------------------make-------------------------------------------
3700 // ptr to klass 'k', if Constant, or possibly to a sub-klass if not a Constant
3701 const TypeKlassPtr *TypeKlassPtr::make( PTR ptr, ciKlass* k, int offset ) {
3702 assert( k != NULL, "Expect a non-NULL klass");
3703 assert(k->is_instance_klass() || k->is_array_klass() ||
3704 k->is_method_klass(), "Incorrect type of klass oop");
3705 TypeKlassPtr *r =
3706 (TypeKlassPtr*)(new TypeKlassPtr(ptr, k, offset))->hashcons();
3708 return r;
3709 }
3711 //------------------------------eq---------------------------------------------
3712 // Structural equality check for Type representations
3713 bool TypeKlassPtr::eq( const Type *t ) const {
3714 const TypeKlassPtr *p = t->is_klassptr();
3715 return
3716 klass()->equals(p->klass()) &&
3717 TypeOopPtr::eq(p);
3718 }
3720 //------------------------------hash-------------------------------------------
3721 // Type-specific hashing function.
3722 int TypeKlassPtr::hash(void) const {
3723 return klass()->hash() + TypeOopPtr::hash();
3724 }
3727 //----------------------compute_klass------------------------------------------
3728 // Compute the defining klass for this class
3729 ciKlass* TypeAryPtr::compute_klass(DEBUG_ONLY(bool verify)) const {
3730 // Compute _klass based on element type.
3731 ciKlass* k_ary = NULL;
3732 const TypeInstPtr *tinst;
3733 const TypeAryPtr *tary;
3734 const Type* el = elem();
3735 if (el->isa_narrowoop()) {
3736 el = el->make_ptr();
3737 }
3739 // Get element klass
3740 if ((tinst = el->isa_instptr()) != NULL) {
3741 // Compute array klass from element klass
3742 k_ary = ciObjArrayKlass::make(tinst->klass());
3743 } else if ((tary = el->isa_aryptr()) != NULL) {
3744 // Compute array klass from element klass
3745 ciKlass* k_elem = tary->klass();
3746 // If element type is something like bottom[], k_elem will be null.
3747 if (k_elem != NULL)
3748 k_ary = ciObjArrayKlass::make(k_elem);
3749 } else if ((el->base() == Type::Top) ||
3750 (el->base() == Type::Bottom)) {
3751 // element type of Bottom occurs from meet of basic type
3752 // and object; Top occurs when doing join on Bottom.
3753 // Leave k_ary at NULL.
3754 } else {
3755 // Cannot compute array klass directly from basic type,
3756 // since subtypes of TypeInt all have basic type T_INT.
3757 #ifdef ASSERT
3758 if (verify && el->isa_int()) {
3759 // Check simple cases when verifying klass.
3760 BasicType bt = T_ILLEGAL;
3761 if (el == TypeInt::BYTE) {
3762 bt = T_BYTE;
3763 } else if (el == TypeInt::SHORT) {
3764 bt = T_SHORT;
3765 } else if (el == TypeInt::CHAR) {
3766 bt = T_CHAR;
3767 } else if (el == TypeInt::INT) {
3768 bt = T_INT;
3769 } else {
3770 return _klass; // just return specified klass
3771 }
3772 return ciTypeArrayKlass::make(bt);
3773 }
3774 #endif
3775 assert(!el->isa_int(),
3776 "integral arrays must be pre-equipped with a class");
3777 // Compute array klass directly from basic type
3778 k_ary = ciTypeArrayKlass::make(el->basic_type());
3779 }
3780 return k_ary;
3781 }
3783 //------------------------------klass------------------------------------------
3784 // Return the defining klass for this class
3785 ciKlass* TypeAryPtr::klass() const {
3786 if( _klass ) return _klass; // Return cached value, if possible
3788 // Oops, need to compute _klass and cache it
3789 ciKlass* k_ary = compute_klass();
3791 if( this != TypeAryPtr::OOPS && this->dual() != TypeAryPtr::OOPS ) {
3792 // The _klass field acts as a cache of the underlying
3793 // ciKlass for this array type. In order to set the field,
3794 // we need to cast away const-ness.
3795 //
3796 // IMPORTANT NOTE: we *never* set the _klass field for the
3797 // type TypeAryPtr::OOPS. This Type is shared between all
3798 // active compilations. However, the ciKlass which represents
3799 // this Type is *not* shared between compilations, so caching
3800 // this value would result in fetching a dangling pointer.
3801 //
3802 // Recomputing the underlying ciKlass for each request is
3803 // a bit less efficient than caching, but calls to
3804 // TypeAryPtr::OOPS->klass() are not common enough to matter.
3805 ((TypeAryPtr*)this)->_klass = k_ary;
3806 if (UseCompressedOops && k_ary != NULL && k_ary->is_obj_array_klass() &&
3807 _offset != 0 && _offset != arrayOopDesc::length_offset_in_bytes()) {
3808 ((TypeAryPtr*)this)->_is_ptr_to_narrowoop = true;
3809 }
3810 }
3811 return k_ary;
3812 }
3815 //------------------------------add_offset-------------------------------------
3816 // Access internals of klass object
3817 const TypePtr *TypeKlassPtr::add_offset( intptr_t offset ) const {
3818 return make( _ptr, klass(), xadd_offset(offset) );
3819 }
3821 //------------------------------cast_to_ptr_type-------------------------------
3822 const Type *TypeKlassPtr::cast_to_ptr_type(PTR ptr) const {
3823 assert(_base == KlassPtr, "subclass must override cast_to_ptr_type");
3824 if( ptr == _ptr ) return this;
3825 return make(ptr, _klass, _offset);
3826 }
3829 //-----------------------------cast_to_exactness-------------------------------
3830 const Type *TypeKlassPtr::cast_to_exactness(bool klass_is_exact) const {
3831 if( klass_is_exact == _klass_is_exact ) return this;
3832 if (!UseExactTypes) return this;
3833 return make(klass_is_exact ? Constant : NotNull, _klass, _offset);
3834 }
3837 //-----------------------------as_instance_type--------------------------------
3838 // Corresponding type for an instance of the given class.
3839 // It will be NotNull, and exact if and only if the klass type is exact.
3840 const TypeOopPtr* TypeKlassPtr::as_instance_type() const {
3841 ciKlass* k = klass();
3842 bool xk = klass_is_exact();
3843 //return TypeInstPtr::make(TypePtr::NotNull, k, xk, NULL, 0);
3844 const TypeOopPtr* toop = TypeOopPtr::make_from_klass_raw(k);
3845 toop = toop->cast_to_ptr_type(TypePtr::NotNull)->is_oopptr();
3846 return toop->cast_to_exactness(xk)->is_oopptr();
3847 }
3850 //------------------------------xmeet------------------------------------------
3851 // Compute the MEET of two types, return a new Type object.
3852 const Type *TypeKlassPtr::xmeet( const Type *t ) const {
3853 // Perform a fast test for common case; meeting the same types together.
3854 if( this == t ) return this; // Meeting same type-rep?
3856 // Current "this->_base" is Pointer
3857 switch (t->base()) { // switch on original type
3859 case Int: // Mixing ints & oops happens when javac
3860 case Long: // reuses local variables
3861 case FloatTop:
3862 case FloatCon:
3863 case FloatBot:
3864 case DoubleTop:
3865 case DoubleCon:
3866 case DoubleBot:
3867 case NarrowOop:
3868 case Bottom: // Ye Olde Default
3869 return Type::BOTTOM;
3870 case Top:
3871 return this;
3873 default: // All else is a mistake
3874 typerr(t);
3876 case RawPtr: return TypePtr::BOTTOM;
3878 case OopPtr: { // Meeting to OopPtrs
3879 // Found a OopPtr type vs self-KlassPtr type
3880 const TypePtr *tp = t->is_oopptr();
3881 int offset = meet_offset(tp->offset());
3882 PTR ptr = meet_ptr(tp->ptr());
3883 switch (tp->ptr()) {
3884 case TopPTR:
3885 case AnyNull:
3886 return make(ptr, klass(), offset);
3887 case BotPTR:
3888 case NotNull:
3889 return TypePtr::make(AnyPtr, ptr, offset);
3890 default: typerr(t);
3891 }
3892 }
3894 case AnyPtr: { // Meeting to AnyPtrs
3895 // Found an AnyPtr type vs self-KlassPtr type
3896 const TypePtr *tp = t->is_ptr();
3897 int offset = meet_offset(tp->offset());
3898 PTR ptr = meet_ptr(tp->ptr());
3899 switch (tp->ptr()) {
3900 case TopPTR:
3901 return this;
3902 case Null:
3903 if( ptr == Null ) return TypePtr::make( AnyPtr, ptr, offset );
3904 case AnyNull:
3905 return make( ptr, klass(), offset );
3906 case BotPTR:
3907 case NotNull:
3908 return TypePtr::make(AnyPtr, ptr, offset);
3909 default: typerr(t);
3910 }
3911 }
3913 case AryPtr: // Meet with AryPtr
3914 case InstPtr: // Meet with InstPtr
3915 return TypeInstPtr::BOTTOM;
3917 //
3918 // A-top }
3919 // / | \ } Tops
3920 // B-top A-any C-top }
3921 // | / | \ | } Any-nulls
3922 // B-any | C-any }
3923 // | | |
3924 // B-con A-con C-con } constants; not comparable across classes
3925 // | | |
3926 // B-not | C-not }
3927 // | \ | / | } not-nulls
3928 // B-bot A-not C-bot }
3929 // \ | / } Bottoms
3930 // A-bot }
3931 //
3933 case KlassPtr: { // Meet two KlassPtr types
3934 const TypeKlassPtr *tkls = t->is_klassptr();
3935 int off = meet_offset(tkls->offset());
3936 PTR ptr = meet_ptr(tkls->ptr());
3938 // Check for easy case; klasses are equal (and perhaps not loaded!)
3939 // If we have constants, then we created oops so classes are loaded
3940 // and we can handle the constants further down. This case handles
3941 // not-loaded classes
3942 if( ptr != Constant && tkls->klass()->equals(klass()) ) {
3943 return make( ptr, klass(), off );
3944 }
3946 // Classes require inspection in the Java klass hierarchy. Must be loaded.
3947 ciKlass* tkls_klass = tkls->klass();
3948 ciKlass* this_klass = this->klass();
3949 assert( tkls_klass->is_loaded(), "This class should have been loaded.");
3950 assert( this_klass->is_loaded(), "This class should have been loaded.");
3952 // If 'this' type is above the centerline and is a superclass of the
3953 // other, we can treat 'this' as having the same type as the other.
3954 if ((above_centerline(this->ptr())) &&
3955 tkls_klass->is_subtype_of(this_klass)) {
3956 this_klass = tkls_klass;
3957 }
3958 // If 'tinst' type is above the centerline and is a superclass of the
3959 // other, we can treat 'tinst' as having the same type as the other.
3960 if ((above_centerline(tkls->ptr())) &&
3961 this_klass->is_subtype_of(tkls_klass)) {
3962 tkls_klass = this_klass;
3963 }
3965 // Check for classes now being equal
3966 if (tkls_klass->equals(this_klass)) {
3967 // If the klasses are equal, the constants may still differ. Fall to
3968 // NotNull if they do (neither constant is NULL; that is a special case
3969 // handled elsewhere).
3970 ciObject* o = NULL; // Assume not constant when done
3971 ciObject* this_oop = const_oop();
3972 ciObject* tkls_oop = tkls->const_oop();
3973 if( ptr == Constant ) {
3974 if (this_oop != NULL && tkls_oop != NULL &&
3975 this_oop->equals(tkls_oop) )
3976 o = this_oop;
3977 else if (above_centerline(this->ptr()))
3978 o = tkls_oop;
3979 else if (above_centerline(tkls->ptr()))
3980 o = this_oop;
3981 else
3982 ptr = NotNull;
3983 }
3984 return make( ptr, this_klass, off );
3985 } // Else classes are not equal
3987 // Since klasses are different, we require the LCA in the Java
3988 // class hierarchy - which means we have to fall to at least NotNull.
3989 if( ptr == TopPTR || ptr == AnyNull || ptr == Constant )
3990 ptr = NotNull;
3991 // Now we find the LCA of Java classes
3992 ciKlass* k = this_klass->least_common_ancestor(tkls_klass);
3993 return make( ptr, k, off );
3994 } // End of case KlassPtr
3996 } // End of switch
3997 return this; // Return the double constant
3998 }
4000 //------------------------------xdual------------------------------------------
4001 // Dual: compute field-by-field dual
4002 const Type *TypeKlassPtr::xdual() const {
4003 return new TypeKlassPtr( dual_ptr(), klass(), dual_offset() );
4004 }
4006 //------------------------------dump2------------------------------------------
4007 // Dump Klass Type
4008 #ifndef PRODUCT
4009 void TypeKlassPtr::dump2( Dict & d, uint depth, outputStream *st ) const {
4010 switch( _ptr ) {
4011 case Constant:
4012 st->print("precise ");
4013 case NotNull:
4014 {
4015 const char *name = klass()->name()->as_utf8();
4016 if( name ) {
4017 st->print("klass %s: " INTPTR_FORMAT, name, klass());
4018 } else {
4019 ShouldNotReachHere();
4020 }
4021 }
4022 case BotPTR:
4023 if( !WizardMode && !Verbose && !_klass_is_exact ) break;
4024 case TopPTR:
4025 case AnyNull:
4026 st->print(":%s", ptr_msg[_ptr]);
4027 if( _klass_is_exact ) st->print(":exact");
4028 break;
4029 }
4031 if( _offset ) { // Dump offset, if any
4032 if( _offset == OffsetBot ) { st->print("+any"); }
4033 else if( _offset == OffsetTop ) { st->print("+unknown"); }
4034 else { st->print("+%d", _offset); }
4035 }
4037 st->print(" *");
4038 }
4039 #endif
4043 //=============================================================================
4044 // Convenience common pre-built types.
4046 //------------------------------make-------------------------------------------
4047 const TypeFunc *TypeFunc::make( const TypeTuple *domain, const TypeTuple *range ) {
4048 return (TypeFunc*)(new TypeFunc(domain,range))->hashcons();
4049 }
4051 //------------------------------make-------------------------------------------
4052 const TypeFunc *TypeFunc::make(ciMethod* method) {
4053 Compile* C = Compile::current();
4054 const TypeFunc* tf = C->last_tf(method); // check cache
4055 if (tf != NULL) return tf; // The hit rate here is almost 50%.
4056 const TypeTuple *domain;
4057 if (method->is_static()) {
4058 domain = TypeTuple::make_domain(NULL, method->signature());
4059 } else {
4060 domain = TypeTuple::make_domain(method->holder(), method->signature());
4061 }
4062 const TypeTuple *range = TypeTuple::make_range(method->signature());
4063 tf = TypeFunc::make(domain, range);
4064 C->set_last_tf(method, tf); // fill cache
4065 return tf;
4066 }
4068 //------------------------------meet-------------------------------------------
4069 // Compute the MEET of two types. It returns a new Type object.
4070 const Type *TypeFunc::xmeet( const Type *t ) const {
4071 // Perform a fast test for common case; meeting the same types together.
4072 if( this == t ) return this; // Meeting same type-rep?
4074 // Current "this->_base" is Func
4075 switch (t->base()) { // switch on original type
4077 case Bottom: // Ye Olde Default
4078 return t;
4080 default: // All else is a mistake
4081 typerr(t);
4083 case Top:
4084 break;
4085 }
4086 return this; // Return the double constant
4087 }
4089 //------------------------------xdual------------------------------------------
4090 // Dual: compute field-by-field dual
4091 const Type *TypeFunc::xdual() const {
4092 return this;
4093 }
4095 //------------------------------eq---------------------------------------------
4096 // Structural equality check for Type representations
4097 bool TypeFunc::eq( const Type *t ) const {
4098 const TypeFunc *a = (const TypeFunc*)t;
4099 return _domain == a->_domain &&
4100 _range == a->_range;
4101 }
4103 //------------------------------hash-------------------------------------------
4104 // Type-specific hashing function.
4105 int TypeFunc::hash(void) const {
4106 return (intptr_t)_domain + (intptr_t)_range;
4107 }
4109 //------------------------------dump2------------------------------------------
4110 // Dump Function Type
4111 #ifndef PRODUCT
4112 void TypeFunc::dump2( Dict &d, uint depth, outputStream *st ) const {
4113 if( _range->_cnt <= Parms )
4114 st->print("void");
4115 else {
4116 uint i;
4117 for (i = Parms; i < _range->_cnt-1; i++) {
4118 _range->field_at(i)->dump2(d,depth,st);
4119 st->print("/");
4120 }
4121 _range->field_at(i)->dump2(d,depth,st);
4122 }
4123 st->print(" ");
4124 st->print("( ");
4125 if( !depth || d[this] ) { // Check for recursive dump
4126 st->print("...)");
4127 return;
4128 }
4129 d.Insert((void*)this,(void*)this); // Stop recursion
4130 if (Parms < _domain->_cnt)
4131 _domain->field_at(Parms)->dump2(d,depth-1,st);
4132 for (uint i = Parms+1; i < _domain->_cnt; i++) {
4133 st->print(", ");
4134 _domain->field_at(i)->dump2(d,depth-1,st);
4135 }
4136 st->print(" )");
4137 }
4139 //------------------------------print_flattened--------------------------------
4140 // Print a 'flattened' signature
4141 static const char * const flat_type_msg[Type::lastype] = {
4142 "bad","control","top","int","long","_", "narrowoop",
4143 "tuple:", "array:",
4144 "ptr", "rawptr", "ptr", "ptr", "ptr", "ptr",
4145 "func", "abIO", "return_address", "mem",
4146 "float_top", "ftcon:", "flt",
4147 "double_top", "dblcon:", "dbl",
4148 "bottom"
4149 };
4151 void TypeFunc::print_flattened() const {
4152 if( _range->_cnt <= Parms )
4153 tty->print("void");
4154 else {
4155 uint i;
4156 for (i = Parms; i < _range->_cnt-1; i++)
4157 tty->print("%s/",flat_type_msg[_range->field_at(i)->base()]);
4158 tty->print("%s",flat_type_msg[_range->field_at(i)->base()]);
4159 }
4160 tty->print(" ( ");
4161 if (Parms < _domain->_cnt)
4162 tty->print("%s",flat_type_msg[_domain->field_at(Parms)->base()]);
4163 for (uint i = Parms+1; i < _domain->_cnt; i++)
4164 tty->print(", %s",flat_type_msg[_domain->field_at(i)->base()]);
4165 tty->print(" )");
4166 }
4167 #endif
4169 //------------------------------singleton--------------------------------------
4170 // TRUE if Type is a singleton type, FALSE otherwise. Singletons are simple
4171 // constants (Ldi nodes). Singletons are integer, float or double constants
4172 // or a single symbol.
4173 bool TypeFunc::singleton(void) const {
4174 return false; // Never a singleton
4175 }
4177 bool TypeFunc::empty(void) const {
4178 return false; // Never empty
4179 }
4182 BasicType TypeFunc::return_type() const{
4183 if (range()->cnt() == TypeFunc::Parms) {
4184 return T_VOID;
4185 }
4186 return range()->field_at(TypeFunc::Parms)->basic_type();
4187 }