src/share/vm/opto/type.cpp

Tue, 25 Feb 2014 18:16:24 +0100

author
roland
date
Tue, 25 Feb 2014 18:16:24 +0100
changeset 6377
b8413a9cbb84
parent 6375
085b304a1cc5
child 6380
62825ea7e51f
permissions
-rw-r--r--

8031752: Failed speculative optimizations should be reattempted when root of compilation is different
Summary: support for speculative traps that keep track of the root of the compilation in which a trap occurs.
Reviewed-by: kvn, twisti

     1 /*
     2  * Copyright (c) 1997, 2013, 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 // Portions of code courtesy of Clifford Click
    46 // Optimization - Graph Style
    48 // Dictionary of types shared among compilations.
    49 Dict* Type::_shared_type_dict = NULL;
    51 // Array which maps compiler types to Basic Types
    52 Type::TypeInfo Type::_type_info[Type::lastype] = {
    53   { Bad,             T_ILLEGAL,    "bad",           false, Node::NotAMachineReg, relocInfo::none          },  // Bad
    54   { Control,         T_ILLEGAL,    "control",       false, 0,                    relocInfo::none          },  // Control
    55   { Bottom,          T_VOID,       "top",           false, 0,                    relocInfo::none          },  // Top
    56   { Bad,             T_INT,        "int:",          false, Op_RegI,              relocInfo::none          },  // Int
    57   { Bad,             T_LONG,       "long:",         false, Op_RegL,              relocInfo::none          },  // Long
    58   { Half,            T_VOID,       "half",          false, 0,                    relocInfo::none          },  // Half
    59   { Bad,             T_NARROWOOP,  "narrowoop:",    false, Op_RegN,              relocInfo::none          },  // NarrowOop
    60   { Bad,             T_NARROWKLASS,"narrowklass:",  false, Op_RegN,              relocInfo::none          },  // NarrowKlass
    61   { Bad,             T_ILLEGAL,    "tuple:",        false, Node::NotAMachineReg, relocInfo::none          },  // Tuple
    62   { Bad,             T_ARRAY,      "array:",        false, Node::NotAMachineReg, relocInfo::none          },  // Array
    64 #ifndef SPARC
    65   { Bad,             T_ILLEGAL,    "vectors:",      false, Op_VecS,              relocInfo::none          },  // VectorS
    66   { Bad,             T_ILLEGAL,    "vectord:",      false, Op_VecD,              relocInfo::none          },  // VectorD
    67   { Bad,             T_ILLEGAL,    "vectorx:",      false, Op_VecX,              relocInfo::none          },  // VectorX
    68   { Bad,             T_ILLEGAL,    "vectory:",      false, Op_VecY,              relocInfo::none          },  // VectorY
    69 #else
    70   { Bad,             T_ILLEGAL,    "vectors:",      false, 0,                    relocInfo::none          },  // VectorS
    71   { Bad,             T_ILLEGAL,    "vectord:",      false, Op_RegD,              relocInfo::none          },  // VectorD
    72   { Bad,             T_ILLEGAL,    "vectorx:",      false, 0,                    relocInfo::none          },  // VectorX
    73   { Bad,             T_ILLEGAL,    "vectory:",      false, 0,                    relocInfo::none          },  // VectorY
    74 #endif // IA32 || AMD64
    75   { Bad,             T_ADDRESS,    "anyptr:",       false, Op_RegP,              relocInfo::none          },  // AnyPtr
    76   { Bad,             T_ADDRESS,    "rawptr:",       false, Op_RegP,              relocInfo::none          },  // RawPtr
    77   { Bad,             T_OBJECT,     "oop:",          true,  Op_RegP,              relocInfo::oop_type      },  // OopPtr
    78   { Bad,             T_OBJECT,     "inst:",         true,  Op_RegP,              relocInfo::oop_type      },  // InstPtr
    79   { Bad,             T_OBJECT,     "ary:",          true,  Op_RegP,              relocInfo::oop_type      },  // AryPtr
    80   { Bad,             T_METADATA,   "metadata:",     false, Op_RegP,              relocInfo::metadata_type },  // MetadataPtr
    81   { Bad,             T_METADATA,   "klass:",        false, Op_RegP,              relocInfo::metadata_type },  // KlassPtr
    82   { Bad,             T_OBJECT,     "func",          false, 0,                    relocInfo::none          },  // Function
    83   { Abio,            T_ILLEGAL,    "abIO",          false, 0,                    relocInfo::none          },  // Abio
    84   { Return_Address,  T_ADDRESS,    "return_address",false, Op_RegP,              relocInfo::none          },  // Return_Address
    85   { Memory,          T_ILLEGAL,    "memory",        false, 0,                    relocInfo::none          },  // Memory
    86   { FloatBot,        T_FLOAT,      "float_top",     false, Op_RegF,              relocInfo::none          },  // FloatTop
    87   { FloatCon,        T_FLOAT,      "ftcon:",        false, Op_RegF,              relocInfo::none          },  // FloatCon
    88   { FloatTop,        T_FLOAT,      "float",         false, Op_RegF,              relocInfo::none          },  // FloatBot
    89   { DoubleBot,       T_DOUBLE,     "double_top",    false, Op_RegD,              relocInfo::none          },  // DoubleTop
    90   { DoubleCon,       T_DOUBLE,     "dblcon:",       false, Op_RegD,              relocInfo::none          },  // DoubleCon
    91   { DoubleTop,       T_DOUBLE,     "double",        false, Op_RegD,              relocInfo::none          },  // DoubleBot
    92   { Top,             T_ILLEGAL,    "bottom",        false, 0,                    relocInfo::none          }   // Bottom
    93 };
    95 // Map ideal registers (machine types) to ideal types
    96 const Type *Type::mreg2type[_last_machine_leaf];
    98 // Map basic types to canonical Type* pointers.
    99 const Type* Type::     _const_basic_type[T_CONFLICT+1];
   101 // Map basic types to constant-zero Types.
   102 const Type* Type::            _zero_type[T_CONFLICT+1];
   104 // Map basic types to array-body alias types.
   105 const TypeAryPtr* TypeAryPtr::_array_body_type[T_CONFLICT+1];
   107 //=============================================================================
   108 // Convenience common pre-built types.
   109 const Type *Type::ABIO;         // State-of-machine only
   110 const Type *Type::BOTTOM;       // All values
   111 const Type *Type::CONTROL;      // Control only
   112 const Type *Type::DOUBLE;       // All doubles
   113 const Type *Type::FLOAT;        // All floats
   114 const Type *Type::HALF;         // Placeholder half of doublewide type
   115 const Type *Type::MEMORY;       // Abstract store only
   116 const Type *Type::RETURN_ADDRESS;
   117 const Type *Type::TOP;          // No values in set
   119 //------------------------------get_const_type---------------------------
   120 const Type* Type::get_const_type(ciType* type) {
   121   if (type == NULL) {
   122     return NULL;
   123   } else if (type->is_primitive_type()) {
   124     return get_const_basic_type(type->basic_type());
   125   } else {
   126     return TypeOopPtr::make_from_klass(type->as_klass());
   127   }
   128 }
   130 //---------------------------array_element_basic_type---------------------------------
   131 // Mapping to the array element's basic type.
   132 BasicType Type::array_element_basic_type() const {
   133   BasicType bt = basic_type();
   134   if (bt == T_INT) {
   135     if (this == TypeInt::INT)   return T_INT;
   136     if (this == TypeInt::CHAR)  return T_CHAR;
   137     if (this == TypeInt::BYTE)  return T_BYTE;
   138     if (this == TypeInt::BOOL)  return T_BOOLEAN;
   139     if (this == TypeInt::SHORT) return T_SHORT;
   140     return T_VOID;
   141   }
   142   return bt;
   143 }
   145 //---------------------------get_typeflow_type---------------------------------
   146 // Import a type produced by ciTypeFlow.
   147 const Type* Type::get_typeflow_type(ciType* type) {
   148   switch (type->basic_type()) {
   150   case ciTypeFlow::StateVector::T_BOTTOM:
   151     assert(type == ciTypeFlow::StateVector::bottom_type(), "");
   152     return Type::BOTTOM;
   154   case ciTypeFlow::StateVector::T_TOP:
   155     assert(type == ciTypeFlow::StateVector::top_type(), "");
   156     return Type::TOP;
   158   case ciTypeFlow::StateVector::T_NULL:
   159     assert(type == ciTypeFlow::StateVector::null_type(), "");
   160     return TypePtr::NULL_PTR;
   162   case ciTypeFlow::StateVector::T_LONG2:
   163     // The ciTypeFlow pass pushes a long, then the half.
   164     // We do the same.
   165     assert(type == ciTypeFlow::StateVector::long2_type(), "");
   166     return TypeInt::TOP;
   168   case ciTypeFlow::StateVector::T_DOUBLE2:
   169     // The ciTypeFlow pass pushes double, then the half.
   170     // Our convention is the same.
   171     assert(type == ciTypeFlow::StateVector::double2_type(), "");
   172     return Type::TOP;
   174   case T_ADDRESS:
   175     assert(type->is_return_address(), "");
   176     return TypeRawPtr::make((address)(intptr_t)type->as_return_address()->bci());
   178   default:
   179     // make sure we did not mix up the cases:
   180     assert(type != ciTypeFlow::StateVector::bottom_type(), "");
   181     assert(type != ciTypeFlow::StateVector::top_type(), "");
   182     assert(type != ciTypeFlow::StateVector::null_type(), "");
   183     assert(type != ciTypeFlow::StateVector::long2_type(), "");
   184     assert(type != ciTypeFlow::StateVector::double2_type(), "");
   185     assert(!type->is_return_address(), "");
   187     return Type::get_const_type(type);
   188   }
   189 }
   192 //-----------------------make_from_constant------------------------------------
   193 const Type* Type::make_from_constant(ciConstant constant,
   194                                      bool require_constant, bool is_autobox_cache) {
   195   switch (constant.basic_type()) {
   196   case T_BOOLEAN:  return TypeInt::make(constant.as_boolean());
   197   case T_CHAR:     return TypeInt::make(constant.as_char());
   198   case T_BYTE:     return TypeInt::make(constant.as_byte());
   199   case T_SHORT:    return TypeInt::make(constant.as_short());
   200   case T_INT:      return TypeInt::make(constant.as_int());
   201   case T_LONG:     return TypeLong::make(constant.as_long());
   202   case T_FLOAT:    return TypeF::make(constant.as_float());
   203   case T_DOUBLE:   return TypeD::make(constant.as_double());
   204   case T_ARRAY:
   205   case T_OBJECT:
   206     {
   207       // cases:
   208       //   can_be_constant    = (oop not scavengable || ScavengeRootsInCode != 0)
   209       //   should_be_constant = (oop not scavengable || ScavengeRootsInCode >= 2)
   210       // An oop is not scavengable if it is in the perm gen.
   211       ciObject* oop_constant = constant.as_object();
   212       if (oop_constant->is_null_object()) {
   213         return Type::get_zero_type(T_OBJECT);
   214       } else if (require_constant || oop_constant->should_be_constant()) {
   215         return TypeOopPtr::make_from_constant(oop_constant, require_constant, is_autobox_cache);
   216       }
   217     }
   218   }
   219   // Fall through to failure
   220   return NULL;
   221 }
   224 //------------------------------make-------------------------------------------
   225 // Create a simple Type, with default empty symbol sets.  Then hashcons it
   226 // and look for an existing copy in the type dictionary.
   227 const Type *Type::make( enum TYPES t ) {
   228   return (new Type(t))->hashcons();
   229 }
   231 //------------------------------cmp--------------------------------------------
   232 int Type::cmp( const Type *const t1, const Type *const t2 ) {
   233   if( t1->_base != t2->_base )
   234     return 1;                   // Missed badly
   235   assert(t1 != t2 || t1->eq(t2), "eq must be reflexive");
   236   return !t1->eq(t2);           // Return ZERO if equal
   237 }
   239 const Type* Type::maybe_remove_speculative(bool include_speculative) const {
   240   if (!include_speculative) {
   241     return remove_speculative();
   242   }
   243   return this;
   244 }
   246 //------------------------------hash-------------------------------------------
   247 int Type::uhash( const Type *const t ) {
   248   return t->hash();
   249 }
   251 #define SMALLINT ((juint)3)  // a value too insignificant to consider widening
   253 //--------------------------Initialize_shared----------------------------------
   254 void Type::Initialize_shared(Compile* current) {
   255   // This method does not need to be locked because the first system
   256   // compilations (stub compilations) occur serially.  If they are
   257   // changed to proceed in parallel, then this section will need
   258   // locking.
   260   Arena* save = current->type_arena();
   261   Arena* shared_type_arena = new (mtCompiler)Arena();
   263   current->set_type_arena(shared_type_arena);
   264   _shared_type_dict =
   265     new (shared_type_arena) Dict( (CmpKey)Type::cmp, (Hash)Type::uhash,
   266                                   shared_type_arena, 128 );
   267   current->set_type_dict(_shared_type_dict);
   269   // Make shared pre-built types.
   270   CONTROL = make(Control);      // Control only
   271   TOP     = make(Top);          // No values in set
   272   MEMORY  = make(Memory);       // Abstract store only
   273   ABIO    = make(Abio);         // State-of-machine only
   274   RETURN_ADDRESS=make(Return_Address);
   275   FLOAT   = make(FloatBot);     // All floats
   276   DOUBLE  = make(DoubleBot);    // All doubles
   277   BOTTOM  = make(Bottom);       // Everything
   278   HALF    = make(Half);         // Placeholder half of doublewide type
   280   TypeF::ZERO = TypeF::make(0.0); // Float 0 (positive zero)
   281   TypeF::ONE  = TypeF::make(1.0); // Float 1
   283   TypeD::ZERO = TypeD::make(0.0); // Double 0 (positive zero)
   284   TypeD::ONE  = TypeD::make(1.0); // Double 1
   286   TypeInt::MINUS_1 = TypeInt::make(-1);  // -1
   287   TypeInt::ZERO    = TypeInt::make( 0);  //  0
   288   TypeInt::ONE     = TypeInt::make( 1);  //  1
   289   TypeInt::BOOL    = TypeInt::make(0,1,   WidenMin);  // 0 or 1, FALSE or TRUE.
   290   TypeInt::CC      = TypeInt::make(-1, 1, WidenMin);  // -1, 0 or 1, condition codes
   291   TypeInt::CC_LT   = TypeInt::make(-1,-1, WidenMin);  // == TypeInt::MINUS_1
   292   TypeInt::CC_GT   = TypeInt::make( 1, 1, WidenMin);  // == TypeInt::ONE
   293   TypeInt::CC_EQ   = TypeInt::make( 0, 0, WidenMin);  // == TypeInt::ZERO
   294   TypeInt::CC_LE   = TypeInt::make(-1, 0, WidenMin);
   295   TypeInt::CC_GE   = TypeInt::make( 0, 1, WidenMin);  // == TypeInt::BOOL
   296   TypeInt::BYTE    = TypeInt::make(-128,127,     WidenMin); // Bytes
   297   TypeInt::UBYTE   = TypeInt::make(0, 255,       WidenMin); // Unsigned Bytes
   298   TypeInt::CHAR    = TypeInt::make(0,65535,      WidenMin); // Java chars
   299   TypeInt::SHORT   = TypeInt::make(-32768,32767, WidenMin); // Java shorts
   300   TypeInt::POS     = TypeInt::make(0,max_jint,   WidenMin); // Non-neg values
   301   TypeInt::POS1    = TypeInt::make(1,max_jint,   WidenMin); // Positive values
   302   TypeInt::INT     = TypeInt::make(min_jint,max_jint, WidenMax); // 32-bit integers
   303   TypeInt::SYMINT  = TypeInt::make(-max_jint,max_jint,WidenMin); // symmetric range
   304   TypeInt::TYPE_DOMAIN  = TypeInt::INT;
   305   // CmpL is overloaded both as the bytecode computation returning
   306   // a trinary (-1,0,+1) integer result AND as an efficient long
   307   // compare returning optimizer ideal-type flags.
   308   assert( TypeInt::CC_LT == TypeInt::MINUS_1, "types must match for CmpL to work" );
   309   assert( TypeInt::CC_GT == TypeInt::ONE,     "types must match for CmpL to work" );
   310   assert( TypeInt::CC_EQ == TypeInt::ZERO,    "types must match for CmpL to work" );
   311   assert( TypeInt::CC_GE == TypeInt::BOOL,    "types must match for CmpL to work" );
   312   assert( (juint)(TypeInt::CC->_hi - TypeInt::CC->_lo) <= SMALLINT, "CC is truly small");
   314   TypeLong::MINUS_1 = TypeLong::make(-1);        // -1
   315   TypeLong::ZERO    = TypeLong::make( 0);        //  0
   316   TypeLong::ONE     = TypeLong::make( 1);        //  1
   317   TypeLong::POS     = TypeLong::make(0,max_jlong, WidenMin); // Non-neg values
   318   TypeLong::LONG    = TypeLong::make(min_jlong,max_jlong,WidenMax); // 64-bit integers
   319   TypeLong::INT     = TypeLong::make((jlong)min_jint,(jlong)max_jint,WidenMin);
   320   TypeLong::UINT    = TypeLong::make(0,(jlong)max_juint,WidenMin);
   321   TypeLong::TYPE_DOMAIN  = TypeLong::LONG;
   323   const Type **fboth =(const Type**)shared_type_arena->Amalloc_4(2*sizeof(Type*));
   324   fboth[0] = Type::CONTROL;
   325   fboth[1] = Type::CONTROL;
   326   TypeTuple::IFBOTH = TypeTuple::make( 2, fboth );
   328   const Type **ffalse =(const Type**)shared_type_arena->Amalloc_4(2*sizeof(Type*));
   329   ffalse[0] = Type::CONTROL;
   330   ffalse[1] = Type::TOP;
   331   TypeTuple::IFFALSE = TypeTuple::make( 2, ffalse );
   333   const Type **fneither =(const Type**)shared_type_arena->Amalloc_4(2*sizeof(Type*));
   334   fneither[0] = Type::TOP;
   335   fneither[1] = Type::TOP;
   336   TypeTuple::IFNEITHER = TypeTuple::make( 2, fneither );
   338   const Type **ftrue =(const Type**)shared_type_arena->Amalloc_4(2*sizeof(Type*));
   339   ftrue[0] = Type::TOP;
   340   ftrue[1] = Type::CONTROL;
   341   TypeTuple::IFTRUE = TypeTuple::make( 2, ftrue );
   343   const Type **floop =(const Type**)shared_type_arena->Amalloc_4(2*sizeof(Type*));
   344   floop[0] = Type::CONTROL;
   345   floop[1] = TypeInt::INT;
   346   TypeTuple::LOOPBODY = TypeTuple::make( 2, floop );
   348   TypePtr::NULL_PTR= TypePtr::make( AnyPtr, TypePtr::Null, 0 );
   349   TypePtr::NOTNULL = TypePtr::make( AnyPtr, TypePtr::NotNull, OffsetBot );
   350   TypePtr::BOTTOM  = TypePtr::make( AnyPtr, TypePtr::BotPTR, OffsetBot );
   352   TypeRawPtr::BOTTOM = TypeRawPtr::make( TypePtr::BotPTR );
   353   TypeRawPtr::NOTNULL= TypeRawPtr::make( TypePtr::NotNull );
   355   const Type **fmembar = TypeTuple::fields(0);
   356   TypeTuple::MEMBAR = TypeTuple::make(TypeFunc::Parms+0, fmembar);
   358   const Type **fsc = (const Type**)shared_type_arena->Amalloc_4(2*sizeof(Type*));
   359   fsc[0] = TypeInt::CC;
   360   fsc[1] = Type::MEMORY;
   361   TypeTuple::STORECONDITIONAL = TypeTuple::make(2, fsc);
   363   TypeInstPtr::NOTNULL = TypeInstPtr::make(TypePtr::NotNull, current->env()->Object_klass());
   364   TypeInstPtr::BOTTOM  = TypeInstPtr::make(TypePtr::BotPTR,  current->env()->Object_klass());
   365   TypeInstPtr::MIRROR  = TypeInstPtr::make(TypePtr::NotNull, current->env()->Class_klass());
   366   TypeInstPtr::MARK    = TypeInstPtr::make(TypePtr::BotPTR,  current->env()->Object_klass(),
   367                                            false, 0, oopDesc::mark_offset_in_bytes());
   368   TypeInstPtr::KLASS   = TypeInstPtr::make(TypePtr::BotPTR,  current->env()->Object_klass(),
   369                                            false, 0, oopDesc::klass_offset_in_bytes());
   370   TypeOopPtr::BOTTOM  = TypeOopPtr::make(TypePtr::BotPTR, OffsetBot, TypeOopPtr::InstanceBot, NULL);
   372   TypeMetadataPtr::BOTTOM = TypeMetadataPtr::make(TypePtr::BotPTR, NULL, OffsetBot);
   374   TypeNarrowOop::NULL_PTR = TypeNarrowOop::make( TypePtr::NULL_PTR );
   375   TypeNarrowOop::BOTTOM   = TypeNarrowOop::make( TypeInstPtr::BOTTOM );
   377   TypeNarrowKlass::NULL_PTR = TypeNarrowKlass::make( TypePtr::NULL_PTR );
   379   mreg2type[Op_Node] = Type::BOTTOM;
   380   mreg2type[Op_Set ] = 0;
   381   mreg2type[Op_RegN] = TypeNarrowOop::BOTTOM;
   382   mreg2type[Op_RegI] = TypeInt::INT;
   383   mreg2type[Op_RegP] = TypePtr::BOTTOM;
   384   mreg2type[Op_RegF] = Type::FLOAT;
   385   mreg2type[Op_RegD] = Type::DOUBLE;
   386   mreg2type[Op_RegL] = TypeLong::LONG;
   387   mreg2type[Op_RegFlags] = TypeInt::CC;
   389   TypeAryPtr::RANGE   = TypeAryPtr::make( TypePtr::BotPTR, TypeAry::make(Type::BOTTOM,TypeInt::POS), NULL /* current->env()->Object_klass() */, false, arrayOopDesc::length_offset_in_bytes());
   391   TypeAryPtr::NARROWOOPS = TypeAryPtr::make(TypePtr::BotPTR, TypeAry::make(TypeNarrowOop::BOTTOM, TypeInt::POS), NULL /*ciArrayKlass::make(o)*/,  false,  Type::OffsetBot);
   393 #ifdef _LP64
   394   if (UseCompressedOops) {
   395     assert(TypeAryPtr::NARROWOOPS->is_ptr_to_narrowoop(), "array of narrow oops must be ptr to narrow oop");
   396     TypeAryPtr::OOPS  = TypeAryPtr::NARROWOOPS;
   397   } else
   398 #endif
   399   {
   400     // There is no shared klass for Object[].  See note in TypeAryPtr::klass().
   401     TypeAryPtr::OOPS  = TypeAryPtr::make(TypePtr::BotPTR, TypeAry::make(TypeInstPtr::BOTTOM,TypeInt::POS), NULL /*ciArrayKlass::make(o)*/,  false,  Type::OffsetBot);
   402   }
   403   TypeAryPtr::BYTES   = TypeAryPtr::make(TypePtr::BotPTR, TypeAry::make(TypeInt::BYTE      ,TypeInt::POS), ciTypeArrayKlass::make(T_BYTE),   true,  Type::OffsetBot);
   404   TypeAryPtr::SHORTS  = TypeAryPtr::make(TypePtr::BotPTR, TypeAry::make(TypeInt::SHORT     ,TypeInt::POS), ciTypeArrayKlass::make(T_SHORT),  true,  Type::OffsetBot);
   405   TypeAryPtr::CHARS   = TypeAryPtr::make(TypePtr::BotPTR, TypeAry::make(TypeInt::CHAR      ,TypeInt::POS), ciTypeArrayKlass::make(T_CHAR),   true,  Type::OffsetBot);
   406   TypeAryPtr::INTS    = TypeAryPtr::make(TypePtr::BotPTR, TypeAry::make(TypeInt::INT       ,TypeInt::POS), ciTypeArrayKlass::make(T_INT),    true,  Type::OffsetBot);
   407   TypeAryPtr::LONGS   = TypeAryPtr::make(TypePtr::BotPTR, TypeAry::make(TypeLong::LONG     ,TypeInt::POS), ciTypeArrayKlass::make(T_LONG),   true,  Type::OffsetBot);
   408   TypeAryPtr::FLOATS  = TypeAryPtr::make(TypePtr::BotPTR, TypeAry::make(Type::FLOAT        ,TypeInt::POS), ciTypeArrayKlass::make(T_FLOAT),  true,  Type::OffsetBot);
   409   TypeAryPtr::DOUBLES = TypeAryPtr::make(TypePtr::BotPTR, TypeAry::make(Type::DOUBLE       ,TypeInt::POS), ciTypeArrayKlass::make(T_DOUBLE), true,  Type::OffsetBot);
   411   // Nobody should ask _array_body_type[T_NARROWOOP]. Use NULL as assert.
   412   TypeAryPtr::_array_body_type[T_NARROWOOP] = NULL;
   413   TypeAryPtr::_array_body_type[T_OBJECT]  = TypeAryPtr::OOPS;
   414   TypeAryPtr::_array_body_type[T_ARRAY]   = TypeAryPtr::OOPS; // arrays are stored in oop arrays
   415   TypeAryPtr::_array_body_type[T_BYTE]    = TypeAryPtr::BYTES;
   416   TypeAryPtr::_array_body_type[T_BOOLEAN] = TypeAryPtr::BYTES;  // boolean[] is a byte array
   417   TypeAryPtr::_array_body_type[T_SHORT]   = TypeAryPtr::SHORTS;
   418   TypeAryPtr::_array_body_type[T_CHAR]    = TypeAryPtr::CHARS;
   419   TypeAryPtr::_array_body_type[T_INT]     = TypeAryPtr::INTS;
   420   TypeAryPtr::_array_body_type[T_LONG]    = TypeAryPtr::LONGS;
   421   TypeAryPtr::_array_body_type[T_FLOAT]   = TypeAryPtr::FLOATS;
   422   TypeAryPtr::_array_body_type[T_DOUBLE]  = TypeAryPtr::DOUBLES;
   424   TypeKlassPtr::OBJECT = TypeKlassPtr::make( TypePtr::NotNull, current->env()->Object_klass(), 0 );
   425   TypeKlassPtr::OBJECT_OR_NULL = TypeKlassPtr::make( TypePtr::BotPTR, current->env()->Object_klass(), 0 );
   427   const Type **fi2c = TypeTuple::fields(2);
   428   fi2c[TypeFunc::Parms+0] = TypeInstPtr::BOTTOM; // Method*
   429   fi2c[TypeFunc::Parms+1] = TypeRawPtr::BOTTOM; // argument pointer
   430   TypeTuple::START_I2C = TypeTuple::make(TypeFunc::Parms+2, fi2c);
   432   const Type **intpair = TypeTuple::fields(2);
   433   intpair[0] = TypeInt::INT;
   434   intpair[1] = TypeInt::INT;
   435   TypeTuple::INT_PAIR = TypeTuple::make(2, intpair);
   437   const Type **longpair = TypeTuple::fields(2);
   438   longpair[0] = TypeLong::LONG;
   439   longpair[1] = TypeLong::LONG;
   440   TypeTuple::LONG_PAIR = TypeTuple::make(2, longpair);
   442   const Type **intccpair = TypeTuple::fields(2);
   443   intccpair[0] = TypeInt::INT;
   444   intccpair[1] = TypeInt::CC;
   445   TypeTuple::INT_CC_PAIR = TypeTuple::make(2, intccpair);
   447   const Type **longccpair = TypeTuple::fields(2);
   448   longccpair[0] = TypeLong::LONG;
   449   longccpair[1] = TypeInt::CC;
   450   TypeTuple::LONG_CC_PAIR = TypeTuple::make(2, longccpair);
   452   _const_basic_type[T_NARROWOOP]   = TypeNarrowOop::BOTTOM;
   453   _const_basic_type[T_NARROWKLASS] = Type::BOTTOM;
   454   _const_basic_type[T_BOOLEAN]     = TypeInt::BOOL;
   455   _const_basic_type[T_CHAR]        = TypeInt::CHAR;
   456   _const_basic_type[T_BYTE]        = TypeInt::BYTE;
   457   _const_basic_type[T_SHORT]       = TypeInt::SHORT;
   458   _const_basic_type[T_INT]         = TypeInt::INT;
   459   _const_basic_type[T_LONG]        = TypeLong::LONG;
   460   _const_basic_type[T_FLOAT]       = Type::FLOAT;
   461   _const_basic_type[T_DOUBLE]      = Type::DOUBLE;
   462   _const_basic_type[T_OBJECT]      = TypeInstPtr::BOTTOM;
   463   _const_basic_type[T_ARRAY]       = TypeInstPtr::BOTTOM; // there is no separate bottom for arrays
   464   _const_basic_type[T_VOID]        = TypePtr::NULL_PTR;   // reflection represents void this way
   465   _const_basic_type[T_ADDRESS]     = TypeRawPtr::BOTTOM;  // both interpreter return addresses & random raw ptrs
   466   _const_basic_type[T_CONFLICT]    = Type::BOTTOM;        // why not?
   468   _zero_type[T_NARROWOOP]   = TypeNarrowOop::NULL_PTR;
   469   _zero_type[T_NARROWKLASS] = TypeNarrowKlass::NULL_PTR;
   470   _zero_type[T_BOOLEAN]     = TypeInt::ZERO;     // false == 0
   471   _zero_type[T_CHAR]        = TypeInt::ZERO;     // '\0' == 0
   472   _zero_type[T_BYTE]        = TypeInt::ZERO;     // 0x00 == 0
   473   _zero_type[T_SHORT]       = TypeInt::ZERO;     // 0x0000 == 0
   474   _zero_type[T_INT]         = TypeInt::ZERO;
   475   _zero_type[T_LONG]        = TypeLong::ZERO;
   476   _zero_type[T_FLOAT]       = TypeF::ZERO;
   477   _zero_type[T_DOUBLE]      = TypeD::ZERO;
   478   _zero_type[T_OBJECT]      = TypePtr::NULL_PTR;
   479   _zero_type[T_ARRAY]       = TypePtr::NULL_PTR; // null array is null oop
   480   _zero_type[T_ADDRESS]     = TypePtr::NULL_PTR; // raw pointers use the same null
   481   _zero_type[T_VOID]        = Type::TOP;         // the only void value is no value at all
   483   // get_zero_type() should not happen for T_CONFLICT
   484   _zero_type[T_CONFLICT]= NULL;
   486   // Vector predefined types, it needs initialized _const_basic_type[].
   487   if (Matcher::vector_size_supported(T_BYTE,4)) {
   488     TypeVect::VECTS = TypeVect::make(T_BYTE,4);
   489   }
   490   if (Matcher::vector_size_supported(T_FLOAT,2)) {
   491     TypeVect::VECTD = TypeVect::make(T_FLOAT,2);
   492   }
   493   if (Matcher::vector_size_supported(T_FLOAT,4)) {
   494     TypeVect::VECTX = TypeVect::make(T_FLOAT,4);
   495   }
   496   if (Matcher::vector_size_supported(T_FLOAT,8)) {
   497     TypeVect::VECTY = TypeVect::make(T_FLOAT,8);
   498   }
   499   mreg2type[Op_VecS] = TypeVect::VECTS;
   500   mreg2type[Op_VecD] = TypeVect::VECTD;
   501   mreg2type[Op_VecX] = TypeVect::VECTX;
   502   mreg2type[Op_VecY] = TypeVect::VECTY;
   504   // Restore working type arena.
   505   current->set_type_arena(save);
   506   current->set_type_dict(NULL);
   507 }
   509 //------------------------------Initialize-------------------------------------
   510 void Type::Initialize(Compile* current) {
   511   assert(current->type_arena() != NULL, "must have created type arena");
   513   if (_shared_type_dict == NULL) {
   514     Initialize_shared(current);
   515   }
   517   Arena* type_arena = current->type_arena();
   519   // Create the hash-cons'ing dictionary with top-level storage allocation
   520   Dict *tdic = new (type_arena) Dict( (CmpKey)Type::cmp,(Hash)Type::uhash, type_arena, 128 );
   521   current->set_type_dict(tdic);
   523   // Transfer the shared types.
   524   DictI i(_shared_type_dict);
   525   for( ; i.test(); ++i ) {
   526     Type* t = (Type*)i._value;
   527     tdic->Insert(t,t);  // New Type, insert into Type table
   528   }
   529 }
   531 //------------------------------hashcons---------------------------------------
   532 // Do the hash-cons trick.  If the Type already exists in the type table,
   533 // delete the current Type and return the existing Type.  Otherwise stick the
   534 // current Type in the Type table.
   535 const Type *Type::hashcons(void) {
   536   debug_only(base());           // Check the assertion in Type::base().
   537   // Look up the Type in the Type dictionary
   538   Dict *tdic = type_dict();
   539   Type* old = (Type*)(tdic->Insert(this, this, false));
   540   if( old ) {                   // Pre-existing Type?
   541     if( old != this )           // Yes, this guy is not the pre-existing?
   542       delete this;              // Yes, Nuke this guy
   543     assert( old->_dual, "" );
   544     return old;                 // Return pre-existing
   545   }
   547   // Every type has a dual (to make my lattice symmetric).
   548   // Since we just discovered a new Type, compute its dual right now.
   549   assert( !_dual, "" );         // No dual yet
   550   _dual = xdual();              // Compute the dual
   551   if( cmp(this,_dual)==0 ) {    // Handle self-symmetric
   552     _dual = this;
   553     return this;
   554   }
   555   assert( !_dual->_dual, "" );  // No reverse dual yet
   556   assert( !(*tdic)[_dual], "" ); // Dual not in type system either
   557   // New Type, insert into Type table
   558   tdic->Insert((void*)_dual,(void*)_dual);
   559   ((Type*)_dual)->_dual = this; // Finish up being symmetric
   560 #ifdef ASSERT
   561   Type *dual_dual = (Type*)_dual->xdual();
   562   assert( eq(dual_dual), "xdual(xdual()) should be identity" );
   563   delete dual_dual;
   564 #endif
   565   return this;                  // Return new Type
   566 }
   568 //------------------------------eq---------------------------------------------
   569 // Structural equality check for Type representations
   570 bool Type::eq( const Type * ) const {
   571   return true;                  // Nothing else can go wrong
   572 }
   574 //------------------------------hash-------------------------------------------
   575 // Type-specific hashing function.
   576 int Type::hash(void) const {
   577   return _base;
   578 }
   580 //------------------------------is_finite--------------------------------------
   581 // Has a finite value
   582 bool Type::is_finite() const {
   583   return false;
   584 }
   586 //------------------------------is_nan-----------------------------------------
   587 // Is not a number (NaN)
   588 bool Type::is_nan()    const {
   589   return false;
   590 }
   592 //----------------------interface_vs_oop---------------------------------------
   593 #ifdef ASSERT
   594 bool Type::interface_vs_oop_helper(const Type *t) const {
   595   bool result = false;
   597   const TypePtr* this_ptr = this->make_ptr(); // In case it is narrow_oop
   598   const TypePtr*    t_ptr =    t->make_ptr();
   599   if( this_ptr == NULL || t_ptr == NULL )
   600     return result;
   602   const TypeInstPtr* this_inst = this_ptr->isa_instptr();
   603   const TypeInstPtr*    t_inst =    t_ptr->isa_instptr();
   604   if( this_inst && this_inst->is_loaded() && t_inst && t_inst->is_loaded() ) {
   605     bool this_interface = this_inst->klass()->is_interface();
   606     bool    t_interface =    t_inst->klass()->is_interface();
   607     result = this_interface ^ t_interface;
   608   }
   610   return result;
   611 }
   613 bool Type::interface_vs_oop(const Type *t) const {
   614   if (interface_vs_oop_helper(t)) {
   615     return true;
   616   }
   617   // Now check the speculative parts as well
   618   const TypeOopPtr* this_spec = isa_oopptr() != NULL ? isa_oopptr()->speculative() : NULL;
   619   const TypeOopPtr* t_spec = t->isa_oopptr() != NULL ? t->isa_oopptr()->speculative() : NULL;
   620   if (this_spec != NULL && t_spec != NULL) {
   621     if (this_spec->interface_vs_oop_helper(t_spec)) {
   622       return true;
   623     }
   624     return false;
   625   }
   626   if (this_spec != NULL && this_spec->interface_vs_oop_helper(t)) {
   627     return true;
   628   }
   629   if (t_spec != NULL && interface_vs_oop_helper(t_spec)) {
   630     return true;
   631   }
   632   return false;
   633 }
   635 #endif
   637 //------------------------------meet-------------------------------------------
   638 // Compute the MEET of two types.  NOT virtual.  It enforces that meet is
   639 // commutative and the lattice is symmetric.
   640 const Type *Type::meet_helper(const Type *t, bool include_speculative) const {
   641   if (isa_narrowoop() && t->isa_narrowoop()) {
   642     const Type* result = make_ptr()->meet_helper(t->make_ptr(), include_speculative);
   643     return result->make_narrowoop();
   644   }
   645   if (isa_narrowklass() && t->isa_narrowklass()) {
   646     const Type* result = make_ptr()->meet_helper(t->make_ptr(), include_speculative);
   647     return result->make_narrowklass();
   648   }
   650   const Type *this_t = maybe_remove_speculative(include_speculative);
   651   t = t->maybe_remove_speculative(include_speculative);
   653   const Type *mt = this_t->xmeet(t);
   654   if (isa_narrowoop() || t->isa_narrowoop()) return mt;
   655   if (isa_narrowklass() || t->isa_narrowklass()) return mt;
   656 #ifdef ASSERT
   657   assert(mt == t->xmeet(this_t), "meet not commutative");
   658   const Type* dual_join = mt->_dual;
   659   const Type *t2t    = dual_join->xmeet(t->_dual);
   660   const Type *t2this = dual_join->xmeet(this_t->_dual);
   662   // Interface meet Oop is Not Symmetric:
   663   // Interface:AnyNull meet Oop:AnyNull == Interface:AnyNull
   664   // Interface:NotNull meet Oop:NotNull == java/lang/Object:NotNull
   666   if( !interface_vs_oop(t) && (t2t != t->_dual || t2this != this_t->_dual) ) {
   667     tty->print_cr("=== Meet Not Symmetric ===");
   668     tty->print("t   =                   ");              t->dump(); tty->cr();
   669     tty->print("this=                   ");         this_t->dump(); tty->cr();
   670     tty->print("mt=(t meet this)=       ");             mt->dump(); tty->cr();
   672     tty->print("t_dual=                 ");       t->_dual->dump(); tty->cr();
   673     tty->print("this_dual=              ");  this_t->_dual->dump(); tty->cr();
   674     tty->print("mt_dual=                ");      mt->_dual->dump(); tty->cr();
   676     tty->print("mt_dual meet t_dual=    "); t2t           ->dump(); tty->cr();
   677     tty->print("mt_dual meet this_dual= "); t2this        ->dump(); tty->cr();
   679     fatal("meet not symmetric" );
   680   }
   681 #endif
   682   return mt;
   683 }
   685 //------------------------------xmeet------------------------------------------
   686 // Compute the MEET of two types.  It returns a new Type object.
   687 const Type *Type::xmeet( const Type *t ) const {
   688   // Perform a fast test for common case; meeting the same types together.
   689   if( this == t ) return this;  // Meeting same type-rep?
   691   // Meeting TOP with anything?
   692   if( _base == Top ) return t;
   694   // Meeting BOTTOM with anything?
   695   if( _base == Bottom ) return BOTTOM;
   697   // Current "this->_base" is one of: Bad, Multi, Control, Top,
   698   // Abio, Abstore, Floatxxx, Doublexxx, Bottom, lastype.
   699   switch (t->base()) {  // Switch on original type
   701   // Cut in half the number of cases I must handle.  Only need cases for when
   702   // the given enum "t->type" is less than or equal to the local enum "type".
   703   case FloatCon:
   704   case DoubleCon:
   705   case Int:
   706   case Long:
   707     return t->xmeet(this);
   709   case OopPtr:
   710     return t->xmeet(this);
   712   case InstPtr:
   713     return t->xmeet(this);
   715   case MetadataPtr:
   716   case KlassPtr:
   717     return t->xmeet(this);
   719   case AryPtr:
   720     return t->xmeet(this);
   722   case NarrowOop:
   723     return t->xmeet(this);
   725   case NarrowKlass:
   726     return t->xmeet(this);
   728   case Bad:                     // Type check
   729   default:                      // Bogus type not in lattice
   730     typerr(t);
   731     return Type::BOTTOM;
   733   case Bottom:                  // Ye Olde Default
   734     return t;
   736   case FloatTop:
   737     if( _base == FloatTop ) return this;
   738   case FloatBot:                // Float
   739     if( _base == FloatBot || _base == FloatTop ) return FLOAT;
   740     if( _base == DoubleTop || _base == DoubleBot ) return Type::BOTTOM;
   741     typerr(t);
   742     return Type::BOTTOM;
   744   case DoubleTop:
   745     if( _base == DoubleTop ) return this;
   746   case DoubleBot:               // Double
   747     if( _base == DoubleBot || _base == DoubleTop ) return DOUBLE;
   748     if( _base == FloatTop || _base == FloatBot ) return Type::BOTTOM;
   749     typerr(t);
   750     return Type::BOTTOM;
   752   // These next few cases must match exactly or it is a compile-time error.
   753   case Control:                 // Control of code
   754   case Abio:                    // State of world outside of program
   755   case Memory:
   756     if( _base == t->_base )  return this;
   757     typerr(t);
   758     return Type::BOTTOM;
   760   case Top:                     // Top of the lattice
   761     return this;
   762   }
   764   // The type is unchanged
   765   return this;
   766 }
   768 //-----------------------------filter------------------------------------------
   769 const Type *Type::filter_helper(const Type *kills, bool include_speculative) const {
   770   const Type* ft = join_helper(kills, include_speculative);
   771   if (ft->empty())
   772     return Type::TOP;           // Canonical empty value
   773   return ft;
   774 }
   776 //------------------------------xdual------------------------------------------
   777 // Compute dual right now.
   778 const Type::TYPES Type::dual_type[Type::lastype] = {
   779   Bad,          // Bad
   780   Control,      // Control
   781   Bottom,       // Top
   782   Bad,          // Int - handled in v-call
   783   Bad,          // Long - handled in v-call
   784   Half,         // Half
   785   Bad,          // NarrowOop - handled in v-call
   786   Bad,          // NarrowKlass - handled in v-call
   788   Bad,          // Tuple - handled in v-call
   789   Bad,          // Array - handled in v-call
   790   Bad,          // VectorS - handled in v-call
   791   Bad,          // VectorD - handled in v-call
   792   Bad,          // VectorX - handled in v-call
   793   Bad,          // VectorY - handled in v-call
   795   Bad,          // AnyPtr - handled in v-call
   796   Bad,          // RawPtr - handled in v-call
   797   Bad,          // OopPtr - handled in v-call
   798   Bad,          // InstPtr - handled in v-call
   799   Bad,          // AryPtr - handled in v-call
   801   Bad,          //  MetadataPtr - handled in v-call
   802   Bad,          // KlassPtr - handled in v-call
   804   Bad,          // Function - handled in v-call
   805   Abio,         // Abio
   806   Return_Address,// Return_Address
   807   Memory,       // Memory
   808   FloatBot,     // FloatTop
   809   FloatCon,     // FloatCon
   810   FloatTop,     // FloatBot
   811   DoubleBot,    // DoubleTop
   812   DoubleCon,    // DoubleCon
   813   DoubleTop,    // DoubleBot
   814   Top           // Bottom
   815 };
   817 const Type *Type::xdual() const {
   818   // Note: the base() accessor asserts the sanity of _base.
   819   assert(_type_info[base()].dual_type != Bad, "implement with v-call");
   820   return new Type(_type_info[_base].dual_type);
   821 }
   823 //------------------------------has_memory-------------------------------------
   824 bool Type::has_memory() const {
   825   Type::TYPES tx = base();
   826   if (tx == Memory) return true;
   827   if (tx == Tuple) {
   828     const TypeTuple *t = is_tuple();
   829     for (uint i=0; i < t->cnt(); i++) {
   830       tx = t->field_at(i)->base();
   831       if (tx == Memory)  return true;
   832     }
   833   }
   834   return false;
   835 }
   837 #ifndef PRODUCT
   838 //------------------------------dump2------------------------------------------
   839 void Type::dump2( Dict &d, uint depth, outputStream *st ) const {
   840   st->print(_type_info[_base].msg);
   841 }
   843 //------------------------------dump-------------------------------------------
   844 void Type::dump_on(outputStream *st) const {
   845   ResourceMark rm;
   846   Dict d(cmpkey,hashkey);       // Stop recursive type dumping
   847   dump2(d,1, st);
   848   if (is_ptr_to_narrowoop()) {
   849     st->print(" [narrow]");
   850   } else if (is_ptr_to_narrowklass()) {
   851     st->print(" [narrowklass]");
   852   }
   853 }
   854 #endif
   856 //------------------------------singleton--------------------------------------
   857 // TRUE if Type is a singleton type, FALSE otherwise.   Singletons are simple
   858 // constants (Ldi nodes).  Singletons are integer, float or double constants.
   859 bool Type::singleton(void) const {
   860   return _base == Top || _base == Half;
   861 }
   863 //------------------------------empty------------------------------------------
   864 // TRUE if Type is a type with no values, FALSE otherwise.
   865 bool Type::empty(void) const {
   866   switch (_base) {
   867   case DoubleTop:
   868   case FloatTop:
   869   case Top:
   870     return true;
   872   case Half:
   873   case Abio:
   874   case Return_Address:
   875   case Memory:
   876   case Bottom:
   877   case FloatBot:
   878   case DoubleBot:
   879     return false;  // never a singleton, therefore never empty
   880   }
   882   ShouldNotReachHere();
   883   return false;
   884 }
   886 //------------------------------dump_stats-------------------------------------
   887 // Dump collected statistics to stderr
   888 #ifndef PRODUCT
   889 void Type::dump_stats() {
   890   tty->print("Types made: %d\n", type_dict()->Size());
   891 }
   892 #endif
   894 //------------------------------typerr-----------------------------------------
   895 void Type::typerr( const Type *t ) const {
   896 #ifndef PRODUCT
   897   tty->print("\nError mixing types: ");
   898   dump();
   899   tty->print(" and ");
   900   t->dump();
   901   tty->print("\n");
   902 #endif
   903   ShouldNotReachHere();
   904 }
   907 //=============================================================================
   908 // Convenience common pre-built types.
   909 const TypeF *TypeF::ZERO;       // Floating point zero
   910 const TypeF *TypeF::ONE;        // Floating point one
   912 //------------------------------make-------------------------------------------
   913 // Create a float constant
   914 const TypeF *TypeF::make(float f) {
   915   return (TypeF*)(new TypeF(f))->hashcons();
   916 }
   918 //------------------------------meet-------------------------------------------
   919 // Compute the MEET of two types.  It returns a new Type object.
   920 const Type *TypeF::xmeet( const Type *t ) const {
   921   // Perform a fast test for common case; meeting the same types together.
   922   if( this == t ) return this;  // Meeting same type-rep?
   924   // Current "this->_base" is FloatCon
   925   switch (t->base()) {          // Switch on original type
   926   case AnyPtr:                  // Mixing with oops happens when javac
   927   case RawPtr:                  // reuses local variables
   928   case OopPtr:
   929   case InstPtr:
   930   case AryPtr:
   931   case MetadataPtr:
   932   case KlassPtr:
   933   case NarrowOop:
   934   case NarrowKlass:
   935   case Int:
   936   case Long:
   937   case DoubleTop:
   938   case DoubleCon:
   939   case DoubleBot:
   940   case Bottom:                  // Ye Olde Default
   941     return Type::BOTTOM;
   943   case FloatBot:
   944     return t;
   946   default:                      // All else is a mistake
   947     typerr(t);
   949   case FloatCon:                // Float-constant vs Float-constant?
   950     if( jint_cast(_f) != jint_cast(t->getf()) )         // unequal constants?
   951                                 // must compare bitwise as positive zero, negative zero and NaN have
   952                                 // all the same representation in C++
   953       return FLOAT;             // Return generic float
   954                                 // Equal constants
   955   case Top:
   956   case FloatTop:
   957     break;                      // Return the float constant
   958   }
   959   return this;                  // Return the float constant
   960 }
   962 //------------------------------xdual------------------------------------------
   963 // Dual: symmetric
   964 const Type *TypeF::xdual() const {
   965   return this;
   966 }
   968 //------------------------------eq---------------------------------------------
   969 // Structural equality check for Type representations
   970 bool TypeF::eq( const Type *t ) const {
   971   if( g_isnan(_f) ||
   972       g_isnan(t->getf()) ) {
   973     // One or both are NANs.  If both are NANs return true, else false.
   974     return (g_isnan(_f) && g_isnan(t->getf()));
   975   }
   976   if (_f == t->getf()) {
   977     // (NaN is impossible at this point, since it is not equal even to itself)
   978     if (_f == 0.0) {
   979       // difference between positive and negative zero
   980       if (jint_cast(_f) != jint_cast(t->getf()))  return false;
   981     }
   982     return true;
   983   }
   984   return false;
   985 }
   987 //------------------------------hash-------------------------------------------
   988 // Type-specific hashing function.
   989 int TypeF::hash(void) const {
   990   return *(int*)(&_f);
   991 }
   993 //------------------------------is_finite--------------------------------------
   994 // Has a finite value
   995 bool TypeF::is_finite() const {
   996   return g_isfinite(getf()) != 0;
   997 }
   999 //------------------------------is_nan-----------------------------------------
  1000 // Is not a number (NaN)
  1001 bool TypeF::is_nan()    const {
  1002   return g_isnan(getf()) != 0;
  1005 //------------------------------dump2------------------------------------------
  1006 // Dump float constant Type
  1007 #ifndef PRODUCT
  1008 void TypeF::dump2( Dict &d, uint depth, outputStream *st ) const {
  1009   Type::dump2(d,depth, st);
  1010   st->print("%f", _f);
  1012 #endif
  1014 //------------------------------singleton--------------------------------------
  1015 // TRUE if Type is a singleton type, FALSE otherwise.   Singletons are simple
  1016 // constants (Ldi nodes).  Singletons are integer, float or double constants
  1017 // or a single symbol.
  1018 bool TypeF::singleton(void) const {
  1019   return true;                  // Always a singleton
  1022 bool TypeF::empty(void) const {
  1023   return false;                 // always exactly a singleton
  1026 //=============================================================================
  1027 // Convenience common pre-built types.
  1028 const TypeD *TypeD::ZERO;       // Floating point zero
  1029 const TypeD *TypeD::ONE;        // Floating point one
  1031 //------------------------------make-------------------------------------------
  1032 const TypeD *TypeD::make(double d) {
  1033   return (TypeD*)(new TypeD(d))->hashcons();
  1036 //------------------------------meet-------------------------------------------
  1037 // Compute the MEET of two types.  It returns a new Type object.
  1038 const Type *TypeD::xmeet( const Type *t ) const {
  1039   // Perform a fast test for common case; meeting the same types together.
  1040   if( this == t ) return this;  // Meeting same type-rep?
  1042   // Current "this->_base" is DoubleCon
  1043   switch (t->base()) {          // Switch on original type
  1044   case AnyPtr:                  // Mixing with oops happens when javac
  1045   case RawPtr:                  // reuses local variables
  1046   case OopPtr:
  1047   case InstPtr:
  1048   case AryPtr:
  1049   case MetadataPtr:
  1050   case KlassPtr:
  1051   case NarrowOop:
  1052   case NarrowKlass:
  1053   case Int:
  1054   case Long:
  1055   case FloatTop:
  1056   case FloatCon:
  1057   case FloatBot:
  1058   case Bottom:                  // Ye Olde Default
  1059     return Type::BOTTOM;
  1061   case DoubleBot:
  1062     return t;
  1064   default:                      // All else is a mistake
  1065     typerr(t);
  1067   case DoubleCon:               // Double-constant vs Double-constant?
  1068     if( jlong_cast(_d) != jlong_cast(t->getd()) )       // unequal constants? (see comment in TypeF::xmeet)
  1069       return DOUBLE;            // Return generic double
  1070   case Top:
  1071   case DoubleTop:
  1072     break;
  1074   return this;                  // Return the double constant
  1077 //------------------------------xdual------------------------------------------
  1078 // Dual: symmetric
  1079 const Type *TypeD::xdual() const {
  1080   return this;
  1083 //------------------------------eq---------------------------------------------
  1084 // Structural equality check for Type representations
  1085 bool TypeD::eq( const Type *t ) const {
  1086   if( g_isnan(_d) ||
  1087       g_isnan(t->getd()) ) {
  1088     // One or both are NANs.  If both are NANs return true, else false.
  1089     return (g_isnan(_d) && g_isnan(t->getd()));
  1091   if (_d == t->getd()) {
  1092     // (NaN is impossible at this point, since it is not equal even to itself)
  1093     if (_d == 0.0) {
  1094       // difference between positive and negative zero
  1095       if (jlong_cast(_d) != jlong_cast(t->getd()))  return false;
  1097     return true;
  1099   return false;
  1102 //------------------------------hash-------------------------------------------
  1103 // Type-specific hashing function.
  1104 int TypeD::hash(void) const {
  1105   return *(int*)(&_d);
  1108 //------------------------------is_finite--------------------------------------
  1109 // Has a finite value
  1110 bool TypeD::is_finite() const {
  1111   return g_isfinite(getd()) != 0;
  1114 //------------------------------is_nan-----------------------------------------
  1115 // Is not a number (NaN)
  1116 bool TypeD::is_nan()    const {
  1117   return g_isnan(getd()) != 0;
  1120 //------------------------------dump2------------------------------------------
  1121 // Dump double constant Type
  1122 #ifndef PRODUCT
  1123 void TypeD::dump2( Dict &d, uint depth, outputStream *st ) const {
  1124   Type::dump2(d,depth,st);
  1125   st->print("%f", _d);
  1127 #endif
  1129 //------------------------------singleton--------------------------------------
  1130 // TRUE if Type is a singleton type, FALSE otherwise.   Singletons are simple
  1131 // constants (Ldi nodes).  Singletons are integer, float or double constants
  1132 // or a single symbol.
  1133 bool TypeD::singleton(void) const {
  1134   return true;                  // Always a singleton
  1137 bool TypeD::empty(void) const {
  1138   return false;                 // always exactly a singleton
  1141 //=============================================================================
  1142 // Convience common pre-built types.
  1143 const TypeInt *TypeInt::MINUS_1;// -1
  1144 const TypeInt *TypeInt::ZERO;   // 0
  1145 const TypeInt *TypeInt::ONE;    // 1
  1146 const TypeInt *TypeInt::BOOL;   // 0 or 1, FALSE or TRUE.
  1147 const TypeInt *TypeInt::CC;     // -1,0 or 1, condition codes
  1148 const TypeInt *TypeInt::CC_LT;  // [-1]  == MINUS_1
  1149 const TypeInt *TypeInt::CC_GT;  // [1]   == ONE
  1150 const TypeInt *TypeInt::CC_EQ;  // [0]   == ZERO
  1151 const TypeInt *TypeInt::CC_LE;  // [-1,0]
  1152 const TypeInt *TypeInt::CC_GE;  // [0,1] == BOOL (!)
  1153 const TypeInt *TypeInt::BYTE;   // Bytes, -128 to 127
  1154 const TypeInt *TypeInt::UBYTE;  // Unsigned Bytes, 0 to 255
  1155 const TypeInt *TypeInt::CHAR;   // Java chars, 0-65535
  1156 const TypeInt *TypeInt::SHORT;  // Java shorts, -32768-32767
  1157 const TypeInt *TypeInt::POS;    // Positive 32-bit integers or zero
  1158 const TypeInt *TypeInt::POS1;   // Positive 32-bit integers
  1159 const TypeInt *TypeInt::INT;    // 32-bit integers
  1160 const TypeInt *TypeInt::SYMINT; // symmetric range [-max_jint..max_jint]
  1161 const TypeInt *TypeInt::TYPE_DOMAIN; // alias for TypeInt::INT
  1163 //------------------------------TypeInt----------------------------------------
  1164 TypeInt::TypeInt( jint lo, jint hi, int w ) : Type(Int), _lo(lo), _hi(hi), _widen(w) {
  1167 //------------------------------make-------------------------------------------
  1168 const TypeInt *TypeInt::make( jint lo ) {
  1169   return (TypeInt*)(new TypeInt(lo,lo,WidenMin))->hashcons();
  1172 static int normalize_int_widen( jint lo, jint hi, int w ) {
  1173   // Certain normalizations keep us sane when comparing types.
  1174   // The 'SMALLINT' covers constants and also CC and its relatives.
  1175   if (lo <= hi) {
  1176     if ((juint)(hi - lo) <= SMALLINT)  w = Type::WidenMin;
  1177     if ((juint)(hi - lo) >= max_juint) w = Type::WidenMax; // TypeInt::INT
  1178   } else {
  1179     if ((juint)(lo - hi) <= SMALLINT)  w = Type::WidenMin;
  1180     if ((juint)(lo - hi) >= max_juint) w = Type::WidenMin; // dual TypeInt::INT
  1182   return w;
  1185 const TypeInt *TypeInt::make( jint lo, jint hi, int w ) {
  1186   w = normalize_int_widen(lo, hi, w);
  1187   return (TypeInt*)(new TypeInt(lo,hi,w))->hashcons();
  1190 //------------------------------meet-------------------------------------------
  1191 // Compute the MEET of two types.  It returns a new Type representation object
  1192 // with reference count equal to the number of Types pointing at it.
  1193 // Caller should wrap a Types around it.
  1194 const Type *TypeInt::xmeet( const Type *t ) const {
  1195   // Perform a fast test for common case; meeting the same types together.
  1196   if( this == t ) return this;  // Meeting same type?
  1198   // Currently "this->_base" is a TypeInt
  1199   switch (t->base()) {          // Switch on original type
  1200   case AnyPtr:                  // Mixing with oops happens when javac
  1201   case RawPtr:                  // reuses local variables
  1202   case OopPtr:
  1203   case InstPtr:
  1204   case AryPtr:
  1205   case MetadataPtr:
  1206   case KlassPtr:
  1207   case NarrowOop:
  1208   case NarrowKlass:
  1209   case Long:
  1210   case FloatTop:
  1211   case FloatCon:
  1212   case FloatBot:
  1213   case DoubleTop:
  1214   case DoubleCon:
  1215   case DoubleBot:
  1216   case Bottom:                  // Ye Olde Default
  1217     return Type::BOTTOM;
  1218   default:                      // All else is a mistake
  1219     typerr(t);
  1220   case Top:                     // No change
  1221     return this;
  1222   case Int:                     // Int vs Int?
  1223     break;
  1226   // Expand covered set
  1227   const TypeInt *r = t->is_int();
  1228   return make( MIN2(_lo,r->_lo), MAX2(_hi,r->_hi), MAX2(_widen,r->_widen) );
  1231 //------------------------------xdual------------------------------------------
  1232 // Dual: reverse hi & lo; flip widen
  1233 const Type *TypeInt::xdual() const {
  1234   int w = normalize_int_widen(_hi,_lo, WidenMax-_widen);
  1235   return new TypeInt(_hi,_lo,w);
  1238 //------------------------------widen------------------------------------------
  1239 // Only happens for optimistic top-down optimizations.
  1240 const Type *TypeInt::widen( const Type *old, const Type* limit ) const {
  1241   // Coming from TOP or such; no widening
  1242   if( old->base() != Int ) return this;
  1243   const TypeInt *ot = old->is_int();
  1245   // If new guy is equal to old guy, no widening
  1246   if( _lo == ot->_lo && _hi == ot->_hi )
  1247     return old;
  1249   // If new guy contains old, then we widened
  1250   if( _lo <= ot->_lo && _hi >= ot->_hi ) {
  1251     // New contains old
  1252     // If new guy is already wider than old, no widening
  1253     if( _widen > ot->_widen ) return this;
  1254     // If old guy was a constant, do not bother
  1255     if (ot->_lo == ot->_hi)  return this;
  1256     // Now widen new guy.
  1257     // Check for widening too far
  1258     if (_widen == WidenMax) {
  1259       int max = max_jint;
  1260       int min = min_jint;
  1261       if (limit->isa_int()) {
  1262         max = limit->is_int()->_hi;
  1263         min = limit->is_int()->_lo;
  1265       if (min < _lo && _hi < max) {
  1266         // If neither endpoint is extremal yet, push out the endpoint
  1267         // which is closer to its respective limit.
  1268         if (_lo >= 0 ||                 // easy common case
  1269             (juint)(_lo - min) >= (juint)(max - _hi)) {
  1270           // Try to widen to an unsigned range type of 31 bits:
  1271           return make(_lo, max, WidenMax);
  1272         } else {
  1273           return make(min, _hi, WidenMax);
  1276       return TypeInt::INT;
  1278     // Returned widened new guy
  1279     return make(_lo,_hi,_widen+1);
  1282   // If old guy contains new, then we probably widened too far & dropped to
  1283   // bottom.  Return the wider fellow.
  1284   if ( ot->_lo <= _lo && ot->_hi >= _hi )
  1285     return old;
  1287   //fatal("Integer value range is not subset");
  1288   //return this;
  1289   return TypeInt::INT;
  1292 //------------------------------narrow---------------------------------------
  1293 // Only happens for pessimistic optimizations.
  1294 const Type *TypeInt::narrow( const Type *old ) const {
  1295   if (_lo >= _hi)  return this;   // already narrow enough
  1296   if (old == NULL)  return this;
  1297   const TypeInt* ot = old->isa_int();
  1298   if (ot == NULL)  return this;
  1299   jint olo = ot->_lo;
  1300   jint ohi = ot->_hi;
  1302   // If new guy is equal to old guy, no narrowing
  1303   if (_lo == olo && _hi == ohi)  return old;
  1305   // If old guy was maximum range, allow the narrowing
  1306   if (olo == min_jint && ohi == max_jint)  return this;
  1308   if (_lo < olo || _hi > ohi)
  1309     return this;                // doesn't narrow; pretty wierd
  1311   // The new type narrows the old type, so look for a "death march".
  1312   // See comments on PhaseTransform::saturate.
  1313   juint nrange = _hi - _lo;
  1314   juint orange = ohi - olo;
  1315   if (nrange < max_juint - 1 && nrange > (orange >> 1) + (SMALLINT*2)) {
  1316     // Use the new type only if the range shrinks a lot.
  1317     // We do not want the optimizer computing 2^31 point by point.
  1318     return old;
  1321   return this;
  1324 //-----------------------------filter------------------------------------------
  1325 const Type *TypeInt::filter_helper(const Type *kills, bool include_speculative) const {
  1326   const TypeInt* ft = join_helper(kills, include_speculative)->isa_int();
  1327   if (ft == NULL || ft->empty())
  1328     return Type::TOP;           // Canonical empty value
  1329   if (ft->_widen < this->_widen) {
  1330     // Do not allow the value of kill->_widen to affect the outcome.
  1331     // The widen bits must be allowed to run freely through the graph.
  1332     ft = TypeInt::make(ft->_lo, ft->_hi, this->_widen);
  1334   return ft;
  1337 //------------------------------eq---------------------------------------------
  1338 // Structural equality check for Type representations
  1339 bool TypeInt::eq( const Type *t ) const {
  1340   const TypeInt *r = t->is_int(); // Handy access
  1341   return r->_lo == _lo && r->_hi == _hi && r->_widen == _widen;
  1344 //------------------------------hash-------------------------------------------
  1345 // Type-specific hashing function.
  1346 int TypeInt::hash(void) const {
  1347   return _lo+_hi+_widen+(int)Type::Int;
  1350 //------------------------------is_finite--------------------------------------
  1351 // Has a finite value
  1352 bool TypeInt::is_finite() const {
  1353   return true;
  1356 //------------------------------dump2------------------------------------------
  1357 // Dump TypeInt
  1358 #ifndef PRODUCT
  1359 static const char* intname(char* buf, jint n) {
  1360   if (n == min_jint)
  1361     return "min";
  1362   else if (n < min_jint + 10000)
  1363     sprintf(buf, "min+" INT32_FORMAT, n - min_jint);
  1364   else if (n == max_jint)
  1365     return "max";
  1366   else if (n > max_jint - 10000)
  1367     sprintf(buf, "max-" INT32_FORMAT, max_jint - n);
  1368   else
  1369     sprintf(buf, INT32_FORMAT, n);
  1370   return buf;
  1373 void TypeInt::dump2( Dict &d, uint depth, outputStream *st ) const {
  1374   char buf[40], buf2[40];
  1375   if (_lo == min_jint && _hi == max_jint)
  1376     st->print("int");
  1377   else if (is_con())
  1378     st->print("int:%s", intname(buf, get_con()));
  1379   else if (_lo == BOOL->_lo && _hi == BOOL->_hi)
  1380     st->print("bool");
  1381   else if (_lo == BYTE->_lo && _hi == BYTE->_hi)
  1382     st->print("byte");
  1383   else if (_lo == CHAR->_lo && _hi == CHAR->_hi)
  1384     st->print("char");
  1385   else if (_lo == SHORT->_lo && _hi == SHORT->_hi)
  1386     st->print("short");
  1387   else if (_hi == max_jint)
  1388     st->print("int:>=%s", intname(buf, _lo));
  1389   else if (_lo == min_jint)
  1390     st->print("int:<=%s", intname(buf, _hi));
  1391   else
  1392     st->print("int:%s..%s", intname(buf, _lo), intname(buf2, _hi));
  1394   if (_widen != 0 && this != TypeInt::INT)
  1395     st->print(":%.*s", _widen, "wwww");
  1397 #endif
  1399 //------------------------------singleton--------------------------------------
  1400 // TRUE if Type is a singleton type, FALSE otherwise.   Singletons are simple
  1401 // constants.
  1402 bool TypeInt::singleton(void) const {
  1403   return _lo >= _hi;
  1406 bool TypeInt::empty(void) const {
  1407   return _lo > _hi;
  1410 //=============================================================================
  1411 // Convenience common pre-built types.
  1412 const TypeLong *TypeLong::MINUS_1;// -1
  1413 const TypeLong *TypeLong::ZERO; // 0
  1414 const TypeLong *TypeLong::ONE;  // 1
  1415 const TypeLong *TypeLong::POS;  // >=0
  1416 const TypeLong *TypeLong::LONG; // 64-bit integers
  1417 const TypeLong *TypeLong::INT;  // 32-bit subrange
  1418 const TypeLong *TypeLong::UINT; // 32-bit unsigned subrange
  1419 const TypeLong *TypeLong::TYPE_DOMAIN; // alias for TypeLong::LONG
  1421 //------------------------------TypeLong---------------------------------------
  1422 TypeLong::TypeLong( jlong lo, jlong hi, int w ) : Type(Long), _lo(lo), _hi(hi), _widen(w) {
  1425 //------------------------------make-------------------------------------------
  1426 const TypeLong *TypeLong::make( jlong lo ) {
  1427   return (TypeLong*)(new TypeLong(lo,lo,WidenMin))->hashcons();
  1430 static int normalize_long_widen( jlong lo, jlong hi, int w ) {
  1431   // Certain normalizations keep us sane when comparing types.
  1432   // The 'SMALLINT' covers constants.
  1433   if (lo <= hi) {
  1434     if ((julong)(hi - lo) <= SMALLINT)   w = Type::WidenMin;
  1435     if ((julong)(hi - lo) >= max_julong) w = Type::WidenMax; // TypeLong::LONG
  1436   } else {
  1437     if ((julong)(lo - hi) <= SMALLINT)   w = Type::WidenMin;
  1438     if ((julong)(lo - hi) >= max_julong) w = Type::WidenMin; // dual TypeLong::LONG
  1440   return w;
  1443 const TypeLong *TypeLong::make( jlong lo, jlong hi, int w ) {
  1444   w = normalize_long_widen(lo, hi, w);
  1445   return (TypeLong*)(new TypeLong(lo,hi,w))->hashcons();
  1449 //------------------------------meet-------------------------------------------
  1450 // Compute the MEET of two types.  It returns a new Type representation object
  1451 // with reference count equal to the number of Types pointing at it.
  1452 // Caller should wrap a Types around it.
  1453 const Type *TypeLong::xmeet( const Type *t ) const {
  1454   // Perform a fast test for common case; meeting the same types together.
  1455   if( this == t ) return this;  // Meeting same type?
  1457   // Currently "this->_base" is a TypeLong
  1458   switch (t->base()) {          // Switch on original type
  1459   case AnyPtr:                  // Mixing with oops happens when javac
  1460   case RawPtr:                  // reuses local variables
  1461   case OopPtr:
  1462   case InstPtr:
  1463   case AryPtr:
  1464   case MetadataPtr:
  1465   case KlassPtr:
  1466   case NarrowOop:
  1467   case NarrowKlass:
  1468   case Int:
  1469   case FloatTop:
  1470   case FloatCon:
  1471   case FloatBot:
  1472   case DoubleTop:
  1473   case DoubleCon:
  1474   case DoubleBot:
  1475   case Bottom:                  // Ye Olde Default
  1476     return Type::BOTTOM;
  1477   default:                      // All else is a mistake
  1478     typerr(t);
  1479   case Top:                     // No change
  1480     return this;
  1481   case Long:                    // Long vs Long?
  1482     break;
  1485   // Expand covered set
  1486   const TypeLong *r = t->is_long(); // Turn into a TypeLong
  1487   return make( MIN2(_lo,r->_lo), MAX2(_hi,r->_hi), MAX2(_widen,r->_widen) );
  1490 //------------------------------xdual------------------------------------------
  1491 // Dual: reverse hi & lo; flip widen
  1492 const Type *TypeLong::xdual() const {
  1493   int w = normalize_long_widen(_hi,_lo, WidenMax-_widen);
  1494   return new TypeLong(_hi,_lo,w);
  1497 //------------------------------widen------------------------------------------
  1498 // Only happens for optimistic top-down optimizations.
  1499 const Type *TypeLong::widen( const Type *old, const Type* limit ) const {
  1500   // Coming from TOP or such; no widening
  1501   if( old->base() != Long ) return this;
  1502   const TypeLong *ot = old->is_long();
  1504   // If new guy is equal to old guy, no widening
  1505   if( _lo == ot->_lo && _hi == ot->_hi )
  1506     return old;
  1508   // If new guy contains old, then we widened
  1509   if( _lo <= ot->_lo && _hi >= ot->_hi ) {
  1510     // New contains old
  1511     // If new guy is already wider than old, no widening
  1512     if( _widen > ot->_widen ) return this;
  1513     // If old guy was a constant, do not bother
  1514     if (ot->_lo == ot->_hi)  return this;
  1515     // Now widen new guy.
  1516     // Check for widening too far
  1517     if (_widen == WidenMax) {
  1518       jlong max = max_jlong;
  1519       jlong min = min_jlong;
  1520       if (limit->isa_long()) {
  1521         max = limit->is_long()->_hi;
  1522         min = limit->is_long()->_lo;
  1524       if (min < _lo && _hi < max) {
  1525         // If neither endpoint is extremal yet, push out the endpoint
  1526         // which is closer to its respective limit.
  1527         if (_lo >= 0 ||                 // easy common case
  1528             (julong)(_lo - min) >= (julong)(max - _hi)) {
  1529           // Try to widen to an unsigned range type of 32/63 bits:
  1530           if (max >= max_juint && _hi < max_juint)
  1531             return make(_lo, max_juint, WidenMax);
  1532           else
  1533             return make(_lo, max, WidenMax);
  1534         } else {
  1535           return make(min, _hi, WidenMax);
  1538       return TypeLong::LONG;
  1540     // Returned widened new guy
  1541     return make(_lo,_hi,_widen+1);
  1544   // If old guy contains new, then we probably widened too far & dropped to
  1545   // bottom.  Return the wider fellow.
  1546   if ( ot->_lo <= _lo && ot->_hi >= _hi )
  1547     return old;
  1549   //  fatal("Long value range is not subset");
  1550   // return this;
  1551   return TypeLong::LONG;
  1554 //------------------------------narrow----------------------------------------
  1555 // Only happens for pessimistic optimizations.
  1556 const Type *TypeLong::narrow( const Type *old ) const {
  1557   if (_lo >= _hi)  return this;   // already narrow enough
  1558   if (old == NULL)  return this;
  1559   const TypeLong* ot = old->isa_long();
  1560   if (ot == NULL)  return this;
  1561   jlong olo = ot->_lo;
  1562   jlong ohi = ot->_hi;
  1564   // If new guy is equal to old guy, no narrowing
  1565   if (_lo == olo && _hi == ohi)  return old;
  1567   // If old guy was maximum range, allow the narrowing
  1568   if (olo == min_jlong && ohi == max_jlong)  return this;
  1570   if (_lo < olo || _hi > ohi)
  1571     return this;                // doesn't narrow; pretty wierd
  1573   // The new type narrows the old type, so look for a "death march".
  1574   // See comments on PhaseTransform::saturate.
  1575   julong nrange = _hi - _lo;
  1576   julong orange = ohi - olo;
  1577   if (nrange < max_julong - 1 && nrange > (orange >> 1) + (SMALLINT*2)) {
  1578     // Use the new type only if the range shrinks a lot.
  1579     // We do not want the optimizer computing 2^31 point by point.
  1580     return old;
  1583   return this;
  1586 //-----------------------------filter------------------------------------------
  1587 const Type *TypeLong::filter_helper(const Type *kills, bool include_speculative) const {
  1588   const TypeLong* ft = join_helper(kills, include_speculative)->isa_long();
  1589   if (ft == NULL || ft->empty())
  1590     return Type::TOP;           // Canonical empty value
  1591   if (ft->_widen < this->_widen) {
  1592     // Do not allow the value of kill->_widen to affect the outcome.
  1593     // The widen bits must be allowed to run freely through the graph.
  1594     ft = TypeLong::make(ft->_lo, ft->_hi, this->_widen);
  1596   return ft;
  1599 //------------------------------eq---------------------------------------------
  1600 // Structural equality check for Type representations
  1601 bool TypeLong::eq( const Type *t ) const {
  1602   const TypeLong *r = t->is_long(); // Handy access
  1603   return r->_lo == _lo &&  r->_hi == _hi  && r->_widen == _widen;
  1606 //------------------------------hash-------------------------------------------
  1607 // Type-specific hashing function.
  1608 int TypeLong::hash(void) const {
  1609   return (int)(_lo+_hi+_widen+(int)Type::Long);
  1612 //------------------------------is_finite--------------------------------------
  1613 // Has a finite value
  1614 bool TypeLong::is_finite() const {
  1615   return true;
  1618 //------------------------------dump2------------------------------------------
  1619 // Dump TypeLong
  1620 #ifndef PRODUCT
  1621 static const char* longnamenear(jlong x, const char* xname, char* buf, jlong n) {
  1622   if (n > x) {
  1623     if (n >= x + 10000)  return NULL;
  1624     sprintf(buf, "%s+" JLONG_FORMAT, xname, n - x);
  1625   } else if (n < x) {
  1626     if (n <= x - 10000)  return NULL;
  1627     sprintf(buf, "%s-" JLONG_FORMAT, xname, x - n);
  1628   } else {
  1629     return xname;
  1631   return buf;
  1634 static const char* longname(char* buf, jlong n) {
  1635   const char* str;
  1636   if (n == min_jlong)
  1637     return "min";
  1638   else if (n < min_jlong + 10000)
  1639     sprintf(buf, "min+" JLONG_FORMAT, n - min_jlong);
  1640   else if (n == max_jlong)
  1641     return "max";
  1642   else if (n > max_jlong - 10000)
  1643     sprintf(buf, "max-" JLONG_FORMAT, max_jlong - n);
  1644   else if ((str = longnamenear(max_juint, "maxuint", buf, n)) != NULL)
  1645     return str;
  1646   else if ((str = longnamenear(max_jint, "maxint", buf, n)) != NULL)
  1647     return str;
  1648   else if ((str = longnamenear(min_jint, "minint", buf, n)) != NULL)
  1649     return str;
  1650   else
  1651     sprintf(buf, JLONG_FORMAT, n);
  1652   return buf;
  1655 void TypeLong::dump2( Dict &d, uint depth, outputStream *st ) const {
  1656   char buf[80], buf2[80];
  1657   if (_lo == min_jlong && _hi == max_jlong)
  1658     st->print("long");
  1659   else if (is_con())
  1660     st->print("long:%s", longname(buf, get_con()));
  1661   else if (_hi == max_jlong)
  1662     st->print("long:>=%s", longname(buf, _lo));
  1663   else if (_lo == min_jlong)
  1664     st->print("long:<=%s", longname(buf, _hi));
  1665   else
  1666     st->print("long:%s..%s", longname(buf, _lo), longname(buf2, _hi));
  1668   if (_widen != 0 && this != TypeLong::LONG)
  1669     st->print(":%.*s", _widen, "wwww");
  1671 #endif
  1673 //------------------------------singleton--------------------------------------
  1674 // TRUE if Type is a singleton type, FALSE otherwise.   Singletons are simple
  1675 // constants
  1676 bool TypeLong::singleton(void) const {
  1677   return _lo >= _hi;
  1680 bool TypeLong::empty(void) const {
  1681   return _lo > _hi;
  1684 //=============================================================================
  1685 // Convenience common pre-built types.
  1686 const TypeTuple *TypeTuple::IFBOTH;     // Return both arms of IF as reachable
  1687 const TypeTuple *TypeTuple::IFFALSE;
  1688 const TypeTuple *TypeTuple::IFTRUE;
  1689 const TypeTuple *TypeTuple::IFNEITHER;
  1690 const TypeTuple *TypeTuple::LOOPBODY;
  1691 const TypeTuple *TypeTuple::MEMBAR;
  1692 const TypeTuple *TypeTuple::STORECONDITIONAL;
  1693 const TypeTuple *TypeTuple::START_I2C;
  1694 const TypeTuple *TypeTuple::INT_PAIR;
  1695 const TypeTuple *TypeTuple::LONG_PAIR;
  1696 const TypeTuple *TypeTuple::INT_CC_PAIR;
  1697 const TypeTuple *TypeTuple::LONG_CC_PAIR;
  1700 //------------------------------make-------------------------------------------
  1701 // Make a TypeTuple from the range of a method signature
  1702 const TypeTuple *TypeTuple::make_range(ciSignature* sig) {
  1703   ciType* return_type = sig->return_type();
  1704   uint total_fields = TypeFunc::Parms + return_type->size();
  1705   const Type **field_array = fields(total_fields);
  1706   switch (return_type->basic_type()) {
  1707   case T_LONG:
  1708     field_array[TypeFunc::Parms]   = TypeLong::LONG;
  1709     field_array[TypeFunc::Parms+1] = Type::HALF;
  1710     break;
  1711   case T_DOUBLE:
  1712     field_array[TypeFunc::Parms]   = Type::DOUBLE;
  1713     field_array[TypeFunc::Parms+1] = Type::HALF;
  1714     break;
  1715   case T_OBJECT:
  1716   case T_ARRAY:
  1717   case T_BOOLEAN:
  1718   case T_CHAR:
  1719   case T_FLOAT:
  1720   case T_BYTE:
  1721   case T_SHORT:
  1722   case T_INT:
  1723     field_array[TypeFunc::Parms] = get_const_type(return_type);
  1724     break;
  1725   case T_VOID:
  1726     break;
  1727   default:
  1728     ShouldNotReachHere();
  1730   return (TypeTuple*)(new TypeTuple(total_fields,field_array))->hashcons();
  1733 // Make a TypeTuple from the domain of a method signature
  1734 const TypeTuple *TypeTuple::make_domain(ciInstanceKlass* recv, ciSignature* sig) {
  1735   uint total_fields = TypeFunc::Parms + sig->size();
  1737   uint pos = TypeFunc::Parms;
  1738   const Type **field_array;
  1739   if (recv != NULL) {
  1740     total_fields++;
  1741     field_array = fields(total_fields);
  1742     // Use get_const_type here because it respects UseUniqueSubclasses:
  1743     field_array[pos++] = get_const_type(recv)->join_speculative(TypePtr::NOTNULL);
  1744   } else {
  1745     field_array = fields(total_fields);
  1748   int i = 0;
  1749   while (pos < total_fields) {
  1750     ciType* type = sig->type_at(i);
  1752     switch (type->basic_type()) {
  1753     case T_LONG:
  1754       field_array[pos++] = TypeLong::LONG;
  1755       field_array[pos++] = Type::HALF;
  1756       break;
  1757     case T_DOUBLE:
  1758       field_array[pos++] = Type::DOUBLE;
  1759       field_array[pos++] = Type::HALF;
  1760       break;
  1761     case T_OBJECT:
  1762     case T_ARRAY:
  1763     case T_BOOLEAN:
  1764     case T_CHAR:
  1765     case T_FLOAT:
  1766     case T_BYTE:
  1767     case T_SHORT:
  1768     case T_INT:
  1769       field_array[pos++] = get_const_type(type);
  1770       break;
  1771     default:
  1772       ShouldNotReachHere();
  1774     i++;
  1776   return (TypeTuple*)(new TypeTuple(total_fields,field_array))->hashcons();
  1779 const TypeTuple *TypeTuple::make( uint cnt, const Type **fields ) {
  1780   return (TypeTuple*)(new TypeTuple(cnt,fields))->hashcons();
  1783 //------------------------------fields-----------------------------------------
  1784 // Subroutine call type with space allocated for argument types
  1785 const Type **TypeTuple::fields( uint arg_cnt ) {
  1786   const Type **flds = (const Type **)(Compile::current()->type_arena()->Amalloc_4((TypeFunc::Parms+arg_cnt)*sizeof(Type*) ));
  1787   flds[TypeFunc::Control  ] = Type::CONTROL;
  1788   flds[TypeFunc::I_O      ] = Type::ABIO;
  1789   flds[TypeFunc::Memory   ] = Type::MEMORY;
  1790   flds[TypeFunc::FramePtr ] = TypeRawPtr::BOTTOM;
  1791   flds[TypeFunc::ReturnAdr] = Type::RETURN_ADDRESS;
  1793   return flds;
  1796 //------------------------------meet-------------------------------------------
  1797 // Compute the MEET of two types.  It returns a new Type object.
  1798 const Type *TypeTuple::xmeet( const Type *t ) const {
  1799   // Perform a fast test for common case; meeting the same types together.
  1800   if( this == t ) return this;  // Meeting same type-rep?
  1802   // Current "this->_base" is Tuple
  1803   switch (t->base()) {          // switch on original type
  1805   case Bottom:                  // Ye Olde Default
  1806     return t;
  1808   default:                      // All else is a mistake
  1809     typerr(t);
  1811   case Tuple: {                 // Meeting 2 signatures?
  1812     const TypeTuple *x = t->is_tuple();
  1813     assert( _cnt == x->_cnt, "" );
  1814     const Type **fields = (const Type **)(Compile::current()->type_arena()->Amalloc_4( _cnt*sizeof(Type*) ));
  1815     for( uint i=0; i<_cnt; i++ )
  1816       fields[i] = field_at(i)->xmeet( x->field_at(i) );
  1817     return TypeTuple::make(_cnt,fields);
  1819   case Top:
  1820     break;
  1822   return this;                  // Return the double constant
  1825 //------------------------------xdual------------------------------------------
  1826 // Dual: compute field-by-field dual
  1827 const Type *TypeTuple::xdual() const {
  1828   const Type **fields = (const Type **)(Compile::current()->type_arena()->Amalloc_4( _cnt*sizeof(Type*) ));
  1829   for( uint i=0; i<_cnt; i++ )
  1830     fields[i] = _fields[i]->dual();
  1831   return new TypeTuple(_cnt,fields);
  1834 //------------------------------eq---------------------------------------------
  1835 // Structural equality check for Type representations
  1836 bool TypeTuple::eq( const Type *t ) const {
  1837   const TypeTuple *s = (const TypeTuple *)t;
  1838   if (_cnt != s->_cnt)  return false;  // Unequal field counts
  1839   for (uint i = 0; i < _cnt; i++)
  1840     if (field_at(i) != s->field_at(i)) // POINTER COMPARE!  NO RECURSION!
  1841       return false;             // Missed
  1842   return true;
  1845 //------------------------------hash-------------------------------------------
  1846 // Type-specific hashing function.
  1847 int TypeTuple::hash(void) const {
  1848   intptr_t sum = _cnt;
  1849   for( uint i=0; i<_cnt; i++ )
  1850     sum += (intptr_t)_fields[i];     // Hash on pointers directly
  1851   return sum;
  1854 //------------------------------dump2------------------------------------------
  1855 // Dump signature Type
  1856 #ifndef PRODUCT
  1857 void TypeTuple::dump2( Dict &d, uint depth, outputStream *st ) const {
  1858   st->print("{");
  1859   if( !depth || d[this] ) {     // Check for recursive print
  1860     st->print("...}");
  1861     return;
  1863   d.Insert((void*)this, (void*)this);   // Stop recursion
  1864   if( _cnt ) {
  1865     uint i;
  1866     for( i=0; i<_cnt-1; i++ ) {
  1867       st->print("%d:", i);
  1868       _fields[i]->dump2(d, depth-1, st);
  1869       st->print(", ");
  1871     st->print("%d:", i);
  1872     _fields[i]->dump2(d, depth-1, st);
  1874   st->print("}");
  1876 #endif
  1878 //------------------------------singleton--------------------------------------
  1879 // TRUE if Type is a singleton type, FALSE otherwise.   Singletons are simple
  1880 // constants (Ldi nodes).  Singletons are integer, float or double constants
  1881 // or a single symbol.
  1882 bool TypeTuple::singleton(void) const {
  1883   return false;                 // Never a singleton
  1886 bool TypeTuple::empty(void) const {
  1887   for( uint i=0; i<_cnt; i++ ) {
  1888     if (_fields[i]->empty())  return true;
  1890   return false;
  1893 //=============================================================================
  1894 // Convenience common pre-built types.
  1896 inline const TypeInt* normalize_array_size(const TypeInt* size) {
  1897   // Certain normalizations keep us sane when comparing types.
  1898   // We do not want arrayOop variables to differ only by the wideness
  1899   // of their index types.  Pick minimum wideness, since that is the
  1900   // forced wideness of small ranges anyway.
  1901   if (size->_widen != Type::WidenMin)
  1902     return TypeInt::make(size->_lo, size->_hi, Type::WidenMin);
  1903   else
  1904     return size;
  1907 //------------------------------make-------------------------------------------
  1908 const TypeAry* TypeAry::make(const Type* elem, const TypeInt* size, bool stable) {
  1909   if (UseCompressedOops && elem->isa_oopptr()) {
  1910     elem = elem->make_narrowoop();
  1912   size = normalize_array_size(size);
  1913   return (TypeAry*)(new TypeAry(elem,size,stable))->hashcons();
  1916 //------------------------------meet-------------------------------------------
  1917 // Compute the MEET of two types.  It returns a new Type object.
  1918 const Type *TypeAry::xmeet( const Type *t ) const {
  1919   // Perform a fast test for common case; meeting the same types together.
  1920   if( this == t ) return this;  // Meeting same type-rep?
  1922   // Current "this->_base" is Ary
  1923   switch (t->base()) {          // switch on original type
  1925   case Bottom:                  // Ye Olde Default
  1926     return t;
  1928   default:                      // All else is a mistake
  1929     typerr(t);
  1931   case Array: {                 // Meeting 2 arrays?
  1932     const TypeAry *a = t->is_ary();
  1933     return TypeAry::make(_elem->meet_speculative(a->_elem),
  1934                          _size->xmeet(a->_size)->is_int(),
  1935                          _stable & a->_stable);
  1937   case Top:
  1938     break;
  1940   return this;                  // Return the double constant
  1943 //------------------------------xdual------------------------------------------
  1944 // Dual: compute field-by-field dual
  1945 const Type *TypeAry::xdual() const {
  1946   const TypeInt* size_dual = _size->dual()->is_int();
  1947   size_dual = normalize_array_size(size_dual);
  1948   return new TypeAry(_elem->dual(), size_dual, !_stable);
  1951 //------------------------------eq---------------------------------------------
  1952 // Structural equality check for Type representations
  1953 bool TypeAry::eq( const Type *t ) const {
  1954   const TypeAry *a = (const TypeAry*)t;
  1955   return _elem == a->_elem &&
  1956     _stable == a->_stable &&
  1957     _size == a->_size;
  1960 //------------------------------hash-------------------------------------------
  1961 // Type-specific hashing function.
  1962 int TypeAry::hash(void) const {
  1963   return (intptr_t)_elem + (intptr_t)_size + (_stable ? 43 : 0);
  1966 /**
  1967  * Return same type without a speculative part in the element
  1968  */
  1969 const Type* TypeAry::remove_speculative() const {
  1970   return make(_elem->remove_speculative(), _size, _stable);
  1973 //----------------------interface_vs_oop---------------------------------------
  1974 #ifdef ASSERT
  1975 bool TypeAry::interface_vs_oop(const Type *t) const {
  1976   const TypeAry* t_ary = t->is_ary();
  1977   if (t_ary) {
  1978     return _elem->interface_vs_oop(t_ary->_elem);
  1980   return false;
  1982 #endif
  1984 //------------------------------dump2------------------------------------------
  1985 #ifndef PRODUCT
  1986 void TypeAry::dump2( Dict &d, uint depth, outputStream *st ) const {
  1987   if (_stable)  st->print("stable:");
  1988   _elem->dump2(d, depth, st);
  1989   st->print("[");
  1990   _size->dump2(d, depth, st);
  1991   st->print("]");
  1993 #endif
  1995 //------------------------------singleton--------------------------------------
  1996 // TRUE if Type is a singleton type, FALSE otherwise.   Singletons are simple
  1997 // constants (Ldi nodes).  Singletons are integer, float or double constants
  1998 // or a single symbol.
  1999 bool TypeAry::singleton(void) const {
  2000   return false;                 // Never a singleton
  2003 bool TypeAry::empty(void) const {
  2004   return _elem->empty() || _size->empty();
  2007 //--------------------------ary_must_be_exact----------------------------------
  2008 bool TypeAry::ary_must_be_exact() const {
  2009   if (!UseExactTypes)       return false;
  2010   // This logic looks at the element type of an array, and returns true
  2011   // if the element type is either a primitive or a final instance class.
  2012   // In such cases, an array built on this ary must have no subclasses.
  2013   if (_elem == BOTTOM)      return false;  // general array not exact
  2014   if (_elem == TOP   )      return false;  // inverted general array not exact
  2015   const TypeOopPtr*  toop = NULL;
  2016   if (UseCompressedOops && _elem->isa_narrowoop()) {
  2017     toop = _elem->make_ptr()->isa_oopptr();
  2018   } else {
  2019     toop = _elem->isa_oopptr();
  2021   if (!toop)                return true;   // a primitive type, like int
  2022   ciKlass* tklass = toop->klass();
  2023   if (tklass == NULL)       return false;  // unloaded class
  2024   if (!tklass->is_loaded()) return false;  // unloaded class
  2025   const TypeInstPtr* tinst;
  2026   if (_elem->isa_narrowoop())
  2027     tinst = _elem->make_ptr()->isa_instptr();
  2028   else
  2029     tinst = _elem->isa_instptr();
  2030   if (tinst)
  2031     return tklass->as_instance_klass()->is_final();
  2032   const TypeAryPtr*  tap;
  2033   if (_elem->isa_narrowoop())
  2034     tap = _elem->make_ptr()->isa_aryptr();
  2035   else
  2036     tap = _elem->isa_aryptr();
  2037   if (tap)
  2038     return tap->ary()->ary_must_be_exact();
  2039   return false;
  2042 //==============================TypeVect=======================================
  2043 // Convenience common pre-built types.
  2044 const TypeVect *TypeVect::VECTS = NULL; //  32-bit vectors
  2045 const TypeVect *TypeVect::VECTD = NULL; //  64-bit vectors
  2046 const TypeVect *TypeVect::VECTX = NULL; // 128-bit vectors
  2047 const TypeVect *TypeVect::VECTY = NULL; // 256-bit vectors
  2049 //------------------------------make-------------------------------------------
  2050 const TypeVect* TypeVect::make(const Type *elem, uint length) {
  2051   BasicType elem_bt = elem->array_element_basic_type();
  2052   assert(is_java_primitive(elem_bt), "only primitive types in vector");
  2053   assert(length > 1 && is_power_of_2(length), "vector length is power of 2");
  2054   assert(Matcher::vector_size_supported(elem_bt, length), "length in range");
  2055   int size = length * type2aelembytes(elem_bt);
  2056   switch (Matcher::vector_ideal_reg(size)) {
  2057   case Op_VecS:
  2058     return (TypeVect*)(new TypeVectS(elem, length))->hashcons();
  2059   case Op_VecD:
  2060   case Op_RegD:
  2061     return (TypeVect*)(new TypeVectD(elem, length))->hashcons();
  2062   case Op_VecX:
  2063     return (TypeVect*)(new TypeVectX(elem, length))->hashcons();
  2064   case Op_VecY:
  2065     return (TypeVect*)(new TypeVectY(elem, length))->hashcons();
  2067  ShouldNotReachHere();
  2068   return NULL;
  2071 //------------------------------meet-------------------------------------------
  2072 // Compute the MEET of two types.  It returns a new Type object.
  2073 const Type *TypeVect::xmeet( const Type *t ) const {
  2074   // Perform a fast test for common case; meeting the same types together.
  2075   if( this == t ) return this;  // Meeting same type-rep?
  2077   // Current "this->_base" is Vector
  2078   switch (t->base()) {          // switch on original type
  2080   case Bottom:                  // Ye Olde Default
  2081     return t;
  2083   default:                      // All else is a mistake
  2084     typerr(t);
  2086   case VectorS:
  2087   case VectorD:
  2088   case VectorX:
  2089   case VectorY: {                // Meeting 2 vectors?
  2090     const TypeVect* v = t->is_vect();
  2091     assert(  base() == v->base(), "");
  2092     assert(length() == v->length(), "");
  2093     assert(element_basic_type() == v->element_basic_type(), "");
  2094     return TypeVect::make(_elem->xmeet(v->_elem), _length);
  2096   case Top:
  2097     break;
  2099   return this;
  2102 //------------------------------xdual------------------------------------------
  2103 // Dual: compute field-by-field dual
  2104 const Type *TypeVect::xdual() const {
  2105   return new TypeVect(base(), _elem->dual(), _length);
  2108 //------------------------------eq---------------------------------------------
  2109 // Structural equality check for Type representations
  2110 bool TypeVect::eq(const Type *t) const {
  2111   const TypeVect *v = t->is_vect();
  2112   return (_elem == v->_elem) && (_length == v->_length);
  2115 //------------------------------hash-------------------------------------------
  2116 // Type-specific hashing function.
  2117 int TypeVect::hash(void) const {
  2118   return (intptr_t)_elem + (intptr_t)_length;
  2121 //------------------------------singleton--------------------------------------
  2122 // TRUE if Type is a singleton type, FALSE otherwise.   Singletons are simple
  2123 // constants (Ldi nodes).  Vector is singleton if all elements are the same
  2124 // constant value (when vector is created with Replicate code).
  2125 bool TypeVect::singleton(void) const {
  2126 // There is no Con node for vectors yet.
  2127 //  return _elem->singleton();
  2128   return false;
  2131 bool TypeVect::empty(void) const {
  2132   return _elem->empty();
  2135 //------------------------------dump2------------------------------------------
  2136 #ifndef PRODUCT
  2137 void TypeVect::dump2(Dict &d, uint depth, outputStream *st) const {
  2138   switch (base()) {
  2139   case VectorS:
  2140     st->print("vectors["); break;
  2141   case VectorD:
  2142     st->print("vectord["); break;
  2143   case VectorX:
  2144     st->print("vectorx["); break;
  2145   case VectorY:
  2146     st->print("vectory["); break;
  2147   default:
  2148     ShouldNotReachHere();
  2150   st->print("%d]:{", _length);
  2151   _elem->dump2(d, depth, st);
  2152   st->print("}");
  2154 #endif
  2157 //=============================================================================
  2158 // Convenience common pre-built types.
  2159 const TypePtr *TypePtr::NULL_PTR;
  2160 const TypePtr *TypePtr::NOTNULL;
  2161 const TypePtr *TypePtr::BOTTOM;
  2163 //------------------------------meet-------------------------------------------
  2164 // Meet over the PTR enum
  2165 const TypePtr::PTR TypePtr::ptr_meet[TypePtr::lastPTR][TypePtr::lastPTR] = {
  2166   //              TopPTR,    AnyNull,   Constant, Null,   NotNull, BotPTR,
  2167   { /* Top     */ TopPTR,    AnyNull,   Constant, Null,   NotNull, BotPTR,},
  2168   { /* AnyNull */ AnyNull,   AnyNull,   Constant, BotPTR, NotNull, BotPTR,},
  2169   { /* Constant*/ Constant,  Constant,  Constant, BotPTR, NotNull, BotPTR,},
  2170   { /* Null    */ Null,      BotPTR,    BotPTR,   Null,   BotPTR,  BotPTR,},
  2171   { /* NotNull */ NotNull,   NotNull,   NotNull,  BotPTR, NotNull, BotPTR,},
  2172   { /* BotPTR  */ BotPTR,    BotPTR,    BotPTR,   BotPTR, BotPTR,  BotPTR,}
  2173 };
  2175 //------------------------------make-------------------------------------------
  2176 const TypePtr *TypePtr::make( TYPES t, enum PTR ptr, int offset ) {
  2177   return (TypePtr*)(new TypePtr(t,ptr,offset))->hashcons();
  2180 //------------------------------cast_to_ptr_type-------------------------------
  2181 const Type *TypePtr::cast_to_ptr_type(PTR ptr) const {
  2182   assert(_base == AnyPtr, "subclass must override cast_to_ptr_type");
  2183   if( ptr == _ptr ) return this;
  2184   return make(_base, ptr, _offset);
  2187 //------------------------------get_con----------------------------------------
  2188 intptr_t TypePtr::get_con() const {
  2189   assert( _ptr == Null, "" );
  2190   return _offset;
  2193 //------------------------------meet-------------------------------------------
  2194 // Compute the MEET of two types.  It returns a new Type object.
  2195 const Type *TypePtr::xmeet( const Type *t ) const {
  2196   // Perform a fast test for common case; meeting the same types together.
  2197   if( this == t ) return this;  // Meeting same type-rep?
  2199   // Current "this->_base" is AnyPtr
  2200   switch (t->base()) {          // switch on original type
  2201   case Int:                     // Mixing ints & oops happens when javac
  2202   case Long:                    // reuses local variables
  2203   case FloatTop:
  2204   case FloatCon:
  2205   case FloatBot:
  2206   case DoubleTop:
  2207   case DoubleCon:
  2208   case DoubleBot:
  2209   case NarrowOop:
  2210   case NarrowKlass:
  2211   case Bottom:                  // Ye Olde Default
  2212     return Type::BOTTOM;
  2213   case Top:
  2214     return this;
  2216   case AnyPtr: {                // Meeting to AnyPtrs
  2217     const TypePtr *tp = t->is_ptr();
  2218     return make( AnyPtr, meet_ptr(tp->ptr()), meet_offset(tp->offset()) );
  2220   case RawPtr:                  // For these, flip the call around to cut down
  2221   case OopPtr:
  2222   case InstPtr:                 // on the cases I have to handle.
  2223   case AryPtr:
  2224   case MetadataPtr:
  2225   case KlassPtr:
  2226     return t->xmeet(this);      // Call in reverse direction
  2227   default:                      // All else is a mistake
  2228     typerr(t);
  2231   return this;
  2234 //------------------------------meet_offset------------------------------------
  2235 int TypePtr::meet_offset( int offset ) const {
  2236   // Either is 'TOP' offset?  Return the other offset!
  2237   if( _offset == OffsetTop ) return offset;
  2238   if( offset == OffsetTop ) return _offset;
  2239   // If either is different, return 'BOTTOM' offset
  2240   if( _offset != offset ) return OffsetBot;
  2241   return _offset;
  2244 //------------------------------dual_offset------------------------------------
  2245 int TypePtr::dual_offset( ) const {
  2246   if( _offset == OffsetTop ) return OffsetBot;// Map 'TOP' into 'BOTTOM'
  2247   if( _offset == OffsetBot ) return OffsetTop;// Map 'BOTTOM' into 'TOP'
  2248   return _offset;               // Map everything else into self
  2251 //------------------------------xdual------------------------------------------
  2252 // Dual: compute field-by-field dual
  2253 const TypePtr::PTR TypePtr::ptr_dual[TypePtr::lastPTR] = {
  2254   BotPTR, NotNull, Constant, Null, AnyNull, TopPTR
  2255 };
  2256 const Type *TypePtr::xdual() const {
  2257   return new TypePtr( AnyPtr, dual_ptr(), dual_offset() );
  2260 //------------------------------xadd_offset------------------------------------
  2261 int TypePtr::xadd_offset( intptr_t offset ) const {
  2262   // Adding to 'TOP' offset?  Return 'TOP'!
  2263   if( _offset == OffsetTop || offset == OffsetTop ) return OffsetTop;
  2264   // Adding to 'BOTTOM' offset?  Return 'BOTTOM'!
  2265   if( _offset == OffsetBot || offset == OffsetBot ) return OffsetBot;
  2266   // Addition overflows or "accidentally" equals to OffsetTop? Return 'BOTTOM'!
  2267   offset += (intptr_t)_offset;
  2268   if (offset != (int)offset || offset == OffsetTop) return OffsetBot;
  2270   // assert( _offset >= 0 && _offset+offset >= 0, "" );
  2271   // It is possible to construct a negative offset during PhaseCCP
  2273   return (int)offset;        // Sum valid offsets
  2276 //------------------------------add_offset-------------------------------------
  2277 const TypePtr *TypePtr::add_offset( intptr_t offset ) const {
  2278   return make( AnyPtr, _ptr, xadd_offset(offset) );
  2281 //------------------------------eq---------------------------------------------
  2282 // Structural equality check for Type representations
  2283 bool TypePtr::eq( const Type *t ) const {
  2284   const TypePtr *a = (const TypePtr*)t;
  2285   return _ptr == a->ptr() && _offset == a->offset();
  2288 //------------------------------hash-------------------------------------------
  2289 // Type-specific hashing function.
  2290 int TypePtr::hash(void) const {
  2291   return _ptr + _offset;
  2294 //------------------------------dump2------------------------------------------
  2295 const char *const TypePtr::ptr_msg[TypePtr::lastPTR] = {
  2296   "TopPTR","AnyNull","Constant","NULL","NotNull","BotPTR"
  2297 };
  2299 #ifndef PRODUCT
  2300 void TypePtr::dump2( Dict &d, uint depth, outputStream *st ) const {
  2301   if( _ptr == Null ) st->print("NULL");
  2302   else st->print("%s *", ptr_msg[_ptr]);
  2303   if( _offset == OffsetTop ) st->print("+top");
  2304   else if( _offset == OffsetBot ) st->print("+bot");
  2305   else if( _offset ) st->print("+%d", _offset);
  2307 #endif
  2309 //------------------------------singleton--------------------------------------
  2310 // TRUE if Type is a singleton type, FALSE otherwise.   Singletons are simple
  2311 // constants
  2312 bool TypePtr::singleton(void) const {
  2313   // TopPTR, Null, AnyNull, Constant are all singletons
  2314   return (_offset != OffsetBot) && !below_centerline(_ptr);
  2317 bool TypePtr::empty(void) const {
  2318   return (_offset == OffsetTop) || above_centerline(_ptr);
  2321 //=============================================================================
  2322 // Convenience common pre-built types.
  2323 const TypeRawPtr *TypeRawPtr::BOTTOM;
  2324 const TypeRawPtr *TypeRawPtr::NOTNULL;
  2326 //------------------------------make-------------------------------------------
  2327 const TypeRawPtr *TypeRawPtr::make( enum PTR ptr ) {
  2328   assert( ptr != Constant, "what is the constant?" );
  2329   assert( ptr != Null, "Use TypePtr for NULL" );
  2330   return (TypeRawPtr*)(new TypeRawPtr(ptr,0))->hashcons();
  2333 const TypeRawPtr *TypeRawPtr::make( address bits ) {
  2334   assert( bits, "Use TypePtr for NULL" );
  2335   return (TypeRawPtr*)(new TypeRawPtr(Constant,bits))->hashcons();
  2338 //------------------------------cast_to_ptr_type-------------------------------
  2339 const Type *TypeRawPtr::cast_to_ptr_type(PTR ptr) const {
  2340   assert( ptr != Constant, "what is the constant?" );
  2341   assert( ptr != Null, "Use TypePtr for NULL" );
  2342   assert( _bits==0, "Why cast a constant address?");
  2343   if( ptr == _ptr ) return this;
  2344   return make(ptr);
  2347 //------------------------------get_con----------------------------------------
  2348 intptr_t TypeRawPtr::get_con() const {
  2349   assert( _ptr == Null || _ptr == Constant, "" );
  2350   return (intptr_t)_bits;
  2353 //------------------------------meet-------------------------------------------
  2354 // Compute the MEET of two types.  It returns a new Type object.
  2355 const Type *TypeRawPtr::xmeet( const Type *t ) const {
  2356   // Perform a fast test for common case; meeting the same types together.
  2357   if( this == t ) return this;  // Meeting same type-rep?
  2359   // Current "this->_base" is RawPtr
  2360   switch( t->base() ) {         // switch on original type
  2361   case Bottom:                  // Ye Olde Default
  2362     return t;
  2363   case Top:
  2364     return this;
  2365   case AnyPtr:                  // Meeting to AnyPtrs
  2366     break;
  2367   case RawPtr: {                // might be top, bot, any/not or constant
  2368     enum PTR tptr = t->is_ptr()->ptr();
  2369     enum PTR ptr = meet_ptr( tptr );
  2370     if( ptr == Constant ) {     // Cannot be equal constants, so...
  2371       if( tptr == Constant && _ptr != Constant)  return t;
  2372       if( _ptr == Constant && tptr != Constant)  return this;
  2373       ptr = NotNull;            // Fall down in lattice
  2375     return make( ptr );
  2378   case OopPtr:
  2379   case InstPtr:
  2380   case AryPtr:
  2381   case MetadataPtr:
  2382   case KlassPtr:
  2383     return TypePtr::BOTTOM;     // Oop meet raw is not well defined
  2384   default:                      // All else is a mistake
  2385     typerr(t);
  2388   // Found an AnyPtr type vs self-RawPtr type
  2389   const TypePtr *tp = t->is_ptr();
  2390   switch (tp->ptr()) {
  2391   case TypePtr::TopPTR:  return this;
  2392   case TypePtr::BotPTR:  return t;
  2393   case TypePtr::Null:
  2394     if( _ptr == TypePtr::TopPTR ) return t;
  2395     return TypeRawPtr::BOTTOM;
  2396   case TypePtr::NotNull: return TypePtr::make( AnyPtr, meet_ptr(TypePtr::NotNull), tp->meet_offset(0) );
  2397   case TypePtr::AnyNull:
  2398     if( _ptr == TypePtr::Constant) return this;
  2399     return make( meet_ptr(TypePtr::AnyNull) );
  2400   default: ShouldNotReachHere();
  2402   return this;
  2405 //------------------------------xdual------------------------------------------
  2406 // Dual: compute field-by-field dual
  2407 const Type *TypeRawPtr::xdual() const {
  2408   return new TypeRawPtr( dual_ptr(), _bits );
  2411 //------------------------------add_offset-------------------------------------
  2412 const TypePtr *TypeRawPtr::add_offset( intptr_t offset ) const {
  2413   if( offset == OffsetTop ) return BOTTOM; // Undefined offset-> undefined pointer
  2414   if( offset == OffsetBot ) return BOTTOM; // Unknown offset-> unknown pointer
  2415   if( offset == 0 ) return this; // No change
  2416   switch (_ptr) {
  2417   case TypePtr::TopPTR:
  2418   case TypePtr::BotPTR:
  2419   case TypePtr::NotNull:
  2420     return this;
  2421   case TypePtr::Null:
  2422   case TypePtr::Constant: {
  2423     address bits = _bits+offset;
  2424     if ( bits == 0 ) return TypePtr::NULL_PTR;
  2425     return make( bits );
  2427   default:  ShouldNotReachHere();
  2429   return NULL;                  // Lint noise
  2432 //------------------------------eq---------------------------------------------
  2433 // Structural equality check for Type representations
  2434 bool TypeRawPtr::eq( const Type *t ) const {
  2435   const TypeRawPtr *a = (const TypeRawPtr*)t;
  2436   return _bits == a->_bits && TypePtr::eq(t);
  2439 //------------------------------hash-------------------------------------------
  2440 // Type-specific hashing function.
  2441 int TypeRawPtr::hash(void) const {
  2442   return (intptr_t)_bits + TypePtr::hash();
  2445 //------------------------------dump2------------------------------------------
  2446 #ifndef PRODUCT
  2447 void TypeRawPtr::dump2( Dict &d, uint depth, outputStream *st ) const {
  2448   if( _ptr == Constant )
  2449     st->print(INTPTR_FORMAT, _bits);
  2450   else
  2451     st->print("rawptr:%s", ptr_msg[_ptr]);
  2453 #endif
  2455 //=============================================================================
  2456 // Convenience common pre-built type.
  2457 const TypeOopPtr *TypeOopPtr::BOTTOM;
  2459 //------------------------------TypeOopPtr-------------------------------------
  2460 TypeOopPtr::TypeOopPtr(TYPES t, PTR ptr, ciKlass* k, bool xk, ciObject* o, int offset, int instance_id, const TypeOopPtr* speculative)
  2461   : TypePtr(t, ptr, offset),
  2462     _const_oop(o), _klass(k),
  2463     _klass_is_exact(xk),
  2464     _is_ptr_to_narrowoop(false),
  2465     _is_ptr_to_narrowklass(false),
  2466     _is_ptr_to_boxed_value(false),
  2467     _instance_id(instance_id),
  2468     _speculative(speculative) {
  2469   if (Compile::current()->eliminate_boxing() && (t == InstPtr) &&
  2470       (offset > 0) && xk && (k != 0) && k->is_instance_klass()) {
  2471     _is_ptr_to_boxed_value = k->as_instance_klass()->is_boxed_value_offset(offset);
  2473 #ifdef _LP64
  2474   if (_offset != 0) {
  2475     if (_offset == oopDesc::klass_offset_in_bytes()) {
  2476       _is_ptr_to_narrowklass = UseCompressedClassPointers;
  2477     } else if (klass() == NULL) {
  2478       // Array with unknown body type
  2479       assert(this->isa_aryptr(), "only arrays without klass");
  2480       _is_ptr_to_narrowoop = UseCompressedOops;
  2481     } else if (this->isa_aryptr()) {
  2482       _is_ptr_to_narrowoop = (UseCompressedOops && klass()->is_obj_array_klass() &&
  2483                              _offset != arrayOopDesc::length_offset_in_bytes());
  2484     } else if (klass()->is_instance_klass()) {
  2485       ciInstanceKlass* ik = klass()->as_instance_klass();
  2486       ciField* field = NULL;
  2487       if (this->isa_klassptr()) {
  2488         // Perm objects don't use compressed references
  2489       } else if (_offset == OffsetBot || _offset == OffsetTop) {
  2490         // unsafe access
  2491         _is_ptr_to_narrowoop = UseCompressedOops;
  2492       } else { // exclude unsafe ops
  2493         assert(this->isa_instptr(), "must be an instance ptr.");
  2495         if (klass() == ciEnv::current()->Class_klass() &&
  2496             (_offset == java_lang_Class::klass_offset_in_bytes() ||
  2497              _offset == java_lang_Class::array_klass_offset_in_bytes())) {
  2498           // Special hidden fields from the Class.
  2499           assert(this->isa_instptr(), "must be an instance ptr.");
  2500           _is_ptr_to_narrowoop = false;
  2501         } else if (klass() == ciEnv::current()->Class_klass() &&
  2502                    _offset >= InstanceMirrorKlass::offset_of_static_fields()) {
  2503           // Static fields
  2504           assert(o != NULL, "must be constant");
  2505           ciInstanceKlass* k = o->as_instance()->java_lang_Class_klass()->as_instance_klass();
  2506           ciField* field = k->get_field_by_offset(_offset, true);
  2507           assert(field != NULL, "missing field");
  2508           BasicType basic_elem_type = field->layout_type();
  2509           _is_ptr_to_narrowoop = UseCompressedOops && (basic_elem_type == T_OBJECT ||
  2510                                                        basic_elem_type == T_ARRAY);
  2511         } else {
  2512           // Instance fields which contains a compressed oop references.
  2513           field = ik->get_field_by_offset(_offset, false);
  2514           if (field != NULL) {
  2515             BasicType basic_elem_type = field->layout_type();
  2516             _is_ptr_to_narrowoop = UseCompressedOops && (basic_elem_type == T_OBJECT ||
  2517                                                          basic_elem_type == T_ARRAY);
  2518           } else if (klass()->equals(ciEnv::current()->Object_klass())) {
  2519             // Compile::find_alias_type() cast exactness on all types to verify
  2520             // that it does not affect alias type.
  2521             _is_ptr_to_narrowoop = UseCompressedOops;
  2522           } else {
  2523             // Type for the copy start in LibraryCallKit::inline_native_clone().
  2524             _is_ptr_to_narrowoop = UseCompressedOops;
  2530 #endif
  2533 //------------------------------make-------------------------------------------
  2534 const TypeOopPtr *TypeOopPtr::make(PTR ptr,
  2535                                    int offset, int instance_id, const TypeOopPtr* speculative) {
  2536   assert(ptr != Constant, "no constant generic pointers");
  2537   ciKlass*  k = Compile::current()->env()->Object_klass();
  2538   bool      xk = false;
  2539   ciObject* o = NULL;
  2540   return (TypeOopPtr*)(new TypeOopPtr(OopPtr, ptr, k, xk, o, offset, instance_id, speculative))->hashcons();
  2544 //------------------------------cast_to_ptr_type-------------------------------
  2545 const Type *TypeOopPtr::cast_to_ptr_type(PTR ptr) const {
  2546   assert(_base == OopPtr, "subclass must override cast_to_ptr_type");
  2547   if( ptr == _ptr ) return this;
  2548   return make(ptr, _offset, _instance_id, _speculative);
  2551 //-----------------------------cast_to_instance_id----------------------------
  2552 const TypeOopPtr *TypeOopPtr::cast_to_instance_id(int instance_id) const {
  2553   // There are no instances of a general oop.
  2554   // Return self unchanged.
  2555   return this;
  2558 //-----------------------------cast_to_exactness-------------------------------
  2559 const Type *TypeOopPtr::cast_to_exactness(bool klass_is_exact) const {
  2560   // There is no such thing as an exact general oop.
  2561   // Return self unchanged.
  2562   return this;
  2566 //------------------------------as_klass_type----------------------------------
  2567 // Return the klass type corresponding to this instance or array type.
  2568 // It is the type that is loaded from an object of this type.
  2569 const TypeKlassPtr* TypeOopPtr::as_klass_type() const {
  2570   ciKlass* k = klass();
  2571   bool    xk = klass_is_exact();
  2572   if (k == NULL)
  2573     return TypeKlassPtr::OBJECT;
  2574   else
  2575     return TypeKlassPtr::make(xk? Constant: NotNull, k, 0);
  2578 const Type *TypeOopPtr::xmeet(const Type *t) const {
  2579   const Type* res = xmeet_helper(t);
  2580   if (res->isa_oopptr() == NULL) {
  2581     return res;
  2584   const TypeOopPtr* res_oopptr = res->is_oopptr();
  2585   if (res_oopptr->speculative() != NULL) {
  2586     // type->speculative() == NULL means that speculation is no better
  2587     // than type, i.e. type->speculative() == type. So there are 2
  2588     // ways to represent the fact that we have no useful speculative
  2589     // data and we should use a single one to be able to test for
  2590     // equality between types. Check whether type->speculative() ==
  2591     // type and set speculative to NULL if it is the case.
  2592     if (res_oopptr->remove_speculative() == res_oopptr->speculative()) {
  2593       return res_oopptr->remove_speculative();
  2597   return res;
  2600 //------------------------------meet-------------------------------------------
  2601 // Compute the MEET of two types.  It returns a new Type object.
  2602 const Type *TypeOopPtr::xmeet_helper(const Type *t) const {
  2603   // Perform a fast test for common case; meeting the same types together.
  2604   if( this == t ) return this;  // Meeting same type-rep?
  2606   // Current "this->_base" is OopPtr
  2607   switch (t->base()) {          // switch on original type
  2609   case Int:                     // Mixing ints & oops happens when javac
  2610   case Long:                    // reuses local variables
  2611   case FloatTop:
  2612   case FloatCon:
  2613   case FloatBot:
  2614   case DoubleTop:
  2615   case DoubleCon:
  2616   case DoubleBot:
  2617   case NarrowOop:
  2618   case NarrowKlass:
  2619   case Bottom:                  // Ye Olde Default
  2620     return Type::BOTTOM;
  2621   case Top:
  2622     return this;
  2624   default:                      // All else is a mistake
  2625     typerr(t);
  2627   case RawPtr:
  2628   case MetadataPtr:
  2629   case KlassPtr:
  2630     return TypePtr::BOTTOM;     // Oop meet raw is not well defined
  2632   case AnyPtr: {
  2633     // Found an AnyPtr type vs self-OopPtr type
  2634     const TypePtr *tp = t->is_ptr();
  2635     int offset = meet_offset(tp->offset());
  2636     PTR ptr = meet_ptr(tp->ptr());
  2637     switch (tp->ptr()) {
  2638     case Null:
  2639       if (ptr == Null)  return TypePtr::make(AnyPtr, ptr, offset);
  2640       // else fall through:
  2641     case TopPTR:
  2642     case AnyNull: {
  2643       int instance_id = meet_instance_id(InstanceTop);
  2644       const TypeOopPtr* speculative = _speculative;
  2645       return make(ptr, offset, instance_id, speculative);
  2647     case BotPTR:
  2648     case NotNull:
  2649       return TypePtr::make(AnyPtr, ptr, offset);
  2650     default: typerr(t);
  2654   case OopPtr: {                 // Meeting to other OopPtrs
  2655     const TypeOopPtr *tp = t->is_oopptr();
  2656     int instance_id = meet_instance_id(tp->instance_id());
  2657     const TypeOopPtr* speculative = xmeet_speculative(tp);
  2658     return make(meet_ptr(tp->ptr()), meet_offset(tp->offset()), instance_id, speculative);
  2661   case InstPtr:                  // For these, flip the call around to cut down
  2662   case AryPtr:
  2663     return t->xmeet(this);      // Call in reverse direction
  2665   } // End of switch
  2666   return this;                  // Return the double constant
  2670 //------------------------------xdual------------------------------------------
  2671 // Dual of a pure heap pointer.  No relevant klass or oop information.
  2672 const Type *TypeOopPtr::xdual() const {
  2673   assert(klass() == Compile::current()->env()->Object_klass(), "no klasses here");
  2674   assert(const_oop() == NULL,             "no constants here");
  2675   return new TypeOopPtr(_base, dual_ptr(), klass(), klass_is_exact(), const_oop(), dual_offset(), dual_instance_id(), dual_speculative());
  2678 //--------------------------make_from_klass_common-----------------------------
  2679 // Computes the element-type given a klass.
  2680 const TypeOopPtr* TypeOopPtr::make_from_klass_common(ciKlass *klass, bool klass_change, bool try_for_exact) {
  2681   if (klass->is_instance_klass()) {
  2682     Compile* C = Compile::current();
  2683     Dependencies* deps = C->dependencies();
  2684     assert((deps != NULL) == (C->method() != NULL && C->method()->code_size() > 0), "sanity");
  2685     // Element is an instance
  2686     bool klass_is_exact = false;
  2687     if (klass->is_loaded()) {
  2688       // Try to set klass_is_exact.
  2689       ciInstanceKlass* ik = klass->as_instance_klass();
  2690       klass_is_exact = ik->is_final();
  2691       if (!klass_is_exact && klass_change
  2692           && deps != NULL && UseUniqueSubclasses) {
  2693         ciInstanceKlass* sub = ik->unique_concrete_subklass();
  2694         if (sub != NULL) {
  2695           deps->assert_abstract_with_unique_concrete_subtype(ik, sub);
  2696           klass = ik = sub;
  2697           klass_is_exact = sub->is_final();
  2700       if (!klass_is_exact && try_for_exact
  2701           && deps != NULL && UseExactTypes) {
  2702         if (!ik->is_interface() && !ik->has_subklass()) {
  2703           // Add a dependence; if concrete subclass added we need to recompile
  2704           deps->assert_leaf_type(ik);
  2705           klass_is_exact = true;
  2709     return TypeInstPtr::make(TypePtr::BotPTR, klass, klass_is_exact, NULL, 0);
  2710   } else if (klass->is_obj_array_klass()) {
  2711     // Element is an object array. Recursively call ourself.
  2712     const TypeOopPtr *etype = TypeOopPtr::make_from_klass_common(klass->as_obj_array_klass()->element_klass(), false, try_for_exact);
  2713     bool xk = etype->klass_is_exact();
  2714     const TypeAry* arr0 = TypeAry::make(etype, TypeInt::POS);
  2715     // We used to pass NotNull in here, asserting that the sub-arrays
  2716     // are all not-null.  This is not true in generally, as code can
  2717     // slam NULLs down in the subarrays.
  2718     const TypeAryPtr* arr = TypeAryPtr::make(TypePtr::BotPTR, arr0, klass, xk, 0);
  2719     return arr;
  2720   } else if (klass->is_type_array_klass()) {
  2721     // Element is an typeArray
  2722     const Type* etype = get_const_basic_type(klass->as_type_array_klass()->element_type());
  2723     const TypeAry* arr0 = TypeAry::make(etype, TypeInt::POS);
  2724     // We used to pass NotNull in here, asserting that the array pointer
  2725     // is not-null. That was not true in general.
  2726     const TypeAryPtr* arr = TypeAryPtr::make(TypePtr::BotPTR, arr0, klass, true, 0);
  2727     return arr;
  2728   } else {
  2729     ShouldNotReachHere();
  2730     return NULL;
  2734 //------------------------------make_from_constant-----------------------------
  2735 // Make a java pointer from an oop constant
  2736 const TypeOopPtr* TypeOopPtr::make_from_constant(ciObject* o,
  2737                                                  bool require_constant,
  2738                                                  bool is_autobox_cache) {
  2739   assert(!o->is_null_object(), "null object not yet handled here.");
  2740   ciKlass* klass = o->klass();
  2741   if (klass->is_instance_klass()) {
  2742     // Element is an instance
  2743     if (require_constant) {
  2744       if (!o->can_be_constant())  return NULL;
  2745     } else if (!o->should_be_constant()) {
  2746       return TypeInstPtr::make(TypePtr::NotNull, klass, true, NULL, 0);
  2748     return TypeInstPtr::make(o);
  2749   } else if (klass->is_obj_array_klass()) {
  2750     // Element is an object array. Recursively call ourself.
  2751     const TypeOopPtr *etype =
  2752       TypeOopPtr::make_from_klass_raw(klass->as_obj_array_klass()->element_klass());
  2753     if (is_autobox_cache) {
  2754       // The pointers in the autobox arrays are always non-null.
  2755       etype = etype->cast_to_ptr_type(TypePtr::NotNull)->is_oopptr();
  2757     const TypeAry* arr0 = TypeAry::make(etype, TypeInt::make(o->as_array()->length()));
  2758     // We used to pass NotNull in here, asserting that the sub-arrays
  2759     // are all not-null.  This is not true in generally, as code can
  2760     // slam NULLs down in the subarrays.
  2761     if (require_constant) {
  2762       if (!o->can_be_constant())  return NULL;
  2763     } else if (!o->should_be_constant()) {
  2764       return TypeAryPtr::make(TypePtr::NotNull, arr0, klass, true, 0);
  2766     const TypeAryPtr* arr = TypeAryPtr::make(TypePtr::Constant, o, arr0, klass, true, 0, InstanceBot, NULL, is_autobox_cache);
  2767     return arr;
  2768   } else if (klass->is_type_array_klass()) {
  2769     // Element is an typeArray
  2770     const Type* etype =
  2771       (Type*)get_const_basic_type(klass->as_type_array_klass()->element_type());
  2772     const TypeAry* arr0 = TypeAry::make(etype, TypeInt::make(o->as_array()->length()));
  2773     // We used to pass NotNull in here, asserting that the array pointer
  2774     // is not-null. That was not true in general.
  2775     if (require_constant) {
  2776       if (!o->can_be_constant())  return NULL;
  2777     } else if (!o->should_be_constant()) {
  2778       return TypeAryPtr::make(TypePtr::NotNull, arr0, klass, true, 0);
  2780     const TypeAryPtr* arr = TypeAryPtr::make(TypePtr::Constant, o, arr0, klass, true, 0);
  2781     return arr;
  2784   fatal("unhandled object type");
  2785   return NULL;
  2788 //------------------------------get_con----------------------------------------
  2789 intptr_t TypeOopPtr::get_con() const {
  2790   assert( _ptr == Null || _ptr == Constant, "" );
  2791   assert( _offset >= 0, "" );
  2793   if (_offset != 0) {
  2794     // After being ported to the compiler interface, the compiler no longer
  2795     // directly manipulates the addresses of oops.  Rather, it only has a pointer
  2796     // to a handle at compile time.  This handle is embedded in the generated
  2797     // code and dereferenced at the time the nmethod is made.  Until that time,
  2798     // it is not reasonable to do arithmetic with the addresses of oops (we don't
  2799     // have access to the addresses!).  This does not seem to currently happen,
  2800     // but this assertion here is to help prevent its occurence.
  2801     tty->print_cr("Found oop constant with non-zero offset");
  2802     ShouldNotReachHere();
  2805   return (intptr_t)const_oop()->constant_encoding();
  2809 //-----------------------------filter------------------------------------------
  2810 // Do not allow interface-vs.-noninterface joins to collapse to top.
  2811 const Type *TypeOopPtr::filter_helper(const Type *kills, bool include_speculative) const {
  2813   const Type* ft = join_helper(kills, include_speculative);
  2814   const TypeInstPtr* ftip = ft->isa_instptr();
  2815   const TypeInstPtr* ktip = kills->isa_instptr();
  2817   if (ft->empty()) {
  2818     // Check for evil case of 'this' being a class and 'kills' expecting an
  2819     // interface.  This can happen because the bytecodes do not contain
  2820     // enough type info to distinguish a Java-level interface variable
  2821     // from a Java-level object variable.  If we meet 2 classes which
  2822     // both implement interface I, but their meet is at 'j/l/O' which
  2823     // doesn't implement I, we have no way to tell if the result should
  2824     // be 'I' or 'j/l/O'.  Thus we'll pick 'j/l/O'.  If this then flows
  2825     // into a Phi which "knows" it's an Interface type we'll have to
  2826     // uplift the type.
  2827     if (!empty() && ktip != NULL && ktip->is_loaded() && ktip->klass()->is_interface())
  2828       return kills;             // Uplift to interface
  2830     return Type::TOP;           // Canonical empty value
  2833   // If we have an interface-typed Phi or cast and we narrow to a class type,
  2834   // the join should report back the class.  However, if we have a J/L/Object
  2835   // class-typed Phi and an interface flows in, it's possible that the meet &
  2836   // join report an interface back out.  This isn't possible but happens
  2837   // because the type system doesn't interact well with interfaces.
  2838   if (ftip != NULL && ktip != NULL &&
  2839       ftip->is_loaded() &&  ftip->klass()->is_interface() &&
  2840       ktip->is_loaded() && !ktip->klass()->is_interface()) {
  2841     // Happens in a CTW of rt.jar, 320-341, no extra flags
  2842     assert(!ftip->klass_is_exact(), "interface could not be exact");
  2843     return ktip->cast_to_ptr_type(ftip->ptr());
  2846   return ft;
  2849 //------------------------------eq---------------------------------------------
  2850 // Structural equality check for Type representations
  2851 bool TypeOopPtr::eq( const Type *t ) const {
  2852   const TypeOopPtr *a = (const TypeOopPtr*)t;
  2853   if (_klass_is_exact != a->_klass_is_exact ||
  2854       _instance_id != a->_instance_id ||
  2855       !eq_speculative(a))  return false;
  2856   ciObject* one = const_oop();
  2857   ciObject* two = a->const_oop();
  2858   if (one == NULL || two == NULL) {
  2859     return (one == two) && TypePtr::eq(t);
  2860   } else {
  2861     return one->equals(two) && TypePtr::eq(t);
  2865 //------------------------------hash-------------------------------------------
  2866 // Type-specific hashing function.
  2867 int TypeOopPtr::hash(void) const {
  2868   return
  2869     (const_oop() ? const_oop()->hash() : 0) +
  2870     _klass_is_exact +
  2871     _instance_id +
  2872     hash_speculative() +
  2873     TypePtr::hash();
  2876 //------------------------------dump2------------------------------------------
  2877 #ifndef PRODUCT
  2878 void TypeOopPtr::dump2( Dict &d, uint depth, outputStream *st ) const {
  2879   st->print("oopptr:%s", ptr_msg[_ptr]);
  2880   if( _klass_is_exact ) st->print(":exact");
  2881   if( const_oop() ) st->print(INTPTR_FORMAT, const_oop());
  2882   switch( _offset ) {
  2883   case OffsetTop: st->print("+top"); break;
  2884   case OffsetBot: st->print("+any"); break;
  2885   case         0: break;
  2886   default:        st->print("+%d",_offset); break;
  2888   if (_instance_id == InstanceTop)
  2889     st->print(",iid=top");
  2890   else if (_instance_id != InstanceBot)
  2891     st->print(",iid=%d",_instance_id);
  2893   dump_speculative(st);
  2896 /**
  2897  *dump the speculative part of the type
  2898  */
  2899 void TypeOopPtr::dump_speculative(outputStream *st) const {
  2900   if (_speculative != NULL) {
  2901     st->print(" (speculative=");
  2902     _speculative->dump_on(st);
  2903     st->print(")");
  2906 #endif
  2908 //------------------------------singleton--------------------------------------
  2909 // TRUE if Type is a singleton type, FALSE otherwise.   Singletons are simple
  2910 // constants
  2911 bool TypeOopPtr::singleton(void) const {
  2912   // detune optimizer to not generate constant oop + constant offset as a constant!
  2913   // TopPTR, Null, AnyNull, Constant are all singletons
  2914   return (_offset == 0) && !below_centerline(_ptr);
  2917 //------------------------------add_offset-------------------------------------
  2918 const TypePtr *TypeOopPtr::add_offset(intptr_t offset) const {
  2919   return make(_ptr, xadd_offset(offset), _instance_id, add_offset_speculative(offset));
  2922 /**
  2923  * Return same type without a speculative part
  2924  */
  2925 const Type* TypeOopPtr::remove_speculative() const {
  2926   if (_speculative == NULL) {
  2927     return this;
  2929   return make(_ptr, _offset, _instance_id, NULL);
  2932 //------------------------------meet_instance_id--------------------------------
  2933 int TypeOopPtr::meet_instance_id( int instance_id ) const {
  2934   // Either is 'TOP' instance?  Return the other instance!
  2935   if( _instance_id == InstanceTop ) return  instance_id;
  2936   if(  instance_id == InstanceTop ) return _instance_id;
  2937   // If either is different, return 'BOTTOM' instance
  2938   if( _instance_id != instance_id ) return InstanceBot;
  2939   return _instance_id;
  2942 //------------------------------dual_instance_id--------------------------------
  2943 int TypeOopPtr::dual_instance_id( ) const {
  2944   if( _instance_id == InstanceTop ) return InstanceBot; // Map TOP into BOTTOM
  2945   if( _instance_id == InstanceBot ) return InstanceTop; // Map BOTTOM into TOP
  2946   return _instance_id;              // Map everything else into self
  2949 /**
  2950  * meet of the speculative parts of 2 types
  2952  * @param other  type to meet with
  2953  */
  2954 const TypeOopPtr* TypeOopPtr::xmeet_speculative(const TypeOopPtr* other) const {
  2955   bool this_has_spec = (_speculative != NULL);
  2956   bool other_has_spec = (other->speculative() != NULL);
  2958   if (!this_has_spec && !other_has_spec) {
  2959     return NULL;
  2962   // If we are at a point where control flow meets and one branch has
  2963   // a speculative type and the other has not, we meet the speculative
  2964   // type of one branch with the actual type of the other. If the
  2965   // actual type is exact and the speculative is as well, then the
  2966   // result is a speculative type which is exact and we can continue
  2967   // speculation further.
  2968   const TypeOopPtr* this_spec = _speculative;
  2969   const TypeOopPtr* other_spec = other->speculative();
  2971   if (!this_has_spec) {
  2972     this_spec = this;
  2975   if (!other_has_spec) {
  2976     other_spec = other;
  2979   return this_spec->meet_speculative(other_spec)->is_oopptr();
  2982 /**
  2983  * dual of the speculative part of the type
  2984  */
  2985 const TypeOopPtr* TypeOopPtr::dual_speculative() const {
  2986   if (_speculative == NULL) {
  2987     return NULL;
  2989   return _speculative->dual()->is_oopptr();
  2992 /**
  2993  * add offset to the speculative part of the type
  2995  * @param offset  offset to add
  2996  */
  2997 const TypeOopPtr* TypeOopPtr::add_offset_speculative(intptr_t offset) const {
  2998   if (_speculative == NULL) {
  2999     return NULL;
  3001   return _speculative->add_offset(offset)->is_oopptr();
  3004 /**
  3005  * Are the speculative parts of 2 types equal?
  3007  * @param other  type to compare this one to
  3008  */
  3009 bool TypeOopPtr::eq_speculative(const TypeOopPtr* other) const {
  3010   if (_speculative == NULL || other->speculative() == NULL) {
  3011     return _speculative == other->speculative();
  3014   if (_speculative->base() != other->speculative()->base()) {
  3015     return false;
  3018   return _speculative->eq(other->speculative());
  3021 /**
  3022  * Hash of the speculative part of the type
  3023  */
  3024 int TypeOopPtr::hash_speculative() const {
  3025   if (_speculative == NULL) {
  3026     return 0;
  3029   return _speculative->hash();
  3033 //=============================================================================
  3034 // Convenience common pre-built types.
  3035 const TypeInstPtr *TypeInstPtr::NOTNULL;
  3036 const TypeInstPtr *TypeInstPtr::BOTTOM;
  3037 const TypeInstPtr *TypeInstPtr::MIRROR;
  3038 const TypeInstPtr *TypeInstPtr::MARK;
  3039 const TypeInstPtr *TypeInstPtr::KLASS;
  3041 //------------------------------TypeInstPtr-------------------------------------
  3042 TypeInstPtr::TypeInstPtr(PTR ptr, ciKlass* k, bool xk, ciObject* o, int off, int instance_id, const TypeOopPtr* speculative)
  3043   : TypeOopPtr(InstPtr, ptr, k, xk, o, off, instance_id, speculative), _name(k->name()) {
  3044    assert(k != NULL &&
  3045           (k->is_loaded() || o == NULL),
  3046           "cannot have constants with non-loaded klass");
  3047 };
  3049 //------------------------------make-------------------------------------------
  3050 const TypeInstPtr *TypeInstPtr::make(PTR ptr,
  3051                                      ciKlass* k,
  3052                                      bool xk,
  3053                                      ciObject* o,
  3054                                      int offset,
  3055                                      int instance_id,
  3056                                      const TypeOopPtr* speculative) {
  3057   assert( !k->is_loaded() || k->is_instance_klass(), "Must be for instance");
  3058   // Either const_oop() is NULL or else ptr is Constant
  3059   assert( (!o && ptr != Constant) || (o && ptr == Constant),
  3060           "constant pointers must have a value supplied" );
  3061   // Ptr is never Null
  3062   assert( ptr != Null, "NULL pointers are not typed" );
  3064   assert(instance_id <= 0 || xk || !UseExactTypes, "instances are always exactly typed");
  3065   if (!UseExactTypes)  xk = false;
  3066   if (ptr == Constant) {
  3067     // Note:  This case includes meta-object constants, such as methods.
  3068     xk = true;
  3069   } else if (k->is_loaded()) {
  3070     ciInstanceKlass* ik = k->as_instance_klass();
  3071     if (!xk && ik->is_final())     xk = true;   // no inexact final klass
  3072     if (xk && ik->is_interface())  xk = false;  // no exact interface
  3075   // Now hash this baby
  3076   TypeInstPtr *result =
  3077     (TypeInstPtr*)(new TypeInstPtr(ptr, k, xk, o ,offset, instance_id, speculative))->hashcons();
  3079   return result;
  3082 /**
  3083  *  Create constant type for a constant boxed value
  3084  */
  3085 const Type* TypeInstPtr::get_const_boxed_value() const {
  3086   assert(is_ptr_to_boxed_value(), "should be called only for boxed value");
  3087   assert((const_oop() != NULL), "should be called only for constant object");
  3088   ciConstant constant = const_oop()->as_instance()->field_value_by_offset(offset());
  3089   BasicType bt = constant.basic_type();
  3090   switch (bt) {
  3091     case T_BOOLEAN:  return TypeInt::make(constant.as_boolean());
  3092     case T_INT:      return TypeInt::make(constant.as_int());
  3093     case T_CHAR:     return TypeInt::make(constant.as_char());
  3094     case T_BYTE:     return TypeInt::make(constant.as_byte());
  3095     case T_SHORT:    return TypeInt::make(constant.as_short());
  3096     case T_FLOAT:    return TypeF::make(constant.as_float());
  3097     case T_DOUBLE:   return TypeD::make(constant.as_double());
  3098     case T_LONG:     return TypeLong::make(constant.as_long());
  3099     default:         break;
  3101   fatal(err_msg_res("Invalid boxed value type '%s'", type2name(bt)));
  3102   return NULL;
  3105 //------------------------------cast_to_ptr_type-------------------------------
  3106 const Type *TypeInstPtr::cast_to_ptr_type(PTR ptr) const {
  3107   if( ptr == _ptr ) return this;
  3108   // Reconstruct _sig info here since not a problem with later lazy
  3109   // construction, _sig will show up on demand.
  3110   return make(ptr, klass(), klass_is_exact(), const_oop(), _offset, _instance_id, _speculative);
  3114 //-----------------------------cast_to_exactness-------------------------------
  3115 const Type *TypeInstPtr::cast_to_exactness(bool klass_is_exact) const {
  3116   if( klass_is_exact == _klass_is_exact ) return this;
  3117   if (!UseExactTypes)  return this;
  3118   if (!_klass->is_loaded())  return this;
  3119   ciInstanceKlass* ik = _klass->as_instance_klass();
  3120   if( (ik->is_final() || _const_oop) )  return this;  // cannot clear xk
  3121   if( ik->is_interface() )              return this;  // cannot set xk
  3122   return make(ptr(), klass(), klass_is_exact, const_oop(), _offset, _instance_id, _speculative);
  3125 //-----------------------------cast_to_instance_id----------------------------
  3126 const TypeOopPtr *TypeInstPtr::cast_to_instance_id(int instance_id) const {
  3127   if( instance_id == _instance_id ) return this;
  3128   return make(_ptr, klass(), _klass_is_exact, const_oop(), _offset, instance_id, _speculative);
  3131 //------------------------------xmeet_unloaded---------------------------------
  3132 // Compute the MEET of two InstPtrs when at least one is unloaded.
  3133 // Assume classes are different since called after check for same name/class-loader
  3134 const TypeInstPtr *TypeInstPtr::xmeet_unloaded(const TypeInstPtr *tinst) const {
  3135     int off = meet_offset(tinst->offset());
  3136     PTR ptr = meet_ptr(tinst->ptr());
  3137     int instance_id = meet_instance_id(tinst->instance_id());
  3138     const TypeOopPtr* speculative = xmeet_speculative(tinst);
  3140     const TypeInstPtr *loaded    = is_loaded() ? this  : tinst;
  3141     const TypeInstPtr *unloaded  = is_loaded() ? tinst : this;
  3142     if( loaded->klass()->equals(ciEnv::current()->Object_klass()) ) {
  3143       //
  3144       // Meet unloaded class with java/lang/Object
  3145       //
  3146       // Meet
  3147       //          |                     Unloaded Class
  3148       //  Object  |   TOP    |   AnyNull | Constant |   NotNull |  BOTTOM   |
  3149       //  ===================================================================
  3150       //   TOP    | ..........................Unloaded......................|
  3151       //  AnyNull |  U-AN    |................Unloaded......................|
  3152       // Constant | ... O-NN .................................. |   O-BOT   |
  3153       //  NotNull | ... O-NN .................................. |   O-BOT   |
  3154       //  BOTTOM  | ........................Object-BOTTOM ..................|
  3155       //
  3156       assert(loaded->ptr() != TypePtr::Null, "insanity check");
  3157       //
  3158       if(      loaded->ptr() == TypePtr::TopPTR ) { return unloaded; }
  3159       else if (loaded->ptr() == TypePtr::AnyNull) { return TypeInstPtr::make(ptr, unloaded->klass(), false, NULL, off, instance_id, speculative); }
  3160       else if (loaded->ptr() == TypePtr::BotPTR ) { return TypeInstPtr::BOTTOM; }
  3161       else if (loaded->ptr() == TypePtr::Constant || loaded->ptr() == TypePtr::NotNull) {
  3162         if (unloaded->ptr() == TypePtr::BotPTR  ) { return TypeInstPtr::BOTTOM;  }
  3163         else                                      { return TypeInstPtr::NOTNULL; }
  3165       else if( unloaded->ptr() == TypePtr::TopPTR )  { return unloaded; }
  3167       return unloaded->cast_to_ptr_type(TypePtr::AnyNull)->is_instptr();
  3170     // Both are unloaded, not the same class, not Object
  3171     // Or meet unloaded with a different loaded class, not java/lang/Object
  3172     if( ptr != TypePtr::BotPTR ) {
  3173       return TypeInstPtr::NOTNULL;
  3175     return TypeInstPtr::BOTTOM;
  3179 //------------------------------meet-------------------------------------------
  3180 // Compute the MEET of two types.  It returns a new Type object.
  3181 const Type *TypeInstPtr::xmeet_helper(const Type *t) const {
  3182   // Perform a fast test for common case; meeting the same types together.
  3183   if( this == t ) return this;  // Meeting same type-rep?
  3185   // Current "this->_base" is Pointer
  3186   switch (t->base()) {          // switch on original type
  3188   case Int:                     // Mixing ints & oops happens when javac
  3189   case Long:                    // reuses local variables
  3190   case FloatTop:
  3191   case FloatCon:
  3192   case FloatBot:
  3193   case DoubleTop:
  3194   case DoubleCon:
  3195   case DoubleBot:
  3196   case NarrowOop:
  3197   case NarrowKlass:
  3198   case Bottom:                  // Ye Olde Default
  3199     return Type::BOTTOM;
  3200   case Top:
  3201     return this;
  3203   default:                      // All else is a mistake
  3204     typerr(t);
  3206   case MetadataPtr:
  3207   case KlassPtr:
  3208   case RawPtr: return TypePtr::BOTTOM;
  3210   case AryPtr: {                // All arrays inherit from Object class
  3211     const TypeAryPtr *tp = t->is_aryptr();
  3212     int offset = meet_offset(tp->offset());
  3213     PTR ptr = meet_ptr(tp->ptr());
  3214     int instance_id = meet_instance_id(tp->instance_id());
  3215     const TypeOopPtr* speculative = xmeet_speculative(tp);
  3216     switch (ptr) {
  3217     case TopPTR:
  3218     case AnyNull:                // Fall 'down' to dual of object klass
  3219       // For instances when a subclass meets a superclass we fall
  3220       // below the centerline when the superclass is exact. We need to
  3221       // do the same here.
  3222       if (klass()->equals(ciEnv::current()->Object_klass()) && !klass_is_exact()) {
  3223         return TypeAryPtr::make(ptr, tp->ary(), tp->klass(), tp->klass_is_exact(), offset, instance_id, speculative);
  3224       } else {
  3225         // cannot subclass, so the meet has to fall badly below the centerline
  3226         ptr = NotNull;
  3227         instance_id = InstanceBot;
  3228         return TypeInstPtr::make( ptr, ciEnv::current()->Object_klass(), false, NULL, offset, instance_id, speculative);
  3230     case Constant:
  3231     case NotNull:
  3232     case BotPTR:                // Fall down to object klass
  3233       // LCA is object_klass, but if we subclass from the top we can do better
  3234       if( above_centerline(_ptr) ) { // if( _ptr == TopPTR || _ptr == AnyNull )
  3235         // If 'this' (InstPtr) is above the centerline and it is Object class
  3236         // then we can subclass in the Java class hierarchy.
  3237         // For instances when a subclass meets a superclass we fall
  3238         // below the centerline when the superclass is exact. We need
  3239         // to do the same here.
  3240         if (klass()->equals(ciEnv::current()->Object_klass()) && !klass_is_exact()) {
  3241           // that is, tp's array type is a subtype of my klass
  3242           return TypeAryPtr::make(ptr, (ptr == Constant ? tp->const_oop() : NULL),
  3243                                   tp->ary(), tp->klass(), tp->klass_is_exact(), offset, instance_id, speculative);
  3246       // The other case cannot happen, since I cannot be a subtype of an array.
  3247       // The meet falls down to Object class below centerline.
  3248       if( ptr == Constant )
  3249          ptr = NotNull;
  3250       instance_id = InstanceBot;
  3251       return make(ptr, ciEnv::current()->Object_klass(), false, NULL, offset, instance_id, speculative);
  3252     default: typerr(t);
  3256   case OopPtr: {                // Meeting to OopPtrs
  3257     // Found a OopPtr type vs self-InstPtr type
  3258     const TypeOopPtr *tp = t->is_oopptr();
  3259     int offset = meet_offset(tp->offset());
  3260     PTR ptr = meet_ptr(tp->ptr());
  3261     switch (tp->ptr()) {
  3262     case TopPTR:
  3263     case AnyNull: {
  3264       int instance_id = meet_instance_id(InstanceTop);
  3265       const TypeOopPtr* speculative = xmeet_speculative(tp);
  3266       return make(ptr, klass(), klass_is_exact(),
  3267                   (ptr == Constant ? const_oop() : NULL), offset, instance_id, speculative);
  3269     case NotNull:
  3270     case BotPTR: {
  3271       int instance_id = meet_instance_id(tp->instance_id());
  3272       const TypeOopPtr* speculative = xmeet_speculative(tp);
  3273       return TypeOopPtr::make(ptr, offset, instance_id, speculative);
  3275     default: typerr(t);
  3279   case AnyPtr: {                // Meeting to AnyPtrs
  3280     // Found an AnyPtr type vs self-InstPtr type
  3281     const TypePtr *tp = t->is_ptr();
  3282     int offset = meet_offset(tp->offset());
  3283     PTR ptr = meet_ptr(tp->ptr());
  3284     switch (tp->ptr()) {
  3285     case Null:
  3286       if( ptr == Null ) return TypePtr::make(AnyPtr, ptr, offset);
  3287       // else fall through to AnyNull
  3288     case TopPTR:
  3289     case AnyNull: {
  3290       int instance_id = meet_instance_id(InstanceTop);
  3291       const TypeOopPtr* speculative = _speculative;
  3292       return make(ptr, klass(), klass_is_exact(),
  3293                   (ptr == Constant ? const_oop() : NULL), offset, instance_id, speculative);
  3295     case NotNull:
  3296     case BotPTR:
  3297       return TypePtr::make(AnyPtr, ptr, offset);
  3298     default: typerr(t);
  3302   /*
  3303                  A-top         }
  3304                /   |   \       }  Tops
  3305            B-top A-any C-top   }
  3306               | /  |  \ |      }  Any-nulls
  3307            B-any   |   C-any   }
  3308               |    |    |
  3309            B-con A-con C-con   } constants; not comparable across classes
  3310               |    |    |
  3311            B-not   |   C-not   }
  3312               | \  |  / |      }  not-nulls
  3313            B-bot A-not C-bot   }
  3314                \   |   /       }  Bottoms
  3315                  A-bot         }
  3316   */
  3318   case InstPtr: {                // Meeting 2 Oops?
  3319     // Found an InstPtr sub-type vs self-InstPtr type
  3320     const TypeInstPtr *tinst = t->is_instptr();
  3321     int off = meet_offset( tinst->offset() );
  3322     PTR ptr = meet_ptr( tinst->ptr() );
  3323     int instance_id = meet_instance_id(tinst->instance_id());
  3324     const TypeOopPtr* speculative = xmeet_speculative(tinst);
  3326     // Check for easy case; klasses are equal (and perhaps not loaded!)
  3327     // If we have constants, then we created oops so classes are loaded
  3328     // and we can handle the constants further down.  This case handles
  3329     // both-not-loaded or both-loaded classes
  3330     if (ptr != Constant && klass()->equals(tinst->klass()) && klass_is_exact() == tinst->klass_is_exact()) {
  3331       return make(ptr, klass(), klass_is_exact(), NULL, off, instance_id, speculative);
  3334     // Classes require inspection in the Java klass hierarchy.  Must be loaded.
  3335     ciKlass* tinst_klass = tinst->klass();
  3336     ciKlass* this_klass  = this->klass();
  3337     bool tinst_xk = tinst->klass_is_exact();
  3338     bool this_xk  = this->klass_is_exact();
  3339     if (!tinst_klass->is_loaded() || !this_klass->is_loaded() ) {
  3340       // One of these classes has not been loaded
  3341       const TypeInstPtr *unloaded_meet = xmeet_unloaded(tinst);
  3342 #ifndef PRODUCT
  3343       if( PrintOpto && Verbose ) {
  3344         tty->print("meet of unloaded classes resulted in: "); unloaded_meet->dump(); tty->cr();
  3345         tty->print("  this == "); this->dump(); tty->cr();
  3346         tty->print(" tinst == "); tinst->dump(); tty->cr();
  3348 #endif
  3349       return unloaded_meet;
  3352     // Handle mixing oops and interfaces first.
  3353     if( this_klass->is_interface() && !(tinst_klass->is_interface() ||
  3354                                         tinst_klass == ciEnv::current()->Object_klass())) {
  3355       ciKlass *tmp = tinst_klass; // Swap interface around
  3356       tinst_klass = this_klass;
  3357       this_klass = tmp;
  3358       bool tmp2 = tinst_xk;
  3359       tinst_xk = this_xk;
  3360       this_xk = tmp2;
  3362     if (tinst_klass->is_interface() &&
  3363         !(this_klass->is_interface() ||
  3364           // Treat java/lang/Object as an honorary interface,
  3365           // because we need a bottom for the interface hierarchy.
  3366           this_klass == ciEnv::current()->Object_klass())) {
  3367       // Oop meets interface!
  3369       // See if the oop subtypes (implements) interface.
  3370       ciKlass *k;
  3371       bool xk;
  3372       if( this_klass->is_subtype_of( tinst_klass ) ) {
  3373         // Oop indeed subtypes.  Now keep oop or interface depending
  3374         // on whether we are both above the centerline or either is
  3375         // below the centerline.  If we are on the centerline
  3376         // (e.g., Constant vs. AnyNull interface), use the constant.
  3377         k  = below_centerline(ptr) ? tinst_klass : this_klass;
  3378         // If we are keeping this_klass, keep its exactness too.
  3379         xk = below_centerline(ptr) ? tinst_xk    : this_xk;
  3380       } else {                  // Does not implement, fall to Object
  3381         // Oop does not implement interface, so mixing falls to Object
  3382         // just like the verifier does (if both are above the
  3383         // centerline fall to interface)
  3384         k = above_centerline(ptr) ? tinst_klass : ciEnv::current()->Object_klass();
  3385         xk = above_centerline(ptr) ? tinst_xk : false;
  3386         // Watch out for Constant vs. AnyNull interface.
  3387         if (ptr == Constant)  ptr = NotNull;   // forget it was a constant
  3388         instance_id = InstanceBot;
  3390       ciObject* o = NULL;  // the Constant value, if any
  3391       if (ptr == Constant) {
  3392         // Find out which constant.
  3393         o = (this_klass == klass()) ? const_oop() : tinst->const_oop();
  3395       return make(ptr, k, xk, o, off, instance_id, speculative);
  3398     // Either oop vs oop or interface vs interface or interface vs Object
  3400     // !!! Here's how the symmetry requirement breaks down into invariants:
  3401     // If we split one up & one down AND they subtype, take the down man.
  3402     // If we split one up & one down AND they do NOT subtype, "fall hard".
  3403     // If both are up and they subtype, take the subtype class.
  3404     // If both are up and they do NOT subtype, "fall hard".
  3405     // If both are down and they subtype, take the supertype class.
  3406     // If both are down and they do NOT subtype, "fall hard".
  3407     // Constants treated as down.
  3409     // Now, reorder the above list; observe that both-down+subtype is also
  3410     // "fall hard"; "fall hard" becomes the default case:
  3411     // If we split one up & one down AND they subtype, take the down man.
  3412     // If both are up and they subtype, take the subtype class.
  3414     // If both are down and they subtype, "fall hard".
  3415     // If both are down and they do NOT subtype, "fall hard".
  3416     // If both are up and they do NOT subtype, "fall hard".
  3417     // If we split one up & one down AND they do NOT subtype, "fall hard".
  3419     // If a proper subtype is exact, and we return it, we return it exactly.
  3420     // If a proper supertype is exact, there can be no subtyping relationship!
  3421     // If both types are equal to the subtype, exactness is and-ed below the
  3422     // centerline and or-ed above it.  (N.B. Constants are always exact.)
  3424     // Check for subtyping:
  3425     ciKlass *subtype = NULL;
  3426     bool subtype_exact = false;
  3427     if( tinst_klass->equals(this_klass) ) {
  3428       subtype = this_klass;
  3429       subtype_exact = below_centerline(ptr) ? (this_xk & tinst_xk) : (this_xk | tinst_xk);
  3430     } else if( !tinst_xk && this_klass->is_subtype_of( tinst_klass ) ) {
  3431       subtype = this_klass;     // Pick subtyping class
  3432       subtype_exact = this_xk;
  3433     } else if( !this_xk && tinst_klass->is_subtype_of( this_klass ) ) {
  3434       subtype = tinst_klass;    // Pick subtyping class
  3435       subtype_exact = tinst_xk;
  3438     if( subtype ) {
  3439       if( above_centerline(ptr) ) { // both are up?
  3440         this_klass = tinst_klass = subtype;
  3441         this_xk = tinst_xk = subtype_exact;
  3442       } else if( above_centerline(this ->_ptr) && !above_centerline(tinst->_ptr) ) {
  3443         this_klass = tinst_klass; // tinst is down; keep down man
  3444         this_xk = tinst_xk;
  3445       } else if( above_centerline(tinst->_ptr) && !above_centerline(this ->_ptr) ) {
  3446         tinst_klass = this_klass; // this is down; keep down man
  3447         tinst_xk = this_xk;
  3448       } else {
  3449         this_xk = subtype_exact;  // either they are equal, or we'll do an LCA
  3453     // Check for classes now being equal
  3454     if (tinst_klass->equals(this_klass)) {
  3455       // If the klasses are equal, the constants may still differ.  Fall to
  3456       // NotNull if they do (neither constant is NULL; that is a special case
  3457       // handled elsewhere).
  3458       ciObject* o = NULL;             // Assume not constant when done
  3459       ciObject* this_oop  = const_oop();
  3460       ciObject* tinst_oop = tinst->const_oop();
  3461       if( ptr == Constant ) {
  3462         if (this_oop != NULL && tinst_oop != NULL &&
  3463             this_oop->equals(tinst_oop) )
  3464           o = this_oop;
  3465         else if (above_centerline(this ->_ptr))
  3466           o = tinst_oop;
  3467         else if (above_centerline(tinst ->_ptr))
  3468           o = this_oop;
  3469         else
  3470           ptr = NotNull;
  3472       return make(ptr, this_klass, this_xk, o, off, instance_id, speculative);
  3473     } // Else classes are not equal
  3475     // Since klasses are different, we require a LCA in the Java
  3476     // class hierarchy - which means we have to fall to at least NotNull.
  3477     if( ptr == TopPTR || ptr == AnyNull || ptr == Constant )
  3478       ptr = NotNull;
  3479     instance_id = InstanceBot;
  3481     // Now we find the LCA of Java classes
  3482     ciKlass* k = this_klass->least_common_ancestor(tinst_klass);
  3483     return make(ptr, k, false, NULL, off, instance_id, speculative);
  3484   } // End of case InstPtr
  3486   } // End of switch
  3487   return this;                  // Return the double constant
  3491 //------------------------java_mirror_type--------------------------------------
  3492 ciType* TypeInstPtr::java_mirror_type() const {
  3493   // must be a singleton type
  3494   if( const_oop() == NULL )  return NULL;
  3496   // must be of type java.lang.Class
  3497   if( klass() != ciEnv::current()->Class_klass() )  return NULL;
  3499   return const_oop()->as_instance()->java_mirror_type();
  3503 //------------------------------xdual------------------------------------------
  3504 // Dual: do NOT dual on klasses.  This means I do NOT understand the Java
  3505 // inheritance mechanism.
  3506 const Type *TypeInstPtr::xdual() const {
  3507   return new TypeInstPtr(dual_ptr(), klass(), klass_is_exact(), const_oop(), dual_offset(), dual_instance_id(), dual_speculative());
  3510 //------------------------------eq---------------------------------------------
  3511 // Structural equality check for Type representations
  3512 bool TypeInstPtr::eq( const Type *t ) const {
  3513   const TypeInstPtr *p = t->is_instptr();
  3514   return
  3515     klass()->equals(p->klass()) &&
  3516     TypeOopPtr::eq(p);          // Check sub-type stuff
  3519 //------------------------------hash-------------------------------------------
  3520 // Type-specific hashing function.
  3521 int TypeInstPtr::hash(void) const {
  3522   int hash = klass()->hash() + TypeOopPtr::hash();
  3523   return hash;
  3526 //------------------------------dump2------------------------------------------
  3527 // Dump oop Type
  3528 #ifndef PRODUCT
  3529 void TypeInstPtr::dump2( Dict &d, uint depth, outputStream *st ) const {
  3530   // Print the name of the klass.
  3531   klass()->print_name_on(st);
  3533   switch( _ptr ) {
  3534   case Constant:
  3535     // TO DO: Make CI print the hex address of the underlying oop.
  3536     if (WizardMode || Verbose) {
  3537       const_oop()->print_oop(st);
  3539   case BotPTR:
  3540     if (!WizardMode && !Verbose) {
  3541       if( _klass_is_exact ) st->print(":exact");
  3542       break;
  3544   case TopPTR:
  3545   case AnyNull:
  3546   case NotNull:
  3547     st->print(":%s", ptr_msg[_ptr]);
  3548     if( _klass_is_exact ) st->print(":exact");
  3549     break;
  3552   if( _offset ) {               // Dump offset, if any
  3553     if( _offset == OffsetBot )      st->print("+any");
  3554     else if( _offset == OffsetTop ) st->print("+unknown");
  3555     else st->print("+%d", _offset);
  3558   st->print(" *");
  3559   if (_instance_id == InstanceTop)
  3560     st->print(",iid=top");
  3561   else if (_instance_id != InstanceBot)
  3562     st->print(",iid=%d",_instance_id);
  3564   dump_speculative(st);
  3566 #endif
  3568 //------------------------------add_offset-------------------------------------
  3569 const TypePtr *TypeInstPtr::add_offset(intptr_t offset) const {
  3570   return make(_ptr, klass(), klass_is_exact(), const_oop(), xadd_offset(offset), _instance_id, add_offset_speculative(offset));
  3573 const Type *TypeInstPtr::remove_speculative() const {
  3574   if (_speculative == NULL) {
  3575     return this;
  3577   return make(_ptr, klass(), klass_is_exact(), const_oop(), _offset, _instance_id, NULL);
  3580 //=============================================================================
  3581 // Convenience common pre-built types.
  3582 const TypeAryPtr *TypeAryPtr::RANGE;
  3583 const TypeAryPtr *TypeAryPtr::OOPS;
  3584 const TypeAryPtr *TypeAryPtr::NARROWOOPS;
  3585 const TypeAryPtr *TypeAryPtr::BYTES;
  3586 const TypeAryPtr *TypeAryPtr::SHORTS;
  3587 const TypeAryPtr *TypeAryPtr::CHARS;
  3588 const TypeAryPtr *TypeAryPtr::INTS;
  3589 const TypeAryPtr *TypeAryPtr::LONGS;
  3590 const TypeAryPtr *TypeAryPtr::FLOATS;
  3591 const TypeAryPtr *TypeAryPtr::DOUBLES;
  3593 //------------------------------make-------------------------------------------
  3594 const TypeAryPtr *TypeAryPtr::make(PTR ptr, const TypeAry *ary, ciKlass* k, bool xk, int offset, int instance_id, const TypeOopPtr* speculative) {
  3595   assert(!(k == NULL && ary->_elem->isa_int()),
  3596          "integral arrays must be pre-equipped with a class");
  3597   if (!xk)  xk = ary->ary_must_be_exact();
  3598   assert(instance_id <= 0 || xk || !UseExactTypes, "instances are always exactly typed");
  3599   if (!UseExactTypes)  xk = (ptr == Constant);
  3600   return (TypeAryPtr*)(new TypeAryPtr(ptr, NULL, ary, k, xk, offset, instance_id, false, speculative))->hashcons();
  3603 //------------------------------make-------------------------------------------
  3604 const TypeAryPtr *TypeAryPtr::make(PTR ptr, ciObject* o, const TypeAry *ary, ciKlass* k, bool xk, int offset, int instance_id, const TypeOopPtr* speculative, bool is_autobox_cache) {
  3605   assert(!(k == NULL && ary->_elem->isa_int()),
  3606          "integral arrays must be pre-equipped with a class");
  3607   assert( (ptr==Constant && o) || (ptr!=Constant && !o), "" );
  3608   if (!xk)  xk = (o != NULL) || ary->ary_must_be_exact();
  3609   assert(instance_id <= 0 || xk || !UseExactTypes, "instances are always exactly typed");
  3610   if (!UseExactTypes)  xk = (ptr == Constant);
  3611   return (TypeAryPtr*)(new TypeAryPtr(ptr, o, ary, k, xk, offset, instance_id, is_autobox_cache, speculative))->hashcons();
  3614 //------------------------------cast_to_ptr_type-------------------------------
  3615 const Type *TypeAryPtr::cast_to_ptr_type(PTR ptr) const {
  3616   if( ptr == _ptr ) return this;
  3617   return make(ptr, const_oop(), _ary, klass(), klass_is_exact(), _offset, _instance_id, _speculative);
  3621 //-----------------------------cast_to_exactness-------------------------------
  3622 const Type *TypeAryPtr::cast_to_exactness(bool klass_is_exact) const {
  3623   if( klass_is_exact == _klass_is_exact ) return this;
  3624   if (!UseExactTypes)  return this;
  3625   if (_ary->ary_must_be_exact())  return this;  // cannot clear xk
  3626   return make(ptr(), const_oop(), _ary, klass(), klass_is_exact, _offset, _instance_id, _speculative);
  3629 //-----------------------------cast_to_instance_id----------------------------
  3630 const TypeOopPtr *TypeAryPtr::cast_to_instance_id(int instance_id) const {
  3631   if( instance_id == _instance_id ) return this;
  3632   return make(_ptr, const_oop(), _ary, klass(), _klass_is_exact, _offset, instance_id, _speculative);
  3635 //-----------------------------narrow_size_type-------------------------------
  3636 // Local cache for arrayOopDesc::max_array_length(etype),
  3637 // which is kind of slow (and cached elsewhere by other users).
  3638 static jint max_array_length_cache[T_CONFLICT+1];
  3639 static jint max_array_length(BasicType etype) {
  3640   jint& cache = max_array_length_cache[etype];
  3641   jint res = cache;
  3642   if (res == 0) {
  3643     switch (etype) {
  3644     case T_NARROWOOP:
  3645       etype = T_OBJECT;
  3646       break;
  3647     case T_NARROWKLASS:
  3648     case T_CONFLICT:
  3649     case T_ILLEGAL:
  3650     case T_VOID:
  3651       etype = T_BYTE;           // will produce conservatively high value
  3653     cache = res = arrayOopDesc::max_array_length(etype);
  3655   return res;
  3658 // Narrow the given size type to the index range for the given array base type.
  3659 // Return NULL if the resulting int type becomes empty.
  3660 const TypeInt* TypeAryPtr::narrow_size_type(const TypeInt* size) const {
  3661   jint hi = size->_hi;
  3662   jint lo = size->_lo;
  3663   jint min_lo = 0;
  3664   jint max_hi = max_array_length(elem()->basic_type());
  3665   //if (index_not_size)  --max_hi;     // type of a valid array index, FTR
  3666   bool chg = false;
  3667   if (lo < min_lo) {
  3668     lo = min_lo;
  3669     if (size->is_con()) {
  3670       hi = lo;
  3672     chg = true;
  3674   if (hi > max_hi) {
  3675     hi = max_hi;
  3676     if (size->is_con()) {
  3677       lo = hi;
  3679     chg = true;
  3681   // Negative length arrays will produce weird intermediate dead fast-path code
  3682   if (lo > hi)
  3683     return TypeInt::ZERO;
  3684   if (!chg)
  3685     return size;
  3686   return TypeInt::make(lo, hi, Type::WidenMin);
  3689 //-------------------------------cast_to_size----------------------------------
  3690 const TypeAryPtr* TypeAryPtr::cast_to_size(const TypeInt* new_size) const {
  3691   assert(new_size != NULL, "");
  3692   new_size = narrow_size_type(new_size);
  3693   if (new_size == size())  return this;
  3694   const TypeAry* new_ary = TypeAry::make(elem(), new_size, is_stable());
  3695   return make(ptr(), const_oop(), new_ary, klass(), klass_is_exact(), _offset, _instance_id, _speculative);
  3699 //------------------------------cast_to_stable---------------------------------
  3700 const TypeAryPtr* TypeAryPtr::cast_to_stable(bool stable, int stable_dimension) const {
  3701   if (stable_dimension <= 0 || (stable_dimension == 1 && stable == this->is_stable()))
  3702     return this;
  3704   const Type* elem = this->elem();
  3705   const TypePtr* elem_ptr = elem->make_ptr();
  3707   if (stable_dimension > 1 && elem_ptr != NULL && elem_ptr->isa_aryptr()) {
  3708     // If this is widened from a narrow oop, TypeAry::make will re-narrow it.
  3709     elem = elem_ptr = elem_ptr->is_aryptr()->cast_to_stable(stable, stable_dimension - 1);
  3712   const TypeAry* new_ary = TypeAry::make(elem, size(), stable);
  3714   return make(ptr(), const_oop(), new_ary, klass(), klass_is_exact(), _offset, _instance_id);
  3717 //-----------------------------stable_dimension--------------------------------
  3718 int TypeAryPtr::stable_dimension() const {
  3719   if (!is_stable())  return 0;
  3720   int dim = 1;
  3721   const TypePtr* elem_ptr = elem()->make_ptr();
  3722   if (elem_ptr != NULL && elem_ptr->isa_aryptr())
  3723     dim += elem_ptr->is_aryptr()->stable_dimension();
  3724   return dim;
  3727 //------------------------------eq---------------------------------------------
  3728 // Structural equality check for Type representations
  3729 bool TypeAryPtr::eq( const Type *t ) const {
  3730   const TypeAryPtr *p = t->is_aryptr();
  3731   return
  3732     _ary == p->_ary &&  // Check array
  3733     TypeOopPtr::eq(p);  // Check sub-parts
  3736 //------------------------------hash-------------------------------------------
  3737 // Type-specific hashing function.
  3738 int TypeAryPtr::hash(void) const {
  3739   return (intptr_t)_ary + TypeOopPtr::hash();
  3742 //------------------------------meet-------------------------------------------
  3743 // Compute the MEET of two types.  It returns a new Type object.
  3744 const Type *TypeAryPtr::xmeet_helper(const Type *t) const {
  3745   // Perform a fast test for common case; meeting the same types together.
  3746   if( this == t ) return this;  // Meeting same type-rep?
  3747   // Current "this->_base" is Pointer
  3748   switch (t->base()) {          // switch on original type
  3750   // Mixing ints & oops happens when javac reuses local variables
  3751   case Int:
  3752   case Long:
  3753   case FloatTop:
  3754   case FloatCon:
  3755   case FloatBot:
  3756   case DoubleTop:
  3757   case DoubleCon:
  3758   case DoubleBot:
  3759   case NarrowOop:
  3760   case NarrowKlass:
  3761   case Bottom:                  // Ye Olde Default
  3762     return Type::BOTTOM;
  3763   case Top:
  3764     return this;
  3766   default:                      // All else is a mistake
  3767     typerr(t);
  3769   case OopPtr: {                // Meeting to OopPtrs
  3770     // Found a OopPtr type vs self-AryPtr type
  3771     const TypeOopPtr *tp = t->is_oopptr();
  3772     int offset = meet_offset(tp->offset());
  3773     PTR ptr = meet_ptr(tp->ptr());
  3774     switch (tp->ptr()) {
  3775     case TopPTR:
  3776     case AnyNull: {
  3777       int instance_id = meet_instance_id(InstanceTop);
  3778       const TypeOopPtr* speculative = xmeet_speculative(tp);
  3779       return make(ptr, (ptr == Constant ? const_oop() : NULL),
  3780                   _ary, _klass, _klass_is_exact, offset, instance_id, speculative);
  3782     case BotPTR:
  3783     case NotNull: {
  3784       int instance_id = meet_instance_id(tp->instance_id());
  3785       const TypeOopPtr* speculative = xmeet_speculative(tp);
  3786       return TypeOopPtr::make(ptr, offset, instance_id, speculative);
  3788     default: ShouldNotReachHere();
  3792   case AnyPtr: {                // Meeting two AnyPtrs
  3793     // Found an AnyPtr type vs self-AryPtr type
  3794     const TypePtr *tp = t->is_ptr();
  3795     int offset = meet_offset(tp->offset());
  3796     PTR ptr = meet_ptr(tp->ptr());
  3797     switch (tp->ptr()) {
  3798     case TopPTR:
  3799       return this;
  3800     case BotPTR:
  3801     case NotNull:
  3802       return TypePtr::make(AnyPtr, ptr, offset);
  3803     case Null:
  3804       if( ptr == Null ) return TypePtr::make(AnyPtr, ptr, offset);
  3805       // else fall through to AnyNull
  3806     case AnyNull: {
  3807       int instance_id = meet_instance_id(InstanceTop);
  3808       const TypeOopPtr* speculative = _speculative;
  3809       return make(ptr, (ptr == Constant ? const_oop() : NULL),
  3810                   _ary, _klass, _klass_is_exact, offset, instance_id, speculative);
  3812     default: ShouldNotReachHere();
  3816   case MetadataPtr:
  3817   case KlassPtr:
  3818   case RawPtr: return TypePtr::BOTTOM;
  3820   case AryPtr: {                // Meeting 2 references?
  3821     const TypeAryPtr *tap = t->is_aryptr();
  3822     int off = meet_offset(tap->offset());
  3823     const TypeAry *tary = _ary->meet_speculative(tap->_ary)->is_ary();
  3824     PTR ptr = meet_ptr(tap->ptr());
  3825     int instance_id = meet_instance_id(tap->instance_id());
  3826     const TypeOopPtr* speculative = xmeet_speculative(tap);
  3827     ciKlass* lazy_klass = NULL;
  3828     if (tary->_elem->isa_int()) {
  3829       // Integral array element types have irrelevant lattice relations.
  3830       // It is the klass that determines array layout, not the element type.
  3831       if (_klass == NULL)
  3832         lazy_klass = tap->_klass;
  3833       else if (tap->_klass == NULL || tap->_klass == _klass) {
  3834         lazy_klass = _klass;
  3835       } else {
  3836         // Something like byte[int+] meets char[int+].
  3837         // This must fall to bottom, not (int[-128..65535])[int+].
  3838         instance_id = InstanceBot;
  3839         tary = TypeAry::make(Type::BOTTOM, tary->_size, tary->_stable);
  3841     } else // Non integral arrays.
  3842       // Must fall to bottom if exact klasses in upper lattice
  3843       // are not equal or super klass is exact.
  3844       if ((above_centerline(ptr) || ptr == Constant) && klass() != tap->klass() &&
  3845           // meet with top[] and bottom[] are processed further down:
  3846           tap->_klass != NULL  && this->_klass != NULL   &&
  3847           // both are exact and not equal:
  3848           ((tap->_klass_is_exact && this->_klass_is_exact) ||
  3849            // 'tap'  is exact and super or unrelated:
  3850            (tap->_klass_is_exact && !tap->klass()->is_subtype_of(klass())) ||
  3851            // 'this' is exact and super or unrelated:
  3852            (this->_klass_is_exact && !klass()->is_subtype_of(tap->klass())))) {
  3853       tary = TypeAry::make(Type::BOTTOM, tary->_size, tary->_stable);
  3854       return make(NotNull, NULL, tary, lazy_klass, false, off, InstanceBot);
  3857     bool xk = false;
  3858     switch (tap->ptr()) {
  3859     case AnyNull:
  3860     case TopPTR:
  3861       // Compute new klass on demand, do not use tap->_klass
  3862       if (below_centerline(this->_ptr)) {
  3863         xk = this->_klass_is_exact;
  3864       } else {
  3865         xk = (tap->_klass_is_exact | this->_klass_is_exact);
  3867       return make(ptr, const_oop(), tary, lazy_klass, xk, off, instance_id, speculative);
  3868     case Constant: {
  3869       ciObject* o = const_oop();
  3870       if( _ptr == Constant ) {
  3871         if( tap->const_oop() != NULL && !o->equals(tap->const_oop()) ) {
  3872           xk = (klass() == tap->klass());
  3873           ptr = NotNull;
  3874           o = NULL;
  3875           instance_id = InstanceBot;
  3876         } else {
  3877           xk = true;
  3879       } else if(above_centerline(_ptr)) {
  3880         o = tap->const_oop();
  3881         xk = true;
  3882       } else {
  3883         // Only precise for identical arrays
  3884         xk = this->_klass_is_exact && (klass() == tap->klass());
  3886       return TypeAryPtr::make(ptr, o, tary, lazy_klass, xk, off, instance_id, speculative);
  3888     case NotNull:
  3889     case BotPTR:
  3890       // Compute new klass on demand, do not use tap->_klass
  3891       if (above_centerline(this->_ptr))
  3892             xk = tap->_klass_is_exact;
  3893       else  xk = (tap->_klass_is_exact & this->_klass_is_exact) &&
  3894               (klass() == tap->klass()); // Only precise for identical arrays
  3895       return TypeAryPtr::make(ptr, NULL, tary, lazy_klass, xk, off, instance_id, speculative);
  3896     default: ShouldNotReachHere();
  3900   // All arrays inherit from Object class
  3901   case InstPtr: {
  3902     const TypeInstPtr *tp = t->is_instptr();
  3903     int offset = meet_offset(tp->offset());
  3904     PTR ptr = meet_ptr(tp->ptr());
  3905     int instance_id = meet_instance_id(tp->instance_id());
  3906     const TypeOopPtr* speculative = xmeet_speculative(tp);
  3907     switch (ptr) {
  3908     case TopPTR:
  3909     case AnyNull:                // Fall 'down' to dual of object klass
  3910       // For instances when a subclass meets a superclass we fall
  3911       // below the centerline when the superclass is exact. We need to
  3912       // do the same here.
  3913       if (tp->klass()->equals(ciEnv::current()->Object_klass()) && !tp->klass_is_exact()) {
  3914         return TypeAryPtr::make(ptr, _ary, _klass, _klass_is_exact, offset, instance_id, speculative);
  3915       } else {
  3916         // cannot subclass, so the meet has to fall badly below the centerline
  3917         ptr = NotNull;
  3918         instance_id = InstanceBot;
  3919         return TypeInstPtr::make(ptr, ciEnv::current()->Object_klass(), false, NULL,offset, instance_id, speculative);
  3921     case Constant:
  3922     case NotNull:
  3923     case BotPTR:                // Fall down to object klass
  3924       // LCA is object_klass, but if we subclass from the top we can do better
  3925       if (above_centerline(tp->ptr())) {
  3926         // If 'tp'  is above the centerline and it is Object class
  3927         // then we can subclass in the Java class hierarchy.
  3928         // For instances when a subclass meets a superclass we fall
  3929         // below the centerline when the superclass is exact. We need
  3930         // to do the same here.
  3931         if (tp->klass()->equals(ciEnv::current()->Object_klass()) && !tp->klass_is_exact()) {
  3932           // that is, my array type is a subtype of 'tp' klass
  3933           return make(ptr, (ptr == Constant ? const_oop() : NULL),
  3934                       _ary, _klass, _klass_is_exact, offset, instance_id, speculative);
  3937       // The other case cannot happen, since t cannot be a subtype of an array.
  3938       // The meet falls down to Object class below centerline.
  3939       if( ptr == Constant )
  3940          ptr = NotNull;
  3941       instance_id = InstanceBot;
  3942       return TypeInstPtr::make(ptr, ciEnv::current()->Object_klass(), false, NULL,offset, instance_id, speculative);
  3943     default: typerr(t);
  3947   return this;                  // Lint noise
  3950 //------------------------------xdual------------------------------------------
  3951 // Dual: compute field-by-field dual
  3952 const Type *TypeAryPtr::xdual() const {
  3953   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());
  3956 //----------------------interface_vs_oop---------------------------------------
  3957 #ifdef ASSERT
  3958 bool TypeAryPtr::interface_vs_oop(const Type *t) const {
  3959   const TypeAryPtr* t_aryptr = t->isa_aryptr();
  3960   if (t_aryptr) {
  3961     return _ary->interface_vs_oop(t_aryptr->_ary);
  3963   return false;
  3965 #endif
  3967 //------------------------------dump2------------------------------------------
  3968 #ifndef PRODUCT
  3969 void TypeAryPtr::dump2( Dict &d, uint depth, outputStream *st ) const {
  3970   _ary->dump2(d,depth,st);
  3971   switch( _ptr ) {
  3972   case Constant:
  3973     const_oop()->print(st);
  3974     break;
  3975   case BotPTR:
  3976     if (!WizardMode && !Verbose) {
  3977       if( _klass_is_exact ) st->print(":exact");
  3978       break;
  3980   case TopPTR:
  3981   case AnyNull:
  3982   case NotNull:
  3983     st->print(":%s", ptr_msg[_ptr]);
  3984     if( _klass_is_exact ) st->print(":exact");
  3985     break;
  3988   if( _offset != 0 ) {
  3989     int header_size = objArrayOopDesc::header_size() * wordSize;
  3990     if( _offset == OffsetTop )       st->print("+undefined");
  3991     else if( _offset == OffsetBot )  st->print("+any");
  3992     else if( _offset < header_size ) st->print("+%d", _offset);
  3993     else {
  3994       BasicType basic_elem_type = elem()->basic_type();
  3995       int array_base = arrayOopDesc::base_offset_in_bytes(basic_elem_type);
  3996       int elem_size = type2aelembytes(basic_elem_type);
  3997       st->print("[%d]", (_offset - array_base)/elem_size);
  4000   st->print(" *");
  4001   if (_instance_id == InstanceTop)
  4002     st->print(",iid=top");
  4003   else if (_instance_id != InstanceBot)
  4004     st->print(",iid=%d",_instance_id);
  4006   dump_speculative(st);
  4008 #endif
  4010 bool TypeAryPtr::empty(void) const {
  4011   if (_ary->empty())       return true;
  4012   return TypeOopPtr::empty();
  4015 //------------------------------add_offset-------------------------------------
  4016 const TypePtr *TypeAryPtr::add_offset(intptr_t offset) const {
  4017   return make(_ptr, _const_oop, _ary, _klass, _klass_is_exact, xadd_offset(offset), _instance_id, add_offset_speculative(offset));
  4020 const Type *TypeAryPtr::remove_speculative() const {
  4021   return make(_ptr, _const_oop, _ary->remove_speculative()->is_ary(), _klass, _klass_is_exact, _offset, _instance_id, NULL);
  4024 //=============================================================================
  4026 //------------------------------hash-------------------------------------------
  4027 // Type-specific hashing function.
  4028 int TypeNarrowPtr::hash(void) const {
  4029   return _ptrtype->hash() + 7;
  4032 bool TypeNarrowPtr::singleton(void) const {    // TRUE if type is a singleton
  4033   return _ptrtype->singleton();
  4036 bool TypeNarrowPtr::empty(void) const {
  4037   return _ptrtype->empty();
  4040 intptr_t TypeNarrowPtr::get_con() const {
  4041   return _ptrtype->get_con();
  4044 bool TypeNarrowPtr::eq( const Type *t ) const {
  4045   const TypeNarrowPtr* tc = isa_same_narrowptr(t);
  4046   if (tc != NULL) {
  4047     if (_ptrtype->base() != tc->_ptrtype->base()) {
  4048       return false;
  4050     return tc->_ptrtype->eq(_ptrtype);
  4052   return false;
  4055 const Type *TypeNarrowPtr::xdual() const {    // Compute dual right now.
  4056   const TypePtr* odual = _ptrtype->dual()->is_ptr();
  4057   return make_same_narrowptr(odual);
  4061 const Type *TypeNarrowPtr::filter_helper(const Type *kills, bool include_speculative) const {
  4062   if (isa_same_narrowptr(kills)) {
  4063     const Type* ft =_ptrtype->filter_helper(is_same_narrowptr(kills)->_ptrtype, include_speculative);
  4064     if (ft->empty())
  4065       return Type::TOP;           // Canonical empty value
  4066     if (ft->isa_ptr()) {
  4067       return make_hash_same_narrowptr(ft->isa_ptr());
  4069     return ft;
  4070   } else if (kills->isa_ptr()) {
  4071     const Type* ft = _ptrtype->join_helper(kills, include_speculative);
  4072     if (ft->empty())
  4073       return Type::TOP;           // Canonical empty value
  4074     return ft;
  4075   } else {
  4076     return Type::TOP;
  4080 //------------------------------xmeet------------------------------------------
  4081 // Compute the MEET of two types.  It returns a new Type object.
  4082 const Type *TypeNarrowPtr::xmeet( const Type *t ) const {
  4083   // Perform a fast test for common case; meeting the same types together.
  4084   if( this == t ) return this;  // Meeting same type-rep?
  4086   if (t->base() == base()) {
  4087     const Type* result = _ptrtype->xmeet(t->make_ptr());
  4088     if (result->isa_ptr()) {
  4089       return make_hash_same_narrowptr(result->is_ptr());
  4091     return result;
  4094   // Current "this->_base" is NarrowKlass or NarrowOop
  4095   switch (t->base()) {          // switch on original type
  4097   case Int:                     // Mixing ints & oops happens when javac
  4098   case Long:                    // reuses local variables
  4099   case FloatTop:
  4100   case FloatCon:
  4101   case FloatBot:
  4102   case DoubleTop:
  4103   case DoubleCon:
  4104   case DoubleBot:
  4105   case AnyPtr:
  4106   case RawPtr:
  4107   case OopPtr:
  4108   case InstPtr:
  4109   case AryPtr:
  4110   case MetadataPtr:
  4111   case KlassPtr:
  4112   case NarrowOop:
  4113   case NarrowKlass:
  4115   case Bottom:                  // Ye Olde Default
  4116     return Type::BOTTOM;
  4117   case Top:
  4118     return this;
  4120   default:                      // All else is a mistake
  4121     typerr(t);
  4123   } // End of switch
  4125   return this;
  4128 #ifndef PRODUCT
  4129 void TypeNarrowPtr::dump2( Dict & d, uint depth, outputStream *st ) const {
  4130   _ptrtype->dump2(d, depth, st);
  4132 #endif
  4134 const TypeNarrowOop *TypeNarrowOop::BOTTOM;
  4135 const TypeNarrowOop *TypeNarrowOop::NULL_PTR;
  4138 const TypeNarrowOop* TypeNarrowOop::make(const TypePtr* type) {
  4139   return (const TypeNarrowOop*)(new TypeNarrowOop(type))->hashcons();
  4143 #ifndef PRODUCT
  4144 void TypeNarrowOop::dump2( Dict & d, uint depth, outputStream *st ) const {
  4145   st->print("narrowoop: ");
  4146   TypeNarrowPtr::dump2(d, depth, st);
  4148 #endif
  4150 const TypeNarrowKlass *TypeNarrowKlass::NULL_PTR;
  4152 const TypeNarrowKlass* TypeNarrowKlass::make(const TypePtr* type) {
  4153   return (const TypeNarrowKlass*)(new TypeNarrowKlass(type))->hashcons();
  4156 #ifndef PRODUCT
  4157 void TypeNarrowKlass::dump2( Dict & d, uint depth, outputStream *st ) const {
  4158   st->print("narrowklass: ");
  4159   TypeNarrowPtr::dump2(d, depth, st);
  4161 #endif
  4164 //------------------------------eq---------------------------------------------
  4165 // Structural equality check for Type representations
  4166 bool TypeMetadataPtr::eq( const Type *t ) const {
  4167   const TypeMetadataPtr *a = (const TypeMetadataPtr*)t;
  4168   ciMetadata* one = metadata();
  4169   ciMetadata* two = a->metadata();
  4170   if (one == NULL || two == NULL) {
  4171     return (one == two) && TypePtr::eq(t);
  4172   } else {
  4173     return one->equals(two) && TypePtr::eq(t);
  4177 //------------------------------hash-------------------------------------------
  4178 // Type-specific hashing function.
  4179 int TypeMetadataPtr::hash(void) const {
  4180   return
  4181     (metadata() ? metadata()->hash() : 0) +
  4182     TypePtr::hash();
  4185 //------------------------------singleton--------------------------------------
  4186 // TRUE if Type is a singleton type, FALSE otherwise.   Singletons are simple
  4187 // constants
  4188 bool TypeMetadataPtr::singleton(void) const {
  4189   // detune optimizer to not generate constant metadta + constant offset as a constant!
  4190   // TopPTR, Null, AnyNull, Constant are all singletons
  4191   return (_offset == 0) && !below_centerline(_ptr);
  4194 //------------------------------add_offset-------------------------------------
  4195 const TypePtr *TypeMetadataPtr::add_offset( intptr_t offset ) const {
  4196   return make( _ptr, _metadata, xadd_offset(offset));
  4199 //-----------------------------filter------------------------------------------
  4200 // Do not allow interface-vs.-noninterface joins to collapse to top.
  4201 const Type *TypeMetadataPtr::filter_helper(const Type *kills, bool include_speculative) const {
  4202   const TypeMetadataPtr* ft = join_helper(kills, include_speculative)->isa_metadataptr();
  4203   if (ft == NULL || ft->empty())
  4204     return Type::TOP;           // Canonical empty value
  4205   return ft;
  4208  //------------------------------get_con----------------------------------------
  4209 intptr_t TypeMetadataPtr::get_con() const {
  4210   assert( _ptr == Null || _ptr == Constant, "" );
  4211   assert( _offset >= 0, "" );
  4213   if (_offset != 0) {
  4214     // After being ported to the compiler interface, the compiler no longer
  4215     // directly manipulates the addresses of oops.  Rather, it only has a pointer
  4216     // to a handle at compile time.  This handle is embedded in the generated
  4217     // code and dereferenced at the time the nmethod is made.  Until that time,
  4218     // it is not reasonable to do arithmetic with the addresses of oops (we don't
  4219     // have access to the addresses!).  This does not seem to currently happen,
  4220     // but this assertion here is to help prevent its occurence.
  4221     tty->print_cr("Found oop constant with non-zero offset");
  4222     ShouldNotReachHere();
  4225   return (intptr_t)metadata()->constant_encoding();
  4228 //------------------------------cast_to_ptr_type-------------------------------
  4229 const Type *TypeMetadataPtr::cast_to_ptr_type(PTR ptr) const {
  4230   if( ptr == _ptr ) return this;
  4231   return make(ptr, metadata(), _offset);
  4234 //------------------------------meet-------------------------------------------
  4235 // Compute the MEET of two types.  It returns a new Type object.
  4236 const Type *TypeMetadataPtr::xmeet( const Type *t ) const {
  4237   // Perform a fast test for common case; meeting the same types together.
  4238   if( this == t ) return this;  // Meeting same type-rep?
  4240   // Current "this->_base" is OopPtr
  4241   switch (t->base()) {          // switch on original type
  4243   case Int:                     // Mixing ints & oops happens when javac
  4244   case Long:                    // reuses local variables
  4245   case FloatTop:
  4246   case FloatCon:
  4247   case FloatBot:
  4248   case DoubleTop:
  4249   case DoubleCon:
  4250   case DoubleBot:
  4251   case NarrowOop:
  4252   case NarrowKlass:
  4253   case Bottom:                  // Ye Olde Default
  4254     return Type::BOTTOM;
  4255   case Top:
  4256     return this;
  4258   default:                      // All else is a mistake
  4259     typerr(t);
  4261   case AnyPtr: {
  4262     // Found an AnyPtr type vs self-OopPtr type
  4263     const TypePtr *tp = t->is_ptr();
  4264     int offset = meet_offset(tp->offset());
  4265     PTR ptr = meet_ptr(tp->ptr());
  4266     switch (tp->ptr()) {
  4267     case Null:
  4268       if (ptr == Null)  return TypePtr::make(AnyPtr, ptr, offset);
  4269       // else fall through:
  4270     case TopPTR:
  4271     case AnyNull: {
  4272       return make(ptr, NULL, offset);
  4274     case BotPTR:
  4275     case NotNull:
  4276       return TypePtr::make(AnyPtr, ptr, offset);
  4277     default: typerr(t);
  4281   case RawPtr:
  4282   case KlassPtr:
  4283   case OopPtr:
  4284   case InstPtr:
  4285   case AryPtr:
  4286     return TypePtr::BOTTOM;     // Oop meet raw is not well defined
  4288   case MetadataPtr: {
  4289     const TypeMetadataPtr *tp = t->is_metadataptr();
  4290     int offset = meet_offset(tp->offset());
  4291     PTR tptr = tp->ptr();
  4292     PTR ptr = meet_ptr(tptr);
  4293     ciMetadata* md = (tptr == TopPTR) ? metadata() : tp->metadata();
  4294     if (tptr == TopPTR || _ptr == TopPTR ||
  4295         metadata()->equals(tp->metadata())) {
  4296       return make(ptr, md, offset);
  4298     // metadata is different
  4299     if( ptr == Constant ) {  // Cannot be equal constants, so...
  4300       if( tptr == Constant && _ptr != Constant)  return t;
  4301       if( _ptr == Constant && tptr != Constant)  return this;
  4302       ptr = NotNull;            // Fall down in lattice
  4304     return make(ptr, NULL, offset);
  4305     break;
  4307   } // End of switch
  4308   return this;                  // Return the double constant
  4312 //------------------------------xdual------------------------------------------
  4313 // Dual of a pure metadata pointer.
  4314 const Type *TypeMetadataPtr::xdual() const {
  4315   return new TypeMetadataPtr(dual_ptr(), metadata(), dual_offset());
  4318 //------------------------------dump2------------------------------------------
  4319 #ifndef PRODUCT
  4320 void TypeMetadataPtr::dump2( Dict &d, uint depth, outputStream *st ) const {
  4321   st->print("metadataptr:%s", ptr_msg[_ptr]);
  4322   if( metadata() ) st->print(INTPTR_FORMAT, metadata());
  4323   switch( _offset ) {
  4324   case OffsetTop: st->print("+top"); break;
  4325   case OffsetBot: st->print("+any"); break;
  4326   case         0: break;
  4327   default:        st->print("+%d",_offset); break;
  4330 #endif
  4333 //=============================================================================
  4334 // Convenience common pre-built type.
  4335 const TypeMetadataPtr *TypeMetadataPtr::BOTTOM;
  4337 TypeMetadataPtr::TypeMetadataPtr(PTR ptr, ciMetadata* metadata, int offset):
  4338   TypePtr(MetadataPtr, ptr, offset), _metadata(metadata) {
  4341 const TypeMetadataPtr* TypeMetadataPtr::make(ciMethod* m) {
  4342   return make(Constant, m, 0);
  4344 const TypeMetadataPtr* TypeMetadataPtr::make(ciMethodData* m) {
  4345   return make(Constant, m, 0);
  4348 //------------------------------make-------------------------------------------
  4349 // Create a meta data constant
  4350 const TypeMetadataPtr *TypeMetadataPtr::make(PTR ptr, ciMetadata* m, int offset) {
  4351   assert(m == NULL || !m->is_klass(), "wrong type");
  4352   return (TypeMetadataPtr*)(new TypeMetadataPtr(ptr, m, offset))->hashcons();
  4356 //=============================================================================
  4357 // Convenience common pre-built types.
  4359 // Not-null object klass or below
  4360 const TypeKlassPtr *TypeKlassPtr::OBJECT;
  4361 const TypeKlassPtr *TypeKlassPtr::OBJECT_OR_NULL;
  4363 //------------------------------TypeKlassPtr-----------------------------------
  4364 TypeKlassPtr::TypeKlassPtr( PTR ptr, ciKlass* klass, int offset )
  4365   : TypePtr(KlassPtr, ptr, offset), _klass(klass), _klass_is_exact(ptr == Constant) {
  4368 //------------------------------make-------------------------------------------
  4369 // ptr to klass 'k', if Constant, or possibly to a sub-klass if not a Constant
  4370 const TypeKlassPtr *TypeKlassPtr::make( PTR ptr, ciKlass* k, int offset ) {
  4371   assert( k != NULL, "Expect a non-NULL klass");
  4372   assert(k->is_instance_klass() || k->is_array_klass(), "Incorrect type of klass oop");
  4373   TypeKlassPtr *r =
  4374     (TypeKlassPtr*)(new TypeKlassPtr(ptr, k, offset))->hashcons();
  4376   return r;
  4379 //------------------------------eq---------------------------------------------
  4380 // Structural equality check for Type representations
  4381 bool TypeKlassPtr::eq( const Type *t ) const {
  4382   const TypeKlassPtr *p = t->is_klassptr();
  4383   return
  4384     klass()->equals(p->klass()) &&
  4385     TypePtr::eq(p);
  4388 //------------------------------hash-------------------------------------------
  4389 // Type-specific hashing function.
  4390 int TypeKlassPtr::hash(void) const {
  4391   return klass()->hash() + TypePtr::hash();
  4394 //------------------------------singleton--------------------------------------
  4395 // TRUE if Type is a singleton type, FALSE otherwise.   Singletons are simple
  4396 // constants
  4397 bool TypeKlassPtr::singleton(void) const {
  4398   // detune optimizer to not generate constant klass + constant offset as a constant!
  4399   // TopPTR, Null, AnyNull, Constant are all singletons
  4400   return (_offset == 0) && !below_centerline(_ptr);
  4403 // Do not allow interface-vs.-noninterface joins to collapse to top.
  4404 const Type *TypeKlassPtr::filter_helper(const Type *kills, bool include_speculative) const {
  4405   // logic here mirrors the one from TypeOopPtr::filter. See comments
  4406   // there.
  4407   const Type* ft = join_helper(kills, include_speculative);
  4408   const TypeKlassPtr* ftkp = ft->isa_klassptr();
  4409   const TypeKlassPtr* ktkp = kills->isa_klassptr();
  4411   if (ft->empty()) {
  4412     if (!empty() && ktkp != NULL && ktkp->klass()->is_loaded() && ktkp->klass()->is_interface())
  4413       return kills;             // Uplift to interface
  4415     return Type::TOP;           // Canonical empty value
  4418   // Interface klass type could be exact in opposite to interface type,
  4419   // return it here instead of incorrect Constant ptr J/L/Object (6894807).
  4420   if (ftkp != NULL && ktkp != NULL &&
  4421       ftkp->is_loaded() &&  ftkp->klass()->is_interface() &&
  4422       !ftkp->klass_is_exact() && // Keep exact interface klass
  4423       ktkp->is_loaded() && !ktkp->klass()->is_interface()) {
  4424     return ktkp->cast_to_ptr_type(ftkp->ptr());
  4427   return ft;
  4430 //----------------------compute_klass------------------------------------------
  4431 // Compute the defining klass for this class
  4432 ciKlass* TypeAryPtr::compute_klass(DEBUG_ONLY(bool verify)) const {
  4433   // Compute _klass based on element type.
  4434   ciKlass* k_ary = NULL;
  4435   const TypeInstPtr *tinst;
  4436   const TypeAryPtr *tary;
  4437   const Type* el = elem();
  4438   if (el->isa_narrowoop()) {
  4439     el = el->make_ptr();
  4442   // Get element klass
  4443   if ((tinst = el->isa_instptr()) != NULL) {
  4444     // Compute array klass from element klass
  4445     k_ary = ciObjArrayKlass::make(tinst->klass());
  4446   } else if ((tary = el->isa_aryptr()) != NULL) {
  4447     // Compute array klass from element klass
  4448     ciKlass* k_elem = tary->klass();
  4449     // If element type is something like bottom[], k_elem will be null.
  4450     if (k_elem != NULL)
  4451       k_ary = ciObjArrayKlass::make(k_elem);
  4452   } else if ((el->base() == Type::Top) ||
  4453              (el->base() == Type::Bottom)) {
  4454     // element type of Bottom occurs from meet of basic type
  4455     // and object; Top occurs when doing join on Bottom.
  4456     // Leave k_ary at NULL.
  4457   } else {
  4458     // Cannot compute array klass directly from basic type,
  4459     // since subtypes of TypeInt all have basic type T_INT.
  4460 #ifdef ASSERT
  4461     if (verify && el->isa_int()) {
  4462       // Check simple cases when verifying klass.
  4463       BasicType bt = T_ILLEGAL;
  4464       if (el == TypeInt::BYTE) {
  4465         bt = T_BYTE;
  4466       } else if (el == TypeInt::SHORT) {
  4467         bt = T_SHORT;
  4468       } else if (el == TypeInt::CHAR) {
  4469         bt = T_CHAR;
  4470       } else if (el == TypeInt::INT) {
  4471         bt = T_INT;
  4472       } else {
  4473         return _klass; // just return specified klass
  4475       return ciTypeArrayKlass::make(bt);
  4477 #endif
  4478     assert(!el->isa_int(),
  4479            "integral arrays must be pre-equipped with a class");
  4480     // Compute array klass directly from basic type
  4481     k_ary = ciTypeArrayKlass::make(el->basic_type());
  4483   return k_ary;
  4486 //------------------------------klass------------------------------------------
  4487 // Return the defining klass for this class
  4488 ciKlass* TypeAryPtr::klass() const {
  4489   if( _klass ) return _klass;   // Return cached value, if possible
  4491   // Oops, need to compute _klass and cache it
  4492   ciKlass* k_ary = compute_klass();
  4494   if( this != TypeAryPtr::OOPS && this->dual() != TypeAryPtr::OOPS ) {
  4495     // The _klass field acts as a cache of the underlying
  4496     // ciKlass for this array type.  In order to set the field,
  4497     // we need to cast away const-ness.
  4498     //
  4499     // IMPORTANT NOTE: we *never* set the _klass field for the
  4500     // type TypeAryPtr::OOPS.  This Type is shared between all
  4501     // active compilations.  However, the ciKlass which represents
  4502     // this Type is *not* shared between compilations, so caching
  4503     // this value would result in fetching a dangling pointer.
  4504     //
  4505     // Recomputing the underlying ciKlass for each request is
  4506     // a bit less efficient than caching, but calls to
  4507     // TypeAryPtr::OOPS->klass() are not common enough to matter.
  4508     ((TypeAryPtr*)this)->_klass = k_ary;
  4509     if (UseCompressedOops && k_ary != NULL && k_ary->is_obj_array_klass() &&
  4510         _offset != 0 && _offset != arrayOopDesc::length_offset_in_bytes()) {
  4511       ((TypeAryPtr*)this)->_is_ptr_to_narrowoop = true;
  4514   return k_ary;
  4518 //------------------------------add_offset-------------------------------------
  4519 // Access internals of klass object
  4520 const TypePtr *TypeKlassPtr::add_offset( intptr_t offset ) const {
  4521   return make( _ptr, klass(), xadd_offset(offset) );
  4524 //------------------------------cast_to_ptr_type-------------------------------
  4525 const Type *TypeKlassPtr::cast_to_ptr_type(PTR ptr) const {
  4526   assert(_base == KlassPtr, "subclass must override cast_to_ptr_type");
  4527   if( ptr == _ptr ) return this;
  4528   return make(ptr, _klass, _offset);
  4532 //-----------------------------cast_to_exactness-------------------------------
  4533 const Type *TypeKlassPtr::cast_to_exactness(bool klass_is_exact) const {
  4534   if( klass_is_exact == _klass_is_exact ) return this;
  4535   if (!UseExactTypes)  return this;
  4536   return make(klass_is_exact ? Constant : NotNull, _klass, _offset);
  4540 //-----------------------------as_instance_type--------------------------------
  4541 // Corresponding type for an instance of the given class.
  4542 // It will be NotNull, and exact if and only if the klass type is exact.
  4543 const TypeOopPtr* TypeKlassPtr::as_instance_type() const {
  4544   ciKlass* k = klass();
  4545   bool    xk = klass_is_exact();
  4546   //return TypeInstPtr::make(TypePtr::NotNull, k, xk, NULL, 0);
  4547   const TypeOopPtr* toop = TypeOopPtr::make_from_klass_raw(k);
  4548   guarantee(toop != NULL, "need type for given klass");
  4549   toop = toop->cast_to_ptr_type(TypePtr::NotNull)->is_oopptr();
  4550   return toop->cast_to_exactness(xk)->is_oopptr();
  4554 //------------------------------xmeet------------------------------------------
  4555 // Compute the MEET of two types, return a new Type object.
  4556 const Type    *TypeKlassPtr::xmeet( const Type *t ) const {
  4557   // Perform a fast test for common case; meeting the same types together.
  4558   if( this == t ) return this;  // Meeting same type-rep?
  4560   // Current "this->_base" is Pointer
  4561   switch (t->base()) {          // switch on original type
  4563   case Int:                     // Mixing ints & oops happens when javac
  4564   case Long:                    // reuses local variables
  4565   case FloatTop:
  4566   case FloatCon:
  4567   case FloatBot:
  4568   case DoubleTop:
  4569   case DoubleCon:
  4570   case DoubleBot:
  4571   case NarrowOop:
  4572   case NarrowKlass:
  4573   case Bottom:                  // Ye Olde Default
  4574     return Type::BOTTOM;
  4575   case Top:
  4576     return this;
  4578   default:                      // All else is a mistake
  4579     typerr(t);
  4581   case AnyPtr: {                // Meeting to AnyPtrs
  4582     // Found an AnyPtr type vs self-KlassPtr type
  4583     const TypePtr *tp = t->is_ptr();
  4584     int offset = meet_offset(tp->offset());
  4585     PTR ptr = meet_ptr(tp->ptr());
  4586     switch (tp->ptr()) {
  4587     case TopPTR:
  4588       return this;
  4589     case Null:
  4590       if( ptr == Null ) return TypePtr::make( AnyPtr, ptr, offset );
  4591     case AnyNull:
  4592       return make( ptr, klass(), offset );
  4593     case BotPTR:
  4594     case NotNull:
  4595       return TypePtr::make(AnyPtr, ptr, offset);
  4596     default: typerr(t);
  4600   case RawPtr:
  4601   case MetadataPtr:
  4602   case OopPtr:
  4603   case AryPtr:                  // Meet with AryPtr
  4604   case InstPtr:                 // Meet with InstPtr
  4605     return TypePtr::BOTTOM;
  4607   //
  4608   //             A-top         }
  4609   //           /   |   \       }  Tops
  4610   //       B-top A-any C-top   }
  4611   //          | /  |  \ |      }  Any-nulls
  4612   //       B-any   |   C-any   }
  4613   //          |    |    |
  4614   //       B-con A-con C-con   } constants; not comparable across classes
  4615   //          |    |    |
  4616   //       B-not   |   C-not   }
  4617   //          | \  |  / |      }  not-nulls
  4618   //       B-bot A-not C-bot   }
  4619   //           \   |   /       }  Bottoms
  4620   //             A-bot         }
  4621   //
  4623   case KlassPtr: {  // Meet two KlassPtr types
  4624     const TypeKlassPtr *tkls = t->is_klassptr();
  4625     int  off     = meet_offset(tkls->offset());
  4626     PTR  ptr     = meet_ptr(tkls->ptr());
  4628     // Check for easy case; klasses are equal (and perhaps not loaded!)
  4629     // If we have constants, then we created oops so classes are loaded
  4630     // and we can handle the constants further down.  This case handles
  4631     // not-loaded classes
  4632     if( ptr != Constant && tkls->klass()->equals(klass()) ) {
  4633       return make( ptr, klass(), off );
  4636     // Classes require inspection in the Java klass hierarchy.  Must be loaded.
  4637     ciKlass* tkls_klass = tkls->klass();
  4638     ciKlass* this_klass = this->klass();
  4639     assert( tkls_klass->is_loaded(), "This class should have been loaded.");
  4640     assert( this_klass->is_loaded(), "This class should have been loaded.");
  4642     // If 'this' type is above the centerline and is a superclass of the
  4643     // other, we can treat 'this' as having the same type as the other.
  4644     if ((above_centerline(this->ptr())) &&
  4645         tkls_klass->is_subtype_of(this_klass)) {
  4646       this_klass = tkls_klass;
  4648     // If 'tinst' type is above the centerline and is a superclass of the
  4649     // other, we can treat 'tinst' as having the same type as the other.
  4650     if ((above_centerline(tkls->ptr())) &&
  4651         this_klass->is_subtype_of(tkls_klass)) {
  4652       tkls_klass = this_klass;
  4655     // Check for classes now being equal
  4656     if (tkls_klass->equals(this_klass)) {
  4657       // If the klasses are equal, the constants may still differ.  Fall to
  4658       // NotNull if they do (neither constant is NULL; that is a special case
  4659       // handled elsewhere).
  4660       if( ptr == Constant ) {
  4661         if (this->_ptr == Constant && tkls->_ptr == Constant &&
  4662             this->klass()->equals(tkls->klass()));
  4663         else if (above_centerline(this->ptr()));
  4664         else if (above_centerline(tkls->ptr()));
  4665         else
  4666           ptr = NotNull;
  4668       return make( ptr, this_klass, off );
  4669     } // Else classes are not equal
  4671     // Since klasses are different, we require the LCA in the Java
  4672     // class hierarchy - which means we have to fall to at least NotNull.
  4673     if( ptr == TopPTR || ptr == AnyNull || ptr == Constant )
  4674       ptr = NotNull;
  4675     // Now we find the LCA of Java classes
  4676     ciKlass* k = this_klass->least_common_ancestor(tkls_klass);
  4677     return   make( ptr, k, off );
  4678   } // End of case KlassPtr
  4680   } // End of switch
  4681   return this;                  // Return the double constant
  4684 //------------------------------xdual------------------------------------------
  4685 // Dual: compute field-by-field dual
  4686 const Type    *TypeKlassPtr::xdual() const {
  4687   return new TypeKlassPtr( dual_ptr(), klass(), dual_offset() );
  4690 //------------------------------get_con----------------------------------------
  4691 intptr_t TypeKlassPtr::get_con() const {
  4692   assert( _ptr == Null || _ptr == Constant, "" );
  4693   assert( _offset >= 0, "" );
  4695   if (_offset != 0) {
  4696     // After being ported to the compiler interface, the compiler no longer
  4697     // directly manipulates the addresses of oops.  Rather, it only has a pointer
  4698     // to a handle at compile time.  This handle is embedded in the generated
  4699     // code and dereferenced at the time the nmethod is made.  Until that time,
  4700     // it is not reasonable to do arithmetic with the addresses of oops (we don't
  4701     // have access to the addresses!).  This does not seem to currently happen,
  4702     // but this assertion here is to help prevent its occurence.
  4703     tty->print_cr("Found oop constant with non-zero offset");
  4704     ShouldNotReachHere();
  4707   return (intptr_t)klass()->constant_encoding();
  4709 //------------------------------dump2------------------------------------------
  4710 // Dump Klass Type
  4711 #ifndef PRODUCT
  4712 void TypeKlassPtr::dump2( Dict & d, uint depth, outputStream *st ) const {
  4713   switch( _ptr ) {
  4714   case Constant:
  4715     st->print("precise ");
  4716   case NotNull:
  4718       const char *name = klass()->name()->as_utf8();
  4719       if( name ) {
  4720         st->print("klass %s: " INTPTR_FORMAT, name, klass());
  4721       } else {
  4722         ShouldNotReachHere();
  4725   case BotPTR:
  4726     if( !WizardMode && !Verbose && !_klass_is_exact ) break;
  4727   case TopPTR:
  4728   case AnyNull:
  4729     st->print(":%s", ptr_msg[_ptr]);
  4730     if( _klass_is_exact ) st->print(":exact");
  4731     break;
  4734   if( _offset ) {               // Dump offset, if any
  4735     if( _offset == OffsetBot )      { st->print("+any"); }
  4736     else if( _offset == OffsetTop ) { st->print("+unknown"); }
  4737     else                            { st->print("+%d", _offset); }
  4740   st->print(" *");
  4742 #endif
  4746 //=============================================================================
  4747 // Convenience common pre-built types.
  4749 //------------------------------make-------------------------------------------
  4750 const TypeFunc *TypeFunc::make( const TypeTuple *domain, const TypeTuple *range ) {
  4751   return (TypeFunc*)(new TypeFunc(domain,range))->hashcons();
  4754 //------------------------------make-------------------------------------------
  4755 const TypeFunc *TypeFunc::make(ciMethod* method) {
  4756   Compile* C = Compile::current();
  4757   const TypeFunc* tf = C->last_tf(method); // check cache
  4758   if (tf != NULL)  return tf;  // The hit rate here is almost 50%.
  4759   const TypeTuple *domain;
  4760   if (method->is_static()) {
  4761     domain = TypeTuple::make_domain(NULL, method->signature());
  4762   } else {
  4763     domain = TypeTuple::make_domain(method->holder(), method->signature());
  4765   const TypeTuple *range  = TypeTuple::make_range(method->signature());
  4766   tf = TypeFunc::make(domain, range);
  4767   C->set_last_tf(method, tf);  // fill cache
  4768   return tf;
  4771 //------------------------------meet-------------------------------------------
  4772 // Compute the MEET of two types.  It returns a new Type object.
  4773 const Type *TypeFunc::xmeet( const Type *t ) const {
  4774   // Perform a fast test for common case; meeting the same types together.
  4775   if( this == t ) return this;  // Meeting same type-rep?
  4777   // Current "this->_base" is Func
  4778   switch (t->base()) {          // switch on original type
  4780   case Bottom:                  // Ye Olde Default
  4781     return t;
  4783   default:                      // All else is a mistake
  4784     typerr(t);
  4786   case Top:
  4787     break;
  4789   return this;                  // Return the double constant
  4792 //------------------------------xdual------------------------------------------
  4793 // Dual: compute field-by-field dual
  4794 const Type *TypeFunc::xdual() const {
  4795   return this;
  4798 //------------------------------eq---------------------------------------------
  4799 // Structural equality check for Type representations
  4800 bool TypeFunc::eq( const Type *t ) const {
  4801   const TypeFunc *a = (const TypeFunc*)t;
  4802   return _domain == a->_domain &&
  4803     _range == a->_range;
  4806 //------------------------------hash-------------------------------------------
  4807 // Type-specific hashing function.
  4808 int TypeFunc::hash(void) const {
  4809   return (intptr_t)_domain + (intptr_t)_range;
  4812 //------------------------------dump2------------------------------------------
  4813 // Dump Function Type
  4814 #ifndef PRODUCT
  4815 void TypeFunc::dump2( Dict &d, uint depth, outputStream *st ) const {
  4816   if( _range->_cnt <= Parms )
  4817     st->print("void");
  4818   else {
  4819     uint i;
  4820     for (i = Parms; i < _range->_cnt-1; i++) {
  4821       _range->field_at(i)->dump2(d,depth,st);
  4822       st->print("/");
  4824     _range->field_at(i)->dump2(d,depth,st);
  4826   st->print(" ");
  4827   st->print("( ");
  4828   if( !depth || d[this] ) {     // Check for recursive dump
  4829     st->print("...)");
  4830     return;
  4832   d.Insert((void*)this,(void*)this);    // Stop recursion
  4833   if (Parms < _domain->_cnt)
  4834     _domain->field_at(Parms)->dump2(d,depth-1,st);
  4835   for (uint i = Parms+1; i < _domain->_cnt; i++) {
  4836     st->print(", ");
  4837     _domain->field_at(i)->dump2(d,depth-1,st);
  4839   st->print(" )");
  4841 #endif
  4843 //------------------------------singleton--------------------------------------
  4844 // TRUE if Type is a singleton type, FALSE otherwise.   Singletons are simple
  4845 // constants (Ldi nodes).  Singletons are integer, float or double constants
  4846 // or a single symbol.
  4847 bool TypeFunc::singleton(void) const {
  4848   return false;                 // Never a singleton
  4851 bool TypeFunc::empty(void) const {
  4852   return false;                 // Never empty
  4856 BasicType TypeFunc::return_type() const{
  4857   if (range()->cnt() == TypeFunc::Parms) {
  4858     return T_VOID;
  4860   return range()->field_at(TypeFunc::Parms)->basic_type();

mercurial