1 /*
   2  * Copyright (c) 1997, 2021, Oracle and/or its affiliates. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   5  * This code is free software; you can redistribute it and/or modify it
   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.
   8  *
   9  * This code is distributed in the hope that it will be useful, but WITHOUT
  10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  11  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  12  * version 2 for more details (a copy is included in the LICENSE file that
  13  * accompanied this code).
  14  *
  15  * You should have received a copy of the GNU General Public License version
  16  * 2 along with this work; if not, write to the Free Software Foundation,
  17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  18  *
  19  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  20  * or visit www.oracle.com if you need additional information or have any
  21  * questions.
  22  *
  23  */
  24 
  25 #include "precompiled.hpp"
  26 #include "ci/ciFlatArrayKlass.hpp"
  27 #include "ci/ciField.hpp"
  28 #include "ci/ciInlineKlass.hpp"
  29 #include "ci/ciMethodData.hpp"
  30 #include "ci/ciTypeFlow.hpp"
  31 #include "classfile/javaClasses.hpp"
  32 #include "classfile/symbolTable.hpp"
  33 #include "compiler/compileLog.hpp"
  34 #include "libadt/dict.hpp"
  35 #include "memory/oopFactory.hpp"
  36 #include "memory/resourceArea.hpp"
  37 #include "oops/instanceKlass.hpp"
  38 #include "oops/instanceMirrorKlass.hpp"
  39 #include "oops/objArrayKlass.hpp"
  40 #include "oops/typeArrayKlass.hpp"
  41 #include "opto/matcher.hpp"
  42 #include "opto/node.hpp"
  43 #include "opto/opcodes.hpp"
  44 #include "opto/type.hpp"
  45 #include "utilities/powerOfTwo.hpp"
  46 #include "utilities/stringUtils.hpp"
  47 
  48 // Portions of code courtesy of Clifford Click
  49 
  50 // Optimization - Graph Style
  51 
  52 // Dictionary of types shared among compilations.
  53 Dict* Type::_shared_type_dict = NULL;
  54 const Type::Offset Type::Offset::top(Type::OffsetTop);
  55 const Type::Offset Type::Offset::bottom(Type::OffsetBot);
  56 
  57 const Type::Offset Type::Offset::meet(const Type::Offset other) const {
  58   // Either is 'TOP' offset?  Return the other offset!
  59   int offset = other._offset;
  60   if (_offset == OffsetTop) return Offset(offset);
  61   if (offset == OffsetTop) return Offset(_offset);
  62   // If either is different, return 'BOTTOM' offset
  63   if (_offset != offset) return bottom;
  64   return Offset(_offset);
  65 }
  66 
  67 const Type::Offset Type::Offset::dual() const {
  68   if (_offset == OffsetTop) return bottom;// Map 'TOP' into 'BOTTOM'
  69   if (_offset == OffsetBot) return top;// Map 'BOTTOM' into 'TOP'
  70   return Offset(_offset);               // Map everything else into self
  71 }
  72 
  73 const Type::Offset Type::Offset::add(intptr_t offset) const {
  74   // Adding to 'TOP' offset?  Return 'TOP'!
  75   if (_offset == OffsetTop || offset == OffsetTop) return top;
  76   // Adding to 'BOTTOM' offset?  Return 'BOTTOM'!
  77   if (_offset == OffsetBot || offset == OffsetBot) return bottom;
  78   // Addition overflows or "accidentally" equals to OffsetTop? Return 'BOTTOM'!
  79   offset += (intptr_t)_offset;
  80   if (offset != (int)offset || offset == OffsetTop) return bottom;
  81 
  82   // assert( _offset >= 0 && _offset+offset >= 0, "" );
  83   // It is possible to construct a negative offset during PhaseCCP
  84 
  85   return Offset((int)offset);        // Sum valid offsets
  86 }
  87 
  88 void Type::Offset::dump2(outputStream *st) const {
  89   if (_offset == 0) {
  90     return;
  91   } else if (_offset == OffsetTop) {
  92     st->print("+top");
  93   }
  94   else if (_offset == OffsetBot) {
  95     st->print("+bot");
  96   } else if (_offset) {
  97     st->print("+%d", _offset);
  98   }
  99 }
 100 
 101 // Array which maps compiler types to Basic Types
 102 const Type::TypeInfo Type::_type_info[Type::lastype] = {
 103   { Bad,             T_ILLEGAL,    "bad",           false, Node::NotAMachineReg, relocInfo::none          },  // Bad
 104   { Control,         T_ILLEGAL,    "control",       false, 0,                    relocInfo::none          },  // Control
 105   { Bottom,          T_VOID,       "top",           false, 0,                    relocInfo::none          },  // Top
 106   { Bad,             T_INT,        "int:",          false, Op_RegI,              relocInfo::none          },  // Int
 107   { Bad,             T_LONG,       "long:",         false, Op_RegL,              relocInfo::none          },  // Long
 108   { Half,            T_VOID,       "half",          false, 0,                    relocInfo::none          },  // Half
 109   { Bad,             T_NARROWOOP,  "narrowoop:",    false, Op_RegN,              relocInfo::none          },  // NarrowOop
 110   { Bad,             T_NARROWKLASS,"narrowklass:",  false, Op_RegN,              relocInfo::none          },  // NarrowKlass
 111   { Bad,             T_ILLEGAL,    "tuple:",        false, Node::NotAMachineReg, relocInfo::none          },  // Tuple
 112   { Bad,             T_ARRAY,      "array:",        false, Node::NotAMachineReg, relocInfo::none          },  // Array
 113 
 114 #if defined(PPC64)
 115   { Bad,             T_ILLEGAL,    "vectormask:",   false, Op_RegVectMask,       relocInfo::none          },  // VectorMask.
 116   { Bad,             T_ILLEGAL,    "vectora:",      false, Op_VecA,              relocInfo::none          },  // VectorA.
 117   { Bad,             T_ILLEGAL,    "vectors:",      false, 0,                    relocInfo::none          },  // VectorS
 118   { Bad,             T_ILLEGAL,    "vectord:",      false, Op_RegL,              relocInfo::none          },  // VectorD
 119   { Bad,             T_ILLEGAL,    "vectorx:",      false, Op_VecX,              relocInfo::none          },  // VectorX
 120   { Bad,             T_ILLEGAL,    "vectory:",      false, 0,                    relocInfo::none          },  // VectorY
 121   { Bad,             T_ILLEGAL,    "vectorz:",      false, 0,                    relocInfo::none          },  // VectorZ
 122 #elif defined(S390)
 123   { Bad,             T_ILLEGAL,    "vectormask:",   false, Op_RegVectMask,       relocInfo::none          },  // VectorMask.
 124   { Bad,             T_ILLEGAL,    "vectora:",      false, Op_VecA,              relocInfo::none          },  // VectorA.
 125   { Bad,             T_ILLEGAL,    "vectors:",      false, 0,                    relocInfo::none          },  // VectorS
 126   { Bad,             T_ILLEGAL,    "vectord:",      false, Op_RegL,              relocInfo::none          },  // VectorD
 127   { Bad,             T_ILLEGAL,    "vectorx:",      false, 0,                    relocInfo::none          },  // VectorX
 128   { Bad,             T_ILLEGAL,    "vectory:",      false, 0,                    relocInfo::none          },  // VectorY
 129   { Bad,             T_ILLEGAL,    "vectorz:",      false, 0,                    relocInfo::none          },  // VectorZ
 130 #else // all other
 131   { Bad,             T_ILLEGAL,    "vectormask:",   false, Op_RegVectMask,       relocInfo::none          },  // VectorMask.
 132   { Bad,             T_ILLEGAL,    "vectora:",      false, Op_VecA,              relocInfo::none          },  // VectorA.
 133   { Bad,             T_ILLEGAL,    "vectors:",      false, Op_VecS,              relocInfo::none          },  // VectorS
 134   { Bad,             T_ILLEGAL,    "vectord:",      false, Op_VecD,              relocInfo::none          },  // VectorD
 135   { Bad,             T_ILLEGAL,    "vectorx:",      false, Op_VecX,              relocInfo::none          },  // VectorX
 136   { Bad,             T_ILLEGAL,    "vectory:",      false, Op_VecY,              relocInfo::none          },  // VectorY
 137   { Bad,             T_ILLEGAL,    "vectorz:",      false, Op_VecZ,              relocInfo::none          },  // VectorZ
 138 #endif
 139   { Bad,             T_INLINE_TYPE, "inline:",      false, Node::NotAMachineReg, relocInfo::none          },  // InlineType
 140   { Bad,             T_ADDRESS,    "anyptr:",       false, Op_RegP,              relocInfo::none          },  // AnyPtr
 141   { Bad,             T_ADDRESS,    "rawptr:",       false, Op_RegP,              relocInfo::none          },  // RawPtr
 142   { Bad,             T_OBJECT,     "oop:",          true,  Op_RegP,              relocInfo::oop_type      },  // OopPtr
 143   { Bad,             T_OBJECT,     "inst:",         true,  Op_RegP,              relocInfo::oop_type      },  // InstPtr
 144   { Bad,             T_OBJECT,     "ary:",          true,  Op_RegP,              relocInfo::oop_type      },  // AryPtr
 145   { Bad,             T_METADATA,   "metadata:",     false, Op_RegP,              relocInfo::metadata_type },  // MetadataPtr
 146   { Bad,             T_METADATA,   "klass:",        false, Op_RegP,              relocInfo::metadata_type },  // KlassPtr
 147   { Bad,             T_METADATA,   "instklass:",    false, Op_RegP,              relocInfo::metadata_type },  // InstKlassPtr
 148   { Bad,             T_METADATA,   "aryklass:",     false, Op_RegP,              relocInfo::metadata_type },  // AryKlassPtr
 149   { Bad,             T_OBJECT,     "func",          false, 0,                    relocInfo::none          },  // Function
 150   { Abio,            T_ILLEGAL,    "abIO",          false, 0,                    relocInfo::none          },  // Abio
 151   { Return_Address,  T_ADDRESS,    "return_address",false, Op_RegP,              relocInfo::none          },  // Return_Address
 152   { Memory,          T_ILLEGAL,    "memory",        false, 0,                    relocInfo::none          },  // Memory
 153   { FloatBot,        T_FLOAT,      "float_top",     false, Op_RegF,              relocInfo::none          },  // FloatTop
 154   { FloatCon,        T_FLOAT,      "ftcon:",        false, Op_RegF,              relocInfo::none          },  // FloatCon
 155   { FloatTop,        T_FLOAT,      "float",         false, Op_RegF,              relocInfo::none          },  // FloatBot
 156   { DoubleBot,       T_DOUBLE,     "double_top",    false, Op_RegD,              relocInfo::none          },  // DoubleTop
 157   { DoubleCon,       T_DOUBLE,     "dblcon:",       false, Op_RegD,              relocInfo::none          },  // DoubleCon
 158   { DoubleTop,       T_DOUBLE,     "double",        false, Op_RegD,              relocInfo::none          },  // DoubleBot
 159   { Top,             T_ILLEGAL,    "bottom",        false, 0,                    relocInfo::none          }   // Bottom
 160 };
 161 
 162 // Map ideal registers (machine types) to ideal types
 163 const Type *Type::mreg2type[_last_machine_leaf];
 164 
 165 // Map basic types to canonical Type* pointers.
 166 const Type* Type::     _const_basic_type[T_CONFLICT+1];
 167 
 168 // Map basic types to constant-zero Types.
 169 const Type* Type::            _zero_type[T_CONFLICT+1];
 170 
 171 // Map basic types to array-body alias types.
 172 const TypeAryPtr* TypeAryPtr::_array_body_type[T_CONFLICT+1];
 173 
 174 //=============================================================================
 175 // Convenience common pre-built types.
 176 const Type *Type::ABIO;         // State-of-machine only
 177 const Type *Type::BOTTOM;       // All values
 178 const Type *Type::CONTROL;      // Control only
 179 const Type *Type::DOUBLE;       // All doubles
 180 const Type *Type::FLOAT;        // All floats
 181 const Type *Type::HALF;         // Placeholder half of doublewide type
 182 const Type *Type::MEMORY;       // Abstract store only
 183 const Type *Type::RETURN_ADDRESS;
 184 const Type *Type::TOP;          // No values in set
 185 
 186 //------------------------------get_const_type---------------------------
 187 const Type* Type::get_const_type(ciType* type) {
 188   if (type == NULL) {
 189     return NULL;
 190   } else if (type->is_primitive_type()) {
 191     return get_const_basic_type(type->basic_type());
 192   } else {
 193     return TypeOopPtr::make_from_klass(type->as_klass());
 194   }
 195 }
 196 
 197 //---------------------------array_element_basic_type---------------------------------
 198 // Mapping to the array element's basic type.
 199 BasicType Type::array_element_basic_type() const {
 200   BasicType bt = basic_type();
 201   if (bt == T_INT) {
 202     if (this == TypeInt::INT)   return T_INT;
 203     if (this == TypeInt::CHAR)  return T_CHAR;
 204     if (this == TypeInt::BYTE)  return T_BYTE;
 205     if (this == TypeInt::BOOL)  return T_BOOLEAN;
 206     if (this == TypeInt::SHORT) return T_SHORT;
 207     return T_VOID;
 208   }
 209   return bt;
 210 }
 211 
 212 // For two instance arrays of same dimension, return the base element types.
 213 // Otherwise or if the arrays have different dimensions, return NULL.
 214 void Type::get_arrays_base_elements(const Type *a1, const Type *a2,
 215                                     const TypeInstPtr **e1, const TypeInstPtr **e2) {
 216 
 217   if (e1) *e1 = NULL;
 218   if (e2) *e2 = NULL;
 219   const TypeAryPtr* a1tap = (a1 == NULL) ? NULL : a1->isa_aryptr();
 220   const TypeAryPtr* a2tap = (a2 == NULL) ? NULL : a2->isa_aryptr();
 221 
 222   if (a1tap != NULL && a2tap != NULL) {
 223     // Handle multidimensional arrays
 224     const TypePtr* a1tp = a1tap->elem()->make_ptr();
 225     const TypePtr* a2tp = a2tap->elem()->make_ptr();
 226     while (a1tp && a1tp->isa_aryptr() && a2tp && a2tp->isa_aryptr()) {
 227       a1tap = a1tp->is_aryptr();
 228       a2tap = a2tp->is_aryptr();
 229       a1tp = a1tap->elem()->make_ptr();
 230       a2tp = a2tap->elem()->make_ptr();
 231     }
 232     if (a1tp && a1tp->isa_instptr() && a2tp && a2tp->isa_instptr()) {
 233       if (e1) *e1 = a1tp->is_instptr();
 234       if (e2) *e2 = a2tp->is_instptr();
 235     }
 236   }
 237 }
 238 
 239 //---------------------------get_typeflow_type---------------------------------
 240 // Import a type produced by ciTypeFlow.
 241 const Type* Type::get_typeflow_type(ciType* type) {
 242   switch (type->basic_type()) {
 243 
 244   case ciTypeFlow::StateVector::T_BOTTOM:
 245     assert(type == ciTypeFlow::StateVector::bottom_type(), "");
 246     return Type::BOTTOM;
 247 
 248   case ciTypeFlow::StateVector::T_TOP:
 249     assert(type == ciTypeFlow::StateVector::top_type(), "");
 250     return Type::TOP;
 251 
 252   case ciTypeFlow::StateVector::T_NULL:
 253     assert(type == ciTypeFlow::StateVector::null_type(), "");
 254     return TypePtr::NULL_PTR;
 255 
 256   case ciTypeFlow::StateVector::T_LONG2:
 257     // The ciTypeFlow pass pushes a long, then the half.
 258     // We do the same.
 259     assert(type == ciTypeFlow::StateVector::long2_type(), "");
 260     return TypeInt::TOP;
 261 
 262   case ciTypeFlow::StateVector::T_DOUBLE2:
 263     // The ciTypeFlow pass pushes double, then the half.
 264     // Our convention is the same.
 265     assert(type == ciTypeFlow::StateVector::double2_type(), "");
 266     return Type::TOP;
 267 
 268   case T_ADDRESS:
 269     assert(type->is_return_address(), "");
 270     return TypeRawPtr::make((address)(intptr_t)type->as_return_address()->bci());
 271 
 272   case T_INLINE_TYPE: {
 273     bool is_null_free = type->is_null_free();
 274     ciInlineKlass* vk = type->unwrap()->as_inline_klass();
 275     if (is_null_free) {
 276       return TypeInlineType::make(vk);
 277     } else {
 278       return TypeOopPtr::make_from_klass(vk)->join_speculative(is_null_free ? TypePtr::NOTNULL : TypePtr::BOTTOM);
 279     }
 280   }
 281 
 282   default:
 283     // make sure we did not mix up the cases:
 284     assert(type != ciTypeFlow::StateVector::bottom_type(), "");
 285     assert(type != ciTypeFlow::StateVector::top_type(), "");
 286     assert(type != ciTypeFlow::StateVector::null_type(), "");
 287     assert(type != ciTypeFlow::StateVector::long2_type(), "");
 288     assert(type != ciTypeFlow::StateVector::double2_type(), "");
 289     assert(!type->is_return_address(), "");
 290 
 291     return Type::get_const_type(type);
 292   }
 293 }
 294 
 295 
 296 //-----------------------make_from_constant------------------------------------
 297 const Type* Type::make_from_constant(ciConstant constant, bool require_constant,
 298                                      int stable_dimension, bool is_narrow_oop,
 299                                      bool is_autobox_cache) {
 300   switch (constant.basic_type()) {
 301     case T_BOOLEAN:  return TypeInt::make(constant.as_boolean());
 302     case T_CHAR:     return TypeInt::make(constant.as_char());
 303     case T_BYTE:     return TypeInt::make(constant.as_byte());
 304     case T_SHORT:    return TypeInt::make(constant.as_short());
 305     case T_INT:      return TypeInt::make(constant.as_int());
 306     case T_LONG:     return TypeLong::make(constant.as_long());
 307     case T_FLOAT:    return TypeF::make(constant.as_float());
 308     case T_DOUBLE:   return TypeD::make(constant.as_double());
 309     case T_ARRAY:
 310     case T_INLINE_TYPE:
 311     case T_OBJECT: {
 312         const Type* con_type = NULL;
 313         ciObject* oop_constant = constant.as_object();
 314         if (oop_constant->is_null_object()) {
 315           con_type = Type::get_zero_type(T_OBJECT);
 316         } else {
 317           guarantee(require_constant || oop_constant->should_be_constant(), "con_type must get computed");
 318           con_type = TypeOopPtr::make_from_constant(oop_constant, require_constant);
 319           if (Compile::current()->eliminate_boxing() && is_autobox_cache) {
 320             con_type = con_type->is_aryptr()->cast_to_autobox_cache();
 321           }
 322           if (stable_dimension > 0) {
 323             assert(FoldStableValues, "sanity");
 324             assert(!con_type->is_zero_type(), "default value for stable field");
 325             con_type = con_type->is_aryptr()->cast_to_stable(true, stable_dimension);
 326           }
 327         }
 328         if (is_narrow_oop) {
 329           con_type = con_type->make_narrowoop();
 330         }
 331         return con_type;
 332       }
 333     case T_ILLEGAL:
 334       // Invalid ciConstant returned due to OutOfMemoryError in the CI
 335       assert(Compile::current()->env()->failing(), "otherwise should not see this");
 336       return NULL;
 337     default:
 338       // Fall through to failure
 339       return NULL;
 340   }
 341 }
 342 
 343 static ciConstant check_mismatched_access(ciConstant con, BasicType loadbt, bool is_unsigned) {
 344   BasicType conbt = con.basic_type();
 345   switch (conbt) {
 346     case T_BOOLEAN: conbt = T_BYTE;   break;
 347     case T_ARRAY:   conbt = T_OBJECT; break;
 348     case T_INLINE_TYPE: conbt = T_OBJECT; break;
 349     default:                          break;
 350   }
 351   switch (loadbt) {
 352     case T_BOOLEAN:   loadbt = T_BYTE;   break;
 353     case T_NARROWOOP: loadbt = T_OBJECT; break;
 354     case T_ARRAY:     loadbt = T_OBJECT; break;
 355     case T_INLINE_TYPE: loadbt = T_OBJECT; break;
 356     case T_ADDRESS:   loadbt = T_OBJECT; break;
 357     default:                             break;
 358   }
 359   if (conbt == loadbt) {
 360     if (is_unsigned && conbt == T_BYTE) {
 361       // LoadB (T_BYTE) with a small mask (<=8-bit) is converted to LoadUB (T_BYTE).
 362       return ciConstant(T_INT, con.as_int() & 0xFF);
 363     } else {
 364       return con;
 365     }
 366   }
 367   if (conbt == T_SHORT && loadbt == T_CHAR) {
 368     // LoadS (T_SHORT) with a small mask (<=16-bit) is converted to LoadUS (T_CHAR).
 369     return ciConstant(T_INT, con.as_int() & 0xFFFF);
 370   }
 371   return ciConstant(); // T_ILLEGAL
 372 }
 373 
 374 // Try to constant-fold a stable array element.
 375 const Type* Type::make_constant_from_array_element(ciArray* array, int off, int stable_dimension,
 376                                                    BasicType loadbt, bool is_unsigned_load) {
 377   // Decode the results of GraphKit::array_element_address.
 378   ciConstant element_value = array->element_value_by_offset(off);
 379   if (element_value.basic_type() == T_ILLEGAL) {
 380     return NULL; // wrong offset
 381   }
 382   ciConstant con = check_mismatched_access(element_value, loadbt, is_unsigned_load);
 383 
 384   assert(con.basic_type() != T_ILLEGAL, "elembt=%s; loadbt=%s; unsigned=%d",
 385          type2name(element_value.basic_type()), type2name(loadbt), is_unsigned_load);
 386 
 387   if (con.is_valid() &&          // not a mismatched access
 388       !con.is_null_or_zero()) {  // not a default value
 389     bool is_narrow_oop = (loadbt == T_NARROWOOP);
 390     return Type::make_from_constant(con, /*require_constant=*/true, stable_dimension, is_narrow_oop, /*is_autobox_cache=*/false);
 391   }
 392   return NULL;
 393 }
 394 
 395 const Type* Type::make_constant_from_field(ciInstance* holder, int off, bool is_unsigned_load, BasicType loadbt) {
 396   ciField* field;
 397   ciType* type = holder->java_mirror_type();
 398   if (type != NULL && type->is_instance_klass() && off >= InstanceMirrorKlass::offset_of_static_fields()) {
 399     // Static field
 400     field = type->as_instance_klass()->get_field_by_offset(off, /*is_static=*/true);
 401   } else {
 402     // Instance field
 403     field = holder->klass()->as_instance_klass()->get_field_by_offset(off, /*is_static=*/false);
 404   }
 405   if (field == NULL) {
 406     return NULL; // Wrong offset
 407   }
 408   return Type::make_constant_from_field(field, holder, loadbt, is_unsigned_load);
 409 }
 410 
 411 const Type* Type::make_constant_from_field(ciField* field, ciInstance* holder,
 412                                            BasicType loadbt, bool is_unsigned_load) {
 413   if (!field->is_constant()) {
 414     return NULL; // Non-constant field
 415   }
 416   ciConstant field_value;
 417   if (field->is_static()) {
 418     // final static field
 419     field_value = field->constant_value();
 420   } else if (holder != NULL) {
 421     // final or stable non-static field
 422     // Treat final non-static fields of trusted classes (classes in
 423     // java.lang.invoke and sun.invoke packages and subpackages) as
 424     // compile time constants.
 425     field_value = field->constant_value_of(holder);
 426   }
 427   if (!field_value.is_valid()) {
 428     return NULL; // Not a constant
 429   }
 430 
 431   ciConstant con = check_mismatched_access(field_value, loadbt, is_unsigned_load);
 432 
 433   assert(con.is_valid(), "elembt=%s; loadbt=%s; unsigned=%d",
 434          type2name(field_value.basic_type()), type2name(loadbt), is_unsigned_load);
 435 
 436   bool is_stable_array = FoldStableValues && field->is_stable() && field->type()->is_array_klass();
 437   int stable_dimension = (is_stable_array ? field->type()->as_array_klass()->dimension() : 0);
 438   bool is_narrow_oop = (loadbt == T_NARROWOOP);
 439 
 440   const Type* con_type = make_from_constant(con, /*require_constant=*/ true,
 441                                             stable_dimension, is_narrow_oop,
 442                                             field->is_autobox_cache());
 443   if (con_type != NULL && field->is_call_site_target()) {
 444     ciCallSite* call_site = holder->as_call_site();
 445     if (!call_site->is_fully_initialized_constant_call_site()) {
 446       ciMethodHandle* target = con.as_object()->as_method_handle();
 447       Compile::current()->dependencies()->assert_call_site_target_value(call_site, target);
 448     }
 449   }
 450   return con_type;
 451 }
 452 
 453 //------------------------------make-------------------------------------------
 454 // Create a simple Type, with default empty symbol sets.  Then hashcons it
 455 // and look for an existing copy in the type dictionary.
 456 const Type *Type::make( enum TYPES t ) {
 457   return (new Type(t))->hashcons();
 458 }
 459 
 460 //------------------------------cmp--------------------------------------------
 461 int Type::cmp( const Type *const t1, const Type *const t2 ) {
 462   if( t1->_base != t2->_base )
 463     return 1;                   // Missed badly
 464   assert(t1 != t2 || t1->eq(t2), "eq must be reflexive");
 465   return !t1->eq(t2);           // Return ZERO if equal
 466 }
 467 
 468 const Type* Type::maybe_remove_speculative(bool include_speculative) const {
 469   if (!include_speculative) {
 470     return remove_speculative();
 471   }
 472   return this;
 473 }
 474 
 475 //------------------------------hash-------------------------------------------
 476 int Type::uhash( const Type *const t ) {
 477   return t->hash();
 478 }
 479 
 480 #define SMALLINT ((juint)3)  // a value too insignificant to consider widening
 481 #define POSITIVE_INFINITE_F 0x7f800000 // hex representation for IEEE 754 single precision positive infinite
 482 #define POSITIVE_INFINITE_D 0x7ff0000000000000 // hex representation for IEEE 754 double precision positive infinite
 483 
 484 //--------------------------Initialize_shared----------------------------------
 485 void Type::Initialize_shared(Compile* current) {
 486   // This method does not need to be locked because the first system
 487   // compilations (stub compilations) occur serially.  If they are
 488   // changed to proceed in parallel, then this section will need
 489   // locking.
 490 
 491   Arena* save = current->type_arena();
 492   Arena* shared_type_arena = new (mtCompiler)Arena(mtCompiler);
 493 
 494   current->set_type_arena(shared_type_arena);
 495   _shared_type_dict =
 496     new (shared_type_arena) Dict( (CmpKey)Type::cmp, (Hash)Type::uhash,
 497                                   shared_type_arena, 128 );
 498   current->set_type_dict(_shared_type_dict);
 499 
 500   // Make shared pre-built types.
 501   CONTROL = make(Control);      // Control only
 502   TOP     = make(Top);          // No values in set
 503   MEMORY  = make(Memory);       // Abstract store only
 504   ABIO    = make(Abio);         // State-of-machine only
 505   RETURN_ADDRESS=make(Return_Address);
 506   FLOAT   = make(FloatBot);     // All floats
 507   DOUBLE  = make(DoubleBot);    // All doubles
 508   BOTTOM  = make(Bottom);       // Everything
 509   HALF    = make(Half);         // Placeholder half of doublewide type
 510 
 511   TypeF::MAX = TypeF::make(max_jfloat); // Float MAX
 512   TypeF::MIN = TypeF::make(min_jfloat); // Float MIN
 513   TypeF::ZERO = TypeF::make(0.0); // Float 0 (positive zero)
 514   TypeF::ONE  = TypeF::make(1.0); // Float 1
 515   TypeF::POS_INF = TypeF::make(jfloat_cast(POSITIVE_INFINITE_F));
 516   TypeF::NEG_INF = TypeF::make(-jfloat_cast(POSITIVE_INFINITE_F));
 517 
 518   TypeD::MAX = TypeD::make(max_jdouble); // Double MAX
 519   TypeD::MIN = TypeD::make(min_jdouble); // Double MIN
 520   TypeD::ZERO = TypeD::make(0.0); // Double 0 (positive zero)
 521   TypeD::ONE  = TypeD::make(1.0); // Double 1
 522   TypeD::POS_INF = TypeD::make(jdouble_cast(POSITIVE_INFINITE_D));
 523   TypeD::NEG_INF = TypeD::make(-jdouble_cast(POSITIVE_INFINITE_D));
 524 
 525   TypeInt::MAX = TypeInt::make(max_jint); // Int MAX
 526   TypeInt::MIN = TypeInt::make(min_jint); // Int MIN
 527   TypeInt::MINUS_1 = TypeInt::make(-1);  // -1
 528   TypeInt::ZERO    = TypeInt::make( 0);  //  0
 529   TypeInt::ONE     = TypeInt::make( 1);  //  1
 530   TypeInt::BOOL    = TypeInt::make(0,1,   WidenMin);  // 0 or 1, FALSE or TRUE.
 531   TypeInt::CC      = TypeInt::make(-1, 1, WidenMin);  // -1, 0 or 1, condition codes
 532   TypeInt::CC_LT   = TypeInt::make(-1,-1, WidenMin);  // == TypeInt::MINUS_1
 533   TypeInt::CC_GT   = TypeInt::make( 1, 1, WidenMin);  // == TypeInt::ONE
 534   TypeInt::CC_EQ   = TypeInt::make( 0, 0, WidenMin);  // == TypeInt::ZERO
 535   TypeInt::CC_LE   = TypeInt::make(-1, 0, WidenMin);
 536   TypeInt::CC_GE   = TypeInt::make( 0, 1, WidenMin);  // == TypeInt::BOOL
 537   TypeInt::BYTE    = TypeInt::make(-128,127,     WidenMin); // Bytes
 538   TypeInt::UBYTE   = TypeInt::make(0, 255,       WidenMin); // Unsigned Bytes
 539   TypeInt::CHAR    = TypeInt::make(0,65535,      WidenMin); // Java chars
 540   TypeInt::SHORT   = TypeInt::make(-32768,32767, WidenMin); // Java shorts
 541   TypeInt::POS     = TypeInt::make(0,max_jint,   WidenMin); // Non-neg values
 542   TypeInt::POS1    = TypeInt::make(1,max_jint,   WidenMin); // Positive values
 543   TypeInt::INT     = TypeInt::make(min_jint,max_jint, WidenMax); // 32-bit integers
 544   TypeInt::SYMINT  = TypeInt::make(-max_jint,max_jint,WidenMin); // symmetric range
 545   TypeInt::TYPE_DOMAIN  = TypeInt::INT;
 546   // CmpL is overloaded both as the bytecode computation returning
 547   // a trinary (-1,0,+1) integer result AND as an efficient long
 548   // compare returning optimizer ideal-type flags.
 549   assert( TypeInt::CC_LT == TypeInt::MINUS_1, "types must match for CmpL to work" );
 550   assert( TypeInt::CC_GT == TypeInt::ONE,     "types must match for CmpL to work" );
 551   assert( TypeInt::CC_EQ == TypeInt::ZERO,    "types must match for CmpL to work" );
 552   assert( TypeInt::CC_GE == TypeInt::BOOL,    "types must match for CmpL to work" );
 553   assert( (juint)(TypeInt::CC->_hi - TypeInt::CC->_lo) <= SMALLINT, "CC is truly small");
 554 
 555   TypeLong::MAX = TypeLong::make(max_jlong);  // Long MAX
 556   TypeLong::MIN = TypeLong::make(min_jlong);  // Long MIN
 557   TypeLong::MINUS_1 = TypeLong::make(-1);        // -1
 558   TypeLong::ZERO    = TypeLong::make( 0);        //  0
 559   TypeLong::ONE     = TypeLong::make( 1);        //  1
 560   TypeLong::POS     = TypeLong::make(0,max_jlong, WidenMin); // Non-neg values
 561   TypeLong::LONG    = TypeLong::make(min_jlong,max_jlong,WidenMax); // 64-bit integers
 562   TypeLong::INT     = TypeLong::make((jlong)min_jint,(jlong)max_jint,WidenMin);
 563   TypeLong::UINT    = TypeLong::make(0,(jlong)max_juint,WidenMin);
 564   TypeLong::TYPE_DOMAIN  = TypeLong::LONG;
 565 
 566   const Type **fboth =(const Type**)shared_type_arena->AmallocWords(2*sizeof(Type*));
 567   fboth[0] = Type::CONTROL;
 568   fboth[1] = Type::CONTROL;
 569   TypeTuple::IFBOTH = TypeTuple::make( 2, fboth );
 570 
 571   const Type **ffalse =(const Type**)shared_type_arena->AmallocWords(2*sizeof(Type*));
 572   ffalse[0] = Type::CONTROL;
 573   ffalse[1] = Type::TOP;
 574   TypeTuple::IFFALSE = TypeTuple::make( 2, ffalse );
 575 
 576   const Type **fneither =(const Type**)shared_type_arena->AmallocWords(2*sizeof(Type*));
 577   fneither[0] = Type::TOP;
 578   fneither[1] = Type::TOP;
 579   TypeTuple::IFNEITHER = TypeTuple::make( 2, fneither );
 580 
 581   const Type **ftrue =(const Type**)shared_type_arena->AmallocWords(2*sizeof(Type*));
 582   ftrue[0] = Type::TOP;
 583   ftrue[1] = Type::CONTROL;
 584   TypeTuple::IFTRUE = TypeTuple::make( 2, ftrue );
 585 
 586   const Type **floop =(const Type**)shared_type_arena->AmallocWords(2*sizeof(Type*));
 587   floop[0] = Type::CONTROL;
 588   floop[1] = TypeInt::INT;
 589   TypeTuple::LOOPBODY = TypeTuple::make( 2, floop );
 590 
 591   TypePtr::NULL_PTR= TypePtr::make(AnyPtr, TypePtr::Null, Offset(0));
 592   TypePtr::NOTNULL = TypePtr::make(AnyPtr, TypePtr::NotNull, Offset::bottom);
 593   TypePtr::BOTTOM  = TypePtr::make(AnyPtr, TypePtr::BotPTR, Offset::bottom);
 594 
 595   TypeRawPtr::BOTTOM = TypeRawPtr::make( TypePtr::BotPTR );
 596   TypeRawPtr::NOTNULL= TypeRawPtr::make( TypePtr::NotNull );
 597 
 598   const Type **fmembar = TypeTuple::fields(0);
 599   TypeTuple::MEMBAR = TypeTuple::make(TypeFunc::Parms+0, fmembar);
 600 
 601   const Type **fsc = (const Type**)shared_type_arena->AmallocWords(2*sizeof(Type*));
 602   fsc[0] = TypeInt::CC;
 603   fsc[1] = Type::MEMORY;
 604   TypeTuple::STORECONDITIONAL = TypeTuple::make(2, fsc);
 605 
 606   TypeInstPtr::NOTNULL = TypeInstPtr::make(TypePtr::NotNull, current->env()->Object_klass());
 607   TypeInstPtr::BOTTOM  = TypeInstPtr::make(TypePtr::BotPTR,  current->env()->Object_klass());
 608   TypeInstPtr::MIRROR  = TypeInstPtr::make(TypePtr::NotNull, current->env()->Class_klass());
 609   TypeInstPtr::MARK    = TypeInstPtr::make(TypePtr::BotPTR,  current->env()->Object_klass(),
 610                                            false, 0, Offset(oopDesc::mark_offset_in_bytes()));
 611   TypeInstPtr::KLASS   = TypeInstPtr::make(TypePtr::BotPTR,  current->env()->Object_klass(),
 612                                            false, 0, Offset(oopDesc::klass_offset_in_bytes()));
 613   TypeOopPtr::BOTTOM  = TypeOopPtr::make(TypePtr::BotPTR, Offset::bottom, TypeOopPtr::InstanceBot);
 614 
 615   TypeMetadataPtr::BOTTOM = TypeMetadataPtr::make(TypePtr::BotPTR, NULL, Offset::bottom);
 616 
 617   TypeInlineType::BOTTOM = TypeInlineType::make(NULL);
 618 
 619   TypeNarrowOop::NULL_PTR = TypeNarrowOop::make( TypePtr::NULL_PTR );
 620   TypeNarrowOop::BOTTOM   = TypeNarrowOop::make( TypeInstPtr::BOTTOM );
 621 
 622   TypeNarrowKlass::NULL_PTR = TypeNarrowKlass::make( TypePtr::NULL_PTR );
 623 
 624   mreg2type[Op_Node] = Type::BOTTOM;
 625   mreg2type[Op_Set ] = 0;
 626   mreg2type[Op_RegN] = TypeNarrowOop::BOTTOM;
 627   mreg2type[Op_RegI] = TypeInt::INT;
 628   mreg2type[Op_RegP] = TypePtr::BOTTOM;
 629   mreg2type[Op_RegF] = Type::FLOAT;
 630   mreg2type[Op_RegD] = Type::DOUBLE;
 631   mreg2type[Op_RegL] = TypeLong::LONG;
 632   mreg2type[Op_RegFlags] = TypeInt::CC;
 633 
 634   TypeAryPtr::RANGE   = TypeAryPtr::make(TypePtr::BotPTR, TypeAry::make(Type::BOTTOM,TypeInt::POS), NULL /* current->env()->Object_klass() */, false, Offset(arrayOopDesc::length_offset_in_bytes()));
 635 
 636   TypeAryPtr::NARROWOOPS = TypeAryPtr::make(TypePtr::BotPTR, TypeAry::make(TypeNarrowOop::BOTTOM, TypeInt::POS), NULL /*ciArrayKlass::make(o)*/,  false,  Offset::bottom);
 637 
 638 #ifdef _LP64
 639   if (UseCompressedOops) {
 640     assert(TypeAryPtr::NARROWOOPS->is_ptr_to_narrowoop(), "array of narrow oops must be ptr to narrow oop");
 641     TypeAryPtr::OOPS  = TypeAryPtr::NARROWOOPS;
 642   } else
 643 #endif
 644   {
 645     // There is no shared klass for Object[].  See note in TypeAryPtr::klass().
 646     TypeAryPtr::OOPS  = TypeAryPtr::make(TypePtr::BotPTR, TypeAry::make(TypeInstPtr::BOTTOM,TypeInt::POS), NULL /*ciArrayKlass::make(o)*/,  false,  Offset::bottom);
 647   }
 648   TypeAryPtr::BYTES   = TypeAryPtr::make(TypePtr::BotPTR, TypeAry::make(TypeInt::BYTE      ,TypeInt::POS), ciTypeArrayKlass::make(T_BYTE),   true,  Offset::bottom);
 649   TypeAryPtr::SHORTS  = TypeAryPtr::make(TypePtr::BotPTR, TypeAry::make(TypeInt::SHORT     ,TypeInt::POS), ciTypeArrayKlass::make(T_SHORT),  true,  Offset::bottom);
 650   TypeAryPtr::CHARS   = TypeAryPtr::make(TypePtr::BotPTR, TypeAry::make(TypeInt::CHAR      ,TypeInt::POS), ciTypeArrayKlass::make(T_CHAR),   true,  Offset::bottom);
 651   TypeAryPtr::INTS    = TypeAryPtr::make(TypePtr::BotPTR, TypeAry::make(TypeInt::INT       ,TypeInt::POS), ciTypeArrayKlass::make(T_INT),    true,  Offset::bottom);
 652   TypeAryPtr::LONGS   = TypeAryPtr::make(TypePtr::BotPTR, TypeAry::make(TypeLong::LONG     ,TypeInt::POS), ciTypeArrayKlass::make(T_LONG),   true,  Offset::bottom);
 653   TypeAryPtr::FLOATS  = TypeAryPtr::make(TypePtr::BotPTR, TypeAry::make(Type::FLOAT        ,TypeInt::POS), ciTypeArrayKlass::make(T_FLOAT),  true,  Offset::bottom);
 654   TypeAryPtr::DOUBLES = TypeAryPtr::make(TypePtr::BotPTR, TypeAry::make(Type::DOUBLE       ,TypeInt::POS), ciTypeArrayKlass::make(T_DOUBLE), true,  Offset::bottom);
 655   TypeAryPtr::INLINES = TypeAryPtr::make(TypePtr::BotPTR, TypeAry::make(TypeInlineType::BOTTOM,TypeInt::POS), NULL, false,  Offset::bottom);
 656 
 657   // Nobody should ask _array_body_type[T_NARROWOOP]. Use NULL as assert.
 658   TypeAryPtr::_array_body_type[T_NARROWOOP] = NULL;
 659   TypeAryPtr::_array_body_type[T_OBJECT]  = TypeAryPtr::OOPS;
 660   TypeAryPtr::_array_body_type[T_INLINE_TYPE] = TypeAryPtr::OOPS;
 661   TypeAryPtr::_array_body_type[T_ARRAY]   = TypeAryPtr::OOPS; // arrays are stored in oop arrays
 662   TypeAryPtr::_array_body_type[T_BYTE]    = TypeAryPtr::BYTES;
 663   TypeAryPtr::_array_body_type[T_BOOLEAN] = TypeAryPtr::BYTES;  // boolean[] is a byte array
 664   TypeAryPtr::_array_body_type[T_SHORT]   = TypeAryPtr::SHORTS;
 665   TypeAryPtr::_array_body_type[T_CHAR]    = TypeAryPtr::CHARS;
 666   TypeAryPtr::_array_body_type[T_INT]     = TypeAryPtr::INTS;
 667   TypeAryPtr::_array_body_type[T_LONG]    = TypeAryPtr::LONGS;
 668   TypeAryPtr::_array_body_type[T_FLOAT]   = TypeAryPtr::FLOATS;
 669   TypeAryPtr::_array_body_type[T_DOUBLE]  = TypeAryPtr::DOUBLES;
 670 
 671   TypeInstKlassPtr::OBJECT = TypeInstKlassPtr::make(TypePtr::NotNull, current->env()->Object_klass(), Offset(0), false);
 672   TypeInstKlassPtr::OBJECT_OR_NULL = TypeInstKlassPtr::make(TypePtr::BotPTR, current->env()->Object_klass(), Offset(0), false);
 673 
 674   const Type **fi2c = TypeTuple::fields(2);
 675   fi2c[TypeFunc::Parms+0] = TypeInstPtr::BOTTOM; // Method*
 676   fi2c[TypeFunc::Parms+1] = TypeRawPtr::BOTTOM; // argument pointer
 677   TypeTuple::START_I2C = TypeTuple::make(TypeFunc::Parms+2, fi2c);
 678 
 679   const Type **intpair = TypeTuple::fields(2);
 680   intpair[0] = TypeInt::INT;
 681   intpair[1] = TypeInt::INT;
 682   TypeTuple::INT_PAIR = TypeTuple::make(2, intpair);
 683 
 684   const Type **longpair = TypeTuple::fields(2);
 685   longpair[0] = TypeLong::LONG;
 686   longpair[1] = TypeLong::LONG;
 687   TypeTuple::LONG_PAIR = TypeTuple::make(2, longpair);
 688 
 689   const Type **intccpair = TypeTuple::fields(2);
 690   intccpair[0] = TypeInt::INT;
 691   intccpair[1] = TypeInt::CC;
 692   TypeTuple::INT_CC_PAIR = TypeTuple::make(2, intccpair);
 693 
 694   const Type **longccpair = TypeTuple::fields(2);
 695   longccpair[0] = TypeLong::LONG;
 696   longccpair[1] = TypeInt::CC;
 697   TypeTuple::LONG_CC_PAIR = TypeTuple::make(2, longccpair);
 698 
 699   _const_basic_type[T_NARROWOOP]   = TypeNarrowOop::BOTTOM;
 700   _const_basic_type[T_NARROWKLASS] = Type::BOTTOM;
 701   _const_basic_type[T_BOOLEAN]     = TypeInt::BOOL;
 702   _const_basic_type[T_CHAR]        = TypeInt::CHAR;
 703   _const_basic_type[T_BYTE]        = TypeInt::BYTE;
 704   _const_basic_type[T_SHORT]       = TypeInt::SHORT;
 705   _const_basic_type[T_INT]         = TypeInt::INT;
 706   _const_basic_type[T_LONG]        = TypeLong::LONG;
 707   _const_basic_type[T_FLOAT]       = Type::FLOAT;
 708   _const_basic_type[T_DOUBLE]      = Type::DOUBLE;
 709   _const_basic_type[T_OBJECT]      = TypeInstPtr::BOTTOM;
 710   _const_basic_type[T_ARRAY]       = TypeInstPtr::BOTTOM; // there is no separate bottom for arrays
 711   _const_basic_type[T_INLINE_TYPE] = TypeInstPtr::BOTTOM;
 712   _const_basic_type[T_VOID]        = TypePtr::NULL_PTR;   // reflection represents void this way
 713   _const_basic_type[T_ADDRESS]     = TypeRawPtr::BOTTOM;  // both interpreter return addresses & random raw ptrs
 714   _const_basic_type[T_CONFLICT]    = Type::BOTTOM;        // why not?
 715 
 716   _zero_type[T_NARROWOOP]   = TypeNarrowOop::NULL_PTR;
 717   _zero_type[T_NARROWKLASS] = TypeNarrowKlass::NULL_PTR;
 718   _zero_type[T_BOOLEAN]     = TypeInt::ZERO;     // false == 0
 719   _zero_type[T_CHAR]        = TypeInt::ZERO;     // '\0' == 0
 720   _zero_type[T_BYTE]        = TypeInt::ZERO;     // 0x00 == 0
 721   _zero_type[T_SHORT]       = TypeInt::ZERO;     // 0x0000 == 0
 722   _zero_type[T_INT]         = TypeInt::ZERO;
 723   _zero_type[T_LONG]        = TypeLong::ZERO;
 724   _zero_type[T_FLOAT]       = TypeF::ZERO;
 725   _zero_type[T_DOUBLE]      = TypeD::ZERO;
 726   _zero_type[T_OBJECT]      = TypePtr::NULL_PTR;
 727   _zero_type[T_ARRAY]       = TypePtr::NULL_PTR; // null array is null oop
 728   _zero_type[T_INLINE_TYPE] = TypePtr::NULL_PTR;
 729   _zero_type[T_ADDRESS]     = TypePtr::NULL_PTR; // raw pointers use the same null
 730   _zero_type[T_VOID]        = Type::TOP;         // the only void value is no value at all
 731 
 732   // get_zero_type() should not happen for T_CONFLICT
 733   _zero_type[T_CONFLICT]= NULL;
 734 
 735   TypeVect::VECTMASK = (TypeVect*)(new TypeVectMask(TypeInt::BOOL, MaxVectorSize))->hashcons();
 736   mreg2type[Op_RegVectMask] = TypeVect::VECTMASK;
 737 
 738   if (Matcher::supports_scalable_vector()) {
 739     TypeVect::VECTA = TypeVect::make(T_BYTE, Matcher::scalable_vector_reg_size(T_BYTE));
 740   }
 741 
 742   // Vector predefined types, it needs initialized _const_basic_type[].
 743   if (Matcher::vector_size_supported(T_BYTE,4)) {
 744     TypeVect::VECTS = TypeVect::make(T_BYTE,4);
 745   }
 746   if (Matcher::vector_size_supported(T_FLOAT,2)) {
 747     TypeVect::VECTD = TypeVect::make(T_FLOAT,2);
 748   }
 749   if (Matcher::vector_size_supported(T_FLOAT,4)) {
 750     TypeVect::VECTX = TypeVect::make(T_FLOAT,4);
 751   }
 752   if (Matcher::vector_size_supported(T_FLOAT,8)) {
 753     TypeVect::VECTY = TypeVect::make(T_FLOAT,8);
 754   }
 755   if (Matcher::vector_size_supported(T_FLOAT,16)) {
 756     TypeVect::VECTZ = TypeVect::make(T_FLOAT,16);
 757   }
 758 
 759   mreg2type[Op_VecA] = TypeVect::VECTA;
 760   mreg2type[Op_VecS] = TypeVect::VECTS;
 761   mreg2type[Op_VecD] = TypeVect::VECTD;
 762   mreg2type[Op_VecX] = TypeVect::VECTX;
 763   mreg2type[Op_VecY] = TypeVect::VECTY;
 764   mreg2type[Op_VecZ] = TypeVect::VECTZ;
 765 
 766   // Restore working type arena.
 767   current->set_type_arena(save);
 768   current->set_type_dict(NULL);
 769 }
 770 
 771 //------------------------------Initialize-------------------------------------
 772 void Type::Initialize(Compile* current) {
 773   assert(current->type_arena() != NULL, "must have created type arena");
 774 
 775   if (_shared_type_dict == NULL) {
 776     Initialize_shared(current);
 777   }
 778 
 779   Arena* type_arena = current->type_arena();
 780 
 781   // Create the hash-cons'ing dictionary with top-level storage allocation
 782   Dict *tdic = new (type_arena) Dict(*_shared_type_dict, type_arena);
 783   current->set_type_dict(tdic);
 784 }
 785 
 786 //------------------------------hashcons---------------------------------------
 787 // Do the hash-cons trick.  If the Type already exists in the type table,
 788 // delete the current Type and return the existing Type.  Otherwise stick the
 789 // current Type in the Type table.
 790 const Type *Type::hashcons(void) {
 791   debug_only(base());           // Check the assertion in Type::base().
 792   // Look up the Type in the Type dictionary
 793   Dict *tdic = type_dict();
 794   Type* old = (Type*)(tdic->Insert(this, this, false));
 795   if( old ) {                   // Pre-existing Type?
 796     if( old != this )           // Yes, this guy is not the pre-existing?
 797       delete this;              // Yes, Nuke this guy
 798     assert( old->_dual, "" );
 799     return old;                 // Return pre-existing
 800   }
 801 
 802   // Every type has a dual (to make my lattice symmetric).
 803   // Since we just discovered a new Type, compute its dual right now.
 804   assert( !_dual, "" );         // No dual yet
 805   _dual = xdual();              // Compute the dual
 806   if (cmp(this, _dual) == 0) {  // Handle self-symmetric
 807     if (_dual != this) {
 808       delete _dual;
 809       _dual = this;
 810     }
 811     return this;
 812   }
 813   assert( !_dual->_dual, "" );  // No reverse dual yet
 814   assert( !(*tdic)[_dual], "" ); // Dual not in type system either
 815   // New Type, insert into Type table
 816   tdic->Insert((void*)_dual,(void*)_dual);
 817   ((Type*)_dual)->_dual = this; // Finish up being symmetric
 818 #ifdef ASSERT
 819   Type *dual_dual = (Type*)_dual->xdual();
 820   assert( eq(dual_dual), "xdual(xdual()) should be identity" );
 821   delete dual_dual;
 822 #endif
 823   return this;                  // Return new Type
 824 }
 825 
 826 //------------------------------eq---------------------------------------------
 827 // Structural equality check for Type representations
 828 bool Type::eq( const Type * ) const {
 829   return true;                  // Nothing else can go wrong
 830 }
 831 
 832 //------------------------------hash-------------------------------------------
 833 // Type-specific hashing function.
 834 int Type::hash(void) const {
 835   return _base;
 836 }
 837 
 838 //------------------------------is_finite--------------------------------------
 839 // Has a finite value
 840 bool Type::is_finite() const {
 841   return false;
 842 }
 843 
 844 //------------------------------is_nan-----------------------------------------
 845 // Is not a number (NaN)
 846 bool Type::is_nan()    const {
 847   return false;
 848 }
 849 
 850 //----------------------interface_vs_oop---------------------------------------
 851 #ifdef ASSERT
 852 bool Type::interface_vs_oop_helper(const Type *t) const {
 853   bool result = false;
 854 
 855   const TypePtr* this_ptr = this->make_ptr(); // In case it is narrow_oop
 856   const TypePtr*    t_ptr =    t->make_ptr();
 857   if( this_ptr == NULL || t_ptr == NULL )
 858     return result;
 859 
 860   const TypeInstPtr* this_inst = this_ptr->isa_instptr();
 861   const TypeInstPtr*    t_inst =    t_ptr->isa_instptr();
 862   if( this_inst && this_inst->is_loaded() && t_inst && t_inst->is_loaded() ) {
 863     bool this_interface = this_inst->klass()->is_interface();
 864     bool    t_interface =    t_inst->klass()->is_interface();
 865     result = this_interface ^ t_interface;
 866   }
 867 
 868   return result;
 869 }
 870 
 871 bool Type::interface_vs_oop(const Type *t) const {
 872   if (interface_vs_oop_helper(t)) {
 873     return true;
 874   }
 875   // Now check the speculative parts as well
 876   const TypePtr* this_spec = isa_ptr() != NULL ? is_ptr()->speculative() : NULL;
 877   const TypePtr* t_spec = t->isa_ptr() != NULL ? t->is_ptr()->speculative() : NULL;
 878   if (this_spec != NULL && t_spec != NULL) {
 879     if (this_spec->interface_vs_oop_helper(t_spec)) {
 880       return true;
 881     }
 882     return false;
 883   }
 884   if (this_spec != NULL && this_spec->interface_vs_oop_helper(t)) {
 885     return true;
 886   }
 887   if (t_spec != NULL && interface_vs_oop_helper(t_spec)) {
 888     return true;
 889   }
 890   return false;
 891 }
 892 
 893 #endif
 894 
 895 void Type::check_symmetrical(const Type* t, const Type* mt) const {
 896 #ifdef ASSERT
 897   const Type* mt2 = t->xmeet(this);
 898   if (mt != mt2) {
 899     tty->print_cr("=== Meet Not Commutative ===");
 900     tty->print("t           = ");   t->dump(); tty->cr();
 901     tty->print("this        = ");      dump(); tty->cr();
 902     tty->print("t meet this = "); mt2->dump(); tty->cr();
 903     tty->print("this meet t = ");  mt->dump(); tty->cr();
 904     fatal("meet not commutative");
 905   }
 906   const Type* dual_join = mt->_dual;
 907   const Type* t2t    = dual_join->xmeet(t->_dual);
 908   const Type* t2this = dual_join->xmeet(this->_dual);
 909 
 910   // Interface meet Oop is Not Symmetric:
 911   // Interface:AnyNull meet Oop:AnyNull == Interface:AnyNull
 912   // Interface:NotNull meet Oop:NotNull == java/lang/Object:NotNull
 913 
 914   if (!interface_vs_oop(t) && (t2t != t->_dual || t2this != this->_dual)) {
 915     tty->print_cr("=== Meet Not Symmetric ===");
 916     tty->print("t   =                   ");              t->dump(); tty->cr();
 917     tty->print("this=                   ");                 dump(); tty->cr();
 918     tty->print("mt=(t meet this)=       ");             mt->dump(); tty->cr();
 919 
 920     tty->print("t_dual=                 ");       t->_dual->dump(); tty->cr();
 921     tty->print("this_dual=              ");          _dual->dump(); tty->cr();
 922     tty->print("mt_dual=                ");      mt->_dual->dump(); tty->cr();
 923 
 924     tty->print("mt_dual meet t_dual=    "); t2t           ->dump(); tty->cr();
 925     tty->print("mt_dual meet this_dual= "); t2this        ->dump(); tty->cr();
 926 
 927     fatal("meet not symmetric");
 928   }
 929 #endif
 930 }
 931 
 932 //------------------------------meet-------------------------------------------
 933 // Compute the MEET of two types.  NOT virtual.  It enforces that meet is
 934 // commutative and the lattice is symmetric.
 935 const Type *Type::meet_helper(const Type *t, bool include_speculative) const {
 936   if (isa_narrowoop() && t->isa_narrowoop()) {
 937     const Type* result = make_ptr()->meet_helper(t->make_ptr(), include_speculative);
 938     return result->make_narrowoop();
 939   }
 940   if (isa_narrowklass() && t->isa_narrowklass()) {
 941     const Type* result = make_ptr()->meet_helper(t->make_ptr(), include_speculative);
 942     return result->make_narrowklass();
 943   }
 944 
 945   const Type *this_t = maybe_remove_speculative(include_speculative);
 946   t = t->maybe_remove_speculative(include_speculative);
 947 
 948   const Type *mt = this_t->xmeet(t);
 949 #ifdef ASSERT
 950   if (isa_narrowoop() || t->isa_narrowoop()) return mt;
 951   if (isa_narrowklass() || t->isa_narrowklass()) return mt;
 952   Compile* C = Compile::current();
 953   if (!C->_type_verify_symmetry) {
 954     return mt;
 955   }
 956   this_t->check_symmetrical(t, mt);
 957   // In the case of an array, computing the meet above, caused the
 958   // computation of the meet of the elements which at verification
 959   // time caused the computation of the meet of the dual of the
 960   // elements. Computing the meet of the dual of the arrays here
 961   // causes the meet of the dual of the elements to be computed which
 962   // would cause the meet of the dual of the dual of the elements,
 963   // that is the meet of the elements already computed above to be
 964   // computed. Avoid redundant computations by requesting no
 965   // verification.
 966   C->_type_verify_symmetry = false;
 967   const Type *mt_dual = this_t->_dual->xmeet(t->_dual);
 968   this_t->_dual->check_symmetrical(t->_dual, mt_dual);
 969   assert(!C->_type_verify_symmetry, "shouldn't have changed");
 970   C->_type_verify_symmetry = true;
 971 #endif
 972   return mt;
 973 }
 974 
 975 //------------------------------xmeet------------------------------------------
 976 // Compute the MEET of two types.  It returns a new Type object.
 977 const Type *Type::xmeet( const Type *t ) const {
 978   // Perform a fast test for common case; meeting the same types together.
 979   if( this == t ) return this;  // Meeting same type-rep?
 980 
 981   // Meeting TOP with anything?
 982   if( _base == Top ) return t;
 983 
 984   // Meeting BOTTOM with anything?
 985   if( _base == Bottom ) return BOTTOM;
 986 
 987   // Current "this->_base" is one of: Bad, Multi, Control, Top,
 988   // Abio, Abstore, Floatxxx, Doublexxx, Bottom, lastype.
 989   switch (t->base()) {  // Switch on original type
 990 
 991   // Cut in half the number of cases I must handle.  Only need cases for when
 992   // the given enum "t->type" is less than or equal to the local enum "type".
 993   case FloatCon:
 994   case DoubleCon:
 995   case Int:
 996   case Long:
 997     return t->xmeet(this);
 998 
 999   case OopPtr:
1000     return t->xmeet(this);
1001 
1002   case InstPtr:
1003     return t->xmeet(this);
1004 
1005   case MetadataPtr:
1006   case KlassPtr:
1007   case InstKlassPtr:
1008   case AryKlassPtr:
1009     return t->xmeet(this);
1010 
1011   case AryPtr:
1012     return t->xmeet(this);
1013 
1014   case NarrowOop:
1015     return t->xmeet(this);
1016 
1017   case NarrowKlass:
1018     return t->xmeet(this);
1019 
1020   case InlineType:
1021     return t->xmeet(this);
1022 
1023   case Bad:                     // Type check
1024   default:                      // Bogus type not in lattice
1025     typerr(t);
1026     return Type::BOTTOM;
1027 
1028   case Bottom:                  // Ye Olde Default
1029     return t;
1030 
1031   case FloatTop:
1032     if( _base == FloatTop ) return this;
1033   case FloatBot:                // Float
1034     if( _base == FloatBot || _base == FloatTop ) return FLOAT;
1035     if( _base == DoubleTop || _base == DoubleBot ) return Type::BOTTOM;
1036     typerr(t);
1037     return Type::BOTTOM;
1038 
1039   case DoubleTop:
1040     if( _base == DoubleTop ) return this;
1041   case DoubleBot:               // Double
1042     if( _base == DoubleBot || _base == DoubleTop ) return DOUBLE;
1043     if( _base == FloatTop || _base == FloatBot ) return Type::BOTTOM;
1044     typerr(t);
1045     return Type::BOTTOM;
1046 
1047   // These next few cases must match exactly or it is a compile-time error.
1048   case Control:                 // Control of code
1049   case Abio:                    // State of world outside of program
1050   case Memory:
1051     if( _base == t->_base )  return this;
1052     typerr(t);
1053     return Type::BOTTOM;
1054 
1055   case Top:                     // Top of the lattice
1056     return this;
1057   }
1058 
1059   // The type is unchanged
1060   return this;
1061 }
1062 
1063 //-----------------------------filter------------------------------------------
1064 const Type *Type::filter_helper(const Type *kills, bool include_speculative) const {
1065   const Type* ft = join_helper(kills, include_speculative);
1066   if (ft->empty())
1067     return Type::TOP;           // Canonical empty value
1068   return ft;
1069 }
1070 
1071 //------------------------------xdual------------------------------------------
1072 
1073 const Type *Type::xdual() const {
1074   // Note: the base() accessor asserts the sanity of _base.
1075   assert(_type_info[base()].dual_type != Bad, "implement with v-call");
1076   return new Type(_type_info[_base].dual_type);
1077 }
1078 
1079 //------------------------------has_memory-------------------------------------
1080 bool Type::has_memory() const {
1081   Type::TYPES tx = base();
1082   if (tx == Memory) return true;
1083   if (tx == Tuple) {
1084     const TypeTuple *t = is_tuple();
1085     for (uint i=0; i < t->cnt(); i++) {
1086       tx = t->field_at(i)->base();
1087       if (tx == Memory)  return true;
1088     }
1089   }
1090   return false;
1091 }
1092 
1093 #ifndef PRODUCT
1094 //------------------------------dump2------------------------------------------
1095 void Type::dump2( Dict &d, uint depth, outputStream *st ) const {
1096   st->print("%s", _type_info[_base].msg);
1097 }
1098 
1099 //------------------------------dump-------------------------------------------
1100 void Type::dump_on(outputStream *st) const {
1101   ResourceMark rm;
1102   Dict d(cmpkey,hashkey);       // Stop recursive type dumping
1103   dump2(d,1, st);
1104   if (is_ptr_to_narrowoop()) {
1105     st->print(" [narrow]");
1106   } else if (is_ptr_to_narrowklass()) {
1107     st->print(" [narrowklass]");
1108   }
1109 }
1110 
1111 //-----------------------------------------------------------------------------
1112 const char* Type::str(const Type* t) {
1113   stringStream ss;
1114   t->dump_on(&ss);
1115   return ss.as_string();
1116 }
1117 #endif
1118 
1119 //------------------------------singleton--------------------------------------
1120 // TRUE if Type is a singleton type, FALSE otherwise.   Singletons are simple
1121 // constants (Ldi nodes).  Singletons are integer, float or double constants.
1122 bool Type::singleton(void) const {
1123   return _base == Top || _base == Half;
1124 }
1125 
1126 //------------------------------empty------------------------------------------
1127 // TRUE if Type is a type with no values, FALSE otherwise.
1128 bool Type::empty(void) const {
1129   switch (_base) {
1130   case DoubleTop:
1131   case FloatTop:
1132   case Top:
1133     return true;
1134 
1135   case Half:
1136   case Abio:
1137   case Return_Address:
1138   case Memory:
1139   case Bottom:
1140   case FloatBot:
1141   case DoubleBot:
1142     return false;  // never a singleton, therefore never empty
1143 
1144   default:
1145     ShouldNotReachHere();
1146     return false;
1147   }
1148 }
1149 
1150 //------------------------------dump_stats-------------------------------------
1151 // Dump collected statistics to stderr
1152 #ifndef PRODUCT
1153 void Type::dump_stats() {
1154   tty->print("Types made: %d\n", type_dict()->Size());
1155 }
1156 #endif
1157 
1158 //------------------------------category---------------------------------------
1159 #ifndef PRODUCT
1160 Type::Category Type::category() const {
1161   const TypeTuple* tuple;
1162   switch (base()) {
1163     case Type::Int:
1164     case Type::Long:
1165     case Type::Half:
1166     case Type::NarrowOop:
1167     case Type::NarrowKlass:
1168     case Type::Array:
1169     case Type::VectorA:
1170     case Type::VectorS:
1171     case Type::VectorD:
1172     case Type::VectorX:
1173     case Type::VectorY:
1174     case Type::VectorZ:
1175     case Type::VectorMask:
1176     case Type::AnyPtr:
1177     case Type::RawPtr:
1178     case Type::OopPtr:
1179     case Type::InstPtr:
1180     case Type::AryPtr:
1181     case Type::MetadataPtr:
1182     case Type::KlassPtr:
1183     case Type::InstKlassPtr:
1184     case Type::AryKlassPtr:
1185     case Type::Function:
1186     case Type::Return_Address:
1187     case Type::FloatTop:
1188     case Type::FloatCon:
1189     case Type::FloatBot:
1190     case Type::DoubleTop:
1191     case Type::DoubleCon:
1192     case Type::DoubleBot:
1193     case Type::InlineType:
1194       return Category::Data;
1195     case Type::Memory:
1196       return Category::Memory;
1197     case Type::Control:
1198       return Category::Control;
1199     case Type::Top:
1200     case Type::Abio:
1201     case Type::Bottom:
1202       return Category::Other;
1203     case Type::Bad:
1204     case Type::lastype:
1205       return Category::Undef;
1206     case Type::Tuple:
1207       // Recursive case. Return CatMixed if the tuple contains types of
1208       // different categories (e.g. CallStaticJavaNode's type), or the specific
1209       // category if all types are of the same category (e.g. IfNode's type).
1210       tuple = is_tuple();
1211       if (tuple->cnt() == 0) {
1212         return Category::Undef;
1213       } else {
1214         Category first = tuple->field_at(0)->category();
1215         for (uint i = 1; i < tuple->cnt(); i++) {
1216           if (tuple->field_at(i)->category() != first) {
1217             return Category::Mixed;
1218           }
1219         }
1220         return first;
1221       }
1222     default:
1223       assert(false, "unmatched base type: all base types must be categorized");
1224   }
1225   return Category::Undef;
1226 }
1227 #endif
1228 
1229 //------------------------------typerr-----------------------------------------
1230 void Type::typerr( const Type *t ) const {
1231 #ifndef PRODUCT
1232   tty->print("\nError mixing types: ");
1233   dump();
1234   tty->print(" and ");
1235   t->dump();
1236   tty->print("\n");
1237 #endif
1238   ShouldNotReachHere();
1239 }
1240 
1241 
1242 //=============================================================================
1243 // Convenience common pre-built types.
1244 const TypeF *TypeF::MAX;        // Floating point max
1245 const TypeF *TypeF::MIN;        // Floating point min
1246 const TypeF *TypeF::ZERO;       // Floating point zero
1247 const TypeF *TypeF::ONE;        // Floating point one
1248 const TypeF *TypeF::POS_INF;    // Floating point positive infinity
1249 const TypeF *TypeF::NEG_INF;    // Floating point negative infinity
1250 
1251 //------------------------------make-------------------------------------------
1252 // Create a float constant
1253 const TypeF *TypeF::make(float f) {
1254   return (TypeF*)(new TypeF(f))->hashcons();
1255 }
1256 
1257 //------------------------------meet-------------------------------------------
1258 // Compute the MEET of two types.  It returns a new Type object.
1259 const Type *TypeF::xmeet( const Type *t ) const {
1260   // Perform a fast test for common case; meeting the same types together.
1261   if( this == t ) return this;  // Meeting same type-rep?
1262 
1263   // Current "this->_base" is FloatCon
1264   switch (t->base()) {          // Switch on original type
1265   case AnyPtr:                  // Mixing with oops happens when javac
1266   case RawPtr:                  // reuses local variables
1267   case OopPtr:
1268   case InstPtr:
1269   case AryPtr:
1270   case MetadataPtr:
1271   case KlassPtr:
1272   case InstKlassPtr:
1273   case AryKlassPtr:
1274   case NarrowOop:
1275   case NarrowKlass:
1276   case Int:
1277   case Long:
1278   case DoubleTop:
1279   case DoubleCon:
1280   case DoubleBot:
1281   case Bottom:                  // Ye Olde Default
1282     return Type::BOTTOM;
1283 
1284   case FloatBot:
1285     return t;
1286 
1287   default:                      // All else is a mistake
1288     typerr(t);
1289 
1290   case FloatCon:                // Float-constant vs Float-constant?
1291     if( jint_cast(_f) != jint_cast(t->getf()) )         // unequal constants?
1292                                 // must compare bitwise as positive zero, negative zero and NaN have
1293                                 // all the same representation in C++
1294       return FLOAT;             // Return generic float
1295                                 // Equal constants
1296   case Top:
1297   case FloatTop:
1298     break;                      // Return the float constant
1299   }
1300   return this;                  // Return the float constant
1301 }
1302 
1303 //------------------------------xdual------------------------------------------
1304 // Dual: symmetric
1305 const Type *TypeF::xdual() const {
1306   return this;
1307 }
1308 
1309 //------------------------------eq---------------------------------------------
1310 // Structural equality check for Type representations
1311 bool TypeF::eq(const Type *t) const {
1312   // Bitwise comparison to distinguish between +/-0. These values must be treated
1313   // as different to be consistent with C1 and the interpreter.
1314   return (jint_cast(_f) == jint_cast(t->getf()));
1315 }
1316 
1317 //------------------------------hash-------------------------------------------
1318 // Type-specific hashing function.
1319 int TypeF::hash(void) const {
1320   return *(int*)(&_f);
1321 }
1322 
1323 //------------------------------is_finite--------------------------------------
1324 // Has a finite value
1325 bool TypeF::is_finite() const {
1326   return g_isfinite(getf()) != 0;
1327 }
1328 
1329 //------------------------------is_nan-----------------------------------------
1330 // Is not a number (NaN)
1331 bool TypeF::is_nan()    const {
1332   return g_isnan(getf()) != 0;
1333 }
1334 
1335 //------------------------------dump2------------------------------------------
1336 // Dump float constant Type
1337 #ifndef PRODUCT
1338 void TypeF::dump2( Dict &d, uint depth, outputStream *st ) const {
1339   Type::dump2(d,depth, st);
1340   st->print("%f", _f);
1341 }
1342 #endif
1343 
1344 //------------------------------singleton--------------------------------------
1345 // TRUE if Type is a singleton type, FALSE otherwise.   Singletons are simple
1346 // constants (Ldi nodes).  Singletons are integer, float or double constants
1347 // or a single symbol.
1348 bool TypeF::singleton(void) const {
1349   return true;                  // Always a singleton
1350 }
1351 
1352 bool TypeF::empty(void) const {
1353   return false;                 // always exactly a singleton
1354 }
1355 
1356 //=============================================================================
1357 // Convenience common pre-built types.
1358 const TypeD *TypeD::MAX;        // Floating point max
1359 const TypeD *TypeD::MIN;        // Floating point min
1360 const TypeD *TypeD::ZERO;       // Floating point zero
1361 const TypeD *TypeD::ONE;        // Floating point one
1362 const TypeD *TypeD::POS_INF;    // Floating point positive infinity
1363 const TypeD *TypeD::NEG_INF;    // Floating point negative infinity
1364 
1365 //------------------------------make-------------------------------------------
1366 const TypeD *TypeD::make(double d) {
1367   return (TypeD*)(new TypeD(d))->hashcons();
1368 }
1369 
1370 //------------------------------meet-------------------------------------------
1371 // Compute the MEET of two types.  It returns a new Type object.
1372 const Type *TypeD::xmeet( const Type *t ) const {
1373   // Perform a fast test for common case; meeting the same types together.
1374   if( this == t ) return this;  // Meeting same type-rep?
1375 
1376   // Current "this->_base" is DoubleCon
1377   switch (t->base()) {          // Switch on original type
1378   case AnyPtr:                  // Mixing with oops happens when javac
1379   case RawPtr:                  // reuses local variables
1380   case OopPtr:
1381   case InstPtr:
1382   case AryPtr:
1383   case MetadataPtr:
1384   case KlassPtr:
1385   case InstKlassPtr:
1386   case AryKlassPtr:
1387   case NarrowOop:
1388   case NarrowKlass:
1389   case Int:
1390   case Long:
1391   case FloatTop:
1392   case FloatCon:
1393   case FloatBot:
1394   case Bottom:                  // Ye Olde Default
1395     return Type::BOTTOM;
1396 
1397   case DoubleBot:
1398     return t;
1399 
1400   default:                      // All else is a mistake
1401     typerr(t);
1402 
1403   case DoubleCon:               // Double-constant vs Double-constant?
1404     if( jlong_cast(_d) != jlong_cast(t->getd()) )       // unequal constants? (see comment in TypeF::xmeet)
1405       return DOUBLE;            // Return generic double
1406   case Top:
1407   case DoubleTop:
1408     break;
1409   }
1410   return this;                  // Return the double constant
1411 }
1412 
1413 //------------------------------xdual------------------------------------------
1414 // Dual: symmetric
1415 const Type *TypeD::xdual() const {
1416   return this;
1417 }
1418 
1419 //------------------------------eq---------------------------------------------
1420 // Structural equality check for Type representations
1421 bool TypeD::eq(const Type *t) const {
1422   // Bitwise comparison to distinguish between +/-0. These values must be treated
1423   // as different to be consistent with C1 and the interpreter.
1424   return (jlong_cast(_d) == jlong_cast(t->getd()));
1425 }
1426 
1427 //------------------------------hash-------------------------------------------
1428 // Type-specific hashing function.
1429 int TypeD::hash(void) const {
1430   return *(int*)(&_d);
1431 }
1432 
1433 //------------------------------is_finite--------------------------------------
1434 // Has a finite value
1435 bool TypeD::is_finite() const {
1436   return g_isfinite(getd()) != 0;
1437 }
1438 
1439 //------------------------------is_nan-----------------------------------------
1440 // Is not a number (NaN)
1441 bool TypeD::is_nan()    const {
1442   return g_isnan(getd()) != 0;
1443 }
1444 
1445 //------------------------------dump2------------------------------------------
1446 // Dump double constant Type
1447 #ifndef PRODUCT
1448 void TypeD::dump2( Dict &d, uint depth, outputStream *st ) const {
1449   Type::dump2(d,depth,st);
1450   st->print("%f", _d);
1451 }
1452 #endif
1453 
1454 //------------------------------singleton--------------------------------------
1455 // TRUE if Type is a singleton type, FALSE otherwise.   Singletons are simple
1456 // constants (Ldi nodes).  Singletons are integer, float or double constants
1457 // or a single symbol.
1458 bool TypeD::singleton(void) const {
1459   return true;                  // Always a singleton
1460 }
1461 
1462 bool TypeD::empty(void) const {
1463   return false;                 // always exactly a singleton
1464 }
1465 
1466 const TypeInteger* TypeInteger::make(jlong lo, jlong hi, int w, BasicType bt) {
1467   if (bt == T_INT) {
1468     return TypeInt::make(checked_cast<jint>(lo), checked_cast<jint>(hi), w);
1469   }
1470   assert(bt == T_LONG, "basic type not an int or long");
1471   return TypeLong::make(lo, hi, w);
1472 }
1473 
1474 jlong TypeInteger::get_con_as_long(BasicType bt) const {
1475   if (bt == T_INT) {
1476     return is_int()->get_con();
1477   }
1478   assert(bt == T_LONG, "basic type not an int or long");
1479   return is_long()->get_con();
1480 }
1481 
1482 const TypeInteger* TypeInteger::bottom(BasicType bt) {
1483   if (bt == T_INT) {
1484     return TypeInt::INT;
1485   }
1486   assert(bt == T_LONG, "basic type not an int or long");
1487   return TypeLong::LONG;
1488 }
1489 
1490 //=============================================================================
1491 // Convience common pre-built types.
1492 const TypeInt *TypeInt::MAX;    // INT_MAX
1493 const TypeInt *TypeInt::MIN;    // INT_MIN
1494 const TypeInt *TypeInt::MINUS_1;// -1
1495 const TypeInt *TypeInt::ZERO;   // 0
1496 const TypeInt *TypeInt::ONE;    // 1
1497 const TypeInt *TypeInt::BOOL;   // 0 or 1, FALSE or TRUE.
1498 const TypeInt *TypeInt::CC;     // -1,0 or 1, condition codes
1499 const TypeInt *TypeInt::CC_LT;  // [-1]  == MINUS_1
1500 const TypeInt *TypeInt::CC_GT;  // [1]   == ONE
1501 const TypeInt *TypeInt::CC_EQ;  // [0]   == ZERO
1502 const TypeInt *TypeInt::CC_LE;  // [-1,0]
1503 const TypeInt *TypeInt::CC_GE;  // [0,1] == BOOL (!)
1504 const TypeInt *TypeInt::BYTE;   // Bytes, -128 to 127
1505 const TypeInt *TypeInt::UBYTE;  // Unsigned Bytes, 0 to 255
1506 const TypeInt *TypeInt::CHAR;   // Java chars, 0-65535
1507 const TypeInt *TypeInt::SHORT;  // Java shorts, -32768-32767
1508 const TypeInt *TypeInt::POS;    // Positive 32-bit integers or zero
1509 const TypeInt *TypeInt::POS1;   // Positive 32-bit integers
1510 const TypeInt *TypeInt::INT;    // 32-bit integers
1511 const TypeInt *TypeInt::SYMINT; // symmetric range [-max_jint..max_jint]
1512 const TypeInt *TypeInt::TYPE_DOMAIN; // alias for TypeInt::INT
1513 
1514 //------------------------------TypeInt----------------------------------------
1515 TypeInt::TypeInt( jint lo, jint hi, int w ) : TypeInteger(Int), _lo(lo), _hi(hi), _widen(w) {
1516 }
1517 
1518 //------------------------------make-------------------------------------------
1519 const TypeInt *TypeInt::make( jint lo ) {
1520   return (TypeInt*)(new TypeInt(lo,lo,WidenMin))->hashcons();
1521 }
1522 
1523 static int normalize_int_widen( jint lo, jint hi, int w ) {
1524   // Certain normalizations keep us sane when comparing types.
1525   // The 'SMALLINT' covers constants and also CC and its relatives.
1526   if (lo <= hi) {
1527     if (((juint)hi - lo) <= SMALLINT)  w = Type::WidenMin;
1528     if (((juint)hi - lo) >= max_juint) w = Type::WidenMax; // TypeInt::INT
1529   } else {
1530     if (((juint)lo - hi) <= SMALLINT)  w = Type::WidenMin;
1531     if (((juint)lo - hi) >= max_juint) w = Type::WidenMin; // dual TypeInt::INT
1532   }
1533   return w;
1534 }
1535 
1536 const TypeInt *TypeInt::make( jint lo, jint hi, int w ) {
1537   w = normalize_int_widen(lo, hi, w);
1538   return (TypeInt*)(new TypeInt(lo,hi,w))->hashcons();
1539 }
1540 
1541 //------------------------------meet-------------------------------------------
1542 // Compute the MEET of two types.  It returns a new Type representation object
1543 // with reference count equal to the number of Types pointing at it.
1544 // Caller should wrap a Types around it.
1545 const Type *TypeInt::xmeet( const Type *t ) const {
1546   // Perform a fast test for common case; meeting the same types together.
1547   if( this == t ) return this;  // Meeting same type?
1548 
1549   // Currently "this->_base" is a TypeInt
1550   switch (t->base()) {          // Switch on original type
1551   case AnyPtr:                  // Mixing with oops happens when javac
1552   case RawPtr:                  // reuses local variables
1553   case OopPtr:
1554   case InstPtr:
1555   case AryPtr:
1556   case MetadataPtr:
1557   case KlassPtr:
1558   case InstKlassPtr:
1559   case AryKlassPtr:
1560   case NarrowOop:
1561   case NarrowKlass:
1562   case Long:
1563   case FloatTop:
1564   case FloatCon:
1565   case FloatBot:
1566   case DoubleTop:
1567   case DoubleCon:
1568   case DoubleBot:
1569   case InlineType:
1570   case Bottom:                  // Ye Olde Default
1571     return Type::BOTTOM;
1572   default:                      // All else is a mistake
1573     typerr(t);
1574   case Top:                     // No change
1575     return this;
1576   case Int:                     // Int vs Int?
1577     break;
1578   }
1579 
1580   // Expand covered set
1581   const TypeInt *r = t->is_int();
1582   return make( MIN2(_lo,r->_lo), MAX2(_hi,r->_hi), MAX2(_widen,r->_widen) );
1583 }
1584 
1585 //------------------------------xdual------------------------------------------
1586 // Dual: reverse hi & lo; flip widen
1587 const Type *TypeInt::xdual() const {
1588   int w = normalize_int_widen(_hi,_lo, WidenMax-_widen);
1589   return new TypeInt(_hi,_lo,w);
1590 }
1591 
1592 //------------------------------widen------------------------------------------
1593 // Only happens for optimistic top-down optimizations.
1594 const Type *TypeInt::widen( const Type *old, const Type* limit ) const {
1595   // Coming from TOP or such; no widening
1596   if( old->base() != Int ) return this;
1597   const TypeInt *ot = old->is_int();
1598 
1599   // If new guy is equal to old guy, no widening
1600   if( _lo == ot->_lo && _hi == ot->_hi )
1601     return old;
1602 
1603   // If new guy contains old, then we widened
1604   if( _lo <= ot->_lo && _hi >= ot->_hi ) {
1605     // New contains old
1606     // If new guy is already wider than old, no widening
1607     if( _widen > ot->_widen ) return this;
1608     // If old guy was a constant, do not bother
1609     if (ot->_lo == ot->_hi)  return this;
1610     // Now widen new guy.
1611     // Check for widening too far
1612     if (_widen == WidenMax) {
1613       int max = max_jint;
1614       int min = min_jint;
1615       if (limit->isa_int()) {
1616         max = limit->is_int()->_hi;
1617         min = limit->is_int()->_lo;
1618       }
1619       if (min < _lo && _hi < max) {
1620         // If neither endpoint is extremal yet, push out the endpoint
1621         // which is closer to its respective limit.
1622         if (_lo >= 0 ||                 // easy common case
1623             (juint)(_lo - min) >= (juint)(max - _hi)) {
1624           // Try to widen to an unsigned range type of 31 bits:
1625           return make(_lo, max, WidenMax);
1626         } else {
1627           return make(min, _hi, WidenMax);
1628         }
1629       }
1630       return TypeInt::INT;
1631     }
1632     // Returned widened new guy
1633     return make(_lo,_hi,_widen+1);
1634   }
1635 
1636   // If old guy contains new, then we probably widened too far & dropped to
1637   // bottom.  Return the wider fellow.
1638   if ( ot->_lo <= _lo && ot->_hi >= _hi )
1639     return old;
1640 
1641   //fatal("Integer value range is not subset");
1642   //return this;
1643   return TypeInt::INT;
1644 }
1645 
1646 //------------------------------narrow---------------------------------------
1647 // Only happens for pessimistic optimizations.
1648 const Type *TypeInt::narrow( const Type *old ) const {
1649   if (_lo >= _hi)  return this;   // already narrow enough
1650   if (old == NULL)  return this;
1651   const TypeInt* ot = old->isa_int();
1652   if (ot == NULL)  return this;
1653   jint olo = ot->_lo;
1654   jint ohi = ot->_hi;
1655 
1656   // If new guy is equal to old guy, no narrowing
1657   if (_lo == olo && _hi == ohi)  return old;
1658 
1659   // If old guy was maximum range, allow the narrowing
1660   if (olo == min_jint && ohi == max_jint)  return this;
1661 
1662   if (_lo < olo || _hi > ohi)
1663     return this;                // doesn't narrow; pretty wierd
1664 
1665   // The new type narrows the old type, so look for a "death march".
1666   // See comments on PhaseTransform::saturate.
1667   juint nrange = (juint)_hi - _lo;
1668   juint orange = (juint)ohi - olo;
1669   if (nrange < max_juint - 1 && nrange > (orange >> 1) + (SMALLINT*2)) {
1670     // Use the new type only if the range shrinks a lot.
1671     // We do not want the optimizer computing 2^31 point by point.
1672     return old;
1673   }
1674 
1675   return this;
1676 }
1677 
1678 //-----------------------------filter------------------------------------------
1679 const Type *TypeInt::filter_helper(const Type *kills, bool include_speculative) const {
1680   const TypeInt* ft = join_helper(kills, include_speculative)->isa_int();
1681   if (ft == NULL || ft->empty())
1682     return Type::TOP;           // Canonical empty value
1683   if (ft->_widen < this->_widen) {
1684     // Do not allow the value of kill->_widen to affect the outcome.
1685     // The widen bits must be allowed to run freely through the graph.
1686     ft = TypeInt::make(ft->_lo, ft->_hi, this->_widen);
1687   }
1688   return ft;
1689 }
1690 
1691 //------------------------------eq---------------------------------------------
1692 // Structural equality check for Type representations
1693 bool TypeInt::eq( const Type *t ) const {
1694   const TypeInt *r = t->is_int(); // Handy access
1695   return r->_lo == _lo && r->_hi == _hi && r->_widen == _widen;
1696 }
1697 
1698 //------------------------------hash-------------------------------------------
1699 // Type-specific hashing function.
1700 int TypeInt::hash(void) const {
1701   return java_add(java_add(_lo, _hi), java_add((jint)_widen, (jint)Type::Int));
1702 }
1703 
1704 //------------------------------is_finite--------------------------------------
1705 // Has a finite value
1706 bool TypeInt::is_finite() const {
1707   return true;
1708 }
1709 
1710 //------------------------------dump2------------------------------------------
1711 // Dump TypeInt
1712 #ifndef PRODUCT
1713 static const char* intname(char* buf, jint n) {
1714   if (n == min_jint)
1715     return "min";
1716   else if (n < min_jint + 10000)
1717     sprintf(buf, "min+" INT32_FORMAT, n - min_jint);
1718   else if (n == max_jint)
1719     return "max";
1720   else if (n > max_jint - 10000)
1721     sprintf(buf, "max-" INT32_FORMAT, max_jint - n);
1722   else
1723     sprintf(buf, INT32_FORMAT, n);
1724   return buf;
1725 }
1726 
1727 void TypeInt::dump2( Dict &d, uint depth, outputStream *st ) const {
1728   char buf[40], buf2[40];
1729   if (_lo == min_jint && _hi == max_jint)
1730     st->print("int");
1731   else if (is_con())
1732     st->print("int:%s", intname(buf, get_con()));
1733   else if (_lo == BOOL->_lo && _hi == BOOL->_hi)
1734     st->print("bool");
1735   else if (_lo == BYTE->_lo && _hi == BYTE->_hi)
1736     st->print("byte");
1737   else if (_lo == CHAR->_lo && _hi == CHAR->_hi)
1738     st->print("char");
1739   else if (_lo == SHORT->_lo && _hi == SHORT->_hi)
1740     st->print("short");
1741   else if (_hi == max_jint)
1742     st->print("int:>=%s", intname(buf, _lo));
1743   else if (_lo == min_jint)
1744     st->print("int:<=%s", intname(buf, _hi));
1745   else
1746     st->print("int:%s..%s", intname(buf, _lo), intname(buf2, _hi));
1747 
1748   if (_widen != 0 && this != TypeInt::INT)
1749     st->print(":%.*s", _widen, "wwww");
1750 }
1751 #endif
1752 
1753 //------------------------------singleton--------------------------------------
1754 // TRUE if Type is a singleton type, FALSE otherwise.   Singletons are simple
1755 // constants.
1756 bool TypeInt::singleton(void) const {
1757   return _lo >= _hi;
1758 }
1759 
1760 bool TypeInt::empty(void) const {
1761   return _lo > _hi;
1762 }
1763 
1764 //=============================================================================
1765 // Convenience common pre-built types.
1766 const TypeLong *TypeLong::MAX;
1767 const TypeLong *TypeLong::MIN;
1768 const TypeLong *TypeLong::MINUS_1;// -1
1769 const TypeLong *TypeLong::ZERO; // 0
1770 const TypeLong *TypeLong::ONE;  // 1
1771 const TypeLong *TypeLong::POS;  // >=0
1772 const TypeLong *TypeLong::LONG; // 64-bit integers
1773 const TypeLong *TypeLong::INT;  // 32-bit subrange
1774 const TypeLong *TypeLong::UINT; // 32-bit unsigned subrange
1775 const TypeLong *TypeLong::TYPE_DOMAIN; // alias for TypeLong::LONG
1776 
1777 //------------------------------TypeLong---------------------------------------
1778 TypeLong::TypeLong(jlong lo, jlong hi, int w) : TypeInteger(Long), _lo(lo), _hi(hi), _widen(w) {
1779 }
1780 
1781 //------------------------------make-------------------------------------------
1782 const TypeLong *TypeLong::make( jlong lo ) {
1783   return (TypeLong*)(new TypeLong(lo,lo,WidenMin))->hashcons();
1784 }
1785 
1786 static int normalize_long_widen( jlong lo, jlong hi, int w ) {
1787   // Certain normalizations keep us sane when comparing types.
1788   // The 'SMALLINT' covers constants.
1789   if (lo <= hi) {
1790     if (((julong)hi - lo) <= SMALLINT)   w = Type::WidenMin;
1791     if (((julong)hi - lo) >= max_julong) w = Type::WidenMax; // TypeLong::LONG
1792   } else {
1793     if (((julong)lo - hi) <= SMALLINT)   w = Type::WidenMin;
1794     if (((julong)lo - hi) >= max_julong) w = Type::WidenMin; // dual TypeLong::LONG
1795   }
1796   return w;
1797 }
1798 
1799 const TypeLong *TypeLong::make( jlong lo, jlong hi, int w ) {
1800   w = normalize_long_widen(lo, hi, w);
1801   return (TypeLong*)(new TypeLong(lo,hi,w))->hashcons();
1802 }
1803 
1804 
1805 //------------------------------meet-------------------------------------------
1806 // Compute the MEET of two types.  It returns a new Type representation object
1807 // with reference count equal to the number of Types pointing at it.
1808 // Caller should wrap a Types around it.
1809 const Type *TypeLong::xmeet( const Type *t ) const {
1810   // Perform a fast test for common case; meeting the same types together.
1811   if( this == t ) return this;  // Meeting same type?
1812 
1813   // Currently "this->_base" is a TypeLong
1814   switch (t->base()) {          // Switch on original type
1815   case AnyPtr:                  // Mixing with oops happens when javac
1816   case RawPtr:                  // reuses local variables
1817   case OopPtr:
1818   case InstPtr:
1819   case AryPtr:
1820   case MetadataPtr:
1821   case KlassPtr:
1822   case InstKlassPtr:
1823   case AryKlassPtr:
1824   case NarrowOop:
1825   case NarrowKlass:
1826   case Int:
1827   case FloatTop:
1828   case FloatCon:
1829   case FloatBot:
1830   case DoubleTop:
1831   case DoubleCon:
1832   case DoubleBot:
1833   case Bottom:                  // Ye Olde Default
1834     return Type::BOTTOM;
1835   default:                      // All else is a mistake
1836     typerr(t);
1837   case Top:                     // No change
1838     return this;
1839   case Long:                    // Long vs Long?
1840     break;
1841   }
1842 
1843   // Expand covered set
1844   const TypeLong *r = t->is_long(); // Turn into a TypeLong
1845   return make( MIN2(_lo,r->_lo), MAX2(_hi,r->_hi), MAX2(_widen,r->_widen) );
1846 }
1847 
1848 //------------------------------xdual------------------------------------------
1849 // Dual: reverse hi & lo; flip widen
1850 const Type *TypeLong::xdual() const {
1851   int w = normalize_long_widen(_hi,_lo, WidenMax-_widen);
1852   return new TypeLong(_hi,_lo,w);
1853 }
1854 
1855 //------------------------------widen------------------------------------------
1856 // Only happens for optimistic top-down optimizations.
1857 const Type *TypeLong::widen( const Type *old, const Type* limit ) const {
1858   // Coming from TOP or such; no widening
1859   if( old->base() != Long ) return this;
1860   const TypeLong *ot = old->is_long();
1861 
1862   // If new guy is equal to old guy, no widening
1863   if( _lo == ot->_lo && _hi == ot->_hi )
1864     return old;
1865 
1866   // If new guy contains old, then we widened
1867   if( _lo <= ot->_lo && _hi >= ot->_hi ) {
1868     // New contains old
1869     // If new guy is already wider than old, no widening
1870     if( _widen > ot->_widen ) return this;
1871     // If old guy was a constant, do not bother
1872     if (ot->_lo == ot->_hi)  return this;
1873     // Now widen new guy.
1874     // Check for widening too far
1875     if (_widen == WidenMax) {
1876       jlong max = max_jlong;
1877       jlong min = min_jlong;
1878       if (limit->isa_long()) {
1879         max = limit->is_long()->_hi;
1880         min = limit->is_long()->_lo;
1881       }
1882       if (min < _lo && _hi < max) {
1883         // If neither endpoint is extremal yet, push out the endpoint
1884         // which is closer to its respective limit.
1885         if (_lo >= 0 ||                 // easy common case
1886             ((julong)_lo - min) >= ((julong)max - _hi)) {
1887           // Try to widen to an unsigned range type of 32/63 bits:
1888           if (max >= max_juint && _hi < max_juint)
1889             return make(_lo, max_juint, WidenMax);
1890           else
1891             return make(_lo, max, WidenMax);
1892         } else {
1893           return make(min, _hi, WidenMax);
1894         }
1895       }
1896       return TypeLong::LONG;
1897     }
1898     // Returned widened new guy
1899     return make(_lo,_hi,_widen+1);
1900   }
1901 
1902   // If old guy contains new, then we probably widened too far & dropped to
1903   // bottom.  Return the wider fellow.
1904   if ( ot->_lo <= _lo && ot->_hi >= _hi )
1905     return old;
1906 
1907   //  fatal("Long value range is not subset");
1908   // return this;
1909   return TypeLong::LONG;
1910 }
1911 
1912 //------------------------------narrow----------------------------------------
1913 // Only happens for pessimistic optimizations.
1914 const Type *TypeLong::narrow( const Type *old ) const {
1915   if (_lo >= _hi)  return this;   // already narrow enough
1916   if (old == NULL)  return this;
1917   const TypeLong* ot = old->isa_long();
1918   if (ot == NULL)  return this;
1919   jlong olo = ot->_lo;
1920   jlong ohi = ot->_hi;
1921 
1922   // If new guy is equal to old guy, no narrowing
1923   if (_lo == olo && _hi == ohi)  return old;
1924 
1925   // If old guy was maximum range, allow the narrowing
1926   if (olo == min_jlong && ohi == max_jlong)  return this;
1927 
1928   if (_lo < olo || _hi > ohi)
1929     return this;                // doesn't narrow; pretty wierd
1930 
1931   // The new type narrows the old type, so look for a "death march".
1932   // See comments on PhaseTransform::saturate.
1933   julong nrange = _hi - _lo;
1934   julong orange = ohi - olo;
1935   if (nrange < max_julong - 1 && nrange > (orange >> 1) + (SMALLINT*2)) {
1936     // Use the new type only if the range shrinks a lot.
1937     // We do not want the optimizer computing 2^31 point by point.
1938     return old;
1939   }
1940 
1941   return this;
1942 }
1943 
1944 //-----------------------------filter------------------------------------------
1945 const Type *TypeLong::filter_helper(const Type *kills, bool include_speculative) const {
1946   const TypeLong* ft = join_helper(kills, include_speculative)->isa_long();
1947   if (ft == NULL || ft->empty())
1948     return Type::TOP;           // Canonical empty value
1949   if (ft->_widen < this->_widen) {
1950     // Do not allow the value of kill->_widen to affect the outcome.
1951     // The widen bits must be allowed to run freely through the graph.
1952     ft = TypeLong::make(ft->_lo, ft->_hi, this->_widen);
1953   }
1954   return ft;
1955 }
1956 
1957 //------------------------------eq---------------------------------------------
1958 // Structural equality check for Type representations
1959 bool TypeLong::eq( const Type *t ) const {
1960   const TypeLong *r = t->is_long(); // Handy access
1961   return r->_lo == _lo &&  r->_hi == _hi  && r->_widen == _widen;
1962 }
1963 
1964 //------------------------------hash-------------------------------------------
1965 // Type-specific hashing function.
1966 int TypeLong::hash(void) const {
1967   return (int)(_lo+_hi+_widen+(int)Type::Long);
1968 }
1969 
1970 //------------------------------is_finite--------------------------------------
1971 // Has a finite value
1972 bool TypeLong::is_finite() const {
1973   return true;
1974 }
1975 
1976 //------------------------------dump2------------------------------------------
1977 // Dump TypeLong
1978 #ifndef PRODUCT
1979 static const char* longnamenear(jlong x, const char* xname, char* buf, jlong n) {
1980   if (n > x) {
1981     if (n >= x + 10000)  return NULL;
1982     sprintf(buf, "%s+" JLONG_FORMAT, xname, n - x);
1983   } else if (n < x) {
1984     if (n <= x - 10000)  return NULL;
1985     sprintf(buf, "%s-" JLONG_FORMAT, xname, x - n);
1986   } else {
1987     return xname;
1988   }
1989   return buf;
1990 }
1991 
1992 static const char* longname(char* buf, jlong n) {
1993   const char* str;
1994   if (n == min_jlong)
1995     return "min";
1996   else if (n < min_jlong + 10000)
1997     sprintf(buf, "min+" JLONG_FORMAT, n - min_jlong);
1998   else if (n == max_jlong)
1999     return "max";
2000   else if (n > max_jlong - 10000)
2001     sprintf(buf, "max-" JLONG_FORMAT, max_jlong - n);
2002   else if ((str = longnamenear(max_juint, "maxuint", buf, n)) != NULL)
2003     return str;
2004   else if ((str = longnamenear(max_jint, "maxint", buf, n)) != NULL)
2005     return str;
2006   else if ((str = longnamenear(min_jint, "minint", buf, n)) != NULL)
2007     return str;
2008   else
2009     sprintf(buf, JLONG_FORMAT, n);
2010   return buf;
2011 }
2012 
2013 void TypeLong::dump2( Dict &d, uint depth, outputStream *st ) const {
2014   char buf[80], buf2[80];
2015   if (_lo == min_jlong && _hi == max_jlong)
2016     st->print("long");
2017   else if (is_con())
2018     st->print("long:%s", longname(buf, get_con()));
2019   else if (_hi == max_jlong)
2020     st->print("long:>=%s", longname(buf, _lo));
2021   else if (_lo == min_jlong)
2022     st->print("long:<=%s", longname(buf, _hi));
2023   else
2024     st->print("long:%s..%s", longname(buf, _lo), longname(buf2, _hi));
2025 
2026   if (_widen != 0 && this != TypeLong::LONG)
2027     st->print(":%.*s", _widen, "wwww");
2028 }
2029 #endif
2030 
2031 //------------------------------singleton--------------------------------------
2032 // TRUE if Type is a singleton type, FALSE otherwise.   Singletons are simple
2033 // constants
2034 bool TypeLong::singleton(void) const {
2035   return _lo >= _hi;
2036 }
2037 
2038 bool TypeLong::empty(void) const {
2039   return _lo > _hi;
2040 }
2041 
2042 //=============================================================================
2043 // Convenience common pre-built types.
2044 const TypeTuple *TypeTuple::IFBOTH;     // Return both arms of IF as reachable
2045 const TypeTuple *TypeTuple::IFFALSE;
2046 const TypeTuple *TypeTuple::IFTRUE;
2047 const TypeTuple *TypeTuple::IFNEITHER;
2048 const TypeTuple *TypeTuple::LOOPBODY;
2049 const TypeTuple *TypeTuple::MEMBAR;
2050 const TypeTuple *TypeTuple::STORECONDITIONAL;
2051 const TypeTuple *TypeTuple::START_I2C;
2052 const TypeTuple *TypeTuple::INT_PAIR;
2053 const TypeTuple *TypeTuple::LONG_PAIR;
2054 const TypeTuple *TypeTuple::INT_CC_PAIR;
2055 const TypeTuple *TypeTuple::LONG_CC_PAIR;
2056 
2057 static void collect_inline_fields(ciInlineKlass* vk, const Type** field_array, uint& pos) {
2058   for (int j = 0; j < vk->nof_nonstatic_fields(); j++) {
2059     ciField* field = vk->nonstatic_field_at(j);
2060     BasicType bt = field->type()->basic_type();
2061     const Type* ft = Type::get_const_type(field->type());
2062     field_array[pos++] = ft;
2063     if (type2size[bt] == 2) {
2064       field_array[pos++] = Type::HALF;
2065     }
2066   }
2067 }
2068 
2069 //------------------------------make-------------------------------------------
2070 // Make a TypeTuple from the range of a method signature
2071 const TypeTuple *TypeTuple::make_range(ciSignature* sig, bool ret_vt_fields) {
2072   ciType* return_type = sig->return_type();
2073   uint arg_cnt = return_type->size();
2074   if (ret_vt_fields) {
2075     arg_cnt = return_type->as_inline_klass()->inline_arg_slots() + 1;
2076   }
2077 
2078   const Type **field_array = fields(arg_cnt);
2079   switch (return_type->basic_type()) {
2080   case T_LONG:
2081     field_array[TypeFunc::Parms]   = TypeLong::LONG;
2082     field_array[TypeFunc::Parms+1] = Type::HALF;
2083     break;
2084   case T_DOUBLE:
2085     field_array[TypeFunc::Parms]   = Type::DOUBLE;
2086     field_array[TypeFunc::Parms+1] = Type::HALF;
2087     break;
2088   case T_OBJECT:
2089   case T_ARRAY:
2090   case T_BOOLEAN:
2091   case T_CHAR:
2092   case T_FLOAT:
2093   case T_BYTE:
2094   case T_SHORT:
2095   case T_INT:
2096     field_array[TypeFunc::Parms] = get_const_type(return_type);
2097     break;
2098   case T_INLINE_TYPE:
2099     if (ret_vt_fields) {
2100       uint pos = TypeFunc::Parms;
2101       field_array[pos++] = get_const_type(return_type); // Oop might be null when returning as fields
2102       collect_inline_fields(return_type->as_inline_klass(), field_array, pos);
2103     } else {
2104       field_array[TypeFunc::Parms] = get_const_type(return_type)->join_speculative(sig->returns_null_free_inline_type() ? TypePtr::NOTNULL : TypePtr::BOTTOM);
2105     }
2106     break;
2107   case T_VOID:
2108     break;
2109   default:
2110     ShouldNotReachHere();
2111   }
2112   return (TypeTuple*)(new TypeTuple(TypeFunc::Parms + arg_cnt, field_array))->hashcons();
2113 }
2114 
2115 // Make a TypeTuple from the domain of a method signature
2116 const TypeTuple *TypeTuple::make_domain(ciMethod* method, bool vt_fields_as_args) {
2117   ciSignature* sig = method->signature();
2118   uint arg_cnt = sig->size() + (method->is_static() ? 0 : 1);
2119   if (vt_fields_as_args) {
2120     arg_cnt = 0;
2121     for (ExtendedSignature sig_cc = ExtendedSignature(method->get_sig_cc(), SigEntryFilter()); !sig_cc.at_end(); ++sig_cc) {
2122       arg_cnt += type2size[(*sig_cc)._bt];
2123     }
2124   }
2125 
2126   uint pos = TypeFunc::Parms;
2127   const Type** field_array = fields(arg_cnt);
2128   if (!method->is_static()) {
2129     ciInstanceKlass* recv = method->holder();
2130     if (vt_fields_as_args && recv->is_inlinetype() && recv->as_inline_klass()->can_be_passed_as_fields()) {
2131       collect_inline_fields(recv->as_inline_klass(), field_array, pos);
2132     } else {
2133       field_array[pos++] = get_const_type(recv)->join_speculative(TypePtr::NOTNULL);
2134     }
2135   }
2136 
2137   int i = 0;
2138   while (pos < TypeFunc::Parms + arg_cnt) {
2139     ciType* type = sig->type_at(i);
2140     BasicType bt = type->basic_type();
2141 
2142     switch (bt) {
2143     case T_LONG:
2144       field_array[pos++] = TypeLong::LONG;
2145       field_array[pos++] = Type::HALF;
2146       break;
2147     case T_DOUBLE:
2148       field_array[pos++] = Type::DOUBLE;
2149       field_array[pos++] = Type::HALF;
2150       break;
2151     case T_OBJECT:
2152     case T_ARRAY:
2153     case T_FLOAT:
2154     case T_INT:
2155       field_array[pos++] = get_const_type(type);
2156       break;
2157     case T_BOOLEAN:
2158     case T_CHAR:
2159     case T_BYTE:
2160     case T_SHORT:
2161       field_array[pos++] = TypeInt::INT;
2162       break;
2163     case T_INLINE_TYPE: {
2164       bool is_null_free = sig->is_null_free_at(i);
2165       if (vt_fields_as_args && type->as_inline_klass()->can_be_passed_as_fields() && is_null_free) {
2166         collect_inline_fields(type->as_inline_klass(), field_array, pos);
2167       } else {
2168         field_array[pos++] = get_const_type(type)->join_speculative(is_null_free ? TypePtr::NOTNULL : TypePtr::BOTTOM);
2169       }
2170       break;
2171     }
2172     default:
2173       ShouldNotReachHere();
2174     }
2175     i++;
2176   }
2177   assert(pos == TypeFunc::Parms + arg_cnt, "wrong number of arguments");
2178 
2179   return (TypeTuple*)(new TypeTuple(TypeFunc::Parms + arg_cnt, field_array))->hashcons();
2180 }
2181 
2182 const TypeTuple *TypeTuple::make( uint cnt, const Type **fields ) {
2183   return (TypeTuple*)(new TypeTuple(cnt,fields))->hashcons();
2184 }
2185 
2186 //------------------------------fields-----------------------------------------
2187 // Subroutine call type with space allocated for argument types
2188 // Memory for Control, I_O, Memory, FramePtr, and ReturnAdr is allocated implicitly
2189 const Type **TypeTuple::fields( uint arg_cnt ) {
2190   const Type **flds = (const Type **)(Compile::current()->type_arena()->AmallocWords((TypeFunc::Parms+arg_cnt)*sizeof(Type*) ));
2191   flds[TypeFunc::Control  ] = Type::CONTROL;
2192   flds[TypeFunc::I_O      ] = Type::ABIO;
2193   flds[TypeFunc::Memory   ] = Type::MEMORY;
2194   flds[TypeFunc::FramePtr ] = TypeRawPtr::BOTTOM;
2195   flds[TypeFunc::ReturnAdr] = Type::RETURN_ADDRESS;
2196 
2197   return flds;
2198 }
2199 
2200 //------------------------------meet-------------------------------------------
2201 // Compute the MEET of two types.  It returns a new Type object.
2202 const Type *TypeTuple::xmeet( const Type *t ) const {
2203   // Perform a fast test for common case; meeting the same types together.
2204   if( this == t ) return this;  // Meeting same type-rep?
2205 
2206   // Current "this->_base" is Tuple
2207   switch (t->base()) {          // switch on original type
2208 
2209   case Bottom:                  // Ye Olde Default
2210     return t;
2211 
2212   default:                      // All else is a mistake
2213     typerr(t);
2214 
2215   case Tuple: {                 // Meeting 2 signatures?
2216     const TypeTuple *x = t->is_tuple();
2217     assert( _cnt == x->_cnt, "" );
2218     const Type **fields = (const Type **)(Compile::current()->type_arena()->AmallocWords( _cnt*sizeof(Type*) ));
2219     for( uint i=0; i<_cnt; i++ )
2220       fields[i] = field_at(i)->xmeet( x->field_at(i) );
2221     return TypeTuple::make(_cnt,fields);
2222   }
2223   case Top:
2224     break;
2225   }
2226   return this;                  // Return the double constant
2227 }
2228 
2229 //------------------------------xdual------------------------------------------
2230 // Dual: compute field-by-field dual
2231 const Type *TypeTuple::xdual() const {
2232   const Type **fields = (const Type **)(Compile::current()->type_arena()->AmallocWords( _cnt*sizeof(Type*) ));
2233   for( uint i=0; i<_cnt; i++ )
2234     fields[i] = _fields[i]->dual();
2235   return new TypeTuple(_cnt,fields);
2236 }
2237 
2238 //------------------------------eq---------------------------------------------
2239 // Structural equality check for Type representations
2240 bool TypeTuple::eq( const Type *t ) const {
2241   const TypeTuple *s = (const TypeTuple *)t;
2242   if (_cnt != s->_cnt)  return false;  // Unequal field counts
2243   for (uint i = 0; i < _cnt; i++)
2244     if (field_at(i) != s->field_at(i)) // POINTER COMPARE!  NO RECURSION!
2245       return false;             // Missed
2246   return true;
2247 }
2248 
2249 //------------------------------hash-------------------------------------------
2250 // Type-specific hashing function.
2251 int TypeTuple::hash(void) const {
2252   intptr_t sum = _cnt;
2253   for( uint i=0; i<_cnt; i++ )
2254     sum += (intptr_t)_fields[i];     // Hash on pointers directly
2255   return sum;
2256 }
2257 
2258 //------------------------------dump2------------------------------------------
2259 // Dump signature Type
2260 #ifndef PRODUCT
2261 void TypeTuple::dump2( Dict &d, uint depth, outputStream *st ) const {
2262   st->print("{");
2263   if( !depth || d[this] ) {     // Check for recursive print
2264     st->print("...}");
2265     return;
2266   }
2267   d.Insert((void*)this, (void*)this);   // Stop recursion
2268   if( _cnt ) {
2269     uint i;
2270     for( i=0; i<_cnt-1; i++ ) {
2271       st->print("%d:", i);
2272       _fields[i]->dump2(d, depth-1, st);
2273       st->print(", ");
2274     }
2275     st->print("%d:", i);
2276     _fields[i]->dump2(d, depth-1, st);
2277   }
2278   st->print("}");
2279 }
2280 #endif
2281 
2282 //------------------------------singleton--------------------------------------
2283 // TRUE if Type is a singleton type, FALSE otherwise.   Singletons are simple
2284 // constants (Ldi nodes).  Singletons are integer, float or double constants
2285 // or a single symbol.
2286 bool TypeTuple::singleton(void) const {
2287   return false;                 // Never a singleton
2288 }
2289 
2290 bool TypeTuple::empty(void) const {
2291   for( uint i=0; i<_cnt; i++ ) {
2292     if (_fields[i]->empty())  return true;
2293   }
2294   return false;
2295 }
2296 
2297 //=============================================================================
2298 // Convenience common pre-built types.
2299 
2300 inline const TypeInt* normalize_array_size(const TypeInt* size) {
2301   // Certain normalizations keep us sane when comparing types.
2302   // We do not want arrayOop variables to differ only by the wideness
2303   // of their index types.  Pick minimum wideness, since that is the
2304   // forced wideness of small ranges anyway.
2305   if (size->_widen != Type::WidenMin)
2306     return TypeInt::make(size->_lo, size->_hi, Type::WidenMin);
2307   else
2308     return size;
2309 }
2310 
2311 //------------------------------make-------------------------------------------
2312 const TypeAry* TypeAry::make(const Type* elem, const TypeInt* size, bool stable,
2313                              bool not_flat, bool not_null_free) {
2314   if (UseCompressedOops && elem->isa_oopptr()) {
2315     elem = elem->make_narrowoop();
2316   }
2317   size = normalize_array_size(size);
2318   return (TypeAry*)(new TypeAry(elem, size, stable, not_flat, not_null_free))->hashcons();
2319 }
2320 
2321 //------------------------------meet-------------------------------------------
2322 // Compute the MEET of two types.  It returns a new Type object.
2323 const Type *TypeAry::xmeet( const Type *t ) const {
2324   // Perform a fast test for common case; meeting the same types together.
2325   if( this == t ) return this;  // Meeting same type-rep?
2326 
2327   // Current "this->_base" is Ary
2328   switch (t->base()) {          // switch on original type
2329 
2330   case Bottom:                  // Ye Olde Default
2331     return t;
2332 
2333   default:                      // All else is a mistake
2334     typerr(t);
2335 
2336   case Array: {                 // Meeting 2 arrays?
2337     const TypeAry *a = t->is_ary();
2338     return TypeAry::make(_elem->meet_speculative(a->_elem),
2339                          _size->xmeet(a->_size)->is_int(),
2340                          _stable && a->_stable,
2341                          _not_flat && a->_not_flat,
2342                          _not_null_free && a->_not_null_free);
2343   }
2344   case Top:
2345     break;
2346   }
2347   return this;                  // Return the double constant
2348 }
2349 
2350 //------------------------------xdual------------------------------------------
2351 // Dual: compute field-by-field dual
2352 const Type *TypeAry::xdual() const {
2353   const TypeInt* size_dual = _size->dual()->is_int();
2354   size_dual = normalize_array_size(size_dual);
2355   return new TypeAry(_elem->dual(), size_dual, !_stable, !_not_flat, !_not_null_free);
2356 }
2357 
2358 //------------------------------eq---------------------------------------------
2359 // Structural equality check for Type representations
2360 bool TypeAry::eq( const Type *t ) const {
2361   const TypeAry *a = (const TypeAry*)t;
2362   return _elem == a->_elem &&
2363     _stable == a->_stable &&
2364     _size == a->_size &&
2365     _not_flat == a->_not_flat &&
2366     _not_null_free == a->_not_null_free;
2367 
2368 }
2369 
2370 //------------------------------hash-------------------------------------------
2371 // Type-specific hashing function.
2372 int TypeAry::hash(void) const {
2373   return (intptr_t)_elem + (intptr_t)_size + (_stable ? 43 : 0);
2374 }
2375 
2376 /**
2377  * Return same type without a speculative part in the element
2378  */
2379 const Type* TypeAry::remove_speculative() const {
2380   return make(_elem->remove_speculative(), _size, _stable, _not_flat, _not_null_free);
2381 }
2382 
2383 /**
2384  * Return same type with cleaned up speculative part of element
2385  */
2386 const Type* TypeAry::cleanup_speculative() const {
2387   return make(_elem->cleanup_speculative(), _size, _stable, _not_flat, _not_null_free);
2388 }
2389 
2390 /**
2391  * Return same type but with a different inline depth (used for speculation)
2392  *
2393  * @param depth  depth to meet with
2394  */
2395 const TypePtr* TypePtr::with_inline_depth(int depth) const {
2396   if (!UseInlineDepthForSpeculativeTypes) {
2397     return this;
2398   }
2399   return make(AnyPtr, _ptr, _offset, _speculative, depth);
2400 }
2401 
2402 //----------------------interface_vs_oop---------------------------------------
2403 #ifdef ASSERT
2404 bool TypeAry::interface_vs_oop(const Type *t) const {
2405   const TypeAry* t_ary = t->is_ary();
2406   if (t_ary) {
2407     const TypePtr* this_ptr = _elem->make_ptr(); // In case we have narrow_oops
2408     const TypePtr*    t_ptr = t_ary->_elem->make_ptr();
2409     if(this_ptr != NULL && t_ptr != NULL) {
2410       return this_ptr->interface_vs_oop(t_ptr);
2411     }
2412   }
2413   return false;
2414 }
2415 #endif
2416 
2417 //------------------------------dump2------------------------------------------
2418 #ifndef PRODUCT
2419 void TypeAry::dump2( Dict &d, uint depth, outputStream *st ) const {
2420   if (_stable)  st->print("stable:");
2421   if (Verbose) {
2422     if (_not_flat) st->print("not flat:");
2423     if (_not_null_free) st->print("not null free:");
2424   }
2425   _elem->dump2(d, depth, st);
2426   st->print("[");
2427   _size->dump2(d, depth, st);
2428   st->print("]");
2429 }
2430 #endif
2431 
2432 //------------------------------singleton--------------------------------------
2433 // TRUE if Type is a singleton type, FALSE otherwise.   Singletons are simple
2434 // constants (Ldi nodes).  Singletons are integer, float or double constants
2435 // or a single symbol.
2436 bool TypeAry::singleton(void) const {
2437   return false;                 // Never a singleton
2438 }
2439 
2440 bool TypeAry::empty(void) const {
2441   return _elem->empty() || _size->empty();
2442 }
2443 
2444 //--------------------------ary_must_be_exact----------------------------------
2445 bool TypeAry::ary_must_be_exact() const {
2446   // This logic looks at the element type of an array, and returns true
2447   // if the element type is either a primitive or a final instance class.
2448   // In such cases, an array built on this ary must have no subclasses.
2449   if (_elem == BOTTOM)      return false;  // general array not exact
2450   if (_elem == TOP   )      return false;  // inverted general array not exact
2451   const TypeOopPtr*  toop = NULL;
2452   if (UseCompressedOops && _elem->isa_narrowoop()) {
2453     toop = _elem->make_ptr()->isa_oopptr();
2454   } else {
2455     toop = _elem->isa_oopptr();
2456   }
2457   if (!toop)                return true;   // a primitive type, like int
2458   ciKlass* tklass = toop->klass();
2459   if (tklass == NULL)       return false;  // unloaded class
2460   if (!tklass->is_loaded()) return false;  // unloaded class
2461   const TypeInstPtr* tinst;
2462   if (_elem->isa_narrowoop())
2463     tinst = _elem->make_ptr()->isa_instptr();
2464   else
2465     tinst = _elem->isa_instptr();
2466   if (tinst) {
2467     if (tklass->as_instance_klass()->is_final()) {
2468       // Even if MyValue is exact, [LMyValue is not exact due to [QMyValue <: [LMyValue.
2469       if (tinst->is_inlinetypeptr() && (tinst->ptr() == TypePtr::BotPTR || tinst->ptr() == TypePtr::TopPTR)) {
2470         return false;
2471       }
2472       return true;
2473     }
2474     return false;
2475   }
2476   const TypeAryPtr*  tap;
2477   if (_elem->isa_narrowoop())
2478     tap = _elem->make_ptr()->isa_aryptr();
2479   else
2480     tap = _elem->isa_aryptr();
2481   if (tap)
2482     return tap->ary()->ary_must_be_exact();
2483   return false;
2484 }
2485 
2486 //==============================TypeInlineType=======================================
2487 
2488 const TypeInlineType* TypeInlineType::BOTTOM;
2489 
2490 //------------------------------make-------------------------------------------
2491 const TypeInlineType* TypeInlineType::make(ciInlineKlass* vk, bool larval) {
2492   return (TypeInlineType*)(new TypeInlineType(vk, larval))->hashcons();
2493 }
2494 
2495 //------------------------------meet-------------------------------------------
2496 // Compute the MEET of two types.  It returns a new Type object.
2497 const Type* TypeInlineType::xmeet(const Type* t) const {
2498   // Perform a fast test for common case; meeting the same types together.
2499   if(this == t) return this;  // Meeting same type-rep?
2500 
2501   // Current "this->_base" is InlineType
2502   switch (t->base()) {          // switch on original type
2503 
2504   case Int:
2505   case Long:
2506   case FloatTop:
2507   case FloatCon:
2508   case FloatBot:
2509   case DoubleTop:
2510   case DoubleCon:
2511   case DoubleBot:
2512   case NarrowKlass:
2513   case Bottom:
2514     return Type::BOTTOM;
2515 
2516   case OopPtr:
2517   case MetadataPtr:
2518   case KlassPtr:
2519   case RawPtr:
2520   case AnyPtr:
2521     return TypePtr::BOTTOM;
2522 
2523   case Top:
2524     return this;
2525 
2526   case NarrowOop: {
2527     const Type* res = t->make_ptr()->xmeet(this);
2528     if (res->isa_ptr()) {
2529       return res->make_narrowoop();
2530     }
2531     return res;
2532   }
2533 
2534   case InstKlassPtr:
2535   case AryKlassPtr:
2536   case AryPtr:
2537   case InstPtr: {
2538     return t->xmeet(this);
2539   }
2540 
2541   case InlineType: {
2542     // All inline types inherit from Object
2543     const TypeInlineType* other = t->is_inlinetype();
2544     if (_vk == NULL) {
2545       return this;
2546     } else if (other->_vk == NULL) {
2547       return other;
2548     } else if (_vk == other->_vk) {
2549       if (_larval == other->_larval ||
2550           !_larval) {
2551         return this;
2552       } else {
2553         return t;
2554       }
2555     }
2556     return TypeInstPtr::NOTNULL;
2557   }
2558 
2559   default:                      // All else is a mistake
2560     typerr(t);
2561 
2562   }
2563   return this;
2564 }
2565 
2566 //------------------------------xdual------------------------------------------
2567 const Type* TypeInlineType::xdual() const {
2568   return this;
2569 }
2570 
2571 //------------------------------eq---------------------------------------------
2572 // Structural equality check for Type representations
2573 bool TypeInlineType::eq(const Type* t) const {
2574   const TypeInlineType* vt = t->is_inlinetype();
2575   return (_vk == vt->inline_klass() && _larval == vt->larval());
2576 }
2577 
2578 //------------------------------hash-------------------------------------------
2579 // Type-specific hashing function.
2580 int TypeInlineType::hash(void) const {
2581   return (intptr_t)_vk;
2582 }
2583 
2584 //------------------------------singleton--------------------------------------
2585 // TRUE if Type is a singleton type, FALSE otherwise. Singletons are simple constants.
2586 bool TypeInlineType::singleton(void) const {
2587   return false;
2588 }
2589 
2590 //------------------------------empty------------------------------------------
2591 // TRUE if Type is a type with no values, FALSE otherwise.
2592 bool TypeInlineType::empty(void) const {
2593   return false;
2594 }
2595 
2596 //------------------------------dump2------------------------------------------
2597 #ifndef PRODUCT
2598 void TypeInlineType::dump2(Dict &d, uint depth, outputStream* st) const {
2599   if (_vk == NULL) {
2600     st->print("BOTTOM inlinetype");
2601     return;
2602   }
2603   int count = _vk->nof_declared_nonstatic_fields();
2604   st->print("inlinetype[%d]:{", count);
2605   st->print("%s", count != 0 ? _vk->declared_nonstatic_field_at(0)->type()->name() : "empty");
2606   for (int i = 1; i < count; ++i) {
2607     st->print(", %s", _vk->declared_nonstatic_field_at(i)->type()->name());
2608   }
2609   st->print("}%s", _larval?" : larval":"");
2610 }
2611 #endif
2612 
2613 //==============================TypeVect=======================================
2614 // Convenience common pre-built types.
2615 const TypeVect *TypeVect::VECTA = NULL; // vector length agnostic
2616 const TypeVect *TypeVect::VECTS = NULL; //  32-bit vectors
2617 const TypeVect *TypeVect::VECTD = NULL; //  64-bit vectors
2618 const TypeVect *TypeVect::VECTX = NULL; // 128-bit vectors
2619 const TypeVect *TypeVect::VECTY = NULL; // 256-bit vectors
2620 const TypeVect *TypeVect::VECTZ = NULL; // 512-bit vectors
2621 const TypeVect *TypeVect::VECTMASK = NULL; // predicate/mask vector
2622 
2623 //------------------------------make-------------------------------------------
2624 const TypeVect* TypeVect::make(const Type *elem, uint length) {
2625   BasicType elem_bt = elem->array_element_basic_type();
2626   assert(is_java_primitive(elem_bt), "only primitive types in vector");
2627   assert(Matcher::vector_size_supported(elem_bt, length), "length in range");
2628   int size = length * type2aelembytes(elem_bt);
2629   switch (Matcher::vector_ideal_reg(size)) {
2630   case Op_VecA:
2631     return (TypeVect*)(new TypeVectA(elem, length))->hashcons();
2632   case Op_VecS:
2633     return (TypeVect*)(new TypeVectS(elem, length))->hashcons();
2634   case Op_RegL:
2635   case Op_VecD:
2636   case Op_RegD:
2637     return (TypeVect*)(new TypeVectD(elem, length))->hashcons();
2638   case Op_VecX:
2639     return (TypeVect*)(new TypeVectX(elem, length))->hashcons();
2640   case Op_VecY:
2641     return (TypeVect*)(new TypeVectY(elem, length))->hashcons();
2642   case Op_VecZ:
2643     return (TypeVect*)(new TypeVectZ(elem, length))->hashcons();
2644   }
2645  ShouldNotReachHere();
2646   return NULL;
2647 }
2648 
2649 const TypeVect *TypeVect::makemask(const Type* elem, uint length) {
2650   if (Matcher::has_predicated_vectors()) {
2651     const TypeVect* mtype = Matcher::predicate_reg_type(elem, length);
2652     return (TypeVect*)(const_cast<TypeVect*>(mtype))->hashcons();
2653   } else {
2654     return make(elem, length);
2655   }
2656 }
2657 
2658 //------------------------------meet-------------------------------------------
2659 // Compute the MEET of two types.  It returns a new Type object.
2660 const Type *TypeVect::xmeet( const Type *t ) const {
2661   // Perform a fast test for common case; meeting the same types together.
2662   if( this == t ) return this;  // Meeting same type-rep?
2663 
2664   // Current "this->_base" is Vector
2665   switch (t->base()) {          // switch on original type
2666 
2667   case Bottom:                  // Ye Olde Default
2668     return t;
2669 
2670   default:                      // All else is a mistake
2671     typerr(t);
2672   case VectorMask: {
2673     const TypeVectMask* v = t->is_vectmask();
2674     assert(  base() == v->base(), "");
2675     assert(length() == v->length(), "");
2676     assert(element_basic_type() == v->element_basic_type(), "");
2677     return TypeVect::makemask(_elem->xmeet(v->_elem), _length);
2678   }
2679   case VectorA:
2680   case VectorS:
2681   case VectorD:
2682   case VectorX:
2683   case VectorY:
2684   case VectorZ: {                // Meeting 2 vectors?
2685     const TypeVect* v = t->is_vect();
2686     assert(  base() == v->base(), "");
2687     assert(length() == v->length(), "");
2688     assert(element_basic_type() == v->element_basic_type(), "");
2689     return TypeVect::make(_elem->xmeet(v->_elem), _length);
2690   }
2691   case Top:
2692     break;
2693   }
2694   return this;
2695 }
2696 
2697 //------------------------------xdual------------------------------------------
2698 // Dual: compute field-by-field dual
2699 const Type *TypeVect::xdual() const {
2700   return new TypeVect(base(), _elem->dual(), _length);
2701 }
2702 
2703 //------------------------------eq---------------------------------------------
2704 // Structural equality check for Type representations
2705 bool TypeVect::eq(const Type *t) const {
2706   const TypeVect *v = t->is_vect();
2707   return (_elem == v->_elem) && (_length == v->_length);
2708 }
2709 
2710 //------------------------------hash-------------------------------------------
2711 // Type-specific hashing function.
2712 int TypeVect::hash(void) const {
2713   return (intptr_t)_elem + (intptr_t)_length;
2714 }
2715 
2716 //------------------------------singleton--------------------------------------
2717 // TRUE if Type is a singleton type, FALSE otherwise.   Singletons are simple
2718 // constants (Ldi nodes).  Vector is singleton if all elements are the same
2719 // constant value (when vector is created with Replicate code).
2720 bool TypeVect::singleton(void) const {
2721 // There is no Con node for vectors yet.
2722 //  return _elem->singleton();
2723   return false;
2724 }
2725 
2726 bool TypeVect::empty(void) const {
2727   return _elem->empty();
2728 }
2729 
2730 //------------------------------dump2------------------------------------------
2731 #ifndef PRODUCT
2732 void TypeVect::dump2(Dict &d, uint depth, outputStream *st) const {
2733   switch (base()) {
2734   case VectorA:
2735     st->print("vectora["); break;
2736   case VectorS:
2737     st->print("vectors["); break;
2738   case VectorD:
2739     st->print("vectord["); break;
2740   case VectorX:
2741     st->print("vectorx["); break;
2742   case VectorY:
2743     st->print("vectory["); break;
2744   case VectorZ:
2745     st->print("vectorz["); break;
2746   case VectorMask:
2747     st->print("vectormask["); break;
2748   default:
2749     ShouldNotReachHere();
2750   }
2751   st->print("%d]:{", _length);
2752   _elem->dump2(d, depth, st);
2753   st->print("}");
2754 }
2755 #endif
2756 
2757 bool TypeVectMask::eq(const Type *t) const {
2758   const TypeVectMask *v = t->is_vectmask();
2759   return (element_type() == v->element_type()) && (length() == v->length());
2760 }
2761 
2762 const Type *TypeVectMask::xdual() const {
2763   return new TypeVectMask(element_type()->dual(), length());
2764 }
2765 
2766 //=============================================================================
2767 // Convenience common pre-built types.
2768 const TypePtr *TypePtr::NULL_PTR;
2769 const TypePtr *TypePtr::NOTNULL;
2770 const TypePtr *TypePtr::BOTTOM;
2771 
2772 //------------------------------meet-------------------------------------------
2773 // Meet over the PTR enum
2774 const TypePtr::PTR TypePtr::ptr_meet[TypePtr::lastPTR][TypePtr::lastPTR] = {
2775   //              TopPTR,    AnyNull,   Constant, Null,   NotNull, BotPTR,
2776   { /* Top     */ TopPTR,    AnyNull,   Constant, Null,   NotNull, BotPTR,},
2777   { /* AnyNull */ AnyNull,   AnyNull,   Constant, BotPTR, NotNull, BotPTR,},
2778   { /* Constant*/ Constant,  Constant,  Constant, BotPTR, NotNull, BotPTR,},
2779   { /* Null    */ Null,      BotPTR,    BotPTR,   Null,   BotPTR,  BotPTR,},
2780   { /* NotNull */ NotNull,   NotNull,   NotNull,  BotPTR, NotNull, BotPTR,},
2781   { /* BotPTR  */ BotPTR,    BotPTR,    BotPTR,   BotPTR, BotPTR,  BotPTR,}
2782 };
2783 
2784 //------------------------------make-------------------------------------------
2785 const TypePtr* TypePtr::make(TYPES t, enum PTR ptr, Offset offset, const TypePtr* speculative, int inline_depth) {
2786   return (TypePtr*)(new TypePtr(t,ptr,offset, speculative, inline_depth))->hashcons();
2787 }
2788 
2789 //------------------------------cast_to_ptr_type-------------------------------
2790 const Type *TypePtr::cast_to_ptr_type(PTR ptr) const {
2791   assert(_base == AnyPtr, "subclass must override cast_to_ptr_type");
2792   if( ptr == _ptr ) return this;
2793   return make(_base, ptr, _offset, _speculative, _inline_depth);
2794 }
2795 
2796 //------------------------------get_con----------------------------------------
2797 intptr_t TypePtr::get_con() const {
2798   assert( _ptr == Null, "" );
2799   return offset();
2800 }
2801 
2802 //------------------------------meet-------------------------------------------
2803 // Compute the MEET of two types.  It returns a new Type object.
2804 const Type *TypePtr::xmeet(const Type *t) const {
2805   const Type* res = xmeet_helper(t);
2806   if (res->isa_ptr() == NULL) {
2807     return res;
2808   }
2809 
2810   const TypePtr* res_ptr = res->is_ptr();
2811   if (res_ptr->speculative() != NULL) {
2812     // type->speculative() == NULL means that speculation is no better
2813     // than type, i.e. type->speculative() == type. So there are 2
2814     // ways to represent the fact that we have no useful speculative
2815     // data and we should use a single one to be able to test for
2816     // equality between types. Check whether type->speculative() ==
2817     // type and set speculative to NULL if it is the case.
2818     if (res_ptr->remove_speculative() == res_ptr->speculative()) {
2819       return res_ptr->remove_speculative();
2820     }
2821   }
2822 
2823   return res;
2824 }
2825 
2826 const Type *TypePtr::xmeet_helper(const Type *t) const {
2827   // Perform a fast test for common case; meeting the same types together.
2828   if( this == t ) return this;  // Meeting same type-rep?
2829 
2830   // Current "this->_base" is AnyPtr
2831   switch (t->base()) {          // switch on original type
2832   case Int:                     // Mixing ints & oops happens when javac
2833   case Long:                    // reuses local variables
2834   case FloatTop:
2835   case FloatCon:
2836   case FloatBot:
2837   case DoubleTop:
2838   case DoubleCon:
2839   case DoubleBot:
2840   case NarrowOop:
2841   case NarrowKlass:
2842   case Bottom:                  // Ye Olde Default
2843     return Type::BOTTOM;
2844   case Top:
2845     return this;
2846 
2847   case AnyPtr: {                // Meeting to AnyPtrs
2848     const TypePtr *tp = t->is_ptr();
2849     const TypePtr* speculative = xmeet_speculative(tp);
2850     int depth = meet_inline_depth(tp->inline_depth());
2851     return make(AnyPtr, meet_ptr(tp->ptr()), meet_offset(tp->offset()), speculative, depth);
2852   }
2853   case RawPtr:                  // For these, flip the call around to cut down
2854   case OopPtr:
2855   case InstPtr:                 // on the cases I have to handle.
2856   case AryPtr:
2857   case MetadataPtr:
2858   case KlassPtr:
2859   case InstKlassPtr:
2860   case AryKlassPtr:
2861   case InlineType:
2862     return t->xmeet(this);      // Call in reverse direction
2863   default:                      // All else is a mistake
2864     typerr(t);
2865 
2866   }
2867   return this;
2868 }
2869 
2870 //------------------------------meet_offset------------------------------------
2871 Type::Offset TypePtr::meet_offset(int offset) const {
2872   return _offset.meet(Offset(offset));





2873 }
2874 
2875 //------------------------------dual_offset------------------------------------
2876 Type::Offset TypePtr::dual_offset() const {
2877   return _offset.dual();


2878 }
2879 
2880 //------------------------------xdual------------------------------------------
2881 // Dual: compute field-by-field dual
2882 const TypePtr::PTR TypePtr::ptr_dual[TypePtr::lastPTR] = {
2883   BotPTR, NotNull, Constant, Null, AnyNull, TopPTR
2884 };
2885 const Type *TypePtr::xdual() const {
2886   return new TypePtr(AnyPtr, dual_ptr(), dual_offset(), dual_speculative(), dual_inline_depth());
2887 }
2888 
2889 //------------------------------xadd_offset------------------------------------
2890 Type::Offset TypePtr::xadd_offset(intptr_t offset) const {
2891   return _offset.add(offset);











2892 }
2893 
2894 //------------------------------add_offset-------------------------------------
2895 const TypePtr *TypePtr::add_offset( intptr_t offset ) const {
2896   return make(AnyPtr, _ptr, xadd_offset(offset), _speculative, _inline_depth);
2897 }
2898 
2899 //------------------------------eq---------------------------------------------
2900 // Structural equality check for Type representations
2901 bool TypePtr::eq( const Type *t ) const {
2902   const TypePtr *a = (const TypePtr*)t;
2903   return _ptr == a->ptr() && _offset == a->_offset && eq_speculative(a) && _inline_depth == a->_inline_depth;
2904 }
2905 
2906 //------------------------------hash-------------------------------------------
2907 // Type-specific hashing function.
2908 int TypePtr::hash(void) const {
2909   return java_add(java_add((jint)_ptr, (jint)offset()), java_add((jint)hash_speculative(), (jint)_inline_depth));
2910 ;
2911 }
2912 
2913 /**
2914  * Return same type without a speculative part
2915  */
2916 const Type* TypePtr::remove_speculative() const {
2917   if (_speculative == NULL) {
2918     return this;
2919   }
2920   assert(_inline_depth == InlineDepthTop || _inline_depth == InlineDepthBottom, "non speculative type shouldn't have inline depth");
2921   return make(AnyPtr, _ptr, _offset, NULL, _inline_depth);
2922 }
2923 
2924 /**
2925  * Return same type but drop speculative part if we know we won't use
2926  * it
2927  */
2928 const Type* TypePtr::cleanup_speculative() const {
2929   if (speculative() == NULL) {
2930     return this;
2931   }
2932   const Type* no_spec = remove_speculative();
2933   // If this is NULL_PTR then we don't need the speculative type
2934   // (with_inline_depth in case the current type inline depth is
2935   // InlineDepthTop)
2936   if (no_spec == NULL_PTR->with_inline_depth(inline_depth())) {
2937     return no_spec;
2938   }
2939   if (above_centerline(speculative()->ptr())) {
2940     return no_spec;
2941   }
2942   const TypeOopPtr* spec_oopptr = speculative()->isa_oopptr();
2943   // If the speculative may be null and is an inexact klass then it
2944   // doesn't help
2945   if (speculative() != TypePtr::NULL_PTR && speculative()->maybe_null() &&
2946       (spec_oopptr == NULL || !spec_oopptr->klass_is_exact())) {
2947     return no_spec;
2948   }
2949   return this;
2950 }
2951 
2952 /**
2953  * dual of the speculative part of the type
2954  */
2955 const TypePtr* TypePtr::dual_speculative() const {
2956   if (_speculative == NULL) {
2957     return NULL;
2958   }
2959   return _speculative->dual()->is_ptr();
2960 }
2961 
2962 /**
2963  * meet of the speculative parts of 2 types
2964  *
2965  * @param other  type to meet with
2966  */
2967 const TypePtr* TypePtr::xmeet_speculative(const TypePtr* other) const {
2968   bool this_has_spec = (_speculative != NULL);
2969   bool other_has_spec = (other->speculative() != NULL);
2970 
2971   if (!this_has_spec && !other_has_spec) {
2972     return NULL;
2973   }
2974 
2975   // If we are at a point where control flow meets and one branch has
2976   // a speculative type and the other has not, we meet the speculative
2977   // type of one branch with the actual type of the other. If the
2978   // actual type is exact and the speculative is as well, then the
2979   // result is a speculative type which is exact and we can continue
2980   // speculation further.
2981   const TypePtr* this_spec = _speculative;
2982   const TypePtr* other_spec = other->speculative();
2983 
2984   if (!this_has_spec) {
2985     this_spec = this;
2986   }
2987 
2988   if (!other_has_spec) {
2989     other_spec = other;
2990   }
2991 
2992   return this_spec->meet(other_spec)->is_ptr();
2993 }
2994 
2995 /**
2996  * dual of the inline depth for this type (used for speculation)
2997  */
2998 int TypePtr::dual_inline_depth() const {
2999   return -inline_depth();
3000 }
3001 
3002 /**
3003  * meet of 2 inline depths (used for speculation)
3004  *
3005  * @param depth  depth to meet with
3006  */
3007 int TypePtr::meet_inline_depth(int depth) const {
3008   return MAX2(inline_depth(), depth);
3009 }
3010 
3011 /**
3012  * Are the speculative parts of 2 types equal?
3013  *
3014  * @param other  type to compare this one to
3015  */
3016 bool TypePtr::eq_speculative(const TypePtr* other) const {
3017   if (_speculative == NULL || other->speculative() == NULL) {
3018     return _speculative == other->speculative();
3019   }
3020 
3021   if (_speculative->base() != other->speculative()->base()) {
3022     return false;
3023   }
3024 
3025   return _speculative->eq(other->speculative());
3026 }
3027 
3028 /**
3029  * Hash of the speculative part of the type
3030  */
3031 int TypePtr::hash_speculative() const {
3032   if (_speculative == NULL) {
3033     return 0;
3034   }
3035 
3036   return _speculative->hash();
3037 }
3038 
3039 /**
3040  * add offset to the speculative part of the type
3041  *
3042  * @param offset  offset to add
3043  */
3044 const TypePtr* TypePtr::add_offset_speculative(intptr_t offset) const {
3045   if (_speculative == NULL) {
3046     return NULL;
3047   }
3048   return _speculative->add_offset(offset)->is_ptr();
3049 }
3050 
3051 /**
3052  * return exact klass from the speculative type if there's one
3053  */
3054 ciKlass* TypePtr::speculative_type() const {
3055   if (_speculative != NULL && _speculative->isa_oopptr()) {
3056     const TypeOopPtr* speculative = _speculative->join(this)->is_oopptr();
3057     if (speculative->klass_is_exact()) {
3058       return speculative->klass();
3059     }
3060   }
3061   return NULL;
3062 }
3063 
3064 /**
3065  * return true if speculative type may be null
3066  */
3067 bool TypePtr::speculative_maybe_null() const {
3068   if (_speculative != NULL) {
3069     const TypePtr* speculative = _speculative->join(this)->is_ptr();
3070     return speculative->maybe_null();
3071   }
3072   return true;
3073 }
3074 
3075 bool TypePtr::speculative_always_null() const {
3076   if (_speculative != NULL) {
3077     const TypePtr* speculative = _speculative->join(this)->is_ptr();
3078     return speculative == TypePtr::NULL_PTR;
3079   }
3080   return false;
3081 }
3082 
3083 /**
3084  * Same as TypePtr::speculative_type() but return the klass only if
3085  * the speculative tells us is not null
3086  */
3087 ciKlass* TypePtr::speculative_type_not_null() const {
3088   if (speculative_maybe_null()) {
3089     return NULL;
3090   }
3091   return speculative_type();
3092 }
3093 
3094 /**
3095  * Check whether new profiling would improve speculative type
3096  *
3097  * @param   exact_kls    class from profiling
3098  * @param   inline_depth inlining depth of profile point
3099  *
3100  * @return  true if type profile is valuable
3101  */
3102 bool TypePtr::would_improve_type(ciKlass* exact_kls, int inline_depth) const {
3103   // no profiling?
3104   if (exact_kls == NULL) {
3105     return false;
3106   }
3107   if (speculative() == TypePtr::NULL_PTR) {
3108     return false;
3109   }
3110   // no speculative type or non exact speculative type?
3111   if (speculative_type() == NULL) {
3112     return true;
3113   }
3114   // If the node already has an exact speculative type keep it,
3115   // unless it was provided by profiling that is at a deeper
3116   // inlining level. Profiling at a higher inlining depth is
3117   // expected to be less accurate.
3118   if (_speculative->inline_depth() == InlineDepthBottom) {
3119     return false;
3120   }
3121   assert(_speculative->inline_depth() != InlineDepthTop, "can't do the comparison");
3122   return inline_depth < _speculative->inline_depth();
3123 }
3124 
3125 /**
3126  * Check whether new profiling would improve ptr (= tells us it is non
3127  * null)
3128  *
3129  * @param   ptr_kind always null or not null?
3130  *
3131  * @return  true if ptr profile is valuable
3132  */
3133 bool TypePtr::would_improve_ptr(ProfilePtrKind ptr_kind) const {
3134   // profiling doesn't tell us anything useful
3135   if (ptr_kind != ProfileAlwaysNull && ptr_kind != ProfileNeverNull) {
3136     return false;
3137   }
3138   // We already know this is not null
3139   if (!this->maybe_null()) {
3140     return false;
3141   }
3142   // We already know the speculative type cannot be null
3143   if (!speculative_maybe_null()) {
3144     return false;
3145   }
3146   // We already know this is always null
3147   if (this == TypePtr::NULL_PTR) {
3148     return false;
3149   }
3150   // We already know the speculative type is always null
3151   if (speculative_always_null()) {
3152     return false;
3153   }
3154   if (ptr_kind == ProfileAlwaysNull && speculative() != NULL && speculative()->isa_oopptr()) {
3155     return false;
3156   }
3157   return true;
3158 }
3159 
3160 //------------------------------dump2------------------------------------------
3161 const char *const TypePtr::ptr_msg[TypePtr::lastPTR] = {
3162   "TopPTR","AnyNull","Constant","NULL","NotNull","BotPTR"
3163 };
3164 
3165 #ifndef PRODUCT
3166 void TypePtr::dump2( Dict &d, uint depth, outputStream *st ) const {
3167   if( _ptr == Null ) st->print("NULL");
3168   else st->print("%s *", ptr_msg[_ptr]);
3169   _offset.dump2(st);


3170   dump_inline_depth(st);
3171   dump_speculative(st);
3172 }
3173 
3174 /**
3175  *dump the speculative part of the type
3176  */
3177 void TypePtr::dump_speculative(outputStream *st) const {
3178   if (_speculative != NULL) {
3179     st->print(" (speculative=");
3180     _speculative->dump_on(st);
3181     st->print(")");
3182   }
3183 }
3184 
3185 /**
3186  *dump the inline depth of the type
3187  */
3188 void TypePtr::dump_inline_depth(outputStream *st) const {
3189   if (_inline_depth != InlineDepthBottom) {
3190     if (_inline_depth == InlineDepthTop) {
3191       st->print(" (inline_depth=InlineDepthTop)");
3192     } else {
3193       st->print(" (inline_depth=%d)", _inline_depth);
3194     }
3195   }
3196 }
3197 #endif
3198 
3199 //------------------------------singleton--------------------------------------
3200 // TRUE if Type is a singleton type, FALSE otherwise.   Singletons are simple
3201 // constants
3202 bool TypePtr::singleton(void) const {
3203   // TopPTR, Null, AnyNull, Constant are all singletons
3204   return (_offset != Offset::bottom) && !below_centerline(_ptr);
3205 }
3206 
3207 bool TypePtr::empty(void) const {
3208   return (_offset == Offset::top) || above_centerline(_ptr);
3209 }
3210 
3211 //=============================================================================
3212 // Convenience common pre-built types.
3213 const TypeRawPtr *TypeRawPtr::BOTTOM;
3214 const TypeRawPtr *TypeRawPtr::NOTNULL;
3215 
3216 //------------------------------make-------------------------------------------
3217 const TypeRawPtr *TypeRawPtr::make( enum PTR ptr ) {
3218   assert( ptr != Constant, "what is the constant?" );
3219   assert( ptr != Null, "Use TypePtr for NULL" );
3220   return (TypeRawPtr*)(new TypeRawPtr(ptr,0))->hashcons();
3221 }
3222 
3223 const TypeRawPtr *TypeRawPtr::make( address bits ) {
3224   assert( bits, "Use TypePtr for NULL" );
3225   return (TypeRawPtr*)(new TypeRawPtr(Constant,bits))->hashcons();
3226 }
3227 
3228 //------------------------------cast_to_ptr_type-------------------------------
3229 const TypeRawPtr* TypeRawPtr::cast_to_ptr_type(PTR ptr) const {
3230   assert( ptr != Constant, "what is the constant?" );
3231   assert( ptr != Null, "Use TypePtr for NULL" );
3232   assert( _bits==0, "Why cast a constant address?");
3233   if( ptr == _ptr ) return this;
3234   return make(ptr);
3235 }
3236 
3237 //------------------------------get_con----------------------------------------
3238 intptr_t TypeRawPtr::get_con() const {
3239   assert( _ptr == Null || _ptr == Constant, "" );
3240   return (intptr_t)_bits;
3241 }
3242 
3243 //------------------------------meet-------------------------------------------
3244 // Compute the MEET of two types.  It returns a new Type object.
3245 const Type *TypeRawPtr::xmeet( const Type *t ) const {
3246   // Perform a fast test for common case; meeting the same types together.
3247   if( this == t ) return this;  // Meeting same type-rep?
3248 
3249   // Current "this->_base" is RawPtr
3250   switch( t->base() ) {         // switch on original type
3251   case Bottom:                  // Ye Olde Default
3252     return t;
3253   case Top:
3254     return this;
3255   case AnyPtr:                  // Meeting to AnyPtrs
3256     break;
3257   case RawPtr: {                // might be top, bot, any/not or constant
3258     enum PTR tptr = t->is_ptr()->ptr();
3259     enum PTR ptr = meet_ptr( tptr );
3260     if( ptr == Constant ) {     // Cannot be equal constants, so...
3261       if( tptr == Constant && _ptr != Constant)  return t;
3262       if( _ptr == Constant && tptr != Constant)  return this;
3263       ptr = NotNull;            // Fall down in lattice
3264     }
3265     return make( ptr );
3266   }
3267 
3268   case OopPtr:
3269   case InstPtr:
3270   case AryPtr:
3271   case MetadataPtr:
3272   case KlassPtr:
3273   case InstKlassPtr:
3274   case AryKlassPtr:
3275     return TypePtr::BOTTOM;     // Oop meet raw is not well defined
3276   default:                      // All else is a mistake
3277     typerr(t);
3278   }
3279 
3280   // Found an AnyPtr type vs self-RawPtr type
3281   const TypePtr *tp = t->is_ptr();
3282   switch (tp->ptr()) {
3283   case TypePtr::TopPTR:  return this;
3284   case TypePtr::BotPTR:  return t;
3285   case TypePtr::Null:
3286     if( _ptr == TypePtr::TopPTR ) return t;
3287     return TypeRawPtr::BOTTOM;
3288   case TypePtr::NotNull: return TypePtr::make(AnyPtr, meet_ptr(TypePtr::NotNull), tp->meet_offset(0), tp->speculative(), tp->inline_depth());
3289   case TypePtr::AnyNull:
3290     if( _ptr == TypePtr::Constant) return this;
3291     return make( meet_ptr(TypePtr::AnyNull) );
3292   default: ShouldNotReachHere();
3293   }
3294   return this;
3295 }
3296 
3297 //------------------------------xdual------------------------------------------
3298 // Dual: compute field-by-field dual
3299 const Type *TypeRawPtr::xdual() const {
3300   return new TypeRawPtr( dual_ptr(), _bits );
3301 }
3302 
3303 //------------------------------add_offset-------------------------------------
3304 const TypePtr *TypeRawPtr::add_offset( intptr_t offset ) const {
3305   if( offset == OffsetTop ) return BOTTOM; // Undefined offset-> undefined pointer
3306   if( offset == OffsetBot ) return BOTTOM; // Unknown offset-> unknown pointer
3307   if( offset == 0 ) return this; // No change
3308   switch (_ptr) {
3309   case TypePtr::TopPTR:
3310   case TypePtr::BotPTR:
3311   case TypePtr::NotNull:
3312     return this;
3313   case TypePtr::Null:
3314   case TypePtr::Constant: {
3315     address bits = _bits+offset;
3316     if ( bits == 0 ) return TypePtr::NULL_PTR;
3317     return make( bits );
3318   }
3319   default:  ShouldNotReachHere();
3320   }
3321   return NULL;                  // Lint noise
3322 }
3323 
3324 //------------------------------eq---------------------------------------------
3325 // Structural equality check for Type representations
3326 bool TypeRawPtr::eq( const Type *t ) const {
3327   const TypeRawPtr *a = (const TypeRawPtr*)t;
3328   return _bits == a->_bits && TypePtr::eq(t);
3329 }
3330 
3331 //------------------------------hash-------------------------------------------
3332 // Type-specific hashing function.
3333 int TypeRawPtr::hash(void) const {
3334   return (intptr_t)_bits + TypePtr::hash();
3335 }
3336 
3337 //------------------------------dump2------------------------------------------
3338 #ifndef PRODUCT
3339 void TypeRawPtr::dump2( Dict &d, uint depth, outputStream *st ) const {
3340   if( _ptr == Constant )
3341     st->print(INTPTR_FORMAT, p2i(_bits));
3342   else
3343     st->print("rawptr:%s", ptr_msg[_ptr]);
3344 }
3345 #endif
3346 
3347 //=============================================================================
3348 // Convenience common pre-built type.
3349 const TypeOopPtr *TypeOopPtr::BOTTOM;
3350 
3351 //------------------------------TypeOopPtr-------------------------------------
3352 TypeOopPtr::TypeOopPtr(TYPES t, PTR ptr, ciKlass* k, bool xk, ciObject* o, Offset offset, Offset field_offset,
3353                        int instance_id, const TypePtr* speculative, int inline_depth)
3354   : TypePtr(t, ptr, offset, speculative, inline_depth),
3355     _const_oop(o), _klass(k),
3356     _klass_is_exact(xk),
3357     _is_ptr_to_narrowoop(false),
3358     _is_ptr_to_narrowklass(false),
3359     _is_ptr_to_boxed_value(false),
3360     _instance_id(instance_id) {
3361   if (Compile::current()->eliminate_boxing() && (t == InstPtr) &&
3362       (offset.get() > 0) && xk && (k != 0) && k->is_instance_klass()) {
3363     _is_ptr_to_boxed_value = k->as_instance_klass()->is_boxed_value_offset(offset.get());
3364   }
3365 #ifdef _LP64
3366   if (this->offset() > 0 || this->offset() == Type::OffsetTop || this->offset() == Type::OffsetBot) {
3367     if (this->offset() == oopDesc::klass_offset_in_bytes()) {
3368       _is_ptr_to_narrowklass = UseCompressedClassPointers;
3369     } else if (klass() == NULL) {
3370       // Array with unknown body type
3371       assert(this->isa_aryptr(), "only arrays without klass");
3372       _is_ptr_to_narrowoop = UseCompressedOops;
3373     } else if (UseCompressedOops && this->isa_aryptr() && this->offset() != arrayOopDesc::length_offset_in_bytes()) {
3374       if (klass()->is_obj_array_klass()) {
3375         _is_ptr_to_narrowoop = true;
3376       } else if (klass()->is_flat_array_klass() && field_offset != Offset::top && field_offset != Offset::bottom) {
3377         // Check if the field of the inline type array element contains oops
3378         ciInlineKlass* vk = klass()->as_flat_array_klass()->element_klass()->as_inline_klass();
3379         int foffset = field_offset.get() + vk->first_field_offset();
3380         ciField* field = vk->get_field_by_offset(foffset, false);
3381         assert(field != NULL, "missing field");
3382         BasicType bt = field->layout_type();
3383         _is_ptr_to_narrowoop = UseCompressedOops && is_reference_type(bt);
3384       }
3385     } else if (klass()->is_instance_klass()) {


3386       if (this->isa_klassptr()) {
3387         // Perm objects don't use compressed references
3388       } else if (_offset == Offset::bottom || _offset == Offset::top) {
3389         // unsafe access
3390         _is_ptr_to_narrowoop = UseCompressedOops;
3391       } else {
3392         assert(this->isa_instptr(), "must be an instance ptr.");

3393         if (klass() == ciEnv::current()->Class_klass() &&
3394             (this->offset() == java_lang_Class::klass_offset() ||
3395              this->offset() == java_lang_Class::array_klass_offset())) {
3396           // Special hidden fields from the Class.
3397           assert(this->isa_instptr(), "must be an instance ptr.");
3398           _is_ptr_to_narrowoop = false;
3399         } else if (klass() == ciEnv::current()->Class_klass() &&
3400                    this->offset() >= InstanceMirrorKlass::offset_of_static_fields()) {
3401           // Static fields
3402           ciField* field = NULL;
3403           if (const_oop() != NULL) {
3404             ciInstanceKlass* k = const_oop()->as_instance()->java_lang_Class_klass()->as_instance_klass();
3405             if (k->is_inlinetype() && this->offset() == k->as_inline_klass()->default_value_offset()) {
3406               // Special hidden field that contains the oop of the default inline type
3407               // basic_elem_type = T_INLINE_TYPE;
3408              _is_ptr_to_narrowoop = UseCompressedOops;
3409             } else {
3410               field = k->get_field_by_offset(this->offset(), true);
3411               if (field != NULL) {
3412                 BasicType basic_elem_type = field->layout_type();
3413                 _is_ptr_to_narrowoop = UseCompressedOops && is_reference_type(basic_elem_type);
3414               } else {
3415                 // unsafe access
3416                 _is_ptr_to_narrowoop = UseCompressedOops;
3417               }
3418             }
3419           }
3420         } else {
3421           // Instance fields which contains a compressed oop references.
3422           ciInstanceKlass* ik = klass()->as_instance_klass();
3423           ciField* field = ik->get_field_by_offset(this->offset(), false);
3424           if (field != NULL) {
3425             BasicType basic_elem_type = field->layout_type();
3426             _is_ptr_to_narrowoop = UseCompressedOops && is_reference_type(basic_elem_type);
3427           } else if (klass()->equals(ciEnv::current()->Object_klass())) {
3428             // Compile::find_alias_type() cast exactness on all types to verify
3429             // that it does not affect alias type.
3430             _is_ptr_to_narrowoop = UseCompressedOops;
3431           } else {
3432             // Type for the copy start in LibraryCallKit::inline_native_clone().
3433             _is_ptr_to_narrowoop = UseCompressedOops;
3434           }
3435         }
3436       }
3437     }
3438   }
3439 #endif
3440 }
3441 
3442 //------------------------------make-------------------------------------------
3443 const TypeOopPtr *TypeOopPtr::make(PTR ptr, Offset offset, int instance_id,
3444                                    const TypePtr* speculative, int inline_depth) {
3445   assert(ptr != Constant, "no constant generic pointers");
3446   ciKlass*  k = Compile::current()->env()->Object_klass();
3447   bool      xk = false;
3448   ciObject* o = NULL;
3449   return (TypeOopPtr*)(new TypeOopPtr(OopPtr, ptr, k, xk, o, offset, Offset::bottom, instance_id, speculative, inline_depth))->hashcons();
3450 }
3451 
3452 
3453 //------------------------------cast_to_ptr_type-------------------------------
3454 const TypeOopPtr* TypeOopPtr::cast_to_ptr_type(PTR ptr) const {
3455   assert(_base == OopPtr, "subclass must override cast_to_ptr_type");
3456   if( ptr == _ptr ) return this;
3457   return make(ptr, _offset, _instance_id, _speculative, _inline_depth);
3458 }
3459 
3460 //-----------------------------cast_to_instance_id----------------------------
3461 const TypeOopPtr *TypeOopPtr::cast_to_instance_id(int instance_id) const {
3462   // There are no instances of a general oop.
3463   // Return self unchanged.
3464   return this;
3465 }
3466 
3467 //-----------------------------cast_to_exactness-------------------------------
3468 const Type *TypeOopPtr::cast_to_exactness(bool klass_is_exact) const {
3469   // There is no such thing as an exact general oop.
3470   // Return self unchanged.
3471   return this;
3472 }
3473 

