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