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