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