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