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 || EnableMVT) ? 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 //------------------------------make------------------------------------------- 1932 // Make a TypeTuple from the range of a method signature 1933 const TypeTuple *TypeTuple::make_range(ciSignature* sig, bool ret_vt_fields) { 1934 ciType* return_type = sig->return_type(); 1935 uint arg_cnt = 0; 1936 if (ret_vt_fields) { 1937 ret_vt_fields = return_type->is_valuetype() && ((ciValueKlass*)return_type)->can_be_returned_as_fields(); 1938 } 1939 if (ret_vt_fields) { 1940 ciValueKlass* vk = (ciValueKlass*)return_type; 1941 arg_cnt = vk->value_arg_slots()+1; 1942 } else { 1943 arg_cnt = return_type->size(); 1944 } 1945 1946 const Type **field_array = fields(arg_cnt); 1947 switch (return_type->basic_type()) { 1948 case T_LONG: 1949 field_array[TypeFunc::Parms] = TypeLong::LONG; 1950 field_array[TypeFunc::Parms+1] = Type::HALF; 1951 break; 1952 case T_DOUBLE: 1953 field_array[TypeFunc::Parms] = Type::DOUBLE; 1954 field_array[TypeFunc::Parms+1] = Type::HALF; 1955 break; 1956 case T_OBJECT: 1957 case T_ARRAY: 1958 case T_BOOLEAN: 1959 case T_CHAR: 1960 case T_FLOAT: 1961 case T_BYTE: 1962 case T_SHORT: 1963 case T_INT: 1964 field_array[TypeFunc::Parms] = get_const_type(return_type); 1965 break; 1966 case T_VALUETYPE: 1967 if (ret_vt_fields) { 1968 ciValueKlass* vk = (ciValueKlass*)return_type; 1969 uint pos = TypeFunc::Parms; 1970 field_array[pos] = TypeKlassPtr::make(vk); 1971 pos++; 1972 collect_value_fields(vk, field_array, pos); 1973 } else { 1974 field_array[TypeFunc::Parms] = get_const_type(return_type); 1975 } 1976 break; 1977 case T_VOID: 1978 break; 1979 default: 1980 ShouldNotReachHere(); 1981 } 1982 return (TypeTuple*)(new TypeTuple(TypeFunc::Parms + arg_cnt, field_array))->hashcons(); 1983 } 1984 1985 // Make a TypeTuple from the domain of a method signature 1986 const TypeTuple *TypeTuple::make_domain(ciInstanceKlass* recv, ciSignature* sig, bool vt_fields_as_args) { 1987 uint arg_cnt = sig->size(); 1988 1989 int vt_extra = 0; 1990 if (vt_fields_as_args) { 1991 for (int i = 0; i < sig->count(); i++) { 1992 ciType* type = sig->type_at(i); 1993 if (type->basic_type() == T_VALUETYPE && type != ciEnv::current()->___Value_klass()) { 1994 assert(type->is_valuetype(), "inconsistent type"); 1995 ciValueKlass* vk = (ciValueKlass*)type; 1996 vt_extra += vk->value_arg_slots()-1; 1997 } 1998 } 1999 assert(((int)arg_cnt) + vt_extra >= 0, "negative number of actual arguments?"); 2000 } 2001 2002 uint pos = TypeFunc::Parms; 2003 const Type **field_array; 2004 if (recv != NULL) { 2005 arg_cnt++; 2006 bool vt_fields_for_recv = vt_fields_as_args && recv->is_valuetype() && 2007 recv != ciEnv::current()->___Value_klass(); 2008 if (vt_fields_for_recv) { 2009 ciValueKlass* vk = (ciValueKlass*)recv; 2010 vt_extra += vk->value_arg_slots()-1; 2011 } 2012 field_array = fields(arg_cnt + vt_extra); 2013 // Use get_const_type here because it respects UseUniqueSubclasses: 2014 if (vt_fields_for_recv) { 2015 ciValueKlass* vk = (ciValueKlass*)recv; 2016 collect_value_fields(vk, field_array, pos); 2017 } else { 2018 field_array[pos++] = get_const_type(recv)->join_speculative(TypePtr::NOTNULL); 2019 } 2020 } else { 2021 field_array = fields(arg_cnt + vt_extra); 2022 } 2023 2024 int i = 0; 2025 while (pos < TypeFunc::Parms + arg_cnt + vt_extra) { 2026 ciType* type = sig->type_at(i); 2027 2028 switch (type->basic_type()) { 2029 case T_LONG: 2030 field_array[pos++] = TypeLong::LONG; 2031 field_array[pos++] = Type::HALF; 2032 break; 2033 case T_DOUBLE: 2034 field_array[pos++] = Type::DOUBLE; 2035 field_array[pos++] = Type::HALF; 2036 break; 2037 case T_OBJECT: 2038 case T_ARRAY: 2039 case T_FLOAT: 2040 case T_INT: 2041 field_array[pos++] = get_const_type(type); 2042 break; 2043 case T_BOOLEAN: 2044 case T_CHAR: 2045 case T_BYTE: 2046 case T_SHORT: 2047 field_array[pos++] = TypeInt::INT; 2048 break; 2049 case T_VALUETYPE: { 2050 assert(type->is_valuetype(), "inconsistent type"); 2051 if (vt_fields_as_args && type != ciEnv::current()->___Value_klass()) { 2052 ciValueKlass* vk = (ciValueKlass*)type; 2053 collect_value_fields(vk, field_array, pos); 2054 } else { 2055 field_array[pos++] = get_const_type(type); 2056 } 2057 break; 2058 } 2059 default: 2060 ShouldNotReachHere(); 2061 } 2062 i++; 2063 } 2064 assert(pos == TypeFunc::Parms + arg_cnt + vt_extra, "wrong number of arguments"); 2065 2066 return (TypeTuple*)(new TypeTuple(TypeFunc::Parms + arg_cnt + vt_extra, field_array))->hashcons(); 2067 } 2068 2069 const TypeTuple *TypeTuple::make( uint cnt, const Type **fields ) { 2070 return (TypeTuple*)(new TypeTuple(cnt,fields))->hashcons(); 2071 } 2072 2073 //------------------------------fields----------------------------------------- 2074 // Subroutine call type with space allocated for argument types 2075 // Memory for Control, I_O, Memory, FramePtr, and ReturnAdr is allocated implicitly 2076 const Type **TypeTuple::fields( uint arg_cnt ) { 2077 const Type **flds = (const Type **)(Compile::current()->type_arena()->Amalloc_4((TypeFunc::Parms+arg_cnt)*sizeof(Type*) )); 2078 flds[TypeFunc::Control ] = Type::CONTROL; 2079 flds[TypeFunc::I_O ] = Type::ABIO; 2080 flds[TypeFunc::Memory ] = Type::MEMORY; 2081 flds[TypeFunc::FramePtr ] = TypeRawPtr::BOTTOM; 2082 flds[TypeFunc::ReturnAdr] = Type::RETURN_ADDRESS; 2083 2084 return flds; 2085 } 2086 2087 //------------------------------meet------------------------------------------- 2088 // Compute the MEET of two types. It returns a new Type object. 2089 const Type *TypeTuple::xmeet( const Type *t ) const { 2090 // Perform a fast test for common case; meeting the same types together. 2091 if( this == t ) return this; // Meeting same type-rep? 2092 2093 // Current "this->_base" is Tuple 2094 switch (t->base()) { // switch on original type 2095 2096 case Bottom: // Ye Olde Default 2097 return t; 2098 2099 default: // All else is a mistake 2100 typerr(t); 2101 2102 case Tuple: { // Meeting 2 signatures? 2103 const TypeTuple *x = t->is_tuple(); 2104 assert( _cnt == x->_cnt, "" ); 2105 const Type **fields = (const Type **)(Compile::current()->type_arena()->Amalloc_4( _cnt*sizeof(Type*) )); 2106 for( uint i=0; i<_cnt; i++ ) 2107 fields[i] = field_at(i)->xmeet( x->field_at(i) ); 2108 return TypeTuple::make(_cnt,fields); 2109 } 2110 case Top: 2111 break; 2112 } 2113 return this; // Return the double constant 2114 } 2115 2116 //------------------------------xdual------------------------------------------ 2117 // Dual: compute field-by-field dual 2118 const Type *TypeTuple::xdual() const { 2119 const Type **fields = (const Type **)(Compile::current()->type_arena()->Amalloc_4( _cnt*sizeof(Type*) )); 2120 for( uint i=0; i<_cnt; i++ ) 2121 fields[i] = _fields[i]->dual(); 2122 return new TypeTuple(_cnt,fields); 2123 } 2124 2125 //------------------------------eq--------------------------------------------- 2126 // Structural equality check for Type representations 2127 bool TypeTuple::eq( const Type *t ) const { 2128 const TypeTuple *s = (const TypeTuple *)t; 2129 if (_cnt != s->_cnt) return false; // Unequal field counts 2130 for (uint i = 0; i < _cnt; i++) 2131 if (field_at(i) != s->field_at(i)) // POINTER COMPARE! NO RECURSION! 2132 return false; // Missed 2133 return true; 2134 } 2135 2136 //------------------------------hash------------------------------------------- 2137 // Type-specific hashing function. 2138 int TypeTuple::hash(void) const { 2139 intptr_t sum = _cnt; 2140 for( uint i=0; i<_cnt; i++ ) 2141 sum += (intptr_t)_fields[i]; // Hash on pointers directly 2142 return sum; 2143 } 2144 2145 //------------------------------dump2------------------------------------------ 2146 // Dump signature Type 2147 #ifndef PRODUCT 2148 void TypeTuple::dump2( Dict &d, uint depth, outputStream *st ) const { 2149 st->print("{"); 2150 if( !depth || d[this] ) { // Check for recursive print 2151 st->print("...}"); 2152 return; 2153 } 2154 d.Insert((void*)this, (void*)this); // Stop recursion 2155 if( _cnt ) { 2156 uint i; 2157 for( i=0; i<_cnt-1; i++ ) { 2158 st->print("%d:", i); 2159 _fields[i]->dump2(d, depth-1, st); 2160 st->print(", "); 2161 } 2162 st->print("%d:", i); 2163 _fields[i]->dump2(d, depth-1, st); 2164 } 2165 st->print("}"); 2166 } 2167 #endif 2168 2169 //------------------------------singleton-------------------------------------- 2170 // TRUE if Type is a singleton type, FALSE otherwise. Singletons are simple 2171 // constants (Ldi nodes). Singletons are integer, float or double constants 2172 // or a single symbol. 2173 bool TypeTuple::singleton(void) const { 2174 return false; // Never a singleton 2175 } 2176 2177 bool TypeTuple::empty(void) const { 2178 for( uint i=0; i<_cnt; i++ ) { 2179 if (_fields[i]->empty()) return true; 2180 } 2181 return false; 2182 } 2183 2184 //============================================================================= 2185 // Convenience common pre-built types. 2186 2187 inline const TypeInt* normalize_array_size(const TypeInt* size) { 2188 // Certain normalizations keep us sane when comparing types. 2189 // We do not want arrayOop variables to differ only by the wideness 2190 // of their index types. Pick minimum wideness, since that is the 2191 // forced wideness of small ranges anyway. 2192 if (size->_widen != Type::WidenMin) 2193 return TypeInt::make(size->_lo, size->_hi, Type::WidenMin); 2194 else 2195 return size; 2196 } 2197 2198 //------------------------------make------------------------------------------- 2199 const TypeAry* TypeAry::make(const Type* elem, const TypeInt* size, bool stable) { 2200 if (UseCompressedOops && elem->isa_oopptr()) { 2201 elem = elem->make_narrowoop(); 2202 } 2203 size = normalize_array_size(size); 2204 return (TypeAry*)(new TypeAry(elem,size,stable))->hashcons(); 2205 } 2206 2207 //------------------------------meet------------------------------------------- 2208 // Compute the MEET of two types. It returns a new Type object. 2209 const Type *TypeAry::xmeet( const Type *t ) const { 2210 // Perform a fast test for common case; meeting the same types together. 2211 if( this == t ) return this; // Meeting same type-rep? 2212 2213 // Current "this->_base" is Ary 2214 switch (t->base()) { // switch on original type 2215 2216 case Bottom: // Ye Olde Default 2217 return t; 2218 2219 default: // All else is a mistake 2220 typerr(t); 2221 2222 case Array: { // Meeting 2 arrays? 2223 const TypeAry *a = t->is_ary(); 2224 return TypeAry::make(_elem->meet_speculative(a->_elem), 2225 _size->xmeet(a->_size)->is_int(), 2226 _stable & a->_stable); 2227 } 2228 case Top: 2229 break; 2230 } 2231 return this; // Return the double constant 2232 } 2233 2234 //------------------------------xdual------------------------------------------ 2235 // Dual: compute field-by-field dual 2236 const Type *TypeAry::xdual() const { 2237 const TypeInt* size_dual = _size->dual()->is_int(); 2238 size_dual = normalize_array_size(size_dual); 2239 return new TypeAry(_elem->dual(), size_dual, !_stable); 2240 } 2241 2242 //------------------------------eq--------------------------------------------- 2243 // Structural equality check for Type representations 2244 bool TypeAry::eq( const Type *t ) const { 2245 const TypeAry *a = (const TypeAry*)t; 2246 return _elem == a->_elem && 2247 _stable == a->_stable && 2248 _size == a->_size; 2249 } 2250 2251 //------------------------------hash------------------------------------------- 2252 // Type-specific hashing function. 2253 int TypeAry::hash(void) const { 2254 return (intptr_t)_elem + (intptr_t)_size + (_stable ? 43 : 0); 2255 } 2256 2257 /** 2258 * Return same type without a speculative part in the element 2259 */ 2260 const Type* TypeAry::remove_speculative() const { 2261 return make(_elem->remove_speculative(), _size, _stable); 2262 } 2263 2264 /** 2265 * Return same type with cleaned up speculative part of element 2266 */ 2267 const Type* TypeAry::cleanup_speculative() const { 2268 return make(_elem->cleanup_speculative(), _size, _stable); 2269 } 2270 2271 /** 2272 * Return same type but with a different inline depth (used for speculation) 2273 * 2274 * @param depth depth to meet with 2275 */ 2276 const TypePtr* TypePtr::with_inline_depth(int depth) const { 2277 if (!UseInlineDepthForSpeculativeTypes) { 2278 return this; 2279 } 2280 return make(AnyPtr, _ptr, _offset, _speculative, depth); 2281 } 2282 2283 //----------------------interface_vs_oop--------------------------------------- 2284 #ifdef ASSERT 2285 bool TypeAry::interface_vs_oop(const Type *t) const { 2286 const TypeAry* t_ary = t->is_ary(); 2287 if (t_ary) { 2288 const TypePtr* this_ptr = _elem->make_ptr(); // In case we have narrow_oops 2289 const TypePtr* t_ptr = t_ary->_elem->make_ptr(); 2290 if(this_ptr != NULL && t_ptr != NULL) { 2291 return this_ptr->interface_vs_oop(t_ptr); 2292 } 2293 } 2294 return false; 2295 } 2296 #endif 2297 2298 //------------------------------dump2------------------------------------------ 2299 #ifndef PRODUCT 2300 void TypeAry::dump2( Dict &d, uint depth, outputStream *st ) const { 2301 if (_stable) st->print("stable:"); 2302 _elem->dump2(d, depth, st); 2303 st->print("["); 2304 _size->dump2(d, depth, st); 2305 st->print("]"); 2306 } 2307 #endif 2308 2309 //------------------------------singleton-------------------------------------- 2310 // TRUE if Type is a singleton type, FALSE otherwise. Singletons are simple 2311 // constants (Ldi nodes). Singletons are integer, float or double constants 2312 // or a single symbol. 2313 bool TypeAry::singleton(void) const { 2314 return false; // Never a singleton 2315 } 2316 2317 bool TypeAry::empty(void) const { 2318 return _elem->empty() || _size->empty(); 2319 } 2320 2321 //--------------------------ary_must_be_exact---------------------------------- 2322 bool TypeAry::ary_must_be_exact() const { 2323 if (!UseExactTypes) return false; 2324 // This logic looks at the element type of an array, and returns true 2325 // if the element type is either a primitive or a final instance class. 2326 // In such cases, an array built on this ary must have no subclasses. 2327 if (_elem == BOTTOM) return false; // general array not exact 2328 if (_elem == TOP ) return false; // inverted general array not exact 2329 const TypeOopPtr* toop = NULL; 2330 if (UseCompressedOops && _elem->isa_narrowoop()) { 2331 toop = _elem->make_ptr()->isa_oopptr(); 2332 } else { 2333 toop = _elem->isa_oopptr(); 2334 } 2335 if (!toop) return true; // a primitive type, like int 2336 ciKlass* tklass = toop->klass(); 2337 if (tklass == NULL) return false; // unloaded class 2338 if (!tklass->is_loaded()) return false; // unloaded class 2339 const TypeInstPtr* tinst; 2340 if (_elem->isa_narrowoop()) 2341 tinst = _elem->make_ptr()->isa_instptr(); 2342 else 2343 tinst = _elem->isa_instptr(); 2344 if (tinst) 2345 return tklass->as_instance_klass()->is_final(); 2346 const TypeAryPtr* tap; 2347 if (_elem->isa_narrowoop()) 2348 tap = _elem->make_ptr()->isa_aryptr(); 2349 else 2350 tap = _elem->isa_aryptr(); 2351 if (tap) 2352 return tap->ary()->ary_must_be_exact(); 2353 return false; 2354 } 2355 2356 //==============================TypeValueType======================================= 2357 2358 //------------------------------make------------------------------------------- 2359 const TypeValueType* TypeValueType::make(ciValueKlass* vk) { 2360 return (TypeValueType*)(new TypeValueType(vk))->hashcons(); 2361 } 2362 2363 //------------------------------meet------------------------------------------- 2364 // Compute the MEET of two types. It returns a new Type object. 2365 const Type* TypeValueType::xmeet(const Type* t) const { 2366 // Perform a fast test for common case; meeting the same types together. 2367 if(this == t) return this; // Meeting same type-rep? 2368 2369 // Current "this->_base" is ValueType 2370 switch (t->base()) { // switch on original type 2371 2372 case Top: 2373 break; 2374 2375 case Bottom: 2376 return t; 2377 2378 default: // All else is a mistake 2379 typerr(t); 2380 2381 } 2382 return this; 2383 } 2384 2385 //------------------------------xdual------------------------------------------ 2386 const Type* TypeValueType::xdual() const { 2387 // FIXME 2388 return new TypeValueType(_vk); 2389 } 2390 2391 //------------------------------eq--------------------------------------------- 2392 // Structural equality check for Type representations 2393 bool TypeValueType::eq(const Type* t) const { 2394 const TypeValueType* vt = t->is_valuetype(); 2395 return (_vk == vt->value_klass()); 2396 } 2397 2398 //------------------------------hash------------------------------------------- 2399 // Type-specific hashing function. 2400 int TypeValueType::hash(void) const { 2401 return (intptr_t)_vk; 2402 } 2403 2404 //------------------------------singleton-------------------------------------- 2405 // TRUE if Type is a singleton type, FALSE otherwise. Singletons are simple constants. 2406 bool TypeValueType::singleton(void) const { 2407 // FIXME 2408 return false; 2409 } 2410 2411 //------------------------------empty------------------------------------------ 2412 // TRUE if Type is a type with no values, FALSE otherwise. 2413 bool TypeValueType::empty(void) const { 2414 // FIXME 2415 return false; 2416 } 2417 2418 //------------------------------dump2------------------------------------------ 2419 #ifndef PRODUCT 2420 void TypeValueType::dump2(Dict &d, uint depth, outputStream* st) const { 2421 st->print("valuetype[%d]:{", _vk->field_count()); 2422 st->print("%s", _vk->field_count() != 0 ? _vk->field_type_by_index(0)->name() : "empty"); 2423 for (int i = 1; i < _vk->field_count(); ++i) { 2424 st->print(", %s", _vk->field_type_by_index(i)->name()); 2425 } 2426 st->print("}"); 2427 } 2428 #endif 2429 2430 //==============================TypeVect======================================= 2431 // Convenience common pre-built types. 2432 const TypeVect *TypeVect::VECTS = NULL; // 32-bit vectors 2433 const TypeVect *TypeVect::VECTD = NULL; // 64-bit vectors 2434 const TypeVect *TypeVect::VECTX = NULL; // 128-bit vectors 2435 const TypeVect *TypeVect::VECTY = NULL; // 256-bit vectors 2436 const TypeVect *TypeVect::VECTZ = NULL; // 512-bit vectors 2437 2438 //------------------------------make------------------------------------------- 2439 const TypeVect* TypeVect::make(const Type *elem, uint length) { 2440 BasicType elem_bt = elem->array_element_basic_type(); 2441 assert(is_java_primitive(elem_bt), "only primitive types in vector"); 2442 assert(length > 1 && is_power_of_2(length), "vector length is power of 2"); 2443 assert(Matcher::vector_size_supported(elem_bt, length), "length in range"); 2444 int size = length * type2aelembytes(elem_bt); 2445 switch (Matcher::vector_ideal_reg(size)) { 2446 case Op_VecS: 2447 return (TypeVect*)(new TypeVectS(elem, length))->hashcons(); 2448 case Op_RegL: 2449 case Op_VecD: 2450 case Op_RegD: 2451 return (TypeVect*)(new TypeVectD(elem, length))->hashcons(); 2452 case Op_VecX: 2453 return (TypeVect*)(new TypeVectX(elem, length))->hashcons(); 2454 case Op_VecY: 2455 return (TypeVect*)(new TypeVectY(elem, length))->hashcons(); 2456 case Op_VecZ: 2457 return (TypeVect*)(new TypeVectZ(elem, length))->hashcons(); 2458 } 2459 ShouldNotReachHere(); 2460 return NULL; 2461 } 2462 2463 //------------------------------meet------------------------------------------- 2464 // Compute the MEET of two types. It returns a new Type object. 2465 const Type *TypeVect::xmeet( const Type *t ) const { 2466 // Perform a fast test for common case; meeting the same types together. 2467 if( this == t ) return this; // Meeting same type-rep? 2468 2469 // Current "this->_base" is Vector 2470 switch (t->base()) { // switch on original type 2471 2472 case Bottom: // Ye Olde Default 2473 return t; 2474 2475 default: // All else is a mistake 2476 typerr(t); 2477 2478 case VectorS: 2479 case VectorD: 2480 case VectorX: 2481 case VectorY: 2482 case VectorZ: { // Meeting 2 vectors? 2483 const TypeVect* v = t->is_vect(); 2484 assert( base() == v->base(), ""); 2485 assert(length() == v->length(), ""); 2486 assert(element_basic_type() == v->element_basic_type(), ""); 2487 return TypeVect::make(_elem->xmeet(v->_elem), _length); 2488 } 2489 case Top: 2490 break; 2491 } 2492 return this; 2493 } 2494 2495 //------------------------------xdual------------------------------------------ 2496 // Dual: compute field-by-field dual 2497 const Type *TypeVect::xdual() const { 2498 return new TypeVect(base(), _elem->dual(), _length); 2499 } 2500 2501 //------------------------------eq--------------------------------------------- 2502 // Structural equality check for Type representations 2503 bool TypeVect::eq(const Type *t) const { 2504 const TypeVect *v = t->is_vect(); 2505 return (_elem == v->_elem) && (_length == v->_length); 2506 } 2507 2508 //------------------------------hash------------------------------------------- 2509 // Type-specific hashing function. 2510 int TypeVect::hash(void) const { 2511 return (intptr_t)_elem + (intptr_t)_length; 2512 } 2513 2514 //------------------------------singleton-------------------------------------- 2515 // TRUE if Type is a singleton type, FALSE otherwise. Singletons are simple 2516 // constants (Ldi nodes). Vector is singleton if all elements are the same 2517 // constant value (when vector is created with Replicate code). 2518 bool TypeVect::singleton(void) const { 2519 // There is no Con node for vectors yet. 2520 // return _elem->singleton(); 2521 return false; 2522 } 2523 2524 bool TypeVect::empty(void) const { 2525 return _elem->empty(); 2526 } 2527 2528 //------------------------------dump2------------------------------------------ 2529 #ifndef PRODUCT 2530 void TypeVect::dump2(Dict &d, uint depth, outputStream *st) const { 2531 switch (base()) { 2532 case VectorS: 2533 st->print("vectors["); break; 2534 case VectorD: 2535 st->print("vectord["); break; 2536 case VectorX: 2537 st->print("vectorx["); break; 2538 case VectorY: 2539 st->print("vectory["); break; 2540 case VectorZ: 2541 st->print("vectorz["); break; 2542 default: 2543 ShouldNotReachHere(); 2544 } 2545 st->print("%d]:{", _length); 2546 _elem->dump2(d, depth, st); 2547 st->print("}"); 2548 } 2549 #endif 2550 2551 2552 //============================================================================= 2553 // Convenience common pre-built types. 2554 const TypePtr *TypePtr::NULL_PTR; 2555 const TypePtr *TypePtr::NOTNULL; 2556 const TypePtr *TypePtr::BOTTOM; 2557 2558 //------------------------------meet------------------------------------------- 2559 // Meet over the PTR enum 2560 const TypePtr::PTR TypePtr::ptr_meet[TypePtr::lastPTR][TypePtr::lastPTR] = { 2561 // TopPTR, AnyNull, Constant, Null, NotNull, BotPTR, 2562 { /* Top */ TopPTR, AnyNull, Constant, Null, NotNull, BotPTR,}, 2563 { /* AnyNull */ AnyNull, AnyNull, Constant, BotPTR, NotNull, BotPTR,}, 2564 { /* Constant*/ Constant, Constant, Constant, BotPTR, NotNull, BotPTR,}, 2565 { /* Null */ Null, BotPTR, BotPTR, Null, BotPTR, BotPTR,}, 2566 { /* NotNull */ NotNull, NotNull, NotNull, BotPTR, NotNull, BotPTR,}, 2567 { /* BotPTR */ BotPTR, BotPTR, BotPTR, BotPTR, BotPTR, BotPTR,} 2568 }; 2569 2570 //------------------------------make------------------------------------------- 2571 const TypePtr* TypePtr::make(TYPES t, enum PTR ptr, Offset offset, const TypePtr* speculative, int inline_depth) { 2572 return (TypePtr*)(new TypePtr(t,ptr,offset, speculative, inline_depth))->hashcons(); 2573 } 2574 2575 //------------------------------cast_to_ptr_type------------------------------- 2576 const Type *TypePtr::cast_to_ptr_type(PTR ptr) const { 2577 assert(_base == AnyPtr, "subclass must override cast_to_ptr_type"); 2578 if( ptr == _ptr ) return this; 2579 return make(_base, ptr, _offset, _speculative, _inline_depth); 2580 } 2581 2582 //------------------------------get_con---------------------------------------- 2583 intptr_t TypePtr::get_con() const { 2584 assert( _ptr == Null, "" ); 2585 return offset(); 2586 } 2587 2588 //------------------------------meet------------------------------------------- 2589 // Compute the MEET of two types. It returns a new Type object. 2590 const Type *TypePtr::xmeet(const Type *t) const { 2591 const Type* res = xmeet_helper(t); 2592 if (res->isa_ptr() == NULL) { 2593 return res; 2594 } 2595 2596 const TypePtr* res_ptr = res->is_ptr(); 2597 if (res_ptr->speculative() != NULL) { 2598 // type->speculative() == NULL means that speculation is no better 2599 // than type, i.e. type->speculative() == type. So there are 2 2600 // ways to represent the fact that we have no useful speculative 2601 // data and we should use a single one to be able to test for 2602 // equality between types. Check whether type->speculative() == 2603 // type and set speculative to NULL if it is the case. 2604 if (res_ptr->remove_speculative() == res_ptr->speculative()) { 2605 return res_ptr->remove_speculative(); 2606 } 2607 } 2608 2609 return res; 2610 } 2611 2612 const Type *TypePtr::xmeet_helper(const Type *t) const { 2613 // Perform a fast test for common case; meeting the same types together. 2614 if( this == t ) return this; // Meeting same type-rep? 2615 2616 // Current "this->_base" is AnyPtr 2617 switch (t->base()) { // switch on original type 2618 case Int: // Mixing ints & oops happens when javac 2619 case Long: // reuses local variables 2620 case FloatTop: 2621 case FloatCon: 2622 case FloatBot: 2623 case DoubleTop: 2624 case DoubleCon: 2625 case DoubleBot: 2626 case NarrowOop: 2627 case NarrowKlass: 2628 case Bottom: // Ye Olde Default 2629 return Type::BOTTOM; 2630 case Top: 2631 return this; 2632 2633 case AnyPtr: { // Meeting to AnyPtrs 2634 const TypePtr *tp = t->is_ptr(); 2635 const TypePtr* speculative = xmeet_speculative(tp); 2636 int depth = meet_inline_depth(tp->inline_depth()); 2637 return make(AnyPtr, meet_ptr(tp->ptr()), meet_offset(tp->offset()), speculative, depth); 2638 } 2639 case RawPtr: // For these, flip the call around to cut down 2640 case OopPtr: 2641 case InstPtr: // on the cases I have to handle. 2642 case ValueTypePtr: 2643 case AryPtr: 2644 case MetadataPtr: 2645 case KlassPtr: 2646 return t->xmeet(this); // Call in reverse direction 2647 default: // All else is a mistake 2648 typerr(t); 2649 2650 } 2651 return this; 2652 } 2653 2654 //------------------------------meet_offset------------------------------------ 2655 Type::Offset TypePtr::meet_offset(int offset) const { 2656 return _offset.meet(Offset(offset)); 2657 } 2658 2659 //------------------------------dual_offset------------------------------------ 2660 Type::Offset TypePtr::dual_offset() const { 2661 return _offset.dual(); 2662 } 2663 2664 //------------------------------xdual------------------------------------------ 2665 // Dual: compute field-by-field dual 2666 const TypePtr::PTR TypePtr::ptr_dual[TypePtr::lastPTR] = { 2667 BotPTR, NotNull, Constant, Null, AnyNull, TopPTR 2668 }; 2669 const Type *TypePtr::xdual() const { 2670 return new TypePtr(AnyPtr, dual_ptr(), dual_offset(), dual_speculative(), dual_inline_depth()); 2671 } 2672 2673 //------------------------------xadd_offset------------------------------------ 2674 Type::Offset TypePtr::xadd_offset(intptr_t offset) const { 2675 return _offset.add(offset); 2676 } 2677 2678 //------------------------------add_offset------------------------------------- 2679 const TypePtr *TypePtr::add_offset( intptr_t offset ) const { 2680 return make(AnyPtr, _ptr, xadd_offset(offset), _speculative, _inline_depth); 2681 } 2682 2683 //------------------------------eq--------------------------------------------- 2684 // Structural equality check for Type representations 2685 bool TypePtr::eq( const Type *t ) const { 2686 const TypePtr *a = (const TypePtr*)t; 2687 return _ptr == a->ptr() && _offset == a->_offset && eq_speculative(a) && _inline_depth == a->_inline_depth; 2688 } 2689 2690 //------------------------------hash------------------------------------------- 2691 // Type-specific hashing function. 2692 int TypePtr::hash(void) const { 2693 return java_add(java_add(_ptr, offset()), java_add( hash_speculative(), _inline_depth)); 2694 ; 2695 } 2696 2697 /** 2698 * Return same type without a speculative part 2699 */ 2700 const Type* TypePtr::remove_speculative() const { 2701 if (_speculative == NULL) { 2702 return this; 2703 } 2704 assert(_inline_depth == InlineDepthTop || _inline_depth == InlineDepthBottom, "non speculative type shouldn't have inline depth"); 2705 return make(AnyPtr, _ptr, _offset, NULL, _inline_depth); 2706 } 2707 2708 /** 2709 * Return same type but drop speculative part if we know we won't use 2710 * it 2711 */ 2712 const Type* TypePtr::cleanup_speculative() const { 2713 if (speculative() == NULL) { 2714 return this; 2715 } 2716 const Type* no_spec = remove_speculative(); 2717 // If this is NULL_PTR then we don't need the speculative type 2718 // (with_inline_depth in case the current type inline depth is 2719 // InlineDepthTop) 2720 if (no_spec == NULL_PTR->with_inline_depth(inline_depth())) { 2721 return no_spec; 2722 } 2723 if (above_centerline(speculative()->ptr())) { 2724 return no_spec; 2725 } 2726 const TypeOopPtr* spec_oopptr = speculative()->isa_oopptr(); 2727 // If the speculative may be null and is an inexact klass then it 2728 // doesn't help 2729 if (speculative()->maybe_null() && (spec_oopptr == NULL || !spec_oopptr->klass_is_exact())) { 2730 return no_spec; 2731 } 2732 return this; 2733 } 2734 2735 /** 2736 * dual of the speculative part of the type 2737 */ 2738 const TypePtr* TypePtr::dual_speculative() const { 2739 if (_speculative == NULL) { 2740 return NULL; 2741 } 2742 return _speculative->dual()->is_ptr(); 2743 } 2744 2745 /** 2746 * meet of the speculative parts of 2 types 2747 * 2748 * @param other type to meet with 2749 */ 2750 const TypePtr* TypePtr::xmeet_speculative(const TypePtr* other) const { 2751 bool this_has_spec = (_speculative != NULL); 2752 bool other_has_spec = (other->speculative() != NULL); 2753 2754 if (!this_has_spec && !other_has_spec) { 2755 return NULL; 2756 } 2757 2758 // If we are at a point where control flow meets and one branch has 2759 // a speculative type and the other has not, we meet the speculative 2760 // type of one branch with the actual type of the other. If the 2761 // actual type is exact and the speculative is as well, then the 2762 // result is a speculative type which is exact and we can continue 2763 // speculation further. 2764 const TypePtr* this_spec = _speculative; 2765 const TypePtr* other_spec = other->speculative(); 2766 2767 if (!this_has_spec) { 2768 this_spec = this; 2769 } 2770 2771 if (!other_has_spec) { 2772 other_spec = other; 2773 } 2774 2775 return this_spec->meet(other_spec)->is_ptr(); 2776 } 2777 2778 /** 2779 * dual of the inline depth for this type (used for speculation) 2780 */ 2781 int TypePtr::dual_inline_depth() const { 2782 return -inline_depth(); 2783 } 2784 2785 /** 2786 * meet of 2 inline depths (used for speculation) 2787 * 2788 * @param depth depth to meet with 2789 */ 2790 int TypePtr::meet_inline_depth(int depth) const { 2791 return MAX2(inline_depth(), depth); 2792 } 2793 2794 /** 2795 * Are the speculative parts of 2 types equal? 2796 * 2797 * @param other type to compare this one to 2798 */ 2799 bool TypePtr::eq_speculative(const TypePtr* other) const { 2800 if (_speculative == NULL || other->speculative() == NULL) { 2801 return _speculative == other->speculative(); 2802 } 2803 2804 if (_speculative->base() != other->speculative()->base()) { 2805 return false; 2806 } 2807 2808 return _speculative->eq(other->speculative()); 2809 } 2810 2811 /** 2812 * Hash of the speculative part of the type 2813 */ 2814 int TypePtr::hash_speculative() const { 2815 if (_speculative == NULL) { 2816 return 0; 2817 } 2818 2819 return _speculative->hash(); 2820 } 2821 2822 /** 2823 * add offset to the speculative part of the type 2824 * 2825 * @param offset offset to add 2826 */ 2827 const TypePtr* TypePtr::add_offset_speculative(intptr_t offset) const { 2828 if (_speculative == NULL) { 2829 return NULL; 2830 } 2831 return _speculative->add_offset(offset)->is_ptr(); 2832 } 2833 2834 /** 2835 * return exact klass from the speculative type if there's one 2836 */ 2837 ciKlass* TypePtr::speculative_type() const { 2838 if (_speculative != NULL && _speculative->isa_oopptr()) { 2839 const TypeOopPtr* speculative = _speculative->join(this)->is_oopptr(); 2840 if (speculative->klass_is_exact()) { 2841 return speculative->klass(); 2842 } 2843 } 2844 return NULL; 2845 } 2846 2847 /** 2848 * return true if speculative type may be null 2849 */ 2850 bool TypePtr::speculative_maybe_null() const { 2851 if (_speculative != NULL) { 2852 const TypePtr* speculative = _speculative->join(this)->is_ptr(); 2853 return speculative->maybe_null(); 2854 } 2855 return true; 2856 } 2857 2858 /** 2859 * Same as TypePtr::speculative_type() but return the klass only if 2860 * the speculative tells us is not null 2861 */ 2862 ciKlass* TypePtr::speculative_type_not_null() const { 2863 if (speculative_maybe_null()) { 2864 return NULL; 2865 } 2866 return speculative_type(); 2867 } 2868 2869 /** 2870 * Check whether new profiling would improve speculative type 2871 * 2872 * @param exact_kls class from profiling 2873 * @param inline_depth inlining depth of profile point 2874 * 2875 * @return true if type profile is valuable 2876 */ 2877 bool TypePtr::would_improve_type(ciKlass* exact_kls, int inline_depth) const { 2878 // no profiling? 2879 if (exact_kls == NULL) { 2880 return false; 2881 } 2882 // no speculative type or non exact speculative type? 2883 if (speculative_type() == NULL) { 2884 return true; 2885 } 2886 // If the node already has an exact speculative type keep it, 2887 // unless it was provided by profiling that is at a deeper 2888 // inlining level. Profiling at a higher inlining depth is 2889 // expected to be less accurate. 2890 if (_speculative->inline_depth() == InlineDepthBottom) { 2891 return false; 2892 } 2893 assert(_speculative->inline_depth() != InlineDepthTop, "can't do the comparison"); 2894 return inline_depth < _speculative->inline_depth(); 2895 } 2896 2897 /** 2898 * Check whether new profiling would improve ptr (= tells us it is non 2899 * null) 2900 * 2901 * @param maybe_null true if profiling tells the ptr may be null 2902 * 2903 * @return true if ptr profile is valuable 2904 */ 2905 bool TypePtr::would_improve_ptr(bool maybe_null) const { 2906 // profiling doesn't tell us anything useful 2907 if (maybe_null) { 2908 return false; 2909 } 2910 // We already know this is not be null 2911 if (!this->maybe_null()) { 2912 return false; 2913 } 2914 // We already know the speculative type cannot be null 2915 if (!speculative_maybe_null()) { 2916 return false; 2917 } 2918 return true; 2919 } 2920 2921 //------------------------------dump2------------------------------------------ 2922 const char *const TypePtr::ptr_msg[TypePtr::lastPTR] = { 2923 "TopPTR","AnyNull","Constant","NULL","NotNull","BotPTR" 2924 }; 2925 2926 #ifndef PRODUCT 2927 void TypePtr::dump2( Dict &d, uint depth, outputStream *st ) const { 2928 if( _ptr == Null ) st->print("NULL"); 2929 else st->print("%s *", ptr_msg[_ptr]); 2930 _offset.dump2(st); 2931 dump_inline_depth(st); 2932 dump_speculative(st); 2933 } 2934 2935 /** 2936 *dump the speculative part of the type 2937 */ 2938 void TypePtr::dump_speculative(outputStream *st) const { 2939 if (_speculative != NULL) { 2940 st->print(" (speculative="); 2941 _speculative->dump_on(st); 2942 st->print(")"); 2943 } 2944 } 2945 2946 /** 2947 *dump the inline depth of the type 2948 */ 2949 void TypePtr::dump_inline_depth(outputStream *st) const { 2950 if (_inline_depth != InlineDepthBottom) { 2951 if (_inline_depth == InlineDepthTop) { 2952 st->print(" (inline_depth=InlineDepthTop)"); 2953 } else { 2954 st->print(" (inline_depth=%d)", _inline_depth); 2955 } 2956 } 2957 } 2958 #endif 2959 2960 //------------------------------singleton-------------------------------------- 2961 // TRUE if Type is a singleton type, FALSE otherwise. Singletons are simple 2962 // constants 2963 bool TypePtr::singleton(void) const { 2964 // TopPTR, Null, AnyNull, Constant are all singletons 2965 return (_offset != Offset::bottom) && !below_centerline(_ptr); 2966 } 2967 2968 bool TypePtr::empty(void) const { 2969 return (_offset == Offset::top) || above_centerline(_ptr); 2970 } 2971 2972 //============================================================================= 2973 // Convenience common pre-built types. 2974 const TypeRawPtr *TypeRawPtr::BOTTOM; 2975 const TypeRawPtr *TypeRawPtr::NOTNULL; 2976 2977 //------------------------------make------------------------------------------- 2978 const TypeRawPtr *TypeRawPtr::make( enum PTR ptr ) { 2979 assert( ptr != Constant, "what is the constant?" ); 2980 assert( ptr != Null, "Use TypePtr for NULL" ); 2981 return (TypeRawPtr*)(new TypeRawPtr(ptr,0))->hashcons(); 2982 } 2983 2984 const TypeRawPtr *TypeRawPtr::make( address bits ) { 2985 assert( bits, "Use TypePtr for NULL" ); 2986 return (TypeRawPtr*)(new TypeRawPtr(Constant,bits))->hashcons(); 2987 } 2988 2989 //------------------------------cast_to_ptr_type------------------------------- 2990 const Type *TypeRawPtr::cast_to_ptr_type(PTR ptr) const { 2991 assert( ptr != Constant, "what is the constant?" ); 2992 assert( ptr != Null, "Use TypePtr for NULL" ); 2993 assert( _bits==0, "Why cast a constant address?"); 2994 if( ptr == _ptr ) return this; 2995 return make(ptr); 2996 } 2997 2998 //------------------------------get_con---------------------------------------- 2999 intptr_t TypeRawPtr::get_con() const { 3000 assert( _ptr == Null || _ptr == Constant, "" ); 3001 return (intptr_t)_bits; 3002 } 3003 3004 //------------------------------meet------------------------------------------- 3005 // Compute the MEET of two types. It returns a new Type object. 3006 const Type *TypeRawPtr::xmeet( const Type *t ) const { 3007 // Perform a fast test for common case; meeting the same types together. 3008 if( this == t ) return this; // Meeting same type-rep? 3009 3010 // Current "this->_base" is RawPtr 3011 switch( t->base() ) { // switch on original type 3012 case Bottom: // Ye Olde Default 3013 return t; 3014 case Top: 3015 return this; 3016 case AnyPtr: // Meeting to AnyPtrs 3017 break; 3018 case RawPtr: { // might be top, bot, any/not or constant 3019 enum PTR tptr = t->is_ptr()->ptr(); 3020 enum PTR ptr = meet_ptr( tptr ); 3021 if( ptr == Constant ) { // Cannot be equal constants, so... 3022 if( tptr == Constant && _ptr != Constant) return t; 3023 if( _ptr == Constant && tptr != Constant) return this; 3024 ptr = NotNull; // Fall down in lattice 3025 } 3026 return make( ptr ); 3027 } 3028 3029 case OopPtr: 3030 case InstPtr: 3031 case ValueTypePtr: 3032 case AryPtr: 3033 case MetadataPtr: 3034 case KlassPtr: 3035 return TypePtr::BOTTOM; // Oop meet raw is not well defined 3036 default: // All else is a mistake 3037 typerr(t); 3038 } 3039 3040 // Found an AnyPtr type vs self-RawPtr type 3041 const TypePtr *tp = t->is_ptr(); 3042 switch (tp->ptr()) { 3043 case TypePtr::TopPTR: return this; 3044 case TypePtr::BotPTR: return t; 3045 case TypePtr::Null: 3046 if( _ptr == TypePtr::TopPTR ) return t; 3047 return TypeRawPtr::BOTTOM; 3048 case TypePtr::NotNull: return TypePtr::make(AnyPtr, meet_ptr(TypePtr::NotNull), tp->meet_offset(0), tp->speculative(), tp->inline_depth()); 3049 case TypePtr::AnyNull: 3050 if( _ptr == TypePtr::Constant) return this; 3051 return make( meet_ptr(TypePtr::AnyNull) ); 3052 default: ShouldNotReachHere(); 3053 } 3054 return this; 3055 } 3056 3057 //------------------------------xdual------------------------------------------ 3058 // Dual: compute field-by-field dual 3059 const Type *TypeRawPtr::xdual() const { 3060 return new TypeRawPtr( dual_ptr(), _bits ); 3061 } 3062 3063 //------------------------------add_offset------------------------------------- 3064 const TypePtr *TypeRawPtr::add_offset( intptr_t offset ) const { 3065 if( offset == OffsetTop ) return BOTTOM; // Undefined offset-> undefined pointer 3066 if( offset == OffsetBot ) return BOTTOM; // Unknown offset-> unknown pointer 3067 if( offset == 0 ) return this; // No change 3068 switch (_ptr) { 3069 case TypePtr::TopPTR: 3070 case TypePtr::BotPTR: 3071 case TypePtr::NotNull: 3072 return this; 3073 case TypePtr::Null: 3074 case TypePtr::Constant: { 3075 address bits = _bits+offset; 3076 if ( bits == 0 ) return TypePtr::NULL_PTR; 3077 return make( bits ); 3078 } 3079 default: ShouldNotReachHere(); 3080 } 3081 return NULL; // Lint noise 3082 } 3083 3084 //------------------------------eq--------------------------------------------- 3085 // Structural equality check for Type representations 3086 bool TypeRawPtr::eq( const Type *t ) const { 3087 const TypeRawPtr *a = (const TypeRawPtr*)t; 3088 return _bits == a->_bits && TypePtr::eq(t); 3089 } 3090 3091 //------------------------------hash------------------------------------------- 3092 // Type-specific hashing function. 3093 int TypeRawPtr::hash(void) const { 3094 return (intptr_t)_bits + TypePtr::hash(); 3095 } 3096 3097 //------------------------------dump2------------------------------------------ 3098 #ifndef PRODUCT 3099 void TypeRawPtr::dump2( Dict &d, uint depth, outputStream *st ) const { 3100 if( _ptr == Constant ) 3101 st->print(INTPTR_FORMAT, p2i(_bits)); 3102 else 3103 st->print("rawptr:%s", ptr_msg[_ptr]); 3104 } 3105 #endif 3106 3107 //============================================================================= 3108 // Convenience common pre-built type. 3109 const TypeOopPtr *TypeOopPtr::BOTTOM; 3110 3111 //------------------------------TypeOopPtr------------------------------------- 3112 TypeOopPtr::TypeOopPtr(TYPES t, PTR ptr, ciKlass* k, bool xk, ciObject* o, Offset offset, Offset field_offset, 3113 int instance_id, const TypePtr* speculative, int inline_depth) 3114 : TypePtr(t, ptr, offset, speculative, inline_depth), 3115 _const_oop(o), _klass(k), 3116 _klass_is_exact(xk), 3117 _is_ptr_to_narrowoop(false), 3118 _is_ptr_to_narrowklass(false), 3119 _is_ptr_to_boxed_value(false), 3120 _instance_id(instance_id) { 3121 if (Compile::current()->eliminate_boxing() && (t == InstPtr) && 3122 (offset.get() > 0) && xk && (k != 0) && k->is_instance_klass()) { 3123 _is_ptr_to_boxed_value = k->as_instance_klass()->is_boxed_value_offset(offset.get()); 3124 } 3125 #ifdef _LP64 3126 if (this->offset() != 0) { 3127 if (this->offset() == oopDesc::klass_offset_in_bytes()) { 3128 _is_ptr_to_narrowklass = UseCompressedClassPointers; 3129 } else if (klass() == NULL) { 3130 // Array with unknown body type 3131 assert(this->isa_aryptr(), "only arrays without klass"); 3132 _is_ptr_to_narrowoop = UseCompressedOops; 3133 } else if (UseCompressedOops && this->isa_aryptr() && this->offset() != arrayOopDesc::length_offset_in_bytes()) { 3134 if (klass()->is_obj_array_klass()) { 3135 _is_ptr_to_narrowoop = true; 3136 } else if (klass()->is_value_array_klass() && field_offset != Offset::top && field_offset != Offset::bottom) { 3137 // Check if the field of the value type array element contains oops 3138 ciValueKlass* vk = klass()->as_value_array_klass()->element_klass()->as_value_klass(); 3139 int foffset = field_offset.get() + vk->first_field_offset(); 3140 ciField* field = vk->get_field_by_offset(foffset, false); 3141 assert(field != NULL, "missing field"); 3142 BasicType bt = field->layout_type(); 3143 assert(bt != T_VALUETYPE, "should be flattened"); 3144 _is_ptr_to_narrowoop = (bt == T_OBJECT || bt == T_ARRAY); 3145 } 3146 } else if (klass()->is_instance_klass()) { 3147 ciInstanceKlass* ik = klass()->as_instance_klass(); 3148 ciField* field = NULL; 3149 if (this->isa_klassptr()) { 3150 // Perm objects don't use compressed references 3151 } else if (_offset == Offset::bottom || _offset == Offset::top) { 3152 // unsafe access 3153 _is_ptr_to_narrowoop = UseCompressedOops; 3154 } else { // exclude unsafe ops 3155 assert(this->isa_instptr() || this->isa_valuetypeptr(), "must be an instance ptr."); 3156 3157 if (klass() == ciEnv::current()->Class_klass() && 3158 (this->offset() == java_lang_Class::klass_offset_in_bytes() || 3159 this->offset() == java_lang_Class::array_klass_offset_in_bytes())) { 3160 // Special hidden fields from the Class. 3161 assert(this->isa_instptr(), "must be an instance ptr."); 3162 _is_ptr_to_narrowoop = false; 3163 } else if (klass() == ciEnv::current()->Class_klass() && 3164 this->offset() >= InstanceMirrorKlass::offset_of_static_fields()) { 3165 // Static fields 3166 assert(o != NULL, "must be constant"); 3167 ciInstanceKlass* k = o->as_instance()->java_lang_Class_klass()->as_instance_klass(); 3168 ciField* field = k->get_field_by_offset(this->offset(), true); 3169 assert(field != NULL, "missing field"); 3170 BasicType basic_elem_type = field->layout_type(); 3171 _is_ptr_to_narrowoop = UseCompressedOops && (basic_elem_type == T_OBJECT || 3172 basic_elem_type == T_ARRAY); 3173 } else { 3174 // Instance fields which contains a compressed oop references. 3175 field = ik->get_field_by_offset(this->offset(), false); 3176 if (field != NULL) { 3177 BasicType basic_elem_type = field->layout_type(); 3178 _is_ptr_to_narrowoop = UseCompressedOops && (basic_elem_type == T_OBJECT || 3179 basic_elem_type == T_ARRAY); 3180 } else if (klass()->equals(ciEnv::current()->Object_klass())) { 3181 // Compile::find_alias_type() cast exactness on all types to verify 3182 // that it does not affect alias type. 3183 _is_ptr_to_narrowoop = UseCompressedOops; 3184 } else { 3185 // Type for the copy start in LibraryCallKit::inline_native_clone(). 3186 _is_ptr_to_narrowoop = UseCompressedOops; 3187 } 3188 } 3189 } 3190 } 3191 } 3192 #endif 3193 } 3194 3195 //------------------------------make------------------------------------------- 3196 const TypeOopPtr *TypeOopPtr::make(PTR ptr, Offset offset, int instance_id, 3197 const TypePtr* speculative, int inline_depth) { 3198 assert(ptr != Constant, "no constant generic pointers"); 3199 ciKlass* k = Compile::current()->env()->Object_klass(); 3200 bool xk = false; 3201 ciObject* o = NULL; 3202 return (TypeOopPtr*)(new TypeOopPtr(OopPtr, ptr, k, xk, o, offset, Offset::bottom, instance_id, speculative, inline_depth))->hashcons(); 3203 } 3204 3205 3206 //------------------------------cast_to_ptr_type------------------------------- 3207 const Type *TypeOopPtr::cast_to_ptr_type(PTR ptr) const { 3208 assert(_base == OopPtr, "subclass must override cast_to_ptr_type"); 3209 if( ptr == _ptr ) return this; 3210 return make(ptr, _offset, _instance_id, _speculative, _inline_depth); 3211 } 3212 3213 //-----------------------------cast_to_instance_id---------------------------- 3214 const TypeOopPtr *TypeOopPtr::cast_to_instance_id(int instance_id) const { 3215 // There are no instances of a general oop. 3216 // Return self unchanged. 3217 return this; 3218 } 3219 3220 //-----------------------------cast_to_exactness------------------------------- 3221 const Type *TypeOopPtr::cast_to_exactness(bool klass_is_exact) const { 3222 // There is no such thing as an exact general oop. 3223 // Return self unchanged. 3224 return this; 3225 } 3226 3227 3228 //------------------------------as_klass_type---------------------------------- 3229 // Return the klass type corresponding to this instance or array type. 3230 // It is the type that is loaded from an object of this type. 3231 const TypeKlassPtr* TypeOopPtr::as_klass_type() const { 3232 ciKlass* k = klass(); 3233 bool xk = klass_is_exact(); 3234 if (k == NULL) 3235 return TypeKlassPtr::OBJECT; 3236 else 3237 return TypeKlassPtr::make(xk? Constant: NotNull, k, Offset(0)); 3238 } 3239 3240 //------------------------------meet------------------------------------------- 3241 // Compute the MEET of two types. It returns a new Type object. 3242 const Type *TypeOopPtr::xmeet_helper(const Type *t) const { 3243 // Perform a fast test for common case; meeting the same types together. 3244 if( this == t ) return this; // Meeting same type-rep? 3245 3246 // Current "this->_base" is OopPtr 3247 switch (t->base()) { // switch on original type 3248 3249 case Int: // Mixing ints & oops happens when javac 3250 case Long: // reuses local variables 3251 case FloatTop: 3252 case FloatCon: 3253 case FloatBot: 3254 case DoubleTop: 3255 case DoubleCon: 3256 case DoubleBot: 3257 case NarrowOop: 3258 case NarrowKlass: 3259 case Bottom: // Ye Olde Default 3260 return Type::BOTTOM; 3261 case Top: 3262 return this; 3263 3264 default: // All else is a mistake 3265 typerr(t); 3266 3267 case RawPtr: 3268 case MetadataPtr: 3269 case KlassPtr: 3270 return TypePtr::BOTTOM; // Oop meet raw is not well defined 3271 3272 case AnyPtr: { 3273 // Found an AnyPtr type vs self-OopPtr type 3274 const TypePtr *tp = t->is_ptr(); 3275 Offset offset = meet_offset(tp->offset()); 3276 PTR ptr = meet_ptr(tp->ptr()); 3277 const TypePtr* speculative = xmeet_speculative(tp); 3278 int depth = meet_inline_depth(tp->inline_depth()); 3279 switch (tp->ptr()) { 3280 case Null: 3281 if (ptr == Null) return TypePtr::make(AnyPtr, ptr, offset, speculative, depth); 3282 // else fall through: 3283 case TopPTR: 3284 case AnyNull: { 3285 int instance_id = meet_instance_id(InstanceTop); 3286 return make(ptr, offset, instance_id, speculative, depth); 3287 } 3288 case BotPTR: 3289 case NotNull: 3290 return TypePtr::make(AnyPtr, ptr, offset, speculative, depth); 3291 default: typerr(t); 3292 } 3293 } 3294 3295 case OopPtr: { // Meeting to other OopPtrs 3296 const TypeOopPtr *tp = t->is_oopptr(); 3297 int instance_id = meet_instance_id(tp->instance_id()); 3298 const TypePtr* speculative = xmeet_speculative(tp); 3299 int depth = meet_inline_depth(tp->inline_depth()); 3300 return make(meet_ptr(tp->ptr()), meet_offset(tp->offset()), instance_id, speculative, depth); 3301 } 3302 3303 case InstPtr: // For these, flip the call around to cut down 3304 case ValueTypePtr: 3305 case AryPtr: 3306 return t->xmeet(this); // Call in reverse direction 3307 3308 } // End of switch 3309 return this; // Return the double constant 3310 } 3311 3312 3313 //------------------------------xdual------------------------------------------ 3314 // Dual of a pure heap pointer. No relevant klass or oop information. 3315 const Type *TypeOopPtr::xdual() const { 3316 assert(klass() == Compile::current()->env()->Object_klass(), "no klasses here"); 3317 assert(const_oop() == NULL, "no constants here"); 3318 return new TypeOopPtr(_base, dual_ptr(), klass(), klass_is_exact(), const_oop(), dual_offset(), Offset::bottom, dual_instance_id(), dual_speculative(), dual_inline_depth()); 3319 } 3320 3321 //--------------------------make_from_klass_common----------------------------- 3322 // Computes the element-type given a klass. 3323 const TypeOopPtr* TypeOopPtr::make_from_klass_common(ciKlass *klass, bool klass_change, bool try_for_exact) { 3324 if (klass->is_valuetype()) { 3325 return TypeValueTypePtr::make(TypePtr::NotNull, klass->as_value_klass()); 3326 } else if (klass->is_instance_klass()) { 3327 Compile* C = Compile::current(); 3328 Dependencies* deps = C->dependencies(); 3329 assert((deps != NULL) == (C->method() != NULL && C->method()->code_size() > 0), "sanity"); 3330 // Element is an instance 3331 bool klass_is_exact = false; 3332 if (klass->is_loaded()) { 3333 // Try to set klass_is_exact. 3334 ciInstanceKlass* ik = klass->as_instance_klass(); 3335 klass_is_exact = ik->is_final(); 3336 if (!klass_is_exact && klass_change 3337 && deps != NULL && UseUniqueSubclasses) { 3338 ciInstanceKlass* sub = ik->unique_concrete_subklass(); 3339 if (sub != NULL) { 3340 deps->assert_abstract_with_unique_concrete_subtype(ik, sub); 3341 klass = ik = sub; 3342 klass_is_exact = sub->is_final(); 3343 } 3344 } 3345 if (!klass_is_exact && try_for_exact 3346 && deps != NULL && UseExactTypes) { 3347 if (!ik->is_interface() && !ik->has_subklass()) { 3348 // Add a dependence; if concrete subclass added we need to recompile 3349 deps->assert_leaf_type(ik); 3350 klass_is_exact = true; 3351 } 3352 } 3353 } 3354 return TypeInstPtr::make(TypePtr::BotPTR, klass, klass_is_exact, NULL, Offset(0)); 3355 } else if (klass->is_obj_array_klass()) { 3356 // Element is an object or value array. Recursively call ourself. 3357 const TypeOopPtr* etype = TypeOopPtr::make_from_klass_common(klass->as_array_klass()->element_klass(), false, try_for_exact); 3358 bool xk = etype->klass_is_exact(); 3359 const TypeAry* arr0 = TypeAry::make(etype, TypeInt::POS); 3360 // We used to pass NotNull in here, asserting that the sub-arrays 3361 // are all not-null. This is not true in generally, as code can 3362 // slam NULLs down in the subarrays. 3363 const TypeAryPtr* arr = TypeAryPtr::make(TypePtr::BotPTR, arr0, klass, xk, Offset(0)); 3364 return arr; 3365 } else if (klass->is_type_array_klass()) { 3366 // Element is an typeArray 3367 const Type* etype = get_const_basic_type(klass->as_type_array_klass()->element_type()); 3368 const TypeAry* arr0 = TypeAry::make(etype, TypeInt::POS); 3369 // We used to pass NotNull in here, asserting that the array pointer 3370 // is not-null. That was not true in general. 3371 const TypeAryPtr* arr = TypeAryPtr::make(TypePtr::BotPTR, arr0, klass, true, Offset(0)); 3372 return arr; 3373 } else if (klass->is_value_array_klass()) { 3374 ciValueKlass* vk = klass->as_array_klass()->element_klass()->as_value_klass(); 3375 const Type* etype = NULL; 3376 bool xk = false; 3377 if (vk->flatten_array()) { 3378 etype = TypeValueType::make(vk); 3379 xk = true; 3380 } else { 3381 const TypeOopPtr* etype_oop = TypeOopPtr::make_from_klass_common(vk, false, try_for_exact); 3382 xk = etype_oop->klass_is_exact(); 3383 etype = etype_oop; 3384 } 3385 const TypeAry* arr0 = TypeAry::make(etype, TypeInt::POS); 3386 const TypeAryPtr* arr = TypeAryPtr::make(TypePtr::BotPTR, arr0, klass, xk, Offset(0)); 3387 return arr; 3388 } else { 3389 ShouldNotReachHere(); 3390 return NULL; 3391 } 3392 } 3393 3394 //------------------------------make_from_constant----------------------------- 3395 // Make a java pointer from an oop constant 3396 const TypeOopPtr* TypeOopPtr::make_from_constant(ciObject* o, bool require_constant) { 3397 assert(!o->is_null_object(), "null object not yet handled here."); 3398 ciKlass* klass = o->klass(); 3399 if (klass->is_valuetype()) { 3400 // Element is a value type 3401 if (require_constant) { 3402 if (!o->can_be_constant()) return NULL; 3403 } else if (!o->should_be_constant()) { 3404 return TypeValueTypePtr::make(TypePtr::NotNull, klass->as_value_klass()); 3405 } 3406 return TypeValueTypePtr::make(o); 3407 } else if (klass->is_instance_klass()) { 3408 // Element is an instance 3409 if (require_constant) { 3410 if (!o->can_be_constant()) return NULL; 3411 } else if (!o->should_be_constant()) { 3412 return TypeInstPtr::make(TypePtr::NotNull, klass, true, NULL, Offset(0)); 3413 } 3414 return TypeInstPtr::make(o); 3415 } else if (klass->is_obj_array_klass() || klass->is_value_array_klass()) { 3416 // Element is an object array. Recursively call ourself. 3417 const TypeOopPtr *etype = 3418 TypeOopPtr::make_from_klass_raw(klass->as_array_klass()->element_klass()); 3419 const TypeAry* arr0 = TypeAry::make(etype, TypeInt::make(o->as_array()->length())); 3420 // We used to pass NotNull in here, asserting that the sub-arrays 3421 // are all not-null. This is not true in generally, as code can 3422 // slam NULLs down in the subarrays. 3423 if (require_constant) { 3424 if (!o->can_be_constant()) return NULL; 3425 } else if (!o->should_be_constant()) { 3426 return TypeAryPtr::make(TypePtr::NotNull, arr0, klass, true, Offset(0)); 3427 } 3428 const TypeAryPtr* arr = TypeAryPtr::make(TypePtr::Constant, o, arr0, klass, true, Offset(0)); 3429 return arr; 3430 } else if (klass->is_type_array_klass()) { 3431 // Element is an typeArray 3432 const Type* etype = 3433 (Type*)get_const_basic_type(klass->as_type_array_klass()->element_type()); 3434 const TypeAry* arr0 = TypeAry::make(etype, TypeInt::make(o->as_array()->length())); 3435 // We used to pass NotNull in here, asserting that the array pointer 3436 // is not-null. That was not true in general. 3437 if (require_constant) { 3438 if (!o->can_be_constant()) return NULL; 3439 } else if (!o->should_be_constant()) { 3440 return TypeAryPtr::make(TypePtr::NotNull, arr0, klass, true, Offset(0)); 3441 } 3442 const TypeAryPtr* arr = TypeAryPtr::make(TypePtr::Constant, o, arr0, klass, true, Offset(0)); 3443 return arr; 3444 } 3445 3446 fatal("unhandled object type"); 3447 return NULL; 3448 } 3449 3450 //------------------------------get_con---------------------------------------- 3451 intptr_t TypeOopPtr::get_con() const { 3452 assert( _ptr == Null || _ptr == Constant, "" ); 3453 assert(offset() >= 0, ""); 3454 3455 if (offset() != 0) { 3456 // After being ported to the compiler interface, the compiler no longer 3457 // directly manipulates the addresses of oops. Rather, it only has a pointer 3458 // to a handle at compile time. This handle is embedded in the generated 3459 // code and dereferenced at the time the nmethod is made. Until that time, 3460 // it is not reasonable to do arithmetic with the addresses of oops (we don't 3461 // have access to the addresses!). This does not seem to currently happen, 3462 // but this assertion here is to help prevent its occurence. 3463 tty->print_cr("Found oop constant with non-zero offset"); 3464 ShouldNotReachHere(); 3465 } 3466 3467 return (intptr_t)const_oop()->constant_encoding(); 3468 } 3469 3470 3471 //-----------------------------filter------------------------------------------ 3472 // Do not allow interface-vs.-noninterface joins to collapse to top. 3473 const Type *TypeOopPtr::filter_helper(const Type *kills, bool include_speculative) const { 3474 3475 const Type* ft = join_helper(kills, include_speculative); 3476 const TypeInstPtr* ftip = ft->isa_instptr(); 3477 const TypeInstPtr* ktip = kills->isa_instptr(); 3478 3479 if (ft->empty()) { 3480 // Check for evil case of 'this' being a class and 'kills' expecting an 3481 // interface. This can happen because the bytecodes do not contain 3482 // enough type info to distinguish a Java-level interface variable 3483 // from a Java-level object variable. If we meet 2 classes which 3484 // both implement interface I, but their meet is at 'j/l/O' which 3485 // doesn't implement I, we have no way to tell if the result should 3486 // be 'I' or 'j/l/O'. Thus we'll pick 'j/l/O'. If this then flows 3487 // into a Phi which "knows" it's an Interface type we'll have to 3488 // uplift the type. 3489 if (!empty()) { 3490 if (ktip != NULL && ktip->is_loaded() && ktip->klass()->is_interface()) { 3491 return kills; // Uplift to interface 3492 } 3493 // Also check for evil cases of 'this' being a class array 3494 // and 'kills' expecting an array of interfaces. 3495 Type::get_arrays_base_elements(ft, kills, NULL, &ktip); 3496 if (ktip != NULL && ktip->is_loaded() && ktip->klass()->is_interface()) { 3497 return kills; // Uplift to array of interface 3498 } 3499 } 3500 3501 return Type::TOP; // Canonical empty value 3502 } 3503 3504 // If we have an interface-typed Phi or cast and we narrow to a class type, 3505 // the join should report back the class. However, if we have a J/L/Object 3506 // class-typed Phi and an interface flows in, it's possible that the meet & 3507 // join report an interface back out. This isn't possible but happens 3508 // because the type system doesn't interact well with interfaces. 3509 if (ftip != NULL && ktip != NULL && 3510 ftip->is_loaded() && ftip->klass()->is_interface() && 3511 ktip->is_loaded() && !ktip->klass()->is_interface()) { 3512 assert(!ftip->klass_is_exact(), "interface could not be exact"); 3513 return ktip->cast_to_ptr_type(ftip->ptr()); 3514 } 3515 3516 return ft; 3517 } 3518 3519 //------------------------------eq--------------------------------------------- 3520 // Structural equality check for Type representations 3521 bool TypeOopPtr::eq( const Type *t ) const { 3522 const TypeOopPtr *a = (const TypeOopPtr*)t; 3523 if (_klass_is_exact != a->_klass_is_exact || 3524 _instance_id != a->_instance_id) return false; 3525 ciObject* one = const_oop(); 3526 ciObject* two = a->const_oop(); 3527 if (one == NULL || two == NULL) { 3528 return (one == two) && TypePtr::eq(t); 3529 } else { 3530 return one->equals(two) && TypePtr::eq(t); 3531 } 3532 } 3533 3534 //------------------------------hash------------------------------------------- 3535 // Type-specific hashing function. 3536 int TypeOopPtr::hash(void) const { 3537 return 3538 java_add(java_add(const_oop() ? const_oop()->hash() : 0, _klass_is_exact), 3539 java_add(_instance_id, TypePtr::hash())); 3540 } 3541 3542 //------------------------------dump2------------------------------------------ 3543 #ifndef PRODUCT 3544 void TypeOopPtr::dump2( Dict &d, uint depth, outputStream *st ) const { 3545 st->print("oopptr:%s", ptr_msg[_ptr]); 3546 if( _klass_is_exact ) st->print(":exact"); 3547 if( const_oop() ) st->print(INTPTR_FORMAT, p2i(const_oop())); 3548 _offset.dump2(st); 3549 if (_instance_id == InstanceTop) 3550 st->print(",iid=top"); 3551 else if (_instance_id != InstanceBot) 3552 st->print(",iid=%d",_instance_id); 3553 3554 dump_inline_depth(st); 3555 dump_speculative(st); 3556 } 3557 #endif 3558 3559 //------------------------------singleton-------------------------------------- 3560 // TRUE if Type is a singleton type, FALSE otherwise. Singletons are simple 3561 // constants 3562 bool TypeOopPtr::singleton(void) const { 3563 // detune optimizer to not generate constant oop + constant offset as a constant! 3564 // TopPTR, Null, AnyNull, Constant are all singletons 3565 return (offset() == 0) && !below_centerline(_ptr); 3566 } 3567 3568 //------------------------------add_offset------------------------------------- 3569 const TypePtr *TypeOopPtr::add_offset(intptr_t offset) const { 3570 return make(_ptr, xadd_offset(offset), _instance_id, add_offset_speculative(offset), _inline_depth); 3571 } 3572 3573 /** 3574 * Return same type without a speculative part 3575 */ 3576 const Type* TypeOopPtr::remove_speculative() const { 3577 if (_speculative == NULL) { 3578 return this; 3579 } 3580 assert(_inline_depth == InlineDepthTop || _inline_depth == InlineDepthBottom, "non speculative type shouldn't have inline depth"); 3581 return make(_ptr, _offset, _instance_id, NULL, _inline_depth); 3582 } 3583 3584 /** 3585 * Return same type but drop speculative part if we know we won't use 3586 * it 3587 */ 3588 const Type* TypeOopPtr::cleanup_speculative() const { 3589 // If the klass is exact and the ptr is not null then there's 3590 // nothing that the speculative type can help us with 3591 if (klass_is_exact() && !maybe_null()) { 3592 return remove_speculative(); 3593 } 3594 return TypePtr::cleanup_speculative(); 3595 } 3596 3597 /** 3598 * Return same type but with a different inline depth (used for speculation) 3599 * 3600 * @param depth depth to meet with 3601 */ 3602 const TypePtr* TypeOopPtr::with_inline_depth(int depth) const { 3603 if (!UseInlineDepthForSpeculativeTypes) { 3604 return this; 3605 } 3606 return make(_ptr, _offset, _instance_id, _speculative, depth); 3607 } 3608 3609 //------------------------------meet_instance_id-------------------------------- 3610 int TypeOopPtr::meet_instance_id( int instance_id ) const { 3611 // Either is 'TOP' instance? Return the other instance! 3612 if( _instance_id == InstanceTop ) return instance_id; 3613 if( instance_id == InstanceTop ) return _instance_id; 3614 // If either is different, return 'BOTTOM' instance 3615 if( _instance_id != instance_id ) return InstanceBot; 3616 return _instance_id; 3617 } 3618 3619 //------------------------------dual_instance_id-------------------------------- 3620 int TypeOopPtr::dual_instance_id( ) const { 3621 if( _instance_id == InstanceTop ) return InstanceBot; // Map TOP into BOTTOM 3622 if( _instance_id == InstanceBot ) return InstanceTop; // Map BOTTOM into TOP 3623 return _instance_id; // Map everything else into self 3624 } 3625 3626 /** 3627 * Check whether new profiling would improve speculative type 3628 * 3629 * @param exact_kls class from profiling 3630 * @param inline_depth inlining depth of profile point 3631 * 3632 * @return true if type profile is valuable 3633 */ 3634 bool TypeOopPtr::would_improve_type(ciKlass* exact_kls, int inline_depth) const { 3635 // no way to improve an already exact type 3636 if (klass_is_exact()) { 3637 return false; 3638 } 3639 return TypePtr::would_improve_type(exact_kls, inline_depth); 3640 } 3641 3642 //============================================================================= 3643 // Convenience common pre-built types. 3644 const TypeInstPtr *TypeInstPtr::NOTNULL; 3645 const TypeInstPtr *TypeInstPtr::BOTTOM; 3646 const TypeInstPtr *TypeInstPtr::MIRROR; 3647 const TypeInstPtr *TypeInstPtr::MARK; 3648 const TypeInstPtr *TypeInstPtr::KLASS; 3649 3650 //------------------------------TypeInstPtr------------------------------------- 3651 TypeInstPtr::TypeInstPtr(PTR ptr, ciKlass* k, bool xk, ciObject* o, Offset off, 3652 int instance_id, const TypePtr* speculative, int inline_depth) 3653 : TypeOopPtr(InstPtr, ptr, k, xk, o, off, Offset::bottom, instance_id, speculative, inline_depth), 3654 _name(k->name()) { 3655 assert(k != NULL && 3656 (k->is_loaded() || o == NULL), 3657 "cannot have constants with non-loaded klass"); 3658 }; 3659 3660 //------------------------------make------------------------------------------- 3661 const TypeInstPtr *TypeInstPtr::make(PTR ptr, 3662 ciKlass* k, 3663 bool xk, 3664 ciObject* o, 3665 Offset offset, 3666 int instance_id, 3667 const TypePtr* speculative, 3668 int inline_depth) { 3669 assert( !k->is_loaded() || k->is_instance_klass(), "Must be for instance"); 3670 // Either const_oop() is NULL or else ptr is Constant 3671 assert( (!o && ptr != Constant) || (o && ptr == Constant), 3672 "constant pointers must have a value supplied" ); 3673 // Ptr is never Null 3674 assert( ptr != Null, "NULL pointers are not typed" ); 3675 3676 assert(instance_id <= 0 || xk || !UseExactTypes, "instances are always exactly typed"); 3677 if (!UseExactTypes) xk = false; 3678 if (ptr == Constant) { 3679 // Note: This case includes meta-object constants, such as methods. 3680 xk = true; 3681 } else if (k->is_loaded()) { 3682 ciInstanceKlass* ik = k->as_instance_klass(); 3683 if (!xk && ik->is_final()) xk = true; // no inexact final klass 3684 if (xk && ik->is_interface()) xk = false; // no exact interface 3685 } 3686 3687 // Now hash this baby 3688 TypeInstPtr *result = 3689 (TypeInstPtr*)(new TypeInstPtr(ptr, k, xk, o ,offset, instance_id, speculative, inline_depth))->hashcons(); 3690 3691 return result; 3692 } 3693 3694 /** 3695 * Create constant type for a constant boxed value 3696 */ 3697 const Type* TypeInstPtr::get_const_boxed_value() const { 3698 assert(is_ptr_to_boxed_value(), "should be called only for boxed value"); 3699 assert((const_oop() != NULL), "should be called only for constant object"); 3700 ciConstant constant = const_oop()->as_instance()->field_value_by_offset(offset()); 3701 BasicType bt = constant.basic_type(); 3702 switch (bt) { 3703 case T_BOOLEAN: return TypeInt::make(constant.as_boolean()); 3704 case T_INT: return TypeInt::make(constant.as_int()); 3705 case T_CHAR: return TypeInt::make(constant.as_char()); 3706 case T_BYTE: return TypeInt::make(constant.as_byte()); 3707 case T_SHORT: return TypeInt::make(constant.as_short()); 3708 case T_FLOAT: return TypeF::make(constant.as_float()); 3709 case T_DOUBLE: return TypeD::make(constant.as_double()); 3710 case T_LONG: return TypeLong::make(constant.as_long()); 3711 default: break; 3712 } 3713 fatal("Invalid boxed value type '%s'", type2name(bt)); 3714 return NULL; 3715 } 3716 3717 //------------------------------cast_to_ptr_type------------------------------- 3718 const Type *TypeInstPtr::cast_to_ptr_type(PTR ptr) const { 3719 if( ptr == _ptr ) return this; 3720 // Reconstruct _sig info here since not a problem with later lazy 3721 // construction, _sig will show up on demand. 3722 return make(ptr, klass(), klass_is_exact(), const_oop(), _offset, _instance_id, _speculative, _inline_depth); 3723 } 3724 3725 3726 //-----------------------------cast_to_exactness------------------------------- 3727 const Type *TypeInstPtr::cast_to_exactness(bool klass_is_exact) const { 3728 if( klass_is_exact == _klass_is_exact ) return this; 3729 if (!UseExactTypes) return this; 3730 if (!_klass->is_loaded()) return this; 3731 ciInstanceKlass* ik = _klass->as_instance_klass(); 3732 if( (ik->is_final() || _const_oop) ) return this; // cannot clear xk 3733 if( ik->is_interface() ) return this; // cannot set xk 3734 return make(ptr(), klass(), klass_is_exact, const_oop(), _offset, _instance_id, _speculative, _inline_depth); 3735 } 3736 3737 //-----------------------------cast_to_instance_id---------------------------- 3738 const TypeOopPtr *TypeInstPtr::cast_to_instance_id(int instance_id) const { 3739 if( instance_id == _instance_id ) return this; 3740 return make(_ptr, klass(), _klass_is_exact, const_oop(), _offset, instance_id, _speculative, _inline_depth); 3741 } 3742 3743 //------------------------------xmeet_unloaded--------------------------------- 3744 // Compute the MEET of two InstPtrs when at least one is unloaded. 3745 // Assume classes are different since called after check for same name/class-loader 3746 const TypeInstPtr *TypeInstPtr::xmeet_unloaded(const TypeInstPtr *tinst) const { 3747 Offset off = meet_offset(tinst->offset()); 3748 PTR ptr = meet_ptr(tinst->ptr()); 3749 int instance_id = meet_instance_id(tinst->instance_id()); 3750 const TypePtr* speculative = xmeet_speculative(tinst); 3751 int depth = meet_inline_depth(tinst->inline_depth()); 3752 3753 const TypeInstPtr *loaded = is_loaded() ? this : tinst; 3754 const TypeInstPtr *unloaded = is_loaded() ? tinst : this; 3755 if( loaded->klass()->equals(ciEnv::current()->Object_klass()) ) { 3756 // 3757 // Meet unloaded class with java/lang/Object 3758 // 3759 // Meet 3760 // | Unloaded Class 3761 // Object | TOP | AnyNull | Constant | NotNull | BOTTOM | 3762 // =================================================================== 3763 // TOP | ..........................Unloaded......................| 3764 // AnyNull | U-AN |................Unloaded......................| 3765 // Constant | ... O-NN .................................. | O-BOT | 3766 // NotNull | ... O-NN .................................. | O-BOT | 3767 // BOTTOM | ........................Object-BOTTOM ..................| 3768 // 3769 assert(loaded->ptr() != TypePtr::Null, "insanity check"); 3770 // 3771 if( loaded->ptr() == TypePtr::TopPTR ) { return unloaded; } 3772 else if (loaded->ptr() == TypePtr::AnyNull) { return TypeInstPtr::make(ptr, unloaded->klass(), false, NULL, off, instance_id, speculative, depth); } 3773 else if (loaded->ptr() == TypePtr::BotPTR ) { return TypeInstPtr::BOTTOM; } 3774 else if (loaded->ptr() == TypePtr::Constant || loaded->ptr() == TypePtr::NotNull) { 3775 if (unloaded->ptr() == TypePtr::BotPTR ) { return TypeInstPtr::BOTTOM; } 3776 else { return TypeInstPtr::NOTNULL; } 3777 } 3778 else if( unloaded->ptr() == TypePtr::TopPTR ) { return unloaded; } 3779 3780 return unloaded->cast_to_ptr_type(TypePtr::AnyNull)->is_instptr(); 3781 } 3782 3783 // Both are unloaded, not the same class, not Object 3784 // Or meet unloaded with a different loaded class, not java/lang/Object 3785 if( ptr != TypePtr::BotPTR ) { 3786 return TypeInstPtr::NOTNULL; 3787 } 3788 return TypeInstPtr::BOTTOM; 3789 } 3790 3791 3792 //------------------------------meet------------------------------------------- 3793 // Compute the MEET of two types. It returns a new Type object. 3794 const Type *TypeInstPtr::xmeet_helper(const Type *t) const { 3795 // Perform a fast test for common case; meeting the same types together. 3796 if( this == t ) return this; // Meeting same type-rep? 3797 3798 // Current "this->_base" is Pointer 3799 switch (t->base()) { // switch on original type 3800 3801 case Int: // Mixing ints & oops happens when javac 3802 case Long: // reuses local variables 3803 case FloatTop: 3804 case FloatCon: 3805 case FloatBot: 3806 case DoubleTop: 3807 case DoubleCon: 3808 case DoubleBot: 3809 case NarrowOop: 3810 case NarrowKlass: 3811 case Bottom: // Ye Olde Default 3812 return Type::BOTTOM; 3813 case Top: 3814 return this; 3815 3816 default: // All else is a mistake 3817 typerr(t); 3818 3819 case MetadataPtr: 3820 case KlassPtr: 3821 case RawPtr: return TypePtr::BOTTOM; 3822 3823 case AryPtr: { // All arrays inherit from Object class 3824 const TypeAryPtr *tp = t->is_aryptr(); 3825 Offset offset = meet_offset(tp->offset()); 3826 PTR ptr = meet_ptr(tp->ptr()); 3827 int instance_id = meet_instance_id(tp->instance_id()); 3828 const TypePtr* speculative = xmeet_speculative(tp); 3829 int depth = meet_inline_depth(tp->inline_depth()); 3830 switch (ptr) { 3831 case TopPTR: 3832 case AnyNull: // Fall 'down' to dual of object klass 3833 // For instances when a subclass meets a superclass we fall 3834 // below the centerline when the superclass is exact. We need to 3835 // do the same here. 3836 if (klass()->equals(ciEnv::current()->Object_klass()) && !klass_is_exact()) { 3837 return TypeAryPtr::make(ptr, tp->ary(), tp->klass(), tp->klass_is_exact(), offset, tp->field_offset(), instance_id, speculative, depth); 3838 } else { 3839 // cannot subclass, so the meet has to fall badly below the centerline 3840 ptr = NotNull; 3841 instance_id = InstanceBot; 3842 return TypeInstPtr::make( ptr, ciEnv::current()->Object_klass(), false, NULL, offset, instance_id, speculative, depth); 3843 } 3844 case Constant: 3845 case NotNull: 3846 case BotPTR: // Fall down to object klass 3847 // LCA is object_klass, but if we subclass from the top we can do better 3848 if( above_centerline(_ptr) ) { // if( _ptr == TopPTR || _ptr == AnyNull ) 3849 // If 'this' (InstPtr) is above the centerline and it is Object class 3850 // then we can subclass in the Java class hierarchy. 3851 // For instances when a subclass meets a superclass we fall 3852 // below the centerline when the superclass is exact. We need 3853 // to do the same here. 3854 if (klass()->equals(ciEnv::current()->Object_klass()) && !klass_is_exact()) { 3855 // that is, tp's array type is a subtype of my klass 3856 return TypeAryPtr::make(ptr, (ptr == Constant ? tp->const_oop() : NULL), 3857 tp->ary(), tp->klass(), tp->klass_is_exact(), offset, tp->field_offset(), instance_id, speculative, depth); 3858 } 3859 } 3860 // The other case cannot happen, since I cannot be a subtype of an array. 3861 // The meet falls down to Object class below centerline. 3862 if( ptr == Constant ) 3863 ptr = NotNull; 3864 instance_id = InstanceBot; 3865 return make(ptr, ciEnv::current()->Object_klass(), false, NULL, offset, instance_id, speculative, depth); 3866 default: typerr(t); 3867 } 3868 } 3869 3870 case OopPtr: { // Meeting to OopPtrs 3871 // Found a OopPtr type vs self-InstPtr type 3872 const TypeOopPtr *tp = t->is_oopptr(); 3873 Offset offset = meet_offset(tp->offset()); 3874 PTR ptr = meet_ptr(tp->ptr()); 3875 switch (tp->ptr()) { 3876 case TopPTR: 3877 case AnyNull: { 3878 int instance_id = meet_instance_id(InstanceTop); 3879 const TypePtr* speculative = xmeet_speculative(tp); 3880 int depth = meet_inline_depth(tp->inline_depth()); 3881 return make(ptr, klass(), klass_is_exact(), 3882 (ptr == Constant ? const_oop() : NULL), offset, instance_id, speculative, depth); 3883 } 3884 case NotNull: 3885 case BotPTR: { 3886 int instance_id = meet_instance_id(tp->instance_id()); 3887 const TypePtr* speculative = xmeet_speculative(tp); 3888 int depth = meet_inline_depth(tp->inline_depth()); 3889 return TypeOopPtr::make(ptr, offset, instance_id, speculative, depth); 3890 } 3891 default: typerr(t); 3892 } 3893 } 3894 3895 case AnyPtr: { // Meeting to AnyPtrs 3896 // Found an AnyPtr type vs self-InstPtr type 3897 const TypePtr *tp = t->is_ptr(); 3898 Offset offset = meet_offset(tp->offset()); 3899 PTR ptr = meet_ptr(tp->ptr()); 3900 int instance_id = meet_instance_id(InstanceTop); 3901 const TypePtr* speculative = xmeet_speculative(tp); 3902 int depth = meet_inline_depth(tp->inline_depth()); 3903 switch (tp->ptr()) { 3904 case Null: 3905 if( ptr == Null ) return TypePtr::make(AnyPtr, ptr, offset, speculative, depth); 3906 // else fall through to AnyNull 3907 case TopPTR: 3908 case AnyNull: { 3909 return make(ptr, klass(), klass_is_exact(), 3910 (ptr == Constant ? const_oop() : NULL), offset, instance_id, speculative, depth); 3911 } 3912 case NotNull: 3913 case BotPTR: 3914 return TypePtr::make(AnyPtr, ptr, offset, speculative,depth); 3915 default: typerr(t); 3916 } 3917 } 3918 3919 /* 3920 A-top } 3921 / | \ } Tops 3922 B-top A-any C-top } 3923 | / | \ | } Any-nulls 3924 B-any | C-any } 3925 | | | 3926 B-con A-con C-con } constants; not comparable across classes 3927 | | | 3928 B-not | C-not } 3929 | \ | / | } not-nulls 3930 B-bot A-not C-bot } 3931 \ | / } Bottoms 3932 A-bot } 3933 */ 3934 3935 case InstPtr: { // Meeting 2 Oops? 3936 // Found an InstPtr sub-type vs self-InstPtr type 3937 const TypeInstPtr *tinst = t->is_instptr(); 3938 Offset off = meet_offset( tinst->offset() ); 3939 PTR ptr = meet_ptr( tinst->ptr() ); 3940 int instance_id = meet_instance_id(tinst->instance_id()); 3941 const TypePtr* speculative = xmeet_speculative(tinst); 3942 int depth = meet_inline_depth(tinst->inline_depth()); 3943 3944 // Check for easy case; klasses are equal (and perhaps not loaded!) 3945 // If we have constants, then we created oops so classes are loaded 3946 // and we can handle the constants further down. This case handles 3947 // both-not-loaded or both-loaded classes 3948 if (ptr != Constant && klass()->equals(tinst->klass()) && klass_is_exact() == tinst->klass_is_exact()) { 3949 return make(ptr, klass(), klass_is_exact(), NULL, off, instance_id, speculative, depth); 3950 } 3951 3952 // Classes require inspection in the Java klass hierarchy. Must be loaded. 3953 ciKlass* tinst_klass = tinst->klass(); 3954 ciKlass* this_klass = this->klass(); 3955 bool tinst_xk = tinst->klass_is_exact(); 3956 bool this_xk = this->klass_is_exact(); 3957 if (!tinst_klass->is_loaded() || !this_klass->is_loaded() ) { 3958 // One of these classes has not been loaded 3959 const TypeInstPtr *unloaded_meet = xmeet_unloaded(tinst); 3960 #ifndef PRODUCT 3961 if( PrintOpto && Verbose ) { 3962 tty->print("meet of unloaded classes resulted in: "); unloaded_meet->dump(); tty->cr(); 3963 tty->print(" this == "); this->dump(); tty->cr(); 3964 tty->print(" tinst == "); tinst->dump(); tty->cr(); 3965 } 3966 #endif 3967 return unloaded_meet; 3968 } 3969 3970 // Handle mixing oops and interfaces first. 3971 if( this_klass->is_interface() && !(tinst_klass->is_interface() || 3972 tinst_klass == ciEnv::current()->Object_klass())) { 3973 ciKlass *tmp = tinst_klass; // Swap interface around 3974 tinst_klass = this_klass; 3975 this_klass = tmp; 3976 bool tmp2 = tinst_xk; 3977 tinst_xk = this_xk; 3978 this_xk = tmp2; 3979 } 3980 if (tinst_klass->is_interface() && 3981 !(this_klass->is_interface() || 3982 // Treat java/lang/Object as an honorary interface, 3983 // because we need a bottom for the interface hierarchy. 3984 this_klass == ciEnv::current()->Object_klass())) { 3985 // Oop meets interface! 3986 3987 // See if the oop subtypes (implements) interface. 3988 ciKlass *k; 3989 bool xk; 3990 if( this_klass->is_subtype_of( tinst_klass ) ) { 3991 // Oop indeed subtypes. Now keep oop or interface depending 3992 // on whether we are both above the centerline or either is 3993 // below the centerline. If we are on the centerline 3994 // (e.g., Constant vs. AnyNull interface), use the constant. 3995 k = below_centerline(ptr) ? tinst_klass : this_klass; 3996 // If we are keeping this_klass, keep its exactness too. 3997 xk = below_centerline(ptr) ? tinst_xk : this_xk; 3998 } else { // Does not implement, fall to Object 3999 // Oop does not implement interface, so mixing falls to Object 4000 // just like the verifier does (if both are above the 4001 // centerline fall to interface) 4002 k = above_centerline(ptr) ? tinst_klass : ciEnv::current()->Object_klass(); 4003 xk = above_centerline(ptr) ? tinst_xk : false; 4004 // Watch out for Constant vs. AnyNull interface. 4005 if (ptr == Constant) ptr = NotNull; // forget it was a constant 4006 instance_id = InstanceBot; 4007 } 4008 ciObject* o = NULL; // the Constant value, if any 4009 if (ptr == Constant) { 4010 // Find out which constant. 4011 o = (this_klass == klass()) ? const_oop() : tinst->const_oop(); 4012 } 4013 return make(ptr, k, xk, o, off, instance_id, speculative, depth); 4014 } 4015 4016 // Either oop vs oop or interface vs interface or interface vs Object 4017 4018 // !!! Here's how the symmetry requirement breaks down into invariants: 4019 // If we split one up & one down AND they subtype, take the down man. 4020 // If we split one up & one down AND they do NOT subtype, "fall hard". 4021 // If both are up and they subtype, take the subtype class. 4022 // If both are up and they do NOT subtype, "fall hard". 4023 // If both are down and they subtype, take the supertype class. 4024 // If both are down and they do NOT subtype, "fall hard". 4025 // Constants treated as down. 4026 4027 // Now, reorder the above list; observe that both-down+subtype is also 4028 // "fall hard"; "fall hard" becomes the default case: 4029 // If we split one up & one down AND they subtype, take the down man. 4030 // If both are up and they subtype, take the subtype class. 4031 4032 // If both are down and they subtype, "fall hard". 4033 // If both are down and they do NOT subtype, "fall hard". 4034 // If both are up and they do NOT subtype, "fall hard". 4035 // If we split one up & one down AND they do NOT subtype, "fall hard". 4036 4037 // If a proper subtype is exact, and we return it, we return it exactly. 4038 // If a proper supertype is exact, there can be no subtyping relationship! 4039 // If both types are equal to the subtype, exactness is and-ed below the 4040 // centerline and or-ed above it. (N.B. Constants are always exact.) 4041 4042 // Check for subtyping: 4043 ciKlass *subtype = NULL; 4044 bool subtype_exact = false; 4045 if( tinst_klass->equals(this_klass) ) { 4046 subtype = this_klass; 4047 subtype_exact = below_centerline(ptr) ? (this_xk & tinst_xk) : (this_xk | tinst_xk); 4048 } else if( !tinst_xk && this_klass->is_subtype_of( tinst_klass ) ) { 4049 subtype = this_klass; // Pick subtyping class 4050 subtype_exact = this_xk; 4051 } else if( !this_xk && tinst_klass->is_subtype_of( this_klass ) ) { 4052 subtype = tinst_klass; // Pick subtyping class 4053 subtype_exact = tinst_xk; 4054 } 4055 4056 if( subtype ) { 4057 if( above_centerline(ptr) ) { // both are up? 4058 this_klass = tinst_klass = subtype; 4059 this_xk = tinst_xk = subtype_exact; 4060 } else if( above_centerline(this ->_ptr) && !above_centerline(tinst->_ptr) ) { 4061 this_klass = tinst_klass; // tinst is down; keep down man 4062 this_xk = tinst_xk; 4063 } else if( above_centerline(tinst->_ptr) && !above_centerline(this ->_ptr) ) { 4064 tinst_klass = this_klass; // this is down; keep down man 4065 tinst_xk = this_xk; 4066 } else { 4067 this_xk = subtype_exact; // either they are equal, or we'll do an LCA 4068 } 4069 } 4070 4071 // Check for classes now being equal 4072 if (tinst_klass->equals(this_klass)) { 4073 // If the klasses are equal, the constants may still differ. Fall to 4074 // NotNull if they do (neither constant is NULL; that is a special case 4075 // handled elsewhere). 4076 ciObject* o = NULL; // Assume not constant when done 4077 ciObject* this_oop = const_oop(); 4078 ciObject* tinst_oop = tinst->const_oop(); 4079 if( ptr == Constant ) { 4080 if (this_oop != NULL && tinst_oop != NULL && 4081 this_oop->equals(tinst_oop) ) 4082 o = this_oop; 4083 else if (above_centerline(this ->_ptr)) 4084 o = tinst_oop; 4085 else if (above_centerline(tinst ->_ptr)) 4086 o = this_oop; 4087 else 4088 ptr = NotNull; 4089 } 4090 return make(ptr, this_klass, this_xk, o, off, instance_id, speculative, depth); 4091 } // Else classes are not equal 4092 4093 // Since klasses are different, we require a LCA in the Java 4094 // class hierarchy - which means we have to fall to at least NotNull. 4095 if( ptr == TopPTR || ptr == AnyNull || ptr == Constant ) 4096 ptr = NotNull; 4097 4098 instance_id = InstanceBot; 4099 4100 // Now we find the LCA of Java classes 4101 ciKlass* k = this_klass->least_common_ancestor(tinst_klass); 4102 return make(ptr, k, false, NULL, off, instance_id, speculative, depth); 4103 } // End of case InstPtr 4104 4105 } // End of switch 4106 return this; // Return the double constant 4107 } 4108 4109 4110 //------------------------java_mirror_type-------------------------------------- 4111 ciType* TypeInstPtr::java_mirror_type() const { 4112 // must be a singleton type 4113 if( const_oop() == NULL ) return NULL; 4114 4115 // must be of type java.lang.Class 4116 if( klass() != ciEnv::current()->Class_klass() ) return NULL; 4117 4118 return const_oop()->as_instance()->java_mirror_type(); 4119 } 4120 4121 4122 //------------------------------xdual------------------------------------------ 4123 // Dual: do NOT dual on klasses. This means I do NOT understand the Java 4124 // inheritance mechanism. 4125 const Type *TypeInstPtr::xdual() const { 4126 return new TypeInstPtr(dual_ptr(), klass(), klass_is_exact(), const_oop(), dual_offset(), dual_instance_id(), dual_speculative(), dual_inline_depth()); 4127 } 4128 4129 //------------------------------eq--------------------------------------------- 4130 // Structural equality check for Type representations 4131 bool TypeInstPtr::eq( const Type *t ) const { 4132 const TypeInstPtr *p = t->is_instptr(); 4133 return 4134 klass()->equals(p->klass()) && 4135 TypeOopPtr::eq(p); // Check sub-type stuff 4136 } 4137 4138 //------------------------------hash------------------------------------------- 4139 // Type-specific hashing function. 4140 int TypeInstPtr::hash(void) const { 4141 int hash = java_add(klass()->hash(), TypeOopPtr::hash()); 4142 return hash; 4143 } 4144 4145 //------------------------------dump2------------------------------------------ 4146 // Dump oop Type 4147 #ifndef PRODUCT 4148 void TypeInstPtr::dump2( Dict &d, uint depth, outputStream *st ) const { 4149 // Print the name of the klass. 4150 klass()->print_name_on(st); 4151 4152 switch( _ptr ) { 4153 case Constant: 4154 // TO DO: Make CI print the hex address of the underlying oop. 4155 if (WizardMode || Verbose) { 4156 const_oop()->print_oop(st); 4157 } 4158 case BotPTR: 4159 if (!WizardMode && !Verbose) { 4160 if( _klass_is_exact ) st->print(":exact"); 4161 break; 4162 } 4163 case TopPTR: 4164 case AnyNull: 4165 case NotNull: 4166 st->print(":%s", ptr_msg[_ptr]); 4167 if( _klass_is_exact ) st->print(":exact"); 4168 break; 4169 } 4170 4171 _offset.dump2(st); 4172 4173 st->print(" *"); 4174 if (_instance_id == InstanceTop) 4175 st->print(",iid=top"); 4176 else if (_instance_id != InstanceBot) 4177 st->print(",iid=%d",_instance_id); 4178 4179 dump_inline_depth(st); 4180 dump_speculative(st); 4181 } 4182 #endif 4183 4184 //------------------------------add_offset------------------------------------- 4185 const TypePtr *TypeInstPtr::add_offset(intptr_t offset) const { 4186 return make(_ptr, klass(), klass_is_exact(), const_oop(), xadd_offset(offset), 4187 _instance_id, add_offset_speculative(offset), _inline_depth); 4188 } 4189 4190 const Type *TypeInstPtr::remove_speculative() const { 4191 if (_speculative == NULL) { 4192 return this; 4193 } 4194 assert(_inline_depth == InlineDepthTop || _inline_depth == InlineDepthBottom, "non speculative type shouldn't have inline depth"); 4195 return make(_ptr, klass(), klass_is_exact(), const_oop(), _offset, 4196 _instance_id, NULL, _inline_depth); 4197 } 4198 4199 const TypePtr *TypeInstPtr::with_inline_depth(int depth) const { 4200 if (!UseInlineDepthForSpeculativeTypes) { 4201 return this; 4202 } 4203 return make(_ptr, klass(), klass_is_exact(), const_oop(), _offset, _instance_id, _speculative, depth); 4204 } 4205 4206 //============================================================================= 4207 // Convenience common pre-built types. 4208 const TypeAryPtr *TypeAryPtr::RANGE; 4209 const TypeAryPtr *TypeAryPtr::OOPS; 4210 const TypeAryPtr *TypeAryPtr::NARROWOOPS; 4211 const TypeAryPtr *TypeAryPtr::BYTES; 4212 const TypeAryPtr *TypeAryPtr::SHORTS; 4213 const TypeAryPtr *TypeAryPtr::CHARS; 4214 const TypeAryPtr *TypeAryPtr::INTS; 4215 const TypeAryPtr *TypeAryPtr::LONGS; 4216 const TypeAryPtr *TypeAryPtr::FLOATS; 4217 const TypeAryPtr *TypeAryPtr::DOUBLES; 4218 4219 //------------------------------make------------------------------------------- 4220 const TypeAryPtr* TypeAryPtr::make(PTR ptr, const TypeAry *ary, ciKlass* k, bool xk, Offset offset, Offset field_offset, 4221 int instance_id, const TypePtr* speculative, int inline_depth) { 4222 assert(!(k == NULL && ary->_elem->isa_int()), 4223 "integral arrays must be pre-equipped with a class"); 4224 if (!xk) xk = ary->ary_must_be_exact(); 4225 assert(instance_id <= 0 || xk || !UseExactTypes, "instances are always exactly typed"); 4226 if (!UseExactTypes) xk = (ptr == Constant); 4227 return (TypeAryPtr*)(new TypeAryPtr(ptr, NULL, ary, k, xk, offset, field_offset, instance_id, false, speculative, inline_depth))->hashcons(); 4228 } 4229 4230 //------------------------------make------------------------------------------- 4231 const TypeAryPtr* TypeAryPtr::make(PTR ptr, ciObject* o, const TypeAry *ary, ciKlass* k, bool xk, Offset offset, Offset field_offset, 4232 int instance_id, const TypePtr* speculative, int inline_depth, 4233 bool is_autobox_cache) { 4234 assert(!(k == NULL && ary->_elem->isa_int()), 4235 "integral arrays must be pre-equipped with a class"); 4236 assert( (ptr==Constant && o) || (ptr!=Constant && !o), "" ); 4237 if (!xk) xk = (o != NULL) || ary->ary_must_be_exact(); 4238 assert(instance_id <= 0 || xk || !UseExactTypes, "instances are always exactly typed"); 4239 if (!UseExactTypes) xk = (ptr == Constant); 4240 return (TypeAryPtr*)(new TypeAryPtr(ptr, o, ary, k, xk, offset, field_offset, instance_id, is_autobox_cache, speculative, inline_depth))->hashcons(); 4241 } 4242 4243 //------------------------------cast_to_ptr_type------------------------------- 4244 const Type *TypeAryPtr::cast_to_ptr_type(PTR ptr) const { 4245 if( ptr == _ptr ) return this; 4246 return make(ptr, const_oop(), _ary, klass(), klass_is_exact(), _offset, _field_offset, _instance_id, _speculative, _inline_depth, _is_autobox_cache); 4247 } 4248 4249 4250 //-----------------------------cast_to_exactness------------------------------- 4251 const Type *TypeAryPtr::cast_to_exactness(bool klass_is_exact) const { 4252 if( klass_is_exact == _klass_is_exact ) return this; 4253 if (!UseExactTypes) return this; 4254 if (_ary->ary_must_be_exact()) return this; // cannot clear xk 4255 return make(ptr(), const_oop(), _ary, klass(), klass_is_exact, _offset, _field_offset, _instance_id, _speculative, _inline_depth, _is_autobox_cache); 4256 } 4257 4258 //-----------------------------cast_to_instance_id---------------------------- 4259 const TypeOopPtr *TypeAryPtr::cast_to_instance_id(int instance_id) const { 4260 if( instance_id == _instance_id ) return this; 4261 return make(_ptr, const_oop(), _ary, klass(), _klass_is_exact, _offset, _field_offset, instance_id, _speculative, _inline_depth, _is_autobox_cache); 4262 } 4263 4264 //-----------------------------narrow_size_type------------------------------- 4265 // Local cache for arrayOopDesc::max_array_length(etype), 4266 // which is kind of slow (and cached elsewhere by other users). 4267 static jint max_array_length_cache[T_CONFLICT+1]; 4268 static jint max_array_length(BasicType etype) { 4269 jint& cache = max_array_length_cache[etype]; 4270 jint res = cache; 4271 if (res == 0) { 4272 switch (etype) { 4273 case T_NARROWOOP: 4274 etype = T_OBJECT; 4275 break; 4276 case T_NARROWKLASS: 4277 case T_CONFLICT: 4278 case T_ILLEGAL: 4279 case T_VOID: 4280 etype = T_BYTE; // will produce conservatively high value 4281 } 4282 cache = res = arrayOopDesc::max_array_length(etype); 4283 } 4284 return res; 4285 } 4286 4287 // Narrow the given size type to the index range for the given array base type. 4288 // Return NULL if the resulting int type becomes empty. 4289 const TypeInt* TypeAryPtr::narrow_size_type(const TypeInt* size) const { 4290 jint hi = size->_hi; 4291 jint lo = size->_lo; 4292 jint min_lo = 0; 4293 jint max_hi = max_array_length(elem()->basic_type()); 4294 //if (index_not_size) --max_hi; // type of a valid array index, FTR 4295 bool chg = false; 4296 if (lo < min_lo) { 4297 lo = min_lo; 4298 if (size->is_con()) { 4299 hi = lo; 4300 } 4301 chg = true; 4302 } 4303 if (hi > max_hi) { 4304 hi = max_hi; 4305 if (size->is_con()) { 4306 lo = hi; 4307 } 4308 chg = true; 4309 } 4310 // Negative length arrays will produce weird intermediate dead fast-path code 4311 if (lo > hi) 4312 return TypeInt::ZERO; 4313 if (!chg) 4314 return size; 4315 return TypeInt::make(lo, hi, Type::WidenMin); 4316 } 4317 4318 //-------------------------------cast_to_size---------------------------------- 4319 const TypeAryPtr* TypeAryPtr::cast_to_size(const TypeInt* new_size) const { 4320 assert(new_size != NULL, ""); 4321 new_size = narrow_size_type(new_size); 4322 if (new_size == size()) return this; 4323 const TypeAry* new_ary = TypeAry::make(elem(), new_size, is_stable()); 4324 return make(ptr(), const_oop(), new_ary, klass(), klass_is_exact(), _offset, _field_offset, _instance_id, _speculative, _inline_depth, _is_autobox_cache); 4325 } 4326 4327 //------------------------------cast_to_stable--------------------------------- 4328 const TypeAryPtr* TypeAryPtr::cast_to_stable(bool stable, int stable_dimension) const { 4329 if (stable_dimension <= 0 || (stable_dimension == 1 && stable == this->is_stable())) 4330 return this; 4331 4332 const Type* elem = this->elem(); 4333 const TypePtr* elem_ptr = elem->make_ptr(); 4334 4335 if (stable_dimension > 1 && elem_ptr != NULL && elem_ptr->isa_aryptr()) { 4336 // If this is widened from a narrow oop, TypeAry::make will re-narrow it. 4337 elem = elem_ptr = elem_ptr->is_aryptr()->cast_to_stable(stable, stable_dimension - 1); 4338 } 4339 4340 const TypeAry* new_ary = TypeAry::make(elem, size(), stable); 4341 4342 return make(ptr(), const_oop(), new_ary, klass(), klass_is_exact(), _offset, _field_offset, _instance_id, _speculative, _inline_depth, _is_autobox_cache); 4343 } 4344 4345 //-----------------------------stable_dimension-------------------------------- 4346 int TypeAryPtr::stable_dimension() const { 4347 if (!is_stable()) return 0; 4348 int dim = 1; 4349 const TypePtr* elem_ptr = elem()->make_ptr(); 4350 if (elem_ptr != NULL && elem_ptr->isa_aryptr()) 4351 dim += elem_ptr->is_aryptr()->stable_dimension(); 4352 return dim; 4353 } 4354 4355 //----------------------cast_to_autobox_cache----------------------------------- 4356 const TypeAryPtr* TypeAryPtr::cast_to_autobox_cache(bool cache) const { 4357 if (is_autobox_cache() == cache) return this; 4358 const TypeOopPtr* etype = elem()->make_oopptr(); 4359 if (etype == NULL) return this; 4360 // The pointers in the autobox arrays are always non-null. 4361 TypePtr::PTR ptr_type = cache ? TypePtr::NotNull : TypePtr::AnyNull; 4362 etype = etype->cast_to_ptr_type(TypePtr::NotNull)->is_oopptr(); 4363 const TypeAry* new_ary = TypeAry::make(etype, size(), is_stable()); 4364 return make(ptr(), const_oop(), new_ary, klass(), klass_is_exact(), _offset, _field_offset, _instance_id, _speculative, _inline_depth, cache); 4365 } 4366 4367 //------------------------------eq--------------------------------------------- 4368 // Structural equality check for Type representations 4369 bool TypeAryPtr::eq( const Type *t ) const { 4370 const TypeAryPtr *p = t->is_aryptr(); 4371 return 4372 _ary == p->_ary && // Check array 4373 TypeOopPtr::eq(p) &&// Check sub-parts 4374 _field_offset == p->_field_offset; 4375 } 4376 4377 //------------------------------hash------------------------------------------- 4378 // Type-specific hashing function. 4379 int TypeAryPtr::hash(void) const { 4380 return (intptr_t)_ary + TypeOopPtr::hash() + _field_offset.get(); 4381 } 4382 4383 //------------------------------meet------------------------------------------- 4384 // Compute the MEET of two types. It returns a new Type object. 4385 const Type *TypeAryPtr::xmeet_helper(const Type *t) const { 4386 // Perform a fast test for common case; meeting the same types together. 4387 if( this == t ) return this; // Meeting same type-rep? 4388 // Current "this->_base" is Pointer 4389 switch (t->base()) { // switch on original type 4390 4391 // Mixing ints & oops happens when javac reuses local variables 4392 case Int: 4393 case Long: 4394 case FloatTop: 4395 case FloatCon: 4396 case FloatBot: 4397 case DoubleTop: 4398 case DoubleCon: 4399 case DoubleBot: 4400 case NarrowOop: 4401 case NarrowKlass: 4402 case Bottom: // Ye Olde Default 4403 return Type::BOTTOM; 4404 case Top: 4405 return this; 4406 4407 default: // All else is a mistake 4408 typerr(t); 4409 4410 case OopPtr: { // Meeting to OopPtrs 4411 // Found a OopPtr type vs self-AryPtr type 4412 const TypeOopPtr *tp = t->is_oopptr(); 4413 Offset offset = meet_offset(tp->offset()); 4414 PTR ptr = meet_ptr(tp->ptr()); 4415 int depth = meet_inline_depth(tp->inline_depth()); 4416 const TypePtr* speculative = xmeet_speculative(tp); 4417 switch (tp->ptr()) { 4418 case TopPTR: 4419 case AnyNull: { 4420 int instance_id = meet_instance_id(InstanceTop); 4421 return make(ptr, (ptr == Constant ? const_oop() : NULL), 4422 _ary, _klass, _klass_is_exact, offset, _field_offset, instance_id, speculative, depth); 4423 } 4424 case BotPTR: 4425 case NotNull: { 4426 int instance_id = meet_instance_id(tp->instance_id()); 4427 return TypeOopPtr::make(ptr, offset, instance_id, speculative, depth); 4428 } 4429 default: ShouldNotReachHere(); 4430 } 4431 } 4432 4433 case AnyPtr: { // Meeting two AnyPtrs 4434 // Found an AnyPtr type vs self-AryPtr type 4435 const TypePtr *tp = t->is_ptr(); 4436 Offset offset = meet_offset(tp->offset()); 4437 PTR ptr = meet_ptr(tp->ptr()); 4438 const TypePtr* speculative = xmeet_speculative(tp); 4439 int depth = meet_inline_depth(tp->inline_depth()); 4440 switch (tp->ptr()) { 4441 case TopPTR: 4442 return this; 4443 case BotPTR: 4444 case NotNull: 4445 return TypePtr::make(AnyPtr, ptr, offset, speculative, depth); 4446 case Null: 4447 if( ptr == Null ) return TypePtr::make(AnyPtr, ptr, offset, speculative, depth); 4448 // else fall through to AnyNull 4449 case AnyNull: { 4450 int instance_id = meet_instance_id(InstanceTop); 4451 return make(ptr, (ptr == Constant ? const_oop() : NULL), 4452 _ary, _klass, _klass_is_exact, offset, _field_offset, instance_id, speculative, depth); 4453 } 4454 default: ShouldNotReachHere(); 4455 } 4456 } 4457 4458 case MetadataPtr: 4459 case KlassPtr: 4460 case RawPtr: return TypePtr::BOTTOM; 4461 4462 case AryPtr: { // Meeting 2 references? 4463 const TypeAryPtr *tap = t->is_aryptr(); 4464 Offset off = meet_offset(tap->offset()); 4465 Offset field_off = meet_field_offset(tap->field_offset()); 4466 const TypeAry *tary = _ary->meet_speculative(tap->_ary)->is_ary(); 4467 PTR ptr = meet_ptr(tap->ptr()); 4468 int instance_id = meet_instance_id(tap->instance_id()); 4469 const TypePtr* speculative = xmeet_speculative(tap); 4470 int depth = meet_inline_depth(tap->inline_depth()); 4471 ciKlass* lazy_klass = NULL; 4472 if (tary->_elem->isa_int()) { 4473 // Integral array element types have irrelevant lattice relations. 4474 // It is the klass that determines array layout, not the element type. 4475 if (_klass == NULL) 4476 lazy_klass = tap->_klass; 4477 else if (tap->_klass == NULL || tap->_klass == _klass) { 4478 lazy_klass = _klass; 4479 } else { 4480 // Something like byte[int+] meets char[int+]. 4481 // This must fall to bottom, not (int[-128..65535])[int+]. 4482 instance_id = InstanceBot; 4483 tary = TypeAry::make(Type::BOTTOM, tary->_size, tary->_stable); 4484 } 4485 } else // Non integral arrays. 4486 // Must fall to bottom if exact klasses in upper lattice 4487 // are not equal or super klass is exact. 4488 if ((above_centerline(ptr) || ptr == Constant) && klass() != tap->klass() && 4489 // meet with top[] and bottom[] are processed further down: 4490 tap->_klass != NULL && this->_klass != NULL && 4491 // both are exact and not equal: 4492 ((tap->_klass_is_exact && this->_klass_is_exact) || 4493 // 'tap' is exact and super or unrelated: 4494 (tap->_klass_is_exact && !tap->klass()->is_subtype_of(klass())) || 4495 // 'this' is exact and super or unrelated: 4496 (this->_klass_is_exact && !klass()->is_subtype_of(tap->klass())))) { 4497 if (above_centerline(ptr)) { 4498 tary = TypeAry::make(Type::BOTTOM, tary->_size, tary->_stable); 4499 } 4500 return make(NotNull, NULL, tary, lazy_klass, false, off, field_off, InstanceBot, speculative, depth); 4501 } 4502 4503 bool xk = false; 4504 switch (tap->ptr()) { 4505 case AnyNull: 4506 case TopPTR: 4507 // Compute new klass on demand, do not use tap->_klass 4508 if (below_centerline(this->_ptr)) { 4509 xk = this->_klass_is_exact; 4510 } else { 4511 xk = (tap->_klass_is_exact | this->_klass_is_exact); 4512 } 4513 return make(ptr, const_oop(), tary, lazy_klass, xk, off, field_off, instance_id, speculative, depth); 4514 case Constant: { 4515 ciObject* o = const_oop(); 4516 if( _ptr == Constant ) { 4517 if( tap->const_oop() != NULL && !o->equals(tap->const_oop()) ) { 4518 xk = (klass() == tap->klass()); 4519 ptr = NotNull; 4520 o = NULL; 4521 instance_id = InstanceBot; 4522 } else { 4523 xk = true; 4524 } 4525 } else if(above_centerline(_ptr)) { 4526 o = tap->const_oop(); 4527 xk = true; 4528 } else { 4529 // Only precise for identical arrays 4530 xk = this->_klass_is_exact && (klass() == tap->klass()); 4531 } 4532 return TypeAryPtr::make(ptr, o, tary, lazy_klass, xk, off, field_off, instance_id, speculative, depth); 4533 } 4534 case NotNull: 4535 case BotPTR: 4536 // Compute new klass on demand, do not use tap->_klass 4537 if (above_centerline(this->_ptr)) 4538 xk = tap->_klass_is_exact; 4539 else xk = (tap->_klass_is_exact & this->_klass_is_exact) && 4540 (klass() == tap->klass()); // Only precise for identical arrays 4541 return TypeAryPtr::make(ptr, NULL, tary, lazy_klass, xk, off, field_off, instance_id, speculative, depth); 4542 default: ShouldNotReachHere(); 4543 } 4544 } 4545 4546 // All arrays inherit from Object class 4547 case InstPtr: { 4548 const TypeInstPtr *tp = t->is_instptr(); 4549 Offset offset = meet_offset(tp->offset()); 4550 PTR ptr = meet_ptr(tp->ptr()); 4551 int instance_id = meet_instance_id(tp->instance_id()); 4552 const TypePtr* speculative = xmeet_speculative(tp); 4553 int depth = meet_inline_depth(tp->inline_depth()); 4554 switch (ptr) { 4555 case TopPTR: 4556 case AnyNull: // Fall 'down' to dual of object klass 4557 // For instances when a subclass meets a superclass we fall 4558 // below the centerline when the superclass is exact. We need to 4559 // do the same here. 4560 if (tp->klass()->equals(ciEnv::current()->Object_klass()) && !tp->klass_is_exact()) { 4561 return TypeAryPtr::make(ptr, _ary, _klass, _klass_is_exact, offset, _field_offset, instance_id, speculative, depth); 4562 } else { 4563 // cannot subclass, so the meet has to fall badly below the centerline 4564 ptr = NotNull; 4565 instance_id = InstanceBot; 4566 return TypeInstPtr::make(ptr, ciEnv::current()->Object_klass(), false, NULL, offset, instance_id, speculative, depth); 4567 } 4568 case Constant: 4569 case NotNull: 4570 case BotPTR: // Fall down to object klass 4571 // LCA is object_klass, but if we subclass from the top we can do better 4572 if (above_centerline(tp->ptr())) { 4573 // If 'tp' is above the centerline and it is Object class 4574 // then we can subclass in the Java class hierarchy. 4575 // For instances when a subclass meets a superclass we fall 4576 // below the centerline when the superclass is exact. We need 4577 // to do the same here. 4578 if (tp->klass()->equals(ciEnv::current()->Object_klass()) && !tp->klass_is_exact()) { 4579 // that is, my array type is a subtype of 'tp' klass 4580 return make(ptr, (ptr == Constant ? const_oop() : NULL), 4581 _ary, _klass, _klass_is_exact, offset, _field_offset, instance_id, speculative, depth); 4582 } 4583 } 4584 // The other case cannot happen, since t cannot be a subtype of an array. 4585 // The meet falls down to Object class below centerline. 4586 if( ptr == Constant ) 4587 ptr = NotNull; 4588 instance_id = InstanceBot; 4589 return TypeInstPtr::make(ptr, ciEnv::current()->Object_klass(), false, NULL,offset, instance_id, speculative, depth); 4590 default: typerr(t); 4591 } 4592 } 4593 } 4594 return this; // Lint noise 4595 } 4596 4597 //------------------------------xdual------------------------------------------ 4598 // Dual: compute field-by-field dual 4599 const Type *TypeAryPtr::xdual() const { 4600 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()); 4601 } 4602 4603 Type::Offset TypeAryPtr::meet_field_offset(const Type::Offset offset) const { 4604 return _field_offset.meet(offset); 4605 } 4606 4607 //------------------------------dual_offset------------------------------------ 4608 Type::Offset TypeAryPtr::dual_field_offset() const { 4609 return _field_offset.dual(); 4610 } 4611 4612 //----------------------interface_vs_oop--------------------------------------- 4613 #ifdef ASSERT 4614 bool TypeAryPtr::interface_vs_oop(const Type *t) const { 4615 const TypeAryPtr* t_aryptr = t->isa_aryptr(); 4616 if (t_aryptr) { 4617 return _ary->interface_vs_oop(t_aryptr->_ary); 4618 } 4619 return false; 4620 } 4621 #endif 4622 4623 //------------------------------dump2------------------------------------------ 4624 #ifndef PRODUCT 4625 void TypeAryPtr::dump2( Dict &d, uint depth, outputStream *st ) const { 4626 _ary->dump2(d,depth,st); 4627 switch( _ptr ) { 4628 case Constant: 4629 const_oop()->print(st); 4630 break; 4631 case BotPTR: 4632 if (!WizardMode && !Verbose) { 4633 if( _klass_is_exact ) st->print(":exact"); 4634 break; 4635 } 4636 case TopPTR: 4637 case AnyNull: 4638 case NotNull: 4639 st->print(":%s", ptr_msg[_ptr]); 4640 if( _klass_is_exact ) st->print(":exact"); 4641 break; 4642 } 4643 4644 if (elem()->isa_valuetype()) { 4645 st->print("("); 4646 _field_offset.dump2(st); 4647 st->print(")"); 4648 } 4649 if (offset() != 0) { 4650 int header_size = objArrayOopDesc::header_size() * wordSize; 4651 if( _offset == Offset::top ) st->print("+undefined"); 4652 else if( _offset == Offset::bottom ) st->print("+any"); 4653 else if( offset() < header_size ) st->print("+%d", offset()); 4654 else { 4655 BasicType basic_elem_type = elem()->basic_type(); 4656 int array_base = arrayOopDesc::base_offset_in_bytes(basic_elem_type); 4657 int elem_size = type2aelembytes(basic_elem_type); 4658 st->print("[%d]", (offset() - array_base)/elem_size); 4659 } 4660 } 4661 st->print(" *"); 4662 if (_instance_id == InstanceTop) 4663 st->print(",iid=top"); 4664 else if (_instance_id != InstanceBot) 4665 st->print(",iid=%d",_instance_id); 4666 4667 dump_inline_depth(st); 4668 dump_speculative(st); 4669 } 4670 #endif 4671 4672 bool TypeAryPtr::empty(void) const { 4673 if (_ary->empty()) return true; 4674 return TypeOopPtr::empty(); 4675 } 4676 4677 //------------------------------add_offset------------------------------------- 4678 const TypePtr *TypeAryPtr::add_offset(intptr_t offset) const { 4679 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); 4680 } 4681 4682 const Type *TypeAryPtr::remove_speculative() const { 4683 if (_speculative == NULL) { 4684 return this; 4685 } 4686 assert(_inline_depth == InlineDepthTop || _inline_depth == InlineDepthBottom, "non speculative type shouldn't have inline depth"); 4687 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); 4688 } 4689 4690 const TypePtr *TypeAryPtr::with_inline_depth(int depth) const { 4691 if (!UseInlineDepthForSpeculativeTypes) { 4692 return this; 4693 } 4694 return make(_ptr, _const_oop, _ary->remove_speculative()->is_ary(), _klass, _klass_is_exact, _offset, _field_offset, _instance_id, _speculative, depth, _is_autobox_cache); 4695 } 4696 4697 const TypeAryPtr* TypeAryPtr::with_field_offset(int offset) const { 4698 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); 4699 } 4700 4701 const TypePtr* TypeAryPtr::with_field_offset_and_offset(intptr_t offset) const { 4702 if (offset != Type::OffsetBot) { 4703 const Type* elemtype = elem(); 4704 if (elemtype->isa_valuetype()) { 4705 uint header = arrayOopDesc::base_offset_in_bytes(T_OBJECT); 4706 if (offset >= (intptr_t)header) { 4707 ciKlass* arytype_klass = klass(); 4708 ciValueArrayKlass* vak = arytype_klass->as_value_array_klass(); 4709 int shift = vak->log2_element_size(); 4710 intptr_t field_offset = ((offset - header) & ((1 << shift) - 1)); 4711 4712 return with_field_offset(field_offset)->add_offset(offset - field_offset); 4713 } 4714 } 4715 } 4716 return add_offset(offset); 4717 } 4718 4719 //============================================================================= 4720 4721 4722 //============================================================================= 4723 4724 const TypeValueTypePtr* TypeValueTypePtr::NOTNULL; 4725 //------------------------------make------------------------------------------- 4726 const TypeValueTypePtr* TypeValueTypePtr::make(const TypeValueType* vt, PTR ptr, ciObject* o, Offset offset, int instance_id, const TypePtr* speculative, int inline_depth) { 4727 return (TypeValueTypePtr*)(new TypeValueTypePtr(vt, ptr, o, offset, instance_id, speculative, inline_depth))->hashcons(); 4728 } 4729 4730 const TypePtr* TypeValueTypePtr::add_offset(intptr_t offset) const { 4731 return make(_vt, _ptr, _const_oop, Offset(offset), _instance_id, _speculative, _inline_depth); 4732 } 4733 4734 //------------------------------cast_to_ptr_type------------------------------- 4735 const Type* TypeValueTypePtr::cast_to_ptr_type(PTR ptr) const { 4736 if (ptr == _ptr) return this; 4737 return make(_vt, ptr, _const_oop, _offset, _instance_id, _speculative, _inline_depth); 4738 } 4739 4740 //-----------------------------cast_to_instance_id---------------------------- 4741 const TypeOopPtr* TypeValueTypePtr::cast_to_instance_id(int instance_id) const { 4742 if (instance_id == _instance_id) return this; 4743 return make(_vt, _ptr, _const_oop, _offset, instance_id, _speculative, _inline_depth); 4744 } 4745 4746 //------------------------------meet------------------------------------------- 4747 // Compute the MEET of two types. It returns a new Type object. 4748 const Type* TypeValueTypePtr::xmeet_helper(const Type* t) const { 4749 // Perform a fast test for common case; meeting the same types together. 4750 if (this == t) return this; // Meeting same type-rep? 4751 4752 switch (t->base()) { // switch on original type 4753 case Int: // Mixing ints & oops happens when javac 4754 case Long: // reuses local variables 4755 case FloatTop: 4756 case FloatCon: 4757 case FloatBot: 4758 case DoubleTop: 4759 case DoubleCon: 4760 case DoubleBot: 4761 case NarrowOop: 4762 case NarrowKlass: 4763 case MetadataPtr: 4764 case KlassPtr: 4765 case RawPtr: 4766 case AryPtr: 4767 case InstPtr: 4768 case Bottom: // Ye Olde Default 4769 return Type::BOTTOM; 4770 case Top: 4771 return this; 4772 4773 default: // All else is a mistake 4774 typerr(t); 4775 4776 case OopPtr: { 4777 // Found a OopPtr type vs self-ValueTypePtr type 4778 const TypeOopPtr* tp = t->is_oopptr(); 4779 Offset offset = meet_offset(tp->offset()); 4780 PTR ptr = meet_ptr(tp->ptr()); 4781 int instance_id = meet_instance_id(tp->instance_id()); 4782 const TypePtr* speculative = xmeet_speculative(tp); 4783 int depth = meet_inline_depth(tp->inline_depth()); 4784 switch (tp->ptr()) { 4785 case TopPTR: 4786 case AnyNull: { 4787 return make(_vt, ptr, NULL, offset, instance_id, speculative, depth); 4788 } 4789 case NotNull: 4790 case BotPTR: { 4791 return TypeOopPtr::make(ptr, offset, instance_id, speculative, depth); 4792 } 4793 default: typerr(t); 4794 } 4795 } 4796 4797 case AnyPtr: { 4798 // Found an AnyPtr type vs self-ValueTypePtr type 4799 const TypePtr* tp = t->is_ptr(); 4800 Offset offset = meet_offset(tp->offset()); 4801 PTR ptr = meet_ptr(tp->ptr()); 4802 int instance_id = meet_instance_id(InstanceTop); 4803 const TypePtr* speculative = xmeet_speculative(tp); 4804 int depth = meet_inline_depth(tp->inline_depth()); 4805 switch (tp->ptr()) { 4806 case Null: 4807 if( ptr == Null ) return TypePtr::make(AnyPtr, ptr, offset, speculative, depth); 4808 // else fall through to AnyNull 4809 case TopPTR: 4810 case AnyNull: { 4811 return make(_vt, ptr, NULL, offset, instance_id, speculative, depth); 4812 } 4813 case NotNull: 4814 case BotPTR: 4815 return TypePtr::make(AnyPtr, ptr, offset, speculative, depth); 4816 default: typerr(t); 4817 } 4818 } 4819 4820 case ValueTypePtr: { 4821 // Found an ValueTypePtr type vs self-ValueTypePtr type 4822 const TypeValueTypePtr* tp = t->is_valuetypeptr(); 4823 Offset offset = meet_offset(tp->offset()); 4824 PTR ptr = meet_ptr(tp->ptr()); 4825 int instance_id = meet_instance_id(InstanceTop); 4826 const TypePtr* speculative = xmeet_speculative(tp); 4827 int depth = meet_inline_depth(tp->inline_depth()); 4828 // Compute constant oop 4829 ciObject* o = NULL; 4830 ciObject* this_oop = const_oop(); 4831 ciObject* tp_oop = tp->const_oop(); 4832 const TypeValueType* vt = NULL; 4833 if (_vt != tp->_vt) { 4834 ciKlass* __value_klass = ciEnv::current()->___Value_klass(); 4835 assert(klass() == __value_klass || tp->klass() == __value_klass, "impossible meet"); 4836 if (above_centerline(ptr)) { 4837 vt = klass() == __value_klass ? tp->_vt : _vt; 4838 } else if (above_centerline(this->_ptr) && !above_centerline(tp->_ptr)) { 4839 vt = tp->_vt; 4840 } else if (above_centerline(tp->_ptr) && !above_centerline(this->_ptr)) { 4841 vt = _vt; 4842 } else { 4843 vt = klass() == __value_klass ? _vt : tp->_vt; 4844 } 4845 } else { 4846 vt = _vt; 4847 } 4848 if (ptr == Constant) { 4849 if (this_oop != NULL && tp_oop != NULL && 4850 this_oop->equals(tp_oop) ) { 4851 o = this_oop; 4852 } else if (above_centerline(this ->_ptr)) { 4853 o = tp_oop; 4854 } else if (above_centerline(tp ->_ptr)) { 4855 o = this_oop; 4856 } else { 4857 ptr = NotNull; 4858 } 4859 } 4860 return make(vt, ptr, o, offset, instance_id, speculative, depth); 4861 } 4862 } 4863 } 4864 4865 // Dual: compute field-by-field dual 4866 const Type* TypeValueTypePtr::xdual() const { 4867 return new TypeValueTypePtr(_vt, dual_ptr(), const_oop(), dual_offset(), dual_instance_id(), dual_speculative(), dual_inline_depth()); 4868 } 4869 4870 //------------------------------eq--------------------------------------------- 4871 // Structural equality check for Type representations 4872 bool TypeValueTypePtr::eq(const Type* t) const { 4873 const TypeValueTypePtr* p = t->is_valuetypeptr(); 4874 return _vt->eq(p->value_type()) && TypeOopPtr::eq(p); 4875 } 4876 4877 //------------------------------hash------------------------------------------- 4878 // Type-specific hashing function. 4879 int TypeValueTypePtr::hash(void) const { 4880 return java_add(_vt->hash(), TypeOopPtr::hash()); 4881 } 4882 4883 //------------------------------empty------------------------------------------ 4884 // TRUE if Type is a type with no values, FALSE otherwise. 4885 bool TypeValueTypePtr::empty(void) const { 4886 // FIXME 4887 return false; 4888 } 4889 4890 //------------------------------dump2------------------------------------------ 4891 #ifndef PRODUCT 4892 void TypeValueTypePtr::dump2(Dict &d, uint depth, outputStream *st) const { 4893 st->print("valuetype* "); 4894 klass()->print_name_on(st); 4895 st->print(":%s", ptr_msg[_ptr]); 4896 _offset.dump2(st); 4897 } 4898 #endif 4899 4900 //============================================================================= 4901 4902 //------------------------------hash------------------------------------------- 4903 // Type-specific hashing function. 4904 int TypeNarrowPtr::hash(void) const { 4905 return _ptrtype->hash() + 7; 4906 } 4907 4908 bool TypeNarrowPtr::singleton(void) const { // TRUE if type is a singleton 4909 return _ptrtype->singleton(); 4910 } 4911 4912 bool TypeNarrowPtr::empty(void) const { 4913 return _ptrtype->empty(); 4914 } 4915 4916 intptr_t TypeNarrowPtr::get_con() const { 4917 return _ptrtype->get_con(); 4918 } 4919 4920 bool TypeNarrowPtr::eq( const Type *t ) const { 4921 const TypeNarrowPtr* tc = isa_same_narrowptr(t); 4922 if (tc != NULL) { 4923 if (_ptrtype->base() != tc->_ptrtype->base()) { 4924 return false; 4925 } 4926 return tc->_ptrtype->eq(_ptrtype); 4927 } 4928 return false; 4929 } 4930 4931 const Type *TypeNarrowPtr::xdual() const { // Compute dual right now. 4932 const TypePtr* odual = _ptrtype->dual()->is_ptr(); 4933 return make_same_narrowptr(odual); 4934 } 4935 4936 4937 const Type *TypeNarrowPtr::filter_helper(const Type *kills, bool include_speculative) const { 4938 if (isa_same_narrowptr(kills)) { 4939 const Type* ft =_ptrtype->filter_helper(is_same_narrowptr(kills)->_ptrtype, include_speculative); 4940 if (ft->empty()) 4941 return Type::TOP; // Canonical empty value 4942 if (ft->isa_ptr()) { 4943 return make_hash_same_narrowptr(ft->isa_ptr()); 4944 } 4945 return ft; 4946 } else if (kills->isa_ptr()) { 4947 const Type* ft = _ptrtype->join_helper(kills, include_speculative); 4948 if (ft->empty()) 4949 return Type::TOP; // Canonical empty value 4950 return ft; 4951 } else { 4952 return Type::TOP; 4953 } 4954 } 4955 4956 //------------------------------xmeet------------------------------------------ 4957 // Compute the MEET of two types. It returns a new Type object. 4958 const Type *TypeNarrowPtr::xmeet( const Type *t ) const { 4959 // Perform a fast test for common case; meeting the same types together. 4960 if( this == t ) return this; // Meeting same type-rep? 4961 4962 if (t->base() == base()) { 4963 const Type* result = _ptrtype->xmeet(t->make_ptr()); 4964 if (result->isa_ptr()) { 4965 return make_hash_same_narrowptr(result->is_ptr()); 4966 } 4967 return result; 4968 } 4969 4970 // Current "this->_base" is NarrowKlass or NarrowOop 4971 switch (t->base()) { // switch on original type 4972 4973 case Int: // Mixing ints & oops happens when javac 4974 case Long: // reuses local variables 4975 case FloatTop: 4976 case FloatCon: 4977 case FloatBot: 4978 case DoubleTop: 4979 case DoubleCon: 4980 case DoubleBot: 4981 case AnyPtr: 4982 case RawPtr: 4983 case OopPtr: 4984 case InstPtr: 4985 case ValueTypePtr: 4986 case AryPtr: 4987 case MetadataPtr: 4988 case KlassPtr: 4989 case NarrowOop: 4990 case NarrowKlass: 4991 4992 case Bottom: // Ye Olde Default 4993 return Type::BOTTOM; 4994 case Top: 4995 return this; 4996 4997 default: // All else is a mistake 4998 typerr(t); 4999 5000 } // End of switch 5001 5002 return this; 5003 } 5004 5005 #ifndef PRODUCT 5006 void TypeNarrowPtr::dump2( Dict & d, uint depth, outputStream *st ) const { 5007 _ptrtype->dump2(d, depth, st); 5008 } 5009 #endif 5010 5011 const TypeNarrowOop *TypeNarrowOop::BOTTOM; 5012 const TypeNarrowOop *TypeNarrowOop::NULL_PTR; 5013 5014 5015 const TypeNarrowOop* TypeNarrowOop::make(const TypePtr* type) { 5016 return (const TypeNarrowOop*)(new TypeNarrowOop(type))->hashcons(); 5017 } 5018 5019 const Type* TypeNarrowOop::remove_speculative() const { 5020 return make(_ptrtype->remove_speculative()->is_ptr()); 5021 } 5022 5023 const Type* TypeNarrowOop::cleanup_speculative() const { 5024 return make(_ptrtype->cleanup_speculative()->is_ptr()); 5025 } 5026 5027 #ifndef PRODUCT 5028 void TypeNarrowOop::dump2( Dict & d, uint depth, outputStream *st ) const { 5029 st->print("narrowoop: "); 5030 TypeNarrowPtr::dump2(d, depth, st); 5031 } 5032 #endif 5033 5034 const TypeNarrowKlass *TypeNarrowKlass::NULL_PTR; 5035 5036 const TypeNarrowKlass* TypeNarrowKlass::make(const TypePtr* type) { 5037 return (const TypeNarrowKlass*)(new TypeNarrowKlass(type))->hashcons(); 5038 } 5039 5040 #ifndef PRODUCT 5041 void TypeNarrowKlass::dump2( Dict & d, uint depth, outputStream *st ) const { 5042 st->print("narrowklass: "); 5043 TypeNarrowPtr::dump2(d, depth, st); 5044 } 5045 #endif 5046 5047 5048 //------------------------------eq--------------------------------------------- 5049 // Structural equality check for Type representations 5050 bool TypeMetadataPtr::eq( const Type *t ) const { 5051 const TypeMetadataPtr *a = (const TypeMetadataPtr*)t; 5052 ciMetadata* one = metadata(); 5053 ciMetadata* two = a->metadata(); 5054 if (one == NULL || two == NULL) { 5055 return (one == two) && TypePtr::eq(t); 5056 } else { 5057 return one->equals(two) && TypePtr::eq(t); 5058 } 5059 } 5060 5061 //------------------------------hash------------------------------------------- 5062 // Type-specific hashing function. 5063 int TypeMetadataPtr::hash(void) const { 5064 return 5065 (metadata() ? metadata()->hash() : 0) + 5066 TypePtr::hash(); 5067 } 5068 5069 //------------------------------singleton-------------------------------------- 5070 // TRUE if Type is a singleton type, FALSE otherwise. Singletons are simple 5071 // constants 5072 bool TypeMetadataPtr::singleton(void) const { 5073 // detune optimizer to not generate constant metadata + constant offset as a constant! 5074 // TopPTR, Null, AnyNull, Constant are all singletons 5075 return (offset() == 0) && !below_centerline(_ptr); 5076 } 5077 5078 //------------------------------add_offset------------------------------------- 5079 const TypePtr *TypeMetadataPtr::add_offset( intptr_t offset ) const { 5080 return make( _ptr, _metadata, xadd_offset(offset)); 5081 } 5082 5083 //-----------------------------filter------------------------------------------ 5084 // Do not allow interface-vs.-noninterface joins to collapse to top. 5085 const Type *TypeMetadataPtr::filter_helper(const Type *kills, bool include_speculative) const { 5086 const TypeMetadataPtr* ft = join_helper(kills, include_speculative)->isa_metadataptr(); 5087 if (ft == NULL || ft->empty()) 5088 return Type::TOP; // Canonical empty value 5089 return ft; 5090 } 5091 5092 //------------------------------get_con---------------------------------------- 5093 intptr_t TypeMetadataPtr::get_con() const { 5094 assert( _ptr == Null || _ptr == Constant, "" ); 5095 assert(offset() >= 0, ""); 5096 5097 if (offset() != 0) { 5098 // After being ported to the compiler interface, the compiler no longer 5099 // directly manipulates the addresses of oops. Rather, it only has a pointer 5100 // to a handle at compile time. This handle is embedded in the generated 5101 // code and dereferenced at the time the nmethod is made. Until that time, 5102 // it is not reasonable to do arithmetic with the addresses of oops (we don't 5103 // have access to the addresses!). This does not seem to currently happen, 5104 // but this assertion here is to help prevent its occurence. 5105 tty->print_cr("Found oop constant with non-zero offset"); 5106 ShouldNotReachHere(); 5107 } 5108 5109 return (intptr_t)metadata()->constant_encoding(); 5110 } 5111 5112 //------------------------------cast_to_ptr_type------------------------------- 5113 const Type *TypeMetadataPtr::cast_to_ptr_type(PTR ptr) const { 5114 if( ptr == _ptr ) return this; 5115 return make(ptr, metadata(), _offset); 5116 } 5117 5118 //------------------------------meet------------------------------------------- 5119 // Compute the MEET of two types. It returns a new Type object. 5120 const Type *TypeMetadataPtr::xmeet( const Type *t ) const { 5121 // Perform a fast test for common case; meeting the same types together. 5122 if( this == t ) return this; // Meeting same type-rep? 5123 5124 // Current "this->_base" is OopPtr 5125 switch (t->base()) { // switch on original type 5126 5127 case Int: // Mixing ints & oops happens when javac 5128 case Long: // reuses local variables 5129 case FloatTop: 5130 case FloatCon: 5131 case FloatBot: 5132 case DoubleTop: 5133 case DoubleCon: 5134 case DoubleBot: 5135 case NarrowOop: 5136 case NarrowKlass: 5137 case Bottom: // Ye Olde Default 5138 return Type::BOTTOM; 5139 case Top: 5140 return this; 5141 5142 default: // All else is a mistake 5143 typerr(t); 5144 5145 case AnyPtr: { 5146 // Found an AnyPtr type vs self-OopPtr type 5147 const TypePtr *tp = t->is_ptr(); 5148 Offset offset = meet_offset(tp->offset()); 5149 PTR ptr = meet_ptr(tp->ptr()); 5150 switch (tp->ptr()) { 5151 case Null: 5152 if (ptr == Null) return TypePtr::make(AnyPtr, ptr, offset, tp->speculative(), tp->inline_depth()); 5153 // else fall through: 5154 case TopPTR: 5155 case AnyNull: { 5156 return make(ptr, _metadata, offset); 5157 } 5158 case BotPTR: 5159 case NotNull: 5160 return TypePtr::make(AnyPtr, ptr, offset, tp->speculative(), tp->inline_depth()); 5161 default: typerr(t); 5162 } 5163 } 5164 5165 case RawPtr: 5166 case KlassPtr: 5167 case OopPtr: 5168 case InstPtr: 5169 case ValueTypePtr: 5170 case AryPtr: 5171 return TypePtr::BOTTOM; // Oop meet raw is not well defined 5172 5173 case MetadataPtr: { 5174 const TypeMetadataPtr *tp = t->is_metadataptr(); 5175 Offset offset = meet_offset(tp->offset()); 5176 PTR tptr = tp->ptr(); 5177 PTR ptr = meet_ptr(tptr); 5178 ciMetadata* md = (tptr == TopPTR) ? metadata() : tp->metadata(); 5179 if (tptr == TopPTR || _ptr == TopPTR || 5180 metadata()->equals(tp->metadata())) { 5181 return make(ptr, md, offset); 5182 } 5183 // metadata is different 5184 if( ptr == Constant ) { // Cannot be equal constants, so... 5185 if( tptr == Constant && _ptr != Constant) return t; 5186 if( _ptr == Constant && tptr != Constant) return this; 5187 ptr = NotNull; // Fall down in lattice 5188 } 5189 return make(ptr, NULL, offset); 5190 break; 5191 } 5192 } // End of switch 5193 return this; // Return the double constant 5194 } 5195 5196 5197 //------------------------------xdual------------------------------------------ 5198 // Dual of a pure metadata pointer. 5199 const Type *TypeMetadataPtr::xdual() const { 5200 return new TypeMetadataPtr(dual_ptr(), metadata(), dual_offset()); 5201 } 5202 5203 //------------------------------dump2------------------------------------------ 5204 #ifndef PRODUCT 5205 void TypeMetadataPtr::dump2( Dict &d, uint depth, outputStream *st ) const { 5206 st->print("metadataptr:%s", ptr_msg[_ptr]); 5207 if( metadata() ) st->print(INTPTR_FORMAT, p2i(metadata())); 5208 switch (offset()) { 5209 case OffsetTop: st->print("+top"); break; 5210 case OffsetBot: st->print("+any"); break; 5211 case 0: break; 5212 default: st->print("+%d",offset()); break; 5213 } 5214 } 5215 #endif 5216 5217 5218 //============================================================================= 5219 // Convenience common pre-built type. 5220 const TypeMetadataPtr *TypeMetadataPtr::BOTTOM; 5221 5222 TypeMetadataPtr::TypeMetadataPtr(PTR ptr, ciMetadata* metadata, Offset offset): 5223 TypePtr(MetadataPtr, ptr, offset), _metadata(metadata) { 5224 } 5225 5226 const TypeMetadataPtr* TypeMetadataPtr::make(ciMethod* m) { 5227 return make(Constant, m, Offset(0)); 5228 } 5229 const TypeMetadataPtr* TypeMetadataPtr::make(ciMethodData* m) { 5230 return make(Constant, m, Offset(0)); 5231 } 5232 5233 //------------------------------make------------------------------------------- 5234 // Create a meta data constant 5235 const TypeMetadataPtr* TypeMetadataPtr::make(PTR ptr, ciMetadata* m, Offset offset) { 5236 assert(m == NULL || !m->is_klass(), "wrong type"); 5237 return (TypeMetadataPtr*)(new TypeMetadataPtr(ptr, m, offset))->hashcons(); 5238 } 5239 5240 5241 //============================================================================= 5242 // Convenience common pre-built types. 5243 5244 // Not-null object klass or below 5245 const TypeKlassPtr *TypeKlassPtr::OBJECT; 5246 const TypeKlassPtr *TypeKlassPtr::OBJECT_OR_NULL; 5247 5248 //------------------------------TypeKlassPtr----------------------------------- 5249 TypeKlassPtr::TypeKlassPtr( PTR ptr, ciKlass* klass, Offset offset ) 5250 : TypePtr(KlassPtr, ptr, offset), _klass(klass), _klass_is_exact(ptr == Constant) { 5251 } 5252 5253 //------------------------------make------------------------------------------- 5254 // ptr to klass 'k', if Constant, or possibly to a sub-klass if not a Constant 5255 const TypeKlassPtr* TypeKlassPtr::make(PTR ptr, ciKlass* k, Offset offset) { 5256 assert( k != NULL, "Expect a non-NULL klass"); 5257 assert(k->is_instance_klass() || k->is_array_klass(), "Incorrect type of klass oop"); 5258 TypeKlassPtr *r = 5259 (TypeKlassPtr*)(new TypeKlassPtr(ptr, k, offset))->hashcons(); 5260 5261 return r; 5262 } 5263 5264 //------------------------------eq--------------------------------------------- 5265 // Structural equality check for Type representations 5266 bool TypeKlassPtr::eq( const Type *t ) const { 5267 const TypeKlassPtr *p = t->is_klassptr(); 5268 return 5269 klass()->equals(p->klass()) && 5270 TypePtr::eq(p); 5271 } 5272 5273 //------------------------------hash------------------------------------------- 5274 // Type-specific hashing function. 5275 int TypeKlassPtr::hash(void) const { 5276 return java_add(klass()->hash(), TypePtr::hash()); 5277 } 5278 5279 //------------------------------singleton-------------------------------------- 5280 // TRUE if Type is a singleton type, FALSE otherwise. Singletons are simple 5281 // constants 5282 bool TypeKlassPtr::singleton(void) const { 5283 // detune optimizer to not generate constant klass + constant offset as a constant! 5284 // TopPTR, Null, AnyNull, Constant are all singletons 5285 return (offset() == 0) && !below_centerline(_ptr); 5286 } 5287 5288 // Do not allow interface-vs.-noninterface joins to collapse to top. 5289 const Type *TypeKlassPtr::filter_helper(const Type *kills, bool include_speculative) const { 5290 // logic here mirrors the one from TypeOopPtr::filter. See comments 5291 // there. 5292 const Type* ft = join_helper(kills, include_speculative); 5293 const TypeKlassPtr* ftkp = ft->isa_klassptr(); 5294 const TypeKlassPtr* ktkp = kills->isa_klassptr(); 5295 5296 if (ft->empty()) { 5297 if (!empty() && ktkp != NULL && ktkp->klass()->is_loaded() && ktkp->klass()->is_interface()) 5298 return kills; // Uplift to interface 5299 5300 return Type::TOP; // Canonical empty value 5301 } 5302 5303 // Interface klass type could be exact in opposite to interface type, 5304 // return it here instead of incorrect Constant ptr J/L/Object (6894807). 5305 if (ftkp != NULL && ktkp != NULL && 5306 ftkp->is_loaded() && ftkp->klass()->is_interface() && 5307 !ftkp->klass_is_exact() && // Keep exact interface klass 5308 ktkp->is_loaded() && !ktkp->klass()->is_interface()) { 5309 return ktkp->cast_to_ptr_type(ftkp->ptr()); 5310 } 5311 5312 return ft; 5313 } 5314 5315 //----------------------compute_klass------------------------------------------ 5316 // Compute the defining klass for this class 5317 ciKlass* TypeAryPtr::compute_klass(DEBUG_ONLY(bool verify)) const { 5318 // Compute _klass based on element type. 5319 ciKlass* k_ary = NULL; 5320 const TypeAryPtr *tary; 5321 const Type* el = elem(); 5322 if (el->isa_narrowoop()) { 5323 el = el->make_ptr(); 5324 } 5325 5326 // Get element klass 5327 if (el->isa_instptr() || el->isa_valuetypeptr()) { 5328 // Compute object array klass from element klass 5329 k_ary = ciArrayKlass::make(el->is_oopptr()->klass()); 5330 } else if (el->isa_valuetype()) { 5331 k_ary = ciArrayKlass::make(el->is_valuetype()->value_klass()); 5332 } else if ((tary = el->isa_aryptr()) != NULL) { 5333 // Compute array klass from element klass 5334 ciKlass* k_elem = tary->klass(); 5335 // If element type is something like bottom[], k_elem will be null. 5336 if (k_elem != NULL) 5337 k_ary = ciObjArrayKlass::make(k_elem); 5338 } else if ((el->base() == Type::Top) || 5339 (el->base() == Type::Bottom)) { 5340 // element type of Bottom occurs from meet of basic type 5341 // and object; Top occurs when doing join on Bottom. 5342 // Leave k_ary at NULL. 5343 } else { 5344 // Cannot compute array klass directly from basic type, 5345 // since subtypes of TypeInt all have basic type T_INT. 5346 #ifdef ASSERT 5347 if (verify && el->isa_int()) { 5348 // Check simple cases when verifying klass. 5349 BasicType bt = T_ILLEGAL; 5350 if (el == TypeInt::BYTE) { 5351 bt = T_BYTE; 5352 } else if (el == TypeInt::SHORT) { 5353 bt = T_SHORT; 5354 } else if (el == TypeInt::CHAR) { 5355 bt = T_CHAR; 5356 } else if (el == TypeInt::INT) { 5357 bt = T_INT; 5358 } else { 5359 return _klass; // just return specified klass 5360 } 5361 return ciTypeArrayKlass::make(bt); 5362 } 5363 #endif 5364 assert(!el->isa_int(), 5365 "integral arrays must be pre-equipped with a class"); 5366 // Compute array klass directly from basic type 5367 k_ary = ciTypeArrayKlass::make(el->basic_type()); 5368 } 5369 return k_ary; 5370 } 5371 5372 //------------------------------klass------------------------------------------ 5373 // Return the defining klass for this class 5374 ciKlass* TypeAryPtr::klass() const { 5375 if( _klass ) return _klass; // Return cached value, if possible 5376 5377 // Oops, need to compute _klass and cache it 5378 ciKlass* k_ary = compute_klass(); 5379 5380 if( this != TypeAryPtr::OOPS && this->dual() != TypeAryPtr::OOPS ) { 5381 // The _klass field acts as a cache of the underlying 5382 // ciKlass for this array type. In order to set the field, 5383 // we need to cast away const-ness. 5384 // 5385 // IMPORTANT NOTE: we *never* set the _klass field for the 5386 // type TypeAryPtr::OOPS. This Type is shared between all 5387 // active compilations. However, the ciKlass which represents 5388 // this Type is *not* shared between compilations, so caching 5389 // this value would result in fetching a dangling pointer. 5390 // 5391 // Recomputing the underlying ciKlass for each request is 5392 // a bit less efficient than caching, but calls to 5393 // TypeAryPtr::OOPS->klass() are not common enough to matter. 5394 ((TypeAryPtr*)this)->_klass = k_ary; 5395 if (UseCompressedOops && k_ary != NULL && k_ary->is_obj_array_klass() && 5396 offset() != 0 && offset() != arrayOopDesc::length_offset_in_bytes()) { 5397 ((TypeAryPtr*)this)->_is_ptr_to_narrowoop = true; 5398 } 5399 } 5400 return k_ary; 5401 } 5402 5403 5404 //------------------------------add_offset------------------------------------- 5405 // Access internals of klass object 5406 const TypePtr *TypeKlassPtr::add_offset( intptr_t offset ) const { 5407 return make( _ptr, klass(), xadd_offset(offset) ); 5408 } 5409 5410 //------------------------------cast_to_ptr_type------------------------------- 5411 const Type *TypeKlassPtr::cast_to_ptr_type(PTR ptr) const { 5412 assert(_base == KlassPtr, "subclass must override cast_to_ptr_type"); 5413 if( ptr == _ptr ) return this; 5414 return make(ptr, _klass, _offset); 5415 } 5416 5417 5418 //-----------------------------cast_to_exactness------------------------------- 5419 const Type *TypeKlassPtr::cast_to_exactness(bool klass_is_exact) const { 5420 if( klass_is_exact == _klass_is_exact ) return this; 5421 if (!UseExactTypes) return this; 5422 return make(klass_is_exact ? Constant : NotNull, _klass, _offset); 5423 } 5424 5425 5426 //-----------------------------as_instance_type-------------------------------- 5427 // Corresponding type for an instance of the given class. 5428 // It will be NotNull, and exact if and only if the klass type is exact. 5429 const TypeOopPtr* TypeKlassPtr::as_instance_type() const { 5430 ciKlass* k = klass(); 5431 bool xk = klass_is_exact(); 5432 //return TypeInstPtr::make(TypePtr::NotNull, k, xk, NULL, 0); 5433 const TypeOopPtr* toop = TypeOopPtr::make_from_klass_raw(k); 5434 guarantee(toop != NULL, "need type for given klass"); 5435 toop = toop->cast_to_ptr_type(TypePtr::NotNull)->is_oopptr(); 5436 return toop->cast_to_exactness(xk)->is_oopptr(); 5437 } 5438 5439 5440 //------------------------------xmeet------------------------------------------ 5441 // Compute the MEET of two types, return a new Type object. 5442 const Type *TypeKlassPtr::xmeet( const Type *t ) const { 5443 // Perform a fast test for common case; meeting the same types together. 5444 if( this == t ) return this; // Meeting same type-rep? 5445 5446 // Current "this->_base" is Pointer 5447 switch (t->base()) { // switch on original type 5448 5449 case Int: // Mixing ints & oops happens when javac 5450 case Long: // reuses local variables 5451 case FloatTop: 5452 case FloatCon: 5453 case FloatBot: 5454 case DoubleTop: 5455 case DoubleCon: 5456 case DoubleBot: 5457 case NarrowOop: 5458 case NarrowKlass: 5459 case Bottom: // Ye Olde Default 5460 return Type::BOTTOM; 5461 case Top: 5462 return this; 5463 5464 default: // All else is a mistake 5465 typerr(t); 5466 5467 case AnyPtr: { // Meeting to AnyPtrs 5468 // Found an AnyPtr type vs self-KlassPtr type 5469 const TypePtr *tp = t->is_ptr(); 5470 Offset offset = meet_offset(tp->offset()); 5471 PTR ptr = meet_ptr(tp->ptr()); 5472 switch (tp->ptr()) { 5473 case TopPTR: 5474 return this; 5475 case Null: 5476 if( ptr == Null ) return TypePtr::make(AnyPtr, ptr, offset, tp->speculative(), tp->inline_depth()); 5477 case AnyNull: 5478 return make( ptr, klass(), offset ); 5479 case BotPTR: 5480 case NotNull: 5481 return TypePtr::make(AnyPtr, ptr, offset, tp->speculative(), tp->inline_depth()); 5482 default: typerr(t); 5483 } 5484 } 5485 5486 case RawPtr: 5487 case MetadataPtr: 5488 case OopPtr: 5489 case AryPtr: // Meet with AryPtr 5490 case InstPtr: // Meet with InstPtr 5491 case ValueTypePtr: 5492 return TypePtr::BOTTOM; 5493 5494 // 5495 // A-top } 5496 // / | \ } Tops 5497 // B-top A-any C-top } 5498 // | / | \ | } Any-nulls 5499 // B-any | C-any } 5500 // | | | 5501 // B-con A-con C-con } constants; not comparable across classes 5502 // | | | 5503 // B-not | C-not } 5504 // | \ | / | } not-nulls 5505 // B-bot A-not C-bot } 5506 // \ | / } Bottoms 5507 // A-bot } 5508 // 5509 5510 case KlassPtr: { // Meet two KlassPtr types 5511 const TypeKlassPtr *tkls = t->is_klassptr(); 5512 Offset off = meet_offset(tkls->offset()); 5513 PTR ptr = meet_ptr(tkls->ptr()); 5514 5515 // Check for easy case; klasses are equal (and perhaps not loaded!) 5516 // If we have constants, then we created oops so classes are loaded 5517 // and we can handle the constants further down. This case handles 5518 // not-loaded classes 5519 if( ptr != Constant && tkls->klass()->equals(klass()) ) { 5520 return make( ptr, klass(), off ); 5521 } 5522 5523 // Classes require inspection in the Java klass hierarchy. Must be loaded. 5524 ciKlass* tkls_klass = tkls->klass(); 5525 ciKlass* this_klass = this->klass(); 5526 assert( tkls_klass->is_loaded(), "This class should have been loaded."); 5527 assert( this_klass->is_loaded(), "This class should have been loaded."); 5528 5529 // If 'this' type is above the centerline and is a superclass of the 5530 // other, we can treat 'this' as having the same type as the other. 5531 if ((above_centerline(this->ptr())) && 5532 tkls_klass->is_subtype_of(this_klass)) { 5533 this_klass = tkls_klass; 5534 } 5535 // If 'tinst' type is above the centerline and is a superclass of the 5536 // other, we can treat 'tinst' as having the same type as the other. 5537 if ((above_centerline(tkls->ptr())) && 5538 this_klass->is_subtype_of(tkls_klass)) { 5539 tkls_klass = this_klass; 5540 } 5541 5542 // Check for classes now being equal 5543 if (tkls_klass->equals(this_klass)) { 5544 // If the klasses are equal, the constants may still differ. Fall to 5545 // NotNull if they do (neither constant is NULL; that is a special case 5546 // handled elsewhere). 5547 if( ptr == Constant ) { 5548 if (this->_ptr == Constant && tkls->_ptr == Constant && 5549 this->klass()->equals(tkls->klass())); 5550 else if (above_centerline(this->ptr())); 5551 else if (above_centerline(tkls->ptr())); 5552 else 5553 ptr = NotNull; 5554 } 5555 return make( ptr, this_klass, off ); 5556 } // Else classes are not equal 5557 5558 // Since klasses are different, we require the LCA in the Java 5559 // class hierarchy - which means we have to fall to at least NotNull. 5560 if( ptr == TopPTR || ptr == AnyNull || ptr == Constant ) 5561 ptr = NotNull; 5562 // Now we find the LCA of Java classes 5563 ciKlass* k = this_klass->least_common_ancestor(tkls_klass); 5564 return make( ptr, k, off ); 5565 } // End of case KlassPtr 5566 5567 } // End of switch 5568 return this; // Return the double constant 5569 } 5570 5571 //------------------------------xdual------------------------------------------ 5572 // Dual: compute field-by-field dual 5573 const Type *TypeKlassPtr::xdual() const { 5574 return new TypeKlassPtr( dual_ptr(), klass(), dual_offset() ); 5575 } 5576 5577 //------------------------------get_con---------------------------------------- 5578 intptr_t TypeKlassPtr::get_con() const { 5579 assert( _ptr == Null || _ptr == Constant, "" ); 5580 assert(offset() >= 0, ""); 5581 5582 if (offset() != 0) { 5583 // After being ported to the compiler interface, the compiler no longer 5584 // directly manipulates the addresses of oops. Rather, it only has a pointer 5585 // to a handle at compile time. This handle is embedded in the generated 5586 // code and dereferenced at the time the nmethod is made. Until that time, 5587 // it is not reasonable to do arithmetic with the addresses of oops (we don't 5588 // have access to the addresses!). This does not seem to currently happen, 5589 // but this assertion here is to help prevent its occurence. 5590 tty->print_cr("Found oop constant with non-zero offset"); 5591 ShouldNotReachHere(); 5592 } 5593 5594 return (intptr_t)klass()->constant_encoding(); 5595 } 5596 //------------------------------dump2------------------------------------------ 5597 // Dump Klass Type 5598 #ifndef PRODUCT 5599 void TypeKlassPtr::dump2( Dict & d, uint depth, outputStream *st ) const { 5600 switch( _ptr ) { 5601 case Constant: 5602 st->print("precise "); 5603 case NotNull: 5604 { 5605 const char *name = klass()->name()->as_utf8(); 5606 if( name ) { 5607 st->print("klass %s: " INTPTR_FORMAT, name, p2i(klass())); 5608 } else { 5609 ShouldNotReachHere(); 5610 } 5611 } 5612 case BotPTR: 5613 if( !WizardMode && !Verbose && !_klass_is_exact ) break; 5614 case TopPTR: 5615 case AnyNull: 5616 st->print(":%s", ptr_msg[_ptr]); 5617 if( _klass_is_exact ) st->print(":exact"); 5618 break; 5619 } 5620 5621 _offset.dump2(st); 5622 5623 st->print(" *"); 5624 } 5625 #endif 5626 5627 5628 5629 //============================================================================= 5630 // Convenience common pre-built types. 5631 5632 //------------------------------make------------------------------------------- 5633 const TypeFunc *TypeFunc::make(const TypeTuple *domain_sig, const TypeTuple* domain_cc, 5634 const TypeTuple *range_sig, const TypeTuple *range_cc) { 5635 return (TypeFunc*)(new TypeFunc(domain_sig, domain_cc, range_sig, range_cc))->hashcons(); 5636 } 5637 5638 const TypeFunc *TypeFunc::make(const TypeTuple *domain, const TypeTuple *range) { 5639 return make(domain, domain, range, range); 5640 } 5641 5642 //------------------------------make------------------------------------------- 5643 const TypeFunc *TypeFunc::make(ciMethod* method) { 5644 Compile* C = Compile::current(); 5645 const TypeFunc* tf = C->last_tf(method); // check cache 5646 if (tf != NULL) return tf; // The hit rate here is almost 50%. 5647 const TypeTuple *domain_sig, *domain_cc; 5648 // Value type arguments are not passed by reference, instead each 5649 // field of the value type is passed as an argument. We maintain 2 5650 // views of the argument list here: one based on the signature (with 5651 // a value type argument as a single slot), one based on the actual 5652 // calling convention (with a value type argument as a list of its 5653 // fields). 5654 if (method->is_static()) { 5655 domain_sig = TypeTuple::make_domain(NULL, method->signature(), false); 5656 domain_cc = TypeTuple::make_domain(NULL, method->signature(), ValueTypePassFieldsAsArgs); 5657 } else { 5658 domain_sig = TypeTuple::make_domain(method->holder(), method->signature(), false); 5659 domain_cc = TypeTuple::make_domain(method->holder(), method->signature(), ValueTypePassFieldsAsArgs); 5660 } 5661 const TypeTuple *range_sig = TypeTuple::make_range(method->signature(), false); 5662 const TypeTuple *range_cc = TypeTuple::make_range(method->signature(), ValueTypeReturnedAsFields); 5663 tf = TypeFunc::make(domain_sig, domain_cc, range_sig, range_cc); 5664 C->set_last_tf(method, tf); // fill cache 5665 return tf; 5666 } 5667 5668 //------------------------------meet------------------------------------------- 5669 // Compute the MEET of two types. It returns a new Type object. 5670 const Type *TypeFunc::xmeet( const Type *t ) const { 5671 // Perform a fast test for common case; meeting the same types together. 5672 if( this == t ) return this; // Meeting same type-rep? 5673 5674 // Current "this->_base" is Func 5675 switch (t->base()) { // switch on original type 5676 5677 case Bottom: // Ye Olde Default 5678 return t; 5679 5680 default: // All else is a mistake 5681 typerr(t); 5682 5683 case Top: 5684 break; 5685 } 5686 return this; // Return the double constant 5687 } 5688 5689 //------------------------------xdual------------------------------------------ 5690 // Dual: compute field-by-field dual 5691 const Type *TypeFunc::xdual() const { 5692 return this; 5693 } 5694 5695 //------------------------------eq--------------------------------------------- 5696 // Structural equality check for Type representations 5697 bool TypeFunc::eq( const Type *t ) const { 5698 const TypeFunc *a = (const TypeFunc*)t; 5699 return _domain_sig == a->_domain_sig && 5700 _domain_cc == a->_domain_cc && 5701 _range_sig == a->_range_sig && 5702 _range_cc == a->_range_cc; 5703 } 5704 5705 //------------------------------hash------------------------------------------- 5706 // Type-specific hashing function. 5707 int TypeFunc::hash(void) const { 5708 return (intptr_t)_domain_sig + (intptr_t)_domain_cc + (intptr_t)_range_sig + (intptr_t)_range_cc; 5709 } 5710 5711 //------------------------------dump2------------------------------------------ 5712 // Dump Function Type 5713 #ifndef PRODUCT 5714 void TypeFunc::dump2( Dict &d, uint depth, outputStream *st ) const { 5715 if( _range_sig->cnt() <= Parms ) 5716 st->print("void"); 5717 else { 5718 uint i; 5719 for (i = Parms; i < _range_sig->cnt()-1; i++) { 5720 _range_sig->field_at(i)->dump2(d,depth,st); 5721 st->print("/"); 5722 } 5723 _range_sig->field_at(i)->dump2(d,depth,st); 5724 } 5725 st->print(" "); 5726 st->print("( "); 5727 if( !depth || d[this] ) { // Check for recursive dump 5728 st->print("...)"); 5729 return; 5730 } 5731 d.Insert((void*)this,(void*)this); // Stop recursion 5732 if (Parms < _domain_sig->cnt()) 5733 _domain_sig->field_at(Parms)->dump2(d,depth-1,st); 5734 for (uint i = Parms+1; i < _domain_sig->cnt(); i++) { 5735 st->print(", "); 5736 _domain_sig->field_at(i)->dump2(d,depth-1,st); 5737 } 5738 st->print(" )"); 5739 } 5740 #endif 5741 5742 //------------------------------singleton-------------------------------------- 5743 // TRUE if Type is a singleton type, FALSE otherwise. Singletons are simple 5744 // constants (Ldi nodes). Singletons are integer, float or double constants 5745 // or a single symbol. 5746 bool TypeFunc::singleton(void) const { 5747 return false; // Never a singleton 5748 } 5749 5750 bool TypeFunc::empty(void) const { 5751 return false; // Never empty 5752 } 5753 5754 5755 BasicType TypeFunc::return_type() const{ 5756 if (range_sig()->cnt() == TypeFunc::Parms) { 5757 return T_VOID; 5758 } 5759 return range_sig()->field_at(TypeFunc::Parms)->basic_type(); 5760 }