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