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