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(ciMethod* method, bool ret_vt_fields) { 1940 ciSignature* sig = method->signature(); 1941 ciType* return_type = sig->return_type(); 1942 return make_range(method, return_type, ret_vt_fields); 1943 } 1944 1945 const TypeTuple *TypeTuple::make_range(ciMethod* method, ciType* return_type, bool ret_vt_fields) { 1946 uint arg_cnt = 0; 1947 if (ret_vt_fields) { 1948 ret_vt_fields = return_type->is_valuetype() && ((ciValueKlass*)return_type)->can_be_returned_as_fields(); 1949 } 1950 if (ret_vt_fields) { 1951 ciValueKlass* vk = (ciValueKlass*)return_type; 1952 arg_cnt = vk->value_arg_slots()+1; 1953 } else { 1954 arg_cnt = return_type->size(); 1955 } 1956 1957 const Type **field_array = fields(arg_cnt); 1958 switch (return_type->basic_type()) { 1959 case T_LONG: 1960 field_array[TypeFunc::Parms] = TypeLong::LONG; 1961 field_array[TypeFunc::Parms+1] = Type::HALF; 1962 break; 1963 case T_DOUBLE: 1964 field_array[TypeFunc::Parms] = Type::DOUBLE; 1965 field_array[TypeFunc::Parms+1] = Type::HALF; 1966 break; 1967 case T_OBJECT: 1968 case T_ARRAY: 1969 case T_BOOLEAN: 1970 case T_CHAR: 1971 case T_FLOAT: 1972 case T_BYTE: 1973 case T_SHORT: 1974 case T_INT: 1975 field_array[TypeFunc::Parms] = get_const_type(return_type); 1976 break; 1977 case T_VALUETYPE: 1978 if (ret_vt_fields) { 1979 ciValueKlass* vk = (ciValueKlass*)return_type; 1980 uint pos = TypeFunc::Parms; 1981 field_array[pos] = TypePtr::BOTTOM; 1982 pos++; 1983 collect_value_fields(vk, field_array, pos); 1984 } else { 1985 if (method->get_Method()->is_returning_vt()) { 1986 // A NULL ValueType cannot be returned to compiled code. The 'areturn' bytecode 1987 // handler will deoptimize its caller if it is about to return a NULL ValueType. 1988 field_array[TypeFunc::Parms] = get_const_type(return_type)->join_speculative(TypePtr::NOTNULL); 1989 } else { 1990 // We're calling a legacy class's method that is returning a VT but doesn't know about it, so 1991 // it won't do the deoptimization at 'areturn'. 1992 field_array[TypeFunc::Parms] = get_const_type(return_type); 1993 } 1994 } 1995 break; 1996 case T_VOID: 1997 break; 1998 default: 1999 ShouldNotReachHere(); 2000 } 2001 return (TypeTuple*)(new TypeTuple(TypeFunc::Parms + arg_cnt, field_array))->hashcons(); 2002 } 2003 2004 // Make a TypeTuple from the domain of a method signature 2005 const TypeTuple *TypeTuple::make_domain(ciInstanceKlass* recv, ciSignature* sig, bool vt_fields_as_args) { 2006 uint arg_cnt = sig->size(); 2007 2008 int vt_extra = 0; 2009 if (vt_fields_as_args) { 2010 for (int i = 0; i < sig->count(); i++) { 2011 ciType* type = sig->type_at(i); 2012 if (type->basic_type() == T_VALUETYPE) { 2013 assert(type->is_valuetype(), "inconsistent type"); 2014 ciValueKlass* vk = (ciValueKlass*)type; 2015 vt_extra += vk->value_arg_slots()-1; 2016 } 2017 } 2018 assert(((int)arg_cnt) + vt_extra >= 0, "negative number of actual arguments?"); 2019 } 2020 2021 uint pos = TypeFunc::Parms; 2022 const Type **field_array; 2023 if (recv != NULL) { 2024 arg_cnt++; 2025 bool vt_fields_for_recv = vt_fields_as_args && recv->is_valuetype(); 2026 if (vt_fields_for_recv) { 2027 ciValueKlass* vk = (ciValueKlass*)recv; 2028 vt_extra += vk->value_arg_slots()-1; 2029 } 2030 field_array = fields(arg_cnt + vt_extra); 2031 // Use get_const_type here because it respects UseUniqueSubclasses: 2032 if (vt_fields_for_recv) { 2033 ciValueKlass* vk = (ciValueKlass*)recv; 2034 collect_value_fields(vk, field_array, pos); 2035 } else { 2036 field_array[pos++] = get_const_type(recv)->join_speculative(TypePtr::NOTNULL); 2037 } 2038 } else { 2039 field_array = fields(arg_cnt + vt_extra); 2040 } 2041 2042 int i = 0; 2043 while (pos < TypeFunc::Parms + arg_cnt + vt_extra) { 2044 ciType* type = sig->type_at(i); 2045 2046 switch (type->basic_type()) { 2047 case T_LONG: 2048 field_array[pos++] = TypeLong::LONG; 2049 field_array[pos++] = Type::HALF; 2050 break; 2051 case T_DOUBLE: 2052 field_array[pos++] = Type::DOUBLE; 2053 field_array[pos++] = Type::HALF; 2054 break; 2055 case T_OBJECT: 2056 case T_ARRAY: 2057 case T_FLOAT: 2058 case T_INT: 2059 field_array[pos++] = get_const_type(type); 2060 break; 2061 case T_BOOLEAN: 2062 case T_CHAR: 2063 case T_BYTE: 2064 case T_SHORT: 2065 field_array[pos++] = TypeInt::INT; 2066 break; 2067 case T_VALUETYPE: { 2068 assert(type->is_valuetype(), "inconsistent type"); 2069 if (vt_fields_as_args) { 2070 ciValueKlass* vk = (ciValueKlass*)type; 2071 collect_value_fields(vk, field_array, pos); 2072 } else { 2073 // Value types arguments cannot be NULL 2074 //field_array[pos++] = get_const_type(type)->join_speculative(TypePtr::NOTNULL); 2075 field_array[pos++] = get_const_type(type); 2076 } 2077 break; 2078 } 2079 default: 2080 ShouldNotReachHere(); 2081 } 2082 i++; 2083 } 2084 assert(pos == TypeFunc::Parms + arg_cnt + vt_extra, "wrong number of arguments"); 2085 2086 return (TypeTuple*)(new TypeTuple(TypeFunc::Parms + arg_cnt + vt_extra, field_array))->hashcons(); 2087 } 2088 2089 const TypeTuple *TypeTuple::make( uint cnt, const Type **fields ) { 2090 return (TypeTuple*)(new TypeTuple(cnt,fields))->hashcons(); 2091 } 2092 2093 //------------------------------fields----------------------------------------- 2094 // Subroutine call type with space allocated for argument types 2095 // Memory for Control, I_O, Memory, FramePtr, and ReturnAdr is allocated implicitly 2096 const Type **TypeTuple::fields( uint arg_cnt ) { 2097 const Type **flds = (const Type **)(Compile::current()->type_arena()->Amalloc_4((TypeFunc::Parms+arg_cnt)*sizeof(Type*) )); 2098 flds[TypeFunc::Control ] = Type::CONTROL; 2099 flds[TypeFunc::I_O ] = Type::ABIO; 2100 flds[TypeFunc::Memory ] = Type::MEMORY; 2101 flds[TypeFunc::FramePtr ] = TypeRawPtr::BOTTOM; 2102 flds[TypeFunc::ReturnAdr] = Type::RETURN_ADDRESS; 2103 2104 return flds; 2105 } 2106 2107 //------------------------------meet------------------------------------------- 2108 // Compute the MEET of two types. It returns a new Type object. 2109 const Type *TypeTuple::xmeet( const Type *t ) const { 2110 // Perform a fast test for common case; meeting the same types together. 2111 if( this == t ) return this; // Meeting same type-rep? 2112 2113 // Current "this->_base" is Tuple 2114 switch (t->base()) { // switch on original type 2115 2116 case Bottom: // Ye Olde Default 2117 return t; 2118 2119 default: // All else is a mistake 2120 typerr(t); 2121 2122 case Tuple: { // Meeting 2 signatures? 2123 const TypeTuple *x = t->is_tuple(); 2124 assert( _cnt == x->_cnt, "" ); 2125 const Type **fields = (const Type **)(Compile::current()->type_arena()->Amalloc_4( _cnt*sizeof(Type*) )); 2126 for( uint i=0; i<_cnt; i++ ) 2127 fields[i] = field_at(i)->xmeet( x->field_at(i) ); 2128 return TypeTuple::make(_cnt,fields); 2129 } 2130 case Top: 2131 break; 2132 } 2133 return this; // Return the double constant 2134 } 2135 2136 //------------------------------xdual------------------------------------------ 2137 // Dual: compute field-by-field dual 2138 const Type *TypeTuple::xdual() const { 2139 const Type **fields = (const Type **)(Compile::current()->type_arena()->Amalloc_4( _cnt*sizeof(Type*) )); 2140 for( uint i=0; i<_cnt; i++ ) 2141 fields[i] = _fields[i]->dual(); 2142 return new TypeTuple(_cnt,fields); 2143 } 2144 2145 //------------------------------eq--------------------------------------------- 2146 // Structural equality check for Type representations 2147 bool TypeTuple::eq( const Type *t ) const { 2148 const TypeTuple *s = (const TypeTuple *)t; 2149 if (_cnt != s->_cnt) return false; // Unequal field counts 2150 for (uint i = 0; i < _cnt; i++) 2151 if (field_at(i) != s->field_at(i)) // POINTER COMPARE! NO RECURSION! 2152 return false; // Missed 2153 return true; 2154 } 2155 2156 //------------------------------hash------------------------------------------- 2157 // Type-specific hashing function. 2158 int TypeTuple::hash(void) const { 2159 intptr_t sum = _cnt; 2160 for( uint i=0; i<_cnt; i++ ) 2161 sum += (intptr_t)_fields[i]; // Hash on pointers directly 2162 return sum; 2163 } 2164 2165 //------------------------------dump2------------------------------------------ 2166 // Dump signature Type 2167 #ifndef PRODUCT 2168 void TypeTuple::dump2( Dict &d, uint depth, outputStream *st ) const { 2169 st->print("{"); 2170 if( !depth || d[this] ) { // Check for recursive print 2171 st->print("...}"); 2172 return; 2173 } 2174 d.Insert((void*)this, (void*)this); // Stop recursion 2175 if( _cnt ) { 2176 uint i; 2177 for( i=0; i<_cnt-1; i++ ) { 2178 st->print("%d:", i); 2179 _fields[i]->dump2(d, depth-1, st); 2180 st->print(", "); 2181 } 2182 st->print("%d:", i); 2183 _fields[i]->dump2(d, depth-1, st); 2184 } 2185 st->print("}"); 2186 } 2187 #endif 2188 2189 //------------------------------singleton-------------------------------------- 2190 // TRUE if Type is a singleton type, FALSE otherwise. Singletons are simple 2191 // constants (Ldi nodes). Singletons are integer, float or double constants 2192 // or a single symbol. 2193 bool TypeTuple::singleton(void) const { 2194 return false; // Never a singleton 2195 } 2196 2197 bool TypeTuple::empty(void) const { 2198 for( uint i=0; i<_cnt; i++ ) { 2199 if (_fields[i]->empty()) return true; 2200 } 2201 return false; 2202 } 2203 2204 //============================================================================= 2205 // Convenience common pre-built types. 2206 2207 inline const TypeInt* normalize_array_size(const TypeInt* size) { 2208 // Certain normalizations keep us sane when comparing types. 2209 // We do not want arrayOop variables to differ only by the wideness 2210 // of their index types. Pick minimum wideness, since that is the 2211 // forced wideness of small ranges anyway. 2212 if (size->_widen != Type::WidenMin) 2213 return TypeInt::make(size->_lo, size->_hi, Type::WidenMin); 2214 else 2215 return size; 2216 } 2217 2218 //------------------------------make------------------------------------------- 2219 const TypeAry* TypeAry::make(const Type* elem, const TypeInt* size, bool stable) { 2220 if (elem->is_valuetypeptr()) { 2221 // Value type array elements cannot be NULL 2222 elem = elem->join_speculative(TypePtr::NOTNULL)->is_oopptr(); 2223 } 2224 if (UseCompressedOops && elem->isa_oopptr()) { 2225 elem = elem->make_narrowoop(); 2226 } 2227 size = normalize_array_size(size); 2228 return (TypeAry*)(new TypeAry(elem,size,stable))->hashcons(); 2229 } 2230 2231 //------------------------------meet------------------------------------------- 2232 // Compute the MEET of two types. It returns a new Type object. 2233 const Type *TypeAry::xmeet( const Type *t ) const { 2234 // Perform a fast test for common case; meeting the same types together. 2235 if( this == t ) return this; // Meeting same type-rep? 2236 2237 // Current "this->_base" is Ary 2238 switch (t->base()) { // switch on original type 2239 2240 case Bottom: // Ye Olde Default 2241 return t; 2242 2243 default: // All else is a mistake 2244 typerr(t); 2245 2246 case Array: { // Meeting 2 arrays? 2247 const TypeAry *a = t->is_ary(); 2248 return TypeAry::make(_elem->meet_speculative(a->_elem), 2249 _size->xmeet(a->_size)->is_int(), 2250 _stable & a->_stable); 2251 } 2252 case Top: 2253 break; 2254 } 2255 return this; // Return the double constant 2256 } 2257 2258 //------------------------------xdual------------------------------------------ 2259 // Dual: compute field-by-field dual 2260 const Type *TypeAry::xdual() const { 2261 const TypeInt* size_dual = _size->dual()->is_int(); 2262 size_dual = normalize_array_size(size_dual); 2263 return new TypeAry(_elem->dual(), size_dual, !_stable); 2264 } 2265 2266 //------------------------------eq--------------------------------------------- 2267 // Structural equality check for Type representations 2268 bool TypeAry::eq( const Type *t ) const { 2269 const TypeAry *a = (const TypeAry*)t; 2270 return _elem == a->_elem && 2271 _stable == a->_stable && 2272 _size == a->_size; 2273 } 2274 2275 //------------------------------hash------------------------------------------- 2276 // Type-specific hashing function. 2277 int TypeAry::hash(void) const { 2278 return (intptr_t)_elem + (intptr_t)_size + (_stable ? 43 : 0); 2279 } 2280 2281 /** 2282 * Return same type without a speculative part in the element 2283 */ 2284 const Type* TypeAry::remove_speculative() const { 2285 return make(_elem->remove_speculative(), _size, _stable); 2286 } 2287 2288 /** 2289 * Return same type with cleaned up speculative part of element 2290 */ 2291 const Type* TypeAry::cleanup_speculative() const { 2292 return make(_elem->cleanup_speculative(), _size, _stable); 2293 } 2294 2295 /** 2296 * Return same type but with a different inline depth (used for speculation) 2297 * 2298 * @param depth depth to meet with 2299 */ 2300 const TypePtr* TypePtr::with_inline_depth(int depth) const { 2301 if (!UseInlineDepthForSpeculativeTypes) { 2302 return this; 2303 } 2304 return make(AnyPtr, _ptr, _offset, _speculative, depth); 2305 } 2306 2307 //----------------------interface_vs_oop--------------------------------------- 2308 #ifdef ASSERT 2309 bool TypeAry::interface_vs_oop(const Type *t) const { 2310 const TypeAry* t_ary = t->is_ary(); 2311 if (t_ary) { 2312 const TypePtr* this_ptr = _elem->make_ptr(); // In case we have narrow_oops 2313 const TypePtr* t_ptr = t_ary->_elem->make_ptr(); 2314 if(this_ptr != NULL && t_ptr != NULL) { 2315 return this_ptr->interface_vs_oop(t_ptr); 2316 } 2317 } 2318 return false; 2319 } 2320 #endif 2321 2322 //------------------------------dump2------------------------------------------ 2323 #ifndef PRODUCT 2324 void TypeAry::dump2( Dict &d, uint depth, outputStream *st ) const { 2325 if (_stable) st->print("stable:"); 2326 _elem->dump2(d, depth, st); 2327 st->print("["); 2328 _size->dump2(d, depth, st); 2329 st->print("]"); 2330 } 2331 #endif 2332 2333 //------------------------------singleton-------------------------------------- 2334 // TRUE if Type is a singleton type, FALSE otherwise. Singletons are simple 2335 // constants (Ldi nodes). Singletons are integer, float or double constants 2336 // or a single symbol. 2337 bool TypeAry::singleton(void) const { 2338 return false; // Never a singleton 2339 } 2340 2341 bool TypeAry::empty(void) const { 2342 return _elem->empty() || _size->empty(); 2343 } 2344 2345 //--------------------------ary_must_be_exact---------------------------------- 2346 bool TypeAry::ary_must_be_exact() const { 2347 if (!UseExactTypes) return false; 2348 // This logic looks at the element type of an array, and returns true 2349 // if the element type is either a primitive or a final instance class. 2350 // In such cases, an array built on this ary must have no subclasses. 2351 if (_elem == BOTTOM) return false; // general array not exact 2352 if (_elem == TOP ) return false; // inverted general array not exact 2353 const TypeOopPtr* toop = NULL; 2354 if (UseCompressedOops && _elem->isa_narrowoop()) { 2355 toop = _elem->make_ptr()->isa_oopptr(); 2356 } else { 2357 toop = _elem->isa_oopptr(); 2358 } 2359 if (!toop) return true; // a primitive type, like int 2360 ciKlass* tklass = toop->klass(); 2361 if (tklass == NULL) return false; // unloaded class 2362 if (!tklass->is_loaded()) return false; // unloaded class 2363 const TypeInstPtr* tinst; 2364 if (_elem->isa_narrowoop()) 2365 tinst = _elem->make_ptr()->isa_instptr(); 2366 else 2367 tinst = _elem->isa_instptr(); 2368 if (tinst) 2369 return tklass->as_instance_klass()->is_final(); 2370 const TypeAryPtr* tap; 2371 if (_elem->isa_narrowoop()) 2372 tap = _elem->make_ptr()->isa_aryptr(); 2373 else 2374 tap = _elem->isa_aryptr(); 2375 if (tap) 2376 return tap->ary()->ary_must_be_exact(); 2377 return false; 2378 } 2379 2380 //==============================TypeValueType======================================= 2381 2382 //------------------------------make------------------------------------------- 2383 const TypeValueType* TypeValueType::make(ciValueKlass* vk) { 2384 return (TypeValueType*)(new TypeValueType(vk))->hashcons(); 2385 } 2386 2387 //------------------------------meet------------------------------------------- 2388 // Compute the MEET of two types. It returns a new Type object. 2389 const Type* TypeValueType::xmeet(const Type* t) const { 2390 // Perform a fast test for common case; meeting the same types together. 2391 if(this == t) return this; // Meeting same type-rep? 2392 2393 // Current "this->_base" is ValueType 2394 switch (t->base()) { // switch on original type 2395 2396 case Int: 2397 case Long: 2398 case FloatTop: 2399 case FloatCon: 2400 case FloatBot: 2401 case DoubleTop: 2402 case DoubleCon: 2403 case DoubleBot: 2404 case NarrowKlass: 2405 case Bottom: 2406 return Type::BOTTOM; 2407 2408 case OopPtr: 2409 case MetadataPtr: 2410 case KlassPtr: 2411 case RawPtr: 2412 return TypePtr::BOTTOM; 2413 2414 case Top: 2415 return this; 2416 2417 case NarrowOop: { 2418 const Type* res = t->make_ptr()->xmeet(this); 2419 if (res->isa_ptr()) { 2420 return res->make_narrowoop(); 2421 } 2422 return res; 2423 } 2424 2425 case AryPtr: 2426 case InstPtr: { 2427 return t->xmeet(this); 2428 } 2429 2430 case ValueType: { 2431 // All value types inherit from Object 2432 return TypeInstPtr::NOTNULL; 2433 } 2434 2435 default: // All else is a mistake 2436 typerr(t); 2437 2438 } 2439 return this; 2440 } 2441 2442 //------------------------------xdual------------------------------------------ 2443 const Type* TypeValueType::xdual() const { 2444 return this; 2445 } 2446 2447 //------------------------------eq--------------------------------------------- 2448 // Structural equality check for Type representations 2449 bool TypeValueType::eq(const Type* t) const { 2450 const TypeValueType* vt = t->is_valuetype(); 2451 return (_vk == vt->value_klass()); 2452 } 2453 2454 //------------------------------hash------------------------------------------- 2455 // Type-specific hashing function. 2456 int TypeValueType::hash(void) const { 2457 return (intptr_t)_vk; 2458 } 2459 2460 //------------------------------singleton-------------------------------------- 2461 // TRUE if Type is a singleton type, FALSE otherwise. Singletons are simple constants. 2462 bool TypeValueType::singleton(void) const { 2463 return false; 2464 } 2465 2466 //------------------------------empty------------------------------------------ 2467 // TRUE if Type is a type with no values, FALSE otherwise. 2468 bool TypeValueType::empty(void) const { 2469 return false; 2470 } 2471 2472 //------------------------------dump2------------------------------------------ 2473 #ifndef PRODUCT 2474 void TypeValueType::dump2(Dict &d, uint depth, outputStream* st) const { 2475 int count = _vk->nof_declared_nonstatic_fields(); 2476 st->print("valuetype[%d]:{", count); 2477 st->print("%s", count != 0 ? _vk->declared_nonstatic_field_at(0)->type()->name() : "empty"); 2478 for (int i = 1; i < count; ++i) { 2479 st->print(", %s", _vk->declared_nonstatic_field_at(i)->type()->name()); 2480 } 2481 st->print("}"); 2482 } 2483 #endif 2484 2485 //==============================TypeVect======================================= 2486 // Convenience common pre-built types. 2487 const TypeVect *TypeVect::VECTS = NULL; // 32-bit vectors 2488 const TypeVect *TypeVect::VECTD = NULL; // 64-bit vectors 2489 const TypeVect *TypeVect::VECTX = NULL; // 128-bit vectors 2490 const TypeVect *TypeVect::VECTY = NULL; // 256-bit vectors 2491 const TypeVect *TypeVect::VECTZ = NULL; // 512-bit vectors 2492 2493 //------------------------------make------------------------------------------- 2494 const TypeVect* TypeVect::make(const Type *elem, uint length) { 2495 BasicType elem_bt = elem->array_element_basic_type(); 2496 assert(is_java_primitive(elem_bt), "only primitive types in vector"); 2497 assert(length > 1 && is_power_of_2(length), "vector length is power of 2"); 2498 assert(Matcher::vector_size_supported(elem_bt, length), "length in range"); 2499 int size = length * type2aelembytes(elem_bt); 2500 switch (Matcher::vector_ideal_reg(size)) { 2501 case Op_VecS: 2502 return (TypeVect*)(new TypeVectS(elem, length))->hashcons(); 2503 case Op_RegL: 2504 case Op_VecD: 2505 case Op_RegD: 2506 return (TypeVect*)(new TypeVectD(elem, length))->hashcons(); 2507 case Op_VecX: 2508 return (TypeVect*)(new TypeVectX(elem, length))->hashcons(); 2509 case Op_VecY: 2510 return (TypeVect*)(new TypeVectY(elem, length))->hashcons(); 2511 case Op_VecZ: 2512 return (TypeVect*)(new TypeVectZ(elem, length))->hashcons(); 2513 } 2514 ShouldNotReachHere(); 2515 return NULL; 2516 } 2517 2518 //------------------------------meet------------------------------------------- 2519 // Compute the MEET of two types. It returns a new Type object. 2520 const Type *TypeVect::xmeet( const Type *t ) const { 2521 // Perform a fast test for common case; meeting the same types together. 2522 if( this == t ) return this; // Meeting same type-rep? 2523 2524 // Current "this->_base" is Vector 2525 switch (t->base()) { // switch on original type 2526 2527 case Bottom: // Ye Olde Default 2528 return t; 2529 2530 default: // All else is a mistake 2531 typerr(t); 2532 2533 case VectorS: 2534 case VectorD: 2535 case VectorX: 2536 case VectorY: 2537 case VectorZ: { // Meeting 2 vectors? 2538 const TypeVect* v = t->is_vect(); 2539 assert( base() == v->base(), ""); 2540 assert(length() == v->length(), ""); 2541 assert(element_basic_type() == v->element_basic_type(), ""); 2542 return TypeVect::make(_elem->xmeet(v->_elem), _length); 2543 } 2544 case Top: 2545 break; 2546 } 2547 return this; 2548 } 2549 2550 //------------------------------xdual------------------------------------------ 2551 // Dual: compute field-by-field dual 2552 const Type *TypeVect::xdual() const { 2553 return new TypeVect(base(), _elem->dual(), _length); 2554 } 2555 2556 //------------------------------eq--------------------------------------------- 2557 // Structural equality check for Type representations 2558 bool TypeVect::eq(const Type *t) const { 2559 const TypeVect *v = t->is_vect(); 2560 return (_elem == v->_elem) && (_length == v->_length); 2561 } 2562 2563 //------------------------------hash------------------------------------------- 2564 // Type-specific hashing function. 2565 int TypeVect::hash(void) const { 2566 return (intptr_t)_elem + (intptr_t)_length; 2567 } 2568 2569 //------------------------------singleton-------------------------------------- 2570 // TRUE if Type is a singleton type, FALSE otherwise. Singletons are simple 2571 // constants (Ldi nodes). Vector is singleton if all elements are the same 2572 // constant value (when vector is created with Replicate code). 2573 bool TypeVect::singleton(void) const { 2574 // There is no Con node for vectors yet. 2575 // return _elem->singleton(); 2576 return false; 2577 } 2578 2579 bool TypeVect::empty(void) const { 2580 return _elem->empty(); 2581 } 2582 2583 //------------------------------dump2------------------------------------------ 2584 #ifndef PRODUCT 2585 void TypeVect::dump2(Dict &d, uint depth, outputStream *st) const { 2586 switch (base()) { 2587 case VectorS: 2588 st->print("vectors["); break; 2589 case VectorD: 2590 st->print("vectord["); break; 2591 case VectorX: 2592 st->print("vectorx["); break; 2593 case VectorY: 2594 st->print("vectory["); break; 2595 case VectorZ: 2596 st->print("vectorz["); break; 2597 default: 2598 ShouldNotReachHere(); 2599 } 2600 st->print("%d]:{", _length); 2601 _elem->dump2(d, depth, st); 2602 st->print("}"); 2603 } 2604 #endif 2605 2606 2607 //============================================================================= 2608 // Convenience common pre-built types. 2609 const TypePtr *TypePtr::NULL_PTR; 2610 const TypePtr *TypePtr::NOTNULL; 2611 const TypePtr *TypePtr::BOTTOM; 2612 2613 //------------------------------meet------------------------------------------- 2614 // Meet over the PTR enum 2615 const TypePtr::PTR TypePtr::ptr_meet[TypePtr::lastPTR][TypePtr::lastPTR] = { 2616 // TopPTR, AnyNull, Constant, Null, NotNull, BotPTR, 2617 { /* Top */ TopPTR, AnyNull, Constant, Null, NotNull, BotPTR,}, 2618 { /* AnyNull */ AnyNull, AnyNull, Constant, BotPTR, NotNull, BotPTR,}, 2619 { /* Constant*/ Constant, Constant, Constant, BotPTR, NotNull, BotPTR,}, 2620 { /* Null */ Null, BotPTR, BotPTR, Null, BotPTR, BotPTR,}, 2621 { /* NotNull */ NotNull, NotNull, NotNull, BotPTR, NotNull, BotPTR,}, 2622 { /* BotPTR */ BotPTR, BotPTR, BotPTR, BotPTR, BotPTR, BotPTR,} 2623 }; 2624 2625 //------------------------------make------------------------------------------- 2626 const TypePtr* TypePtr::make(TYPES t, enum PTR ptr, Offset offset, const TypePtr* speculative, int inline_depth) { 2627 return (TypePtr*)(new TypePtr(t,ptr,offset, speculative, inline_depth))->hashcons(); 2628 } 2629 2630 //------------------------------cast_to_ptr_type------------------------------- 2631 const Type *TypePtr::cast_to_ptr_type(PTR ptr) const { 2632 assert(_base == AnyPtr, "subclass must override cast_to_ptr_type"); 2633 if( ptr == _ptr ) return this; 2634 return make(_base, ptr, _offset, _speculative, _inline_depth); 2635 } 2636 2637 //------------------------------get_con---------------------------------------- 2638 intptr_t TypePtr::get_con() const { 2639 assert( _ptr == Null, "" ); 2640 return offset(); 2641 } 2642 2643 //------------------------------meet------------------------------------------- 2644 // Compute the MEET of two types. It returns a new Type object. 2645 const Type *TypePtr::xmeet(const Type *t) const { 2646 const Type* res = xmeet_helper(t); 2647 if (res->isa_ptr() == NULL) { 2648 return res; 2649 } 2650 2651 const TypePtr* res_ptr = res->is_ptr(); 2652 if (res_ptr->speculative() != NULL) { 2653 // type->speculative() == NULL means that speculation is no better 2654 // than type, i.e. type->speculative() == type. So there are 2 2655 // ways to represent the fact that we have no useful speculative 2656 // data and we should use a single one to be able to test for 2657 // equality between types. Check whether type->speculative() == 2658 // type and set speculative to NULL if it is the case. 2659 if (res_ptr->remove_speculative() == res_ptr->speculative()) { 2660 return res_ptr->remove_speculative(); 2661 } 2662 } 2663 2664 return res; 2665 } 2666 2667 const Type *TypePtr::xmeet_helper(const Type *t) const { 2668 // Perform a fast test for common case; meeting the same types together. 2669 if( this == t ) return this; // Meeting same type-rep? 2670 2671 // Current "this->_base" is AnyPtr 2672 switch (t->base()) { // switch on original type 2673 case Int: // Mixing ints & oops happens when javac 2674 case Long: // reuses local variables 2675 case FloatTop: 2676 case FloatCon: 2677 case FloatBot: 2678 case DoubleTop: 2679 case DoubleCon: 2680 case DoubleBot: 2681 case NarrowOop: 2682 case NarrowKlass: 2683 case Bottom: // Ye Olde Default 2684 return Type::BOTTOM; 2685 case Top: 2686 return this; 2687 2688 case AnyPtr: { // Meeting to AnyPtrs 2689 const TypePtr *tp = t->is_ptr(); 2690 const TypePtr* speculative = xmeet_speculative(tp); 2691 int depth = meet_inline_depth(tp->inline_depth()); 2692 return make(AnyPtr, meet_ptr(tp->ptr()), meet_offset(tp->offset()), speculative, depth); 2693 } 2694 case RawPtr: // For these, flip the call around to cut down 2695 case OopPtr: 2696 case InstPtr: // on the cases I have to handle. 2697 case AryPtr: 2698 case MetadataPtr: 2699 case KlassPtr: 2700 return t->xmeet(this); // Call in reverse direction 2701 default: // All else is a mistake 2702 typerr(t); 2703 2704 } 2705 return this; 2706 } 2707 2708 //------------------------------meet_offset------------------------------------ 2709 Type::Offset TypePtr::meet_offset(int offset) const { 2710 return _offset.meet(Offset(offset)); 2711 } 2712 2713 //------------------------------dual_offset------------------------------------ 2714 Type::Offset TypePtr::dual_offset() const { 2715 return _offset.dual(); 2716 } 2717 2718 //------------------------------xdual------------------------------------------ 2719 // Dual: compute field-by-field dual 2720 const TypePtr::PTR TypePtr::ptr_dual[TypePtr::lastPTR] = { 2721 BotPTR, NotNull, Constant, Null, AnyNull, TopPTR 2722 }; 2723 const Type *TypePtr::xdual() const { 2724 return new TypePtr(AnyPtr, dual_ptr(), dual_offset(), dual_speculative(), dual_inline_depth()); 2725 } 2726 2727 //------------------------------xadd_offset------------------------------------ 2728 Type::Offset TypePtr::xadd_offset(intptr_t offset) const { 2729 return _offset.add(offset); 2730 } 2731 2732 //------------------------------add_offset------------------------------------- 2733 const TypePtr *TypePtr::add_offset( intptr_t offset ) const { 2734 return make(AnyPtr, _ptr, xadd_offset(offset), _speculative, _inline_depth); 2735 } 2736 2737 //------------------------------eq--------------------------------------------- 2738 // Structural equality check for Type representations 2739 bool TypePtr::eq( const Type *t ) const { 2740 const TypePtr *a = (const TypePtr*)t; 2741 return _ptr == a->ptr() && _offset == a->_offset && eq_speculative(a) && _inline_depth == a->_inline_depth; 2742 } 2743 2744 //------------------------------hash------------------------------------------- 2745 // Type-specific hashing function. 2746 int TypePtr::hash(void) const { 2747 return java_add(java_add((jint)_ptr, (jint)offset()), java_add((jint)hash_speculative(), (jint)_inline_depth)); 2748 ; 2749 } 2750 2751 /** 2752 * Return same type without a speculative part 2753 */ 2754 const Type* TypePtr::remove_speculative() const { 2755 if (_speculative == NULL) { 2756 return this; 2757 } 2758 assert(_inline_depth == InlineDepthTop || _inline_depth == InlineDepthBottom, "non speculative type shouldn't have inline depth"); 2759 return make(AnyPtr, _ptr, _offset, NULL, _inline_depth); 2760 } 2761 2762 /** 2763 * Return same type but drop speculative part if we know we won't use 2764 * it 2765 */ 2766 const Type* TypePtr::cleanup_speculative() const { 2767 if (speculative() == NULL) { 2768 return this; 2769 } 2770 const Type* no_spec = remove_speculative(); 2771 // If this is NULL_PTR then we don't need the speculative type 2772 // (with_inline_depth in case the current type inline depth is 2773 // InlineDepthTop) 2774 if (no_spec == NULL_PTR->with_inline_depth(inline_depth())) { 2775 return no_spec; 2776 } 2777 if (above_centerline(speculative()->ptr())) { 2778 return no_spec; 2779 } 2780 const TypeOopPtr* spec_oopptr = speculative()->isa_oopptr(); 2781 // If the speculative may be null and is an inexact klass then it 2782 // doesn't help 2783 if (speculative() != TypePtr::NULL_PTR && speculative()->maybe_null() && 2784 (spec_oopptr == NULL || !spec_oopptr->klass_is_exact())) { 2785 return no_spec; 2786 } 2787 return this; 2788 } 2789 2790 /** 2791 * dual of the speculative part of the type 2792 */ 2793 const TypePtr* TypePtr::dual_speculative() const { 2794 if (_speculative == NULL) { 2795 return NULL; 2796 } 2797 return _speculative->dual()->is_ptr(); 2798 } 2799 2800 /** 2801 * meet of the speculative parts of 2 types 2802 * 2803 * @param other type to meet with 2804 */ 2805 const TypePtr* TypePtr::xmeet_speculative(const TypePtr* other) const { 2806 bool this_has_spec = (_speculative != NULL); 2807 bool other_has_spec = (other->speculative() != NULL); 2808 2809 if (!this_has_spec && !other_has_spec) { 2810 return NULL; 2811 } 2812 2813 // If we are at a point where control flow meets and one branch has 2814 // a speculative type and the other has not, we meet the speculative 2815 // type of one branch with the actual type of the other. If the 2816 // actual type is exact and the speculative is as well, then the 2817 // result is a speculative type which is exact and we can continue 2818 // speculation further. 2819 const TypePtr* this_spec = _speculative; 2820 const TypePtr* other_spec = other->speculative(); 2821 2822 if (!this_has_spec) { 2823 this_spec = this; 2824 } 2825 2826 if (!other_has_spec) { 2827 other_spec = other; 2828 } 2829 2830 return this_spec->meet(other_spec)->is_ptr(); 2831 } 2832 2833 /** 2834 * dual of the inline depth for this type (used for speculation) 2835 */ 2836 int TypePtr::dual_inline_depth() const { 2837 return -inline_depth(); 2838 } 2839 2840 /** 2841 * meet of 2 inline depths (used for speculation) 2842 * 2843 * @param depth depth to meet with 2844 */ 2845 int TypePtr::meet_inline_depth(int depth) const { 2846 return MAX2(inline_depth(), depth); 2847 } 2848 2849 /** 2850 * Are the speculative parts of 2 types equal? 2851 * 2852 * @param other type to compare this one to 2853 */ 2854 bool TypePtr::eq_speculative(const TypePtr* other) const { 2855 if (_speculative == NULL || other->speculative() == NULL) { 2856 return _speculative == other->speculative(); 2857 } 2858 2859 if (_speculative->base() != other->speculative()->base()) { 2860 return false; 2861 } 2862 2863 return _speculative->eq(other->speculative()); 2864 } 2865 2866 /** 2867 * Hash of the speculative part of the type 2868 */ 2869 int TypePtr::hash_speculative() const { 2870 if (_speculative == NULL) { 2871 return 0; 2872 } 2873 2874 return _speculative->hash(); 2875 } 2876 2877 /** 2878 * add offset to the speculative part of the type 2879 * 2880 * @param offset offset to add 2881 */ 2882 const TypePtr* TypePtr::add_offset_speculative(intptr_t offset) const { 2883 if (_speculative == NULL) { 2884 return NULL; 2885 } 2886 return _speculative->add_offset(offset)->is_ptr(); 2887 } 2888 2889 /** 2890 * return exact klass from the speculative type if there's one 2891 */ 2892 ciKlass* TypePtr::speculative_type() const { 2893 if (_speculative != NULL && _speculative->isa_oopptr()) { 2894 const TypeOopPtr* speculative = _speculative->join(this)->is_oopptr(); 2895 if (speculative->klass_is_exact()) { 2896 return speculative->klass(); 2897 } 2898 } 2899 return NULL; 2900 } 2901 2902 /** 2903 * return true if speculative type may be null 2904 */ 2905 bool TypePtr::speculative_maybe_null() const { 2906 if (_speculative != NULL) { 2907 const TypePtr* speculative = _speculative->join(this)->is_ptr(); 2908 return speculative->maybe_null(); 2909 } 2910 return true; 2911 } 2912 2913 bool TypePtr::speculative_always_null() const { 2914 if (_speculative != NULL) { 2915 const TypePtr* speculative = _speculative->join(this)->is_ptr(); 2916 return speculative == TypePtr::NULL_PTR; 2917 } 2918 return false; 2919 } 2920 2921 /** 2922 * Same as TypePtr::speculative_type() but return the klass only if 2923 * the speculative tells us is not null 2924 */ 2925 ciKlass* TypePtr::speculative_type_not_null() const { 2926 if (speculative_maybe_null()) { 2927 return NULL; 2928 } 2929 return speculative_type(); 2930 } 2931 2932 /** 2933 * Check whether new profiling would improve speculative type 2934 * 2935 * @param exact_kls class from profiling 2936 * @param inline_depth inlining depth of profile point 2937 * 2938 * @return true if type profile is valuable 2939 */ 2940 bool TypePtr::would_improve_type(ciKlass* exact_kls, int inline_depth) const { 2941 // no profiling? 2942 if (exact_kls == NULL) { 2943 return false; 2944 } 2945 if (speculative() == TypePtr::NULL_PTR) { 2946 return false; 2947 } 2948 // no speculative type or non exact speculative type? 2949 if (speculative_type() == NULL) { 2950 return true; 2951 } 2952 // If the node already has an exact speculative type keep it, 2953 // unless it was provided by profiling that is at a deeper 2954 // inlining level. Profiling at a higher inlining depth is 2955 // expected to be less accurate. 2956 if (_speculative->inline_depth() == InlineDepthBottom) { 2957 return false; 2958 } 2959 assert(_speculative->inline_depth() != InlineDepthTop, "can't do the comparison"); 2960 return inline_depth < _speculative->inline_depth(); 2961 } 2962 2963 /** 2964 * Check whether new profiling would improve ptr (= tells us it is non 2965 * null) 2966 * 2967 * @param ptr_kind always null or not null? 2968 * 2969 * @return true if ptr profile is valuable 2970 */ 2971 bool TypePtr::would_improve_ptr(ProfilePtrKind ptr_kind) const { 2972 // profiling doesn't tell us anything useful 2973 if (ptr_kind != ProfileAlwaysNull && ptr_kind != ProfileNeverNull) { 2974 return false; 2975 } 2976 // We already know this is not null 2977 if (!this->maybe_null()) { 2978 return false; 2979 } 2980 // We already know the speculative type cannot be null 2981 if (!speculative_maybe_null()) { 2982 return false; 2983 } 2984 // We already know this is always null 2985 if (this == TypePtr::NULL_PTR) { 2986 return false; 2987 } 2988 // We already know the speculative type is always null 2989 if (speculative_always_null()) { 2990 return false; 2991 } 2992 if (ptr_kind == ProfileAlwaysNull && speculative() != NULL && speculative()->isa_oopptr()) { 2993 return false; 2994 } 2995 return true; 2996 } 2997 2998 //------------------------------dump2------------------------------------------ 2999 const char *const TypePtr::ptr_msg[TypePtr::lastPTR] = { 3000 "TopPTR","AnyNull","Constant","NULL","NotNull","BotPTR" 3001 }; 3002 3003 #ifndef PRODUCT 3004 void TypePtr::dump2( Dict &d, uint depth, outputStream *st ) const { 3005 if( _ptr == Null ) st->print("NULL"); 3006 else st->print("%s *", ptr_msg[_ptr]); 3007 _offset.dump2(st); 3008 dump_inline_depth(st); 3009 dump_speculative(st); 3010 } 3011 3012 /** 3013 *dump the speculative part of the type 3014 */ 3015 void TypePtr::dump_speculative(outputStream *st) const { 3016 if (_speculative != NULL) { 3017 st->print(" (speculative="); 3018 _speculative->dump_on(st); 3019 st->print(")"); 3020 } 3021 } 3022 3023 /** 3024 *dump the inline depth of the type 3025 */ 3026 void TypePtr::dump_inline_depth(outputStream *st) const { 3027 if (_inline_depth != InlineDepthBottom) { 3028 if (_inline_depth == InlineDepthTop) { 3029 st->print(" (inline_depth=InlineDepthTop)"); 3030 } else { 3031 st->print(" (inline_depth=%d)", _inline_depth); 3032 } 3033 } 3034 } 3035 #endif 3036 3037 //------------------------------singleton-------------------------------------- 3038 // TRUE if Type is a singleton type, FALSE otherwise. Singletons are simple 3039 // constants 3040 bool TypePtr::singleton(void) const { 3041 // TopPTR, Null, AnyNull, Constant are all singletons 3042 return (_offset != Offset::bottom) && !below_centerline(_ptr); 3043 } 3044 3045 bool TypePtr::empty(void) const { 3046 return (_offset == Offset::top) || above_centerline(_ptr); 3047 } 3048 3049 //============================================================================= 3050 // Convenience common pre-built types. 3051 const TypeRawPtr *TypeRawPtr::BOTTOM; 3052 const TypeRawPtr *TypeRawPtr::NOTNULL; 3053 3054 //------------------------------make------------------------------------------- 3055 const TypeRawPtr *TypeRawPtr::make( enum PTR ptr ) { 3056 assert( ptr != Constant, "what is the constant?" ); 3057 assert( ptr != Null, "Use TypePtr for NULL" ); 3058 return (TypeRawPtr*)(new TypeRawPtr(ptr,0))->hashcons(); 3059 } 3060 3061 const TypeRawPtr *TypeRawPtr::make( address bits ) { 3062 assert( bits, "Use TypePtr for NULL" ); 3063 return (TypeRawPtr*)(new TypeRawPtr(Constant,bits))->hashcons(); 3064 } 3065 3066 //------------------------------cast_to_ptr_type------------------------------- 3067 const Type *TypeRawPtr::cast_to_ptr_type(PTR ptr) const { 3068 assert( ptr != Constant, "what is the constant?" ); 3069 assert( ptr != Null, "Use TypePtr for NULL" ); 3070 assert( _bits==0, "Why cast a constant address?"); 3071 if( ptr == _ptr ) return this; 3072 return make(ptr); 3073 } 3074 3075 //------------------------------get_con---------------------------------------- 3076 intptr_t TypeRawPtr::get_con() const { 3077 assert( _ptr == Null || _ptr == Constant, "" ); 3078 return (intptr_t)_bits; 3079 } 3080 3081 //------------------------------meet------------------------------------------- 3082 // Compute the MEET of two types. It returns a new Type object. 3083 const Type *TypeRawPtr::xmeet( const Type *t ) const { 3084 // Perform a fast test for common case; meeting the same types together. 3085 if( this == t ) return this; // Meeting same type-rep? 3086 3087 // Current "this->_base" is RawPtr 3088 switch( t->base() ) { // switch on original type 3089 case Bottom: // Ye Olde Default 3090 return t; 3091 case Top: 3092 return this; 3093 case AnyPtr: // Meeting to AnyPtrs 3094 break; 3095 case RawPtr: { // might be top, bot, any/not or constant 3096 enum PTR tptr = t->is_ptr()->ptr(); 3097 enum PTR ptr = meet_ptr( tptr ); 3098 if( ptr == Constant ) { // Cannot be equal constants, so... 3099 if( tptr == Constant && _ptr != Constant) return t; 3100 if( _ptr == Constant && tptr != Constant) return this; 3101 ptr = NotNull; // Fall down in lattice 3102 } 3103 return make( ptr ); 3104 } 3105 3106 case OopPtr: 3107 case InstPtr: 3108 case AryPtr: 3109 case MetadataPtr: 3110 case KlassPtr: 3111 return TypePtr::BOTTOM; // Oop meet raw is not well defined 3112 default: // All else is a mistake 3113 typerr(t); 3114 } 3115 3116 // Found an AnyPtr type vs self-RawPtr type 3117 const TypePtr *tp = t->is_ptr(); 3118 switch (tp->ptr()) { 3119 case TypePtr::TopPTR: return this; 3120 case TypePtr::BotPTR: return t; 3121 case TypePtr::Null: 3122 if( _ptr == TypePtr::TopPTR ) return t; 3123 return TypeRawPtr::BOTTOM; 3124 case TypePtr::NotNull: return TypePtr::make(AnyPtr, meet_ptr(TypePtr::NotNull), tp->meet_offset(0), tp->speculative(), tp->inline_depth()); 3125 case TypePtr::AnyNull: 3126 if( _ptr == TypePtr::Constant) return this; 3127 return make( meet_ptr(TypePtr::AnyNull) ); 3128 default: ShouldNotReachHere(); 3129 } 3130 return this; 3131 } 3132 3133 //------------------------------xdual------------------------------------------ 3134 // Dual: compute field-by-field dual 3135 const Type *TypeRawPtr::xdual() const { 3136 return new TypeRawPtr( dual_ptr(), _bits ); 3137 } 3138 3139 //------------------------------add_offset------------------------------------- 3140 const TypePtr *TypeRawPtr::add_offset( intptr_t offset ) const { 3141 if( offset == OffsetTop ) return BOTTOM; // Undefined offset-> undefined pointer 3142 if( offset == OffsetBot ) return BOTTOM; // Unknown offset-> unknown pointer 3143 if( offset == 0 ) return this; // No change 3144 switch (_ptr) { 3145 case TypePtr::TopPTR: 3146 case TypePtr::BotPTR: 3147 case TypePtr::NotNull: 3148 return this; 3149 case TypePtr::Null: 3150 case TypePtr::Constant: { 3151 address bits = _bits+offset; 3152 if ( bits == 0 ) return TypePtr::NULL_PTR; 3153 return make( bits ); 3154 } 3155 default: ShouldNotReachHere(); 3156 } 3157 return NULL; // Lint noise 3158 } 3159 3160 //------------------------------eq--------------------------------------------- 3161 // Structural equality check for Type representations 3162 bool TypeRawPtr::eq( const Type *t ) const { 3163 const TypeRawPtr *a = (const TypeRawPtr*)t; 3164 return _bits == a->_bits && TypePtr::eq(t); 3165 } 3166 3167 //------------------------------hash------------------------------------------- 3168 // Type-specific hashing function. 3169 int TypeRawPtr::hash(void) const { 3170 return (intptr_t)_bits + TypePtr::hash(); 3171 } 3172 3173 //------------------------------dump2------------------------------------------ 3174 #ifndef PRODUCT 3175 void TypeRawPtr::dump2( Dict &d, uint depth, outputStream *st ) const { 3176 if( _ptr == Constant ) 3177 st->print(INTPTR_FORMAT, p2i(_bits)); 3178 else 3179 st->print("rawptr:%s", ptr_msg[_ptr]); 3180 } 3181 #endif 3182 3183 //============================================================================= 3184 // Convenience common pre-built type. 3185 const TypeOopPtr *TypeOopPtr::BOTTOM; 3186 3187 //------------------------------TypeOopPtr------------------------------------- 3188 TypeOopPtr::TypeOopPtr(TYPES t, PTR ptr, ciKlass* k, bool xk, ciObject* o, Offset offset, Offset field_offset, 3189 int instance_id, const TypePtr* speculative, int inline_depth) 3190 : TypePtr(t, ptr, offset, speculative, inline_depth), 3191 _const_oop(o), _klass(k), 3192 _klass_is_exact(xk), 3193 _is_ptr_to_narrowoop(false), 3194 _is_ptr_to_narrowklass(false), 3195 _is_ptr_to_boxed_value(false), 3196 _instance_id(instance_id) { 3197 if (Compile::current()->eliminate_boxing() && (t == InstPtr) && 3198 (offset.get() > 0) && xk && (k != 0) && k->is_instance_klass()) { 3199 _is_ptr_to_boxed_value = k->as_instance_klass()->is_boxed_value_offset(offset.get()); 3200 } 3201 #ifdef _LP64 3202 if (this->offset() != 0) { 3203 if (this->offset() == oopDesc::klass_offset_in_bytes()) { 3204 _is_ptr_to_narrowklass = UseCompressedClassPointers; 3205 } else if (klass() == NULL) { 3206 // Array with unknown body type 3207 assert(this->isa_aryptr(), "only arrays without klass"); 3208 _is_ptr_to_narrowoop = UseCompressedOops; 3209 } else if (UseCompressedOops && this->isa_aryptr() && this->offset() != arrayOopDesc::length_offset_in_bytes()) { 3210 if (klass()->is_obj_array_klass()) { 3211 _is_ptr_to_narrowoop = true; 3212 } else if (klass()->is_value_array_klass() && field_offset != Offset::top && field_offset != Offset::bottom) { 3213 // Check if the field of the value type array element contains oops 3214 ciValueKlass* vk = klass()->as_value_array_klass()->element_klass()->as_value_klass(); 3215 int foffset = field_offset.get() + vk->first_field_offset(); 3216 ciField* field = vk->get_field_by_offset(foffset, false); 3217 assert(field != NULL, "missing field"); 3218 BasicType bt = field->layout_type(); 3219 assert(bt != T_VALUETYPEPTR, "unexpected type"); 3220 _is_ptr_to_narrowoop = (bt == T_OBJECT || bt == T_ARRAY || T_VALUETYPE); 3221 } 3222 } else if (klass()->is_instance_klass()) { 3223 if (this->isa_klassptr()) { 3224 // Perm objects don't use compressed references 3225 } else if (_offset == Offset::bottom || _offset == Offset::top) { 3226 // unsafe access 3227 _is_ptr_to_narrowoop = UseCompressedOops; 3228 } else { // exclude unsafe ops 3229 assert(this->isa_instptr(), "must be an instance ptr."); 3230 if (klass() == ciEnv::current()->Class_klass() && 3231 (this->offset() == java_lang_Class::klass_offset_in_bytes() || 3232 this->offset() == java_lang_Class::array_klass_offset_in_bytes())) { 3233 // Special hidden fields from the Class. 3234 assert(this->isa_instptr(), "must be an instance ptr."); 3235 _is_ptr_to_narrowoop = false; 3236 } else if (klass() == ciEnv::current()->Class_klass() && 3237 this->offset() >= InstanceMirrorKlass::offset_of_static_fields()) { 3238 // Static fields 3239 assert(o != NULL, "must be constant"); 3240 ciInstanceKlass* ik = o->as_instance()->java_lang_Class_klass()->as_instance_klass(); 3241 BasicType basic_elem_type; 3242 if (ik->is_valuetype() && this->offset() == ik->as_value_klass()->default_value_offset()) { 3243 // Special hidden field that contains the oop of the default value type 3244 basic_elem_type = T_VALUETYPE; 3245 } else { 3246 ciField* field = ik->get_field_by_offset(this->offset(), true); 3247 assert(field != NULL, "missing field"); 3248 basic_elem_type = field->layout_type(); 3249 } 3250 _is_ptr_to_narrowoop = UseCompressedOops && (basic_elem_type == T_OBJECT || 3251 basic_elem_type == T_VALUETYPE || 3252 basic_elem_type == T_ARRAY); 3253 } else { 3254 // Instance fields which contains a compressed oop references. 3255 ciInstanceKlass* ik = klass()->as_instance_klass(); 3256 ciField* field = ik->get_field_by_offset(this->offset(), false); 3257 if (field != NULL) { 3258 BasicType basic_elem_type = field->layout_type(); 3259 _is_ptr_to_narrowoop = UseCompressedOops && (basic_elem_type == T_OBJECT || 3260 basic_elem_type == T_VALUETYPE || 3261 basic_elem_type == T_ARRAY); 3262 assert(basic_elem_type != T_VALUETYPEPTR, "unexpected type"); 3263 } else if (klass()->equals(ciEnv::current()->Object_klass())) { 3264 // Compile::find_alias_type() cast exactness on all types to verify 3265 // that it does not affect alias type. 3266 _is_ptr_to_narrowoop = UseCompressedOops; 3267 } else { 3268 // Type for the copy start in LibraryCallKit::inline_native_clone(). 3269 _is_ptr_to_narrowoop = UseCompressedOops; 3270 } 3271 } 3272 } 3273 } 3274 } 3275 #endif 3276 } 3277 3278 //------------------------------make------------------------------------------- 3279 const TypeOopPtr *TypeOopPtr::make(PTR ptr, Offset offset, int instance_id, 3280 const TypePtr* speculative, int inline_depth) { 3281 assert(ptr != Constant, "no constant generic pointers"); 3282 ciKlass* k = Compile::current()->env()->Object_klass(); 3283 bool xk = false; 3284 ciObject* o = NULL; 3285 return (TypeOopPtr*)(new TypeOopPtr(OopPtr, ptr, k, xk, o, offset, Offset::bottom, instance_id, speculative, inline_depth))->hashcons(); 3286 } 3287 3288 3289 //------------------------------cast_to_ptr_type------------------------------- 3290 const Type *TypeOopPtr::cast_to_ptr_type(PTR ptr) const { 3291 assert(_base == OopPtr, "subclass must override cast_to_ptr_type"); 3292 if( ptr == _ptr ) return this; 3293 return make(ptr, _offset, _instance_id, _speculative, _inline_depth); 3294 } 3295 3296 //-----------------------------cast_to_instance_id---------------------------- 3297 const TypeOopPtr *TypeOopPtr::cast_to_instance_id(int instance_id) const { 3298 // There are no instances of a general oop. 3299 // Return self unchanged. 3300 return this; 3301 } 3302 3303 //-----------------------------cast_to_exactness------------------------------- 3304 const Type *TypeOopPtr::cast_to_exactness(bool klass_is_exact) const { 3305 // There is no such thing as an exact general oop. 3306 // Return self unchanged. 3307 return this; 3308 } 3309 3310 3311 //------------------------------as_klass_type---------------------------------- 3312 // Return the klass type corresponding to this instance or array type. 3313 // It is the type that is loaded from an object of this type. 3314 const TypeKlassPtr* TypeOopPtr::as_klass_type() const { 3315 ciKlass* k = klass(); 3316 bool xk = klass_is_exact(); 3317 if (k == NULL) 3318 return TypeKlassPtr::OBJECT; 3319 else 3320 return TypeKlassPtr::make(xk? Constant: NotNull, k, Offset(0)); 3321 } 3322 3323 //------------------------------meet------------------------------------------- 3324 // Compute the MEET of two types. It returns a new Type object. 3325 const Type *TypeOopPtr::xmeet_helper(const Type *t) const { 3326 // Perform a fast test for common case; meeting the same types together. 3327 if( this == t ) return this; // Meeting same type-rep? 3328 3329 // Current "this->_base" is OopPtr 3330 switch (t->base()) { // switch on original type 3331 3332 case Int: // Mixing ints & oops happens when javac 3333 case Long: // reuses local variables 3334 case FloatTop: 3335 case FloatCon: 3336 case FloatBot: 3337 case DoubleTop: 3338 case DoubleCon: 3339 case DoubleBot: 3340 case NarrowOop: 3341 case NarrowKlass: 3342 case Bottom: // Ye Olde Default 3343 return Type::BOTTOM; 3344 case Top: 3345 return this; 3346 3347 default: // All else is a mistake 3348 typerr(t); 3349 3350 case RawPtr: 3351 case MetadataPtr: 3352 case KlassPtr: 3353 return TypePtr::BOTTOM; // Oop meet raw is not well defined 3354 3355 case AnyPtr: { 3356 // Found an AnyPtr type vs self-OopPtr type 3357 const TypePtr *tp = t->is_ptr(); 3358 Offset offset = meet_offset(tp->offset()); 3359 PTR ptr = meet_ptr(tp->ptr()); 3360 const TypePtr* speculative = xmeet_speculative(tp); 3361 int depth = meet_inline_depth(tp->inline_depth()); 3362 switch (tp->ptr()) { 3363 case Null: 3364 if (ptr == Null) return TypePtr::make(AnyPtr, ptr, offset, speculative, depth); 3365 // else fall through: 3366 case TopPTR: 3367 case AnyNull: { 3368 int instance_id = meet_instance_id(InstanceTop); 3369 return make(ptr, offset, instance_id, speculative, depth); 3370 } 3371 case BotPTR: 3372 case NotNull: 3373 return TypePtr::make(AnyPtr, ptr, offset, speculative, depth); 3374 default: typerr(t); 3375 } 3376 } 3377 3378 case OopPtr: { // Meeting to other OopPtrs 3379 const TypeOopPtr *tp = t->is_oopptr(); 3380 int instance_id = meet_instance_id(tp->instance_id()); 3381 const TypePtr* speculative = xmeet_speculative(tp); 3382 int depth = meet_inline_depth(tp->inline_depth()); 3383 return make(meet_ptr(tp->ptr()), meet_offset(tp->offset()), instance_id, speculative, depth); 3384 } 3385 3386 case InstPtr: // For these, flip the call around to cut down 3387 case AryPtr: 3388 return t->xmeet(this); // Call in reverse direction 3389 3390 } // End of switch 3391 return this; // Return the double constant 3392 } 3393 3394 3395 //------------------------------xdual------------------------------------------ 3396 // Dual of a pure heap pointer. No relevant klass or oop information. 3397 const Type *TypeOopPtr::xdual() const { 3398 assert(klass() == Compile::current()->env()->Object_klass(), "no klasses here"); 3399 assert(const_oop() == NULL, "no constants here"); 3400 return new TypeOopPtr(_base, dual_ptr(), klass(), klass_is_exact(), const_oop(), dual_offset(), Offset::bottom, dual_instance_id(), dual_speculative(), dual_inline_depth()); 3401 } 3402 3403 //--------------------------make_from_klass_common----------------------------- 3404 // Computes the element-type given a klass. 3405 const TypeOopPtr* TypeOopPtr::make_from_klass_common(ciKlass *klass, bool klass_change, bool try_for_exact) { 3406 if (klass->is_instance_klass() || klass->is_valuetype()) { 3407 Compile* C = Compile::current(); 3408 Dependencies* deps = C->dependencies(); 3409 assert((deps != NULL) == (C->method() != NULL && C->method()->code_size() > 0), "sanity"); 3410 // Element is an instance 3411 bool klass_is_exact = false; 3412 if (klass->is_loaded()) { 3413 // Try to set klass_is_exact. 3414 ciInstanceKlass* ik = klass->as_instance_klass(); 3415 klass_is_exact = ik->is_final(); 3416 if (!klass_is_exact && klass_change 3417 && deps != NULL && UseUniqueSubclasses) { 3418 ciInstanceKlass* sub = ik->unique_concrete_subklass(); 3419 if (sub != NULL) { 3420 deps->assert_abstract_with_unique_concrete_subtype(ik, sub); 3421 klass = ik = sub; 3422 klass_is_exact = sub->is_final(); 3423 } 3424 } 3425 if (!klass_is_exact && try_for_exact 3426 && deps != NULL && UseExactTypes) { 3427 if (!ik->is_interface() && !ik->has_subklass()) { 3428 // Add a dependence; if concrete subclass added we need to recompile 3429 deps->assert_leaf_type(ik); 3430 klass_is_exact = true; 3431 } 3432 } 3433 } 3434 return TypeInstPtr::make(TypePtr::BotPTR, klass, klass_is_exact, NULL, Offset(0)); 3435 } else if (klass->is_obj_array_klass()) { 3436 // Element is an object or value array. Recursively call ourself. 3437 const TypeOopPtr* etype = TypeOopPtr::make_from_klass_common(klass->as_array_klass()->element_klass(), false, try_for_exact); 3438 bool xk = etype->klass_is_exact(); 3439 const TypeAry* arr0 = TypeAry::make(etype, TypeInt::POS); 3440 // We used to pass NotNull in here, asserting that the sub-arrays 3441 // are all not-null. This is not true in generally, as code can 3442 // slam NULLs down in the subarrays. 3443 const TypeAryPtr* arr = TypeAryPtr::make(TypePtr::BotPTR, arr0, klass, xk, Offset(0)); 3444 return arr; 3445 } else if (klass->is_type_array_klass()) { 3446 // Element is an typeArray 3447 const Type* etype = get_const_basic_type(klass->as_type_array_klass()->element_type()); 3448 const TypeAry* arr0 = TypeAry::make(etype, TypeInt::POS); 3449 // We used to pass NotNull in here, asserting that the array pointer 3450 // is not-null. That was not true in general. 3451 const TypeAryPtr* arr = TypeAryPtr::make(TypePtr::BotPTR, arr0, klass, true, Offset(0)); 3452 return arr; 3453 } else if (klass->is_value_array_klass()) { 3454 ciValueKlass* vk = klass->as_array_klass()->element_klass()->as_value_klass(); 3455 const TypeAry* arr0 = TypeAry::make(TypeValueType::make(vk), TypeInt::POS); 3456 const TypeAryPtr* arr = TypeAryPtr::make(TypePtr::BotPTR, arr0, klass, true, Offset(0)); 3457 return arr; 3458 } else { 3459 ShouldNotReachHere(); 3460 return NULL; 3461 } 3462 } 3463 3464 //------------------------------make_from_constant----------------------------- 3465 // Make a java pointer from an oop constant 3466 const TypeOopPtr* TypeOopPtr::make_from_constant(ciObject* o, bool require_constant) { 3467 assert(!o->is_null_object(), "null object not yet handled here."); 3468 ciKlass* klass = o->klass(); 3469 if (klass->is_instance_klass() || klass->is_valuetype()) { 3470 // Element is an instance or value type 3471 if (require_constant) { 3472 if (!o->can_be_constant()) return NULL; 3473 } else if (!o->should_be_constant()) { 3474 return TypeInstPtr::make(TypePtr::NotNull, klass, true, NULL, Offset(0)); 3475 } 3476 return TypeInstPtr::make(o); 3477 } else if (klass->is_obj_array_klass()) { 3478 // Element is an object array. Recursively call ourself. 3479 const TypeOopPtr *etype = 3480 TypeOopPtr::make_from_klass_raw(klass->as_array_klass()->element_klass()); 3481 const TypeAry* arr0 = TypeAry::make(etype, TypeInt::make(o->as_array()->length())); 3482 // We used to pass NotNull in here, asserting that the sub-arrays 3483 // are all not-null. This is not true in generally, as code can 3484 // slam NULLs down in the subarrays. 3485 if (require_constant) { 3486 if (!o->can_be_constant()) return NULL; 3487 } else if (!o->should_be_constant()) { 3488 return TypeAryPtr::make(TypePtr::NotNull, arr0, klass, true, Offset(0)); 3489 } 3490 const TypeAryPtr* arr = TypeAryPtr::make(TypePtr::Constant, o, arr0, klass, true, Offset(0)); 3491 return arr; 3492 } else if (klass->is_type_array_klass()) { 3493 // Element is an typeArray 3494 const Type* etype = 3495 (Type*)get_const_basic_type(klass->as_type_array_klass()->element_type()); 3496 const TypeAry* arr0 = TypeAry::make(etype, TypeInt::make(o->as_array()->length())); 3497 // We used to pass NotNull in here, asserting that the array pointer 3498 // is not-null. That was not true in general. 3499 if (require_constant) { 3500 if (!o->can_be_constant()) return NULL; 3501 } else if (!o->should_be_constant()) { 3502 return TypeAryPtr::make(TypePtr::NotNull, arr0, klass, true, Offset(0)); 3503 } 3504 const TypeAryPtr* arr = TypeAryPtr::make(TypePtr::Constant, o, arr0, klass, true, Offset(0)); 3505 return arr; 3506 } else if (klass->is_value_array_klass()) { 3507 ciValueKlass* vk = klass->as_array_klass()->element_klass()->as_value_klass(); 3508 const TypeAry* arr0 = TypeAry::make(TypeValueType::make(vk), TypeInt::make(o->as_array()->length())); 3509 // We used to pass NotNull in here, asserting that the sub-arrays 3510 // are all not-null. This is not true in generally, as code can 3511 // slam NULLs down in the subarrays. 3512 if (require_constant) { 3513 if (!o->can_be_constant()) return NULL; 3514 } else if (!o->should_be_constant()) { 3515 return TypeAryPtr::make(TypePtr::NotNull, arr0, klass, true, Offset(0)); 3516 } 3517 const TypeAryPtr* arr = TypeAryPtr::make(TypePtr::Constant, o, arr0, klass, true, Offset(0)); 3518 return arr; 3519 } 3520 3521 fatal("unhandled object type"); 3522 return NULL; 3523 } 3524 3525 //------------------------------get_con---------------------------------------- 3526 intptr_t TypeOopPtr::get_con() const { 3527 assert( _ptr == Null || _ptr == Constant, "" ); 3528 assert(offset() >= 0, ""); 3529 3530 if (offset() != 0) { 3531 // After being ported to the compiler interface, the compiler no longer 3532 // directly manipulates the addresses of oops. Rather, it only has a pointer 3533 // to a handle at compile time. This handle is embedded in the generated 3534 // code and dereferenced at the time the nmethod is made. Until that time, 3535 // it is not reasonable to do arithmetic with the addresses of oops (we don't 3536 // have access to the addresses!). This does not seem to currently happen, 3537 // but this assertion here is to help prevent its occurence. 3538 tty->print_cr("Found oop constant with non-zero offset"); 3539 ShouldNotReachHere(); 3540 } 3541 3542 return (intptr_t)const_oop()->constant_encoding(); 3543 } 3544 3545 3546 //-----------------------------filter------------------------------------------ 3547 // Do not allow interface-vs.-noninterface joins to collapse to top. 3548 const Type *TypeOopPtr::filter_helper(const Type *kills, bool include_speculative) const { 3549 3550 const Type* ft = join_helper(kills, include_speculative); 3551 const TypeInstPtr* ftip = ft->isa_instptr(); 3552 const TypeInstPtr* ktip = kills->isa_instptr(); 3553 3554 if (ft->empty()) { 3555 // Check for evil case of 'this' being a class and 'kills' expecting an 3556 // interface. This can happen because the bytecodes do not contain 3557 // enough type info to distinguish a Java-level interface variable 3558 // from a Java-level object variable. If we meet 2 classes which 3559 // both implement interface I, but their meet is at 'j/l/O' which 3560 // doesn't implement I, we have no way to tell if the result should 3561 // be 'I' or 'j/l/O'. Thus we'll pick 'j/l/O'. If this then flows 3562 // into a Phi which "knows" it's an Interface type we'll have to 3563 // uplift the type. 3564 if (!empty()) { 3565 if (ktip != NULL && ktip->is_loaded() && ktip->klass()->is_interface()) { 3566 return kills; // Uplift to interface 3567 } 3568 // Also check for evil cases of 'this' being a class array 3569 // and 'kills' expecting an array of interfaces. 3570 Type::get_arrays_base_elements(ft, kills, NULL, &ktip); 3571 if (ktip != NULL && ktip->is_loaded() && ktip->klass()->is_interface()) { 3572 return kills; // Uplift to array of interface 3573 } 3574 } 3575 3576 return Type::TOP; // Canonical empty value 3577 } 3578 3579 // If we have an interface-typed Phi or cast and we narrow to a class type, 3580 // the join should report back the class. However, if we have a J/L/Object 3581 // class-typed Phi and an interface flows in, it's possible that the meet & 3582 // join report an interface back out. This isn't possible but happens 3583 // because the type system doesn't interact well with interfaces. 3584 if (ftip != NULL && ktip != NULL && 3585 ftip->is_loaded() && ftip->klass()->is_interface() && 3586 ktip->is_loaded() && !ktip->klass()->is_interface()) { 3587 assert(!ftip->klass_is_exact(), "interface could not be exact"); 3588 return ktip->cast_to_ptr_type(ftip->ptr()); 3589 } 3590 3591 return ft; 3592 } 3593 3594 //------------------------------eq--------------------------------------------- 3595 // Structural equality check for Type representations 3596 bool TypeOopPtr::eq( const Type *t ) const { 3597 const TypeOopPtr *a = (const TypeOopPtr*)t; 3598 if (_klass_is_exact != a->_klass_is_exact || 3599 _instance_id != a->_instance_id) return false; 3600 ciObject* one = const_oop(); 3601 ciObject* two = a->const_oop(); 3602 if (one == NULL || two == NULL) { 3603 return (one == two) && TypePtr::eq(t); 3604 } else { 3605 return one->equals(two) && TypePtr::eq(t); 3606 } 3607 } 3608 3609 //------------------------------hash------------------------------------------- 3610 // Type-specific hashing function. 3611 int TypeOopPtr::hash(void) const { 3612 return 3613 java_add(java_add((jint)(const_oop() ? const_oop()->hash() : 0), (jint)_klass_is_exact), 3614 java_add((jint)_instance_id, (jint)TypePtr::hash())); 3615 } 3616 3617 //------------------------------dump2------------------------------------------ 3618 #ifndef PRODUCT 3619 void TypeOopPtr::dump2( Dict &d, uint depth, outputStream *st ) const { 3620 st->print("oopptr:%s", ptr_msg[_ptr]); 3621 if( _klass_is_exact ) st->print(":exact"); 3622 if( const_oop() ) st->print(INTPTR_FORMAT, p2i(const_oop())); 3623 _offset.dump2(st); 3624 if (_instance_id == InstanceTop) 3625 st->print(",iid=top"); 3626 else if (_instance_id != InstanceBot) 3627 st->print(",iid=%d",_instance_id); 3628 3629 dump_inline_depth(st); 3630 dump_speculative(st); 3631 } 3632 #endif 3633 3634 //------------------------------singleton-------------------------------------- 3635 // TRUE if Type is a singleton type, FALSE otherwise. Singletons are simple 3636 // constants 3637 bool TypeOopPtr::singleton(void) const { 3638 // detune optimizer to not generate constant oop + constant offset as a constant! 3639 // TopPTR, Null, AnyNull, Constant are all singletons 3640 return (offset() == 0) && !below_centerline(_ptr); 3641 } 3642 3643 //------------------------------add_offset------------------------------------- 3644 const TypePtr *TypeOopPtr::add_offset(intptr_t offset) const { 3645 return make(_ptr, xadd_offset(offset), _instance_id, add_offset_speculative(offset), _inline_depth); 3646 } 3647 3648 /** 3649 * Return same type without a speculative part 3650 */ 3651 const Type* TypeOopPtr::remove_speculative() const { 3652 if (_speculative == NULL) { 3653 return this; 3654 } 3655 assert(_inline_depth == InlineDepthTop || _inline_depth == InlineDepthBottom, "non speculative type shouldn't have inline depth"); 3656 return make(_ptr, _offset, _instance_id, NULL, _inline_depth); 3657 } 3658 3659 /** 3660 * Return same type but drop speculative part if we know we won't use 3661 * it 3662 */ 3663 const Type* TypeOopPtr::cleanup_speculative() const { 3664 // If the klass is exact and the ptr is not null then there's 3665 // nothing that the speculative type can help us with 3666 if (klass_is_exact() && !maybe_null()) { 3667 return remove_speculative(); 3668 } 3669 return TypePtr::cleanup_speculative(); 3670 } 3671 3672 /** 3673 * Return same type but with a different inline depth (used for speculation) 3674 * 3675 * @param depth depth to meet with 3676 */ 3677 const TypePtr* TypeOopPtr::with_inline_depth(int depth) const { 3678 if (!UseInlineDepthForSpeculativeTypes) { 3679 return this; 3680 } 3681 return make(_ptr, _offset, _instance_id, _speculative, depth); 3682 } 3683 3684 //------------------------------meet_instance_id-------------------------------- 3685 int TypeOopPtr::meet_instance_id( int instance_id ) const { 3686 // Either is 'TOP' instance? Return the other instance! 3687 if( _instance_id == InstanceTop ) return instance_id; 3688 if( instance_id == InstanceTop ) return _instance_id; 3689 // If either is different, return 'BOTTOM' instance 3690 if( _instance_id != instance_id ) return InstanceBot; 3691 return _instance_id; 3692 } 3693 3694 //------------------------------dual_instance_id-------------------------------- 3695 int TypeOopPtr::dual_instance_id( ) const { 3696 if( _instance_id == InstanceTop ) return InstanceBot; // Map TOP into BOTTOM 3697 if( _instance_id == InstanceBot ) return InstanceTop; // Map BOTTOM into TOP 3698 return _instance_id; // Map everything else into self 3699 } 3700 3701 /** 3702 * Check whether new profiling would improve speculative type 3703 * 3704 * @param exact_kls class from profiling 3705 * @param inline_depth inlining depth of profile point 3706 * 3707 * @return true if type profile is valuable 3708 */ 3709 bool TypeOopPtr::would_improve_type(ciKlass* exact_kls, int inline_depth) const { 3710 // no way to improve an already exact type 3711 if (klass_is_exact()) { 3712 return false; 3713 } 3714 return TypePtr::would_improve_type(exact_kls, inline_depth); 3715 } 3716 3717 //============================================================================= 3718 // Convenience common pre-built types. 3719 const TypeInstPtr *TypeInstPtr::NOTNULL; 3720 const TypeInstPtr *TypeInstPtr::BOTTOM; 3721 const TypeInstPtr *TypeInstPtr::MIRROR; 3722 const TypeInstPtr *TypeInstPtr::MARK; 3723 const TypeInstPtr *TypeInstPtr::KLASS; 3724 3725 //------------------------------TypeInstPtr------------------------------------- 3726 TypeInstPtr::TypeInstPtr(PTR ptr, ciKlass* k, bool xk, ciObject* o, Offset off, 3727 int instance_id, const TypePtr* speculative, int inline_depth) 3728 : TypeOopPtr(InstPtr, ptr, k, xk, o, off, Offset::bottom, instance_id, speculative, inline_depth), 3729 _name(k->name()) { 3730 assert(k != NULL && 3731 (k->is_loaded() || o == NULL), 3732 "cannot have constants with non-loaded klass"); 3733 }; 3734 3735 //------------------------------make------------------------------------------- 3736 const TypeInstPtr *TypeInstPtr::make(PTR ptr, 3737 ciKlass* k, 3738 bool xk, 3739 ciObject* o, 3740 Offset offset, 3741 int instance_id, 3742 const TypePtr* speculative, 3743 int inline_depth) { 3744 assert( !k->is_loaded() || k->is_instance_klass(), "Must be for instance"); 3745 // Either const_oop() is NULL or else ptr is Constant 3746 assert( (!o && ptr != Constant) || (o && ptr == Constant), 3747 "constant pointers must have a value supplied" ); 3748 // Ptr is never Null 3749 assert( ptr != Null, "NULL pointers are not typed" ); 3750 3751 assert(instance_id <= 0 || xk || !UseExactTypes, "instances are always exactly typed"); 3752 if (!UseExactTypes) xk = false; 3753 if (ptr == Constant) { 3754 // Note: This case includes meta-object constants, such as methods. 3755 xk = true; 3756 } else if (k->is_loaded()) { 3757 ciInstanceKlass* ik = k->as_instance_klass(); 3758 if (!xk && ik->is_final()) xk = true; // no inexact final klass 3759 if (xk && ik->is_interface()) xk = false; // no exact interface 3760 } 3761 3762 // Now hash this baby 3763 TypeInstPtr *result = 3764 (TypeInstPtr*)(new TypeInstPtr(ptr, k, xk, o ,offset, instance_id, speculative, inline_depth))->hashcons(); 3765 3766 return result; 3767 } 3768 3769 /** 3770 * Create constant type for a constant boxed value 3771 */ 3772 const Type* TypeInstPtr::get_const_boxed_value() const { 3773 assert(is_ptr_to_boxed_value(), "should be called only for boxed value"); 3774 assert((const_oop() != NULL), "should be called only for constant object"); 3775 ciConstant constant = const_oop()->as_instance()->field_value_by_offset(offset()); 3776 BasicType bt = constant.basic_type(); 3777 switch (bt) { 3778 case T_BOOLEAN: return TypeInt::make(constant.as_boolean()); 3779 case T_INT: return TypeInt::make(constant.as_int()); 3780 case T_CHAR: return TypeInt::make(constant.as_char()); 3781 case T_BYTE: return TypeInt::make(constant.as_byte()); 3782 case T_SHORT: return TypeInt::make(constant.as_short()); 3783 case T_FLOAT: return TypeF::make(constant.as_float()); 3784 case T_DOUBLE: return TypeD::make(constant.as_double()); 3785 case T_LONG: return TypeLong::make(constant.as_long()); 3786 default: break; 3787 } 3788 fatal("Invalid boxed value type '%s'", type2name(bt)); 3789 return NULL; 3790 } 3791 3792 //------------------------------cast_to_ptr_type------------------------------- 3793 const Type *TypeInstPtr::cast_to_ptr_type(PTR ptr) const { 3794 if( ptr == _ptr ) return this; 3795 // Reconstruct _sig info here since not a problem with later lazy 3796 // construction, _sig will show up on demand. 3797 return make(ptr, klass(), klass_is_exact(), const_oop(), _offset, _instance_id, _speculative, _inline_depth); 3798 } 3799 3800 3801 //-----------------------------cast_to_exactness------------------------------- 3802 const Type *TypeInstPtr::cast_to_exactness(bool klass_is_exact) const { 3803 if( klass_is_exact == _klass_is_exact ) return this; 3804 if (!UseExactTypes) return this; 3805 if (!_klass->is_loaded()) return this; 3806 ciInstanceKlass* ik = _klass->as_instance_klass(); 3807 if( (ik->is_final() || _const_oop) ) return this; // cannot clear xk 3808 if( ik->is_interface() ) return this; // cannot set xk 3809 return make(ptr(), klass(), klass_is_exact, const_oop(), _offset, _instance_id, _speculative, _inline_depth); 3810 } 3811 3812 //-----------------------------cast_to_instance_id---------------------------- 3813 const TypeOopPtr *TypeInstPtr::cast_to_instance_id(int instance_id) const { 3814 if( instance_id == _instance_id ) return this; 3815 return make(_ptr, klass(), _klass_is_exact, const_oop(), _offset, instance_id, _speculative, _inline_depth); 3816 } 3817 3818 //------------------------------xmeet_unloaded--------------------------------- 3819 // Compute the MEET of two InstPtrs when at least one is unloaded. 3820 // Assume classes are different since called after check for same name/class-loader 3821 const TypeInstPtr *TypeInstPtr::xmeet_unloaded(const TypeInstPtr *tinst) const { 3822 Offset off = meet_offset(tinst->offset()); 3823 PTR ptr = meet_ptr(tinst->ptr()); 3824 int instance_id = meet_instance_id(tinst->instance_id()); 3825 const TypePtr* speculative = xmeet_speculative(tinst); 3826 int depth = meet_inline_depth(tinst->inline_depth()); 3827 3828 const TypeInstPtr *loaded = is_loaded() ? this : tinst; 3829 const TypeInstPtr *unloaded = is_loaded() ? tinst : this; 3830 if( loaded->klass()->equals(ciEnv::current()->Object_klass()) ) { 3831 // 3832 // Meet unloaded class with java/lang/Object 3833 // 3834 // Meet 3835 // | Unloaded Class 3836 // Object | TOP | AnyNull | Constant | NotNull | BOTTOM | 3837 // =================================================================== 3838 // TOP | ..........................Unloaded......................| 3839 // AnyNull | U-AN |................Unloaded......................| 3840 // Constant | ... O-NN .................................. | O-BOT | 3841 // NotNull | ... O-NN .................................. | O-BOT | 3842 // BOTTOM | ........................Object-BOTTOM ..................| 3843 // 3844 assert(loaded->ptr() != TypePtr::Null, "insanity check"); 3845 // 3846 if( loaded->ptr() == TypePtr::TopPTR ) { return unloaded; } 3847 else if (loaded->ptr() == TypePtr::AnyNull) { return TypeInstPtr::make(ptr, unloaded->klass(), false, NULL, off, instance_id, speculative, depth); } 3848 else if (loaded->ptr() == TypePtr::BotPTR ) { return TypeInstPtr::BOTTOM; } 3849 else if (loaded->ptr() == TypePtr::Constant || loaded->ptr() == TypePtr::NotNull) { 3850 if (unloaded->ptr() == TypePtr::BotPTR ) { return TypeInstPtr::BOTTOM; } 3851 else { return TypeInstPtr::NOTNULL; } 3852 } 3853 else if( unloaded->ptr() == TypePtr::TopPTR ) { return unloaded; } 3854 3855 return unloaded->cast_to_ptr_type(TypePtr::AnyNull)->is_instptr(); 3856 } 3857 3858 // Both are unloaded, not the same class, not Object 3859 // Or meet unloaded with a different loaded class, not java/lang/Object 3860 if( ptr != TypePtr::BotPTR ) { 3861 return TypeInstPtr::NOTNULL; 3862 } 3863 return TypeInstPtr::BOTTOM; 3864 } 3865 3866 3867 //------------------------------meet------------------------------------------- 3868 // Compute the MEET of two types. It returns a new Type object. 3869 const Type *TypeInstPtr::xmeet_helper(const Type *t) const { 3870 // Perform a fast test for common case; meeting the same types together. 3871 if( this == t ) return this; // Meeting same type-rep? 3872 3873 // Current "this->_base" is Pointer 3874 switch (t->base()) { // switch on original type 3875 3876 case Int: // Mixing ints & oops happens when javac 3877 case Long: // reuses local variables 3878 case FloatTop: 3879 case FloatCon: 3880 case FloatBot: 3881 case DoubleTop: 3882 case DoubleCon: 3883 case DoubleBot: 3884 case NarrowOop: 3885 case NarrowKlass: 3886 case Bottom: // Ye Olde Default 3887 return Type::BOTTOM; 3888 case Top: 3889 return this; 3890 3891 default: // All else is a mistake 3892 typerr(t); 3893 3894 case MetadataPtr: 3895 case KlassPtr: 3896 case RawPtr: return TypePtr::BOTTOM; 3897 3898 case AryPtr: { // All arrays inherit from Object class 3899 const TypeAryPtr *tp = t->is_aryptr(); 3900 Offset offset = meet_offset(tp->offset()); 3901 PTR ptr = meet_ptr(tp->ptr()); 3902 int instance_id = meet_instance_id(tp->instance_id()); 3903 const TypePtr* speculative = xmeet_speculative(tp); 3904 int depth = meet_inline_depth(tp->inline_depth()); 3905 switch (ptr) { 3906 case TopPTR: 3907 case AnyNull: // Fall 'down' to dual of object klass 3908 // For instances when a subclass meets a superclass we fall 3909 // below the centerline when the superclass is exact. We need to 3910 // do the same here. 3911 if (klass()->equals(ciEnv::current()->Object_klass()) && !klass_is_exact()) { 3912 return TypeAryPtr::make(ptr, tp->ary(), tp->klass(), tp->klass_is_exact(), offset, tp->field_offset(), instance_id, speculative, depth); 3913 } else { 3914 // cannot subclass, so the meet has to fall badly below the centerline 3915 ptr = NotNull; 3916 instance_id = InstanceBot; 3917 return TypeInstPtr::make( ptr, ciEnv::current()->Object_klass(), false, NULL, offset, instance_id, speculative, depth); 3918 } 3919 case Constant: 3920 case NotNull: 3921 case BotPTR: // Fall down to object klass 3922 // LCA is object_klass, but if we subclass from the top we can do better 3923 if( above_centerline(_ptr) ) { // if( _ptr == TopPTR || _ptr == AnyNull ) 3924 // If 'this' (InstPtr) is above the centerline and it is Object class 3925 // then we can subclass in the Java class hierarchy. 3926 // For instances when a subclass meets a superclass we fall 3927 // below the centerline when the superclass is exact. We need 3928 // to do the same here. 3929 if (klass()->equals(ciEnv::current()->Object_klass()) && !klass_is_exact()) { 3930 // that is, tp's array type is a subtype of my klass 3931 return TypeAryPtr::make(ptr, (ptr == Constant ? tp->const_oop() : NULL), 3932 tp->ary(), tp->klass(), tp->klass_is_exact(), offset, tp->field_offset(), instance_id, speculative, depth); 3933 } 3934 } 3935 // The other case cannot happen, since I cannot be a subtype of an array. 3936 // The meet falls down to Object class below centerline. 3937 if( ptr == Constant ) 3938 ptr = NotNull; 3939 instance_id = InstanceBot; 3940 return make(ptr, ciEnv::current()->Object_klass(), false, NULL, offset, instance_id, speculative, depth); 3941 default: typerr(t); 3942 } 3943 } 3944 3945 case OopPtr: { // Meeting to OopPtrs 3946 // Found a OopPtr type vs self-InstPtr type 3947 const TypeOopPtr *tp = t->is_oopptr(); 3948 Offset offset = meet_offset(tp->offset()); 3949 PTR ptr = meet_ptr(tp->ptr()); 3950 switch (tp->ptr()) { 3951 case TopPTR: 3952 case AnyNull: { 3953 int instance_id = meet_instance_id(InstanceTop); 3954 const TypePtr* speculative = xmeet_speculative(tp); 3955 int depth = meet_inline_depth(tp->inline_depth()); 3956 return make(ptr, klass(), klass_is_exact(), 3957 (ptr == Constant ? const_oop() : NULL), offset, instance_id, speculative, depth); 3958 } 3959 case NotNull: 3960 case BotPTR: { 3961 int instance_id = meet_instance_id(tp->instance_id()); 3962 const TypePtr* speculative = xmeet_speculative(tp); 3963 int depth = meet_inline_depth(tp->inline_depth()); 3964 return TypeOopPtr::make(ptr, offset, instance_id, speculative, depth); 3965 } 3966 default: typerr(t); 3967 } 3968 } 3969 3970 case AnyPtr: { // Meeting to AnyPtrs 3971 // Found an AnyPtr type vs self-InstPtr type 3972 const TypePtr *tp = t->is_ptr(); 3973 Offset offset = meet_offset(tp->offset()); 3974 PTR ptr = meet_ptr(tp->ptr()); 3975 int instance_id = meet_instance_id(InstanceTop); 3976 const TypePtr* speculative = xmeet_speculative(tp); 3977 int depth = meet_inline_depth(tp->inline_depth()); 3978 switch (tp->ptr()) { 3979 case Null: 3980 if( ptr == Null ) return TypePtr::make(AnyPtr, ptr, offset, speculative, depth); 3981 // else fall through to AnyNull 3982 case TopPTR: 3983 case AnyNull: { 3984 return make(ptr, klass(), klass_is_exact(), 3985 (ptr == Constant ? const_oop() : NULL), offset, instance_id, speculative, depth); 3986 } 3987 case NotNull: 3988 case BotPTR: 3989 return TypePtr::make(AnyPtr, ptr, offset, speculative,depth); 3990 default: typerr(t); 3991 } 3992 } 3993 3994 /* 3995 A-top } 3996 / | \ } Tops 3997 B-top A-any C-top } 3998 | / | \ | } Any-nulls 3999 B-any | C-any } 4000 | | | 4001 B-con A-con C-con } constants; not comparable across classes 4002 | | | 4003 B-not | C-not } 4004 | \ | / | } not-nulls 4005 B-bot A-not C-bot } 4006 \ | / } Bottoms 4007 A-bot } 4008 */ 4009 4010 case InstPtr: { // Meeting 2 Oops? 4011 // Found an InstPtr sub-type vs self-InstPtr type 4012 const TypeInstPtr *tinst = t->is_instptr(); 4013 Offset off = meet_offset( tinst->offset() ); 4014 PTR ptr = meet_ptr( tinst->ptr() ); 4015 int instance_id = meet_instance_id(tinst->instance_id()); 4016 const TypePtr* speculative = xmeet_speculative(tinst); 4017 int depth = meet_inline_depth(tinst->inline_depth()); 4018 4019 // Check for easy case; klasses are equal (and perhaps not loaded!) 4020 // If we have constants, then we created oops so classes are loaded 4021 // and we can handle the constants further down. This case handles 4022 // both-not-loaded or both-loaded classes 4023 if (ptr != Constant && klass()->equals(tinst->klass()) && klass_is_exact() == tinst->klass_is_exact()) { 4024 return make(ptr, klass(), klass_is_exact(), NULL, off, instance_id, speculative, depth); 4025 } 4026 4027 // Classes require inspection in the Java klass hierarchy. Must be loaded. 4028 ciKlass* tinst_klass = tinst->klass(); 4029 ciKlass* this_klass = this->klass(); 4030 bool tinst_xk = tinst->klass_is_exact(); 4031 bool this_xk = this->klass_is_exact(); 4032 if (!tinst_klass->is_loaded() || !this_klass->is_loaded() ) { 4033 // One of these classes has not been loaded 4034 const TypeInstPtr *unloaded_meet = xmeet_unloaded(tinst); 4035 #ifndef PRODUCT 4036 if( PrintOpto && Verbose ) { 4037 tty->print("meet of unloaded classes resulted in: "); unloaded_meet->dump(); tty->cr(); 4038 tty->print(" this == "); this->dump(); tty->cr(); 4039 tty->print(" tinst == "); tinst->dump(); tty->cr(); 4040 } 4041 #endif 4042 return unloaded_meet; 4043 } 4044 4045 // Handle mixing oops and interfaces first. 4046 if( this_klass->is_interface() && !(tinst_klass->is_interface() || 4047 tinst_klass == ciEnv::current()->Object_klass())) { 4048 ciKlass *tmp = tinst_klass; // Swap interface around 4049 tinst_klass = this_klass; 4050 this_klass = tmp; 4051 bool tmp2 = tinst_xk; 4052 tinst_xk = this_xk; 4053 this_xk = tmp2; 4054 } 4055 if (tinst_klass->is_interface() && 4056 !(this_klass->is_interface() || 4057 // Treat java/lang/Object as an honorary interface, 4058 // because we need a bottom for the interface hierarchy. 4059 this_klass == ciEnv::current()->Object_klass())) { 4060 // Oop meets interface! 4061 4062 // See if the oop subtypes (implements) interface. 4063 ciKlass *k; 4064 bool xk; 4065 if( this_klass->is_subtype_of( tinst_klass ) ) { 4066 // Oop indeed subtypes. Now keep oop or interface depending 4067 // on whether we are both above the centerline or either is 4068 // below the centerline. If we are on the centerline 4069 // (e.g., Constant vs. AnyNull interface), use the constant. 4070 k = below_centerline(ptr) ? tinst_klass : this_klass; 4071 // If we are keeping this_klass, keep its exactness too. 4072 xk = below_centerline(ptr) ? tinst_xk : this_xk; 4073 } else { // Does not implement, fall to Object 4074 // Oop does not implement interface, so mixing falls to Object 4075 // just like the verifier does (if both are above the 4076 // centerline fall to interface) 4077 k = above_centerline(ptr) ? tinst_klass : ciEnv::current()->Object_klass(); 4078 xk = above_centerline(ptr) ? tinst_xk : false; 4079 // Watch out for Constant vs. AnyNull interface. 4080 if (ptr == Constant) ptr = NotNull; // forget it was a constant 4081 instance_id = InstanceBot; 4082 } 4083 ciObject* o = NULL; // the Constant value, if any 4084 if (ptr == Constant) { 4085 // Find out which constant. 4086 o = (this_klass == klass()) ? const_oop() : tinst->const_oop(); 4087 } 4088 return make(ptr, k, xk, o, off, instance_id, speculative, depth); 4089 } 4090 4091 // Either oop vs oop or interface vs interface or interface vs Object 4092 4093 // !!! Here's how the symmetry requirement breaks down into invariants: 4094 // If we split one up & one down AND they subtype, take the down man. 4095 // If we split one up & one down AND they do NOT subtype, "fall hard". 4096 // If both are up and they subtype, take the subtype class. 4097 // If both are up and they do NOT subtype, "fall hard". 4098 // If both are down and they subtype, take the supertype class. 4099 // If both are down and they do NOT subtype, "fall hard". 4100 // Constants treated as down. 4101 4102 // Now, reorder the above list; observe that both-down+subtype is also 4103 // "fall hard"; "fall hard" becomes the default case: 4104 // If we split one up & one down AND they subtype, take the down man. 4105 // If both are up and they subtype, take the subtype class. 4106 4107 // If both are down and they subtype, "fall hard". 4108 // If both are down and they do NOT subtype, "fall hard". 4109 // If both are up and they do NOT subtype, "fall hard". 4110 // If we split one up & one down AND they do NOT subtype, "fall hard". 4111 4112 // If a proper subtype is exact, and we return it, we return it exactly. 4113 // If a proper supertype is exact, there can be no subtyping relationship! 4114 // If both types are equal to the subtype, exactness is and-ed below the 4115 // centerline and or-ed above it. (N.B. Constants are always exact.) 4116 4117 // Check for subtyping: 4118 ciKlass *subtype = NULL; 4119 bool subtype_exact = false; 4120 if( tinst_klass->equals(this_klass) ) { 4121 subtype = this_klass; 4122 subtype_exact = below_centerline(ptr) ? (this_xk & tinst_xk) : (this_xk | tinst_xk); 4123 } else if( !tinst_xk && this_klass->is_subtype_of( tinst_klass ) ) { 4124 subtype = this_klass; // Pick subtyping class 4125 subtype_exact = this_xk; 4126 } else if( !this_xk && tinst_klass->is_subtype_of( this_klass ) ) { 4127 subtype = tinst_klass; // Pick subtyping class 4128 subtype_exact = tinst_xk; 4129 } 4130 4131 if( subtype ) { 4132 if( above_centerline(ptr) ) { // both are up? 4133 this_klass = tinst_klass = subtype; 4134 this_xk = tinst_xk = subtype_exact; 4135 } else if( above_centerline(this ->_ptr) && !above_centerline(tinst->_ptr) ) { 4136 this_klass = tinst_klass; // tinst is down; keep down man 4137 this_xk = tinst_xk; 4138 } else if( above_centerline(tinst->_ptr) && !above_centerline(this ->_ptr) ) { 4139 tinst_klass = this_klass; // this is down; keep down man 4140 tinst_xk = this_xk; 4141 } else { 4142 this_xk = subtype_exact; // either they are equal, or we'll do an LCA 4143 } 4144 } 4145 4146 // Check for classes now being equal 4147 if (tinst_klass->equals(this_klass)) { 4148 // If the klasses are equal, the constants may still differ. Fall to 4149 // NotNull if they do (neither constant is NULL; that is a special case 4150 // handled elsewhere). 4151 ciObject* o = NULL; // Assume not constant when done 4152 ciObject* this_oop = const_oop(); 4153 ciObject* tinst_oop = tinst->const_oop(); 4154 if( ptr == Constant ) { 4155 if (this_oop != NULL && tinst_oop != NULL && 4156 this_oop->equals(tinst_oop) ) 4157 o = this_oop; 4158 else if (above_centerline(this ->_ptr)) 4159 o = tinst_oop; 4160 else if (above_centerline(tinst ->_ptr)) 4161 o = this_oop; 4162 else 4163 ptr = NotNull; 4164 } 4165 return make(ptr, this_klass, this_xk, o, off, instance_id, speculative, depth); 4166 } // Else classes are not equal 4167 4168 // Since klasses are different, we require a LCA in the Java 4169 // class hierarchy - which means we have to fall to at least NotNull. 4170 if( ptr == TopPTR || ptr == AnyNull || ptr == Constant ) 4171 ptr = NotNull; 4172 4173 instance_id = InstanceBot; 4174 4175 // Now we find the LCA of Java classes 4176 ciKlass* k = this_klass->least_common_ancestor(tinst_klass); 4177 return make(ptr, k, false, NULL, off, instance_id, speculative, depth); 4178 } // End of case InstPtr 4179 4180 case ValueType: { 4181 const TypeValueType *tv = t->is_valuetype(); 4182 4183 if (above_centerline(ptr())) { 4184 if (tv->value_klass()->is_subtype_of(_klass)) { 4185 return t; 4186 } else { 4187 return TypeInstPtr::make(NotNull, _klass); 4188 } 4189 } else { 4190 if (tv->value_klass()->is_subtype_of(_klass)) { 4191 return TypeInstPtr::make(ptr(), _klass); 4192 } else { 4193 return TypeInstPtr::make(ptr(), ciEnv::current()->Object_klass()); 4194 } 4195 } 4196 } 4197 4198 } // End of switch 4199 return this; // Return the double constant 4200 } 4201 4202 4203 //------------------------java_mirror_type-------------------------------------- 4204 ciType* TypeInstPtr::java_mirror_type() const { 4205 // must be a singleton type 4206 if( const_oop() == NULL ) return NULL; 4207 4208 // must be of type java.lang.Class 4209 if( klass() != ciEnv::current()->Class_klass() ) return NULL; 4210 4211 return const_oop()->as_instance()->java_mirror_type(); 4212 } 4213 4214 4215 //------------------------------xdual------------------------------------------ 4216 // Dual: do NOT dual on klasses. This means I do NOT understand the Java 4217 // inheritance mechanism. 4218 const Type *TypeInstPtr::xdual() const { 4219 return new TypeInstPtr(dual_ptr(), klass(), klass_is_exact(), const_oop(), dual_offset(), dual_instance_id(), dual_speculative(), dual_inline_depth()); 4220 } 4221 4222 //------------------------------eq--------------------------------------------- 4223 // Structural equality check for Type representations 4224 bool TypeInstPtr::eq( const Type *t ) const { 4225 const TypeInstPtr *p = t->is_instptr(); 4226 return 4227 klass()->equals(p->klass()) && 4228 TypeOopPtr::eq(p); // Check sub-type stuff 4229 } 4230 4231 //------------------------------hash------------------------------------------- 4232 // Type-specific hashing function. 4233 int TypeInstPtr::hash(void) const { 4234 int hash = java_add((jint)klass()->hash(), (jint)TypeOopPtr::hash()); 4235 return hash; 4236 } 4237 4238 //------------------------------dump2------------------------------------------ 4239 // Dump oop Type 4240 #ifndef PRODUCT 4241 void TypeInstPtr::dump2( Dict &d, uint depth, outputStream *st ) const { 4242 // Print the name of the klass. 4243 klass()->print_name_on(st); 4244 4245 switch( _ptr ) { 4246 case Constant: 4247 // TO DO: Make CI print the hex address of the underlying oop. 4248 if (WizardMode || Verbose) { 4249 const_oop()->print_oop(st); 4250 } 4251 case BotPTR: 4252 if (!WizardMode && !Verbose) { 4253 if( _klass_is_exact ) st->print(":exact"); 4254 break; 4255 } 4256 case TopPTR: 4257 case AnyNull: 4258 case NotNull: 4259 st->print(":%s", ptr_msg[_ptr]); 4260 if( _klass_is_exact ) st->print(":exact"); 4261 break; 4262 default: 4263 break; 4264 } 4265 4266 _offset.dump2(st); 4267 4268 st->print(" *"); 4269 if (_instance_id == InstanceTop) 4270 st->print(",iid=top"); 4271 else if (_instance_id != InstanceBot) 4272 st->print(",iid=%d",_instance_id); 4273 4274 dump_inline_depth(st); 4275 dump_speculative(st); 4276 } 4277 #endif 4278 4279 //------------------------------add_offset------------------------------------- 4280 const TypePtr *TypeInstPtr::add_offset(intptr_t offset) const { 4281 return make(_ptr, klass(), klass_is_exact(), const_oop(), xadd_offset(offset), 4282 _instance_id, add_offset_speculative(offset), _inline_depth); 4283 } 4284 4285 const Type *TypeInstPtr::remove_speculative() const { 4286 if (_speculative == NULL) { 4287 return this; 4288 } 4289 assert(_inline_depth == InlineDepthTop || _inline_depth == InlineDepthBottom, "non speculative type shouldn't have inline depth"); 4290 return make(_ptr, klass(), klass_is_exact(), const_oop(), _offset, 4291 _instance_id, NULL, _inline_depth); 4292 } 4293 4294 const TypePtr *TypeInstPtr::with_inline_depth(int depth) const { 4295 if (!UseInlineDepthForSpeculativeTypes) { 4296 return this; 4297 } 4298 return make(_ptr, klass(), klass_is_exact(), const_oop(), _offset, _instance_id, _speculative, depth); 4299 } 4300 4301 //============================================================================= 4302 // Convenience common pre-built types. 4303 const TypeAryPtr *TypeAryPtr::RANGE; 4304 const TypeAryPtr *TypeAryPtr::OOPS; 4305 const TypeAryPtr *TypeAryPtr::NARROWOOPS; 4306 const TypeAryPtr *TypeAryPtr::BYTES; 4307 const TypeAryPtr *TypeAryPtr::SHORTS; 4308 const TypeAryPtr *TypeAryPtr::CHARS; 4309 const TypeAryPtr *TypeAryPtr::INTS; 4310 const TypeAryPtr *TypeAryPtr::LONGS; 4311 const TypeAryPtr *TypeAryPtr::FLOATS; 4312 const TypeAryPtr *TypeAryPtr::DOUBLES; 4313 4314 //------------------------------make------------------------------------------- 4315 const TypeAryPtr* TypeAryPtr::make(PTR ptr, const TypeAry *ary, ciKlass* k, bool xk, Offset offset, Offset field_offset, 4316 int instance_id, const TypePtr* speculative, int inline_depth) { 4317 assert(!(k == NULL && ary->_elem->isa_int()), 4318 "integral arrays must be pre-equipped with a class"); 4319 if (!xk) xk = ary->ary_must_be_exact(); 4320 assert(instance_id <= 0 || xk || !UseExactTypes, "instances are always exactly typed"); 4321 if (!UseExactTypes) xk = (ptr == Constant); 4322 return (TypeAryPtr*)(new TypeAryPtr(ptr, NULL, ary, k, xk, offset, field_offset, instance_id, false, speculative, inline_depth))->hashcons(); 4323 } 4324 4325 //------------------------------make------------------------------------------- 4326 const TypeAryPtr* TypeAryPtr::make(PTR ptr, ciObject* o, const TypeAry *ary, ciKlass* k, bool xk, Offset offset, Offset field_offset, 4327 int instance_id, const TypePtr* speculative, int inline_depth, 4328 bool is_autobox_cache) { 4329 assert(!(k == NULL && ary->_elem->isa_int()), 4330 "integral arrays must be pre-equipped with a class"); 4331 assert( (ptr==Constant && o) || (ptr!=Constant && !o), "" ); 4332 if (!xk) xk = (o != NULL) || ary->ary_must_be_exact(); 4333 assert(instance_id <= 0 || xk || !UseExactTypes, "instances are always exactly typed"); 4334 if (!UseExactTypes) xk = (ptr == Constant); 4335 return (TypeAryPtr*)(new TypeAryPtr(ptr, o, ary, k, xk, offset, field_offset, instance_id, is_autobox_cache, speculative, inline_depth))->hashcons(); 4336 } 4337 4338 //------------------------------cast_to_ptr_type------------------------------- 4339 const Type *TypeAryPtr::cast_to_ptr_type(PTR ptr) const { 4340 if( ptr == _ptr ) return this; 4341 return make(ptr, const_oop(), _ary, klass(), klass_is_exact(), _offset, _field_offset, _instance_id, _speculative, _inline_depth, _is_autobox_cache); 4342 } 4343 4344 4345 //-----------------------------cast_to_exactness------------------------------- 4346 const Type *TypeAryPtr::cast_to_exactness(bool klass_is_exact) const { 4347 if( klass_is_exact == _klass_is_exact ) return this; 4348 if (!UseExactTypes) return this; 4349 if (_ary->ary_must_be_exact()) return this; // cannot clear xk 4350 return make(ptr(), const_oop(), _ary, klass(), klass_is_exact, _offset, _field_offset, _instance_id, _speculative, _inline_depth, _is_autobox_cache); 4351 } 4352 4353 //-----------------------------cast_to_instance_id---------------------------- 4354 const TypeOopPtr *TypeAryPtr::cast_to_instance_id(int instance_id) const { 4355 if( instance_id == _instance_id ) return this; 4356 return make(_ptr, const_oop(), _ary, klass(), _klass_is_exact, _offset, _field_offset, instance_id, _speculative, _inline_depth, _is_autobox_cache); 4357 } 4358 4359 //-----------------------------narrow_size_type------------------------------- 4360 // Local cache for arrayOopDesc::max_array_length(etype), 4361 // which is kind of slow (and cached elsewhere by other users). 4362 static jint max_array_length_cache[T_CONFLICT+1]; 4363 static jint max_array_length(BasicType etype) { 4364 jint& cache = max_array_length_cache[etype]; 4365 jint res = cache; 4366 if (res == 0) { 4367 switch (etype) { 4368 case T_NARROWOOP: 4369 etype = T_OBJECT; 4370 break; 4371 case T_NARROWKLASS: 4372 case T_CONFLICT: 4373 case T_ILLEGAL: 4374 case T_VOID: 4375 etype = T_BYTE; // will produce conservatively high value 4376 break; 4377 default: 4378 break; 4379 } 4380 cache = res = arrayOopDesc::max_array_length(etype); 4381 } 4382 return res; 4383 } 4384 4385 // Narrow the given size type to the index range for the given array base type. 4386 // Return NULL if the resulting int type becomes empty. 4387 const TypeInt* TypeAryPtr::narrow_size_type(const TypeInt* size) const { 4388 jint hi = size->_hi; 4389 jint lo = size->_lo; 4390 jint min_lo = 0; 4391 jint max_hi = max_array_length(elem()->basic_type()); 4392 //if (index_not_size) --max_hi; // type of a valid array index, FTR 4393 bool chg = false; 4394 if (lo < min_lo) { 4395 lo = min_lo; 4396 if (size->is_con()) { 4397 hi = lo; 4398 } 4399 chg = true; 4400 } 4401 if (hi > max_hi) { 4402 hi = max_hi; 4403 if (size->is_con()) { 4404 lo = hi; 4405 } 4406 chg = true; 4407 } 4408 // Negative length arrays will produce weird intermediate dead fast-path code 4409 if (lo > hi) 4410 return TypeInt::ZERO; 4411 if (!chg) 4412 return size; 4413 return TypeInt::make(lo, hi, Type::WidenMin); 4414 } 4415 4416 //-------------------------------cast_to_size---------------------------------- 4417 const TypeAryPtr* TypeAryPtr::cast_to_size(const TypeInt* new_size) const { 4418 assert(new_size != NULL, ""); 4419 new_size = narrow_size_type(new_size); 4420 if (new_size == size()) return this; 4421 const TypeAry* new_ary = TypeAry::make(elem(), new_size, is_stable()); 4422 return make(ptr(), const_oop(), new_ary, klass(), klass_is_exact(), _offset, _field_offset, _instance_id, _speculative, _inline_depth, _is_autobox_cache); 4423 } 4424 4425 //------------------------------cast_to_stable--------------------------------- 4426 const TypeAryPtr* TypeAryPtr::cast_to_stable(bool stable, int stable_dimension) const { 4427 if (stable_dimension <= 0 || (stable_dimension == 1 && stable == this->is_stable())) 4428 return this; 4429 4430 const Type* elem = this->elem(); 4431 const TypePtr* elem_ptr = elem->make_ptr(); 4432 4433 if (stable_dimension > 1 && elem_ptr != NULL && elem_ptr->isa_aryptr()) { 4434 // If this is widened from a narrow oop, TypeAry::make will re-narrow it. 4435 elem = elem_ptr = elem_ptr->is_aryptr()->cast_to_stable(stable, stable_dimension - 1); 4436 } 4437 4438 const TypeAry* new_ary = TypeAry::make(elem, size(), stable); 4439 4440 return make(ptr(), const_oop(), new_ary, klass(), klass_is_exact(), _offset, _field_offset, _instance_id, _speculative, _inline_depth, _is_autobox_cache); 4441 } 4442 4443 //-----------------------------stable_dimension-------------------------------- 4444 int TypeAryPtr::stable_dimension() const { 4445 if (!is_stable()) return 0; 4446 int dim = 1; 4447 const TypePtr* elem_ptr = elem()->make_ptr(); 4448 if (elem_ptr != NULL && elem_ptr->isa_aryptr()) 4449 dim += elem_ptr->is_aryptr()->stable_dimension(); 4450 return dim; 4451 } 4452 4453 //----------------------cast_to_autobox_cache----------------------------------- 4454 const TypeAryPtr* TypeAryPtr::cast_to_autobox_cache(bool cache) const { 4455 if (is_autobox_cache() == cache) return this; 4456 const TypeOopPtr* etype = elem()->make_oopptr(); 4457 if (etype == NULL) return this; 4458 // The pointers in the autobox arrays are always non-null. 4459 TypePtr::PTR ptr_type = cache ? TypePtr::NotNull : TypePtr::AnyNull; 4460 etype = etype->cast_to_ptr_type(TypePtr::NotNull)->is_oopptr(); 4461 const TypeAry* new_ary = TypeAry::make(etype, size(), is_stable()); 4462 return make(ptr(), const_oop(), new_ary, klass(), klass_is_exact(), _offset, _field_offset, _instance_id, _speculative, _inline_depth, cache); 4463 } 4464 4465 //------------------------------eq--------------------------------------------- 4466 // Structural equality check for Type representations 4467 bool TypeAryPtr::eq( const Type *t ) const { 4468 const TypeAryPtr *p = t->is_aryptr(); 4469 return 4470 _ary == p->_ary && // Check array 4471 TypeOopPtr::eq(p) &&// Check sub-parts 4472 _field_offset == p->_field_offset; 4473 } 4474 4475 //------------------------------hash------------------------------------------- 4476 // Type-specific hashing function. 4477 int TypeAryPtr::hash(void) const { 4478 return (intptr_t)_ary + TypeOopPtr::hash() + _field_offset.get(); 4479 } 4480 4481 //------------------------------meet------------------------------------------- 4482 // Compute the MEET of two types. It returns a new Type object. 4483 const Type *TypeAryPtr::xmeet_helper(const Type *t) const { 4484 // Perform a fast test for common case; meeting the same types together. 4485 if( this == t ) return this; // Meeting same type-rep? 4486 // Current "this->_base" is Pointer 4487 switch (t->base()) { // switch on original type 4488 4489 // Mixing ints & oops happens when javac reuses local variables 4490 case Int: 4491 case Long: 4492 case FloatTop: 4493 case FloatCon: 4494 case FloatBot: 4495 case DoubleTop: 4496 case DoubleCon: 4497 case DoubleBot: 4498 case NarrowOop: 4499 case NarrowKlass: 4500 case Bottom: // Ye Olde Default 4501 return Type::BOTTOM; 4502 case Top: 4503 return this; 4504 4505 default: // All else is a mistake 4506 typerr(t); 4507 4508 case OopPtr: { // Meeting to OopPtrs 4509 // Found a OopPtr type vs self-AryPtr type 4510 const TypeOopPtr *tp = t->is_oopptr(); 4511 Offset offset = meet_offset(tp->offset()); 4512 PTR ptr = meet_ptr(tp->ptr()); 4513 int depth = meet_inline_depth(tp->inline_depth()); 4514 const TypePtr* speculative = xmeet_speculative(tp); 4515 switch (tp->ptr()) { 4516 case TopPTR: 4517 case AnyNull: { 4518 int instance_id = meet_instance_id(InstanceTop); 4519 return make(ptr, (ptr == Constant ? const_oop() : NULL), 4520 _ary, _klass, _klass_is_exact, offset, _field_offset, instance_id, speculative, depth); 4521 } 4522 case BotPTR: 4523 case NotNull: { 4524 int instance_id = meet_instance_id(tp->instance_id()); 4525 return TypeOopPtr::make(ptr, offset, instance_id, speculative, depth); 4526 } 4527 default: ShouldNotReachHere(); 4528 } 4529 } 4530 4531 case AnyPtr: { // Meeting two AnyPtrs 4532 // Found an AnyPtr type vs self-AryPtr type 4533 const TypePtr *tp = t->is_ptr(); 4534 Offset offset = meet_offset(tp->offset()); 4535 PTR ptr = meet_ptr(tp->ptr()); 4536 const TypePtr* speculative = xmeet_speculative(tp); 4537 int depth = meet_inline_depth(tp->inline_depth()); 4538 switch (tp->ptr()) { 4539 case TopPTR: 4540 return this; 4541 case BotPTR: 4542 case NotNull: 4543 return TypePtr::make(AnyPtr, ptr, offset, speculative, depth); 4544 case Null: 4545 if( ptr == Null ) return TypePtr::make(AnyPtr, ptr, offset, speculative, depth); 4546 // else fall through to AnyNull 4547 case AnyNull: { 4548 int instance_id = meet_instance_id(InstanceTop); 4549 return make(ptr, (ptr == Constant ? const_oop() : NULL), 4550 _ary, _klass, _klass_is_exact, offset, _field_offset, instance_id, speculative, depth); 4551 } 4552 default: ShouldNotReachHere(); 4553 } 4554 } 4555 4556 case MetadataPtr: 4557 case KlassPtr: 4558 case RawPtr: return TypePtr::BOTTOM; 4559 4560 case AryPtr: { // Meeting 2 references? 4561 const TypeAryPtr *tap = t->is_aryptr(); 4562 Offset off = meet_offset(tap->offset()); 4563 Offset field_off = meet_field_offset(tap->field_offset()); 4564 const TypeAry *tary = _ary->meet_speculative(tap->_ary)->is_ary(); 4565 PTR ptr = meet_ptr(tap->ptr()); 4566 int instance_id = meet_instance_id(tap->instance_id()); 4567 const TypePtr* speculative = xmeet_speculative(tap); 4568 int depth = meet_inline_depth(tap->inline_depth()); 4569 ciKlass* lazy_klass = NULL; 4570 if (tary->_elem->isa_int()) { 4571 // Integral array element types have irrelevant lattice relations. 4572 // It is the klass that determines array layout, not the element type. 4573 if (_klass == NULL) 4574 lazy_klass = tap->_klass; 4575 else if (tap->_klass == NULL || tap->_klass == _klass) { 4576 lazy_klass = _klass; 4577 } else { 4578 // Something like byte[int+] meets char[int+]. 4579 // This must fall to bottom, not (int[-128..65535])[int+]. 4580 instance_id = InstanceBot; 4581 tary = TypeAry::make(Type::BOTTOM, tary->_size, tary->_stable); 4582 } 4583 } else // Non integral arrays. 4584 // Must fall to bottom if exact klasses in upper lattice 4585 // are not equal or super klass is exact. 4586 if ((above_centerline(ptr) || ptr == Constant) && klass() != tap->klass() && 4587 // meet with top[] and bottom[] are processed further down: 4588 tap->_klass != NULL && this->_klass != NULL && 4589 // both are exact and not equal: 4590 ((tap->_klass_is_exact && this->_klass_is_exact) || 4591 // 'tap' is exact and super or unrelated: 4592 (tap->_klass_is_exact && !tap->klass()->is_subtype_of(klass())) || 4593 // 'this' is exact and super or unrelated: 4594 (this->_klass_is_exact && !klass()->is_subtype_of(tap->klass())))) { 4595 if (above_centerline(ptr)) { 4596 tary = TypeAry::make(Type::BOTTOM, tary->_size, tary->_stable); 4597 } 4598 return make(NotNull, NULL, tary, lazy_klass, false, off, field_off, InstanceBot, speculative, depth); 4599 } 4600 4601 bool xk = false; 4602 switch (tap->ptr()) { 4603 case AnyNull: 4604 case TopPTR: 4605 // Compute new klass on demand, do not use tap->_klass 4606 if (below_centerline(this->_ptr)) { 4607 xk = this->_klass_is_exact; 4608 } else { 4609 xk = (tap->_klass_is_exact | this->_klass_is_exact); 4610 } 4611 return make(ptr, const_oop(), tary, lazy_klass, xk, off, field_off, instance_id, speculative, depth); 4612 case Constant: { 4613 ciObject* o = const_oop(); 4614 if( _ptr == Constant ) { 4615 if( tap->const_oop() != NULL && !o->equals(tap->const_oop()) ) { 4616 xk = (klass() == tap->klass()); 4617 ptr = NotNull; 4618 o = NULL; 4619 instance_id = InstanceBot; 4620 } else { 4621 xk = true; 4622 } 4623 } else if(above_centerline(_ptr)) { 4624 o = tap->const_oop(); 4625 xk = true; 4626 } else { 4627 // Only precise for identical arrays 4628 xk = this->_klass_is_exact && (klass() == tap->klass()); 4629 } 4630 return TypeAryPtr::make(ptr, o, tary, lazy_klass, xk, off, field_off, instance_id, speculative, depth); 4631 } 4632 case NotNull: 4633 case BotPTR: 4634 // Compute new klass on demand, do not use tap->_klass 4635 if (above_centerline(this->_ptr)) 4636 xk = tap->_klass_is_exact; 4637 else xk = (tap->_klass_is_exact & this->_klass_is_exact) && 4638 (klass() == tap->klass()); // Only precise for identical arrays 4639 return TypeAryPtr::make(ptr, NULL, tary, lazy_klass, xk, off, field_off, instance_id, speculative, depth); 4640 default: ShouldNotReachHere(); 4641 } 4642 } 4643 4644 // All arrays inherit from Object class 4645 case InstPtr: { 4646 const TypeInstPtr *tp = t->is_instptr(); 4647 Offset offset = meet_offset(tp->offset()); 4648 PTR ptr = meet_ptr(tp->ptr()); 4649 int instance_id = meet_instance_id(tp->instance_id()); 4650 const TypePtr* speculative = xmeet_speculative(tp); 4651 int depth = meet_inline_depth(tp->inline_depth()); 4652 switch (ptr) { 4653 case TopPTR: 4654 case AnyNull: // Fall 'down' to dual of object klass 4655 // For instances when a subclass meets a superclass we fall 4656 // below the centerline when the superclass is exact. We need to 4657 // do the same here. 4658 if (tp->klass()->equals(ciEnv::current()->Object_klass()) && !tp->klass_is_exact()) { 4659 return TypeAryPtr::make(ptr, _ary, _klass, _klass_is_exact, offset, _field_offset, instance_id, speculative, depth); 4660 } else { 4661 // cannot subclass, so the meet has to fall badly below the centerline 4662 ptr = NotNull; 4663 instance_id = InstanceBot; 4664 return TypeInstPtr::make(ptr, ciEnv::current()->Object_klass(), false, NULL, offset, instance_id, speculative, depth); 4665 } 4666 case Constant: 4667 case NotNull: 4668 case BotPTR: // Fall down to object klass 4669 // LCA is object_klass, but if we subclass from the top we can do better 4670 if (above_centerline(tp->ptr())) { 4671 // If 'tp' is above the centerline and it is Object class 4672 // then we can subclass in the Java class hierarchy. 4673 // For instances when a subclass meets a superclass we fall 4674 // below the centerline when the superclass is exact. We need 4675 // to do the same here. 4676 if (tp->klass()->equals(ciEnv::current()->Object_klass()) && !tp->klass_is_exact()) { 4677 // that is, my array type is a subtype of 'tp' klass 4678 return make(ptr, (ptr == Constant ? const_oop() : NULL), 4679 _ary, _klass, _klass_is_exact, offset, _field_offset, instance_id, speculative, depth); 4680 } 4681 } 4682 // The other case cannot happen, since t cannot be a subtype of an array. 4683 // The meet falls down to Object class below centerline. 4684 if( ptr == Constant ) 4685 ptr = NotNull; 4686 instance_id = InstanceBot; 4687 return TypeInstPtr::make(ptr, ciEnv::current()->Object_klass(), false, NULL,offset, instance_id, speculative, depth); 4688 default: typerr(t); 4689 } 4690 } 4691 4692 case ValueType: { 4693 // All value types inherit from Object 4694 return TypeInstPtr::make(ptr(), ciEnv::current()->Object_klass()); 4695 } 4696 4697 } 4698 return this; // Lint noise 4699 } 4700 4701 //------------------------------xdual------------------------------------------ 4702 // Dual: compute field-by-field dual 4703 const Type *TypeAryPtr::xdual() const { 4704 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()); 4705 } 4706 4707 Type::Offset TypeAryPtr::meet_field_offset(const Type::Offset offset) const { 4708 return _field_offset.meet(offset); 4709 } 4710 4711 //------------------------------dual_offset------------------------------------ 4712 Type::Offset TypeAryPtr::dual_field_offset() const { 4713 return _field_offset.dual(); 4714 } 4715 4716 //----------------------interface_vs_oop--------------------------------------- 4717 #ifdef ASSERT 4718 bool TypeAryPtr::interface_vs_oop(const Type *t) const { 4719 const TypeAryPtr* t_aryptr = t->isa_aryptr(); 4720 if (t_aryptr) { 4721 return _ary->interface_vs_oop(t_aryptr->_ary); 4722 } 4723 return false; 4724 } 4725 #endif 4726 4727 //------------------------------dump2------------------------------------------ 4728 #ifndef PRODUCT 4729 void TypeAryPtr::dump2( Dict &d, uint depth, outputStream *st ) const { 4730 _ary->dump2(d,depth,st); 4731 switch( _ptr ) { 4732 case Constant: 4733 const_oop()->print(st); 4734 break; 4735 case BotPTR: 4736 if (!WizardMode && !Verbose) { 4737 if( _klass_is_exact ) st->print(":exact"); 4738 break; 4739 } 4740 case TopPTR: 4741 case AnyNull: 4742 case NotNull: 4743 st->print(":%s", ptr_msg[_ptr]); 4744 if( _klass_is_exact ) st->print(":exact"); 4745 break; 4746 default: 4747 break; 4748 } 4749 4750 if (elem()->isa_valuetype()) { 4751 st->print("("); 4752 _field_offset.dump2(st); 4753 st->print(")"); 4754 } 4755 if (offset() != 0) { 4756 int header_size = objArrayOopDesc::header_size() * wordSize; 4757 if( _offset == Offset::top ) st->print("+undefined"); 4758 else if( _offset == Offset::bottom ) st->print("+any"); 4759 else if( offset() < header_size ) st->print("+%d", offset()); 4760 else { 4761 BasicType basic_elem_type = elem()->basic_type(); 4762 int array_base = arrayOopDesc::base_offset_in_bytes(basic_elem_type); 4763 int elem_size = type2aelembytes(basic_elem_type); 4764 st->print("[%d]", (offset() - array_base)/elem_size); 4765 } 4766 } 4767 st->print(" *"); 4768 if (_instance_id == InstanceTop) 4769 st->print(",iid=top"); 4770 else if (_instance_id != InstanceBot) 4771 st->print(",iid=%d",_instance_id); 4772 4773 dump_inline_depth(st); 4774 dump_speculative(st); 4775 } 4776 #endif 4777 4778 bool TypeAryPtr::empty(void) const { 4779 if (_ary->empty()) return true; 4780 return TypeOopPtr::empty(); 4781 } 4782 4783 //------------------------------add_offset------------------------------------- 4784 const TypePtr *TypeAryPtr::add_offset(intptr_t offset) const { 4785 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); 4786 } 4787 4788 const Type *TypeAryPtr::remove_speculative() const { 4789 if (_speculative == NULL) { 4790 return this; 4791 } 4792 assert(_inline_depth == InlineDepthTop || _inline_depth == InlineDepthBottom, "non speculative type shouldn't have inline depth"); 4793 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); 4794 } 4795 4796 const TypePtr *TypeAryPtr::with_inline_depth(int depth) const { 4797 if (!UseInlineDepthForSpeculativeTypes) { 4798 return this; 4799 } 4800 return make(_ptr, _const_oop, _ary->remove_speculative()->is_ary(), _klass, _klass_is_exact, _offset, _field_offset, _instance_id, _speculative, depth, _is_autobox_cache); 4801 } 4802 4803 const TypeAryPtr* TypeAryPtr::with_field_offset(int offset) const { 4804 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); 4805 } 4806 4807 const TypePtr* TypeAryPtr::add_field_offset_and_offset(intptr_t offset) const { 4808 int adj = 0; 4809 if (offset != Type::OffsetBot && offset != Type::OffsetTop) { 4810 const Type* elemtype = elem(); 4811 if (elemtype->isa_valuetype()) { 4812 if (_offset.get() != OffsetBot && _offset.get() != OffsetTop) { 4813 adj = _offset.get(); 4814 offset += _offset.get(); 4815 } 4816 uint header = arrayOopDesc::base_offset_in_bytes(T_OBJECT); 4817 if (_field_offset.get() != OffsetBot && _field_offset.get() != OffsetTop) { 4818 offset += _field_offset.get(); 4819 if (_offset.get() == OffsetBot || _offset.get() == OffsetTop) { 4820 offset += header; 4821 } 4822 } 4823 if (offset >= (intptr_t)header || offset < 0) { 4824 // Try to get the field of the value type array element we are pointing to 4825 ciKlass* arytype_klass = klass(); 4826 ciValueArrayKlass* vak = arytype_klass->as_value_array_klass(); 4827 ciValueKlass* vk = vak->element_klass()->as_value_klass(); 4828 int shift = vak->log2_element_size(); 4829 int mask = (1 << shift) - 1; 4830 intptr_t field_offset = ((offset - header) & mask); 4831 ciField* field = vk->get_field_by_offset(field_offset + vk->first_field_offset(), false); 4832 if (field == NULL) { 4833 // This may happen with nested AddP(base, AddP(base, base, offset), longcon(16)) 4834 return add_offset(offset); 4835 } else { 4836 return with_field_offset(field_offset)->add_offset(offset - field_offset - adj); 4837 } 4838 } 4839 } 4840 } 4841 return add_offset(offset - adj); 4842 } 4843 4844 // Return offset incremented by field_offset for flattened value type arrays 4845 const int TypeAryPtr::flattened_offset() const { 4846 int offset = _offset.get(); 4847 if (offset != Type::OffsetBot && offset != Type::OffsetTop && 4848 _field_offset != Offset::bottom && _field_offset != Offset::top) { 4849 offset += _field_offset.get(); 4850 } 4851 return offset; 4852 } 4853 4854 //============================================================================= 4855 4856 4857 //------------------------------hash------------------------------------------- 4858 // Type-specific hashing function. 4859 int TypeNarrowPtr::hash(void) const { 4860 return _ptrtype->hash() + 7; 4861 } 4862 4863 bool TypeNarrowPtr::singleton(void) const { // TRUE if type is a singleton 4864 return _ptrtype->singleton(); 4865 } 4866 4867 bool TypeNarrowPtr::empty(void) const { 4868 return _ptrtype->empty(); 4869 } 4870 4871 intptr_t TypeNarrowPtr::get_con() const { 4872 return _ptrtype->get_con(); 4873 } 4874 4875 bool TypeNarrowPtr::eq( const Type *t ) const { 4876 const TypeNarrowPtr* tc = isa_same_narrowptr(t); 4877 if (tc != NULL) { 4878 if (_ptrtype->base() != tc->_ptrtype->base()) { 4879 return false; 4880 } 4881 return tc->_ptrtype->eq(_ptrtype); 4882 } 4883 return false; 4884 } 4885 4886 const Type *TypeNarrowPtr::xdual() const { // Compute dual right now. 4887 const TypePtr* odual = _ptrtype->dual()->is_ptr(); 4888 return make_same_narrowptr(odual); 4889 } 4890 4891 4892 const Type *TypeNarrowPtr::filter_helper(const Type *kills, bool include_speculative) const { 4893 if (isa_same_narrowptr(kills)) { 4894 const Type* ft =_ptrtype->filter_helper(is_same_narrowptr(kills)->_ptrtype, include_speculative); 4895 if (ft->empty()) 4896 return Type::TOP; // Canonical empty value 4897 if (ft->isa_ptr()) { 4898 return make_hash_same_narrowptr(ft->isa_ptr()); 4899 } 4900 return ft; 4901 } else if (kills->isa_ptr()) { 4902 const Type* ft = _ptrtype->join_helper(kills, include_speculative); 4903 if (ft->empty()) 4904 return Type::TOP; // Canonical empty value 4905 return ft; 4906 } else { 4907 return Type::TOP; 4908 } 4909 } 4910 4911 //------------------------------xmeet------------------------------------------ 4912 // Compute the MEET of two types. It returns a new Type object. 4913 const Type *TypeNarrowPtr::xmeet( const Type *t ) const { 4914 // Perform a fast test for common case; meeting the same types together. 4915 if( this == t ) return this; // Meeting same type-rep? 4916 4917 if (t->base() == base()) { 4918 const Type* result = _ptrtype->xmeet(t->make_ptr()); 4919 if (result->isa_ptr()) { 4920 return make_hash_same_narrowptr(result->is_ptr()); 4921 } 4922 return result; 4923 } 4924 4925 // Current "this->_base" is NarrowKlass or NarrowOop 4926 switch (t->base()) { // switch on original type 4927 4928 case Int: // Mixing ints & oops happens when javac 4929 case Long: // reuses local variables 4930 case FloatTop: 4931 case FloatCon: 4932 case FloatBot: 4933 case DoubleTop: 4934 case DoubleCon: 4935 case DoubleBot: 4936 case AnyPtr: 4937 case RawPtr: 4938 case OopPtr: 4939 case InstPtr: 4940 case AryPtr: 4941 case MetadataPtr: 4942 case KlassPtr: 4943 case NarrowOop: 4944 case NarrowKlass: 4945 case Bottom: // Ye Olde Default 4946 return Type::BOTTOM; 4947 case Top: 4948 return this; 4949 4950 case ValueType: 4951 return t->xmeet(this); 4952 4953 default: // All else is a mistake 4954 typerr(t); 4955 4956 } // End of switch 4957 4958 return this; 4959 } 4960 4961 #ifndef PRODUCT 4962 void TypeNarrowPtr::dump2( Dict & d, uint depth, outputStream *st ) const { 4963 _ptrtype->dump2(d, depth, st); 4964 } 4965 #endif 4966 4967 const TypeNarrowOop *TypeNarrowOop::BOTTOM; 4968 const TypeNarrowOop *TypeNarrowOop::NULL_PTR; 4969 4970 4971 const TypeNarrowOop* TypeNarrowOop::make(const TypePtr* type) { 4972 return (const TypeNarrowOop*)(new TypeNarrowOop(type))->hashcons(); 4973 } 4974 4975 const Type* TypeNarrowOop::remove_speculative() const { 4976 return make(_ptrtype->remove_speculative()->is_ptr()); 4977 } 4978 4979 const Type* TypeNarrowOop::cleanup_speculative() const { 4980 return make(_ptrtype->cleanup_speculative()->is_ptr()); 4981 } 4982 4983 #ifndef PRODUCT 4984 void TypeNarrowOop::dump2( Dict & d, uint depth, outputStream *st ) const { 4985 st->print("narrowoop: "); 4986 TypeNarrowPtr::dump2(d, depth, st); 4987 } 4988 #endif 4989 4990 const TypeNarrowKlass *TypeNarrowKlass::NULL_PTR; 4991 4992 const TypeNarrowKlass* TypeNarrowKlass::make(const TypePtr* type) { 4993 return (const TypeNarrowKlass*)(new TypeNarrowKlass(type))->hashcons(); 4994 } 4995 4996 #ifndef PRODUCT 4997 void TypeNarrowKlass::dump2( Dict & d, uint depth, outputStream *st ) const { 4998 st->print("narrowklass: "); 4999 TypeNarrowPtr::dump2(d, depth, st); 5000 } 5001 #endif 5002 5003 5004 //------------------------------eq--------------------------------------------- 5005 // Structural equality check for Type representations 5006 bool TypeMetadataPtr::eq( const Type *t ) const { 5007 const TypeMetadataPtr *a = (const TypeMetadataPtr*)t; 5008 ciMetadata* one = metadata(); 5009 ciMetadata* two = a->metadata(); 5010 if (one == NULL || two == NULL) { 5011 return (one == two) && TypePtr::eq(t); 5012 } else { 5013 return one->equals(two) && TypePtr::eq(t); 5014 } 5015 } 5016 5017 //------------------------------hash------------------------------------------- 5018 // Type-specific hashing function. 5019 int TypeMetadataPtr::hash(void) const { 5020 return 5021 (metadata() ? metadata()->hash() : 0) + 5022 TypePtr::hash(); 5023 } 5024 5025 //------------------------------singleton-------------------------------------- 5026 // TRUE if Type is a singleton type, FALSE otherwise. Singletons are simple 5027 // constants 5028 bool TypeMetadataPtr::singleton(void) const { 5029 // detune optimizer to not generate constant metadata + constant offset as a constant! 5030 // TopPTR, Null, AnyNull, Constant are all singletons 5031 return (offset() == 0) && !below_centerline(_ptr); 5032 } 5033 5034 //------------------------------add_offset------------------------------------- 5035 const TypePtr *TypeMetadataPtr::add_offset( intptr_t offset ) const { 5036 return make( _ptr, _metadata, xadd_offset(offset)); 5037 } 5038 5039 //-----------------------------filter------------------------------------------ 5040 // Do not allow interface-vs.-noninterface joins to collapse to top. 5041 const Type *TypeMetadataPtr::filter_helper(const Type *kills, bool include_speculative) const { 5042 const TypeMetadataPtr* ft = join_helper(kills, include_speculative)->isa_metadataptr(); 5043 if (ft == NULL || ft->empty()) 5044 return Type::TOP; // Canonical empty value 5045 return ft; 5046 } 5047 5048 //------------------------------get_con---------------------------------------- 5049 intptr_t TypeMetadataPtr::get_con() const { 5050 assert( _ptr == Null || _ptr == Constant, "" ); 5051 assert(offset() >= 0, ""); 5052 5053 if (offset() != 0) { 5054 // After being ported to the compiler interface, the compiler no longer 5055 // directly manipulates the addresses of oops. Rather, it only has a pointer 5056 // to a handle at compile time. This handle is embedded in the generated 5057 // code and dereferenced at the time the nmethod is made. Until that time, 5058 // it is not reasonable to do arithmetic with the addresses of oops (we don't 5059 // have access to the addresses!). This does not seem to currently happen, 5060 // but this assertion here is to help prevent its occurence. 5061 tty->print_cr("Found oop constant with non-zero offset"); 5062 ShouldNotReachHere(); 5063 } 5064 5065 return (intptr_t)metadata()->constant_encoding(); 5066 } 5067 5068 //------------------------------cast_to_ptr_type------------------------------- 5069 const Type *TypeMetadataPtr::cast_to_ptr_type(PTR ptr) const { 5070 if( ptr == _ptr ) return this; 5071 return make(ptr, metadata(), _offset); 5072 } 5073 5074 //------------------------------meet------------------------------------------- 5075 // Compute the MEET of two types. It returns a new Type object. 5076 const Type *TypeMetadataPtr::xmeet( const Type *t ) const { 5077 // Perform a fast test for common case; meeting the same types together. 5078 if( this == t ) return this; // Meeting same type-rep? 5079 5080 // Current "this->_base" is OopPtr 5081 switch (t->base()) { // switch on original type 5082 5083 case Int: // Mixing ints & oops happens when javac 5084 case Long: // reuses local variables 5085 case FloatTop: 5086 case FloatCon: 5087 case FloatBot: 5088 case DoubleTop: 5089 case DoubleCon: 5090 case DoubleBot: 5091 case NarrowOop: 5092 case NarrowKlass: 5093 case Bottom: // Ye Olde Default 5094 return Type::BOTTOM; 5095 case Top: 5096 return this; 5097 5098 default: // All else is a mistake 5099 typerr(t); 5100 5101 case AnyPtr: { 5102 // Found an AnyPtr type vs self-OopPtr type 5103 const TypePtr *tp = t->is_ptr(); 5104 Offset offset = meet_offset(tp->offset()); 5105 PTR ptr = meet_ptr(tp->ptr()); 5106 switch (tp->ptr()) { 5107 case Null: 5108 if (ptr == Null) return TypePtr::make(AnyPtr, ptr, offset, tp->speculative(), tp->inline_depth()); 5109 // else fall through: 5110 case TopPTR: 5111 case AnyNull: { 5112 return make(ptr, _metadata, offset); 5113 } 5114 case BotPTR: 5115 case NotNull: 5116 return TypePtr::make(AnyPtr, ptr, offset, tp->speculative(), tp->inline_depth()); 5117 default: typerr(t); 5118 } 5119 } 5120 5121 case RawPtr: 5122 case KlassPtr: 5123 case OopPtr: 5124 case InstPtr: 5125 case AryPtr: 5126 return TypePtr::BOTTOM; // Oop meet raw is not well defined 5127 5128 case MetadataPtr: { 5129 const TypeMetadataPtr *tp = t->is_metadataptr(); 5130 Offset offset = meet_offset(tp->offset()); 5131 PTR tptr = tp->ptr(); 5132 PTR ptr = meet_ptr(tptr); 5133 ciMetadata* md = (tptr == TopPTR) ? metadata() : tp->metadata(); 5134 if (tptr == TopPTR || _ptr == TopPTR || 5135 metadata()->equals(tp->metadata())) { 5136 return make(ptr, md, offset); 5137 } 5138 // metadata is different 5139 if( ptr == Constant ) { // Cannot be equal constants, so... 5140 if( tptr == Constant && _ptr != Constant) return t; 5141 if( _ptr == Constant && tptr != Constant) return this; 5142 ptr = NotNull; // Fall down in lattice 5143 } 5144 return make(ptr, NULL, offset); 5145 break; 5146 } 5147 } // End of switch 5148 return this; // Return the double constant 5149 } 5150 5151 5152 //------------------------------xdual------------------------------------------ 5153 // Dual of a pure metadata pointer. 5154 const Type *TypeMetadataPtr::xdual() const { 5155 return new TypeMetadataPtr(dual_ptr(), metadata(), dual_offset()); 5156 } 5157 5158 //------------------------------dump2------------------------------------------ 5159 #ifndef PRODUCT 5160 void TypeMetadataPtr::dump2( Dict &d, uint depth, outputStream *st ) const { 5161 st->print("metadataptr:%s", ptr_msg[_ptr]); 5162 if( metadata() ) st->print(INTPTR_FORMAT, p2i(metadata())); 5163 switch (offset()) { 5164 case OffsetTop: st->print("+top"); break; 5165 case OffsetBot: st->print("+any"); break; 5166 case 0: break; 5167 default: st->print("+%d",offset()); break; 5168 } 5169 } 5170 #endif 5171 5172 5173 //============================================================================= 5174 // Convenience common pre-built type. 5175 const TypeMetadataPtr *TypeMetadataPtr::BOTTOM; 5176 5177 TypeMetadataPtr::TypeMetadataPtr(PTR ptr, ciMetadata* metadata, Offset offset): 5178 TypePtr(MetadataPtr, ptr, offset), _metadata(metadata) { 5179 } 5180 5181 const TypeMetadataPtr* TypeMetadataPtr::make(ciMethod* m) { 5182 return make(Constant, m, Offset(0)); 5183 } 5184 const TypeMetadataPtr* TypeMetadataPtr::make(ciMethodData* m) { 5185 return make(Constant, m, Offset(0)); 5186 } 5187 5188 //------------------------------make------------------------------------------- 5189 // Create a meta data constant 5190 const TypeMetadataPtr* TypeMetadataPtr::make(PTR ptr, ciMetadata* m, Offset offset) { 5191 assert(m == NULL || !m->is_klass(), "wrong type"); 5192 return (TypeMetadataPtr*)(new TypeMetadataPtr(ptr, m, offset))->hashcons(); 5193 } 5194 5195 5196 //============================================================================= 5197 // Convenience common pre-built types. 5198 5199 // Not-null object klass or below 5200 const TypeKlassPtr *TypeKlassPtr::OBJECT; 5201 const TypeKlassPtr *TypeKlassPtr::OBJECT_OR_NULL; 5202 const TypeKlassPtr* TypeKlassPtr::BOTTOM; 5203 5204 //------------------------------TypeKlassPtr----------------------------------- 5205 TypeKlassPtr::TypeKlassPtr( PTR ptr, ciKlass* klass, Offset offset ) 5206 : TypePtr(KlassPtr, ptr, offset), _klass(klass), _klass_is_exact(ptr == Constant) { 5207 } 5208 5209 //------------------------------make------------------------------------------- 5210 // ptr to klass 'k', if Constant, or possibly to a sub-klass if not a Constant 5211 const TypeKlassPtr* TypeKlassPtr::make(PTR ptr, ciKlass* k, Offset offset) { 5212 assert(k == NULL || k->is_instance_klass() || k->is_array_klass(), "Incorrect type of klass oop"); 5213 return (TypeKlassPtr*)(new TypeKlassPtr(ptr, k, offset))->hashcons(); 5214 } 5215 5216 //------------------------------eq--------------------------------------------- 5217 // Structural equality check for Type representations 5218 bool TypeKlassPtr::eq( const Type *t ) const { 5219 const TypeKlassPtr *p = t->is_klassptr(); 5220 return klass() == p->klass() && TypePtr::eq(p); 5221 } 5222 5223 //------------------------------hash------------------------------------------- 5224 // Type-specific hashing function. 5225 int TypeKlassPtr::hash(void) const { 5226 return java_add(klass() != NULL ? klass()->hash() : (jint)0, (jint)TypePtr::hash()); 5227 } 5228 5229 //------------------------------singleton-------------------------------------- 5230 // TRUE if Type is a singleton type, FALSE otherwise. Singletons are simple 5231 // constants 5232 bool TypeKlassPtr::singleton(void) const { 5233 // detune optimizer to not generate constant klass + constant offset as a constant! 5234 // TopPTR, Null, AnyNull, Constant are all singletons 5235 return (offset() == 0) && !below_centerline(_ptr); 5236 } 5237 5238 // Do not allow interface-vs.-noninterface joins to collapse to top. 5239 const Type *TypeKlassPtr::filter_helper(const Type *kills, bool include_speculative) const { 5240 // logic here mirrors the one from TypeOopPtr::filter. See comments 5241 // there. 5242 const Type* ft = join_helper(kills, include_speculative); 5243 const TypeKlassPtr* ftkp = ft->isa_klassptr(); 5244 const TypeKlassPtr* ktkp = kills->isa_klassptr(); 5245 5246 if (ft->empty()) { 5247 if (!empty() && ktkp != NULL && ktkp->is_loaded() && ktkp->klass()->is_interface()) 5248 return kills; // Uplift to interface 5249 5250 return Type::TOP; // Canonical empty value 5251 } 5252 5253 // Interface klass type could be exact in opposite to interface type, 5254 // return it here instead of incorrect Constant ptr J/L/Object (6894807). 5255 if (ftkp != NULL && ktkp != NULL && 5256 ftkp->is_loaded() && ftkp->klass()->is_interface() && 5257 !ftkp->klass_is_exact() && // Keep exact interface klass 5258 ktkp->is_loaded() && !ktkp->klass()->is_interface()) { 5259 return ktkp->cast_to_ptr_type(ftkp->ptr()); 5260 } 5261 5262 return ft; 5263 } 5264 5265 //----------------------compute_klass------------------------------------------ 5266 // Compute the defining klass for this class 5267 ciKlass* TypeAryPtr::compute_klass(DEBUG_ONLY(bool verify)) const { 5268 // Compute _klass based on element type. 5269 ciKlass* k_ary = NULL; 5270 const TypeAryPtr *tary; 5271 const Type* el = elem(); 5272 if (el->isa_narrowoop()) { 5273 el = el->make_ptr(); 5274 } 5275 5276 // Get element klass 5277 if (el->isa_instptr()) { 5278 // Compute object array klass from element klass 5279 k_ary = ciArrayKlass::make(el->is_oopptr()->klass()); 5280 } else if (el->isa_valuetype()) { 5281 k_ary = ciArrayKlass::make(el->is_valuetype()->value_klass()); 5282 } else if ((tary = el->isa_aryptr()) != NULL) { 5283 // Compute array klass from element klass 5284 ciKlass* k_elem = tary->klass(); 5285 // If element type is something like bottom[], k_elem will be null. 5286 if (k_elem != NULL) 5287 k_ary = ciObjArrayKlass::make(k_elem); 5288 } else if ((el->base() == Type::Top) || 5289 (el->base() == Type::Bottom)) { 5290 // element type of Bottom occurs from meet of basic type 5291 // and object; Top occurs when doing join on Bottom. 5292 // Leave k_ary at NULL. 5293 } else { 5294 // Cannot compute array klass directly from basic type, 5295 // since subtypes of TypeInt all have basic type T_INT. 5296 #ifdef ASSERT 5297 if (verify && el->isa_int()) { 5298 // Check simple cases when verifying klass. 5299 BasicType bt = T_ILLEGAL; 5300 if (el == TypeInt::BYTE) { 5301 bt = T_BYTE; 5302 } else if (el == TypeInt::SHORT) { 5303 bt = T_SHORT; 5304 } else if (el == TypeInt::CHAR) { 5305 bt = T_CHAR; 5306 } else if (el == TypeInt::INT) { 5307 bt = T_INT; 5308 } else { 5309 return _klass; // just return specified klass 5310 } 5311 return ciTypeArrayKlass::make(bt); 5312 } 5313 #endif 5314 assert(!el->isa_int(), 5315 "integral arrays must be pre-equipped with a class"); 5316 // Compute array klass directly from basic type 5317 k_ary = ciTypeArrayKlass::make(el->basic_type()); 5318 } 5319 return k_ary; 5320 } 5321 5322 //------------------------------klass------------------------------------------ 5323 // Return the defining klass for this class 5324 ciKlass* TypeAryPtr::klass() const { 5325 if( _klass ) return _klass; // Return cached value, if possible 5326 5327 // Oops, need to compute _klass and cache it 5328 ciKlass* k_ary = compute_klass(); 5329 5330 if( this != TypeAryPtr::OOPS && this->dual() != TypeAryPtr::OOPS ) { 5331 // The _klass field acts as a cache of the underlying 5332 // ciKlass for this array type. In order to set the field, 5333 // we need to cast away const-ness. 5334 // 5335 // IMPORTANT NOTE: we *never* set the _klass field for the 5336 // type TypeAryPtr::OOPS. This Type is shared between all 5337 // active compilations. However, the ciKlass which represents 5338 // this Type is *not* shared between compilations, so caching 5339 // this value would result in fetching a dangling pointer. 5340 // 5341 // Recomputing the underlying ciKlass for each request is 5342 // a bit less efficient than caching, but calls to 5343 // TypeAryPtr::OOPS->klass() are not common enough to matter. 5344 ((TypeAryPtr*)this)->_klass = k_ary; 5345 if (UseCompressedOops && k_ary != NULL && k_ary->is_obj_array_klass() && 5346 offset() != 0 && offset() != arrayOopDesc::length_offset_in_bytes()) { 5347 ((TypeAryPtr*)this)->_is_ptr_to_narrowoop = true; 5348 } 5349 } 5350 return k_ary; 5351 } 5352 5353 5354 //------------------------------add_offset------------------------------------- 5355 // Access internals of klass object 5356 const TypePtr *TypeKlassPtr::add_offset( intptr_t offset ) const { 5357 return make( _ptr, klass(), xadd_offset(offset) ); 5358 } 5359 5360 //------------------------------cast_to_ptr_type------------------------------- 5361 const Type *TypeKlassPtr::cast_to_ptr_type(PTR ptr) const { 5362 assert(_base == KlassPtr, "subclass must override cast_to_ptr_type"); 5363 if( ptr == _ptr ) return this; 5364 return make(ptr, _klass, _offset); 5365 } 5366 5367 5368 //-----------------------------cast_to_exactness------------------------------- 5369 const Type *TypeKlassPtr::cast_to_exactness(bool klass_is_exact) const { 5370 if( klass_is_exact == _klass_is_exact ) return this; 5371 if (!UseExactTypes) return this; 5372 return make(klass_is_exact ? Constant : NotNull, _klass, _offset); 5373 } 5374 5375 5376 //-----------------------------as_instance_type-------------------------------- 5377 // Corresponding type for an instance of the given class. 5378 // It will be NotNull, and exact if and only if the klass type is exact. 5379 const TypeOopPtr* TypeKlassPtr::as_instance_type() const { 5380 ciKlass* k = klass(); 5381 assert(k != NULL, "klass should not be NULL"); 5382 bool xk = klass_is_exact(); 5383 //return TypeInstPtr::make(TypePtr::NotNull, k, xk, NULL, 0); 5384 const TypeOopPtr* toop = TypeOopPtr::make_from_klass_raw(k); 5385 guarantee(toop != NULL, "need type for given klass"); 5386 toop = toop->cast_to_ptr_type(TypePtr::NotNull)->is_oopptr(); 5387 return toop->cast_to_exactness(xk)->is_oopptr(); 5388 } 5389 5390 5391 //------------------------------xmeet------------------------------------------ 5392 // Compute the MEET of two types, return a new Type object. 5393 const Type *TypeKlassPtr::xmeet( const Type *t ) const { 5394 // Perform a fast test for common case; meeting the same types together. 5395 if( this == t ) return this; // Meeting same type-rep? 5396 5397 // Current "this->_base" is Pointer 5398 switch (t->base()) { // switch on original type 5399 5400 case Int: // Mixing ints & oops happens when javac 5401 case Long: // reuses local variables 5402 case FloatTop: 5403 case FloatCon: 5404 case FloatBot: 5405 case DoubleTop: 5406 case DoubleCon: 5407 case DoubleBot: 5408 case NarrowOop: 5409 case NarrowKlass: 5410 case Bottom: // Ye Olde Default 5411 return Type::BOTTOM; 5412 case Top: 5413 return this; 5414 5415 default: // All else is a mistake 5416 typerr(t); 5417 5418 case AnyPtr: { // Meeting to AnyPtrs 5419 // Found an AnyPtr type vs self-KlassPtr type 5420 const TypePtr *tp = t->is_ptr(); 5421 Offset offset = meet_offset(tp->offset()); 5422 PTR ptr = meet_ptr(tp->ptr()); 5423 switch (tp->ptr()) { 5424 case TopPTR: 5425 return this; 5426 case Null: 5427 if( ptr == Null ) return TypePtr::make(AnyPtr, ptr, offset, tp->speculative(), tp->inline_depth()); 5428 case AnyNull: 5429 return make( ptr, klass(), offset ); 5430 case BotPTR: 5431 case NotNull: 5432 return TypePtr::make(AnyPtr, ptr, offset, tp->speculative(), tp->inline_depth()); 5433 default: typerr(t); 5434 } 5435 } 5436 5437 case RawPtr: 5438 case MetadataPtr: 5439 case OopPtr: 5440 case AryPtr: // Meet with AryPtr 5441 case InstPtr: // Meet with InstPtr 5442 return TypePtr::BOTTOM; 5443 5444 // 5445 // A-top } 5446 // / | \ } Tops 5447 // B-top A-any C-top } 5448 // | / | \ | } Any-nulls 5449 // B-any | C-any } 5450 // | | | 5451 // B-con A-con C-con } constants; not comparable across classes 5452 // | | | 5453 // B-not | C-not } 5454 // | \ | / | } not-nulls 5455 // B-bot A-not C-bot } 5456 // \ | / } Bottoms 5457 // A-bot } 5458 // 5459 5460 case KlassPtr: { // Meet two KlassPtr types 5461 const TypeKlassPtr *tkls = t->is_klassptr(); 5462 Offset off = meet_offset(tkls->offset()); 5463 PTR ptr = meet_ptr(tkls->ptr()); 5464 5465 if (klass() == NULL || tkls->klass() == NULL) { 5466 ciKlass* k = NULL; 5467 if (ptr == Constant) { 5468 k = (klass() == NULL) ? tkls->klass() : klass(); 5469 } 5470 return make(ptr, k, off); 5471 } 5472 5473 // Check for easy case; klasses are equal (and perhaps not loaded!) 5474 // If we have constants, then we created oops so classes are loaded 5475 // and we can handle the constants further down. This case handles 5476 // not-loaded classes 5477 if( ptr != Constant && tkls->klass()->equals(klass()) ) { 5478 return make( ptr, klass(), off ); 5479 } 5480 5481 // Classes require inspection in the Java klass hierarchy. Must be loaded. 5482 ciKlass* tkls_klass = tkls->klass(); 5483 ciKlass* this_klass = this->klass(); 5484 assert( tkls_klass->is_loaded(), "This class should have been loaded."); 5485 assert( this_klass->is_loaded(), "This class should have been loaded."); 5486 5487 // If 'this' type is above the centerline and is a superclass of the 5488 // other, we can treat 'this' as having the same type as the other. 5489 if ((above_centerline(this->ptr())) && 5490 tkls_klass->is_subtype_of(this_klass)) { 5491 this_klass = tkls_klass; 5492 } 5493 // If 'tinst' type is above the centerline and is a superclass of the 5494 // other, we can treat 'tinst' as having the same type as the other. 5495 if ((above_centerline(tkls->ptr())) && 5496 this_klass->is_subtype_of(tkls_klass)) { 5497 tkls_klass = this_klass; 5498 } 5499 5500 // Check for classes now being equal 5501 if (tkls_klass->equals(this_klass)) { 5502 // If the klasses are equal, the constants may still differ. Fall to 5503 // NotNull if they do (neither constant is NULL; that is a special case 5504 // handled elsewhere). 5505 if( ptr == Constant ) { 5506 if (this->_ptr == Constant && tkls->_ptr == Constant && 5507 this->klass()->equals(tkls->klass())); 5508 else if (above_centerline(this->ptr())); 5509 else if (above_centerline(tkls->ptr())); 5510 else 5511 ptr = NotNull; 5512 } 5513 return make( ptr, this_klass, off ); 5514 } // Else classes are not equal 5515 5516 // Since klasses are different, we require the LCA in the Java 5517 // class hierarchy - which means we have to fall to at least NotNull. 5518 if( ptr == TopPTR || ptr == AnyNull || ptr == Constant ) 5519 ptr = NotNull; 5520 // Now we find the LCA of Java classes 5521 ciKlass* k = this_klass->least_common_ancestor(tkls_klass); 5522 return make( ptr, k, off ); 5523 } // End of case KlassPtr 5524 5525 } // End of switch 5526 return this; // Return the double constant 5527 } 5528 5529 //------------------------------xdual------------------------------------------ 5530 // Dual: compute field-by-field dual 5531 const Type *TypeKlassPtr::xdual() const { 5532 return new TypeKlassPtr( dual_ptr(), klass(), dual_offset() ); 5533 } 5534 5535 //------------------------------get_con---------------------------------------- 5536 intptr_t TypeKlassPtr::get_con() const { 5537 assert( _ptr == Null || _ptr == Constant, "" ); 5538 assert(offset() >= 0, ""); 5539 5540 if (offset() != 0) { 5541 // After being ported to the compiler interface, the compiler no longer 5542 // directly manipulates the addresses of oops. Rather, it only has a pointer 5543 // to a handle at compile time. This handle is embedded in the generated 5544 // code and dereferenced at the time the nmethod is made. Until that time, 5545 // it is not reasonable to do arithmetic with the addresses of oops (we don't 5546 // have access to the addresses!). This does not seem to currently happen, 5547 // but this assertion here is to help prevent its occurence. 5548 tty->print_cr("Found oop constant with non-zero offset"); 5549 ShouldNotReachHere(); 5550 } 5551 5552 return (intptr_t)klass()->constant_encoding(); 5553 } 5554 //------------------------------dump2------------------------------------------ 5555 // Dump Klass Type 5556 #ifndef PRODUCT 5557 void TypeKlassPtr::dump2( Dict & d, uint depth, outputStream *st ) const { 5558 switch( _ptr ) { 5559 case Constant: 5560 st->print("precise "); 5561 case NotNull: 5562 { 5563 if (klass() != NULL) { 5564 const char* name = klass()->name()->as_utf8(); 5565 st->print("klass %s: " INTPTR_FORMAT, name, p2i(klass())); 5566 } else { 5567 st->print("klass BOTTOM"); 5568 } 5569 } 5570 case BotPTR: 5571 if( !WizardMode && !Verbose && !_klass_is_exact ) break; 5572 case TopPTR: 5573 case AnyNull: 5574 st->print(":%s", ptr_msg[_ptr]); 5575 if( _klass_is_exact ) st->print(":exact"); 5576 break; 5577 default: 5578 break; 5579 } 5580 5581 _offset.dump2(st); 5582 5583 st->print(" *"); 5584 } 5585 #endif 5586 5587 5588 5589 //============================================================================= 5590 // Convenience common pre-built types. 5591 5592 //------------------------------make------------------------------------------- 5593 const TypeFunc *TypeFunc::make(const TypeTuple *domain_sig, const TypeTuple* domain_cc, 5594 const TypeTuple *range_sig, const TypeTuple *range_cc) { 5595 return (TypeFunc*)(new TypeFunc(domain_sig, domain_cc, range_sig, range_cc))->hashcons(); 5596 } 5597 5598 const TypeFunc *TypeFunc::make(const TypeTuple *domain, const TypeTuple *range) { 5599 return make(domain, domain, range, range); 5600 } 5601 5602 //------------------------------make------------------------------------------- 5603 const TypeFunc *TypeFunc::make(ciMethod* method) { 5604 Compile* C = Compile::current(); 5605 const TypeFunc* tf = C->last_tf(method); // check cache 5606 if (tf != NULL) return tf; // The hit rate here is almost 50%. 5607 const TypeTuple *domain_sig, *domain_cc; 5608 // Value type arguments are not passed by reference, instead each 5609 // field of the value type is passed as an argument. We maintain 2 5610 // views of the argument list here: one based on the signature (with 5611 // a value type argument as a single slot), one based on the actual 5612 // calling convention (with a value type argument as a list of its 5613 // fields). 5614 if (method->is_static()) { 5615 domain_sig = TypeTuple::make_domain(NULL, method->signature(), false); 5616 domain_cc = TypeTuple::make_domain(NULL, method->signature(), ValueTypePassFieldsAsArgs); 5617 } else { 5618 domain_sig = TypeTuple::make_domain(method->holder(), method->signature(), false); 5619 domain_cc = TypeTuple::make_domain(method->holder(), method->signature(), ValueTypePassFieldsAsArgs); 5620 } 5621 const TypeTuple *range_sig = TypeTuple::make_range(method, false); 5622 const TypeTuple *range_cc = TypeTuple::make_range(method, ValueTypeReturnedAsFields); 5623 tf = TypeFunc::make(domain_sig, domain_cc, range_sig, range_cc); 5624 C->set_last_tf(method, tf); // fill cache 5625 return tf; 5626 } 5627 5628 //------------------------------meet------------------------------------------- 5629 // Compute the MEET of two types. It returns a new Type object. 5630 const Type *TypeFunc::xmeet( const Type *t ) const { 5631 // Perform a fast test for common case; meeting the same types together. 5632 if( this == t ) return this; // Meeting same type-rep? 5633 5634 // Current "this->_base" is Func 5635 switch (t->base()) { // switch on original type 5636 5637 case Bottom: // Ye Olde Default 5638 return t; 5639 5640 default: // All else is a mistake 5641 typerr(t); 5642 5643 case Top: 5644 break; 5645 } 5646 return this; // Return the double constant 5647 } 5648 5649 //------------------------------xdual------------------------------------------ 5650 // Dual: compute field-by-field dual 5651 const Type *TypeFunc::xdual() const { 5652 return this; 5653 } 5654 5655 //------------------------------eq--------------------------------------------- 5656 // Structural equality check for Type representations 5657 bool TypeFunc::eq( const Type *t ) const { 5658 const TypeFunc *a = (const TypeFunc*)t; 5659 return _domain_sig == a->_domain_sig && 5660 _domain_cc == a->_domain_cc && 5661 _range_sig == a->_range_sig && 5662 _range_cc == a->_range_cc; 5663 } 5664 5665 //------------------------------hash------------------------------------------- 5666 // Type-specific hashing function. 5667 int TypeFunc::hash(void) const { 5668 return (intptr_t)_domain_sig + (intptr_t)_domain_cc + (intptr_t)_range_sig + (intptr_t)_range_cc; 5669 } 5670 5671 //------------------------------dump2------------------------------------------ 5672 // Dump Function Type 5673 #ifndef PRODUCT 5674 void TypeFunc::dump2( Dict &d, uint depth, outputStream *st ) const { 5675 if( _range_sig->cnt() <= Parms ) 5676 st->print("void"); 5677 else { 5678 uint i; 5679 for (i = Parms; i < _range_sig->cnt()-1; i++) { 5680 _range_sig->field_at(i)->dump2(d,depth,st); 5681 st->print("/"); 5682 } 5683 _range_sig->field_at(i)->dump2(d,depth,st); 5684 } 5685 st->print(" "); 5686 st->print("( "); 5687 if( !depth || d[this] ) { // Check for recursive dump 5688 st->print("...)"); 5689 return; 5690 } 5691 d.Insert((void*)this,(void*)this); // Stop recursion 5692 if (Parms < _domain_sig->cnt()) 5693 _domain_sig->field_at(Parms)->dump2(d,depth-1,st); 5694 for (uint i = Parms+1; i < _domain_sig->cnt(); i++) { 5695 st->print(", "); 5696 _domain_sig->field_at(i)->dump2(d,depth-1,st); 5697 } 5698 st->print(" )"); 5699 } 5700 #endif 5701 5702 //------------------------------singleton-------------------------------------- 5703 // TRUE if Type is a singleton type, FALSE otherwise. Singletons are simple 5704 // constants (Ldi nodes). Singletons are integer, float or double constants 5705 // or a single symbol. 5706 bool TypeFunc::singleton(void) const { 5707 return false; // Never a singleton 5708 } 5709 5710 bool TypeFunc::empty(void) const { 5711 return false; // Never empty 5712 } 5713 5714 5715 BasicType TypeFunc::return_type() const{ 5716 if (range_sig()->cnt() == TypeFunc::Parms) { 5717 return T_VOID; 5718 } 5719 return range_sig()->field_at(TypeFunc::Parms)->basic_type(); 5720 }