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