< prev index next >

src/hotspot/share/opto/type.cpp

Print this page

   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/ciMethodData.hpp"
  27 #include "ci/ciTypeFlow.hpp"
  28 #include "classfile/javaClasses.hpp"
  29 #include "classfile/symbolTable.hpp"
  30 #include "compiler/compileLog.hpp"
  31 #include "libadt/dict.hpp"
  32 #include "memory/oopFactory.hpp"
  33 #include "memory/resourceArea.hpp"
  34 #include "oops/instanceKlass.hpp"
  35 #include "oops/instanceMirrorKlass.hpp"
  36 #include "oops/objArrayKlass.hpp"
  37 #include "oops/typeArrayKlass.hpp"
  38 #include "opto/matcher.hpp"
  39 #include "opto/node.hpp"
  40 #include "opto/opcodes.hpp"
  41 #include "opto/type.hpp"
  42 #include "utilities/powerOfTwo.hpp"
  43 #include "utilities/stringUtils.hpp"
  44 
  45 // Portions of code courtesy of Clifford Click
  46 
  47 // Optimization - Graph Style
  48 
  49 // Dictionary of types shared among compilations.
  50 Dict* Type::_shared_type_dict = NULL;














































  51 
  52 // Array which maps compiler types to Basic Types
  53 const Type::TypeInfo Type::_type_info[Type::lastype] = {
  54   { Bad,             T_ILLEGAL,    "bad",           false, Node::NotAMachineReg, relocInfo::none          },  // Bad
  55   { Control,         T_ILLEGAL,    "control",       false, 0,                    relocInfo::none          },  // Control
  56   { Bottom,          T_VOID,       "top",           false, 0,                    relocInfo::none          },  // Top
  57   { Bad,             T_INT,        "int:",          false, Op_RegI,              relocInfo::none          },  // Int
  58   { Bad,             T_LONG,       "long:",         false, Op_RegL,              relocInfo::none          },  // Long
  59   { Half,            T_VOID,       "half",          false, 0,                    relocInfo::none          },  // Half
  60   { Bad,             T_NARROWOOP,  "narrowoop:",    false, Op_RegN,              relocInfo::none          },  // NarrowOop
  61   { Bad,             T_NARROWKLASS,"narrowklass:",  false, Op_RegN,              relocInfo::none          },  // NarrowKlass
  62   { Bad,             T_ILLEGAL,    "tuple:",        false, Node::NotAMachineReg, relocInfo::none          },  // Tuple
  63   { Bad,             T_ARRAY,      "array:",        false, Node::NotAMachineReg, relocInfo::none          },  // Array
  64 
  65 #if defined(PPC64)
  66   { Bad,             T_ILLEGAL,    "vectormask:",   false, Op_RegVectMask,       relocInfo::none          },  // VectorMask.
  67   { Bad,             T_ILLEGAL,    "vectora:",      false, Op_VecA,              relocInfo::none          },  // VectorA.
  68   { Bad,             T_ILLEGAL,    "vectors:",      false, 0,                    relocInfo::none          },  // VectorS
  69   { Bad,             T_ILLEGAL,    "vectord:",      false, Op_RegL,              relocInfo::none          },  // VectorD
  70   { Bad,             T_ILLEGAL,    "vectorx:",      false, Op_VecX,              relocInfo::none          },  // VectorX

 204   case ciTypeFlow::StateVector::T_NULL:
 205     assert(type == ciTypeFlow::StateVector::null_type(), "");
 206     return TypePtr::NULL_PTR;
 207 
 208   case ciTypeFlow::StateVector::T_LONG2:
 209     // The ciTypeFlow pass pushes a long, then the half.
 210     // We do the same.
 211     assert(type == ciTypeFlow::StateVector::long2_type(), "");
 212     return TypeInt::TOP;
 213 
 214   case ciTypeFlow::StateVector::T_DOUBLE2:
 215     // The ciTypeFlow pass pushes double, then the half.
 216     // Our convention is the same.
 217     assert(type == ciTypeFlow::StateVector::double2_type(), "");
 218     return Type::TOP;
 219 
 220   case T_ADDRESS:
 221     assert(type->is_return_address(), "");
 222     return TypeRawPtr::make((address)(intptr_t)type->as_return_address()->bci());
 223 





 224   default:
 225     // make sure we did not mix up the cases:
 226     assert(type != ciTypeFlow::StateVector::bottom_type(), "");
 227     assert(type != ciTypeFlow::StateVector::top_type(), "");
 228     assert(type != ciTypeFlow::StateVector::null_type(), "");
 229     assert(type != ciTypeFlow::StateVector::long2_type(), "");
 230     assert(type != ciTypeFlow::StateVector::double2_type(), "");
 231     assert(!type->is_return_address(), "");
 232 
 233     return Type::get_const_type(type);
 234   }
 235 }
 236 
 237 
 238 //-----------------------make_from_constant------------------------------------
 239 const Type* Type::make_from_constant(ciConstant constant, bool require_constant,
 240                                      int stable_dimension, bool is_narrow_oop,
 241                                      bool is_autobox_cache) {
 242   switch (constant.basic_type()) {
 243     case T_BOOLEAN:  return TypeInt::make(constant.as_boolean());
 244     case T_CHAR:     return TypeInt::make(constant.as_char());
 245     case T_BYTE:     return TypeInt::make(constant.as_byte());
 246     case T_SHORT:    return TypeInt::make(constant.as_short());
 247     case T_INT:      return TypeInt::make(constant.as_int());
 248     case T_LONG:     return TypeLong::make(constant.as_long());
 249     case T_FLOAT:    return TypeF::make(constant.as_float());
 250     case T_DOUBLE:   return TypeD::make(constant.as_double());
 251     case T_ARRAY:

 252     case T_OBJECT: {
 253         const Type* con_type = NULL;
 254         ciObject* oop_constant = constant.as_object();
 255         if (oop_constant->is_null_object()) {
 256           con_type = Type::get_zero_type(T_OBJECT);
 257         } else {
 258           guarantee(require_constant || oop_constant->should_be_constant(), "con_type must get computed");
 259           con_type = TypeOopPtr::make_from_constant(oop_constant, require_constant);
 260           if (Compile::current()->eliminate_boxing() && is_autobox_cache) {
 261             con_type = con_type->is_aryptr()->cast_to_autobox_cache();
 262           }
 263           if (stable_dimension > 0) {
 264             assert(FoldStableValues, "sanity");
 265             assert(!con_type->is_zero_type(), "default value for stable field");
 266             con_type = con_type->is_aryptr()->cast_to_stable(true, stable_dimension);
 267           }
 268         }
 269         if (is_narrow_oop) {
 270           con_type = con_type->make_narrowoop();
 271         }
 272         return con_type;
 273       }
 274     case T_ILLEGAL:
 275       // Invalid ciConstant returned due to OutOfMemoryError in the CI
 276       assert(Compile::current()->env()->failing(), "otherwise should not see this");
 277       return NULL;
 278     default:
 279       // Fall through to failure
 280       return NULL;
 281   }
 282 }
 283 
 284 static ciConstant check_mismatched_access(ciConstant con, BasicType loadbt, bool is_unsigned) {
 285   BasicType conbt = con.basic_type();
 286   switch (conbt) {
 287     case T_BOOLEAN: conbt = T_BYTE;   break;
 288     case T_ARRAY:   conbt = T_OBJECT; break;

 289     default:                          break;
 290   }
 291   switch (loadbt) {
 292     case T_BOOLEAN:   loadbt = T_BYTE;   break;
 293     case T_NARROWOOP: loadbt = T_OBJECT; break;
 294     case T_ARRAY:     loadbt = T_OBJECT; break;

 295     case T_ADDRESS:   loadbt = T_OBJECT; break;
 296     default:                             break;
 297   }
 298   if (conbt == loadbt) {
 299     if (is_unsigned && conbt == T_BYTE) {
 300       // LoadB (T_BYTE) with a small mask (<=8-bit) is converted to LoadUB (T_BYTE).
 301       return ciConstant(T_INT, con.as_int() & 0xFF);
 302     } else {
 303       return con;
 304     }
 305   }
 306   if (conbt == T_SHORT && loadbt == T_CHAR) {
 307     // LoadS (T_SHORT) with a small mask (<=16-bit) is converted to LoadUS (T_CHAR).
 308     return ciConstant(T_INT, con.as_int() & 0xFFFF);
 309   }
 310   return ciConstant(); // T_ILLEGAL
 311 }
 312 
 313 // Try to constant-fold a stable array element.
 314 const Type* Type::make_constant_from_array_element(ciArray* array, int off, int stable_dimension,

 510   const Type **ffalse =(const Type**)shared_type_arena->AmallocWords(2*sizeof(Type*));
 511   ffalse[0] = Type::CONTROL;
 512   ffalse[1] = Type::TOP;
 513   TypeTuple::IFFALSE = TypeTuple::make( 2, ffalse );
 514 
 515   const Type **fneither =(const Type**)shared_type_arena->AmallocWords(2*sizeof(Type*));
 516   fneither[0] = Type::TOP;
 517   fneither[1] = Type::TOP;
 518   TypeTuple::IFNEITHER = TypeTuple::make( 2, fneither );
 519 
 520   const Type **ftrue =(const Type**)shared_type_arena->AmallocWords(2*sizeof(Type*));
 521   ftrue[0] = Type::TOP;
 522   ftrue[1] = Type::CONTROL;
 523   TypeTuple::IFTRUE = TypeTuple::make( 2, ftrue );
 524 
 525   const Type **floop =(const Type**)shared_type_arena->AmallocWords(2*sizeof(Type*));
 526   floop[0] = Type::CONTROL;
 527   floop[1] = TypeInt::INT;
 528   TypeTuple::LOOPBODY = TypeTuple::make( 2, floop );
 529 
 530   TypePtr::NULL_PTR= TypePtr::make(AnyPtr, TypePtr::Null, 0);
 531   TypePtr::NOTNULL = TypePtr::make(AnyPtr, TypePtr::NotNull, OffsetBot);
 532   TypePtr::BOTTOM  = TypePtr::make(AnyPtr, TypePtr::BotPTR, OffsetBot);
 533 
 534   TypeRawPtr::BOTTOM = TypeRawPtr::make( TypePtr::BotPTR );
 535   TypeRawPtr::NOTNULL= TypeRawPtr::make( TypePtr::NotNull );
 536 
 537   const Type **fmembar = TypeTuple::fields(0);
 538   TypeTuple::MEMBAR = TypeTuple::make(TypeFunc::Parms+0, fmembar);
 539 
 540   const Type **fsc = (const Type**)shared_type_arena->AmallocWords(2*sizeof(Type*));
 541   fsc[0] = TypeInt::CC;
 542   fsc[1] = Type::MEMORY;
 543   TypeTuple::STORECONDITIONAL = TypeTuple::make(2, fsc);
 544 
 545   TypeInstPtr::NOTNULL = TypeInstPtr::make(TypePtr::NotNull, current->env()->Object_klass());
 546   TypeInstPtr::BOTTOM  = TypeInstPtr::make(TypePtr::BotPTR,  current->env()->Object_klass());
 547   TypeInstPtr::MIRROR  = TypeInstPtr::make(TypePtr::NotNull, current->env()->Class_klass());
 548   TypeInstPtr::MARK    = TypeInstPtr::make(TypePtr::BotPTR,  current->env()->Object_klass(),
 549                                            false, 0, oopDesc::mark_offset_in_bytes());
 550   TypeInstPtr::KLASS   = TypeInstPtr::make(TypePtr::BotPTR,  current->env()->Object_klass(),
 551                                            false, 0, oopDesc::klass_offset_in_bytes());
 552   TypeOopPtr::BOTTOM  = TypeOopPtr::make(TypePtr::BotPTR, OffsetBot, TypeOopPtr::InstanceBot);
 553 
 554   TypeMetadataPtr::BOTTOM = TypeMetadataPtr::make(TypePtr::BotPTR, NULL, OffsetBot);
 555 
 556   TypeNarrowOop::NULL_PTR = TypeNarrowOop::make( TypePtr::NULL_PTR );
 557   TypeNarrowOop::BOTTOM   = TypeNarrowOop::make( TypeInstPtr::BOTTOM );
 558 
 559   TypeNarrowKlass::NULL_PTR = TypeNarrowKlass::make( TypePtr::NULL_PTR );
 560 
 561   mreg2type[Op_Node] = Type::BOTTOM;
 562   mreg2type[Op_Set ] = 0;
 563   mreg2type[Op_RegN] = TypeNarrowOop::BOTTOM;
 564   mreg2type[Op_RegI] = TypeInt::INT;
 565   mreg2type[Op_RegP] = TypePtr::BOTTOM;
 566   mreg2type[Op_RegF] = Type::FLOAT;
 567   mreg2type[Op_RegD] = Type::DOUBLE;
 568   mreg2type[Op_RegL] = TypeLong::LONG;
 569   mreg2type[Op_RegFlags] = TypeInt::CC;
 570 
 571   GrowableArray<ciInstanceKlass*> array_interfaces;
 572   array_interfaces.push(current->env()->Cloneable_klass());
 573   array_interfaces.push(current->env()->Serializable_klass());
 574   TypeAryPtr::_array_interfaces = new TypePtr::InterfaceSet(&array_interfaces);
 575   TypeAryKlassPtr::_array_interfaces = TypeAryPtr::_array_interfaces;
 576 
 577   TypeAryPtr::RANGE   = TypeAryPtr::make( TypePtr::BotPTR, TypeAry::make(Type::BOTTOM,TypeInt::POS), NULL /* current->env()->Object_klass() */, false, arrayOopDesc::length_offset_in_bytes());
 578 
 579   TypeAryPtr::NARROWOOPS = TypeAryPtr::make(TypePtr::BotPTR, TypeAry::make(TypeNarrowOop::BOTTOM, TypeInt::POS), NULL /*ciArrayKlass::make(o)*/,  false,  Type::OffsetBot);
 580 
 581 #ifdef _LP64
 582   if (UseCompressedOops) {
 583     assert(TypeAryPtr::NARROWOOPS->is_ptr_to_narrowoop(), "array of narrow oops must be ptr to narrow oop");
 584     TypeAryPtr::OOPS  = TypeAryPtr::NARROWOOPS;
 585   } else
 586 #endif
 587   {
 588     // There is no shared klass for Object[].  See note in TypeAryPtr::klass().
 589     TypeAryPtr::OOPS  = TypeAryPtr::make(TypePtr::BotPTR, TypeAry::make(TypeInstPtr::BOTTOM,TypeInt::POS), NULL /*ciArrayKlass::make(o)*/,  false,  Type::OffsetBot);
 590   }
 591   TypeAryPtr::BYTES   = TypeAryPtr::make(TypePtr::BotPTR, TypeAry::make(TypeInt::BYTE      ,TypeInt::POS), ciTypeArrayKlass::make(T_BYTE),   true,  Type::OffsetBot);
 592   TypeAryPtr::SHORTS  = TypeAryPtr::make(TypePtr::BotPTR, TypeAry::make(TypeInt::SHORT     ,TypeInt::POS), ciTypeArrayKlass::make(T_SHORT),  true,  Type::OffsetBot);
 593   TypeAryPtr::CHARS   = TypeAryPtr::make(TypePtr::BotPTR, TypeAry::make(TypeInt::CHAR      ,TypeInt::POS), ciTypeArrayKlass::make(T_CHAR),   true,  Type::OffsetBot);
 594   TypeAryPtr::INTS    = TypeAryPtr::make(TypePtr::BotPTR, TypeAry::make(TypeInt::INT       ,TypeInt::POS), ciTypeArrayKlass::make(T_INT),    true,  Type::OffsetBot);
 595   TypeAryPtr::LONGS   = TypeAryPtr::make(TypePtr::BotPTR, TypeAry::make(TypeLong::LONG     ,TypeInt::POS), ciTypeArrayKlass::make(T_LONG),   true,  Type::OffsetBot);
 596   TypeAryPtr::FLOATS  = TypeAryPtr::make(TypePtr::BotPTR, TypeAry::make(Type::FLOAT        ,TypeInt::POS), ciTypeArrayKlass::make(T_FLOAT),  true,  Type::OffsetBot);
 597   TypeAryPtr::DOUBLES = TypeAryPtr::make(TypePtr::BotPTR, TypeAry::make(Type::DOUBLE       ,TypeInt::POS), ciTypeArrayKlass::make(T_DOUBLE), true,  Type::OffsetBot);

 598 
 599   // Nobody should ask _array_body_type[T_NARROWOOP]. Use NULL as assert.
 600   TypeAryPtr::_array_body_type[T_NARROWOOP] = NULL;
 601   TypeAryPtr::_array_body_type[T_OBJECT]  = TypeAryPtr::OOPS;

 602   TypeAryPtr::_array_body_type[T_ARRAY]   = TypeAryPtr::OOPS; // arrays are stored in oop arrays
 603   TypeAryPtr::_array_body_type[T_BYTE]    = TypeAryPtr::BYTES;
 604   TypeAryPtr::_array_body_type[T_BOOLEAN] = TypeAryPtr::BYTES;  // boolean[] is a byte array
 605   TypeAryPtr::_array_body_type[T_SHORT]   = TypeAryPtr::SHORTS;
 606   TypeAryPtr::_array_body_type[T_CHAR]    = TypeAryPtr::CHARS;
 607   TypeAryPtr::_array_body_type[T_INT]     = TypeAryPtr::INTS;
 608   TypeAryPtr::_array_body_type[T_LONG]    = TypeAryPtr::LONGS;
 609   TypeAryPtr::_array_body_type[T_FLOAT]   = TypeAryPtr::FLOATS;
 610   TypeAryPtr::_array_body_type[T_DOUBLE]  = TypeAryPtr::DOUBLES;
 611 
 612   TypeInstKlassPtr::OBJECT = TypeInstKlassPtr::make(TypePtr::NotNull, current->env()->Object_klass(), 0);
 613   TypeInstKlassPtr::OBJECT_OR_NULL = TypeInstKlassPtr::make(TypePtr::BotPTR, current->env()->Object_klass(), 0);
 614 
 615   const Type **fi2c = TypeTuple::fields(2);
 616   fi2c[TypeFunc::Parms+0] = TypeInstPtr::BOTTOM; // Method*
 617   fi2c[TypeFunc::Parms+1] = TypeRawPtr::BOTTOM; // argument pointer
 618   TypeTuple::START_I2C = TypeTuple::make(TypeFunc::Parms+2, fi2c);
 619 
 620   const Type **intpair = TypeTuple::fields(2);
 621   intpair[0] = TypeInt::INT;
 622   intpair[1] = TypeInt::INT;
 623   TypeTuple::INT_PAIR = TypeTuple::make(2, intpair);
 624 
 625   const Type **longpair = TypeTuple::fields(2);
 626   longpair[0] = TypeLong::LONG;
 627   longpair[1] = TypeLong::LONG;
 628   TypeTuple::LONG_PAIR = TypeTuple::make(2, longpair);
 629 
 630   const Type **intccpair = TypeTuple::fields(2);
 631   intccpair[0] = TypeInt::INT;
 632   intccpair[1] = TypeInt::CC;
 633   TypeTuple::INT_CC_PAIR = TypeTuple::make(2, intccpair);
 634 
 635   const Type **longccpair = TypeTuple::fields(2);
 636   longccpair[0] = TypeLong::LONG;
 637   longccpair[1] = TypeInt::CC;
 638   TypeTuple::LONG_CC_PAIR = TypeTuple::make(2, longccpair);
 639 
 640   _const_basic_type[T_NARROWOOP]   = TypeNarrowOop::BOTTOM;
 641   _const_basic_type[T_NARROWKLASS] = Type::BOTTOM;
 642   _const_basic_type[T_BOOLEAN]     = TypeInt::BOOL;
 643   _const_basic_type[T_CHAR]        = TypeInt::CHAR;
 644   _const_basic_type[T_BYTE]        = TypeInt::BYTE;
 645   _const_basic_type[T_SHORT]       = TypeInt::SHORT;
 646   _const_basic_type[T_INT]         = TypeInt::INT;
 647   _const_basic_type[T_LONG]        = TypeLong::LONG;
 648   _const_basic_type[T_FLOAT]       = Type::FLOAT;
 649   _const_basic_type[T_DOUBLE]      = Type::DOUBLE;
 650   _const_basic_type[T_OBJECT]      = TypeInstPtr::BOTTOM;
 651   _const_basic_type[T_ARRAY]       = TypeInstPtr::BOTTOM; // there is no separate bottom for arrays

 652   _const_basic_type[T_VOID]        = TypePtr::NULL_PTR;   // reflection represents void this way
 653   _const_basic_type[T_ADDRESS]     = TypeRawPtr::BOTTOM;  // both interpreter return addresses & random raw ptrs
 654   _const_basic_type[T_CONFLICT]    = Type::BOTTOM;        // why not?
 655 
 656   _zero_type[T_NARROWOOP]   = TypeNarrowOop::NULL_PTR;
 657   _zero_type[T_NARROWKLASS] = TypeNarrowKlass::NULL_PTR;
 658   _zero_type[T_BOOLEAN]     = TypeInt::ZERO;     // false == 0
 659   _zero_type[T_CHAR]        = TypeInt::ZERO;     // '\0' == 0
 660   _zero_type[T_BYTE]        = TypeInt::ZERO;     // 0x00 == 0
 661   _zero_type[T_SHORT]       = TypeInt::ZERO;     // 0x0000 == 0
 662   _zero_type[T_INT]         = TypeInt::ZERO;
 663   _zero_type[T_LONG]        = TypeLong::ZERO;
 664   _zero_type[T_FLOAT]       = TypeF::ZERO;
 665   _zero_type[T_DOUBLE]      = TypeD::ZERO;
 666   _zero_type[T_OBJECT]      = TypePtr::NULL_PTR;
 667   _zero_type[T_ARRAY]       = TypePtr::NULL_PTR; // null array is null oop

 668   _zero_type[T_ADDRESS]     = TypePtr::NULL_PTR; // raw pointers use the same null
 669   _zero_type[T_VOID]        = Type::TOP;         // the only void value is no value at all
 670 
 671   // get_zero_type() should not happen for T_CONFLICT
 672   _zero_type[T_CONFLICT]= NULL;
 673 
 674   TypeVect::VECTMASK = (TypeVect*)(new TypeVectMask(TypeInt::BOOL, MaxVectorSize))->hashcons();
 675   mreg2type[Op_RegVectMask] = TypeVect::VECTMASK;
 676 
 677   if (Matcher::supports_scalable_vector()) {
 678     TypeVect::VECTA = TypeVect::make(T_BYTE, Matcher::scalable_vector_reg_size(T_BYTE));
 679   }
 680 
 681   // Vector predefined types, it needs initialized _const_basic_type[].
 682   if (Matcher::vector_size_supported(T_BYTE,4)) {
 683     TypeVect::VECTS = TypeVect::make(T_BYTE,4);
 684   }
 685   if (Matcher::vector_size_supported(T_FLOAT,2)) {
 686     TypeVect::VECTD = TypeVect::make(T_FLOAT,2);
 687   }

1964 
1965 bool TypeLong::empty(void) const {
1966   return _lo > _hi;
1967 }
1968 
1969 //=============================================================================
1970 // Convenience common pre-built types.
1971 const TypeTuple *TypeTuple::IFBOTH;     // Return both arms of IF as reachable
1972 const TypeTuple *TypeTuple::IFFALSE;
1973 const TypeTuple *TypeTuple::IFTRUE;
1974 const TypeTuple *TypeTuple::IFNEITHER;
1975 const TypeTuple *TypeTuple::LOOPBODY;
1976 const TypeTuple *TypeTuple::MEMBAR;
1977 const TypeTuple *TypeTuple::STORECONDITIONAL;
1978 const TypeTuple *TypeTuple::START_I2C;
1979 const TypeTuple *TypeTuple::INT_PAIR;
1980 const TypeTuple *TypeTuple::LONG_PAIR;
1981 const TypeTuple *TypeTuple::INT_CC_PAIR;
1982 const TypeTuple *TypeTuple::LONG_CC_PAIR;
1983 












1984 //------------------------------make-------------------------------------------
1985 // Make a TypeTuple from the range of a method signature
1986 const TypeTuple *TypeTuple::make_range(ciSignature* sig, InterfaceHandling interface_handling) {
1987   ciType* return_type = sig->return_type();
1988   uint arg_cnt = return_type->size();








1989   const Type **field_array = fields(arg_cnt);
1990   switch (return_type->basic_type()) {
1991   case T_LONG:
1992     field_array[TypeFunc::Parms]   = TypeLong::LONG;
1993     field_array[TypeFunc::Parms+1] = Type::HALF;
1994     break;
1995   case T_DOUBLE:
1996     field_array[TypeFunc::Parms]   = Type::DOUBLE;
1997     field_array[TypeFunc::Parms+1] = Type::HALF;
1998     break;
1999   case T_OBJECT:
2000   case T_ARRAY:
2001   case T_BOOLEAN:
2002   case T_CHAR:
2003   case T_FLOAT:
2004   case T_BYTE:
2005   case T_SHORT:
2006   case T_INT:
2007     field_array[TypeFunc::Parms] = get_const_type(return_type, interface_handling);
2008     break;













2009   case T_VOID:
2010     break;
2011   default:
2012     ShouldNotReachHere();
2013   }
2014   return (TypeTuple*)(new TypeTuple(TypeFunc::Parms + arg_cnt, field_array))->hashcons();
2015 }
2016 
2017 // Make a TypeTuple from the domain of a method signature
2018 const TypeTuple *TypeTuple::make_domain(ciInstanceKlass* recv, ciSignature* sig, InterfaceHandling interface_handling) {
2019   uint arg_cnt = sig->size();








2020 
2021   uint pos = TypeFunc::Parms;
2022   const Type **field_array;
2023   if (recv != NULL) {
2024     arg_cnt++;
2025     field_array = fields(arg_cnt);
2026     // Use get_const_type here because it respects UseUniqueSubclasses:
2027     field_array[pos++] = get_const_type(recv, interface_handling)->join_speculative(TypePtr::NOTNULL);
2028   } else {
2029     field_array = fields(arg_cnt);
2030   }
2031 
2032   int i = 0;
2033   while (pos < TypeFunc::Parms + arg_cnt) {
2034     ciType* type = sig->type_at(i);

2035 
2036     switch (type->basic_type()) {
2037     case T_LONG:
2038       field_array[pos++] = TypeLong::LONG;
2039       field_array[pos++] = Type::HALF;
2040       break;
2041     case T_DOUBLE:
2042       field_array[pos++] = Type::DOUBLE;
2043       field_array[pos++] = Type::HALF;
2044       break;
2045     case T_OBJECT:
2046     case T_ARRAY:
2047     case T_FLOAT:
2048     case T_INT:
2049       field_array[pos++] = get_const_type(type, interface_handling);
2050       break;
2051     case T_BOOLEAN:
2052     case T_CHAR:
2053     case T_BYTE:
2054     case T_SHORT:
2055       field_array[pos++] = TypeInt::INT;
2056       break;












2057     default:
2058       ShouldNotReachHere();
2059     }
2060     i++;
2061   }

2062 
2063   return (TypeTuple*)(new TypeTuple(TypeFunc::Parms + arg_cnt, field_array))->hashcons();
2064 }
2065 
2066 const TypeTuple *TypeTuple::make( uint cnt, const Type **fields ) {
2067   return (TypeTuple*)(new TypeTuple(cnt,fields))->hashcons();
2068 }
2069 
2070 //------------------------------fields-----------------------------------------
2071 // Subroutine call type with space allocated for argument types
2072 // Memory for Control, I_O, Memory, FramePtr, and ReturnAdr is allocated implicitly
2073 const Type **TypeTuple::fields( uint arg_cnt ) {
2074   const Type **flds = (const Type **)(Compile::current()->type_arena()->AmallocWords((TypeFunc::Parms+arg_cnt)*sizeof(Type*) ));
2075   flds[TypeFunc::Control  ] = Type::CONTROL;
2076   flds[TypeFunc::I_O      ] = Type::ABIO;
2077   flds[TypeFunc::Memory   ] = Type::MEMORY;
2078   flds[TypeFunc::FramePtr ] = TypeRawPtr::BOTTOM;
2079   flds[TypeFunc::ReturnAdr] = Type::RETURN_ADDRESS;
2080 
2081   return flds;

2176     if (_fields[i]->empty())  return true;
2177   }
2178   return false;
2179 }
2180 
2181 //=============================================================================
2182 // Convenience common pre-built types.
2183 
2184 inline const TypeInt* normalize_array_size(const TypeInt* size) {
2185   // Certain normalizations keep us sane when comparing types.
2186   // We do not want arrayOop variables to differ only by the wideness
2187   // of their index types.  Pick minimum wideness, since that is the
2188   // forced wideness of small ranges anyway.
2189   if (size->_widen != Type::WidenMin)
2190     return TypeInt::make(size->_lo, size->_hi, Type::WidenMin);
2191   else
2192     return size;
2193 }
2194 
2195 //------------------------------make-------------------------------------------
2196 const TypeAry* TypeAry::make(const Type* elem, const TypeInt* size, bool stable) {

2197   if (UseCompressedOops && elem->isa_oopptr()) {
2198     elem = elem->make_narrowoop();
2199   }
2200   size = normalize_array_size(size);
2201   return (TypeAry*)(new TypeAry(elem,size,stable))->hashcons();
2202 }
2203 
2204 //------------------------------meet-------------------------------------------
2205 // Compute the MEET of two types.  It returns a new Type object.
2206 const Type *TypeAry::xmeet( const Type *t ) const {
2207   // Perform a fast test for common case; meeting the same types together.
2208   if( this == t ) return this;  // Meeting same type-rep?
2209 
2210   // Current "this->_base" is Ary
2211   switch (t->base()) {          // switch on original type
2212 
2213   case Bottom:                  // Ye Olde Default
2214     return t;
2215 
2216   default:                      // All else is a mistake
2217     typerr(t);
2218 
2219   case Array: {                 // Meeting 2 arrays?
2220     const TypeAry *a = t->is_ary();
2221     return TypeAry::make(_elem->meet_speculative(a->_elem),
2222                          _size->xmeet(a->_size)->is_int(),
2223                          _stable && a->_stable);



2224   }
2225   case Top:
2226     break;
2227   }
2228   return this;                  // Return the double constant
2229 }
2230 
2231 //------------------------------xdual------------------------------------------
2232 // Dual: compute field-by-field dual
2233 const Type *TypeAry::xdual() const {
2234   const TypeInt* size_dual = _size->dual()->is_int();
2235   size_dual = normalize_array_size(size_dual);
2236   return new TypeAry(_elem->dual(), size_dual, !_stable);
2237 }
2238 
2239 //------------------------------eq---------------------------------------------
2240 // Structural equality check for Type representations
2241 bool TypeAry::eq( const Type *t ) const {
2242   const TypeAry *a = (const TypeAry*)t;
2243   return _elem == a->_elem &&
2244     _stable == a->_stable &&
2245     _size == a->_size;




2246 }
2247 
2248 //------------------------------hash-------------------------------------------
2249 // Type-specific hashing function.
2250 int TypeAry::hash(void) const {
2251   return (intptr_t)_elem + (intptr_t)_size + (_stable ? 43 : 0);

2252 }
2253 
2254 /**
2255  * Return same type without a speculative part in the element
2256  */
2257 const TypeAry* TypeAry::remove_speculative() const {
2258   return make(_elem->remove_speculative(), _size, _stable);
2259 }
2260 
2261 /**
2262  * Return same type with cleaned up speculative part of element
2263  */
2264 const Type* TypeAry::cleanup_speculative() const {
2265   return make(_elem->cleanup_speculative(), _size, _stable);
2266 }
2267 
2268 /**
2269  * Return same type but with a different inline depth (used for speculation)
2270  *
2271  * @param depth  depth to meet with
2272  */
2273 const TypePtr* TypePtr::with_inline_depth(int depth) const {
2274   if (!UseInlineDepthForSpeculativeTypes) {
2275     return this;
2276   }
2277   return make(AnyPtr, _ptr, _offset, _speculative, depth);
2278 }
2279 
2280 //------------------------------dump2------------------------------------------
2281 #ifndef PRODUCT
2282 void TypeAry::dump2( Dict &d, uint depth, outputStream *st ) const {
2283   if (_stable)  st->print("stable:");





2284   _elem->dump2(d, depth, st);
2285   st->print("[");
2286   _size->dump2(d, depth, st);
2287   st->print("]");
2288 }
2289 #endif
2290 
2291 //------------------------------singleton--------------------------------------
2292 // TRUE if Type is a singleton type, FALSE otherwise.   Singletons are simple
2293 // constants (Ldi nodes).  Singletons are integer, float or double constants
2294 // or a single symbol.
2295 bool TypeAry::singleton(void) const {
2296   return false;                 // Never a singleton
2297 }
2298 
2299 bool TypeAry::empty(void) const {
2300   return _elem->empty() || _size->empty();
2301 }
2302 
2303 //--------------------------ary_must_be_exact----------------------------------
2304 bool TypeAry::ary_must_be_exact() const {
2305   // This logic looks at the element type of an array, and returns true
2306   // if the element type is either a primitive or a final instance class.
2307   // In such cases, an array built on this ary must have no subclasses.
2308   if (_elem == BOTTOM)      return false;  // general array not exact
2309   if (_elem == TOP   )      return false;  // inverted general array not exact
2310   const TypeOopPtr*  toop = NULL;
2311   if (UseCompressedOops && _elem->isa_narrowoop()) {
2312     toop = _elem->make_ptr()->isa_oopptr();
2313   } else {
2314     toop = _elem->isa_oopptr();
2315   }
2316   if (!toop)                return true;   // a primitive type, like int
2317   if (!toop->is_loaded())   return false;  // unloaded class
2318   const TypeInstPtr* tinst;
2319   if (_elem->isa_narrowoop())
2320     tinst = _elem->make_ptr()->isa_instptr();
2321   else
2322     tinst = _elem->isa_instptr();
2323   if (tinst)
2324     return tinst->instance_klass()->is_final();








2325   const TypeAryPtr*  tap;
2326   if (_elem->isa_narrowoop())
2327     tap = _elem->make_ptr()->isa_aryptr();
2328   else
2329     tap = _elem->isa_aryptr();
2330   if (tap)
2331     return tap->ary()->ary_must_be_exact();
2332   return false;
2333 }
2334 
2335 //==============================TypeVect=======================================
2336 // Convenience common pre-built types.
2337 const TypeVect *TypeVect::VECTA = NULL; // vector length agnostic
2338 const TypeVect *TypeVect::VECTS = NULL; //  32-bit vectors
2339 const TypeVect *TypeVect::VECTD = NULL; //  64-bit vectors
2340 const TypeVect *TypeVect::VECTX = NULL; // 128-bit vectors
2341 const TypeVect *TypeVect::VECTY = NULL; // 256-bit vectors
2342 const TypeVect *TypeVect::VECTZ = NULL; // 512-bit vectors
2343 const TypeVect *TypeVect::VECTMASK = NULL; // predicate/mask vector
2344 

2500 
2501 //=============================================================================
2502 // Convenience common pre-built types.
2503 const TypePtr *TypePtr::NULL_PTR;
2504 const TypePtr *TypePtr::NOTNULL;
2505 const TypePtr *TypePtr::BOTTOM;
2506 
2507 //------------------------------meet-------------------------------------------
2508 // Meet over the PTR enum
2509 const TypePtr::PTR TypePtr::ptr_meet[TypePtr::lastPTR][TypePtr::lastPTR] = {
2510   //              TopPTR,    AnyNull,   Constant, Null,   NotNull, BotPTR,
2511   { /* Top     */ TopPTR,    AnyNull,   Constant, Null,   NotNull, BotPTR,},
2512   { /* AnyNull */ AnyNull,   AnyNull,   Constant, BotPTR, NotNull, BotPTR,},
2513   { /* Constant*/ Constant,  Constant,  Constant, BotPTR, NotNull, BotPTR,},
2514   { /* Null    */ Null,      BotPTR,    BotPTR,   Null,   BotPTR,  BotPTR,},
2515   { /* NotNull */ NotNull,   NotNull,   NotNull,  BotPTR, NotNull, BotPTR,},
2516   { /* BotPTR  */ BotPTR,    BotPTR,    BotPTR,   BotPTR, BotPTR,  BotPTR,}
2517 };
2518 
2519 //------------------------------make-------------------------------------------
2520 const TypePtr *TypePtr::make(TYPES t, enum PTR ptr, int offset, const TypePtr* speculative, int inline_depth) {
2521   return (TypePtr*)(new TypePtr(t,ptr,offset, speculative, inline_depth))->hashcons();
2522 }
2523 
2524 //------------------------------cast_to_ptr_type-------------------------------
2525 const TypePtr* TypePtr::cast_to_ptr_type(PTR ptr) const {
2526   assert(_base == AnyPtr, "subclass must override cast_to_ptr_type");
2527   if( ptr == _ptr ) return this;
2528   return make(_base, ptr, _offset, _speculative, _inline_depth);
2529 }
2530 
2531 //------------------------------get_con----------------------------------------
2532 intptr_t TypePtr::get_con() const {
2533   assert( _ptr == Null, "" );
2534   return _offset;
2535 }
2536 
2537 //------------------------------meet-------------------------------------------
2538 // Compute the MEET of two types.  It returns a new Type object.
2539 const Type *TypePtr::xmeet(const Type *t) const {
2540   const Type* res = xmeet_helper(t);
2541   if (res->isa_ptr() == NULL) {
2542     return res;
2543   }
2544 
2545   const TypePtr* res_ptr = res->is_ptr();
2546   if (res_ptr->speculative() != NULL) {
2547     // type->speculative() == NULL means that speculation is no better
2548     // than type, i.e. type->speculative() == type. So there are 2
2549     // ways to represent the fact that we have no useful speculative
2550     // data and we should use a single one to be able to test for
2551     // equality between types. Check whether type->speculative() ==
2552     // type and set speculative to NULL if it is the case.
2553     if (res_ptr->remove_speculative() == res_ptr->speculative()) {
2554       return res_ptr->remove_speculative();

2585     int depth = meet_inline_depth(tp->inline_depth());
2586     return make(AnyPtr, meet_ptr(tp->ptr()), meet_offset(tp->offset()), speculative, depth);
2587   }
2588   case RawPtr:                  // For these, flip the call around to cut down
2589   case OopPtr:
2590   case InstPtr:                 // on the cases I have to handle.
2591   case AryPtr:
2592   case MetadataPtr:
2593   case KlassPtr:
2594   case InstKlassPtr:
2595   case AryKlassPtr:
2596     return t->xmeet(this);      // Call in reverse direction
2597   default:                      // All else is a mistake
2598     typerr(t);
2599 
2600   }
2601   return this;
2602 }
2603 
2604 //------------------------------meet_offset------------------------------------
2605 int TypePtr::meet_offset( int offset ) const {
2606   // Either is 'TOP' offset?  Return the other offset!
2607   if( _offset == OffsetTop ) return offset;
2608   if( offset == OffsetTop ) return _offset;
2609   // If either is different, return 'BOTTOM' offset
2610   if( _offset != offset ) return OffsetBot;
2611   return _offset;
2612 }
2613 
2614 //------------------------------dual_offset------------------------------------
2615 int TypePtr::dual_offset( ) const {
2616   if( _offset == OffsetTop ) return OffsetBot;// Map 'TOP' into 'BOTTOM'
2617   if( _offset == OffsetBot ) return OffsetTop;// Map 'BOTTOM' into 'TOP'
2618   return _offset;               // Map everything else into self
2619 }
2620 
2621 //------------------------------xdual------------------------------------------
2622 // Dual: compute field-by-field dual
2623 const TypePtr::PTR TypePtr::ptr_dual[TypePtr::lastPTR] = {
2624   BotPTR, NotNull, Constant, Null, AnyNull, TopPTR
2625 };
2626 const Type *TypePtr::xdual() const {
2627   return new TypePtr(AnyPtr, dual_ptr(), dual_offset(), dual_speculative(), dual_inline_depth());
2628 }
2629 
2630 //------------------------------xadd_offset------------------------------------
2631 int TypePtr::xadd_offset( intptr_t offset ) const {
2632   // Adding to 'TOP' offset?  Return 'TOP'!
2633   if( _offset == OffsetTop || offset == OffsetTop ) return OffsetTop;
2634   // Adding to 'BOTTOM' offset?  Return 'BOTTOM'!
2635   if( _offset == OffsetBot || offset == OffsetBot ) return OffsetBot;
2636   // Addition overflows or "accidentally" equals to OffsetTop? Return 'BOTTOM'!
2637   offset += (intptr_t)_offset;
2638   if (offset != (int)offset || offset == OffsetTop) return OffsetBot;
2639 
2640   // assert( _offset >= 0 && _offset+offset >= 0, "" );
2641   // It is possible to construct a negative offset during PhaseCCP
2642 
2643   return (int)offset;        // Sum valid offsets
2644 }
2645 
2646 //------------------------------add_offset-------------------------------------
2647 const TypePtr *TypePtr::add_offset( intptr_t offset ) const {
2648   return make(AnyPtr, _ptr, xadd_offset(offset), _speculative, _inline_depth);
2649 }
2650 
2651 const TypePtr *TypePtr::with_offset(intptr_t offset) const {
2652   return make(AnyPtr, _ptr, offset, _speculative, _inline_depth);
2653 }
2654 
2655 //------------------------------eq---------------------------------------------
2656 // Structural equality check for Type representations
2657 bool TypePtr::eq( const Type *t ) const {
2658   const TypePtr *a = (const TypePtr*)t;
2659   return _ptr == a->ptr() && _offset == a->offset() && eq_speculative(a) && _inline_depth == a->_inline_depth;
2660 }
2661 
2662 //------------------------------hash-------------------------------------------
2663 // Type-specific hashing function.
2664 int TypePtr::hash(void) const {
2665   return java_add(java_add((jint)_ptr, (jint)_offset), java_add((jint)hash_speculative(), (jint)_inline_depth));
2666 ;
2667 }
2668 
2669 /**
2670  * Return same type without a speculative part
2671  */
2672 const TypePtr* TypePtr::remove_speculative() const {
2673   if (_speculative == NULL) {
2674     return this;
2675   }
2676   assert(_inline_depth == InlineDepthTop || _inline_depth == InlineDepthBottom, "non speculative type shouldn't have inline depth");
2677   return make(AnyPtr, _ptr, _offset, NULL, _inline_depth);
2678 }
2679 
2680 /**
2681  * Return same type but drop speculative part if we know we won't use
2682  * it
2683  */
2684 const Type* TypePtr::cleanup_speculative() const {
2685   if (speculative() == NULL) {

2801   if (_speculative == NULL) {
2802     return NULL;
2803   }
2804   return _speculative->add_offset(offset)->is_ptr();
2805 }
2806 
2807 const TypePtr* TypePtr::with_offset_speculative(intptr_t offset) const {
2808   if (_speculative == NULL) {
2809     return NULL;
2810   }
2811   return _speculative->with_offset(offset)->is_ptr();
2812 }
2813 
2814 /**
2815  * return exact klass from the speculative type if there's one
2816  */
2817 ciKlass* TypePtr::speculative_type() const {
2818   if (_speculative != NULL && _speculative->isa_oopptr()) {
2819     const TypeOopPtr* speculative = _speculative->join(this)->is_oopptr();
2820     if (speculative->klass_is_exact()) {
2821       return speculative->klass();
2822     }
2823   }
2824   return NULL;
2825 }
2826 
2827 /**
2828  * return true if speculative type may be null
2829  */
2830 bool TypePtr::speculative_maybe_null() const {
2831   if (_speculative != NULL) {
2832     const TypePtr* speculative = _speculative->join(this)->is_ptr();
2833     return speculative->maybe_null();
2834   }
2835   return true;
2836 }
2837 
2838 bool TypePtr::speculative_always_null() const {
2839   if (_speculative != NULL) {
2840     const TypePtr* speculative = _speculative->join(this)->is_ptr();
2841     return speculative == TypePtr::NULL_PTR;

2912   }
2913   // We already know the speculative type is always null
2914   if (speculative_always_null()) {
2915     return false;
2916   }
2917   if (ptr_kind == ProfileAlwaysNull && speculative() != NULL && speculative()->isa_oopptr()) {
2918     return false;
2919   }
2920   return true;
2921 }
2922 
2923 //------------------------------dump2------------------------------------------
2924 const char *const TypePtr::ptr_msg[TypePtr::lastPTR] = {
2925   "TopPTR","AnyNull","Constant","NULL","NotNull","BotPTR"
2926 };
2927 
2928 #ifndef PRODUCT
2929 void TypePtr::dump2( Dict &d, uint depth, outputStream *st ) const {
2930   if( _ptr == Null ) st->print("NULL");
2931   else st->print("%s *", ptr_msg[_ptr]);
2932   if( _offset == OffsetTop ) st->print("+top");
2933   else if( _offset == OffsetBot ) st->print("+bot");
2934   else if( _offset ) st->print("+%d", _offset);
2935   dump_inline_depth(st);
2936   dump_speculative(st);
2937 }
2938 
2939 /**
2940  *dump the speculative part of the type
2941  */
2942 void TypePtr::dump_speculative(outputStream *st) const {
2943   if (_speculative != NULL) {
2944     st->print(" (speculative=");
2945     _speculative->dump_on(st);
2946     st->print(")");
2947   }
2948 }
2949 
2950 /**
2951  *dump the inline depth of the type
2952  */
2953 void TypePtr::dump_inline_depth(outputStream *st) const {
2954   if (_inline_depth != InlineDepthBottom) {
2955     if (_inline_depth == InlineDepthTop) {
2956       st->print(" (inline_depth=InlineDepthTop)");
2957     } else {
2958       st->print(" (inline_depth=%d)", _inline_depth);
2959     }
2960   }
2961 }
2962 #endif
2963 
2964 //------------------------------singleton--------------------------------------
2965 // TRUE if Type is a singleton type, FALSE otherwise.   Singletons are simple
2966 // constants
2967 bool TypePtr::singleton(void) const {
2968   // TopPTR, Null, AnyNull, Constant are all singletons
2969   return (_offset != OffsetBot) && !below_centerline(_ptr);
2970 }
2971 
2972 bool TypePtr::empty(void) const {
2973   return (_offset == OffsetTop) || above_centerline(_ptr);
2974 }
2975 
2976 //=============================================================================
2977 // Convenience common pre-built types.
2978 const TypeRawPtr *TypeRawPtr::BOTTOM;
2979 const TypeRawPtr *TypeRawPtr::NOTNULL;
2980 
2981 //------------------------------make-------------------------------------------
2982 const TypeRawPtr *TypeRawPtr::make( enum PTR ptr ) {
2983   assert( ptr != Constant, "what is the constant?" );
2984   assert( ptr != Null, "Use TypePtr for NULL" );
2985   return (TypeRawPtr*)(new TypeRawPtr(ptr,0))->hashcons();
2986 }
2987 
2988 const TypeRawPtr *TypeRawPtr::make( address bits ) {
2989   assert( bits, "Use TypePtr for NULL" );
2990   return (TypeRawPtr*)(new TypeRawPtr(Constant,bits))->hashcons();
2991 }
2992 
2993 //------------------------------cast_to_ptr_type-------------------------------

3326     return _is_loaded;
3327   }
3328   const_cast<InterfaceSet*>(this)->compute_is_loaded();
3329   assert(_is_loaded_computed, "should be computed now");
3330   return _is_loaded;
3331 }
3332 
3333 void TypePtr::InterfaceSet::compute_is_loaded() {
3334   _is_loaded_computed = 1;
3335   for (int i = 0; i < _list.length(); i++) {
3336     ciKlass* interface = _list.at(i);
3337     if (!interface->is_loaded()) {
3338       _is_loaded = false;
3339       return;
3340     }
3341   }
3342   _is_loaded = true;
3343 }
3344 
3345 //------------------------------TypeOopPtr-------------------------------------
3346 TypeOopPtr::TypeOopPtr(TYPES t, PTR ptr, ciKlass* k, const InterfaceSet& interfaces, bool xk, ciObject* o, int offset,
3347                        int instance_id, const TypePtr* speculative, int inline_depth)
3348   : TypePtr(t, ptr, offset, speculative, inline_depth),
3349     _const_oop(o), _klass(k),
3350     _interfaces(interfaces),
3351     _klass_is_exact(xk),
3352     _is_ptr_to_narrowoop(false),
3353     _is_ptr_to_narrowklass(false),
3354     _is_ptr_to_boxed_value(false),
3355     _instance_id(instance_id) {
3356   if (Compile::current()->eliminate_boxing() && (t == InstPtr) &&
3357       (offset > 0) && xk && (k != 0) && k->is_instance_klass()) {
3358     _is_ptr_to_boxed_value = k->as_instance_klass()->is_boxed_value_offset(offset);
3359   }
3360 #ifdef _LP64
3361   if (_offset > 0 || _offset == Type::OffsetTop || _offset == Type::OffsetBot) {
3362     if (_offset == oopDesc::klass_offset_in_bytes()) {
3363       _is_ptr_to_narrowklass = UseCompressedClassPointers;
3364     } else if (klass() == NULL) {
3365       // Array with unknown body type
3366       assert(this->isa_aryptr(), "only arrays without klass");
3367       _is_ptr_to_narrowoop = UseCompressedOops;
3368     } else if (this->isa_aryptr()) {
3369       _is_ptr_to_narrowoop = (UseCompressedOops && klass()->is_obj_array_klass() &&
3370                              _offset != arrayOopDesc::length_offset_in_bytes());









3371     } else if (klass()->is_instance_klass()) {
3372       ciInstanceKlass* ik = klass()->as_instance_klass();
3373       ciField* field = NULL;
3374       if (this->isa_klassptr()) {
3375         // Perm objects don't use compressed references
3376       } else if (_offset == OffsetBot || _offset == OffsetTop) {
3377         // unsafe access
3378         _is_ptr_to_narrowoop = UseCompressedOops;
3379       } else {
3380         assert(this->isa_instptr(), "must be an instance ptr.");
3381 
3382         if (klass() == ciEnv::current()->Class_klass() &&
3383             (_offset == java_lang_Class::klass_offset() ||
3384              _offset == java_lang_Class::array_klass_offset())) {
3385           // Special hidden fields from the Class.
3386           assert(this->isa_instptr(), "must be an instance ptr.");
3387           _is_ptr_to_narrowoop = false;
3388         } else if (klass() == ciEnv::current()->Class_klass() &&
3389                    _offset >= InstanceMirrorKlass::offset_of_static_fields()) {
3390           // Static fields
3391           ciField* field = NULL;
3392           if (const_oop() != NULL) {
3393             ciInstanceKlass* k = const_oop()->as_instance()->java_lang_Class_klass()->as_instance_klass();
3394             field = k->get_field_by_offset(_offset, true);
3395           }
3396           if (field != NULL) {
3397             BasicType basic_elem_type = field->layout_type();
3398             _is_ptr_to_narrowoop = UseCompressedOops && ::is_reference_type(basic_elem_type);
3399           } else {
3400             // unsafe access
3401             _is_ptr_to_narrowoop = UseCompressedOops;






3402           }
3403         } else {
3404           // Instance fields which contains a compressed oop references.
3405           field = ik->get_field_by_offset(_offset, false);

3406           if (field != NULL) {
3407             BasicType basic_elem_type = field->layout_type();
3408             _is_ptr_to_narrowoop = UseCompressedOops && ::is_reference_type(basic_elem_type);
3409           } else if (klass()->equals(ciEnv::current()->Object_klass())) {
3410             // Compile::find_alias_type() cast exactness on all types to verify
3411             // that it does not affect alias type.
3412             _is_ptr_to_narrowoop = UseCompressedOops;
3413           } else {
3414             // Type for the copy start in LibraryCallKit::inline_native_clone().
3415             _is_ptr_to_narrowoop = UseCompressedOops;
3416           }
3417         }
3418       }
3419     }
3420   }
3421 #endif
3422 }
3423 
3424 //------------------------------make-------------------------------------------
3425 const TypeOopPtr *TypeOopPtr::make(PTR ptr, int offset, int instance_id,
3426                                      const TypePtr* speculative, int inline_depth) {
3427   assert(ptr != Constant, "no constant generic pointers");
3428   ciKlass*  k = Compile::current()->env()->Object_klass();
3429   bool      xk = false;
3430   ciObject* o = NULL;
3431   return (TypeOopPtr*)(new TypeOopPtr(OopPtr, ptr, k, InterfaceSet(), xk, o, offset, instance_id, speculative, inline_depth))->hashcons();
3432 }
3433 
3434 
3435 //------------------------------cast_to_ptr_type-------------------------------
3436 const TypeOopPtr* TypeOopPtr::cast_to_ptr_type(PTR ptr) const {
3437   assert(_base == OopPtr, "subclass must override cast_to_ptr_type");
3438   if( ptr == _ptr ) return this;
3439   return make(ptr, _offset, _instance_id, _speculative, _inline_depth);
3440 }
3441 
3442 //-----------------------------cast_to_instance_id----------------------------
3443 const TypeOopPtr *TypeOopPtr::cast_to_instance_id(int instance_id) const {
3444   // There are no instances of a general oop.
3445   // Return self unchanged.
3446   return this;
3447 }
3448 
3449 //-----------------------------cast_to_exactness-------------------------------
3450 const TypeOopPtr* TypeOopPtr::cast_to_exactness(bool klass_is_exact) const {
3451   // There is no such thing as an exact general oop.
3452   // Return self unchanged.
3453   return this;
3454 }
3455 
3456 
3457 //------------------------------as_klass_type----------------------------------
3458 // Return the klass type corresponding to this instance or array type.
3459 // It is the type that is loaded from an object of this type.
3460 const TypeKlassPtr* TypeOopPtr::as_klass_type(bool try_for_exact) const {
3461   ShouldNotReachHere();
3462   return NULL;
3463 }
3464 
3465 //------------------------------meet-------------------------------------------
3466 // Compute the MEET of two types.  It returns a new Type object.
3467 const Type *TypeOopPtr::xmeet_helper(const Type *t) const {
3468   // Perform a fast test for common case; meeting the same types together.
3469   if( this == t ) return this;  // Meeting same type-rep?
3470 
3471   // Current "this->_base" is OopPtr
3472   switch (t->base()) {          // switch on original type
3473 
3474   case Int:                     // Mixing ints & oops happens when javac
3475   case Long:                    // reuses local variables
3476   case FloatTop:

3482   case NarrowOop:
3483   case NarrowKlass:
3484   case Bottom:                  // Ye Olde Default
3485     return Type::BOTTOM;
3486   case Top:
3487     return this;
3488 
3489   default:                      // All else is a mistake
3490     typerr(t);
3491 
3492   case RawPtr:
3493   case MetadataPtr:
3494   case KlassPtr:
3495   case InstKlassPtr:
3496   case AryKlassPtr:
3497     return TypePtr::BOTTOM;     // Oop meet raw is not well defined
3498 
3499   case AnyPtr: {
3500     // Found an AnyPtr type vs self-OopPtr type
3501     const TypePtr *tp = t->is_ptr();
3502     int offset = meet_offset(tp->offset());
3503     PTR ptr = meet_ptr(tp->ptr());
3504     const TypePtr* speculative = xmeet_speculative(tp);
3505     int depth = meet_inline_depth(tp->inline_depth());
3506     switch (tp->ptr()) {
3507     case Null:
3508       if (ptr == Null)  return TypePtr::make(AnyPtr, ptr, offset, speculative, depth);
3509       // else fall through:
3510     case TopPTR:
3511     case AnyNull: {
3512       int instance_id = meet_instance_id(InstanceTop);
3513       return make(ptr, offset, instance_id, speculative, depth);
3514     }
3515     case BotPTR:
3516     case NotNull:
3517       return TypePtr::make(AnyPtr, ptr, offset, speculative, depth);
3518     default: typerr(t);
3519     }
3520   }
3521 
3522   case OopPtr: {                 // Meeting to other OopPtrs

3524     int instance_id = meet_instance_id(tp->instance_id());
3525     const TypePtr* speculative = xmeet_speculative(tp);
3526     int depth = meet_inline_depth(tp->inline_depth());
3527     return make(meet_ptr(tp->ptr()), meet_offset(tp->offset()), instance_id, speculative, depth);
3528   }
3529 
3530   case InstPtr:                  // For these, flip the call around to cut down
3531   case AryPtr:
3532     return t->xmeet(this);      // Call in reverse direction
3533 
3534   } // End of switch
3535   return this;                  // Return the double constant
3536 }
3537 
3538 
3539 //------------------------------xdual------------------------------------------
3540 // Dual of a pure heap pointer.  No relevant klass or oop information.
3541 const Type *TypeOopPtr::xdual() const {
3542   assert(klass() == Compile::current()->env()->Object_klass(), "no klasses here");
3543   assert(const_oop() == NULL,             "no constants here");
3544   return new TypeOopPtr(_base, dual_ptr(), klass(), _interfaces, klass_is_exact(), const_oop(), dual_offset(), dual_instance_id(), dual_speculative(), dual_inline_depth());
3545 }
3546 
3547 //--------------------------make_from_klass_common-----------------------------
3548 // Computes the element-type given a klass.
3549 const TypeOopPtr* TypeOopPtr::make_from_klass_common(ciKlass* klass, bool klass_change, bool try_for_exact, InterfaceHandling interface_handling) {
3550   if (klass->is_instance_klass()) {
3551     Compile* C = Compile::current();
3552     Dependencies* deps = C->dependencies();
3553     assert((deps != NULL) == (C->method() != NULL && C->method()->code_size() > 0), "sanity");
3554     // Element is an instance
3555     bool klass_is_exact = false;
3556     if (klass->is_loaded()) {
3557       // Try to set klass_is_exact.
3558       ciInstanceKlass* ik = klass->as_instance_klass();
3559       klass_is_exact = ik->is_final();
3560       if (!klass_is_exact && klass_change
3561           && deps != NULL && UseUniqueSubclasses) {
3562         ciInstanceKlass* sub = ik->unique_concrete_subklass();
3563         if (sub != NULL) {
3564           deps->assert_abstract_with_unique_concrete_subtype(ik, sub);
3565           klass = ik = sub;
3566           klass_is_exact = sub->is_final();
3567         }
3568       }
3569       if (!klass_is_exact && try_for_exact && deps != NULL &&
3570           !ik->is_interface() && !ik->has_subklass()) {
3571         // Add a dependence; if concrete subclass added we need to recompile
3572         deps->assert_leaf_type(ik);
3573         klass_is_exact = true;
3574       }
3575     }
3576     const TypePtr::InterfaceSet interfaces = TypePtr::interfaces(klass, true, true, false, interface_handling);
3577     return TypeInstPtr::make(TypePtr::BotPTR, klass, interfaces, klass_is_exact, NULL, 0);
3578   } else if (klass->is_obj_array_klass()) {
3579     // Element is an object array. Recursively call ourself.
3580     ciKlass* eklass = klass->as_obj_array_klass()->element_klass();
3581     const TypeOopPtr *etype = TypeOopPtr::make_from_klass_common(eklass, try_for_exact, false, interface_handling);
3582     bool xk = etype->klass_is_exact();
3583     const TypeAry* arr0 = TypeAry::make(etype, TypeInt::POS);













3584     // We used to pass NotNull in here, asserting that the sub-arrays
3585     // are all not-null.  This is not true in generally, as code can
3586     // slam NULLs down in the subarrays.
3587     const TypeAryPtr* arr = TypeAryPtr::make(TypePtr::BotPTR, arr0, NULL, xk, 0);
3588     return arr;
3589   } else if (klass->is_type_array_klass()) {
3590     // Element is an typeArray
3591     const Type* etype = get_const_basic_type(klass->as_type_array_klass()->element_type());
3592     const TypeAry* arr0 = TypeAry::make(etype, TypeInt::POS);

3593     // We used to pass NotNull in here, asserting that the array pointer
3594     // is not-null. That was not true in general.
3595     const TypeAryPtr* arr = TypeAryPtr::make(TypePtr::BotPTR, arr0, klass, true, 0);






3596     return arr;
3597   } else {
3598     ShouldNotReachHere();
3599     return NULL;
3600   }
3601 }
3602 
3603 //------------------------------make_from_constant-----------------------------
3604 // Make a java pointer from an oop constant
3605 const TypeOopPtr* TypeOopPtr::make_from_constant(ciObject* o, bool require_constant) {
3606   assert(!o->is_null_object(), "null object not yet handled here.");
3607 
3608   const bool make_constant = require_constant || o->should_be_constant();
3609 
3610   ciKlass* klass = o->klass();
3611   if (klass->is_instance_klass()) {
3612     // Element is an instance
3613     if (make_constant) {
3614       return TypeInstPtr::make(o);
3615     } else {
3616       return TypeInstPtr::make(TypePtr::NotNull, klass, true, NULL, 0);
3617     }
3618   } else if (klass->is_obj_array_klass()) {
3619     // Element is an object array. Recursively call ourself.
3620     const TypeOopPtr *etype =
3621       TypeOopPtr::make_from_klass_raw(klass->as_obj_array_klass()->element_klass(), trust_interfaces);
3622     const TypeAry* arr0 = TypeAry::make(etype, TypeInt::make(o->as_array()->length()));





3623     // We used to pass NotNull in here, asserting that the sub-arrays
3624     // are all not-null.  This is not true in generally, as code can
3625     // slam NULLs down in the subarrays.
3626     if (make_constant) {
3627       return TypeAryPtr::make(TypePtr::Constant, o, arr0, klass, true, 0);
3628     } else {
3629       return TypeAryPtr::make(TypePtr::NotNull, arr0, klass, true, 0);
3630     }
3631   } else if (klass->is_type_array_klass()) {
3632     // Element is an typeArray
3633     const Type* etype =
3634       (Type*)get_const_basic_type(klass->as_type_array_klass()->element_type());
3635     const TypeAry* arr0 = TypeAry::make(etype, TypeInt::make(o->as_array()->length()));
3636     // We used to pass NotNull in here, asserting that the array pointer
3637     // is not-null. That was not true in general.
3638     if (make_constant) {
3639       return TypeAryPtr::make(TypePtr::Constant, o, arr0, klass, true, 0);












3640     } else {
3641       return TypeAryPtr::make(TypePtr::NotNull, arr0, klass, true, 0);
3642     }
3643   }
3644 
3645   fatal("unhandled object type");
3646   return NULL;
3647 }
3648 
3649 //------------------------------get_con----------------------------------------
3650 intptr_t TypeOopPtr::get_con() const {
3651   assert( _ptr == Null || _ptr == Constant, "" );
3652   assert( _offset >= 0, "" );
3653 
3654   if (_offset != 0) {
3655     // After being ported to the compiler interface, the compiler no longer
3656     // directly manipulates the addresses of oops.  Rather, it only has a pointer
3657     // to a handle at compile time.  This handle is embedded in the generated
3658     // code and dereferenced at the time the nmethod is made.  Until that time,
3659     // it is not reasonable to do arithmetic with the addresses of oops (we don't
3660     // have access to the addresses!).  This does not seem to currently happen,
3661     // but this assertion here is to help prevent its occurrence.
3662     tty->print_cr("Found oop constant with non-zero offset");
3663     ShouldNotReachHere();
3664   }
3665 
3666   return (intptr_t)const_oop()->constant_encoding();
3667 }
3668 
3669 
3670 //-----------------------------filter------------------------------------------
3671 // Do not allow interface-vs.-noninterface joins to collapse to top.
3672 const Type *TypeOopPtr::filter_helper(const Type *kills, bool include_speculative) const {
3673 
3674   const Type* ft = join_helper(kills, include_speculative);

3694     return (one == two) && TypePtr::eq(t);
3695   } else {
3696     return one->equals(two) && TypePtr::eq(t);
3697   }
3698 }
3699 
3700 //------------------------------hash-------------------------------------------
3701 // Type-specific hashing function.
3702 int TypeOopPtr::hash(void) const {
3703   return
3704     java_add(java_add((jint)(const_oop() ? const_oop()->hash() : 0), (jint)_klass_is_exact),
3705              java_add((jint)_instance_id, (jint)TypePtr::hash()));
3706 }
3707 
3708 //------------------------------dump2------------------------------------------
3709 #ifndef PRODUCT
3710 void TypeOopPtr::dump2( Dict &d, uint depth, outputStream *st ) const {
3711   st->print("oopptr:%s", ptr_msg[_ptr]);
3712   if( _klass_is_exact ) st->print(":exact");
3713   if( const_oop() ) st->print(INTPTR_FORMAT, p2i(const_oop()));
3714   switch( _offset ) {
3715   case OffsetTop: st->print("+top"); break;
3716   case OffsetBot: st->print("+any"); break;
3717   case         0: break;
3718   default:        st->print("+%d",_offset); break;
3719   }
3720   if (_instance_id == InstanceTop)
3721     st->print(",iid=top");
3722   else if (_instance_id != InstanceBot)
3723     st->print(",iid=%d",_instance_id);
3724 
3725   dump_inline_depth(st);
3726   dump_speculative(st);
3727 }
3728 #endif
3729 
3730 //------------------------------singleton--------------------------------------
3731 // TRUE if Type is a singleton type, FALSE otherwise.   Singletons are simple
3732 // constants
3733 bool TypeOopPtr::singleton(void) const {
3734   // detune optimizer to not generate constant oop + constant offset as a constant!
3735   // TopPTR, Null, AnyNull, Constant are all singletons
3736   return (_offset == 0) && !below_centerline(_ptr);
3737 }
3738 
3739 //------------------------------add_offset-------------------------------------
3740 const TypePtr* TypeOopPtr::add_offset(intptr_t offset) const {
3741   return make(_ptr, xadd_offset(offset), _instance_id, add_offset_speculative(offset), _inline_depth);
3742 }
3743 
3744 const TypeOopPtr* TypeOopPtr::with_offset(intptr_t offset) const {
3745   return make(_ptr, offset, _instance_id, with_offset_speculative(offset), _inline_depth);
3746 }
3747 
3748 /**
3749  * Return same type without a speculative part
3750  */
3751 const TypeOopPtr* TypeOopPtr::remove_speculative() const {
3752   if (_speculative == NULL) {
3753     return this;
3754   }
3755   assert(_inline_depth == InlineDepthTop || _inline_depth == InlineDepthBottom, "non speculative type shouldn't have inline depth");
3756   return make(_ptr, _offset, _instance_id, NULL, _inline_depth);
3757 }
3758 
3759 /**
3760  * Return same type but drop speculative part if we know we won't use
3761  * it
3762  */
3763 const Type* TypeOopPtr::cleanup_speculative() const {
3764   // If the klass is exact and the ptr is not null then there's
3765   // nothing that the speculative type can help us with

3840 const TypeInstPtr *TypeInstPtr::MARK;
3841 const TypeInstPtr *TypeInstPtr::KLASS;
3842 
3843 // Is there a single ciKlass* that can represent that type?
3844 ciKlass* TypeInstPtr::exact_klass_helper() const {
3845   if (_interfaces.empty()) {
3846     return _klass;
3847   }
3848   if (_klass != ciEnv::current()->Object_klass()) {
3849     ciKlass* k = _klass;
3850     const TypePtr::InterfaceSet interfaces = TypePtr::interfaces(k, true, false, false, ignore_interfaces);
3851     if (_interfaces.eq(interfaces)) {
3852       return _klass;
3853     }
3854     return NULL;
3855   }
3856   return _interfaces.exact_klass();
3857 }
3858 
3859 //------------------------------TypeInstPtr-------------------------------------
3860 TypeInstPtr::TypeInstPtr(PTR ptr, ciKlass* k, const InterfaceSet& interfaces, bool xk, ciObject* o, int off,
3861                          int instance_id, const TypePtr* speculative, int inline_depth)
3862   : TypeOopPtr(InstPtr, ptr, k, interfaces, xk, o, off, instance_id, speculative, inline_depth) {

3863   assert(k == NULL || !k->is_loaded() || !k->is_interface(), "no interface here");
3864   assert(k != NULL &&
3865          (k->is_loaded() || o == NULL),
3866          "cannot have constants with non-loaded klass");


3867 };
3868 
3869 //------------------------------make-------------------------------------------
3870 const TypeInstPtr *TypeInstPtr::make(PTR ptr,
3871                                      ciKlass* k,
3872                                      const InterfaceSet& interfaces,
3873                                      bool xk,
3874                                      ciObject* o,
3875                                      int offset,

3876                                      int instance_id,
3877                                      const TypePtr* speculative,
3878                                      int inline_depth) {
3879   assert( !k->is_loaded() || k->is_instance_klass(), "Must be for instance");
3880   // Either const_oop() is NULL or else ptr is Constant
3881   assert( (!o && ptr != Constant) || (o && ptr == Constant),
3882           "constant pointers must have a value supplied" );
3883   // Ptr is never Null
3884   assert( ptr != Null, "NULL pointers are not typed" );
3885 
3886   assert(instance_id <= 0 || xk, "instances are always exactly typed");
3887   if (ptr == Constant) {
3888     // Note:  This case includes meta-object constants, such as methods.
3889     xk = true;
3890   } else if (k->is_loaded()) {
3891     ciInstanceKlass* ik = k->as_instance_klass();
3892     if (!xk && ik->is_final())     xk = true;   // no inexact final klass
3893     assert(!ik->is_interface(), "no interface here");
3894     if (xk && ik->is_interface())  xk = false;  // no exact interface
3895   }
3896 



3897   // Now hash this baby
3898   TypeInstPtr *result =
3899     (TypeInstPtr*)(new TypeInstPtr(ptr, k, interfaces, xk, o ,offset, instance_id, speculative, inline_depth))->hashcons();
3900 
3901   return result;
3902 }
3903 
3904 TypePtr::InterfaceSet TypePtr::interfaces(ciKlass*& k, bool klass, bool interface, bool array, InterfaceHandling interface_handling) {
3905   if (k->is_instance_klass()) {
3906     if (k->is_loaded()) {
3907       if (k->is_interface() && interface_handling == ignore_interfaces) {
3908         assert(interface, "no interface expected");
3909         k = ciEnv::current()->Object_klass();
3910         InterfaceSet interfaces;
3911         return interfaces;
3912       }
3913       GrowableArray<ciInstanceKlass *> *k_interfaces = k->as_instance_klass()->transitive_interfaces();
3914       InterfaceSet interfaces(k_interfaces);
3915       if (k->is_interface()) {
3916         assert(interface, "no interface expected");
3917         k = ciEnv::current()->Object_klass();
3918       } else {
3919         assert(klass, "no instance klass expected");

3945   switch (bt) {
3946     case T_BOOLEAN:  return TypeInt::make(constant.as_boolean());
3947     case T_INT:      return TypeInt::make(constant.as_int());
3948     case T_CHAR:     return TypeInt::make(constant.as_char());
3949     case T_BYTE:     return TypeInt::make(constant.as_byte());
3950     case T_SHORT:    return TypeInt::make(constant.as_short());
3951     case T_FLOAT:    return TypeF::make(constant.as_float());
3952     case T_DOUBLE:   return TypeD::make(constant.as_double());
3953     case T_LONG:     return TypeLong::make(constant.as_long());
3954     default:         break;
3955   }
3956   fatal("Invalid boxed value type '%s'", type2name(bt));
3957   return NULL;
3958 }
3959 
3960 //------------------------------cast_to_ptr_type-------------------------------
3961 const TypeInstPtr* TypeInstPtr::cast_to_ptr_type(PTR ptr) const {
3962   if( ptr == _ptr ) return this;
3963   // Reconstruct _sig info here since not a problem with later lazy
3964   // construction, _sig will show up on demand.
3965   return make(ptr, klass(), _interfaces, klass_is_exact(), ptr == Constant ? const_oop() : NULL, _offset, _instance_id, _speculative, _inline_depth);
3966 }
3967 
3968 
3969 //-----------------------------cast_to_exactness-------------------------------
3970 const TypeInstPtr* TypeInstPtr::cast_to_exactness(bool klass_is_exact) const {
3971   if( klass_is_exact == _klass_is_exact ) return this;
3972   if (!_klass->is_loaded())  return this;
3973   ciInstanceKlass* ik = _klass->as_instance_klass();
3974   if( (ik->is_final() || _const_oop) )  return this;  // cannot clear xk
3975   assert(!ik->is_interface(), "no interface here");
3976   return make(ptr(), klass(), _interfaces, klass_is_exact, const_oop(), _offset, _instance_id, _speculative, _inline_depth);
3977 }
3978 
3979 //-----------------------------cast_to_instance_id----------------------------
3980 const TypeInstPtr* TypeInstPtr::cast_to_instance_id(int instance_id) const {
3981   if( instance_id == _instance_id ) return this;
3982   return make(_ptr, klass(),  _interfaces, _klass_is_exact, const_oop(), _offset, instance_id, _speculative, _inline_depth);
3983 }
3984 
3985 //------------------------------xmeet_unloaded---------------------------------
3986 // Compute the MEET of two InstPtrs when at least one is unloaded.
3987 // Assume classes are different since called after check for same name/class-loader
3988 const TypeInstPtr *TypeInstPtr::xmeet_unloaded(const TypeInstPtr *tinst, const InterfaceSet& interfaces) const {
3989   int off = meet_offset(tinst->offset());
3990   PTR ptr = meet_ptr(tinst->ptr());
3991   int instance_id = meet_instance_id(tinst->instance_id());
3992   const TypePtr* speculative = xmeet_speculative(tinst);
3993   int depth = meet_inline_depth(tinst->inline_depth());
3994 
3995   const TypeInstPtr *loaded    = is_loaded() ? this  : tinst;
3996   const TypeInstPtr *unloaded  = is_loaded() ? tinst : this;
3997   if( loaded->klass()->equals(ciEnv::current()->Object_klass()) ) {
3998     //
3999     // Meet unloaded class with java/lang/Object
4000     //
4001     // Meet
4002     //          |                     Unloaded Class
4003     //  Object  |   TOP    |   AnyNull | Constant |   NotNull |  BOTTOM   |
4004     //  ===================================================================
4005     //   TOP    | ..........................Unloaded......................|
4006     //  AnyNull |  U-AN    |................Unloaded......................|
4007     // Constant | ... O-NN .................................. |   O-BOT   |
4008     //  NotNull | ... O-NN .................................. |   O-BOT   |
4009     //  BOTTOM  | ........................Object-BOTTOM ..................|
4010     //
4011     assert(loaded->ptr() != TypePtr::Null, "insanity check");
4012     //
4013     if (loaded->ptr() == TypePtr::TopPTR)        { return unloaded; }
4014     else if (loaded->ptr() == TypePtr::AnyNull)  { return make(ptr, unloaded->klass(), interfaces, false, NULL, off, instance_id, speculative, depth); }
4015     else if (loaded->ptr() == TypePtr::BotPTR)   { return TypeInstPtr::BOTTOM; }
4016     else if (loaded->ptr() == TypePtr::Constant || loaded->ptr() == TypePtr::NotNull) {
4017       if (unloaded->ptr() == TypePtr::BotPTR)    { return TypeInstPtr::BOTTOM;  }
4018       else                                       { return TypeInstPtr::NOTNULL; }
4019     }
4020     else if (unloaded->ptr() == TypePtr::TopPTR) { return unloaded; }
4021 
4022     return unloaded->cast_to_ptr_type(TypePtr::AnyNull)->is_instptr();
4023   }
4024 
4025   // Both are unloaded, not the same class, not Object
4026   // Or meet unloaded with a different loaded class, not java/lang/Object
4027   if (ptr != TypePtr::BotPTR) {
4028     return TypeInstPtr::NOTNULL;
4029   }
4030   return TypeInstPtr::BOTTOM;
4031 }
4032 
4033 
4034 //------------------------------meet-------------------------------------------

4055   case Top:
4056     return this;
4057 
4058   default:                      // All else is a mistake
4059     typerr(t);
4060 
4061   case MetadataPtr:
4062   case KlassPtr:
4063   case InstKlassPtr:
4064   case AryKlassPtr:
4065   case RawPtr: return TypePtr::BOTTOM;
4066 
4067   case AryPtr: {                // All arrays inherit from Object class
4068     // Call in reverse direction to avoid duplication
4069     return t->is_aryptr()->xmeet_helper(this);
4070   }
4071 
4072   case OopPtr: {                // Meeting to OopPtrs
4073     // Found a OopPtr type vs self-InstPtr type
4074     const TypeOopPtr *tp = t->is_oopptr();
4075     int offset = meet_offset(tp->offset());
4076     PTR ptr = meet_ptr(tp->ptr());
4077     switch (tp->ptr()) {
4078     case TopPTR:
4079     case AnyNull: {
4080       int instance_id = meet_instance_id(InstanceTop);
4081       const TypePtr* speculative = xmeet_speculative(tp);
4082       int depth = meet_inline_depth(tp->inline_depth());
4083       return make(ptr, klass(), _interfaces, klass_is_exact(),
4084                   (ptr == Constant ? const_oop() : NULL), offset, instance_id, speculative, depth);
4085     }
4086     case NotNull:
4087     case BotPTR: {
4088       int instance_id = meet_instance_id(tp->instance_id());
4089       const TypePtr* speculative = xmeet_speculative(tp);
4090       int depth = meet_inline_depth(tp->inline_depth());
4091       return TypeOopPtr::make(ptr, offset, instance_id, speculative, depth);
4092     }
4093     default: typerr(t);
4094     }
4095   }
4096 
4097   case AnyPtr: {                // Meeting to AnyPtrs
4098     // Found an AnyPtr type vs self-InstPtr type
4099     const TypePtr *tp = t->is_ptr();
4100     int offset = meet_offset(tp->offset());
4101     PTR ptr = meet_ptr(tp->ptr());
4102     int instance_id = meet_instance_id(InstanceTop);
4103     const TypePtr* speculative = xmeet_speculative(tp);
4104     int depth = meet_inline_depth(tp->inline_depth());
4105     switch (tp->ptr()) {
4106     case Null:
4107       if( ptr == Null ) return TypePtr::make(AnyPtr, ptr, offset, speculative, depth);
4108       // else fall through to AnyNull
4109     case TopPTR:
4110     case AnyNull: {
4111       return make(ptr, klass(), _interfaces, klass_is_exact(),
4112                   (ptr == Constant ? const_oop() : NULL), offset, instance_id, speculative, depth);
4113     }
4114     case NotNull:
4115     case BotPTR:
4116       return TypePtr::make(AnyPtr, ptr, offset, speculative,depth);
4117     default: typerr(t);
4118     }
4119   }
4120 
4121   /*
4122                  A-top         }
4123                /   |   \       }  Tops
4124            B-top A-any C-top   }
4125               | /  |  \ |      }  Any-nulls
4126            B-any   |   C-any   }
4127               |    |    |
4128            B-con A-con C-con   } constants; not comparable across classes
4129               |    |    |
4130            B-not   |   C-not   }
4131               | \  |  / |      }  not-nulls
4132            B-bot A-not C-bot   }
4133                \   |   /       }  Bottoms
4134                  A-bot         }
4135   */
4136 
4137   case InstPtr: {                // Meeting 2 Oops?
4138     // Found an InstPtr sub-type vs self-InstPtr type
4139     const TypeInstPtr *tinst = t->is_instptr();
4140     int off = meet_offset(tinst->offset());
4141     PTR ptr = meet_ptr(tinst->ptr());
4142     int instance_id = meet_instance_id(tinst->instance_id());
4143     const TypePtr* speculative = xmeet_speculative(tinst);
4144     int depth = meet_inline_depth(tinst->inline_depth());
4145     InterfaceSet interfaces = meet_interfaces(tinst);
4146 
4147     ciKlass* tinst_klass = tinst->klass();
4148     ciKlass* this_klass  = klass();
4149 
4150     ciKlass* res_klass = NULL;
4151     bool res_xk = false;

4152     const Type* res;
4153     MeetResult kind = meet_instptr(ptr, interfaces, this, tinst, res_klass, res_xk);
4154 
4155     if (kind == UNLOADED) {
4156       // One of these classes has not been loaded
4157       const TypeInstPtr* unloaded_meet = xmeet_unloaded(tinst, interfaces);
4158 #ifndef PRODUCT
4159       if (PrintOpto && Verbose) {
4160         tty->print("meet of unloaded classes resulted in: ");
4161         unloaded_meet->dump();
4162         tty->cr();
4163         tty->print("  this == ");
4164         dump();
4165         tty->cr();
4166         tty->print(" tinst == ");
4167         tinst->dump();
4168         tty->cr();
4169       }
4170 #endif
4171       res = unloaded_meet;
4172     } else {
4173       if (kind == NOT_SUBTYPE && instance_id > 0) {
4174         instance_id = InstanceBot;
4175       } else if (kind == LCA) {
4176         instance_id = InstanceBot;
4177       }
4178       ciObject* o = NULL;             // Assume not constant when done
4179       ciObject* this_oop = const_oop();
4180       ciObject* tinst_oop = tinst->const_oop();
4181       if (ptr == Constant) {
4182         if (this_oop != NULL && tinst_oop != NULL &&
4183             this_oop->equals(tinst_oop))
4184           o = this_oop;
4185         else if (above_centerline(_ptr)) {
4186           assert(!tinst_klass->is_interface(), "");
4187           o = tinst_oop;
4188         } else if (above_centerline(tinst->_ptr)) {
4189           assert(!this_klass->is_interface(), "");
4190           o = this_oop;
4191         } else
4192           ptr = NotNull;
4193       }
4194       res = make(ptr, res_klass, interfaces, res_xk, o, off, instance_id, speculative, depth);
4195     }
4196 
4197     return res;
4198 
4199   } // End of case InstPtr
4200 
4201   } // End of switch
4202   return this;                  // Return the double constant
4203 }
4204 
4205 template<class T> TypePtr::MeetResult TypePtr::meet_instptr(PTR& ptr, InterfaceSet& interfaces, const T* this_type, const T* other_type,
4206                       ciKlass*& res_klass, bool& res_xk) {
4207   ciKlass* this_klass = this_type->klass();
4208   ciKlass* other_klass = other_type->klass();




4209   bool this_xk = this_type->klass_is_exact();
4210   bool other_xk = other_type->klass_is_exact();
4211   PTR this_ptr = this_type->ptr();
4212   PTR other_ptr = other_type->ptr();
4213   InterfaceSet this_interfaces = this_type->interfaces();
4214   InterfaceSet other_interfaces = other_type->interfaces();
4215   // Check for easy case; klasses are equal (and perhaps not loaded!)
4216   // If we have constants, then we created oops so classes are loaded
4217   // and we can handle the constants further down.  This case handles
4218   // both-not-loaded or both-loaded classes
4219   if (ptr != Constant && this_klass->equals(other_klass) && this_xk == other_xk) {
4220     res_klass = this_klass;
4221     res_xk = this_xk;

4222     return QUICK;
4223   }
4224 
4225   // Classes require inspection in the Java klass hierarchy.  Must be loaded.
4226   if (!other_klass->is_loaded() || !this_klass->is_loaded()) {
4227     return UNLOADED;
4228   }
4229 
4230   // !!! Here's how the symmetry requirement breaks down into invariants:
4231   // If we split one up & one down AND they subtype, take the down man.
4232   // If we split one up & one down AND they do NOT subtype, "fall hard".
4233   // If both are up and they subtype, take the subtype class.
4234   // If both are up and they do NOT subtype, "fall hard".
4235   // If both are down and they subtype, take the supertype class.
4236   // If both are down and they do NOT subtype, "fall hard".
4237   // Constants treated as down.
4238 
4239   // Now, reorder the above list; observe that both-down+subtype is also
4240   // "fall hard"; "fall hard" becomes the default case:
4241   // If we split one up & one down AND they subtype, take the down man.
4242   // If both are up and they subtype, take the subtype class.
4243 
4244   // If both are down and they subtype, "fall hard".
4245   // If both are down and they do NOT subtype, "fall hard".
4246   // If both are up and they do NOT subtype, "fall hard".
4247   // If we split one up & one down AND they do NOT subtype, "fall hard".
4248 
4249   // If a proper subtype is exact, and we return it, we return it exactly.
4250   // If a proper supertype is exact, there can be no subtyping relationship!
4251   // If both types are equal to the subtype, exactness is and-ed below the
4252   // centerline and or-ed above it.  (N.B. Constants are always exact.)
4253 
4254   // Check for subtyping:
4255   const T* subtype = NULL;
4256   bool subtype_exact = false;

4257   InterfaceSet subtype_interfaces;
4258 
4259   if (this_type->is_same_java_type_as(other_type)) {
4260     subtype = this_type;
4261     subtype_exact = below_centerline(ptr) ? (this_xk && other_xk) : (this_xk || other_xk);
4262   } else if (!other_xk && this_type->is_meet_subtype_of(other_type)) {

4263     subtype = this_type;     // Pick subtyping class
4264     subtype_exact = this_xk;
4265   } else if(!this_xk && other_type->is_meet_subtype_of(this_type)) {

4266     subtype = other_type;    // Pick subtyping class
4267     subtype_exact = other_xk;

4268   }
4269 
4270   if (subtype) {
4271     if (above_centerline(ptr)) { // both are up?
4272       this_type = other_type = subtype;
4273       this_xk = other_xk = subtype_exact;

4274     } else if (above_centerline(this_ptr) && !above_centerline(other_ptr)) {
4275       this_type = other_type; // tinst is down; keep down man
4276       this_xk = other_xk;

4277     } else if (above_centerline(other_ptr) && !above_centerline(this_ptr)) {
4278       other_type = this_type; // this is down; keep down man
4279       other_xk = this_xk;

4280     } else {
4281       this_xk = subtype_exact;  // either they are equal, or we'll do an LCA

4282     }
4283   }
4284 
4285   // Check for classes now being equal
4286   if (this_type->is_same_java_type_as(other_type)) {
4287     // If the klasses are equal, the constants may still differ.  Fall to
4288     // NotNull if they do (neither constant is NULL; that is a special case
4289     // handled elsewhere).
4290     res_klass = this_type->klass();
4291     res_xk = this_xk;

4292     return SUBTYPE;
4293   } // Else classes are not equal
4294 
4295   // Since klasses are different, we require a LCA in the Java
4296   // class hierarchy - which means we have to fall to at least NotNull.
4297   if (ptr == TopPTR || ptr == AnyNull || ptr == Constant) {
4298     ptr = NotNull;
4299   }
4300 
4301   interfaces = this_interfaces.intersection_with(other_interfaces);
4302 
4303   // Now we find the LCA of Java classes
4304   ciKlass* k = this_klass->least_common_ancestor(other_klass);
4305 
4306   res_klass = k;
4307   res_xk = false;

4308 
4309   return LCA;
4310 }
4311 
4312 //------------------------java_mirror_type--------------------------------------
4313 ciType* TypeInstPtr::java_mirror_type() const {
4314   // must be a singleton type
4315   if( const_oop() == NULL )  return NULL;
4316 
4317   // must be of type java.lang.Class
4318   if( klass() != ciEnv::current()->Class_klass() )  return NULL;
4319 
4320   return const_oop()->as_instance()->java_mirror_type();
4321 }
4322 
4323 
4324 //------------------------------xdual------------------------------------------
4325 // Dual: do NOT dual on klasses.  This means I do NOT understand the Java
4326 // inheritance mechanism.
4327 const Type *TypeInstPtr::xdual() const {
4328   return new TypeInstPtr(dual_ptr(), klass(), _interfaces, klass_is_exact(), const_oop(), dual_offset(), dual_instance_id(), dual_speculative(), dual_inline_depth());
4329 }
4330 
4331 //------------------------------eq---------------------------------------------
4332 // Structural equality check for Type representations
4333 bool TypeInstPtr::eq( const Type *t ) const {
4334   const TypeInstPtr *p = t->is_instptr();
4335   return
4336     klass()->equals(p->klass()) &&

4337     _interfaces.eq(p->_interfaces) &&
4338     TypeOopPtr::eq(p);          // Check sub-type stuff
4339 }
4340 
4341 //------------------------------hash-------------------------------------------
4342 // Type-specific hashing function.
4343 int TypeInstPtr::hash(void) const {
4344   int hash = java_add(java_add((jint)klass()->hash(), (jint)TypeOopPtr::hash()), _interfaces.hash());
4345   return hash;
4346 }
4347 
4348 bool TypeInstPtr::is_java_subtype_of_helper(const TypeOopPtr* other, bool this_exact, bool other_exact) const {
4349   return TypePtr::is_java_subtype_of_helper_for_instance(this, other, this_exact, other_exact);
4350 }
4351 
4352 
4353 bool TypeInstPtr::is_same_java_type_as_helper(const TypeOopPtr* other) const {
4354   return TypePtr::is_same_java_type_as_helper_for_instance(this, other);
4355 }
4356 
4357 bool TypeInstPtr::maybe_java_subtype_of_helper(const TypeOopPtr* other, bool this_exact, bool other_exact) const {
4358   return TypePtr::maybe_java_subtype_of_helper_for_instance(this, other, this_exact, other_exact);
4359 }
4360 
4361 
4362 //------------------------------dump2------------------------------------------
4363 // Dump oop Type
4364 #ifndef PRODUCT

4379       // suppress newlines from it so -XX:+Verbose -XX:+PrintIdeal dumps one-liner for each node.
4380       char* buf = ss.as_string(/* c_heap= */false);
4381       StringUtils::replace_no_expand(buf, "\n", "");
4382       st->print_raw(buf);
4383     }
4384   case BotPTR:
4385     if (!WizardMode && !Verbose) {
4386       if( _klass_is_exact ) st->print(":exact");
4387       break;
4388     }
4389   case TopPTR:
4390   case AnyNull:
4391   case NotNull:
4392     st->print(":%s", ptr_msg[_ptr]);
4393     if( _klass_is_exact ) st->print(":exact");
4394     break;
4395   default:
4396     break;
4397   }
4398 
4399   if( _offset ) {               // Dump offset, if any
4400     if( _offset == OffsetBot )      st->print("+any");
4401     else if( _offset == OffsetTop ) st->print("+unknown");
4402     else st->print("+%d", _offset);
4403   }
4404 
4405   st->print(" *");





4406   if (_instance_id == InstanceTop)
4407     st->print(",iid=top");
4408   else if (_instance_id != InstanceBot)
4409     st->print(",iid=%d",_instance_id);
4410 
4411   dump_inline_depth(st);
4412   dump_speculative(st);
4413 }
4414 #endif
4415 
4416 //------------------------------add_offset-------------------------------------
4417 const TypePtr* TypeInstPtr::add_offset(intptr_t offset) const {
4418   return make(_ptr, klass(), _interfaces, klass_is_exact(), const_oop(), xadd_offset(offset),
4419               _instance_id, add_offset_speculative(offset), _inline_depth);
4420 }
4421 
4422 const TypeInstPtr* TypeInstPtr::with_offset(intptr_t offset) const {
4423   return make(_ptr, klass(), _interfaces, klass_is_exact(), const_oop(), offset,
4424               _instance_id, with_offset_speculative(offset), _inline_depth);
4425 }
4426 
4427 const TypeInstPtr* TypeInstPtr::remove_speculative() const {
4428   if (_speculative == NULL) {
4429     return this;
4430   }
4431   assert(_inline_depth == InlineDepthTop || _inline_depth == InlineDepthBottom, "non speculative type shouldn't have inline depth");
4432   return make(_ptr, klass(), _interfaces, klass_is_exact(), const_oop(), _offset,
4433               _instance_id, NULL, _inline_depth);
4434 }
4435 
4436 const TypePtr* TypeInstPtr::with_inline_depth(int depth) const {
4437   if (!UseInlineDepthForSpeculativeTypes) {
4438     return this;
4439   }
4440   return make(_ptr, klass(), _interfaces, klass_is_exact(), const_oop(), _offset, _instance_id, _speculative, depth);
4441 }
4442 
4443 const TypePtr* TypeInstPtr::with_instance_id(int instance_id) const {
4444   assert(is_known_instance(), "should be known");
4445   return make(_ptr, klass(), _interfaces, klass_is_exact(), const_oop(), _offset, instance_id, _speculative, _inline_depth);




4446 }
4447 
4448 const TypeKlassPtr* TypeInstPtr::as_klass_type(bool try_for_exact) const {
4449   bool xk = klass_is_exact();
4450   ciInstanceKlass* ik = klass()->as_instance_klass();
4451   if (try_for_exact && !xk && !ik->has_subklass() && !ik->is_final()) {
4452     ciKlass* k = ik;
4453     TypePtr::InterfaceSet interfaces = TypePtr::interfaces(k, true, false, false, ignore_interfaces);
4454     assert(k == ik, "");
4455     if (interfaces.eq(_interfaces)) {
4456       Compile *C = Compile::current();
4457       Dependencies* deps = C->dependencies();
4458       deps->assert_leaf_type(ik);
4459       xk = true;
4460     }
4461   }
4462   return TypeInstKlassPtr::make(xk ? TypePtr::Constant : TypePtr::NotNull, klass(), _interfaces, 0);
4463 }
4464 
4465 template <class T1, class T2> bool TypePtr::is_meet_subtype_of_helper_for_instance(const T1* this_one, const T2* other, bool this_xk, bool other_xk) {
4466   static_assert(std::is_base_of<T2, T1>::value, "");
4467 
4468   if (!this_one->is_instance_type(other)) {
4469     return false;
4470   }
4471 
4472   if (other->klass() == ciEnv::current()->Object_klass() && other->_interfaces.empty()) {
4473     return true;
4474   }
4475 
4476   return this_one->klass()->is_subtype_of(other->klass()) &&
4477          (!this_xk || this_one->_interfaces.contains(other->_interfaces));
4478 }
4479 
4480 
4481 bool TypeInstPtr::is_meet_subtype_of_helper(const TypeOopPtr *other, bool this_xk, bool other_xk) const {
4482   return TypePtr::is_meet_subtype_of_helper_for_instance(this, other, this_xk, other_xk);

4487   if (other->klass() == ciEnv::current()->Object_klass() && other->_interfaces.empty()) {
4488     return true;
4489   }
4490 
4491   if (this_one->is_instance_type(other)) {
4492     return other->klass() == ciEnv::current()->Object_klass() && this_one->_interfaces.contains(other->_interfaces);
4493   }
4494 
4495   int dummy;
4496   bool this_top_or_bottom = (this_one->base_element_type(dummy) == Type::TOP || this_one->base_element_type(dummy) == Type::BOTTOM);
4497   if (this_top_or_bottom) {
4498     return false;
4499   }
4500 
4501   const T1* other_ary = this_one->is_array_type(other);
4502   const TypePtr* other_elem = other_ary->elem()->make_ptr();
4503   const TypePtr* this_elem = this_one->elem()->make_ptr();
4504   if (other_elem != NULL && this_elem != NULL) {
4505     return this_one->is_reference_type(this_elem)->is_meet_subtype_of_helper(this_one->is_reference_type(other_elem), this_xk, other_xk);
4506   }
4507 
4508   if (other_elem == NULL && this_elem == NULL) {
4509     return this_one->_klass->is_subtype_of(other->_klass);
4510   }
4511 
4512   return false;
4513 }
4514 
4515 bool TypeAryPtr::is_meet_subtype_of_helper(const TypeOopPtr *other, bool this_xk, bool other_xk) const {
4516   return TypePtr::is_meet_subtype_of_helper_for_array(this, other, this_xk, other_xk);
4517 }
4518 
4519 bool TypeInstKlassPtr::is_meet_subtype_of_helper(const TypeKlassPtr *other, bool this_xk, bool other_xk) const {
4520   return TypePtr::is_meet_subtype_of_helper_for_instance(this, other, this_xk, other_xk);
4521 }
4522 
4523 bool TypeAryKlassPtr::is_meet_subtype_of_helper(const TypeKlassPtr *other, bool this_xk, bool other_xk) const {
4524   return TypePtr::is_meet_subtype_of_helper_for_array(this, other, this_xk, other_xk);
4525 }
4526 
4527 //=============================================================================
4528 // Convenience common pre-built types.
4529 const TypeAryPtr *TypeAryPtr::RANGE;
4530 const TypeAryPtr *TypeAryPtr::OOPS;
4531 const TypeAryPtr *TypeAryPtr::NARROWOOPS;
4532 const TypeAryPtr *TypeAryPtr::BYTES;
4533 const TypeAryPtr *TypeAryPtr::SHORTS;
4534 const TypeAryPtr *TypeAryPtr::CHARS;
4535 const TypeAryPtr *TypeAryPtr::INTS;
4536 const TypeAryPtr *TypeAryPtr::LONGS;
4537 const TypeAryPtr *TypeAryPtr::FLOATS;
4538 const TypeAryPtr *TypeAryPtr::DOUBLES;

4539 
4540 //------------------------------make-------------------------------------------
4541 const TypeAryPtr *TypeAryPtr::make(PTR ptr, const TypeAry *ary, ciKlass* k, bool xk, int offset,
4542                                    int instance_id, const TypePtr* speculative, int inline_depth) {
4543   assert(!(k == NULL && ary->_elem->isa_int()),
4544          "integral arrays must be pre-equipped with a class");
4545   if (!xk)  xk = ary->ary_must_be_exact();
4546   assert(instance_id <= 0 || xk, "instances are always exactly typed");
4547   if (k != NULL && k->is_loaded() && k->is_obj_array_klass() &&
4548       k->as_obj_array_klass()->base_element_klass()->is_interface()) {
4549     k = NULL;
4550   }
4551   return (TypeAryPtr*)(new TypeAryPtr(ptr, NULL, ary, k, xk, offset, instance_id, false, speculative, inline_depth))->hashcons();



4552 }
4553 
4554 //------------------------------make-------------------------------------------
4555 const TypeAryPtr *TypeAryPtr::make(PTR ptr, ciObject* o, const TypeAry *ary, ciKlass* k, bool xk, int offset,
4556                                    int instance_id, const TypePtr* speculative, int inline_depth,
4557                                    bool is_autobox_cache) {
4558   assert(!(k == NULL && ary->_elem->isa_int()),
4559          "integral arrays must be pre-equipped with a class");
4560   assert( (ptr==Constant && o) || (ptr!=Constant && !o), "" );
4561   if (!xk)  xk = (o != NULL) || ary->ary_must_be_exact();
4562   assert(instance_id <= 0 || xk, "instances are always exactly typed");
4563   if (k != NULL && k->is_loaded() && k->is_obj_array_klass() &&
4564       k->as_obj_array_klass()->base_element_klass()->is_interface()) {
4565     k = NULL;
4566   }
4567   return (TypeAryPtr*)(new TypeAryPtr(ptr, o, ary, k, xk, offset, instance_id, is_autobox_cache, speculative, inline_depth))->hashcons();



4568 }
4569 
4570 //------------------------------cast_to_ptr_type-------------------------------
4571 const TypeAryPtr* TypeAryPtr::cast_to_ptr_type(PTR ptr) const {
4572   if( ptr == _ptr ) return this;
4573   return make(ptr, ptr == Constant ? const_oop() : NULL, _ary, klass(), klass_is_exact(), _offset, _instance_id, _speculative, _inline_depth);
4574 }
4575 
4576 
4577 //-----------------------------cast_to_exactness-------------------------------
4578 const TypeAryPtr* TypeAryPtr::cast_to_exactness(bool klass_is_exact) const {
4579   if( klass_is_exact == _klass_is_exact ) return this;
4580   if (_ary->ary_must_be_exact())  return this;  // cannot clear xk
4581   return make(ptr(), const_oop(), _ary, klass(), klass_is_exact, _offset, _instance_id, _speculative, _inline_depth);
4582 }
4583 
4584 //-----------------------------cast_to_instance_id----------------------------
4585 const TypeAryPtr* TypeAryPtr::cast_to_instance_id(int instance_id) const {
4586   if( instance_id == _instance_id ) return this;
4587   return make(_ptr, const_oop(), _ary, klass(), _klass_is_exact, _offset, instance_id, _speculative, _inline_depth);
4588 }
4589 
4590 
4591 //-----------------------------max_array_length-------------------------------
4592 // A wrapper around arrayOopDesc::max_array_length(etype) with some input normalization.
4593 jint TypeAryPtr::max_array_length(BasicType etype) {
4594   if (!is_java_primitive(etype) && !::is_reference_type(etype)) {
4595     if (etype == T_NARROWOOP) {
4596       etype = T_OBJECT;
4597     } else if (etype == T_ILLEGAL) { // bottom[]
4598       etype = T_BYTE; // will produce conservatively high value
4599     } else {
4600       fatal("not an element type: %s", type2name(etype));
4601     }
4602   }
4603   return arrayOopDesc::max_array_length(etype);
4604 }
4605 
4606 //-----------------------------narrow_size_type-------------------------------
4607 // Narrow the given size type to the index range for the given array base type.

4623   if (hi > max_hi) {
4624     hi = max_hi;
4625     if (size->is_con()) {
4626       lo = hi;
4627     }
4628     chg = true;
4629   }
4630   // Negative length arrays will produce weird intermediate dead fast-path code
4631   if (lo > hi)
4632     return TypeInt::ZERO;
4633   if (!chg)
4634     return size;
4635   return TypeInt::make(lo, hi, Type::WidenMin);
4636 }
4637 
4638 //-------------------------------cast_to_size----------------------------------
4639 const TypeAryPtr* TypeAryPtr::cast_to_size(const TypeInt* new_size) const {
4640   assert(new_size != NULL, "");
4641   new_size = narrow_size_type(new_size);
4642   if (new_size == size())  return this;
4643   const TypeAry* new_ary = TypeAry::make(elem(), new_size, is_stable());
4644   return make(ptr(), const_oop(), new_ary, klass(), klass_is_exact(), _offset, _instance_id, _speculative, _inline_depth);




















































4645 }
4646 
4647 //------------------------------cast_to_stable---------------------------------
4648 const TypeAryPtr* TypeAryPtr::cast_to_stable(bool stable, int stable_dimension) const {
4649   if (stable_dimension <= 0 || (stable_dimension == 1 && stable == this->is_stable()))
4650     return this;
4651 
4652   const Type* elem = this->elem();
4653   const TypePtr* elem_ptr = elem->make_ptr();
4654 
4655   if (stable_dimension > 1 && elem_ptr != NULL && elem_ptr->isa_aryptr()) {
4656     // If this is widened from a narrow oop, TypeAry::make will re-narrow it.
4657     elem = elem_ptr = elem_ptr->is_aryptr()->cast_to_stable(stable, stable_dimension - 1);
4658   }
4659 
4660   const TypeAry* new_ary = TypeAry::make(elem, size(), stable);
4661 
4662   return make(ptr(), const_oop(), new_ary, klass(), klass_is_exact(), _offset, _instance_id, _speculative, _inline_depth);
4663 }
4664 
4665 //-----------------------------stable_dimension--------------------------------
4666 int TypeAryPtr::stable_dimension() const {
4667   if (!is_stable())  return 0;
4668   int dim = 1;
4669   const TypePtr* elem_ptr = elem()->make_ptr();
4670   if (elem_ptr != NULL && elem_ptr->isa_aryptr())
4671     dim += elem_ptr->is_aryptr()->stable_dimension();
4672   return dim;
4673 }
4674 
4675 //----------------------cast_to_autobox_cache-----------------------------------
4676 const TypeAryPtr* TypeAryPtr::cast_to_autobox_cache() const {
4677   if (is_autobox_cache())  return this;
4678   const TypeOopPtr* etype = elem()->make_oopptr();
4679   if (etype == NULL)  return this;
4680   // The pointers in the autobox arrays are always non-null.
4681   etype = etype->cast_to_ptr_type(TypePtr::NotNull)->is_oopptr();
4682   const TypeAry* new_ary = TypeAry::make(etype, size(), is_stable());
4683   return make(ptr(), const_oop(), new_ary, klass(), klass_is_exact(), _offset, _instance_id, _speculative, _inline_depth, /*is_autobox_cache=*/true);
4684 }
4685 
4686 //------------------------------eq---------------------------------------------
4687 // Structural equality check for Type representations
4688 bool TypeAryPtr::eq( const Type *t ) const {
4689   const TypeAryPtr *p = t->is_aryptr();
4690   return
4691     _ary == p->_ary &&  // Check array
4692     TypeOopPtr::eq(p);  // Check sub-parts

4693 }
4694 
4695 //------------------------------hash-------------------------------------------
4696 // Type-specific hashing function.
4697 int TypeAryPtr::hash(void) const {
4698   return (intptr_t)_ary + TypeOopPtr::hash();
4699 }
4700 
4701 bool TypeAryPtr::is_java_subtype_of_helper(const TypeOopPtr* other, bool this_exact, bool other_exact) const {
4702   return TypePtr::is_java_subtype_of_helper_for_array(this, other, this_exact, other_exact);
4703 }
4704 
4705 bool TypeAryPtr::is_same_java_type_as_helper(const TypeOopPtr* other) const {
4706   return TypePtr::is_same_java_type_as_helper_for_array(this, other);
4707 }
4708 
4709 bool TypeAryPtr::maybe_java_subtype_of_helper(const TypeOopPtr* other, bool this_exact, bool other_exact) const {
4710   return TypePtr::maybe_java_subtype_of_helper_for_array(this, other, this_exact, other_exact);
4711 }
4712 //------------------------------meet-------------------------------------------
4713 // Compute the MEET of two types.  It returns a new Type object.
4714 const Type *TypeAryPtr::xmeet_helper(const Type *t) const {
4715   // Perform a fast test for common case; meeting the same types together.
4716   if( this == t ) return this;  // Meeting same type-rep?
4717   // Current "this->_base" is Pointer
4718   switch (t->base()) {          // switch on original type

4722   case Long:
4723   case FloatTop:
4724   case FloatCon:
4725   case FloatBot:
4726   case DoubleTop:
4727   case DoubleCon:
4728   case DoubleBot:
4729   case NarrowOop:
4730   case NarrowKlass:
4731   case Bottom:                  // Ye Olde Default
4732     return Type::BOTTOM;
4733   case Top:
4734     return this;
4735 
4736   default:                      // All else is a mistake
4737     typerr(t);
4738 
4739   case OopPtr: {                // Meeting to OopPtrs
4740     // Found a OopPtr type vs self-AryPtr type
4741     const TypeOopPtr *tp = t->is_oopptr();
4742     int offset = meet_offset(tp->offset());
4743     PTR ptr = meet_ptr(tp->ptr());
4744     int depth = meet_inline_depth(tp->inline_depth());
4745     const TypePtr* speculative = xmeet_speculative(tp);
4746     switch (tp->ptr()) {
4747     case TopPTR:
4748     case AnyNull: {
4749       int instance_id = meet_instance_id(InstanceTop);
4750       return make(ptr, (ptr == Constant ? const_oop() : NULL),
4751                   _ary, _klass, _klass_is_exact, offset, instance_id, speculative, depth);
4752     }
4753     case BotPTR:
4754     case NotNull: {
4755       int instance_id = meet_instance_id(tp->instance_id());
4756       return TypeOopPtr::make(ptr, offset, instance_id, speculative, depth);
4757     }
4758     default: ShouldNotReachHere();
4759     }
4760   }
4761 
4762   case AnyPtr: {                // Meeting two AnyPtrs
4763     // Found an AnyPtr type vs self-AryPtr type
4764     const TypePtr *tp = t->is_ptr();
4765     int offset = meet_offset(tp->offset());
4766     PTR ptr = meet_ptr(tp->ptr());
4767     const TypePtr* speculative = xmeet_speculative(tp);
4768     int depth = meet_inline_depth(tp->inline_depth());
4769     switch (tp->ptr()) {
4770     case TopPTR:
4771       return this;
4772     case BotPTR:
4773     case NotNull:
4774       return TypePtr::make(AnyPtr, ptr, offset, speculative, depth);
4775     case Null:
4776       if( ptr == Null ) return TypePtr::make(AnyPtr, ptr, offset, speculative, depth);
4777       // else fall through to AnyNull
4778     case AnyNull: {
4779       int instance_id = meet_instance_id(InstanceTop);
4780       return make(ptr, (ptr == Constant ? const_oop() : NULL),
4781                   _ary, _klass, _klass_is_exact, offset, instance_id, speculative, depth);
4782     }
4783     default: ShouldNotReachHere();
4784     }
4785   }
4786 
4787   case MetadataPtr:
4788   case KlassPtr:
4789   case InstKlassPtr:
4790   case AryKlassPtr:
4791   case RawPtr: return TypePtr::BOTTOM;
4792 
4793   case AryPtr: {                // Meeting 2 references?
4794     const TypeAryPtr *tap = t->is_aryptr();
4795     int off = meet_offset(tap->offset());

4796     const TypeAry *tary = _ary->meet_speculative(tap->_ary)->is_ary();
4797     PTR ptr = meet_ptr(tap->ptr());
4798     int instance_id = meet_instance_id(tap->instance_id());
4799     const TypePtr* speculative = xmeet_speculative(tap);
4800     int depth = meet_inline_depth(tap->inline_depth());
4801 
4802     ciKlass* res_klass = NULL;
4803     bool res_xk = false;



4804     const Type* elem = tary->_elem;
4805     if (meet_aryptr(ptr, elem, this, tap, res_klass, res_xk) == NOT_SUBTYPE) {
4806       instance_id = InstanceBot;














4807     }
4808 
4809     ciObject* o = NULL;             // Assume not constant when done
4810     ciObject* this_oop = const_oop();
4811     ciObject* tap_oop = tap->const_oop();
4812     if (ptr == Constant) {
4813       if (this_oop != NULL && tap_oop != NULL &&
4814           this_oop->equals(tap_oop)) {
4815         o = tap_oop;
4816       } else if (above_centerline(_ptr)) {
4817         o = tap_oop;
4818       } else if (above_centerline(tap->_ptr)) {
4819         o = this_oop;
4820       } else {
4821         ptr = NotNull;
4822       }
4823     }
4824     return make(ptr, o, TypeAry::make(elem, tary->_size, tary->_stable), res_klass, res_xk, off, instance_id, speculative, depth);
4825   }
4826 
4827   // All arrays inherit from Object class
4828   case InstPtr: {
4829     const TypeInstPtr *tp = t->is_instptr();
4830     int offset = meet_offset(tp->offset());
4831     PTR ptr = meet_ptr(tp->ptr());
4832     int instance_id = meet_instance_id(tp->instance_id());
4833     const TypePtr* speculative = xmeet_speculative(tp);
4834     int depth = meet_inline_depth(tp->inline_depth());
4835     InterfaceSet interfaces = meet_interfaces(tp);
4836     InterfaceSet tp_interfaces = tp->_interfaces;
4837     InterfaceSet this_interfaces = _interfaces;
4838 
4839     switch (ptr) {
4840     case TopPTR:
4841     case AnyNull:                // Fall 'down' to dual of object klass
4842       // For instances when a subclass meets a superclass we fall
4843       // below the centerline when the superclass is exact. We need to
4844       // do the same here.
4845       if (tp->klass()->equals(ciEnv::current()->Object_klass()) && this_interfaces.contains(tp_interfaces) && !tp->klass_is_exact()) {
4846         return TypeAryPtr::make(ptr, _ary, _klass, _klass_is_exact, offset, instance_id, speculative, depth);
4847       } else {
4848         // cannot subclass, so the meet has to fall badly below the centerline
4849         ptr = NotNull;
4850         instance_id = InstanceBot;
4851         interfaces = this_interfaces.intersection_with(tp_interfaces);
4852         return TypeInstPtr::make(ptr, ciEnv::current()->Object_klass(), interfaces, false, NULL,offset, instance_id, speculative, depth);
4853       }
4854     case Constant:
4855     case NotNull:
4856     case BotPTR:                // Fall down to object klass
4857       // LCA is object_klass, but if we subclass from the top we can do better
4858       if (above_centerline(tp->ptr())) {
4859         // If 'tp'  is above the centerline and it is Object class
4860         // then we can subclass in the Java class hierarchy.
4861         // For instances when a subclass meets a superclass we fall
4862         // below the centerline when the superclass is exact. We need
4863         // to do the same here.
4864         if (tp->klass()->equals(ciEnv::current()->Object_klass()) && this_interfaces.contains(tp_interfaces) && !tp->klass_is_exact()) {
4865           // that is, my array type is a subtype of 'tp' klass
4866           return make(ptr, (ptr == Constant ? const_oop() : NULL),
4867                       _ary, _klass, _klass_is_exact, offset, instance_id, speculative, depth);
4868         }
4869       }
4870       // The other case cannot happen, since t cannot be a subtype of an array.
4871       // The meet falls down to Object class below centerline.
4872       if (ptr == Constant) {
4873          ptr = NotNull;
4874       }
4875       if (instance_id > 0) {
4876         instance_id = InstanceBot;
4877       }
4878       interfaces = this_interfaces.intersection_with(tp_interfaces);
4879       return TypeInstPtr::make(ptr, ciEnv::current()->Object_klass(), interfaces, false, NULL, offset, instance_id, speculative, depth);
4880     default: typerr(t);
4881     }
4882   }
4883   }
4884   return this;                  // Lint noise
4885 }
4886 
4887 
4888 template<class T> TypePtr::MeetResult TypePtr::meet_aryptr(PTR& ptr, const Type*& elem, const T* this_ary,
4889                                                            const T* other_ary, ciKlass*& res_klass, bool& res_xk) {
4890   int dummy;
4891   bool this_top_or_bottom = (this_ary->base_element_type(dummy) == Type::TOP || this_ary->base_element_type(dummy) == Type::BOTTOM);
4892   bool other_top_or_bottom = (other_ary->base_element_type(dummy) == Type::TOP || other_ary->base_element_type(dummy) == Type::BOTTOM);
4893   ciKlass* this_klass = this_ary->klass();
4894   ciKlass* other_klass = other_ary->klass();
4895   bool this_xk = this_ary->klass_is_exact();
4896   bool other_xk = other_ary->klass_is_exact();
4897   PTR this_ptr = this_ary->ptr();
4898   PTR other_ptr = other_ary->ptr();






4899   res_klass = NULL;
4900   MeetResult result = SUBTYPE;




4901   if (elem->isa_int()) {
4902     // Integral array element types have irrelevant lattice relations.
4903     // It is the klass that determines array layout, not the element type.
4904     if (this_top_or_bottom)
4905       res_klass = other_klass;
4906     else if (other_top_or_bottom || other_klass == this_klass) {
4907       res_klass = this_klass;
4908     } else {
4909       // Something like byte[int+] meets char[int+].
4910       // This must fall to bottom, not (int[-128..65535])[int+].
4911       // instance_id = InstanceBot;
4912       elem = Type::BOTTOM;
4913       result = NOT_SUBTYPE;
4914     }
4915   } else {// Non integral arrays.
4916     // Must fall to bottom if exact klasses in upper lattice
4917     // are not equal or super klass is exact.
4918     if ((above_centerline(ptr) || ptr == Constant) && !this_ary->is_same_java_type_as(other_ary) &&
4919         // meet with top[] and bottom[] are processed further down:
4920         !this_top_or_bottom && !other_top_or_bottom &&
4921         // both are exact and not equal:
4922         ((other_xk && this_xk) ||
4923          // 'tap'  is exact and super or unrelated:
4924          (other_xk && !other_ary->is_meet_subtype_of(this_ary)) ||
4925          // 'this' is exact and super or unrelated:
4926          (this_xk && !this_ary->is_meet_subtype_of(other_ary)))) {
4927       if (above_centerline(ptr) || (elem->make_ptr() && above_centerline(elem->make_ptr()->_ptr))) {
4928         elem = Type::BOTTOM;
4929       }
4930       ptr = NotNull;
4931       res_xk = false;
4932       return NOT_SUBTYPE;
4933     }
4934   }
4935 
4936   res_xk = false;
4937   switch (other_ptr) {
4938     case AnyNull:
4939     case TopPTR:
4940       // Compute new klass on demand, do not use tap->_klass
4941       if (below_centerline(this_ptr)) {
4942         res_xk = this_xk;



4943       } else {
4944         res_xk = (other_xk || this_xk);
4945       }
4946       return result;
4947     case Constant: {
4948       if (this_ptr == Constant) {
4949           res_xk = true;
4950       } else if(above_centerline(this_ptr)) {
4951         res_xk = true;
4952       } else {
4953         // Only precise for identical arrays
4954         res_xk = this_xk && (this_ary->is_same_java_type_as(other_ary) || (this_top_or_bottom && other_top_or_bottom));




4955       }
4956       return result;
4957     }
4958     case NotNull:
4959     case BotPTR:
4960       // Compute new klass on demand, do not use tap->_klass
4961       if (above_centerline(this_ptr)) {
4962         res_xk = other_xk;



4963       } else {
4964         res_xk = (other_xk && this_xk) &&
4965                  (this_ary->is_same_java_type_as(other_ary) || (this_top_or_bottom && other_top_or_bottom)); // Only precise for identical arrays




4966       }
4967       return result;
4968     default:  {
4969       ShouldNotReachHere();
4970       return result;
4971     }
4972   }
4973   return result;
4974 }
4975 
4976 
4977 //------------------------------xdual------------------------------------------
4978 // Dual: compute field-by-field dual
4979 const Type *TypeAryPtr::xdual() const {
4980   return new TypeAryPtr(dual_ptr(), _const_oop, _ary->dual()->is_ary(),_klass, _klass_is_exact, dual_offset(), dual_instance_id(), is_autobox_cache(), dual_speculative(), dual_inline_depth());









4981 }
4982 
4983 //------------------------------dump2------------------------------------------
4984 #ifndef PRODUCT
4985 void TypeAryPtr::dump2( Dict &d, uint depth, outputStream *st ) const {
4986   _ary->dump2(d,depth,st);
4987   _interfaces.dump(st);
4988 
4989   switch( _ptr ) {
4990   case Constant:
4991     const_oop()->print(st);
4992     break;
4993   case BotPTR:
4994     if (!WizardMode && !Verbose) {
4995       if( _klass_is_exact ) st->print(":exact");
4996       break;
4997     }
4998   case TopPTR:
4999   case AnyNull:
5000   case NotNull:
5001     st->print(":%s", ptr_msg[_ptr]);
5002     if( _klass_is_exact ) st->print(":exact");
5003     break;
5004   default:
5005     break;
5006   }
5007 
5008   if( _offset != 0 ) {









5009     int header_size = objArrayOopDesc::header_size() * wordSize;
5010     if( _offset == OffsetTop )       st->print("+undefined");
5011     else if( _offset == OffsetBot )  st->print("+any");
5012     else if( _offset < header_size ) st->print("+%d", _offset);
5013     else {
5014       BasicType basic_elem_type = elem()->basic_type();
5015       if (basic_elem_type == T_ILLEGAL) {
5016         st->print("+any");
5017       } else {
5018         int array_base = arrayOopDesc::base_offset_in_bytes(basic_elem_type);
5019         int elem_size = type2aelembytes(basic_elem_type);
5020         st->print("[%d]", (_offset - array_base)/elem_size);
5021       }
5022     }
5023   }
5024   st->print(" *");
5025   if (_instance_id == InstanceTop)
5026     st->print(",iid=top");
5027   else if (_instance_id != InstanceBot)
5028     st->print(",iid=%d",_instance_id);
5029 
5030   dump_inline_depth(st);
5031   dump_speculative(st);
5032 }
5033 #endif
5034 
5035 bool TypeAryPtr::empty(void) const {
5036   if (_ary->empty())       return true;




5037   return TypeOopPtr::empty();
5038 }
5039 
5040 //------------------------------add_offset-------------------------------------
5041 const TypePtr* TypeAryPtr::add_offset(intptr_t offset) const {
5042   return make(_ptr, _const_oop, _ary, _klass, _klass_is_exact, xadd_offset(offset), _instance_id, add_offset_speculative(offset), _inline_depth);
5043 }
5044 
5045 const TypeAryPtr* TypeAryPtr::with_offset(intptr_t offset) const {
5046   return make(_ptr, _const_oop, _ary, _klass, _klass_is_exact, offset, _instance_id, with_offset_speculative(offset), _inline_depth);
5047 }
5048 
5049 const TypeAryPtr* TypeAryPtr::with_ary(const TypeAry* ary) const {
5050   return make(_ptr, _const_oop, ary, _klass, _klass_is_exact, _offset, _instance_id, _speculative, _inline_depth);
5051 }
5052 
5053 const TypeAryPtr* TypeAryPtr::remove_speculative() const {
5054   if (_speculative == NULL) {
5055     return this;
5056   }
5057   assert(_inline_depth == InlineDepthTop || _inline_depth == InlineDepthBottom, "non speculative type shouldn't have inline depth");
5058   return make(_ptr, _const_oop, _ary->remove_speculative()->is_ary(), _klass, _klass_is_exact, _offset, _instance_id, NULL, _inline_depth);













5059 }
5060 
5061 const TypePtr* TypeAryPtr::with_inline_depth(int depth) const {
5062   if (!UseInlineDepthForSpeculativeTypes) {
5063     return this;
5064   }
5065   return make(_ptr, _const_oop, _ary->remove_speculative()->is_ary(), _klass, _klass_is_exact, _offset, _instance_id, _speculative, depth);











































5066 }
5067 
5068 const TypePtr* TypeAryPtr::with_instance_id(int instance_id) const {
5069   assert(is_known_instance(), "should be known");
5070   return make(_ptr, _const_oop, _ary->remove_speculative()->is_ary(), _klass, _klass_is_exact, _offset, instance_id, _speculative, _inline_depth);
5071 }
5072 
5073 //=============================================================================
5074 

5075 //------------------------------hash-------------------------------------------
5076 // Type-specific hashing function.
5077 int TypeNarrowPtr::hash(void) const {
5078   return _ptrtype->hash() + 7;
5079 }
5080 
5081 bool TypeNarrowPtr::singleton(void) const {    // TRUE if type is a singleton
5082   return _ptrtype->singleton();
5083 }
5084 
5085 bool TypeNarrowPtr::empty(void) const {
5086   return _ptrtype->empty();
5087 }
5088 
5089 intptr_t TypeNarrowPtr::get_con() const {
5090   return _ptrtype->get_con();
5091 }
5092 
5093 bool TypeNarrowPtr::eq( const Type *t ) const {
5094   const TypeNarrowPtr* tc = isa_same_narrowptr(t);

5145 
5146   case Int:                     // Mixing ints & oops happens when javac
5147   case Long:                    // reuses local variables
5148   case FloatTop:
5149   case FloatCon:
5150   case FloatBot:
5151   case DoubleTop:
5152   case DoubleCon:
5153   case DoubleBot:
5154   case AnyPtr:
5155   case RawPtr:
5156   case OopPtr:
5157   case InstPtr:
5158   case AryPtr:
5159   case MetadataPtr:
5160   case KlassPtr:
5161   case InstKlassPtr:
5162   case AryKlassPtr:
5163   case NarrowOop:
5164   case NarrowKlass:
5165 
5166   case Bottom:                  // Ye Olde Default
5167     return Type::BOTTOM;
5168   case Top:
5169     return this;
5170 
5171   default:                      // All else is a mistake
5172     typerr(t);
5173 
5174   } // End of switch
5175 
5176   return this;
5177 }
5178 
5179 #ifndef PRODUCT
5180 void TypeNarrowPtr::dump2( Dict & d, uint depth, outputStream *st ) const {
5181   _ptrtype->dump2(d, depth, st);
5182 }
5183 #endif
5184 
5185 const TypeNarrowOop *TypeNarrowOop::BOTTOM;

5229     return (one == two) && TypePtr::eq(t);
5230   } else {
5231     return one->equals(two) && TypePtr::eq(t);
5232   }
5233 }
5234 
5235 //------------------------------hash-------------------------------------------
5236 // Type-specific hashing function.
5237 int TypeMetadataPtr::hash(void) const {
5238   return
5239     (metadata() ? metadata()->hash() : 0) +
5240     TypePtr::hash();
5241 }
5242 
5243 //------------------------------singleton--------------------------------------
5244 // TRUE if Type is a singleton type, FALSE otherwise.   Singletons are simple
5245 // constants
5246 bool TypeMetadataPtr::singleton(void) const {
5247   // detune optimizer to not generate constant metadata + constant offset as a constant!
5248   // TopPTR, Null, AnyNull, Constant are all singletons
5249   return (_offset == 0) && !below_centerline(_ptr);
5250 }
5251 
5252 //------------------------------add_offset-------------------------------------
5253 const TypePtr* TypeMetadataPtr::add_offset( intptr_t offset ) const {
5254   return make( _ptr, _metadata, xadd_offset(offset));
5255 }
5256 
5257 //-----------------------------filter------------------------------------------
5258 // Do not allow interface-vs.-noninterface joins to collapse to top.
5259 const Type *TypeMetadataPtr::filter_helper(const Type *kills, bool include_speculative) const {
5260   const TypeMetadataPtr* ft = join_helper(kills, include_speculative)->isa_metadataptr();
5261   if (ft == NULL || ft->empty())
5262     return Type::TOP;           // Canonical empty value
5263   return ft;
5264 }
5265 
5266  //------------------------------get_con----------------------------------------
5267 intptr_t TypeMetadataPtr::get_con() const {
5268   assert( _ptr == Null || _ptr == Constant, "" );
5269   assert( _offset >= 0, "" );
5270 
5271   if (_offset != 0) {
5272     // After being ported to the compiler interface, the compiler no longer
5273     // directly manipulates the addresses of oops.  Rather, it only has a pointer
5274     // to a handle at compile time.  This handle is embedded in the generated
5275     // code and dereferenced at the time the nmethod is made.  Until that time,
5276     // it is not reasonable to do arithmetic with the addresses of oops (we don't
5277     // have access to the addresses!).  This does not seem to currently happen,
5278     // but this assertion here is to help prevent its occurrence.
5279     tty->print_cr("Found oop constant with non-zero offset");
5280     ShouldNotReachHere();
5281   }
5282 
5283   return (intptr_t)metadata()->constant_encoding();
5284 }
5285 
5286 //------------------------------cast_to_ptr_type-------------------------------
5287 const TypeMetadataPtr* TypeMetadataPtr::cast_to_ptr_type(PTR ptr) const {
5288   if( ptr == _ptr ) return this;
5289   return make(ptr, metadata(), _offset);
5290 }
5291 

5302   case Long:                    // reuses local variables
5303   case FloatTop:
5304   case FloatCon:
5305   case FloatBot:
5306   case DoubleTop:
5307   case DoubleCon:
5308   case DoubleBot:
5309   case NarrowOop:
5310   case NarrowKlass:
5311   case Bottom:                  // Ye Olde Default
5312     return Type::BOTTOM;
5313   case Top:
5314     return this;
5315 
5316   default:                      // All else is a mistake
5317     typerr(t);
5318 
5319   case AnyPtr: {
5320     // Found an AnyPtr type vs self-OopPtr type
5321     const TypePtr *tp = t->is_ptr();
5322     int offset = meet_offset(tp->offset());
5323     PTR ptr = meet_ptr(tp->ptr());
5324     switch (tp->ptr()) {
5325     case Null:
5326       if (ptr == Null)  return TypePtr::make(AnyPtr, ptr, offset, tp->speculative(), tp->inline_depth());
5327       // else fall through:
5328     case TopPTR:
5329     case AnyNull: {
5330       return make(ptr, _metadata, offset);
5331     }
5332     case BotPTR:
5333     case NotNull:
5334       return TypePtr::make(AnyPtr, ptr, offset, tp->speculative(), tp->inline_depth());
5335     default: typerr(t);
5336     }
5337   }
5338 
5339   case RawPtr:
5340   case KlassPtr:
5341   case InstKlassPtr:
5342   case AryKlassPtr:
5343   case OopPtr:
5344   case InstPtr:
5345   case AryPtr:
5346     return TypePtr::BOTTOM;     // Oop meet raw is not well defined
5347 
5348   case MetadataPtr: {
5349     const TypeMetadataPtr *tp = t->is_metadataptr();
5350     int offset = meet_offset(tp->offset());
5351     PTR tptr = tp->ptr();
5352     PTR ptr = meet_ptr(tptr);
5353     ciMetadata* md = (tptr == TopPTR) ? metadata() : tp->metadata();
5354     if (tptr == TopPTR || _ptr == TopPTR ||
5355         metadata()->equals(tp->metadata())) {
5356       return make(ptr, md, offset);
5357     }
5358     // metadata is different
5359     if( ptr == Constant ) {  // Cannot be equal constants, so...
5360       if( tptr == Constant && _ptr != Constant)  return t;
5361       if( _ptr == Constant && tptr != Constant)  return this;
5362       ptr = NotNull;            // Fall down in lattice
5363     }
5364     return make(ptr, NULL, offset);
5365     break;
5366   }
5367   } // End of switch
5368   return this;                  // Return the double constant
5369 }
5370 
5371 
5372 //------------------------------xdual------------------------------------------
5373 // Dual of a pure metadata pointer.
5374 const Type *TypeMetadataPtr::xdual() const {
5375   return new TypeMetadataPtr(dual_ptr(), metadata(), dual_offset());
5376 }
5377 
5378 //------------------------------dump2------------------------------------------
5379 #ifndef PRODUCT
5380 void TypeMetadataPtr::dump2( Dict &d, uint depth, outputStream *st ) const {
5381   st->print("metadataptr:%s", ptr_msg[_ptr]);
5382   if( metadata() ) st->print(INTPTR_FORMAT, p2i(metadata()));
5383   switch( _offset ) {
5384   case OffsetTop: st->print("+top"); break;
5385   case OffsetBot: st->print("+any"); break;
5386   case         0: break;
5387   default:        st->print("+%d",_offset); break;
5388   }
5389 }
5390 #endif
5391 
5392 
5393 //=============================================================================
5394 // Convenience common pre-built type.
5395 const TypeMetadataPtr *TypeMetadataPtr::BOTTOM;
5396 
5397 TypeMetadataPtr::TypeMetadataPtr(PTR ptr, ciMetadata* metadata, int offset):
5398   TypePtr(MetadataPtr, ptr, offset), _metadata(metadata) {
5399 }
5400 
5401 const TypeMetadataPtr* TypeMetadataPtr::make(ciMethod* m) {
5402   return make(Constant, m, 0);
5403 }
5404 const TypeMetadataPtr* TypeMetadataPtr::make(ciMethodData* m) {
5405   return make(Constant, m, 0);
5406 }
5407 
5408 //------------------------------make-------------------------------------------
5409 // Create a meta data constant
5410 const TypeMetadataPtr *TypeMetadataPtr::make(PTR ptr, ciMetadata* m, int offset) {
5411   assert(m == NULL || !m->is_klass(), "wrong type");
5412   return (TypeMetadataPtr*)(new TypeMetadataPtr(ptr, m, offset))->hashcons();
5413 }
5414 
5415 
5416 const TypeKlassPtr* TypeAryPtr::as_klass_type(bool try_for_exact) const {
5417   const Type* elem = _ary->_elem;
5418   bool xk = klass_is_exact();
5419   if (elem->make_oopptr() != NULL) {
5420     elem = elem->make_oopptr()->as_klass_type(try_for_exact);
5421     if (elem->is_klassptr()->klass_is_exact()) {


5422       xk = true;
5423     }
5424   }
5425   return TypeAryKlassPtr::make(xk ? TypePtr::Constant : TypePtr::NotNull, elem, klass(), 0);
5426 }
5427 
5428 const TypeKlassPtr* TypeKlassPtr::make(ciKlass *klass, InterfaceHandling interface_handling) {
5429   if (klass->is_instance_klass()) {
5430     return TypeInstKlassPtr::make(klass, interface_handling);
5431   }
5432   return TypeAryKlassPtr::make(klass, interface_handling);
5433 }
5434 
5435 const TypeKlassPtr* TypeKlassPtr::make(PTR ptr, ciKlass* klass, int offset, InterfaceHandling interface_handling) {
5436   if (klass->is_instance_klass()) {
5437     const InterfaceSet interfaces = TypePtr::interfaces(klass, true, true, false, interface_handling);
5438     return TypeInstKlassPtr::make(ptr, klass, interfaces, offset);
5439   }
5440   return TypeAryKlassPtr::make(ptr, klass, offset, interface_handling);
5441 }
5442 
5443 
5444 //------------------------------TypeKlassPtr-----------------------------------
5445 TypeKlassPtr::TypeKlassPtr(TYPES t, PTR ptr, ciKlass* klass, const InterfaceSet& interfaces, int offset)
5446   : TypePtr(t, ptr, offset), _klass(klass), _interfaces(interfaces) {
5447   assert(klass == NULL || !klass->is_loaded() || (klass->is_instance_klass() && !klass->is_interface()) ||
5448          klass->is_type_array_klass() || !klass->as_obj_array_klass()->base_element_klass()->is_interface(), "no interface here");
5449 }
5450 
5451 // Is there a single ciKlass* that can represent that type?
5452 ciKlass* TypeKlassPtr::exact_klass_helper() const {
5453   assert(_klass->is_instance_klass() && !_klass->is_interface(), "No interface");
5454   if (_interfaces.empty()) {
5455     return _klass;
5456   }
5457   if (_klass != ciEnv::current()->Object_klass()) {
5458     ciKlass* k = _klass;
5459     if (_interfaces.eq(TypePtr::interfaces(k, true, false, true, ignore_interfaces))) {
5460       return _klass;
5461     }
5462     return NULL;
5463   }
5464   return _interfaces.exact_klass();
5465 }
5466 
5467 //------------------------------eq---------------------------------------------
5468 // Structural equality check for Type representations
5469 bool TypeKlassPtr::eq(const Type *t) const {
5470   const TypeKlassPtr *p = t->is_klassptr();
5471   return
5472     _interfaces.eq(p->_interfaces) &&
5473     TypePtr::eq(p);
5474 }
5475 
5476 //------------------------------hash-------------------------------------------
5477 // Type-specific hashing function.
5478 int TypeKlassPtr::hash(void) const {
5479   return java_add((jint)TypePtr::hash(), _interfaces.hash());
5480 }
5481 
5482 //------------------------------singleton--------------------------------------
5483 // TRUE if Type is a singleton type, FALSE otherwise.   Singletons are simple
5484 // constants
5485 bool TypeKlassPtr::singleton(void) const {
5486   // detune optimizer to not generate constant klass + constant offset as a constant!
5487   // TopPTR, Null, AnyNull, Constant are all singletons
5488   return (_offset == 0) && !below_centerline(_ptr);
5489 }
5490 
5491 // Do not allow interface-vs.-noninterface joins to collapse to top.
5492 const Type *TypeKlassPtr::filter_helper(const Type *kills, bool include_speculative) const {
5493   // logic here mirrors the one from TypeOopPtr::filter. See comments
5494   // there.
5495   const Type* ft = join_helper(kills, include_speculative);
5496   const TypeKlassPtr* ftkp = ft->isa_instklassptr();
5497   const TypeKlassPtr* ktkp = kills->isa_instklassptr();
5498 
5499   if (ft->empty()) {
5500     return Type::TOP;           // Canonical empty value
5501   }
5502 
5503   return ft;
5504 }
5505 
5506 TypePtr::InterfaceSet TypeKlassPtr::meet_interfaces(const TypeKlassPtr* other) const {
5507   if (above_centerline(_ptr) && above_centerline(other->_ptr)) {
5508     return _interfaces.union_with(other->_interfaces);
5509   } else if (above_centerline(_ptr) && !above_centerline(other->_ptr)) {
5510     return other->_interfaces;
5511   } else if (above_centerline(other->_ptr) && !above_centerline(_ptr)) {
5512     return _interfaces;
5513   }
5514   return _interfaces.intersection_with(other->_interfaces);
5515 }
5516 
5517 //------------------------------get_con----------------------------------------
5518 intptr_t TypeKlassPtr::get_con() const {
5519   assert( _ptr == Null || _ptr == Constant, "" );
5520   assert( _offset >= 0, "" );
5521 
5522   if (_offset != 0) {
5523     // After being ported to the compiler interface, the compiler no longer
5524     // directly manipulates the addresses of oops.  Rather, it only has a pointer
5525     // to a handle at compile time.  This handle is embedded in the generated
5526     // code and dereferenced at the time the nmethod is made.  Until that time,
5527     // it is not reasonable to do arithmetic with the addresses of oops (we don't
5528     // have access to the addresses!).  This does not seem to currently happen,
5529     // but this assertion here is to help prevent its occurrence.
5530     tty->print_cr("Found oop constant with non-zero offset");
5531     ShouldNotReachHere();
5532   }
5533 
5534   ciKlass* k = exact_klass();
5535 
5536   return (intptr_t)k->constant_encoding();
5537 }
5538 
5539 //------------------------------dump2------------------------------------------
5540 // Dump Klass Type
5541 #ifndef PRODUCT
5542 void TypeKlassPtr::dump2(Dict & d, uint depth, outputStream *st) const {

5546   case NotNull:
5547     {
5548       const char *name = klass()->name()->as_utf8();
5549       if (name) {
5550         st->print("%s: " INTPTR_FORMAT, name, p2i(klass()));
5551       } else {
5552         ShouldNotReachHere();
5553       }
5554       _interfaces.dump(st);
5555     }
5556   case BotPTR:
5557     if (!WizardMode && !Verbose && _ptr != Constant) break;
5558   case TopPTR:
5559   case AnyNull:
5560     st->print(":%s", ptr_msg[_ptr]);
5561     if (_ptr == Constant) st->print(":exact");
5562     break;
5563   default:
5564     break;
5565   }
5566 
5567   if (_offset) {               // Dump offset, if any
5568     if (_offset == OffsetBot)      { st->print("+any"); }
5569     else if (_offset == OffsetTop) { st->print("+unknown"); }
5570     else                            { st->print("+%d", _offset); }
5571   }
5572 
5573   st->print(" *");
5574 }
5575 #endif
5576 
5577 //=============================================================================
5578 // Convenience common pre-built types.
5579 
5580 // Not-null object klass or below
5581 const TypeInstKlassPtr *TypeInstKlassPtr::OBJECT;
5582 const TypeInstKlassPtr *TypeInstKlassPtr::OBJECT_OR_NULL;
5583 
5584 bool TypeInstKlassPtr::eq(const Type *t) const {
5585   const TypeKlassPtr *p = t->is_klassptr();
5586   return
5587     klass()->equals(p->klass()) &&

5588     TypeKlassPtr::eq(p);
5589 }
5590 
5591 int TypeInstKlassPtr::hash(void) const {
5592   return java_add((jint)klass()->hash(), TypeKlassPtr::hash());
5593 }
5594 
5595 const TypeInstKlassPtr *TypeInstKlassPtr::make(PTR ptr, ciKlass* k, const InterfaceSet& interfaces, int offset) {


5596   TypeInstKlassPtr *r =
5597     (TypeInstKlassPtr*)(new TypeInstKlassPtr(ptr, k, interfaces, offset))->hashcons();
5598 
5599   return r;
5600 }
5601 
5602 //------------------------------add_offset-------------------------------------
5603 // Access internals of klass object
5604 const TypePtr* TypeInstKlassPtr::add_offset( intptr_t offset ) const {
5605   return make( _ptr, klass(), _interfaces, xadd_offset(offset) );
5606 }
5607 
5608 const TypeInstKlassPtr* TypeInstKlassPtr::with_offset(intptr_t offset) const {
5609   return make(_ptr, klass(), _interfaces, offset);
5610 }
5611 
5612 //------------------------------cast_to_ptr_type-------------------------------
5613 const TypeInstKlassPtr* TypeInstKlassPtr::cast_to_ptr_type(PTR ptr) const {
5614   assert(_base == InstKlassPtr, "subclass must override cast_to_ptr_type");
5615   if( ptr == _ptr ) return this;
5616   return make(ptr, _klass, _interfaces, _offset);
5617 }
5618 
5619 
5620 bool TypeInstKlassPtr::must_be_exact() const {
5621   if (!_klass->is_loaded())  return false;
5622   ciInstanceKlass* ik = _klass->as_instance_klass();
5623   if (ik->is_final())  return true;  // cannot clear xk
5624   return false;
5625 }
5626 
5627 //-----------------------------cast_to_exactness-------------------------------
5628 const TypeKlassPtr* TypeInstKlassPtr::cast_to_exactness(bool klass_is_exact) const {
5629   if (klass_is_exact == (_ptr == Constant)) return this;
5630   if (must_be_exact()) return this;
5631   ciKlass* k = klass();
5632   return make(klass_is_exact ? Constant : NotNull, k, _interfaces, _offset);
5633 }
5634 
5635 
5636 //-----------------------------as_instance_type--------------------------------
5637 // Corresponding type for an instance of the given class.
5638 // It will be NotNull, and exact if and only if the klass type is exact.
5639 const TypeOopPtr* TypeInstKlassPtr::as_instance_type(bool klass_change) const {
5640   ciKlass* k = klass();
5641   bool xk = klass_is_exact();
5642   Compile* C = Compile::current();
5643   Dependencies* deps = C->dependencies();
5644   assert((deps != NULL) == (C->method() != NULL && C->method()->code_size() > 0), "sanity");
5645   // Element is an instance
5646   bool klass_is_exact = false;
5647   TypePtr::InterfaceSet interfaces = _interfaces;
5648   if (k->is_loaded()) {
5649     // Try to set klass_is_exact.
5650     ciInstanceKlass* ik = k->as_instance_klass();
5651     klass_is_exact = ik->is_final();
5652     if (!klass_is_exact && klass_change
5653         && deps != NULL && UseUniqueSubclasses) {
5654       ciInstanceKlass* sub = ik->unique_concrete_subklass();
5655       if (sub != NULL) {
5656         ciKlass* sub_k = sub;
5657         TypePtr::InterfaceSet sub_interfaces = TypePtr::interfaces(sub_k, true, false, false, ignore_interfaces);
5658         assert(sub_k == sub, "");
5659         if (sub_interfaces.eq(_interfaces)) {
5660           deps->assert_abstract_with_unique_concrete_subtype(ik, sub);
5661           k = ik = sub;
5662           xk = sub->is_final();
5663         }
5664       }
5665     }
5666   }
5667   return TypeInstPtr::make(TypePtr::BotPTR, k, interfaces, xk, NULL, 0);
5668 }
5669 
5670 //------------------------------xmeet------------------------------------------
5671 // Compute the MEET of two types, return a new Type object.
5672 const Type    *TypeInstKlassPtr::xmeet( const Type *t ) const {
5673   // Perform a fast test for common case; meeting the same types together.
5674   if( this == t ) return this;  // Meeting same type-rep?
5675 
5676   // Current "this->_base" is Pointer
5677   switch (t->base()) {          // switch on original type
5678 
5679   case Int:                     // Mixing ints & oops happens when javac
5680   case Long:                    // reuses local variables
5681   case FloatTop:
5682   case FloatCon:
5683   case FloatBot:
5684   case DoubleTop:
5685   case DoubleCon:
5686   case DoubleBot:
5687   case NarrowOop:
5688   case NarrowKlass:
5689   case Bottom:                  // Ye Olde Default
5690     return Type::BOTTOM;
5691   case Top:
5692     return this;
5693 
5694   default:                      // All else is a mistake
5695     typerr(t);
5696 
5697   case AnyPtr: {                // Meeting to AnyPtrs
5698     // Found an AnyPtr type vs self-KlassPtr type
5699     const TypePtr *tp = t->is_ptr();
5700     int offset = meet_offset(tp->offset());
5701     PTR ptr = meet_ptr(tp->ptr());
5702     switch (tp->ptr()) {
5703     case TopPTR:
5704       return this;
5705     case Null:
5706       if( ptr == Null ) return TypePtr::make(AnyPtr, ptr, offset, tp->speculative(), tp->inline_depth());
5707     case AnyNull:
5708       return make( ptr, klass(), _interfaces, offset );
5709     case BotPTR:
5710     case NotNull:
5711       return TypePtr::make(AnyPtr, ptr, offset, tp->speculative(), tp->inline_depth());
5712     default: typerr(t);
5713     }
5714   }
5715 
5716   case RawPtr:
5717   case MetadataPtr:
5718   case OopPtr:
5719   case AryPtr:                  // Meet with AryPtr
5720   case InstPtr:                 // Meet with InstPtr
5721     return TypePtr::BOTTOM;
5722 
5723   //
5724   //             A-top         }
5725   //           /   |   \       }  Tops
5726   //       B-top A-any C-top   }
5727   //          | /  |  \ |      }  Any-nulls
5728   //       B-any   |   C-any   }
5729   //          |    |    |
5730   //       B-con A-con C-con   } constants; not comparable across classes
5731   //          |    |    |
5732   //       B-not   |   C-not   }
5733   //          | \  |  / |      }  not-nulls
5734   //       B-bot A-not C-bot   }
5735   //           \   |   /       }  Bottoms
5736   //             A-bot         }
5737   //
5738 
5739   case InstKlassPtr: {  // Meet two KlassPtr types
5740     const TypeInstKlassPtr *tkls = t->is_instklassptr();
5741     int  off     = meet_offset(tkls->offset());
5742     PTR  ptr     = meet_ptr(tkls->ptr());
5743     InterfaceSet interfaces = meet_interfaces(tkls);
5744 
5745     ciKlass* res_klass = NULL;
5746     bool res_xk = false;
5747     switch(meet_instptr(ptr, interfaces, this, tkls, res_klass, res_xk)) {

5748       case UNLOADED:
5749         ShouldNotReachHere();
5750       case SUBTYPE:
5751       case NOT_SUBTYPE:
5752       case LCA:
5753       case QUICK: {
5754         assert(res_xk == (ptr == Constant), "");
5755         const Type* res = make(ptr, res_klass, interfaces, off);
5756         return res;
5757       }
5758       default:
5759         ShouldNotReachHere();
5760     }
5761   } // End of case KlassPtr
5762   case AryKlassPtr: {                // All arrays inherit from Object class
5763     const TypeAryKlassPtr *tp = t->is_aryklassptr();
5764     int offset = meet_offset(tp->offset());
5765     PTR ptr = meet_ptr(tp->ptr());
5766     InterfaceSet interfaces = meet_interfaces(tp);
5767     InterfaceSet tp_interfaces = tp->_interfaces;
5768     InterfaceSet this_interfaces = _interfaces;
5769 
5770     switch (ptr) {
5771     case TopPTR:
5772     case AnyNull:                // Fall 'down' to dual of object klass
5773       // For instances when a subclass meets a superclass we fall
5774       // below the centerline when the superclass is exact. We need to
5775       // do the same here.
5776       if (klass()->equals(ciEnv::current()->Object_klass()) && tp_interfaces.contains(this_interfaces) && !klass_is_exact()) {
5777         return TypeAryKlassPtr::make(ptr, tp->elem(), tp->klass(), offset);
5778       } else {
5779         // cannot subclass, so the meet has to fall badly below the centerline
5780         ptr = NotNull;
5781         interfaces = _interfaces.intersection_with(tp->_interfaces);
5782         return make(ptr, ciEnv::current()->Object_klass(), interfaces, offset);
5783       }
5784     case Constant:
5785     case NotNull:
5786     case BotPTR:                // Fall down to object klass
5787       // LCA is object_klass, but if we subclass from the top we can do better
5788       if( above_centerline(_ptr) ) { // if( _ptr == TopPTR || _ptr == AnyNull )
5789         // If 'this' (InstPtr) is above the centerline and it is Object class
5790         // then we can subclass in the Java class hierarchy.
5791         // For instances when a subclass meets a superclass we fall
5792         // below the centerline when the superclass is exact. We need
5793         // to do the same here.
5794         if (klass()->equals(ciEnv::current()->Object_klass()) && tp_interfaces.contains(this_interfaces) && !klass_is_exact()) {
5795           // that is, tp's array type is a subtype of my klass
5796           return TypeAryKlassPtr::make(ptr,
5797                                        tp->elem(), tp->klass(), offset);
5798         }
5799       }
5800       // The other case cannot happen, since I cannot be a subtype of an array.
5801       // The meet falls down to Object class below centerline.
5802       if( ptr == Constant )
5803          ptr = NotNull;
5804       interfaces = this_interfaces.intersection_with(tp_interfaces);
5805       return make(ptr, ciEnv::current()->Object_klass(), interfaces, offset);
5806     default: typerr(t);
5807     }
5808   }
5809 
5810   } // End of switch
5811   return this;                  // Return the double constant
5812 }
5813 
5814 //------------------------------xdual------------------------------------------
5815 // Dual: compute field-by-field dual
5816 const Type    *TypeInstKlassPtr::xdual() const {
5817   return new TypeInstKlassPtr(dual_ptr(), klass(), _interfaces, dual_offset());
5818 }
5819 
5820 template <class T1, class T2> bool TypePtr::is_java_subtype_of_helper_for_instance(const T1* this_one, const T2* other, bool this_exact, bool other_exact) {
5821   static_assert(std::is_base_of<T2, T1>::value, "");
5822   if (!this_one->is_loaded() || !other->is_loaded()) {
5823     return false;
5824   }
5825   if (!this_one->is_instance_type(other)) {
5826     return false;
5827   }
5828 
5829   if (!other_exact) {
5830     return false;
5831   }
5832 
5833   if (other->klass()->equals(ciEnv::current()->Object_klass()) && other->_interfaces.empty()) {
5834     return true;
5835   }
5836 
5837   return this_one->_klass->is_subtype_of(other->_klass) && this_one->_interfaces.contains(other->_interfaces);

5901     bool klass_is_exact = ik->is_final();
5902     if (!klass_is_exact &&
5903         deps != NULL) {
5904       ciInstanceKlass* sub = ik->unique_concrete_subklass();
5905       if (sub != NULL) {
5906         ciKlass *sub_k = sub;
5907         TypePtr::InterfaceSet sub_interfaces = TypePtr::interfaces(sub_k, true, false, false, ignore_interfaces);
5908         assert(sub_k == sub, "");
5909         if (sub_interfaces.eq(_interfaces)) {
5910           deps->assert_abstract_with_unique_concrete_subtype(ik, sub);
5911           k = ik = sub;
5912           klass_is_exact = sub->is_final();
5913           return TypeKlassPtr::make(klass_is_exact ? Constant : _ptr, k, _offset);
5914         }
5915       }
5916     }
5917   }
5918   return this;
5919 }
5920 















5921 
5922 const TypeAryKlassPtr *TypeAryKlassPtr::make(PTR ptr, const Type* elem, ciKlass* k, int offset) {
5923   return (TypeAryKlassPtr*)(new TypeAryKlassPtr(ptr, elem, k, offset))->hashcons();
5924 }
5925 
5926 const TypeAryKlassPtr *TypeAryKlassPtr::make(PTR ptr, ciKlass* k, int offset, InterfaceHandling interface_handling) {
5927   if (k->is_obj_array_klass()) {
5928     // Element is an object array. Recursively call ourself.
5929     ciKlass* eklass = k->as_obj_array_klass()->element_klass();
5930     const TypeKlassPtr *etype = TypeKlassPtr::make(eklass, interface_handling)->cast_to_exactness(false);
5931     return TypeAryKlassPtr::make(ptr, etype, NULL, offset);




5932   } else if (k->is_type_array_klass()) {
5933     // Element is an typeArray
5934     const Type* etype = get_const_basic_type(k->as_type_array_klass()->element_type());
5935     return TypeAryKlassPtr::make(ptr, etype, k, offset);




5936   } else {
5937     ShouldNotReachHere();
5938     return NULL;
5939   }
5940 }
5941 











5942 const TypeAryKlassPtr* TypeAryKlassPtr::make(ciKlass* klass, InterfaceHandling interface_handling) {
5943   return TypeAryKlassPtr::make(Constant, klass, 0, interface_handling);
5944 }
5945 
5946 //------------------------------eq---------------------------------------------
5947 // Structural equality check for Type representations
5948 bool TypeAryKlassPtr::eq(const Type *t) const {
5949   const TypeAryKlassPtr *p = t->is_aryklassptr();
5950   return
5951     _elem == p->_elem &&  // Check array



5952     TypeKlassPtr::eq(p);  // Check sub-parts
5953 }
5954 
5955 //------------------------------hash-------------------------------------------
5956 // Type-specific hashing function.
5957 int TypeAryKlassPtr::hash(void) const {
5958   return (intptr_t)_elem + TypeKlassPtr::hash();

5959 }
5960 
5961 //----------------------compute_klass------------------------------------------
5962 // Compute the defining klass for this class
5963 ciKlass* TypeAryPtr::compute_klass(DEBUG_ONLY(bool verify)) const {
5964   // Compute _klass based on element type.
5965   ciKlass* k_ary = NULL;
5966   const TypeInstPtr *tinst;
5967   const TypeAryPtr *tary;
5968   const Type* el = elem();
5969   if (el->isa_narrowoop()) {
5970     el = el->make_ptr();
5971   }
5972 
5973   // Get element klass
5974   if ((tinst = el->isa_instptr()) != NULL) {





5975     // Leave k_ary at NULL.
5976   } else if ((tary = el->isa_aryptr()) != NULL) {
5977     // Leave k_ary at NULL.
5978   } else if ((el->base() == Type::Top) ||
5979              (el->base() == Type::Bottom)) {
5980     // element type of Bottom occurs from meet of basic type
5981     // and object; Top occurs when doing join on Bottom.
5982     // Leave k_ary at NULL.
5983   } else {
5984     // Cannot compute array klass directly from basic type,
5985     // since subtypes of TypeInt all have basic type T_INT.
5986 #ifdef ASSERT
5987     if (verify && el->isa_int()) {
5988       // Check simple cases when verifying klass.
5989       BasicType bt = T_ILLEGAL;
5990       if (el == TypeInt::BYTE) {
5991         bt = T_BYTE;
5992       } else if (el == TypeInt::SHORT) {
5993         bt = T_SHORT;
5994       } else if (el == TypeInt::CHAR) {

6026     // type TypeAryPtr::OOPS.  This Type is shared between all
6027     // active compilations.  However, the ciKlass which represents
6028     // this Type is *not* shared between compilations, so caching
6029     // this value would result in fetching a dangling pointer.
6030     //
6031     // Recomputing the underlying ciKlass for each request is
6032     // a bit less efficient than caching, but calls to
6033     // TypeAryPtr::OOPS->klass() are not common enough to matter.
6034     ((TypeAryPtr*)this)->_klass = k_ary;
6035   }
6036   return k_ary;
6037 }
6038 
6039 // Is there a single ciKlass* that can represent that type?
6040 ciKlass* TypeAryPtr::exact_klass_helper() const {
6041   if (_ary->_elem->make_ptr() && _ary->_elem->make_ptr()->isa_oopptr()) {
6042     ciKlass* k = _ary->_elem->make_ptr()->is_oopptr()->exact_klass_helper();
6043     if (k == NULL) {
6044       return NULL;
6045     }
6046     k = ciObjArrayKlass::make(k);
6047     return k;
6048   }
6049 
6050   return klass();
6051 }
6052 
6053 const Type* TypeAryPtr::base_element_type(int& dims) const {
6054   const Type* elem = this->elem();
6055   dims = 1;
6056   while (elem->make_ptr() && elem->make_ptr()->isa_aryptr()) {
6057     elem = elem->make_ptr()->is_aryptr()->elem();
6058     dims++;
6059   }
6060   return elem;
6061 }
6062 
6063 //------------------------------add_offset-------------------------------------
6064 // Access internals of klass object
6065 const TypePtr* TypeAryKlassPtr::add_offset(intptr_t offset) const {
6066   return make(_ptr, elem(), klass(), xadd_offset(offset));
6067 }
6068 
6069 const TypeAryKlassPtr* TypeAryKlassPtr::with_offset(intptr_t offset) const {
6070   return make(_ptr, elem(), klass(), offset);
6071 }
6072 
6073 //------------------------------cast_to_ptr_type-------------------------------
6074 const TypeAryKlassPtr* TypeAryKlassPtr::cast_to_ptr_type(PTR ptr) const {
6075   assert(_base == AryKlassPtr, "subclass must override cast_to_ptr_type");
6076   if (ptr == _ptr) return this;
6077   return make(ptr, elem(), _klass, _offset);
6078 }
6079 
6080 bool TypeAryKlassPtr::must_be_exact() const {
6081   if (_elem == Type::BOTTOM) return false;
6082   if (_elem == Type::TOP   ) return false;
6083   const TypeKlassPtr*  tk = _elem->isa_klassptr();
6084   if (!tk)             return true;   // a primitive type, like int




6085   return tk->must_be_exact();
6086 }
6087 
6088 
6089 //-----------------------------cast_to_exactness-------------------------------
6090 const TypeKlassPtr *TypeAryKlassPtr::cast_to_exactness(bool klass_is_exact) const {
6091   if (must_be_exact()) return this;  // cannot clear xk



6092   ciKlass* k = _klass;
6093   const Type* elem = this->elem();
6094   if (elem->isa_klassptr() && !klass_is_exact) {
6095     elem = elem->is_klassptr()->cast_to_exactness(klass_is_exact);
6096   }
6097   return make(klass_is_exact ? Constant : NotNull, elem, k, _offset);















6098 }
6099 
6100 
6101 //-----------------------------as_instance_type--------------------------------
6102 // Corresponding type for an instance of the given class.
6103 // It will be NotNull, and exact if and only if the klass type is exact.
6104 const TypeOopPtr* TypeAryKlassPtr::as_instance_type(bool klass_change) const {
6105   ciKlass* k = klass();
6106   bool    xk = klass_is_exact();
6107   const Type* el = NULL;
6108   if (elem()->isa_klassptr()) {
6109     el = elem()->is_klassptr()->as_instance_type(false)->cast_to_exactness(false);
6110     k = NULL;
6111   } else {
6112     el = elem();
6113   }
6114   return TypeAryPtr::make(TypePtr::BotPTR, TypeAry::make(el, TypeInt::POS), k, xk, 0);




6115 }
6116 
6117 
6118 //------------------------------xmeet------------------------------------------
6119 // Compute the MEET of two types, return a new Type object.
6120 const Type    *TypeAryKlassPtr::xmeet( const Type *t ) const {
6121   // Perform a fast test for common case; meeting the same types together.
6122   if( this == t ) return this;  // Meeting same type-rep?
6123 
6124   // Current "this->_base" is Pointer
6125   switch (t->base()) {          // switch on original type
6126 
6127   case Int:                     // Mixing ints & oops happens when javac
6128   case Long:                    // reuses local variables
6129   case FloatTop:
6130   case FloatCon:
6131   case FloatBot:
6132   case DoubleTop:
6133   case DoubleCon:
6134   case DoubleBot:
6135   case NarrowOop:
6136   case NarrowKlass:
6137   case Bottom:                  // Ye Olde Default
6138     return Type::BOTTOM;
6139   case Top:
6140     return this;
6141 
6142   default:                      // All else is a mistake
6143     typerr(t);
6144 
6145   case AnyPtr: {                // Meeting to AnyPtrs
6146     // Found an AnyPtr type vs self-KlassPtr type
6147     const TypePtr *tp = t->is_ptr();
6148     int offset = meet_offset(tp->offset());
6149     PTR ptr = meet_ptr(tp->ptr());
6150     switch (tp->ptr()) {
6151     case TopPTR:
6152       return this;
6153     case Null:
6154       if( ptr == Null ) return TypePtr::make(AnyPtr, ptr, offset, tp->speculative(), tp->inline_depth());
6155     case AnyNull:
6156       return make( ptr, _elem, klass(), offset );
6157     case BotPTR:
6158     case NotNull:
6159       return TypePtr::make(AnyPtr, ptr, offset, tp->speculative(), tp->inline_depth());
6160     default: typerr(t);
6161     }
6162   }
6163 
6164   case RawPtr:
6165   case MetadataPtr:
6166   case OopPtr:
6167   case AryPtr:                  // Meet with AryPtr
6168   case InstPtr:                 // Meet with InstPtr
6169     return TypePtr::BOTTOM;
6170 
6171   //
6172   //             A-top         }
6173   //           /   |   \       }  Tops
6174   //       B-top A-any C-top   }
6175   //          | /  |  \ |      }  Any-nulls
6176   //       B-any   |   C-any   }
6177   //          |    |    |
6178   //       B-con A-con C-con   } constants; not comparable across classes
6179   //          |    |    |
6180   //       B-not   |   C-not   }
6181   //          | \  |  / |      }  not-nulls
6182   //       B-bot A-not C-bot   }
6183   //           \   |   /       }  Bottoms
6184   //             A-bot         }
6185   //
6186 
6187   case AryKlassPtr: {  // Meet two KlassPtr types
6188     const TypeAryKlassPtr *tap = t->is_aryklassptr();
6189     int off = meet_offset(tap->offset());
6190     const Type* elem = _elem->meet(tap->_elem);
6191 
6192     PTR ptr = meet_ptr(tap->ptr());
6193     ciKlass* res_klass = NULL;
6194     bool res_xk = false;
6195     meet_aryptr(ptr, elem, this, tap, res_klass, res_xk);




6196     assert(res_xk == (ptr == Constant), "");
6197     return make(ptr, elem, res_klass, off);












6198   } // End of case KlassPtr
6199   case InstKlassPtr: {
6200     const TypeInstKlassPtr *tp = t->is_instklassptr();
6201     int offset = meet_offset(tp->offset());
6202     PTR ptr = meet_ptr(tp->ptr());
6203     InterfaceSet interfaces = meet_interfaces(tp);
6204     InterfaceSet tp_interfaces = tp->_interfaces;
6205     InterfaceSet this_interfaces = _interfaces;
6206 
6207     switch (ptr) {
6208     case TopPTR:
6209     case AnyNull:                // Fall 'down' to dual of object klass
6210       // For instances when a subclass meets a superclass we fall
6211       // below the centerline when the superclass is exact. We need to
6212       // do the same here.
6213       if (tp->klass()->equals(ciEnv::current()->Object_klass()) && this_interfaces.intersection_with(tp_interfaces).eq(tp_interfaces) && !tp->klass_is_exact()) {
6214         return TypeAryKlassPtr::make(ptr, _elem, _klass, offset);
6215       } else {
6216         // cannot subclass, so the meet has to fall badly below the centerline
6217         ptr = NotNull;
6218         interfaces = this_interfaces.intersection_with(tp->_interfaces);
6219         return TypeInstKlassPtr::make(ptr, ciEnv::current()->Object_klass(), interfaces, offset);
6220       }
6221     case Constant:
6222     case NotNull:
6223     case BotPTR:                // Fall down to object klass
6224       // LCA is object_klass, but if we subclass from the top we can do better
6225       if (above_centerline(tp->ptr())) {
6226         // If 'tp'  is above the centerline and it is Object class
6227         // then we can subclass in the Java class hierarchy.
6228         // For instances when a subclass meets a superclass we fall
6229         // below the centerline when the superclass is exact. We need
6230         // to do the same here.
6231         if (tp->klass()->equals(ciEnv::current()->Object_klass()) && this_interfaces.intersection_with(tp_interfaces).eq(tp_interfaces) && !tp->klass_is_exact()) {
6232           // that is, my array type is a subtype of 'tp' klass
6233           return make(ptr, _elem, _klass, offset);
6234         }
6235       }
6236       // The other case cannot happen, since t cannot be a subtype of an array.
6237       // The meet falls down to Object class below centerline.
6238       if (ptr == Constant)
6239          ptr = NotNull;
6240       interfaces = this_interfaces.intersection_with(tp_interfaces);
6241       return TypeInstKlassPtr::make(ptr, ciEnv::current()->Object_klass(), interfaces, offset);
6242     default: typerr(t);
6243     }
6244   }
6245 
6246   } // End of switch
6247   return this;                  // Return the double constant
6248 }
6249 
6250 template <class T1, class T2> bool TypePtr::is_java_subtype_of_helper_for_array(const T1* this_one, const T2* other, bool this_exact, bool other_exact) {
6251   static_assert(std::is_base_of<T2, T1>::value, "");
6252 
6253   if (other->klass() == ciEnv::current()->Object_klass() && other->_interfaces.empty() && other_exact) {
6254     return true;
6255   }
6256 
6257   int dummy;
6258   bool this_top_or_bottom = (this_one->base_element_type(dummy) == Type::TOP || this_one->base_element_type(dummy) == Type::BOTTOM);
6259 
6260   if (!this_one->is_loaded() || !other->is_loaded() || this_top_or_bottom) {
6261     return false;
6262   }
6263 
6264   if (this_one->is_instance_type(other)) {
6265     return other->klass() == ciEnv::current()->Object_klass() && other->_interfaces.intersection_with(this_one->_interfaces).eq(other->_interfaces) && other_exact;
6266   }
6267 
6268   assert(this_one->is_array_type(other), "");
6269   const T1* other_ary = this_one->is_array_type(other);
6270   bool other_top_or_bottom = (other_ary->base_element_type(dummy) == Type::TOP || other_ary->base_element_type(dummy) == Type::BOTTOM);
6271   if (other_top_or_bottom) {
6272     return false;
6273   }
6274 
6275   const TypePtr* other_elem = other_ary->elem()->make_ptr();
6276   const TypePtr* this_elem = this_one->elem()->make_ptr();
6277   if (this_elem != NULL && other_elem != NULL) {



6278     return this_one->is_reference_type(this_elem)->is_java_subtype_of_helper(this_one->is_reference_type(other_elem), this_exact, other_exact);
6279   }
6280   if (this_elem == NULL && other_elem == NULL) {
6281     return this_one->_klass->is_subtype_of(other->_klass);
6282   }
6283   return false;
6284 }
6285 
6286 bool TypeAryKlassPtr::is_java_subtype_of_helper(const TypeKlassPtr* other, bool this_exact, bool other_exact) const {
6287   return TypePtr::is_java_subtype_of_helper_for_array(this, other, this_exact, other_exact);
6288 }
6289 
6290 template <class T1, class T2> bool TypePtr::is_same_java_type_as_helper_for_array(const T1* this_one, const T2* other) {
6291   static_assert(std::is_base_of<T2, T1>::value, "");
6292 
6293   int dummy;
6294   bool this_top_or_bottom = (this_one->base_element_type(dummy) == Type::TOP || this_one->base_element_type(dummy) == Type::BOTTOM);
6295 
6296   if (!this_one->is_array_type(other) ||
6297       !this_one->is_loaded() || !other->is_loaded() || this_top_or_bottom) {

6345   }
6346 
6347   const TypePtr* this_elem = this_one->elem()->make_ptr();
6348   const TypePtr* other_elem = other_ary->elem()->make_ptr();
6349   if (other_elem != NULL && this_elem != NULL) {
6350     return this_one->is_reference_type(this_elem)->maybe_java_subtype_of_helper(this_one->is_reference_type(other_elem), this_exact, other_exact);
6351   }
6352   if (other_elem == NULL && this_elem == NULL) {
6353     return this_one->_klass->is_subtype_of(other->_klass);
6354   }
6355   return false;
6356 }
6357 
6358 bool TypeAryKlassPtr::maybe_java_subtype_of_helper(const TypeKlassPtr* other, bool this_exact, bool other_exact) const {
6359   return TypePtr::maybe_java_subtype_of_helper_for_array(this, other, this_exact, other_exact);
6360 }
6361 
6362 //------------------------------xdual------------------------------------------
6363 // Dual: compute field-by-field dual
6364 const Type    *TypeAryKlassPtr::xdual() const {
6365   return new TypeAryKlassPtr(dual_ptr(), elem()->dual(), klass(), dual_offset());
6366 }
6367 
6368 // Is there a single ciKlass* that can represent that type?
6369 ciKlass* TypeAryKlassPtr::exact_klass_helper() const {
6370   if (elem()->isa_klassptr()) {
6371     ciKlass* k = elem()->is_klassptr()->exact_klass_helper();
6372     if (k == NULL) {
6373       return NULL;
6374     }
6375     k = ciObjArrayKlass::make(k);
6376     return k;
6377   }
6378 
6379   return klass();
6380 }
6381 
6382 ciKlass* TypeAryKlassPtr::klass() const {
6383   if (_klass != NULL) {
6384     return _klass;
6385   }
6386   ciKlass* k = NULL;
6387   if (elem()->isa_klassptr()) {
6388     // leave NULL
6389   } else if ((elem()->base() == Type::Top) ||
6390              (elem()->base() == Type::Bottom)) {
6391   } else {
6392     k = ciTypeArrayKlass::make(elem()->basic_type());
6393     ((TypeAryKlassPtr*)this)->_klass = k;
6394   }
6395   return k;

6402   switch( _ptr ) {
6403   case Constant:
6404     st->print("precise ");
6405   case NotNull:
6406     {
6407       st->print("[");
6408       _elem->dump2(d, depth, st);
6409       _interfaces.dump(st);
6410       st->print(": ");
6411     }
6412   case BotPTR:
6413     if( !WizardMode && !Verbose && _ptr != Constant ) break;
6414   case TopPTR:
6415   case AnyNull:
6416     st->print(":%s", ptr_msg[_ptr]);
6417     if( _ptr == Constant ) st->print(":exact");
6418     break;
6419   default:
6420     break;
6421   }
6422 
6423   if( _offset ) {               // Dump offset, if any
6424     if( _offset == OffsetBot )      { st->print("+any"); }
6425     else if( _offset == OffsetTop ) { st->print("+unknown"); }
6426     else                            { st->print("+%d", _offset); }
6427   }
6428 


6429   st->print(" *");
6430 }
6431 #endif
6432 
6433 const Type* TypeAryKlassPtr::base_element_type(int& dims) const {
6434   const Type* elem = this->elem();
6435   dims = 1;
6436   while (elem->isa_aryklassptr()) {
6437     elem = elem->is_aryklassptr()->elem();
6438     dims++;
6439   }
6440   return elem;
6441 }
6442 
6443 //=============================================================================
6444 // Convenience common pre-built types.
6445 
6446 //------------------------------make-------------------------------------------
6447 const TypeFunc *TypeFunc::make( const TypeTuple *domain, const TypeTuple *range ) {
6448   return (TypeFunc*)(new TypeFunc(domain,range))->hashcons();












6449 }
6450 
6451 //------------------------------make-------------------------------------------
6452 const TypeFunc *TypeFunc::make(ciMethod* method) {
6453   Compile* C = Compile::current();
6454   const TypeFunc* tf = C->last_tf(method); // check cache
6455   if (tf != NULL)  return tf;  // The hit rate here is almost 50%.
6456   const TypeTuple *domain;
6457   if (method->is_static()) {
6458     domain = TypeTuple::make_domain(NULL, method->signature(), ignore_interfaces);
6459   } else {
6460     domain = TypeTuple::make_domain(method->holder(), method->signature(), ignore_interfaces);













6461   }
6462   const TypeTuple *range  = TypeTuple::make_range(method->signature(), ignore_interfaces);
6463   tf = TypeFunc::make(domain, range);
6464   C->set_last_tf(method, tf);  // fill cache
6465   return tf;
6466 }
6467 
6468 //------------------------------meet-------------------------------------------
6469 // Compute the MEET of two types.  It returns a new Type object.
6470 const Type *TypeFunc::xmeet( const Type *t ) const {
6471   // Perform a fast test for common case; meeting the same types together.
6472   if( this == t ) return this;  // Meeting same type-rep?
6473 
6474   // Current "this->_base" is Func
6475   switch (t->base()) {          // switch on original type
6476 
6477   case Bottom:                  // Ye Olde Default
6478     return t;
6479 
6480   default:                      // All else is a mistake
6481     typerr(t);
6482 
6483   case Top:
6484     break;
6485   }
6486   return this;                  // Return the double constant
6487 }
6488 
6489 //------------------------------xdual------------------------------------------
6490 // Dual: compute field-by-field dual
6491 const Type *TypeFunc::xdual() const {
6492   return this;
6493 }
6494 
6495 //------------------------------eq---------------------------------------------
6496 // Structural equality check for Type representations
6497 bool TypeFunc::eq( const Type *t ) const {
6498   const TypeFunc *a = (const TypeFunc*)t;
6499   return _domain == a->_domain &&
6500     _range == a->_range;


6501 }
6502 
6503 //------------------------------hash-------------------------------------------
6504 // Type-specific hashing function.
6505 int TypeFunc::hash(void) const {
6506   return (intptr_t)_domain + (intptr_t)_range;
6507 }
6508 
6509 //------------------------------dump2------------------------------------------
6510 // Dump Function Type
6511 #ifndef PRODUCT
6512 void TypeFunc::dump2( Dict &d, uint depth, outputStream *st ) const {
6513   if( _range->cnt() <= Parms )
6514     st->print("void");
6515   else {
6516     uint i;
6517     for (i = Parms; i < _range->cnt()-1; i++) {
6518       _range->field_at(i)->dump2(d,depth,st);
6519       st->print("/");
6520     }
6521     _range->field_at(i)->dump2(d,depth,st);
6522   }
6523   st->print(" ");
6524   st->print("( ");
6525   if( !depth || d[this] ) {     // Check for recursive dump
6526     st->print("...)");
6527     return;
6528   }
6529   d.Insert((void*)this,(void*)this);    // Stop recursion
6530   if (Parms < _domain->cnt())
6531     _domain->field_at(Parms)->dump2(d,depth-1,st);
6532   for (uint i = Parms+1; i < _domain->cnt(); i++) {
6533     st->print(", ");
6534     _domain->field_at(i)->dump2(d,depth-1,st);
6535   }
6536   st->print(" )");
6537 }
6538 #endif
6539 
6540 //------------------------------singleton--------------------------------------
6541 // TRUE if Type is a singleton type, FALSE otherwise.   Singletons are simple
6542 // constants (Ldi nodes).  Singletons are integer, float or double constants
6543 // or a single symbol.
6544 bool TypeFunc::singleton(void) const {
6545   return false;                 // Never a singleton
6546 }
6547 
6548 bool TypeFunc::empty(void) const {
6549   return false;                 // Never empty
6550 }
6551 
6552 
6553 BasicType TypeFunc::return_type() const{
6554   if (range()->cnt() == TypeFunc::Parms) {
6555     return T_VOID;
6556   }
6557   return range()->field_at(TypeFunc::Parms)->basic_type();
6558 }

   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

 253   case ciTypeFlow::StateVector::T_NULL:
 254     assert(type == ciTypeFlow::StateVector::null_type(), "");
 255     return TypePtr::NULL_PTR;
 256 
 257   case ciTypeFlow::StateVector::T_LONG2:
 258     // The ciTypeFlow pass pushes a long, then the half.
 259     // We do the same.
 260     assert(type == ciTypeFlow::StateVector::long2_type(), "");
 261     return TypeInt::TOP;
 262 
 263   case ciTypeFlow::StateVector::T_DOUBLE2:
 264     // The ciTypeFlow pass pushes double, then the half.
 265     // Our convention is the same.
 266     assert(type == ciTypeFlow::StateVector::double2_type(), "");
 267     return Type::TOP;
 268 
 269   case T_ADDRESS:
 270     assert(type->is_return_address(), "");
 271     return TypeRawPtr::make((address)(intptr_t)type->as_return_address()->bci());
 272 
 273   case T_PRIMITIVE_OBJECT: {
 274     ciInlineKlass* vk = type->unwrap()->as_inline_klass();
 275     return TypeOopPtr::make_from_klass(vk)->join_speculative(type->is_null_free() ? TypePtr::NOTNULL : TypePtr::BOTTOM);
 276   }
 277 
 278   default:
 279     // make sure we did not mix up the cases:
 280     assert(type != ciTypeFlow::StateVector::bottom_type(), "");
 281     assert(type != ciTypeFlow::StateVector::top_type(), "");
 282     assert(type != ciTypeFlow::StateVector::null_type(), "");
 283     assert(type != ciTypeFlow::StateVector::long2_type(), "");
 284     assert(type != ciTypeFlow::StateVector::double2_type(), "");
 285     assert(!type->is_return_address(), "");
 286 
 287     return Type::get_const_type(type);
 288   }
 289 }
 290 
 291 
 292 //-----------------------make_from_constant------------------------------------
 293 const Type* Type::make_from_constant(ciConstant constant, bool require_constant,
 294                                      int stable_dimension, bool is_narrow_oop,
 295                                      bool is_autobox_cache) {
 296   switch (constant.basic_type()) {
 297     case T_BOOLEAN:  return TypeInt::make(constant.as_boolean());
 298     case T_CHAR:     return TypeInt::make(constant.as_char());
 299     case T_BYTE:     return TypeInt::make(constant.as_byte());
 300     case T_SHORT:    return TypeInt::make(constant.as_short());
 301     case T_INT:      return TypeInt::make(constant.as_int());
 302     case T_LONG:     return TypeLong::make(constant.as_long());
 303     case T_FLOAT:    return TypeF::make(constant.as_float());
 304     case T_DOUBLE:   return TypeD::make(constant.as_double());
 305     case T_ARRAY:
 306     case T_PRIMITIVE_OBJECT:
 307     case T_OBJECT: {
 308         const Type* con_type = NULL;
 309         ciObject* oop_constant = constant.as_object();
 310         if (oop_constant->is_null_object()) {
 311           con_type = Type::get_zero_type(T_OBJECT);
 312         } else {
 313           guarantee(require_constant || oop_constant->should_be_constant(), "con_type must get computed");
 314           con_type = TypeOopPtr::make_from_constant(oop_constant, require_constant);
 315           if (Compile::current()->eliminate_boxing() && is_autobox_cache) {
 316             con_type = con_type->is_aryptr()->cast_to_autobox_cache();
 317           }
 318           if (stable_dimension > 0) {
 319             assert(FoldStableValues, "sanity");
 320             assert(!con_type->is_zero_type(), "default value for stable field");
 321             con_type = con_type->is_aryptr()->cast_to_stable(true, stable_dimension);
 322           }
 323         }
 324         if (is_narrow_oop) {
 325           con_type = con_type->make_narrowoop();
 326         }
 327         return con_type;
 328       }
 329     case T_ILLEGAL:
 330       // Invalid ciConstant returned due to OutOfMemoryError in the CI
 331       assert(Compile::current()->env()->failing(), "otherwise should not see this");
 332       return NULL;
 333     default:
 334       // Fall through to failure
 335       return NULL;
 336   }
 337 }
 338 
 339 static ciConstant check_mismatched_access(ciConstant con, BasicType loadbt, bool is_unsigned) {
 340   BasicType conbt = con.basic_type();
 341   switch (conbt) {
 342     case T_BOOLEAN: conbt = T_BYTE;   break;
 343     case T_ARRAY:   conbt = T_OBJECT; break;
 344     case T_PRIMITIVE_OBJECT: conbt = T_OBJECT; break;
 345     default:                          break;
 346   }
 347   switch (loadbt) {
 348     case T_BOOLEAN:   loadbt = T_BYTE;   break;
 349     case T_NARROWOOP: loadbt = T_OBJECT; break;
 350     case T_ARRAY:     loadbt = T_OBJECT; break;
 351     case T_PRIMITIVE_OBJECT: loadbt = T_OBJECT; break;
 352     case T_ADDRESS:   loadbt = T_OBJECT; break;
 353     default:                             break;
 354   }
 355   if (conbt == loadbt) {
 356     if (is_unsigned && conbt == T_BYTE) {
 357       // LoadB (T_BYTE) with a small mask (<=8-bit) is converted to LoadUB (T_BYTE).
 358       return ciConstant(T_INT, con.as_int() & 0xFF);
 359     } else {
 360       return con;
 361     }
 362   }
 363   if (conbt == T_SHORT && loadbt == T_CHAR) {
 364     // LoadS (T_SHORT) with a small mask (<=16-bit) is converted to LoadUS (T_CHAR).
 365     return ciConstant(T_INT, con.as_int() & 0xFFFF);
 366   }
 367   return ciConstant(); // T_ILLEGAL
 368 }
 369 
 370 // Try to constant-fold a stable array element.
 371 const Type* Type::make_constant_from_array_element(ciArray* array, int off, int stable_dimension,

 567   const Type **ffalse =(const Type**)shared_type_arena->AmallocWords(2*sizeof(Type*));
 568   ffalse[0] = Type::CONTROL;
 569   ffalse[1] = Type::TOP;
 570   TypeTuple::IFFALSE = TypeTuple::make( 2, ffalse );
 571 
 572   const Type **fneither =(const Type**)shared_type_arena->AmallocWords(2*sizeof(Type*));
 573   fneither[0] = Type::TOP;
 574   fneither[1] = Type::TOP;
 575   TypeTuple::IFNEITHER = TypeTuple::make( 2, fneither );
 576 
 577   const Type **ftrue =(const Type**)shared_type_arena->AmallocWords(2*sizeof(Type*));
 578   ftrue[0] = Type::TOP;
 579   ftrue[1] = Type::CONTROL;
 580   TypeTuple::IFTRUE = TypeTuple::make( 2, ftrue );
 581 
 582   const Type **floop =(const Type**)shared_type_arena->AmallocWords(2*sizeof(Type*));
 583   floop[0] = Type::CONTROL;
 584   floop[1] = TypeInt::INT;
 585   TypeTuple::LOOPBODY = TypeTuple::make( 2, floop );
 586 
 587   TypePtr::NULL_PTR= TypePtr::make(AnyPtr, TypePtr::Null, Offset(0));
 588   TypePtr::NOTNULL = TypePtr::make(AnyPtr, TypePtr::NotNull, Offset::bottom);
 589   TypePtr::BOTTOM  = TypePtr::make(AnyPtr, TypePtr::BotPTR, Offset::bottom);
 590 
 591   TypeRawPtr::BOTTOM = TypeRawPtr::make( TypePtr::BotPTR );
 592   TypeRawPtr::NOTNULL= TypeRawPtr::make( TypePtr::NotNull );
 593 
 594   const Type **fmembar = TypeTuple::fields(0);
 595   TypeTuple::MEMBAR = TypeTuple::make(TypeFunc::Parms+0, fmembar);
 596 
 597   const Type **fsc = (const Type**)shared_type_arena->AmallocWords(2*sizeof(Type*));
 598   fsc[0] = TypeInt::CC;
 599   fsc[1] = Type::MEMORY;
 600   TypeTuple::STORECONDITIONAL = TypeTuple::make(2, fsc);
 601 
 602   TypeInstPtr::NOTNULL = TypeInstPtr::make(TypePtr::NotNull, current->env()->Object_klass());
 603   TypeInstPtr::BOTTOM  = TypeInstPtr::make(TypePtr::BotPTR,  current->env()->Object_klass());
 604   TypeInstPtr::MIRROR  = TypeInstPtr::make(TypePtr::NotNull, current->env()->Class_klass());
 605   TypeInstPtr::MARK    = TypeInstPtr::make(TypePtr::BotPTR,  current->env()->Object_klass(),
 606                                            false, 0, Offset(oopDesc::mark_offset_in_bytes()));
 607   TypeInstPtr::KLASS   = TypeInstPtr::make(TypePtr::BotPTR,  current->env()->Object_klass(),
 608                                            false, 0, Offset(oopDesc::klass_offset_in_bytes()));
 609   TypeOopPtr::BOTTOM  = TypeOopPtr::make(TypePtr::BotPTR, Offset::bottom, TypeOopPtr::InstanceBot);
 610 
 611   TypeMetadataPtr::BOTTOM = TypeMetadataPtr::make(TypePtr::BotPTR, NULL, Offset::bottom);
 612 
 613   TypeNarrowOop::NULL_PTR = TypeNarrowOop::make( TypePtr::NULL_PTR );
 614   TypeNarrowOop::BOTTOM   = TypeNarrowOop::make( TypeInstPtr::BOTTOM );
 615 
 616   TypeNarrowKlass::NULL_PTR = TypeNarrowKlass::make( TypePtr::NULL_PTR );
 617 
 618   mreg2type[Op_Node] = Type::BOTTOM;
 619   mreg2type[Op_Set ] = 0;
 620   mreg2type[Op_RegN] = TypeNarrowOop::BOTTOM;
 621   mreg2type[Op_RegI] = TypeInt::INT;
 622   mreg2type[Op_RegP] = TypePtr::BOTTOM;
 623   mreg2type[Op_RegF] = Type::FLOAT;
 624   mreg2type[Op_RegD] = Type::DOUBLE;
 625   mreg2type[Op_RegL] = TypeLong::LONG;
 626   mreg2type[Op_RegFlags] = TypeInt::CC;
 627 
 628   GrowableArray<ciInstanceKlass*> array_interfaces;
 629   array_interfaces.push(current->env()->Cloneable_klass());
 630   array_interfaces.push(current->env()->Serializable_klass());
 631   TypeAryPtr::_array_interfaces = new TypePtr::InterfaceSet(&array_interfaces);
 632   TypeAryKlassPtr::_array_interfaces = TypeAryPtr::_array_interfaces;
 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(TypeInstPtr::BOTTOM,TypeInt::POS, /* stable= */ false, /* flat= */ true), 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));
 672   TypeInstKlassPtr::OBJECT_OR_NULL = TypeInstKlassPtr::make(TypePtr::BotPTR, current->env()->Object_klass(), Offset(0));
 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   }

2025 
2026 bool TypeLong::empty(void) const {
2027   return _lo > _hi;
2028 }
2029 
2030 //=============================================================================
2031 // Convenience common pre-built types.
2032 const TypeTuple *TypeTuple::IFBOTH;     // Return both arms of IF as reachable
2033 const TypeTuple *TypeTuple::IFFALSE;
2034 const TypeTuple *TypeTuple::IFTRUE;
2035 const TypeTuple *TypeTuple::IFNEITHER;
2036 const TypeTuple *TypeTuple::LOOPBODY;
2037 const TypeTuple *TypeTuple::MEMBAR;
2038 const TypeTuple *TypeTuple::STORECONDITIONAL;
2039 const TypeTuple *TypeTuple::START_I2C;
2040 const TypeTuple *TypeTuple::INT_PAIR;
2041 const TypeTuple *TypeTuple::LONG_PAIR;
2042 const TypeTuple *TypeTuple::INT_CC_PAIR;
2043 const TypeTuple *TypeTuple::LONG_CC_PAIR;
2044 
2045 static void collect_inline_fields(ciInlineKlass* vk, const Type** field_array, uint& pos) {
2046   for (int j = 0; j < vk->nof_nonstatic_fields(); j++) {
2047     ciField* field = vk->nonstatic_field_at(j);
2048     BasicType bt = field->type()->basic_type();
2049     const Type* ft = Type::get_const_type(field->type());
2050     field_array[pos++] = ft;
2051     if (type2size[bt] == 2) {
2052       field_array[pos++] = Type::HALF;
2053     }
2054   }
2055 }
2056 
2057 //------------------------------make-------------------------------------------
2058 // Make a TypeTuple from the range of a method signature
2059 const TypeTuple *TypeTuple::make_range(ciSignature* sig, InterfaceHandling interface_handling, bool ret_vt_fields) {
2060   ciType* return_type = sig->return_type();
2061   uint arg_cnt = return_type->size();
2062   if (ret_vt_fields) {
2063     arg_cnt = return_type->as_inline_klass()->inline_arg_slots() + 1;
2064     if (!sig->returns_null_free_inline_type()) {
2065       // InlineTypeNode::IsInit field used for null checking
2066       arg_cnt++;
2067     }
2068   }
2069 
2070   const Type **field_array = fields(arg_cnt);
2071   switch (return_type->basic_type()) {
2072   case T_LONG:
2073     field_array[TypeFunc::Parms]   = TypeLong::LONG;
2074     field_array[TypeFunc::Parms+1] = Type::HALF;
2075     break;
2076   case T_DOUBLE:
2077     field_array[TypeFunc::Parms]   = Type::DOUBLE;
2078     field_array[TypeFunc::Parms+1] = Type::HALF;
2079     break;
2080   case T_OBJECT:
2081   case T_ARRAY:
2082   case T_BOOLEAN:
2083   case T_CHAR:
2084   case T_FLOAT:
2085   case T_BYTE:
2086   case T_SHORT:
2087   case T_INT:
2088     field_array[TypeFunc::Parms] = get_const_type(return_type, interface_handling);
2089     break;
2090   case T_PRIMITIVE_OBJECT:
2091     if (ret_vt_fields) {
2092       uint pos = TypeFunc::Parms;
2093       field_array[pos++] = get_const_type(return_type); // Oop might be null when returning as fields
2094       collect_inline_fields(return_type->as_inline_klass(), field_array, pos);
2095       if (!sig->returns_null_free_inline_type()) {
2096         // InlineTypeNode::IsInit field used for null checking
2097         field_array[pos++] = get_const_basic_type(T_BOOLEAN);
2098       }
2099     } else {
2100       field_array[TypeFunc::Parms] = get_const_type(return_type)->join_speculative(sig->returns_null_free_inline_type() ? TypePtr::NOTNULL : TypePtr::BOTTOM);
2101     }
2102     break;
2103   case T_VOID:
2104     break;
2105   default:
2106     ShouldNotReachHere();
2107   }
2108   return (TypeTuple*)(new TypeTuple(TypeFunc::Parms + arg_cnt, field_array))->hashcons();
2109 }
2110 
2111 // Make a TypeTuple from the domain of a method signature
2112 const TypeTuple *TypeTuple::make_domain(ciMethod* method, InterfaceHandling interface_handling, bool vt_fields_as_args) {
2113   ciSignature* sig = method->signature();
2114   uint arg_cnt = sig->size() + (method->is_static() ? 0 : 1);
2115   if (vt_fields_as_args) {
2116     arg_cnt = 0;
2117     assert(method->get_sig_cc() != NULL, "Should have scalarized signature");
2118     for (ExtendedSignature sig_cc = ExtendedSignature(method->get_sig_cc(), SigEntryFilter()); !sig_cc.at_end(); ++sig_cc) {
2119       arg_cnt += type2size[(*sig_cc)._bt];
2120     }
2121   }
2122 
2123   uint pos = TypeFunc::Parms;
2124   const Type** field_array = fields(arg_cnt);
2125   if (!method->is_static()) {
2126     ciInstanceKlass* recv = method->holder();
2127     if (vt_fields_as_args && recv->is_inlinetype() && recv->as_inline_klass()->can_be_passed_as_fields()) {
2128       collect_inline_fields(recv->as_inline_klass(), field_array, pos);
2129     } else {
2130       field_array[pos++] = get_const_type(recv, interface_handling)->join_speculative(TypePtr::NOTNULL);
2131     }
2132   }
2133 
2134   int i = 0;
2135   while (pos < TypeFunc::Parms + arg_cnt) {
2136     ciType* type = sig->type_at(i);
2137     BasicType bt = type->basic_type();
2138 
2139     switch (bt) {
2140     case T_LONG:
2141       field_array[pos++] = TypeLong::LONG;
2142       field_array[pos++] = Type::HALF;
2143       break;
2144     case T_DOUBLE:
2145       field_array[pos++] = Type::DOUBLE;
2146       field_array[pos++] = Type::HALF;
2147       break;
2148     case T_OBJECT:
2149     case T_ARRAY:
2150     case T_FLOAT:
2151     case T_INT:
2152       field_array[pos++] = get_const_type(type, interface_handling);
2153       break;
2154     case T_BOOLEAN:
2155     case T_CHAR:
2156     case T_BYTE:
2157     case T_SHORT:
2158       field_array[pos++] = TypeInt::INT;
2159       break;
2160     case T_PRIMITIVE_OBJECT: {
2161       if (vt_fields_as_args && method->is_scalarized_arg(i + (method->is_static() ? 0 : 1))) {
2162         if (!sig->is_null_free_at(i)) {
2163           // InlineTypeNode::IsInit field used for null checking
2164           field_array[pos++] = get_const_basic_type(T_BOOLEAN);
2165         }
2166         collect_inline_fields(type->as_inline_klass(), field_array, pos);
2167       } else {
2168         field_array[pos++] = get_const_type(type)->join_speculative(sig->is_null_free_at(i) ? TypePtr::NOTNULL : TypePtr::BOTTOM);
2169       }
2170       break;
2171     }
2172     default:
2173       ShouldNotReachHere();
2174     }
2175     i++;
2176   }
2177   assert(pos == TypeFunc::Parms + arg_cnt, "wrong number of arguments");
2178 
2179   return (TypeTuple*)(new TypeTuple(TypeFunc::Parms + arg_cnt, field_array))->hashcons();
2180 }
2181 
2182 const TypeTuple *TypeTuple::make( uint cnt, const Type **fields ) {
2183   return (TypeTuple*)(new TypeTuple(cnt,fields))->hashcons();
2184 }
2185 
2186 //------------------------------fields-----------------------------------------
2187 // Subroutine call type with space allocated for argument types
2188 // Memory for Control, I_O, Memory, FramePtr, and ReturnAdr is allocated implicitly
2189 const Type **TypeTuple::fields( uint arg_cnt ) {
2190   const Type **flds = (const Type **)(Compile::current()->type_arena()->AmallocWords((TypeFunc::Parms+arg_cnt)*sizeof(Type*) ));
2191   flds[TypeFunc::Control  ] = Type::CONTROL;
2192   flds[TypeFunc::I_O      ] = Type::ABIO;
2193   flds[TypeFunc::Memory   ] = Type::MEMORY;
2194   flds[TypeFunc::FramePtr ] = TypeRawPtr::BOTTOM;
2195   flds[TypeFunc::ReturnAdr] = Type::RETURN_ADDRESS;
2196 
2197   return flds;

2292     if (_fields[i]->empty())  return true;
2293   }
2294   return false;
2295 }
2296 
2297 //=============================================================================
2298 // Convenience common pre-built types.
2299 
2300 inline const TypeInt* normalize_array_size(const TypeInt* size) {
2301   // Certain normalizations keep us sane when comparing types.
2302   // We do not want arrayOop variables to differ only by the wideness
2303   // of their index types.  Pick minimum wideness, since that is the
2304   // forced wideness of small ranges anyway.
2305   if (size->_widen != Type::WidenMin)
2306     return TypeInt::make(size->_lo, size->_hi, Type::WidenMin);
2307   else
2308     return size;
2309 }
2310 
2311 //------------------------------make-------------------------------------------
2312 const TypeAry* TypeAry::make(const Type* elem, const TypeInt* size, bool stable,
2313                              bool flat, bool not_flat, bool not_null_free) {
2314   if (UseCompressedOops && elem->isa_oopptr()) {
2315     elem = elem->make_narrowoop();
2316   }
2317   size = normalize_array_size(size);
2318   return (TypeAry*)(new TypeAry(elem, size, stable, flat, not_flat, not_null_free))->hashcons();
2319 }
2320 
2321 //------------------------------meet-------------------------------------------
2322 // Compute the MEET of two types.  It returns a new Type object.
2323 const Type *TypeAry::xmeet( const Type *t ) const {
2324   // Perform a fast test for common case; meeting the same types together.
2325   if( this == t ) return this;  // Meeting same type-rep?
2326 
2327   // Current "this->_base" is Ary
2328   switch (t->base()) {          // switch on original type
2329 
2330   case Bottom:                  // Ye Olde Default
2331     return t;
2332 
2333   default:                      // All else is a mistake
2334     typerr(t);
2335 
2336   case Array: {                 // Meeting 2 arrays?
2337     const TypeAry *a = t->is_ary();
2338     return TypeAry::make(_elem->meet_speculative(a->_elem),
2339                          _size->xmeet(a->_size)->is_int(),
2340                          _stable && a->_stable,
2341                          _flat && a->_flat,
2342                          _not_flat && a->_not_flat,
2343                          _not_null_free && a->_not_null_free);
2344   }
2345   case Top:
2346     break;
2347   }
2348   return this;                  // Return the double constant
2349 }
2350 
2351 //------------------------------xdual------------------------------------------
2352 // Dual: compute field-by-field dual
2353 const Type *TypeAry::xdual() const {
2354   const TypeInt* size_dual = _size->dual()->is_int();
2355   size_dual = normalize_array_size(size_dual);
2356   return new TypeAry(_elem->dual(), size_dual, !_stable, !_flat, !_not_flat, !_not_null_free);
2357 }
2358 
2359 //------------------------------eq---------------------------------------------
2360 // Structural equality check for Type representations
2361 bool TypeAry::eq( const Type *t ) const {
2362   const TypeAry *a = (const TypeAry*)t;
2363   return _elem == a->_elem &&
2364     _stable == a->_stable &&
2365     _size == a->_size &&
2366     _flat == a->_flat &&
2367     _not_flat == a->_not_flat &&
2368     _not_null_free == a->_not_null_free;
2369 
2370 }
2371 
2372 //------------------------------hash-------------------------------------------
2373 // Type-specific hashing function.
2374 int TypeAry::hash(void) const {
2375   return (intptr_t)_elem + (intptr_t)_size + (_stable ? 43 : 0) +
2376       (_flat ? 44 : 0) + (_not_flat ? 45 : 0) + (_not_null_free ? 46 : 0);
2377 }
2378 
2379 /**
2380  * Return same type without a speculative part in the element
2381  */
2382 const TypeAry* TypeAry::remove_speculative() const {
2383   return make(_elem->remove_speculative(), _size, _stable, _flat, _not_flat, _not_null_free);
2384 }
2385 
2386 /**
2387  * Return same type with cleaned up speculative part of element
2388  */
2389 const Type* TypeAry::cleanup_speculative() const {
2390   return make(_elem->cleanup_speculative(), _size, _stable, _flat, _not_flat, _not_null_free);
2391 }
2392 
2393 /**
2394  * Return same type but with a different inline depth (used for speculation)
2395  *
2396  * @param depth  depth to meet with
2397  */
2398 const TypePtr* TypePtr::with_inline_depth(int depth) const {
2399   if (!UseInlineDepthForSpeculativeTypes) {
2400     return this;
2401   }
2402   return make(AnyPtr, _ptr, _offset, _speculative, depth);
2403 }
2404 
2405 //------------------------------dump2------------------------------------------
2406 #ifndef PRODUCT
2407 void TypeAry::dump2( Dict &d, uint depth, outputStream *st ) const {
2408   if (_stable)  st->print("stable:");
2409   if (_flat) st->print("flat:");
2410   if (Verbose) {
2411     if (_not_flat) st->print("not flat:");
2412     if (_not_null_free) st->print("not null free:");
2413   }
2414   _elem->dump2(d, depth, st);
2415   st->print("[");
2416   _size->dump2(d, depth, st);
2417   st->print("]");
2418 }
2419 #endif
2420 
2421 //------------------------------singleton--------------------------------------
2422 // TRUE if Type is a singleton type, FALSE otherwise.   Singletons are simple
2423 // constants (Ldi nodes).  Singletons are integer, float or double constants
2424 // or a single symbol.
2425 bool TypeAry::singleton(void) const {
2426   return false;                 // Never a singleton
2427 }
2428 
2429 bool TypeAry::empty(void) const {
2430   return _elem->empty() || _size->empty();
2431 }
2432 
2433 //--------------------------ary_must_be_exact----------------------------------
2434 bool TypeAry::ary_must_be_exact() const {
2435   // This logic looks at the element type of an array, and returns true
2436   // if the element type is either a primitive or a final instance class.
2437   // In such cases, an array built on this ary must have no subclasses.
2438   if (_elem == BOTTOM)      return false;  // general array not exact
2439   if (_elem == TOP   )      return false;  // inverted general array not exact
2440   const TypeOopPtr*  toop = NULL;
2441   if (UseCompressedOops && _elem->isa_narrowoop()) {
2442     toop = _elem->make_ptr()->isa_oopptr();
2443   } else {
2444     toop = _elem->isa_oopptr();
2445   }
2446   if (!toop)                return true;   // a primitive type, like int
2447   if (!toop->is_loaded())   return false;  // unloaded class
2448   const TypeInstPtr* tinst;
2449   if (_elem->isa_narrowoop())
2450     tinst = _elem->make_ptr()->isa_instptr();
2451   else
2452     tinst = _elem->isa_instptr();
2453   if (tinst) {
2454     if (tinst->instance_klass()->is_final()) {
2455       // Even if MyValue is exact, [LMyValue is not exact due to [QMyValue <: [LMyValue.
2456       if (tinst->is_inlinetypeptr() && (tinst->ptr() == TypePtr::BotPTR || tinst->ptr() == TypePtr::TopPTR)) {
2457         return false;
2458       }
2459       return true;
2460     }
2461     return false;
2462   }
2463   const TypeAryPtr*  tap;
2464   if (_elem->isa_narrowoop())
2465     tap = _elem->make_ptr()->isa_aryptr();
2466   else
2467     tap = _elem->isa_aryptr();
2468   if (tap)
2469     return tap->ary()->ary_must_be_exact();
2470   return false;
2471 }
2472 
2473 //==============================TypeVect=======================================
2474 // Convenience common pre-built types.
2475 const TypeVect *TypeVect::VECTA = NULL; // vector length agnostic
2476 const TypeVect *TypeVect::VECTS = NULL; //  32-bit vectors
2477 const TypeVect *TypeVect::VECTD = NULL; //  64-bit vectors
2478 const TypeVect *TypeVect::VECTX = NULL; // 128-bit vectors
2479 const TypeVect *TypeVect::VECTY = NULL; // 256-bit vectors
2480 const TypeVect *TypeVect::VECTZ = NULL; // 512-bit vectors
2481 const TypeVect *TypeVect::VECTMASK = NULL; // predicate/mask vector
2482 

2638 
2639 //=============================================================================
2640 // Convenience common pre-built types.
2641 const TypePtr *TypePtr::NULL_PTR;
2642 const TypePtr *TypePtr::NOTNULL;
2643 const TypePtr *TypePtr::BOTTOM;
2644 
2645 //------------------------------meet-------------------------------------------
2646 // Meet over the PTR enum
2647 const TypePtr::PTR TypePtr::ptr_meet[TypePtr::lastPTR][TypePtr::lastPTR] = {
2648   //              TopPTR,    AnyNull,   Constant, Null,   NotNull, BotPTR,
2649   { /* Top     */ TopPTR,    AnyNull,   Constant, Null,   NotNull, BotPTR,},
2650   { /* AnyNull */ AnyNull,   AnyNull,   Constant, BotPTR, NotNull, BotPTR,},
2651   { /* Constant*/ Constant,  Constant,  Constant, BotPTR, NotNull, BotPTR,},
2652   { /* Null    */ Null,      BotPTR,    BotPTR,   Null,   BotPTR,  BotPTR,},
2653   { /* NotNull */ NotNull,   NotNull,   NotNull,  BotPTR, NotNull, BotPTR,},
2654   { /* BotPTR  */ BotPTR,    BotPTR,    BotPTR,   BotPTR, BotPTR,  BotPTR,}
2655 };
2656 
2657 //------------------------------make-------------------------------------------
2658 const TypePtr* TypePtr::make(TYPES t, enum PTR ptr, Offset offset, const TypePtr* speculative, int inline_depth) {
2659   return (TypePtr*)(new TypePtr(t,ptr,offset, speculative, inline_depth))->hashcons();
2660 }
2661 
2662 //------------------------------cast_to_ptr_type-------------------------------
2663 const TypePtr* TypePtr::cast_to_ptr_type(PTR ptr) const {
2664   assert(_base == AnyPtr, "subclass must override cast_to_ptr_type");
2665   if( ptr == _ptr ) return this;
2666   return make(_base, ptr, _offset, _speculative, _inline_depth);
2667 }
2668 
2669 //------------------------------get_con----------------------------------------
2670 intptr_t TypePtr::get_con() const {
2671   assert( _ptr == Null, "" );
2672   return offset();
2673 }
2674 
2675 //------------------------------meet-------------------------------------------
2676 // Compute the MEET of two types.  It returns a new Type object.
2677 const Type *TypePtr::xmeet(const Type *t) const {
2678   const Type* res = xmeet_helper(t);
2679   if (res->isa_ptr() == NULL) {
2680     return res;
2681   }
2682 
2683   const TypePtr* res_ptr = res->is_ptr();
2684   if (res_ptr->speculative() != NULL) {
2685     // type->speculative() == NULL means that speculation is no better
2686     // than type, i.e. type->speculative() == type. So there are 2
2687     // ways to represent the fact that we have no useful speculative
2688     // data and we should use a single one to be able to test for
2689     // equality between types. Check whether type->speculative() ==
2690     // type and set speculative to NULL if it is the case.
2691     if (res_ptr->remove_speculative() == res_ptr->speculative()) {
2692       return res_ptr->remove_speculative();

2723     int depth = meet_inline_depth(tp->inline_depth());
2724     return make(AnyPtr, meet_ptr(tp->ptr()), meet_offset(tp->offset()), speculative, depth);
2725   }
2726   case RawPtr:                  // For these, flip the call around to cut down
2727   case OopPtr:
2728   case InstPtr:                 // on the cases I have to handle.
2729   case AryPtr:
2730   case MetadataPtr:
2731   case KlassPtr:
2732   case InstKlassPtr:
2733   case AryKlassPtr:
2734     return t->xmeet(this);      // Call in reverse direction
2735   default:                      // All else is a mistake
2736     typerr(t);
2737 
2738   }
2739   return this;
2740 }
2741 
2742 //------------------------------meet_offset------------------------------------
2743 Type::Offset TypePtr::meet_offset(int offset) const {
2744   return _offset.meet(Offset(offset));





2745 }
2746 
2747 //------------------------------dual_offset------------------------------------
2748 Type::Offset TypePtr::dual_offset() const {
2749   return _offset.dual();


2750 }
2751 
2752 //------------------------------xdual------------------------------------------
2753 // Dual: compute field-by-field dual
2754 const TypePtr::PTR TypePtr::ptr_dual[TypePtr::lastPTR] = {
2755   BotPTR, NotNull, Constant, Null, AnyNull, TopPTR
2756 };
2757 const Type *TypePtr::xdual() const {
2758   return new TypePtr(AnyPtr, dual_ptr(), dual_offset(), dual_speculative(), dual_inline_depth());
2759 }
2760 
2761 //------------------------------xadd_offset------------------------------------
2762 Type::Offset TypePtr::xadd_offset(intptr_t offset) const {
2763   return _offset.add(offset);











2764 }
2765 
2766 //------------------------------add_offset-------------------------------------
2767 const TypePtr *TypePtr::add_offset( intptr_t offset ) const {
2768   return make(AnyPtr, _ptr, xadd_offset(offset), _speculative, _inline_depth);
2769 }
2770 
2771 const TypePtr *TypePtr::with_offset(intptr_t offset) const {
2772   return make(AnyPtr, _ptr, Offset(offset), _speculative, _inline_depth);
2773 }
2774 
2775 //------------------------------eq---------------------------------------------
2776 // Structural equality check for Type representations
2777 bool TypePtr::eq( const Type *t ) const {
2778   const TypePtr *a = (const TypePtr*)t;
2779   return _ptr == a->ptr() && _offset == a->_offset && eq_speculative(a) && _inline_depth == a->_inline_depth;
2780 }
2781 
2782 //------------------------------hash-------------------------------------------
2783 // Type-specific hashing function.
2784 int TypePtr::hash(void) const {
2785   return java_add(java_add((jint)_ptr, (jint)offset()), java_add((jint)hash_speculative(), (jint)_inline_depth));
2786 ;
2787 }
2788 
2789 /**
2790  * Return same type without a speculative part
2791  */
2792 const TypePtr* TypePtr::remove_speculative() const {
2793   if (_speculative == NULL) {
2794     return this;
2795   }
2796   assert(_inline_depth == InlineDepthTop || _inline_depth == InlineDepthBottom, "non speculative type shouldn't have inline depth");
2797   return make(AnyPtr, _ptr, _offset, NULL, _inline_depth);
2798 }
2799 
2800 /**
2801  * Return same type but drop speculative part if we know we won't use
2802  * it
2803  */
2804 const Type* TypePtr::cleanup_speculative() const {
2805   if (speculative() == NULL) {

2921   if (_speculative == NULL) {
2922     return NULL;
2923   }
2924   return _speculative->add_offset(offset)->is_ptr();
2925 }
2926 
2927 const TypePtr* TypePtr::with_offset_speculative(intptr_t offset) const {
2928   if (_speculative == NULL) {
2929     return NULL;
2930   }
2931   return _speculative->with_offset(offset)->is_ptr();
2932 }
2933 
2934 /**
2935  * return exact klass from the speculative type if there's one
2936  */
2937 ciKlass* TypePtr::speculative_type() const {
2938   if (_speculative != NULL && _speculative->isa_oopptr()) {
2939     const TypeOopPtr* speculative = _speculative->join(this)->is_oopptr();
2940     if (speculative->klass_is_exact()) {
2941       return speculative->exact_klass();
2942     }
2943   }
2944   return NULL;
2945 }
2946 
2947 /**
2948  * return true if speculative type may be null
2949  */
2950 bool TypePtr::speculative_maybe_null() const {
2951   if (_speculative != NULL) {
2952     const TypePtr* speculative = _speculative->join(this)->is_ptr();
2953     return speculative->maybe_null();
2954   }
2955   return true;
2956 }
2957 
2958 bool TypePtr::speculative_always_null() const {
2959   if (_speculative != NULL) {
2960     const TypePtr* speculative = _speculative->join(this)->is_ptr();
2961     return speculative == TypePtr::NULL_PTR;

3032   }
3033   // We already know the speculative type is always null
3034   if (speculative_always_null()) {
3035     return false;
3036   }
3037   if (ptr_kind == ProfileAlwaysNull && speculative() != NULL && speculative()->isa_oopptr()) {
3038     return false;
3039   }
3040   return true;
3041 }
3042 
3043 //------------------------------dump2------------------------------------------
3044 const char *const TypePtr::ptr_msg[TypePtr::lastPTR] = {
3045   "TopPTR","AnyNull","Constant","NULL","NotNull","BotPTR"
3046 };
3047 
3048 #ifndef PRODUCT
3049 void TypePtr::dump2( Dict &d, uint depth, outputStream *st ) const {
3050   if( _ptr == Null ) st->print("NULL");
3051   else st->print("%s *", ptr_msg[_ptr]);
3052   _offset.dump2(st);


3053   dump_inline_depth(st);
3054   dump_speculative(st);
3055 }
3056 
3057 /**
3058  *dump the speculative part of the type
3059  */
3060 void TypePtr::dump_speculative(outputStream *st) const {
3061   if (_speculative != NULL) {
3062     st->print(" (speculative=");
3063     _speculative->dump_on(st);
3064     st->print(")");
3065   }
3066 }
3067 
3068 /**
3069  *dump the inline depth of the type
3070  */
3071 void TypePtr::dump_inline_depth(outputStream *st) const {
3072   if (_inline_depth != InlineDepthBottom) {
3073     if (_inline_depth == InlineDepthTop) {
3074       st->print(" (inline_depth=InlineDepthTop)");
3075     } else {
3076       st->print(" (inline_depth=%d)", _inline_depth);
3077     }
3078   }
3079 }
3080 #endif
3081 
3082 //------------------------------singleton--------------------------------------
3083 // TRUE if Type is a singleton type, FALSE otherwise.   Singletons are simple
3084 // constants
3085 bool TypePtr::singleton(void) const {
3086   // TopPTR, Null, AnyNull, Constant are all singletons
3087   return (_offset != Offset::bottom) && !below_centerline(_ptr);
3088 }
3089 
3090 bool TypePtr::empty(void) const {
3091   return (_offset == Offset::top) || above_centerline(_ptr);
3092 }
3093 
3094 //=============================================================================
3095 // Convenience common pre-built types.
3096 const TypeRawPtr *TypeRawPtr::BOTTOM;
3097 const TypeRawPtr *TypeRawPtr::NOTNULL;
3098 
3099 //------------------------------make-------------------------------------------
3100 const TypeRawPtr *TypeRawPtr::make( enum PTR ptr ) {
3101   assert( ptr != Constant, "what is the constant?" );
3102   assert( ptr != Null, "Use TypePtr for NULL" );
3103   return (TypeRawPtr*)(new TypeRawPtr(ptr,0))->hashcons();
3104 }
3105 
3106 const TypeRawPtr *TypeRawPtr::make( address bits ) {
3107   assert( bits, "Use TypePtr for NULL" );
3108   return (TypeRawPtr*)(new TypeRawPtr(Constant,bits))->hashcons();
3109 }
3110 
3111 //------------------------------cast_to_ptr_type-------------------------------

3444     return _is_loaded;
3445   }
3446   const_cast<InterfaceSet*>(this)->compute_is_loaded();
3447   assert(_is_loaded_computed, "should be computed now");
3448   return _is_loaded;
3449 }
3450 
3451 void TypePtr::InterfaceSet::compute_is_loaded() {
3452   _is_loaded_computed = 1;
3453   for (int i = 0; i < _list.length(); i++) {
3454     ciKlass* interface = _list.at(i);
3455     if (!interface->is_loaded()) {
3456       _is_loaded = false;
3457       return;
3458     }
3459   }
3460   _is_loaded = true;
3461 }
3462 
3463 //------------------------------TypeOopPtr-------------------------------------
3464 TypeOopPtr::TypeOopPtr(TYPES t, PTR ptr, ciKlass* k, const InterfaceSet& interfaces, bool xk, ciObject* o, Offset offset, Offset field_offset,
3465                        int instance_id, const TypePtr* speculative, int inline_depth)
3466   : TypePtr(t, ptr, offset, speculative, inline_depth),
3467     _const_oop(o), _klass(k),
3468     _interfaces(interfaces),
3469     _klass_is_exact(xk),
3470     _is_ptr_to_narrowoop(false),
3471     _is_ptr_to_narrowklass(false),
3472     _is_ptr_to_boxed_value(false),
3473     _instance_id(instance_id) {
3474   if (Compile::current()->eliminate_boxing() && (t == InstPtr) &&
3475       (offset.get() > 0) && xk && (k != 0) && k->is_instance_klass()) {
3476     _is_ptr_to_boxed_value = k->as_instance_klass()->is_boxed_value_offset(offset.get());
3477   }
3478 #ifdef _LP64
3479   if (this->offset() > 0 || this->offset() == Type::OffsetTop || this->offset() == Type::OffsetBot) {
3480     if (this->offset() == oopDesc::klass_offset_in_bytes()) {
3481       _is_ptr_to_narrowklass = UseCompressedClassPointers;
3482     } else if (klass() == NULL) {
3483       // Array with unknown body type
3484       assert(this->isa_aryptr(), "only arrays without klass");
3485       _is_ptr_to_narrowoop = UseCompressedOops;
3486     } else if (UseCompressedOops && this->isa_aryptr() && this->offset() != arrayOopDesc::length_offset_in_bytes()) {
3487       if (klass()->is_obj_array_klass()) {
3488         _is_ptr_to_narrowoop = true;
3489       } else if (klass()->is_flat_array_klass() && field_offset != Offset::top && field_offset != Offset::bottom) {
3490         // Check if the field of the inline type array element contains oops
3491         ciInlineKlass* vk = klass()->as_flat_array_klass()->element_klass()->as_inline_klass();
3492         int foffset = field_offset.get() + vk->first_field_offset();
3493         ciField* field = vk->get_field_by_offset(foffset, false);
3494         assert(field != NULL, "missing field");
3495         BasicType bt = field->layout_type();
3496         _is_ptr_to_narrowoop = UseCompressedOops && ::is_reference_type(bt);
3497       }
3498     } else if (klass()->is_instance_klass()) {


3499       if (this->isa_klassptr()) {
3500         // Perm objects don't use compressed references
3501       } else if (_offset == Offset::bottom || _offset == Offset::top) {
3502         // unsafe access
3503         _is_ptr_to_narrowoop = UseCompressedOops;
3504       } else {
3505         assert(this->isa_instptr(), "must be an instance ptr.");

3506         if (klass() == ciEnv::current()->Class_klass() &&
3507             (this->offset() == java_lang_Class::klass_offset() ||
3508              this->offset() == java_lang_Class::array_klass_offset())) {
3509           // Special hidden fields from the Class.
3510           assert(this->isa_instptr(), "must be an instance ptr.");
3511           _is_ptr_to_narrowoop = false;
3512         } else if (klass() == ciEnv::current()->Class_klass() &&
3513                    this->offset() >= InstanceMirrorKlass::offset_of_static_fields()) {
3514           // Static fields
3515           ciField* field = NULL;
3516           if (const_oop() != NULL) {
3517             ciInstanceKlass* k = const_oop()->as_instance()->java_lang_Class_klass()->as_instance_klass();
3518             if (k->is_inlinetype() && this->offset() == k->as_inline_klass()->default_value_offset()) {
3519               // Special hidden field that contains the oop of the default inline type
3520               // basic_elem_type = T_PRIMITIVE_OBJECT;
3521              _is_ptr_to_narrowoop = UseCompressedOops;
3522             } else {
3523               field = k->get_field_by_offset(this->offset(), true);
3524               if (field != NULL) {
3525                 BasicType basic_elem_type = field->layout_type();
3526                 _is_ptr_to_narrowoop = UseCompressedOops && ::is_reference_type(basic_elem_type);
3527               } else {
3528                 // unsafe access
3529                 _is_ptr_to_narrowoop = UseCompressedOops;
3530               }
3531             }
3532           }
3533         } else {
3534           // Instance fields which contains a compressed oop references.
3535           ciInstanceKlass* ik = klass()->as_instance_klass();
3536           ciField* field = ik->get_field_by_offset(this->offset(), false);
3537           if (field != NULL) {
3538             BasicType basic_elem_type = field->layout_type();
3539             _is_ptr_to_narrowoop = UseCompressedOops && ::is_reference_type(basic_elem_type);
3540           } else if (klass()->equals(ciEnv::current()->Object_klass())) {
3541             // Compile::find_alias_type() cast exactness on all types to verify
3542             // that it does not affect alias type.
3543             _is_ptr_to_narrowoop = UseCompressedOops;
3544           } else {
3545             // Type for the copy start in LibraryCallKit::inline_native_clone().
3546             _is_ptr_to_narrowoop = UseCompressedOops;
3547           }
3548         }
3549       }
3550     }
3551   }
3552 #endif
3553 }
3554 
3555 //------------------------------make-------------------------------------------
3556 const TypeOopPtr *TypeOopPtr::make(PTR ptr, Offset offset, int instance_id,
3557                                    const TypePtr* speculative, int inline_depth) {
3558   assert(ptr != Constant, "no constant generic pointers");
3559   ciKlass*  k = Compile::current()->env()->Object_klass();
3560   bool      xk = false;
3561   ciObject* o = NULL;
3562   return (TypeOopPtr*)(new TypeOopPtr(OopPtr, ptr, k, InterfaceSet(), xk, o, offset, Offset::bottom, instance_id, speculative, inline_depth))->hashcons();
3563 }
3564 
3565 
3566 //------------------------------cast_to_ptr_type-------------------------------
3567 const TypeOopPtr* TypeOopPtr::cast_to_ptr_type(PTR ptr) const {
3568   assert(_base == OopPtr, "subclass must override cast_to_ptr_type");
3569   if( ptr == _ptr ) return this;
3570   return make(ptr, _offset, _instance_id, _speculative, _inline_depth);
3571 }
3572 
3573 //-----------------------------cast_to_instance_id----------------------------
3574 const TypeOopPtr *TypeOopPtr::cast_to_instance_id(int instance_id) const {
3575   // There are no instances of a general oop.
3576   // Return self unchanged.
3577   return this;
3578 }
3579 
3580 //-----------------------------cast_to_exactness-------------------------------
3581 const TypeOopPtr* TypeOopPtr::cast_to_exactness(bool klass_is_exact) const {
3582   // There is no such thing as an exact general oop.
3583   // Return self unchanged.
3584   return this;
3585 }
3586 

3587 //------------------------------as_klass_type----------------------------------
3588 // Return the klass type corresponding to this instance or array type.
3589 // It is the type that is loaded from an object of this type.
3590 const TypeKlassPtr* TypeOopPtr::as_klass_type(bool try_for_exact) const {
3591   ShouldNotReachHere();
3592   return NULL;
3593 }
3594 
3595 //------------------------------meet-------------------------------------------
3596 // Compute the MEET of two types.  It returns a new Type object.
3597 const Type *TypeOopPtr::xmeet_helper(const Type *t) const {
3598   // Perform a fast test for common case; meeting the same types together.
3599   if( this == t ) return this;  // Meeting same type-rep?
3600 
3601   // Current "this->_base" is OopPtr
3602   switch (t->base()) {          // switch on original type
3603 
3604   case Int:                     // Mixing ints & oops happens when javac
3605   case Long:                    // reuses local variables
3606   case FloatTop:

3612   case NarrowOop:
3613   case NarrowKlass:
3614   case Bottom:                  // Ye Olde Default
3615     return Type::BOTTOM;
3616   case Top:
3617     return this;
3618 
3619   default:                      // All else is a mistake
3620     typerr(t);
3621 
3622   case RawPtr:
3623   case MetadataPtr:
3624   case KlassPtr:
3625   case InstKlassPtr:
3626   case AryKlassPtr:
3627     return TypePtr::BOTTOM;     // Oop meet raw is not well defined
3628 
3629   case AnyPtr: {
3630     // Found an AnyPtr type vs self-OopPtr type
3631     const TypePtr *tp = t->is_ptr();
3632     Offset offset = meet_offset(tp->offset());
3633     PTR ptr = meet_ptr(tp->ptr());
3634     const TypePtr* speculative = xmeet_speculative(tp);
3635     int depth = meet_inline_depth(tp->inline_depth());
3636     switch (tp->ptr()) {
3637     case Null:
3638       if (ptr == Null)  return TypePtr::make(AnyPtr, ptr, offset, speculative, depth);
3639       // else fall through:
3640     case TopPTR:
3641     case AnyNull: {
3642       int instance_id = meet_instance_id(InstanceTop);
3643       return make(ptr, offset, instance_id, speculative, depth);
3644     }
3645     case BotPTR:
3646     case NotNull:
3647       return TypePtr::make(AnyPtr, ptr, offset, speculative, depth);
3648     default: typerr(t);
3649     }
3650   }
3651 
3652   case OopPtr: {                 // Meeting to other OopPtrs

3654     int instance_id = meet_instance_id(tp->instance_id());
3655     const TypePtr* speculative = xmeet_speculative(tp);
3656     int depth = meet_inline_depth(tp->inline_depth());
3657     return make(meet_ptr(tp->ptr()), meet_offset(tp->offset()), instance_id, speculative, depth);
3658   }
3659 
3660   case InstPtr:                  // For these, flip the call around to cut down
3661   case AryPtr:
3662     return t->xmeet(this);      // Call in reverse direction
3663 
3664   } // End of switch
3665   return this;                  // Return the double constant
3666 }
3667 
3668 
3669 //------------------------------xdual------------------------------------------
3670 // Dual of a pure heap pointer.  No relevant klass or oop information.
3671 const Type *TypeOopPtr::xdual() const {
3672   assert(klass() == Compile::current()->env()->Object_klass(), "no klasses here");
3673   assert(const_oop() == NULL,             "no constants here");
3674   return new TypeOopPtr(_base, dual_ptr(), klass(), _interfaces, klass_is_exact(), const_oop(), dual_offset(), Offset::bottom, dual_instance_id(), dual_speculative(), dual_inline_depth());
3675 }
3676 
3677 //--------------------------make_from_klass_common-----------------------------
3678 // Computes the element-type given a klass.
3679 const TypeOopPtr* TypeOopPtr::make_from_klass_common(ciKlass *klass, bool klass_change, bool try_for_exact, InterfaceHandling interface_handling) {
3680   if (klass->is_instance_klass() || klass->is_inlinetype()) {
3681     Compile* C = Compile::current();
3682     Dependencies* deps = C->dependencies();
3683     assert((deps != NULL) == (C->method() != NULL && C->method()->code_size() > 0), "sanity");
3684     // Element is an instance
3685     bool klass_is_exact = false;
3686     if (klass->is_loaded()) {
3687       // Try to set klass_is_exact.
3688       ciInstanceKlass* ik = klass->as_instance_klass();
3689       klass_is_exact = ik->is_final();
3690       if (!klass_is_exact && klass_change
3691           && deps != NULL && UseUniqueSubclasses) {
3692         ciInstanceKlass* sub = ik->unique_concrete_subklass();
3693         if (sub != NULL) {
3694           deps->assert_abstract_with_unique_concrete_subtype(ik, sub);
3695           klass = ik = sub;
3696           klass_is_exact = sub->is_final();
3697         }
3698       }
3699       if (!klass_is_exact && try_for_exact && deps != NULL &&
3700           !ik->is_interface() && !ik->has_subklass()) {
3701         // Add a dependence; if concrete subclass added we need to recompile
3702         deps->assert_leaf_type(ik);
3703         klass_is_exact = true;
3704       }
3705     }
3706     const TypePtr::InterfaceSet interfaces = TypePtr::interfaces(klass, true, true, false, interface_handling);
3707     return TypeInstPtr::make(TypePtr::BotPTR, klass, interfaces, klass_is_exact, NULL, Offset(0));
3708   } else if (klass->is_obj_array_klass()) {
3709     // Element is an object or inline type array. Recursively call ourself.
3710     const TypeOopPtr* etype = TypeOopPtr::make_from_klass_common(klass->as_array_klass()->element_klass(), /* klass_change= */ false, try_for_exact, interface_handling);
3711     bool null_free = klass->as_array_klass()->is_elem_null_free();
3712     if (null_free) {
3713       etype = etype->join_speculative(TypePtr::NOTNULL)->is_oopptr();
3714     }
3715     // Determine null-free/flattened properties
3716     const TypeOopPtr* exact_etype = etype;
3717     if (etype->can_be_inline_type()) {
3718       // Use exact type if element can be an inline type
3719       exact_etype = TypeOopPtr::make_from_klass_common(klass->as_array_klass()->element_klass(), /* klass_change= */ true, /* try_for_exact= */ true, interface_handling);
3720     }
3721     bool not_null_free = !exact_etype->can_be_inline_type();
3722     bool not_flat = !UseFlatArray || not_null_free || (exact_etype->is_inlinetypeptr() && !exact_etype->inline_klass()->flatten_array());
3723 
3724     // Even if MyValue is exact, [LMyValue is not exact due to [QMyValue <: [LMyValue.
3725     bool xk = etype->klass_is_exact() && (!etype->is_inlinetypeptr() || null_free);
3726     const TypeAry* arr0 = TypeAry::make(etype, TypeInt::POS, /* stable= */ false, /* flat= */ false, not_flat, not_null_free);
3727     // We used to pass NotNull in here, asserting that the sub-arrays
3728     // are all not-null.  This is not true in generally, as code can
3729     // slam NULLs down in the subarrays.
3730     const TypeAryPtr* arr = TypeAryPtr::make(TypePtr::BotPTR, arr0, NULL, xk, Offset(0));
3731     return arr;
3732   } else if (klass->is_type_array_klass()) {
3733     // Element is an typeArray
3734     const Type* etype = get_const_basic_type(klass->as_type_array_klass()->element_type());
3735     const TypeAry* arr0 = TypeAry::make(etype, TypeInt::POS,
3736                                         /* stable= */ false, /* flat= */ false, /* not_flat= */ true, /* not_null_free= */ true);
3737     // We used to pass NotNull in here, asserting that the array pointer
3738     // is not-null. That was not true in general.
3739     const TypeAryPtr* arr = TypeAryPtr::make(TypePtr::BotPTR, arr0, klass, true, Offset(0));
3740     return arr;
3741   } else if (klass->is_flat_array_klass()) {
3742     const TypeOopPtr* etype = TypeOopPtr::make_from_klass_raw(klass->as_array_klass()->element_klass(), trust_interfaces);
3743     etype = etype->join_speculative(TypePtr::NOTNULL)->is_oopptr();
3744     const TypeAry* arr0 = TypeAry::make(etype, TypeInt::POS, /* stable= */ false, /* flat= */ true);
3745     const TypeAryPtr* arr = TypeAryPtr::make(TypePtr::BotPTR, arr0, klass, true, Offset(0));
3746     return arr;
3747   } else {
3748     ShouldNotReachHere();
3749     return NULL;
3750   }
3751 }
3752 
3753 //------------------------------make_from_constant-----------------------------
3754 // Make a java pointer from an oop constant
3755 const TypeOopPtr* TypeOopPtr::make_from_constant(ciObject* o, bool require_constant) {
3756   assert(!o->is_null_object(), "null object not yet handled here.");
3757 
3758   const bool make_constant = require_constant || o->should_be_constant();
3759 
3760   ciKlass* klass = o->klass();
3761   if (klass->is_instance_klass() || klass->is_inlinetype()) {
3762     // Element is an instance or inline type
3763     if (make_constant) {
3764       return TypeInstPtr::make(o);
3765     } else {
3766       return TypeInstPtr::make(TypePtr::NotNull, klass, true, NULL, Offset(0));
3767     }
3768   } else if (klass->is_obj_array_klass()) {
3769     // Element is an object array. Recursively call ourself.
3770     const TypeOopPtr* etype = TypeOopPtr::make_from_klass_raw(klass->as_array_klass()->element_klass(), trust_interfaces);
3771     bool null_free = false;
3772     if (klass->as_array_klass()->is_elem_null_free()) {
3773       null_free = true;
3774       etype = etype->join_speculative(TypePtr::NOTNULL)->is_oopptr();
3775     }
3776     const TypeAry* arr0 = TypeAry::make(etype, TypeInt::make(o->as_array()->length()),
3777                                         /* stable= */ false, /* flat= */ false, /* not_flat= */ true, /* not_null_free= */ !null_free);
3778     // We used to pass NotNull in here, asserting that the sub-arrays
3779     // are all not-null.  This is not true in generally, as code can
3780     // slam NULLs down in the subarrays.
3781     if (make_constant) {
3782       return TypeAryPtr::make(TypePtr::Constant, o, arr0, klass, true, Offset(0));
3783     } else {
3784       return TypeAryPtr::make(TypePtr::NotNull, arr0, klass, true, Offset(0));
3785     }
3786   } else if (klass->is_type_array_klass()) {
3787     // Element is an typeArray
3788     const Type* etype = (Type*)get_const_basic_type(klass->as_type_array_klass()->element_type());
3789     const TypeAry* arr0 = TypeAry::make(etype, TypeInt::make(o->as_array()->length()),
3790                                         /* stable= */ false, /* flat= */ false, /* not_flat= */ true, /* not_null_free= */ true);
3791     // We used to pass NotNull in here, asserting that the array pointer
3792     // is not-null. That was not true in general.
3793     if (make_constant) {
3794       return TypeAryPtr::make(TypePtr::Constant, o, arr0, klass, true, Offset(0));
3795     } else {
3796       return TypeAryPtr::make(TypePtr::NotNull, arr0, klass, true, Offset(0));
3797     }
3798   } else if (klass->is_flat_array_klass()) {
3799     const TypeOopPtr* etype = TypeOopPtr::make_from_klass_raw(klass->as_array_klass()->element_klass(), trust_interfaces);
3800     etype = etype->join_speculative(TypePtr::NOTNULL)->is_oopptr();
3801     const TypeAry* arr0 = TypeAry::make(etype, TypeInt::make(o->as_array()->length()), /* stable= */ false, /* flat= */ true);
3802     // We used to pass NotNull in here, asserting that the sub-arrays
3803     // are all not-null.  This is not true in generally, as code can
3804     // slam NULLs down in the subarrays.
3805     if (make_constant) {
3806       return TypeAryPtr::make(TypePtr::Constant, o, arr0, klass, true, Offset(0));
3807     } else {
3808       return TypeAryPtr::make(TypePtr::NotNull, arr0, klass, true, Offset(0));
3809     }
3810   }
3811 
3812   fatal("unhandled object type");
3813   return NULL;
3814 }
3815 
3816 //------------------------------get_con----------------------------------------
3817 intptr_t TypeOopPtr::get_con() const {
3818   assert( _ptr == Null || _ptr == Constant, "" );
3819   assert(offset() >= 0, "");
3820 
3821   if (offset() != 0) {
3822     // After being ported to the compiler interface, the compiler no longer
3823     // directly manipulates the addresses of oops.  Rather, it only has a pointer
3824     // to a handle at compile time.  This handle is embedded in the generated
3825     // code and dereferenced at the time the nmethod is made.  Until that time,
3826     // it is not reasonable to do arithmetic with the addresses of oops (we don't
3827     // have access to the addresses!).  This does not seem to currently happen,
3828     // but this assertion here is to help prevent its occurrence.
3829     tty->print_cr("Found oop constant with non-zero offset");
3830     ShouldNotReachHere();
3831   }
3832 
3833   return (intptr_t)const_oop()->constant_encoding();
3834 }
3835 
3836 
3837 //-----------------------------filter------------------------------------------
3838 // Do not allow interface-vs.-noninterface joins to collapse to top.
3839 const Type *TypeOopPtr::filter_helper(const Type *kills, bool include_speculative) const {
3840 
3841   const Type* ft = join_helper(kills, include_speculative);

3861     return (one == two) && TypePtr::eq(t);
3862   } else {
3863     return one->equals(two) && TypePtr::eq(t);
3864   }
3865 }
3866 
3867 //------------------------------hash-------------------------------------------
3868 // Type-specific hashing function.
3869 int TypeOopPtr::hash(void) const {
3870   return
3871     java_add(java_add((jint)(const_oop() ? const_oop()->hash() : 0), (jint)_klass_is_exact),
3872              java_add((jint)_instance_id, (jint)TypePtr::hash()));
3873 }
3874 
3875 //------------------------------dump2------------------------------------------
3876 #ifndef PRODUCT
3877 void TypeOopPtr::dump2( Dict &d, uint depth, outputStream *st ) const {
3878   st->print("oopptr:%s", ptr_msg[_ptr]);
3879   if( _klass_is_exact ) st->print(":exact");
3880   if( const_oop() ) st->print(INTPTR_FORMAT, p2i(const_oop()));
3881   _offset.dump2(st);





3882   if (_instance_id == InstanceTop)
3883     st->print(",iid=top");
3884   else if (_instance_id != InstanceBot)
3885     st->print(",iid=%d",_instance_id);
3886 
3887   dump_inline_depth(st);
3888   dump_speculative(st);
3889 }
3890 #endif
3891 
3892 //------------------------------singleton--------------------------------------
3893 // TRUE if Type is a singleton type, FALSE otherwise.   Singletons are simple
3894 // constants
3895 bool TypeOopPtr::singleton(void) const {
3896   // detune optimizer to not generate constant oop + constant offset as a constant!
3897   // TopPTR, Null, AnyNull, Constant are all singletons
3898   return (offset() == 0) && !below_centerline(_ptr);
3899 }
3900 
3901 //------------------------------add_offset-------------------------------------
3902 const TypePtr* TypeOopPtr::add_offset(intptr_t offset) const {
3903   return make(_ptr, xadd_offset(offset), _instance_id, add_offset_speculative(offset), _inline_depth);
3904 }
3905 
3906 const TypeOopPtr* TypeOopPtr::with_offset(intptr_t offset) const {
3907   return make(_ptr, Offset(offset), _instance_id, with_offset_speculative(offset), _inline_depth);
3908 }
3909 
3910 /**
3911  * Return same type without a speculative part
3912  */
3913 const TypeOopPtr* TypeOopPtr::remove_speculative() const {
3914   if (_speculative == NULL) {
3915     return this;
3916   }
3917   assert(_inline_depth == InlineDepthTop || _inline_depth == InlineDepthBottom, "non speculative type shouldn't have inline depth");
3918   return make(_ptr, _offset, _instance_id, NULL, _inline_depth);
3919 }
3920 
3921 /**
3922  * Return same type but drop speculative part if we know we won't use
3923  * it
3924  */
3925 const Type* TypeOopPtr::cleanup_speculative() const {
3926   // If the klass is exact and the ptr is not null then there's
3927   // nothing that the speculative type can help us with

4002 const TypeInstPtr *TypeInstPtr::MARK;
4003 const TypeInstPtr *TypeInstPtr::KLASS;
4004 
4005 // Is there a single ciKlass* that can represent that type?
4006 ciKlass* TypeInstPtr::exact_klass_helper() const {
4007   if (_interfaces.empty()) {
4008     return _klass;
4009   }
4010   if (_klass != ciEnv::current()->Object_klass()) {
4011     ciKlass* k = _klass;
4012     const TypePtr::InterfaceSet interfaces = TypePtr::interfaces(k, true, false, false, ignore_interfaces);
4013     if (_interfaces.eq(interfaces)) {
4014       return _klass;
4015     }
4016     return NULL;
4017   }
4018   return _interfaces.exact_klass();
4019 }
4020 
4021 //------------------------------TypeInstPtr-------------------------------------
4022 TypeInstPtr::TypeInstPtr(PTR ptr, ciKlass* k, const InterfaceSet& interfaces, bool xk, ciObject* o, Offset off,
4023                          bool flatten_array, int instance_id, const TypePtr* speculative, int inline_depth)
4024   : TypeOopPtr(InstPtr, ptr, k, interfaces, xk, o, off, Offset::bottom, instance_id, speculative, inline_depth),
4025     _flatten_array(flatten_array) {
4026   assert(k == NULL || !k->is_loaded() || !k->is_interface(), "no interface here");
4027   assert(k != NULL &&
4028          (k->is_loaded() || o == NULL),
4029          "cannot have constants with non-loaded klass");
4030   assert(!klass()->flatten_array() || flatten_array, "Should be flat in array");
4031   assert(!flatten_array || can_be_inline_type(), "Only inline types can be flat in array");
4032 };
4033 
4034 //------------------------------make-------------------------------------------
4035 const TypeInstPtr *TypeInstPtr::make(PTR ptr,
4036                                      ciKlass* k,
4037                                      const InterfaceSet& interfaces,
4038                                      bool xk,
4039                                      ciObject* o,
4040                                      Offset offset,
4041                                      bool flatten_array,
4042                                      int instance_id,
4043                                      const TypePtr* speculative,
4044                                      int inline_depth) {
4045   assert( !k->is_loaded() || k->is_instance_klass(), "Must be for instance");
4046   // Either const_oop() is NULL or else ptr is Constant
4047   assert( (!o && ptr != Constant) || (o && ptr == Constant),
4048           "constant pointers must have a value supplied" );
4049   // Ptr is never Null
4050   assert( ptr != Null, "NULL pointers are not typed" );
4051 
4052   assert(instance_id <= 0 || xk, "instances are always exactly typed");
4053   if (ptr == Constant) {
4054     // Note:  This case includes meta-object constants, such as methods.
4055     xk = true;
4056   } else if (k->is_loaded()) {
4057     ciInstanceKlass* ik = k->as_instance_klass();
4058     if (!xk && ik->is_final())     xk = true;   // no inexact final klass
4059     assert(!ik->is_interface(), "no interface here");
4060     if (xk && ik->is_interface())  xk = false;  // no exact interface
4061   }
4062 
4063   // Check if this type is known to be flat in arrays
4064   flatten_array = flatten_array || k->flatten_array();
4065 
4066   // Now hash this baby
4067   TypeInstPtr *result =
4068     (TypeInstPtr*)(new TypeInstPtr(ptr, k, interfaces, xk, o, offset, flatten_array, instance_id, speculative, inline_depth))->hashcons();
4069 
4070   return result;
4071 }
4072 
4073 TypePtr::InterfaceSet TypePtr::interfaces(ciKlass*& k, bool klass, bool interface, bool array, InterfaceHandling interface_handling) {
4074   if (k->is_instance_klass()) {
4075     if (k->is_loaded()) {
4076       if (k->is_interface() && interface_handling == ignore_interfaces) {
4077         assert(interface, "no interface expected");
4078         k = ciEnv::current()->Object_klass();
4079         InterfaceSet interfaces;
4080         return interfaces;
4081       }
4082       GrowableArray<ciInstanceKlass *> *k_interfaces = k->as_instance_klass()->transitive_interfaces();
4083       InterfaceSet interfaces(k_interfaces);
4084       if (k->is_interface()) {
4085         assert(interface, "no interface expected");
4086         k = ciEnv::current()->Object_klass();
4087       } else {
4088         assert(klass, "no instance klass expected");

4114   switch (bt) {
4115     case T_BOOLEAN:  return TypeInt::make(constant.as_boolean());
4116     case T_INT:      return TypeInt::make(constant.as_int());
4117     case T_CHAR:     return TypeInt::make(constant.as_char());
4118     case T_BYTE:     return TypeInt::make(constant.as_byte());
4119     case T_SHORT:    return TypeInt::make(constant.as_short());
4120     case T_FLOAT:    return TypeF::make(constant.as_float());
4121     case T_DOUBLE:   return TypeD::make(constant.as_double());
4122     case T_LONG:     return TypeLong::make(constant.as_long());
4123     default:         break;
4124   }
4125   fatal("Invalid boxed value type '%s'", type2name(bt));
4126   return NULL;
4127 }
4128 
4129 //------------------------------cast_to_ptr_type-------------------------------
4130 const TypeInstPtr* TypeInstPtr::cast_to_ptr_type(PTR ptr) const {
4131   if( ptr == _ptr ) return this;
4132   // Reconstruct _sig info here since not a problem with later lazy
4133   // construction, _sig will show up on demand.
4134   return make(ptr, klass(), _interfaces, klass_is_exact(), ptr == Constant ? const_oop() : NULL, _offset, _flatten_array, _instance_id, _speculative, _inline_depth);
4135 }
4136 
4137 
4138 //-----------------------------cast_to_exactness-------------------------------
4139 const TypeInstPtr* TypeInstPtr::cast_to_exactness(bool klass_is_exact) const {
4140   if( klass_is_exact == _klass_is_exact ) return this;
4141   if (!_klass->is_loaded())  return this;
4142   ciInstanceKlass* ik = _klass->as_instance_klass();
4143   if( (ik->is_final() || _const_oop) )  return this;  // cannot clear xk
4144   assert(!ik->is_interface(), "no interface here");
4145   return make(ptr(), klass(), _interfaces, klass_is_exact, const_oop(), _offset, _flatten_array, _instance_id, _speculative, _inline_depth);
4146 }
4147 
4148 //-----------------------------cast_to_instance_id----------------------------
4149 const TypeInstPtr* TypeInstPtr::cast_to_instance_id(int instance_id) const {
4150   if( instance_id == _instance_id ) return this;
4151   return make(_ptr, klass(), _interfaces, _klass_is_exact, const_oop(), _offset, _flatten_array, instance_id, _speculative, _inline_depth);
4152 }
4153 
4154 //------------------------------xmeet_unloaded---------------------------------
4155 // Compute the MEET of two InstPtrs when at least one is unloaded.
4156 // Assume classes are different since called after check for same name/class-loader
4157 const TypeInstPtr *TypeInstPtr::xmeet_unloaded(const TypeInstPtr *tinst, const InterfaceSet& interfaces) const {
4158   Offset off = meet_offset(tinst->offset());
4159   PTR ptr = meet_ptr(tinst->ptr());
4160   int instance_id = meet_instance_id(tinst->instance_id());
4161   const TypePtr* speculative = xmeet_speculative(tinst);
4162   int depth = meet_inline_depth(tinst->inline_depth());
4163 
4164   const TypeInstPtr *loaded    = is_loaded() ? this  : tinst;
4165   const TypeInstPtr *unloaded  = is_loaded() ? tinst : this;
4166   if( loaded->klass()->equals(ciEnv::current()->Object_klass()) ) {
4167     //
4168     // Meet unloaded class with java/lang/Object
4169     //
4170     // Meet
4171     //          |                     Unloaded Class
4172     //  Object  |   TOP    |   AnyNull | Constant |   NotNull |  BOTTOM   |
4173     //  ===================================================================
4174     //   TOP    | ..........................Unloaded......................|
4175     //  AnyNull |  U-AN    |................Unloaded......................|
4176     // Constant | ... O-NN .................................. |   O-BOT   |
4177     //  NotNull | ... O-NN .................................. |   O-BOT   |
4178     //  BOTTOM  | ........................Object-BOTTOM ..................|
4179     //
4180     assert(loaded->ptr() != TypePtr::Null, "insanity check");
4181     //
4182     if (loaded->ptr() == TypePtr::TopPTR)        { return unloaded; }
4183     else if (loaded->ptr() == TypePtr::AnyNull)  { return make(ptr, unloaded->klass(), interfaces, false, NULL, off, false, instance_id, speculative, depth); }
4184     else if (loaded->ptr() == TypePtr::BotPTR)   { return TypeInstPtr::BOTTOM; }
4185     else if (loaded->ptr() == TypePtr::Constant || loaded->ptr() == TypePtr::NotNull) {
4186       if (unloaded->ptr() == TypePtr::BotPTR)    { return TypeInstPtr::BOTTOM;  }
4187       else                                       { return TypeInstPtr::NOTNULL; }
4188     }
4189     else if (unloaded->ptr() == TypePtr::TopPTR) { return unloaded; }
4190 
4191     return unloaded->cast_to_ptr_type(TypePtr::AnyNull)->is_instptr();
4192   }
4193 
4194   // Both are unloaded, not the same class, not Object
4195   // Or meet unloaded with a different loaded class, not java/lang/Object
4196   if (ptr != TypePtr::BotPTR) {
4197     return TypeInstPtr::NOTNULL;
4198   }
4199   return TypeInstPtr::BOTTOM;
4200 }
4201 
4202 
4203 //------------------------------meet-------------------------------------------

4224   case Top:
4225     return this;
4226 
4227   default:                      // All else is a mistake
4228     typerr(t);
4229 
4230   case MetadataPtr:
4231   case KlassPtr:
4232   case InstKlassPtr:
4233   case AryKlassPtr:
4234   case RawPtr: return TypePtr::BOTTOM;
4235 
4236   case AryPtr: {                // All arrays inherit from Object class
4237     // Call in reverse direction to avoid duplication
4238     return t->is_aryptr()->xmeet_helper(this);
4239   }
4240 
4241   case OopPtr: {                // Meeting to OopPtrs
4242     // Found a OopPtr type vs self-InstPtr type
4243     const TypeOopPtr *tp = t->is_oopptr();
4244     Offset offset = meet_offset(tp->offset());
4245     PTR ptr = meet_ptr(tp->ptr());
4246     switch (tp->ptr()) {
4247     case TopPTR:
4248     case AnyNull: {
4249       int instance_id = meet_instance_id(InstanceTop);
4250       const TypePtr* speculative = xmeet_speculative(tp);
4251       int depth = meet_inline_depth(tp->inline_depth());
4252       return make(ptr, klass(), _interfaces, klass_is_exact(),
4253                   (ptr == Constant ? const_oop() : NULL), offset, flatten_array(), instance_id, speculative, depth);
4254     }
4255     case NotNull:
4256     case BotPTR: {
4257       int instance_id = meet_instance_id(tp->instance_id());
4258       const TypePtr* speculative = xmeet_speculative(tp);
4259       int depth = meet_inline_depth(tp->inline_depth());
4260       return TypeOopPtr::make(ptr, offset, instance_id, speculative, depth);
4261     }
4262     default: typerr(t);
4263     }
4264   }
4265 
4266   case AnyPtr: {                // Meeting to AnyPtrs
4267     // Found an AnyPtr type vs self-InstPtr type
4268     const TypePtr *tp = t->is_ptr();
4269     Offset offset = meet_offset(tp->offset());
4270     PTR ptr = meet_ptr(tp->ptr());
4271     int instance_id = meet_instance_id(InstanceTop);
4272     const TypePtr* speculative = xmeet_speculative(tp);
4273     int depth = meet_inline_depth(tp->inline_depth());
4274     switch (tp->ptr()) {
4275     case Null:
4276       if( ptr == Null ) return TypePtr::make(AnyPtr, ptr, offset, speculative, depth);
4277       // else fall through to AnyNull
4278     case TopPTR:
4279     case AnyNull: {
4280       return make(ptr, klass(), _interfaces, klass_is_exact(),
4281                   (ptr == Constant ? const_oop() : NULL), offset, flatten_array(), instance_id, speculative, depth);
4282     }
4283     case NotNull:
4284     case BotPTR:
4285       return TypePtr::make(AnyPtr, ptr, offset, speculative,depth);
4286     default: typerr(t);
4287     }
4288   }
4289 
4290   /*
4291                  A-top         }
4292                /   |   \       }  Tops
4293            B-top A-any C-top   }
4294               | /  |  \ |      }  Any-nulls
4295            B-any   |   C-any   }
4296               |    |    |
4297            B-con A-con C-con   } constants; not comparable across classes
4298               |    |    |
4299            B-not   |   C-not   }
4300               | \  |  / |      }  not-nulls
4301            B-bot A-not C-bot   }
4302                \   |   /       }  Bottoms
4303                  A-bot         }
4304   */
4305 
4306   case InstPtr: {                // Meeting 2 Oops?
4307     // Found an InstPtr sub-type vs self-InstPtr type
4308     const TypeInstPtr *tinst = t->is_instptr();
4309     Offset off = meet_offset(tinst->offset());
4310     PTR ptr = meet_ptr(tinst->ptr());
4311     int instance_id = meet_instance_id(tinst->instance_id());
4312     const TypePtr* speculative = xmeet_speculative(tinst);
4313     int depth = meet_inline_depth(tinst->inline_depth());
4314     InterfaceSet interfaces = meet_interfaces(tinst);
4315 
4316     ciKlass* tinst_klass = tinst->klass();
4317     ciKlass* this_klass  = klass();
4318 
4319     ciKlass* res_klass = NULL;
4320     bool res_xk = false;
4321     bool res_flatten_array = false;
4322     const Type* res;
4323     MeetResult kind = meet_instptr(ptr, interfaces, this, tinst, res_klass, res_xk, res_flatten_array);
4324 
4325     if (kind == UNLOADED) {
4326       // One of these classes has not been loaded
4327       const TypeInstPtr* unloaded_meet = xmeet_unloaded(tinst, interfaces);
4328 #ifndef PRODUCT
4329       if (PrintOpto && Verbose) {
4330         tty->print("meet of unloaded classes resulted in: ");
4331         unloaded_meet->dump();
4332         tty->cr();
4333         tty->print("  this == ");
4334         dump();
4335         tty->cr();
4336         tty->print(" tinst == ");
4337         tinst->dump();
4338         tty->cr();
4339       }
4340 #endif
4341       res = unloaded_meet;
4342     } else {
4343       if (kind == NOT_SUBTYPE && instance_id > 0) {
4344         instance_id = InstanceBot;
4345       } else if (kind == LCA) {
4346         instance_id = InstanceBot;
4347       }
4348       ciObject* o = NULL;             // Assume not constant when done
4349       ciObject* this_oop = const_oop();
4350       ciObject* tinst_oop = tinst->const_oop();
4351       if (ptr == Constant) {
4352         if (this_oop != NULL && tinst_oop != NULL &&
4353             this_oop->equals(tinst_oop))
4354           o = this_oop;
4355         else if (above_centerline(_ptr)) {
4356           assert(!tinst_klass->is_interface(), "");
4357           o = tinst_oop;
4358         } else if (above_centerline(tinst->_ptr)) {
4359           assert(!this_klass->is_interface(), "");
4360           o = this_oop;
4361         } else
4362           ptr = NotNull;
4363       }
4364       res = make(ptr, res_klass, interfaces, res_xk, o, off, res_flatten_array, instance_id, speculative, depth);
4365     }
4366 
4367     return res;
4368 
4369   } // End of case InstPtr
4370 
4371   } // End of switch
4372   return this;                  // Return the double constant
4373 }
4374 
4375 template<class T> TypePtr::MeetResult TypePtr::meet_instptr(PTR& ptr, InterfaceSet& interfaces, const T* this_type, const T* other_type,
4376                                                             ciKlass*& res_klass, bool& res_xk, bool& res_flatten_array) {
4377   ciKlass* this_klass = this_type->klass();
4378   ciKlass* other_klass = other_type->klass();
4379   bool this_flatten_array = this_type->flatten_array();
4380   bool other_flatten_array = other_type->flatten_array();
4381   bool this_flatten_array_orig = this_flatten_array;
4382   bool other_flatten_array_orig = other_flatten_array;
4383   bool this_xk = this_type->klass_is_exact();
4384   bool other_xk = other_type->klass_is_exact();
4385   PTR this_ptr = this_type->ptr();
4386   PTR other_ptr = other_type->ptr();
4387   InterfaceSet this_interfaces = this_type->interfaces();
4388   InterfaceSet other_interfaces = other_type->interfaces();
4389   // Check for easy case; klasses are equal (and perhaps not loaded!)
4390   // If we have constants, then we created oops so classes are loaded
4391   // and we can handle the constants further down.  This case handles
4392   // both-not-loaded or both-loaded classes
4393   if (ptr != Constant && this_klass->equals(other_klass) && this_xk == other_xk && this_flatten_array == other_flatten_array) {
4394     res_klass = this_klass;
4395     res_xk = this_xk;
4396     res_flatten_array = this_flatten_array;
4397     return QUICK;
4398   }
4399 
4400   // Classes require inspection in the Java klass hierarchy.  Must be loaded.
4401   if (!other_klass->is_loaded() || !this_klass->is_loaded()) {
4402     return UNLOADED;
4403   }
4404 
4405   // !!! Here's how the symmetry requirement breaks down into invariants:
4406   // If we split one up & one down AND they subtype, take the down man.
4407   // If we split one up & one down AND they do NOT subtype, "fall hard".
4408   // If both are up and they subtype, take the subtype class.
4409   // If both are up and they do NOT subtype, "fall hard".
4410   // If both are down and they subtype, take the supertype class.
4411   // If both are down and they do NOT subtype, "fall hard".
4412   // Constants treated as down.
4413 
4414   // Now, reorder the above list; observe that both-down+subtype is also
4415   // "fall hard"; "fall hard" becomes the default case:
4416   // If we split one up & one down AND they subtype, take the down man.
4417   // If both are up and they subtype, take the subtype class.
4418 
4419   // If both are down and they subtype, "fall hard".
4420   // If both are down and they do NOT subtype, "fall hard".
4421   // If both are up and they do NOT subtype, "fall hard".
4422   // If we split one up & one down AND they do NOT subtype, "fall hard".
4423 
4424   // If a proper subtype is exact, and we return it, we return it exactly.
4425   // If a proper supertype is exact, there can be no subtyping relationship!
4426   // If both types are equal to the subtype, exactness is and-ed below the
4427   // centerline and or-ed above it.  (N.B. Constants are always exact.)
4428 
4429   // Check for subtyping:
4430   const T* subtype = NULL;
4431   bool subtype_exact = false;
4432   bool flat_array = false;
4433   InterfaceSet subtype_interfaces;

4434   if (this_type->is_same_java_type_as(other_type)) {
4435     subtype = this_type;
4436     subtype_exact = below_centerline(ptr) ? (this_xk && other_xk) : (this_xk || other_xk);
4437     flat_array = below_centerline(ptr) ? (this_flatten_array && other_flatten_array) : (this_flatten_array || other_flatten_array);
4438   } else if (!other_xk && this_type->is_meet_subtype_of(other_type) && (!other_flatten_array || this_flatten_array)) {
4439     subtype = this_type;     // Pick subtyping class
4440     subtype_exact = this_xk;
4441     flat_array = this_flatten_array;
4442   } else if (!this_xk && other_type->is_meet_subtype_of(this_type) && (!this_flatten_array || other_flatten_array)) {
4443     subtype = other_type;    // Pick subtyping class
4444     subtype_exact = other_xk;
4445     flat_array = other_flatten_array;
4446   }
4447 
4448   if (subtype) {
4449     if (above_centerline(ptr)) { // both are up?
4450       this_type = other_type = subtype;
4451       this_xk = other_xk = subtype_exact;
4452       this_flatten_array = other_flatten_array = flat_array;
4453     } else if (above_centerline(this_ptr) && !above_centerline(other_ptr)) {
4454       this_type = other_type; // tinst is down; keep down man
4455       this_xk = other_xk;
4456       this_flatten_array = other_flatten_array;
4457     } else if (above_centerline(other_ptr) && !above_centerline(this_ptr)) {
4458       other_type = this_type; // this is down; keep down man
4459       other_xk = this_xk;
4460       other_flatten_array = this_flatten_array;
4461     } else {
4462       this_xk = subtype_exact;  // either they are equal, or we'll do an LCA
4463       this_flatten_array = flat_array;
4464     }
4465   }
4466 
4467   // Check for classes now being equal
4468   if (this_type->is_same_java_type_as(other_type)) {
4469     // If the klasses are equal, the constants may still differ.  Fall to
4470     // NotNull if they do (neither constant is NULL; that is a special case
4471     // handled elsewhere).
4472     res_klass = this_type->klass();
4473     res_xk = this_xk;
4474     res_flatten_array = this_flatten_array;
4475     return SUBTYPE;
4476   } // Else classes are not equal
4477 
4478   // Since klasses are different, we require a LCA in the Java
4479   // class hierarchy - which means we have to fall to at least NotNull.
4480   if (ptr == TopPTR || ptr == AnyNull || ptr == Constant) {
4481     ptr = NotNull;
4482   }
4483 
4484   interfaces = this_interfaces.intersection_with(other_interfaces);
4485 
4486   // Now we find the LCA of Java classes
4487   ciKlass* k = this_klass->least_common_ancestor(other_klass);
4488 
4489   res_klass = k;
4490   res_xk = false;
4491   res_flatten_array = this_flatten_array_orig && other_flatten_array_orig;
4492 
4493   return LCA;
4494 }
4495 
4496 //------------------------java_mirror_type--------------------------------------
4497 ciType* TypeInstPtr::java_mirror_type(bool* is_val_mirror) const {
4498   // must be a singleton type
4499   if( const_oop() == NULL )  return NULL;
4500 
4501   // must be of type java.lang.Class
4502   if( klass() != ciEnv::current()->Class_klass() )  return NULL;
4503   return const_oop()->as_instance()->java_mirror_type(is_val_mirror);

4504 }
4505 
4506 
4507 //------------------------------xdual------------------------------------------
4508 // Dual: do NOT dual on klasses.  This means I do NOT understand the Java
4509 // inheritance mechanism.
4510 const Type *TypeInstPtr::xdual() const {
4511   return new TypeInstPtr(dual_ptr(), klass(), _interfaces, klass_is_exact(), const_oop(), dual_offset(), flatten_array(), dual_instance_id(), dual_speculative(), dual_inline_depth());
4512 }
4513 
4514 //------------------------------eq---------------------------------------------
4515 // Structural equality check for Type representations
4516 bool TypeInstPtr::eq( const Type *t ) const {
4517   const TypeInstPtr *p = t->is_instptr();
4518   return
4519     klass()->equals(p->klass()) &&
4520     flatten_array() == p->flatten_array() &&
4521     _interfaces.eq(p->_interfaces) &&
4522     TypeOopPtr::eq(p);          // Check sub-type stuff
4523 }
4524 
4525 //------------------------------hash-------------------------------------------
4526 // Type-specific hashing function.
4527 int TypeInstPtr::hash(void) const {
4528   int hash = java_add(java_add(java_add((jint)klass()->hash(), (jint)TypeOopPtr::hash()), _interfaces.hash()), (jint)flatten_array());
4529   return hash;
4530 }
4531 
4532 bool TypeInstPtr::is_java_subtype_of_helper(const TypeOopPtr* other, bool this_exact, bool other_exact) const {
4533   return TypePtr::is_java_subtype_of_helper_for_instance(this, other, this_exact, other_exact);
4534 }
4535 
4536 
4537 bool TypeInstPtr::is_same_java_type_as_helper(const TypeOopPtr* other) const {
4538   return TypePtr::is_same_java_type_as_helper_for_instance(this, other);
4539 }
4540 
4541 bool TypeInstPtr::maybe_java_subtype_of_helper(const TypeOopPtr* other, bool this_exact, bool other_exact) const {
4542   return TypePtr::maybe_java_subtype_of_helper_for_instance(this, other, this_exact, other_exact);
4543 }
4544 
4545 
4546 //------------------------------dump2------------------------------------------
4547 // Dump oop Type
4548 #ifndef PRODUCT

4563       // suppress newlines from it so -XX:+Verbose -XX:+PrintIdeal dumps one-liner for each node.
4564       char* buf = ss.as_string(/* c_heap= */false);
4565       StringUtils::replace_no_expand(buf, "\n", "");
4566       st->print_raw(buf);
4567     }
4568   case BotPTR:
4569     if (!WizardMode && !Verbose) {
4570       if( _klass_is_exact ) st->print(":exact");
4571       break;
4572     }
4573   case TopPTR:
4574   case AnyNull:
4575   case NotNull:
4576     st->print(":%s", ptr_msg[_ptr]);
4577     if( _klass_is_exact ) st->print(":exact");
4578     break;
4579   default:
4580     break;
4581   }
4582 
4583   _offset.dump2(st);




4584 
4585   st->print(" *");
4586 
4587   if (flatten_array() && !klass()->is_inlinetype()) {
4588     st->print(" (flatten array)");
4589   }
4590 
4591   if (_instance_id == InstanceTop)
4592     st->print(",iid=top");
4593   else if (_instance_id != InstanceBot)
4594     st->print(",iid=%d",_instance_id);
4595 
4596   dump_inline_depth(st);
4597   dump_speculative(st);
4598 }
4599 #endif
4600 
4601 //------------------------------add_offset-------------------------------------
4602 const TypePtr* TypeInstPtr::add_offset(intptr_t offset) const {
4603   return make(_ptr, klass(), _interfaces, klass_is_exact(), const_oop(), xadd_offset(offset), flatten_array(),
4604               _instance_id, add_offset_speculative(offset), _inline_depth);
4605 }
4606 
4607 const TypeInstPtr* TypeInstPtr::with_offset(intptr_t offset) const {
4608   return make(_ptr, klass(), _interfaces, klass_is_exact(), const_oop(), Offset(offset), flatten_array(),
4609               _instance_id, with_offset_speculative(offset), _inline_depth);
4610 }
4611 
4612 const TypeInstPtr* TypeInstPtr::remove_speculative() const {
4613   if (_speculative == NULL) {
4614     return this;
4615   }
4616   assert(_inline_depth == InlineDepthTop || _inline_depth == InlineDepthBottom, "non speculative type shouldn't have inline depth");
4617   return make(_ptr, klass(), _interfaces, klass_is_exact(), const_oop(), _offset, flatten_array(),
4618               _instance_id, NULL, _inline_depth);
4619 }
4620 
4621 const TypePtr* TypeInstPtr::with_inline_depth(int depth) const {
4622   if (!UseInlineDepthForSpeculativeTypes) {
4623     return this;
4624   }
4625   return make(_ptr, klass(), _interfaces, klass_is_exact(), const_oop(), _offset, flatten_array(), _instance_id, _speculative, depth);
4626 }
4627 
4628 const TypePtr* TypeInstPtr::with_instance_id(int instance_id) const {
4629   assert(is_known_instance(), "should be known");
4630   return make(_ptr, klass(), _interfaces, klass_is_exact(), const_oop(), _offset, flatten_array(), instance_id, _speculative, _inline_depth);
4631 }
4632 
4633 const TypeInstPtr *TypeInstPtr::cast_to_flatten_array() const {
4634   return make(_ptr, klass(), _interfaces, klass_is_exact(), const_oop(), _offset, true, _instance_id, _speculative, _inline_depth);
4635 }
4636 
4637 const TypeKlassPtr* TypeInstPtr::as_klass_type(bool try_for_exact) const {
4638   bool xk = klass_is_exact();
4639   ciInstanceKlass* ik = klass()->as_instance_klass();
4640   if (try_for_exact && !xk && !ik->has_subklass() && !ik->is_final()) {
4641     ciKlass* k = ik;
4642     TypePtr::InterfaceSet interfaces = TypePtr::interfaces(k, true, false, false, ignore_interfaces);
4643     assert(k == ik, "");
4644     if (interfaces.eq(_interfaces)) {
4645       Compile *C = Compile::current();
4646       Dependencies* deps = C->dependencies();
4647       deps->assert_leaf_type(ik);
4648       xk = true;
4649     }
4650   }
4651   return TypeInstKlassPtr::make(xk ? TypePtr::Constant : TypePtr::NotNull, klass(), _interfaces, Offset(0), flatten_array());
4652 }
4653 
4654 template <class T1, class T2> bool TypePtr::is_meet_subtype_of_helper_for_instance(const T1* this_one, const T2* other, bool this_xk, bool other_xk) {
4655   static_assert(std::is_base_of<T2, T1>::value, "");
4656 
4657   if (!this_one->is_instance_type(other)) {
4658     return false;
4659   }
4660 
4661   if (other->klass() == ciEnv::current()->Object_klass() && other->_interfaces.empty()) {
4662     return true;
4663   }
4664 
4665   return this_one->klass()->is_subtype_of(other->klass()) &&
4666          (!this_xk || this_one->_interfaces.contains(other->_interfaces));
4667 }
4668 
4669 
4670 bool TypeInstPtr::is_meet_subtype_of_helper(const TypeOopPtr *other, bool this_xk, bool other_xk) const {
4671   return TypePtr::is_meet_subtype_of_helper_for_instance(this, other, this_xk, other_xk);

4676   if (other->klass() == ciEnv::current()->Object_klass() && other->_interfaces.empty()) {
4677     return true;
4678   }
4679 
4680   if (this_one->is_instance_type(other)) {
4681     return other->klass() == ciEnv::current()->Object_klass() && this_one->_interfaces.contains(other->_interfaces);
4682   }
4683 
4684   int dummy;
4685   bool this_top_or_bottom = (this_one->base_element_type(dummy) == Type::TOP || this_one->base_element_type(dummy) == Type::BOTTOM);
4686   if (this_top_or_bottom) {
4687     return false;
4688   }
4689 
4690   const T1* other_ary = this_one->is_array_type(other);
4691   const TypePtr* other_elem = other_ary->elem()->make_ptr();
4692   const TypePtr* this_elem = this_one->elem()->make_ptr();
4693   if (other_elem != NULL && this_elem != NULL) {
4694     return this_one->is_reference_type(this_elem)->is_meet_subtype_of_helper(this_one->is_reference_type(other_elem), this_xk, other_xk);
4695   }

4696   if (other_elem == NULL && this_elem == NULL) {
4697     return this_one->_klass->is_subtype_of(other->_klass);
4698   }
4699 
4700   return false;
4701 }
4702 
4703 bool TypeAryPtr::is_meet_subtype_of_helper(const TypeOopPtr *other, bool this_xk, bool other_xk) const {
4704   return TypePtr::is_meet_subtype_of_helper_for_array(this, other, this_xk, other_xk);
4705 }
4706 
4707 bool TypeInstKlassPtr::is_meet_subtype_of_helper(const TypeKlassPtr *other, bool this_xk, bool other_xk) const {
4708   return TypePtr::is_meet_subtype_of_helper_for_instance(this, other, this_xk, other_xk);
4709 }
4710 
4711 bool TypeAryKlassPtr::is_meet_subtype_of_helper(const TypeKlassPtr *other, bool this_xk, bool other_xk) const {
4712   return TypePtr::is_meet_subtype_of_helper_for_array(this, other, this_xk, other_xk);
4713 }
4714 
4715 //=============================================================================
4716 // Convenience common pre-built types.
4717 const TypeAryPtr *TypeAryPtr::RANGE;
4718 const TypeAryPtr *TypeAryPtr::OOPS;
4719 const TypeAryPtr *TypeAryPtr::NARROWOOPS;
4720 const TypeAryPtr *TypeAryPtr::BYTES;
4721 const TypeAryPtr *TypeAryPtr::SHORTS;
4722 const TypeAryPtr *TypeAryPtr::CHARS;
4723 const TypeAryPtr *TypeAryPtr::INTS;
4724 const TypeAryPtr *TypeAryPtr::LONGS;
4725 const TypeAryPtr *TypeAryPtr::FLOATS;
4726 const TypeAryPtr *TypeAryPtr::DOUBLES;
4727 const TypeAryPtr *TypeAryPtr::INLINES;
4728 
4729 //------------------------------make-------------------------------------------
4730 const TypeAryPtr* TypeAryPtr::make(PTR ptr, const TypeAry *ary, ciKlass* k, bool xk, Offset offset, Offset field_offset,
4731                                    int instance_id, const TypePtr* speculative, int inline_depth) {
4732   assert(!(k == NULL && ary->_elem->isa_int()),
4733          "integral arrays must be pre-equipped with a class");
4734   if (!xk)  xk = ary->ary_must_be_exact();
4735   assert(instance_id <= 0 || xk, "instances are always exactly typed");
4736   if (k != NULL && k->is_loaded() && k->is_obj_array_klass() &&
4737       k->as_obj_array_klass()->base_element_klass()->is_interface()) {
4738     k = NULL;
4739   }
4740   if (k != NULL && k->is_flat_array_klass() && !ary->_flat) {
4741     k = NULL;
4742   }
4743   return (TypeAryPtr*)(new TypeAryPtr(ptr, NULL, ary, k, xk, offset, field_offset, instance_id, false, speculative, inline_depth))->hashcons();
4744 }
4745 
4746 //------------------------------make-------------------------------------------
4747 const TypeAryPtr* TypeAryPtr::make(PTR ptr, ciObject* o, const TypeAry *ary, ciKlass* k, bool xk, Offset offset, Offset field_offset,
4748                                    int instance_id, const TypePtr* speculative, int inline_depth,
4749                                    bool is_autobox_cache) {
4750   assert(!(k == NULL && ary->_elem->isa_int()),
4751          "integral arrays must be pre-equipped with a class");
4752   assert( (ptr==Constant && o) || (ptr!=Constant && !o), "" );
4753   if (!xk)  xk = (o != NULL) || ary->ary_must_be_exact();
4754   assert(instance_id <= 0 || xk, "instances are always exactly typed");
4755   if (k != NULL && k->is_loaded() && k->is_obj_array_klass() &&
4756       k->as_obj_array_klass()->base_element_klass()->is_interface()) {
4757     k = NULL;
4758   }
4759   if (k != NULL && k->is_flat_array_klass() && !ary->_flat) {
4760     k = NULL;
4761   }
4762   return (TypeAryPtr*)(new TypeAryPtr(ptr, o, ary, k, xk, offset, field_offset, instance_id, is_autobox_cache, speculative, inline_depth))->hashcons();
4763 }
4764 
4765 //------------------------------cast_to_ptr_type-------------------------------
4766 const TypeAryPtr* TypeAryPtr::cast_to_ptr_type(PTR ptr) const {
4767   if( ptr == _ptr ) return this;
4768   return make(ptr, ptr == Constant ? const_oop() : NULL, _ary, klass(), klass_is_exact(), _offset, _field_offset, _instance_id, _speculative, _inline_depth, _is_autobox_cache);
4769 }
4770 
4771 
4772 //-----------------------------cast_to_exactness-------------------------------
4773 const TypeAryPtr* TypeAryPtr::cast_to_exactness(bool klass_is_exact) const {
4774   if( klass_is_exact == _klass_is_exact ) return this;
4775   if (_ary->ary_must_be_exact())  return this;  // cannot clear xk
4776   return make(ptr(), const_oop(), _ary, klass(), klass_is_exact, _offset, _field_offset, _instance_id, _speculative, _inline_depth, _is_autobox_cache);
4777 }
4778 
4779 //-----------------------------cast_to_instance_id----------------------------
4780 const TypeAryPtr* TypeAryPtr::cast_to_instance_id(int instance_id) const {
4781   if( instance_id == _instance_id ) return this;
4782   return make(_ptr, const_oop(), _ary, klass(), _klass_is_exact, _offset, _field_offset, instance_id, _speculative, _inline_depth, _is_autobox_cache);
4783 }
4784 
4785 
4786 //-----------------------------max_array_length-------------------------------
4787 // A wrapper around arrayOopDesc::max_array_length(etype) with some input normalization.
4788 jint TypeAryPtr::max_array_length(BasicType etype) {
4789   if (!is_java_primitive(etype) && !::is_reference_type(etype)) {
4790     if (etype == T_NARROWOOP) {
4791       etype = T_OBJECT;
4792     } else if (etype == T_ILLEGAL) { // bottom[]
4793       etype = T_BYTE; // will produce conservatively high value
4794     } else {
4795       fatal("not an element type: %s", type2name(etype));
4796     }
4797   }
4798   return arrayOopDesc::max_array_length(etype);
4799 }
4800 
4801 //-----------------------------narrow_size_type-------------------------------
4802 // Narrow the given size type to the index range for the given array base type.

4818   if (hi > max_hi) {
4819     hi = max_hi;
4820     if (size->is_con()) {
4821       lo = hi;
4822     }
4823     chg = true;
4824   }
4825   // Negative length arrays will produce weird intermediate dead fast-path code
4826   if (lo > hi)
4827     return TypeInt::ZERO;
4828   if (!chg)
4829     return size;
4830   return TypeInt::make(lo, hi, Type::WidenMin);
4831 }
4832 
4833 //-------------------------------cast_to_size----------------------------------
4834 const TypeAryPtr* TypeAryPtr::cast_to_size(const TypeInt* new_size) const {
4835   assert(new_size != NULL, "");
4836   new_size = narrow_size_type(new_size);
4837   if (new_size == size())  return this;
4838   const TypeAry* new_ary = TypeAry::make(elem(), new_size, is_stable(), is_flat(), is_not_flat(), is_not_null_free());
4839   return make(ptr(), const_oop(), new_ary, klass(), klass_is_exact(), _offset, _field_offset, _instance_id, _speculative, _inline_depth, _is_autobox_cache);
4840 }
4841 
4842 //-------------------------------cast_to_not_flat------------------------------
4843 const TypeAryPtr* TypeAryPtr::cast_to_not_flat(bool not_flat) const {
4844   if (not_flat == is_not_flat()) {
4845     return this;
4846   }
4847   assert(!not_flat || !is_flat(), "inconsistency");
4848   const TypeAry* new_ary = TypeAry::make(elem(), size(), is_stable(), is_flat(), not_flat, is_not_null_free());
4849   return make(ptr(), const_oop(), new_ary, klass(), klass_is_exact(), _offset, _field_offset, _instance_id, _speculative, _inline_depth, _is_autobox_cache);
4850 }
4851 
4852 //-------------------------------cast_to_not_null_free-------------------------
4853 const TypeAryPtr* TypeAryPtr::cast_to_not_null_free(bool not_null_free) const {
4854   if (not_null_free == is_not_null_free()) {
4855     return this;
4856   }
4857   assert(!not_null_free || !is_flat(), "inconsistency");
4858   const TypeAry* new_ary = TypeAry::make(elem(), size(), is_stable(), is_flat(), /* not_flat= */ not_null_free ? true : is_not_flat(), not_null_free);
4859   const TypeAryPtr* res = make(ptr(), const_oop(), new_ary, klass(), klass_is_exact(), _offset, _field_offset,
4860                                _instance_id, _speculative, _inline_depth, _is_autobox_cache);
4861   if (res->speculative() == res->remove_speculative()) {
4862     return res->remove_speculative();
4863   }
4864   return res;
4865 }
4866 
4867 //---------------------------------update_properties---------------------------
4868 const TypeAryPtr* TypeAryPtr::update_properties(const TypeAryPtr* from) const {
4869   if ((from->is_flat()          && is_not_flat()) ||
4870       (from->is_not_flat()      && is_flat()) ||
4871       (from->is_null_free()     && is_not_null_free()) ||
4872       (from->is_not_null_free() && is_null_free())) {
4873     return NULL; // Inconsistent properties
4874   } else if (from->is_not_null_free()) {
4875     return cast_to_not_null_free(); // Implies not flat
4876   } else if (from->is_not_flat()) {
4877     return cast_to_not_flat();
4878   }
4879   return this;
4880 }
4881 
4882 jint TypeAryPtr::flat_layout_helper() const {
4883   return klass()->as_flat_array_klass()->layout_helper();
4884 }
4885 
4886 int TypeAryPtr::flat_elem_size() const {
4887   return klass()->as_flat_array_klass()->element_byte_size();
4888 }
4889 
4890 int TypeAryPtr::flat_log_elem_size() const {
4891   return klass()->as_flat_array_klass()->log2_element_size();
4892 }
4893 
4894 //------------------------------cast_to_stable---------------------------------
4895 const TypeAryPtr* TypeAryPtr::cast_to_stable(bool stable, int stable_dimension) const {
4896   if (stable_dimension <= 0 || (stable_dimension == 1 && stable == this->is_stable()))
4897     return this;
4898 
4899   const Type* elem = this->elem();
4900   const TypePtr* elem_ptr = elem->make_ptr();
4901 
4902   if (stable_dimension > 1 && elem_ptr != NULL && elem_ptr->isa_aryptr()) {
4903     // If this is widened from a narrow oop, TypeAry::make will re-narrow it.
4904     elem = elem_ptr = elem_ptr->is_aryptr()->cast_to_stable(stable, stable_dimension - 1);
4905   }
4906 
4907   const TypeAry* new_ary = TypeAry::make(elem, size(), stable, is_flat(), is_not_flat(), is_not_null_free());
4908 
4909   return make(ptr(), const_oop(), new_ary, klass(), klass_is_exact(), _offset, _field_offset, _instance_id, _speculative, _inline_depth, _is_autobox_cache);
4910 }
4911 
4912 //-----------------------------stable_dimension--------------------------------
4913 int TypeAryPtr::stable_dimension() const {
4914   if (!is_stable())  return 0;
4915   int dim = 1;
4916   const TypePtr* elem_ptr = elem()->make_ptr();
4917   if (elem_ptr != NULL && elem_ptr->isa_aryptr())
4918     dim += elem_ptr->is_aryptr()->stable_dimension();
4919   return dim;
4920 }
4921 
4922 //----------------------cast_to_autobox_cache-----------------------------------
4923 const TypeAryPtr* TypeAryPtr::cast_to_autobox_cache() const {
4924   if (is_autobox_cache())  return this;
4925   const TypeOopPtr* etype = elem()->make_oopptr();
4926   if (etype == NULL)  return this;
4927   // The pointers in the autobox arrays are always non-null.
4928   etype = etype->cast_to_ptr_type(TypePtr::NotNull)->is_oopptr();
4929   const TypeAry* new_ary = TypeAry::make(etype, size(), is_stable(), is_flat(), is_not_flat(), is_not_null_free());
4930   return make(ptr(), const_oop(), new_ary, klass(), klass_is_exact(), _offset, _field_offset, _instance_id, _speculative, _inline_depth, /*is_autobox_cache=*/true);
4931 }
4932 
4933 //------------------------------eq---------------------------------------------
4934 // Structural equality check for Type representations
4935 bool TypeAryPtr::eq( const Type *t ) const {
4936   const TypeAryPtr *p = t->is_aryptr();
4937   return
4938     _ary == p->_ary &&  // Check array
4939     TypeOopPtr::eq(p) &&// Check sub-parts
4940     _field_offset == p->_field_offset;
4941 }
4942 
4943 //------------------------------hash-------------------------------------------
4944 // Type-specific hashing function.
4945 int TypeAryPtr::hash(void) const {
4946   return (intptr_t)_ary + TypeOopPtr::hash() + _field_offset.get();
4947 }
4948 
4949 bool TypeAryPtr::is_java_subtype_of_helper(const TypeOopPtr* other, bool this_exact, bool other_exact) const {
4950   return TypePtr::is_java_subtype_of_helper_for_array(this, other, this_exact, other_exact);
4951 }
4952 
4953 bool TypeAryPtr::is_same_java_type_as_helper(const TypeOopPtr* other) const {
4954   return TypePtr::is_same_java_type_as_helper_for_array(this, other);
4955 }
4956 
4957 bool TypeAryPtr::maybe_java_subtype_of_helper(const TypeOopPtr* other, bool this_exact, bool other_exact) const {
4958   return TypePtr::maybe_java_subtype_of_helper_for_array(this, other, this_exact, other_exact);
4959 }
4960 //------------------------------meet-------------------------------------------
4961 // Compute the MEET of two types.  It returns a new Type object.
4962 const Type *TypeAryPtr::xmeet_helper(const Type *t) const {
4963   // Perform a fast test for common case; meeting the same types together.
4964   if( this == t ) return this;  // Meeting same type-rep?
4965   // Current "this->_base" is Pointer
4966   switch (t->base()) {          // switch on original type

4970   case Long:
4971   case FloatTop:
4972   case FloatCon:
4973   case FloatBot:
4974   case DoubleTop:
4975   case DoubleCon:
4976   case DoubleBot:
4977   case NarrowOop:
4978   case NarrowKlass:
4979   case Bottom:                  // Ye Olde Default
4980     return Type::BOTTOM;
4981   case Top:
4982     return this;
4983 
4984   default:                      // All else is a mistake
4985     typerr(t);
4986 
4987   case OopPtr: {                // Meeting to OopPtrs
4988     // Found a OopPtr type vs self-AryPtr type
4989     const TypeOopPtr *tp = t->is_oopptr();
4990     Offset offset = meet_offset(tp->offset());
4991     PTR ptr = meet_ptr(tp->ptr());
4992     int depth = meet_inline_depth(tp->inline_depth());
4993     const TypePtr* speculative = xmeet_speculative(tp);
4994     switch (tp->ptr()) {
4995     case TopPTR:
4996     case AnyNull: {
4997       int instance_id = meet_instance_id(InstanceTop);
4998       return make(ptr, (ptr == Constant ? const_oop() : NULL),
4999                   _ary, _klass, _klass_is_exact, offset, _field_offset, instance_id, speculative, depth);
5000     }
5001     case BotPTR:
5002     case NotNull: {
5003       int instance_id = meet_instance_id(tp->instance_id());
5004       return TypeOopPtr::make(ptr, offset, instance_id, speculative, depth);
5005     }
5006     default: ShouldNotReachHere();
5007     }
5008   }
5009 
5010   case AnyPtr: {                // Meeting two AnyPtrs
5011     // Found an AnyPtr type vs self-AryPtr type
5012     const TypePtr *tp = t->is_ptr();
5013     Offset offset = meet_offset(tp->offset());
5014     PTR ptr = meet_ptr(tp->ptr());
5015     const TypePtr* speculative = xmeet_speculative(tp);
5016     int depth = meet_inline_depth(tp->inline_depth());
5017     switch (tp->ptr()) {
5018     case TopPTR:
5019       return this;
5020     case BotPTR:
5021     case NotNull:
5022       return TypePtr::make(AnyPtr, ptr, offset, speculative, depth);
5023     case Null:
5024       if( ptr == Null ) return TypePtr::make(AnyPtr, ptr, offset, speculative, depth);
5025       // else fall through to AnyNull
5026     case AnyNull: {
5027       int instance_id = meet_instance_id(InstanceTop);
5028       return make(ptr, (ptr == Constant ? const_oop() : NULL),
5029                   _ary, _klass, _klass_is_exact, offset, _field_offset, instance_id, speculative, depth);
5030     }
5031     default: ShouldNotReachHere();
5032     }
5033   }
5034 
5035   case MetadataPtr:
5036   case KlassPtr:
5037   case InstKlassPtr:
5038   case AryKlassPtr:
5039   case RawPtr: return TypePtr::BOTTOM;
5040 
5041   case AryPtr: {                // Meeting 2 references?
5042     const TypeAryPtr *tap = t->is_aryptr();
5043     Offset off = meet_offset(tap->offset());
5044     Offset field_off = meet_field_offset(tap->field_offset());
5045     const TypeAry *tary = _ary->meet_speculative(tap->_ary)->is_ary();
5046     PTR ptr = meet_ptr(tap->ptr());
5047     int instance_id = meet_instance_id(tap->instance_id());
5048     const TypePtr* speculative = xmeet_speculative(tap);
5049     int depth = meet_inline_depth(tap->inline_depth());
5050 
5051     ciKlass* res_klass = NULL;
5052     bool res_xk = false;
5053     bool res_flat = false;
5054     bool res_not_flat = false;
5055     bool res_not_null_free = false;
5056     const Type* elem = tary->_elem;
5057     if (meet_aryptr(ptr, elem, this, tap, res_klass, res_xk, res_flat, res_not_flat, res_not_null_free) == NOT_SUBTYPE) {
5058       instance_id = InstanceBot;
5059     } else if (this->is_flat() != tap->is_flat()) {
5060       // Meeting flattened inline type array with non-flattened array. Adjust (field) offset accordingly.
5061       if (tary->_flat) {
5062         // Result is flattened
5063         off = Offset(is_flat() ? offset() : tap->offset());
5064         field_off = is_flat() ? field_offset() : tap->field_offset();
5065       } else if (below_centerline(ptr)) {
5066         // Result is non-flattened
5067         off = Offset(flattened_offset()).meet(Offset(tap->flattened_offset()));
5068         field_off = Offset::bottom;
5069       } else if (flattened_offset() == tap->flattened_offset()) {
5070         off = Offset(!is_flat() ? offset() : tap->offset());
5071         field_off = !is_flat() ? field_offset() : tap->field_offset();
5072       }
5073     }
5074 
5075     ciObject* o = NULL;             // Assume not constant when done
5076     ciObject* this_oop = const_oop();
5077     ciObject* tap_oop = tap->const_oop();
5078     if (ptr == Constant) {
5079       if (this_oop != NULL && tap_oop != NULL &&
5080           this_oop->equals(tap_oop)) {
5081         o = tap_oop;
5082       } else if (above_centerline(_ptr)) {
5083         o = tap_oop;
5084       } else if (above_centerline(tap->_ptr)) {
5085         o = this_oop;
5086       } else {
5087         ptr = NotNull;
5088       }
5089     }
5090     return make(ptr, o, TypeAry::make(elem, tary->_size, tary->_stable, res_flat, res_not_flat, res_not_null_free), res_klass, res_xk, off, field_off, instance_id, speculative, depth);
5091   }
5092 
5093   // All arrays inherit from Object class
5094   case InstPtr: {
5095     const TypeInstPtr *tp = t->is_instptr();
5096     Offset offset = meet_offset(tp->offset());
5097     PTR ptr = meet_ptr(tp->ptr());
5098     int instance_id = meet_instance_id(tp->instance_id());
5099     const TypePtr* speculative = xmeet_speculative(tp);
5100     int depth = meet_inline_depth(tp->inline_depth());
5101     InterfaceSet interfaces = meet_interfaces(tp);
5102     InterfaceSet tp_interfaces = tp->_interfaces;
5103     InterfaceSet this_interfaces = _interfaces;
5104 
5105     switch (ptr) {
5106     case TopPTR:
5107     case AnyNull:                // Fall 'down' to dual of object klass
5108       // For instances when a subclass meets a superclass we fall
5109       // below the centerline when the superclass is exact. We need to
5110       // do the same here.
5111       if (tp->klass()->equals(ciEnv::current()->Object_klass()) && this_interfaces.contains(tp_interfaces) && !tp->klass_is_exact() && !tp->flatten_array()) {
5112         return TypeAryPtr::make(ptr, _ary, _klass, _klass_is_exact, offset, _field_offset, instance_id, speculative, depth);
5113       } else {
5114         // cannot subclass, so the meet has to fall badly below the centerline
5115         ptr = NotNull;
5116         instance_id = InstanceBot;
5117         interfaces = this_interfaces.intersection_with(tp_interfaces);
5118         return TypeInstPtr::make(ptr, ciEnv::current()->Object_klass(), interfaces, false, NULL, offset, false, instance_id, speculative, depth);
5119       }
5120     case Constant:
5121     case NotNull:
5122     case BotPTR:                // Fall down to object klass
5123       // LCA is object_klass, but if we subclass from the top we can do better
5124       if (above_centerline(tp->ptr())) {
5125         // If 'tp'  is above the centerline and it is Object class
5126         // then we can subclass in the Java class hierarchy.
5127         // For instances when a subclass meets a superclass we fall
5128         // below the centerline when the superclass is exact. We need
5129         // to do the same here.
5130         if (tp->klass()->equals(ciEnv::current()->Object_klass()) && this_interfaces.contains(tp_interfaces) && !tp->klass_is_exact() && !tp->flatten_array()) {
5131           // that is, my array type is a subtype of 'tp' klass
5132           return make(ptr, (ptr == Constant ? const_oop() : NULL),
5133                       _ary, _klass, _klass_is_exact, offset, _field_offset, instance_id, speculative, depth);
5134         }
5135       }
5136       // The other case cannot happen, since t cannot be a subtype of an array.
5137       // The meet falls down to Object class below centerline.
5138       if (ptr == Constant) {
5139          ptr = NotNull;
5140       }
5141       if (instance_id > 0) {
5142         instance_id = InstanceBot;
5143       }
5144       interfaces = this_interfaces.intersection_with(tp_interfaces);
5145       return TypeInstPtr::make(ptr, ciEnv::current()->Object_klass(), interfaces, false, NULL, offset, false, instance_id, speculative, depth);
5146     default: typerr(t);
5147     }
5148   }
5149   }
5150   return this;                  // Lint noise
5151 }
5152 
5153 
5154 template<class T> TypePtr::MeetResult TypePtr::meet_aryptr(PTR& ptr, const Type*& elem, const T* this_ary, const T* other_ary,
5155                                                            ciKlass*& res_klass, bool& res_xk, bool &res_flat, bool& res_not_flat, bool& res_not_null_free) {
5156   int dummy;
5157   bool this_top_or_bottom = (this_ary->base_element_type(dummy) == Type::TOP || this_ary->base_element_type(dummy) == Type::BOTTOM);
5158   bool other_top_or_bottom = (other_ary->base_element_type(dummy) == Type::TOP || other_ary->base_element_type(dummy) == Type::BOTTOM);
5159   ciKlass* this_klass = this_ary->klass();
5160   ciKlass* other_klass = other_ary->klass();
5161   bool this_xk = this_ary->klass_is_exact();
5162   bool other_xk = other_ary->klass_is_exact();
5163   PTR this_ptr = this_ary->ptr();
5164   PTR other_ptr = other_ary->ptr();
5165   bool this_flat = this_ary->is_flat();
5166   bool this_not_flat = this_ary->is_not_flat();
5167   bool other_flat = other_ary->is_flat();
5168   bool other_not_flat = other_ary->is_not_flat();
5169   bool this_not_null_free = this_ary->is_not_null_free();
5170   bool other_not_null_free = other_ary->is_not_null_free();
5171   res_klass = NULL;
5172   MeetResult result = SUBTYPE;
5173   res_flat = this_flat && other_flat;
5174   res_not_flat = this_not_flat && other_not_flat;
5175   res_not_null_free = this_not_null_free && other_not_null_free;
5176 
5177   if (elem->isa_int()) {
5178     // Integral array element types have irrelevant lattice relations.
5179     // It is the klass that determines array layout, not the element type.
5180       if (this_top_or_bottom) {
5181         res_klass = other_klass;
5182       } else if (other_top_or_bottom || other_klass == this_klass) {
5183       res_klass = this_klass;
5184     } else {
5185       // Something like byte[int+] meets char[int+].
5186       // This must fall to bottom, not (int[-128..65535])[int+].
5187       // instance_id = InstanceBot;
5188       elem = Type::BOTTOM;
5189       result = NOT_SUBTYPE;
5190     }
5191   } else {// Non integral arrays.
5192     // Must fall to bottom if exact klasses in upper lattice
5193     // are not equal or super klass is exact.
5194     if ((above_centerline(ptr) || ptr == Constant) && !this_ary->is_same_java_type_as(other_ary) &&
5195         // meet with top[] and bottom[] are processed further down:
5196         !this_top_or_bottom && !other_top_or_bottom &&
5197         // both are exact and not equal:
5198         ((other_xk && this_xk) ||
5199          // 'tap'  is exact and super or unrelated:
5200          (other_xk && !other_ary->is_meet_subtype_of(this_ary)) ||
5201          // 'this' is exact and super or unrelated:
5202          (this_xk && !this_ary->is_meet_subtype_of(other_ary)))) {
5203       if (above_centerline(ptr) || (elem->make_ptr() && above_centerline(elem->make_ptr()->_ptr))) {
5204         elem = Type::BOTTOM;
5205       }
5206       ptr = NotNull;
5207       res_xk = false;
5208       return NOT_SUBTYPE;
5209     }
5210   }
5211 
5212   res_xk = false;
5213   switch (other_ptr) {
5214     case AnyNull:
5215     case TopPTR:
5216       // Compute new klass on demand, do not use tap->_klass
5217       if (below_centerline(this_ptr)) {
5218         res_xk = this_xk;
5219         if (this_ary->is_flat()) {
5220           elem = this_ary->elem();
5221         }
5222       } else {
5223         res_xk = (other_xk || this_xk);
5224       }
5225       break;
5226     case Constant: {
5227       if (this_ptr == Constant) {
5228         res_xk = true;
5229       } else if (above_centerline(this_ptr)) {
5230         res_xk = true;
5231       } else {
5232         // Only precise for identical arrays
5233         res_xk = this_xk && (this_ary->is_same_java_type_as(other_ary) || (this_top_or_bottom && other_top_or_bottom));
5234         // Even if MyValue is exact, [LMyValue is not exact due to [QMyValue <: [LMyValue.
5235         if (res_xk && !res_not_null_free) {
5236           res_xk = false;
5237         }
5238       }
5239       break;
5240     }
5241     case NotNull:
5242     case BotPTR:
5243       // Compute new klass on demand, do not use tap->_klass
5244       if (above_centerline(this_ptr)) {
5245         res_xk = other_xk;
5246         if (other_ary->is_flat()) {
5247           elem = other_ary->elem();
5248         }
5249       } else {
5250         res_xk = (other_xk && this_xk) &&
5251                  (this_ary->is_same_java_type_as(other_ary) || (this_top_or_bottom && other_top_or_bottom)); // Only precise for identical arrays
5252         // Even if MyValue is exact, [LMyValue is not exact due to [QMyValue <: [LMyValue.
5253         if (res_xk && !res_not_null_free) {
5254           res_xk = false;
5255         }
5256       }
5257       break;
5258     default:  {
5259       ShouldNotReachHere();
5260       return result;
5261     }
5262   }
5263   return result;
5264 }
5265 
5266 
5267 //------------------------------xdual------------------------------------------
5268 // Dual: compute field-by-field dual
5269 const Type *TypeAryPtr::xdual() const {
5270   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());
5271 }
5272 
5273 Type::Offset TypeAryPtr::meet_field_offset(const Type::Offset offset) const {
5274   return _field_offset.meet(offset);
5275 }
5276 
5277 //------------------------------dual_offset------------------------------------
5278 Type::Offset TypeAryPtr::dual_field_offset() const {
5279   return _field_offset.dual();
5280 }
5281 
5282 //------------------------------dump2------------------------------------------
5283 #ifndef PRODUCT
5284 void TypeAryPtr::dump2( Dict &d, uint depth, outputStream *st ) const {
5285   _ary->dump2(d,depth,st);
5286   _interfaces.dump(st);
5287 
5288   switch( _ptr ) {
5289   case Constant:
5290     const_oop()->print(st);
5291     break;
5292   case BotPTR:
5293     if (!WizardMode && !Verbose) {
5294       if( _klass_is_exact ) st->print(":exact");
5295       break;
5296     }
5297   case TopPTR:
5298   case AnyNull:
5299   case NotNull:
5300     st->print(":%s", ptr_msg[_ptr]);
5301     if( _klass_is_exact ) st->print(":exact");
5302     break;
5303   default:
5304     break;
5305   }
5306 
5307   if (is_flat()) {
5308     st->print(":flat");
5309     st->print("(");
5310     _field_offset.dump2(st);
5311     st->print(")");
5312   }
5313   if (is_null_free()) {
5314     st->print(":null_free");
5315   }
5316   if (offset() != 0) {
5317     int header_size = objArrayOopDesc::header_size() * wordSize;
5318     if( _offset == Offset::top )       st->print("+undefined");
5319     else if( _offset == Offset::bottom )  st->print("+any");
5320     else if( offset() < header_size ) st->print("+%d", offset());
5321     else {
5322       BasicType basic_elem_type = elem()->basic_type();
5323       if (basic_elem_type == T_ILLEGAL) {
5324         st->print("+any");
5325       } else {
5326         int array_base = arrayOopDesc::base_offset_in_bytes(basic_elem_type);
5327         int elem_size = type2aelembytes(basic_elem_type);
5328         st->print("[%d]", (offset() - array_base)/elem_size);
5329       }
5330     }
5331   }
5332   st->print(" *");
5333   if (_instance_id == InstanceTop)
5334     st->print(",iid=top");
5335   else if (_instance_id != InstanceBot)
5336     st->print(",iid=%d",_instance_id);
5337 
5338   dump_inline_depth(st);
5339   dump_speculative(st);
5340 }
5341 #endif
5342 
5343 bool TypeAryPtr::empty(void) const {
5344   if (_ary->empty())       return true;
5345   // FIXME: Does this belong here? Or in the meet code itself?
5346   if (is_flat() && is_not_flat()) {
5347     return true;
5348   }
5349   return TypeOopPtr::empty();
5350 }
5351 
5352 //------------------------------add_offset-------------------------------------
5353 const TypePtr* TypeAryPtr::add_offset(intptr_t offset) const {
5354   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);
5355 }
5356 
5357 const TypeAryPtr* TypeAryPtr::with_offset(intptr_t offset) const {
5358   return make(_ptr, _const_oop, _ary, _klass, _klass_is_exact, Offset(offset), _field_offset, _instance_id, with_offset_speculative(offset), _inline_depth, _is_autobox_cache);
5359 }
5360 
5361 const TypeAryPtr* TypeAryPtr::with_ary(const TypeAry* ary) const {
5362   return make(_ptr, _const_oop, ary, _klass, _klass_is_exact, _offset, _field_offset, _instance_id, _speculative, _inline_depth, _is_autobox_cache);
5363 }
5364 
5365 const TypeAryPtr* TypeAryPtr::remove_speculative() const {
5366   if (_speculative == NULL) {
5367     return this;
5368   }
5369   assert(_inline_depth == InlineDepthTop || _inline_depth == InlineDepthBottom, "non speculative type shouldn't have inline depth");
5370   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);
5371 }
5372 
5373 const Type* TypeAryPtr::cleanup_speculative() const {
5374   if (speculative() == NULL) {
5375     return this;
5376   }
5377   // Keep speculative part if it contains information about flat-/nullability
5378   const TypeAryPtr* spec_aryptr = speculative()->isa_aryptr();
5379   if (spec_aryptr != NULL && !above_centerline(spec_aryptr->ptr()) &&
5380       (spec_aryptr->is_not_flat() || spec_aryptr->is_not_null_free())) {
5381     return this;
5382   }
5383   return TypeOopPtr::cleanup_speculative();
5384 }
5385 
5386 const TypePtr* TypeAryPtr::with_inline_depth(int depth) const {
5387   if (!UseInlineDepthForSpeculativeTypes) {
5388     return this;
5389   }
5390   return make(_ptr, _const_oop, _ary->remove_speculative()->is_ary(), _klass, _klass_is_exact, _offset, _field_offset, _instance_id, _speculative, depth, _is_autobox_cache);
5391 }
5392 
5393 const TypeAryPtr* TypeAryPtr::with_field_offset(int offset) const {
5394   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);
5395 }
5396 
5397 const TypePtr* TypeAryPtr::add_field_offset_and_offset(intptr_t offset) const {
5398   int adj = 0;
5399   if (is_flat() && offset != Type::OffsetBot && offset != Type::OffsetTop) {
5400     if (_offset.get() != OffsetBot && _offset.get() != OffsetTop) {
5401       adj = _offset.get();
5402       offset += _offset.get();
5403     }
5404     uint header = arrayOopDesc::base_offset_in_bytes(T_OBJECT);
5405     if (_field_offset.get() != OffsetBot && _field_offset.get() != OffsetTop) {
5406       offset += _field_offset.get();
5407       if (_offset.get() == OffsetBot || _offset.get() == OffsetTop) {
5408         offset += header;
5409       }
5410     }
5411     if (offset >= (intptr_t)header || offset < 0) {
5412       // Try to get the field of the inline type array element we are pointing to
5413       ciInlineKlass* vk = elem()->inline_klass();
5414       int shift = flat_log_elem_size();
5415       int mask = (1 << shift) - 1;
5416       intptr_t field_offset = ((offset - header) & mask);
5417       ciField* field = vk->get_field_by_offset(field_offset + vk->first_field_offset(), false);
5418       if (field != NULL) {
5419         return with_field_offset(field_offset)->add_offset(offset - field_offset - adj);
5420       }
5421     }
5422   }
5423   return add_offset(offset - adj);
5424 }
5425 
5426 // Return offset incremented by field_offset for flattened inline type arrays
5427 const int TypeAryPtr::flattened_offset() const {
5428   int offset = _offset.get();
5429   if (offset != Type::OffsetBot && offset != Type::OffsetTop &&
5430       _field_offset != Offset::bottom && _field_offset != Offset::top) {
5431     offset += _field_offset.get();
5432   }
5433   return offset;
5434 }
5435 
5436 const TypePtr* TypeAryPtr::with_instance_id(int instance_id) const {
5437   assert(is_known_instance(), "should be known");
5438   return make(_ptr, _const_oop, _ary->remove_speculative()->is_ary(), _klass, _klass_is_exact, _offset, _field_offset, instance_id, _speculative, _inline_depth);
5439 }
5440 
5441 //=============================================================================
5442 
5443 
5444 //------------------------------hash-------------------------------------------
5445 // Type-specific hashing function.
5446 int TypeNarrowPtr::hash(void) const {
5447   return _ptrtype->hash() + 7;
5448 }
5449 
5450 bool TypeNarrowPtr::singleton(void) const {    // TRUE if type is a singleton
5451   return _ptrtype->singleton();
5452 }
5453 
5454 bool TypeNarrowPtr::empty(void) const {
5455   return _ptrtype->empty();
5456 }
5457 
5458 intptr_t TypeNarrowPtr::get_con() const {
5459   return _ptrtype->get_con();
5460 }
5461 
5462 bool TypeNarrowPtr::eq( const Type *t ) const {
5463   const TypeNarrowPtr* tc = isa_same_narrowptr(t);

5514 
5515   case Int:                     // Mixing ints & oops happens when javac
5516   case Long:                    // reuses local variables
5517   case FloatTop:
5518   case FloatCon:
5519   case FloatBot:
5520   case DoubleTop:
5521   case DoubleCon:
5522   case DoubleBot:
5523   case AnyPtr:
5524   case RawPtr:
5525   case OopPtr:
5526   case InstPtr:
5527   case AryPtr:
5528   case MetadataPtr:
5529   case KlassPtr:
5530   case InstKlassPtr:
5531   case AryKlassPtr:
5532   case NarrowOop:
5533   case NarrowKlass:

5534   case Bottom:                  // Ye Olde Default
5535     return Type::BOTTOM;
5536   case Top:
5537     return this;
5538 
5539   default:                      // All else is a mistake
5540     typerr(t);
5541 
5542   } // End of switch
5543 
5544   return this;
5545 }
5546 
5547 #ifndef PRODUCT
5548 void TypeNarrowPtr::dump2( Dict & d, uint depth, outputStream *st ) const {
5549   _ptrtype->dump2(d, depth, st);
5550 }
5551 #endif
5552 
5553 const TypeNarrowOop *TypeNarrowOop::BOTTOM;

5597     return (one == two) && TypePtr::eq(t);
5598   } else {
5599     return one->equals(two) && TypePtr::eq(t);
5600   }
5601 }
5602 
5603 //------------------------------hash-------------------------------------------
5604 // Type-specific hashing function.
5605 int TypeMetadataPtr::hash(void) const {
5606   return
5607     (metadata() ? metadata()->hash() : 0) +
5608     TypePtr::hash();
5609 }
5610 
5611 //------------------------------singleton--------------------------------------
5612 // TRUE if Type is a singleton type, FALSE otherwise.   Singletons are simple
5613 // constants
5614 bool TypeMetadataPtr::singleton(void) const {
5615   // detune optimizer to not generate constant metadata + constant offset as a constant!
5616   // TopPTR, Null, AnyNull, Constant are all singletons
5617   return (offset() == 0) && !below_centerline(_ptr);
5618 }
5619 
5620 //------------------------------add_offset-------------------------------------
5621 const TypePtr* TypeMetadataPtr::add_offset( intptr_t offset ) const {
5622   return make( _ptr, _metadata, xadd_offset(offset));
5623 }
5624 
5625 //-----------------------------filter------------------------------------------
5626 // Do not allow interface-vs.-noninterface joins to collapse to top.
5627 const Type *TypeMetadataPtr::filter_helper(const Type *kills, bool include_speculative) const {
5628   const TypeMetadataPtr* ft = join_helper(kills, include_speculative)->isa_metadataptr();
5629   if (ft == NULL || ft->empty())
5630     return Type::TOP;           // Canonical empty value
5631   return ft;
5632 }
5633 
5634  //------------------------------get_con----------------------------------------
5635 intptr_t TypeMetadataPtr::get_con() const {
5636   assert( _ptr == Null || _ptr == Constant, "" );
5637   assert(offset() >= 0, "");
5638 
5639   if (offset() != 0) {
5640     // After being ported to the compiler interface, the compiler no longer
5641     // directly manipulates the addresses of oops.  Rather, it only has a pointer
5642     // to a handle at compile time.  This handle is embedded in the generated
5643     // code and dereferenced at the time the nmethod is made.  Until that time,
5644     // it is not reasonable to do arithmetic with the addresses of oops (we don't
5645     // have access to the addresses!).  This does not seem to currently happen,
5646     // but this assertion here is to help prevent its occurrence.
5647     tty->print_cr("Found oop constant with non-zero offset");
5648     ShouldNotReachHere();
5649   }
5650 
5651   return (intptr_t)metadata()->constant_encoding();
5652 }
5653 
5654 //------------------------------cast_to_ptr_type-------------------------------
5655 const TypeMetadataPtr* TypeMetadataPtr::cast_to_ptr_type(PTR ptr) const {
5656   if( ptr == _ptr ) return this;
5657   return make(ptr, metadata(), _offset);
5658 }
5659 

5670   case Long:                    // reuses local variables
5671   case FloatTop:
5672   case FloatCon:
5673   case FloatBot:
5674   case DoubleTop:
5675   case DoubleCon:
5676   case DoubleBot:
5677   case NarrowOop:
5678   case NarrowKlass:
5679   case Bottom:                  // Ye Olde Default
5680     return Type::BOTTOM;
5681   case Top:
5682     return this;
5683 
5684   default:                      // All else is a mistake
5685     typerr(t);
5686 
5687   case AnyPtr: {
5688     // Found an AnyPtr type vs self-OopPtr type
5689     const TypePtr *tp = t->is_ptr();
5690     Offset offset = meet_offset(tp->offset());
5691     PTR ptr = meet_ptr(tp->ptr());
5692     switch (tp->ptr()) {
5693     case Null:
5694       if (ptr == Null)  return TypePtr::make(AnyPtr, ptr, offset, tp->speculative(), tp->inline_depth());
5695       // else fall through:
5696     case TopPTR:
5697     case AnyNull: {
5698       return make(ptr, _metadata, offset);
5699     }
5700     case BotPTR:
5701     case NotNull:
5702       return TypePtr::make(AnyPtr, ptr, offset, tp->speculative(), tp->inline_depth());
5703     default: typerr(t);
5704     }
5705   }
5706 
5707   case RawPtr:
5708   case KlassPtr:
5709   case InstKlassPtr:
5710   case AryKlassPtr:
5711   case OopPtr:
5712   case InstPtr:
5713   case AryPtr:
5714     return TypePtr::BOTTOM;     // Oop meet raw is not well defined
5715 
5716   case MetadataPtr: {
5717     const TypeMetadataPtr *tp = t->is_metadataptr();
5718     Offset offset = meet_offset(tp->offset());
5719     PTR tptr = tp->ptr();
5720     PTR ptr = meet_ptr(tptr);
5721     ciMetadata* md = (tptr == TopPTR) ? metadata() : tp->metadata();
5722     if (tptr == TopPTR || _ptr == TopPTR ||
5723         metadata()->equals(tp->metadata())) {
5724       return make(ptr, md, offset);
5725     }
5726     // metadata is different
5727     if( ptr == Constant ) {  // Cannot be equal constants, so...
5728       if( tptr == Constant && _ptr != Constant)  return t;
5729       if( _ptr == Constant && tptr != Constant)  return this;
5730       ptr = NotNull;            // Fall down in lattice
5731     }
5732     return make(ptr, NULL, offset);
5733     break;
5734   }
5735   } // End of switch
5736   return this;                  // Return the double constant
5737 }
5738 
5739 
5740 //------------------------------xdual------------------------------------------
5741 // Dual of a pure metadata pointer.
5742 const Type *TypeMetadataPtr::xdual() const {
5743   return new TypeMetadataPtr(dual_ptr(), metadata(), dual_offset());
5744 }
5745 
5746 //------------------------------dump2------------------------------------------
5747 #ifndef PRODUCT
5748 void TypeMetadataPtr::dump2( Dict &d, uint depth, outputStream *st ) const {
5749   st->print("metadataptr:%s", ptr_msg[_ptr]);
5750   if( metadata() ) st->print(INTPTR_FORMAT, p2i(metadata()));
5751   switch (offset()) {
5752   case OffsetTop: st->print("+top"); break;
5753   case OffsetBot: st->print("+any"); break;
5754   case         0: break;
5755   default:        st->print("+%d",offset()); break;
5756   }
5757 }
5758 #endif
5759 
5760 
5761 //=============================================================================
5762 // Convenience common pre-built type.
5763 const TypeMetadataPtr *TypeMetadataPtr::BOTTOM;
5764 
5765 TypeMetadataPtr::TypeMetadataPtr(PTR ptr, ciMetadata* metadata, Offset offset):
5766   TypePtr(MetadataPtr, ptr, offset), _metadata(metadata) {
5767 }
5768 
5769 const TypeMetadataPtr* TypeMetadataPtr::make(ciMethod* m) {
5770   return make(Constant, m, Offset(0));
5771 }
5772 const TypeMetadataPtr* TypeMetadataPtr::make(ciMethodData* m) {
5773   return make(Constant, m, Offset(0));
5774 }
5775 
5776 //------------------------------make-------------------------------------------
5777 // Create a meta data constant
5778 const TypeMetadataPtr* TypeMetadataPtr::make(PTR ptr, ciMetadata* m, Offset offset) {
5779   assert(m == NULL || !m->is_klass(), "wrong type");
5780   return (TypeMetadataPtr*)(new TypeMetadataPtr(ptr, m, offset))->hashcons();
5781 }
5782 
5783 
5784 const TypeKlassPtr* TypeAryPtr::as_klass_type(bool try_for_exact) const {
5785   const Type* elem = _ary->_elem;
5786   bool xk = klass_is_exact();
5787   if (elem->make_oopptr() != NULL) {
5788     elem = elem->make_oopptr()->as_klass_type(try_for_exact);
5789     if (elem->is_klassptr()->klass_is_exact() &&
5790         // Even if MyValue is exact, [LMyValue is not exact due to [QMyValue <: [LMyValue.
5791         (is_null_free() || is_flat() || !_ary->_elem->make_oopptr()->is_inlinetypeptr())) {
5792       xk = true;
5793     }
5794   }
5795   return TypeAryKlassPtr::make(xk ? TypePtr::Constant : TypePtr::NotNull, elem, klass(), Offset(0), is_not_flat(), is_not_null_free(), is_null_free());
5796 }
5797 
5798 const TypeKlassPtr* TypeKlassPtr::make(ciKlass* klass, InterfaceHandling interface_handling) {
5799   if (klass->is_instance_klass()) {
5800     return TypeInstKlassPtr::make(klass, interface_handling);
5801   }
5802   return TypeAryKlassPtr::make(klass, interface_handling);
5803 }
5804 
5805 const TypeKlassPtr* TypeKlassPtr::make(PTR ptr, ciKlass* klass, Offset offset, InterfaceHandling interface_handling) {
5806   if (klass->is_instance_klass()) {
5807     const InterfaceSet interfaces = TypePtr::interfaces(klass, true, true, false, interface_handling);
5808     return TypeInstKlassPtr::make(ptr, klass, interfaces, offset);
5809   }
5810   return TypeAryKlassPtr::make(ptr, klass, offset, interface_handling);
5811 }
5812 
5813 TypeKlassPtr::TypeKlassPtr(TYPES t, PTR ptr, ciKlass* klass, const InterfaceSet& interfaces, Offset offset)


5814   : TypePtr(t, ptr, offset), _klass(klass), _interfaces(interfaces) {
5815   assert(klass == NULL || !klass->is_loaded() || (klass->is_instance_klass() && !klass->is_interface()) ||
5816          klass->is_type_array_klass() || klass->is_flat_array_klass() || !klass->as_obj_array_klass()->base_element_klass()->is_interface(), "no interface here");
5817 }
5818 
5819 // Is there a single ciKlass* that can represent that type?
5820 ciKlass* TypeKlassPtr::exact_klass_helper() const {
5821   assert(_klass->is_instance_klass() && !_klass->is_interface(), "No interface");
5822   if (_interfaces.empty()) {
5823     return _klass;
5824   }
5825   if (_klass != ciEnv::current()->Object_klass()) {
5826     ciKlass* k = _klass;
5827     if (_interfaces.eq(TypePtr::interfaces(k, true, false, true, ignore_interfaces))) {
5828       return _klass;
5829     }
5830     return NULL;
5831   }
5832   return _interfaces.exact_klass();
5833 }
5834 
5835 //------------------------------eq---------------------------------------------
5836 // Structural equality check for Type representations
5837 bool TypeKlassPtr::eq(const Type *t) const {
5838   const TypeKlassPtr *p = t->is_klassptr();
5839   return
5840     _interfaces.eq(p->_interfaces) &&
5841     TypePtr::eq(p);
5842 }
5843 
5844 //------------------------------hash-------------------------------------------
5845 // Type-specific hashing function.
5846 int TypeKlassPtr::hash(void) const {
5847   return java_add((jint)TypePtr::hash(), _interfaces.hash());
5848 }
5849 
5850 //------------------------------singleton--------------------------------------
5851 // TRUE if Type is a singleton type, FALSE otherwise.   Singletons are simple
5852 // constants
5853 bool TypeKlassPtr::singleton(void) const {
5854   // detune optimizer to not generate constant klass + constant offset as a constant!
5855   // TopPTR, Null, AnyNull, Constant are all singletons
5856   return (offset() == 0) && !below_centerline(_ptr);
5857 }
5858 
5859 // Do not allow interface-vs.-noninterface joins to collapse to top.
5860 const Type *TypeKlassPtr::filter_helper(const Type *kills, bool include_speculative) const {
5861   // logic here mirrors the one from TypeOopPtr::filter. See comments
5862   // there.
5863   const Type* ft = join_helper(kills, include_speculative);
5864   const TypeKlassPtr* ftkp = ft->isa_instklassptr();
5865   const TypeKlassPtr* ktkp = kills->isa_instklassptr();
5866 
5867   if (ft->empty()) {
5868     return Type::TOP;           // Canonical empty value
5869   }
5870 
5871   return ft;
5872 }
5873 
5874 TypePtr::InterfaceSet TypeKlassPtr::meet_interfaces(const TypeKlassPtr* other) const {
5875   if (above_centerline(_ptr) && above_centerline(other->_ptr)) {
5876     return _interfaces.union_with(other->_interfaces);
5877   } else if (above_centerline(_ptr) && !above_centerline(other->_ptr)) {
5878     return other->_interfaces;
5879   } else if (above_centerline(other->_ptr) && !above_centerline(_ptr)) {
5880     return _interfaces;
5881   }
5882   return _interfaces.intersection_with(other->_interfaces);
5883 }
5884 
5885 //------------------------------get_con----------------------------------------
5886 intptr_t TypeKlassPtr::get_con() const {
5887   assert( _ptr == Null || _ptr == Constant, "" );
5888   assert( offset() >= 0, "" );
5889 
5890   if (offset() != 0) {
5891     // After being ported to the compiler interface, the compiler no longer
5892     // directly manipulates the addresses of oops.  Rather, it only has a pointer
5893     // to a handle at compile time.  This handle is embedded in the generated
5894     // code and dereferenced at the time the nmethod is made.  Until that time,
5895     // it is not reasonable to do arithmetic with the addresses of oops (we don't
5896     // have access to the addresses!).  This does not seem to currently happen,
5897     // but this assertion here is to help prevent its occurrence.
5898     tty->print_cr("Found oop constant with non-zero offset");
5899     ShouldNotReachHere();
5900   }
5901 
5902   ciKlass* k = exact_klass();
5903 
5904   return (intptr_t)k->constant_encoding();
5905 }
5906 
5907 //------------------------------dump2------------------------------------------
5908 // Dump Klass Type
5909 #ifndef PRODUCT
5910 void TypeKlassPtr::dump2(Dict & d, uint depth, outputStream *st) const {

5914   case NotNull:
5915     {
5916       const char *name = klass()->name()->as_utf8();
5917       if (name) {
5918         st->print("%s: " INTPTR_FORMAT, name, p2i(klass()));
5919       } else {
5920         ShouldNotReachHere();
5921       }
5922       _interfaces.dump(st);
5923     }
5924   case BotPTR:
5925     if (!WizardMode && !Verbose && _ptr != Constant) break;
5926   case TopPTR:
5927   case AnyNull:
5928     st->print(":%s", ptr_msg[_ptr]);
5929     if (_ptr == Constant) st->print(":exact");
5930     break;
5931   default:
5932     break;
5933   }
5934   if (Verbose) {
5935     if (isa_instklassptr() && is_instklassptr()->flatten_array()) st->print(":flatten array");



5936   }
5937   _offset.dump2(st);
5938   st->print(" *");
5939 }
5940 #endif
5941 
5942 //=============================================================================
5943 // Convenience common pre-built types.
5944 
5945 // Not-null object klass or below
5946 const TypeInstKlassPtr *TypeInstKlassPtr::OBJECT;
5947 const TypeInstKlassPtr *TypeInstKlassPtr::OBJECT_OR_NULL;
5948 
5949 bool TypeInstKlassPtr::eq(const Type *t) const {
5950   const TypeKlassPtr *p = t->is_klassptr();
5951   return
5952     klass()->equals(p->klass()) &&
5953     flatten_array() == p->flatten_array() &&
5954     TypeKlassPtr::eq(p);
5955 }
5956 
5957 int TypeInstKlassPtr::hash(void) const {
5958   return java_add(java_add((jint)klass()->hash(), TypeKlassPtr::hash()), (jint)flatten_array());
5959 }
5960 
5961 const TypeInstKlassPtr *TypeInstKlassPtr::make(PTR ptr, ciKlass* k, const InterfaceSet& interfaces, Offset offset, bool flatten_array) {
5962   flatten_array = flatten_array || k->flatten_array();
5963 
5964   TypeInstKlassPtr *r =
5965     (TypeInstKlassPtr*)(new TypeInstKlassPtr(ptr, k, interfaces, offset, flatten_array))->hashcons();
5966 
5967   return r;
5968 }
5969 
5970 //------------------------------add_offset-------------------------------------
5971 // Access internals of klass object
5972 const TypePtr *TypeInstKlassPtr::add_offset( intptr_t offset ) const {
5973   return make(_ptr, klass(), _interfaces, xadd_offset(offset), flatten_array());
5974 }
5975 
5976 const TypeInstKlassPtr* TypeInstKlassPtr::with_offset(intptr_t offset) const {
5977   return make(_ptr, klass(), _interfaces, Offset(offset), flatten_array());
5978 }
5979 
5980 //------------------------------cast_to_ptr_type-------------------------------
5981 const TypeInstKlassPtr* TypeInstKlassPtr::cast_to_ptr_type(PTR ptr) const {
5982   assert(_base == InstKlassPtr, "subclass must override cast_to_ptr_type");
5983   if( ptr == _ptr ) return this;
5984   return make(ptr, _klass, _interfaces, _offset, flatten_array());
5985 }
5986 
5987 
5988 bool TypeInstKlassPtr::must_be_exact() const {
5989   if (!_klass->is_loaded())  return false;
5990   ciInstanceKlass* ik = _klass->as_instance_klass();
5991   if (ik->is_final())  return true;  // cannot clear xk
5992   return false;
5993 }
5994 
5995 //-----------------------------cast_to_exactness-------------------------------
5996 const TypeKlassPtr* TypeInstKlassPtr::cast_to_exactness(bool klass_is_exact) const {
5997   if (klass_is_exact == (_ptr == Constant)) return this;
5998   if (must_be_exact()) return this;
5999   ciKlass* k = klass();
6000   return make(klass_is_exact ? Constant : NotNull, k, _interfaces, _offset, flatten_array());
6001 }
6002 
6003 
6004 //-----------------------------as_instance_type--------------------------------
6005 // Corresponding type for an instance of the given class.
6006 // It will be NotNull, and exact if and only if the klass type is exact.
6007 const TypeOopPtr* TypeInstKlassPtr::as_instance_type(bool klass_change) const {
6008   ciKlass* k = klass();
6009   bool xk = klass_is_exact();
6010   Compile* C = Compile::current();
6011   Dependencies* deps = C->dependencies();
6012   assert((deps != NULL) == (C->method() != NULL && C->method()->code_size() > 0), "sanity");
6013   // Element is an instance
6014   bool klass_is_exact = false;
6015   TypePtr::InterfaceSet interfaces = _interfaces;
6016   if (k->is_loaded()) {
6017     // Try to set klass_is_exact.
6018     ciInstanceKlass* ik = k->as_instance_klass();
6019     klass_is_exact = ik->is_final();
6020     if (!klass_is_exact && klass_change
6021         && deps != NULL && UseUniqueSubclasses) {
6022       ciInstanceKlass* sub = ik->unique_concrete_subklass();
6023       if (sub != NULL) {
6024         ciKlass* sub_k = sub;
6025         TypePtr::InterfaceSet sub_interfaces = TypePtr::interfaces(sub_k, true, false, false, ignore_interfaces);
6026         assert(sub_k == sub, "");
6027         if (sub_interfaces.eq(_interfaces)) {
6028           deps->assert_abstract_with_unique_concrete_subtype(ik, sub);
6029           k = ik = sub;
6030           xk = sub->is_final();
6031         }
6032       }
6033     }
6034   }
6035   return TypeInstPtr::make(TypePtr::BotPTR, k, interfaces, xk, NULL, Offset(0), flatten_array() && !klass()->is_inlinetype());
6036 }
6037 
6038 //------------------------------xmeet------------------------------------------
6039 // Compute the MEET of two types, return a new Type object.
6040 const Type    *TypeInstKlassPtr::xmeet( const Type *t ) const {
6041   // Perform a fast test for common case; meeting the same types together.
6042   if( this == t ) return this;  // Meeting same type-rep?
6043 
6044   // Current "this->_base" is Pointer
6045   switch (t->base()) {          // switch on original type
6046 
6047   case Int:                     // Mixing ints & oops happens when javac
6048   case Long:                    // reuses local variables
6049   case FloatTop:
6050   case FloatCon:
6051   case FloatBot:
6052   case DoubleTop:
6053   case DoubleCon:
6054   case DoubleBot:
6055   case NarrowOop:
6056   case NarrowKlass:
6057   case Bottom:                  // Ye Olde Default
6058     return Type::BOTTOM;
6059   case Top:
6060     return this;
6061 
6062   default:                      // All else is a mistake
6063     typerr(t);
6064 
6065   case AnyPtr: {                // Meeting to AnyPtrs
6066     // Found an AnyPtr type vs self-KlassPtr type
6067     const TypePtr *tp = t->is_ptr();
6068     Offset offset = meet_offset(tp->offset());
6069     PTR ptr = meet_ptr(tp->ptr());
6070     switch (tp->ptr()) {
6071     case TopPTR:
6072       return this;
6073     case Null:
6074       if( ptr == Null ) return TypePtr::make(AnyPtr, ptr, offset, tp->speculative(), tp->inline_depth());
6075     case AnyNull:
6076       return make(ptr, klass(), _interfaces, offset, flatten_array());
6077     case BotPTR:
6078     case NotNull:
6079       return TypePtr::make(AnyPtr, ptr, offset, tp->speculative(), tp->inline_depth());
6080     default: typerr(t);
6081     }
6082   }
6083 
6084   case RawPtr:
6085   case MetadataPtr:
6086   case OopPtr:
6087   case AryPtr:                  // Meet with AryPtr
6088   case InstPtr:                 // Meet with InstPtr
6089       return TypePtr::BOTTOM;
6090 
6091   //
6092   //             A-top         }
6093   //           /   |   \       }  Tops
6094   //       B-top A-any C-top   }
6095   //          | /  |  \ |      }  Any-nulls
6096   //       B-any   |   C-any   }
6097   //          |    |    |
6098   //       B-con A-con C-con   } constants; not comparable across classes
6099   //          |    |    |
6100   //       B-not   |   C-not   }
6101   //          | \  |  / |      }  not-nulls
6102   //       B-bot A-not C-bot   }
6103   //           \   |   /       }  Bottoms
6104   //             A-bot         }
6105   //
6106 
6107   case InstKlassPtr: {  // Meet two KlassPtr types
6108     const TypeInstKlassPtr *tkls = t->is_instklassptr();
6109     Offset  off     = meet_offset(tkls->offset());
6110     PTR  ptr     = meet_ptr(tkls->ptr());
6111     InterfaceSet interfaces = meet_interfaces(tkls);
6112 
6113     ciKlass* res_klass = NULL;
6114     bool res_xk = false;
6115     bool res_flatten_array = false;
6116     switch(meet_instptr(ptr, interfaces, this, tkls, res_klass, res_xk, res_flatten_array)) {
6117       case UNLOADED:
6118         ShouldNotReachHere();
6119       case SUBTYPE:
6120       case NOT_SUBTYPE:
6121       case LCA:
6122       case QUICK: {
6123         assert(res_xk == (ptr == Constant), "");
6124         const Type* res = make(ptr, res_klass, interfaces, off, res_flatten_array);
6125         return res;
6126       }
6127       default:
6128         ShouldNotReachHere();
6129     }
6130   } // End of case KlassPtr
6131   case AryKlassPtr: {                // All arrays inherit from Object class
6132     const TypeAryKlassPtr *tp = t->is_aryklassptr();
6133     Offset offset = meet_offset(tp->offset());
6134     PTR ptr = meet_ptr(tp->ptr());
6135     InterfaceSet interfaces = meet_interfaces(tp);
6136     InterfaceSet tp_interfaces = tp->_interfaces;
6137     InterfaceSet this_interfaces = _interfaces;
6138 
6139     switch (ptr) {
6140     case TopPTR:
6141     case AnyNull:                // Fall 'down' to dual of object klass
6142       // For instances when a subclass meets a superclass we fall
6143       // below the centerline when the superclass is exact. We need to
6144       // do the same here.
6145       if (klass()->equals(ciEnv::current()->Object_klass()) && tp_interfaces.contains(this_interfaces) && !klass_is_exact()) {
6146         return TypeAryKlassPtr::make(ptr, tp->elem(), tp->klass(), offset, tp->is_not_flat(), tp->is_not_null_free(), tp->is_null_free());
6147       } else {
6148         // cannot subclass, so the meet has to fall badly below the centerline
6149         ptr = NotNull;
6150         interfaces = _interfaces.intersection_with(tp->_interfaces);
6151         return make(ptr, ciEnv::current()->Object_klass(), interfaces, offset, false);
6152       }
6153     case Constant:
6154     case NotNull:
6155     case BotPTR:                // Fall down to object klass
6156       // LCA is object_klass, but if we subclass from the top we can do better
6157       if( above_centerline(_ptr) ) { // if( _ptr == TopPTR || _ptr == AnyNull )
6158         // If 'this' (InstPtr) is above the centerline and it is Object class
6159         // then we can subclass in the Java class hierarchy.
6160         // For instances when a subclass meets a superclass we fall
6161         // below the centerline when the superclass is exact. We need
6162         // to do the same here.
6163         if (klass()->equals(ciEnv::current()->Object_klass()) && tp_interfaces.contains(this_interfaces) && !klass_is_exact()) {
6164           // that is, tp's array type is a subtype of my klass
6165           return TypeAryKlassPtr::make(ptr, tp->elem(), tp->klass(), offset, tp->is_not_flat(), tp->is_not_null_free(), tp->is_null_free());

6166         }
6167       }
6168       // The other case cannot happen, since I cannot be a subtype of an array.
6169       // The meet falls down to Object class below centerline.
6170       if( ptr == Constant )
6171          ptr = NotNull;
6172       interfaces = this_interfaces.intersection_with(tp_interfaces);
6173       return make(ptr, ciEnv::current()->Object_klass(), interfaces, offset, false);
6174     default: typerr(t);
6175     }
6176   }
6177 
6178   } // End of switch
6179   return this;                  // Return the double constant
6180 }
6181 
6182 //------------------------------xdual------------------------------------------
6183 // Dual: compute field-by-field dual
6184 const Type    *TypeInstKlassPtr::xdual() const {
6185   return new TypeInstKlassPtr(dual_ptr(), klass(), _interfaces, dual_offset(), flatten_array());
6186 }
6187 
6188 template <class T1, class T2> bool TypePtr::is_java_subtype_of_helper_for_instance(const T1* this_one, const T2* other, bool this_exact, bool other_exact) {
6189   static_assert(std::is_base_of<T2, T1>::value, "");
6190   if (!this_one->is_loaded() || !other->is_loaded()) {
6191     return false;
6192   }
6193   if (!this_one->is_instance_type(other)) {
6194     return false;
6195   }
6196 
6197   if (!other_exact) {
6198     return false;
6199   }
6200 
6201   if (other->klass()->equals(ciEnv::current()->Object_klass()) && other->_interfaces.empty()) {
6202     return true;
6203   }
6204 
6205   return this_one->_klass->is_subtype_of(other->_klass) && this_one->_interfaces.contains(other->_interfaces);

6269     bool klass_is_exact = ik->is_final();
6270     if (!klass_is_exact &&
6271         deps != NULL) {
6272       ciInstanceKlass* sub = ik->unique_concrete_subklass();
6273       if (sub != NULL) {
6274         ciKlass *sub_k = sub;
6275         TypePtr::InterfaceSet sub_interfaces = TypePtr::interfaces(sub_k, true, false, false, ignore_interfaces);
6276         assert(sub_k == sub, "");
6277         if (sub_interfaces.eq(_interfaces)) {
6278           deps->assert_abstract_with_unique_concrete_subtype(ik, sub);
6279           k = ik = sub;
6280           klass_is_exact = sub->is_final();
6281           return TypeKlassPtr::make(klass_is_exact ? Constant : _ptr, k, _offset);
6282         }
6283       }
6284     }
6285   }
6286   return this;
6287 }
6288 
6289 bool TypeInstKlassPtr::can_be_inline_array() const {
6290   return _klass->equals(ciEnv::current()->Object_klass()) && TypeAryKlassPtr::_array_interfaces->contains(_interfaces);
6291 }
6292 
6293 bool TypeAryKlassPtr::can_be_inline_array() const {
6294   return _elem->isa_instklassptr() && _elem->is_instklassptr()->_klass->can_be_inline_klass();
6295 }
6296 
6297 bool TypeInstPtr::can_be_inline_array() const {
6298   return _klass->equals(ciEnv::current()->Object_klass()) && TypeAryPtr::_array_interfaces->contains(_interfaces);
6299 }
6300 
6301 bool TypeAryPtr::can_be_inline_array() const {
6302   return elem()->make_ptr() && elem()->make_ptr()->isa_instptr() && elem()->make_ptr()->is_instptr()->_klass->can_be_inline_klass();
6303 }
6304 
6305 const TypeAryKlassPtr *TypeAryKlassPtr::make(PTR ptr, const Type* elem, ciKlass* k, Offset offset, bool not_flat, bool not_null_free, bool null_free) {
6306   return (TypeAryKlassPtr*)(new TypeAryKlassPtr(ptr, elem, k, offset, not_flat, not_null_free, null_free))->hashcons();
6307 }
6308 
6309 const TypeAryKlassPtr* TypeAryKlassPtr::make(PTR ptr, ciKlass* k, Offset offset, InterfaceHandling interface_handling, bool not_flat, bool not_null_free, bool null_free) {
6310   if (k->is_obj_array_klass()) {
6311     // Element is an object array. Recursively call ourself.
6312     ciKlass* eklass = k->as_obj_array_klass()->element_klass();
6313     const TypeKlassPtr* etype = TypeKlassPtr::make(eklass, interface_handling)->cast_to_exactness(false);
6314     // Even if MyValue is exact, [LMyValue is not exact due to [QMyValue <: [LMyValue.
6315     if (etype->klass_is_exact() && etype->isa_instklassptr() && etype->is_instklassptr()->klass()->is_inlinetype() && !null_free) {
6316       etype = TypeInstKlassPtr::make(NotNull, etype->is_instklassptr()->klass(), Offset(etype->is_instklassptr()->offset()));
6317     }
6318     return TypeAryKlassPtr::make(ptr, etype, NULL, offset, not_flat, not_null_free, null_free);
6319   } else if (k->is_type_array_klass()) {
6320     // Element is an typeArray
6321     const Type* etype = get_const_basic_type(k->as_type_array_klass()->element_type());
6322     return TypeAryKlassPtr::make(ptr, etype, k, offset, not_flat, not_null_free, null_free);
6323   } else if (k->is_flat_array_klass()) {
6324     ciKlass* eklass = k->as_flat_array_klass()->element_klass();
6325     const TypeKlassPtr* etype = TypeKlassPtr::make(eklass);
6326     return TypeAryKlassPtr::make(ptr, etype, k, offset, not_flat, not_null_free, null_free);
6327   } else {
6328     ShouldNotReachHere();
6329     return NULL;
6330   }
6331 }
6332 
6333 const TypeAryKlassPtr* TypeAryKlassPtr::make(PTR ptr, ciKlass* k, Offset offset, InterfaceHandling interface_handling) {
6334   bool null_free = k->as_array_klass()->is_elem_null_free();
6335   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));
6336 
6337   bool not_flat = !UseFlatArray || not_null_free || (k->as_array_klass()->element_klass() != NULL &&
6338                                                      k->as_array_klass()->element_klass()->is_inlinetype() &&
6339                                                      !k->as_array_klass()->element_klass()->flatten_array());
6340 
6341   return TypeAryKlassPtr::make(ptr, k, offset, interface_handling, not_flat, not_null_free, null_free);
6342 }
6343 
6344 const TypeAryKlassPtr* TypeAryKlassPtr::make(ciKlass* klass, InterfaceHandling interface_handling) {
6345   return TypeAryKlassPtr::make(Constant, klass, Offset(0), interface_handling);
6346 }
6347 
6348 //------------------------------eq---------------------------------------------
6349 // Structural equality check for Type representations
6350 bool TypeAryKlassPtr::eq(const Type *t) const {
6351   const TypeAryKlassPtr *p = t->is_aryklassptr();
6352   return
6353     _elem == p->_elem &&  // Check array
6354     _not_flat == p->_not_flat &&
6355     _not_null_free == p->_not_null_free &&
6356     _null_free == p->_null_free &&
6357     TypeKlassPtr::eq(p);  // Check sub-parts
6358 }
6359 
6360 //------------------------------hash-------------------------------------------
6361 // Type-specific hashing function.
6362 int TypeAryKlassPtr::hash(void) const {
6363   return (intptr_t)_elem + TypeKlassPtr::hash() + (_not_flat ? 43 : 0) +
6364       (_not_null_free ? 44 : 0) + (_null_free ? 45 : 0);
6365 }
6366 
6367 //----------------------compute_klass------------------------------------------
6368 // Compute the defining klass for this class
6369 ciKlass* TypeAryPtr::compute_klass(DEBUG_ONLY(bool verify)) const {
6370   // Compute _klass based on element type.
6371   ciKlass* k_ary = NULL;
6372   const TypeInstPtr *tinst;
6373   const TypeAryPtr *tary;
6374   const Type* el = elem();
6375   if (el->isa_narrowoop()) {
6376     el = el->make_ptr();
6377   }
6378 
6379   // Get element klass
6380   if (is_flat() && el->is_inlinetypeptr()) {
6381     // Klass is required by TypeAryPtr::flat_layout_helper() and others
6382     if (el->inline_klass() != NULL) {
6383       k_ary = ciArrayKlass::make(el->inline_klass(), /* null_free */ true);
6384     }
6385   } else if ((tinst = el->isa_instptr()) != NULL) {
6386     // Leave k_ary at NULL.
6387   } else if ((tary = el->isa_aryptr()) != NULL) {
6388     // Leave k_ary at NULL.
6389   } else if ((el->base() == Type::Top) ||
6390              (el->base() == Type::Bottom)) {
6391     // element type of Bottom occurs from meet of basic type
6392     // and object; Top occurs when doing join on Bottom.
6393     // Leave k_ary at NULL.
6394   } else {
6395     // Cannot compute array klass directly from basic type,
6396     // since subtypes of TypeInt all have basic type T_INT.
6397 #ifdef ASSERT
6398     if (verify && el->isa_int()) {
6399       // Check simple cases when verifying klass.
6400       BasicType bt = T_ILLEGAL;
6401       if (el == TypeInt::BYTE) {
6402         bt = T_BYTE;
6403       } else if (el == TypeInt::SHORT) {
6404         bt = T_SHORT;
6405       } else if (el == TypeInt::CHAR) {

6437     // type TypeAryPtr::OOPS.  This Type is shared between all
6438     // active compilations.  However, the ciKlass which represents
6439     // this Type is *not* shared between compilations, so caching
6440     // this value would result in fetching a dangling pointer.
6441     //
6442     // Recomputing the underlying ciKlass for each request is
6443     // a bit less efficient than caching, but calls to
6444     // TypeAryPtr::OOPS->klass() are not common enough to matter.
6445     ((TypeAryPtr*)this)->_klass = k_ary;
6446   }
6447   return k_ary;
6448 }
6449 
6450 // Is there a single ciKlass* that can represent that type?
6451 ciKlass* TypeAryPtr::exact_klass_helper() const {
6452   if (_ary->_elem->make_ptr() && _ary->_elem->make_ptr()->isa_oopptr()) {
6453     ciKlass* k = _ary->_elem->make_ptr()->is_oopptr()->exact_klass_helper();
6454     if (k == NULL) {
6455       return NULL;
6456     }
6457     k = ciArrayKlass::make(k, is_null_free());
6458     return k;
6459   }
6460 
6461   return klass();
6462 }
6463 
6464 const Type* TypeAryPtr::base_element_type(int& dims) const {
6465   const Type* elem = this->elem();
6466   dims = 1;
6467   while (elem->make_ptr() && elem->make_ptr()->isa_aryptr()) {
6468     elem = elem->make_ptr()->is_aryptr()->elem();
6469     dims++;
6470   }
6471   return elem;
6472 }
6473 
6474 //------------------------------add_offset-------------------------------------
6475 // Access internals of klass object
6476 const TypePtr* TypeAryKlassPtr::add_offset(intptr_t offset) const {
6477   return make(_ptr, elem(), klass(), xadd_offset(offset), is_not_flat(), is_not_null_free(), _null_free);
6478 }
6479 
6480 const TypeAryKlassPtr* TypeAryKlassPtr::with_offset(intptr_t offset) const {
6481   return make(_ptr, elem(), klass(), Offset(offset), is_not_flat(), is_not_null_free(), _null_free);
6482 }
6483 
6484 //------------------------------cast_to_ptr_type-------------------------------
6485 const TypeAryKlassPtr* TypeAryKlassPtr::cast_to_ptr_type(PTR ptr) const {
6486   assert(_base == AryKlassPtr, "subclass must override cast_to_ptr_type");
6487   if (ptr == _ptr) return this;
6488   return make(ptr, elem(), _klass, _offset, is_not_flat(), is_not_null_free(), _null_free);
6489 }
6490 
6491 bool TypeAryKlassPtr::must_be_exact() const {
6492   if (_elem == Type::BOTTOM) return false;
6493   if (_elem == Type::TOP   ) return false;
6494   const TypeKlassPtr*  tk = _elem->isa_klassptr();
6495   if (!tk)             return true;   // a primitive type, like int
6496   // Even if MyValue is exact, [LMyValue is not exact due to [QMyValue <: [LMyValue.
6497   if (tk->isa_instklassptr() && tk->klass()->is_inlinetype() && !is_null_free()) {
6498     return false;
6499   }
6500   return tk->must_be_exact();
6501 }
6502 
6503 
6504 //-----------------------------cast_to_exactness-------------------------------
6505 const TypeKlassPtr *TypeAryKlassPtr::cast_to_exactness(bool klass_is_exact) const {
6506   if (must_be_exact() && !klass_is_exact) return this;  // cannot clear xk
6507   if (klass_is_exact == this->klass_is_exact()) {
6508     return this;
6509   }
6510   ciKlass* k = _klass;
6511   const Type* elem = this->elem();
6512   if (elem->isa_klassptr() && !klass_is_exact) {
6513     elem = elem->is_klassptr()->cast_to_exactness(klass_is_exact);
6514   }
6515   bool not_flat = is_not_flat();
6516   bool not_null_free = is_not_null_free();
6517   if (_elem->isa_klassptr()) {
6518     if (klass_is_exact || _elem->isa_aryklassptr()) {
6519       assert(!is_null_free() && !is_flat(), "null-free (or flat) inline type arrays should always be exact");
6520       // An array can't be null-free (or flat) if the klass is exact
6521       not_null_free = true;
6522       not_flat = true;
6523     } else {
6524       // Klass is not exact (anymore), re-compute null-free/flat properties
6525       const TypeOopPtr* exact_etype = TypeOopPtr::make_from_klass_unique(_elem->is_instklassptr()->instance_klass());
6526       not_null_free = !exact_etype->can_be_inline_type();
6527       not_flat = !UseFlatArray || not_null_free || (exact_etype->is_inlinetypeptr() && !exact_etype->inline_klass()->flatten_array());
6528     }
6529   }
6530   return make(klass_is_exact ? Constant : NotNull, elem, k, _offset, not_flat, not_null_free, _null_free);
6531 }
6532 
6533 
6534 //-----------------------------as_instance_type--------------------------------
6535 // Corresponding type for an instance of the given class.
6536 // It will be NotNull, and exact if and only if the klass type is exact.
6537 const TypeOopPtr* TypeAryKlassPtr::as_instance_type(bool klass_change) const {
6538   ciKlass* k = klass();
6539   bool    xk = klass_is_exact();
6540   const Type* el = NULL;
6541   if (elem()->isa_klassptr()) {
6542     el = elem()->is_klassptr()->as_instance_type(false)->cast_to_exactness(false);
6543     k = NULL;
6544   } else {
6545     el = elem();
6546   }
6547   bool null_free = _null_free;
6548   if (null_free && el->isa_ptr()) {
6549     el = el->is_ptr()->join_speculative(TypePtr::NOTNULL);
6550   }
6551   return TypeAryPtr::make(TypePtr::BotPTR, TypeAry::make(el, TypeInt::POS, false, is_flat(), is_not_flat(), is_not_null_free()), k, xk, Offset(0));
6552 }
6553 
6554 
6555 //------------------------------xmeet------------------------------------------
6556 // Compute the MEET of two types, return a new Type object.
6557 const Type    *TypeAryKlassPtr::xmeet( const Type *t ) const {
6558   // Perform a fast test for common case; meeting the same types together.
6559   if( this == t ) return this;  // Meeting same type-rep?
6560 
6561   // Current "this->_base" is Pointer
6562   switch (t->base()) {          // switch on original type
6563 
6564   case Int:                     // Mixing ints & oops happens when javac
6565   case Long:                    // reuses local variables
6566   case FloatTop:
6567   case FloatCon:
6568   case FloatBot:
6569   case DoubleTop:
6570   case DoubleCon:
6571   case DoubleBot:
6572   case NarrowOop:
6573   case NarrowKlass:
6574   case Bottom:                  // Ye Olde Default
6575     return Type::BOTTOM;
6576   case Top:
6577     return this;
6578 
6579   default:                      // All else is a mistake
6580     typerr(t);
6581 
6582   case AnyPtr: {                // Meeting to AnyPtrs
6583     // Found an AnyPtr type vs self-KlassPtr type
6584     const TypePtr *tp = t->is_ptr();
6585     Offset offset = meet_offset(tp->offset());
6586     PTR ptr = meet_ptr(tp->ptr());
6587     switch (tp->ptr()) {
6588     case TopPTR:
6589       return this;
6590     case Null:
6591       if( ptr == Null ) return TypePtr::make(AnyPtr, ptr, offset, tp->speculative(), tp->inline_depth());
6592     case AnyNull:
6593       return make(ptr, _elem, klass(), offset, is_not_flat(), is_not_null_free(), is_null_free());
6594     case BotPTR:
6595     case NotNull:
6596       return TypePtr::make(AnyPtr, ptr, offset, tp->speculative(), tp->inline_depth());
6597     default: typerr(t);
6598     }
6599   }
6600 
6601   case RawPtr:
6602   case MetadataPtr:
6603   case OopPtr:
6604   case AryPtr:                  // Meet with AryPtr
6605   case InstPtr:                 // Meet with InstPtr
6606     return TypePtr::BOTTOM;
6607 
6608   //
6609   //             A-top         }
6610   //           /   |   \       }  Tops
6611   //       B-top A-any C-top   }
6612   //          | /  |  \ |      }  Any-nulls
6613   //       B-any   |   C-any   }
6614   //          |    |    |
6615   //       B-con A-con C-con   } constants; not comparable across classes
6616   //          |    |    |
6617   //       B-not   |   C-not   }
6618   //          | \  |  / |      }  not-nulls
6619   //       B-bot A-not C-bot   }
6620   //           \   |   /       }  Bottoms
6621   //             A-bot         }
6622   //
6623 
6624   case AryKlassPtr: {  // Meet two KlassPtr types
6625     const TypeAryKlassPtr *tap = t->is_aryklassptr();
6626     Offset off = meet_offset(tap->offset());
6627     const Type* elem = _elem->meet(tap->_elem);

6628     PTR ptr = meet_ptr(tap->ptr());
6629     ciKlass* res_klass = NULL;
6630     bool res_xk = false;
6631     bool res_flat = false;
6632     bool res_not_flat = false;
6633     bool res_not_null_free = false;
6634     MeetResult res = meet_aryptr(ptr, elem, this, tap,
6635                                  res_klass, res_xk, res_flat, res_not_flat, res_not_null_free);
6636     assert(res_xk == (ptr == Constant), "");
6637     bool null_free = meet_null_free(tap->_null_free);
6638     if (res == NOT_SUBTYPE) {
6639       null_free = false;
6640     } else if (res == SUBTYPE) {
6641       if (above_centerline(tap->ptr()) && !above_centerline(this->ptr())) {
6642         null_free = _null_free;
6643       } else if (above_centerline(this->ptr()) && !above_centerline(tap->ptr())) {
6644         null_free = tap->_null_free;
6645       } else if (above_centerline(this->ptr()) && above_centerline(tap->ptr())) {
6646         null_free = _null_free || tap->_null_free;
6647       }
6648     }
6649     return make(ptr, elem, res_klass, off, res_not_flat, res_not_null_free, null_free);
6650   } // End of case KlassPtr
6651   case InstKlassPtr: {
6652     const TypeInstKlassPtr *tp = t->is_instklassptr();
6653     Offset offset = meet_offset(tp->offset());
6654     PTR ptr = meet_ptr(tp->ptr());
6655     InterfaceSet interfaces = meet_interfaces(tp);
6656     InterfaceSet tp_interfaces = tp->_interfaces;
6657     InterfaceSet this_interfaces = _interfaces;
6658 
6659     switch (ptr) {
6660     case TopPTR:
6661     case AnyNull:                // Fall 'down' to dual of object klass
6662       // For instances when a subclass meets a superclass we fall
6663       // below the centerline when the superclass is exact. We need to
6664       // do the same here.
6665       if (tp->klass()->equals(ciEnv::current()->Object_klass()) && this_interfaces.intersection_with(tp_interfaces).eq(tp_interfaces) && !tp->klass_is_exact()) {
6666         return TypeAryKlassPtr::make(ptr, _elem, _klass, offset, is_not_flat(), is_not_null_free(), is_null_free());
6667       } else {
6668         // cannot subclass, so the meet has to fall badly below the centerline
6669         ptr = NotNull;
6670         interfaces = this_interfaces.intersection_with(tp->_interfaces);
6671         return TypeInstKlassPtr::make(ptr, ciEnv::current()->Object_klass(), interfaces, offset, false);
6672       }
6673     case Constant:
6674     case NotNull:
6675     case BotPTR:                // Fall down to object klass
6676       // LCA is object_klass, but if we subclass from the top we can do better
6677       if (above_centerline(tp->ptr())) {
6678         // If 'tp'  is above the centerline and it is Object class
6679         // then we can subclass in the Java class hierarchy.
6680         // For instances when a subclass meets a superclass we fall
6681         // below the centerline when the superclass is exact. We need
6682         // to do the same here.
6683         if (tp->klass()->equals(ciEnv::current()->Object_klass()) && this_interfaces.intersection_with(tp_interfaces).eq(tp_interfaces) && !tp->klass_is_exact()) {
6684           // that is, my array type is a subtype of 'tp' klass
6685           return make(ptr, _elem, _klass, offset, is_not_flat(), is_not_null_free(), is_null_free());
6686         }
6687       }
6688       // The other case cannot happen, since t cannot be a subtype of an array.
6689       // The meet falls down to Object class below centerline.
6690       if (ptr == Constant)
6691          ptr = NotNull;
6692       interfaces = this_interfaces.intersection_with(tp_interfaces);
6693       return TypeInstKlassPtr::make(ptr, ciEnv::current()->Object_klass(), interfaces, offset, false);
6694     default: typerr(t);
6695     }
6696   }
6697 
6698   } // End of switch
6699   return this;                  // Return the double constant
6700 }
6701 
6702 template <class T1, class T2> bool TypePtr::is_java_subtype_of_helper_for_array(const T1* this_one, const T2* other, bool this_exact, bool other_exact) {
6703   static_assert(std::is_base_of<T2, T1>::value, "");
6704 
6705   if (other->klass() == ciEnv::current()->Object_klass() && other->_interfaces.empty() && other_exact) {
6706     return true;
6707   }
6708 
6709   int dummy;
6710   bool this_top_or_bottom = (this_one->base_element_type(dummy) == Type::TOP || this_one->base_element_type(dummy) == Type::BOTTOM);
6711 
6712   if (!this_one->is_loaded() || !other->is_loaded() || this_top_or_bottom) {
6713     return false;
6714   }
6715 
6716   if (this_one->is_instance_type(other)) {
6717     return other->klass() == ciEnv::current()->Object_klass() && other->_interfaces.intersection_with(this_one->_interfaces).eq(other->_interfaces) && other_exact;
6718   }
6719 
6720   assert(this_one->is_array_type(other), "");
6721   const T1* other_ary = this_one->is_array_type(other);
6722   bool other_top_or_bottom = (other_ary->base_element_type(dummy) == Type::TOP || other_ary->base_element_type(dummy) == Type::BOTTOM);
6723   if (other_top_or_bottom) {
6724     return false;
6725   }
6726 
6727   const TypePtr* other_elem = other_ary->elem()->make_ptr();
6728   const TypePtr* this_elem = this_one->elem()->make_ptr();
6729   if (this_elem != NULL && other_elem != NULL) {
6730     if (other->is_null_free() && !this_one->is_null_free()) {
6731       return false; // [LMyValue is not a subtype of [QMyValue
6732     }
6733     return this_one->is_reference_type(this_elem)->is_java_subtype_of_helper(this_one->is_reference_type(other_elem), this_exact, other_exact);
6734   }
6735   if (this_elem == NULL && other_elem == NULL) {
6736     return this_one->_klass->is_subtype_of(other->_klass);
6737   }
6738   return false;
6739 }
6740 
6741 bool TypeAryKlassPtr::is_java_subtype_of_helper(const TypeKlassPtr* other, bool this_exact, bool other_exact) const {
6742   return TypePtr::is_java_subtype_of_helper_for_array(this, other, this_exact, other_exact);
6743 }
6744 
6745 template <class T1, class T2> bool TypePtr::is_same_java_type_as_helper_for_array(const T1* this_one, const T2* other) {
6746   static_assert(std::is_base_of<T2, T1>::value, "");
6747 
6748   int dummy;
6749   bool this_top_or_bottom = (this_one->base_element_type(dummy) == Type::TOP || this_one->base_element_type(dummy) == Type::BOTTOM);
6750 
6751   if (!this_one->is_array_type(other) ||
6752       !this_one->is_loaded() || !other->is_loaded() || this_top_or_bottom) {

6800   }
6801 
6802   const TypePtr* this_elem = this_one->elem()->make_ptr();
6803   const TypePtr* other_elem = other_ary->elem()->make_ptr();
6804   if (other_elem != NULL && this_elem != NULL) {
6805     return this_one->is_reference_type(this_elem)->maybe_java_subtype_of_helper(this_one->is_reference_type(other_elem), this_exact, other_exact);
6806   }
6807   if (other_elem == NULL && this_elem == NULL) {
6808     return this_one->_klass->is_subtype_of(other->_klass);
6809   }
6810   return false;
6811 }
6812 
6813 bool TypeAryKlassPtr::maybe_java_subtype_of_helper(const TypeKlassPtr* other, bool this_exact, bool other_exact) const {
6814   return TypePtr::maybe_java_subtype_of_helper_for_array(this, other, this_exact, other_exact);
6815 }
6816 
6817 //------------------------------xdual------------------------------------------
6818 // Dual: compute field-by-field dual
6819 const Type    *TypeAryKlassPtr::xdual() const {
6820   return new TypeAryKlassPtr(dual_ptr(), elem()->dual(), klass(), dual_offset(), !is_not_flat(), !is_not_null_free(), dual_null_free());
6821 }
6822 
6823 // Is there a single ciKlass* that can represent that type?
6824 ciKlass* TypeAryKlassPtr::exact_klass_helper() const {
6825   if (elem()->isa_klassptr()) {
6826     ciKlass* k = elem()->is_klassptr()->exact_klass_helper();
6827     if (k == NULL) {
6828       return NULL;
6829     }
6830     k = ciArrayKlass::make(k, _null_free);
6831     return k;
6832   }
6833 
6834   return klass();
6835 }
6836 
6837 ciKlass* TypeAryKlassPtr::klass() const {
6838   if (_klass != NULL) {
6839     return _klass;
6840   }
6841   ciKlass* k = NULL;
6842   if (elem()->isa_klassptr()) {
6843     // leave NULL
6844   } else if ((elem()->base() == Type::Top) ||
6845              (elem()->base() == Type::Bottom)) {
6846   } else {
6847     k = ciTypeArrayKlass::make(elem()->basic_type());
6848     ((TypeAryKlassPtr*)this)->_klass = k;
6849   }
6850   return k;

6857   switch( _ptr ) {
6858   case Constant:
6859     st->print("precise ");
6860   case NotNull:
6861     {
6862       st->print("[");
6863       _elem->dump2(d, depth, st);
6864       _interfaces.dump(st);
6865       st->print(": ");
6866     }
6867   case BotPTR:
6868     if( !WizardMode && !Verbose && _ptr != Constant ) break;
6869   case TopPTR:
6870   case AnyNull:
6871     st->print(":%s", ptr_msg[_ptr]);
6872     if( _ptr == Constant ) st->print(":exact");
6873     break;
6874   default:
6875     break;
6876   }
6877   if (is_flat()) st->print(":flat");
6878   if (_null_free) st->print(":null free");
6879   if (Verbose) {
6880     if (_not_flat) st->print(":not flat");
6881     if (_not_null_free) st->print(":not null free");
6882   }
6883 
6884   _offset.dump2(st);
6885 
6886   st->print(" *");
6887 }
6888 #endif
6889 
6890 const Type* TypeAryKlassPtr::base_element_type(int& dims) const {
6891   const Type* elem = this->elem();
6892   dims = 1;
6893   while (elem->isa_aryklassptr()) {
6894     elem = elem->is_aryklassptr()->elem();
6895     dims++;
6896   }
6897   return elem;
6898 }
6899 
6900 //=============================================================================
6901 // Convenience common pre-built types.
6902 
6903 //------------------------------make-------------------------------------------
6904 const TypeFunc *TypeFunc::make(const TypeTuple *domain_sig, const TypeTuple* domain_cc,
6905                                const TypeTuple *range_sig, const TypeTuple *range_cc) {
6906   return (TypeFunc*)(new TypeFunc(domain_sig, domain_cc, range_sig, range_cc))->hashcons();
6907 }
6908 
6909 const TypeFunc *TypeFunc::make(const TypeTuple *domain, const TypeTuple *range) {
6910   return make(domain, domain, range, range);
6911 }
6912 
6913 //------------------------------osr_domain-----------------------------
6914 const TypeTuple* osr_domain() {
6915   const Type **fields = TypeTuple::fields(2);
6916   fields[TypeFunc::Parms+0] = TypeRawPtr::BOTTOM;  // address of osr buffer
6917   return TypeTuple::make(TypeFunc::Parms+1, fields);
6918 }
6919 
6920 //------------------------------make-------------------------------------------
6921 const TypeFunc* TypeFunc::make(ciMethod* method, bool is_osr_compilation) {
6922   Compile* C = Compile::current();
6923   const TypeFunc* tf = NULL;
6924   if (!is_osr_compilation) {
6925     tf = C->last_tf(method); // check cache
6926     if (tf != NULL)  return tf;  // The hit rate here is almost 50%.
6927   }
6928   // Inline types are not passed/returned by reference, instead each field of
6929   // the inline type is passed/returned as an argument. We maintain two views of
6930   // the argument/return list here: one based on the signature (with an inline
6931   // type argument/return as a single slot), one based on the actual calling
6932   // convention (with an inline type argument/return as a list of its fields).
6933   bool has_scalar_args = method->has_scalarized_args() && !is_osr_compilation;
6934   const TypeTuple* domain_sig = is_osr_compilation ? osr_domain() : TypeTuple::make_domain(method, ignore_interfaces, false);
6935   const TypeTuple* domain_cc = has_scalar_args ? TypeTuple::make_domain(method, ignore_interfaces, true) : domain_sig;
6936   ciSignature* sig = method->signature();
6937   bool has_scalar_ret = sig->return_type()->is_inlinetype() && sig->return_type()->as_inline_klass()->can_be_returned_as_fields();
6938   const TypeTuple* range_sig = TypeTuple::make_range(sig, ignore_interfaces, false);
6939   const TypeTuple* range_cc = has_scalar_ret ? TypeTuple::make_range(sig, ignore_interfaces, true) : range_sig;
6940   tf = TypeFunc::make(domain_sig, domain_cc, range_sig, range_cc);
6941   if (!is_osr_compilation) {
6942     C->set_last_tf(method, tf);  // fill cache
6943   }



6944   return tf;
6945 }
6946 
6947 //------------------------------meet-------------------------------------------
6948 // Compute the MEET of two types.  It returns a new Type object.
6949 const Type *TypeFunc::xmeet( const Type *t ) const {
6950   // Perform a fast test for common case; meeting the same types together.
6951   if( this == t ) return this;  // Meeting same type-rep?
6952 
6953   // Current "this->_base" is Func
6954   switch (t->base()) {          // switch on original type
6955 
6956   case Bottom:                  // Ye Olde Default
6957     return t;
6958 
6959   default:                      // All else is a mistake
6960     typerr(t);
6961 
6962   case Top:
6963     break;
6964   }
6965   return this;                  // Return the double constant
6966 }
6967 
6968 //------------------------------xdual------------------------------------------
6969 // Dual: compute field-by-field dual
6970 const Type *TypeFunc::xdual() const {
6971   return this;
6972 }
6973 
6974 //------------------------------eq---------------------------------------------
6975 // Structural equality check for Type representations
6976 bool TypeFunc::eq( const Type *t ) const {
6977   const TypeFunc *a = (const TypeFunc*)t;
6978   return _domain_sig == a->_domain_sig &&
6979     _domain_cc == a->_domain_cc &&
6980     _range_sig == a->_range_sig &&
6981     _range_cc == a->_range_cc;
6982 }
6983 
6984 //------------------------------hash-------------------------------------------
6985 // Type-specific hashing function.
6986 int TypeFunc::hash(void) const {
6987   return (intptr_t)_domain_sig + (intptr_t)_domain_cc + (intptr_t)_range_sig + (intptr_t)_range_cc;
6988 }
6989 
6990 //------------------------------dump2------------------------------------------
6991 // Dump Function Type
6992 #ifndef PRODUCT
6993 void TypeFunc::dump2( Dict &d, uint depth, outputStream *st ) const {
6994   if( _range_sig->cnt() <= Parms )
6995     st->print("void");
6996   else {
6997     uint i;
6998     for (i = Parms; i < _range_sig->cnt()-1; i++) {
6999       _range_sig->field_at(i)->dump2(d,depth,st);
7000       st->print("/");
7001     }
7002     _range_sig->field_at(i)->dump2(d,depth,st);
7003   }
7004   st->print(" ");
7005   st->print("( ");
7006   if( !depth || d[this] ) {     // Check for recursive dump
7007     st->print("...)");
7008     return;
7009   }
7010   d.Insert((void*)this,(void*)this);    // Stop recursion
7011   if (Parms < _domain_sig->cnt())
7012     _domain_sig->field_at(Parms)->dump2(d,depth-1,st);
7013   for (uint i = Parms+1; i < _domain_sig->cnt(); i++) {
7014     st->print(", ");
7015     _domain_sig->field_at(i)->dump2(d,depth-1,st);
7016   }
7017   st->print(" )");
7018 }
7019 #endif
7020 
7021 //------------------------------singleton--------------------------------------
7022 // TRUE if Type is a singleton type, FALSE otherwise.   Singletons are simple
7023 // constants (Ldi nodes).  Singletons are integer, float or double constants
7024 // or a single symbol.
7025 bool TypeFunc::singleton(void) const {
7026   return false;                 // Never a singleton
7027 }
7028 
7029 bool TypeFunc::empty(void) const {
7030   return false;                 // Never empty
7031 }
7032 
7033 
7034 BasicType TypeFunc::return_type() const{
7035   if (range_sig()->cnt() == TypeFunc::Parms) {
7036     return T_VOID;
7037   }
7038   return range_sig()->field_at(TypeFunc::Parms)->basic_type();
7039 }
< prev index next >