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