src/share/vm/opto/type.cpp

Thu, 12 Oct 2017 21:27:07 +0800

author
aoqi
date
Thu, 12 Oct 2017 21:27:07 +0800
changeset 7535
7ae4e26cb1e0
parent 7074
833b0f92429a
parent 6876
710a3c8b516e
child 7994
04ff2f6cd0eb
permissions
-rw-r--r--

merge

     1 /*
     2  * Copyright (c) 1997, 2014, Oracle and/or its affiliates. All rights reserved.
     3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     4  *
     5  * This code is free software; you can redistribute it and/or modify it
     6  * under the terms of the GNU General Public License version 2 only, as
     7  * published by the Free Software Foundation.
     8  *
     9  * This code is distributed in the hope that it will be useful, but WITHOUT
    10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
    11  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
    12  * version 2 for more details (a copy is included in the LICENSE file that
    13  * accompanied this code).
    14  *
    15  * You should have received a copy of the GNU General Public License version
    16  * 2 along with this work; if not, write to the Free Software Foundation,
    17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
    18  *
    19  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
    20  * or visit www.oracle.com if you need additional information or have any
    21  * questions.
    22  *
    23  */
    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/gcLocker.hpp"
    33 #include "memory/oopFactory.hpp"
    34 #include "memory/resourceArea.hpp"
    35 #include "oops/instanceKlass.hpp"
    36 #include "oops/instanceMirrorKlass.hpp"
    37 #include "oops/objArrayKlass.hpp"
    38 #include "oops/typeArrayKlass.hpp"
    39 #include "opto/matcher.hpp"
    40 #include "opto/node.hpp"
    41 #include "opto/opcodes.hpp"
    42 #include "opto/type.hpp"
    44 PRAGMA_FORMAT_MUTE_WARNINGS_FOR_GCC
    46 // Portions of code courtesy of Clifford Click
    48 // Optimization - Graph Style
    50 // Dictionary of types shared among compilations.
    51 Dict* Type::_shared_type_dict = NULL;
    53 // Array which maps compiler types to Basic Types
    54 Type::TypeInfo Type::_type_info[Type::lastype] = {
    55   { Bad,             T_ILLEGAL,    "bad",           false, Node::NotAMachineReg, relocInfo::none          },  // Bad
    56   { Control,         T_ILLEGAL,    "control",       false, 0,                    relocInfo::none          },  // Control
    57   { Bottom,          T_VOID,       "top",           false, 0,                    relocInfo::none          },  // Top
    58   { Bad,             T_INT,        "int:",          false, Op_RegI,              relocInfo::none          },  // Int
    59   { Bad,             T_LONG,       "long:",         false, Op_RegL,              relocInfo::none          },  // Long
    60   { Half,            T_VOID,       "half",          false, 0,                    relocInfo::none          },  // Half
    61   { Bad,             T_NARROWOOP,  "narrowoop:",    false, Op_RegN,              relocInfo::none          },  // NarrowOop
    62   { Bad,             T_NARROWKLASS,"narrowklass:",  false, Op_RegN,              relocInfo::none          },  // NarrowKlass
    63   { Bad,             T_ILLEGAL,    "tuple:",        false, Node::NotAMachineReg, relocInfo::none          },  // Tuple
    64   { Bad,             T_ARRAY,      "array:",        false, Node::NotAMachineReg, relocInfo::none          },  // Array
    66 #ifdef SPARC
    67   { Bad,             T_ILLEGAL,    "vectors:",      false, 0,                    relocInfo::none          },  // VectorS
    68   { Bad,             T_ILLEGAL,    "vectord:",      false, Op_RegD,              relocInfo::none          },  // VectorD
    69   { Bad,             T_ILLEGAL,    "vectorx:",      false, 0,                    relocInfo::none          },  // VectorX
    70   { Bad,             T_ILLEGAL,    "vectory:",      false, 0,                    relocInfo::none          },  // VectorY
    71 #elif defined(MIPS64)
    72   { Bad,             T_ILLEGAL,    "vectors:",      false, 0,                    relocInfo::none          },  // VectorS
    73   { Bad,             T_ILLEGAL,    "vectord:",      false, Op_VecD,              relocInfo::none          },  // VectorD
    74   { Bad,             T_ILLEGAL,    "vectorx:",      false, 0,                    relocInfo::none          },  // VectorX
    75   { Bad,             T_ILLEGAL,    "vectory:",      false, 0,                    relocInfo::none          },  // VectorY
    76 #elif defined(PPC64)
    77   { Bad,             T_ILLEGAL,    "vectors:",      false, 0,                    relocInfo::none          },  // VectorS
    78   { Bad,             T_ILLEGAL,    "vectord:",      false, Op_RegL,              relocInfo::none          },  // VectorD
    79   { Bad,             T_ILLEGAL,    "vectorx:",      false, 0,                    relocInfo::none          },  // VectorX
    80   { Bad,             T_ILLEGAL,    "vectory:",      false, 0,                    relocInfo::none          },  // VectorY
    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 #endif
    87   { Bad,             T_ADDRESS,    "anyptr:",       false, Op_RegP,              relocInfo::none          },  // AnyPtr
    88   { Bad,             T_ADDRESS,    "rawptr:",       false, Op_RegP,              relocInfo::none          },  // RawPtr
    89   { Bad,             T_OBJECT,     "oop:",          true,  Op_RegP,              relocInfo::oop_type      },  // OopPtr
    90   { Bad,             T_OBJECT,     "inst:",         true,  Op_RegP,              relocInfo::oop_type      },  // InstPtr
    91   { Bad,             T_OBJECT,     "ary:",          true,  Op_RegP,              relocInfo::oop_type      },  // AryPtr
    92   { Bad,             T_METADATA,   "metadata:",     false, Op_RegP,              relocInfo::metadata_type },  // MetadataPtr
    93   { Bad,             T_METADATA,   "klass:",        false, Op_RegP,              relocInfo::metadata_type },  // KlassPtr
    94   { Bad,             T_OBJECT,     "func",          false, 0,                    relocInfo::none          },  // Function
    95   { Abio,            T_ILLEGAL,    "abIO",          false, 0,                    relocInfo::none          },  // Abio
    96   { Return_Address,  T_ADDRESS,    "return_address",false, Op_RegP,              relocInfo::none          },  // Return_Address
    97   { Memory,          T_ILLEGAL,    "memory",        false, 0,                    relocInfo::none          },  // Memory
    98   { FloatBot,        T_FLOAT,      "float_top",     false, Op_RegF,              relocInfo::none          },  // FloatTop
    99   { FloatCon,        T_FLOAT,      "ftcon:",        false, Op_RegF,              relocInfo::none          },  // FloatCon
   100   { FloatTop,        T_FLOAT,      "float",         false, Op_RegF,              relocInfo::none          },  // FloatBot
   101   { DoubleBot,       T_DOUBLE,     "double_top",    false, Op_RegD,              relocInfo::none          },  // DoubleTop
   102   { DoubleCon,       T_DOUBLE,     "dblcon:",       false, Op_RegD,              relocInfo::none          },  // DoubleCon
   103   { DoubleTop,       T_DOUBLE,     "double",        false, Op_RegD,              relocInfo::none          },  // DoubleBot
   104   { Top,             T_ILLEGAL,    "bottom",        false, 0,                    relocInfo::none          }   // Bottom
   105 };
   107 // Map ideal registers (machine types) to ideal types
   108 const Type *Type::mreg2type[_last_machine_leaf];
   110 // Map basic types to canonical Type* pointers.
   111 const Type* Type::     _const_basic_type[T_CONFLICT+1];
   113 // Map basic types to constant-zero Types.
   114 const Type* Type::            _zero_type[T_CONFLICT+1];
   116 // Map basic types to array-body alias types.
   117 const TypeAryPtr* TypeAryPtr::_array_body_type[T_CONFLICT+1];
   119 //=============================================================================
   120 // Convenience common pre-built types.
   121 const Type *Type::ABIO;         // State-of-machine only
   122 const Type *Type::BOTTOM;       // All values
   123 const Type *Type::CONTROL;      // Control only
   124 const Type *Type::DOUBLE;       // All doubles
   125 const Type *Type::FLOAT;        // All floats
   126 const Type *Type::HALF;         // Placeholder half of doublewide type
   127 const Type *Type::MEMORY;       // Abstract store only
   128 const Type *Type::RETURN_ADDRESS;
   129 const Type *Type::TOP;          // No values in set
   131 //------------------------------get_const_type---------------------------
   132 const Type* Type::get_const_type(ciType* type) {
   133   if (type == NULL) {
   134     return NULL;
   135   } else if (type->is_primitive_type()) {
   136     return get_const_basic_type(type->basic_type());
   137   } else {
   138     return TypeOopPtr::make_from_klass(type->as_klass());
   139   }
   140 }
   142 //---------------------------array_element_basic_type---------------------------------
   143 // Mapping to the array element's basic type.
   144 BasicType Type::array_element_basic_type() const {
   145   BasicType bt = basic_type();
   146   if (bt == T_INT) {
   147     if (this == TypeInt::INT)   return T_INT;
   148     if (this == TypeInt::CHAR)  return T_CHAR;
   149     if (this == TypeInt::BYTE)  return T_BYTE;
   150     if (this == TypeInt::BOOL)  return T_BOOLEAN;
   151     if (this == TypeInt::SHORT) return T_SHORT;
   152     return T_VOID;
   153   }
   154   return bt;
   155 }
   157 //---------------------------get_typeflow_type---------------------------------
   158 // Import a type produced by ciTypeFlow.
   159 const Type* Type::get_typeflow_type(ciType* type) {
   160   switch (type->basic_type()) {
   162   case ciTypeFlow::StateVector::T_BOTTOM:
   163     assert(type == ciTypeFlow::StateVector::bottom_type(), "");
   164     return Type::BOTTOM;
   166   case ciTypeFlow::StateVector::T_TOP:
   167     assert(type == ciTypeFlow::StateVector::top_type(), "");
   168     return Type::TOP;
   170   case ciTypeFlow::StateVector::T_NULL:
   171     assert(type == ciTypeFlow::StateVector::null_type(), "");
   172     return TypePtr::NULL_PTR;
   174   case ciTypeFlow::StateVector::T_LONG2:
   175     // The ciTypeFlow pass pushes a long, then the half.
   176     // We do the same.
   177     assert(type == ciTypeFlow::StateVector::long2_type(), "");
   178     return TypeInt::TOP;
   180   case ciTypeFlow::StateVector::T_DOUBLE2:
   181     // The ciTypeFlow pass pushes double, then the half.
   182     // Our convention is the same.
   183     assert(type == ciTypeFlow::StateVector::double2_type(), "");
   184     return Type::TOP;
   186   case T_ADDRESS:
   187     assert(type->is_return_address(), "");
   188     return TypeRawPtr::make((address)(intptr_t)type->as_return_address()->bci());
   190   default:
   191     // make sure we did not mix up the cases:
   192     assert(type != ciTypeFlow::StateVector::bottom_type(), "");
   193     assert(type != ciTypeFlow::StateVector::top_type(), "");
   194     assert(type != ciTypeFlow::StateVector::null_type(), "");
   195     assert(type != ciTypeFlow::StateVector::long2_type(), "");
   196     assert(type != ciTypeFlow::StateVector::double2_type(), "");
   197     assert(!type->is_return_address(), "");
   199     return Type::get_const_type(type);
   200   }
   201 }
   204 //-----------------------make_from_constant------------------------------------
   205 const Type* Type::make_from_constant(ciConstant constant,
   206                                      bool require_constant, bool is_autobox_cache) {
   207   switch (constant.basic_type()) {
   208   case T_BOOLEAN:  return TypeInt::make(constant.as_boolean());
   209   case T_CHAR:     return TypeInt::make(constant.as_char());
   210   case T_BYTE:     return TypeInt::make(constant.as_byte());
   211   case T_SHORT:    return TypeInt::make(constant.as_short());
   212   case T_INT:      return TypeInt::make(constant.as_int());
   213   case T_LONG:     return TypeLong::make(constant.as_long());
   214   case T_FLOAT:    return TypeF::make(constant.as_float());
   215   case T_DOUBLE:   return TypeD::make(constant.as_double());
   216   case T_ARRAY:
   217   case T_OBJECT:
   218     {
   219       // cases:
   220       //   can_be_constant    = (oop not scavengable || ScavengeRootsInCode != 0)
   221       //   should_be_constant = (oop not scavengable || ScavengeRootsInCode >= 2)
   222       // An oop is not scavengable if it is in the perm gen.
   223       ciObject* oop_constant = constant.as_object();
   224       if (oop_constant->is_null_object()) {
   225         return Type::get_zero_type(T_OBJECT);
   226       } else if (require_constant || oop_constant->should_be_constant()) {
   227         return TypeOopPtr::make_from_constant(oop_constant, require_constant, is_autobox_cache);
   228       }
   229     }
   230   }
   231   // Fall through to failure
   232   return NULL;
   233 }
   236 //------------------------------make-------------------------------------------
   237 // Create a simple Type, with default empty symbol sets.  Then hashcons it
   238 // and look for an existing copy in the type dictionary.
   239 const Type *Type::make( enum TYPES t ) {
   240   return (new Type(t))->hashcons();
   241 }
   243 //------------------------------cmp--------------------------------------------
   244 int Type::cmp( const Type *const t1, const Type *const t2 ) {
   245   if( t1->_base != t2->_base )
   246     return 1;                   // Missed badly
   247   assert(t1 != t2 || t1->eq(t2), "eq must be reflexive");
   248   return !t1->eq(t2);           // Return ZERO if equal
   249 }
   251 const Type* Type::maybe_remove_speculative(bool include_speculative) const {
   252   if (!include_speculative) {
   253     return remove_speculative();
   254   }
   255   return this;
   256 }
   258 //------------------------------hash-------------------------------------------
   259 int Type::uhash( const Type *const t ) {
   260   return t->hash();
   261 }
   263 #define SMALLINT ((juint)3)  // a value too insignificant to consider widening
   265 //--------------------------Initialize_shared----------------------------------
   266 void Type::Initialize_shared(Compile* current) {
   267   // This method does not need to be locked because the first system
   268   // compilations (stub compilations) occur serially.  If they are
   269   // changed to proceed in parallel, then this section will need
   270   // locking.
   272   Arena* save = current->type_arena();
   273   Arena* shared_type_arena = new (mtCompiler)Arena(mtCompiler);
   275   current->set_type_arena(shared_type_arena);
   276   _shared_type_dict =
   277     new (shared_type_arena) Dict( (CmpKey)Type::cmp, (Hash)Type::uhash,
   278                                   shared_type_arena, 128 );
   279   current->set_type_dict(_shared_type_dict);
   281   // Make shared pre-built types.
   282   CONTROL = make(Control);      // Control only
   283   TOP     = make(Top);          // No values in set
   284   MEMORY  = make(Memory);       // Abstract store only
   285   ABIO    = make(Abio);         // State-of-machine only
   286   RETURN_ADDRESS=make(Return_Address);
   287   FLOAT   = make(FloatBot);     // All floats
   288   DOUBLE  = make(DoubleBot);    // All doubles
   289   BOTTOM  = make(Bottom);       // Everything
   290   HALF    = make(Half);         // Placeholder half of doublewide type
   292   TypeF::ZERO = TypeF::make(0.0); // Float 0 (positive zero)
   293   TypeF::ONE  = TypeF::make(1.0); // Float 1
   295   TypeD::ZERO = TypeD::make(0.0); // Double 0 (positive zero)
   296   TypeD::ONE  = TypeD::make(1.0); // Double 1
   298   TypeInt::MINUS_1 = TypeInt::make(-1);  // -1
   299   TypeInt::ZERO    = TypeInt::make( 0);  //  0
   300   TypeInt::ONE     = TypeInt::make( 1);  //  1
   301   TypeInt::BOOL    = TypeInt::make(0,1,   WidenMin);  // 0 or 1, FALSE or TRUE.
   302   TypeInt::CC      = TypeInt::make(-1, 1, WidenMin);  // -1, 0 or 1, condition codes
   303   TypeInt::CC_LT   = TypeInt::make(-1,-1, WidenMin);  // == TypeInt::MINUS_1
   304   TypeInt::CC_GT   = TypeInt::make( 1, 1, WidenMin);  // == TypeInt::ONE
   305   TypeInt::CC_EQ   = TypeInt::make( 0, 0, WidenMin);  // == TypeInt::ZERO
   306   TypeInt::CC_LE   = TypeInt::make(-1, 0, WidenMin);
   307   TypeInt::CC_GE   = TypeInt::make( 0, 1, WidenMin);  // == TypeInt::BOOL
   308   TypeInt::BYTE    = TypeInt::make(-128,127,     WidenMin); // Bytes
   309   TypeInt::UBYTE   = TypeInt::make(0, 255,       WidenMin); // Unsigned Bytes
   310   TypeInt::CHAR    = TypeInt::make(0,65535,      WidenMin); // Java chars
   311   TypeInt::SHORT   = TypeInt::make(-32768,32767, WidenMin); // Java shorts
   312   TypeInt::POS     = TypeInt::make(0,max_jint,   WidenMin); // Non-neg values
   313   TypeInt::POS1    = TypeInt::make(1,max_jint,   WidenMin); // Positive values
   314   TypeInt::INT     = TypeInt::make(min_jint,max_jint, WidenMax); // 32-bit integers
   315   TypeInt::SYMINT  = TypeInt::make(-max_jint,max_jint,WidenMin); // symmetric range
   316   TypeInt::TYPE_DOMAIN  = TypeInt::INT;
   317   // CmpL is overloaded both as the bytecode computation returning
   318   // a trinary (-1,0,+1) integer result AND as an efficient long
   319   // compare returning optimizer ideal-type flags.
   320   assert( TypeInt::CC_LT == TypeInt::MINUS_1, "types must match for CmpL to work" );
   321   assert( TypeInt::CC_GT == TypeInt::ONE,     "types must match for CmpL to work" );
   322   assert( TypeInt::CC_EQ == TypeInt::ZERO,    "types must match for CmpL to work" );
   323   assert( TypeInt::CC_GE == TypeInt::BOOL,    "types must match for CmpL to work" );
   324   assert( (juint)(TypeInt::CC->_hi - TypeInt::CC->_lo) <= SMALLINT, "CC is truly small");
   326   TypeLong::MINUS_1 = TypeLong::make(-1);        // -1
   327   TypeLong::ZERO    = TypeLong::make( 0);        //  0
   328   TypeLong::ONE     = TypeLong::make( 1);        //  1
   329   TypeLong::POS     = TypeLong::make(0,max_jlong, WidenMin); // Non-neg values
   330   TypeLong::LONG    = TypeLong::make(min_jlong,max_jlong,WidenMax); // 64-bit integers
   331   TypeLong::INT     = TypeLong::make((jlong)min_jint,(jlong)max_jint,WidenMin);
   332   TypeLong::UINT    = TypeLong::make(0,(jlong)max_juint,WidenMin);
   333   TypeLong::TYPE_DOMAIN  = TypeLong::LONG;
   335   const Type **fboth =(const Type**)shared_type_arena->Amalloc_4(2*sizeof(Type*));
   336   fboth[0] = Type::CONTROL;
   337   fboth[1] = Type::CONTROL;
   338   TypeTuple::IFBOTH = TypeTuple::make( 2, fboth );
   340   const Type **ffalse =(const Type**)shared_type_arena->Amalloc_4(2*sizeof(Type*));
   341   ffalse[0] = Type::CONTROL;
   342   ffalse[1] = Type::TOP;
   343   TypeTuple::IFFALSE = TypeTuple::make( 2, ffalse );
   345   const Type **fneither =(const Type**)shared_type_arena->Amalloc_4(2*sizeof(Type*));
   346   fneither[0] = Type::TOP;
   347   fneither[1] = Type::TOP;
   348   TypeTuple::IFNEITHER = TypeTuple::make( 2, fneither );
   350   const Type **ftrue =(const Type**)shared_type_arena->Amalloc_4(2*sizeof(Type*));
   351   ftrue[0] = Type::TOP;
   352   ftrue[1] = Type::CONTROL;
   353   TypeTuple::IFTRUE = TypeTuple::make( 2, ftrue );
   355   const Type **floop =(const Type**)shared_type_arena->Amalloc_4(2*sizeof(Type*));
   356   floop[0] = Type::CONTROL;
   357   floop[1] = TypeInt::INT;
   358   TypeTuple::LOOPBODY = TypeTuple::make( 2, floop );
   360   TypePtr::NULL_PTR= TypePtr::make( AnyPtr, TypePtr::Null, 0 );
   361   TypePtr::NOTNULL = TypePtr::make( AnyPtr, TypePtr::NotNull, OffsetBot );
   362   TypePtr::BOTTOM  = TypePtr::make( AnyPtr, TypePtr::BotPTR, OffsetBot );
   364   TypeRawPtr::BOTTOM = TypeRawPtr::make( TypePtr::BotPTR );
   365   TypeRawPtr::NOTNULL= TypeRawPtr::make( TypePtr::NotNull );
   367   const Type **fmembar = TypeTuple::fields(0);
   368   TypeTuple::MEMBAR = TypeTuple::make(TypeFunc::Parms+0, fmembar);
   370   const Type **fsc = (const Type**)shared_type_arena->Amalloc_4(2*sizeof(Type*));
   371   fsc[0] = TypeInt::CC;
   372   fsc[1] = Type::MEMORY;
   373   TypeTuple::STORECONDITIONAL = TypeTuple::make(2, fsc);
   375   TypeInstPtr::NOTNULL = TypeInstPtr::make(TypePtr::NotNull, current->env()->Object_klass());
   376   TypeInstPtr::BOTTOM  = TypeInstPtr::make(TypePtr::BotPTR,  current->env()->Object_klass());
   377   TypeInstPtr::MIRROR  = TypeInstPtr::make(TypePtr::NotNull, current->env()->Class_klass());
   378   TypeInstPtr::MARK    = TypeInstPtr::make(TypePtr::BotPTR,  current->env()->Object_klass(),
   379                                            false, 0, oopDesc::mark_offset_in_bytes());
   380   TypeInstPtr::KLASS   = TypeInstPtr::make(TypePtr::BotPTR,  current->env()->Object_klass(),
   381                                            false, 0, oopDesc::klass_offset_in_bytes());
   382   TypeOopPtr::BOTTOM  = TypeOopPtr::make(TypePtr::BotPTR, OffsetBot, TypeOopPtr::InstanceBot, NULL);
   384   TypeMetadataPtr::BOTTOM = TypeMetadataPtr::make(TypePtr::BotPTR, NULL, OffsetBot);
   386   TypeNarrowOop::NULL_PTR = TypeNarrowOop::make( TypePtr::NULL_PTR );
   387   TypeNarrowOop::BOTTOM   = TypeNarrowOop::make( TypeInstPtr::BOTTOM );
   389   TypeNarrowKlass::NULL_PTR = TypeNarrowKlass::make( TypePtr::NULL_PTR );
   391   mreg2type[Op_Node] = Type::BOTTOM;
   392   mreg2type[Op_Set ] = 0;
   393   mreg2type[Op_RegN] = TypeNarrowOop::BOTTOM;
   394   mreg2type[Op_RegI] = TypeInt::INT;
   395   mreg2type[Op_RegP] = TypePtr::BOTTOM;
   396   mreg2type[Op_RegF] = Type::FLOAT;
   397   mreg2type[Op_RegD] = Type::DOUBLE;
   398   mreg2type[Op_RegL] = TypeLong::LONG;
   399   mreg2type[Op_RegFlags] = TypeInt::CC;
   401   TypeAryPtr::RANGE   = TypeAryPtr::make( TypePtr::BotPTR, TypeAry::make(Type::BOTTOM,TypeInt::POS), NULL /* current->env()->Object_klass() */, false, arrayOopDesc::length_offset_in_bytes());
   403   TypeAryPtr::NARROWOOPS = TypeAryPtr::make(TypePtr::BotPTR, TypeAry::make(TypeNarrowOop::BOTTOM, TypeInt::POS), NULL /*ciArrayKlass::make(o)*/,  false,  Type::OffsetBot);
   405 #ifdef _LP64
   406   if (UseCompressedOops) {
   407     assert(TypeAryPtr::NARROWOOPS->is_ptr_to_narrowoop(), "array of narrow oops must be ptr to narrow oop");
   408     TypeAryPtr::OOPS  = TypeAryPtr::NARROWOOPS;
   409   } else
   410 #endif
   411   {
   412     // There is no shared klass for Object[].  See note in TypeAryPtr::klass().
   413     TypeAryPtr::OOPS  = TypeAryPtr::make(TypePtr::BotPTR, TypeAry::make(TypeInstPtr::BOTTOM,TypeInt::POS), NULL /*ciArrayKlass::make(o)*/,  false,  Type::OffsetBot);
   414   }
   415   TypeAryPtr::BYTES   = TypeAryPtr::make(TypePtr::BotPTR, TypeAry::make(TypeInt::BYTE      ,TypeInt::POS), ciTypeArrayKlass::make(T_BYTE),   true,  Type::OffsetBot);
   416   TypeAryPtr::SHORTS  = TypeAryPtr::make(TypePtr::BotPTR, TypeAry::make(TypeInt::SHORT     ,TypeInt::POS), ciTypeArrayKlass::make(T_SHORT),  true,  Type::OffsetBot);
   417   TypeAryPtr::CHARS   = TypeAryPtr::make(TypePtr::BotPTR, TypeAry::make(TypeInt::CHAR      ,TypeInt::POS), ciTypeArrayKlass::make(T_CHAR),   true,  Type::OffsetBot);
   418   TypeAryPtr::INTS    = TypeAryPtr::make(TypePtr::BotPTR, TypeAry::make(TypeInt::INT       ,TypeInt::POS), ciTypeArrayKlass::make(T_INT),    true,  Type::OffsetBot);
   419   TypeAryPtr::LONGS   = TypeAryPtr::make(TypePtr::BotPTR, TypeAry::make(TypeLong::LONG     ,TypeInt::POS), ciTypeArrayKlass::make(T_LONG),   true,  Type::OffsetBot);
   420   TypeAryPtr::FLOATS  = TypeAryPtr::make(TypePtr::BotPTR, TypeAry::make(Type::FLOAT        ,TypeInt::POS), ciTypeArrayKlass::make(T_FLOAT),  true,  Type::OffsetBot);
   421   TypeAryPtr::DOUBLES = TypeAryPtr::make(TypePtr::BotPTR, TypeAry::make(Type::DOUBLE       ,TypeInt::POS), ciTypeArrayKlass::make(T_DOUBLE), true,  Type::OffsetBot);
   423   // Nobody should ask _array_body_type[T_NARROWOOP]. Use NULL as assert.
   424   TypeAryPtr::_array_body_type[T_NARROWOOP] = NULL;
   425   TypeAryPtr::_array_body_type[T_OBJECT]  = TypeAryPtr::OOPS;
   426   TypeAryPtr::_array_body_type[T_ARRAY]   = TypeAryPtr::OOPS; // arrays are stored in oop arrays
   427   TypeAryPtr::_array_body_type[T_BYTE]    = TypeAryPtr::BYTES;
   428   TypeAryPtr::_array_body_type[T_BOOLEAN] = TypeAryPtr::BYTES;  // boolean[] is a byte array
   429   TypeAryPtr::_array_body_type[T_SHORT]   = TypeAryPtr::SHORTS;
   430   TypeAryPtr::_array_body_type[T_CHAR]    = TypeAryPtr::CHARS;
   431   TypeAryPtr::_array_body_type[T_INT]     = TypeAryPtr::INTS;
   432   TypeAryPtr::_array_body_type[T_LONG]    = TypeAryPtr::LONGS;
   433   TypeAryPtr::_array_body_type[T_FLOAT]   = TypeAryPtr::FLOATS;
   434   TypeAryPtr::_array_body_type[T_DOUBLE]  = TypeAryPtr::DOUBLES;
   436   TypeKlassPtr::OBJECT = TypeKlassPtr::make( TypePtr::NotNull, current->env()->Object_klass(), 0 );
   437   TypeKlassPtr::OBJECT_OR_NULL = TypeKlassPtr::make( TypePtr::BotPTR, current->env()->Object_klass(), 0 );
   439   const Type **fi2c = TypeTuple::fields(2);
   440   fi2c[TypeFunc::Parms+0] = TypeInstPtr::BOTTOM; // Method*
   441   fi2c[TypeFunc::Parms+1] = TypeRawPtr::BOTTOM; // argument pointer
   442   TypeTuple::START_I2C = TypeTuple::make(TypeFunc::Parms+2, fi2c);
   444   const Type **intpair = TypeTuple::fields(2);
   445   intpair[0] = TypeInt::INT;
   446   intpair[1] = TypeInt::INT;
   447   TypeTuple::INT_PAIR = TypeTuple::make(2, intpair);
   449   const Type **longpair = TypeTuple::fields(2);
   450   longpair[0] = TypeLong::LONG;
   451   longpair[1] = TypeLong::LONG;
   452   TypeTuple::LONG_PAIR = TypeTuple::make(2, longpair);
   454   const Type **intccpair = TypeTuple::fields(2);
   455   intccpair[0] = TypeInt::INT;
   456   intccpair[1] = TypeInt::CC;
   457   TypeTuple::INT_CC_PAIR = TypeTuple::make(2, intccpair);
   459   const Type **longccpair = TypeTuple::fields(2);
   460   longccpair[0] = TypeLong::LONG;
   461   longccpair[1] = TypeInt::CC;
   462   TypeTuple::LONG_CC_PAIR = TypeTuple::make(2, longccpair);
   464   _const_basic_type[T_NARROWOOP]   = TypeNarrowOop::BOTTOM;
   465   _const_basic_type[T_NARROWKLASS] = Type::BOTTOM;
   466   _const_basic_type[T_BOOLEAN]     = TypeInt::BOOL;
   467   _const_basic_type[T_CHAR]        = TypeInt::CHAR;
   468   _const_basic_type[T_BYTE]        = TypeInt::BYTE;
   469   _const_basic_type[T_SHORT]       = TypeInt::SHORT;
   470   _const_basic_type[T_INT]         = TypeInt::INT;
   471   _const_basic_type[T_LONG]        = TypeLong::LONG;
   472   _const_basic_type[T_FLOAT]       = Type::FLOAT;
   473   _const_basic_type[T_DOUBLE]      = Type::DOUBLE;
   474   _const_basic_type[T_OBJECT]      = TypeInstPtr::BOTTOM;
   475   _const_basic_type[T_ARRAY]       = TypeInstPtr::BOTTOM; // there is no separate bottom for arrays
   476   _const_basic_type[T_VOID]        = TypePtr::NULL_PTR;   // reflection represents void this way
   477   _const_basic_type[T_ADDRESS]     = TypeRawPtr::BOTTOM;  // both interpreter return addresses & random raw ptrs
   478   _const_basic_type[T_CONFLICT]    = Type::BOTTOM;        // why not?
   480   _zero_type[T_NARROWOOP]   = TypeNarrowOop::NULL_PTR;
   481   _zero_type[T_NARROWKLASS] = TypeNarrowKlass::NULL_PTR;
   482   _zero_type[T_BOOLEAN]     = TypeInt::ZERO;     // false == 0
   483   _zero_type[T_CHAR]        = TypeInt::ZERO;     // '\0' == 0
   484   _zero_type[T_BYTE]        = TypeInt::ZERO;     // 0x00 == 0
   485   _zero_type[T_SHORT]       = TypeInt::ZERO;     // 0x0000 == 0
   486   _zero_type[T_INT]         = TypeInt::ZERO;
   487   _zero_type[T_LONG]        = TypeLong::ZERO;
   488   _zero_type[T_FLOAT]       = TypeF::ZERO;
   489   _zero_type[T_DOUBLE]      = TypeD::ZERO;
   490   _zero_type[T_OBJECT]      = TypePtr::NULL_PTR;
   491   _zero_type[T_ARRAY]       = TypePtr::NULL_PTR; // null array is null oop
   492   _zero_type[T_ADDRESS]     = TypePtr::NULL_PTR; // raw pointers use the same null
   493   _zero_type[T_VOID]        = Type::TOP;         // the only void value is no value at all
   495   // get_zero_type() should not happen for T_CONFLICT
   496   _zero_type[T_CONFLICT]= NULL;
   498   // Vector predefined types, it needs initialized _const_basic_type[].
   499   if (Matcher::vector_size_supported(T_BYTE,4)) {
   500     TypeVect::VECTS = TypeVect::make(T_BYTE,4);
   501   }
   502   if (Matcher::vector_size_supported(T_FLOAT,2)) {
   503     TypeVect::VECTD = TypeVect::make(T_FLOAT,2);
   504   }
   505   if (Matcher::vector_size_supported(T_FLOAT,4)) {
   506     TypeVect::VECTX = TypeVect::make(T_FLOAT,4);
   507   }
   508   if (Matcher::vector_size_supported(T_FLOAT,8)) {
   509     TypeVect::VECTY = TypeVect::make(T_FLOAT,8);
   510   }
   511   mreg2type[Op_VecS] = TypeVect::VECTS;
   512   mreg2type[Op_VecD] = TypeVect::VECTD;
   513   mreg2type[Op_VecX] = TypeVect::VECTX;
   514   mreg2type[Op_VecY] = TypeVect::VECTY;
   516   // Restore working type arena.
   517   current->set_type_arena(save);
   518   current->set_type_dict(NULL);
   519 }
   521 //------------------------------Initialize-------------------------------------
   522 void Type::Initialize(Compile* current) {
   523   assert(current->type_arena() != NULL, "must have created type arena");
   525   if (_shared_type_dict == NULL) {
   526     Initialize_shared(current);
   527   }
   529   Arena* type_arena = current->type_arena();
   531   // Create the hash-cons'ing dictionary with top-level storage allocation
   532   Dict *tdic = new (type_arena) Dict( (CmpKey)Type::cmp,(Hash)Type::uhash, type_arena, 128 );
   533   current->set_type_dict(tdic);
   535   // Transfer the shared types.
   536   DictI i(_shared_type_dict);
   537   for( ; i.test(); ++i ) {
   538     Type* t = (Type*)i._value;
   539     tdic->Insert(t,t);  // New Type, insert into Type table
   540   }
   541 }
   543 //------------------------------hashcons---------------------------------------
   544 // Do the hash-cons trick.  If the Type already exists in the type table,
   545 // delete the current Type and return the existing Type.  Otherwise stick the
   546 // current Type in the Type table.
   547 const Type *Type::hashcons(void) {
   548   debug_only(base());           // Check the assertion in Type::base().
   549   // Look up the Type in the Type dictionary
   550   Dict *tdic = type_dict();
   551   Type* old = (Type*)(tdic->Insert(this, this, false));
   552   if( old ) {                   // Pre-existing Type?
   553     if( old != this )           // Yes, this guy is not the pre-existing?
   554       delete this;              // Yes, Nuke this guy
   555     assert( old->_dual, "" );
   556     return old;                 // Return pre-existing
   557   }
   559   // Every type has a dual (to make my lattice symmetric).
   560   // Since we just discovered a new Type, compute its dual right now.
   561   assert( !_dual, "" );         // No dual yet
   562   _dual = xdual();              // Compute the dual
   563   if( cmp(this,_dual)==0 ) {    // Handle self-symmetric
   564     _dual = this;
   565     return this;
   566   }
   567   assert( !_dual->_dual, "" );  // No reverse dual yet
   568   assert( !(*tdic)[_dual], "" ); // Dual not in type system either
   569   // New Type, insert into Type table
   570   tdic->Insert((void*)_dual,(void*)_dual);
   571   ((Type*)_dual)->_dual = this; // Finish up being symmetric
   572 #ifdef ASSERT
   573   Type *dual_dual = (Type*)_dual->xdual();
   574   assert( eq(dual_dual), "xdual(xdual()) should be identity" );
   575   delete dual_dual;
   576 #endif
   577   return this;                  // Return new Type
   578 }
   580 //------------------------------eq---------------------------------------------
   581 // Structural equality check for Type representations
   582 bool Type::eq( const Type * ) const {
   583   return true;                  // Nothing else can go wrong
   584 }
   586 //------------------------------hash-------------------------------------------
   587 // Type-specific hashing function.
   588 int Type::hash(void) const {
   589   return _base;
   590 }
   592 //------------------------------is_finite--------------------------------------
   593 // Has a finite value
   594 bool Type::is_finite() const {
   595   return false;
   596 }
   598 //------------------------------is_nan-----------------------------------------
   599 // Is not a number (NaN)
   600 bool Type::is_nan()    const {
   601   return false;
   602 }
   604 //----------------------interface_vs_oop---------------------------------------
   605 #ifdef ASSERT
   606 bool Type::interface_vs_oop_helper(const Type *t) const {
   607   bool result = false;
   609   const TypePtr* this_ptr = this->make_ptr(); // In case it is narrow_oop
   610   const TypePtr*    t_ptr =    t->make_ptr();
   611   if( this_ptr == NULL || t_ptr == NULL )
   612     return result;
   614   const TypeInstPtr* this_inst = this_ptr->isa_instptr();
   615   const TypeInstPtr*    t_inst =    t_ptr->isa_instptr();
   616   if( this_inst && this_inst->is_loaded() && t_inst && t_inst->is_loaded() ) {
   617     bool this_interface = this_inst->klass()->is_interface();
   618     bool    t_interface =    t_inst->klass()->is_interface();
   619     result = this_interface ^ t_interface;
   620   }
   622   return result;
   623 }
   625 bool Type::interface_vs_oop(const Type *t) const {
   626   if (interface_vs_oop_helper(t)) {
   627     return true;
   628   }
   629   // Now check the speculative parts as well
   630   const TypeOopPtr* this_spec = isa_oopptr() != NULL ? isa_oopptr()->speculative() : NULL;
   631   const TypeOopPtr* t_spec = t->isa_oopptr() != NULL ? t->isa_oopptr()->speculative() : NULL;
   632   if (this_spec != NULL && t_spec != NULL) {
   633     if (this_spec->interface_vs_oop_helper(t_spec)) {
   634       return true;
   635     }
   636     return false;
   637   }
   638   if (this_spec != NULL && this_spec->interface_vs_oop_helper(t)) {
   639     return true;
   640   }
   641   if (t_spec != NULL && interface_vs_oop_helper(t_spec)) {
   642     return true;
   643   }
   644   return false;
   645 }
   647 #endif
   649 //------------------------------meet-------------------------------------------
   650 // Compute the MEET of two types.  NOT virtual.  It enforces that meet is
   651 // commutative and the lattice is symmetric.
   652 const Type *Type::meet_helper(const Type *t, bool include_speculative) const {
   653   if (isa_narrowoop() && t->isa_narrowoop()) {
   654     const Type* result = make_ptr()->meet_helper(t->make_ptr(), include_speculative);
   655     return result->make_narrowoop();
   656   }
   657   if (isa_narrowklass() && t->isa_narrowklass()) {
   658     const Type* result = make_ptr()->meet_helper(t->make_ptr(), include_speculative);
   659     return result->make_narrowklass();
   660   }
   662   const Type *this_t = maybe_remove_speculative(include_speculative);
   663   t = t->maybe_remove_speculative(include_speculative);
   665   const Type *mt = this_t->xmeet(t);
   666   if (isa_narrowoop() || t->isa_narrowoop()) return mt;
   667   if (isa_narrowklass() || t->isa_narrowklass()) return mt;
   668 #ifdef ASSERT
   669   assert(mt == t->xmeet(this_t), "meet not commutative");
   670   const Type* dual_join = mt->_dual;
   671   const Type *t2t    = dual_join->xmeet(t->_dual);
   672   const Type *t2this = dual_join->xmeet(this_t->_dual);
   674   // Interface meet Oop is Not Symmetric:
   675   // Interface:AnyNull meet Oop:AnyNull == Interface:AnyNull
   676   // Interface:NotNull meet Oop:NotNull == java/lang/Object:NotNull
   678   if( !interface_vs_oop(t) && (t2t != t->_dual || t2this != this_t->_dual) ) {
   679     tty->print_cr("=== Meet Not Symmetric ===");
   680     tty->print("t   =                   ");              t->dump(); tty->cr();
   681     tty->print("this=                   ");         this_t->dump(); tty->cr();
   682     tty->print("mt=(t meet this)=       ");             mt->dump(); tty->cr();
   684     tty->print("t_dual=                 ");       t->_dual->dump(); tty->cr();
   685     tty->print("this_dual=              ");  this_t->_dual->dump(); tty->cr();
   686     tty->print("mt_dual=                ");      mt->_dual->dump(); tty->cr();
   688     tty->print("mt_dual meet t_dual=    "); t2t           ->dump(); tty->cr();
   689     tty->print("mt_dual meet this_dual= "); t2this        ->dump(); tty->cr();
   691     fatal("meet not symmetric" );
   692   }
   693 #endif
   694   return mt;
   695 }
   697 //------------------------------xmeet------------------------------------------
   698 // Compute the MEET of two types.  It returns a new Type object.
   699 const Type *Type::xmeet( const Type *t ) const {
   700   // Perform a fast test for common case; meeting the same types together.
   701   if( this == t ) return this;  // Meeting same type-rep?
   703   // Meeting TOP with anything?
   704   if( _base == Top ) return t;
   706   // Meeting BOTTOM with anything?
   707   if( _base == Bottom ) return BOTTOM;
   709   // Current "this->_base" is one of: Bad, Multi, Control, Top,
   710   // Abio, Abstore, Floatxxx, Doublexxx, Bottom, lastype.
   711   switch (t->base()) {  // Switch on original type
   713   // Cut in half the number of cases I must handle.  Only need cases for when
   714   // the given enum "t->type" is less than or equal to the local enum "type".
   715   case FloatCon:
   716   case DoubleCon:
   717   case Int:
   718   case Long:
   719     return t->xmeet(this);
   721   case OopPtr:
   722     return t->xmeet(this);
   724   case InstPtr:
   725     return t->xmeet(this);
   727   case MetadataPtr:
   728   case KlassPtr:
   729     return t->xmeet(this);
   731   case AryPtr:
   732     return t->xmeet(this);
   734   case NarrowOop:
   735     return t->xmeet(this);
   737   case NarrowKlass:
   738     return t->xmeet(this);
   740   case Bad:                     // Type check
   741   default:                      // Bogus type not in lattice
   742     typerr(t);
   743     return Type::BOTTOM;
   745   case Bottom:                  // Ye Olde Default
   746     return t;
   748   case FloatTop:
   749     if( _base == FloatTop ) return this;
   750   case FloatBot:                // Float
   751     if( _base == FloatBot || _base == FloatTop ) return FLOAT;
   752     if( _base == DoubleTop || _base == DoubleBot ) return Type::BOTTOM;
   753     typerr(t);
   754     return Type::BOTTOM;
   756   case DoubleTop:
   757     if( _base == DoubleTop ) return this;
   758   case DoubleBot:               // Double
   759     if( _base == DoubleBot || _base == DoubleTop ) return DOUBLE;
   760     if( _base == FloatTop || _base == FloatBot ) return Type::BOTTOM;
   761     typerr(t);
   762     return Type::BOTTOM;
   764   // These next few cases must match exactly or it is a compile-time error.
   765   case Control:                 // Control of code
   766   case Abio:                    // State of world outside of program
   767   case Memory:
   768     if( _base == t->_base )  return this;
   769     typerr(t);
   770     return Type::BOTTOM;
   772   case Top:                     // Top of the lattice
   773     return this;
   774   }
   776   // The type is unchanged
   777   return this;
   778 }
   780 //-----------------------------filter------------------------------------------
   781 const Type *Type::filter_helper(const Type *kills, bool include_speculative) const {
   782   const Type* ft = join_helper(kills, include_speculative);
   783   if (ft->empty())
   784     return Type::TOP;           // Canonical empty value
   785   return ft;
   786 }
   788 //------------------------------xdual------------------------------------------
   789 // Compute dual right now.
   790 const Type::TYPES Type::dual_type[Type::lastype] = {
   791   Bad,          // Bad
   792   Control,      // Control
   793   Bottom,       // Top
   794   Bad,          // Int - handled in v-call
   795   Bad,          // Long - handled in v-call
   796   Half,         // Half
   797   Bad,          // NarrowOop - handled in v-call
   798   Bad,          // NarrowKlass - handled in v-call
   800   Bad,          // Tuple - handled in v-call
   801   Bad,          // Array - handled in v-call
   802   Bad,          // VectorS - handled in v-call
   803   Bad,          // VectorD - handled in v-call
   804   Bad,          // VectorX - handled in v-call
   805   Bad,          // VectorY - handled in v-call
   807   Bad,          // AnyPtr - handled in v-call
   808   Bad,          // RawPtr - handled in v-call
   809   Bad,          // OopPtr - handled in v-call
   810   Bad,          // InstPtr - handled in v-call
   811   Bad,          // AryPtr - handled in v-call
   813   Bad,          //  MetadataPtr - handled in v-call
   814   Bad,          // KlassPtr - handled in v-call
   816   Bad,          // Function - handled in v-call
   817   Abio,         // Abio
   818   Return_Address,// Return_Address
   819   Memory,       // Memory
   820   FloatBot,     // FloatTop
   821   FloatCon,     // FloatCon
   822   FloatTop,     // FloatBot
   823   DoubleBot,    // DoubleTop
   824   DoubleCon,    // DoubleCon
   825   DoubleTop,    // DoubleBot
   826   Top           // Bottom
   827 };
   829 const Type *Type::xdual() const {
   830   // Note: the base() accessor asserts the sanity of _base.
   831   assert(_type_info[base()].dual_type != Bad, "implement with v-call");
   832   return new Type(_type_info[_base].dual_type);
   833 }
   835 //------------------------------has_memory-------------------------------------
   836 bool Type::has_memory() const {
   837   Type::TYPES tx = base();
   838   if (tx == Memory) return true;
   839   if (tx == Tuple) {
   840     const TypeTuple *t = is_tuple();
   841     for (uint i=0; i < t->cnt(); i++) {
   842       tx = t->field_at(i)->base();
   843       if (tx == Memory)  return true;
   844     }
   845   }
   846   return false;
   847 }
   849 #ifndef PRODUCT
   850 //------------------------------dump2------------------------------------------
   851 void Type::dump2( Dict &d, uint depth, outputStream *st ) const {
   852   st->print("%s", _type_info[_base].msg);
   853 }
   855 //------------------------------dump-------------------------------------------
   856 void Type::dump_on(outputStream *st) const {
   857   ResourceMark rm;
   858   Dict d(cmpkey,hashkey);       // Stop recursive type dumping
   859   dump2(d,1, st);
   860   if (is_ptr_to_narrowoop()) {
   861     st->print(" [narrow]");
   862   } else if (is_ptr_to_narrowklass()) {
   863     st->print(" [narrowklass]");
   864   }
   865 }
   866 #endif
   868 //------------------------------singleton--------------------------------------
   869 // TRUE if Type is a singleton type, FALSE otherwise.   Singletons are simple
   870 // constants (Ldi nodes).  Singletons are integer, float or double constants.
   871 bool Type::singleton(void) const {
   872   return _base == Top || _base == Half;
   873 }
   875 //------------------------------empty------------------------------------------
   876 // TRUE if Type is a type with no values, FALSE otherwise.
   877 bool Type::empty(void) const {
   878   switch (_base) {
   879   case DoubleTop:
   880   case FloatTop:
   881   case Top:
   882     return true;
   884   case Half:
   885   case Abio:
   886   case Return_Address:
   887   case Memory:
   888   case Bottom:
   889   case FloatBot:
   890   case DoubleBot:
   891     return false;  // never a singleton, therefore never empty
   892   }
   894   ShouldNotReachHere();
   895   return false;
   896 }
   898 //------------------------------dump_stats-------------------------------------
   899 // Dump collected statistics to stderr
   900 #ifndef PRODUCT
   901 void Type::dump_stats() {
   902   tty->print("Types made: %d\n", type_dict()->Size());
   903 }
   904 #endif
   906 //------------------------------typerr-----------------------------------------
   907 void Type::typerr( const Type *t ) const {
   908 #ifndef PRODUCT
   909   tty->print("\nError mixing types: ");
   910   dump();
   911   tty->print(" and ");
   912   t->dump();
   913   tty->print("\n");
   914 #endif
   915   ShouldNotReachHere();
   916 }
   919 //=============================================================================
   920 // Convenience common pre-built types.
   921 const TypeF *TypeF::ZERO;       // Floating point zero
   922 const TypeF *TypeF::ONE;        // Floating point one
   924 //------------------------------make-------------------------------------------
   925 // Create a float constant
   926 const TypeF *TypeF::make(float f) {
   927   return (TypeF*)(new TypeF(f))->hashcons();
   928 }
   930 //------------------------------meet-------------------------------------------
   931 // Compute the MEET of two types.  It returns a new Type object.
   932 const Type *TypeF::xmeet( const Type *t ) const {
   933   // Perform a fast test for common case; meeting the same types together.
   934   if( this == t ) return this;  // Meeting same type-rep?
   936   // Current "this->_base" is FloatCon
   937   switch (t->base()) {          // Switch on original type
   938   case AnyPtr:                  // Mixing with oops happens when javac
   939   case RawPtr:                  // reuses local variables
   940   case OopPtr:
   941   case InstPtr:
   942   case AryPtr:
   943   case MetadataPtr:
   944   case KlassPtr:
   945   case NarrowOop:
   946   case NarrowKlass:
   947   case Int:
   948   case Long:
   949   case DoubleTop:
   950   case DoubleCon:
   951   case DoubleBot:
   952   case Bottom:                  // Ye Olde Default
   953     return Type::BOTTOM;
   955   case FloatBot:
   956     return t;
   958   default:                      // All else is a mistake
   959     typerr(t);
   961   case FloatCon:                // Float-constant vs Float-constant?
   962     if( jint_cast(_f) != jint_cast(t->getf()) )         // unequal constants?
   963                                 // must compare bitwise as positive zero, negative zero and NaN have
   964                                 // all the same representation in C++
   965       return FLOAT;             // Return generic float
   966                                 // Equal constants
   967   case Top:
   968   case FloatTop:
   969     break;                      // Return the float constant
   970   }
   971   return this;                  // Return the float constant
   972 }
   974 //------------------------------xdual------------------------------------------
   975 // Dual: symmetric
   976 const Type *TypeF::xdual() const {
   977   return this;
   978 }
   980 //------------------------------eq---------------------------------------------
   981 // Structural equality check for Type representations
   982 bool TypeF::eq( const Type *t ) const {
   983   if( g_isnan(_f) ||
   984       g_isnan(t->getf()) ) {
   985     // One or both are NANs.  If both are NANs return true, else false.
   986     return (g_isnan(_f) && g_isnan(t->getf()));
   987   }
   988   if (_f == t->getf()) {
   989     // (NaN is impossible at this point, since it is not equal even to itself)
   990     if (_f == 0.0) {
   991       // difference between positive and negative zero
   992       if (jint_cast(_f) != jint_cast(t->getf()))  return false;
   993     }
   994     return true;
   995   }
   996   return false;
   997 }
   999 //------------------------------hash-------------------------------------------
  1000 // Type-specific hashing function.
  1001 int TypeF::hash(void) const {
  1002   return *(int*)(&_f);
  1005 //------------------------------is_finite--------------------------------------
  1006 // Has a finite value
  1007 bool TypeF::is_finite() const {
  1008   return g_isfinite(getf()) != 0;
  1011 //------------------------------is_nan-----------------------------------------
  1012 // Is not a number (NaN)
  1013 bool TypeF::is_nan()    const {
  1014   return g_isnan(getf()) != 0;
  1017 //------------------------------dump2------------------------------------------
  1018 // Dump float constant Type
  1019 #ifndef PRODUCT
  1020 void TypeF::dump2( Dict &d, uint depth, outputStream *st ) const {
  1021   Type::dump2(d,depth, st);
  1022   st->print("%f", _f);
  1024 #endif
  1026 //------------------------------singleton--------------------------------------
  1027 // TRUE if Type is a singleton type, FALSE otherwise.   Singletons are simple
  1028 // constants (Ldi nodes).  Singletons are integer, float or double constants
  1029 // or a single symbol.
  1030 bool TypeF::singleton(void) const {
  1031   return true;                  // Always a singleton
  1034 bool TypeF::empty(void) const {
  1035   return false;                 // always exactly a singleton
  1038 //=============================================================================
  1039 // Convenience common pre-built types.
  1040 const TypeD *TypeD::ZERO;       // Floating point zero
  1041 const TypeD *TypeD::ONE;        // Floating point one
  1043 //------------------------------make-------------------------------------------
  1044 const TypeD *TypeD::make(double d) {
  1045   return (TypeD*)(new TypeD(d))->hashcons();
  1048 //------------------------------meet-------------------------------------------
  1049 // Compute the MEET of two types.  It returns a new Type object.
  1050 const Type *TypeD::xmeet( const Type *t ) const {
  1051   // Perform a fast test for common case; meeting the same types together.
  1052   if( this == t ) return this;  // Meeting same type-rep?
  1054   // Current "this->_base" is DoubleCon
  1055   switch (t->base()) {          // Switch on original type
  1056   case AnyPtr:                  // Mixing with oops happens when javac
  1057   case RawPtr:                  // reuses local variables
  1058   case OopPtr:
  1059   case InstPtr:
  1060   case AryPtr:
  1061   case MetadataPtr:
  1062   case KlassPtr:
  1063   case NarrowOop:
  1064   case NarrowKlass:
  1065   case Int:
  1066   case Long:
  1067   case FloatTop:
  1068   case FloatCon:
  1069   case FloatBot:
  1070   case Bottom:                  // Ye Olde Default
  1071     return Type::BOTTOM;
  1073   case DoubleBot:
  1074     return t;
  1076   default:                      // All else is a mistake
  1077     typerr(t);
  1079   case DoubleCon:               // Double-constant vs Double-constant?
  1080     if( jlong_cast(_d) != jlong_cast(t->getd()) )       // unequal constants? (see comment in TypeF::xmeet)
  1081       return DOUBLE;            // Return generic double
  1082   case Top:
  1083   case DoubleTop:
  1084     break;
  1086   return this;                  // Return the double constant
  1089 //------------------------------xdual------------------------------------------
  1090 // Dual: symmetric
  1091 const Type *TypeD::xdual() const {
  1092   return this;
  1095 //------------------------------eq---------------------------------------------
  1096 // Structural equality check for Type representations
  1097 bool TypeD::eq( const Type *t ) const {
  1098   if( g_isnan(_d) ||
  1099       g_isnan(t->getd()) ) {
  1100     // One or both are NANs.  If both are NANs return true, else false.
  1101     return (g_isnan(_d) && g_isnan(t->getd()));
  1103   if (_d == t->getd()) {
  1104     // (NaN is impossible at this point, since it is not equal even to itself)
  1105     if (_d == 0.0) {
  1106       // difference between positive and negative zero
  1107       if (jlong_cast(_d) != jlong_cast(t->getd()))  return false;
  1109     return true;
  1111   return false;
  1114 //------------------------------hash-------------------------------------------
  1115 // Type-specific hashing function.
  1116 int TypeD::hash(void) const {
  1117   return *(int*)(&_d);
  1120 //------------------------------is_finite--------------------------------------
  1121 // Has a finite value
  1122 bool TypeD::is_finite() const {
  1123   return g_isfinite(getd()) != 0;
  1126 //------------------------------is_nan-----------------------------------------
  1127 // Is not a number (NaN)
  1128 bool TypeD::is_nan()    const {
  1129   return g_isnan(getd()) != 0;
  1132 //------------------------------dump2------------------------------------------
  1133 // Dump double constant Type
  1134 #ifndef PRODUCT
  1135 void TypeD::dump2( Dict &d, uint depth, outputStream *st ) const {
  1136   Type::dump2(d,depth,st);
  1137   st->print("%f", _d);
  1139 #endif
  1141 //------------------------------singleton--------------------------------------
  1142 // TRUE if Type is a singleton type, FALSE otherwise.   Singletons are simple
  1143 // constants (Ldi nodes).  Singletons are integer, float or double constants
  1144 // or a single symbol.
  1145 bool TypeD::singleton(void) const {
  1146   return true;                  // Always a singleton
  1149 bool TypeD::empty(void) const {
  1150   return false;                 // always exactly a singleton
  1153 //=============================================================================
  1154 // Convience common pre-built types.
  1155 const TypeInt *TypeInt::MINUS_1;// -1
  1156 const TypeInt *TypeInt::ZERO;   // 0
  1157 const TypeInt *TypeInt::ONE;    // 1
  1158 const TypeInt *TypeInt::BOOL;   // 0 or 1, FALSE or TRUE.
  1159 const TypeInt *TypeInt::CC;     // -1,0 or 1, condition codes
  1160 const TypeInt *TypeInt::CC_LT;  // [-1]  == MINUS_1
  1161 const TypeInt *TypeInt::CC_GT;  // [1]   == ONE
  1162 const TypeInt *TypeInt::CC_EQ;  // [0]   == ZERO
  1163 const TypeInt *TypeInt::CC_LE;  // [-1,0]
  1164 const TypeInt *TypeInt::CC_GE;  // [0,1] == BOOL (!)
  1165 const TypeInt *TypeInt::BYTE;   // Bytes, -128 to 127
  1166 const TypeInt *TypeInt::UBYTE;  // Unsigned Bytes, 0 to 255
  1167 const TypeInt *TypeInt::CHAR;   // Java chars, 0-65535
  1168 const TypeInt *TypeInt::SHORT;  // Java shorts, -32768-32767
  1169 const TypeInt *TypeInt::POS;    // Positive 32-bit integers or zero
  1170 const TypeInt *TypeInt::POS1;   // Positive 32-bit integers
  1171 const TypeInt *TypeInt::INT;    // 32-bit integers
  1172 const TypeInt *TypeInt::SYMINT; // symmetric range [-max_jint..max_jint]
  1173 const TypeInt *TypeInt::TYPE_DOMAIN; // alias for TypeInt::INT
  1175 //------------------------------TypeInt----------------------------------------
  1176 TypeInt::TypeInt( jint lo, jint hi, int w ) : Type(Int), _lo(lo), _hi(hi), _widen(w) {
  1179 //------------------------------make-------------------------------------------
  1180 const TypeInt *TypeInt::make( jint lo ) {
  1181   return (TypeInt*)(new TypeInt(lo,lo,WidenMin))->hashcons();
  1184 static int normalize_int_widen( jint lo, jint hi, int w ) {
  1185   // Certain normalizations keep us sane when comparing types.
  1186   // The 'SMALLINT' covers constants and also CC and its relatives.
  1187   if (lo <= hi) {
  1188     if ((juint)(hi - lo) <= SMALLINT)  w = Type::WidenMin;
  1189     if ((juint)(hi - lo) >= max_juint) w = Type::WidenMax; // TypeInt::INT
  1190   } else {
  1191     if ((juint)(lo - hi) <= SMALLINT)  w = Type::WidenMin;
  1192     if ((juint)(lo - hi) >= max_juint) w = Type::WidenMin; // dual TypeInt::INT
  1194   return w;
  1197 const TypeInt *TypeInt::make( jint lo, jint hi, int w ) {
  1198   w = normalize_int_widen(lo, hi, w);
  1199   return (TypeInt*)(new TypeInt(lo,hi,w))->hashcons();
  1202 //------------------------------meet-------------------------------------------
  1203 // Compute the MEET of two types.  It returns a new Type representation object
  1204 // with reference count equal to the number of Types pointing at it.
  1205 // Caller should wrap a Types around it.
  1206 const Type *TypeInt::xmeet( const Type *t ) const {
  1207   // Perform a fast test for common case; meeting the same types together.
  1208   if( this == t ) return this;  // Meeting same type?
  1210   // Currently "this->_base" is a TypeInt
  1211   switch (t->base()) {          // Switch on original type
  1212   case AnyPtr:                  // Mixing with oops happens when javac
  1213   case RawPtr:                  // reuses local variables
  1214   case OopPtr:
  1215   case InstPtr:
  1216   case AryPtr:
  1217   case MetadataPtr:
  1218   case KlassPtr:
  1219   case NarrowOop:
  1220   case NarrowKlass:
  1221   case Long:
  1222   case FloatTop:
  1223   case FloatCon:
  1224   case FloatBot:
  1225   case DoubleTop:
  1226   case DoubleCon:
  1227   case DoubleBot:
  1228   case Bottom:                  // Ye Olde Default
  1229     return Type::BOTTOM;
  1230   default:                      // All else is a mistake
  1231     typerr(t);
  1232   case Top:                     // No change
  1233     return this;
  1234   case Int:                     // Int vs Int?
  1235     break;
  1238   // Expand covered set
  1239   const TypeInt *r = t->is_int();
  1240   return make( MIN2(_lo,r->_lo), MAX2(_hi,r->_hi), MAX2(_widen,r->_widen) );
  1243 //------------------------------xdual------------------------------------------
  1244 // Dual: reverse hi & lo; flip widen
  1245 const Type *TypeInt::xdual() const {
  1246   int w = normalize_int_widen(_hi,_lo, WidenMax-_widen);
  1247   return new TypeInt(_hi,_lo,w);
  1250 //------------------------------widen------------------------------------------
  1251 // Only happens for optimistic top-down optimizations.
  1252 const Type *TypeInt::widen( const Type *old, const Type* limit ) const {
  1253   // Coming from TOP or such; no widening
  1254   if( old->base() != Int ) return this;
  1255   const TypeInt *ot = old->is_int();
  1257   // If new guy is equal to old guy, no widening
  1258   if( _lo == ot->_lo && _hi == ot->_hi )
  1259     return old;
  1261   // If new guy contains old, then we widened
  1262   if( _lo <= ot->_lo && _hi >= ot->_hi ) {
  1263     // New contains old
  1264     // If new guy is already wider than old, no widening
  1265     if( _widen > ot->_widen ) return this;
  1266     // If old guy was a constant, do not bother
  1267     if (ot->_lo == ot->_hi)  return this;
  1268     // Now widen new guy.
  1269     // Check for widening too far
  1270     if (_widen == WidenMax) {
  1271       int max = max_jint;
  1272       int min = min_jint;
  1273       if (limit->isa_int()) {
  1274         max = limit->is_int()->_hi;
  1275         min = limit->is_int()->_lo;
  1277       if (min < _lo && _hi < max) {
  1278         // If neither endpoint is extremal yet, push out the endpoint
  1279         // which is closer to its respective limit.
  1280         if (_lo >= 0 ||                 // easy common case
  1281             (juint)(_lo - min) >= (juint)(max - _hi)) {
  1282           // Try to widen to an unsigned range type of 31 bits:
  1283           return make(_lo, max, WidenMax);
  1284         } else {
  1285           return make(min, _hi, WidenMax);
  1288       return TypeInt::INT;
  1290     // Returned widened new guy
  1291     return make(_lo,_hi,_widen+1);
  1294   // If old guy contains new, then we probably widened too far & dropped to
  1295   // bottom.  Return the wider fellow.
  1296   if ( ot->_lo <= _lo && ot->_hi >= _hi )
  1297     return old;
  1299   //fatal("Integer value range is not subset");
  1300   //return this;
  1301   return TypeInt::INT;
  1304 //------------------------------narrow---------------------------------------
  1305 // Only happens for pessimistic optimizations.
  1306 const Type *TypeInt::narrow( const Type *old ) const {
  1307   if (_lo >= _hi)  return this;   // already narrow enough
  1308   if (old == NULL)  return this;
  1309   const TypeInt* ot = old->isa_int();
  1310   if (ot == NULL)  return this;
  1311   jint olo = ot->_lo;
  1312   jint ohi = ot->_hi;
  1314   // If new guy is equal to old guy, no narrowing
  1315   if (_lo == olo && _hi == ohi)  return old;
  1317   // If old guy was maximum range, allow the narrowing
  1318   if (olo == min_jint && ohi == max_jint)  return this;
  1320   if (_lo < olo || _hi > ohi)
  1321     return this;                // doesn't narrow; pretty wierd
  1323   // The new type narrows the old type, so look for a "death march".
  1324   // See comments on PhaseTransform::saturate.
  1325   juint nrange = _hi - _lo;
  1326   juint orange = ohi - olo;
  1327   if (nrange < max_juint - 1 && nrange > (orange >> 1) + (SMALLINT*2)) {
  1328     // Use the new type only if the range shrinks a lot.
  1329     // We do not want the optimizer computing 2^31 point by point.
  1330     return old;
  1333   return this;
  1336 //-----------------------------filter------------------------------------------
  1337 const Type *TypeInt::filter_helper(const Type *kills, bool include_speculative) const {
  1338   const TypeInt* ft = join_helper(kills, include_speculative)->isa_int();
  1339   if (ft == NULL || ft->empty())
  1340     return Type::TOP;           // Canonical empty value
  1341   if (ft->_widen < this->_widen) {
  1342     // Do not allow the value of kill->_widen to affect the outcome.
  1343     // The widen bits must be allowed to run freely through the graph.
  1344     ft = TypeInt::make(ft->_lo, ft->_hi, this->_widen);
  1346   return ft;
  1349 //------------------------------eq---------------------------------------------
  1350 // Structural equality check for Type representations
  1351 bool TypeInt::eq( const Type *t ) const {
  1352   const TypeInt *r = t->is_int(); // Handy access
  1353   return r->_lo == _lo && r->_hi == _hi && r->_widen == _widen;
  1356 //------------------------------hash-------------------------------------------
  1357 // Type-specific hashing function.
  1358 int TypeInt::hash(void) const {
  1359   return _lo+_hi+_widen+(int)Type::Int;
  1362 //------------------------------is_finite--------------------------------------
  1363 // Has a finite value
  1364 bool TypeInt::is_finite() const {
  1365   return true;
  1368 //------------------------------dump2------------------------------------------
  1369 // Dump TypeInt
  1370 #ifndef PRODUCT
  1371 static const char* intname(char* buf, jint n) {
  1372   if (n == min_jint)
  1373     return "min";
  1374   else if (n < min_jint + 10000)
  1375     sprintf(buf, "min+" INT32_FORMAT, n - min_jint);
  1376   else if (n == max_jint)
  1377     return "max";
  1378   else if (n > max_jint - 10000)
  1379     sprintf(buf, "max-" INT32_FORMAT, max_jint - n);
  1380   else
  1381     sprintf(buf, INT32_FORMAT, n);
  1382   return buf;
  1385 void TypeInt::dump2( Dict &d, uint depth, outputStream *st ) const {
  1386   char buf[40], buf2[40];
  1387   if (_lo == min_jint && _hi == max_jint)
  1388     st->print("int");
  1389   else if (is_con())
  1390     st->print("int:%s", intname(buf, get_con()));
  1391   else if (_lo == BOOL->_lo && _hi == BOOL->_hi)
  1392     st->print("bool");
  1393   else if (_lo == BYTE->_lo && _hi == BYTE->_hi)
  1394     st->print("byte");
  1395   else if (_lo == CHAR->_lo && _hi == CHAR->_hi)
  1396     st->print("char");
  1397   else if (_lo == SHORT->_lo && _hi == SHORT->_hi)
  1398     st->print("short");
  1399   else if (_hi == max_jint)
  1400     st->print("int:>=%s", intname(buf, _lo));
  1401   else if (_lo == min_jint)
  1402     st->print("int:<=%s", intname(buf, _hi));
  1403   else
  1404     st->print("int:%s..%s", intname(buf, _lo), intname(buf2, _hi));
  1406   if (_widen != 0 && this != TypeInt::INT)
  1407     st->print(":%.*s", _widen, "wwww");
  1409 #endif
  1411 //------------------------------singleton--------------------------------------
  1412 // TRUE if Type is a singleton type, FALSE otherwise.   Singletons are simple
  1413 // constants.
  1414 bool TypeInt::singleton(void) const {
  1415   return _lo >= _hi;
  1418 bool TypeInt::empty(void) const {
  1419   return _lo > _hi;
  1422 //=============================================================================
  1423 // Convenience common pre-built types.
  1424 const TypeLong *TypeLong::MINUS_1;// -1
  1425 const TypeLong *TypeLong::ZERO; // 0
  1426 const TypeLong *TypeLong::ONE;  // 1
  1427 const TypeLong *TypeLong::POS;  // >=0
  1428 const TypeLong *TypeLong::LONG; // 64-bit integers
  1429 const TypeLong *TypeLong::INT;  // 32-bit subrange
  1430 const TypeLong *TypeLong::UINT; // 32-bit unsigned subrange
  1431 const TypeLong *TypeLong::TYPE_DOMAIN; // alias for TypeLong::LONG
  1433 //------------------------------TypeLong---------------------------------------
  1434 TypeLong::TypeLong( jlong lo, jlong hi, int w ) : Type(Long), _lo(lo), _hi(hi), _widen(w) {
  1437 //------------------------------make-------------------------------------------
  1438 const TypeLong *TypeLong::make( jlong lo ) {
  1439   return (TypeLong*)(new TypeLong(lo,lo,WidenMin))->hashcons();
  1442 static int normalize_long_widen( jlong lo, jlong hi, int w ) {
  1443   // Certain normalizations keep us sane when comparing types.
  1444   // The 'SMALLINT' covers constants.
  1445   if (lo <= hi) {
  1446     if ((julong)(hi - lo) <= SMALLINT)   w = Type::WidenMin;
  1447     if ((julong)(hi - lo) >= max_julong) w = Type::WidenMax; // TypeLong::LONG
  1448   } else {
  1449     if ((julong)(lo - hi) <= SMALLINT)   w = Type::WidenMin;
  1450     if ((julong)(lo - hi) >= max_julong) w = Type::WidenMin; // dual TypeLong::LONG
  1452   return w;
  1455 const TypeLong *TypeLong::make( jlong lo, jlong hi, int w ) {
  1456   w = normalize_long_widen(lo, hi, w);
  1457   return (TypeLong*)(new TypeLong(lo,hi,w))->hashcons();
  1461 //------------------------------meet-------------------------------------------
  1462 // Compute the MEET of two types.  It returns a new Type representation object
  1463 // with reference count equal to the number of Types pointing at it.
  1464 // Caller should wrap a Types around it.
  1465 const Type *TypeLong::xmeet( const Type *t ) const {
  1466   // Perform a fast test for common case; meeting the same types together.
  1467   if( this == t ) return this;  // Meeting same type?
  1469   // Currently "this->_base" is a TypeLong
  1470   switch (t->base()) {          // Switch on original type
  1471   case AnyPtr:                  // Mixing with oops happens when javac
  1472   case RawPtr:                  // reuses local variables
  1473   case OopPtr:
  1474   case InstPtr:
  1475   case AryPtr:
  1476   case MetadataPtr:
  1477   case KlassPtr:
  1478   case NarrowOop:
  1479   case NarrowKlass:
  1480   case Int:
  1481   case FloatTop:
  1482   case FloatCon:
  1483   case FloatBot:
  1484   case DoubleTop:
  1485   case DoubleCon:
  1486   case DoubleBot:
  1487   case Bottom:                  // Ye Olde Default
  1488     return Type::BOTTOM;
  1489   default:                      // All else is a mistake
  1490     typerr(t);
  1491   case Top:                     // No change
  1492     return this;
  1493   case Long:                    // Long vs Long?
  1494     break;
  1497   // Expand covered set
  1498   const TypeLong *r = t->is_long(); // Turn into a TypeLong
  1499   return make( MIN2(_lo,r->_lo), MAX2(_hi,r->_hi), MAX2(_widen,r->_widen) );
  1502 //------------------------------xdual------------------------------------------
  1503 // Dual: reverse hi & lo; flip widen
  1504 const Type *TypeLong::xdual() const {
  1505   int w = normalize_long_widen(_hi,_lo, WidenMax-_widen);
  1506   return new TypeLong(_hi,_lo,w);
  1509 //------------------------------widen------------------------------------------
  1510 // Only happens for optimistic top-down optimizations.
  1511 const Type *TypeLong::widen( const Type *old, const Type* limit ) const {
  1512   // Coming from TOP or such; no widening
  1513   if( old->base() != Long ) return this;
  1514   const TypeLong *ot = old->is_long();
  1516   // If new guy is equal to old guy, no widening
  1517   if( _lo == ot->_lo && _hi == ot->_hi )
  1518     return old;
  1520   // If new guy contains old, then we widened
  1521   if( _lo <= ot->_lo && _hi >= ot->_hi ) {
  1522     // New contains old
  1523     // If new guy is already wider than old, no widening
  1524     if( _widen > ot->_widen ) return this;
  1525     // If old guy was a constant, do not bother
  1526     if (ot->_lo == ot->_hi)  return this;
  1527     // Now widen new guy.
  1528     // Check for widening too far
  1529     if (_widen == WidenMax) {
  1530       jlong max = max_jlong;
  1531       jlong min = min_jlong;
  1532       if (limit->isa_long()) {
  1533         max = limit->is_long()->_hi;
  1534         min = limit->is_long()->_lo;
  1536       if (min < _lo && _hi < max) {
  1537         // If neither endpoint is extremal yet, push out the endpoint
  1538         // which is closer to its respective limit.
  1539         if (_lo >= 0 ||                 // easy common case
  1540             (julong)(_lo - min) >= (julong)(max - _hi)) {
  1541           // Try to widen to an unsigned range type of 32/63 bits:
  1542           if (max >= max_juint && _hi < max_juint)
  1543             return make(_lo, max_juint, WidenMax);
  1544           else
  1545             return make(_lo, max, WidenMax);
  1546         } else {
  1547           return make(min, _hi, WidenMax);
  1550       return TypeLong::LONG;
  1552     // Returned widened new guy
  1553     return make(_lo,_hi,_widen+1);
  1556   // If old guy contains new, then we probably widened too far & dropped to
  1557   // bottom.  Return the wider fellow.
  1558   if ( ot->_lo <= _lo && ot->_hi >= _hi )
  1559     return old;
  1561   //  fatal("Long value range is not subset");
  1562   // return this;
  1563   return TypeLong::LONG;
  1566 //------------------------------narrow----------------------------------------
  1567 // Only happens for pessimistic optimizations.
  1568 const Type *TypeLong::narrow( const Type *old ) const {
  1569   if (_lo >= _hi)  return this;   // already narrow enough
  1570   if (old == NULL)  return this;
  1571   const TypeLong* ot = old->isa_long();
  1572   if (ot == NULL)  return this;
  1573   jlong olo = ot->_lo;
  1574   jlong ohi = ot->_hi;
  1576   // If new guy is equal to old guy, no narrowing
  1577   if (_lo == olo && _hi == ohi)  return old;
  1579   // If old guy was maximum range, allow the narrowing
  1580   if (olo == min_jlong && ohi == max_jlong)  return this;
  1582   if (_lo < olo || _hi > ohi)
  1583     return this;                // doesn't narrow; pretty wierd
  1585   // The new type narrows the old type, so look for a "death march".
  1586   // See comments on PhaseTransform::saturate.
  1587   julong nrange = _hi - _lo;
  1588   julong orange = ohi - olo;
  1589   if (nrange < max_julong - 1 && nrange > (orange >> 1) + (SMALLINT*2)) {
  1590     // Use the new type only if the range shrinks a lot.
  1591     // We do not want the optimizer computing 2^31 point by point.
  1592     return old;
  1595   return this;
  1598 //-----------------------------filter------------------------------------------
  1599 const Type *TypeLong::filter_helper(const Type *kills, bool include_speculative) const {
  1600   const TypeLong* ft = join_helper(kills, include_speculative)->isa_long();
  1601   if (ft == NULL || ft->empty())
  1602     return Type::TOP;           // Canonical empty value
  1603   if (ft->_widen < this->_widen) {
  1604     // Do not allow the value of kill->_widen to affect the outcome.
  1605     // The widen bits must be allowed to run freely through the graph.
  1606     ft = TypeLong::make(ft->_lo, ft->_hi, this->_widen);
  1608   return ft;
  1611 //------------------------------eq---------------------------------------------
  1612 // Structural equality check for Type representations
  1613 bool TypeLong::eq( const Type *t ) const {
  1614   const TypeLong *r = t->is_long(); // Handy access
  1615   return r->_lo == _lo &&  r->_hi == _hi  && r->_widen == _widen;
  1618 //------------------------------hash-------------------------------------------
  1619 // Type-specific hashing function.
  1620 int TypeLong::hash(void) const {
  1621   return (int)(_lo+_hi+_widen+(int)Type::Long);
  1624 //------------------------------is_finite--------------------------------------
  1625 // Has a finite value
  1626 bool TypeLong::is_finite() const {
  1627   return true;
  1630 //------------------------------dump2------------------------------------------
  1631 // Dump TypeLong
  1632 #ifndef PRODUCT
  1633 static const char* longnamenear(jlong x, const char* xname, char* buf, jlong n) {
  1634   if (n > x) {
  1635     if (n >= x + 10000)  return NULL;
  1636     sprintf(buf, "%s+" JLONG_FORMAT, xname, n - x);
  1637   } else if (n < x) {
  1638     if (n <= x - 10000)  return NULL;
  1639     sprintf(buf, "%s-" JLONG_FORMAT, xname, x - n);
  1640   } else {
  1641     return xname;
  1643   return buf;
  1646 static const char* longname(char* buf, jlong n) {
  1647   const char* str;
  1648   if (n == min_jlong)
  1649     return "min";
  1650   else if (n < min_jlong + 10000)
  1651     sprintf(buf, "min+" JLONG_FORMAT, n - min_jlong);
  1652   else if (n == max_jlong)
  1653     return "max";
  1654   else if (n > max_jlong - 10000)
  1655     sprintf(buf, "max-" JLONG_FORMAT, max_jlong - n);
  1656   else if ((str = longnamenear(max_juint, "maxuint", buf, n)) != NULL)
  1657     return str;
  1658   else if ((str = longnamenear(max_jint, "maxint", buf, n)) != NULL)
  1659     return str;
  1660   else if ((str = longnamenear(min_jint, "minint", buf, n)) != NULL)
  1661     return str;
  1662   else
  1663     sprintf(buf, JLONG_FORMAT, n);
  1664   return buf;
  1667 void TypeLong::dump2( Dict &d, uint depth, outputStream *st ) const {
  1668   char buf[80], buf2[80];
  1669   if (_lo == min_jlong && _hi == max_jlong)
  1670     st->print("long");
  1671   else if (is_con())
  1672     st->print("long:%s", longname(buf, get_con()));
  1673   else if (_hi == max_jlong)
  1674     st->print("long:>=%s", longname(buf, _lo));
  1675   else if (_lo == min_jlong)
  1676     st->print("long:<=%s", longname(buf, _hi));
  1677   else
  1678     st->print("long:%s..%s", longname(buf, _lo), longname(buf2, _hi));
  1680   if (_widen != 0 && this != TypeLong::LONG)
  1681     st->print(":%.*s", _widen, "wwww");
  1683 #endif
  1685 //------------------------------singleton--------------------------------------
  1686 // TRUE if Type is a singleton type, FALSE otherwise.   Singletons are simple
  1687 // constants
  1688 bool TypeLong::singleton(void) const {
  1689   return _lo >= _hi;
  1692 bool TypeLong::empty(void) const {
  1693   return _lo > _hi;
  1696 //=============================================================================
  1697 // Convenience common pre-built types.
  1698 const TypeTuple *TypeTuple::IFBOTH;     // Return both arms of IF as reachable
  1699 const TypeTuple *TypeTuple::IFFALSE;
  1700 const TypeTuple *TypeTuple::IFTRUE;
  1701 const TypeTuple *TypeTuple::IFNEITHER;
  1702 const TypeTuple *TypeTuple::LOOPBODY;
  1703 const TypeTuple *TypeTuple::MEMBAR;
  1704 const TypeTuple *TypeTuple::STORECONDITIONAL;
  1705 const TypeTuple *TypeTuple::START_I2C;
  1706 const TypeTuple *TypeTuple::INT_PAIR;
  1707 const TypeTuple *TypeTuple::LONG_PAIR;
  1708 const TypeTuple *TypeTuple::INT_CC_PAIR;
  1709 const TypeTuple *TypeTuple::LONG_CC_PAIR;
  1712 //------------------------------make-------------------------------------------
  1713 // Make a TypeTuple from the range of a method signature
  1714 const TypeTuple *TypeTuple::make_range(ciSignature* sig) {
  1715   ciType* return_type = sig->return_type();
  1716   uint total_fields = TypeFunc::Parms + return_type->size();
  1717   const Type **field_array = fields(total_fields);
  1718   switch (return_type->basic_type()) {
  1719   case T_LONG:
  1720     field_array[TypeFunc::Parms]   = TypeLong::LONG;
  1721     field_array[TypeFunc::Parms+1] = Type::HALF;
  1722     break;
  1723   case T_DOUBLE:
  1724     field_array[TypeFunc::Parms]   = Type::DOUBLE;
  1725     field_array[TypeFunc::Parms+1] = Type::HALF;
  1726     break;
  1727   case T_OBJECT:
  1728   case T_ARRAY:
  1729   case T_BOOLEAN:
  1730   case T_CHAR:
  1731   case T_FLOAT:
  1732   case T_BYTE:
  1733   case T_SHORT:
  1734   case T_INT:
  1735     field_array[TypeFunc::Parms] = get_const_type(return_type);
  1736     break;
  1737   case T_VOID:
  1738     break;
  1739   default:
  1740     ShouldNotReachHere();
  1742   return (TypeTuple*)(new TypeTuple(total_fields,field_array))->hashcons();
  1745 // Make a TypeTuple from the domain of a method signature
  1746 const TypeTuple *TypeTuple::make_domain(ciInstanceKlass* recv, ciSignature* sig) {
  1747   uint total_fields = TypeFunc::Parms + sig->size();
  1749   uint pos = TypeFunc::Parms;
  1750   const Type **field_array;
  1751   if (recv != NULL) {
  1752     total_fields++;
  1753     field_array = fields(total_fields);
  1754     // Use get_const_type here because it respects UseUniqueSubclasses:
  1755     field_array[pos++] = get_const_type(recv)->join_speculative(TypePtr::NOTNULL);
  1756   } else {
  1757     field_array = fields(total_fields);
  1760   int i = 0;
  1761   while (pos < total_fields) {
  1762     ciType* type = sig->type_at(i);
  1764     switch (type->basic_type()) {
  1765     case T_LONG:
  1766       field_array[pos++] = TypeLong::LONG;
  1767       field_array[pos++] = Type::HALF;
  1768       break;
  1769     case T_DOUBLE:
  1770       field_array[pos++] = Type::DOUBLE;
  1771       field_array[pos++] = Type::HALF;
  1772       break;
  1773     case T_OBJECT:
  1774     case T_ARRAY:
  1775     case T_BOOLEAN:
  1776     case T_CHAR:
  1777     case T_FLOAT:
  1778     case T_BYTE:
  1779     case T_SHORT:
  1780     case T_INT:
  1781       field_array[pos++] = get_const_type(type);
  1782       break;
  1783     default:
  1784       ShouldNotReachHere();
  1786     i++;
  1788   return (TypeTuple*)(new TypeTuple(total_fields,field_array))->hashcons();
  1791 const TypeTuple *TypeTuple::make( uint cnt, const Type **fields ) {
  1792   return (TypeTuple*)(new TypeTuple(cnt,fields))->hashcons();
  1795 //------------------------------fields-----------------------------------------
  1796 // Subroutine call type with space allocated for argument types
  1797 const Type **TypeTuple::fields( uint arg_cnt ) {
  1798   const Type **flds = (const Type **)(Compile::current()->type_arena()->Amalloc_4((TypeFunc::Parms+arg_cnt)*sizeof(Type*) ));
  1799   flds[TypeFunc::Control  ] = Type::CONTROL;
  1800   flds[TypeFunc::I_O      ] = Type::ABIO;
  1801   flds[TypeFunc::Memory   ] = Type::MEMORY;
  1802   flds[TypeFunc::FramePtr ] = TypeRawPtr::BOTTOM;
  1803   flds[TypeFunc::ReturnAdr] = Type::RETURN_ADDRESS;
  1805   return flds;
  1808 //------------------------------meet-------------------------------------------
  1809 // Compute the MEET of two types.  It returns a new Type object.
  1810 const Type *TypeTuple::xmeet( const Type *t ) const {
  1811   // Perform a fast test for common case; meeting the same types together.
  1812   if( this == t ) return this;  // Meeting same type-rep?
  1814   // Current "this->_base" is Tuple
  1815   switch (t->base()) {          // switch on original type
  1817   case Bottom:                  // Ye Olde Default
  1818     return t;
  1820   default:                      // All else is a mistake
  1821     typerr(t);
  1823   case Tuple: {                 // Meeting 2 signatures?
  1824     const TypeTuple *x = t->is_tuple();
  1825     assert( _cnt == x->_cnt, "" );
  1826     const Type **fields = (const Type **)(Compile::current()->type_arena()->Amalloc_4( _cnt*sizeof(Type*) ));
  1827     for( uint i=0; i<_cnt; i++ )
  1828       fields[i] = field_at(i)->xmeet( x->field_at(i) );
  1829     return TypeTuple::make(_cnt,fields);
  1831   case Top:
  1832     break;
  1834   return this;                  // Return the double constant
  1837 //------------------------------xdual------------------------------------------
  1838 // Dual: compute field-by-field dual
  1839 const Type *TypeTuple::xdual() const {
  1840   const Type **fields = (const Type **)(Compile::current()->type_arena()->Amalloc_4( _cnt*sizeof(Type*) ));
  1841   for( uint i=0; i<_cnt; i++ )
  1842     fields[i] = _fields[i]->dual();
  1843   return new TypeTuple(_cnt,fields);
  1846 //------------------------------eq---------------------------------------------
  1847 // Structural equality check for Type representations
  1848 bool TypeTuple::eq( const Type *t ) const {
  1849   const TypeTuple *s = (const TypeTuple *)t;
  1850   if (_cnt != s->_cnt)  return false;  // Unequal field counts
  1851   for (uint i = 0; i < _cnt; i++)
  1852     if (field_at(i) != s->field_at(i)) // POINTER COMPARE!  NO RECURSION!
  1853       return false;             // Missed
  1854   return true;
  1857 //------------------------------hash-------------------------------------------
  1858 // Type-specific hashing function.
  1859 int TypeTuple::hash(void) const {
  1860   intptr_t sum = _cnt;
  1861   for( uint i=0; i<_cnt; i++ )
  1862     sum += (intptr_t)_fields[i];     // Hash on pointers directly
  1863   return sum;
  1866 //------------------------------dump2------------------------------------------
  1867 // Dump signature Type
  1868 #ifndef PRODUCT
  1869 void TypeTuple::dump2( Dict &d, uint depth, outputStream *st ) const {
  1870   st->print("{");
  1871   if( !depth || d[this] ) {     // Check for recursive print
  1872     st->print("...}");
  1873     return;
  1875   d.Insert((void*)this, (void*)this);   // Stop recursion
  1876   if( _cnt ) {
  1877     uint i;
  1878     for( i=0; i<_cnt-1; i++ ) {
  1879       st->print("%d:", i);
  1880       _fields[i]->dump2(d, depth-1, st);
  1881       st->print(", ");
  1883     st->print("%d:", i);
  1884     _fields[i]->dump2(d, depth-1, st);
  1886   st->print("}");
  1888 #endif
  1890 //------------------------------singleton--------------------------------------
  1891 // TRUE if Type is a singleton type, FALSE otherwise.   Singletons are simple
  1892 // constants (Ldi nodes).  Singletons are integer, float or double constants
  1893 // or a single symbol.
  1894 bool TypeTuple::singleton(void) const {
  1895   return false;                 // Never a singleton
  1898 bool TypeTuple::empty(void) const {
  1899   for( uint i=0; i<_cnt; i++ ) {
  1900     if (_fields[i]->empty())  return true;
  1902   return false;
  1905 //=============================================================================
  1906 // Convenience common pre-built types.
  1908 inline const TypeInt* normalize_array_size(const TypeInt* size) {
  1909   // Certain normalizations keep us sane when comparing types.
  1910   // We do not want arrayOop variables to differ only by the wideness
  1911   // of their index types.  Pick minimum wideness, since that is the
  1912   // forced wideness of small ranges anyway.
  1913   if (size->_widen != Type::WidenMin)
  1914     return TypeInt::make(size->_lo, size->_hi, Type::WidenMin);
  1915   else
  1916     return size;
  1919 //------------------------------make-------------------------------------------
  1920 const TypeAry* TypeAry::make(const Type* elem, const TypeInt* size, bool stable) {
  1921   if (UseCompressedOops && elem->isa_oopptr()) {
  1922     elem = elem->make_narrowoop();
  1924   size = normalize_array_size(size);
  1925   return (TypeAry*)(new TypeAry(elem,size,stable))->hashcons();
  1928 //------------------------------meet-------------------------------------------
  1929 // Compute the MEET of two types.  It returns a new Type object.
  1930 const Type *TypeAry::xmeet( const Type *t ) const {
  1931   // Perform a fast test for common case; meeting the same types together.
  1932   if( this == t ) return this;  // Meeting same type-rep?
  1934   // Current "this->_base" is Ary
  1935   switch (t->base()) {          // switch on original type
  1937   case Bottom:                  // Ye Olde Default
  1938     return t;
  1940   default:                      // All else is a mistake
  1941     typerr(t);
  1943   case Array: {                 // Meeting 2 arrays?
  1944     const TypeAry *a = t->is_ary();
  1945     return TypeAry::make(_elem->meet_speculative(a->_elem),
  1946                          _size->xmeet(a->_size)->is_int(),
  1947                          _stable & a->_stable);
  1949   case Top:
  1950     break;
  1952   return this;                  // Return the double constant
  1955 //------------------------------xdual------------------------------------------
  1956 // Dual: compute field-by-field dual
  1957 const Type *TypeAry::xdual() const {
  1958   const TypeInt* size_dual = _size->dual()->is_int();
  1959   size_dual = normalize_array_size(size_dual);
  1960   return new TypeAry(_elem->dual(), size_dual, !_stable);
  1963 //------------------------------eq---------------------------------------------
  1964 // Structural equality check for Type representations
  1965 bool TypeAry::eq( const Type *t ) const {
  1966   const TypeAry *a = (const TypeAry*)t;
  1967   return _elem == a->_elem &&
  1968     _stable == a->_stable &&
  1969     _size == a->_size;
  1972 //------------------------------hash-------------------------------------------
  1973 // Type-specific hashing function.
  1974 int TypeAry::hash(void) const {
  1975   return (intptr_t)_elem + (intptr_t)_size + (_stable ? 43 : 0);
  1978 /**
  1979  * Return same type without a speculative part in the element
  1980  */
  1981 const Type* TypeAry::remove_speculative() const {
  1982   return make(_elem->remove_speculative(), _size, _stable);
  1985 //----------------------interface_vs_oop---------------------------------------
  1986 #ifdef ASSERT
  1987 bool TypeAry::interface_vs_oop(const Type *t) const {
  1988   const TypeAry* t_ary = t->is_ary();
  1989   if (t_ary) {
  1990     return _elem->interface_vs_oop(t_ary->_elem);
  1992   return false;
  1994 #endif
  1996 //------------------------------dump2------------------------------------------
  1997 #ifndef PRODUCT
  1998 void TypeAry::dump2( Dict &d, uint depth, outputStream *st ) const {
  1999   if (_stable)  st->print("stable:");
  2000   _elem->dump2(d, depth, st);
  2001   st->print("[");
  2002   _size->dump2(d, depth, st);
  2003   st->print("]");
  2005 #endif
  2007 //------------------------------singleton--------------------------------------
  2008 // TRUE if Type is a singleton type, FALSE otherwise.   Singletons are simple
  2009 // constants (Ldi nodes).  Singletons are integer, float or double constants
  2010 // or a single symbol.
  2011 bool TypeAry::singleton(void) const {
  2012   return false;                 // Never a singleton
  2015 bool TypeAry::empty(void) const {
  2016   return _elem->empty() || _size->empty();
  2019 //--------------------------ary_must_be_exact----------------------------------
  2020 bool TypeAry::ary_must_be_exact() const {
  2021   if (!UseExactTypes)       return false;
  2022   // This logic looks at the element type of an array, and returns true
  2023   // if the element type is either a primitive or a final instance class.
  2024   // In such cases, an array built on this ary must have no subclasses.
  2025   if (_elem == BOTTOM)      return false;  // general array not exact
  2026   if (_elem == TOP   )      return false;  // inverted general array not exact
  2027   const TypeOopPtr*  toop = NULL;
  2028   if (UseCompressedOops && _elem->isa_narrowoop()) {
  2029     toop = _elem->make_ptr()->isa_oopptr();
  2030   } else {
  2031     toop = _elem->isa_oopptr();
  2033   if (!toop)                return true;   // a primitive type, like int
  2034   ciKlass* tklass = toop->klass();
  2035   if (tklass == NULL)       return false;  // unloaded class
  2036   if (!tklass->is_loaded()) return false;  // unloaded class
  2037   const TypeInstPtr* tinst;
  2038   if (_elem->isa_narrowoop())
  2039     tinst = _elem->make_ptr()->isa_instptr();
  2040   else
  2041     tinst = _elem->isa_instptr();
  2042   if (tinst)
  2043     return tklass->as_instance_klass()->is_final();
  2044   const TypeAryPtr*  tap;
  2045   if (_elem->isa_narrowoop())
  2046     tap = _elem->make_ptr()->isa_aryptr();
  2047   else
  2048     tap = _elem->isa_aryptr();
  2049   if (tap)
  2050     return tap->ary()->ary_must_be_exact();
  2051   return false;
  2054 //==============================TypeVect=======================================
  2055 // Convenience common pre-built types.
  2056 const TypeVect *TypeVect::VECTS = NULL; //  32-bit vectors
  2057 const TypeVect *TypeVect::VECTD = NULL; //  64-bit vectors
  2058 const TypeVect *TypeVect::VECTX = NULL; // 128-bit vectors
  2059 const TypeVect *TypeVect::VECTY = NULL; // 256-bit vectors
  2061 //------------------------------make-------------------------------------------
  2062 const TypeVect* TypeVect::make(const Type *elem, uint length) {
  2063   BasicType elem_bt = elem->array_element_basic_type();
  2064   assert(is_java_primitive(elem_bt), "only primitive types in vector");
  2065   assert(length > 1 && is_power_of_2(length), "vector length is power of 2");
  2066   assert(Matcher::vector_size_supported(elem_bt, length), "length in range");
  2067   int size = length * type2aelembytes(elem_bt);
  2068   switch (Matcher::vector_ideal_reg(size)) {
  2069   case Op_VecS:
  2070     return (TypeVect*)(new TypeVectS(elem, length))->hashcons();
  2071   case Op_RegL:
  2072   case Op_VecD:
  2073   case Op_RegD:
  2074     return (TypeVect*)(new TypeVectD(elem, length))->hashcons();
  2075   case Op_VecX:
  2076     return (TypeVect*)(new TypeVectX(elem, length))->hashcons();
  2077   case Op_VecY:
  2078     return (TypeVect*)(new TypeVectY(elem, length))->hashcons();
  2080  ShouldNotReachHere();
  2081   return NULL;
  2084 //------------------------------meet-------------------------------------------
  2085 // Compute the MEET of two types.  It returns a new Type object.
  2086 const Type *TypeVect::xmeet( const Type *t ) const {
  2087   // Perform a fast test for common case; meeting the same types together.
  2088   if( this == t ) return this;  // Meeting same type-rep?
  2090   // Current "this->_base" is Vector
  2091   switch (t->base()) {          // switch on original type
  2093   case Bottom:                  // Ye Olde Default
  2094     return t;
  2096   default:                      // All else is a mistake
  2097     typerr(t);
  2099   case VectorS:
  2100   case VectorD:
  2101   case VectorX:
  2102   case VectorY: {                // Meeting 2 vectors?
  2103     const TypeVect* v = t->is_vect();
  2104     assert(  base() == v->base(), "");
  2105     assert(length() == v->length(), "");
  2106     assert(element_basic_type() == v->element_basic_type(), "");
  2107     return TypeVect::make(_elem->xmeet(v->_elem), _length);
  2109   case Top:
  2110     break;
  2112   return this;
  2115 //------------------------------xdual------------------------------------------
  2116 // Dual: compute field-by-field dual
  2117 const Type *TypeVect::xdual() const {
  2118   return new TypeVect(base(), _elem->dual(), _length);
  2121 //------------------------------eq---------------------------------------------
  2122 // Structural equality check for Type representations
  2123 bool TypeVect::eq(const Type *t) const {
  2124   const TypeVect *v = t->is_vect();
  2125   return (_elem == v->_elem) && (_length == v->_length);
  2128 //------------------------------hash-------------------------------------------
  2129 // Type-specific hashing function.
  2130 int TypeVect::hash(void) const {
  2131   return (intptr_t)_elem + (intptr_t)_length;
  2134 //------------------------------singleton--------------------------------------
  2135 // TRUE if Type is a singleton type, FALSE otherwise.   Singletons are simple
  2136 // constants (Ldi nodes).  Vector is singleton if all elements are the same
  2137 // constant value (when vector is created with Replicate code).
  2138 bool TypeVect::singleton(void) const {
  2139 // There is no Con node for vectors yet.
  2140 //  return _elem->singleton();
  2141   return false;
  2144 bool TypeVect::empty(void) const {
  2145   return _elem->empty();
  2148 //------------------------------dump2------------------------------------------
  2149 #ifndef PRODUCT
  2150 void TypeVect::dump2(Dict &d, uint depth, outputStream *st) const {
  2151   switch (base()) {
  2152   case VectorS:
  2153     st->print("vectors["); break;
  2154   case VectorD:
  2155     st->print("vectord["); break;
  2156   case VectorX:
  2157     st->print("vectorx["); break;
  2158   case VectorY:
  2159     st->print("vectory["); break;
  2160   default:
  2161     ShouldNotReachHere();
  2163   st->print("%d]:{", _length);
  2164   _elem->dump2(d, depth, st);
  2165   st->print("}");
  2167 #endif
  2170 //=============================================================================
  2171 // Convenience common pre-built types.
  2172 const TypePtr *TypePtr::NULL_PTR;
  2173 const TypePtr *TypePtr::NOTNULL;
  2174 const TypePtr *TypePtr::BOTTOM;
  2176 //------------------------------meet-------------------------------------------
  2177 // Meet over the PTR enum
  2178 const TypePtr::PTR TypePtr::ptr_meet[TypePtr::lastPTR][TypePtr::lastPTR] = {
  2179   //              TopPTR,    AnyNull,   Constant, Null,   NotNull, BotPTR,
  2180   { /* Top     */ TopPTR,    AnyNull,   Constant, Null,   NotNull, BotPTR,},
  2181   { /* AnyNull */ AnyNull,   AnyNull,   Constant, BotPTR, NotNull, BotPTR,},
  2182   { /* Constant*/ Constant,  Constant,  Constant, BotPTR, NotNull, BotPTR,},
  2183   { /* Null    */ Null,      BotPTR,    BotPTR,   Null,   BotPTR,  BotPTR,},
  2184   { /* NotNull */ NotNull,   NotNull,   NotNull,  BotPTR, NotNull, BotPTR,},
  2185   { /* BotPTR  */ BotPTR,    BotPTR,    BotPTR,   BotPTR, BotPTR,  BotPTR,}
  2186 };
  2188 //------------------------------make-------------------------------------------
  2189 const TypePtr *TypePtr::make( TYPES t, enum PTR ptr, int offset ) {
  2190   return (TypePtr*)(new TypePtr(t,ptr,offset))->hashcons();
  2193 //------------------------------cast_to_ptr_type-------------------------------
  2194 const Type *TypePtr::cast_to_ptr_type(PTR ptr) const {
  2195   assert(_base == AnyPtr, "subclass must override cast_to_ptr_type");
  2196   if( ptr == _ptr ) return this;
  2197   return make(_base, ptr, _offset);
  2200 //------------------------------get_con----------------------------------------
  2201 intptr_t TypePtr::get_con() const {
  2202   assert( _ptr == Null, "" );
  2203   return _offset;
  2206 //------------------------------meet-------------------------------------------
  2207 // Compute the MEET of two types.  It returns a new Type object.
  2208 const Type *TypePtr::xmeet( const Type *t ) const {
  2209   // Perform a fast test for common case; meeting the same types together.
  2210   if( this == t ) return this;  // Meeting same type-rep?
  2212   // Current "this->_base" is AnyPtr
  2213   switch (t->base()) {          // switch on original type
  2214   case Int:                     // Mixing ints & oops happens when javac
  2215   case Long:                    // reuses local variables
  2216   case FloatTop:
  2217   case FloatCon:
  2218   case FloatBot:
  2219   case DoubleTop:
  2220   case DoubleCon:
  2221   case DoubleBot:
  2222   case NarrowOop:
  2223   case NarrowKlass:
  2224   case Bottom:                  // Ye Olde Default
  2225     return Type::BOTTOM;
  2226   case Top:
  2227     return this;
  2229   case AnyPtr: {                // Meeting to AnyPtrs
  2230     const TypePtr *tp = t->is_ptr();
  2231     return make( AnyPtr, meet_ptr(tp->ptr()), meet_offset(tp->offset()) );
  2233   case RawPtr:                  // For these, flip the call around to cut down
  2234   case OopPtr:
  2235   case InstPtr:                 // on the cases I have to handle.
  2236   case AryPtr:
  2237   case MetadataPtr:
  2238   case KlassPtr:
  2239     return t->xmeet(this);      // Call in reverse direction
  2240   default:                      // All else is a mistake
  2241     typerr(t);
  2244   return this;
  2247 //------------------------------meet_offset------------------------------------
  2248 int TypePtr::meet_offset( int offset ) const {
  2249   // Either is 'TOP' offset?  Return the other offset!
  2250   if( _offset == OffsetTop ) return offset;
  2251   if( offset == OffsetTop ) return _offset;
  2252   // If either is different, return 'BOTTOM' offset
  2253   if( _offset != offset ) return OffsetBot;
  2254   return _offset;
  2257 //------------------------------dual_offset------------------------------------
  2258 int TypePtr::dual_offset( ) const {
  2259   if( _offset == OffsetTop ) return OffsetBot;// Map 'TOP' into 'BOTTOM'
  2260   if( _offset == OffsetBot ) return OffsetTop;// Map 'BOTTOM' into 'TOP'
  2261   return _offset;               // Map everything else into self
  2264 //------------------------------xdual------------------------------------------
  2265 // Dual: compute field-by-field dual
  2266 const TypePtr::PTR TypePtr::ptr_dual[TypePtr::lastPTR] = {
  2267   BotPTR, NotNull, Constant, Null, AnyNull, TopPTR
  2268 };
  2269 const Type *TypePtr::xdual() const {
  2270   return new TypePtr( AnyPtr, dual_ptr(), dual_offset() );
  2273 //------------------------------xadd_offset------------------------------------
  2274 int TypePtr::xadd_offset( intptr_t offset ) const {
  2275   // Adding to 'TOP' offset?  Return 'TOP'!
  2276   if( _offset == OffsetTop || offset == OffsetTop ) return OffsetTop;
  2277   // Adding to 'BOTTOM' offset?  Return 'BOTTOM'!
  2278   if( _offset == OffsetBot || offset == OffsetBot ) return OffsetBot;
  2279   // Addition overflows or "accidentally" equals to OffsetTop? Return 'BOTTOM'!
  2280   offset += (intptr_t)_offset;
  2281   if (offset != (int)offset || offset == OffsetTop) return OffsetBot;
  2283   // assert( _offset >= 0 && _offset+offset >= 0, "" );
  2284   // It is possible to construct a negative offset during PhaseCCP
  2286   return (int)offset;        // Sum valid offsets
  2289 //------------------------------add_offset-------------------------------------
  2290 const TypePtr *TypePtr::add_offset( intptr_t offset ) const {
  2291   return make( AnyPtr, _ptr, xadd_offset(offset) );
  2294 //------------------------------eq---------------------------------------------
  2295 // Structural equality check for Type representations
  2296 bool TypePtr::eq( const Type *t ) const {
  2297   const TypePtr *a = (const TypePtr*)t;
  2298   return _ptr == a->ptr() && _offset == a->offset();
  2301 //------------------------------hash-------------------------------------------
  2302 // Type-specific hashing function.
  2303 int TypePtr::hash(void) const {
  2304   return _ptr + _offset;
  2307 //------------------------------dump2------------------------------------------
  2308 const char *const TypePtr::ptr_msg[TypePtr::lastPTR] = {
  2309   "TopPTR","AnyNull","Constant","NULL","NotNull","BotPTR"
  2310 };
  2312 #ifndef PRODUCT
  2313 void TypePtr::dump2( Dict &d, uint depth, outputStream *st ) const {
  2314   if( _ptr == Null ) st->print("NULL");
  2315   else st->print("%s *", ptr_msg[_ptr]);
  2316   if( _offset == OffsetTop ) st->print("+top");
  2317   else if( _offset == OffsetBot ) st->print("+bot");
  2318   else if( _offset ) st->print("+%d", _offset);
  2320 #endif
  2322 //------------------------------singleton--------------------------------------
  2323 // TRUE if Type is a singleton type, FALSE otherwise.   Singletons are simple
  2324 // constants
  2325 bool TypePtr::singleton(void) const {
  2326   // TopPTR, Null, AnyNull, Constant are all singletons
  2327   return (_offset != OffsetBot) && !below_centerline(_ptr);
  2330 bool TypePtr::empty(void) const {
  2331   return (_offset == OffsetTop) || above_centerline(_ptr);
  2334 //=============================================================================
  2335 // Convenience common pre-built types.
  2336 const TypeRawPtr *TypeRawPtr::BOTTOM;
  2337 const TypeRawPtr *TypeRawPtr::NOTNULL;
  2339 //------------------------------make-------------------------------------------
  2340 const TypeRawPtr *TypeRawPtr::make( enum PTR ptr ) {
  2341   assert( ptr != Constant, "what is the constant?" );
  2342   assert( ptr != Null, "Use TypePtr for NULL" );
  2343   return (TypeRawPtr*)(new TypeRawPtr(ptr,0))->hashcons();
  2346 const TypeRawPtr *TypeRawPtr::make( address bits ) {
  2347   assert( bits, "Use TypePtr for NULL" );
  2348   return (TypeRawPtr*)(new TypeRawPtr(Constant,bits))->hashcons();
  2351 //------------------------------cast_to_ptr_type-------------------------------
  2352 const Type *TypeRawPtr::cast_to_ptr_type(PTR ptr) const {
  2353   assert( ptr != Constant, "what is the constant?" );
  2354   assert( ptr != Null, "Use TypePtr for NULL" );
  2355   assert( _bits==0, "Why cast a constant address?");
  2356   if( ptr == _ptr ) return this;
  2357   return make(ptr);
  2360 //------------------------------get_con----------------------------------------
  2361 intptr_t TypeRawPtr::get_con() const {
  2362   assert( _ptr == Null || _ptr == Constant, "" );
  2363   return (intptr_t)_bits;
  2366 //------------------------------meet-------------------------------------------
  2367 // Compute the MEET of two types.  It returns a new Type object.
  2368 const Type *TypeRawPtr::xmeet( const Type *t ) const {
  2369   // Perform a fast test for common case; meeting the same types together.
  2370   if( this == t ) return this;  // Meeting same type-rep?
  2372   // Current "this->_base" is RawPtr
  2373   switch( t->base() ) {         // switch on original type
  2374   case Bottom:                  // Ye Olde Default
  2375     return t;
  2376   case Top:
  2377     return this;
  2378   case AnyPtr:                  // Meeting to AnyPtrs
  2379     break;
  2380   case RawPtr: {                // might be top, bot, any/not or constant
  2381     enum PTR tptr = t->is_ptr()->ptr();
  2382     enum PTR ptr = meet_ptr( tptr );
  2383     if( ptr == Constant ) {     // Cannot be equal constants, so...
  2384       if( tptr == Constant && _ptr != Constant)  return t;
  2385       if( _ptr == Constant && tptr != Constant)  return this;
  2386       ptr = NotNull;            // Fall down in lattice
  2388     return make( ptr );
  2391   case OopPtr:
  2392   case InstPtr:
  2393   case AryPtr:
  2394   case MetadataPtr:
  2395   case KlassPtr:
  2396     return TypePtr::BOTTOM;     // Oop meet raw is not well defined
  2397   default:                      // All else is a mistake
  2398     typerr(t);
  2401   // Found an AnyPtr type vs self-RawPtr type
  2402   const TypePtr *tp = t->is_ptr();
  2403   switch (tp->ptr()) {
  2404   case TypePtr::TopPTR:  return this;
  2405   case TypePtr::BotPTR:  return t;
  2406   case TypePtr::Null:
  2407     if( _ptr == TypePtr::TopPTR ) return t;
  2408     return TypeRawPtr::BOTTOM;
  2409   case TypePtr::NotNull: return TypePtr::make( AnyPtr, meet_ptr(TypePtr::NotNull), tp->meet_offset(0) );
  2410   case TypePtr::AnyNull:
  2411     if( _ptr == TypePtr::Constant) return this;
  2412     return make( meet_ptr(TypePtr::AnyNull) );
  2413   default: ShouldNotReachHere();
  2415   return this;
  2418 //------------------------------xdual------------------------------------------
  2419 // Dual: compute field-by-field dual
  2420 const Type *TypeRawPtr::xdual() const {
  2421   return new TypeRawPtr( dual_ptr(), _bits );
  2424 //------------------------------add_offset-------------------------------------
  2425 const TypePtr *TypeRawPtr::add_offset( intptr_t offset ) const {
  2426   if( offset == OffsetTop ) return BOTTOM; // Undefined offset-> undefined pointer
  2427   if( offset == OffsetBot ) return BOTTOM; // Unknown offset-> unknown pointer
  2428   if( offset == 0 ) return this; // No change
  2429   switch (_ptr) {
  2430   case TypePtr::TopPTR:
  2431   case TypePtr::BotPTR:
  2432   case TypePtr::NotNull:
  2433     return this;
  2434   case TypePtr::Null:
  2435   case TypePtr::Constant: {
  2436     address bits = _bits+offset;
  2437     if ( bits == 0 ) return TypePtr::NULL_PTR;
  2438     return make( bits );
  2440   default:  ShouldNotReachHere();
  2442   return NULL;                  // Lint noise
  2445 //------------------------------eq---------------------------------------------
  2446 // Structural equality check for Type representations
  2447 bool TypeRawPtr::eq( const Type *t ) const {
  2448   const TypeRawPtr *a = (const TypeRawPtr*)t;
  2449   return _bits == a->_bits && TypePtr::eq(t);
  2452 //------------------------------hash-------------------------------------------
  2453 // Type-specific hashing function.
  2454 int TypeRawPtr::hash(void) const {
  2455   return (intptr_t)_bits + TypePtr::hash();
  2458 //------------------------------dump2------------------------------------------
  2459 #ifndef PRODUCT
  2460 void TypeRawPtr::dump2( Dict &d, uint depth, outputStream *st ) const {
  2461   if( _ptr == Constant )
  2462     st->print(INTPTR_FORMAT, _bits);
  2463   else
  2464     st->print("rawptr:%s", ptr_msg[_ptr]);
  2466 #endif
  2468 //=============================================================================
  2469 // Convenience common pre-built type.
  2470 const TypeOopPtr *TypeOopPtr::BOTTOM;
  2472 //------------------------------TypeOopPtr-------------------------------------
  2473 TypeOopPtr::TypeOopPtr(TYPES t, PTR ptr, ciKlass* k, bool xk, ciObject* o, int offset, int instance_id, const TypeOopPtr* speculative, int inline_depth)
  2474   : TypePtr(t, ptr, offset),
  2475     _const_oop(o), _klass(k),
  2476     _klass_is_exact(xk),
  2477     _is_ptr_to_narrowoop(false),
  2478     _is_ptr_to_narrowklass(false),
  2479     _is_ptr_to_boxed_value(false),
  2480     _instance_id(instance_id),
  2481     _speculative(speculative),
  2482     _inline_depth(inline_depth){
  2483   if (Compile::current()->eliminate_boxing() && (t == InstPtr) &&
  2484       (offset > 0) && xk && (k != 0) && k->is_instance_klass()) {
  2485     _is_ptr_to_boxed_value = k->as_instance_klass()->is_boxed_value_offset(offset);
  2487 #ifdef _LP64
  2488   if (_offset != 0) {
  2489     if (_offset == oopDesc::klass_offset_in_bytes()) {
  2490       _is_ptr_to_narrowklass = UseCompressedClassPointers;
  2491     } else if (klass() == NULL) {
  2492       // Array with unknown body type
  2493       assert(this->isa_aryptr(), "only arrays without klass");
  2494       _is_ptr_to_narrowoop = UseCompressedOops;
  2495     } else if (this->isa_aryptr()) {
  2496       _is_ptr_to_narrowoop = (UseCompressedOops && klass()->is_obj_array_klass() &&
  2497                              _offset != arrayOopDesc::length_offset_in_bytes());
  2498     } else if (klass()->is_instance_klass()) {
  2499       ciInstanceKlass* ik = klass()->as_instance_klass();
  2500       ciField* field = NULL;
  2501       if (this->isa_klassptr()) {
  2502         // Perm objects don't use compressed references
  2503       } else if (_offset == OffsetBot || _offset == OffsetTop) {
  2504         // unsafe access
  2505         _is_ptr_to_narrowoop = UseCompressedOops;
  2506       } else { // exclude unsafe ops
  2507         assert(this->isa_instptr(), "must be an instance ptr.");
  2509         if (klass() == ciEnv::current()->Class_klass() &&
  2510             (_offset == java_lang_Class::klass_offset_in_bytes() ||
  2511              _offset == java_lang_Class::array_klass_offset_in_bytes())) {
  2512           // Special hidden fields from the Class.
  2513           assert(this->isa_instptr(), "must be an instance ptr.");
  2514           _is_ptr_to_narrowoop = false;
  2515         } else if (klass() == ciEnv::current()->Class_klass() &&
  2516                    _offset >= InstanceMirrorKlass::offset_of_static_fields()) {
  2517           // Static fields
  2518           assert(o != NULL, "must be constant");
  2519           ciInstanceKlass* k = o->as_instance()->java_lang_Class_klass()->as_instance_klass();
  2520           ciField* field = k->get_field_by_offset(_offset, true);
  2521           assert(field != NULL, "missing field");
  2522           BasicType basic_elem_type = field->layout_type();
  2523           _is_ptr_to_narrowoop = UseCompressedOops && (basic_elem_type == T_OBJECT ||
  2524                                                        basic_elem_type == T_ARRAY);
  2525         } else {
  2526           // Instance fields which contains a compressed oop references.
  2527           field = ik->get_field_by_offset(_offset, false);
  2528           if (field != NULL) {
  2529             BasicType basic_elem_type = field->layout_type();
  2530             _is_ptr_to_narrowoop = UseCompressedOops && (basic_elem_type == T_OBJECT ||
  2531                                                          basic_elem_type == T_ARRAY);
  2532           } else if (klass()->equals(ciEnv::current()->Object_klass())) {
  2533             // Compile::find_alias_type() cast exactness on all types to verify
  2534             // that it does not affect alias type.
  2535             _is_ptr_to_narrowoop = UseCompressedOops;
  2536           } else {
  2537             // Type for the copy start in LibraryCallKit::inline_native_clone().
  2538             _is_ptr_to_narrowoop = UseCompressedOops;
  2544 #endif
  2547 //------------------------------make-------------------------------------------
  2548 const TypeOopPtr *TypeOopPtr::make(PTR ptr,
  2549                                    int offset, int instance_id, const TypeOopPtr* speculative, int inline_depth) {
  2550   assert(ptr != Constant, "no constant generic pointers");
  2551   ciKlass*  k = Compile::current()->env()->Object_klass();
  2552   bool      xk = false;
  2553   ciObject* o = NULL;
  2554   return (TypeOopPtr*)(new TypeOopPtr(OopPtr, ptr, k, xk, o, offset, instance_id, speculative, inline_depth))->hashcons();
  2558 //------------------------------cast_to_ptr_type-------------------------------
  2559 const Type *TypeOopPtr::cast_to_ptr_type(PTR ptr) const {
  2560   assert(_base == OopPtr, "subclass must override cast_to_ptr_type");
  2561   if( ptr == _ptr ) return this;
  2562   return make(ptr, _offset, _instance_id, _speculative, _inline_depth);
  2565 //-----------------------------cast_to_instance_id----------------------------
  2566 const TypeOopPtr *TypeOopPtr::cast_to_instance_id(int instance_id) const {
  2567   // There are no instances of a general oop.
  2568   // Return self unchanged.
  2569   return this;
  2572 //-----------------------------cast_to_exactness-------------------------------
  2573 const Type *TypeOopPtr::cast_to_exactness(bool klass_is_exact) const {
  2574   // There is no such thing as an exact general oop.
  2575   // Return self unchanged.
  2576   return this;
  2580 //------------------------------as_klass_type----------------------------------
  2581 // Return the klass type corresponding to this instance or array type.
  2582 // It is the type that is loaded from an object of this type.
  2583 const TypeKlassPtr* TypeOopPtr::as_klass_type() const {
  2584   ciKlass* k = klass();
  2585   bool    xk = klass_is_exact();
  2586   if (k == NULL)
  2587     return TypeKlassPtr::OBJECT;
  2588   else
  2589     return TypeKlassPtr::make(xk? Constant: NotNull, k, 0);
  2592 const Type *TypeOopPtr::xmeet(const Type *t) const {
  2593   const Type* res = xmeet_helper(t);
  2594   if (res->isa_oopptr() == NULL) {
  2595     return res;
  2598   const TypeOopPtr* res_oopptr = res->is_oopptr();
  2599   if (res_oopptr->speculative() != NULL) {
  2600     // type->speculative() == NULL means that speculation is no better
  2601     // than type, i.e. type->speculative() == type. So there are 2
  2602     // ways to represent the fact that we have no useful speculative
  2603     // data and we should use a single one to be able to test for
  2604     // equality between types. Check whether type->speculative() ==
  2605     // type and set speculative to NULL if it is the case.
  2606     if (res_oopptr->remove_speculative() == res_oopptr->speculative()) {
  2607       return res_oopptr->remove_speculative();
  2611   return res;
  2614 //------------------------------meet-------------------------------------------
  2615 // Compute the MEET of two types.  It returns a new Type object.
  2616 const Type *TypeOopPtr::xmeet_helper(const Type *t) const {
  2617   // Perform a fast test for common case; meeting the same types together.
  2618   if( this == t ) return this;  // Meeting same type-rep?
  2620   // Current "this->_base" is OopPtr
  2621   switch (t->base()) {          // switch on original type
  2623   case Int:                     // Mixing ints & oops happens when javac
  2624   case Long:                    // reuses local variables
  2625   case FloatTop:
  2626   case FloatCon:
  2627   case FloatBot:
  2628   case DoubleTop:
  2629   case DoubleCon:
  2630   case DoubleBot:
  2631   case NarrowOop:
  2632   case NarrowKlass:
  2633   case Bottom:                  // Ye Olde Default
  2634     return Type::BOTTOM;
  2635   case Top:
  2636     return this;
  2638   default:                      // All else is a mistake
  2639     typerr(t);
  2641   case RawPtr:
  2642   case MetadataPtr:
  2643   case KlassPtr:
  2644     return TypePtr::BOTTOM;     // Oop meet raw is not well defined
  2646   case AnyPtr: {
  2647     // Found an AnyPtr type vs self-OopPtr type
  2648     const TypePtr *tp = t->is_ptr();
  2649     int offset = meet_offset(tp->offset());
  2650     PTR ptr = meet_ptr(tp->ptr());
  2651     switch (tp->ptr()) {
  2652     case Null:
  2653       if (ptr == Null)  return TypePtr::make(AnyPtr, ptr, offset);
  2654       // else fall through:
  2655     case TopPTR:
  2656     case AnyNull: {
  2657       int instance_id = meet_instance_id(InstanceTop);
  2658       const TypeOopPtr* speculative = _speculative;
  2659       return make(ptr, offset, instance_id, speculative, _inline_depth);
  2661     case BotPTR:
  2662     case NotNull:
  2663       return TypePtr::make(AnyPtr, ptr, offset);
  2664     default: typerr(t);
  2668   case OopPtr: {                 // Meeting to other OopPtrs
  2669     const TypeOopPtr *tp = t->is_oopptr();
  2670     int instance_id = meet_instance_id(tp->instance_id());
  2671     const TypeOopPtr* speculative = xmeet_speculative(tp);
  2672     int depth = meet_inline_depth(tp->inline_depth());
  2673     return make(meet_ptr(tp->ptr()), meet_offset(tp->offset()), instance_id, speculative, depth);
  2676   case InstPtr:                  // For these, flip the call around to cut down
  2677   case AryPtr:
  2678     return t->xmeet(this);      // Call in reverse direction
  2680   } // End of switch
  2681   return this;                  // Return the double constant
  2685 //------------------------------xdual------------------------------------------
  2686 // Dual of a pure heap pointer.  No relevant klass or oop information.
  2687 const Type *TypeOopPtr::xdual() const {
  2688   assert(klass() == Compile::current()->env()->Object_klass(), "no klasses here");
  2689   assert(const_oop() == NULL,             "no constants here");
  2690   return new TypeOopPtr(_base, dual_ptr(), klass(), klass_is_exact(), const_oop(), dual_offset(), dual_instance_id(), dual_speculative(), dual_inline_depth());
  2693 //--------------------------make_from_klass_common-----------------------------
  2694 // Computes the element-type given a klass.
  2695 const TypeOopPtr* TypeOopPtr::make_from_klass_common(ciKlass *klass, bool klass_change, bool try_for_exact) {
  2696   if (klass->is_instance_klass()) {
  2697     Compile* C = Compile::current();
  2698     Dependencies* deps = C->dependencies();
  2699     assert((deps != NULL) == (C->method() != NULL && C->method()->code_size() > 0), "sanity");
  2700     // Element is an instance
  2701     bool klass_is_exact = false;
  2702     if (klass->is_loaded()) {
  2703       // Try to set klass_is_exact.
  2704       ciInstanceKlass* ik = klass->as_instance_klass();
  2705       klass_is_exact = ik->is_final();
  2706       if (!klass_is_exact && klass_change
  2707           && deps != NULL && UseUniqueSubclasses) {
  2708         ciInstanceKlass* sub = ik->unique_concrete_subklass();
  2709         if (sub != NULL) {
  2710           deps->assert_abstract_with_unique_concrete_subtype(ik, sub);
  2711           klass = ik = sub;
  2712           klass_is_exact = sub->is_final();
  2715       if (!klass_is_exact && try_for_exact
  2716           && deps != NULL && UseExactTypes) {
  2717         if (!ik->is_interface() && !ik->has_subklass()) {
  2718           // Add a dependence; if concrete subclass added we need to recompile
  2719           deps->assert_leaf_type(ik);
  2720           klass_is_exact = true;
  2724     return TypeInstPtr::make(TypePtr::BotPTR, klass, klass_is_exact, NULL, 0);
  2725   } else if (klass->is_obj_array_klass()) {
  2726     // Element is an object array. Recursively call ourself.
  2727     const TypeOopPtr *etype = TypeOopPtr::make_from_klass_common(klass->as_obj_array_klass()->element_klass(), false, try_for_exact);
  2728     bool xk = etype->klass_is_exact();
  2729     const TypeAry* arr0 = TypeAry::make(etype, TypeInt::POS);
  2730     // We used to pass NotNull in here, asserting that the sub-arrays
  2731     // are all not-null.  This is not true in generally, as code can
  2732     // slam NULLs down in the subarrays.
  2733     const TypeAryPtr* arr = TypeAryPtr::make(TypePtr::BotPTR, arr0, klass, xk, 0);
  2734     return arr;
  2735   } else if (klass->is_type_array_klass()) {
  2736     // Element is an typeArray
  2737     const Type* etype = get_const_basic_type(klass->as_type_array_klass()->element_type());
  2738     const TypeAry* arr0 = TypeAry::make(etype, TypeInt::POS);
  2739     // We used to pass NotNull in here, asserting that the array pointer
  2740     // is not-null. That was not true in general.
  2741     const TypeAryPtr* arr = TypeAryPtr::make(TypePtr::BotPTR, arr0, klass, true, 0);
  2742     return arr;
  2743   } else {
  2744     ShouldNotReachHere();
  2745     return NULL;
  2749 //------------------------------make_from_constant-----------------------------
  2750 // Make a java pointer from an oop constant
  2751 const TypeOopPtr* TypeOopPtr::make_from_constant(ciObject* o,
  2752                                                  bool require_constant,
  2753                                                  bool is_autobox_cache) {
  2754   assert(!o->is_null_object(), "null object not yet handled here.");
  2755   ciKlass* klass = o->klass();
  2756   if (klass->is_instance_klass()) {
  2757     // Element is an instance
  2758     if (require_constant) {
  2759       if (!o->can_be_constant())  return NULL;
  2760     } else if (!o->should_be_constant()) {
  2761       return TypeInstPtr::make(TypePtr::NotNull, klass, true, NULL, 0);
  2763     return TypeInstPtr::make(o);
  2764   } else if (klass->is_obj_array_klass()) {
  2765     // Element is an object array. Recursively call ourself.
  2766     const TypeOopPtr *etype =
  2767       TypeOopPtr::make_from_klass_raw(klass->as_obj_array_klass()->element_klass());
  2768     if (is_autobox_cache) {
  2769       // The pointers in the autobox arrays are always non-null.
  2770       etype = etype->cast_to_ptr_type(TypePtr::NotNull)->is_oopptr();
  2772     const TypeAry* arr0 = TypeAry::make(etype, TypeInt::make(o->as_array()->length()));
  2773     // We used to pass NotNull in here, asserting that the sub-arrays
  2774     // are all not-null.  This is not true in generally, as code can
  2775     // slam NULLs down in the subarrays.
  2776     if (require_constant) {
  2777       if (!o->can_be_constant())  return NULL;
  2778     } else if (!o->should_be_constant()) {
  2779       return TypeAryPtr::make(TypePtr::NotNull, arr0, klass, true, 0);
  2781     const TypeAryPtr* arr = TypeAryPtr::make(TypePtr::Constant, o, arr0, klass, true, 0, InstanceBot, NULL, InlineDepthBottom, is_autobox_cache);
  2782     return arr;
  2783   } else if (klass->is_type_array_klass()) {
  2784     // Element is an typeArray
  2785     const Type* etype =
  2786       (Type*)get_const_basic_type(klass->as_type_array_klass()->element_type());
  2787     const TypeAry* arr0 = TypeAry::make(etype, TypeInt::make(o->as_array()->length()));
  2788     // We used to pass NotNull in here, asserting that the array pointer
  2789     // is not-null. That was not true in general.
  2790     if (require_constant) {
  2791       if (!o->can_be_constant())  return NULL;
  2792     } else if (!o->should_be_constant()) {
  2793       return TypeAryPtr::make(TypePtr::NotNull, arr0, klass, true, 0);
  2795     const TypeAryPtr* arr = TypeAryPtr::make(TypePtr::Constant, o, arr0, klass, true, 0);
  2796     return arr;
  2799   fatal("unhandled object type");
  2800   return NULL;
  2803 //------------------------------get_con----------------------------------------
  2804 intptr_t TypeOopPtr::get_con() const {
  2805   assert( _ptr == Null || _ptr == Constant, "" );
  2806   assert( _offset >= 0, "" );
  2808   if (_offset != 0) {
  2809     // After being ported to the compiler interface, the compiler no longer
  2810     // directly manipulates the addresses of oops.  Rather, it only has a pointer
  2811     // to a handle at compile time.  This handle is embedded in the generated
  2812     // code and dereferenced at the time the nmethod is made.  Until that time,
  2813     // it is not reasonable to do arithmetic with the addresses of oops (we don't
  2814     // have access to the addresses!).  This does not seem to currently happen,
  2815     // but this assertion here is to help prevent its occurence.
  2816     tty->print_cr("Found oop constant with non-zero offset");
  2817     ShouldNotReachHere();
  2820   return (intptr_t)const_oop()->constant_encoding();
  2824 //-----------------------------filter------------------------------------------
  2825 // Do not allow interface-vs.-noninterface joins to collapse to top.
  2826 const Type *TypeOopPtr::filter_helper(const Type *kills, bool include_speculative) const {
  2828   const Type* ft = join_helper(kills, include_speculative);
  2829   const TypeInstPtr* ftip = ft->isa_instptr();
  2830   const TypeInstPtr* ktip = kills->isa_instptr();
  2832   if (ft->empty()) {
  2833     // Check for evil case of 'this' being a class and 'kills' expecting an
  2834     // interface.  This can happen because the bytecodes do not contain
  2835     // enough type info to distinguish a Java-level interface variable
  2836     // from a Java-level object variable.  If we meet 2 classes which
  2837     // both implement interface I, but their meet is at 'j/l/O' which
  2838     // doesn't implement I, we have no way to tell if the result should
  2839     // be 'I' or 'j/l/O'.  Thus we'll pick 'j/l/O'.  If this then flows
  2840     // into a Phi which "knows" it's an Interface type we'll have to
  2841     // uplift the type.
  2842     if (!empty() && ktip != NULL && ktip->is_loaded() && ktip->klass()->is_interface())
  2843       return kills;             // Uplift to interface
  2845     return Type::TOP;           // Canonical empty value
  2848   // If we have an interface-typed Phi or cast and we narrow to a class type,
  2849   // the join should report back the class.  However, if we have a J/L/Object
  2850   // class-typed Phi and an interface flows in, it's possible that the meet &
  2851   // join report an interface back out.  This isn't possible but happens
  2852   // because the type system doesn't interact well with interfaces.
  2853   if (ftip != NULL && ktip != NULL &&
  2854       ftip->is_loaded() &&  ftip->klass()->is_interface() &&
  2855       ktip->is_loaded() && !ktip->klass()->is_interface()) {
  2856     // Happens in a CTW of rt.jar, 320-341, no extra flags
  2857     assert(!ftip->klass_is_exact(), "interface could not be exact");
  2858     return ktip->cast_to_ptr_type(ftip->ptr());
  2861   return ft;
  2864 //------------------------------eq---------------------------------------------
  2865 // Structural equality check for Type representations
  2866 bool TypeOopPtr::eq( const Type *t ) const {
  2867   const TypeOopPtr *a = (const TypeOopPtr*)t;
  2868   if (_klass_is_exact != a->_klass_is_exact ||
  2869       _instance_id != a->_instance_id ||
  2870       !eq_speculative(a) ||
  2871       _inline_depth != a->_inline_depth)  return false;
  2872   ciObject* one = const_oop();
  2873   ciObject* two = a->const_oop();
  2874   if (one == NULL || two == NULL) {
  2875     return (one == two) && TypePtr::eq(t);
  2876   } else {
  2877     return one->equals(two) && TypePtr::eq(t);
  2881 //------------------------------hash-------------------------------------------
  2882 // Type-specific hashing function.
  2883 int TypeOopPtr::hash(void) const {
  2884   return
  2885     (const_oop() ? const_oop()->hash() : 0) +
  2886     _klass_is_exact +
  2887     _instance_id +
  2888     hash_speculative() +
  2889     _inline_depth +
  2890     TypePtr::hash();
  2893 //------------------------------dump2------------------------------------------
  2894 #ifndef PRODUCT
  2895 void TypeOopPtr::dump2( Dict &d, uint depth, outputStream *st ) const {
  2896   st->print("oopptr:%s", ptr_msg[_ptr]);
  2897   if( _klass_is_exact ) st->print(":exact");
  2898   if( const_oop() ) st->print(INTPTR_FORMAT, const_oop());
  2899   switch( _offset ) {
  2900   case OffsetTop: st->print("+top"); break;
  2901   case OffsetBot: st->print("+any"); break;
  2902   case         0: break;
  2903   default:        st->print("+%d",_offset); break;
  2905   if (_instance_id == InstanceTop)
  2906     st->print(",iid=top");
  2907   else if (_instance_id != InstanceBot)
  2908     st->print(",iid=%d",_instance_id);
  2910   dump_inline_depth(st);
  2911   dump_speculative(st);
  2914 /**
  2915  *dump the speculative part of the type
  2916  */
  2917 void TypeOopPtr::dump_speculative(outputStream *st) const {
  2918   if (_speculative != NULL) {
  2919     st->print(" (speculative=");
  2920     _speculative->dump_on(st);
  2921     st->print(")");
  2925 void TypeOopPtr::dump_inline_depth(outputStream *st) const {
  2926   if (_inline_depth != InlineDepthBottom) {
  2927     if (_inline_depth == InlineDepthTop) {
  2928       st->print(" (inline_depth=InlineDepthTop)");
  2929     } else {
  2930       st->print(" (inline_depth=%d)", _inline_depth);
  2934 #endif
  2936 //------------------------------singleton--------------------------------------
  2937 // TRUE if Type is a singleton type, FALSE otherwise.   Singletons are simple
  2938 // constants
  2939 bool TypeOopPtr::singleton(void) const {
  2940   // detune optimizer to not generate constant oop + constant offset as a constant!
  2941   // TopPTR, Null, AnyNull, Constant are all singletons
  2942   return (_offset == 0) && !below_centerline(_ptr);
  2945 //------------------------------add_offset-------------------------------------
  2946 const TypePtr *TypeOopPtr::add_offset(intptr_t offset) const {
  2947   return make(_ptr, xadd_offset(offset), _instance_id, add_offset_speculative(offset), _inline_depth);
  2950 /**
  2951  * Return same type without a speculative part
  2952  */
  2953 const Type* TypeOopPtr::remove_speculative() const {
  2954   if (_speculative == NULL) {
  2955     return this;
  2957   assert(_inline_depth == InlineDepthTop || _inline_depth == InlineDepthBottom, "non speculative type shouldn't have inline depth");
  2958   return make(_ptr, _offset, _instance_id, NULL, _inline_depth);
  2961 /**
  2962  * Return same type but with a different inline depth (used for speculation)
  2964  * @param depth  depth to meet with
  2965  */
  2966 const TypeOopPtr* TypeOopPtr::with_inline_depth(int depth) const {
  2967   if (!UseInlineDepthForSpeculativeTypes) {
  2968     return this;
  2970   return make(_ptr, _offset, _instance_id, _speculative, depth);
  2973 /**
  2974  * Check whether new profiling would improve speculative type
  2976  * @param   exact_kls    class from profiling
  2977  * @param   inline_depth inlining depth of profile point
  2979  * @return  true if type profile is valuable
  2980  */
  2981 bool TypeOopPtr::would_improve_type(ciKlass* exact_kls, int inline_depth) const {
  2982   // no way to improve an already exact type
  2983   if (klass_is_exact()) {
  2984     return false;
  2986   // no profiling?
  2987   if (exact_kls == NULL) {
  2988     return false;
  2990   // no speculative type or non exact speculative type?
  2991   if (speculative_type() == NULL) {
  2992     return true;
  2994   // If the node already has an exact speculative type keep it,
  2995   // unless it was provided by profiling that is at a deeper
  2996   // inlining level. Profiling at a higher inlining depth is
  2997   // expected to be less accurate.
  2998   if (_speculative->inline_depth() == InlineDepthBottom) {
  2999     return false;
  3001   assert(_speculative->inline_depth() != InlineDepthTop, "can't do the comparison");
  3002   return inline_depth < _speculative->inline_depth();
  3005 //------------------------------meet_instance_id--------------------------------
  3006 int TypeOopPtr::meet_instance_id( int instance_id ) const {
  3007   // Either is 'TOP' instance?  Return the other instance!
  3008   if( _instance_id == InstanceTop ) return  instance_id;
  3009   if(  instance_id == InstanceTop ) return _instance_id;
  3010   // If either is different, return 'BOTTOM' instance
  3011   if( _instance_id != instance_id ) return InstanceBot;
  3012   return _instance_id;
  3015 //------------------------------dual_instance_id--------------------------------
  3016 int TypeOopPtr::dual_instance_id( ) const {
  3017   if( _instance_id == InstanceTop ) return InstanceBot; // Map TOP into BOTTOM
  3018   if( _instance_id == InstanceBot ) return InstanceTop; // Map BOTTOM into TOP
  3019   return _instance_id;              // Map everything else into self
  3022 /**
  3023  * meet of the speculative parts of 2 types
  3025  * @param other  type to meet with
  3026  */
  3027 const TypeOopPtr* TypeOopPtr::xmeet_speculative(const TypeOopPtr* other) const {
  3028   bool this_has_spec = (_speculative != NULL);
  3029   bool other_has_spec = (other->speculative() != NULL);
  3031   if (!this_has_spec && !other_has_spec) {
  3032     return NULL;
  3035   // If we are at a point where control flow meets and one branch has
  3036   // a speculative type and the other has not, we meet the speculative
  3037   // type of one branch with the actual type of the other. If the
  3038   // actual type is exact and the speculative is as well, then the
  3039   // result is a speculative type which is exact and we can continue
  3040   // speculation further.
  3041   const TypeOopPtr* this_spec = _speculative;
  3042   const TypeOopPtr* other_spec = other->speculative();
  3044   if (!this_has_spec) {
  3045     this_spec = this;
  3048   if (!other_has_spec) {
  3049     other_spec = other;
  3052   return this_spec->meet_speculative(other_spec)->is_oopptr();
  3055 /**
  3056  * dual of the speculative part of the type
  3057  */
  3058 const TypeOopPtr* TypeOopPtr::dual_speculative() const {
  3059   if (_speculative == NULL) {
  3060     return NULL;
  3062   return _speculative->dual()->is_oopptr();
  3065 /**
  3066  * add offset to the speculative part of the type
  3068  * @param offset  offset to add
  3069  */
  3070 const TypeOopPtr* TypeOopPtr::add_offset_speculative(intptr_t offset) const {
  3071   if (_speculative == NULL) {
  3072     return NULL;
  3074   return _speculative->add_offset(offset)->is_oopptr();
  3077 /**
  3078  * Are the speculative parts of 2 types equal?
  3080  * @param other  type to compare this one to
  3081  */
  3082 bool TypeOopPtr::eq_speculative(const TypeOopPtr* other) const {
  3083   if (_speculative == NULL || other->speculative() == NULL) {
  3084     return _speculative == other->speculative();
  3087   if (_speculative->base() != other->speculative()->base()) {
  3088     return false;
  3091   return _speculative->eq(other->speculative());
  3094 /**
  3095  * Hash of the speculative part of the type
  3096  */
  3097 int TypeOopPtr::hash_speculative() const {
  3098   if (_speculative == NULL) {
  3099     return 0;
  3102   return _speculative->hash();
  3105 /**
  3106  * dual of the inline depth for this type (used for speculation)
  3107  */
  3108 int TypeOopPtr::dual_inline_depth() const {
  3109   return -inline_depth();
  3112 /**
  3113  * meet of 2 inline depth (used for speculation)
  3115  * @param depth  depth to meet with
  3116  */
  3117 int TypeOopPtr::meet_inline_depth(int depth) const {
  3118   return MAX2(inline_depth(), depth);
  3121 //=============================================================================
  3122 // Convenience common pre-built types.
  3123 const TypeInstPtr *TypeInstPtr::NOTNULL;
  3124 const TypeInstPtr *TypeInstPtr::BOTTOM;
  3125 const TypeInstPtr *TypeInstPtr::MIRROR;
  3126 const TypeInstPtr *TypeInstPtr::MARK;
  3127 const TypeInstPtr *TypeInstPtr::KLASS;
  3129 //------------------------------TypeInstPtr-------------------------------------
  3130 TypeInstPtr::TypeInstPtr(PTR ptr, ciKlass* k, bool xk, ciObject* o, int off, int instance_id, const TypeOopPtr* speculative, int inline_depth)
  3131   : TypeOopPtr(InstPtr, ptr, k, xk, o, off, instance_id, speculative, inline_depth), _name(k->name()) {
  3132    assert(k != NULL &&
  3133           (k->is_loaded() || o == NULL),
  3134           "cannot have constants with non-loaded klass");
  3135 };
  3137 //------------------------------make-------------------------------------------
  3138 const TypeInstPtr *TypeInstPtr::make(PTR ptr,
  3139                                      ciKlass* k,
  3140                                      bool xk,
  3141                                      ciObject* o,
  3142                                      int offset,
  3143                                      int instance_id,
  3144                                      const TypeOopPtr* speculative,
  3145                                      int inline_depth) {
  3146   assert( !k->is_loaded() || k->is_instance_klass(), "Must be for instance");
  3147   // Either const_oop() is NULL or else ptr is Constant
  3148   assert( (!o && ptr != Constant) || (o && ptr == Constant),
  3149           "constant pointers must have a value supplied" );
  3150   // Ptr is never Null
  3151   assert( ptr != Null, "NULL pointers are not typed" );
  3153   assert(instance_id <= 0 || xk || !UseExactTypes, "instances are always exactly typed");
  3154   if (!UseExactTypes)  xk = false;
  3155   if (ptr == Constant) {
  3156     // Note:  This case includes meta-object constants, such as methods.
  3157     xk = true;
  3158   } else if (k->is_loaded()) {
  3159     ciInstanceKlass* ik = k->as_instance_klass();
  3160     if (!xk && ik->is_final())     xk = true;   // no inexact final klass
  3161     if (xk && ik->is_interface())  xk = false;  // no exact interface
  3164   // Now hash this baby
  3165   TypeInstPtr *result =
  3166     (TypeInstPtr*)(new TypeInstPtr(ptr, k, xk, o ,offset, instance_id, speculative, inline_depth))->hashcons();
  3168   return result;
  3171 /**
  3172  *  Create constant type for a constant boxed value
  3173  */
  3174 const Type* TypeInstPtr::get_const_boxed_value() const {
  3175   assert(is_ptr_to_boxed_value(), "should be called only for boxed value");
  3176   assert((const_oop() != NULL), "should be called only for constant object");
  3177   ciConstant constant = const_oop()->as_instance()->field_value_by_offset(offset());
  3178   BasicType bt = constant.basic_type();
  3179   switch (bt) {
  3180     case T_BOOLEAN:  return TypeInt::make(constant.as_boolean());
  3181     case T_INT:      return TypeInt::make(constant.as_int());
  3182     case T_CHAR:     return TypeInt::make(constant.as_char());
  3183     case T_BYTE:     return TypeInt::make(constant.as_byte());
  3184     case T_SHORT:    return TypeInt::make(constant.as_short());
  3185     case T_FLOAT:    return TypeF::make(constant.as_float());
  3186     case T_DOUBLE:   return TypeD::make(constant.as_double());
  3187     case T_LONG:     return TypeLong::make(constant.as_long());
  3188     default:         break;
  3190   fatal(err_msg_res("Invalid boxed value type '%s'", type2name(bt)));
  3191   return NULL;
  3194 //------------------------------cast_to_ptr_type-------------------------------
  3195 const Type *TypeInstPtr::cast_to_ptr_type(PTR ptr) const {
  3196   if( ptr == _ptr ) return this;
  3197   // Reconstruct _sig info here since not a problem with later lazy
  3198   // construction, _sig will show up on demand.
  3199   return make(ptr, klass(), klass_is_exact(), const_oop(), _offset, _instance_id, _speculative, _inline_depth);
  3203 //-----------------------------cast_to_exactness-------------------------------
  3204 const Type *TypeInstPtr::cast_to_exactness(bool klass_is_exact) const {
  3205   if( klass_is_exact == _klass_is_exact ) return this;
  3206   if (!UseExactTypes)  return this;
  3207   if (!_klass->is_loaded())  return this;
  3208   ciInstanceKlass* ik = _klass->as_instance_klass();
  3209   if( (ik->is_final() || _const_oop) )  return this;  // cannot clear xk
  3210   if( ik->is_interface() )              return this;  // cannot set xk
  3211   return make(ptr(), klass(), klass_is_exact, const_oop(), _offset, _instance_id, _speculative, _inline_depth);
  3214 //-----------------------------cast_to_instance_id----------------------------
  3215 const TypeOopPtr *TypeInstPtr::cast_to_instance_id(int instance_id) const {
  3216   if( instance_id == _instance_id ) return this;
  3217   return make(_ptr, klass(), _klass_is_exact, const_oop(), _offset, instance_id, _speculative, _inline_depth);
  3220 //------------------------------xmeet_unloaded---------------------------------
  3221 // Compute the MEET of two InstPtrs when at least one is unloaded.
  3222 // Assume classes are different since called after check for same name/class-loader
  3223 const TypeInstPtr *TypeInstPtr::xmeet_unloaded(const TypeInstPtr *tinst) const {
  3224     int off = meet_offset(tinst->offset());
  3225     PTR ptr = meet_ptr(tinst->ptr());
  3226     int instance_id = meet_instance_id(tinst->instance_id());
  3227     const TypeOopPtr* speculative = xmeet_speculative(tinst);
  3228     int depth = meet_inline_depth(tinst->inline_depth());
  3230     const TypeInstPtr *loaded    = is_loaded() ? this  : tinst;
  3231     const TypeInstPtr *unloaded  = is_loaded() ? tinst : this;
  3232     if( loaded->klass()->equals(ciEnv::current()->Object_klass()) ) {
  3233       //
  3234       // Meet unloaded class with java/lang/Object
  3235       //
  3236       // Meet
  3237       //          |                     Unloaded Class
  3238       //  Object  |   TOP    |   AnyNull | Constant |   NotNull |  BOTTOM   |
  3239       //  ===================================================================
  3240       //   TOP    | ..........................Unloaded......................|
  3241       //  AnyNull |  U-AN    |................Unloaded......................|
  3242       // Constant | ... O-NN .................................. |   O-BOT   |
  3243       //  NotNull | ... O-NN .................................. |   O-BOT   |
  3244       //  BOTTOM  | ........................Object-BOTTOM ..................|
  3245       //
  3246       assert(loaded->ptr() != TypePtr::Null, "insanity check");
  3247       //
  3248       if(      loaded->ptr() == TypePtr::TopPTR ) { return unloaded; }
  3249       else if (loaded->ptr() == TypePtr::AnyNull) { return TypeInstPtr::make(ptr, unloaded->klass(), false, NULL, off, instance_id, speculative, depth); }
  3250       else if (loaded->ptr() == TypePtr::BotPTR ) { return TypeInstPtr::BOTTOM; }
  3251       else if (loaded->ptr() == TypePtr::Constant || loaded->ptr() == TypePtr::NotNull) {
  3252         if (unloaded->ptr() == TypePtr::BotPTR  ) { return TypeInstPtr::BOTTOM;  }
  3253         else                                      { return TypeInstPtr::NOTNULL; }
  3255       else if( unloaded->ptr() == TypePtr::TopPTR )  { return unloaded; }
  3257       return unloaded->cast_to_ptr_type(TypePtr::AnyNull)->is_instptr();
  3260     // Both are unloaded, not the same class, not Object
  3261     // Or meet unloaded with a different loaded class, not java/lang/Object
  3262     if( ptr != TypePtr::BotPTR ) {
  3263       return TypeInstPtr::NOTNULL;
  3265     return TypeInstPtr::BOTTOM;
  3269 //------------------------------meet-------------------------------------------
  3270 // Compute the MEET of two types.  It returns a new Type object.
  3271 const Type *TypeInstPtr::xmeet_helper(const Type *t) const {
  3272   // Perform a fast test for common case; meeting the same types together.
  3273   if( this == t ) return this;  // Meeting same type-rep?
  3275   // Current "this->_base" is Pointer
  3276   switch (t->base()) {          // switch on original type
  3278   case Int:                     // Mixing ints & oops happens when javac
  3279   case Long:                    // reuses local variables
  3280   case FloatTop:
  3281   case FloatCon:
  3282   case FloatBot:
  3283   case DoubleTop:
  3284   case DoubleCon:
  3285   case DoubleBot:
  3286   case NarrowOop:
  3287   case NarrowKlass:
  3288   case Bottom:                  // Ye Olde Default
  3289     return Type::BOTTOM;
  3290   case Top:
  3291     return this;
  3293   default:                      // All else is a mistake
  3294     typerr(t);
  3296   case MetadataPtr:
  3297   case KlassPtr:
  3298   case RawPtr: return TypePtr::BOTTOM;
  3300   case AryPtr: {                // All arrays inherit from Object class
  3301     const TypeAryPtr *tp = t->is_aryptr();
  3302     int offset = meet_offset(tp->offset());
  3303     PTR ptr = meet_ptr(tp->ptr());
  3304     int instance_id = meet_instance_id(tp->instance_id());
  3305     const TypeOopPtr* speculative = xmeet_speculative(tp);
  3306     int depth = meet_inline_depth(tp->inline_depth());
  3307     switch (ptr) {
  3308     case TopPTR:
  3309     case AnyNull:                // Fall 'down' to dual of object klass
  3310       // For instances when a subclass meets a superclass we fall
  3311       // below the centerline when the superclass is exact. We need to
  3312       // do the same here.
  3313       if (klass()->equals(ciEnv::current()->Object_klass()) && !klass_is_exact()) {
  3314         return TypeAryPtr::make(ptr, tp->ary(), tp->klass(), tp->klass_is_exact(), offset, instance_id, speculative, depth);
  3315       } else {
  3316         // cannot subclass, so the meet has to fall badly below the centerline
  3317         ptr = NotNull;
  3318         instance_id = InstanceBot;
  3319         return TypeInstPtr::make( ptr, ciEnv::current()->Object_klass(), false, NULL, offset, instance_id, speculative, depth);
  3321     case Constant:
  3322     case NotNull:
  3323     case BotPTR:                // Fall down to object klass
  3324       // LCA is object_klass, but if we subclass from the top we can do better
  3325       if( above_centerline(_ptr) ) { // if( _ptr == TopPTR || _ptr == AnyNull )
  3326         // If 'this' (InstPtr) is above the centerline and it is Object class
  3327         // then we can subclass in the Java class hierarchy.
  3328         // For instances when a subclass meets a superclass we fall
  3329         // below the centerline when the superclass is exact. We need
  3330         // to do the same here.
  3331         if (klass()->equals(ciEnv::current()->Object_klass()) && !klass_is_exact()) {
  3332           // that is, tp's array type is a subtype of my klass
  3333           return TypeAryPtr::make(ptr, (ptr == Constant ? tp->const_oop() : NULL),
  3334                                   tp->ary(), tp->klass(), tp->klass_is_exact(), offset, instance_id, speculative, depth);
  3337       // The other case cannot happen, since I cannot be a subtype of an array.
  3338       // The meet falls down to Object class below centerline.
  3339       if( ptr == Constant )
  3340          ptr = NotNull;
  3341       instance_id = InstanceBot;
  3342       return make(ptr, ciEnv::current()->Object_klass(), false, NULL, offset, instance_id, speculative, depth);
  3343     default: typerr(t);
  3347   case OopPtr: {                // Meeting to OopPtrs
  3348     // Found a OopPtr type vs self-InstPtr type
  3349     const TypeOopPtr *tp = t->is_oopptr();
  3350     int offset = meet_offset(tp->offset());
  3351     PTR ptr = meet_ptr(tp->ptr());
  3352     switch (tp->ptr()) {
  3353     case TopPTR:
  3354     case AnyNull: {
  3355       int instance_id = meet_instance_id(InstanceTop);
  3356       const TypeOopPtr* speculative = xmeet_speculative(tp);
  3357       int depth = meet_inline_depth(tp->inline_depth());
  3358       return make(ptr, klass(), klass_is_exact(),
  3359                   (ptr == Constant ? const_oop() : NULL), offset, instance_id, speculative, depth);
  3361     case NotNull:
  3362     case BotPTR: {
  3363       int instance_id = meet_instance_id(tp->instance_id());
  3364       const TypeOopPtr* speculative = xmeet_speculative(tp);
  3365       int depth = meet_inline_depth(tp->inline_depth());
  3366       return TypeOopPtr::make(ptr, offset, instance_id, speculative, depth);
  3368     default: typerr(t);
  3372   case AnyPtr: {                // Meeting to AnyPtrs
  3373     // Found an AnyPtr type vs self-InstPtr type
  3374     const TypePtr *tp = t->is_ptr();
  3375     int offset = meet_offset(tp->offset());
  3376     PTR ptr = meet_ptr(tp->ptr());
  3377     switch (tp->ptr()) {
  3378     case Null:
  3379       if( ptr == Null ) return TypePtr::make(AnyPtr, ptr, offset);
  3380       // else fall through to AnyNull
  3381     case TopPTR:
  3382     case AnyNull: {
  3383       int instance_id = meet_instance_id(InstanceTop);
  3384       const TypeOopPtr* speculative = _speculative;
  3385       return make(ptr, klass(), klass_is_exact(),
  3386                   (ptr == Constant ? const_oop() : NULL), offset, instance_id, speculative, _inline_depth);
  3388     case NotNull:
  3389     case BotPTR:
  3390       return TypePtr::make(AnyPtr, ptr, offset);
  3391     default: typerr(t);
  3395   /*
  3396                  A-top         }
  3397                /   |   \       }  Tops
  3398            B-top A-any C-top   }
  3399               | /  |  \ |      }  Any-nulls
  3400            B-any   |   C-any   }
  3401               |    |    |
  3402            B-con A-con C-con   } constants; not comparable across classes
  3403               |    |    |
  3404            B-not   |   C-not   }
  3405               | \  |  / |      }  not-nulls
  3406            B-bot A-not C-bot   }
  3407                \   |   /       }  Bottoms
  3408                  A-bot         }
  3409   */
  3411   case InstPtr: {                // Meeting 2 Oops?
  3412     // Found an InstPtr sub-type vs self-InstPtr type
  3413     const TypeInstPtr *tinst = t->is_instptr();
  3414     int off = meet_offset( tinst->offset() );
  3415     PTR ptr = meet_ptr( tinst->ptr() );
  3416     int instance_id = meet_instance_id(tinst->instance_id());
  3417     const TypeOopPtr* speculative = xmeet_speculative(tinst);
  3418     int depth = meet_inline_depth(tinst->inline_depth());
  3420     // Check for easy case; klasses are equal (and perhaps not loaded!)
  3421     // If we have constants, then we created oops so classes are loaded
  3422     // and we can handle the constants further down.  This case handles
  3423     // both-not-loaded or both-loaded classes
  3424     if (ptr != Constant && klass()->equals(tinst->klass()) && klass_is_exact() == tinst->klass_is_exact()) {
  3425       return make(ptr, klass(), klass_is_exact(), NULL, off, instance_id, speculative, depth);
  3428     // Classes require inspection in the Java klass hierarchy.  Must be loaded.
  3429     ciKlass* tinst_klass = tinst->klass();
  3430     ciKlass* this_klass  = this->klass();
  3431     bool tinst_xk = tinst->klass_is_exact();
  3432     bool this_xk  = this->klass_is_exact();
  3433     if (!tinst_klass->is_loaded() || !this_klass->is_loaded() ) {
  3434       // One of these classes has not been loaded
  3435       const TypeInstPtr *unloaded_meet = xmeet_unloaded(tinst);
  3436 #ifndef PRODUCT
  3437       if( PrintOpto && Verbose ) {
  3438         tty->print("meet of unloaded classes resulted in: "); unloaded_meet->dump(); tty->cr();
  3439         tty->print("  this == "); this->dump(); tty->cr();
  3440         tty->print(" tinst == "); tinst->dump(); tty->cr();
  3442 #endif
  3443       return unloaded_meet;
  3446     // Handle mixing oops and interfaces first.
  3447     if( this_klass->is_interface() && !(tinst_klass->is_interface() ||
  3448                                         tinst_klass == ciEnv::current()->Object_klass())) {
  3449       ciKlass *tmp = tinst_klass; // Swap interface around
  3450       tinst_klass = this_klass;
  3451       this_klass = tmp;
  3452       bool tmp2 = tinst_xk;
  3453       tinst_xk = this_xk;
  3454       this_xk = tmp2;
  3456     if (tinst_klass->is_interface() &&
  3457         !(this_klass->is_interface() ||
  3458           // Treat java/lang/Object as an honorary interface,
  3459           // because we need a bottom for the interface hierarchy.
  3460           this_klass == ciEnv::current()->Object_klass())) {
  3461       // Oop meets interface!
  3463       // See if the oop subtypes (implements) interface.
  3464       ciKlass *k;
  3465       bool xk;
  3466       if( this_klass->is_subtype_of( tinst_klass ) ) {
  3467         // Oop indeed subtypes.  Now keep oop or interface depending
  3468         // on whether we are both above the centerline or either is
  3469         // below the centerline.  If we are on the centerline
  3470         // (e.g., Constant vs. AnyNull interface), use the constant.
  3471         k  = below_centerline(ptr) ? tinst_klass : this_klass;
  3472         // If we are keeping this_klass, keep its exactness too.
  3473         xk = below_centerline(ptr) ? tinst_xk    : this_xk;
  3474       } else {                  // Does not implement, fall to Object
  3475         // Oop does not implement interface, so mixing falls to Object
  3476         // just like the verifier does (if both are above the
  3477         // centerline fall to interface)
  3478         k = above_centerline(ptr) ? tinst_klass : ciEnv::current()->Object_klass();
  3479         xk = above_centerline(ptr) ? tinst_xk : false;
  3480         // Watch out for Constant vs. AnyNull interface.
  3481         if (ptr == Constant)  ptr = NotNull;   // forget it was a constant
  3482         instance_id = InstanceBot;
  3484       ciObject* o = NULL;  // the Constant value, if any
  3485       if (ptr == Constant) {
  3486         // Find out which constant.
  3487         o = (this_klass == klass()) ? const_oop() : tinst->const_oop();
  3489       return make(ptr, k, xk, o, off, instance_id, speculative, depth);
  3492     // Either oop vs oop or interface vs interface or interface vs Object
  3494     // !!! Here's how the symmetry requirement breaks down into invariants:
  3495     // If we split one up & one down AND they subtype, take the down man.
  3496     // If we split one up & one down AND they do NOT subtype, "fall hard".
  3497     // If both are up and they subtype, take the subtype class.
  3498     // If both are up and they do NOT subtype, "fall hard".
  3499     // If both are down and they subtype, take the supertype class.
  3500     // If both are down and they do NOT subtype, "fall hard".
  3501     // Constants treated as down.
  3503     // Now, reorder the above list; observe that both-down+subtype is also
  3504     // "fall hard"; "fall hard" becomes the default case:
  3505     // If we split one up & one down AND they subtype, take the down man.
  3506     // If both are up and they subtype, take the subtype class.
  3508     // If both are down and they subtype, "fall hard".
  3509     // If both are down and they do NOT subtype, "fall hard".
  3510     // If both are up and they do NOT subtype, "fall hard".
  3511     // If we split one up & one down AND they do NOT subtype, "fall hard".
  3513     // If a proper subtype is exact, and we return it, we return it exactly.
  3514     // If a proper supertype is exact, there can be no subtyping relationship!
  3515     // If both types are equal to the subtype, exactness is and-ed below the
  3516     // centerline and or-ed above it.  (N.B. Constants are always exact.)
  3518     // Check for subtyping:
  3519     ciKlass *subtype = NULL;
  3520     bool subtype_exact = false;
  3521     if( tinst_klass->equals(this_klass) ) {
  3522       subtype = this_klass;
  3523       subtype_exact = below_centerline(ptr) ? (this_xk & tinst_xk) : (this_xk | tinst_xk);
  3524     } else if( !tinst_xk && this_klass->is_subtype_of( tinst_klass ) ) {
  3525       subtype = this_klass;     // Pick subtyping class
  3526       subtype_exact = this_xk;
  3527     } else if( !this_xk && tinst_klass->is_subtype_of( this_klass ) ) {
  3528       subtype = tinst_klass;    // Pick subtyping class
  3529       subtype_exact = tinst_xk;
  3532     if( subtype ) {
  3533       if( above_centerline(ptr) ) { // both are up?
  3534         this_klass = tinst_klass = subtype;
  3535         this_xk = tinst_xk = subtype_exact;
  3536       } else if( above_centerline(this ->_ptr) && !above_centerline(tinst->_ptr) ) {
  3537         this_klass = tinst_klass; // tinst is down; keep down man
  3538         this_xk = tinst_xk;
  3539       } else if( above_centerline(tinst->_ptr) && !above_centerline(this ->_ptr) ) {
  3540         tinst_klass = this_klass; // this is down; keep down man
  3541         tinst_xk = this_xk;
  3542       } else {
  3543         this_xk = subtype_exact;  // either they are equal, or we'll do an LCA
  3547     // Check for classes now being equal
  3548     if (tinst_klass->equals(this_klass)) {
  3549       // If the klasses are equal, the constants may still differ.  Fall to
  3550       // NotNull if they do (neither constant is NULL; that is a special case
  3551       // handled elsewhere).
  3552       ciObject* o = NULL;             // Assume not constant when done
  3553       ciObject* this_oop  = const_oop();
  3554       ciObject* tinst_oop = tinst->const_oop();
  3555       if( ptr == Constant ) {
  3556         if (this_oop != NULL && tinst_oop != NULL &&
  3557             this_oop->equals(tinst_oop) )
  3558           o = this_oop;
  3559         else if (above_centerline(this ->_ptr))
  3560           o = tinst_oop;
  3561         else if (above_centerline(tinst ->_ptr))
  3562           o = this_oop;
  3563         else
  3564           ptr = NotNull;
  3566       return make(ptr, this_klass, this_xk, o, off, instance_id, speculative, depth);
  3567     } // Else classes are not equal
  3569     // Since klasses are different, we require a LCA in the Java
  3570     // class hierarchy - which means we have to fall to at least NotNull.
  3571     if( ptr == TopPTR || ptr == AnyNull || ptr == Constant )
  3572       ptr = NotNull;
  3573     instance_id = InstanceBot;
  3575     // Now we find the LCA of Java classes
  3576     ciKlass* k = this_klass->least_common_ancestor(tinst_klass);
  3577     return make(ptr, k, false, NULL, off, instance_id, speculative, depth);
  3578   } // End of case InstPtr
  3580   } // End of switch
  3581   return this;                  // Return the double constant
  3585 //------------------------java_mirror_type--------------------------------------
  3586 ciType* TypeInstPtr::java_mirror_type() const {
  3587   // must be a singleton type
  3588   if( const_oop() == NULL )  return NULL;
  3590   // must be of type java.lang.Class
  3591   if( klass() != ciEnv::current()->Class_klass() )  return NULL;
  3593   return const_oop()->as_instance()->java_mirror_type();
  3597 //------------------------------xdual------------------------------------------
  3598 // Dual: do NOT dual on klasses.  This means I do NOT understand the Java
  3599 // inheritance mechanism.
  3600 const Type *TypeInstPtr::xdual() const {
  3601   return new TypeInstPtr(dual_ptr(), klass(), klass_is_exact(), const_oop(), dual_offset(), dual_instance_id(), dual_speculative(), dual_inline_depth());
  3604 //------------------------------eq---------------------------------------------
  3605 // Structural equality check for Type representations
  3606 bool TypeInstPtr::eq( const Type *t ) const {
  3607   const TypeInstPtr *p = t->is_instptr();
  3608   return
  3609     klass()->equals(p->klass()) &&
  3610     TypeOopPtr::eq(p);          // Check sub-type stuff
  3613 //------------------------------hash-------------------------------------------
  3614 // Type-specific hashing function.
  3615 int TypeInstPtr::hash(void) const {
  3616   int hash = klass()->hash() + TypeOopPtr::hash();
  3617   return hash;
  3620 //------------------------------dump2------------------------------------------
  3621 // Dump oop Type
  3622 #ifndef PRODUCT
  3623 void TypeInstPtr::dump2( Dict &d, uint depth, outputStream *st ) const {
  3624   // Print the name of the klass.
  3625   klass()->print_name_on(st);
  3627   switch( _ptr ) {
  3628   case Constant:
  3629     // TO DO: Make CI print the hex address of the underlying oop.
  3630     if (WizardMode || Verbose) {
  3631       const_oop()->print_oop(st);
  3633   case BotPTR:
  3634     if (!WizardMode && !Verbose) {
  3635       if( _klass_is_exact ) st->print(":exact");
  3636       break;
  3638   case TopPTR:
  3639   case AnyNull:
  3640   case NotNull:
  3641     st->print(":%s", ptr_msg[_ptr]);
  3642     if( _klass_is_exact ) st->print(":exact");
  3643     break;
  3646   if( _offset ) {               // Dump offset, if any
  3647     if( _offset == OffsetBot )      st->print("+any");
  3648     else if( _offset == OffsetTop ) st->print("+unknown");
  3649     else st->print("+%d", _offset);
  3652   st->print(" *");
  3653   if (_instance_id == InstanceTop)
  3654     st->print(",iid=top");
  3655   else if (_instance_id != InstanceBot)
  3656     st->print(",iid=%d",_instance_id);
  3658   dump_inline_depth(st);
  3659   dump_speculative(st);
  3661 #endif
  3663 //------------------------------add_offset-------------------------------------
  3664 const TypePtr *TypeInstPtr::add_offset(intptr_t offset) const {
  3665   return make(_ptr, klass(), klass_is_exact(), const_oop(), xadd_offset(offset), _instance_id, add_offset_speculative(offset));
  3668 const Type *TypeInstPtr::remove_speculative() const {
  3669   if (_speculative == NULL) {
  3670     return this;
  3672   assert(_inline_depth == InlineDepthTop || _inline_depth == InlineDepthBottom, "non speculative type shouldn't have inline depth");
  3673   return make(_ptr, klass(), klass_is_exact(), const_oop(), _offset, _instance_id, NULL, _inline_depth);
  3676 const TypeOopPtr *TypeInstPtr::with_inline_depth(int depth) const {
  3677   if (!UseInlineDepthForSpeculativeTypes) {
  3678     return this;
  3680   return make(_ptr, klass(), klass_is_exact(), const_oop(), _offset, _instance_id, _speculative, depth);
  3683 //=============================================================================
  3684 // Convenience common pre-built types.
  3685 const TypeAryPtr *TypeAryPtr::RANGE;
  3686 const TypeAryPtr *TypeAryPtr::OOPS;
  3687 const TypeAryPtr *TypeAryPtr::NARROWOOPS;
  3688 const TypeAryPtr *TypeAryPtr::BYTES;
  3689 const TypeAryPtr *TypeAryPtr::SHORTS;
  3690 const TypeAryPtr *TypeAryPtr::CHARS;
  3691 const TypeAryPtr *TypeAryPtr::INTS;
  3692 const TypeAryPtr *TypeAryPtr::LONGS;
  3693 const TypeAryPtr *TypeAryPtr::FLOATS;
  3694 const TypeAryPtr *TypeAryPtr::DOUBLES;
  3696 //------------------------------make-------------------------------------------
  3697 const TypeAryPtr *TypeAryPtr::make(PTR ptr, const TypeAry *ary, ciKlass* k, bool xk, int offset, int instance_id, const TypeOopPtr* speculative, int inline_depth) {
  3698   assert(!(k == NULL && ary->_elem->isa_int()),
  3699          "integral arrays must be pre-equipped with a class");
  3700   if (!xk)  xk = ary->ary_must_be_exact();
  3701   assert(instance_id <= 0 || xk || !UseExactTypes, "instances are always exactly typed");
  3702   if (!UseExactTypes)  xk = (ptr == Constant);
  3703   return (TypeAryPtr*)(new TypeAryPtr(ptr, NULL, ary, k, xk, offset, instance_id, false, speculative, inline_depth))->hashcons();
  3706 //------------------------------make-------------------------------------------
  3707 const TypeAryPtr *TypeAryPtr::make(PTR ptr, ciObject* o, const TypeAry *ary, ciKlass* k, bool xk, int offset, int instance_id, const TypeOopPtr* speculative, int inline_depth, bool is_autobox_cache) {
  3708   assert(!(k == NULL && ary->_elem->isa_int()),
  3709          "integral arrays must be pre-equipped with a class");
  3710   assert( (ptr==Constant && o) || (ptr!=Constant && !o), "" );
  3711   if (!xk)  xk = (o != NULL) || ary->ary_must_be_exact();
  3712   assert(instance_id <= 0 || xk || !UseExactTypes, "instances are always exactly typed");
  3713   if (!UseExactTypes)  xk = (ptr == Constant);
  3714   return (TypeAryPtr*)(new TypeAryPtr(ptr, o, ary, k, xk, offset, instance_id, is_autobox_cache, speculative, inline_depth))->hashcons();
  3717 //------------------------------cast_to_ptr_type-------------------------------
  3718 const Type *TypeAryPtr::cast_to_ptr_type(PTR ptr) const {
  3719   if( ptr == _ptr ) return this;
  3720   return make(ptr, const_oop(), _ary, klass(), klass_is_exact(), _offset, _instance_id, _speculative, _inline_depth);
  3724 //-----------------------------cast_to_exactness-------------------------------
  3725 const Type *TypeAryPtr::cast_to_exactness(bool klass_is_exact) const {
  3726   if( klass_is_exact == _klass_is_exact ) return this;
  3727   if (!UseExactTypes)  return this;
  3728   if (_ary->ary_must_be_exact())  return this;  // cannot clear xk
  3729   return make(ptr(), const_oop(), _ary, klass(), klass_is_exact, _offset, _instance_id, _speculative, _inline_depth);
  3732 //-----------------------------cast_to_instance_id----------------------------
  3733 const TypeOopPtr *TypeAryPtr::cast_to_instance_id(int instance_id) const {
  3734   if( instance_id == _instance_id ) return this;
  3735   return make(_ptr, const_oop(), _ary, klass(), _klass_is_exact, _offset, instance_id, _speculative, _inline_depth);
  3738 //-----------------------------narrow_size_type-------------------------------
  3739 // Local cache for arrayOopDesc::max_array_length(etype),
  3740 // which is kind of slow (and cached elsewhere by other users).
  3741 static jint max_array_length_cache[T_CONFLICT+1];
  3742 static jint max_array_length(BasicType etype) {
  3743   jint& cache = max_array_length_cache[etype];
  3744   jint res = cache;
  3745   if (res == 0) {
  3746     switch (etype) {
  3747     case T_NARROWOOP:
  3748       etype = T_OBJECT;
  3749       break;
  3750     case T_NARROWKLASS:
  3751     case T_CONFLICT:
  3752     case T_ILLEGAL:
  3753     case T_VOID:
  3754       etype = T_BYTE;           // will produce conservatively high value
  3756     cache = res = arrayOopDesc::max_array_length(etype);
  3758   return res;
  3761 // Narrow the given size type to the index range for the given array base type.
  3762 // Return NULL if the resulting int type becomes empty.
  3763 const TypeInt* TypeAryPtr::narrow_size_type(const TypeInt* size) const {
  3764   jint hi = size->_hi;
  3765   jint lo = size->_lo;
  3766   jint min_lo = 0;
  3767   jint max_hi = max_array_length(elem()->basic_type());
  3768   //if (index_not_size)  --max_hi;     // type of a valid array index, FTR
  3769   bool chg = false;
  3770   if (lo < min_lo) {
  3771     lo = min_lo;
  3772     if (size->is_con()) {
  3773       hi = lo;
  3775     chg = true;
  3777   if (hi > max_hi) {
  3778     hi = max_hi;
  3779     if (size->is_con()) {
  3780       lo = hi;
  3782     chg = true;
  3784   // Negative length arrays will produce weird intermediate dead fast-path code
  3785   if (lo > hi)
  3786     return TypeInt::ZERO;
  3787   if (!chg)
  3788     return size;
  3789   return TypeInt::make(lo, hi, Type::WidenMin);
  3792 //-------------------------------cast_to_size----------------------------------
  3793 const TypeAryPtr* TypeAryPtr::cast_to_size(const TypeInt* new_size) const {
  3794   assert(new_size != NULL, "");
  3795   new_size = narrow_size_type(new_size);
  3796   if (new_size == size())  return this;
  3797   const TypeAry* new_ary = TypeAry::make(elem(), new_size, is_stable());
  3798   return make(ptr(), const_oop(), new_ary, klass(), klass_is_exact(), _offset, _instance_id, _speculative, _inline_depth);
  3802 //------------------------------cast_to_stable---------------------------------
  3803 const TypeAryPtr* TypeAryPtr::cast_to_stable(bool stable, int stable_dimension) const {
  3804   if (stable_dimension <= 0 || (stable_dimension == 1 && stable == this->is_stable()))
  3805     return this;
  3807   const Type* elem = this->elem();
  3808   const TypePtr* elem_ptr = elem->make_ptr();
  3810   if (stable_dimension > 1 && elem_ptr != NULL && elem_ptr->isa_aryptr()) {
  3811     // If this is widened from a narrow oop, TypeAry::make will re-narrow it.
  3812     elem = elem_ptr = elem_ptr->is_aryptr()->cast_to_stable(stable, stable_dimension - 1);
  3815   const TypeAry* new_ary = TypeAry::make(elem, size(), stable);
  3817   return make(ptr(), const_oop(), new_ary, klass(), klass_is_exact(), _offset, _instance_id);
  3820 //-----------------------------stable_dimension--------------------------------
  3821 int TypeAryPtr::stable_dimension() const {
  3822   if (!is_stable())  return 0;
  3823   int dim = 1;
  3824   const TypePtr* elem_ptr = elem()->make_ptr();
  3825   if (elem_ptr != NULL && elem_ptr->isa_aryptr())
  3826     dim += elem_ptr->is_aryptr()->stable_dimension();
  3827   return dim;
  3830 //------------------------------eq---------------------------------------------
  3831 // Structural equality check for Type representations
  3832 bool TypeAryPtr::eq( const Type *t ) const {
  3833   const TypeAryPtr *p = t->is_aryptr();
  3834   return
  3835     _ary == p->_ary &&  // Check array
  3836     TypeOopPtr::eq(p);  // Check sub-parts
  3839 //------------------------------hash-------------------------------------------
  3840 // Type-specific hashing function.
  3841 int TypeAryPtr::hash(void) const {
  3842   return (intptr_t)_ary + TypeOopPtr::hash();
  3845 //------------------------------meet-------------------------------------------
  3846 // Compute the MEET of two types.  It returns a new Type object.
  3847 const Type *TypeAryPtr::xmeet_helper(const Type *t) const {
  3848   // Perform a fast test for common case; meeting the same types together.
  3849   if( this == t ) return this;  // Meeting same type-rep?
  3850   // Current "this->_base" is Pointer
  3851   switch (t->base()) {          // switch on original type
  3853   // Mixing ints & oops happens when javac reuses local variables
  3854   case Int:
  3855   case Long:
  3856   case FloatTop:
  3857   case FloatCon:
  3858   case FloatBot:
  3859   case DoubleTop:
  3860   case DoubleCon:
  3861   case DoubleBot:
  3862   case NarrowOop:
  3863   case NarrowKlass:
  3864   case Bottom:                  // Ye Olde Default
  3865     return Type::BOTTOM;
  3866   case Top:
  3867     return this;
  3869   default:                      // All else is a mistake
  3870     typerr(t);
  3872   case OopPtr: {                // Meeting to OopPtrs
  3873     // Found a OopPtr type vs self-AryPtr type
  3874     const TypeOopPtr *tp = t->is_oopptr();
  3875     int offset = meet_offset(tp->offset());
  3876     PTR ptr = meet_ptr(tp->ptr());
  3877     int depth = meet_inline_depth(tp->inline_depth());
  3878     switch (tp->ptr()) {
  3879     case TopPTR:
  3880     case AnyNull: {
  3881       int instance_id = meet_instance_id(InstanceTop);
  3882       const TypeOopPtr* speculative = xmeet_speculative(tp);
  3883       return make(ptr, (ptr == Constant ? const_oop() : NULL),
  3884                   _ary, _klass, _klass_is_exact, offset, instance_id, speculative, depth);
  3886     case BotPTR:
  3887     case NotNull: {
  3888       int instance_id = meet_instance_id(tp->instance_id());
  3889       const TypeOopPtr* speculative = xmeet_speculative(tp);
  3890       return TypeOopPtr::make(ptr, offset, instance_id, speculative, depth);
  3892     default: ShouldNotReachHere();
  3896   case AnyPtr: {                // Meeting two AnyPtrs
  3897     // Found an AnyPtr type vs self-AryPtr type
  3898     const TypePtr *tp = t->is_ptr();
  3899     int offset = meet_offset(tp->offset());
  3900     PTR ptr = meet_ptr(tp->ptr());
  3901     switch (tp->ptr()) {
  3902     case TopPTR:
  3903       return this;
  3904     case BotPTR:
  3905     case NotNull:
  3906       return TypePtr::make(AnyPtr, ptr, offset);
  3907     case Null:
  3908       if( ptr == Null ) return TypePtr::make(AnyPtr, ptr, offset);
  3909       // else fall through to AnyNull
  3910     case AnyNull: {
  3911       int instance_id = meet_instance_id(InstanceTop);
  3912       const TypeOopPtr* speculative = _speculative;
  3913       return make(ptr, (ptr == Constant ? const_oop() : NULL),
  3914                   _ary, _klass, _klass_is_exact, offset, instance_id, speculative, _inline_depth);
  3916     default: ShouldNotReachHere();
  3920   case MetadataPtr:
  3921   case KlassPtr:
  3922   case RawPtr: return TypePtr::BOTTOM;
  3924   case AryPtr: {                // Meeting 2 references?
  3925     const TypeAryPtr *tap = t->is_aryptr();
  3926     int off = meet_offset(tap->offset());
  3927     const TypeAry *tary = _ary->meet_speculative(tap->_ary)->is_ary();
  3928     PTR ptr = meet_ptr(tap->ptr());
  3929     int instance_id = meet_instance_id(tap->instance_id());
  3930     const TypeOopPtr* speculative = xmeet_speculative(tap);
  3931     int depth = meet_inline_depth(tap->inline_depth());
  3932     ciKlass* lazy_klass = NULL;
  3933     if (tary->_elem->isa_int()) {
  3934       // Integral array element types have irrelevant lattice relations.
  3935       // It is the klass that determines array layout, not the element type.
  3936       if (_klass == NULL)
  3937         lazy_klass = tap->_klass;
  3938       else if (tap->_klass == NULL || tap->_klass == _klass) {
  3939         lazy_klass = _klass;
  3940       } else {
  3941         // Something like byte[int+] meets char[int+].
  3942         // This must fall to bottom, not (int[-128..65535])[int+].
  3943         instance_id = InstanceBot;
  3944         tary = TypeAry::make(Type::BOTTOM, tary->_size, tary->_stable);
  3946     } else // Non integral arrays.
  3947       // Must fall to bottom if exact klasses in upper lattice
  3948       // are not equal or super klass is exact.
  3949       if ((above_centerline(ptr) || ptr == Constant) && klass() != tap->klass() &&
  3950           // meet with top[] and bottom[] are processed further down:
  3951           tap->_klass != NULL  && this->_klass != NULL   &&
  3952           // both are exact and not equal:
  3953           ((tap->_klass_is_exact && this->_klass_is_exact) ||
  3954            // 'tap'  is exact and super or unrelated:
  3955            (tap->_klass_is_exact && !tap->klass()->is_subtype_of(klass())) ||
  3956            // 'this' is exact and super or unrelated:
  3957            (this->_klass_is_exact && !klass()->is_subtype_of(tap->klass())))) {
  3958       tary = TypeAry::make(Type::BOTTOM, tary->_size, tary->_stable);
  3959       return make(NotNull, NULL, tary, lazy_klass, false, off, InstanceBot);
  3962     bool xk = false;
  3963     switch (tap->ptr()) {
  3964     case AnyNull:
  3965     case TopPTR:
  3966       // Compute new klass on demand, do not use tap->_klass
  3967       if (below_centerline(this->_ptr)) {
  3968         xk = this->_klass_is_exact;
  3969       } else {
  3970         xk = (tap->_klass_is_exact | this->_klass_is_exact);
  3972       return make(ptr, const_oop(), tary, lazy_klass, xk, off, instance_id, speculative, depth);
  3973     case Constant: {
  3974       ciObject* o = const_oop();
  3975       if( _ptr == Constant ) {
  3976         if( tap->const_oop() != NULL && !o->equals(tap->const_oop()) ) {
  3977           xk = (klass() == tap->klass());
  3978           ptr = NotNull;
  3979           o = NULL;
  3980           instance_id = InstanceBot;
  3981         } else {
  3982           xk = true;
  3984       } else if(above_centerline(_ptr)) {
  3985         o = tap->const_oop();
  3986         xk = true;
  3987       } else {
  3988         // Only precise for identical arrays
  3989         xk = this->_klass_is_exact && (klass() == tap->klass());
  3991       return TypeAryPtr::make(ptr, o, tary, lazy_klass, xk, off, instance_id, speculative, depth);
  3993     case NotNull:
  3994     case BotPTR:
  3995       // Compute new klass on demand, do not use tap->_klass
  3996       if (above_centerline(this->_ptr))
  3997             xk = tap->_klass_is_exact;
  3998       else  xk = (tap->_klass_is_exact & this->_klass_is_exact) &&
  3999               (klass() == tap->klass()); // Only precise for identical arrays
  4000       return TypeAryPtr::make(ptr, NULL, tary, lazy_klass, xk, off, instance_id, speculative, depth);
  4001     default: ShouldNotReachHere();
  4005   // All arrays inherit from Object class
  4006   case InstPtr: {
  4007     const TypeInstPtr *tp = t->is_instptr();
  4008     int offset = meet_offset(tp->offset());
  4009     PTR ptr = meet_ptr(tp->ptr());
  4010     int instance_id = meet_instance_id(tp->instance_id());
  4011     const TypeOopPtr* speculative = xmeet_speculative(tp);
  4012     int depth = meet_inline_depth(tp->inline_depth());
  4013     switch (ptr) {
  4014     case TopPTR:
  4015     case AnyNull:                // Fall 'down' to dual of object klass
  4016       // For instances when a subclass meets a superclass we fall
  4017       // below the centerline when the superclass is exact. We need to
  4018       // do the same here.
  4019       if (tp->klass()->equals(ciEnv::current()->Object_klass()) && !tp->klass_is_exact()) {
  4020         return TypeAryPtr::make(ptr, _ary, _klass, _klass_is_exact, offset, instance_id, speculative, depth);
  4021       } else {
  4022         // cannot subclass, so the meet has to fall badly below the centerline
  4023         ptr = NotNull;
  4024         instance_id = InstanceBot;
  4025         return TypeInstPtr::make(ptr, ciEnv::current()->Object_klass(), false, NULL,offset, instance_id, speculative, depth);
  4027     case Constant:
  4028     case NotNull:
  4029     case BotPTR:                // Fall down to object klass
  4030       // LCA is object_klass, but if we subclass from the top we can do better
  4031       if (above_centerline(tp->ptr())) {
  4032         // If 'tp'  is above the centerline and it is Object class
  4033         // then we can subclass in the Java class hierarchy.
  4034         // For instances when a subclass meets a superclass we fall
  4035         // below the centerline when the superclass is exact. We need
  4036         // to do the same here.
  4037         if (tp->klass()->equals(ciEnv::current()->Object_klass()) && !tp->klass_is_exact()) {
  4038           // that is, my array type is a subtype of 'tp' klass
  4039           return make(ptr, (ptr == Constant ? const_oop() : NULL),
  4040                       _ary, _klass, _klass_is_exact, offset, instance_id, speculative, depth);
  4043       // The other case cannot happen, since t cannot be a subtype of an array.
  4044       // The meet falls down to Object class below centerline.
  4045       if( ptr == Constant )
  4046          ptr = NotNull;
  4047       instance_id = InstanceBot;
  4048       return TypeInstPtr::make(ptr, ciEnv::current()->Object_klass(), false, NULL,offset, instance_id, speculative, depth);
  4049     default: typerr(t);
  4053   return this;                  // Lint noise
  4056 //------------------------------xdual------------------------------------------
  4057 // Dual: compute field-by-field dual
  4058 const Type *TypeAryPtr::xdual() const {
  4059   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());
  4062 //----------------------interface_vs_oop---------------------------------------
  4063 #ifdef ASSERT
  4064 bool TypeAryPtr::interface_vs_oop(const Type *t) const {
  4065   const TypeAryPtr* t_aryptr = t->isa_aryptr();
  4066   if (t_aryptr) {
  4067     return _ary->interface_vs_oop(t_aryptr->_ary);
  4069   return false;
  4071 #endif
  4073 //------------------------------dump2------------------------------------------
  4074 #ifndef PRODUCT
  4075 void TypeAryPtr::dump2( Dict &d, uint depth, outputStream *st ) const {
  4076   _ary->dump2(d,depth,st);
  4077   switch( _ptr ) {
  4078   case Constant:
  4079     const_oop()->print(st);
  4080     break;
  4081   case BotPTR:
  4082     if (!WizardMode && !Verbose) {
  4083       if( _klass_is_exact ) st->print(":exact");
  4084       break;
  4086   case TopPTR:
  4087   case AnyNull:
  4088   case NotNull:
  4089     st->print(":%s", ptr_msg[_ptr]);
  4090     if( _klass_is_exact ) st->print(":exact");
  4091     break;
  4094   if( _offset != 0 ) {
  4095     int header_size = objArrayOopDesc::header_size() * wordSize;
  4096     if( _offset == OffsetTop )       st->print("+undefined");
  4097     else if( _offset == OffsetBot )  st->print("+any");
  4098     else if( _offset < header_size ) st->print("+%d", _offset);
  4099     else {
  4100       BasicType basic_elem_type = elem()->basic_type();
  4101       int array_base = arrayOopDesc::base_offset_in_bytes(basic_elem_type);
  4102       int elem_size = type2aelembytes(basic_elem_type);
  4103       st->print("[%d]", (_offset - array_base)/elem_size);
  4106   st->print(" *");
  4107   if (_instance_id == InstanceTop)
  4108     st->print(",iid=top");
  4109   else if (_instance_id != InstanceBot)
  4110     st->print(",iid=%d",_instance_id);
  4112   dump_inline_depth(st);
  4113   dump_speculative(st);
  4115 #endif
  4117 bool TypeAryPtr::empty(void) const {
  4118   if (_ary->empty())       return true;
  4119   return TypeOopPtr::empty();
  4122 //------------------------------add_offset-------------------------------------
  4123 const TypePtr *TypeAryPtr::add_offset(intptr_t offset) const {
  4124   return make(_ptr, _const_oop, _ary, _klass, _klass_is_exact, xadd_offset(offset), _instance_id, add_offset_speculative(offset), _inline_depth);
  4127 const Type *TypeAryPtr::remove_speculative() const {
  4128   if (_speculative == NULL) {
  4129     return this;
  4131   assert(_inline_depth == InlineDepthTop || _inline_depth == InlineDepthBottom, "non speculative type shouldn't have inline depth");
  4132   return make(_ptr, _const_oop, _ary->remove_speculative()->is_ary(), _klass, _klass_is_exact, _offset, _instance_id, NULL, _inline_depth);
  4135 const TypeOopPtr *TypeAryPtr::with_inline_depth(int depth) const {
  4136   if (!UseInlineDepthForSpeculativeTypes) {
  4137     return this;
  4139   return make(_ptr, _const_oop, _ary->remove_speculative()->is_ary(), _klass, _klass_is_exact, _offset, _instance_id, _speculative, depth);
  4142 //=============================================================================
  4144 //------------------------------hash-------------------------------------------
  4145 // Type-specific hashing function.
  4146 int TypeNarrowPtr::hash(void) const {
  4147   return _ptrtype->hash() + 7;
  4150 bool TypeNarrowPtr::singleton(void) const {    // TRUE if type is a singleton
  4151   return _ptrtype->singleton();
  4154 bool TypeNarrowPtr::empty(void) const {
  4155   return _ptrtype->empty();
  4158 intptr_t TypeNarrowPtr::get_con() const {
  4159   return _ptrtype->get_con();
  4162 bool TypeNarrowPtr::eq( const Type *t ) const {
  4163   const TypeNarrowPtr* tc = isa_same_narrowptr(t);
  4164   if (tc != NULL) {
  4165     if (_ptrtype->base() != tc->_ptrtype->base()) {
  4166       return false;
  4168     return tc->_ptrtype->eq(_ptrtype);
  4170   return false;
  4173 const Type *TypeNarrowPtr::xdual() const {    // Compute dual right now.
  4174   const TypePtr* odual = _ptrtype->dual()->is_ptr();
  4175   return make_same_narrowptr(odual);
  4179 const Type *TypeNarrowPtr::filter_helper(const Type *kills, bool include_speculative) const {
  4180   if (isa_same_narrowptr(kills)) {
  4181     const Type* ft =_ptrtype->filter_helper(is_same_narrowptr(kills)->_ptrtype, include_speculative);
  4182     if (ft->empty())
  4183       return Type::TOP;           // Canonical empty value
  4184     if (ft->isa_ptr()) {
  4185       return make_hash_same_narrowptr(ft->isa_ptr());
  4187     return ft;
  4188   } else if (kills->isa_ptr()) {
  4189     const Type* ft = _ptrtype->join_helper(kills, include_speculative);
  4190     if (ft->empty())
  4191       return Type::TOP;           // Canonical empty value
  4192     return ft;
  4193   } else {
  4194     return Type::TOP;
  4198 //------------------------------xmeet------------------------------------------
  4199 // Compute the MEET of two types.  It returns a new Type object.
  4200 const Type *TypeNarrowPtr::xmeet( const Type *t ) const {
  4201   // Perform a fast test for common case; meeting the same types together.
  4202   if( this == t ) return this;  // Meeting same type-rep?
  4204   if (t->base() == base()) {
  4205     const Type* result = _ptrtype->xmeet(t->make_ptr());
  4206     if (result->isa_ptr()) {
  4207       return make_hash_same_narrowptr(result->is_ptr());
  4209     return result;
  4212   // Current "this->_base" is NarrowKlass or NarrowOop
  4213   switch (t->base()) {          // switch on original type
  4215   case Int:                     // Mixing ints & oops happens when javac
  4216   case Long:                    // reuses local variables
  4217   case FloatTop:
  4218   case FloatCon:
  4219   case FloatBot:
  4220   case DoubleTop:
  4221   case DoubleCon:
  4222   case DoubleBot:
  4223   case AnyPtr:
  4224   case RawPtr:
  4225   case OopPtr:
  4226   case InstPtr:
  4227   case AryPtr:
  4228   case MetadataPtr:
  4229   case KlassPtr:
  4230   case NarrowOop:
  4231   case NarrowKlass:
  4233   case Bottom:                  // Ye Olde Default
  4234     return Type::BOTTOM;
  4235   case Top:
  4236     return this;
  4238   default:                      // All else is a mistake
  4239     typerr(t);
  4241   } // End of switch
  4243   return this;
  4246 #ifndef PRODUCT
  4247 void TypeNarrowPtr::dump2( Dict & d, uint depth, outputStream *st ) const {
  4248   _ptrtype->dump2(d, depth, st);
  4250 #endif
  4252 const TypeNarrowOop *TypeNarrowOop::BOTTOM;
  4253 const TypeNarrowOop *TypeNarrowOop::NULL_PTR;
  4256 const TypeNarrowOop* TypeNarrowOop::make(const TypePtr* type) {
  4257   return (const TypeNarrowOop*)(new TypeNarrowOop(type))->hashcons();
  4261 #ifndef PRODUCT
  4262 void TypeNarrowOop::dump2( Dict & d, uint depth, outputStream *st ) const {
  4263   st->print("narrowoop: ");
  4264   TypeNarrowPtr::dump2(d, depth, st);
  4266 #endif
  4268 const TypeNarrowKlass *TypeNarrowKlass::NULL_PTR;
  4270 const TypeNarrowKlass* TypeNarrowKlass::make(const TypePtr* type) {
  4271   return (const TypeNarrowKlass*)(new TypeNarrowKlass(type))->hashcons();
  4274 #ifndef PRODUCT
  4275 void TypeNarrowKlass::dump2( Dict & d, uint depth, outputStream *st ) const {
  4276   st->print("narrowklass: ");
  4277   TypeNarrowPtr::dump2(d, depth, st);
  4279 #endif
  4282 //------------------------------eq---------------------------------------------
  4283 // Structural equality check for Type representations
  4284 bool TypeMetadataPtr::eq( const Type *t ) const {
  4285   const TypeMetadataPtr *a = (const TypeMetadataPtr*)t;
  4286   ciMetadata* one = metadata();
  4287   ciMetadata* two = a->metadata();
  4288   if (one == NULL || two == NULL) {
  4289     return (one == two) && TypePtr::eq(t);
  4290   } else {
  4291     return one->equals(two) && TypePtr::eq(t);
  4295 //------------------------------hash-------------------------------------------
  4296 // Type-specific hashing function.
  4297 int TypeMetadataPtr::hash(void) const {
  4298   return
  4299     (metadata() ? metadata()->hash() : 0) +
  4300     TypePtr::hash();
  4303 //------------------------------singleton--------------------------------------
  4304 // TRUE if Type is a singleton type, FALSE otherwise.   Singletons are simple
  4305 // constants
  4306 bool TypeMetadataPtr::singleton(void) const {
  4307   // detune optimizer to not generate constant metadta + constant offset as a constant!
  4308   // TopPTR, Null, AnyNull, Constant are all singletons
  4309   return (_offset == 0) && !below_centerline(_ptr);
  4312 //------------------------------add_offset-------------------------------------
  4313 const TypePtr *TypeMetadataPtr::add_offset( intptr_t offset ) const {
  4314   return make( _ptr, _metadata, xadd_offset(offset));
  4317 //-----------------------------filter------------------------------------------
  4318 // Do not allow interface-vs.-noninterface joins to collapse to top.
  4319 const Type *TypeMetadataPtr::filter_helper(const Type *kills, bool include_speculative) const {
  4320   const TypeMetadataPtr* ft = join_helper(kills, include_speculative)->isa_metadataptr();
  4321   if (ft == NULL || ft->empty())
  4322     return Type::TOP;           // Canonical empty value
  4323   return ft;
  4326  //------------------------------get_con----------------------------------------
  4327 intptr_t TypeMetadataPtr::get_con() const {
  4328   assert( _ptr == Null || _ptr == Constant, "" );
  4329   assert( _offset >= 0, "" );
  4331   if (_offset != 0) {
  4332     // After being ported to the compiler interface, the compiler no longer
  4333     // directly manipulates the addresses of oops.  Rather, it only has a pointer
  4334     // to a handle at compile time.  This handle is embedded in the generated
  4335     // code and dereferenced at the time the nmethod is made.  Until that time,
  4336     // it is not reasonable to do arithmetic with the addresses of oops (we don't
  4337     // have access to the addresses!).  This does not seem to currently happen,
  4338     // but this assertion here is to help prevent its occurence.
  4339     tty->print_cr("Found oop constant with non-zero offset");
  4340     ShouldNotReachHere();
  4343   return (intptr_t)metadata()->constant_encoding();
  4346 //------------------------------cast_to_ptr_type-------------------------------
  4347 const Type *TypeMetadataPtr::cast_to_ptr_type(PTR ptr) const {
  4348   if( ptr == _ptr ) return this;
  4349   return make(ptr, metadata(), _offset);
  4352 //------------------------------meet-------------------------------------------
  4353 // Compute the MEET of two types.  It returns a new Type object.
  4354 const Type *TypeMetadataPtr::xmeet( const Type *t ) const {
  4355   // Perform a fast test for common case; meeting the same types together.
  4356   if( this == t ) return this;  // Meeting same type-rep?
  4358   // Current "this->_base" is OopPtr
  4359   switch (t->base()) {          // switch on original type
  4361   case Int:                     // Mixing ints & oops happens when javac
  4362   case Long:                    // reuses local variables
  4363   case FloatTop:
  4364   case FloatCon:
  4365   case FloatBot:
  4366   case DoubleTop:
  4367   case DoubleCon:
  4368   case DoubleBot:
  4369   case NarrowOop:
  4370   case NarrowKlass:
  4371   case Bottom:                  // Ye Olde Default
  4372     return Type::BOTTOM;
  4373   case Top:
  4374     return this;
  4376   default:                      // All else is a mistake
  4377     typerr(t);
  4379   case AnyPtr: {
  4380     // Found an AnyPtr type vs self-OopPtr type
  4381     const TypePtr *tp = t->is_ptr();
  4382     int offset = meet_offset(tp->offset());
  4383     PTR ptr = meet_ptr(tp->ptr());
  4384     switch (tp->ptr()) {
  4385     case Null:
  4386       if (ptr == Null)  return TypePtr::make(AnyPtr, ptr, offset);
  4387       // else fall through:
  4388     case TopPTR:
  4389     case AnyNull: {
  4390       return make(ptr, _metadata, offset);
  4392     case BotPTR:
  4393     case NotNull:
  4394       return TypePtr::make(AnyPtr, ptr, offset);
  4395     default: typerr(t);
  4399   case RawPtr:
  4400   case KlassPtr:
  4401   case OopPtr:
  4402   case InstPtr:
  4403   case AryPtr:
  4404     return TypePtr::BOTTOM;     // Oop meet raw is not well defined
  4406   case MetadataPtr: {
  4407     const TypeMetadataPtr *tp = t->is_metadataptr();
  4408     int offset = meet_offset(tp->offset());
  4409     PTR tptr = tp->ptr();
  4410     PTR ptr = meet_ptr(tptr);
  4411     ciMetadata* md = (tptr == TopPTR) ? metadata() : tp->metadata();
  4412     if (tptr == TopPTR || _ptr == TopPTR ||
  4413         metadata()->equals(tp->metadata())) {
  4414       return make(ptr, md, offset);
  4416     // metadata is different
  4417     if( ptr == Constant ) {  // Cannot be equal constants, so...
  4418       if( tptr == Constant && _ptr != Constant)  return t;
  4419       if( _ptr == Constant && tptr != Constant)  return this;
  4420       ptr = NotNull;            // Fall down in lattice
  4422     return make(ptr, NULL, offset);
  4423     break;
  4425   } // End of switch
  4426   return this;                  // Return the double constant
  4430 //------------------------------xdual------------------------------------------
  4431 // Dual of a pure metadata pointer.
  4432 const Type *TypeMetadataPtr::xdual() const {
  4433   return new TypeMetadataPtr(dual_ptr(), metadata(), dual_offset());
  4436 //------------------------------dump2------------------------------------------
  4437 #ifndef PRODUCT
  4438 void TypeMetadataPtr::dump2( Dict &d, uint depth, outputStream *st ) const {
  4439   st->print("metadataptr:%s", ptr_msg[_ptr]);
  4440   if( metadata() ) st->print(INTPTR_FORMAT, metadata());
  4441   switch( _offset ) {
  4442   case OffsetTop: st->print("+top"); break;
  4443   case OffsetBot: st->print("+any"); break;
  4444   case         0: break;
  4445   default:        st->print("+%d",_offset); break;
  4448 #endif
  4451 //=============================================================================
  4452 // Convenience common pre-built type.
  4453 const TypeMetadataPtr *TypeMetadataPtr::BOTTOM;
  4455 TypeMetadataPtr::TypeMetadataPtr(PTR ptr, ciMetadata* metadata, int offset):
  4456   TypePtr(MetadataPtr, ptr, offset), _metadata(metadata) {
  4459 const TypeMetadataPtr* TypeMetadataPtr::make(ciMethod* m) {
  4460   return make(Constant, m, 0);
  4462 const TypeMetadataPtr* TypeMetadataPtr::make(ciMethodData* m) {
  4463   return make(Constant, m, 0);
  4466 //------------------------------make-------------------------------------------
  4467 // Create a meta data constant
  4468 const TypeMetadataPtr *TypeMetadataPtr::make(PTR ptr, ciMetadata* m, int offset) {
  4469   assert(m == NULL || !m->is_klass(), "wrong type");
  4470   return (TypeMetadataPtr*)(new TypeMetadataPtr(ptr, m, offset))->hashcons();
  4474 //=============================================================================
  4475 // Convenience common pre-built types.
  4477 // Not-null object klass or below
  4478 const TypeKlassPtr *TypeKlassPtr::OBJECT;
  4479 const TypeKlassPtr *TypeKlassPtr::OBJECT_OR_NULL;
  4481 //------------------------------TypeKlassPtr-----------------------------------
  4482 TypeKlassPtr::TypeKlassPtr( PTR ptr, ciKlass* klass, int offset )
  4483   : TypePtr(KlassPtr, ptr, offset), _klass(klass), _klass_is_exact(ptr == Constant) {
  4486 //------------------------------make-------------------------------------------
  4487 // ptr to klass 'k', if Constant, or possibly to a sub-klass if not a Constant
  4488 const TypeKlassPtr *TypeKlassPtr::make( PTR ptr, ciKlass* k, int offset ) {
  4489   assert( k != NULL, "Expect a non-NULL klass");
  4490   assert(k->is_instance_klass() || k->is_array_klass(), "Incorrect type of klass oop");
  4491   TypeKlassPtr *r =
  4492     (TypeKlassPtr*)(new TypeKlassPtr(ptr, k, offset))->hashcons();
  4494   return r;
  4497 //------------------------------eq---------------------------------------------
  4498 // Structural equality check for Type representations
  4499 bool TypeKlassPtr::eq( const Type *t ) const {
  4500   const TypeKlassPtr *p = t->is_klassptr();
  4501   return
  4502     klass()->equals(p->klass()) &&
  4503     TypePtr::eq(p);
  4506 //------------------------------hash-------------------------------------------
  4507 // Type-specific hashing function.
  4508 int TypeKlassPtr::hash(void) const {
  4509   return klass()->hash() + TypePtr::hash();
  4512 //------------------------------singleton--------------------------------------
  4513 // TRUE if Type is a singleton type, FALSE otherwise.   Singletons are simple
  4514 // constants
  4515 bool TypeKlassPtr::singleton(void) const {
  4516   // detune optimizer to not generate constant klass + constant offset as a constant!
  4517   // TopPTR, Null, AnyNull, Constant are all singletons
  4518   return (_offset == 0) && !below_centerline(_ptr);
  4521 // Do not allow interface-vs.-noninterface joins to collapse to top.
  4522 const Type *TypeKlassPtr::filter_helper(const Type *kills, bool include_speculative) const {
  4523   // logic here mirrors the one from TypeOopPtr::filter. See comments
  4524   // there.
  4525   const Type* ft = join_helper(kills, include_speculative);
  4526   const TypeKlassPtr* ftkp = ft->isa_klassptr();
  4527   const TypeKlassPtr* ktkp = kills->isa_klassptr();
  4529   if (ft->empty()) {
  4530     if (!empty() && ktkp != NULL && ktkp->klass()->is_loaded() && ktkp->klass()->is_interface())
  4531       return kills;             // Uplift to interface
  4533     return Type::TOP;           // Canonical empty value
  4536   // Interface klass type could be exact in opposite to interface type,
  4537   // return it here instead of incorrect Constant ptr J/L/Object (6894807).
  4538   if (ftkp != NULL && ktkp != NULL &&
  4539       ftkp->is_loaded() &&  ftkp->klass()->is_interface() &&
  4540       !ftkp->klass_is_exact() && // Keep exact interface klass
  4541       ktkp->is_loaded() && !ktkp->klass()->is_interface()) {
  4542     return ktkp->cast_to_ptr_type(ftkp->ptr());
  4545   return ft;
  4548 //----------------------compute_klass------------------------------------------
  4549 // Compute the defining klass for this class
  4550 ciKlass* TypeAryPtr::compute_klass(DEBUG_ONLY(bool verify)) const {
  4551   // Compute _klass based on element type.
  4552   ciKlass* k_ary = NULL;
  4553   const TypeInstPtr *tinst;
  4554   const TypeAryPtr *tary;
  4555   const Type* el = elem();
  4556   if (el->isa_narrowoop()) {
  4557     el = el->make_ptr();
  4560   // Get element klass
  4561   if ((tinst = el->isa_instptr()) != NULL) {
  4562     // Compute array klass from element klass
  4563     k_ary = ciObjArrayKlass::make(tinst->klass());
  4564   } else if ((tary = el->isa_aryptr()) != NULL) {
  4565     // Compute array klass from element klass
  4566     ciKlass* k_elem = tary->klass();
  4567     // If element type is something like bottom[], k_elem will be null.
  4568     if (k_elem != NULL)
  4569       k_ary = ciObjArrayKlass::make(k_elem);
  4570   } else if ((el->base() == Type::Top) ||
  4571              (el->base() == Type::Bottom)) {
  4572     // element type of Bottom occurs from meet of basic type
  4573     // and object; Top occurs when doing join on Bottom.
  4574     // Leave k_ary at NULL.
  4575   } else {
  4576     // Cannot compute array klass directly from basic type,
  4577     // since subtypes of TypeInt all have basic type T_INT.
  4578 #ifdef ASSERT
  4579     if (verify && el->isa_int()) {
  4580       // Check simple cases when verifying klass.
  4581       BasicType bt = T_ILLEGAL;
  4582       if (el == TypeInt::BYTE) {
  4583         bt = T_BYTE;
  4584       } else if (el == TypeInt::SHORT) {
  4585         bt = T_SHORT;
  4586       } else if (el == TypeInt::CHAR) {
  4587         bt = T_CHAR;
  4588       } else if (el == TypeInt::INT) {
  4589         bt = T_INT;
  4590       } else {
  4591         return _klass; // just return specified klass
  4593       return ciTypeArrayKlass::make(bt);
  4595 #endif
  4596     assert(!el->isa_int(),
  4597            "integral arrays must be pre-equipped with a class");
  4598     // Compute array klass directly from basic type
  4599     k_ary = ciTypeArrayKlass::make(el->basic_type());
  4601   return k_ary;
  4604 //------------------------------klass------------------------------------------
  4605 // Return the defining klass for this class
  4606 ciKlass* TypeAryPtr::klass() const {
  4607   if( _klass ) return _klass;   // Return cached value, if possible
  4609   // Oops, need to compute _klass and cache it
  4610   ciKlass* k_ary = compute_klass();
  4612   if( this != TypeAryPtr::OOPS && this->dual() != TypeAryPtr::OOPS ) {
  4613     // The _klass field acts as a cache of the underlying
  4614     // ciKlass for this array type.  In order to set the field,
  4615     // we need to cast away const-ness.
  4616     //
  4617     // IMPORTANT NOTE: we *never* set the _klass field for the
  4618     // type TypeAryPtr::OOPS.  This Type is shared between all
  4619     // active compilations.  However, the ciKlass which represents
  4620     // this Type is *not* shared between compilations, so caching
  4621     // this value would result in fetching a dangling pointer.
  4622     //
  4623     // Recomputing the underlying ciKlass for each request is
  4624     // a bit less efficient than caching, but calls to
  4625     // TypeAryPtr::OOPS->klass() are not common enough to matter.
  4626     ((TypeAryPtr*)this)->_klass = k_ary;
  4627     if (UseCompressedOops && k_ary != NULL && k_ary->is_obj_array_klass() &&
  4628         _offset != 0 && _offset != arrayOopDesc::length_offset_in_bytes()) {
  4629       ((TypeAryPtr*)this)->_is_ptr_to_narrowoop = true;
  4632   return k_ary;
  4636 //------------------------------add_offset-------------------------------------
  4637 // Access internals of klass object
  4638 const TypePtr *TypeKlassPtr::add_offset( intptr_t offset ) const {
  4639   return make( _ptr, klass(), xadd_offset(offset) );
  4642 //------------------------------cast_to_ptr_type-------------------------------
  4643 const Type *TypeKlassPtr::cast_to_ptr_type(PTR ptr) const {
  4644   assert(_base == KlassPtr, "subclass must override cast_to_ptr_type");
  4645   if( ptr == _ptr ) return this;
  4646   return make(ptr, _klass, _offset);
  4650 //-----------------------------cast_to_exactness-------------------------------
  4651 const Type *TypeKlassPtr::cast_to_exactness(bool klass_is_exact) const {
  4652   if( klass_is_exact == _klass_is_exact ) return this;
  4653   if (!UseExactTypes)  return this;
  4654   return make(klass_is_exact ? Constant : NotNull, _klass, _offset);
  4658 //-----------------------------as_instance_type--------------------------------
  4659 // Corresponding type for an instance of the given class.
  4660 // It will be NotNull, and exact if and only if the klass type is exact.
  4661 const TypeOopPtr* TypeKlassPtr::as_instance_type() const {
  4662   ciKlass* k = klass();
  4663   bool    xk = klass_is_exact();
  4664   //return TypeInstPtr::make(TypePtr::NotNull, k, xk, NULL, 0);
  4665   const TypeOopPtr* toop = TypeOopPtr::make_from_klass_raw(k);
  4666   guarantee(toop != NULL, "need type for given klass");
  4667   toop = toop->cast_to_ptr_type(TypePtr::NotNull)->is_oopptr();
  4668   return toop->cast_to_exactness(xk)->is_oopptr();
  4672 //------------------------------xmeet------------------------------------------
  4673 // Compute the MEET of two types, return a new Type object.
  4674 const Type    *TypeKlassPtr::xmeet( const Type *t ) const {
  4675   // Perform a fast test for common case; meeting the same types together.
  4676   if( this == t ) return this;  // Meeting same type-rep?
  4678   // Current "this->_base" is Pointer
  4679   switch (t->base()) {          // switch on original type
  4681   case Int:                     // Mixing ints & oops happens when javac
  4682   case Long:                    // reuses local variables
  4683   case FloatTop:
  4684   case FloatCon:
  4685   case FloatBot:
  4686   case DoubleTop:
  4687   case DoubleCon:
  4688   case DoubleBot:
  4689   case NarrowOop:
  4690   case NarrowKlass:
  4691   case Bottom:                  // Ye Olde Default
  4692     return Type::BOTTOM;
  4693   case Top:
  4694     return this;
  4696   default:                      // All else is a mistake
  4697     typerr(t);
  4699   case AnyPtr: {                // Meeting to AnyPtrs
  4700     // Found an AnyPtr type vs self-KlassPtr type
  4701     const TypePtr *tp = t->is_ptr();
  4702     int offset = meet_offset(tp->offset());
  4703     PTR ptr = meet_ptr(tp->ptr());
  4704     switch (tp->ptr()) {
  4705     case TopPTR:
  4706       return this;
  4707     case Null:
  4708       if( ptr == Null ) return TypePtr::make( AnyPtr, ptr, offset );
  4709     case AnyNull:
  4710       return make( ptr, klass(), offset );
  4711     case BotPTR:
  4712     case NotNull:
  4713       return TypePtr::make(AnyPtr, ptr, offset);
  4714     default: typerr(t);
  4718   case RawPtr:
  4719   case MetadataPtr:
  4720   case OopPtr:
  4721   case AryPtr:                  // Meet with AryPtr
  4722   case InstPtr:                 // Meet with InstPtr
  4723     return TypePtr::BOTTOM;
  4725   //
  4726   //             A-top         }
  4727   //           /   |   \       }  Tops
  4728   //       B-top A-any C-top   }
  4729   //          | /  |  \ |      }  Any-nulls
  4730   //       B-any   |   C-any   }
  4731   //          |    |    |
  4732   //       B-con A-con C-con   } constants; not comparable across classes
  4733   //          |    |    |
  4734   //       B-not   |   C-not   }
  4735   //          | \  |  / |      }  not-nulls
  4736   //       B-bot A-not C-bot   }
  4737   //           \   |   /       }  Bottoms
  4738   //             A-bot         }
  4739   //
  4741   case KlassPtr: {  // Meet two KlassPtr types
  4742     const TypeKlassPtr *tkls = t->is_klassptr();
  4743     int  off     = meet_offset(tkls->offset());
  4744     PTR  ptr     = meet_ptr(tkls->ptr());
  4746     // Check for easy case; klasses are equal (and perhaps not loaded!)
  4747     // If we have constants, then we created oops so classes are loaded
  4748     // and we can handle the constants further down.  This case handles
  4749     // not-loaded classes
  4750     if( ptr != Constant && tkls->klass()->equals(klass()) ) {
  4751       return make( ptr, klass(), off );
  4754     // Classes require inspection in the Java klass hierarchy.  Must be loaded.
  4755     ciKlass* tkls_klass = tkls->klass();
  4756     ciKlass* this_klass = this->klass();
  4757     assert( tkls_klass->is_loaded(), "This class should have been loaded.");
  4758     assert( this_klass->is_loaded(), "This class should have been loaded.");
  4760     // If 'this' type is above the centerline and is a superclass of the
  4761     // other, we can treat 'this' as having the same type as the other.
  4762     if ((above_centerline(this->ptr())) &&
  4763         tkls_klass->is_subtype_of(this_klass)) {
  4764       this_klass = tkls_klass;
  4766     // If 'tinst' type is above the centerline and is a superclass of the
  4767     // other, we can treat 'tinst' as having the same type as the other.
  4768     if ((above_centerline(tkls->ptr())) &&
  4769         this_klass->is_subtype_of(tkls_klass)) {
  4770       tkls_klass = this_klass;
  4773     // Check for classes now being equal
  4774     if (tkls_klass->equals(this_klass)) {
  4775       // If the klasses are equal, the constants may still differ.  Fall to
  4776       // NotNull if they do (neither constant is NULL; that is a special case
  4777       // handled elsewhere).
  4778       if( ptr == Constant ) {
  4779         if (this->_ptr == Constant && tkls->_ptr == Constant &&
  4780             this->klass()->equals(tkls->klass()));
  4781         else if (above_centerline(this->ptr()));
  4782         else if (above_centerline(tkls->ptr()));
  4783         else
  4784           ptr = NotNull;
  4786       return make( ptr, this_klass, off );
  4787     } // Else classes are not equal
  4789     // Since klasses are different, we require the LCA in the Java
  4790     // class hierarchy - which means we have to fall to at least NotNull.
  4791     if( ptr == TopPTR || ptr == AnyNull || ptr == Constant )
  4792       ptr = NotNull;
  4793     // Now we find the LCA of Java classes
  4794     ciKlass* k = this_klass->least_common_ancestor(tkls_klass);
  4795     return   make( ptr, k, off );
  4796   } // End of case KlassPtr
  4798   } // End of switch
  4799   return this;                  // Return the double constant
  4802 //------------------------------xdual------------------------------------------
  4803 // Dual: compute field-by-field dual
  4804 const Type    *TypeKlassPtr::xdual() const {
  4805   return new TypeKlassPtr( dual_ptr(), klass(), dual_offset() );
  4808 //------------------------------get_con----------------------------------------
  4809 intptr_t TypeKlassPtr::get_con() const {
  4810   assert( _ptr == Null || _ptr == Constant, "" );
  4811   assert( _offset >= 0, "" );
  4813   if (_offset != 0) {
  4814     // After being ported to the compiler interface, the compiler no longer
  4815     // directly manipulates the addresses of oops.  Rather, it only has a pointer
  4816     // to a handle at compile time.  This handle is embedded in the generated
  4817     // code and dereferenced at the time the nmethod is made.  Until that time,
  4818     // it is not reasonable to do arithmetic with the addresses of oops (we don't
  4819     // have access to the addresses!).  This does not seem to currently happen,
  4820     // but this assertion here is to help prevent its occurence.
  4821     tty->print_cr("Found oop constant with non-zero offset");
  4822     ShouldNotReachHere();
  4825   return (intptr_t)klass()->constant_encoding();
  4827 //------------------------------dump2------------------------------------------
  4828 // Dump Klass Type
  4829 #ifndef PRODUCT
  4830 void TypeKlassPtr::dump2( Dict & d, uint depth, outputStream *st ) const {
  4831   switch( _ptr ) {
  4832   case Constant:
  4833     st->print("precise ");
  4834   case NotNull:
  4836       const char *name = klass()->name()->as_utf8();
  4837       if( name ) {
  4838         st->print("klass %s: " INTPTR_FORMAT, name, klass());
  4839       } else {
  4840         ShouldNotReachHere();
  4843   case BotPTR:
  4844     if( !WizardMode && !Verbose && !_klass_is_exact ) break;
  4845   case TopPTR:
  4846   case AnyNull:
  4847     st->print(":%s", ptr_msg[_ptr]);
  4848     if( _klass_is_exact ) st->print(":exact");
  4849     break;
  4852   if( _offset ) {               // Dump offset, if any
  4853     if( _offset == OffsetBot )      { st->print("+any"); }
  4854     else if( _offset == OffsetTop ) { st->print("+unknown"); }
  4855     else                            { st->print("+%d", _offset); }
  4858   st->print(" *");
  4860 #endif
  4864 //=============================================================================
  4865 // Convenience common pre-built types.
  4867 //------------------------------make-------------------------------------------
  4868 const TypeFunc *TypeFunc::make( const TypeTuple *domain, const TypeTuple *range ) {
  4869   return (TypeFunc*)(new TypeFunc(domain,range))->hashcons();
  4872 //------------------------------make-------------------------------------------
  4873 const TypeFunc *TypeFunc::make(ciMethod* method) {
  4874   Compile* C = Compile::current();
  4875   const TypeFunc* tf = C->last_tf(method); // check cache
  4876   if (tf != NULL)  return tf;  // The hit rate here is almost 50%.
  4877   const TypeTuple *domain;
  4878   if (method->is_static()) {
  4879     domain = TypeTuple::make_domain(NULL, method->signature());
  4880   } else {
  4881     domain = TypeTuple::make_domain(method->holder(), method->signature());
  4883   const TypeTuple *range  = TypeTuple::make_range(method->signature());
  4884   tf = TypeFunc::make(domain, range);
  4885   C->set_last_tf(method, tf);  // fill cache
  4886   return tf;
  4889 //------------------------------meet-------------------------------------------
  4890 // Compute the MEET of two types.  It returns a new Type object.
  4891 const Type *TypeFunc::xmeet( const Type *t ) const {
  4892   // Perform a fast test for common case; meeting the same types together.
  4893   if( this == t ) return this;  // Meeting same type-rep?
  4895   // Current "this->_base" is Func
  4896   switch (t->base()) {          // switch on original type
  4898   case Bottom:                  // Ye Olde Default
  4899     return t;
  4901   default:                      // All else is a mistake
  4902     typerr(t);
  4904   case Top:
  4905     break;
  4907   return this;                  // Return the double constant
  4910 //------------------------------xdual------------------------------------------
  4911 // Dual: compute field-by-field dual
  4912 const Type *TypeFunc::xdual() const {
  4913   return this;
  4916 //------------------------------eq---------------------------------------------
  4917 // Structural equality check for Type representations
  4918 bool TypeFunc::eq( const Type *t ) const {
  4919   const TypeFunc *a = (const TypeFunc*)t;
  4920   return _domain == a->_domain &&
  4921     _range == a->_range;
  4924 //------------------------------hash-------------------------------------------
  4925 // Type-specific hashing function.
  4926 int TypeFunc::hash(void) const {
  4927   return (intptr_t)_domain + (intptr_t)_range;
  4930 //------------------------------dump2------------------------------------------
  4931 // Dump Function Type
  4932 #ifndef PRODUCT
  4933 void TypeFunc::dump2( Dict &d, uint depth, outputStream *st ) const {
  4934   if( _range->_cnt <= Parms )
  4935     st->print("void");
  4936   else {
  4937     uint i;
  4938     for (i = Parms; i < _range->_cnt-1; i++) {
  4939       _range->field_at(i)->dump2(d,depth,st);
  4940       st->print("/");
  4942     _range->field_at(i)->dump2(d,depth,st);
  4944   st->print(" ");
  4945   st->print("( ");
  4946   if( !depth || d[this] ) {     // Check for recursive dump
  4947     st->print("...)");
  4948     return;
  4950   d.Insert((void*)this,(void*)this);    // Stop recursion
  4951   if (Parms < _domain->_cnt)
  4952     _domain->field_at(Parms)->dump2(d,depth-1,st);
  4953   for (uint i = Parms+1; i < _domain->_cnt; i++) {
  4954     st->print(", ");
  4955     _domain->field_at(i)->dump2(d,depth-1,st);
  4957   st->print(" )");
  4959 #endif
  4961 //------------------------------singleton--------------------------------------
  4962 // TRUE if Type is a singleton type, FALSE otherwise.   Singletons are simple
  4963 // constants (Ldi nodes).  Singletons are integer, float or double constants
  4964 // or a single symbol.
  4965 bool TypeFunc::singleton(void) const {
  4966   return false;                 // Never a singleton
  4969 bool TypeFunc::empty(void) const {
  4970   return false;                 // Never empty
  4974 BasicType TypeFunc::return_type() const{
  4975   if (range()->cnt() == TypeFunc::Parms) {
  4976     return T_VOID;
  4978   return range()->field_at(TypeFunc::Parms)->basic_type();

mercurial