< 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         // cases:
 248         //   can_be_constant    = (oop not scavengable || ScavengeRootsInCode != 0)
 249         //   should_be_constant = (oop not scavengable || ScavengeRootsInCode >= 2)
 250         // An oop is not scavengable if it is in the perm gen.
 251         const Type* con_type = NULL;
 252         ciObject* oop_constant = constant.as_object();
 253         if (oop_constant->is_null_object()) {
 254           con_type = Type::get_zero_type(T_OBJECT);
 255         } else {
 256           guarantee(require_constant || oop_constant->should_be_constant(), "con_type must get computed");
 257           con_type = TypeOopPtr::make_from_constant(oop_constant, require_constant);
 258           if (Compile::current()->eliminate_boxing() && is_autobox_cache) {
 259             con_type = con_type->is_aryptr()->cast_to_autobox_cache(true);
 260           }
 261           if (stable_dimension > 0) {
 262             assert(FoldStableValues, "sanity");
 263             assert(!con_type->is_zero_type(), "default value for stable field");
 264             con_type = con_type->is_aryptr()->cast_to_stable(true, stable_dimension);
 265           }


 267         if (is_narrow_oop) {
 268           con_type = con_type->make_narrowoop();
 269         }
 270         return con_type;
 271       }
 272     case T_ILLEGAL:
 273       // Invalid ciConstant returned due to OutOfMemoryError in the CI
 274       assert(Compile::current()->env()->failing(), "otherwise should not see this");
 275       return NULL;
 276     default:
 277       // Fall through to failure
 278       return NULL;
 279   }
 280 }
 281 
 282 static ciConstant check_mismatched_access(ciConstant con, BasicType loadbt, bool is_unsigned) {
 283   BasicType conbt = con.basic_type();
 284   switch (conbt) {
 285     case T_BOOLEAN: conbt = T_BYTE;   break;
 286     case T_ARRAY:   conbt = T_OBJECT; break;

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

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


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

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

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

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


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



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


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

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


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


















1876 
1877 //------------------------------make-------------------------------------------
1878 // Make a TypeTuple from the range of a method signature
1879 const TypeTuple *TypeTuple::make_range(ciSignature* sig) {
1880   ciType* return_type = sig->return_type();


1881   uint arg_cnt = return_type->size();





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











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









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




1923   }
1924 
1925   int i = 0;
1926   while (pos < TypeFunc::Parms + arg_cnt) {
1927     ciType* type = sig->type_at(i);


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










1950     default:
1951       ShouldNotReachHere();
1952     }







1953     i++;
1954   }

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


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




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


2226   ciKlass* tklass = toop->klass();
2227   if (tklass == NULL)       return false;  // unloaded class
2228   if (!tklass->is_loaded()) return false;  // unloaded class
2229   const TypeInstPtr* tinst;
2230   if (_elem->isa_narrowoop())
2231     tinst = _elem->make_ptr()->isa_instptr();
2232   else
2233     tinst = _elem->isa_instptr();
2234   if (tinst)
2235     return tklass->as_instance_klass()->is_final();
2236   const TypeAryPtr*  tap;
2237   if (_elem->isa_narrowoop())
2238     tap = _elem->make_ptr()->isa_aryptr();
2239   else
2240     tap = _elem->isa_aryptr();
2241   if (tap)
2242     return tap->ary()->ary_must_be_exact();
2243   return false;
2244 }
2245 


















































































































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


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


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


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


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









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





3016           assert(field != NULL, "missing field");
3017           BasicType basic_elem_type = field->layout_type();

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

