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