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 const TypeOopPtr *TypeOopPtr::cast_to_nonconst() const { 3056 return this; 3057 } 3058 3059 //-----------------------------cast_to_exactness------------------------------- 3060 const Type *TypeOopPtr::cast_to_exactness(bool klass_is_exact) const { 3061 // There is no such thing as an exact general oop. 3062 // Return self unchanged. 3063 return this; 3064 } 3065 3066 3067 //------------------------------as_klass_type---------------------------------- 3068 // Return the klass type corresponding to this instance or array type. 3069 // It is the type that is loaded from an object of this type. 3070 const TypeKlassPtr* TypeOopPtr::as_klass_type() const { 3071 ciKlass* k = klass(); 3072 bool xk = klass_is_exact(); 3073 if (k == NULL) 3074 return TypeKlassPtr::OBJECT; 3075 else 3076 return TypeKlassPtr::make(xk? Constant: NotNull, k, 0); 3077 } 3078 3079 //------------------------------meet------------------------------------------- 3080 // Compute the MEET of two types. It returns a new Type object. 3081 const Type *TypeOopPtr::xmeet_helper(const Type *t) const { 3082 // Perform a fast test for common case; meeting the same types together. 3083 if( this == t ) return this; // Meeting same type-rep? 3084 3085 // Current "this->_base" is OopPtr 3086 switch (t->base()) { // switch on original type 3087 3088 case Int: // Mixing ints & oops happens when javac 3089 case Long: // reuses local variables 3090 case FloatTop: 3091 case FloatCon: 3092 case FloatBot: 3093 case DoubleTop: 3094 case DoubleCon: 3095 case DoubleBot: 3096 case NarrowOop: 3097 case NarrowKlass: 3098 case Bottom: // Ye Olde Default 3099 return Type::BOTTOM; 3100 case Top: 3101 return this; 3102 3103 default: // All else is a mistake 3104 typerr(t); 3105 3106 case RawPtr: 3107 case MetadataPtr: 3108 case KlassPtr: 3109 return TypePtr::BOTTOM; // Oop meet raw is not well defined 3110 3111 case AnyPtr: { 3112 // Found an AnyPtr type vs self-OopPtr type 3113 const TypePtr *tp = t->is_ptr(); 3114 int offset = meet_offset(tp->offset()); 3115 PTR ptr = meet_ptr(tp->ptr()); 3116 const TypePtr* speculative = xmeet_speculative(tp); 3117 int depth = meet_inline_depth(tp->inline_depth()); 3118 switch (tp->ptr()) { 3119 case Null: 3120 if (ptr == Null) return TypePtr::make(AnyPtr, ptr, offset, speculative, depth); 3121 // else fall through: 3122 case TopPTR: 3123 case AnyNull: { 3124 int instance_id = meet_instance_id(InstanceTop); 3125 return make(ptr, offset, instance_id, speculative, depth); 3126 } 3127 case BotPTR: 3128 case NotNull: 3129 return TypePtr::make(AnyPtr, ptr, offset, speculative, depth); 3130 default: typerr(t); 3131 } 3132 } 3133 3134 case OopPtr: { // Meeting to other OopPtrs 3135 const TypeOopPtr *tp = t->is_oopptr(); 3136 int instance_id = meet_instance_id(tp->instance_id()); 3137 const TypePtr* speculative = xmeet_speculative(tp); 3138 int depth = meet_inline_depth(tp->inline_depth()); 3139 return make(meet_ptr(tp->ptr()), meet_offset(tp->offset()), instance_id, speculative, depth); 3140 } 3141 3142 case InstPtr: // For these, flip the call around to cut down 3143 case AryPtr: 3144 return t->xmeet(this); // Call in reverse direction 3145 3146 } // End of switch 3147 return this; // Return the double constant 3148 } 3149 3150 3151 //------------------------------xdual------------------------------------------ 3152 // Dual of a pure heap pointer. No relevant klass or oop information. 3153 const Type *TypeOopPtr::xdual() const { 3154 assert(klass() == Compile::current()->env()->Object_klass(), "no klasses here"); 3155 assert(const_oop() == NULL, "no constants here"); 3156 return new TypeOopPtr(_base, dual_ptr(), klass(), klass_is_exact(), const_oop(), dual_offset(), dual_instance_id(), dual_speculative(), dual_inline_depth()); 3157 } 3158 3159 //--------------------------make_from_klass_common----------------------------- 3160 // Computes the element-type given a klass. 3161 const TypeOopPtr* TypeOopPtr::make_from_klass_common(ciKlass *klass, bool klass_change, bool try_for_exact) { 3162 if (klass->is_instance_klass()) { 3163 Compile* C = Compile::current(); 3164 Dependencies* deps = C->dependencies(); 3165 assert((deps != NULL) == (C->method() != NULL && C->method()->code_size() > 0), "sanity"); 3166 // Element is an instance 3167 bool klass_is_exact = false; 3168 if (klass->is_loaded()) { 3169 // Try to set klass_is_exact. 3170 ciInstanceKlass* ik = klass->as_instance_klass(); 3171 klass_is_exact = ik->is_final(); 3172 if (!klass_is_exact && klass_change 3173 && deps != NULL && UseUniqueSubclasses) { 3174 ciInstanceKlass* sub = ik->unique_concrete_subklass(); 3175 if (sub != NULL) { 3176 deps->assert_abstract_with_unique_concrete_subtype(ik, sub); 3177 klass = ik = sub; 3178 klass_is_exact = sub->is_final(); 3179 } 3180 } 3181 if (!klass_is_exact && try_for_exact 3182 && deps != NULL && UseExactTypes) { 3183 if (!ik->is_interface() && !ik->has_subklass()) { 3184 // Add a dependence; if concrete subclass added we need to recompile 3185 deps->assert_leaf_type(ik); 3186 klass_is_exact = true; 3187 } 3188 } 3189 } 3190 return TypeInstPtr::make(TypePtr::BotPTR, klass, klass_is_exact, NULL, 0); 3191 } else if (klass->is_obj_array_klass()) { 3192 // Element is an object array. Recursively call ourself. 3193 const TypeOopPtr *etype = TypeOopPtr::make_from_klass_common(klass->as_obj_array_klass()->element_klass(), false, try_for_exact); 3194 bool xk = etype->klass_is_exact(); 3195 const TypeAry* arr0 = TypeAry::make(etype, TypeInt::POS); 3196 // We used to pass NotNull in here, asserting that the sub-arrays 3197 // are all not-null. This is not true in generally, as code can 3198 // slam NULLs down in the subarrays. 3199 const TypeAryPtr* arr = TypeAryPtr::make(TypePtr::BotPTR, arr0, klass, xk, 0); 3200 return arr; 3201 } else if (klass->is_type_array_klass()) { 3202 // Element is an typeArray 3203 const Type* etype = get_const_basic_type(klass->as_type_array_klass()->element_type()); 3204 const TypeAry* arr0 = TypeAry::make(etype, TypeInt::POS); 3205 // We used to pass NotNull in here, asserting that the array pointer 3206 // is not-null. That was not true in general. 3207 const TypeAryPtr* arr = TypeAryPtr::make(TypePtr::BotPTR, arr0, klass, true, 0); 3208 return arr; 3209 } else { 3210 ShouldNotReachHere(); 3211 return NULL; 3212 } 3213 } 3214 3215 //------------------------------make_from_constant----------------------------- 3216 // Make a java pointer from an oop constant 3217 const TypeOopPtr* TypeOopPtr::make_from_constant(ciObject* o, bool require_constant) { 3218 assert(!o->is_null_object(), "null object not yet handled here."); 3219 ciKlass* klass = o->klass(); 3220 if (klass->is_instance_klass()) { 3221 // Element is an instance 3222 if (require_constant) { 3223 if (!o->can_be_constant()) return NULL; 3224 } else if (!o->should_be_constant()) { 3225 return TypeInstPtr::make(TypePtr::NotNull, klass, true, NULL, 0); 3226 } 3227 return TypeInstPtr::make(o); 3228 } else if (klass->is_obj_array_klass()) { 3229 // Element is an object array. Recursively call ourself. 3230 const TypeOopPtr *etype = 3231 TypeOopPtr::make_from_klass_raw(klass->as_obj_array_klass()->element_klass()); 3232 const TypeAry* arr0 = TypeAry::make(etype, TypeInt::make(o->as_array()->length())); 3233 // We used to pass NotNull in here, asserting that the sub-arrays 3234 // are all not-null. This is not true in generally, as code can 3235 // slam NULLs down in the subarrays. 3236 if (require_constant) { 3237 if (!o->can_be_constant()) return NULL; 3238 } else if (!o->should_be_constant()) { 3239 return TypeAryPtr::make(TypePtr::NotNull, arr0, klass, true, 0); 3240 } 3241 const TypeAryPtr* arr = TypeAryPtr::make(TypePtr::Constant, o, arr0, klass, true, 0); 3242 return arr; 3243 } else if (klass->is_type_array_klass()) { 3244 // Element is an typeArray 3245 const Type* etype = 3246 (Type*)get_const_basic_type(klass->as_type_array_klass()->element_type()); 3247 const TypeAry* arr0 = TypeAry::make(etype, TypeInt::make(o->as_array()->length())); 3248 // We used to pass NotNull in here, asserting that the array pointer 3249 // is not-null. That was not true in general. 3250 if (require_constant) { 3251 if (!o->can_be_constant()) return NULL; 3252 } else if (!o->should_be_constant()) { 3253 return TypeAryPtr::make(TypePtr::NotNull, arr0, klass, true, 0); 3254 } 3255 const TypeAryPtr* arr = TypeAryPtr::make(TypePtr::Constant, o, arr0, klass, true, 0); 3256 return arr; 3257 } 3258 3259 fatal("unhandled object type"); 3260 return NULL; 3261 } 3262 3263 //------------------------------get_con---------------------------------------- 3264 intptr_t TypeOopPtr::get_con() const { 3265 assert( _ptr == Null || _ptr == Constant, "" ); 3266 assert( _offset >= 0, "" ); 3267 3268 if (_offset != 0) { 3269 // After being ported to the compiler interface, the compiler no longer 3270 // directly manipulates the addresses of oops. Rather, it only has a pointer 3271 // to a handle at compile time. This handle is embedded in the generated 3272 // code and dereferenced at the time the nmethod is made. Until that time, 3273 // it is not reasonable to do arithmetic with the addresses of oops (we don't 3274 // have access to the addresses!). This does not seem to currently happen, 3275 // but this assertion here is to help prevent its occurence. 3276 tty->print_cr("Found oop constant with non-zero offset"); 3277 ShouldNotReachHere(); 3278 } 3279 3280 return (intptr_t)const_oop()->constant_encoding(); 3281 } 3282 3283 3284 //-----------------------------filter------------------------------------------ 3285 // Do not allow interface-vs.-noninterface joins to collapse to top. 3286 const Type *TypeOopPtr::filter_helper(const Type *kills, bool include_speculative) const { 3287 3288 const Type* ft = join_helper(kills, include_speculative); 3289 const TypeInstPtr* ftip = ft->isa_instptr(); 3290 const TypeInstPtr* ktip = kills->isa_instptr(); 3291 3292 if (ft->empty()) { 3293 // Check for evil case of 'this' being a class and 'kills' expecting an 3294 // interface. This can happen because the bytecodes do not contain 3295 // enough type info to distinguish a Java-level interface variable 3296 // from a Java-level object variable. If we meet 2 classes which 3297 // both implement interface I, but their meet is at 'j/l/O' which 3298 // doesn't implement I, we have no way to tell if the result should 3299 // be 'I' or 'j/l/O'. Thus we'll pick 'j/l/O'. If this then flows 3300 // into a Phi which "knows" it's an Interface type we'll have to 3301 // uplift the type. 3302 if (!empty()) { 3303 if (ktip != NULL && ktip->is_loaded() && ktip->klass()->is_interface()) { 3304 return kills; // Uplift to interface 3305 } 3306 // Also check for evil cases of 'this' being a class array 3307 // and 'kills' expecting an array of interfaces. 3308 Type::get_arrays_base_elements(ft, kills, NULL, &ktip); 3309 if (ktip != NULL && ktip->is_loaded() && ktip->klass()->is_interface()) { 3310 return kills; // Uplift to array of interface 3311 } 3312 } 3313 3314 return Type::TOP; // Canonical empty value 3315 } 3316 3317 // If we have an interface-typed Phi or cast and we narrow to a class type, 3318 // the join should report back the class. However, if we have a J/L/Object 3319 // class-typed Phi and an interface flows in, it's possible that the meet & 3320 // join report an interface back out. This isn't possible but happens 3321 // because the type system doesn't interact well with interfaces. 3322 if (ftip != NULL && ktip != NULL && 3323 ftip->is_loaded() && ftip->klass()->is_interface() && 3324 ktip->is_loaded() && !ktip->klass()->is_interface()) { 3325 assert(!ftip->klass_is_exact(), "interface could not be exact"); 3326 return ktip->cast_to_ptr_type(ftip->ptr()); 3327 } 3328 3329 return ft; 3330 } 3331 3332 //------------------------------eq--------------------------------------------- 3333 // Structural equality check for Type representations 3334 bool TypeOopPtr::eq( const Type *t ) const { 3335 const TypeOopPtr *a = (const TypeOopPtr*)t; 3336 if (_klass_is_exact != a->_klass_is_exact || 3337 _instance_id != a->_instance_id) return false; 3338 ciObject* one = const_oop(); 3339 ciObject* two = a->const_oop(); 3340 if (one == NULL || two == NULL) { 3341 return (one == two) && TypePtr::eq(t); 3342 } else { 3343 return one->equals(two) && TypePtr::eq(t); 3344 } 3345 } 3346 3347 //------------------------------hash------------------------------------------- 3348 // Type-specific hashing function. 3349 int TypeOopPtr::hash(void) const { 3350 return 3351 java_add(java_add((jint)(const_oop() ? const_oop()->hash() : 0), (jint)_klass_is_exact), 3352 java_add((jint)_instance_id, (jint)TypePtr::hash())); 3353 } 3354 3355 //------------------------------dump2------------------------------------------ 3356 #ifndef PRODUCT 3357 void TypeOopPtr::dump2( Dict &d, uint depth, outputStream *st ) const { 3358 st->print("oopptr:%s", ptr_msg[_ptr]); 3359 if( _klass_is_exact ) st->print(":exact"); 3360 if( const_oop() ) st->print(INTPTR_FORMAT, p2i(const_oop())); 3361 switch( _offset ) { 3362 case OffsetTop: st->print("+top"); break; 3363 case OffsetBot: st->print("+any"); break; 3364 case 0: break; 3365 default: st->print("+%d",_offset); break; 3366 } 3367 if (_instance_id == InstanceTop) 3368 st->print(",iid=top"); 3369 else if (_instance_id != InstanceBot) 3370 st->print(",iid=%d",_instance_id); 3371 3372 dump_inline_depth(st); 3373 dump_speculative(st); 3374 } 3375 #endif 3376 3377 //------------------------------singleton-------------------------------------- 3378 // TRUE if Type is a singleton type, FALSE otherwise. Singletons are simple 3379 // constants 3380 bool TypeOopPtr::singleton(void) const { 3381 // detune optimizer to not generate constant oop + constant offset as a constant! 3382 // TopPTR, Null, AnyNull, Constant are all singletons 3383 return (_offset == 0) && !below_centerline(_ptr); 3384 } 3385 3386 //------------------------------add_offset------------------------------------- 3387 const TypePtr *TypeOopPtr::add_offset(intptr_t offset) const { 3388 return make(_ptr, xadd_offset(offset), _instance_id, add_offset_speculative(offset), _inline_depth); 3389 } 3390 3391 /** 3392 * Return same type without a speculative part 3393 */ 3394 const Type* TypeOopPtr::remove_speculative() const { 3395 if (_speculative == NULL) { 3396 return this; 3397 } 3398 assert(_inline_depth == InlineDepthTop || _inline_depth == InlineDepthBottom, "non speculative type shouldn't have inline depth"); 3399 return make(_ptr, _offset, _instance_id, NULL, _inline_depth); 3400 } 3401 3402 /** 3403 * Return same type but drop speculative part if we know we won't use 3404 * it 3405 */ 3406 const Type* TypeOopPtr::cleanup_speculative() const { 3407 // If the klass is exact and the ptr is not null then there's 3408 // nothing that the speculative type can help us with 3409 if (klass_is_exact() && !maybe_null()) { 3410 return remove_speculative(); 3411 } 3412 return TypePtr::cleanup_speculative(); 3413 } 3414 3415 /** 3416 * Return same type but with a different inline depth (used for speculation) 3417 * 3418 * @param depth depth to meet with 3419 */ 3420 const TypePtr* TypeOopPtr::with_inline_depth(int depth) const { 3421 if (!UseInlineDepthForSpeculativeTypes) { 3422 return this; 3423 } 3424 return make(_ptr, _offset, _instance_id, _speculative, depth); 3425 } 3426 3427 //------------------------------meet_instance_id-------------------------------- 3428 int TypeOopPtr::meet_instance_id( int instance_id ) const { 3429 // Either is 'TOP' instance? Return the other instance! 3430 if( _instance_id == InstanceTop ) return instance_id; 3431 if( instance_id == InstanceTop ) return _instance_id; 3432 // If either is different, return 'BOTTOM' instance 3433 if( _instance_id != instance_id ) return InstanceBot; 3434 return _instance_id; 3435 } 3436 3437 //------------------------------dual_instance_id-------------------------------- 3438 int TypeOopPtr::dual_instance_id( ) const { 3439 if( _instance_id == InstanceTop ) return InstanceBot; // Map TOP into BOTTOM 3440 if( _instance_id == InstanceBot ) return InstanceTop; // Map BOTTOM into TOP 3441 return _instance_id; // Map everything else into self 3442 } 3443 3444 /** 3445 * Check whether new profiling would improve speculative type 3446 * 3447 * @param exact_kls class from profiling 3448 * @param inline_depth inlining depth of profile point 3449 * 3450 * @return true if type profile is valuable 3451 */ 3452 bool TypeOopPtr::would_improve_type(ciKlass* exact_kls, int inline_depth) const { 3453 // no way to improve an already exact type 3454 if (klass_is_exact()) { 3455 return false; 3456 } 3457 return TypePtr::would_improve_type(exact_kls, inline_depth); 3458 } 3459 3460 //============================================================================= 3461 // Convenience common pre-built types. 3462 const TypeInstPtr *TypeInstPtr::NOTNULL; 3463 const TypeInstPtr *TypeInstPtr::BOTTOM; 3464 const TypeInstPtr *TypeInstPtr::MIRROR; 3465 const TypeInstPtr *TypeInstPtr::MARK; 3466 const TypeInstPtr *TypeInstPtr::KLASS; 3467 3468 //------------------------------TypeInstPtr------------------------------------- 3469 TypeInstPtr::TypeInstPtr(PTR ptr, ciKlass* k, bool xk, ciObject* o, int off, 3470 int instance_id, const TypePtr* speculative, int inline_depth) 3471 : TypeOopPtr(InstPtr, ptr, k, xk, o, off, instance_id, speculative, inline_depth), 3472 _name(k->name()) { 3473 assert(k != NULL && 3474 (k->is_loaded() || o == NULL), 3475 "cannot have constants with non-loaded klass"); 3476 }; 3477 3478 //------------------------------make------------------------------------------- 3479 const TypeInstPtr *TypeInstPtr::make(PTR ptr, 3480 ciKlass* k, 3481 bool xk, 3482 ciObject* o, 3483 int offset, 3484 int instance_id, 3485 const TypePtr* speculative, 3486 int inline_depth) { 3487 assert( !k->is_loaded() || k->is_instance_klass(), "Must be for instance"); 3488 // Either const_oop() is NULL or else ptr is Constant 3489 assert( (!o && ptr != Constant) || (o && ptr == Constant), 3490 "constant pointers must have a value supplied" ); 3491 // Ptr is never Null 3492 assert( ptr != Null, "NULL pointers are not typed" ); 3493 3494 assert(instance_id <= 0 || xk || !UseExactTypes, "instances are always exactly typed"); 3495 if (!UseExactTypes) xk = false; 3496 if (ptr == Constant) { 3497 // Note: This case includes meta-object constants, such as methods. 3498 xk = true; 3499 } else if (k->is_loaded()) { 3500 ciInstanceKlass* ik = k->as_instance_klass(); 3501 if (!xk && ik->is_final()) xk = true; // no inexact final klass 3502 if (xk && ik->is_interface()) xk = false; // no exact interface 3503 } 3504 3505 // Now hash this baby 3506 TypeInstPtr *result = 3507 (TypeInstPtr*)(new TypeInstPtr(ptr, k, xk, o ,offset, instance_id, speculative, inline_depth))->hashcons(); 3508 3509 return result; 3510 } 3511 3512 /** 3513 * Create constant type for a constant boxed value 3514 */ 3515 const Type* TypeInstPtr::get_const_boxed_value() const { 3516 assert(is_ptr_to_boxed_value(), "should be called only for boxed value"); 3517 assert((const_oop() != NULL), "should be called only for constant object"); 3518 ciConstant constant = const_oop()->as_instance()->field_value_by_offset(offset()); 3519 BasicType bt = constant.basic_type(); 3520 switch (bt) { 3521 case T_BOOLEAN: return TypeInt::make(constant.as_boolean()); 3522 case T_INT: return TypeInt::make(constant.as_int()); 3523 case T_CHAR: return TypeInt::make(constant.as_char()); 3524 case T_BYTE: return TypeInt::make(constant.as_byte()); 3525 case T_SHORT: return TypeInt::make(constant.as_short()); 3526 case T_FLOAT: return TypeF::make(constant.as_float()); 3527 case T_DOUBLE: return TypeD::make(constant.as_double()); 3528 case T_LONG: return TypeLong::make(constant.as_long()); 3529 default: break; 3530 } 3531 fatal("Invalid boxed value type '%s'", type2name(bt)); 3532 return NULL; 3533 } 3534 3535 //------------------------------cast_to_ptr_type------------------------------- 3536 const Type *TypeInstPtr::cast_to_ptr_type(PTR ptr) const { 3537 if( ptr == _ptr ) return this; 3538 // Reconstruct _sig info here since not a problem with later lazy 3539 // construction, _sig will show up on demand. 3540 return make(ptr, klass(), klass_is_exact(), const_oop(), _offset, _instance_id, _speculative, _inline_depth); 3541 } 3542 3543 3544 //-----------------------------cast_to_exactness------------------------------- 3545 const Type *TypeInstPtr::cast_to_exactness(bool klass_is_exact) const { 3546 if( klass_is_exact == _klass_is_exact ) return this; 3547 if (!UseExactTypes) return this; 3548 if (!_klass->is_loaded()) return this; 3549 ciInstanceKlass* ik = _klass->as_instance_klass(); 3550 if( (ik->is_final() || _const_oop) ) return this; // cannot clear xk 3551 if( ik->is_interface() ) return this; // cannot set xk 3552 return make(ptr(), klass(), klass_is_exact, const_oop(), _offset, _instance_id, _speculative, _inline_depth); 3553 } 3554 3555 //-----------------------------cast_to_instance_id---------------------------- 3556 const TypeOopPtr *TypeInstPtr::cast_to_instance_id(int instance_id) const { 3557 if( instance_id == _instance_id ) return this; 3558 return make(_ptr, klass(), _klass_is_exact, const_oop(), _offset, instance_id, _speculative, _inline_depth); 3559 } 3560 3561 const TypeOopPtr *TypeInstPtr::cast_to_nonconst() const { 3562 if (const_oop() == NULL) return this; 3563 return make(NotNull, klass(), _klass_is_exact, NULL, _offset, _instance_id, _speculative, _inline_depth); 3564 } 3565 3566 //------------------------------xmeet_unloaded--------------------------------- 3567 // Compute the MEET of two InstPtrs when at least one is unloaded. 3568 // Assume classes are different since called after check for same name/class-loader 3569 const TypeInstPtr *TypeInstPtr::xmeet_unloaded(const TypeInstPtr *tinst) const { 3570 int off = meet_offset(tinst->offset()); 3571 PTR ptr = meet_ptr(tinst->ptr()); 3572 int instance_id = meet_instance_id(tinst->instance_id()); 3573 const TypePtr* speculative = xmeet_speculative(tinst); 3574 int depth = meet_inline_depth(tinst->inline_depth()); 3575 3576 const TypeInstPtr *loaded = is_loaded() ? this : tinst; 3577 const TypeInstPtr *unloaded = is_loaded() ? tinst : this; 3578 if( loaded->klass()->equals(ciEnv::current()->Object_klass()) ) { 3579 // 3580 // Meet unloaded class with java/lang/Object 3581 // 3582 // Meet 3583 // | Unloaded Class 3584 // Object | TOP | AnyNull | Constant | NotNull | BOTTOM | 3585 // =================================================================== 3586 // TOP | ..........................Unloaded......................| 3587 // AnyNull | U-AN |................Unloaded......................| 3588 // Constant | ... O-NN .................................. | O-BOT | 3589 // NotNull | ... O-NN .................................. | O-BOT | 3590 // BOTTOM | ........................Object-BOTTOM ..................| 3591 // 3592 assert(loaded->ptr() != TypePtr::Null, "insanity check"); 3593 // 3594 if( loaded->ptr() == TypePtr::TopPTR ) { return unloaded; } 3595 else if (loaded->ptr() == TypePtr::AnyNull) { return TypeInstPtr::make(ptr, unloaded->klass(), false, NULL, off, instance_id, speculative, depth); } 3596 else if (loaded->ptr() == TypePtr::BotPTR ) { return TypeInstPtr::BOTTOM; } 3597 else if (loaded->ptr() == TypePtr::Constant || loaded->ptr() == TypePtr::NotNull) { 3598 if (unloaded->ptr() == TypePtr::BotPTR ) { return TypeInstPtr::BOTTOM; } 3599 else { return TypeInstPtr::NOTNULL; } 3600 } 3601 else if( unloaded->ptr() == TypePtr::TopPTR ) { return unloaded; } 3602 3603 return unloaded->cast_to_ptr_type(TypePtr::AnyNull)->is_instptr(); 3604 } 3605 3606 // Both are unloaded, not the same class, not Object 3607 // Or meet unloaded with a different loaded class, not java/lang/Object 3608 if( ptr != TypePtr::BotPTR ) { 3609 return TypeInstPtr::NOTNULL; 3610 } 3611 return TypeInstPtr::BOTTOM; 3612 } 3613 3614 3615 //------------------------------meet------------------------------------------- 3616 // Compute the MEET of two types. It returns a new Type object. 3617 const Type *TypeInstPtr::xmeet_helper(const Type *t) const { 3618 // Perform a fast test for common case; meeting the same types together. 3619 if( this == t ) return this; // Meeting same type-rep? 3620 3621 // Current "this->_base" is Pointer 3622 switch (t->base()) { // switch on original type 3623 3624 case Int: // Mixing ints & oops happens when javac 3625 case Long: // reuses local variables 3626 case FloatTop: 3627 case FloatCon: 3628 case FloatBot: 3629 case DoubleTop: 3630 case DoubleCon: 3631 case DoubleBot: 3632 case NarrowOop: 3633 case NarrowKlass: 3634 case Bottom: // Ye Olde Default 3635 return Type::BOTTOM; 3636 case Top: 3637 return this; 3638 3639 default: // All else is a mistake 3640 typerr(t); 3641 3642 case MetadataPtr: 3643 case KlassPtr: 3644 case RawPtr: return TypePtr::BOTTOM; 3645 3646 case AryPtr: { // All arrays inherit from Object class 3647 const TypeAryPtr *tp = t->is_aryptr(); 3648 int offset = meet_offset(tp->offset()); 3649 PTR ptr = meet_ptr(tp->ptr()); 3650 int instance_id = meet_instance_id(tp->instance_id()); 3651 const TypePtr* speculative = xmeet_speculative(tp); 3652 int depth = meet_inline_depth(tp->inline_depth()); 3653 switch (ptr) { 3654 case TopPTR: 3655 case AnyNull: // Fall 'down' to dual of object klass 3656 // For instances when a subclass meets a superclass we fall 3657 // below the centerline when the superclass is exact. We need to 3658 // do the same here. 3659 if (klass()->equals(ciEnv::current()->Object_klass()) && !klass_is_exact()) { 3660 return TypeAryPtr::make(ptr, tp->ary(), tp->klass(), tp->klass_is_exact(), offset, instance_id, speculative, depth); 3661 } else { 3662 // cannot subclass, so the meet has to fall badly below the centerline 3663 ptr = NotNull; 3664 instance_id = InstanceBot; 3665 return TypeInstPtr::make( ptr, ciEnv::current()->Object_klass(), false, NULL, offset, instance_id, speculative, depth); 3666 } 3667 case Constant: 3668 case NotNull: 3669 case BotPTR: // Fall down to object klass 3670 // LCA is object_klass, but if we subclass from the top we can do better 3671 if( above_centerline(_ptr) ) { // if( _ptr == TopPTR || _ptr == AnyNull ) 3672 // If 'this' (InstPtr) is above the centerline and it is Object class 3673 // then we can subclass in the Java class hierarchy. 3674 // For instances when a subclass meets a superclass we fall 3675 // below the centerline when the superclass is exact. We need 3676 // to do the same here. 3677 if (klass()->equals(ciEnv::current()->Object_klass()) && !klass_is_exact()) { 3678 // that is, tp's array type is a subtype of my klass 3679 return TypeAryPtr::make(ptr, (ptr == Constant ? tp->const_oop() : NULL), 3680 tp->ary(), tp->klass(), tp->klass_is_exact(), offset, instance_id, speculative, depth); 3681 } 3682 } 3683 // The other case cannot happen, since I cannot be a subtype of an array. 3684 // The meet falls down to Object class below centerline. 3685 if( ptr == Constant ) 3686 ptr = NotNull; 3687 instance_id = InstanceBot; 3688 return make(ptr, ciEnv::current()->Object_klass(), false, NULL, offset, instance_id, speculative, depth); 3689 default: typerr(t); 3690 } 3691 } 3692 3693 case OopPtr: { // Meeting to OopPtrs 3694 // Found a OopPtr type vs self-InstPtr type 3695 const TypeOopPtr *tp = t->is_oopptr(); 3696 int offset = meet_offset(tp->offset()); 3697 PTR ptr = meet_ptr(tp->ptr()); 3698 switch (tp->ptr()) { 3699 case TopPTR: 3700 case AnyNull: { 3701 int instance_id = meet_instance_id(InstanceTop); 3702 const TypePtr* speculative = xmeet_speculative(tp); 3703 int depth = meet_inline_depth(tp->inline_depth()); 3704 return make(ptr, klass(), klass_is_exact(), 3705 (ptr == Constant ? const_oop() : NULL), offset, instance_id, speculative, depth); 3706 } 3707 case NotNull: 3708 case BotPTR: { 3709 int instance_id = meet_instance_id(tp->instance_id()); 3710 const TypePtr* speculative = xmeet_speculative(tp); 3711 int depth = meet_inline_depth(tp->inline_depth()); 3712 return TypeOopPtr::make(ptr, offset, instance_id, speculative, depth); 3713 } 3714 default: typerr(t); 3715 } 3716 } 3717 3718 case AnyPtr: { // Meeting to AnyPtrs 3719 // Found an AnyPtr type vs self-InstPtr type 3720 const TypePtr *tp = t->is_ptr(); 3721 int offset = meet_offset(tp->offset()); 3722 PTR ptr = meet_ptr(tp->ptr()); 3723 int instance_id = meet_instance_id(InstanceTop); 3724 const TypePtr* speculative = xmeet_speculative(tp); 3725 int depth = meet_inline_depth(tp->inline_depth()); 3726 switch (tp->ptr()) { 3727 case Null: 3728 if( ptr == Null ) return TypePtr::make(AnyPtr, ptr, offset, speculative, depth); 3729 // else fall through to AnyNull 3730 case TopPTR: 3731 case AnyNull: { 3732 return make(ptr, klass(), klass_is_exact(), 3733 (ptr == Constant ? const_oop() : NULL), offset, instance_id, speculative, depth); 3734 } 3735 case NotNull: 3736 case BotPTR: 3737 return TypePtr::make(AnyPtr, ptr, offset, speculative,depth); 3738 default: typerr(t); 3739 } 3740 } 3741 3742 /* 3743 A-top } 3744 / | \ } Tops 3745 B-top A-any C-top } 3746 | / | \ | } Any-nulls 3747 B-any | C-any } 3748 | | | 3749 B-con A-con C-con } constants; not comparable across classes 3750 | | | 3751 B-not | C-not } 3752 | \ | / | } not-nulls 3753 B-bot A-not C-bot } 3754 \ | / } Bottoms 3755 A-bot } 3756 */ 3757 3758 case InstPtr: { // Meeting 2 Oops? 3759 // Found an InstPtr sub-type vs self-InstPtr type 3760 const TypeInstPtr *tinst = t->is_instptr(); 3761 int off = meet_offset( tinst->offset() ); 3762 PTR ptr = meet_ptr( tinst->ptr() ); 3763 int instance_id = meet_instance_id(tinst->instance_id()); 3764 const TypePtr* speculative = xmeet_speculative(tinst); 3765 int depth = meet_inline_depth(tinst->inline_depth()); 3766 3767 // Check for easy case; klasses are equal (and perhaps not loaded!) 3768 // If we have constants, then we created oops so classes are loaded 3769 // and we can handle the constants further down. This case handles 3770 // both-not-loaded or both-loaded classes 3771 if (ptr != Constant && klass()->equals(tinst->klass()) && klass_is_exact() == tinst->klass_is_exact()) { 3772 return make(ptr, klass(), klass_is_exact(), NULL, off, instance_id, speculative, depth); 3773 } 3774 3775 // Classes require inspection in the Java klass hierarchy. Must be loaded. 3776 ciKlass* tinst_klass = tinst->klass(); 3777 ciKlass* this_klass = this->klass(); 3778 bool tinst_xk = tinst->klass_is_exact(); 3779 bool this_xk = this->klass_is_exact(); 3780 if (!tinst_klass->is_loaded() || !this_klass->is_loaded() ) { 3781 // One of these classes has not been loaded 3782 const TypeInstPtr *unloaded_meet = xmeet_unloaded(tinst); 3783 #ifndef PRODUCT 3784 if( PrintOpto && Verbose ) { 3785 tty->print("meet of unloaded classes resulted in: "); unloaded_meet->dump(); tty->cr(); 3786 tty->print(" this == "); this->dump(); tty->cr(); 3787 tty->print(" tinst == "); tinst->dump(); tty->cr(); 3788 } 3789 #endif 3790 return unloaded_meet; 3791 } 3792 3793 // Handle mixing oops and interfaces first. 3794 if( this_klass->is_interface() && !(tinst_klass->is_interface() || 3795 tinst_klass == ciEnv::current()->Object_klass())) { 3796 ciKlass *tmp = tinst_klass; // Swap interface around 3797 tinst_klass = this_klass; 3798 this_klass = tmp; 3799 bool tmp2 = tinst_xk; 3800 tinst_xk = this_xk; 3801 this_xk = tmp2; 3802 } 3803 if (tinst_klass->is_interface() && 3804 !(this_klass->is_interface() || 3805 // Treat java/lang/Object as an honorary interface, 3806 // because we need a bottom for the interface hierarchy. 3807 this_klass == ciEnv::current()->Object_klass())) { 3808 // Oop meets interface! 3809 3810 // See if the oop subtypes (implements) interface. 3811 ciKlass *k; 3812 bool xk; 3813 if( this_klass->is_subtype_of( tinst_klass ) ) { 3814 // Oop indeed subtypes. Now keep oop or interface depending 3815 // on whether we are both above the centerline or either is 3816 // below the centerline. If we are on the centerline 3817 // (e.g., Constant vs. AnyNull interface), use the constant. 3818 k = below_centerline(ptr) ? tinst_klass : this_klass; 3819 // If we are keeping this_klass, keep its exactness too. 3820 xk = below_centerline(ptr) ? tinst_xk : this_xk; 3821 } else { // Does not implement, fall to Object 3822 // Oop does not implement interface, so mixing falls to Object 3823 // just like the verifier does (if both are above the 3824 // centerline fall to interface) 3825 k = above_centerline(ptr) ? tinst_klass : ciEnv::current()->Object_klass(); 3826 xk = above_centerline(ptr) ? tinst_xk : false; 3827 // Watch out for Constant vs. AnyNull interface. 3828 if (ptr == Constant) ptr = NotNull; // forget it was a constant 3829 instance_id = InstanceBot; 3830 } 3831 ciObject* o = NULL; // the Constant value, if any 3832 if (ptr == Constant) { 3833 // Find out which constant. 3834 o = (this_klass == klass()) ? const_oop() : tinst->const_oop(); 3835 } 3836 return make(ptr, k, xk, o, off, instance_id, speculative, depth); 3837 } 3838 3839 // Either oop vs oop or interface vs interface or interface vs Object 3840 3841 // !!! Here's how the symmetry requirement breaks down into invariants: 3842 // If we split one up & one down AND they subtype, take the down man. 3843 // If we split one up & one down AND they do NOT subtype, "fall hard". 3844 // If both are up and they subtype, take the subtype class. 3845 // If both are up and they do NOT subtype, "fall hard". 3846 // If both are down and they subtype, take the supertype class. 3847 // If both are down and they do NOT subtype, "fall hard". 3848 // Constants treated as down. 3849 3850 // Now, reorder the above list; observe that both-down+subtype is also 3851 // "fall hard"; "fall hard" becomes the default case: 3852 // If we split one up & one down AND they subtype, take the down man. 3853 // If both are up and they subtype, take the subtype class. 3854 3855 // If both are down and they subtype, "fall hard". 3856 // If both are down and they do NOT subtype, "fall hard". 3857 // If both are up and they do NOT subtype, "fall hard". 3858 // If we split one up & one down AND they do NOT subtype, "fall hard". 3859 3860 // If a proper subtype is exact, and we return it, we return it exactly. 3861 // If a proper supertype is exact, there can be no subtyping relationship! 3862 // If both types are equal to the subtype, exactness is and-ed below the 3863 // centerline and or-ed above it. (N.B. Constants are always exact.) 3864 3865 // Check for subtyping: 3866 ciKlass *subtype = NULL; 3867 bool subtype_exact = false; 3868 if( tinst_klass->equals(this_klass) ) { 3869 subtype = this_klass; 3870 subtype_exact = below_centerline(ptr) ? (this_xk & tinst_xk) : (this_xk | tinst_xk); 3871 } else if( !tinst_xk && this_klass->is_subtype_of( tinst_klass ) ) { 3872 subtype = this_klass; // Pick subtyping class 3873 subtype_exact = this_xk; 3874 } else if( !this_xk && tinst_klass->is_subtype_of( this_klass ) ) { 3875 subtype = tinst_klass; // Pick subtyping class 3876 subtype_exact = tinst_xk; 3877 } 3878 3879 if( subtype ) { 3880 if( above_centerline(ptr) ) { // both are up? 3881 this_klass = tinst_klass = subtype; 3882 this_xk = tinst_xk = subtype_exact; 3883 } else if( above_centerline(this ->_ptr) && !above_centerline(tinst->_ptr) ) { 3884 this_klass = tinst_klass; // tinst is down; keep down man 3885 this_xk = tinst_xk; 3886 } else if( above_centerline(tinst->_ptr) && !above_centerline(this ->_ptr) ) { 3887 tinst_klass = this_klass; // this is down; keep down man 3888 tinst_xk = this_xk; 3889 } else { 3890 this_xk = subtype_exact; // either they are equal, or we'll do an LCA 3891 } 3892 } 3893 3894 // Check for classes now being equal 3895 if (tinst_klass->equals(this_klass)) { 3896 // If the klasses are equal, the constants may still differ. Fall to 3897 // NotNull if they do (neither constant is NULL; that is a special case 3898 // handled elsewhere). 3899 ciObject* o = NULL; // Assume not constant when done 3900 ciObject* this_oop = const_oop(); 3901 ciObject* tinst_oop = tinst->const_oop(); 3902 if( ptr == Constant ) { 3903 if (this_oop != NULL && tinst_oop != NULL && 3904 this_oop->equals(tinst_oop) ) 3905 o = this_oop; 3906 else if (above_centerline(this ->_ptr)) 3907 o = tinst_oop; 3908 else if (above_centerline(tinst ->_ptr)) 3909 o = this_oop; 3910 else 3911 ptr = NotNull; 3912 } 3913 return make(ptr, this_klass, this_xk, o, off, instance_id, speculative, depth); 3914 } // Else classes are not equal 3915 3916 // Since klasses are different, we require a LCA in the Java 3917 // class hierarchy - which means we have to fall to at least NotNull. 3918 if( ptr == TopPTR || ptr == AnyNull || ptr == Constant ) 3919 ptr = NotNull; 3920 3921 instance_id = InstanceBot; 3922 3923 // Now we find the LCA of Java classes 3924 ciKlass* k = this_klass->least_common_ancestor(tinst_klass); 3925 return make(ptr, k, false, NULL, off, instance_id, speculative, depth); 3926 } // End of case InstPtr 3927 3928 } // End of switch 3929 return this; // Return the double constant 3930 } 3931 3932 3933 //------------------------java_mirror_type-------------------------------------- 3934 ciType* TypeInstPtr::java_mirror_type() const { 3935 // must be a singleton type 3936 if( const_oop() == NULL ) return NULL; 3937 3938 // must be of type java.lang.Class 3939 if( klass() != ciEnv::current()->Class_klass() ) return NULL; 3940 3941 return const_oop()->as_instance()->java_mirror_type(); 3942 } 3943 3944 3945 //------------------------------xdual------------------------------------------ 3946 // Dual: do NOT dual on klasses. This means I do NOT understand the Java 3947 // inheritance mechanism. 3948 const Type *TypeInstPtr::xdual() const { 3949 return new TypeInstPtr(dual_ptr(), klass(), klass_is_exact(), const_oop(), dual_offset(), dual_instance_id(), dual_speculative(), dual_inline_depth()); 3950 } 3951 3952 //------------------------------eq--------------------------------------------- 3953 // Structural equality check for Type representations 3954 bool TypeInstPtr::eq( const Type *t ) const { 3955 const TypeInstPtr *p = t->is_instptr(); 3956 return 3957 klass()->equals(p->klass()) && 3958 TypeOopPtr::eq(p); // Check sub-type stuff 3959 } 3960 3961 //------------------------------hash------------------------------------------- 3962 // Type-specific hashing function. 3963 int TypeInstPtr::hash(void) const { 3964 int hash = java_add((jint)klass()->hash(), (jint)TypeOopPtr::hash()); 3965 return hash; 3966 } 3967 3968 //------------------------------dump2------------------------------------------ 3969 // Dump oop Type 3970 #ifndef PRODUCT 3971 void TypeInstPtr::dump2( Dict &d, uint depth, outputStream *st ) const { 3972 // Print the name of the klass. 3973 klass()->print_name_on(st); 3974 3975 switch( _ptr ) { 3976 case Constant: 3977 // TO DO: Make CI print the hex address of the underlying oop. 3978 if (WizardMode || Verbose) { 3979 const_oop()->print_oop(st); 3980 } 3981 case BotPTR: 3982 if (!WizardMode && !Verbose) { 3983 if( _klass_is_exact ) st->print(":exact"); 3984 break; 3985 } 3986 case TopPTR: 3987 case AnyNull: 3988 case NotNull: 3989 st->print(":%s", ptr_msg[_ptr]); 3990 if( _klass_is_exact ) st->print(":exact"); 3991 break; 3992 default: 3993 break; 3994 } 3995 3996 if( _offset ) { // Dump offset, if any 3997 if( _offset == OffsetBot ) st->print("+any"); 3998 else if( _offset == OffsetTop ) st->print("+unknown"); 3999 else st->print("+%d", _offset); 4000 } 4001 4002 st->print(" *"); 4003 if (_instance_id == InstanceTop) 4004 st->print(",iid=top"); 4005 else if (_instance_id != InstanceBot) 4006 st->print(",iid=%d",_instance_id); 4007 4008 dump_inline_depth(st); 4009 dump_speculative(st); 4010 } 4011 #endif 4012 4013 //------------------------------add_offset------------------------------------- 4014 const TypePtr *TypeInstPtr::add_offset(intptr_t offset) const { 4015 return make(_ptr, klass(), klass_is_exact(), const_oop(), xadd_offset(offset), 4016 _instance_id, add_offset_speculative(offset), _inline_depth); 4017 } 4018 4019 const Type *TypeInstPtr::remove_speculative() const { 4020 if (_speculative == NULL) { 4021 return this; 4022 } 4023 assert(_inline_depth == InlineDepthTop || _inline_depth == InlineDepthBottom, "non speculative type shouldn't have inline depth"); 4024 return make(_ptr, klass(), klass_is_exact(), const_oop(), _offset, 4025 _instance_id, NULL, _inline_depth); 4026 } 4027 4028 const TypePtr *TypeInstPtr::with_inline_depth(int depth) const { 4029 if (!UseInlineDepthForSpeculativeTypes) { 4030 return this; 4031 } 4032 return make(_ptr, klass(), klass_is_exact(), const_oop(), _offset, _instance_id, _speculative, depth); 4033 } 4034 4035 //============================================================================= 4036 // Convenience common pre-built types. 4037 const TypeAryPtr *TypeAryPtr::RANGE; 4038 const TypeAryPtr *TypeAryPtr::OOPS; 4039 const TypeAryPtr *TypeAryPtr::NARROWOOPS; 4040 const TypeAryPtr *TypeAryPtr::BYTES; 4041 const TypeAryPtr *TypeAryPtr::SHORTS; 4042 const TypeAryPtr *TypeAryPtr::CHARS; 4043 const TypeAryPtr *TypeAryPtr::INTS; 4044 const TypeAryPtr *TypeAryPtr::LONGS; 4045 const TypeAryPtr *TypeAryPtr::FLOATS; 4046 const TypeAryPtr *TypeAryPtr::DOUBLES; 4047 4048 //------------------------------make------------------------------------------- 4049 const TypeAryPtr *TypeAryPtr::make(PTR ptr, const TypeAry *ary, ciKlass* k, bool xk, int offset, 4050 int instance_id, const TypePtr* speculative, int inline_depth) { 4051 assert(!(k == NULL && ary->_elem->isa_int()), 4052 "integral arrays must be pre-equipped with a class"); 4053 if (!xk) xk = ary->ary_must_be_exact(); 4054 assert(instance_id <= 0 || xk || !UseExactTypes, "instances are always exactly typed"); 4055 if (!UseExactTypes) xk = (ptr == Constant); 4056 return (TypeAryPtr*)(new TypeAryPtr(ptr, NULL, ary, k, xk, offset, instance_id, false, speculative, inline_depth))->hashcons(); 4057 } 4058 4059 //------------------------------make------------------------------------------- 4060 const TypeAryPtr *TypeAryPtr::make(PTR ptr, ciObject* o, const TypeAry *ary, ciKlass* k, bool xk, int offset, 4061 int instance_id, const TypePtr* speculative, int inline_depth, 4062 bool is_autobox_cache) { 4063 assert(!(k == NULL && ary->_elem->isa_int()), 4064 "integral arrays must be pre-equipped with a class"); 4065 assert( (ptr==Constant && o) || (ptr!=Constant && !o), "" ); 4066 if (!xk) xk = (o != NULL) || ary->ary_must_be_exact(); 4067 assert(instance_id <= 0 || xk || !UseExactTypes, "instances are always exactly typed"); 4068 if (!UseExactTypes) xk = (ptr == Constant); 4069 return (TypeAryPtr*)(new TypeAryPtr(ptr, o, ary, k, xk, offset, instance_id, is_autobox_cache, speculative, inline_depth))->hashcons(); 4070 } 4071 4072 //------------------------------cast_to_ptr_type------------------------------- 4073 const Type *TypeAryPtr::cast_to_ptr_type(PTR ptr) const { 4074 if( ptr == _ptr ) return this; 4075 return make(ptr, const_oop(), _ary, klass(), klass_is_exact(), _offset, _instance_id, _speculative, _inline_depth); 4076 } 4077 4078 4079 //-----------------------------cast_to_exactness------------------------------- 4080 const Type *TypeAryPtr::cast_to_exactness(bool klass_is_exact) const { 4081 if( klass_is_exact == _klass_is_exact ) return this; 4082 if (!UseExactTypes) return this; 4083 if (_ary->ary_must_be_exact()) return this; // cannot clear xk 4084 return make(ptr(), const_oop(), _ary, klass(), klass_is_exact, _offset, _instance_id, _speculative, _inline_depth); 4085 } 4086 4087 //-----------------------------cast_to_instance_id---------------------------- 4088 const TypeOopPtr *TypeAryPtr::cast_to_instance_id(int instance_id) const { 4089 if( instance_id == _instance_id ) return this; 4090 return make(_ptr, const_oop(), _ary, klass(), _klass_is_exact, _offset, instance_id, _speculative, _inline_depth); 4091 } 4092 4093 const TypeOopPtr *TypeAryPtr::cast_to_nonconst() const { 4094 if (const_oop() == NULL) return this; 4095 return make(NotNull, NULL, _ary, klass(), _klass_is_exact, _offset, _instance_id, _speculative, _inline_depth); 4096 } 4097 4098 4099 //-----------------------------narrow_size_type------------------------------- 4100 // Local cache for arrayOopDesc::max_array_length(etype), 4101 // which is kind of slow (and cached elsewhere by other users). 4102 static jint max_array_length_cache[T_CONFLICT+1]; 4103 static jint max_array_length(BasicType etype) { 4104 jint& cache = max_array_length_cache[etype]; 4105 jint res = cache; 4106 if (res == 0) { 4107 switch (etype) { 4108 case T_NARROWOOP: 4109 etype = T_OBJECT; 4110 break; 4111 case T_NARROWKLASS: 4112 case T_CONFLICT: 4113 case T_ILLEGAL: 4114 case T_VOID: 4115 etype = T_BYTE; // will produce conservatively high value 4116 break; 4117 default: 4118 break; 4119 } 4120 cache = res = arrayOopDesc::max_array_length(etype); 4121 } 4122 return res; 4123 } 4124 4125 // Narrow the given size type to the index range for the given array base type. 4126 // Return NULL if the resulting int type becomes empty. 4127 const TypeInt* TypeAryPtr::narrow_size_type(const TypeInt* size) const { 4128 jint hi = size->_hi; 4129 jint lo = size->_lo; 4130 jint min_lo = 0; 4131 jint max_hi = max_array_length(elem()->basic_type()); 4132 //if (index_not_size) --max_hi; // type of a valid array index, FTR 4133 bool chg = false; 4134 if (lo < min_lo) { 4135 lo = min_lo; 4136 if (size->is_con()) { 4137 hi = lo; 4138 } 4139 chg = true; 4140 } 4141 if (hi > max_hi) { 4142 hi = max_hi; 4143 if (size->is_con()) { 4144 lo = hi; 4145 } 4146 chg = true; 4147 } 4148 // Negative length arrays will produce weird intermediate dead fast-path code 4149 if (lo > hi) 4150 return TypeInt::ZERO; 4151 if (!chg) 4152 return size; 4153 return TypeInt::make(lo, hi, Type::WidenMin); 4154 } 4155 4156 //-------------------------------cast_to_size---------------------------------- 4157 const TypeAryPtr* TypeAryPtr::cast_to_size(const TypeInt* new_size) const { 4158 assert(new_size != NULL, ""); 4159 new_size = narrow_size_type(new_size); 4160 if (new_size == size()) return this; 4161 const TypeAry* new_ary = TypeAry::make(elem(), new_size, is_stable()); 4162 return make(ptr(), const_oop(), new_ary, klass(), klass_is_exact(), _offset, _instance_id, _speculative, _inline_depth); 4163 } 4164 4165 //------------------------------cast_to_stable--------------------------------- 4166 const TypeAryPtr* TypeAryPtr::cast_to_stable(bool stable, int stable_dimension) const { 4167 if (stable_dimension <= 0 || (stable_dimension == 1 && stable == this->is_stable())) 4168 return this; 4169 4170 const Type* elem = this->elem(); 4171 const TypePtr* elem_ptr = elem->make_ptr(); 4172 4173 if (stable_dimension > 1 && elem_ptr != NULL && elem_ptr->isa_aryptr()) { 4174 // If this is widened from a narrow oop, TypeAry::make will re-narrow it. 4175 elem = elem_ptr = elem_ptr->is_aryptr()->cast_to_stable(stable, stable_dimension - 1); 4176 } 4177 4178 const TypeAry* new_ary = TypeAry::make(elem, size(), stable); 4179 4180 return make(ptr(), const_oop(), new_ary, klass(), klass_is_exact(), _offset, _instance_id, _speculative, _inline_depth); 4181 } 4182 4183 //-----------------------------stable_dimension-------------------------------- 4184 int TypeAryPtr::stable_dimension() const { 4185 if (!is_stable()) return 0; 4186 int dim = 1; 4187 const TypePtr* elem_ptr = elem()->make_ptr(); 4188 if (elem_ptr != NULL && elem_ptr->isa_aryptr()) 4189 dim += elem_ptr->is_aryptr()->stable_dimension(); 4190 return dim; 4191 } 4192 4193 //----------------------cast_to_autobox_cache----------------------------------- 4194 const TypeAryPtr* TypeAryPtr::cast_to_autobox_cache(bool cache) const { 4195 if (is_autobox_cache() == cache) return this; 4196 const TypeOopPtr* etype = elem()->make_oopptr(); 4197 if (etype == NULL) return this; 4198 // The pointers in the autobox arrays are always non-null. 4199 TypePtr::PTR ptr_type = cache ? TypePtr::NotNull : TypePtr::AnyNull; 4200 etype = etype->cast_to_ptr_type(TypePtr::NotNull)->is_oopptr(); 4201 const TypeAry* new_ary = TypeAry::make(etype, size(), is_stable()); 4202 return make(ptr(), const_oop(), new_ary, klass(), klass_is_exact(), _offset, _instance_id, _speculative, _inline_depth, cache); 4203 } 4204 4205 //------------------------------eq--------------------------------------------- 4206 // Structural equality check for Type representations 4207 bool TypeAryPtr::eq( const Type *t ) const { 4208 const TypeAryPtr *p = t->is_aryptr(); 4209 return 4210 _ary == p->_ary && // Check array 4211 TypeOopPtr::eq(p); // Check sub-parts 4212 } 4213 4214 //------------------------------hash------------------------------------------- 4215 // Type-specific hashing function. 4216 int TypeAryPtr::hash(void) const { 4217 return (intptr_t)_ary + TypeOopPtr::hash(); 4218 } 4219 4220 //------------------------------meet------------------------------------------- 4221 // Compute the MEET of two types. It returns a new Type object. 4222 const Type *TypeAryPtr::xmeet_helper(const Type *t) const { 4223 // Perform a fast test for common case; meeting the same types together. 4224 if( this == t ) return this; // Meeting same type-rep? 4225 // Current "this->_base" is Pointer 4226 switch (t->base()) { // switch on original type 4227 4228 // Mixing ints & oops happens when javac reuses local variables 4229 case Int: 4230 case Long: 4231 case FloatTop: 4232 case FloatCon: 4233 case FloatBot: 4234 case DoubleTop: 4235 case DoubleCon: 4236 case DoubleBot: 4237 case NarrowOop: 4238 case NarrowKlass: 4239 case Bottom: // Ye Olde Default 4240 return Type::BOTTOM; 4241 case Top: 4242 return this; 4243 4244 default: // All else is a mistake 4245 typerr(t); 4246 4247 case OopPtr: { // Meeting to OopPtrs 4248 // Found a OopPtr type vs self-AryPtr type 4249 const TypeOopPtr *tp = t->is_oopptr(); 4250 int offset = meet_offset(tp->offset()); 4251 PTR ptr = meet_ptr(tp->ptr()); 4252 int depth = meet_inline_depth(tp->inline_depth()); 4253 const TypePtr* speculative = xmeet_speculative(tp); 4254 switch (tp->ptr()) { 4255 case TopPTR: 4256 case AnyNull: { 4257 int instance_id = meet_instance_id(InstanceTop); 4258 return make(ptr, (ptr == Constant ? const_oop() : NULL), 4259 _ary, _klass, _klass_is_exact, offset, instance_id, speculative, depth); 4260 } 4261 case BotPTR: 4262 case NotNull: { 4263 int instance_id = meet_instance_id(tp->instance_id()); 4264 return TypeOopPtr::make(ptr, offset, instance_id, speculative, depth); 4265 } 4266 default: ShouldNotReachHere(); 4267 } 4268 } 4269 4270 case AnyPtr: { // Meeting two AnyPtrs 4271 // Found an AnyPtr type vs self-AryPtr type 4272 const TypePtr *tp = t->is_ptr(); 4273 int offset = meet_offset(tp->offset()); 4274 PTR ptr = meet_ptr(tp->ptr()); 4275 const TypePtr* speculative = xmeet_speculative(tp); 4276 int depth = meet_inline_depth(tp->inline_depth()); 4277 switch (tp->ptr()) { 4278 case TopPTR: 4279 return this; 4280 case BotPTR: 4281 case NotNull: 4282 return TypePtr::make(AnyPtr, ptr, offset, speculative, depth); 4283 case Null: 4284 if( ptr == Null ) return TypePtr::make(AnyPtr, ptr, offset, speculative, depth); 4285 // else fall through to AnyNull 4286 case AnyNull: { 4287 int instance_id = meet_instance_id(InstanceTop); 4288 return make(ptr, (ptr == Constant ? const_oop() : NULL), 4289 _ary, _klass, _klass_is_exact, offset, instance_id, speculative, depth); 4290 } 4291 default: ShouldNotReachHere(); 4292 } 4293 } 4294 4295 case MetadataPtr: 4296 case KlassPtr: 4297 case RawPtr: return TypePtr::BOTTOM; 4298 4299 case AryPtr: { // Meeting 2 references? 4300 const TypeAryPtr *tap = t->is_aryptr(); 4301 int off = meet_offset(tap->offset()); 4302 const TypeAry *tary = _ary->meet_speculative(tap->_ary)->is_ary(); 4303 PTR ptr = meet_ptr(tap->ptr()); 4304 int instance_id = meet_instance_id(tap->instance_id()); 4305 const TypePtr* speculative = xmeet_speculative(tap); 4306 int depth = meet_inline_depth(tap->inline_depth()); 4307 ciKlass* lazy_klass = NULL; 4308 if (tary->_elem->isa_int()) { 4309 // Integral array element types have irrelevant lattice relations. 4310 // It is the klass that determines array layout, not the element type. 4311 if (_klass == NULL) 4312 lazy_klass = tap->_klass; 4313 else if (tap->_klass == NULL || tap->_klass == _klass) { 4314 lazy_klass = _klass; 4315 } else { 4316 // Something like byte[int+] meets char[int+]. 4317 // This must fall to bottom, not (int[-128..65535])[int+]. 4318 instance_id = InstanceBot; 4319 tary = TypeAry::make(Type::BOTTOM, tary->_size, tary->_stable); 4320 } 4321 } else // Non integral arrays. 4322 // Must fall to bottom if exact klasses in upper lattice 4323 // are not equal or super klass is exact. 4324 if ((above_centerline(ptr) || ptr == Constant) && klass() != tap->klass() && 4325 // meet with top[] and bottom[] are processed further down: 4326 tap->_klass != NULL && this->_klass != NULL && 4327 // both are exact and not equal: 4328 ((tap->_klass_is_exact && this->_klass_is_exact) || 4329 // 'tap' is exact and super or unrelated: 4330 (tap->_klass_is_exact && !tap->klass()->is_subtype_of(klass())) || 4331 // 'this' is exact and super or unrelated: 4332 (this->_klass_is_exact && !klass()->is_subtype_of(tap->klass())))) { 4333 if (above_centerline(ptr)) { 4334 tary = TypeAry::make(Type::BOTTOM, tary->_size, tary->_stable); 4335 } 4336 return make(NotNull, NULL, tary, lazy_klass, false, off, InstanceBot, speculative, depth); 4337 } 4338 4339 bool xk = false; 4340 switch (tap->ptr()) { 4341 case AnyNull: 4342 case TopPTR: 4343 // Compute new klass on demand, do not use tap->_klass 4344 if (below_centerline(this->_ptr)) { 4345 xk = this->_klass_is_exact; 4346 } else { 4347 xk = (tap->_klass_is_exact | this->_klass_is_exact); 4348 } 4349 return make(ptr, const_oop(), tary, lazy_klass, xk, off, instance_id, speculative, depth); 4350 case Constant: { 4351 ciObject* o = const_oop(); 4352 if( _ptr == Constant ) { 4353 if( tap->const_oop() != NULL && !o->equals(tap->const_oop()) ) { 4354 xk = (klass() == tap->klass()); 4355 ptr = NotNull; 4356 o = NULL; 4357 instance_id = InstanceBot; 4358 } else { 4359 xk = true; 4360 } 4361 } else if(above_centerline(_ptr)) { 4362 o = tap->const_oop(); 4363 xk = true; 4364 } else { 4365 // Only precise for identical arrays 4366 xk = this->_klass_is_exact && (klass() == tap->klass()); 4367 } 4368 return TypeAryPtr::make(ptr, o, tary, lazy_klass, xk, off, instance_id, speculative, depth); 4369 } 4370 case NotNull: 4371 case BotPTR: 4372 // Compute new klass on demand, do not use tap->_klass 4373 if (above_centerline(this->_ptr)) 4374 xk = tap->_klass_is_exact; 4375 else xk = (tap->_klass_is_exact & this->_klass_is_exact) && 4376 (klass() == tap->klass()); // Only precise for identical arrays 4377 return TypeAryPtr::make(ptr, NULL, tary, lazy_klass, xk, off, instance_id, speculative, depth); 4378 default: ShouldNotReachHere(); 4379 } 4380 } 4381 4382 // All arrays inherit from Object class 4383 case InstPtr: { 4384 const TypeInstPtr *tp = t->is_instptr(); 4385 int offset = meet_offset(tp->offset()); 4386 PTR ptr = meet_ptr(tp->ptr()); 4387 int instance_id = meet_instance_id(tp->instance_id()); 4388 const TypePtr* speculative = xmeet_speculative(tp); 4389 int depth = meet_inline_depth(tp->inline_depth()); 4390 switch (ptr) { 4391 case TopPTR: 4392 case AnyNull: // Fall 'down' to dual of object klass 4393 // For instances when a subclass meets a superclass we fall 4394 // below the centerline when the superclass is exact. We need to 4395 // do the same here. 4396 if (tp->klass()->equals(ciEnv::current()->Object_klass()) && !tp->klass_is_exact()) { 4397 return TypeAryPtr::make(ptr, _ary, _klass, _klass_is_exact, offset, instance_id, speculative, depth); 4398 } else { 4399 // cannot subclass, so the meet has to fall badly below the centerline 4400 ptr = NotNull; 4401 instance_id = InstanceBot; 4402 return TypeInstPtr::make(ptr, ciEnv::current()->Object_klass(), false, NULL,offset, instance_id, speculative, depth); 4403 } 4404 case Constant: 4405 case NotNull: 4406 case BotPTR: // Fall down to object klass 4407 // LCA is object_klass, but if we subclass from the top we can do better 4408 if (above_centerline(tp->ptr())) { 4409 // If 'tp' is above the centerline and it is Object class 4410 // then we can subclass in the Java class hierarchy. 4411 // For instances when a subclass meets a superclass we fall 4412 // below the centerline when the superclass is exact. We need 4413 // to do the same here. 4414 if (tp->klass()->equals(ciEnv::current()->Object_klass()) && !tp->klass_is_exact()) { 4415 // that is, my array type is a subtype of 'tp' klass 4416 return make(ptr, (ptr == Constant ? const_oop() : NULL), 4417 _ary, _klass, _klass_is_exact, offset, instance_id, speculative, depth); 4418 } 4419 } 4420 // The other case cannot happen, since t cannot be a subtype of an array. 4421 // The meet falls down to Object class below centerline. 4422 if( ptr == Constant ) 4423 ptr = NotNull; 4424 instance_id = InstanceBot; 4425 return TypeInstPtr::make(ptr, ciEnv::current()->Object_klass(), false, NULL,offset, instance_id, speculative, depth); 4426 default: typerr(t); 4427 } 4428 } 4429 } 4430 return this; // Lint noise 4431 } 4432 4433 //------------------------------xdual------------------------------------------ 4434 // Dual: compute field-by-field dual 4435 const Type *TypeAryPtr::xdual() const { 4436 return new TypeAryPtr(dual_ptr(), _const_oop, _ary->dual()->is_ary(),_klass, _klass_is_exact, dual_offset(), dual_instance_id(), is_autobox_cache(), dual_speculative(), dual_inline_depth()); 4437 } 4438 4439 //----------------------interface_vs_oop--------------------------------------- 4440 #ifdef ASSERT 4441 bool TypeAryPtr::interface_vs_oop(const Type *t) const { 4442 const TypeAryPtr* t_aryptr = t->isa_aryptr(); 4443 if (t_aryptr) { 4444 return _ary->interface_vs_oop(t_aryptr->_ary); 4445 } 4446 return false; 4447 } 4448 #endif 4449 4450 //------------------------------dump2------------------------------------------ 4451 #ifndef PRODUCT 4452 void TypeAryPtr::dump2( Dict &d, uint depth, outputStream *st ) const { 4453 _ary->dump2(d,depth,st); 4454 switch( _ptr ) { 4455 case Constant: 4456 const_oop()->print(st); 4457 break; 4458 case BotPTR: 4459 if (!WizardMode && !Verbose) { 4460 if( _klass_is_exact ) st->print(":exact"); 4461 break; 4462 } 4463 case TopPTR: 4464 case AnyNull: 4465 case NotNull: 4466 st->print(":%s", ptr_msg[_ptr]); 4467 if( _klass_is_exact ) st->print(":exact"); 4468 break; 4469 default: 4470 break; 4471 } 4472 4473 if( _offset != 0 ) { 4474 int header_size = objArrayOopDesc::header_size() * wordSize; 4475 if( _offset == OffsetTop ) st->print("+undefined"); 4476 else if( _offset == OffsetBot ) st->print("+any"); 4477 else if( _offset < header_size ) st->print("+%d", _offset); 4478 else { 4479 BasicType basic_elem_type = elem()->basic_type(); 4480 int array_base = arrayOopDesc::base_offset_in_bytes(basic_elem_type); 4481 int elem_size = type2aelembytes(basic_elem_type); 4482 st->print("[%d]", (_offset - array_base)/elem_size); 4483 } 4484 } 4485 st->print(" *"); 4486 if (_instance_id == InstanceTop) 4487 st->print(",iid=top"); 4488 else if (_instance_id != InstanceBot) 4489 st->print(",iid=%d",_instance_id); 4490 4491 dump_inline_depth(st); 4492 dump_speculative(st); 4493 } 4494 #endif 4495 4496 bool TypeAryPtr::empty(void) const { 4497 if (_ary->empty()) return true; 4498 return TypeOopPtr::empty(); 4499 } 4500 4501 //------------------------------add_offset------------------------------------- 4502 const TypePtr *TypeAryPtr::add_offset(intptr_t offset) const { 4503 return make(_ptr, _const_oop, _ary, _klass, _klass_is_exact, xadd_offset(offset), _instance_id, add_offset_speculative(offset), _inline_depth); 4504 } 4505 4506 const Type *TypeAryPtr::remove_speculative() const { 4507 if (_speculative == NULL) { 4508 return this; 4509 } 4510 assert(_inline_depth == InlineDepthTop || _inline_depth == InlineDepthBottom, "non speculative type shouldn't have inline depth"); 4511 return make(_ptr, _const_oop, _ary->remove_speculative()->is_ary(), _klass, _klass_is_exact, _offset, _instance_id, NULL, _inline_depth); 4512 } 4513 4514 const TypePtr *TypeAryPtr::with_inline_depth(int depth) const { 4515 if (!UseInlineDepthForSpeculativeTypes) { 4516 return this; 4517 } 4518 return make(_ptr, _const_oop, _ary->remove_speculative()->is_ary(), _klass, _klass_is_exact, _offset, _instance_id, _speculative, depth); 4519 } 4520 4521 //============================================================================= 4522 4523 //------------------------------hash------------------------------------------- 4524 // Type-specific hashing function. 4525 int TypeNarrowPtr::hash(void) const { 4526 return _ptrtype->hash() + 7; 4527 } 4528 4529 bool TypeNarrowPtr::singleton(void) const { // TRUE if type is a singleton 4530 return _ptrtype->singleton(); 4531 } 4532 4533 bool TypeNarrowPtr::empty(void) const { 4534 return _ptrtype->empty(); 4535 } 4536 4537 intptr_t TypeNarrowPtr::get_con() const { 4538 return _ptrtype->get_con(); 4539 } 4540 4541 bool TypeNarrowPtr::eq( const Type *t ) const { 4542 const TypeNarrowPtr* tc = isa_same_narrowptr(t); 4543 if (tc != NULL) { 4544 if (_ptrtype->base() != tc->_ptrtype->base()) { 4545 return false; 4546 } 4547 return tc->_ptrtype->eq(_ptrtype); 4548 } 4549 return false; 4550 } 4551 4552 const Type *TypeNarrowPtr::xdual() const { // Compute dual right now. 4553 const TypePtr* odual = _ptrtype->dual()->is_ptr(); 4554 return make_same_narrowptr(odual); 4555 } 4556 4557 4558 const Type *TypeNarrowPtr::filter_helper(const Type *kills, bool include_speculative) const { 4559 if (isa_same_narrowptr(kills)) { 4560 const Type* ft =_ptrtype->filter_helper(is_same_narrowptr(kills)->_ptrtype, include_speculative); 4561 if (ft->empty()) 4562 return Type::TOP; // Canonical empty value 4563 if (ft->isa_ptr()) { 4564 return make_hash_same_narrowptr(ft->isa_ptr()); 4565 } 4566 return ft; 4567 } else if (kills->isa_ptr()) { 4568 const Type* ft = _ptrtype->join_helper(kills, include_speculative); 4569 if (ft->empty()) 4570 return Type::TOP; // Canonical empty value 4571 return ft; 4572 } else { 4573 return Type::TOP; 4574 } 4575 } 4576 4577 //------------------------------xmeet------------------------------------------ 4578 // Compute the MEET of two types. It returns a new Type object. 4579 const Type *TypeNarrowPtr::xmeet( const Type *t ) const { 4580 // Perform a fast test for common case; meeting the same types together. 4581 if( this == t ) return this; // Meeting same type-rep? 4582 4583 if (t->base() == base()) { 4584 const Type* result = _ptrtype->xmeet(t->make_ptr()); 4585 if (result->isa_ptr()) { 4586 return make_hash_same_narrowptr(result->is_ptr()); 4587 } 4588 return result; 4589 } 4590 4591 // Current "this->_base" is NarrowKlass or NarrowOop 4592 switch (t->base()) { // switch on original type 4593 4594 case Int: // Mixing ints & oops happens when javac 4595 case Long: // reuses local variables 4596 case FloatTop: 4597 case FloatCon: 4598 case FloatBot: 4599 case DoubleTop: 4600 case DoubleCon: 4601 case DoubleBot: 4602 case AnyPtr: 4603 case RawPtr: 4604 case OopPtr: 4605 case InstPtr: 4606 case AryPtr: 4607 case MetadataPtr: 4608 case KlassPtr: 4609 case NarrowOop: 4610 case NarrowKlass: 4611 4612 case Bottom: // Ye Olde Default 4613 return Type::BOTTOM; 4614 case Top: 4615 return this; 4616 4617 default: // All else is a mistake 4618 typerr(t); 4619 4620 } // End of switch 4621 4622 return this; 4623 } 4624 4625 #ifndef PRODUCT 4626 void TypeNarrowPtr::dump2( Dict & d, uint depth, outputStream *st ) const { 4627 _ptrtype->dump2(d, depth, st); 4628 } 4629 #endif 4630 4631 const TypeNarrowOop *TypeNarrowOop::BOTTOM; 4632 const TypeNarrowOop *TypeNarrowOop::NULL_PTR; 4633 4634 4635 const TypeNarrowOop* TypeNarrowOop::make(const TypePtr* type) { 4636 return (const TypeNarrowOop*)(new TypeNarrowOop(type))->hashcons(); 4637 } 4638 4639 const Type* TypeNarrowOop::remove_speculative() const { 4640 return make(_ptrtype->remove_speculative()->is_ptr()); 4641 } 4642 4643 const Type* TypeNarrowOop::cleanup_speculative() const { 4644 return make(_ptrtype->cleanup_speculative()->is_ptr()); 4645 } 4646 4647 #ifndef PRODUCT 4648 void TypeNarrowOop::dump2( Dict & d, uint depth, outputStream *st ) const { 4649 st->print("narrowoop: "); 4650 TypeNarrowPtr::dump2(d, depth, st); 4651 } 4652 #endif 4653 4654 const TypeNarrowKlass *TypeNarrowKlass::NULL_PTR; 4655 4656 const TypeNarrowKlass* TypeNarrowKlass::make(const TypePtr* type) { 4657 return (const TypeNarrowKlass*)(new TypeNarrowKlass(type))->hashcons(); 4658 } 4659 4660 #ifndef PRODUCT 4661 void TypeNarrowKlass::dump2( Dict & d, uint depth, outputStream *st ) const { 4662 st->print("narrowklass: "); 4663 TypeNarrowPtr::dump2(d, depth, st); 4664 } 4665 #endif 4666 4667 4668 //------------------------------eq--------------------------------------------- 4669 // Structural equality check for Type representations 4670 bool TypeMetadataPtr::eq( const Type *t ) const { 4671 const TypeMetadataPtr *a = (const TypeMetadataPtr*)t; 4672 ciMetadata* one = metadata(); 4673 ciMetadata* two = a->metadata(); 4674 if (one == NULL || two == NULL) { 4675 return (one == two) && TypePtr::eq(t); 4676 } else { 4677 return one->equals(two) && TypePtr::eq(t); 4678 } 4679 } 4680 4681 //------------------------------hash------------------------------------------- 4682 // Type-specific hashing function. 4683 int TypeMetadataPtr::hash(void) const { 4684 return 4685 (metadata() ? metadata()->hash() : 0) + 4686 TypePtr::hash(); 4687 } 4688 4689 //------------------------------singleton-------------------------------------- 4690 // TRUE if Type is a singleton type, FALSE otherwise. Singletons are simple 4691 // constants 4692 bool TypeMetadataPtr::singleton(void) const { 4693 // detune optimizer to not generate constant metadata + constant offset as a constant! 4694 // TopPTR, Null, AnyNull, Constant are all singletons 4695 return (_offset == 0) && !below_centerline(_ptr); 4696 } 4697 4698 //------------------------------add_offset------------------------------------- 4699 const TypePtr *TypeMetadataPtr::add_offset( intptr_t offset ) const { 4700 return make( _ptr, _metadata, xadd_offset(offset)); 4701 } 4702 4703 //-----------------------------filter------------------------------------------ 4704 // Do not allow interface-vs.-noninterface joins to collapse to top. 4705 const Type *TypeMetadataPtr::filter_helper(const Type *kills, bool include_speculative) const { 4706 const TypeMetadataPtr* ft = join_helper(kills, include_speculative)->isa_metadataptr(); 4707 if (ft == NULL || ft->empty()) 4708 return Type::TOP; // Canonical empty value 4709 return ft; 4710 } 4711 4712 //------------------------------get_con---------------------------------------- 4713 intptr_t TypeMetadataPtr::get_con() const { 4714 assert( _ptr == Null || _ptr == Constant, "" ); 4715 assert( _offset >= 0, "" ); 4716 4717 if (_offset != 0) { 4718 // After being ported to the compiler interface, the compiler no longer 4719 // directly manipulates the addresses of oops. Rather, it only has a pointer 4720 // to a handle at compile time. This handle is embedded in the generated 4721 // code and dereferenced at the time the nmethod is made. Until that time, 4722 // it is not reasonable to do arithmetic with the addresses of oops (we don't 4723 // have access to the addresses!). This does not seem to currently happen, 4724 // but this assertion here is to help prevent its occurence. 4725 tty->print_cr("Found oop constant with non-zero offset"); 4726 ShouldNotReachHere(); 4727 } 4728 4729 return (intptr_t)metadata()->constant_encoding(); 4730 } 4731 4732 //------------------------------cast_to_ptr_type------------------------------- 4733 const Type *TypeMetadataPtr::cast_to_ptr_type(PTR ptr) const { 4734 if( ptr == _ptr ) return this; 4735 return make(ptr, metadata(), _offset); 4736 } 4737 4738 //------------------------------meet------------------------------------------- 4739 // Compute the MEET of two types. It returns a new Type object. 4740 const Type *TypeMetadataPtr::xmeet( const Type *t ) const { 4741 // Perform a fast test for common case; meeting the same types together. 4742 if( this == t ) return this; // Meeting same type-rep? 4743 4744 // Current "this->_base" is OopPtr 4745 switch (t->base()) { // switch on original type 4746 4747 case Int: // Mixing ints & oops happens when javac 4748 case Long: // reuses local variables 4749 case FloatTop: 4750 case FloatCon: 4751 case FloatBot: 4752 case DoubleTop: 4753 case DoubleCon: 4754 case DoubleBot: 4755 case NarrowOop: 4756 case NarrowKlass: 4757 case Bottom: // Ye Olde Default 4758 return Type::BOTTOM; 4759 case Top: 4760 return this; 4761 4762 default: // All else is a mistake 4763 typerr(t); 4764 4765 case AnyPtr: { 4766 // Found an AnyPtr type vs self-OopPtr type 4767 const TypePtr *tp = t->is_ptr(); 4768 int offset = meet_offset(tp->offset()); 4769 PTR ptr = meet_ptr(tp->ptr()); 4770 switch (tp->ptr()) { 4771 case Null: 4772 if (ptr == Null) return TypePtr::make(AnyPtr, ptr, offset, tp->speculative(), tp->inline_depth()); 4773 // else fall through: 4774 case TopPTR: 4775 case AnyNull: { 4776 return make(ptr, _metadata, offset); 4777 } 4778 case BotPTR: 4779 case NotNull: 4780 return TypePtr::make(AnyPtr, ptr, offset, tp->speculative(), tp->inline_depth()); 4781 default: typerr(t); 4782 } 4783 } 4784 4785 case RawPtr: 4786 case KlassPtr: 4787 case OopPtr: 4788 case InstPtr: 4789 case AryPtr: 4790 return TypePtr::BOTTOM; // Oop meet raw is not well defined 4791 4792 case MetadataPtr: { 4793 const TypeMetadataPtr *tp = t->is_metadataptr(); 4794 int offset = meet_offset(tp->offset()); 4795 PTR tptr = tp->ptr(); 4796 PTR ptr = meet_ptr(tptr); 4797 ciMetadata* md = (tptr == TopPTR) ? metadata() : tp->metadata(); 4798 if (tptr == TopPTR || _ptr == TopPTR || 4799 metadata()->equals(tp->metadata())) { 4800 return make(ptr, md, offset); 4801 } 4802 // metadata is different 4803 if( ptr == Constant ) { // Cannot be equal constants, so... 4804 if( tptr == Constant && _ptr != Constant) return t; 4805 if( _ptr == Constant && tptr != Constant) return this; 4806 ptr = NotNull; // Fall down in lattice 4807 } 4808 return make(ptr, NULL, offset); 4809 break; 4810 } 4811 } // End of switch 4812 return this; // Return the double constant 4813 } 4814 4815 4816 //------------------------------xdual------------------------------------------ 4817 // Dual of a pure metadata pointer. 4818 const Type *TypeMetadataPtr::xdual() const { 4819 return new TypeMetadataPtr(dual_ptr(), metadata(), dual_offset()); 4820 } 4821 4822 //------------------------------dump2------------------------------------------ 4823 #ifndef PRODUCT 4824 void TypeMetadataPtr::dump2( Dict &d, uint depth, outputStream *st ) const { 4825 st->print("metadataptr:%s", ptr_msg[_ptr]); 4826 if( metadata() ) st->print(INTPTR_FORMAT, p2i(metadata())); 4827 switch( _offset ) { 4828 case OffsetTop: st->print("+top"); break; 4829 case OffsetBot: st->print("+any"); break; 4830 case 0: break; 4831 default: st->print("+%d",_offset); break; 4832 } 4833 } 4834 #endif 4835 4836 4837 //============================================================================= 4838 // Convenience common pre-built type. 4839 const TypeMetadataPtr *TypeMetadataPtr::BOTTOM; 4840 4841 TypeMetadataPtr::TypeMetadataPtr(PTR ptr, ciMetadata* metadata, int offset): 4842 TypePtr(MetadataPtr, ptr, offset), _metadata(metadata) { 4843 } 4844 4845 const TypeMetadataPtr* TypeMetadataPtr::make(ciMethod* m) { 4846 return make(Constant, m, 0); 4847 } 4848 const TypeMetadataPtr* TypeMetadataPtr::make(ciMethodData* m) { 4849 return make(Constant, m, 0); 4850 } 4851 4852 //------------------------------make------------------------------------------- 4853 // Create a meta data constant 4854 const TypeMetadataPtr *TypeMetadataPtr::make(PTR ptr, ciMetadata* m, int offset) { 4855 assert(m == NULL || !m->is_klass(), "wrong type"); 4856 return (TypeMetadataPtr*)(new TypeMetadataPtr(ptr, m, offset))->hashcons(); 4857 } 4858 4859 4860 //============================================================================= 4861 // Convenience common pre-built types. 4862 4863 // Not-null object klass or below 4864 const TypeKlassPtr *TypeKlassPtr::OBJECT; 4865 const TypeKlassPtr *TypeKlassPtr::OBJECT_OR_NULL; 4866 4867 //------------------------------TypeKlassPtr----------------------------------- 4868 TypeKlassPtr::TypeKlassPtr( PTR ptr, ciKlass* klass, int offset ) 4869 : TypePtr(KlassPtr, ptr, offset), _klass(klass), _klass_is_exact(ptr == Constant) { 4870 } 4871 4872 //------------------------------make------------------------------------------- 4873 // ptr to klass 'k', if Constant, or possibly to a sub-klass if not a Constant 4874 const TypeKlassPtr *TypeKlassPtr::make( PTR ptr, ciKlass* k, int offset ) { 4875 assert( k != NULL, "Expect a non-NULL klass"); 4876 assert(k->is_instance_klass() || k->is_array_klass(), "Incorrect type of klass oop"); 4877 TypeKlassPtr *r = 4878 (TypeKlassPtr*)(new TypeKlassPtr(ptr, k, offset))->hashcons(); 4879 4880 return r; 4881 } 4882 4883 //------------------------------eq--------------------------------------------- 4884 // Structural equality check for Type representations 4885 bool TypeKlassPtr::eq( const Type *t ) const { 4886 const TypeKlassPtr *p = t->is_klassptr(); 4887 return 4888 klass()->equals(p->klass()) && 4889 TypePtr::eq(p); 4890 } 4891 4892 //------------------------------hash------------------------------------------- 4893 // Type-specific hashing function. 4894 int TypeKlassPtr::hash(void) const { 4895 return java_add((jint)klass()->hash(), (jint)TypePtr::hash()); 4896 } 4897 4898 //------------------------------singleton-------------------------------------- 4899 // TRUE if Type is a singleton type, FALSE otherwise. Singletons are simple 4900 // constants 4901 bool TypeKlassPtr::singleton(void) const { 4902 // detune optimizer to not generate constant klass + constant offset as a constant! 4903 // TopPTR, Null, AnyNull, Constant are all singletons 4904 return (_offset == 0) && !below_centerline(_ptr); 4905 } 4906 4907 // Do not allow interface-vs.-noninterface joins to collapse to top. 4908 const Type *TypeKlassPtr::filter_helper(const Type *kills, bool include_speculative) const { 4909 // logic here mirrors the one from TypeOopPtr::filter. See comments 4910 // there. 4911 const Type* ft = join_helper(kills, include_speculative); 4912 const TypeKlassPtr* ftkp = ft->isa_klassptr(); 4913 const TypeKlassPtr* ktkp = kills->isa_klassptr(); 4914 4915 if (ft->empty()) { 4916 if (!empty() && ktkp != NULL && ktkp->klass()->is_loaded() && ktkp->klass()->is_interface()) 4917 return kills; // Uplift to interface 4918 4919 return Type::TOP; // Canonical empty value 4920 } 4921 4922 // Interface klass type could be exact in opposite to interface type, 4923 // return it here instead of incorrect Constant ptr J/L/Object (6894807). 4924 if (ftkp != NULL && ktkp != NULL && 4925 ftkp->is_loaded() && ftkp->klass()->is_interface() && 4926 !ftkp->klass_is_exact() && // Keep exact interface klass 4927 ktkp->is_loaded() && !ktkp->klass()->is_interface()) { 4928 return ktkp->cast_to_ptr_type(ftkp->ptr()); 4929 } 4930 4931 return ft; 4932 } 4933 4934 //----------------------compute_klass------------------------------------------ 4935 // Compute the defining klass for this class 4936 ciKlass* TypeAryPtr::compute_klass(DEBUG_ONLY(bool verify)) const { 4937 // Compute _klass based on element type. 4938 ciKlass* k_ary = NULL; 4939 const TypeInstPtr *tinst; 4940 const TypeAryPtr *tary; 4941 const Type* el = elem(); 4942 if (el->isa_narrowoop()) { 4943 el = el->make_ptr(); 4944 } 4945 4946 // Get element klass 4947 if ((tinst = el->isa_instptr()) != NULL) { 4948 // Compute array klass from element klass 4949 k_ary = ciObjArrayKlass::make(tinst->klass()); 4950 } else if ((tary = el->isa_aryptr()) != NULL) { 4951 // Compute array klass from element klass 4952 ciKlass* k_elem = tary->klass(); 4953 // If element type is something like bottom[], k_elem will be null. 4954 if (k_elem != NULL) 4955 k_ary = ciObjArrayKlass::make(k_elem); 4956 } else if ((el->base() == Type::Top) || 4957 (el->base() == Type::Bottom)) { 4958 // element type of Bottom occurs from meet of basic type 4959 // and object; Top occurs when doing join on Bottom. 4960 // Leave k_ary at NULL. 4961 } else { 4962 // Cannot compute array klass directly from basic type, 4963 // since subtypes of TypeInt all have basic type T_INT. 4964 #ifdef ASSERT 4965 if (verify && el->isa_int()) { 4966 // Check simple cases when verifying klass. 4967 BasicType bt = T_ILLEGAL; 4968 if (el == TypeInt::BYTE) { 4969 bt = T_BYTE; 4970 } else if (el == TypeInt::SHORT) { 4971 bt = T_SHORT; 4972 } else if (el == TypeInt::CHAR) { 4973 bt = T_CHAR; 4974 } else if (el == TypeInt::INT) { 4975 bt = T_INT; 4976 } else { 4977 return _klass; // just return specified klass 4978 } 4979 return ciTypeArrayKlass::make(bt); 4980 } 4981 #endif 4982 assert(!el->isa_int(), 4983 "integral arrays must be pre-equipped with a class"); 4984 // Compute array klass directly from basic type 4985 k_ary = ciTypeArrayKlass::make(el->basic_type()); 4986 } 4987 return k_ary; 4988 } 4989 4990 //------------------------------klass------------------------------------------ 4991 // Return the defining klass for this class 4992 ciKlass* TypeAryPtr::klass() const { 4993 if( _klass ) return _klass; // Return cached value, if possible 4994 4995 // Oops, need to compute _klass and cache it 4996 ciKlass* k_ary = compute_klass(); 4997 4998 if( this != TypeAryPtr::OOPS && this->dual() != TypeAryPtr::OOPS ) { 4999 // The _klass field acts as a cache of the underlying 5000 // ciKlass for this array type. In order to set the field, 5001 // we need to cast away const-ness. 5002 // 5003 // IMPORTANT NOTE: we *never* set the _klass field for the 5004 // type TypeAryPtr::OOPS. This Type is shared between all 5005 // active compilations. However, the ciKlass which represents 5006 // this Type is *not* shared between compilations, so caching 5007 // this value would result in fetching a dangling pointer. 5008 // 5009 // Recomputing the underlying ciKlass for each request is 5010 // a bit less efficient than caching, but calls to 5011 // TypeAryPtr::OOPS->klass() are not common enough to matter. 5012 ((TypeAryPtr*)this)->_klass = k_ary; 5013 if (UseCompressedOops && k_ary != NULL && k_ary->is_obj_array_klass() && 5014 _offset != 0 && _offset != arrayOopDesc::length_offset_in_bytes()) { 5015 ((TypeAryPtr*)this)->_is_ptr_to_narrowoop = true; 5016 } 5017 } 5018 return k_ary; 5019 } 5020 5021 5022 //------------------------------add_offset------------------------------------- 5023 // Access internals of klass object 5024 const TypePtr *TypeKlassPtr::add_offset( intptr_t offset ) const { 5025 return make( _ptr, klass(), xadd_offset(offset) ); 5026 } 5027 5028 //------------------------------cast_to_ptr_type------------------------------- 5029 const Type *TypeKlassPtr::cast_to_ptr_type(PTR ptr) const { 5030 assert(_base == KlassPtr, "subclass must override cast_to_ptr_type"); 5031 if( ptr == _ptr ) return this; 5032 return make(ptr, _klass, _offset); 5033 } 5034 5035 5036 //-----------------------------cast_to_exactness------------------------------- 5037 const Type *TypeKlassPtr::cast_to_exactness(bool klass_is_exact) const { 5038 if( klass_is_exact == _klass_is_exact ) return this; 5039 if (!UseExactTypes) return this; 5040 return make(klass_is_exact ? Constant : NotNull, _klass, _offset); 5041 } 5042 5043 5044 //-----------------------------as_instance_type-------------------------------- 5045 // Corresponding type for an instance of the given class. 5046 // It will be NotNull, and exact if and only if the klass type is exact. 5047 const TypeOopPtr* TypeKlassPtr::as_instance_type() const { 5048 ciKlass* k = klass(); 5049 bool xk = klass_is_exact(); 5050 //return TypeInstPtr::make(TypePtr::NotNull, k, xk, NULL, 0); 5051 const TypeOopPtr* toop = TypeOopPtr::make_from_klass_raw(k); 5052 guarantee(toop != NULL, "need type for given klass"); 5053 toop = toop->cast_to_ptr_type(TypePtr::NotNull)->is_oopptr(); 5054 return toop->cast_to_exactness(xk)->is_oopptr(); 5055 } 5056 5057 5058 //------------------------------xmeet------------------------------------------ 5059 // Compute the MEET of two types, return a new Type object. 5060 const Type *TypeKlassPtr::xmeet( const Type *t ) const { 5061 // Perform a fast test for common case; meeting the same types together. 5062 if( this == t ) return this; // Meeting same type-rep? 5063 5064 // Current "this->_base" is Pointer 5065 switch (t->base()) { // switch on original type 5066 5067 case Int: // Mixing ints & oops happens when javac 5068 case Long: // reuses local variables 5069 case FloatTop: 5070 case FloatCon: 5071 case FloatBot: 5072 case DoubleTop: 5073 case DoubleCon: 5074 case DoubleBot: 5075 case NarrowOop: 5076 case NarrowKlass: 5077 case Bottom: // Ye Olde Default 5078 return Type::BOTTOM; 5079 case Top: 5080 return this; 5081 5082 default: // All else is a mistake 5083 typerr(t); 5084 5085 case AnyPtr: { // Meeting to AnyPtrs 5086 // Found an AnyPtr type vs self-KlassPtr type 5087 const TypePtr *tp = t->is_ptr(); 5088 int offset = meet_offset(tp->offset()); 5089 PTR ptr = meet_ptr(tp->ptr()); 5090 switch (tp->ptr()) { 5091 case TopPTR: 5092 return this; 5093 case Null: 5094 if( ptr == Null ) return TypePtr::make(AnyPtr, ptr, offset, tp->speculative(), tp->inline_depth()); 5095 case AnyNull: 5096 return make( ptr, klass(), offset ); 5097 case BotPTR: 5098 case NotNull: 5099 return TypePtr::make(AnyPtr, ptr, offset, tp->speculative(), tp->inline_depth()); 5100 default: typerr(t); 5101 } 5102 } 5103 5104 case RawPtr: 5105 case MetadataPtr: 5106 case OopPtr: 5107 case AryPtr: // Meet with AryPtr 5108 case InstPtr: // Meet with InstPtr 5109 return TypePtr::BOTTOM; 5110 5111 // 5112 // A-top } 5113 // / | \ } Tops 5114 // B-top A-any C-top } 5115 // | / | \ | } Any-nulls 5116 // B-any | C-any } 5117 // | | | 5118 // B-con A-con C-con } constants; not comparable across classes 5119 // | | | 5120 // B-not | C-not } 5121 // | \ | / | } not-nulls 5122 // B-bot A-not C-bot } 5123 // \ | / } Bottoms 5124 // A-bot } 5125 // 5126 5127 case KlassPtr: { // Meet two KlassPtr types 5128 const TypeKlassPtr *tkls = t->is_klassptr(); 5129 int off = meet_offset(tkls->offset()); 5130 PTR ptr = meet_ptr(tkls->ptr()); 5131 5132 // Check for easy case; klasses are equal (and perhaps not loaded!) 5133 // If we have constants, then we created oops so classes are loaded 5134 // and we can handle the constants further down. This case handles 5135 // not-loaded classes 5136 if( ptr != Constant && tkls->klass()->equals(klass()) ) { 5137 return make( ptr, klass(), off ); 5138 } 5139 5140 // Classes require inspection in the Java klass hierarchy. Must be loaded. 5141 ciKlass* tkls_klass = tkls->klass(); 5142 ciKlass* this_klass = this->klass(); 5143 assert( tkls_klass->is_loaded(), "This class should have been loaded."); 5144 assert( this_klass->is_loaded(), "This class should have been loaded."); 5145 5146 // If 'this' type is above the centerline and is a superclass of the 5147 // other, we can treat 'this' as having the same type as the other. 5148 if ((above_centerline(this->ptr())) && 5149 tkls_klass->is_subtype_of(this_klass)) { 5150 this_klass = tkls_klass; 5151 } 5152 // If 'tinst' type is above the centerline and is a superclass of the 5153 // other, we can treat 'tinst' as having the same type as the other. 5154 if ((above_centerline(tkls->ptr())) && 5155 this_klass->is_subtype_of(tkls_klass)) { 5156 tkls_klass = this_klass; 5157 } 5158 5159 // Check for classes now being equal 5160 if (tkls_klass->equals(this_klass)) { 5161 // If the klasses are equal, the constants may still differ. Fall to 5162 // NotNull if they do (neither constant is NULL; that is a special case 5163 // handled elsewhere). 5164 if( ptr == Constant ) { 5165 if (this->_ptr == Constant && tkls->_ptr == Constant && 5166 this->klass()->equals(tkls->klass())); 5167 else if (above_centerline(this->ptr())); 5168 else if (above_centerline(tkls->ptr())); 5169 else 5170 ptr = NotNull; 5171 } 5172 return make( ptr, this_klass, off ); 5173 } // Else classes are not equal 5174 5175 // Since klasses are different, we require the LCA in the Java 5176 // class hierarchy - which means we have to fall to at least NotNull. 5177 if( ptr == TopPTR || ptr == AnyNull || ptr == Constant ) 5178 ptr = NotNull; 5179 // Now we find the LCA of Java classes 5180 ciKlass* k = this_klass->least_common_ancestor(tkls_klass); 5181 return make( ptr, k, off ); 5182 } // End of case KlassPtr 5183 5184 } // End of switch 5185 return this; // Return the double constant 5186 } 5187 5188 //------------------------------xdual------------------------------------------ 5189 // Dual: compute field-by-field dual 5190 const Type *TypeKlassPtr::xdual() const { 5191 return new TypeKlassPtr( dual_ptr(), klass(), dual_offset() ); 5192 } 5193 5194 //------------------------------get_con---------------------------------------- 5195 intptr_t TypeKlassPtr::get_con() const { 5196 assert( _ptr == Null || _ptr == Constant, "" ); 5197 assert( _offset >= 0, "" ); 5198 5199 if (_offset != 0) { 5200 // After being ported to the compiler interface, the compiler no longer 5201 // directly manipulates the addresses of oops. Rather, it only has a pointer 5202 // to a handle at compile time. This handle is embedded in the generated 5203 // code and dereferenced at the time the nmethod is made. Until that time, 5204 // it is not reasonable to do arithmetic with the addresses of oops (we don't 5205 // have access to the addresses!). This does not seem to currently happen, 5206 // but this assertion here is to help prevent its occurence. 5207 tty->print_cr("Found oop constant with non-zero offset"); 5208 ShouldNotReachHere(); 5209 } 5210 5211 return (intptr_t)klass()->constant_encoding(); 5212 } 5213 //------------------------------dump2------------------------------------------ 5214 // Dump Klass Type 5215 #ifndef PRODUCT 5216 void TypeKlassPtr::dump2( Dict & d, uint depth, outputStream *st ) const { 5217 switch( _ptr ) { 5218 case Constant: 5219 st->print("precise "); 5220 case NotNull: 5221 { 5222 const char *name = klass()->name()->as_utf8(); 5223 if( name ) { 5224 st->print("klass %s: " INTPTR_FORMAT, name, p2i(klass())); 5225 } else { 5226 ShouldNotReachHere(); 5227 } 5228 } 5229 case BotPTR: 5230 if( !WizardMode && !Verbose && !_klass_is_exact ) break; 5231 case TopPTR: 5232 case AnyNull: 5233 st->print(":%s", ptr_msg[_ptr]); 5234 if( _klass_is_exact ) st->print(":exact"); 5235 break; 5236 default: 5237 break; 5238 } 5239 5240 if( _offset ) { // Dump offset, if any 5241 if( _offset == OffsetBot ) { st->print("+any"); } 5242 else if( _offset == OffsetTop ) { st->print("+unknown"); } 5243 else { st->print("+%d", _offset); } 5244 } 5245 5246 st->print(" *"); 5247 } 5248 #endif 5249 5250 5251 5252 //============================================================================= 5253 // Convenience common pre-built types. 5254 5255 //------------------------------make------------------------------------------- 5256 const TypeFunc *TypeFunc::make( const TypeTuple *domain, const TypeTuple *range ) { 5257 return (TypeFunc*)(new TypeFunc(domain,range))->hashcons(); 5258 } 5259 5260 //------------------------------make------------------------------------------- 5261 const TypeFunc *TypeFunc::make(ciMethod* method) { 5262 Compile* C = Compile::current(); 5263 const TypeFunc* tf = C->last_tf(method); // check cache 5264 if (tf != NULL) return tf; // The hit rate here is almost 50%. 5265 const TypeTuple *domain; 5266 if (method->is_static()) { 5267 domain = TypeTuple::make_domain(NULL, method->signature()); 5268 } else { 5269 domain = TypeTuple::make_domain(method->holder(), method->signature()); 5270 } 5271 const TypeTuple *range = TypeTuple::make_range(method->signature()); 5272 tf = TypeFunc::make(domain, range); 5273 C->set_last_tf(method, tf); // fill cache 5274 return tf; 5275 } 5276 5277 //------------------------------meet------------------------------------------- 5278 // Compute the MEET of two types. It returns a new Type object. 5279 const Type *TypeFunc::xmeet( const Type *t ) const { 5280 // Perform a fast test for common case; meeting the same types together. 5281 if( this == t ) return this; // Meeting same type-rep? 5282 5283 // Current "this->_base" is Func 5284 switch (t->base()) { // switch on original type 5285 5286 case Bottom: // Ye Olde Default 5287 return t; 5288 5289 default: // All else is a mistake 5290 typerr(t); 5291 5292 case Top: 5293 break; 5294 } 5295 return this; // Return the double constant 5296 } 5297 5298 //------------------------------xdual------------------------------------------ 5299 // Dual: compute field-by-field dual 5300 const Type *TypeFunc::xdual() const { 5301 return this; 5302 } 5303 5304 //------------------------------eq--------------------------------------------- 5305 // Structural equality check for Type representations 5306 bool TypeFunc::eq( const Type *t ) const { 5307 const TypeFunc *a = (const TypeFunc*)t; 5308 return _domain == a->_domain && 5309 _range == a->_range; 5310 } 5311 5312 //------------------------------hash------------------------------------------- 5313 // Type-specific hashing function. 5314 int TypeFunc::hash(void) const { 5315 return (intptr_t)_domain + (intptr_t)_range; 5316 } 5317 5318 //------------------------------dump2------------------------------------------ 5319 // Dump Function Type 5320 #ifndef PRODUCT 5321 void TypeFunc::dump2( Dict &d, uint depth, outputStream *st ) const { 5322 if( _range->cnt() <= Parms ) 5323 st->print("void"); 5324 else { 5325 uint i; 5326 for (i = Parms; i < _range->cnt()-1; i++) { 5327 _range->field_at(i)->dump2(d,depth,st); 5328 st->print("/"); 5329 } 5330 _range->field_at(i)->dump2(d,depth,st); 5331 } 5332 st->print(" "); 5333 st->print("( "); 5334 if( !depth || d[this] ) { // Check for recursive dump 5335 st->print("...)"); 5336 return; 5337 } 5338 d.Insert((void*)this,(void*)this); // Stop recursion 5339 if (Parms < _domain->cnt()) 5340 _domain->field_at(Parms)->dump2(d,depth-1,st); 5341 for (uint i = Parms+1; i < _domain->cnt(); i++) { 5342 st->print(", "); 5343 _domain->field_at(i)->dump2(d,depth-1,st); 5344 } 5345 st->print(" )"); 5346 } 5347 #endif 5348 5349 //------------------------------singleton-------------------------------------- 5350 // TRUE if Type is a singleton type, FALSE otherwise. Singletons are simple 5351 // constants (Ldi nodes). Singletons are integer, float or double constants 5352 // or a single symbol. 5353 bool TypeFunc::singleton(void) const { 5354 return false; // Never a singleton 5355 } 5356 5357 bool TypeFunc::empty(void) const { 5358 return false; // Never empty 5359 } 5360 5361 5362 BasicType TypeFunc::return_type() const{ 5363 if (range()->cnt() == TypeFunc::Parms) { 5364 return T_VOID; 5365 } 5366 return range()->field_at(TypeFunc::Parms)->basic_type(); 5367 }