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