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