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