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