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