3474 //------------------------------as_klass_type----------------------------------
3475 // Return the klass type corresponding to this instance or array type.
3476 // It is the type that is loaded from an object of this type.
3477 const TypeKlassPtr* TypeOopPtr::as_klass_type(bool try_for_exact) const {
3478   ShouldNotReachHere();
3479   return NULL;
3480 }
3481 
3482 //------------------------------meet-------------------------------------------
3483 // Compute the MEET of two types.  It returns a new Type object.
3484 const Type *TypeOopPtr::xmeet_helper(const Type *t) const {
3485   // Perform a fast test for common case; meeting the same types together.
3486   if( this == t ) return this;  // Meeting same type-rep?
3487 
3488   // Current "this->_base" is OopPtr
3489   switch (t->base()) {          // switch on original type
3490 
3491   case Int:                     // Mixing ints & oops happens when javac
3492   case Long:                    // reuses local variables
3493   case FloatTop:
3494   case FloatCon:
3495   case FloatBot:
3496   case DoubleTop:
3497   case DoubleCon:
3498   case DoubleBot:
3499   case NarrowOop:
3500   case NarrowKlass:
3501   case Bottom:                  // Ye Olde Default
3502     return Type::BOTTOM;
3503   case Top:
3504     return this;
3505 
3506   default:                      // All else is a mistake
3507     typerr(t);
3508 
3509   case RawPtr:
3510   case MetadataPtr:
3511   case KlassPtr:
3512   case InstKlassPtr:
3513   case AryKlassPtr:
3514     return TypePtr::BOTTOM;     // Oop meet raw is not well defined
3515 
3516   case AnyPtr: {
3517     // Found an AnyPtr type vs self-OopPtr type
3518     const TypePtr *tp = t->is_ptr();
3519     Offset offset = meet_offset(tp->offset());
3520     PTR ptr = meet_ptr(tp->ptr());
3521     const TypePtr* speculative = xmeet_speculative(tp);
3522     int depth = meet_inline_depth(tp->inline_depth());
3523     switch (tp->ptr()) {
3524     case Null:
3525       if (ptr == Null)  return TypePtr::make(AnyPtr, ptr, offset, speculative, depth);
3526       // else fall through:
3527     case TopPTR:
3528     case AnyNull: {
3529       int instance_id = meet_instance_id(InstanceTop);
3530       return make(ptr, offset, instance_id, speculative, depth);
3531     }
3532     case BotPTR:
3533     case NotNull:
3534       return TypePtr::make(AnyPtr, ptr, offset, speculative, depth);
3535     default: typerr(t);
3536     }
3537   }
3538 
3539   case OopPtr: {                 // Meeting to other OopPtrs
3540     const TypeOopPtr *tp = t->is_oopptr();
3541     int instance_id = meet_instance_id(tp->instance_id());
3542     const TypePtr* speculative = xmeet_speculative(tp);
3543     int depth = meet_inline_depth(tp->inline_depth());
3544     return make(meet_ptr(tp->ptr()), meet_offset(tp->offset()), instance_id, speculative, depth);
3545   }
3546 
3547   case InstPtr:                  // For these, flip the call around to cut down
3548   case AryPtr:
3549     return t->xmeet(this);      // Call in reverse direction
3550 
3551   } // End of switch
3552   return this;                  // Return the double constant
3553 }
3554 
3555 
3556 //------------------------------xdual------------------------------------------
3557 // Dual of a pure heap pointer.  No relevant klass or oop information.
3558 const Type *TypeOopPtr::xdual() const {
3559   assert(klass() == Compile::current()->env()->Object_klass(), "no klasses here");
3560   assert(const_oop() == NULL,             "no constants here");
3561   return new TypeOopPtr(_base, dual_ptr(), klass(), klass_is_exact(), const_oop(), dual_offset(), Offset::bottom, dual_instance_id(), dual_speculative(), dual_inline_depth());
3562 }
3563 
3564 //--------------------------make_from_klass_common-----------------------------
3565 // Computes the element-type given a klass.
3566 const TypeOopPtr* TypeOopPtr::make_from_klass_common(ciKlass *klass, bool klass_change, bool try_for_exact) {
3567   if (klass->is_instance_klass() || klass->is_inlinetype()) {
3568     Compile* C = Compile::current();
3569     Dependencies* deps = C->dependencies();
3570     assert((deps != NULL) == (C->method() != NULL && C->method()->code_size() > 0), "sanity");
3571     // Element is an instance
3572     bool klass_is_exact = false;
3573     if (klass->is_loaded()) {
3574       // Try to set klass_is_exact.
3575       ciInstanceKlass* ik = klass->as_instance_klass();
3576       klass_is_exact = ik->is_final();
3577       if (!klass_is_exact && klass_change
3578           && deps != NULL && UseUniqueSubclasses) {
3579         ciInstanceKlass* sub = ik->unique_concrete_subklass();
3580         if (sub != NULL) {
3581           deps->assert_abstract_with_unique_concrete_subtype(ik, sub);
3582           klass = ik = sub;
3583           klass_is_exact = sub->is_final();
3584         }
3585       }
3586       if (!klass_is_exact && try_for_exact && deps != NULL &&
3587           !ik->is_interface() && !ik->has_subklass()) {
3588         // Add a dependence; if concrete subclass added we need to recompile
3589         deps->assert_leaf_type(ik);
3590         klass_is_exact = true;
3591       }
3592     }
3593     return TypeInstPtr::make(TypePtr::BotPTR, klass, klass_is_exact, NULL, Offset(0));
3594   } else if (klass->is_obj_array_klass()) {
3595     // Element is an object or inline type array. Recursively call ourself.
3596     const TypeOopPtr* etype = TypeOopPtr::make_from_klass_common(klass->as_array_klass()->element_klass(), /* klass_change= */ false, try_for_exact);
3597     bool null_free = klass->as_array_klass()->is_elem_null_free();
3598     if (null_free) {
3599       etype = etype->join_speculative(TypePtr::NOTNULL)->is_oopptr();
3600     }
3601     // Determine null-free/flattened properties
3602     const TypeOopPtr* exact_etype = etype;
3603     if (etype->can_be_inline_type()) {
3604       // Use exact type if element can be an inline type
3605       exact_etype = TypeOopPtr::make_from_klass_common(klass->as_array_klass()->element_klass(), /* klass_change= */ true, /* try_for_exact= */ true);
3606     }
3607     bool not_null_free = !exact_etype->can_be_inline_type();
3608     bool not_flat = !UseFlatArray || not_null_free || (exact_etype->is_inlinetypeptr() && !exact_etype->inline_klass()->flatten_array());
3609 
3610     // Even if MyValue is exact, [LMyValue is not exact due to [QMyValue <: [LMyValue.
3611     bool xk = etype->klass_is_exact() && (!etype->is_inlinetypeptr() || null_free);
3612     const TypeAry* arr0 = TypeAry::make(etype, TypeInt::POS, false, not_flat, not_null_free);
3613     // We used to pass NotNull in here, asserting that the sub-arrays
3614     // are all not-null.  This is not true in generally, as code can
3615     // slam NULLs down in the subarrays.
3616     const TypeAryPtr* arr = TypeAryPtr::make(TypePtr::BotPTR, arr0, klass, xk, Offset(0));
3617     return arr;
3618   } else if (klass->is_type_array_klass()) {
3619     // Element is an typeArray
3620     const Type* etype = get_const_basic_type(klass->as_type_array_klass()->element_type());
3621     const TypeAry* arr0 = TypeAry::make(etype, TypeInt::POS,
3622                                         /* stable= */ false, /* not_flat= */ true, /* not_null_free= */ true);
3623     // We used to pass NotNull in here, asserting that the array pointer
3624     // is not-null. That was not true in general.
3625     const TypeAryPtr* arr = TypeAryPtr::make(TypePtr::BotPTR, arr0, klass, true, Offset(0));
3626     return arr;
3627   } else if (klass->is_flat_array_klass()) {
3628     ciInlineKlass* vk = klass->as_array_klass()->element_klass()->as_inline_klass();
3629     const TypeAry* arr0 = TypeAry::make(TypeInlineType::make(vk), TypeInt::POS);
3630     const TypeAryPtr* arr = TypeAryPtr::make(TypePtr::BotPTR, arr0, klass, true, Offset(0));
3631     return arr;
3632   } else {
3633     ShouldNotReachHere();
3634     return NULL;
3635   }
3636 }
3637 
3638 //------------------------------make_from_constant-----------------------------
3639 // Make a java pointer from an oop constant
3640 const TypeOopPtr* TypeOopPtr::make_from_constant(ciObject* o, bool require_constant) {
3641   assert(!o->is_null_object(), "null object not yet handled here.");
3642 
3643   const bool make_constant = require_constant || o->should_be_constant();
3644 
3645   ciKlass* klass = o->klass();
3646   if (klass->is_instance_klass() || klass->is_inlinetype()) {
3647     // Element is an instance or inline type
3648     if (make_constant) {
3649       return TypeInstPtr::make(o);
3650     } else {
3651       return TypeInstPtr::make(TypePtr::NotNull, klass, true, NULL, Offset(0));
3652     }
3653   } else if (klass->is_obj_array_klass()) {
3654     // Element is an object array. Recursively call ourself.
3655     const TypeOopPtr* etype = TypeOopPtr::make_from_klass_raw(klass->as_array_klass()->element_klass());
3656     bool null_free = false;
3657     if (klass->as_array_klass()->is_elem_null_free()) {
3658       null_free = true;
3659       etype = etype->join_speculative(TypePtr::NOTNULL)->is_oopptr();
3660     }
3661     const TypeAry* arr0 = TypeAry::make(etype, TypeInt::make(o->as_array()->length()),
3662                                         /* stable= */ false, /* not_flat= */ true, /* not_null_free= */ !null_free);
3663     // We used to pass NotNull in here, asserting that the sub-arrays
3664     // are all not-null.  This is not true in generally, as code can
3665     // slam NULLs down in the subarrays.
3666     if (make_constant) {
3667       return TypeAryPtr::make(TypePtr::Constant, o, arr0, klass, true, Offset(0));
3668     } else {
3669       return TypeAryPtr::make(TypePtr::NotNull, arr0, klass, true, Offset(0));
3670     }
3671   } else if (klass->is_type_array_klass()) {
3672     // Element is an typeArray
3673     const Type* etype = (Type*)get_const_basic_type(klass->as_type_array_klass()->element_type());
3674     const TypeAry* arr0 = TypeAry::make(etype, TypeInt::make(o->as_array()->length()),
3675                                         /* stable= */ false, /* not_flat= */ true, /* not_null_free= */ true);
3676     // We used to pass NotNull in here, asserting that the array pointer
3677     // is not-null. That was not true in general.
3678     if (make_constant) {
3679       return TypeAryPtr::make(TypePtr::Constant, o, arr0, klass, true, Offset(0));
3680     } else {
3681       return TypeAryPtr::make(TypePtr::NotNull, arr0, klass, true, Offset(0));
3682     }
3683   } else if (klass->is_flat_array_klass()) {
3684     ciInlineKlass* vk = klass->as_array_klass()->element_klass()->as_inline_klass();
3685     const TypeAry* arr0 = TypeAry::make(TypeInlineType::make(vk), TypeInt::make(o->as_array()->length()));
3686     // We used to pass NotNull in here, asserting that the sub-arrays
3687     // are all not-null.  This is not true in generally, as code can
3688     // slam NULLs down in the subarrays.
3689     if (make_constant) {
3690       return TypeAryPtr::make(TypePtr::Constant, o, arr0, klass, true, Offset(0));
3691     } else {
3692       return TypeAryPtr::make(TypePtr::NotNull, arr0, klass, true, Offset(0));
3693     }
3694   }
3695 
3696   fatal("unhandled object type");
3697   return NULL;
3698 }
3699 
3700 //------------------------------get_con----------------------------------------
3701 intptr_t TypeOopPtr::get_con() const {
3702   assert( _ptr == Null || _ptr == Constant, "" );
3703   assert(offset() >= 0, "");
3704 
3705   if (offset() != 0) {
3706     // After being ported to the compiler interface, the compiler no longer
3707     // directly manipulates the addresses of oops.  Rather, it only has a pointer
3708     // to a handle at compile time.  This handle is embedded in the generated
3709     // code and dereferenced at the time the nmethod is made.  Until that time,
3710     // it is not reasonable to do arithmetic with the addresses of oops (we don't
3711     // have access to the addresses!).  This does not seem to currently happen,
3712     // but this assertion here is to help prevent its occurence.
3713     tty->print_cr("Found oop constant with non-zero offset");
3714     ShouldNotReachHere();
3715   }
3716 
3717   return (intptr_t)const_oop()->constant_encoding();
3718 }
3719 
3720 
3721 //-----------------------------filter------------------------------------------
3722 // Do not allow interface-vs.-noninterface joins to collapse to top.
3723 const Type *TypeOopPtr::filter_helper(const Type *kills, bool include_speculative) const {
3724 
3725   const Type* ft = join_helper(kills, include_speculative);
3726   const TypeInstPtr* ftip = ft->isa_instptr();
3727   const TypeInstPtr* ktip = kills->isa_instptr();
3728 
3729   if (ft->empty()) {
3730     // Check for evil case of 'this' being a class and 'kills' expecting an
3731     // interface.  This can happen because the bytecodes do not contain
3732     // enough type info to distinguish a Java-level interface variable
3733     // from a Java-level object variable.  If we meet 2 classes which
3734     // both implement interface I, but their meet is at 'j/l/O' which
3735     // doesn't implement I, we have no way to tell if the result should
3736     // be 'I' or 'j/l/O'.  Thus we'll pick 'j/l/O'.  If this then flows
3737     // into a Phi which "knows" it's an Interface type we'll have to
3738     // uplift the type.
3739     if (!empty()) {
3740       if (ktip != NULL && ktip->is_loaded() && ktip->klass()->is_interface()) {
3741         return kills;           // Uplift to interface
3742       }
3743       // Also check for evil cases of 'this' being a class array
3744       // and 'kills' expecting an array of interfaces.
3745       Type::get_arrays_base_elements(ft, kills, NULL, &ktip);
3746       if (ktip != NULL && ktip->is_loaded() && ktip->klass()->is_interface()) {
3747         return kills;           // Uplift to array of interface
3748       }
3749     }
3750 
3751     return Type::TOP;           // Canonical empty value
3752   }
3753 
3754   // If we have an interface-typed Phi or cast and we narrow to a class type,
3755   // the join should report back the class.  However, if we have a J/L/Object
3756   // class-typed Phi and an interface flows in, it's possible that the meet &
3757   // join report an interface back out.  This isn't possible but happens
3758   // because the type system doesn't interact well with interfaces.
3759   if (ftip != NULL && ktip != NULL &&
3760       ftip->is_loaded() &&  ftip->klass()->is_interface() &&
3761       ktip->is_loaded() && !ktip->klass()->is_interface()) {
3762     assert(!ftip->klass_is_exact(), "interface could not be exact");
3763     return ktip->cast_to_ptr_type(ftip->ptr());
3764   }
3765 
3766   return ft;
3767 }
3768 
3769 //------------------------------eq---------------------------------------------
3770 // Structural equality check for Type representations
3771 bool TypeOopPtr::eq( const Type *t ) const {
3772   const TypeOopPtr *a = (const TypeOopPtr*)t;
3773   if (_klass_is_exact != a->_klass_is_exact ||
3774       _instance_id != a->_instance_id)  return false;
3775   ciObject* one = const_oop();
3776   ciObject* two = a->const_oop();
3777   if (one == NULL || two == NULL) {
3778     return (one == two) && TypePtr::eq(t);
3779   } else {
3780     return one->equals(two) && TypePtr::eq(t);
3781   }
3782 }
3783 
3784 //------------------------------hash-------------------------------------------
3785 // Type-specific hashing function.
3786 int TypeOopPtr::hash(void) const {
3787   return
3788     java_add(java_add((jint)(const_oop() ? const_oop()->hash() : 0), (jint)_klass_is_exact),
3789              java_add((jint)_instance_id, (jint)TypePtr::hash()));
3790 }
3791 
3792 //------------------------------dump2------------------------------------------
3793 #ifndef PRODUCT
3794 void TypeOopPtr::dump2( Dict &d, uint depth, outputStream *st ) const {
3795   st->print("oopptr:%s", ptr_msg[_ptr]);
3796   if( _klass_is_exact ) st->print(":exact");
3797   if( const_oop() ) st->print(INTPTR_FORMAT, p2i(const_oop()));
3798   _offset.dump2(st);





3799   if (_instance_id == InstanceTop)
3800     st->print(",iid=top");
3801   else if (_instance_id != InstanceBot)
3802     st->print(",iid=%d",_instance_id);
3803 
3804   dump_inline_depth(st);
3805   dump_speculative(st);
3806 }
3807 #endif
3808 
3809 //------------------------------singleton--------------------------------------
3810 // TRUE if Type is a singleton type, FALSE otherwise.   Singletons are simple
3811 // constants
3812 bool TypeOopPtr::singleton(void) const {
3813   // detune optimizer to not generate constant oop + constant offset as a constant!
3814   // TopPTR, Null, AnyNull, Constant are all singletons
3815   return (offset() == 0) && !below_centerline(_ptr);
3816 }
3817 
3818 //------------------------------add_offset-------------------------------------
3819 const TypePtr *TypeOopPtr::add_offset(intptr_t offset) const {
3820   return make(_ptr, xadd_offset(offset), _instance_id, add_offset_speculative(offset), _inline_depth);
3821 }
3822 
3823 /**
3824  * Return same type without a speculative part
3825  */
3826 const Type* TypeOopPtr::remove_speculative() const {
3827   if (_speculative == NULL) {
3828     return this;
3829   }
3830   assert(_inline_depth == InlineDepthTop || _inline_depth == InlineDepthBottom, "non speculative type shouldn't have inline depth");
3831   return make(_ptr, _offset, _instance_id, NULL, _inline_depth);
3832 }
3833 
3834 /**
3835  * Return same type but drop speculative part if we know we won't use
3836  * it
3837  */
3838 const Type* TypeOopPtr::cleanup_speculative() const {
3839   // If the klass is exact and the ptr is not null then there's
3840   // nothing that the speculative type can help us with
3841   if (klass_is_exact() && !maybe_null()) {
3842     return remove_speculative();
3843   }
3844   return TypePtr::cleanup_speculative();
3845 }
3846 
3847 /**
3848  * Return same type but with a different inline depth (used for speculation)
3849  *
3850  * @param depth  depth to meet with
3851  */
3852 const TypePtr* TypeOopPtr::with_inline_depth(int depth) const {
3853   if (!UseInlineDepthForSpeculativeTypes) {
3854     return this;
3855   }
3856   return make(_ptr, _offset, _instance_id, _speculative, depth);
3857 }
3858 
3859 //------------------------------with_instance_id--------------------------------
3860 const TypePtr* TypeOopPtr::with_instance_id(int instance_id) const {
3861   assert(_instance_id != -1, "should be known");
3862   return make(_ptr, _offset, instance_id, _speculative, _inline_depth);
3863 }
3864 
3865 //------------------------------meet_instance_id--------------------------------
3866 int TypeOopPtr::meet_instance_id( int instance_id ) const {
3867   // Either is 'TOP' instance?  Return the other instance!
3868   if( _instance_id == InstanceTop ) return  instance_id;
3869   if(  instance_id == InstanceTop ) return _instance_id;
3870   // If either is different, return 'BOTTOM' instance
3871   if( _instance_id != instance_id ) return InstanceBot;
3872   return _instance_id;
3873 }
3874 
3875 //------------------------------dual_instance_id--------------------------------
3876 int TypeOopPtr::dual_instance_id( ) const {
3877   if( _instance_id == InstanceTop ) return InstanceBot; // Map TOP into BOTTOM
3878   if( _instance_id == InstanceBot ) return InstanceTop; // Map BOTTOM into TOP
3879   return _instance_id;              // Map everything else into self
3880 }
3881 
3882 /**
3883  * Check whether new profiling would improve speculative type
3884  *
3885  * @param   exact_kls    class from profiling
3886  * @param   inline_depth inlining depth of profile point
3887  *
3888  * @return  true if type profile is valuable
3889  */
3890 bool TypeOopPtr::would_improve_type(ciKlass* exact_kls, int inline_depth) const {
3891   // no way to improve an already exact type
3892   if (klass_is_exact()) {
3893     return false;
3894   }
3895   return TypePtr::would_improve_type(exact_kls, inline_depth);
3896 }
3897 
3898 //=============================================================================
3899 // Convenience common pre-built types.
3900 const TypeInstPtr *TypeInstPtr::NOTNULL;
3901 const TypeInstPtr *TypeInstPtr::BOTTOM;
3902 const TypeInstPtr *TypeInstPtr::MIRROR;
3903 const TypeInstPtr *TypeInstPtr::MARK;
3904 const TypeInstPtr *TypeInstPtr::KLASS;
3905 
3906 //------------------------------TypeInstPtr-------------------------------------
3907 TypeInstPtr::TypeInstPtr(PTR ptr, ciKlass* k, bool xk, ciObject* o, Offset off,
3908                          bool flatten_array, int instance_id, const TypePtr* speculative,
3909                          int inline_depth)
3910   : TypeOopPtr(InstPtr, ptr, k, xk, o, off, Offset::bottom, instance_id, speculative, inline_depth),
3911     _name(k->name()), _flatten_array(flatten_array) {
3912   assert(k != NULL &&
3913          (k->is_loaded() || o == NULL),
3914          "cannot have constants with non-loaded klass");
3915   assert(!klass()->flatten_array() || flatten_array, "Should be flat in array");
3916   assert(!flatten_array || can_be_inline_type(), "Only inline types can be flat in array");
3917 };
3918 
3919 //------------------------------make-------------------------------------------
3920 const TypeInstPtr *TypeInstPtr::make(PTR ptr,
3921                                      ciKlass* k,
3922                                      bool xk,
3923                                      ciObject* o,
3924                                      Offset offset,
3925                                      bool flatten_array,
3926                                      int instance_id,
3927                                      const TypePtr* speculative,
3928                                      int inline_depth) {
3929   assert( !k->is_loaded() || k->is_instance_klass(), "Must be for instance");
3930   // Either const_oop() is NULL or else ptr is Constant
3931   assert( (!o && ptr != Constant) || (o && ptr == Constant),
3932           "constant pointers must have a value supplied" );
3933   // Ptr is never Null
3934   assert( ptr != Null, "NULL pointers are not typed" );
3935 
3936   assert(instance_id <= 0 || xk, "instances are always exactly typed");
3937   if (ptr == Constant) {
3938     // Note:  This case includes meta-object constants, such as methods.
3939     xk = true;
3940   } else if (k->is_loaded()) {
3941     ciInstanceKlass* ik = k->as_instance_klass();
3942     if (!xk && ik->is_final())     xk = true;   // no inexact final klass
3943     if (xk && ik->is_interface())  xk = false;  // no exact interface
3944   }
3945 
3946   // Check if this type is known to be flat in arrays
3947   flatten_array = flatten_array || k->flatten_array();
3948 
3949   // Now hash this baby
3950   TypeInstPtr *result =
3951     (TypeInstPtr*)(new TypeInstPtr(ptr, k, xk, o, offset, flatten_array, instance_id, speculative, inline_depth))->hashcons();
3952 
3953   return result;
3954 }
3955 
3956 /**
3957  *  Create constant type for a constant boxed value
3958  */
3959 const Type* TypeInstPtr::get_const_boxed_value() const {
3960   assert(is_ptr_to_boxed_value(), "should be called only for boxed value");
3961   assert((const_oop() != NULL), "should be called only for constant object");
3962   ciConstant constant = const_oop()->as_instance()->field_value_by_offset(offset());
3963   BasicType bt = constant.basic_type();
3964   switch (bt) {
3965     case T_BOOLEAN:  return TypeInt::make(constant.as_boolean());
3966     case T_INT:      return TypeInt::make(constant.as_int());
3967     case T_CHAR:     return TypeInt::make(constant.as_char());
3968     case T_BYTE:     return TypeInt::make(constant.as_byte());
3969     case T_SHORT:    return TypeInt::make(constant.as_short());
3970     case T_FLOAT:    return TypeF::make(constant.as_float());
3971     case T_DOUBLE:   return TypeD::make(constant.as_double());
3972     case T_LONG:     return TypeLong::make(constant.as_long());
3973     default:         break;
3974   }
3975   fatal("Invalid boxed value type '%s'", type2name(bt));
3976   return NULL;
3977 }
3978 
3979 //------------------------------cast_to_ptr_type-------------------------------
3980 const TypeInstPtr *TypeInstPtr::cast_to_ptr_type(PTR ptr) const {
3981   if( ptr == _ptr ) return this;
3982   // Reconstruct _sig info here since not a problem with later lazy
3983   // construction, _sig will show up on demand.
3984   return make(ptr, klass(), klass_is_exact(), const_oop(), _offset, _flatten_array, _instance_id, _speculative, _inline_depth);
3985 }
3986 
3987 
3988 //-----------------------------cast_to_exactness-------------------------------
3989 const Type *TypeInstPtr::cast_to_exactness(bool klass_is_exact) const {
3990   if( klass_is_exact == _klass_is_exact ) return this;
3991   if (!_klass->is_loaded())  return this;
3992   ciInstanceKlass* ik = _klass->as_instance_klass();
3993   if( (ik->is_final() || _const_oop) )  return this;  // cannot clear xk
3994   if( ik->is_interface() )              return this;  // cannot set xk
3995   return make(ptr(), klass(), klass_is_exact, const_oop(), _offset, _flatten_array, _instance_id, _speculative, _inline_depth);
3996 }
3997 
3998 //-----------------------------cast_to_instance_id----------------------------
3999 const TypeOopPtr *TypeInstPtr::cast_to_instance_id(int instance_id) const {
4000   if( instance_id == _instance_id ) return this;
4001   return make(_ptr, klass(), _klass_is_exact, const_oop(), _offset, _flatten_array, instance_id, _speculative, _inline_depth);
4002 }
4003 
4004 //------------------------------xmeet_unloaded---------------------------------
4005 // Compute the MEET of two InstPtrs when at least one is unloaded.
4006 // Assume classes are different since called after check for same name/class-loader
4007 const TypeInstPtr *TypeInstPtr::xmeet_unloaded(const TypeInstPtr *tinst) const {
4008     Offset off = meet_offset(tinst->offset());
4009     PTR ptr = meet_ptr(tinst->ptr());
4010     int instance_id = meet_instance_id(tinst->instance_id());
4011     const TypePtr* speculative = xmeet_speculative(tinst);
4012     int depth = meet_inline_depth(tinst->inline_depth());
4013 
4014     const TypeInstPtr *loaded    = is_loaded() ? this  : tinst;
4015     const TypeInstPtr *unloaded  = is_loaded() ? tinst : this;
4016     if( loaded->klass()->equals(ciEnv::current()->Object_klass()) ) {
4017       //
4018       // Meet unloaded class with java/lang/Object
4019       //
4020       // Meet
4021       //          |                     Unloaded Class
4022       //  Object  |   TOP    |   AnyNull | Constant |   NotNull |  BOTTOM   |
4023       //  ===================================================================
4024       //   TOP    | ..........................Unloaded......................|
4025       //  AnyNull |  U-AN    |................Unloaded......................|
4026       // Constant | ... O-NN .................................. |   O-BOT   |
4027       //  NotNull | ... O-NN .................................. |   O-BOT   |
4028       //  BOTTOM  | ........................Object-BOTTOM ..................|
4029       //
4030       assert(loaded->ptr() != TypePtr::Null, "insanity check");
4031       //
4032       if(      loaded->ptr() == TypePtr::TopPTR ) { return unloaded; }
4033       else if (loaded->ptr() == TypePtr::AnyNull) { return TypeInstPtr::make(ptr, unloaded->klass(), false, NULL, off, false, instance_id, speculative, depth); }
4034       else if (loaded->ptr() == TypePtr::BotPTR ) { return TypeInstPtr::BOTTOM; }
4035       else if (loaded->ptr() == TypePtr::Constant || loaded->ptr() == TypePtr::NotNull) {
4036         if (unloaded->ptr() == TypePtr::BotPTR  ) { return TypeInstPtr::BOTTOM;  }
4037         else                                      { return TypeInstPtr::NOTNULL; }
4038       }
4039       else if( unloaded->ptr() == TypePtr::TopPTR )  { return unloaded; }
4040 
4041       return unloaded->cast_to_ptr_type(TypePtr::AnyNull)->is_instptr();
4042     }
4043 
4044     // Both are unloaded, not the same class, not Object
4045     // Or meet unloaded with a different loaded class, not java/lang/Object
4046     if( ptr != TypePtr::BotPTR ) {
4047       return TypeInstPtr::NOTNULL;
4048     }
4049     return TypeInstPtr::BOTTOM;
4050 }
4051 
4052 
4053 //------------------------------meet-------------------------------------------
4054 // Compute the MEET of two types.  It returns a new Type object.
4055 const Type *TypeInstPtr::xmeet_helper(const Type *t) const {
4056   // Perform a fast test for common case; meeting the same types together.
4057   if( this == t ) return this;  // Meeting same type-rep?
4058 
4059   // Current "this->_base" is Pointer
4060   switch (t->base()) {          // switch on original type
4061 
4062   case Int:                     // Mixing ints & oops happens when javac
4063   case Long:                    // reuses local variables
4064   case FloatTop:
4065   case FloatCon:
4066   case FloatBot:
4067   case DoubleTop:
4068   case DoubleCon:
4069   case DoubleBot:
4070   case NarrowOop:
4071   case NarrowKlass:
4072   case Bottom:                  // Ye Olde Default
4073     return Type::BOTTOM;
4074   case Top:
4075     return this;
4076 
4077   default:                      // All else is a mistake
4078     typerr(t);
4079 
4080   case MetadataPtr:
4081   case KlassPtr:
4082   case InstKlassPtr:
4083   case AryKlassPtr:
4084   case RawPtr: return TypePtr::BOTTOM;
4085 
4086   case AryPtr: {                // All arrays inherit from Object class
4087     // Call in reverse direction to avoid duplication
4088     return t->is_aryptr()->xmeet_helper(this);
4089   }
4090 
4091   case OopPtr: {                // Meeting to OopPtrs
4092     // Found a OopPtr type vs self-InstPtr type
4093     const TypeOopPtr *tp = t->is_oopptr();
4094     Offset offset = meet_offset(tp->offset());
4095     PTR ptr = meet_ptr(tp->ptr());
4096     switch (tp->ptr()) {
4097     case TopPTR:
4098     case AnyNull: {
4099       int instance_id = meet_instance_id(InstanceTop);
4100       const TypePtr* speculative = xmeet_speculative(tp);
4101       int depth = meet_inline_depth(tp->inline_depth());
4102       return make(ptr, klass(), klass_is_exact(),
4103                   (ptr == Constant ? const_oop() : NULL), offset, flatten_array(), instance_id, speculative, depth);
4104     }
4105     case NotNull:
4106     case BotPTR: {
4107       int instance_id = meet_instance_id(tp->instance_id());
4108       const TypePtr* speculative = xmeet_speculative(tp);
4109       int depth = meet_inline_depth(tp->inline_depth());
4110       return TypeOopPtr::make(ptr, offset, instance_id, speculative, depth);
4111     }
4112     default: typerr(t);
4113     }
4114   }
4115 
4116   case AnyPtr: {                // Meeting to AnyPtrs
4117     // Found an AnyPtr type vs self-InstPtr type
4118     const TypePtr *tp = t->is_ptr();
4119     Offset offset = meet_offset(tp->offset());
4120     PTR ptr = meet_ptr(tp->ptr());
4121     int instance_id = meet_instance_id(InstanceTop);
4122     const TypePtr* speculative = xmeet_speculative(tp);
4123     int depth = meet_inline_depth(tp->inline_depth());
4124     switch (tp->ptr()) {
4125     case Null:
4126       if( ptr == Null ) return TypePtr::make(AnyPtr, ptr, offset, speculative, depth);
4127       // else fall through to AnyNull
4128     case TopPTR:
4129     case AnyNull: {
4130       return make(ptr, klass(), klass_is_exact(),
4131                   (ptr == Constant ? const_oop() : NULL), offset, flatten_array(), instance_id, speculative, depth);
4132     }
4133     case NotNull:
4134     case BotPTR:
4135       return TypePtr::make(AnyPtr, ptr, offset, speculative,depth);
4136     default: typerr(t);
4137     }
4138   }
4139 
4140   /*
4141                  A-top         }
4142                /   |   \       }  Tops
4143            B-top A-any C-top   }
4144               | /  |  \ |      }  Any-nulls
4145            B-any   |   C-any   }
4146               |    |    |
4147            B-con A-con C-con   } constants; not comparable across classes
4148               |    |    |
4149            B-not   |   C-not   }
4150               | \  |  / |      }  not-nulls
4151            B-bot A-not C-bot   }
4152                \   |   /       }  Bottoms
4153                  A-bot         }
4154   */
4155 
4156   case InstPtr: {                // Meeting 2 Oops?
4157     // Found an InstPtr sub-type vs self-InstPtr type
4158     const TypeInstPtr *tinst = t->is_instptr();
4159     Offset off = meet_offset(tinst->offset());
4160     PTR ptr = meet_ptr(tinst->ptr());
4161     int instance_id = meet_instance_id(tinst->instance_id());
4162     const TypePtr* speculative = xmeet_speculative(tinst);
4163     int depth = meet_inline_depth(tinst->inline_depth());
4164     ciKlass* tinst_klass = tinst->klass();
4165     ciKlass* this_klass  = klass();
4166     bool tinst_xk = tinst->klass_is_exact();
4167     bool this_xk  = this->klass_is_exact();
4168     bool tinst_flatten_array = tinst->flatten_array();
4169     bool this_flatten_array  = this->flatten_array();
4170 
4171     ciKlass* res_klass = NULL;
4172     bool res_xk = false;
4173     bool res_flatten_array = false;
4174     const Type* res;
4175     MeetResult kind = meet_instptr(ptr, this_klass, tinst_klass, this_xk, tinst_xk, this->_ptr, tinst->_ptr,
4176                                    this_flatten_array, tinst_flatten_array,
4177                                    res_klass, res_xk, res_flatten_array);
4178     if (kind == UNLOADED) {
4179       // One of these classes has not been loaded
4180       const TypeInstPtr* unloaded_meet = xmeet_unloaded(tinst);
4181 #ifndef PRODUCT
4182       if (PrintOpto && Verbose) {
4183         tty->print("meet of unloaded classes resulted in: ");
4184         unloaded_meet->dump();
4185         tty->cr();
4186         tty->print("  this == ");
4187         dump();
4188         tty->cr();
4189         tty->print(" tinst == ");
4190         tinst->dump();
4191         tty->cr();
4192       }
4193 #endif
4194       res = unloaded_meet;
4195     } else {
4196       if (kind == NOT_SUBTYPE && instance_id > 0) {
4197         instance_id = InstanceBot;
4198       } else if (kind == LCA) {
4199         instance_id = InstanceBot;
4200       }
4201       ciObject* o = NULL;             // Assume not constant when done
4202       ciObject* this_oop = const_oop();
4203       ciObject* tinst_oop = tinst->const_oop();
4204       if (ptr == Constant) {
4205         if (this_oop != NULL && tinst_oop != NULL &&
4206             this_oop->equals(tinst_oop))
4207           o = this_oop;
4208         else if (above_centerline(_ptr)) {
4209           assert(!tinst_klass->is_interface(), "");
4210           o = tinst_oop;
4211         } else if (above_centerline(tinst->_ptr)) {
4212           assert(!this_klass->is_interface(), "");
4213           o = this_oop;
4214         } else
4215           ptr = NotNull;
4216       }
4217       res = make(ptr, res_klass, res_xk, o, off, res_flatten_array, instance_id, speculative, depth);
4218     }
4219 
4220     return res;
4221 
4222   } // End of case InstPtr
4223 
4224   case InlineType: {
4225     const TypeInlineType* tv = t->is_inlinetype();
4226     if (above_centerline(ptr())) {
4227       if (tv->inline_klass()->is_subtype_of(_klass)) {
4228         return t;
4229       } else {
4230         return TypeInstPtr::NOTNULL;
4231       }
4232     } else {
4233       PTR ptr = this->_ptr;
4234       if (ptr == Constant) {
4235         ptr = NotNull;
4236       }
4237       if (tv->inline_klass()->is_subtype_of(_klass)) {
4238         return make(ptr, _klass, false, NULL, Offset(0), _flatten_array, InstanceBot, _speculative);
4239       } else {
4240         return make(ptr, ciEnv::current()->Object_klass());
4241       }
4242     }
4243   }
4244 
4245   } // End of switch
4246   return this;                  // Return the double constant
4247 }
4248 
4249 TypePtr::MeetResult TypePtr::meet_instptr(PTR &ptr, ciKlass* this_klass, ciKlass* tinst_klass, bool this_xk, bool tinst_xk,
4250                                           PTR this_ptr, PTR tinst_ptr, bool this_flatten_array, bool tinst_flatten_array,
4251                                           ciKlass*&res_klass, bool &res_xk, bool& res_flatten_array) {
4252 
4253   bool this_flatten_array_orig = this_flatten_array;
4254   bool tinst_flatten_array_orig = tinst_flatten_array;
4255 
4256   // Check for easy case; klasses are equal (and perhaps not loaded!)
4257   // If we have constants, then we created oops so classes are loaded
4258   // and we can handle the constants further down.  This case handles
4259   // both-not-loaded or both-loaded classes
4260   if (ptr != Constant && this_klass->equals(tinst_klass) && this_xk == tinst_xk && this_flatten_array == tinst_flatten_array) {
4261     res_klass = this_klass;
4262     res_xk = this_xk;
4263     res_flatten_array = this_flatten_array;
4264     return QUICK;
4265   }
4266 
4267   // Classes require inspection in the Java klass hierarchy.  Must be loaded.
4268   if (!tinst_klass->is_loaded() || !this_klass->is_loaded()) {
4269     return UNLOADED;
4270   }
4271 
4272   // Handle mixing oops and interfaces first.
4273   if (this_klass->is_interface() && !(tinst_klass->is_interface() ||
4274                                       tinst_klass == ciEnv::current()->Object_klass())) {
4275     ciKlass *tmp = tinst_klass; // Swap interface around
4276     tinst_klass = this_klass;
4277     this_klass = tmp;
4278     bool tmp2 = tinst_xk;
4279     tinst_xk = this_xk;
4280     this_xk = tmp2;
4281     tmp2 = tinst_flatten_array;
4282     tinst_flatten_array = this_flatten_array;
4283     this_flatten_array = tmp2;
4284   }
4285   if (tinst_klass->is_interface() &&
4286       !(this_klass->is_interface() ||
4287         // Treat java/lang/Object as an honorary interface,
4288         // because we need a bottom for the interface hierarchy.
4289         this_klass == ciEnv::current()->Object_klass())) {
4290     // Oop meets interface!
4291 
4292     // See if the oop subtypes (implements) interface.
4293     if (this_klass->is_subtype_of(tinst_klass)) {
4294       // Oop indeed subtypes.  Now keep oop or interface depending
4295       // on whether we are both above the centerline or either is
4296       // below the centerline.  If we are on the centerline
4297       // (e.g., Constant vs. AnyNull interface), use the constant.
4298       res_klass  = below_centerline(ptr) ? tinst_klass : this_klass;
4299       // If we are keeping this_klass, keep its exactness too.
4300       res_xk = below_centerline(ptr) ? tinst_xk    : this_xk;
4301       res_flatten_array = below_centerline(ptr) ? tinst_flatten_array    : this_flatten_array;
4302       return SUBTYPE;
4303     } else {                  // Does not implement, fall to Object
4304       // Oop does not implement interface, so mixing falls to Object
4305       // just like the verifier does (if both are above the
4306       // centerline fall to interface)
4307       res_klass = above_centerline(ptr) ? tinst_klass : ciEnv::current()->Object_klass();
4308       res_xk = above_centerline(ptr) ? tinst_xk : false;
4309       res_flatten_array = above_centerline(ptr) ? tinst_flatten_array : false;
4310       // Watch out for Constant vs. AnyNull interface.
4311       if (ptr == Constant)  ptr = NotNull;   // forget it was a constant
4312       return NOT_SUBTYPE;
4313     }
4314   }
4315 
4316   // Either oop vs oop or interface vs interface or interface vs Object
4317 
4318   // !!! Here's how the symmetry requirement breaks down into invariants:
4319   // If we split one up & one down AND they subtype, take the down man.
4320   // If we split one up & one down AND they do NOT subtype, "fall hard".
4321   // If both are up and they subtype, take the subtype class.
4322   // If both are up and they do NOT subtype, "fall hard".
4323   // If both are down and they subtype, take the supertype class.
4324   // If both are down and they do NOT subtype, "fall hard".
4325   // Constants treated as down.
4326 
4327   // Now, reorder the above list; observe that both-down+subtype is also
4328   // "fall hard"; "fall hard" becomes the default case:
4329   // If we split one up & one down AND they subtype, take the down man.
4330   // If both are up and they subtype, take the subtype class.
4331 
4332   // If both are down and they subtype, "fall hard".
4333   // If both are down and they do NOT subtype, "fall hard".
4334   // If both are up and they do NOT subtype, "fall hard".
4335   // If we split one up & one down AND they do NOT subtype, "fall hard".
4336 
4337   // If a proper subtype is exact, and we return it, we return it exactly.
4338   // If a proper supertype is exact, there can be no subtyping relationship!
4339   // If both types are equal to the subtype, exactness is and-ed below the
4340   // centerline and or-ed above it.  (N.B. Constants are always exact.)
4341 
4342   // Check for subtyping:
4343   ciKlass *subtype = NULL;
4344   bool subtype_exact = false;
4345   bool flat_array = false;
4346   if (tinst_klass->equals(this_klass)) {
4347     subtype = this_klass;
4348     subtype_exact = below_centerline(ptr) ? (this_xk && tinst_xk) : (this_xk || tinst_xk);
4349     flat_array = below_centerline(ptr) ? (this_flatten_array && tinst_flatten_array) : (this_flatten_array || tinst_flatten_array);
4350   } else if (!tinst_xk && this_klass->is_subtype_of(tinst_klass) && (!tinst_flatten_array || this_flatten_array)) {
4351     subtype = this_klass;     // Pick subtyping class
4352     subtype_exact = this_xk;
4353     flat_array = this_flatten_array;
4354   } else if (!this_xk && tinst_klass->is_subtype_of(this_klass) && (!this_flatten_array || tinst_flatten_array)) {
4355     subtype = tinst_klass;    // Pick subtyping class
4356     subtype_exact = tinst_xk;
4357     flat_array = tinst_flatten_array;
4358   }
4359 
4360   if (subtype) {
4361     if (above_centerline(ptr)) { // both are up?
4362       this_klass = tinst_klass = subtype;
4363       this_xk = tinst_xk = subtype_exact;
4364       this_flatten_array = tinst_flatten_array = flat_array;
4365     } else if (above_centerline(this_ptr) && !above_centerline(tinst_ptr)) {
4366       this_klass = tinst_klass; // tinst is down; keep down man
4367       this_xk = tinst_xk;
4368       this_flatten_array = tinst_flatten_array;
4369     } else if (above_centerline(tinst_ptr) && !above_centerline(this_ptr)) {
4370       tinst_klass = this_klass; // this is down; keep down man
4371       tinst_xk = this_xk;
4372       tinst_flatten_array = this_flatten_array;
4373     } else {
4374       this_xk = subtype_exact;  // either they are equal, or we'll do an LCA
4375       this_flatten_array = flat_array;
4376     }
4377   }
4378 
4379   // Check for classes now being equal
4380   if (tinst_klass->equals(this_klass)) {
4381     // If the klasses are equal, the constants may still differ.  Fall to
4382     // NotNull if they do (neither constant is NULL; that is a special case
4383     // handled elsewhere).
4384     res_klass = this_klass;
4385     res_xk = this_xk;
4386     res_flatten_array = this_flatten_array;
4387     return SUBTYPE;
4388   } // Else classes are not equal
4389 
4390   // Since klasses are different, we require a LCA in the Java
4391   // class hierarchy - which means we have to fall to at least NotNull.
4392   if (ptr == TopPTR || ptr == AnyNull || ptr == Constant) {
4393     ptr = NotNull;
4394   }
4395 
4396   // Now we find the LCA of Java classes
4397   ciKlass* k = this_klass->least_common_ancestor(tinst_klass);
4398 
4399   res_klass = k;
4400   res_xk = false;
4401   res_flatten_array = this_flatten_array_orig && tinst_flatten_array_orig;
4402 
4403   return LCA;
4404 }
4405 
4406 
4407 //------------------------java_mirror_type--------------------------------------
4408 ciType* TypeInstPtr::java_mirror_type(bool* is_val_mirror) const {
4409   // must be a singleton type
4410   if( const_oop() == NULL )  return NULL;
4411 
4412   // must be of type java.lang.Class
4413   if( klass() != ciEnv::current()->Class_klass() )  return NULL;
4414   return const_oop()->as_instance()->java_mirror_type(is_val_mirror);

4415 }
4416 
4417 
4418 //------------------------------xdual------------------------------------------
4419 // Dual: do NOT dual on klasses.  This means I do NOT understand the Java
4420 // inheritance mechanism.
4421 const Type *TypeInstPtr::xdual() const {
4422   return new TypeInstPtr(dual_ptr(), klass(), klass_is_exact(), const_oop(), dual_offset(), flatten_array(), dual_instance_id(), dual_speculative(), dual_inline_depth());
4423 }
4424 
4425 //------------------------------eq---------------------------------------------
4426 // Structural equality check for Type representations
4427 bool TypeInstPtr::eq( const Type *t ) const {
4428   const TypeInstPtr *p = t->is_instptr();
4429   return
4430     klass()->equals(p->klass()) &&
4431     flatten_array() == p->flatten_array() &&
4432     TypeOopPtr::eq(p);          // Check sub-type stuff
4433 }
4434 
4435 //------------------------------hash-------------------------------------------
4436 // Type-specific hashing function.
4437 int TypeInstPtr::hash(void) const {
4438   int hash = java_add(java_add((jint)klass()->hash(), (jint)TypeOopPtr::hash()), (jint)flatten_array());
4439   return hash;
4440 }
4441 
4442 //------------------------------dump2------------------------------------------
4443 // Dump oop Type
4444 #ifndef PRODUCT
4445 void TypeInstPtr::dump2(Dict &d, uint depth, outputStream* st) const {
4446   // Print the name of the klass.
4447   klass()->print_name_on(st);
4448 
4449   switch( _ptr ) {
4450   case Constant:
4451     if (WizardMode || Verbose) {
4452       ResourceMark rm;
4453       stringStream ss;
4454 
4455       st->print(" ");
4456       const_oop()->print_oop(&ss);
4457       // 'const_oop->print_oop()' may emit newlines('\n') into ss.
4458       // suppress newlines from it so -XX:+Verbose -XX:+PrintIdeal dumps one-liner for each node.
4459       char* buf = ss.as_string(/* c_heap= */false);
4460       StringUtils::replace_no_expand(buf, "\n", "");
4461       st->print_raw(buf);
4462     }
4463   case BotPTR:
4464     if (!WizardMode && !Verbose) {
4465       if( _klass_is_exact ) st->print(":exact");
4466       break;
4467     }
4468   case TopPTR:
4469   case AnyNull:
4470   case NotNull:
4471     st->print(":%s", ptr_msg[_ptr]);
4472     if( _klass_is_exact ) st->print(":exact");
4473     break;
4474   default:
4475     break;
4476   }
4477 
4478   _offset.dump2(st);




4479 
4480   st->print(" *");
4481 
4482   if (flatten_array() && !klass()->is_inlinetype()) {
4483     st->print(" (flatten array)");
4484   }
4485 
4486   if (_instance_id == InstanceTop)
4487     st->print(",iid=top");
4488   else if (_instance_id != InstanceBot)
4489     st->print(",iid=%d",_instance_id);
4490 
4491   dump_inline_depth(st);
4492   dump_speculative(st);
4493 }
4494 #endif
4495 
4496 //------------------------------add_offset-------------------------------------
4497 const TypePtr *TypeInstPtr::add_offset(intptr_t offset) const {
4498   return make(_ptr, klass(), klass_is_exact(), const_oop(), xadd_offset(offset), flatten_array(),
4499               _instance_id, add_offset_speculative(offset), _inline_depth);
4500 }
4501 
4502 const Type *TypeInstPtr::remove_speculative() const {
4503   if (_speculative == NULL) {
4504     return this;
4505   }
4506   assert(_inline_depth == InlineDepthTop || _inline_depth == InlineDepthBottom, "non speculative type shouldn't have inline depth");
4507   return make(_ptr, klass(), klass_is_exact(), const_oop(), _offset, flatten_array(),
4508               _instance_id, NULL, _inline_depth);
4509 }
4510 
4511 const TypePtr *TypeInstPtr::with_inline_depth(int depth) const {
4512   if (!UseInlineDepthForSpeculativeTypes) {
4513     return this;
4514   }
4515   return make(_ptr, klass(), klass_is_exact(), const_oop(), _offset, flatten_array(), _instance_id, _speculative, depth);
4516 }
4517 
4518 const TypePtr *TypeInstPtr::with_instance_id(int instance_id) const {
4519   assert(is_known_instance(), "should be known");
4520   return make(_ptr, klass(), klass_is_exact(), const_oop(), _offset, flatten_array(), instance_id, _speculative, _inline_depth);
4521 }
4522 
4523 const TypeInstPtr *TypeInstPtr::cast_to_flatten_array() const {
4524   return make(_ptr, klass(), klass_is_exact(), const_oop(), _offset, true, _instance_id, _speculative, _inline_depth);
4525 }
4526 
4527 const TypeKlassPtr* TypeInstPtr::as_klass_type(bool try_for_exact) const {
4528   bool xk = klass_is_exact();
4529   ciInstanceKlass* ik = klass()->as_instance_klass();
4530   if (try_for_exact && !xk && !ik->has_subklass() && !ik->is_final() && !ik->is_interface()) {
4531     Compile* C = Compile::current();
4532     Dependencies* deps = C->dependencies();
4533     deps->assert_leaf_type(ik);
4534     xk = true;
4535   }
4536   return TypeInstKlassPtr::make(xk ? TypePtr::Constant : TypePtr::NotNull, klass(), Offset(0), flatten_array());
4537 }
4538 
4539 //=============================================================================
4540 // Convenience common pre-built types.
4541 const TypeAryPtr *TypeAryPtr::RANGE;
4542 const TypeAryPtr *TypeAryPtr::OOPS;
4543 const TypeAryPtr *TypeAryPtr::NARROWOOPS;
4544 const TypeAryPtr *TypeAryPtr::BYTES;
4545 const TypeAryPtr *TypeAryPtr::SHORTS;
4546 const TypeAryPtr *TypeAryPtr::CHARS;
4547 const TypeAryPtr *TypeAryPtr::INTS;
4548 const TypeAryPtr *TypeAryPtr::LONGS;
4549 const TypeAryPtr *TypeAryPtr::FLOATS;
4550 const TypeAryPtr *TypeAryPtr::DOUBLES;
4551 const TypeAryPtr *TypeAryPtr::INLINES;
4552 
4553 //------------------------------make-------------------------------------------
4554 const TypeAryPtr* TypeAryPtr::make(PTR ptr, const TypeAry *ary, ciKlass* k, bool xk, Offset offset, Offset field_offset,
4555                                    int instance_id, const TypePtr* speculative, int inline_depth) {
4556   assert(!(k == NULL && ary->_elem->isa_int()),
4557          "integral arrays must be pre-equipped with a class");
4558   if (!xk)  xk = ary->ary_must_be_exact();
4559   assert(instance_id <= 0 || xk, "instances are always exactly typed");
4560   return (TypeAryPtr*)(new TypeAryPtr(ptr, NULL, ary, k, xk, offset, field_offset, instance_id, false, speculative, inline_depth))->hashcons();
4561 }
4562 
4563 //------------------------------make-------------------------------------------
4564 const TypeAryPtr* TypeAryPtr::make(PTR ptr, ciObject* o, const TypeAry *ary, ciKlass* k, bool xk, Offset offset, Offset field_offset,
4565                                    int instance_id, const TypePtr* speculative, int inline_depth,
4566                                    bool is_autobox_cache) {
4567   assert(!(k == NULL && ary->_elem->isa_int()),
4568          "integral arrays must be pre-equipped with a class");
4569   assert( (ptr==Constant && o) || (ptr!=Constant && !o), "" );
4570   if (!xk)  xk = (o != NULL) || ary->ary_must_be_exact();
4571   assert(instance_id <= 0 || xk, "instances are always exactly typed");
4572   return (TypeAryPtr*)(new TypeAryPtr(ptr, o, ary, k, xk, offset, field_offset, instance_id, is_autobox_cache, speculative, inline_depth))->hashcons();
4573 }
4574 
4575 //------------------------------cast_to_ptr_type-------------------------------
4576 const TypeAryPtr* TypeAryPtr::cast_to_ptr_type(PTR ptr) const {
4577   if( ptr == _ptr ) return this;
4578   return make(ptr, const_oop(), _ary, klass(), klass_is_exact(), _offset, _field_offset, _instance_id, _speculative, _inline_depth, _is_autobox_cache);
4579 }
4580 
4581 
4582 //-----------------------------cast_to_exactness-------------------------------
4583 const Type *TypeAryPtr::cast_to_exactness(bool klass_is_exact) const {
4584   if( klass_is_exact == _klass_is_exact ) return this;
4585   if (_ary->ary_must_be_exact())  return this;  // cannot clear xk
4586 
4587   const TypeAry* new_ary = _ary;
4588   if (klass() != NULL && klass()->is_obj_array_klass() && klass_is_exact) {
4589     // An object array can't be flat or null-free if the klass is exact
4590     new_ary = TypeAry::make(elem(), size(), is_stable(), /* not_flat= */ true, /* not_null_free= */ true);
4591   }
4592   return make(ptr(), const_oop(), new_ary, klass(), klass_is_exact, _offset, _field_offset, _instance_id, _speculative, _inline_depth, _is_autobox_cache);
4593 }
4594 
4595 //-----------------------------cast_to_instance_id----------------------------
4596 const TypeOopPtr *TypeAryPtr::cast_to_instance_id(int instance_id) const {
4597   if( instance_id == _instance_id ) return this;
4598   return make(_ptr, const_oop(), _ary, klass(), _klass_is_exact, _offset, _field_offset, instance_id, _speculative, _inline_depth, _is_autobox_cache);
4599 }
4600 
4601 
4602 //-----------------------------max_array_length-------------------------------
4603 // A wrapper around arrayOopDesc::max_array_length(etype) with some input normalization.
4604 jint TypeAryPtr::max_array_length(BasicType etype) {
4605   if (!is_java_primitive(etype) && !is_reference_type(etype)) {
4606     if (etype == T_NARROWOOP) {
4607       etype = T_OBJECT;
4608     } else if (etype == T_ILLEGAL) { // bottom[]
4609       etype = T_BYTE; // will produce conservatively high value
4610     } else {
4611       fatal("not an element type: %s", type2name(etype));
4612     }
4613   }
4614   return arrayOopDesc::max_array_length(etype);
4615 }
4616 
4617 //-----------------------------narrow_size_type-------------------------------
4618 // Narrow the given size type to the index range for the given array base type.
4619 // Return NULL if the resulting int type becomes empty.
4620 const TypeInt* TypeAryPtr::narrow_size_type(const TypeInt* size) const {
4621   jint hi = size->_hi;
4622   jint lo = size->_lo;
4623   jint min_lo = 0;
4624   jint max_hi = max_array_length(elem()->basic_type());
4625   //if (index_not_size)  --max_hi;     // type of a valid array index, FTR
4626   bool chg = false;
4627   if (lo < min_lo) {
4628     lo = min_lo;
4629     if (size->is_con()) {
4630       hi = lo;
4631     }
4632     chg = true;
4633   }
4634   if (hi > max_hi) {
4635     hi = max_hi;
4636     if (size->is_con()) {
4637       lo = hi;
4638     }
4639     chg = true;
4640   }
4641   // Negative length arrays will produce weird intermediate dead fast-path code
4642   if (lo > hi)
4643     return TypeInt::ZERO;
4644   if (!chg)
4645     return size;
4646   return TypeInt::make(lo, hi, Type::WidenMin);
4647 }
4648 
4649 //-------------------------------cast_to_size----------------------------------
4650 const TypeAryPtr* TypeAryPtr::cast_to_size(const TypeInt* new_size) const {
4651   assert(new_size != NULL, "");
4652   new_size = narrow_size_type(new_size);
4653   if (new_size == size())  return this;
4654   const TypeAry* new_ary = TypeAry::make(elem(), new_size, is_stable(), is_not_flat(), is_not_null_free());
4655   return make(ptr(), const_oop(), new_ary, klass(), klass_is_exact(), _offset, _field_offset, _instance_id, _speculative, _inline_depth, _is_autobox_cache);
4656 }
4657 
4658 //-------------------------------cast_to_not_flat------------------------------
4659 const TypeAryPtr* TypeAryPtr::cast_to_not_flat(bool not_flat) const {
4660   if (not_flat == is_not_flat()) {
4661     return this;
4662   }
4663   const TypeAry* new_ary = TypeAry::make(elem(), size(), is_stable(), not_flat, is_not_null_free());
4664   return make(ptr(), const_oop(), new_ary, klass(), klass_is_exact(), _offset, _field_offset, _instance_id, _speculative, _inline_depth, _is_autobox_cache);
4665 }
4666 
4667 //-------------------------------cast_to_not_null_free-------------------------
4668 const TypeAryPtr* TypeAryPtr::cast_to_not_null_free(bool not_null_free) const {
4669   if (not_null_free == is_not_null_free()) {
4670     return this;
4671   }
4672   // Not null free implies not flat
4673   const TypeAry* new_ary = TypeAry::make(elem(), size(), is_stable(), not_null_free ? true : is_not_flat(), not_null_free);
4674   return make(ptr(), const_oop(), new_ary, klass(), klass_is_exact(), _offset, _field_offset, _instance_id, _speculative, _inline_depth, _is_autobox_cache);
4675 }
4676 
4677 //---------------------------------update_properties---------------------------
4678 const TypeAryPtr* TypeAryPtr::update_properties(const TypeAryPtr* from) const {
4679   if ((from->is_flat()          && is_not_flat()) ||
4680       (from->is_not_flat()      && is_flat()) ||
4681       (from->is_null_free()     && is_not_null_free()) ||
4682       (from->is_not_null_free() && is_null_free())) {
4683     return NULL; // Inconsistent properties
4684   } else if (from->is_not_null_free()) {
4685     return cast_to_not_null_free(); // Implies not flat
4686   } else if (from->is_not_flat()) {
4687     return cast_to_not_flat();
4688   }
4689   return this;
4690 }
4691 
4692 //------------------------------cast_to_stable---------------------------------
4693 const TypeAryPtr* TypeAryPtr::cast_to_stable(bool stable, int stable_dimension) const {
4694   if (stable_dimension <= 0 || (stable_dimension == 1 && stable == this->is_stable()))
4695     return this;
4696 
4697   const Type* elem = this->elem();
4698   const TypePtr* elem_ptr = elem->make_ptr();
4699 
4700   if (stable_dimension > 1 && elem_ptr != NULL && elem_ptr->isa_aryptr()) {
4701     // If this is widened from a narrow oop, TypeAry::make will re-narrow it.
4702     elem = elem_ptr = elem_ptr->is_aryptr()->cast_to_stable(stable, stable_dimension - 1);
4703   }
4704 
4705   const TypeAry* new_ary = TypeAry::make(elem, size(), stable, is_not_flat(), is_not_null_free());
4706 
4707   return make(ptr(), const_oop(), new_ary, klass(), klass_is_exact(), _offset, _field_offset, _instance_id, _speculative, _inline_depth, _is_autobox_cache);
4708 }
4709 
4710 //-----------------------------stable_dimension--------------------------------
4711 int TypeAryPtr::stable_dimension() const {
4712   if (!is_stable())  return 0;
4713   int dim = 1;
4714   const TypePtr* elem_ptr = elem()->make_ptr();
4715   if (elem_ptr != NULL && elem_ptr->isa_aryptr())
4716     dim += elem_ptr->is_aryptr()->stable_dimension();
4717   return dim;
4718 }
4719 
4720 //----------------------cast_to_autobox_cache-----------------------------------
4721 const TypeAryPtr* TypeAryPtr::cast_to_autobox_cache() const {
4722   if (is_autobox_cache())  return this;
4723   const TypeOopPtr* etype = elem()->make_oopptr();
4724   if (etype == NULL)  return this;
4725   // The pointers in the autobox arrays are always non-null.
4726   etype = etype->cast_to_ptr_type(TypePtr::NotNull)->is_oopptr();
4727   const TypeAry* new_ary = TypeAry::make(etype, size(), is_stable(), is_not_flat(), is_not_null_free());
4728   return make(ptr(), const_oop(), new_ary, klass(), klass_is_exact(), _offset, _field_offset, _instance_id, _speculative, _inline_depth, /*is_autobox_cache=*/true);
4729 }
4730 
4731 //------------------------------eq---------------------------------------------
4732 // Structural equality check for Type representations
4733 bool TypeAryPtr::eq( const Type *t ) const {
4734   const TypeAryPtr *p = t->is_aryptr();
4735   return
4736     _ary == p->_ary &&  // Check array
4737     TypeOopPtr::eq(p) &&// Check sub-parts
4738     _field_offset == p->_field_offset;
4739 }
4740 
4741 //------------------------------hash-------------------------------------------
4742 // Type-specific hashing function.
4743 int TypeAryPtr::hash(void) const {
4744   return (intptr_t)_ary + TypeOopPtr::hash() + _field_offset.get();
4745 }
4746 
4747 //------------------------------meet-------------------------------------------
4748 // Compute the MEET of two types.  It returns a new Type object.
4749 const Type *TypeAryPtr::xmeet_helper(const Type *t) const {
4750   // Perform a fast test for common case; meeting the same types together.
4751   if( this == t ) return this;  // Meeting same type-rep?
4752   // Current "this->_base" is Pointer
4753   switch (t->base()) {          // switch on original type
4754 
4755   // Mixing ints & oops happens when javac reuses local variables
4756   case Int:
4757   case Long:
4758   case FloatTop:
4759   case FloatCon:
4760   case FloatBot:
4761   case DoubleTop:
4762   case DoubleCon:
4763   case DoubleBot:
4764   case NarrowOop:
4765   case NarrowKlass:
4766   case Bottom:                  // Ye Olde Default
4767     return Type::BOTTOM;
4768   case Top:
4769     return this;
4770 
4771   default:                      // All else is a mistake
4772     typerr(t);
4773 
4774   case OopPtr: {                // Meeting to OopPtrs
4775     // Found a OopPtr type vs self-AryPtr type
4776     const TypeOopPtr *tp = t->is_oopptr();
4777     Offset offset = meet_offset(tp->offset());
4778     PTR ptr = meet_ptr(tp->ptr());
4779     int depth = meet_inline_depth(tp->inline_depth());
4780     const TypePtr* speculative = xmeet_speculative(tp);
4781     switch (tp->ptr()) {
4782     case TopPTR:
4783     case AnyNull: {
4784       int instance_id = meet_instance_id(InstanceTop);
4785       return make(ptr, (ptr == Constant ? const_oop() : NULL),
4786                   _ary, _klass, _klass_is_exact, offset, _field_offset, instance_id, speculative, depth);
4787     }
4788     case BotPTR:
4789     case NotNull: {
4790       int instance_id = meet_instance_id(tp->instance_id());
4791       return TypeOopPtr::make(ptr, offset, instance_id, speculative, depth);
4792     }
4793     default: ShouldNotReachHere();
4794     }
4795   }
4796 
4797   case AnyPtr: {                // Meeting two AnyPtrs
4798     // Found an AnyPtr type vs self-AryPtr type
4799     const TypePtr *tp = t->is_ptr();
4800     Offset offset = meet_offset(tp->offset());
4801     PTR ptr = meet_ptr(tp->ptr());
4802     const TypePtr* speculative = xmeet_speculative(tp);
4803     int depth = meet_inline_depth(tp->inline_depth());
4804     switch (tp->ptr()) {
4805     case TopPTR:
4806       return this;
4807     case BotPTR:
4808     case NotNull:
4809       return TypePtr::make(AnyPtr, ptr, offset, speculative, depth);
4810     case Null:
4811       if( ptr == Null ) return TypePtr::make(AnyPtr, ptr, offset, speculative, depth);
4812       // else fall through to AnyNull
4813     case AnyNull: {
4814       int instance_id = meet_instance_id(InstanceTop);
4815       return make(ptr, (ptr == Constant ? const_oop() : NULL),
4816                   _ary, _klass, _klass_is_exact, offset, _field_offset, instance_id, speculative, depth);
4817     }
4818     default: ShouldNotReachHere();
4819     }
4820   }
4821 
4822   case MetadataPtr:
4823   case KlassPtr:
4824   case InstKlassPtr:
4825   case AryKlassPtr:
4826   case RawPtr: return TypePtr::BOTTOM;
4827 
4828   case AryPtr: {                // Meeting 2 references?
4829     const TypeAryPtr *tap = t->is_aryptr();
4830     Offset off = meet_offset(tap->offset());
4831     Offset field_off = meet_field_offset(tap->field_offset());
4832     const TypeAry *tary = _ary->meet_speculative(tap->_ary)->is_ary();
4833     PTR ptr = meet_ptr(tap->ptr());
4834     int instance_id = meet_instance_id(tap->instance_id());
4835     const TypePtr* speculative = xmeet_speculative(tap);
4836     int depth = meet_inline_depth(tap->inline_depth());
4837 
4838     ciKlass* res_klass = NULL;
4839     bool res_xk = false;
4840     bool res_not_flat = false;
4841     bool res_not_null_free = false;
4842     const Type* res_elem = NULL;
4843     if (meet_aryptr(ptr, _ary->_elem, tap->_ary->_elem, this->klass(), tap->klass(),
4844                     this->klass_is_exact(), tap->klass_is_exact(), this->ptr(), tap->ptr(),
4845                     this->is_not_flat(), tap->is_not_flat(),
4846                     this->is_not_null_free(), tap->is_not_null_free(),
4847                     res_elem, res_klass, res_xk, res_not_flat, res_not_null_free) == NOT_SUBTYPE) {
4848       instance_id = InstanceBot;
4849     } else if (klass() != NULL && tap->klass() != NULL && klass()->is_flat_array_klass() != tap->klass()->is_flat_array_klass()) {
4850       // Meeting flattened inline type array with non-flattened array. Adjust (field) offset accordingly.
4851       if (tary->_elem->isa_inlinetype()) {
4852         // Result is flattened
4853         off = Offset(is_flat() ? offset() : tap->offset());
4854         field_off = is_flat() ? field_offset() : tap->field_offset();
4855       } else if (tary->_elem->make_oopptr() != NULL && tary->_elem->make_oopptr()->isa_instptr() && below_centerline(ptr)) {
4856         // Result is non-flattened
4857         off = Offset(flattened_offset()).meet(Offset(tap->flattened_offset()));
4858         field_off = Offset::bottom;
4859       }
4860     }
4861 
4862     ciObject* o = NULL;             // Assume not constant when done
4863     ciObject* this_oop = const_oop();
4864     ciObject* tap_oop = tap->const_oop();
4865     if (ptr == Constant) {
4866       if (this_oop != NULL && tap_oop != NULL &&
4867           this_oop->equals(tap_oop)) {
4868         o = tap_oop;
4869       } else if (above_centerline(_ptr)) {
4870         o = tap_oop;
4871       } else if (above_centerline(tap->_ptr)) {
4872         o = this_oop;
4873       } else {
4874         ptr = NotNull;
4875       }
4876     }
4877     return make(ptr, o, TypeAry::make(res_elem, tary->_size, tary->_stable, res_not_flat, res_not_null_free), res_klass, res_xk, off, field_off, instance_id, speculative, depth);
4878   }
4879 
4880   // All arrays inherit from Object class
4881   case InstPtr: {
4882     const TypeInstPtr *tp = t->is_instptr();
4883     Offset offset = meet_offset(tp->offset());
4884     PTR ptr = meet_ptr(tp->ptr());
4885     int instance_id = meet_instance_id(tp->instance_id());
4886     const TypePtr* speculative = xmeet_speculative(tp);
4887     int depth = meet_inline_depth(tp->inline_depth());
4888     switch (ptr) {
4889     case TopPTR:
4890     case AnyNull:                // Fall 'down' to dual of object klass
4891       // For instances when a subclass meets a superclass we fall
4892       // below the centerline when the superclass is exact. We need to
4893       // do the same here.
4894       if (tp->klass()->equals(ciEnv::current()->Object_klass()) && !tp->klass_is_exact() && !tp->flatten_array()) {
4895         return make(ptr, _ary, _klass, _klass_is_exact, offset, _field_offset, instance_id, speculative, depth);
4896       } else {
4897         // cannot subclass, so the meet has to fall badly below the centerline
4898         ptr = NotNull;
4899         instance_id = InstanceBot;
4900         return TypeInstPtr::make(ptr, ciEnv::current()->Object_klass(), false, NULL, offset, false, instance_id, speculative, depth);
4901       }
4902     case Constant:
4903     case NotNull:
4904     case BotPTR:                // Fall down to object klass
4905       // LCA is object_klass, but if we subclass from the top we can do better
4906       if (above_centerline(tp->ptr())) {
4907         // If 'tp'  is above the centerline and it is Object class
4908         // then we can subclass in the Java class hierarchy.
4909         // For instances when a subclass meets a superclass we fall
4910         // below the centerline when the superclass is exact. We need
4911         // to do the same here.
4912         if (tp->klass()->equals(ciEnv::current()->Object_klass()) && !tp->klass_is_exact() && !tp->flatten_array()) {
4913           // that is, my array type is a subtype of 'tp' klass
4914           return make(ptr, (ptr == Constant ? const_oop() : NULL),
4915                       _ary, _klass, _klass_is_exact, offset, _field_offset, instance_id, speculative, depth);
4916         }
4917       }
4918       // The other case cannot happen, since t cannot be a subtype of an array.
4919       // The meet falls down to Object class below centerline.
4920       if (ptr == Constant) {
4921          ptr = NotNull;
4922       }
4923       if (instance_id > 0) {
4924         instance_id = InstanceBot;
4925       }
4926       return TypeInstPtr::make(ptr, ciEnv::current()->Object_klass(), false, NULL, offset, false, instance_id, speculative, depth);
4927     default: typerr(t);
4928     }
4929   }
4930 
4931   case InlineType: {
4932     const TypeInlineType* tv = t->is_inlinetype();
4933     if (above_centerline(ptr())) {
4934       return TypeInstPtr::NOTNULL;
4935     } else {
4936       PTR ptr = this->_ptr;
4937       if (ptr == Constant) {
4938         ptr = NotNull;
4939       }
4940       return TypeInstPtr::make(ptr, ciEnv::current()->Object_klass());
4941     }
4942   }
4943   }
4944   return this;                  // Lint noise
4945 }
4946 
4947 
4948 TypePtr::MeetResult TypePtr::meet_aryptr(PTR& ptr, const Type* this_elem, const Type* tap_elem,
4949                                          ciKlass* this_klass, ciKlass* tap_klass,
4950                                          bool this_xk, bool tap_xk, PTR this_ptr, PTR tap_ptr,
4951                                          bool this_not_flat, bool tap_not_flat,
4952                                          bool this_not_null_free, bool tap_not_null_free,
4953                                          const Type*& res_elem, ciKlass*& res_klass,
4954                                          bool& res_xk, bool& res_not_flat, bool& res_not_null_free) {
4955   res_klass = NULL;
4956   MeetResult result = SUBTYPE;
4957   res_elem = this_elem->meet(tap_elem);
4958   res_not_flat = this_not_flat && tap_not_flat;
4959   res_not_null_free = this_not_null_free && tap_not_null_free;
4960 
4961   if (res_elem->isa_int()) {
4962     // Integral array element types have irrelevant lattice relations.
4963     // It is the klass that determines array layout, not the element type.
4964     if (this_klass == NULL) {
4965       res_klass = tap_klass;
4966     } else if (tap_klass == NULL || tap_klass == this_klass) {
4967       res_klass = this_klass;
4968     } else {
4969       // Something like byte[int+] meets char[int+].
4970       // This must fall to bottom, not (int[-128..65535])[int+].
4971       // instance_id = InstanceBot;
4972       res_elem = Type::BOTTOM;
4973       result = NOT_SUBTYPE;
4974     }
4975   } else // Non integral arrays.
4976     // Must fall to bottom if exact klasses in upper lattice
4977     // are not equal or super klass is exact.
4978     if ((above_centerline(ptr) || ptr == Constant) && this_klass != tap_klass &&
4979         // meet with top[] and bottom[] are processed further down:
4980         tap_klass != NULL  && this_klass != NULL   &&
4981         // both are exact and not equal:
4982         ((tap_xk && this_xk) ||
4983          // 'tap'  is exact and super or unrelated:
4984          (tap_xk && !tap_klass->is_subtype_of(this_klass)) ||
4985          // 'this' is exact and super or unrelated:
4986          (this_xk && !this_klass->is_subtype_of(tap_klass)))) {
4987       if (above_centerline(ptr) || (res_elem->make_ptr() && above_centerline(res_elem->make_ptr()->_ptr)) ||
4988           res_elem->isa_inlinetype()) {
4989         res_elem = Type::BOTTOM;
4990       }
4991       ptr = NotNull;
4992       res_xk = false;
4993       return NOT_SUBTYPE;
4994     }
4995 
4996   res_xk = false;
4997   switch (tap_ptr) {
4998     case AnyNull:
4999     case TopPTR:
5000       // Compute new klass on demand, do not use tap->_klass
5001       if (below_centerline(this_ptr)) {
5002         res_xk = this_xk;
5003         if (this_elem->isa_inlinetype()) {
5004           res_elem = this_elem;
5005         }
5006       } else {
5007         res_xk = (tap_xk || this_xk);
5008       }
5009       break;
5010     case Constant: {
5011       if (this_ptr == Constant) {
5012         res_xk = true;
5013       } else if(above_centerline(this_ptr)) {
5014         res_xk = true;
5015       } else {
5016         // Only precise for identical arrays
5017         res_xk = this_xk && (this_klass == tap_klass);
5018       }
5019       break;
5020     }
5021     case NotNull:
5022     case BotPTR:
5023       // Compute new klass on demand, do not use tap->_klass
5024       if (above_centerline(this_ptr)) {
5025         res_xk = tap_xk;
5026         if (tap_elem->isa_inlinetype()) {
5027           res_elem = tap_elem;
5028         }
5029       } else {
5030         res_xk = (tap_xk && this_xk) &&
5031           (this_klass == tap_klass); // Only precise for identical arrays
5032       }
5033       break;
5034     default:  {
5035       ShouldNotReachHere();
5036       return result;
5037     }
5038   }
5039 
5040   return result;
5041 }
5042 
5043 
5044 //------------------------------xdual------------------------------------------
5045 // Dual: compute field-by-field dual
5046 const Type *TypeAryPtr::xdual() const {
5047   return new TypeAryPtr(dual_ptr(), _const_oop, _ary->dual()->is_ary(), _klass, _klass_is_exact, dual_offset(), dual_field_offset(), dual_instance_id(), is_autobox_cache(), dual_speculative(), dual_inline_depth());
5048 }
5049 
5050 Type::Offset TypeAryPtr::meet_field_offset(const Type::Offset offset) const {
5051   return _field_offset.meet(offset);
5052 }
5053 
5054 //------------------------------dual_offset------------------------------------
5055 Type::Offset TypeAryPtr::dual_field_offset() const {
5056   return _field_offset.dual();
5057 }
5058 
5059 //----------------------interface_vs_oop---------------------------------------
5060 #ifdef ASSERT
5061 bool TypeAryPtr::interface_vs_oop(const Type *t) const {
5062   const TypeAryPtr* t_aryptr = t->isa_aryptr();
5063   if (t_aryptr) {
5064     return _ary->interface_vs_oop(t_aryptr->_ary);
5065   }
5066   return false;
5067 }
5068 #endif
5069 
5070 //------------------------------dump2------------------------------------------
5071 #ifndef PRODUCT
5072 void TypeAryPtr::dump2( Dict &d, uint depth, outputStream *st ) const {
5073   _ary->dump2(d,depth,st);
5074   switch( _ptr ) {
5075   case Constant:
5076     const_oop()->print(st);
5077     break;
5078   case BotPTR:
5079     if (!WizardMode && !Verbose) {
5080       if( _klass_is_exact ) st->print(":exact");
5081       break;
5082     }
5083   case TopPTR:
5084   case AnyNull:
5085   case NotNull:
5086     st->print(":%s", ptr_msg[_ptr]);
5087     if( _klass_is_exact ) st->print(":exact");
5088     break;
5089   default:
5090     break;
5091   }
5092 
5093   if (is_flat()) {
5094     st->print("(");
5095     _field_offset.dump2(st);
5096     st->print(")");
5097   }
5098   if (offset() != 0) {
5099     int header_size = objArrayOopDesc::header_size() * wordSize;
5100     if( _offset == Offset::top )       st->print("+undefined");
5101     else if( _offset == Offset::bottom )  st->print("+any");
5102     else if( offset() < header_size ) st->print("+%d", offset());
5103     else {
5104       BasicType basic_elem_type = elem()->basic_type();
5105       int array_base = arrayOopDesc::base_offset_in_bytes(basic_elem_type);
5106       int elem_size = type2aelembytes(basic_elem_type);
5107       st->print("[%d]", (offset() - array_base)/elem_size);
5108     }
5109   }
5110   st->print(" *");
5111   if (_instance_id == InstanceTop)
5112     st->print(",iid=top");
5113   else if (_instance_id != InstanceBot)
5114     st->print(",iid=%d",_instance_id);
5115 
5116   dump_inline_depth(st);
5117   dump_speculative(st);
5118 }
5119 #endif
5120 
5121 bool TypeAryPtr::empty(void) const {
5122   if (_ary->empty())       return true;
5123   return TypeOopPtr::empty();
5124 }
5125 
5126 //------------------------------add_offset-------------------------------------
5127 const TypePtr *TypeAryPtr::add_offset(intptr_t offset) const {
5128   return make(_ptr, _const_oop, _ary, _klass, _klass_is_exact, xadd_offset(offset), _field_offset, _instance_id, add_offset_speculative(offset), _inline_depth, _is_autobox_cache);
5129 }
5130 
5131 const Type *TypeAryPtr::remove_speculative() const {
5132   if (_speculative == NULL) {
5133     return this;
5134   }
5135   assert(_inline_depth == InlineDepthTop || _inline_depth == InlineDepthBottom, "non speculative type shouldn't have inline depth");
5136   return make(_ptr, _const_oop, _ary->remove_speculative()->is_ary(), _klass, _klass_is_exact, _offset, _field_offset, _instance_id, NULL, _inline_depth, _is_autobox_cache);
5137 }
5138 
5139 const Type* TypeAryPtr::cleanup_speculative() const {
5140   if (speculative() == NULL) {
5141     return this;
5142   }
5143   // Keep speculative part if it contains information about flat-/nullability
5144   const TypeAryPtr* spec_aryptr = speculative()->isa_aryptr();
5145   if (spec_aryptr != NULL && (spec_aryptr->is_not_flat() || spec_aryptr->is_not_null_free())) {
5146     return this;
5147   }
5148   return TypeOopPtr::cleanup_speculative();
5149 }
5150 
5151 const TypePtr *TypeAryPtr::with_inline_depth(int depth) const {
5152   if (!UseInlineDepthForSpeculativeTypes) {
5153     return this;
5154   }
5155   return make(_ptr, _const_oop, _ary->remove_speculative()->is_ary(), _klass, _klass_is_exact, _offset, _field_offset, _instance_id, _speculative, depth, _is_autobox_cache);
5156 }
5157 
5158 const TypeAryPtr* TypeAryPtr::with_field_offset(int offset) const {
5159   return make(_ptr, _const_oop, _ary->remove_speculative()->is_ary(), _klass, _klass_is_exact, _offset, Offset(offset), _instance_id, _speculative, _inline_depth, _is_autobox_cache);
5160 }
5161 
5162 const TypePtr* TypeAryPtr::add_field_offset_and_offset(intptr_t offset) const {
5163   int adj = 0;
5164   if (offset != Type::OffsetBot && offset != Type::OffsetTop) {
5165     const Type* elemtype = elem();
5166     if (elemtype->isa_inlinetype()) {
5167       if (_offset.get() != OffsetBot && _offset.get() != OffsetTop) {
5168         adj = _offset.get();
5169         offset += _offset.get();
5170       }
5171       uint header = arrayOopDesc::base_offset_in_bytes(T_OBJECT);
5172       if (_field_offset.get() != OffsetBot && _field_offset.get() != OffsetTop) {
5173         offset += _field_offset.get();
5174         if (_offset.get() == OffsetBot || _offset.get() == OffsetTop) {
5175           offset += header;
5176         }
5177       }
5178       if (offset >= (intptr_t)header || offset < 0) {
5179         // Try to get the field of the inline type array element we are pointing to
5180         ciKlass* arytype_klass = klass();
5181         ciFlatArrayKlass* vak = arytype_klass->as_flat_array_klass();
5182         ciInlineKlass* vk = vak->element_klass()->as_inline_klass();
5183         int shift = vak->log2_element_size();
5184         int mask = (1 << shift) - 1;
5185         intptr_t field_offset = ((offset - header) & mask);
5186         ciField* field = vk->get_field_by_offset(field_offset + vk->first_field_offset(), false);
5187         if (field == NULL) {
5188           // This may happen with nested AddP(base, AddP(base, base, offset), longcon(16))
5189           return add_offset(offset);
5190         } else {
5191           return with_field_offset(field_offset)->add_offset(offset - field_offset - adj);
5192         }
5193       }
5194     }
5195   }
5196   return add_offset(offset - adj);
5197 }
5198 
5199 // Return offset incremented by field_offset for flattened inline type arrays
5200 const int TypeAryPtr::flattened_offset() const {
5201   int offset = _offset.get();
5202   if (offset != Type::OffsetBot && offset != Type::OffsetTop &&
5203       _field_offset != Offset::bottom && _field_offset != Offset::top) {
5204     offset += _field_offset.get();
5205   }
5206   return offset;
5207 }
5208 
5209 const TypePtr *TypeAryPtr::with_instance_id(int instance_id) const {
5210   assert(is_known_instance(), "should be known");
5211   return make(_ptr, _const_oop, _ary->remove_speculative()->is_ary(), _klass, _klass_is_exact, _offset, _field_offset, instance_id, _speculative, _inline_depth);
5212 }
5213 
5214 //=============================================================================
5215 
5216 
5217 //------------------------------hash-------------------------------------------
5218 // Type-specific hashing function.
5219 int TypeNarrowPtr::hash(void) const {
5220   return _ptrtype->hash() + 7;
5221 }
5222 
5223 bool TypeNarrowPtr::singleton(void) const {    // TRUE if type is a singleton
5224   return _ptrtype->singleton();
5225 }
5226 
5227 bool TypeNarrowPtr::empty(void) const {
5228   return _ptrtype->empty();
5229 }
5230 
5231 intptr_t TypeNarrowPtr::get_con() const {
5232   return _ptrtype->get_con();
5233 }
5234 
5235 bool TypeNarrowPtr::eq( const Type *t ) const {
5236   const TypeNarrowPtr* tc = isa_same_narrowptr(t);
5237   if (tc != NULL) {
5238     if (_ptrtype->base() != tc->_ptrtype->base()) {
5239       return false;
5240     }
5241     return tc->_ptrtype->eq(_ptrtype);
5242   }
5243   return false;
5244 }
5245 
5246 const Type *TypeNarrowPtr::xdual() const {    // Compute dual right now.
5247   const TypePtr* odual = _ptrtype->dual()->is_ptr();
5248   return make_same_narrowptr(odual);
5249 }
5250 
5251 
5252 const Type *TypeNarrowPtr::filter_helper(const Type *kills, bool include_speculative) const {
5253   if (isa_same_narrowptr(kills)) {
5254     const Type* ft =_ptrtype->filter_helper(is_same_narrowptr(kills)->_ptrtype, include_speculative);
5255     if (ft->empty())
5256       return Type::TOP;           // Canonical empty value
5257     if (ft->isa_ptr()) {
5258       return make_hash_same_narrowptr(ft->isa_ptr());
5259     }
5260     return ft;
5261   } else if (kills->isa_ptr()) {
5262     const Type* ft = _ptrtype->join_helper(kills, include_speculative);
5263     if (ft->empty())
5264       return Type::TOP;           // Canonical empty value
5265     return ft;
5266   } else {
5267     return Type::TOP;
5268   }
5269 }
5270 
5271 //------------------------------xmeet------------------------------------------
5272 // Compute the MEET of two types.  It returns a new Type object.
5273 const Type *TypeNarrowPtr::xmeet( const Type *t ) const {
5274   // Perform a fast test for common case; meeting the same types together.
5275   if( this == t ) return this;  // Meeting same type-rep?
5276 
5277   if (t->base() == base()) {
5278     const Type* result = _ptrtype->xmeet(t->make_ptr());
5279     if (result->isa_ptr()) {
5280       return make_hash_same_narrowptr(result->is_ptr());
5281     }
5282     return result;
5283   }
5284 
5285   // Current "this->_base" is NarrowKlass or NarrowOop
5286   switch (t->base()) {          // switch on original type
5287 
5288   case Int:                     // Mixing ints & oops happens when javac
5289   case Long:                    // reuses local variables
5290   case FloatTop:
5291   case FloatCon:
5292   case FloatBot:
5293   case DoubleTop:
5294   case DoubleCon:
5295   case DoubleBot:
5296   case AnyPtr:
5297   case RawPtr:
5298   case OopPtr:
5299   case InstPtr:
5300   case AryPtr:
5301   case MetadataPtr:
5302   case KlassPtr:
5303   case InstKlassPtr:
5304   case AryKlassPtr:
5305   case NarrowOop:
5306   case NarrowKlass:

5307   case Bottom:                  // Ye Olde Default
5308     return Type::BOTTOM;
5309   case Top:
5310     return this;
5311 
5312   case InlineType:
5313     return t->xmeet(this);
5314 
5315   default:                      // All else is a mistake
5316     typerr(t);
5317 
5318   } // End of switch
5319 
5320   return this;
5321 }
5322 
5323 #ifndef PRODUCT
5324 void TypeNarrowPtr::dump2( Dict & d, uint depth, outputStream *st ) const {
5325   _ptrtype->dump2(d, depth, st);
5326 }
5327 #endif
5328 
5329 const TypeNarrowOop *TypeNarrowOop::BOTTOM;
5330 const TypeNarrowOop *TypeNarrowOop::NULL_PTR;
5331 
5332 
5333 const TypeNarrowOop* TypeNarrowOop::make(const TypePtr* type) {
5334   return (const TypeNarrowOop*)(new TypeNarrowOop(type))->hashcons();
5335 }
5336 
5337 const Type* TypeNarrowOop::remove_speculative() const {
5338   return make(_ptrtype->remove_speculative()->is_ptr());
5339 }
5340 
5341 const Type* TypeNarrowOop::cleanup_speculative() const {
5342   return make(_ptrtype->cleanup_speculative()->is_ptr());
5343 }
5344 
5345 #ifndef PRODUCT
5346 void TypeNarrowOop::dump2( Dict & d, uint depth, outputStream *st ) const {
5347   st->print("narrowoop: ");
5348   TypeNarrowPtr::dump2(d, depth, st);
5349 }
5350 #endif
5351 
5352 const TypeNarrowKlass *TypeNarrowKlass::NULL_PTR;
5353 
5354 const TypeNarrowKlass* TypeNarrowKlass::make(const TypePtr* type) {
5355   return (const TypeNarrowKlass*)(new TypeNarrowKlass(type))->hashcons();
5356 }
5357 
5358 #ifndef PRODUCT
5359 void TypeNarrowKlass::dump2( Dict & d, uint depth, outputStream *st ) const {
5360   st->print("narrowklass: ");
5361   TypeNarrowPtr::dump2(d, depth, st);
5362 }
5363 #endif
5364 
5365 
5366 //------------------------------eq---------------------------------------------
5367 // Structural equality check for Type representations
5368 bool TypeMetadataPtr::eq( const Type *t ) const {
5369   const TypeMetadataPtr *a = (const TypeMetadataPtr*)t;
5370   ciMetadata* one = metadata();
5371   ciMetadata* two = a->metadata();
5372   if (one == NULL || two == NULL) {
5373     return (one == two) && TypePtr::eq(t);
5374   } else {
5375     return one->equals(two) && TypePtr::eq(t);
5376   }
5377 }
5378 
5379 //------------------------------hash-------------------------------------------
5380 // Type-specific hashing function.
5381 int TypeMetadataPtr::hash(void) const {
5382   return
5383     (metadata() ? metadata()->hash() : 0) +
5384     TypePtr::hash();
5385 }
5386 
5387 //------------------------------singleton--------------------------------------
5388 // TRUE if Type is a singleton type, FALSE otherwise.   Singletons are simple
5389 // constants
5390 bool TypeMetadataPtr::singleton(void) const {
5391   // detune optimizer to not generate constant metadata + constant offset as a constant!
5392   // TopPTR, Null, AnyNull, Constant are all singletons
5393   return (offset() == 0) && !below_centerline(_ptr);
5394 }
5395 
5396 //------------------------------add_offset-------------------------------------
5397 const TypePtr *TypeMetadataPtr::add_offset( intptr_t offset ) const {
5398   return make( _ptr, _metadata, xadd_offset(offset));
5399 }
5400 
5401 //-----------------------------filter------------------------------------------
5402 // Do not allow interface-vs.-noninterface joins to collapse to top.
5403 const Type *TypeMetadataPtr::filter_helper(const Type *kills, bool include_speculative) const {
5404   const TypeMetadataPtr* ft = join_helper(kills, include_speculative)->isa_metadataptr();
5405   if (ft == NULL || ft->empty())
5406     return Type::TOP;           // Canonical empty value
5407   return ft;
5408 }
5409 
5410  //------------------------------get_con----------------------------------------
5411 intptr_t TypeMetadataPtr::get_con() const {
5412   assert( _ptr == Null || _ptr == Constant, "" );
5413   assert(offset() >= 0, "");
5414 
5415   if (offset() != 0) {
5416     // After being ported to the compiler interface, the compiler no longer
5417     // directly manipulates the addresses of oops.  Rather, it only has a pointer
5418     // to a handle at compile time.  This handle is embedded in the generated
5419     // code and dereferenced at the time the nmethod is made.  Until that time,
5420     // it is not reasonable to do arithmetic with the addresses of oops (we don't
5421     // have access to the addresses!).  This does not seem to currently happen,
5422     // but this assertion here is to help prevent its occurence.
5423     tty->print_cr("Found oop constant with non-zero offset");
5424     ShouldNotReachHere();
5425   }
5426 
5427   return (intptr_t)metadata()->constant_encoding();
5428 }
5429 
5430 //------------------------------cast_to_ptr_type-------------------------------
5431 const TypeMetadataPtr* TypeMetadataPtr::cast_to_ptr_type(PTR ptr) const {
5432   if( ptr == _ptr ) return this;
5433   return make(ptr, metadata(), _offset);
5434 }
5435 
5436 //------------------------------meet-------------------------------------------
5437 // Compute the MEET of two types.  It returns a new Type object.
5438 const Type *TypeMetadataPtr::xmeet( const Type *t ) const {
5439   // Perform a fast test for common case; meeting the same types together.
5440   if( this == t ) return this;  // Meeting same type-rep?
5441 
5442   // Current "this->_base" is OopPtr
5443   switch (t->base()) {          // switch on original type
5444 
5445   case Int:                     // Mixing ints & oops happens when javac
5446   case Long:                    // reuses local variables
5447   case FloatTop:
5448   case FloatCon:
5449   case FloatBot:
5450   case DoubleTop:
5451   case DoubleCon:
5452   case DoubleBot:
5453   case NarrowOop:
5454   case NarrowKlass:
5455   case Bottom:                  // Ye Olde Default
5456     return Type::BOTTOM;
5457   case Top:
5458     return this;
5459 
5460   default:                      // All else is a mistake
5461     typerr(t);
5462 
5463   case AnyPtr: {
5464     // Found an AnyPtr type vs self-OopPtr type
5465     const TypePtr *tp = t->is_ptr();
5466     Offset offset = meet_offset(tp->offset());
5467     PTR ptr = meet_ptr(tp->ptr());
5468     switch (tp->ptr()) {
5469     case Null:
5470       if (ptr == Null)  return TypePtr::make(AnyPtr, ptr, offset, tp->speculative(), tp->inline_depth());
5471       // else fall through:
5472     case TopPTR:
5473     case AnyNull: {
5474       return make(ptr, _metadata, offset);
5475     }
5476     case BotPTR:
5477     case NotNull:
5478       return TypePtr::make(AnyPtr, ptr, offset, tp->speculative(), tp->inline_depth());
5479     default: typerr(t);
5480     }
5481   }
5482 
5483   case RawPtr:
5484   case KlassPtr:
5485   case InstKlassPtr:
5486   case AryKlassPtr:
5487   case OopPtr:
5488   case InstPtr:
5489   case AryPtr:
5490     return TypePtr::BOTTOM;     // Oop meet raw is not well defined
5491 
5492   case MetadataPtr: {
5493     const TypeMetadataPtr *tp = t->is_metadataptr();
5494     Offset offset = meet_offset(tp->offset());
5495     PTR tptr = tp->ptr();
5496     PTR ptr = meet_ptr(tptr);
5497     ciMetadata* md = (tptr == TopPTR) ? metadata() : tp->metadata();
5498     if (tptr == TopPTR || _ptr == TopPTR ||
5499         metadata()->equals(tp->metadata())) {
5500       return make(ptr, md, offset);
5501     }
5502     // metadata is different
5503     if( ptr == Constant ) {  // Cannot be equal constants, so...
5504       if( tptr == Constant && _ptr != Constant)  return t;
5505       if( _ptr == Constant && tptr != Constant)  return this;
5506       ptr = NotNull;            // Fall down in lattice
5507     }
5508     return make(ptr, NULL, offset);
5509     break;
5510   }
5511   } // End of switch
5512   return this;                  // Return the double constant
5513 }
5514 
5515 
5516 //------------------------------xdual------------------------------------------
5517 // Dual of a pure metadata pointer.
5518 const Type *TypeMetadataPtr::xdual() const {
5519   return new TypeMetadataPtr(dual_ptr(), metadata(), dual_offset());
5520 }
5521 
5522 //------------------------------dump2------------------------------------------
5523 #ifndef PRODUCT
5524 void TypeMetadataPtr::dump2( Dict &d, uint depth, outputStream *st ) const {
5525   st->print("metadataptr:%s", ptr_msg[_ptr]);
5526   if( metadata() ) st->print(INTPTR_FORMAT, p2i(metadata()));
5527   switch (offset()) {
5528   case OffsetTop: st->print("+top"); break;
5529   case OffsetBot: st->print("+any"); break;
5530   case         0: break;
5531   default:        st->print("+%d",offset()); break;
5532   }
5533 }
5534 #endif
5535 
5536 
5537 //=============================================================================
5538 // Convenience common pre-built type.
5539 const TypeMetadataPtr *TypeMetadataPtr::BOTTOM;
5540 
5541 TypeMetadataPtr::TypeMetadataPtr(PTR ptr, ciMetadata* metadata, Offset offset):
5542   TypePtr(MetadataPtr, ptr, offset), _metadata(metadata) {
5543 }
5544 
5545 const TypeMetadataPtr* TypeMetadataPtr::make(ciMethod* m) {
5546   return make(Constant, m, Offset(0));
5547 }
5548 const TypeMetadataPtr* TypeMetadataPtr::make(ciMethodData* m) {
5549   return make(Constant, m, Offset(0));
5550 }
5551 
5552 //------------------------------make-------------------------------------------
5553 // Create a meta data constant
5554 const TypeMetadataPtr* TypeMetadataPtr::make(PTR ptr, ciMetadata* m, Offset offset) {
5555   assert(m == NULL || !m->is_klass(), "wrong type");
5556   return (TypeMetadataPtr*)(new TypeMetadataPtr(ptr, m, offset))->hashcons();
5557 }
5558 
5559 
5560 const TypeKlassPtr* TypeAryPtr::as_klass_type(bool try_for_exact) const {
5561   const Type* elem = _ary->_elem;
5562   bool xk = klass_is_exact();
5563   if (elem->make_oopptr() != NULL) {
5564     elem = elem->make_oopptr()->as_klass_type(try_for_exact);
5565     if (elem->is_klassptr()->klass_is_exact()) {
5566       xk = true;
5567     }
5568   }
5569   return TypeAryKlassPtr::make(xk ? TypePtr::Constant : TypePtr::NotNull, elem, klass(), Offset(0), is_not_flat(), is_not_null_free(), is_null_free());
5570 }
5571 
5572 const TypeKlassPtr* TypeKlassPtr::make(ciKlass *klass) {
5573   if (klass->is_instance_klass()) {
5574     return TypeInstKlassPtr::make(klass);
5575   }
5576   return TypeAryKlassPtr::make(klass);
5577 }
5578 
5579 const TypeKlassPtr* TypeKlassPtr::make(PTR ptr, ciKlass* klass, Offset offset) {
5580   if (klass->is_instance_klass()) {
5581     return TypeInstKlassPtr::make(ptr, klass, offset);
5582   }
5583   return TypeAryKlassPtr::make(klass, ptr, offset);
5584 }
5585 

