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