3019                                                        basic_elem_type == T_ARRAY);
3020         } else {
3021           // Instance fields which contains a compressed oop references.
3022           field = ik->get_field_by_offset(_offset, false);

3023           if (field != NULL) {
3024             BasicType basic_elem_type = field->layout_type();
3025             _is_ptr_to_narrowoop = UseCompressedOops && (basic_elem_type == T_OBJECT ||

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


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





3220     return arr;
3221   } else {
3222     ShouldNotReachHere();
3223     return NULL;
3224   }
3225 }
3226 
3227 //------------------------------make_from_constant-----------------------------
3228 // Make a java pointer from an oop constant
3229 const TypeOopPtr* TypeOopPtr::make_from_constant(ciObject* o, bool require_constant) {
3230   assert(!o->is_null_object(), "null object not yet handled here.");
3231   ciKlass* klass = o->klass();
3232   if (klass->is_instance_klass()) {
3233     // Element is an instance
3234     if (require_constant) {
3235       if (!o->can_be_constant())  return NULL;
3236     } else if (!o->should_be_constant()) {
3237       return TypeInstPtr::make(TypePtr::NotNull, klass, true, NULL, 0);
3238     }
3239     return TypeInstPtr::make(o);
3240   } else if (klass->is_obj_array_klass()) {
3241     // Element is an object array. Recursively call ourself.
3242     const TypeOopPtr *etype =
3243       TypeOopPtr::make_from_klass_raw(klass->as_obj_array_klass()->element_klass());
3244     const TypeAry* arr0 = TypeAry::make(etype, TypeInt::make(o->as_array()->length()));
3245     // We used to pass NotNull in here, asserting that the sub-arrays
3246     // are all not-null.  This is not true in generally, as code can
3247     // slam NULLs down in the subarrays.
3248     if (require_constant) {
3249       if (!o->can_be_constant())  return NULL;
3250     } else if (!o->should_be_constant()) {
3251       return TypeAryPtr::make(TypePtr::NotNull, arr0, klass, true, 0);
3252     }
3253     const TypeAryPtr* arr = TypeAryPtr::make(TypePtr::Constant, o, arr0, klass, true, 0);
3254     return arr;
3255   } else if (klass->is_type_array_klass()) {
3256     // Element is an typeArray
3257     const Type* etype =
3258       (Type*)get_const_basic_type(klass->as_type_array_klass()->element_type());
3259     const TypeAry* arr0 = TypeAry::make(etype, TypeInt::make(o->as_array()->length()));
3260     // We used to pass NotNull in here, asserting that the array pointer
3261     // is not-null. That was not true in general.
3262     if (require_constant) {
3263       if (!o->can_be_constant())  return NULL;
3264     } else if (!o->should_be_constant()) {
3265       return TypeAryPtr::make(TypePtr::NotNull, arr0, klass, true, 0);













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


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


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


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


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


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


















3946   } // End of switch
3947   return this;                  // Return the double constant
3948 }
3949 
3950 
3951 //------------------------java_mirror_type--------------------------------------
3952 ciType* TypeInstPtr::java_mirror_type() const {
3953   // must be a singleton type
3954   if( const_oop() == NULL )  return NULL;
3955 
3956   // must be of type java.lang.Class
3957   if( klass() != ciEnv::current()->Class_klass() )  return NULL;
3958 
3959   return const_oop()->as_instance()->java_mirror_type();
3960 }
3961 
3962 
3963 //------------------------------xdual------------------------------------------
3964 // Dual: do NOT dual on klasses.  This means I do NOT understand the Java
3965 // inheritance mechanism.


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


4052 
4053 const TypePtr *TypeInstPtr::with_instance_id(int instance_id) const {
4054   assert(is_known_instance(), "should be known");
4055   return make(_ptr, klass(), klass_is_exact(), const_oop(), _offset, instance_id, _speculative, _inline_depth);
4056 }
4057 
4058 //=============================================================================
4059 // Convenience common pre-built types.
4060 const TypeAryPtr *TypeAryPtr::RANGE;
4061 const TypeAryPtr *TypeAryPtr::OOPS;
4062 const TypeAryPtr *TypeAryPtr::NARROWOOPS;
4063 const TypeAryPtr *TypeAryPtr::BYTES;
4064 const TypeAryPtr *TypeAryPtr::SHORTS;
4065 const TypeAryPtr *TypeAryPtr::CHARS;
4066 const TypeAryPtr *TypeAryPtr::INTS;
4067 const TypeAryPtr *TypeAryPtr::LONGS;
4068 const TypeAryPtr *TypeAryPtr::FLOATS;
4069 const TypeAryPtr *TypeAryPtr::DOUBLES;
4070 
4071 //------------------------------make-------------------------------------------
4072 const TypeAryPtr *TypeAryPtr::make(PTR ptr, const TypeAry *ary, ciKlass* k, bool xk, int offset,
4073                                    int instance_id, const TypePtr* speculative, int inline_depth) {
4074   assert(!(k == NULL && ary->_elem->isa_int()),
4075          "integral arrays must be pre-equipped with a class");
4076   if (!xk)  xk = ary->ary_must_be_exact();
4077   assert(instance_id <= 0 || xk || !UseExactTypes, "instances are always exactly typed");
4078   if (!UseExactTypes)  xk = (ptr == Constant);
4079   return (TypeAryPtr*)(new TypeAryPtr(ptr, NULL, ary, k, xk, offset, instance_id, false, speculative, inline_depth))->hashcons();
4080 }
4081 
4082 //------------------------------make-------------------------------------------
4083 const TypeAryPtr *TypeAryPtr::make(PTR ptr, ciObject* o, const TypeAry *ary, ciKlass* k, bool xk, int offset,
4084                                    int instance_id, const TypePtr* speculative, int inline_depth,
4085                                    bool is_autobox_cache) {
4086   assert(!(k == NULL && ary->_elem->isa_int()),
4087          "integral arrays must be pre-equipped with a class");
4088   assert( (ptr==Constant && o) || (ptr!=Constant && !o), "" );
4089   if (!xk)  xk = (o != NULL) || ary->ary_must_be_exact();
4090   assert(instance_id <= 0 || xk || !UseExactTypes, "instances are always exactly typed");
4091   if (!UseExactTypes)  xk = (ptr == Constant);
4092   return (TypeAryPtr*)(new TypeAryPtr(ptr, o, ary, k, xk, offset, instance_id, is_autobox_cache, speculative, inline_depth))->hashcons();
4093 }
4094 
4095 //------------------------------cast_to_ptr_type-------------------------------
4096 const Type *TypeAryPtr::cast_to_ptr_type(PTR ptr) const {
4097   if( ptr == _ptr ) return this;
4098   return make(ptr, const_oop(), _ary, klass(), klass_is_exact(), _offset, _instance_id, _speculative, _inline_depth);
4099 }
4100 
4101 
4102 //-----------------------------cast_to_exactness-------------------------------
4103 const Type *TypeAryPtr::cast_to_exactness(bool klass_is_exact) const {
4104   if( klass_is_exact == _klass_is_exact ) return this;
4105   if (!UseExactTypes)  return this;
4106   if (_ary->ary_must_be_exact())  return this;  // cannot clear xk
4107   return make(ptr(), const_oop(), _ary, klass(), klass_is_exact, _offset, _instance_id, _speculative, _inline_depth);
4108 }
4109 
4110 //-----------------------------cast_to_instance_id----------------------------
4111 const TypeOopPtr *TypeAryPtr::cast_to_instance_id(int instance_id) const {
4112   if( instance_id == _instance_id ) return this;
4113   return make(_ptr, const_oop(), _ary, klass(), _klass_is_exact, _offset, instance_id, _speculative, _inline_depth);
4114 }
4115 
4116 const TypeOopPtr *TypeAryPtr::cast_to_nonconst() const {
4117   if (const_oop() == NULL) return this;
4118   return make(NotNull, NULL, _ary, klass(), _klass_is_exact, _offset, _instance_id, _speculative, _inline_depth);
4119 }
4120 
4121 
4122 //-----------------------------narrow_size_type-------------------------------
4123 // Local cache for arrayOopDesc::max_array_length(etype),
4124 // which is kind of slow (and cached elsewhere by other users).
4125 static jint max_array_length_cache[T_CONFLICT+1];
4126 static jint max_array_length(BasicType etype) {
4127   jint& cache = max_array_length_cache[etype];
4128   jint res = cache;
4129   if (res == 0) {
4130     switch (etype) {
4131     case T_NARROWOOP:
4132       etype = T_OBJECT;
4133       break;
4134     case T_NARROWKLASS:
4135     case T_CONFLICT:
4136     case T_ILLEGAL:
4137     case T_VOID:
4138       etype = T_BYTE;           // will produce conservatively high value


4165     hi = max_hi;
4166     if (size->is_con()) {
4167       lo = hi;
4168     }
4169     chg = true;
4170   }
4171   // Negative length arrays will produce weird intermediate dead fast-path code
4172   if (lo > hi)
4173     return TypeInt::ZERO;
4174   if (!chg)
4175     return size;
4176   return TypeInt::make(lo, hi, Type::WidenMin);
4177 }
4178 
4179 //-------------------------------cast_to_size----------------------------------
4180 const TypeAryPtr* TypeAryPtr::cast_to_size(const TypeInt* new_size) const {
4181   assert(new_size != NULL, "");
4182   new_size = narrow_size_type(new_size);
4183   if (new_size == size())  return this;
4184   const TypeAry* new_ary = TypeAry::make(elem(), new_size, is_stable());
4185   return make(ptr(), const_oop(), new_ary, klass(), klass_is_exact(), _offset, _instance_id, _speculative, _inline_depth);
4186 }
4187 
4188 //------------------------------cast_to_stable---------------------------------
4189 const TypeAryPtr* TypeAryPtr::cast_to_stable(bool stable, int stable_dimension) const {
4190   if (stable_dimension <= 0 || (stable_dimension == 1 && stable == this->is_stable()))
4191     return this;
4192 
4193   const Type* elem = this->elem();
4194   const TypePtr* elem_ptr = elem->make_ptr();
4195 
4196   if (stable_dimension > 1 && elem_ptr != NULL && elem_ptr->isa_aryptr()) {
4197     // If this is widened from a narrow oop, TypeAry::make will re-narrow it.
4198     elem = elem_ptr = elem_ptr->is_aryptr()->cast_to_stable(stable, stable_dimension - 1);
4199   }
4200 
4201   const TypeAry* new_ary = TypeAry::make(elem, size(), stable);
4202 
4203   return make(ptr(), const_oop(), new_ary, klass(), klass_is_exact(), _offset, _instance_id, _speculative, _inline_depth);
4204 }
4205 
4206 //-----------------------------stable_dimension--------------------------------
4207 int TypeAryPtr::stable_dimension() const {
4208   if (!is_stable())  return 0;
4209   int dim = 1;
4210   const TypePtr* elem_ptr = elem()->make_ptr();
4211   if (elem_ptr != NULL && elem_ptr->isa_aryptr())
4212     dim += elem_ptr->is_aryptr()->stable_dimension();
4213   return dim;
4214 }
4215 
4216 //----------------------cast_to_autobox_cache-----------------------------------
4217 const TypeAryPtr* TypeAryPtr::cast_to_autobox_cache(bool cache) const {
4218   if (is_autobox_cache() == cache)  return this;
4219   const TypeOopPtr* etype = elem()->make_oopptr();
4220   if (etype == NULL)  return this;
4221   // The pointers in the autobox arrays are always non-null.
4222   TypePtr::PTR ptr_type = cache ? TypePtr::NotNull : TypePtr::AnyNull;
4223   etype = etype->cast_to_ptr_type(TypePtr::NotNull)->is_oopptr();
4224   const TypeAry* new_ary = TypeAry::make(etype, size(), is_stable());
4225   return make(ptr(), const_oop(), new_ary, klass(), klass_is_exact(), _offset, _instance_id, _speculative, _inline_depth, cache);
4226 }
4227 
4228 //------------------------------eq---------------------------------------------
4229 // Structural equality check for Type representations
4230 bool TypeAryPtr::eq( const Type *t ) const {
4231   const TypeAryPtr *p = t->is_aryptr();
4232   return
4233     _ary == p->_ary &&  // Check array
4234     TypeOopPtr::eq(p);  // Check sub-parts

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

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






4452   }
4453   return this;                  // Lint noise
4454 }
4455 
4456 //------------------------------xdual------------------------------------------
4457 // Dual: compute field-by-field dual
4458 const Type *TypeAryPtr::xdual() const {
4459   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());









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





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



















































4542 }
4543 
4544 const TypePtr *TypeAryPtr::with_instance_id(int instance_id) const {
4545   assert(is_known_instance(), "should be known");
4546   return make(_ptr, _const_oop, _ary->remove_speculative()->is_ary(), _klass, _klass_is_exact, _offset, instance_id, _speculative, _inline_depth);
4547 }
4548 
4549 //=============================================================================
4550 

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


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



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


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


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


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


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

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








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


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





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


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


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


   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         // cases:
 308         //   can_be_constant    = (oop not scavengable || ScavengeRootsInCode != 0)
 309         //   should_be_constant = (oop not scavengable || ScavengeRootsInCode >= 2)
 310         // An oop is not scavengable if it is in the perm gen.
 311         const Type* con_type = NULL;
 312         ciObject* oop_constant = constant.as_object();
 313         if (oop_constant->is_null_object()) {
 314           con_type = Type::get_zero_type(T_OBJECT);
 315         } else {
 316           guarantee(require_constant || oop_constant->should_be_constant(), "con_type must get computed");
 317           con_type = TypeOopPtr::make_from_constant(oop_constant, require_constant);
 318           if (Compile::current()->eliminate_boxing() && is_autobox_cache) {
 319             con_type = con_type->is_aryptr()->cast_to_autobox_cache(true);
 320           }
 321           if (stable_dimension > 0) {
 322             assert(FoldStableValues, "sanity");
 323             assert(!con_type->is_zero_type(), "default value for stable field");
 324             con_type = con_type->is_aryptr()->cast_to_stable(true, stable_dimension);
 325           }


 327         if (is_narrow_oop) {
 328           con_type = con_type->make_narrowoop();
 329         }
 330         return con_type;
 331       }
 332     case T_ILLEGAL:
 333       // Invalid ciConstant returned due to OutOfMemoryError in the CI
 334       assert(Compile::current()->env()->failing(), "otherwise should not see this");
 335       return NULL;
 336     default:
 337       // Fall through to failure
 338       return NULL;
 339   }
 340 }
 341 
 342 static ciConstant check_mismatched_access(ciConstant con, BasicType loadbt, bool is_unsigned) {
 343   BasicType conbt = con.basic_type();
 344   switch (conbt) {
 345     case T_BOOLEAN: conbt = T_BYTE;   break;
 346     case T_ARRAY:   conbt = T_OBJECT; break;
 347     case T_VALUETYPE: conbt = T_OBJECT; break;
 348     default:                          break;
 349   }
 350   switch (loadbt) {
 351     case T_BOOLEAN:   loadbt = T_BYTE;   break;
 352     case T_NARROWOOP: loadbt = T_OBJECT; break;
 353     case T_ARRAY:     loadbt = T_OBJECT; break;
 354     case T_VALUETYPE: loadbt = T_OBJECT; break;
 355     case T_ADDRESS:   loadbt = T_OBJECT; break;
 356     default:                             break;
 357   }
 358   if (conbt == loadbt) {
 359     if (is_unsigned && conbt == T_BYTE) {
 360       // LoadB (T_BYTE) with a small mask (<=8-bit) is converted to LoadUB (T_BYTE).
 361       return ciConstant(T_INT, con.as_int() & 0xFF);
 362     } else {
 363       return con;
 364     }
 365   }
 366   if (conbt == T_SHORT && loadbt == T_CHAR) {
 367     // LoadS (T_SHORT) with a small mask (<=16-bit) is converted to LoadUS (T_CHAR).
 368     return ciConstant(T_INT, con.as_int() & 0xFFFF);
 369   }
 370   return ciConstant(); // T_ILLEGAL
 371 }
 372 
 373 // Try to constant-fold a stable array element.
 374 const Type* Type::make_constant_from_array_element(ciArray* array, int off, int stable_dimension,


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


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


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


1925 
1926 bool TypeLong::empty(void) const {
1927   return _lo > _hi;
1928 }
1929 
1930 //=============================================================================
1931 // Convenience common pre-built types.
1932 const TypeTuple *TypeTuple::IFBOTH;     // Return both arms of IF as reachable
1933 const TypeTuple *TypeTuple::IFFALSE;
1934 const TypeTuple *TypeTuple::IFTRUE;
1935 const TypeTuple *TypeTuple::IFNEITHER;
1936 const TypeTuple *TypeTuple::LOOPBODY;
1937 const TypeTuple *TypeTuple::MEMBAR;
1938 const TypeTuple *TypeTuple::STORECONDITIONAL;
1939 const TypeTuple *TypeTuple::START_I2C;
1940 const TypeTuple *TypeTuple::INT_PAIR;
1941 const TypeTuple *TypeTuple::LONG_PAIR;
1942 const TypeTuple *TypeTuple::INT_CC_PAIR;
1943 const TypeTuple *TypeTuple::LONG_CC_PAIR;
1944 
1945 static void collect_value_fields(ciValueKlass* vk, const Type** field_array, uint& pos, ExtendedSignature& sig_cc) {
1946   for (int j = 0; j < vk->nof_nonstatic_fields(); j++) {
1947     ciField* field = vk->nonstatic_field_at(j);
1948     BasicType bt = field->type()->basic_type();
1949     const Type* ft = Type::get_const_type(field->type());
1950     field_array[pos++] = ft;
1951     if (type2size[bt] == 2) {
1952       field_array[pos++] = Type::HALF;
1953     }
1954     // Skip reserved arguments
1955     while (SigEntry::next_is_reserved(sig_cc, bt)) {
1956       field_array[pos++] = Type::get_const_basic_type(bt);
1957       if (type2size[bt] == 2) {
1958         field_array[pos++] = Type::HALF;
1959       }
1960     }
1961   }
1962 }
1963 
1964 //------------------------------make-------------------------------------------
1965 // Make a TypeTuple from the range of a method signature
1966 const TypeTuple *TypeTuple::make_range(ciSignature* sig, bool ret_vt_fields) {
1967   ciType* return_type = sig->return_type();
1968   bool never_null = sig->returns_never_null();
1969 
1970   uint arg_cnt = return_type->size();
1971   ret_vt_fields = ret_vt_fields && never_null && return_type->as_value_klass()->can_be_returned_as_fields();
1972   if (ret_vt_fields) {
1973     arg_cnt = return_type->as_value_klass()->value_arg_slots() + 1;
1974   }
1975 
1976   const Type **field_array = fields(arg_cnt);
1977   switch (return_type->basic_type()) {
1978   case T_LONG:
1979     field_array[TypeFunc::Parms]   = TypeLong::LONG;
1980     field_array[TypeFunc::Parms+1] = Type::HALF;
1981     break;
1982   case T_DOUBLE:
1983     field_array[TypeFunc::Parms]   = Type::DOUBLE;
1984     field_array[TypeFunc::Parms+1] = Type::HALF;
1985     break;
1986   case T_OBJECT:
1987   case T_ARRAY:
1988   case T_BOOLEAN:
1989   case T_CHAR:
1990   case T_FLOAT:
1991   case T_BYTE:
1992   case T_SHORT:
1993   case T_INT:
1994     field_array[TypeFunc::Parms] = get_const_type(return_type);
1995     break;
1996   case T_VALUETYPE:
1997     if (ret_vt_fields) {
1998       uint pos = TypeFunc::Parms;
1999       field_array[pos] = TypePtr::BOTTOM;
2000       pos++;
2001       ExtendedSignature sig = ExtendedSignature(NULL, SigEntryFilter());
2002       collect_value_fields(return_type->as_value_klass(), field_array, pos, sig);
2003     } else {
2004       field_array[TypeFunc::Parms] = get_const_type(return_type)->join_speculative(never_null ? TypePtr::NOTNULL : TypePtr::BOTTOM);
2005     }
2006     break;
2007   case T_VOID:
2008     break;
2009   default:
2010     ShouldNotReachHere();
2011   }
2012   return (TypeTuple*)(new TypeTuple(TypeFunc::Parms + arg_cnt, field_array))->hashcons();
2013 }
2014 
2015 // Make a TypeTuple from the domain of a method signature
2016 const TypeTuple *TypeTuple::make_domain(ciMethod* method, bool vt_fields_as_args) {
2017   ciSignature* sig = method->signature();
2018   ExtendedSignature sig_cc = ExtendedSignature(vt_fields_as_args ? method->get_sig_cc() : NULL, SigEntryFilter());
2019 
2020   uint arg_cnt = sig->size() + (method->is_static() ? 0 : 1);
2021   if (vt_fields_as_args) {
2022     for (arg_cnt = 0; !sig_cc.at_end(); ++sig_cc) {
2023       arg_cnt += type2size[(*sig_cc)._bt];
2024     }
2025     sig_cc = ExtendedSignature(method->get_sig_cc(), SigEntryFilter());
2026   }
2027 
2028   uint pos = TypeFunc::Parms;
2029   const Type** field_array = fields(arg_cnt);
2030   if (!method->is_static()) {
2031     ciInstanceKlass* recv = method->holder();
2032     if (vt_fields_as_args && recv->is_valuetype()) {
2033       collect_value_fields(recv->as_value_klass(), field_array, pos, sig_cc);

2034     } else {
2035       field_array[pos++] = get_const_type(recv)->join_speculative(TypePtr::NOTNULL);
2036       if (vt_fields_as_args) {
2037         ++sig_cc;
2038       }
2039     }
2040   }
2041 
2042   int i = 0;
2043   while (pos < TypeFunc::Parms + arg_cnt) {
2044     ciType* type = sig->type_at(i);
2045     BasicType bt = type->basic_type();
2046     bool is_flattened = false;
2047 
2048     switch (bt) {
2049     case T_LONG:
2050       field_array[pos++] = TypeLong::LONG;
2051       field_array[pos++] = Type::HALF;
2052       break;
2053     case T_DOUBLE:
2054       field_array[pos++] = Type::DOUBLE;
2055       field_array[pos++] = Type::HALF;
2056       break;
2057     case T_OBJECT:
2058     case T_ARRAY:
2059     case T_FLOAT:
2060     case T_INT:
2061       field_array[pos++] = get_const_type(type);
2062       break;
2063     case T_BOOLEAN:
2064     case T_CHAR:
2065     case T_BYTE:
2066     case T_SHORT:
2067       field_array[pos++] = TypeInt::INT;
2068       break;
2069     case T_VALUETYPE: {
2070       bool never_null = sig->is_never_null_at(i);
2071       if (vt_fields_as_args && never_null) {
2072         is_flattened = true;
2073         collect_value_fields(type->as_value_klass(), field_array, pos, sig_cc);
2074       } else {
2075         field_array[pos++] = get_const_type(type)->join_speculative(never_null ? TypePtr::NOTNULL : TypePtr::BOTTOM);
2076       }
2077       break;
2078     }
2079     default:
2080       ShouldNotReachHere();
2081     }
2082     // Skip reserved arguments
2083     while (!is_flattened && SigEntry::next_is_reserved(sig_cc, bt)) {
2084       field_array[pos++] = Type::get_const_basic_type(bt);
2085       if (type2size[bt] == 2) {
2086         field_array[pos++] = Type::HALF;
2087       }
2088     }
2089     i++;
2090   }
2091   assert(pos == TypeFunc::Parms + arg_cnt, "wrong number of arguments");
2092 
2093   return (TypeTuple*)(new TypeTuple(TypeFunc::Parms + arg_cnt, field_array))->hashcons();
2094 }
2095 
2096 const TypeTuple *TypeTuple::make( uint cnt, const Type **fields ) {
2097   return (TypeTuple*)(new TypeTuple(cnt,fields))->hashcons();
2098 }
2099 
2100 //------------------------------fields-----------------------------------------
2101 // Subroutine call type with space allocated for argument types
2102 // Memory for Control, I_O, Memory, FramePtr, and ReturnAdr is allocated implicitly
2103 const Type **TypeTuple::fields( uint arg_cnt ) {
2104   const Type **flds = (const Type **)(Compile::current()->type_arena()->Amalloc_4((TypeFunc::Parms+arg_cnt)*sizeof(Type*) ));
2105   flds[TypeFunc::Control  ] = Type::CONTROL;
2106   flds[TypeFunc::I_O      ] = Type::ABIO;
2107   flds[TypeFunc::Memory   ] = Type::MEMORY;
2108   flds[TypeFunc::FramePtr ] = TypeRawPtr::BOTTOM;
2109   flds[TypeFunc::ReturnAdr] = Type::RETURN_ADDRESS;
2110 
2111   return flds;


2207   }
2208   return false;
2209 }
2210 
2211 //=============================================================================
2212 // Convenience common pre-built types.
2213 
2214 inline const TypeInt* normalize_array_size(const TypeInt* size) {
2215   // Certain normalizations keep us sane when comparing types.
2216   // We do not want arrayOop variables to differ only by the wideness
2217   // of their index types.  Pick minimum wideness, since that is the
2218   // forced wideness of small ranges anyway.
2219   if (size->_widen != Type::WidenMin)
2220     return TypeInt::make(size->_lo, size->_hi, Type::WidenMin);
2221   else
2222     return size;
2223 }
2224 
2225 //------------------------------make-------------------------------------------
2226 const TypeAry* TypeAry::make(const Type* elem, const TypeInt* size, bool stable) {
2227   if (elem->is_valuetypeptr()) {
2228     // Value type array elements cannot be NULL
2229     elem = elem->join_speculative(TypePtr::NOTNULL)->is_oopptr();
2230   }
2231   if (UseCompressedOops && elem->isa_oopptr()) {
2232     elem = elem->make_narrowoop();
2233   }
2234   size = normalize_array_size(size);
2235   return (TypeAry*)(new TypeAry(elem,size,stable))->hashcons();
2236 }
2237 
2238 //------------------------------meet-------------------------------------------
2239 // Compute the MEET of two types.  It returns a new Type object.
2240 const Type *TypeAry::xmeet( const Type *t ) const {
2241   // Perform a fast test for common case; meeting the same types together.
2242   if( this == t ) return this;  // Meeting same type-rep?
2243 
2244   // Current "this->_base" is Ary
2245   switch (t->base()) {          // switch on original type
2246 
2247   case Bottom:                  // Ye Olde Default
2248     return t;
2249 
2250   default:                      // All else is a mistake


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


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


2705     const TypePtr *tp = t->is_ptr();
2706     const TypePtr* speculative = xmeet_speculative(tp);
2707     int depth = meet_inline_depth(tp->inline_depth());
2708     return make(AnyPtr, meet_ptr(tp->ptr()), meet_offset(tp->offset()), speculative, depth);
2709   }
2710   case RawPtr:                  // For these, flip the call around to cut down
2711   case OopPtr:
2712   case InstPtr:                 // on the cases I have to handle.
2713   case AryPtr:
2714   case MetadataPtr:
2715   case KlassPtr:
2716     return t->xmeet(this);      // Call in reverse direction
2717   default:                      // All else is a mistake
2718     typerr(t);
2719 
2720   }
2721   return this;
2722 }
2723 
2724 //------------------------------meet_offset------------------------------------
2725 Type::Offset TypePtr::meet_offset(int offset) const {
2726   return _offset.meet(Offset(offset));





2727 }
2728 
2729 //------------------------------dual_offset------------------------------------
2730 Type::Offset TypePtr::dual_offset() const {
2731   return _offset.dual();


2732 }
2733 
2734 //------------------------------xdual------------------------------------------
2735 // Dual: compute field-by-field dual
2736 const TypePtr::PTR TypePtr::ptr_dual[TypePtr::lastPTR] = {
2737   BotPTR, NotNull, Constant, Null, AnyNull, TopPTR
2738 };
2739 const Type *TypePtr::xdual() const {
2740   return new TypePtr(AnyPtr, dual_ptr(), dual_offset(), dual_speculative(), dual_inline_depth());
2741 }
2742 
2743 //------------------------------xadd_offset------------------------------------
2744 Type::Offset TypePtr::xadd_offset(intptr_t offset) const {
2745   return _offset.add(offset);











2746 }
2747 
2748 //------------------------------add_offset-------------------------------------
2749 const TypePtr *TypePtr::add_offset( intptr_t offset ) const {
2750   return make(AnyPtr, _ptr, xadd_offset(offset), _speculative, _inline_depth);
2751 }
2752 
2753 //------------------------------eq---------------------------------------------
2754 // Structural equality check for Type representations
2755 bool TypePtr::eq( const Type *t ) const {
2756   const TypePtr *a = (const TypePtr*)t;
2757   return _ptr == a->ptr() && _offset == a->_offset && eq_speculative(a) && _inline_depth == a->_inline_depth;
2758 }
2759 
2760 //------------------------------hash-------------------------------------------
2761 // Type-specific hashing function.
2762 int TypePtr::hash(void) const {
2763   return java_add(java_add((jint)_ptr, (jint)offset()), java_add((jint)hash_speculative(), (jint)_inline_depth));
2764 ;
2765 }
2766 
2767 /**
2768  * Return same type without a speculative part
2769  */
2770 const Type* TypePtr::remove_speculative() const {
2771   if (_speculative == NULL) {
2772     return this;
2773   }
2774   assert(_inline_depth == InlineDepthTop || _inline_depth == InlineDepthBottom, "non speculative type shouldn't have inline depth");
2775   return make(AnyPtr, _ptr, _offset, NULL, _inline_depth);
2776 }
2777 
2778 /**
2779  * Return same type but drop speculative part if we know we won't use
2780  * it
2781  */
2782 const Type* TypePtr::cleanup_speculative() const {
2783   if (speculative() == NULL) {


3003   }
3004   // We already know the speculative type is always null
3005   if (speculative_always_null()) {
3006     return false;
3007   }
3008   if (ptr_kind == ProfileAlwaysNull && speculative() != NULL && speculative()->isa_oopptr()) {
3009     return false;
3010   }
3011   return true;
3012 }
3013 
3014 //------------------------------dump2------------------------------------------
3015 const char *const TypePtr::ptr_msg[TypePtr::lastPTR] = {
3016   "TopPTR","AnyNull","Constant","NULL","NotNull","BotPTR"
3017 };
3018 
3019 #ifndef PRODUCT
3020 void TypePtr::dump2( Dict &d, uint depth, outputStream *st ) const {
3021   if( _ptr == Null ) st->print("NULL");
3022   else st->print("%s *", ptr_msg[_ptr]);
3023   _offset.dump2(st);


3024   dump_inline_depth(st);
3025   dump_speculative(st);
3026 }
3027 
3028 /**
3029  *dump the speculative part of the type
3030  */
3031 void TypePtr::dump_speculative(outputStream *st) const {
3032   if (_speculative != NULL) {
3033     st->print(" (speculative=");
3034     _speculative->dump_on(st);
3035     st->print(")");
3036   }
3037 }
3038 
3039 /**
3040  *dump the inline depth of the type
3041  */
3042 void TypePtr::dump_inline_depth(outputStream *st) const {
3043   if (_inline_depth != InlineDepthBottom) {
3044     if (_inline_depth == InlineDepthTop) {
3045       st->print(" (inline_depth=InlineDepthTop)");
3046     } else {
3047       st->print(" (inline_depth=%d)", _inline_depth);
3048     }
3049   }
3050 }
3051 #endif
3052 
3053 //------------------------------singleton--------------------------------------
3054 // TRUE if Type is a singleton type, FALSE otherwise.   Singletons are simple
3055 // constants
3056 bool TypePtr::singleton(void) const {
3057   // TopPTR, Null, AnyNull, Constant are all singletons
3058   return (_offset != Offset::bottom) && !below_centerline(_ptr);
3059 }
3060 
3061 bool TypePtr::empty(void) const {
3062   return (_offset == Offset::top) || above_centerline(_ptr);
3063 }
3064 
3065 //=============================================================================
3066 // Convenience common pre-built types.
3067 const TypeRawPtr *TypeRawPtr::BOTTOM;
3068 const TypeRawPtr *TypeRawPtr::NOTNULL;
3069 
3070 //------------------------------make-------------------------------------------
3071 const TypeRawPtr *TypeRawPtr::make( enum PTR ptr ) {
3072   assert( ptr != Constant, "what is the constant?" );
3073   assert( ptr != Null, "Use TypePtr for NULL" );
3074   return (TypeRawPtr*)(new TypeRawPtr(ptr,0))->hashcons();
3075 }
3076 
3077 const TypeRawPtr *TypeRawPtr::make( address bits ) {
3078   assert( bits, "Use TypePtr for NULL" );
3079   return (TypeRawPtr*)(new TypeRawPtr(Constant,bits))->hashcons();
3080 }
3081 
3082 //------------------------------cast_to_ptr_type-------------------------------


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


