src/share/vm/opto/type.cpp

Thu, 24 May 2018 17:06:56 +0800

author
aoqi
date
Thu, 24 May 2018 17:06:56 +0800
changeset 8604
04d83ba48607
parent 8424
2094cac55c59
parent 7994
04ff2f6cd0eb
child 9041
95a08233f46c
permissions
-rw-r--r--

Merge

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

mercurial