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