3238       if (this->isa_klassptr()) {
3239         // Perm objects don't use compressed references
3240       } else if (_offset == Offset::bottom || _offset == Offset::top) {
3241         // unsafe access
3242         _is_ptr_to_narrowoop = UseCompressedOops;
3243       } else { // exclude unsafe ops
3244         assert(this->isa_instptr(), "must be an instance ptr.");

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


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


3621     return (one == two) && TypePtr::eq(t);
3622   } else {
3623     return one->equals(two) && TypePtr::eq(t);
3624   }
3625 }
3626 
3627 //------------------------------hash-------------------------------------------
3628 // Type-specific hashing function.
3629 int TypeOopPtr::hash(void) const {
3630   return
3631     java_add(java_add((jint)(const_oop() ? const_oop()->hash() : 0), (jint)_klass_is_exact),
3632              java_add((jint)_instance_id, (jint)TypePtr::hash()));
3633 }
3634 
3635 //------------------------------dump2------------------------------------------
3636 #ifndef PRODUCT
3637 void TypeOopPtr::dump2( Dict &d, uint depth, outputStream *st ) const {
3638   st->print("oopptr:%s", ptr_msg[_ptr]);
3639   if( _klass_is_exact ) st->print(":exact");
3640   if( const_oop() ) st->print(INTPTR_FORMAT, p2i(const_oop()));
3641   _offset.dump2(st);





3642   if (_instance_id == InstanceTop)
3643     st->print(",iid=top");
3644   else if (_instance_id != InstanceBot)
3645     st->print(",iid=%d",_instance_id);
3646 
3647   dump_inline_depth(st);
3648   dump_speculative(st);
3649 }
3650 #endif
3651 
3652 //------------------------------singleton--------------------------------------
3653 // TRUE if Type is a singleton type, FALSE otherwise.   Singletons are simple
3654 // constants
3655 bool TypeOopPtr::singleton(void) const {
3656   // detune optimizer to not generate constant oop + constant offset as a constant!
3657   // TopPTR, Null, AnyNull, Constant are all singletons
3658   return (offset() == 0) && !below_centerline(_ptr);
3659 }
3660 
3661 //------------------------------add_offset-------------------------------------
3662 const TypePtr *TypeOopPtr::add_offset(intptr_t offset) const {
3663   return make(_ptr, xadd_offset(offset), _instance_id, add_offset_speculative(offset), _inline_depth);
3664 }
3665 
3666 /**
3667  * Return same type without a speculative part
3668  */
3669 const Type* TypeOopPtr::remove_speculative() const {
3670   if (_speculative == NULL) {
3671     return this;
3672   }
3673   assert(_inline_depth == InlineDepthTop || _inline_depth == InlineDepthBottom, "non speculative type shouldn't have inline depth");
3674   return make(_ptr, _offset, _instance_id, NULL, _inline_depth);
3675 }
3676 
3677 /**
3678  * Return same type but drop speculative part if we know we won't use


3730  *
3731  * @return  true if type profile is valuable
3732  */
3733 bool TypeOopPtr::would_improve_type(ciKlass* exact_kls, int inline_depth) const {
3734   // no way to improve an already exact type
3735   if (klass_is_exact()) {
3736     return false;
3737   }
3738   return TypePtr::would_improve_type(exact_kls, inline_depth);
3739 }
3740 
3741 //=============================================================================
3742 // Convenience common pre-built types.
3743 const TypeInstPtr *TypeInstPtr::NOTNULL;
3744 const TypeInstPtr *TypeInstPtr::BOTTOM;
3745 const TypeInstPtr *TypeInstPtr::MIRROR;
3746 const TypeInstPtr *TypeInstPtr::MARK;
3747 const TypeInstPtr *TypeInstPtr::KLASS;
3748 
3749 //------------------------------TypeInstPtr-------------------------------------
3750 TypeInstPtr::TypeInstPtr(PTR ptr, ciKlass* k, bool xk, ciObject* o, Offset off,
3751                          int instance_id, const TypePtr* speculative, int inline_depth)
3752   : TypeOopPtr(InstPtr, ptr, k, xk, o, off, Offset::bottom, instance_id, speculative, inline_depth),
3753     _name(k->name()) {
3754    assert(k != NULL &&
3755           (k->is_loaded() || o == NULL),
3756           "cannot have constants with non-loaded klass");
3757 };
3758 
3759 //------------------------------make-------------------------------------------
3760 const TypeInstPtr *TypeInstPtr::make(PTR ptr,
3761                                      ciKlass* k,
3762                                      bool xk,
3763                                      ciObject* o,
3764                                      Offset offset,
3765                                      int instance_id,
3766                                      const TypePtr* speculative,
3767                                      int inline_depth) {
3768   assert( !k->is_loaded() || k->is_instance_klass(), "Must be for instance");
3769   // Either const_oop() is NULL or else ptr is Constant
3770   assert( (!o && ptr != Constant) || (o && ptr == Constant),
3771           "constant pointers must have a value supplied" );
3772   // Ptr is never Null
3773   assert( ptr != Null, "NULL pointers are not typed" );
3774 
3775   assert(instance_id <= 0 || xk || !UseExactTypes, "instances are always exactly typed");
3776   if (!UseExactTypes)  xk = false;
3777   if (ptr == Constant) {
3778     // Note:  This case includes meta-object constants, such as methods.
3779     xk = true;
3780   } else if (k->is_loaded()) {
3781     ciInstanceKlass* ik = k->as_instance_klass();
3782     if (!xk && ik->is_final())     xk = true;   // no inexact final klass
3783     if (xk && ik->is_interface())  xk = false;  // no exact interface
3784   }


3831   if( (ik->is_final() || _const_oop) )  return this;  // cannot clear xk
3832   if( ik->is_interface() )              return this;  // cannot set xk
3833   return make(ptr(), klass(), klass_is_exact, const_oop(), _offset, _instance_id, _speculative, _inline_depth);
3834 }
3835 
3836 //-----------------------------cast_to_instance_id----------------------------
3837 const TypeOopPtr *TypeInstPtr::cast_to_instance_id(int instance_id) const {
3838   if( instance_id == _instance_id ) return this;
3839   return make(_ptr, klass(), _klass_is_exact, const_oop(), _offset, instance_id, _speculative, _inline_depth);
3840 }
3841 
3842 const TypeOopPtr *TypeInstPtr::cast_to_nonconst() const {
3843   if (const_oop() == NULL) return this;
3844   return make(NotNull, klass(), _klass_is_exact, NULL, _offset, _instance_id, _speculative, _inline_depth);
3845 }
3846 
3847 //------------------------------xmeet_unloaded---------------------------------
3848 // Compute the MEET of two InstPtrs when at least one is unloaded.
3849 // Assume classes are different since called after check for same name/class-loader
3850 const TypeInstPtr *TypeInstPtr::xmeet_unloaded(const TypeInstPtr *tinst) const {
3851     Offset off = meet_offset(tinst->offset());
3852     PTR ptr = meet_ptr(tinst->ptr());
3853     int instance_id = meet_instance_id(tinst->instance_id());
3854     const TypePtr* speculative = xmeet_speculative(tinst);
3855     int depth = meet_inline_depth(tinst->inline_depth());
3856 
3857     const TypeInstPtr *loaded    = is_loaded() ? this  : tinst;
3858     const TypeInstPtr *unloaded  = is_loaded() ? tinst : this;
3859     if( loaded->klass()->equals(ciEnv::current()->Object_klass()) ) {
3860       //
3861       // Meet unloaded class with java/lang/Object
3862       //
3863       // Meet
3864       //          |                     Unloaded Class
3865       //  Object  |   TOP    |   AnyNull | Constant |   NotNull |  BOTTOM   |
3866       //  ===================================================================
3867       //   TOP    | ..........................Unloaded......................|
3868       //  AnyNull |  U-AN    |................Unloaded......................|
3869       // Constant | ... O-NN .................................. |   O-BOT   |
3870       //  NotNull | ... O-NN .................................. |   O-BOT   |
3871       //  BOTTOM  | ........................Object-BOTTOM ..................|


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


4189         else if (above_centerline(tinst ->_ptr))
4190           o = this_oop;
4191         else
4192           ptr = NotNull;
4193       }
4194       return make(ptr, this_klass, this_xk, o, off, instance_id, speculative, depth);
4195     } // Else classes are not equal
4196 
4197     // Since klasses are different, we require a LCA in the Java
4198     // class hierarchy - which means we have to fall to at least NotNull.
4199     if( ptr == TopPTR || ptr == AnyNull || ptr == Constant )
4200       ptr = NotNull;
4201 
4202     instance_id = InstanceBot;
4203 
4204     // Now we find the LCA of Java classes
4205     ciKlass* k = this_klass->least_common_ancestor(tinst_klass);
4206     return make(ptr, k, false, NULL, off, instance_id, speculative, depth);
4207   } // End of case InstPtr
4208 
4209   case ValueType: {
4210     const TypeValueType *tv = t->is_valuetype();
4211 
4212     if (above_centerline(ptr())) {
4213       if (tv->value_klass()->is_subtype_of(_klass)) {
4214         return t;
4215       } else {
4216         return TypeInstPtr::make(NotNull, _klass);
4217       }
4218     } else {
4219       if (tv->value_klass()->is_subtype_of(_klass)) {
4220         return TypeInstPtr::make(ptr(), _klass);
4221       } else {
4222         return TypeInstPtr::make(ptr(), ciEnv::current()->Object_klass());
4223       }
4224     }
4225   }
4226 
4227   } // End of switch
4228   return this;                  // Return the double constant
4229 }
4230 
4231 
4232 //------------------------java_mirror_type--------------------------------------
4233 ciType* TypeInstPtr::java_mirror_type() const {
4234   // must be a singleton type
4235   if( const_oop() == NULL )  return NULL;
4236 
4237   // must be of type java.lang.Class
4238   if( klass() != ciEnv::current()->Class_klass() )  return NULL;
4239 
4240   return const_oop()->as_instance()->java_mirror_type();
4241 }
4242 
4243 
4244 //------------------------------xdual------------------------------------------
4245 // Dual: do NOT dual on klasses.  This means I do NOT understand the Java
4246 // inheritance mechanism.


