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