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