annotate src/share/vm/opto/type.cpp @ 5223:edb5ab0f3fe5

8001107: @Stable annotation for constant folding of lazily evaluated variables Reviewed-by: rbackman, twisti, kvn Contributed-by: john.r.rose@oracle.com, vladimir.x.ivanov@oracle.com
author vlivanov
date Tue, 10 Sep 2013 14:51:48 -0700
parents 6f3fd5150b67
children 884ed7a10f09
rev   line source
duke@0 1 /*
hseigel@4030 2 * Copyright (c) 1997, 2013, Oracle and/or its affiliates. All rights reserved.
duke@0 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
duke@0 4 *
duke@0 5 * This code is free software; you can redistribute it and/or modify it
duke@0 6 * under the terms of the GNU General Public License version 2 only, as
duke@0 7 * published by the Free Software Foundation.
duke@0 8 *
duke@0 9 * This code is distributed in the hope that it will be useful, but WITHOUT
duke@0 10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
duke@0 11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
duke@0 12 * version 2 for more details (a copy is included in the LICENSE file that
duke@0 13 * accompanied this code).
duke@0 14 *
duke@0 15 * You should have received a copy of the GNU General Public License version
duke@0 16 * 2 along with this work; if not, write to the Free Software Foundation,
duke@0 17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
duke@0 18 *
trims@1472 19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
trims@1472 20 * or visit www.oracle.com if you need additional information or have any
trims@1472 21 * questions.
duke@0 22 *
duke@0 23 */
duke@0 24
stefank@1879 25 #include "precompiled.hpp"
coleenp@3602 26 #include "ci/ciMethodData.hpp"
stefank@1879 27 #include "ci/ciTypeFlow.hpp"
stefank@1879 28 #include "classfile/symbolTable.hpp"
stefank@1879 29 #include "classfile/systemDictionary.hpp"
stefank@1879 30 #include "compiler/compileLog.hpp"
stefank@1879 31 #include "libadt/dict.hpp"
stefank@1879 32 #include "memory/gcLocker.hpp"
stefank@1879 33 #include "memory/oopFactory.hpp"
stefank@1879 34 #include "memory/resourceArea.hpp"
stefank@1879 35 #include "oops/instanceKlass.hpp"
never@2223 36 #include "oops/instanceMirrorKlass.hpp"
stefank@1879 37 #include "oops/objArrayKlass.hpp"
stefank@1879 38 #include "oops/typeArrayKlass.hpp"
stefank@1879 39 #include "opto/matcher.hpp"
stefank@1879 40 #include "opto/node.hpp"
stefank@1879 41 #include "opto/opcodes.hpp"
stefank@1879 42 #include "opto/type.hpp"
stefank@1879 43
duke@0 44 // Portions of code courtesy of Clifford Click
duke@0 45
duke@0 46 // Optimization - Graph Style
duke@0 47
duke@0 48 // Dictionary of types shared among compilations.
duke@0 49 Dict* Type::_shared_type_dict = NULL;
duke@0 50
duke@0 51 // Array which maps compiler types to Basic Types
coleenp@3602 52 Type::TypeInfo Type::_type_info[Type::lastype] = {
coleenp@3602 53 { Bad, T_ILLEGAL, "bad", false, Node::NotAMachineReg, relocInfo::none }, // Bad
coleenp@3602 54 { Control, T_ILLEGAL, "control", false, 0, relocInfo::none }, // Control
coleenp@3602 55 { Bottom, T_VOID, "top", false, 0, relocInfo::none }, // Top
coleenp@3602 56 { Bad, T_INT, "int:", false, Op_RegI, relocInfo::none }, // Int
coleenp@3602 57 { Bad, T_LONG, "long:", false, Op_RegL, relocInfo::none }, // Long
coleenp@3602 58 { Half, T_VOID, "half", false, 0, relocInfo::none }, // Half
coleenp@3602 59 { Bad, T_NARROWOOP, "narrowoop:", false, Op_RegN, relocInfo::none }, // NarrowOop
roland@3724 60 { Bad, T_NARROWKLASS,"narrowklass:", false, Op_RegN, relocInfo::none }, // NarrowKlass
coleenp@3602 61 { Bad, T_ILLEGAL, "tuple:", false, Node::NotAMachineReg, relocInfo::none }, // Tuple
coleenp@3602 62 { Bad, T_ARRAY, "array:", false, Node::NotAMachineReg, relocInfo::none }, // Array
coleenp@3602 63
dlong@3766 64 #ifndef SPARC
coleenp@3602 65 { Bad, T_ILLEGAL, "vectors:", false, Op_VecS, relocInfo::none }, // VectorS
coleenp@3602 66 { Bad, T_ILLEGAL, "vectord:", false, Op_VecD, relocInfo::none }, // VectorD
coleenp@3602 67 { Bad, T_ILLEGAL, "vectorx:", false, Op_VecX, relocInfo::none }, // VectorX
coleenp@3602 68 { Bad, T_ILLEGAL, "vectory:", false, Op_VecY, relocInfo::none }, // VectorY
coleenp@3602 69 #else
coleenp@3602 70 { Bad, T_ILLEGAL, "vectors:", false, 0, relocInfo::none }, // VectorS
coleenp@3602 71 { Bad, T_ILLEGAL, "vectord:", false, Op_RegD, relocInfo::none }, // VectorD
coleenp@3602 72 { Bad, T_ILLEGAL, "vectorx:", false, 0, relocInfo::none }, // VectorX
coleenp@3602 73 { Bad, T_ILLEGAL, "vectory:", false, 0, relocInfo::none }, // VectorY
coleenp@3602 74 #endif // IA32 || AMD64
coleenp@3602 75 { Bad, T_ADDRESS, "anyptr:", false, Op_RegP, relocInfo::none }, // AnyPtr
coleenp@3602 76 { Bad, T_ADDRESS, "rawptr:", false, Op_RegP, relocInfo::none }, // RawPtr
coleenp@3602 77 { Bad, T_OBJECT, "oop:", true, Op_RegP, relocInfo::oop_type }, // OopPtr
coleenp@3602 78 { Bad, T_OBJECT, "inst:", true, Op_RegP, relocInfo::oop_type }, // InstPtr
coleenp@3602 79 { Bad, T_OBJECT, "ary:", true, Op_RegP, relocInfo::oop_type }, // AryPtr
coleenp@3602 80 { Bad, T_METADATA, "metadata:", false, Op_RegP, relocInfo::metadata_type }, // MetadataPtr
coleenp@3602 81 { Bad, T_METADATA, "klass:", false, Op_RegP, relocInfo::metadata_type }, // KlassPtr
coleenp@3602 82 { Bad, T_OBJECT, "func", false, 0, relocInfo::none }, // Function
coleenp@3602 83 { Abio, T_ILLEGAL, "abIO", false, 0, relocInfo::none }, // Abio
coleenp@3602 84 { Return_Address, T_ADDRESS, "return_address",false, Op_RegP, relocInfo::none }, // Return_Address
coleenp@3602 85 { Memory, T_ILLEGAL, "memory", false, 0, relocInfo::none }, // Memory
coleenp@3602 86 { FloatBot, T_FLOAT, "float_top", false, Op_RegF, relocInfo::none }, // FloatTop
coleenp@3602 87 { FloatCon, T_FLOAT, "ftcon:", false, Op_RegF, relocInfo::none }, // FloatCon
coleenp@3602 88 { FloatTop, T_FLOAT, "float", false, Op_RegF, relocInfo::none }, // FloatBot
coleenp@3602 89 { DoubleBot, T_DOUBLE, "double_top", false, Op_RegD, relocInfo::none }, // DoubleTop
coleenp@3602 90 { DoubleCon, T_DOUBLE, "dblcon:", false, Op_RegD, relocInfo::none }, // DoubleCon
coleenp@3602 91 { DoubleTop, T_DOUBLE, "double", false, Op_RegD, relocInfo::none }, // DoubleBot
coleenp@3602 92 { Top, T_ILLEGAL, "bottom", false, 0, relocInfo::none } // Bottom
duke@0 93 };
duke@0 94
duke@0 95 // Map ideal registers (machine types) to ideal types
duke@0 96 const Type *Type::mreg2type[_last_machine_leaf];
duke@0 97
duke@0 98 // Map basic types to canonical Type* pointers.
duke@0 99 const Type* Type:: _const_basic_type[T_CONFLICT+1];
duke@0 100
duke@0 101 // Map basic types to constant-zero Types.
duke@0 102 const Type* Type:: _zero_type[T_CONFLICT+1];
duke@0 103
duke@0 104 // Map basic types to array-body alias types.
duke@0 105 const TypeAryPtr* TypeAryPtr::_array_body_type[T_CONFLICT+1];
duke@0 106
duke@0 107 //=============================================================================
duke@0 108 // Convenience common pre-built types.
duke@0 109 const Type *Type::ABIO; // State-of-machine only
duke@0 110 const Type *Type::BOTTOM; // All values
duke@0 111 const Type *Type::CONTROL; // Control only
duke@0 112 const Type *Type::DOUBLE; // All doubles
duke@0 113 const Type *Type::FLOAT; // All floats
duke@0 114 const Type *Type::HALF; // Placeholder half of doublewide type
duke@0 115 const Type *Type::MEMORY; // Abstract store only
duke@0 116 const Type *Type::RETURN_ADDRESS;
duke@0 117 const Type *Type::TOP; // No values in set
duke@0 118
duke@0 119 //------------------------------get_const_type---------------------------
duke@0 120 const Type* Type::get_const_type(ciType* type) {
duke@0 121 if (type == NULL) {
duke@0 122 return NULL;
duke@0 123 } else if (type->is_primitive_type()) {
duke@0 124 return get_const_basic_type(type->basic_type());
duke@0 125 } else {
duke@0 126 return TypeOopPtr::make_from_klass(type->as_klass());
duke@0 127 }
duke@0 128 }
duke@0 129
duke@0 130 //---------------------------array_element_basic_type---------------------------------
duke@0 131 // Mapping to the array element's basic type.
duke@0 132 BasicType Type::array_element_basic_type() const {
duke@0 133 BasicType bt = basic_type();
duke@0 134 if (bt == T_INT) {
duke@0 135 if (this == TypeInt::INT) return T_INT;
duke@0 136 if (this == TypeInt::CHAR) return T_CHAR;
duke@0 137 if (this == TypeInt::BYTE) return T_BYTE;
duke@0 138 if (this == TypeInt::BOOL) return T_BOOLEAN;
duke@0 139 if (this == TypeInt::SHORT) return T_SHORT;
duke@0 140 return T_VOID;
duke@0 141 }
duke@0 142 return bt;
duke@0 143 }
duke@0 144
duke@0 145 //---------------------------get_typeflow_type---------------------------------
duke@0 146 // Import a type produced by ciTypeFlow.
duke@0 147 const Type* Type::get_typeflow_type(ciType* type) {
duke@0 148 switch (type->basic_type()) {
duke@0 149
duke@0 150 case ciTypeFlow::StateVector::T_BOTTOM:
duke@0 151 assert(type == ciTypeFlow::StateVector::bottom_type(), "");
duke@0 152 return Type::BOTTOM;
duke@0 153
duke@0 154 case ciTypeFlow::StateVector::T_TOP:
duke@0 155 assert(type == ciTypeFlow::StateVector::top_type(), "");
duke@0 156 return Type::TOP;
duke@0 157
duke@0 158 case ciTypeFlow::StateVector::T_NULL:
duke@0 159 assert(type == ciTypeFlow::StateVector::null_type(), "");
duke@0 160 return TypePtr::NULL_PTR;
duke@0 161
duke@0 162 case ciTypeFlow::StateVector::T_LONG2:
duke@0 163 // The ciTypeFlow pass pushes a long, then the half.
duke@0 164 // We do the same.
duke@0 165 assert(type == ciTypeFlow::StateVector::long2_type(), "");
duke@0 166 return TypeInt::TOP;
duke@0 167
duke@0 168 case ciTypeFlow::StateVector::T_DOUBLE2:
duke@0 169 // The ciTypeFlow pass pushes double, then the half.
duke@0 170 // Our convention is the same.
duke@0 171 assert(type == ciTypeFlow::StateVector::double2_type(), "");
duke@0 172 return Type::TOP;
duke@0 173
duke@0 174 case T_ADDRESS:
duke@0 175 assert(type->is_return_address(), "");
duke@0 176 return TypeRawPtr::make((address)(intptr_t)type->as_return_address()->bci());
duke@0 177
duke@0 178 default:
duke@0 179 // make sure we did not mix up the cases:
duke@0 180 assert(type != ciTypeFlow::StateVector::bottom_type(), "");
duke@0 181 assert(type != ciTypeFlow::StateVector::top_type(), "");
duke@0 182 assert(type != ciTypeFlow::StateVector::null_type(), "");
duke@0 183 assert(type != ciTypeFlow::StateVector::long2_type(), "");
duke@0 184 assert(type != ciTypeFlow::StateVector::double2_type(), "");
duke@0 185 assert(!type->is_return_address(), "");
duke@0 186
duke@0 187 return Type::get_const_type(type);
duke@0 188 }
duke@0 189 }
duke@0 190
duke@0 191
vlivanov@5223 192 //-----------------------make_from_constant------------------------------------
vlivanov@5223 193 const Type* Type::make_from_constant(ciConstant constant,
vlivanov@5223 194 bool require_constant, bool is_autobox_cache) {
vlivanov@5223 195 switch (constant.basic_type()) {
vlivanov@5223 196 case T_BOOLEAN: return TypeInt::make(constant.as_boolean());
vlivanov@5223 197 case T_CHAR: return TypeInt::make(constant.as_char());
vlivanov@5223 198 case T_BYTE: return TypeInt::make(constant.as_byte());
vlivanov@5223 199 case T_SHORT: return TypeInt::make(constant.as_short());
vlivanov@5223 200 case T_INT: return TypeInt::make(constant.as_int());
vlivanov@5223 201 case T_LONG: return TypeLong::make(constant.as_long());
vlivanov@5223 202 case T_FLOAT: return TypeF::make(constant.as_float());
vlivanov@5223 203 case T_DOUBLE: return TypeD::make(constant.as_double());
vlivanov@5223 204 case T_ARRAY:
vlivanov@5223 205 case T_OBJECT:
vlivanov@5223 206 {
vlivanov@5223 207 // cases:
vlivanov@5223 208 // can_be_constant = (oop not scavengable || ScavengeRootsInCode != 0)
vlivanov@5223 209 // should_be_constant = (oop not scavengable || ScavengeRootsInCode >= 2)
vlivanov@5223 210 // An oop is not scavengable if it is in the perm gen.
vlivanov@5223 211 ciObject* oop_constant = constant.as_object();
vlivanov@5223 212 if (oop_constant->is_null_object()) {
vlivanov@5223 213 return Type::get_zero_type(T_OBJECT);
vlivanov@5223 214 } else if (require_constant || oop_constant->should_be_constant()) {
vlivanov@5223 215 return TypeOopPtr::make_from_constant(oop_constant, require_constant, is_autobox_cache);
vlivanov@5223 216 }
vlivanov@5223 217 }
vlivanov@5223 218 }
vlivanov@5223 219 // Fall through to failure
vlivanov@5223 220 return NULL;
vlivanov@5223 221 }
vlivanov@5223 222
vlivanov@5223 223
duke@0 224 //------------------------------make-------------------------------------------
duke@0 225 // Create a simple Type, with default empty symbol sets. Then hashcons it
duke@0 226 // and look for an existing copy in the type dictionary.
duke@0 227 const Type *Type::make( enum TYPES t ) {
duke@0 228 return (new Type(t))->hashcons();
duke@0 229 }
kvn@223 230
duke@0 231 //------------------------------cmp--------------------------------------------
duke@0 232 int Type::cmp( const Type *const t1, const Type *const t2 ) {
duke@0 233 if( t1->_base != t2->_base )
duke@0 234 return 1; // Missed badly
duke@0 235 assert(t1 != t2 || t1->eq(t2), "eq must be reflexive");
duke@0 236 return !t1->eq(t2); // Return ZERO if equal
duke@0 237 }
duke@0 238
duke@0 239 //------------------------------hash-------------------------------------------
duke@0 240 int Type::uhash( const Type *const t ) {
duke@0 241 return t->hash();
duke@0 242 }
duke@0 243
kvn@1540 244 #define SMALLINT ((juint)3) // a value too insignificant to consider widening
kvn@1540 245
duke@0 246 //--------------------------Initialize_shared----------------------------------
duke@0 247 void Type::Initialize_shared(Compile* current) {
duke@0 248 // This method does not need to be locked because the first system
duke@0 249 // compilations (stub compilations) occur serially. If they are
duke@0 250 // changed to proceed in parallel, then this section will need
duke@0 251 // locking.
duke@0 252
duke@0 253 Arena* save = current->type_arena();
zgu@3465 254 Arena* shared_type_arena = new (mtCompiler)Arena();
duke@0 255
duke@0 256 current->set_type_arena(shared_type_arena);
duke@0 257 _shared_type_dict =
duke@0 258 new (shared_type_arena) Dict( (CmpKey)Type::cmp, (Hash)Type::uhash,
duke@0 259 shared_type_arena, 128 );
duke@0 260 current->set_type_dict(_shared_type_dict);
duke@0 261
duke@0 262 // Make shared pre-built types.
duke@0 263 CONTROL = make(Control); // Control only
duke@0 264 TOP = make(Top); // No values in set
duke@0 265 MEMORY = make(Memory); // Abstract store only
duke@0 266 ABIO = make(Abio); // State-of-machine only
duke@0 267 RETURN_ADDRESS=make(Return_Address);
duke@0 268 FLOAT = make(FloatBot); // All floats
duke@0 269 DOUBLE = make(DoubleBot); // All doubles
duke@0 270 BOTTOM = make(Bottom); // Everything
duke@0 271 HALF = make(Half); // Placeholder half of doublewide type
duke@0 272
duke@0 273 TypeF::ZERO = TypeF::make(0.0); // Float 0 (positive zero)
duke@0 274 TypeF::ONE = TypeF::make(1.0); // Float 1
duke@0 275
duke@0 276 TypeD::ZERO = TypeD::make(0.0); // Double 0 (positive zero)
duke@0 277 TypeD::ONE = TypeD::make(1.0); // Double 1
duke@0 278
duke@0 279 TypeInt::MINUS_1 = TypeInt::make(-1); // -1
duke@0 280 TypeInt::ZERO = TypeInt::make( 0); // 0
duke@0 281 TypeInt::ONE = TypeInt::make( 1); // 1
duke@0 282 TypeInt::BOOL = TypeInt::make(0,1, WidenMin); // 0 or 1, FALSE or TRUE.
duke@0 283 TypeInt::CC = TypeInt::make(-1, 1, WidenMin); // -1, 0 or 1, condition codes
duke@0 284 TypeInt::CC_LT = TypeInt::make(-1,-1, WidenMin); // == TypeInt::MINUS_1
duke@0 285 TypeInt::CC_GT = TypeInt::make( 1, 1, WidenMin); // == TypeInt::ONE
duke@0 286 TypeInt::CC_EQ = TypeInt::make( 0, 0, WidenMin); // == TypeInt::ZERO
duke@0 287 TypeInt::CC_LE = TypeInt::make(-1, 0, WidenMin);
duke@0 288 TypeInt::CC_GE = TypeInt::make( 0, 1, WidenMin); // == TypeInt::BOOL
duke@0 289 TypeInt::BYTE = TypeInt::make(-128,127, WidenMin); // Bytes
twisti@624 290 TypeInt::UBYTE = TypeInt::make(0, 255, WidenMin); // Unsigned Bytes
duke@0 291 TypeInt::CHAR = TypeInt::make(0,65535, WidenMin); // Java chars
duke@0 292 TypeInt::SHORT = TypeInt::make(-32768,32767, WidenMin); // Java shorts
duke@0 293 TypeInt::POS = TypeInt::make(0,max_jint, WidenMin); // Non-neg values
duke@0 294 TypeInt::POS1 = TypeInt::make(1,max_jint, WidenMin); // Positive values
duke@0 295 TypeInt::INT = TypeInt::make(min_jint,max_jint, WidenMax); // 32-bit integers
duke@0 296 TypeInt::SYMINT = TypeInt::make(-max_jint,max_jint,WidenMin); // symmetric range
duke@0 297 // CmpL is overloaded both as the bytecode computation returning
duke@0 298 // a trinary (-1,0,+1) integer result AND as an efficient long
duke@0 299 // compare returning optimizer ideal-type flags.
duke@0 300 assert( TypeInt::CC_LT == TypeInt::MINUS_1, "types must match for CmpL to work" );
duke@0 301 assert( TypeInt::CC_GT == TypeInt::ONE, "types must match for CmpL to work" );
duke@0 302 assert( TypeInt::CC_EQ == TypeInt::ZERO, "types must match for CmpL to work" );
duke@0 303 assert( TypeInt::CC_GE == TypeInt::BOOL, "types must match for CmpL to work" );
kvn@1540 304 assert( (juint)(TypeInt::CC->_hi - TypeInt::CC->_lo) <= SMALLINT, "CC is truly small");
duke@0 305
duke@0 306 TypeLong::MINUS_1 = TypeLong::make(-1); // -1
duke@0 307 TypeLong::ZERO = TypeLong::make( 0); // 0
duke@0 308 TypeLong::ONE = TypeLong::make( 1); // 1
duke@0 309 TypeLong::POS = TypeLong::make(0,max_jlong, WidenMin); // Non-neg values
duke@0 310 TypeLong::LONG = TypeLong::make(min_jlong,max_jlong,WidenMax); // 64-bit integers
duke@0 311 TypeLong::INT = TypeLong::make((jlong)min_jint,(jlong)max_jint,WidenMin);
duke@0 312 TypeLong::UINT = TypeLong::make(0,(jlong)max_juint,WidenMin);
duke@0 313
duke@0 314 const Type **fboth =(const Type**)shared_type_arena->Amalloc_4(2*sizeof(Type*));
duke@0 315 fboth[0] = Type::CONTROL;
duke@0 316 fboth[1] = Type::CONTROL;
duke@0 317 TypeTuple::IFBOTH = TypeTuple::make( 2, fboth );
duke@0 318
duke@0 319 const Type **ffalse =(const Type**)shared_type_arena->Amalloc_4(2*sizeof(Type*));
duke@0 320 ffalse[0] = Type::CONTROL;
duke@0 321 ffalse[1] = Type::TOP;
duke@0 322 TypeTuple::IFFALSE = TypeTuple::make( 2, ffalse );
duke@0 323
duke@0 324 const Type **fneither =(const Type**)shared_type_arena->Amalloc_4(2*sizeof(Type*));
duke@0 325 fneither[0] = Type::TOP;
duke@0 326 fneither[1] = Type::TOP;
duke@0 327 TypeTuple::IFNEITHER = TypeTuple::make( 2, fneither );
duke@0 328
duke@0 329 const Type **ftrue =(const Type**)shared_type_arena->Amalloc_4(2*sizeof(Type*));
duke@0 330 ftrue[0] = Type::TOP;
duke@0 331 ftrue[1] = Type::CONTROL;
duke@0 332 TypeTuple::IFTRUE = TypeTuple::make( 2, ftrue );
duke@0 333
duke@0 334 const Type **floop =(const Type**)shared_type_arena->Amalloc_4(2*sizeof(Type*));
duke@0 335 floop[0] = Type::CONTROL;
duke@0 336 floop[1] = TypeInt::INT;
duke@0 337 TypeTuple::LOOPBODY = TypeTuple::make( 2, floop );
duke@0 338
duke@0 339 TypePtr::NULL_PTR= TypePtr::make( AnyPtr, TypePtr::Null, 0 );
duke@0 340 TypePtr::NOTNULL = TypePtr::make( AnyPtr, TypePtr::NotNull, OffsetBot );
duke@0 341 TypePtr::BOTTOM = TypePtr::make( AnyPtr, TypePtr::BotPTR, OffsetBot );
duke@0 342
duke@0 343 TypeRawPtr::BOTTOM = TypeRawPtr::make( TypePtr::BotPTR );
duke@0 344 TypeRawPtr::NOTNULL= TypeRawPtr::make( TypePtr::NotNull );
duke@0 345
duke@0 346 const Type **fmembar = TypeTuple::fields(0);
duke@0 347 TypeTuple::MEMBAR = TypeTuple::make(TypeFunc::Parms+0, fmembar);
duke@0 348
duke@0 349 const Type **fsc = (const Type**)shared_type_arena->Amalloc_4(2*sizeof(Type*));
duke@0 350 fsc[0] = TypeInt::CC;
duke@0 351 fsc[1] = Type::MEMORY;
duke@0 352 TypeTuple::STORECONDITIONAL = TypeTuple::make(2, fsc);
duke@0 353
duke@0 354 TypeInstPtr::NOTNULL = TypeInstPtr::make(TypePtr::NotNull, current->env()->Object_klass());
duke@0 355 TypeInstPtr::BOTTOM = TypeInstPtr::make(TypePtr::BotPTR, current->env()->Object_klass());
duke@0 356 TypeInstPtr::MIRROR = TypeInstPtr::make(TypePtr::NotNull, current->env()->Class_klass());
duke@0 357 TypeInstPtr::MARK = TypeInstPtr::make(TypePtr::BotPTR, current->env()->Object_klass(),
duke@0 358 false, 0, oopDesc::mark_offset_in_bytes());
duke@0 359 TypeInstPtr::KLASS = TypeInstPtr::make(TypePtr::BotPTR, current->env()->Object_klass(),
duke@0 360 false, 0, oopDesc::klass_offset_in_bytes());
kvn@992 361 TypeOopPtr::BOTTOM = TypeOopPtr::make(TypePtr::BotPTR, OffsetBot, TypeOopPtr::InstanceBot);
duke@0 362
coleenp@3602 363 TypeMetadataPtr::BOTTOM = TypeMetadataPtr::make(TypePtr::BotPTR, NULL, OffsetBot);
coleenp@3602 364
coleenp@113 365 TypeNarrowOop::NULL_PTR = TypeNarrowOop::make( TypePtr::NULL_PTR );
coleenp@113 366 TypeNarrowOop::BOTTOM = TypeNarrowOop::make( TypeInstPtr::BOTTOM );
coleenp@113 367
roland@3724 368 TypeNarrowKlass::NULL_PTR = TypeNarrowKlass::make( TypePtr::NULL_PTR );
roland@3724 369
coleenp@113 370 mreg2type[Op_Node] = Type::BOTTOM;
coleenp@113 371 mreg2type[Op_Set ] = 0;
coleenp@113 372 mreg2type[Op_RegN] = TypeNarrowOop::BOTTOM;
coleenp@113 373 mreg2type[Op_RegI] = TypeInt::INT;
coleenp@113 374 mreg2type[Op_RegP] = TypePtr::BOTTOM;
coleenp@113 375 mreg2type[Op_RegF] = Type::FLOAT;
coleenp@113 376 mreg2type[Op_RegD] = Type::DOUBLE;
coleenp@113 377 mreg2type[Op_RegL] = TypeLong::LONG;
coleenp@113 378 mreg2type[Op_RegFlags] = TypeInt::CC;
coleenp@113 379
kvn@1681 380 TypeAryPtr::RANGE = TypeAryPtr::make( TypePtr::BotPTR, TypeAry::make(Type::BOTTOM,TypeInt::POS), NULL /* current->env()->Object_klass() */, false, arrayOopDesc::length_offset_in_bytes());
kvn@163 381
kvn@163 382 TypeAryPtr::NARROWOOPS = TypeAryPtr::make(TypePtr::BotPTR, TypeAry::make(TypeNarrowOop::BOTTOM, TypeInt::POS), NULL /*ciArrayKlass::make(o)*/, false, Type::OffsetBot);
kvn@163 383
kvn@163 384 #ifdef _LP64
kvn@163 385 if (UseCompressedOops) {
coleenp@3602 386 assert(TypeAryPtr::NARROWOOPS->is_ptr_to_narrowoop(), "array of narrow oops must be ptr to narrow oop");
kvn@163 387 TypeAryPtr::OOPS = TypeAryPtr::NARROWOOPS;
kvn@163 388 } else
kvn@163 389 #endif
kvn@163 390 {
kvn@163 391 // There is no shared klass for Object[]. See note in TypeAryPtr::klass().
kvn@163 392 TypeAryPtr::OOPS = TypeAryPtr::make(TypePtr::BotPTR, TypeAry::make(TypeInstPtr::BOTTOM,TypeInt::POS), NULL /*ciArrayKlass::make(o)*/, false, Type::OffsetBot);
kvn@163 393 }
duke@0 394 TypeAryPtr::BYTES = TypeAryPtr::make(TypePtr::BotPTR, TypeAry::make(TypeInt::BYTE ,TypeInt::POS), ciTypeArrayKlass::make(T_BYTE), true, Type::OffsetBot);
duke@0 395 TypeAryPtr::SHORTS = TypeAryPtr::make(TypePtr::BotPTR, TypeAry::make(TypeInt::SHORT ,TypeInt::POS), ciTypeArrayKlass::make(T_SHORT), true, Type::OffsetBot);
duke@0 396 TypeAryPtr::CHARS = TypeAryPtr::make(TypePtr::BotPTR, TypeAry::make(TypeInt::CHAR ,TypeInt::POS), ciTypeArrayKlass::make(T_CHAR), true, Type::OffsetBot);
duke@0 397 TypeAryPtr::INTS = TypeAryPtr::make(TypePtr::BotPTR, TypeAry::make(TypeInt::INT ,TypeInt::POS), ciTypeArrayKlass::make(T_INT), true, Type::OffsetBot);
duke@0 398 TypeAryPtr::LONGS = TypeAryPtr::make(TypePtr::BotPTR, TypeAry::make(TypeLong::LONG ,TypeInt::POS), ciTypeArrayKlass::make(T_LONG), true, Type::OffsetBot);
duke@0 399 TypeAryPtr::FLOATS = TypeAryPtr::make(TypePtr::BotPTR, TypeAry::make(Type::FLOAT ,TypeInt::POS), ciTypeArrayKlass::make(T_FLOAT), true, Type::OffsetBot);
duke@0 400 TypeAryPtr::DOUBLES = TypeAryPtr::make(TypePtr::BotPTR, TypeAry::make(Type::DOUBLE ,TypeInt::POS), ciTypeArrayKlass::make(T_DOUBLE), true, Type::OffsetBot);
duke@0 401
kvn@163 402 // Nobody should ask _array_body_type[T_NARROWOOP]. Use NULL as assert.
kvn@163 403 TypeAryPtr::_array_body_type[T_NARROWOOP] = NULL;
duke@0 404 TypeAryPtr::_array_body_type[T_OBJECT] = TypeAryPtr::OOPS;
kvn@163 405 TypeAryPtr::_array_body_type[T_ARRAY] = TypeAryPtr::OOPS; // arrays are stored in oop arrays
duke@0 406 TypeAryPtr::_array_body_type[T_BYTE] = TypeAryPtr::BYTES;
duke@0 407 TypeAryPtr::_array_body_type[T_BOOLEAN] = TypeAryPtr::BYTES; // boolean[] is a byte array
duke@0 408 TypeAryPtr::_array_body_type[T_SHORT] = TypeAryPtr::SHORTS;
duke@0 409 TypeAryPtr::_array_body_type[T_CHAR] = TypeAryPtr::CHARS;
duke@0 410 TypeAryPtr::_array_body_type[T_INT] = TypeAryPtr::INTS;
duke@0 411 TypeAryPtr::_array_body_type[T_LONG] = TypeAryPtr::LONGS;
duke@0 412 TypeAryPtr::_array_body_type[T_FLOAT] = TypeAryPtr::FLOATS;
duke@0 413 TypeAryPtr::_array_body_type[T_DOUBLE] = TypeAryPtr::DOUBLES;
duke@0 414
duke@0 415 TypeKlassPtr::OBJECT = TypeKlassPtr::make( TypePtr::NotNull, current->env()->Object_klass(), 0 );
duke@0 416 TypeKlassPtr::OBJECT_OR_NULL = TypeKlassPtr::make( TypePtr::BotPTR, current->env()->Object_klass(), 0 );
duke@0 417
duke@0 418 const Type **fi2c = TypeTuple::fields(2);
coleenp@3602 419 fi2c[TypeFunc::Parms+0] = TypeInstPtr::BOTTOM; // Method*
duke@0 420 fi2c[TypeFunc::Parms+1] = TypeRawPtr::BOTTOM; // argument pointer
duke@0 421 TypeTuple::START_I2C = TypeTuple::make(TypeFunc::Parms+2, fi2c);
duke@0 422
duke@0 423 const Type **intpair = TypeTuple::fields(2);
duke@0 424 intpair[0] = TypeInt::INT;
duke@0 425 intpair[1] = TypeInt::INT;
duke@0 426 TypeTuple::INT_PAIR = TypeTuple::make(2, intpair);
duke@0 427
duke@0 428 const Type **longpair = TypeTuple::fields(2);
duke@0 429 longpair[0] = TypeLong::LONG;
duke@0 430 longpair[1] = TypeLong::LONG;
duke@0 431 TypeTuple::LONG_PAIR = TypeTuple::make(2, longpair);
duke@0 432
roland@3724 433 _const_basic_type[T_NARROWOOP] = TypeNarrowOop::BOTTOM;
roland@3724 434 _const_basic_type[T_NARROWKLASS] = Type::BOTTOM;
roland@3724 435 _const_basic_type[T_BOOLEAN] = TypeInt::BOOL;
roland@3724 436 _const_basic_type[T_CHAR] = TypeInt::CHAR;
roland@3724 437 _const_basic_type[T_BYTE] = TypeInt::BYTE;
roland@3724 438 _const_basic_type[T_SHORT] = TypeInt::SHORT;
roland@3724 439 _const_basic_type[T_INT] = TypeInt::INT;
roland@3724 440 _const_basic_type[T_LONG] = TypeLong::LONG;
roland@3724 441 _const_basic_type[T_FLOAT] = Type::FLOAT;
roland@3724 442 _const_basic_type[T_DOUBLE] = Type::DOUBLE;
roland@3724 443 _const_basic_type[T_OBJECT] = TypeInstPtr::BOTTOM;
roland@3724 444 _const_basic_type[T_ARRAY] = TypeInstPtr::BOTTOM; // there is no separate bottom for arrays
roland@3724 445 _const_basic_type[T_VOID] = TypePtr::NULL_PTR; // reflection represents void this way
roland@3724 446 _const_basic_type[T_ADDRESS] = TypeRawPtr::BOTTOM; // both interpreter return addresses & random raw ptrs
roland@3724 447 _const_basic_type[T_CONFLICT] = Type::BOTTOM; // why not?
roland@3724 448
roland@3724 449 _zero_type[T_NARROWOOP] = TypeNarrowOop::NULL_PTR;
roland@3724 450 _zero_type[T_NARROWKLASS] = TypeNarrowKlass::NULL_PTR;
roland@3724 451 _zero_type[T_BOOLEAN] = TypeInt::ZERO; // false == 0
roland@3724 452 _zero_type[T_CHAR] = TypeInt::ZERO; // '\0' == 0
roland@3724 453 _zero_type[T_BYTE] = TypeInt::ZERO; // 0x00 == 0
roland@3724 454 _zero_type[T_SHORT] = TypeInt::ZERO; // 0x0000 == 0
roland@3724 455 _zero_type[T_INT] = TypeInt::ZERO;
roland@3724 456 _zero_type[T_LONG] = TypeLong::ZERO;
roland@3724 457 _zero_type[T_FLOAT] = TypeF::ZERO;
roland@3724 458 _zero_type[T_DOUBLE] = TypeD::ZERO;
roland@3724 459 _zero_type[T_OBJECT] = TypePtr::NULL_PTR;
roland@3724 460 _zero_type[T_ARRAY] = TypePtr::NULL_PTR; // null array is null oop
roland@3724 461 _zero_type[T_ADDRESS] = TypePtr::NULL_PTR; // raw pointers use the same null
roland@3724 462 _zero_type[T_VOID] = Type::TOP; // the only void value is no value at all
duke@0 463
duke@0 464 // get_zero_type() should not happen for T_CONFLICT
duke@0 465 _zero_type[T_CONFLICT]= NULL;
duke@0 466
kvn@3447 467 // Vector predefined types, it needs initialized _const_basic_type[].
kvn@3447 468 if (Matcher::vector_size_supported(T_BYTE,4)) {
kvn@3447 469 TypeVect::VECTS = TypeVect::make(T_BYTE,4);
kvn@3447 470 }
kvn@3447 471 if (Matcher::vector_size_supported(T_FLOAT,2)) {
kvn@3447 472 TypeVect::VECTD = TypeVect::make(T_FLOAT,2);
kvn@3447 473 }
kvn@3447 474 if (Matcher::vector_size_supported(T_FLOAT,4)) {
kvn@3447 475 TypeVect::VECTX = TypeVect::make(T_FLOAT,4);
kvn@3447 476 }
kvn@3447 477 if (Matcher::vector_size_supported(T_FLOAT,8)) {
kvn@3447 478 TypeVect::VECTY = TypeVect::make(T_FLOAT,8);
kvn@3447 479 }
kvn@3447 480 mreg2type[Op_VecS] = TypeVect::VECTS;
kvn@3447 481 mreg2type[Op_VecD] = TypeVect::VECTD;
kvn@3447 482 mreg2type[Op_VecX] = TypeVect::VECTX;
kvn@3447 483 mreg2type[Op_VecY] = TypeVect::VECTY;
kvn@3447 484
duke@0 485 // Restore working type arena.
duke@0 486 current->set_type_arena(save);
duke@0 487 current->set_type_dict(NULL);
duke@0 488 }
duke@0 489
duke@0 490 //------------------------------Initialize-------------------------------------
duke@0 491 void Type::Initialize(Compile* current) {
duke@0 492 assert(current->type_arena() != NULL, "must have created type arena");
duke@0 493
duke@0 494 if (_shared_type_dict == NULL) {
duke@0 495 Initialize_shared(current);
duke@0 496 }
duke@0 497
duke@0 498 Arena* type_arena = current->type_arena();
duke@0 499
duke@0 500 // Create the hash-cons'ing dictionary with top-level storage allocation
duke@0 501 Dict *tdic = new (type_arena) Dict( (CmpKey)Type::cmp,(Hash)Type::uhash, type_arena, 128 );
duke@0 502 current->set_type_dict(tdic);
duke@0 503
duke@0 504 // Transfer the shared types.
duke@0 505 DictI i(_shared_type_dict);
duke@0 506 for( ; i.test(); ++i ) {
duke@0 507 Type* t = (Type*)i._value;
duke@0 508 tdic->Insert(t,t); // New Type, insert into Type table
duke@0 509 }
duke@0 510 }
duke@0 511
duke@0 512 //------------------------------hashcons---------------------------------------
duke@0 513 // Do the hash-cons trick. If the Type already exists in the type table,
duke@0 514 // delete the current Type and return the existing Type. Otherwise stick the
duke@0 515 // current Type in the Type table.
duke@0 516 const Type *Type::hashcons(void) {
duke@0 517 debug_only(base()); // Check the assertion in Type::base().
duke@0 518 // Look up the Type in the Type dictionary
duke@0 519 Dict *tdic = type_dict();
duke@0 520 Type* old = (Type*)(tdic->Insert(this, this, false));
duke@0 521 if( old ) { // Pre-existing Type?
duke@0 522 if( old != this ) // Yes, this guy is not the pre-existing?
duke@0 523 delete this; // Yes, Nuke this guy
duke@0 524 assert( old->_dual, "" );
duke@0 525 return old; // Return pre-existing
duke@0 526 }
duke@0 527
duke@0 528 // Every type has a dual (to make my lattice symmetric).
duke@0 529 // Since we just discovered a new Type, compute its dual right now.
duke@0 530 assert( !_dual, "" ); // No dual yet
duke@0 531 _dual = xdual(); // Compute the dual
duke@0 532 if( cmp(this,_dual)==0 ) { // Handle self-symmetric
duke@0 533 _dual = this;
duke@0 534 return this;
duke@0 535 }
duke@0 536 assert( !_dual->_dual, "" ); // No reverse dual yet
duke@0 537 assert( !(*tdic)[_dual], "" ); // Dual not in type system either
duke@0 538 // New Type, insert into Type table
duke@0 539 tdic->Insert((void*)_dual,(void*)_dual);
duke@0 540 ((Type*)_dual)->_dual = this; // Finish up being symmetric
duke@0 541 #ifdef ASSERT
duke@0 542 Type *dual_dual = (Type*)_dual->xdual();
duke@0 543 assert( eq(dual_dual), "xdual(xdual()) should be identity" );
duke@0 544 delete dual_dual;
duke@0 545 #endif
duke@0 546 return this; // Return new Type
duke@0 547 }
duke@0 548
duke@0 549 //------------------------------eq---------------------------------------------
duke@0 550 // Structural equality check for Type representations
duke@0 551 bool Type::eq( const Type * ) const {
duke@0 552 return true; // Nothing else can go wrong
duke@0 553 }
duke@0 554
duke@0 555 //------------------------------hash-------------------------------------------
duke@0 556 // Type-specific hashing function.
duke@0 557 int Type::hash(void) const {
duke@0 558 return _base;
duke@0 559 }
duke@0 560
duke@0 561 //------------------------------is_finite--------------------------------------
duke@0 562 // Has a finite value
duke@0 563 bool Type::is_finite() const {
duke@0 564 return false;
duke@0 565 }
duke@0 566
duke@0 567 //------------------------------is_nan-----------------------------------------
duke@0 568 // Is not a number (NaN)
duke@0 569 bool Type::is_nan() const {
duke@0 570 return false;
duke@0 571 }
duke@0 572
kvn@820 573 //----------------------interface_vs_oop---------------------------------------
kvn@820 574 #ifdef ASSERT
kvn@820 575 bool Type::interface_vs_oop(const Type *t) const {
kvn@820 576 bool result = false;
kvn@820 577
kvn@992 578 const TypePtr* this_ptr = this->make_ptr(); // In case it is narrow_oop
kvn@992 579 const TypePtr* t_ptr = t->make_ptr();
kvn@992 580 if( this_ptr == NULL || t_ptr == NULL )
kvn@992 581 return result;
kvn@992 582
kvn@992 583 const TypeInstPtr* this_inst = this_ptr->isa_instptr();
kvn@992 584 const TypeInstPtr* t_inst = t_ptr->isa_instptr();
kvn@820 585 if( this_inst && this_inst->is_loaded() && t_inst && t_inst->is_loaded() ) {
kvn@820 586 bool this_interface = this_inst->klass()->is_interface();
kvn@820 587 bool t_interface = t_inst->klass()->is_interface();
kvn@820 588 result = this_interface ^ t_interface;
kvn@820 589 }
kvn@820 590
kvn@820 591 return result;
kvn@820 592 }
kvn@820 593 #endif
kvn@820 594
duke@0 595 //------------------------------meet-------------------------------------------
duke@0 596 // Compute the MEET of two types. NOT virtual. It enforces that meet is
duke@0 597 // commutative and the lattice is symmetric.
duke@0 598 const Type *Type::meet( const Type *t ) const {
coleenp@113 599 if (isa_narrowoop() && t->isa_narrowoop()) {
kvn@221 600 const Type* result = make_ptr()->meet(t->make_ptr());
kvn@221 601 return result->make_narrowoop();
coleenp@113 602 }
roland@3724 603 if (isa_narrowklass() && t->isa_narrowklass()) {
roland@3724 604 const Type* result = make_ptr()->meet(t->make_ptr());
roland@3724 605 return result->make_narrowklass();
roland@3724 606 }
coleenp@113 607
duke@0 608 const Type *mt = xmeet(t);
coleenp@113 609 if (isa_narrowoop() || t->isa_narrowoop()) return mt;
roland@3724 610 if (isa_narrowklass() || t->isa_narrowklass()) return mt;
duke@0 611 #ifdef ASSERT
duke@0 612 assert( mt == t->xmeet(this), "meet not commutative" );
duke@0 613 const Type* dual_join = mt->_dual;
duke@0 614 const Type *t2t = dual_join->xmeet(t->_dual);
duke@0 615 const Type *t2this = dual_join->xmeet( _dual);
duke@0 616
duke@0 617 // Interface meet Oop is Not Symmetric:
duke@0 618 // Interface:AnyNull meet Oop:AnyNull == Interface:AnyNull
duke@0 619 // Interface:NotNull meet Oop:NotNull == java/lang/Object:NotNull
kvn@820 620
kvn@820 621 if( !interface_vs_oop(t) && (t2t != t->_dual || t2this != _dual) ) {
duke@0 622 tty->print_cr("=== Meet Not Symmetric ===");
duke@0 623 tty->print("t = "); t->dump(); tty->cr();
duke@0 624 tty->print("this= "); dump(); tty->cr();
duke@0 625 tty->print("mt=(t meet this)= "); mt->dump(); tty->cr();
duke@0 626
duke@0 627 tty->print("t_dual= "); t->_dual->dump(); tty->cr();
duke@0 628 tty->print("this_dual= "); _dual->dump(); tty->cr();
duke@0 629 tty->print("mt_dual= "); mt->_dual->dump(); tty->cr();
duke@0 630
duke@0 631 tty->print("mt_dual meet t_dual= "); t2t ->dump(); tty->cr();
duke@0 632 tty->print("mt_dual meet this_dual= "); t2this ->dump(); tty->cr();
duke@0 633
duke@0 634 fatal("meet not symmetric" );
duke@0 635 }
duke@0 636 #endif
duke@0 637 return mt;
duke@0 638 }
duke@0 639
duke@0 640 //------------------------------xmeet------------------------------------------
duke@0 641 // Compute the MEET of two types. It returns a new Type object.
duke@0 642 const Type *Type::xmeet( const Type *t ) const {
duke@0 643 // Perform a fast test for common case; meeting the same types together.
duke@0 644 if( this == t ) return this; // Meeting same type-rep?
duke@0 645
duke@0 646 // Meeting TOP with anything?
duke@0 647 if( _base == Top ) return t;
duke@0 648
duke@0 649 // Meeting BOTTOM with anything?
duke@0 650 if( _base == Bottom ) return BOTTOM;
duke@0 651
duke@0 652 // Current "this->_base" is one of: Bad, Multi, Control, Top,
duke@0 653 // Abio, Abstore, Floatxxx, Doublexxx, Bottom, lastype.
duke@0 654 switch (t->base()) { // Switch on original type
duke@0 655
duke@0 656 // Cut in half the number of cases I must handle. Only need cases for when
duke@0 657 // the given enum "t->type" is less than or equal to the local enum "type".
duke@0 658 case FloatCon:
duke@0 659 case DoubleCon:
duke@0 660 case Int:
duke@0 661 case Long:
duke@0 662 return t->xmeet(this);
duke@0 663
duke@0 664 case OopPtr:
duke@0 665 return t->xmeet(this);
duke@0 666
duke@0 667 case InstPtr:
duke@0 668 return t->xmeet(this);
duke@0 669
coleenp@3602 670 case MetadataPtr:
duke@0 671 case KlassPtr:
duke@0 672 return t->xmeet(this);
duke@0 673
duke@0 674 case AryPtr:
duke@0 675 return t->xmeet(this);
duke@0 676
coleenp@113 677 case NarrowOop:
coleenp@113 678 return t->xmeet(this);
coleenp@113 679
roland@3724 680 case NarrowKlass:
roland@3724 681 return t->xmeet(this);
roland@3724 682
duke@0 683 case Bad: // Type check
duke@0 684 default: // Bogus type not in lattice
duke@0 685 typerr(t);
duke@0 686 return Type::BOTTOM;
duke@0 687
duke@0 688 case Bottom: // Ye Olde Default
duke@0 689 return t;
duke@0 690
duke@0 691 case FloatTop:
duke@0 692 if( _base == FloatTop ) return this;
duke@0 693 case FloatBot: // Float
duke@0 694 if( _base == FloatBot || _base == FloatTop ) return FLOAT;
duke@0 695 if( _base == DoubleTop || _base == DoubleBot ) return Type::BOTTOM;
duke@0 696 typerr(t);
duke@0 697 return Type::BOTTOM;
duke@0 698
duke@0 699 case DoubleTop:
duke@0 700 if( _base == DoubleTop ) return this;
duke@0 701 case DoubleBot: // Double
duke@0 702 if( _base == DoubleBot || _base == DoubleTop ) return DOUBLE;
duke@0 703 if( _base == FloatTop || _base == FloatBot ) return Type::BOTTOM;
duke@0 704 typerr(t);
duke@0 705 return Type::BOTTOM;
duke@0 706
duke@0 707 // These next few cases must match exactly or it is a compile-time error.
duke@0 708 case Control: // Control of code
duke@0 709 case Abio: // State of world outside of program
duke@0 710 case Memory:
duke@0 711 if( _base == t->_base ) return this;
duke@0 712 typerr(t);
duke@0 713 return Type::BOTTOM;
duke@0 714
duke@0 715 case Top: // Top of the lattice
duke@0 716 return this;
duke@0 717 }
duke@0 718
duke@0 719 // The type is unchanged
duke@0 720 return this;
duke@0 721 }
duke@0 722
duke@0 723 //-----------------------------filter------------------------------------------
duke@0 724 const Type *Type::filter( const Type *kills ) const {
duke@0 725 const Type* ft = join(kills);
duke@0 726 if (ft->empty())
duke@0 727 return Type::TOP; // Canonical empty value
duke@0 728 return ft;
duke@0 729 }
duke@0 730
duke@0 731 //------------------------------xdual------------------------------------------
duke@0 732 // Compute dual right now.
duke@0 733 const Type::TYPES Type::dual_type[Type::lastype] = {
duke@0 734 Bad, // Bad
duke@0 735 Control, // Control
duke@0 736 Bottom, // Top
duke@0 737 Bad, // Int - handled in v-call
duke@0 738 Bad, // Long - handled in v-call
duke@0 739 Half, // Half
coleenp@113 740 Bad, // NarrowOop - handled in v-call
roland@3724 741 Bad, // NarrowKlass - handled in v-call
duke@0 742
duke@0 743 Bad, // Tuple - handled in v-call
duke@0 744 Bad, // Array - handled in v-call
kvn@3447 745 Bad, // VectorS - handled in v-call
kvn@3447 746 Bad, // VectorD - handled in v-call
kvn@3447 747 Bad, // VectorX - handled in v-call
kvn@3447 748 Bad, // VectorY - handled in v-call
duke@0 749
duke@0 750 Bad, // AnyPtr - handled in v-call
duke@0 751 Bad, // RawPtr - handled in v-call
duke@0 752 Bad, // OopPtr - handled in v-call
duke@0 753 Bad, // InstPtr - handled in v-call
duke@0 754 Bad, // AryPtr - handled in v-call
coleenp@3602 755
coleenp@3602 756 Bad, // MetadataPtr - handled in v-call
duke@0 757 Bad, // KlassPtr - handled in v-call
duke@0 758
duke@0 759 Bad, // Function - handled in v-call
duke@0 760 Abio, // Abio
duke@0 761 Return_Address,// Return_Address
duke@0 762 Memory, // Memory
duke@0 763 FloatBot, // FloatTop
duke@0 764 FloatCon, // FloatCon
duke@0 765 FloatTop, // FloatBot
duke@0 766 DoubleBot, // DoubleTop
duke@0 767 DoubleCon, // DoubleCon
duke@0 768 DoubleTop, // DoubleBot
duke@0 769 Top // Bottom
duke@0 770 };
duke@0 771
duke@0 772 const Type *Type::xdual() const {
duke@0 773 // Note: the base() accessor asserts the sanity of _base.
coleenp@3602 774 assert(_type_info[base()].dual_type != Bad, "implement with v-call");
coleenp@3602 775 return new Type(_type_info[_base].dual_type);
duke@0 776 }
duke@0 777
duke@0 778 //------------------------------has_memory-------------------------------------
duke@0 779 bool Type::has_memory() const {
duke@0 780 Type::TYPES tx = base();
duke@0 781 if (tx == Memory) return true;
duke@0 782 if (tx == Tuple) {
duke@0 783 const TypeTuple *t = is_tuple();
duke@0 784 for (uint i=0; i < t->cnt(); i++) {
duke@0 785 tx = t->field_at(i)->base();
duke@0 786 if (tx == Memory) return true;
duke@0 787 }
duke@0 788 }
duke@0 789 return false;
duke@0 790 }
duke@0 791
duke@0 792 #ifndef PRODUCT
duke@0 793 //------------------------------dump2------------------------------------------
duke@0 794 void Type::dump2( Dict &d, uint depth, outputStream *st ) const {
coleenp@3602 795 st->print(_type_info[_base].msg);
duke@0 796 }
duke@0 797
duke@0 798 //------------------------------dump-------------------------------------------
duke@0 799 void Type::dump_on(outputStream *st) const {
duke@0 800 ResourceMark rm;
duke@0 801 Dict d(cmpkey,hashkey); // Stop recursive type dumping
duke@0 802 dump2(d,1, st);
kvn@163 803 if (is_ptr_to_narrowoop()) {
coleenp@113 804 st->print(" [narrow]");
roland@3724 805 } else if (is_ptr_to_narrowklass()) {
roland@3724 806 st->print(" [narrowklass]");
coleenp@113 807 }
duke@0 808 }
duke@0 809 #endif
duke@0 810
duke@0 811 //------------------------------singleton--------------------------------------
duke@0 812 // TRUE if Type is a singleton type, FALSE otherwise. Singletons are simple
duke@0 813 // constants (Ldi nodes). Singletons are integer, float or double constants.
duke@0 814 bool Type::singleton(void) const {
duke@0 815 return _base == Top || _base == Half;
duke@0 816 }
duke@0 817
duke@0 818 //------------------------------empty------------------------------------------
duke@0 819 // TRUE if Type is a type with no values, FALSE otherwise.
duke@0 820 bool Type::empty(void) const {
duke@0 821 switch (_base) {
duke@0 822 case DoubleTop:
duke@0 823 case FloatTop:
duke@0 824 case Top:
duke@0 825 return true;
duke@0 826
duke@0 827 case Half:
duke@0 828 case Abio:
duke@0 829 case Return_Address:
duke@0 830 case Memory:
duke@0 831 case Bottom:
duke@0 832 case FloatBot:
duke@0 833 case DoubleBot:
duke@0 834 return false; // never a singleton, therefore never empty
duke@0 835 }
duke@0 836
duke@0 837 ShouldNotReachHere();
duke@0 838 return false;
duke@0 839 }
duke@0 840
duke@0 841 //------------------------------dump_stats-------------------------------------
duke@0 842 // Dump collected statistics to stderr
duke@0 843 #ifndef PRODUCT
duke@0 844 void Type::dump_stats() {
duke@0 845 tty->print("Types made: %d\n", type_dict()->Size());
duke@0 846 }
duke@0 847 #endif
duke@0 848
duke@0 849 //------------------------------typerr-----------------------------------------
duke@0 850 void Type::typerr( const Type *t ) const {
duke@0 851 #ifndef PRODUCT
duke@0 852 tty->print("\nError mixing types: ");
duke@0 853 dump();
duke@0 854 tty->print(" and ");
duke@0 855 t->dump();
duke@0 856 tty->print("\n");
duke@0 857 #endif
duke@0 858 ShouldNotReachHere();
duke@0 859 }
duke@0 860
duke@0 861
duke@0 862 //=============================================================================
duke@0 863 // Convenience common pre-built types.
duke@0 864 const TypeF *TypeF::ZERO; // Floating point zero
duke@0 865 const TypeF *TypeF::ONE; // Floating point one
duke@0 866
duke@0 867 //------------------------------make-------------------------------------------
duke@0 868 // Create a float constant
duke@0 869 const TypeF *TypeF::make(float f) {
duke@0 870 return (TypeF*)(new TypeF(f))->hashcons();
duke@0 871 }
duke@0 872
duke@0 873 //------------------------------meet-------------------------------------------
duke@0 874 // Compute the MEET of two types. It returns a new Type object.
duke@0 875 const Type *TypeF::xmeet( const Type *t ) const {
duke@0 876 // Perform a fast test for common case; meeting the same types together.
duke@0 877 if( this == t ) return this; // Meeting same type-rep?
duke@0 878
duke@0 879 // Current "this->_base" is FloatCon
duke@0 880 switch (t->base()) { // Switch on original type
duke@0 881 case AnyPtr: // Mixing with oops happens when javac
duke@0 882 case RawPtr: // reuses local variables
duke@0 883 case OopPtr:
duke@0 884 case InstPtr:
coleenp@3602 885 case AryPtr:
coleenp@3602 886 case MetadataPtr:
duke@0 887 case KlassPtr:
kvn@293 888 case NarrowOop:
roland@3724 889 case NarrowKlass:
duke@0 890 case Int:
duke@0 891 case Long:
duke@0 892 case DoubleTop:
duke@0 893 case DoubleCon:
duke@0 894 case DoubleBot:
duke@0 895 case Bottom: // Ye Olde Default
duke@0 896 return Type::BOTTOM;
duke@0 897
duke@0 898 case FloatBot:
duke@0 899 return t;
duke@0 900
duke@0 901 default: // All else is a mistake
duke@0 902 typerr(t);
duke@0 903
duke@0 904 case FloatCon: // Float-constant vs Float-constant?
duke@0 905 if( jint_cast(_f) != jint_cast(t->getf()) ) // unequal constants?
duke@0 906 // must compare bitwise as positive zero, negative zero and NaN have
duke@0 907 // all the same representation in C++
duke@0 908 return FLOAT; // Return generic float
duke@0 909 // Equal constants
duke@0 910 case Top:
duke@0 911 case FloatTop:
duke@0 912 break; // Return the float constant
duke@0 913 }
duke@0 914 return this; // Return the float constant
duke@0 915 }
duke@0 916
duke@0 917 //------------------------------xdual------------------------------------------
duke@0 918 // Dual: symmetric
duke@0 919 const Type *TypeF::xdual() const {
duke@0 920 return this;
duke@0 921 }
duke@0 922
duke@0 923 //------------------------------eq---------------------------------------------
duke@0 924 // Structural equality check for Type representations
duke@0 925 bool TypeF::eq( const Type *t ) const {
duke@0 926 if( g_isnan(_f) ||
duke@0 927 g_isnan(t->getf()) ) {
duke@0 928 // One or both are NANs. If both are NANs return true, else false.
duke@0 929 return (g_isnan(_f) && g_isnan(t->getf()));
duke@0 930 }
duke@0 931 if (_f == t->getf()) {
duke@0 932 // (NaN is impossible at this point, since it is not equal even to itself)
duke@0 933 if (_f == 0.0) {
duke@0 934 // difference between positive and negative zero
duke@0 935 if (jint_cast(_f) != jint_cast(t->getf())) return false;
duke@0 936 }
duke@0 937 return true;
duke@0 938 }
duke@0 939 return false;
duke@0 940 }
duke@0 941
duke@0 942 //------------------------------hash-------------------------------------------
duke@0 943 // Type-specific hashing function.
duke@0 944 int TypeF::hash(void) const {
duke@0 945 return *(int*)(&_f);
duke@0 946 }
duke@0 947
duke@0 948 //------------------------------is_finite--------------------------------------
duke@0 949 // Has a finite value
duke@0 950 bool TypeF::is_finite() const {
duke@0 951 return g_isfinite(getf()) != 0;
duke@0 952 }
duke@0 953
duke@0 954 //------------------------------is_nan-----------------------------------------
duke@0 955 // Is not a number (NaN)
duke@0 956 bool TypeF::is_nan() const {
duke@0 957 return g_isnan(getf()) != 0;
duke@0 958 }
duke@0 959
duke@0 960 //------------------------------dump2------------------------------------------
duke@0 961 // Dump float constant Type
duke@0 962 #ifndef PRODUCT
duke@0 963 void TypeF::dump2( Dict &d, uint depth, outputStream *st ) const {
duke@0 964 Type::dump2(d,depth, st);
duke@0 965 st->print("%f", _f);
duke@0 966 }
duke@0 967 #endif
duke@0 968
duke@0 969 //------------------------------singleton--------------------------------------
duke@0 970 // TRUE if Type is a singleton type, FALSE otherwise. Singletons are simple
duke@0 971 // constants (Ldi nodes). Singletons are integer, float or double constants
duke@0 972 // or a single symbol.
duke@0 973 bool TypeF::singleton(void) const {
duke@0 974 return true; // Always a singleton
duke@0 975 }
duke@0 976
duke@0 977 bool TypeF::empty(void) const {
duke@0 978 return false; // always exactly a singleton
duke@0 979 }
duke@0 980
duke@0 981 //=============================================================================
duke@0 982 // Convenience common pre-built types.
duke@0 983 const TypeD *TypeD::ZERO; // Floating point zero
duke@0 984 const TypeD *TypeD::ONE; // Floating point one
duke@0 985
duke@0 986 //------------------------------make-------------------------------------------
duke@0 987 const TypeD *TypeD::make(double d) {
duke@0 988 return (TypeD*)(new TypeD(d))->hashcons();
duke@0 989 }
duke@0 990
duke@0 991 //------------------------------meet-------------------------------------------
duke@0 992 // Compute the MEET of two types. It returns a new Type object.
duke@0 993 const Type *TypeD::xmeet( const Type *t ) const {
duke@0 994 // Perform a fast test for common case; meeting the same types together.
duke@0 995 if( this == t ) return this; // Meeting same type-rep?
duke@0 996
duke@0 997 // Current "this->_base" is DoubleCon
duke@0 998 switch (t->base()) { // Switch on original type
duke@0 999 case AnyPtr: // Mixing with oops happens when javac
duke@0 1000 case RawPtr: // reuses local variables
duke@0 1001 case OopPtr:
duke@0 1002 case InstPtr:
coleenp@3602 1003 case AryPtr:
coleenp@3602 1004 case MetadataPtr:
duke@0 1005 case KlassPtr:
never@183 1006 case NarrowOop:
roland@3724 1007 case NarrowKlass:
duke@0 1008 case Int:
duke@0 1009 case Long:
duke@0 1010 case FloatTop:
duke@0 1011 case FloatCon:
duke@0 1012 case FloatBot:
duke@0 1013 case Bottom: // Ye Olde Default
duke@0 1014 return Type::BOTTOM;
duke@0 1015
duke@0 1016 case DoubleBot:
duke@0 1017 return t;
duke@0 1018
duke@0 1019 default: // All else is a mistake
duke@0 1020 typerr(t);
duke@0 1021
duke@0 1022 case DoubleCon: // Double-constant vs Double-constant?
duke@0 1023 if( jlong_cast(_d) != jlong_cast(t->getd()) ) // unequal constants? (see comment in TypeF::xmeet)
duke@0 1024 return DOUBLE; // Return generic double
duke@0 1025 case Top:
duke@0 1026 case DoubleTop:
duke@0 1027 break;
duke@0 1028 }
duke@0 1029 return this; // Return the double constant
duke@0 1030 }
duke@0 1031
duke@0 1032 //------------------------------xdual------------------------------------------
duke@0 1033 // Dual: symmetric
duke@0 1034 const Type *TypeD::xdual() const {
duke@0 1035 return this;
duke@0 1036 }
duke@0 1037
duke@0 1038 //------------------------------eq---------------------------------------------
duke@0 1039 // Structural equality check for Type representations
duke@0 1040 bool TypeD::eq( const Type *t ) const {
duke@0 1041 if( g_isnan(_d) ||
duke@0 1042 g_isnan(t->getd()) ) {
duke@0 1043 // One or both are NANs. If both are NANs return true, else false.
duke@0 1044 return (g_isnan(_d) && g_isnan(t->getd()));
duke@0 1045 }
duke@0 1046 if (_d == t->getd()) {
duke@0 1047 // (NaN is impossible at this point, since it is not equal even to itself)
duke@0 1048 if (_d == 0.0) {
duke@0 1049 // difference between positive and negative zero
duke@0 1050 if (jlong_cast(_d) != jlong_cast(t->getd())) return false;
duke@0 1051 }
duke@0 1052 return true;
duke@0 1053 }
duke@0 1054 return false;
duke@0 1055 }
duke@0 1056
duke@0 1057 //------------------------------hash-------------------------------------------
duke@0 1058 // Type-specific hashing function.
duke@0 1059 int TypeD::hash(void) const {
duke@0 1060 return *(int*)(&_d);
duke@0 1061 }
duke@0 1062
duke@0 1063 //------------------------------is_finite--------------------------------------
duke@0 1064 // Has a finite value
duke@0 1065 bool TypeD::is_finite() const {
duke@0 1066 return g_isfinite(getd()) != 0;
duke@0 1067 }
duke@0 1068
duke@0 1069 //------------------------------is_nan-----------------------------------------
duke@0 1070 // Is not a number (NaN)
duke@0 1071 bool TypeD::is_nan() const {
duke@0 1072 return g_isnan(getd()) != 0;
duke@0 1073 }
duke@0 1074
duke@0 1075 //------------------------------dump2------------------------------------------
duke@0 1076 // Dump double constant Type
duke@0 1077 #ifndef PRODUCT
duke@0 1078 void TypeD::dump2( Dict &d, uint depth, outputStream *st ) const {
duke@0 1079 Type::dump2(d,depth,st);
duke@0 1080 st->print("%f", _d);
duke@0 1081 }
duke@0 1082 #endif
duke@0 1083
duke@0 1084 //------------------------------singleton--------------------------------------
duke@0 1085 // TRUE if Type is a singleton type, FALSE otherwise. Singletons are simple
duke@0 1086 // constants (Ldi nodes). Singletons are integer, float or double constants
duke@0 1087 // or a single symbol.
duke@0 1088 bool TypeD::singleton(void) const {
duke@0 1089 return true; // Always a singleton
duke@0 1090 }
duke@0 1091
duke@0 1092 bool TypeD::empty(void) const {
duke@0 1093 return false; // always exactly a singleton
duke@0 1094 }
duke@0 1095
duke@0 1096 //=============================================================================
duke@0 1097 // Convience common pre-built types.
duke@0 1098 const TypeInt *TypeInt::MINUS_1;// -1
duke@0 1099 const TypeInt *TypeInt::ZERO; // 0
duke@0 1100 const TypeInt *TypeInt::ONE; // 1
duke@0 1101 const TypeInt *TypeInt::BOOL; // 0 or 1, FALSE or TRUE.
duke@0 1102 const TypeInt *TypeInt::CC; // -1,0 or 1, condition codes
duke@0 1103 const TypeInt *TypeInt::CC_LT; // [-1] == MINUS_1
duke@0 1104 const TypeInt *TypeInt::CC_GT; // [1] == ONE
duke@0 1105 const TypeInt *TypeInt::CC_EQ; // [0] == ZERO
duke@0 1106 const TypeInt *TypeInt::CC_LE; // [-1,0]
duke@0 1107 const TypeInt *TypeInt::CC_GE; // [0,1] == BOOL (!)
duke@0 1108 const TypeInt *TypeInt::BYTE; // Bytes, -128 to 127
twisti@624 1109 const TypeInt *TypeInt::UBYTE; // Unsigned Bytes, 0 to 255
duke@0 1110 const TypeInt *TypeInt::CHAR; // Java chars, 0-65535
duke@0 1111 const TypeInt *TypeInt::SHORT; // Java shorts, -32768-32767
duke@0 1112 const TypeInt *TypeInt::POS; // Positive 32-bit integers or zero
duke@0 1113 const TypeInt *TypeInt::POS1; // Positive 32-bit integers
duke@0 1114 const TypeInt *TypeInt::INT; // 32-bit integers
duke@0 1115 const TypeInt *TypeInt::SYMINT; // symmetric range [-max_jint..max_jint]
duke@0 1116
duke@0 1117 //------------------------------TypeInt----------------------------------------
duke@0 1118 TypeInt::TypeInt( jint lo, jint hi, int w ) : Type(Int), _lo(lo), _hi(hi), _widen(w) {
duke@0 1119 }
duke@0 1120
duke@0 1121 //------------------------------make-------------------------------------------
duke@0 1122 const TypeInt *TypeInt::make( jint lo ) {
duke@0 1123 return (TypeInt*)(new TypeInt(lo,lo,WidenMin))->hashcons();
duke@0 1124 }
duke@0 1125
kvn@1540 1126 static int normalize_int_widen( jint lo, jint hi, int w ) {
duke@0 1127 // Certain normalizations keep us sane when comparing types.
duke@0 1128 // The 'SMALLINT' covers constants and also CC and its relatives.
duke@0 1129 if (lo <= hi) {
kvn@1540 1130 if ((juint)(hi - lo) <= SMALLINT) w = Type::WidenMin;
kvn@1540 1131 if ((juint)(hi - lo) >= max_juint) w = Type::WidenMax; // TypeInt::INT
kvn@1540 1132 } else {
kvn@1540 1133 if ((juint)(lo - hi) <= SMALLINT) w = Type::WidenMin;
kvn@1540 1134 if ((juint)(lo - hi) >= max_juint) w = Type::WidenMin; // dual TypeInt::INT
duke@0 1135 }
kvn@1540 1136 return w;
kvn@1540 1137 }
kvn@1540 1138
kvn@1540 1139 const TypeInt *TypeInt::make( jint lo, jint hi, int w ) {
kvn@1540 1140 w = normalize_int_widen(lo, hi, w);
duke@0 1141 return (TypeInt*)(new TypeInt(lo,hi,w))->hashcons();
duke@0 1142 }
duke@0 1143
duke@0 1144 //------------------------------meet-------------------------------------------
duke@0 1145 // Compute the MEET of two types. It returns a new Type representation object
duke@0 1146 // with reference count equal to the number of Types pointing at it.
duke@0 1147 // Caller should wrap a Types around it.
duke@0 1148 const Type *TypeInt::xmeet( const Type *t ) const {
duke@0 1149 // Perform a fast test for common case; meeting the same types together.
duke@0 1150 if( this == t ) return this; // Meeting same type?
duke@0 1151
duke@0 1152 // Currently "this->_base" is a TypeInt
duke@0 1153 switch (t->base()) { // Switch on original type
duke@0 1154 case AnyPtr: // Mixing with oops happens when javac
duke@0 1155 case RawPtr: // reuses local variables
duke@0 1156 case OopPtr:
duke@0 1157 case InstPtr:
coleenp@3602 1158 case AryPtr:
coleenp@3602 1159 case MetadataPtr:
duke@0 1160 case KlassPtr:
never@183 1161 case NarrowOop:
roland@3724 1162 case NarrowKlass:
duke@0 1163 case Long:
duke@0 1164 case FloatTop:
duke@0 1165 case FloatCon:
duke@0 1166 case FloatBot:
duke@0 1167 case DoubleTop:
duke@0 1168 case DoubleCon:
duke@0 1169 case DoubleBot:
duke@0 1170 case Bottom: // Ye Olde Default
duke@0 1171 return Type::BOTTOM;
duke@0 1172 default: // All else is a mistake
duke@0 1173 typerr(t);
duke@0 1174 case Top: // No change
duke@0 1175 return this;
duke@0 1176 case Int: // Int vs Int?
duke@0 1177 break;
duke@0 1178 }
duke@0 1179
duke@0 1180 // Expand covered set
duke@0 1181 const TypeInt *r = t->is_int();
kvn@1540 1182 return make( MIN2(_lo,r->_lo), MAX2(_hi,r->_hi), MAX2(_widen,r->_widen) );
duke@0 1183 }
duke@0 1184
duke@0 1185 //------------------------------xdual------------------------------------------
duke@0 1186 // Dual: reverse hi & lo; flip widen
duke@0 1187 const Type *TypeInt::xdual() const {
kvn@1540 1188 int w = normalize_int_widen(_hi,_lo, WidenMax-_widen);
kvn@1540 1189 return new TypeInt(_hi,_lo,w);
duke@0 1190 }
duke@0 1191
duke@0 1192 //------------------------------widen------------------------------------------
duke@0 1193 // Only happens for optimistic top-down optimizations.
never@1009 1194 const Type *TypeInt::widen( const Type *old, const Type* limit ) const {
duke@0 1195 // Coming from TOP or such; no widening
duke@0 1196 if( old->base() != Int ) return this;
duke@0 1197 const TypeInt *ot = old->is_int();
duke@0 1198
duke@0 1199 // If new guy is equal to old guy, no widening
duke@0 1200 if( _lo == ot->_lo && _hi == ot->_hi )
duke@0 1201 return old;
duke@0 1202
duke@0 1203 // If new guy contains old, then we widened
duke@0 1204 if( _lo <= ot->_lo && _hi >= ot->_hi ) {
duke@0 1205 // New contains old
duke@0 1206 // If new guy is already wider than old, no widening
duke@0 1207 if( _widen > ot->_widen ) return this;
duke@0 1208 // If old guy was a constant, do not bother
duke@0 1209 if (ot->_lo == ot->_hi) return this;
duke@0 1210 // Now widen new guy.
duke@0 1211 // Check for widening too far
duke@0 1212 if (_widen == WidenMax) {
never@1009 1213 int max = max_jint;
never@1009 1214 int min = min_jint;
never@1009 1215 if (limit->isa_int()) {
never@1009 1216 max = limit->is_int()->_hi;
never@1009 1217 min = limit->is_int()->_lo;
never@1009 1218 }
never@1009 1219 if (min < _lo && _hi < max) {
duke@0 1220 // If neither endpoint is extremal yet, push out the endpoint
duke@0 1221 // which is closer to its respective limit.
duke@0 1222 if (_lo >= 0 || // easy common case
never@1009 1223 (juint)(_lo - min) >= (juint)(max - _hi)) {
duke@0 1224 // Try to widen to an unsigned range type of 31 bits:
never@1009 1225 return make(_lo, max, WidenMax);
duke@0 1226 } else {
never@1009 1227 return make(min, _hi, WidenMax);
duke@0 1228 }
duke@0 1229 }
duke@0 1230 return TypeInt::INT;
duke@0 1231 }
duke@0 1232 // Returned widened new guy
duke@0 1233 return make(_lo,_hi,_widen+1);
duke@0 1234 }
duke@0 1235
duke@0 1236 // If old guy contains new, then we probably widened too far & dropped to
duke@0 1237 // bottom. Return the wider fellow.
duke@0 1238 if ( ot->_lo <= _lo && ot->_hi >= _hi )
duke@0 1239 return old;
duke@0 1240
duke@0 1241 //fatal("Integer value range is not subset");
duke@0 1242 //return this;
duke@0 1243 return TypeInt::INT;
duke@0 1244 }
duke@0 1245
duke@0 1246 //------------------------------narrow---------------------------------------
duke@0 1247 // Only happens for pessimistic optimizations.
duke@0 1248 const Type *TypeInt::narrow( const Type *old ) const {
duke@0 1249 if (_lo >= _hi) return this; // already narrow enough
duke@0 1250 if (old == NULL) return this;
duke@0 1251 const TypeInt* ot = old->isa_int();
duke@0 1252 if (ot == NULL) return this;
duke@0 1253 jint olo = ot->_lo;
duke@0 1254 jint ohi = ot->_hi;
duke@0 1255
duke@0 1256 // If new guy is equal to old guy, no narrowing
duke@0 1257 if (_lo == olo && _hi == ohi) return old;
duke@0 1258
duke@0 1259 // If old guy was maximum range, allow the narrowing
duke@0 1260 if (olo == min_jint && ohi == max_jint) return this;
duke@0 1261
duke@0 1262 if (_lo < olo || _hi > ohi)
duke@0 1263 return this; // doesn't narrow; pretty wierd
duke@0 1264
duke@0 1265 // The new type narrows the old type, so look for a "death march".
duke@0 1266 // See comments on PhaseTransform::saturate.
duke@0 1267 juint nrange = _hi - _lo;
duke@0 1268 juint orange = ohi - olo;
duke@0 1269 if (nrange < max_juint - 1 && nrange > (orange >> 1) + (SMALLINT*2)) {
duke@0 1270 // Use the new type only if the range shrinks a lot.
duke@0 1271 // We do not want the optimizer computing 2^31 point by point.
duke@0 1272 return old;
duke@0 1273 }
duke@0 1274
duke@0 1275 return this;
duke@0 1276 }
duke@0 1277
duke@0 1278 //-----------------------------filter------------------------------------------
duke@0 1279 const Type *TypeInt::filter( const Type *kills ) const {
duke@0 1280 const TypeInt* ft = join(kills)->isa_int();
kvn@1540 1281 if (ft == NULL || ft->empty())
duke@0 1282 return Type::TOP; // Canonical empty value
duke@0 1283 if (ft->_widen < this->_widen) {
duke@0 1284 // Do not allow the value of kill->_widen to affect the outcome.
duke@0 1285 // The widen bits must be allowed to run freely through the graph.
duke@0 1286 ft = TypeInt::make(ft->_lo, ft->_hi, this->_widen);
duke@0 1287 }
duke@0 1288 return ft;
duke@0 1289 }
duke@0 1290
duke@0 1291 //------------------------------eq---------------------------------------------
duke@0 1292 // Structural equality check for Type representations
duke@0 1293 bool TypeInt::eq( const Type *t ) const {
duke@0 1294 const TypeInt *r = t->is_int(); // Handy access
duke@0 1295 return r->_lo == _lo && r->_hi == _hi && r->_widen == _widen;
duke@0 1296 }
duke@0 1297
duke@0 1298 //------------------------------hash-------------------------------------------
duke@0 1299 // Type-specific hashing function.
duke@0 1300 int TypeInt::hash(void) const {
duke@0 1301 return _lo+_hi+_widen+(int)Type::Int;
duke@0 1302 }
duke@0 1303
duke@0 1304 //------------------------------is_finite--------------------------------------
duke@0 1305 // Has a finite value
duke@0 1306 bool TypeInt::is_finite() const {
duke@0 1307 return true;
duke@0 1308 }
duke@0 1309
duke@0 1310 //------------------------------dump2------------------------------------------
duke@0 1311 // Dump TypeInt
duke@0 1312 #ifndef PRODUCT
duke@0 1313 static const char* intname(char* buf, jint n) {
duke@0 1314 if (n == min_jint)
duke@0 1315 return "min";
duke@0 1316 else if (n < min_jint + 10000)
duke@0 1317 sprintf(buf, "min+" INT32_FORMAT, n - min_jint);
duke@0 1318 else if (n == max_jint)
duke@0 1319 return "max";
duke@0 1320 else if (n > max_jint - 10000)
duke@0 1321 sprintf(buf, "max-" INT32_FORMAT, max_jint - n);
duke@0 1322 else
duke@0 1323 sprintf(buf, INT32_FORMAT, n);
duke@0 1324 return buf;
duke@0 1325 }
duke@0 1326
duke@0 1327 void TypeInt::dump2( Dict &d, uint depth, outputStream *st ) const {
duke@0 1328 char buf[40], buf2[40];
duke@0 1329 if (_lo == min_jint && _hi == max_jint)
duke@0 1330 st->print("int");
duke@0 1331 else if (is_con())
duke@0 1332 st->print("int:%s", intname(buf, get_con()));
duke@0 1333 else if (_lo == BOOL->_lo && _hi == BOOL->_hi)
duke@0 1334 st->print("bool");
duke@0 1335 else if (_lo == BYTE->_lo && _hi == BYTE->_hi)
duke@0 1336 st->print("byte");
duke@0 1337 else if (_lo == CHAR->_lo && _hi == CHAR->_hi)
duke@0 1338 st->print("char");
duke@0 1339 else if (_lo == SHORT->_lo && _hi == SHORT->_hi)
duke@0 1340 st->print("short");
duke@0 1341 else if (_hi == max_jint)
duke@0 1342 st->print("int:>=%s", intname(buf, _lo));
duke@0 1343 else if (_lo == min_jint)
duke@0 1344 st->print("int:<=%s", intname(buf, _hi));
duke@0 1345 else
duke@0 1346 st->print("int:%s..%s", intname(buf, _lo), intname(buf2, _hi));
duke@0 1347
duke@0 1348 if (_widen != 0 && this != TypeInt::INT)
duke@0 1349 st->print(":%.*s", _widen, "wwww");
duke@0 1350 }
duke@0 1351 #endif
duke@0 1352
duke@0 1353 //------------------------------singleton--------------------------------------
duke@0 1354 // TRUE if Type is a singleton type, FALSE otherwise. Singletons are simple
duke@0 1355 // constants.
duke@0 1356 bool TypeInt::singleton(void) const {
duke@0 1357 return _lo >= _hi;
duke@0 1358 }
duke@0 1359
duke@0 1360 bool TypeInt::empty(void) const {
duke@0 1361 return _lo > _hi;
duke@0 1362 }
duke@0 1363
duke@0 1364 //=============================================================================
duke@0 1365 // Convenience common pre-built types.
duke@0 1366 const TypeLong *TypeLong::MINUS_1;// -1
duke@0 1367 const TypeLong *TypeLong::ZERO; // 0
duke@0 1368 const TypeLong *TypeLong::ONE; // 1
duke@0 1369 const TypeLong *TypeLong::POS; // >=0
duke@0 1370 const TypeLong *TypeLong::LONG; // 64-bit integers
duke@0 1371 const TypeLong *TypeLong::INT; // 32-bit subrange
duke@0 1372 const TypeLong *TypeLong::UINT; // 32-bit unsigned subrange
duke@0 1373
duke@0 1374 //------------------------------TypeLong---------------------------------------
duke@0 1375 TypeLong::TypeLong( jlong lo, jlong hi, int w ) : Type(Long), _lo(lo), _hi(hi), _widen(w) {
duke@0 1376 }
duke@0 1377
duke@0 1378 //------------------------------make-------------------------------------------
duke@0 1379 const TypeLong *TypeLong::make( jlong lo ) {
duke@0 1380 return (TypeLong*)(new TypeLong(lo,lo,WidenMin))->hashcons();
duke@0 1381 }
duke@0 1382
kvn@1540 1383 static int normalize_long_widen( jlong lo, jlong hi, int w ) {
kvn@1540 1384 // Certain normalizations keep us sane when comparing types.
kvn@1540 1385 // The 'SMALLINT' covers constants.
kvn@1540 1386 if (lo <= hi) {
kvn@1540 1387 if ((julong)(hi - lo) <= SMALLINT) w = Type::WidenMin;
kvn@1540 1388 if ((julong)(hi - lo) >= max_julong) w = Type::WidenMax; // TypeLong::LONG
kvn@1540 1389 } else {
kvn@1540 1390 if ((julong)(lo - hi) <= SMALLINT) w = Type::WidenMin;
kvn@1540 1391 if ((julong)(lo - hi) >= max_julong) w = Type::WidenMin; // dual TypeLong::LONG
kvn@1540 1392 }
kvn@1540 1393 return w;
kvn@1540 1394 }
kvn@1540 1395
duke@0 1396 const TypeLong *TypeLong::make( jlong lo, jlong hi, int w ) {
kvn@1540 1397 w = normalize_long_widen(lo, hi, w);
duke@0 1398 return (TypeLong*)(new TypeLong(lo,hi,w))->hashcons();
duke@0 1399 }
duke@0 1400
duke@0 1401
duke@0 1402 //------------------------------meet-------------------------------------------
duke@0 1403 // Compute the MEET of two types. It returns a new Type representation object
duke@0 1404 // with reference count equal to the number of Types pointing at it.
duke@0 1405 // Caller should wrap a Types around it.
duke@0 1406 const Type *TypeLong::xmeet( const Type *t ) const {
duke@0 1407 // Perform a fast test for common case; meeting the same types together.
duke@0 1408 if( this == t ) return this; // Meeting same type?
duke@0 1409
duke@0 1410 // Currently "this->_base" is a TypeLong
duke@0 1411 switch (t->base()) { // Switch on original type
duke@0 1412 case AnyPtr: // Mixing with oops happens when javac
duke@0 1413 case RawPtr: // reuses local variables
duke@0 1414 case OopPtr:
duke@0 1415 case InstPtr:
coleenp@3602 1416 case AryPtr:
coleenp@3602 1417 case MetadataPtr:
duke@0 1418 case KlassPtr:
never@183 1419 case NarrowOop:
roland@3724 1420 case NarrowKlass:
duke@0 1421 case Int:
duke@0 1422 case FloatTop:
duke@0 1423 case FloatCon:
duke@0 1424 case FloatBot:
duke@0 1425 case DoubleTop:
duke@0 1426 case DoubleCon:
duke@0 1427 case DoubleBot:
duke@0 1428 case Bottom: // Ye Olde Default
duke@0 1429 return Type::BOTTOM;
duke@0 1430 default: // All else is a mistake
duke@0 1431 typerr(t);
duke@0 1432 case Top: // No change
duke@0 1433 return this;
duke@0 1434 case Long: // Long vs Long?
duke@0 1435 break;
duke@0 1436 }
duke@0 1437
duke@0 1438 // Expand covered set
duke@0 1439 const TypeLong *r = t->is_long(); // Turn into a TypeLong
kvn@1540 1440 return make( MIN2(_lo,r->_lo), MAX2(_hi,r->_hi), MAX2(_widen,r->_widen) );
duke@0 1441 }
duke@0 1442
duke@0 1443 //------------------------------xdual------------------------------------------
duke@0 1444 // Dual: reverse hi & lo; flip widen
duke@0 1445 const Type *TypeLong::xdual() const {
kvn@1540 1446 int w = normalize_long_widen(_hi,_lo, WidenMax-_widen);
kvn@1540 1447 return new TypeLong(_hi,_lo,w);
duke@0 1448 }
duke@0 1449
duke@0 1450 //------------------------------widen------------------------------------------
duke@0 1451 // Only happens for optimistic top-down optimizations.
never@1009 1452 const Type *TypeLong::widen( const Type *old, const Type* limit ) const {
duke@0 1453 // Coming from TOP or such; no widening
duke@0 1454 if( old->base() != Long ) return this;
duke@0 1455 const TypeLong *ot = old->is_long();
duke@0 1456
duke@0 1457 // If new guy is equal to old guy, no widening
duke@0 1458 if( _lo == ot->_lo && _hi == ot->_hi )
duke@0 1459 return old;
duke@0 1460
duke@0 1461 // If new guy contains old, then we widened
duke@0 1462 if( _lo <= ot->_lo && _hi >= ot->_hi ) {
duke@0 1463 // New contains old
duke@0 1464 // If new guy is already wider than old, no widening
duke@0 1465 if( _widen > ot->_widen ) return this;
duke@0 1466 // If old guy was a constant, do not bother
duke@0 1467 if (ot->_lo == ot->_hi) return this;
duke@0 1468 // Now widen new guy.
duke@0 1469 // Check for widening too far
duke@0 1470 if (_widen == WidenMax) {
never@1009 1471 jlong max = max_jlong;
never@1009 1472 jlong min = min_jlong;
never@1009 1473 if (limit->isa_long()) {
never@1009 1474 max = limit->is_long()->_hi;
never@1009 1475 min = limit->is_long()->_lo;
never@1009 1476 }
never@1009 1477 if (min < _lo && _hi < max) {
duke@0 1478 // If neither endpoint is extremal yet, push out the endpoint
duke@0 1479 // which is closer to its respective limit.
duke@0 1480 if (_lo >= 0 || // easy common case
never@1009 1481 (julong)(_lo - min) >= (julong)(max - _hi)) {
duke@0 1482 // Try to widen to an unsigned range type of 32/63 bits:
never@1009 1483 if (max >= max_juint && _hi < max_juint)
duke@0 1484 return make(_lo, max_juint, WidenMax);
duke@0 1485 else
never@1009 1486 return make(_lo, max, WidenMax);
duke@0 1487 } else {
never@1009 1488 return make(min, _hi, WidenMax);
duke@0 1489 }
duke@0 1490 }
duke@0 1491 return TypeLong::LONG;
duke@0 1492 }
duke@0 1493 // Returned widened new guy
duke@0 1494 return make(_lo,_hi,_widen+1);
duke@0 1495 }
duke@0 1496
duke@0 1497 // If old guy contains new, then we probably widened too far & dropped to
duke@0 1498 // bottom. Return the wider fellow.
duke@0 1499 if ( ot->_lo <= _lo && ot->_hi >= _hi )
duke@0 1500 return old;
duke@0 1501
duke@0 1502 // fatal("Long value range is not subset");
duke@0 1503 // return this;
duke@0 1504 return TypeLong::LONG;
duke@0 1505 }
duke@0 1506
duke@0 1507 //------------------------------narrow----------------------------------------
duke@0 1508 // Only happens for pessimistic optimizations.
duke@0 1509 const Type *TypeLong::narrow( const Type *old ) const {
duke@0 1510 if (_lo >= _hi) return this; // already narrow enough
duke@0 1511 if (old == NULL) return this;
duke@0 1512 const TypeLong* ot = old->isa_long();
duke@0 1513 if (ot == NULL) return this;
duke@0 1514 jlong olo = ot->_lo;
duke@0 1515 jlong ohi = ot->_hi;
duke@0 1516
duke@0 1517 // If new guy is equal to old guy, no narrowing
duke@0 1518 if (_lo == olo && _hi == ohi) return old;
duke@0 1519
duke@0 1520 // If old guy was maximum range, allow the narrowing
duke@0 1521 if (olo == min_jlong && ohi == max_jlong) return this;
duke@0 1522
duke@0 1523 if (_lo < olo || _hi > ohi)
duke@0 1524 return this; // doesn't narrow; pretty wierd
duke@0 1525
duke@0 1526 // The new type narrows the old type, so look for a "death march".
duke@0 1527 // See comments on PhaseTransform::saturate.
duke@0 1528 julong nrange = _hi - _lo;
duke@0 1529 julong orange = ohi - olo;
duke@0 1530 if (nrange < max_julong - 1 && nrange > (orange >> 1) + (SMALLINT*2)) {
duke@0 1531 // Use the new type only if the range shrinks a lot.
duke@0 1532 // We do not want the optimizer computing 2^31 point by point.
duke@0 1533 return old;
duke@0 1534 }
duke@0 1535
duke@0 1536 return this;
duke@0 1537 }
duke@0 1538
duke@0 1539 //-----------------------------filter------------------------------------------
duke@0 1540 const Type *TypeLong::filter( const Type *kills ) const {
duke@0 1541 const TypeLong* ft = join(kills)->isa_long();
kvn@1540 1542 if (ft == NULL || ft->empty())
duke@0 1543 return Type::TOP; // Canonical empty value
duke@0 1544 if (ft->_widen < this->_widen) {
duke@0 1545 // Do not allow the value of kill->_widen to affect the outcome.
duke@0 1546 // The widen bits must be allowed to run freely through the graph.
duke@0 1547 ft = TypeLong::make(ft->_lo, ft->_hi, this->_widen);
duke@0 1548 }
duke@0 1549 return ft;
duke@0 1550 }
duke@0 1551
duke@0 1552 //------------------------------eq---------------------------------------------
duke@0 1553 // Structural equality check for Type representations
duke@0 1554 bool TypeLong::eq( const Type *t ) const {
duke@0 1555 const TypeLong *r = t->is_long(); // Handy access
duke@0 1556 return r->_lo == _lo && r->_hi == _hi && r->_widen == _widen;
duke@0 1557 }
duke@0 1558
duke@0 1559 //------------------------------hash-------------------------------------------
duke@0 1560 // Type-specific hashing function.
duke@0 1561 int TypeLong::hash(void) const {
duke@0 1562 return (int)(_lo+_hi+_widen+(int)Type::Long);
duke@0 1563 }
duke@0 1564
duke@0 1565 //------------------------------is_finite--------------------------------------
duke@0 1566 // Has a finite value
duke@0 1567 bool TypeLong::is_finite() const {
duke@0 1568 return true;
duke@0 1569 }
duke@0 1570
duke@0 1571 //------------------------------dump2------------------------------------------
duke@0 1572 // Dump TypeLong
duke@0 1573 #ifndef PRODUCT
duke@0 1574 static const char* longnamenear(jlong x, const char* xname, char* buf, jlong n) {
duke@0 1575 if (n > x) {
duke@0 1576 if (n >= x + 10000) return NULL;
hseigel@4030 1577 sprintf(buf, "%s+" JLONG_FORMAT, xname, n - x);
duke@0 1578 } else if (n < x) {
duke@0 1579 if (n <= x - 10000) return NULL;
hseigel@4030 1580 sprintf(buf, "%s-" JLONG_FORMAT, xname, x - n);
duke@0 1581 } else {
duke@0 1582 return xname;
duke@0 1583 }
duke@0 1584 return buf;
duke@0 1585 }
duke@0 1586
duke@0 1587 static const char* longname(char* buf, jlong n) {
duke@0 1588 const char* str;
duke@0 1589 if (n == min_jlong)
duke@0 1590 return "min";
duke@0 1591 else if (n < min_jlong + 10000)
hseigel@4030 1592 sprintf(buf, "min+" JLONG_FORMAT, n - min_jlong);
duke@0 1593 else if (n == max_jlong)
duke@0 1594 return "max";
duke@0 1595 else if (n > max_jlong - 10000)
hseigel@4030 1596 sprintf(buf, "max-" JLONG_FORMAT, max_jlong - n);
duke@0 1597 else if ((str = longnamenear(max_juint, "maxuint", buf, n)) != NULL)
duke@0 1598 return str;
duke@0 1599 else if ((str = longnamenear(max_jint, "maxint", buf, n)) != NULL)
duke@0 1600 return str;
duke@0 1601 else if ((str = longnamenear(min_jint, "minint", buf, n)) != NULL)
duke@0 1602 return str;
duke@0 1603 else
hseigel@4030 1604 sprintf(buf, JLONG_FORMAT, n);
duke@0 1605 return buf;
duke@0 1606 }
duke@0 1607
duke@0 1608 void TypeLong::dump2( Dict &d, uint depth, outputStream *st ) const {
duke@0 1609 char buf[80], buf2[80];
duke@0 1610 if (_lo == min_jlong && _hi == max_jlong)
duke@0 1611 st->print("long");
duke@0 1612 else if (is_con())
duke@0 1613 st->print("long:%s", longname(buf, get_con()));
duke@0 1614 else if (_hi == max_jlong)
duke@0 1615 st->print("long:>=%s", longname(buf, _lo));
duke@0 1616 else if (_lo == min_jlong)
duke@0 1617 st->print("long:<=%s", longname(buf, _hi));
duke@0 1618 else
duke@0 1619 st->print("long:%s..%s", longname(buf, _lo), longname(buf2, _hi));
duke@0 1620
duke@0 1621 if (_widen != 0 && this != TypeLong::LONG)
duke@0 1622 st->print(":%.*s", _widen, "wwww");
duke@0 1623 }
duke@0 1624 #endif
duke@0 1625
duke@0 1626 //------------------------------singleton--------------------------------------
duke@0 1627 // TRUE if Type is a singleton type, FALSE otherwise. Singletons are simple
duke@0 1628 // constants
duke@0 1629 bool TypeLong::singleton(void) const {
duke@0 1630 return _lo >= _hi;
duke@0 1631 }
duke@0 1632
duke@0 1633 bool TypeLong::empty(void) const {
duke@0 1634 return _lo > _hi;
duke@0 1635 }
duke@0 1636
duke@0 1637 //=============================================================================
duke@0 1638 // Convenience common pre-built types.
duke@0 1639 const TypeTuple *TypeTuple::IFBOTH; // Return both arms of IF as reachable
duke@0 1640 const TypeTuple *TypeTuple::IFFALSE;
duke@0 1641 const TypeTuple *TypeTuple::IFTRUE;
duke@0 1642 const TypeTuple *TypeTuple::IFNEITHER;
duke@0 1643 const TypeTuple *TypeTuple::LOOPBODY;
duke@0 1644 const TypeTuple *TypeTuple::MEMBAR;
duke@0 1645 const TypeTuple *TypeTuple::STORECONDITIONAL;
duke@0 1646 const TypeTuple *TypeTuple::START_I2C;
duke@0 1647 const TypeTuple *TypeTuple::INT_PAIR;
duke@0 1648 const TypeTuple *TypeTuple::LONG_PAIR;
duke@0 1649
duke@0 1650
duke@0 1651 //------------------------------make-------------------------------------------
duke@0 1652 // Make a TypeTuple from the range of a method signature
duke@0 1653 const TypeTuple *TypeTuple::make_range(ciSignature* sig) {
duke@0 1654 ciType* return_type = sig->return_type();
duke@0 1655 uint total_fields = TypeFunc::Parms + return_type->size();
duke@0 1656 const Type **field_array = fields(total_fields);
duke@0 1657 switch (return_type->basic_type()) {
duke@0 1658 case T_LONG:
duke@0 1659 field_array[TypeFunc::Parms] = TypeLong::LONG;
duke@0 1660 field_array[TypeFunc::Parms+1] = Type::HALF;
duke@0 1661 break;
duke@0 1662 case T_DOUBLE:
duke@0 1663 field_array[TypeFunc::Parms] = Type::DOUBLE;
duke@0 1664 field_array[TypeFunc::Parms+1] = Type::HALF;
duke@0 1665 break;
duke@0 1666 case T_OBJECT:
duke@0 1667 case T_ARRAY:
duke@0 1668 case T_BOOLEAN:
duke@0 1669 case T_CHAR:
duke@0 1670 case T_FLOAT:
duke@0 1671 case T_BYTE:
duke@0 1672 case T_SHORT:
duke@0 1673 case T_INT:
duke@0 1674 field_array[TypeFunc::Parms] = get_const_type(return_type);
duke@0 1675 break;
duke@0 1676 case T_VOID:
duke@0 1677 break;
duke@0 1678 default:
duke@0 1679 ShouldNotReachHere();
duke@0 1680 }
duke@0 1681 return (TypeTuple*)(new TypeTuple(total_fields,field_array))->hashcons();
duke@0 1682 }
duke@0 1683
duke@0 1684 // Make a TypeTuple from the domain of a method signature
duke@0 1685 const TypeTuple *TypeTuple::make_domain(ciInstanceKlass* recv, ciSignature* sig) {
duke@0 1686 uint total_fields = TypeFunc::Parms + sig->size();
duke@0 1687
duke@0 1688 uint pos = TypeFunc::Parms;
duke@0 1689 const Type **field_array;
duke@0 1690 if (recv != NULL) {
duke@0 1691 total_fields++;
duke@0 1692 field_array = fields(total_fields);
duke@0 1693 // Use get_const_type here because it respects UseUniqueSubclasses:
duke@0 1694 field_array[pos++] = get_const_type(recv)->join(TypePtr::NOTNULL);
duke@0 1695 } else {
duke@0 1696 field_array = fields(total_fields);
duke@0 1697 }
duke@0 1698
duke@0 1699 int i = 0;
duke@0 1700 while (pos < total_fields) {
duke@0 1701 ciType* type = sig->type_at(i);
duke@0 1702
duke@0 1703 switch (type->basic_type()) {
duke@0 1704 case T_LONG:
duke@0 1705 field_array[pos++] = TypeLong::LONG;
duke@0 1706 field_array[pos++] = Type::HALF;
duke@0 1707 break;
duke@0 1708 case T_DOUBLE:
duke@0 1709 field_array[pos++] = Type::DOUBLE;
duke@0 1710 field_array[pos++] = Type::HALF;
duke@0 1711 break;
duke@0 1712 case T_OBJECT:
duke@0 1713 case T_ARRAY:
duke@0 1714 case T_BOOLEAN:
duke@0 1715 case T_CHAR:
duke@0 1716 case T_FLOAT:
duke@0 1717 case T_BYTE:
duke@0 1718 case T_SHORT:
duke@0 1719 case T_INT:
duke@0 1720 field_array[pos++] = get_const_type(type);
duke@0 1721 break;
duke@0 1722 default:
duke@0 1723 ShouldNotReachHere();
duke@0 1724 }
duke@0 1725 i++;
duke@0 1726 }
duke@0 1727 return (TypeTuple*)(new TypeTuple(total_fields,field_array))->hashcons();
duke@0 1728 }
duke@0 1729
duke@0 1730 const TypeTuple *TypeTuple::make( uint cnt, const Type **fields ) {
duke@0 1731 return (TypeTuple*)(new TypeTuple(cnt,fields))->hashcons();
duke@0 1732 }
duke@0 1733
duke@0 1734 //------------------------------fields-----------------------------------------
duke@0 1735 // Subroutine call type with space allocated for argument types
duke@0 1736 const Type **TypeTuple::fields( uint arg_cnt ) {
duke@0 1737 const Type **flds = (const Type **)(Compile::current()->type_arena()->Amalloc_4((TypeFunc::Parms+arg_cnt)*sizeof(Type*) ));
duke@0 1738 flds[TypeFunc::Control ] = Type::CONTROL;
duke@0 1739 flds[TypeFunc::I_O ] = Type::ABIO;
duke@0 1740 flds[TypeFunc::Memory ] = Type::MEMORY;
duke@0 1741 flds[TypeFunc::FramePtr ] = TypeRawPtr::BOTTOM;
duke@0 1742 flds[TypeFunc::ReturnAdr] = Type::RETURN_ADDRESS;
duke@0 1743
duke@0 1744 return flds;
duke@0 1745 }
duke@0 1746
duke@0 1747 //------------------------------meet-------------------------------------------
duke@0 1748 // Compute the MEET of two types. It returns a new Type object.
duke@0 1749 const Type *TypeTuple::xmeet( const Type *t ) const {
duke@0 1750 // Perform a fast test for common case; meeting the same types together.
duke@0 1751 if( this == t ) return this; // Meeting same type-rep?
duke@0 1752
duke@0 1753 // Current "this->_base" is Tuple
duke@0 1754 switch (t->base()) { // switch on original type
duke@0 1755
duke@0 1756 case Bottom: // Ye Olde Default
duke@0 1757 return t;
duke@0 1758
duke@0 1759 default: // All else is a mistake
duke@0 1760 typerr(t);
duke@0 1761
duke@0 1762 case Tuple: { // Meeting 2 signatures?
duke@0 1763 const TypeTuple *x = t->is_tuple();
duke@0 1764 assert( _cnt == x->_cnt, "" );
duke@0 1765 const Type **fields = (const Type **)(Compile::current()->type_arena()->Amalloc_4( _cnt*sizeof(Type*) ));
duke@0 1766 for( uint i=0; i<_cnt; i++ )
duke@0 1767 fields[i] = field_at(i)->xmeet( x->field_at(i) );
duke@0 1768 return TypeTuple::make(_cnt,fields);
duke@0 1769 }
duke@0 1770 case Top:
duke@0 1771 break;
duke@0 1772 }
duke@0 1773 return this; // Return the double constant
duke@0 1774 }
duke@0 1775
duke@0 1776 //------------------------------xdual------------------------------------------
duke@0 1777 // Dual: compute field-by-field dual
duke@0 1778 const Type *TypeTuple::xdual() const {
duke@0 1779 const Type **fields = (const Type **)(Compile::current()->type_arena()->Amalloc_4( _cnt*sizeof(Type*) ));
duke@0 1780 for( uint i=0; i<_cnt; i++ )
duke@0 1781 fields[i] = _fields[i]->dual();
duke@0 1782 return new TypeTuple(_cnt,fields);
duke@0 1783 }
duke@0 1784
duke@0 1785 //------------------------------eq---------------------------------------------
duke@0 1786 // Structural equality check for Type representations
duke@0 1787 bool TypeTuple::eq( const Type *t ) const {
duke@0 1788 const TypeTuple *s = (const TypeTuple *)t;
duke@0 1789 if (_cnt != s->_cnt) return false; // Unequal field counts
duke@0 1790 for (uint i = 0; i < _cnt; i++)
duke@0 1791 if (field_at(i) != s->field_at(i)) // POINTER COMPARE! NO RECURSION!
duke@0 1792 return false; // Missed
duke@0 1793 return true;
duke@0 1794 }
duke@0 1795
duke@0 1796 //------------------------------hash-------------------------------------------
duke@0 1797 // Type-specific hashing function.
duke@0 1798 int TypeTuple::hash(void) const {
duke@0 1799 intptr_t sum = _cnt;
duke@0 1800 for( uint i=0; i<_cnt; i++ )
duke@0 1801 sum += (intptr_t)_fields[i]; // Hash on pointers directly
duke@0 1802 return sum;
duke@0 1803 }
duke@0 1804
duke@0 1805 //------------------------------dump2------------------------------------------
duke@0 1806 // Dump signature Type
duke@0 1807 #ifndef PRODUCT
duke@0 1808 void TypeTuple::dump2( Dict &d, uint depth, outputStream *st ) const {
duke@0 1809 st->print("{");
duke@0 1810 if( !depth || d[this] ) { // Check for recursive print
duke@0 1811 st->print("...}");
duke@0 1812 return;
duke@0 1813 }
duke@0 1814 d.Insert((void*)this, (void*)this); // Stop recursion
duke@0 1815 if( _cnt ) {
duke@0 1816 uint i;
duke@0 1817 for( i=0; i<_cnt-1; i++ ) {
duke@0 1818 st->print("%d:", i);
duke@0 1819 _fields[i]->dump2(d, depth-1, st);
duke@0 1820 st->print(", ");
duke@0 1821 }
duke@0 1822 st->print("%d:", i);
duke@0 1823 _fields[i]->dump2(d, depth-1, st);
duke@0 1824 }
duke@0 1825 st->print("}");
duke@0 1826 }
duke@0 1827 #endif
duke@0 1828
duke@0 1829 //------------------------------singleton--------------------------------------
duke@0 1830 // TRUE if Type is a singleton type, FALSE otherwise. Singletons are simple
duke@0 1831 // constants (Ldi nodes). Singletons are integer, float or double constants
duke@0 1832 // or a single symbol.
duke@0 1833 bool TypeTuple::singleton(void) const {
duke@0 1834 return false; // Never a singleton
duke@0 1835 }
duke@0 1836
duke@0 1837 bool TypeTuple::empty(void) const {
duke@0 1838 for( uint i=0; i<_cnt; i++ ) {
duke@0 1839 if (_fields[i]->empty()) return true;
duke@0 1840 }
duke@0 1841 return false;
duke@0 1842 }
duke@0 1843
duke@0 1844 //=============================================================================
duke@0 1845 // Convenience common pre-built types.
duke@0 1846
duke@0 1847 inline const TypeInt* normalize_array_size(const TypeInt* size) {
duke@0 1848 // Certain normalizations keep us sane when comparing types.
duke@0 1849 // We do not want arrayOop variables to differ only by the wideness
duke@0 1850 // of their index types. Pick minimum wideness, since that is the
duke@0 1851 // forced wideness of small ranges anyway.
duke@0 1852 if (size->_widen != Type::WidenMin)
duke@0 1853 return TypeInt::make(size->_lo, size->_hi, Type::WidenMin);
duke@0 1854 else
duke@0 1855 return size;
duke@0 1856 }
duke@0 1857
duke@0 1858 //------------------------------make-------------------------------------------
vlivanov@5223 1859 const TypeAry* TypeAry::make(const Type* elem, const TypeInt* size, bool stable) {
coleenp@113 1860 if (UseCompressedOops && elem->isa_oopptr()) {
kvn@221 1861 elem = elem->make_narrowoop();
coleenp@113 1862 }
duke@0 1863 size = normalize_array_size(size);
vlivanov@5223 1864 return (TypeAry*)(new TypeAry(elem,size,stable))->hashcons();
duke@0 1865 }
duke@0 1866
duke@0 1867 //------------------------------meet-------------------------------------------
duke@0 1868 // Compute the MEET of two types. It returns a new Type object.
duke@0 1869 const Type *TypeAry::xmeet( const Type *t ) const {
duke@0 1870 // Perform a fast test for common case; meeting the same types together.
duke@0 1871 if( this == t ) return this; // Meeting same type-rep?
duke@0 1872
duke@0 1873 // Current "this->_base" is Ary
duke@0 1874 switch (t->base()) { // switch on original type
duke@0 1875
duke@0 1876 case Bottom: // Ye Olde Default
duke@0 1877 return t;
duke@0 1878
duke@0 1879 default: // All else is a mistake
duke@0 1880 typerr(t);
duke@0 1881
duke@0 1882 case Array: { // Meeting 2 arrays?
duke@0 1883 const TypeAry *a = t->is_ary();
duke@0 1884 return TypeAry::make(_elem->meet(a->_elem),
vlivanov@5223 1885 _size->xmeet(a->_size)->is_int(),
vlivanov@5223 1886 _stable & a->_stable);
duke@0 1887 }
duke@0 1888 case Top:
duke@0 1889 break;
duke@0 1890 }
duke@0 1891 return this; // Return the double constant
duke@0 1892 }
duke@0 1893
duke@0 1894 //------------------------------xdual------------------------------------------
duke@0 1895 // Dual: compute field-by-field dual
duke@0 1896 const Type *TypeAry::xdual() const {
duke@0 1897 const TypeInt* size_dual = _size->dual()->is_int();
duke@0 1898 size_dual = normalize_array_size(size_dual);
vlivanov@5223 1899 return new TypeAry(_elem->dual(), size_dual, !_stable);
duke@0 1900 }
duke@0 1901
duke@0 1902 //------------------------------eq---------------------------------------------
duke@0 1903 // Structural equality check for Type representations
duke@0 1904 bool TypeAry::eq( const Type *t ) const {
duke@0 1905 const TypeAry *a = (const TypeAry*)t;
duke@0 1906 return _elem == a->_elem &&
vlivanov@5223 1907 _stable == a->_stable &&
duke@0 1908 _size == a->_size;
duke@0 1909 }
duke@0 1910
duke@0 1911 //------------------------------hash-------------------------------------------
duke@0 1912 // Type-specific hashing function.
duke@0 1913 int TypeAry::hash(void) const {
vlivanov@5223 1914 return (intptr_t)_elem + (intptr_t)_size + (_stable ? 43 : 0);
duke@0 1915 }
duke@0 1916
kvn@820 1917 //----------------------interface_vs_oop---------------------------------------
kvn@820 1918 #ifdef ASSERT
kvn@820 1919 bool TypeAry::interface_vs_oop(const Type *t) const {
kvn@820 1920 const TypeAry* t_ary = t->is_ary();
kvn@820 1921 if (t_ary) {
kvn@820 1922 return _elem->interface_vs_oop(t_ary->_elem);
kvn@820 1923 }
kvn@820 1924 return false;
kvn@820 1925 }
kvn@820 1926 #endif
kvn@820 1927
duke@0 1928 //------------------------------dump2------------------------------------------
duke@0 1929 #ifndef PRODUCT
duke@0 1930 void TypeAry::dump2( Dict &d, uint depth, outputStream *st ) const {
vlivanov@5223 1931 if (_stable) st->print("stable:");
duke@0 1932 _elem->dump2(d, depth, st);
duke@0 1933 st->print("[");
duke@0 1934 _size->dump2(d, depth, st);
duke@0 1935 st->print("]");
duke@0 1936 }
duke@0 1937 #endif
duke@0 1938
duke@0 1939 //------------------------------singleton--------------------------------------
duke@0 1940 // TRUE if Type is a singleton type, FALSE otherwise. Singletons are simple
duke@0 1941 // constants (Ldi nodes). Singletons are integer, float or double constants
duke@0 1942 // or a single symbol.
duke@0 1943 bool TypeAry::singleton(void) const {
duke@0 1944 return false; // Never a singleton
duke@0 1945 }
duke@0 1946
duke@0 1947 bool TypeAry::empty(void) const {
duke@0 1948 return _elem->empty() || _size->empty();
duke@0 1949 }
duke@0 1950
duke@0 1951 //--------------------------ary_must_be_exact----------------------------------
duke@0 1952 bool TypeAry::ary_must_be_exact() const {
duke@0 1953 if (!UseExactTypes) return false;
duke@0 1954 // This logic looks at the element type of an array, and returns true
duke@0 1955 // if the element type is either a primitive or a final instance class.
duke@0 1956 // In such cases, an array built on this ary must have no subclasses.
duke@0 1957 if (_elem == BOTTOM) return false; // general array not exact
duke@0 1958 if (_elem == TOP ) return false; // inverted general array not exact
coleenp@113 1959 const TypeOopPtr* toop = NULL;
kvn@221 1960 if (UseCompressedOops && _elem->isa_narrowoop()) {
kvn@221 1961 toop = _elem->make_ptr()->isa_oopptr();
coleenp@113 1962 } else {
coleenp@113 1963 toop = _elem->isa_oopptr();
coleenp@113 1964 }
duke@0 1965 if (!toop) return true; // a primitive type, like int
duke@0 1966 ciKlass* tklass = toop->klass();
duke@0 1967 if (tklass == NULL) return false; // unloaded class
duke@0 1968 if (!tklass->is_loaded()) return false; // unloaded class
coleenp@113 1969 const TypeInstPtr* tinst;
coleenp@113 1970 if (_elem->isa_narrowoop())
kvn@221 1971 tinst = _elem->make_ptr()->isa_instptr();
coleenp@113 1972 else
coleenp@113 1973 tinst = _elem->isa_instptr();
kvn@221 1974 if (tinst)
kvn@221 1975 return tklass->as_instance_klass()->is_final();
coleenp@113 1976 const TypeAryPtr* tap;
coleenp@113 1977 if (_elem->isa_narrowoop())
kvn@221 1978 tap = _elem->make_ptr()->isa_aryptr();
coleenp@113 1979 else
coleenp@113 1980 tap = _elem->isa_aryptr();
kvn@221 1981 if (tap)
kvn@221 1982 return tap->ary()->ary_must_be_exact();
duke@0 1983 return false;
duke@0 1984 }
duke@0 1985
kvn@3447 1986 //==============================TypeVect=======================================
kvn@3447 1987 // Convenience common pre-built types.
kvn@3447 1988 const TypeVect *TypeVect::VECTS = NULL; // 32-bit vectors
kvn@3447 1989 const TypeVect *TypeVect::VECTD = NULL; // 64-bit vectors
kvn@3447 1990 const TypeVect *TypeVect::VECTX = NULL; // 128-bit vectors
kvn@3447 1991 const TypeVect *TypeVect::VECTY = NULL; // 256-bit vectors
kvn@3447 1992
kvn@3447 1993 //------------------------------make-------------------------------------------
kvn@3447 1994 const TypeVect* TypeVect::make(const Type *elem, uint length) {
kvn@3447 1995 BasicType elem_bt = elem->array_element_basic_type();
kvn@3447 1996 assert(is_java_primitive(elem_bt), "only primitive types in vector");
kvn@3447 1997 assert(length > 1 && is_power_of_2(length), "vector length is power of 2");
kvn@3447 1998 assert(Matcher::vector_size_supported(elem_bt, length), "length in range");
kvn@3447 1999 int size = length * type2aelembytes(elem_bt);
kvn@3447 2000 switch (Matcher::vector_ideal_reg(size)) {
kvn@3447 2001 case Op_VecS:
kvn@3447 2002 return (TypeVect*)(new TypeVectS(elem, length))->hashcons();
kvn@3447 2003 case Op_VecD:
kvn@3447 2004 case Op_RegD:
kvn@3447 2005 return (TypeVect*)(new TypeVectD(elem, length))->hashcons();
kvn@3447 2006 case Op_VecX:
kvn@3447 2007 return (TypeVect*)(new TypeVectX(elem, length))->hashcons();
kvn@3447 2008 case Op_VecY:
kvn@3447 2009 return (TypeVect*)(new TypeVectY(elem, length))->hashcons();
kvn@3447 2010 }
kvn@3447 2011 ShouldNotReachHere();
kvn@3447 2012 return NULL;
kvn@3447 2013 }
kvn@3447 2014
kvn@3447 2015 //------------------------------meet-------------------------------------------
kvn@3447 2016 // Compute the MEET of two types. It returns a new Type object.
kvn@3447 2017 const Type *TypeVect::xmeet( const Type *t ) const {
kvn@3447 2018 // Perform a fast test for common case; meeting the same types together.
kvn@3447 2019 if( this == t ) return this; // Meeting same type-rep?
kvn@3447 2020
kvn@3447 2021 // Current "this->_base" is Vector
kvn@3447 2022 switch (t->base()) { // switch on original type
kvn@3447 2023
kvn@3447 2024 case Bottom: // Ye Olde Default
kvn@3447 2025 return t;
kvn@3447 2026
kvn@3447 2027 default: // All else is a mistake
kvn@3447 2028 typerr(t);
kvn@3447 2029
kvn@3447 2030 case VectorS:
kvn@3447 2031 case VectorD:
kvn@3447 2032 case VectorX:
kvn@3447 2033 case VectorY: { // Meeting 2 vectors?
kvn@3447 2034 const TypeVect* v = t->is_vect();
kvn@3447 2035 assert( base() == v->base(), "");
kvn@3447 2036 assert(length() == v->length(), "");
kvn@3447 2037 assert(element_basic_type() == v->element_basic_type(), "");
kvn@3447 2038 return TypeVect::make(_elem->xmeet(v->_elem), _length);
kvn@3447 2039 }
kvn@3447 2040 case Top:
kvn@3447 2041 break;
kvn@3447 2042 }
kvn@3447 2043 return this;
kvn@3447 2044 }
kvn@3447 2045
kvn@3447 2046 //------------------------------xdual------------------------------------------
kvn@3447 2047 // Dual: compute field-by-field dual
kvn@3447 2048 const Type *TypeVect::xdual() const {
kvn@3447 2049 return new TypeVect(base(), _elem->dual(), _length);
kvn@3447 2050 }
kvn@3447 2051
kvn@3447 2052 //------------------------------eq---------------------------------------------
kvn@3447 2053 // Structural equality check for Type representations
kvn@3447 2054 bool TypeVect::eq(const Type *t) const {
kvn@3447 2055 const TypeVect *v = t->is_vect();
kvn@3447 2056 return (_elem == v->_elem) && (_length == v->_length);
kvn@3447 2057 }
kvn@3447 2058
kvn@3447 2059 //------------------------------hash-------------------------------------------
kvn@3447 2060 // Type-specific hashing function.
kvn@3447 2061 int TypeVect::hash(void) const {
kvn@3447 2062 return (intptr_t)_elem + (intptr_t)_length;
kvn@3447 2063 }
kvn@3447 2064
kvn@3447 2065 //------------------------------singleton--------------------------------------
kvn@3447 2066 // TRUE if Type is a singleton type, FALSE otherwise. Singletons are simple
kvn@3447 2067 // constants (Ldi nodes). Vector is singleton if all elements are the same
kvn@3447 2068 // constant value (when vector is created with Replicate code).
kvn@3447 2069 bool TypeVect::singleton(void) const {
kvn@3447 2070 // There is no Con node for vectors yet.
kvn@3447 2071 // return _elem->singleton();
kvn@3447 2072 return false;
kvn@3447 2073 }
kvn@3447 2074
kvn@3447 2075 bool TypeVect::empty(void) const {
kvn@3447 2076 return _elem->empty();
kvn@3447 2077 }
kvn@3447 2078
kvn@3447 2079 //------------------------------dump2------------------------------------------
kvn@3447 2080 #ifndef PRODUCT
kvn@3447 2081 void TypeVect::dump2(Dict &d, uint depth, outputStream *st) const {
kvn@3447 2082 switch (base()) {
kvn@3447 2083 case VectorS:
kvn@3447 2084 st->print("vectors["); break;
kvn@3447 2085 case VectorD:
kvn@3447 2086 st->print("vectord["); break;
kvn@3447 2087 case VectorX:
kvn@3447 2088 st->print("vectorx["); break;
kvn@3447 2089 case VectorY:
kvn@3447 2090 st->print("vectory["); break;
kvn@3447 2091 default:
kvn@3447 2092 ShouldNotReachHere();
kvn@3447 2093 }
kvn@3447 2094 st->print("%d]:{", _length);
kvn@3447 2095 _elem->dump2(d, depth, st);
kvn@3447 2096 st->print("}");
kvn@3447 2097 }
kvn@3447 2098 #endif
kvn@3447 2099
kvn@3447 2100
duke@0 2101 //=============================================================================
duke@0 2102 // Convenience common pre-built types.
duke@0 2103 const TypePtr *TypePtr::NULL_PTR;
duke@0 2104 const TypePtr *TypePtr::NOTNULL;
duke@0 2105 const TypePtr *TypePtr::BOTTOM;
duke@0 2106
duke@0 2107 //------------------------------meet-------------------------------------------
duke@0 2108 // Meet over the PTR enum
duke@0 2109 const TypePtr::PTR TypePtr::ptr_meet[TypePtr::lastPTR][TypePtr::lastPTR] = {
duke@0 2110 // TopPTR, AnyNull, Constant, Null, NotNull, BotPTR,
duke@0 2111 { /* Top */ TopPTR, AnyNull, Constant, Null, NotNull, BotPTR,},
duke@0 2112 { /* AnyNull */ AnyNull, AnyNull, Constant, BotPTR, NotNull, BotPTR,},
duke@0 2113 { /* Constant*/ Constant, Constant, Constant, BotPTR, NotNull, BotPTR,},
duke@0 2114 { /* Null */ Null, BotPTR, BotPTR, Null, BotPTR, BotPTR,},
duke@0 2115 { /* NotNull */ NotNull, NotNull, NotNull, BotPTR, NotNull, BotPTR,},
duke@0 2116 { /* BotPTR */ BotPTR, BotPTR, BotPTR, BotPTR, BotPTR, BotPTR,}
duke@0 2117 };
duke@0 2118
duke@0 2119 //------------------------------make-------------------------------------------
duke@0 2120 const TypePtr *TypePtr::make( TYPES t, enum PTR ptr, int offset ) {
duke@0 2121 return (TypePtr*)(new TypePtr(t,ptr,offset))->hashcons();
duke@0 2122 }
duke@0 2123
duke@0 2124 //------------------------------cast_to_ptr_type-------------------------------
duke@0 2125 const Type *TypePtr::cast_to_ptr_type(PTR ptr) const {
duke@0 2126 assert(_base == AnyPtr, "subclass must override cast_to_ptr_type");
duke@0 2127 if( ptr == _ptr ) return this;
duke@0 2128 return make(_base, ptr, _offset);
duke@0 2129 }
duke@0 2130
duke@0 2131 //------------------------------get_con----------------------------------------
duke@0 2132 intptr_t TypePtr::get_con() const {
duke@0 2133 assert( _ptr == Null, "" );
duke@0 2134 return _offset;
duke@0 2135 }
duke@0 2136
duke@0 2137 //------------------------------meet-------------------------------------------
duke@0 2138 // Compute the MEET of two types. It returns a new Type object.
duke@0 2139 const Type *TypePtr::xmeet( const Type *t ) const {
duke@0 2140 // Perform a fast test for common case; meeting the same types together.
duke@0 2141 if( this == t ) return this; // Meeting same type-rep?
duke@0 2142
duke@0 2143 // Current "this->_base" is AnyPtr
duke@0 2144 switch (t->base()) { // switch on original type
duke@0 2145 case Int: // Mixing ints & oops happens when javac
duke@0 2146 case Long: // reuses local variables
duke@0 2147 case FloatTop:
duke@0 2148 case FloatCon:
duke@0 2149 case FloatBot:
duke@0 2150 case DoubleTop:
duke@0 2151 case DoubleCon:
duke@0 2152 case DoubleBot:
coleenp@113 2153 case NarrowOop:
roland@3724 2154 case NarrowKlass:
duke@0 2155 case Bottom: // Ye Olde Default
duke@0 2156 return Type::BOTTOM;
duke@0 2157 case Top:
duke@0 2158 return this;
duke@0 2159
duke@0 2160 case AnyPtr: { // Meeting to AnyPtrs
duke@0 2161 const TypePtr *tp = t->is_ptr();
duke@0 2162 return make( AnyPtr, meet_ptr(tp->ptr()), meet_offset(tp->offset()) );
duke@0 2163 }
duke@0 2164 case RawPtr: // For these, flip the call around to cut down
duke@0 2165 case OopPtr:
duke@0 2166 case InstPtr: // on the cases I have to handle.
coleenp@3602 2167 case AryPtr:
coleenp@3602 2168 case MetadataPtr:
duke@0 2169 case KlassPtr:
duke@0 2170 return t->xmeet(this); // Call in reverse direction
duke@0 2171 default: // All else is a mistake
duke@0 2172 typerr(t);
duke@0 2173
duke@0 2174 }
duke@0 2175 return this;
duke@0 2176 }
duke@0 2177
duke@0 2178 //------------------------------meet_offset------------------------------------
duke@0 2179 int TypePtr::meet_offset( int offset ) const {
duke@0 2180 // Either is 'TOP' offset? Return the other offset!
duke@0 2181 if( _offset == OffsetTop ) return offset;
duke@0 2182 if( offset == OffsetTop ) return _offset;
duke@0 2183 // If either is different, return 'BOTTOM' offset
duke@0 2184 if( _offset != offset ) return OffsetBot;
duke@0 2185 return _offset;
duke@0 2186 }
duke@0 2187
duke@0 2188 //------------------------------dual_offset------------------------------------
duke@0 2189 int TypePtr::dual_offset( ) const {
duke@0 2190 if( _offset == OffsetTop ) return OffsetBot;// Map 'TOP' into 'BOTTOM'
duke@0 2191 if( _offset == OffsetBot ) return OffsetTop;// Map 'BOTTOM' into 'TOP'
duke@0 2192 return _offset; // Map everything else into self
duke@0 2193 }
duke@0 2194
duke@0 2195 //------------------------------xdual------------------------------------------
duke@0 2196 // Dual: compute field-by-field dual
duke@0 2197 const TypePtr::PTR TypePtr::ptr_dual[TypePtr::lastPTR] = {
duke@0 2198 BotPTR, NotNull, Constant, Null, AnyNull, TopPTR
duke@0 2199 };
duke@0 2200 const Type *TypePtr::xdual() const {
duke@0 2201 return new TypePtr( AnyPtr, dual_ptr(), dual_offset() );
duke@0 2202 }
duke@0 2203
kvn@306 2204 //------------------------------xadd_offset------------------------------------
kvn@306 2205 int TypePtr::xadd_offset( intptr_t offset ) const {
kvn@306 2206 // Adding to 'TOP' offset? Return 'TOP'!
kvn@306 2207 if( _offset == OffsetTop || offset == OffsetTop ) return OffsetTop;
kvn@306 2208 // Adding to 'BOTTOM' offset? Return 'BOTTOM'!
kvn@306 2209 if( _offset == OffsetBot || offset == OffsetBot ) return OffsetBot;
kvn@306 2210 // Addition overflows or "accidentally" equals to OffsetTop? Return 'BOTTOM'!
kvn@306 2211 offset += (intptr_t)_offset;
kvn@306 2212 if (offset != (int)offset || offset == OffsetTop) return OffsetBot;
kvn@306 2213
kvn@306 2214 // assert( _offset >= 0 && _offset+offset >= 0, "" );
kvn@306 2215 // It is possible to construct a negative offset during PhaseCCP
kvn@306 2216
kvn@306 2217 return (int)offset; // Sum valid offsets
kvn@306 2218 }
kvn@306 2219
duke@0 2220 //------------------------------add_offset-------------------------------------
kvn@306 2221 const TypePtr *TypePtr::add_offset( intptr_t offset ) const {
kvn@306 2222 return make( AnyPtr, _ptr, xadd_offset(offset) );
duke@0 2223 }
duke@0 2224
duke@0 2225 //------------------------------eq---------------------------------------------
duke@0 2226 // Structural equality check for Type representations
duke@0 2227 bool TypePtr::eq( const Type *t ) const {
duke@0 2228 const TypePtr *a = (const TypePtr*)t;
duke@0 2229 return _ptr == a->ptr() && _offset == a->offset();
duke@0 2230 }
duke@0 2231
duke@0 2232 //------------------------------hash-------------------------------------------
duke@0 2233 // Type-specific hashing function.
duke@0 2234 int TypePtr::hash(void) const {
duke@0 2235 return _ptr + _offset;
duke@0 2236 }
duke@0 2237
duke@0 2238 //------------------------------dump2------------------------------------------
duke@0 2239 const char *const TypePtr::ptr_msg[TypePtr::lastPTR] = {
duke@0 2240 "TopPTR","AnyNull","Constant","NULL","NotNull","BotPTR"
duke@0 2241 };
duke@0 2242
duke@0 2243 #ifndef PRODUCT
duke@0 2244 void TypePtr::dump2( Dict &d, uint depth, outputStream *st ) const {
duke@0 2245 if( _ptr == Null ) st->print("NULL");
duke@0 2246 else st->print("%s *", ptr_msg[_ptr]);
duke@0 2247 if( _offset == OffsetTop ) st->print("+top");
duke@0 2248 else if( _offset == OffsetBot ) st->print("+bot");
duke@0 2249 else if( _offset ) st->print("+%d", _offset);
duke@0 2250 }
duke@0 2251 #endif
duke@0 2252
duke@0 2253 //------------------------------singleton--------------------------------------
duke@0 2254 // TRUE if Type is a singleton type, FALSE otherwise. Singletons are simple
duke@0 2255 // constants
duke@0 2256 bool TypePtr::singleton(void) const {
duke@0 2257 // TopPTR, Null, AnyNull, Constant are all singletons
duke@0 2258 return (_offset != OffsetBot) && !below_centerline(_ptr);
duke@0 2259 }
duke@0 2260
duke@0 2261 bool TypePtr::empty(void) const {
duke@0 2262 return (_offset == OffsetTop) || above_centerline(_ptr);
duke@0 2263 }
duke@0 2264
duke@0 2265 //=============================================================================
duke@0 2266 // Convenience common pre-built types.
duke@0 2267 const TypeRawPtr *TypeRawPtr::BOTTOM;
duke@0 2268 const TypeRawPtr *TypeRawPtr::NOTNULL;
duke@0 2269
duke@0 2270 //------------------------------make-------------------------------------------
duke@0 2271 const TypeRawPtr *TypeRawPtr::make( enum PTR ptr ) {
duke@0 2272 assert( ptr != Constant, "what is the constant?" );
duke@0 2273 assert( ptr != Null, "Use TypePtr for NULL" );
duke@0 2274 return (TypeRawPtr*)(new TypeRawPtr(ptr,0))->hashcons();
duke@0 2275 }
duke@0 2276
duke@0 2277 const TypeRawPtr *TypeRawPtr::make( address bits ) {
duke@0 2278 assert( bits, "Use TypePtr for NULL" );
duke@0 2279 return (TypeRawPtr*)(new TypeRawPtr(Constant,bits))->hashcons();
duke@0 2280 }
duke@0 2281
duke@0 2282 //------------------------------cast_to_ptr_type-------------------------------
duke@0 2283 const Type *TypeRawPtr::cast_to_ptr_type(PTR ptr) const {
duke@0 2284 assert( ptr != Constant, "what is the constant?" );
duke@0 2285 assert( ptr != Null, "Use TypePtr for NULL" );
duke@0 2286 assert( _bits==0, "Why cast a constant address?");
duke@0 2287 if( ptr == _ptr ) return this;
duke@0 2288 return make(ptr);
duke@0 2289 }
duke@0 2290
duke@0 2291 //------------------------------get_con----------------------------------------
duke@0 2292 intptr_t TypeRawPtr::get_con() const {
duke@0 2293 assert( _ptr == Null || _ptr == Constant, "" );
duke@0 2294 return (intptr_t)_bits;
duke@0 2295 }
duke@0 2296
duke@0 2297 //------------------------------meet-------------------------------------------
duke@0 2298 // Compute the MEET of two types. It returns a new Type object.
duke@0 2299 const Type *TypeRawPtr::xmeet( const Type *t ) const {
duke@0 2300 // Perform a fast test for common case; meeting the same types together.
duke@0 2301 if( this == t ) return this; // Meeting same type-rep?
duke@0 2302
duke@0 2303 // Current "this->_base" is RawPtr
duke@0 2304 switch( t->base() ) { // switch on original type
duke@0 2305 case Bottom: // Ye Olde Default
duke@0 2306 return t;
duke@0 2307 case Top:
duke@0 2308 return this;
duke@0 2309 case AnyPtr: // Meeting to AnyPtrs
duke@0 2310 break;
duke@0 2311 case RawPtr: { // might be top, bot, any/not or constant
duke@0 2312 enum PTR tptr = t->is_ptr()->ptr();
duke@0 2313 enum PTR ptr = meet_ptr( tptr );
duke@0 2314 if( ptr == Constant ) { // Cannot be equal constants, so...
duke@0 2315 if( tptr == Constant && _ptr != Constant) return t;
duke@0 2316 if( _ptr == Constant && tptr != Constant) return this;
duke@0 2317 ptr = NotNull; // Fall down in lattice
duke@0 2318 }
duke@0 2319 return make( ptr );
duke@0 2320 }
duke@0 2321
duke@0 2322 case OopPtr:
duke@0 2323 case InstPtr:
coleenp@3602 2324 case AryPtr:
coleenp@3602 2325 case MetadataPtr:
duke@0 2326 case KlassPtr:
duke@0 2327 return TypePtr::BOTTOM; // Oop meet raw is not well defined
duke@0 2328 default: // All else is a mistake
duke@0 2329 typerr(t);
duke@0 2330 }
duke@0 2331
duke@0 2332 // Found an AnyPtr type vs self-RawPtr type
duke@0 2333 const TypePtr *tp = t->is_ptr();
duke@0 2334 switch (tp->ptr()) {
duke@0 2335 case TypePtr::TopPTR: return this;
duke@0 2336 case TypePtr::BotPTR: return t;
duke@0 2337 case TypePtr::Null:
duke@0 2338 if( _ptr == TypePtr::TopPTR ) return t;
duke@0 2339 return TypeRawPtr::BOTTOM;
duke@0 2340 case TypePtr::NotNull: return TypePtr::make( AnyPtr, meet_ptr(TypePtr::NotNull), tp->meet_offset(0) );
duke@0 2341 case TypePtr::AnyNull:
duke@0 2342 if( _ptr == TypePtr::Constant) return this;
duke@0 2343 return make( meet_ptr(TypePtr::AnyNull) );
duke@0 2344 default: ShouldNotReachHere();
duke@0 2345 }
duke@0 2346 return this;
duke@0 2347 }
duke@0 2348
duke@0 2349 //------------------------------xdual------------------------------------------
duke@0 2350 // Dual: compute field-by-field dual
duke@0 2351 const Type *TypeRawPtr::xdual() const {
duke@0 2352 return new TypeRawPtr( dual_ptr(), _bits );
duke@0 2353 }
duke@0 2354
duke@0 2355 //------------------------------add_offset-------------------------------------
kvn@306 2356 const TypePtr *TypeRawPtr::add_offset( intptr_t offset ) const {
duke@0 2357 if( offset == OffsetTop ) return BOTTOM; // Undefined offset-> undefined pointer
duke@0 2358 if( offset == OffsetBot ) return BOTTOM; // Unknown offset-> unknown pointer
duke@0 2359 if( offset == 0 ) return this; // No change
duke@0 2360 switch (_ptr) {
duke@0 2361 case TypePtr::TopPTR:
duke@0 2362 case TypePtr::BotPTR:
duke@0 2363 case TypePtr::NotNull:
duke@0 2364 return this;
duke@0 2365 case TypePtr::Null:
kvn@2000 2366 case TypePtr::Constant: {
kvn@2000 2367 address bits = _bits+offset;
kvn@2000 2368 if ( bits == 0 ) return TypePtr::NULL_PTR;
kvn@2000 2369 return make( bits );
kvn@2000 2370 }
duke@0 2371 default: ShouldNotReachHere();
duke@0 2372 }
duke@0 2373 return NULL; // Lint noise
duke@0 2374 }
duke@0 2375
duke@0 2376 //------------------------------eq---------------------------------------------
duke@0 2377 // Structural equality check for Type representations
duke@0 2378 bool TypeRawPtr::eq( const Type *t ) const {
duke@0 2379 const TypeRawPtr *a = (const TypeRawPtr*)t;
duke@0 2380 return _bits == a->_bits && TypePtr::eq(t);
duke@0 2381 }
duke@0 2382
duke@0 2383 //------------------------------hash-------------------------------------------
duke@0 2384 // Type-specific hashing function.
duke@0 2385 int TypeRawPtr::hash(void) const {
duke@0 2386 return (intptr_t)_bits + TypePtr::hash();
duke@0 2387 }
duke@0 2388
duke@0 2389 //------------------------------dump2------------------------------------------
duke@0 2390 #ifndef PRODUCT
duke@0 2391 void TypeRawPtr::dump2( Dict &d, uint depth, outputStream *st ) const {
duke@0 2392 if( _ptr == Constant )
duke@0 2393 st->print(INTPTR_FORMAT, _bits);
duke@0 2394 else
duke@0 2395 st->print("rawptr:%s", ptr_msg[_ptr]);
duke@0 2396 }
duke@0 2397 #endif
duke@0 2398
duke@0 2399 //=============================================================================
duke@0 2400 // Convenience common pre-built type.
duke@0 2401 const TypeOopPtr *TypeOopPtr::BOTTOM;
duke@0 2402
kvn@163 2403 //------------------------------TypeOopPtr-------------------------------------
kvn@163 2404 TypeOopPtr::TypeOopPtr( TYPES t, PTR ptr, ciKlass* k, bool xk, ciObject* o, int offset, int instance_id )
kvn@163 2405 : TypePtr(t, ptr, offset),
kvn@163 2406 _const_oop(o), _klass(k),
kvn@163 2407 _klass_is_exact(xk),
kvn@163 2408 _is_ptr_to_narrowoop(false),
roland@3724 2409 _is_ptr_to_narrowklass(false),
kvn@4675 2410 _is_ptr_to_boxed_value(false),
kvn@163 2411 _instance_id(instance_id) {
kvn@4675 2412 if (Compile::current()->eliminate_boxing() && (t == InstPtr) &&
kvn@4675 2413 (offset > 0) && xk && (k != 0) && k->is_instance_klass()) {
kvn@4675 2414 _is_ptr_to_boxed_value = k->as_instance_klass()->is_boxed_value_offset(offset);
kvn@4675 2415 }
kvn@163 2416 #ifdef _LP64
roland@3724 2417 if (_offset != 0) {
coleenp@3602 2418 if (_offset == oopDesc::klass_offset_in_bytes()) {
roland@3724 2419 _is_ptr_to_narrowklass = UseCompressedKlassPointers;
coleenp@3602 2420 } else if (klass() == NULL) {
coleenp@3602 2421 // Array with unknown body type
kvn@163 2422 assert(this->isa_aryptr(), "only arrays without klass");
roland@3724 2423 _is_ptr_to_narrowoop = UseCompressedOops;
kvn@163 2424 } else if (this->isa_aryptr()) {
roland@3724 2425 _is_ptr_to_narrowoop = (UseCompressedOops && klass()->is_obj_array_klass() &&
kvn@163 2426 _offset != arrayOopDesc::length_offset_in_bytes());
kvn@163 2427 } else if (klass()->is_instance_klass()) {
kvn@163 2428 ciInstanceKlass* ik = klass()->as_instance_klass();
kvn@163 2429 ciField* field = NULL;
kvn@163 2430 if (this->isa_klassptr()) {
never@2223 2431 // Perm objects don't use compressed references
kvn@163 2432 } else if (_offset == OffsetBot || _offset == OffsetTop) {
kvn@163 2433 // unsafe access
roland@3724 2434 _is_ptr_to_narrowoop = UseCompressedOops;
kvn@163 2435 } else { // exclude unsafe ops
kvn@163 2436 assert(this->isa_instptr(), "must be an instance ptr.");
never@2223 2437
never@2223 2438 if (klass() == ciEnv::current()->Class_klass() &&
never@2223 2439 (_offset == java_lang_Class::klass_offset_in_bytes() ||
never@2223 2440 _offset == java_lang_Class::array_klass_offset_in_bytes())) {
never@2223 2441 // Special hidden fields from the Class.
never@2223 2442 assert(this->isa_instptr(), "must be an instance ptr.");
coleenp@3602 2443 _is_ptr_to_narrowoop = false;
never@2223 2444 } else if (klass() == ciEnv::current()->Class_klass() &&
coleenp@3612 2445 _offset >= InstanceMirrorKlass::offset_of_static_fields()) {
never@2223 2446 // Static fields
never@2223 2447 assert(o != NULL, "must be constant");
never@2223 2448 ciInstanceKlass* k = o->as_instance()->java_lang_Class_klass()->as_instance_klass();
never@2223 2449 ciField* field = k->get_field_by_offset(_offset, true);
never@2223 2450 assert(field != NULL, "missing field");
kvn@163 2451 BasicType basic_elem_type = field->layout_type();
roland@3724 2452 _is_ptr_to_narrowoop = UseCompressedOops && (basic_elem_type == T_OBJECT ||
roland@3724 2453 basic_elem_type == T_ARRAY);
kvn@163 2454 } else {
never@2223 2455 // Instance fields which contains a compressed oop references.
never@2223 2456 field = ik->get_field_by_offset(_offset, false);
never@2223 2457 if (field != NULL) {
never@2223 2458 BasicType basic_elem_type = field->layout_type();
roland@3724 2459 _is_ptr_to_narrowoop = UseCompressedOops && (basic_elem_type == T_OBJECT ||
roland@3724 2460 basic_elem_type == T_ARRAY);
never@2223 2461 } else if (klass()->equals(ciEnv::current()->Object_klass())) {
never@2223 2462 // Compile::find_alias_type() cast exactness on all types to verify
never@2223 2463 // that it does not affect alias type.
roland@3724 2464 _is_ptr_to_narrowoop = UseCompressedOops;
never@2223 2465 } else {
never@2223 2466 // Type for the copy start in LibraryCallKit::inline_native_clone().
roland@3724 2467 _is_ptr_to_narrowoop = UseCompressedOops;
never@2223 2468 }
kvn@163 2469 }
kvn@163 2470 }
kvn@163 2471 }
kvn@163 2472 }
kvn@163 2473 #endif
kvn@163 2474 }
kvn@163 2475
duke@0 2476 //------------------------------make-------------------------------------------
duke@0 2477 const TypeOopPtr *TypeOopPtr::make(PTR ptr,
kvn@958 2478 int offset, int instance_id) {
duke@0 2479 assert(ptr != Constant, "no constant generic pointers");
coleenp@3602 2480 ciKlass* k = Compile::current()->env()->Object_klass();
duke@0 2481 bool xk = false;
duke@0 2482 ciObject* o = NULL;
kvn@958 2483 return (TypeOopPtr*)(new TypeOopPtr(OopPtr, ptr, k, xk, o, offset, instance_id))->hashcons();
duke@0 2484 }
duke@0 2485
duke@0 2486
duke@0 2487 //------------------------------cast_to_ptr_type-------------------------------
duke@0 2488 const Type *TypeOopPtr::cast_to_ptr_type(PTR ptr) const {
duke@0 2489 assert(_base == OopPtr, "subclass must override cast_to_ptr_type");
duke@0 2490 if( ptr == _ptr ) return this;
kvn@992 2491 return make(ptr, _offset, _instance_id);
duke@0 2492 }
duke@0 2493
kvn@247 2494 //-----------------------------cast_to_instance_id----------------------------
kvn@223 2495 const TypeOopPtr *TypeOopPtr::cast_to_instance_id(int instance_id) const {
duke@0 2496 // There are no instances of a general oop.
duke@0 2497 // Return self unchanged.
duke@0 2498 return this;
duke@0 2499 }
duke@0 2500
duke@0 2501 //-----------------------------cast_to_exactness-------------------------------
duke@0 2502 const Type *TypeOopPtr::cast_to_exactness(bool klass_is_exact) const {
duke@0 2503 // There is no such thing as an exact general oop.
duke@0 2504 // Return self unchanged.
duke@0 2505 return this;
duke@0 2506 }
duke@0 2507
duke@0 2508
duke@0 2509 //------------------------------as_klass_type----------------------------------
duke@0 2510 // Return the klass type corresponding to this instance or array type.
duke@0 2511 // It is the type that is loaded from an object of this type.
duke@0 2512 const TypeKlassPtr* TypeOopPtr::as_klass_type() const {
duke@0 2513 ciKlass* k = klass();
duke@0 2514 bool xk = klass_is_exact();
coleenp@3602 2515 if (k == NULL)
duke@0 2516 return TypeKlassPtr::OBJECT;
duke@0 2517 else
duke@0 2518 return TypeKlassPtr::make(xk? Constant: NotNull, k, 0);
duke@0 2519 }
duke@0 2520
duke@0 2521
duke@0 2522 //------------------------------meet-------------------------------------------
duke@0 2523 // Compute the MEET of two types. It returns a new Type object.
duke@0 2524 const Type *TypeOopPtr::xmeet( const Type *t ) const {
duke@0 2525 // Perform a fast test for common case; meeting the same types together.
duke@0 2526 if( this == t ) return this; // Meeting same type-rep?
duke@0 2527
duke@0 2528 // Current "this->_base" is OopPtr
duke@0 2529 switch (t->base()) { // switch on original type
duke@0 2530
duke@0 2531 case Int: // Mixing ints & oops happens when javac
duke@0 2532 case Long: // reuses local variables
duke@0 2533 case FloatTop:
duke@0 2534 case FloatCon:
duke@0 2535 case FloatBot:
duke@0 2536 case DoubleTop:
duke@0 2537 case DoubleCon:
duke@0 2538 case DoubleBot:
kvn@293 2539 case NarrowOop:
roland@3724 2540 case NarrowKlass:
duke@0 2541 case Bottom: // Ye Olde Default
duke@0 2542 return Type::BOTTOM;
duke@0 2543 case Top:
duke@0 2544 return this;
duke@0 2545
duke@0 2546 default: // All else is a mistake
duke@0 2547 typerr(t);
duke@0 2548
duke@0 2549 case RawPtr:
coleenp@3602 2550 case MetadataPtr:
coleenp@3602 2551 case KlassPtr:
duke@0 2552 return TypePtr::BOTTOM; // Oop meet raw is not well defined
duke@0 2553
duke@0 2554 case AnyPtr: {
duke@0 2555 // Found an AnyPtr type vs self-OopPtr type
duke@0 2556 const TypePtr *tp = t->is_ptr();
duke@0 2557 int offset = meet_offset(tp->offset());
duke@0 2558 PTR ptr = meet_ptr(tp->ptr());
duke@0 2559 switch (tp->ptr()) {
duke@0 2560 case Null:
duke@0 2561 if (ptr == Null) return TypePtr::make(AnyPtr, ptr, offset);
duke@0 2562 // else fall through:
duke@0 2563 case TopPTR:
kvn@992 2564 case AnyNull: {
kvn@992 2565 int instance_id = meet_instance_id(InstanceTop);
kvn@992 2566 return make(ptr, offset, instance_id);
kvn@992 2567 }
duke@0 2568 case BotPTR:
duke@0 2569 case NotNull:
duke@0 2570 return TypePtr::make(AnyPtr, ptr, offset);
duke@0 2571 default: typerr(t);
duke@0 2572 }
duke@0 2573 }
duke@0 2574
duke@0 2575 case OopPtr: { // Meeting to other OopPtrs
duke@0 2576 const TypeOopPtr *tp = t->is_oopptr();
kvn@958 2577 int instance_id = meet_instance_id(tp->instance_id());
kvn@958 2578 return make( meet_ptr(tp->ptr()), meet_offset(tp->offset()), instance_id );
duke@0 2579 }
duke@0 2580
duke@0 2581 case InstPtr: // For these, flip the call around to cut down
duke@0 2582 case AryPtr:
duke@0 2583 return t->xmeet(this); // Call in reverse direction
duke@0 2584
duke@0 2585 } // End of switch
duke@0 2586 return this; // Return the double constant
duke@0 2587 }
duke@0 2588
duke@0 2589
duke@0 2590 //------------------------------xdual------------------------------------------
duke@0 2591 // Dual of a pure heap pointer. No relevant klass or oop information.
duke@0 2592 const Type *TypeOopPtr::xdual() const {
coleenp@3602 2593 assert(klass() == Compile::current()->env()->Object_klass(), "no klasses here");
duke@0 2594 assert(const_oop() == NULL, "no constants here");
kvn@223 2595 return new TypeOopPtr(_base, dual_ptr(), klass(), klass_is_exact(), const_oop(), dual_offset(), dual_instance_id() );
duke@0 2596 }
duke@0 2597
duke@0 2598 //--------------------------make_from_klass_common-----------------------------
duke@0 2599 // Computes the element-type given a klass.
duke@0 2600 const TypeOopPtr* TypeOopPtr::make_from_klass_common(ciKlass *klass, bool klass_change, bool try_for_exact) {
duke@0 2601 if (klass->is_instance_klass()) {
duke@0 2602 Compile* C = Compile::current();
duke@0 2603 Dependencies* deps = C->dependencies();
duke@0 2604 assert((deps != NULL) == (C->method() != NULL && C->method()->code_size() > 0), "sanity");
duke@0 2605 // Element is an instance
duke@0 2606 bool klass_is_exact = false;
duke@0 2607 if (klass->is_loaded()) {
duke@0 2608 // Try to set klass_is_exact.
duke@0 2609 ciInstanceKlass* ik = klass->as_instance_klass();
duke@0 2610 klass_is_exact = ik->is_final();
duke@0 2611 if (!klass_is_exact && klass_change
duke@0 2612 && deps != NULL && UseUniqueSubclasses) {
duke@0 2613 ciInstanceKlass* sub = ik->unique_concrete_subklass();
duke@0 2614 if (sub != NULL) {
duke@0 2615 deps->assert_abstract_with_unique_concrete_subtype(ik, sub);
duke@0 2616 klass = ik = sub;
duke@0 2617 klass_is_exact = sub->is_final();
duke@0 2618 }
duke@0 2619 }
duke@0 2620 if (!klass_is_exact && try_for_exact
duke@0 2621 && deps != NULL && UseExactTypes) {
duke@0 2622 if (!ik->is_interface() && !ik->has_subklass()) {
duke@0 2623 // Add a dependence; if concrete subclass added we need to recompile
duke@0 2624 deps->assert_leaf_type(ik);
duke@0 2625 klass_is_exact = true;
duke@0 2626 }
duke@0 2627 }
duke@0 2628 }
duke@0 2629 return TypeInstPtr::make(TypePtr::BotPTR, klass, klass_is_exact, NULL, 0);
duke@0 2630 } else if (klass->is_obj_array_klass()) {
duke@0 2631 // Element is an object array. Recursively call ourself.
duke@0 2632 const TypeOopPtr *etype = TypeOopPtr::make_from_klass_common(klass->as_obj_array_klass()->element_klass(), false, try_for_exact);
duke@0 2633 bool xk = etype->klass_is_exact();
duke@0 2634 const TypeAry* arr0 = TypeAry::make(etype, TypeInt::POS);
duke@0 2635 // We used to pass NotNull in here, asserting that the sub-arrays
duke@0 2636 // are all not-null. This is not true in generally, as code can
duke@0 2637 // slam NULLs down in the subarrays.
duke@0 2638 const TypeAryPtr* arr = TypeAryPtr::make(TypePtr::BotPTR, arr0, klass, xk, 0);
duke@0 2639 return arr;
duke@0 2640 } else if (klass->is_type_array_klass()) {
duke@0 2641 // Element is an typeArray
duke@0 2642 const Type* etype = get_const_basic_type(klass->as_type_array_klass()->element_type());
duke@0 2643 const TypeAry* arr0 = TypeAry::make(etype, TypeInt::POS);
duke@0 2644 // We used to pass NotNull in here, asserting that the array pointer
duke@0 2645 // is not-null. That was not true in general.
duke@0 2646 const TypeAryPtr* arr = TypeAryPtr::make(TypePtr::BotPTR, arr0, klass, true, 0);
duke@0 2647 return arr;
duke@0 2648 } else {
duke@0 2649 ShouldNotReachHere();
duke@0 2650 return NULL;
duke@0 2651 }
duke@0 2652 }
duke@0 2653
duke@0 2654 //------------------------------make_from_constant-----------------------------
duke@0 2655 // Make a java pointer from an oop constant
kvn@4675 2656 const TypeOopPtr* TypeOopPtr::make_from_constant(ciObject* o,
kvn@4675 2657 bool require_constant,
kvn@4675 2658 bool is_autobox_cache) {
kvn@4675 2659 assert(!o->is_null_object(), "null object not yet handled here.");
kvn@4675 2660 ciKlass* klass = o->klass();
kvn@4675 2661 if (klass->is_instance_klass()) {
kvn@4675 2662 // Element is an instance
kvn@4675 2663 if (require_constant) {
kvn@4675 2664 if (!o->can_be_constant()) return NULL;
kvn@4675 2665 } else if (!o->should_be_constant()) {
kvn@4675 2666 return TypeInstPtr::make(TypePtr::NotNull, klass, true, NULL, 0);
kvn@4675 2667 }
kvn@4675 2668 return TypeInstPtr::make(o);
kvn@4675 2669 } else if (klass->is_obj_array_klass()) {
kvn@4675 2670 // Element is an object array. Recursively call ourself.
kvn@4675 2671 const TypeOopPtr *etype =
coleenp@3602 2672 TypeOopPtr::make_from_klass_raw(klass->as_obj_array_klass()->element_klass());
kvn@4675 2673 if (is_autobox_cache) {
kvn@4675 2674 // The pointers in the autobox arrays are always non-null.
kvn@4675 2675 etype = etype->cast_to_ptr_type(TypePtr::NotNull)->is_oopptr();
kvn@4675 2676 }
kvn@4675 2677 const TypeAry* arr0 = TypeAry::make(etype, TypeInt::make(o->as_array()->length()));
kvn@4675 2678 // We used to pass NotNull in here, asserting that the sub-arrays
kvn@4675 2679 // are all not-null. This is not true in generally, as code can
kvn@4675 2680 // slam NULLs down in the subarrays.
kvn@4675 2681 if (require_constant) {
kvn@4675 2682 if (!o->can_be_constant()) return NULL;
kvn@4675 2683 } else if (!o->should_be_constant()) {
kvn@4675 2684 return TypeAryPtr::make(TypePtr::NotNull, arr0, klass, true, 0);
kvn@4675 2685 }
kvn@4675 2686 const TypeAryPtr* arr = TypeAryPtr::make(TypePtr::Constant, o, arr0, klass, true, 0, InstanceBot, is_autobox_cache);
coleenp@3602 2687 return arr;
kvn@4675 2688 } else if (klass->is_type_array_klass()) {
kvn@4675 2689 // Element is an typeArray
coleenp@3602 2690 const Type* etype =
coleenp@3602 2691 (Type*)get_const_basic_type(klass->as_type_array_klass()->element_type());
kvn@4675 2692 const TypeAry* arr0 = TypeAry::make(etype, TypeInt::make(o->as_array()->length()));
kvn@4675 2693 // We used to pass NotNull in here, asserting that the array pointer
kvn@4675 2694 // is not-null. That was not true in general.
kvn@4675 2695 if (require_constant) {
kvn@4675 2696 if (!o->can_be_constant()) return NULL;
kvn@4675 2697 } else if (!o->should_be_constant()) {
kvn@4675 2698 return TypeAryPtr::make(TypePtr::NotNull, arr0, klass, true, 0);
kvn@4675 2699 }
coleenp@3602 2700 const TypeAryPtr* arr = TypeAryPtr::make(TypePtr::Constant, o, arr0, klass, true, 0);
coleenp@3602 2701 return arr;
duke@0 2702 }
duke@0 2703
twisti@3450 2704 fatal("unhandled object type");
duke@0 2705 return NULL;
duke@0 2706 }
duke@0 2707
duke@0 2708 //------------------------------get_con----------------------------------------
duke@0 2709 intptr_t TypeOopPtr::get_con() const {
duke@0 2710 assert( _ptr == Null || _ptr == Constant, "" );
duke@0 2711 assert( _offset >= 0, "" );
duke@0 2712
duke@0 2713 if (_offset != 0) {
duke@0 2714 // After being ported to the compiler interface, the compiler no longer
duke@0 2715 // directly manipulates the addresses of oops. Rather, it only has a pointer
duke@0 2716 // to a handle at compile time. This handle is embedded in the generated
duke@0 2717 // code and dereferenced at the time the nmethod is made. Until that time,
duke@0 2718 // it is not reasonable to do arithmetic with the addresses of oops (we don't
duke@0 2719 // have access to the addresses!). This does not seem to currently happen,
twisti@605 2720 // but this assertion here is to help prevent its occurence.
duke@0 2721 tty->print_cr("Found oop constant with non-zero offset");
duke@0 2722 ShouldNotReachHere();
duke@0 2723 }
duke@0 2724
jrose@989 2725 return (intptr_t)const_oop()->constant_encoding();
duke@0 2726 }
duke@0 2727
duke@0 2728
duke@0 2729 //-----------------------------filter------------------------------------------
duke@0 2730 // Do not allow interface-vs.-noninterface joins to collapse to top.
duke@0 2731 const Type *TypeOopPtr::filter( const Type *kills ) const {
duke@0 2732
duke@0 2733 const Type* ft = join(kills);
duke@0 2734 const TypeInstPtr* ftip = ft->isa_instptr();
duke@0 2735 const TypeInstPtr* ktip = kills->isa_instptr();
never@555 2736 const TypeKlassPtr* ftkp = ft->isa_klassptr();
never@555 2737 const TypeKlassPtr* ktkp = kills->isa_klassptr();
duke@0 2738
duke@0 2739 if (ft->empty()) {
duke@0 2740 // Check for evil case of 'this' being a class and 'kills' expecting an
duke@0 2741 // interface. This can happen because the bytecodes do not contain
duke@0 2742 // enough type info to distinguish a Java-level interface variable
duke@0 2743 // from a Java-level object variable. If we meet 2 classes which
duke@0 2744 // both implement interface I, but their meet is at 'j/l/O' which
duke@0 2745 // doesn't implement I, we have no way to tell if the result should
duke@0 2746 // be 'I' or 'j/l/O'. Thus we'll pick 'j/l/O'. If this then flows
duke@0 2747 // into a Phi which "knows" it's an Interface type we'll have to
duke@0 2748 // uplift the type.
duke@0 2749 if (!empty() && ktip != NULL && ktip->is_loaded() && ktip->klass()->is_interface())
duke@0 2750 return kills; // Uplift to interface
never@555 2751 if (!empty() && ktkp != NULL && ktkp->klass()->is_loaded() && ktkp->klass()->is_interface())
never@555 2752 return kills; // Uplift to interface
duke@0 2753
duke@0 2754 return Type::TOP; // Canonical empty value
duke@0 2755 }
duke@0 2756
duke@0 2757 // If we have an interface-typed Phi or cast and we narrow to a class type,
duke@0 2758 // the join should report back the class. However, if we have a J/L/Object
duke@0 2759 // class-typed Phi and an interface flows in, it's possible that the meet &
duke@0 2760 // join report an interface back out. This isn't possible but happens
duke@0 2761 // because the type system doesn't interact well with interfaces.
duke@0 2762 if (ftip != NULL && ktip != NULL &&
duke@0 2763 ftip->is_loaded() && ftip->klass()->is_interface() &&
duke@0 2764 ktip->is_loaded() && !ktip->klass()->is_interface()) {
duke@0 2765 // Happens in a CTW of rt.jar, 320-341, no extra flags
kvn@1335 2766 assert(!ftip->klass_is_exact(), "interface could not be exact");
duke@0 2767 return ktip->cast_to_ptr_type(ftip->ptr());
duke@0 2768 }
kvn@1335 2769 // Interface klass type could be exact in opposite to interface type,
kvn@1335 2770 // return it here instead of incorrect Constant ptr J/L/Object (6894807).
never@555 2771 if (ftkp != NULL && ktkp != NULL &&
never@555 2772 ftkp->is_loaded() && ftkp->klass()->is_interface() &&
kvn@1335 2773 !ftkp->klass_is_exact() && // Keep exact interface klass
never@555 2774 ktkp->is_loaded() && !ktkp->klass()->is_interface()) {
never@555 2775 return ktkp->cast_to_ptr_type(ftkp->ptr());
never@555 2776 }
duke@0 2777
duke@0 2778 return ft;
duke@0 2779 }
duke@0 2780
duke@0 2781 //------------------------------eq---------------------------------------------
duke@0 2782 // Structural equality check for Type representations
duke@0 2783 bool TypeOopPtr::eq( const Type *t ) const {
duke@0 2784 const TypeOopPtr *a = (const TypeOopPtr*)t;
duke@0 2785 if (_klass_is_exact != a->_klass_is_exact ||
duke@0 2786 _instance_id != a->_instance_id) return false;
duke@0 2787 ciObject* one = const_oop();
duke@0 2788 ciObject* two = a->const_oop();
duke@0 2789 if (one == NULL || two == NULL) {
duke@0 2790 return (one == two) && TypePtr::eq(t);
duke@0 2791 } else {
duke@0 2792 return one->equals(two) && TypePtr::eq(t);
duke@0 2793 }
duke@0 2794 }
duke@0 2795
duke@0 2796 //------------------------------hash-------------------------------------------
duke@0 2797 // Type-specific hashing function.
duke@0 2798 int TypeOopPtr::hash(void) const {
duke@0 2799 return
duke@0 2800 (const_oop() ? const_oop()->hash() : 0) +
duke@0 2801 _klass_is_exact +
duke@0 2802 _instance_id +
duke@0 2803 TypePtr::hash();
duke@0 2804 }
duke@0 2805
duke@0 2806 //------------------------------dump2------------------------------------------
duke@0 2807 #ifndef PRODUCT
duke@0 2808 void TypeOopPtr::dump2( Dict &d, uint depth, outputStream *st ) const {
duke@0 2809 st->print("oopptr:%s", ptr_msg[_ptr]);
duke@0 2810 if( _klass_is_exact ) st->print(":exact");
duke@0 2811 if( const_oop() ) st->print(INTPTR_FORMAT, const_oop());
duke@0 2812 switch( _offset ) {
duke@0 2813 case OffsetTop: st->print("+top"); break;
duke@0 2814 case OffsetBot: st->print("+any"); break;
duke@0 2815 case 0: break;
duke@0 2816 default: st->print("+%d",_offset); break;
duke@0 2817 }
kvn@223 2818 if (_instance_id == InstanceTop)
kvn@223 2819 st->print(",iid=top");
kvn@223 2820 else if (_instance_id != InstanceBot)
duke@0 2821 st->print(",iid=%d",_instance_id);
duke@0 2822 }
duke@0 2823 #endif
duke@0 2824
duke@0 2825 //------------------------------singleton--------------------------------------
duke@0 2826 // TRUE if Type is a singleton type, FALSE otherwise. Singletons are simple
duke@0 2827 // constants
duke@0 2828 bool TypeOopPtr::singleton(void) const {
duke@0 2829 // detune optimizer to not generate constant oop + constant offset as a constant!
duke@0 2830 // TopPTR, Null, AnyNull, Constant are all singletons
duke@0 2831 return (_offset == 0) && !below_centerline(_ptr);
duke@0 2832 }
duke@0 2833
duke@0 2834 //------------------------------add_offset-------------------------------------
kvn@306 2835 const TypePtr *TypeOopPtr::add_offset( intptr_t offset ) const {
kvn@992 2836 return make( _ptr, xadd_offset(offset), _instance_id);
duke@0 2837 }
duke@0 2838
kvn@223 2839 //------------------------------meet_instance_id--------------------------------
kvn@223 2840 int TypeOopPtr::meet_instance_id( int instance_id ) const {
kvn@223 2841 // Either is 'TOP' instance? Return the other instance!
kvn@223 2842 if( _instance_id == InstanceTop ) return instance_id;
kvn@223 2843 if( instance_id == InstanceTop ) return _instance_id;
kvn@223 2844 // If either is different, return 'BOTTOM' instance
kvn@223 2845 if( _instance_id != instance_id ) return InstanceBot;
kvn@223 2846 return _instance_id;
duke@0 2847 }
duke@0 2848
kvn@223 2849 //------------------------------dual_instance_id--------------------------------
kvn@223 2850 int TypeOopPtr::dual_instance_id( ) const {
kvn@223 2851 if( _instance_id == InstanceTop ) return InstanceBot; // Map TOP into BOTTOM
kvn@223 2852 if( _instance_id == InstanceBot ) return InstanceTop; // Map BOTTOM into TOP
kvn@223 2853 return _instance_id; // Map everything else into self
kvn@223 2854 }
kvn@223 2855
kvn@223 2856
duke@0 2857 //=============================================================================
duke@0 2858 // Convenience common pre-built types.
duke@0 2859 const TypeInstPtr *TypeInstPtr::NOTNULL;
duke@0 2860 const TypeInstPtr *TypeInstPtr::BOTTOM;
duke@0 2861 const TypeInstPtr *TypeInstPtr::MIRROR;
duke@0 2862 const TypeInstPtr *TypeInstPtr::MARK;
duke@0 2863 const TypeInstPtr *TypeInstPtr::KLASS;
duke@0 2864
duke@0 2865 //------------------------------TypeInstPtr-------------------------------------
duke@0 2866 TypeInstPtr::TypeInstPtr(PTR ptr, ciKlass* k, bool xk, ciObject* o, int off, int instance_id)
duke@0 2867 : TypeOopPtr(InstPtr, ptr, k, xk, o, off, instance_id), _name(k->name()) {
duke@0 2868 assert(k != NULL &&
duke@0 2869 (k->is_loaded() || o == NULL),
duke@0 2870 "cannot have constants with non-loaded klass");
duke@0 2871 };
duke@0 2872
duke@0 2873 //------------------------------make-------------------------------------------
duke@0 2874 const TypeInstPtr *TypeInstPtr::make(PTR ptr,
duke@0 2875 ciKlass* k,
duke@0 2876 bool xk,
duke@0 2877 ciObject* o,
duke@0 2878 int offset,
duke@0 2879 int instance_id) {
coleenp@3602 2880 assert( !k->is_loaded() || k->is_instance_klass(), "Must be for instance");
duke@0 2881 // Either const_oop() is NULL or else ptr is Constant
duke@0 2882 assert( (!o && ptr != Constant) || (o && ptr == Constant),
duke@0 2883 "constant pointers must have a value supplied" );
duke@0 2884 // Ptr is never Null
duke@0 2885 assert( ptr != Null, "NULL pointers are not typed" );
duke@0 2886
kvn@247 2887 assert(instance_id <= 0 || xk || !UseExactTypes, "instances are always exactly typed");
duke@0 2888 if (!UseExactTypes) xk = false;
duke@0 2889 if (ptr == Constant) {
duke@0 2890 // Note: This case includes meta-object constants, such as methods.
duke@0 2891 xk = true;
duke@0 2892 } else if (k->is_loaded()) {
duke@0 2893 ciInstanceKlass* ik = k->as_instance_klass();
duke@0 2894 if (!xk && ik->is_final()) xk = true; // no inexact final klass
duke@0 2895 if (xk && ik->is_interface()) xk = false; // no exact interface
duke@0 2896 }
duke@0 2897
duke@0 2898 // Now hash this baby
duke@0 2899 TypeInstPtr *result =
duke@0 2900 (TypeInstPtr*)(new TypeInstPtr(ptr, k, xk, o ,offset, instance_id))->hashcons();
duke@0 2901
duke@0 2902 return result;
duke@0 2903 }
duke@0 2904
kvn@4675 2905 /**
kvn@4675 2906 * Create constant type for a constant boxed value
kvn@4675 2907 */
kvn@4675 2908 const Type* TypeInstPtr::get_const_boxed_value() const {
kvn@4675 2909 assert(is_ptr_to_boxed_value(), "should be called only for boxed value");
kvn@4675 2910 assert((const_oop() != NULL), "should be called only for constant object");
kvn@4675 2911 ciConstant constant = const_oop()->as_instance()->field_value_by_offset(offset());
kvn@4675 2912 BasicType bt = constant.basic_type();
kvn@4675 2913 switch (bt) {
kvn@4675 2914 case T_BOOLEAN: return TypeInt::make(constant.as_boolean());
kvn@4675 2915 case T_INT: return TypeInt::make(constant.as_int());
kvn@4675 2916 case T_CHAR: return TypeInt::make(constant.as_char());
kvn@4675 2917 case T_BYTE: return TypeInt::make(constant.as_byte());
kvn@4675 2918 case T_SHORT: return TypeInt::make(constant.as_short());
kvn@4675 2919 case T_FLOAT: return TypeF::make(constant.as_float());
kvn@4675 2920 case T_DOUBLE: return TypeD::make(constant.as_double());
kvn@4675 2921 case T_LONG: return TypeLong::make(constant.as_long());
kvn@4675 2922 default: break;
kvn@4675 2923 }
kvn@4675 2924 fatal(err_msg_res("Invalid boxed value type '%s'", type2name(bt)));
kvn@4675 2925 return NULL;
kvn@4675 2926 }
duke@0 2927
duke@0 2928 //------------------------------cast_to_ptr_type-------------------------------
duke@0 2929 const Type *TypeInstPtr::cast_to_ptr_type(PTR ptr) const {
duke@0 2930 if( ptr == _ptr ) return this;
duke@0 2931 // Reconstruct _sig info here since not a problem with later lazy
duke@0 2932 // construction, _sig will show up on demand.
kvn@223 2933 return make(ptr, klass(), klass_is_exact(), const_oop(), _offset, _instance_id);
duke@0 2934 }
duke@0 2935
duke@0 2936
duke@0 2937 //-----------------------------cast_to_exactness-------------------------------
duke@0 2938 const Type *TypeInstPtr::cast_to_exactness(bool klass_is_exact) const {
duke@0 2939 if( klass_is_exact == _klass_is_exact ) return this;
duke@0 2940 if (!UseExactTypes) return this;
duke@0 2941 if (!_klass->is_loaded()) return this;
duke@0 2942 ciInstanceKlass* ik = _klass->as_instance_klass();
duke@0 2943 if( (ik->is_final() || _const_oop) ) return this; // cannot clear xk
duke@0 2944 if( ik->is_interface() ) return this; // cannot set xk
duke@0 2945 return make(ptr(), klass(), klass_is_exact, const_oop(), _offset, _instance_id);
duke@0 2946 }
duke@0 2947
kvn@247 2948 //-----------------------------cast_to_instance_id----------------------------
kvn@223 2949 const TypeOopPtr *TypeInstPtr::cast_to_instance_id(int instance_id) const {
kvn@223 2950 if( instance_id == _instance_id ) return this;
kvn@247 2951 return make(_ptr, klass(), _klass_is_exact, const_oop(), _offset, instance_id);
duke@0 2952 }
duke@0 2953
duke@0 2954 //------------------------------xmeet_unloaded---------------------------------
duke@0 2955 // Compute the MEET of two InstPtrs when at least one is unloaded.
duke@0 2956 // Assume classes are different since called after check for same name/class-loader
duke@0 2957 const TypeInstPtr *TypeInstPtr::xmeet_unloaded(const TypeInstPtr *tinst) const {
duke@0 2958 int off = meet_offset(tinst->offset());
duke@0 2959 PTR ptr = meet_ptr(tinst->ptr());
kvn@992 2960 int instance_id = meet_instance_id(tinst->instance_id());
duke@0 2961
duke@0 2962 const TypeInstPtr *loaded = is_loaded() ? this : tinst;
duke@0 2963 const TypeInstPtr *unloaded = is_loaded() ? tinst : this;
duke@0 2964 if( loaded->klass()->equals(ciEnv::current()->Object_klass()) ) {
duke@0 2965 //
duke@0 2966 // Meet unloaded class with java/lang/Object
duke@0 2967 //
duke@0 2968 // Meet
duke@0 2969 // | Unloaded Class
duke@0 2970 // Object | TOP | AnyNull | Constant | NotNull | BOTTOM |
duke@0 2971 // ===================================================================
duke@0 2972 // TOP | ..........................Unloaded......................|
duke@0 2973 // AnyNull | U-AN |................Unloaded......................|
duke@0 2974 // Constant | ... O-NN .................................. | O-BOT |
duke@0 2975 // NotNull | ... O-NN .................................. | O-BOT |
duke@0 2976 // BOTTOM | ........................Object-BOTTOM ..................|
duke@0 2977 //
duke@0 2978 assert(loaded->ptr() != TypePtr::Null, "insanity check");
duke@0 2979 //
duke@0 2980 if( loaded->ptr() == TypePtr::TopPTR ) { return unloaded; }
kvn@992 2981 else if (loaded->ptr() == TypePtr::AnyNull) { return TypeInstPtr::make( ptr, unloaded->klass(), false, NULL, off, instance_id ); }
duke@0 2982 else if (loaded->ptr() == TypePtr::BotPTR ) { return TypeInstPtr::BOTTOM; }
duke@0 2983 else if (loaded->ptr() == TypePtr::Constant || loaded->ptr() == TypePtr::NotNull) {
duke@0 2984 if (unloaded->ptr() == TypePtr::BotPTR ) { return TypeInstPtr::BOTTOM; }
duke@0 2985 else { return TypeInstPtr::NOTNULL; }
duke@0 2986 }
duke@0 2987 else if( unloaded->ptr() == TypePtr::TopPTR ) { return unloaded; }
duke@0 2988
duke@0 2989 return unloaded->cast_to_ptr_type(TypePtr::AnyNull)->is_instptr();
duke@0 2990 }
duke@0 2991
duke@0 2992 // Both are unloaded, not the same class, not Object
duke@0 2993 // Or meet unloaded with a different loaded class, not java/lang/Object
duke@0 2994 if( ptr != TypePtr::BotPTR ) {
duke@0 2995 return TypeInstPtr::NOTNULL;
duke@0 2996 }
duke@0 2997 return TypeInstPtr::BOTTOM;
duke@0 2998 }
duke@0 2999
duke@0 3000
duke@0 3001 //------------------------------meet-------------------------------------------
duke@0 3002 // Compute the MEET of two types. It returns a new Type object.
duke@0 3003 const Type *TypeInstPtr::xmeet( const Type *t ) const {
duke@0 3004 // Perform a fast test for common case; meeting the same types together.
duke@0 3005 if( this == t ) return this; // Meeting same type-rep?
duke@0 3006
duke@0 3007 // Current "this->_base" is Pointer
duke@0 3008 switch (t->base()) { // switch on original type
duke@0 3009
duke@0 3010 case Int: // Mixing ints & oops happens when javac
duke@0 3011 case Long: // reuses local variables
duke@0 3012 case FloatTop:
duke@0 3013 case FloatCon:
duke@0 3014 case FloatBot:
duke@0 3015 case DoubleTop:
duke@0 3016 case DoubleCon:
duke@0 3017 case DoubleBot:
coleenp@113 3018 case NarrowOop:
roland@3724 3019 case NarrowKlass:
duke@0 3020 case Bottom: // Ye Olde Default
duke@0 3021 return Type::BOTTOM;
duke@0 3022 case Top:
duke@0 3023 return this;
duke@0 3024
duke@0 3025 default: // All else is a mistake
duke@0 3026 typerr(t);
duke@0 3027
coleenp@3602 3028 case MetadataPtr:
coleenp@3602 3029 case KlassPtr:
duke@0 3030 case RawPtr: return TypePtr::BOTTOM;
duke@0 3031
duke@0 3032 case AryPtr: { // All arrays inherit from Object class
duke@0 3033 const TypeAryPtr *tp = t->is_aryptr();
duke@0 3034 int offset = meet_offset(tp->offset());
duke@0 3035 PTR ptr = meet_ptr(tp->ptr());
kvn@223 3036 int instance_id = meet_instance_id(tp->instance_id());
duke@0 3037 switch (ptr) {
duke@0 3038 case TopPTR:
duke@0 3039 case AnyNull: // Fall 'down' to dual of object klass
duke@0 3040 if (klass()->equals(ciEnv::current()->Object_klass())) {
kvn@223 3041 return TypeAryPtr::make(ptr, tp->ary(), tp->klass(), tp->klass_is_exact(), offset, instance_id);
duke@0 3042 } else {
duke@0 3043 // cannot subclass, so the meet has to fall badly below the centerline
duke@0 3044 ptr = NotNull;
kvn@223 3045 instance_id = InstanceBot;
kvn@223 3046 return TypeInstPtr::make( ptr, ciEnv::current()->Object_klass(), false, NULL, offset, instance_id);
duke@0 3047 }
duke@0 3048 case Constant:
duke@0 3049 case NotNull:
duke@0 3050 case BotPTR: // Fall down to object klass
duke@0 3051 // LCA is object_klass, but if we subclass from the top we can do better
duke@0 3052 if( above_centerline(_ptr) ) { // if( _ptr == TopPTR || _ptr == AnyNull )
duke@0 3053 // If 'this' (InstPtr) is above the centerline and it is Object class
twisti@605 3054 // then we can subclass in the Java class hierarchy.
duke@0 3055 if (klass()->equals(ciEnv::current()->Object_klass())) {
duke@0 3056 // that is, tp's array type is a subtype of my klass
kvn@1279 3057 return TypeAryPtr::make(ptr, (ptr == Constant ? tp->const_oop() : NULL),
kvn@1279 3058 tp->ary(), tp->klass(), tp->klass_is_exact(), offset, instance_id);
duke@0 3059 }
duke@0 3060 }
duke@0 3061 // The other case cannot happen, since I cannot be a subtype of an array.
duke@0 3062 // The meet falls down to Object class below centerline.
duke@0 3063 if( ptr == Constant )
duke@0 3064 ptr = NotNull;
kvn@223 3065 instance_id = InstanceBot;
kvn@223 3066 return make( ptr, ciEnv::current()->Object_klass(), false, NULL, offset, instance_id );
duke@0 3067 default: typerr(t);
duke@0 3068 }
duke@0 3069 }
duke@0 3070
duke@0 3071 case OopPtr: { // Meeting to OopPtrs
duke@0 3072 // Found a OopPtr type vs self-InstPtr type
kvn@958 3073 const TypeOopPtr *tp = t->is_oopptr();
duke@0 3074 int offset = meet_offset(tp->offset());
duke@0 3075 PTR ptr = meet_ptr(tp->ptr());
duke@0 3076 switch (tp->ptr()) {
duke@0 3077 case TopPTR:
kvn@223 3078 case AnyNull: {
kvn@223 3079 int instance_id = meet_instance_id(InstanceTop);
duke@0 3080 return make(ptr, klass(), klass_is_exact(),
kvn@223 3081 (ptr == Constant ? const_oop() : NULL), offset, instance_id);
kvn@223 3082 }
duke@0 3083 case NotNull:
kvn@958 3084 case BotPTR: {
kvn@958 3085 int instance_id = meet_instance_id(tp->instance_id());
kvn@958 3086 return TypeOopPtr::make(ptr, offset, instance_id);
kvn@958 3087 }
duke@0 3088 default: typerr(t);
duke@0 3089 }
duke@0 3090 }
duke@0 3091
duke@0 3092 case AnyPtr: { // Meeting to AnyPtrs
duke@0 3093 // Found an AnyPtr type vs self-InstPtr type
duke@0 3094 const TypePtr *tp = t->is_ptr();
duke@0 3095 int offset = meet_offset(tp->offset());
duke@0 3096 PTR ptr = meet_ptr(tp->ptr());
duke@0 3097 switch (tp->ptr()) {
duke@0 3098 case Null:
duke@0 3099 if( ptr == Null ) return TypePtr::make( AnyPtr, ptr, offset );
kvn@223 3100 // else fall through to AnyNull
duke@0 3101 case TopPTR:
kvn@223 3102 case AnyNull: {
kvn@223 3103 int instance_id = meet_instance_id(InstanceTop);
duke@0 3104 return make( ptr, klass(), klass_is_exact(),
kvn@223 3105 (ptr == Constant ? const_oop() : NULL), offset, instance_id);
kvn@223 3106 }
duke@0 3107 case NotNull:
duke@0 3108 case BotPTR:
duke@0 3109 return TypePtr::make( AnyPtr, ptr, offset );
duke@0 3110 default: typerr(t);
duke@0 3111 }
duke@0 3112 }
duke@0 3113
duke@0 3114 /*
duke@0 3115 A-top }
duke@0 3116 / | \ } Tops
duke@0 3117 B-top A-any C-top }
duke@0 3118 | / | \ | } Any-nulls
duke@0 3119 B-any | C-any }
duke@0 3120 | | |
duke@0 3121 B-con A-con C-con } constants; not comparable across classes
duke@0 3122 | | |
duke@0 3123 B-not | C-not }
duke@0 3124 | \ | / | } not-nulls
duke@0 3125 B-bot A-not C-bot }
duke@0 3126 \ | / } Bottoms
duke@0 3127 A-bot }
duke@0 3128 */
duke@0 3129
duke@0 3130 case InstPtr: { // Meeting 2 Oops?
duke@0 3131 // Found an InstPtr sub-type vs self-InstPtr type
duke@0 3132 const TypeInstPtr *tinst = t->is_instptr();
duke@0 3133 int off = meet_offset( tinst->offset() );
duke@0 3134 PTR ptr = meet_ptr( tinst->ptr() );
kvn@223 3135 int instance_id = meet_instance_id(tinst->instance_id());
duke@0 3136
duke@0 3137 // Check for easy case; klasses are equal (and perhaps not loaded!)
duke@0 3138 // If we have constants, then we created oops so classes are loaded
duke@0 3139 // and we can handle the constants further down. This case handles
duke@0 3140 // both-not-loaded or both-loaded classes
duke@0 3141 if (ptr != Constant && klass()->equals(tinst->klass()) && klass_is_exact() == tinst->klass_is_exact()) {
duke@0 3142 return make( ptr, klass(), klass_is_exact(), NULL, off, instance_id );
duke@0 3143 }
duke@0 3144
duke@0 3145 // Classes require inspection in the Java klass hierarchy. Must be loaded.
duke@0 3146 ciKlass* tinst_klass = tinst->klass();
duke@0 3147 ciKlass* this_klass = this->klass();
duke@0 3148 bool tinst_xk = tinst->klass_is_exact();
duke@0 3149 bool this_xk = this->klass_is_exact();
duke@0 3150 if (!tinst_klass->is_loaded() || !this_klass->is_loaded() ) {
duke@0 3151 // One of these classes has not been loaded
duke@0 3152 const TypeInstPtr *unloaded_meet = xmeet_unloaded(tinst);
duke@0 3153 #ifndef PRODUCT
duke@0 3154 if( PrintOpto && Verbose ) {
duke@0 3155 tty->print("meet of unloaded classes resulted in: "); unloaded_meet->dump(); tty->cr();
duke@0 3156 tty->print(" this == "); this->dump(); tty->cr();
duke@0 3157 tty->print(" tinst == "); tinst->dump(); tty->cr();
duke@0 3158 }
duke@0 3159 #endif
duke@0 3160 return unloaded_meet;
duke@0 3161 }
duke@0 3162
duke@0 3163 // Handle mixing oops and interfaces first.
duke@0 3164 if( this_klass->is_interface() && !tinst_klass->is_interface() ) {
duke@0 3165 ciKlass *tmp = tinst_klass; // Swap interface around
duke@0 3166 tinst_klass = this_klass;
duke@0 3167 this_klass = tmp;
duke@0 3168 bool tmp2 = tinst_xk;
duke@0 3169 tinst_xk = this_xk;
duke@0 3170 this_xk = tmp2;
duke@0 3171 }
duke@0 3172 if (tinst_klass->is_interface() &&
duke@0 3173 !(this_klass->is_interface() ||
duke@0 3174 // Treat java/lang/Object as an honorary interface,
duke@0 3175 // because we need a bottom for the interface hierarchy.
duke@0 3176 this_klass == ciEnv::current()->Object_klass())) {
duke@0 3177 // Oop meets interface!
duke@0 3178
duke@0 3179 // See if the oop subtypes (implements) interface.
duke@0 3180 ciKlass *k;
duke@0 3181 bool xk;
duke@0 3182 if( this_klass->is_subtype_of( tinst_klass ) ) {
duke@0 3183 // Oop indeed subtypes. Now keep oop or interface depending
duke@0 3184 // on whether we are both above the centerline or either is
duke@0 3185 // below the centerline. If we are on the centerline
duke@0 3186 // (e.g., Constant vs. AnyNull interface), use the constant.
duke@0 3187 k = below_centerline(ptr) ? tinst_klass : this_klass;
duke@0 3188 // If we are keeping this_klass, keep its exactness too.
duke@0 3189 xk = below_centerline(ptr) ? tinst_xk : this_xk;
duke@0 3190 } else { // Does not implement, fall to Object
duke@0 3191 // Oop does not implement interface, so mixing falls to Object
duke@0 3192 // just like the verifier does (if both are above the
duke@0 3193 // centerline fall to interface)
duke@0 3194 k = above_centerline(ptr) ? tinst_klass : ciEnv::current()->Object_klass();
duke@0 3195 xk = above_centerline(ptr) ? tinst_xk : false;
duke@0 3196 // Watch out for Constant vs. AnyNull interface.
duke@0 3197 if (ptr == Constant) ptr = NotNull; // forget it was a constant
kvn@247 3198 instance_id = InstanceBot;
duke@0 3199 }
duke@0 3200 ciObject* o = NULL; // the Constant value, if any
duke@0 3201 if (ptr == Constant) {
duke@0 3202 // Find out which constant.
duke@0 3203 o = (this_klass == klass()) ? const_oop() : tinst->const_oop();
duke@0 3204 }
kvn@223 3205 return make( ptr, k, xk, o, off, instance_id );
duke@0 3206 }
duke@0 3207
duke@0 3208 // Either oop vs oop or interface vs interface or interface vs Object
duke@0 3209
duke@0 3210 // !!! Here's how the symmetry requirement breaks down into invariants:
duke@0 3211 // If we split one up & one down AND they subtype, take the down man.
duke@0 3212 // If we split one up & one down AND they do NOT subtype, "fall hard".
duke@0 3213 // If both are up and they subtype, take the subtype class.
duke@0 3214 // If both are up and they do NOT subtype, "fall hard".
duke@0 3215 // If both are down and they subtype, take the supertype class.
duke@0 3216 // If both are down and they do NOT subtype, "fall hard".
duke@0 3217 // Constants treated as down.
duke@0 3218
duke@0 3219 // Now, reorder the above list; observe that both-down+subtype is also
duke@0 3220 // "fall hard"; "fall hard" becomes the default case:
duke@0 3221 // If we split one up & one down AND they subtype, take the down man.
duke@0 3222 // If both are up and they subtype, take the subtype class.
duke@0 3223
duke@0 3224 // If both are down and they subtype, "fall hard".
duke@0 3225 // If both are down and they do NOT subtype, "fall hard".
duke@0 3226 // If both are up and they do NOT subtype, "fall hard".
duke@0 3227 // If we split one up & one down AND they do NOT subtype, "fall hard".
duke@0 3228
duke@0 3229 // If a proper subtype is exact, and we return it, we return it exactly.
duke@0 3230 // If a proper supertype is exact, there can be no subtyping relationship!
duke@0 3231 // If both types are equal to the subtype, exactness is and-ed below the
duke@0 3232 // centerline and or-ed above it. (N.B. Constants are always exact.)
duke@0 3233
duke@0 3234 // Check for subtyping:
duke@0 3235 ciKlass *subtype = NULL;
duke@0 3236 bool subtype_exact = false;
duke@0 3237 if( tinst_klass->equals(this_klass) ) {
duke@0 3238 subtype = this_klass;
duke@0 3239 subtype_exact = below_centerline(ptr) ? (this_xk & tinst_xk) : (this_xk | tinst_xk);
duke@0 3240 } else if( !tinst_xk && this_klass->is_subtype_of( tinst_klass ) ) {
duke@0 3241 subtype = this_klass; // Pick subtyping class
duke@0 3242 subtype_exact = this_xk;
duke@0 3243 } else if( !this_xk && tinst_klass->is_subtype_of( this_klass ) ) {
duke@0 3244 subtype = tinst_klass; // Pick subtyping class
duke@0 3245 subtype_exact = tinst_xk;
duke@0 3246 }
duke@0 3247
duke@0 3248 if( subtype ) {
duke@0 3249 if( above_centerline(ptr) ) { // both are up?
duke@0 3250 this_klass = tinst_klass = subtype;
duke@0 3251 this_xk = tinst_xk = subtype_exact;
duke@0 3252 } else if( above_centerline(this ->_ptr) && !above_centerline(tinst->_ptr) ) {
duke@0 3253 this_klass = tinst_klass; // tinst is down; keep down man
duke@0 3254 this_xk = tinst_xk;
duke@0 3255 } else if( above_centerline(tinst->_ptr) && !above_centerline(this ->_ptr) ) {
duke@0 3256 tinst_klass = this_klass; // this is down; keep down man
duke@0 3257 tinst_xk = this_xk;
duke@0 3258 } else {
duke@0 3259 this_xk = subtype_exact; // either they are equal, or we'll do an LCA
duke@0 3260 }
duke@0 3261 }
duke@0 3262
duke@0 3263 // Check for classes now being equal
duke@0 3264 if (tinst_klass->equals(this_klass)) {
duke@0 3265 // If the klasses are equal, the constants may still differ. Fall to
duke@0 3266 // NotNull if they do (neither constant is NULL; that is a special case
duke@0 3267 // handled elsewhere).
duke@0 3268 ciObject* o = NULL; // Assume not constant when done
duke@0 3269 ciObject* this_oop = const_oop();
duke@0 3270 ciObject* tinst_oop = tinst->const_oop();
duke@0 3271 if( ptr == Constant ) {
duke@0 3272 if (this_oop != NULL && tinst_oop != NULL &&
duke@0 3273 this_oop->equals(tinst_oop) )
duke@0 3274 o = this_oop;
duke@0 3275 else if (above_centerline(this ->_ptr))
duke@0 3276 o = tinst_oop;
duke@0 3277 else if (above_centerline(tinst ->_ptr))
duke@0 3278 o = this_oop;
duke@0 3279 else
duke@0 3280 ptr = NotNull;
duke@0 3281 }
duke@0 3282 return make( ptr, this_klass, this_xk, o, off, instance_id );
duke@0 3283 } // Else classes are not equal
duke@0 3284
duke@0 3285 // Since klasses are different, we require a LCA in the Java
duke@0 3286 // class hierarchy - which means we have to fall to at least NotNull.
duke@0 3287 if( ptr == TopPTR || ptr == AnyNull || ptr == Constant )
duke@0 3288 ptr = NotNull;
kvn@247 3289 instance_id = InstanceBot;
duke@0 3290
duke@0 3291 // Now we find the LCA of Java classes
duke@0 3292 ciKlass* k = this_klass->least_common_ancestor(tinst_klass);
kvn@223 3293 return make( ptr, k, false, NULL, off, instance_id );
duke@0 3294 } // End of case InstPtr
duke@0 3295
duke@0 3296 } // End of switch
duke@0 3297 return this; // Return the double constant
duke@0 3298 }
duke@0 3299
duke@0 3300
duke@0 3301 //------------------------java_mirror_type--------------------------------------
duke@0 3302 ciType* TypeInstPtr::java_mirror_type() const {
duke@0 3303 // must be a singleton type
duke@0 3304 if( const_oop() == NULL ) return NULL;
duke@0 3305
duke@0 3306 // must be of type java.lang.Class
duke@0 3307 if( klass() != ciEnv::current()->Class_klass() ) return NULL;
duke@0 3308
duke@0 3309 return const_oop()->as_instance()->java_mirror_type();
duke@0 3310 }
duke@0 3311
duke@0 3312
duke@0 3313 //------------------------------xdual------------------------------------------
duke@0 3314 // Dual: do NOT dual on klasses. This means I do NOT understand the Java
twisti@605 3315 // inheritance mechanism.
duke@0 3316 const Type *TypeInstPtr::xdual() const {
kvn@223 3317 return new TypeInstPtr( dual_ptr(), klass(), klass_is_exact(), const_oop(), dual_offset(), dual_instance_id() );
duke@0 3318 }
duke@0 3319
duke@0 3320 //------------------------------eq---------------------------------------------
duke@0 3321 // Structural equality check for Type representations
duke@0 3322 bool TypeInstPtr::eq( const Type *t ) const {
duke@0 3323 const TypeInstPtr *p = t->is_instptr();
duke@0 3324 return
duke@0 3325 klass()->equals(p->klass()) &&
duke@0 3326 TypeOopPtr::eq(p); // Check sub-type stuff
duke@0 3327 }
duke@0 3328
duke@0 3329 //------------------------------hash-------------------------------------------
duke@0 3330 // Type-specific hashing function.
duke@0 3331 int TypeInstPtr::hash(void) const {
duke@0 3332 int hash = klass()->hash() + TypeOopPtr::hash();
duke@0 3333 return hash;
duke@0 3334 }
duke@0 3335
duke@0 3336 //------------------------------dump2------------------------------------------
duke@0 3337 // Dump oop Type
duke@0 3338 #ifndef PRODUCT
duke@0 3339 void TypeInstPtr::dump2( Dict &d, uint depth, outputStream *st ) const {
duke@0 3340 // Print the name of the klass.
duke@0 3341 klass()->print_name_on(st);
duke@0 3342
duke@0 3343 switch( _ptr ) {
duke@0 3344 case Constant:
duke@0 3345 // TO DO: Make CI print the hex address of the underlying oop.
duke@0 3346 if (WizardMode || Verbose) {
duke@0 3347 const_oop()->print_oop(st);
duke@0 3348 }
duke@0 3349 case BotPTR:
duke@0 3350 if (!WizardMode && !Verbose) {
duke@0 3351 if( _klass_is_exact ) st->print(":exact");
duke@0 3352 break;
duke@0 3353 }
duke@0 3354 case TopPTR:
duke@0 3355 case AnyNull:
duke@0 3356 case NotNull:
duke@0 3357 st->print(":%s", ptr_msg[_ptr]);
duke@0 3358 if( _klass_is_exact ) st->print(":exact");
duke@0 3359 break;
duke@0 3360 }
duke@0 3361
duke@0 3362 if( _offset ) { // Dump offset, if any
duke@0 3363 if( _offset == OffsetBot ) st->print("+any");
duke@0 3364 else if( _offset == OffsetTop ) st->print("+unknown");
duke@0 3365 else st->print("+%d", _offset);
duke@0 3366 }
duke@0 3367
duke@0 3368 st->print(" *");
kvn@223 3369 if (_instance_id == InstanceTop)
kvn@223 3370 st->print(",iid=top");
kvn@223 3371 else if (_instance_id != InstanceBot)
duke@0 3372 st->print(",iid=%d",_instance_id);
duke@0 3373 }
duke@0 3374 #endif
duke@0 3375
duke@0 3376 //------------------------------add_offset-------------------------------------
kvn@306 3377 const TypePtr *TypeInstPtr::add_offset( intptr_t offset ) const {
duke@0 3378 return make( _ptr, klass(), klass_is_exact(), const_oop(), xadd_offset(offset), _instance_id );
duke@0 3379 }
duke@0 3380
duke@0 3381 //=============================================================================
duke@0 3382 // Convenience common pre-built types.
duke@0 3383 const TypeAryPtr *TypeAryPtr::RANGE;
duke@0 3384 const TypeAryPtr *TypeAryPtr::OOPS;
kvn@163 3385 const TypeAryPtr *TypeAryPtr::NARROWOOPS;
duke@0 3386 const TypeAryPtr *TypeAryPtr::BYTES;
duke@0 3387 const TypeAryPtr *TypeAryPtr::SHORTS;
duke@0 3388 const TypeAryPtr *TypeAryPtr::CHARS;
duke@0 3389 const TypeAryPtr *TypeAryPtr::INTS;
duke@0 3390 const TypeAryPtr *TypeAryPtr::LONGS;
duke@0 3391 const TypeAryPtr *TypeAryPtr::FLOATS;
duke@0 3392 const TypeAryPtr *TypeAryPtr::DOUBLES;
duke@0 3393
duke@0 3394 //------------------------------make-------------------------------------------
duke@0 3395 const TypeAryPtr *TypeAryPtr::make( PTR ptr, const TypeAry *ary, ciKlass* k, bool xk, int offset, int instance_id ) {
duke@0 3396 assert(!(k == NULL && ary->_elem->isa_int()),
duke@0 3397 "integral arrays must be pre-equipped with a class");
duke@0 3398 if (!xk) xk = ary->ary_must_be_exact();
kvn@247 3399 assert(instance_id <= 0 || xk || !UseExactTypes, "instances are always exactly typed");
duke@0 3400 if (!UseExactTypes) xk = (ptr == Constant);
kvn@4675 3401 return (TypeAryPtr*)(new TypeAryPtr(ptr, NULL, ary, k, xk, offset, instance_id, false))->hashcons();
duke@0 3402 }
duke@0 3403
duke@0 3404 //------------------------------make-------------------------------------------
kvn@4675 3405 const TypeAryPtr *TypeAryPtr::make( PTR ptr, ciObject* o, const TypeAry *ary, ciKlass* k, bool xk, int offset, int instance_id, bool is_autobox_cache) {
duke@0 3406 assert(!(k == NULL && ary->_elem->isa_int()),
duke@0 3407 "integral arrays must be pre-equipped with a class");
duke@0 3408 assert( (ptr==Constant && o) || (ptr!=Constant && !o), "" );
duke@0 3409 if (!xk) xk = (o != NULL) || ary->ary_must_be_exact();
kvn@247 3410 assert(instance_id <= 0 || xk || !UseExactTypes, "instances are always exactly typed");
duke@0 3411 if (!UseExactTypes) xk = (ptr == Constant);
kvn@4675 3412 return (TypeAryPtr*)(new TypeAryPtr(ptr, o, ary, k, xk, offset, instance_id, is_autobox_cache))->hashcons();
duke@0 3413 }
duke@0 3414
duke@0 3415 //------------------------------cast_to_ptr_type-------------------------------
duke@0 3416 const Type *TypeAryPtr::cast_to_ptr_type(PTR ptr) const {
duke@0 3417 if( ptr == _ptr ) return this;
kvn@223 3418 return make(ptr, const_oop(), _ary, klass(), klass_is_exact(), _offset, _instance_id);
duke@0 3419 }
duke@0 3420
duke@0 3421
duke@0 3422 //-----------------------------cast_to_exactness-------------------------------
duke@0 3423 const Type *TypeAryPtr::cast_to_exactness(bool klass_is_exact) const {
duke@0 3424 if( klass_is_exact == _klass_is_exact ) return this;
duke@0 3425 if (!UseExactTypes) return this;
duke@0 3426 if (_ary->ary_must_be_exact()) return this; // cannot clear xk
duke@0 3427 return make(ptr(), const_oop(), _ary, klass(), klass_is_exact, _offset, _instance_id);
duke@0 3428 }
duke@0 3429
kvn@247 3430 //-----------------------------cast_to_instance_id----------------------------
kvn@223 3431 const TypeOopPtr *TypeAryPtr::cast_to_instance_id(int instance_id) const {
kvn@223 3432 if( instance_id == _instance_id ) return this;
kvn@247 3433 return make(_ptr, const_oop(), _ary, klass(), _klass_is_exact, _offset, instance_id);
duke@0 3434 }
duke@0 3435
duke@0 3436 //-----------------------------narrow_size_type-------------------------------
duke@0 3437 // Local cache for arrayOopDesc::max_array_length(etype),
duke@0 3438 // which is kind of slow (and cached elsewhere by other users).
duke@0 3439 static jint max_array_length_cache[T_CONFLICT+1];
duke@0 3440 static jint max_array_length(BasicType etype) {
duke@0 3441 jint& cache = max_array_length_cache[etype];
duke@0 3442 jint res = cache;
duke@0 3443 if (res == 0) {
duke@0 3444 switch (etype) {
coleenp@113 3445 case T_NARROWOOP:
coleenp@113 3446 etype = T_OBJECT;
coleenp@113 3447 break;
roland@3724 3448 case T_NARROWKLASS:
duke@0 3449 case T_CONFLICT:
duke@0 3450 case T_ILLEGAL:
duke@0 3451 case T_VOID:
duke@0 3452 etype = T_BYTE; // will produce conservatively high value
duke@0 3453 }
duke@0 3454 cache = res = arrayOopDesc::max_array_length(etype);
duke@0 3455 }
duke@0 3456 return res;
duke@0 3457 }
duke@0 3458
duke@0 3459 // Narrow the given size type to the index range for the given array base type.
duke@0 3460 // Return NULL if the resulting int type becomes empty.
rasbold@366 3461 const TypeInt* TypeAryPtr::narrow_size_type(const TypeInt* size) const {
duke@0 3462 jint hi = size->_hi;
duke@0 3463 jint lo = size->_lo;
duke@0 3464 jint min_lo = 0;
rasbold@366 3465 jint max_hi = max_array_length(elem()->basic_type());
duke@0 3466 //if (index_not_size) --max_hi; // type of a valid array index, FTR
duke@0 3467 bool chg = false;
kvn@4675 3468 if (lo < min_lo) {
kvn@4675 3469 lo = min_lo;
kvn@4675 3470 if (size->is_con()) {
kvn@4675 3471 hi = lo;
kvn@4675 3472 }
kvn@4675 3473 chg = true;
kvn@4675 3474 }
kvn@4675 3475 if (hi > max_hi) {
kvn@4675 3476 hi = max_hi;
kvn@4675 3477 if (size->is_con()) {
kvn@4675 3478 lo = hi;
kvn@4675 3479 }
kvn@4675 3480 chg = true;
kvn@4675 3481 }
twisti@605 3482 // Negative length arrays will produce weird intermediate dead fast-path code
duke@0 3483 if (lo > hi)
rasbold@366 3484 return TypeInt::ZERO;
duke@0 3485 if (!chg)
duke@0 3486 return size;
duke@0 3487 return TypeInt::make(lo, hi, Type::WidenMin);
duke@0 3488 }
duke@0 3489
duke@0 3490 //-------------------------------cast_to_size----------------------------------
duke@0 3491 const TypeAryPtr* TypeAryPtr::cast_to_size(const TypeInt* new_size) const {
duke@0 3492 assert(new_size != NULL, "");
rasbold@366 3493 new_size = narrow_size_type(new_size);
duke@0 3494 if (new_size == size()) return this;
vlivanov@5223 3495 const TypeAry* new_ary = TypeAry::make(elem(), new_size, is_stable());
kvn@223 3496 return make(ptr(), const_oop(), new_ary, klass(), klass_is_exact(), _offset, _instance_id);
duke@0 3497 }
duke@0 3498
duke@0 3499
vlivanov@5223 3500 //------------------------------cast_to_stable---------------------------------
vlivanov@5223 3501 const TypeAryPtr* TypeAryPtr::cast_to_stable(bool stable, int stable_dimension) const {
vlivanov@5223 3502 if (stable_dimension <= 0 || (stable_dimension == 1 && stable == this->is_stable()))
vlivanov@5223 3503 return this;
vlivanov@5223 3504
vlivanov@5223 3505 const Type* elem = this->elem();
vlivanov@5223 3506 const TypePtr* elem_ptr = elem->make_ptr();
vlivanov@5223 3507
vlivanov@5223 3508 if (stable_dimension > 1 && elem_ptr != NULL && elem_ptr->isa_aryptr()) {
vlivanov@5223 3509 // If this is widened from a narrow oop, TypeAry::make will re-narrow it.
vlivanov@5223 3510 elem = elem_ptr = elem_ptr->is_aryptr()->cast_to_stable(stable, stable_dimension - 1);
vlivanov@5223 3511 }
vlivanov@5223 3512
vlivanov@5223 3513 const TypeAry* new_ary = TypeAry::make(elem, size(), stable);
vlivanov@5223 3514
vlivanov@5223 3515 return make(ptr(), const_oop(), new_ary, klass(), klass_is_exact(), _offset, _instance_id);
vlivanov@5223 3516 }
vlivanov@5223 3517
vlivanov@5223 3518 //-----------------------------stable_dimension--------------------------------
vlivanov@5223 3519 int TypeAryPtr::stable_dimension() const {
vlivanov@5223 3520 if (!is_stable()) return 0;
vlivanov@5223 3521 int dim = 1;
vlivanov@5223 3522 const TypePtr* elem_ptr = elem()->make_ptr();
vlivanov@5223 3523 if (elem_ptr != NULL && elem_ptr->isa_aryptr())
vlivanov@5223 3524 dim += elem_ptr->is_aryptr()->stable_dimension();
vlivanov@5223 3525 return dim;
vlivanov@5223 3526 }
vlivanov@5223 3527
duke@0 3528 //------------------------------eq---------------------------------------------
duke@0 3529 // Structural equality check for Type representations
duke@0 3530 bool TypeAryPtr::eq( const Type *t ) const {
duke@0 3531 const TypeAryPtr *p = t->is_aryptr();
duke@0 3532 return
duke@0 3533 _ary == p->_ary && // Check array
duke@0 3534 TypeOopPtr::eq(p); // Check sub-parts
duke@0 3535 }
duke@0 3536
duke@0 3537 //------------------------------hash-------------------------------------------
duke@0 3538 // Type-specific hashing function.
duke@0 3539 int TypeAryPtr::hash(void) const {
duke@0 3540 return (intptr_t)_ary + TypeOopPtr::hash();
duke@0 3541 }
duke@0 3542
duke@0 3543 //------------------------------meet-------------------------------------------
duke@0 3544 // Compute the MEET of two types. It returns a new Type object.
duke@0 3545 const Type *TypeAryPtr::xmeet( const Type *t ) const {
duke@0 3546 // Perform a fast test for common case; meeting the same types together.
duke@0 3547 if( this == t ) return this; // Meeting same type-rep?
duke@0 3548 // Current "this->_base" is Pointer
duke@0 3549 switch (t->base()) { // switch on original type
duke@0 3550
duke@0 3551 // Mixing ints & oops happens when javac reuses local variables
duke@0 3552 case Int:
duke@0 3553 case Long:
duke@0 3554 case FloatTop:
duke@0 3555 case FloatCon:
duke@0 3556 case FloatBot:
duke@0 3557 case DoubleTop:
duke@0 3558 case DoubleCon:
duke@0 3559 case DoubleBot:
coleenp@113 3560 case NarrowOop:
roland@3724 3561 case NarrowKlass:
duke@0 3562 case Bottom: // Ye Olde Default
duke@0 3563 return Type::BOTTOM;
duke@0 3564 case Top:
duke@0 3565 return this;
duke@0 3566
duke@0 3567 default: // All else is a mistake
duke@0 3568 typerr(t);
duke@0 3569
duke@0 3570 case OopPtr: { // Meeting to OopPtrs
duke@0 3571 // Found a OopPtr type vs self-AryPtr type
kvn@958 3572 const TypeOopPtr *tp = t->is_oopptr();
duke@0 3573 int offset = meet_offset(tp->offset());
duke@0 3574 PTR ptr = meet_ptr(tp->ptr());
duke@0 3575 switch (tp->ptr()) {
duke@0 3576 case TopPTR:
kvn@223 3577 case AnyNull: {
kvn@223 3578 int instance_id = meet_instance_id(InstanceTop);
kvn@223 3579 return make(ptr, (ptr == Constant ? const_oop() : NULL),
kvn@223 3580 _ary, _klass, _klass_is_exact, offset, instance_id);
kvn@223 3581 }
duke@0 3582 case BotPTR:
kvn@958 3583 case NotNull: {
kvn@958 3584 int instance_id = meet_instance_id(tp->instance_id());
kvn@958 3585 return TypeOopPtr::make(ptr, offset, instance_id);
kvn@958 3586 }
duke@0 3587 default: ShouldNotReachHere();
duke@0 3588 }
duke@0 3589 }
duke@0 3590
duke@0 3591 case AnyPtr: { // Meeting two AnyPtrs
duke@0 3592 // Found an AnyPtr type vs self-AryPtr type
duke@0 3593 const TypePtr *tp = t->is_ptr();
duke@0 3594 int offset = meet_offset(tp->offset());
duke@0 3595 PTR ptr = meet_ptr(tp->ptr());
duke@0 3596 switch (tp->ptr()) {
duke@0 3597 case TopPTR:
duke@0 3598 return this;
duke@0 3599 case BotPTR:
duke@0 3600 case NotNull:
duke@0 3601 return TypePtr::make(AnyPtr, ptr, offset);
duke@0 3602 case Null:
duke@0 3603 if( ptr == Null ) return TypePtr::make(AnyPtr, ptr, offset);
kvn@223 3604 // else fall through to AnyNull
kvn@223 3605 case AnyNull: {
kvn@223 3606 int instance_id = meet_instance_id(InstanceTop);
kvn@223 3607 return make( ptr, (ptr == Constant ? const_oop() : NULL),
kvn@223 3608 _ary, _klass, _klass_is_exact, offset, instance_id);
kvn@223 3609 }
duke@0 3610 default: ShouldNotReachHere();
duke@0 3611 }
duke@0 3612 }
duke@0 3613
coleenp@3602 3614 case MetadataPtr:
coleenp@3602 3615 case KlassPtr:
duke@0 3616 case RawPtr: return TypePtr::BOTTOM;
duke@0 3617
duke@0 3618 case AryPtr: { // Meeting 2 references?
duke@0 3619 const TypeAryPtr *tap = t->is_aryptr();
duke@0 3620 int off = meet_offset(tap->offset());
duke@0 3621 const TypeAry *tary = _ary->meet(tap->_ary)->is_ary();
duke@0 3622 PTR ptr = meet_ptr(tap->ptr());
kvn@223 3623 int instance_id = meet_instance_id(tap->instance_id());
duke@0 3624 ciKlass* lazy_klass = NULL;
duke@0 3625 if (tary->_elem->isa_int()) {
duke@0 3626 // Integral array element types have irrelevant lattice relations.
duke@0 3627 // It is the klass that determines array layout, not the element type.
duke@0 3628 if (_klass == NULL)
duke@0 3629 lazy_klass = tap->_klass;
duke@0 3630 else if (tap->_klass == NULL || tap->_klass == _klass) {
duke@0 3631 lazy_klass = _klass;
duke@0 3632 } else {
duke@0 3633 // Something like byte[int+] meets char[int+].
duke@0 3634 // This must fall to bottom, not (int[-128..65535])[int+].
kvn@247 3635 instance_id = InstanceBot;
vlivanov@5223 3636 tary = TypeAry::make(Type::BOTTOM, tary->_size, tary->_stable);
duke@0 3637 }
kvn@2198 3638 } else // Non integral arrays.
kvn@2198 3639 // Must fall to bottom if exact klasses in upper lattice
kvn@2198 3640 // are not equal or super klass is exact.
kvn@2198 3641 if ( above_centerline(ptr) && klass() != tap->klass() &&
kvn@2198 3642 // meet with top[] and bottom[] are processed further down:
kvn@2198 3643 tap ->_klass != NULL && this->_klass != NULL &&
kvn@2198 3644 // both are exact and not equal:
kvn@2198 3645 ((tap ->_klass_is_exact && this->_klass_is_exact) ||
kvn@2198 3646 // 'tap' is exact and super or unrelated:
kvn@2198 3647 (tap ->_klass_is_exact && !tap->klass()->is_subtype_of(klass())) ||
kvn@2198 3648 // 'this' is exact and super or unrelated:
kvn@2198 3649 (this->_klass_is_exact && !klass()->is_subtype_of(tap->klass())))) {
vlivanov@5223 3650 tary = TypeAry::make(Type::BOTTOM, tary->_size, tary->_stable);
kvn@2198 3651 return make( NotNull, NULL, tary, lazy_klass, false, off, InstanceBot );
duke@0 3652 }
kvn@2198 3653
kvn@1685 3654 bool xk = false;
duke@0 3655 switch (tap->ptr()) {
duke@0 3656 case AnyNull:
duke@0 3657 case TopPTR:
duke@0 3658 // Compute new klass on demand, do not use tap->_klass
duke@0 3659 xk = (tap->_klass_is_exact | this->_klass_is_exact);
kvn@223 3660 return make( ptr, const_oop(), tary, lazy_klass, xk, off, instance_id );
duke@0 3661 case Constant: {
duke@0 3662 ciObject* o = const_oop();
duke@0 3663 if( _ptr == Constant ) {
duke@0 3664 if( tap->const_oop() != NULL && !o->equals(tap->const_oop()) ) {
jrose@989 3665 xk = (klass() == tap->klass());
duke@0 3666 ptr = NotNull;
duke@0 3667 o = NULL;
kvn@247 3668 instance_id = InstanceBot;
jrose@989 3669 } else {
jrose@989 3670 xk = true;
duke@0 3671 }
duke@0 3672 } else if( above_centerline(_ptr) ) {
duke@0 3673 o = tap->const_oop();