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