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