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