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