< 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/symbolTable.hpp"
  29 #include "classfile/systemDictionary.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 
  43 // Portions of code courtesy of Clifford Click
  44 
  45 // Optimization - Graph Style
  46 
  47 // Dictionary of types shared among compilations.
  48 Dict* Type::_shared_type_dict = NULL;














































  49 
  50 // Array which maps compiler types to Basic Types
  51 const Type::TypeInfo Type::_type_info[Type::lastype] = {
  52   { Bad,             T_ILLEGAL,    "bad",           false, Node::NotAMachineReg, relocInfo::none          },  // Bad
  53   { Control,         T_ILLEGAL,    "control",       false, 0,                    relocInfo::none          },  // Control
  54   { Bottom,          T_VOID,       "top",           false, 0,                    relocInfo::none          },  // Top
  55   { Bad,             T_INT,        "int:",          false, Op_RegI,              relocInfo::none          },  // Int
  56   { Bad,             T_LONG,       "long:",         false, Op_RegL,              relocInfo::none          },  // Long
  57   { Half,            T_VOID,       "half",          false, 0,                    relocInfo::none          },  // Half
  58   { Bad,             T_NARROWOOP,  "narrowoop:",    false, Op_RegN,              relocInfo::none          },  // NarrowOop
  59   { Bad,             T_NARROWKLASS,"narrowklass:",  false, Op_RegN,              relocInfo::none          },  // NarrowKlass
  60   { Bad,             T_ILLEGAL,    "tuple:",        false, Node::NotAMachineReg, relocInfo::none          },  // Tuple
  61   { Bad,             T_ARRAY,      "array:",        false, Node::NotAMachineReg, relocInfo::none          },  // Array
  62 
  63 #ifdef SPARC
  64   { Bad,             T_ILLEGAL,    "vectors:",      false, 0,                    relocInfo::none          },  // VectorS
  65   { Bad,             T_ILLEGAL,    "vectord:",      false, Op_RegD,              relocInfo::none          },  // VectorD
  66   { Bad,             T_ILLEGAL,    "vectorx:",      false, 0,                    relocInfo::none          },  // VectorX
  67   { Bad,             T_ILLEGAL,    "vectory:",      false, 0,                    relocInfo::none          },  // VectorY
  68   { Bad,             T_ILLEGAL,    "vectorz:",      false, 0,                    relocInfo::none          },  // VectorZ
  69 #elif defined(PPC64)
  70   { Bad,             T_ILLEGAL,    "vectors:",      false, 0,                    relocInfo::none          },  // VectorS
  71   { Bad,             T_ILLEGAL,    "vectord:",      false, Op_RegL,              relocInfo::none          },  // VectorD
  72   { Bad,             T_ILLEGAL,    "vectorx:",      false, Op_VecX,              relocInfo::none          },  // VectorX
  73   { Bad,             T_ILLEGAL,    "vectory:",      false, 0,                    relocInfo::none          },  // VectorY
  74   { Bad,             T_ILLEGAL,    "vectorz:",      false, 0,                    relocInfo::none          },  // VectorZ
  75 #elif defined(S390)
  76   { Bad,             T_ILLEGAL,    "vectors:",      false, 0,                    relocInfo::none          },  // VectorS
  77   { Bad,             T_ILLEGAL,    "vectord:",      false, Op_RegL,              relocInfo::none          },  // VectorD
  78   { Bad,             T_ILLEGAL,    "vectorx:",      false, 0,                    relocInfo::none          },  // VectorX
  79   { Bad,             T_ILLEGAL,    "vectory:",      false, 0,                    relocInfo::none          },  // VectorY
  80   { Bad,             T_ILLEGAL,    "vectorz:",      false, 0,                    relocInfo::none          },  // VectorZ
  81 #else // all other
  82   { Bad,             T_ILLEGAL,    "vectors:",      false, Op_VecS,              relocInfo::none          },  // VectorS
  83   { Bad,             T_ILLEGAL,    "vectord:",      false, Op_VecD,              relocInfo::none          },  // VectorD
  84   { Bad,             T_ILLEGAL,    "vectorx:",      false, Op_VecX,              relocInfo::none          },  // VectorX
  85   { Bad,             T_ILLEGAL,    "vectory:",      false, Op_VecY,              relocInfo::none          },  // VectorY
  86   { Bad,             T_ILLEGAL,    "vectorz:",      false, Op_VecZ,              relocInfo::none          },  // VectorZ
  87 #endif

  88   { Bad,             T_ADDRESS,    "anyptr:",       false, Op_RegP,              relocInfo::none          },  // AnyPtr
  89   { Bad,             T_ADDRESS,    "rawptr:",       false, Op_RegP,              relocInfo::none          },  // RawPtr
  90   { Bad,             T_OBJECT,     "oop:",          true,  Op_RegP,              relocInfo::oop_type      },  // OopPtr
  91   { Bad,             T_OBJECT,     "inst:",         true,  Op_RegP,              relocInfo::oop_type      },  // InstPtr
  92   { Bad,             T_OBJECT,     "ary:",          true,  Op_RegP,              relocInfo::oop_type      },  // AryPtr
  93   { Bad,             T_METADATA,   "metadata:",     false, Op_RegP,              relocInfo::metadata_type },  // MetadataPtr
  94   { Bad,             T_METADATA,   "klass:",        false, Op_RegP,              relocInfo::metadata_type },  // KlassPtr
  95   { Bad,             T_OBJECT,     "func",          false, 0,                    relocInfo::none          },  // Function
  96   { Abio,            T_ILLEGAL,    "abIO",          false, 0,                    relocInfo::none          },  // Abio
  97   { Return_Address,  T_ADDRESS,    "return_address",false, Op_RegP,              relocInfo::none          },  // Return_Address
  98   { Memory,          T_ILLEGAL,    "memory",        false, 0,                    relocInfo::none          },  // Memory
  99   { FloatBot,        T_FLOAT,      "float_top",     false, Op_RegF,              relocInfo::none          },  // FloatTop
 100   { FloatCon,        T_FLOAT,      "ftcon:",        false, Op_RegF,              relocInfo::none          },  // FloatCon
 101   { FloatTop,        T_FLOAT,      "float",         false, Op_RegF,              relocInfo::none          },  // FloatBot
 102   { DoubleBot,       T_DOUBLE,     "double_top",    false, Op_RegD,              relocInfo::none          },  // DoubleTop
 103   { DoubleCon,       T_DOUBLE,     "dblcon:",       false, Op_RegD,              relocInfo::none          },  // DoubleCon
 104   { DoubleTop,       T_DOUBLE,     "double",        false, Op_RegD,              relocInfo::none          },  // DoubleBot
 105   { Top,             T_ILLEGAL,    "bottom",        false, 0,                    relocInfo::none          }   // Bottom
 106 };
 107 


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










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

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

 283     default:                          break;
 284   }
 285   switch (loadbt) {
 286     case T_BOOLEAN:   loadbt = T_BYTE;   break;
 287     case T_NARROWOOP: loadbt = T_OBJECT; break;
 288     case T_ARRAY:     loadbt = T_OBJECT; break;

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


 506   const Type **ffalse =(const Type**)shared_type_arena->Amalloc_4(2*sizeof(Type*));
 507   ffalse[0] = Type::CONTROL;
 508   ffalse[1] = Type::TOP;
 509   TypeTuple::IFFALSE = TypeTuple::make( 2, ffalse );
 510 
 511   const Type **fneither =(const Type**)shared_type_arena->Amalloc_4(2*sizeof(Type*));
 512   fneither[0] = Type::TOP;
 513   fneither[1] = Type::TOP;
 514   TypeTuple::IFNEITHER = TypeTuple::make( 2, fneither );
 515 
 516   const Type **ftrue =(const Type**)shared_type_arena->Amalloc_4(2*sizeof(Type*));
 517   ftrue[0] = Type::TOP;
 518   ftrue[1] = Type::CONTROL;
 519   TypeTuple::IFTRUE = TypeTuple::make( 2, ftrue );
 520 
 521   const Type **floop =(const Type**)shared_type_arena->Amalloc_4(2*sizeof(Type*));
 522   floop[0] = Type::CONTROL;
 523   floop[1] = TypeInt::INT;
 524   TypeTuple::LOOPBODY = TypeTuple::make( 2, floop );
 525 
 526   TypePtr::NULL_PTR= TypePtr::make(AnyPtr, TypePtr::Null, 0);
 527   TypePtr::NOTNULL = TypePtr::make(AnyPtr, TypePtr::NotNull, OffsetBot);
 528   TypePtr::BOTTOM  = TypePtr::make(AnyPtr, TypePtr::BotPTR, OffsetBot);
 529 
 530   TypeRawPtr::BOTTOM = TypeRawPtr::make( TypePtr::BotPTR );
 531   TypeRawPtr::NOTNULL= TypeRawPtr::make( TypePtr::NotNull );
 532 
 533   const Type **fmembar = TypeTuple::fields(0);
 534   TypeTuple::MEMBAR = TypeTuple::make(TypeFunc::Parms+0, fmembar);
 535 
 536   const Type **fsc = (const Type**)shared_type_arena->Amalloc_4(2*sizeof(Type*));
 537   fsc[0] = TypeInt::CC;
 538   fsc[1] = Type::MEMORY;
 539   TypeTuple::STORECONDITIONAL = TypeTuple::make(2, fsc);
 540 
 541   TypeInstPtr::NOTNULL = TypeInstPtr::make(TypePtr::NotNull, current->env()->Object_klass());
 542   TypeInstPtr::BOTTOM  = TypeInstPtr::make(TypePtr::BotPTR,  current->env()->Object_klass());
 543   TypeInstPtr::MIRROR  = TypeInstPtr::make(TypePtr::NotNull, current->env()->Class_klass());
 544   TypeInstPtr::MARK    = TypeInstPtr::make(TypePtr::BotPTR,  current->env()->Object_klass(),
 545                                            false, 0, oopDesc::mark_offset_in_bytes());
 546   TypeInstPtr::KLASS   = TypeInstPtr::make(TypePtr::BotPTR,  current->env()->Object_klass(),
 547                                            false, 0, oopDesc::klass_offset_in_bytes());
 548   TypeOopPtr::BOTTOM  = TypeOopPtr::make(TypePtr::BotPTR, OffsetBot, TypeOopPtr::InstanceBot);


 549 
 550   TypeMetadataPtr::BOTTOM = TypeMetadataPtr::make(TypePtr::BotPTR, NULL, OffsetBot);
 551 
 552   TypeNarrowOop::NULL_PTR = TypeNarrowOop::make( TypePtr::NULL_PTR );
 553   TypeNarrowOop::BOTTOM   = TypeNarrowOop::make( TypeInstPtr::BOTTOM );
 554 
 555   TypeNarrowKlass::NULL_PTR = TypeNarrowKlass::make( TypePtr::NULL_PTR );
 556 
 557   mreg2type[Op_Node] = Type::BOTTOM;
 558   mreg2type[Op_Set ] = 0;
 559   mreg2type[Op_RegN] = TypeNarrowOop::BOTTOM;
 560   mreg2type[Op_RegI] = TypeInt::INT;
 561   mreg2type[Op_RegP] = TypePtr::BOTTOM;
 562   mreg2type[Op_RegF] = Type::FLOAT;
 563   mreg2type[Op_RegD] = Type::DOUBLE;
 564   mreg2type[Op_RegL] = TypeLong::LONG;
 565   mreg2type[Op_RegFlags] = TypeInt::CC;
 566 
 567   TypeAryPtr::RANGE   = TypeAryPtr::make( TypePtr::BotPTR, TypeAry::make(Type::BOTTOM,TypeInt::POS), NULL /* current->env()->Object_klass() */, false, arrayOopDesc::length_offset_in_bytes());
 568 
 569   TypeAryPtr::NARROWOOPS = TypeAryPtr::make(TypePtr::BotPTR, TypeAry::make(TypeNarrowOop::BOTTOM, TypeInt::POS), NULL /*ciArrayKlass::make(o)*/,  false,  Type::OffsetBot);
 570 
 571 #ifdef _LP64
 572   if (UseCompressedOops) {
 573     assert(TypeAryPtr::NARROWOOPS->is_ptr_to_narrowoop(), "array of narrow oops must be ptr to narrow oop");
 574     TypeAryPtr::OOPS  = TypeAryPtr::NARROWOOPS;
 575   } else
 576 #endif
 577   {
 578     // There is no shared klass for Object[].  See note in TypeAryPtr::klass().
 579     TypeAryPtr::OOPS  = TypeAryPtr::make(TypePtr::BotPTR, TypeAry::make(TypeInstPtr::BOTTOM,TypeInt::POS), NULL /*ciArrayKlass::make(o)*/,  false,  Type::OffsetBot);
 580   }
 581   TypeAryPtr::BYTES   = TypeAryPtr::make(TypePtr::BotPTR, TypeAry::make(TypeInt::BYTE      ,TypeInt::POS), ciTypeArrayKlass::make(T_BYTE),   true,  Type::OffsetBot);
 582   TypeAryPtr::SHORTS  = TypeAryPtr::make(TypePtr::BotPTR, TypeAry::make(TypeInt::SHORT     ,TypeInt::POS), ciTypeArrayKlass::make(T_SHORT),  true,  Type::OffsetBot);
 583   TypeAryPtr::CHARS   = TypeAryPtr::make(TypePtr::BotPTR, TypeAry::make(TypeInt::CHAR      ,TypeInt::POS), ciTypeArrayKlass::make(T_CHAR),   true,  Type::OffsetBot);
 584   TypeAryPtr::INTS    = TypeAryPtr::make(TypePtr::BotPTR, TypeAry::make(TypeInt::INT       ,TypeInt::POS), ciTypeArrayKlass::make(T_INT),    true,  Type::OffsetBot);
 585   TypeAryPtr::LONGS   = TypeAryPtr::make(TypePtr::BotPTR, TypeAry::make(TypeLong::LONG     ,TypeInt::POS), ciTypeArrayKlass::make(T_LONG),   true,  Type::OffsetBot);
 586   TypeAryPtr::FLOATS  = TypeAryPtr::make(TypePtr::BotPTR, TypeAry::make(Type::FLOAT        ,TypeInt::POS), ciTypeArrayKlass::make(T_FLOAT),  true,  Type::OffsetBot);
 587   TypeAryPtr::DOUBLES = TypeAryPtr::make(TypePtr::BotPTR, TypeAry::make(Type::DOUBLE       ,TypeInt::POS), ciTypeArrayKlass::make(T_DOUBLE), true,  Type::OffsetBot);

 588 
 589   // Nobody should ask _array_body_type[T_NARROWOOP]. Use NULL as assert.
 590   TypeAryPtr::_array_body_type[T_NARROWOOP] = NULL;
 591   TypeAryPtr::_array_body_type[T_OBJECT]  = TypeAryPtr::OOPS;

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

 642   _const_basic_type[T_VOID]        = TypePtr::NULL_PTR;   // reflection represents void this way
 643   _const_basic_type[T_ADDRESS]     = TypeRawPtr::BOTTOM;  // both interpreter return addresses & random raw ptrs
 644   _const_basic_type[T_CONFLICT]    = Type::BOTTOM;        // why not?
 645 
 646   _zero_type[T_NARROWOOP]   = TypeNarrowOop::NULL_PTR;
 647   _zero_type[T_NARROWKLASS] = TypeNarrowKlass::NULL_PTR;
 648   _zero_type[T_BOOLEAN]     = TypeInt::ZERO;     // false == 0
 649   _zero_type[T_CHAR]        = TypeInt::ZERO;     // '\0' == 0
 650   _zero_type[T_BYTE]        = TypeInt::ZERO;     // 0x00 == 0
 651   _zero_type[T_SHORT]       = TypeInt::ZERO;     // 0x0000 == 0
 652   _zero_type[T_INT]         = TypeInt::ZERO;
 653   _zero_type[T_LONG]        = TypeLong::ZERO;
 654   _zero_type[T_FLOAT]       = TypeF::ZERO;
 655   _zero_type[T_DOUBLE]      = TypeD::ZERO;
 656   _zero_type[T_OBJECT]      = TypePtr::NULL_PTR;
 657   _zero_type[T_ARRAY]       = TypePtr::NULL_PTR; // null array is null oop

 658   _zero_type[T_ADDRESS]     = TypePtr::NULL_PTR; // raw pointers use the same null
 659   _zero_type[T_VOID]        = Type::TOP;         // the only void value is no value at all
 660 
 661   // get_zero_type() should not happen for T_CONFLICT
 662   _zero_type[T_CONFLICT]= NULL;
 663 
 664   // Vector predefined types, it needs initialized _const_basic_type[].
 665   if (Matcher::vector_size_supported(T_BYTE,4)) {
 666     TypeVect::VECTS = TypeVect::make(T_BYTE,4);
 667   }
 668   if (Matcher::vector_size_supported(T_FLOAT,2)) {
 669     TypeVect::VECTD = TypeVect::make(T_FLOAT,2);
 670   }
 671   if (Matcher::vector_size_supported(T_FLOAT,4)) {
 672     TypeVect::VECTX = TypeVect::make(T_FLOAT,4);
 673   }
 674   if (Matcher::vector_size_supported(T_FLOAT,8)) {
 675     TypeVect::VECTY = TypeVect::make(T_FLOAT,8);
 676   }
 677   if (Matcher::vector_size_supported(T_FLOAT,16)) {


 890 
 891   case OopPtr:
 892     return t->xmeet(this);
 893 
 894   case InstPtr:
 895     return t->xmeet(this);
 896 
 897   case MetadataPtr:
 898   case KlassPtr:
 899     return t->xmeet(this);
 900 
 901   case AryPtr:
 902     return t->xmeet(this);
 903 
 904   case NarrowOop:
 905     return t->xmeet(this);
 906 
 907   case NarrowKlass:
 908     return t->xmeet(this);
 909 



 910   case Bad:                     // Type check
 911   default:                      // Bogus type not in lattice
 912     typerr(t);
 913     return Type::BOTTOM;
 914 
 915   case Bottom:                  // Ye Olde Default
 916     return t;
 917 
 918   case FloatTop:
 919     if( _base == FloatTop ) return this;
 920   case FloatBot:                // Float
 921     if( _base == FloatBot || _base == FloatTop ) return FLOAT;
 922     if( _base == DoubleTop || _base == DoubleBot ) return Type::BOTTOM;
 923     typerr(t);
 924     return Type::BOTTOM;
 925 
 926   case DoubleTop:
 927     if( _base == DoubleTop ) return this;
 928   case DoubleBot:               // Double
 929     if( _base == DoubleBot || _base == DoubleTop ) return DOUBLE;


 957 
 958 //------------------------------xdual------------------------------------------
 959 // Compute dual right now.
 960 const Type::TYPES Type::dual_type[Type::lastype] = {
 961   Bad,          // Bad
 962   Control,      // Control
 963   Bottom,       // Top
 964   Bad,          // Int - handled in v-call
 965   Bad,          // Long - handled in v-call
 966   Half,         // Half
 967   Bad,          // NarrowOop - handled in v-call
 968   Bad,          // NarrowKlass - handled in v-call
 969 
 970   Bad,          // Tuple - handled in v-call
 971   Bad,          // Array - handled in v-call
 972   Bad,          // VectorS - handled in v-call
 973   Bad,          // VectorD - handled in v-call
 974   Bad,          // VectorX - handled in v-call
 975   Bad,          // VectorY - handled in v-call
 976   Bad,          // VectorZ - handled in v-call

 977 
 978   Bad,          // AnyPtr - handled in v-call
 979   Bad,          // RawPtr - handled in v-call
 980   Bad,          // OopPtr - handled in v-call
 981   Bad,          // InstPtr - handled in v-call
 982   Bad,          // AryPtr - handled in v-call
 983 
 984   Bad,          //  MetadataPtr - handled in v-call
 985   Bad,          // KlassPtr - handled in v-call
 986 
 987   Bad,          // Function - handled in v-call
 988   Abio,         // Abio
 989   Return_Address,// Return_Address
 990   Memory,       // Memory
 991   FloatBot,     // FloatTop
 992   FloatCon,     // FloatCon
 993   FloatTop,     // FloatBot
 994   DoubleBot,    // DoubleTop
 995   DoubleCon,    // DoubleCon
 996   DoubleTop,    // DoubleBot


1852 
1853 bool TypeLong::empty(void) const {
1854   return _lo > _hi;
1855 }
1856 
1857 //=============================================================================
1858 // Convenience common pre-built types.
1859 const TypeTuple *TypeTuple::IFBOTH;     // Return both arms of IF as reachable
1860 const TypeTuple *TypeTuple::IFFALSE;
1861 const TypeTuple *TypeTuple::IFTRUE;
1862 const TypeTuple *TypeTuple::IFNEITHER;
1863 const TypeTuple *TypeTuple::LOOPBODY;
1864 const TypeTuple *TypeTuple::MEMBAR;
1865 const TypeTuple *TypeTuple::STORECONDITIONAL;
1866 const TypeTuple *TypeTuple::START_I2C;
1867 const TypeTuple *TypeTuple::INT_PAIR;
1868 const TypeTuple *TypeTuple::LONG_PAIR;
1869 const TypeTuple *TypeTuple::INT_CC_PAIR;
1870 const TypeTuple *TypeTuple::LONG_CC_PAIR;
1871 


















1872 
1873 //------------------------------make-------------------------------------------
1874 // Make a TypeTuple from the range of a method signature
1875 const TypeTuple *TypeTuple::make_range(ciSignature* sig) {
1876   ciType* return_type = sig->return_type();
1877   uint arg_cnt = return_type->size();




1878   const Type **field_array = fields(arg_cnt);
1879   switch (return_type->basic_type()) {
1880   case T_LONG:
1881     field_array[TypeFunc::Parms]   = TypeLong::LONG;
1882     field_array[TypeFunc::Parms+1] = Type::HALF;
1883     break;
1884   case T_DOUBLE:
1885     field_array[TypeFunc::Parms]   = Type::DOUBLE;
1886     field_array[TypeFunc::Parms+1] = Type::HALF;
1887     break;
1888   case T_OBJECT:
1889   case T_ARRAY:
1890   case T_BOOLEAN:
1891   case T_CHAR:
1892   case T_FLOAT:
1893   case T_BYTE:
1894   case T_SHORT:
1895   case T_INT:
1896     field_array[TypeFunc::Parms] = get_const_type(return_type);
1897     break;











1898   case T_VOID:
1899     break;
1900   default:
1901     ShouldNotReachHere();
1902   }
1903   return (TypeTuple*)(new TypeTuple(TypeFunc::Parms + arg_cnt, field_array))->hashcons();
1904 }
1905 
1906 // Make a TypeTuple from the domain of a method signature
1907 const TypeTuple *TypeTuple::make_domain(ciInstanceKlass* recv, ciSignature* sig) {
1908   uint arg_cnt = sig->size();









1909 
1910   uint pos = TypeFunc::Parms;
1911   const Type **field_array;
1912   if (recv != NULL) {
1913     arg_cnt++;
1914     field_array = fields(arg_cnt);
1915     // Use get_const_type here because it respects UseUniqueSubclasses:
1916     field_array[pos++] = get_const_type(recv)->join_speculative(TypePtr::NOTNULL);
1917   } else {
1918     field_array = fields(arg_cnt);



1919   }
1920 
1921   int i = 0;
1922   while (pos < TypeFunc::Parms + arg_cnt) {
1923     ciType* type = sig->type_at(i);


1924 
1925     switch (type->basic_type()) {
1926     case T_LONG:
1927       field_array[pos++] = TypeLong::LONG;
1928       field_array[pos++] = Type::HALF;
1929       break;
1930     case T_DOUBLE:
1931       field_array[pos++] = Type::DOUBLE;
1932       field_array[pos++] = Type::HALF;
1933       break;
1934     case T_OBJECT:
1935     case T_ARRAY:
1936     case T_FLOAT:
1937     case T_INT:
1938       field_array[pos++] = get_const_type(type);
1939       break;
1940     case T_BOOLEAN:
1941     case T_CHAR:
1942     case T_BYTE:
1943     case T_SHORT:
1944       field_array[pos++] = TypeInt::INT;
1945       break;










1946     default:
1947       ShouldNotReachHere();
1948     }







1949     i++;
1950   }

1951 
1952   return (TypeTuple*)(new TypeTuple(TypeFunc::Parms + arg_cnt, field_array))->hashcons();
1953 }
1954 
1955 const TypeTuple *TypeTuple::make( uint cnt, const Type **fields ) {
1956   return (TypeTuple*)(new TypeTuple(cnt,fields))->hashcons();
1957 }
1958 
1959 //------------------------------fields-----------------------------------------
1960 // Subroutine call type with space allocated for argument types
1961 // Memory for Control, I_O, Memory, FramePtr, and ReturnAdr is allocated implicitly
1962 const Type **TypeTuple::fields( uint arg_cnt ) {
1963   const Type **flds = (const Type **)(Compile::current()->type_arena()->Amalloc_4((TypeFunc::Parms+arg_cnt)*sizeof(Type*) ));
1964   flds[TypeFunc::Control  ] = Type::CONTROL;
1965   flds[TypeFunc::I_O      ] = Type::ABIO;
1966   flds[TypeFunc::Memory   ] = Type::MEMORY;
1967   flds[TypeFunc::FramePtr ] = TypeRawPtr::BOTTOM;
1968   flds[TypeFunc::ReturnAdr] = Type::RETURN_ADDRESS;
1969 
1970   return flds;


2065     if (_fields[i]->empty())  return true;
2066   }
2067   return false;
2068 }
2069 
2070 //=============================================================================
2071 // Convenience common pre-built types.
2072 
2073 inline const TypeInt* normalize_array_size(const TypeInt* size) {
2074   // Certain normalizations keep us sane when comparing types.
2075   // We do not want arrayOop variables to differ only by the wideness
2076   // of their index types.  Pick minimum wideness, since that is the
2077   // forced wideness of small ranges anyway.
2078   if (size->_widen != Type::WidenMin)
2079     return TypeInt::make(size->_lo, size->_hi, Type::WidenMin);
2080   else
2081     return size;
2082 }
2083 
2084 //------------------------------make-------------------------------------------
2085 const TypeAry* TypeAry::make(const Type* elem, const TypeInt* size, bool stable) {

2086   if (UseCompressedOops && elem->isa_oopptr()) {
2087     elem = elem->make_narrowoop();
2088   }
2089   size = normalize_array_size(size);
2090   return (TypeAry*)(new TypeAry(elem,size,stable))->hashcons();
2091 }
2092 
2093 //------------------------------meet-------------------------------------------
2094 // Compute the MEET of two types.  It returns a new Type object.
2095 const Type *TypeAry::xmeet( const Type *t ) const {
2096   // Perform a fast test for common case; meeting the same types together.
2097   if( this == t ) return this;  // Meeting same type-rep?
2098 
2099   // Current "this->_base" is Ary
2100   switch (t->base()) {          // switch on original type
2101 
2102   case Bottom:                  // Ye Olde Default
2103     return t;
2104 
2105   default:                      // All else is a mistake
2106     typerr(t);
2107 
2108   case Array: {                 // Meeting 2 arrays?
2109     const TypeAry *a = t->is_ary();
2110     return TypeAry::make(_elem->meet_speculative(a->_elem),
2111                          _size->xmeet(a->_size)->is_int(),
2112                          _stable && a->_stable);


2113   }
2114   case Top:
2115     break;
2116   }
2117   return this;                  // Return the double constant
2118 }
2119 
2120 //------------------------------xdual------------------------------------------
2121 // Dual: compute field-by-field dual
2122 const Type *TypeAry::xdual() const {
2123   const TypeInt* size_dual = _size->dual()->is_int();
2124   size_dual = normalize_array_size(size_dual);
2125   return new TypeAry(_elem->dual(), size_dual, !_stable);
2126 }
2127 
2128 //------------------------------eq---------------------------------------------
2129 // Structural equality check for Type representations
2130 bool TypeAry::eq( const Type *t ) const {
2131   const TypeAry *a = (const TypeAry*)t;
2132   return _elem == a->_elem &&
2133     _stable == a->_stable &&
2134     _size == a->_size;



2135 }
2136 
2137 //------------------------------hash-------------------------------------------
2138 // Type-specific hashing function.
2139 int TypeAry::hash(void) const {
2140   return (intptr_t)_elem + (intptr_t)_size + (_stable ? 43 : 0);
2141 }
2142 
2143 /**
2144  * Return same type without a speculative part in the element
2145  */
2146 const Type* TypeAry::remove_speculative() const {
2147   return make(_elem->remove_speculative(), _size, _stable);
2148 }
2149 
2150 /**
2151  * Return same type with cleaned up speculative part of element
2152  */
2153 const Type* TypeAry::cleanup_speculative() const {
2154   return make(_elem->cleanup_speculative(), _size, _stable);
2155 }
2156 
2157 /**
2158  * Return same type but with a different inline depth (used for speculation)
2159  *
2160  * @param depth  depth to meet with
2161  */
2162 const TypePtr* TypePtr::with_inline_depth(int depth) const {
2163   if (!UseInlineDepthForSpeculativeTypes) {
2164     return this;
2165   }
2166   return make(AnyPtr, _ptr, _offset, _speculative, depth);
2167 }
2168 
2169 //----------------------interface_vs_oop---------------------------------------
2170 #ifdef ASSERT
2171 bool TypeAry::interface_vs_oop(const Type *t) const {
2172   const TypeAry* t_ary = t->is_ary();
2173   if (t_ary) {
2174     const TypePtr* this_ptr = _elem->make_ptr(); // In case we have narrow_oops
2175     const TypePtr*    t_ptr = t_ary->_elem->make_ptr();
2176     if(this_ptr != NULL && t_ptr != NULL) {
2177       return this_ptr->interface_vs_oop(t_ptr);
2178     }
2179   }
2180   return false;
2181 }
2182 #endif
2183 
2184 //------------------------------dump2------------------------------------------
2185 #ifndef PRODUCT
2186 void TypeAry::dump2( Dict &d, uint depth, outputStream *st ) const {
2187   if (_stable)  st->print("stable:");




2188   _elem->dump2(d, depth, st);
2189   st->print("[");
2190   _size->dump2(d, depth, st);
2191   st->print("]");
2192 }
2193 #endif
2194 
2195 //------------------------------singleton--------------------------------------
2196 // TRUE if Type is a singleton type, FALSE otherwise.   Singletons are simple
2197 // constants (Ldi nodes).  Singletons are integer, float or double constants
2198 // or a single symbol.
2199 bool TypeAry::singleton(void) const {
2200   return false;                 // Never a singleton
2201 }
2202 
2203 bool TypeAry::empty(void) const {
2204   return _elem->empty() || _size->empty();
2205 }
2206 
2207 //--------------------------ary_must_be_exact----------------------------------


2210   // This logic looks at the element type of an array, and returns true
2211   // if the element type is either a primitive or a final instance class.
2212   // In such cases, an array built on this ary must have no subclasses.
2213   if (_elem == BOTTOM)      return false;  // general array not exact
2214   if (_elem == TOP   )      return false;  // inverted general array not exact
2215   const TypeOopPtr*  toop = NULL;
2216   if (UseCompressedOops && _elem->isa_narrowoop()) {
2217     toop = _elem->make_ptr()->isa_oopptr();
2218   } else {
2219     toop = _elem->isa_oopptr();
2220   }
2221   if (!toop)                return true;   // a primitive type, like int
2222   ciKlass* tklass = toop->klass();
2223   if (tklass == NULL)       return false;  // unloaded class
2224   if (!tklass->is_loaded()) return false;  // unloaded class
2225   const TypeInstPtr* tinst;
2226   if (_elem->isa_narrowoop())
2227     tinst = _elem->make_ptr()->isa_instptr();
2228   else
2229     tinst = _elem->isa_instptr();
2230   if (tinst)
2231     return tklass->as_instance_klass()->is_final();








2232   const TypeAryPtr*  tap;
2233   if (_elem->isa_narrowoop())
2234     tap = _elem->make_ptr()->isa_aryptr();
2235   else
2236     tap = _elem->isa_aryptr();
2237   if (tap)
2238     return tap->ary()->ary_must_be_exact();
2239   return false;
2240 }
2241 




























































































































2242 //==============================TypeVect=======================================
2243 // Convenience common pre-built types.
2244 const TypeVect *TypeVect::VECTS = NULL; //  32-bit vectors
2245 const TypeVect *TypeVect::VECTD = NULL; //  64-bit vectors
2246 const TypeVect *TypeVect::VECTX = NULL; // 128-bit vectors
2247 const TypeVect *TypeVect::VECTY = NULL; // 256-bit vectors
2248 const TypeVect *TypeVect::VECTZ = NULL; // 512-bit vectors
2249 
2250 //------------------------------make-------------------------------------------
2251 const TypeVect* TypeVect::make(const Type *elem, uint length) {
2252   BasicType elem_bt = elem->array_element_basic_type();
2253   assert(is_java_primitive(elem_bt), "only primitive types in vector");
2254   assert(length > 1 && is_power_of_2(length), "vector length is power of 2");
2255   assert(Matcher::vector_size_supported(elem_bt, length), "length in range");
2256   int size = length * type2aelembytes(elem_bt);
2257   switch (Matcher::vector_ideal_reg(size)) {
2258   case Op_VecS:
2259     return (TypeVect*)(new TypeVectS(elem, length))->hashcons();
2260   case Op_RegL:
2261   case Op_VecD:


2363 
2364 //=============================================================================
2365 // Convenience common pre-built types.
2366 const TypePtr *TypePtr::NULL_PTR;
2367 const TypePtr *TypePtr::NOTNULL;
2368 const TypePtr *TypePtr::BOTTOM;
2369 
2370 //------------------------------meet-------------------------------------------
2371 // Meet over the PTR enum
2372 const TypePtr::PTR TypePtr::ptr_meet[TypePtr::lastPTR][TypePtr::lastPTR] = {
2373   //              TopPTR,    AnyNull,   Constant, Null,   NotNull, BotPTR,
2374   { /* Top     */ TopPTR,    AnyNull,   Constant, Null,   NotNull, BotPTR,},
2375   { /* AnyNull */ AnyNull,   AnyNull,   Constant, BotPTR, NotNull, BotPTR,},
2376   { /* Constant*/ Constant,  Constant,  Constant, BotPTR, NotNull, BotPTR,},
2377   { /* Null    */ Null,      BotPTR,    BotPTR,   Null,   BotPTR,  BotPTR,},
2378   { /* NotNull */ NotNull,   NotNull,   NotNull,  BotPTR, NotNull, BotPTR,},
2379   { /* BotPTR  */ BotPTR,    BotPTR,    BotPTR,   BotPTR, BotPTR,  BotPTR,}
2380 };
2381 
2382 //------------------------------make-------------------------------------------
2383 const TypePtr *TypePtr::make(TYPES t, enum PTR ptr, int offset, const TypePtr* speculative, int inline_depth) {
2384   return (TypePtr*)(new TypePtr(t,ptr,offset, speculative, inline_depth))->hashcons();
2385 }
2386 
2387 //------------------------------cast_to_ptr_type-------------------------------
2388 const Type *TypePtr::cast_to_ptr_type(PTR ptr) const {
2389   assert(_base == AnyPtr, "subclass must override cast_to_ptr_type");
2390   if( ptr == _ptr ) return this;
2391   return make(_base, ptr, _offset, _speculative, _inline_depth);
2392 }
2393 
2394 //------------------------------get_con----------------------------------------
2395 intptr_t TypePtr::get_con() const {
2396   assert( _ptr == Null, "" );
2397   return _offset;
2398 }
2399 
2400 //------------------------------meet-------------------------------------------
2401 // Compute the MEET of two types.  It returns a new Type object.
2402 const Type *TypePtr::xmeet(const Type *t) const {
2403   const Type* res = xmeet_helper(t);
2404   if (res->isa_ptr() == NULL) {
2405     return res;
2406   }
2407 
2408   const TypePtr* res_ptr = res->is_ptr();
2409   if (res_ptr->speculative() != NULL) {
2410     // type->speculative() == NULL means that speculation is no better
2411     // than type, i.e. type->speculative() == type. So there are 2
2412     // ways to represent the fact that we have no useful speculative
2413     // data and we should use a single one to be able to test for
2414     // equality between types. Check whether type->speculative() ==
2415     // type and set speculative to NULL if it is the case.
2416     if (res_ptr->remove_speculative() == res_ptr->speculative()) {
2417       return res_ptr->remove_speculative();


2446     const TypePtr *tp = t->is_ptr();
2447     const TypePtr* speculative = xmeet_speculative(tp);
2448     int depth = meet_inline_depth(tp->inline_depth());
2449     return make(AnyPtr, meet_ptr(tp->ptr()), meet_offset(tp->offset()), speculative, depth);
2450   }
2451   case RawPtr:                  // For these, flip the call around to cut down
2452   case OopPtr:
2453   case InstPtr:                 // on the cases I have to handle.
2454   case AryPtr:
2455   case MetadataPtr:
2456   case KlassPtr:
2457     return t->xmeet(this);      // Call in reverse direction
2458   default:                      // All else is a mistake
2459     typerr(t);
2460 
2461   }
2462   return this;
2463 }
2464 
2465 //------------------------------meet_offset------------------------------------
2466 int TypePtr::meet_offset( int offset ) const {
2467   // Either is 'TOP' offset?  Return the other offset!
2468   if( _offset == OffsetTop ) return offset;
2469   if( offset == OffsetTop ) return _offset;
2470   // If either is different, return 'BOTTOM' offset
2471   if( _offset != offset ) return OffsetBot;
2472   return _offset;
2473 }
2474 
2475 //------------------------------dual_offset------------------------------------
2476 int TypePtr::dual_offset( ) const {
2477   if( _offset == OffsetTop ) return OffsetBot;// Map 'TOP' into 'BOTTOM'
2478   if( _offset == OffsetBot ) return OffsetTop;// Map 'BOTTOM' into 'TOP'
2479   return _offset;               // Map everything else into self
2480 }
2481 
2482 //------------------------------xdual------------------------------------------
2483 // Dual: compute field-by-field dual
2484 const TypePtr::PTR TypePtr::ptr_dual[TypePtr::lastPTR] = {
2485   BotPTR, NotNull, Constant, Null, AnyNull, TopPTR
2486 };
2487 const Type *TypePtr::xdual() const {
2488   return new TypePtr(AnyPtr, dual_ptr(), dual_offset(), dual_speculative(), dual_inline_depth());
2489 }
2490 
2491 //------------------------------xadd_offset------------------------------------
2492 int TypePtr::xadd_offset( intptr_t offset ) const {
2493   // Adding to 'TOP' offset?  Return 'TOP'!
2494   if( _offset == OffsetTop || offset == OffsetTop ) return OffsetTop;
2495   // Adding to 'BOTTOM' offset?  Return 'BOTTOM'!
2496   if( _offset == OffsetBot || offset == OffsetBot ) return OffsetBot;
2497   // Addition overflows or "accidentally" equals to OffsetTop? Return 'BOTTOM'!
2498   offset += (intptr_t)_offset;
2499   if (offset != (int)offset || offset == OffsetTop) return OffsetBot;
2500 
2501   // assert( _offset >= 0 && _offset+offset >= 0, "" );
2502   // It is possible to construct a negative offset during PhaseCCP
2503 
2504   return (int)offset;        // Sum valid offsets
2505 }
2506 
2507 //------------------------------add_offset-------------------------------------
2508 const TypePtr *TypePtr::add_offset( intptr_t offset ) const {
2509   return make(AnyPtr, _ptr, xadd_offset(offset), _speculative, _inline_depth);
2510 }
2511 
2512 //------------------------------eq---------------------------------------------
2513 // Structural equality check for Type representations
2514 bool TypePtr::eq( const Type *t ) const {
2515   const TypePtr *a = (const TypePtr*)t;
2516   return _ptr == a->ptr() && _offset == a->offset() && eq_speculative(a) && _inline_depth == a->_inline_depth;
2517 }
2518 
2519 //------------------------------hash-------------------------------------------
2520 // Type-specific hashing function.
2521 int TypePtr::hash(void) const {
2522   return java_add(java_add((jint)_ptr, (jint)_offset), java_add((jint)hash_speculative(), (jint)_inline_depth));
2523 ;
2524 }
2525 
2526 /**
2527  * Return same type without a speculative part
2528  */
2529 const Type* TypePtr::remove_speculative() const {
2530   if (_speculative == NULL) {
2531     return this;
2532   }
2533   assert(_inline_depth == InlineDepthTop || _inline_depth == InlineDepthBottom, "non speculative type shouldn't have inline depth");
2534   return make(AnyPtr, _ptr, _offset, NULL, _inline_depth);
2535 }
2536 
2537 /**
2538  * Return same type but drop speculative part if we know we won't use
2539  * it
2540  */
2541 const Type* TypePtr::cleanup_speculative() const {
2542   if (speculative() == NULL) {


2762   }
2763   // We already know the speculative type is always null
2764   if (speculative_always_null()) {
2765     return false;
2766   }
2767   if (ptr_kind == ProfileAlwaysNull && speculative() != NULL && speculative()->isa_oopptr()) {
2768     return false;
2769   }
2770   return true;
2771 }
2772 
2773 //------------------------------dump2------------------------------------------
2774 const char *const TypePtr::ptr_msg[TypePtr::lastPTR] = {
2775   "TopPTR","AnyNull","Constant","NULL","NotNull","BotPTR"
2776 };
2777 
2778 #ifndef PRODUCT
2779 void TypePtr::dump2( Dict &d, uint depth, outputStream *st ) const {
2780   if( _ptr == Null ) st->print("NULL");
2781   else st->print("%s *", ptr_msg[_ptr]);
2782   if( _offset == OffsetTop ) st->print("+top");
2783   else if( _offset == OffsetBot ) st->print("+bot");
2784   else if( _offset ) st->print("+%d", _offset);
2785   dump_inline_depth(st);
2786   dump_speculative(st);
2787 }
2788 
2789 /**
2790  *dump the speculative part of the type
2791  */
2792 void TypePtr::dump_speculative(outputStream *st) const {
2793   if (_speculative != NULL) {
2794     st->print(" (speculative=");
2795     _speculative->dump_on(st);
2796     st->print(")");
2797   }
2798 }
2799 
2800 /**
2801  *dump the inline depth of the type
2802  */
2803 void TypePtr::dump_inline_depth(outputStream *st) const {
2804   if (_inline_depth != InlineDepthBottom) {
2805     if (_inline_depth == InlineDepthTop) {
2806       st->print(" (inline_depth=InlineDepthTop)");
2807     } else {
2808       st->print(" (inline_depth=%d)", _inline_depth);
2809     }
2810   }
2811 }
2812 #endif
2813 
2814 //------------------------------singleton--------------------------------------
2815 // TRUE if Type is a singleton type, FALSE otherwise.   Singletons are simple
2816 // constants
2817 bool TypePtr::singleton(void) const {
2818   // TopPTR, Null, AnyNull, Constant are all singletons
2819   return (_offset != OffsetBot) && !below_centerline(_ptr);
2820 }
2821 
2822 bool TypePtr::empty(void) const {
2823   return (_offset == OffsetTop) || above_centerline(_ptr);
2824 }
2825 
2826 //=============================================================================
2827 // Convenience common pre-built types.
2828 const TypeRawPtr *TypeRawPtr::BOTTOM;
2829 const TypeRawPtr *TypeRawPtr::NOTNULL;
2830 
2831 //------------------------------make-------------------------------------------
2832 const TypeRawPtr *TypeRawPtr::make( enum PTR ptr ) {
2833   assert( ptr != Constant, "what is the constant?" );
2834   assert( ptr != Null, "Use TypePtr for NULL" );
2835   return (TypeRawPtr*)(new TypeRawPtr(ptr,0))->hashcons();
2836 }
2837 
2838 const TypeRawPtr *TypeRawPtr::make( address bits ) {
2839   assert( bits, "Use TypePtr for NULL" );
2840   return (TypeRawPtr*)(new TypeRawPtr(Constant,bits))->hashcons();
2841 }
2842 
2843 //------------------------------cast_to_ptr_type-------------------------------


2945 // Type-specific hashing function.
2946 int TypeRawPtr::hash(void) const {
2947   return (intptr_t)_bits + TypePtr::hash();
2948 }
2949 
2950 //------------------------------dump2------------------------------------------
2951 #ifndef PRODUCT
2952 void TypeRawPtr::dump2( Dict &d, uint depth, outputStream *st ) const {
2953   if( _ptr == Constant )
2954     st->print(INTPTR_FORMAT, p2i(_bits));
2955   else
2956     st->print("rawptr:%s", ptr_msg[_ptr]);
2957 }
2958 #endif
2959 
2960 //=============================================================================
2961 // Convenience common pre-built type.
2962 const TypeOopPtr *TypeOopPtr::BOTTOM;
2963 
2964 //------------------------------TypeOopPtr-------------------------------------
2965 TypeOopPtr::TypeOopPtr(TYPES t, PTR ptr, ciKlass* k, bool xk, ciObject* o, int offset,
2966                        int instance_id, const TypePtr* speculative, int inline_depth)
2967   : TypePtr(t, ptr, offset, speculative, inline_depth),
2968     _const_oop(o), _klass(k),
2969     _klass_is_exact(xk),
2970     _is_ptr_to_narrowoop(false),
2971     _is_ptr_to_narrowklass(false),
2972     _is_ptr_to_boxed_value(false),
2973     _instance_id(instance_id) {
2974   if (Compile::current()->eliminate_boxing() && (t == InstPtr) &&
2975       (offset > 0) && xk && (k != 0) && k->is_instance_klass()) {
2976     _is_ptr_to_boxed_value = k->as_instance_klass()->is_boxed_value_offset(offset);
2977   }
2978 #ifdef _LP64
2979   if (_offset > 0 || _offset == Type::OffsetTop || _offset == Type::OffsetBot) {
2980     if (_offset == oopDesc::klass_offset_in_bytes()) {
2981       _is_ptr_to_narrowklass = UseCompressedClassPointers;
2982     } else if (klass() == NULL) {
2983       // Array with unknown body type
2984       assert(this->isa_aryptr(), "only arrays without klass");
2985       _is_ptr_to_narrowoop = UseCompressedOops;
2986     } else if (this->isa_aryptr()) {
2987       _is_ptr_to_narrowoop = (UseCompressedOops && klass()->is_obj_array_klass() &&
2988                              _offset != arrayOopDesc::length_offset_in_bytes());









2989     } else if (klass()->is_instance_klass()) {
2990       ciInstanceKlass* ik = klass()->as_instance_klass();
2991       ciField* field = NULL;
2992       if (this->isa_klassptr()) {
2993         // Perm objects don't use compressed references
2994       } else if (_offset == OffsetBot || _offset == OffsetTop) {
2995         // unsafe access
2996         _is_ptr_to_narrowoop = UseCompressedOops;
2997       } else { // exclude unsafe ops
2998         assert(this->isa_instptr(), "must be an instance ptr.");
2999 
3000         if (klass() == ciEnv::current()->Class_klass() &&
3001             (_offset == java_lang_Class::klass_offset_in_bytes() ||
3002              _offset == java_lang_Class::array_klass_offset_in_bytes())) {
3003           // Special hidden fields from the Class.
3004           assert(this->isa_instptr(), "must be an instance ptr.");
3005           _is_ptr_to_narrowoop = false;
3006         } else if (klass() == ciEnv::current()->Class_klass() &&
3007                    _offset >= InstanceMirrorKlass::offset_of_static_fields()) {
3008           // Static fields
3009           assert(o != NULL, "must be constant");
3010           ciInstanceKlass* k = o->as_instance()->java_lang_Class_klass()->as_instance_klass();
3011           ciField* field = k->get_field_by_offset(_offset, true);
3012           assert(field != NULL, "missing field");
3013           BasicType basic_elem_type = field->layout_type();






3014           _is_ptr_to_narrowoop = UseCompressedOops && (basic_elem_type == T_OBJECT ||

3015                                                        basic_elem_type == T_ARRAY);
3016         } else {
3017           // Instance fields which contains a compressed oop references.
3018           field = ik->get_field_by_offset(_offset, false);

3019           if (field != NULL) {
3020             BasicType basic_elem_type = field->layout_type();
3021             _is_ptr_to_narrowoop = UseCompressedOops && (basic_elem_type == T_OBJECT ||

3022                                                          basic_elem_type == T_ARRAY);
3023           } else if (klass()->equals(ciEnv::current()->Object_klass())) {
3024             // Compile::find_alias_type() cast exactness on all types to verify
3025             // that it does not affect alias type.
3026             _is_ptr_to_narrowoop = UseCompressedOops;
3027           } else {
3028             // Type for the copy start in LibraryCallKit::inline_native_clone().
3029             _is_ptr_to_narrowoop = UseCompressedOops;
3030           }
3031         }
3032       }
3033     }
3034   }
3035 #endif
3036 }
3037 
3038 //------------------------------make-------------------------------------------
3039 const TypeOopPtr *TypeOopPtr::make(PTR ptr, int offset, int instance_id,
3040                                      const TypePtr* speculative, int inline_depth) {
3041   assert(ptr != Constant, "no constant generic pointers");
3042   ciKlass*  k = Compile::current()->env()->Object_klass();
3043   bool      xk = false;
3044   ciObject* o = NULL;
3045   return (TypeOopPtr*)(new TypeOopPtr(OopPtr, ptr, k, xk, o, offset, instance_id, speculative, inline_depth))->hashcons();
3046 }
3047 
3048 
3049 //------------------------------cast_to_ptr_type-------------------------------
3050 const Type *TypeOopPtr::cast_to_ptr_type(PTR ptr) const {
3051   assert(_base == OopPtr, "subclass must override cast_to_ptr_type");
3052   if( ptr == _ptr ) return this;
3053   return make(ptr, _offset, _instance_id, _speculative, _inline_depth);
3054 }
3055 
3056 //-----------------------------cast_to_instance_id----------------------------
3057 const TypeOopPtr *TypeOopPtr::cast_to_instance_id(int instance_id) const {
3058   // There are no instances of a general oop.
3059   // Return self unchanged.
3060   return this;
3061 }
3062 
3063 const TypeOopPtr *TypeOopPtr::cast_to_nonconst() const {
3064   return this;
3065 }
3066 
3067 //-----------------------------cast_to_exactness-------------------------------
3068 const Type *TypeOopPtr::cast_to_exactness(bool klass_is_exact) const {
3069   // There is no such thing as an exact general oop.
3070   // Return self unchanged.
3071   return this;
3072 }
3073 
3074 
3075 //------------------------------as_klass_type----------------------------------
3076 // Return the klass type corresponding to this instance or array type.
3077 // It is the type that is loaded from an object of this type.
3078 const TypeKlassPtr* TypeOopPtr::as_klass_type() const {
3079   ciKlass* k = klass();
3080   bool    xk = klass_is_exact();
3081   if (k == NULL)
3082     return TypeKlassPtr::OBJECT;
3083   else
3084     return TypeKlassPtr::make(xk? Constant: NotNull, k, 0);
3085 }
3086 
3087 //------------------------------meet-------------------------------------------
3088 // Compute the MEET of two types.  It returns a new Type object.
3089 const Type *TypeOopPtr::xmeet_helper(const Type *t) const {
3090   // Perform a fast test for common case; meeting the same types together.
3091   if( this == t ) return this;  // Meeting same type-rep?
3092 
3093   // Current "this->_base" is OopPtr
3094   switch (t->base()) {          // switch on original type
3095 
3096   case Int:                     // Mixing ints & oops happens when javac
3097   case Long:                    // reuses local variables
3098   case FloatTop:
3099   case FloatCon:
3100   case FloatBot:
3101   case DoubleTop:
3102   case DoubleCon:
3103   case DoubleBot:
3104   case NarrowOop:
3105   case NarrowKlass:
3106   case Bottom:                  // Ye Olde Default
3107     return Type::BOTTOM;
3108   case Top:
3109     return this;
3110 
3111   default:                      // All else is a mistake
3112     typerr(t);
3113 
3114   case RawPtr:
3115   case MetadataPtr:
3116   case KlassPtr:
3117     return TypePtr::BOTTOM;     // Oop meet raw is not well defined
3118 
3119   case AnyPtr: {
3120     // Found an AnyPtr type vs self-OopPtr type
3121     const TypePtr *tp = t->is_ptr();
3122     int offset = meet_offset(tp->offset());
3123     PTR ptr = meet_ptr(tp->ptr());
3124     const TypePtr* speculative = xmeet_speculative(tp);
3125     int depth = meet_inline_depth(tp->inline_depth());
3126     switch (tp->ptr()) {
3127     case Null:
3128       if (ptr == Null)  return TypePtr::make(AnyPtr, ptr, offset, speculative, depth);
3129       // else fall through:
3130     case TopPTR:
3131     case AnyNull: {
3132       int instance_id = meet_instance_id(InstanceTop);
3133       return make(ptr, offset, instance_id, speculative, depth);
3134     }
3135     case BotPTR:
3136     case NotNull:
3137       return TypePtr::make(AnyPtr, ptr, offset, speculative, depth);
3138     default: typerr(t);
3139     }
3140   }
3141 
3142   case OopPtr: {                 // Meeting to other OopPtrs


3144     int instance_id = meet_instance_id(tp->instance_id());
3145     const TypePtr* speculative = xmeet_speculative(tp);
3146     int depth = meet_inline_depth(tp->inline_depth());
3147     return make(meet_ptr(tp->ptr()), meet_offset(tp->offset()), instance_id, speculative, depth);
3148   }
3149 
3150   case InstPtr:                  // For these, flip the call around to cut down
3151   case AryPtr:
3152     return t->xmeet(this);      // Call in reverse direction
3153 
3154   } // End of switch
3155   return this;                  // Return the double constant
3156 }
3157 
3158 
3159 //------------------------------xdual------------------------------------------
3160 // Dual of a pure heap pointer.  No relevant klass or oop information.
3161 const Type *TypeOopPtr::xdual() const {
3162   assert(klass() == Compile::current()->env()->Object_klass(), "no klasses here");
3163   assert(const_oop() == NULL,             "no constants here");
3164   return new TypeOopPtr(_base, dual_ptr(), klass(), klass_is_exact(), const_oop(), dual_offset(), dual_instance_id(), dual_speculative(), dual_inline_depth());
3165 }
3166 
3167 //--------------------------make_from_klass_common-----------------------------
3168 // Computes the element-type given a klass.
3169 const TypeOopPtr* TypeOopPtr::make_from_klass_common(ciKlass *klass, bool klass_change, bool try_for_exact) {
3170   if (klass->is_instance_klass()) {
3171     Compile* C = Compile::current();
3172     Dependencies* deps = C->dependencies();
3173     assert((deps != NULL) == (C->method() != NULL && C->method()->code_size() > 0), "sanity");
3174     // Element is an instance
3175     bool klass_is_exact = false;
3176     if (klass->is_loaded()) {
3177       // Try to set klass_is_exact.
3178       ciInstanceKlass* ik = klass->as_instance_klass();
3179       klass_is_exact = ik->is_final();
3180       if (!klass_is_exact && klass_change
3181           && deps != NULL && UseUniqueSubclasses) {
3182         ciInstanceKlass* sub = ik->unique_concrete_subklass();
3183         if (sub != NULL) {
3184           deps->assert_abstract_with_unique_concrete_subtype(ik, sub);
3185           klass = ik = sub;
3186           klass_is_exact = sub->is_final();
3187         }
3188       }
3189       if (!klass_is_exact && try_for_exact
3190           && deps != NULL && UseExactTypes) {
3191         if (!ik->is_interface() && !ik->has_subklass()) {
3192           // Add a dependence; if concrete subclass added we need to recompile
3193           deps->assert_leaf_type(ik);
3194           klass_is_exact = true;
3195         }
3196       }
3197     }
3198     return TypeInstPtr::make(TypePtr::BotPTR, klass, klass_is_exact, NULL, 0);
3199   } else if (klass->is_obj_array_klass()) {
3200     // Element is an object array. Recursively call ourself.
3201     const TypeOopPtr *etype = TypeOopPtr::make_from_klass_common(klass->as_obj_array_klass()->element_klass(), false, try_for_exact);
3202     bool xk = etype->klass_is_exact();
3203     const TypeAry* arr0 = TypeAry::make(etype, TypeInt::POS);








3204     // We used to pass NotNull in here, asserting that the sub-arrays
3205     // are all not-null.  This is not true in generally, as code can
3206     // slam NULLs down in the subarrays.
3207     const TypeAryPtr* arr = TypeAryPtr::make(TypePtr::BotPTR, arr0, klass, xk, 0);
3208     return arr;
3209   } else if (klass->is_type_array_klass()) {
3210     // Element is an typeArray
3211     const Type* etype = get_const_basic_type(klass->as_type_array_klass()->element_type());
3212     const TypeAry* arr0 = TypeAry::make(etype, TypeInt::POS);

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





3216     return arr;
3217   } else {
3218     ShouldNotReachHere();
3219     return NULL;
3220   }
3221 }
3222 
3223 //------------------------------make_from_constant-----------------------------
3224 // Make a java pointer from an oop constant
3225 const TypeOopPtr* TypeOopPtr::make_from_constant(ciObject* o, bool require_constant) {
3226   assert(!o->is_null_object(), "null object not yet handled here.");
3227 
3228   const bool make_constant = require_constant || o->should_be_constant();
3229 
3230   ciKlass* klass = o->klass();
3231   if (klass->is_instance_klass()) {
3232     // Element is an instance
3233     if (make_constant) {
3234       return TypeInstPtr::make(o);
3235     } else {
3236       return TypeInstPtr::make(TypePtr::NotNull, klass, true, NULL, 0);
3237     }
3238   } else if (klass->is_obj_array_klass()) {
3239     // Element is an object array. Recursively call ourself.
3240     const TypeOopPtr *etype =
3241       TypeOopPtr::make_from_klass_raw(klass->as_obj_array_klass()->element_klass());
3242     const TypeAry* arr0 = TypeAry::make(etype, TypeInt::make(o->as_array()->length()));





3243     // We used to pass NotNull in here, asserting that the sub-arrays
3244     // are all not-null.  This is not true in generally, as code can
3245     // slam NULLs down in the subarrays.
3246     if (make_constant) {
3247       return TypeAryPtr::make(TypePtr::Constant, o, arr0, klass, true, 0);
3248     } else {
3249       return TypeAryPtr::make(TypePtr::NotNull, arr0, klass, true, 0);
3250     }
3251   } else if (klass->is_type_array_klass()) {
3252     // Element is an typeArray
3253     const Type* etype =
3254       (Type*)get_const_basic_type(klass->as_type_array_klass()->element_type());
3255     const TypeAry* arr0 = TypeAry::make(etype, TypeInt::make(o->as_array()->length()));
3256     // We used to pass NotNull in here, asserting that the array pointer
3257     // is not-null. That was not true in general.
3258     if (make_constant) {
3259       return TypeAryPtr::make(TypePtr::Constant, o, arr0, klass, true, 0);
3260     } else {
3261       return TypeAryPtr::make(TypePtr::NotNull, arr0, klass, true, 0);











3262     }
3263   }
3264 
3265   fatal("unhandled object type");
3266   return NULL;
3267 }
3268 
3269 //------------------------------get_con----------------------------------------
3270 intptr_t TypeOopPtr::get_con() const {
3271   assert( _ptr == Null || _ptr == Constant, "" );
3272   assert( _offset >= 0, "" );
3273 
3274   if (_offset != 0) {
3275     // After being ported to the compiler interface, the compiler no longer
3276     // directly manipulates the addresses of oops.  Rather, it only has a pointer
3277     // to a handle at compile time.  This handle is embedded in the generated
3278     // code and dereferenced at the time the nmethod is made.  Until that time,
3279     // it is not reasonable to do arithmetic with the addresses of oops (we don't
3280     // have access to the addresses!).  This does not seem to currently happen,
3281     // but this assertion here is to help prevent its occurence.
3282     tty->print_cr("Found oop constant with non-zero offset");
3283     ShouldNotReachHere();
3284   }
3285 
3286   return (intptr_t)const_oop()->constant_encoding();
3287 }
3288 
3289 
3290 //-----------------------------filter------------------------------------------
3291 // Do not allow interface-vs.-noninterface joins to collapse to top.
3292 const Type *TypeOopPtr::filter_helper(const Type *kills, bool include_speculative) const {
3293 
3294   const Type* ft = join_helper(kills, include_speculative);


3347     return (one == two) && TypePtr::eq(t);
3348   } else {
3349     return one->equals(two) && TypePtr::eq(t);
3350   }
3351 }
3352 
3353 //------------------------------hash-------------------------------------------
3354 // Type-specific hashing function.
3355 int TypeOopPtr::hash(void) const {
3356   return
3357     java_add(java_add((jint)(const_oop() ? const_oop()->hash() : 0), (jint)_klass_is_exact),
3358              java_add((jint)_instance_id, (jint)TypePtr::hash()));
3359 }
3360 
3361 //------------------------------dump2------------------------------------------
3362 #ifndef PRODUCT
3363 void TypeOopPtr::dump2( Dict &d, uint depth, outputStream *st ) const {
3364   st->print("oopptr:%s", ptr_msg[_ptr]);
3365   if( _klass_is_exact ) st->print(":exact");
3366   if( const_oop() ) st->print(INTPTR_FORMAT, p2i(const_oop()));
3367   switch( _offset ) {
3368   case OffsetTop: st->print("+top"); break;
3369   case OffsetBot: st->print("+any"); break;
3370   case         0: break;
3371   default:        st->print("+%d",_offset); break;
3372   }
3373   if (_instance_id == InstanceTop)
3374     st->print(",iid=top");
3375   else if (_instance_id != InstanceBot)
3376     st->print(",iid=%d",_instance_id);
3377 
3378   dump_inline_depth(st);
3379   dump_speculative(st);
3380 }
3381 #endif
3382 
3383 //------------------------------singleton--------------------------------------
3384 // TRUE if Type is a singleton type, FALSE otherwise.   Singletons are simple
3385 // constants
3386 bool TypeOopPtr::singleton(void) const {
3387   // detune optimizer to not generate constant oop + constant offset as a constant!
3388   // TopPTR, Null, AnyNull, Constant are all singletons
3389   return (_offset == 0) && !below_centerline(_ptr);
3390 }
3391 
3392 //------------------------------add_offset-------------------------------------
3393 const TypePtr *TypeOopPtr::add_offset(intptr_t offset) const {
3394   return make(_ptr, xadd_offset(offset), _instance_id, add_offset_speculative(offset), _inline_depth);
3395 }
3396 
3397 /**
3398  * Return same type without a speculative part
3399  */
3400 const Type* TypeOopPtr::remove_speculative() const {
3401   if (_speculative == NULL) {
3402     return this;
3403   }
3404   assert(_inline_depth == InlineDepthTop || _inline_depth == InlineDepthBottom, "non speculative type shouldn't have inline depth");
3405   return make(_ptr, _offset, _instance_id, NULL, _inline_depth);
3406 }
3407 
3408 /**
3409  * Return same type but drop speculative part if we know we won't use


3461  *
3462  * @return  true if type profile is valuable
3463  */
3464 bool TypeOopPtr::would_improve_type(ciKlass* exact_kls, int inline_depth) const {
3465   // no way to improve an already exact type
3466   if (klass_is_exact()) {
3467     return false;
3468   }
3469   return TypePtr::would_improve_type(exact_kls, inline_depth);
3470 }
3471 
3472 //=============================================================================
3473 // Convenience common pre-built types.
3474 const TypeInstPtr *TypeInstPtr::NOTNULL;
3475 const TypeInstPtr *TypeInstPtr::BOTTOM;
3476 const TypeInstPtr *TypeInstPtr::MIRROR;
3477 const TypeInstPtr *TypeInstPtr::MARK;
3478 const TypeInstPtr *TypeInstPtr::KLASS;
3479 
3480 //------------------------------TypeInstPtr-------------------------------------
3481 TypeInstPtr::TypeInstPtr(PTR ptr, ciKlass* k, bool xk, ciObject* o, int off,
3482                          int instance_id, const TypePtr* speculative, int inline_depth)
3483   : TypeOopPtr(InstPtr, ptr, k, xk, o, off, instance_id, speculative, inline_depth),
3484     _name(k->name()) {
3485    assert(k != NULL &&
3486           (k->is_loaded() || o == NULL),
3487           "cannot have constants with non-loaded klass");
3488 };
3489 
3490 //------------------------------make-------------------------------------------
3491 const TypeInstPtr *TypeInstPtr::make(PTR ptr,
3492                                      ciKlass* k,
3493                                      bool xk,
3494                                      ciObject* o,
3495                                      int offset,
3496                                      int instance_id,
3497                                      const TypePtr* speculative,
3498                                      int inline_depth) {
3499   assert( !k->is_loaded() || k->is_instance_klass(), "Must be for instance");
3500   // Either const_oop() is NULL or else ptr is Constant
3501   assert( (!o && ptr != Constant) || (o && ptr == Constant),
3502           "constant pointers must have a value supplied" );
3503   // Ptr is never Null
3504   assert( ptr != Null, "NULL pointers are not typed" );
3505 
3506   assert(instance_id <= 0 || xk || !UseExactTypes, "instances are always exactly typed");
3507   if (!UseExactTypes)  xk = false;
3508   if (ptr == Constant) {
3509     // Note:  This case includes meta-object constants, such as methods.
3510     xk = true;
3511   } else if (k->is_loaded()) {
3512     ciInstanceKlass* ik = k->as_instance_klass();
3513     if (!xk && ik->is_final())     xk = true;   // no inexact final klass
3514     if (xk && ik->is_interface())  xk = false;  // no exact interface
3515   }


3562   if( (ik->is_final() || _const_oop) )  return this;  // cannot clear xk
3563   if( ik->is_interface() )              return this;  // cannot set xk
3564   return make(ptr(), klass(), klass_is_exact, const_oop(), _offset, _instance_id, _speculative, _inline_depth);
3565 }
3566 
3567 //-----------------------------cast_to_instance_id----------------------------
3568 const TypeOopPtr *TypeInstPtr::cast_to_instance_id(int instance_id) const {
3569   if( instance_id == _instance_id ) return this;
3570   return make(_ptr, klass(), _klass_is_exact, const_oop(), _offset, instance_id, _speculative, _inline_depth);
3571 }
3572 
3573 const TypeOopPtr *TypeInstPtr::cast_to_nonconst() const {
3574   if (const_oop() == NULL) return this;
3575   return make(NotNull, klass(), _klass_is_exact, NULL, _offset, _instance_id, _speculative, _inline_depth);
3576 }
3577 
3578 //------------------------------xmeet_unloaded---------------------------------
3579 // Compute the MEET of two InstPtrs when at least one is unloaded.
3580 // Assume classes are different since called after check for same name/class-loader
3581 const TypeInstPtr *TypeInstPtr::xmeet_unloaded(const TypeInstPtr *tinst) const {
3582     int off = meet_offset(tinst->offset());
3583     PTR ptr = meet_ptr(tinst->ptr());
3584     int instance_id = meet_instance_id(tinst->instance_id());
3585     const TypePtr* speculative = xmeet_speculative(tinst);
3586     int depth = meet_inline_depth(tinst->inline_depth());
3587 
3588     const TypeInstPtr *loaded    = is_loaded() ? this  : tinst;
3589     const TypeInstPtr *unloaded  = is_loaded() ? tinst : this;
3590     if( loaded->klass()->equals(ciEnv::current()->Object_klass()) ) {
3591       //
3592       // Meet unloaded class with java/lang/Object
3593       //
3594       // Meet
3595       //          |                     Unloaded Class
3596       //  Object  |   TOP    |   AnyNull | Constant |   NotNull |  BOTTOM   |
3597       //  ===================================================================
3598       //   TOP    | ..........................Unloaded......................|
3599       //  AnyNull |  U-AN    |................Unloaded......................|
3600       // Constant | ... O-NN .................................. |   O-BOT   |
3601       //  NotNull | ... O-NN .................................. |   O-BOT   |
3602       //  BOTTOM  | ........................Object-BOTTOM ..................|


3640   case FloatBot:
3641   case DoubleTop:
3642   case DoubleCon:
3643   case DoubleBot:
3644   case NarrowOop:
3645   case NarrowKlass:
3646   case Bottom:                  // Ye Olde Default
3647     return Type::BOTTOM;
3648   case Top:
3649     return this;
3650 
3651   default:                      // All else is a mistake
3652     typerr(t);
3653 
3654   case MetadataPtr:
3655   case KlassPtr:
3656   case RawPtr: return TypePtr::BOTTOM;
3657 
3658   case AryPtr: {                // All arrays inherit from Object class
3659     const TypeAryPtr *tp = t->is_aryptr();
3660     int offset = meet_offset(tp->offset());
3661     PTR ptr = meet_ptr(tp->ptr());
3662     int instance_id = meet_instance_id(tp->instance_id());
3663     const TypePtr* speculative = xmeet_speculative(tp);
3664     int depth = meet_inline_depth(tp->inline_depth());
3665     switch (ptr) {
3666     case TopPTR:
3667     case AnyNull:                // Fall 'down' to dual of object klass
3668       // For instances when a subclass meets a superclass we fall
3669       // below the centerline when the superclass is exact. We need to
3670       // do the same here.
3671       if (klass()->equals(ciEnv::current()->Object_klass()) && !klass_is_exact()) {
3672         return TypeAryPtr::make(ptr, tp->ary(), tp->klass(), tp->klass_is_exact(), offset, instance_id, speculative, depth);
3673       } else {
3674         // cannot subclass, so the meet has to fall badly below the centerline
3675         ptr = NotNull;
3676         instance_id = InstanceBot;
3677         return TypeInstPtr::make( ptr, ciEnv::current()->Object_klass(), false, NULL, offset, instance_id, speculative, depth);
3678       }
3679     case Constant:
3680     case NotNull:
3681     case BotPTR:                // Fall down to object klass
3682       // LCA is object_klass, but if we subclass from the top we can do better
3683       if( above_centerline(_ptr) ) { // if( _ptr == TopPTR || _ptr == AnyNull )
3684         // If 'this' (InstPtr) is above the centerline and it is Object class
3685         // then we can subclass in the Java class hierarchy.
3686         // For instances when a subclass meets a superclass we fall
3687         // below the centerline when the superclass is exact. We need
3688         // to do the same here.
3689         if (klass()->equals(ciEnv::current()->Object_klass()) && !klass_is_exact()) {
3690           // that is, tp's array type is a subtype of my klass
3691           return TypeAryPtr::make(ptr, (ptr == Constant ? tp->const_oop() : NULL),
3692                                   tp->ary(), tp->klass(), tp->klass_is_exact(), offset, instance_id, speculative, depth);
3693         }
3694       }
3695       // The other case cannot happen, since I cannot be a subtype of an array.
3696       // The meet falls down to Object class below centerline.
3697       if( ptr == Constant )
3698          ptr = NotNull;
3699       instance_id = InstanceBot;
3700       return make(ptr, ciEnv::current()->Object_klass(), false, NULL, offset, instance_id, speculative, depth);
3701     default: typerr(t);
3702     }
3703   }
3704 
3705   case OopPtr: {                // Meeting to OopPtrs
3706     // Found a OopPtr type vs self-InstPtr type
3707     const TypeOopPtr *tp = t->is_oopptr();
3708     int offset = meet_offset(tp->offset());
3709     PTR ptr = meet_ptr(tp->ptr());
3710     switch (tp->ptr()) {
3711     case TopPTR:
3712     case AnyNull: {
3713       int instance_id = meet_instance_id(InstanceTop);
3714       const TypePtr* speculative = xmeet_speculative(tp);
3715       int depth = meet_inline_depth(tp->inline_depth());
3716       return make(ptr, klass(), klass_is_exact(),
3717                   (ptr == Constant ? const_oop() : NULL), offset, instance_id, speculative, depth);
3718     }
3719     case NotNull:
3720     case BotPTR: {
3721       int instance_id = meet_instance_id(tp->instance_id());
3722       const TypePtr* speculative = xmeet_speculative(tp);
3723       int depth = meet_inline_depth(tp->inline_depth());
3724       return TypeOopPtr::make(ptr, offset, instance_id, speculative, depth);
3725     }
3726     default: typerr(t);
3727     }
3728   }
3729 
3730   case AnyPtr: {                // Meeting to AnyPtrs
3731     // Found an AnyPtr type vs self-InstPtr type
3732     const TypePtr *tp = t->is_ptr();
3733     int offset = meet_offset(tp->offset());
3734     PTR ptr = meet_ptr(tp->ptr());
3735     int instance_id = meet_instance_id(InstanceTop);
3736     const TypePtr* speculative = xmeet_speculative(tp);
3737     int depth = meet_inline_depth(tp->inline_depth());
3738     switch (tp->ptr()) {
3739     case Null:
3740       if( ptr == Null ) return TypePtr::make(AnyPtr, ptr, offset, speculative, depth);
3741       // else fall through to AnyNull
3742     case TopPTR:
3743     case AnyNull: {
3744       return make(ptr, klass(), klass_is_exact(),
3745                   (ptr == Constant ? const_oop() : NULL), offset, instance_id, speculative, depth);
3746     }
3747     case NotNull:
3748     case BotPTR:
3749       return TypePtr::make(AnyPtr, ptr, offset, speculative,depth);
3750     default: typerr(t);
3751     }
3752   }
3753 
3754   /*
3755                  A-top         }
3756                /   |   \       }  Tops
3757            B-top A-any C-top   }
3758               | /  |  \ |      }  Any-nulls
3759            B-any   |   C-any   }
3760               |    |    |
3761            B-con A-con C-con   } constants; not comparable across classes
3762               |    |    |
3763            B-not   |   C-not   }
3764               | \  |  / |      }  not-nulls
3765            B-bot A-not C-bot   }
3766                \   |   /       }  Bottoms
3767                  A-bot         }
3768   */
3769 
3770   case InstPtr: {                // Meeting 2 Oops?
3771     // Found an InstPtr sub-type vs self-InstPtr type
3772     const TypeInstPtr *tinst = t->is_instptr();
3773     int off = meet_offset( tinst->offset() );
3774     PTR ptr = meet_ptr( tinst->ptr() );
3775     int instance_id = meet_instance_id(tinst->instance_id());
3776     const TypePtr* speculative = xmeet_speculative(tinst);
3777     int depth = meet_inline_depth(tinst->inline_depth());
3778 
3779     // Check for easy case; klasses are equal (and perhaps not loaded!)
3780     // If we have constants, then we created oops so classes are loaded
3781     // and we can handle the constants further down.  This case handles
3782     // both-not-loaded or both-loaded classes
3783     if (ptr != Constant && klass()->equals(tinst->klass()) && klass_is_exact() == tinst->klass_is_exact()) {
3784       return make(ptr, klass(), klass_is_exact(), NULL, off, instance_id, speculative, depth);
3785     }
3786 
3787     // Classes require inspection in the Java klass hierarchy.  Must be loaded.
3788     ciKlass* tinst_klass = tinst->klass();
3789     ciKlass* this_klass  = this->klass();
3790     bool tinst_xk = tinst->klass_is_exact();
3791     bool this_xk  = this->klass_is_exact();
3792     if (!tinst_klass->is_loaded() || !this_klass->is_loaded() ) {
3793       // One of these classes has not been loaded


3920         else if (above_centerline(tinst ->_ptr))
3921           o = this_oop;
3922         else
3923           ptr = NotNull;
3924       }
3925       return make(ptr, this_klass, this_xk, o, off, instance_id, speculative, depth);
3926     } // Else classes are not equal
3927 
3928     // Since klasses are different, we require a LCA in the Java
3929     // class hierarchy - which means we have to fall to at least NotNull.
3930     if( ptr == TopPTR || ptr == AnyNull || ptr == Constant )
3931       ptr = NotNull;
3932 
3933     instance_id = InstanceBot;
3934 
3935     // Now we find the LCA of Java classes
3936     ciKlass* k = this_klass->least_common_ancestor(tinst_klass);
3937     return make(ptr, k, false, NULL, off, instance_id, speculative, depth);
3938   } // End of case InstPtr
3939 





















3940   } // End of switch
3941   return this;                  // Return the double constant
3942 }
3943 
3944 
3945 //------------------------java_mirror_type--------------------------------------
3946 ciType* TypeInstPtr::java_mirror_type() const {
3947   // must be a singleton type
3948   if( const_oop() == NULL )  return NULL;
3949 
3950   // must be of type java.lang.Class
3951   if( klass() != ciEnv::current()->Class_klass() )  return NULL;
3952 
3953   return const_oop()->as_instance()->java_mirror_type();
3954 }
3955 
3956 
3957 //------------------------------xdual------------------------------------------
3958 // Dual: do NOT dual on klasses.  This means I do NOT understand the Java
3959 // inheritance mechanism.
3960 const Type *TypeInstPtr::xdual() const {
3961   return new TypeInstPtr(dual_ptr(), klass(), klass_is_exact(), const_oop(), dual_offset(), dual_instance_id(), dual_speculative(), dual_inline_depth());
3962 }
3963 
3964 //------------------------------eq---------------------------------------------
3965 // Structural equality check for Type representations
3966 bool TypeInstPtr::eq( const Type *t ) const {
3967   const TypeInstPtr *p = t->is_instptr();
3968   return
3969     klass()->equals(p->klass()) &&
3970     TypeOopPtr::eq(p);          // Check sub-type stuff
3971 }
3972 
3973 //------------------------------hash-------------------------------------------


3988   case Constant:
3989     // TO DO: Make CI print the hex address of the underlying oop.
3990     if (WizardMode || Verbose) {
3991       const_oop()->print_oop(st);
3992     }
3993   case BotPTR:
3994     if (!WizardMode && !Verbose) {
3995       if( _klass_is_exact ) st->print(":exact");
3996       break;
3997     }
3998   case TopPTR:
3999   case AnyNull:
4000   case NotNull:
4001     st->print(":%s", ptr_msg[_ptr]);
4002     if( _klass_is_exact ) st->print(":exact");
4003     break;
4004   default:
4005     break;
4006   }
4007 
4008   if( _offset ) {               // Dump offset, if any
4009     if( _offset == OffsetBot )      st->print("+any");
4010     else if( _offset == OffsetTop ) st->print("+unknown");
4011     else st->print("+%d", _offset);
4012   }
4013 
4014   st->print(" *");
4015   if (_instance_id == InstanceTop)
4016     st->print(",iid=top");
4017   else if (_instance_id != InstanceBot)
4018     st->print(",iid=%d",_instance_id);
4019 
4020   dump_inline_depth(st);
4021   dump_speculative(st);
4022 }
4023 #endif
4024 
4025 //------------------------------add_offset-------------------------------------
4026 const TypePtr *TypeInstPtr::add_offset(intptr_t offset) const {
4027   return make(_ptr, klass(), klass_is_exact(), const_oop(), xadd_offset(offset),
4028               _instance_id, add_offset_speculative(offset), _inline_depth);
4029 }
4030 
4031 const Type *TypeInstPtr::remove_speculative() const {
4032   if (_speculative == NULL) {


4044   return make(_ptr, klass(), klass_is_exact(), const_oop(), _offset, _instance_id, _speculative, depth);
4045 }
4046 
4047 const TypePtr *TypeInstPtr::with_instance_id(int instance_id) const {
4048   assert(is_known_instance(), "should be known");
4049   return make(_ptr, klass(), klass_is_exact(), const_oop(), _offset, instance_id, _speculative, _inline_depth);
4050 }
4051 
4052 //=============================================================================
4053 // Convenience common pre-built types.
4054 const TypeAryPtr *TypeAryPtr::RANGE;
4055 const TypeAryPtr *TypeAryPtr::OOPS;
4056 const TypeAryPtr *TypeAryPtr::NARROWOOPS;
4057 const TypeAryPtr *TypeAryPtr::BYTES;
4058 const TypeAryPtr *TypeAryPtr::SHORTS;
4059 const TypeAryPtr *TypeAryPtr::CHARS;
4060 const TypeAryPtr *TypeAryPtr::INTS;
4061 const TypeAryPtr *TypeAryPtr::LONGS;
4062 const TypeAryPtr *TypeAryPtr::FLOATS;
4063 const TypeAryPtr *TypeAryPtr::DOUBLES;

4064 
4065 //------------------------------make-------------------------------------------
4066 const TypeAryPtr *TypeAryPtr::make(PTR ptr, const TypeAry *ary, ciKlass* k, bool xk, int offset,
4067                                    int instance_id, const TypePtr* speculative, int inline_depth) {
4068   assert(!(k == NULL && ary->_elem->isa_int()),
4069          "integral arrays must be pre-equipped with a class");
4070   if (!xk)  xk = ary->ary_must_be_exact();
4071   assert(instance_id <= 0 || xk || !UseExactTypes, "instances are always exactly typed");
4072   if (!UseExactTypes)  xk = (ptr == Constant);
4073   return (TypeAryPtr*)(new TypeAryPtr(ptr, NULL, ary, k, xk, offset, instance_id, false, speculative, inline_depth))->hashcons();
4074 }
4075 
4076 //------------------------------make-------------------------------------------
4077 const TypeAryPtr *TypeAryPtr::make(PTR ptr, ciObject* o, const TypeAry *ary, ciKlass* k, bool xk, int offset,
4078                                    int instance_id, const TypePtr* speculative, int inline_depth,
4079                                    bool is_autobox_cache) {
4080   assert(!(k == NULL && ary->_elem->isa_int()),
4081          "integral arrays must be pre-equipped with a class");
4082   assert( (ptr==Constant && o) || (ptr!=Constant && !o), "" );
4083   if (!xk)  xk = (o != NULL) || ary->ary_must_be_exact();
4084   assert(instance_id <= 0 || xk || !UseExactTypes, "instances are always exactly typed");
4085   if (!UseExactTypes)  xk = (ptr == Constant);
4086   return (TypeAryPtr*)(new TypeAryPtr(ptr, o, ary, k, xk, offset, instance_id, is_autobox_cache, speculative, inline_depth))->hashcons();
4087 }
4088 
4089 //------------------------------cast_to_ptr_type-------------------------------
4090 const Type *TypeAryPtr::cast_to_ptr_type(PTR ptr) const {
4091   if( ptr == _ptr ) return this;
4092   return make(ptr, const_oop(), _ary, klass(), klass_is_exact(), _offset, _instance_id, _speculative, _inline_depth);
4093 }
4094 
4095 
4096 //-----------------------------cast_to_exactness-------------------------------
4097 const Type *TypeAryPtr::cast_to_exactness(bool klass_is_exact) const {
4098   if( klass_is_exact == _klass_is_exact ) return this;
4099   if (!UseExactTypes)  return this;
4100   if (_ary->ary_must_be_exact())  return this;  // cannot clear xk
4101   return make(ptr(), const_oop(), _ary, klass(), klass_is_exact, _offset, _instance_id, _speculative, _inline_depth);






4102 }
4103 
4104 //-----------------------------cast_to_instance_id----------------------------
4105 const TypeOopPtr *TypeAryPtr::cast_to_instance_id(int instance_id) const {
4106   if( instance_id == _instance_id ) return this;
4107   return make(_ptr, const_oop(), _ary, klass(), _klass_is_exact, _offset, instance_id, _speculative, _inline_depth);
4108 }
4109 
4110 const TypeOopPtr *TypeAryPtr::cast_to_nonconst() const {
4111   if (const_oop() == NULL) return this;
4112   return make(NotNull, NULL, _ary, klass(), _klass_is_exact, _offset, _instance_id, _speculative, _inline_depth);
4113 }
4114 
4115 
4116 //-----------------------------narrow_size_type-------------------------------
4117 // Local cache for arrayOopDesc::max_array_length(etype),
4118 // which is kind of slow (and cached elsewhere by other users).
4119 static jint max_array_length_cache[T_CONFLICT+1];
4120 static jint max_array_length(BasicType etype) {
4121   jint& cache = max_array_length_cache[etype];
4122   jint res = cache;
4123   if (res == 0) {
4124     switch (etype) {
4125     case T_NARROWOOP:
4126       etype = T_OBJECT;
4127       break;
4128     case T_NARROWKLASS:
4129     case T_CONFLICT:
4130     case T_ILLEGAL:
4131     case T_VOID:
4132       etype = T_BYTE;           // will produce conservatively high value


4158   if (hi > max_hi) {
4159     hi = max_hi;
4160     if (size->is_con()) {
4161       lo = hi;
4162     }
4163     chg = true;
4164   }
4165   // Negative length arrays will produce weird intermediate dead fast-path code
4166   if (lo > hi)
4167     return TypeInt::ZERO;
4168   if (!chg)
4169     return size;
4170   return TypeInt::make(lo, hi, Type::WidenMin);
4171 }
4172 
4173 //-------------------------------cast_to_size----------------------------------
4174 const TypeAryPtr* TypeAryPtr::cast_to_size(const TypeInt* new_size) const {
4175   assert(new_size != NULL, "");
4176   new_size = narrow_size_type(new_size);
4177   if (new_size == size())  return this;
4178   const TypeAry* new_ary = TypeAry::make(elem(), new_size, is_stable());
4179   return make(ptr(), const_oop(), new_ary, klass(), klass_is_exact(), _offset, _instance_id, _speculative, _inline_depth);



















4180 }
4181 
4182 //------------------------------cast_to_stable---------------------------------
4183 const TypeAryPtr* TypeAryPtr::cast_to_stable(bool stable, int stable_dimension) const {
4184   if (stable_dimension <= 0 || (stable_dimension == 1 && stable == this->is_stable()))
4185     return this;
4186 
4187   const Type* elem = this->elem();
4188   const TypePtr* elem_ptr = elem->make_ptr();
4189 
4190   if (stable_dimension > 1 && elem_ptr != NULL && elem_ptr->isa_aryptr()) {
4191     // If this is widened from a narrow oop, TypeAry::make will re-narrow it.
4192     elem = elem_ptr = elem_ptr->is_aryptr()->cast_to_stable(stable, stable_dimension - 1);
4193   }
4194 
4195   const TypeAry* new_ary = TypeAry::make(elem, size(), stable);
4196 
4197   return make(ptr(), const_oop(), new_ary, klass(), klass_is_exact(), _offset, _instance_id, _speculative, _inline_depth);
4198 }
4199 
4200 //-----------------------------stable_dimension--------------------------------
4201 int TypeAryPtr::stable_dimension() const {
4202   if (!is_stable())  return 0;
4203   int dim = 1;
4204   const TypePtr* elem_ptr = elem()->make_ptr();
4205   if (elem_ptr != NULL && elem_ptr->isa_aryptr())
4206     dim += elem_ptr->is_aryptr()->stable_dimension();
4207   return dim;
4208 }
4209 
4210 //----------------------cast_to_autobox_cache-----------------------------------
4211 const TypeAryPtr* TypeAryPtr::cast_to_autobox_cache(bool cache) const {
4212   if (is_autobox_cache() == cache)  return this;
4213   const TypeOopPtr* etype = elem()->make_oopptr();
4214   if (etype == NULL)  return this;
4215   // The pointers in the autobox arrays are always non-null.
4216   TypePtr::PTR ptr_type = cache ? TypePtr::NotNull : TypePtr::AnyNull;
4217   etype = etype->cast_to_ptr_type(TypePtr::NotNull)->is_oopptr();
4218   const TypeAry* new_ary = TypeAry::make(etype, size(), is_stable());
4219   return make(ptr(), const_oop(), new_ary, klass(), klass_is_exact(), _offset, _instance_id, _speculative, _inline_depth, cache);
4220 }
4221 
4222 //------------------------------eq---------------------------------------------
4223 // Structural equality check for Type representations
4224 bool TypeAryPtr::eq( const Type *t ) const {
4225   const TypeAryPtr *p = t->is_aryptr();
4226   return
4227     _ary == p->_ary &&  // Check array
4228     TypeOopPtr::eq(p);  // Check sub-parts

4229 }
4230 
4231 //------------------------------hash-------------------------------------------
4232 // Type-specific hashing function.
4233 int TypeAryPtr::hash(void) const {
4234   return (intptr_t)_ary + TypeOopPtr::hash();
4235 }
4236 
4237 //------------------------------meet-------------------------------------------
4238 // Compute the MEET of two types.  It returns a new Type object.
4239 const Type *TypeAryPtr::xmeet_helper(const Type *t) const {
4240   // Perform a fast test for common case; meeting the same types together.
4241   if( this == t ) return this;  // Meeting same type-rep?
4242   // Current "this->_base" is Pointer
4243   switch (t->base()) {          // switch on original type
4244 
4245   // Mixing ints & oops happens when javac reuses local variables
4246   case Int:
4247   case Long:
4248   case FloatTop:
4249   case FloatCon:
4250   case FloatBot:
4251   case DoubleTop:
4252   case DoubleCon:
4253   case DoubleBot:
4254   case NarrowOop:
4255   case NarrowKlass:
4256   case Bottom:                  // Ye Olde Default
4257     return Type::BOTTOM;
4258   case Top:
4259     return this;
4260 
4261   default:                      // All else is a mistake
4262     typerr(t);
4263 
4264   case OopPtr: {                // Meeting to OopPtrs
4265     // Found a OopPtr type vs self-AryPtr type
4266     const TypeOopPtr *tp = t->is_oopptr();
4267     int offset = meet_offset(tp->offset());
4268     PTR ptr = meet_ptr(tp->ptr());
4269     int depth = meet_inline_depth(tp->inline_depth());
4270     const TypePtr* speculative = xmeet_speculative(tp);
4271     switch (tp->ptr()) {
4272     case TopPTR:
4273     case AnyNull: {
4274       int instance_id = meet_instance_id(InstanceTop);
4275       return make(ptr, (ptr == Constant ? const_oop() : NULL),
4276                   _ary, _klass, _klass_is_exact, offset, instance_id, speculative, depth);
4277     }
4278     case BotPTR:
4279     case NotNull: {
4280       int instance_id = meet_instance_id(tp->instance_id());
4281       return TypeOopPtr::make(ptr, offset, instance_id, speculative, depth);
4282     }
4283     default: ShouldNotReachHere();
4284     }
4285   }
4286 
4287   case AnyPtr: {                // Meeting two AnyPtrs
4288     // Found an AnyPtr type vs self-AryPtr type
4289     const TypePtr *tp = t->is_ptr();
4290     int offset = meet_offset(tp->offset());
4291     PTR ptr = meet_ptr(tp->ptr());
4292     const TypePtr* speculative = xmeet_speculative(tp);
4293     int depth = meet_inline_depth(tp->inline_depth());
4294     switch (tp->ptr()) {
4295     case TopPTR:
4296       return this;
4297     case BotPTR:
4298     case NotNull:
4299       return TypePtr::make(AnyPtr, ptr, offset, speculative, depth);
4300     case Null:
4301       if( ptr == Null ) return TypePtr::make(AnyPtr, ptr, offset, speculative, depth);
4302       // else fall through to AnyNull
4303     case AnyNull: {
4304       int instance_id = meet_instance_id(InstanceTop);
4305       return make(ptr, (ptr == Constant ? const_oop() : NULL),
4306                   _ary, _klass, _klass_is_exact, offset, instance_id, speculative, depth);
4307     }
4308     default: ShouldNotReachHere();
4309     }
4310   }
4311 
4312   case MetadataPtr:
4313   case KlassPtr:
4314   case RawPtr: return TypePtr::BOTTOM;
4315 
4316   case AryPtr: {                // Meeting 2 references?
4317     const TypeAryPtr *tap = t->is_aryptr();
4318     int off = meet_offset(tap->offset());

4319     const TypeAry *tary = _ary->meet_speculative(tap->_ary)->is_ary();
4320     PTR ptr = meet_ptr(tap->ptr());
4321     int instance_id = meet_instance_id(tap->instance_id());
4322     const TypePtr* speculative = xmeet_speculative(tap);
4323     int depth = meet_inline_depth(tap->inline_depth());
4324     ciKlass* lazy_klass = NULL;
4325     if (tary->_elem->isa_int()) {
4326       // Integral array element types have irrelevant lattice relations.
4327       // It is the klass that determines array layout, not the element type.
4328       if (_klass == NULL)
4329         lazy_klass = tap->_klass;
4330       else if (tap->_klass == NULL || tap->_klass == _klass) {
4331         lazy_klass = _klass;
4332       } else {
4333         // Something like byte[int+] meets char[int+].
4334         // This must fall to bottom, not (int[-128..65535])[int+].
4335         instance_id = InstanceBot;
4336         tary = TypeAry::make(Type::BOTTOM, tary->_size, tary->_stable);












4337       }
4338     } else // Non integral arrays.
4339       // Must fall to bottom if exact klasses in upper lattice
4340       // are not equal or super klass is exact.
4341       if ((above_centerline(ptr) || ptr == Constant) && klass() != tap->klass() &&
4342           // meet with top[] and bottom[] are processed further down:
4343           tap->_klass != NULL  && this->_klass != NULL   &&
4344           // both are exact and not equal:
4345           ((tap->_klass_is_exact && this->_klass_is_exact) ||
4346            // 'tap'  is exact and super or unrelated:
4347            (tap->_klass_is_exact && !tap->klass()->is_subtype_of(klass())) ||
4348            // 'this' is exact and super or unrelated:
4349            (this->_klass_is_exact && !klass()->is_subtype_of(tap->klass())))) {
4350       if (above_centerline(ptr)) {
4351         tary = TypeAry::make(Type::BOTTOM, tary->_size, tary->_stable);
4352       }
4353       return make(NotNull, NULL, tary, lazy_klass, false, off, InstanceBot, speculative, depth);
4354     }
4355 
4356     bool xk = false;
4357     switch (tap->ptr()) {
4358     case AnyNull:
4359     case TopPTR:
4360       // Compute new klass on demand, do not use tap->_klass
4361       if (below_centerline(this->_ptr)) {
4362         xk = this->_klass_is_exact;
4363       } else {
4364         xk = (tap->_klass_is_exact || this->_klass_is_exact);
4365       }
4366       return make(ptr, const_oop(), tary, lazy_klass, xk, off, instance_id, speculative, depth);
4367     case Constant: {
4368       ciObject* o = const_oop();
4369       if( _ptr == Constant ) {
4370         if( tap->const_oop() != NULL && !o->equals(tap->const_oop()) ) {
4371           xk = (klass() == tap->klass());
4372           ptr = NotNull;
4373           o = NULL;
4374           instance_id = InstanceBot;
4375         } else {
4376           xk = true;
4377         }
4378       } else if(above_centerline(_ptr)) {
4379         o = tap->const_oop();
4380         xk = true;
4381       } else {
4382         // Only precise for identical arrays
4383         xk = this->_klass_is_exact && (klass() == tap->klass());
4384       }
4385       return TypeAryPtr::make(ptr, o, tary, lazy_klass, xk, off, instance_id, speculative, depth);
4386     }
4387     case NotNull:
4388     case BotPTR:
4389       // Compute new klass on demand, do not use tap->_klass
4390       if (above_centerline(this->_ptr))
4391             xk = tap->_klass_is_exact;
4392       else  xk = (tap->_klass_is_exact & this->_klass_is_exact) &&
4393               (klass() == tap->klass()); // Only precise for identical arrays
4394       return TypeAryPtr::make(ptr, NULL, tary, lazy_klass, xk, off, instance_id, speculative, depth);
4395     default: ShouldNotReachHere();
4396     }
4397   }
4398 
4399   // All arrays inherit from Object class
4400   case InstPtr: {
4401     const TypeInstPtr *tp = t->is_instptr();
4402     int offset = meet_offset(tp->offset());
4403     PTR ptr = meet_ptr(tp->ptr());
4404     int instance_id = meet_instance_id(tp->instance_id());
4405     const TypePtr* speculative = xmeet_speculative(tp);
4406     int depth = meet_inline_depth(tp->inline_depth());
4407     switch (ptr) {
4408     case TopPTR:
4409     case AnyNull:                // Fall 'down' to dual of object klass
4410       // For instances when a subclass meets a superclass we fall
4411       // below the centerline when the superclass is exact. We need to
4412       // do the same here.
4413       if (tp->klass()->equals(ciEnv::current()->Object_klass()) && !tp->klass_is_exact()) {
4414         return TypeAryPtr::make(ptr, _ary, _klass, _klass_is_exact, offset, instance_id, speculative, depth);
4415       } else {
4416         // cannot subclass, so the meet has to fall badly below the centerline
4417         ptr = NotNull;
4418         instance_id = InstanceBot;
4419         return TypeInstPtr::make(ptr, ciEnv::current()->Object_klass(), false, NULL,offset, instance_id, speculative, depth);
4420       }
4421     case Constant:
4422     case NotNull:
4423     case BotPTR:                // Fall down to object klass
4424       // LCA is object_klass, but if we subclass from the top we can do better
4425       if (above_centerline(tp->ptr())) {
4426         // If 'tp'  is above the centerline and it is Object class
4427         // then we can subclass in the Java class hierarchy.
4428         // For instances when a subclass meets a superclass we fall
4429         // below the centerline when the superclass is exact. We need
4430         // to do the same here.
4431         if (tp->klass()->equals(ciEnv::current()->Object_klass()) && !tp->klass_is_exact()) {
4432           // that is, my array type is a subtype of 'tp' klass
4433           return make(ptr, (ptr == Constant ? const_oop() : NULL),
4434                       _ary, _klass, _klass_is_exact, offset, instance_id, speculative, depth);
4435         }
4436       }
4437       // The other case cannot happen, since t cannot be a subtype of an array.
4438       // The meet falls down to Object class below centerline.
4439       if( ptr == Constant )
4440          ptr = NotNull;
4441       instance_id = InstanceBot;
4442       return TypeInstPtr::make(ptr, ciEnv::current()->Object_klass(), false, NULL,offset, instance_id, speculative, depth);
4443     default: typerr(t);
4444     }
4445   }










4446   }
4447   return this;                  // Lint noise
4448 }
4449 
4450 //------------------------------xdual------------------------------------------
4451 // Dual: compute field-by-field dual
4452 const Type *TypeAryPtr::xdual() const {
4453   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());









4454 }
4455 
4456 //----------------------interface_vs_oop---------------------------------------
4457 #ifdef ASSERT
4458 bool TypeAryPtr::interface_vs_oop(const Type *t) const {
4459   const TypeAryPtr* t_aryptr = t->isa_aryptr();
4460   if (t_aryptr) {
4461     return _ary->interface_vs_oop(t_aryptr->_ary);
4462   }
4463   return false;
4464 }
4465 #endif
4466 
4467 //------------------------------dump2------------------------------------------
4468 #ifndef PRODUCT
4469 void TypeAryPtr::dump2( Dict &d, uint depth, outputStream *st ) const {
4470   _ary->dump2(d,depth,st);
4471   switch( _ptr ) {
4472   case Constant:
4473     const_oop()->print(st);
4474     break;
4475   case BotPTR:
4476     if (!WizardMode && !Verbose) {
4477       if( _klass_is_exact ) st->print(":exact");
4478       break;
4479     }
4480   case TopPTR:
4481   case AnyNull:
4482   case NotNull:
4483     st->print(":%s", ptr_msg[_ptr]);
4484     if( _klass_is_exact ) st->print(":exact");
4485     break;
4486   default:
4487     break;
4488   }
4489 
4490   if( _offset != 0 ) {





4491     int header_size = objArrayOopDesc::header_size() * wordSize;
4492     if( _offset == OffsetTop )       st->print("+undefined");
4493     else if( _offset == OffsetBot )  st->print("+any");
4494     else if( _offset < header_size ) st->print("+%d", _offset);
4495     else {
4496       BasicType basic_elem_type = elem()->basic_type();
4497       int array_base = arrayOopDesc::base_offset_in_bytes(basic_elem_type);
4498       int elem_size = type2aelembytes(basic_elem_type);
4499       st->print("[%d]", (_offset - array_base)/elem_size);
4500     }
4501   }
4502   st->print(" *");
4503   if (_instance_id == InstanceTop)
4504     st->print(",iid=top");
4505   else if (_instance_id != InstanceBot)
4506     st->print(",iid=%d",_instance_id);
4507 
4508   dump_inline_depth(st);
4509   dump_speculative(st);
4510 }
4511 #endif
4512 
4513 bool TypeAryPtr::empty(void) const {
4514   if (_ary->empty())       return true;
4515   return TypeOopPtr::empty();
4516 }
4517 
4518 //------------------------------add_offset-------------------------------------
4519 const TypePtr *TypeAryPtr::add_offset(intptr_t offset) const {
4520   return make(_ptr, _const_oop, _ary, _klass, _klass_is_exact, xadd_offset(offset), _instance_id, add_offset_speculative(offset), _inline_depth);
4521 }
4522 
4523 const Type *TypeAryPtr::remove_speculative() const {
4524   if (_speculative == NULL) {
4525     return this;
4526   }
4527   assert(_inline_depth == InlineDepthTop || _inline_depth == InlineDepthBottom, "non speculative type shouldn't have inline depth");
4528   return make(_ptr, _const_oop, _ary->remove_speculative()->is_ary(), _klass, _klass_is_exact, _offset, _instance_id, NULL, _inline_depth);












4529 }
4530 
4531 const TypePtr *TypeAryPtr::with_inline_depth(int depth) const {
4532   if (!UseInlineDepthForSpeculativeTypes) {
4533     return this;
4534   }
4535   return make(_ptr, _const_oop, _ary->remove_speculative()->is_ary(), _klass, _klass_is_exact, _offset, _instance_id, _speculative, depth);



















































4536 }
4537 
4538 const TypePtr *TypeAryPtr::with_instance_id(int instance_id) const {
4539   assert(is_known_instance(), "should be known");
4540   return make(_ptr, _const_oop, _ary->remove_speculative()->is_ary(), _klass, _klass_is_exact, _offset, instance_id, _speculative, _inline_depth);
4541 }
4542 
4543 //=============================================================================
4544 

4545 //------------------------------hash-------------------------------------------
4546 // Type-specific hashing function.
4547 int TypeNarrowPtr::hash(void) const {
4548   return _ptrtype->hash() + 7;
4549 }
4550 
4551 bool TypeNarrowPtr::singleton(void) const {    // TRUE if type is a singleton
4552   return _ptrtype->singleton();
4553 }
4554 
4555 bool TypeNarrowPtr::empty(void) const {
4556   return _ptrtype->empty();
4557 }
4558 
4559 intptr_t TypeNarrowPtr::get_con() const {
4560   return _ptrtype->get_con();
4561 }
4562 
4563 bool TypeNarrowPtr::eq( const Type *t ) const {
4564   const TypeNarrowPtr* tc = isa_same_narrowptr(t);


4613   // Current "this->_base" is NarrowKlass or NarrowOop
4614   switch (t->base()) {          // switch on original type
4615 
4616   case Int:                     // Mixing ints & oops happens when javac
4617   case Long:                    // reuses local variables
4618   case FloatTop:
4619   case FloatCon:
4620   case FloatBot:
4621   case DoubleTop:
4622   case DoubleCon:
4623   case DoubleBot:
4624   case AnyPtr:
4625   case RawPtr:
4626   case OopPtr:
4627   case InstPtr:
4628   case AryPtr:
4629   case MetadataPtr:
4630   case KlassPtr:
4631   case NarrowOop:
4632   case NarrowKlass:
4633 
4634   case Bottom:                  // Ye Olde Default
4635     return Type::BOTTOM;
4636   case Top:
4637     return this;
4638 



4639   default:                      // All else is a mistake
4640     typerr(t);
4641 
4642   } // End of switch
4643 
4644   return this;
4645 }
4646 
4647 #ifndef PRODUCT
4648 void TypeNarrowPtr::dump2( Dict & d, uint depth, outputStream *st ) const {
4649   _ptrtype->dump2(d, depth, st);
4650 }
4651 #endif
4652 
4653 const TypeNarrowOop *TypeNarrowOop::BOTTOM;
4654 const TypeNarrowOop *TypeNarrowOop::NULL_PTR;
4655 
4656 
4657 const TypeNarrowOop* TypeNarrowOop::make(const TypePtr* type) {
4658   return (const TypeNarrowOop*)(new TypeNarrowOop(type))->hashcons();


4697     return (one == two) && TypePtr::eq(t);
4698   } else {
4699     return one->equals(two) && TypePtr::eq(t);
4700   }
4701 }
4702 
4703 //------------------------------hash-------------------------------------------
4704 // Type-specific hashing function.
4705 int TypeMetadataPtr::hash(void) const {
4706   return
4707     (metadata() ? metadata()->hash() : 0) +
4708     TypePtr::hash();
4709 }
4710 
4711 //------------------------------singleton--------------------------------------
4712 // TRUE if Type is a singleton type, FALSE otherwise.   Singletons are simple
4713 // constants
4714 bool TypeMetadataPtr::singleton(void) const {
4715   // detune optimizer to not generate constant metadata + constant offset as a constant!
4716   // TopPTR, Null, AnyNull, Constant are all singletons
4717   return (_offset == 0) && !below_centerline(_ptr);
4718 }
4719 
4720 //------------------------------add_offset-------------------------------------
4721 const TypePtr *TypeMetadataPtr::add_offset( intptr_t offset ) const {
4722   return make( _ptr, _metadata, xadd_offset(offset));
4723 }
4724 
4725 //-----------------------------filter------------------------------------------
4726 // Do not allow interface-vs.-noninterface joins to collapse to top.
4727 const Type *TypeMetadataPtr::filter_helper(const Type *kills, bool include_speculative) const {
4728   const TypeMetadataPtr* ft = join_helper(kills, include_speculative)->isa_metadataptr();
4729   if (ft == NULL || ft->empty())
4730     return Type::TOP;           // Canonical empty value
4731   return ft;
4732 }
4733 
4734  //------------------------------get_con----------------------------------------
4735 intptr_t TypeMetadataPtr::get_con() const {
4736   assert( _ptr == Null || _ptr == Constant, "" );
4737   assert( _offset >= 0, "" );
4738 
4739   if (_offset != 0) {
4740     // After being ported to the compiler interface, the compiler no longer
4741     // directly manipulates the addresses of oops.  Rather, it only has a pointer
4742     // to a handle at compile time.  This handle is embedded in the generated
4743     // code and dereferenced at the time the nmethod is made.  Until that time,
4744     // it is not reasonable to do arithmetic with the addresses of oops (we don't
4745     // have access to the addresses!).  This does not seem to currently happen,
4746     // but this assertion here is to help prevent its occurence.
4747     tty->print_cr("Found oop constant with non-zero offset");
4748     ShouldNotReachHere();
4749   }
4750 
4751   return (intptr_t)metadata()->constant_encoding();
4752 }
4753 
4754 //------------------------------cast_to_ptr_type-------------------------------
4755 const Type *TypeMetadataPtr::cast_to_ptr_type(PTR ptr) const {
4756   if( ptr == _ptr ) return this;
4757   return make(ptr, metadata(), _offset);
4758 }
4759 


4770   case Long:                    // reuses local variables
4771   case FloatTop:
4772   case FloatCon:
4773   case FloatBot:
4774   case DoubleTop:
4775   case DoubleCon:
4776   case DoubleBot:
4777   case NarrowOop:
4778   case NarrowKlass:
4779   case Bottom:                  // Ye Olde Default
4780     return Type::BOTTOM;
4781   case Top:
4782     return this;
4783 
4784   default:                      // All else is a mistake
4785     typerr(t);
4786 
4787   case AnyPtr: {
4788     // Found an AnyPtr type vs self-OopPtr type
4789     const TypePtr *tp = t->is_ptr();
4790     int offset = meet_offset(tp->offset());
4791     PTR ptr = meet_ptr(tp->ptr());
4792     switch (tp->ptr()) {
4793     case Null:
4794       if (ptr == Null)  return TypePtr::make(AnyPtr, ptr, offset, tp->speculative(), tp->inline_depth());
4795       // else fall through:
4796     case TopPTR:
4797     case AnyNull: {
4798       return make(ptr, _metadata, offset);
4799     }
4800     case BotPTR:
4801     case NotNull:
4802       return TypePtr::make(AnyPtr, ptr, offset, tp->speculative(), tp->inline_depth());
4803     default: typerr(t);
4804     }
4805   }
4806 
4807   case RawPtr:
4808   case KlassPtr:
4809   case OopPtr:
4810   case InstPtr:
4811   case AryPtr:
4812     return TypePtr::BOTTOM;     // Oop meet raw is not well defined
4813 
4814   case MetadataPtr: {
4815     const TypeMetadataPtr *tp = t->is_metadataptr();
4816     int offset = meet_offset(tp->offset());
4817     PTR tptr = tp->ptr();
4818     PTR ptr = meet_ptr(tptr);
4819     ciMetadata* md = (tptr == TopPTR) ? metadata() : tp->metadata();
4820     if (tptr == TopPTR || _ptr == TopPTR ||
4821         metadata()->equals(tp->metadata())) {
4822       return make(ptr, md, offset);
4823     }
4824     // metadata is different
4825     if( ptr == Constant ) {  // Cannot be equal constants, so...
4826       if( tptr == Constant && _ptr != Constant)  return t;
4827       if( _ptr == Constant && tptr != Constant)  return this;
4828       ptr = NotNull;            // Fall down in lattice
4829     }
4830     return make(ptr, NULL, offset);
4831     break;
4832   }
4833   } // End of switch
4834   return this;                  // Return the double constant
4835 }
4836 
4837 
4838 //------------------------------xdual------------------------------------------
4839 // Dual of a pure metadata pointer.
4840 const Type *TypeMetadataPtr::xdual() const {
4841   return new TypeMetadataPtr(dual_ptr(), metadata(), dual_offset());
4842 }
4843 
4844 //------------------------------dump2------------------------------------------
4845 #ifndef PRODUCT
4846 void TypeMetadataPtr::dump2( Dict &d, uint depth, outputStream *st ) const {
4847   st->print("metadataptr:%s", ptr_msg[_ptr]);
4848   if( metadata() ) st->print(INTPTR_FORMAT, p2i(metadata()));
4849   switch( _offset ) {
4850   case OffsetTop: st->print("+top"); break;
4851   case OffsetBot: st->print("+any"); break;
4852   case         0: break;
4853   default:        st->print("+%d",_offset); break;
4854   }
4855 }
4856 #endif
4857 
4858 
4859 //=============================================================================
4860 // Convenience common pre-built type.
4861 const TypeMetadataPtr *TypeMetadataPtr::BOTTOM;
4862 
4863 TypeMetadataPtr::TypeMetadataPtr(PTR ptr, ciMetadata* metadata, int offset):
4864   TypePtr(MetadataPtr, ptr, offset), _metadata(metadata) {
4865 }
4866 
4867 const TypeMetadataPtr* TypeMetadataPtr::make(ciMethod* m) {
4868   return make(Constant, m, 0);
4869 }
4870 const TypeMetadataPtr* TypeMetadataPtr::make(ciMethodData* m) {
4871   return make(Constant, m, 0);
4872 }
4873 
4874 //------------------------------make-------------------------------------------
4875 // Create a meta data constant
4876 const TypeMetadataPtr *TypeMetadataPtr::make(PTR ptr, ciMetadata* m, int offset) {
4877   assert(m == NULL || !m->is_klass(), "wrong type");
4878   return (TypeMetadataPtr*)(new TypeMetadataPtr(ptr, m, offset))->hashcons();
4879 }
4880 
4881 
4882 //=============================================================================
4883 // Convenience common pre-built types.
4884 
4885 // Not-null object klass or below
4886 const TypeKlassPtr *TypeKlassPtr::OBJECT;
4887 const TypeKlassPtr *TypeKlassPtr::OBJECT_OR_NULL;
4888 
4889 //------------------------------TypeKlassPtr-----------------------------------
4890 TypeKlassPtr::TypeKlassPtr( PTR ptr, ciKlass* klass, int offset )
4891   : TypePtr(KlassPtr, ptr, offset), _klass(klass), _klass_is_exact(ptr == Constant) {
4892 }
4893 
4894 //------------------------------make-------------------------------------------
4895 // ptr to klass 'k', if Constant, or possibly to a sub-klass if not a Constant
4896 const TypeKlassPtr *TypeKlassPtr::make( PTR ptr, ciKlass* k, int offset ) {
4897   assert( k != NULL, "Expect a non-NULL klass");
4898   assert(k->is_instance_klass() || k->is_array_klass(), "Incorrect type of klass oop");
4899   TypeKlassPtr *r =
4900     (TypeKlassPtr*)(new TypeKlassPtr(ptr, k, offset))->hashcons();
4901 
4902   return r;
4903 }
4904 
4905 //------------------------------eq---------------------------------------------
4906 // Structural equality check for Type representations
4907 bool TypeKlassPtr::eq( const Type *t ) const {
4908   const TypeKlassPtr *p = t->is_klassptr();
4909   return
4910     klass()->equals(p->klass()) &&
4911     TypePtr::eq(p);
4912 }
4913 
4914 //------------------------------hash-------------------------------------------
4915 // Type-specific hashing function.
4916 int TypeKlassPtr::hash(void) const {
4917   return java_add((jint)klass()->hash(), (jint)TypePtr::hash());
4918 }
4919 
4920 //------------------------------singleton--------------------------------------
4921 // TRUE if Type is a singleton type, FALSE otherwise.   Singletons are simple
4922 // constants
4923 bool TypeKlassPtr::singleton(void) const {
4924   // detune optimizer to not generate constant klass + constant offset as a constant!
4925   // TopPTR, Null, AnyNull, Constant are all singletons
4926   return (_offset == 0) && !below_centerline(_ptr);
4927 }
4928 
4929 // Do not allow interface-vs.-noninterface joins to collapse to top.
4930 const Type *TypeKlassPtr::filter_helper(const Type *kills, bool include_speculative) const {
4931   // logic here mirrors the one from TypeOopPtr::filter. See comments
4932   // there.
4933   const Type* ft = join_helper(kills, include_speculative);
4934   const TypeKlassPtr* ftkp = ft->isa_klassptr();
4935   const TypeKlassPtr* ktkp = kills->isa_klassptr();
4936 
4937   if (ft->empty()) {
4938     if (!empty() && ktkp != NULL && ktkp->klass()->is_loaded() && ktkp->klass()->is_interface())
4939       return kills;             // Uplift to interface
4940 
4941     return Type::TOP;           // Canonical empty value
4942   }
4943 
4944   // Interface klass type could be exact in opposite to interface type,
4945   // return it here instead of incorrect Constant ptr J/L/Object (6894807).
4946   if (ftkp != NULL && ktkp != NULL &&
4947       ftkp->is_loaded() &&  ftkp->klass()->is_interface() &&
4948       !ftkp->klass_is_exact() && // Keep exact interface klass
4949       ktkp->is_loaded() && !ktkp->klass()->is_interface()) {
4950     return ktkp->cast_to_ptr_type(ftkp->ptr());
4951   }
4952 
4953   return ft;
4954 }
4955 
4956 //----------------------compute_klass------------------------------------------
4957 // Compute the defining klass for this class
4958 ciKlass* TypeAryPtr::compute_klass(DEBUG_ONLY(bool verify)) const {
4959   // Compute _klass based on element type.
4960   ciKlass* k_ary = NULL;
4961   const TypeInstPtr *tinst;
4962   const TypeAryPtr *tary;
4963   const Type* el = elem();
4964   if (el->isa_narrowoop()) {
4965     el = el->make_ptr();
4966   }
4967 
4968   // Get element klass
4969   if ((tinst = el->isa_instptr()) != NULL) {
4970     // Compute array klass from element klass
4971     k_ary = ciObjArrayKlass::make(tinst->klass());





4972   } else if ((tary = el->isa_aryptr()) != NULL) {
4973     // Compute array klass from element klass
4974     ciKlass* k_elem = tary->klass();
4975     // If element type is something like bottom[], k_elem will be null.
4976     if (k_elem != NULL)
4977       k_ary = ciObjArrayKlass::make(k_elem);
4978   } else if ((el->base() == Type::Top) ||
4979              (el->base() == Type::Bottom)) {
4980     // element type of Bottom occurs from meet of basic type
4981     // and object; Top occurs when doing join on Bottom.
4982     // Leave k_ary at NULL.
4983   } else {
4984     // Cannot compute array klass directly from basic type,
4985     // since subtypes of TypeInt all have basic type T_INT.
4986 #ifdef ASSERT
4987     if (verify && el->isa_int()) {
4988       // Check simple cases when verifying klass.
4989       BasicType bt = T_ILLEGAL;
4990       if (el == TypeInt::BYTE) {
4991         bt = T_BYTE;


5016 
5017   // Oops, need to compute _klass and cache it
5018   ciKlass* k_ary = compute_klass();
5019 
5020   if( this != TypeAryPtr::OOPS && this->dual() != TypeAryPtr::OOPS ) {
5021     // The _klass field acts as a cache of the underlying
5022     // ciKlass for this array type.  In order to set the field,
5023     // we need to cast away const-ness.
5024     //
5025     // IMPORTANT NOTE: we *never* set the _klass field for the
5026     // type TypeAryPtr::OOPS.  This Type is shared between all
5027     // active compilations.  However, the ciKlass which represents
5028     // this Type is *not* shared between compilations, so caching
5029     // this value would result in fetching a dangling pointer.
5030     //
5031     // Recomputing the underlying ciKlass for each request is
5032     // a bit less efficient than caching, but calls to
5033     // TypeAryPtr::OOPS->klass() are not common enough to matter.
5034     ((TypeAryPtr*)this)->_klass = k_ary;
5035     if (UseCompressedOops && k_ary != NULL && k_ary->is_obj_array_klass() &&
5036         _offset != 0 && _offset != arrayOopDesc::length_offset_in_bytes()) {
5037       ((TypeAryPtr*)this)->_is_ptr_to_narrowoop = true;
5038     }
5039   }
5040   return k_ary;
5041 }
5042 
5043 
5044 //------------------------------add_offset-------------------------------------
5045 // Access internals of klass object
5046 const TypePtr *TypeKlassPtr::add_offset( intptr_t offset ) const {
5047   return make( _ptr, klass(), xadd_offset(offset) );
5048 }
5049 
5050 //------------------------------cast_to_ptr_type-------------------------------
5051 const Type *TypeKlassPtr::cast_to_ptr_type(PTR ptr) const {
5052   assert(_base == KlassPtr, "subclass must override cast_to_ptr_type");
5053   if( ptr == _ptr ) return this;
5054   return make(ptr, _klass, _offset);
5055 }
5056 
5057 
5058 //-----------------------------cast_to_exactness-------------------------------
5059 const Type *TypeKlassPtr::cast_to_exactness(bool klass_is_exact) const {
5060   if( klass_is_exact == _klass_is_exact ) return this;
5061   if (!UseExactTypes)  return this;
5062   return make(klass_is_exact ? Constant : NotNull, _klass, _offset);
5063 }
5064 
5065 
5066 //-----------------------------as_instance_type--------------------------------
5067 // Corresponding type for an instance of the given class.
5068 // It will be NotNull, and exact if and only if the klass type is exact.
5069 const TypeOopPtr* TypeKlassPtr::as_instance_type() const {
5070   ciKlass* k = klass();

5071   bool    xk = klass_is_exact();
5072   //return TypeInstPtr::make(TypePtr::NotNull, k, xk, NULL, 0);
5073   const TypeOopPtr* toop = TypeOopPtr::make_from_klass_raw(k);
5074   guarantee(toop != NULL, "need type for given klass");
5075   toop = toop->cast_to_ptr_type(TypePtr::NotNull)->is_oopptr();
5076   return toop->cast_to_exactness(xk)->is_oopptr();
5077 }
5078 
5079 
5080 //------------------------------xmeet------------------------------------------
5081 // Compute the MEET of two types, return a new Type object.
5082 const Type    *TypeKlassPtr::xmeet( const Type *t ) const {
5083   // Perform a fast test for common case; meeting the same types together.
5084   if( this == t ) return this;  // Meeting same type-rep?
5085 
5086   // Current "this->_base" is Pointer
5087   switch (t->base()) {          // switch on original type
5088 
5089   case Int:                     // Mixing ints & oops happens when javac
5090   case Long:                    // reuses local variables
5091   case FloatTop:
5092   case FloatCon:
5093   case FloatBot:
5094   case DoubleTop:
5095   case DoubleCon:
5096   case DoubleBot:
5097   case NarrowOop:
5098   case NarrowKlass:
5099   case Bottom:                  // Ye Olde Default
5100     return Type::BOTTOM;
5101   case Top:
5102     return this;
5103 
5104   default:                      // All else is a mistake
5105     typerr(t);
5106 
5107   case AnyPtr: {                // Meeting to AnyPtrs
5108     // Found an AnyPtr type vs self-KlassPtr type
5109     const TypePtr *tp = t->is_ptr();
5110     int offset = meet_offset(tp->offset());
5111     PTR ptr = meet_ptr(tp->ptr());
5112     switch (tp->ptr()) {
5113     case TopPTR:
5114       return this;
5115     case Null:
5116       if( ptr == Null ) return TypePtr::make(AnyPtr, ptr, offset, tp->speculative(), tp->inline_depth());
5117     case AnyNull:
5118       return make( ptr, klass(), offset );
5119     case BotPTR:
5120     case NotNull:
5121       return TypePtr::make(AnyPtr, ptr, offset, tp->speculative(), tp->inline_depth());
5122     default: typerr(t);
5123     }
5124   }
5125 
5126   case RawPtr:
5127   case MetadataPtr:
5128   case OopPtr:
5129   case AryPtr:                  // Meet with AryPtr
5130   case InstPtr:                 // Meet with InstPtr
5131     return TypePtr::BOTTOM;
5132 
5133   //
5134   //             A-top         }
5135   //           /   |   \       }  Tops
5136   //       B-top A-any C-top   }
5137   //          | /  |  \ |      }  Any-nulls
5138   //       B-any   |   C-any   }
5139   //          |    |    |
5140   //       B-con A-con C-con   } constants; not comparable across classes
5141   //          |    |    |
5142   //       B-not   |   C-not   }
5143   //          | \  |  / |      }  not-nulls
5144   //       B-bot A-not C-bot   }
5145   //           \   |   /       }  Bottoms
5146   //             A-bot         }
5147   //
5148 
5149   case KlassPtr: {  // Meet two KlassPtr types
5150     const TypeKlassPtr *tkls = t->is_klassptr();
5151     int  off     = meet_offset(tkls->offset());
5152     PTR  ptr     = meet_ptr(tkls->ptr());
5153 








5154     // Check for easy case; klasses are equal (and perhaps not loaded!)
5155     // If we have constants, then we created oops so classes are loaded
5156     // and we can handle the constants further down.  This case handles
5157     // not-loaded classes
5158     if( ptr != Constant && tkls->klass()->equals(klass()) ) {
5159       return make( ptr, klass(), off );
5160     }
5161 
5162     // Classes require inspection in the Java klass hierarchy.  Must be loaded.
5163     ciKlass* tkls_klass = tkls->klass();
5164     ciKlass* this_klass = this->klass();
5165     assert( tkls_klass->is_loaded(), "This class should have been loaded.");
5166     assert( this_klass->is_loaded(), "This class should have been loaded.");
5167 
5168     // If 'this' type is above the centerline and is a superclass of the
5169     // other, we can treat 'this' as having the same type as the other.
5170     if ((above_centerline(this->ptr())) &&
5171         tkls_klass->is_subtype_of(this_klass)) {
5172       this_klass = tkls_klass;
5173     }


5199     if( ptr == TopPTR || ptr == AnyNull || ptr == Constant )
5200       ptr = NotNull;
5201     // Now we find the LCA of Java classes
5202     ciKlass* k = this_klass->least_common_ancestor(tkls_klass);
5203     return   make( ptr, k, off );
5204   } // End of case KlassPtr
5205 
5206   } // End of switch
5207   return this;                  // Return the double constant
5208 }
5209 
5210 //------------------------------xdual------------------------------------------
5211 // Dual: compute field-by-field dual
5212 const Type    *TypeKlassPtr::xdual() const {
5213   return new TypeKlassPtr( dual_ptr(), klass(), dual_offset() );
5214 }
5215 
5216 //------------------------------get_con----------------------------------------
5217 intptr_t TypeKlassPtr::get_con() const {
5218   assert( _ptr == Null || _ptr == Constant, "" );
5219   assert( _offset >= 0, "" );
5220 
5221   if (_offset != 0) {
5222     // After being ported to the compiler interface, the compiler no longer
5223     // directly manipulates the addresses of oops.  Rather, it only has a pointer
5224     // to a handle at compile time.  This handle is embedded in the generated
5225     // code and dereferenced at the time the nmethod is made.  Until that time,
5226     // it is not reasonable to do arithmetic with the addresses of oops (we don't
5227     // have access to the addresses!).  This does not seem to currently happen,
5228     // but this assertion here is to help prevent its occurence.
5229     tty->print_cr("Found oop constant with non-zero offset");
5230     ShouldNotReachHere();
5231   }
5232 
5233   return (intptr_t)klass()->constant_encoding();
5234 }
5235 //------------------------------dump2------------------------------------------
5236 // Dump Klass Type
5237 #ifndef PRODUCT
5238 void TypeKlassPtr::dump2( Dict & d, uint depth, outputStream *st ) const {
5239   switch( _ptr ) {
5240   case Constant:
5241     st->print("precise ");
5242   case NotNull:
5243     {
5244       const char *name = klass()->name()->as_utf8();
5245       if( name ) {
5246         st->print("klass %s: " INTPTR_FORMAT, name, p2i(klass()));
5247       } else {
5248         ShouldNotReachHere();
5249       }
5250     }
5251   case BotPTR:
5252     if( !WizardMode && !Verbose && !_klass_is_exact ) break;
5253   case TopPTR:
5254   case AnyNull:
5255     st->print(":%s", ptr_msg[_ptr]);
5256     if( _klass_is_exact ) st->print(":exact");
5257     break;
5258   default:
5259     break;
5260   }
5261 
5262   if( _offset ) {               // Dump offset, if any
5263     if( _offset == OffsetBot )      { st->print("+any"); }
5264     else if( _offset == OffsetTop ) { st->print("+unknown"); }
5265     else                            { st->print("+%d", _offset); }
5266   }
5267 
5268   st->print(" *");
5269 }
5270 #endif
5271 
5272 
5273 
5274 //=============================================================================
5275 // Convenience common pre-built types.
5276 
5277 //------------------------------make-------------------------------------------
5278 const TypeFunc *TypeFunc::make( const TypeTuple *domain, const TypeTuple *range ) {
5279   return (TypeFunc*)(new TypeFunc(domain,range))->hashcons();





5280 }
5281 
5282 //------------------------------make-------------------------------------------
5283 const TypeFunc *TypeFunc::make(ciMethod* method) {
5284   Compile* C = Compile::current();
5285   const TypeFunc* tf = C->last_tf(method); // check cache
5286   if (tf != NULL)  return tf;  // The hit rate here is almost 50%.
5287   const TypeTuple *domain;
5288   if (method->is_static()) {
5289     domain = TypeTuple::make_domain(NULL, method->signature());
5290   } else {
5291     domain = TypeTuple::make_domain(method->holder(), method->signature());
5292   }
5293   const TypeTuple *range  = TypeTuple::make_range(method->signature());
5294   tf = TypeFunc::make(domain, range);




5295   C->set_last_tf(method, tf);  // fill cache
5296   return tf;
5297 }
5298 
5299 //------------------------------meet-------------------------------------------
5300 // Compute the MEET of two types.  It returns a new Type object.
5301 const Type *TypeFunc::xmeet( const Type *t ) const {
5302   // Perform a fast test for common case; meeting the same types together.
5303   if( this == t ) return this;  // Meeting same type-rep?
5304 
5305   // Current "this->_base" is Func
5306   switch (t->base()) {          // switch on original type
5307 
5308   case Bottom:                  // Ye Olde Default
5309     return t;
5310 
5311   default:                      // All else is a mistake
5312     typerr(t);
5313 
5314   case Top:
5315     break;
5316   }
5317   return this;                  // Return the double constant
5318 }
5319 
5320 //------------------------------xdual------------------------------------------
5321 // Dual: compute field-by-field dual
5322 const Type *TypeFunc::xdual() const {
5323   return this;
5324 }
5325 
5326 //------------------------------eq---------------------------------------------
5327 // Structural equality check for Type representations
5328 bool TypeFunc::eq( const Type *t ) const {
5329   const TypeFunc *a = (const TypeFunc*)t;
5330   return _domain == a->_domain &&
5331     _range == a->_range;


5332 }
5333 
5334 //------------------------------hash-------------------------------------------
5335 // Type-specific hashing function.
5336 int TypeFunc::hash(void) const {
5337   return (intptr_t)_domain + (intptr_t)_range;
5338 }
5339 
5340 //------------------------------dump2------------------------------------------
5341 // Dump Function Type
5342 #ifndef PRODUCT
5343 void TypeFunc::dump2( Dict &d, uint depth, outputStream *st ) const {
5344   if( _range->cnt() <= Parms )
5345     st->print("void");
5346   else {
5347     uint i;
5348     for (i = Parms; i < _range->cnt()-1; i++) {
5349       _range->field_at(i)->dump2(d,depth,st);
5350       st->print("/");
5351     }
5352     _range->field_at(i)->dump2(d,depth,st);
5353   }
5354   st->print(" ");
5355   st->print("( ");
5356   if( !depth || d[this] ) {     // Check for recursive dump
5357     st->print("...)");
5358     return;
5359   }
5360   d.Insert((void*)this,(void*)this);    // Stop recursion
5361   if (Parms < _domain->cnt())
5362     _domain->field_at(Parms)->dump2(d,depth-1,st);
5363   for (uint i = Parms+1; i < _domain->cnt(); i++) {
5364     st->print(", ");
5365     _domain->field_at(i)->dump2(d,depth-1,st);
5366   }
5367   st->print(" )");
5368 }
5369 #endif
5370 
5371 //------------------------------singleton--------------------------------------
5372 // TRUE if Type is a singleton type, FALSE otherwise.   Singletons are simple
5373 // constants (Ldi nodes).  Singletons are integer, float or double constants
5374 // or a single symbol.
5375 bool TypeFunc::singleton(void) const {
5376   return false;                 // Never a singleton
5377 }
5378 
5379 bool TypeFunc::empty(void) const {
5380   return false;                 // Never empty
5381 }
5382 
5383 
5384 BasicType TypeFunc::return_type() const{
5385   if (range()->cnt() == TypeFunc::Parms) {
5386     return T_VOID;
5387   }
5388   return range()->field_at(TypeFunc::Parms)->basic_type();
5389 }


   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/ciField.hpp"
  27 #include "ci/ciMethodData.hpp"
  28 #include "ci/ciTypeFlow.hpp"
  29 #include "ci/ciValueKlass.hpp"
  30 #include "classfile/symbolTable.hpp"
  31 #include "classfile/systemDictionary.hpp"
  32 #include "compiler/compileLog.hpp"
  33 #include "libadt/dict.hpp"
  34 #include "memory/oopFactory.hpp"
  35 #include "memory/resourceArea.hpp"
  36 #include "oops/instanceKlass.hpp"
  37 #include "oops/instanceMirrorKlass.hpp"
  38 #include "oops/objArrayKlass.hpp"
  39 #include "oops/typeArrayKlass.hpp"
  40 #include "opto/matcher.hpp"
  41 #include "opto/node.hpp"
  42 #include "opto/opcodes.hpp"
  43 #include "opto/type.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 const Type::Offset Type::Offset::top(Type::OffsetTop);
  52 const Type::Offset Type::Offset::bottom(Type::OffsetBot);
  53 
  54 const Type::Offset Type::Offset::meet(const Type::Offset other) const {
  55   // Either is 'TOP' offset?  Return the other offset!
  56   int offset = other._offset;
  57   if (_offset == OffsetTop) return Offset(offset);
  58   if (offset == OffsetTop) return Offset(_offset);
  59   // If either is different, return 'BOTTOM' offset
  60   if (_offset != offset) return bottom;
  61   return Offset(_offset);
  62 }
  63 
  64 const Type::Offset Type::Offset::dual() const {
  65   if (_offset == OffsetTop) return bottom;// Map 'TOP' into 'BOTTOM'
  66   if (_offset == OffsetBot) return top;// Map 'BOTTOM' into 'TOP'
  67   return Offset(_offset);               // Map everything else into self
  68 }
  69 
  70 const Type::Offset Type::Offset::add(intptr_t offset) const {
  71   // Adding to 'TOP' offset?  Return 'TOP'!
  72   if (_offset == OffsetTop || offset == OffsetTop) return top;
  73   // Adding to 'BOTTOM' offset?  Return 'BOTTOM'!
  74   if (_offset == OffsetBot || offset == OffsetBot) return bottom;
  75   // Addition overflows or "accidentally" equals to OffsetTop? Return 'BOTTOM'!
  76   offset += (intptr_t)_offset;
  77   if (offset != (int)offset || offset == OffsetTop) return bottom;
  78 
  79   // assert( _offset >= 0 && _offset+offset >= 0, "" );
  80   // It is possible to construct a negative offset during PhaseCCP
  81 
  82   return Offset((int)offset);        // Sum valid offsets
  83 }
  84 
  85 void Type::Offset::dump2(outputStream *st) const {
  86   if (_offset == 0) {
  87     return;
  88   } else if (_offset == OffsetTop) {
  89     st->print("+top");
  90   }
  91   else if (_offset == OffsetBot) {
  92     st->print("+bot");
  93   } else if (_offset) {
  94     st->print("+%d", _offset);
  95   }
  96 }
  97 
  98 // Array which maps compiler types to Basic Types
  99 const Type::TypeInfo Type::_type_info[Type::lastype] = {
 100   { Bad,             T_ILLEGAL,    "bad",           false, Node::NotAMachineReg, relocInfo::none          },  // Bad
 101   { Control,         T_ILLEGAL,    "control",       false, 0,                    relocInfo::none          },  // Control
 102   { Bottom,          T_VOID,       "top",           false, 0,                    relocInfo::none          },  // Top
 103   { Bad,             T_INT,        "int:",          false, Op_RegI,              relocInfo::none          },  // Int
 104   { Bad,             T_LONG,       "long:",         false, Op_RegL,              relocInfo::none          },  // Long
 105   { Half,            T_VOID,       "half",          false, 0,                    relocInfo::none          },  // Half
 106   { Bad,             T_NARROWOOP,  "narrowoop:",    false, Op_RegN,              relocInfo::none          },  // NarrowOop
 107   { Bad,             T_NARROWKLASS,"narrowklass:",  false, Op_RegN,              relocInfo::none          },  // NarrowKlass
 108   { Bad,             T_ILLEGAL,    "tuple:",        false, Node::NotAMachineReg, relocInfo::none          },  // Tuple
 109   { Bad,             T_ARRAY,      "array:",        false, Node::NotAMachineReg, relocInfo::none          },  // Array
 110 
 111 #ifdef SPARC
 112   { Bad,             T_ILLEGAL,    "vectors:",      false, 0,                    relocInfo::none          },  // VectorS
 113   { Bad,             T_ILLEGAL,    "vectord:",      false, Op_RegD,              relocInfo::none          },  // VectorD
 114   { Bad,             T_ILLEGAL,    "vectorx:",      false, 0,                    relocInfo::none          },  // VectorX
 115   { Bad,             T_ILLEGAL,    "vectory:",      false, 0,                    relocInfo::none          },  // VectorY
 116   { Bad,             T_ILLEGAL,    "vectorz:",      false, 0,                    relocInfo::none          },  // VectorZ
 117 #elif defined(PPC64)
 118   { Bad,             T_ILLEGAL,    "vectors:",      false, 0,                    relocInfo::none          },  // VectorS
 119   { Bad,             T_ILLEGAL,    "vectord:",      false, Op_RegL,              relocInfo::none          },  // VectorD
 120   { Bad,             T_ILLEGAL,    "vectorx:",      false, Op_VecX,              relocInfo::none          },  // VectorX
 121   { Bad,             T_ILLEGAL,    "vectory:",      false, 0,                    relocInfo::none          },  // VectorY
 122   { Bad,             T_ILLEGAL,    "vectorz:",      false, 0,                    relocInfo::none          },  // VectorZ
 123 #elif defined(S390)
 124   { Bad,             T_ILLEGAL,    "vectors:",      false, 0,                    relocInfo::none          },  // VectorS
 125   { Bad,             T_ILLEGAL,    "vectord:",      false, Op_RegL,              relocInfo::none          },  // VectorD
 126   { Bad,             T_ILLEGAL,    "vectorx:",      false, 0,                    relocInfo::none          },  // VectorX
 127   { Bad,             T_ILLEGAL,    "vectory:",      false, 0,                    relocInfo::none          },  // VectorY
 128   { Bad,             T_ILLEGAL,    "vectorz:",      false, 0,                    relocInfo::none          },  // VectorZ
 129 #else // all other
 130   { Bad,             T_ILLEGAL,    "vectors:",      false, Op_VecS,              relocInfo::none          },  // VectorS
 131   { Bad,             T_ILLEGAL,    "vectord:",      false, Op_VecD,              relocInfo::none          },  // VectorD
 132   { Bad,             T_ILLEGAL,    "vectorx:",      false, Op_VecX,              relocInfo::none          },  // VectorX
 133   { Bad,             T_ILLEGAL,    "vectory:",      false, Op_VecY,              relocInfo::none          },  // VectorY
 134   { Bad,             T_ILLEGAL,    "vectorz:",      false, Op_VecZ,              relocInfo::none          },  // VectorZ
 135 #endif
 136   { Bad,             T_VALUETYPE,  "value:",        false, Node::NotAMachineReg, relocInfo::none          },  // ValueType
 137   { Bad,             T_ADDRESS,    "anyptr:",       false, Op_RegP,              relocInfo::none          },  // AnyPtr
 138   { Bad,             T_ADDRESS,    "rawptr:",       false, Op_RegP,              relocInfo::none          },  // RawPtr
 139   { Bad,             T_OBJECT,     "oop:",          true,  Op_RegP,              relocInfo::oop_type      },  // OopPtr
 140   { Bad,             T_OBJECT,     "inst:",         true,  Op_RegP,              relocInfo::oop_type      },  // InstPtr
 141   { Bad,             T_OBJECT,     "ary:",          true,  Op_RegP,              relocInfo::oop_type      },  // AryPtr
 142   { Bad,             T_METADATA,   "metadata:",     false, Op_RegP,              relocInfo::metadata_type },  // MetadataPtr
 143   { Bad,             T_METADATA,   "klass:",        false, Op_RegP,              relocInfo::metadata_type },  // KlassPtr
 144   { Bad,             T_OBJECT,     "func",          false, 0,                    relocInfo::none          },  // Function
 145   { Abio,            T_ILLEGAL,    "abIO",          false, 0,                    relocInfo::none          },  // Abio
 146   { Return_Address,  T_ADDRESS,    "return_address",false, Op_RegP,              relocInfo::none          },  // Return_Address
 147   { Memory,          T_ILLEGAL,    "memory",        false, 0,                    relocInfo::none          },  // Memory
 148   { FloatBot,        T_FLOAT,      "float_top",     false, Op_RegF,              relocInfo::none          },  // FloatTop
 149   { FloatCon,        T_FLOAT,      "ftcon:",        false, Op_RegF,              relocInfo::none          },  // FloatCon
 150   { FloatTop,        T_FLOAT,      "float",         false, Op_RegF,              relocInfo::none          },  // FloatBot
 151   { DoubleBot,       T_DOUBLE,     "double_top",    false, Op_RegD,              relocInfo::none          },  // DoubleTop
 152   { DoubleCon,       T_DOUBLE,     "dblcon:",       false, Op_RegD,              relocInfo::none          },  // DoubleCon
 153   { DoubleTop,       T_DOUBLE,     "double",        false, Op_RegD,              relocInfo::none          },  // DoubleBot
 154   { Top,             T_ILLEGAL,    "bottom",        false, 0,                    relocInfo::none          }   // Bottom
 155 };
 156 


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


 568   const Type **ffalse =(const Type**)shared_type_arena->Amalloc_4(2*sizeof(Type*));
 569   ffalse[0] = Type::CONTROL;
 570   ffalse[1] = Type::TOP;
 571   TypeTuple::IFFALSE = TypeTuple::make( 2, ffalse );
 572 
 573   const Type **fneither =(const Type**)shared_type_arena->Amalloc_4(2*sizeof(Type*));
 574   fneither[0] = Type::TOP;
 575   fneither[1] = Type::TOP;
 576   TypeTuple::IFNEITHER = TypeTuple::make( 2, fneither );
 577 
 578   const Type **ftrue =(const Type**)shared_type_arena->Amalloc_4(2*sizeof(Type*));
 579   ftrue[0] = Type::TOP;
 580   ftrue[1] = Type::CONTROL;
 581   TypeTuple::IFTRUE = TypeTuple::make( 2, ftrue );
 582 
 583   const Type **floop =(const Type**)shared_type_arena->Amalloc_4(2*sizeof(Type*));
 584   floop[0] = Type::CONTROL;
 585   floop[1] = TypeInt::INT;
 586   TypeTuple::LOOPBODY = TypeTuple::make( 2, floop );
 587 
 588   TypePtr::NULL_PTR= TypePtr::make(AnyPtr, TypePtr::Null, Offset(0));
 589   TypePtr::NOTNULL = TypePtr::make(AnyPtr, TypePtr::NotNull, Offset::bottom);
 590   TypePtr::BOTTOM  = TypePtr::make(AnyPtr, TypePtr::BotPTR, Offset::bottom);
 591 
 592   TypeRawPtr::BOTTOM = TypeRawPtr::make( TypePtr::BotPTR );
 593   TypeRawPtr::NOTNULL= TypeRawPtr::make( TypePtr::NotNull );
 594 
 595   const Type **fmembar = TypeTuple::fields(0);
 596   TypeTuple::MEMBAR = TypeTuple::make(TypeFunc::Parms+0, fmembar);
 597 
 598   const Type **fsc = (const Type**)shared_type_arena->Amalloc_4(2*sizeof(Type*));
 599   fsc[0] = TypeInt::CC;
 600   fsc[1] = Type::MEMORY;
 601   TypeTuple::STORECONDITIONAL = TypeTuple::make(2, fsc);
 602 
 603   TypeInstPtr::NOTNULL = TypeInstPtr::make(TypePtr::NotNull, current->env()->Object_klass());
 604   TypeInstPtr::BOTTOM  = TypeInstPtr::make(TypePtr::BotPTR,  current->env()->Object_klass());
 605   TypeInstPtr::MIRROR  = TypeInstPtr::make(TypePtr::NotNull, current->env()->Class_klass());
 606   TypeInstPtr::MARK    = TypeInstPtr::make(TypePtr::BotPTR,  current->env()->Object_klass(),
 607                                            false, 0, Offset(oopDesc::mark_offset_in_bytes()));
 608   TypeInstPtr::KLASS   = TypeInstPtr::make(TypePtr::BotPTR,  current->env()->Object_klass(),
 609                                            false, 0, Offset(oopDesc::klass_offset_in_bytes()));
 610   TypeOopPtr::BOTTOM  = TypeOopPtr::make(TypePtr::BotPTR, Offset::bottom, TypeOopPtr::InstanceBot);
 611 
 612   TypeMetadataPtr::BOTTOM = TypeMetadataPtr::make(TypePtr::BotPTR, NULL, Offset::bottom);
 613 
 614   TypeValueType::BOTTOM = TypeValueType::make(NULL);
 615 
 616   TypeNarrowOop::NULL_PTR = TypeNarrowOop::make( TypePtr::NULL_PTR );
 617   TypeNarrowOop::BOTTOM   = TypeNarrowOop::make( TypeInstPtr::BOTTOM );
 618 
 619   TypeNarrowKlass::NULL_PTR = TypeNarrowKlass::make( TypePtr::NULL_PTR );
 620 
 621   mreg2type[Op_Node] = Type::BOTTOM;
 622   mreg2type[Op_Set ] = 0;
 623   mreg2type[Op_RegN] = TypeNarrowOop::BOTTOM;
 624   mreg2type[Op_RegI] = TypeInt::INT;
 625   mreg2type[Op_RegP] = TypePtr::BOTTOM;
 626   mreg2type[Op_RegF] = Type::FLOAT;
 627   mreg2type[Op_RegD] = Type::DOUBLE;
 628   mreg2type[Op_RegL] = TypeLong::LONG;
 629   mreg2type[Op_RegFlags] = TypeInt::CC;
 630 
 631   TypeAryPtr::RANGE   = TypeAryPtr::make(TypePtr::BotPTR, TypeAry::make(Type::BOTTOM,TypeInt::POS), NULL /* current->env()->Object_klass() */, false, Offset(arrayOopDesc::length_offset_in_bytes()));
 632 
 633   TypeAryPtr::NARROWOOPS = TypeAryPtr::make(TypePtr::BotPTR, TypeAry::make(TypeNarrowOop::BOTTOM, TypeInt::POS), NULL /*ciArrayKlass::make(o)*/,  false,  Offset::bottom);
 634 
 635 #ifdef _LP64
 636   if (UseCompressedOops) {
 637     assert(TypeAryPtr::NARROWOOPS->is_ptr_to_narrowoop(), "array of narrow oops must be ptr to narrow oop");
 638     TypeAryPtr::OOPS  = TypeAryPtr::NARROWOOPS;
 639   } else
 640 #endif
 641   {
 642     // There is no shared klass for Object[].  See note in TypeAryPtr::klass().
 643     TypeAryPtr::OOPS  = TypeAryPtr::make(TypePtr::BotPTR, TypeAry::make(TypeInstPtr::BOTTOM,TypeInt::POS), NULL /*ciArrayKlass::make(o)*/,  false,  Offset::bottom);
 644   }
 645   TypeAryPtr::BYTES   = TypeAryPtr::make(TypePtr::BotPTR, TypeAry::make(TypeInt::BYTE      ,TypeInt::POS), ciTypeArrayKlass::make(T_BYTE),   true,  Offset::bottom);
 646   TypeAryPtr::SHORTS  = TypeAryPtr::make(TypePtr::BotPTR, TypeAry::make(TypeInt::SHORT     ,TypeInt::POS), ciTypeArrayKlass::make(T_SHORT),  true,  Offset::bottom);
 647   TypeAryPtr::CHARS   = TypeAryPtr::make(TypePtr::BotPTR, TypeAry::make(TypeInt::CHAR      ,TypeInt::POS), ciTypeArrayKlass::make(T_CHAR),   true,  Offset::bottom);
 648   TypeAryPtr::INTS    = TypeAryPtr::make(TypePtr::BotPTR, TypeAry::make(TypeInt::INT       ,TypeInt::POS), ciTypeArrayKlass::make(T_INT),    true,  Offset::bottom);
 649   TypeAryPtr::LONGS   = TypeAryPtr::make(TypePtr::BotPTR, TypeAry::make(TypeLong::LONG     ,TypeInt::POS), ciTypeArrayKlass::make(T_LONG),   true,  Offset::bottom);
 650   TypeAryPtr::FLOATS  = TypeAryPtr::make(TypePtr::BotPTR, TypeAry::make(Type::FLOAT        ,TypeInt::POS), ciTypeArrayKlass::make(T_FLOAT),  true,  Offset::bottom);
 651   TypeAryPtr::DOUBLES = TypeAryPtr::make(TypePtr::BotPTR, TypeAry::make(Type::DOUBLE       ,TypeInt::POS), ciTypeArrayKlass::make(T_DOUBLE), true,  Offset::bottom);
 652   TypeAryPtr::VALUES  = TypeAryPtr::make(TypePtr::BotPTR, TypeAry::make(TypeValueType::BOTTOM,TypeInt::POS), NULL, false,  Offset::bottom);
 653 
 654   // Nobody should ask _array_body_type[T_NARROWOOP]. Use NULL as assert.
 655   TypeAryPtr::_array_body_type[T_NARROWOOP] = NULL;
 656   TypeAryPtr::_array_body_type[T_OBJECT]  = TypeAryPtr::OOPS;
 657   TypeAryPtr::_array_body_type[T_VALUETYPE] = TypeAryPtr::OOPS;
 658   TypeAryPtr::_array_body_type[T_ARRAY]   = TypeAryPtr::OOPS; // arrays are stored in oop arrays
 659   TypeAryPtr::_array_body_type[T_BYTE]    = TypeAryPtr::BYTES;
 660   TypeAryPtr::_array_body_type[T_BOOLEAN] = TypeAryPtr::BYTES;  // boolean[] is a byte array
 661   TypeAryPtr::_array_body_type[T_SHORT]   = TypeAryPtr::SHORTS;
 662   TypeAryPtr::_array_body_type[T_CHAR]    = TypeAryPtr::CHARS;
 663   TypeAryPtr::_array_body_type[T_INT]     = TypeAryPtr::INTS;
 664   TypeAryPtr::_array_body_type[T_LONG]    = TypeAryPtr::LONGS;
 665   TypeAryPtr::_array_body_type[T_FLOAT]   = TypeAryPtr::FLOATS;
 666   TypeAryPtr::_array_body_type[T_DOUBLE]  = TypeAryPtr::DOUBLES;
 667 
 668   TypeKlassPtr::OBJECT = TypeKlassPtr::make(TypePtr::NotNull, current->env()->Object_klass(), Offset(0) );
 669   TypeKlassPtr::OBJECT_OR_NULL = TypeKlassPtr::make(TypePtr::BotPTR, current->env()->Object_klass(), Offset(0) );
 670 
 671   const Type **fi2c = TypeTuple::fields(2);
 672   fi2c[TypeFunc::Parms+0] = TypeInstPtr::BOTTOM; // Method*
 673   fi2c[TypeFunc::Parms+1] = TypeRawPtr::BOTTOM; // argument pointer
 674   TypeTuple::START_I2C = TypeTuple::make(TypeFunc::Parms+2, fi2c);
 675 
 676   const Type **intpair = TypeTuple::fields(2);
 677   intpair[0] = TypeInt::INT;
 678   intpair[1] = TypeInt::INT;
 679   TypeTuple::INT_PAIR = TypeTuple::make(2, intpair);
 680 
 681   const Type **longpair = TypeTuple::fields(2);
 682   longpair[0] = TypeLong::LONG;
 683   longpair[1] = TypeLong::LONG;
 684   TypeTuple::LONG_PAIR = TypeTuple::make(2, longpair);
 685 
 686   const Type **intccpair = TypeTuple::fields(2);
 687   intccpair[0] = TypeInt::INT;
 688   intccpair[1] = TypeInt::CC;
 689   TypeTuple::INT_CC_PAIR = TypeTuple::make(2, intccpair);
 690 
 691   const Type **longccpair = TypeTuple::fields(2);
 692   longccpair[0] = TypeLong::LONG;
 693   longccpair[1] = TypeInt::CC;
 694   TypeTuple::LONG_CC_PAIR = TypeTuple::make(2, longccpair);
 695 
 696   _const_basic_type[T_NARROWOOP]   = TypeNarrowOop::BOTTOM;
 697   _const_basic_type[T_NARROWKLASS] = Type::BOTTOM;
 698   _const_basic_type[T_BOOLEAN]     = TypeInt::BOOL;
 699   _const_basic_type[T_CHAR]        = TypeInt::CHAR;
 700   _const_basic_type[T_BYTE]        = TypeInt::BYTE;
 701   _const_basic_type[T_SHORT]       = TypeInt::SHORT;
 702   _const_basic_type[T_INT]         = TypeInt::INT;
 703   _const_basic_type[T_LONG]        = TypeLong::LONG;
 704   _const_basic_type[T_FLOAT]       = Type::FLOAT;
 705   _const_basic_type[T_DOUBLE]      = Type::DOUBLE;
 706   _const_basic_type[T_OBJECT]      = TypeInstPtr::BOTTOM;
 707   _const_basic_type[T_ARRAY]       = TypeInstPtr::BOTTOM; // there is no separate bottom for arrays
 708   _const_basic_type[T_VALUETYPE]   = TypeInstPtr::BOTTOM;
 709   _const_basic_type[T_VOID]        = TypePtr::NULL_PTR;   // reflection represents void this way
 710   _const_basic_type[T_ADDRESS]     = TypeRawPtr::BOTTOM;  // both interpreter return addresses & random raw ptrs
 711   _const_basic_type[T_CONFLICT]    = Type::BOTTOM;        // why not?
 712 
 713   _zero_type[T_NARROWOOP]   = TypeNarrowOop::NULL_PTR;
 714   _zero_type[T_NARROWKLASS] = TypeNarrowKlass::NULL_PTR;
 715   _zero_type[T_BOOLEAN]     = TypeInt::ZERO;     // false == 0
 716   _zero_type[T_CHAR]        = TypeInt::ZERO;     // '\0' == 0
 717   _zero_type[T_BYTE]        = TypeInt::ZERO;     // 0x00 == 0
 718   _zero_type[T_SHORT]       = TypeInt::ZERO;     // 0x0000 == 0
 719   _zero_type[T_INT]         = TypeInt::ZERO;
 720   _zero_type[T_LONG]        = TypeLong::ZERO;
 721   _zero_type[T_FLOAT]       = TypeF::ZERO;
 722   _zero_type[T_DOUBLE]      = TypeD::ZERO;
 723   _zero_type[T_OBJECT]      = TypePtr::NULL_PTR;
 724   _zero_type[T_ARRAY]       = TypePtr::NULL_PTR; // null array is null oop
 725   _zero_type[T_VALUETYPE]   = TypePtr::NULL_PTR;
 726   _zero_type[T_ADDRESS]     = TypePtr::NULL_PTR; // raw pointers use the same null
 727   _zero_type[T_VOID]        = Type::TOP;         // the only void value is no value at all
 728 
 729   // get_zero_type() should not happen for T_CONFLICT
 730   _zero_type[T_CONFLICT]= NULL;
 731 
 732   // Vector predefined types, it needs initialized _const_basic_type[].
 733   if (Matcher::vector_size_supported(T_BYTE,4)) {
 734     TypeVect::VECTS = TypeVect::make(T_BYTE,4);
 735   }
 736   if (Matcher::vector_size_supported(T_FLOAT,2)) {
 737     TypeVect::VECTD = TypeVect::make(T_FLOAT,2);
 738   }
 739   if (Matcher::vector_size_supported(T_FLOAT,4)) {
 740     TypeVect::VECTX = TypeVect::make(T_FLOAT,4);
 741   }
 742   if (Matcher::vector_size_supported(T_FLOAT,8)) {
 743     TypeVect::VECTY = TypeVect::make(T_FLOAT,8);
 744   }
 745   if (Matcher::vector_size_supported(T_FLOAT,16)) {


 958 
 959   case OopPtr:
 960     return t->xmeet(this);
 961 
 962   case InstPtr:
 963     return t->xmeet(this);
 964 
 965   case MetadataPtr:
 966   case KlassPtr:
 967     return t->xmeet(this);
 968 
 969   case AryPtr:
 970     return t->xmeet(this);
 971 
 972   case NarrowOop:
 973     return t->xmeet(this);
 974 
 975   case NarrowKlass:
 976     return t->xmeet(this);
 977 
 978   case ValueType:
 979     return t->xmeet(this);
 980 
 981   case Bad:                     // Type check
 982   default:                      // Bogus type not in lattice
 983     typerr(t);
 984     return Type::BOTTOM;
 985 
 986   case Bottom:                  // Ye Olde Default
 987     return t;
 988 
 989   case FloatTop:
 990     if( _base == FloatTop ) return this;
 991   case FloatBot:                // Float
 992     if( _base == FloatBot || _base == FloatTop ) return FLOAT;
 993     if( _base == DoubleTop || _base == DoubleBot ) return Type::BOTTOM;
 994     typerr(t);
 995     return Type::BOTTOM;
 996 
 997   case DoubleTop:
 998     if( _base == DoubleTop ) return this;
 999   case DoubleBot:               // Double
1000     if( _base == DoubleBot || _base == DoubleTop ) return DOUBLE;


1028 
1029 //------------------------------xdual------------------------------------------
1030 // Compute dual right now.
1031 const Type::TYPES Type::dual_type[Type::lastype] = {
1032   Bad,          // Bad
1033   Control,      // Control
1034   Bottom,       // Top
1035   Bad,          // Int - handled in v-call
1036   Bad,          // Long - handled in v-call
1037   Half,         // Half
1038   Bad,          // NarrowOop - handled in v-call
1039   Bad,          // NarrowKlass - handled in v-call
1040 
1041   Bad,          // Tuple - handled in v-call
1042   Bad,          // Array - handled in v-call
1043   Bad,          // VectorS - handled in v-call
1044   Bad,          // VectorD - handled in v-call
1045   Bad,          // VectorX - handled in v-call
1046   Bad,          // VectorY - handled in v-call
1047   Bad,          // VectorZ - handled in v-call
1048   Bad,          // ValueType - handled in v-call
1049 
1050   Bad,          // AnyPtr - handled in v-call
1051   Bad,          // RawPtr - handled in v-call
1052   Bad,          // OopPtr - handled in v-call
1053   Bad,          // InstPtr - handled in v-call
1054   Bad,          // AryPtr - handled in v-call
1055 
1056   Bad,          //  MetadataPtr - handled in v-call
1057   Bad,          // KlassPtr - handled in v-call
1058 
1059   Bad,          // Function - handled in v-call
1060   Abio,         // Abio
1061   Return_Address,// Return_Address
1062   Memory,       // Memory
1063   FloatBot,     // FloatTop
1064   FloatCon,     // FloatCon
1065   FloatTop,     // FloatBot
1066   DoubleBot,    // DoubleTop
1067   DoubleCon,    // DoubleCon
1068   DoubleTop,    // DoubleBot


1924 
1925 bool TypeLong::empty(void) const {
1926   return _lo > _hi;
1927 }
1928 
1929 //=============================================================================
1930 // Convenience common pre-built types.
1931 const TypeTuple *TypeTuple::IFBOTH;     // Return both arms of IF as reachable
1932 const TypeTuple *TypeTuple::IFFALSE;
1933 const TypeTuple *TypeTuple::IFTRUE;
1934 const TypeTuple *TypeTuple::IFNEITHER;
1935 const TypeTuple *TypeTuple::LOOPBODY;
1936 const TypeTuple *TypeTuple::MEMBAR;
1937 const TypeTuple *TypeTuple::STORECONDITIONAL;
1938 const TypeTuple *TypeTuple::START_I2C;
1939 const TypeTuple *TypeTuple::INT_PAIR;
1940 const TypeTuple *TypeTuple::LONG_PAIR;
1941 const TypeTuple *TypeTuple::INT_CC_PAIR;
1942 const TypeTuple *TypeTuple::LONG_CC_PAIR;
1943 
1944 static void collect_value_fields(ciValueKlass* vk, const Type** field_array, uint& pos, ExtendedSignature& sig_cc) {
1945   for (int j = 0; j < vk->nof_nonstatic_fields(); j++) {
1946     ciField* field = vk->nonstatic_field_at(j);
1947     BasicType bt = field->type()->basic_type();
1948     const Type* ft = Type::get_const_type(field->type());
1949     field_array[pos++] = ft;
1950     if (type2size[bt] == 2) {
1951       field_array[pos++] = Type::HALF;
1952     }
1953     // Skip reserved arguments
1954     while (SigEntry::next_is_reserved(sig_cc, bt)) {
1955       field_array[pos++] = Type::get_const_basic_type(bt);
1956       if (type2size[bt] == 2) {
1957         field_array[pos++] = Type::HALF;
1958       }
1959     }
1960   }
1961 }
1962 
1963 //------------------------------make-------------------------------------------
1964 // Make a TypeTuple from the range of a method signature
1965 const TypeTuple *TypeTuple::make_range(ciSignature* sig, bool ret_vt_fields) {
1966   ciType* return_type = sig->return_type();
1967   uint arg_cnt = return_type->size();
1968   if (ret_vt_fields) {
1969     arg_cnt = return_type->as_value_klass()->value_arg_slots() + 1;
1970   }
1971 
1972   const Type **field_array = fields(arg_cnt);
1973   switch (return_type->basic_type()) {
1974   case T_LONG:
1975     field_array[TypeFunc::Parms]   = TypeLong::LONG;
1976     field_array[TypeFunc::Parms+1] = Type::HALF;
1977     break;
1978   case T_DOUBLE:
1979     field_array[TypeFunc::Parms]   = Type::DOUBLE;
1980     field_array[TypeFunc::Parms+1] = Type::HALF;
1981     break;
1982   case T_OBJECT:
1983   case T_ARRAY:
1984   case T_BOOLEAN:
1985   case T_CHAR:
1986   case T_FLOAT:
1987   case T_BYTE:
1988   case T_SHORT:
1989   case T_INT:
1990     field_array[TypeFunc::Parms] = get_const_type(return_type);
1991     break;
1992   case T_VALUETYPE:
1993     if (ret_vt_fields) {
1994       uint pos = TypeFunc::Parms;
1995       field_array[pos] = TypePtr::BOTTOM;
1996       pos++;
1997       ExtendedSignature sig = ExtendedSignature(NULL, SigEntryFilter());
1998       collect_value_fields(return_type->as_value_klass(), field_array, pos, sig);
1999     } else {
2000       field_array[TypeFunc::Parms] = get_const_type(return_type)->join_speculative(sig->returns_never_null() ? TypePtr::NOTNULL : TypePtr::BOTTOM);
2001     }
2002     break;
2003   case T_VOID:
2004     break;
2005   default:
2006     ShouldNotReachHere();
2007   }
2008   return (TypeTuple*)(new TypeTuple(TypeFunc::Parms + arg_cnt, field_array))->hashcons();
2009 }
2010 
2011 // Make a TypeTuple from the domain of a method signature
2012 const TypeTuple *TypeTuple::make_domain(ciMethod* method, bool vt_fields_as_args) {
2013   ciSignature* sig = method->signature();
2014   ExtendedSignature sig_cc = ExtendedSignature(vt_fields_as_args ? method->get_sig_cc() : NULL, SigEntryFilter());
2015 
2016   uint arg_cnt = sig->size() + (method->is_static() ? 0 : 1);
2017   if (vt_fields_as_args) {
2018     for (arg_cnt = 0; !sig_cc.at_end(); ++sig_cc) {
2019       arg_cnt += type2size[(*sig_cc)._bt];
2020     }
2021     sig_cc = ExtendedSignature(method->get_sig_cc(), SigEntryFilter());
2022   }
2023 
2024   uint pos = TypeFunc::Parms;
2025   const Type** field_array = fields(arg_cnt);
2026   if (!method->is_static()) {
2027     ciInstanceKlass* recv = method->holder();
2028     if (vt_fields_as_args && recv->is_valuetype() && recv->as_value_klass()->is_scalarizable()) {
2029       collect_value_fields(recv->as_value_klass(), field_array, pos, sig_cc);
2030     } else {
2031       field_array[pos++] = get_const_type(recv)->join_speculative(TypePtr::NOTNULL);
2032       if (vt_fields_as_args) {
2033         ++sig_cc;
2034       }
2035     }
2036   }
2037 
2038   int i = 0;
2039   while (pos < TypeFunc::Parms + arg_cnt) {
2040     ciType* type = sig->type_at(i);
2041     BasicType bt = type->basic_type();
2042     bool is_flattened = false;
2043 
2044     switch (bt) {
2045     case T_LONG:
2046       field_array[pos++] = TypeLong::LONG;
2047       field_array[pos++] = Type::HALF;
2048       break;
2049     case T_DOUBLE:
2050       field_array[pos++] = Type::DOUBLE;
2051       field_array[pos++] = Type::HALF;
2052       break;
2053     case T_OBJECT:
2054     case T_ARRAY:
2055     case T_FLOAT:
2056     case T_INT:
2057       field_array[pos++] = get_const_type(type);
2058       break;
2059     case T_BOOLEAN:
2060     case T_CHAR:
2061     case T_BYTE:
2062     case T_SHORT:
2063       field_array[pos++] = TypeInt::INT;
2064       break;
2065     case T_VALUETYPE: {
2066       bool never_null = sig->is_never_null_at(i);
2067       if (vt_fields_as_args && type->as_value_klass()->is_scalarizable() && never_null) {
2068         is_flattened = true;
2069         collect_value_fields(type->as_value_klass(), field_array, pos, sig_cc);
2070       } else {
2071         field_array[pos++] = get_const_type(type)->join_speculative(never_null ? TypePtr::NOTNULL : TypePtr::BOTTOM);
2072       }
2073       break;
2074     }
2075     default:
2076       ShouldNotReachHere();
2077     }
2078     // Skip reserved arguments
2079     while (!is_flattened && SigEntry::next_is_reserved(sig_cc, bt)) {
2080       field_array[pos++] = Type::get_const_basic_type(bt);
2081       if (type2size[bt] == 2) {
2082         field_array[pos++] = Type::HALF;
2083       }
2084     }
2085     i++;
2086   }
2087   assert(pos == TypeFunc::Parms + arg_cnt, "wrong number of arguments");
2088 
2089   return (TypeTuple*)(new TypeTuple(TypeFunc::Parms + arg_cnt, field_array))->hashcons();
2090 }
2091 
2092 const TypeTuple *TypeTuple::make( uint cnt, const Type **fields ) {
2093   return (TypeTuple*)(new TypeTuple(cnt,fields))->hashcons();
2094 }
2095 
2096 //------------------------------fields-----------------------------------------
2097 // Subroutine call type with space allocated for argument types
2098 // Memory for Control, I_O, Memory, FramePtr, and ReturnAdr is allocated implicitly
2099 const Type **TypeTuple::fields( uint arg_cnt ) {
2100   const Type **flds = (const Type **)(Compile::current()->type_arena()->Amalloc_4((TypeFunc::Parms+arg_cnt)*sizeof(Type*) ));
2101   flds[TypeFunc::Control  ] = Type::CONTROL;
2102   flds[TypeFunc::I_O      ] = Type::ABIO;
2103   flds[TypeFunc::Memory   ] = Type::MEMORY;
2104   flds[TypeFunc::FramePtr ] = TypeRawPtr::BOTTOM;
2105   flds[TypeFunc::ReturnAdr] = Type::RETURN_ADDRESS;
2106 
2107   return flds;


2202     if (_fields[i]->empty())  return true;
2203   }
2204   return false;
2205 }
2206 
2207 //=============================================================================
2208 // Convenience common pre-built types.
2209 
2210 inline const TypeInt* normalize_array_size(const TypeInt* size) {
2211   // Certain normalizations keep us sane when comparing types.
2212   // We do not want arrayOop variables to differ only by the wideness
2213   // of their index types.  Pick minimum wideness, since that is the
2214   // forced wideness of small ranges anyway.
2215   if (size->_widen != Type::WidenMin)
2216     return TypeInt::make(size->_lo, size->_hi, Type::WidenMin);
2217   else
2218     return size;
2219 }
2220 
2221 //------------------------------make-------------------------------------------
2222 const TypeAry* TypeAry::make(const Type* elem, const TypeInt* size, bool stable,
2223                              bool not_flat, bool not_null_free) {
2224   if (UseCompressedOops && elem->isa_oopptr()) {
2225     elem = elem->make_narrowoop();
2226   }
2227   size = normalize_array_size(size);
2228   return (TypeAry*)(new TypeAry(elem, size, stable, not_flat, not_null_free))->hashcons();
2229 }
2230 
2231 //------------------------------meet-------------------------------------------
2232 // Compute the MEET of two types.  It returns a new Type object.
2233 const Type *TypeAry::xmeet( const Type *t ) const {
2234   // Perform a fast test for common case; meeting the same types together.
2235   if( this == t ) return this;  // Meeting same type-rep?
2236 
2237   // Current "this->_base" is Ary
2238   switch (t->base()) {          // switch on original type
2239 
2240   case Bottom:                  // Ye Olde Default
2241     return t;
2242 
2243   default:                      // All else is a mistake
2244     typerr(t);
2245 
2246   case Array: {                 // Meeting 2 arrays?
2247     const TypeAry *a = t->is_ary();
2248     return TypeAry::make(_elem->meet_speculative(a->_elem),
2249                          _size->xmeet(a->_size)->is_int(),
2250                          _stable && a->_stable,
2251                          _not_flat && a->_not_flat,
2252                          _not_null_free && a->_not_null_free);
2253   }
2254   case Top:
2255     break;
2256   }
2257   return this;                  // Return the double constant
2258 }
2259 
2260 //------------------------------xdual------------------------------------------
2261 // Dual: compute field-by-field dual
2262 const Type *TypeAry::xdual() const {
2263   const TypeInt* size_dual = _size->dual()->is_int();
2264   size_dual = normalize_array_size(size_dual);
2265   return new TypeAry(_elem->dual(), size_dual, !_stable, !_not_flat, !_not_null_free);
2266 }
2267 
2268 //------------------------------eq---------------------------------------------
2269 // Structural equality check for Type representations
2270 bool TypeAry::eq( const Type *t ) const {
2271   const TypeAry *a = (const TypeAry*)t;
2272   return _elem == a->_elem &&
2273     _stable == a->_stable &&
2274     _size == a->_size &&
2275     _not_flat == a->_not_flat &&
2276     _not_null_free == a->_not_null_free;
2277 
2278 }
2279 
2280 //------------------------------hash-------------------------------------------
2281 // Type-specific hashing function.
2282 int TypeAry::hash(void) const {
2283   return (intptr_t)_elem + (intptr_t)_size + (_stable ? 43 : 0);
2284 }
2285 
2286 /**
2287  * Return same type without a speculative part in the element
2288  */
2289 const Type* TypeAry::remove_speculative() const {
2290   return make(_elem->remove_speculative(), _size, _stable, _not_flat, _not_null_free);
2291 }
2292 
2293 /**
2294  * Return same type with cleaned up speculative part of element
2295  */
2296 const Type* TypeAry::cleanup_speculative() const {
2297   return make(_elem->cleanup_speculative(), _size, _stable, _not_flat, _not_null_free);
2298 }
2299 
2300 /**
2301  * Return same type but with a different inline depth (used for speculation)
2302  *
2303  * @param depth  depth to meet with
2304  */
2305 const TypePtr* TypePtr::with_inline_depth(int depth) const {
2306   if (!UseInlineDepthForSpeculativeTypes) {
2307     return this;
2308   }
2309   return make(AnyPtr, _ptr, _offset, _speculative, depth);
2310 }
2311 
2312 //----------------------interface_vs_oop---------------------------------------
2313 #ifdef ASSERT
2314 bool TypeAry::interface_vs_oop(const Type *t) const {
2315   const TypeAry* t_ary = t->is_ary();
2316   if (t_ary) {
2317     const TypePtr* this_ptr = _elem->make_ptr(); // In case we have narrow_oops
2318     const TypePtr*    t_ptr = t_ary->_elem->make_ptr();
2319     if(this_ptr != NULL && t_ptr != NULL) {
2320       return this_ptr->interface_vs_oop(t_ptr);
2321     }
2322   }
2323   return false;
2324 }
2325 #endif
2326 
2327 //------------------------------dump2------------------------------------------
2328 #ifndef PRODUCT
2329 void TypeAry::dump2( Dict &d, uint depth, outputStream *st ) const {
2330   if (_stable)  st->print("stable:");
2331   if (Verbose) {
2332     if (_not_flat) st->print("not flat:");
2333     if (_not_null_free) st->print("not null free:");
2334   }
2335   _elem->dump2(d, depth, st);
2336   st->print("[");
2337   _size->dump2(d, depth, st);
2338   st->print("]");
2339 }
2340 #endif
2341 
2342 //------------------------------singleton--------------------------------------
2343 // TRUE if Type is a singleton type, FALSE otherwise.   Singletons are simple
2344 // constants (Ldi nodes).  Singletons are integer, float or double constants
2345 // or a single symbol.
2346 bool TypeAry::singleton(void) const {
2347   return false;                 // Never a singleton
2348 }
2349 
2350 bool TypeAry::empty(void) const {
2351   return _elem->empty() || _size->empty();
2352 }
2353 
2354 //--------------------------ary_must_be_exact----------------------------------


2357   // This logic looks at the element type of an array, and returns true
2358   // if the element type is either a primitive or a final instance class.
2359   // In such cases, an array built on this ary must have no subclasses.
2360   if (_elem == BOTTOM)      return false;  // general array not exact
2361   if (_elem == TOP   )      return false;  // inverted general array not exact
2362   const TypeOopPtr*  toop = NULL;
2363   if (UseCompressedOops && _elem->isa_narrowoop()) {
2364     toop = _elem->make_ptr()->isa_oopptr();
2365   } else {
2366     toop = _elem->isa_oopptr();
2367   }
2368   if (!toop)                return true;   // a primitive type, like int
2369   ciKlass* tklass = toop->klass();
2370   if (tklass == NULL)       return false;  // unloaded class
2371   if (!tklass->is_loaded()) return false;  // unloaded class
2372   const TypeInstPtr* tinst;
2373   if (_elem->isa_narrowoop())
2374     tinst = _elem->make_ptr()->isa_instptr();
2375   else
2376     tinst = _elem->isa_instptr();
2377   if (tinst) {
2378     // [V? has a subtype: [V. So even though V is final, [V? is not exact.
2379     if (tklass->as_instance_klass()->is_final()) {
2380       if (tinst->is_valuetypeptr() && (tinst->ptr() == TypePtr::BotPTR || tinst->ptr() == TypePtr::TopPTR)) {
2381         return false;
2382       }
2383       return true;
2384     }
2385     return false;
2386   }
2387   const TypeAryPtr*  tap;
2388   if (_elem->isa_narrowoop())
2389     tap = _elem->make_ptr()->isa_aryptr();
2390   else
2391     tap = _elem->isa_aryptr();
2392   if (tap)
2393     return tap->ary()->ary_must_be_exact();
2394   return false;
2395 }
2396 
2397 //==============================TypeValueType=======================================
2398 
2399 const TypeValueType *TypeValueType::BOTTOM;
2400 
2401 //------------------------------make-------------------------------------------
2402 const TypeValueType* TypeValueType::make(ciValueKlass* vk, bool larval) {
2403   return (TypeValueType*)(new TypeValueType(vk, larval))->hashcons();
2404 }
2405 
2406 //------------------------------meet-------------------------------------------
2407 // Compute the MEET of two types.  It returns a new Type object.
2408 const Type* TypeValueType::xmeet(const Type* t) const {
2409   // Perform a fast test for common case; meeting the same types together.
2410   if(this == t) return this;  // Meeting same type-rep?
2411 
2412   // Current "this->_base" is ValueType
2413   switch (t->base()) {          // switch on original type
2414 
2415   case Int:
2416   case Long:
2417   case FloatTop:
2418   case FloatCon:
2419   case FloatBot:
2420   case DoubleTop:
2421   case DoubleCon:
2422   case DoubleBot:
2423   case NarrowKlass:
2424   case Bottom:
2425     return Type::BOTTOM;
2426 
2427   case OopPtr:
2428   case MetadataPtr:
2429   case KlassPtr:
2430   case RawPtr:
2431     return TypePtr::BOTTOM;
2432 
2433   case Top:
2434     return this;
2435 
2436   case NarrowOop: {
2437     const Type* res = t->make_ptr()->xmeet(this);
2438     if (res->isa_ptr()) {
2439       return res->make_narrowoop();
2440     }
2441     return res;
2442   }
2443 
2444   case AryPtr:
2445   case InstPtr: {
2446     return t->xmeet(this);
2447   }
2448 
2449   case ValueType: {
2450     // All value types inherit from Object
2451     const TypeValueType* other = t->is_valuetype();
2452     if (_vk == NULL) {
2453       return this;
2454     } else if (other->_vk == NULL) {
2455       return other;
2456     } else if (_vk == other->_vk) {
2457       if (_larval == other->_larval ||
2458           !_larval) {
2459         return this;
2460       } else {
2461         return t;
2462       }
2463     }
2464     return TypeInstPtr::NOTNULL;
2465   }
2466 
2467   default:                      // All else is a mistake
2468     typerr(t);
2469 
2470   }
2471   return this;
2472 }
2473 
2474 //------------------------------xdual------------------------------------------
2475 const Type* TypeValueType::xdual() const {
2476   return this;
2477 }
2478 
2479 //------------------------------eq---------------------------------------------
2480 // Structural equality check for Type representations
2481 bool TypeValueType::eq(const Type* t) const {
2482   const TypeValueType* vt = t->is_valuetype();
2483   return (_vk == vt->value_klass() && _larval == vt->larval());
2484 }
2485 
2486 //------------------------------hash-------------------------------------------
2487 // Type-specific hashing function.
2488 int TypeValueType::hash(void) const {
2489   return (intptr_t)_vk;
2490 }
2491 
2492 //------------------------------singleton--------------------------------------
2493 // TRUE if Type is a singleton type, FALSE otherwise. Singletons are simple constants.
2494 bool TypeValueType::singleton(void) const {
2495   return false;
2496 }
2497 
2498 //------------------------------empty------------------------------------------
2499 // TRUE if Type is a type with no values, FALSE otherwise.
2500 bool TypeValueType::empty(void) const {
2501   return false;
2502 }
2503 
2504 //------------------------------dump2------------------------------------------
2505 #ifndef PRODUCT
2506 void TypeValueType::dump2(Dict &d, uint depth, outputStream* st) const {
2507   if (_vk == NULL) {
2508     st->print("BOTTOM valuetype");
2509     return;
2510   }
2511   int count = _vk->nof_declared_nonstatic_fields();
2512   st->print("valuetype[%d]:{", count);
2513   st->print("%s", count != 0 ? _vk->declared_nonstatic_field_at(0)->type()->name() : "empty");
2514   for (int i = 1; i < count; ++i) {
2515     st->print(", %s", _vk->declared_nonstatic_field_at(i)->type()->name());
2516   }
2517   st->print("}%s", _larval?" : larval":"");
2518 }
2519 #endif
2520 
2521 //==============================TypeVect=======================================
2522 // Convenience common pre-built types.
2523 const TypeVect *TypeVect::VECTS = NULL; //  32-bit vectors
2524 const TypeVect *TypeVect::VECTD = NULL; //  64-bit vectors
2525 const TypeVect *TypeVect::VECTX = NULL; // 128-bit vectors
2526 const TypeVect *TypeVect::VECTY = NULL; // 256-bit vectors
2527 const TypeVect *TypeVect::VECTZ = NULL; // 512-bit vectors
2528 
2529 //------------------------------make-------------------------------------------
2530 const TypeVect* TypeVect::make(const Type *elem, uint length) {
2531   BasicType elem_bt = elem->array_element_basic_type();
2532   assert(is_java_primitive(elem_bt), "only primitive types in vector");
2533   assert(length > 1 && is_power_of_2(length), "vector length is power of 2");
2534   assert(Matcher::vector_size_supported(elem_bt, length), "length in range");
2535   int size = length * type2aelembytes(elem_bt);
2536   switch (Matcher::vector_ideal_reg(size)) {
2537   case Op_VecS:
2538     return (TypeVect*)(new TypeVectS(elem, length))->hashcons();
2539   case Op_RegL:
2540   case Op_VecD:


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


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





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


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











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


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


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


3204 // Type-specific hashing function.
3205 int TypeRawPtr::hash(void) const {
3206   return (intptr_t)_bits + TypePtr::hash();
3207 }
3208 
3209 //------------------------------dump2------------------------------------------
3210 #ifndef PRODUCT
3211 void TypeRawPtr::dump2( Dict &d, uint depth, outputStream *st ) const {
3212   if( _ptr == Constant )
3213     st->print(INTPTR_FORMAT, p2i(_bits));
3214   else
3215     st->print("rawptr:%s", ptr_msg[_ptr]);
3216 }
3217 #endif
3218 
3219 //=============================================================================
3220 // Convenience common pre-built type.
3221 const TypeOopPtr *TypeOopPtr::BOTTOM;
3222 
3223 //------------------------------TypeOopPtr-------------------------------------
3224 TypeOopPtr::TypeOopPtr(TYPES t, PTR ptr, ciKlass* k, bool xk, ciObject* o, Offset offset, Offset field_offset,
3225                        int instance_id, const TypePtr* speculative, int inline_depth)
3226   : TypePtr(t, ptr, offset, speculative, inline_depth),
3227     _const_oop(o), _klass(k),
3228     _klass_is_exact(xk),
3229     _is_ptr_to_narrowoop(false),
3230     _is_ptr_to_narrowklass(false),
3231     _is_ptr_to_boxed_value(false),
3232     _instance_id(instance_id) {
3233   if (Compile::current()->eliminate_boxing() && (t == InstPtr) &&
3234       (offset.get() > 0) && xk && (k != 0) && k->is_instance_klass()) {
3235     _is_ptr_to_boxed_value = k->as_instance_klass()->is_boxed_value_offset(offset.get());
3236   }
3237 #ifdef _LP64
3238   if (this->offset() > 0 || this->offset() == Type::OffsetTop || this->offset() == Type::OffsetBot) {
3239     if (this->offset() == oopDesc::klass_offset_in_bytes()) {
3240       _is_ptr_to_narrowklass = UseCompressedClassPointers;
3241     } else if (klass() == NULL) {
3242       // Array with unknown body type
3243       assert(this->isa_aryptr(), "only arrays without klass");
3244       _is_ptr_to_narrowoop = UseCompressedOops;
3245     } else if (UseCompressedOops && this->isa_aryptr() && this->offset() != arrayOopDesc::length_offset_in_bytes()) {
3246       if (klass()->is_obj_array_klass()) {
3247         _is_ptr_to_narrowoop = true;
3248       } else if (klass()->is_value_array_klass() && field_offset != Offset::top && field_offset != Offset::bottom) {
3249         // Check if the field of the value type array element contains oops
3250         ciValueKlass* vk = klass()->as_value_array_klass()->element_klass()->as_value_klass();
3251         int foffset = field_offset.get() + vk->first_field_offset();
3252         ciField* field = vk->get_field_by_offset(foffset, false);
3253         assert(field != NULL, "missing field");
3254         BasicType bt = field->layout_type();
3255         _is_ptr_to_narrowoop = (bt == T_OBJECT || bt == T_ARRAY || T_VALUETYPE);
3256       }
3257     } else if (klass()->is_instance_klass()) {


3258       if (this->isa_klassptr()) {
3259         // Perm objects don't use compressed references
3260       } else if (_offset == Offset::bottom || _offset == Offset::top) {
3261         // unsafe access
3262         _is_ptr_to_narrowoop = UseCompressedOops;
3263       } else { // exclude unsafe ops
3264         assert(this->isa_instptr(), "must be an instance ptr.");

3265         if (klass() == ciEnv::current()->Class_klass() &&
3266             (this->offset() == java_lang_Class::klass_offset_in_bytes() ||
3267              this->offset() == java_lang_Class::array_klass_offset_in_bytes())) {
3268           // Special hidden fields from the Class.
3269           assert(this->isa_instptr(), "must be an instance ptr.");
3270           _is_ptr_to_narrowoop = false;
3271         } else if (klass() == ciEnv::current()->Class_klass() &&
3272                    this->offset() >= InstanceMirrorKlass::offset_of_static_fields()) {
3273           // Static fields
3274           assert(o != NULL, "must be constant");
3275           ciInstanceKlass* ik = o->as_instance()->java_lang_Class_klass()->as_instance_klass();
3276           BasicType basic_elem_type;
3277           if (ik->is_valuetype() && this->offset() == ik->as_value_klass()->default_value_offset()) {
3278             // Special hidden field that contains the oop of the default value type
3279             basic_elem_type = T_VALUETYPE;
3280           } else {
3281             ciField* field = ik->get_field_by_offset(this->offset(), true);
3282             assert(field != NULL, "missing field");
3283             basic_elem_type = field->layout_type();
3284           }
3285           _is_ptr_to_narrowoop = UseCompressedOops && (basic_elem_type == T_OBJECT ||
3286                                                        basic_elem_type == T_VALUETYPE ||
3287                                                        basic_elem_type == T_ARRAY);
3288         } else {
3289           // Instance fields which contains a compressed oop references.
3290           ciInstanceKlass* ik = klass()->as_instance_klass();
3291           ciField* field = ik->get_field_by_offset(this->offset(), false);
3292           if (field != NULL) {
3293             BasicType basic_elem_type = field->layout_type();
3294             _is_ptr_to_narrowoop = UseCompressedOops && (basic_elem_type == T_OBJECT ||
3295                                                          basic_elem_type == T_VALUETYPE ||
3296                                                          basic_elem_type == T_ARRAY);
3297           } else if (klass()->equals(ciEnv::current()->Object_klass())) {
3298             // Compile::find_alias_type() cast exactness on all types to verify
3299             // that it does not affect alias type.
3300             _is_ptr_to_narrowoop = UseCompressedOops;
3301           } else {
3302             // Type for the copy start in LibraryCallKit::inline_native_clone().
3303             _is_ptr_to_narrowoop = UseCompressedOops;
3304           }
3305         }
3306       }
3307     }
3308   }
3309 #endif
3310 }
3311 
3312 //------------------------------make-------------------------------------------
3313 const TypeOopPtr *TypeOopPtr::make(PTR ptr, Offset offset, int instance_id,
3314                                    const TypePtr* speculative, int inline_depth) {
3315   assert(ptr != Constant, "no constant generic pointers");
3316   ciKlass*  k = Compile::current()->env()->Object_klass();
3317   bool      xk = false;
3318   ciObject* o = NULL;
3319   return (TypeOopPtr*)(new TypeOopPtr(OopPtr, ptr, k, xk, o, offset, Offset::bottom, instance_id, speculative, inline_depth))->hashcons();
3320 }
3321 
3322 
3323 //------------------------------cast_to_ptr_type-------------------------------
3324 const Type *TypeOopPtr::cast_to_ptr_type(PTR ptr) const {
3325   assert(_base == OopPtr, "subclass must override cast_to_ptr_type");
3326   if( ptr == _ptr ) return this;
3327   return make(ptr, _offset, _instance_id, _speculative, _inline_depth);
3328 }
3329 
3330 //-----------------------------cast_to_instance_id----------------------------
3331 const TypeOopPtr *TypeOopPtr::cast_to_instance_id(int instance_id) const {
3332   // There are no instances of a general oop.
3333   // Return self unchanged.
3334   return this;
3335 }
3336 
3337 const TypeOopPtr *TypeOopPtr::cast_to_nonconst() const {
3338   return this;
3339 }
3340 
3341 //-----------------------------cast_to_exactness-------------------------------
3342 const Type *TypeOopPtr::cast_to_exactness(bool klass_is_exact) const {
3343   // There is no such thing as an exact general oop.
3344   // Return self unchanged.
3345   return this;
3346 }
3347 
3348 
3349 //------------------------------as_klass_type----------------------------------
3350 // Return the klass type corresponding to this instance or array type.
3351 // It is the type that is loaded from an object of this type.
3352 const TypeKlassPtr* TypeOopPtr::as_klass_type() const {
3353   ciKlass* k = klass();
3354   bool    xk = klass_is_exact();
3355   if (k == NULL)
3356     return TypeKlassPtr::OBJECT;
3357   else
3358     return TypeKlassPtr::make(xk? Constant: NotNull, k, Offset(0));
3359 }
3360 
3361 //------------------------------meet-------------------------------------------
3362 // Compute the MEET of two types.  It returns a new Type object.
3363 const Type *TypeOopPtr::xmeet_helper(const Type *t) const {
3364   // Perform a fast test for common case; meeting the same types together.
3365   if( this == t ) return this;  // Meeting same type-rep?
3366 
3367   // Current "this->_base" is OopPtr
3368   switch (t->base()) {          // switch on original type
3369 
3370   case Int:                     // Mixing ints & oops happens when javac
3371   case Long:                    // reuses local variables
3372   case FloatTop:
3373   case FloatCon:
3374   case FloatBot:
3375   case DoubleTop:
3376   case DoubleCon:
3377   case DoubleBot:
3378   case NarrowOop:
3379   case NarrowKlass:
3380   case Bottom:                  // Ye Olde Default
3381     return Type::BOTTOM;
3382   case Top:
3383     return this;
3384 
3385   default:                      // All else is a mistake
3386     typerr(t);
3387 
3388   case RawPtr:
3389   case MetadataPtr:
3390   case KlassPtr:
3391     return TypePtr::BOTTOM;     // Oop meet raw is not well defined
3392 
3393   case AnyPtr: {
3394     // Found an AnyPtr type vs self-OopPtr type
3395     const TypePtr *tp = t->is_ptr();
3396     Offset offset = meet_offset(tp->offset());
3397     PTR ptr = meet_ptr(tp->ptr());
3398     const TypePtr* speculative = xmeet_speculative(tp);
3399     int depth = meet_inline_depth(tp->inline_depth());
3400     switch (tp->ptr()) {
3401     case Null:
3402       if (ptr == Null)  return TypePtr::make(AnyPtr, ptr, offset, speculative, depth);
3403       // else fall through:
3404     case TopPTR:
3405     case AnyNull: {
3406       int instance_id = meet_instance_id(InstanceTop);
3407       return make(ptr, offset, instance_id, speculative, depth);
3408     }
3409     case BotPTR:
3410     case NotNull:
3411       return TypePtr::make(AnyPtr, ptr, offset, speculative, depth);
3412     default: typerr(t);
3413     }
3414   }
3415 
3416   case OopPtr: {                 // Meeting to other OopPtrs


3418     int instance_id = meet_instance_id(tp->instance_id());
3419     const TypePtr* speculative = xmeet_speculative(tp);
3420     int depth = meet_inline_depth(tp->inline_depth());
3421     return make(meet_ptr(tp->ptr()), meet_offset(tp->offset()), instance_id, speculative, depth);
3422   }
3423 
3424   case InstPtr:                  // For these, flip the call around to cut down
3425   case AryPtr:
3426     return t->xmeet(this);      // Call in reverse direction
3427 
3428   } // End of switch
3429   return this;                  // Return the double constant
3430 }
3431 
3432 
3433 //------------------------------xdual------------------------------------------
3434 // Dual of a pure heap pointer.  No relevant klass or oop information.
3435 const Type *TypeOopPtr::xdual() const {
3436   assert(klass() == Compile::current()->env()->Object_klass(), "no klasses here");
3437   assert(const_oop() == NULL,             "no constants here");
3438   return new TypeOopPtr(_base, dual_ptr(), klass(), klass_is_exact(), const_oop(), dual_offset(), Offset::bottom, dual_instance_id(), dual_speculative(), dual_inline_depth());
3439 }
3440 
3441 //--------------------------make_from_klass_common-----------------------------
3442 // Computes the element-type given a klass.
3443 const TypeOopPtr* TypeOopPtr::make_from_klass_common(ciKlass *klass, bool klass_change, bool try_for_exact) {
3444   if (klass->is_instance_klass() || klass->is_valuetype()) {
3445     Compile* C = Compile::current();
3446     Dependencies* deps = C->dependencies();
3447     assert((deps != NULL) == (C->method() != NULL && C->method()->code_size() > 0), "sanity");
3448     // Element is an instance
3449     bool klass_is_exact = false;
3450     if (klass->is_loaded()) {
3451       // Try to set klass_is_exact.
3452       ciInstanceKlass* ik = klass->as_instance_klass();
3453       klass_is_exact = ik->is_final();
3454       if (!klass_is_exact && klass_change
3455           && deps != NULL && UseUniqueSubclasses) {
3456         ciInstanceKlass* sub = ik->unique_concrete_subklass();
3457         if (sub != NULL) {
3458           deps->assert_abstract_with_unique_concrete_subtype(ik, sub);
3459           klass = ik = sub;
3460           klass_is_exact = sub->is_final();
3461         }
3462       }
3463       if (!klass_is_exact && try_for_exact
3464           && deps != NULL && UseExactTypes) {
3465         if (!ik->is_interface() && !ik->has_subklass()) {
3466           // Add a dependence; if concrete subclass added we need to recompile
3467           deps->assert_leaf_type(ik);
3468           klass_is_exact = true;
3469         }
3470       }
3471     }
3472     return TypeInstPtr::make(TypePtr::BotPTR, klass, klass_is_exact, NULL, Offset(0));
3473   } else if (klass->is_obj_array_klass()) {
3474     // Element is an object or value array. Recursively call ourself.
3475     const TypeOopPtr* etype = TypeOopPtr::make_from_klass_common(klass->as_array_klass()->element_klass(), false, try_for_exact);
3476     bool null_free = klass->is_loaded() && klass->as_array_klass()->storage_properties().is_null_free();
3477     if (null_free) {
3478       assert(etype->is_valuetypeptr(), "must be a valuetypeptr");
3479       etype = etype->join_speculative(TypePtr::NOTNULL)->is_oopptr();
3480     }
3481     // [V? has a subtype: [V. So even though V is final, [V? is not exact.
3482     bool xk = etype->klass_is_exact() && (!etype->is_valuetypeptr() || null_free);
3483     bool not_null_free = !etype->can_be_value_type() || xk;
3484     bool not_flat = !ValueArrayFlatten || not_null_free || (etype->is_valuetypeptr() && !etype->value_klass()->flatten_array());
3485     const TypeAry* arr0 = TypeAry::make(etype, TypeInt::POS, false, not_flat, not_null_free);
3486     // We used to pass NotNull in here, asserting that the sub-arrays
3487     // are all not-null.  This is not true in generally, as code can
3488     // slam NULLs down in the subarrays.
3489     const TypeAryPtr* arr = TypeAryPtr::make(TypePtr::BotPTR, arr0, klass, xk, Offset(0));
3490     return arr;
3491   } else if (klass->is_type_array_klass()) {
3492     // Element is an typeArray
3493     const Type* etype = get_const_basic_type(klass->as_type_array_klass()->element_type());
3494     const TypeAry* arr0 = TypeAry::make(etype, TypeInt::POS,
3495                                         /* stable= */ false, /* not_flat= */ true, /* not_null_free= */ true);
3496     // We used to pass NotNull in here, asserting that the array pointer
3497     // is not-null. That was not true in general.
3498     const TypeAryPtr* arr = TypeAryPtr::make(TypePtr::BotPTR, arr0, klass, true, Offset(0));
3499     return arr;
3500   } else if (klass->is_value_array_klass()) {
3501     ciValueKlass* vk = klass->as_array_klass()->element_klass()->as_value_klass();
3502     const TypeAry* arr0 = TypeAry::make(TypeValueType::make(vk), TypeInt::POS);
3503     const TypeAryPtr* arr = TypeAryPtr::make(TypePtr::BotPTR, arr0, klass, true, Offset(0));
3504     return arr;
3505   } else {
3506     ShouldNotReachHere();
3507     return NULL;
3508   }
3509 }
3510 
3511 //------------------------------make_from_constant-----------------------------
3512 // Make a java pointer from an oop constant
3513 const TypeOopPtr* TypeOopPtr::make_from_constant(ciObject* o, bool require_constant) {
3514   assert(!o->is_null_object(), "null object not yet handled here.");
3515 
3516   const bool make_constant = require_constant || o->should_be_constant();
3517 
3518   ciKlass* klass = o->klass();
3519   if (klass->is_instance_klass() || klass->is_valuetype()) {
3520     // Element is an instance or value type
3521     if (make_constant) {
3522       return TypeInstPtr::make(o);
3523     } else {
3524       return TypeInstPtr::make(TypePtr::NotNull, klass, true, NULL, Offset(0));
3525     }
3526   } else if (klass->is_obj_array_klass()) {
3527     // Element is an object array. Recursively call ourself.
3528     const TypeOopPtr* etype = TypeOopPtr::make_from_klass_raw(klass->as_array_klass()->element_klass());
3529     bool null_free = klass->is_loaded() && klass->as_array_klass()->storage_properties().is_null_free();
3530     if (null_free) {
3531       assert(etype->is_valuetypeptr(), "must be a valuetypeptr");
3532       etype = etype->join_speculative(TypePtr::NOTNULL)->is_oopptr();
3533     }
3534     const TypeAry* arr0 = TypeAry::make(etype, TypeInt::make(o->as_array()->length()),
3535                                         /* stable= */ false, /* not_flat= */ true, /* not_null_free= */ !null_free);
3536     // We used to pass NotNull in here, asserting that the sub-arrays
3537     // are all not-null.  This is not true in generally, as code can
3538     // slam NULLs down in the subarrays.
3539     if (make_constant) {
3540       return TypeAryPtr::make(TypePtr::Constant, o, arr0, klass, true, Offset(0));
3541     } else {
3542       return TypeAryPtr::make(TypePtr::NotNull, arr0, klass, true, Offset(0));
3543     }
3544   } else if (klass->is_type_array_klass()) {
3545     // Element is an typeArray
3546     const Type* etype = (Type*)get_const_basic_type(klass->as_type_array_klass()->element_type());
3547     const TypeAry* arr0 = TypeAry::make(etype, TypeInt::make(o->as_array()->length()),
3548                                         /* stable= */ false, /* not_flat= */ true, /* not_null_free= */ true);
3549     // We used to pass NotNull in here, asserting that the array pointer
3550     // is not-null. That was not true in general.
3551     if (make_constant) {
3552       return TypeAryPtr::make(TypePtr::Constant, o, arr0, klass, true, Offset(0));
3553     } else {
3554       return TypeAryPtr::make(TypePtr::NotNull, arr0, klass, true, Offset(0));
3555     }
3556   } else if (klass->is_value_array_klass()) {
3557     ciValueKlass* vk = klass->as_array_klass()->element_klass()->as_value_klass();
3558     const TypeAry* arr0 = TypeAry::make(TypeValueType::make(vk), TypeInt::make(o->as_array()->length()));
3559     // We used to pass NotNull in here, asserting that the sub-arrays
3560     // are all not-null.  This is not true in generally, as code can
3561     // slam NULLs down in the subarrays.
3562     if (make_constant) {
3563       return TypeAryPtr::make(TypePtr::Constant, o, arr0, klass, true, Offset(0));
3564     } else {
3565       return TypeAryPtr::make(TypePtr::NotNull, arr0, klass, true, Offset(0));
3566     }
3567   }
3568 
3569   fatal("unhandled object type");
3570   return NULL;
3571 }
3572 
3573 //------------------------------get_con----------------------------------------
3574 intptr_t TypeOopPtr::get_con() const {
3575   assert( _ptr == Null || _ptr == Constant, "" );
3576   assert(offset() >= 0, "");
3577 
3578   if (offset() != 0) {
3579     // After being ported to the compiler interface, the compiler no longer
3580     // directly manipulates the addresses of oops.  Rather, it only has a pointer
3581     // to a handle at compile time.  This handle is embedded in the generated
3582     // code and dereferenced at the time the nmethod is made.  Until that time,
3583     // it is not reasonable to do arithmetic with the addresses of oops (we don't
3584     // have access to the addresses!).  This does not seem to currently happen,
3585     // but this assertion here is to help prevent its occurence.
3586     tty->print_cr("Found oop constant with non-zero offset");
3587     ShouldNotReachHere();
3588   }
3589 
3590   return (intptr_t)const_oop()->constant_encoding();
3591 }
3592 
3593 
3594 //-----------------------------filter------------------------------------------
3595 // Do not allow interface-vs.-noninterface joins to collapse to top.
3596 const Type *TypeOopPtr::filter_helper(const Type *kills, bool include_speculative) const {
3597 
3598   const Type* ft = join_helper(kills, include_speculative);


3651     return (one == two) && TypePtr::eq(t);
3652   } else {
3653     return one->equals(two) && TypePtr::eq(t);
3654   }
3655 }
3656 
3657 //------------------------------hash-------------------------------------------
3658 // Type-specific hashing function.
3659 int TypeOopPtr::hash(void) const {
3660   return
3661     java_add(java_add((jint)(const_oop() ? const_oop()->hash() : 0), (jint)_klass_is_exact),
3662              java_add((jint)_instance_id, (jint)TypePtr::hash()));
3663 }
3664 
3665 //------------------------------dump2------------------------------------------
3666 #ifndef PRODUCT
3667 void TypeOopPtr::dump2( Dict &d, uint depth, outputStream *st ) const {
3668   st->print("oopptr:%s", ptr_msg[_ptr]);
3669   if( _klass_is_exact ) st->print(":exact");
3670   if( const_oop() ) st->print(INTPTR_FORMAT, p2i(const_oop()));
3671   _offset.dump2(st);





3672   if (_instance_id == InstanceTop)
3673     st->print(",iid=top");
3674   else if (_instance_id != InstanceBot)
3675     st->print(",iid=%d",_instance_id);
3676 
3677   dump_inline_depth(st);
3678   dump_speculative(st);
3679 }
3680 #endif
3681 
3682 //------------------------------singleton--------------------------------------
3683 // TRUE if Type is a singleton type, FALSE otherwise.   Singletons are simple
3684 // constants
3685 bool TypeOopPtr::singleton(void) const {
3686   // detune optimizer to not generate constant oop + constant offset as a constant!
3687   // TopPTR, Null, AnyNull, Constant are all singletons
3688   return (offset() == 0) && !below_centerline(_ptr);
3689 }
3690 
3691 //------------------------------add_offset-------------------------------------
3692 const TypePtr *TypeOopPtr::add_offset(intptr_t offset) const {
3693   return make(_ptr, xadd_offset(offset), _instance_id, add_offset_speculative(offset), _inline_depth);
3694 }
3695 
3696 /**
3697  * Return same type without a speculative part
3698  */
3699 const Type* TypeOopPtr::remove_speculative() const {
3700   if (_speculative == NULL) {
3701     return this;
3702   }
3703   assert(_inline_depth == InlineDepthTop || _inline_depth == InlineDepthBottom, "non speculative type shouldn't have inline depth");
3704   return make(_ptr, _offset, _instance_id, NULL, _inline_depth);
3705 }
3706 
3707 /**
3708  * Return same type but drop speculative part if we know we won't use


3760  *
3761  * @return  true if type profile is valuable
3762  */
3763 bool TypeOopPtr::would_improve_type(ciKlass* exact_kls, int inline_depth) const {
3764   // no way to improve an already exact type
3765   if (klass_is_exact()) {
3766     return false;
3767   }
3768   return TypePtr::would_improve_type(exact_kls, inline_depth);
3769 }
3770 
3771 //=============================================================================
3772 // Convenience common pre-built types.
3773 const TypeInstPtr *TypeInstPtr::NOTNULL;
3774 const TypeInstPtr *TypeInstPtr::BOTTOM;
3775 const TypeInstPtr *TypeInstPtr::MIRROR;
3776 const TypeInstPtr *TypeInstPtr::MARK;
3777 const TypeInstPtr *TypeInstPtr::KLASS;
3778 
3779 //------------------------------TypeInstPtr-------------------------------------
3780 TypeInstPtr::TypeInstPtr(PTR ptr, ciKlass* k, bool xk, ciObject* o, Offset off,
3781                          int instance_id, const TypePtr* speculative, int inline_depth)
3782   : TypeOopPtr(InstPtr, ptr, k, xk, o, off, Offset::bottom, instance_id, speculative, inline_depth),
3783     _name(k->name()) {
3784    assert(k != NULL &&
3785           (k->is_loaded() || o == NULL),
3786           "cannot have constants with non-loaded klass");
3787 };
3788 
3789 //------------------------------make-------------------------------------------
3790 const TypeInstPtr *TypeInstPtr::make(PTR ptr,
3791                                      ciKlass* k,
3792                                      bool xk,
3793                                      ciObject* o,
3794                                      Offset offset,
3795                                      int instance_id,
3796                                      const TypePtr* speculative,
3797                                      int inline_depth) {
3798   assert( !k->is_loaded() || k->is_instance_klass(), "Must be for instance");
3799   // Either const_oop() is NULL or else ptr is Constant
3800   assert( (!o && ptr != Constant) || (o && ptr == Constant),
3801           "constant pointers must have a value supplied" );
3802   // Ptr is never Null
3803   assert( ptr != Null, "NULL pointers are not typed" );
3804 
3805   assert(instance_id <= 0 || xk || !UseExactTypes, "instances are always exactly typed");
3806   if (!UseExactTypes)  xk = false;
3807   if (ptr == Constant) {
3808     // Note:  This case includes meta-object constants, such as methods.
3809     xk = true;
3810   } else if (k->is_loaded()) {
3811     ciInstanceKlass* ik = k->as_instance_klass();
3812     if (!xk && ik->is_final())     xk = true;   // no inexact final klass
3813     if (xk && ik->is_interface())  xk = false;  // no exact interface
3814   }


3861   if( (ik->is_final() || _const_oop) )  return this;  // cannot clear xk
3862   if( ik->is_interface() )              return this;  // cannot set xk
3863   return make(ptr(), klass(), klass_is_exact, const_oop(), _offset, _instance_id, _speculative, _inline_depth);
3864 }
3865 
3866 //-----------------------------cast_to_instance_id----------------------------
3867 const TypeOopPtr *TypeInstPtr::cast_to_instance_id(int instance_id) const {
3868   if( instance_id == _instance_id ) return this;
3869   return make(_ptr, klass(), _klass_is_exact, const_oop(), _offset, instance_id, _speculative, _inline_depth);
3870 }
3871 
3872 const TypeOopPtr *TypeInstPtr::cast_to_nonconst() const {
3873   if (const_oop() == NULL) return this;
3874   return make(NotNull, klass(), _klass_is_exact, NULL, _offset, _instance_id, _speculative, _inline_depth);
3875 }
3876 
3877 //------------------------------xmeet_unloaded---------------------------------
3878 // Compute the MEET of two InstPtrs when at least one is unloaded.
3879 // Assume classes are different since called after check for same name/class-loader
3880 const TypeInstPtr *TypeInstPtr::xmeet_unloaded(const TypeInstPtr *tinst) const {
3881     Offset off = meet_offset(tinst->offset());
3882     PTR ptr = meet_ptr(tinst->ptr());
3883     int instance_id = meet_instance_id(tinst->instance_id());
3884     const TypePtr* speculative = xmeet_speculative(tinst);
3885     int depth = meet_inline_depth(tinst->inline_depth());
3886 
3887     const TypeInstPtr *loaded    = is_loaded() ? this  : tinst;
3888     const TypeInstPtr *unloaded  = is_loaded() ? tinst : this;
3889     if( loaded->klass()->equals(ciEnv::current()->Object_klass()) ) {
3890       //
3891       // Meet unloaded class with java/lang/Object
3892       //
3893       // Meet
3894       //          |                     Unloaded Class
3895       //  Object  |   TOP    |   AnyNull | Constant |   NotNull |  BOTTOM   |
3896       //  ===================================================================
3897       //   TOP    | ..........................Unloaded......................|
3898       //  AnyNull |  U-AN    |................Unloaded......................|
3899       // Constant | ... O-NN .................................. |   O-BOT   |
3900       //  NotNull | ... O-NN .................................. |   O-BOT   |
3901       //  BOTTOM  | ........................Object-BOTTOM ..................|


3939   case FloatBot:
3940   case DoubleTop:
3941   case DoubleCon:
3942   case DoubleBot:
3943   case NarrowOop:
3944   case NarrowKlass:
3945   case Bottom:                  // Ye Olde Default
3946     return Type::BOTTOM;
3947   case Top:
3948     return this;
3949 
3950   default:                      // All else is a mistake
3951     typerr(t);
3952 
3953   case MetadataPtr:
3954   case KlassPtr:
3955   case RawPtr: return TypePtr::BOTTOM;
3956 
3957   case AryPtr: {                // All arrays inherit from Object class
3958     const TypeAryPtr *tp = t->is_aryptr();
3959     Offset offset = meet_offset(tp->offset());
3960     PTR ptr = meet_ptr(tp->ptr());
3961     int instance_id = meet_instance_id(tp->instance_id());
3962     const TypePtr* speculative = xmeet_speculative(tp);
3963     int depth = meet_inline_depth(tp->inline_depth());
3964     switch (ptr) {
3965     case TopPTR:
3966     case AnyNull:                // Fall 'down' to dual of object klass
3967       // For instances when a subclass meets a superclass we fall
3968       // below the centerline when the superclass is exact. We need to
3969       // do the same here.
3970       if (klass()->equals(ciEnv::current()->Object_klass()) && !klass_is_exact()) {
3971         return TypeAryPtr::make(ptr, tp->ary(), tp->klass(), tp->klass_is_exact(), offset, tp->field_offset(), instance_id, speculative, depth);
3972       } else {
3973         // cannot subclass, so the meet has to fall badly below the centerline
3974         ptr = NotNull;
3975         instance_id = InstanceBot;
3976         return TypeInstPtr::make( ptr, ciEnv::current()->Object_klass(), false, NULL, offset, instance_id, speculative, depth);
3977       }
3978     case Constant:
3979     case NotNull:
3980     case BotPTR:                // Fall down to object klass
3981       // LCA is object_klass, but if we subclass from the top we can do better
3982       if( above_centerline(_ptr) ) { // if( _ptr == TopPTR || _ptr == AnyNull )
3983         // If 'this' (InstPtr) is above the centerline and it is Object class
3984         // then we can subclass in the Java class hierarchy.
3985         // For instances when a subclass meets a superclass we fall
3986         // below the centerline when the superclass is exact. We need
3987         // to do the same here.
3988         if (klass()->equals(ciEnv::current()->Object_klass()) && !klass_is_exact()) {
3989           // that is, tp's array type is a subtype of my klass
3990           return TypeAryPtr::make(ptr, (ptr == Constant ? tp->const_oop() : NULL),
3991                                   tp->ary(), tp->klass(), tp->klass_is_exact(), offset, tp->field_offset(), instance_id, speculative, depth);
3992         }
3993       }
3994       // The other case cannot happen, since I cannot be a subtype of an array.
3995       // The meet falls down to Object class below centerline.
3996       if( ptr == Constant )
3997          ptr = NotNull;
3998       instance_id = InstanceBot;
3999       return make(ptr, ciEnv::current()->Object_klass(), false, NULL, offset, instance_id, speculative, depth);
4000     default: typerr(t);
4001     }
4002   }
4003 
4004   case OopPtr: {                // Meeting to OopPtrs
4005     // Found a OopPtr type vs self-InstPtr type
4006     const TypeOopPtr *tp = t->is_oopptr();
4007     Offset offset = meet_offset(tp->offset());
4008     PTR ptr = meet_ptr(tp->ptr());
4009     switch (tp->ptr()) {
4010     case TopPTR:
4011     case AnyNull: {
4012       int instance_id = meet_instance_id(InstanceTop);
4013       const TypePtr* speculative = xmeet_speculative(tp);
4014       int depth = meet_inline_depth(tp->inline_depth());
4015       return make(ptr, klass(), klass_is_exact(),
4016                   (ptr == Constant ? const_oop() : NULL), offset, instance_id, speculative, depth);
4017     }
4018     case NotNull:
4019     case BotPTR: {
4020       int instance_id = meet_instance_id(tp->instance_id());
4021       const TypePtr* speculative = xmeet_speculative(tp);
4022       int depth = meet_inline_depth(tp->inline_depth());
4023       return TypeOopPtr::make(ptr, offset, instance_id, speculative, depth);
4024     }
4025     default: typerr(t);
4026     }
4027   }
4028 
4029   case AnyPtr: {                // Meeting to AnyPtrs
4030     // Found an AnyPtr type vs self-InstPtr type
4031     const TypePtr *tp = t->is_ptr();
4032     Offset offset = meet_offset(tp->offset());
4033     PTR ptr = meet_ptr(tp->ptr());
4034     int instance_id = meet_instance_id(InstanceTop);
4035     const TypePtr* speculative = xmeet_speculative(tp);
4036     int depth = meet_inline_depth(tp->inline_depth());
4037     switch (tp->ptr()) {
4038     case Null:
4039       if( ptr == Null ) return TypePtr::make(AnyPtr, ptr, offset, speculative, depth);
4040       // else fall through to AnyNull
4041     case TopPTR:
4042     case AnyNull: {
4043       return make(ptr, klass(), klass_is_exact(),
4044                   (ptr == Constant ? const_oop() : NULL), offset, instance_id, speculative, depth);
4045     }
4046     case NotNull:
4047     case BotPTR:
4048       return TypePtr::make(AnyPtr, ptr, offset, speculative,depth);
4049     default: typerr(t);
4050     }
4051   }
4052 
4053   /*
4054                  A-top         }
4055                /   |   \       }  Tops
4056            B-top A-any C-top   }
4057               | /  |  \ |      }  Any-nulls
4058            B-any   |   C-any   }
4059               |    |    |
4060            B-con A-con C-con   } constants; not comparable across classes
4061               |    |    |
4062            B-not   |   C-not   }
4063               | \  |  / |      }  not-nulls
4064            B-bot A-not C-bot   }
4065                \   |   /       }  Bottoms
4066                  A-bot         }
4067   */
4068 
4069   case InstPtr: {                // Meeting 2 Oops?
4070     // Found an InstPtr sub-type vs self-InstPtr type
4071     const TypeInstPtr *tinst = t->is_instptr();
4072     Offset off = meet_offset( tinst->offset() );
4073     PTR ptr = meet_ptr( tinst->ptr() );
4074     int instance_id = meet_instance_id(tinst->instance_id());
4075     const TypePtr* speculative = xmeet_speculative(tinst);
4076     int depth = meet_inline_depth(tinst->inline_depth());
4077 
4078     // Check for easy case; klasses are equal (and perhaps not loaded!)
4079     // If we have constants, then we created oops so classes are loaded
4080     // and we can handle the constants further down.  This case handles
4081     // both-not-loaded or both-loaded classes
4082     if (ptr != Constant && klass()->equals(tinst->klass()) && klass_is_exact() == tinst->klass_is_exact()) {
4083       return make(ptr, klass(), klass_is_exact(), NULL, off, instance_id, speculative, depth);
4084     }
4085 
4086     // Classes require inspection in the Java klass hierarchy.  Must be loaded.
4087     ciKlass* tinst_klass = tinst->klass();
4088     ciKlass* this_klass  = this->klass();
4089     bool tinst_xk = tinst->klass_is_exact();
4090     bool this_xk  = this->klass_is_exact();
4091     if (!tinst_klass->is_loaded() || !this_klass->is_loaded() ) {
4092       // One of these classes has not been loaded


4219         else if (above_centerline(tinst ->_ptr))
4220           o = this_oop;
4221         else
4222           ptr = NotNull;
4223       }
4224       return make(ptr, this_klass, this_xk, o, off, instance_id, speculative, depth);
4225     } // Else classes are not equal
4226 
4227     // Since klasses are different, we require a LCA in the Java
4228     // class hierarchy - which means we have to fall to at least NotNull.
4229     if( ptr == TopPTR || ptr == AnyNull || ptr == Constant )
4230       ptr = NotNull;
4231 
4232     instance_id = InstanceBot;
4233 
4234     // Now we find the LCA of Java classes
4235     ciKlass* k = this_klass->least_common_ancestor(tinst_klass);
4236     return make(ptr, k, false, NULL, off, instance_id, speculative, depth);
4237   } // End of case InstPtr
4238 
4239   case ValueType: {
4240     const TypeValueType* tv = t->is_valuetype();
4241     if (above_centerline(ptr())) {
4242       if (tv->value_klass()->is_subtype_of(_klass)) {
4243         return t;
4244       } else {
4245         return TypeInstPtr::make(NotNull, _klass);
4246       }
4247     } else {
4248       PTR ptr = this->_ptr;
4249       if (ptr == Constant) {
4250         ptr = NotNull;
4251       }
4252       if (tv->value_klass()->is_subtype_of(_klass)) {
4253         return TypeInstPtr::make(ptr, _klass);
4254       } else {
4255         return TypeInstPtr::make(ptr, ciEnv::current()->Object_klass());
4256       }
4257     }
4258   }
4259 
4260   } // End of switch
4261   return this;                  // Return the double constant
4262 }
4263 
4264 
4265 //------------------------java_mirror_type--------------------------------------
4266 ciType* TypeInstPtr::java_mirror_type(bool* is_indirect_type) const {
4267   // must be a singleton type
4268   if( const_oop() == NULL )  return NULL;
4269 
4270   // must be of type java.lang.Class
4271   if( klass() != ciEnv::current()->Class_klass() )  return NULL;
4272 
4273   return const_oop()->as_instance()->java_mirror_type(is_indirect_type);
4274 }
4275 
4276 
4277 //------------------------------xdual------------------------------------------
4278 // Dual: do NOT dual on klasses.  This means I do NOT understand the Java
4279 // inheritance mechanism.
4280 const Type *TypeInstPtr::xdual() const {
4281   return new TypeInstPtr(dual_ptr(), klass(), klass_is_exact(), const_oop(), dual_offset(), dual_instance_id(), dual_speculative(), dual_inline_depth());
4282 }
4283 
4284 //------------------------------eq---------------------------------------------
4285 // Structural equality check for Type representations
4286 bool TypeInstPtr::eq( const Type *t ) const {
4287   const TypeInstPtr *p = t->is_instptr();
4288   return
4289     klass()->equals(p->klass()) &&
4290     TypeOopPtr::eq(p);          // Check sub-type stuff
4291 }
4292 
4293 //------------------------------hash-------------------------------------------


4308   case Constant:
4309     // TO DO: Make CI print the hex address of the underlying oop.
4310     if (WizardMode || Verbose) {
4311       const_oop()->print_oop(st);
4312     }
4313   case BotPTR:
4314     if (!WizardMode && !Verbose) {
4315       if( _klass_is_exact ) st->print(":exact");
4316       break;
4317     }
4318   case TopPTR:
4319   case AnyNull:
4320   case NotNull:
4321     st->print(":%s", ptr_msg[_ptr]);
4322     if( _klass_is_exact ) st->print(":exact");
4323     break;
4324   default:
4325     break;
4326   }
4327 
4328   _offset.dump2(st);




4329 
4330   st->print(" *");
4331   if (_instance_id == InstanceTop)
4332     st->print(",iid=top");
4333   else if (_instance_id != InstanceBot)
4334     st->print(",iid=%d",_instance_id);
4335 
4336   dump_inline_depth(st);
4337   dump_speculative(st);
4338 }
4339 #endif
4340 
4341 //------------------------------add_offset-------------------------------------
4342 const TypePtr *TypeInstPtr::add_offset(intptr_t offset) const {
4343   return make(_ptr, klass(), klass_is_exact(), const_oop(), xadd_offset(offset),
4344               _instance_id, add_offset_speculative(offset), _inline_depth);
4345 }
4346 
4347 const Type *TypeInstPtr::remove_speculative() const {
4348   if (_speculative == NULL) {


4360   return make(_ptr, klass(), klass_is_exact(), const_oop(), _offset, _instance_id, _speculative, depth);
4361 }
4362 
4363 const TypePtr *TypeInstPtr::with_instance_id(int instance_id) const {
4364   assert(is_known_instance(), "should be known");
4365   return make(_ptr, klass(), klass_is_exact(), const_oop(), _offset, instance_id, _speculative, _inline_depth);
4366 }
4367 
4368 //=============================================================================
4369 // Convenience common pre-built types.
4370 const TypeAryPtr *TypeAryPtr::RANGE;
4371 const TypeAryPtr *TypeAryPtr::OOPS;
4372 const TypeAryPtr *TypeAryPtr::NARROWOOPS;
4373 const TypeAryPtr *TypeAryPtr::BYTES;
4374 const TypeAryPtr *TypeAryPtr::SHORTS;
4375 const TypeAryPtr *TypeAryPtr::CHARS;
4376 const TypeAryPtr *TypeAryPtr::INTS;
4377 const TypeAryPtr *TypeAryPtr::LONGS;
4378 const TypeAryPtr *TypeAryPtr::FLOATS;
4379 const TypeAryPtr *TypeAryPtr::DOUBLES;
4380 const TypeAryPtr *TypeAryPtr::VALUES;
4381 
4382 //------------------------------make-------------------------------------------
4383 const TypeAryPtr* TypeAryPtr::make(PTR ptr, const TypeAry *ary, ciKlass* k, bool xk, Offset offset, Offset field_offset,
4384                                    int instance_id, const TypePtr* speculative, int inline_depth) {
4385   assert(!(k == NULL && ary->_elem->isa_int()),
4386          "integral arrays must be pre-equipped with a class");
4387   if (!xk) xk = ary->ary_must_be_exact();
4388   assert(instance_id <= 0 || xk || !UseExactTypes, "instances are always exactly typed");
4389   if (!UseExactTypes)  xk = (ptr == Constant);
4390   return (TypeAryPtr*)(new TypeAryPtr(ptr, NULL, ary, k, xk, offset, field_offset, instance_id, false, speculative, inline_depth))->hashcons();
4391 }
4392 
4393 //------------------------------make-------------------------------------------
4394 const TypeAryPtr* TypeAryPtr::make(PTR ptr, ciObject* o, const TypeAry *ary, ciKlass* k, bool xk, Offset offset, Offset field_offset,
4395                                    int instance_id, const TypePtr* speculative, int inline_depth,
4396                                    bool is_autobox_cache) {
4397   assert(!(k == NULL && ary->_elem->isa_int()),
4398          "integral arrays must be pre-equipped with a class");
4399   assert( (ptr==Constant && o) || (ptr!=Constant && !o), "" );
4400   if (!xk)  xk = (o != NULL) || ary->ary_must_be_exact();
4401   assert(instance_id <= 0 || xk || !UseExactTypes, "instances are always exactly typed");
4402   if (!UseExactTypes)  xk = (ptr == Constant);
4403   return (TypeAryPtr*)(new TypeAryPtr(ptr, o, ary, k, xk, offset, field_offset, instance_id, is_autobox_cache, speculative, inline_depth))->hashcons();
4404 }
4405 
4406 //------------------------------cast_to_ptr_type-------------------------------
4407 const Type *TypeAryPtr::cast_to_ptr_type(PTR ptr) const {
4408   if( ptr == _ptr ) return this;
4409   return make(ptr, const_oop(), _ary, klass(), klass_is_exact(), _offset, _field_offset, _instance_id, _speculative, _inline_depth, _is_autobox_cache);
4410 }
4411 
4412 
4413 //-----------------------------cast_to_exactness-------------------------------
4414 const Type *TypeAryPtr::cast_to_exactness(bool klass_is_exact) const {
4415   if( klass_is_exact == _klass_is_exact ) return this;
4416   if (!UseExactTypes)  return this;
4417   if (_ary->ary_must_be_exact())  return this;  // cannot clear xk
4418 
4419   const TypeAry* new_ary = _ary;
4420   if (klass() != NULL && klass()->is_obj_array_klass() && klass_is_exact) {
4421     // An object array can't be flat or null-free if the klass is exact
4422     new_ary = TypeAry::make(elem(), size(), is_stable(), /* not_flat= */ true, /* not_null_free= */ true);
4423   }
4424   return make(ptr(), const_oop(), new_ary, klass(), klass_is_exact, _offset, _field_offset, _instance_id, _speculative, _inline_depth, _is_autobox_cache);
4425 }
4426 
4427 //-----------------------------cast_to_instance_id----------------------------
4428 const TypeOopPtr *TypeAryPtr::cast_to_instance_id(int instance_id) const {
4429   if( instance_id == _instance_id ) return this;
4430   return make(_ptr, const_oop(), _ary, klass(), _klass_is_exact, _offset, _field_offset, instance_id, _speculative, _inline_depth, _is_autobox_cache);
4431 }
4432 
4433 const TypeOopPtr *TypeAryPtr::cast_to_nonconst() const {
4434   if (const_oop() == NULL) return this;
4435   return make(NotNull, NULL, _ary, klass(), _klass_is_exact, _offset, _field_offset, _instance_id, _speculative, _inline_depth);
4436 }
4437 
4438 
4439 //-----------------------------narrow_size_type-------------------------------
4440 // Local cache for arrayOopDesc::max_array_length(etype),
4441 // which is kind of slow (and cached elsewhere by other users).
4442 static jint max_array_length_cache[T_CONFLICT+1];
4443 static jint max_array_length(BasicType etype) {
4444   jint& cache = max_array_length_cache[etype];
4445   jint res = cache;
4446   if (res == 0) {
4447     switch (etype) {
4448     case T_NARROWOOP:
4449       etype = T_OBJECT;
4450       break;
4451     case T_NARROWKLASS:
4452     case T_CONFLICT:
4453     case T_ILLEGAL:
4454     case T_VOID:
4455       etype = T_BYTE;           // will produce conservatively high value


4481   if (hi > max_hi) {
4482     hi = max_hi;
4483     if (size->is_con()) {
4484       lo = hi;
4485     }
4486     chg = true;
4487   }
4488   // Negative length arrays will produce weird intermediate dead fast-path code
4489   if (lo > hi)
4490     return TypeInt::ZERO;
4491   if (!chg)
4492     return size;
4493   return TypeInt::make(lo, hi, Type::WidenMin);
4494 }
4495 
4496 //-------------------------------cast_to_size----------------------------------
4497 const TypeAryPtr* TypeAryPtr::cast_to_size(const TypeInt* new_size) const {
4498   assert(new_size != NULL, "");
4499   new_size = narrow_size_type(new_size);
4500   if (new_size == size())  return this;
4501   const TypeAry* new_ary = TypeAry::make(elem(), new_size, is_stable(), is_not_flat(), is_not_null_free());
4502   return make(ptr(), const_oop(), new_ary, klass(), klass_is_exact(), _offset, _field_offset, _instance_id, _speculative, _inline_depth, _is_autobox_cache);
4503 }
4504 
4505 //-------------------------------cast_to_not_flat------------------------------
4506 const TypeAryPtr* TypeAryPtr::cast_to_not_flat(bool not_flat) const {
4507   if (not_flat == is_not_flat()) {
4508     return this;
4509   }
4510   const TypeAry* new_ary = TypeAry::make(elem(), size(), is_stable(), not_flat, is_not_null_free());
4511   return make(ptr(), const_oop(), new_ary, klass(), klass_is_exact(), _offset, _field_offset, _instance_id, _speculative, _inline_depth, _is_autobox_cache);
4512 }
4513 
4514 //-------------------------------cast_to_not_null_free-------------------------
4515 const TypeAryPtr* TypeAryPtr::cast_to_not_null_free(bool not_null_free) const {
4516   if (not_null_free == is_not_null_free()) {
4517     return this;
4518   }
4519   // Not null free implies not flat
4520   const TypeAry* new_ary = TypeAry::make(elem(), size(), is_stable(), not_null_free ? true : is_not_flat(), not_null_free);
4521   return make(ptr(), const_oop(), new_ary, klass(), klass_is_exact(), _offset, _field_offset, _instance_id, _speculative, _inline_depth, _is_autobox_cache);
4522 }
4523 
4524 //------------------------------cast_to_stable---------------------------------
4525 const TypeAryPtr* TypeAryPtr::cast_to_stable(bool stable, int stable_dimension) const {
4526   if (stable_dimension <= 0 || (stable_dimension == 1 && stable == this->is_stable()))
4527     return this;
4528 
4529   const Type* elem = this->elem();
4530   const TypePtr* elem_ptr = elem->make_ptr();
4531 
4532   if (stable_dimension > 1 && elem_ptr != NULL && elem_ptr->isa_aryptr()) {
4533     // If this is widened from a narrow oop, TypeAry::make will re-narrow it.
4534     elem = elem_ptr = elem_ptr->is_aryptr()->cast_to_stable(stable, stable_dimension - 1);
4535   }
4536 
4537   const TypeAry* new_ary = TypeAry::make(elem, size(), stable, is_not_flat(), is_not_null_free());
4538 
4539   return make(ptr(), const_oop(), new_ary, klass(), klass_is_exact(), _offset, _field_offset, _instance_id, _speculative, _inline_depth, _is_autobox_cache);
4540 }
4541 
4542 //-----------------------------stable_dimension--------------------------------
4543 int TypeAryPtr::stable_dimension() const {
4544   if (!is_stable())  return 0;
4545   int dim = 1;
4546   const TypePtr* elem_ptr = elem()->make_ptr();
4547   if (elem_ptr != NULL && elem_ptr->isa_aryptr())
4548     dim += elem_ptr->is_aryptr()->stable_dimension();
4549   return dim;
4550 }
4551 
4552 //----------------------cast_to_autobox_cache-----------------------------------
4553 const TypeAryPtr* TypeAryPtr::cast_to_autobox_cache(bool cache) const {
4554   if (is_autobox_cache() == cache)  return this;
4555   const TypeOopPtr* etype = elem()->make_oopptr();
4556   if (etype == NULL)  return this;
4557   // The pointers in the autobox arrays are always non-null.
4558   TypePtr::PTR ptr_type = cache ? TypePtr::NotNull : TypePtr::AnyNull;
4559   etype = etype->cast_to_ptr_type(TypePtr::NotNull)->is_oopptr();
4560   const TypeAry* new_ary = TypeAry::make(etype, size(), is_stable(), is_not_flat(), is_not_null_free());
4561   return make(ptr(), const_oop(), new_ary, klass(), klass_is_exact(), _offset, _field_offset, _instance_id, _speculative, _inline_depth, cache);
4562 }
4563 
4564 //------------------------------eq---------------------------------------------
4565 // Structural equality check for Type representations
4566 bool TypeAryPtr::eq( const Type *t ) const {
4567   const TypeAryPtr *p = t->is_aryptr();
4568   return
4569     _ary == p->_ary &&  // Check array
4570     TypeOopPtr::eq(p) &&// Check sub-parts
4571     _field_offset == p->_field_offset;
4572 }
4573 
4574 //------------------------------hash-------------------------------------------
4575 // Type-specific hashing function.
4576 int TypeAryPtr::hash(void) const {
4577   return (intptr_t)_ary + TypeOopPtr::hash() + _field_offset.get();
4578 }
4579 
4580 //------------------------------meet-------------------------------------------
4581 // Compute the MEET of two types.  It returns a new Type object.
4582 const Type *TypeAryPtr::xmeet_helper(const Type *t) const {
4583   // Perform a fast test for common case; meeting the same types together.
4584   if( this == t ) return this;  // Meeting same type-rep?
4585   // Current "this->_base" is Pointer
4586   switch (t->base()) {          // switch on original type
4587 
4588   // Mixing ints & oops happens when javac reuses local variables
4589   case Int:
4590   case Long:
4591   case FloatTop:
4592   case FloatCon:
4593   case FloatBot:
4594   case DoubleTop:
4595   case DoubleCon:
4596   case DoubleBot:
4597   case NarrowOop:
4598   case NarrowKlass:
4599   case Bottom:                  // Ye Olde Default
4600     return Type::BOTTOM;
4601   case Top:
4602     return this;
4603 
4604   default:                      // All else is a mistake
4605     typerr(t);
4606 
4607   case OopPtr: {                // Meeting to OopPtrs
4608     // Found a OopPtr type vs self-AryPtr type
4609     const TypeOopPtr *tp = t->is_oopptr();
4610     Offset offset = meet_offset(tp->offset());
4611     PTR ptr = meet_ptr(tp->ptr());
4612     int depth = meet_inline_depth(tp->inline_depth());
4613     const TypePtr* speculative = xmeet_speculative(tp);
4614     switch (tp->ptr()) {
4615     case TopPTR:
4616     case AnyNull: {
4617       int instance_id = meet_instance_id(InstanceTop);
4618       return make(ptr, (ptr == Constant ? const_oop() : NULL),
4619                   _ary, _klass, _klass_is_exact, offset, _field_offset, instance_id, speculative, depth);
4620     }
4621     case BotPTR:
4622     case NotNull: {
4623       int instance_id = meet_instance_id(tp->instance_id());
4624       return TypeOopPtr::make(ptr, offset, instance_id, speculative, depth);
4625     }
4626     default: ShouldNotReachHere();
4627     }
4628   }
4629 
4630   case AnyPtr: {                // Meeting two AnyPtrs
4631     // Found an AnyPtr type vs self-AryPtr type
4632     const TypePtr *tp = t->is_ptr();
4633     Offset offset = meet_offset(tp->offset());
4634     PTR ptr = meet_ptr(tp->ptr());
4635     const TypePtr* speculative = xmeet_speculative(tp);
4636     int depth = meet_inline_depth(tp->inline_depth());
4637     switch (tp->ptr()) {
4638     case TopPTR:
4639       return this;
4640     case BotPTR:
4641     case NotNull:
4642       return TypePtr::make(AnyPtr, ptr, offset, speculative, depth);
4643     case Null:
4644       if( ptr == Null ) return TypePtr::make(AnyPtr, ptr, offset, speculative, depth);
4645       // else fall through to AnyNull
4646     case AnyNull: {
4647       int instance_id = meet_instance_id(InstanceTop);
4648       return make(ptr, (ptr == Constant ? const_oop() : NULL),
4649                   _ary, _klass, _klass_is_exact, offset, _field_offset, instance_id, speculative, depth);
4650     }
4651     default: ShouldNotReachHere();
4652     }
4653   }
4654 
4655   case MetadataPtr:
4656   case KlassPtr:
4657   case RawPtr: return TypePtr::BOTTOM;
4658 
4659   case AryPtr: {                // Meeting 2 references?
4660     const TypeAryPtr *tap = t->is_aryptr();
4661     Offset off = meet_offset(tap->offset());
4662     Offset field_off = meet_field_offset(tap->field_offset());
4663     const TypeAry *tary = _ary->meet_speculative(tap->_ary)->is_ary();
4664     PTR ptr = meet_ptr(tap->ptr());
4665     int instance_id = meet_instance_id(tap->instance_id());
4666     const TypePtr* speculative = xmeet_speculative(tap);
4667     int depth = meet_inline_depth(tap->inline_depth());
4668     ciKlass* lazy_klass = NULL;
4669     if (tary->_elem->isa_int()) {
4670       // Integral array element types have irrelevant lattice relations.
4671       // It is the klass that determines array layout, not the element type.
4672       if (_klass == NULL)
4673         lazy_klass = tap->_klass;
4674       else if (tap->_klass == NULL || tap->_klass == _klass) {
4675         lazy_klass = _klass;
4676       } else {
4677         // Something like byte[int+] meets char[int+].
4678         // This must fall to bottom, not (int[-128..65535])[int+].
4679         instance_id = InstanceBot;
4680         tary = TypeAry::make(Type::BOTTOM, tary->_size, tary->_stable, tary->_not_flat, tary->_not_null_free);
4681       }
4682     } else if (klass() != NULL && tap->klass() != NULL &&
4683                klass()->as_array_klass()->storage_properties().value() != tap->klass()->as_array_klass()->storage_properties().value()) {
4684       // Meeting value type arrays with conflicting storage properties
4685       if (tary->_elem->isa_valuetype()) {
4686         // Result is flattened
4687         off = Offset(elem()->isa_valuetype() ? offset() : tap->offset());
4688         field_off = elem()->isa_valuetype() ? field_offset() : tap->field_offset();
4689       } else if (tary->_elem->make_oopptr() != NULL && tary->_elem->make_oopptr()->isa_instptr() && below_centerline(ptr)) {
4690         // Result is non-flattened
4691         off = Offset(flattened_offset()).meet(Offset(tap->flattened_offset()));
4692         field_off = Offset::bottom;
4693       }
4694     } else // Non integral arrays.
4695       // Must fall to bottom if exact klasses in upper lattice
4696       // are not equal or super klass is exact.
4697       if ((above_centerline(ptr) || ptr == Constant) && klass() != tap->klass() &&
4698           // meet with top[] and bottom[] are processed further down:
4699           tap->_klass != NULL && this->_klass != NULL &&
4700           // both are exact and not equal:
4701           ((tap->_klass_is_exact && this->_klass_is_exact) ||
4702            // 'tap' is exact and super or unrelated:
4703            (tap->_klass_is_exact && !tap->klass()->is_subtype_of(klass())) ||
4704            // 'this' is exact and super or unrelated:
4705            (this->_klass_is_exact && !klass()->is_subtype_of(tap->klass())))) {
4706       if (above_centerline(ptr)) {
4707         tary = TypeAry::make(Type::BOTTOM, tary->_size, tary->_stable, tary->_not_flat, tary->_not_null_free);
4708       }
4709       return make(NotNull, NULL, tary, lazy_klass, false, off, field_off, InstanceBot, speculative, depth);
4710     }
4711 
4712     bool xk = false;
4713     switch (tap->ptr()) {
4714     case AnyNull:
4715     case TopPTR:
4716       // Compute new klass on demand, do not use tap->_klass
4717       if (below_centerline(this->_ptr)) {
4718         xk = this->_klass_is_exact;
4719       } else {
4720         xk = (tap->_klass_is_exact || this->_klass_is_exact);
4721       }
4722       return make(ptr, const_oop(), tary, lazy_klass, xk, off, field_off, instance_id, speculative, depth);
4723     case Constant: {
4724       ciObject* o = const_oop();
4725       if( _ptr == Constant ) {
4726         if( tap->const_oop() != NULL && !o->equals(tap->const_oop()) ) {
4727           xk = (klass() == tap->klass());
4728           ptr = NotNull;
4729           o = NULL;
4730           instance_id = InstanceBot;
4731         } else {
4732           xk = true;
4733         }
4734       } else if(above_centerline(_ptr)) {
4735         o = tap->const_oop();
4736         xk = true;
4737       } else {
4738         // Only precise for identical arrays
4739         xk = this->_klass_is_exact && (klass() == tap->klass());
4740       }
4741       return TypeAryPtr::make(ptr, o, tary, lazy_klass, xk, off, field_off, instance_id, speculative, depth);
4742     }
4743     case NotNull:
4744     case BotPTR:
4745       // Compute new klass on demand, do not use tap->_klass
4746       if (above_centerline(this->_ptr))
4747             xk = tap->_klass_is_exact;
4748       else  xk = (tap->_klass_is_exact & this->_klass_is_exact) &&
4749               (klass() == tap->klass()); // Only precise for identical arrays
4750       return TypeAryPtr::make(ptr, NULL, tary, lazy_klass, xk, off, field_off, instance_id, speculative, depth);
4751     default: ShouldNotReachHere();
4752     }
4753   }
4754 
4755   // All arrays inherit from Object class
4756   case InstPtr: {
4757     const TypeInstPtr *tp = t->is_instptr();
4758     Offset offset = meet_offset(tp->offset());
4759     PTR ptr = meet_ptr(tp->ptr());
4760     int instance_id = meet_instance_id(tp->instance_id());
4761     const TypePtr* speculative = xmeet_speculative(tp);
4762     int depth = meet_inline_depth(tp->inline_depth());
4763     switch (ptr) {
4764     case TopPTR:
4765     case AnyNull:                // Fall 'down' to dual of object klass
4766       // For instances when a subclass meets a superclass we fall
4767       // below the centerline when the superclass is exact. We need to
4768       // do the same here.
4769       if (tp->klass()->equals(ciEnv::current()->Object_klass()) && !tp->klass_is_exact()) {
4770         return TypeAryPtr::make(ptr, _ary, _klass, _klass_is_exact, offset, _field_offset, instance_id, speculative, depth);
4771       } else {
4772         // cannot subclass, so the meet has to fall badly below the centerline
4773         ptr = NotNull;
4774         instance_id = InstanceBot;
4775         return TypeInstPtr::make(ptr, ciEnv::current()->Object_klass(), false, NULL, offset, instance_id, speculative, depth);
4776       }
4777     case Constant:
4778     case NotNull:
4779     case BotPTR:                // Fall down to object klass
4780       // LCA is object_klass, but if we subclass from the top we can do better
4781       if (above_centerline(tp->ptr())) {
4782         // If 'tp'  is above the centerline and it is Object class
4783         // then we can subclass in the Java class hierarchy.
4784         // For instances when a subclass meets a superclass we fall
4785         // below the centerline when the superclass is exact. We need
4786         // to do the same here.
4787         if (tp->klass()->equals(ciEnv::current()->Object_klass()) && !tp->klass_is_exact()) {
4788           // that is, my array type is a subtype of 'tp' klass
4789           return make(ptr, (ptr == Constant ? const_oop() : NULL),
4790                       _ary, _klass, _klass_is_exact, offset, _field_offset, instance_id, speculative, depth);
4791         }
4792       }
4793       // The other case cannot happen, since t cannot be a subtype of an array.
4794       // The meet falls down to Object class below centerline.
4795       if( ptr == Constant )
4796          ptr = NotNull;
4797       instance_id = InstanceBot;
4798       return TypeInstPtr::make(ptr, ciEnv::current()->Object_klass(), false, NULL, offset, instance_id, speculative, depth);
4799     default: typerr(t);
4800     }
4801   }
4802 
4803   case ValueType: {
4804     // All value types inherit from Object
4805     PTR ptr = this->_ptr;
4806     if (ptr == Constant) {
4807       ptr = NotNull;
4808     }
4809     return TypeInstPtr::make(ptr, ciEnv::current()->Object_klass());
4810   }
4811 
4812   }
4813   return this;                  // Lint noise
4814 }
4815 
4816 //------------------------------xdual------------------------------------------
4817 // Dual: compute field-by-field dual
4818 const Type *TypeAryPtr::xdual() const {
4819   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());
4820 }
4821 
4822 Type::Offset TypeAryPtr::meet_field_offset(const Type::Offset offset) const {
4823   return _field_offset.meet(offset);
4824 }
4825 
4826 //------------------------------dual_offset------------------------------------
4827 Type::Offset TypeAryPtr::dual_field_offset() const {
4828   return _field_offset.dual();
4829 }
4830 
4831 //----------------------interface_vs_oop---------------------------------------
4832 #ifdef ASSERT
4833 bool TypeAryPtr::interface_vs_oop(const Type *t) const {
4834   const TypeAryPtr* t_aryptr = t->isa_aryptr();
4835   if (t_aryptr) {
4836     return _ary->interface_vs_oop(t_aryptr->_ary);
4837   }
4838   return false;
4839 }
4840 #endif
4841 
4842 //------------------------------dump2------------------------------------------
4843 #ifndef PRODUCT
4844 void TypeAryPtr::dump2( Dict &d, uint depth, outputStream *st ) const {
4845   _ary->dump2(d,depth,st);
4846   switch( _ptr ) {
4847   case Constant:
4848     const_oop()->print(st);
4849     break;
4850   case BotPTR:
4851     if (!WizardMode && !Verbose) {
4852       if( _klass_is_exact ) st->print(":exact");
4853       break;
4854     }
4855   case TopPTR:
4856   case AnyNull:
4857   case NotNull:
4858     st->print(":%s", ptr_msg[_ptr]);
4859     if( _klass_is_exact ) st->print(":exact");
4860     break;
4861   default:
4862     break;
4863   }
4864 
4865   if (elem()->isa_valuetype()) {
4866     st->print("(");
4867     _field_offset.dump2(st);
4868     st->print(")");
4869   }
4870   if (offset() != 0) {
4871     int header_size = objArrayOopDesc::header_size() * wordSize;
4872     if( _offset == Offset::top )       st->print("+undefined");
4873     else if( _offset == Offset::bottom )  st->print("+any");
4874     else if( offset() < header_size ) st->print("+%d", offset());
4875     else {
4876       BasicType basic_elem_type = elem()->basic_type();
4877       int array_base = arrayOopDesc::base_offset_in_bytes(basic_elem_type);
4878       int elem_size = type2aelembytes(basic_elem_type);
4879       st->print("[%d]", (offset() - array_base)/elem_size);
4880     }
4881   }
4882   st->print(" *");
4883   if (_instance_id == InstanceTop)
4884     st->print(",iid=top");
4885   else if (_instance_id != InstanceBot)
4886     st->print(",iid=%d",_instance_id);
4887 
4888   dump_inline_depth(st);
4889   dump_speculative(st);
4890 }
4891 #endif
4892 
4893 bool TypeAryPtr::empty(void) const {
4894   if (_ary->empty())       return true;
4895   return TypeOopPtr::empty();
4896 }
4897 
4898 //------------------------------add_offset-------------------------------------
4899 const TypePtr *TypeAryPtr::add_offset(intptr_t offset) const {
4900   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);
4901 }
4902 
4903 const Type *TypeAryPtr::remove_speculative() const {
4904   if (_speculative == NULL) {
4905     return this;
4906   }
4907   assert(_inline_depth == InlineDepthTop || _inline_depth == InlineDepthBottom, "non speculative type shouldn't have inline depth");
4908   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);
4909 }
4910 
4911 const Type* TypeAryPtr::cleanup_speculative() const {
4912   if (speculative() == NULL) {
4913     return this;
4914   }
4915   // Keep speculative part if it contains information about flat-/nullability
4916   const TypeAryPtr* spec_aryptr = speculative()->isa_aryptr();
4917   if (spec_aryptr != NULL && (spec_aryptr->is_not_flat() || spec_aryptr->is_not_null_free())) {
4918     return this;
4919   }
4920   return TypeOopPtr::cleanup_speculative();
4921 }
4922 
4923 const TypePtr *TypeAryPtr::with_inline_depth(int depth) const {
4924   if (!UseInlineDepthForSpeculativeTypes) {
4925     return this;
4926   }
4927   return make(_ptr, _const_oop, _ary->remove_speculative()->is_ary(), _klass, _klass_is_exact, _offset, _field_offset, _instance_id, _speculative, depth, _is_autobox_cache);
4928 }
4929 
4930 const TypeAryPtr* TypeAryPtr::with_field_offset(int offset) const {
4931   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);
4932 }
4933 
4934 const TypePtr* TypeAryPtr::add_field_offset_and_offset(intptr_t offset) const {
4935   int adj = 0;
4936   if (offset != Type::OffsetBot && offset != Type::OffsetTop) {
4937     const Type* elemtype = elem();
4938     if (elemtype->isa_valuetype()) {
4939       if (_offset.get() != OffsetBot && _offset.get() != OffsetTop) {
4940         adj = _offset.get();
4941         offset += _offset.get();
4942       }
4943       uint header = arrayOopDesc::base_offset_in_bytes(T_OBJECT);
4944       if (_field_offset.get() != OffsetBot && _field_offset.get() != OffsetTop) {
4945         offset += _field_offset.get();
4946         if (_offset.get() == OffsetBot || _offset.get() == OffsetTop) {
4947           offset += header;
4948         }
4949       }
4950       if (offset >= (intptr_t)header || offset < 0) {
4951         // Try to get the field of the value type array element we are pointing to
4952         ciKlass* arytype_klass = klass();
4953         ciValueArrayKlass* vak = arytype_klass->as_value_array_klass();
4954         ciValueKlass* vk = vak->element_klass()->as_value_klass();
4955         int shift = vak->log2_element_size();
4956         int mask = (1 << shift) - 1;
4957         intptr_t field_offset = ((offset - header) & mask);
4958         ciField* field = vk->get_field_by_offset(field_offset + vk->first_field_offset(), false);
4959         if (field == NULL) {
4960           // This may happen with nested AddP(base, AddP(base, base, offset), longcon(16))
4961           return add_offset(offset);
4962         } else {
4963           return with_field_offset(field_offset)->add_offset(offset - field_offset - adj);
4964         }
4965       }
4966     }
4967   }
4968   return add_offset(offset - adj);
4969 }
4970 
4971 // Return offset incremented by field_offset for flattened value type arrays
4972 const int TypeAryPtr::flattened_offset() const {
4973   int offset = _offset.get();
4974   if (offset != Type::OffsetBot && offset != Type::OffsetTop &&
4975       _field_offset != Offset::bottom && _field_offset != Offset::top) {
4976     offset += _field_offset.get();
4977   }
4978   return offset;
4979 }
4980 
4981 const TypePtr *TypeAryPtr::with_instance_id(int instance_id) const {
4982   assert(is_known_instance(), "should be known");
4983   return make(_ptr, _const_oop, _ary->remove_speculative()->is_ary(), _klass, _klass_is_exact, _offset, _field_offset, instance_id, _speculative, _inline_depth);
4984 }
4985 
4986 //=============================================================================
4987 
4988 
4989 //------------------------------hash-------------------------------------------
4990 // Type-specific hashing function.
4991 int TypeNarrowPtr::hash(void) const {
4992   return _ptrtype->hash() + 7;
4993 }
4994 
4995 bool TypeNarrowPtr::singleton(void) const {    // TRUE if type is a singleton
4996   return _ptrtype->singleton();
4997 }
4998 
4999 bool TypeNarrowPtr::empty(void) const {
5000   return _ptrtype->empty();
5001 }
5002 
5003 intptr_t TypeNarrowPtr::get_con() const {
5004   return _ptrtype->get_con();
5005 }
5006 
5007 bool TypeNarrowPtr::eq( const Type *t ) const {
5008   const TypeNarrowPtr* tc = isa_same_narrowptr(t);


5057   // Current "this->_base" is NarrowKlass or NarrowOop
5058   switch (t->base()) {          // switch on original type
5059 
5060   case Int:                     // Mixing ints & oops happens when javac
5061   case Long:                    // reuses local variables
5062   case FloatTop:
5063   case FloatCon:
5064   case FloatBot:
5065   case DoubleTop:
5066   case DoubleCon:
5067   case DoubleBot:
5068   case AnyPtr:
5069   case RawPtr:
5070   case OopPtr:
5071   case InstPtr:
5072   case AryPtr:
5073   case MetadataPtr:
5074   case KlassPtr:
5075   case NarrowOop:
5076   case NarrowKlass:

5077   case Bottom:                  // Ye Olde Default
5078     return Type::BOTTOM;
5079   case Top:
5080     return this;
5081 
5082   case ValueType:
5083     return t->xmeet(this);
5084 
5085   default:                      // All else is a mistake
5086     typerr(t);
5087 
5088   } // End of switch
5089 
5090   return this;
5091 }
5092 
5093 #ifndef PRODUCT
5094 void TypeNarrowPtr::dump2( Dict & d, uint depth, outputStream *st ) const {
5095   _ptrtype->dump2(d, depth, st);
5096 }
5097 #endif
5098 
5099 const TypeNarrowOop *TypeNarrowOop::BOTTOM;
5100 const TypeNarrowOop *TypeNarrowOop::NULL_PTR;
5101 
5102 
5103 const TypeNarrowOop* TypeNarrowOop::make(const TypePtr* type) {
5104   return (const TypeNarrowOop*)(new TypeNarrowOop(type))->hashcons();


5143     return (one == two) && TypePtr::eq(t);
5144   } else {
5145     return one->equals(two) && TypePtr::eq(t);
5146   }
5147 }
5148 
5149 //------------------------------hash-------------------------------------------
5150 // Type-specific hashing function.
5151 int TypeMetadataPtr::hash(void) const {
5152   return
5153     (metadata() ? metadata()->hash() : 0) +
5154     TypePtr::hash();
5155 }
5156 
5157 //------------------------------singleton--------------------------------------
5158 // TRUE if Type is a singleton type, FALSE otherwise.   Singletons are simple
5159 // constants
5160 bool TypeMetadataPtr::singleton(void) const {
5161   // detune optimizer to not generate constant metadata + constant offset as a constant!
5162   // TopPTR, Null, AnyNull, Constant are all singletons
5163   return (offset() == 0) && !below_centerline(_ptr);
5164 }
5165 
5166 //------------------------------add_offset-------------------------------------
5167 const TypePtr *TypeMetadataPtr::add_offset( intptr_t offset ) const {
5168   return make( _ptr, _metadata, xadd_offset(offset));
5169 }
5170 
5171 //-----------------------------filter------------------------------------------
5172 // Do not allow interface-vs.-noninterface joins to collapse to top.
5173 const Type *TypeMetadataPtr::filter_helper(const Type *kills, bool include_speculative) const {
5174   const TypeMetadataPtr* ft = join_helper(kills, include_speculative)->isa_metadataptr();
5175   if (ft == NULL || ft->empty())
5176     return Type::TOP;           // Canonical empty value
5177   return ft;
5178 }
5179 
5180  //------------------------------get_con----------------------------------------
5181 intptr_t TypeMetadataPtr::get_con() const {
5182   assert( _ptr == Null || _ptr == Constant, "" );
5183   assert(offset() >= 0, "");
5184 
5185   if (offset() != 0) {
5186     // After being ported to the compiler interface, the compiler no longer
5187     // directly manipulates the addresses of oops.  Rather, it only has a pointer
5188     // to a handle at compile time.  This handle is embedded in the generated
5189     // code and dereferenced at the time the nmethod is made.  Until that time,
5190     // it is not reasonable to do arithmetic with the addresses of oops (we don't
5191     // have access to the addresses!).  This does not seem to currently happen,
5192     // but this assertion here is to help prevent its occurence.
5193     tty->print_cr("Found oop constant with non-zero offset");
5194     ShouldNotReachHere();
5195   }
5196 
5197   return (intptr_t)metadata()->constant_encoding();
5198 }
5199 
5200 //------------------------------cast_to_ptr_type-------------------------------
5201 const Type *TypeMetadataPtr::cast_to_ptr_type(PTR ptr) const {
5202   if( ptr == _ptr ) return this;
5203   return make(ptr, metadata(), _offset);
5204 }
5205 


