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