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