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