1 /*
   2  * Copyright (c) 1997, 2022, 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_PRIMITIVE_OBJECT, "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_PRIMITIVE_OBJECT: {
 273     ciInlineKlass* vk = type->unwrap()->as_inline_klass();
 274     return TypeOopPtr::make_from_klass(vk)->join_speculative(type->is_null_free() ? TypePtr::NOTNULL : TypePtr::BOTTOM);
 275   }
 276 
 277   default:
 278     // make sure we did not mix up the cases:
 279     assert(type != ciTypeFlow::StateVector::bottom_type(), "");
 280     assert(type != ciTypeFlow::StateVector::top_type(), "");
 281     assert(type != ciTypeFlow::StateVector::null_type(), "");
 282     assert(type != ciTypeFlow::StateVector::long2_type(), "");
 283     assert(type != ciTypeFlow::StateVector::double2_type(), "");
 284     assert(!type->is_return_address(), "");
 285 
 286     return Type::get_const_type(type);
 287   }
 288 }
 289 
 290 
 291 //-----------------------make_from_constant------------------------------------
 292 const Type* Type::make_from_constant(ciConstant constant, bool require_constant,
 293                                      int stable_dimension, bool is_narrow_oop,
 294                                      bool is_autobox_cache) {
 295   switch (constant.basic_type()) {
 296     case T_BOOLEAN:  return TypeInt::make(constant.as_boolean());
 297     case T_CHAR:     return TypeInt::make(constant.as_char());
 298     case T_BYTE:     return TypeInt::make(constant.as_byte());
 299     case T_SHORT:    return TypeInt::make(constant.as_short());
 300     case T_INT:      return TypeInt::make(constant.as_int());
 301     case T_LONG:     return TypeLong::make(constant.as_long());
 302     case T_FLOAT:    return TypeF::make(constant.as_float());
 303     case T_DOUBLE:   return TypeD::make(constant.as_double());
 304     case T_ARRAY:
 305     case T_PRIMITIVE_OBJECT:
 306     case T_OBJECT: {
 307         const Type* con_type = NULL;
 308         ciObject* oop_constant = constant.as_object();
 309         if (oop_constant->is_null_object()) {
 310           con_type = Type::get_zero_type(T_OBJECT);
 311         } else {
 312           guarantee(require_constant || oop_constant->should_be_constant(), "con_type must get computed");
 313           con_type = TypeOopPtr::make_from_constant(oop_constant, require_constant);
 314           if (Compile::current()->eliminate_boxing() && is_autobox_cache) {
 315             con_type = con_type->is_aryptr()->cast_to_autobox_cache();
 316           }
 317           if (stable_dimension > 0) {
 318             assert(FoldStableValues, "sanity");
 319             assert(!con_type->is_zero_type(), "default value for stable field");
 320             con_type = con_type->is_aryptr()->cast_to_stable(true, stable_dimension);
 321           }
 322         }
 323         if (is_narrow_oop) {
 324           con_type = con_type->make_narrowoop();
 325         }
 326         return con_type;
 327       }
 328     case T_ILLEGAL:
 329       // Invalid ciConstant returned due to OutOfMemoryError in the CI
 330       assert(Compile::current()->env()->failing(), "otherwise should not see this");
 331       return NULL;
 332     default:
 333       // Fall through to failure
 334       return NULL;
 335   }
 336 }
 337 
 338 static ciConstant check_mismatched_access(ciConstant con, BasicType loadbt, bool is_unsigned) {
 339   BasicType conbt = con.basic_type();
 340   switch (conbt) {
 341     case T_BOOLEAN: conbt = T_BYTE;   break;
 342     case T_ARRAY:   conbt = T_OBJECT; break;
 343     case T_PRIMITIVE_OBJECT: conbt = T_OBJECT; break;
 344     default:                          break;
 345   }
 346   switch (loadbt) {
 347     case T_BOOLEAN:   loadbt = T_BYTE;   break;
 348     case T_NARROWOOP: loadbt = T_OBJECT; break;
 349     case T_ARRAY:     loadbt = T_OBJECT; break;
 350     case T_PRIMITIVE_OBJECT: loadbt = T_OBJECT; break;
 351     case T_ADDRESS:   loadbt = T_OBJECT; break;
 352     default:                             break;
 353   }
 354   if (conbt == loadbt) {
 355     if (is_unsigned && conbt == T_BYTE) {
 356       // LoadB (T_BYTE) with a small mask (<=8-bit) is converted to LoadUB (T_BYTE).
 357       return ciConstant(T_INT, con.as_int() & 0xFF);
 358     } else {
 359       return con;
 360     }
 361   }
 362   if (conbt == T_SHORT && loadbt == T_CHAR) {
 363     // LoadS (T_SHORT) with a small mask (<=16-bit) is converted to LoadUS (T_CHAR).
 364     return ciConstant(T_INT, con.as_int() & 0xFFFF);
 365   }
 366   return ciConstant(); // T_ILLEGAL
 367 }
 368 
 369 // Try to constant-fold a stable array element.
 370 const Type* Type::make_constant_from_array_element(ciArray* array, int off, int stable_dimension,
 371                                                    BasicType loadbt, bool is_unsigned_load) {
 372   // Decode the results of GraphKit::array_element_address.
 373   ciConstant element_value = array->element_value_by_offset(off);
 374   if (element_value.basic_type() == T_ILLEGAL) {
 375     return NULL; // wrong offset
 376   }
 377   ciConstant con = check_mismatched_access(element_value, loadbt, is_unsigned_load);
 378 
 379   assert(con.basic_type() != T_ILLEGAL, "elembt=%s; loadbt=%s; unsigned=%d",
 380          type2name(element_value.basic_type()), type2name(loadbt), is_unsigned_load);
 381 
 382   if (con.is_valid() &&          // not a mismatched access
 383       !con.is_null_or_zero()) {  // not a default value
 384     bool is_narrow_oop = (loadbt == T_NARROWOOP);
 385     return Type::make_from_constant(con, /*require_constant=*/true, stable_dimension, is_narrow_oop, /*is_autobox_cache=*/false);
 386   }
 387   return NULL;
 388 }
 389 
 390 const Type* Type::make_constant_from_field(ciInstance* holder, int off, bool is_unsigned_load, BasicType loadbt) {
 391   ciField* field;
 392   ciType* type = holder->java_mirror_type();
 393   if (type != NULL && type->is_instance_klass() && off >= InstanceMirrorKlass::offset_of_static_fields()) {
 394     // Static field
 395     field = type->as_instance_klass()->get_field_by_offset(off, /*is_static=*/true);
 396   } else {
 397     // Instance field
 398     field = holder->klass()->as_instance_klass()->get_field_by_offset(off, /*is_static=*/false);
 399   }
 400   if (field == NULL) {
 401     return NULL; // Wrong offset
 402   }
 403   return Type::make_constant_from_field(field, holder, loadbt, is_unsigned_load);
 404 }
 405 
 406 const Type* Type::make_constant_from_field(ciField* field, ciInstance* holder,
 407                                            BasicType loadbt, bool is_unsigned_load) {
 408   if (!field->is_constant()) {
 409     return NULL; // Non-constant field
 410   }
 411   ciConstant field_value;
 412   if (field->is_static()) {
 413     // final static field
 414     field_value = field->constant_value();
 415   } else if (holder != NULL) {
 416     // final or stable non-static field
 417     // Treat final non-static fields of trusted classes (classes in
 418     // java.lang.invoke and sun.invoke packages and subpackages) as
 419     // compile time constants.
 420     field_value = field->constant_value_of(holder);
 421   }
 422   if (!field_value.is_valid()) {
 423     return NULL; // Not a constant
 424   }
 425 
 426   ciConstant con = check_mismatched_access(field_value, loadbt, is_unsigned_load);
 427 
 428   assert(con.is_valid(), "elembt=%s; loadbt=%s; unsigned=%d",
 429          type2name(field_value.basic_type()), type2name(loadbt), is_unsigned_load);
 430 
 431   bool is_stable_array = FoldStableValues && field->is_stable() && field->type()->is_array_klass();
 432   int stable_dimension = (is_stable_array ? field->type()->as_array_klass()->dimension() : 0);
 433   bool is_narrow_oop = (loadbt == T_NARROWOOP);
 434 
 435   const Type* con_type = make_from_constant(con, /*require_constant=*/ true,
 436                                             stable_dimension, is_narrow_oop,
 437                                             field->is_autobox_cache());
 438   if (con_type != NULL && field->is_call_site_target()) {
 439     ciCallSite* call_site = holder->as_call_site();
 440     if (!call_site->is_fully_initialized_constant_call_site()) {
 441       ciMethodHandle* target = con.as_object()->as_method_handle();
 442       Compile::current()->dependencies()->assert_call_site_target_value(call_site, target);
 443     }
 444   }
 445   return con_type;
 446 }
 447 
 448 //------------------------------make-------------------------------------------
 449 // Create a simple Type, with default empty symbol sets.  Then hashcons it
 450 // and look for an existing copy in the type dictionary.
 451 const Type *Type::make( enum TYPES t ) {
 452   return (new Type(t))->hashcons();
 453 }
 454 
 455 //------------------------------cmp--------------------------------------------
 456 int Type::cmp( const Type *const t1, const Type *const t2 ) {
 457   if( t1->_base != t2->_base )
 458     return 1;                   // Missed badly
 459   assert(t1 != t2 || t1->eq(t2), "eq must be reflexive");
 460   return !t1->eq(t2);           // Return ZERO if equal
 461 }
 462 
 463 const Type* Type::maybe_remove_speculative(bool include_speculative) const {
 464   if (!include_speculative) {
 465     return remove_speculative();
 466   }
 467   return this;
 468 }
 469 
 470 //------------------------------hash-------------------------------------------
 471 int Type::uhash( const Type *const t ) {
 472   return t->hash();
 473 }
 474 
 475 #define SMALLINT ((juint)3)  // a value too insignificant to consider widening
 476 #define POSITIVE_INFINITE_F 0x7f800000 // hex representation for IEEE 754 single precision positive infinite
 477 #define POSITIVE_INFINITE_D 0x7ff0000000000000 // hex representation for IEEE 754 double precision positive infinite
 478 
 479 //--------------------------Initialize_shared----------------------------------
 480 void Type::Initialize_shared(Compile* current) {
 481   // This method does not need to be locked because the first system
 482   // compilations (stub compilations) occur serially.  If they are
 483   // changed to proceed in parallel, then this section will need
 484   // locking.
 485 
 486   Arena* save = current->type_arena();
 487   Arena* shared_type_arena = new (mtCompiler)Arena(mtCompiler);
 488 
 489   current->set_type_arena(shared_type_arena);
 490   _shared_type_dict =
 491     new (shared_type_arena) Dict( (CmpKey)Type::cmp, (Hash)Type::uhash,
 492                                   shared_type_arena, 128 );
 493   current->set_type_dict(_shared_type_dict);
 494 
 495   // Make shared pre-built types.
 496   CONTROL = make(Control);      // Control only
 497   TOP     = make(Top);          // No values in set
 498   MEMORY  = make(Memory);       // Abstract store only
 499   ABIO    = make(Abio);         // State-of-machine only
 500   RETURN_ADDRESS=make(Return_Address);
 501   FLOAT   = make(FloatBot);     // All floats
 502   DOUBLE  = make(DoubleBot);    // All doubles
 503   BOTTOM  = make(Bottom);       // Everything
 504   HALF    = make(Half);         // Placeholder half of doublewide type
 505 
 506   TypeF::MAX = TypeF::make(max_jfloat); // Float MAX
 507   TypeF::MIN = TypeF::make(min_jfloat); // Float MIN
 508   TypeF::ZERO = TypeF::make(0.0); // Float 0 (positive zero)
 509   TypeF::ONE  = TypeF::make(1.0); // Float 1
 510   TypeF::POS_INF = TypeF::make(jfloat_cast(POSITIVE_INFINITE_F));
 511   TypeF::NEG_INF = TypeF::make(-jfloat_cast(POSITIVE_INFINITE_F));
 512 
 513   TypeD::MAX = TypeD::make(max_jdouble); // Double MAX
 514   TypeD::MIN = TypeD::make(min_jdouble); // Double MIN
 515   TypeD::ZERO = TypeD::make(0.0); // Double 0 (positive zero)
 516   TypeD::ONE  = TypeD::make(1.0); // Double 1
 517   TypeD::POS_INF = TypeD::make(jdouble_cast(POSITIVE_INFINITE_D));
 518   TypeD::NEG_INF = TypeD::make(-jdouble_cast(POSITIVE_INFINITE_D));
 519 
 520   TypeInt::MAX = TypeInt::make(max_jint); // Int MAX
 521   TypeInt::MIN = TypeInt::make(min_jint); // Int MIN
 522   TypeInt::MINUS_1 = TypeInt::make(-1);  // -1
 523   TypeInt::ZERO    = TypeInt::make( 0);  //  0
 524   TypeInt::ONE     = TypeInt::make( 1);  //  1
 525   TypeInt::BOOL    = TypeInt::make(0,1,   WidenMin);  // 0 or 1, FALSE or TRUE.
 526   TypeInt::CC      = TypeInt::make(-1, 1, WidenMin);  // -1, 0 or 1, condition codes
 527   TypeInt::CC_LT   = TypeInt::make(-1,-1, WidenMin);  // == TypeInt::MINUS_1
 528   TypeInt::CC_GT   = TypeInt::make( 1, 1, WidenMin);  // == TypeInt::ONE
 529   TypeInt::CC_EQ   = TypeInt::make( 0, 0, WidenMin);  // == TypeInt::ZERO
 530   TypeInt::CC_LE   = TypeInt::make(-1, 0, WidenMin);
 531   TypeInt::CC_GE   = TypeInt::make( 0, 1, WidenMin);  // == TypeInt::BOOL
 532   TypeInt::BYTE    = TypeInt::make(-128,127,     WidenMin); // Bytes
 533   TypeInt::UBYTE   = TypeInt::make(0, 255,       WidenMin); // Unsigned Bytes
 534   TypeInt::CHAR    = TypeInt::make(0,65535,      WidenMin); // Java chars
 535   TypeInt::SHORT   = TypeInt::make(-32768,32767, WidenMin); // Java shorts
 536   TypeInt::POS     = TypeInt::make(0,max_jint,   WidenMin); // Non-neg values
 537   TypeInt::POS1    = TypeInt::make(1,max_jint,   WidenMin); // Positive values
 538   TypeInt::INT     = TypeInt::make(min_jint,max_jint, WidenMax); // 32-bit integers
 539   TypeInt::SYMINT  = TypeInt::make(-max_jint,max_jint,WidenMin); // symmetric range
 540   TypeInt::TYPE_DOMAIN  = TypeInt::INT;
 541   // CmpL is overloaded both as the bytecode computation returning
 542   // a trinary (-1,0,+1) integer result AND as an efficient long
 543   // compare returning optimizer ideal-type flags.
 544   assert( TypeInt::CC_LT == TypeInt::MINUS_1, "types must match for CmpL to work" );
 545   assert( TypeInt::CC_GT == TypeInt::ONE,     "types must match for CmpL to work" );
 546   assert( TypeInt::CC_EQ == TypeInt::ZERO,    "types must match for CmpL to work" );
 547   assert( TypeInt::CC_GE == TypeInt::BOOL,    "types must match for CmpL to work" );
 548   assert( (juint)(TypeInt::CC->_hi - TypeInt::CC->_lo) <= SMALLINT, "CC is truly small");
 549 
 550   TypeLong::MAX = TypeLong::make(max_jlong);  // Long MAX
 551   TypeLong::MIN = TypeLong::make(min_jlong);  // Long MIN
 552   TypeLong::MINUS_1 = TypeLong::make(-1);        // -1
 553   TypeLong::ZERO    = TypeLong::make( 0);        //  0
 554   TypeLong::ONE     = TypeLong::make( 1);        //  1
 555   TypeLong::POS     = TypeLong::make(0,max_jlong, WidenMin); // Non-neg values
 556   TypeLong::LONG    = TypeLong::make(min_jlong,max_jlong,WidenMax); // 64-bit integers
 557   TypeLong::INT     = TypeLong::make((jlong)min_jint,(jlong)max_jint,WidenMin);
 558   TypeLong::UINT    = TypeLong::make(0,(jlong)max_juint,WidenMin);
 559   TypeLong::TYPE_DOMAIN  = TypeLong::LONG;
 560 
 561   const Type **fboth =(const Type**)shared_type_arena->AmallocWords(2*sizeof(Type*));
 562   fboth[0] = Type::CONTROL;
 563   fboth[1] = Type::CONTROL;
 564   TypeTuple::IFBOTH = TypeTuple::make( 2, fboth );
 565 
 566   const Type **ffalse =(const Type**)shared_type_arena->AmallocWords(2*sizeof(Type*));
 567   ffalse[0] = Type::CONTROL;
 568   ffalse[1] = Type::TOP;
 569   TypeTuple::IFFALSE = TypeTuple::make( 2, ffalse );
 570 
 571   const Type **fneither =(const Type**)shared_type_arena->AmallocWords(2*sizeof(Type*));
 572   fneither[0] = Type::TOP;
 573   fneither[1] = Type::TOP;
 574   TypeTuple::IFNEITHER = TypeTuple::make( 2, fneither );
 575 
 576   const Type **ftrue =(const Type**)shared_type_arena->AmallocWords(2*sizeof(Type*));
 577   ftrue[0] = Type::TOP;
 578   ftrue[1] = Type::CONTROL;
 579   TypeTuple::IFTRUE = TypeTuple::make( 2, ftrue );
 580 
 581   const Type **floop =(const Type**)shared_type_arena->AmallocWords(2*sizeof(Type*));
 582   floop[0] = Type::CONTROL;
 583   floop[1] = TypeInt::INT;
 584   TypeTuple::LOOPBODY = TypeTuple::make( 2, floop );
 585 
 586   TypePtr::NULL_PTR= TypePtr::make(AnyPtr, TypePtr::Null, Offset(0));
 587   TypePtr::NOTNULL = TypePtr::make(AnyPtr, TypePtr::NotNull, Offset::bottom);
 588   TypePtr::BOTTOM  = TypePtr::make(AnyPtr, TypePtr::BotPTR, Offset::bottom);
 589 
 590   TypeRawPtr::BOTTOM = TypeRawPtr::make( TypePtr::BotPTR );
 591   TypeRawPtr::NOTNULL= TypeRawPtr::make( TypePtr::NotNull );
 592 
 593   const Type **fmembar = TypeTuple::fields(0);
 594   TypeTuple::MEMBAR = TypeTuple::make(TypeFunc::Parms+0, fmembar);
 595 
 596   const Type **fsc = (const Type**)shared_type_arena->AmallocWords(2*sizeof(Type*));
 597   fsc[0] = TypeInt::CC;
 598   fsc[1] = Type::MEMORY;
 599   TypeTuple::STORECONDITIONAL = TypeTuple::make(2, fsc);
 600 
 601   TypeInstPtr::NOTNULL = TypeInstPtr::make(TypePtr::NotNull, current->env()->Object_klass());
 602   TypeInstPtr::BOTTOM  = TypeInstPtr::make(TypePtr::BotPTR,  current->env()->Object_klass());
 603   TypeInstPtr::MIRROR  = TypeInstPtr::make(TypePtr::NotNull, current->env()->Class_klass());
 604   TypeInstPtr::MARK    = TypeInstPtr::make(TypePtr::BotPTR,  current->env()->Object_klass(),
 605                                            false, 0, Offset(oopDesc::mark_offset_in_bytes()));
 606   TypeInstPtr::KLASS   = TypeInstPtr::make(TypePtr::BotPTR,  current->env()->Object_klass(),
 607                                            false, 0, Offset(oopDesc::klass_offset_in_bytes()));
 608   TypeOopPtr::BOTTOM  = TypeOopPtr::make(TypePtr::BotPTR, Offset::bottom, TypeOopPtr::InstanceBot);
 609 
 610   TypeMetadataPtr::BOTTOM = TypeMetadataPtr::make(TypePtr::BotPTR, NULL, Offset::bottom);
 611 
 612   TypeInlineType::BOTTOM = TypeInlineType::make(NULL);
 613 
 614   TypeNarrowOop::NULL_PTR = TypeNarrowOop::make( TypePtr::NULL_PTR );
 615   TypeNarrowOop::BOTTOM   = TypeNarrowOop::make( TypeInstPtr::BOTTOM );
 616 
 617   TypeNarrowKlass::NULL_PTR = TypeNarrowKlass::make( TypePtr::NULL_PTR );
 618 
 619   mreg2type[Op_Node] = Type::BOTTOM;
 620   mreg2type[Op_Set ] = 0;
 621   mreg2type[Op_RegN] = TypeNarrowOop::BOTTOM;
 622   mreg2type[Op_RegI] = TypeInt::INT;
 623   mreg2type[Op_RegP] = TypePtr::BOTTOM;
 624   mreg2type[Op_RegF] = Type::FLOAT;
 625   mreg2type[Op_RegD] = Type::DOUBLE;
 626   mreg2type[Op_RegL] = TypeLong::LONG;
 627   mreg2type[Op_RegFlags] = TypeInt::CC;
 628 
 629   TypeAryPtr::RANGE   = TypeAryPtr::make(TypePtr::BotPTR, TypeAry::make(Type::BOTTOM,TypeInt::POS), NULL /* current->env()->Object_klass() */, false, Offset(arrayOopDesc::length_offset_in_bytes()));
 630 
 631   TypeAryPtr::NARROWOOPS = TypeAryPtr::make(TypePtr::BotPTR, TypeAry::make(TypeNarrowOop::BOTTOM, TypeInt::POS), NULL /*ciArrayKlass::make(o)*/,  false,  Offset::bottom);
 632 
 633 #ifdef _LP64
 634   if (UseCompressedOops) {
 635     assert(TypeAryPtr::NARROWOOPS->is_ptr_to_narrowoop(), "array of narrow oops must be ptr to narrow oop");
 636     TypeAryPtr::OOPS  = TypeAryPtr::NARROWOOPS;
 637   } else
 638 #endif
 639   {
 640     // There is no shared klass for Object[].  See note in TypeAryPtr::klass().
 641     TypeAryPtr::OOPS  = TypeAryPtr::make(TypePtr::BotPTR, TypeAry::make(TypeInstPtr::BOTTOM,TypeInt::POS), NULL /*ciArrayKlass::make(o)*/,  false,  Offset::bottom);
 642   }
 643   TypeAryPtr::BYTES   = TypeAryPtr::make(TypePtr::BotPTR, TypeAry::make(TypeInt::BYTE      ,TypeInt::POS), ciTypeArrayKlass::make(T_BYTE),   true,  Offset::bottom);
 644   TypeAryPtr::SHORTS  = TypeAryPtr::make(TypePtr::BotPTR, TypeAry::make(TypeInt::SHORT     ,TypeInt::POS), ciTypeArrayKlass::make(T_SHORT),  true,  Offset::bottom);
 645   TypeAryPtr::CHARS   = TypeAryPtr::make(TypePtr::BotPTR, TypeAry::make(TypeInt::CHAR      ,TypeInt::POS), ciTypeArrayKlass::make(T_CHAR),   true,  Offset::bottom);
 646   TypeAryPtr::INTS    = TypeAryPtr::make(TypePtr::BotPTR, TypeAry::make(TypeInt::INT       ,TypeInt::POS), ciTypeArrayKlass::make(T_INT),    true,  Offset::bottom);
 647   TypeAryPtr::LONGS   = TypeAryPtr::make(TypePtr::BotPTR, TypeAry::make(TypeLong::LONG     ,TypeInt::POS), ciTypeArrayKlass::make(T_LONG),   true,  Offset::bottom);
 648   TypeAryPtr::FLOATS  = TypeAryPtr::make(TypePtr::BotPTR, TypeAry::make(Type::FLOAT        ,TypeInt::POS), ciTypeArrayKlass::make(T_FLOAT),  true,  Offset::bottom);
 649   TypeAryPtr::DOUBLES = TypeAryPtr::make(TypePtr::BotPTR, TypeAry::make(Type::DOUBLE       ,TypeInt::POS), ciTypeArrayKlass::make(T_DOUBLE), true,  Offset::bottom);
 650   TypeAryPtr::INLINES = TypeAryPtr::make(TypePtr::BotPTR, TypeAry::make(TypeInlineType::BOTTOM,TypeInt::POS), NULL, false,  Offset::bottom);
 651 
 652   // Nobody should ask _array_body_type[T_NARROWOOP]. Use NULL as assert.
 653   TypeAryPtr::_array_body_type[T_NARROWOOP] = NULL;
 654   TypeAryPtr::_array_body_type[T_OBJECT]  = TypeAryPtr::OOPS;
 655   TypeAryPtr::_array_body_type[T_PRIMITIVE_OBJECT] = TypeAryPtr::OOPS;
 656   TypeAryPtr::_array_body_type[T_ARRAY]   = TypeAryPtr::OOPS; // arrays are stored in oop arrays
 657   TypeAryPtr::_array_body_type[T_BYTE]    = TypeAryPtr::BYTES;
 658   TypeAryPtr::_array_body_type[T_BOOLEAN] = TypeAryPtr::BYTES;  // boolean[] is a byte array
 659   TypeAryPtr::_array_body_type[T_SHORT]   = TypeAryPtr::SHORTS;
 660   TypeAryPtr::_array_body_type[T_CHAR]    = TypeAryPtr::CHARS;
 661   TypeAryPtr::_array_body_type[T_INT]     = TypeAryPtr::INTS;
 662   TypeAryPtr::_array_body_type[T_LONG]    = TypeAryPtr::LONGS;
 663   TypeAryPtr::_array_body_type[T_FLOAT]   = TypeAryPtr::FLOATS;
 664   TypeAryPtr::_array_body_type[T_DOUBLE]  = TypeAryPtr::DOUBLES;
 665 
 666   TypeInstKlassPtr::OBJECT = TypeInstKlassPtr::make(TypePtr::NotNull, current->env()->Object_klass(), Offset(0), false);
 667   TypeInstKlassPtr::OBJECT_OR_NULL = TypeInstKlassPtr::make(TypePtr::BotPTR, current->env()->Object_klass(), Offset(0), false);
 668 
 669   const Type **fi2c = TypeTuple::fields(2);
 670   fi2c[TypeFunc::Parms+0] = TypeInstPtr::BOTTOM; // Method*
 671   fi2c[TypeFunc::Parms+1] = TypeRawPtr::BOTTOM; // argument pointer
 672   TypeTuple::START_I2C = TypeTuple::make(TypeFunc::Parms+2, fi2c);
 673 
 674   const Type **intpair = TypeTuple::fields(2);
 675   intpair[0] = TypeInt::INT;
 676   intpair[1] = TypeInt::INT;
 677   TypeTuple::INT_PAIR = TypeTuple::make(2, intpair);
 678 
 679   const Type **longpair = TypeTuple::fields(2);
 680   longpair[0] = TypeLong::LONG;
 681   longpair[1] = TypeLong::LONG;
 682   TypeTuple::LONG_PAIR = TypeTuple::make(2, longpair);
 683 
 684   const Type **intccpair = TypeTuple::fields(2);
 685   intccpair[0] = TypeInt::INT;
 686   intccpair[1] = TypeInt::CC;
 687   TypeTuple::INT_CC_PAIR = TypeTuple::make(2, intccpair);
 688 
 689   const Type **longccpair = TypeTuple::fields(2);
 690   longccpair[0] = TypeLong::LONG;
 691   longccpair[1] = TypeInt::CC;
 692   TypeTuple::LONG_CC_PAIR = TypeTuple::make(2, longccpair);
 693 
 694   _const_basic_type[T_NARROWOOP]   = TypeNarrowOop::BOTTOM;
 695   _const_basic_type[T_NARROWKLASS] = Type::BOTTOM;
 696   _const_basic_type[T_BOOLEAN]     = TypeInt::BOOL;
 697   _const_basic_type[T_CHAR]        = TypeInt::CHAR;
 698   _const_basic_type[T_BYTE]        = TypeInt::BYTE;
 699   _const_basic_type[T_SHORT]       = TypeInt::SHORT;
 700   _const_basic_type[T_INT]         = TypeInt::INT;
 701   _const_basic_type[T_LONG]        = TypeLong::LONG;
 702   _const_basic_type[T_FLOAT]       = Type::FLOAT;
 703   _const_basic_type[T_DOUBLE]      = Type::DOUBLE;
 704   _const_basic_type[T_OBJECT]      = TypeInstPtr::BOTTOM;
 705   _const_basic_type[T_ARRAY]       = TypeInstPtr::BOTTOM; // there is no separate bottom for arrays
 706   _const_basic_type[T_PRIMITIVE_OBJECT] = TypeInstPtr::BOTTOM;
 707   _const_basic_type[T_VOID]        = TypePtr::NULL_PTR;   // reflection represents void this way
 708   _const_basic_type[T_ADDRESS]     = TypeRawPtr::BOTTOM;  // both interpreter return addresses & random raw ptrs
 709   _const_basic_type[T_CONFLICT]    = Type::BOTTOM;        // why not?
 710 
 711   _zero_type[T_NARROWOOP]   = TypeNarrowOop::NULL_PTR;
 712   _zero_type[T_NARROWKLASS] = TypeNarrowKlass::NULL_PTR;
 713   _zero_type[T_BOOLEAN]     = TypeInt::ZERO;     // false == 0
 714   _zero_type[T_CHAR]        = TypeInt::ZERO;     // '\0' == 0
 715   _zero_type[T_BYTE]        = TypeInt::ZERO;     // 0x00 == 0
 716   _zero_type[T_SHORT]       = TypeInt::ZERO;     // 0x0000 == 0
 717   _zero_type[T_INT]         = TypeInt::ZERO;
 718   _zero_type[T_LONG]        = TypeLong::ZERO;
 719   _zero_type[T_FLOAT]       = TypeF::ZERO;
 720   _zero_type[T_DOUBLE]      = TypeD::ZERO;
 721   _zero_type[T_OBJECT]      = TypePtr::NULL_PTR;
 722   _zero_type[T_ARRAY]       = TypePtr::NULL_PTR; // null array is null oop
 723   _zero_type[T_PRIMITIVE_OBJECT] = TypePtr::NULL_PTR;
 724   _zero_type[T_ADDRESS]     = TypePtr::NULL_PTR; // raw pointers use the same null
 725   _zero_type[T_VOID]        = Type::TOP;         // the only void value is no value at all
 726 
 727   // get_zero_type() should not happen for T_CONFLICT
 728   _zero_type[T_CONFLICT]= NULL;
 729 
 730   TypeVect::VECTMASK = (TypeVect*)(new TypeVectMask(TypeInt::BOOL, MaxVectorSize))->hashcons();
 731   mreg2type[Op_RegVectMask] = TypeVect::VECTMASK;
 732 
 733   if (Matcher::supports_scalable_vector()) {
 734     TypeVect::VECTA = TypeVect::make(T_BYTE, Matcher::scalable_vector_reg_size(T_BYTE));
 735   }
 736 
 737   // Vector predefined types, it needs initialized _const_basic_type[].
 738   if (Matcher::vector_size_supported(T_BYTE,4)) {
 739     TypeVect::VECTS = TypeVect::make(T_BYTE,4);
 740   }
 741   if (Matcher::vector_size_supported(T_FLOAT,2)) {
 742     TypeVect::VECTD = TypeVect::make(T_FLOAT,2);
 743   }
 744   if (Matcher::vector_size_supported(T_FLOAT,4)) {
 745     TypeVect::VECTX = TypeVect::make(T_FLOAT,4);
 746   }
 747   if (Matcher::vector_size_supported(T_FLOAT,8)) {
 748     TypeVect::VECTY = TypeVect::make(T_FLOAT,8);
 749   }
 750   if (Matcher::vector_size_supported(T_FLOAT,16)) {
 751     TypeVect::VECTZ = TypeVect::make(T_FLOAT,16);
 752   }
 753 
 754   mreg2type[Op_VecA] = TypeVect::VECTA;
 755   mreg2type[Op_VecS] = TypeVect::VECTS;
 756   mreg2type[Op_VecD] = TypeVect::VECTD;
 757   mreg2type[Op_VecX] = TypeVect::VECTX;
 758   mreg2type[Op_VecY] = TypeVect::VECTY;
 759   mreg2type[Op_VecZ] = TypeVect::VECTZ;
 760 
 761   // Restore working type arena.
 762   current->set_type_arena(save);
 763   current->set_type_dict(NULL);
 764 }
 765 
 766 //------------------------------Initialize-------------------------------------
 767 void Type::Initialize(Compile* current) {
 768   assert(current->type_arena() != NULL, "must have created type arena");
 769 
 770   if (_shared_type_dict == NULL) {
 771     Initialize_shared(current);
 772   }
 773 
 774   Arena* type_arena = current->type_arena();
 775 
 776   // Create the hash-cons'ing dictionary with top-level storage allocation
 777   Dict *tdic = new (type_arena) Dict(*_shared_type_dict, type_arena);
 778   current->set_type_dict(tdic);
 779 }
 780 
 781 //------------------------------hashcons---------------------------------------
 782 // Do the hash-cons trick.  If the Type already exists in the type table,
 783 // delete the current Type and return the existing Type.  Otherwise stick the
 784 // current Type in the Type table.
 785 const Type *Type::hashcons(void) {
 786   debug_only(base());           // Check the assertion in Type::base().
 787   // Look up the Type in the Type dictionary
 788   Dict *tdic = type_dict();
 789   Type* old = (Type*)(tdic->Insert(this, this, false));
 790   if( old ) {                   // Pre-existing Type?
 791     if( old != this )           // Yes, this guy is not the pre-existing?
 792       delete this;              // Yes, Nuke this guy
 793     assert( old->_dual, "" );
 794     return old;                 // Return pre-existing
 795   }
 796 
 797   // Every type has a dual (to make my lattice symmetric).
 798   // Since we just discovered a new Type, compute its dual right now.
 799   assert( !_dual, "" );         // No dual yet
 800   _dual = xdual();              // Compute the dual
 801   if (cmp(this, _dual) == 0) {  // Handle self-symmetric
 802     if (_dual != this) {
 803       delete _dual;
 804       _dual = this;
 805     }
 806     return this;
 807   }
 808   assert( !_dual->_dual, "" );  // No reverse dual yet
 809   assert( !(*tdic)[_dual], "" ); // Dual not in type system either
 810   // New Type, insert into Type table
 811   tdic->Insert((void*)_dual,(void*)_dual);
 812   ((Type*)_dual)->_dual = this; // Finish up being symmetric
 813 #ifdef ASSERT
 814   Type *dual_dual = (Type*)_dual->xdual();
 815   assert( eq(dual_dual), "xdual(xdual()) should be identity" );
 816   delete dual_dual;
 817 #endif
 818   return this;                  // Return new Type
 819 }
 820 
 821 //------------------------------eq---------------------------------------------
 822 // Structural equality check for Type representations
 823 bool Type::eq( const Type * ) const {
 824   return true;                  // Nothing else can go wrong
 825 }
 826 
 827 //------------------------------hash-------------------------------------------
 828 // Type-specific hashing function.
 829 int Type::hash(void) const {
 830   return _base;
 831 }
 832 
 833 //------------------------------is_finite--------------------------------------
 834 // Has a finite value
 835 bool Type::is_finite() const {
 836   return false;
 837 }
 838 
 839 //------------------------------is_nan-----------------------------------------
 840 // Is not a number (NaN)
 841 bool Type::is_nan()    const {
 842   return false;
 843 }
 844 
 845 //----------------------interface_vs_oop---------------------------------------
 846 #ifdef ASSERT
 847 bool Type::interface_vs_oop_helper(const Type *t) const {
 848   bool result = false;
 849 
 850   const TypePtr* this_ptr = this->make_ptr(); // In case it is narrow_oop
 851   const TypePtr*    t_ptr =    t->make_ptr();
 852   if( this_ptr == NULL || t_ptr == NULL )
 853     return result;
 854 
 855   const TypeInstPtr* this_inst = this_ptr->isa_instptr();
 856   const TypeInstPtr*    t_inst =    t_ptr->isa_instptr();
 857   if( this_inst && this_inst->is_loaded() && t_inst && t_inst->is_loaded() ) {
 858     bool this_interface = this_inst->is_interface();
 859     bool    t_interface =    t_inst->is_interface();
 860     result = this_interface ^ t_interface;
 861   }
 862 
 863   return result;
 864 }
 865 
 866 bool Type::interface_vs_oop(const Type *t) const {
 867   if (interface_vs_oop_helper(t)) {
 868     return true;
 869   }
 870   // Now check the speculative parts as well
 871   const TypePtr* this_spec = isa_ptr() != NULL ? is_ptr()->speculative() : NULL;
 872   const TypePtr* t_spec = t->isa_ptr() != NULL ? t->is_ptr()->speculative() : NULL;
 873   if (this_spec != NULL && t_spec != NULL) {
 874     if (this_spec->interface_vs_oop_helper(t_spec)) {
 875       return true;
 876     }
 877     return false;
 878   }
 879   if (this_spec != NULL && this_spec->interface_vs_oop_helper(t)) {
 880     return true;
 881   }
 882   if (t_spec != NULL && interface_vs_oop_helper(t_spec)) {
 883     return true;
 884   }
 885   return false;
 886 }
 887 
 888 #endif
 889 
 890 void Type::check_symmetrical(const Type* t, const Type* mt) const {
 891 #ifdef ASSERT
 892   const Type* mt2 = t->xmeet(this);
 893   if (mt != mt2) {
 894     tty->print_cr("=== Meet Not Commutative ===");
 895     tty->print("t           = ");   t->dump(); tty->cr();
 896     tty->print("this        = ");      dump(); tty->cr();
 897     tty->print("t meet this = "); mt2->dump(); tty->cr();
 898     tty->print("this meet t = ");  mt->dump(); tty->cr();
 899     fatal("meet not commutative");
 900   }
 901   const Type* dual_join = mt->_dual;
 902   const Type* t2t    = dual_join->xmeet(t->_dual);
 903   const Type* t2this = dual_join->xmeet(this->_dual);
 904 
 905   // Interface meet Oop is Not Symmetric:
 906   // Interface:AnyNull meet Oop:AnyNull == Interface:AnyNull
 907   // Interface:NotNull meet Oop:NotNull == java/lang/Object:NotNull
 908 
 909   if (!interface_vs_oop(t) && (t2t != t->_dual || t2this != this->_dual)) {
 910     tty->print_cr("=== Meet Not Symmetric ===");
 911     tty->print("t   =                   ");              t->dump(); tty->cr();
 912     tty->print("this=                   ");                 dump(); tty->cr();
 913     tty->print("mt=(t meet this)=       ");             mt->dump(); tty->cr();
 914 
 915     tty->print("t_dual=                 ");       t->_dual->dump(); tty->cr();
 916     tty->print("this_dual=              ");          _dual->dump(); tty->cr();
 917     tty->print("mt_dual=                ");      mt->_dual->dump(); tty->cr();
 918 
 919     tty->print("mt_dual meet t_dual=    "); t2t           ->dump(); tty->cr();
 920     tty->print("mt_dual meet this_dual= "); t2this        ->dump(); tty->cr();
 921 
 922     fatal("meet not symmetric");
 923   }
 924 #endif
 925 }
 926 
 927 //------------------------------meet-------------------------------------------
 928 // Compute the MEET of two types.  NOT virtual.  It enforces that meet is
 929 // commutative and the lattice is symmetric.
 930 const Type *Type::meet_helper(const Type *t, bool include_speculative) const {
 931   if (isa_narrowoop() && t->isa_narrowoop()) {
 932     const Type* result = make_ptr()->meet_helper(t->make_ptr(), include_speculative);
 933     return result->make_narrowoop();
 934   }
 935   if (isa_narrowklass() && t->isa_narrowklass()) {
 936     const Type* result = make_ptr()->meet_helper(t->make_ptr(), include_speculative);
 937     return result->make_narrowklass();
 938   }
 939 
 940   const Type *this_t = maybe_remove_speculative(include_speculative);
 941   t = t->maybe_remove_speculative(include_speculative);
 942 
 943   const Type *mt = this_t->xmeet(t);
 944 #ifdef ASSERT
 945   if (isa_narrowoop() || t->isa_narrowoop()) return mt;
 946   if (isa_narrowklass() || t->isa_narrowklass()) return mt;
 947   Compile* C = Compile::current();
 948   if (!C->_type_verify_symmetry) {
 949     return mt;
 950   }
 951   this_t->check_symmetrical(t, mt);
 952   // In the case of an array, computing the meet above, caused the
 953   // computation of the meet of the elements which at verification
 954   // time caused the computation of the meet of the dual of the
 955   // elements. Computing the meet of the dual of the arrays here
 956   // causes the meet of the dual of the elements to be computed which
 957   // would cause the meet of the dual of the dual of the elements,
 958   // that is the meet of the elements already computed above to be
 959   // computed. Avoid redundant computations by requesting no
 960   // verification.
 961   C->_type_verify_symmetry = false;
 962   const Type *mt_dual = this_t->_dual->xmeet(t->_dual);
 963   this_t->_dual->check_symmetrical(t->_dual, mt_dual);
 964   assert(!C->_type_verify_symmetry, "shouldn't have changed");
 965   C->_type_verify_symmetry = true;
 966 #endif
 967   return mt;
 968 }
 969 
 970 //------------------------------xmeet------------------------------------------
 971 // Compute the MEET of two types.  It returns a new Type object.
 972 const Type *Type::xmeet( const Type *t ) const {
 973   // Perform a fast test for common case; meeting the same types together.
 974   if( this == t ) return this;  // Meeting same type-rep?
 975 
 976   // Meeting TOP with anything?
 977   if( _base == Top ) return t;
 978 
 979   // Meeting BOTTOM with anything?
 980   if( _base == Bottom ) return BOTTOM;
 981 
 982   // Current "this->_base" is one of: Bad, Multi, Control, Top,
 983   // Abio, Abstore, Floatxxx, Doublexxx, Bottom, lastype.
 984   switch (t->base()) {  // Switch on original type
 985 
 986   // Cut in half the number of cases I must handle.  Only need cases for when
 987   // the given enum "t->type" is less than or equal to the local enum "type".
 988   case FloatCon:
 989   case DoubleCon:
 990   case Int:
 991   case Long:
 992     return t->xmeet(this);
 993 
 994   case OopPtr:
 995     return t->xmeet(this);
 996 
 997   case InstPtr:
 998     return t->xmeet(this);
 999 
1000   case MetadataPtr:
1001   case KlassPtr:
1002   case InstKlassPtr:
1003   case AryKlassPtr:
1004     return t->xmeet(this);
1005 
1006   case AryPtr:
1007     return t->xmeet(this);
1008 
1009   case NarrowOop:
1010     return t->xmeet(this);
1011 
1012   case NarrowKlass:
1013     return t->xmeet(this);
1014 
1015   case InlineType:
1016     return t->xmeet(this);
1017 
1018   case Bad:                     // Type check
1019   default:                      // Bogus type not in lattice
1020     typerr(t);
1021     return Type::BOTTOM;
1022 
1023   case Bottom:                  // Ye Olde Default
1024     return t;
1025 
1026   case FloatTop:
1027     if( _base == FloatTop ) return this;
1028   case FloatBot:                // Float
1029     if( _base == FloatBot || _base == FloatTop ) return FLOAT;
1030     if( _base == DoubleTop || _base == DoubleBot ) return Type::BOTTOM;
1031     typerr(t);
1032     return Type::BOTTOM;
1033 
1034   case DoubleTop:
1035     if( _base == DoubleTop ) return this;
1036   case DoubleBot:               // Double
1037     if( _base == DoubleBot || _base == DoubleTop ) return DOUBLE;
1038     if( _base == FloatTop || _base == FloatBot ) return Type::BOTTOM;
1039     typerr(t);
1040     return Type::BOTTOM;
1041 
1042   // These next few cases must match exactly or it is a compile-time error.
1043   case Control:                 // Control of code
1044   case Abio:                    // State of world outside of program
1045   case Memory:
1046     if( _base == t->_base )  return this;
1047     typerr(t);
1048     return Type::BOTTOM;
1049 
1050   case Top:                     // Top of the lattice
1051     return this;
1052   }
1053 
1054   // The type is unchanged
1055   return this;
1056 }
1057 
1058 //-----------------------------filter------------------------------------------
1059 const Type *Type::filter_helper(const Type *kills, bool include_speculative) const {
1060   const Type* ft = join_helper(kills, include_speculative);
1061   if (ft->empty())
1062     return Type::TOP;           // Canonical empty value
1063   return ft;
1064 }
1065 
1066 //------------------------------xdual------------------------------------------
1067 const Type *Type::xdual() const {
1068   // Note: the base() accessor asserts the sanity of _base.
1069   assert(_type_info[base()].dual_type != Bad, "implement with v-call");
1070   return new Type(_type_info[_base].dual_type);
1071 }
1072 
1073 //------------------------------has_memory-------------------------------------
1074 bool Type::has_memory() const {
1075   Type::TYPES tx = base();
1076   if (tx == Memory) return true;
1077   if (tx == Tuple) {
1078     const TypeTuple *t = is_tuple();
1079     for (uint i=0; i < t->cnt(); i++) {
1080       tx = t->field_at(i)->base();
1081       if (tx == Memory)  return true;
1082     }
1083   }
1084   return false;
1085 }
1086 
1087 #ifndef PRODUCT
1088 //------------------------------dump2------------------------------------------
1089 void Type::dump2( Dict &d, uint depth, outputStream *st ) const {
1090   st->print("%s", _type_info[_base].msg);
1091 }
1092 
1093 //------------------------------dump-------------------------------------------
1094 void Type::dump_on(outputStream *st) const {
1095   ResourceMark rm;
1096   Dict d(cmpkey,hashkey);       // Stop recursive type dumping
1097   dump2(d,1, st);
1098   if (is_ptr_to_narrowoop()) {
1099     st->print(" [narrow]");
1100   } else if (is_ptr_to_narrowklass()) {
1101     st->print(" [narrowklass]");
1102   }
1103 }
1104 
1105 //-----------------------------------------------------------------------------
1106 const char* Type::str(const Type* t) {
1107   stringStream ss;
1108   t->dump_on(&ss);
1109   return ss.as_string();
1110 }
1111 #endif
1112 
1113 //------------------------------singleton--------------------------------------
1114 // TRUE if Type is a singleton type, FALSE otherwise.   Singletons are simple
1115 // constants (Ldi nodes).  Singletons are integer, float or double constants.
1116 bool Type::singleton(void) const {
1117   return _base == Top || _base == Half;
1118 }
1119 
1120 //------------------------------empty------------------------------------------
1121 // TRUE if Type is a type with no values, FALSE otherwise.
1122 bool Type::empty(void) const {
1123   switch (_base) {
1124   case DoubleTop:
1125   case FloatTop:
1126   case Top:
1127     return true;
1128 
1129   case Half:
1130   case Abio:
1131   case Return_Address:
1132   case Memory:
1133   case Bottom:
1134   case FloatBot:
1135   case DoubleBot:
1136     return false;  // never a singleton, therefore never empty
1137 
1138   default:
1139     ShouldNotReachHere();
1140     return false;
1141   }
1142 }
1143 
1144 //------------------------------dump_stats-------------------------------------
1145 // Dump collected statistics to stderr
1146 #ifndef PRODUCT
1147 void Type::dump_stats() {
1148   tty->print("Types made: %d\n", type_dict()->Size());
1149 }
1150 #endif
1151 
1152 //------------------------------category---------------------------------------
1153 #ifndef PRODUCT
1154 Type::Category Type::category() const {
1155   const TypeTuple* tuple;
1156   switch (base()) {
1157     case Type::Int:
1158     case Type::Long:
1159     case Type::Half:
1160     case Type::NarrowOop:
1161     case Type::NarrowKlass:
1162     case Type::Array:
1163     case Type::VectorA:
1164     case Type::VectorS:
1165     case Type::VectorD:
1166     case Type::VectorX:
1167     case Type::VectorY:
1168     case Type::VectorZ:
1169     case Type::VectorMask:
1170     case Type::AnyPtr:
1171     case Type::RawPtr:
1172     case Type::OopPtr:
1173     case Type::InstPtr:
1174     case Type::AryPtr:
1175     case Type::MetadataPtr:
1176     case Type::KlassPtr:
1177     case Type::InstKlassPtr:
1178     case Type::AryKlassPtr:
1179     case Type::Function:
1180     case Type::Return_Address:
1181     case Type::FloatTop:
1182     case Type::FloatCon:
1183     case Type::FloatBot:
1184     case Type::DoubleTop:
1185     case Type::DoubleCon:
1186     case Type::DoubleBot:
1187     case Type::InlineType:
1188       return Category::Data;
1189     case Type::Memory:
1190       return Category::Memory;
1191     case Type::Control:
1192       return Category::Control;
1193     case Type::Top:
1194     case Type::Abio:
1195     case Type::Bottom:
1196       return Category::Other;
1197     case Type::Bad:
1198     case Type::lastype:
1199       return Category::Undef;
1200     case Type::Tuple:
1201       // Recursive case. Return CatMixed if the tuple contains types of
1202       // different categories (e.g. CallStaticJavaNode's type), or the specific
1203       // category if all types are of the same category (e.g. IfNode's type).
1204       tuple = is_tuple();
1205       if (tuple->cnt() == 0) {
1206         return Category::Undef;
1207       } else {
1208         Category first = tuple->field_at(0)->category();
1209         for (uint i = 1; i < tuple->cnt(); i++) {
1210           if (tuple->field_at(i)->category() != first) {
1211             return Category::Mixed;
1212           }
1213         }
1214         return first;
1215       }
1216     default:
1217       assert(false, "unmatched base type: all base types must be categorized");
1218   }
1219   return Category::Undef;
1220 }
1221 
1222 bool Type::has_category(Type::Category cat) const {
1223   if (category() == cat) {
1224     return true;
1225   }
1226   if (category() == Category::Mixed) {
1227     const TypeTuple* tuple = is_tuple();
1228     for (uint i = 0; i < tuple->cnt(); i++) {
1229       if (tuple->field_at(i)->has_category(cat)) {
1230         return true;
1231       }
1232     }
1233   }
1234   return false;
1235 }
1236 #endif
1237 
1238 //------------------------------typerr-----------------------------------------
1239 void Type::typerr( const Type *t ) const {
1240 #ifndef PRODUCT
1241   tty->print("\nError mixing types: ");
1242   dump();
1243   tty->print(" and ");
1244   t->dump();
1245   tty->print("\n");
1246 #endif
1247   ShouldNotReachHere();
1248 }
1249 
1250 
1251 //=============================================================================
1252 // Convenience common pre-built types.
1253 const TypeF *TypeF::MAX;        // Floating point max
1254 const TypeF *TypeF::MIN;        // Floating point min
1255 const TypeF *TypeF::ZERO;       // Floating point zero
1256 const TypeF *TypeF::ONE;        // Floating point one
1257 const TypeF *TypeF::POS_INF;    // Floating point positive infinity
1258 const TypeF *TypeF::NEG_INF;    // Floating point negative infinity
1259 
1260 //------------------------------make-------------------------------------------
1261 // Create a float constant
1262 const TypeF *TypeF::make(float f) {
1263   return (TypeF*)(new TypeF(f))->hashcons();
1264 }
1265 
1266 //------------------------------meet-------------------------------------------
1267 // Compute the MEET of two types.  It returns a new Type object.
1268 const Type *TypeF::xmeet( const Type *t ) const {
1269   // Perform a fast test for common case; meeting the same types together.
1270   if( this == t ) return this;  // Meeting same type-rep?
1271 
1272   // Current "this->_base" is FloatCon
1273   switch (t->base()) {          // Switch on original type
1274   case AnyPtr:                  // Mixing with oops happens when javac
1275   case RawPtr:                  // reuses local variables
1276   case OopPtr:
1277   case InstPtr:
1278   case AryPtr:
1279   case MetadataPtr:
1280   case KlassPtr:
1281   case InstKlassPtr:
1282   case AryKlassPtr:
1283   case NarrowOop:
1284   case NarrowKlass:
1285   case Int:
1286   case Long:
1287   case DoubleTop:
1288   case DoubleCon:
1289   case DoubleBot:
1290   case Bottom:                  // Ye Olde Default
1291     return Type::BOTTOM;
1292 
1293   case FloatBot:
1294     return t;
1295 
1296   default:                      // All else is a mistake
1297     typerr(t);
1298 
1299   case FloatCon:                // Float-constant vs Float-constant?
1300     if( jint_cast(_f) != jint_cast(t->getf()) )         // unequal constants?
1301                                 // must compare bitwise as positive zero, negative zero and NaN have
1302                                 // all the same representation in C++
1303       return FLOAT;             // Return generic float
1304                                 // Equal constants
1305   case Top:
1306   case FloatTop:
1307     break;                      // Return the float constant
1308   }
1309   return this;                  // Return the float constant
1310 }
1311 
1312 //------------------------------xdual------------------------------------------
1313 // Dual: symmetric
1314 const Type *TypeF::xdual() const {
1315   return this;
1316 }
1317 
1318 //------------------------------eq---------------------------------------------
1319 // Structural equality check for Type representations
1320 bool TypeF::eq(const Type *t) const {
1321   // Bitwise comparison to distinguish between +/-0. These values must be treated
1322   // as different to be consistent with C1 and the interpreter.
1323   return (jint_cast(_f) == jint_cast(t->getf()));
1324 }
1325 
1326 //------------------------------hash-------------------------------------------
1327 // Type-specific hashing function.
1328 int TypeF::hash(void) const {
1329   return *(int*)(&_f);
1330 }
1331 
1332 //------------------------------is_finite--------------------------------------
1333 // Has a finite value
1334 bool TypeF::is_finite() const {
1335   return g_isfinite(getf()) != 0;
1336 }
1337 
1338 //------------------------------is_nan-----------------------------------------
1339 // Is not a number (NaN)
1340 bool TypeF::is_nan()    const {
1341   return g_isnan(getf()) != 0;
1342 }
1343 
1344 //------------------------------dump2------------------------------------------
1345 // Dump float constant Type
1346 #ifndef PRODUCT
1347 void TypeF::dump2( Dict &d, uint depth, outputStream *st ) const {
1348   Type::dump2(d,depth, st);
1349   st->print("%f", _f);
1350 }
1351 #endif
1352 
1353 //------------------------------singleton--------------------------------------
1354 // TRUE if Type is a singleton type, FALSE otherwise.   Singletons are simple
1355 // constants (Ldi nodes).  Singletons are integer, float or double constants
1356 // or a single symbol.
1357 bool TypeF::singleton(void) const {
1358   return true;                  // Always a singleton
1359 }
1360 
1361 bool TypeF::empty(void) const {
1362   return false;                 // always exactly a singleton
1363 }
1364 
1365 //=============================================================================
1366 // Convenience common pre-built types.
1367 const TypeD *TypeD::MAX;        // Floating point max
1368 const TypeD *TypeD::MIN;        // Floating point min
1369 const TypeD *TypeD::ZERO;       // Floating point zero
1370 const TypeD *TypeD::ONE;        // Floating point one
1371 const TypeD *TypeD::POS_INF;    // Floating point positive infinity
1372 const TypeD *TypeD::NEG_INF;    // Floating point negative infinity
1373 
1374 //------------------------------make-------------------------------------------
1375 const TypeD *TypeD::make(double d) {
1376   return (TypeD*)(new TypeD(d))->hashcons();
1377 }
1378 
1379 //------------------------------meet-------------------------------------------
1380 // Compute the MEET of two types.  It returns a new Type object.
1381 const Type *TypeD::xmeet( const Type *t ) const {
1382   // Perform a fast test for common case; meeting the same types together.
1383   if( this == t ) return this;  // Meeting same type-rep?
1384 
1385   // Current "this->_base" is DoubleCon
1386   switch (t->base()) {          // Switch on original type
1387   case AnyPtr:                  // Mixing with oops happens when javac
1388   case RawPtr:                  // reuses local variables
1389   case OopPtr:
1390   case InstPtr:
1391   case AryPtr:
1392   case MetadataPtr:
1393   case KlassPtr:
1394   case InstKlassPtr:
1395   case AryKlassPtr:
1396   case NarrowOop:
1397   case NarrowKlass:
1398   case Int:
1399   case Long:
1400   case FloatTop:
1401   case FloatCon:
1402   case FloatBot:
1403   case Bottom:                  // Ye Olde Default
1404     return Type::BOTTOM;
1405 
1406   case DoubleBot:
1407     return t;
1408 
1409   default:                      // All else is a mistake
1410     typerr(t);
1411 
1412   case DoubleCon:               // Double-constant vs Double-constant?
1413     if( jlong_cast(_d) != jlong_cast(t->getd()) )       // unequal constants? (see comment in TypeF::xmeet)
1414       return DOUBLE;            // Return generic double
1415   case Top:
1416   case DoubleTop:
1417     break;
1418   }
1419   return this;                  // Return the double constant
1420 }
1421 
1422 //------------------------------xdual------------------------------------------
1423 // Dual: symmetric
1424 const Type *TypeD::xdual() const {
1425   return this;
1426 }
1427 
1428 //------------------------------eq---------------------------------------------
1429 // Structural equality check for Type representations
1430 bool TypeD::eq(const Type *t) const {
1431   // Bitwise comparison to distinguish between +/-0. These values must be treated
1432   // as different to be consistent with C1 and the interpreter.
1433   return (jlong_cast(_d) == jlong_cast(t->getd()));
1434 }
1435 
1436 //------------------------------hash-------------------------------------------
1437 // Type-specific hashing function.
1438 int TypeD::hash(void) const {
1439   return *(int*)(&_d);
1440 }
1441 
1442 //------------------------------is_finite--------------------------------------
1443 // Has a finite value
1444 bool TypeD::is_finite() const {
1445   return g_isfinite(getd()) != 0;
1446 }
1447 
1448 //------------------------------is_nan-----------------------------------------
1449 // Is not a number (NaN)
1450 bool TypeD::is_nan()    const {
1451   return g_isnan(getd()) != 0;
1452 }
1453 
1454 //------------------------------dump2------------------------------------------
1455 // Dump double constant Type
1456 #ifndef PRODUCT
1457 void TypeD::dump2( Dict &d, uint depth, outputStream *st ) const {
1458   Type::dump2(d,depth,st);
1459   st->print("%f", _d);
1460 }
1461 #endif
1462 
1463 //------------------------------singleton--------------------------------------
1464 // TRUE if Type is a singleton type, FALSE otherwise.   Singletons are simple
1465 // constants (Ldi nodes).  Singletons are integer, float or double constants
1466 // or a single symbol.
1467 bool TypeD::singleton(void) const {
1468   return true;                  // Always a singleton
1469 }
1470 
1471 bool TypeD::empty(void) const {
1472   return false;                 // always exactly a singleton
1473 }
1474 
1475 const TypeInteger* TypeInteger::make(jlong lo, jlong hi, int w, BasicType bt) {
1476   if (bt == T_INT) {
1477     return TypeInt::make(checked_cast<jint>(lo), checked_cast<jint>(hi), w);
1478   }
1479   assert(bt == T_LONG, "basic type not an int or long");
1480   return TypeLong::make(lo, hi, w);
1481 }
1482 
1483 jlong TypeInteger::get_con_as_long(BasicType bt) const {
1484   if (bt == T_INT) {
1485     return is_int()->get_con();
1486   }
1487   assert(bt == T_LONG, "basic type not an int or long");
1488   return is_long()->get_con();
1489 }
1490 
1491 const TypeInteger* TypeInteger::bottom(BasicType bt) {
1492   if (bt == T_INT) {
1493     return TypeInt::INT;
1494   }
1495   assert(bt == T_LONG, "basic type not an int or long");
1496   return TypeLong::LONG;
1497 }
1498 
1499 const TypeInteger* TypeInteger::zero(BasicType bt) {
1500   if (bt == T_INT) {
1501     return TypeInt::ZERO;
1502   }
1503   assert(bt == T_LONG, "basic type not an int or long");
1504   return TypeLong::ZERO;
1505 }
1506 
1507 const TypeInteger* TypeInteger::one(BasicType bt) {
1508   if (bt == T_INT) {
1509     return TypeInt::ONE;
1510   }
1511   assert(bt == T_LONG, "basic type not an int or long");
1512   return TypeLong::ONE;
1513 }
1514 
1515 const TypeInteger* TypeInteger::minus_1(BasicType bt) {
1516   if (bt == T_INT) {
1517     return TypeInt::MINUS_1;
1518   }
1519   assert(bt == T_LONG, "basic type not an int or long");
1520   return TypeLong::MINUS_1;
1521 }
1522 
1523 //=============================================================================
1524 // Convenience common pre-built types.
1525 const TypeInt *TypeInt::MAX;    // INT_MAX
1526 const TypeInt *TypeInt::MIN;    // INT_MIN
1527 const TypeInt *TypeInt::MINUS_1;// -1
1528 const TypeInt *TypeInt::ZERO;   // 0
1529 const TypeInt *TypeInt::ONE;    // 1
1530 const TypeInt *TypeInt::BOOL;   // 0 or 1, FALSE or TRUE.
1531 const TypeInt *TypeInt::CC;     // -1,0 or 1, condition codes
1532 const TypeInt *TypeInt::CC_LT;  // [-1]  == MINUS_1
1533 const TypeInt *TypeInt::CC_GT;  // [1]   == ONE
1534 const TypeInt *TypeInt::CC_EQ;  // [0]   == ZERO
1535 const TypeInt *TypeInt::CC_LE;  // [-1,0]
1536 const TypeInt *TypeInt::CC_GE;  // [0,1] == BOOL (!)
1537 const TypeInt *TypeInt::BYTE;   // Bytes, -128 to 127
1538 const TypeInt *TypeInt::UBYTE;  // Unsigned Bytes, 0 to 255
1539 const TypeInt *TypeInt::CHAR;   // Java chars, 0-65535
1540 const TypeInt *TypeInt::SHORT;  // Java shorts, -32768-32767
1541 const TypeInt *TypeInt::POS;    // Positive 32-bit integers or zero
1542 const TypeInt *TypeInt::POS1;   // Positive 32-bit integers
1543 const TypeInt *TypeInt::INT;    // 32-bit integers
1544 const TypeInt *TypeInt::SYMINT; // symmetric range [-max_jint..max_jint]
1545 const TypeInt *TypeInt::TYPE_DOMAIN; // alias for TypeInt::INT
1546 
1547 //------------------------------TypeInt----------------------------------------
1548 TypeInt::TypeInt( jint lo, jint hi, int w ) : TypeInteger(Int, w), _lo(lo), _hi(hi) {
1549 }
1550 
1551 //------------------------------make-------------------------------------------
1552 const TypeInt *TypeInt::make( jint lo ) {
1553   return (TypeInt*)(new TypeInt(lo,lo,WidenMin))->hashcons();
1554 }
1555 
1556 static int normalize_int_widen( jint lo, jint hi, int w ) {
1557   // Certain normalizations keep us sane when comparing types.
1558   // The 'SMALLINT' covers constants and also CC and its relatives.
1559   if (lo <= hi) {
1560     if (((juint)hi - lo) <= SMALLINT)  w = Type::WidenMin;
1561     if (((juint)hi - lo) >= max_juint) w = Type::WidenMax; // TypeInt::INT
1562   } else {
1563     if (((juint)lo - hi) <= SMALLINT)  w = Type::WidenMin;
1564     if (((juint)lo - hi) >= max_juint) w = Type::WidenMin; // dual TypeInt::INT
1565   }
1566   return w;
1567 }
1568 
1569 const TypeInt *TypeInt::make( jint lo, jint hi, int w ) {
1570   w = normalize_int_widen(lo, hi, w);
1571   return (TypeInt*)(new TypeInt(lo,hi,w))->hashcons();
1572 }
1573 
1574 //------------------------------meet-------------------------------------------
1575 // Compute the MEET of two types.  It returns a new Type representation object
1576 // with reference count equal to the number of Types pointing at it.
1577 // Caller should wrap a Types around it.
1578 const Type *TypeInt::xmeet( const Type *t ) const {
1579   // Perform a fast test for common case; meeting the same types together.
1580   if( this == t ) return this;  // Meeting same type?
1581 
1582   // Currently "this->_base" is a TypeInt
1583   switch (t->base()) {          // Switch on original type
1584   case AnyPtr:                  // Mixing with oops happens when javac
1585   case RawPtr:                  // reuses local variables
1586   case OopPtr:
1587   case InstPtr:
1588   case AryPtr:
1589   case MetadataPtr:
1590   case KlassPtr:
1591   case InstKlassPtr:
1592   case AryKlassPtr:
1593   case NarrowOop:
1594   case NarrowKlass:
1595   case Long:
1596   case FloatTop:
1597   case FloatCon:
1598   case FloatBot:
1599   case DoubleTop:
1600   case DoubleCon:
1601   case DoubleBot:
1602   case InlineType:
1603   case Bottom:                  // Ye Olde Default
1604     return Type::BOTTOM;
1605   default:                      // All else is a mistake
1606     typerr(t);
1607   case Top:                     // No change
1608     return this;
1609   case Int:                     // Int vs Int?
1610     break;
1611   }
1612 
1613   // Expand covered set
1614   const TypeInt *r = t->is_int();
1615   return make( MIN2(_lo,r->_lo), MAX2(_hi,r->_hi), MAX2(_widen,r->_widen) );
1616 }
1617 
1618 //------------------------------xdual------------------------------------------
1619 // Dual: reverse hi & lo; flip widen
1620 const Type *TypeInt::xdual() const {
1621   int w = normalize_int_widen(_hi,_lo, WidenMax-_widen);
1622   return new TypeInt(_hi,_lo,w);
1623 }
1624 
1625 //------------------------------widen------------------------------------------
1626 // Only happens for optimistic top-down optimizations.
1627 const Type *TypeInt::widen( const Type *old, const Type* limit ) const {
1628   // Coming from TOP or such; no widening
1629   if( old->base() != Int ) return this;
1630   const TypeInt *ot = old->is_int();
1631 
1632   // If new guy is equal to old guy, no widening
1633   if( _lo == ot->_lo && _hi == ot->_hi )
1634     return old;
1635 
1636   // If new guy contains old, then we widened
1637   if( _lo <= ot->_lo && _hi >= ot->_hi ) {
1638     // New contains old
1639     // If new guy is already wider than old, no widening
1640     if( _widen > ot->_widen ) return this;
1641     // If old guy was a constant, do not bother
1642     if (ot->_lo == ot->_hi)  return this;
1643     // Now widen new guy.
1644     // Check for widening too far
1645     if (_widen == WidenMax) {
1646       int max = max_jint;
1647       int min = min_jint;
1648       if (limit->isa_int()) {
1649         max = limit->is_int()->_hi;
1650         min = limit->is_int()->_lo;
1651       }
1652       if (min < _lo && _hi < max) {
1653         // If neither endpoint is extremal yet, push out the endpoint
1654         // which is closer to its respective limit.
1655         if (_lo >= 0 ||                 // easy common case
1656             (juint)(_lo - min) >= (juint)(max - _hi)) {
1657           // Try to widen to an unsigned range type of 31 bits:
1658           return make(_lo, max, WidenMax);
1659         } else {
1660           return make(min, _hi, WidenMax);
1661         }
1662       }
1663       return TypeInt::INT;
1664     }
1665     // Returned widened new guy
1666     return make(_lo,_hi,_widen+1);
1667   }
1668 
1669   // If old guy contains new, then we probably widened too far & dropped to
1670   // bottom.  Return the wider fellow.
1671   if ( ot->_lo <= _lo && ot->_hi >= _hi )
1672     return old;
1673 
1674   //fatal("Integer value range is not subset");
1675   //return this;
1676   return TypeInt::INT;
1677 }
1678 
1679 //------------------------------narrow---------------------------------------
1680 // Only happens for pessimistic optimizations.
1681 const Type *TypeInt::narrow( const Type *old ) const {
1682   if (_lo >= _hi)  return this;   // already narrow enough
1683   if (old == NULL)  return this;
1684   const TypeInt* ot = old->isa_int();
1685   if (ot == NULL)  return this;
1686   jint olo = ot->_lo;
1687   jint ohi = ot->_hi;
1688 
1689   // If new guy is equal to old guy, no narrowing
1690   if (_lo == olo && _hi == ohi)  return old;
1691 
1692   // If old guy was maximum range, allow the narrowing
1693   if (olo == min_jint && ohi == max_jint)  return this;
1694 
1695   if (_lo < olo || _hi > ohi)
1696     return this;                // doesn't narrow; pretty weird
1697 
1698   // The new type narrows the old type, so look for a "death march".
1699   // See comments on PhaseTransform::saturate.
1700   juint nrange = (juint)_hi - _lo;
1701   juint orange = (juint)ohi - olo;
1702   if (nrange < max_juint - 1 && nrange > (orange >> 1) + (SMALLINT*2)) {
1703     // Use the new type only if the range shrinks a lot.
1704     // We do not want the optimizer computing 2^31 point by point.
1705     return old;
1706   }
1707 
1708   return this;
1709 }
1710 
1711 //-----------------------------filter------------------------------------------
1712 const Type *TypeInt::filter_helper(const Type *kills, bool include_speculative) const {
1713   const TypeInt* ft = join_helper(kills, include_speculative)->isa_int();
1714   if (ft == NULL || ft->empty())
1715     return Type::TOP;           // Canonical empty value
1716   if (ft->_widen < this->_widen) {
1717     // Do not allow the value of kill->_widen to affect the outcome.
1718     // The widen bits must be allowed to run freely through the graph.
1719     ft = TypeInt::make(ft->_lo, ft->_hi, this->_widen);
1720   }
1721   return ft;
1722 }
1723 
1724 //------------------------------eq---------------------------------------------
1725 // Structural equality check for Type representations
1726 bool TypeInt::eq( const Type *t ) const {
1727   const TypeInt *r = t->is_int(); // Handy access
1728   return r->_lo == _lo && r->_hi == _hi && r->_widen == _widen;
1729 }
1730 
1731 //------------------------------hash-------------------------------------------
1732 // Type-specific hashing function.
1733 int TypeInt::hash(void) const {
1734   return java_add(java_add(_lo, _hi), java_add((jint)_widen, (jint)Type::Int));
1735 }
1736 
1737 //------------------------------is_finite--------------------------------------
1738 // Has a finite value
1739 bool TypeInt::is_finite() const {
1740   return true;
1741 }
1742 
1743 //------------------------------dump2------------------------------------------
1744 // Dump TypeInt
1745 #ifndef PRODUCT
1746 static const char* intname(char* buf, jint n) {
1747   if (n == min_jint)
1748     return "min";
1749   else if (n < min_jint + 10000)
1750     sprintf(buf, "min+" INT32_FORMAT, n - min_jint);
1751   else if (n == max_jint)
1752     return "max";
1753   else if (n > max_jint - 10000)
1754     sprintf(buf, "max-" INT32_FORMAT, max_jint - n);
1755   else
1756     sprintf(buf, INT32_FORMAT, n);
1757   return buf;
1758 }
1759 
1760 void TypeInt::dump2( Dict &d, uint depth, outputStream *st ) const {
1761   char buf[40], buf2[40];
1762   if (_lo == min_jint && _hi == max_jint)
1763     st->print("int");
1764   else if (is_con())
1765     st->print("int:%s", intname(buf, get_con()));
1766   else if (_lo == BOOL->_lo && _hi == BOOL->_hi)
1767     st->print("bool");
1768   else if (_lo == BYTE->_lo && _hi == BYTE->_hi)
1769     st->print("byte");
1770   else if (_lo == CHAR->_lo && _hi == CHAR->_hi)
1771     st->print("char");
1772   else if (_lo == SHORT->_lo && _hi == SHORT->_hi)
1773     st->print("short");
1774   else if (_hi == max_jint)
1775     st->print("int:>=%s", intname(buf, _lo));
1776   else if (_lo == min_jint)
1777     st->print("int:<=%s", intname(buf, _hi));
1778   else
1779     st->print("int:%s..%s", intname(buf, _lo), intname(buf2, _hi));
1780 
1781   if (_widen != 0 && this != TypeInt::INT)
1782     st->print(":%.*s", _widen, "wwww");
1783 }
1784 #endif
1785 
1786 //------------------------------singleton--------------------------------------
1787 // TRUE if Type is a singleton type, FALSE otherwise.   Singletons are simple
1788 // constants.
1789 bool TypeInt::singleton(void) const {
1790   return _lo >= _hi;
1791 }
1792 
1793 bool TypeInt::empty(void) const {
1794   return _lo > _hi;
1795 }
1796 
1797 //=============================================================================
1798 // Convenience common pre-built types.
1799 const TypeLong *TypeLong::MAX;
1800 const TypeLong *TypeLong::MIN;
1801 const TypeLong *TypeLong::MINUS_1;// -1
1802 const TypeLong *TypeLong::ZERO; // 0
1803 const TypeLong *TypeLong::ONE;  // 1
1804 const TypeLong *TypeLong::POS;  // >=0
1805 const TypeLong *TypeLong::LONG; // 64-bit integers
1806 const TypeLong *TypeLong::INT;  // 32-bit subrange
1807 const TypeLong *TypeLong::UINT; // 32-bit unsigned subrange
1808 const TypeLong *TypeLong::TYPE_DOMAIN; // alias for TypeLong::LONG
1809 
1810 //------------------------------TypeLong---------------------------------------
1811 TypeLong::TypeLong(jlong lo, jlong hi, int w) : TypeInteger(Long, w), _lo(lo), _hi(hi) {
1812 }
1813 
1814 //------------------------------make-------------------------------------------
1815 const TypeLong *TypeLong::make( jlong lo ) {
1816   return (TypeLong*)(new TypeLong(lo,lo,WidenMin))->hashcons();
1817 }
1818 
1819 static int normalize_long_widen( jlong lo, jlong hi, int w ) {
1820   // Certain normalizations keep us sane when comparing types.
1821   // The 'SMALLINT' covers constants.
1822   if (lo <= hi) {
1823     if (((julong)hi - lo) <= SMALLINT)   w = Type::WidenMin;
1824     if (((julong)hi - lo) >= max_julong) w = Type::WidenMax; // TypeLong::LONG
1825   } else {
1826     if (((julong)lo - hi) <= SMALLINT)   w = Type::WidenMin;
1827     if (((julong)lo - hi) >= max_julong) w = Type::WidenMin; // dual TypeLong::LONG
1828   }
1829   return w;
1830 }
1831 
1832 const TypeLong *TypeLong::make( jlong lo, jlong hi, int w ) {
1833   w = normalize_long_widen(lo, hi, w);
1834   return (TypeLong*)(new TypeLong(lo,hi,w))->hashcons();
1835 }
1836 
1837 
1838 //------------------------------meet-------------------------------------------
1839 // Compute the MEET of two types.  It returns a new Type representation object
1840 // with reference count equal to the number of Types pointing at it.
1841 // Caller should wrap a Types around it.
1842 const Type *TypeLong::xmeet( const Type *t ) const {
1843   // Perform a fast test for common case; meeting the same types together.
1844   if( this == t ) return this;  // Meeting same type?
1845 
1846   // Currently "this->_base" is a TypeLong
1847   switch (t->base()) {          // Switch on original type
1848   case AnyPtr:                  // Mixing with oops happens when javac
1849   case RawPtr:                  // reuses local variables
1850   case OopPtr:
1851   case InstPtr:
1852   case AryPtr:
1853   case MetadataPtr:
1854   case KlassPtr:
1855   case InstKlassPtr:
1856   case AryKlassPtr:
1857   case NarrowOop:
1858   case NarrowKlass:
1859   case Int:
1860   case FloatTop:
1861   case FloatCon:
1862   case FloatBot:
1863   case DoubleTop:
1864   case DoubleCon:
1865   case DoubleBot:
1866   case Bottom:                  // Ye Olde Default
1867     return Type::BOTTOM;
1868   default:                      // All else is a mistake
1869     typerr(t);
1870   case Top:                     // No change
1871     return this;
1872   case Long:                    // Long vs Long?
1873     break;
1874   }
1875 
1876   // Expand covered set
1877   const TypeLong *r = t->is_long(); // Turn into a TypeLong
1878   return make( MIN2(_lo,r->_lo), MAX2(_hi,r->_hi), MAX2(_widen,r->_widen) );
1879 }
1880 
1881 //------------------------------xdual------------------------------------------
1882 // Dual: reverse hi & lo; flip widen
1883 const Type *TypeLong::xdual() const {
1884   int w = normalize_long_widen(_hi,_lo, WidenMax-_widen);
1885   return new TypeLong(_hi,_lo,w);
1886 }
1887 
1888 //------------------------------widen------------------------------------------
1889 // Only happens for optimistic top-down optimizations.
1890 const Type *TypeLong::widen( const Type *old, const Type* limit ) const {
1891   // Coming from TOP or such; no widening
1892   if( old->base() != Long ) return this;
1893   const TypeLong *ot = old->is_long();
1894 
1895   // If new guy is equal to old guy, no widening
1896   if( _lo == ot->_lo && _hi == ot->_hi )
1897     return old;
1898 
1899   // If new guy contains old, then we widened
1900   if( _lo <= ot->_lo && _hi >= ot->_hi ) {
1901     // New contains old
1902     // If new guy is already wider than old, no widening
1903     if( _widen > ot->_widen ) return this;
1904     // If old guy was a constant, do not bother
1905     if (ot->_lo == ot->_hi)  return this;
1906     // Now widen new guy.
1907     // Check for widening too far
1908     if (_widen == WidenMax) {
1909       jlong max = max_jlong;
1910       jlong min = min_jlong;
1911       if (limit->isa_long()) {
1912         max = limit->is_long()->_hi;
1913         min = limit->is_long()->_lo;
1914       }
1915       if (min < _lo && _hi < max) {
1916         // If neither endpoint is extremal yet, push out the endpoint
1917         // which is closer to its respective limit.
1918         if (_lo >= 0 ||                 // easy common case
1919             ((julong)_lo - min) >= ((julong)max - _hi)) {
1920           // Try to widen to an unsigned range type of 32/63 bits:
1921           if (max >= max_juint && _hi < max_juint)
1922             return make(_lo, max_juint, WidenMax);
1923           else
1924             return make(_lo, max, WidenMax);
1925         } else {
1926           return make(min, _hi, WidenMax);
1927         }
1928       }
1929       return TypeLong::LONG;
1930     }
1931     // Returned widened new guy
1932     return make(_lo,_hi,_widen+1);
1933   }
1934 
1935   // If old guy contains new, then we probably widened too far & dropped to
1936   // bottom.  Return the wider fellow.
1937   if ( ot->_lo <= _lo && ot->_hi >= _hi )
1938     return old;
1939 
1940   //  fatal("Long value range is not subset");
1941   // return this;
1942   return TypeLong::LONG;
1943 }
1944 
1945 //------------------------------narrow----------------------------------------
1946 // Only happens for pessimistic optimizations.
1947 const Type *TypeLong::narrow( const Type *old ) const {
1948   if (_lo >= _hi)  return this;   // already narrow enough
1949   if (old == NULL)  return this;
1950   const TypeLong* ot = old->isa_long();
1951   if (ot == NULL)  return this;
1952   jlong olo = ot->_lo;
1953   jlong ohi = ot->_hi;
1954 
1955   // If new guy is equal to old guy, no narrowing
1956   if (_lo == olo && _hi == ohi)  return old;
1957 
1958   // If old guy was maximum range, allow the narrowing
1959   if (olo == min_jlong && ohi == max_jlong)  return this;
1960 
1961   if (_lo < olo || _hi > ohi)
1962     return this;                // doesn't narrow; pretty weird
1963 
1964   // The new type narrows the old type, so look for a "death march".
1965   // See comments on PhaseTransform::saturate.
1966   julong nrange = _hi - _lo;
1967   julong orange = ohi - olo;
1968   if (nrange < max_julong - 1 && nrange > (orange >> 1) + (SMALLINT*2)) {
1969     // Use the new type only if the range shrinks a lot.
1970     // We do not want the optimizer computing 2^31 point by point.
1971     return old;
1972   }
1973 
1974   return this;
1975 }
1976 
1977 //-----------------------------filter------------------------------------------
1978 const Type *TypeLong::filter_helper(const Type *kills, bool include_speculative) const {
1979   const TypeLong* ft = join_helper(kills, include_speculative)->isa_long();
1980   if (ft == NULL || ft->empty())
1981     return Type::TOP;           // Canonical empty value
1982   if (ft->_widen < this->_widen) {
1983     // Do not allow the value of kill->_widen to affect the outcome.
1984     // The widen bits must be allowed to run freely through the graph.
1985     ft = TypeLong::make(ft->_lo, ft->_hi, this->_widen);
1986   }
1987   return ft;
1988 }
1989 
1990 //------------------------------eq---------------------------------------------
1991 // Structural equality check for Type representations
1992 bool TypeLong::eq( const Type *t ) const {
1993   const TypeLong *r = t->is_long(); // Handy access
1994   return r->_lo == _lo &&  r->_hi == _hi  && r->_widen == _widen;
1995 }
1996 
1997 //------------------------------hash-------------------------------------------
1998 // Type-specific hashing function.
1999 int TypeLong::hash(void) const {
2000   return (int)(_lo+_hi+_widen+(int)Type::Long);
2001 }
2002 
2003 //------------------------------is_finite--------------------------------------
2004 // Has a finite value
2005 bool TypeLong::is_finite() const {
2006   return true;
2007 }
2008 
2009 //------------------------------dump2------------------------------------------
2010 // Dump TypeLong
2011 #ifndef PRODUCT
2012 static const char* longnamenear(jlong x, const char* xname, char* buf, jlong n) {
2013   if (n > x) {
2014     if (n >= x + 10000)  return NULL;
2015     sprintf(buf, "%s+" JLONG_FORMAT, xname, n - x);
2016   } else if (n < x) {
2017     if (n <= x - 10000)  return NULL;
2018     sprintf(buf, "%s-" JLONG_FORMAT, xname, x - n);
2019   } else {
2020     return xname;
2021   }
2022   return buf;
2023 }
2024 
2025 static const char* longname(char* buf, jlong n) {
2026   const char* str;
2027   if (n == min_jlong)
2028     return "min";
2029   else if (n < min_jlong + 10000)
2030     sprintf(buf, "min+" JLONG_FORMAT, n - min_jlong);
2031   else if (n == max_jlong)
2032     return "max";
2033   else if (n > max_jlong - 10000)
2034     sprintf(buf, "max-" JLONG_FORMAT, max_jlong - n);
2035   else if ((str = longnamenear(max_juint, "maxuint", buf, n)) != NULL)
2036     return str;
2037   else if ((str = longnamenear(max_jint, "maxint", buf, n)) != NULL)
2038     return str;
2039   else if ((str = longnamenear(min_jint, "minint", buf, n)) != NULL)
2040     return str;
2041   else
2042     sprintf(buf, JLONG_FORMAT, n);
2043   return buf;
2044 }
2045 
2046 void TypeLong::dump2( Dict &d, uint depth, outputStream *st ) const {
2047   char buf[80], buf2[80];
2048   if (_lo == min_jlong && _hi == max_jlong)
2049     st->print("long");
2050   else if (is_con())
2051     st->print("long:%s", longname(buf, get_con()));
2052   else if (_hi == max_jlong)
2053     st->print("long:>=%s", longname(buf, _lo));
2054   else if (_lo == min_jlong)
2055     st->print("long:<=%s", longname(buf, _hi));
2056   else
2057     st->print("long:%s..%s", longname(buf, _lo), longname(buf2, _hi));
2058 
2059   if (_widen != 0 && this != TypeLong::LONG)
2060     st->print(":%.*s", _widen, "wwww");
2061 }
2062 #endif
2063 
2064 //------------------------------singleton--------------------------------------
2065 // TRUE if Type is a singleton type, FALSE otherwise.   Singletons are simple
2066 // constants
2067 bool TypeLong::singleton(void) const {
2068   return _lo >= _hi;
2069 }
2070 
2071 bool TypeLong::empty(void) const {
2072   return _lo > _hi;
2073 }
2074 
2075 //=============================================================================
2076 // Convenience common pre-built types.
2077 const TypeTuple *TypeTuple::IFBOTH;     // Return both arms of IF as reachable
2078 const TypeTuple *TypeTuple::IFFALSE;
2079 const TypeTuple *TypeTuple::IFTRUE;
2080 const TypeTuple *TypeTuple::IFNEITHER;
2081 const TypeTuple *TypeTuple::LOOPBODY;
2082 const TypeTuple *TypeTuple::MEMBAR;
2083 const TypeTuple *TypeTuple::STORECONDITIONAL;
2084 const TypeTuple *TypeTuple::START_I2C;
2085 const TypeTuple *TypeTuple::INT_PAIR;
2086 const TypeTuple *TypeTuple::LONG_PAIR;
2087 const TypeTuple *TypeTuple::INT_CC_PAIR;
2088 const TypeTuple *TypeTuple::LONG_CC_PAIR;
2089 
2090 static void collect_inline_fields(ciInlineKlass* vk, const Type** field_array, uint& pos) {
2091   for (int j = 0; j < vk->nof_nonstatic_fields(); j++) {
2092     ciField* field = vk->nonstatic_field_at(j);
2093     BasicType bt = field->type()->basic_type();
2094     const Type* ft = Type::get_const_type(field->type());
2095     field_array[pos++] = ft;
2096     if (type2size[bt] == 2) {
2097       field_array[pos++] = Type::HALF;
2098     }
2099   }
2100 }
2101 
2102 //------------------------------make-------------------------------------------
2103 // Make a TypeTuple from the range of a method signature
2104 const TypeTuple *TypeTuple::make_range(ciSignature* sig, bool ret_vt_fields) {
2105   ciType* return_type = sig->return_type();
2106   uint arg_cnt = return_type->size();
2107   if (ret_vt_fields) {
2108     arg_cnt = return_type->as_inline_klass()->inline_arg_slots() + 1;
2109     if (!sig->returns_null_free_inline_type()) {
2110       // InlineTypeNode::IsInit field used for null checking
2111       arg_cnt++;
2112     }
2113   }
2114 
2115   const Type **field_array = fields(arg_cnt);
2116   switch (return_type->basic_type()) {
2117   case T_LONG:
2118     field_array[TypeFunc::Parms]   = TypeLong::LONG;
2119     field_array[TypeFunc::Parms+1] = Type::HALF;
2120     break;
2121   case T_DOUBLE:
2122     field_array[TypeFunc::Parms]   = Type::DOUBLE;
2123     field_array[TypeFunc::Parms+1] = Type::HALF;
2124     break;
2125   case T_OBJECT:
2126   case T_ARRAY:
2127   case T_BOOLEAN:
2128   case T_CHAR:
2129   case T_FLOAT:
2130   case T_BYTE:
2131   case T_SHORT:
2132   case T_INT:
2133     field_array[TypeFunc::Parms] = get_const_type(return_type);
2134     break;
2135   case T_PRIMITIVE_OBJECT:
2136     if (ret_vt_fields) {
2137       uint pos = TypeFunc::Parms;
2138       field_array[pos++] = get_const_type(return_type); // Oop might be null when returning as fields
2139       collect_inline_fields(return_type->as_inline_klass(), field_array, pos);
2140       if (!sig->returns_null_free_inline_type()) {
2141         // InlineTypeNode::IsInit field used for null checking
2142         field_array[pos++] = get_const_basic_type(T_BOOLEAN);
2143       }
2144     } else {
2145       field_array[TypeFunc::Parms] = get_const_type(return_type)->join_speculative(sig->returns_null_free_inline_type() ? TypePtr::NOTNULL : TypePtr::BOTTOM);
2146     }
2147     break;
2148   case T_VOID:
2149     break;
2150   default:
2151     ShouldNotReachHere();
2152   }
2153   return (TypeTuple*)(new TypeTuple(TypeFunc::Parms + arg_cnt, field_array))->hashcons();
2154 }
2155 
2156 // Make a TypeTuple from the domain of a method signature
2157 const TypeTuple *TypeTuple::make_domain(ciMethod* method, bool vt_fields_as_args) {
2158   ciSignature* sig = method->signature();
2159   uint arg_cnt = sig->size() + (method->is_static() ? 0 : 1);
2160   if (vt_fields_as_args) {
2161     arg_cnt = 0;
2162     assert(method->get_sig_cc() != NULL, "Should have scalarized signature");
2163     for (ExtendedSignature sig_cc = ExtendedSignature(method->get_sig_cc(), SigEntryFilter()); !sig_cc.at_end(); ++sig_cc) {
2164       arg_cnt += type2size[(*sig_cc)._bt];
2165     }
2166   }
2167 
2168   uint pos = TypeFunc::Parms;
2169   const Type** field_array = fields(arg_cnt);
2170   if (!method->is_static()) {
2171     ciInstanceKlass* recv = method->holder();
2172     if (vt_fields_as_args && recv->is_inlinetype() && recv->as_inline_klass()->can_be_passed_as_fields()) {
2173       collect_inline_fields(recv->as_inline_klass(), field_array, pos);
2174     } else {
2175       field_array[pos++] = get_const_type(recv)->join_speculative(TypePtr::NOTNULL);
2176     }
2177   }
2178 
2179   int i = 0;
2180   while (pos < TypeFunc::Parms + arg_cnt) {
2181     ciType* type = sig->type_at(i);
2182     BasicType bt = type->basic_type();
2183 
2184     switch (bt) {
2185     case T_LONG:
2186       field_array[pos++] = TypeLong::LONG;
2187       field_array[pos++] = Type::HALF;
2188       break;
2189     case T_DOUBLE:
2190       field_array[pos++] = Type::DOUBLE;
2191       field_array[pos++] = Type::HALF;
2192       break;
2193     case T_OBJECT:
2194     case T_ARRAY:
2195     case T_FLOAT:
2196     case T_INT:
2197       field_array[pos++] = get_const_type(type);
2198       break;
2199     case T_BOOLEAN:
2200     case T_CHAR:
2201     case T_BYTE:
2202     case T_SHORT:
2203       field_array[pos++] = TypeInt::INT;
2204       break;
2205     case T_PRIMITIVE_OBJECT: {
2206       if (vt_fields_as_args && method->is_scalarized_arg(i + (method->is_static() ? 0 : 1))) {
2207         if (!sig->is_null_free_at(i)) {
2208           // InlineTypeNode::IsInit field used for null checking
2209           field_array[pos++] = get_const_basic_type(T_BOOLEAN);
2210         }
2211         collect_inline_fields(type->as_inline_klass(), field_array, pos);
2212       } else {
2213         field_array[pos++] = get_const_type(type)->join_speculative(sig->is_null_free_at(i) ? TypePtr::NOTNULL : TypePtr::BOTTOM);
2214       }
2215       break;
2216     }
2217     default:
2218       ShouldNotReachHere();
2219     }
2220     i++;
2221   }
2222   assert(pos == TypeFunc::Parms + arg_cnt, "wrong number of arguments");
2223 
2224   return (TypeTuple*)(new TypeTuple(TypeFunc::Parms + arg_cnt, field_array))->hashcons();
2225 }
2226 
2227 const TypeTuple *TypeTuple::make( uint cnt, const Type **fields ) {
2228   return (TypeTuple*)(new TypeTuple(cnt,fields))->hashcons();
2229 }
2230 
2231 //------------------------------fields-----------------------------------------
2232 // Subroutine call type with space allocated for argument types
2233 // Memory for Control, I_O, Memory, FramePtr, and ReturnAdr is allocated implicitly
2234 const Type **TypeTuple::fields( uint arg_cnt ) {
2235   const Type **flds = (const Type **)(Compile::current()->type_arena()->AmallocWords((TypeFunc::Parms+arg_cnt)*sizeof(Type*) ));
2236   flds[TypeFunc::Control  ] = Type::CONTROL;
2237   flds[TypeFunc::I_O      ] = Type::ABIO;
2238   flds[TypeFunc::Memory   ] = Type::MEMORY;
2239   flds[TypeFunc::FramePtr ] = TypeRawPtr::BOTTOM;
2240   flds[TypeFunc::ReturnAdr] = Type::RETURN_ADDRESS;
2241 
2242   return flds;
2243 }
2244 
2245 //------------------------------meet-------------------------------------------
2246 // Compute the MEET of two types.  It returns a new Type object.
2247 const Type *TypeTuple::xmeet( const Type *t ) const {
2248   // Perform a fast test for common case; meeting the same types together.
2249   if( this == t ) return this;  // Meeting same type-rep?
2250 
2251   // Current "this->_base" is Tuple
2252   switch (t->base()) {          // switch on original type
2253 
2254   case Bottom:                  // Ye Olde Default
2255     return t;
2256 
2257   default:                      // All else is a mistake
2258     typerr(t);
2259 
2260   case Tuple: {                 // Meeting 2 signatures?
2261     const TypeTuple *x = t->is_tuple();
2262     assert( _cnt == x->_cnt, "" );
2263     const Type **fields = (const Type **)(Compile::current()->type_arena()->AmallocWords( _cnt*sizeof(Type*) ));
2264     for( uint i=0; i<_cnt; i++ )
2265       fields[i] = field_at(i)->xmeet( x->field_at(i) );
2266     return TypeTuple::make(_cnt,fields);
2267   }
2268   case Top:
2269     break;
2270   }
2271   return this;                  // Return the double constant
2272 }
2273 
2274 //------------------------------xdual------------------------------------------
2275 // Dual: compute field-by-field dual
2276 const Type *TypeTuple::xdual() const {
2277   const Type **fields = (const Type **)(Compile::current()->type_arena()->AmallocWords( _cnt*sizeof(Type*) ));
2278   for( uint i=0; i<_cnt; i++ )
2279     fields[i] = _fields[i]->dual();
2280   return new TypeTuple(_cnt,fields);
2281 }
2282 
2283 //------------------------------eq---------------------------------------------
2284 // Structural equality check for Type representations
2285 bool TypeTuple::eq( const Type *t ) const {
2286   const TypeTuple *s = (const TypeTuple *)t;
2287   if (_cnt != s->_cnt)  return false;  // Unequal field counts
2288   for (uint i = 0; i < _cnt; i++)
2289     if (field_at(i) != s->field_at(i)) // POINTER COMPARE!  NO RECURSION!
2290       return false;             // Missed
2291   return true;
2292 }
2293 
2294 //------------------------------hash-------------------------------------------
2295 // Type-specific hashing function.
2296 int TypeTuple::hash(void) const {
2297   intptr_t sum = _cnt;
2298   for( uint i=0; i<_cnt; i++ )
2299     sum += (intptr_t)_fields[i];     // Hash on pointers directly
2300   return sum;
2301 }
2302 
2303 //------------------------------dump2------------------------------------------
2304 // Dump signature Type
2305 #ifndef PRODUCT
2306 void TypeTuple::dump2( Dict &d, uint depth, outputStream *st ) const {
2307   st->print("{");
2308   if( !depth || d[this] ) {     // Check for recursive print
2309     st->print("...}");
2310     return;
2311   }
2312   d.Insert((void*)this, (void*)this);   // Stop recursion
2313   if( _cnt ) {
2314     uint i;
2315     for( i=0; i<_cnt-1; i++ ) {
2316       st->print("%d:", i);
2317       _fields[i]->dump2(d, depth-1, st);
2318       st->print(", ");
2319     }
2320     st->print("%d:", i);
2321     _fields[i]->dump2(d, depth-1, st);
2322   }
2323   st->print("}");
2324 }
2325 #endif
2326 
2327 //------------------------------singleton--------------------------------------
2328 // TRUE if Type is a singleton type, FALSE otherwise.   Singletons are simple
2329 // constants (Ldi nodes).  Singletons are integer, float or double constants
2330 // or a single symbol.
2331 bool TypeTuple::singleton(void) const {
2332   return false;                 // Never a singleton
2333 }
2334 
2335 bool TypeTuple::empty(void) const {
2336   for( uint i=0; i<_cnt; i++ ) {
2337     if (_fields[i]->empty())  return true;
2338   }
2339   return false;
2340 }
2341 
2342 //=============================================================================
2343 // Convenience common pre-built types.
2344 
2345 inline const TypeInt* normalize_array_size(const TypeInt* size) {
2346   // Certain normalizations keep us sane when comparing types.
2347   // We do not want arrayOop variables to differ only by the wideness
2348   // of their index types.  Pick minimum wideness, since that is the
2349   // forced wideness of small ranges anyway.
2350   if (size->_widen != Type::WidenMin)
2351     return TypeInt::make(size->_lo, size->_hi, Type::WidenMin);
2352   else
2353     return size;
2354 }
2355 
2356 //------------------------------make-------------------------------------------
2357 const TypeAry* TypeAry::make(const Type* elem, const TypeInt* size, bool stable,
2358                              bool not_flat, bool not_null_free) {
2359   if (UseCompressedOops && elem->isa_oopptr()) {
2360     elem = elem->make_narrowoop();
2361   }
2362   size = normalize_array_size(size);
2363   return (TypeAry*)(new TypeAry(elem, size, stable, not_flat, not_null_free))->hashcons();
2364 }
2365 
2366 //------------------------------meet-------------------------------------------
2367 // Compute the MEET of two types.  It returns a new Type object.
2368 const Type *TypeAry::xmeet( const Type *t ) const {
2369   // Perform a fast test for common case; meeting the same types together.
2370   if( this == t ) return this;  // Meeting same type-rep?
2371 
2372   // Current "this->_base" is Ary
2373   switch (t->base()) {          // switch on original type
2374 
2375   case Bottom:                  // Ye Olde Default
2376     return t;
2377 
2378   default:                      // All else is a mistake
2379     typerr(t);
2380 
2381   case Array: {                 // Meeting 2 arrays?
2382     const TypeAry *a = t->is_ary();
2383     return TypeAry::make(_elem->meet_speculative(a->_elem),
2384                          _size->xmeet(a->_size)->is_int(),
2385                          _stable && a->_stable,
2386                          _not_flat && a->_not_flat,
2387                          _not_null_free && a->_not_null_free);
2388   }
2389   case Top:
2390     break;
2391   }
2392   return this;                  // Return the double constant
2393 }
2394 
2395 //------------------------------xdual------------------------------------------
2396 // Dual: compute field-by-field dual
2397 const Type *TypeAry::xdual() const {
2398   const TypeInt* size_dual = _size->dual()->is_int();
2399   size_dual = normalize_array_size(size_dual);
2400   return new TypeAry(_elem->dual(), size_dual, !_stable, !_not_flat, !_not_null_free);
2401 }
2402 
2403 //------------------------------eq---------------------------------------------
2404 // Structural equality check for Type representations
2405 bool TypeAry::eq( const Type *t ) const {
2406   const TypeAry *a = (const TypeAry*)t;
2407   return _elem == a->_elem &&
2408     _stable == a->_stable &&
2409     _size == a->_size &&
2410     _not_flat == a->_not_flat &&
2411     _not_null_free == a->_not_null_free;
2412 
2413 }
2414 
2415 //------------------------------hash-------------------------------------------
2416 // Type-specific hashing function.
2417 int TypeAry::hash(void) const {
2418   return (intptr_t)_elem + (intptr_t)_size + (_stable ? 43 : 0);
2419 }
2420 
2421 /**
2422  * Return same type without a speculative part in the element
2423  */
2424 const TypeAry* TypeAry::remove_speculative() const {
2425   return make(_elem->remove_speculative(), _size, _stable, _not_flat, _not_null_free);
2426 }
2427 
2428 /**
2429  * Return same type with cleaned up speculative part of element
2430  */
2431 const Type* TypeAry::cleanup_speculative() const {
2432   return make(_elem->cleanup_speculative(), _size, _stable, _not_flat, _not_null_free);
2433 }
2434 
2435 /**
2436  * Return same type but with a different inline depth (used for speculation)
2437  *
2438  * @param depth  depth to meet with
2439  */
2440 const TypePtr* TypePtr::with_inline_depth(int depth) const {
2441   if (!UseInlineDepthForSpeculativeTypes) {
2442     return this;
2443   }
2444   return make(AnyPtr, _ptr, _offset, _speculative, depth);
2445 }
2446 
2447 //----------------------interface_vs_oop---------------------------------------
2448 #ifdef ASSERT
2449 bool TypeAry::interface_vs_oop(const Type *t) const {
2450   const TypeAry* t_ary = t->is_ary();
2451   if (t_ary) {
2452     const TypePtr* this_ptr = _elem->make_ptr(); // In case we have narrow_oops
2453     const TypePtr*    t_ptr = t_ary->_elem->make_ptr();
2454     if(this_ptr != NULL && t_ptr != NULL) {
2455       return this_ptr->interface_vs_oop(t_ptr);
2456     }
2457   }
2458   return false;
2459 }
2460 #endif
2461 
2462 //------------------------------dump2------------------------------------------
2463 #ifndef PRODUCT
2464 void TypeAry::dump2( Dict &d, uint depth, outputStream *st ) const {
2465   if (_stable)  st->print("stable:");
2466   if (Verbose) {
2467     if (_not_flat) st->print("not flat:");
2468     if (_not_null_free) st->print("not null free:");
2469   }
2470   _elem->dump2(d, depth, st);
2471   st->print("[");
2472   _size->dump2(d, depth, st);
2473   st->print("]");
2474 }
2475 #endif
2476 
2477 //------------------------------singleton--------------------------------------
2478 // TRUE if Type is a singleton type, FALSE otherwise.   Singletons are simple
2479 // constants (Ldi nodes).  Singletons are integer, float or double constants
2480 // or a single symbol.
2481 bool TypeAry::singleton(void) const {
2482   return false;                 // Never a singleton
2483 }
2484 
2485 bool TypeAry::empty(void) const {
2486   return _elem->empty() || _size->empty();
2487 }
2488 
2489 //--------------------------ary_must_be_exact----------------------------------
2490 bool TypeAry::ary_must_be_exact() const {
2491   // This logic looks at the element type of an array, and returns true
2492   // if the element type is either a primitive or a final instance class.
2493   // In such cases, an array built on this ary must have no subclasses.
2494   if (_elem == BOTTOM)      return false;  // general array not exact
2495   if (_elem == TOP   )      return false;  // inverted general array not exact
2496   const TypeOopPtr*  toop = NULL;
2497   if (UseCompressedOops && _elem->isa_narrowoop()) {
2498     toop = _elem->make_ptr()->isa_oopptr();
2499   } else {
2500     toop = _elem->isa_oopptr();
2501   }
2502   if (!toop)                return true;   // a primitive type, like int
2503   ciKlass* tklass = toop->klass();
2504   if (tklass == NULL)       return false;  // unloaded class
2505   if (!tklass->is_loaded()) return false;  // unloaded class
2506   const TypeInstPtr* tinst;
2507   if (_elem->isa_narrowoop())
2508     tinst = _elem->make_ptr()->isa_instptr();
2509   else
2510     tinst = _elem->isa_instptr();
2511   if (tinst) {
2512     if (tklass->as_instance_klass()->is_final()) {
2513       // Even if MyValue is exact, [LMyValue is not exact due to [QMyValue <: [LMyValue.
2514       if (tinst->is_inlinetypeptr() && (tinst->ptr() == TypePtr::BotPTR || tinst->ptr() == TypePtr::TopPTR)) {
2515         return false;
2516       }
2517       return true;
2518     }
2519     return false;
2520   }
2521   const TypeAryPtr*  tap;
2522   if (_elem->isa_narrowoop())
2523     tap = _elem->make_ptr()->isa_aryptr();
2524   else
2525     tap = _elem->isa_aryptr();
2526   if (tap)
2527     return tap->ary()->ary_must_be_exact();
2528   return false;
2529 }
2530 
2531 //==============================TypeInlineType=======================================
2532 
2533 const TypeInlineType* TypeInlineType::BOTTOM;
2534 
2535 //------------------------------make-------------------------------------------
2536 const TypeInlineType* TypeInlineType::make(ciInlineKlass* vk, bool larval) {
2537   return (TypeInlineType*)(new TypeInlineType(vk, larval))->hashcons();
2538 }
2539 
2540 //------------------------------meet-------------------------------------------
2541 // Compute the MEET of two types.  It returns a new Type object.
2542 const Type* TypeInlineType::xmeet(const Type* t) const {
2543   // Perform a fast test for common case; meeting the same types together.
2544   if(this == t) return this;  // Meeting same type-rep?
2545 
2546   // Current "this->_base" is InlineType
2547   switch (t->base()) {          // switch on original type
2548 
2549   case Int:
2550   case Long:
2551   case FloatTop:
2552   case FloatCon:
2553   case FloatBot:
2554   case DoubleTop:
2555   case DoubleCon:
2556   case DoubleBot:
2557   case NarrowKlass:
2558   case Bottom:
2559     return Type::BOTTOM;
2560 
2561   case OopPtr:
2562   case MetadataPtr:
2563   case KlassPtr:
2564   case RawPtr:
2565   case AnyPtr:
2566     return TypePtr::BOTTOM;
2567 
2568   case Top:
2569     return this;
2570 
2571   case NarrowOop: {
2572     const Type* res = t->make_ptr()->xmeet(this);
2573     if (res->isa_ptr()) {
2574       return res->make_narrowoop();
2575     }
2576     return res;
2577   }
2578 
2579   case InstKlassPtr:
2580   case AryKlassPtr:
2581   case AryPtr:
2582   case InstPtr: {
2583     return t->xmeet(this);
2584   }
2585 
2586   case InlineType: {
2587     // All inline types inherit from Object
2588     const TypeInlineType* other = t->is_inlinetype();
2589     if (_vk == NULL) {
2590       return this;
2591     } else if (other->_vk == NULL) {
2592       return other;
2593     } else if (_vk == other->_vk) {
2594       if (_larval == other->_larval ||
2595           !_larval) {
2596         return this;
2597       } else {
2598         return t;
2599       }
2600     }
2601     return TypeInstPtr::NOTNULL;
2602   }
2603 
2604   default:                      // All else is a mistake
2605     typerr(t);
2606 
2607   }
2608   return this;
2609 }
2610 
2611 //------------------------------xdual------------------------------------------
2612 const Type* TypeInlineType::xdual() const {
2613   return this;
2614 }
2615 
2616 //------------------------------eq---------------------------------------------
2617 // Structural equality check for Type representations
2618 bool TypeInlineType::eq(const Type* t) const {
2619   const TypeInlineType* vt = t->is_inlinetype();
2620   return (_vk == vt->inline_klass() && _larval == vt->larval());
2621 }
2622 
2623 //------------------------------hash-------------------------------------------
2624 // Type-specific hashing function.
2625 int TypeInlineType::hash(void) const {
2626   return (intptr_t)_vk;
2627 }
2628 
2629 //------------------------------singleton--------------------------------------
2630 // TRUE if Type is a singleton type, FALSE otherwise. Singletons are simple constants.
2631 bool TypeInlineType::singleton(void) const {
2632   return false;
2633 }
2634 
2635 //------------------------------empty------------------------------------------
2636 // TRUE if Type is a type with no values, FALSE otherwise.
2637 bool TypeInlineType::empty(void) const {
2638   return false;
2639 }
2640 
2641 //------------------------------dump2------------------------------------------
2642 #ifndef PRODUCT
2643 void TypeInlineType::dump2(Dict &d, uint depth, outputStream* st) const {
2644   if (_vk == NULL) {
2645     st->print("BOTTOM inlinetype");
2646     return;
2647   }
2648   int count = _vk->nof_declared_nonstatic_fields();
2649   st->print("inlinetype[%d]:{", count);
2650   st->print("%s", count != 0 ? _vk->declared_nonstatic_field_at(0)->type()->name() : "empty");
2651   for (int i = 1; i < count; ++i) {
2652     st->print(", %s", _vk->declared_nonstatic_field_at(i)->type()->name());
2653   }
2654   st->print("}%s", _larval?" : larval":"");
2655 }
2656 #endif
2657 
2658 //==============================TypeVect=======================================
2659 // Convenience common pre-built types.
2660 const TypeVect *TypeVect::VECTA = NULL; // vector length agnostic
2661 const TypeVect *TypeVect::VECTS = NULL; //  32-bit vectors
2662 const TypeVect *TypeVect::VECTD = NULL; //  64-bit vectors
2663 const TypeVect *TypeVect::VECTX = NULL; // 128-bit vectors
2664 const TypeVect *TypeVect::VECTY = NULL; // 256-bit vectors
2665 const TypeVect *TypeVect::VECTZ = NULL; // 512-bit vectors
2666 const TypeVect *TypeVect::VECTMASK = NULL; // predicate/mask vector
2667 
2668 //------------------------------make-------------------------------------------
2669 const TypeVect* TypeVect::make(const Type *elem, uint length, bool is_mask) {
2670   if (is_mask) {
2671     return makemask(elem, length);
2672   }
2673   BasicType elem_bt = elem->array_element_basic_type();
2674   assert(is_java_primitive(elem_bt), "only primitive types in vector");
2675   assert(Matcher::vector_size_supported(elem_bt, length), "length in range");
2676   int size = length * type2aelembytes(elem_bt);
2677   switch (Matcher::vector_ideal_reg(size)) {
2678   case Op_VecA:
2679     return (TypeVect*)(new TypeVectA(elem, length))->hashcons();
2680   case Op_VecS:
2681     return (TypeVect*)(new TypeVectS(elem, length))->hashcons();
2682   case Op_RegL:
2683   case Op_VecD:
2684   case Op_RegD:
2685     return (TypeVect*)(new TypeVectD(elem, length))->hashcons();
2686   case Op_VecX:
2687     return (TypeVect*)(new TypeVectX(elem, length))->hashcons();
2688   case Op_VecY:
2689     return (TypeVect*)(new TypeVectY(elem, length))->hashcons();
2690   case Op_VecZ:
2691     return (TypeVect*)(new TypeVectZ(elem, length))->hashcons();
2692   }
2693  ShouldNotReachHere();
2694   return NULL;
2695 }
2696 
2697 const TypeVect *TypeVect::makemask(const Type* elem, uint length) {
2698   BasicType elem_bt = elem->array_element_basic_type();
2699   if (Matcher::has_predicated_vectors() &&
2700       Matcher::match_rule_supported_vector_masked(Op_VectorLoadMask, length, elem_bt)) {
2701     return TypeVectMask::make(elem, length);
2702   } else {
2703     return make(elem, length);
2704   }
2705 }
2706 
2707 //------------------------------meet-------------------------------------------
2708 // Compute the MEET of two types.  It returns a new Type object.
2709 const Type *TypeVect::xmeet( const Type *t ) const {
2710   // Perform a fast test for common case; meeting the same types together.
2711   if( this == t ) return this;  // Meeting same type-rep?
2712 
2713   // Current "this->_base" is Vector
2714   switch (t->base()) {          // switch on original type
2715 
2716   case Bottom:                  // Ye Olde Default
2717     return t;
2718 
2719   default:                      // All else is a mistake
2720     typerr(t);
2721   case VectorMask: {
2722     const TypeVectMask* v = t->is_vectmask();
2723     assert(  base() == v->base(), "");
2724     assert(length() == v->length(), "");
2725     assert(element_basic_type() == v->element_basic_type(), "");
2726     return TypeVect::makemask(_elem->xmeet(v->_elem), _length);
2727   }
2728   case VectorA:
2729   case VectorS:
2730   case VectorD:
2731   case VectorX:
2732   case VectorY:
2733   case VectorZ: {                // Meeting 2 vectors?
2734     const TypeVect* v = t->is_vect();
2735     assert(  base() == v->base(), "");
2736     assert(length() == v->length(), "");
2737     assert(element_basic_type() == v->element_basic_type(), "");
2738     return TypeVect::make(_elem->xmeet(v->_elem), _length);
2739   }
2740   case Top:
2741     break;
2742   }
2743   return this;
2744 }
2745 
2746 //------------------------------xdual------------------------------------------
2747 // Dual: compute field-by-field dual
2748 const Type *TypeVect::xdual() const {
2749   return new TypeVect(base(), _elem->dual(), _length);
2750 }
2751 
2752 //------------------------------eq---------------------------------------------
2753 // Structural equality check for Type representations
2754 bool TypeVect::eq(const Type *t) const {
2755   const TypeVect *v = t->is_vect();
2756   return (_elem == v->_elem) && (_length == v->_length);
2757 }
2758 
2759 //------------------------------hash-------------------------------------------
2760 // Type-specific hashing function.
2761 int TypeVect::hash(void) const {
2762   return (intptr_t)_elem + (intptr_t)_length;
2763 }
2764 
2765 //------------------------------singleton--------------------------------------
2766 // TRUE if Type is a singleton type, FALSE otherwise.   Singletons are simple
2767 // constants (Ldi nodes).  Vector is singleton if all elements are the same
2768 // constant value (when vector is created with Replicate code).
2769 bool TypeVect::singleton(void) const {
2770 // There is no Con node for vectors yet.
2771 //  return _elem->singleton();
2772   return false;
2773 }
2774 
2775 bool TypeVect::empty(void) const {
2776   return _elem->empty();
2777 }
2778 
2779 //------------------------------dump2------------------------------------------
2780 #ifndef PRODUCT
2781 void TypeVect::dump2(Dict &d, uint depth, outputStream *st) const {
2782   switch (base()) {
2783   case VectorA:
2784     st->print("vectora["); break;
2785   case VectorS:
2786     st->print("vectors["); break;
2787   case VectorD:
2788     st->print("vectord["); break;
2789   case VectorX:
2790     st->print("vectorx["); break;
2791   case VectorY:
2792     st->print("vectory["); break;
2793   case VectorZ:
2794     st->print("vectorz["); break;
2795   case VectorMask:
2796     st->print("vectormask["); break;
2797   default:
2798     ShouldNotReachHere();
2799   }
2800   st->print("%d]:{", _length);
2801   _elem->dump2(d, depth, st);
2802   st->print("}");
2803 }
2804 #endif
2805 
2806 bool TypeVectMask::eq(const Type *t) const {
2807   const TypeVectMask *v = t->is_vectmask();
2808   return (element_type() == v->element_type()) && (length() == v->length());
2809 }
2810 
2811 const Type *TypeVectMask::xdual() const {
2812   return new TypeVectMask(element_type()->dual(), length());
2813 }
2814 
2815 const TypeVectMask *TypeVectMask::make(const BasicType elem_bt, uint length) {
2816   return make(get_const_basic_type(elem_bt), length);
2817 }
2818 
2819 const TypeVectMask *TypeVectMask::make(const Type* elem, uint length) {
2820   const TypeVectMask* mtype = Matcher::predicate_reg_type(elem, length);
2821   return (TypeVectMask*) const_cast<TypeVectMask*>(mtype)->hashcons();
2822 }
2823 
2824 //=============================================================================
2825 // Convenience common pre-built types.
2826 const TypePtr *TypePtr::NULL_PTR;
2827 const TypePtr *TypePtr::NOTNULL;
2828 const TypePtr *TypePtr::BOTTOM;
2829 
2830 //------------------------------meet-------------------------------------------
2831 // Meet over the PTR enum
2832 const TypePtr::PTR TypePtr::ptr_meet[TypePtr::lastPTR][TypePtr::lastPTR] = {
2833   //              TopPTR,    AnyNull,   Constant, Null,   NotNull, BotPTR,
2834   { /* Top     */ TopPTR,    AnyNull,   Constant, Null,   NotNull, BotPTR,},
2835   { /* AnyNull */ AnyNull,   AnyNull,   Constant, BotPTR, NotNull, BotPTR,},
2836   { /* Constant*/ Constant,  Constant,  Constant, BotPTR, NotNull, BotPTR,},
2837   { /* Null    */ Null,      BotPTR,    BotPTR,   Null,   BotPTR,  BotPTR,},
2838   { /* NotNull */ NotNull,   NotNull,   NotNull,  BotPTR, NotNull, BotPTR,},
2839   { /* BotPTR  */ BotPTR,    BotPTR,    BotPTR,   BotPTR, BotPTR,  BotPTR,}
2840 };
2841 
2842 //------------------------------make-------------------------------------------
2843 const TypePtr* TypePtr::make(TYPES t, enum PTR ptr, Offset offset, const TypePtr* speculative, int inline_depth) {
2844   return (TypePtr*)(new TypePtr(t,ptr,offset, speculative, inline_depth))->hashcons();
2845 }
2846 
2847 //------------------------------cast_to_ptr_type-------------------------------
2848 const TypePtr* TypePtr::cast_to_ptr_type(PTR ptr) const {
2849   assert(_base == AnyPtr, "subclass must override cast_to_ptr_type");
2850   if( ptr == _ptr ) return this;
2851   return make(_base, ptr, _offset, _speculative, _inline_depth);
2852 }
2853 
2854 //------------------------------get_con----------------------------------------
2855 intptr_t TypePtr::get_con() const {
2856   assert( _ptr == Null, "" );
2857   return offset();
2858 }
2859 
2860 //------------------------------meet-------------------------------------------
2861 // Compute the MEET of two types.  It returns a new Type object.
2862 const Type *TypePtr::xmeet(const Type *t) const {
2863   const Type* res = xmeet_helper(t);
2864   if (res->isa_ptr() == NULL) {
2865     return res;
2866   }
2867 
2868   const TypePtr* res_ptr = res->is_ptr();
2869   if (res_ptr->speculative() != NULL) {
2870     // type->speculative() == NULL means that speculation is no better
2871     // than type, i.e. type->speculative() == type. So there are 2
2872     // ways to represent the fact that we have no useful speculative
2873     // data and we should use a single one to be able to test for
2874     // equality between types. Check whether type->speculative() ==
2875     // type and set speculative to NULL if it is the case.
2876     if (res_ptr->remove_speculative() == res_ptr->speculative()) {
2877       return res_ptr->remove_speculative();
2878     }
2879   }
2880 
2881   return res;
2882 }
2883 
2884 const Type *TypePtr::xmeet_helper(const Type *t) const {
2885   // Perform a fast test for common case; meeting the same types together.
2886   if( this == t ) return this;  // Meeting same type-rep?
2887 
2888   // Current "this->_base" is AnyPtr
2889   switch (t->base()) {          // switch on original type
2890   case Int:                     // Mixing ints & oops happens when javac
2891   case Long:                    // reuses local variables
2892   case FloatTop:
2893   case FloatCon:
2894   case FloatBot:
2895   case DoubleTop:
2896   case DoubleCon:
2897   case DoubleBot:
2898   case NarrowOop:
2899   case NarrowKlass:
2900   case Bottom:                  // Ye Olde Default
2901     return Type::BOTTOM;
2902   case Top:
2903     return this;
2904 
2905   case AnyPtr: {                // Meeting to AnyPtrs
2906     const TypePtr *tp = t->is_ptr();
2907     const TypePtr* speculative = xmeet_speculative(tp);
2908     int depth = meet_inline_depth(tp->inline_depth());
2909     return make(AnyPtr, meet_ptr(tp->ptr()), meet_offset(tp->offset()), speculative, depth);
2910   }
2911   case RawPtr:                  // For these, flip the call around to cut down
2912   case OopPtr:
2913   case InstPtr:                 // on the cases I have to handle.
2914   case AryPtr:
2915   case MetadataPtr:
2916   case KlassPtr:
2917   case InstKlassPtr:
2918   case AryKlassPtr:
2919   case InlineType:
2920     return t->xmeet(this);      // Call in reverse direction
2921   default:                      // All else is a mistake
2922     typerr(t);
2923 
2924   }
2925   return this;
2926 }
2927 
2928 //------------------------------meet_offset------------------------------------
2929 Type::Offset TypePtr::meet_offset(int offset) const {
2930   return _offset.meet(Offset(offset));
2931 }
2932 
2933 //------------------------------dual_offset------------------------------------
2934 Type::Offset TypePtr::dual_offset() const {
2935   return _offset.dual();
2936 }
2937 
2938 //------------------------------xdual------------------------------------------
2939 // Dual: compute field-by-field dual
2940 const TypePtr::PTR TypePtr::ptr_dual[TypePtr::lastPTR] = {
2941   BotPTR, NotNull, Constant, Null, AnyNull, TopPTR
2942 };
2943 const Type *TypePtr::xdual() const {
2944   return new TypePtr(AnyPtr, dual_ptr(), dual_offset(), dual_speculative(), dual_inline_depth());
2945 }
2946 
2947 //------------------------------xadd_offset------------------------------------
2948 Type::Offset TypePtr::xadd_offset(intptr_t offset) const {
2949   return _offset.add(offset);
2950 }
2951 
2952 //------------------------------add_offset-------------------------------------
2953 const TypePtr *TypePtr::add_offset( intptr_t offset ) const {
2954   return make(AnyPtr, _ptr, xadd_offset(offset), _speculative, _inline_depth);
2955 }
2956 
2957 const TypePtr *TypePtr::with_offset(intptr_t offset) const {
2958   return make(AnyPtr, _ptr, Offset(offset), _speculative, _inline_depth);
2959 }
2960 
2961 //------------------------------eq---------------------------------------------
2962 // Structural equality check for Type representations
2963 bool TypePtr::eq( const Type *t ) const {
2964   const TypePtr *a = (const TypePtr*)t;
2965   return _ptr == a->ptr() && _offset == a->_offset && eq_speculative(a) && _inline_depth == a->_inline_depth;
2966 }
2967 
2968 //------------------------------hash-------------------------------------------
2969 // Type-specific hashing function.
2970 int TypePtr::hash(void) const {
2971   return java_add(java_add((jint)_ptr, (jint)offset()), java_add((jint)hash_speculative(), (jint)_inline_depth));
2972 ;
2973 }
2974 
2975 /**
2976  * Return same type without a speculative part
2977  */
2978 const TypePtr* TypePtr::remove_speculative() const {
2979   if (_speculative == NULL) {
2980     return this;
2981   }
2982   assert(_inline_depth == InlineDepthTop || _inline_depth == InlineDepthBottom, "non speculative type shouldn't have inline depth");
2983   return make(AnyPtr, _ptr, _offset, NULL, _inline_depth);
2984 }
2985 
2986 /**
2987  * Return same type but drop speculative part if we know we won't use
2988  * it
2989  */
2990 const Type* TypePtr::cleanup_speculative() const {
2991   if (speculative() == NULL) {
2992     return this;
2993   }
2994   const Type* no_spec = remove_speculative();
2995   // If this is NULL_PTR then we don't need the speculative type
2996   // (with_inline_depth in case the current type inline depth is
2997   // InlineDepthTop)
2998   if (no_spec == NULL_PTR->with_inline_depth(inline_depth())) {
2999     return no_spec;
3000   }
3001   if (above_centerline(speculative()->ptr())) {
3002     return no_spec;
3003   }
3004   const TypeOopPtr* spec_oopptr = speculative()->isa_oopptr();
3005   // If the speculative may be null and is an inexact klass then it
3006   // doesn't help
3007   if (speculative() != TypePtr::NULL_PTR && speculative()->maybe_null() &&
3008       (spec_oopptr == NULL || !spec_oopptr->klass_is_exact())) {
3009     return no_spec;
3010   }
3011   return this;
3012 }
3013 
3014 /**
3015  * dual of the speculative part of the type
3016  */
3017 const TypePtr* TypePtr::dual_speculative() const {
3018   if (_speculative == NULL) {
3019     return NULL;
3020   }
3021   return _speculative->dual()->is_ptr();
3022 }
3023 
3024 /**
3025  * meet of the speculative parts of 2 types
3026  *
3027  * @param other  type to meet with
3028  */
3029 const TypePtr* TypePtr::xmeet_speculative(const TypePtr* other) const {
3030   bool this_has_spec = (_speculative != NULL);
3031   bool other_has_spec = (other->speculative() != NULL);
3032 
3033   if (!this_has_spec && !other_has_spec) {
3034     return NULL;
3035   }
3036 
3037   // If we are at a point where control flow meets and one branch has
3038   // a speculative type and the other has not, we meet the speculative
3039   // type of one branch with the actual type of the other. If the
3040   // actual type is exact and the speculative is as well, then the
3041   // result is a speculative type which is exact and we can continue
3042   // speculation further.
3043   const TypePtr* this_spec = _speculative;
3044   const TypePtr* other_spec = other->speculative();
3045 
3046   if (!this_has_spec) {
3047     this_spec = this;
3048   }
3049 
3050   if (!other_has_spec) {
3051     other_spec = other;
3052   }
3053 
3054   return this_spec->meet(other_spec)->is_ptr();
3055 }
3056 
3057 /**
3058  * dual of the inline depth for this type (used for speculation)
3059  */
3060 int TypePtr::dual_inline_depth() const {
3061   return -inline_depth();
3062 }
3063 
3064 /**
3065  * meet of 2 inline depths (used for speculation)
3066  *
3067  * @param depth  depth to meet with
3068  */
3069 int TypePtr::meet_inline_depth(int depth) const {
3070   return MAX2(inline_depth(), depth);
3071 }
3072 
3073 /**
3074  * Are the speculative parts of 2 types equal?
3075  *
3076  * @param other  type to compare this one to
3077  */
3078 bool TypePtr::eq_speculative(const TypePtr* other) const {
3079   if (_speculative == NULL || other->speculative() == NULL) {
3080     return _speculative == other->speculative();
3081   }
3082 
3083   if (_speculative->base() != other->speculative()->base()) {
3084     return false;
3085   }
3086 
3087   return _speculative->eq(other->speculative());
3088 }
3089 
3090 /**
3091  * Hash of the speculative part of the type
3092  */
3093 int TypePtr::hash_speculative() const {
3094   if (_speculative == NULL) {
3095     return 0;
3096   }
3097 
3098   return _speculative->hash();
3099 }
3100 
3101 /**
3102  * add offset to the speculative part of the type
3103  *
3104  * @param offset  offset to add
3105  */
3106 const TypePtr* TypePtr::add_offset_speculative(intptr_t offset) const {
3107   if (_speculative == NULL) {
3108     return NULL;
3109   }
3110   return _speculative->add_offset(offset)->is_ptr();
3111 }
3112 
3113 const TypePtr* TypePtr::with_offset_speculative(intptr_t offset) const {
3114   if (_speculative == NULL) {
3115     return NULL;
3116   }
3117   return _speculative->with_offset(offset)->is_ptr();
3118 }
3119 
3120 /**
3121  * return exact klass from the speculative type if there's one
3122  */
3123 ciKlass* TypePtr::speculative_type() const {
3124   if (_speculative != NULL && _speculative->isa_oopptr()) {
3125     const TypeOopPtr* speculative = _speculative->join(this)->is_oopptr();
3126     if (speculative->klass_is_exact()) {
3127       return speculative->klass();
3128     }
3129   }
3130   return NULL;
3131 }
3132 
3133 /**
3134  * return true if speculative type may be null
3135  */
3136 bool TypePtr::speculative_maybe_null() const {
3137   if (_speculative != NULL) {
3138     const TypePtr* speculative = _speculative->join(this)->is_ptr();
3139     return speculative->maybe_null();
3140   }
3141   return true;
3142 }
3143 
3144 bool TypePtr::speculative_always_null() const {
3145   if (_speculative != NULL) {
3146     const TypePtr* speculative = _speculative->join(this)->is_ptr();
3147     return speculative == TypePtr::NULL_PTR;
3148   }
3149   return false;
3150 }
3151 
3152 /**
3153  * Same as TypePtr::speculative_type() but return the klass only if
3154  * the speculative tells us is not null
3155  */
3156 ciKlass* TypePtr::speculative_type_not_null() const {
3157   if (speculative_maybe_null()) {
3158     return NULL;
3159   }
3160   return speculative_type();
3161 }
3162 
3163 /**
3164  * Check whether new profiling would improve speculative type
3165  *
3166  * @param   exact_kls    class from profiling
3167  * @param   inline_depth inlining depth of profile point
3168  *
3169  * @return  true if type profile is valuable
3170  */
3171 bool TypePtr::would_improve_type(ciKlass* exact_kls, int inline_depth) const {
3172   // no profiling?
3173   if (exact_kls == NULL) {
3174     return false;
3175   }
3176   if (speculative() == TypePtr::NULL_PTR) {
3177     return false;
3178   }
3179   // no speculative type or non exact speculative type?
3180   if (speculative_type() == NULL) {
3181     return true;
3182   }
3183   // If the node already has an exact speculative type keep it,
3184   // unless it was provided by profiling that is at a deeper
3185   // inlining level. Profiling at a higher inlining depth is
3186   // expected to be less accurate.
3187   if (_speculative->inline_depth() == InlineDepthBottom) {
3188     return false;
3189   }
3190   assert(_speculative->inline_depth() != InlineDepthTop, "can't do the comparison");
3191   return inline_depth < _speculative->inline_depth();
3192 }
3193 
3194 /**
3195  * Check whether new profiling would improve ptr (= tells us it is non
3196  * null)
3197  *
3198  * @param   ptr_kind always null or not null?
3199  *
3200  * @return  true if ptr profile is valuable
3201  */
3202 bool TypePtr::would_improve_ptr(ProfilePtrKind ptr_kind) const {
3203   // profiling doesn't tell us anything useful
3204   if (ptr_kind != ProfileAlwaysNull && ptr_kind != ProfileNeverNull) {
3205     return false;
3206   }
3207   // We already know this is not null
3208   if (!this->maybe_null()) {
3209     return false;
3210   }
3211   // We already know the speculative type cannot be null
3212   if (!speculative_maybe_null()) {
3213     return false;
3214   }
3215   // We already know this is always null
3216   if (this == TypePtr::NULL_PTR) {
3217     return false;
3218   }
3219   // We already know the speculative type is always null
3220   if (speculative_always_null()) {
3221     return false;
3222   }
3223   if (ptr_kind == ProfileAlwaysNull && speculative() != NULL && speculative()->isa_oopptr()) {
3224     return false;
3225   }
3226   return true;
3227 }
3228 
3229 //------------------------------dump2------------------------------------------
3230 const char *const TypePtr::ptr_msg[TypePtr::lastPTR] = {
3231   "TopPTR","AnyNull","Constant","NULL","NotNull","BotPTR"
3232 };
3233 
3234 #ifndef PRODUCT
3235 void TypePtr::dump2( Dict &d, uint depth, outputStream *st ) const {
3236   if( _ptr == Null ) st->print("NULL");
3237   else st->print("%s *", ptr_msg[_ptr]);
3238   _offset.dump2(st);
3239   dump_inline_depth(st);
3240   dump_speculative(st);
3241 }
3242 
3243 /**
3244  *dump the speculative part of the type
3245  */
3246 void TypePtr::dump_speculative(outputStream *st) const {
3247   if (_speculative != NULL) {
3248     st->print(" (speculative=");
3249     _speculative->dump_on(st);
3250     st->print(")");
3251   }
3252 }
3253 
3254 /**
3255  *dump the inline depth of the type
3256  */
3257 void TypePtr::dump_inline_depth(outputStream *st) const {
3258   if (_inline_depth != InlineDepthBottom) {
3259     if (_inline_depth == InlineDepthTop) {
3260       st->print(" (inline_depth=InlineDepthTop)");
3261     } else {
3262       st->print(" (inline_depth=%d)", _inline_depth);
3263     }
3264   }
3265 }
3266 #endif
3267 
3268 //------------------------------singleton--------------------------------------
3269 // TRUE if Type is a singleton type, FALSE otherwise.   Singletons are simple
3270 // constants
3271 bool TypePtr::singleton(void) const {
3272   // TopPTR, Null, AnyNull, Constant are all singletons
3273   return (_offset != Offset::bottom) && !below_centerline(_ptr);
3274 }
3275 
3276 bool TypePtr::empty(void) const {
3277   return (_offset == Offset::top) || above_centerline(_ptr);
3278 }
3279 
3280 //=============================================================================
3281 // Convenience common pre-built types.
3282 const TypeRawPtr *TypeRawPtr::BOTTOM;
3283 const TypeRawPtr *TypeRawPtr::NOTNULL;
3284 
3285 //------------------------------make-------------------------------------------
3286 const TypeRawPtr *TypeRawPtr::make( enum PTR ptr ) {
3287   assert( ptr != Constant, "what is the constant?" );
3288   assert( ptr != Null, "Use TypePtr for NULL" );
3289   return (TypeRawPtr*)(new TypeRawPtr(ptr,0))->hashcons();
3290 }
3291 
3292 const TypeRawPtr *TypeRawPtr::make( address bits ) {
3293   assert( bits, "Use TypePtr for NULL" );
3294   return (TypeRawPtr*)(new TypeRawPtr(Constant,bits))->hashcons();
3295 }
3296 
3297 //------------------------------cast_to_ptr_type-------------------------------
3298 const TypeRawPtr* TypeRawPtr::cast_to_ptr_type(PTR ptr) const {
3299   assert( ptr != Constant, "what is the constant?" );
3300   assert( ptr != Null, "Use TypePtr for NULL" );
3301   assert( _bits==0, "Why cast a constant address?");
3302   if( ptr == _ptr ) return this;
3303   return make(ptr);
3304 }
3305 
3306 //------------------------------get_con----------------------------------------
3307 intptr_t TypeRawPtr::get_con() const {
3308   assert( _ptr == Null || _ptr == Constant, "" );
3309   return (intptr_t)_bits;
3310 }
3311 
3312 //------------------------------meet-------------------------------------------
3313 // Compute the MEET of two types.  It returns a new Type object.
3314 const Type *TypeRawPtr::xmeet( const Type *t ) const {
3315   // Perform a fast test for common case; meeting the same types together.
3316   if( this == t ) return this;  // Meeting same type-rep?
3317 
3318   // Current "this->_base" is RawPtr
3319   switch( t->base() ) {         // switch on original type
3320   case Bottom:                  // Ye Olde Default
3321     return t;
3322   case Top:
3323     return this;
3324   case AnyPtr:                  // Meeting to AnyPtrs
3325     break;
3326   case RawPtr: {                // might be top, bot, any/not or constant
3327     enum PTR tptr = t->is_ptr()->ptr();
3328     enum PTR ptr = meet_ptr( tptr );
3329     if( ptr == Constant ) {     // Cannot be equal constants, so...
3330       if( tptr == Constant && _ptr != Constant)  return t;
3331       if( _ptr == Constant && tptr != Constant)  return this;
3332       ptr = NotNull;            // Fall down in lattice
3333     }
3334     return make( ptr );
3335   }
3336 
3337   case OopPtr:
3338   case InstPtr:
3339   case AryPtr:
3340   case MetadataPtr:
3341   case KlassPtr:
3342   case InstKlassPtr:
3343   case AryKlassPtr:
3344     return TypePtr::BOTTOM;     // Oop meet raw is not well defined
3345   default:                      // All else is a mistake
3346     typerr(t);
3347   }
3348 
3349   // Found an AnyPtr type vs self-RawPtr type
3350   const TypePtr *tp = t->is_ptr();
3351   switch (tp->ptr()) {
3352   case TypePtr::TopPTR:  return this;
3353   case TypePtr::BotPTR:  return t;
3354   case TypePtr::Null:
3355     if( _ptr == TypePtr::TopPTR ) return t;
3356     return TypeRawPtr::BOTTOM;
3357   case TypePtr::NotNull: return TypePtr::make(AnyPtr, meet_ptr(TypePtr::NotNull), tp->meet_offset(0), tp->speculative(), tp->inline_depth());
3358   case TypePtr::AnyNull:
3359     if( _ptr == TypePtr::Constant) return this;
3360     return make( meet_ptr(TypePtr::AnyNull) );
3361   default: ShouldNotReachHere();
3362   }
3363   return this;
3364 }
3365 
3366 //------------------------------xdual------------------------------------------
3367 // Dual: compute field-by-field dual
3368 const Type *TypeRawPtr::xdual() const {
3369   return new TypeRawPtr( dual_ptr(), _bits );
3370 }
3371 
3372 //------------------------------add_offset-------------------------------------
3373 const TypePtr* TypeRawPtr::add_offset(intptr_t offset) const {
3374   if( offset == OffsetTop ) return BOTTOM; // Undefined offset-> undefined pointer
3375   if( offset == OffsetBot ) return BOTTOM; // Unknown offset-> unknown pointer
3376   if( offset == 0 ) return this; // No change
3377   switch (_ptr) {
3378   case TypePtr::TopPTR:
3379   case TypePtr::BotPTR:
3380   case TypePtr::NotNull:
3381     return this;
3382   case TypePtr::Null:
3383   case TypePtr::Constant: {
3384     address bits = _bits+offset;
3385     if ( bits == 0 ) return TypePtr::NULL_PTR;
3386     return make( bits );
3387   }
3388   default:  ShouldNotReachHere();
3389   }
3390   return NULL;                  // Lint noise
3391 }
3392 
3393 //------------------------------eq---------------------------------------------
3394 // Structural equality check for Type representations
3395 bool TypeRawPtr::eq( const Type *t ) const {
3396   const TypeRawPtr *a = (const TypeRawPtr*)t;
3397   return _bits == a->_bits && TypePtr::eq(t);
3398 }
3399 
3400 //------------------------------hash-------------------------------------------
3401 // Type-specific hashing function.
3402 int TypeRawPtr::hash(void) const {
3403   return (intptr_t)_bits + TypePtr::hash();
3404 }
3405 
3406 //------------------------------dump2------------------------------------------
3407 #ifndef PRODUCT
3408 void TypeRawPtr::dump2( Dict &d, uint depth, outputStream *st ) const {
3409   if( _ptr == Constant )
3410     st->print(INTPTR_FORMAT, p2i(_bits));
3411   else
3412     st->print("rawptr:%s", ptr_msg[_ptr]);
3413 }
3414 #endif
3415 
3416 //=============================================================================
3417 // Convenience common pre-built type.
3418 const TypeOopPtr *TypeOopPtr::BOTTOM;
3419 
3420 //------------------------------TypeOopPtr-------------------------------------
3421 TypeOopPtr::TypeOopPtr(TYPES t, PTR ptr, ciKlass* k, bool xk, ciObject* o, Offset offset, Offset field_offset,
3422                        int instance_id, const TypePtr* speculative, int inline_depth)
3423   : TypePtr(t, ptr, offset, speculative, inline_depth),
3424     _const_oop(o), _klass(k),
3425     _klass_is_exact(xk),
3426     _is_ptr_to_narrowoop(false),
3427     _is_ptr_to_narrowklass(false),
3428     _is_ptr_to_boxed_value(false),
3429     _instance_id(instance_id) {
3430   if (Compile::current()->eliminate_boxing() && (t == InstPtr) &&
3431       (offset.get() > 0) && xk && (k != 0) && k->is_instance_klass()) {
3432     _is_ptr_to_boxed_value = k->as_instance_klass()->is_boxed_value_offset(offset.get());
3433   }
3434 #ifdef _LP64
3435   if (this->offset() > 0 || this->offset() == Type::OffsetTop || this->offset() == Type::OffsetBot) {
3436     if (this->offset() == oopDesc::klass_offset_in_bytes()) {
3437       _is_ptr_to_narrowklass = UseCompressedClassPointers;
3438     } else if (klass() == NULL) {
3439       // Array with unknown body type
3440       assert(this->isa_aryptr(), "only arrays without klass");
3441       _is_ptr_to_narrowoop = UseCompressedOops;
3442     } else if (UseCompressedOops && this->isa_aryptr() && this->offset() != arrayOopDesc::length_offset_in_bytes()) {
3443       if (klass()->is_obj_array_klass()) {
3444         _is_ptr_to_narrowoop = true;
3445       } else if (klass()->is_flat_array_klass() && field_offset != Offset::top && field_offset != Offset::bottom) {
3446         // Check if the field of the inline type array element contains oops
3447         ciInlineKlass* vk = klass()->as_flat_array_klass()->element_klass()->as_inline_klass();
3448         int foffset = field_offset.get() + vk->first_field_offset();
3449         ciField* field = vk->get_field_by_offset(foffset, false);
3450         assert(field != NULL, "missing field");
3451         BasicType bt = field->layout_type();
3452         _is_ptr_to_narrowoop = UseCompressedOops && is_reference_type(bt);
3453       }
3454     } else if (klass()->is_instance_klass()) {
3455       if (this->isa_klassptr()) {
3456         // Perm objects don't use compressed references
3457       } else if (_offset == Offset::bottom || _offset == Offset::top) {
3458         // unsafe access
3459         _is_ptr_to_narrowoop = UseCompressedOops;
3460       } else {
3461         assert(this->isa_instptr(), "must be an instance ptr.");
3462         if (klass() == ciEnv::current()->Class_klass() &&
3463             (this->offset() == java_lang_Class::klass_offset() ||
3464              this->offset() == java_lang_Class::array_klass_offset())) {
3465           // Special hidden fields from the Class.
3466           assert(this->isa_instptr(), "must be an instance ptr.");
3467           _is_ptr_to_narrowoop = false;
3468         } else if (klass() == ciEnv::current()->Class_klass() &&
3469                    this->offset() >= InstanceMirrorKlass::offset_of_static_fields()) {
3470           // Static fields
3471           ciField* field = NULL;
3472           if (const_oop() != NULL) {
3473             ciInstanceKlass* k = const_oop()->as_instance()->java_lang_Class_klass()->as_instance_klass();
3474             if (k->is_inlinetype() && this->offset() == k->as_inline_klass()->default_value_offset()) {
3475               // Special hidden field that contains the oop of the default inline type
3476               // basic_elem_type = T_PRIMITIVE_OBJECT;
3477              _is_ptr_to_narrowoop = UseCompressedOops;
3478             } else {
3479               field = k->get_field_by_offset(this->offset(), true);
3480               if (field != NULL) {
3481                 BasicType basic_elem_type = field->layout_type();
3482                 _is_ptr_to_narrowoop = UseCompressedOops && is_reference_type(basic_elem_type);
3483               } else {
3484                 // unsafe access
3485                 _is_ptr_to_narrowoop = UseCompressedOops;
3486               }
3487             }
3488           }
3489         } else {
3490           // Instance fields which contains a compressed oop references.
3491           ciInstanceKlass* ik = klass()->as_instance_klass();
3492           ciField* field = ik->get_field_by_offset(this->offset(), false);
3493           if (field != NULL) {
3494             BasicType basic_elem_type = field->layout_type();
3495             _is_ptr_to_narrowoop = UseCompressedOops && is_reference_type(basic_elem_type);
3496           } else if (klass()->equals(ciEnv::current()->Object_klass())) {
3497             // Compile::find_alias_type() cast exactness on all types to verify
3498             // that it does not affect alias type.
3499             _is_ptr_to_narrowoop = UseCompressedOops;
3500           } else {
3501             // Type for the copy start in LibraryCallKit::inline_native_clone().
3502             _is_ptr_to_narrowoop = UseCompressedOops;
3503           }
3504         }
3505       }
3506     }
3507   }
3508 #endif
3509 }
3510 
3511 //------------------------------make-------------------------------------------
3512 const TypeOopPtr *TypeOopPtr::make(PTR ptr, Offset offset, int instance_id,
3513                                    const TypePtr* speculative, int inline_depth) {
3514   assert(ptr != Constant, "no constant generic pointers");
3515   ciKlass*  k = Compile::current()->env()->Object_klass();
3516   bool      xk = false;
3517   ciObject* o = NULL;
3518   return (TypeOopPtr*)(new TypeOopPtr(OopPtr, ptr, k, xk, o, offset, Offset::bottom, instance_id, speculative, inline_depth))->hashcons();
3519 }
3520 
3521 
3522 //------------------------------cast_to_ptr_type-------------------------------
3523 const TypeOopPtr* TypeOopPtr::cast_to_ptr_type(PTR ptr) const {
3524   assert(_base == OopPtr, "subclass must override cast_to_ptr_type");
3525   if( ptr == _ptr ) return this;
3526   return make(ptr, _offset, _instance_id, _speculative, _inline_depth);
3527 }
3528 
3529 //-----------------------------cast_to_instance_id----------------------------
3530 const TypeOopPtr *TypeOopPtr::cast_to_instance_id(int instance_id) const {
3531   // There are no instances of a general oop.
3532   // Return self unchanged.
3533   return this;
3534 }
3535 
3536 //-----------------------------cast_to_exactness-------------------------------
3537 const TypeOopPtr* TypeOopPtr::cast_to_exactness(bool klass_is_exact) const {
3538   // There is no such thing as an exact general oop.
3539   // Return self unchanged.
3540   return this;
3541 }
3542 
3543 //------------------------------as_klass_type----------------------------------
3544 // Return the klass type corresponding to this instance or array type.
3545 // It is the type that is loaded from an object of this type.
3546 const TypeKlassPtr* TypeOopPtr::as_klass_type(bool try_for_exact) const {
3547   ShouldNotReachHere();
3548   return NULL;
3549 }
3550 
3551 //------------------------------meet-------------------------------------------
3552 // Compute the MEET of two types.  It returns a new Type object.
3553 const Type *TypeOopPtr::xmeet_helper(const Type *t) const {
3554   // Perform a fast test for common case; meeting the same types together.
3555   if( this == t ) return this;  // Meeting same type-rep?
3556 
3557   // Current "this->_base" is OopPtr
3558   switch (t->base()) {          // switch on original type
3559 
3560   case Int:                     // Mixing ints & oops happens when javac
3561   case Long:                    // reuses local variables
3562   case FloatTop:
3563   case FloatCon:
3564   case FloatBot:
3565   case DoubleTop:
3566   case DoubleCon:
3567   case DoubleBot:
3568   case NarrowOop:
3569   case NarrowKlass:
3570   case Bottom:                  // Ye Olde Default
3571     return Type::BOTTOM;
3572   case Top:
3573     return this;
3574 
3575   default:                      // All else is a mistake
3576     typerr(t);
3577 
3578   case RawPtr:
3579   case MetadataPtr:
3580   case KlassPtr:
3581   case InstKlassPtr:
3582   case AryKlassPtr:
3583     return TypePtr::BOTTOM;     // Oop meet raw is not well defined
3584 
3585   case AnyPtr: {
3586     // Found an AnyPtr type vs self-OopPtr type
3587     const TypePtr *tp = t->is_ptr();
3588     Offset offset = meet_offset(tp->offset());
3589     PTR ptr = meet_ptr(tp->ptr());
3590     const TypePtr* speculative = xmeet_speculative(tp);
3591     int depth = meet_inline_depth(tp->inline_depth());
3592     switch (tp->ptr()) {
3593     case Null:
3594       if (ptr == Null)  return TypePtr::make(AnyPtr, ptr, offset, speculative, depth);
3595       // else fall through:
3596     case TopPTR:
3597     case AnyNull: {
3598       int instance_id = meet_instance_id(InstanceTop);
3599       return make(ptr, offset, instance_id, speculative, depth);
3600     }
3601     case BotPTR:
3602     case NotNull:
3603       return TypePtr::make(AnyPtr, ptr, offset, speculative, depth);
3604     default: typerr(t);
3605     }
3606   }
3607 
3608   case OopPtr: {                 // Meeting to other OopPtrs
3609     const TypeOopPtr *tp = t->is_oopptr();
3610     int instance_id = meet_instance_id(tp->instance_id());
3611     const TypePtr* speculative = xmeet_speculative(tp);
3612     int depth = meet_inline_depth(tp->inline_depth());
3613     return make(meet_ptr(tp->ptr()), meet_offset(tp->offset()), instance_id, speculative, depth);
3614   }
3615 
3616   case InstPtr:                  // For these, flip the call around to cut down
3617   case AryPtr:
3618     return t->xmeet(this);      // Call in reverse direction
3619 
3620   } // End of switch
3621   return this;                  // Return the double constant
3622 }
3623 
3624 
3625 //------------------------------xdual------------------------------------------
3626 // Dual of a pure heap pointer.  No relevant klass or oop information.
3627 const Type *TypeOopPtr::xdual() const {
3628   assert(klass() == Compile::current()->env()->Object_klass(), "no klasses here");
3629   assert(const_oop() == NULL,             "no constants here");
3630   return new TypeOopPtr(_base, dual_ptr(), klass(), klass_is_exact(), const_oop(), dual_offset(), Offset::bottom, dual_instance_id(), dual_speculative(), dual_inline_depth());
3631 }
3632 
3633 //--------------------------make_from_klass_common-----------------------------
3634 // Computes the element-type given a klass.
3635 const TypeOopPtr* TypeOopPtr::make_from_klass_common(ciKlass *klass, bool klass_change, bool try_for_exact) {
3636   if (klass->is_instance_klass() || klass->is_inlinetype()) {
3637     Compile* C = Compile::current();
3638     Dependencies* deps = C->dependencies();
3639     assert((deps != NULL) == (C->method() != NULL && C->method()->code_size() > 0), "sanity");
3640     // Element is an instance
3641     bool klass_is_exact = false;
3642     if (klass->is_loaded()) {
3643       // Try to set klass_is_exact.
3644       ciInstanceKlass* ik = klass->as_instance_klass();
3645       klass_is_exact = ik->is_final();
3646       if (!klass_is_exact && klass_change
3647           && deps != NULL && UseUniqueSubclasses) {
3648         ciInstanceKlass* sub = ik->unique_concrete_subklass();
3649         if (sub != NULL) {
3650           deps->assert_abstract_with_unique_concrete_subtype(ik, sub);
3651           klass = ik = sub;
3652           klass_is_exact = sub->is_final();
3653         }
3654       }
3655       if (!klass_is_exact && try_for_exact && deps != NULL &&
3656           !ik->is_interface() && !ik->has_subklass()) {
3657         // Add a dependence; if concrete subclass added we need to recompile
3658         deps->assert_leaf_type(ik);
3659         klass_is_exact = true;
3660       }
3661     }
3662     return TypeInstPtr::make(TypePtr::BotPTR, klass, klass_is_exact, NULL, Offset(0));
3663   } else if (klass->is_obj_array_klass()) {
3664     // Element is an object or inline type array. Recursively call ourself.
3665     const TypeOopPtr* etype = TypeOopPtr::make_from_klass_common(klass->as_array_klass()->element_klass(), /* klass_change= */ false, try_for_exact);
3666     bool null_free = klass->as_array_klass()->is_elem_null_free();
3667     if (null_free) {
3668       etype = etype->join_speculative(TypePtr::NOTNULL)->is_oopptr();
3669     }
3670     // Determine null-free/flattened properties
3671     const TypeOopPtr* exact_etype = etype;
3672     if (etype->can_be_inline_type()) {
3673       // Use exact type if element can be an inline type
3674       exact_etype = TypeOopPtr::make_from_klass_common(klass->as_array_klass()->element_klass(), /* klass_change= */ true, /* try_for_exact= */ true);
3675     }
3676     bool not_null_free = !exact_etype->can_be_inline_type();
3677     bool not_flat = !UseFlatArray || not_null_free || (exact_etype->is_inlinetypeptr() && !exact_etype->inline_klass()->flatten_array());
3678 
3679     // Even if MyValue is exact, [LMyValue is not exact due to [QMyValue <: [LMyValue.
3680     bool xk = etype->klass_is_exact() && (!etype->is_inlinetypeptr() || null_free);
3681     const TypeAry* arr0 = TypeAry::make(etype, TypeInt::POS, false, not_flat, not_null_free);
3682     // We used to pass NotNull in here, asserting that the sub-arrays
3683     // are all not-null.  This is not true in generally, as code can
3684     // slam NULLs down in the subarrays.
3685     const TypeAryPtr* arr = TypeAryPtr::make(TypePtr::BotPTR, arr0, klass, xk, Offset(0));
3686     return arr;
3687   } else if (klass->is_type_array_klass()) {
3688     // Element is an typeArray
3689     const Type* etype = get_const_basic_type(klass->as_type_array_klass()->element_type());
3690     const TypeAry* arr0 = TypeAry::make(etype, TypeInt::POS,
3691                                         /* stable= */ false, /* not_flat= */ true, /* not_null_free= */ true);
3692     // We used to pass NotNull in here, asserting that the array pointer
3693     // is not-null. That was not true in general.
3694     const TypeAryPtr* arr = TypeAryPtr::make(TypePtr::BotPTR, arr0, klass, true, Offset(0));
3695     return arr;
3696   } else if (klass->is_flat_array_klass()) {
3697     ciInlineKlass* vk = klass->as_array_klass()->element_klass()->as_inline_klass();
3698     const TypeAry* arr0 = TypeAry::make(TypeInlineType::make(vk), TypeInt::POS);
3699     const TypeAryPtr* arr = TypeAryPtr::make(TypePtr::BotPTR, arr0, klass, true, Offset(0));
3700     return arr;
3701   } else {
3702     ShouldNotReachHere();
3703     return NULL;
3704   }
3705 }
3706 
3707 //------------------------------make_from_constant-----------------------------
3708 // Make a java pointer from an oop constant
3709 const TypeOopPtr* TypeOopPtr::make_from_constant(ciObject* o, bool require_constant) {
3710   assert(!o->is_null_object(), "null object not yet handled here.");
3711 
3712   const bool make_constant = require_constant || o->should_be_constant();
3713 
3714   ciKlass* klass = o->klass();
3715   if (klass->is_instance_klass() || klass->is_inlinetype()) {
3716     // Element is an instance or inline type
3717     if (make_constant) {
3718       return TypeInstPtr::make(o);
3719     } else {
3720       return TypeInstPtr::make(TypePtr::NotNull, klass, true, NULL, Offset(0));
3721     }
3722   } else if (klass->is_obj_array_klass()) {
3723     // Element is an object array. Recursively call ourself.
3724     const TypeOopPtr* etype = TypeOopPtr::make_from_klass_raw(klass->as_array_klass()->element_klass());
3725     bool null_free = false;
3726     if (klass->as_array_klass()->is_elem_null_free()) {
3727       null_free = true;
3728       etype = etype->join_speculative(TypePtr::NOTNULL)->is_oopptr();
3729     }
3730     const TypeAry* arr0 = TypeAry::make(etype, TypeInt::make(o->as_array()->length()),
3731                                         /* stable= */ false, /* not_flat= */ true, /* not_null_free= */ !null_free);
3732     // We used to pass NotNull in here, asserting that the sub-arrays
3733     // are all not-null.  This is not true in generally, as code can
3734     // slam NULLs down in the subarrays.
3735     if (make_constant) {
3736       return TypeAryPtr::make(TypePtr::Constant, o, arr0, klass, true, Offset(0));
3737     } else {
3738       return TypeAryPtr::make(TypePtr::NotNull, arr0, klass, true, Offset(0));
3739     }
3740   } else if (klass->is_type_array_klass()) {
3741     // Element is an typeArray
3742     const Type* etype = (Type*)get_const_basic_type(klass->as_type_array_klass()->element_type());
3743     const TypeAry* arr0 = TypeAry::make(etype, TypeInt::make(o->as_array()->length()),
3744                                         /* stable= */ false, /* not_flat= */ true, /* not_null_free= */ true);
3745     // We used to pass NotNull in here, asserting that the array pointer
3746     // is not-null. That was not true in general.
3747     if (make_constant) {
3748       return TypeAryPtr::make(TypePtr::Constant, o, arr0, klass, true, Offset(0));
3749     } else {
3750       return TypeAryPtr::make(TypePtr::NotNull, arr0, klass, true, Offset(0));
3751     }
3752   } else if (klass->is_flat_array_klass()) {
3753     ciInlineKlass* vk = klass->as_array_klass()->element_klass()->as_inline_klass();
3754     const TypeAry* arr0 = TypeAry::make(TypeInlineType::make(vk), TypeInt::make(o->as_array()->length()));
3755     // We used to pass NotNull in here, asserting that the sub-arrays
3756     // are all not-null.  This is not true in generally, as code can
3757     // slam NULLs down in the subarrays.
3758     if (make_constant) {
3759       return TypeAryPtr::make(TypePtr::Constant, o, arr0, klass, true, Offset(0));
3760     } else {
3761       return TypeAryPtr::make(TypePtr::NotNull, arr0, klass, true, Offset(0));
3762     }
3763   }
3764 
3765   fatal("unhandled object type");
3766   return NULL;
3767 }
3768 
3769 //------------------------------get_con----------------------------------------
3770 intptr_t TypeOopPtr::get_con() const {
3771   assert( _ptr == Null || _ptr == Constant, "" );
3772   assert(offset() >= 0, "");
3773 
3774   if (offset() != 0) {
3775     // After being ported to the compiler interface, the compiler no longer
3776     // directly manipulates the addresses of oops.  Rather, it only has a pointer
3777     // to a handle at compile time.  This handle is embedded in the generated
3778     // code and dereferenced at the time the nmethod is made.  Until that time,
3779     // it is not reasonable to do arithmetic with the addresses of oops (we don't
3780     // have access to the addresses!).  This does not seem to currently happen,
3781     // but this assertion here is to help prevent its occurrence.
3782     tty->print_cr("Found oop constant with non-zero offset");
3783     ShouldNotReachHere();
3784   }
3785 
3786   return (intptr_t)const_oop()->constant_encoding();
3787 }
3788 
3789 
3790 //-----------------------------filter------------------------------------------
3791 // Do not allow interface-vs.-noninterface joins to collapse to top.
3792 const Type *TypeOopPtr::filter_helper(const Type *kills, bool include_speculative) const {
3793 
3794   const Type* ft = join_helper(kills, include_speculative);
3795   const TypeInstPtr* ftip = ft->isa_instptr();
3796   const TypeInstPtr* ktip = kills->isa_instptr();
3797 
3798   if (ft->empty()) {
3799     // Check for evil case of 'this' being a class and 'kills' expecting an
3800     // interface.  This can happen because the bytecodes do not contain
3801     // enough type info to distinguish a Java-level interface variable
3802     // from a Java-level object variable.  If we meet 2 classes which
3803     // both implement interface I, but their meet is at 'j/l/O' which
3804     // doesn't implement I, we have no way to tell if the result should
3805     // be 'I' or 'j/l/O'.  Thus we'll pick 'j/l/O'.  If this then flows
3806     // into a Phi which "knows" it's an Interface type we'll have to
3807     // uplift the type.
3808     if (!empty()) {
3809       if (ktip != NULL && ktip->is_loaded() && ktip->klass()->is_interface()) {
3810         return kills;           // Uplift to interface
3811       }
3812       // Also check for evil cases of 'this' being a class array
3813       // and 'kills' expecting an array of interfaces.
3814       Type::get_arrays_base_elements(ft, kills, NULL, &ktip);
3815       if (ktip != NULL && ktip->is_loaded() && ktip->klass()->is_interface()) {
3816         return kills;           // Uplift to array of interface
3817       }
3818     }
3819 
3820     return Type::TOP;           // Canonical empty value
3821   }
3822 
3823   // If we have an interface-typed Phi or cast and we narrow to a class type,
3824   // the join should report back the class.  However, if we have a J/L/Object
3825   // class-typed Phi and an interface flows in, it's possible that the meet &
3826   // join report an interface back out.  This isn't possible but happens
3827   // because the type system doesn't interact well with interfaces.
3828   if (ftip != NULL && ktip != NULL &&
3829       ftip->is_loaded() &&  ftip->klass()->is_interface() &&
3830       ktip->is_loaded() && !ktip->klass()->is_interface()) {
3831     assert(!ftip->klass_is_exact(), "interface could not be exact");
3832     return ktip->cast_to_ptr_type(ftip->ptr());
3833   }
3834 
3835   return ft;
3836 }
3837 
3838 //------------------------------eq---------------------------------------------
3839 // Structural equality check for Type representations
3840 bool TypeOopPtr::eq( const Type *t ) const {
3841   const TypeOopPtr *a = (const TypeOopPtr*)t;
3842   if (_klass_is_exact != a->_klass_is_exact ||
3843       _instance_id != a->_instance_id)  return false;
3844   ciObject* one = const_oop();
3845   ciObject* two = a->const_oop();
3846   if (one == NULL || two == NULL) {
3847     return (one == two) && TypePtr::eq(t);
3848   } else {
3849     return one->equals(two) && TypePtr::eq(t);
3850   }
3851 }
3852 
3853 //------------------------------hash-------------------------------------------
3854 // Type-specific hashing function.
3855 int TypeOopPtr::hash(void) const {
3856   return
3857     java_add(java_add((jint)(const_oop() ? const_oop()->hash() : 0), (jint)_klass_is_exact),
3858              java_add((jint)_instance_id, (jint)TypePtr::hash()));
3859 }
3860 
3861 //------------------------------dump2------------------------------------------
3862 #ifndef PRODUCT
3863 void TypeOopPtr::dump2( Dict &d, uint depth, outputStream *st ) const {
3864   st->print("oopptr:%s", ptr_msg[_ptr]);
3865   if( _klass_is_exact ) st->print(":exact");
3866   if( const_oop() ) st->print(INTPTR_FORMAT, p2i(const_oop()));
3867   _offset.dump2(st);
3868   if (_instance_id == InstanceTop)
3869     st->print(",iid=top");
3870   else if (_instance_id != InstanceBot)
3871     st->print(",iid=%d",_instance_id);
3872 
3873   dump_inline_depth(st);
3874   dump_speculative(st);
3875 }
3876 #endif
3877 
3878 //------------------------------singleton--------------------------------------
3879 // TRUE if Type is a singleton type, FALSE otherwise.   Singletons are simple
3880 // constants
3881 bool TypeOopPtr::singleton(void) const {
3882   // detune optimizer to not generate constant oop + constant offset as a constant!
3883   // TopPTR, Null, AnyNull, Constant are all singletons
3884   return (offset() == 0) && !below_centerline(_ptr);
3885 }
3886 
3887 //------------------------------add_offset-------------------------------------
3888 const TypePtr *TypeOopPtr::add_offset(intptr_t offset) const {
3889   return make(_ptr, xadd_offset(offset), _instance_id, add_offset_speculative(offset), _inline_depth);
3890 }
3891 
3892 const TypeOopPtr* TypeOopPtr::with_offset(intptr_t offset) const {
3893   return make(_ptr, Offset(offset), _instance_id, with_offset_speculative(offset), _inline_depth);
3894 }
3895 
3896 /**
3897  * Return same type without a speculative part
3898  */
3899 const TypeOopPtr* TypeOopPtr::remove_speculative() const {
3900   if (_speculative == NULL) {
3901     return this;
3902   }
3903   assert(_inline_depth == InlineDepthTop || _inline_depth == InlineDepthBottom, "non speculative type shouldn't have inline depth");
3904   return make(_ptr, _offset, _instance_id, NULL, _inline_depth);
3905 }
3906 
3907 /**
3908  * Return same type but drop speculative part if we know we won't use
3909  * it
3910  */
3911 const Type* TypeOopPtr::cleanup_speculative() const {
3912   // If the klass is exact and the ptr is not null then there's
3913   // nothing that the speculative type can help us with
3914   if (klass_is_exact() && !maybe_null()) {
3915     return remove_speculative();
3916   }
3917   return TypePtr::cleanup_speculative();
3918 }
3919 
3920 /**
3921  * Return same type but with a different inline depth (used for speculation)
3922  *
3923  * @param depth  depth to meet with
3924  */
3925 const TypePtr* TypeOopPtr::with_inline_depth(int depth) const {
3926   if (!UseInlineDepthForSpeculativeTypes) {
3927     return this;
3928   }
3929   return make(_ptr, _offset, _instance_id, _speculative, depth);
3930 }
3931 
3932 //------------------------------with_instance_id--------------------------------
3933 const TypePtr* TypeOopPtr::with_instance_id(int instance_id) const {
3934   assert(_instance_id != -1, "should be known");
3935   return make(_ptr, _offset, instance_id, _speculative, _inline_depth);
3936 }
3937 
3938 //------------------------------meet_instance_id--------------------------------
3939 int TypeOopPtr::meet_instance_id( int instance_id ) const {
3940   // Either is 'TOP' instance?  Return the other instance!
3941   if( _instance_id == InstanceTop ) return  instance_id;
3942   if(  instance_id == InstanceTop ) return _instance_id;
3943   // If either is different, return 'BOTTOM' instance
3944   if( _instance_id != instance_id ) return InstanceBot;
3945   return _instance_id;
3946 }
3947 
3948 //------------------------------dual_instance_id--------------------------------
3949 int TypeOopPtr::dual_instance_id( ) const {
3950   if( _instance_id == InstanceTop ) return InstanceBot; // Map TOP into BOTTOM
3951   if( _instance_id == InstanceBot ) return InstanceTop; // Map BOTTOM into TOP
3952   return _instance_id;              // Map everything else into self
3953 }
3954 
3955 /**
3956  * Check whether new profiling would improve speculative type
3957  *
3958  * @param   exact_kls    class from profiling
3959  * @param   inline_depth inlining depth of profile point
3960  *
3961  * @return  true if type profile is valuable
3962  */
3963 bool TypeOopPtr::would_improve_type(ciKlass* exact_kls, int inline_depth) const {
3964   // no way to improve an already exact type
3965   if (klass_is_exact()) {
3966     return false;
3967   }
3968   return TypePtr::would_improve_type(exact_kls, inline_depth);
3969 }
3970 
3971 //=============================================================================
3972 // Convenience common pre-built types.
3973 const TypeInstPtr *TypeInstPtr::NOTNULL;
3974 const TypeInstPtr *TypeInstPtr::BOTTOM;
3975 const TypeInstPtr *TypeInstPtr::MIRROR;
3976 const TypeInstPtr *TypeInstPtr::MARK;
3977 const TypeInstPtr *TypeInstPtr::KLASS;
3978 
3979 ciKlass* TypeInstPtr::exact_klass_helper() const {
3980   return _klass;
3981 }
3982 
3983 //------------------------------TypeInstPtr-------------------------------------
3984 TypeInstPtr::TypeInstPtr(PTR ptr, ciKlass* k, bool xk, ciObject* o, Offset off,
3985                          bool flatten_array, int instance_id, const TypePtr* speculative, int inline_depth)
3986   : TypeOopPtr(InstPtr, ptr, k, xk, o, off, Offset::bottom, instance_id, speculative, inline_depth),
3987     _flatten_array(flatten_array) {
3988    assert(k != NULL &&
3989           (k->is_loaded() || o == NULL),
3990           "cannot have constants with non-loaded klass");
3991    assert(!klass()->flatten_array() || flatten_array, "Should be flat in array");
3992    assert(!flatten_array || can_be_inline_type(), "Only inline types can be flat in array");
3993 };
3994 
3995 //------------------------------make-------------------------------------------
3996 const TypeInstPtr *TypeInstPtr::make(PTR ptr,
3997                                      ciKlass* k,
3998                                      bool xk,
3999                                      ciObject* o,
4000                                      Offset offset,
4001                                      bool flatten_array,
4002                                      int instance_id,
4003                                      const TypePtr* speculative,
4004                                      int inline_depth) {
4005   assert( !k->is_loaded() || k->is_instance_klass(), "Must be for instance");
4006   // Either const_oop() is NULL or else ptr is Constant
4007   assert( (!o && ptr != Constant) || (o && ptr == Constant),
4008           "constant pointers must have a value supplied" );
4009   // Ptr is never Null
4010   assert( ptr != Null, "NULL pointers are not typed" );
4011 
4012   assert(instance_id <= 0 || xk, "instances are always exactly typed");
4013   if (ptr == Constant) {
4014     // Note:  This case includes meta-object constants, such as methods.
4015     xk = true;
4016   } else if (k->is_loaded()) {
4017     ciInstanceKlass* ik = k->as_instance_klass();
4018     if (!xk && ik->is_final())     xk = true;   // no inexact final klass
4019     if (xk && ik->is_interface())  xk = false;  // no exact interface
4020   }
4021 
4022   // Check if this type is known to be flat in arrays
4023   flatten_array = flatten_array || k->flatten_array();
4024 
4025   // Now hash this baby
4026   TypeInstPtr *result =
4027     (TypeInstPtr*)(new TypeInstPtr(ptr, k, xk, o, offset, flatten_array, instance_id, speculative, inline_depth))->hashcons();
4028 
4029   return result;
4030 }
4031 
4032 /**
4033  *  Create constant type for a constant boxed value
4034  */
4035 const Type* TypeInstPtr::get_const_boxed_value() const {
4036   assert(is_ptr_to_boxed_value(), "should be called only for boxed value");
4037   assert((const_oop() != NULL), "should be called only for constant object");
4038   ciConstant constant = const_oop()->as_instance()->field_value_by_offset(offset());
4039   BasicType bt = constant.basic_type();
4040   switch (bt) {
4041     case T_BOOLEAN:  return TypeInt::make(constant.as_boolean());
4042     case T_INT:      return TypeInt::make(constant.as_int());
4043     case T_CHAR:     return TypeInt::make(constant.as_char());
4044     case T_BYTE:     return TypeInt::make(constant.as_byte());
4045     case T_SHORT:    return TypeInt::make(constant.as_short());
4046     case T_FLOAT:    return TypeF::make(constant.as_float());
4047     case T_DOUBLE:   return TypeD::make(constant.as_double());
4048     case T_LONG:     return TypeLong::make(constant.as_long());
4049     default:         break;
4050   }
4051   fatal("Invalid boxed value type '%s'", type2name(bt));
4052   return NULL;
4053 }
4054 
4055 //------------------------------cast_to_ptr_type-------------------------------
4056 const TypeInstPtr* TypeInstPtr::cast_to_ptr_type(PTR ptr) const {
4057   if( ptr == _ptr ) return this;
4058   // Reconstruct _sig info here since not a problem with later lazy
4059   // construction, _sig will show up on demand.
4060   return make(ptr, klass(), klass_is_exact(), ptr == Constant ? const_oop() : NULL, _offset, _flatten_array, _instance_id, _speculative, _inline_depth);
4061 }
4062 
4063 
4064 //-----------------------------cast_to_exactness-------------------------------
4065 const TypeInstPtr* TypeInstPtr::cast_to_exactness(bool klass_is_exact) const {
4066   if( klass_is_exact == _klass_is_exact ) return this;
4067   if (!_klass->is_loaded())  return this;
4068   ciInstanceKlass* ik = _klass->as_instance_klass();
4069   if( (ik->is_final() || _const_oop) )  return this;  // cannot clear xk
4070   if( ik->is_interface() )              return this;  // cannot set xk
4071   return make(ptr(), klass(), klass_is_exact, const_oop(), _offset, _flatten_array, _instance_id, _speculative, _inline_depth);
4072 }
4073 
4074 //-----------------------------cast_to_instance_id----------------------------
4075 const TypeInstPtr* TypeInstPtr::cast_to_instance_id(int instance_id) const {
4076   if( instance_id == _instance_id ) return this;
4077   return make(_ptr, klass(), _klass_is_exact, const_oop(), _offset, _flatten_array, instance_id, _speculative, _inline_depth);
4078 }
4079 
4080 //------------------------------xmeet_unloaded---------------------------------
4081 // Compute the MEET of two InstPtrs when at least one is unloaded.
4082 // Assume classes are different since called after check for same name/class-loader
4083 const TypeInstPtr *TypeInstPtr::xmeet_unloaded(const TypeInstPtr *tinst) const {
4084     Offset off = meet_offset(tinst->offset());
4085     PTR ptr = meet_ptr(tinst->ptr());
4086     int instance_id = meet_instance_id(tinst->instance_id());
4087     const TypePtr* speculative = xmeet_speculative(tinst);
4088     int depth = meet_inline_depth(tinst->inline_depth());
4089 
4090     const TypeInstPtr *loaded    = is_loaded() ? this  : tinst;
4091     const TypeInstPtr *unloaded  = is_loaded() ? tinst : this;
4092     if( loaded->klass()->equals(ciEnv::current()->Object_klass()) ) {
4093       //
4094       // Meet unloaded class with java/lang/Object
4095       //
4096       // Meet
4097       //          |                     Unloaded Class
4098       //  Object  |   TOP    |   AnyNull | Constant |   NotNull |  BOTTOM   |
4099       //  ===================================================================
4100       //   TOP    | ..........................Unloaded......................|
4101       //  AnyNull |  U-AN    |................Unloaded......................|
4102       // Constant | ... O-NN .................................. |   O-BOT   |
4103       //  NotNull | ... O-NN .................................. |   O-BOT   |
4104       //  BOTTOM  | ........................Object-BOTTOM ..................|
4105       //
4106       assert(loaded->ptr() != TypePtr::Null, "insanity check");
4107       //
4108       if(      loaded->ptr() == TypePtr::TopPTR ) { return unloaded; }
4109       else if (loaded->ptr() == TypePtr::AnyNull) { return TypeInstPtr::make(ptr, unloaded->klass(), false, NULL, off, false, instance_id, speculative, depth); }
4110       else if (loaded->ptr() == TypePtr::BotPTR ) { return TypeInstPtr::BOTTOM; }
4111       else if (loaded->ptr() == TypePtr::Constant || loaded->ptr() == TypePtr::NotNull) {
4112         if (unloaded->ptr() == TypePtr::BotPTR  ) { return TypeInstPtr::BOTTOM;  }
4113         else                                      { return TypeInstPtr::NOTNULL; }
4114       }
4115       else if( unloaded->ptr() == TypePtr::TopPTR )  { return unloaded; }
4116 
4117       return unloaded->cast_to_ptr_type(TypePtr::AnyNull)->is_instptr();
4118     }
4119 
4120     // Both are unloaded, not the same class, not Object
4121     // Or meet unloaded with a different loaded class, not java/lang/Object
4122     if( ptr != TypePtr::BotPTR ) {
4123       return TypeInstPtr::NOTNULL;
4124     }
4125     return TypeInstPtr::BOTTOM;
4126 }
4127 
4128 
4129 //------------------------------meet-------------------------------------------
4130 // Compute the MEET of two types.  It returns a new Type object.
4131 const Type *TypeInstPtr::xmeet_helper(const Type *t) const {
4132   // Perform a fast test for common case; meeting the same types together.
4133   if( this == t ) return this;  // Meeting same type-rep?
4134 
4135   // Current "this->_base" is Pointer
4136   switch (t->base()) {          // switch on original type
4137 
4138   case Int:                     // Mixing ints & oops happens when javac
4139   case Long:                    // reuses local variables
4140   case FloatTop:
4141   case FloatCon:
4142   case FloatBot:
4143   case DoubleTop:
4144   case DoubleCon:
4145   case DoubleBot:
4146   case NarrowOop:
4147   case NarrowKlass:
4148   case Bottom:                  // Ye Olde Default
4149     return Type::BOTTOM;
4150   case Top:
4151     return this;
4152 
4153   default:                      // All else is a mistake
4154     typerr(t);
4155 
4156   case MetadataPtr:
4157   case KlassPtr:
4158   case InstKlassPtr:
4159   case AryKlassPtr:
4160   case RawPtr: return TypePtr::BOTTOM;
4161 
4162   case AryPtr: {                // All arrays inherit from Object class
4163     // Call in reverse direction to avoid duplication
4164     return t->is_aryptr()->xmeet_helper(this);
4165   }
4166 
4167   case OopPtr: {                // Meeting to OopPtrs
4168     // Found a OopPtr type vs self-InstPtr type
4169     const TypeOopPtr *tp = t->is_oopptr();
4170     Offset offset = meet_offset(tp->offset());
4171     PTR ptr = meet_ptr(tp->ptr());
4172     switch (tp->ptr()) {
4173     case TopPTR:
4174     case AnyNull: {
4175       int instance_id = meet_instance_id(InstanceTop);
4176       const TypePtr* speculative = xmeet_speculative(tp);
4177       int depth = meet_inline_depth(tp->inline_depth());
4178       return make(ptr, klass(), klass_is_exact(),
4179                   (ptr == Constant ? const_oop() : NULL), offset, flatten_array(), instance_id, speculative, depth);
4180     }
4181     case NotNull:
4182     case BotPTR: {
4183       int instance_id = meet_instance_id(tp->instance_id());
4184       const TypePtr* speculative = xmeet_speculative(tp);
4185       int depth = meet_inline_depth(tp->inline_depth());
4186       return TypeOopPtr::make(ptr, offset, instance_id, speculative, depth);
4187     }
4188     default: typerr(t);
4189     }
4190   }
4191 
4192   case AnyPtr: {                // Meeting to AnyPtrs
4193     // Found an AnyPtr type vs self-InstPtr type
4194     const TypePtr *tp = t->is_ptr();
4195     Offset offset = meet_offset(tp->offset());
4196     PTR ptr = meet_ptr(tp->ptr());
4197     int instance_id = meet_instance_id(InstanceTop);
4198     const TypePtr* speculative = xmeet_speculative(tp);
4199     int depth = meet_inline_depth(tp->inline_depth());
4200     switch (tp->ptr()) {
4201     case Null:
4202       if( ptr == Null ) return TypePtr::make(AnyPtr, ptr, offset, speculative, depth);
4203       // else fall through to AnyNull
4204     case TopPTR:
4205     case AnyNull: {
4206       return make(ptr, klass(), klass_is_exact(),
4207                   (ptr == Constant ? const_oop() : NULL), offset, flatten_array(), instance_id, speculative, depth);
4208     }
4209     case NotNull:
4210     case BotPTR:
4211       return TypePtr::make(AnyPtr, ptr, offset, speculative,depth);
4212     default: typerr(t);
4213     }
4214   }
4215 
4216   /*
4217                  A-top         }
4218                /   |   \       }  Tops
4219            B-top A-any C-top   }
4220               | /  |  \ |      }  Any-nulls
4221            B-any   |   C-any   }
4222               |    |    |
4223            B-con A-con C-con   } constants; not comparable across classes
4224               |    |    |
4225            B-not   |   C-not   }
4226               | \  |  / |      }  not-nulls
4227            B-bot A-not C-bot   }
4228                \   |   /       }  Bottoms
4229                  A-bot         }
4230   */
4231 
4232   case InstPtr: {                // Meeting 2 Oops?
4233     // Found an InstPtr sub-type vs self-InstPtr type
4234     const TypeInstPtr *tinst = t->is_instptr();
4235     Offset off = meet_offset(tinst->offset());
4236     PTR ptr = meet_ptr(tinst->ptr());
4237     int instance_id = meet_instance_id(tinst->instance_id());
4238     const TypePtr* speculative = xmeet_speculative(tinst);
4239     int depth = meet_inline_depth(tinst->inline_depth());
4240     ciKlass* tinst_klass = tinst->klass();
4241     ciKlass* this_klass  = klass();
4242     bool tinst_xk = tinst->klass_is_exact();
4243     bool this_xk  = this->klass_is_exact();
4244     bool tinst_flatten_array = tinst->flatten_array();
4245     bool this_flatten_array  = this->flatten_array();
4246 
4247     ciKlass* res_klass = NULL;
4248     bool res_xk = false;
4249     bool res_flatten_array = false;
4250     const Type* res;
4251     MeetResult kind = meet_instptr(ptr, this_klass, tinst_klass, this_xk, tinst_xk, this->_ptr, tinst->_ptr,
4252                                    this_flatten_array, tinst_flatten_array,
4253                                    res_klass, res_xk, res_flatten_array);
4254     if (kind == UNLOADED) {
4255       // One of these classes has not been loaded
4256       const TypeInstPtr* unloaded_meet = xmeet_unloaded(tinst);
4257 #ifndef PRODUCT
4258       if (PrintOpto && Verbose) {
4259         tty->print("meet of unloaded classes resulted in: ");
4260         unloaded_meet->dump();
4261         tty->cr();
4262         tty->print("  this == ");
4263         dump();
4264         tty->cr();
4265         tty->print(" tinst == ");
4266         tinst->dump();
4267         tty->cr();
4268       }
4269 #endif
4270       res = unloaded_meet;
4271     } else {
4272       if (kind == NOT_SUBTYPE && instance_id > 0) {
4273         instance_id = InstanceBot;
4274       } else if (kind == LCA) {
4275         instance_id = InstanceBot;
4276       }
4277       ciObject* o = NULL;             // Assume not constant when done
4278       ciObject* this_oop = const_oop();
4279       ciObject* tinst_oop = tinst->const_oop();
4280       if (ptr == Constant) {
4281         if (this_oop != NULL && tinst_oop != NULL &&
4282             this_oop->equals(tinst_oop))
4283           o = this_oop;
4284         else if (above_centerline(_ptr)) {
4285           assert(!tinst_klass->is_interface(), "");
4286           o = tinst_oop;
4287         } else if (above_centerline(tinst->_ptr)) {
4288           assert(!this_klass->is_interface(), "");
4289           o = this_oop;
4290         } else
4291           ptr = NotNull;
4292       }
4293       res = make(ptr, res_klass, res_xk, o, off, res_flatten_array, instance_id, speculative, depth);
4294     }
4295 
4296     return res;
4297 
4298   } // End of case InstPtr
4299 
4300   case InlineType: {
4301     const TypeInlineType* tv = t->is_inlinetype();
4302     if (above_centerline(ptr())) {
4303       if (tv->inline_klass()->is_subtype_of(_klass)) {
4304         return t;
4305       } else {
4306         return TypeInstPtr::NOTNULL;
4307       }
4308     } else {
4309       PTR ptr = this->_ptr;
4310       if (ptr == Constant) {
4311         ptr = NotNull;
4312       }
4313       if (tv->inline_klass()->is_subtype_of(_klass)) {
4314         return make(ptr, _klass, false, NULL, Offset(0), _flatten_array, InstanceBot, _speculative);
4315       } else {
4316         return make(ptr, ciEnv::current()->Object_klass());
4317       }
4318     }
4319   }
4320 
4321   } // End of switch
4322   return this;                  // Return the double constant
4323 }
4324 
4325 TypePtr::MeetResult TypePtr::meet_instptr(PTR &ptr, ciKlass* this_klass, ciKlass* tinst_klass, bool this_xk, bool tinst_xk,
4326                                           PTR this_ptr, PTR tinst_ptr, bool this_flatten_array, bool tinst_flatten_array,
4327                                           ciKlass*&res_klass, bool &res_xk, bool& res_flatten_array) {
4328 
4329   bool this_flatten_array_orig = this_flatten_array;
4330   bool tinst_flatten_array_orig = tinst_flatten_array;
4331 
4332   // Check for easy case; klasses are equal (and perhaps not loaded!)
4333   // If we have constants, then we created oops so classes are loaded
4334   // and we can handle the constants further down.  This case handles
4335   // both-not-loaded or both-loaded classes
4336   if (ptr != Constant && this_klass->equals(tinst_klass) && this_xk == tinst_xk && this_flatten_array == tinst_flatten_array) {
4337     res_klass = this_klass;
4338     res_xk = this_xk;
4339     res_flatten_array = this_flatten_array;
4340     return QUICK;
4341   }
4342 
4343   // Classes require inspection in the Java klass hierarchy.  Must be loaded.
4344   if (!tinst_klass->is_loaded() || !this_klass->is_loaded()) {
4345     return UNLOADED;
4346   }
4347 
4348   // Handle mixing oops and interfaces first.
4349   if (this_klass->is_interface() && !(tinst_klass->is_interface() ||
4350                                       tinst_klass == ciEnv::current()->Object_klass())) {
4351     ciKlass *tmp = tinst_klass; // Swap interface around
4352     tinst_klass = this_klass;
4353     this_klass = tmp;
4354     bool tmp2 = tinst_xk;
4355     tinst_xk = this_xk;
4356     this_xk = tmp2;
4357     tmp2 = tinst_flatten_array;
4358     tinst_flatten_array = this_flatten_array;
4359     this_flatten_array = tmp2;
4360   }
4361   if (tinst_klass->is_interface() &&
4362       !(this_klass->is_interface() ||
4363         // Treat java/lang/Object as an honorary interface,
4364         // because we need a bottom for the interface hierarchy.
4365         this_klass == ciEnv::current()->Object_klass())) {
4366     // Oop meets interface!
4367 
4368     // See if the oop subtypes (implements) interface.
4369     if (this_klass->is_subtype_of(tinst_klass)) {
4370       // Oop indeed subtypes.  Now keep oop or interface depending
4371       // on whether we are both above the centerline or either is
4372       // below the centerline.  If we are on the centerline
4373       // (e.g., Constant vs. AnyNull interface), use the constant.
4374       res_klass  = below_centerline(ptr) ? tinst_klass : this_klass;
4375       // If we are keeping this_klass, keep its exactness too.
4376       res_xk = below_centerline(ptr) ? tinst_xk    : this_xk;
4377       res_flatten_array = below_centerline(ptr) ? tinst_flatten_array    : this_flatten_array;
4378       return SUBTYPE;
4379     } else {                  // Does not implement, fall to Object
4380       // Oop does not implement interface, so mixing falls to Object
4381       // just like the verifier does (if both are above the
4382       // centerline fall to interface)
4383       res_klass = above_centerline(ptr) ? tinst_klass : ciEnv::current()->Object_klass();
4384       res_xk = above_centerline(ptr) ? tinst_xk : false;
4385       res_flatten_array = above_centerline(ptr) ? tinst_flatten_array : false;
4386       // Watch out for Constant vs. AnyNull interface.
4387       if (ptr == Constant)  ptr = NotNull;   // forget it was a constant
4388       return NOT_SUBTYPE;
4389     }
4390   }
4391 
4392   // Either oop vs oop or interface vs interface or interface vs Object
4393 
4394   // !!! Here's how the symmetry requirement breaks down into invariants:
4395   // If we split one up & one down AND they subtype, take the down man.
4396   // If we split one up & one down AND they do NOT subtype, "fall hard".
4397   // If both are up and they subtype, take the subtype class.
4398   // If both are up and they do NOT subtype, "fall hard".
4399   // If both are down and they subtype, take the supertype class.
4400   // If both are down and they do NOT subtype, "fall hard".
4401   // Constants treated as down.
4402 
4403   // Now, reorder the above list; observe that both-down+subtype is also
4404   // "fall hard"; "fall hard" becomes the default case:
4405   // If we split one up & one down AND they subtype, take the down man.
4406   // If both are up and they subtype, take the subtype class.
4407 
4408   // If both are down and they subtype, "fall hard".
4409   // If both are down and they do NOT subtype, "fall hard".
4410   // If both are up and they do NOT subtype, "fall hard".
4411   // If we split one up & one down AND they do NOT subtype, "fall hard".
4412 
4413   // If a proper subtype is exact, and we return it, we return it exactly.
4414   // If a proper supertype is exact, there can be no subtyping relationship!
4415   // If both types are equal to the subtype, exactness is and-ed below the
4416   // centerline and or-ed above it.  (N.B. Constants are always exact.)
4417 
4418   // Check for subtyping:
4419   ciKlass *subtype = NULL;
4420   bool subtype_exact = false;
4421   bool flat_array = false;
4422   if (tinst_klass->equals(this_klass)) {
4423     subtype = this_klass;
4424     subtype_exact = below_centerline(ptr) ? (this_xk && tinst_xk) : (this_xk || tinst_xk);
4425     flat_array = below_centerline(ptr) ? (this_flatten_array && tinst_flatten_array) : (this_flatten_array || tinst_flatten_array);
4426   } else if (!tinst_xk && this_klass->is_subtype_of(tinst_klass) && (!tinst_flatten_array || this_flatten_array)) {
4427     subtype = this_klass;     // Pick subtyping class
4428     subtype_exact = this_xk;
4429     flat_array = this_flatten_array;
4430   } else if (!this_xk && tinst_klass->is_subtype_of(this_klass) && (!this_flatten_array || tinst_flatten_array)) {
4431     subtype = tinst_klass;    // Pick subtyping class
4432     subtype_exact = tinst_xk;
4433     flat_array = tinst_flatten_array;
4434   }
4435 
4436   if (subtype) {
4437     if (above_centerline(ptr)) { // both are up?
4438       this_klass = tinst_klass = subtype;
4439       this_xk = tinst_xk = subtype_exact;
4440       this_flatten_array = tinst_flatten_array = flat_array;
4441     } else if (above_centerline(this_ptr) && !above_centerline(tinst_ptr)) {
4442       this_klass = tinst_klass; // tinst is down; keep down man
4443       this_xk = tinst_xk;
4444       this_flatten_array = tinst_flatten_array;
4445     } else if (above_centerline(tinst_ptr) && !above_centerline(this_ptr)) {
4446       tinst_klass = this_klass; // this is down; keep down man
4447       tinst_xk = this_xk;
4448       tinst_flatten_array = this_flatten_array;
4449     } else {
4450       this_xk = subtype_exact;  // either they are equal, or we'll do an LCA
4451       this_flatten_array = flat_array;
4452     }
4453   }
4454 
4455   // Check for classes now being equal
4456   if (tinst_klass->equals(this_klass)) {
4457     // If the klasses are equal, the constants may still differ.  Fall to
4458     // NotNull if they do (neither constant is NULL; that is a special case
4459     // handled elsewhere).
4460     res_klass = this_klass;
4461     res_xk = this_xk;
4462     res_flatten_array = this_flatten_array;
4463     return SUBTYPE;
4464   } // Else classes are not equal
4465 
4466   // Since klasses are different, we require a LCA in the Java
4467   // class hierarchy - which means we have to fall to at least NotNull.
4468   if (ptr == TopPTR || ptr == AnyNull || ptr == Constant) {
4469     ptr = NotNull;
4470   }
4471 
4472   // Now we find the LCA of Java classes
4473   ciKlass* k = this_klass->least_common_ancestor(tinst_klass);
4474 
4475   res_klass = k;
4476   res_xk = false;
4477   res_flatten_array = this_flatten_array_orig && tinst_flatten_array_orig;
4478 
4479   return LCA;
4480 }
4481 
4482 
4483 //------------------------java_mirror_type--------------------------------------
4484 ciType* TypeInstPtr::java_mirror_type(bool* is_val_mirror) const {
4485   // must be a singleton type
4486   if( const_oop() == NULL )  return NULL;
4487 
4488   // must be of type java.lang.Class
4489   if( klass() != ciEnv::current()->Class_klass() )  return NULL;
4490   return const_oop()->as_instance()->java_mirror_type(is_val_mirror);
4491 }
4492 
4493 
4494 //------------------------------xdual------------------------------------------
4495 // Dual: do NOT dual on klasses.  This means I do NOT understand the Java
4496 // inheritance mechanism.
4497 const Type *TypeInstPtr::xdual() const {
4498   return new TypeInstPtr(dual_ptr(), klass(), klass_is_exact(), const_oop(), dual_offset(), flatten_array(), dual_instance_id(), dual_speculative(), dual_inline_depth());
4499 }
4500 
4501 //------------------------------eq---------------------------------------------
4502 // Structural equality check for Type representations
4503 bool TypeInstPtr::eq( const Type *t ) const {
4504   const TypeInstPtr *p = t->is_instptr();
4505   return
4506     klass()->equals(p->klass()) &&
4507     flatten_array() == p->flatten_array() &&
4508     TypeOopPtr::eq(p);          // Check sub-type stuff
4509 }
4510 
4511 //------------------------------hash-------------------------------------------
4512 // Type-specific hashing function.
4513 int TypeInstPtr::hash(void) const {
4514   int hash = java_add(java_add((jint)klass()->hash(), (jint)TypeOopPtr::hash()), (jint)flatten_array());
4515   return hash;
4516 }
4517 
4518 bool TypeInstPtr::is_java_subtype_of_helper(const TypeOopPtr* other, bool this_exact, bool other_exact) const {
4519   if (!is_loaded() || !other->is_loaded()) {
4520     return false;
4521   }
4522   if (!other->isa_instptr()) {
4523     return false;
4524   }
4525 
4526   if (!other_exact) {
4527     return false;
4528   }
4529 
4530   if (other->klass()->equals(ciEnv::current()->Object_klass())) {
4531     return true;
4532   }
4533 
4534   if (!this_exact && klass()->is_interface()) {
4535     return false;
4536   }
4537 
4538   return _klass->is_subtype_of(other->klass());
4539 }
4540 
4541 bool TypeInstPtr::is_same_java_type_as(const TypeOopPtr* other) const {
4542   if (!is_loaded() || !other->is_loaded()) {
4543     return false;
4544   }
4545   if (!other->isa_instptr()) {
4546     return false;
4547   }
4548   return _klass->equals(other->_klass);
4549 }
4550 
4551 bool TypeInstPtr::maybe_java_subtype_of_helper(const TypeOopPtr* other, bool this_exact, bool other_exact) const {
4552   if (!is_loaded() || !other->is_loaded()) {
4553     return true;
4554   }
4555 
4556   if (other->isa_aryptr()) {
4557     return !this_exact && (_klass->equals(ciEnv::current()->Object_klass()) || _klass->is_interface());
4558   }
4559 
4560   if ((_klass->is_interface() && !this_exact) || (other->klass()->is_interface() /*&& !other_exact*/)) {
4561     return true;
4562   }
4563 
4564   assert(other->isa_instptr(), "unsupported");
4565 
4566   if (this_exact && other_exact) {
4567     return is_java_subtype_of(other);
4568   }
4569 
4570   if (!_klass->is_subtype_of(other->_klass) && !other->_klass->is_subtype_of(_klass)) {
4571     return false;
4572   }
4573 
4574   if (this_exact) {
4575     return _klass->is_subtype_of(other->_klass);
4576   }
4577 
4578   return true;
4579 }
4580 
4581 
4582 //------------------------------dump2------------------------------------------
4583 // Dump oop Type
4584 #ifndef PRODUCT
4585 void TypeInstPtr::dump2(Dict &d, uint depth, outputStream* st) const {
4586   // Print the name of the klass.
4587   klass()->print_name_on(st);
4588 
4589   switch( _ptr ) {
4590   case Constant:
4591     if (WizardMode || Verbose) {
4592       ResourceMark rm;
4593       stringStream ss;
4594 
4595       st->print(" ");
4596       const_oop()->print_oop(&ss);
4597       // 'const_oop->print_oop()' may emit newlines('\n') into ss.
4598       // suppress newlines from it so -XX:+Verbose -XX:+PrintIdeal dumps one-liner for each node.
4599       char* buf = ss.as_string(/* c_heap= */false);
4600       StringUtils::replace_no_expand(buf, "\n", "");
4601       st->print_raw(buf);
4602     }
4603   case BotPTR:
4604     if (!WizardMode && !Verbose) {
4605       if( _klass_is_exact ) st->print(":exact");
4606       break;
4607     }
4608   case TopPTR:
4609   case AnyNull:
4610   case NotNull:
4611     st->print(":%s", ptr_msg[_ptr]);
4612     if( _klass_is_exact ) st->print(":exact");
4613     break;
4614   default:
4615     break;
4616   }
4617 
4618   _offset.dump2(st);
4619 
4620   st->print(" *");
4621 
4622   if (flatten_array() && !klass()->is_inlinetype()) {
4623     st->print(" (flatten array)");
4624   }
4625 
4626   if (_instance_id == InstanceTop)
4627     st->print(",iid=top");
4628   else if (_instance_id != InstanceBot)
4629     st->print(",iid=%d",_instance_id);
4630 
4631   dump_inline_depth(st);
4632   dump_speculative(st);
4633 }
4634 #endif
4635 
4636 //------------------------------add_offset-------------------------------------
4637 const TypePtr* TypeInstPtr::add_offset(intptr_t offset) const {
4638   return make(_ptr, klass(), klass_is_exact(), const_oop(), xadd_offset(offset), flatten_array(),
4639               _instance_id, add_offset_speculative(offset), _inline_depth);
4640 }
4641 
4642 const TypeInstPtr* TypeInstPtr::with_offset(intptr_t offset) const {
4643   return make(_ptr, klass(), klass_is_exact(), const_oop(), Offset(offset), flatten_array(),
4644               _instance_id, with_offset_speculative(offset), _inline_depth);
4645 }
4646 
4647 const TypeInstPtr* TypeInstPtr::remove_speculative() const {
4648   if (_speculative == NULL) {
4649     return this;
4650   }
4651   assert(_inline_depth == InlineDepthTop || _inline_depth == InlineDepthBottom, "non speculative type shouldn't have inline depth");
4652   return make(_ptr, klass(), klass_is_exact(), const_oop(), _offset, flatten_array(),
4653               _instance_id, NULL, _inline_depth);
4654 }
4655 
4656 const TypePtr *TypeInstPtr::with_inline_depth(int depth) const {
4657   if (!UseInlineDepthForSpeculativeTypes) {
4658     return this;
4659   }
4660   return make(_ptr, klass(), klass_is_exact(), const_oop(), _offset, flatten_array(), _instance_id, _speculative, depth);
4661 }
4662 
4663 const TypePtr *TypeInstPtr::with_instance_id(int instance_id) const {
4664   assert(is_known_instance(), "should be known");
4665   return make(_ptr, klass(), klass_is_exact(), const_oop(), _offset, flatten_array(), instance_id, _speculative, _inline_depth);
4666 }
4667 
4668 const TypeInstPtr *TypeInstPtr::cast_to_flatten_array() const {
4669   return make(_ptr, klass(), klass_is_exact(), const_oop(), _offset, true, _instance_id, _speculative, _inline_depth);
4670 }
4671 
4672 const TypeKlassPtr* TypeInstPtr::as_klass_type(bool try_for_exact) const {
4673   bool xk = klass_is_exact();
4674   ciInstanceKlass* ik = klass()->as_instance_klass();
4675   if (try_for_exact && !xk && !ik->has_subklass() && !ik->is_final() && !ik->is_interface()) {
4676     Compile* C = Compile::current();
4677     Dependencies* deps = C->dependencies();
4678     deps->assert_leaf_type(ik);
4679     xk = true;
4680   }
4681   return TypeInstKlassPtr::make(xk ? TypePtr::Constant : TypePtr::NotNull, klass(), Offset(0), flatten_array());
4682 }
4683 
4684 //=============================================================================
4685 // Convenience common pre-built types.
4686 const TypeAryPtr *TypeAryPtr::RANGE;
4687 const TypeAryPtr *TypeAryPtr::OOPS;
4688 const TypeAryPtr *TypeAryPtr::NARROWOOPS;
4689 const TypeAryPtr *TypeAryPtr::BYTES;
4690 const TypeAryPtr *TypeAryPtr::SHORTS;
4691 const TypeAryPtr *TypeAryPtr::CHARS;
4692 const TypeAryPtr *TypeAryPtr::INTS;
4693 const TypeAryPtr *TypeAryPtr::LONGS;
4694 const TypeAryPtr *TypeAryPtr::FLOATS;
4695 const TypeAryPtr *TypeAryPtr::DOUBLES;
4696 const TypeAryPtr *TypeAryPtr::INLINES;
4697 
4698 //------------------------------make-------------------------------------------
4699 const TypeAryPtr* TypeAryPtr::make(PTR ptr, const TypeAry *ary, ciKlass* k, bool xk, Offset offset, Offset field_offset,
4700                                    int instance_id, const TypePtr* speculative, int inline_depth) {
4701   assert(!(k == NULL && ary->_elem->isa_int()),
4702          "integral arrays must be pre-equipped with a class");
4703   if (!xk)  xk = ary->ary_must_be_exact();
4704   assert(instance_id <= 0 || xk, "instances are always exactly typed");
4705   return (TypeAryPtr*)(new TypeAryPtr(ptr, NULL, ary, k, xk, offset, field_offset, instance_id, false, speculative, inline_depth))->hashcons();
4706 }
4707 
4708 //------------------------------make-------------------------------------------
4709 const TypeAryPtr* TypeAryPtr::make(PTR ptr, ciObject* o, const TypeAry *ary, ciKlass* k, bool xk, Offset offset, Offset field_offset,
4710                                    int instance_id, const TypePtr* speculative, int inline_depth,
4711                                    bool is_autobox_cache) {
4712   assert(!(k == NULL && ary->_elem->isa_int()),
4713          "integral arrays must be pre-equipped with a class");
4714   assert( (ptr==Constant && o) || (ptr!=Constant && !o), "" );
4715   if (!xk)  xk = (o != NULL) || ary->ary_must_be_exact();
4716   assert(instance_id <= 0 || xk, "instances are always exactly typed");
4717   return (TypeAryPtr*)(new TypeAryPtr(ptr, o, ary, k, xk, offset, field_offset, instance_id, is_autobox_cache, speculative, inline_depth))->hashcons();
4718 }
4719 
4720 //------------------------------cast_to_ptr_type-------------------------------
4721 const TypeAryPtr* TypeAryPtr::cast_to_ptr_type(PTR ptr) const {
4722   if( ptr == _ptr ) return this;
4723   return make(ptr, ptr == Constant ? const_oop() : NULL, _ary, klass(), klass_is_exact(), _offset, _field_offset, _instance_id, _speculative, _inline_depth, _is_autobox_cache);
4724 }
4725 
4726 
4727 //-----------------------------cast_to_exactness-------------------------------
4728 const TypeAryPtr* TypeAryPtr::cast_to_exactness(bool klass_is_exact) const {
4729   if( klass_is_exact == _klass_is_exact ) return this;
4730   if (_ary->ary_must_be_exact())  return this;  // cannot clear xk
4731 
4732   const TypeAry* new_ary = _ary;
4733   if (klass() != NULL && klass()->is_obj_array_klass() && klass_is_exact) {
4734     // An object array can't be flat or null-free if the klass is exact
4735     new_ary = TypeAry::make(elem(), size(), is_stable(), /* not_flat= */ true, /* not_null_free= */ true);
4736   }
4737   return make(ptr(), const_oop(), new_ary, klass(), klass_is_exact, _offset, _field_offset, _instance_id, _speculative, _inline_depth, _is_autobox_cache);
4738 }
4739 
4740 //-----------------------------cast_to_instance_id----------------------------
4741 const TypeAryPtr* TypeAryPtr::cast_to_instance_id(int instance_id) const {
4742   if( instance_id == _instance_id ) return this;
4743   return make(_ptr, const_oop(), _ary, klass(), _klass_is_exact, _offset, _field_offset, instance_id, _speculative, _inline_depth, _is_autobox_cache);
4744 }
4745 
4746 
4747 //-----------------------------max_array_length-------------------------------
4748 // A wrapper around arrayOopDesc::max_array_length(etype) with some input normalization.
4749 jint TypeAryPtr::max_array_length(BasicType etype) {
4750   if (!is_java_primitive(etype) && !is_reference_type(etype)) {
4751     if (etype == T_NARROWOOP) {
4752       etype = T_OBJECT;
4753     } else if (etype == T_ILLEGAL) { // bottom[]
4754       etype = T_BYTE; // will produce conservatively high value
4755     } else {
4756       fatal("not an element type: %s", type2name(etype));
4757     }
4758   }
4759   return arrayOopDesc::max_array_length(etype);
4760 }
4761 
4762 //-----------------------------narrow_size_type-------------------------------
4763 // Narrow the given size type to the index range for the given array base type.
4764 // Return NULL if the resulting int type becomes empty.
4765 const TypeInt* TypeAryPtr::narrow_size_type(const TypeInt* size) const {
4766   jint hi = size->_hi;
4767   jint lo = size->_lo;
4768   jint min_lo = 0;
4769   jint max_hi = max_array_length(elem()->basic_type());
4770   //if (index_not_size)  --max_hi;     // type of a valid array index, FTR
4771   bool chg = false;
4772   if (lo < min_lo) {
4773     lo = min_lo;
4774     if (size->is_con()) {
4775       hi = lo;
4776     }
4777     chg = true;
4778   }
4779   if (hi > max_hi) {
4780     hi = max_hi;
4781     if (size->is_con()) {
4782       lo = hi;
4783     }
4784     chg = true;
4785   }
4786   // Negative length arrays will produce weird intermediate dead fast-path code
4787   if (lo > hi)
4788     return TypeInt::ZERO;
4789   if (!chg)
4790     return size;
4791   return TypeInt::make(lo, hi, Type::WidenMin);
4792 }
4793 
4794 //-------------------------------cast_to_size----------------------------------
4795 const TypeAryPtr* TypeAryPtr::cast_to_size(const TypeInt* new_size) const {
4796   assert(new_size != NULL, "");
4797   new_size = narrow_size_type(new_size);
4798   if (new_size == size())  return this;
4799   const TypeAry* new_ary = TypeAry::make(elem(), new_size, is_stable(), is_not_flat(), is_not_null_free());
4800   return make(ptr(), const_oop(), new_ary, klass(), klass_is_exact(), _offset, _field_offset, _instance_id, _speculative, _inline_depth, _is_autobox_cache);
4801 }
4802 
4803 //-------------------------------cast_to_not_flat------------------------------
4804 const TypeAryPtr* TypeAryPtr::cast_to_not_flat(bool not_flat) const {
4805   if (not_flat == is_not_flat()) {
4806     return this;
4807   }
4808   const TypeAry* new_ary = TypeAry::make(elem(), size(), is_stable(), not_flat, is_not_null_free());
4809   return make(ptr(), const_oop(), new_ary, klass(), klass_is_exact(), _offset, _field_offset, _instance_id, _speculative, _inline_depth, _is_autobox_cache);
4810 }
4811 
4812 //-------------------------------cast_to_not_null_free-------------------------
4813 const TypeAryPtr* TypeAryPtr::cast_to_not_null_free(bool not_null_free) const {
4814   if (not_null_free == is_not_null_free()) {
4815     return this;
4816   }
4817   // Not null free implies not flat
4818   const TypeAry* new_ary = TypeAry::make(elem(), size(), is_stable(), not_null_free ? true : is_not_flat(), not_null_free);
4819   return make(ptr(), const_oop(), new_ary, klass(), klass_is_exact(), _offset, _field_offset, _instance_id, _speculative, _inline_depth, _is_autobox_cache);
4820 }
4821 
4822 //---------------------------------update_properties---------------------------
4823 const TypeAryPtr* TypeAryPtr::update_properties(const TypeAryPtr* from) const {
4824   if ((from->is_flat()          && is_not_flat()) ||
4825       (from->is_not_flat()      && is_flat()) ||
4826       (from->is_null_free()     && is_not_null_free()) ||
4827       (from->is_not_null_free() && is_null_free())) {
4828     return NULL; // Inconsistent properties
4829   } else if (from->is_not_null_free()) {
4830     return cast_to_not_null_free(); // Implies not flat
4831   } else if (from->is_not_flat()) {
4832     return cast_to_not_flat();
4833   }
4834   return this;
4835 }
4836 
4837 jint TypeAryPtr::flat_layout_helper() const {
4838   return klass()->as_flat_array_klass()->layout_helper();
4839 }
4840 
4841 int TypeAryPtr::flat_elem_size() const {
4842   return klass()->as_flat_array_klass()->element_byte_size();
4843 }
4844 
4845 int TypeAryPtr::flat_log_elem_size() const {
4846   return klass()->as_flat_array_klass()->log2_element_size();
4847 }
4848 
4849 //------------------------------cast_to_stable---------------------------------
4850 const TypeAryPtr* TypeAryPtr::cast_to_stable(bool stable, int stable_dimension) const {
4851   if (stable_dimension <= 0 || (stable_dimension == 1 && stable == this->is_stable()))
4852     return this;
4853 
4854   const Type* elem = this->elem();
4855   const TypePtr* elem_ptr = elem->make_ptr();
4856 
4857   if (stable_dimension > 1 && elem_ptr != NULL && elem_ptr->isa_aryptr()) {
4858     // If this is widened from a narrow oop, TypeAry::make will re-narrow it.
4859     elem = elem_ptr = elem_ptr->is_aryptr()->cast_to_stable(stable, stable_dimension - 1);
4860   }
4861 
4862   const TypeAry* new_ary = TypeAry::make(elem, size(), stable, is_not_flat(), is_not_null_free());
4863 
4864   return make(ptr(), const_oop(), new_ary, klass(), klass_is_exact(), _offset, _field_offset, _instance_id, _speculative, _inline_depth, _is_autobox_cache);
4865 }
4866 
4867 //-----------------------------stable_dimension--------------------------------
4868 int TypeAryPtr::stable_dimension() const {
4869   if (!is_stable())  return 0;
4870   int dim = 1;
4871   const TypePtr* elem_ptr = elem()->make_ptr();
4872   if (elem_ptr != NULL && elem_ptr->isa_aryptr())
4873     dim += elem_ptr->is_aryptr()->stable_dimension();
4874   return dim;
4875 }
4876 
4877 //----------------------cast_to_autobox_cache-----------------------------------
4878 const TypeAryPtr* TypeAryPtr::cast_to_autobox_cache() const {
4879   if (is_autobox_cache())  return this;
4880   const TypeOopPtr* etype = elem()->make_oopptr();
4881   if (etype == NULL)  return this;
4882   // TODO fix with JDK-8284164
4883   // Ignore inline types to not confuse logic in TypeAryPtr::compute_klass
4884   if (!etype->is_inlinetypeptr()) {
4885     // The pointers in the autobox arrays are always non-null.
4886     etype = etype->cast_to_ptr_type(TypePtr::NotNull)->is_oopptr();
4887   }
4888   const TypeAry* new_ary = TypeAry::make(etype, size(), is_stable(), is_not_flat(), is_not_null_free());
4889   return make(ptr(), const_oop(), new_ary, klass(), klass_is_exact(), _offset, _field_offset, _instance_id, _speculative, _inline_depth, /*is_autobox_cache=*/true);
4890 }
4891 
4892 //------------------------------eq---------------------------------------------
4893 // Structural equality check for Type representations
4894 bool TypeAryPtr::eq( const Type *t ) const {
4895   const TypeAryPtr *p = t->is_aryptr();
4896   return
4897     _ary == p->_ary &&  // Check array
4898     TypeOopPtr::eq(p) &&// Check sub-parts
4899     _field_offset == p->_field_offset;
4900 }
4901 
4902 //------------------------------hash-------------------------------------------
4903 // Type-specific hashing function.
4904 int TypeAryPtr::hash(void) const {
4905   return (intptr_t)_ary + TypeOopPtr::hash() + _field_offset.get();
4906 }
4907 
4908 bool TypeAryPtr::is_java_subtype_of_helper(const TypeOopPtr* other, bool this_exact, bool other_exact) const {
4909   if (other->klass() == ciEnv::current()->Object_klass() && other_exact) {
4910     return true;
4911   }
4912 
4913   if (!is_loaded() || !other->is_loaded() || other->klass() == NULL || klass() == NULL) {
4914     return false;
4915   }
4916   if (other->isa_instptr()) {
4917     return _klass->is_subtype_of(other->_klass) && other_exact;
4918   }
4919   if (klass() == NULL) {
4920     return false;
4921   }
4922   assert(other->isa_aryptr(), "");
4923   const TypeAryPtr* other_ary = other->isa_aryptr();
4924   if (other_ary->elem()->make_oopptr() && elem()->make_oopptr()) {
4925     return elem()->make_oopptr()->is_java_subtype_of_helper(other_ary->elem()->make_oopptr(), this_exact, other_exact);
4926   }
4927   if (!other_ary->elem()->make_oopptr() && !elem()->make_oopptr()) {
4928     return _klass->is_subtype_of(other->_klass);
4929   }
4930   return false;
4931 }
4932 
4933 bool TypeAryPtr::is_same_java_type_as(const TypeOopPtr* other) const {
4934   if (!other->isa_aryptr() ||
4935       !is_loaded() || !other->is_loaded() || klass() == NULL || other->klass() == NULL) {
4936     return false;
4937   }
4938   const TypeAryPtr* other_ary = other->isa_aryptr();
4939   if (other_ary->elem()->make_oopptr() && elem()->make_oopptr()) {
4940     return elem()->make_oopptr()->is_same_java_type_as(other_ary->elem()->make_oopptr());
4941   }
4942   if (!other_ary->elem()->make_oopptr() && !elem()->make_oopptr()) {
4943     return _klass->equals(other->_klass);
4944   }
4945   return false;
4946 }
4947 
4948 bool TypeAryPtr::maybe_java_subtype_of_helper(const TypeOopPtr* other, bool this_exact, bool other_exact) const {
4949   if (other->klass() == ciEnv::current()->Object_klass()) {
4950     return true;
4951   }
4952 
4953   if (!is_loaded() || !other->is_loaded() || klass() == NULL || other->klass() == NULL) {
4954     return true;
4955   }
4956   if (other->isa_instptr()) {
4957     return (!other_exact && other->_klass->is_interface()) || _klass->is_subtype_of(other->_klass);
4958   }
4959   assert(other->isa_aryptr(), "");
4960 
4961   if (this_exact && other_exact) {
4962     return is_java_subtype_of(other);
4963   }
4964 
4965   const TypeAryPtr* other_ary = other->isa_aryptr();
4966   if (other_ary->elem()->make_oopptr() && elem()->make_oopptr()) {
4967     return elem()->make_oopptr()->maybe_java_subtype_of_helper(other_ary->elem()->make_oopptr(), this_exact,
4968                                                                other_exact);
4969   }
4970   if (!other_ary->elem()->make_oopptr() && !elem()->make_oopptr()) {
4971     return _klass->is_subtype_of(other->_klass);
4972   }
4973   return false;
4974 }
4975 //------------------------------meet-------------------------------------------
4976 // Compute the MEET of two types.  It returns a new Type object.
4977 const Type *TypeAryPtr::xmeet_helper(const Type *t) const {
4978   // Perform a fast test for common case; meeting the same types together.
4979   if( this == t ) return this;  // Meeting same type-rep?
4980   // Current "this->_base" is Pointer
4981   switch (t->base()) {          // switch on original type
4982 
4983   // Mixing ints & oops happens when javac reuses local variables
4984   case Int:
4985   case Long:
4986   case FloatTop:
4987   case FloatCon:
4988   case FloatBot:
4989   case DoubleTop:
4990   case DoubleCon:
4991   case DoubleBot:
4992   case NarrowOop:
4993   case NarrowKlass:
4994   case Bottom:                  // Ye Olde Default
4995     return Type::BOTTOM;
4996   case Top:
4997     return this;
4998 
4999   default:                      // All else is a mistake
5000     typerr(t);
5001 
5002   case OopPtr: {                // Meeting to OopPtrs
5003     // Found a OopPtr type vs self-AryPtr type
5004     const TypeOopPtr *tp = t->is_oopptr();
5005     Offset offset = meet_offset(tp->offset());
5006     PTR ptr = meet_ptr(tp->ptr());
5007     int depth = meet_inline_depth(tp->inline_depth());
5008     const TypePtr* speculative = xmeet_speculative(tp);
5009     switch (tp->ptr()) {
5010     case TopPTR:
5011     case AnyNull: {
5012       int instance_id = meet_instance_id(InstanceTop);
5013       return make(ptr, (ptr == Constant ? const_oop() : NULL),
5014                   _ary, _klass, _klass_is_exact, offset, _field_offset, instance_id, speculative, depth);
5015     }
5016     case BotPTR:
5017     case NotNull: {
5018       int instance_id = meet_instance_id(tp->instance_id());
5019       return TypeOopPtr::make(ptr, offset, instance_id, speculative, depth);
5020     }
5021     default: ShouldNotReachHere();
5022     }
5023   }
5024 
5025   case AnyPtr: {                // Meeting two AnyPtrs
5026     // Found an AnyPtr type vs self-AryPtr type
5027     const TypePtr *tp = t->is_ptr();
5028     Offset offset = meet_offset(tp->offset());
5029     PTR ptr = meet_ptr(tp->ptr());
5030     const TypePtr* speculative = xmeet_speculative(tp);
5031     int depth = meet_inline_depth(tp->inline_depth());
5032     switch (tp->ptr()) {
5033     case TopPTR:
5034       return this;
5035     case BotPTR:
5036     case NotNull:
5037       return TypePtr::make(AnyPtr, ptr, offset, speculative, depth);
5038     case Null:
5039       if( ptr == Null ) return TypePtr::make(AnyPtr, ptr, offset, speculative, depth);
5040       // else fall through to AnyNull
5041     case AnyNull: {
5042       int instance_id = meet_instance_id(InstanceTop);
5043       return make(ptr, (ptr == Constant ? const_oop() : NULL),
5044                   _ary, _klass, _klass_is_exact, offset, _field_offset, instance_id, speculative, depth);
5045     }
5046     default: ShouldNotReachHere();
5047     }
5048   }
5049 
5050   case MetadataPtr:
5051   case KlassPtr:
5052   case InstKlassPtr:
5053   case AryKlassPtr:
5054   case RawPtr: return TypePtr::BOTTOM;
5055 
5056   case AryPtr: {                // Meeting 2 references?
5057     const TypeAryPtr *tap = t->is_aryptr();
5058     Offset off = meet_offset(tap->offset());
5059     Offset field_off = meet_field_offset(tap->field_offset());
5060     const TypeAry *tary = _ary->meet_speculative(tap->_ary)->is_ary();
5061     PTR ptr = meet_ptr(tap->ptr());
5062     int instance_id = meet_instance_id(tap->instance_id());
5063     const TypePtr* speculative = xmeet_speculative(tap);
5064     int depth = meet_inline_depth(tap->inline_depth());
5065 
5066     ciKlass* res_klass = NULL;
5067     bool res_xk = false;
5068     bool res_not_flat = false;
5069     bool res_not_null_free = false;
5070     const Type* res_elem = NULL;
5071     if (meet_aryptr(ptr, _ary->_elem, tap->_ary->_elem, this->klass(), tap->klass(),
5072                     this->klass_is_exact(), tap->klass_is_exact(), this->ptr(), tap->ptr(),
5073                     this->is_not_flat(), tap->is_not_flat(),
5074                     this->is_not_null_free(), tap->is_not_null_free(),
5075                     res_elem, res_klass, res_xk, res_not_flat, res_not_null_free) == NOT_SUBTYPE) {
5076       instance_id = InstanceBot;
5077     } else if (klass() != NULL && tap->klass() != NULL && klass()->is_flat_array_klass() != tap->klass()->is_flat_array_klass()) {
5078       // Meeting flattened inline type array with non-flattened array. Adjust (field) offset accordingly.
5079       if (tary->_elem->isa_inlinetype()) {
5080         // Result is flattened
5081         off = Offset(is_flat() ? offset() : tap->offset());
5082         field_off = is_flat() ? field_offset() : tap->field_offset();
5083       } else if (tary->_elem->make_oopptr() != NULL && tary->_elem->make_oopptr()->isa_instptr() && below_centerline(ptr)) {
5084         // Result is non-flattened
5085         off = Offset(flattened_offset()).meet(Offset(tap->flattened_offset()));
5086         field_off = Offset::bottom;
5087       }
5088     }
5089 
5090     ciObject* o = NULL;             // Assume not constant when done
5091     ciObject* this_oop = const_oop();
5092     ciObject* tap_oop = tap->const_oop();
5093     if (ptr == Constant) {
5094       if (this_oop != NULL && tap_oop != NULL &&
5095           this_oop->equals(tap_oop)) {
5096         o = tap_oop;
5097       } else if (above_centerline(_ptr)) {
5098         o = tap_oop;
5099       } else if (above_centerline(tap->_ptr)) {
5100         o = this_oop;
5101       } else {
5102         ptr = NotNull;
5103       }
5104     }
5105     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);
5106   }
5107 
5108   // All arrays inherit from Object class
5109   case InstPtr: {
5110     const TypeInstPtr *tp = t->is_instptr();
5111     Offset offset = meet_offset(tp->offset());
5112     PTR ptr = meet_ptr(tp->ptr());
5113     int instance_id = meet_instance_id(tp->instance_id());
5114     const TypePtr* speculative = xmeet_speculative(tp);
5115     int depth = meet_inline_depth(tp->inline_depth());
5116     switch (ptr) {
5117     case TopPTR:
5118     case AnyNull:                // Fall 'down' to dual of object klass
5119       // For instances when a subclass meets a superclass we fall
5120       // below the centerline when the superclass is exact. We need to
5121       // do the same here.
5122       if (tp->klass()->equals(ciEnv::current()->Object_klass()) && !tp->klass_is_exact() && !tp->flatten_array()) {
5123         return make(ptr, _ary, _klass, _klass_is_exact, offset, _field_offset, instance_id, speculative, depth);
5124       } else {
5125         // cannot subclass, so the meet has to fall badly below the centerline
5126         ptr = NotNull;
5127         instance_id = InstanceBot;
5128         return TypeInstPtr::make(ptr, ciEnv::current()->Object_klass(), false, NULL, offset, false, instance_id, speculative, depth);
5129       }
5130     case Constant:
5131     case NotNull:
5132     case BotPTR:                // Fall down to object klass
5133       // LCA is object_klass, but if we subclass from the top we can do better
5134       if (above_centerline(tp->ptr())) {
5135         // If 'tp'  is above the centerline and it is Object class
5136         // then we can subclass in the Java class hierarchy.
5137         // For instances when a subclass meets a superclass we fall
5138         // below the centerline when the superclass is exact. We need
5139         // to do the same here.
5140         if (tp->klass()->equals(ciEnv::current()->Object_klass()) && !tp->klass_is_exact() && !tp->flatten_array()) {
5141           // that is, my array type is a subtype of 'tp' klass
5142           return make(ptr, (ptr == Constant ? const_oop() : NULL),
5143                       _ary, _klass, _klass_is_exact, offset, _field_offset, instance_id, speculative, depth);
5144         }
5145       }
5146       // The other case cannot happen, since t cannot be a subtype of an array.
5147       // The meet falls down to Object class below centerline.
5148       if (ptr == Constant) {
5149          ptr = NotNull;
5150       }
5151       if (instance_id > 0) {
5152         instance_id = InstanceBot;
5153       }
5154       return TypeInstPtr::make(ptr, ciEnv::current()->Object_klass(), false, NULL, offset, false, instance_id, speculative, depth);
5155     default: typerr(t);
5156     }
5157   }
5158 
5159   case InlineType: {
5160     const TypeInlineType* tv = t->is_inlinetype();
5161     if (above_centerline(ptr())) {
5162       return TypeInstPtr::NOTNULL;
5163     } else {
5164       PTR ptr = this->_ptr;
5165       if (ptr == Constant) {
5166         ptr = NotNull;
5167       }
5168       return TypeInstPtr::make(ptr, ciEnv::current()->Object_klass());
5169     }
5170   }
5171   }
5172   return this;                  // Lint noise
5173 }
5174 
5175 
5176 TypePtr::MeetResult TypePtr::meet_aryptr(PTR& ptr, const Type* this_elem, const Type* tap_elem,
5177                                          ciKlass* this_klass, ciKlass* tap_klass,
5178                                          bool this_xk, bool tap_xk, PTR this_ptr, PTR tap_ptr,
5179                                          bool this_not_flat, bool tap_not_flat,
5180                                          bool this_not_null_free, bool tap_not_null_free,
5181                                          const Type*& res_elem, ciKlass*& res_klass,
5182                                          bool& res_xk, bool& res_not_flat, bool& res_not_null_free) {
5183   res_klass = NULL;
5184   MeetResult result = SUBTYPE;
5185   res_elem = this_elem->meet(tap_elem);
5186   res_not_flat = this_not_flat && tap_not_flat;
5187   res_not_null_free = this_not_null_free && tap_not_null_free;
5188 
5189   if (res_elem->isa_int()) {
5190     // Integral array element types have irrelevant lattice relations.
5191     // It is the klass that determines array layout, not the element type.
5192     if (this_klass == NULL) {
5193       res_klass = tap_klass;
5194     } else if (tap_klass == NULL || tap_klass == this_klass) {
5195       res_klass = this_klass;
5196     } else {
5197       // Something like byte[int+] meets char[int+].
5198       // This must fall to bottom, not (int[-128..65535])[int+].
5199       // instance_id = InstanceBot;
5200       res_elem = Type::BOTTOM;
5201       result = NOT_SUBTYPE;
5202     }
5203   } else // Non integral arrays.
5204     // Must fall to bottom if exact klasses in upper lattice
5205     // are not equal or super klass is exact.
5206     if ((above_centerline(ptr) || ptr == Constant) && this_klass != tap_klass &&
5207         // meet with top[] and bottom[] are processed further down:
5208         tap_klass != NULL  && this_klass != NULL   &&
5209         // both are exact and not equal:
5210         ((tap_xk && this_xk) ||
5211          // 'tap'  is exact and super or unrelated:
5212          (tap_xk && !tap_klass->is_subtype_of(this_klass)) ||
5213          // 'this' is exact and super or unrelated:
5214          (this_xk && !this_klass->is_subtype_of(tap_klass)))) {
5215       if (above_centerline(ptr) || (res_elem->make_ptr() && above_centerline(res_elem->make_ptr()->_ptr)) ||
5216           res_elem->isa_inlinetype()) {
5217         res_elem = Type::BOTTOM;
5218       }
5219       ptr = NotNull;
5220       res_xk = false;
5221       return NOT_SUBTYPE;
5222     }
5223 
5224   res_xk = false;
5225   switch (tap_ptr) {
5226     case AnyNull:
5227     case TopPTR:
5228       // Compute new klass on demand, do not use tap->_klass
5229       if (below_centerline(this_ptr)) {
5230         res_xk = this_xk;
5231         if (this_elem->isa_inlinetype()) {
5232           res_elem = this_elem;
5233         }
5234       } else {
5235         res_xk = (tap_xk || this_xk);
5236       }
5237       break;
5238     case Constant: {
5239       if (this_ptr == Constant) {
5240         res_xk = true;
5241       } else if(above_centerline(this_ptr)) {
5242         res_xk = true;
5243       } else {
5244         // Only precise for identical arrays
5245         res_xk = this_xk && (this_klass == tap_klass);
5246       }
5247       break;
5248     }
5249     case NotNull:
5250     case BotPTR:
5251       // Compute new klass on demand, do not use tap->_klass
5252       if (above_centerline(this_ptr)) {
5253         res_xk = tap_xk;
5254         if (tap_elem->isa_inlinetype()) {
5255           res_elem = tap_elem;
5256         }
5257       } else {
5258         res_xk = (tap_xk && this_xk) &&
5259           (this_klass == tap_klass); // Only precise for identical arrays
5260       }
5261       break;
5262     default:  {
5263       ShouldNotReachHere();
5264       return result;
5265     }
5266   }
5267 
5268   return result;
5269 }
5270 
5271 
5272 //------------------------------xdual------------------------------------------
5273 // Dual: compute field-by-field dual
5274 const Type *TypeAryPtr::xdual() const {
5275   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());
5276 }
5277 
5278 Type::Offset TypeAryPtr::meet_field_offset(const Type::Offset offset) const {
5279   return _field_offset.meet(offset);
5280 }
5281 
5282 //------------------------------dual_offset------------------------------------
5283 Type::Offset TypeAryPtr::dual_field_offset() const {
5284   return _field_offset.dual();
5285 }
5286 
5287 //----------------------interface_vs_oop---------------------------------------
5288 #ifdef ASSERT
5289 bool TypeAryPtr::interface_vs_oop(const Type *t) const {
5290   const TypeAryPtr* t_aryptr = t->isa_aryptr();
5291   if (t_aryptr) {
5292     return _ary->interface_vs_oop(t_aryptr->_ary);
5293   }
5294   return false;
5295 }
5296 #endif
5297 
5298 //------------------------------dump2------------------------------------------
5299 #ifndef PRODUCT
5300 void TypeAryPtr::dump2( Dict &d, uint depth, outputStream *st ) const {
5301   _ary->dump2(d,depth,st);
5302   switch( _ptr ) {
5303   case Constant:
5304     const_oop()->print(st);
5305     break;
5306   case BotPTR:
5307     if (!WizardMode && !Verbose) {
5308       if( _klass_is_exact ) st->print(":exact");
5309       break;
5310     }
5311   case TopPTR:
5312   case AnyNull:
5313   case NotNull:
5314     st->print(":%s", ptr_msg[_ptr]);
5315     if( _klass_is_exact ) st->print(":exact");
5316     break;
5317   default:
5318     break;
5319   }
5320 
5321   if (is_flat()) {
5322     st->print("(");
5323     _field_offset.dump2(st);
5324     st->print(")");
5325   }
5326   if (offset() != 0) {
5327     int header_size = objArrayOopDesc::header_size() * wordSize;
5328     if( _offset == Offset::top )       st->print("+undefined");
5329     else if( _offset == Offset::bottom )  st->print("+any");
5330     else if( offset() < header_size ) st->print("+%d", offset());
5331     else {
5332       BasicType basic_elem_type = elem()->basic_type();
5333       if (basic_elem_type == T_ILLEGAL) {
5334         st->print("+any");
5335       } else {
5336         int array_base = arrayOopDesc::base_offset_in_bytes(basic_elem_type);
5337         int elem_size = type2aelembytes(basic_elem_type);
5338         st->print("[%d]", (offset() - array_base)/elem_size);
5339       }
5340     }
5341   }
5342   st->print(" *");
5343   if (_instance_id == InstanceTop)
5344     st->print(",iid=top");
5345   else if (_instance_id != InstanceBot)
5346     st->print(",iid=%d",_instance_id);
5347 
5348   dump_inline_depth(st);
5349   dump_speculative(st);
5350 }
5351 #endif
5352 
5353 bool TypeAryPtr::empty(void) const {
5354   if (_ary->empty())       return true;
5355   return TypeOopPtr::empty();
5356 }
5357 
5358 //------------------------------add_offset-------------------------------------
5359 const TypePtr *TypeAryPtr::add_offset(intptr_t offset) const {
5360   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);
5361 }
5362 
5363 const TypeAryPtr* TypeAryPtr::with_offset(intptr_t offset) const {
5364   return make(_ptr, _const_oop, _ary, _klass, _klass_is_exact, Offset(offset), _field_offset, _instance_id, with_offset_speculative(offset), _inline_depth, _is_autobox_cache);
5365 }
5366 
5367 const TypeAryPtr* TypeAryPtr::with_ary(const TypeAry* ary) const {
5368   return make(_ptr, _const_oop, ary, _klass, _klass_is_exact, _offset, _field_offset, _instance_id, _speculative, _inline_depth, _is_autobox_cache);
5369 }
5370 
5371 const TypeAryPtr* TypeAryPtr::remove_speculative() const {
5372   if (_speculative == NULL) {
5373     return this;
5374   }
5375   assert(_inline_depth == InlineDepthTop || _inline_depth == InlineDepthBottom, "non speculative type shouldn't have inline depth");
5376   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);
5377 }
5378 
5379 const Type* TypeAryPtr::cleanup_speculative() const {
5380   if (speculative() == NULL) {
5381     return this;
5382   }
5383   // Keep speculative part if it contains information about flat-/nullability
5384   const TypeAryPtr* spec_aryptr = speculative()->isa_aryptr();
5385   if (spec_aryptr != NULL && (spec_aryptr->is_not_flat() || spec_aryptr->is_not_null_free())) {
5386     return this;
5387   }
5388   return TypeOopPtr::cleanup_speculative();
5389 }
5390 
5391 const TypePtr *TypeAryPtr::with_inline_depth(int depth) const {
5392   if (!UseInlineDepthForSpeculativeTypes) {
5393     return this;
5394   }
5395   return make(_ptr, _const_oop, _ary->remove_speculative()->is_ary(), _klass, _klass_is_exact, _offset, _field_offset, _instance_id, _speculative, depth, _is_autobox_cache);
5396 }
5397 
5398 const TypeAryPtr* TypeAryPtr::with_field_offset(int offset) const {
5399   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);
5400 }
5401 
5402 const TypePtr* TypeAryPtr::add_field_offset_and_offset(intptr_t offset) const {
5403   int adj = 0;
5404   if (offset != Type::OffsetBot && offset != Type::OffsetTop) {
5405     const Type* elemtype = elem();
5406     if (elemtype->isa_inlinetype()) {
5407       if (_offset.get() != OffsetBot && _offset.get() != OffsetTop) {
5408         adj = _offset.get();
5409         offset += _offset.get();
5410       }
5411       uint header = arrayOopDesc::base_offset_in_bytes(T_OBJECT);
5412       if (_field_offset.get() != OffsetBot && _field_offset.get() != OffsetTop) {
5413         offset += _field_offset.get();
5414         if (_offset.get() == OffsetBot || _offset.get() == OffsetTop) {
5415           offset += header;
5416         }
5417       }
5418       if (offset >= (intptr_t)header || offset < 0) {
5419         // Try to get the field of the inline type array element we are pointing to
5420         ciKlass* arytype_klass = klass();
5421         ciFlatArrayKlass* vak = arytype_klass->as_flat_array_klass();
5422         ciInlineKlass* vk = vak->element_klass()->as_inline_klass();
5423         int shift = vak->log2_element_size();
5424         int mask = (1 << shift) - 1;
5425         intptr_t field_offset = ((offset - header) & mask);
5426         ciField* field = vk->get_field_by_offset(field_offset + vk->first_field_offset(), false);
5427         if (field != NULL) {
5428           return with_field_offset(field_offset)->add_offset(offset - field_offset - adj);
5429         }
5430       }
5431     }
5432   }
5433   return add_offset(offset - adj);
5434 }
5435 
5436 // Return offset incremented by field_offset for flattened inline type arrays
5437 const int TypeAryPtr::flattened_offset() const {
5438   int offset = _offset.get();
5439   if (offset != Type::OffsetBot && offset != Type::OffsetTop &&
5440       _field_offset != Offset::bottom && _field_offset != Offset::top) {
5441     offset += _field_offset.get();
5442   }
5443   return offset;
5444 }
5445 
5446 const TypePtr *TypeAryPtr::with_instance_id(int instance_id) const {
5447   assert(is_known_instance(), "should be known");
5448   return make(_ptr, _const_oop, _ary->remove_speculative()->is_ary(), _klass, _klass_is_exact, _offset, _field_offset, instance_id, _speculative, _inline_depth);
5449 }
5450 
5451 //=============================================================================
5452 
5453 
5454 //------------------------------hash-------------------------------------------
5455 // Type-specific hashing function.
5456 int TypeNarrowPtr::hash(void) const {
5457   return _ptrtype->hash() + 7;
5458 }
5459 
5460 bool TypeNarrowPtr::singleton(void) const {    // TRUE if type is a singleton
5461   return _ptrtype->singleton();
5462 }
5463 
5464 bool TypeNarrowPtr::empty(void) const {
5465   return _ptrtype->empty();
5466 }
5467 
5468 intptr_t TypeNarrowPtr::get_con() const {
5469   return _ptrtype->get_con();
5470 }
5471 
5472 bool TypeNarrowPtr::eq( const Type *t ) const {
5473   const TypeNarrowPtr* tc = isa_same_narrowptr(t);
5474   if (tc != NULL) {
5475     if (_ptrtype->base() != tc->_ptrtype->base()) {
5476       return false;
5477     }
5478     return tc->_ptrtype->eq(_ptrtype);
5479   }
5480   return false;
5481 }
5482 
5483 const Type *TypeNarrowPtr::xdual() const {    // Compute dual right now.
5484   const TypePtr* odual = _ptrtype->dual()->is_ptr();
5485   return make_same_narrowptr(odual);
5486 }
5487 
5488 
5489 const Type *TypeNarrowPtr::filter_helper(const Type *kills, bool include_speculative) const {
5490   if (isa_same_narrowptr(kills)) {
5491     const Type* ft =_ptrtype->filter_helper(is_same_narrowptr(kills)->_ptrtype, include_speculative);
5492     if (ft->empty())
5493       return Type::TOP;           // Canonical empty value
5494     if (ft->isa_ptr()) {
5495       return make_hash_same_narrowptr(ft->isa_ptr());
5496     }
5497     return ft;
5498   } else if (kills->isa_ptr()) {
5499     const Type* ft = _ptrtype->join_helper(kills, include_speculative);
5500     if (ft->empty())
5501       return Type::TOP;           // Canonical empty value
5502     return ft;
5503   } else {
5504     return Type::TOP;
5505   }
5506 }
5507 
5508 //------------------------------xmeet------------------------------------------
5509 // Compute the MEET of two types.  It returns a new Type object.
5510 const Type *TypeNarrowPtr::xmeet( const Type *t ) const {
5511   // Perform a fast test for common case; meeting the same types together.
5512   if( this == t ) return this;  // Meeting same type-rep?
5513 
5514   if (t->base() == base()) {
5515     const Type* result = _ptrtype->xmeet(t->make_ptr());
5516     if (result->isa_ptr()) {
5517       return make_hash_same_narrowptr(result->is_ptr());
5518     }
5519     return result;
5520   }
5521 
5522   // Current "this->_base" is NarrowKlass or NarrowOop
5523   switch (t->base()) {          // switch on original type
5524 
5525   case Int:                     // Mixing ints & oops happens when javac
5526   case Long:                    // reuses local variables
5527   case FloatTop:
5528   case FloatCon:
5529   case FloatBot:
5530   case DoubleTop:
5531   case DoubleCon:
5532   case DoubleBot:
5533   case AnyPtr:
5534   case RawPtr:
5535   case OopPtr:
5536   case InstPtr:
5537   case AryPtr:
5538   case MetadataPtr:
5539   case KlassPtr:
5540   case InstKlassPtr:
5541   case AryKlassPtr:
5542   case NarrowOop:
5543   case NarrowKlass:
5544   case Bottom:                  // Ye Olde Default
5545     return Type::BOTTOM;
5546   case Top:
5547     return this;
5548 
5549   case InlineType:
5550     return t->xmeet(this);
5551 
5552   default:                      // All else is a mistake
5553     typerr(t);
5554 
5555   } // End of switch
5556 
5557   return this;
5558 }
5559 
5560 #ifndef PRODUCT
5561 void TypeNarrowPtr::dump2( Dict & d, uint depth, outputStream *st ) const {
5562   _ptrtype->dump2(d, depth, st);
5563 }
5564 #endif
5565 
5566 const TypeNarrowOop *TypeNarrowOop::BOTTOM;
5567 const TypeNarrowOop *TypeNarrowOop::NULL_PTR;
5568 
5569 
5570 const TypeNarrowOop* TypeNarrowOop::make(const TypePtr* type) {
5571   return (const TypeNarrowOop*)(new TypeNarrowOop(type))->hashcons();
5572 }
5573 
5574 const TypeNarrowOop* TypeNarrowOop::remove_speculative() const {
5575   return make(_ptrtype->remove_speculative()->is_ptr());
5576 }
5577 
5578 const Type* TypeNarrowOop::cleanup_speculative() const {
5579   return make(_ptrtype->cleanup_speculative()->is_ptr());
5580 }
5581 
5582 #ifndef PRODUCT
5583 void TypeNarrowOop::dump2( Dict & d, uint depth, outputStream *st ) const {
5584   st->print("narrowoop: ");
5585   TypeNarrowPtr::dump2(d, depth, st);
5586 }
5587 #endif
5588 
5589 const TypeNarrowKlass *TypeNarrowKlass::NULL_PTR;
5590 
5591 const TypeNarrowKlass* TypeNarrowKlass::make(const TypePtr* type) {
5592   return (const TypeNarrowKlass*)(new TypeNarrowKlass(type))->hashcons();
5593 }
5594 
5595 #ifndef PRODUCT
5596 void TypeNarrowKlass::dump2( Dict & d, uint depth, outputStream *st ) const {
5597   st->print("narrowklass: ");
5598   TypeNarrowPtr::dump2(d, depth, st);
5599 }
5600 #endif
5601 
5602 
5603 //------------------------------eq---------------------------------------------
5604 // Structural equality check for Type representations
5605 bool TypeMetadataPtr::eq( const Type *t ) const {
5606   const TypeMetadataPtr *a = (const TypeMetadataPtr*)t;
5607   ciMetadata* one = metadata();
5608   ciMetadata* two = a->metadata();
5609   if (one == NULL || two == NULL) {
5610     return (one == two) && TypePtr::eq(t);
5611   } else {
5612     return one->equals(two) && TypePtr::eq(t);
5613   }
5614 }
5615 
5616 //------------------------------hash-------------------------------------------
5617 // Type-specific hashing function.
5618 int TypeMetadataPtr::hash(void) const {
5619   return
5620     (metadata() ? metadata()->hash() : 0) +
5621     TypePtr::hash();
5622 }
5623 
5624 //------------------------------singleton--------------------------------------
5625 // TRUE if Type is a singleton type, FALSE otherwise.   Singletons are simple
5626 // constants
5627 bool TypeMetadataPtr::singleton(void) const {
5628   // detune optimizer to not generate constant metadata + constant offset as a constant!
5629   // TopPTR, Null, AnyNull, Constant are all singletons
5630   return (offset() == 0) && !below_centerline(_ptr);
5631 }
5632 
5633 //------------------------------add_offset-------------------------------------
5634 const TypePtr *TypeMetadataPtr::add_offset( intptr_t offset ) const {
5635   return make( _ptr, _metadata, xadd_offset(offset));
5636 }
5637 
5638 //-----------------------------filter------------------------------------------
5639 // Do not allow interface-vs.-noninterface joins to collapse to top.
5640 const Type *TypeMetadataPtr::filter_helper(const Type *kills, bool include_speculative) const {
5641   const TypeMetadataPtr* ft = join_helper(kills, include_speculative)->isa_metadataptr();
5642   if (ft == NULL || ft->empty())
5643     return Type::TOP;           // Canonical empty value
5644   return ft;
5645 }
5646 
5647  //------------------------------get_con----------------------------------------
5648 intptr_t TypeMetadataPtr::get_con() const {
5649   assert( _ptr == Null || _ptr == Constant, "" );
5650   assert(offset() >= 0, "");
5651 
5652   if (offset() != 0) {
5653     // After being ported to the compiler interface, the compiler no longer
5654     // directly manipulates the addresses of oops.  Rather, it only has a pointer
5655     // to a handle at compile time.  This handle is embedded in the generated
5656     // code and dereferenced at the time the nmethod is made.  Until that time,
5657     // it is not reasonable to do arithmetic with the addresses of oops (we don't
5658     // have access to the addresses!).  This does not seem to currently happen,
5659     // but this assertion here is to help prevent its occurrence.
5660     tty->print_cr("Found oop constant with non-zero offset");
5661     ShouldNotReachHere();
5662   }
5663 
5664   return (intptr_t)metadata()->constant_encoding();
5665 }
5666 
5667 //------------------------------cast_to_ptr_type-------------------------------
5668 const TypeMetadataPtr* TypeMetadataPtr::cast_to_ptr_type(PTR ptr) const {
5669   if( ptr == _ptr ) return this;
5670   return make(ptr, metadata(), _offset);
5671 }
5672 
5673 //------------------------------meet-------------------------------------------
5674 // Compute the MEET of two types.  It returns a new Type object.
5675 const Type *TypeMetadataPtr::xmeet( const Type *t ) const {
5676   // Perform a fast test for common case; meeting the same types together.
5677   if( this == t ) return this;  // Meeting same type-rep?
5678 
5679   // Current "this->_base" is OopPtr
5680   switch (t->base()) {          // switch on original type
5681 
5682   case Int:                     // Mixing ints & oops happens when javac
5683   case Long:                    // reuses local variables
5684   case FloatTop:
5685   case FloatCon:
5686   case FloatBot:
5687   case DoubleTop:
5688   case DoubleCon:
5689   case DoubleBot:
5690   case NarrowOop:
5691   case NarrowKlass:
5692   case Bottom:                  // Ye Olde Default
5693     return Type::BOTTOM;
5694   case Top:
5695     return this;
5696 
5697   default:                      // All else is a mistake
5698     typerr(t);
5699 
5700   case AnyPtr: {
5701     // Found an AnyPtr type vs self-OopPtr type
5702     const TypePtr *tp = t->is_ptr();
5703     Offset offset = meet_offset(tp->offset());
5704     PTR ptr = meet_ptr(tp->ptr());
5705     switch (tp->ptr()) {
5706     case Null:
5707       if (ptr == Null)  return TypePtr::make(AnyPtr, ptr, offset, tp->speculative(), tp->inline_depth());
5708       // else fall through:
5709     case TopPTR:
5710     case AnyNull: {
5711       return make(ptr, _metadata, offset);
5712     }
5713     case BotPTR:
5714     case NotNull:
5715       return TypePtr::make(AnyPtr, ptr, offset, tp->speculative(), tp->inline_depth());
5716     default: typerr(t);
5717     }
5718   }
5719 
5720   case RawPtr:
5721   case KlassPtr:
5722   case InstKlassPtr:
5723   case AryKlassPtr:
5724   case OopPtr:
5725   case InstPtr:
5726   case AryPtr:
5727     return TypePtr::BOTTOM;     // Oop meet raw is not well defined
5728 
5729   case MetadataPtr: {
5730     const TypeMetadataPtr *tp = t->is_metadataptr();
5731     Offset offset = meet_offset(tp->offset());
5732     PTR tptr = tp->ptr();
5733     PTR ptr = meet_ptr(tptr);
5734     ciMetadata* md = (tptr == TopPTR) ? metadata() : tp->metadata();
5735     if (tptr == TopPTR || _ptr == TopPTR ||
5736         metadata()->equals(tp->metadata())) {
5737       return make(ptr, md, offset);
5738     }
5739     // metadata is different
5740     if( ptr == Constant ) {  // Cannot be equal constants, so...
5741       if( tptr == Constant && _ptr != Constant)  return t;
5742       if( _ptr == Constant && tptr != Constant)  return this;
5743       ptr = NotNull;            // Fall down in lattice
5744     }
5745     return make(ptr, NULL, offset);
5746     break;
5747   }
5748   } // End of switch
5749   return this;                  // Return the double constant
5750 }
5751 
5752 
5753 //------------------------------xdual------------------------------------------
5754 // Dual of a pure metadata pointer.
5755 const Type *TypeMetadataPtr::xdual() const {
5756   return new TypeMetadataPtr(dual_ptr(), metadata(), dual_offset());
5757 }
5758 
5759 //------------------------------dump2------------------------------------------
5760 #ifndef PRODUCT
5761 void TypeMetadataPtr::dump2( Dict &d, uint depth, outputStream *st ) const {
5762   st->print("metadataptr:%s", ptr_msg[_ptr]);
5763   if( metadata() ) st->print(INTPTR_FORMAT, p2i(metadata()));
5764   switch (offset()) {
5765   case OffsetTop: st->print("+top"); break;
5766   case OffsetBot: st->print("+any"); break;
5767   case         0: break;
5768   default:        st->print("+%d",offset()); break;
5769   }
5770 }
5771 #endif
5772 
5773 
5774 //=============================================================================
5775 // Convenience common pre-built type.
5776 const TypeMetadataPtr *TypeMetadataPtr::BOTTOM;
5777 
5778 TypeMetadataPtr::TypeMetadataPtr(PTR ptr, ciMetadata* metadata, Offset offset):
5779   TypePtr(MetadataPtr, ptr, offset), _metadata(metadata) {
5780 }
5781 
5782 const TypeMetadataPtr* TypeMetadataPtr::make(ciMethod* m) {
5783   return make(Constant, m, Offset(0));
5784 }
5785 const TypeMetadataPtr* TypeMetadataPtr::make(ciMethodData* m) {
5786   return make(Constant, m, Offset(0));
5787 }
5788 
5789 //------------------------------make-------------------------------------------
5790 // Create a meta data constant
5791 const TypeMetadataPtr* TypeMetadataPtr::make(PTR ptr, ciMetadata* m, Offset offset) {
5792   assert(m == NULL || !m->is_klass(), "wrong type");
5793   return (TypeMetadataPtr*)(new TypeMetadataPtr(ptr, m, offset))->hashcons();
5794 }
5795 
5796 
5797 const TypeKlassPtr* TypeAryPtr::as_klass_type(bool try_for_exact) const {
5798   const Type* elem = _ary->_elem;
5799   bool xk = klass_is_exact();
5800   if (elem->make_oopptr() != NULL) {
5801     elem = elem->make_oopptr()->as_klass_type(try_for_exact);
5802     if (elem->is_klassptr()->klass_is_exact() &&
5803         // Even if MyValue is exact, [LMyValue is not exact due to [QMyValue <: [LMyValue.
5804         (is_null_free() || !_ary->_elem->make_oopptr()->is_inlinetypeptr())) {
5805       xk = true;
5806     }
5807   } else if (elem->isa_inlinetype() != NULL) {
5808     elem = TypeKlassPtr::make(elem->inline_klass());
5809   }
5810   return TypeAryKlassPtr::make(xk ? TypePtr::Constant : TypePtr::NotNull, elem, klass(), Offset(0), is_not_flat(), is_not_null_free(), is_null_free());
5811 }
5812 
5813 const TypeKlassPtr* TypeKlassPtr::make(ciKlass* klass) {
5814   if (klass->is_instance_klass()) {
5815     return TypeInstKlassPtr::make(klass);
5816   }
5817   return TypeAryKlassPtr::make(klass);
5818 }
5819 
5820 const TypeKlassPtr* TypeKlassPtr::make(PTR ptr, ciKlass* klass, Offset offset) {
5821   if (klass->is_instance_klass()) {
5822     return TypeInstKlassPtr::make(ptr, klass, offset);
5823   }
5824   return TypeAryKlassPtr::make(ptr, klass, offset);
5825 }
5826 
5827 //------------------------------TypeKlassPtr-----------------------------------
5828 TypeKlassPtr::TypeKlassPtr(TYPES t, PTR ptr, ciKlass* klass, Offset offset)
5829   : TypePtr(t, ptr, offset), _klass(klass) {
5830 }
5831 
5832 ciKlass* TypeKlassPtr::exact_klass_helper() const {
5833   return _klass;
5834 }
5835 
5836 //------------------------------eq---------------------------------------------
5837 // Structural equality check for Type representations
5838 bool TypeKlassPtr::eq(const Type *t) const {
5839   const TypeKlassPtr *p = t->is_klassptr();
5840   return
5841     TypePtr::eq(p);
5842 }
5843 
5844 //------------------------------hash-------------------------------------------
5845 // Type-specific hashing function.
5846 int TypeKlassPtr::hash(void) const {
5847   return TypePtr::hash();
5848 }
5849 
5850 //------------------------------singleton--------------------------------------
5851 // TRUE if Type is a singleton type, FALSE otherwise.   Singletons are simple
5852 // constants
5853 bool TypeKlassPtr::singleton(void) const {
5854   // detune optimizer to not generate constant klass + constant offset as a constant!
5855   // TopPTR, Null, AnyNull, Constant are all singletons
5856   return (offset() == 0) && !below_centerline(_ptr);
5857 }
5858 
5859 // Do not allow interface-vs.-noninterface joins to collapse to top.
5860 const Type *TypeKlassPtr::filter_helper(const Type *kills, bool include_speculative) const {
5861   // logic here mirrors the one from TypeOopPtr::filter. See comments
5862   // there.
5863   const Type* ft = join_helper(kills, include_speculative);
5864   const TypeKlassPtr* ftkp = ft->isa_instklassptr();
5865   const TypeKlassPtr* ktkp = kills->isa_instklassptr();
5866 
5867   if (ft->empty()) {
5868     if (!empty() && ktkp != NULL && ktkp->is_loaded() && ktkp->klass()->is_interface())
5869       return kills;             // Uplift to interface
5870 
5871     return Type::TOP;           // Canonical empty value
5872   }
5873 
5874   // Interface klass type could be exact in opposite to interface type,
5875   // return it here instead of incorrect Constant ptr J/L/Object (6894807).
5876   if (ftkp != NULL && ktkp != NULL &&
5877       ftkp->is_loaded() &&  ftkp->klass()->is_interface() &&
5878       !ftkp->klass_is_exact() && // Keep exact interface klass
5879       ktkp->is_loaded() && !ktkp->klass()->is_interface()) {
5880     return ktkp->cast_to_ptr_type(ftkp->ptr());
5881   }
5882 
5883   return ft;
5884 }
5885 
5886 //------------------------------get_con----------------------------------------
5887 intptr_t TypeKlassPtr::get_con() const {
5888   assert( _ptr == Null || _ptr == Constant, "" );
5889   assert( offset() >= 0, "" );
5890 
5891   if (offset() != 0) {
5892     // After being ported to the compiler interface, the compiler no longer
5893     // directly manipulates the addresses of oops.  Rather, it only has a pointer
5894     // to a handle at compile time.  This handle is embedded in the generated
5895     // code and dereferenced at the time the nmethod is made.  Until that time,
5896     // it is not reasonable to do arithmetic with the addresses of oops (we don't
5897     // have access to the addresses!).  This does not seem to currently happen,
5898     // but this assertion here is to help prevent its occurrence.
5899     tty->print_cr("Found oop constant with non-zero offset");
5900     ShouldNotReachHere();
5901   }
5902 
5903   ciKlass* k = exact_klass();
5904 
5905   return (intptr_t)k->constant_encoding();
5906 }
5907 
5908 //------------------------------dump2------------------------------------------
5909 // Dump Klass Type
5910 #ifndef PRODUCT
5911 void TypeInstKlassPtr::dump2(Dict & d, uint depth, outputStream *st) const {
5912   switch(_ptr) {
5913   case Constant:
5914     st->print("precise ");
5915   case NotNull:
5916     {
5917       const char *name = klass()->name()->as_utf8();
5918       if (name) {
5919         st->print("%s: " INTPTR_FORMAT, name, p2i(klass()));
5920       } else {
5921         ShouldNotReachHere();
5922       }
5923     }
5924   case BotPTR:
5925     if (!WizardMode && !Verbose && _ptr != Constant) break;
5926   case TopPTR:
5927   case AnyNull:
5928     st->print(":%s", ptr_msg[_ptr]);
5929     if (_ptr == Constant) st->print(":exact");
5930     break;
5931   default:
5932     break;
5933   }
5934   if (Verbose) {
5935     if (_flatten_array) st->print(":flatten array");
5936   }
5937   _offset.dump2(st);
5938   st->print(" *");
5939 }
5940 #endif
5941 
5942 //=============================================================================
5943 // Convenience common pre-built types.
5944 
5945 // Not-null object klass or below
5946 const TypeInstKlassPtr *TypeInstKlassPtr::OBJECT;
5947 const TypeInstKlassPtr *TypeInstKlassPtr::OBJECT_OR_NULL;
5948 
5949 bool TypeInstKlassPtr::eq(const Type *t) const {
5950   const TypeKlassPtr *p = t->is_klassptr();
5951   return
5952     klass()->equals(p->klass()) &&
5953     flatten_array() == p->flatten_array() &&
5954     TypeKlassPtr::eq(p);
5955 }
5956 
5957 int TypeInstKlassPtr::hash(void) const {
5958   return java_add(java_add((jint)klass()->hash(), TypeKlassPtr::hash()), (jint)flatten_array());
5959 }
5960 
5961 const TypeInstKlassPtr *TypeInstKlassPtr::make(PTR ptr, ciKlass* k, Offset offset, bool flatten_array) {
5962   flatten_array = flatten_array || k->flatten_array();
5963 
5964   TypeInstKlassPtr *r =
5965     (TypeInstKlassPtr*)(new TypeInstKlassPtr(ptr, k, offset, flatten_array))->hashcons();
5966 
5967   return r;
5968 }
5969 
5970 //------------------------------add_offset-------------------------------------
5971 // Access internals of klass object
5972 const TypePtr *TypeInstKlassPtr::add_offset( intptr_t offset ) const {
5973   return make(_ptr, klass(), xadd_offset(offset), flatten_array());
5974 }
5975 
5976 const TypeInstKlassPtr* TypeInstKlassPtr::with_offset(intptr_t offset) const {
5977   return make(_ptr, klass(), Offset(offset), flatten_array());
5978 }
5979 
5980 //------------------------------cast_to_ptr_type-------------------------------
5981 const TypeInstKlassPtr* TypeInstKlassPtr::cast_to_ptr_type(PTR ptr) const {
5982   assert(_base == InstKlassPtr, "subclass must override cast_to_ptr_type");
5983   if( ptr == _ptr ) return this;
5984   return make(ptr, _klass, _offset, flatten_array());
5985 }
5986 
5987 
5988 bool TypeInstKlassPtr::must_be_exact() const {
5989   if (!_klass->is_loaded())  return false;
5990   ciInstanceKlass* ik = _klass->as_instance_klass();
5991   if (ik->is_final())  return true;  // cannot clear xk
5992   return false;
5993 }
5994 
5995 //-----------------------------cast_to_exactness-------------------------------
5996 const TypeKlassPtr* TypeInstKlassPtr::cast_to_exactness(bool klass_is_exact) const {
5997   if (klass_is_exact == (_ptr == Constant)) return this;
5998   if (must_be_exact()) return this;
5999   ciKlass* k = klass();
6000   return make(klass_is_exact ? Constant : NotNull, k, _offset, flatten_array());
6001 }
6002 
6003 
6004 //-----------------------------as_instance_type--------------------------------
6005 // Corresponding type for an instance of the given class.
6006 // It will be NotNull, and exact if and only if the klass type is exact.
6007 const TypeOopPtr* TypeInstKlassPtr::as_instance_type(bool klass_change) const {
6008   ciKlass* k = klass();
6009   bool xk = klass_is_exact();
6010   Compile* C = Compile::current();
6011   Dependencies* deps = C->dependencies();
6012   assert((deps != NULL) == (C->method() != NULL && C->method()->code_size() > 0), "sanity");
6013   // Element is an instance
6014   bool klass_is_exact = false;
6015   if (k->is_loaded()) {
6016     // Try to set klass_is_exact.
6017     ciInstanceKlass* ik = k->as_instance_klass();
6018     klass_is_exact = ik->is_final();
6019     if (!klass_is_exact && klass_change
6020         && deps != NULL && UseUniqueSubclasses) {
6021       ciInstanceKlass* sub = ik->unique_concrete_subklass();
6022       if (sub != NULL) {
6023         deps->assert_abstract_with_unique_concrete_subtype(ik, sub);
6024         k = ik = sub;
6025         xk = sub->is_final();
6026       }
6027     }
6028   }
6029   return TypeInstPtr::make(TypePtr::BotPTR, k, xk, NULL, Offset(0), flatten_array() && !klass()->is_inlinetype());
6030 }
6031 
6032 //------------------------------xmeet------------------------------------------
6033 // Compute the MEET of two types, return a new Type object.
6034 const Type    *TypeInstKlassPtr::xmeet( const Type *t ) const {
6035   // Perform a fast test for common case; meeting the same types together.
6036   if( this == t ) return this;  // Meeting same type-rep?
6037 
6038   // Current "this->_base" is Pointer
6039   switch (t->base()) {          // switch on original type
6040 
6041   case Int:                     // Mixing ints & oops happens when javac
6042   case Long:                    // reuses local variables
6043   case FloatTop:
6044   case FloatCon:
6045   case FloatBot:
6046   case DoubleTop:
6047   case DoubleCon:
6048   case DoubleBot:
6049   case NarrowOop:
6050   case NarrowKlass:
6051   case Bottom:                  // Ye Olde Default
6052     return Type::BOTTOM;
6053   case Top:
6054     return this;
6055 
6056   default:                      // All else is a mistake
6057     typerr(t);
6058 
6059   case AnyPtr: {                // Meeting to AnyPtrs
6060     // Found an AnyPtr type vs self-KlassPtr type
6061     const TypePtr *tp = t->is_ptr();
6062     Offset offset = meet_offset(tp->offset());
6063     PTR ptr = meet_ptr(tp->ptr());
6064     switch (tp->ptr()) {
6065     case TopPTR:
6066       return this;
6067     case Null:
6068       if( ptr == Null ) return TypePtr::make(AnyPtr, ptr, offset, tp->speculative(), tp->inline_depth());
6069     case AnyNull:
6070       return make(ptr, klass(), offset, flatten_array());
6071     case BotPTR:
6072     case NotNull:
6073       return TypePtr::make(AnyPtr, ptr, offset, tp->speculative(), tp->inline_depth());
6074     default: typerr(t);
6075     }
6076   }
6077 
6078   case RawPtr:
6079   case MetadataPtr:
6080   case OopPtr:
6081   case AryPtr:                  // Meet with AryPtr
6082   case InstPtr:                 // Meet with InstPtr
6083       return TypePtr::BOTTOM;
6084 
6085   //
6086   //             A-top         }
6087   //           /   |   \       }  Tops
6088   //       B-top A-any C-top   }
6089   //          | /  |  \ |      }  Any-nulls
6090   //       B-any   |   C-any   }
6091   //          |    |    |
6092   //       B-con A-con C-con   } constants; not comparable across classes
6093   //          |    |    |
6094   //       B-not   |   C-not   }
6095   //          | \  |  / |      }  not-nulls
6096   //       B-bot A-not C-bot   }
6097   //           \   |   /       }  Bottoms
6098   //             A-bot         }
6099   //
6100 
6101   case InstKlassPtr: {  // Meet two KlassPtr types
6102     const TypeInstKlassPtr *tkls = t->is_instklassptr();
6103     Offset  off     = meet_offset(tkls->offset());
6104     PTR  ptr     = meet_ptr(tkls->ptr());
6105     ciKlass* tkls_klass = tkls->klass();
6106     ciKlass* this_klass  = klass();
6107     bool tkls_xk = tkls->klass_is_exact();
6108     bool this_xk  = klass_is_exact();
6109     bool tkls_flatten_array = tkls->flatten_array();
6110     bool this_flatten_array  = this->flatten_array();
6111 
6112     ciKlass* res_klass = NULL;
6113     bool res_xk = false;
6114     bool res_flatten_array = false;
6115     switch(meet_instptr(ptr, this_klass, tkls_klass, this_xk, tkls_xk, this->_ptr, tkls->_ptr,
6116                         this_flatten_array, tkls_flatten_array, res_klass, res_xk, res_flatten_array)) {
6117       case UNLOADED:
6118         ShouldNotReachHere();
6119       case SUBTYPE:
6120       case NOT_SUBTYPE:
6121       case LCA:
6122       case QUICK: {
6123         assert(res_xk == (ptr == Constant), "");
6124         const Type* res1 = make(ptr, res_klass, off, res_flatten_array);
6125         return res1;
6126       }
6127       default:
6128         ShouldNotReachHere();
6129     }
6130   } // End of case KlassPtr
6131   case AryKlassPtr: {                // All arrays inherit from Object class
6132     const TypeAryKlassPtr *tp = t->is_aryklassptr();
6133     Offset offset = meet_offset(tp->offset());
6134     PTR ptr = meet_ptr(tp->ptr());
6135 
6136     switch (ptr) {
6137     case TopPTR:
6138     case AnyNull:                // Fall 'down' to dual of object klass
6139       // For instances when a subclass meets a superclass we fall
6140       // below the centerline when the superclass is exact. We need to
6141       // do the same here.
6142       if (klass()->equals(ciEnv::current()->Object_klass()) && !klass_is_exact()) {
6143         return TypeAryKlassPtr::make(ptr, tp->elem(), tp->klass(), offset, tp->is_not_flat(), tp->is_not_null_free(), tp->is_null_free());
6144       } else {
6145         // cannot subclass, so the meet has to fall badly below the centerline
6146         ptr = NotNull;
6147         return make(ptr, ciEnv::current()->Object_klass(), offset, false);
6148       }
6149     case Constant:
6150     case NotNull:
6151     case BotPTR:                // Fall down to object klass
6152       // LCA is object_klass, but if we subclass from the top we can do better
6153       if( above_centerline(_ptr) ) { // if( _ptr == TopPTR || _ptr == AnyNull )
6154         // If 'this' (InstPtr) is above the centerline and it is Object class
6155         // then we can subclass in the Java class hierarchy.
6156         // For instances when a subclass meets a superclass we fall
6157         // below the centerline when the superclass is exact. We need
6158         // to do the same here.
6159         if (klass()->equals(ciEnv::current()->Object_klass())) {
6160           // that is, tp's array type is a subtype of my klass
6161           return TypeAryKlassPtr::make(ptr,
6162                                        tp->elem(), tp->klass(), offset, tp->is_not_flat(), tp->is_not_null_free(), tp->is_null_free());
6163         }
6164       }
6165       // The other case cannot happen, since I cannot be a subtype of an array.
6166       // The meet falls down to Object class below centerline.
6167       if( ptr == Constant )
6168          ptr = NotNull;
6169       return make(ptr, ciEnv::current()->Object_klass(), offset, false);
6170     default: typerr(t);
6171     }
6172   }
6173   case InlineType: {
6174     const TypeInlineType* tv = t->is_inlinetype();
6175     if (above_centerline(ptr())) {
6176       if (tv->inline_klass()->is_subtype_of(_klass)) {
6177         return t;
6178       } else {
6179         return TypeInstPtr::NOTNULL;
6180       }
6181     } else {
6182       PTR ptr = this->_ptr;
6183       if (ptr == Constant) {
6184         ptr = NotNull;
6185       }
6186       if (tv->inline_klass()->is_subtype_of(_klass)) {
6187         return make(ptr, _klass, Offset(0), _flatten_array);
6188       } else {
6189         return make(ptr, ciEnv::current()->Object_klass(), Offset(0));
6190       }
6191     }
6192   }
6193 
6194   } // End of switch
6195   return this;                  // Return the double constant
6196 }
6197 
6198 //------------------------------xdual------------------------------------------
6199 // Dual: compute field-by-field dual
6200 const Type    *TypeInstKlassPtr::xdual() const {
6201   return new TypeInstKlassPtr(dual_ptr(), klass(), dual_offset(), flatten_array());
6202 }
6203 
6204 bool TypeInstKlassPtr::is_java_subtype_of_helper(const TypeKlassPtr* other, bool this_exact, bool other_exact) const {
6205   if (!is_loaded() || !other->is_loaded()) {
6206     return false;
6207   }
6208   if (!other->isa_instklassptr()) {
6209     return false;
6210   }
6211 
6212   if (!other_exact) {
6213     return false;
6214   }
6215 
6216   if (other->_klass->equals(ciEnv::current()->Object_klass())) {
6217     return true;
6218   }
6219 
6220   if (!this_exact && klass()->is_interface()) {
6221     return false;
6222   }
6223 
6224   return _klass->is_subtype_of(other->_klass);
6225 }
6226 
6227 bool TypeInstKlassPtr::is_same_java_type_as(const TypeKlassPtr* other) const {
6228   if (!is_loaded() || !other->is_loaded()) {
6229     return false;
6230   }
6231   if (!other->isa_instklassptr()) {
6232     return false;
6233   }
6234   return _klass->equals(other->_klass);
6235 }
6236 
6237 bool TypeInstKlassPtr::maybe_java_subtype_of_helper(const TypeKlassPtr* other, bool this_exact, bool other_exact) const {
6238   if (!is_loaded() || !other->is_loaded()) {
6239     return true;
6240   }
6241 
6242   if (other->isa_aryklassptr()) {
6243     return !this_exact && (_klass->equals(ciEnv::current()->Object_klass()) || _klass->is_interface());
6244   }
6245 
6246   if ((_klass->is_interface() && !this_exact) || (other->klass()->is_interface() /*&& !other_exact*/)) {
6247     return true;
6248   }
6249 
6250   assert(other->isa_instklassptr(), "unsupported");
6251 
6252   if (this_exact && other_exact) {
6253     return is_java_subtype_of(other);
6254   }
6255 
6256   if (!_klass->is_subtype_of(other->_klass) && !other->_klass->is_subtype_of(_klass)) {
6257     return false;
6258   }
6259 
6260   if (this_exact) {
6261     return _klass->is_subtype_of(other->_klass);
6262   }
6263 
6264   return true;
6265 }
6266 
6267 const TypeAryKlassPtr* TypeAryKlassPtr::make(PTR ptr, const Type* elem, ciKlass* k, Offset offset, bool not_flat, bool not_null_free, bool null_free) {
6268   return (TypeAryKlassPtr*)(new TypeAryKlassPtr(ptr, elem, k, offset, not_flat, not_null_free, null_free))->hashcons();
6269 }
6270 
6271 const TypeAryKlassPtr* TypeAryKlassPtr::make(PTR ptr, ciKlass* klass, Offset offset, bool not_flat, bool not_null_free, bool null_free) {
6272   if (klass->is_obj_array_klass()) {
6273     // Element is an object array. Recursively call ourself.
6274     ciKlass* eklass = klass->as_obj_array_klass()->element_klass();
6275     const TypeKlassPtr* etype = TypeKlassPtr::make(eklass)->cast_to_exactness(false);
6276 
6277     // Even if MyValue is exact, [LMyValue is not exact due to [QMyValue <: [LMyValue.
6278     if (etype->klass_is_exact() && etype->isa_instklassptr() && etype->is_instklassptr()->klass()->is_inlinetype() && !null_free) {
6279       etype = TypeInstKlassPtr::make(NotNull, etype->is_instklassptr()->klass(), Offset(etype->is_instklassptr()->offset()), etype->is_instklassptr()->flatten_array());
6280     }
6281 
6282     const TypeAryKlassPtr* res = TypeAryKlassPtr::make(ptr, etype, NULL, offset, not_flat, not_null_free, null_free);
6283     assert(res->klass() == klass, "");
6284     return res;
6285   } else if (klass->is_type_array_klass()) {
6286     // Element is an typeArray
6287     const Type* etype = get_const_basic_type(klass->as_type_array_klass()->element_type());
6288     return TypeAryKlassPtr::make(ptr, etype, klass, offset, not_flat, not_null_free, null_free);
6289   } else if (klass->is_flat_array_klass()) {
6290     ciKlass* eklass = klass->as_flat_array_klass()->element_klass();
6291     const TypeKlassPtr* etype = TypeKlassPtr::make(eklass);
6292     return TypeAryKlassPtr::make(ptr, etype, klass, offset, not_flat, not_null_free, null_free);
6293   } else {
6294     ShouldNotReachHere();
6295     return NULL;
6296   }
6297 }
6298 
6299 const TypeAryKlassPtr* TypeAryKlassPtr::make(PTR ptr, ciKlass* k, Offset offset) {
6300   bool null_free = k->as_array_klass()->is_elem_null_free();
6301   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));
6302 
6303   bool not_flat = !UseFlatArray || not_null_free || (k->as_array_klass()->element_klass() != NULL &&
6304                                                      k->as_array_klass()->element_klass()->is_inlinetype() &&
6305                                                      !k->as_array_klass()->element_klass()->flatten_array());
6306 
6307   return TypeAryKlassPtr::make(ptr, k, offset, not_flat, not_null_free, null_free);
6308 }
6309 
6310 const TypeAryKlassPtr* TypeAryKlassPtr::make(ciKlass* klass) {
6311   return TypeAryKlassPtr::make(Constant, klass, Offset(0));
6312 }
6313 
6314 //------------------------------eq---------------------------------------------
6315 // Structural equality check for Type representations
6316 bool TypeAryKlassPtr::eq(const Type *t) const {
6317   const TypeAryKlassPtr *p = t->is_aryklassptr();
6318   return
6319     _elem == p->_elem &&  // Check array
6320     _not_flat == p->_not_flat &&
6321     _not_null_free == p->_not_null_free &&
6322     _null_free == p->_null_free &&
6323     TypeKlassPtr::eq(p);  // Check sub-parts
6324 }
6325 
6326 //------------------------------hash-------------------------------------------
6327 // Type-specific hashing function.
6328 int TypeAryKlassPtr::hash(void) const {
6329   return (intptr_t)_elem + TypeKlassPtr::hash();
6330 }
6331 
6332 //----------------------compute_klass------------------------------------------
6333 // Compute the defining klass for this class
6334 ciKlass* TypeAryPtr::compute_klass(DEBUG_ONLY(bool verify)) const {
6335   // Compute _klass based on element type.
6336   ciKlass* k_ary = NULL;
6337   const TypeAryPtr *tary;
6338   const Type* el = elem();
6339   if (el->isa_narrowoop()) {
6340     el = el->make_ptr();
6341   }
6342 
6343   // Get element klass
6344   if (el->isa_instptr()) {
6345     // Compute object array klass from element klass
6346     bool null_free = el->is_inlinetypeptr() && el->isa_instptr()->ptr() != TypePtr::TopPTR && !el->isa_instptr()->maybe_null();
6347     k_ary = ciArrayKlass::make(el->is_oopptr()->klass(), null_free);
6348   } else if (el->isa_inlinetype()) {
6349     // If element type is TypeInlineType::BOTTOM, inline_klass() will be null.
6350     if (el->inline_klass() != NULL) {
6351       k_ary = ciArrayKlass::make(el->inline_klass(), /* null_free */ true);
6352     }
6353   } else if ((tary = el->isa_aryptr()) != NULL) {
6354     // Compute array klass from element klass
6355     ciKlass* k_elem = tary->klass();
6356     // If element type is something like bottom[], k_elem will be null.
6357     if (k_elem != NULL)
6358       k_ary = ciObjArrayKlass::make(k_elem);
6359   } else if ((el->base() == Type::Top) ||
6360              (el->base() == Type::Bottom)) {
6361     // element type of Bottom occurs from meet of basic type
6362     // and object; Top occurs when doing join on Bottom.
6363     // Leave k_ary at NULL.
6364   } else {
6365     // Cannot compute array klass directly from basic type,
6366     // since subtypes of TypeInt all have basic type T_INT.
6367 #ifdef ASSERT
6368     if (verify && el->isa_int()) {
6369       // Check simple cases when verifying klass.
6370       BasicType bt = T_ILLEGAL;
6371       if (el == TypeInt::BYTE) {
6372         bt = T_BYTE;
6373       } else if (el == TypeInt::SHORT) {
6374         bt = T_SHORT;
6375       } else if (el == TypeInt::CHAR) {
6376         bt = T_CHAR;
6377       } else if (el == TypeInt::INT) {
6378         bt = T_INT;
6379       } else {
6380         return _klass; // just return specified klass
6381       }
6382       return ciTypeArrayKlass::make(bt);
6383     }
6384 #endif
6385     assert(!el->isa_int(),
6386            "integral arrays must be pre-equipped with a class");
6387     // Compute array klass directly from basic type
6388     k_ary = ciTypeArrayKlass::make(el->basic_type());
6389   }
6390   return k_ary;
6391 }
6392 
6393 //------------------------------klass------------------------------------------
6394 // Return the defining klass for this class
6395 ciKlass* TypeAryPtr::klass() const {
6396   if( _klass ) return _klass;   // Return cached value, if possible
6397 
6398   // Oops, need to compute _klass and cache it
6399   ciKlass* k_ary = compute_klass();
6400 
6401   if( this != TypeAryPtr::OOPS && this->dual() != TypeAryPtr::OOPS ) {
6402     // The _klass field acts as a cache of the underlying
6403     // ciKlass for this array type.  In order to set the field,
6404     // we need to cast away const-ness.
6405     //
6406     // IMPORTANT NOTE: we *never* set the _klass field for the
6407     // type TypeAryPtr::OOPS.  This Type is shared between all
6408     // active compilations.  However, the ciKlass which represents
6409     // this Type is *not* shared between compilations, so caching
6410     // this value would result in fetching a dangling pointer.
6411     //
6412     // Recomputing the underlying ciKlass for each request is
6413     // a bit less efficient than caching, but calls to
6414     // TypeAryPtr::OOPS->klass() are not common enough to matter.
6415     ((TypeAryPtr*)this)->_klass = k_ary;
6416     if (UseCompressedOops && k_ary != NULL && k_ary->is_obj_array_klass() &&
6417         offset() != 0 && offset() != arrayOopDesc::length_offset_in_bytes() &&
6418         offset() != arrayOopDesc::klass_offset_in_bytes()) {
6419       ((TypeAryPtr*)this)->_is_ptr_to_narrowoop = true;
6420     }
6421   }
6422   return k_ary;
6423 }
6424 
6425 ciKlass* TypeAryPtr::exact_klass_helper() const {
6426   if (_ary->_elem->make_ptr() && _ary->_elem->make_ptr()->isa_oopptr()) {
6427     ciKlass* k = _ary->_elem->make_ptr()->is_oopptr()->exact_klass_helper();
6428     if (k == NULL) {
6429       return NULL;
6430     }
6431     k = ciArrayKlass::make(k, is_null_free());
6432     return k;
6433   }
6434 
6435   return klass();
6436 }
6437 
6438 const Type* TypeAryPtr::base_element_type(int& dims) const {
6439   const Type* elem = this->elem();
6440   dims = 1;
6441   while (elem->make_ptr() && elem->make_ptr()->isa_aryptr()) {
6442     elem = elem->make_ptr()->is_aryptr()->elem();
6443     dims++;
6444   }
6445   return elem;
6446 }
6447 
6448 //------------------------------add_offset-------------------------------------
6449 // Access internals of klass object
6450 const TypePtr *TypeAryKlassPtr::add_offset(intptr_t offset) const {
6451   return make(_ptr, elem(), klass(), xadd_offset(offset), is_not_flat(), is_not_null_free(), _null_free);
6452 }
6453 
6454 const TypeAryKlassPtr* TypeAryKlassPtr::with_offset(intptr_t offset) const {
6455   return make(_ptr, elem(), klass(), Offset(offset), is_not_flat(), is_not_null_free(), _null_free);
6456 }
6457 
6458 //------------------------------cast_to_ptr_type-------------------------------
6459 const TypeAryKlassPtr* TypeAryKlassPtr::cast_to_ptr_type(PTR ptr) const {
6460   assert(_base == AryKlassPtr, "subclass must override cast_to_ptr_type");
6461   if (ptr == _ptr) return this;
6462   return make(ptr, elem(), _klass, _offset, is_not_flat(), is_not_null_free(), _null_free);
6463 }
6464 
6465 bool TypeAryKlassPtr::must_be_exact() const {
6466   if (_elem == Type::BOTTOM) return false;
6467   if (_elem == Type::TOP   ) return false;
6468   const TypeKlassPtr*  tk = _elem->isa_klassptr();
6469   if (!tk)             return true;   // a primitive type, like int
6470   // Even if MyValue is exact, [LMyValue is not exact due to [QMyValue <: [LMyValue.
6471   if (tk->klass()->is_inlinetype() && !is_null_free()) {
6472     return false;
6473   }
6474   return tk->must_be_exact();
6475 }
6476 
6477 
6478 //-----------------------------cast_to_exactness-------------------------------
6479 const TypeKlassPtr *TypeAryKlassPtr::cast_to_exactness(bool klass_is_exact) const {
6480   if (must_be_exact() && !klass_is_exact) return this;  // cannot clear xk
6481   ciKlass* k = _klass;
6482   const Type* elem = this->elem();
6483   if (elem->isa_klassptr() && !klass_is_exact) {
6484     elem = elem->is_klassptr()->cast_to_exactness(klass_is_exact);
6485   }
6486   bool not_flat = is_not_flat();
6487   bool not_null_free = is_not_null_free();
6488   if (k != NULL && k->is_obj_array_klass()) {
6489     if (klass_is_exact) {
6490       // An object array can't be flat or null-free if the klass is exact
6491       not_flat = true;
6492       not_null_free = true;
6493     } else {
6494       // Klass is not exact (anymore), re-compute null-free/flat properties
6495       const TypeOopPtr* exact_etype = TypeOopPtr::make_from_klass_unique(k->as_array_klass()->element_klass());
6496       not_null_free = !exact_etype->can_be_inline_type();
6497       not_flat = !UseFlatArray || not_null_free || (exact_etype->is_inlinetypeptr() && !exact_etype->inline_klass()->flatten_array());
6498     }
6499   }
6500   return make(klass_is_exact ? Constant : NotNull, elem, k, _offset, not_flat, not_null_free, _null_free);
6501 }
6502 
6503 
6504 //-----------------------------as_instance_type--------------------------------
6505 // Corresponding type for an instance of the given class.
6506 // It will be NotNull, and exact if and only if the klass type is exact.
6507 const TypeOopPtr* TypeAryKlassPtr::as_instance_type(bool klass_change) const {
6508   ciKlass* k = klass();
6509   assert(k != NULL, "klass should not be NULL");
6510   bool    xk = klass_is_exact();
6511   const Type* el = NULL;
6512   if (elem()->isa_klassptr()) {
6513     el = elem()->is_klassptr()->as_instance_type(false)->cast_to_exactness(false);
6514     k = NULL;
6515   } else {
6516     el = elem();
6517   }
6518   bool null_free = _null_free;
6519   if (null_free && el->isa_ptr()) {
6520     el = el->is_ptr()->join_speculative(TypePtr::NOTNULL);
6521   }
6522   bool not_flat = is_not_flat();
6523   bool not_null_free = is_not_null_free();
6524   if (is_flat()) {
6525     el = TypeInlineType::make(el->inline_klass());
6526   }
6527   return TypeAryPtr::make(TypePtr::BotPTR, TypeAry::make(el, TypeInt::POS, false, not_flat, not_null_free), k, xk, Offset(0));
6528 }
6529 
6530 
6531 //------------------------------xmeet------------------------------------------
6532 // Compute the MEET of two types, return a new Type object.
6533 const Type    *TypeAryKlassPtr::xmeet( const Type *t ) const {
6534   // Perform a fast test for common case; meeting the same types together.
6535   if( this == t ) return this;  // Meeting same type-rep?
6536 
6537   // Current "this->_base" is Pointer
6538   switch (t->base()) {          // switch on original type
6539 
6540   case Int:                     // Mixing ints & oops happens when javac
6541   case Long:                    // reuses local variables
6542   case FloatTop:
6543   case FloatCon:
6544   case FloatBot:
6545   case DoubleTop:
6546   case DoubleCon:
6547   case DoubleBot:
6548   case NarrowOop:
6549   case NarrowKlass:
6550   case Bottom:                  // Ye Olde Default
6551     return Type::BOTTOM;
6552   case Top:
6553     return this;
6554 
6555   default:                      // All else is a mistake
6556     typerr(t);
6557 
6558   case AnyPtr: {                // Meeting to AnyPtrs
6559     // Found an AnyPtr type vs self-KlassPtr type
6560     const TypePtr *tp = t->is_ptr();
6561     Offset offset = meet_offset(tp->offset());
6562     PTR ptr = meet_ptr(tp->ptr());
6563     switch (tp->ptr()) {
6564     case TopPTR:
6565       return this;
6566     case Null:
6567       if( ptr == Null ) return TypePtr::make(AnyPtr, ptr, offset, tp->speculative(), tp->inline_depth());
6568     case AnyNull:
6569       return make(ptr, _elem, klass(), offset, is_not_flat(), is_not_null_free(), _null_free);
6570     case BotPTR:
6571     case NotNull:
6572       return TypePtr::make(AnyPtr, ptr, offset, tp->speculative(), tp->inline_depth());
6573     default: typerr(t);
6574     }
6575   }
6576 
6577   case RawPtr:
6578   case MetadataPtr:
6579   case OopPtr:
6580   case AryPtr:                  // Meet with AryPtr
6581   case InstPtr:                 // Meet with InstPtr
6582     return TypePtr::BOTTOM;
6583 
6584   //
6585   //             A-top         }
6586   //           /   |   \       }  Tops
6587   //       B-top A-any C-top   }
6588   //          | /  |  \ |      }  Any-nulls
6589   //       B-any   |   C-any   }
6590   //          |    |    |
6591   //       B-con A-con C-con   } constants; not comparable across classes
6592   //          |    |    |
6593   //       B-not   |   C-not   }
6594   //          | \  |  / |      }  not-nulls
6595   //       B-bot A-not C-bot   }
6596   //           \   |   /       }  Bottoms
6597   //             A-bot         }
6598   //
6599 
6600   case AryKlassPtr: {  // Meet two KlassPtr types
6601     const TypeAryKlassPtr *tap = t->is_aryklassptr();
6602     Offset off = meet_offset(tap->offset());
6603     const Type* res_elem = NULL;
6604     PTR ptr = meet_ptr(tap->ptr());
6605     ciKlass* res_klass = NULL;
6606     bool res_xk = false;
6607     bool res_not_flat = false;
6608     bool res_not_null_free = false;
6609     MeetResult res = meet_aryptr(ptr, _elem, tap->_elem, this->klass(), tap->klass(),
6610                                  this->klass_is_exact(), tap->klass_is_exact(),
6611                                  this->ptr(), tap->ptr(), this->is_not_flat(), tap->is_not_flat(),
6612                                  this->is_not_null_free(), tap->is_not_null_free(),
6613                                  res_elem, res_klass, res_xk, res_not_flat, res_not_null_free);
6614     assert(res_xk == (ptr == Constant), "");
6615     bool null_free = meet_null_free(tap->_null_free);
6616     if (res == NOT_SUBTYPE) {
6617       null_free = false;
6618     } else if (res == SUBTYPE) {
6619       if (above_centerline(tap->ptr()) && !above_centerline(this->ptr())) {
6620         null_free = _null_free;
6621       } else if (above_centerline(this->ptr()) && !above_centerline(tap->ptr())) {
6622         null_free = tap->_null_free;
6623       }
6624     }
6625     return make(ptr, res_elem, res_klass, off, res_not_flat, res_not_null_free, null_free);
6626   } // End of case KlassPtr
6627   case InstKlassPtr: {
6628     const TypeInstKlassPtr *tp = t->is_instklassptr();
6629     Offset offset = meet_offset(tp->offset());
6630     PTR ptr = meet_ptr(tp->ptr());
6631 
6632     switch (ptr) {
6633     case TopPTR:
6634     case AnyNull:                // Fall 'down' to dual of object klass
6635       // For instances when a subclass meets a superclass we fall
6636       // below the centerline when the superclass is exact. We need to
6637       // do the same here.
6638       if (tp->klass()->equals(ciEnv::current()->Object_klass()) && !tp->klass_is_exact()) {
6639         return TypeAryKlassPtr::make(ptr, _elem, _klass, offset, is_not_flat(), is_not_null_free(), _null_free);
6640       } else {
6641         // cannot subclass, so the meet has to fall badly below the centerline
6642         ptr = NotNull;
6643         return TypeInstKlassPtr::make(ptr, ciEnv::current()->Object_klass(), offset, false);
6644       }
6645     case Constant:
6646     case NotNull:
6647     case BotPTR:                // Fall down to object klass
6648       // LCA is object_klass, but if we subclass from the top we can do better
6649       if (above_centerline(tp->ptr())) {
6650         // If 'tp'  is above the centerline and it is Object class
6651         // then we can subclass in the Java class hierarchy.
6652         // For instances when a subclass meets a superclass we fall
6653         // below the centerline when the superclass is exact. We need
6654         // to do the same here.
6655         if (tp->klass()->equals(ciEnv::current()->Object_klass()) && !tp->klass_is_exact()) {
6656           // that is, my array type is a subtype of 'tp' klass
6657           return make(ptr, _elem, _klass, offset, is_not_flat(), is_not_null_free(), _null_free);
6658         }
6659       }
6660       // The other case cannot happen, since t cannot be a subtype of an array.
6661       // The meet falls down to Object class below centerline.
6662       if (ptr == Constant)
6663          ptr = NotNull;
6664       return TypeInstKlassPtr::make(ptr, ciEnv::current()->Object_klass(), offset, false);
6665     default: typerr(t);
6666     }
6667   }
6668   case InlineType: {
6669     const TypeInlineType* tv = t->is_inlinetype();
6670     if (above_centerline(ptr())) {
6671       return TypeInstKlassPtr::BOTTOM;
6672     } else {
6673       PTR ptr = this->_ptr;
6674       if (ptr == Constant) {
6675         ptr = NotNull;
6676       }
6677       return TypeInstKlassPtr::make(ptr, ciEnv::current()->Object_klass(), Offset(0));
6678     }
6679   }
6680 
6681   } // End of switch
6682   return this;                  // Return the double constant
6683 }
6684 
6685 bool TypeAryKlassPtr::is_java_subtype_of_helper(const TypeKlassPtr* other, bool this_exact, bool other_exact) const {
6686   if (other->klass() == ciEnv::current()->Object_klass() && other_exact) {
6687     return true;
6688   }
6689 
6690   if (!is_loaded() || !other->is_loaded() || other->klass() == NULL || klass() == NULL) {
6691     return false;
6692   }
6693   if (other->isa_instklassptr()) {
6694     return _klass->is_subtype_of(other->_klass) && other_exact;
6695   }
6696   if (klass() == NULL) {
6697     return false;
6698   }
6699   assert(other->isa_aryklassptr(), "");
6700   const TypeAryKlassPtr* other_ary = other->isa_aryklassptr();
6701   if (other_ary->_elem->isa_klassptr() && _elem->isa_klassptr()) {
6702     if (other->is_null_free() && !is_null_free()) {
6703       return false; // [LMyValue is not a subtype of [QMyValue
6704     }
6705     return _elem->is_klassptr()->is_java_subtype_of_helper(other_ary->_elem->is_klassptr(), this_exact, other_exact);
6706   }
6707   if (!other_ary->_elem->isa_klassptr() && !_elem->isa_klassptr()) {
6708     return _klass->is_subtype_of(other->_klass);
6709   }
6710   return false;
6711 }
6712 
6713 bool TypeAryKlassPtr::is_same_java_type_as(const TypeKlassPtr* other) const {
6714   if (!other->isa_aryklassptr() ||
6715       !is_loaded() || !other->is_loaded() || klass() == NULL || other->klass() == NULL) {
6716     return false;
6717   }
6718   const TypeAryKlassPtr* other_ary = other->isa_aryklassptr();
6719   if (other_ary->_elem->isa_klassptr() && _elem->isa_klassptr()) {
6720     return _elem->is_klassptr()->is_same_java_type_as(other_ary->_elem->is_klassptr());
6721   }
6722   if (!other_ary->_elem->isa_klassptr() && !_elem->isa_klassptr()) {
6723     return _klass->equals(other->_klass);
6724   }
6725   return false;
6726 }
6727 
6728 bool TypeAryKlassPtr::maybe_java_subtype_of_helper(const TypeKlassPtr* other, bool this_exact, bool other_exact) const {
6729   if (other->klass() == ciEnv::current()->Object_klass()) {
6730     return true;
6731   }
6732   if (!is_loaded() || !other->is_loaded() || klass() == NULL || other->klass() == NULL) {
6733     return true;
6734   }
6735   if (other->isa_instklassptr()) {
6736     return (!other_exact && other->_klass->is_interface()) || _klass->is_subtype_of(other->_klass);
6737   }
6738   assert(other->isa_aryklassptr(), "");
6739 
6740   if (this_exact && other_exact) {
6741     return is_java_subtype_of(other);
6742   }
6743 
6744   const TypeAryKlassPtr* other_ary = other->isa_aryklassptr();
6745   if (other_ary->_elem->isa_klassptr() && _elem->isa_klassptr()) {
6746     return _elem->is_klassptr()->maybe_java_subtype_of_helper(other_ary->_elem->is_klassptr(), this_exact, other_exact);
6747   }
6748   if (!other_ary->_elem->isa_klassptr() && !_elem->isa_klassptr()) {
6749     return _klass->is_subtype_of(other->_klass);
6750   }
6751   return false;
6752 }
6753 
6754 //------------------------------xdual------------------------------------------
6755 // Dual: compute field-by-field dual
6756 const Type    *TypeAryKlassPtr::xdual() const {
6757   return new TypeAryKlassPtr(dual_ptr(), elem()->dual(), klass(), dual_offset(), !is_not_flat(), !is_not_null_free(), dual_null_free());
6758 }
6759 
6760 //------------------------------get_con----------------------------------------
6761 ciKlass* TypeAryKlassPtr::exact_klass_helper() const {
6762   if (elem()->isa_klassptr()) {
6763     ciKlass* k = elem()->is_klassptr()->exact_klass_helper();
6764     if (k == NULL) {
6765       return NULL;
6766     }
6767     k = ciArrayKlass::make(k, _null_free);
6768     return k;
6769   }
6770 
6771   return klass();
6772 }
6773 
6774 ciKlass* TypeAryKlassPtr::klass() const {
6775   if (_klass != NULL) {
6776     return _klass;
6777   }
6778   ciKlass* k = NULL;
6779   const Type* el = elem();
6780   if (el->isa_instklassptr()) {
6781     // Compute object array klass from element klass
6782     bool null_free = el->is_instklassptr()->klass()->is_inlinetype() && el->isa_instklassptr()->ptr() != TypePtr::TopPTR && (_null_free != 0);
6783     k = ciArrayKlass::make(el->is_klassptr()->klass(), null_free);
6784     ((TypeAryKlassPtr*)this)->_klass = k;
6785   } else if (el->isa_inlinetype()) {
6786     // If element type is TypeInlineType::BOTTOM, inline_klass() will be null.
6787     if (el->inline_klass() != NULL) {
6788       k = ciArrayKlass::make(el->inline_klass(), /* null_free */ true);
6789       ((TypeAryKlassPtr*)this)->_klass = k;
6790     }
6791   } else if (el->isa_aryklassptr() != NULL) {
6792     // Compute array klass from element klass
6793     ciKlass* k_elem = el->is_aryklassptr()->klass();
6794     // If element type is something like bottom[], k_elem will be null.
6795     if (k_elem != NULL) {
6796       k = ciObjArrayKlass::make(k_elem);
6797       ((TypeAryKlassPtr*)this)->_klass = k;
6798     }
6799   } else if ((elem()->base() == Type::Top) ||
6800              (elem()->base() == Type::Bottom)) {
6801   } else {
6802     k = ciTypeArrayKlass::make(elem()->basic_type());
6803   }
6804   return k;
6805 }
6806 
6807 //------------------------------dump2------------------------------------------
6808 // Dump Klass Type
6809 #ifndef PRODUCT
6810 void TypeAryKlassPtr::dump2( Dict & d, uint depth, outputStream *st ) const {
6811   switch( _ptr ) {
6812   case Constant:
6813     st->print("precise ");
6814   case NotNull:
6815     {
6816       st->print("[");
6817       if (_elem->isa_inlinetype()) {
6818         const char *name = _elem->is_inlinetype()->inline_klass()->name()->as_utf8();
6819         st->print("precise %s: " INTPTR_FORMAT " ", name, p2i(klass()));
6820       }
6821       _elem->dump2(d, depth, st);
6822       st->print(": ");
6823     }
6824   case BotPTR:
6825     if( !WizardMode && !Verbose && _ptr != Constant ) break;
6826   case TopPTR:
6827   case AnyNull:
6828     st->print(":%s", ptr_msg[_ptr]);
6829     if( _ptr == Constant ) st->print(":exact");
6830     break;
6831   default:
6832     break;
6833   }
6834   if (Verbose) {
6835     if (is_flat()) st->print(":flat");
6836     if (_not_flat) st->print(":not flat");
6837     if (_not_null_free) st->print(":not null free");
6838     if (_null_free) st->print(":null free");
6839   }
6840 
6841   _offset.dump2(st);
6842 
6843   st->print(" *");
6844 }
6845 #endif
6846 
6847 const Type* TypeAryKlassPtr::base_element_type(int& dims) const {
6848   const Type* elem = this->elem();
6849   dims = 1;
6850   while (elem->isa_aryklassptr()) {
6851     elem = elem->is_aryklassptr()->elem();
6852     dims++;
6853   }
6854   return elem;
6855 }
6856 
6857 //=============================================================================
6858 // Convenience common pre-built types.
6859 
6860 //------------------------------make-------------------------------------------
6861 const TypeFunc *TypeFunc::make(const TypeTuple *domain_sig, const TypeTuple* domain_cc,
6862                                const TypeTuple *range_sig, const TypeTuple *range_cc) {
6863   return (TypeFunc*)(new TypeFunc(domain_sig, domain_cc, range_sig, range_cc))->hashcons();
6864 }
6865 
6866 const TypeFunc *TypeFunc::make(const TypeTuple *domain, const TypeTuple *range) {
6867   return make(domain, domain, range, range);
6868 }
6869 
6870 //------------------------------osr_domain-----------------------------
6871 const TypeTuple* osr_domain() {
6872   const Type **fields = TypeTuple::fields(2);
6873   fields[TypeFunc::Parms+0] = TypeRawPtr::BOTTOM;  // address of osr buffer
6874   return TypeTuple::make(TypeFunc::Parms+1, fields);
6875 }
6876 
6877 //------------------------------make-------------------------------------------
6878 const TypeFunc* TypeFunc::make(ciMethod* method, bool is_osr_compilation) {
6879   Compile* C = Compile::current();
6880   const TypeFunc* tf = NULL;
6881   if (!is_osr_compilation) {
6882     tf = C->last_tf(method); // check cache
6883     if (tf != NULL)  return tf;  // The hit rate here is almost 50%.
6884   }
6885   // Inline types are not passed/returned by reference, instead each field of
6886   // the inline type is passed/returned as an argument. We maintain two views of
6887   // the argument/return list here: one based on the signature (with an inline
6888   // type argument/return as a single slot), one based on the actual calling
6889   // convention (with an inline type argument/return as a list of its fields).
6890   bool has_scalar_args = method->has_scalarized_args() && !is_osr_compilation;
6891   const TypeTuple* domain_sig = is_osr_compilation ? osr_domain() : TypeTuple::make_domain(method, false);
6892   const TypeTuple* domain_cc = has_scalar_args ? TypeTuple::make_domain(method, true) : domain_sig;
6893   ciSignature* sig = method->signature();
6894   bool has_scalar_ret = sig->return_type()->is_inlinetype() && sig->return_type()->as_inline_klass()->can_be_returned_as_fields();
6895   const TypeTuple* range_sig = TypeTuple::make_range(sig, false);
6896   const TypeTuple* range_cc = has_scalar_ret ? TypeTuple::make_range(sig, true) : range_sig;
6897   tf = TypeFunc::make(domain_sig, domain_cc, range_sig, range_cc);
6898   if (!is_osr_compilation) {
6899     C->set_last_tf(method, tf);  // fill cache
6900   }
6901   return tf;
6902 }
6903 
6904 //------------------------------meet-------------------------------------------
6905 // Compute the MEET of two types.  It returns a new Type object.
6906 const Type *TypeFunc::xmeet( const Type *t ) const {
6907   // Perform a fast test for common case; meeting the same types together.
6908   if( this == t ) return this;  // Meeting same type-rep?
6909 
6910   // Current "this->_base" is Func
6911   switch (t->base()) {          // switch on original type
6912 
6913   case Bottom:                  // Ye Olde Default
6914     return t;
6915 
6916   default:                      // All else is a mistake
6917     typerr(t);
6918 
6919   case Top:
6920     break;
6921   }
6922   return this;                  // Return the double constant
6923 }
6924 
6925 //------------------------------xdual------------------------------------------
6926 // Dual: compute field-by-field dual
6927 const Type *TypeFunc::xdual() const {
6928   return this;
6929 }
6930 
6931 //------------------------------eq---------------------------------------------
6932 // Structural equality check for Type representations
6933 bool TypeFunc::eq( const Type *t ) const {
6934   const TypeFunc *a = (const TypeFunc*)t;
6935   return _domain_sig == a->_domain_sig &&
6936     _domain_cc == a->_domain_cc &&
6937     _range_sig == a->_range_sig &&
6938     _range_cc == a->_range_cc;
6939 }
6940 
6941 //------------------------------hash-------------------------------------------
6942 // Type-specific hashing function.
6943 int TypeFunc::hash(void) const {
6944   return (intptr_t)_domain_sig + (intptr_t)_domain_cc + (intptr_t)_range_sig + (intptr_t)_range_cc;
6945 }
6946 
6947 //------------------------------dump2------------------------------------------
6948 // Dump Function Type
6949 #ifndef PRODUCT
6950 void TypeFunc::dump2( Dict &d, uint depth, outputStream *st ) const {
6951   if( _range_sig->cnt() <= Parms )
6952     st->print("void");
6953   else {
6954     uint i;
6955     for (i = Parms; i < _range_sig->cnt()-1; i++) {
6956       _range_sig->field_at(i)->dump2(d,depth,st);
6957       st->print("/");
6958     }
6959     _range_sig->field_at(i)->dump2(d,depth,st);
6960   }
6961   st->print(" ");
6962   st->print("( ");
6963   if( !depth || d[this] ) {     // Check for recursive dump
6964     st->print("...)");
6965     return;
6966   }
6967   d.Insert((void*)this,(void*)this);    // Stop recursion
6968   if (Parms < _domain_sig->cnt())
6969     _domain_sig->field_at(Parms)->dump2(d,depth-1,st);
6970   for (uint i = Parms+1; i < _domain_sig->cnt(); i++) {
6971     st->print(", ");
6972     _domain_sig->field_at(i)->dump2(d,depth-1,st);
6973   }
6974   st->print(" )");
6975 }
6976 #endif
6977 
6978 //------------------------------singleton--------------------------------------
6979 // TRUE if Type is a singleton type, FALSE otherwise.   Singletons are simple
6980 // constants (Ldi nodes).  Singletons are integer, float or double constants
6981 // or a single symbol.
6982 bool TypeFunc::singleton(void) const {
6983   return false;                 // Never a singleton
6984 }
6985 
6986 bool TypeFunc::empty(void) const {
6987   return false;                 // Never empty
6988 }
6989 
6990 
6991 BasicType TypeFunc::return_type() const{
6992   if (range_sig()->cnt() == TypeFunc::Parms) {
6993     return T_VOID;
6994   }
6995   return range_sig()->field_at(TypeFunc::Parms)->basic_type();
6996 }