5216   case Long:                    // reuses local variables
5217   case FloatTop:
5218   case FloatCon:
5219   case FloatBot:
5220   case DoubleTop:
5221   case DoubleCon:
5222   case DoubleBot:
5223   case NarrowOop:
5224   case NarrowKlass:
5225   case Bottom:                  // Ye Olde Default
5226     return Type::BOTTOM;
5227   case Top:
5228     return this;
5229 
5230   default:                      // All else is a mistake
5231     typerr(t);
5232 
5233   case AnyPtr: {
5234     // Found an AnyPtr type vs self-OopPtr type
5235     const TypePtr *tp = t->is_ptr();
5236     Offset offset = meet_offset(tp->offset());
5237     PTR ptr = meet_ptr(tp->ptr());
5238     switch (tp->ptr()) {
5239     case Null:
5240       if (ptr == Null)  return TypePtr::make(AnyPtr, ptr, offset, tp->speculative(), tp->inline_depth());
5241       // else fall through:
5242     case TopPTR:
5243     case AnyNull: {
5244       return make(ptr, _metadata, offset);
5245     }
5246     case BotPTR:
5247     case NotNull:
5248       return TypePtr::make(AnyPtr, ptr, offset, tp->speculative(), tp->inline_depth());
5249     default: typerr(t);
5250     }
5251   }
5252 
5253   case RawPtr:
5254   case KlassPtr:
5255   case OopPtr:
5256   case InstPtr:
5257   case AryPtr:
5258     return TypePtr::BOTTOM;     // Oop meet raw is not well defined
5259 
5260   case MetadataPtr: {
5261     const TypeMetadataPtr *tp = t->is_metadataptr();
5262     Offset offset = meet_offset(tp->offset());
5263     PTR tptr = tp->ptr();
5264     PTR ptr = meet_ptr(tptr);
5265     ciMetadata* md = (tptr == TopPTR) ? metadata() : tp->metadata();
5266     if (tptr == TopPTR || _ptr == TopPTR ||
5267         metadata()->equals(tp->metadata())) {
5268       return make(ptr, md, offset);
5269     }
5270     // metadata is different
5271     if( ptr == Constant ) {  // Cannot be equal constants, so...
5272       if( tptr == Constant && _ptr != Constant)  return t;
5273       if( _ptr == Constant && tptr != Constant)  return this;
5274       ptr = NotNull;            // Fall down in lattice
5275     }
5276     return make(ptr, NULL, offset);
5277     break;
5278   }
5279   } // End of switch
5280   return this;                  // Return the double constant
5281 }
5282 
5283 
5284 //------------------------------xdual------------------------------------------
5285 // Dual of a pure metadata pointer.
5286 const Type *TypeMetadataPtr::xdual() const {
5287   return new TypeMetadataPtr(dual_ptr(), metadata(), dual_offset());
5288 }
5289 
5290 //------------------------------dump2------------------------------------------
5291 #ifndef PRODUCT
5292 void TypeMetadataPtr::dump2( Dict &d, uint depth, outputStream *st ) const {
5293   st->print("metadataptr:%s", ptr_msg[_ptr]);
5294   if( metadata() ) st->print(INTPTR_FORMAT, p2i(metadata()));
5295   switch (offset()) {
5296   case OffsetTop: st->print("+top"); break;
5297   case OffsetBot: st->print("+any"); break;
5298   case         0: break;
5299   default:        st->print("+%d",offset()); break;
5300   }
5301 }
5302 #endif
5303 
5304 
5305 //=============================================================================
5306 // Convenience common pre-built type.
5307 const TypeMetadataPtr *TypeMetadataPtr::BOTTOM;
5308 
5309 TypeMetadataPtr::TypeMetadataPtr(PTR ptr, ciMetadata* metadata, Offset offset):
5310   TypePtr(MetadataPtr, ptr, offset), _metadata(metadata) {
5311 }
5312 
5313 const TypeMetadataPtr* TypeMetadataPtr::make(ciMethod* m) {
5314   return make(Constant, m, Offset(0));
5315 }
5316 const TypeMetadataPtr* TypeMetadataPtr::make(ciMethodData* m) {
5317   return make(Constant, m, Offset(0));
5318 }
5319 
5320 //------------------------------make-------------------------------------------
5321 // Create a meta data constant
5322 const TypeMetadataPtr* TypeMetadataPtr::make(PTR ptr, ciMetadata* m, Offset offset) {
5323   assert(m == NULL || !m->is_klass(), "wrong type");
5324   return (TypeMetadataPtr*)(new TypeMetadataPtr(ptr, m, offset))->hashcons();
5325 }
5326 
5327 
5328 //=============================================================================
5329 // Convenience common pre-built types.
5330 
5331 // Not-null object klass or below
5332 const TypeKlassPtr *TypeKlassPtr::OBJECT;
5333 const TypeKlassPtr *TypeKlassPtr::OBJECT_OR_NULL;
5334 
5335 //------------------------------TypeKlassPtr-----------------------------------
5336 TypeKlassPtr::TypeKlassPtr( PTR ptr, ciKlass* klass, Offset offset )
5337   : TypePtr(KlassPtr, ptr, offset), _klass(klass), _klass_is_exact(ptr == Constant) {
5338 }
5339 
5340 //------------------------------make-------------------------------------------
5341 // ptr to klass 'k', if Constant, or possibly to a sub-klass if not a Constant
5342 const TypeKlassPtr* TypeKlassPtr::make(PTR ptr, ciKlass* k, Offset offset) {
5343   assert(k == NULL || k->is_instance_klass() || k->is_array_klass(), "Incorrect type of klass oop");
5344   return (TypeKlassPtr*)(new TypeKlassPtr(ptr, k, offset))->hashcons();




5345 }
5346 
5347 //------------------------------eq---------------------------------------------
5348 // Structural equality check for Type representations
5349 bool TypeKlassPtr::eq( const Type *t ) const {
5350   const TypeKlassPtr *p = t->is_klassptr();
5351   return klass() == p->klass() && TypePtr::eq(p);


5352 }
5353 
5354 //------------------------------hash-------------------------------------------
5355 // Type-specific hashing function.
5356 int TypeKlassPtr::hash(void) const {
5357   return java_add(klass() != NULL ? klass()->hash() : (jint)0, (jint)TypePtr::hash());
5358 }
5359 
5360 //------------------------------singleton--------------------------------------
5361 // TRUE if Type is a singleton type, FALSE otherwise.   Singletons are simple
5362 // constants
5363 bool TypeKlassPtr::singleton(void) const {
5364   // detune optimizer to not generate constant klass + constant offset as a constant!
5365   // TopPTR, Null, AnyNull, Constant are all singletons
5366   return (offset() == 0) && !below_centerline(_ptr);
5367 }
5368 
5369 // Do not allow interface-vs.-noninterface joins to collapse to top.
5370 const Type *TypeKlassPtr::filter_helper(const Type *kills, bool include_speculative) const {
5371   // logic here mirrors the one from TypeOopPtr::filter. See comments
5372   // there.
5373   const Type* ft = join_helper(kills, include_speculative);
5374   const TypeKlassPtr* ftkp = ft->isa_klassptr();
5375   const TypeKlassPtr* ktkp = kills->isa_klassptr();
5376 
5377   if (ft->empty()) {
5378     if (!empty() && ktkp != NULL && ktkp->is_loaded() && ktkp->klass()->is_interface())
5379       return kills;             // Uplift to interface
5380 
5381     return Type::TOP;           // Canonical empty value
5382   }
5383 
5384   // Interface klass type could be exact in opposite to interface type,
5385   // return it here instead of incorrect Constant ptr J/L/Object (6894807).
5386   if (ftkp != NULL && ktkp != NULL &&
5387       ftkp->is_loaded() &&  ftkp->klass()->is_interface() &&
5388       !ftkp->klass_is_exact() && // Keep exact interface klass
5389       ktkp->is_loaded() && !ktkp->klass()->is_interface()) {
5390     return ktkp->cast_to_ptr_type(ftkp->ptr());
5391   }
5392 
5393   return ft;
5394 }
5395 
5396 //----------------------compute_klass------------------------------------------
5397 // Compute the defining klass for this class
5398 ciKlass* TypeAryPtr::compute_klass(DEBUG_ONLY(bool verify)) const {
5399   // Compute _klass based on element type.
5400   ciKlass* k_ary = NULL;

5401   const TypeAryPtr *tary;
5402   const Type* el = elem();
5403   if (el->isa_narrowoop()) {
5404     el = el->make_ptr();
5405   }
5406 
5407   // Get element klass
5408   if (el->isa_instptr()) {
5409     // Compute object array klass from element klass
5410     bool null_free = el->is_valuetypeptr() && el->isa_instptr()->ptr() != TypePtr::TopPTR && !el->isa_instptr()->maybe_null();
5411     k_ary = ciArrayKlass::make(el->is_oopptr()->klass(), null_free);
5412   } else if (el->isa_valuetype()) {
5413     if (el->value_klass() != NULL) {
5414       k_ary = ciArrayKlass::make(el->value_klass(), /* null_free */ true);
5415     }
5416   } else if ((tary = el->isa_aryptr()) != NULL) {
5417     // Compute array klass from element klass
5418     ciKlass* k_elem = tary->klass();
5419     // If element type is something like bottom[], k_elem will be null.
5420     if (k_elem != NULL)
5421       k_ary = ciObjArrayKlass::make(k_elem);
5422   } else if ((el->base() == Type::Top) ||
5423              (el->base() == Type::Bottom)) {
5424     // element type of Bottom occurs from meet of basic type
5425     // and object; Top occurs when doing join on Bottom.
5426     // Leave k_ary at NULL.
5427   } else {
5428     // Cannot compute array klass directly from basic type,
5429     // since subtypes of TypeInt all have basic type T_INT.
5430 #ifdef ASSERT
5431     if (verify && el->isa_int()) {
5432       // Check simple cases when verifying klass.
5433       BasicType bt = T_ILLEGAL;
5434       if (el == TypeInt::BYTE) {
5435         bt = T_BYTE;


5460 
5461   // Oops, need to compute _klass and cache it
5462   ciKlass* k_ary = compute_klass();
5463 
5464   if( this != TypeAryPtr::OOPS && this->dual() != TypeAryPtr::OOPS ) {
5465     // The _klass field acts as a cache of the underlying
5466     // ciKlass for this array type.  In order to set the field,
5467     // we need to cast away const-ness.
5468     //
5469     // IMPORTANT NOTE: we *never* set the _klass field for the
5470     // type TypeAryPtr::OOPS.  This Type is shared between all
5471     // active compilations.  However, the ciKlass which represents
5472     // this Type is *not* shared between compilations, so caching
5473     // this value would result in fetching a dangling pointer.
5474     //
5475     // Recomputing the underlying ciKlass for each request is
5476     // a bit less efficient than caching, but calls to
5477     // TypeAryPtr::OOPS->klass() are not common enough to matter.
5478     ((TypeAryPtr*)this)->_klass = k_ary;
5479     if (UseCompressedOops && k_ary != NULL && k_ary->is_obj_array_klass() &&
5480         offset() != 0 && offset() != arrayOopDesc::length_offset_in_bytes()) {
5481       ((TypeAryPtr*)this)->_is_ptr_to_narrowoop = true;
5482     }
5483   }
5484   return k_ary;
5485 }
5486 
5487 
5488 //------------------------------add_offset-------------------------------------
5489 // Access internals of klass object
5490 const TypePtr *TypeKlassPtr::add_offset( intptr_t offset ) const {
5491   return make( _ptr, klass(), xadd_offset(offset) );
5492 }
5493 
5494 //------------------------------cast_to_ptr_type-------------------------------
5495 const Type *TypeKlassPtr::cast_to_ptr_type(PTR ptr) const {
5496   assert(_base == KlassPtr, "subclass must override cast_to_ptr_type");
5497   if( ptr == _ptr ) return this;
5498   return make(ptr, _klass, _offset);
5499 }
5500 
5501 
5502 //-----------------------------cast_to_exactness-------------------------------
5503 const Type *TypeKlassPtr::cast_to_exactness(bool klass_is_exact) const {
5504   if( klass_is_exact == _klass_is_exact ) return this;
5505   if (!UseExactTypes)  return this;
5506   return make(klass_is_exact ? Constant : NotNull, _klass, _offset);
5507 }
5508 
5509 
5510 //-----------------------------as_instance_type--------------------------------
5511 // Corresponding type for an instance of the given class.
5512 // It will be NotNull, and exact if and only if the klass type is exact.
5513 const TypeOopPtr* TypeKlassPtr::as_instance_type() const {
5514   ciKlass* k = klass();
5515   assert(k != NULL, "klass should not be NULL");
5516   bool    xk = klass_is_exact();
5517   //return TypeInstPtr::make(TypePtr::NotNull, k, xk, NULL, 0);
5518   const TypeOopPtr* toop = TypeOopPtr::make_from_klass_raw(k);
5519   guarantee(toop != NULL, "need type for given klass");
5520   toop = toop->cast_to_ptr_type(TypePtr::NotNull)->is_oopptr();
5521   return toop->cast_to_exactness(xk)->is_oopptr();
5522 }
5523 
5524 
5525 //------------------------------xmeet------------------------------------------
5526 // Compute the MEET of two types, return a new Type object.
5527 const Type    *TypeKlassPtr::xmeet( const Type *t ) const {
5528   // Perform a fast test for common case; meeting the same types together.
5529   if( this == t ) return this;  // Meeting same type-rep?
5530 
5531   // Current "this->_base" is Pointer
5532   switch (t->base()) {          // switch on original type
5533 
5534   case Int:                     // Mixing ints & oops happens when javac
5535   case Long:                    // reuses local variables
5536   case FloatTop:
5537   case FloatCon:
5538   case FloatBot:
5539   case DoubleTop:
5540   case DoubleCon:
5541   case DoubleBot:
5542   case NarrowOop:
5543   case NarrowKlass:
5544   case Bottom:                  // Ye Olde Default
5545     return Type::BOTTOM;
5546   case Top:
5547     return this;
5548 
5549   default:                      // All else is a mistake
5550     typerr(t);
5551 
5552   case AnyPtr: {                // Meeting to AnyPtrs
5553     // Found an AnyPtr type vs self-KlassPtr type
5554     const TypePtr *tp = t->is_ptr();
5555     Offset offset = meet_offset(tp->offset());
5556     PTR ptr = meet_ptr(tp->ptr());
5557     switch (tp->ptr()) {
5558     case TopPTR:
5559       return this;
5560     case Null:
5561       if( ptr == Null ) return TypePtr::make(AnyPtr, ptr, offset, tp->speculative(), tp->inline_depth());
5562     case AnyNull:
5563       return make( ptr, klass(), offset );
5564     case BotPTR:
5565     case NotNull:
5566       return TypePtr::make(AnyPtr, ptr, offset, tp->speculative(), tp->inline_depth());
5567     default: typerr(t);
5568     }
5569   }
5570 
5571   case RawPtr:
5572   case MetadataPtr:
5573   case OopPtr:
5574   case AryPtr:                  // Meet with AryPtr
5575   case InstPtr:                 // Meet with InstPtr
5576     return TypePtr::BOTTOM;
5577 
5578   //
5579   //             A-top         }
5580   //           /   |   \       }  Tops
5581   //       B-top A-any C-top   }
5582   //          | /  |  \ |      }  Any-nulls
5583   //       B-any   |   C-any   }
5584   //          |    |    |
5585   //       B-con A-con C-con   } constants; not comparable across classes
5586   //          |    |    |
5587   //       B-not   |   C-not   }
5588   //          | \  |  / |      }  not-nulls
5589   //       B-bot A-not C-bot   }
5590   //           \   |   /       }  Bottoms
5591   //             A-bot         }
5592   //
5593 
5594   case KlassPtr: {  // Meet two KlassPtr types
5595     const TypeKlassPtr *tkls = t->is_klassptr();
5596     Offset  off  = meet_offset(tkls->offset());
5597     PTR  ptr     = meet_ptr(tkls->ptr());
5598 
5599     if (klass() == NULL || tkls->klass() == NULL) {
5600       ciKlass* k = NULL;
5601       if (ptr == Constant) {
5602         k = (klass() == NULL) ? tkls->klass() : klass();
5603       }
5604       return make(ptr, k, off);
5605     }
5606 
5607     // Check for easy case; klasses are equal (and perhaps not loaded!)
5608     // If we have constants, then we created oops so classes are loaded
5609     // and we can handle the constants further down.  This case handles
5610     // not-loaded classes
5611     if( ptr != Constant && tkls->klass()->equals(klass()) ) {
5612       return make( ptr, klass(), off );
5613     }
5614 
5615     // Classes require inspection in the Java klass hierarchy.  Must be loaded.
5616     ciKlass* tkls_klass = tkls->klass();
5617     ciKlass* this_klass = this->klass();
5618     assert( tkls_klass->is_loaded(), "This class should have been loaded.");
5619     assert( this_klass->is_loaded(), "This class should have been loaded.");
5620 
5621     // If 'this' type is above the centerline and is a superclass of the
5622     // other, we can treat 'this' as having the same type as the other.
5623     if ((above_centerline(this->ptr())) &&
5624         tkls_klass->is_subtype_of(this_klass)) {
5625       this_klass = tkls_klass;
5626     }


5652     if( ptr == TopPTR || ptr == AnyNull || ptr == Constant )
5653       ptr = NotNull;
5654     // Now we find the LCA of Java classes
5655     ciKlass* k = this_klass->least_common_ancestor(tkls_klass);
5656     return   make( ptr, k, off );
5657   } // End of case KlassPtr
5658 
5659   } // End of switch
5660   return this;                  // Return the double constant
5661 }
5662 
5663 //------------------------------xdual------------------------------------------
5664 // Dual: compute field-by-field dual
5665 const Type    *TypeKlassPtr::xdual() const {
5666   return new TypeKlassPtr( dual_ptr(), klass(), dual_offset() );
5667 }
5668 
5669 //------------------------------get_con----------------------------------------
5670 intptr_t TypeKlassPtr::get_con() const {
5671   assert( _ptr == Null || _ptr == Constant, "" );
5672   assert(offset() >= 0, "");
5673 
5674   if (offset() != 0) {
5675     // After being ported to the compiler interface, the compiler no longer
5676     // directly manipulates the addresses of oops.  Rather, it only has a pointer
5677     // to a handle at compile time.  This handle is embedded in the generated
5678     // code and dereferenced at the time the nmethod is made.  Until that time,
5679     // it is not reasonable to do arithmetic with the addresses of oops (we don't
5680     // have access to the addresses!).  This does not seem to currently happen,
5681     // but this assertion here is to help prevent its occurence.
5682     tty->print_cr("Found oop constant with non-zero offset");
5683     ShouldNotReachHere();
5684   }
5685 
5686   return (intptr_t)klass()->constant_encoding();
5687 }
5688 //------------------------------dump2------------------------------------------
5689 // Dump Klass Type
5690 #ifndef PRODUCT
5691 void TypeKlassPtr::dump2( Dict & d, uint depth, outputStream *st ) const {
5692   switch( _ptr ) {
5693   case Constant:
5694     st->print("precise ");
5695   case NotNull:
5696     {
5697       if (klass() != NULL) {
5698         const char* name = klass()->name()->as_utf8();
5699         st->print("klass %s: " INTPTR_FORMAT, name, p2i(klass()));
5700       } else {
5701         st->print("klass BOTTOM");
5702       }
5703     }
5704   case BotPTR:
5705     if( !WizardMode && !Verbose && !_klass_is_exact ) break;
5706   case TopPTR:
5707   case AnyNull:
5708     st->print(":%s", ptr_msg[_ptr]);
5709     if( _klass_is_exact ) st->print(":exact");
5710     break;
5711   default:
5712     break;
5713   }
5714 
5715   _offset.dump2(st);




5716 
5717   st->print(" *");
5718 }
5719 #endif
5720 
5721 
5722 
5723 //=============================================================================
5724 // Convenience common pre-built types.
5725 
5726 //------------------------------make-------------------------------------------
5727 const TypeFunc *TypeFunc::make(const TypeTuple *domain_sig, const TypeTuple* domain_cc,
5728                                const TypeTuple *range_sig, const TypeTuple *range_cc) {
5729   return (TypeFunc*)(new TypeFunc(domain_sig, domain_cc, range_sig, range_cc))->hashcons();
5730 }
5731 
5732 const TypeFunc *TypeFunc::make(const TypeTuple *domain, const TypeTuple *range) {
5733   return make(domain, domain, range, range);
5734 }
5735 
5736 //------------------------------make-------------------------------------------
5737 const TypeFunc *TypeFunc::make(ciMethod* method) {
5738   Compile* C = Compile::current();
5739   const TypeFunc* tf = C->last_tf(method); // check cache
5740   if (tf != NULL)  return tf;  // The hit rate here is almost 50%.
5741   // Value types are not passed/returned by reference, instead each field of
5742   // the value type is passed/returned as an argument. We maintain two views of
5743   // the argument/return list here: one based on the signature (with a value
5744   // type argument/return as a single slot), one based on the actual calling
5745   // convention (with a value type argument/return as a list of its fields).
5746   const TypeTuple* domain_sig = TypeTuple::make_domain(method, false);
5747   const TypeTuple* domain_cc = method->has_scalarized_args() ? TypeTuple::make_domain(method, true) : domain_sig;
5748   ciSignature* sig = method->signature();
5749   bool has_scalarized_ret = sig->returns_never_null() && sig->return_type()->as_value_klass()->can_be_returned_as_fields();
5750   const TypeTuple* range_sig = TypeTuple::make_range(sig, false);
5751   const TypeTuple* range_cc = has_scalarized_ret ? TypeTuple::make_range(sig, true) : range_sig;
5752   tf = TypeFunc::make(domain_sig, domain_cc, range_sig, range_cc);
5753   C->set_last_tf(method, tf);  // fill cache
5754   return tf;
5755 }
5756 
5757 //------------------------------meet-------------------------------------------
5758 // Compute the MEET of two types.  It returns a new Type object.
5759 const Type *TypeFunc::xmeet( const Type *t ) const {
5760   // Perform a fast test for common case; meeting the same types together.
5761   if( this == t ) return this;  // Meeting same type-rep?
5762 
5763   // Current "this->_base" is Func
5764   switch (t->base()) {          // switch on original type
5765 
5766   case Bottom:                  // Ye Olde Default
5767     return t;
5768 
5769   default:                      // All else is a mistake
5770     typerr(t);
5771 
5772   case Top:
5773     break;
5774   }
5775   return this;                  // Return the double constant
5776 }
5777 
5778 //------------------------------xdual------------------------------------------
5779 // Dual: compute field-by-field dual
5780 const Type *TypeFunc::xdual() const {
5781   return this;
5782 }
5783 
5784 //------------------------------eq---------------------------------------------
5785 // Structural equality check for Type representations
5786 bool TypeFunc::eq( const Type *t ) const {
5787   const TypeFunc *a = (const TypeFunc*)t;
5788   return _domain_sig == a->_domain_sig &&
5789     _domain_cc == a->_domain_cc &&
5790     _range_sig == a->_range_sig &&
5791     _range_cc == a->_range_cc;
5792 }
5793 
5794 //------------------------------hash-------------------------------------------
5795 // Type-specific hashing function.
5796 int TypeFunc::hash(void) const {
5797   return (intptr_t)_domain_sig + (intptr_t)_domain_cc + (intptr_t)_range_sig + (intptr_t)_range_cc;
5798 }
5799 
5800 //------------------------------dump2------------------------------------------
5801 // Dump Function Type
5802 #ifndef PRODUCT
5803 void TypeFunc::dump2( Dict &d, uint depth, outputStream *st ) const {
5804   if( _range_sig->cnt() <= Parms )
5805     st->print("void");
5806   else {
5807     uint i;
5808     for (i = Parms; i < _range_sig->cnt()-1; i++) {
5809       _range_sig->field_at(i)->dump2(d,depth,st);
5810       st->print("/");
5811     }
5812     _range_sig->field_at(i)->dump2(d,depth,st);
5813   }
5814   st->print(" ");
5815   st->print("( ");
5816   if( !depth || d[this] ) {     // Check for recursive dump
5817     st->print("...)");
5818     return;
5819   }
5820   d.Insert((void*)this,(void*)this);    // Stop recursion
5821   if (Parms < _domain_sig->cnt())
5822     _domain_sig->field_at(Parms)->dump2(d,depth-1,st);
5823   for (uint i = Parms+1; i < _domain_sig->cnt(); i++) {
5824     st->print(", ");
5825     _domain_sig->field_at(i)->dump2(d,depth-1,st);
5826   }
5827   st->print(" )");
5828 }
5829 #endif
5830 
5831 //------------------------------singleton--------------------------------------
5832 // TRUE if Type is a singleton type, FALSE otherwise.   Singletons are simple
5833 // constants (Ldi nodes).  Singletons are integer, float or double constants
5834 // or a single symbol.
5835 bool TypeFunc::singleton(void) const {
5836   return false;                 // Never a singleton
5837 }
5838 
5839 bool TypeFunc::empty(void) const {
5840   return false;                 // Never empty
5841 }
5842 
5843 
5844 BasicType TypeFunc::return_type() const{
5845   if (range_sig()->cnt() == TypeFunc::Parms) {
5846     return T_VOID;
5847   }
5848   return range_sig()->field_at(TypeFunc::Parms)->basic_type();
5849 }
< prev index next >