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