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