1 /* 2 * Copyright (c) 1997, 2015, 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 */ 24 25 #include "precompiled.hpp" 26 #include "ci/ciField.hpp" 27 #include "ci/ciMethodData.hpp" 28 #include "ci/ciTypeFlow.hpp" 29 #include "ci/ciValueKlass.hpp" 30 #include "classfile/symbolTable.hpp" 31 #include "classfile/systemDictionary.hpp" 32 #include "compiler/compileLog.hpp" 33 #include "gc/shared/gcLocker.hpp" 34 #include "libadt/dict.hpp" 35 #include "memory/oopFactory.hpp" 36 #include "memory/resourceArea.hpp" 37 #include "oops/instanceKlass.hpp" 38 #include "oops/instanceMirrorKlass.hpp" 39 #include "oops/objArrayKlass.hpp" 40 #include "oops/typeArrayKlass.hpp" 41 #include "opto/matcher.hpp" 42 #include "opto/node.hpp" 43 #include "opto/opcodes.hpp" 44 #include "opto/type.hpp" 45 46 // Portions of code courtesy of Clifford Click 47 48 // Optimization - Graph Style 49 50 // Dictionary of types shared among compilations. 51 Dict* Type::_shared_type_dict = NULL; 52 const Type::Offset Type::Offset::top(Type::OffsetTop); 53 const Type::Offset Type::Offset::bottom(Type::OffsetBot); 54 55 const Type::Offset Type::Offset::meet(const Type::Offset other) const { 56 // Either is 'TOP' offset? Return the other offset! 57 int offset = other._offset; 58 if (_offset == OffsetTop) return Offset(offset); 59 if (offset == OffsetTop) return Offset(_offset); 60 // If either is different, return 'BOTTOM' offset 61 if (_offset != offset) return bottom; 62 return Offset(_offset); 63 } 64 65 const Type::Offset Type::Offset::dual() const { 66 if (_offset == OffsetTop) return bottom;// Map 'TOP' into 'BOTTOM' 67 if (_offset == OffsetBot) return top;// Map 'BOTTOM' into 'TOP' 68 return Offset(_offset); // Map everything else into self 69 } 70 71 const Type::Offset Type::Offset::add(intptr_t offset) const { 72 // Adding to 'TOP' offset? Return 'TOP'! 73 if (_offset == OffsetTop || offset == OffsetTop) return top; 74 // Adding to 'BOTTOM' offset? Return 'BOTTOM'! 75 if (_offset == OffsetBot || offset == OffsetBot) return bottom; 76 // Addition overflows or "accidentally" equals to OffsetTop? Return 'BOTTOM'! 77 offset += (intptr_t)_offset; 78 if (offset != (int)offset || offset == OffsetTop) return bottom; 79 80 // assert( _offset >= 0 && _offset+offset >= 0, "" ); 81 // It is possible to construct a negative offset during PhaseCCP 82 83 return Offset((int)offset); // Sum valid offsets 84 } 85 86 void Type::Offset::dump2(outputStream *st) const { 87 if (_offset == 0) { 88 return; 89 } else if (_offset == OffsetTop) { 90 st->print("+top"); 91 } 92 else if (_offset == OffsetBot) { 93 st->print("+bot"); 94 } else if (_offset) { 95 st->print("+%d", _offset); 96 } 97 } 98 99 // Array which maps compiler types to Basic Types 100 Type::TypeInfo Type::_type_info[Type::lastype] = { 101 { Bad, T_ILLEGAL, "bad", false, Node::NotAMachineReg, relocInfo::none }, // Bad 102 { Control, T_ILLEGAL, "control", false, 0, relocInfo::none }, // Control 103 { Bottom, T_VOID, "top", false, 0, relocInfo::none }, // Top 104 { Bad, T_INT, "int:", false, Op_RegI, relocInfo::none }, // Int 105 { Bad, T_LONG, "long:", false, Op_RegL, relocInfo::none }, // Long 106 { Half, T_VOID, "half", false, 0, relocInfo::none }, // Half 107 { Bad, T_NARROWOOP, "narrowoop:", false, Op_RegN, relocInfo::none }, // NarrowOop 108 { Bad, T_NARROWKLASS,"narrowklass:", false, Op_RegN, relocInfo::none }, // NarrowKlass 109 { Bad, T_ILLEGAL, "tuple:", false, Node::NotAMachineReg, relocInfo::none }, // Tuple 110 { Bad, T_ARRAY, "array:", false, Node::NotAMachineReg, relocInfo::none }, // Array 111 112 #ifdef SPARC 113 { Bad, T_ILLEGAL, "vectors:", false, 0, relocInfo::none }, // VectorS 114 { Bad, T_ILLEGAL, "vectord:", false, Op_RegD, relocInfo::none }, // VectorD 115 { Bad, T_ILLEGAL, "vectorx:", false, 0, relocInfo::none }, // VectorX 116 { Bad, T_ILLEGAL, "vectory:", false, 0, relocInfo::none }, // VectorY 117 { Bad, T_ILLEGAL, "vectorz:", false, 0, relocInfo::none }, // VectorZ 118 #elif defined(PPC64) 119 { Bad, T_ILLEGAL, "vectors:", false, 0, relocInfo::none }, // VectorS 120 { Bad, T_ILLEGAL, "vectord:", false, Op_RegL, relocInfo::none }, // VectorD 121 { Bad, T_ILLEGAL, "vectorx:", false, 0, relocInfo::none }, // VectorX 122 { Bad, T_ILLEGAL, "vectory:", false, 0, relocInfo::none }, // VectorY 123 { Bad, T_ILLEGAL, "vectorz:", false, 0, relocInfo::none }, // VectorZ 124 #else // all other 125 { Bad, T_ILLEGAL, "vectors:", false, Op_VecS, relocInfo::none }, // VectorS 126 { Bad, T_ILLEGAL, "vectord:", false, Op_VecD, relocInfo::none }, // VectorD 127 { Bad, T_ILLEGAL, "vectorx:", false, Op_VecX, relocInfo::none }, // VectorX 128 { Bad, T_ILLEGAL, "vectory:", false, Op_VecY, relocInfo::none }, // VectorY 129 { Bad, T_ILLEGAL, "vectorz:", false, Op_VecZ, relocInfo::none }, // VectorZ 130 #endif 131 { Bad, T_VALUETYPE, "value:", false, Node::NotAMachineReg, relocInfo::none }, // ValueType 132 { Bad, T_ADDRESS, "anyptr:", false, Op_RegP, relocInfo::none }, // AnyPtr 133 { Bad, T_ADDRESS, "rawptr:", false, Op_RegP, relocInfo::none }, // RawPtr 134 { Bad, T_OBJECT, "oop:", true, Op_RegP, relocInfo::oop_type }, // OopPtr 135 { Bad, T_OBJECT, "inst:", true, Op_RegP, relocInfo::oop_type }, // InstPtr 136 { Bad, T_OBJECT, "valueptr:", true, Op_RegP, relocInfo::oop_type }, // ValueTypePtr 137 { Bad, T_OBJECT, "ary:", true, Op_RegP, relocInfo::oop_type }, // AryPtr 138 { Bad, T_METADATA, "metadata:", false, Op_RegP, relocInfo::metadata_type }, // MetadataPtr 139 { Bad, T_METADATA, "klass:", false, Op_RegP, relocInfo::metadata_type }, // KlassPtr 140 { Bad, T_OBJECT, "func", false, 0, relocInfo::none }, // Function 141 { Abio, T_ILLEGAL, "abIO", false, 0, relocInfo::none }, // Abio 142 { Return_Address, T_ADDRESS, "return_address",false, Op_RegP, relocInfo::none }, // Return_Address 143 { Memory, T_ILLEGAL, "memory", false, 0, relocInfo::none }, // Memory 144 { FloatBot, T_FLOAT, "float_top", false, Op_RegF, relocInfo::none }, // FloatTop 145 { FloatCon, T_FLOAT, "ftcon:", false, Op_RegF, relocInfo::none }, // FloatCon 146 { FloatTop, T_FLOAT, "float", false, Op_RegF, relocInfo::none }, // FloatBot 147 { DoubleBot, T_DOUBLE, "double_top", false, Op_RegD, relocInfo::none }, // DoubleTop 148 { DoubleCon, T_DOUBLE, "dblcon:", false, Op_RegD, relocInfo::none }, // DoubleCon 149 { DoubleTop, T_DOUBLE, "double", false, Op_RegD, relocInfo::none }, // DoubleBot 150 { Top, T_ILLEGAL, "bottom", false, 0, relocInfo::none } // Bottom 151 }; 152 153 // Map ideal registers (machine types) to ideal types 154 const Type *Type::mreg2type[_last_machine_leaf]; 155 156 // Map basic types to canonical Type* pointers. 157 const Type* Type:: _const_basic_type[T_CONFLICT+1]; 158 159 // Map basic types to constant-zero Types. 160 const Type* Type:: _zero_type[T_CONFLICT+1]; 161 162 // Map basic types to array-body alias types. 163 const TypeAryPtr* TypeAryPtr::_array_body_type[T_CONFLICT+1]; 164 165 //============================================================================= 166 // Convenience common pre-built types. 167 const Type *Type::ABIO; // State-of-machine only 168 const Type *Type::BOTTOM; // All values 169 const Type *Type::CONTROL; // Control only 170 const Type *Type::DOUBLE; // All doubles 171 const Type *Type::FLOAT; // All floats 172 const Type *Type::HALF; // Placeholder half of doublewide type 173 const Type *Type::MEMORY; // Abstract store only 174 const Type *Type::RETURN_ADDRESS; 175 const Type *Type::TOP; // No values in set 176 177 //------------------------------get_const_type--------------------------- 178 const Type* Type::get_const_type(ciType* type) { 179 if (type == NULL) { 180 return NULL; 181 } else if (type->is_primitive_type()) { 182 return get_const_basic_type(type->basic_type()); 183 } else { 184 return TypeOopPtr::make_from_klass(type->as_klass()); 185 } 186 } 187 188 //---------------------------array_element_basic_type--------------------------------- 189 // Mapping to the array element's basic type. 190 BasicType Type::array_element_basic_type() const { 191 BasicType bt = basic_type(); 192 if (bt == T_INT) { 193 if (this == TypeInt::INT) return T_INT; 194 if (this == TypeInt::CHAR) return T_CHAR; 195 if (this == TypeInt::BYTE) return T_BYTE; 196 if (this == TypeInt::BOOL) return T_BOOLEAN; 197 if (this == TypeInt::SHORT) return T_SHORT; 198 return T_VOID; 199 } 200 return bt; 201 } 202 203 // For two instance arrays of same dimension, return the base element types. 204 // Otherwise or if the arrays have different dimensions, return NULL. 205 void Type::get_arrays_base_elements(const Type *a1, const Type *a2, 206 const TypeInstPtr **e1, const TypeInstPtr **e2) { 207 208 if (e1) *e1 = NULL; 209 if (e2) *e2 = NULL; 210 const TypeAryPtr* a1tap = (a1 == NULL) ? NULL : a1->isa_aryptr(); 211 const TypeAryPtr* a2tap = (a2 == NULL) ? NULL : a2->isa_aryptr(); 212 213 if (a1tap != NULL && a2tap != NULL) { 214 // Handle multidimensional arrays 215 const TypePtr* a1tp = a1tap->elem()->make_ptr(); 216 const TypePtr* a2tp = a2tap->elem()->make_ptr(); 217 while (a1tp && a1tp->isa_aryptr() && a2tp && a2tp->isa_aryptr()) { 218 a1tap = a1tp->is_aryptr(); 219 a2tap = a2tp->is_aryptr(); 220 a1tp = a1tap->elem()->make_ptr(); 221 a2tp = a2tap->elem()->make_ptr(); 222 } 223 if (a1tp && a1tp->isa_instptr() && a2tp && a2tp->isa_instptr()) { 224 if (e1) *e1 = a1tp->is_instptr(); 225 if (e2) *e2 = a2tp->is_instptr(); 226 } 227 } 228 } 229 230 //---------------------------get_typeflow_type--------------------------------- 231 // Import a type produced by ciTypeFlow. 232 const Type* Type::get_typeflow_type(ciType* type) { 233 switch (type->basic_type()) { 234 235 case ciTypeFlow::StateVector::T_BOTTOM: 236 assert(type == ciTypeFlow::StateVector::bottom_type(), ""); 237 return Type::BOTTOM; 238 239 case ciTypeFlow::StateVector::T_TOP: 240 assert(type == ciTypeFlow::StateVector::top_type(), ""); 241 return Type::TOP; 242 243 case ciTypeFlow::StateVector::T_NULL: 244 assert(type == ciTypeFlow::StateVector::null_type(), ""); 245 return TypePtr::NULL_PTR; 246 247 case ciTypeFlow::StateVector::T_LONG2: 248 // The ciTypeFlow pass pushes a long, then the half. 249 // We do the same. 250 assert(type == ciTypeFlow::StateVector::long2_type(), ""); 251 return TypeInt::TOP; 252 253 case ciTypeFlow::StateVector::T_DOUBLE2: 254 // The ciTypeFlow pass pushes double, then the half. 255 // Our convention is the same. 256 assert(type == ciTypeFlow::StateVector::double2_type(), ""); 257 return Type::TOP; 258 259 case T_ADDRESS: 260 assert(type->is_return_address(), ""); 261 return TypeRawPtr::make((address)(intptr_t)type->as_return_address()->bci()); 262 263 case T_VALUETYPE: 264 return TypeValueType::make(type->as_value_klass()); 265 266 default: 267 // make sure we did not mix up the cases: 268 assert(type != ciTypeFlow::StateVector::bottom_type(), ""); 269 assert(type != ciTypeFlow::StateVector::top_type(), ""); 270 assert(type != ciTypeFlow::StateVector::null_type(), ""); 271 assert(type != ciTypeFlow::StateVector::long2_type(), ""); 272 assert(type != ciTypeFlow::StateVector::double2_type(), ""); 273 assert(!type->is_return_address(), ""); 274 275 return Type::get_const_type(type); 276 } 277 } 278 279 280 //-----------------------make_from_constant------------------------------------ 281 const Type* Type::make_from_constant(ciConstant constant, bool require_constant) { 282 switch (constant.basic_type()) { 283 case T_BOOLEAN: return TypeInt::make(constant.as_boolean()); 284 case T_CHAR: return TypeInt::make(constant.as_char()); 285 case T_BYTE: return TypeInt::make(constant.as_byte()); 286 case T_SHORT: return TypeInt::make(constant.as_short()); 287 case T_INT: return TypeInt::make(constant.as_int()); 288 case T_LONG: return TypeLong::make(constant.as_long()); 289 case T_FLOAT: return TypeF::make(constant.as_float()); 290 case T_DOUBLE: return TypeD::make(constant.as_double()); 291 case T_ARRAY: 292 case T_VALUETYPE: 293 case T_OBJECT: 294 { 295 // cases: 296 // can_be_constant = (oop not scavengable || ScavengeRootsInCode != 0) 297 // should_be_constant = (oop not scavengable || ScavengeRootsInCode >= 2) 298 // An oop is not scavengable if it is in the perm gen. 299 ciObject* oop_constant = constant.as_object(); 300 if (oop_constant->is_null_object()) { 301 return Type::get_zero_type(T_OBJECT); 302 } else if (require_constant || oop_constant->should_be_constant()) { 303 return TypeOopPtr::make_from_constant(oop_constant, require_constant); 304 } 305 } 306 case T_ILLEGAL: 307 // Invalid ciConstant returned due to OutOfMemoryError in the CI 308 assert(Compile::current()->env()->failing(), "otherwise should not see this"); 309 return NULL; 310 } 311 // Fall through to failure 312 return NULL; 313 } 314 315 316 const Type* Type::make_constant(ciField* field, Node* obj) { 317 if (!field->is_constant()) return NULL; 318 319 const Type* con_type = NULL; 320 if (field->is_static()) { 321 // final static field 322 con_type = Type::make_from_constant(field->constant_value(), /*require_const=*/true); 323 if (Compile::current()->eliminate_boxing() && field->is_autobox_cache() && con_type != NULL) { 324 con_type = con_type->is_aryptr()->cast_to_autobox_cache(true); 325 } 326 } else { 327 // final or stable non-static field 328 // Treat final non-static fields of trusted classes (classes in 329 // java.lang.invoke and sun.invoke packages and subpackages) as 330 // compile time constants. 331 if (obj->is_Con()) { 332 const TypeOopPtr* oop_ptr = obj->bottom_type()->isa_oopptr(); 333 ciObject* constant_oop = oop_ptr->const_oop(); 334 ciConstant constant = field->constant_value_of(constant_oop); 335 con_type = Type::make_from_constant(constant, /*require_const=*/true); 336 } 337 } 338 if (FoldStableValues && field->is_stable() && con_type != NULL) { 339 if (con_type->is_zero_type()) { 340 return NULL; // the field hasn't been initialized yet 341 } else if (con_type->isa_oopptr()) { 342 const Type* stable_type = Type::get_const_type(field->type()); 343 if (field->type()->is_array_klass()) { 344 int stable_dimension = field->type()->as_array_klass()->dimension(); 345 stable_type = stable_type->is_aryptr()->cast_to_stable(true, stable_dimension); 346 } 347 if (stable_type != NULL) { 348 con_type = con_type->join_speculative(stable_type); 349 } 350 } 351 } 352 return con_type; 353 } 354 355 //------------------------------make------------------------------------------- 356 // Create a simple Type, with default empty symbol sets. Then hashcons it 357 // and look for an existing copy in the type dictionary. 358 const Type *Type::make( enum TYPES t ) { 359 return (new Type(t))->hashcons(); 360 } 361 362 //------------------------------cmp-------------------------------------------- 363 int Type::cmp( const Type *const t1, const Type *const t2 ) { 364 if( t1->_base != t2->_base ) 365 return 1; // Missed badly 366 assert(t1 != t2 || t1->eq(t2), "eq must be reflexive"); 367 return !t1->eq(t2); // Return ZERO if equal 368 } 369 370 const Type* Type::maybe_remove_speculative(bool include_speculative) const { 371 if (!include_speculative) { 372 return remove_speculative(); 373 } 374 return this; 375 } 376 377 //------------------------------hash------------------------------------------- 378 int Type::uhash( const Type *const t ) { 379 return t->hash(); 380 } 381 382 #define SMALLINT ((juint)3) // a value too insignificant to consider widening 383 384 //--------------------------Initialize_shared---------------------------------- 385 void Type::Initialize_shared(Compile* current) { 386 // This method does not need to be locked because the first system 387 // compilations (stub compilations) occur serially. If they are 388 // changed to proceed in parallel, then this section will need 389 // locking. 390 391 Arena* save = current->type_arena(); 392 Arena* shared_type_arena = new (mtCompiler)Arena(mtCompiler); 393 394 current->set_type_arena(shared_type_arena); 395 _shared_type_dict = 396 new (shared_type_arena) Dict( (CmpKey)Type::cmp, (Hash)Type::uhash, 397 shared_type_arena, 128 ); 398 current->set_type_dict(_shared_type_dict); 399 400 // Make shared pre-built types. 401 CONTROL = make(Control); // Control only 402 TOP = make(Top); // No values in set 403 MEMORY = make(Memory); // Abstract store only 404 ABIO = make(Abio); // State-of-machine only 405 RETURN_ADDRESS=make(Return_Address); 406 FLOAT = make(FloatBot); // All floats 407 DOUBLE = make(DoubleBot); // All doubles 408 BOTTOM = make(Bottom); // Everything 409 HALF = make(Half); // Placeholder half of doublewide type 410 411 TypeF::ZERO = TypeF::make(0.0); // Float 0 (positive zero) 412 TypeF::ONE = TypeF::make(1.0); // Float 1 413 414 TypeD::ZERO = TypeD::make(0.0); // Double 0 (positive zero) 415 TypeD::ONE = TypeD::make(1.0); // Double 1 416 417 TypeInt::MINUS_1 = TypeInt::make(-1); // -1 418 TypeInt::ZERO = TypeInt::make( 0); // 0 419 TypeInt::ONE = TypeInt::make( 1); // 1 420 TypeInt::BOOL = TypeInt::make(0,1, WidenMin); // 0 or 1, FALSE or TRUE. 421 TypeInt::CC = TypeInt::make(-1, 1, WidenMin); // -1, 0 or 1, condition codes 422 TypeInt::CC_LT = TypeInt::make(-1,-1, WidenMin); // == TypeInt::MINUS_1 423 TypeInt::CC_GT = TypeInt::make( 1, 1, WidenMin); // == TypeInt::ONE 424 TypeInt::CC_EQ = TypeInt::make( 0, 0, WidenMin); // == TypeInt::ZERO 425 TypeInt::CC_LE = TypeInt::make(-1, 0, WidenMin); 426 TypeInt::CC_GE = TypeInt::make( 0, 1, WidenMin); // == TypeInt::BOOL 427 TypeInt::BYTE = TypeInt::make(-128,127, WidenMin); // Bytes 428 TypeInt::UBYTE = TypeInt::make(0, 255, WidenMin); // Unsigned Bytes 429 TypeInt::CHAR = TypeInt::make(0,65535, WidenMin); // Java chars 430 TypeInt::SHORT = TypeInt::make(-32768,32767, WidenMin); // Java shorts 431 TypeInt::POS = TypeInt::make(0,max_jint, WidenMin); // Non-neg values 432 TypeInt::POS1 = TypeInt::make(1,max_jint, WidenMin); // Positive values 433 TypeInt::INT = TypeInt::make(min_jint,max_jint, WidenMax); // 32-bit integers 434 TypeInt::SYMINT = TypeInt::make(-max_jint,max_jint,WidenMin); // symmetric range 435 TypeInt::TYPE_DOMAIN = TypeInt::INT; 436 // CmpL is overloaded both as the bytecode computation returning 437 // a trinary (-1,0,+1) integer result AND as an efficient long 438 // compare returning optimizer ideal-type flags. 439 assert( TypeInt::CC_LT == TypeInt::MINUS_1, "types must match for CmpL to work" ); 440 assert( TypeInt::CC_GT == TypeInt::ONE, "types must match for CmpL to work" ); 441 assert( TypeInt::CC_EQ == TypeInt::ZERO, "types must match for CmpL to work" ); 442 assert( TypeInt::CC_GE == TypeInt::BOOL, "types must match for CmpL to work" ); 443 assert( (juint)(TypeInt::CC->_hi - TypeInt::CC->_lo) <= SMALLINT, "CC is truly small"); 444 445 TypeLong::MINUS_1 = TypeLong::make(-1); // -1 446 TypeLong::ZERO = TypeLong::make( 0); // 0 447 TypeLong::ONE = TypeLong::make( 1); // 1 448 TypeLong::POS = TypeLong::make(0,max_jlong, WidenMin); // Non-neg values 449 TypeLong::LONG = TypeLong::make(min_jlong,max_jlong,WidenMax); // 64-bit integers 450 TypeLong::INT = TypeLong::make((jlong)min_jint,(jlong)max_jint,WidenMin); 451 TypeLong::UINT = TypeLong::make(0,(jlong)max_juint,WidenMin); 452 TypeLong::TYPE_DOMAIN = TypeLong::LONG; 453 454 const Type **fboth =(const Type**)shared_type_arena->Amalloc_4(2*sizeof(Type*)); 455 fboth[0] = Type::CONTROL; 456 fboth[1] = Type::CONTROL; 457 TypeTuple::IFBOTH = TypeTuple::make( 2, fboth ); 458 459 const Type **ffalse =(const Type**)shared_type_arena->Amalloc_4(2*sizeof(Type*)); 460 ffalse[0] = Type::CONTROL; 461 ffalse[1] = Type::TOP; 462 TypeTuple::IFFALSE = TypeTuple::make( 2, ffalse ); 463 464 const Type **fneither =(const Type**)shared_type_arena->Amalloc_4(2*sizeof(Type*)); 465 fneither[0] = Type::TOP; 466 fneither[1] = Type::TOP; 467 TypeTuple::IFNEITHER = TypeTuple::make( 2, fneither ); 468 469 const Type **ftrue =(const Type**)shared_type_arena->Amalloc_4(2*sizeof(Type*)); 470 ftrue[0] = Type::TOP; 471 ftrue[1] = Type::CONTROL; 472 TypeTuple::IFTRUE = TypeTuple::make( 2, ftrue ); 473 474 const Type **floop =(const Type**)shared_type_arena->Amalloc_4(2*sizeof(Type*)); 475 floop[0] = Type::CONTROL; 476 floop[1] = TypeInt::INT; 477 TypeTuple::LOOPBODY = TypeTuple::make( 2, floop ); 478 479 TypePtr::NULL_PTR= TypePtr::make(AnyPtr, TypePtr::Null, Offset(0)); 480 TypePtr::NOTNULL = TypePtr::make(AnyPtr, TypePtr::NotNull, Offset::bottom); 481 TypePtr::BOTTOM = TypePtr::make(AnyPtr, TypePtr::BotPTR, Offset::bottom); 482 483 TypeRawPtr::BOTTOM = TypeRawPtr::make( TypePtr::BotPTR ); 484 TypeRawPtr::NOTNULL= TypeRawPtr::make( TypePtr::NotNull ); 485 486 const Type **fmembar = TypeTuple::fields(0); 487 TypeTuple::MEMBAR = TypeTuple::make(TypeFunc::Parms+0, fmembar); 488 489 const Type **fsc = (const Type**)shared_type_arena->Amalloc_4(2*sizeof(Type*)); 490 fsc[0] = TypeInt::CC; 491 fsc[1] = Type::MEMORY; 492 TypeTuple::STORECONDITIONAL = TypeTuple::make(2, fsc); 493 494 TypeInstPtr::NOTNULL = TypeInstPtr::make(TypePtr::NotNull, current->env()->Object_klass()); 495 TypeInstPtr::BOTTOM = TypeInstPtr::make(TypePtr::BotPTR, current->env()->Object_klass()); 496 TypeInstPtr::MIRROR = TypeInstPtr::make(TypePtr::NotNull, current->env()->Class_klass()); 497 TypeInstPtr::MARK = TypeInstPtr::make(TypePtr::BotPTR, current->env()->Object_klass(), 498 false, 0, Offset(oopDesc::mark_offset_in_bytes())); 499 TypeInstPtr::KLASS = TypeInstPtr::make(TypePtr::BotPTR, current->env()->Object_klass(), 500 false, 0, Offset(oopDesc::klass_offset_in_bytes())); 501 TypeOopPtr::BOTTOM = TypeOopPtr::make(TypePtr::BotPTR, Offset::bottom, TypeOopPtr::InstanceBot); 502 503 TypeMetadataPtr::BOTTOM = TypeMetadataPtr::make(TypePtr::BotPTR, NULL, Offset::bottom); 504 505 TypeNarrowOop::NULL_PTR = TypeNarrowOop::make( TypePtr::NULL_PTR ); 506 TypeNarrowOop::BOTTOM = TypeNarrowOop::make( TypeInstPtr::BOTTOM ); 507 508 TypeNarrowKlass::NULL_PTR = TypeNarrowKlass::make( TypePtr::NULL_PTR ); 509 510 mreg2type[Op_Node] = Type::BOTTOM; 511 mreg2type[Op_Set ] = 0; 512 mreg2type[Op_RegN] = TypeNarrowOop::BOTTOM; 513 mreg2type[Op_RegI] = TypeInt::INT; 514 mreg2type[Op_RegP] = TypePtr::BOTTOM; 515 mreg2type[Op_RegF] = Type::FLOAT; 516 mreg2type[Op_RegD] = Type::DOUBLE; 517 mreg2type[Op_RegL] = TypeLong::LONG; 518 mreg2type[Op_RegFlags] = TypeInt::CC; 519 520 TypeAryPtr::RANGE = TypeAryPtr::make(TypePtr::BotPTR, TypeAry::make(Type::BOTTOM,TypeInt::POS), NULL /* current->env()->Object_klass() */, false, Offset(arrayOopDesc::length_offset_in_bytes())); 521 522 TypeAryPtr::NARROWOOPS = TypeAryPtr::make(TypePtr::BotPTR, TypeAry::make(TypeNarrowOop::BOTTOM, TypeInt::POS), NULL /*ciArrayKlass::make(o)*/, false, Offset::bottom); 523 524 #ifdef _LP64 525 if (UseCompressedOops) { 526 assert(TypeAryPtr::NARROWOOPS->is_ptr_to_narrowoop(), "array of narrow oops must be ptr to narrow oop"); 527 TypeAryPtr::OOPS = TypeAryPtr::NARROWOOPS; 528 } else 529 #endif 530 { 531 // There is no shared klass for Object[]. See note in TypeAryPtr::klass(). 532 TypeAryPtr::OOPS = TypeAryPtr::make(TypePtr::BotPTR, TypeAry::make(TypeInstPtr::BOTTOM,TypeInt::POS), NULL /*ciArrayKlass::make(o)*/, false, Offset::bottom); 533 } 534 TypeAryPtr::BYTES = TypeAryPtr::make(TypePtr::BotPTR, TypeAry::make(TypeInt::BYTE ,TypeInt::POS), ciTypeArrayKlass::make(T_BYTE), true, Offset::bottom); 535 TypeAryPtr::SHORTS = TypeAryPtr::make(TypePtr::BotPTR, TypeAry::make(TypeInt::SHORT ,TypeInt::POS), ciTypeArrayKlass::make(T_SHORT), true, Offset::bottom); 536 TypeAryPtr::CHARS = TypeAryPtr::make(TypePtr::BotPTR, TypeAry::make(TypeInt::CHAR ,TypeInt::POS), ciTypeArrayKlass::make(T_CHAR), true, Offset::bottom); 537 TypeAryPtr::INTS = TypeAryPtr::make(TypePtr::BotPTR, TypeAry::make(TypeInt::INT ,TypeInt::POS), ciTypeArrayKlass::make(T_INT), true, Offset::bottom); 538 TypeAryPtr::LONGS = TypeAryPtr::make(TypePtr::BotPTR, TypeAry::make(TypeLong::LONG ,TypeInt::POS), ciTypeArrayKlass::make(T_LONG), true, Offset::bottom); 539 TypeAryPtr::FLOATS = TypeAryPtr::make(TypePtr::BotPTR, TypeAry::make(Type::FLOAT ,TypeInt::POS), ciTypeArrayKlass::make(T_FLOAT), true, Offset::bottom); 540 TypeAryPtr::DOUBLES = TypeAryPtr::make(TypePtr::BotPTR, TypeAry::make(Type::DOUBLE ,TypeInt::POS), ciTypeArrayKlass::make(T_DOUBLE), true, Offset::bottom); 541 542 // Nobody should ask _array_body_type[T_NARROWOOP]. Use NULL as assert. 543 TypeAryPtr::_array_body_type[T_NARROWOOP] = NULL; 544 TypeAryPtr::_array_body_type[T_OBJECT] = TypeAryPtr::OOPS; 545 TypeAryPtr::_array_body_type[T_ARRAY] = TypeAryPtr::OOPS; // arrays are stored in oop arrays 546 TypeAryPtr::_array_body_type[T_VALUETYPE] = TypeAryPtr::OOPS; 547 TypeAryPtr::_array_body_type[T_BYTE] = TypeAryPtr::BYTES; 548 TypeAryPtr::_array_body_type[T_BOOLEAN] = TypeAryPtr::BYTES; // boolean[] is a byte array 549 TypeAryPtr::_array_body_type[T_SHORT] = TypeAryPtr::SHORTS; 550 TypeAryPtr::_array_body_type[T_CHAR] = TypeAryPtr::CHARS; 551 TypeAryPtr::_array_body_type[T_INT] = TypeAryPtr::INTS; 552 TypeAryPtr::_array_body_type[T_LONG] = TypeAryPtr::LONGS; 553 TypeAryPtr::_array_body_type[T_FLOAT] = TypeAryPtr::FLOATS; 554 TypeAryPtr::_array_body_type[T_DOUBLE] = TypeAryPtr::DOUBLES; 555 556 TypeKlassPtr::OBJECT = TypeKlassPtr::make(TypePtr::NotNull, current->env()->Object_klass(), Offset(0) ); 557 TypeKlassPtr::OBJECT_OR_NULL = TypeKlassPtr::make(TypePtr::BotPTR, current->env()->Object_klass(), Offset(0) ); 558 559 const Type **fi2c = TypeTuple::fields(2); 560 fi2c[TypeFunc::Parms+0] = TypeInstPtr::BOTTOM; // Method* 561 fi2c[TypeFunc::Parms+1] = TypeRawPtr::BOTTOM; // argument pointer 562 TypeTuple::START_I2C = TypeTuple::make(TypeFunc::Parms+2, fi2c); 563 564 const Type **intpair = TypeTuple::fields(2); 565 intpair[0] = TypeInt::INT; 566 intpair[1] = TypeInt::INT; 567 TypeTuple::INT_PAIR = TypeTuple::make(2, intpair); 568 569 const Type **longpair = TypeTuple::fields(2); 570 longpair[0] = TypeLong::LONG; 571 longpair[1] = TypeLong::LONG; 572 TypeTuple::LONG_PAIR = TypeTuple::make(2, longpair); 573 574 const Type **intccpair = TypeTuple::fields(2); 575 intccpair[0] = TypeInt::INT; 576 intccpair[1] = TypeInt::CC; 577 TypeTuple::INT_CC_PAIR = TypeTuple::make(2, intccpair); 578 579 const Type **longccpair = TypeTuple::fields(2); 580 longccpair[0] = TypeLong::LONG; 581 longccpair[1] = TypeInt::CC; 582 TypeTuple::LONG_CC_PAIR = TypeTuple::make(2, longccpair); 583 584 _const_basic_type[T_NARROWOOP] = TypeNarrowOop::BOTTOM; 585 _const_basic_type[T_NARROWKLASS] = Type::BOTTOM; 586 _const_basic_type[T_BOOLEAN] = TypeInt::BOOL; 587 _const_basic_type[T_CHAR] = TypeInt::CHAR; 588 _const_basic_type[T_BYTE] = TypeInt::BYTE; 589 _const_basic_type[T_SHORT] = TypeInt::SHORT; 590 _const_basic_type[T_INT] = TypeInt::INT; 591 _const_basic_type[T_LONG] = TypeLong::LONG; 592 _const_basic_type[T_FLOAT] = Type::FLOAT; 593 _const_basic_type[T_DOUBLE] = Type::DOUBLE; 594 _const_basic_type[T_OBJECT] = TypeInstPtr::BOTTOM; 595 _const_basic_type[T_ARRAY] = TypeInstPtr::BOTTOM; // there is no separate bottom for arrays 596 _const_basic_type[T_VALUETYPE] = TypeInstPtr::BOTTOM; 597 _const_basic_type[T_VOID] = TypePtr::NULL_PTR; // reflection represents void this way 598 _const_basic_type[T_ADDRESS] = TypeRawPtr::BOTTOM; // both interpreter return addresses & random raw ptrs 599 _const_basic_type[T_CONFLICT] = Type::BOTTOM; // why not? 600 601 _zero_type[T_NARROWOOP] = TypeNarrowOop::NULL_PTR; 602 _zero_type[T_NARROWKLASS] = TypeNarrowKlass::NULL_PTR; 603 _zero_type[T_BOOLEAN] = TypeInt::ZERO; // false == 0 604 _zero_type[T_CHAR] = TypeInt::ZERO; // '\0' == 0 605 _zero_type[T_BYTE] = TypeInt::ZERO; // 0x00 == 0 606 _zero_type[T_SHORT] = TypeInt::ZERO; // 0x0000 == 0 607 _zero_type[T_INT] = TypeInt::ZERO; 608 _zero_type[T_LONG] = TypeLong::ZERO; 609 _zero_type[T_FLOAT] = TypeF::ZERO; 610 _zero_type[T_DOUBLE] = TypeD::ZERO; 611 _zero_type[T_OBJECT] = TypePtr::NULL_PTR; 612 _zero_type[T_ARRAY] = TypePtr::NULL_PTR; // null array is null oop 613 _zero_type[T_VALUETYPE] = TypePtr::NULL_PTR; 614 _zero_type[T_ADDRESS] = TypePtr::NULL_PTR; // raw pointers use the same null 615 _zero_type[T_VOID] = Type::TOP; // the only void value is no value at all 616 617 // get_zero_type() should not happen for T_CONFLICT 618 _zero_type[T_CONFLICT]= NULL; 619 620 // Vector predefined types, it needs initialized _const_basic_type[]. 621 if (Matcher::vector_size_supported(T_BYTE,4)) { 622 TypeVect::VECTS = TypeVect::make(T_BYTE,4); 623 } 624 if (Matcher::vector_size_supported(T_FLOAT,2)) { 625 TypeVect::VECTD = TypeVect::make(T_FLOAT,2); 626 } 627 if (Matcher::vector_size_supported(T_FLOAT,4)) { 628 TypeVect::VECTX = TypeVect::make(T_FLOAT,4); 629 } 630 if (Matcher::vector_size_supported(T_FLOAT,8)) { 631 TypeVect::VECTY = TypeVect::make(T_FLOAT,8); 632 } 633 if (Matcher::vector_size_supported(T_FLOAT,16)) { 634 TypeVect::VECTZ = TypeVect::make(T_FLOAT,16); 635 } 636 mreg2type[Op_VecS] = TypeVect::VECTS; 637 mreg2type[Op_VecD] = TypeVect::VECTD; 638 mreg2type[Op_VecX] = TypeVect::VECTX; 639 mreg2type[Op_VecY] = TypeVect::VECTY; 640 mreg2type[Op_VecZ] = TypeVect::VECTZ; 641 642 // Restore working type arena. 643 current->set_type_arena(save); 644 current->set_type_dict(NULL); 645 } 646 647 //------------------------------Initialize------------------------------------- 648 void Type::Initialize(Compile* current) { 649 assert(current->type_arena() != NULL, "must have created type arena"); 650 651 if (_shared_type_dict == NULL) { 652 Initialize_shared(current); 653 } 654 655 Arena* type_arena = current->type_arena(); 656 657 // Create the hash-cons'ing dictionary with top-level storage allocation 658 Dict *tdic = new (type_arena) Dict( (CmpKey)Type::cmp,(Hash)Type::uhash, type_arena, 128 ); 659 current->set_type_dict(tdic); 660 661 // Transfer the shared types. 662 DictI i(_shared_type_dict); 663 for( ; i.test(); ++i ) { 664 Type* t = (Type*)i._value; 665 tdic->Insert(t,t); // New Type, insert into Type table 666 } 667 } 668 669 //------------------------------hashcons--------------------------------------- 670 // Do the hash-cons trick. If the Type already exists in the type table, 671 // delete the current Type and return the existing Type. Otherwise stick the 672 // current Type in the Type table. 673 const Type *Type::hashcons(void) { 674 debug_only(base()); // Check the assertion in Type::base(). 675 // Look up the Type in the Type dictionary 676 Dict *tdic = type_dict(); 677 Type* old = (Type*)(tdic->Insert(this, this, false)); 678 if( old ) { // Pre-existing Type? 679 if( old != this ) // Yes, this guy is not the pre-existing? 680 delete this; // Yes, Nuke this guy 681 assert( old->_dual, "" ); 682 return old; // Return pre-existing 683 } 684 685 // Every type has a dual (to make my lattice symmetric). 686 // Since we just discovered a new Type, compute its dual right now. 687 assert( !_dual, "" ); // No dual yet 688 _dual = xdual(); // Compute the dual 689 if( cmp(this,_dual)==0 ) { // Handle self-symmetric 690 _dual = this; 691 return this; 692 } 693 assert( !_dual->_dual, "" ); // No reverse dual yet 694 assert( !(*tdic)[_dual], "" ); // Dual not in type system either 695 // New Type, insert into Type table 696 tdic->Insert((void*)_dual,(void*)_dual); 697 ((Type*)_dual)->_dual = this; // Finish up being symmetric 698 #ifdef ASSERT 699 Type *dual_dual = (Type*)_dual->xdual(); 700 assert( eq(dual_dual), "xdual(xdual()) should be identity" ); 701 delete dual_dual; 702 #endif 703 return this; // Return new Type 704 } 705 706 //------------------------------eq--------------------------------------------- 707 // Structural equality check for Type representations 708 bool Type::eq( const Type * ) const { 709 return true; // Nothing else can go wrong 710 } 711 712 //------------------------------hash------------------------------------------- 713 // Type-specific hashing function. 714 int Type::hash(void) const { 715 return _base; 716 } 717 718 //------------------------------is_finite-------------------------------------- 719 // Has a finite value 720 bool Type::is_finite() const { 721 return false; 722 } 723 724 //------------------------------is_nan----------------------------------------- 725 // Is not a number (NaN) 726 bool Type::is_nan() const { 727 return false; 728 } 729 730 //----------------------interface_vs_oop--------------------------------------- 731 #ifdef ASSERT 732 bool Type::interface_vs_oop_helper(const Type *t) const { 733 bool result = false; 734 735 const TypePtr* this_ptr = this->make_ptr(); // In case it is narrow_oop 736 const TypePtr* t_ptr = t->make_ptr(); 737 if( this_ptr == NULL || t_ptr == NULL ) 738 return result; 739 740 const TypeInstPtr* this_inst = this_ptr->isa_instptr(); 741 const TypeInstPtr* t_inst = t_ptr->isa_instptr(); 742 if( this_inst && this_inst->is_loaded() && t_inst && t_inst->is_loaded() ) { 743 bool this_interface = this_inst->klass()->is_interface(); 744 bool t_interface = t_inst->klass()->is_interface(); 745 result = this_interface ^ t_interface; 746 } 747 748 return result; 749 } 750 751 bool Type::interface_vs_oop(const Type *t) const { 752 if (interface_vs_oop_helper(t)) { 753 return true; 754 } 755 // Now check the speculative parts as well 756 const TypePtr* this_spec = isa_ptr() != NULL ? is_ptr()->speculative() : NULL; 757 const TypePtr* t_spec = t->isa_ptr() != NULL ? t->is_ptr()->speculative() : NULL; 758 if (this_spec != NULL && t_spec != NULL) { 759 if (this_spec->interface_vs_oop_helper(t_spec)) { 760 return true; 761 } 762 return false; 763 } 764 if (this_spec != NULL && this_spec->interface_vs_oop_helper(t)) { 765 return true; 766 } 767 if (t_spec != NULL && interface_vs_oop_helper(t_spec)) { 768 return true; 769 } 770 return false; 771 } 772 773 #endif 774 775 //------------------------------meet------------------------------------------- 776 // Compute the MEET of two types. NOT virtual. It enforces that meet is 777 // commutative and the lattice is symmetric. 778 const Type *Type::meet_helper(const Type *t, bool include_speculative) const { 779 if (isa_narrowoop() && t->isa_narrowoop()) { 780 const Type* result = make_ptr()->meet_helper(t->make_ptr(), include_speculative); 781 return result->make_narrowoop(); 782 } 783 if (isa_narrowklass() && t->isa_narrowklass()) { 784 const Type* result = make_ptr()->meet_helper(t->make_ptr(), include_speculative); 785 return result->make_narrowklass(); 786 } 787 788 const Type *this_t = maybe_remove_speculative(include_speculative); 789 t = t->maybe_remove_speculative(include_speculative); 790 791 const Type *mt = this_t->xmeet(t); 792 if (isa_narrowoop() || t->isa_narrowoop()) return mt; 793 if (isa_narrowklass() || t->isa_narrowklass()) return mt; 794 #ifdef ASSERT 795 assert(mt == t->xmeet(this_t), "meet not commutative"); 796 const Type* dual_join = mt->_dual; 797 const Type *t2t = dual_join->xmeet(t->_dual); 798 const Type *t2this = dual_join->xmeet(this_t->_dual); 799 800 // Interface meet Oop is Not Symmetric: 801 // Interface:AnyNull meet Oop:AnyNull == Interface:AnyNull 802 // Interface:NotNull meet Oop:NotNull == java/lang/Object:NotNull 803 804 if( !interface_vs_oop(t) && (t2t != t->_dual || t2this != this_t->_dual) ) { 805 tty->print_cr("=== Meet Not Symmetric ==="); 806 tty->print("t = "); t->dump(); tty->cr(); 807 tty->print("this= "); this_t->dump(); tty->cr(); 808 tty->print("mt=(t meet this)= "); mt->dump(); tty->cr(); 809 810 tty->print("t_dual= "); t->_dual->dump(); tty->cr(); 811 tty->print("this_dual= "); this_t->_dual->dump(); tty->cr(); 812 tty->print("mt_dual= "); mt->_dual->dump(); tty->cr(); 813 814 tty->print("mt_dual meet t_dual= "); t2t ->dump(); tty->cr(); 815 tty->print("mt_dual meet this_dual= "); t2this ->dump(); tty->cr(); 816 817 fatal("meet not symmetric" ); 818 } 819 #endif 820 return mt; 821 } 822 823 //------------------------------xmeet------------------------------------------ 824 // Compute the MEET of two types. It returns a new Type object. 825 const Type *Type::xmeet( const Type *t ) const { 826 // Perform a fast test for common case; meeting the same types together. 827 if( this == t ) return this; // Meeting same type-rep? 828 829 // Meeting TOP with anything? 830 if( _base == Top ) return t; 831 832 // Meeting BOTTOM with anything? 833 if( _base == Bottom ) return BOTTOM; 834 835 // Current "this->_base" is one of: Bad, Multi, Control, Top, 836 // Abio, Abstore, Floatxxx, Doublexxx, Bottom, lastype. 837 switch (t->base()) { // Switch on original type 838 839 // Cut in half the number of cases I must handle. Only need cases for when 840 // the given enum "t->type" is less than or equal to the local enum "type". 841 case FloatCon: 842 case DoubleCon: 843 case Int: 844 case Long: 845 return t->xmeet(this); 846 847 case OopPtr: 848 return t->xmeet(this); 849 850 case InstPtr: 851 case ValueTypePtr: 852 return t->xmeet(this); 853 854 case MetadataPtr: 855 case KlassPtr: 856 return t->xmeet(this); 857 858 case AryPtr: 859 return t->xmeet(this); 860 861 case NarrowOop: 862 return t->xmeet(this); 863 864 case NarrowKlass: 865 return t->xmeet(this); 866 867 case ValueType: 868 return t->xmeet(this); 869 870 case Bad: // Type check 871 default: // Bogus type not in lattice 872 typerr(t); 873 return Type::BOTTOM; 874 875 case Bottom: // Ye Olde Default 876 return t; 877 878 case FloatTop: 879 if( _base == FloatTop ) return this; 880 case FloatBot: // Float 881 if( _base == FloatBot || _base == FloatTop ) return FLOAT; 882 if( _base == DoubleTop || _base == DoubleBot ) return Type::BOTTOM; 883 typerr(t); 884 return Type::BOTTOM; 885 886 case DoubleTop: 887 if( _base == DoubleTop ) return this; 888 case DoubleBot: // Double 889 if( _base == DoubleBot || _base == DoubleTop ) return DOUBLE; 890 if( _base == FloatTop || _base == FloatBot ) return Type::BOTTOM; 891 typerr(t); 892 return Type::BOTTOM; 893 894 // These next few cases must match exactly or it is a compile-time error. 895 case Control: // Control of code 896 case Abio: // State of world outside of program 897 case Memory: 898 if( _base == t->_base ) return this; 899 typerr(t); 900 return Type::BOTTOM; 901 902 case Top: // Top of the lattice 903 return this; 904 } 905 906 // The type is unchanged 907 return this; 908 } 909 910 //-----------------------------filter------------------------------------------ 911 const Type *Type::filter_helper(const Type *kills, bool include_speculative) const { 912 const Type* ft = join_helper(kills, include_speculative); 913 if (ft->empty()) 914 return Type::TOP; // Canonical empty value 915 return ft; 916 } 917 918 //------------------------------xdual------------------------------------------ 919 // Compute dual right now. 920 const Type::TYPES Type::dual_type[Type::lastype] = { 921 Bad, // Bad 922 Control, // Control 923 Bottom, // Top 924 Bad, // Int - handled in v-call 925 Bad, // Long - handled in v-call 926 Half, // Half 927 Bad, // NarrowOop - handled in v-call 928 Bad, // NarrowKlass - handled in v-call 929 930 Bad, // Tuple - handled in v-call 931 Bad, // Array - handled in v-call 932 Bad, // VectorS - handled in v-call 933 Bad, // VectorD - handled in v-call 934 Bad, // VectorX - handled in v-call 935 Bad, // VectorY - handled in v-call 936 Bad, // VectorZ - handled in v-call 937 Bad, // ValueType - handled in v-call 938 939 Bad, // AnyPtr - handled in v-call 940 Bad, // RawPtr - handled in v-call 941 Bad, // OopPtr - handled in v-call 942 Bad, // InstPtr - handled in v-call 943 Bad, // ValueTypePtr - handled in v-call 944 Bad, // AryPtr - handled in v-call 945 946 Bad, // MetadataPtr - handled in v-call 947 Bad, // KlassPtr - handled in v-call 948 949 Bad, // Function - handled in v-call 950 Abio, // Abio 951 Return_Address,// Return_Address 952 Memory, // Memory 953 FloatBot, // FloatTop 954 FloatCon, // FloatCon 955 FloatTop, // FloatBot 956 DoubleBot, // DoubleTop 957 DoubleCon, // DoubleCon 958 DoubleTop, // DoubleBot 959 Top // Bottom 960 }; 961 962 const Type *Type::xdual() const { 963 // Note: the base() accessor asserts the sanity of _base. 964 assert(_type_info[base()].dual_type != Bad, "implement with v-call"); 965 return new Type(_type_info[_base].dual_type); 966 } 967 968 //------------------------------has_memory------------------------------------- 969 bool Type::has_memory() const { 970 Type::TYPES tx = base(); 971 if (tx == Memory) return true; 972 if (tx == Tuple) { 973 const TypeTuple *t = is_tuple(); 974 for (uint i=0; i < t->cnt(); i++) { 975 tx = t->field_at(i)->base(); 976 if (tx == Memory) return true; 977 } 978 } 979 return false; 980 } 981 982 #ifndef PRODUCT 983 //------------------------------dump2------------------------------------------ 984 void Type::dump2( Dict &d, uint depth, outputStream *st ) const { 985 st->print("%s", _type_info[_base].msg); 986 } 987 988 //------------------------------dump------------------------------------------- 989 void Type::dump_on(outputStream *st) const { 990 ResourceMark rm; 991 Dict d(cmpkey,hashkey); // Stop recursive type dumping 992 dump2(d,1, st); 993 if (is_ptr_to_narrowoop()) { 994 st->print(" [narrow]"); 995 } else if (is_ptr_to_narrowklass()) { 996 st->print(" [narrowklass]"); 997 } 998 } 999 #endif 1000 1001 //------------------------------singleton-------------------------------------- 1002 // TRUE if Type is a singleton type, FALSE otherwise. Singletons are simple 1003 // constants (Ldi nodes). Singletons are integer, float or double constants. 1004 bool Type::singleton(void) const { 1005 return _base == Top || _base == Half; 1006 } 1007 1008 //------------------------------empty------------------------------------------ 1009 // TRUE if Type is a type with no values, FALSE otherwise. 1010 bool Type::empty(void) const { 1011 switch (_base) { 1012 case DoubleTop: 1013 case FloatTop: 1014 case Top: 1015 return true; 1016 1017 case Half: 1018 case Abio: 1019 case Return_Address: 1020 case Memory: 1021 case Bottom: 1022 case FloatBot: 1023 case DoubleBot: 1024 return false; // never a singleton, therefore never empty 1025 } 1026 1027 ShouldNotReachHere(); 1028 return false; 1029 } 1030 1031 //------------------------------dump_stats------------------------------------- 1032 // Dump collected statistics to stderr 1033 #ifndef PRODUCT 1034 void Type::dump_stats() { 1035 tty->print("Types made: %d\n", type_dict()->Size()); 1036 } 1037 #endif 1038 1039 //------------------------------typerr----------------------------------------- 1040 void Type::typerr( const Type *t ) const { 1041 #ifndef PRODUCT 1042 tty->print("\nError mixing types: "); 1043 dump(); 1044 tty->print(" and "); 1045 t->dump(); 1046 tty->print("\n"); 1047 #endif 1048 ShouldNotReachHere(); 1049 } 1050 1051 1052 //============================================================================= 1053 // Convenience common pre-built types. 1054 const TypeF *TypeF::ZERO; // Floating point zero 1055 const TypeF *TypeF::ONE; // Floating point one 1056 1057 //------------------------------make------------------------------------------- 1058 // Create a float constant 1059 const TypeF *TypeF::make(float f) { 1060 return (TypeF*)(new TypeF(f))->hashcons(); 1061 } 1062 1063 //------------------------------meet------------------------------------------- 1064 // Compute the MEET of two types. It returns a new Type object. 1065 const Type *TypeF::xmeet( const Type *t ) const { 1066 // Perform a fast test for common case; meeting the same types together. 1067 if( this == t ) return this; // Meeting same type-rep? 1068 1069 // Current "this->_base" is FloatCon 1070 switch (t->base()) { // Switch on original type 1071 case AnyPtr: // Mixing with oops happens when javac 1072 case RawPtr: // reuses local variables 1073 case OopPtr: 1074 case InstPtr: 1075 case ValueTypePtr: 1076 case AryPtr: 1077 case MetadataPtr: 1078 case KlassPtr: 1079 case NarrowOop: 1080 case NarrowKlass: 1081 case Int: 1082 case Long: 1083 case DoubleTop: 1084 case DoubleCon: 1085 case DoubleBot: 1086 case Bottom: // Ye Olde Default 1087 return Type::BOTTOM; 1088 1089 case FloatBot: 1090 return t; 1091 1092 default: // All else is a mistake 1093 typerr(t); 1094 1095 case FloatCon: // Float-constant vs Float-constant? 1096 if( jint_cast(_f) != jint_cast(t->getf()) ) // unequal constants? 1097 // must compare bitwise as positive zero, negative zero and NaN have 1098 // all the same representation in C++ 1099 return FLOAT; // Return generic float 1100 // Equal constants 1101 case Top: 1102 case FloatTop: 1103 break; // Return the float constant 1104 } 1105 return this; // Return the float constant 1106 } 1107 1108 //------------------------------xdual------------------------------------------ 1109 // Dual: symmetric 1110 const Type *TypeF::xdual() const { 1111 return this; 1112 } 1113 1114 //------------------------------eq--------------------------------------------- 1115 // Structural equality check for Type representations 1116 bool TypeF::eq(const Type *t) const { 1117 // Bitwise comparison to distinguish between +/-0. These values must be treated 1118 // as different to be consistent with C1 and the interpreter. 1119 return (jint_cast(_f) == jint_cast(t->getf())); 1120 } 1121 1122 //------------------------------hash------------------------------------------- 1123 // Type-specific hashing function. 1124 int TypeF::hash(void) const { 1125 return *(int*)(&_f); 1126 } 1127 1128 //------------------------------is_finite-------------------------------------- 1129 // Has a finite value 1130 bool TypeF::is_finite() const { 1131 return g_isfinite(getf()) != 0; 1132 } 1133 1134 //------------------------------is_nan----------------------------------------- 1135 // Is not a number (NaN) 1136 bool TypeF::is_nan() const { 1137 return g_isnan(getf()) != 0; 1138 } 1139 1140 //------------------------------dump2------------------------------------------ 1141 // Dump float constant Type 1142 #ifndef PRODUCT 1143 void TypeF::dump2( Dict &d, uint depth, outputStream *st ) const { 1144 Type::dump2(d,depth, st); 1145 st->print("%f", _f); 1146 } 1147 #endif 1148 1149 //------------------------------singleton-------------------------------------- 1150 // TRUE if Type is a singleton type, FALSE otherwise. Singletons are simple 1151 // constants (Ldi nodes). Singletons are integer, float or double constants 1152 // or a single symbol. 1153 bool TypeF::singleton(void) const { 1154 return true; // Always a singleton 1155 } 1156 1157 bool TypeF::empty(void) const { 1158 return false; // always exactly a singleton 1159 } 1160 1161 //============================================================================= 1162 // Convenience common pre-built types. 1163 const TypeD *TypeD::ZERO; // Floating point zero 1164 const TypeD *TypeD::ONE; // Floating point one 1165 1166 //------------------------------make------------------------------------------- 1167 const TypeD *TypeD::make(double d) { 1168 return (TypeD*)(new TypeD(d))->hashcons(); 1169 } 1170 1171 //------------------------------meet------------------------------------------- 1172 // Compute the MEET of two types. It returns a new Type object. 1173 const Type *TypeD::xmeet( const Type *t ) const { 1174 // Perform a fast test for common case; meeting the same types together. 1175 if( this == t ) return this; // Meeting same type-rep? 1176 1177 // Current "this->_base" is DoubleCon 1178 switch (t->base()) { // Switch on original type 1179 case AnyPtr: // Mixing with oops happens when javac 1180 case RawPtr: // reuses local variables 1181 case OopPtr: 1182 case InstPtr: 1183 case ValueTypePtr: 1184 case AryPtr: 1185 case MetadataPtr: 1186 case KlassPtr: 1187 case NarrowOop: 1188 case NarrowKlass: 1189 case Int: 1190 case Long: 1191 case FloatTop: 1192 case FloatCon: 1193 case FloatBot: 1194 case Bottom: // Ye Olde Default 1195 return Type::BOTTOM; 1196 1197 case DoubleBot: 1198 return t; 1199 1200 default: // All else is a mistake 1201 typerr(t); 1202 1203 case DoubleCon: // Double-constant vs Double-constant? 1204 if( jlong_cast(_d) != jlong_cast(t->getd()) ) // unequal constants? (see comment in TypeF::xmeet) 1205 return DOUBLE; // Return generic double 1206 case Top: 1207 case DoubleTop: 1208 break; 1209 } 1210 return this; // Return the double constant 1211 } 1212 1213 //------------------------------xdual------------------------------------------ 1214 // Dual: symmetric 1215 const Type *TypeD::xdual() const { 1216 return this; 1217 } 1218 1219 //------------------------------eq--------------------------------------------- 1220 // Structural equality check for Type representations 1221 bool TypeD::eq(const Type *t) const { 1222 // Bitwise comparison to distinguish between +/-0. These values must be treated 1223 // as different to be consistent with C1 and the interpreter. 1224 return (jlong_cast(_d) == jlong_cast(t->getd())); 1225 } 1226 1227 //------------------------------hash------------------------------------------- 1228 // Type-specific hashing function. 1229 int TypeD::hash(void) const { 1230 return *(int*)(&_d); 1231 } 1232 1233 //------------------------------is_finite-------------------------------------- 1234 // Has a finite value 1235 bool TypeD::is_finite() const { 1236 return g_isfinite(getd()) != 0; 1237 } 1238 1239 //------------------------------is_nan----------------------------------------- 1240 // Is not a number (NaN) 1241 bool TypeD::is_nan() const { 1242 return g_isnan(getd()) != 0; 1243 } 1244 1245 //------------------------------dump2------------------------------------------ 1246 // Dump double constant Type 1247 #ifndef PRODUCT 1248 void TypeD::dump2( Dict &d, uint depth, outputStream *st ) const { 1249 Type::dump2(d,depth,st); 1250 st->print("%f", _d); 1251 } 1252 #endif 1253 1254 //------------------------------singleton-------------------------------------- 1255 // TRUE if Type is a singleton type, FALSE otherwise. Singletons are simple 1256 // constants (Ldi nodes). Singletons are integer, float or double constants 1257 // or a single symbol. 1258 bool TypeD::singleton(void) const { 1259 return true; // Always a singleton 1260 } 1261 1262 bool TypeD::empty(void) const { 1263 return false; // always exactly a singleton 1264 } 1265 1266 //============================================================================= 1267 // Convience common pre-built types. 1268 const TypeInt *TypeInt::MINUS_1;// -1 1269 const TypeInt *TypeInt::ZERO; // 0 1270 const TypeInt *TypeInt::ONE; // 1 1271 const TypeInt *TypeInt::BOOL; // 0 or 1, FALSE or TRUE. 1272 const TypeInt *TypeInt::CC; // -1,0 or 1, condition codes 1273 const TypeInt *TypeInt::CC_LT; // [-1] == MINUS_1 1274 const TypeInt *TypeInt::CC_GT; // [1] == ONE 1275 const TypeInt *TypeInt::CC_EQ; // [0] == ZERO 1276 const TypeInt *TypeInt::CC_LE; // [-1,0] 1277 const TypeInt *TypeInt::CC_GE; // [0,1] == BOOL (!) 1278 const TypeInt *TypeInt::BYTE; // Bytes, -128 to 127 1279 const TypeInt *TypeInt::UBYTE; // Unsigned Bytes, 0 to 255 1280 const TypeInt *TypeInt::CHAR; // Java chars, 0-65535 1281 const TypeInt *TypeInt::SHORT; // Java shorts, -32768-32767 1282 const TypeInt *TypeInt::POS; // Positive 32-bit integers or zero 1283 const TypeInt *TypeInt::POS1; // Positive 32-bit integers 1284 const TypeInt *TypeInt::INT; // 32-bit integers 1285 const TypeInt *TypeInt::SYMINT; // symmetric range [-max_jint..max_jint] 1286 const TypeInt *TypeInt::TYPE_DOMAIN; // alias for TypeInt::INT 1287 1288 //------------------------------TypeInt---------------------------------------- 1289 TypeInt::TypeInt( jint lo, jint hi, int w ) : Type(Int), _lo(lo), _hi(hi), _widen(w) { 1290 } 1291 1292 //------------------------------make------------------------------------------- 1293 const TypeInt *TypeInt::make( jint lo ) { 1294 return (TypeInt*)(new TypeInt(lo,lo,WidenMin))->hashcons(); 1295 } 1296 1297 static int normalize_int_widen( jint lo, jint hi, int w ) { 1298 // Certain normalizations keep us sane when comparing types. 1299 // The 'SMALLINT' covers constants and also CC and its relatives. 1300 if (lo <= hi) { 1301 if (((juint)hi - lo) <= SMALLINT) w = Type::WidenMin; 1302 if (((juint)hi - lo) >= max_juint) w = Type::WidenMax; // TypeInt::INT 1303 } else { 1304 if (((juint)lo - hi) <= SMALLINT) w = Type::WidenMin; 1305 if (((juint)lo - hi) >= max_juint) w = Type::WidenMin; // dual TypeInt::INT 1306 } 1307 return w; 1308 } 1309 1310 const TypeInt *TypeInt::make( jint lo, jint hi, int w ) { 1311 w = normalize_int_widen(lo, hi, w); 1312 return (TypeInt*)(new TypeInt(lo,hi,w))->hashcons(); 1313 } 1314 1315 //------------------------------meet------------------------------------------- 1316 // Compute the MEET of two types. It returns a new Type representation object 1317 // with reference count equal to the number of Types pointing at it. 1318 // Caller should wrap a Types around it. 1319 const Type *TypeInt::xmeet( const Type *t ) const { 1320 // Perform a fast test for common case; meeting the same types together. 1321 if( this == t ) return this; // Meeting same type? 1322 1323 // Currently "this->_base" is a TypeInt 1324 switch (t->base()) { // Switch on original type 1325 case AnyPtr: // Mixing with oops happens when javac 1326 case RawPtr: // reuses local variables 1327 case OopPtr: 1328 case InstPtr: 1329 case ValueTypePtr: 1330 case AryPtr: 1331 case MetadataPtr: 1332 case KlassPtr: 1333 case NarrowOop: 1334 case NarrowKlass: 1335 case Long: 1336 case FloatTop: 1337 case FloatCon: 1338 case FloatBot: 1339 case DoubleTop: 1340 case DoubleCon: 1341 case DoubleBot: 1342 case Bottom: // Ye Olde Default 1343 return Type::BOTTOM; 1344 default: // All else is a mistake 1345 typerr(t); 1346 case Top: // No change 1347 return this; 1348 case Int: // Int vs Int? 1349 break; 1350 } 1351 1352 // Expand covered set 1353 const TypeInt *r = t->is_int(); 1354 return make( MIN2(_lo,r->_lo), MAX2(_hi,r->_hi), MAX2(_widen,r->_widen) ); 1355 } 1356 1357 //------------------------------xdual------------------------------------------ 1358 // Dual: reverse hi & lo; flip widen 1359 const Type *TypeInt::xdual() const { 1360 int w = normalize_int_widen(_hi,_lo, WidenMax-_widen); 1361 return new TypeInt(_hi,_lo,w); 1362 } 1363 1364 //------------------------------widen------------------------------------------ 1365 // Only happens for optimistic top-down optimizations. 1366 const Type *TypeInt::widen( const Type *old, const Type* limit ) const { 1367 // Coming from TOP or such; no widening 1368 if( old->base() != Int ) return this; 1369 const TypeInt *ot = old->is_int(); 1370 1371 // If new guy is equal to old guy, no widening 1372 if( _lo == ot->_lo && _hi == ot->_hi ) 1373 return old; 1374 1375 // If new guy contains old, then we widened 1376 if( _lo <= ot->_lo && _hi >= ot->_hi ) { 1377 // New contains old 1378 // If new guy is already wider than old, no widening 1379 if( _widen > ot->_widen ) return this; 1380 // If old guy was a constant, do not bother 1381 if (ot->_lo == ot->_hi) return this; 1382 // Now widen new guy. 1383 // Check for widening too far 1384 if (_widen == WidenMax) { 1385 int max = max_jint; 1386 int min = min_jint; 1387 if (limit->isa_int()) { 1388 max = limit->is_int()->_hi; 1389 min = limit->is_int()->_lo; 1390 } 1391 if (min < _lo && _hi < max) { 1392 // If neither endpoint is extremal yet, push out the endpoint 1393 // which is closer to its respective limit. 1394 if (_lo >= 0 || // easy common case 1395 (juint)(_lo - min) >= (juint)(max - _hi)) { 1396 // Try to widen to an unsigned range type of 31 bits: 1397 return make(_lo, max, WidenMax); 1398 } else { 1399 return make(min, _hi, WidenMax); 1400 } 1401 } 1402 return TypeInt::INT; 1403 } 1404 // Returned widened new guy 1405 return make(_lo,_hi,_widen+1); 1406 } 1407 1408 // If old guy contains new, then we probably widened too far & dropped to 1409 // bottom. Return the wider fellow. 1410 if ( ot->_lo <= _lo && ot->_hi >= _hi ) 1411 return old; 1412 1413 //fatal("Integer value range is not subset"); 1414 //return this; 1415 return TypeInt::INT; 1416 } 1417 1418 //------------------------------narrow--------------------------------------- 1419 // Only happens for pessimistic optimizations. 1420 const Type *TypeInt::narrow( const Type *old ) const { 1421 if (_lo >= _hi) return this; // already narrow enough 1422 if (old == NULL) return this; 1423 const TypeInt* ot = old->isa_int(); 1424 if (ot == NULL) return this; 1425 jint olo = ot->_lo; 1426 jint ohi = ot->_hi; 1427 1428 // If new guy is equal to old guy, no narrowing 1429 if (_lo == olo && _hi == ohi) return old; 1430 1431 // If old guy was maximum range, allow the narrowing 1432 if (olo == min_jint && ohi == max_jint) return this; 1433 1434 if (_lo < olo || _hi > ohi) 1435 return this; // doesn't narrow; pretty wierd 1436 1437 // The new type narrows the old type, so look for a "death march". 1438 // See comments on PhaseTransform::saturate. 1439 juint nrange = (juint)_hi - _lo; 1440 juint orange = (juint)ohi - olo; 1441 if (nrange < max_juint - 1 && nrange > (orange >> 1) + (SMALLINT*2)) { 1442 // Use the new type only if the range shrinks a lot. 1443 // We do not want the optimizer computing 2^31 point by point. 1444 return old; 1445 } 1446 1447 return this; 1448 } 1449 1450 //-----------------------------filter------------------------------------------ 1451 const Type *TypeInt::filter_helper(const Type *kills, bool include_speculative) const { 1452 const TypeInt* ft = join_helper(kills, include_speculative)->isa_int(); 1453 if (ft == NULL || ft->empty()) 1454 return Type::TOP; // Canonical empty value 1455 if (ft->_widen < this->_widen) { 1456 // Do not allow the value of kill->_widen to affect the outcome. 1457 // The widen bits must be allowed to run freely through the graph. 1458 ft = TypeInt::make(ft->_lo, ft->_hi, this->_widen); 1459 } 1460 return ft; 1461 } 1462 1463 //------------------------------eq--------------------------------------------- 1464 // Structural equality check for Type representations 1465 bool TypeInt::eq( const Type *t ) const { 1466 const TypeInt *r = t->is_int(); // Handy access 1467 return r->_lo == _lo && r->_hi == _hi && r->_widen == _widen; 1468 } 1469 1470 //------------------------------hash------------------------------------------- 1471 // Type-specific hashing function. 1472 int TypeInt::hash(void) const { 1473 return java_add(java_add(_lo, _hi), java_add(_widen, (int)Type::Int)); 1474 } 1475 1476 //------------------------------is_finite-------------------------------------- 1477 // Has a finite value 1478 bool TypeInt::is_finite() const { 1479 return true; 1480 } 1481 1482 //------------------------------dump2------------------------------------------ 1483 // Dump TypeInt 1484 #ifndef PRODUCT 1485 static const char* intname(char* buf, jint n) { 1486 if (n == min_jint) 1487 return "min"; 1488 else if (n < min_jint + 10000) 1489 sprintf(buf, "min+" INT32_FORMAT, n - min_jint); 1490 else if (n == max_jint) 1491 return "max"; 1492 else if (n > max_jint - 10000) 1493 sprintf(buf, "max-" INT32_FORMAT, max_jint - n); 1494 else 1495 sprintf(buf, INT32_FORMAT, n); 1496 return buf; 1497 } 1498 1499 void TypeInt::dump2( Dict &d, uint depth, outputStream *st ) const { 1500 char buf[40], buf2[40]; 1501 if (_lo == min_jint && _hi == max_jint) 1502 st->print("int"); 1503 else if (is_con()) 1504 st->print("int:%s", intname(buf, get_con())); 1505 else if (_lo == BOOL->_lo && _hi == BOOL->_hi) 1506 st->print("bool"); 1507 else if (_lo == BYTE->_lo && _hi == BYTE->_hi) 1508 st->print("byte"); 1509 else if (_lo == CHAR->_lo && _hi == CHAR->_hi) 1510 st->print("char"); 1511 else if (_lo == SHORT->_lo && _hi == SHORT->_hi) 1512 st->print("short"); 1513 else if (_hi == max_jint) 1514 st->print("int:>=%s", intname(buf, _lo)); 1515 else if (_lo == min_jint) 1516 st->print("int:<=%s", intname(buf, _hi)); 1517 else 1518 st->print("int:%s..%s", intname(buf, _lo), intname(buf2, _hi)); 1519 1520 if (_widen != 0 && this != TypeInt::INT) 1521 st->print(":%.*s", _widen, "wwww"); 1522 } 1523 #endif 1524 1525 //------------------------------singleton-------------------------------------- 1526 // TRUE if Type is a singleton type, FALSE otherwise. Singletons are simple 1527 // constants. 1528 bool TypeInt::singleton(void) const { 1529 return _lo >= _hi; 1530 } 1531 1532 bool TypeInt::empty(void) const { 1533 return _lo > _hi; 1534 } 1535 1536 //============================================================================= 1537 // Convenience common pre-built types. 1538 const TypeLong *TypeLong::MINUS_1;// -1 1539 const TypeLong *TypeLong::ZERO; // 0 1540 const TypeLong *TypeLong::ONE; // 1 1541 const TypeLong *TypeLong::POS; // >=0 1542 const TypeLong *TypeLong::LONG; // 64-bit integers 1543 const TypeLong *TypeLong::INT; // 32-bit subrange 1544 const TypeLong *TypeLong::UINT; // 32-bit unsigned subrange 1545 const TypeLong *TypeLong::TYPE_DOMAIN; // alias for TypeLong::LONG 1546 1547 //------------------------------TypeLong--------------------------------------- 1548 TypeLong::TypeLong( jlong lo, jlong hi, int w ) : Type(Long), _lo(lo), _hi(hi), _widen(w) { 1549 } 1550 1551 //------------------------------make------------------------------------------- 1552 const TypeLong *TypeLong::make( jlong lo ) { 1553 return (TypeLong*)(new TypeLong(lo,lo,WidenMin))->hashcons(); 1554 } 1555 1556 static int normalize_long_widen( jlong lo, jlong hi, int w ) { 1557 // Certain normalizations keep us sane when comparing types. 1558 // The 'SMALLINT' covers constants. 1559 if (lo <= hi) { 1560 if (((julong)hi - lo) <= SMALLINT) w = Type::WidenMin; 1561 if (((julong)hi - lo) >= max_julong) w = Type::WidenMax; // TypeLong::LONG 1562 } else { 1563 if (((julong)lo - hi) <= SMALLINT) w = Type::WidenMin; 1564 if (((julong)lo - hi) >= max_julong) w = Type::WidenMin; // dual TypeLong::LONG 1565 } 1566 return w; 1567 } 1568 1569 const TypeLong *TypeLong::make( jlong lo, jlong hi, int w ) { 1570 w = normalize_long_widen(lo, hi, w); 1571 return (TypeLong*)(new TypeLong(lo,hi,w))->hashcons(); 1572 } 1573 1574 1575 //------------------------------meet------------------------------------------- 1576 // Compute the MEET of two types. It returns a new Type representation object 1577 // with reference count equal to the number of Types pointing at it. 1578 // Caller should wrap a Types around it. 1579 const Type *TypeLong::xmeet( const Type *t ) const { 1580 // Perform a fast test for common case; meeting the same types together. 1581 if( this == t ) return this; // Meeting same type? 1582 1583 // Currently "this->_base" is a TypeLong 1584 switch (t->base()) { // Switch on original type 1585 case AnyPtr: // Mixing with oops happens when javac 1586 case RawPtr: // reuses local variables 1587 case OopPtr: 1588 case InstPtr: 1589 case ValueTypePtr: 1590 case AryPtr: 1591 case MetadataPtr: 1592 case KlassPtr: 1593 case NarrowOop: 1594 case NarrowKlass: 1595 case Int: 1596 case FloatTop: 1597 case FloatCon: 1598 case FloatBot: 1599 case DoubleTop: 1600 case DoubleCon: 1601 case DoubleBot: 1602 case Bottom: // Ye Olde Default 1603 return Type::BOTTOM; 1604 default: // All else is a mistake 1605 typerr(t); 1606 case Top: // No change 1607 return this; 1608 case Long: // Long vs Long? 1609 break; 1610 } 1611 1612 // Expand covered set 1613 const TypeLong *r = t->is_long(); // Turn into a TypeLong 1614 return make( MIN2(_lo,r->_lo), MAX2(_hi,r->_hi), MAX2(_widen,r->_widen) ); 1615 } 1616 1617 //------------------------------xdual------------------------------------------ 1618 // Dual: reverse hi & lo; flip widen 1619 const Type *TypeLong::xdual() const { 1620 int w = normalize_long_widen(_hi,_lo, WidenMax-_widen); 1621 return new TypeLong(_hi,_lo,w); 1622 } 1623 1624 //------------------------------widen------------------------------------------ 1625 // Only happens for optimistic top-down optimizations. 1626 const Type *TypeLong::widen( const Type *old, const Type* limit ) const { 1627 // Coming from TOP or such; no widening 1628 if( old->base() != Long ) return this; 1629 const TypeLong *ot = old->is_long(); 1630 1631 // If new guy is equal to old guy, no widening 1632 if( _lo == ot->_lo && _hi == ot->_hi ) 1633 return old; 1634 1635 // If new guy contains old, then we widened 1636 if( _lo <= ot->_lo && _hi >= ot->_hi ) { 1637 // New contains old 1638 // If new guy is already wider than old, no widening 1639 if( _widen > ot->_widen ) return this; 1640 // If old guy was a constant, do not bother 1641 if (ot->_lo == ot->_hi) return this; 1642 // Now widen new guy. 1643 // Check for widening too far 1644 if (_widen == WidenMax) { 1645 jlong max = max_jlong; 1646 jlong min = min_jlong; 1647 if (limit->isa_long()) { 1648 max = limit->is_long()->_hi; 1649 min = limit->is_long()->_lo; 1650 } 1651 if (min < _lo && _hi < max) { 1652 // If neither endpoint is extremal yet, push out the endpoint 1653 // which is closer to its respective limit. 1654 if (_lo >= 0 || // easy common case 1655 ((julong)_lo - min) >= ((julong)max - _hi)) { 1656 // Try to widen to an unsigned range type of 32/63 bits: 1657 if (max >= max_juint && _hi < max_juint) 1658 return make(_lo, max_juint, WidenMax); 1659 else 1660 return make(_lo, max, WidenMax); 1661 } else { 1662 return make(min, _hi, WidenMax); 1663 } 1664 } 1665 return TypeLong::LONG; 1666 } 1667 // Returned widened new guy 1668 return make(_lo,_hi,_widen+1); 1669 } 1670 1671 // If old guy contains new, then we probably widened too far & dropped to 1672 // bottom. Return the wider fellow. 1673 if ( ot->_lo <= _lo && ot->_hi >= _hi ) 1674 return old; 1675 1676 // fatal("Long value range is not subset"); 1677 // return this; 1678 return TypeLong::LONG; 1679 } 1680 1681 //------------------------------narrow---------------------------------------- 1682 // Only happens for pessimistic optimizations. 1683 const Type *TypeLong::narrow( const Type *old ) const { 1684 if (_lo >= _hi) return this; // already narrow enough 1685 if (old == NULL) return this; 1686 const TypeLong* ot = old->isa_long(); 1687 if (ot == NULL) return this; 1688 jlong olo = ot->_lo; 1689 jlong ohi = ot->_hi; 1690 1691 // If new guy is equal to old guy, no narrowing 1692 if (_lo == olo && _hi == ohi) return old; 1693 1694 // If old guy was maximum range, allow the narrowing 1695 if (olo == min_jlong && ohi == max_jlong) return this; 1696 1697 if (_lo < olo || _hi > ohi) 1698 return this; // doesn't narrow; pretty wierd 1699 1700 // The new type narrows the old type, so look for a "death march". 1701 // See comments on PhaseTransform::saturate. 1702 julong nrange = _hi - _lo; 1703 julong orange = ohi - olo; 1704 if (nrange < max_julong - 1 && nrange > (orange >> 1) + (SMALLINT*2)) { 1705 // Use the new type only if the range shrinks a lot. 1706 // We do not want the optimizer computing 2^31 point by point. 1707 return old; 1708 } 1709 1710 return this; 1711 } 1712 1713 //-----------------------------filter------------------------------------------ 1714 const Type *TypeLong::filter_helper(const Type *kills, bool include_speculative) const { 1715 const TypeLong* ft = join_helper(kills, include_speculative)->isa_long(); 1716 if (ft == NULL || ft->empty()) 1717 return Type::TOP; // Canonical empty value 1718 if (ft->_widen < this->_widen) { 1719 // Do not allow the value of kill->_widen to affect the outcome. 1720 // The widen bits must be allowed to run freely through the graph. 1721 ft = TypeLong::make(ft->_lo, ft->_hi, this->_widen); 1722 } 1723 return ft; 1724 } 1725 1726 //------------------------------eq--------------------------------------------- 1727 // Structural equality check for Type representations 1728 bool TypeLong::eq( const Type *t ) const { 1729 const TypeLong *r = t->is_long(); // Handy access 1730 return r->_lo == _lo && r->_hi == _hi && r->_widen == _widen; 1731 } 1732 1733 //------------------------------hash------------------------------------------- 1734 // Type-specific hashing function. 1735 int TypeLong::hash(void) const { 1736 return (int)(_lo+_hi+_widen+(int)Type::Long); 1737 } 1738 1739 //------------------------------is_finite-------------------------------------- 1740 // Has a finite value 1741 bool TypeLong::is_finite() const { 1742 return true; 1743 } 1744 1745 //------------------------------dump2------------------------------------------ 1746 // Dump TypeLong 1747 #ifndef PRODUCT 1748 static const char* longnamenear(jlong x, const char* xname, char* buf, jlong n) { 1749 if (n > x) { 1750 if (n >= x + 10000) return NULL; 1751 sprintf(buf, "%s+" JLONG_FORMAT, xname, n - x); 1752 } else if (n < x) { 1753 if (n <= x - 10000) return NULL; 1754 sprintf(buf, "%s-" JLONG_FORMAT, xname, x - n); 1755 } else { 1756 return xname; 1757 } 1758 return buf; 1759 } 1760 1761 static const char* longname(char* buf, jlong n) { 1762 const char* str; 1763 if (n == min_jlong) 1764 return "min"; 1765 else if (n < min_jlong + 10000) 1766 sprintf(buf, "min+" JLONG_FORMAT, n - min_jlong); 1767 else if (n == max_jlong) 1768 return "max"; 1769 else if (n > max_jlong - 10000) 1770 sprintf(buf, "max-" JLONG_FORMAT, max_jlong - n); 1771 else if ((str = longnamenear(max_juint, "maxuint", buf, n)) != NULL) 1772 return str; 1773 else if ((str = longnamenear(max_jint, "maxint", buf, n)) != NULL) 1774 return str; 1775 else if ((str = longnamenear(min_jint, "minint", buf, n)) != NULL) 1776 return str; 1777 else 1778 sprintf(buf, JLONG_FORMAT, n); 1779 return buf; 1780 } 1781 1782 void TypeLong::dump2( Dict &d, uint depth, outputStream *st ) const { 1783 char buf[80], buf2[80]; 1784 if (_lo == min_jlong && _hi == max_jlong) 1785 st->print("long"); 1786 else if (is_con()) 1787 st->print("long:%s", longname(buf, get_con())); 1788 else if (_hi == max_jlong) 1789 st->print("long:>=%s", longname(buf, _lo)); 1790 else if (_lo == min_jlong) 1791 st->print("long:<=%s", longname(buf, _hi)); 1792 else 1793 st->print("long:%s..%s", longname(buf, _lo), longname(buf2, _hi)); 1794 1795 if (_widen != 0 && this != TypeLong::LONG) 1796 st->print(":%.*s", _widen, "wwww"); 1797 } 1798 #endif 1799 1800 //------------------------------singleton-------------------------------------- 1801 // TRUE if Type is a singleton type, FALSE otherwise. Singletons are simple 1802 // constants 1803 bool TypeLong::singleton(void) const { 1804 return _lo >= _hi; 1805 } 1806 1807 bool TypeLong::empty(void) const { 1808 return _lo > _hi; 1809 } 1810 1811 //============================================================================= 1812 // Convenience common pre-built types. 1813 const TypeTuple *TypeTuple::IFBOTH; // Return both arms of IF as reachable 1814 const TypeTuple *TypeTuple::IFFALSE; 1815 const TypeTuple *TypeTuple::IFTRUE; 1816 const TypeTuple *TypeTuple::IFNEITHER; 1817 const TypeTuple *TypeTuple::LOOPBODY; 1818 const TypeTuple *TypeTuple::MEMBAR; 1819 const TypeTuple *TypeTuple::STORECONDITIONAL; 1820 const TypeTuple *TypeTuple::START_I2C; 1821 const TypeTuple *TypeTuple::INT_PAIR; 1822 const TypeTuple *TypeTuple::LONG_PAIR; 1823 const TypeTuple *TypeTuple::INT_CC_PAIR; 1824 const TypeTuple *TypeTuple::LONG_CC_PAIR; 1825 1826 1827 //------------------------------make------------------------------------------- 1828 // Make a TypeTuple from the range of a method signature 1829 const TypeTuple *TypeTuple::make_range(ciSignature* sig) { 1830 ciType* return_type = sig->return_type(); 1831 uint arg_cnt = return_type->size(); 1832 const Type **field_array = fields(arg_cnt); 1833 switch (return_type->basic_type()) { 1834 case T_LONG: 1835 field_array[TypeFunc::Parms] = TypeLong::LONG; 1836 field_array[TypeFunc::Parms+1] = Type::HALF; 1837 break; 1838 case T_DOUBLE: 1839 field_array[TypeFunc::Parms] = Type::DOUBLE; 1840 field_array[TypeFunc::Parms+1] = Type::HALF; 1841 break; 1842 case T_OBJECT: 1843 case T_VALUETYPE: 1844 case T_ARRAY: 1845 case T_BOOLEAN: 1846 case T_CHAR: 1847 case T_FLOAT: 1848 case T_BYTE: 1849 case T_SHORT: 1850 case T_INT: 1851 field_array[TypeFunc::Parms] = get_const_type(return_type); 1852 break; 1853 case T_VOID: 1854 break; 1855 default: 1856 ShouldNotReachHere(); 1857 } 1858 return (TypeTuple*)(new TypeTuple(TypeFunc::Parms + arg_cnt, field_array))->hashcons(); 1859 } 1860 1861 static void collect_value_fields(ciValueKlass* vk, const Type**& field_array, uint& pos) { 1862 for (int j = 0; j < vk->nof_nonstatic_fields(); j++) { 1863 ciField* f = vk->nonstatic_field_at(j); 1864 BasicType bt = f->type()->basic_type(); 1865 assert(bt < T_VALUETYPE && bt >= T_BOOLEAN, "not yet supported"); 1866 field_array[pos++] = Type::get_const_type(f->type()); 1867 if (bt == T_LONG || bt == T_DOUBLE) { 1868 field_array[pos++] = Type::HALF; 1869 } 1870 } 1871 } 1872 1873 // Make a TypeTuple from the domain of a method signature 1874 const TypeTuple *TypeTuple::make_domain(ciInstanceKlass* recv, ciSignature* sig, bool vt_fields_as_args) { 1875 uint arg_cnt = sig->size(); 1876 1877 int vt_extra = 0; 1878 if (vt_fields_as_args) { 1879 for (int i = 0; i < sig->count(); i++) { 1880 ciType* type = sig->type_at(i); 1881 if (type->basic_type() == T_VALUETYPE) { 1882 assert(type->is_valuetype(), "inconsistent type"); 1883 ciValueKlass* vk = (ciValueKlass*)type; 1884 vt_extra += vk->value_arg_slots()-1; 1885 } 1886 } 1887 assert(((int)arg_cnt) + vt_extra >= 0, "negative number of actual arguments?"); 1888 } 1889 1890 uint pos = TypeFunc::Parms; 1891 const Type **field_array; 1892 if (recv != NULL) { 1893 arg_cnt++; 1894 if (vt_fields_as_args && recv->is_valuetype()) { 1895 ciValueKlass* vk = (ciValueKlass*)recv; 1896 vt_extra += vk->value_arg_slots()-1; 1897 } 1898 field_array = fields(arg_cnt + vt_extra); 1899 // Use get_const_type here because it respects UseUniqueSubclasses: 1900 if (vt_fields_as_args && recv->is_valuetype()) { 1901 ciValueKlass* vk = (ciValueKlass*)recv; 1902 collect_value_fields(vk, field_array, pos); 1903 } else { 1904 field_array[pos++] = get_const_type(recv)->join_speculative(TypePtr::NOTNULL); 1905 } 1906 } else { 1907 field_array = fields(arg_cnt + vt_extra); 1908 } 1909 1910 int i = 0; 1911 while (pos < TypeFunc::Parms + arg_cnt + vt_extra) { 1912 ciType* type = sig->type_at(i); 1913 1914 switch (type->basic_type()) { 1915 case T_LONG: 1916 field_array[pos++] = TypeLong::LONG; 1917 field_array[pos++] = Type::HALF; 1918 break; 1919 case T_DOUBLE: 1920 field_array[pos++] = Type::DOUBLE; 1921 field_array[pos++] = Type::HALF; 1922 break; 1923 case T_OBJECT: 1924 case T_ARRAY: 1925 case T_BOOLEAN: 1926 case T_CHAR: 1927 case T_FLOAT: 1928 case T_BYTE: 1929 case T_SHORT: 1930 case T_INT: 1931 field_array[pos++] = get_const_type(type); 1932 break; 1933 case T_VALUETYPE: { 1934 assert(type->is_valuetype(), "inconsistent type"); 1935 if (vt_fields_as_args) { 1936 ciValueKlass* vk = (ciValueKlass*)type; 1937 collect_value_fields(vk, field_array, pos); 1938 } else { 1939 field_array[pos++] = get_const_type(type); 1940 } 1941 break; 1942 } 1943 default: 1944 ShouldNotReachHere(); 1945 } 1946 i++; 1947 } 1948 assert(pos == TypeFunc::Parms + arg_cnt + vt_extra, "wrong number of arguments"); 1949 1950 return (TypeTuple*)(new TypeTuple(TypeFunc::Parms + arg_cnt + vt_extra, field_array))->hashcons(); 1951 } 1952 1953 const TypeTuple *TypeTuple::make( uint cnt, const Type **fields ) { 1954 return (TypeTuple*)(new TypeTuple(cnt,fields))->hashcons(); 1955 } 1956 1957 //------------------------------fields----------------------------------------- 1958 // Subroutine call type with space allocated for argument types 1959 // Memory for Control, I_O, Memory, FramePtr, and ReturnAdr is allocated implicitly 1960 const Type **TypeTuple::fields( uint arg_cnt ) { 1961 const Type **flds = (const Type **)(Compile::current()->type_arena()->Amalloc_4((TypeFunc::Parms+arg_cnt)*sizeof(Type*) )); 1962 flds[TypeFunc::Control ] = Type::CONTROL; 1963 flds[TypeFunc::I_O ] = Type::ABIO; 1964 flds[TypeFunc::Memory ] = Type::MEMORY; 1965 flds[TypeFunc::FramePtr ] = TypeRawPtr::BOTTOM; 1966 flds[TypeFunc::ReturnAdr] = Type::RETURN_ADDRESS; 1967 1968 return flds; 1969 } 1970 1971 //------------------------------meet------------------------------------------- 1972 // Compute the MEET of two types. It returns a new Type object. 1973 const Type *TypeTuple::xmeet( const Type *t ) const { 1974 // Perform a fast test for common case; meeting the same types together. 1975 if( this == t ) return this; // Meeting same type-rep? 1976 1977 // Current "this->_base" is Tuple 1978 switch (t->base()) { // switch on original type 1979 1980 case Bottom: // Ye Olde Default 1981 return t; 1982 1983 default: // All else is a mistake 1984 typerr(t); 1985 1986 case Tuple: { // Meeting 2 signatures? 1987 const TypeTuple *x = t->is_tuple(); 1988 assert( _cnt == x->_cnt, "" ); 1989 const Type **fields = (const Type **)(Compile::current()->type_arena()->Amalloc_4( _cnt*sizeof(Type*) )); 1990 for( uint i=0; i<_cnt; i++ ) 1991 fields[i] = field_at(i)->xmeet( x->field_at(i) ); 1992 return TypeTuple::make(_cnt,fields); 1993 } 1994 case Top: 1995 break; 1996 } 1997 return this; // Return the double constant 1998 } 1999 2000 //------------------------------xdual------------------------------------------ 2001 // Dual: compute field-by-field dual 2002 const Type *TypeTuple::xdual() const { 2003 const Type **fields = (const Type **)(Compile::current()->type_arena()->Amalloc_4( _cnt*sizeof(Type*) )); 2004 for( uint i=0; i<_cnt; i++ ) 2005 fields[i] = _fields[i]->dual(); 2006 return new TypeTuple(_cnt,fields); 2007 } 2008 2009 //------------------------------eq--------------------------------------------- 2010 // Structural equality check for Type representations 2011 bool TypeTuple::eq( const Type *t ) const { 2012 const TypeTuple *s = (const TypeTuple *)t; 2013 if (_cnt != s->_cnt) return false; // Unequal field counts 2014 for (uint i = 0; i < _cnt; i++) 2015 if (field_at(i) != s->field_at(i)) // POINTER COMPARE! NO RECURSION! 2016 return false; // Missed 2017 return true; 2018 } 2019 2020 //------------------------------hash------------------------------------------- 2021 // Type-specific hashing function. 2022 int TypeTuple::hash(void) const { 2023 intptr_t sum = _cnt; 2024 for( uint i=0; i<_cnt; i++ ) 2025 sum += (intptr_t)_fields[i]; // Hash on pointers directly 2026 return sum; 2027 } 2028 2029 //------------------------------dump2------------------------------------------ 2030 // Dump signature Type 2031 #ifndef PRODUCT 2032 void TypeTuple::dump2( Dict &d, uint depth, outputStream *st ) const { 2033 st->print("{"); 2034 if( !depth || d[this] ) { // Check for recursive print 2035 st->print("...}"); 2036 return; 2037 } 2038 d.Insert((void*)this, (void*)this); // Stop recursion 2039 if( _cnt ) { 2040 uint i; 2041 for( i=0; i<_cnt-1; i++ ) { 2042 st->print("%d:", i); 2043 _fields[i]->dump2(d, depth-1, st); 2044 st->print(", "); 2045 } 2046 st->print("%d:", i); 2047 _fields[i]->dump2(d, depth-1, st); 2048 } 2049 st->print("}"); 2050 } 2051 #endif 2052 2053 //------------------------------singleton-------------------------------------- 2054 // TRUE if Type is a singleton type, FALSE otherwise. Singletons are simple 2055 // constants (Ldi nodes). Singletons are integer, float or double constants 2056 // or a single symbol. 2057 bool TypeTuple::singleton(void) const { 2058 return false; // Never a singleton 2059 } 2060 2061 bool TypeTuple::empty(void) const { 2062 for( uint i=0; i<_cnt; i++ ) { 2063 if (_fields[i]->empty()) return true; 2064 } 2065 return false; 2066 } 2067 2068 //============================================================================= 2069 // Convenience common pre-built types. 2070 2071 inline const TypeInt* normalize_array_size(const TypeInt* size) { 2072 // Certain normalizations keep us sane when comparing types. 2073 // We do not want arrayOop variables to differ only by the wideness 2074 // of their index types. Pick minimum wideness, since that is the 2075 // forced wideness of small ranges anyway. 2076 if (size->_widen != Type::WidenMin) 2077 return TypeInt::make(size->_lo, size->_hi, Type::WidenMin); 2078 else 2079 return size; 2080 } 2081 2082 //------------------------------make------------------------------------------- 2083 const TypeAry* TypeAry::make(const Type* elem, const TypeInt* size, bool stable) { 2084 if (UseCompressedOops && elem->isa_oopptr()) { 2085 elem = elem->make_narrowoop(); 2086 } 2087 size = normalize_array_size(size); 2088 return (TypeAry*)(new TypeAry(elem,size,stable))->hashcons(); 2089 } 2090 2091 //------------------------------meet------------------------------------------- 2092 // Compute the MEET of two types. It returns a new Type object. 2093 const Type *TypeAry::xmeet( const Type *t ) const { 2094 // Perform a fast test for common case; meeting the same types together. 2095 if( this == t ) return this; // Meeting same type-rep? 2096 2097 // Current "this->_base" is Ary 2098 switch (t->base()) { // switch on original type 2099 2100 case Bottom: // Ye Olde Default 2101 return t; 2102 2103 default: // All else is a mistake 2104 typerr(t); 2105 2106 case Array: { // Meeting 2 arrays? 2107 const TypeAry *a = t->is_ary(); 2108 return TypeAry::make(_elem->meet_speculative(a->_elem), 2109 _size->xmeet(a->_size)->is_int(), 2110 _stable & a->_stable); 2111 } 2112 case Top: 2113 break; 2114 } 2115 return this; // Return the double constant 2116 } 2117 2118 //------------------------------xdual------------------------------------------ 2119 // Dual: compute field-by-field dual 2120 const Type *TypeAry::xdual() const { 2121 const TypeInt* size_dual = _size->dual()->is_int(); 2122 size_dual = normalize_array_size(size_dual); 2123 return new TypeAry(_elem->dual(), size_dual, !_stable); 2124 } 2125 2126 //------------------------------eq--------------------------------------------- 2127 // Structural equality check for Type representations 2128 bool TypeAry::eq( const Type *t ) const { 2129 const TypeAry *a = (const TypeAry*)t; 2130 return _elem == a->_elem && 2131 _stable == a->_stable && 2132 _size == a->_size; 2133 } 2134 2135 //------------------------------hash------------------------------------------- 2136 // Type-specific hashing function. 2137 int TypeAry::hash(void) const { 2138 return (intptr_t)_elem + (intptr_t)_size + (_stable ? 43 : 0); 2139 } 2140 2141 /** 2142 * Return same type without a speculative part in the element 2143 */ 2144 const Type* TypeAry::remove_speculative() const { 2145 return make(_elem->remove_speculative(), _size, _stable); 2146 } 2147 2148 /** 2149 * Return same type with cleaned up speculative part of element 2150 */ 2151 const Type* TypeAry::cleanup_speculative() const { 2152 return make(_elem->cleanup_speculative(), _size, _stable); 2153 } 2154 2155 /** 2156 * Return same type but with a different inline depth (used for speculation) 2157 * 2158 * @param depth depth to meet with 2159 */ 2160 const TypePtr* TypePtr::with_inline_depth(int depth) const { 2161 if (!UseInlineDepthForSpeculativeTypes) { 2162 return this; 2163 } 2164 return make(AnyPtr, _ptr, _offset, _speculative, depth); 2165 } 2166 2167 //----------------------interface_vs_oop--------------------------------------- 2168 #ifdef ASSERT 2169 bool TypeAry::interface_vs_oop(const Type *t) const { 2170 const TypeAry* t_ary = t->is_ary(); 2171 if (t_ary) { 2172 const TypePtr* this_ptr = _elem->make_ptr(); // In case we have narrow_oops 2173 const TypePtr* t_ptr = t_ary->_elem->make_ptr(); 2174 if(this_ptr != NULL && t_ptr != NULL) { 2175 return this_ptr->interface_vs_oop(t_ptr); 2176 } 2177 } 2178 return false; 2179 } 2180 #endif 2181 2182 //------------------------------dump2------------------------------------------ 2183 #ifndef PRODUCT 2184 void TypeAry::dump2( Dict &d, uint depth, outputStream *st ) const { 2185 if (_stable) st->print("stable:"); 2186 _elem->dump2(d, depth, st); 2187 st->print("["); 2188 _size->dump2(d, depth, st); 2189 st->print("]"); 2190 } 2191 #endif 2192 2193 //------------------------------singleton-------------------------------------- 2194 // TRUE if Type is a singleton type, FALSE otherwise. Singletons are simple 2195 // constants (Ldi nodes). Singletons are integer, float or double constants 2196 // or a single symbol. 2197 bool TypeAry::singleton(void) const { 2198 return false; // Never a singleton 2199 } 2200 2201 bool TypeAry::empty(void) const { 2202 return _elem->empty() || _size->empty(); 2203 } 2204 2205 //--------------------------ary_must_be_exact---------------------------------- 2206 bool TypeAry::ary_must_be_exact() const { 2207 if (!UseExactTypes) return false; 2208 // This logic looks at the element type of an array, and returns true 2209 // if the element type is either a primitive or a final instance class. 2210 // In such cases, an array built on this ary must have no subclasses. 2211 if (_elem == BOTTOM) return false; // general array not exact 2212 if (_elem == TOP ) return false; // inverted general array not exact 2213 const TypeOopPtr* toop = NULL; 2214 if (UseCompressedOops && _elem->isa_narrowoop()) { 2215 toop = _elem->make_ptr()->isa_oopptr(); 2216 } else { 2217 toop = _elem->isa_oopptr(); 2218 } 2219 if (!toop) return true; // a primitive type, like int 2220 ciKlass* tklass = toop->klass(); 2221 if (tklass == NULL) return false; // unloaded class 2222 if (!tklass->is_loaded()) return false; // unloaded class 2223 const TypeInstPtr* tinst; 2224 if (_elem->isa_narrowoop()) 2225 tinst = _elem->make_ptr()->isa_instptr(); 2226 else 2227 tinst = _elem->isa_instptr(); 2228 if (tinst) 2229 return tklass->as_instance_klass()->is_final(); 2230 const TypeAryPtr* tap; 2231 if (_elem->isa_narrowoop()) 2232 tap = _elem->make_ptr()->isa_aryptr(); 2233 else 2234 tap = _elem->isa_aryptr(); 2235 if (tap) 2236 return tap->ary()->ary_must_be_exact(); 2237 return false; 2238 } 2239 2240 //==============================TypeValueType======================================= 2241 2242 //------------------------------make------------------------------------------- 2243 const TypeValueType* TypeValueType::make(ciValueKlass* vk) { 2244 return (TypeValueType*)(new TypeValueType(vk))->hashcons(); 2245 } 2246 2247 //------------------------------meet------------------------------------------- 2248 // Compute the MEET of two types. It returns a new Type object. 2249 const Type* TypeValueType::xmeet(const Type* t) const { 2250 // Perform a fast test for common case; meeting the same types together. 2251 if(this == t) return this; // Meeting same type-rep? 2252 2253 // Current "this->_base" is ValueType 2254 switch (t->base()) { // switch on original type 2255 2256 case Top: 2257 break; 2258 2259 case Bottom: 2260 return t; 2261 2262 default: // All else is a mistake 2263 typerr(t); 2264 2265 } 2266 return this; 2267 } 2268 2269 //------------------------------xdual------------------------------------------ 2270 const Type* TypeValueType::xdual() const { 2271 // FIXME 2272 return new TypeValueType(_vk); 2273 } 2274 2275 //------------------------------eq--------------------------------------------- 2276 // Structural equality check for Type representations 2277 bool TypeValueType::eq(const Type* t) const { 2278 const TypeValueType* vt = t->is_valuetype(); 2279 return (_vk == vt->value_klass()); 2280 } 2281 2282 //------------------------------hash------------------------------------------- 2283 // Type-specific hashing function. 2284 int TypeValueType::hash(void) const { 2285 return (intptr_t)_vk; 2286 } 2287 2288 //------------------------------singleton-------------------------------------- 2289 // TRUE if Type is a singleton type, FALSE otherwise. Singletons are simple constants. 2290 bool TypeValueType::singleton(void) const { 2291 // FIXME 2292 return false; 2293 } 2294 2295 //------------------------------empty------------------------------------------ 2296 // TRUE if Type is a type with no values, FALSE otherwise. 2297 bool TypeValueType::empty(void) const { 2298 // FIXME 2299 return false; 2300 } 2301 2302 //------------------------------dump2------------------------------------------ 2303 #ifndef PRODUCT 2304 void TypeValueType::dump2(Dict &d, uint depth, outputStream* st) const { 2305 st->print("valuetype[%d]:{", _vk->field_count()); 2306 st->print("%s", _vk->field_type_by_index(0)->name()); 2307 for (int i = 1; i < _vk->field_count(); ++i) { 2308 st->print(", %s", _vk->field_type_by_index(i)->name()); 2309 } 2310 st->print("}"); 2311 } 2312 #endif 2313 2314 //==============================TypeVect======================================= 2315 // Convenience common pre-built types. 2316 const TypeVect *TypeVect::VECTS = NULL; // 32-bit vectors 2317 const TypeVect *TypeVect::VECTD = NULL; // 64-bit vectors 2318 const TypeVect *TypeVect::VECTX = NULL; // 128-bit vectors 2319 const TypeVect *TypeVect::VECTY = NULL; // 256-bit vectors 2320 const TypeVect *TypeVect::VECTZ = NULL; // 512-bit vectors 2321 2322 //------------------------------make------------------------------------------- 2323 const TypeVect* TypeVect::make(const Type *elem, uint length) { 2324 BasicType elem_bt = elem->array_element_basic_type(); 2325 assert(is_java_primitive(elem_bt), "only primitive types in vector"); 2326 assert(length > 1 && is_power_of_2(length), "vector length is power of 2"); 2327 assert(Matcher::vector_size_supported(elem_bt, length), "length in range"); 2328 int size = length * type2aelembytes(elem_bt); 2329 switch (Matcher::vector_ideal_reg(size)) { 2330 case Op_VecS: 2331 return (TypeVect*)(new TypeVectS(elem, length))->hashcons(); 2332 case Op_RegL: 2333 case Op_VecD: 2334 case Op_RegD: 2335 return (TypeVect*)(new TypeVectD(elem, length))->hashcons(); 2336 case Op_VecX: 2337 return (TypeVect*)(new TypeVectX(elem, length))->hashcons(); 2338 case Op_VecY: 2339 return (TypeVect*)(new TypeVectY(elem, length))->hashcons(); 2340 case Op_VecZ: 2341 return (TypeVect*)(new TypeVectZ(elem, length))->hashcons(); 2342 } 2343 ShouldNotReachHere(); 2344 return NULL; 2345 } 2346 2347 //------------------------------meet------------------------------------------- 2348 // Compute the MEET of two types. It returns a new Type object. 2349 const Type *TypeVect::xmeet( const Type *t ) const { 2350 // Perform a fast test for common case; meeting the same types together. 2351 if( this == t ) return this; // Meeting same type-rep? 2352 2353 // Current "this->_base" is Vector 2354 switch (t->base()) { // switch on original type 2355 2356 case Bottom: // Ye Olde Default 2357 return t; 2358 2359 default: // All else is a mistake 2360 typerr(t); 2361 2362 case VectorS: 2363 case VectorD: 2364 case VectorX: 2365 case VectorY: 2366 case VectorZ: { // Meeting 2 vectors? 2367 const TypeVect* v = t->is_vect(); 2368 assert( base() == v->base(), ""); 2369 assert(length() == v->length(), ""); 2370 assert(element_basic_type() == v->element_basic_type(), ""); 2371 return TypeVect::make(_elem->xmeet(v->_elem), _length); 2372 } 2373 case Top: 2374 break; 2375 } 2376 return this; 2377 } 2378 2379 //------------------------------xdual------------------------------------------ 2380 // Dual: compute field-by-field dual 2381 const Type *TypeVect::xdual() const { 2382 return new TypeVect(base(), _elem->dual(), _length); 2383 } 2384 2385 //------------------------------eq--------------------------------------------- 2386 // Structural equality check for Type representations 2387 bool TypeVect::eq(const Type *t) const { 2388 const TypeVect *v = t->is_vect(); 2389 return (_elem == v->_elem) && (_length == v->_length); 2390 } 2391 2392 //------------------------------hash------------------------------------------- 2393 // Type-specific hashing function. 2394 int TypeVect::hash(void) const { 2395 return (intptr_t)_elem + (intptr_t)_length; 2396 } 2397 2398 //------------------------------singleton-------------------------------------- 2399 // TRUE if Type is a singleton type, FALSE otherwise. Singletons are simple 2400 // constants (Ldi nodes). Vector is singleton if all elements are the same 2401 // constant value (when vector is created with Replicate code). 2402 bool TypeVect::singleton(void) const { 2403 // There is no Con node for vectors yet. 2404 // return _elem->singleton(); 2405 return false; 2406 } 2407 2408 bool TypeVect::empty(void) const { 2409 return _elem->empty(); 2410 } 2411 2412 //------------------------------dump2------------------------------------------ 2413 #ifndef PRODUCT 2414 void TypeVect::dump2(Dict &d, uint depth, outputStream *st) const { 2415 switch (base()) { 2416 case VectorS: 2417 st->print("vectors["); break; 2418 case VectorD: 2419 st->print("vectord["); break; 2420 case VectorX: 2421 st->print("vectorx["); break; 2422 case VectorY: 2423 st->print("vectory["); break; 2424 case VectorZ: 2425 st->print("vectorz["); break; 2426 default: 2427 ShouldNotReachHere(); 2428 } 2429 st->print("%d]:{", _length); 2430 _elem->dump2(d, depth, st); 2431 st->print("}"); 2432 } 2433 #endif 2434 2435 2436 //============================================================================= 2437 // Convenience common pre-built types. 2438 const TypePtr *TypePtr::NULL_PTR; 2439 const TypePtr *TypePtr::NOTNULL; 2440 const TypePtr *TypePtr::BOTTOM; 2441 2442 //------------------------------meet------------------------------------------- 2443 // Meet over the PTR enum 2444 const TypePtr::PTR TypePtr::ptr_meet[TypePtr::lastPTR][TypePtr::lastPTR] = { 2445 // TopPTR, AnyNull, Constant, Null, NotNull, BotPTR, 2446 { /* Top */ TopPTR, AnyNull, Constant, Null, NotNull, BotPTR,}, 2447 { /* AnyNull */ AnyNull, AnyNull, Constant, BotPTR, NotNull, BotPTR,}, 2448 { /* Constant*/ Constant, Constant, Constant, BotPTR, NotNull, BotPTR,}, 2449 { /* Null */ Null, BotPTR, BotPTR, Null, BotPTR, BotPTR,}, 2450 { /* NotNull */ NotNull, NotNull, NotNull, BotPTR, NotNull, BotPTR,}, 2451 { /* BotPTR */ BotPTR, BotPTR, BotPTR, BotPTR, BotPTR, BotPTR,} 2452 }; 2453 2454 //------------------------------make------------------------------------------- 2455 const TypePtr* TypePtr::make(TYPES t, enum PTR ptr, Offset offset, const TypePtr* speculative, int inline_depth) { 2456 return (TypePtr*)(new TypePtr(t,ptr,offset, speculative, inline_depth))->hashcons(); 2457 } 2458 2459 //------------------------------cast_to_ptr_type------------------------------- 2460 const Type *TypePtr::cast_to_ptr_type(PTR ptr) const { 2461 assert(_base == AnyPtr, "subclass must override cast_to_ptr_type"); 2462 if( ptr == _ptr ) return this; 2463 return make(_base, ptr, _offset, _speculative, _inline_depth); 2464 } 2465 2466 //------------------------------get_con---------------------------------------- 2467 intptr_t TypePtr::get_con() const { 2468 assert( _ptr == Null, "" ); 2469 return offset(); 2470 } 2471 2472 //------------------------------meet------------------------------------------- 2473 // Compute the MEET of two types. It returns a new Type object. 2474 const Type *TypePtr::xmeet(const Type *t) const { 2475 const Type* res = xmeet_helper(t); 2476 if (res->isa_ptr() == NULL) { 2477 return res; 2478 } 2479 2480 const TypePtr* res_ptr = res->is_ptr(); 2481 if (res_ptr->speculative() != NULL) { 2482 // type->speculative() == NULL means that speculation is no better 2483 // than type, i.e. type->speculative() == type. So there are 2 2484 // ways to represent the fact that we have no useful speculative 2485 // data and we should use a single one to be able to test for 2486 // equality between types. Check whether type->speculative() == 2487 // type and set speculative to NULL if it is the case. 2488 if (res_ptr->remove_speculative() == res_ptr->speculative()) { 2489 return res_ptr->remove_speculative(); 2490 } 2491 } 2492 2493 return res; 2494 } 2495 2496 const Type *TypePtr::xmeet_helper(const Type *t) const { 2497 // Perform a fast test for common case; meeting the same types together. 2498 if( this == t ) return this; // Meeting same type-rep? 2499 2500 // Current "this->_base" is AnyPtr 2501 switch (t->base()) { // switch on original type 2502 case Int: // Mixing ints & oops happens when javac 2503 case Long: // reuses local variables 2504 case FloatTop: 2505 case FloatCon: 2506 case FloatBot: 2507 case DoubleTop: 2508 case DoubleCon: 2509 case DoubleBot: 2510 case NarrowOop: 2511 case NarrowKlass: 2512 case Bottom: // Ye Olde Default 2513 return Type::BOTTOM; 2514 case Top: 2515 return this; 2516 2517 case AnyPtr: { // Meeting to AnyPtrs 2518 const TypePtr *tp = t->is_ptr(); 2519 const TypePtr* speculative = xmeet_speculative(tp); 2520 int depth = meet_inline_depth(tp->inline_depth()); 2521 return make(AnyPtr, meet_ptr(tp->ptr()), meet_offset(tp->offset()), speculative, depth); 2522 } 2523 case RawPtr: // For these, flip the call around to cut down 2524 case OopPtr: 2525 case InstPtr: // on the cases I have to handle. 2526 case ValueTypePtr: 2527 case AryPtr: 2528 case MetadataPtr: 2529 case KlassPtr: 2530 return t->xmeet(this); // Call in reverse direction 2531 default: // All else is a mistake 2532 typerr(t); 2533 2534 } 2535 return this; 2536 } 2537 2538 //------------------------------meet_offset------------------------------------ 2539 Type::Offset TypePtr::meet_offset(int offset) const { 2540 return _offset.meet(Offset(offset)); 2541 } 2542 2543 //------------------------------dual_offset------------------------------------ 2544 Type::Offset TypePtr::dual_offset() const { 2545 return _offset.dual(); 2546 } 2547 2548 //------------------------------xdual------------------------------------------ 2549 // Dual: compute field-by-field dual 2550 const TypePtr::PTR TypePtr::ptr_dual[TypePtr::lastPTR] = { 2551 BotPTR, NotNull, Constant, Null, AnyNull, TopPTR 2552 }; 2553 const Type *TypePtr::xdual() const { 2554 return new TypePtr(AnyPtr, dual_ptr(), dual_offset(), dual_speculative(), dual_inline_depth()); 2555 } 2556 2557 //------------------------------xadd_offset------------------------------------ 2558 Type::Offset TypePtr::xadd_offset(intptr_t offset) const { 2559 return _offset.add(offset); 2560 } 2561 2562 //------------------------------add_offset------------------------------------- 2563 const TypePtr *TypePtr::add_offset( intptr_t offset ) const { 2564 return make(AnyPtr, _ptr, xadd_offset(offset), _speculative, _inline_depth); 2565 } 2566 2567 //------------------------------eq--------------------------------------------- 2568 // Structural equality check for Type representations 2569 bool TypePtr::eq( const Type *t ) const { 2570 const TypePtr *a = (const TypePtr*)t; 2571 return _ptr == a->ptr() && _offset == a->_offset && eq_speculative(a) && _inline_depth == a->_inline_depth; 2572 } 2573 2574 //------------------------------hash------------------------------------------- 2575 // Type-specific hashing function. 2576 int TypePtr::hash(void) const { 2577 return java_add(java_add(_ptr, offset()), java_add( hash_speculative(), _inline_depth)); 2578 ; 2579 } 2580 2581 /** 2582 * Return same type without a speculative part 2583 */ 2584 const Type* TypePtr::remove_speculative() const { 2585 if (_speculative == NULL) { 2586 return this; 2587 } 2588 assert(_inline_depth == InlineDepthTop || _inline_depth == InlineDepthBottom, "non speculative type shouldn't have inline depth"); 2589 return make(AnyPtr, _ptr, _offset, NULL, _inline_depth); 2590 } 2591 2592 /** 2593 * Return same type but drop speculative part if we know we won't use 2594 * it 2595 */ 2596 const Type* TypePtr::cleanup_speculative() const { 2597 if (speculative() == NULL) { 2598 return this; 2599 } 2600 const Type* no_spec = remove_speculative(); 2601 // If this is NULL_PTR then we don't need the speculative type 2602 // (with_inline_depth in case the current type inline depth is 2603 // InlineDepthTop) 2604 if (no_spec == NULL_PTR->with_inline_depth(inline_depth())) { 2605 return no_spec; 2606 } 2607 if (above_centerline(speculative()->ptr())) { 2608 return no_spec; 2609 } 2610 const TypeOopPtr* spec_oopptr = speculative()->isa_oopptr(); 2611 // If the speculative may be null and is an inexact klass then it 2612 // doesn't help 2613 if (speculative()->maybe_null() && (spec_oopptr == NULL || !spec_oopptr->klass_is_exact())) { 2614 return no_spec; 2615 } 2616 return this; 2617 } 2618 2619 /** 2620 * dual of the speculative part of the type 2621 */ 2622 const TypePtr* TypePtr::dual_speculative() const { 2623 if (_speculative == NULL) { 2624 return NULL; 2625 } 2626 return _speculative->dual()->is_ptr(); 2627 } 2628 2629 /** 2630 * meet of the speculative parts of 2 types 2631 * 2632 * @param other type to meet with 2633 */ 2634 const TypePtr* TypePtr::xmeet_speculative(const TypePtr* other) const { 2635 bool this_has_spec = (_speculative != NULL); 2636 bool other_has_spec = (other->speculative() != NULL); 2637 2638 if (!this_has_spec && !other_has_spec) { 2639 return NULL; 2640 } 2641 2642 // If we are at a point where control flow meets and one branch has 2643 // a speculative type and the other has not, we meet the speculative 2644 // type of one branch with the actual type of the other. If the 2645 // actual type is exact and the speculative is as well, then the 2646 // result is a speculative type which is exact and we can continue 2647 // speculation further. 2648 const TypePtr* this_spec = _speculative; 2649 const TypePtr* other_spec = other->speculative(); 2650 2651 if (!this_has_spec) { 2652 this_spec = this; 2653 } 2654 2655 if (!other_has_spec) { 2656 other_spec = other; 2657 } 2658 2659 return this_spec->meet(other_spec)->is_ptr(); 2660 } 2661 2662 /** 2663 * dual of the inline depth for this type (used for speculation) 2664 */ 2665 int TypePtr::dual_inline_depth() const { 2666 return -inline_depth(); 2667 } 2668 2669 /** 2670 * meet of 2 inline depths (used for speculation) 2671 * 2672 * @param depth depth to meet with 2673 */ 2674 int TypePtr::meet_inline_depth(int depth) const { 2675 return MAX2(inline_depth(), depth); 2676 } 2677 2678 /** 2679 * Are the speculative parts of 2 types equal? 2680 * 2681 * @param other type to compare this one to 2682 */ 2683 bool TypePtr::eq_speculative(const TypePtr* other) const { 2684 if (_speculative == NULL || other->speculative() == NULL) { 2685 return _speculative == other->speculative(); 2686 } 2687 2688 if (_speculative->base() != other->speculative()->base()) { 2689 return false; 2690 } 2691 2692 return _speculative->eq(other->speculative()); 2693 } 2694 2695 /** 2696 * Hash of the speculative part of the type 2697 */ 2698 int TypePtr::hash_speculative() const { 2699 if (_speculative == NULL) { 2700 return 0; 2701 } 2702 2703 return _speculative->hash(); 2704 } 2705 2706 /** 2707 * add offset to the speculative part of the type 2708 * 2709 * @param offset offset to add 2710 */ 2711 const TypePtr* TypePtr::add_offset_speculative(intptr_t offset) const { 2712 if (_speculative == NULL) { 2713 return NULL; 2714 } 2715 return _speculative->add_offset(offset)->is_ptr(); 2716 } 2717 2718 /** 2719 * return exact klass from the speculative type if there's one 2720 */ 2721 ciKlass* TypePtr::speculative_type() const { 2722 if (_speculative != NULL && _speculative->isa_oopptr()) { 2723 const TypeOopPtr* speculative = _speculative->join(this)->is_oopptr(); 2724 if (speculative->klass_is_exact()) { 2725 return speculative->klass(); 2726 } 2727 } 2728 return NULL; 2729 } 2730 2731 /** 2732 * return true if speculative type may be null 2733 */ 2734 bool TypePtr::speculative_maybe_null() const { 2735 if (_speculative != NULL) { 2736 const TypePtr* speculative = _speculative->join(this)->is_ptr(); 2737 return speculative->maybe_null(); 2738 } 2739 return true; 2740 } 2741 2742 /** 2743 * Same as TypePtr::speculative_type() but return the klass only if 2744 * the speculative tells us is not null 2745 */ 2746 ciKlass* TypePtr::speculative_type_not_null() const { 2747 if (speculative_maybe_null()) { 2748 return NULL; 2749 } 2750 return speculative_type(); 2751 } 2752 2753 /** 2754 * Check whether new profiling would improve speculative type 2755 * 2756 * @param exact_kls class from profiling 2757 * @param inline_depth inlining depth of profile point 2758 * 2759 * @return true if type profile is valuable 2760 */ 2761 bool TypePtr::would_improve_type(ciKlass* exact_kls, int inline_depth) const { 2762 // no profiling? 2763 if (exact_kls == NULL) { 2764 return false; 2765 } 2766 // no speculative type or non exact speculative type? 2767 if (speculative_type() == NULL) { 2768 return true; 2769 } 2770 // If the node already has an exact speculative type keep it, 2771 // unless it was provided by profiling that is at a deeper 2772 // inlining level. Profiling at a higher inlining depth is 2773 // expected to be less accurate. 2774 if (_speculative->inline_depth() == InlineDepthBottom) { 2775 return false; 2776 } 2777 assert(_speculative->inline_depth() != InlineDepthTop, "can't do the comparison"); 2778 return inline_depth < _speculative->inline_depth(); 2779 } 2780 2781 /** 2782 * Check whether new profiling would improve ptr (= tells us it is non 2783 * null) 2784 * 2785 * @param maybe_null true if profiling tells the ptr may be null 2786 * 2787 * @return true if ptr profile is valuable 2788 */ 2789 bool TypePtr::would_improve_ptr(bool maybe_null) const { 2790 // profiling doesn't tell us anything useful 2791 if (maybe_null) { 2792 return false; 2793 } 2794 // We already know this is not be null 2795 if (!this->maybe_null()) { 2796 return false; 2797 } 2798 // We already know the speculative type cannot be null 2799 if (!speculative_maybe_null()) { 2800 return false; 2801 } 2802 return true; 2803 } 2804 2805 //------------------------------dump2------------------------------------------ 2806 const char *const TypePtr::ptr_msg[TypePtr::lastPTR] = { 2807 "TopPTR","AnyNull","Constant","NULL","NotNull","BotPTR" 2808 }; 2809 2810 #ifndef PRODUCT 2811 void TypePtr::dump2( Dict &d, uint depth, outputStream *st ) const { 2812 if( _ptr == Null ) st->print("NULL"); 2813 else st->print("%s *", ptr_msg[_ptr]); 2814 _offset.dump2(st); 2815 dump_inline_depth(st); 2816 dump_speculative(st); 2817 } 2818 2819 /** 2820 *dump the speculative part of the type 2821 */ 2822 void TypePtr::dump_speculative(outputStream *st) const { 2823 if (_speculative != NULL) { 2824 st->print(" (speculative="); 2825 _speculative->dump_on(st); 2826 st->print(")"); 2827 } 2828 } 2829 2830 /** 2831 *dump the inline depth of the type 2832 */ 2833 void TypePtr::dump_inline_depth(outputStream *st) const { 2834 if (_inline_depth != InlineDepthBottom) { 2835 if (_inline_depth == InlineDepthTop) { 2836 st->print(" (inline_depth=InlineDepthTop)"); 2837 } else { 2838 st->print(" (inline_depth=%d)", _inline_depth); 2839 } 2840 } 2841 } 2842 #endif 2843 2844 //------------------------------singleton-------------------------------------- 2845 // TRUE if Type is a singleton type, FALSE otherwise. Singletons are simple 2846 // constants 2847 bool TypePtr::singleton(void) const { 2848 // TopPTR, Null, AnyNull, Constant are all singletons 2849 return (_offset != Offset::bottom) && !below_centerline(_ptr); 2850 } 2851 2852 bool TypePtr::empty(void) const { 2853 return (_offset == Offset::top) || above_centerline(_ptr); 2854 } 2855 2856 //============================================================================= 2857 // Convenience common pre-built types. 2858 const TypeRawPtr *TypeRawPtr::BOTTOM; 2859 const TypeRawPtr *TypeRawPtr::NOTNULL; 2860 2861 //------------------------------make------------------------------------------- 2862 const TypeRawPtr *TypeRawPtr::make( enum PTR ptr ) { 2863 assert( ptr != Constant, "what is the constant?" ); 2864 assert( ptr != Null, "Use TypePtr for NULL" ); 2865 return (TypeRawPtr*)(new TypeRawPtr(ptr,0))->hashcons(); 2866 } 2867 2868 const TypeRawPtr *TypeRawPtr::make( address bits ) { 2869 assert( bits, "Use TypePtr for NULL" ); 2870 return (TypeRawPtr*)(new TypeRawPtr(Constant,bits))->hashcons(); 2871 } 2872 2873 //------------------------------cast_to_ptr_type------------------------------- 2874 const Type *TypeRawPtr::cast_to_ptr_type(PTR ptr) const { 2875 assert( ptr != Constant, "what is the constant?" ); 2876 assert( ptr != Null, "Use TypePtr for NULL" ); 2877 assert( _bits==0, "Why cast a constant address?"); 2878 if( ptr == _ptr ) return this; 2879 return make(ptr); 2880 } 2881 2882 //------------------------------get_con---------------------------------------- 2883 intptr_t TypeRawPtr::get_con() const { 2884 assert( _ptr == Null || _ptr == Constant, "" ); 2885 return (intptr_t)_bits; 2886 } 2887 2888 //------------------------------meet------------------------------------------- 2889 // Compute the MEET of two types. It returns a new Type object. 2890 const Type *TypeRawPtr::xmeet( const Type *t ) const { 2891 // Perform a fast test for common case; meeting the same types together. 2892 if( this == t ) return this; // Meeting same type-rep? 2893 2894 // Current "this->_base" is RawPtr 2895 switch( t->base() ) { // switch on original type 2896 case Bottom: // Ye Olde Default 2897 return t; 2898 case Top: 2899 return this; 2900 case AnyPtr: // Meeting to AnyPtrs 2901 break; 2902 case RawPtr: { // might be top, bot, any/not or constant 2903 enum PTR tptr = t->is_ptr()->ptr(); 2904 enum PTR ptr = meet_ptr( tptr ); 2905 if( ptr == Constant ) { // Cannot be equal constants, so... 2906 if( tptr == Constant && _ptr != Constant) return t; 2907 if( _ptr == Constant && tptr != Constant) return this; 2908 ptr = NotNull; // Fall down in lattice 2909 } 2910 return make( ptr ); 2911 } 2912 2913 case OopPtr: 2914 case InstPtr: 2915 case ValueTypePtr: 2916 case AryPtr: 2917 case MetadataPtr: 2918 case KlassPtr: 2919 return TypePtr::BOTTOM; // Oop meet raw is not well defined 2920 default: // All else is a mistake 2921 typerr(t); 2922 } 2923 2924 // Found an AnyPtr type vs self-RawPtr type 2925 const TypePtr *tp = t->is_ptr(); 2926 switch (tp->ptr()) { 2927 case TypePtr::TopPTR: return this; 2928 case TypePtr::BotPTR: return t; 2929 case TypePtr::Null: 2930 if( _ptr == TypePtr::TopPTR ) return t; 2931 return TypeRawPtr::BOTTOM; 2932 case TypePtr::NotNull: return TypePtr::make(AnyPtr, meet_ptr(TypePtr::NotNull), tp->meet_offset(0), tp->speculative(), tp->inline_depth()); 2933 case TypePtr::AnyNull: 2934 if( _ptr == TypePtr::Constant) return this; 2935 return make( meet_ptr(TypePtr::AnyNull) ); 2936 default: ShouldNotReachHere(); 2937 } 2938 return this; 2939 } 2940 2941 //------------------------------xdual------------------------------------------ 2942 // Dual: compute field-by-field dual 2943 const Type *TypeRawPtr::xdual() const { 2944 return new TypeRawPtr( dual_ptr(), _bits ); 2945 } 2946 2947 //------------------------------add_offset------------------------------------- 2948 const TypePtr *TypeRawPtr::add_offset( intptr_t offset ) const { 2949 if( offset == OffsetTop ) return BOTTOM; // Undefined offset-> undefined pointer 2950 if( offset == OffsetBot ) return BOTTOM; // Unknown offset-> unknown pointer 2951 if( offset == 0 ) return this; // No change 2952 switch (_ptr) { 2953 case TypePtr::TopPTR: 2954 case TypePtr::BotPTR: 2955 case TypePtr::NotNull: 2956 return this; 2957 case TypePtr::Null: 2958 case TypePtr::Constant: { 2959 address bits = _bits+offset; 2960 if ( bits == 0 ) return TypePtr::NULL_PTR; 2961 return make( bits ); 2962 } 2963 default: ShouldNotReachHere(); 2964 } 2965 return NULL; // Lint noise 2966 } 2967 2968 //------------------------------eq--------------------------------------------- 2969 // Structural equality check for Type representations 2970 bool TypeRawPtr::eq( const Type *t ) const { 2971 const TypeRawPtr *a = (const TypeRawPtr*)t; 2972 return _bits == a->_bits && TypePtr::eq(t); 2973 } 2974 2975 //------------------------------hash------------------------------------------- 2976 // Type-specific hashing function. 2977 int TypeRawPtr::hash(void) const { 2978 return (intptr_t)_bits + TypePtr::hash(); 2979 } 2980 2981 //------------------------------dump2------------------------------------------ 2982 #ifndef PRODUCT 2983 void TypeRawPtr::dump2( Dict &d, uint depth, outputStream *st ) const { 2984 if( _ptr == Constant ) 2985 st->print(INTPTR_FORMAT, p2i(_bits)); 2986 else 2987 st->print("rawptr:%s", ptr_msg[_ptr]); 2988 } 2989 #endif 2990 2991 //============================================================================= 2992 // Convenience common pre-built type. 2993 const TypeOopPtr *TypeOopPtr::BOTTOM; 2994 2995 //------------------------------TypeOopPtr------------------------------------- 2996 TypeOopPtr::TypeOopPtr(TYPES t, PTR ptr, ciKlass* k, bool xk, ciObject* o, Offset offset, 2997 int instance_id, const TypePtr* speculative, int inline_depth) 2998 : TypePtr(t, ptr, offset, speculative, inline_depth), 2999 _const_oop(o), _klass(k), 3000 _klass_is_exact(xk), 3001 _is_ptr_to_narrowoop(false), 3002 _is_ptr_to_narrowklass(false), 3003 _is_ptr_to_boxed_value(false), 3004 _instance_id(instance_id) { 3005 if (Compile::current()->eliminate_boxing() && (t == InstPtr) && 3006 (offset.get() > 0) && xk && (k != 0) && k->is_instance_klass()) { 3007 _is_ptr_to_boxed_value = k->as_instance_klass()->is_boxed_value_offset(offset.get()); 3008 } 3009 #ifdef _LP64 3010 if (this->offset() != 0) { 3011 if (this->offset() == oopDesc::klass_offset_in_bytes()) { 3012 _is_ptr_to_narrowklass = UseCompressedClassPointers; 3013 } else if (klass() == NULL) { 3014 // Array with unknown body type 3015 assert(this->isa_aryptr(), "only arrays without klass"); 3016 _is_ptr_to_narrowoop = UseCompressedOops; 3017 } else if (this->isa_aryptr()) { 3018 _is_ptr_to_narrowoop = (UseCompressedOops && klass()->is_obj_array_klass() && 3019 this->offset() != arrayOopDesc::length_offset_in_bytes()); 3020 } else if (klass()->is_instance_klass()) { 3021 ciInstanceKlass* ik = klass()->as_instance_klass(); 3022 ciField* field = NULL; 3023 if (this->isa_klassptr()) { 3024 // Perm objects don't use compressed references 3025 } else if (_offset == Offset::bottom || _offset == Offset::top) { 3026 // unsafe access 3027 _is_ptr_to_narrowoop = UseCompressedOops; 3028 } else { // exclude unsafe ops 3029 assert(this->isa_instptr() || this->isa_valuetypeptr(), "must be an instance ptr."); 3030 3031 if (klass() == ciEnv::current()->Class_klass() && 3032 (this->offset() == java_lang_Class::klass_offset_in_bytes() || 3033 this->offset() == java_lang_Class::array_klass_offset_in_bytes())) { 3034 // Special hidden fields from the Class. 3035 assert(this->isa_instptr(), "must be an instance ptr."); 3036 _is_ptr_to_narrowoop = false; 3037 } else if (klass() == ciEnv::current()->Class_klass() && 3038 this->offset() >= InstanceMirrorKlass::offset_of_static_fields()) { 3039 // Static fields 3040 assert(o != NULL, "must be constant"); 3041 ciInstanceKlass* k = o->as_instance()->java_lang_Class_klass()->as_instance_klass(); 3042 ciField* field = k->get_field_by_offset(this->offset(), true); 3043 assert(field != NULL, "missing field"); 3044 BasicType basic_elem_type = field->layout_type(); 3045 _is_ptr_to_narrowoop = UseCompressedOops && (basic_elem_type == T_OBJECT || 3046 basic_elem_type == T_ARRAY); 3047 } else { 3048 // Instance fields which contains a compressed oop references. 3049 field = ik->get_field_by_offset(this->offset(), false); 3050 if (field != NULL) { 3051 BasicType basic_elem_type = field->layout_type(); 3052 _is_ptr_to_narrowoop = UseCompressedOops && (basic_elem_type == T_OBJECT || 3053 basic_elem_type == T_ARRAY); 3054 } else if (klass()->equals(ciEnv::current()->Object_klass())) { 3055 // Compile::find_alias_type() cast exactness on all types to verify 3056 // that it does not affect alias type. 3057 _is_ptr_to_narrowoop = UseCompressedOops; 3058 } else { 3059 // Type for the copy start in LibraryCallKit::inline_native_clone(). 3060 _is_ptr_to_narrowoop = UseCompressedOops; 3061 } 3062 } 3063 } 3064 } 3065 } 3066 #endif 3067 } 3068 3069 //------------------------------make------------------------------------------- 3070 const TypeOopPtr *TypeOopPtr::make(PTR ptr, Offset offset, int instance_id, 3071 const TypePtr* speculative, int inline_depth) { 3072 assert(ptr != Constant, "no constant generic pointers"); 3073 ciKlass* k = Compile::current()->env()->Object_klass(); 3074 bool xk = false; 3075 ciObject* o = NULL; 3076 return (TypeOopPtr*)(new TypeOopPtr(OopPtr, ptr, k, xk, o, offset, instance_id, speculative, inline_depth))->hashcons(); 3077 } 3078 3079 3080 //------------------------------cast_to_ptr_type------------------------------- 3081 const Type *TypeOopPtr::cast_to_ptr_type(PTR ptr) const { 3082 assert(_base == OopPtr, "subclass must override cast_to_ptr_type"); 3083 if( ptr == _ptr ) return this; 3084 return make(ptr, _offset, _instance_id, _speculative, _inline_depth); 3085 } 3086 3087 //-----------------------------cast_to_instance_id---------------------------- 3088 const TypeOopPtr *TypeOopPtr::cast_to_instance_id(int instance_id) const { 3089 // There are no instances of a general oop. 3090 // Return self unchanged. 3091 return this; 3092 } 3093 3094 //-----------------------------cast_to_exactness------------------------------- 3095 const Type *TypeOopPtr::cast_to_exactness(bool klass_is_exact) const { 3096 // There is no such thing as an exact general oop. 3097 // Return self unchanged. 3098 return this; 3099 } 3100 3101 3102 //------------------------------as_klass_type---------------------------------- 3103 // Return the klass type corresponding to this instance or array type. 3104 // It is the type that is loaded from an object of this type. 3105 const TypeKlassPtr* TypeOopPtr::as_klass_type() const { 3106 ciKlass* k = klass(); 3107 bool xk = klass_is_exact(); 3108 if (k == NULL) 3109 return TypeKlassPtr::OBJECT; 3110 else 3111 return TypeKlassPtr::make(xk? Constant: NotNull, k, Offset(0)); 3112 } 3113 3114 //------------------------------meet------------------------------------------- 3115 // Compute the MEET of two types. It returns a new Type object. 3116 const Type *TypeOopPtr::xmeet_helper(const Type *t) const { 3117 // Perform a fast test for common case; meeting the same types together. 3118 if( this == t ) return this; // Meeting same type-rep? 3119 3120 // Current "this->_base" is OopPtr 3121 switch (t->base()) { // switch on original type 3122 3123 case Int: // Mixing ints & oops happens when javac 3124 case Long: // reuses local variables 3125 case FloatTop: 3126 case FloatCon: 3127 case FloatBot: 3128 case DoubleTop: 3129 case DoubleCon: 3130 case DoubleBot: 3131 case NarrowOop: 3132 case NarrowKlass: 3133 case Bottom: // Ye Olde Default 3134 return Type::BOTTOM; 3135 case Top: 3136 return this; 3137 3138 default: // All else is a mistake 3139 typerr(t); 3140 3141 case RawPtr: 3142 case MetadataPtr: 3143 case KlassPtr: 3144 return TypePtr::BOTTOM; // Oop meet raw is not well defined 3145 3146 case AnyPtr: { 3147 // Found an AnyPtr type vs self-OopPtr type 3148 const TypePtr *tp = t->is_ptr(); 3149 Offset offset = meet_offset(tp->offset()); 3150 PTR ptr = meet_ptr(tp->ptr()); 3151 const TypePtr* speculative = xmeet_speculative(tp); 3152 int depth = meet_inline_depth(tp->inline_depth()); 3153 switch (tp->ptr()) { 3154 case Null: 3155 if (ptr == Null) return TypePtr::make(AnyPtr, ptr, offset, speculative, depth); 3156 // else fall through: 3157 case TopPTR: 3158 case AnyNull: { 3159 int instance_id = meet_instance_id(InstanceTop); 3160 return make(ptr, offset, instance_id, speculative, depth); 3161 } 3162 case BotPTR: 3163 case NotNull: 3164 return TypePtr::make(AnyPtr, ptr, offset, speculative, depth); 3165 default: typerr(t); 3166 } 3167 } 3168 3169 case OopPtr: { // Meeting to other OopPtrs 3170 const TypeOopPtr *tp = t->is_oopptr(); 3171 int instance_id = meet_instance_id(tp->instance_id()); 3172 const TypePtr* speculative = xmeet_speculative(tp); 3173 int depth = meet_inline_depth(tp->inline_depth()); 3174 return make(meet_ptr(tp->ptr()), meet_offset(tp->offset()), instance_id, speculative, depth); 3175 } 3176 3177 case InstPtr: // For these, flip the call around to cut down 3178 case ValueTypePtr: 3179 case AryPtr: 3180 return t->xmeet(this); // Call in reverse direction 3181 3182 } // End of switch 3183 return this; // Return the double constant 3184 } 3185 3186 3187 //------------------------------xdual------------------------------------------ 3188 // Dual of a pure heap pointer. No relevant klass or oop information. 3189 const Type *TypeOopPtr::xdual() const { 3190 assert(klass() == Compile::current()->env()->Object_klass(), "no klasses here"); 3191 assert(const_oop() == NULL, "no constants here"); 3192 return new TypeOopPtr(_base, dual_ptr(), klass(), klass_is_exact(), const_oop(), dual_offset(), dual_instance_id(), dual_speculative(), dual_inline_depth()); 3193 } 3194 3195 //--------------------------make_from_klass_common----------------------------- 3196 // Computes the element-type given a klass. 3197 const TypeOopPtr* TypeOopPtr::make_from_klass_common(ciKlass *klass, bool klass_change, bool try_for_exact) { 3198 if (klass->is_valuetype()) { 3199 return TypeValueTypePtr::make(TypePtr::NotNull, klass->as_value_klass()); 3200 } else if (klass->is_instance_klass()) { 3201 Compile* C = Compile::current(); 3202 Dependencies* deps = C->dependencies(); 3203 assert((deps != NULL) == (C->method() != NULL && C->method()->code_size() > 0), "sanity"); 3204 // Element is an instance 3205 bool klass_is_exact = false; 3206 if (klass->is_loaded()) { 3207 // Try to set klass_is_exact. 3208 ciInstanceKlass* ik = klass->as_instance_klass(); 3209 klass_is_exact = ik->is_final(); 3210 if (!klass_is_exact && klass_change 3211 && deps != NULL && UseUniqueSubclasses) { 3212 ciInstanceKlass* sub = ik->unique_concrete_subklass(); 3213 if (sub != NULL) { 3214 deps->assert_abstract_with_unique_concrete_subtype(ik, sub); 3215 klass = ik = sub; 3216 klass_is_exact = sub->is_final(); 3217 } 3218 } 3219 if (!klass_is_exact && try_for_exact 3220 && deps != NULL && UseExactTypes) { 3221 if (!ik->is_interface() && !ik->has_subklass()) { 3222 // Add a dependence; if concrete subclass added we need to recompile 3223 deps->assert_leaf_type(ik); 3224 klass_is_exact = true; 3225 } 3226 } 3227 } 3228 return TypeInstPtr::make(TypePtr::BotPTR, klass, klass_is_exact, NULL, Offset(0)); 3229 } else if (klass->is_obj_array_klass()) { 3230 // Element is an object or value array. Recursively call ourself. 3231 const TypeOopPtr* etype = TypeOopPtr::make_from_klass_common(klass->as_array_klass()->element_klass(), false, try_for_exact); 3232 bool xk = etype->klass_is_exact(); 3233 const TypeAry* arr0 = TypeAry::make(etype, TypeInt::POS); 3234 // We used to pass NotNull in here, asserting that the sub-arrays 3235 // are all not-null. This is not true in generally, as code can 3236 // slam NULLs down in the subarrays. 3237 const TypeAryPtr* arr = TypeAryPtr::make(TypePtr::BotPTR, arr0, klass, xk, Offset(0)); 3238 return arr; 3239 } else if (klass->is_type_array_klass()) { 3240 // Element is an typeArray 3241 const Type* etype = get_const_basic_type(klass->as_type_array_klass()->element_type()); 3242 const TypeAry* arr0 = TypeAry::make(etype, TypeInt::POS); 3243 // We used to pass NotNull in here, asserting that the array pointer 3244 // is not-null. That was not true in general. 3245 const TypeAryPtr* arr = TypeAryPtr::make(TypePtr::BotPTR, arr0, klass, true, Offset(0)); 3246 return arr; 3247 } else if (klass->is_value_array_klass()) { 3248 ciValueKlass* vk = klass->as_array_klass()->element_klass()->as_value_klass(); 3249 const Type* etype = NULL; 3250 bool xk = false; 3251 if (vk->flatten_array()) { 3252 etype = TypeValueType::make(vk); 3253 xk = true; 3254 } else { 3255 const TypeOopPtr* etype_oop = TypeOopPtr::make_from_klass_common(vk, false, try_for_exact); 3256 xk = etype_oop->klass_is_exact(); 3257 etype = etype_oop; 3258 } 3259 const TypeAry* arr0 = TypeAry::make(etype, TypeInt::POS); 3260 const TypeAryPtr* arr = TypeAryPtr::make(TypePtr::BotPTR, arr0, klass, xk, Offset(0)); 3261 return arr; 3262 } else { 3263 ShouldNotReachHere(); 3264 return NULL; 3265 } 3266 } 3267 3268 //------------------------------make_from_constant----------------------------- 3269 // Make a java pointer from an oop constant 3270 const TypeOopPtr* TypeOopPtr::make_from_constant(ciObject* o, bool require_constant) { 3271 assert(!o->is_null_object(), "null object not yet handled here."); 3272 ciKlass* klass = o->klass(); 3273 if (klass->is_valuetype()) { 3274 // Element is a value type 3275 if (require_constant) { 3276 if (!o->can_be_constant()) return NULL; 3277 } else if (!o->should_be_constant()) { 3278 return TypeValueTypePtr::make(TypePtr::NotNull, klass->as_value_klass()); 3279 } 3280 return TypeValueTypePtr::make(o); 3281 } else if (klass->is_instance_klass()) { 3282 // Element is an instance 3283 if (require_constant) { 3284 if (!o->can_be_constant()) return NULL; 3285 } else if (!o->should_be_constant()) { 3286 return TypeInstPtr::make(TypePtr::NotNull, klass, true, NULL, Offset(0)); 3287 } 3288 return TypeInstPtr::make(o); 3289 } else if (klass->is_obj_array_klass() || klass->is_value_array_klass()) { 3290 // Element is an object array. Recursively call ourself. 3291 const TypeOopPtr *etype = 3292 TypeOopPtr::make_from_klass_raw(klass->as_array_klass()->element_klass()); 3293 const TypeAry* arr0 = TypeAry::make(etype, TypeInt::make(o->as_array()->length())); 3294 // We used to pass NotNull in here, asserting that the sub-arrays 3295 // are all not-null. This is not true in generally, as code can 3296 // slam NULLs down in the subarrays. 3297 if (require_constant) { 3298 if (!o->can_be_constant()) return NULL; 3299 } else if (!o->should_be_constant()) { 3300 return TypeAryPtr::make(TypePtr::NotNull, arr0, klass, true, Offset(0)); 3301 } 3302 const TypeAryPtr* arr = TypeAryPtr::make(TypePtr::Constant, o, arr0, klass, true, Offset(0)); 3303 return arr; 3304 } else if (klass->is_type_array_klass()) { 3305 // Element is an typeArray 3306 const Type* etype = 3307 (Type*)get_const_basic_type(klass->as_type_array_klass()->element_type()); 3308 const TypeAry* arr0 = TypeAry::make(etype, TypeInt::make(o->as_array()->length())); 3309 // We used to pass NotNull in here, asserting that the array pointer 3310 // is not-null. That was not true in general. 3311 if (require_constant) { 3312 if (!o->can_be_constant()) return NULL; 3313 } else if (!o->should_be_constant()) { 3314 return TypeAryPtr::make(TypePtr::NotNull, arr0, klass, true, Offset(0)); 3315 } 3316 const TypeAryPtr* arr = TypeAryPtr::make(TypePtr::Constant, o, arr0, klass, true, Offset(0)); 3317 return arr; 3318 } 3319 3320 fatal("unhandled object type"); 3321 return NULL; 3322 } 3323 3324 //------------------------------get_con---------------------------------------- 3325 intptr_t TypeOopPtr::get_con() const { 3326 assert( _ptr == Null || _ptr == Constant, "" ); 3327 assert(offset() >= 0, ""); 3328 3329 if (offset() != 0) { 3330 // After being ported to the compiler interface, the compiler no longer 3331 // directly manipulates the addresses of oops. Rather, it only has a pointer 3332 // to a handle at compile time. This handle is embedded in the generated 3333 // code and dereferenced at the time the nmethod is made. Until that time, 3334 // it is not reasonable to do arithmetic with the addresses of oops (we don't 3335 // have access to the addresses!). This does not seem to currently happen, 3336 // but this assertion here is to help prevent its occurence. 3337 tty->print_cr("Found oop constant with non-zero offset"); 3338 ShouldNotReachHere(); 3339 } 3340 3341 return (intptr_t)const_oop()->constant_encoding(); 3342 } 3343 3344 3345 //-----------------------------filter------------------------------------------ 3346 // Do not allow interface-vs.-noninterface joins to collapse to top. 3347 const Type *TypeOopPtr::filter_helper(const Type *kills, bool include_speculative) const { 3348 3349 const Type* ft = join_helper(kills, include_speculative); 3350 const TypeInstPtr* ftip = ft->isa_instptr(); 3351 const TypeInstPtr* ktip = kills->isa_instptr(); 3352 3353 if (ft->empty()) { 3354 // Check for evil case of 'this' being a class and 'kills' expecting an 3355 // interface. This can happen because the bytecodes do not contain 3356 // enough type info to distinguish a Java-level interface variable 3357 // from a Java-level object variable. If we meet 2 classes which 3358 // both implement interface I, but their meet is at 'j/l/O' which 3359 // doesn't implement I, we have no way to tell if the result should 3360 // be 'I' or 'j/l/O'. Thus we'll pick 'j/l/O'. If this then flows 3361 // into a Phi which "knows" it's an Interface type we'll have to 3362 // uplift the type. 3363 if (!empty()) { 3364 if (ktip != NULL && ktip->is_loaded() && ktip->klass()->is_interface()) { 3365 return kills; // Uplift to interface 3366 } 3367 // Also check for evil cases of 'this' being a class array 3368 // and 'kills' expecting an array of interfaces. 3369 Type::get_arrays_base_elements(ft, kills, NULL, &ktip); 3370 if (ktip != NULL && ktip->is_loaded() && ktip->klass()->is_interface()) { 3371 return kills; // Uplift to array of interface 3372 } 3373 } 3374 3375 return Type::TOP; // Canonical empty value 3376 } 3377 3378 // If we have an interface-typed Phi or cast and we narrow to a class type, 3379 // the join should report back the class. However, if we have a J/L/Object 3380 // class-typed Phi and an interface flows in, it's possible that the meet & 3381 // join report an interface back out. This isn't possible but happens 3382 // because the type system doesn't interact well with interfaces. 3383 if (ftip != NULL && ktip != NULL && 3384 ftip->is_loaded() && ftip->klass()->is_interface() && 3385 ktip->is_loaded() && !ktip->klass()->is_interface()) { 3386 assert(!ftip->klass_is_exact(), "interface could not be exact"); 3387 return ktip->cast_to_ptr_type(ftip->ptr()); 3388 } 3389 3390 return ft; 3391 } 3392 3393 //------------------------------eq--------------------------------------------- 3394 // Structural equality check for Type representations 3395 bool TypeOopPtr::eq( const Type *t ) const { 3396 const TypeOopPtr *a = (const TypeOopPtr*)t; 3397 if (_klass_is_exact != a->_klass_is_exact || 3398 _instance_id != a->_instance_id) return false; 3399 ciObject* one = const_oop(); 3400 ciObject* two = a->const_oop(); 3401 if (one == NULL || two == NULL) { 3402 return (one == two) && TypePtr::eq(t); 3403 } else { 3404 return one->equals(two) && TypePtr::eq(t); 3405 } 3406 } 3407 3408 //------------------------------hash------------------------------------------- 3409 // Type-specific hashing function. 3410 int TypeOopPtr::hash(void) const { 3411 return 3412 java_add(java_add(const_oop() ? const_oop()->hash() : 0, _klass_is_exact), 3413 java_add(_instance_id, TypePtr::hash())); 3414 } 3415 3416 //------------------------------dump2------------------------------------------ 3417 #ifndef PRODUCT 3418 void TypeOopPtr::dump2( Dict &d, uint depth, outputStream *st ) const { 3419 st->print("oopptr:%s", ptr_msg[_ptr]); 3420 if( _klass_is_exact ) st->print(":exact"); 3421 if( const_oop() ) st->print(INTPTR_FORMAT, p2i(const_oop())); 3422 _offset.dump2(st); 3423 if (_instance_id == InstanceTop) 3424 st->print(",iid=top"); 3425 else if (_instance_id != InstanceBot) 3426 st->print(",iid=%d",_instance_id); 3427 3428 dump_inline_depth(st); 3429 dump_speculative(st); 3430 } 3431 #endif 3432 3433 //------------------------------singleton-------------------------------------- 3434 // TRUE if Type is a singleton type, FALSE otherwise. Singletons are simple 3435 // constants 3436 bool TypeOopPtr::singleton(void) const { 3437 // detune optimizer to not generate constant oop + constant offset as a constant! 3438 // TopPTR, Null, AnyNull, Constant are all singletons 3439 return (offset() == 0) && !below_centerline(_ptr); 3440 } 3441 3442 //------------------------------add_offset------------------------------------- 3443 const TypePtr *TypeOopPtr::add_offset(intptr_t offset) const { 3444 return make(_ptr, xadd_offset(offset), _instance_id, add_offset_speculative(offset), _inline_depth); 3445 } 3446 3447 /** 3448 * Return same type without a speculative part 3449 */ 3450 const Type* TypeOopPtr::remove_speculative() const { 3451 if (_speculative == NULL) { 3452 return this; 3453 } 3454 assert(_inline_depth == InlineDepthTop || _inline_depth == InlineDepthBottom, "non speculative type shouldn't have inline depth"); 3455 return make(_ptr, _offset, _instance_id, NULL, _inline_depth); 3456 } 3457 3458 /** 3459 * Return same type but drop speculative part if we know we won't use 3460 * it 3461 */ 3462 const Type* TypeOopPtr::cleanup_speculative() const { 3463 // If the klass is exact and the ptr is not null then there's 3464 // nothing that the speculative type can help us with 3465 if (klass_is_exact() && !maybe_null()) { 3466 return remove_speculative(); 3467 } 3468 return TypePtr::cleanup_speculative(); 3469 } 3470 3471 /** 3472 * Return same type but with a different inline depth (used for speculation) 3473 * 3474 * @param depth depth to meet with 3475 */ 3476 const TypePtr* TypeOopPtr::with_inline_depth(int depth) const { 3477 if (!UseInlineDepthForSpeculativeTypes) { 3478 return this; 3479 } 3480 return make(_ptr, _offset, _instance_id, _speculative, depth); 3481 } 3482 3483 //------------------------------meet_instance_id-------------------------------- 3484 int TypeOopPtr::meet_instance_id( int instance_id ) const { 3485 // Either is 'TOP' instance? Return the other instance! 3486 if( _instance_id == InstanceTop ) return instance_id; 3487 if( instance_id == InstanceTop ) return _instance_id; 3488 // If either is different, return 'BOTTOM' instance 3489 if( _instance_id != instance_id ) return InstanceBot; 3490 return _instance_id; 3491 } 3492 3493 //------------------------------dual_instance_id-------------------------------- 3494 int TypeOopPtr::dual_instance_id( ) const { 3495 if( _instance_id == InstanceTop ) return InstanceBot; // Map TOP into BOTTOM 3496 if( _instance_id == InstanceBot ) return InstanceTop; // Map BOTTOM into TOP 3497 return _instance_id; // Map everything else into self 3498 } 3499 3500 /** 3501 * Check whether new profiling would improve speculative type 3502 * 3503 * @param exact_kls class from profiling 3504 * @param inline_depth inlining depth of profile point 3505 * 3506 * @return true if type profile is valuable 3507 */ 3508 bool TypeOopPtr::would_improve_type(ciKlass* exact_kls, int inline_depth) const { 3509 // no way to improve an already exact type 3510 if (klass_is_exact()) { 3511 return false; 3512 } 3513 return TypePtr::would_improve_type(exact_kls, inline_depth); 3514 } 3515 3516 //============================================================================= 3517 // Convenience common pre-built types. 3518 const TypeInstPtr *TypeInstPtr::NOTNULL; 3519 const TypeInstPtr *TypeInstPtr::BOTTOM; 3520 const TypeInstPtr *TypeInstPtr::MIRROR; 3521 const TypeInstPtr *TypeInstPtr::MARK; 3522 const TypeInstPtr *TypeInstPtr::KLASS; 3523 3524 //------------------------------TypeInstPtr------------------------------------- 3525 TypeInstPtr::TypeInstPtr(PTR ptr, ciKlass* k, bool xk, ciObject* o, Offset off, 3526 int instance_id, const TypePtr* speculative, int inline_depth) 3527 : TypeOopPtr(InstPtr, ptr, k, xk, o, off, instance_id, speculative, inline_depth), 3528 _name(k->name()) { 3529 assert(k != NULL && 3530 (k->is_loaded() || o == NULL), 3531 "cannot have constants with non-loaded klass"); 3532 }; 3533 3534 //------------------------------make------------------------------------------- 3535 const TypeInstPtr *TypeInstPtr::make(PTR ptr, 3536 ciKlass* k, 3537 bool xk, 3538 ciObject* o, 3539 Offset offset, 3540 int instance_id, 3541 const TypePtr* speculative, 3542 int inline_depth) { 3543 assert( !k->is_loaded() || k->is_instance_klass(), "Must be for instance"); 3544 // Either const_oop() is NULL or else ptr is Constant 3545 assert( (!o && ptr != Constant) || (o && ptr == Constant), 3546 "constant pointers must have a value supplied" ); 3547 // Ptr is never Null 3548 assert( ptr != Null, "NULL pointers are not typed" ); 3549 3550 assert(instance_id <= 0 || xk || !UseExactTypes, "instances are always exactly typed"); 3551 if (!UseExactTypes) xk = false; 3552 if (ptr == Constant) { 3553 // Note: This case includes meta-object constants, such as methods. 3554 xk = true; 3555 } else if (k->is_loaded()) { 3556 ciInstanceKlass* ik = k->as_instance_klass(); 3557 if (!xk && ik->is_final()) xk = true; // no inexact final klass 3558 if (xk && ik->is_interface()) xk = false; // no exact interface 3559 } 3560 3561 // Now hash this baby 3562 TypeInstPtr *result = 3563 (TypeInstPtr*)(new TypeInstPtr(ptr, k, xk, o ,offset, instance_id, speculative, inline_depth))->hashcons(); 3564 3565 return result; 3566 } 3567 3568 /** 3569 * Create constant type for a constant boxed value 3570 */ 3571 const Type* TypeInstPtr::get_const_boxed_value() const { 3572 assert(is_ptr_to_boxed_value(), "should be called only for boxed value"); 3573 assert((const_oop() != NULL), "should be called only for constant object"); 3574 ciConstant constant = const_oop()->as_instance()->field_value_by_offset(offset()); 3575 BasicType bt = constant.basic_type(); 3576 switch (bt) { 3577 case T_BOOLEAN: return TypeInt::make(constant.as_boolean()); 3578 case T_INT: return TypeInt::make(constant.as_int()); 3579 case T_CHAR: return TypeInt::make(constant.as_char()); 3580 case T_BYTE: return TypeInt::make(constant.as_byte()); 3581 case T_SHORT: return TypeInt::make(constant.as_short()); 3582 case T_FLOAT: return TypeF::make(constant.as_float()); 3583 case T_DOUBLE: return TypeD::make(constant.as_double()); 3584 case T_LONG: return TypeLong::make(constant.as_long()); 3585 default: break; 3586 } 3587 fatal("Invalid boxed value type '%s'", type2name(bt)); 3588 return NULL; 3589 } 3590 3591 //------------------------------cast_to_ptr_type------------------------------- 3592 const Type *TypeInstPtr::cast_to_ptr_type(PTR ptr) const { 3593 if( ptr == _ptr ) return this; 3594 // Reconstruct _sig info here since not a problem with later lazy 3595 // construction, _sig will show up on demand. 3596 return make(ptr, klass(), klass_is_exact(), const_oop(), _offset, _instance_id, _speculative, _inline_depth); 3597 } 3598 3599 3600 //-----------------------------cast_to_exactness------------------------------- 3601 const Type *TypeInstPtr::cast_to_exactness(bool klass_is_exact) const { 3602 if( klass_is_exact == _klass_is_exact ) return this; 3603 if (!UseExactTypes) return this; 3604 if (!_klass->is_loaded()) return this; 3605 ciInstanceKlass* ik = _klass->as_instance_klass(); 3606 if( (ik->is_final() || _const_oop) ) return this; // cannot clear xk 3607 if( ik->is_interface() ) return this; // cannot set xk 3608 return make(ptr(), klass(), klass_is_exact, const_oop(), _offset, _instance_id, _speculative, _inline_depth); 3609 } 3610 3611 //-----------------------------cast_to_instance_id---------------------------- 3612 const TypeOopPtr *TypeInstPtr::cast_to_instance_id(int instance_id) const { 3613 if( instance_id == _instance_id ) return this; 3614 return make(_ptr, klass(), _klass_is_exact, const_oop(), _offset, instance_id, _speculative, _inline_depth); 3615 } 3616 3617 //------------------------------xmeet_unloaded--------------------------------- 3618 // Compute the MEET of two InstPtrs when at least one is unloaded. 3619 // Assume classes are different since called after check for same name/class-loader 3620 const TypeInstPtr *TypeInstPtr::xmeet_unloaded(const TypeInstPtr *tinst) const { 3621 Offset off = meet_offset(tinst->offset()); 3622 PTR ptr = meet_ptr(tinst->ptr()); 3623 int instance_id = meet_instance_id(tinst->instance_id()); 3624 const TypePtr* speculative = xmeet_speculative(tinst); 3625 int depth = meet_inline_depth(tinst->inline_depth()); 3626 3627 const TypeInstPtr *loaded = is_loaded() ? this : tinst; 3628 const TypeInstPtr *unloaded = is_loaded() ? tinst : this; 3629 if( loaded->klass()->equals(ciEnv::current()->Object_klass()) ) { 3630 // 3631 // Meet unloaded class with java/lang/Object 3632 // 3633 // Meet 3634 // | Unloaded Class 3635 // Object | TOP | AnyNull | Constant | NotNull | BOTTOM | 3636 // =================================================================== 3637 // TOP | ..........................Unloaded......................| 3638 // AnyNull | U-AN |................Unloaded......................| 3639 // Constant | ... O-NN .................................. | O-BOT | 3640 // NotNull | ... O-NN .................................. | O-BOT | 3641 // BOTTOM | ........................Object-BOTTOM ..................| 3642 // 3643 assert(loaded->ptr() != TypePtr::Null, "insanity check"); 3644 // 3645 if( loaded->ptr() == TypePtr::TopPTR ) { return unloaded; } 3646 else if (loaded->ptr() == TypePtr::AnyNull) { return TypeInstPtr::make(ptr, unloaded->klass(), false, NULL, off, instance_id, speculative, depth); } 3647 else if (loaded->ptr() == TypePtr::BotPTR ) { return TypeInstPtr::BOTTOM; } 3648 else if (loaded->ptr() == TypePtr::Constant || loaded->ptr() == TypePtr::NotNull) { 3649 if (unloaded->ptr() == TypePtr::BotPTR ) { return TypeInstPtr::BOTTOM; } 3650 else { return TypeInstPtr::NOTNULL; } 3651 } 3652 else if( unloaded->ptr() == TypePtr::TopPTR ) { return unloaded; } 3653 3654 return unloaded->cast_to_ptr_type(TypePtr::AnyNull)->is_instptr(); 3655 } 3656 3657 // Both are unloaded, not the same class, not Object 3658 // Or meet unloaded with a different loaded class, not java/lang/Object 3659 if( ptr != TypePtr::BotPTR ) { 3660 return TypeInstPtr::NOTNULL; 3661 } 3662 return TypeInstPtr::BOTTOM; 3663 } 3664 3665 3666 //------------------------------meet------------------------------------------- 3667 // Compute the MEET of two types. It returns a new Type object. 3668 const Type *TypeInstPtr::xmeet_helper(const Type *t) const { 3669 // Perform a fast test for common case; meeting the same types together. 3670 if( this == t ) return this; // Meeting same type-rep? 3671 3672 // Current "this->_base" is Pointer 3673 switch (t->base()) { // switch on original type 3674 3675 case Int: // Mixing ints & oops happens when javac 3676 case Long: // reuses local variables 3677 case FloatTop: 3678 case FloatCon: 3679 case FloatBot: 3680 case DoubleTop: 3681 case DoubleCon: 3682 case DoubleBot: 3683 case NarrowOop: 3684 case NarrowKlass: 3685 case Bottom: // Ye Olde Default 3686 return Type::BOTTOM; 3687 case Top: 3688 return this; 3689 3690 default: // All else is a mistake 3691 typerr(t); 3692 3693 case MetadataPtr: 3694 case KlassPtr: 3695 case RawPtr: return TypePtr::BOTTOM; 3696 3697 case AryPtr: { // All arrays inherit from Object class 3698 const TypeAryPtr *tp = t->is_aryptr(); 3699 Offset offset = meet_offset(tp->offset()); 3700 PTR ptr = meet_ptr(tp->ptr()); 3701 int instance_id = meet_instance_id(tp->instance_id()); 3702 const TypePtr* speculative = xmeet_speculative(tp); 3703 int depth = meet_inline_depth(tp->inline_depth()); 3704 switch (ptr) { 3705 case TopPTR: 3706 case AnyNull: // Fall 'down' to dual of object klass 3707 // For instances when a subclass meets a superclass we fall 3708 // below the centerline when the superclass is exact. We need to 3709 // do the same here. 3710 if (klass()->equals(ciEnv::current()->Object_klass()) && !klass_is_exact()) { 3711 return TypeAryPtr::make(ptr, tp->ary(), tp->klass(), tp->klass_is_exact(), offset, tp->_field_offset, instance_id, speculative, depth); 3712 } else { 3713 // cannot subclass, so the meet has to fall badly below the centerline 3714 ptr = NotNull; 3715 instance_id = InstanceBot; 3716 return TypeInstPtr::make( ptr, ciEnv::current()->Object_klass(), false, NULL, offset, instance_id, speculative, depth); 3717 } 3718 case Constant: 3719 case NotNull: 3720 case BotPTR: // Fall down to object klass 3721 // LCA is object_klass, but if we subclass from the top we can do better 3722 if( above_centerline(_ptr) ) { // if( _ptr == TopPTR || _ptr == AnyNull ) 3723 // If 'this' (InstPtr) is above the centerline and it is Object class 3724 // then we can subclass in the Java class hierarchy. 3725 // For instances when a subclass meets a superclass we fall 3726 // below the centerline when the superclass is exact. We need 3727 // to do the same here. 3728 if (klass()->equals(ciEnv::current()->Object_klass()) && !klass_is_exact()) { 3729 // that is, tp's array type is a subtype of my klass 3730 return TypeAryPtr::make(ptr, (ptr == Constant ? tp->const_oop() : NULL), 3731 tp->ary(), tp->klass(), tp->klass_is_exact(), offset, tp->_field_offset, instance_id, speculative, depth); 3732 } 3733 } 3734 // The other case cannot happen, since I cannot be a subtype of an array. 3735 // The meet falls down to Object class below centerline. 3736 if( ptr == Constant ) 3737 ptr = NotNull; 3738 instance_id = InstanceBot; 3739 return make(ptr, ciEnv::current()->Object_klass(), false, NULL, offset, instance_id, speculative, depth); 3740 default: typerr(t); 3741 } 3742 } 3743 3744 case OopPtr: { // Meeting to OopPtrs 3745 // Found a OopPtr type vs self-InstPtr type 3746 const TypeOopPtr *tp = t->is_oopptr(); 3747 Offset offset = meet_offset(tp->offset()); 3748 PTR ptr = meet_ptr(tp->ptr()); 3749 switch (tp->ptr()) { 3750 case TopPTR: 3751 case AnyNull: { 3752 int instance_id = meet_instance_id(InstanceTop); 3753 const TypePtr* speculative = xmeet_speculative(tp); 3754 int depth = meet_inline_depth(tp->inline_depth()); 3755 return make(ptr, klass(), klass_is_exact(), 3756 (ptr == Constant ? const_oop() : NULL), offset, instance_id, speculative, depth); 3757 } 3758 case NotNull: 3759 case BotPTR: { 3760 int instance_id = meet_instance_id(tp->instance_id()); 3761 const TypePtr* speculative = xmeet_speculative(tp); 3762 int depth = meet_inline_depth(tp->inline_depth()); 3763 return TypeOopPtr::make(ptr, offset, instance_id, speculative, depth); 3764 } 3765 default: typerr(t); 3766 } 3767 } 3768 3769 case AnyPtr: { // Meeting to AnyPtrs 3770 // Found an AnyPtr type vs self-InstPtr type 3771 const TypePtr *tp = t->is_ptr(); 3772 Offset offset = meet_offset(tp->offset()); 3773 PTR ptr = meet_ptr(tp->ptr()); 3774 int instance_id = meet_instance_id(InstanceTop); 3775 const TypePtr* speculative = xmeet_speculative(tp); 3776 int depth = meet_inline_depth(tp->inline_depth()); 3777 switch (tp->ptr()) { 3778 case Null: 3779 if( ptr == Null ) return TypePtr::make(AnyPtr, ptr, offset, speculative, depth); 3780 // else fall through to AnyNull 3781 case TopPTR: 3782 case AnyNull: { 3783 return make(ptr, klass(), klass_is_exact(), 3784 (ptr == Constant ? const_oop() : NULL), offset, instance_id, speculative, depth); 3785 } 3786 case NotNull: 3787 case BotPTR: 3788 return TypePtr::make(AnyPtr, ptr, offset, speculative,depth); 3789 default: typerr(t); 3790 } 3791 } 3792 3793 /* 3794 A-top } 3795 / | \ } Tops 3796 B-top A-any C-top } 3797 | / | \ | } Any-nulls 3798 B-any | C-any } 3799 | | | 3800 B-con A-con C-con } constants; not comparable across classes 3801 | | | 3802 B-not | C-not } 3803 | \ | / | } not-nulls 3804 B-bot A-not C-bot } 3805 \ | / } Bottoms 3806 A-bot } 3807 */ 3808 3809 case InstPtr: { // Meeting 2 Oops? 3810 // Found an InstPtr sub-type vs self-InstPtr type 3811 const TypeInstPtr *tinst = t->is_instptr(); 3812 Offset off = meet_offset( tinst->offset() ); 3813 PTR ptr = meet_ptr( tinst->ptr() ); 3814 int instance_id = meet_instance_id(tinst->instance_id()); 3815 const TypePtr* speculative = xmeet_speculative(tinst); 3816 int depth = meet_inline_depth(tinst->inline_depth()); 3817 3818 // Check for easy case; klasses are equal (and perhaps not loaded!) 3819 // If we have constants, then we created oops so classes are loaded 3820 // and we can handle the constants further down. This case handles 3821 // both-not-loaded or both-loaded classes 3822 if (ptr != Constant && klass()->equals(tinst->klass()) && klass_is_exact() == tinst->klass_is_exact()) { 3823 return make(ptr, klass(), klass_is_exact(), NULL, off, instance_id, speculative, depth); 3824 } 3825 3826 // Classes require inspection in the Java klass hierarchy. Must be loaded. 3827 ciKlass* tinst_klass = tinst->klass(); 3828 ciKlass* this_klass = this->klass(); 3829 bool tinst_xk = tinst->klass_is_exact(); 3830 bool this_xk = this->klass_is_exact(); 3831 if (!tinst_klass->is_loaded() || !this_klass->is_loaded() ) { 3832 // One of these classes has not been loaded 3833 const TypeInstPtr *unloaded_meet = xmeet_unloaded(tinst); 3834 #ifndef PRODUCT 3835 if( PrintOpto && Verbose ) { 3836 tty->print("meet of unloaded classes resulted in: "); unloaded_meet->dump(); tty->cr(); 3837 tty->print(" this == "); this->dump(); tty->cr(); 3838 tty->print(" tinst == "); tinst->dump(); tty->cr(); 3839 } 3840 #endif 3841 return unloaded_meet; 3842 } 3843 3844 // Handle mixing oops and interfaces first. 3845 if( this_klass->is_interface() && !(tinst_klass->is_interface() || 3846 tinst_klass == ciEnv::current()->Object_klass())) { 3847 ciKlass *tmp = tinst_klass; // Swap interface around 3848 tinst_klass = this_klass; 3849 this_klass = tmp; 3850 bool tmp2 = tinst_xk; 3851 tinst_xk = this_xk; 3852 this_xk = tmp2; 3853 } 3854 if (tinst_klass->is_interface() && 3855 !(this_klass->is_interface() || 3856 // Treat java/lang/Object as an honorary interface, 3857 // because we need a bottom for the interface hierarchy. 3858 this_klass == ciEnv::current()->Object_klass())) { 3859 // Oop meets interface! 3860 3861 // See if the oop subtypes (implements) interface. 3862 ciKlass *k; 3863 bool xk; 3864 if( this_klass->is_subtype_of( tinst_klass ) ) { 3865 // Oop indeed subtypes. Now keep oop or interface depending 3866 // on whether we are both above the centerline or either is 3867 // below the centerline. If we are on the centerline 3868 // (e.g., Constant vs. AnyNull interface), use the constant. 3869 k = below_centerline(ptr) ? tinst_klass : this_klass; 3870 // If we are keeping this_klass, keep its exactness too. 3871 xk = below_centerline(ptr) ? tinst_xk : this_xk; 3872 } else { // Does not implement, fall to Object 3873 // Oop does not implement interface, so mixing falls to Object 3874 // just like the verifier does (if both are above the 3875 // centerline fall to interface) 3876 k = above_centerline(ptr) ? tinst_klass : ciEnv::current()->Object_klass(); 3877 xk = above_centerline(ptr) ? tinst_xk : false; 3878 // Watch out for Constant vs. AnyNull interface. 3879 if (ptr == Constant) ptr = NotNull; // forget it was a constant 3880 instance_id = InstanceBot; 3881 } 3882 ciObject* o = NULL; // the Constant value, if any 3883 if (ptr == Constant) { 3884 // Find out which constant. 3885 o = (this_klass == klass()) ? const_oop() : tinst->const_oop(); 3886 } 3887 return make(ptr, k, xk, o, off, instance_id, speculative, depth); 3888 } 3889 3890 // Either oop vs oop or interface vs interface or interface vs Object 3891 3892 // !!! Here's how the symmetry requirement breaks down into invariants: 3893 // If we split one up & one down AND they subtype, take the down man. 3894 // If we split one up & one down AND they do NOT subtype, "fall hard". 3895 // If both are up and they subtype, take the subtype class. 3896 // If both are up and they do NOT subtype, "fall hard". 3897 // If both are down and they subtype, take the supertype class. 3898 // If both are down and they do NOT subtype, "fall hard". 3899 // Constants treated as down. 3900 3901 // Now, reorder the above list; observe that both-down+subtype is also 3902 // "fall hard"; "fall hard" becomes the default case: 3903 // If we split one up & one down AND they subtype, take the down man. 3904 // If both are up and they subtype, take the subtype class. 3905 3906 // If both are down and they subtype, "fall hard". 3907 // If both are down and they do NOT subtype, "fall hard". 3908 // If both are up and they do NOT subtype, "fall hard". 3909 // If we split one up & one down AND they do NOT subtype, "fall hard". 3910 3911 // If a proper subtype is exact, and we return it, we return it exactly. 3912 // If a proper supertype is exact, there can be no subtyping relationship! 3913 // If both types are equal to the subtype, exactness is and-ed below the 3914 // centerline and or-ed above it. (N.B. Constants are always exact.) 3915 3916 // Check for subtyping: 3917 ciKlass *subtype = NULL; 3918 bool subtype_exact = false; 3919 if( tinst_klass->equals(this_klass) ) { 3920 subtype = this_klass; 3921 subtype_exact = below_centerline(ptr) ? (this_xk & tinst_xk) : (this_xk | tinst_xk); 3922 } else if( !tinst_xk && this_klass->is_subtype_of( tinst_klass ) ) { 3923 subtype = this_klass; // Pick subtyping class 3924 subtype_exact = this_xk; 3925 } else if( !this_xk && tinst_klass->is_subtype_of( this_klass ) ) { 3926 subtype = tinst_klass; // Pick subtyping class 3927 subtype_exact = tinst_xk; 3928 } 3929 3930 if( subtype ) { 3931 if( above_centerline(ptr) ) { // both are up? 3932 this_klass = tinst_klass = subtype; 3933 this_xk = tinst_xk = subtype_exact; 3934 } else if( above_centerline(this ->_ptr) && !above_centerline(tinst->_ptr) ) { 3935 this_klass = tinst_klass; // tinst is down; keep down man 3936 this_xk = tinst_xk; 3937 } else if( above_centerline(tinst->_ptr) && !above_centerline(this ->_ptr) ) { 3938 tinst_klass = this_klass; // this is down; keep down man 3939 tinst_xk = this_xk; 3940 } else { 3941 this_xk = subtype_exact; // either they are equal, or we'll do an LCA 3942 } 3943 } 3944 3945 // Check for classes now being equal 3946 if (tinst_klass->equals(this_klass)) { 3947 // If the klasses are equal, the constants may still differ. Fall to 3948 // NotNull if they do (neither constant is NULL; that is a special case 3949 // handled elsewhere). 3950 ciObject* o = NULL; // Assume not constant when done 3951 ciObject* this_oop = const_oop(); 3952 ciObject* tinst_oop = tinst->const_oop(); 3953 if( ptr == Constant ) { 3954 if (this_oop != NULL && tinst_oop != NULL && 3955 this_oop->equals(tinst_oop) ) 3956 o = this_oop; 3957 else if (above_centerline(this ->_ptr)) 3958 o = tinst_oop; 3959 else if (above_centerline(tinst ->_ptr)) 3960 o = this_oop; 3961 else 3962 ptr = NotNull; 3963 } 3964 return make(ptr, this_klass, this_xk, o, off, instance_id, speculative, depth); 3965 } // Else classes are not equal 3966 3967 // Since klasses are different, we require a LCA in the Java 3968 // class hierarchy - which means we have to fall to at least NotNull. 3969 if( ptr == TopPTR || ptr == AnyNull || ptr == Constant ) 3970 ptr = NotNull; 3971 3972 instance_id = InstanceBot; 3973 3974 // Now we find the LCA of Java classes 3975 ciKlass* k = this_klass->least_common_ancestor(tinst_klass); 3976 return make(ptr, k, false, NULL, off, instance_id, speculative, depth); 3977 } // End of case InstPtr 3978 3979 } // End of switch 3980 return this; // Return the double constant 3981 } 3982 3983 3984 //------------------------java_mirror_type-------------------------------------- 3985 ciType* TypeInstPtr::java_mirror_type() const { 3986 // must be a singleton type 3987 if( const_oop() == NULL ) return NULL; 3988 3989 // must be of type java.lang.Class 3990 if( klass() != ciEnv::current()->Class_klass() ) return NULL; 3991 3992 return const_oop()->as_instance()->java_mirror_type(); 3993 } 3994 3995 3996 //------------------------------xdual------------------------------------------ 3997 // Dual: do NOT dual on klasses. This means I do NOT understand the Java 3998 // inheritance mechanism. 3999 const Type *TypeInstPtr::xdual() const { 4000 return new TypeInstPtr(dual_ptr(), klass(), klass_is_exact(), const_oop(), dual_offset(), dual_instance_id(), dual_speculative(), dual_inline_depth()); 4001 } 4002 4003 //------------------------------eq--------------------------------------------- 4004 // Structural equality check for Type representations 4005 bool TypeInstPtr::eq( const Type *t ) const { 4006 const TypeInstPtr *p = t->is_instptr(); 4007 return 4008 klass()->equals(p->klass()) && 4009 TypeOopPtr::eq(p); // Check sub-type stuff 4010 } 4011 4012 //------------------------------hash------------------------------------------- 4013 // Type-specific hashing function. 4014 int TypeInstPtr::hash(void) const { 4015 int hash = java_add(klass()->hash(), TypeOopPtr::hash()); 4016 return hash; 4017 } 4018 4019 //------------------------------dump2------------------------------------------ 4020 // Dump oop Type 4021 #ifndef PRODUCT 4022 void TypeInstPtr::dump2( Dict &d, uint depth, outputStream *st ) const { 4023 // Print the name of the klass. 4024 klass()->print_name_on(st); 4025 4026 switch( _ptr ) { 4027 case Constant: 4028 // TO DO: Make CI print the hex address of the underlying oop. 4029 if (WizardMode || Verbose) { 4030 const_oop()->print_oop(st); 4031 } 4032 case BotPTR: 4033 if (!WizardMode && !Verbose) { 4034 if( _klass_is_exact ) st->print(":exact"); 4035 break; 4036 } 4037 case TopPTR: 4038 case AnyNull: 4039 case NotNull: 4040 st->print(":%s", ptr_msg[_ptr]); 4041 if( _klass_is_exact ) st->print(":exact"); 4042 break; 4043 } 4044 4045 _offset.dump2(st); 4046 4047 st->print(" *"); 4048 if (_instance_id == InstanceTop) 4049 st->print(",iid=top"); 4050 else if (_instance_id != InstanceBot) 4051 st->print(",iid=%d",_instance_id); 4052 4053 dump_inline_depth(st); 4054 dump_speculative(st); 4055 } 4056 #endif 4057 4058 //------------------------------add_offset------------------------------------- 4059 const TypePtr *TypeInstPtr::add_offset(intptr_t offset) const { 4060 return make(_ptr, klass(), klass_is_exact(), const_oop(), xadd_offset(offset), 4061 _instance_id, add_offset_speculative(offset), _inline_depth); 4062 } 4063 4064 const Type *TypeInstPtr::remove_speculative() const { 4065 if (_speculative == NULL) { 4066 return this; 4067 } 4068 assert(_inline_depth == InlineDepthTop || _inline_depth == InlineDepthBottom, "non speculative type shouldn't have inline depth"); 4069 return make(_ptr, klass(), klass_is_exact(), const_oop(), _offset, 4070 _instance_id, NULL, _inline_depth); 4071 } 4072 4073 const TypePtr *TypeInstPtr::with_inline_depth(int depth) const { 4074 if (!UseInlineDepthForSpeculativeTypes) { 4075 return this; 4076 } 4077 return make(_ptr, klass(), klass_is_exact(), const_oop(), _offset, _instance_id, _speculative, depth); 4078 } 4079 4080 //============================================================================= 4081 // Convenience common pre-built types. 4082 const TypeAryPtr *TypeAryPtr::RANGE; 4083 const TypeAryPtr *TypeAryPtr::OOPS; 4084 const TypeAryPtr *TypeAryPtr::NARROWOOPS; 4085 const TypeAryPtr *TypeAryPtr::BYTES; 4086 const TypeAryPtr *TypeAryPtr::SHORTS; 4087 const TypeAryPtr *TypeAryPtr::CHARS; 4088 const TypeAryPtr *TypeAryPtr::INTS; 4089 const TypeAryPtr *TypeAryPtr::LONGS; 4090 const TypeAryPtr *TypeAryPtr::FLOATS; 4091 const TypeAryPtr *TypeAryPtr::DOUBLES; 4092 4093 //------------------------------make------------------------------------------- 4094 const TypeAryPtr* TypeAryPtr::make(PTR ptr, const TypeAry *ary, ciKlass* k, bool xk, Offset offset, Offset field_offset, 4095 int instance_id, const TypePtr* speculative, int inline_depth) { 4096 assert(!(k == NULL && ary->_elem->isa_int()), 4097 "integral arrays must be pre-equipped with a class"); 4098 if (!xk) xk = ary->ary_must_be_exact(); 4099 assert(instance_id <= 0 || xk || !UseExactTypes, "instances are always exactly typed"); 4100 if (!UseExactTypes) xk = (ptr == Constant); 4101 return (TypeAryPtr*)(new TypeAryPtr(ptr, NULL, ary, k, xk, offset, field_offset, instance_id, false, speculative, inline_depth))->hashcons(); 4102 } 4103 4104 //------------------------------make------------------------------------------- 4105 const TypeAryPtr* TypeAryPtr::make(PTR ptr, ciObject* o, const TypeAry *ary, ciKlass* k, bool xk, Offset offset, Offset field_offset, 4106 int instance_id, const TypePtr* speculative, int inline_depth, 4107 bool is_autobox_cache) { 4108 assert(!(k == NULL && ary->_elem->isa_int()), 4109 "integral arrays must be pre-equipped with a class"); 4110 assert( (ptr==Constant && o) || (ptr!=Constant && !o), "" ); 4111 if (!xk) xk = (o != NULL) || ary->ary_must_be_exact(); 4112 assert(instance_id <= 0 || xk || !UseExactTypes, "instances are always exactly typed"); 4113 if (!UseExactTypes) xk = (ptr == Constant); 4114 return (TypeAryPtr*)(new TypeAryPtr(ptr, o, ary, k, xk, offset, field_offset, instance_id, is_autobox_cache, speculative, inline_depth))->hashcons(); 4115 } 4116 4117 //------------------------------cast_to_ptr_type------------------------------- 4118 const Type *TypeAryPtr::cast_to_ptr_type(PTR ptr) const { 4119 if( ptr == _ptr ) return this; 4120 return make(ptr, const_oop(), _ary, klass(), klass_is_exact(), _offset, _field_offset, _instance_id, _speculative, _inline_depth, _is_autobox_cache); 4121 } 4122 4123 4124 //-----------------------------cast_to_exactness------------------------------- 4125 const Type *TypeAryPtr::cast_to_exactness(bool klass_is_exact) const { 4126 if( klass_is_exact == _klass_is_exact ) return this; 4127 if (!UseExactTypes) return this; 4128 if (_ary->ary_must_be_exact()) return this; // cannot clear xk 4129 return make(ptr(), const_oop(), _ary, klass(), klass_is_exact, _offset, _field_offset, _instance_id, _speculative, _inline_depth, _is_autobox_cache); 4130 } 4131 4132 //-----------------------------cast_to_instance_id---------------------------- 4133 const TypeOopPtr *TypeAryPtr::cast_to_instance_id(int instance_id) const { 4134 if( instance_id == _instance_id ) return this; 4135 return make(_ptr, const_oop(), _ary, klass(), _klass_is_exact, _offset, _field_offset, instance_id, _speculative, _inline_depth, _is_autobox_cache); 4136 } 4137 4138 //-----------------------------narrow_size_type------------------------------- 4139 // Local cache for arrayOopDesc::max_array_length(etype), 4140 // which is kind of slow (and cached elsewhere by other users). 4141 static jint max_array_length_cache[T_CONFLICT+1]; 4142 static jint max_array_length(BasicType etype) { 4143 jint& cache = max_array_length_cache[etype]; 4144 jint res = cache; 4145 if (res == 0) { 4146 switch (etype) { 4147 case T_NARROWOOP: 4148 etype = T_OBJECT; 4149 break; 4150 case T_NARROWKLASS: 4151 case T_CONFLICT: 4152 case T_ILLEGAL: 4153 case T_VOID: 4154 etype = T_BYTE; // will produce conservatively high value 4155 } 4156 cache = res = arrayOopDesc::max_array_length(etype); 4157 } 4158 return res; 4159 } 4160 4161 // Narrow the given size type to the index range for the given array base type. 4162 // Return NULL if the resulting int type becomes empty. 4163 const TypeInt* TypeAryPtr::narrow_size_type(const TypeInt* size) const { 4164 jint hi = size->_hi; 4165 jint lo = size->_lo; 4166 jint min_lo = 0; 4167 jint max_hi = max_array_length(elem()->basic_type()); 4168 //if (index_not_size) --max_hi; // type of a valid array index, FTR 4169 bool chg = false; 4170 if (lo < min_lo) { 4171 lo = min_lo; 4172 if (size->is_con()) { 4173 hi = lo; 4174 } 4175 chg = true; 4176 } 4177 if (hi > max_hi) { 4178 hi = max_hi; 4179 if (size->is_con()) { 4180 lo = hi; 4181 } 4182 chg = true; 4183 } 4184 // Negative length arrays will produce weird intermediate dead fast-path code 4185 if (lo > hi) 4186 return TypeInt::ZERO; 4187 if (!chg) 4188 return size; 4189 return TypeInt::make(lo, hi, Type::WidenMin); 4190 } 4191 4192 //-------------------------------cast_to_size---------------------------------- 4193 const TypeAryPtr* TypeAryPtr::cast_to_size(const TypeInt* new_size) const { 4194 assert(new_size != NULL, ""); 4195 new_size = narrow_size_type(new_size); 4196 if (new_size == size()) return this; 4197 const TypeAry* new_ary = TypeAry::make(elem(), new_size, is_stable()); 4198 return make(ptr(), const_oop(), new_ary, klass(), klass_is_exact(), _offset, _field_offset, _instance_id, _speculative, _inline_depth, _is_autobox_cache); 4199 } 4200 4201 //------------------------------cast_to_stable--------------------------------- 4202 const TypeAryPtr* TypeAryPtr::cast_to_stable(bool stable, int stable_dimension) const { 4203 if (stable_dimension <= 0 || (stable_dimension == 1 && stable == this->is_stable())) 4204 return this; 4205 4206 const Type* elem = this->elem(); 4207 const TypePtr* elem_ptr = elem->make_ptr(); 4208 4209 if (stable_dimension > 1 && elem_ptr != NULL && elem_ptr->isa_aryptr()) { 4210 // If this is widened from a narrow oop, TypeAry::make will re-narrow it. 4211 elem = elem_ptr = elem_ptr->is_aryptr()->cast_to_stable(stable, stable_dimension - 1); 4212 } 4213 4214 const TypeAry* new_ary = TypeAry::make(elem, size(), stable); 4215 4216 return make(ptr(), const_oop(), new_ary, klass(), klass_is_exact(), _offset, _field_offset, _instance_id, _speculative, _inline_depth, _is_autobox_cache); 4217 } 4218 4219 //-----------------------------stable_dimension-------------------------------- 4220 int TypeAryPtr::stable_dimension() const { 4221 if (!is_stable()) return 0; 4222 int dim = 1; 4223 const TypePtr* elem_ptr = elem()->make_ptr(); 4224 if (elem_ptr != NULL && elem_ptr->isa_aryptr()) 4225 dim += elem_ptr->is_aryptr()->stable_dimension(); 4226 return dim; 4227 } 4228 4229 //----------------------cast_to_autobox_cache----------------------------------- 4230 const TypeAryPtr* TypeAryPtr::cast_to_autobox_cache(bool cache) const { 4231 if (is_autobox_cache() == cache) return this; 4232 const TypeOopPtr* etype = elem()->make_oopptr(); 4233 if (etype == NULL) return this; 4234 // The pointers in the autobox arrays are always non-null. 4235 TypePtr::PTR ptr_type = cache ? TypePtr::NotNull : TypePtr::AnyNull; 4236 etype = etype->cast_to_ptr_type(TypePtr::NotNull)->is_oopptr(); 4237 const TypeAry* new_ary = TypeAry::make(etype, size(), is_stable()); 4238 return make(ptr(), const_oop(), new_ary, klass(), klass_is_exact(), _offset, _field_offset, _instance_id, _speculative, _inline_depth, cache); 4239 } 4240 4241 //------------------------------eq--------------------------------------------- 4242 // Structural equality check for Type representations 4243 bool TypeAryPtr::eq( const Type *t ) const { 4244 const TypeAryPtr *p = t->is_aryptr(); 4245 return 4246 _ary == p->_ary && // Check array 4247 TypeOopPtr::eq(p) &&// Check sub-parts 4248 _field_offset == p->_field_offset; 4249 } 4250 4251 //------------------------------hash------------------------------------------- 4252 // Type-specific hashing function. 4253 int TypeAryPtr::hash(void) const { 4254 return (intptr_t)_ary + TypeOopPtr::hash() + field_offset(); 4255 } 4256 4257 //------------------------------meet------------------------------------------- 4258 // Compute the MEET of two types. It returns a new Type object. 4259 const Type *TypeAryPtr::xmeet_helper(const Type *t) const { 4260 // Perform a fast test for common case; meeting the same types together. 4261 if( this == t ) return this; // Meeting same type-rep? 4262 // Current "this->_base" is Pointer 4263 switch (t->base()) { // switch on original type 4264 4265 // Mixing ints & oops happens when javac reuses local variables 4266 case Int: 4267 case Long: 4268 case FloatTop: 4269 case FloatCon: 4270 case FloatBot: 4271 case DoubleTop: 4272 case DoubleCon: 4273 case DoubleBot: 4274 case NarrowOop: 4275 case NarrowKlass: 4276 case Bottom: // Ye Olde Default 4277 return Type::BOTTOM; 4278 case Top: 4279 return this; 4280 4281 default: // All else is a mistake 4282 typerr(t); 4283 4284 case OopPtr: { // Meeting to OopPtrs 4285 // Found a OopPtr type vs self-AryPtr type 4286 const TypeOopPtr *tp = t->is_oopptr(); 4287 Offset offset = meet_offset(tp->offset()); 4288 PTR ptr = meet_ptr(tp->ptr()); 4289 int depth = meet_inline_depth(tp->inline_depth()); 4290 const TypePtr* speculative = xmeet_speculative(tp); 4291 switch (tp->ptr()) { 4292 case TopPTR: 4293 case AnyNull: { 4294 int instance_id = meet_instance_id(InstanceTop); 4295 return make(ptr, (ptr == Constant ? const_oop() : NULL), 4296 _ary, _klass, _klass_is_exact, offset, _field_offset, instance_id, speculative, depth); 4297 } 4298 case BotPTR: 4299 case NotNull: { 4300 int instance_id = meet_instance_id(tp->instance_id()); 4301 return TypeOopPtr::make(ptr, offset, instance_id, speculative, depth); 4302 } 4303 default: ShouldNotReachHere(); 4304 } 4305 } 4306 4307 case AnyPtr: { // Meeting two AnyPtrs 4308 // Found an AnyPtr type vs self-AryPtr type 4309 const TypePtr *tp = t->is_ptr(); 4310 Offset offset = meet_offset(tp->offset()); 4311 PTR ptr = meet_ptr(tp->ptr()); 4312 const TypePtr* speculative = xmeet_speculative(tp); 4313 int depth = meet_inline_depth(tp->inline_depth()); 4314 switch (tp->ptr()) { 4315 case TopPTR: 4316 return this; 4317 case BotPTR: 4318 case NotNull: 4319 return TypePtr::make(AnyPtr, ptr, offset, speculative, depth); 4320 case Null: 4321 if( ptr == Null ) return TypePtr::make(AnyPtr, ptr, offset, speculative, depth); 4322 // else fall through to AnyNull 4323 case AnyNull: { 4324 int instance_id = meet_instance_id(InstanceTop); 4325 return make(ptr, (ptr == Constant ? const_oop() : NULL), 4326 _ary, _klass, _klass_is_exact, offset, _field_offset, instance_id, speculative, depth); 4327 } 4328 default: ShouldNotReachHere(); 4329 } 4330 } 4331 4332 case MetadataPtr: 4333 case KlassPtr: 4334 case RawPtr: return TypePtr::BOTTOM; 4335 4336 case AryPtr: { // Meeting 2 references? 4337 const TypeAryPtr *tap = t->is_aryptr(); 4338 Offset off = meet_offset(tap->offset()); 4339 Offset field_off = meet_field_offset(tap->field_offset()); 4340 const TypeAry *tary = _ary->meet_speculative(tap->_ary)->is_ary(); 4341 PTR ptr = meet_ptr(tap->ptr()); 4342 int instance_id = meet_instance_id(tap->instance_id()); 4343 const TypePtr* speculative = xmeet_speculative(tap); 4344 int depth = meet_inline_depth(tap->inline_depth()); 4345 ciKlass* lazy_klass = NULL; 4346 if (tary->_elem->isa_int()) { 4347 // Integral array element types have irrelevant lattice relations. 4348 // It is the klass that determines array layout, not the element type. 4349 if (_klass == NULL) 4350 lazy_klass = tap->_klass; 4351 else if (tap->_klass == NULL || tap->_klass == _klass) { 4352 lazy_klass = _klass; 4353 } else { 4354 // Something like byte[int+] meets char[int+]. 4355 // This must fall to bottom, not (int[-128..65535])[int+]. 4356 instance_id = InstanceBot; 4357 tary = TypeAry::make(Type::BOTTOM, tary->_size, tary->_stable); 4358 } 4359 } else // Non integral arrays. 4360 // Must fall to bottom if exact klasses in upper lattice 4361 // are not equal or super klass is exact. 4362 if ((above_centerline(ptr) || ptr == Constant) && klass() != tap->klass() && 4363 // meet with top[] and bottom[] are processed further down: 4364 tap->_klass != NULL && this->_klass != NULL && 4365 // both are exact and not equal: 4366 ((tap->_klass_is_exact && this->_klass_is_exact) || 4367 // 'tap' is exact and super or unrelated: 4368 (tap->_klass_is_exact && !tap->klass()->is_subtype_of(klass())) || 4369 // 'this' is exact and super or unrelated: 4370 (this->_klass_is_exact && !klass()->is_subtype_of(tap->klass())))) { 4371 if (above_centerline(ptr)) { 4372 tary = TypeAry::make(Type::BOTTOM, tary->_size, tary->_stable); 4373 } 4374 return make(NotNull, NULL, tary, lazy_klass, false, off, field_off, InstanceBot, speculative, depth); 4375 } 4376 4377 bool xk = false; 4378 switch (tap->ptr()) { 4379 case AnyNull: 4380 case TopPTR: 4381 // Compute new klass on demand, do not use tap->_klass 4382 if (below_centerline(this->_ptr)) { 4383 xk = this->_klass_is_exact; 4384 } else { 4385 xk = (tap->_klass_is_exact | this->_klass_is_exact); 4386 } 4387 return make(ptr, const_oop(), tary, lazy_klass, xk, off, field_off, instance_id, speculative, depth); 4388 case Constant: { 4389 ciObject* o = const_oop(); 4390 if( _ptr == Constant ) { 4391 if( tap->const_oop() != NULL && !o->equals(tap->const_oop()) ) { 4392 xk = (klass() == tap->klass()); 4393 ptr = NotNull; 4394 o = NULL; 4395 instance_id = InstanceBot; 4396 } else { 4397 xk = true; 4398 } 4399 } else if(above_centerline(_ptr)) { 4400 o = tap->const_oop(); 4401 xk = true; 4402 } else { 4403 // Only precise for identical arrays 4404 xk = this->_klass_is_exact && (klass() == tap->klass()); 4405 } 4406 return TypeAryPtr::make(ptr, o, tary, lazy_klass, xk, off, field_off, instance_id, speculative, depth); 4407 } 4408 case NotNull: 4409 case BotPTR: 4410 // Compute new klass on demand, do not use tap->_klass 4411 if (above_centerline(this->_ptr)) 4412 xk = tap->_klass_is_exact; 4413 else xk = (tap->_klass_is_exact & this->_klass_is_exact) && 4414 (klass() == tap->klass()); // Only precise for identical arrays 4415 return TypeAryPtr::make(ptr, NULL, tary, lazy_klass, xk, off, field_off, instance_id, speculative, depth); 4416 default: ShouldNotReachHere(); 4417 } 4418 } 4419 4420 // All arrays inherit from Object class 4421 case InstPtr: { 4422 const TypeInstPtr *tp = t->is_instptr(); 4423 Offset offset = meet_offset(tp->offset()); 4424 PTR ptr = meet_ptr(tp->ptr()); 4425 int instance_id = meet_instance_id(tp->instance_id()); 4426 const TypePtr* speculative = xmeet_speculative(tp); 4427 int depth = meet_inline_depth(tp->inline_depth()); 4428 switch (ptr) { 4429 case TopPTR: 4430 case AnyNull: // Fall 'down' to dual of object klass 4431 // For instances when a subclass meets a superclass we fall 4432 // below the centerline when the superclass is exact. We need to 4433 // do the same here. 4434 if (tp->klass()->equals(ciEnv::current()->Object_klass()) && !tp->klass_is_exact()) { 4435 return TypeAryPtr::make(ptr, _ary, _klass, _klass_is_exact, offset, _field_offset, instance_id, speculative, depth); 4436 } else { 4437 // cannot subclass, so the meet has to fall badly below the centerline 4438 ptr = NotNull; 4439 instance_id = InstanceBot; 4440 return TypeInstPtr::make(ptr, ciEnv::current()->Object_klass(), false, NULL,offset, instance_id, speculative, depth); 4441 } 4442 case Constant: 4443 case NotNull: 4444 case BotPTR: // Fall down to object klass 4445 // LCA is object_klass, but if we subclass from the top we can do better 4446 if (above_centerline(tp->ptr())) { 4447 // If 'tp' is above the centerline and it is Object class 4448 // then we can subclass in the Java class hierarchy. 4449 // For instances when a subclass meets a superclass we fall 4450 // below the centerline when the superclass is exact. We need 4451 // to do the same here. 4452 if (tp->klass()->equals(ciEnv::current()->Object_klass()) && !tp->klass_is_exact()) { 4453 // that is, my array type is a subtype of 'tp' klass 4454 return make(ptr, (ptr == Constant ? const_oop() : NULL), 4455 _ary, _klass, _klass_is_exact, offset, _field_offset, instance_id, speculative, depth); 4456 } 4457 } 4458 // The other case cannot happen, since t cannot be a subtype of an array. 4459 // The meet falls down to Object class below centerline. 4460 if( ptr == Constant ) 4461 ptr = NotNull; 4462 instance_id = InstanceBot; 4463 return TypeInstPtr::make(ptr, ciEnv::current()->Object_klass(), false, NULL,offset, instance_id, speculative, depth); 4464 default: typerr(t); 4465 } 4466 } 4467 } 4468 return this; // Lint noise 4469 } 4470 4471 //------------------------------xdual------------------------------------------ 4472 // Dual: compute field-by-field dual 4473 const Type *TypeAryPtr::xdual() const { 4474 return new TypeAryPtr(dual_ptr(), _const_oop, _ary->dual()->is_ary(),_klass, _klass_is_exact, dual_offset(), dual_field_offset(), dual_instance_id(), is_autobox_cache(), dual_speculative(), dual_inline_depth()); 4475 } 4476 4477 Type::Offset TypeAryPtr::meet_field_offset(int field_offset) const { 4478 return _field_offset.meet(Offset(field_offset)); 4479 } 4480 4481 //------------------------------dual_offset------------------------------------ 4482 Type::Offset TypeAryPtr::dual_field_offset() const { 4483 return _field_offset.dual(); 4484 } 4485 4486 //----------------------interface_vs_oop--------------------------------------- 4487 #ifdef ASSERT 4488 bool TypeAryPtr::interface_vs_oop(const Type *t) const { 4489 const TypeAryPtr* t_aryptr = t->isa_aryptr(); 4490 if (t_aryptr) { 4491 return _ary->interface_vs_oop(t_aryptr->_ary); 4492 } 4493 return false; 4494 } 4495 #endif 4496 4497 //------------------------------dump2------------------------------------------ 4498 #ifndef PRODUCT 4499 void TypeAryPtr::dump2( Dict &d, uint depth, outputStream *st ) const { 4500 _ary->dump2(d,depth,st); 4501 switch( _ptr ) { 4502 case Constant: 4503 const_oop()->print(st); 4504 break; 4505 case BotPTR: 4506 if (!WizardMode && !Verbose) { 4507 if( _klass_is_exact ) st->print(":exact"); 4508 break; 4509 } 4510 case TopPTR: 4511 case AnyNull: 4512 case NotNull: 4513 st->print(":%s", ptr_msg[_ptr]); 4514 if( _klass_is_exact ) st->print(":exact"); 4515 break; 4516 } 4517 4518 if (elem()->isa_valuetype()) { 4519 st->print("("); 4520 _field_offset.dump2(st); 4521 st->print(")"); 4522 } 4523 if (offset() != 0) { 4524 int header_size = objArrayOopDesc::header_size() * wordSize; 4525 if( _offset == Offset::top ) st->print("+undefined"); 4526 else if( _offset == Offset::bottom ) st->print("+any"); 4527 else if( offset() < header_size ) st->print("+%d", offset()); 4528 else { 4529 BasicType basic_elem_type = elem()->basic_type(); 4530 int array_base = arrayOopDesc::base_offset_in_bytes(basic_elem_type); 4531 int elem_size = type2aelembytes(basic_elem_type); 4532 st->print("[%d]", (offset() - array_base)/elem_size); 4533 } 4534 } 4535 st->print(" *"); 4536 if (_instance_id == InstanceTop) 4537 st->print(",iid=top"); 4538 else if (_instance_id != InstanceBot) 4539 st->print(",iid=%d",_instance_id); 4540 4541 dump_inline_depth(st); 4542 dump_speculative(st); 4543 } 4544 #endif 4545 4546 bool TypeAryPtr::empty(void) const { 4547 if (_ary->empty()) return true; 4548 return TypeOopPtr::empty(); 4549 } 4550 4551 //------------------------------add_offset------------------------------------- 4552 const TypePtr *TypeAryPtr::add_offset(intptr_t offset) const { 4553 return make(_ptr, _const_oop, _ary, _klass, _klass_is_exact, xadd_offset(offset), _field_offset, _instance_id, add_offset_speculative(offset), _inline_depth, _is_autobox_cache); 4554 } 4555 4556 const Type *TypeAryPtr::remove_speculative() const { 4557 if (_speculative == NULL) { 4558 return this; 4559 } 4560 assert(_inline_depth == InlineDepthTop || _inline_depth == InlineDepthBottom, "non speculative type shouldn't have inline depth"); 4561 return make(_ptr, _const_oop, _ary->remove_speculative()->is_ary(), _klass, _klass_is_exact, _offset, _field_offset, _instance_id, NULL, _inline_depth, _is_autobox_cache); 4562 } 4563 4564 const TypePtr *TypeAryPtr::with_inline_depth(int depth) const { 4565 if (!UseInlineDepthForSpeculativeTypes) { 4566 return this; 4567 } 4568 return make(_ptr, _const_oop, _ary->remove_speculative()->is_ary(), _klass, _klass_is_exact, _offset, _field_offset, _instance_id, _speculative, depth, _is_autobox_cache); 4569 } 4570 4571 const TypeAryPtr* TypeAryPtr::with_field_offset(int offset) const { 4572 return make(_ptr, _const_oop, _ary->remove_speculative()->is_ary(), _klass, _klass_is_exact, _offset, Offset(offset), _instance_id, _speculative, _inline_depth, _is_autobox_cache); 4573 } 4574 4575 const TypePtr* TypeAryPtr::with_field_offset_and_offset(intptr_t offset) const { 4576 if (offset != Type::OffsetBot) { 4577 const Type* elemtype = elem(); 4578 if (elemtype->isa_valuetype()) { 4579 uint header = arrayOopDesc::base_offset_in_bytes(T_OBJECT); 4580 if (offset >= (intptr_t)header) { 4581 ciKlass* arytype_klass = klass(); 4582 ciValueArrayKlass* vak = arytype_klass->as_value_array_klass(); 4583 int shift = vak->log2_element_size(); 4584 intptr_t field_offset = ((offset - header) & ((1 << shift) - 1)); 4585 4586 return with_field_offset(field_offset)->add_offset(offset - field_offset); 4587 } 4588 } 4589 } 4590 return add_offset(offset); 4591 } 4592 4593 //============================================================================= 4594 4595 4596 //============================================================================= 4597 4598 //------------------------------make------------------------------------------- 4599 const TypeValueTypePtr* TypeValueTypePtr::make(const TypeValueType* vt, PTR ptr, ciObject* o, Offset offset, int instance_id, const TypePtr* speculative, int inline_depth) { 4600 return (TypeValueTypePtr*)(new TypeValueTypePtr(vt, ptr, o, offset, instance_id, speculative, inline_depth))->hashcons(); 4601 } 4602 4603 const TypePtr* TypeValueTypePtr::add_offset(intptr_t offset) const { 4604 return make(_vt, _ptr, _const_oop, Offset(offset), _instance_id, _speculative, _inline_depth); 4605 } 4606 4607 //------------------------------cast_to_ptr_type------------------------------- 4608 const Type* TypeValueTypePtr::cast_to_ptr_type(PTR ptr) const { 4609 if (ptr == _ptr) return this; 4610 return make(_vt, ptr, _const_oop, _offset, _instance_id, _speculative, _inline_depth); 4611 } 4612 4613 //-----------------------------cast_to_instance_id---------------------------- 4614 const TypeOopPtr* TypeValueTypePtr::cast_to_instance_id(int instance_id) const { 4615 if (instance_id == _instance_id) return this; 4616 return make(_vt, _ptr, _const_oop, _offset, instance_id, _speculative, _inline_depth); 4617 } 4618 4619 //------------------------------meet------------------------------------------- 4620 // Compute the MEET of two types. It returns a new Type object. 4621 const Type* TypeValueTypePtr::xmeet_helper(const Type* t) const { 4622 // Perform a fast test for common case; meeting the same types together. 4623 if (this == t) return this; // Meeting same type-rep? 4624 4625 switch (t->base()) { // switch on original type 4626 case Int: // Mixing ints & oops happens when javac 4627 case Long: // reuses local variables 4628 case FloatTop: 4629 case FloatCon: 4630 case FloatBot: 4631 case DoubleTop: 4632 case DoubleCon: 4633 case DoubleBot: 4634 case NarrowOop: 4635 case NarrowKlass: 4636 case MetadataPtr: 4637 case KlassPtr: 4638 case RawPtr: 4639 case AryPtr: 4640 case InstPtr: 4641 case Bottom: // Ye Olde Default 4642 return Type::BOTTOM; 4643 case Top: 4644 return this; 4645 4646 default: // All else is a mistake 4647 typerr(t); 4648 4649 case OopPtr: { 4650 // Found a OopPtr type vs self-ValueTypePtr type 4651 const TypeOopPtr* tp = t->is_oopptr(); 4652 Offset offset = meet_offset(tp->offset()); 4653 PTR ptr = meet_ptr(tp->ptr()); 4654 int instance_id = meet_instance_id(tp->instance_id()); 4655 const TypePtr* speculative = xmeet_speculative(tp); 4656 int depth = meet_inline_depth(tp->inline_depth()); 4657 switch (tp->ptr()) { 4658 case TopPTR: 4659 case AnyNull: { 4660 return make(_vt, ptr, NULL, offset, instance_id, speculative, depth); 4661 } 4662 case NotNull: 4663 case BotPTR: { 4664 return TypeOopPtr::make(ptr, offset, instance_id, speculative, depth); 4665 } 4666 default: typerr(t); 4667 } 4668 } 4669 4670 case AnyPtr: { 4671 // Found an AnyPtr type vs self-ValueTypePtr type 4672 const TypePtr* tp = t->is_ptr(); 4673 Offset offset = meet_offset(tp->offset()); 4674 PTR ptr = meet_ptr(tp->ptr()); 4675 int instance_id = meet_instance_id(InstanceTop); 4676 const TypePtr* speculative = xmeet_speculative(tp); 4677 int depth = meet_inline_depth(tp->inline_depth()); 4678 switch (tp->ptr()) { 4679 case Null: 4680 if( ptr == Null ) return TypePtr::make(AnyPtr, ptr, offset, speculative, depth); 4681 // else fall through to AnyNull 4682 case TopPTR: 4683 case AnyNull: { 4684 return make(_vt, ptr, NULL, offset, instance_id, speculative, depth); 4685 } 4686 case NotNull: 4687 case BotPTR: 4688 return TypePtr::make(AnyPtr, ptr, offset, speculative, depth); 4689 default: typerr(t); 4690 } 4691 } 4692 4693 case ValueTypePtr: { 4694 // Found an ValueTypePtr type vs self-ValueTypePtr type 4695 const TypeValueTypePtr* tp = t->is_valuetypeptr(); 4696 Offset offset = meet_offset(tp->offset()); 4697 PTR ptr = meet_ptr(tp->ptr()); 4698 int instance_id = meet_instance_id(InstanceTop); 4699 const TypePtr* speculative = xmeet_speculative(tp); 4700 int depth = meet_inline_depth(tp->inline_depth()); 4701 // Compute constant oop 4702 ciObject* o = NULL; 4703 ciObject* this_oop = const_oop(); 4704 ciObject* tp_oop = tp->const_oop(); 4705 if (ptr == Constant) { 4706 if (this_oop != NULL && tp_oop != NULL && 4707 this_oop->equals(tp_oop) ) { 4708 o = this_oop; 4709 } else if (above_centerline(this ->_ptr)) { 4710 o = tp_oop; 4711 } else if (above_centerline(tp ->_ptr)) { 4712 o = this_oop; 4713 } else { 4714 ptr = NotNull; 4715 } 4716 } 4717 return make(_vt, ptr, o, offset, instance_id, speculative, depth); 4718 } 4719 } 4720 } 4721 4722 // Dual: compute field-by-field dual 4723 const Type* TypeValueTypePtr::xdual() const { 4724 return new TypeValueTypePtr(_vt, dual_ptr(), const_oop(), dual_offset(), dual_instance_id(), dual_speculative(), dual_inline_depth()); 4725 } 4726 4727 //------------------------------eq--------------------------------------------- 4728 // Structural equality check for Type representations 4729 bool TypeValueTypePtr::eq(const Type* t) const { 4730 const TypeValueTypePtr* p = t->is_valuetypeptr(); 4731 return _vt->eq(p->value_type()) && TypeOopPtr::eq(p); 4732 } 4733 4734 //------------------------------hash------------------------------------------- 4735 // Type-specific hashing function. 4736 int TypeValueTypePtr::hash(void) const { 4737 return java_add(_vt->hash(), TypeOopPtr::hash()); 4738 } 4739 4740 //------------------------------empty------------------------------------------ 4741 // TRUE if Type is a type with no values, FALSE otherwise. 4742 bool TypeValueTypePtr::empty(void) const { 4743 // FIXME 4744 return false; 4745 } 4746 4747 //------------------------------dump2------------------------------------------ 4748 #ifndef PRODUCT 4749 void TypeValueTypePtr::dump2(Dict &d, uint depth, outputStream *st) const { 4750 st->print("valuetype* "); 4751 klass()->print_name_on(st); 4752 st->print(":%s", ptr_msg[_ptr]); 4753 _offset.dump2(st); 4754 } 4755 #endif 4756 4757 //============================================================================= 4758 4759 //------------------------------hash------------------------------------------- 4760 // Type-specific hashing function. 4761 int TypeNarrowPtr::hash(void) const { 4762 return _ptrtype->hash() + 7; 4763 } 4764 4765 bool TypeNarrowPtr::singleton(void) const { // TRUE if type is a singleton 4766 return _ptrtype->singleton(); 4767 } 4768 4769 bool TypeNarrowPtr::empty(void) const { 4770 return _ptrtype->empty(); 4771 } 4772 4773 intptr_t TypeNarrowPtr::get_con() const { 4774 return _ptrtype->get_con(); 4775 } 4776 4777 bool TypeNarrowPtr::eq( const Type *t ) const { 4778 const TypeNarrowPtr* tc = isa_same_narrowptr(t); 4779 if (tc != NULL) { 4780 if (_ptrtype->base() != tc->_ptrtype->base()) { 4781 return false; 4782 } 4783 return tc->_ptrtype->eq(_ptrtype); 4784 } 4785 return false; 4786 } 4787 4788 const Type *TypeNarrowPtr::xdual() const { // Compute dual right now. 4789 const TypePtr* odual = _ptrtype->dual()->is_ptr(); 4790 return make_same_narrowptr(odual); 4791 } 4792 4793 4794 const Type *TypeNarrowPtr::filter_helper(const Type *kills, bool include_speculative) const { 4795 if (isa_same_narrowptr(kills)) { 4796 const Type* ft =_ptrtype->filter_helper(is_same_narrowptr(kills)->_ptrtype, include_speculative); 4797 if (ft->empty()) 4798 return Type::TOP; // Canonical empty value 4799 if (ft->isa_ptr()) { 4800 return make_hash_same_narrowptr(ft->isa_ptr()); 4801 } 4802 return ft; 4803 } else if (kills->isa_ptr()) { 4804 const Type* ft = _ptrtype->join_helper(kills, include_speculative); 4805 if (ft->empty()) 4806 return Type::TOP; // Canonical empty value 4807 return ft; 4808 } else { 4809 return Type::TOP; 4810 } 4811 } 4812 4813 //------------------------------xmeet------------------------------------------ 4814 // Compute the MEET of two types. It returns a new Type object. 4815 const Type *TypeNarrowPtr::xmeet( const Type *t ) const { 4816 // Perform a fast test for common case; meeting the same types together. 4817 if( this == t ) return this; // Meeting same type-rep? 4818 4819 if (t->base() == base()) { 4820 const Type* result = _ptrtype->xmeet(t->make_ptr()); 4821 if (result->isa_ptr()) { 4822 return make_hash_same_narrowptr(result->is_ptr()); 4823 } 4824 return result; 4825 } 4826 4827 // Current "this->_base" is NarrowKlass or NarrowOop 4828 switch (t->base()) { // switch on original type 4829 4830 case Int: // Mixing ints & oops happens when javac 4831 case Long: // reuses local variables 4832 case FloatTop: 4833 case FloatCon: 4834 case FloatBot: 4835 case DoubleTop: 4836 case DoubleCon: 4837 case DoubleBot: 4838 case AnyPtr: 4839 case RawPtr: 4840 case OopPtr: 4841 case InstPtr: 4842 case ValueTypePtr: 4843 case AryPtr: 4844 case MetadataPtr: 4845 case KlassPtr: 4846 case NarrowOop: 4847 case NarrowKlass: 4848 4849 case Bottom: // Ye Olde Default 4850 return Type::BOTTOM; 4851 case Top: 4852 return this; 4853 4854 default: // All else is a mistake 4855 typerr(t); 4856 4857 } // End of switch 4858 4859 return this; 4860 } 4861 4862 #ifndef PRODUCT 4863 void TypeNarrowPtr::dump2( Dict & d, uint depth, outputStream *st ) const { 4864 _ptrtype->dump2(d, depth, st); 4865 } 4866 #endif 4867 4868 const TypeNarrowOop *TypeNarrowOop::BOTTOM; 4869 const TypeNarrowOop *TypeNarrowOop::NULL_PTR; 4870 4871 4872 const TypeNarrowOop* TypeNarrowOop::make(const TypePtr* type) { 4873 return (const TypeNarrowOop*)(new TypeNarrowOop(type))->hashcons(); 4874 } 4875 4876 const Type* TypeNarrowOop::remove_speculative() const { 4877 return make(_ptrtype->remove_speculative()->is_ptr()); 4878 } 4879 4880 const Type* TypeNarrowOop::cleanup_speculative() const { 4881 return make(_ptrtype->cleanup_speculative()->is_ptr()); 4882 } 4883 4884 #ifndef PRODUCT 4885 void TypeNarrowOop::dump2( Dict & d, uint depth, outputStream *st ) const { 4886 st->print("narrowoop: "); 4887 TypeNarrowPtr::dump2(d, depth, st); 4888 } 4889 #endif 4890 4891 const TypeNarrowKlass *TypeNarrowKlass::NULL_PTR; 4892 4893 const TypeNarrowKlass* TypeNarrowKlass::make(const TypePtr* type) { 4894 return (const TypeNarrowKlass*)(new TypeNarrowKlass(type))->hashcons(); 4895 } 4896 4897 #ifndef PRODUCT 4898 void TypeNarrowKlass::dump2( Dict & d, uint depth, outputStream *st ) const { 4899 st->print("narrowklass: "); 4900 TypeNarrowPtr::dump2(d, depth, st); 4901 } 4902 #endif 4903 4904 4905 //------------------------------eq--------------------------------------------- 4906 // Structural equality check for Type representations 4907 bool TypeMetadataPtr::eq( const Type *t ) const { 4908 const TypeMetadataPtr *a = (const TypeMetadataPtr*)t; 4909 ciMetadata* one = metadata(); 4910 ciMetadata* two = a->metadata(); 4911 if (one == NULL || two == NULL) { 4912 return (one == two) && TypePtr::eq(t); 4913 } else { 4914 return one->equals(two) && TypePtr::eq(t); 4915 } 4916 } 4917 4918 //------------------------------hash------------------------------------------- 4919 // Type-specific hashing function. 4920 int TypeMetadataPtr::hash(void) const { 4921 return 4922 (metadata() ? metadata()->hash() : 0) + 4923 TypePtr::hash(); 4924 } 4925 4926 //------------------------------singleton-------------------------------------- 4927 // TRUE if Type is a singleton type, FALSE otherwise. Singletons are simple 4928 // constants 4929 bool TypeMetadataPtr::singleton(void) const { 4930 // detune optimizer to not generate constant metadata + constant offset as a constant! 4931 // TopPTR, Null, AnyNull, Constant are all singletons 4932 return (offset() == 0) && !below_centerline(_ptr); 4933 } 4934 4935 //------------------------------add_offset------------------------------------- 4936 const TypePtr *TypeMetadataPtr::add_offset( intptr_t offset ) const { 4937 return make( _ptr, _metadata, xadd_offset(offset)); 4938 } 4939 4940 //-----------------------------filter------------------------------------------ 4941 // Do not allow interface-vs.-noninterface joins to collapse to top. 4942 const Type *TypeMetadataPtr::filter_helper(const Type *kills, bool include_speculative) const { 4943 const TypeMetadataPtr* ft = join_helper(kills, include_speculative)->isa_metadataptr(); 4944 if (ft == NULL || ft->empty()) 4945 return Type::TOP; // Canonical empty value 4946 return ft; 4947 } 4948 4949 //------------------------------get_con---------------------------------------- 4950 intptr_t TypeMetadataPtr::get_con() const { 4951 assert( _ptr == Null || _ptr == Constant, "" ); 4952 assert(offset() >= 0, ""); 4953 4954 if (offset() != 0) { 4955 // After being ported to the compiler interface, the compiler no longer 4956 // directly manipulates the addresses of oops. Rather, it only has a pointer 4957 // to a handle at compile time. This handle is embedded in the generated 4958 // code and dereferenced at the time the nmethod is made. Until that time, 4959 // it is not reasonable to do arithmetic with the addresses of oops (we don't 4960 // have access to the addresses!). This does not seem to currently happen, 4961 // but this assertion here is to help prevent its occurence. 4962 tty->print_cr("Found oop constant with non-zero offset"); 4963 ShouldNotReachHere(); 4964 } 4965 4966 return (intptr_t)metadata()->constant_encoding(); 4967 } 4968 4969 //------------------------------cast_to_ptr_type------------------------------- 4970 const Type *TypeMetadataPtr::cast_to_ptr_type(PTR ptr) const { 4971 if( ptr == _ptr ) return this; 4972 return make(ptr, metadata(), _offset); 4973 } 4974 4975 //------------------------------meet------------------------------------------- 4976 // Compute the MEET of two types. It returns a new Type object. 4977 const Type *TypeMetadataPtr::xmeet( const Type *t ) const { 4978 // Perform a fast test for common case; meeting the same types together. 4979 if( this == t ) return this; // Meeting same type-rep? 4980 4981 // Current "this->_base" is OopPtr 4982 switch (t->base()) { // switch on original type 4983 4984 case Int: // Mixing ints & oops happens when javac 4985 case Long: // reuses local variables 4986 case FloatTop: 4987 case FloatCon: 4988 case FloatBot: 4989 case DoubleTop: 4990 case DoubleCon: 4991 case DoubleBot: 4992 case NarrowOop: 4993 case NarrowKlass: 4994 case Bottom: // Ye Olde Default 4995 return Type::BOTTOM; 4996 case Top: 4997 return this; 4998 4999 default: // All else is a mistake 5000 typerr(t); 5001 5002 case AnyPtr: { 5003 // Found an AnyPtr type vs self-OopPtr type 5004 const TypePtr *tp = t->is_ptr(); 5005 Offset offset = meet_offset(tp->offset()); 5006 PTR ptr = meet_ptr(tp->ptr()); 5007 switch (tp->ptr()) { 5008 case Null: 5009 if (ptr == Null) return TypePtr::make(AnyPtr, ptr, offset, tp->speculative(), tp->inline_depth()); 5010 // else fall through: 5011 case TopPTR: 5012 case AnyNull: { 5013 return make(ptr, _metadata, offset); 5014 } 5015 case BotPTR: 5016 case NotNull: 5017 return TypePtr::make(AnyPtr, ptr, offset, tp->speculative(), tp->inline_depth()); 5018 default: typerr(t); 5019 } 5020 } 5021 5022 case RawPtr: 5023 case KlassPtr: 5024 case OopPtr: 5025 case InstPtr: 5026 case ValueTypePtr: 5027 case AryPtr: 5028 return TypePtr::BOTTOM; // Oop meet raw is not well defined 5029 5030 case MetadataPtr: { 5031 const TypeMetadataPtr *tp = t->is_metadataptr(); 5032 Offset offset = meet_offset(tp->offset()); 5033 PTR tptr = tp->ptr(); 5034 PTR ptr = meet_ptr(tptr); 5035 ciMetadata* md = (tptr == TopPTR) ? metadata() : tp->metadata(); 5036 if (tptr == TopPTR || _ptr == TopPTR || 5037 metadata()->equals(tp->metadata())) { 5038 return make(ptr, md, offset); 5039 } 5040 // metadata is different 5041 if( ptr == Constant ) { // Cannot be equal constants, so... 5042 if( tptr == Constant && _ptr != Constant) return t; 5043 if( _ptr == Constant && tptr != Constant) return this; 5044 ptr = NotNull; // Fall down in lattice 5045 } 5046 return make(ptr, NULL, offset); 5047 break; 5048 } 5049 } // End of switch 5050 return this; // Return the double constant 5051 } 5052 5053 5054 //------------------------------xdual------------------------------------------ 5055 // Dual of a pure metadata pointer. 5056 const Type *TypeMetadataPtr::xdual() const { 5057 return new TypeMetadataPtr(dual_ptr(), metadata(), dual_offset()); 5058 } 5059 5060 //------------------------------dump2------------------------------------------ 5061 #ifndef PRODUCT 5062 void TypeMetadataPtr::dump2( Dict &d, uint depth, outputStream *st ) const { 5063 st->print("metadataptr:%s", ptr_msg[_ptr]); 5064 if( metadata() ) st->print(INTPTR_FORMAT, p2i(metadata())); 5065 switch (offset()) { 5066 case OffsetTop: st->print("+top"); break; 5067 case OffsetBot: st->print("+any"); break; 5068 case 0: break; 5069 default: st->print("+%d",offset()); break; 5070 } 5071 } 5072 #endif 5073 5074 5075 //============================================================================= 5076 // Convenience common pre-built type. 5077 const TypeMetadataPtr *TypeMetadataPtr::BOTTOM; 5078 5079 TypeMetadataPtr::TypeMetadataPtr(PTR ptr, ciMetadata* metadata, Offset offset): 5080 TypePtr(MetadataPtr, ptr, offset), _metadata(metadata) { 5081 } 5082 5083 const TypeMetadataPtr* TypeMetadataPtr::make(ciMethod* m) { 5084 return make(Constant, m, Offset(0)); 5085 } 5086 const TypeMetadataPtr* TypeMetadataPtr::make(ciMethodData* m) { 5087 return make(Constant, m, Offset(0)); 5088 } 5089 5090 //------------------------------make------------------------------------------- 5091 // Create a meta data constant 5092 const TypeMetadataPtr* TypeMetadataPtr::make(PTR ptr, ciMetadata* m, Offset offset) { 5093 assert(m == NULL || !m->is_klass(), "wrong type"); 5094 return (TypeMetadataPtr*)(new TypeMetadataPtr(ptr, m, offset))->hashcons(); 5095 } 5096 5097 5098 //============================================================================= 5099 // Convenience common pre-built types. 5100 5101 // Not-null object klass or below 5102 const TypeKlassPtr *TypeKlassPtr::OBJECT; 5103 const TypeKlassPtr *TypeKlassPtr::OBJECT_OR_NULL; 5104 5105 //------------------------------TypeKlassPtr----------------------------------- 5106 TypeKlassPtr::TypeKlassPtr( PTR ptr, ciKlass* klass, Offset offset ) 5107 : TypePtr(KlassPtr, ptr, offset), _klass(klass), _klass_is_exact(ptr == Constant) { 5108 } 5109 5110 //------------------------------make------------------------------------------- 5111 // ptr to klass 'k', if Constant, or possibly to a sub-klass if not a Constant 5112 const TypeKlassPtr* TypeKlassPtr::make(PTR ptr, ciKlass* k, Offset offset) { 5113 assert( k != NULL, "Expect a non-NULL klass"); 5114 assert(k->is_instance_klass() || k->is_array_klass(), "Incorrect type of klass oop"); 5115 TypeKlassPtr *r = 5116 (TypeKlassPtr*)(new TypeKlassPtr(ptr, k, offset))->hashcons(); 5117 5118 return r; 5119 } 5120 5121 //------------------------------eq--------------------------------------------- 5122 // Structural equality check for Type representations 5123 bool TypeKlassPtr::eq( const Type *t ) const { 5124 const TypeKlassPtr *p = t->is_klassptr(); 5125 return 5126 klass()->equals(p->klass()) && 5127 TypePtr::eq(p); 5128 } 5129 5130 //------------------------------hash------------------------------------------- 5131 // Type-specific hashing function. 5132 int TypeKlassPtr::hash(void) const { 5133 return java_add(klass()->hash(), TypePtr::hash()); 5134 } 5135 5136 //------------------------------singleton-------------------------------------- 5137 // TRUE if Type is a singleton type, FALSE otherwise. Singletons are simple 5138 // constants 5139 bool TypeKlassPtr::singleton(void) const { 5140 // detune optimizer to not generate constant klass + constant offset as a constant! 5141 // TopPTR, Null, AnyNull, Constant are all singletons 5142 return (offset() == 0) && !below_centerline(_ptr); 5143 } 5144 5145 // Do not allow interface-vs.-noninterface joins to collapse to top. 5146 const Type *TypeKlassPtr::filter_helper(const Type *kills, bool include_speculative) const { 5147 // logic here mirrors the one from TypeOopPtr::filter. See comments 5148 // there. 5149 const Type* ft = join_helper(kills, include_speculative); 5150 const TypeKlassPtr* ftkp = ft->isa_klassptr(); 5151 const TypeKlassPtr* ktkp = kills->isa_klassptr(); 5152 5153 if (ft->empty()) { 5154 if (!empty() && ktkp != NULL && ktkp->klass()->is_loaded() && ktkp->klass()->is_interface()) 5155 return kills; // Uplift to interface 5156 5157 return Type::TOP; // Canonical empty value 5158 } 5159 5160 // Interface klass type could be exact in opposite to interface type, 5161 // return it here instead of incorrect Constant ptr J/L/Object (6894807). 5162 if (ftkp != NULL && ktkp != NULL && 5163 ftkp->is_loaded() && ftkp->klass()->is_interface() && 5164 !ftkp->klass_is_exact() && // Keep exact interface klass 5165 ktkp->is_loaded() && !ktkp->klass()->is_interface()) { 5166 return ktkp->cast_to_ptr_type(ftkp->ptr()); 5167 } 5168 5169 return ft; 5170 } 5171 5172 //----------------------compute_klass------------------------------------------ 5173 // Compute the defining klass for this class 5174 ciKlass* TypeAryPtr::compute_klass(DEBUG_ONLY(bool verify)) const { 5175 // Compute _klass based on element type. 5176 ciKlass* k_ary = NULL; 5177 const TypeAryPtr *tary; 5178 const Type* el = elem(); 5179 if (el->isa_narrowoop()) { 5180 el = el->make_ptr(); 5181 } 5182 5183 // Get element klass 5184 if (el->isa_instptr() || el->isa_valuetypeptr()) { 5185 // Compute object array klass from element klass 5186 k_ary = ciArrayKlass::make(el->is_oopptr()->klass()); 5187 } else if (el->isa_valuetype()) { 5188 k_ary = ciArrayKlass::make(el->is_valuetype()->value_klass()); 5189 } else if ((tary = el->isa_aryptr()) != NULL) { 5190 // Compute array klass from element klass 5191 ciKlass* k_elem = tary->klass(); 5192 // If element type is something like bottom[], k_elem will be null. 5193 if (k_elem != NULL) 5194 k_ary = ciObjArrayKlass::make(k_elem); 5195 } else if ((el->base() == Type::Top) || 5196 (el->base() == Type::Bottom)) { 5197 // element type of Bottom occurs from meet of basic type 5198 // and object; Top occurs when doing join on Bottom. 5199 // Leave k_ary at NULL. 5200 } else { 5201 // Cannot compute array klass directly from basic type, 5202 // since subtypes of TypeInt all have basic type T_INT. 5203 #ifdef ASSERT 5204 if (verify && el->isa_int()) { 5205 // Check simple cases when verifying klass. 5206 BasicType bt = T_ILLEGAL; 5207 if (el == TypeInt::BYTE) { 5208 bt = T_BYTE; 5209 } else if (el == TypeInt::SHORT) { 5210 bt = T_SHORT; 5211 } else if (el == TypeInt::CHAR) { 5212 bt = T_CHAR; 5213 } else if (el == TypeInt::INT) { 5214 bt = T_INT; 5215 } else { 5216 return _klass; // just return specified klass 5217 } 5218 return ciTypeArrayKlass::make(bt); 5219 } 5220 #endif 5221 assert(!el->isa_int(), 5222 "integral arrays must be pre-equipped with a class"); 5223 // Compute array klass directly from basic type 5224 k_ary = ciTypeArrayKlass::make(el->basic_type()); 5225 } 5226 return k_ary; 5227 } 5228 5229 //------------------------------klass------------------------------------------ 5230 // Return the defining klass for this class 5231 ciKlass* TypeAryPtr::klass() const { 5232 if( _klass ) return _klass; // Return cached value, if possible 5233 5234 // Oops, need to compute _klass and cache it 5235 ciKlass* k_ary = compute_klass(); 5236 5237 if( this != TypeAryPtr::OOPS && this->dual() != TypeAryPtr::OOPS ) { 5238 // The _klass field acts as a cache of the underlying 5239 // ciKlass for this array type. In order to set the field, 5240 // we need to cast away const-ness. 5241 // 5242 // IMPORTANT NOTE: we *never* set the _klass field for the 5243 // type TypeAryPtr::OOPS. This Type is shared between all 5244 // active compilations. However, the ciKlass which represents 5245 // this Type is *not* shared between compilations, so caching 5246 // this value would result in fetching a dangling pointer. 5247 // 5248 // Recomputing the underlying ciKlass for each request is 5249 // a bit less efficient than caching, but calls to 5250 // TypeAryPtr::OOPS->klass() are not common enough to matter. 5251 ((TypeAryPtr*)this)->_klass = k_ary; 5252 if (UseCompressedOops && k_ary != NULL && k_ary->is_obj_array_klass() && 5253 offset() != 0 && offset() != arrayOopDesc::length_offset_in_bytes()) { 5254 ((TypeAryPtr*)this)->_is_ptr_to_narrowoop = true; 5255 } 5256 } 5257 return k_ary; 5258 } 5259 5260 5261 //------------------------------add_offset------------------------------------- 5262 // Access internals of klass object 5263 const TypePtr *TypeKlassPtr::add_offset( intptr_t offset ) const { 5264 return make( _ptr, klass(), xadd_offset(offset) ); 5265 } 5266 5267 //------------------------------cast_to_ptr_type------------------------------- 5268 const Type *TypeKlassPtr::cast_to_ptr_type(PTR ptr) const { 5269 assert(_base == KlassPtr, "subclass must override cast_to_ptr_type"); 5270 if( ptr == _ptr ) return this; 5271 return make(ptr, _klass, _offset); 5272 } 5273 5274 5275 //-----------------------------cast_to_exactness------------------------------- 5276 const Type *TypeKlassPtr::cast_to_exactness(bool klass_is_exact) const { 5277 if( klass_is_exact == _klass_is_exact ) return this; 5278 if (!UseExactTypes) return this; 5279 return make(klass_is_exact ? Constant : NotNull, _klass, _offset); 5280 } 5281 5282 5283 //-----------------------------as_instance_type-------------------------------- 5284 // Corresponding type for an instance of the given class. 5285 // It will be NotNull, and exact if and only if the klass type is exact. 5286 const TypeOopPtr* TypeKlassPtr::as_instance_type() const { 5287 ciKlass* k = klass(); 5288 bool xk = klass_is_exact(); 5289 //return TypeInstPtr::make(TypePtr::NotNull, k, xk, NULL, 0); 5290 const TypeOopPtr* toop = TypeOopPtr::make_from_klass_raw(k); 5291 guarantee(toop != NULL, "need type for given klass"); 5292 toop = toop->cast_to_ptr_type(TypePtr::NotNull)->is_oopptr(); 5293 return toop->cast_to_exactness(xk)->is_oopptr(); 5294 } 5295 5296 5297 //------------------------------xmeet------------------------------------------ 5298 // Compute the MEET of two types, return a new Type object. 5299 const Type *TypeKlassPtr::xmeet( const Type *t ) const { 5300 // Perform a fast test for common case; meeting the same types together. 5301 if( this == t ) return this; // Meeting same type-rep? 5302 5303 // Current "this->_base" is Pointer 5304 switch (t->base()) { // switch on original type 5305 5306 case Int: // Mixing ints & oops happens when javac 5307 case Long: // reuses local variables 5308 case FloatTop: 5309 case FloatCon: 5310 case FloatBot: 5311 case DoubleTop: 5312 case DoubleCon: 5313 case DoubleBot: 5314 case NarrowOop: 5315 case NarrowKlass: 5316 case Bottom: // Ye Olde Default 5317 return Type::BOTTOM; 5318 case Top: 5319 return this; 5320 5321 default: // All else is a mistake 5322 typerr(t); 5323 5324 case AnyPtr: { // Meeting to AnyPtrs 5325 // Found an AnyPtr type vs self-KlassPtr type 5326 const TypePtr *tp = t->is_ptr(); 5327 Offset offset = meet_offset(tp->offset()); 5328 PTR ptr = meet_ptr(tp->ptr()); 5329 switch (tp->ptr()) { 5330 case TopPTR: 5331 return this; 5332 case Null: 5333 if( ptr == Null ) return TypePtr::make(AnyPtr, ptr, offset, tp->speculative(), tp->inline_depth()); 5334 case AnyNull: 5335 return make( ptr, klass(), offset ); 5336 case BotPTR: 5337 case NotNull: 5338 return TypePtr::make(AnyPtr, ptr, offset, tp->speculative(), tp->inline_depth()); 5339 default: typerr(t); 5340 } 5341 } 5342 5343 case RawPtr: 5344 case MetadataPtr: 5345 case OopPtr: 5346 case AryPtr: // Meet with AryPtr 5347 case InstPtr: // Meet with InstPtr 5348 case ValueTypePtr: 5349 return TypePtr::BOTTOM; 5350 5351 // 5352 // A-top } 5353 // / | \ } Tops 5354 // B-top A-any C-top } 5355 // | / | \ | } Any-nulls 5356 // B-any | C-any } 5357 // | | | 5358 // B-con A-con C-con } constants; not comparable across classes 5359 // | | | 5360 // B-not | C-not } 5361 // | \ | / | } not-nulls 5362 // B-bot A-not C-bot } 5363 // \ | / } Bottoms 5364 // A-bot } 5365 // 5366 5367 case KlassPtr: { // Meet two KlassPtr types 5368 const TypeKlassPtr *tkls = t->is_klassptr(); 5369 Offset off = meet_offset(tkls->offset()); 5370 PTR ptr = meet_ptr(tkls->ptr()); 5371 5372 // Check for easy case; klasses are equal (and perhaps not loaded!) 5373 // If we have constants, then we created oops so classes are loaded 5374 // and we can handle the constants further down. This case handles 5375 // not-loaded classes 5376 if( ptr != Constant && tkls->klass()->equals(klass()) ) { 5377 return make( ptr, klass(), off ); 5378 } 5379 5380 // Classes require inspection in the Java klass hierarchy. Must be loaded. 5381 ciKlass* tkls_klass = tkls->klass(); 5382 ciKlass* this_klass = this->klass(); 5383 assert( tkls_klass->is_loaded(), "This class should have been loaded."); 5384 assert( this_klass->is_loaded(), "This class should have been loaded."); 5385 5386 // If 'this' type is above the centerline and is a superclass of the 5387 // other, we can treat 'this' as having the same type as the other. 5388 if ((above_centerline(this->ptr())) && 5389 tkls_klass->is_subtype_of(this_klass)) { 5390 this_klass = tkls_klass; 5391 } 5392 // If 'tinst' type is above the centerline and is a superclass of the 5393 // other, we can treat 'tinst' as having the same type as the other. 5394 if ((above_centerline(tkls->ptr())) && 5395 this_klass->is_subtype_of(tkls_klass)) { 5396 tkls_klass = this_klass; 5397 } 5398 5399 // Check for classes now being equal 5400 if (tkls_klass->equals(this_klass)) { 5401 // If the klasses are equal, the constants may still differ. Fall to 5402 // NotNull if they do (neither constant is NULL; that is a special case 5403 // handled elsewhere). 5404 if( ptr == Constant ) { 5405 if (this->_ptr == Constant && tkls->_ptr == Constant && 5406 this->klass()->equals(tkls->klass())); 5407 else if (above_centerline(this->ptr())); 5408 else if (above_centerline(tkls->ptr())); 5409 else 5410 ptr = NotNull; 5411 } 5412 return make( ptr, this_klass, off ); 5413 } // Else classes are not equal 5414 5415 // Since klasses are different, we require the LCA in the Java 5416 // class hierarchy - which means we have to fall to at least NotNull. 5417 if( ptr == TopPTR || ptr == AnyNull || ptr == Constant ) 5418 ptr = NotNull; 5419 // Now we find the LCA of Java classes 5420 ciKlass* k = this_klass->least_common_ancestor(tkls_klass); 5421 return make( ptr, k, off ); 5422 } // End of case KlassPtr 5423 5424 } // End of switch 5425 return this; // Return the double constant 5426 } 5427 5428 //------------------------------xdual------------------------------------------ 5429 // Dual: compute field-by-field dual 5430 const Type *TypeKlassPtr::xdual() const { 5431 return new TypeKlassPtr( dual_ptr(), klass(), dual_offset() ); 5432 } 5433 5434 //------------------------------get_con---------------------------------------- 5435 intptr_t TypeKlassPtr::get_con() const { 5436 assert( _ptr == Null || _ptr == Constant, "" ); 5437 assert(offset() >= 0, ""); 5438 5439 if (offset() != 0) { 5440 // After being ported to the compiler interface, the compiler no longer 5441 // directly manipulates the addresses of oops. Rather, it only has a pointer 5442 // to a handle at compile time. This handle is embedded in the generated 5443 // code and dereferenced at the time the nmethod is made. Until that time, 5444 // it is not reasonable to do arithmetic with the addresses of oops (we don't 5445 // have access to the addresses!). This does not seem to currently happen, 5446 // but this assertion here is to help prevent its occurence. 5447 tty->print_cr("Found oop constant with non-zero offset"); 5448 ShouldNotReachHere(); 5449 } 5450 5451 return (intptr_t)klass()->constant_encoding(); 5452 } 5453 //------------------------------dump2------------------------------------------ 5454 // Dump Klass Type 5455 #ifndef PRODUCT 5456 void TypeKlassPtr::dump2( Dict & d, uint depth, outputStream *st ) const { 5457 switch( _ptr ) { 5458 case Constant: 5459 st->print("precise "); 5460 case NotNull: 5461 { 5462 const char *name = klass()->name()->as_utf8(); 5463 if( name ) { 5464 st->print("klass %s: " INTPTR_FORMAT, name, p2i(klass())); 5465 } else { 5466 ShouldNotReachHere(); 5467 } 5468 } 5469 case BotPTR: 5470 if( !WizardMode && !Verbose && !_klass_is_exact ) break; 5471 case TopPTR: 5472 case AnyNull: 5473 st->print(":%s", ptr_msg[_ptr]); 5474 if( _klass_is_exact ) st->print(":exact"); 5475 break; 5476 } 5477 5478 _offset.dump2(st); 5479 5480 st->print(" *"); 5481 } 5482 #endif 5483 5484 5485 5486 //============================================================================= 5487 // Convenience common pre-built types. 5488 5489 //------------------------------make------------------------------------------- 5490 const TypeFunc *TypeFunc::make( const TypeTuple *domain_sig, const TypeTuple* domain_cc, const TypeTuple *range ) { 5491 return (TypeFunc*)(new TypeFunc(domain_sig, domain_cc, range))->hashcons(); 5492 } 5493 5494 const TypeFunc *TypeFunc::make( const TypeTuple *domain, const TypeTuple *range ) { 5495 return make(domain, domain, range); 5496 } 5497 5498 //------------------------------make------------------------------------------- 5499 const TypeFunc *TypeFunc::make(ciMethod* method) { 5500 Compile* C = Compile::current(); 5501 const TypeFunc* tf = C->last_tf(method); // check cache 5502 if (tf != NULL) return tf; // The hit rate here is almost 50%. 5503 const TypeTuple *domain_sig, *domain_cc; 5504 // Value type arguments are not passed by reference, instead each 5505 // field of the value type is passed as an argument. We maintain 2 5506 // views of the argument list here: one based on the signature (with 5507 // a value type argument as a single slot), one based on the actual 5508 // calling convention (with a value type argument as a list of its 5509 // fields). 5510 if (method->is_static()) { 5511 domain_sig = TypeTuple::make_domain(NULL, method->signature(), false); 5512 domain_cc = TypeTuple::make_domain(NULL, method->signature(), ValueTypePassFieldsAsArgs); 5513 } else { 5514 domain_sig = TypeTuple::make_domain(method->holder(), method->signature(), false); 5515 domain_cc = TypeTuple::make_domain(method->holder(), method->signature(), ValueTypePassFieldsAsArgs); 5516 } 5517 const TypeTuple *range = TypeTuple::make_range(method->signature()); 5518 tf = TypeFunc::make(domain_sig, domain_cc, range); 5519 C->set_last_tf(method, tf); // fill cache 5520 return tf; 5521 } 5522 5523 //------------------------------meet------------------------------------------- 5524 // Compute the MEET of two types. It returns a new Type object. 5525 const Type *TypeFunc::xmeet( const Type *t ) const { 5526 // Perform a fast test for common case; meeting the same types together. 5527 if( this == t ) return this; // Meeting same type-rep? 5528 5529 // Current "this->_base" is Func 5530 switch (t->base()) { // switch on original type 5531 5532 case Bottom: // Ye Olde Default 5533 return t; 5534 5535 default: // All else is a mistake 5536 typerr(t); 5537 5538 case Top: 5539 break; 5540 } 5541 return this; // Return the double constant 5542 } 5543 5544 //------------------------------xdual------------------------------------------ 5545 // Dual: compute field-by-field dual 5546 const Type *TypeFunc::xdual() const { 5547 return this; 5548 } 5549 5550 //------------------------------eq--------------------------------------------- 5551 // Structural equality check for Type representations 5552 bool TypeFunc::eq( const Type *t ) const { 5553 const TypeFunc *a = (const TypeFunc*)t; 5554 return _domain_sig == a->_domain_sig && 5555 _domain_cc == a->_domain_cc && 5556 _range == a->_range; 5557 } 5558 5559 //------------------------------hash------------------------------------------- 5560 // Type-specific hashing function. 5561 int TypeFunc::hash(void) const { 5562 return (intptr_t)_domain_sig + (intptr_t)_domain_cc + (intptr_t)_range; 5563 } 5564 5565 //------------------------------dump2------------------------------------------ 5566 // Dump Function Type 5567 #ifndef PRODUCT 5568 void TypeFunc::dump2( Dict &d, uint depth, outputStream *st ) const { 5569 if( _range->cnt() <= Parms ) 5570 st->print("void"); 5571 else { 5572 uint i; 5573 for (i = Parms; i < _range->cnt()-1; i++) { 5574 _range->field_at(i)->dump2(d,depth,st); 5575 st->print("/"); 5576 } 5577 _range->field_at(i)->dump2(d,depth,st); 5578 } 5579 st->print(" "); 5580 st->print("( "); 5581 if( !depth || d[this] ) { // Check for recursive dump 5582 st->print("...)"); 5583 return; 5584 } 5585 d.Insert((void*)this,(void*)this); // Stop recursion 5586 if (Parms < _domain_sig->cnt()) 5587 _domain_sig->field_at(Parms)->dump2(d,depth-1,st); 5588 for (uint i = Parms+1; i < _domain_sig->cnt(); i++) { 5589 st->print(", "); 5590 _domain_sig->field_at(i)->dump2(d,depth-1,st); 5591 } 5592 st->print(" )"); 5593 } 5594 #endif 5595 5596 //------------------------------singleton-------------------------------------- 5597 // TRUE if Type is a singleton type, FALSE otherwise. Singletons are simple 5598 // constants (Ldi nodes). Singletons are integer, float or double constants 5599 // or a single symbol. 5600 bool TypeFunc::singleton(void) const { 5601 return false; // Never a singleton 5602 } 5603 5604 bool TypeFunc::empty(void) const { 5605 return false; // Never empty 5606 } 5607 5608 5609 BasicType TypeFunc::return_type() const{ 5610 if (range()->cnt() == TypeFunc::Parms) { 5611 return T_VOID; 5612 } 5613 return range()->field_at(TypeFunc::Parms)->basic_type(); 5614 }