5586 //------------------------------TypeKlassPtr-----------------------------------
5587 TypeKlassPtr::TypeKlassPtr(TYPES t, PTR ptr, ciKlass* klass, Offset offset)
5588   : TypePtr(t, ptr, offset), _klass(klass) {
5589 }
5590 
5591 //------------------------------eq---------------------------------------------
5592 // Structural equality check for Type representations
5593 bool TypeKlassPtr::eq(const Type *t) const {
5594   const TypeKlassPtr *p = t->is_klassptr();
5595   return
5596     TypePtr::eq(p);
5597 }
5598 
5599 //------------------------------hash-------------------------------------------
5600 // Type-specific hashing function.
5601 int TypeKlassPtr::hash(void) const {
5602   return TypePtr::hash();
5603 }
5604 
5605 //------------------------------singleton--------------------------------------
5606 // TRUE if Type is a singleton type, FALSE otherwise.   Singletons are simple
5607 // constants
5608 bool TypeKlassPtr::singleton(void) const {
5609   // detune optimizer to not generate constant klass + constant offset as a constant!
5610   // TopPTR, Null, AnyNull, Constant are all singletons
5611   return (offset() == 0) && !below_centerline(_ptr);
5612 }
5613 
5614 // Do not allow interface-vs.-noninterface joins to collapse to top.
5615 const Type *TypeKlassPtr::filter_helper(const Type *kills, bool include_speculative) const {
5616   // logic here mirrors the one from TypeOopPtr::filter. See comments
5617   // there.
5618   const Type* ft = join_helper(kills, include_speculative);
5619   const TypeKlassPtr* ftkp = ft->isa_instklassptr();
5620   const TypeKlassPtr* ktkp = kills->isa_instklassptr();
5621 
5622   if (ft->empty()) {
5623     if (!empty() && ktkp != NULL && ktkp->is_loaded() && ktkp->klass()->is_interface())
5624       return kills;             // Uplift to interface
5625 
5626     return Type::TOP;           // Canonical empty value
5627   }
5628 
5629   // Interface klass type could be exact in opposite to interface type,
5630   // return it here instead of incorrect Constant ptr J/L/Object (6894807).
5631   if (ftkp != NULL && ktkp != NULL &&
5632       ftkp->is_loaded() &&  ftkp->klass()->is_interface() &&
5633       !ftkp->klass_is_exact() && // Keep exact interface klass
5634       ktkp->is_loaded() && !ktkp->klass()->is_interface()) {
5635     return ktkp->cast_to_ptr_type(ftkp->ptr());
5636   }
5637 
5638   return ft;
5639 }
5640 
5641 //------------------------------get_con----------------------------------------
5642 intptr_t TypeKlassPtr::get_con() const {
5643   assert( _ptr == Null || _ptr == Constant, "" );
5644   assert( offset() >= 0, "" );
5645 
5646   if (offset() != 0) {
5647     // After being ported to the compiler interface, the compiler no longer
5648     // directly manipulates the addresses of oops.  Rather, it only has a pointer
5649     // to a handle at compile time.  This handle is embedded in the generated
5650     // code and dereferenced at the time the nmethod is made.  Until that time,
5651     // it is not reasonable to do arithmetic with the addresses of oops (we don't
5652     // have access to the addresses!).  This does not seem to currently happen,
5653     // but this assertion here is to help prevent its occurence.
5654     tty->print_cr("Found oop constant with non-zero offset");
5655     ShouldNotReachHere();
5656   }
5657 
5658   return (intptr_t)klass()->constant_encoding();
5659 }
5660 
5661 //------------------------------dump2------------------------------------------
5662 // Dump Klass Type
5663 #ifndef PRODUCT
5664 void TypeInstKlassPtr::dump2(Dict & d, uint depth, outputStream *st) const {
5665   switch(_ptr) {
5666   case Constant:
5667     st->print("precise ");
5668   case NotNull:
5669     {
5670       const char *name = klass()->name()->as_utf8();
5671       if (name) {
5672         st->print("%s: " INTPTR_FORMAT, name, p2i(klass()));
5673       } else {
5674         ShouldNotReachHere();
5675       }
5676     }
5677   case BotPTR:
5678     if (!WizardMode && !Verbose && _ptr != Constant) break;
5679   case TopPTR:
5680   case AnyNull:
5681     st->print(":%s", ptr_msg[_ptr]);
5682     if (_ptr == Constant) st->print(":exact");
5683     break;
5684   default:
5685     break;
5686   }
5687   if (Verbose) {
5688     if (_flatten_array) st->print(":flatten array");



5689   }
5690   _offset.dump2(st);
5691   st->print(" *");
5692 }
5693 #endif
5694 
5695 //=============================================================================
5696 // Convenience common pre-built types.
5697 
5698 // Not-null object klass or below
5699 const TypeInstKlassPtr *TypeInstKlassPtr::OBJECT;
5700 const TypeInstKlassPtr *TypeInstKlassPtr::OBJECT_OR_NULL;
5701 
5702 bool TypeInstKlassPtr::eq(const Type *t) const {
5703   const TypeKlassPtr *p = t->is_klassptr();
5704   return
5705     klass()->equals(p->klass()) &&
5706     flatten_array() == p->flatten_array() &&
5707     TypeKlassPtr::eq(p);
5708 }
5709 
5710 int TypeInstKlassPtr::hash(void) const {
5711   return java_add(java_add((jint)klass()->hash(), TypeKlassPtr::hash()), (jint)flatten_array());
5712 }
5713 
5714 const TypeInstKlassPtr *TypeInstKlassPtr::make(PTR ptr, ciKlass* k, Offset offset, bool flatten_array) {
5715   flatten_array = flatten_array || k->flatten_array();
5716 
5717   TypeInstKlassPtr *r =
5718     (TypeInstKlassPtr*)(new TypeInstKlassPtr(ptr, k, offset, flatten_array))->hashcons();
5719 
5720   return r;
5721 }
5722 
5723 //------------------------------add_offset-------------------------------------
5724 // Access internals of klass object
5725 const TypePtr *TypeInstKlassPtr::add_offset( intptr_t offset ) const {
5726   return make(_ptr, klass(), xadd_offset(offset), flatten_array());
5727 }
5728 
5729 const TypeKlassPtr *TypeInstKlassPtr::with_offset(intptr_t offset) const {
5730   return make(_ptr, klass(), Offset(offset), flatten_array());
5731 }
5732 
5733 //------------------------------cast_to_ptr_type-------------------------------
5734 const TypePtr* TypeInstKlassPtr::cast_to_ptr_type(PTR ptr) const {
5735   assert(_base == InstKlassPtr, "subclass must override cast_to_ptr_type");
5736   if( ptr == _ptr ) return this;
5737   return make(ptr, _klass, _offset, flatten_array());
5738 }
5739 
5740 
5741 bool TypeInstKlassPtr::must_be_exact() const {
5742   if (!_klass->is_loaded())  return false;
5743   ciInstanceKlass* ik = _klass->as_instance_klass();
5744   if (ik->is_final())  return true;  // cannot clear xk
5745   return false;
5746 }
5747 
5748 //-----------------------------cast_to_exactness-------------------------------
5749 const TypeKlassPtr* TypeInstKlassPtr::cast_to_exactness(bool klass_is_exact) const {
5750   if (klass_is_exact == (_ptr == Constant)) return this;
5751   if (must_be_exact()) return this;
5752   ciKlass* k = klass();
5753   return make(klass_is_exact ? Constant : NotNull, k, _offset, flatten_array());
5754 }
5755 
5756 
5757 //-----------------------------as_instance_type--------------------------------
5758 // Corresponding type for an instance of the given class.
5759 // It will be NotNull, and exact if and only if the klass type is exact.
5760 const TypeOopPtr* TypeInstKlassPtr::as_instance_type() const {
5761   ciKlass* k = klass();
5762   bool    xk = klass_is_exact();
5763   return TypeInstPtr::make(TypePtr::BotPTR, k, xk, NULL, Offset(0), flatten_array() && !klass()->is_inlinetype());
5764 }
5765 
5766 //------------------------------xmeet------------------------------------------
5767 // Compute the MEET of two types, return a new Type object.
5768 const Type    *TypeInstKlassPtr::xmeet( const Type *t ) const {
5769   // Perform a fast test for common case; meeting the same types together.
5770   if( this == t ) return this;  // Meeting same type-rep?
5771 
5772   // Current "this->_base" is Pointer
5773   switch (t->base()) {          // switch on original type
5774 
5775   case Int:                     // Mixing ints & oops happens when javac
5776   case Long:                    // reuses local variables
5777   case FloatTop:
5778   case FloatCon:
5779   case FloatBot:
5780   case DoubleTop:
5781   case DoubleCon:
5782   case DoubleBot:
5783   case NarrowOop:
5784   case NarrowKlass:
5785   case Bottom:                  // Ye Olde Default
5786     return Type::BOTTOM;
5787   case Top:
5788     return this;
5789 
5790   default:                      // All else is a mistake
5791     typerr(t);
5792 
5793   case AnyPtr: {                // Meeting to AnyPtrs
5794     // Found an AnyPtr type vs self-KlassPtr type
5795     const TypePtr *tp = t->is_ptr();
5796     Offset offset = meet_offset(tp->offset());
5797     PTR ptr = meet_ptr(tp->ptr());
5798     switch (tp->ptr()) {
5799     case TopPTR:
5800       return this;
5801     case Null:
5802       if( ptr == Null ) return TypePtr::make(AnyPtr, ptr, offset, tp->speculative(), tp->inline_depth());
5803     case AnyNull:
5804       return make(ptr, klass(), offset, flatten_array());
5805     case BotPTR:
5806     case NotNull:
5807       return TypePtr::make(AnyPtr, ptr, offset, tp->speculative(), tp->inline_depth());
5808     default: typerr(t);
5809     }
5810   }
5811 
5812   case RawPtr:
5813   case MetadataPtr:
5814   case OopPtr:
5815   case AryPtr:                  // Meet with AryPtr
5816   case InstPtr:                 // Meet with InstPtr
5817       return TypePtr::BOTTOM;
5818 
5819   //
5820   //             A-top         }
5821   //           /   |   \       }  Tops
5822   //       B-top A-any C-top   }
5823   //          | /  |  \ |      }  Any-nulls
5824   //       B-any   |   C-any   }
5825   //          |    |    |
5826   //       B-con A-con C-con   } constants; not comparable across classes
5827   //          |    |    |
5828   //       B-not   |   C-not   }
5829   //          | \  |  / |      }  not-nulls
5830   //       B-bot A-not C-bot   }
5831   //           \   |   /       }  Bottoms
5832   //             A-bot         }
5833   //
5834 
5835   case InstKlassPtr: {  // Meet two KlassPtr types
5836     const TypeInstKlassPtr *tkls = t->is_instklassptr();
5837     Offset  off     = meet_offset(tkls->offset());
5838     PTR  ptr     = meet_ptr(tkls->ptr());
5839     ciKlass* tkls_klass = tkls->klass();
5840     ciKlass* this_klass  = klass();
5841     bool tkls_xk = tkls->klass_is_exact();
5842     bool this_xk  = klass_is_exact();
5843     bool tkls_flatten_array = tkls->flatten_array();
5844     bool this_flatten_array  = this->flatten_array();
5845 
5846     ciKlass* res_klass = NULL;
5847     bool res_xk = false;
5848     bool res_flatten_array = false;
5849     switch(meet_instptr(ptr, this_klass, tkls_klass, this_xk, tkls_xk, this->_ptr, tkls->_ptr,
5850                         this_flatten_array, tkls_flatten_array, res_klass, res_xk, res_flatten_array)) {
5851       case UNLOADED:
5852         ShouldNotReachHere();
5853       case SUBTYPE:
5854       case NOT_SUBTYPE:
5855       case LCA:
5856       case QUICK: {
5857         assert(res_xk == (ptr == Constant), "");
5858         const Type* res1 = make(ptr, res_klass, off, res_flatten_array);
5859         return res1;
5860       }
5861       default:
5862         ShouldNotReachHere();
5863     }
5864   } // End of case KlassPtr
5865   case AryKlassPtr: {                // All arrays inherit from Object class
5866     const TypeAryKlassPtr *tp = t->is_aryklassptr();
5867     Offset offset = meet_offset(tp->offset());
5868     PTR ptr = meet_ptr(tp->ptr());
5869 
5870     switch (ptr) {
5871     case TopPTR:
5872     case AnyNull:                // Fall 'down' to dual of object klass
5873       // For instances when a subclass meets a superclass we fall
5874       // below the centerline when the superclass is exact. We need to
5875       // do the same here.
5876       if (klass()->equals(ciEnv::current()->Object_klass()) && !klass_is_exact()) {
5877         return TypeAryKlassPtr::make(ptr, tp->elem(), tp->klass(), offset, tp->is_not_flat(), tp->is_not_null_free(), tp->null_free());
5878       } else {
5879         // cannot subclass, so the meet has to fall badly below the centerline
5880         ptr = NotNull;
5881         return make(ptr, ciEnv::current()->Object_klass(), offset, false);
5882       }
5883     case Constant:
5884     case NotNull:
5885     case BotPTR:                // Fall down to object klass
5886       // LCA is object_klass, but if we subclass from the top we can do better
5887       if( above_centerline(_ptr) ) { // if( _ptr == TopPTR || _ptr == AnyNull )
5888         // If 'this' (InstPtr) is above the centerline and it is Object class
5889         // then we can subclass in the Java class hierarchy.
5890         // For instances when a subclass meets a superclass we fall
5891         // below the centerline when the superclass is exact. We need
5892         // to do the same here.
5893         if (klass()->equals(ciEnv::current()->Object_klass())) {
5894           // that is, tp's array type is a subtype of my klass
5895           return TypeAryKlassPtr::make(ptr,
5896                                        tp->elem(), tp->klass(), offset, tp->is_not_flat(), tp->is_not_null_free(), tp->null_free());
5897         }
5898       }
5899       // The other case cannot happen, since I cannot be a subtype of an array.
5900       // The meet falls down to Object class below centerline.
5901       if( ptr == Constant )
5902          ptr = NotNull;
5903       return make(ptr, ciEnv::current()->Object_klass(), offset, false);
5904     default: typerr(t);
5905     }
5906   }
5907   case InlineType: {
5908     const TypeInlineType* tv = t->is_inlinetype();
5909     if (above_centerline(ptr())) {
5910       if (tv->inline_klass()->is_subtype_of(_klass)) {
5911         return t;
5912       } else {
5913         return TypeInstPtr::NOTNULL;
5914       }
5915     } else {
5916       PTR ptr = this->_ptr;
5917       if (ptr == Constant) {
5918         ptr = NotNull;
5919       }
5920       if (tv->inline_klass()->is_subtype_of(_klass)) {
5921         return make(ptr, _klass, Offset(0), _flatten_array);
5922       } else {
5923         return make(ptr, ciEnv::current()->Object_klass(), Offset(0));
5924       }
5925     }
5926   }
5927 
5928   } // End of switch
5929   return this;                  // Return the double constant
5930 }
5931 
5932 //------------------------------xdual------------------------------------------
5933 // Dual: compute field-by-field dual
5934 const Type    *TypeInstKlassPtr::xdual() const {
5935   return new TypeInstKlassPtr(dual_ptr(), klass(), dual_offset(), flatten_array());
5936 }
5937 
5938 const TypeAryKlassPtr *TypeAryKlassPtr::make(PTR ptr, const Type* elem, ciKlass* k, Offset offset, bool not_flat, bool not_null_free, bool null_free) {
5939   return (TypeAryKlassPtr*)(new TypeAryKlassPtr(ptr, elem, k, offset, not_flat, not_null_free, null_free))->hashcons();
5940 }
5941 
5942 const TypeAryKlassPtr *TypeAryKlassPtr::make(PTR ptr, ciKlass* klass, Offset offset, bool not_flat, bool not_null_free, bool null_free) {
5943   if (klass->is_obj_array_klass()) {
5944     // Element is an object array. Recursively call ourself.
5945     ciKlass* eklass = klass->as_obj_array_klass()->element_klass();
5946     const TypeKlassPtr *etype = TypeKlassPtr::make(eklass)->cast_to_exactness(false);
5947 
5948     // Even if MyValue is exact, [LMyValue is not exact due to [QMyValue <: [LMyValue.
5949     if (etype->klass_is_exact() && etype->isa_instklassptr() && etype->is_instklassptr()->klass()->is_inlinetype() && !null_free) {
5950       etype = TypeInstKlassPtr::make(NotNull, etype->is_instklassptr()->klass(), Offset(etype->is_instklassptr()->offset()), etype->is_instklassptr()->flatten_array());
5951     }
5952 
5953     const TypeAryKlassPtr* res = TypeAryKlassPtr::make(ptr, etype, NULL, offset, not_flat, not_null_free, null_free);
5954     assert(res->klass() == klass, "");
5955     return res;
5956   } else if (klass->is_type_array_klass()) {
5957     // Element is an typeArray
5958     const Type* etype = get_const_basic_type(klass->as_type_array_klass()->element_type());
5959     return TypeAryKlassPtr::make(ptr, etype, klass, offset, not_flat, not_null_free, null_free);
5960   } else if (klass->is_flat_array_klass()) {
5961     ciInlineKlass* vk = klass->as_array_klass()->element_klass()->as_inline_klass();
5962     return TypeAryKlassPtr::make(ptr, TypeInlineType::make(vk), klass, offset, not_flat, not_null_free, null_free);
5963   } else {
5964     ShouldNotReachHere();
5965     return NULL;
5966   }
5967 }
5968 
5969 const TypeAryKlassPtr* TypeAryKlassPtr::make(ciKlass* k, PTR ptr, Offset offset) {
5970   bool null_free = k->as_array_klass()->is_elem_null_free();
5971   bool not_null_free = ptr == Constant ? !null_free : !k->is_flat_array_klass() && (k->is_type_array_klass() || !k->as_array_klass()->element_klass()->can_be_inline_klass(false));
5972 
5973   bool not_flat = !UseFlatArray || not_null_free || (k->as_array_klass()->element_klass() != NULL &&
5974                                                      k->as_array_klass()->element_klass()->is_inlinetype() &&
5975                                                      !k->as_array_klass()->element_klass()->flatten_array());
5976 
5977   return TypeAryKlassPtr::make(ptr, k, offset, not_flat, not_null_free, null_free);
5978 }
5979 
5980 //------------------------------eq---------------------------------------------
5981 // Structural equality check for Type representations
5982 bool TypeAryKlassPtr::eq(const Type *t) const {
5983   const TypeAryKlassPtr *p = t->is_aryklassptr();
5984   return
5985     _elem == p->_elem &&  // Check array
5986     _not_flat == p->_not_flat &&
5987     _not_null_free == p->_not_null_free &&
5988     _null_free == p->_null_free &&
5989     TypeKlassPtr::eq(p);  // Check sub-parts
5990 }
5991 
5992 //------------------------------hash-------------------------------------------
5993 // Type-specific hashing function.
5994 int TypeAryKlassPtr::hash(void) const {
5995   return (intptr_t)_elem + TypeKlassPtr::hash();
5996 }
5997 
5998 //----------------------compute_klass------------------------------------------
5999 // Compute the defining klass for this class
6000 ciKlass* TypeAryPtr::compute_klass(DEBUG_ONLY(bool verify)) const {
6001   // Compute _klass based on element type.
6002   ciKlass* k_ary = NULL;

6003   const TypeAryPtr *tary;
6004   const Type* el = elem();
6005   if (el->isa_narrowoop()) {
6006     el = el->make_ptr();
6007   }
6008 
6009   // Get element klass
6010   if (el->isa_instptr()) {
6011     // Compute object array klass from element klass
6012     bool null_free = el->is_inlinetypeptr() && el->isa_instptr()->ptr() != TypePtr::TopPTR && !el->isa_instptr()->maybe_null();
6013     k_ary = ciArrayKlass::make(el->is_oopptr()->klass(), null_free);
6014   } else if (el->isa_inlinetype()) {
6015     // If element type is TypeInlineType::BOTTOM, inline_klass() will be null.
6016     if (el->inline_klass() != NULL) {
6017       k_ary = ciArrayKlass::make(el->inline_klass(), /* null_free */ true);
6018     }
6019   } else if ((tary = el->isa_aryptr()) != NULL) {
6020     // Compute array klass from element klass
6021     ciKlass* k_elem = tary->klass();
6022     // If element type is something like bottom[], k_elem will be null.
6023     if (k_elem != NULL)
6024       k_ary = ciObjArrayKlass::make(k_elem);
6025   } else if ((el->base() == Type::Top) ||
6026              (el->base() == Type::Bottom)) {
6027     // element type of Bottom occurs from meet of basic type
6028     // and object; Top occurs when doing join on Bottom.
6029     // Leave k_ary at NULL.
6030   } else {
6031     // Cannot compute array klass directly from basic type,
6032     // since subtypes of TypeInt all have basic type T_INT.
6033 #ifdef ASSERT
6034     if (verify && el->isa_int()) {
6035       // Check simple cases when verifying klass.
6036       BasicType bt = T_ILLEGAL;
6037       if (el == TypeInt::BYTE) {
6038         bt = T_BYTE;
6039       } else if (el == TypeInt::SHORT) {
6040         bt = T_SHORT;
6041       } else if (el == TypeInt::CHAR) {
6042         bt = T_CHAR;
6043       } else if (el == TypeInt::INT) {
6044         bt = T_INT;
6045       } else {
6046         return _klass; // just return specified klass
6047       }
6048       return ciTypeArrayKlass::make(bt);
6049     }
6050 #endif
6051     assert(!el->isa_int(),
6052            "integral arrays must be pre-equipped with a class");
6053     // Compute array klass directly from basic type
6054     k_ary = ciTypeArrayKlass::make(el->basic_type());
6055   }
6056   return k_ary;
6057 }
6058 
6059 //------------------------------klass------------------------------------------
6060 // Return the defining klass for this class
6061 ciKlass* TypeAryPtr::klass() const {
6062   if( _klass ) return _klass;   // Return cached value, if possible
6063 
6064   // Oops, need to compute _klass and cache it
6065   ciKlass* k_ary = compute_klass();
6066 
6067   if( this != TypeAryPtr::OOPS && this->dual() != TypeAryPtr::OOPS ) {
6068     // The _klass field acts as a cache of the underlying
6069     // ciKlass for this array type.  In order to set the field,
6070     // we need to cast away const-ness.
6071     //
6072     // IMPORTANT NOTE: we *never* set the _klass field for the
6073     // type TypeAryPtr::OOPS.  This Type is shared between all
6074     // active compilations.  However, the ciKlass which represents
6075     // this Type is *not* shared between compilations, so caching
6076     // this value would result in fetching a dangling pointer.
6077     //
6078     // Recomputing the underlying ciKlass for each request is
6079     // a bit less efficient than caching, but calls to
6080     // TypeAryPtr::OOPS->klass() are not common enough to matter.
6081     ((TypeAryPtr*)this)->_klass = k_ary;
6082     if (UseCompressedOops && k_ary != NULL && k_ary->is_obj_array_klass() &&
6083         offset() != 0 && offset() != arrayOopDesc::length_offset_in_bytes()) {
6084       ((TypeAryPtr*)this)->_is_ptr_to_narrowoop = true;
6085     }
6086   }
6087   return k_ary;
6088 }
6089 
6090 
6091 //------------------------------add_offset-------------------------------------
6092 // Access internals of klass object
6093 const TypePtr *TypeAryKlassPtr::add_offset(intptr_t offset) const {
6094   return make(_ptr, elem(), klass(), xadd_offset(offset), is_not_flat(), is_not_null_free(), _null_free);
6095 }
6096 
6097 const TypeKlassPtr *TypeAryKlassPtr::with_offset(intptr_t offset) const {
6098   return make(_ptr, elem(), klass(), Offset(offset), is_not_flat(), is_not_null_free(), _null_free);
6099 }
6100 
6101 //------------------------------cast_to_ptr_type-------------------------------
6102 const TypePtr* TypeAryKlassPtr::cast_to_ptr_type(PTR ptr) const {
6103   assert(_base == AryKlassPtr, "subclass must override cast_to_ptr_type");
6104   if (ptr == _ptr) return this;
6105   return make(ptr, elem(), _klass, _offset, is_not_flat(), is_not_null_free(), _null_free);
6106 }
6107 
6108 bool TypeAryKlassPtr::must_be_exact() const {
6109   if (_elem == Type::BOTTOM) return false;
6110   if (_elem == Type::TOP   ) return false;
6111   const TypeKlassPtr*  tk = _elem->isa_klassptr();
6112   if (!tk)             return true;   // a primitive type, like int
6113   return tk->must_be_exact();
6114 }
6115 
6116 
6117 //-----------------------------cast_to_exactness-------------------------------
6118 const TypeKlassPtr *TypeAryKlassPtr::cast_to_exactness(bool klass_is_exact) const {
6119   if (must_be_exact() && !klass_is_exact) return this;  // cannot clear xk
6120   ciKlass* k = _klass;
6121   const Type* elem = this->elem();
6122   if (elem->isa_klassptr() && !klass_is_exact) {
6123     elem = elem->is_klassptr()->cast_to_exactness(klass_is_exact);
6124   }
6125   bool not_flat = is_not_flat();
6126   bool not_null_free = is_not_null_free();
6127   if (klass() != NULL && klass()->is_obj_array_klass() && klass_is_exact) {
6128     // An object array can't be flat or null-free if the klass is exact
6129     not_flat = true;
6130     not_null_free = true;
6131   }
6132   return make(klass_is_exact ? Constant : NotNull, elem, k, _offset, not_flat, not_null_free, _null_free);
6133 }
6134 
6135 
6136 //-----------------------------as_instance_type--------------------------------
6137 // Corresponding type for an instance of the given class.
6138 // It will be exact if and only if the klass type is exact.
6139 const TypeOopPtr* TypeAryKlassPtr::as_instance_type() const {
6140   ciKlass* k = klass();
6141   assert(k != NULL, "klass should not be NULL");
6142   bool    xk = klass_is_exact();
6143   const Type* el = elem()->isa_klassptr() ? elem()->is_klassptr()->as_instance_type()->is_oopptr()->cast_to_exactness(false) : elem();
6144   bool null_free = _null_free;
6145   if (null_free && el->isa_ptr()) {
6146     el = el->is_ptr()->join_speculative(TypePtr::NOTNULL);
6147   }
6148   bool not_flat = is_not_flat();
6149   bool not_null_free = is_not_null_free();
6150   return TypeAryPtr::make(TypePtr::BotPTR, TypeAry::make(el, TypeInt::POS, false, not_flat, not_null_free), k, xk, Offset(0));
6151 }
6152 
6153 
6154 //------------------------------xmeet------------------------------------------
6155 // Compute the MEET of two types, return a new Type object.
6156 const Type    *TypeAryKlassPtr::xmeet( const Type *t ) const {
6157   // Perform a fast test for common case; meeting the same types together.
6158   if( this == t ) return this;  // Meeting same type-rep?
6159 
6160   // Current "this->_base" is Pointer
6161   switch (t->base()) {          // switch on original type
6162 
6163   case Int:                     // Mixing ints & oops happens when javac
6164   case Long:                    // reuses local variables
6165   case FloatTop:
6166   case FloatCon:
6167   case FloatBot:
6168   case DoubleTop:
6169   case DoubleCon:
6170   case DoubleBot:
6171   case NarrowOop:
6172   case NarrowKlass:
6173   case Bottom:                  // Ye Olde Default
6174     return Type::BOTTOM;
6175   case Top:
6176     return this;
6177 
6178   default:                      // All else is a mistake
6179     typerr(t);
6180 
6181   case AnyPtr: {                // Meeting to AnyPtrs
6182     // Found an AnyPtr type vs self-KlassPtr type
6183     const TypePtr *tp = t->is_ptr();
6184     Offset offset = meet_offset(tp->offset());
6185     PTR ptr = meet_ptr(tp->ptr());
6186     switch (tp->ptr()) {
6187     case TopPTR:
6188       return this;
6189     case Null:
6190       if( ptr == Null ) return TypePtr::make(AnyPtr, ptr, offset, tp->speculative(), tp->inline_depth());
6191     case AnyNull:
6192       return make(ptr, _elem, klass(), offset, is_not_flat(), is_not_null_free(), _null_free);
6193     case BotPTR:
6194     case NotNull:
6195       return TypePtr::make(AnyPtr, ptr, offset, tp->speculative(), tp->inline_depth());
6196     default: typerr(t);
6197     }
6198   }
6199 
6200   case RawPtr:
6201   case MetadataPtr:
6202   case OopPtr:
6203   case AryPtr:                  // Meet with AryPtr
6204   case InstPtr:                 // Meet with InstPtr
6205     return TypePtr::BOTTOM;
6206 
6207   //
6208   //             A-top         }
6209   //           /   |   \       }  Tops
6210   //       B-top A-any C-top   }
6211   //          | /  |  \ |      }  Any-nulls
6212   //       B-any   |   C-any   }
6213   //          |    |    |
6214   //       B-con A-con C-con   } constants; not comparable across classes
6215   //          |    |    |
6216   //       B-not   |   C-not   }
6217   //          | \  |  / |      }  not-nulls
6218   //       B-bot A-not C-bot   }
6219   //           \   |   /       }  Bottoms
6220   //             A-bot         }
6221   //
6222 
6223   case AryKlassPtr: {  // Meet two KlassPtr types
6224     const TypeAryKlassPtr *tap = t->is_aryklassptr();
6225     Offset off = meet_offset(tap->offset());
6226     const Type* res_elem = NULL;

6227     PTR ptr = meet_ptr(tap->ptr());
6228     ciKlass* res_klass = NULL;
6229     bool res_xk = false;
6230     bool res_not_flat = false;
6231     bool res_not_null_free = false;
6232     MeetResult res = meet_aryptr(ptr, _elem, tap->_elem, this->klass(), tap->klass(),
6233                                  this->klass_is_exact(), tap->klass_is_exact(),
6234                                  this->ptr(), tap->ptr(), this->is_not_flat(), tap->is_not_flat(),
6235                                  this->is_not_null_free(), tap->is_not_null_free(),
6236                                  res_elem, res_klass, res_xk, res_not_flat, res_not_null_free);
6237     assert(res_xk == (ptr == Constant), "");
6238     bool null_free = meet_null_free(tap->_null_free);
6239     if (res == NOT_SUBTYPE) {
6240       null_free = false;
6241     } else if (res == SUBTYPE) {
6242       if (above_centerline(tap->ptr()) && !above_centerline(this->ptr())) {
6243         null_free = _null_free;
6244       } else if (above_centerline(this->ptr()) && !above_centerline(tap->ptr())) {
6245         null_free = tap->_null_free;
6246       }
6247     }
6248     return make(ptr, res_elem, res_klass, off, res_not_flat, res_not_null_free, null_free);
6249   } // End of case KlassPtr
6250   case InstKlassPtr: {
6251     const TypeInstKlassPtr *tp = t->is_instklassptr();
6252     Offset offset = meet_offset(tp->offset());
6253     PTR ptr = meet_ptr(tp->ptr());
6254 
6255     switch (ptr) {
6256     case TopPTR:
6257     case AnyNull:                // Fall 'down' to dual of object klass
6258       // For instances when a subclass meets a superclass we fall
6259       // below the centerline when the superclass is exact. We need to
6260       // do the same here.
6261       if (tp->klass()->equals(ciEnv::current()->Object_klass()) && !tp->klass_is_exact()) {
6262         return TypeAryKlassPtr::make(ptr, _elem, _klass, offset, is_not_flat(), is_not_null_free(), _null_free);
6263       } else {
6264         // cannot subclass, so the meet has to fall badly below the centerline
6265         ptr = NotNull;
6266         return TypeInstKlassPtr::make(ptr, ciEnv::current()->Object_klass(), offset, false);
6267       }
6268     case Constant:
6269     case NotNull:
6270     case BotPTR:                // Fall down to object klass
6271       // LCA is object_klass, but if we subclass from the top we can do better
6272       if (above_centerline(tp->ptr())) {
6273         // If 'tp'  is above the centerline and it is Object class
6274         // then we can subclass in the Java class hierarchy.
6275         // For instances when a subclass meets a superclass we fall
6276         // below the centerline when the superclass is exact. We need
6277         // to do the same here.
6278         if (tp->klass()->equals(ciEnv::current()->Object_klass()) && !tp->klass_is_exact()) {
6279           // that is, my array type is a subtype of 'tp' klass
6280           return make(ptr, _elem, _klass, offset, is_not_flat(), is_not_null_free(), _null_free);
6281         }
6282       }
6283       // The other case cannot happen, since t cannot be a subtype of an array.
6284       // The meet falls down to Object class below centerline.
6285       if (ptr == Constant)
6286          ptr = NotNull;
6287       return TypeInstKlassPtr::make(ptr, ciEnv::current()->Object_klass(), offset, false);
6288     default: typerr(t);
6289     }
6290   }
6291   case InlineType: {
6292     const TypeInlineType* tv = t->is_inlinetype();
6293     if (above_centerline(ptr())) {
6294       return TypeInstKlassPtr::BOTTOM;
6295     } else {
6296       PTR ptr = this->_ptr;
6297       if (ptr == Constant) {
6298         ptr = NotNull;
6299       }
6300       return TypeInstKlassPtr::make(ptr, ciEnv::current()->Object_klass(), Offset(0));
6301     }
6302   }
6303 
6304   } // End of switch
6305   return this;                  // Return the double constant
6306 }
6307 
6308 //------------------------------xdual------------------------------------------
6309 // Dual: compute field-by-field dual
6310 const Type    *TypeAryKlassPtr::xdual() const {
6311   return new TypeAryKlassPtr(dual_ptr(), elem()->dual(), klass(), dual_offset(), !is_not_flat(), !is_not_null_free(), dual_null_free());
6312 }
6313 
6314 //------------------------------get_con----------------------------------------
6315 ciKlass* TypeAryKlassPtr::klass() const {
6316     if (_klass != NULL) {
6317     return _klass;
6318   }
6319   ciKlass* k = NULL;
6320   const Type* el = elem();
6321   if (el->isa_instklassptr()) {
6322     // Compute object array klass from element klass
6323     bool null_free = el->is_instklassptr()->klass()->is_inlinetype() && el->isa_instklassptr()->ptr() != TypePtr::TopPTR && (_null_free != 0);
6324     k = ciArrayKlass::make(el->is_klassptr()->klass(), null_free);
6325     ((TypeAryKlassPtr*)this)->_klass = k;
6326   } else if (el->isa_inlinetype()) {
6327     // If element type is TypeInlineType::BOTTOM, inline_klass() will be null.
6328     if (el->inline_klass() != NULL) {
6329       k = ciArrayKlass::make(el->inline_klass(), /* null_free */ true);
6330       ((TypeAryKlassPtr*)this)->_klass = k;
6331     }
6332   } else if (el->isa_aryklassptr() != NULL) {
6333     // Compute array klass from element klass
6334     ciKlass* k_elem = el->is_aryklassptr()->klass();
6335     // If element type is something like bottom[], k_elem will be null.
6336     if (k_elem != NULL) {
6337       k = ciObjArrayKlass::make(k_elem);
6338       ((TypeAryKlassPtr*)this)->_klass = k;
6339     }
6340   } else if ((elem()->base() == Type::Top) ||
6341              (elem()->base() == Type::Bottom)) {
6342   } else {
6343     k = ciTypeArrayKlass::make(elem()->basic_type());
6344   }
6345   return k;
6346 }
6347 
6348 //------------------------------dump2------------------------------------------
6349 // Dump Klass Type
6350 #ifndef PRODUCT
6351 void TypeAryKlassPtr::dump2( Dict & d, uint depth, outputStream *st ) const {
6352   switch( _ptr ) {
6353   case Constant:
6354     st->print("precise ");
6355   case NotNull:
6356     {
6357       st->print("[");
6358       if (_elem->isa_inlinetype()) {
6359         const char *name = _elem->is_inlinetype()->inline_klass()->name()->as_utf8();
6360         st->print("precise %s: " INTPTR_FORMAT " ", name, p2i(klass()));
6361       }
6362       _elem->dump2(d, depth, st);
6363       st->print(": ");
6364     }
6365   case BotPTR:
6366     if( !WizardMode && !Verbose && _ptr != Constant ) break;
6367   case TopPTR:
6368   case AnyNull:
6369     st->print(":%s", ptr_msg[_ptr]);
6370     if( _ptr == Constant ) st->print(":exact");
6371     break;
6372   default:
6373     break;
6374   }
6375   if (Verbose) {
6376     if (_not_flat) st->print(":not flat");
6377     if (_not_null_free) st->print(":not null free");
6378     if (_null_free != 0) st->print(":null free(%d)", _null_free);

6379   }
6380 
6381   _offset.dump2(st);
6382 
6383   st->print(" *");
6384 }
6385 #endif
6386 
6387 const Type* TypeAryKlassPtr::base_element_type(int& dims) const {
6388   const Type* elem = this->elem();
6389   dims = 1;
6390   while (elem->isa_aryklassptr()) {
6391     elem = elem->is_aryklassptr()->elem();
6392     dims++;
6393   }
6394   return elem;
6395 }
6396 
6397 //=============================================================================
6398 // Convenience common pre-built types.
6399 
6400 //------------------------------make-------------------------------------------
6401 const TypeFunc *TypeFunc::make(const TypeTuple *domain_sig, const TypeTuple* domain_cc,
6402                                const TypeTuple *range_sig, const TypeTuple *range_cc) {
6403   return (TypeFunc*)(new TypeFunc(domain_sig, domain_cc, range_sig, range_cc))->hashcons();
6404 }
6405 
6406 const TypeFunc *TypeFunc::make(const TypeTuple *domain, const TypeTuple *range) {
6407   return make(domain, domain, range, range);
6408 }
6409 
6410 //------------------------------osr_domain-----------------------------
6411 const TypeTuple* osr_domain() {
6412   const Type **fields = TypeTuple::fields(2);
6413   fields[TypeFunc::Parms+0] = TypeRawPtr::BOTTOM;  // address of osr buffer
6414   return TypeTuple::make(TypeFunc::Parms+1, fields);
6415 }
6416 
6417 //------------------------------make-------------------------------------------
6418 const TypeFunc* TypeFunc::make(ciMethod* method, bool is_osr_compilation) {
6419   Compile* C = Compile::current();
6420   const TypeFunc* tf = NULL;
6421   if (!is_osr_compilation) {
6422     tf = C->last_tf(method); // check cache
6423     if (tf != NULL)  return tf;  // The hit rate here is almost 50%.
6424   }
6425   // Inline types are not passed/returned by reference, instead each field of
6426   // the inline type is passed/returned as an argument. We maintain two views of
6427   // the argument/return list here: one based on the signature (with an inline
6428   // type argument/return as a single slot), one based on the actual calling
6429   // convention (with an inline type argument/return as a list of its fields).
6430   bool has_scalar_args = method->has_scalarized_args() && !is_osr_compilation;
6431   const TypeTuple* domain_sig = is_osr_compilation ? osr_domain() : TypeTuple::make_domain(method, false);
6432   const TypeTuple* domain_cc = has_scalar_args ? TypeTuple::make_domain(method, true) : domain_sig;
6433   ciSignature* sig = method->signature();
6434   bool has_scalar_ret = sig->returns_null_free_inline_type() && sig->return_type()->as_inline_klass()->can_be_returned_as_fields();
6435   const TypeTuple* range_sig = TypeTuple::make_range(sig, false);
6436   const TypeTuple* range_cc = has_scalar_ret ? TypeTuple::make_range(sig, true) : range_sig;
6437   tf = TypeFunc::make(domain_sig, domain_cc, range_sig, range_cc);
6438   if (!is_osr_compilation) {
6439     C->set_last_tf(method, tf);  // fill cache
6440   }



6441   return tf;
6442 }
6443 
6444 //------------------------------meet-------------------------------------------
6445 // Compute the MEET of two types.  It returns a new Type object.
6446 const Type *TypeFunc::xmeet( const Type *t ) const {
6447   // Perform a fast test for common case; meeting the same types together.
6448   if( this == t ) return this;  // Meeting same type-rep?
6449 
6450   // Current "this->_base" is Func
6451   switch (t->base()) {          // switch on original type
6452 
6453   case Bottom:                  // Ye Olde Default
6454     return t;
6455 
6456   default:                      // All else is a mistake
6457     typerr(t);
6458 
6459   case Top:
6460     break;
6461   }
6462   return this;                  // Return the double constant
6463 }
6464 
6465 //------------------------------xdual------------------------------------------
6466 // Dual: compute field-by-field dual
6467 const Type *TypeFunc::xdual() const {
6468   return this;
6469 }
6470 
6471 //------------------------------eq---------------------------------------------
6472 // Structural equality check for Type representations
6473 bool TypeFunc::eq( const Type *t ) const {
6474   const TypeFunc *a = (const TypeFunc*)t;
6475   return _domain_sig == a->_domain_sig &&
6476     _domain_cc == a->_domain_cc &&
6477     _range_sig == a->_range_sig &&
6478     _range_cc == a->_range_cc;
6479 }
6480 
6481 //------------------------------hash-------------------------------------------
6482 // Type-specific hashing function.
6483 int TypeFunc::hash(void) const {
6484   return (intptr_t)_domain_sig + (intptr_t)_domain_cc + (intptr_t)_range_sig + (intptr_t)_range_cc;
6485 }
6486 
6487 //------------------------------dump2------------------------------------------
6488 // Dump Function Type
6489 #ifndef PRODUCT
6490 void TypeFunc::dump2( Dict &d, uint depth, outputStream *st ) const {
6491   if( _range_sig->cnt() <= Parms )
6492     st->print("void");
6493   else {
6494     uint i;
6495     for (i = Parms; i < _range_sig->cnt()-1; i++) {
6496       _range_sig->field_at(i)->dump2(d,depth,st);
6497       st->print("/");
6498     }
6499     _range_sig->field_at(i)->dump2(d,depth,st);
6500   }
6501   st->print(" ");
6502   st->print("( ");
6503   if( !depth || d[this] ) {     // Check for recursive dump
6504     st->print("...)");
6505     return;
6506   }
6507   d.Insert((void*)this,(void*)this);    // Stop recursion
6508   if (Parms < _domain_sig->cnt())
6509     _domain_sig->field_at(Parms)->dump2(d,depth-1,st);
6510   for (uint i = Parms+1; i < _domain_sig->cnt(); i++) {
6511     st->print(", ");
6512     _domain_sig->field_at(i)->dump2(d,depth-1,st);
6513   }
6514   st->print(" )");
6515 }
6516 #endif
6517 
6518 //------------------------------singleton--------------------------------------
6519 // TRUE if Type is a singleton type, FALSE otherwise.   Singletons are simple
6520 // constants (Ldi nodes).  Singletons are integer, float or double constants
6521 // or a single symbol.
6522 bool TypeFunc::singleton(void) const {
6523   return false;                 // Never a singleton
6524 }
6525 
6526 bool TypeFunc::empty(void) const {
6527   return false;                 // Never empty
6528 }
6529 
6530 
6531 BasicType TypeFunc::return_type() const{
6532   if (range_sig()->cnt() == TypeFunc::Parms) {
6533     return T_VOID;
6534   }
6535   return range_sig()->field_at(TypeFunc::Parms)->basic_type();
6536 }
--- EOF ---