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