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