src/share/vm/opto/type.cpp

Tue, 07 Jan 2014 16:02:10 +0100

author
roland
date
Tue, 07 Jan 2014 16:02:10 +0100
changeset 6214
5231c2210388
parent 6043
6c2f07d1495f
child 6313
de95063c0e34
child 6503
a9becfeecd1b
permissions
-rw-r--r--

8027571: fatal error: meet not symmetric
Summary: meet of one constant array and one exact array not symmetric.
Reviewed-by: kvn

     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 //------------------------------hash-------------------------------------------
   240 int Type::uhash( const Type *const t ) {
   241   return t->hash();
   242 }
   244 #define SMALLINT ((juint)3)  // a value too insignificant to consider widening
   246 //--------------------------Initialize_shared----------------------------------
   247 void Type::Initialize_shared(Compile* current) {
   248   // This method does not need to be locked because the first system
   249   // compilations (stub compilations) occur serially.  If they are
   250   // changed to proceed in parallel, then this section will need
   251   // locking.
   253   Arena* save = current->type_arena();
   254   Arena* shared_type_arena = new (mtCompiler)Arena();
   256   current->set_type_arena(shared_type_arena);
   257   _shared_type_dict =
   258     new (shared_type_arena) Dict( (CmpKey)Type::cmp, (Hash)Type::uhash,
   259                                   shared_type_arena, 128 );
   260   current->set_type_dict(_shared_type_dict);
   262   // Make shared pre-built types.
   263   CONTROL = make(Control);      // Control only
   264   TOP     = make(Top);          // No values in set
   265   MEMORY  = make(Memory);       // Abstract store only
   266   ABIO    = make(Abio);         // State-of-machine only
   267   RETURN_ADDRESS=make(Return_Address);
   268   FLOAT   = make(FloatBot);     // All floats
   269   DOUBLE  = make(DoubleBot);    // All doubles
   270   BOTTOM  = make(Bottom);       // Everything
   271   HALF    = make(Half);         // Placeholder half of doublewide type
   273   TypeF::ZERO = TypeF::make(0.0); // Float 0 (positive zero)
   274   TypeF::ONE  = TypeF::make(1.0); // Float 1
   276   TypeD::ZERO = TypeD::make(0.0); // Double 0 (positive zero)
   277   TypeD::ONE  = TypeD::make(1.0); // Double 1
   279   TypeInt::MINUS_1 = TypeInt::make(-1);  // -1
   280   TypeInt::ZERO    = TypeInt::make( 0);  //  0
   281   TypeInt::ONE     = TypeInt::make( 1);  //  1
   282   TypeInt::BOOL    = TypeInt::make(0,1,   WidenMin);  // 0 or 1, FALSE or TRUE.
   283   TypeInt::CC      = TypeInt::make(-1, 1, WidenMin);  // -1, 0 or 1, condition codes
   284   TypeInt::CC_LT   = TypeInt::make(-1,-1, WidenMin);  // == TypeInt::MINUS_1
   285   TypeInt::CC_GT   = TypeInt::make( 1, 1, WidenMin);  // == TypeInt::ONE
   286   TypeInt::CC_EQ   = TypeInt::make( 0, 0, WidenMin);  // == TypeInt::ZERO
   287   TypeInt::CC_LE   = TypeInt::make(-1, 0, WidenMin);
   288   TypeInt::CC_GE   = TypeInt::make( 0, 1, WidenMin);  // == TypeInt::BOOL
   289   TypeInt::BYTE    = TypeInt::make(-128,127,     WidenMin); // Bytes
   290   TypeInt::UBYTE   = TypeInt::make(0, 255,       WidenMin); // Unsigned Bytes
   291   TypeInt::CHAR    = TypeInt::make(0,65535,      WidenMin); // Java chars
   292   TypeInt::SHORT   = TypeInt::make(-32768,32767, WidenMin); // Java shorts
   293   TypeInt::POS     = TypeInt::make(0,max_jint,   WidenMin); // Non-neg values
   294   TypeInt::POS1    = TypeInt::make(1,max_jint,   WidenMin); // Positive values
   295   TypeInt::INT     = TypeInt::make(min_jint,max_jint, WidenMax); // 32-bit integers
   296   TypeInt::SYMINT  = TypeInt::make(-max_jint,max_jint,WidenMin); // symmetric range
   297   // CmpL is overloaded both as the bytecode computation returning
   298   // a trinary (-1,0,+1) integer result AND as an efficient long
   299   // compare returning optimizer ideal-type flags.
   300   assert( TypeInt::CC_LT == TypeInt::MINUS_1, "types must match for CmpL to work" );
   301   assert( TypeInt::CC_GT == TypeInt::ONE,     "types must match for CmpL to work" );
   302   assert( TypeInt::CC_EQ == TypeInt::ZERO,    "types must match for CmpL to work" );
   303   assert( TypeInt::CC_GE == TypeInt::BOOL,    "types must match for CmpL to work" );
   304   assert( (juint)(TypeInt::CC->_hi - TypeInt::CC->_lo) <= SMALLINT, "CC is truly small");
   306   TypeLong::MINUS_1 = TypeLong::make(-1);        // -1
   307   TypeLong::ZERO    = TypeLong::make( 0);        //  0
   308   TypeLong::ONE     = TypeLong::make( 1);        //  1
   309   TypeLong::POS     = TypeLong::make(0,max_jlong, WidenMin); // Non-neg values
   310   TypeLong::LONG    = TypeLong::make(min_jlong,max_jlong,WidenMax); // 64-bit integers
   311   TypeLong::INT     = TypeLong::make((jlong)min_jint,(jlong)max_jint,WidenMin);
   312   TypeLong::UINT    = TypeLong::make(0,(jlong)max_juint,WidenMin);
   314   const Type **fboth =(const Type**)shared_type_arena->Amalloc_4(2*sizeof(Type*));
   315   fboth[0] = Type::CONTROL;
   316   fboth[1] = Type::CONTROL;
   317   TypeTuple::IFBOTH = TypeTuple::make( 2, fboth );
   319   const Type **ffalse =(const Type**)shared_type_arena->Amalloc_4(2*sizeof(Type*));
   320   ffalse[0] = Type::CONTROL;
   321   ffalse[1] = Type::TOP;
   322   TypeTuple::IFFALSE = TypeTuple::make( 2, ffalse );
   324   const Type **fneither =(const Type**)shared_type_arena->Amalloc_4(2*sizeof(Type*));
   325   fneither[0] = Type::TOP;
   326   fneither[1] = Type::TOP;
   327   TypeTuple::IFNEITHER = TypeTuple::make( 2, fneither );
   329   const Type **ftrue =(const Type**)shared_type_arena->Amalloc_4(2*sizeof(Type*));
   330   ftrue[0] = Type::TOP;
   331   ftrue[1] = Type::CONTROL;
   332   TypeTuple::IFTRUE = TypeTuple::make( 2, ftrue );
   334   const Type **floop =(const Type**)shared_type_arena->Amalloc_4(2*sizeof(Type*));
   335   floop[0] = Type::CONTROL;
   336   floop[1] = TypeInt::INT;
   337   TypeTuple::LOOPBODY = TypeTuple::make( 2, floop );
   339   TypePtr::NULL_PTR= TypePtr::make( AnyPtr, TypePtr::Null, 0 );
   340   TypePtr::NOTNULL = TypePtr::make( AnyPtr, TypePtr::NotNull, OffsetBot );
   341   TypePtr::BOTTOM  = TypePtr::make( AnyPtr, TypePtr::BotPTR, OffsetBot );
   343   TypeRawPtr::BOTTOM = TypeRawPtr::make( TypePtr::BotPTR );
   344   TypeRawPtr::NOTNULL= TypeRawPtr::make( TypePtr::NotNull );
   346   const Type **fmembar = TypeTuple::fields(0);
   347   TypeTuple::MEMBAR = TypeTuple::make(TypeFunc::Parms+0, fmembar);
   349   const Type **fsc = (const Type**)shared_type_arena->Amalloc_4(2*sizeof(Type*));
   350   fsc[0] = TypeInt::CC;
   351   fsc[1] = Type::MEMORY;
   352   TypeTuple::STORECONDITIONAL = TypeTuple::make(2, fsc);
   354   TypeInstPtr::NOTNULL = TypeInstPtr::make(TypePtr::NotNull, current->env()->Object_klass());
   355   TypeInstPtr::BOTTOM  = TypeInstPtr::make(TypePtr::BotPTR,  current->env()->Object_klass());
   356   TypeInstPtr::MIRROR  = TypeInstPtr::make(TypePtr::NotNull, current->env()->Class_klass());
   357   TypeInstPtr::MARK    = TypeInstPtr::make(TypePtr::BotPTR,  current->env()->Object_klass(),
   358                                            false, 0, oopDesc::mark_offset_in_bytes());
   359   TypeInstPtr::KLASS   = TypeInstPtr::make(TypePtr::BotPTR,  current->env()->Object_klass(),
   360                                            false, 0, oopDesc::klass_offset_in_bytes());
   361   TypeOopPtr::BOTTOM  = TypeOopPtr::make(TypePtr::BotPTR, OffsetBot, TypeOopPtr::InstanceBot, NULL);
   363   TypeMetadataPtr::BOTTOM = TypeMetadataPtr::make(TypePtr::BotPTR, NULL, OffsetBot);
   365   TypeNarrowOop::NULL_PTR = TypeNarrowOop::make( TypePtr::NULL_PTR );
   366   TypeNarrowOop::BOTTOM   = TypeNarrowOop::make( TypeInstPtr::BOTTOM );
   368   TypeNarrowKlass::NULL_PTR = TypeNarrowKlass::make( TypePtr::NULL_PTR );
   370   mreg2type[Op_Node] = Type::BOTTOM;
   371   mreg2type[Op_Set ] = 0;
   372   mreg2type[Op_RegN] = TypeNarrowOop::BOTTOM;
   373   mreg2type[Op_RegI] = TypeInt::INT;
   374   mreg2type[Op_RegP] = TypePtr::BOTTOM;
   375   mreg2type[Op_RegF] = Type::FLOAT;
   376   mreg2type[Op_RegD] = Type::DOUBLE;
   377   mreg2type[Op_RegL] = TypeLong::LONG;
   378   mreg2type[Op_RegFlags] = TypeInt::CC;
   380   TypeAryPtr::RANGE   = TypeAryPtr::make( TypePtr::BotPTR, TypeAry::make(Type::BOTTOM,TypeInt::POS), NULL /* current->env()->Object_klass() */, false, arrayOopDesc::length_offset_in_bytes());
   382   TypeAryPtr::NARROWOOPS = TypeAryPtr::make(TypePtr::BotPTR, TypeAry::make(TypeNarrowOop::BOTTOM, TypeInt::POS), NULL /*ciArrayKlass::make(o)*/,  false,  Type::OffsetBot);
   384 #ifdef _LP64
   385   if (UseCompressedOops) {
   386     assert(TypeAryPtr::NARROWOOPS->is_ptr_to_narrowoop(), "array of narrow oops must be ptr to narrow oop");
   387     TypeAryPtr::OOPS  = TypeAryPtr::NARROWOOPS;
   388   } else
   389 #endif
   390   {
   391     // There is no shared klass for Object[].  See note in TypeAryPtr::klass().
   392     TypeAryPtr::OOPS  = TypeAryPtr::make(TypePtr::BotPTR, TypeAry::make(TypeInstPtr::BOTTOM,TypeInt::POS), NULL /*ciArrayKlass::make(o)*/,  false,  Type::OffsetBot);
   393   }
   394   TypeAryPtr::BYTES   = TypeAryPtr::make(TypePtr::BotPTR, TypeAry::make(TypeInt::BYTE      ,TypeInt::POS), ciTypeArrayKlass::make(T_BYTE),   true,  Type::OffsetBot);
   395   TypeAryPtr::SHORTS  = TypeAryPtr::make(TypePtr::BotPTR, TypeAry::make(TypeInt::SHORT     ,TypeInt::POS), ciTypeArrayKlass::make(T_SHORT),  true,  Type::OffsetBot);
   396   TypeAryPtr::CHARS   = TypeAryPtr::make(TypePtr::BotPTR, TypeAry::make(TypeInt::CHAR      ,TypeInt::POS), ciTypeArrayKlass::make(T_CHAR),   true,  Type::OffsetBot);
   397   TypeAryPtr::INTS    = TypeAryPtr::make(TypePtr::BotPTR, TypeAry::make(TypeInt::INT       ,TypeInt::POS), ciTypeArrayKlass::make(T_INT),    true,  Type::OffsetBot);
   398   TypeAryPtr::LONGS   = TypeAryPtr::make(TypePtr::BotPTR, TypeAry::make(TypeLong::LONG     ,TypeInt::POS), ciTypeArrayKlass::make(T_LONG),   true,  Type::OffsetBot);
   399   TypeAryPtr::FLOATS  = TypeAryPtr::make(TypePtr::BotPTR, TypeAry::make(Type::FLOAT        ,TypeInt::POS), ciTypeArrayKlass::make(T_FLOAT),  true,  Type::OffsetBot);
   400   TypeAryPtr::DOUBLES = TypeAryPtr::make(TypePtr::BotPTR, TypeAry::make(Type::DOUBLE       ,TypeInt::POS), ciTypeArrayKlass::make(T_DOUBLE), true,  Type::OffsetBot);
   402   // Nobody should ask _array_body_type[T_NARROWOOP]. Use NULL as assert.
   403   TypeAryPtr::_array_body_type[T_NARROWOOP] = NULL;
   404   TypeAryPtr::_array_body_type[T_OBJECT]  = TypeAryPtr::OOPS;
   405   TypeAryPtr::_array_body_type[T_ARRAY]   = TypeAryPtr::OOPS; // arrays are stored in oop arrays
   406   TypeAryPtr::_array_body_type[T_BYTE]    = TypeAryPtr::BYTES;
   407   TypeAryPtr::_array_body_type[T_BOOLEAN] = TypeAryPtr::BYTES;  // boolean[] is a byte array
   408   TypeAryPtr::_array_body_type[T_SHORT]   = TypeAryPtr::SHORTS;
   409   TypeAryPtr::_array_body_type[T_CHAR]    = TypeAryPtr::CHARS;
   410   TypeAryPtr::_array_body_type[T_INT]     = TypeAryPtr::INTS;
   411   TypeAryPtr::_array_body_type[T_LONG]    = TypeAryPtr::LONGS;
   412   TypeAryPtr::_array_body_type[T_FLOAT]   = TypeAryPtr::FLOATS;
   413   TypeAryPtr::_array_body_type[T_DOUBLE]  = TypeAryPtr::DOUBLES;
   415   TypeKlassPtr::OBJECT = TypeKlassPtr::make( TypePtr::NotNull, current->env()->Object_klass(), 0 );
   416   TypeKlassPtr::OBJECT_OR_NULL = TypeKlassPtr::make( TypePtr::BotPTR, current->env()->Object_klass(), 0 );
   418   const Type **fi2c = TypeTuple::fields(2);
   419   fi2c[TypeFunc::Parms+0] = TypeInstPtr::BOTTOM; // Method*
   420   fi2c[TypeFunc::Parms+1] = TypeRawPtr::BOTTOM; // argument pointer
   421   TypeTuple::START_I2C = TypeTuple::make(TypeFunc::Parms+2, fi2c);
   423   const Type **intpair = TypeTuple::fields(2);
   424   intpair[0] = TypeInt::INT;
   425   intpair[1] = TypeInt::INT;
   426   TypeTuple::INT_PAIR = TypeTuple::make(2, intpair);
   428   const Type **longpair = TypeTuple::fields(2);
   429   longpair[0] = TypeLong::LONG;
   430   longpair[1] = TypeLong::LONG;
   431   TypeTuple::LONG_PAIR = TypeTuple::make(2, longpair);
   433   const Type **intccpair = TypeTuple::fields(2);
   434   intccpair[0] = TypeInt::INT;
   435   intccpair[1] = TypeInt::CC;
   436   TypeTuple::INT_CC_PAIR = TypeTuple::make(2, intccpair);
   438   const Type **longccpair = TypeTuple::fields(2);
   439   longccpair[0] = TypeLong::LONG;
   440   longccpair[1] = TypeInt::CC;
   441   TypeTuple::LONG_CC_PAIR = TypeTuple::make(2, longccpair);
   443   _const_basic_type[T_NARROWOOP]   = TypeNarrowOop::BOTTOM;
   444   _const_basic_type[T_NARROWKLASS] = Type::BOTTOM;
   445   _const_basic_type[T_BOOLEAN]     = TypeInt::BOOL;
   446   _const_basic_type[T_CHAR]        = TypeInt::CHAR;
   447   _const_basic_type[T_BYTE]        = TypeInt::BYTE;
   448   _const_basic_type[T_SHORT]       = TypeInt::SHORT;
   449   _const_basic_type[T_INT]         = TypeInt::INT;
   450   _const_basic_type[T_LONG]        = TypeLong::LONG;
   451   _const_basic_type[T_FLOAT]       = Type::FLOAT;
   452   _const_basic_type[T_DOUBLE]      = Type::DOUBLE;
   453   _const_basic_type[T_OBJECT]      = TypeInstPtr::BOTTOM;
   454   _const_basic_type[T_ARRAY]       = TypeInstPtr::BOTTOM; // there is no separate bottom for arrays
   455   _const_basic_type[T_VOID]        = TypePtr::NULL_PTR;   // reflection represents void this way
   456   _const_basic_type[T_ADDRESS]     = TypeRawPtr::BOTTOM;  // both interpreter return addresses & random raw ptrs
   457   _const_basic_type[T_CONFLICT]    = Type::BOTTOM;        // why not?
   459   _zero_type[T_NARROWOOP]   = TypeNarrowOop::NULL_PTR;
   460   _zero_type[T_NARROWKLASS] = TypeNarrowKlass::NULL_PTR;
   461   _zero_type[T_BOOLEAN]     = TypeInt::ZERO;     // false == 0
   462   _zero_type[T_CHAR]        = TypeInt::ZERO;     // '\0' == 0
   463   _zero_type[T_BYTE]        = TypeInt::ZERO;     // 0x00 == 0
   464   _zero_type[T_SHORT]       = TypeInt::ZERO;     // 0x0000 == 0
   465   _zero_type[T_INT]         = TypeInt::ZERO;
   466   _zero_type[T_LONG]        = TypeLong::ZERO;
   467   _zero_type[T_FLOAT]       = TypeF::ZERO;
   468   _zero_type[T_DOUBLE]      = TypeD::ZERO;
   469   _zero_type[T_OBJECT]      = TypePtr::NULL_PTR;
   470   _zero_type[T_ARRAY]       = TypePtr::NULL_PTR; // null array is null oop
   471   _zero_type[T_ADDRESS]     = TypePtr::NULL_PTR; // raw pointers use the same null
   472   _zero_type[T_VOID]        = Type::TOP;         // the only void value is no value at all
   474   // get_zero_type() should not happen for T_CONFLICT
   475   _zero_type[T_CONFLICT]= NULL;
   477   // Vector predefined types, it needs initialized _const_basic_type[].
   478   if (Matcher::vector_size_supported(T_BYTE,4)) {
   479     TypeVect::VECTS = TypeVect::make(T_BYTE,4);
   480   }
   481   if (Matcher::vector_size_supported(T_FLOAT,2)) {
   482     TypeVect::VECTD = TypeVect::make(T_FLOAT,2);
   483   }
   484   if (Matcher::vector_size_supported(T_FLOAT,4)) {
   485     TypeVect::VECTX = TypeVect::make(T_FLOAT,4);
   486   }
   487   if (Matcher::vector_size_supported(T_FLOAT,8)) {
   488     TypeVect::VECTY = TypeVect::make(T_FLOAT,8);
   489   }
   490   mreg2type[Op_VecS] = TypeVect::VECTS;
   491   mreg2type[Op_VecD] = TypeVect::VECTD;
   492   mreg2type[Op_VecX] = TypeVect::VECTX;
   493   mreg2type[Op_VecY] = TypeVect::VECTY;
   495   // Restore working type arena.
   496   current->set_type_arena(save);
   497   current->set_type_dict(NULL);
   498 }
   500 //------------------------------Initialize-------------------------------------
   501 void Type::Initialize(Compile* current) {
   502   assert(current->type_arena() != NULL, "must have created type arena");
   504   if (_shared_type_dict == NULL) {
   505     Initialize_shared(current);
   506   }
   508   Arena* type_arena = current->type_arena();
   510   // Create the hash-cons'ing dictionary with top-level storage allocation
   511   Dict *tdic = new (type_arena) Dict( (CmpKey)Type::cmp,(Hash)Type::uhash, type_arena, 128 );
   512   current->set_type_dict(tdic);
   514   // Transfer the shared types.
   515   DictI i(_shared_type_dict);
   516   for( ; i.test(); ++i ) {
   517     Type* t = (Type*)i._value;
   518     tdic->Insert(t,t);  // New Type, insert into Type table
   519   }
   520 }
   522 //------------------------------hashcons---------------------------------------
   523 // Do the hash-cons trick.  If the Type already exists in the type table,
   524 // delete the current Type and return the existing Type.  Otherwise stick the
   525 // current Type in the Type table.
   526 const Type *Type::hashcons(void) {
   527   debug_only(base());           // Check the assertion in Type::base().
   528   // Look up the Type in the Type dictionary
   529   Dict *tdic = type_dict();
   530   Type* old = (Type*)(tdic->Insert(this, this, false));
   531   if( old ) {                   // Pre-existing Type?
   532     if( old != this )           // Yes, this guy is not the pre-existing?
   533       delete this;              // Yes, Nuke this guy
   534     assert( old->_dual, "" );
   535     return old;                 // Return pre-existing
   536   }
   538   // Every type has a dual (to make my lattice symmetric).
   539   // Since we just discovered a new Type, compute its dual right now.
   540   assert( !_dual, "" );         // No dual yet
   541   _dual = xdual();              // Compute the dual
   542   if( cmp(this,_dual)==0 ) {    // Handle self-symmetric
   543     _dual = this;
   544     return this;
   545   }
   546   assert( !_dual->_dual, "" );  // No reverse dual yet
   547   assert( !(*tdic)[_dual], "" ); // Dual not in type system either
   548   // New Type, insert into Type table
   549   tdic->Insert((void*)_dual,(void*)_dual);
   550   ((Type*)_dual)->_dual = this; // Finish up being symmetric
   551 #ifdef ASSERT
   552   Type *dual_dual = (Type*)_dual->xdual();
   553   assert( eq(dual_dual), "xdual(xdual()) should be identity" );
   554   delete dual_dual;
   555 #endif
   556   return this;                  // Return new Type
   557 }
   559 //------------------------------eq---------------------------------------------
   560 // Structural equality check for Type representations
   561 bool Type::eq( const Type * ) const {
   562   return true;                  // Nothing else can go wrong
   563 }
   565 //------------------------------hash-------------------------------------------
   566 // Type-specific hashing function.
   567 int Type::hash(void) const {
   568   return _base;
   569 }
   571 //------------------------------is_finite--------------------------------------
   572 // Has a finite value
   573 bool Type::is_finite() const {
   574   return false;
   575 }
   577 //------------------------------is_nan-----------------------------------------
   578 // Is not a number (NaN)
   579 bool Type::is_nan()    const {
   580   return false;
   581 }
   583 //----------------------interface_vs_oop---------------------------------------
   584 #ifdef ASSERT
   585 bool Type::interface_vs_oop_helper(const Type *t) const {
   586   bool result = false;
   588   const TypePtr* this_ptr = this->make_ptr(); // In case it is narrow_oop
   589   const TypePtr*    t_ptr =    t->make_ptr();
   590   if( this_ptr == NULL || t_ptr == NULL )
   591     return result;
   593   const TypeInstPtr* this_inst = this_ptr->isa_instptr();
   594   const TypeInstPtr*    t_inst =    t_ptr->isa_instptr();
   595   if( this_inst && this_inst->is_loaded() && t_inst && t_inst->is_loaded() ) {
   596     bool this_interface = this_inst->klass()->is_interface();
   597     bool    t_interface =    t_inst->klass()->is_interface();
   598     result = this_interface ^ t_interface;
   599   }
   601   return result;
   602 }
   604 bool Type::interface_vs_oop(const Type *t) const {
   605   if (interface_vs_oop_helper(t)) {
   606     return true;
   607   }
   608   // Now check the speculative parts as well
   609   const TypeOopPtr* this_spec = isa_oopptr() != NULL ? isa_oopptr()->speculative() : NULL;
   610   const TypeOopPtr* t_spec = t->isa_oopptr() != NULL ? t->isa_oopptr()->speculative() : NULL;
   611   if (this_spec != NULL && t_spec != NULL) {
   612     if (this_spec->interface_vs_oop_helper(t_spec)) {
   613       return true;
   614     }
   615     return false;
   616   }
   617   if (this_spec != NULL && this_spec->interface_vs_oop_helper(t)) {
   618     return true;
   619   }
   620   if (t_spec != NULL && interface_vs_oop_helper(t_spec)) {
   621     return true;
   622   }
   623   return false;
   624 }
   626 #endif
   628 //------------------------------meet-------------------------------------------
   629 // Compute the MEET of two types.  NOT virtual.  It enforces that meet is
   630 // commutative and the lattice is symmetric.
   631 const Type *Type::meet( const Type *t ) const {
   632   if (isa_narrowoop() && t->isa_narrowoop()) {
   633     const Type* result = make_ptr()->meet(t->make_ptr());
   634     return result->make_narrowoop();
   635   }
   636   if (isa_narrowklass() && t->isa_narrowklass()) {
   637     const Type* result = make_ptr()->meet(t->make_ptr());
   638     return result->make_narrowklass();
   639   }
   641   const Type *mt = xmeet(t);
   642   if (isa_narrowoop() || t->isa_narrowoop()) return mt;
   643   if (isa_narrowklass() || t->isa_narrowklass()) return mt;
   644 #ifdef ASSERT
   645   assert( mt == t->xmeet(this), "meet not commutative" );
   646   const Type* dual_join = mt->_dual;
   647   const Type *t2t    = dual_join->xmeet(t->_dual);
   648   const Type *t2this = dual_join->xmeet(   _dual);
   650   // Interface meet Oop is Not Symmetric:
   651   // Interface:AnyNull meet Oop:AnyNull == Interface:AnyNull
   652   // Interface:NotNull meet Oop:NotNull == java/lang/Object:NotNull
   654   if( !interface_vs_oop(t) && (t2t != t->_dual || t2this != _dual) ) {
   655     tty->print_cr("=== Meet Not Symmetric ===");
   656     tty->print("t   =                   ");         t->dump(); tty->cr();
   657     tty->print("this=                   ");            dump(); tty->cr();
   658     tty->print("mt=(t meet this)=       ");        mt->dump(); tty->cr();
   660     tty->print("t_dual=                 ");  t->_dual->dump(); tty->cr();
   661     tty->print("this_dual=              ");     _dual->dump(); tty->cr();
   662     tty->print("mt_dual=                "); mt->_dual->dump(); tty->cr();
   664     tty->print("mt_dual meet t_dual=    "); t2t      ->dump(); tty->cr();
   665     tty->print("mt_dual meet this_dual= "); t2this   ->dump(); tty->cr();
   667     fatal("meet not symmetric" );
   668   }
   669 #endif
   670   return mt;
   671 }
   673 //------------------------------xmeet------------------------------------------
   674 // Compute the MEET of two types.  It returns a new Type object.
   675 const Type *Type::xmeet( const Type *t ) const {
   676   // Perform a fast test for common case; meeting the same types together.
   677   if( this == t ) return this;  // Meeting same type-rep?
   679   // Meeting TOP with anything?
   680   if( _base == Top ) return t;
   682   // Meeting BOTTOM with anything?
   683   if( _base == Bottom ) return BOTTOM;
   685   // Current "this->_base" is one of: Bad, Multi, Control, Top,
   686   // Abio, Abstore, Floatxxx, Doublexxx, Bottom, lastype.
   687   switch (t->base()) {  // Switch on original type
   689   // Cut in half the number of cases I must handle.  Only need cases for when
   690   // the given enum "t->type" is less than or equal to the local enum "type".
   691   case FloatCon:
   692   case DoubleCon:
   693   case Int:
   694   case Long:
   695     return t->xmeet(this);
   697   case OopPtr:
   698     return t->xmeet(this);
   700   case InstPtr:
   701     return t->xmeet(this);
   703   case MetadataPtr:
   704   case KlassPtr:
   705     return t->xmeet(this);
   707   case AryPtr:
   708     return t->xmeet(this);
   710   case NarrowOop:
   711     return t->xmeet(this);
   713   case NarrowKlass:
   714     return t->xmeet(this);
   716   case Bad:                     // Type check
   717   default:                      // Bogus type not in lattice
   718     typerr(t);
   719     return Type::BOTTOM;
   721   case Bottom:                  // Ye Olde Default
   722     return t;
   724   case FloatTop:
   725     if( _base == FloatTop ) return this;
   726   case FloatBot:                // Float
   727     if( _base == FloatBot || _base == FloatTop ) return FLOAT;
   728     if( _base == DoubleTop || _base == DoubleBot ) return Type::BOTTOM;
   729     typerr(t);
   730     return Type::BOTTOM;
   732   case DoubleTop:
   733     if( _base == DoubleTop ) return this;
   734   case DoubleBot:               // Double
   735     if( _base == DoubleBot || _base == DoubleTop ) return DOUBLE;
   736     if( _base == FloatTop || _base == FloatBot ) return Type::BOTTOM;
   737     typerr(t);
   738     return Type::BOTTOM;
   740   // These next few cases must match exactly or it is a compile-time error.
   741   case Control:                 // Control of code
   742   case Abio:                    // State of world outside of program
   743   case Memory:
   744     if( _base == t->_base )  return this;
   745     typerr(t);
   746     return Type::BOTTOM;
   748   case Top:                     // Top of the lattice
   749     return this;
   750   }
   752   // The type is unchanged
   753   return this;
   754 }
   756 //-----------------------------filter------------------------------------------
   757 const Type *Type::filter( const Type *kills ) const {
   758   const Type* ft = join(kills);
   759   if (ft->empty())
   760     return Type::TOP;           // Canonical empty value
   761   return ft;
   762 }
   764 //------------------------------xdual------------------------------------------
   765 // Compute dual right now.
   766 const Type::TYPES Type::dual_type[Type::lastype] = {
   767   Bad,          // Bad
   768   Control,      // Control
   769   Bottom,       // Top
   770   Bad,          // Int - handled in v-call
   771   Bad,          // Long - handled in v-call
   772   Half,         // Half
   773   Bad,          // NarrowOop - handled in v-call
   774   Bad,          // NarrowKlass - handled in v-call
   776   Bad,          // Tuple - handled in v-call
   777   Bad,          // Array - handled in v-call
   778   Bad,          // VectorS - handled in v-call
   779   Bad,          // VectorD - handled in v-call
   780   Bad,          // VectorX - handled in v-call
   781   Bad,          // VectorY - handled in v-call
   783   Bad,          // AnyPtr - handled in v-call
   784   Bad,          // RawPtr - handled in v-call
   785   Bad,          // OopPtr - handled in v-call
   786   Bad,          // InstPtr - handled in v-call
   787   Bad,          // AryPtr - handled in v-call
   789   Bad,          //  MetadataPtr - handled in v-call
   790   Bad,          // KlassPtr - handled in v-call
   792   Bad,          // Function - handled in v-call
   793   Abio,         // Abio
   794   Return_Address,// Return_Address
   795   Memory,       // Memory
   796   FloatBot,     // FloatTop
   797   FloatCon,     // FloatCon
   798   FloatTop,     // FloatBot
   799   DoubleBot,    // DoubleTop
   800   DoubleCon,    // DoubleCon
   801   DoubleTop,    // DoubleBot
   802   Top           // Bottom
   803 };
   805 const Type *Type::xdual() const {
   806   // Note: the base() accessor asserts the sanity of _base.
   807   assert(_type_info[base()].dual_type != Bad, "implement with v-call");
   808   return new Type(_type_info[_base].dual_type);
   809 }
   811 //------------------------------has_memory-------------------------------------
   812 bool Type::has_memory() const {
   813   Type::TYPES tx = base();
   814   if (tx == Memory) return true;
   815   if (tx == Tuple) {
   816     const TypeTuple *t = is_tuple();
   817     for (uint i=0; i < t->cnt(); i++) {
   818       tx = t->field_at(i)->base();
   819       if (tx == Memory)  return true;
   820     }
   821   }
   822   return false;
   823 }
   825 #ifndef PRODUCT
   826 //------------------------------dump2------------------------------------------
   827 void Type::dump2( Dict &d, uint depth, outputStream *st ) const {
   828   st->print(_type_info[_base].msg);
   829 }
   831 //------------------------------dump-------------------------------------------
   832 void Type::dump_on(outputStream *st) const {
   833   ResourceMark rm;
   834   Dict d(cmpkey,hashkey);       // Stop recursive type dumping
   835   dump2(d,1, st);
   836   if (is_ptr_to_narrowoop()) {
   837     st->print(" [narrow]");
   838   } else if (is_ptr_to_narrowklass()) {
   839     st->print(" [narrowklass]");
   840   }
   841 }
   842 #endif
   844 //------------------------------singleton--------------------------------------
   845 // TRUE if Type is a singleton type, FALSE otherwise.   Singletons are simple
   846 // constants (Ldi nodes).  Singletons are integer, float or double constants.
   847 bool Type::singleton(void) const {
   848   return _base == Top || _base == Half;
   849 }
   851 //------------------------------empty------------------------------------------
   852 // TRUE if Type is a type with no values, FALSE otherwise.
   853 bool Type::empty(void) const {
   854   switch (_base) {
   855   case DoubleTop:
   856   case FloatTop:
   857   case Top:
   858     return true;
   860   case Half:
   861   case Abio:
   862   case Return_Address:
   863   case Memory:
   864   case Bottom:
   865   case FloatBot:
   866   case DoubleBot:
   867     return false;  // never a singleton, therefore never empty
   868   }
   870   ShouldNotReachHere();
   871   return false;
   872 }
   874 //------------------------------dump_stats-------------------------------------
   875 // Dump collected statistics to stderr
   876 #ifndef PRODUCT
   877 void Type::dump_stats() {
   878   tty->print("Types made: %d\n", type_dict()->Size());
   879 }
   880 #endif
   882 //------------------------------typerr-----------------------------------------
   883 void Type::typerr( const Type *t ) const {
   884 #ifndef PRODUCT
   885   tty->print("\nError mixing types: ");
   886   dump();
   887   tty->print(" and ");
   888   t->dump();
   889   tty->print("\n");
   890 #endif
   891   ShouldNotReachHere();
   892 }
   895 //=============================================================================
   896 // Convenience common pre-built types.
   897 const TypeF *TypeF::ZERO;       // Floating point zero
   898 const TypeF *TypeF::ONE;        // Floating point one
   900 //------------------------------make-------------------------------------------
   901 // Create a float constant
   902 const TypeF *TypeF::make(float f) {
   903   return (TypeF*)(new TypeF(f))->hashcons();
   904 }
   906 //------------------------------meet-------------------------------------------
   907 // Compute the MEET of two types.  It returns a new Type object.
   908 const Type *TypeF::xmeet( const Type *t ) const {
   909   // Perform a fast test for common case; meeting the same types together.
   910   if( this == t ) return this;  // Meeting same type-rep?
   912   // Current "this->_base" is FloatCon
   913   switch (t->base()) {          // Switch on original type
   914   case AnyPtr:                  // Mixing with oops happens when javac
   915   case RawPtr:                  // reuses local variables
   916   case OopPtr:
   917   case InstPtr:
   918   case AryPtr:
   919   case MetadataPtr:
   920   case KlassPtr:
   921   case NarrowOop:
   922   case NarrowKlass:
   923   case Int:
   924   case Long:
   925   case DoubleTop:
   926   case DoubleCon:
   927   case DoubleBot:
   928   case Bottom:                  // Ye Olde Default
   929     return Type::BOTTOM;
   931   case FloatBot:
   932     return t;
   934   default:                      // All else is a mistake
   935     typerr(t);
   937   case FloatCon:                // Float-constant vs Float-constant?
   938     if( jint_cast(_f) != jint_cast(t->getf()) )         // unequal constants?
   939                                 // must compare bitwise as positive zero, negative zero and NaN have
   940                                 // all the same representation in C++
   941       return FLOAT;             // Return generic float
   942                                 // Equal constants
   943   case Top:
   944   case FloatTop:
   945     break;                      // Return the float constant
   946   }
   947   return this;                  // Return the float constant
   948 }
   950 //------------------------------xdual------------------------------------------
   951 // Dual: symmetric
   952 const Type *TypeF::xdual() const {
   953   return this;
   954 }
   956 //------------------------------eq---------------------------------------------
   957 // Structural equality check for Type representations
   958 bool TypeF::eq( const Type *t ) const {
   959   if( g_isnan(_f) ||
   960       g_isnan(t->getf()) ) {
   961     // One or both are NANs.  If both are NANs return true, else false.
   962     return (g_isnan(_f) && g_isnan(t->getf()));
   963   }
   964   if (_f == t->getf()) {
   965     // (NaN is impossible at this point, since it is not equal even to itself)
   966     if (_f == 0.0) {
   967       // difference between positive and negative zero
   968       if (jint_cast(_f) != jint_cast(t->getf()))  return false;
   969     }
   970     return true;
   971   }
   972   return false;
   973 }
   975 //------------------------------hash-------------------------------------------
   976 // Type-specific hashing function.
   977 int TypeF::hash(void) const {
   978   return *(int*)(&_f);
   979 }
   981 //------------------------------is_finite--------------------------------------
   982 // Has a finite value
   983 bool TypeF::is_finite() const {
   984   return g_isfinite(getf()) != 0;
   985 }
   987 //------------------------------is_nan-----------------------------------------
   988 // Is not a number (NaN)
   989 bool TypeF::is_nan()    const {
   990   return g_isnan(getf()) != 0;
   991 }
   993 //------------------------------dump2------------------------------------------
   994 // Dump float constant Type
   995 #ifndef PRODUCT
   996 void TypeF::dump2( Dict &d, uint depth, outputStream *st ) const {
   997   Type::dump2(d,depth, st);
   998   st->print("%f", _f);
   999 }
  1000 #endif
  1002 //------------------------------singleton--------------------------------------
  1003 // TRUE if Type is a singleton type, FALSE otherwise.   Singletons are simple
  1004 // constants (Ldi nodes).  Singletons are integer, float or double constants
  1005 // or a single symbol.
  1006 bool TypeF::singleton(void) const {
  1007   return true;                  // Always a singleton
  1010 bool TypeF::empty(void) const {
  1011   return false;                 // always exactly a singleton
  1014 //=============================================================================
  1015 // Convenience common pre-built types.
  1016 const TypeD *TypeD::ZERO;       // Floating point zero
  1017 const TypeD *TypeD::ONE;        // Floating point one
  1019 //------------------------------make-------------------------------------------
  1020 const TypeD *TypeD::make(double d) {
  1021   return (TypeD*)(new TypeD(d))->hashcons();
  1024 //------------------------------meet-------------------------------------------
  1025 // Compute the MEET of two types.  It returns a new Type object.
  1026 const Type *TypeD::xmeet( const Type *t ) const {
  1027   // Perform a fast test for common case; meeting the same types together.
  1028   if( this == t ) return this;  // Meeting same type-rep?
  1030   // Current "this->_base" is DoubleCon
  1031   switch (t->base()) {          // Switch on original type
  1032   case AnyPtr:                  // Mixing with oops happens when javac
  1033   case RawPtr:                  // reuses local variables
  1034   case OopPtr:
  1035   case InstPtr:
  1036   case AryPtr:
  1037   case MetadataPtr:
  1038   case KlassPtr:
  1039   case NarrowOop:
  1040   case NarrowKlass:
  1041   case Int:
  1042   case Long:
  1043   case FloatTop:
  1044   case FloatCon:
  1045   case FloatBot:
  1046   case Bottom:                  // Ye Olde Default
  1047     return Type::BOTTOM;
  1049   case DoubleBot:
  1050     return t;
  1052   default:                      // All else is a mistake
  1053     typerr(t);
  1055   case DoubleCon:               // Double-constant vs Double-constant?
  1056     if( jlong_cast(_d) != jlong_cast(t->getd()) )       // unequal constants? (see comment in TypeF::xmeet)
  1057       return DOUBLE;            // Return generic double
  1058   case Top:
  1059   case DoubleTop:
  1060     break;
  1062   return this;                  // Return the double constant
  1065 //------------------------------xdual------------------------------------------
  1066 // Dual: symmetric
  1067 const Type *TypeD::xdual() const {
  1068   return this;
  1071 //------------------------------eq---------------------------------------------
  1072 // Structural equality check for Type representations
  1073 bool TypeD::eq( const Type *t ) const {
  1074   if( g_isnan(_d) ||
  1075       g_isnan(t->getd()) ) {
  1076     // One or both are NANs.  If both are NANs return true, else false.
  1077     return (g_isnan(_d) && g_isnan(t->getd()));
  1079   if (_d == t->getd()) {
  1080     // (NaN is impossible at this point, since it is not equal even to itself)
  1081     if (_d == 0.0) {
  1082       // difference between positive and negative zero
  1083       if (jlong_cast(_d) != jlong_cast(t->getd()))  return false;
  1085     return true;
  1087   return false;
  1090 //------------------------------hash-------------------------------------------
  1091 // Type-specific hashing function.
  1092 int TypeD::hash(void) const {
  1093   return *(int*)(&_d);
  1096 //------------------------------is_finite--------------------------------------
  1097 // Has a finite value
  1098 bool TypeD::is_finite() const {
  1099   return g_isfinite(getd()) != 0;
  1102 //------------------------------is_nan-----------------------------------------
  1103 // Is not a number (NaN)
  1104 bool TypeD::is_nan()    const {
  1105   return g_isnan(getd()) != 0;
  1108 //------------------------------dump2------------------------------------------
  1109 // Dump double constant Type
  1110 #ifndef PRODUCT
  1111 void TypeD::dump2( Dict &d, uint depth, outputStream *st ) const {
  1112   Type::dump2(d,depth,st);
  1113   st->print("%f", _d);
  1115 #endif
  1117 //------------------------------singleton--------------------------------------
  1118 // TRUE if Type is a singleton type, FALSE otherwise.   Singletons are simple
  1119 // constants (Ldi nodes).  Singletons are integer, float or double constants
  1120 // or a single symbol.
  1121 bool TypeD::singleton(void) const {
  1122   return true;                  // Always a singleton
  1125 bool TypeD::empty(void) const {
  1126   return false;                 // always exactly a singleton
  1129 //=============================================================================
  1130 // Convience common pre-built types.
  1131 const TypeInt *TypeInt::MINUS_1;// -1
  1132 const TypeInt *TypeInt::ZERO;   // 0
  1133 const TypeInt *TypeInt::ONE;    // 1
  1134 const TypeInt *TypeInt::BOOL;   // 0 or 1, FALSE or TRUE.
  1135 const TypeInt *TypeInt::CC;     // -1,0 or 1, condition codes
  1136 const TypeInt *TypeInt::CC_LT;  // [-1]  == MINUS_1
  1137 const TypeInt *TypeInt::CC_GT;  // [1]   == ONE
  1138 const TypeInt *TypeInt::CC_EQ;  // [0]   == ZERO
  1139 const TypeInt *TypeInt::CC_LE;  // [-1,0]
  1140 const TypeInt *TypeInt::CC_GE;  // [0,1] == BOOL (!)
  1141 const TypeInt *TypeInt::BYTE;   // Bytes, -128 to 127
  1142 const TypeInt *TypeInt::UBYTE;  // Unsigned Bytes, 0 to 255
  1143 const TypeInt *TypeInt::CHAR;   // Java chars, 0-65535
  1144 const TypeInt *TypeInt::SHORT;  // Java shorts, -32768-32767
  1145 const TypeInt *TypeInt::POS;    // Positive 32-bit integers or zero
  1146 const TypeInt *TypeInt::POS1;   // Positive 32-bit integers
  1147 const TypeInt *TypeInt::INT;    // 32-bit integers
  1148 const TypeInt *TypeInt::SYMINT; // symmetric range [-max_jint..max_jint]
  1150 //------------------------------TypeInt----------------------------------------
  1151 TypeInt::TypeInt( jint lo, jint hi, int w ) : Type(Int), _lo(lo), _hi(hi), _widen(w) {
  1154 //------------------------------make-------------------------------------------
  1155 const TypeInt *TypeInt::make( jint lo ) {
  1156   return (TypeInt*)(new TypeInt(lo,lo,WidenMin))->hashcons();
  1159 static int normalize_int_widen( jint lo, jint hi, int w ) {
  1160   // Certain normalizations keep us sane when comparing types.
  1161   // The 'SMALLINT' covers constants and also CC and its relatives.
  1162   if (lo <= hi) {
  1163     if ((juint)(hi - lo) <= SMALLINT)  w = Type::WidenMin;
  1164     if ((juint)(hi - lo) >= max_juint) w = Type::WidenMax; // TypeInt::INT
  1165   } else {
  1166     if ((juint)(lo - hi) <= SMALLINT)  w = Type::WidenMin;
  1167     if ((juint)(lo - hi) >= max_juint) w = Type::WidenMin; // dual TypeInt::INT
  1169   return w;
  1172 const TypeInt *TypeInt::make( jint lo, jint hi, int w ) {
  1173   w = normalize_int_widen(lo, hi, w);
  1174   return (TypeInt*)(new TypeInt(lo,hi,w))->hashcons();
  1177 //------------------------------meet-------------------------------------------
  1178 // Compute the MEET of two types.  It returns a new Type representation object
  1179 // with reference count equal to the number of Types pointing at it.
  1180 // Caller should wrap a Types around it.
  1181 const Type *TypeInt::xmeet( const Type *t ) const {
  1182   // Perform a fast test for common case; meeting the same types together.
  1183   if( this == t ) return this;  // Meeting same type?
  1185   // Currently "this->_base" is a TypeInt
  1186   switch (t->base()) {          // Switch on original type
  1187   case AnyPtr:                  // Mixing with oops happens when javac
  1188   case RawPtr:                  // reuses local variables
  1189   case OopPtr:
  1190   case InstPtr:
  1191   case AryPtr:
  1192   case MetadataPtr:
  1193   case KlassPtr:
  1194   case NarrowOop:
  1195   case NarrowKlass:
  1196   case Long:
  1197   case FloatTop:
  1198   case FloatCon:
  1199   case FloatBot:
  1200   case DoubleTop:
  1201   case DoubleCon:
  1202   case DoubleBot:
  1203   case Bottom:                  // Ye Olde Default
  1204     return Type::BOTTOM;
  1205   default:                      // All else is a mistake
  1206     typerr(t);
  1207   case Top:                     // No change
  1208     return this;
  1209   case Int:                     // Int vs Int?
  1210     break;
  1213   // Expand covered set
  1214   const TypeInt *r = t->is_int();
  1215   return make( MIN2(_lo,r->_lo), MAX2(_hi,r->_hi), MAX2(_widen,r->_widen) );
  1218 //------------------------------xdual------------------------------------------
  1219 // Dual: reverse hi & lo; flip widen
  1220 const Type *TypeInt::xdual() const {
  1221   int w = normalize_int_widen(_hi,_lo, WidenMax-_widen);
  1222   return new TypeInt(_hi,_lo,w);
  1225 //------------------------------widen------------------------------------------
  1226 // Only happens for optimistic top-down optimizations.
  1227 const Type *TypeInt::widen( const Type *old, const Type* limit ) const {
  1228   // Coming from TOP or such; no widening
  1229   if( old->base() != Int ) return this;
  1230   const TypeInt *ot = old->is_int();
  1232   // If new guy is equal to old guy, no widening
  1233   if( _lo == ot->_lo && _hi == ot->_hi )
  1234     return old;
  1236   // If new guy contains old, then we widened
  1237   if( _lo <= ot->_lo && _hi >= ot->_hi ) {
  1238     // New contains old
  1239     // If new guy is already wider than old, no widening
  1240     if( _widen > ot->_widen ) return this;
  1241     // If old guy was a constant, do not bother
  1242     if (ot->_lo == ot->_hi)  return this;
  1243     // Now widen new guy.
  1244     // Check for widening too far
  1245     if (_widen == WidenMax) {
  1246       int max = max_jint;
  1247       int min = min_jint;
  1248       if (limit->isa_int()) {
  1249         max = limit->is_int()->_hi;
  1250         min = limit->is_int()->_lo;
  1252       if (min < _lo && _hi < max) {
  1253         // If neither endpoint is extremal yet, push out the endpoint
  1254         // which is closer to its respective limit.
  1255         if (_lo >= 0 ||                 // easy common case
  1256             (juint)(_lo - min) >= (juint)(max - _hi)) {
  1257           // Try to widen to an unsigned range type of 31 bits:
  1258           return make(_lo, max, WidenMax);
  1259         } else {
  1260           return make(min, _hi, WidenMax);
  1263       return TypeInt::INT;
  1265     // Returned widened new guy
  1266     return make(_lo,_hi,_widen+1);
  1269   // If old guy contains new, then we probably widened too far & dropped to
  1270   // bottom.  Return the wider fellow.
  1271   if ( ot->_lo <= _lo && ot->_hi >= _hi )
  1272     return old;
  1274   //fatal("Integer value range is not subset");
  1275   //return this;
  1276   return TypeInt::INT;
  1279 //------------------------------narrow---------------------------------------
  1280 // Only happens for pessimistic optimizations.
  1281 const Type *TypeInt::narrow( const Type *old ) const {
  1282   if (_lo >= _hi)  return this;   // already narrow enough
  1283   if (old == NULL)  return this;
  1284   const TypeInt* ot = old->isa_int();
  1285   if (ot == NULL)  return this;
  1286   jint olo = ot->_lo;
  1287   jint ohi = ot->_hi;
  1289   // If new guy is equal to old guy, no narrowing
  1290   if (_lo == olo && _hi == ohi)  return old;
  1292   // If old guy was maximum range, allow the narrowing
  1293   if (olo == min_jint && ohi == max_jint)  return this;
  1295   if (_lo < olo || _hi > ohi)
  1296     return this;                // doesn't narrow; pretty wierd
  1298   // The new type narrows the old type, so look for a "death march".
  1299   // See comments on PhaseTransform::saturate.
  1300   juint nrange = _hi - _lo;
  1301   juint orange = ohi - olo;
  1302   if (nrange < max_juint - 1 && nrange > (orange >> 1) + (SMALLINT*2)) {
  1303     // Use the new type only if the range shrinks a lot.
  1304     // We do not want the optimizer computing 2^31 point by point.
  1305     return old;
  1308   return this;
  1311 //-----------------------------filter------------------------------------------
  1312 const Type *TypeInt::filter( const Type *kills ) const {
  1313   const TypeInt* ft = join(kills)->isa_int();
  1314   if (ft == NULL || ft->empty())
  1315     return Type::TOP;           // Canonical empty value
  1316   if (ft->_widen < this->_widen) {
  1317     // Do not allow the value of kill->_widen to affect the outcome.
  1318     // The widen bits must be allowed to run freely through the graph.
  1319     ft = TypeInt::make(ft->_lo, ft->_hi, this->_widen);
  1321   return ft;
  1324 //------------------------------eq---------------------------------------------
  1325 // Structural equality check for Type representations
  1326 bool TypeInt::eq( const Type *t ) const {
  1327   const TypeInt *r = t->is_int(); // Handy access
  1328   return r->_lo == _lo && r->_hi == _hi && r->_widen == _widen;
  1331 //------------------------------hash-------------------------------------------
  1332 // Type-specific hashing function.
  1333 int TypeInt::hash(void) const {
  1334   return _lo+_hi+_widen+(int)Type::Int;
  1337 //------------------------------is_finite--------------------------------------
  1338 // Has a finite value
  1339 bool TypeInt::is_finite() const {
  1340   return true;
  1343 //------------------------------dump2------------------------------------------
  1344 // Dump TypeInt
  1345 #ifndef PRODUCT
  1346 static const char* intname(char* buf, jint n) {
  1347   if (n == min_jint)
  1348     return "min";
  1349   else if (n < min_jint + 10000)
  1350     sprintf(buf, "min+" INT32_FORMAT, n - min_jint);
  1351   else if (n == max_jint)
  1352     return "max";
  1353   else if (n > max_jint - 10000)
  1354     sprintf(buf, "max-" INT32_FORMAT, max_jint - n);
  1355   else
  1356     sprintf(buf, INT32_FORMAT, n);
  1357   return buf;
  1360 void TypeInt::dump2( Dict &d, uint depth, outputStream *st ) const {
  1361   char buf[40], buf2[40];
  1362   if (_lo == min_jint && _hi == max_jint)
  1363     st->print("int");
  1364   else if (is_con())
  1365     st->print("int:%s", intname(buf, get_con()));
  1366   else if (_lo == BOOL->_lo && _hi == BOOL->_hi)
  1367     st->print("bool");
  1368   else if (_lo == BYTE->_lo && _hi == BYTE->_hi)
  1369     st->print("byte");
  1370   else if (_lo == CHAR->_lo && _hi == CHAR->_hi)
  1371     st->print("char");
  1372   else if (_lo == SHORT->_lo && _hi == SHORT->_hi)
  1373     st->print("short");
  1374   else if (_hi == max_jint)
  1375     st->print("int:>=%s", intname(buf, _lo));
  1376   else if (_lo == min_jint)
  1377     st->print("int:<=%s", intname(buf, _hi));
  1378   else
  1379     st->print("int:%s..%s", intname(buf, _lo), intname(buf2, _hi));
  1381   if (_widen != 0 && this != TypeInt::INT)
  1382     st->print(":%.*s", _widen, "wwww");
  1384 #endif
  1386 //------------------------------singleton--------------------------------------
  1387 // TRUE if Type is a singleton type, FALSE otherwise.   Singletons are simple
  1388 // constants.
  1389 bool TypeInt::singleton(void) const {
  1390   return _lo >= _hi;
  1393 bool TypeInt::empty(void) const {
  1394   return _lo > _hi;
  1397 //=============================================================================
  1398 // Convenience common pre-built types.
  1399 const TypeLong *TypeLong::MINUS_1;// -1
  1400 const TypeLong *TypeLong::ZERO; // 0
  1401 const TypeLong *TypeLong::ONE;  // 1
  1402 const TypeLong *TypeLong::POS;  // >=0
  1403 const TypeLong *TypeLong::LONG; // 64-bit integers
  1404 const TypeLong *TypeLong::INT;  // 32-bit subrange
  1405 const TypeLong *TypeLong::UINT; // 32-bit unsigned subrange
  1407 //------------------------------TypeLong---------------------------------------
  1408 TypeLong::TypeLong( jlong lo, jlong hi, int w ) : Type(Long), _lo(lo), _hi(hi), _widen(w) {
  1411 //------------------------------make-------------------------------------------
  1412 const TypeLong *TypeLong::make( jlong lo ) {
  1413   return (TypeLong*)(new TypeLong(lo,lo,WidenMin))->hashcons();
  1416 static int normalize_long_widen( jlong lo, jlong hi, int w ) {
  1417   // Certain normalizations keep us sane when comparing types.
  1418   // The 'SMALLINT' covers constants.
  1419   if (lo <= hi) {
  1420     if ((julong)(hi - lo) <= SMALLINT)   w = Type::WidenMin;
  1421     if ((julong)(hi - lo) >= max_julong) w = Type::WidenMax; // TypeLong::LONG
  1422   } else {
  1423     if ((julong)(lo - hi) <= SMALLINT)   w = Type::WidenMin;
  1424     if ((julong)(lo - hi) >= max_julong) w = Type::WidenMin; // dual TypeLong::LONG
  1426   return w;
  1429 const TypeLong *TypeLong::make( jlong lo, jlong hi, int w ) {
  1430   w = normalize_long_widen(lo, hi, w);
  1431   return (TypeLong*)(new TypeLong(lo,hi,w))->hashcons();
  1435 //------------------------------meet-------------------------------------------
  1436 // Compute the MEET of two types.  It returns a new Type representation object
  1437 // with reference count equal to the number of Types pointing at it.
  1438 // Caller should wrap a Types around it.
  1439 const Type *TypeLong::xmeet( const Type *t ) const {
  1440   // Perform a fast test for common case; meeting the same types together.
  1441   if( this == t ) return this;  // Meeting same type?
  1443   // Currently "this->_base" is a TypeLong
  1444   switch (t->base()) {          // Switch on original type
  1445   case AnyPtr:                  // Mixing with oops happens when javac
  1446   case RawPtr:                  // reuses local variables
  1447   case OopPtr:
  1448   case InstPtr:
  1449   case AryPtr:
  1450   case MetadataPtr:
  1451   case KlassPtr:
  1452   case NarrowOop:
  1453   case NarrowKlass:
  1454   case Int:
  1455   case FloatTop:
  1456   case FloatCon:
  1457   case FloatBot:
  1458   case DoubleTop:
  1459   case DoubleCon:
  1460   case DoubleBot:
  1461   case Bottom:                  // Ye Olde Default
  1462     return Type::BOTTOM;
  1463   default:                      // All else is a mistake
  1464     typerr(t);
  1465   case Top:                     // No change
  1466     return this;
  1467   case Long:                    // Long vs Long?
  1468     break;
  1471   // Expand covered set
  1472   const TypeLong *r = t->is_long(); // Turn into a TypeLong
  1473   return make( MIN2(_lo,r->_lo), MAX2(_hi,r->_hi), MAX2(_widen,r->_widen) );
  1476 //------------------------------xdual------------------------------------------
  1477 // Dual: reverse hi & lo; flip widen
  1478 const Type *TypeLong::xdual() const {
  1479   int w = normalize_long_widen(_hi,_lo, WidenMax-_widen);
  1480   return new TypeLong(_hi,_lo,w);
  1483 //------------------------------widen------------------------------------------
  1484 // Only happens for optimistic top-down optimizations.
  1485 const Type *TypeLong::widen( const Type *old, const Type* limit ) const {
  1486   // Coming from TOP or such; no widening
  1487   if( old->base() != Long ) return this;
  1488   const TypeLong *ot = old->is_long();
  1490   // If new guy is equal to old guy, no widening
  1491   if( _lo == ot->_lo && _hi == ot->_hi )
  1492     return old;
  1494   // If new guy contains old, then we widened
  1495   if( _lo <= ot->_lo && _hi >= ot->_hi ) {
  1496     // New contains old
  1497     // If new guy is already wider than old, no widening
  1498     if( _widen > ot->_widen ) return this;
  1499     // If old guy was a constant, do not bother
  1500     if (ot->_lo == ot->_hi)  return this;
  1501     // Now widen new guy.
  1502     // Check for widening too far
  1503     if (_widen == WidenMax) {
  1504       jlong max = max_jlong;
  1505       jlong min = min_jlong;
  1506       if (limit->isa_long()) {
  1507         max = limit->is_long()->_hi;
  1508         min = limit->is_long()->_lo;
  1510       if (min < _lo && _hi < max) {
  1511         // If neither endpoint is extremal yet, push out the endpoint
  1512         // which is closer to its respective limit.
  1513         if (_lo >= 0 ||                 // easy common case
  1514             (julong)(_lo - min) >= (julong)(max - _hi)) {
  1515           // Try to widen to an unsigned range type of 32/63 bits:
  1516           if (max >= max_juint && _hi < max_juint)
  1517             return make(_lo, max_juint, WidenMax);
  1518           else
  1519             return make(_lo, max, WidenMax);
  1520         } else {
  1521           return make(min, _hi, WidenMax);
  1524       return TypeLong::LONG;
  1526     // Returned widened new guy
  1527     return make(_lo,_hi,_widen+1);
  1530   // If old guy contains new, then we probably widened too far & dropped to
  1531   // bottom.  Return the wider fellow.
  1532   if ( ot->_lo <= _lo && ot->_hi >= _hi )
  1533     return old;
  1535   //  fatal("Long value range is not subset");
  1536   // return this;
  1537   return TypeLong::LONG;
  1540 //------------------------------narrow----------------------------------------
  1541 // Only happens for pessimistic optimizations.
  1542 const Type *TypeLong::narrow( const Type *old ) const {
  1543   if (_lo >= _hi)  return this;   // already narrow enough
  1544   if (old == NULL)  return this;
  1545   const TypeLong* ot = old->isa_long();
  1546   if (ot == NULL)  return this;
  1547   jlong olo = ot->_lo;
  1548   jlong ohi = ot->_hi;
  1550   // If new guy is equal to old guy, no narrowing
  1551   if (_lo == olo && _hi == ohi)  return old;
  1553   // If old guy was maximum range, allow the narrowing
  1554   if (olo == min_jlong && ohi == max_jlong)  return this;
  1556   if (_lo < olo || _hi > ohi)
  1557     return this;                // doesn't narrow; pretty wierd
  1559   // The new type narrows the old type, so look for a "death march".
  1560   // See comments on PhaseTransform::saturate.
  1561   julong nrange = _hi - _lo;
  1562   julong orange = ohi - olo;
  1563   if (nrange < max_julong - 1 && nrange > (orange >> 1) + (SMALLINT*2)) {
  1564     // Use the new type only if the range shrinks a lot.
  1565     // We do not want the optimizer computing 2^31 point by point.
  1566     return old;
  1569   return this;
  1572 //-----------------------------filter------------------------------------------
  1573 const Type *TypeLong::filter( const Type *kills ) const {
  1574   const TypeLong* ft = join(kills)->isa_long();
  1575   if (ft == NULL || ft->empty())
  1576     return Type::TOP;           // Canonical empty value
  1577   if (ft->_widen < this->_widen) {
  1578     // Do not allow the value of kill->_widen to affect the outcome.
  1579     // The widen bits must be allowed to run freely through the graph.
  1580     ft = TypeLong::make(ft->_lo, ft->_hi, this->_widen);
  1582   return ft;
  1585 //------------------------------eq---------------------------------------------
  1586 // Structural equality check for Type representations
  1587 bool TypeLong::eq( const Type *t ) const {
  1588   const TypeLong *r = t->is_long(); // Handy access
  1589   return r->_lo == _lo &&  r->_hi == _hi  && r->_widen == _widen;
  1592 //------------------------------hash-------------------------------------------
  1593 // Type-specific hashing function.
  1594 int TypeLong::hash(void) const {
  1595   return (int)(_lo+_hi+_widen+(int)Type::Long);
  1598 //------------------------------is_finite--------------------------------------
  1599 // Has a finite value
  1600 bool TypeLong::is_finite() const {
  1601   return true;
  1604 //------------------------------dump2------------------------------------------
  1605 // Dump TypeLong
  1606 #ifndef PRODUCT
  1607 static const char* longnamenear(jlong x, const char* xname, char* buf, jlong n) {
  1608   if (n > x) {
  1609     if (n >= x + 10000)  return NULL;
  1610     sprintf(buf, "%s+" JLONG_FORMAT, xname, n - x);
  1611   } else if (n < x) {
  1612     if (n <= x - 10000)  return NULL;
  1613     sprintf(buf, "%s-" JLONG_FORMAT, xname, x - n);
  1614   } else {
  1615     return xname;
  1617   return buf;
  1620 static const char* longname(char* buf, jlong n) {
  1621   const char* str;
  1622   if (n == min_jlong)
  1623     return "min";
  1624   else if (n < min_jlong + 10000)
  1625     sprintf(buf, "min+" JLONG_FORMAT, n - min_jlong);
  1626   else if (n == max_jlong)
  1627     return "max";
  1628   else if (n > max_jlong - 10000)
  1629     sprintf(buf, "max-" JLONG_FORMAT, max_jlong - n);
  1630   else if ((str = longnamenear(max_juint, "maxuint", buf, n)) != NULL)
  1631     return str;
  1632   else if ((str = longnamenear(max_jint, "maxint", buf, n)) != NULL)
  1633     return str;
  1634   else if ((str = longnamenear(min_jint, "minint", buf, n)) != NULL)
  1635     return str;
  1636   else
  1637     sprintf(buf, JLONG_FORMAT, n);
  1638   return buf;
  1641 void TypeLong::dump2( Dict &d, uint depth, outputStream *st ) const {
  1642   char buf[80], buf2[80];
  1643   if (_lo == min_jlong && _hi == max_jlong)
  1644     st->print("long");
  1645   else if (is_con())
  1646     st->print("long:%s", longname(buf, get_con()));
  1647   else if (_hi == max_jlong)
  1648     st->print("long:>=%s", longname(buf, _lo));
  1649   else if (_lo == min_jlong)
  1650     st->print("long:<=%s", longname(buf, _hi));
  1651   else
  1652     st->print("long:%s..%s", longname(buf, _lo), longname(buf2, _hi));
  1654   if (_widen != 0 && this != TypeLong::LONG)
  1655     st->print(":%.*s", _widen, "wwww");
  1657 #endif
  1659 //------------------------------singleton--------------------------------------
  1660 // TRUE if Type is a singleton type, FALSE otherwise.   Singletons are simple
  1661 // constants
  1662 bool TypeLong::singleton(void) const {
  1663   return _lo >= _hi;
  1666 bool TypeLong::empty(void) const {
  1667   return _lo > _hi;
  1670 //=============================================================================
  1671 // Convenience common pre-built types.
  1672 const TypeTuple *TypeTuple::IFBOTH;     // Return both arms of IF as reachable
  1673 const TypeTuple *TypeTuple::IFFALSE;
  1674 const TypeTuple *TypeTuple::IFTRUE;
  1675 const TypeTuple *TypeTuple::IFNEITHER;
  1676 const TypeTuple *TypeTuple::LOOPBODY;
  1677 const TypeTuple *TypeTuple::MEMBAR;
  1678 const TypeTuple *TypeTuple::STORECONDITIONAL;
  1679 const TypeTuple *TypeTuple::START_I2C;
  1680 const TypeTuple *TypeTuple::INT_PAIR;
  1681 const TypeTuple *TypeTuple::LONG_PAIR;
  1682 const TypeTuple *TypeTuple::INT_CC_PAIR;
  1683 const TypeTuple *TypeTuple::LONG_CC_PAIR;
  1686 //------------------------------make-------------------------------------------
  1687 // Make a TypeTuple from the range of a method signature
  1688 const TypeTuple *TypeTuple::make_range(ciSignature* sig) {
  1689   ciType* return_type = sig->return_type();
  1690   uint total_fields = TypeFunc::Parms + return_type->size();
  1691   const Type **field_array = fields(total_fields);
  1692   switch (return_type->basic_type()) {
  1693   case T_LONG:
  1694     field_array[TypeFunc::Parms]   = TypeLong::LONG;
  1695     field_array[TypeFunc::Parms+1] = Type::HALF;
  1696     break;
  1697   case T_DOUBLE:
  1698     field_array[TypeFunc::Parms]   = Type::DOUBLE;
  1699     field_array[TypeFunc::Parms+1] = Type::HALF;
  1700     break;
  1701   case T_OBJECT:
  1702   case T_ARRAY:
  1703   case T_BOOLEAN:
  1704   case T_CHAR:
  1705   case T_FLOAT:
  1706   case T_BYTE:
  1707   case T_SHORT:
  1708   case T_INT:
  1709     field_array[TypeFunc::Parms] = get_const_type(return_type);
  1710     break;
  1711   case T_VOID:
  1712     break;
  1713   default:
  1714     ShouldNotReachHere();
  1716   return (TypeTuple*)(new TypeTuple(total_fields,field_array))->hashcons();
  1719 // Make a TypeTuple from the domain of a method signature
  1720 const TypeTuple *TypeTuple::make_domain(ciInstanceKlass* recv, ciSignature* sig) {
  1721   uint total_fields = TypeFunc::Parms + sig->size();
  1723   uint pos = TypeFunc::Parms;
  1724   const Type **field_array;
  1725   if (recv != NULL) {
  1726     total_fields++;
  1727     field_array = fields(total_fields);
  1728     // Use get_const_type here because it respects UseUniqueSubclasses:
  1729     field_array[pos++] = get_const_type(recv)->join(TypePtr::NOTNULL);
  1730   } else {
  1731     field_array = fields(total_fields);
  1734   int i = 0;
  1735   while (pos < total_fields) {
  1736     ciType* type = sig->type_at(i);
  1738     switch (type->basic_type()) {
  1739     case T_LONG:
  1740       field_array[pos++] = TypeLong::LONG;
  1741       field_array[pos++] = Type::HALF;
  1742       break;
  1743     case T_DOUBLE:
  1744       field_array[pos++] = Type::DOUBLE;
  1745       field_array[pos++] = Type::HALF;
  1746       break;
  1747     case T_OBJECT:
  1748     case T_ARRAY:
  1749     case T_BOOLEAN:
  1750     case T_CHAR:
  1751     case T_FLOAT:
  1752     case T_BYTE:
  1753     case T_SHORT:
  1754     case T_INT:
  1755       field_array[pos++] = get_const_type(type);
  1756       break;
  1757     default:
  1758       ShouldNotReachHere();
  1760     i++;
  1762   return (TypeTuple*)(new TypeTuple(total_fields,field_array))->hashcons();
  1765 const TypeTuple *TypeTuple::make( uint cnt, const Type **fields ) {
  1766   return (TypeTuple*)(new TypeTuple(cnt,fields))->hashcons();
  1769 //------------------------------fields-----------------------------------------
  1770 // Subroutine call type with space allocated for argument types
  1771 const Type **TypeTuple::fields( uint arg_cnt ) {
  1772   const Type **flds = (const Type **)(Compile::current()->type_arena()->Amalloc_4((TypeFunc::Parms+arg_cnt)*sizeof(Type*) ));
  1773   flds[TypeFunc::Control  ] = Type::CONTROL;
  1774   flds[TypeFunc::I_O      ] = Type::ABIO;
  1775   flds[TypeFunc::Memory   ] = Type::MEMORY;
  1776   flds[TypeFunc::FramePtr ] = TypeRawPtr::BOTTOM;
  1777   flds[TypeFunc::ReturnAdr] = Type::RETURN_ADDRESS;
  1779   return flds;
  1782 //------------------------------meet-------------------------------------------
  1783 // Compute the MEET of two types.  It returns a new Type object.
  1784 const Type *TypeTuple::xmeet( const Type *t ) const {
  1785   // Perform a fast test for common case; meeting the same types together.
  1786   if( this == t ) return this;  // Meeting same type-rep?
  1788   // Current "this->_base" is Tuple
  1789   switch (t->base()) {          // switch on original type
  1791   case Bottom:                  // Ye Olde Default
  1792     return t;
  1794   default:                      // All else is a mistake
  1795     typerr(t);
  1797   case Tuple: {                 // Meeting 2 signatures?
  1798     const TypeTuple *x = t->is_tuple();
  1799     assert( _cnt == x->_cnt, "" );
  1800     const Type **fields = (const Type **)(Compile::current()->type_arena()->Amalloc_4( _cnt*sizeof(Type*) ));
  1801     for( uint i=0; i<_cnt; i++ )
  1802       fields[i] = field_at(i)->xmeet( x->field_at(i) );
  1803     return TypeTuple::make(_cnt,fields);
  1805   case Top:
  1806     break;
  1808   return this;                  // Return the double constant
  1811 //------------------------------xdual------------------------------------------
  1812 // Dual: compute field-by-field dual
  1813 const Type *TypeTuple::xdual() const {
  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] = _fields[i]->dual();
  1817   return new TypeTuple(_cnt,fields);
  1820 //------------------------------eq---------------------------------------------
  1821 // Structural equality check for Type representations
  1822 bool TypeTuple::eq( const Type *t ) const {
  1823   const TypeTuple *s = (const TypeTuple *)t;
  1824   if (_cnt != s->_cnt)  return false;  // Unequal field counts
  1825   for (uint i = 0; i < _cnt; i++)
  1826     if (field_at(i) != s->field_at(i)) // POINTER COMPARE!  NO RECURSION!
  1827       return false;             // Missed
  1828   return true;
  1831 //------------------------------hash-------------------------------------------
  1832 // Type-specific hashing function.
  1833 int TypeTuple::hash(void) const {
  1834   intptr_t sum = _cnt;
  1835   for( uint i=0; i<_cnt; i++ )
  1836     sum += (intptr_t)_fields[i];     // Hash on pointers directly
  1837   return sum;
  1840 //------------------------------dump2------------------------------------------
  1841 // Dump signature Type
  1842 #ifndef PRODUCT
  1843 void TypeTuple::dump2( Dict &d, uint depth, outputStream *st ) const {
  1844   st->print("{");
  1845   if( !depth || d[this] ) {     // Check for recursive print
  1846     st->print("...}");
  1847     return;
  1849   d.Insert((void*)this, (void*)this);   // Stop recursion
  1850   if( _cnt ) {
  1851     uint i;
  1852     for( i=0; i<_cnt-1; i++ ) {
  1853       st->print("%d:", i);
  1854       _fields[i]->dump2(d, depth-1, st);
  1855       st->print(", ");
  1857     st->print("%d:", i);
  1858     _fields[i]->dump2(d, depth-1, st);
  1860   st->print("}");
  1862 #endif
  1864 //------------------------------singleton--------------------------------------
  1865 // TRUE if Type is a singleton type, FALSE otherwise.   Singletons are simple
  1866 // constants (Ldi nodes).  Singletons are integer, float or double constants
  1867 // or a single symbol.
  1868 bool TypeTuple::singleton(void) const {
  1869   return false;                 // Never a singleton
  1872 bool TypeTuple::empty(void) const {
  1873   for( uint i=0; i<_cnt; i++ ) {
  1874     if (_fields[i]->empty())  return true;
  1876   return false;
  1879 //=============================================================================
  1880 // Convenience common pre-built types.
  1882 inline const TypeInt* normalize_array_size(const TypeInt* size) {
  1883   // Certain normalizations keep us sane when comparing types.
  1884   // We do not want arrayOop variables to differ only by the wideness
  1885   // of their index types.  Pick minimum wideness, since that is the
  1886   // forced wideness of small ranges anyway.
  1887   if (size->_widen != Type::WidenMin)
  1888     return TypeInt::make(size->_lo, size->_hi, Type::WidenMin);
  1889   else
  1890     return size;
  1893 //------------------------------make-------------------------------------------
  1894 const TypeAry* TypeAry::make(const Type* elem, const TypeInt* size, bool stable) {
  1895   if (UseCompressedOops && elem->isa_oopptr()) {
  1896     elem = elem->make_narrowoop();
  1898   size = normalize_array_size(size);
  1899   return (TypeAry*)(new TypeAry(elem,size,stable))->hashcons();
  1902 //------------------------------meet-------------------------------------------
  1903 // Compute the MEET of two types.  It returns a new Type object.
  1904 const Type *TypeAry::xmeet( const Type *t ) const {
  1905   // Perform a fast test for common case; meeting the same types together.
  1906   if( this == t ) return this;  // Meeting same type-rep?
  1908   // Current "this->_base" is Ary
  1909   switch (t->base()) {          // switch on original type
  1911   case Bottom:                  // Ye Olde Default
  1912     return t;
  1914   default:                      // All else is a mistake
  1915     typerr(t);
  1917   case Array: {                 // Meeting 2 arrays?
  1918     const TypeAry *a = t->is_ary();
  1919     return TypeAry::make(_elem->meet(a->_elem),
  1920                          _size->xmeet(a->_size)->is_int(),
  1921                          _stable & a->_stable);
  1923   case Top:
  1924     break;
  1926   return this;                  // Return the double constant
  1929 //------------------------------xdual------------------------------------------
  1930 // Dual: compute field-by-field dual
  1931 const Type *TypeAry::xdual() const {
  1932   const TypeInt* size_dual = _size->dual()->is_int();
  1933   size_dual = normalize_array_size(size_dual);
  1934   return new TypeAry(_elem->dual(), size_dual, !_stable);
  1937 //------------------------------eq---------------------------------------------
  1938 // Structural equality check for Type representations
  1939 bool TypeAry::eq( const Type *t ) const {
  1940   const TypeAry *a = (const TypeAry*)t;
  1941   return _elem == a->_elem &&
  1942     _stable == a->_stable &&
  1943     _size == a->_size;
  1946 //------------------------------hash-------------------------------------------
  1947 // Type-specific hashing function.
  1948 int TypeAry::hash(void) const {
  1949   return (intptr_t)_elem + (intptr_t)_size + (_stable ? 43 : 0);
  1952 //----------------------interface_vs_oop---------------------------------------
  1953 #ifdef ASSERT
  1954 bool TypeAry::interface_vs_oop(const Type *t) const {
  1955   const TypeAry* t_ary = t->is_ary();
  1956   if (t_ary) {
  1957     return _elem->interface_vs_oop(t_ary->_elem);
  1959   return false;
  1961 #endif
  1963 //------------------------------dump2------------------------------------------
  1964 #ifndef PRODUCT
  1965 void TypeAry::dump2( Dict &d, uint depth, outputStream *st ) const {
  1966   if (_stable)  st->print("stable:");
  1967   _elem->dump2(d, depth, st);
  1968   st->print("[");
  1969   _size->dump2(d, depth, st);
  1970   st->print("]");
  1972 #endif
  1974 //------------------------------singleton--------------------------------------
  1975 // TRUE if Type is a singleton type, FALSE otherwise.   Singletons are simple
  1976 // constants (Ldi nodes).  Singletons are integer, float or double constants
  1977 // or a single symbol.
  1978 bool TypeAry::singleton(void) const {
  1979   return false;                 // Never a singleton
  1982 bool TypeAry::empty(void) const {
  1983   return _elem->empty() || _size->empty();
  1986 //--------------------------ary_must_be_exact----------------------------------
  1987 bool TypeAry::ary_must_be_exact() const {
  1988   if (!UseExactTypes)       return false;
  1989   // This logic looks at the element type of an array, and returns true
  1990   // if the element type is either a primitive or a final instance class.
  1991   // In such cases, an array built on this ary must have no subclasses.
  1992   if (_elem == BOTTOM)      return false;  // general array not exact
  1993   if (_elem == TOP   )      return false;  // inverted general array not exact
  1994   const TypeOopPtr*  toop = NULL;
  1995   if (UseCompressedOops && _elem->isa_narrowoop()) {
  1996     toop = _elem->make_ptr()->isa_oopptr();
  1997   } else {
  1998     toop = _elem->isa_oopptr();
  2000   if (!toop)                return true;   // a primitive type, like int
  2001   ciKlass* tklass = toop->klass();
  2002   if (tklass == NULL)       return false;  // unloaded class
  2003   if (!tklass->is_loaded()) return false;  // unloaded class
  2004   const TypeInstPtr* tinst;
  2005   if (_elem->isa_narrowoop())
  2006     tinst = _elem->make_ptr()->isa_instptr();
  2007   else
  2008     tinst = _elem->isa_instptr();
  2009   if (tinst)
  2010     return tklass->as_instance_klass()->is_final();
  2011   const TypeAryPtr*  tap;
  2012   if (_elem->isa_narrowoop())
  2013     tap = _elem->make_ptr()->isa_aryptr();
  2014   else
  2015     tap = _elem->isa_aryptr();
  2016   if (tap)
  2017     return tap->ary()->ary_must_be_exact();
  2018   return false;
  2021 //==============================TypeVect=======================================
  2022 // Convenience common pre-built types.
  2023 const TypeVect *TypeVect::VECTS = NULL; //  32-bit vectors
  2024 const TypeVect *TypeVect::VECTD = NULL; //  64-bit vectors
  2025 const TypeVect *TypeVect::VECTX = NULL; // 128-bit vectors
  2026 const TypeVect *TypeVect::VECTY = NULL; // 256-bit vectors
  2028 //------------------------------make-------------------------------------------
  2029 const TypeVect* TypeVect::make(const Type *elem, uint length) {
  2030   BasicType elem_bt = elem->array_element_basic_type();
  2031   assert(is_java_primitive(elem_bt), "only primitive types in vector");
  2032   assert(length > 1 && is_power_of_2(length), "vector length is power of 2");
  2033   assert(Matcher::vector_size_supported(elem_bt, length), "length in range");
  2034   int size = length * type2aelembytes(elem_bt);
  2035   switch (Matcher::vector_ideal_reg(size)) {
  2036   case Op_VecS:
  2037     return (TypeVect*)(new TypeVectS(elem, length))->hashcons();
  2038   case Op_VecD:
  2039   case Op_RegD:
  2040     return (TypeVect*)(new TypeVectD(elem, length))->hashcons();
  2041   case Op_VecX:
  2042     return (TypeVect*)(new TypeVectX(elem, length))->hashcons();
  2043   case Op_VecY:
  2044     return (TypeVect*)(new TypeVectY(elem, length))->hashcons();
  2046  ShouldNotReachHere();
  2047   return NULL;
  2050 //------------------------------meet-------------------------------------------
  2051 // Compute the MEET of two types.  It returns a new Type object.
  2052 const Type *TypeVect::xmeet( const Type *t ) const {
  2053   // Perform a fast test for common case; meeting the same types together.
  2054   if( this == t ) return this;  // Meeting same type-rep?
  2056   // Current "this->_base" is Vector
  2057   switch (t->base()) {          // switch on original type
  2059   case Bottom:                  // Ye Olde Default
  2060     return t;
  2062   default:                      // All else is a mistake
  2063     typerr(t);
  2065   case VectorS:
  2066   case VectorD:
  2067   case VectorX:
  2068   case VectorY: {                // Meeting 2 vectors?
  2069     const TypeVect* v = t->is_vect();
  2070     assert(  base() == v->base(), "");
  2071     assert(length() == v->length(), "");
  2072     assert(element_basic_type() == v->element_basic_type(), "");
  2073     return TypeVect::make(_elem->xmeet(v->_elem), _length);
  2075   case Top:
  2076     break;
  2078   return this;
  2081 //------------------------------xdual------------------------------------------
  2082 // Dual: compute field-by-field dual
  2083 const Type *TypeVect::xdual() const {
  2084   return new TypeVect(base(), _elem->dual(), _length);
  2087 //------------------------------eq---------------------------------------------
  2088 // Structural equality check for Type representations
  2089 bool TypeVect::eq(const Type *t) const {
  2090   const TypeVect *v = t->is_vect();
  2091   return (_elem == v->_elem) && (_length == v->_length);
  2094 //------------------------------hash-------------------------------------------
  2095 // Type-specific hashing function.
  2096 int TypeVect::hash(void) const {
  2097   return (intptr_t)_elem + (intptr_t)_length;
  2100 //------------------------------singleton--------------------------------------
  2101 // TRUE if Type is a singleton type, FALSE otherwise.   Singletons are simple
  2102 // constants (Ldi nodes).  Vector is singleton if all elements are the same
  2103 // constant value (when vector is created with Replicate code).
  2104 bool TypeVect::singleton(void) const {
  2105 // There is no Con node for vectors yet.
  2106 //  return _elem->singleton();
  2107   return false;
  2110 bool TypeVect::empty(void) const {
  2111   return _elem->empty();
  2114 //------------------------------dump2------------------------------------------
  2115 #ifndef PRODUCT
  2116 void TypeVect::dump2(Dict &d, uint depth, outputStream *st) const {
  2117   switch (base()) {
  2118   case VectorS:
  2119     st->print("vectors["); break;
  2120   case VectorD:
  2121     st->print("vectord["); break;
  2122   case VectorX:
  2123     st->print("vectorx["); break;
  2124   case VectorY:
  2125     st->print("vectory["); break;
  2126   default:
  2127     ShouldNotReachHere();
  2129   st->print("%d]:{", _length);
  2130   _elem->dump2(d, depth, st);
  2131   st->print("}");
  2133 #endif
  2136 //=============================================================================
  2137 // Convenience common pre-built types.
  2138 const TypePtr *TypePtr::NULL_PTR;
  2139 const TypePtr *TypePtr::NOTNULL;
  2140 const TypePtr *TypePtr::BOTTOM;
  2142 //------------------------------meet-------------------------------------------
  2143 // Meet over the PTR enum
  2144 const TypePtr::PTR TypePtr::ptr_meet[TypePtr::lastPTR][TypePtr::lastPTR] = {
  2145   //              TopPTR,    AnyNull,   Constant, Null,   NotNull, BotPTR,
  2146   { /* Top     */ TopPTR,    AnyNull,   Constant, Null,   NotNull, BotPTR,},
  2147   { /* AnyNull */ AnyNull,   AnyNull,   Constant, BotPTR, NotNull, BotPTR,},
  2148   { /* Constant*/ Constant,  Constant,  Constant, BotPTR, NotNull, BotPTR,},
  2149   { /* Null    */ Null,      BotPTR,    BotPTR,   Null,   BotPTR,  BotPTR,},
  2150   { /* NotNull */ NotNull,   NotNull,   NotNull,  BotPTR, NotNull, BotPTR,},
  2151   { /* BotPTR  */ BotPTR,    BotPTR,    BotPTR,   BotPTR, BotPTR,  BotPTR,}
  2152 };
  2154 //------------------------------make-------------------------------------------
  2155 const TypePtr *TypePtr::make( TYPES t, enum PTR ptr, int offset ) {
  2156   return (TypePtr*)(new TypePtr(t,ptr,offset))->hashcons();
  2159 //------------------------------cast_to_ptr_type-------------------------------
  2160 const Type *TypePtr::cast_to_ptr_type(PTR ptr) const {
  2161   assert(_base == AnyPtr, "subclass must override cast_to_ptr_type");
  2162   if( ptr == _ptr ) return this;
  2163   return make(_base, ptr, _offset);
  2166 //------------------------------get_con----------------------------------------
  2167 intptr_t TypePtr::get_con() const {
  2168   assert( _ptr == Null, "" );
  2169   return _offset;
  2172 //------------------------------meet-------------------------------------------
  2173 // Compute the MEET of two types.  It returns a new Type object.
  2174 const Type *TypePtr::xmeet( const Type *t ) const {
  2175   // Perform a fast test for common case; meeting the same types together.
  2176   if( this == t ) return this;  // Meeting same type-rep?
  2178   // Current "this->_base" is AnyPtr
  2179   switch (t->base()) {          // switch on original type
  2180   case Int:                     // Mixing ints & oops happens when javac
  2181   case Long:                    // reuses local variables
  2182   case FloatTop:
  2183   case FloatCon:
  2184   case FloatBot:
  2185   case DoubleTop:
  2186   case DoubleCon:
  2187   case DoubleBot:
  2188   case NarrowOop:
  2189   case NarrowKlass:
  2190   case Bottom:                  // Ye Olde Default
  2191     return Type::BOTTOM;
  2192   case Top:
  2193     return this;
  2195   case AnyPtr: {                // Meeting to AnyPtrs
  2196     const TypePtr *tp = t->is_ptr();
  2197     return make( AnyPtr, meet_ptr(tp->ptr()), meet_offset(tp->offset()) );
  2199   case RawPtr:                  // For these, flip the call around to cut down
  2200   case OopPtr:
  2201   case InstPtr:                 // on the cases I have to handle.
  2202   case AryPtr:
  2203   case MetadataPtr:
  2204   case KlassPtr:
  2205     return t->xmeet(this);      // Call in reverse direction
  2206   default:                      // All else is a mistake
  2207     typerr(t);
  2210   return this;
  2213 //------------------------------meet_offset------------------------------------
  2214 int TypePtr::meet_offset( int offset ) const {
  2215   // Either is 'TOP' offset?  Return the other offset!
  2216   if( _offset == OffsetTop ) return offset;
  2217   if( offset == OffsetTop ) return _offset;
  2218   // If either is different, return 'BOTTOM' offset
  2219   if( _offset != offset ) return OffsetBot;
  2220   return _offset;
  2223 //------------------------------dual_offset------------------------------------
  2224 int TypePtr::dual_offset( ) const {
  2225   if( _offset == OffsetTop ) return OffsetBot;// Map 'TOP' into 'BOTTOM'
  2226   if( _offset == OffsetBot ) return OffsetTop;// Map 'BOTTOM' into 'TOP'
  2227   return _offset;               // Map everything else into self
  2230 //------------------------------xdual------------------------------------------
  2231 // Dual: compute field-by-field dual
  2232 const TypePtr::PTR TypePtr::ptr_dual[TypePtr::lastPTR] = {
  2233   BotPTR, NotNull, Constant, Null, AnyNull, TopPTR
  2234 };
  2235 const Type *TypePtr::xdual() const {
  2236   return new TypePtr( AnyPtr, dual_ptr(), dual_offset() );
  2239 //------------------------------xadd_offset------------------------------------
  2240 int TypePtr::xadd_offset( intptr_t offset ) const {
  2241   // Adding to 'TOP' offset?  Return 'TOP'!
  2242   if( _offset == OffsetTop || offset == OffsetTop ) return OffsetTop;
  2243   // Adding to 'BOTTOM' offset?  Return 'BOTTOM'!
  2244   if( _offset == OffsetBot || offset == OffsetBot ) return OffsetBot;
  2245   // Addition overflows or "accidentally" equals to OffsetTop? Return 'BOTTOM'!
  2246   offset += (intptr_t)_offset;
  2247   if (offset != (int)offset || offset == OffsetTop) return OffsetBot;
  2249   // assert( _offset >= 0 && _offset+offset >= 0, "" );
  2250   // It is possible to construct a negative offset during PhaseCCP
  2252   return (int)offset;        // Sum valid offsets
  2255 //------------------------------add_offset-------------------------------------
  2256 const TypePtr *TypePtr::add_offset( intptr_t offset ) const {
  2257   return make( AnyPtr, _ptr, xadd_offset(offset) );
  2260 //------------------------------eq---------------------------------------------
  2261 // Structural equality check for Type representations
  2262 bool TypePtr::eq( const Type *t ) const {
  2263   const TypePtr *a = (const TypePtr*)t;
  2264   return _ptr == a->ptr() && _offset == a->offset();
  2267 //------------------------------hash-------------------------------------------
  2268 // Type-specific hashing function.
  2269 int TypePtr::hash(void) const {
  2270   return _ptr + _offset;
  2273 //------------------------------dump2------------------------------------------
  2274 const char *const TypePtr::ptr_msg[TypePtr::lastPTR] = {
  2275   "TopPTR","AnyNull","Constant","NULL","NotNull","BotPTR"
  2276 };
  2278 #ifndef PRODUCT
  2279 void TypePtr::dump2( Dict &d, uint depth, outputStream *st ) const {
  2280   if( _ptr == Null ) st->print("NULL");
  2281   else st->print("%s *", ptr_msg[_ptr]);
  2282   if( _offset == OffsetTop ) st->print("+top");
  2283   else if( _offset == OffsetBot ) st->print("+bot");
  2284   else if( _offset ) st->print("+%d", _offset);
  2286 #endif
  2288 //------------------------------singleton--------------------------------------
  2289 // TRUE if Type is a singleton type, FALSE otherwise.   Singletons are simple
  2290 // constants
  2291 bool TypePtr::singleton(void) const {
  2292   // TopPTR, Null, AnyNull, Constant are all singletons
  2293   return (_offset != OffsetBot) && !below_centerline(_ptr);
  2296 bool TypePtr::empty(void) const {
  2297   return (_offset == OffsetTop) || above_centerline(_ptr);
  2300 //=============================================================================
  2301 // Convenience common pre-built types.
  2302 const TypeRawPtr *TypeRawPtr::BOTTOM;
  2303 const TypeRawPtr *TypeRawPtr::NOTNULL;
  2305 //------------------------------make-------------------------------------------
  2306 const TypeRawPtr *TypeRawPtr::make( enum PTR ptr ) {
  2307   assert( ptr != Constant, "what is the constant?" );
  2308   assert( ptr != Null, "Use TypePtr for NULL" );
  2309   return (TypeRawPtr*)(new TypeRawPtr(ptr,0))->hashcons();
  2312 const TypeRawPtr *TypeRawPtr::make( address bits ) {
  2313   assert( bits, "Use TypePtr for NULL" );
  2314   return (TypeRawPtr*)(new TypeRawPtr(Constant,bits))->hashcons();
  2317 //------------------------------cast_to_ptr_type-------------------------------
  2318 const Type *TypeRawPtr::cast_to_ptr_type(PTR ptr) const {
  2319   assert( ptr != Constant, "what is the constant?" );
  2320   assert( ptr != Null, "Use TypePtr for NULL" );
  2321   assert( _bits==0, "Why cast a constant address?");
  2322   if( ptr == _ptr ) return this;
  2323   return make(ptr);
  2326 //------------------------------get_con----------------------------------------
  2327 intptr_t TypeRawPtr::get_con() const {
  2328   assert( _ptr == Null || _ptr == Constant, "" );
  2329   return (intptr_t)_bits;
  2332 //------------------------------meet-------------------------------------------
  2333 // Compute the MEET of two types.  It returns a new Type object.
  2334 const Type *TypeRawPtr::xmeet( const Type *t ) const {
  2335   // Perform a fast test for common case; meeting the same types together.
  2336   if( this == t ) return this;  // Meeting same type-rep?
  2338   // Current "this->_base" is RawPtr
  2339   switch( t->base() ) {         // switch on original type
  2340   case Bottom:                  // Ye Olde Default
  2341     return t;
  2342   case Top:
  2343     return this;
  2344   case AnyPtr:                  // Meeting to AnyPtrs
  2345     break;
  2346   case RawPtr: {                // might be top, bot, any/not or constant
  2347     enum PTR tptr = t->is_ptr()->ptr();
  2348     enum PTR ptr = meet_ptr( tptr );
  2349     if( ptr == Constant ) {     // Cannot be equal constants, so...
  2350       if( tptr == Constant && _ptr != Constant)  return t;
  2351       if( _ptr == Constant && tptr != Constant)  return this;
  2352       ptr = NotNull;            // Fall down in lattice
  2354     return make( ptr );
  2357   case OopPtr:
  2358   case InstPtr:
  2359   case AryPtr:
  2360   case MetadataPtr:
  2361   case KlassPtr:
  2362     return TypePtr::BOTTOM;     // Oop meet raw is not well defined
  2363   default:                      // All else is a mistake
  2364     typerr(t);
  2367   // Found an AnyPtr type vs self-RawPtr type
  2368   const TypePtr *tp = t->is_ptr();
  2369   switch (tp->ptr()) {
  2370   case TypePtr::TopPTR:  return this;
  2371   case TypePtr::BotPTR:  return t;
  2372   case TypePtr::Null:
  2373     if( _ptr == TypePtr::TopPTR ) return t;
  2374     return TypeRawPtr::BOTTOM;
  2375   case TypePtr::NotNull: return TypePtr::make( AnyPtr, meet_ptr(TypePtr::NotNull), tp->meet_offset(0) );
  2376   case TypePtr::AnyNull:
  2377     if( _ptr == TypePtr::Constant) return this;
  2378     return make( meet_ptr(TypePtr::AnyNull) );
  2379   default: ShouldNotReachHere();
  2381   return this;
  2384 //------------------------------xdual------------------------------------------
  2385 // Dual: compute field-by-field dual
  2386 const Type *TypeRawPtr::xdual() const {
  2387   return new TypeRawPtr( dual_ptr(), _bits );
  2390 //------------------------------add_offset-------------------------------------
  2391 const TypePtr *TypeRawPtr::add_offset( intptr_t offset ) const {
  2392   if( offset == OffsetTop ) return BOTTOM; // Undefined offset-> undefined pointer
  2393   if( offset == OffsetBot ) return BOTTOM; // Unknown offset-> unknown pointer
  2394   if( offset == 0 ) return this; // No change
  2395   switch (_ptr) {
  2396   case TypePtr::TopPTR:
  2397   case TypePtr::BotPTR:
  2398   case TypePtr::NotNull:
  2399     return this;
  2400   case TypePtr::Null:
  2401   case TypePtr::Constant: {
  2402     address bits = _bits+offset;
  2403     if ( bits == 0 ) return TypePtr::NULL_PTR;
  2404     return make( bits );
  2406   default:  ShouldNotReachHere();
  2408   return NULL;                  // Lint noise
  2411 //------------------------------eq---------------------------------------------
  2412 // Structural equality check for Type representations
  2413 bool TypeRawPtr::eq( const Type *t ) const {
  2414   const TypeRawPtr *a = (const TypeRawPtr*)t;
  2415   return _bits == a->_bits && TypePtr::eq(t);
  2418 //------------------------------hash-------------------------------------------
  2419 // Type-specific hashing function.
  2420 int TypeRawPtr::hash(void) const {
  2421   return (intptr_t)_bits + TypePtr::hash();
  2424 //------------------------------dump2------------------------------------------
  2425 #ifndef PRODUCT
  2426 void TypeRawPtr::dump2( Dict &d, uint depth, outputStream *st ) const {
  2427   if( _ptr == Constant )
  2428     st->print(INTPTR_FORMAT, _bits);
  2429   else
  2430     st->print("rawptr:%s", ptr_msg[_ptr]);
  2432 #endif
  2434 //=============================================================================
  2435 // Convenience common pre-built type.
  2436 const TypeOopPtr *TypeOopPtr::BOTTOM;
  2438 //------------------------------TypeOopPtr-------------------------------------
  2439 TypeOopPtr::TypeOopPtr(TYPES t, PTR ptr, ciKlass* k, bool xk, ciObject* o, int offset, int instance_id, const TypeOopPtr* speculative)
  2440   : TypePtr(t, ptr, offset),
  2441     _const_oop(o), _klass(k),
  2442     _klass_is_exact(xk),
  2443     _is_ptr_to_narrowoop(false),
  2444     _is_ptr_to_narrowklass(false),
  2445     _is_ptr_to_boxed_value(false),
  2446     _instance_id(instance_id),
  2447     _speculative(speculative) {
  2448   if (Compile::current()->eliminate_boxing() && (t == InstPtr) &&
  2449       (offset > 0) && xk && (k != 0) && k->is_instance_klass()) {
  2450     _is_ptr_to_boxed_value = k->as_instance_klass()->is_boxed_value_offset(offset);
  2452 #ifdef _LP64
  2453   if (_offset != 0) {
  2454     if (_offset == oopDesc::klass_offset_in_bytes()) {
  2455       _is_ptr_to_narrowklass = UseCompressedClassPointers;
  2456     } else if (klass() == NULL) {
  2457       // Array with unknown body type
  2458       assert(this->isa_aryptr(), "only arrays without klass");
  2459       _is_ptr_to_narrowoop = UseCompressedOops;
  2460     } else if (this->isa_aryptr()) {
  2461       _is_ptr_to_narrowoop = (UseCompressedOops && klass()->is_obj_array_klass() &&
  2462                              _offset != arrayOopDesc::length_offset_in_bytes());
  2463     } else if (klass()->is_instance_klass()) {
  2464       ciInstanceKlass* ik = klass()->as_instance_klass();
  2465       ciField* field = NULL;
  2466       if (this->isa_klassptr()) {
  2467         // Perm objects don't use compressed references
  2468       } else if (_offset == OffsetBot || _offset == OffsetTop) {
  2469         // unsafe access
  2470         _is_ptr_to_narrowoop = UseCompressedOops;
  2471       } else { // exclude unsafe ops
  2472         assert(this->isa_instptr(), "must be an instance ptr.");
  2474         if (klass() == ciEnv::current()->Class_klass() &&
  2475             (_offset == java_lang_Class::klass_offset_in_bytes() ||
  2476              _offset == java_lang_Class::array_klass_offset_in_bytes())) {
  2477           // Special hidden fields from the Class.
  2478           assert(this->isa_instptr(), "must be an instance ptr.");
  2479           _is_ptr_to_narrowoop = false;
  2480         } else if (klass() == ciEnv::current()->Class_klass() &&
  2481                    _offset >= InstanceMirrorKlass::offset_of_static_fields()) {
  2482           // Static fields
  2483           assert(o != NULL, "must be constant");
  2484           ciInstanceKlass* k = o->as_instance()->java_lang_Class_klass()->as_instance_klass();
  2485           ciField* field = k->get_field_by_offset(_offset, true);
  2486           assert(field != NULL, "missing field");
  2487           BasicType basic_elem_type = field->layout_type();
  2488           _is_ptr_to_narrowoop = UseCompressedOops && (basic_elem_type == T_OBJECT ||
  2489                                                        basic_elem_type == T_ARRAY);
  2490         } else {
  2491           // Instance fields which contains a compressed oop references.
  2492           field = ik->get_field_by_offset(_offset, false);
  2493           if (field != NULL) {
  2494             BasicType basic_elem_type = field->layout_type();
  2495             _is_ptr_to_narrowoop = UseCompressedOops && (basic_elem_type == T_OBJECT ||
  2496                                                          basic_elem_type == T_ARRAY);
  2497           } else if (klass()->equals(ciEnv::current()->Object_klass())) {
  2498             // Compile::find_alias_type() cast exactness on all types to verify
  2499             // that it does not affect alias type.
  2500             _is_ptr_to_narrowoop = UseCompressedOops;
  2501           } else {
  2502             // Type for the copy start in LibraryCallKit::inline_native_clone().
  2503             _is_ptr_to_narrowoop = UseCompressedOops;
  2509 #endif
  2512 //------------------------------make-------------------------------------------
  2513 const TypeOopPtr *TypeOopPtr::make(PTR ptr,
  2514                                    int offset, int instance_id, const TypeOopPtr* speculative) {
  2515   assert(ptr != Constant, "no constant generic pointers");
  2516   ciKlass*  k = Compile::current()->env()->Object_klass();
  2517   bool      xk = false;
  2518   ciObject* o = NULL;
  2519   return (TypeOopPtr*)(new TypeOopPtr(OopPtr, ptr, k, xk, o, offset, instance_id, speculative))->hashcons();
  2523 //------------------------------cast_to_ptr_type-------------------------------
  2524 const Type *TypeOopPtr::cast_to_ptr_type(PTR ptr) const {
  2525   assert(_base == OopPtr, "subclass must override cast_to_ptr_type");
  2526   if( ptr == _ptr ) return this;
  2527   return make(ptr, _offset, _instance_id, _speculative);
  2530 //-----------------------------cast_to_instance_id----------------------------
  2531 const TypeOopPtr *TypeOopPtr::cast_to_instance_id(int instance_id) const {
  2532   // There are no instances of a general oop.
  2533   // Return self unchanged.
  2534   return this;
  2537 //-----------------------------cast_to_exactness-------------------------------
  2538 const Type *TypeOopPtr::cast_to_exactness(bool klass_is_exact) const {
  2539   // There is no such thing as an exact general oop.
  2540   // Return self unchanged.
  2541   return this;
  2545 //------------------------------as_klass_type----------------------------------
  2546 // Return the klass type corresponding to this instance or array type.
  2547 // It is the type that is loaded from an object of this type.
  2548 const TypeKlassPtr* TypeOopPtr::as_klass_type() const {
  2549   ciKlass* k = klass();
  2550   bool    xk = klass_is_exact();
  2551   if (k == NULL)
  2552     return TypeKlassPtr::OBJECT;
  2553   else
  2554     return TypeKlassPtr::make(xk? Constant: NotNull, k, 0);
  2557 const Type *TypeOopPtr::xmeet(const Type *t) const {
  2558   const Type* res = xmeet_helper(t);
  2559   if (res->isa_oopptr() == NULL) {
  2560     return res;
  2563   if (res->isa_oopptr() != NULL) {
  2564     // type->speculative() == NULL means that speculation is no better
  2565     // than type, i.e. type->speculative() == type. So there are 2
  2566     // ways to represent the fact that we have no useful speculative
  2567     // data and we should use a single one to be able to test for
  2568     // equality between types. Check whether type->speculative() ==
  2569     // type and set speculative to NULL if it is the case.
  2570     const TypeOopPtr* res_oopptr = res->is_oopptr();
  2571     if (res_oopptr->remove_speculative() == res_oopptr->speculative()) {
  2572       return res_oopptr->remove_speculative();
  2576   return res;
  2579 //------------------------------meet-------------------------------------------
  2580 // Compute the MEET of two types.  It returns a new Type object.
  2581 const Type *TypeOopPtr::xmeet_helper(const Type *t) const {
  2582   // Perform a fast test for common case; meeting the same types together.
  2583   if( this == t ) return this;  // Meeting same type-rep?
  2585   // Current "this->_base" is OopPtr
  2586   switch (t->base()) {          // switch on original type
  2588   case Int:                     // Mixing ints & oops happens when javac
  2589   case Long:                    // reuses local variables
  2590   case FloatTop:
  2591   case FloatCon:
  2592   case FloatBot:
  2593   case DoubleTop:
  2594   case DoubleCon:
  2595   case DoubleBot:
  2596   case NarrowOop:
  2597   case NarrowKlass:
  2598   case Bottom:                  // Ye Olde Default
  2599     return Type::BOTTOM;
  2600   case Top:
  2601     return this;
  2603   default:                      // All else is a mistake
  2604     typerr(t);
  2606   case RawPtr:
  2607   case MetadataPtr:
  2608   case KlassPtr:
  2609     return TypePtr::BOTTOM;     // Oop meet raw is not well defined
  2611   case AnyPtr: {
  2612     // Found an AnyPtr type vs self-OopPtr type
  2613     const TypePtr *tp = t->is_ptr();
  2614     int offset = meet_offset(tp->offset());
  2615     PTR ptr = meet_ptr(tp->ptr());
  2616     switch (tp->ptr()) {
  2617     case Null:
  2618       if (ptr == Null)  return TypePtr::make(AnyPtr, ptr, offset);
  2619       // else fall through:
  2620     case TopPTR:
  2621     case AnyNull: {
  2622       int instance_id = meet_instance_id(InstanceTop);
  2623       const TypeOopPtr* speculative = _speculative;
  2624       return make(ptr, offset, instance_id, speculative);
  2626     case BotPTR:
  2627     case NotNull:
  2628       return TypePtr::make(AnyPtr, ptr, offset);
  2629     default: typerr(t);
  2633   case OopPtr: {                 // Meeting to other OopPtrs
  2634     const TypeOopPtr *tp = t->is_oopptr();
  2635     int instance_id = meet_instance_id(tp->instance_id());
  2636     const TypeOopPtr* speculative = meet_speculative(tp);
  2637     return make(meet_ptr(tp->ptr()), meet_offset(tp->offset()), instance_id, speculative);
  2640   case InstPtr:                  // For these, flip the call around to cut down
  2641   case AryPtr:
  2642     return t->xmeet(this);      // Call in reverse direction
  2644   } // End of switch
  2645   return this;                  // Return the double constant
  2649 //------------------------------xdual------------------------------------------
  2650 // Dual of a pure heap pointer.  No relevant klass or oop information.
  2651 const Type *TypeOopPtr::xdual() const {
  2652   assert(klass() == Compile::current()->env()->Object_klass(), "no klasses here");
  2653   assert(const_oop() == NULL,             "no constants here");
  2654   return new TypeOopPtr(_base, dual_ptr(), klass(), klass_is_exact(), const_oop(), dual_offset(), dual_instance_id(), dual_speculative());
  2657 //--------------------------make_from_klass_common-----------------------------
  2658 // Computes the element-type given a klass.
  2659 const TypeOopPtr* TypeOopPtr::make_from_klass_common(ciKlass *klass, bool klass_change, bool try_for_exact) {
  2660   if (klass->is_instance_klass()) {
  2661     Compile* C = Compile::current();
  2662     Dependencies* deps = C->dependencies();
  2663     assert((deps != NULL) == (C->method() != NULL && C->method()->code_size() > 0), "sanity");
  2664     // Element is an instance
  2665     bool klass_is_exact = false;
  2666     if (klass->is_loaded()) {
  2667       // Try to set klass_is_exact.
  2668       ciInstanceKlass* ik = klass->as_instance_klass();
  2669       klass_is_exact = ik->is_final();
  2670       if (!klass_is_exact && klass_change
  2671           && deps != NULL && UseUniqueSubclasses) {
  2672         ciInstanceKlass* sub = ik->unique_concrete_subklass();
  2673         if (sub != NULL) {
  2674           deps->assert_abstract_with_unique_concrete_subtype(ik, sub);
  2675           klass = ik = sub;
  2676           klass_is_exact = sub->is_final();
  2679       if (!klass_is_exact && try_for_exact
  2680           && deps != NULL && UseExactTypes) {
  2681         if (!ik->is_interface() && !ik->has_subklass()) {
  2682           // Add a dependence; if concrete subclass added we need to recompile
  2683           deps->assert_leaf_type(ik);
  2684           klass_is_exact = true;
  2688     return TypeInstPtr::make(TypePtr::BotPTR, klass, klass_is_exact, NULL, 0);
  2689   } else if (klass->is_obj_array_klass()) {
  2690     // Element is an object array. Recursively call ourself.
  2691     const TypeOopPtr *etype = TypeOopPtr::make_from_klass_common(klass->as_obj_array_klass()->element_klass(), false, try_for_exact);
  2692     bool xk = etype->klass_is_exact();
  2693     const TypeAry* arr0 = TypeAry::make(etype, TypeInt::POS);
  2694     // We used to pass NotNull in here, asserting that the sub-arrays
  2695     // are all not-null.  This is not true in generally, as code can
  2696     // slam NULLs down in the subarrays.
  2697     const TypeAryPtr* arr = TypeAryPtr::make(TypePtr::BotPTR, arr0, klass, xk, 0);
  2698     return arr;
  2699   } else if (klass->is_type_array_klass()) {
  2700     // Element is an typeArray
  2701     const Type* etype = get_const_basic_type(klass->as_type_array_klass()->element_type());
  2702     const TypeAry* arr0 = TypeAry::make(etype, TypeInt::POS);
  2703     // We used to pass NotNull in here, asserting that the array pointer
  2704     // is not-null. That was not true in general.
  2705     const TypeAryPtr* arr = TypeAryPtr::make(TypePtr::BotPTR, arr0, klass, true, 0);
  2706     return arr;
  2707   } else {
  2708     ShouldNotReachHere();
  2709     return NULL;
  2713 //------------------------------make_from_constant-----------------------------
  2714 // Make a java pointer from an oop constant
  2715 const TypeOopPtr* TypeOopPtr::make_from_constant(ciObject* o,
  2716                                                  bool require_constant,
  2717                                                  bool is_autobox_cache) {
  2718   assert(!o->is_null_object(), "null object not yet handled here.");
  2719   ciKlass* klass = o->klass();
  2720   if (klass->is_instance_klass()) {
  2721     // Element is an instance
  2722     if (require_constant) {
  2723       if (!o->can_be_constant())  return NULL;
  2724     } else if (!o->should_be_constant()) {
  2725       return TypeInstPtr::make(TypePtr::NotNull, klass, true, NULL, 0);
  2727     return TypeInstPtr::make(o);
  2728   } else if (klass->is_obj_array_klass()) {
  2729     // Element is an object array. Recursively call ourself.
  2730     const TypeOopPtr *etype =
  2731       TypeOopPtr::make_from_klass_raw(klass->as_obj_array_klass()->element_klass());
  2732     if (is_autobox_cache) {
  2733       // The pointers in the autobox arrays are always non-null.
  2734       etype = etype->cast_to_ptr_type(TypePtr::NotNull)->is_oopptr();
  2736     const TypeAry* arr0 = TypeAry::make(etype, TypeInt::make(o->as_array()->length()));
  2737     // We used to pass NotNull in here, asserting that the sub-arrays
  2738     // are all not-null.  This is not true in generally, as code can
  2739     // slam NULLs down in the subarrays.
  2740     if (require_constant) {
  2741       if (!o->can_be_constant())  return NULL;
  2742     } else if (!o->should_be_constant()) {
  2743       return TypeAryPtr::make(TypePtr::NotNull, arr0, klass, true, 0);
  2745     const TypeAryPtr* arr = TypeAryPtr::make(TypePtr::Constant, o, arr0, klass, true, 0, InstanceBot, NULL, is_autobox_cache);
  2746     return arr;
  2747   } else if (klass->is_type_array_klass()) {
  2748     // Element is an typeArray
  2749     const Type* etype =
  2750       (Type*)get_const_basic_type(klass->as_type_array_klass()->element_type());
  2751     const TypeAry* arr0 = TypeAry::make(etype, TypeInt::make(o->as_array()->length()));
  2752     // We used to pass NotNull in here, asserting that the array pointer
  2753     // is not-null. That was not true in general.
  2754     if (require_constant) {
  2755       if (!o->can_be_constant())  return NULL;
  2756     } else if (!o->should_be_constant()) {
  2757       return TypeAryPtr::make(TypePtr::NotNull, arr0, klass, true, 0);
  2759     const TypeAryPtr* arr = TypeAryPtr::make(TypePtr::Constant, o, arr0, klass, true, 0);
  2760     return arr;
  2763   fatal("unhandled object type");
  2764   return NULL;
  2767 //------------------------------get_con----------------------------------------
  2768 intptr_t TypeOopPtr::get_con() const {
  2769   assert( _ptr == Null || _ptr == Constant, "" );
  2770   assert( _offset >= 0, "" );
  2772   if (_offset != 0) {
  2773     // After being ported to the compiler interface, the compiler no longer
  2774     // directly manipulates the addresses of oops.  Rather, it only has a pointer
  2775     // to a handle at compile time.  This handle is embedded in the generated
  2776     // code and dereferenced at the time the nmethod is made.  Until that time,
  2777     // it is not reasonable to do arithmetic with the addresses of oops (we don't
  2778     // have access to the addresses!).  This does not seem to currently happen,
  2779     // but this assertion here is to help prevent its occurence.
  2780     tty->print_cr("Found oop constant with non-zero offset");
  2781     ShouldNotReachHere();
  2784   return (intptr_t)const_oop()->constant_encoding();
  2788 //-----------------------------filter------------------------------------------
  2789 // Do not allow interface-vs.-noninterface joins to collapse to top.
  2790 const Type *TypeOopPtr::filter(const Type *kills) const {
  2792   const Type* ft = join(kills);
  2793   const TypeInstPtr* ftip = ft->isa_instptr();
  2794   const TypeInstPtr* ktip = kills->isa_instptr();
  2796   if (ft->empty()) {
  2797     // Check for evil case of 'this' being a class and 'kills' expecting an
  2798     // interface.  This can happen because the bytecodes do not contain
  2799     // enough type info to distinguish a Java-level interface variable
  2800     // from a Java-level object variable.  If we meet 2 classes which
  2801     // both implement interface I, but their meet is at 'j/l/O' which
  2802     // doesn't implement I, we have no way to tell if the result should
  2803     // be 'I' or 'j/l/O'.  Thus we'll pick 'j/l/O'.  If this then flows
  2804     // into a Phi which "knows" it's an Interface type we'll have to
  2805     // uplift the type.
  2806     if (!empty() && ktip != NULL && ktip->is_loaded() && ktip->klass()->is_interface())
  2807       return kills;             // Uplift to interface
  2809     return Type::TOP;           // Canonical empty value
  2812   // If we have an interface-typed Phi or cast and we narrow to a class type,
  2813   // the join should report back the class.  However, if we have a J/L/Object
  2814   // class-typed Phi and an interface flows in, it's possible that the meet &
  2815   // join report an interface back out.  This isn't possible but happens
  2816   // because the type system doesn't interact well with interfaces.
  2817   if (ftip != NULL && ktip != NULL &&
  2818       ftip->is_loaded() &&  ftip->klass()->is_interface() &&
  2819       ktip->is_loaded() && !ktip->klass()->is_interface()) {
  2820     // Happens in a CTW of rt.jar, 320-341, no extra flags
  2821     assert(!ftip->klass_is_exact(), "interface could not be exact");
  2822     return ktip->cast_to_ptr_type(ftip->ptr());
  2825   return ft;
  2828 //------------------------------eq---------------------------------------------
  2829 // Structural equality check for Type representations
  2830 bool TypeOopPtr::eq( const Type *t ) const {
  2831   const TypeOopPtr *a = (const TypeOopPtr*)t;
  2832   if (_klass_is_exact != a->_klass_is_exact ||
  2833       _instance_id != a->_instance_id ||
  2834       !eq_speculative(a))  return false;
  2835   ciObject* one = const_oop();
  2836   ciObject* two = a->const_oop();
  2837   if (one == NULL || two == NULL) {
  2838     return (one == two) && TypePtr::eq(t);
  2839   } else {
  2840     return one->equals(two) && TypePtr::eq(t);
  2844 //------------------------------hash-------------------------------------------
  2845 // Type-specific hashing function.
  2846 int TypeOopPtr::hash(void) const {
  2847   return
  2848     (const_oop() ? const_oop()->hash() : 0) +
  2849     _klass_is_exact +
  2850     _instance_id +
  2851     hash_speculative() +
  2852     TypePtr::hash();
  2855 //------------------------------dump2------------------------------------------
  2856 #ifndef PRODUCT
  2857 void TypeOopPtr::dump2( Dict &d, uint depth, outputStream *st ) const {
  2858   st->print("oopptr:%s", ptr_msg[_ptr]);
  2859   if( _klass_is_exact ) st->print(":exact");
  2860   if( const_oop() ) st->print(INTPTR_FORMAT, const_oop());
  2861   switch( _offset ) {
  2862   case OffsetTop: st->print("+top"); break;
  2863   case OffsetBot: st->print("+any"); break;
  2864   case         0: break;
  2865   default:        st->print("+%d",_offset); break;
  2867   if (_instance_id == InstanceTop)
  2868     st->print(",iid=top");
  2869   else if (_instance_id != InstanceBot)
  2870     st->print(",iid=%d",_instance_id);
  2872   dump_speculative(st);
  2875 /**
  2876  *dump the speculative part of the type
  2877  */
  2878 void TypeOopPtr::dump_speculative(outputStream *st) const {
  2879   if (_speculative != NULL) {
  2880     st->print(" (speculative=");
  2881     _speculative->dump_on(st);
  2882     st->print(")");
  2885 #endif
  2887 //------------------------------singleton--------------------------------------
  2888 // TRUE if Type is a singleton type, FALSE otherwise.   Singletons are simple
  2889 // constants
  2890 bool TypeOopPtr::singleton(void) const {
  2891   // detune optimizer to not generate constant oop + constant offset as a constant!
  2892   // TopPTR, Null, AnyNull, Constant are all singletons
  2893   return (_offset == 0) && !below_centerline(_ptr);
  2896 //------------------------------add_offset-------------------------------------
  2897 const TypePtr *TypeOopPtr::add_offset(intptr_t offset) const {
  2898   return make(_ptr, xadd_offset(offset), _instance_id, add_offset_speculative(offset));
  2901 /**
  2902  * Return same type without a speculative part
  2903  */
  2904 const TypeOopPtr* TypeOopPtr::remove_speculative() const {
  2905   return make(_ptr, _offset, _instance_id, NULL);
  2908 //------------------------------meet_instance_id--------------------------------
  2909 int TypeOopPtr::meet_instance_id( int instance_id ) const {
  2910   // Either is 'TOP' instance?  Return the other instance!
  2911   if( _instance_id == InstanceTop ) return  instance_id;
  2912   if(  instance_id == InstanceTop ) return _instance_id;
  2913   // If either is different, return 'BOTTOM' instance
  2914   if( _instance_id != instance_id ) return InstanceBot;
  2915   return _instance_id;
  2918 //------------------------------dual_instance_id--------------------------------
  2919 int TypeOopPtr::dual_instance_id( ) const {
  2920   if( _instance_id == InstanceTop ) return InstanceBot; // Map TOP into BOTTOM
  2921   if( _instance_id == InstanceBot ) return InstanceTop; // Map BOTTOM into TOP
  2922   return _instance_id;              // Map everything else into self
  2925 /**
  2926  * meet of the speculative parts of 2 types
  2928  * @param other  type to meet with
  2929  */
  2930 const TypeOopPtr* TypeOopPtr::meet_speculative(const TypeOopPtr* other) const {
  2931   bool this_has_spec = (_speculative != NULL);
  2932   bool other_has_spec = (other->speculative() != NULL);
  2934   if (!this_has_spec && !other_has_spec) {
  2935     return NULL;
  2938   // If we are at a point where control flow meets and one branch has
  2939   // a speculative type and the other has not, we meet the speculative
  2940   // type of one branch with the actual type of the other. If the
  2941   // actual type is exact and the speculative is as well, then the
  2942   // result is a speculative type which is exact and we can continue
  2943   // speculation further.
  2944   const TypeOopPtr* this_spec = _speculative;
  2945   const TypeOopPtr* other_spec = other->speculative();
  2947   if (!this_has_spec) {
  2948     this_spec = this;
  2951   if (!other_has_spec) {
  2952     other_spec = other;
  2955   return this_spec->meet(other_spec)->is_oopptr();
  2958 /**
  2959  * dual of the speculative part of the type
  2960  */
  2961 const TypeOopPtr* TypeOopPtr::dual_speculative() const {
  2962   if (_speculative == NULL) {
  2963     return NULL;
  2965   return _speculative->dual()->is_oopptr();
  2968 /**
  2969  * add offset to the speculative part of the type
  2971  * @param offset  offset to add
  2972  */
  2973 const TypeOopPtr* TypeOopPtr::add_offset_speculative(intptr_t offset) const {
  2974   if (_speculative == NULL) {
  2975     return NULL;
  2977   return _speculative->add_offset(offset)->is_oopptr();
  2980 /**
  2981  * Are the speculative parts of 2 types equal?
  2983  * @param other  type to compare this one to
  2984  */
  2985 bool TypeOopPtr::eq_speculative(const TypeOopPtr* other) const {
  2986   if (_speculative == NULL || other->speculative() == NULL) {
  2987     return _speculative == other->speculative();
  2990   if (_speculative->base() != other->speculative()->base()) {
  2991     return false;
  2994   return _speculative->eq(other->speculative());
  2997 /**
  2998  * Hash of the speculative part of the type
  2999  */
  3000 int TypeOopPtr::hash_speculative() const {
  3001   if (_speculative == NULL) {
  3002     return 0;
  3005   return _speculative->hash();
  3009 //=============================================================================
  3010 // Convenience common pre-built types.
  3011 const TypeInstPtr *TypeInstPtr::NOTNULL;
  3012 const TypeInstPtr *TypeInstPtr::BOTTOM;
  3013 const TypeInstPtr *TypeInstPtr::MIRROR;
  3014 const TypeInstPtr *TypeInstPtr::MARK;
  3015 const TypeInstPtr *TypeInstPtr::KLASS;
  3017 //------------------------------TypeInstPtr-------------------------------------
  3018 TypeInstPtr::TypeInstPtr(PTR ptr, ciKlass* k, bool xk, ciObject* o, int off, int instance_id, const TypeOopPtr* speculative)
  3019   : TypeOopPtr(InstPtr, ptr, k, xk, o, off, instance_id, speculative), _name(k->name()) {
  3020    assert(k != NULL &&
  3021           (k->is_loaded() || o == NULL),
  3022           "cannot have constants with non-loaded klass");
  3023 };
  3025 //------------------------------make-------------------------------------------
  3026 const TypeInstPtr *TypeInstPtr::make(PTR ptr,
  3027                                      ciKlass* k,
  3028                                      bool xk,
  3029                                      ciObject* o,
  3030                                      int offset,
  3031                                      int instance_id,
  3032                                      const TypeOopPtr* speculative) {
  3033   assert( !k->is_loaded() || k->is_instance_klass(), "Must be for instance");
  3034   // Either const_oop() is NULL or else ptr is Constant
  3035   assert( (!o && ptr != Constant) || (o && ptr == Constant),
  3036           "constant pointers must have a value supplied" );
  3037   // Ptr is never Null
  3038   assert( ptr != Null, "NULL pointers are not typed" );
  3040   assert(instance_id <= 0 || xk || !UseExactTypes, "instances are always exactly typed");
  3041   if (!UseExactTypes)  xk = false;
  3042   if (ptr == Constant) {
  3043     // Note:  This case includes meta-object constants, such as methods.
  3044     xk = true;
  3045   } else if (k->is_loaded()) {
  3046     ciInstanceKlass* ik = k->as_instance_klass();
  3047     if (!xk && ik->is_final())     xk = true;   // no inexact final klass
  3048     if (xk && ik->is_interface())  xk = false;  // no exact interface
  3051   // Now hash this baby
  3052   TypeInstPtr *result =
  3053     (TypeInstPtr*)(new TypeInstPtr(ptr, k, xk, o ,offset, instance_id, speculative))->hashcons();
  3055   return result;
  3058 /**
  3059  *  Create constant type for a constant boxed value
  3060  */
  3061 const Type* TypeInstPtr::get_const_boxed_value() const {
  3062   assert(is_ptr_to_boxed_value(), "should be called only for boxed value");
  3063   assert((const_oop() != NULL), "should be called only for constant object");
  3064   ciConstant constant = const_oop()->as_instance()->field_value_by_offset(offset());
  3065   BasicType bt = constant.basic_type();
  3066   switch (bt) {
  3067     case T_BOOLEAN:  return TypeInt::make(constant.as_boolean());
  3068     case T_INT:      return TypeInt::make(constant.as_int());
  3069     case T_CHAR:     return TypeInt::make(constant.as_char());
  3070     case T_BYTE:     return TypeInt::make(constant.as_byte());
  3071     case T_SHORT:    return TypeInt::make(constant.as_short());
  3072     case T_FLOAT:    return TypeF::make(constant.as_float());
  3073     case T_DOUBLE:   return TypeD::make(constant.as_double());
  3074     case T_LONG:     return TypeLong::make(constant.as_long());
  3075     default:         break;
  3077   fatal(err_msg_res("Invalid boxed value type '%s'", type2name(bt)));
  3078   return NULL;
  3081 //------------------------------cast_to_ptr_type-------------------------------
  3082 const Type *TypeInstPtr::cast_to_ptr_type(PTR ptr) const {
  3083   if( ptr == _ptr ) return this;
  3084   // Reconstruct _sig info here since not a problem with later lazy
  3085   // construction, _sig will show up on demand.
  3086   return make(ptr, klass(), klass_is_exact(), const_oop(), _offset, _instance_id, _speculative);
  3090 //-----------------------------cast_to_exactness-------------------------------
  3091 const Type *TypeInstPtr::cast_to_exactness(bool klass_is_exact) const {
  3092   if( klass_is_exact == _klass_is_exact ) return this;
  3093   if (!UseExactTypes)  return this;
  3094   if (!_klass->is_loaded())  return this;
  3095   ciInstanceKlass* ik = _klass->as_instance_klass();
  3096   if( (ik->is_final() || _const_oop) )  return this;  // cannot clear xk
  3097   if( ik->is_interface() )              return this;  // cannot set xk
  3098   return make(ptr(), klass(), klass_is_exact, const_oop(), _offset, _instance_id, _speculative);
  3101 //-----------------------------cast_to_instance_id----------------------------
  3102 const TypeOopPtr *TypeInstPtr::cast_to_instance_id(int instance_id) const {
  3103   if( instance_id == _instance_id ) return this;
  3104   return make(_ptr, klass(), _klass_is_exact, const_oop(), _offset, instance_id, _speculative);
  3107 //------------------------------xmeet_unloaded---------------------------------
  3108 // Compute the MEET of two InstPtrs when at least one is unloaded.
  3109 // Assume classes are different since called after check for same name/class-loader
  3110 const TypeInstPtr *TypeInstPtr::xmeet_unloaded(const TypeInstPtr *tinst) const {
  3111     int off = meet_offset(tinst->offset());
  3112     PTR ptr = meet_ptr(tinst->ptr());
  3113     int instance_id = meet_instance_id(tinst->instance_id());
  3114     const TypeOopPtr* speculative = meet_speculative(tinst);
  3116     const TypeInstPtr *loaded    = is_loaded() ? this  : tinst;
  3117     const TypeInstPtr *unloaded  = is_loaded() ? tinst : this;
  3118     if( loaded->klass()->equals(ciEnv::current()->Object_klass()) ) {
  3119       //
  3120       // Meet unloaded class with java/lang/Object
  3121       //
  3122       // Meet
  3123       //          |                     Unloaded Class
  3124       //  Object  |   TOP    |   AnyNull | Constant |   NotNull |  BOTTOM   |
  3125       //  ===================================================================
  3126       //   TOP    | ..........................Unloaded......................|
  3127       //  AnyNull |  U-AN    |................Unloaded......................|
  3128       // Constant | ... O-NN .................................. |   O-BOT   |
  3129       //  NotNull | ... O-NN .................................. |   O-BOT   |
  3130       //  BOTTOM  | ........................Object-BOTTOM ..................|
  3131       //
  3132       assert(loaded->ptr() != TypePtr::Null, "insanity check");
  3133       //
  3134       if(      loaded->ptr() == TypePtr::TopPTR ) { return unloaded; }
  3135       else if (loaded->ptr() == TypePtr::AnyNull) { return TypeInstPtr::make(ptr, unloaded->klass(), false, NULL, off, instance_id, speculative); }
  3136       else if (loaded->ptr() == TypePtr::BotPTR ) { return TypeInstPtr::BOTTOM; }
  3137       else if (loaded->ptr() == TypePtr::Constant || loaded->ptr() == TypePtr::NotNull) {
  3138         if (unloaded->ptr() == TypePtr::BotPTR  ) { return TypeInstPtr::BOTTOM;  }
  3139         else                                      { return TypeInstPtr::NOTNULL; }
  3141       else if( unloaded->ptr() == TypePtr::TopPTR )  { return unloaded; }
  3143       return unloaded->cast_to_ptr_type(TypePtr::AnyNull)->is_instptr();
  3146     // Both are unloaded, not the same class, not Object
  3147     // Or meet unloaded with a different loaded class, not java/lang/Object
  3148     if( ptr != TypePtr::BotPTR ) {
  3149       return TypeInstPtr::NOTNULL;
  3151     return TypeInstPtr::BOTTOM;
  3155 //------------------------------meet-------------------------------------------
  3156 // Compute the MEET of two types.  It returns a new Type object.
  3157 const Type *TypeInstPtr::xmeet_helper(const Type *t) const {
  3158   // Perform a fast test for common case; meeting the same types together.
  3159   if( this == t ) return this;  // Meeting same type-rep?
  3161   // Current "this->_base" is Pointer
  3162   switch (t->base()) {          // switch on original type
  3164   case Int:                     // Mixing ints & oops happens when javac
  3165   case Long:                    // reuses local variables
  3166   case FloatTop:
  3167   case FloatCon:
  3168   case FloatBot:
  3169   case DoubleTop:
  3170   case DoubleCon:
  3171   case DoubleBot:
  3172   case NarrowOop:
  3173   case NarrowKlass:
  3174   case Bottom:                  // Ye Olde Default
  3175     return Type::BOTTOM;
  3176   case Top:
  3177     return this;
  3179   default:                      // All else is a mistake
  3180     typerr(t);
  3182   case MetadataPtr:
  3183   case KlassPtr:
  3184   case RawPtr: return TypePtr::BOTTOM;
  3186   case AryPtr: {                // All arrays inherit from Object class
  3187     const TypeAryPtr *tp = t->is_aryptr();
  3188     int offset = meet_offset(tp->offset());
  3189     PTR ptr = meet_ptr(tp->ptr());
  3190     int instance_id = meet_instance_id(tp->instance_id());
  3191     const TypeOopPtr* speculative = meet_speculative(tp);
  3192     switch (ptr) {
  3193     case TopPTR:
  3194     case AnyNull:                // Fall 'down' to dual of object klass
  3195       // For instances when a subclass meets a superclass we fall
  3196       // below the centerline when the superclass is exact. We need to
  3197       // do the same here.
  3198       if (klass()->equals(ciEnv::current()->Object_klass()) && !klass_is_exact()) {
  3199         return TypeAryPtr::make(ptr, tp->ary(), tp->klass(), tp->klass_is_exact(), offset, instance_id, speculative);
  3200       } else {
  3201         // cannot subclass, so the meet has to fall badly below the centerline
  3202         ptr = NotNull;
  3203         instance_id = InstanceBot;
  3204         return TypeInstPtr::make( ptr, ciEnv::current()->Object_klass(), false, NULL, offset, instance_id, speculative);
  3206     case Constant:
  3207     case NotNull:
  3208     case BotPTR:                // Fall down to object klass
  3209       // LCA is object_klass, but if we subclass from the top we can do better
  3210       if( above_centerline(_ptr) ) { // if( _ptr == TopPTR || _ptr == AnyNull )
  3211         // If 'this' (InstPtr) is above the centerline and it is Object class
  3212         // then we can subclass in the Java class hierarchy.
  3213         // For instances when a subclass meets a superclass we fall
  3214         // below the centerline when the superclass is exact. We need
  3215         // to do the same here.
  3216         if (klass()->equals(ciEnv::current()->Object_klass()) && !klass_is_exact()) {
  3217           // that is, tp's array type is a subtype of my klass
  3218           return TypeAryPtr::make(ptr, (ptr == Constant ? tp->const_oop() : NULL),
  3219                                   tp->ary(), tp->klass(), tp->klass_is_exact(), offset, instance_id, speculative);
  3222       // The other case cannot happen, since I cannot be a subtype of an array.
  3223       // The meet falls down to Object class below centerline.
  3224       if( ptr == Constant )
  3225          ptr = NotNull;
  3226       instance_id = InstanceBot;
  3227       return make(ptr, ciEnv::current()->Object_klass(), false, NULL, offset, instance_id, speculative);
  3228     default: typerr(t);
  3232   case OopPtr: {                // Meeting to OopPtrs
  3233     // Found a OopPtr type vs self-InstPtr type
  3234     const TypeOopPtr *tp = t->is_oopptr();
  3235     int offset = meet_offset(tp->offset());
  3236     PTR ptr = meet_ptr(tp->ptr());
  3237     switch (tp->ptr()) {
  3238     case TopPTR:
  3239     case AnyNull: {
  3240       int instance_id = meet_instance_id(InstanceTop);
  3241       const TypeOopPtr* speculative = meet_speculative(tp);
  3242       return make(ptr, klass(), klass_is_exact(),
  3243                   (ptr == Constant ? const_oop() : NULL), offset, instance_id, speculative);
  3245     case NotNull:
  3246     case BotPTR: {
  3247       int instance_id = meet_instance_id(tp->instance_id());
  3248       const TypeOopPtr* speculative = meet_speculative(tp);
  3249       return TypeOopPtr::make(ptr, offset, instance_id, speculative);
  3251     default: typerr(t);
  3255   case AnyPtr: {                // Meeting to AnyPtrs
  3256     // Found an AnyPtr type vs self-InstPtr type
  3257     const TypePtr *tp = t->is_ptr();
  3258     int offset = meet_offset(tp->offset());
  3259     PTR ptr = meet_ptr(tp->ptr());
  3260     switch (tp->ptr()) {
  3261     case Null:
  3262       if( ptr == Null ) return TypePtr::make(AnyPtr, ptr, offset);
  3263       // else fall through to AnyNull
  3264     case TopPTR:
  3265     case AnyNull: {
  3266       int instance_id = meet_instance_id(InstanceTop);
  3267       const TypeOopPtr* speculative = _speculative;
  3268       return make(ptr, klass(), klass_is_exact(),
  3269                   (ptr == Constant ? const_oop() : NULL), offset, instance_id, speculative);
  3271     case NotNull:
  3272     case BotPTR:
  3273       return TypePtr::make(AnyPtr, ptr, offset);
  3274     default: typerr(t);
  3278   /*
  3279                  A-top         }
  3280                /   |   \       }  Tops
  3281            B-top A-any C-top   }
  3282               | /  |  \ |      }  Any-nulls
  3283            B-any   |   C-any   }
  3284               |    |    |
  3285            B-con A-con C-con   } constants; not comparable across classes
  3286               |    |    |
  3287            B-not   |   C-not   }
  3288               | \  |  / |      }  not-nulls
  3289            B-bot A-not C-bot   }
  3290                \   |   /       }  Bottoms
  3291                  A-bot         }
  3292   */
  3294   case InstPtr: {                // Meeting 2 Oops?
  3295     // Found an InstPtr sub-type vs self-InstPtr type
  3296     const TypeInstPtr *tinst = t->is_instptr();
  3297     int off = meet_offset( tinst->offset() );
  3298     PTR ptr = meet_ptr( tinst->ptr() );
  3299     int instance_id = meet_instance_id(tinst->instance_id());
  3300     const TypeOopPtr* speculative = meet_speculative(tinst);
  3302     // Check for easy case; klasses are equal (and perhaps not loaded!)
  3303     // If we have constants, then we created oops so classes are loaded
  3304     // and we can handle the constants further down.  This case handles
  3305     // both-not-loaded or both-loaded classes
  3306     if (ptr != Constant && klass()->equals(tinst->klass()) && klass_is_exact() == tinst->klass_is_exact()) {
  3307       return make(ptr, klass(), klass_is_exact(), NULL, off, instance_id, speculative);
  3310     // Classes require inspection in the Java klass hierarchy.  Must be loaded.
  3311     ciKlass* tinst_klass = tinst->klass();
  3312     ciKlass* this_klass  = this->klass();
  3313     bool tinst_xk = tinst->klass_is_exact();
  3314     bool this_xk  = this->klass_is_exact();
  3315     if (!tinst_klass->is_loaded() || !this_klass->is_loaded() ) {
  3316       // One of these classes has not been loaded
  3317       const TypeInstPtr *unloaded_meet = xmeet_unloaded(tinst);
  3318 #ifndef PRODUCT
  3319       if( PrintOpto && Verbose ) {
  3320         tty->print("meet of unloaded classes resulted in: "); unloaded_meet->dump(); tty->cr();
  3321         tty->print("  this == "); this->dump(); tty->cr();
  3322         tty->print(" tinst == "); tinst->dump(); tty->cr();
  3324 #endif
  3325       return unloaded_meet;
  3328     // Handle mixing oops and interfaces first.
  3329     if( this_klass->is_interface() && !(tinst_klass->is_interface() ||
  3330                                         tinst_klass == ciEnv::current()->Object_klass())) {
  3331       ciKlass *tmp = tinst_klass; // Swap interface around
  3332       tinst_klass = this_klass;
  3333       this_klass = tmp;
  3334       bool tmp2 = tinst_xk;
  3335       tinst_xk = this_xk;
  3336       this_xk = tmp2;
  3338     if (tinst_klass->is_interface() &&
  3339         !(this_klass->is_interface() ||
  3340           // Treat java/lang/Object as an honorary interface,
  3341           // because we need a bottom for the interface hierarchy.
  3342           this_klass == ciEnv::current()->Object_klass())) {
  3343       // Oop meets interface!
  3345       // See if the oop subtypes (implements) interface.
  3346       ciKlass *k;
  3347       bool xk;
  3348       if( this_klass->is_subtype_of( tinst_klass ) ) {
  3349         // Oop indeed subtypes.  Now keep oop or interface depending
  3350         // on whether we are both above the centerline or either is
  3351         // below the centerline.  If we are on the centerline
  3352         // (e.g., Constant vs. AnyNull interface), use the constant.
  3353         k  = below_centerline(ptr) ? tinst_klass : this_klass;
  3354         // If we are keeping this_klass, keep its exactness too.
  3355         xk = below_centerline(ptr) ? tinst_xk    : this_xk;
  3356       } else {                  // Does not implement, fall to Object
  3357         // Oop does not implement interface, so mixing falls to Object
  3358         // just like the verifier does (if both are above the
  3359         // centerline fall to interface)
  3360         k = above_centerline(ptr) ? tinst_klass : ciEnv::current()->Object_klass();
  3361         xk = above_centerline(ptr) ? tinst_xk : false;
  3362         // Watch out for Constant vs. AnyNull interface.
  3363         if (ptr == Constant)  ptr = NotNull;   // forget it was a constant
  3364         instance_id = InstanceBot;
  3366       ciObject* o = NULL;  // the Constant value, if any
  3367       if (ptr == Constant) {
  3368         // Find out which constant.
  3369         o = (this_klass == klass()) ? const_oop() : tinst->const_oop();
  3371       return make(ptr, k, xk, o, off, instance_id, speculative);
  3374     // Either oop vs oop or interface vs interface or interface vs Object
  3376     // !!! Here's how the symmetry requirement breaks down into invariants:
  3377     // If we split one up & one down AND they subtype, take the down man.
  3378     // If we split one up & one down AND they do NOT subtype, "fall hard".
  3379     // If both are up and they subtype, take the subtype class.
  3380     // If both are up and they do NOT subtype, "fall hard".
  3381     // If both are down and they subtype, take the supertype class.
  3382     // If both are down and they do NOT subtype, "fall hard".
  3383     // Constants treated as down.
  3385     // Now, reorder the above list; observe that both-down+subtype is also
  3386     // "fall hard"; "fall hard" becomes the default case:
  3387     // If we split one up & one down AND they subtype, take the down man.
  3388     // If both are up and they subtype, take the subtype class.
  3390     // If both are down and they subtype, "fall hard".
  3391     // If both are down and they do NOT subtype, "fall hard".
  3392     // If both are up and they do NOT subtype, "fall hard".
  3393     // If we split one up & one down AND they do NOT subtype, "fall hard".
  3395     // If a proper subtype is exact, and we return it, we return it exactly.
  3396     // If a proper supertype is exact, there can be no subtyping relationship!
  3397     // If both types are equal to the subtype, exactness is and-ed below the
  3398     // centerline and or-ed above it.  (N.B. Constants are always exact.)
  3400     // Check for subtyping:
  3401     ciKlass *subtype = NULL;
  3402     bool subtype_exact = false;
  3403     if( tinst_klass->equals(this_klass) ) {
  3404       subtype = this_klass;
  3405       subtype_exact = below_centerline(ptr) ? (this_xk & tinst_xk) : (this_xk | tinst_xk);
  3406     } else if( !tinst_xk && this_klass->is_subtype_of( tinst_klass ) ) {
  3407       subtype = this_klass;     // Pick subtyping class
  3408       subtype_exact = this_xk;
  3409     } else if( !this_xk && tinst_klass->is_subtype_of( this_klass ) ) {
  3410       subtype = tinst_klass;    // Pick subtyping class
  3411       subtype_exact = tinst_xk;
  3414     if( subtype ) {
  3415       if( above_centerline(ptr) ) { // both are up?
  3416         this_klass = tinst_klass = subtype;
  3417         this_xk = tinst_xk = subtype_exact;
  3418       } else if( above_centerline(this ->_ptr) && !above_centerline(tinst->_ptr) ) {
  3419         this_klass = tinst_klass; // tinst is down; keep down man
  3420         this_xk = tinst_xk;
  3421       } else if( above_centerline(tinst->_ptr) && !above_centerline(this ->_ptr) ) {
  3422         tinst_klass = this_klass; // this is down; keep down man
  3423         tinst_xk = this_xk;
  3424       } else {
  3425         this_xk = subtype_exact;  // either they are equal, or we'll do an LCA
  3429     // Check for classes now being equal
  3430     if (tinst_klass->equals(this_klass)) {
  3431       // If the klasses are equal, the constants may still differ.  Fall to
  3432       // NotNull if they do (neither constant is NULL; that is a special case
  3433       // handled elsewhere).
  3434       ciObject* o = NULL;             // Assume not constant when done
  3435       ciObject* this_oop  = const_oop();
  3436       ciObject* tinst_oop = tinst->const_oop();
  3437       if( ptr == Constant ) {
  3438         if (this_oop != NULL && tinst_oop != NULL &&
  3439             this_oop->equals(tinst_oop) )
  3440           o = this_oop;
  3441         else if (above_centerline(this ->_ptr))
  3442           o = tinst_oop;
  3443         else if (above_centerline(tinst ->_ptr))
  3444           o = this_oop;
  3445         else
  3446           ptr = NotNull;
  3448       return make(ptr, this_klass, this_xk, o, off, instance_id, speculative);
  3449     } // Else classes are not equal
  3451     // Since klasses are different, we require a LCA in the Java
  3452     // class hierarchy - which means we have to fall to at least NotNull.
  3453     if( ptr == TopPTR || ptr == AnyNull || ptr == Constant )
  3454       ptr = NotNull;
  3455     instance_id = InstanceBot;
  3457     // Now we find the LCA of Java classes
  3458     ciKlass* k = this_klass->least_common_ancestor(tinst_klass);
  3459     return make(ptr, k, false, NULL, off, instance_id, speculative);
  3460   } // End of case InstPtr
  3462   } // End of switch
  3463   return this;                  // Return the double constant
  3467 //------------------------java_mirror_type--------------------------------------
  3468 ciType* TypeInstPtr::java_mirror_type() const {
  3469   // must be a singleton type
  3470   if( const_oop() == NULL )  return NULL;
  3472   // must be of type java.lang.Class
  3473   if( klass() != ciEnv::current()->Class_klass() )  return NULL;
  3475   return const_oop()->as_instance()->java_mirror_type();
  3479 //------------------------------xdual------------------------------------------
  3480 // Dual: do NOT dual on klasses.  This means I do NOT understand the Java
  3481 // inheritance mechanism.
  3482 const Type *TypeInstPtr::xdual() const {
  3483   return new TypeInstPtr(dual_ptr(), klass(), klass_is_exact(), const_oop(), dual_offset(), dual_instance_id(), dual_speculative());
  3486 //------------------------------eq---------------------------------------------
  3487 // Structural equality check for Type representations
  3488 bool TypeInstPtr::eq( const Type *t ) const {
  3489   const TypeInstPtr *p = t->is_instptr();
  3490   return
  3491     klass()->equals(p->klass()) &&
  3492     TypeOopPtr::eq(p);          // Check sub-type stuff
  3495 //------------------------------hash-------------------------------------------
  3496 // Type-specific hashing function.
  3497 int TypeInstPtr::hash(void) const {
  3498   int hash = klass()->hash() + TypeOopPtr::hash();
  3499   return hash;
  3502 //------------------------------dump2------------------------------------------
  3503 // Dump oop Type
  3504 #ifndef PRODUCT
  3505 void TypeInstPtr::dump2( Dict &d, uint depth, outputStream *st ) const {
  3506   // Print the name of the klass.
  3507   klass()->print_name_on(st);
  3509   switch( _ptr ) {
  3510   case Constant:
  3511     // TO DO: Make CI print the hex address of the underlying oop.
  3512     if (WizardMode || Verbose) {
  3513       const_oop()->print_oop(st);
  3515   case BotPTR:
  3516     if (!WizardMode && !Verbose) {
  3517       if( _klass_is_exact ) st->print(":exact");
  3518       break;
  3520   case TopPTR:
  3521   case AnyNull:
  3522   case NotNull:
  3523     st->print(":%s", ptr_msg[_ptr]);
  3524     if( _klass_is_exact ) st->print(":exact");
  3525     break;
  3528   if( _offset ) {               // Dump offset, if any
  3529     if( _offset == OffsetBot )      st->print("+any");
  3530     else if( _offset == OffsetTop ) st->print("+unknown");
  3531     else st->print("+%d", _offset);
  3534   st->print(" *");
  3535   if (_instance_id == InstanceTop)
  3536     st->print(",iid=top");
  3537   else if (_instance_id != InstanceBot)
  3538     st->print(",iid=%d",_instance_id);
  3540   dump_speculative(st);
  3542 #endif
  3544 //------------------------------add_offset-------------------------------------
  3545 const TypePtr *TypeInstPtr::add_offset(intptr_t offset) const {
  3546   return make(_ptr, klass(), klass_is_exact(), const_oop(), xadd_offset(offset), _instance_id, add_offset_speculative(offset));
  3549 const TypeOopPtr *TypeInstPtr::remove_speculative() const {
  3550   return make(_ptr, klass(), klass_is_exact(), const_oop(), _offset, _instance_id, NULL);
  3553 //=============================================================================
  3554 // Convenience common pre-built types.
  3555 const TypeAryPtr *TypeAryPtr::RANGE;
  3556 const TypeAryPtr *TypeAryPtr::OOPS;
  3557 const TypeAryPtr *TypeAryPtr::NARROWOOPS;
  3558 const TypeAryPtr *TypeAryPtr::BYTES;
  3559 const TypeAryPtr *TypeAryPtr::SHORTS;
  3560 const TypeAryPtr *TypeAryPtr::CHARS;
  3561 const TypeAryPtr *TypeAryPtr::INTS;
  3562 const TypeAryPtr *TypeAryPtr::LONGS;
  3563 const TypeAryPtr *TypeAryPtr::FLOATS;
  3564 const TypeAryPtr *TypeAryPtr::DOUBLES;
  3566 //------------------------------make-------------------------------------------
  3567 const TypeAryPtr *TypeAryPtr::make(PTR ptr, const TypeAry *ary, ciKlass* k, bool xk, int offset, int instance_id, const TypeOopPtr* speculative) {
  3568   assert(!(k == NULL && ary->_elem->isa_int()),
  3569          "integral arrays must be pre-equipped with a class");
  3570   if (!xk)  xk = ary->ary_must_be_exact();
  3571   assert(instance_id <= 0 || xk || !UseExactTypes, "instances are always exactly typed");
  3572   if (!UseExactTypes)  xk = (ptr == Constant);
  3573   return (TypeAryPtr*)(new TypeAryPtr(ptr, NULL, ary, k, xk, offset, instance_id, false, speculative))->hashcons();
  3576 //------------------------------make-------------------------------------------
  3577 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) {
  3578   assert(!(k == NULL && ary->_elem->isa_int()),
  3579          "integral arrays must be pre-equipped with a class");
  3580   assert( (ptr==Constant && o) || (ptr!=Constant && !o), "" );
  3581   if (!xk)  xk = (o != NULL) || ary->ary_must_be_exact();
  3582   assert(instance_id <= 0 || xk || !UseExactTypes, "instances are always exactly typed");
  3583   if (!UseExactTypes)  xk = (ptr == Constant);
  3584   return (TypeAryPtr*)(new TypeAryPtr(ptr, o, ary, k, xk, offset, instance_id, is_autobox_cache, speculative))->hashcons();
  3587 //------------------------------cast_to_ptr_type-------------------------------
  3588 const Type *TypeAryPtr::cast_to_ptr_type(PTR ptr) const {
  3589   if( ptr == _ptr ) return this;
  3590   return make(ptr, const_oop(), _ary, klass(), klass_is_exact(), _offset, _instance_id, _speculative);
  3594 //-----------------------------cast_to_exactness-------------------------------
  3595 const Type *TypeAryPtr::cast_to_exactness(bool klass_is_exact) const {
  3596   if( klass_is_exact == _klass_is_exact ) return this;
  3597   if (!UseExactTypes)  return this;
  3598   if (_ary->ary_must_be_exact())  return this;  // cannot clear xk
  3599   return make(ptr(), const_oop(), _ary, klass(), klass_is_exact, _offset, _instance_id, _speculative);
  3602 //-----------------------------cast_to_instance_id----------------------------
  3603 const TypeOopPtr *TypeAryPtr::cast_to_instance_id(int instance_id) const {
  3604   if( instance_id == _instance_id ) return this;
  3605   return make(_ptr, const_oop(), _ary, klass(), _klass_is_exact, _offset, instance_id, _speculative);
  3608 //-----------------------------narrow_size_type-------------------------------
  3609 // Local cache for arrayOopDesc::max_array_length(etype),
  3610 // which is kind of slow (and cached elsewhere by other users).
  3611 static jint max_array_length_cache[T_CONFLICT+1];
  3612 static jint max_array_length(BasicType etype) {
  3613   jint& cache = max_array_length_cache[etype];
  3614   jint res = cache;
  3615   if (res == 0) {
  3616     switch (etype) {
  3617     case T_NARROWOOP:
  3618       etype = T_OBJECT;
  3619       break;
  3620     case T_NARROWKLASS:
  3621     case T_CONFLICT:
  3622     case T_ILLEGAL:
  3623     case T_VOID:
  3624       etype = T_BYTE;           // will produce conservatively high value
  3626     cache = res = arrayOopDesc::max_array_length(etype);
  3628   return res;
  3631 // Narrow the given size type to the index range for the given array base type.
  3632 // Return NULL if the resulting int type becomes empty.
  3633 const TypeInt* TypeAryPtr::narrow_size_type(const TypeInt* size) const {
  3634   jint hi = size->_hi;
  3635   jint lo = size->_lo;
  3636   jint min_lo = 0;
  3637   jint max_hi = max_array_length(elem()->basic_type());
  3638   //if (index_not_size)  --max_hi;     // type of a valid array index, FTR
  3639   bool chg = false;
  3640   if (lo < min_lo) {
  3641     lo = min_lo;
  3642     if (size->is_con()) {
  3643       hi = lo;
  3645     chg = true;
  3647   if (hi > max_hi) {
  3648     hi = max_hi;
  3649     if (size->is_con()) {
  3650       lo = hi;
  3652     chg = true;
  3654   // Negative length arrays will produce weird intermediate dead fast-path code
  3655   if (lo > hi)
  3656     return TypeInt::ZERO;
  3657   if (!chg)
  3658     return size;
  3659   return TypeInt::make(lo, hi, Type::WidenMin);
  3662 //-------------------------------cast_to_size----------------------------------
  3663 const TypeAryPtr* TypeAryPtr::cast_to_size(const TypeInt* new_size) const {
  3664   assert(new_size != NULL, "");
  3665   new_size = narrow_size_type(new_size);
  3666   if (new_size == size())  return this;
  3667   const TypeAry* new_ary = TypeAry::make(elem(), new_size, is_stable());
  3668   return make(ptr(), const_oop(), new_ary, klass(), klass_is_exact(), _offset, _instance_id, _speculative);
  3672 //------------------------------cast_to_stable---------------------------------
  3673 const TypeAryPtr* TypeAryPtr::cast_to_stable(bool stable, int stable_dimension) const {
  3674   if (stable_dimension <= 0 || (stable_dimension == 1 && stable == this->is_stable()))
  3675     return this;
  3677   const Type* elem = this->elem();
  3678   const TypePtr* elem_ptr = elem->make_ptr();
  3680   if (stable_dimension > 1 && elem_ptr != NULL && elem_ptr->isa_aryptr()) {
  3681     // If this is widened from a narrow oop, TypeAry::make will re-narrow it.
  3682     elem = elem_ptr = elem_ptr->is_aryptr()->cast_to_stable(stable, stable_dimension - 1);
  3685   const TypeAry* new_ary = TypeAry::make(elem, size(), stable);
  3687   return make(ptr(), const_oop(), new_ary, klass(), klass_is_exact(), _offset, _instance_id);
  3690 //-----------------------------stable_dimension--------------------------------
  3691 int TypeAryPtr::stable_dimension() const {
  3692   if (!is_stable())  return 0;
  3693   int dim = 1;
  3694   const TypePtr* elem_ptr = elem()->make_ptr();
  3695   if (elem_ptr != NULL && elem_ptr->isa_aryptr())
  3696     dim += elem_ptr->is_aryptr()->stable_dimension();
  3697   return dim;
  3700 //------------------------------eq---------------------------------------------
  3701 // Structural equality check for Type representations
  3702 bool TypeAryPtr::eq( const Type *t ) const {
  3703   const TypeAryPtr *p = t->is_aryptr();
  3704   return
  3705     _ary == p->_ary &&  // Check array
  3706     TypeOopPtr::eq(p);  // Check sub-parts
  3709 //------------------------------hash-------------------------------------------
  3710 // Type-specific hashing function.
  3711 int TypeAryPtr::hash(void) const {
  3712   return (intptr_t)_ary + TypeOopPtr::hash();
  3715 //------------------------------meet-------------------------------------------
  3716 // Compute the MEET of two types.  It returns a new Type object.
  3717 const Type *TypeAryPtr::xmeet_helper(const Type *t) const {
  3718   // Perform a fast test for common case; meeting the same types together.
  3719   if( this == t ) return this;  // Meeting same type-rep?
  3720   // Current "this->_base" is Pointer
  3721   switch (t->base()) {          // switch on original type
  3723   // Mixing ints & oops happens when javac reuses local variables
  3724   case Int:
  3725   case Long:
  3726   case FloatTop:
  3727   case FloatCon:
  3728   case FloatBot:
  3729   case DoubleTop:
  3730   case DoubleCon:
  3731   case DoubleBot:
  3732   case NarrowOop:
  3733   case NarrowKlass:
  3734   case Bottom:                  // Ye Olde Default
  3735     return Type::BOTTOM;
  3736   case Top:
  3737     return this;
  3739   default:                      // All else is a mistake
  3740     typerr(t);
  3742   case OopPtr: {                // Meeting to OopPtrs
  3743     // Found a OopPtr type vs self-AryPtr type
  3744     const TypeOopPtr *tp = t->is_oopptr();
  3745     int offset = meet_offset(tp->offset());
  3746     PTR ptr = meet_ptr(tp->ptr());
  3747     switch (tp->ptr()) {
  3748     case TopPTR:
  3749     case AnyNull: {
  3750       int instance_id = meet_instance_id(InstanceTop);
  3751       const TypeOopPtr* speculative = meet_speculative(tp);
  3752       return make(ptr, (ptr == Constant ? const_oop() : NULL),
  3753                   _ary, _klass, _klass_is_exact, offset, instance_id, speculative);
  3755     case BotPTR:
  3756     case NotNull: {
  3757       int instance_id = meet_instance_id(tp->instance_id());
  3758       const TypeOopPtr* speculative = meet_speculative(tp);
  3759       return TypeOopPtr::make(ptr, offset, instance_id, speculative);
  3761     default: ShouldNotReachHere();
  3765   case AnyPtr: {                // Meeting two AnyPtrs
  3766     // Found an AnyPtr type vs self-AryPtr type
  3767     const TypePtr *tp = t->is_ptr();
  3768     int offset = meet_offset(tp->offset());
  3769     PTR ptr = meet_ptr(tp->ptr());
  3770     switch (tp->ptr()) {
  3771     case TopPTR:
  3772       return this;
  3773     case BotPTR:
  3774     case NotNull:
  3775       return TypePtr::make(AnyPtr, ptr, offset);
  3776     case Null:
  3777       if( ptr == Null ) return TypePtr::make(AnyPtr, ptr, offset);
  3778       // else fall through to AnyNull
  3779     case AnyNull: {
  3780       int instance_id = meet_instance_id(InstanceTop);
  3781       const TypeOopPtr* speculative = _speculative;
  3782       return make(ptr, (ptr == Constant ? const_oop() : NULL),
  3783                   _ary, _klass, _klass_is_exact, offset, instance_id, speculative);
  3785     default: ShouldNotReachHere();
  3789   case MetadataPtr:
  3790   case KlassPtr:
  3791   case RawPtr: return TypePtr::BOTTOM;
  3793   case AryPtr: {                // Meeting 2 references?
  3794     const TypeAryPtr *tap = t->is_aryptr();
  3795     int off = meet_offset(tap->offset());
  3796     const TypeAry *tary = _ary->meet(tap->_ary)->is_ary();
  3797     PTR ptr = meet_ptr(tap->ptr());
  3798     int instance_id = meet_instance_id(tap->instance_id());
  3799     const TypeOopPtr* speculative = meet_speculative(tap);
  3800     ciKlass* lazy_klass = NULL;
  3801     if (tary->_elem->isa_int()) {
  3802       // Integral array element types have irrelevant lattice relations.
  3803       // It is the klass that determines array layout, not the element type.
  3804       if (_klass == NULL)
  3805         lazy_klass = tap->_klass;
  3806       else if (tap->_klass == NULL || tap->_klass == _klass) {
  3807         lazy_klass = _klass;
  3808       } else {
  3809         // Something like byte[int+] meets char[int+].
  3810         // This must fall to bottom, not (int[-128..65535])[int+].
  3811         instance_id = InstanceBot;
  3812         tary = TypeAry::make(Type::BOTTOM, tary->_size, tary->_stable);
  3814     } else // Non integral arrays.
  3815       // Must fall to bottom if exact klasses in upper lattice
  3816       // are not equal or super klass is exact.
  3817       if ((above_centerline(ptr) || ptr == Constant) && klass() != tap->klass() &&
  3818           // meet with top[] and bottom[] are processed further down:
  3819           tap->_klass != NULL  && this->_klass != NULL   &&
  3820           // both are exact and not equal:
  3821           ((tap->_klass_is_exact && this->_klass_is_exact) ||
  3822            // 'tap'  is exact and super or unrelated:
  3823            (tap->_klass_is_exact && !tap->klass()->is_subtype_of(klass())) ||
  3824            // 'this' is exact and super or unrelated:
  3825            (this->_klass_is_exact && !klass()->is_subtype_of(tap->klass())))) {
  3826       tary = TypeAry::make(Type::BOTTOM, tary->_size, tary->_stable);
  3827       return make(NotNull, NULL, tary, lazy_klass, false, off, InstanceBot);
  3830     bool xk = false;
  3831     switch (tap->ptr()) {
  3832     case AnyNull:
  3833     case TopPTR:
  3834       // Compute new klass on demand, do not use tap->_klass
  3835       if (below_centerline(this->_ptr)) {
  3836         xk = this->_klass_is_exact;
  3837       } else {
  3838         xk = (tap->_klass_is_exact | this->_klass_is_exact);
  3840       return make(ptr, const_oop(), tary, lazy_klass, xk, off, instance_id, speculative);
  3841     case Constant: {
  3842       ciObject* o = const_oop();
  3843       if( _ptr == Constant ) {
  3844         if( tap->const_oop() != NULL && !o->equals(tap->const_oop()) ) {
  3845           xk = (klass() == tap->klass());
  3846           ptr = NotNull;
  3847           o = NULL;
  3848           instance_id = InstanceBot;
  3849         } else {
  3850           xk = true;
  3852       } else if(above_centerline(_ptr)) {
  3853         o = tap->const_oop();
  3854         xk = true;
  3855       } else {
  3856         // Only precise for identical arrays
  3857         xk = this->_klass_is_exact && (klass() == tap->klass());
  3859       return TypeAryPtr::make(ptr, o, tary, lazy_klass, xk, off, instance_id, speculative);
  3861     case NotNull:
  3862     case BotPTR:
  3863       // Compute new klass on demand, do not use tap->_klass
  3864       if (above_centerline(this->_ptr))
  3865             xk = tap->_klass_is_exact;
  3866       else  xk = (tap->_klass_is_exact & this->_klass_is_exact) &&
  3867               (klass() == tap->klass()); // Only precise for identical arrays
  3868       return TypeAryPtr::make(ptr, NULL, tary, lazy_klass, xk, off, instance_id, speculative);
  3869     default: ShouldNotReachHere();
  3873   // All arrays inherit from Object class
  3874   case InstPtr: {
  3875     const TypeInstPtr *tp = t->is_instptr();
  3876     int offset = meet_offset(tp->offset());
  3877     PTR ptr = meet_ptr(tp->ptr());
  3878     int instance_id = meet_instance_id(tp->instance_id());
  3879     const TypeOopPtr* speculative = meet_speculative(tp);
  3880     switch (ptr) {
  3881     case TopPTR:
  3882     case AnyNull:                // Fall 'down' to dual of object klass
  3883       // For instances when a subclass meets a superclass we fall
  3884       // below the centerline when the superclass is exact. We need to
  3885       // do the same here.
  3886       if (tp->klass()->equals(ciEnv::current()->Object_klass()) && !tp->klass_is_exact()) {
  3887         return TypeAryPtr::make(ptr, _ary, _klass, _klass_is_exact, offset, instance_id, speculative);
  3888       } else {
  3889         // cannot subclass, so the meet has to fall badly below the centerline
  3890         ptr = NotNull;
  3891         instance_id = InstanceBot;
  3892         return TypeInstPtr::make(ptr, ciEnv::current()->Object_klass(), false, NULL,offset, instance_id, speculative);
  3894     case Constant:
  3895     case NotNull:
  3896     case BotPTR:                // Fall down to object klass
  3897       // LCA is object_klass, but if we subclass from the top we can do better
  3898       if (above_centerline(tp->ptr())) {
  3899         // If 'tp'  is above the centerline and it is Object class
  3900         // then we can subclass in the Java class hierarchy.
  3901         // For instances when a subclass meets a superclass we fall
  3902         // below the centerline when the superclass is exact. We need
  3903         // to do the same here.
  3904         if (tp->klass()->equals(ciEnv::current()->Object_klass()) && !tp->klass_is_exact()) {
  3905           // that is, my array type is a subtype of 'tp' klass
  3906           return make(ptr, (ptr == Constant ? const_oop() : NULL),
  3907                       _ary, _klass, _klass_is_exact, offset, instance_id, speculative);
  3910       // The other case cannot happen, since t cannot be a subtype of an array.
  3911       // The meet falls down to Object class below centerline.
  3912       if( ptr == Constant )
  3913          ptr = NotNull;
  3914       instance_id = InstanceBot;
  3915       return TypeInstPtr::make(ptr, ciEnv::current()->Object_klass(), false, NULL,offset, instance_id, speculative);
  3916     default: typerr(t);
  3920   return this;                  // Lint noise
  3923 //------------------------------xdual------------------------------------------
  3924 // Dual: compute field-by-field dual
  3925 const Type *TypeAryPtr::xdual() const {
  3926   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());
  3929 //----------------------interface_vs_oop---------------------------------------
  3930 #ifdef ASSERT
  3931 bool TypeAryPtr::interface_vs_oop(const Type *t) const {
  3932   const TypeAryPtr* t_aryptr = t->isa_aryptr();
  3933   if (t_aryptr) {
  3934     return _ary->interface_vs_oop(t_aryptr->_ary);
  3936   return false;
  3938 #endif
  3940 //------------------------------dump2------------------------------------------
  3941 #ifndef PRODUCT
  3942 void TypeAryPtr::dump2( Dict &d, uint depth, outputStream *st ) const {
  3943   _ary->dump2(d,depth,st);
  3944   switch( _ptr ) {
  3945   case Constant:
  3946     const_oop()->print(st);
  3947     break;
  3948   case BotPTR:
  3949     if (!WizardMode && !Verbose) {
  3950       if( _klass_is_exact ) st->print(":exact");
  3951       break;
  3953   case TopPTR:
  3954   case AnyNull:
  3955   case NotNull:
  3956     st->print(":%s", ptr_msg[_ptr]);
  3957     if( _klass_is_exact ) st->print(":exact");
  3958     break;
  3961   if( _offset != 0 ) {
  3962     int header_size = objArrayOopDesc::header_size() * wordSize;
  3963     if( _offset == OffsetTop )       st->print("+undefined");
  3964     else if( _offset == OffsetBot )  st->print("+any");
  3965     else if( _offset < header_size ) st->print("+%d", _offset);
  3966     else {
  3967       BasicType basic_elem_type = elem()->basic_type();
  3968       int array_base = arrayOopDesc::base_offset_in_bytes(basic_elem_type);
  3969       int elem_size = type2aelembytes(basic_elem_type);
  3970       st->print("[%d]", (_offset - array_base)/elem_size);
  3973   st->print(" *");
  3974   if (_instance_id == InstanceTop)
  3975     st->print(",iid=top");
  3976   else if (_instance_id != InstanceBot)
  3977     st->print(",iid=%d",_instance_id);
  3979   dump_speculative(st);
  3981 #endif
  3983 bool TypeAryPtr::empty(void) const {
  3984   if (_ary->empty())       return true;
  3985   return TypeOopPtr::empty();
  3988 //------------------------------add_offset-------------------------------------
  3989 const TypePtr *TypeAryPtr::add_offset(intptr_t offset) const {
  3990   return make(_ptr, _const_oop, _ary, _klass, _klass_is_exact, xadd_offset(offset), _instance_id, add_offset_speculative(offset));
  3993 const TypeOopPtr *TypeAryPtr::remove_speculative() const {
  3994   return make(_ptr, _const_oop, _ary, _klass, _klass_is_exact, _offset, _instance_id, NULL);
  3997 //=============================================================================
  3999 //------------------------------hash-------------------------------------------
  4000 // Type-specific hashing function.
  4001 int TypeNarrowPtr::hash(void) const {
  4002   return _ptrtype->hash() + 7;
  4005 bool TypeNarrowPtr::singleton(void) const {    // TRUE if type is a singleton
  4006   return _ptrtype->singleton();
  4009 bool TypeNarrowPtr::empty(void) const {
  4010   return _ptrtype->empty();
  4013 intptr_t TypeNarrowPtr::get_con() const {
  4014   return _ptrtype->get_con();
  4017 bool TypeNarrowPtr::eq( const Type *t ) const {
  4018   const TypeNarrowPtr* tc = isa_same_narrowptr(t);
  4019   if (tc != NULL) {
  4020     if (_ptrtype->base() != tc->_ptrtype->base()) {
  4021       return false;
  4023     return tc->_ptrtype->eq(_ptrtype);
  4025   return false;
  4028 const Type *TypeNarrowPtr::xdual() const {    // Compute dual right now.
  4029   const TypePtr* odual = _ptrtype->dual()->is_ptr();
  4030   return make_same_narrowptr(odual);
  4034 const Type *TypeNarrowPtr::filter( const Type *kills ) const {
  4035   if (isa_same_narrowptr(kills)) {
  4036     const Type* ft =_ptrtype->filter(is_same_narrowptr(kills)->_ptrtype);
  4037     if (ft->empty())
  4038       return Type::TOP;           // Canonical empty value
  4039     if (ft->isa_ptr()) {
  4040       return make_hash_same_narrowptr(ft->isa_ptr());
  4042     return ft;
  4043   } else if (kills->isa_ptr()) {
  4044     const Type* ft = _ptrtype->join(kills);
  4045     if (ft->empty())
  4046       return Type::TOP;           // Canonical empty value
  4047     return ft;
  4048   } else {
  4049     return Type::TOP;
  4053 //------------------------------xmeet------------------------------------------
  4054 // Compute the MEET of two types.  It returns a new Type object.
  4055 const Type *TypeNarrowPtr::xmeet( const Type *t ) const {
  4056   // Perform a fast test for common case; meeting the same types together.
  4057   if( this == t ) return this;  // Meeting same type-rep?
  4059   if (t->base() == base()) {
  4060     const Type* result = _ptrtype->xmeet(t->make_ptr());
  4061     if (result->isa_ptr()) {
  4062       return make_hash_same_narrowptr(result->is_ptr());
  4064     return result;
  4067   // Current "this->_base" is NarrowKlass or NarrowOop
  4068   switch (t->base()) {          // switch on original type
  4070   case Int:                     // Mixing ints & oops happens when javac
  4071   case Long:                    // reuses local variables
  4072   case FloatTop:
  4073   case FloatCon:
  4074   case FloatBot:
  4075   case DoubleTop:
  4076   case DoubleCon:
  4077   case DoubleBot:
  4078   case AnyPtr:
  4079   case RawPtr:
  4080   case OopPtr:
  4081   case InstPtr:
  4082   case AryPtr:
  4083   case MetadataPtr:
  4084   case KlassPtr:
  4085   case NarrowOop:
  4086   case NarrowKlass:
  4088   case Bottom:                  // Ye Olde Default
  4089     return Type::BOTTOM;
  4090   case Top:
  4091     return this;
  4093   default:                      // All else is a mistake
  4094     typerr(t);
  4096   } // End of switch
  4098   return this;
  4101 #ifndef PRODUCT
  4102 void TypeNarrowPtr::dump2( Dict & d, uint depth, outputStream *st ) const {
  4103   _ptrtype->dump2(d, depth, st);
  4105 #endif
  4107 const TypeNarrowOop *TypeNarrowOop::BOTTOM;
  4108 const TypeNarrowOop *TypeNarrowOop::NULL_PTR;
  4111 const TypeNarrowOop* TypeNarrowOop::make(const TypePtr* type) {
  4112   return (const TypeNarrowOop*)(new TypeNarrowOop(type))->hashcons();
  4116 #ifndef PRODUCT
  4117 void TypeNarrowOop::dump2( Dict & d, uint depth, outputStream *st ) const {
  4118   st->print("narrowoop: ");
  4119   TypeNarrowPtr::dump2(d, depth, st);
  4121 #endif
  4123 const TypeNarrowKlass *TypeNarrowKlass::NULL_PTR;
  4125 const TypeNarrowKlass* TypeNarrowKlass::make(const TypePtr* type) {
  4126   return (const TypeNarrowKlass*)(new TypeNarrowKlass(type))->hashcons();
  4129 #ifndef PRODUCT
  4130 void TypeNarrowKlass::dump2( Dict & d, uint depth, outputStream *st ) const {
  4131   st->print("narrowklass: ");
  4132   TypeNarrowPtr::dump2(d, depth, st);
  4134 #endif
  4137 //------------------------------eq---------------------------------------------
  4138 // Structural equality check for Type representations
  4139 bool TypeMetadataPtr::eq( const Type *t ) const {
  4140   const TypeMetadataPtr *a = (const TypeMetadataPtr*)t;
  4141   ciMetadata* one = metadata();
  4142   ciMetadata* two = a->metadata();
  4143   if (one == NULL || two == NULL) {
  4144     return (one == two) && TypePtr::eq(t);
  4145   } else {
  4146     return one->equals(two) && TypePtr::eq(t);
  4150 //------------------------------hash-------------------------------------------
  4151 // Type-specific hashing function.
  4152 int TypeMetadataPtr::hash(void) const {
  4153   return
  4154     (metadata() ? metadata()->hash() : 0) +
  4155     TypePtr::hash();
  4158 //------------------------------singleton--------------------------------------
  4159 // TRUE if Type is a singleton type, FALSE otherwise.   Singletons are simple
  4160 // constants
  4161 bool TypeMetadataPtr::singleton(void) const {
  4162   // detune optimizer to not generate constant metadta + constant offset as a constant!
  4163   // TopPTR, Null, AnyNull, Constant are all singletons
  4164   return (_offset == 0) && !below_centerline(_ptr);
  4167 //------------------------------add_offset-------------------------------------
  4168 const TypePtr *TypeMetadataPtr::add_offset( intptr_t offset ) const {
  4169   return make( _ptr, _metadata, xadd_offset(offset));
  4172 //-----------------------------filter------------------------------------------
  4173 // Do not allow interface-vs.-noninterface joins to collapse to top.
  4174 const Type *TypeMetadataPtr::filter( const Type *kills ) const {
  4175   const TypeMetadataPtr* ft = join(kills)->isa_metadataptr();
  4176   if (ft == NULL || ft->empty())
  4177     return Type::TOP;           // Canonical empty value
  4178   return ft;
  4181  //------------------------------get_con----------------------------------------
  4182 intptr_t TypeMetadataPtr::get_con() const {
  4183   assert( _ptr == Null || _ptr == Constant, "" );
  4184   assert( _offset >= 0, "" );
  4186   if (_offset != 0) {
  4187     // After being ported to the compiler interface, the compiler no longer
  4188     // directly manipulates the addresses of oops.  Rather, it only has a pointer
  4189     // to a handle at compile time.  This handle is embedded in the generated
  4190     // code and dereferenced at the time the nmethod is made.  Until that time,
  4191     // it is not reasonable to do arithmetic with the addresses of oops (we don't
  4192     // have access to the addresses!).  This does not seem to currently happen,
  4193     // but this assertion here is to help prevent its occurence.
  4194     tty->print_cr("Found oop constant with non-zero offset");
  4195     ShouldNotReachHere();
  4198   return (intptr_t)metadata()->constant_encoding();
  4201 //------------------------------cast_to_ptr_type-------------------------------
  4202 const Type *TypeMetadataPtr::cast_to_ptr_type(PTR ptr) const {
  4203   if( ptr == _ptr ) return this;
  4204   return make(ptr, metadata(), _offset);
  4207 //------------------------------meet-------------------------------------------
  4208 // Compute the MEET of two types.  It returns a new Type object.
  4209 const Type *TypeMetadataPtr::xmeet( const Type *t ) const {
  4210   // Perform a fast test for common case; meeting the same types together.
  4211   if( this == t ) return this;  // Meeting same type-rep?
  4213   // Current "this->_base" is OopPtr
  4214   switch (t->base()) {          // switch on original type
  4216   case Int:                     // Mixing ints & oops happens when javac
  4217   case Long:                    // reuses local variables
  4218   case FloatTop:
  4219   case FloatCon:
  4220   case FloatBot:
  4221   case DoubleTop:
  4222   case DoubleCon:
  4223   case DoubleBot:
  4224   case NarrowOop:
  4225   case NarrowKlass:
  4226   case Bottom:                  // Ye Olde Default
  4227     return Type::BOTTOM;
  4228   case Top:
  4229     return this;
  4231   default:                      // All else is a mistake
  4232     typerr(t);
  4234   case AnyPtr: {
  4235     // Found an AnyPtr type vs self-OopPtr type
  4236     const TypePtr *tp = t->is_ptr();
  4237     int offset = meet_offset(tp->offset());
  4238     PTR ptr = meet_ptr(tp->ptr());
  4239     switch (tp->ptr()) {
  4240     case Null:
  4241       if (ptr == Null)  return TypePtr::make(AnyPtr, ptr, offset);
  4242       // else fall through:
  4243     case TopPTR:
  4244     case AnyNull: {
  4245       return make(ptr, NULL, offset);
  4247     case BotPTR:
  4248     case NotNull:
  4249       return TypePtr::make(AnyPtr, ptr, offset);
  4250     default: typerr(t);
  4254   case RawPtr:
  4255   case KlassPtr:
  4256   case OopPtr:
  4257   case InstPtr:
  4258   case AryPtr:
  4259     return TypePtr::BOTTOM;     // Oop meet raw is not well defined
  4261   case MetadataPtr: {
  4262     const TypeMetadataPtr *tp = t->is_metadataptr();
  4263     int offset = meet_offset(tp->offset());
  4264     PTR tptr = tp->ptr();
  4265     PTR ptr = meet_ptr(tptr);
  4266     ciMetadata* md = (tptr == TopPTR) ? metadata() : tp->metadata();
  4267     if (tptr == TopPTR || _ptr == TopPTR ||
  4268         metadata()->equals(tp->metadata())) {
  4269       return make(ptr, md, offset);
  4271     // metadata is different
  4272     if( ptr == Constant ) {  // Cannot be equal constants, so...
  4273       if( tptr == Constant && _ptr != Constant)  return t;
  4274       if( _ptr == Constant && tptr != Constant)  return this;
  4275       ptr = NotNull;            // Fall down in lattice
  4277     return make(ptr, NULL, offset);
  4278     break;
  4280   } // End of switch
  4281   return this;                  // Return the double constant
  4285 //------------------------------xdual------------------------------------------
  4286 // Dual of a pure metadata pointer.
  4287 const Type *TypeMetadataPtr::xdual() const {
  4288   return new TypeMetadataPtr(dual_ptr(), metadata(), dual_offset());
  4291 //------------------------------dump2------------------------------------------
  4292 #ifndef PRODUCT
  4293 void TypeMetadataPtr::dump2( Dict &d, uint depth, outputStream *st ) const {
  4294   st->print("metadataptr:%s", ptr_msg[_ptr]);
  4295   if( metadata() ) st->print(INTPTR_FORMAT, metadata());
  4296   switch( _offset ) {
  4297   case OffsetTop: st->print("+top"); break;
  4298   case OffsetBot: st->print("+any"); break;
  4299   case         0: break;
  4300   default:        st->print("+%d",_offset); break;
  4303 #endif
  4306 //=============================================================================
  4307 // Convenience common pre-built type.
  4308 const TypeMetadataPtr *TypeMetadataPtr::BOTTOM;
  4310 TypeMetadataPtr::TypeMetadataPtr(PTR ptr, ciMetadata* metadata, int offset):
  4311   TypePtr(MetadataPtr, ptr, offset), _metadata(metadata) {
  4314 const TypeMetadataPtr* TypeMetadataPtr::make(ciMethod* m) {
  4315   return make(Constant, m, 0);
  4317 const TypeMetadataPtr* TypeMetadataPtr::make(ciMethodData* m) {
  4318   return make(Constant, m, 0);
  4321 //------------------------------make-------------------------------------------
  4322 // Create a meta data constant
  4323 const TypeMetadataPtr *TypeMetadataPtr::make(PTR ptr, ciMetadata* m, int offset) {
  4324   assert(m == NULL || !m->is_klass(), "wrong type");
  4325   return (TypeMetadataPtr*)(new TypeMetadataPtr(ptr, m, offset))->hashcons();
  4329 //=============================================================================
  4330 // Convenience common pre-built types.
  4332 // Not-null object klass or below
  4333 const TypeKlassPtr *TypeKlassPtr::OBJECT;
  4334 const TypeKlassPtr *TypeKlassPtr::OBJECT_OR_NULL;
  4336 //------------------------------TypeKlassPtr-----------------------------------
  4337 TypeKlassPtr::TypeKlassPtr( PTR ptr, ciKlass* klass, int offset )
  4338   : TypePtr(KlassPtr, ptr, offset), _klass(klass), _klass_is_exact(ptr == Constant) {
  4341 //------------------------------make-------------------------------------------
  4342 // ptr to klass 'k', if Constant, or possibly to a sub-klass if not a Constant
  4343 const TypeKlassPtr *TypeKlassPtr::make( PTR ptr, ciKlass* k, int offset ) {
  4344   assert( k != NULL, "Expect a non-NULL klass");
  4345   assert(k->is_instance_klass() || k->is_array_klass(), "Incorrect type of klass oop");
  4346   TypeKlassPtr *r =
  4347     (TypeKlassPtr*)(new TypeKlassPtr(ptr, k, offset))->hashcons();
  4349   return r;
  4352 //------------------------------eq---------------------------------------------
  4353 // Structural equality check for Type representations
  4354 bool TypeKlassPtr::eq( const Type *t ) const {
  4355   const TypeKlassPtr *p = t->is_klassptr();
  4356   return
  4357     klass()->equals(p->klass()) &&
  4358     TypePtr::eq(p);
  4361 //------------------------------hash-------------------------------------------
  4362 // Type-specific hashing function.
  4363 int TypeKlassPtr::hash(void) const {
  4364   return klass()->hash() + TypePtr::hash();
  4367 //------------------------------singleton--------------------------------------
  4368 // TRUE if Type is a singleton type, FALSE otherwise.   Singletons are simple
  4369 // constants
  4370 bool TypeKlassPtr::singleton(void) const {
  4371   // detune optimizer to not generate constant klass + constant offset as a constant!
  4372   // TopPTR, Null, AnyNull, Constant are all singletons
  4373   return (_offset == 0) && !below_centerline(_ptr);
  4376 // Do not allow interface-vs.-noninterface joins to collapse to top.
  4377 const Type *TypeKlassPtr::filter(const Type *kills) const {
  4378   // logic here mirrors the one from TypeOopPtr::filter. See comments
  4379   // there.
  4380   const Type* ft = join(kills);
  4381   const TypeKlassPtr* ftkp = ft->isa_klassptr();
  4382   const TypeKlassPtr* ktkp = kills->isa_klassptr();
  4384   if (ft->empty()) {
  4385     if (!empty() && ktkp != NULL && ktkp->klass()->is_loaded() && ktkp->klass()->is_interface())
  4386       return kills;             // Uplift to interface
  4388     return Type::TOP;           // Canonical empty value
  4391   // Interface klass type could be exact in opposite to interface type,
  4392   // return it here instead of incorrect Constant ptr J/L/Object (6894807).
  4393   if (ftkp != NULL && ktkp != NULL &&
  4394       ftkp->is_loaded() &&  ftkp->klass()->is_interface() &&
  4395       !ftkp->klass_is_exact() && // Keep exact interface klass
  4396       ktkp->is_loaded() && !ktkp->klass()->is_interface()) {
  4397     return ktkp->cast_to_ptr_type(ftkp->ptr());
  4400   return ft;
  4403 //----------------------compute_klass------------------------------------------
  4404 // Compute the defining klass for this class
  4405 ciKlass* TypeAryPtr::compute_klass(DEBUG_ONLY(bool verify)) const {
  4406   // Compute _klass based on element type.
  4407   ciKlass* k_ary = NULL;
  4408   const TypeInstPtr *tinst;
  4409   const TypeAryPtr *tary;
  4410   const Type* el = elem();
  4411   if (el->isa_narrowoop()) {
  4412     el = el->make_ptr();
  4415   // Get element klass
  4416   if ((tinst = el->isa_instptr()) != NULL) {
  4417     // Compute array klass from element klass
  4418     k_ary = ciObjArrayKlass::make(tinst->klass());
  4419   } else if ((tary = el->isa_aryptr()) != NULL) {
  4420     // Compute array klass from element klass
  4421     ciKlass* k_elem = tary->klass();
  4422     // If element type is something like bottom[], k_elem will be null.
  4423     if (k_elem != NULL)
  4424       k_ary = ciObjArrayKlass::make(k_elem);
  4425   } else if ((el->base() == Type::Top) ||
  4426              (el->base() == Type::Bottom)) {
  4427     // element type of Bottom occurs from meet of basic type
  4428     // and object; Top occurs when doing join on Bottom.
  4429     // Leave k_ary at NULL.
  4430   } else {
  4431     // Cannot compute array klass directly from basic type,
  4432     // since subtypes of TypeInt all have basic type T_INT.
  4433 #ifdef ASSERT
  4434     if (verify && el->isa_int()) {
  4435       // Check simple cases when verifying klass.
  4436       BasicType bt = T_ILLEGAL;
  4437       if (el == TypeInt::BYTE) {
  4438         bt = T_BYTE;
  4439       } else if (el == TypeInt::SHORT) {
  4440         bt = T_SHORT;
  4441       } else if (el == TypeInt::CHAR) {
  4442         bt = T_CHAR;
  4443       } else if (el == TypeInt::INT) {
  4444         bt = T_INT;
  4445       } else {
  4446         return _klass; // just return specified klass
  4448       return ciTypeArrayKlass::make(bt);
  4450 #endif
  4451     assert(!el->isa_int(),
  4452            "integral arrays must be pre-equipped with a class");
  4453     // Compute array klass directly from basic type
  4454     k_ary = ciTypeArrayKlass::make(el->basic_type());
  4456   return k_ary;
  4459 //------------------------------klass------------------------------------------
  4460 // Return the defining klass for this class
  4461 ciKlass* TypeAryPtr::klass() const {
  4462   if( _klass ) return _klass;   // Return cached value, if possible
  4464   // Oops, need to compute _klass and cache it
  4465   ciKlass* k_ary = compute_klass();
  4467   if( this != TypeAryPtr::OOPS && this->dual() != TypeAryPtr::OOPS ) {
  4468     // The _klass field acts as a cache of the underlying
  4469     // ciKlass for this array type.  In order to set the field,
  4470     // we need to cast away const-ness.
  4471     //
  4472     // IMPORTANT NOTE: we *never* set the _klass field for the
  4473     // type TypeAryPtr::OOPS.  This Type is shared between all
  4474     // active compilations.  However, the ciKlass which represents
  4475     // this Type is *not* shared between compilations, so caching
  4476     // this value would result in fetching a dangling pointer.
  4477     //
  4478     // Recomputing the underlying ciKlass for each request is
  4479     // a bit less efficient than caching, but calls to
  4480     // TypeAryPtr::OOPS->klass() are not common enough to matter.
  4481     ((TypeAryPtr*)this)->_klass = k_ary;
  4482     if (UseCompressedOops && k_ary != NULL && k_ary->is_obj_array_klass() &&
  4483         _offset != 0 && _offset != arrayOopDesc::length_offset_in_bytes()) {
  4484       ((TypeAryPtr*)this)->_is_ptr_to_narrowoop = true;
  4487   return k_ary;
  4491 //------------------------------add_offset-------------------------------------
  4492 // Access internals of klass object
  4493 const TypePtr *TypeKlassPtr::add_offset( intptr_t offset ) const {
  4494   return make( _ptr, klass(), xadd_offset(offset) );
  4497 //------------------------------cast_to_ptr_type-------------------------------
  4498 const Type *TypeKlassPtr::cast_to_ptr_type(PTR ptr) const {
  4499   assert(_base == KlassPtr, "subclass must override cast_to_ptr_type");
  4500   if( ptr == _ptr ) return this;
  4501   return make(ptr, _klass, _offset);
  4505 //-----------------------------cast_to_exactness-------------------------------
  4506 const Type *TypeKlassPtr::cast_to_exactness(bool klass_is_exact) const {
  4507   if( klass_is_exact == _klass_is_exact ) return this;
  4508   if (!UseExactTypes)  return this;
  4509   return make(klass_is_exact ? Constant : NotNull, _klass, _offset);
  4513 //-----------------------------as_instance_type--------------------------------
  4514 // Corresponding type for an instance of the given class.
  4515 // It will be NotNull, and exact if and only if the klass type is exact.
  4516 const TypeOopPtr* TypeKlassPtr::as_instance_type() const {
  4517   ciKlass* k = klass();
  4518   bool    xk = klass_is_exact();
  4519   //return TypeInstPtr::make(TypePtr::NotNull, k, xk, NULL, 0);
  4520   const TypeOopPtr* toop = TypeOopPtr::make_from_klass_raw(k);
  4521   guarantee(toop != NULL, "need type for given klass");
  4522   toop = toop->cast_to_ptr_type(TypePtr::NotNull)->is_oopptr();
  4523   return toop->cast_to_exactness(xk)->is_oopptr();
  4527 //------------------------------xmeet------------------------------------------
  4528 // Compute the MEET of two types, return a new Type object.
  4529 const Type    *TypeKlassPtr::xmeet( const Type *t ) const {
  4530   // Perform a fast test for common case; meeting the same types together.
  4531   if( this == t ) return this;  // Meeting same type-rep?
  4533   // Current "this->_base" is Pointer
  4534   switch (t->base()) {          // switch on original type
  4536   case Int:                     // Mixing ints & oops happens when javac
  4537   case Long:                    // reuses local variables
  4538   case FloatTop:
  4539   case FloatCon:
  4540   case FloatBot:
  4541   case DoubleTop:
  4542   case DoubleCon:
  4543   case DoubleBot:
  4544   case NarrowOop:
  4545   case NarrowKlass:
  4546   case Bottom:                  // Ye Olde Default
  4547     return Type::BOTTOM;
  4548   case Top:
  4549     return this;
  4551   default:                      // All else is a mistake
  4552     typerr(t);
  4554   case AnyPtr: {                // Meeting to AnyPtrs
  4555     // Found an AnyPtr type vs self-KlassPtr type
  4556     const TypePtr *tp = t->is_ptr();
  4557     int offset = meet_offset(tp->offset());
  4558     PTR ptr = meet_ptr(tp->ptr());
  4559     switch (tp->ptr()) {
  4560     case TopPTR:
  4561       return this;
  4562     case Null:
  4563       if( ptr == Null ) return TypePtr::make( AnyPtr, ptr, offset );
  4564     case AnyNull:
  4565       return make( ptr, klass(), offset );
  4566     case BotPTR:
  4567     case NotNull:
  4568       return TypePtr::make(AnyPtr, ptr, offset);
  4569     default: typerr(t);
  4573   case RawPtr:
  4574   case MetadataPtr:
  4575   case OopPtr:
  4576   case AryPtr:                  // Meet with AryPtr
  4577   case InstPtr:                 // Meet with InstPtr
  4578     return TypePtr::BOTTOM;
  4580   //
  4581   //             A-top         }
  4582   //           /   |   \       }  Tops
  4583   //       B-top A-any C-top   }
  4584   //          | /  |  \ |      }  Any-nulls
  4585   //       B-any   |   C-any   }
  4586   //          |    |    |
  4587   //       B-con A-con C-con   } constants; not comparable across classes
  4588   //          |    |    |
  4589   //       B-not   |   C-not   }
  4590   //          | \  |  / |      }  not-nulls
  4591   //       B-bot A-not C-bot   }
  4592   //           \   |   /       }  Bottoms
  4593   //             A-bot         }
  4594   //
  4596   case KlassPtr: {  // Meet two KlassPtr types
  4597     const TypeKlassPtr *tkls = t->is_klassptr();
  4598     int  off     = meet_offset(tkls->offset());
  4599     PTR  ptr     = meet_ptr(tkls->ptr());
  4601     // Check for easy case; klasses are equal (and perhaps not loaded!)
  4602     // If we have constants, then we created oops so classes are loaded
  4603     // and we can handle the constants further down.  This case handles
  4604     // not-loaded classes
  4605     if( ptr != Constant && tkls->klass()->equals(klass()) ) {
  4606       return make( ptr, klass(), off );
  4609     // Classes require inspection in the Java klass hierarchy.  Must be loaded.
  4610     ciKlass* tkls_klass = tkls->klass();
  4611     ciKlass* this_klass = this->klass();
  4612     assert( tkls_klass->is_loaded(), "This class should have been loaded.");
  4613     assert( this_klass->is_loaded(), "This class should have been loaded.");
  4615     // If 'this' type is above the centerline and is a superclass of the
  4616     // other, we can treat 'this' as having the same type as the other.
  4617     if ((above_centerline(this->ptr())) &&
  4618         tkls_klass->is_subtype_of(this_klass)) {
  4619       this_klass = tkls_klass;
  4621     // If 'tinst' type is above the centerline and is a superclass of the
  4622     // other, we can treat 'tinst' as having the same type as the other.
  4623     if ((above_centerline(tkls->ptr())) &&
  4624         this_klass->is_subtype_of(tkls_klass)) {
  4625       tkls_klass = this_klass;
  4628     // Check for classes now being equal
  4629     if (tkls_klass->equals(this_klass)) {
  4630       // If the klasses are equal, the constants may still differ.  Fall to
  4631       // NotNull if they do (neither constant is NULL; that is a special case
  4632       // handled elsewhere).
  4633       if( ptr == Constant ) {
  4634         if (this->_ptr == Constant && tkls->_ptr == Constant &&
  4635             this->klass()->equals(tkls->klass()));
  4636         else if (above_centerline(this->ptr()));
  4637         else if (above_centerline(tkls->ptr()));
  4638         else
  4639           ptr = NotNull;
  4641       return make( ptr, this_klass, off );
  4642     } // Else classes are not equal
  4644     // Since klasses are different, we require the LCA in the Java
  4645     // class hierarchy - which means we have to fall to at least NotNull.
  4646     if( ptr == TopPTR || ptr == AnyNull || ptr == Constant )
  4647       ptr = NotNull;
  4648     // Now we find the LCA of Java classes
  4649     ciKlass* k = this_klass->least_common_ancestor(tkls_klass);
  4650     return   make( ptr, k, off );
  4651   } // End of case KlassPtr
  4653   } // End of switch
  4654   return this;                  // Return the double constant
  4657 //------------------------------xdual------------------------------------------
  4658 // Dual: compute field-by-field dual
  4659 const Type    *TypeKlassPtr::xdual() const {
  4660   return new TypeKlassPtr( dual_ptr(), klass(), dual_offset() );
  4663 //------------------------------get_con----------------------------------------
  4664 intptr_t TypeKlassPtr::get_con() const {
  4665   assert( _ptr == Null || _ptr == Constant, "" );
  4666   assert( _offset >= 0, "" );
  4668   if (_offset != 0) {
  4669     // After being ported to the compiler interface, the compiler no longer
  4670     // directly manipulates the addresses of oops.  Rather, it only has a pointer
  4671     // to a handle at compile time.  This handle is embedded in the generated
  4672     // code and dereferenced at the time the nmethod is made.  Until that time,
  4673     // it is not reasonable to do arithmetic with the addresses of oops (we don't
  4674     // have access to the addresses!).  This does not seem to currently happen,
  4675     // but this assertion here is to help prevent its occurence.
  4676     tty->print_cr("Found oop constant with non-zero offset");
  4677     ShouldNotReachHere();
  4680   return (intptr_t)klass()->constant_encoding();
  4682 //------------------------------dump2------------------------------------------
  4683 // Dump Klass Type
  4684 #ifndef PRODUCT
  4685 void TypeKlassPtr::dump2( Dict & d, uint depth, outputStream *st ) const {
  4686   switch( _ptr ) {
  4687   case Constant:
  4688     st->print("precise ");
  4689   case NotNull:
  4691       const char *name = klass()->name()->as_utf8();
  4692       if( name ) {
  4693         st->print("klass %s: " INTPTR_FORMAT, name, klass());
  4694       } else {
  4695         ShouldNotReachHere();
  4698   case BotPTR:
  4699     if( !WizardMode && !Verbose && !_klass_is_exact ) break;
  4700   case TopPTR:
  4701   case AnyNull:
  4702     st->print(":%s", ptr_msg[_ptr]);
  4703     if( _klass_is_exact ) st->print(":exact");
  4704     break;
  4707   if( _offset ) {               // Dump offset, if any
  4708     if( _offset == OffsetBot )      { st->print("+any"); }
  4709     else if( _offset == OffsetTop ) { st->print("+unknown"); }
  4710     else                            { st->print("+%d", _offset); }
  4713   st->print(" *");
  4715 #endif
  4719 //=============================================================================
  4720 // Convenience common pre-built types.
  4722 //------------------------------make-------------------------------------------
  4723 const TypeFunc *TypeFunc::make( const TypeTuple *domain, const TypeTuple *range ) {
  4724   return (TypeFunc*)(new TypeFunc(domain,range))->hashcons();
  4727 //------------------------------make-------------------------------------------
  4728 const TypeFunc *TypeFunc::make(ciMethod* method) {
  4729   Compile* C = Compile::current();
  4730   const TypeFunc* tf = C->last_tf(method); // check cache
  4731   if (tf != NULL)  return tf;  // The hit rate here is almost 50%.
  4732   const TypeTuple *domain;
  4733   if (method->is_static()) {
  4734     domain = TypeTuple::make_domain(NULL, method->signature());
  4735   } else {
  4736     domain = TypeTuple::make_domain(method->holder(), method->signature());
  4738   const TypeTuple *range  = TypeTuple::make_range(method->signature());
  4739   tf = TypeFunc::make(domain, range);
  4740   C->set_last_tf(method, tf);  // fill cache
  4741   return tf;
  4744 //------------------------------meet-------------------------------------------
  4745 // Compute the MEET of two types.  It returns a new Type object.
  4746 const Type *TypeFunc::xmeet( const Type *t ) const {
  4747   // Perform a fast test for common case; meeting the same types together.
  4748   if( this == t ) return this;  // Meeting same type-rep?
  4750   // Current "this->_base" is Func
  4751   switch (t->base()) {          // switch on original type
  4753   case Bottom:                  // Ye Olde Default
  4754     return t;
  4756   default:                      // All else is a mistake
  4757     typerr(t);
  4759   case Top:
  4760     break;
  4762   return this;                  // Return the double constant
  4765 //------------------------------xdual------------------------------------------
  4766 // Dual: compute field-by-field dual
  4767 const Type *TypeFunc::xdual() const {
  4768   return this;
  4771 //------------------------------eq---------------------------------------------
  4772 // Structural equality check for Type representations
  4773 bool TypeFunc::eq( const Type *t ) const {
  4774   const TypeFunc *a = (const TypeFunc*)t;
  4775   return _domain == a->_domain &&
  4776     _range == a->_range;
  4779 //------------------------------hash-------------------------------------------
  4780 // Type-specific hashing function.
  4781 int TypeFunc::hash(void) const {
  4782   return (intptr_t)_domain + (intptr_t)_range;
  4785 //------------------------------dump2------------------------------------------
  4786 // Dump Function Type
  4787 #ifndef PRODUCT
  4788 void TypeFunc::dump2( Dict &d, uint depth, outputStream *st ) const {
  4789   if( _range->_cnt <= Parms )
  4790     st->print("void");
  4791   else {
  4792     uint i;
  4793     for (i = Parms; i < _range->_cnt-1; i++) {
  4794       _range->field_at(i)->dump2(d,depth,st);
  4795       st->print("/");
  4797     _range->field_at(i)->dump2(d,depth,st);
  4799   st->print(" ");
  4800   st->print("( ");
  4801   if( !depth || d[this] ) {     // Check for recursive dump
  4802     st->print("...)");
  4803     return;
  4805   d.Insert((void*)this,(void*)this);    // Stop recursion
  4806   if (Parms < _domain->_cnt)
  4807     _domain->field_at(Parms)->dump2(d,depth-1,st);
  4808   for (uint i = Parms+1; i < _domain->_cnt; i++) {
  4809     st->print(", ");
  4810     _domain->field_at(i)->dump2(d,depth-1,st);
  4812   st->print(" )");
  4814 #endif
  4816 //------------------------------singleton--------------------------------------
  4817 // TRUE if Type is a singleton type, FALSE otherwise.   Singletons are simple
  4818 // constants (Ldi nodes).  Singletons are integer, float or double constants
  4819 // or a single symbol.
  4820 bool TypeFunc::singleton(void) const {
  4821   return false;                 // Never a singleton
  4824 bool TypeFunc::empty(void) const {
  4825   return false;                 // Never empty
  4829 BasicType TypeFunc::return_type() const{
  4830   if (range()->cnt() == TypeFunc::Parms) {
  4831     return T_VOID;
  4833   return range()->field_at(TypeFunc::Parms)->basic_type();

mercurial