4275   case Constant:
4276     // TO DO: Make CI print the hex address of the underlying oop.
4277     if (WizardMode || Verbose) {
4278       const_oop()->print_oop(st);
4279     }
4280   case BotPTR:
4281     if (!WizardMode && !Verbose) {
4282       if( _klass_is_exact ) st->print(":exact");
4283       break;
4284     }
4285   case TopPTR:
4286   case AnyNull:
4287   case NotNull:
4288     st->print(":%s", ptr_msg[_ptr]);
4289     if( _klass_is_exact ) st->print(":exact");
4290     break;
4291   default:
4292     break;
4293   }
4294 
4295   _offset.dump2(st);




4296 
4297   st->print(" *");
4298   if (_instance_id == InstanceTop)
4299     st->print(",iid=top");
4300   else if (_instance_id != InstanceBot)
4301     st->print(",iid=%d",_instance_id);
4302 
4303   dump_inline_depth(st);
4304   dump_speculative(st);
4305 }
4306 #endif
4307 
4308 //------------------------------add_offset-------------------------------------
4309 const TypePtr *TypeInstPtr::add_offset(intptr_t offset) const {
4310   return make(_ptr, klass(), klass_is_exact(), const_oop(), xadd_offset(offset),
4311               _instance_id, add_offset_speculative(offset), _inline_depth);
4312 }
4313 
4314 const Type *TypeInstPtr::remove_speculative() const {
4315   if (_speculative == NULL) {


4329 
4330 const TypePtr *TypeInstPtr::with_instance_id(int instance_id) const {
4331   assert(is_known_instance(), "should be known");
4332   return make(_ptr, klass(), klass_is_exact(), const_oop(), _offset, instance_id, _speculative, _inline_depth);
4333 }
4334 
4335 //=============================================================================
4336 // Convenience common pre-built types.
4337 const TypeAryPtr *TypeAryPtr::RANGE;
4338 const TypeAryPtr *TypeAryPtr::OOPS;
4339 const TypeAryPtr *TypeAryPtr::NARROWOOPS;
4340 const TypeAryPtr *TypeAryPtr::BYTES;
4341 const TypeAryPtr *TypeAryPtr::SHORTS;
4342 const TypeAryPtr *TypeAryPtr::CHARS;
4343 const TypeAryPtr *TypeAryPtr::INTS;
4344 const TypeAryPtr *TypeAryPtr::LONGS;
4345 const TypeAryPtr *TypeAryPtr::FLOATS;
4346 const TypeAryPtr *TypeAryPtr::DOUBLES;
4347 
4348 //------------------------------make-------------------------------------------
4349 const TypeAryPtr* TypeAryPtr::make(PTR ptr, const TypeAry *ary, ciKlass* k, bool xk, Offset offset, Offset field_offset,
4350                                    int instance_id, const TypePtr* speculative, int inline_depth) {
4351   assert(!(k == NULL && ary->_elem->isa_int()),
4352          "integral arrays must be pre-equipped with a class");
4353   if (!xk)  xk = ary->ary_must_be_exact();
4354   assert(instance_id <= 0 || xk || !UseExactTypes, "instances are always exactly typed");
4355   if (!UseExactTypes)  xk = (ptr == Constant);
4356   return (TypeAryPtr*)(new TypeAryPtr(ptr, NULL, ary, k, xk, offset, field_offset, instance_id, false, speculative, inline_depth))->hashcons();
4357 }
4358 
4359 //------------------------------make-------------------------------------------
4360 const TypeAryPtr* TypeAryPtr::make(PTR ptr, ciObject* o, const TypeAry *ary, ciKlass* k, bool xk, Offset offset, Offset field_offset,
4361                                    int instance_id, const TypePtr* speculative, int inline_depth,
4362                                    bool is_autobox_cache) {
4363   assert(!(k == NULL && ary->_elem->isa_int()),
4364          "integral arrays must be pre-equipped with a class");
4365   assert( (ptr==Constant && o) || (ptr!=Constant && !o), "" );
4366   if (!xk)  xk = (o != NULL) || ary->ary_must_be_exact();
4367   assert(instance_id <= 0 || xk || !UseExactTypes, "instances are always exactly typed");
4368   if (!UseExactTypes)  xk = (ptr == Constant);
4369   return (TypeAryPtr*)(new TypeAryPtr(ptr, o, ary, k, xk, offset, field_offset, instance_id, is_autobox_cache, speculative, inline_depth))->hashcons();
4370 }
4371 
4372 //------------------------------cast_to_ptr_type-------------------------------
4373 const Type *TypeAryPtr::cast_to_ptr_type(PTR ptr) const {
4374   if( ptr == _ptr ) return this;
4375   return make(ptr, const_oop(), _ary, klass(), klass_is_exact(), _offset, _field_offset, _instance_id, _speculative, _inline_depth, _is_autobox_cache);
4376 }
4377 
4378 
4379 //-----------------------------cast_to_exactness-------------------------------
4380 const Type *TypeAryPtr::cast_to_exactness(bool klass_is_exact) const {
4381   if( klass_is_exact == _klass_is_exact ) return this;
4382   if (!UseExactTypes)  return this;
4383   if (_ary->ary_must_be_exact())  return this;  // cannot clear xk
4384   return make(ptr(), const_oop(), _ary, klass(), klass_is_exact, _offset, _field_offset, _instance_id, _speculative, _inline_depth, _is_autobox_cache);
4385 }
4386 
4387 //-----------------------------cast_to_instance_id----------------------------
4388 const TypeOopPtr *TypeAryPtr::cast_to_instance_id(int instance_id) const {
4389   if( instance_id == _instance_id ) return this;
4390   return make(_ptr, const_oop(), _ary, klass(), _klass_is_exact, _offset, _field_offset, instance_id, _speculative, _inline_depth, _is_autobox_cache);
4391 }
4392 
4393 const TypeOopPtr *TypeAryPtr::cast_to_nonconst() const {
4394   if (const_oop() == NULL) return this;
4395   return make(NotNull, NULL, _ary, klass(), _klass_is_exact, _offset, _field_offset, _instance_id, _speculative, _inline_depth);
4396 }
4397 
4398 
4399 //-----------------------------narrow_size_type-------------------------------
4400 // Local cache for arrayOopDesc::max_array_length(etype),
4401 // which is kind of slow (and cached elsewhere by other users).
4402 static jint max_array_length_cache[T_CONFLICT+1];
4403 static jint max_array_length(BasicType etype) {
4404   jint& cache = max_array_length_cache[etype];
4405   jint res = cache;
4406   if (res == 0) {
4407     switch (etype) {
4408     case T_NARROWOOP:
4409       etype = T_OBJECT;
4410       break;
4411     case T_NARROWKLASS:
4412     case T_CONFLICT:
4413     case T_ILLEGAL:
4414     case T_VOID:
4415       etype = T_BYTE;           // will produce conservatively high value


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


4970   // Current "this->_base" is NarrowKlass or NarrowOop
4971   switch (t->base()) {          // switch on original type
4972 
4973   case Int:                     // Mixing ints & oops happens when javac
4974   case Long:                    // reuses local variables
4975   case FloatTop:
4976   case FloatCon:
4977   case FloatBot:
4978   case DoubleTop:
4979   case DoubleCon:
4980   case DoubleBot:
4981   case AnyPtr:
4982   case RawPtr:
4983   case OopPtr:
4984   case InstPtr:
4985   case AryPtr:
4986   case MetadataPtr:
4987   case KlassPtr:
4988   case NarrowOop:
4989   case NarrowKlass:

4990   case Bottom:                  // Ye Olde Default
4991     return Type::BOTTOM;
4992   case Top:
4993     return this;
4994 
4995   case ValueType:
4996     return t->xmeet(this);
4997 
4998   default:                      // All else is a mistake
4999     typerr(t);
5000 
5001   } // End of switch
5002 
5003   return this;
5004 }
5005 
5006 #ifndef PRODUCT
5007 void TypeNarrowPtr::dump2( Dict & d, uint depth, outputStream *st ) const {
5008   _ptrtype->dump2(d, depth, st);
5009 }
5010 #endif
5011 
5012 const TypeNarrowOop *TypeNarrowOop::BOTTOM;
5013 const TypeNarrowOop *TypeNarrowOop::NULL_PTR;
5014 
5015 
5016 const TypeNarrowOop* TypeNarrowOop::make(const TypePtr* type) {
5017   return (const TypeNarrowOop*)(new TypeNarrowOop(type))->hashcons();


5056     return (one == two) && TypePtr::eq(t);
5057   } else {
5058     return one->equals(two) && TypePtr::eq(t);
5059   }
5060 }
5061 
5062 //------------------------------hash-------------------------------------------
5063 // Type-specific hashing function.
5064 int TypeMetadataPtr::hash(void) const {
5065   return
5066     (metadata() ? metadata()->hash() : 0) +
5067     TypePtr::hash();
5068 }
5069 
5070 //------------------------------singleton--------------------------------------
5071 // TRUE if Type is a singleton type, FALSE otherwise.   Singletons are simple
5072 // constants
5073 bool TypeMetadataPtr::singleton(void) const {
5074   // detune optimizer to not generate constant metadata + constant offset as a constant!
5075   // TopPTR, Null, AnyNull, Constant are all singletons
5076   return (offset() == 0) && !below_centerline(_ptr);
5077 }
5078 
5079 //------------------------------add_offset-------------------------------------
5080 const TypePtr *TypeMetadataPtr::add_offset( intptr_t offset ) const {
5081   return make( _ptr, _metadata, xadd_offset(offset));
5082 }
5083 
5084 //-----------------------------filter------------------------------------------
5085 // Do not allow interface-vs.-noninterface joins to collapse to top.
5086 const Type *TypeMetadataPtr::filter_helper(const Type *kills, bool include_speculative) const {
5087   const TypeMetadataPtr* ft = join_helper(kills, include_speculative)->isa_metadataptr();
5088   if (ft == NULL || ft->empty())
5089     return Type::TOP;           // Canonical empty value
5090   return ft;
5091 }
5092 
5093  //------------------------------get_con----------------------------------------
5094 intptr_t TypeMetadataPtr::get_con() const {
5095   assert( _ptr == Null || _ptr == Constant, "" );
5096   assert(offset() >= 0, "");
5097 
5098   if (offset() != 0) {
5099     // After being ported to the compiler interface, the compiler no longer
5100     // directly manipulates the addresses of oops.  Rather, it only has a pointer
5101     // to a handle at compile time.  This handle is embedded in the generated
5102     // code and dereferenced at the time the nmethod is made.  Until that time,
5103     // it is not reasonable to do arithmetic with the addresses of oops (we don't
5104     // have access to the addresses!).  This does not seem to currently happen,
5105     // but this assertion here is to help prevent its occurence.
5106     tty->print_cr("Found oop constant with non-zero offset");
5107     ShouldNotReachHere();
5108   }
5109 
5110   return (intptr_t)metadata()->constant_encoding();
5111 }
5112 
5113 //------------------------------cast_to_ptr_type-------------------------------
5114 const Type *TypeMetadataPtr::cast_to_ptr_type(PTR ptr) const {
5115   if( ptr == _ptr ) return this;
5116   return make(ptr, metadata(), _offset);
5117 }
5118 


5129   case Long:                    // reuses local variables
5130   case FloatTop:
5131   case FloatCon:
5132   case FloatBot:
5133   case DoubleTop:
5134   case DoubleCon:
5135   case DoubleBot:
5136   case NarrowOop:
5137   case NarrowKlass:
5138   case Bottom:                  // Ye Olde Default
5139     return Type::BOTTOM;
5140   case Top:
5141     return this;
5142 
5143   default:                      // All else is a mistake
5144     typerr(t);
5145 
5146   case AnyPtr: {
5147     // Found an AnyPtr type vs self-OopPtr type
5148     const TypePtr *tp = t->is_ptr();
5149     Offset offset = meet_offset(tp->offset());
5150     PTR ptr = meet_ptr(tp->ptr());
5151     switch (tp->ptr()) {
5152     case Null:
5153       if (ptr == Null)  return TypePtr::make(AnyPtr, ptr, offset, tp->speculative(), tp->inline_depth());
5154       // else fall through:
5155     case TopPTR:
5156     case AnyNull: {
5157       return make(ptr, _metadata, offset);
5158     }
5159     case BotPTR:
5160     case NotNull:
5161       return TypePtr::make(AnyPtr, ptr, offset, tp->speculative(), tp->inline_depth());
5162     default: typerr(t);
5163     }
5164   }
5165 
5166   case RawPtr:
5167   case KlassPtr:
5168   case OopPtr:
5169   case InstPtr:
5170   case AryPtr:
5171     return TypePtr::BOTTOM;     // Oop meet raw is not well defined
5172 
5173   case MetadataPtr: {
5174     const TypeMetadataPtr *tp = t->is_metadataptr();
5175     Offset offset = meet_offset(tp->offset());
5176     PTR tptr = tp->ptr();
5177     PTR ptr = meet_ptr(tptr);
5178     ciMetadata* md = (tptr == TopPTR) ? metadata() : tp->metadata();
5179     if (tptr == TopPTR || _ptr == TopPTR ||
5180         metadata()->equals(tp->metadata())) {
5181       return make(ptr, md, offset);
5182     }
5183     // metadata is different
5184     if( ptr == Constant ) {  // Cannot be equal constants, so...
5185       if( tptr == Constant && _ptr != Constant)  return t;
5186       if( _ptr == Constant && tptr != Constant)  return this;
5187       ptr = NotNull;            // Fall down in lattice
5188     }
5189     return make(ptr, NULL, offset);
5190     break;
5191   }
5192   } // End of switch
5193   return this;                  // Return the double constant
5194 }
5195 
5196 
5197 //------------------------------xdual------------------------------------------
5198 // Dual of a pure metadata pointer.
5199 const Type *TypeMetadataPtr::xdual() const {
5200   return new TypeMetadataPtr(dual_ptr(), metadata(), dual_offset());
5201 }
5202 
5203 //------------------------------dump2------------------------------------------
5204 #ifndef PRODUCT
5205 void TypeMetadataPtr::dump2( Dict &d, uint depth, outputStream *st ) const {
5206   st->print("metadataptr:%s", ptr_msg[_ptr]);
5207   if( metadata() ) st->print(INTPTR_FORMAT, p2i(metadata()));
5208   switch (offset()) {
5209   case OffsetTop: st->print("+top"); break;
5210   case OffsetBot: st->print("+any"); break;
5211   case         0: break;
5212   default:        st->print("+%d",offset()); break;
5213   }
5214 }
5215 #endif
5216 
5217 
5218 //=============================================================================
5219 // Convenience common pre-built type.
5220 const TypeMetadataPtr *TypeMetadataPtr::BOTTOM;
5221 
5222 TypeMetadataPtr::TypeMetadataPtr(PTR ptr, ciMetadata* metadata, Offset offset):
5223   TypePtr(MetadataPtr, ptr, offset), _metadata(metadata) {
5224 }
5225 
5226 const TypeMetadataPtr* TypeMetadataPtr::make(ciMethod* m) {
5227   return make(Constant, m, Offset(0));
5228 }
5229 const TypeMetadataPtr* TypeMetadataPtr::make(ciMethodData* m) {
5230   return make(Constant, m, Offset(0));
5231 }
5232 
5233 //------------------------------make-------------------------------------------
5234 // Create a meta data constant
5235 const TypeMetadataPtr* TypeMetadataPtr::make(PTR ptr, ciMetadata* m, Offset offset) {
5236   assert(m == NULL || !m->is_klass(), "wrong type");
5237   return (TypeMetadataPtr*)(new TypeMetadataPtr(ptr, m, offset))->hashcons();
5238 }
5239 
5240 
5241 //=============================================================================
5242 // Convenience common pre-built types.
5243 
5244 // Not-null object klass or below
5245 const TypeKlassPtr *TypeKlassPtr::OBJECT;
5246 const TypeKlassPtr *TypeKlassPtr::OBJECT_OR_NULL;
5247 
5248 //------------------------------TypeKlassPtr-----------------------------------
5249 TypeKlassPtr::TypeKlassPtr( PTR ptr, ciKlass* klass, Offset offset )
5250   : TypePtr(KlassPtr, ptr, offset), _klass(klass), _klass_is_exact(ptr == Constant) {
5251 }
5252 
5253 //------------------------------make-------------------------------------------
5254 // ptr to klass 'k', if Constant, or possibly to a sub-klass if not a Constant
5255 const TypeKlassPtr* TypeKlassPtr::make(PTR ptr, ciKlass* k, Offset offset) {
5256   assert(k == NULL || k->is_instance_klass() || k->is_array_klass(), "Incorrect type of klass oop");
5257   return (TypeKlassPtr*)(new TypeKlassPtr(ptr, k, offset))->hashcons();




5258 }
5259 
5260 //------------------------------eq---------------------------------------------
5261 // Structural equality check for Type representations
5262 bool TypeKlassPtr::eq( const Type *t ) const {
5263   const TypeKlassPtr *p = t->is_klassptr();
5264   return klass() == p->klass() && TypePtr::eq(p);


5265 }
5266 
5267 //------------------------------hash-------------------------------------------
5268 // Type-specific hashing function.
5269 int TypeKlassPtr::hash(void) const {
5270   return java_add(klass() != NULL ? klass()->hash() : (jint)0, (jint)TypePtr::hash());
5271 }
5272 
5273 //------------------------------singleton--------------------------------------
5274 // TRUE if Type is a singleton type, FALSE otherwise.   Singletons are simple
5275 // constants
5276 bool TypeKlassPtr::singleton(void) const {
5277   // detune optimizer to not generate constant klass + constant offset as a constant!
5278   // TopPTR, Null, AnyNull, Constant are all singletons
5279   return (offset() == 0) && !below_centerline(_ptr);
5280 }
5281 
5282 // Do not allow interface-vs.-noninterface joins to collapse to top.
5283 const Type *TypeKlassPtr::filter_helper(const Type *kills, bool include_speculative) const {
5284   // logic here mirrors the one from TypeOopPtr::filter. See comments
5285   // there.
5286   const Type* ft = join_helper(kills, include_speculative);
5287   const TypeKlassPtr* ftkp = ft->isa_klassptr();
5288   const TypeKlassPtr* ktkp = kills->isa_klassptr();
5289 
5290   if (ft->empty()) {
5291     if (!empty() && ktkp != NULL && ktkp->is_loaded() && ktkp->klass()->is_interface())
5292       return kills;             // Uplift to interface
5293 
5294     return Type::TOP;           // Canonical empty value
5295   }
5296 
5297   // Interface klass type could be exact in opposite to interface type,
5298   // return it here instead of incorrect Constant ptr J/L/Object (6894807).
5299   if (ftkp != NULL && ktkp != NULL &&
5300       ftkp->is_loaded() &&  ftkp->klass()->is_interface() &&
5301       !ftkp->klass_is_exact() && // Keep exact interface klass
5302       ktkp->is_loaded() && !ktkp->klass()->is_interface()) {
5303     return ktkp->cast_to_ptr_type(ftkp->ptr());
5304   }
5305 
5306   return ft;
5307 }
5308 
5309 //----------------------compute_klass------------------------------------------
5310 // Compute the defining klass for this class
5311 ciKlass* TypeAryPtr::compute_klass(DEBUG_ONLY(bool verify)) const {
5312   // Compute _klass based on element type.
5313   ciKlass* k_ary = NULL;

5314   const TypeAryPtr *tary;
5315   const Type* el = elem();
5316   if (el->isa_narrowoop()) {
5317     el = el->make_ptr();
5318   }
5319 
5320   // Get element klass
5321   if (el->isa_instptr()) {
5322     // Compute object array klass from element klass
5323     k_ary = ciArrayKlass::make(el->is_oopptr()->klass());
5324   } else if (el->isa_valuetype()) {
5325     k_ary = ciArrayKlass::make(el->is_valuetype()->value_klass());
5326   } else if ((tary = el->isa_aryptr()) != NULL) {
5327     // Compute array klass from element klass
5328     ciKlass* k_elem = tary->klass();
5329     // If element type is something like bottom[], k_elem will be null.
5330     if (k_elem != NULL)
5331       k_ary = ciObjArrayKlass::make(k_elem);
5332   } else if ((el->base() == Type::Top) ||
5333              (el->base() == Type::Bottom)) {
5334     // element type of Bottom occurs from meet of basic type
5335     // and object; Top occurs when doing join on Bottom.
5336     // Leave k_ary at NULL.
5337   } else {
5338     // Cannot compute array klass directly from basic type,
5339     // since subtypes of TypeInt all have basic type T_INT.
5340 #ifdef ASSERT
5341     if (verify && el->isa_int()) {
5342       // Check simple cases when verifying klass.
5343       BasicType bt = T_ILLEGAL;
5344       if (el == TypeInt::BYTE) {
5345         bt = T_BYTE;


5370 
5371   // Oops, need to compute _klass and cache it
5372   ciKlass* k_ary = compute_klass();
5373 
5374   if( this != TypeAryPtr::OOPS && this->dual() != TypeAryPtr::OOPS ) {
5375     // The _klass field acts as a cache of the underlying
5376     // ciKlass for this array type.  In order to set the field,
5377     // we need to cast away const-ness.
5378     //
5379     // IMPORTANT NOTE: we *never* set the _klass field for the
5380     // type TypeAryPtr::OOPS.  This Type is shared between all
5381     // active compilations.  However, the ciKlass which represents
5382     // this Type is *not* shared between compilations, so caching
5383     // this value would result in fetching a dangling pointer.
5384     //
5385     // Recomputing the underlying ciKlass for each request is
5386     // a bit less efficient than caching, but calls to
5387     // TypeAryPtr::OOPS->klass() are not common enough to matter.
5388     ((TypeAryPtr*)this)->_klass = k_ary;
5389     if (UseCompressedOops && k_ary != NULL && k_ary->is_obj_array_klass() &&
5390         offset() != 0 && offset() != arrayOopDesc::length_offset_in_bytes()) {
5391       ((TypeAryPtr*)this)->_is_ptr_to_narrowoop = true;
5392     }
5393   }
5394   return k_ary;
5395 }
5396 
5397 
5398 //------------------------------add_offset-------------------------------------
5399 // Access internals of klass object
5400 const TypePtr *TypeKlassPtr::add_offset( intptr_t offset ) const {
5401   return make( _ptr, klass(), xadd_offset(offset) );
5402 }
5403 
5404 //------------------------------cast_to_ptr_type-------------------------------
5405 const Type *TypeKlassPtr::cast_to_ptr_type(PTR ptr) const {
5406   assert(_base == KlassPtr, "subclass must override cast_to_ptr_type");
5407   if( ptr == _ptr ) return this;
5408   return make(ptr, _klass, _offset);
5409 }
5410 
5411 
5412 //-----------------------------cast_to_exactness-------------------------------
5413 const Type *TypeKlassPtr::cast_to_exactness(bool klass_is_exact) const {
5414   if( klass_is_exact == _klass_is_exact ) return this;
5415   if (!UseExactTypes)  return this;
5416   return make(klass_is_exact ? Constant : NotNull, _klass, _offset);
5417 }
5418 
5419 
5420 //-----------------------------as_instance_type--------------------------------
5421 // Corresponding type for an instance of the given class.
5422 // It will be NotNull, and exact if and only if the klass type is exact.
5423 const TypeOopPtr* TypeKlassPtr::as_instance_type() const {
5424   ciKlass* k = klass();
5425   assert(k != NULL, "klass should not be NULL");
5426   bool    xk = klass_is_exact();
5427   //return TypeInstPtr::make(TypePtr::NotNull, k, xk, NULL, 0);
5428   const TypeOopPtr* toop = TypeOopPtr::make_from_klass_raw(k);
5429   guarantee(toop != NULL, "need type for given klass");
5430   toop = toop->cast_to_ptr_type(TypePtr::NotNull)->is_oopptr();
5431   return toop->cast_to_exactness(xk)->is_oopptr();
5432 }
5433 
5434 
5435 //------------------------------xmeet------------------------------------------
5436 // Compute the MEET of two types, return a new Type object.
5437 const Type    *TypeKlassPtr::xmeet( const Type *t ) const {
5438   // Perform a fast test for common case; meeting the same types together.
5439   if( this == t ) return this;  // Meeting same type-rep?
5440 
5441   // Current "this->_base" is Pointer
5442   switch (t->base()) {          // switch on original type
5443 
5444   case Int:                     // Mixing ints & oops happens when javac
5445   case Long:                    // reuses local variables
5446   case FloatTop:
5447   case FloatCon:
5448   case FloatBot:
5449   case DoubleTop:
5450   case DoubleCon:
5451   case DoubleBot:
5452   case NarrowOop:
5453   case NarrowKlass:
5454   case Bottom:                  // Ye Olde Default
5455     return Type::BOTTOM;
5456   case Top:
5457     return this;
5458 
5459   default:                      // All else is a mistake
5460     typerr(t);
5461 
5462   case AnyPtr: {                // Meeting to AnyPtrs
5463     // Found an AnyPtr type vs self-KlassPtr type
5464     const TypePtr *tp = t->is_ptr();
5465     Offset offset = meet_offset(tp->offset());
5466     PTR ptr = meet_ptr(tp->ptr());
5467     switch (tp->ptr()) {
5468     case TopPTR:
5469       return this;
5470     case Null:
5471       if( ptr == Null ) return TypePtr::make(AnyPtr, ptr, offset, tp->speculative(), tp->inline_depth());
5472     case AnyNull:
5473       return make( ptr, klass(), offset );
5474     case BotPTR:
5475     case NotNull:
5476       return TypePtr::make(AnyPtr, ptr, offset, tp->speculative(), tp->inline_depth());
5477     default: typerr(t);
5478     }
5479   }
5480 
5481   case RawPtr:
5482   case MetadataPtr:
5483   case OopPtr:
5484   case AryPtr:                  // Meet with AryPtr
5485   case InstPtr:                 // Meet with InstPtr
5486     return TypePtr::BOTTOM;
5487 
5488   //
5489   //             A-top         }
5490   //           /   |   \       }  Tops
5491   //       B-top A-any C-top   }
5492   //          | /  |  \ |      }  Any-nulls
5493   //       B-any   |   C-any   }
5494   //          |    |    |
5495   //       B-con A-con C-con   } constants; not comparable across classes
5496   //          |    |    |
5497   //       B-not   |   C-not   }
5498   //          | \  |  / |      }  not-nulls
5499   //       B-bot A-not C-bot   }
5500   //           \   |   /       }  Bottoms
5501   //             A-bot         }
5502   //
5503 
5504   case KlassPtr: {  // Meet two KlassPtr types
5505     const TypeKlassPtr *tkls = t->is_klassptr();
5506     Offset  off  = meet_offset(tkls->offset());
5507     PTR  ptr     = meet_ptr(tkls->ptr());
5508 
5509     if (klass() == NULL || tkls->klass() == NULL) {
5510       ciKlass* k = NULL;
5511       if (ptr == Constant) {
5512         k = (klass() == NULL) ? tkls->klass() : klass();
5513       }
5514       return make(ptr, k, off);
5515     }
5516 
5517     // Check for easy case; klasses are equal (and perhaps not loaded!)
5518     // If we have constants, then we created oops so classes are loaded
5519     // and we can handle the constants further down.  This case handles
5520     // not-loaded classes
5521     if( ptr != Constant && tkls->klass()->equals(klass()) ) {
5522       return make( ptr, klass(), off );
5523     }
5524 
5525     // Classes require inspection in the Java klass hierarchy.  Must be loaded.
5526     ciKlass* tkls_klass = tkls->klass();
5527     ciKlass* this_klass = this->klass();
5528     assert( tkls_klass->is_loaded(), "This class should have been loaded.");
5529     assert( this_klass->is_loaded(), "This class should have been loaded.");
5530 
5531     // If 'this' type is above the centerline and is a superclass of the
5532     // other, we can treat 'this' as having the same type as the other.
5533     if ((above_centerline(this->ptr())) &&
5534         tkls_klass->is_subtype_of(this_klass)) {
5535       this_klass = tkls_klass;
5536     }


5562     if( ptr == TopPTR || ptr == AnyNull || ptr == Constant )
5563       ptr = NotNull;
5564     // Now we find the LCA of Java classes
5565     ciKlass* k = this_klass->least_common_ancestor(tkls_klass);
5566     return   make( ptr, k, off );
5567   } // End of case KlassPtr
5568 
5569   } // End of switch
5570   return this;                  // Return the double constant
5571 }
5572 
5573 //------------------------------xdual------------------------------------------
5574 // Dual: compute field-by-field dual
5575 const Type    *TypeKlassPtr::xdual() const {
5576   return new TypeKlassPtr( dual_ptr(), klass(), dual_offset() );
5577 }
5578 
5579 //------------------------------get_con----------------------------------------
5580 intptr_t TypeKlassPtr::get_con() const {
5581   assert( _ptr == Null || _ptr == Constant, "" );
5582   assert(offset() >= 0, "");
5583 
5584   if (offset() != 0) {
5585     // After being ported to the compiler interface, the compiler no longer
5586     // directly manipulates the addresses of oops.  Rather, it only has a pointer
5587     // to a handle at compile time.  This handle is embedded in the generated
5588     // code and dereferenced at the time the nmethod is made.  Until that time,
5589     // it is not reasonable to do arithmetic with the addresses of oops (we don't
5590     // have access to the addresses!).  This does not seem to currently happen,
5591     // but this assertion here is to help prevent its occurence.
5592     tty->print_cr("Found oop constant with non-zero offset");
5593     ShouldNotReachHere();
5594   }
5595 
5596   return (intptr_t)klass()->constant_encoding();
5597 }
5598 //------------------------------dump2------------------------------------------
5599 // Dump Klass Type
5600 #ifndef PRODUCT
5601 void TypeKlassPtr::dump2( Dict & d, uint depth, outputStream *st ) const {
5602   switch( _ptr ) {
5603   case Constant:
5604     st->print("precise ");
5605   case NotNull:
5606     {
5607       if (klass() != NULL) {
5608         const char* name = klass()->name()->as_utf8();
5609         st->print("klass %s: " INTPTR_FORMAT, name, p2i(klass()));
5610       } else {
5611         st->print("klass BOTTOM");
5612       }
5613     }
5614   case BotPTR:
5615     if( !WizardMode && !Verbose && !_klass_is_exact ) break;
5616   case TopPTR:
5617   case AnyNull:
5618     st->print(":%s", ptr_msg[_ptr]);
5619     if( _klass_is_exact ) st->print(":exact");
5620     break;
5621   default:
5622     break;
5623   }
5624 
5625   _offset.dump2(st);




5626 
5627   st->print(" *");
5628 }
5629 #endif
5630 
5631 
5632 
5633 //=============================================================================
5634 // Convenience common pre-built types.
5635 
5636 //------------------------------make-------------------------------------------
5637 const TypeFunc *TypeFunc::make(const TypeTuple *domain_sig, const TypeTuple* domain_cc,
5638                                const TypeTuple *range_sig, const TypeTuple *range_cc) {
5639   return (TypeFunc*)(new TypeFunc(domain_sig, domain_cc, range_sig, range_cc))->hashcons();
5640 }
5641 
5642 const TypeFunc *TypeFunc::make(const TypeTuple *domain, const TypeTuple *range) {
5643   return make(domain, domain, range, range);
5644 }
5645 
5646 //------------------------------make-------------------------------------------
5647 const TypeFunc *TypeFunc::make(ciMethod* method) {
5648   Compile* C = Compile::current();
5649   const TypeFunc* tf = C->last_tf(method); // check cache
5650   if (tf != NULL)  return tf;  // The hit rate here is almost 50%.
5651   // Value types are not passed/returned by reference, instead each field of
5652   // the value type is passed/returned as an argument. We maintain two views of
5653   // the argument/return list here: one based on the signature (with a value
5654   // type argument/return as a single slot), one based on the actual calling
5655   // convention (with a value type argument/return as a list of its fields).
5656   const TypeTuple* domain_sig = TypeTuple::make_domain(method, false);
5657   const TypeTuple* domain_cc = TypeTuple::make_domain(method, method->has_scalarized_args());
5658   const TypeTuple* range_sig = TypeTuple::make_range(method->signature(), false);
5659   const TypeTuple* range_cc = TypeTuple::make_range(method->signature(), ValueTypeReturnedAsFields);
5660   tf = TypeFunc::make(domain_sig, domain_cc, range_sig, range_cc);
5661   C->set_last_tf(method, tf);  // fill cache
5662   return tf;
5663 }
5664 
5665 //------------------------------meet-------------------------------------------
5666 // Compute the MEET of two types.  It returns a new Type object.
5667 const Type *TypeFunc::xmeet( const Type *t ) const {
5668   // Perform a fast test for common case; meeting the same types together.
5669   if( this == t ) return this;  // Meeting same type-rep?
5670 
5671   // Current "this->_base" is Func
5672   switch (t->base()) {          // switch on original type
5673 
5674   case Bottom:                  // Ye Olde Default
5675     return t;
5676 
5677   default:                      // All else is a mistake
5678     typerr(t);
5679 
5680   case Top:
5681     break;
5682   }
5683   return this;                  // Return the double constant
5684 }
5685 
5686 //------------------------------xdual------------------------------------------
5687 // Dual: compute field-by-field dual
5688 const Type *TypeFunc::xdual() const {
5689   return this;
5690 }
5691 
5692 //------------------------------eq---------------------------------------------
5693 // Structural equality check for Type representations
5694 bool TypeFunc::eq( const Type *t ) const {
5695   const TypeFunc *a = (const TypeFunc*)t;
5696   return _domain_sig == a->_domain_sig &&
5697     _domain_cc == a->_domain_cc &&
5698     _range_sig == a->_range_sig &&
5699     _range_cc == a->_range_cc;
5700 }
5701 
5702 //------------------------------hash-------------------------------------------
5703 // Type-specific hashing function.
5704 int TypeFunc::hash(void) const {
5705   return (intptr_t)_domain_sig + (intptr_t)_domain_cc + (intptr_t)_range_sig + (intptr_t)_range_cc;
5706 }
5707 
5708 //------------------------------dump2------------------------------------------
5709 // Dump Function Type
5710 #ifndef PRODUCT
5711 void TypeFunc::dump2( Dict &d, uint depth, outputStream *st ) const {
5712   if( _range_sig->cnt() <= Parms )
5713     st->print("void");
5714   else {
5715     uint i;
5716     for (i = Parms; i < _range_sig->cnt()-1; i++) {
5717       _range_sig->field_at(i)->dump2(d,depth,st);
5718       st->print("/");
5719     }
5720     _range_sig->field_at(i)->dump2(d,depth,st);
5721   }
5722   st->print(" ");
5723   st->print("( ");
5724   if( !depth || d[this] ) {     // Check for recursive dump
5725     st->print("...)");
5726     return;
5727   }
5728   d.Insert((void*)this,(void*)this);    // Stop recursion
5729   if (Parms < _domain_sig->cnt())
5730     _domain_sig->field_at(Parms)->dump2(d,depth-1,st);
5731   for (uint i = Parms+1; i < _domain_sig->cnt(); i++) {
5732     st->print(", ");
5733     _domain_sig->field_at(i)->dump2(d,depth-1,st);
5734   }
5735   st->print(" )");
5736 }
5737 #endif
5738 
5739 //------------------------------singleton--------------------------------------
5740 // TRUE if Type is a singleton type, FALSE otherwise.   Singletons are simple
5741 // constants (Ldi nodes).  Singletons are integer, float or double constants
5742 // or a single symbol.
5743 bool TypeFunc::singleton(void) const {
5744   return false;                 // Never a singleton
5745 }
5746 
5747 bool TypeFunc::empty(void) const {
5748   return false;                 // Never empty
5749 }
5750 
5751 
5752 BasicType TypeFunc::return_type() const{
5753   if (range_sig()->cnt() == TypeFunc::Parms) {
5754     return T_VOID;
5755   }
5756   return range_sig()->field_at(TypeFunc::Parms)->basic_type();
5757 }
< prev index next >