src/share/vm/opto/type.cpp

Mon, 06 Jan 2014 11:02:21 +0100

author
goetz
date
Mon, 06 Jan 2014 11:02:21 +0100
changeset 6500
4345c6a92f35
parent 6487
15120a36272d
child 6503
a9becfeecd1b
permissions
-rw-r--r--

8031188: Fix for 8029015: PPC64 (part 216): opto: trap based null and range checks
Summary: Swap the Projs in the block list so that the new block is added behind the proper node.
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 #ifdef SPARC
    65   { Bad,             T_ILLEGAL,    "vectors:",      false, 0,                    relocInfo::none          },  // VectorS
    66   { Bad,             T_ILLEGAL,    "vectord:",      false, Op_RegD,              relocInfo::none          },  // VectorD
    67   { Bad,             T_ILLEGAL,    "vectorx:",      false, 0,                    relocInfo::none          },  // VectorX
    68   { Bad,             T_ILLEGAL,    "vectory:",      false, 0,                    relocInfo::none          },  // VectorY
    69 #elif defined(PPC64)
    70   { Bad,             T_ILLEGAL,    "vectors:",      false, 0,                    relocInfo::none          },  // VectorS
    71   { Bad,             T_ILLEGAL,    "vectord:",      false, Op_RegL,              relocInfo::none          },  // VectorD
    72   { Bad,             T_ILLEGAL,    "vectorx:",      false, 0,                    relocInfo::none          },  // VectorX
    73   { Bad,             T_ILLEGAL,    "vectory:",      false, 0,                    relocInfo::none          },  // VectorY
    74 #else // all other
    75   { Bad,             T_ILLEGAL,    "vectors:",      false, Op_VecS,              relocInfo::none          },  // VectorS
    76   { Bad,             T_ILLEGAL,    "vectord:",      false, Op_VecD,              relocInfo::none          },  // VectorD
    77   { Bad,             T_ILLEGAL,    "vectorx:",      false, Op_VecX,              relocInfo::none          },  // VectorX
    78   { Bad,             T_ILLEGAL,    "vectory:",      false, Op_VecY,              relocInfo::none          },  // VectorY
    79 #endif
    80   { Bad,             T_ADDRESS,    "anyptr:",       false, Op_RegP,              relocInfo::none          },  // AnyPtr
    81   { Bad,             T_ADDRESS,    "rawptr:",       false, Op_RegP,              relocInfo::none          },  // RawPtr
    82   { Bad,             T_OBJECT,     "oop:",          true,  Op_RegP,              relocInfo::oop_type      },  // OopPtr
    83   { Bad,             T_OBJECT,     "inst:",         true,  Op_RegP,              relocInfo::oop_type      },  // InstPtr
    84   { Bad,             T_OBJECT,     "ary:",          true,  Op_RegP,              relocInfo::oop_type      },  // AryPtr
    85   { Bad,             T_METADATA,   "metadata:",     false, Op_RegP,              relocInfo::metadata_type },  // MetadataPtr
    86   { Bad,             T_METADATA,   "klass:",        false, Op_RegP,              relocInfo::metadata_type },  // KlassPtr
    87   { Bad,             T_OBJECT,     "func",          false, 0,                    relocInfo::none          },  // Function
    88   { Abio,            T_ILLEGAL,    "abIO",          false, 0,                    relocInfo::none          },  // Abio
    89   { Return_Address,  T_ADDRESS,    "return_address",false, Op_RegP,              relocInfo::none          },  // Return_Address
    90   { Memory,          T_ILLEGAL,    "memory",        false, 0,                    relocInfo::none          },  // Memory
    91   { FloatBot,        T_FLOAT,      "float_top",     false, Op_RegF,              relocInfo::none          },  // FloatTop
    92   { FloatCon,        T_FLOAT,      "ftcon:",        false, Op_RegF,              relocInfo::none          },  // FloatCon
    93   { FloatTop,        T_FLOAT,      "float",         false, Op_RegF,              relocInfo::none          },  // FloatBot
    94   { DoubleBot,       T_DOUBLE,     "double_top",    false, Op_RegD,              relocInfo::none          },  // DoubleTop
    95   { DoubleCon,       T_DOUBLE,     "dblcon:",       false, Op_RegD,              relocInfo::none          },  // DoubleCon
    96   { DoubleTop,       T_DOUBLE,     "double",        false, Op_RegD,              relocInfo::none          },  // DoubleBot
    97   { Top,             T_ILLEGAL,    "bottom",        false, 0,                    relocInfo::none          }   // Bottom
    98 };
   100 // Map ideal registers (machine types) to ideal types
   101 const Type *Type::mreg2type[_last_machine_leaf];
   103 // Map basic types to canonical Type* pointers.
   104 const Type* Type::     _const_basic_type[T_CONFLICT+1];
   106 // Map basic types to constant-zero Types.
   107 const Type* Type::            _zero_type[T_CONFLICT+1];
   109 // Map basic types to array-body alias types.
   110 const TypeAryPtr* TypeAryPtr::_array_body_type[T_CONFLICT+1];
   112 //=============================================================================
   113 // Convenience common pre-built types.
   114 const Type *Type::ABIO;         // State-of-machine only
   115 const Type *Type::BOTTOM;       // All values
   116 const Type *Type::CONTROL;      // Control only
   117 const Type *Type::DOUBLE;       // All doubles
   118 const Type *Type::FLOAT;        // All floats
   119 const Type *Type::HALF;         // Placeholder half of doublewide type
   120 const Type *Type::MEMORY;       // Abstract store only
   121 const Type *Type::RETURN_ADDRESS;
   122 const Type *Type::TOP;          // No values in set
   124 //------------------------------get_const_type---------------------------
   125 const Type* Type::get_const_type(ciType* type) {
   126   if (type == NULL) {
   127     return NULL;
   128   } else if (type->is_primitive_type()) {
   129     return get_const_basic_type(type->basic_type());
   130   } else {
   131     return TypeOopPtr::make_from_klass(type->as_klass());
   132   }
   133 }
   135 //---------------------------array_element_basic_type---------------------------------
   136 // Mapping to the array element's basic type.
   137 BasicType Type::array_element_basic_type() const {
   138   BasicType bt = basic_type();
   139   if (bt == T_INT) {
   140     if (this == TypeInt::INT)   return T_INT;
   141     if (this == TypeInt::CHAR)  return T_CHAR;
   142     if (this == TypeInt::BYTE)  return T_BYTE;
   143     if (this == TypeInt::BOOL)  return T_BOOLEAN;
   144     if (this == TypeInt::SHORT) return T_SHORT;
   145     return T_VOID;
   146   }
   147   return bt;
   148 }
   150 //---------------------------get_typeflow_type---------------------------------
   151 // Import a type produced by ciTypeFlow.
   152 const Type* Type::get_typeflow_type(ciType* type) {
   153   switch (type->basic_type()) {
   155   case ciTypeFlow::StateVector::T_BOTTOM:
   156     assert(type == ciTypeFlow::StateVector::bottom_type(), "");
   157     return Type::BOTTOM;
   159   case ciTypeFlow::StateVector::T_TOP:
   160     assert(type == ciTypeFlow::StateVector::top_type(), "");
   161     return Type::TOP;
   163   case ciTypeFlow::StateVector::T_NULL:
   164     assert(type == ciTypeFlow::StateVector::null_type(), "");
   165     return TypePtr::NULL_PTR;
   167   case ciTypeFlow::StateVector::T_LONG2:
   168     // The ciTypeFlow pass pushes a long, then the half.
   169     // We do the same.
   170     assert(type == ciTypeFlow::StateVector::long2_type(), "");
   171     return TypeInt::TOP;
   173   case ciTypeFlow::StateVector::T_DOUBLE2:
   174     // The ciTypeFlow pass pushes double, then the half.
   175     // Our convention is the same.
   176     assert(type == ciTypeFlow::StateVector::double2_type(), "");
   177     return Type::TOP;
   179   case T_ADDRESS:
   180     assert(type->is_return_address(), "");
   181     return TypeRawPtr::make((address)(intptr_t)type->as_return_address()->bci());
   183   default:
   184     // make sure we did not mix up the cases:
   185     assert(type != ciTypeFlow::StateVector::bottom_type(), "");
   186     assert(type != ciTypeFlow::StateVector::top_type(), "");
   187     assert(type != ciTypeFlow::StateVector::null_type(), "");
   188     assert(type != ciTypeFlow::StateVector::long2_type(), "");
   189     assert(type != ciTypeFlow::StateVector::double2_type(), "");
   190     assert(!type->is_return_address(), "");
   192     return Type::get_const_type(type);
   193   }
   194 }
   197 //-----------------------make_from_constant------------------------------------
   198 const Type* Type::make_from_constant(ciConstant constant,
   199                                      bool require_constant, bool is_autobox_cache) {
   200   switch (constant.basic_type()) {
   201   case T_BOOLEAN:  return TypeInt::make(constant.as_boolean());
   202   case T_CHAR:     return TypeInt::make(constant.as_char());
   203   case T_BYTE:     return TypeInt::make(constant.as_byte());
   204   case T_SHORT:    return TypeInt::make(constant.as_short());
   205   case T_INT:      return TypeInt::make(constant.as_int());
   206   case T_LONG:     return TypeLong::make(constant.as_long());
   207   case T_FLOAT:    return TypeF::make(constant.as_float());
   208   case T_DOUBLE:   return TypeD::make(constant.as_double());
   209   case T_ARRAY:
   210   case T_OBJECT:
   211     {
   212       // cases:
   213       //   can_be_constant    = (oop not scavengable || ScavengeRootsInCode != 0)
   214       //   should_be_constant = (oop not scavengable || ScavengeRootsInCode >= 2)
   215       // An oop is not scavengable if it is in the perm gen.
   216       ciObject* oop_constant = constant.as_object();
   217       if (oop_constant->is_null_object()) {
   218         return Type::get_zero_type(T_OBJECT);
   219       } else if (require_constant || oop_constant->should_be_constant()) {
   220         return TypeOopPtr::make_from_constant(oop_constant, require_constant, is_autobox_cache);
   221       }
   222     }
   223   }
   224   // Fall through to failure
   225   return NULL;
   226 }
   229 //------------------------------make-------------------------------------------
   230 // Create a simple Type, with default empty symbol sets.  Then hashcons it
   231 // and look for an existing copy in the type dictionary.
   232 const Type *Type::make( enum TYPES t ) {
   233   return (new Type(t))->hashcons();
   234 }
   236 //------------------------------cmp--------------------------------------------
   237 int Type::cmp( const Type *const t1, const Type *const t2 ) {
   238   if( t1->_base != t2->_base )
   239     return 1;                   // Missed badly
   240   assert(t1 != t2 || t1->eq(t2), "eq must be reflexive");
   241   return !t1->eq(t2);           // Return ZERO if equal
   242 }
   244 //------------------------------hash-------------------------------------------
   245 int Type::uhash( const Type *const t ) {
   246   return t->hash();
   247 }
   249 #define SMALLINT ((juint)3)  // a value too insignificant to consider widening
   251 //--------------------------Initialize_shared----------------------------------
   252 void Type::Initialize_shared(Compile* current) {
   253   // This method does not need to be locked because the first system
   254   // compilations (stub compilations) occur serially.  If they are
   255   // changed to proceed in parallel, then this section will need
   256   // locking.
   258   Arena* save = current->type_arena();
   259   Arena* shared_type_arena = new (mtCompiler)Arena();
   261   current->set_type_arena(shared_type_arena);
   262   _shared_type_dict =
   263     new (shared_type_arena) Dict( (CmpKey)Type::cmp, (Hash)Type::uhash,
   264                                   shared_type_arena, 128 );
   265   current->set_type_dict(_shared_type_dict);
   267   // Make shared pre-built types.
   268   CONTROL = make(Control);      // Control only
   269   TOP     = make(Top);          // No values in set
   270   MEMORY  = make(Memory);       // Abstract store only
   271   ABIO    = make(Abio);         // State-of-machine only
   272   RETURN_ADDRESS=make(Return_Address);
   273   FLOAT   = make(FloatBot);     // All floats
   274   DOUBLE  = make(DoubleBot);    // All doubles
   275   BOTTOM  = make(Bottom);       // Everything
   276   HALF    = make(Half);         // Placeholder half of doublewide type
   278   TypeF::ZERO = TypeF::make(0.0); // Float 0 (positive zero)
   279   TypeF::ONE  = TypeF::make(1.0); // Float 1
   281   TypeD::ZERO = TypeD::make(0.0); // Double 0 (positive zero)
   282   TypeD::ONE  = TypeD::make(1.0); // Double 1
   284   TypeInt::MINUS_1 = TypeInt::make(-1);  // -1
   285   TypeInt::ZERO    = TypeInt::make( 0);  //  0
   286   TypeInt::ONE     = TypeInt::make( 1);  //  1
   287   TypeInt::BOOL    = TypeInt::make(0,1,   WidenMin);  // 0 or 1, FALSE or TRUE.
   288   TypeInt::CC      = TypeInt::make(-1, 1, WidenMin);  // -1, 0 or 1, condition codes
   289   TypeInt::CC_LT   = TypeInt::make(-1,-1, WidenMin);  // == TypeInt::MINUS_1
   290   TypeInt::CC_GT   = TypeInt::make( 1, 1, WidenMin);  // == TypeInt::ONE
   291   TypeInt::CC_EQ   = TypeInt::make( 0, 0, WidenMin);  // == TypeInt::ZERO
   292   TypeInt::CC_LE   = TypeInt::make(-1, 0, WidenMin);
   293   TypeInt::CC_GE   = TypeInt::make( 0, 1, WidenMin);  // == TypeInt::BOOL
   294   TypeInt::BYTE    = TypeInt::make(-128,127,     WidenMin); // Bytes
   295   TypeInt::UBYTE   = TypeInt::make(0, 255,       WidenMin); // Unsigned Bytes
   296   TypeInt::CHAR    = TypeInt::make(0,65535,      WidenMin); // Java chars
   297   TypeInt::SHORT   = TypeInt::make(-32768,32767, WidenMin); // Java shorts
   298   TypeInt::POS     = TypeInt::make(0,max_jint,   WidenMin); // Non-neg values
   299   TypeInt::POS1    = TypeInt::make(1,max_jint,   WidenMin); // Positive values
   300   TypeInt::INT     = TypeInt::make(min_jint,max_jint, WidenMax); // 32-bit integers
   301   TypeInt::SYMINT  = TypeInt::make(-max_jint,max_jint,WidenMin); // symmetric range
   302   // CmpL is overloaded both as the bytecode computation returning
   303   // a trinary (-1,0,+1) integer result AND as an efficient long
   304   // compare returning optimizer ideal-type flags.
   305   assert( TypeInt::CC_LT == TypeInt::MINUS_1, "types must match for CmpL to work" );
   306   assert( TypeInt::CC_GT == TypeInt::ONE,     "types must match for CmpL to work" );
   307   assert( TypeInt::CC_EQ == TypeInt::ZERO,    "types must match for CmpL to work" );
   308   assert( TypeInt::CC_GE == TypeInt::BOOL,    "types must match for CmpL to work" );
   309   assert( (juint)(TypeInt::CC->_hi - TypeInt::CC->_lo) <= SMALLINT, "CC is truly small");
   311   TypeLong::MINUS_1 = TypeLong::make(-1);        // -1
   312   TypeLong::ZERO    = TypeLong::make( 0);        //  0
   313   TypeLong::ONE     = TypeLong::make( 1);        //  1
   314   TypeLong::POS     = TypeLong::make(0,max_jlong, WidenMin); // Non-neg values
   315   TypeLong::LONG    = TypeLong::make(min_jlong,max_jlong,WidenMax); // 64-bit integers
   316   TypeLong::INT     = TypeLong::make((jlong)min_jint,(jlong)max_jint,WidenMin);
   317   TypeLong::UINT    = TypeLong::make(0,(jlong)max_juint,WidenMin);
   319   const Type **fboth =(const Type**)shared_type_arena->Amalloc_4(2*sizeof(Type*));
   320   fboth[0] = Type::CONTROL;
   321   fboth[1] = Type::CONTROL;
   322   TypeTuple::IFBOTH = TypeTuple::make( 2, fboth );
   324   const Type **ffalse =(const Type**)shared_type_arena->Amalloc_4(2*sizeof(Type*));
   325   ffalse[0] = Type::CONTROL;
   326   ffalse[1] = Type::TOP;
   327   TypeTuple::IFFALSE = TypeTuple::make( 2, ffalse );
   329   const Type **fneither =(const Type**)shared_type_arena->Amalloc_4(2*sizeof(Type*));
   330   fneither[0] = Type::TOP;
   331   fneither[1] = Type::TOP;
   332   TypeTuple::IFNEITHER = TypeTuple::make( 2, fneither );
   334   const Type **ftrue =(const Type**)shared_type_arena->Amalloc_4(2*sizeof(Type*));
   335   ftrue[0] = Type::TOP;
   336   ftrue[1] = Type::CONTROL;
   337   TypeTuple::IFTRUE = TypeTuple::make( 2, ftrue );
   339   const Type **floop =(const Type**)shared_type_arena->Amalloc_4(2*sizeof(Type*));
   340   floop[0] = Type::CONTROL;
   341   floop[1] = TypeInt::INT;
   342   TypeTuple::LOOPBODY = TypeTuple::make( 2, floop );
   344   TypePtr::NULL_PTR= TypePtr::make( AnyPtr, TypePtr::Null, 0 );
   345   TypePtr::NOTNULL = TypePtr::make( AnyPtr, TypePtr::NotNull, OffsetBot );
   346   TypePtr::BOTTOM  = TypePtr::make( AnyPtr, TypePtr::BotPTR, OffsetBot );
   348   TypeRawPtr::BOTTOM = TypeRawPtr::make( TypePtr::BotPTR );
   349   TypeRawPtr::NOTNULL= TypeRawPtr::make( TypePtr::NotNull );
   351   const Type **fmembar = TypeTuple::fields(0);
   352   TypeTuple::MEMBAR = TypeTuple::make(TypeFunc::Parms+0, fmembar);
   354   const Type **fsc = (const Type**)shared_type_arena->Amalloc_4(2*sizeof(Type*));
   355   fsc[0] = TypeInt::CC;
   356   fsc[1] = Type::MEMORY;
   357   TypeTuple::STORECONDITIONAL = TypeTuple::make(2, fsc);
   359   TypeInstPtr::NOTNULL = TypeInstPtr::make(TypePtr::NotNull, current->env()->Object_klass());
   360   TypeInstPtr::BOTTOM  = TypeInstPtr::make(TypePtr::BotPTR,  current->env()->Object_klass());
   361   TypeInstPtr::MIRROR  = TypeInstPtr::make(TypePtr::NotNull, current->env()->Class_klass());
   362   TypeInstPtr::MARK    = TypeInstPtr::make(TypePtr::BotPTR,  current->env()->Object_klass(),
   363                                            false, 0, oopDesc::mark_offset_in_bytes());
   364   TypeInstPtr::KLASS   = TypeInstPtr::make(TypePtr::BotPTR,  current->env()->Object_klass(),
   365                                            false, 0, oopDesc::klass_offset_in_bytes());
   366   TypeOopPtr::BOTTOM  = TypeOopPtr::make(TypePtr::BotPTR, OffsetBot, TypeOopPtr::InstanceBot, NULL);
   368   TypeMetadataPtr::BOTTOM = TypeMetadataPtr::make(TypePtr::BotPTR, NULL, OffsetBot);
   370   TypeNarrowOop::NULL_PTR = TypeNarrowOop::make( TypePtr::NULL_PTR );
   371   TypeNarrowOop::BOTTOM   = TypeNarrowOop::make( TypeInstPtr::BOTTOM );
   373   TypeNarrowKlass::NULL_PTR = TypeNarrowKlass::make( TypePtr::NULL_PTR );
   375   mreg2type[Op_Node] = Type::BOTTOM;
   376   mreg2type[Op_Set ] = 0;
   377   mreg2type[Op_RegN] = TypeNarrowOop::BOTTOM;
   378   mreg2type[Op_RegI] = TypeInt::INT;
   379   mreg2type[Op_RegP] = TypePtr::BOTTOM;
   380   mreg2type[Op_RegF] = Type::FLOAT;
   381   mreg2type[Op_RegD] = Type::DOUBLE;
   382   mreg2type[Op_RegL] = TypeLong::LONG;
   383   mreg2type[Op_RegFlags] = TypeInt::CC;
   385   TypeAryPtr::RANGE   = TypeAryPtr::make( TypePtr::BotPTR, TypeAry::make(Type::BOTTOM,TypeInt::POS), NULL /* current->env()->Object_klass() */, false, arrayOopDesc::length_offset_in_bytes());
   387   TypeAryPtr::NARROWOOPS = TypeAryPtr::make(TypePtr::BotPTR, TypeAry::make(TypeNarrowOop::BOTTOM, TypeInt::POS), NULL /*ciArrayKlass::make(o)*/,  false,  Type::OffsetBot);
   389 #ifdef _LP64
   390   if (UseCompressedOops) {
   391     assert(TypeAryPtr::NARROWOOPS->is_ptr_to_narrowoop(), "array of narrow oops must be ptr to narrow oop");
   392     TypeAryPtr::OOPS  = TypeAryPtr::NARROWOOPS;
   393   } else
   394 #endif
   395   {
   396     // There is no shared klass for Object[].  See note in TypeAryPtr::klass().
   397     TypeAryPtr::OOPS  = TypeAryPtr::make(TypePtr::BotPTR, TypeAry::make(TypeInstPtr::BOTTOM,TypeInt::POS), NULL /*ciArrayKlass::make(o)*/,  false,  Type::OffsetBot);
   398   }
   399   TypeAryPtr::BYTES   = TypeAryPtr::make(TypePtr::BotPTR, TypeAry::make(TypeInt::BYTE      ,TypeInt::POS), ciTypeArrayKlass::make(T_BYTE),   true,  Type::OffsetBot);
   400   TypeAryPtr::SHORTS  = TypeAryPtr::make(TypePtr::BotPTR, TypeAry::make(TypeInt::SHORT     ,TypeInt::POS), ciTypeArrayKlass::make(T_SHORT),  true,  Type::OffsetBot);
   401   TypeAryPtr::CHARS   = TypeAryPtr::make(TypePtr::BotPTR, TypeAry::make(TypeInt::CHAR      ,TypeInt::POS), ciTypeArrayKlass::make(T_CHAR),   true,  Type::OffsetBot);
   402   TypeAryPtr::INTS    = TypeAryPtr::make(TypePtr::BotPTR, TypeAry::make(TypeInt::INT       ,TypeInt::POS), ciTypeArrayKlass::make(T_INT),    true,  Type::OffsetBot);
   403   TypeAryPtr::LONGS   = TypeAryPtr::make(TypePtr::BotPTR, TypeAry::make(TypeLong::LONG     ,TypeInt::POS), ciTypeArrayKlass::make(T_LONG),   true,  Type::OffsetBot);
   404   TypeAryPtr::FLOATS  = TypeAryPtr::make(TypePtr::BotPTR, TypeAry::make(Type::FLOAT        ,TypeInt::POS), ciTypeArrayKlass::make(T_FLOAT),  true,  Type::OffsetBot);
   405   TypeAryPtr::DOUBLES = TypeAryPtr::make(TypePtr::BotPTR, TypeAry::make(Type::DOUBLE       ,TypeInt::POS), ciTypeArrayKlass::make(T_DOUBLE), true,  Type::OffsetBot);
   407   // Nobody should ask _array_body_type[T_NARROWOOP]. Use NULL as assert.
   408   TypeAryPtr::_array_body_type[T_NARROWOOP] = NULL;
   409   TypeAryPtr::_array_body_type[T_OBJECT]  = TypeAryPtr::OOPS;
   410   TypeAryPtr::_array_body_type[T_ARRAY]   = TypeAryPtr::OOPS; // arrays are stored in oop arrays
   411   TypeAryPtr::_array_body_type[T_BYTE]    = TypeAryPtr::BYTES;
   412   TypeAryPtr::_array_body_type[T_BOOLEAN] = TypeAryPtr::BYTES;  // boolean[] is a byte array
   413   TypeAryPtr::_array_body_type[T_SHORT]   = TypeAryPtr::SHORTS;
   414   TypeAryPtr::_array_body_type[T_CHAR]    = TypeAryPtr::CHARS;
   415   TypeAryPtr::_array_body_type[T_INT]     = TypeAryPtr::INTS;
   416   TypeAryPtr::_array_body_type[T_LONG]    = TypeAryPtr::LONGS;
   417   TypeAryPtr::_array_body_type[T_FLOAT]   = TypeAryPtr::FLOATS;
   418   TypeAryPtr::_array_body_type[T_DOUBLE]  = TypeAryPtr::DOUBLES;
   420   TypeKlassPtr::OBJECT = TypeKlassPtr::make( TypePtr::NotNull, current->env()->Object_klass(), 0 );
   421   TypeKlassPtr::OBJECT_OR_NULL = TypeKlassPtr::make( TypePtr::BotPTR, current->env()->Object_klass(), 0 );
   423   const Type **fi2c = TypeTuple::fields(2);
   424   fi2c[TypeFunc::Parms+0] = TypeInstPtr::BOTTOM; // Method*
   425   fi2c[TypeFunc::Parms+1] = TypeRawPtr::BOTTOM; // argument pointer
   426   TypeTuple::START_I2C = TypeTuple::make(TypeFunc::Parms+2, fi2c);
   428   const Type **intpair = TypeTuple::fields(2);
   429   intpair[0] = TypeInt::INT;
   430   intpair[1] = TypeInt::INT;
   431   TypeTuple::INT_PAIR = TypeTuple::make(2, intpair);
   433   const Type **longpair = TypeTuple::fields(2);
   434   longpair[0] = TypeLong::LONG;
   435   longpair[1] = TypeLong::LONG;
   436   TypeTuple::LONG_PAIR = TypeTuple::make(2, longpair);
   438   const Type **intccpair = TypeTuple::fields(2);
   439   intccpair[0] = TypeInt::INT;
   440   intccpair[1] = TypeInt::CC;
   441   TypeTuple::INT_CC_PAIR = TypeTuple::make(2, intccpair);
   443   const Type **longccpair = TypeTuple::fields(2);
   444   longccpair[0] = TypeLong::LONG;
   445   longccpair[1] = TypeInt::CC;
   446   TypeTuple::LONG_CC_PAIR = TypeTuple::make(2, longccpair);
   448   _const_basic_type[T_NARROWOOP]   = TypeNarrowOop::BOTTOM;
   449   _const_basic_type[T_NARROWKLASS] = Type::BOTTOM;
   450   _const_basic_type[T_BOOLEAN]     = TypeInt::BOOL;
   451   _const_basic_type[T_CHAR]        = TypeInt::CHAR;
   452   _const_basic_type[T_BYTE]        = TypeInt::BYTE;
   453   _const_basic_type[T_SHORT]       = TypeInt::SHORT;
   454   _const_basic_type[T_INT]         = TypeInt::INT;
   455   _const_basic_type[T_LONG]        = TypeLong::LONG;
   456   _const_basic_type[T_FLOAT]       = Type::FLOAT;
   457   _const_basic_type[T_DOUBLE]      = Type::DOUBLE;
   458   _const_basic_type[T_OBJECT]      = TypeInstPtr::BOTTOM;
   459   _const_basic_type[T_ARRAY]       = TypeInstPtr::BOTTOM; // there is no separate bottom for arrays
   460   _const_basic_type[T_VOID]        = TypePtr::NULL_PTR;   // reflection represents void this way
   461   _const_basic_type[T_ADDRESS]     = TypeRawPtr::BOTTOM;  // both interpreter return addresses & random raw ptrs
   462   _const_basic_type[T_CONFLICT]    = Type::BOTTOM;        // why not?
   464   _zero_type[T_NARROWOOP]   = TypeNarrowOop::NULL_PTR;
   465   _zero_type[T_NARROWKLASS] = TypeNarrowKlass::NULL_PTR;
   466   _zero_type[T_BOOLEAN]     = TypeInt::ZERO;     // false == 0
   467   _zero_type[T_CHAR]        = TypeInt::ZERO;     // '\0' == 0
   468   _zero_type[T_BYTE]        = TypeInt::ZERO;     // 0x00 == 0
   469   _zero_type[T_SHORT]       = TypeInt::ZERO;     // 0x0000 == 0
   470   _zero_type[T_INT]         = TypeInt::ZERO;
   471   _zero_type[T_LONG]        = TypeLong::ZERO;
   472   _zero_type[T_FLOAT]       = TypeF::ZERO;
   473   _zero_type[T_DOUBLE]      = TypeD::ZERO;
   474   _zero_type[T_OBJECT]      = TypePtr::NULL_PTR;
   475   _zero_type[T_ARRAY]       = TypePtr::NULL_PTR; // null array is null oop
   476   _zero_type[T_ADDRESS]     = TypePtr::NULL_PTR; // raw pointers use the same null
   477   _zero_type[T_VOID]        = Type::TOP;         // the only void value is no value at all
   479   // get_zero_type() should not happen for T_CONFLICT
   480   _zero_type[T_CONFLICT]= NULL;
   482   // Vector predefined types, it needs initialized _const_basic_type[].
   483   if (Matcher::vector_size_supported(T_BYTE,4)) {
   484     TypeVect::VECTS = TypeVect::make(T_BYTE,4);
   485   }
   486   if (Matcher::vector_size_supported(T_FLOAT,2)) {
   487     TypeVect::VECTD = TypeVect::make(T_FLOAT,2);
   488   }
   489   if (Matcher::vector_size_supported(T_FLOAT,4)) {
   490     TypeVect::VECTX = TypeVect::make(T_FLOAT,4);
   491   }
   492   if (Matcher::vector_size_supported(T_FLOAT,8)) {
   493     TypeVect::VECTY = TypeVect::make(T_FLOAT,8);
   494   }
   495   mreg2type[Op_VecS] = TypeVect::VECTS;
   496   mreg2type[Op_VecD] = TypeVect::VECTD;
   497   mreg2type[Op_VecX] = TypeVect::VECTX;
   498   mreg2type[Op_VecY] = TypeVect::VECTY;
   500   // Restore working type arena.
   501   current->set_type_arena(save);
   502   current->set_type_dict(NULL);
   503 }
   505 //------------------------------Initialize-------------------------------------
   506 void Type::Initialize(Compile* current) {
   507   assert(current->type_arena() != NULL, "must have created type arena");
   509   if (_shared_type_dict == NULL) {
   510     Initialize_shared(current);
   511   }
   513   Arena* type_arena = current->type_arena();
   515   // Create the hash-cons'ing dictionary with top-level storage allocation
   516   Dict *tdic = new (type_arena) Dict( (CmpKey)Type::cmp,(Hash)Type::uhash, type_arena, 128 );
   517   current->set_type_dict(tdic);
   519   // Transfer the shared types.
   520   DictI i(_shared_type_dict);
   521   for( ; i.test(); ++i ) {
   522     Type* t = (Type*)i._value;
   523     tdic->Insert(t,t);  // New Type, insert into Type table
   524   }
   525 }
   527 //------------------------------hashcons---------------------------------------
   528 // Do the hash-cons trick.  If the Type already exists in the type table,
   529 // delete the current Type and return the existing Type.  Otherwise stick the
   530 // current Type in the Type table.
   531 const Type *Type::hashcons(void) {
   532   debug_only(base());           // Check the assertion in Type::base().
   533   // Look up the Type in the Type dictionary
   534   Dict *tdic = type_dict();
   535   Type* old = (Type*)(tdic->Insert(this, this, false));
   536   if( old ) {                   // Pre-existing Type?
   537     if( old != this )           // Yes, this guy is not the pre-existing?
   538       delete this;              // Yes, Nuke this guy
   539     assert( old->_dual, "" );
   540     return old;                 // Return pre-existing
   541   }
   543   // Every type has a dual (to make my lattice symmetric).
   544   // Since we just discovered a new Type, compute its dual right now.
   545   assert( !_dual, "" );         // No dual yet
   546   _dual = xdual();              // Compute the dual
   547   if( cmp(this,_dual)==0 ) {    // Handle self-symmetric
   548     _dual = this;
   549     return this;
   550   }
   551   assert( !_dual->_dual, "" );  // No reverse dual yet
   552   assert( !(*tdic)[_dual], "" ); // Dual not in type system either
   553   // New Type, insert into Type table
   554   tdic->Insert((void*)_dual,(void*)_dual);
   555   ((Type*)_dual)->_dual = this; // Finish up being symmetric
   556 #ifdef ASSERT
   557   Type *dual_dual = (Type*)_dual->xdual();
   558   assert( eq(dual_dual), "xdual(xdual()) should be identity" );
   559   delete dual_dual;
   560 #endif
   561   return this;                  // Return new Type
   562 }
   564 //------------------------------eq---------------------------------------------
   565 // Structural equality check for Type representations
   566 bool Type::eq( const Type * ) const {
   567   return true;                  // Nothing else can go wrong
   568 }
   570 //------------------------------hash-------------------------------------------
   571 // Type-specific hashing function.
   572 int Type::hash(void) const {
   573   return _base;
   574 }
   576 //------------------------------is_finite--------------------------------------
   577 // Has a finite value
   578 bool Type::is_finite() const {
   579   return false;
   580 }
   582 //------------------------------is_nan-----------------------------------------
   583 // Is not a number (NaN)
   584 bool Type::is_nan()    const {
   585   return false;
   586 }
   588 //----------------------interface_vs_oop---------------------------------------
   589 #ifdef ASSERT
   590 bool Type::interface_vs_oop_helper(const Type *t) const {
   591   bool result = false;
   593   const TypePtr* this_ptr = this->make_ptr(); // In case it is narrow_oop
   594   const TypePtr*    t_ptr =    t->make_ptr();
   595   if( this_ptr == NULL || t_ptr == NULL )
   596     return result;
   598   const TypeInstPtr* this_inst = this_ptr->isa_instptr();
   599   const TypeInstPtr*    t_inst =    t_ptr->isa_instptr();
   600   if( this_inst && this_inst->is_loaded() && t_inst && t_inst->is_loaded() ) {
   601     bool this_interface = this_inst->klass()->is_interface();
   602     bool    t_interface =    t_inst->klass()->is_interface();
   603     result = this_interface ^ t_interface;
   604   }
   606   return result;
   607 }
   609 bool Type::interface_vs_oop(const Type *t) const {
   610   if (interface_vs_oop_helper(t)) {
   611     return true;
   612   }
   613   // Now check the speculative parts as well
   614   const TypeOopPtr* this_spec = isa_oopptr() != NULL ? isa_oopptr()->speculative() : NULL;
   615   const TypeOopPtr* t_spec = t->isa_oopptr() != NULL ? t->isa_oopptr()->speculative() : NULL;
   616   if (this_spec != NULL && t_spec != NULL) {
   617     if (this_spec->interface_vs_oop_helper(t_spec)) {
   618       return true;
   619     }
   620     return false;
   621   }
   622   if (this_spec != NULL && this_spec->interface_vs_oop_helper(t)) {
   623     return true;
   624   }
   625   if (t_spec != NULL && interface_vs_oop_helper(t_spec)) {
   626     return true;
   627   }
   628   return false;
   629 }
   631 #endif
   633 //------------------------------meet-------------------------------------------
   634 // Compute the MEET of two types.  NOT virtual.  It enforces that meet is
   635 // commutative and the lattice is symmetric.
   636 const Type *Type::meet( const Type *t ) const {
   637   if (isa_narrowoop() && t->isa_narrowoop()) {
   638     const Type* result = make_ptr()->meet(t->make_ptr());
   639     return result->make_narrowoop();
   640   }
   641   if (isa_narrowklass() && t->isa_narrowklass()) {
   642     const Type* result = make_ptr()->meet(t->make_ptr());
   643     return result->make_narrowklass();
   644   }
   646   const Type *mt = xmeet(t);
   647   if (isa_narrowoop() || t->isa_narrowoop()) return mt;
   648   if (isa_narrowklass() || t->isa_narrowklass()) return mt;
   649 #ifdef ASSERT
   650   assert( mt == t->xmeet(this), "meet not commutative" );
   651   const Type* dual_join = mt->_dual;
   652   const Type *t2t    = dual_join->xmeet(t->_dual);
   653   const Type *t2this = dual_join->xmeet(   _dual);
   655   // Interface meet Oop is Not Symmetric:
   656   // Interface:AnyNull meet Oop:AnyNull == Interface:AnyNull
   657   // Interface:NotNull meet Oop:NotNull == java/lang/Object:NotNull
   659   if( !interface_vs_oop(t) && (t2t != t->_dual || t2this != _dual) ) {
   660     tty->print_cr("=== Meet Not Symmetric ===");
   661     tty->print("t   =                   ");         t->dump(); tty->cr();
   662     tty->print("this=                   ");            dump(); tty->cr();
   663     tty->print("mt=(t meet this)=       ");        mt->dump(); tty->cr();
   665     tty->print("t_dual=                 ");  t->_dual->dump(); tty->cr();
   666     tty->print("this_dual=              ");     _dual->dump(); tty->cr();
   667     tty->print("mt_dual=                "); mt->_dual->dump(); tty->cr();
   669     tty->print("mt_dual meet t_dual=    "); t2t      ->dump(); tty->cr();
   670     tty->print("mt_dual meet this_dual= "); t2this   ->dump(); tty->cr();
   672     fatal("meet not symmetric" );
   673   }
   674 #endif
   675   return mt;
   676 }
   678 //------------------------------xmeet------------------------------------------
   679 // Compute the MEET of two types.  It returns a new Type object.
   680 const Type *Type::xmeet( const Type *t ) const {
   681   // Perform a fast test for common case; meeting the same types together.
   682   if( this == t ) return this;  // Meeting same type-rep?
   684   // Meeting TOP with anything?
   685   if( _base == Top ) return t;
   687   // Meeting BOTTOM with anything?
   688   if( _base == Bottom ) return BOTTOM;
   690   // Current "this->_base" is one of: Bad, Multi, Control, Top,
   691   // Abio, Abstore, Floatxxx, Doublexxx, Bottom, lastype.
   692   switch (t->base()) {  // Switch on original type
   694   // Cut in half the number of cases I must handle.  Only need cases for when
   695   // the given enum "t->type" is less than or equal to the local enum "type".
   696   case FloatCon:
   697   case DoubleCon:
   698   case Int:
   699   case Long:
   700     return t->xmeet(this);
   702   case OopPtr:
   703     return t->xmeet(this);
   705   case InstPtr:
   706     return t->xmeet(this);
   708   case MetadataPtr:
   709   case KlassPtr:
   710     return t->xmeet(this);
   712   case AryPtr:
   713     return t->xmeet(this);
   715   case NarrowOop:
   716     return t->xmeet(this);
   718   case NarrowKlass:
   719     return t->xmeet(this);
   721   case Bad:                     // Type check
   722   default:                      // Bogus type not in lattice
   723     typerr(t);
   724     return Type::BOTTOM;
   726   case Bottom:                  // Ye Olde Default
   727     return t;
   729   case FloatTop:
   730     if( _base == FloatTop ) return this;
   731   case FloatBot:                // Float
   732     if( _base == FloatBot || _base == FloatTop ) return FLOAT;
   733     if( _base == DoubleTop || _base == DoubleBot ) return Type::BOTTOM;
   734     typerr(t);
   735     return Type::BOTTOM;
   737   case DoubleTop:
   738     if( _base == DoubleTop ) return this;
   739   case DoubleBot:               // Double
   740     if( _base == DoubleBot || _base == DoubleTop ) return DOUBLE;
   741     if( _base == FloatTop || _base == FloatBot ) return Type::BOTTOM;
   742     typerr(t);
   743     return Type::BOTTOM;
   745   // These next few cases must match exactly or it is a compile-time error.
   746   case Control:                 // Control of code
   747   case Abio:                    // State of world outside of program
   748   case Memory:
   749     if( _base == t->_base )  return this;
   750     typerr(t);
   751     return Type::BOTTOM;
   753   case Top:                     // Top of the lattice
   754     return this;
   755   }
   757   // The type is unchanged
   758   return this;
   759 }
   761 //-----------------------------filter------------------------------------------
   762 const Type *Type::filter( const Type *kills ) const {
   763   const Type* ft = join(kills);
   764   if (ft->empty())
   765     return Type::TOP;           // Canonical empty value
   766   return ft;
   767 }
   769 //------------------------------xdual------------------------------------------
   770 // Compute dual right now.
   771 const Type::TYPES Type::dual_type[Type::lastype] = {
   772   Bad,          // Bad
   773   Control,      // Control
   774   Bottom,       // Top
   775   Bad,          // Int - handled in v-call
   776   Bad,          // Long - handled in v-call
   777   Half,         // Half
   778   Bad,          // NarrowOop - handled in v-call
   779   Bad,          // NarrowKlass - handled in v-call
   781   Bad,          // Tuple - handled in v-call
   782   Bad,          // Array - handled in v-call
   783   Bad,          // VectorS - handled in v-call
   784   Bad,          // VectorD - handled in v-call
   785   Bad,          // VectorX - handled in v-call
   786   Bad,          // VectorY - handled in v-call
   788   Bad,          // AnyPtr - handled in v-call
   789   Bad,          // RawPtr - handled in v-call
   790   Bad,          // OopPtr - handled in v-call
   791   Bad,          // InstPtr - handled in v-call
   792   Bad,          // AryPtr - handled in v-call
   794   Bad,          //  MetadataPtr - handled in v-call
   795   Bad,          // KlassPtr - handled in v-call
   797   Bad,          // Function - handled in v-call
   798   Abio,         // Abio
   799   Return_Address,// Return_Address
   800   Memory,       // Memory
   801   FloatBot,     // FloatTop
   802   FloatCon,     // FloatCon
   803   FloatTop,     // FloatBot
   804   DoubleBot,    // DoubleTop
   805   DoubleCon,    // DoubleCon
   806   DoubleTop,    // DoubleBot
   807   Top           // Bottom
   808 };
   810 const Type *Type::xdual() const {
   811   // Note: the base() accessor asserts the sanity of _base.
   812   assert(_type_info[base()].dual_type != Bad, "implement with v-call");
   813   return new Type(_type_info[_base].dual_type);
   814 }
   816 //------------------------------has_memory-------------------------------------
   817 bool Type::has_memory() const {
   818   Type::TYPES tx = base();
   819   if (tx == Memory) return true;
   820   if (tx == Tuple) {
   821     const TypeTuple *t = is_tuple();
   822     for (uint i=0; i < t->cnt(); i++) {
   823       tx = t->field_at(i)->base();
   824       if (tx == Memory)  return true;
   825     }
   826   }
   827   return false;
   828 }
   830 #ifndef PRODUCT
   831 //------------------------------dump2------------------------------------------
   832 void Type::dump2( Dict &d, uint depth, outputStream *st ) const {
   833   st->print(_type_info[_base].msg);
   834 }
   836 //------------------------------dump-------------------------------------------
   837 void Type::dump_on(outputStream *st) const {
   838   ResourceMark rm;
   839   Dict d(cmpkey,hashkey);       // Stop recursive type dumping
   840   dump2(d,1, st);
   841   if (is_ptr_to_narrowoop()) {
   842     st->print(" [narrow]");
   843   } else if (is_ptr_to_narrowklass()) {
   844     st->print(" [narrowklass]");
   845   }
   846 }
   847 #endif
   849 //------------------------------singleton--------------------------------------
   850 // TRUE if Type is a singleton type, FALSE otherwise.   Singletons are simple
   851 // constants (Ldi nodes).  Singletons are integer, float or double constants.
   852 bool Type::singleton(void) const {
   853   return _base == Top || _base == Half;
   854 }
   856 //------------------------------empty------------------------------------------
   857 // TRUE if Type is a type with no values, FALSE otherwise.
   858 bool Type::empty(void) const {
   859   switch (_base) {
   860   case DoubleTop:
   861   case FloatTop:
   862   case Top:
   863     return true;
   865   case Half:
   866   case Abio:
   867   case Return_Address:
   868   case Memory:
   869   case Bottom:
   870   case FloatBot:
   871   case DoubleBot:
   872     return false;  // never a singleton, therefore never empty
   873   }
   875   ShouldNotReachHere();
   876   return false;
   877 }
   879 //------------------------------dump_stats-------------------------------------
   880 // Dump collected statistics to stderr
   881 #ifndef PRODUCT
   882 void Type::dump_stats() {
   883   tty->print("Types made: %d\n", type_dict()->Size());
   884 }
   885 #endif
   887 //------------------------------typerr-----------------------------------------
   888 void Type::typerr( const Type *t ) const {
   889 #ifndef PRODUCT
   890   tty->print("\nError mixing types: ");
   891   dump();
   892   tty->print(" and ");
   893   t->dump();
   894   tty->print("\n");
   895 #endif
   896   ShouldNotReachHere();
   897 }
   900 //=============================================================================
   901 // Convenience common pre-built types.
   902 const TypeF *TypeF::ZERO;       // Floating point zero
   903 const TypeF *TypeF::ONE;        // Floating point one
   905 //------------------------------make-------------------------------------------
   906 // Create a float constant
   907 const TypeF *TypeF::make(float f) {
   908   return (TypeF*)(new TypeF(f))->hashcons();
   909 }
   911 //------------------------------meet-------------------------------------------
   912 // Compute the MEET of two types.  It returns a new Type object.
   913 const Type *TypeF::xmeet( const Type *t ) const {
   914   // Perform a fast test for common case; meeting the same types together.
   915   if( this == t ) return this;  // Meeting same type-rep?
   917   // Current "this->_base" is FloatCon
   918   switch (t->base()) {          // Switch on original type
   919   case AnyPtr:                  // Mixing with oops happens when javac
   920   case RawPtr:                  // reuses local variables
   921   case OopPtr:
   922   case InstPtr:
   923   case AryPtr:
   924   case MetadataPtr:
   925   case KlassPtr:
   926   case NarrowOop:
   927   case NarrowKlass:
   928   case Int:
   929   case Long:
   930   case DoubleTop:
   931   case DoubleCon:
   932   case DoubleBot:
   933   case Bottom:                  // Ye Olde Default
   934     return Type::BOTTOM;
   936   case FloatBot:
   937     return t;
   939   default:                      // All else is a mistake
   940     typerr(t);
   942   case FloatCon:                // Float-constant vs Float-constant?
   943     if( jint_cast(_f) != jint_cast(t->getf()) )         // unequal constants?
   944                                 // must compare bitwise as positive zero, negative zero and NaN have
   945                                 // all the same representation in C++
   946       return FLOAT;             // Return generic float
   947                                 // Equal constants
   948   case Top:
   949   case FloatTop:
   950     break;                      // Return the float constant
   951   }
   952   return this;                  // Return the float constant
   953 }
   955 //------------------------------xdual------------------------------------------
   956 // Dual: symmetric
   957 const Type *TypeF::xdual() const {
   958   return this;
   959 }
   961 //------------------------------eq---------------------------------------------
   962 // Structural equality check for Type representations
   963 bool TypeF::eq( const Type *t ) const {
   964   if( g_isnan(_f) ||
   965       g_isnan(t->getf()) ) {
   966     // One or both are NANs.  If both are NANs return true, else false.
   967     return (g_isnan(_f) && g_isnan(t->getf()));
   968   }
   969   if (_f == t->getf()) {
   970     // (NaN is impossible at this point, since it is not equal even to itself)
   971     if (_f == 0.0) {
   972       // difference between positive and negative zero
   973       if (jint_cast(_f) != jint_cast(t->getf()))  return false;
   974     }
   975     return true;
   976   }
   977   return false;
   978 }
   980 //------------------------------hash-------------------------------------------
   981 // Type-specific hashing function.
   982 int TypeF::hash(void) const {
   983   return *(int*)(&_f);
   984 }
   986 //------------------------------is_finite--------------------------------------
   987 // Has a finite value
   988 bool TypeF::is_finite() const {
   989   return g_isfinite(getf()) != 0;
   990 }
   992 //------------------------------is_nan-----------------------------------------
   993 // Is not a number (NaN)
   994 bool TypeF::is_nan()    const {
   995   return g_isnan(getf()) != 0;
   996 }
   998 //------------------------------dump2------------------------------------------
   999 // Dump float constant Type
  1000 #ifndef PRODUCT
  1001 void TypeF::dump2( Dict &d, uint depth, outputStream *st ) const {
  1002   Type::dump2(d,depth, st);
  1003   st->print("%f", _f);
  1005 #endif
  1007 //------------------------------singleton--------------------------------------
  1008 // TRUE if Type is a singleton type, FALSE otherwise.   Singletons are simple
  1009 // constants (Ldi nodes).  Singletons are integer, float or double constants
  1010 // or a single symbol.
  1011 bool TypeF::singleton(void) const {
  1012   return true;                  // Always a singleton
  1015 bool TypeF::empty(void) const {
  1016   return false;                 // always exactly a singleton
  1019 //=============================================================================
  1020 // Convenience common pre-built types.
  1021 const TypeD *TypeD::ZERO;       // Floating point zero
  1022 const TypeD *TypeD::ONE;        // Floating point one
  1024 //------------------------------make-------------------------------------------
  1025 const TypeD *TypeD::make(double d) {
  1026   return (TypeD*)(new TypeD(d))->hashcons();
  1029 //------------------------------meet-------------------------------------------
  1030 // Compute the MEET of two types.  It returns a new Type object.
  1031 const Type *TypeD::xmeet( const Type *t ) const {
  1032   // Perform a fast test for common case; meeting the same types together.
  1033   if( this == t ) return this;  // Meeting same type-rep?
  1035   // Current "this->_base" is DoubleCon
  1036   switch (t->base()) {          // Switch on original type
  1037   case AnyPtr:                  // Mixing with oops happens when javac
  1038   case RawPtr:                  // reuses local variables
  1039   case OopPtr:
  1040   case InstPtr:
  1041   case AryPtr:
  1042   case MetadataPtr:
  1043   case KlassPtr:
  1044   case NarrowOop:
  1045   case NarrowKlass:
  1046   case Int:
  1047   case Long:
  1048   case FloatTop:
  1049   case FloatCon:
  1050   case FloatBot:
  1051   case Bottom:                  // Ye Olde Default
  1052     return Type::BOTTOM;
  1054   case DoubleBot:
  1055     return t;
  1057   default:                      // All else is a mistake
  1058     typerr(t);
  1060   case DoubleCon:               // Double-constant vs Double-constant?
  1061     if( jlong_cast(_d) != jlong_cast(t->getd()) )       // unequal constants? (see comment in TypeF::xmeet)
  1062       return DOUBLE;            // Return generic double
  1063   case Top:
  1064   case DoubleTop:
  1065     break;
  1067   return this;                  // Return the double constant
  1070 //------------------------------xdual------------------------------------------
  1071 // Dual: symmetric
  1072 const Type *TypeD::xdual() const {
  1073   return this;
  1076 //------------------------------eq---------------------------------------------
  1077 // Structural equality check for Type representations
  1078 bool TypeD::eq( const Type *t ) const {
  1079   if( g_isnan(_d) ||
  1080       g_isnan(t->getd()) ) {
  1081     // One or both are NANs.  If both are NANs return true, else false.
  1082     return (g_isnan(_d) && g_isnan(t->getd()));
  1084   if (_d == t->getd()) {
  1085     // (NaN is impossible at this point, since it is not equal even to itself)
  1086     if (_d == 0.0) {
  1087       // difference between positive and negative zero
  1088       if (jlong_cast(_d) != jlong_cast(t->getd()))  return false;
  1090     return true;
  1092   return false;
  1095 //------------------------------hash-------------------------------------------
  1096 // Type-specific hashing function.
  1097 int TypeD::hash(void) const {
  1098   return *(int*)(&_d);
  1101 //------------------------------is_finite--------------------------------------
  1102 // Has a finite value
  1103 bool TypeD::is_finite() const {
  1104   return g_isfinite(getd()) != 0;
  1107 //------------------------------is_nan-----------------------------------------
  1108 // Is not a number (NaN)
  1109 bool TypeD::is_nan()    const {
  1110   return g_isnan(getd()) != 0;
  1113 //------------------------------dump2------------------------------------------
  1114 // Dump double constant Type
  1115 #ifndef PRODUCT
  1116 void TypeD::dump2( Dict &d, uint depth, outputStream *st ) const {
  1117   Type::dump2(d,depth,st);
  1118   st->print("%f", _d);
  1120 #endif
  1122 //------------------------------singleton--------------------------------------
  1123 // TRUE if Type is a singleton type, FALSE otherwise.   Singletons are simple
  1124 // constants (Ldi nodes).  Singletons are integer, float or double constants
  1125 // or a single symbol.
  1126 bool TypeD::singleton(void) const {
  1127   return true;                  // Always a singleton
  1130 bool TypeD::empty(void) const {
  1131   return false;                 // always exactly a singleton
  1134 //=============================================================================
  1135 // Convience common pre-built types.
  1136 const TypeInt *TypeInt::MINUS_1;// -1
  1137 const TypeInt *TypeInt::ZERO;   // 0
  1138 const TypeInt *TypeInt::ONE;    // 1
  1139 const TypeInt *TypeInt::BOOL;   // 0 or 1, FALSE or TRUE.
  1140 const TypeInt *TypeInt::CC;     // -1,0 or 1, condition codes
  1141 const TypeInt *TypeInt::CC_LT;  // [-1]  == MINUS_1
  1142 const TypeInt *TypeInt::CC_GT;  // [1]   == ONE
  1143 const TypeInt *TypeInt::CC_EQ;  // [0]   == ZERO
  1144 const TypeInt *TypeInt::CC_LE;  // [-1,0]
  1145 const TypeInt *TypeInt::CC_GE;  // [0,1] == BOOL (!)
  1146 const TypeInt *TypeInt::BYTE;   // Bytes, -128 to 127
  1147 const TypeInt *TypeInt::UBYTE;  // Unsigned Bytes, 0 to 255
  1148 const TypeInt *TypeInt::CHAR;   // Java chars, 0-65535
  1149 const TypeInt *TypeInt::SHORT;  // Java shorts, -32768-32767
  1150 const TypeInt *TypeInt::POS;    // Positive 32-bit integers or zero
  1151 const TypeInt *TypeInt::POS1;   // Positive 32-bit integers
  1152 const TypeInt *TypeInt::INT;    // 32-bit integers
  1153 const TypeInt *TypeInt::SYMINT; // symmetric range [-max_jint..max_jint]
  1155 //------------------------------TypeInt----------------------------------------
  1156 TypeInt::TypeInt( jint lo, jint hi, int w ) : Type(Int), _lo(lo), _hi(hi), _widen(w) {
  1159 //------------------------------make-------------------------------------------
  1160 const TypeInt *TypeInt::make( jint lo ) {
  1161   return (TypeInt*)(new TypeInt(lo,lo,WidenMin))->hashcons();
  1164 static int normalize_int_widen( jint lo, jint hi, int w ) {
  1165   // Certain normalizations keep us sane when comparing types.
  1166   // The 'SMALLINT' covers constants and also CC and its relatives.
  1167   if (lo <= hi) {
  1168     if ((juint)(hi - lo) <= SMALLINT)  w = Type::WidenMin;
  1169     if ((juint)(hi - lo) >= max_juint) w = Type::WidenMax; // TypeInt::INT
  1170   } else {
  1171     if ((juint)(lo - hi) <= SMALLINT)  w = Type::WidenMin;
  1172     if ((juint)(lo - hi) >= max_juint) w = Type::WidenMin; // dual TypeInt::INT
  1174   return w;
  1177 const TypeInt *TypeInt::make( jint lo, jint hi, int w ) {
  1178   w = normalize_int_widen(lo, hi, w);
  1179   return (TypeInt*)(new TypeInt(lo,hi,w))->hashcons();
  1182 //------------------------------meet-------------------------------------------
  1183 // Compute the MEET of two types.  It returns a new Type representation object
  1184 // with reference count equal to the number of Types pointing at it.
  1185 // Caller should wrap a Types around it.
  1186 const Type *TypeInt::xmeet( const Type *t ) const {
  1187   // Perform a fast test for common case; meeting the same types together.
  1188   if( this == t ) return this;  // Meeting same type?
  1190   // Currently "this->_base" is a TypeInt
  1191   switch (t->base()) {          // Switch on original type
  1192   case AnyPtr:                  // Mixing with oops happens when javac
  1193   case RawPtr:                  // reuses local variables
  1194   case OopPtr:
  1195   case InstPtr:
  1196   case AryPtr:
  1197   case MetadataPtr:
  1198   case KlassPtr:
  1199   case NarrowOop:
  1200   case NarrowKlass:
  1201   case Long:
  1202   case FloatTop:
  1203   case FloatCon:
  1204   case FloatBot:
  1205   case DoubleTop:
  1206   case DoubleCon:
  1207   case DoubleBot:
  1208   case Bottom:                  // Ye Olde Default
  1209     return Type::BOTTOM;
  1210   default:                      // All else is a mistake
  1211     typerr(t);
  1212   case Top:                     // No change
  1213     return this;
  1214   case Int:                     // Int vs Int?
  1215     break;
  1218   // Expand covered set
  1219   const TypeInt *r = t->is_int();
  1220   return make( MIN2(_lo,r->_lo), MAX2(_hi,r->_hi), MAX2(_widen,r->_widen) );
  1223 //------------------------------xdual------------------------------------------
  1224 // Dual: reverse hi & lo; flip widen
  1225 const Type *TypeInt::xdual() const {
  1226   int w = normalize_int_widen(_hi,_lo, WidenMax-_widen);
  1227   return new TypeInt(_hi,_lo,w);
  1230 //------------------------------widen------------------------------------------
  1231 // Only happens for optimistic top-down optimizations.
  1232 const Type *TypeInt::widen( const Type *old, const Type* limit ) const {
  1233   // Coming from TOP or such; no widening
  1234   if( old->base() != Int ) return this;
  1235   const TypeInt *ot = old->is_int();
  1237   // If new guy is equal to old guy, no widening
  1238   if( _lo == ot->_lo && _hi == ot->_hi )
  1239     return old;
  1241   // If new guy contains old, then we widened
  1242   if( _lo <= ot->_lo && _hi >= ot->_hi ) {
  1243     // New contains old
  1244     // If new guy is already wider than old, no widening
  1245     if( _widen > ot->_widen ) return this;
  1246     // If old guy was a constant, do not bother
  1247     if (ot->_lo == ot->_hi)  return this;
  1248     // Now widen new guy.
  1249     // Check for widening too far
  1250     if (_widen == WidenMax) {
  1251       int max = max_jint;
  1252       int min = min_jint;
  1253       if (limit->isa_int()) {
  1254         max = limit->is_int()->_hi;
  1255         min = limit->is_int()->_lo;
  1257       if (min < _lo && _hi < max) {
  1258         // If neither endpoint is extremal yet, push out the endpoint
  1259         // which is closer to its respective limit.
  1260         if (_lo >= 0 ||                 // easy common case
  1261             (juint)(_lo - min) >= (juint)(max - _hi)) {
  1262           // Try to widen to an unsigned range type of 31 bits:
  1263           return make(_lo, max, WidenMax);
  1264         } else {
  1265           return make(min, _hi, WidenMax);
  1268       return TypeInt::INT;
  1270     // Returned widened new guy
  1271     return make(_lo,_hi,_widen+1);
  1274   // If old guy contains new, then we probably widened too far & dropped to
  1275   // bottom.  Return the wider fellow.
  1276   if ( ot->_lo <= _lo && ot->_hi >= _hi )
  1277     return old;
  1279   //fatal("Integer value range is not subset");
  1280   //return this;
  1281   return TypeInt::INT;
  1284 //------------------------------narrow---------------------------------------
  1285 // Only happens for pessimistic optimizations.
  1286 const Type *TypeInt::narrow( const Type *old ) const {
  1287   if (_lo >= _hi)  return this;   // already narrow enough
  1288   if (old == NULL)  return this;
  1289   const TypeInt* ot = old->isa_int();
  1290   if (ot == NULL)  return this;
  1291   jint olo = ot->_lo;
  1292   jint ohi = ot->_hi;
  1294   // If new guy is equal to old guy, no narrowing
  1295   if (_lo == olo && _hi == ohi)  return old;
  1297   // If old guy was maximum range, allow the narrowing
  1298   if (olo == min_jint && ohi == max_jint)  return this;
  1300   if (_lo < olo || _hi > ohi)
  1301     return this;                // doesn't narrow; pretty wierd
  1303   // The new type narrows the old type, so look for a "death march".
  1304   // See comments on PhaseTransform::saturate.
  1305   juint nrange = _hi - _lo;
  1306   juint orange = ohi - olo;
  1307   if (nrange < max_juint - 1 && nrange > (orange >> 1) + (SMALLINT*2)) {
  1308     // Use the new type only if the range shrinks a lot.
  1309     // We do not want the optimizer computing 2^31 point by point.
  1310     return old;
  1313   return this;
  1316 //-----------------------------filter------------------------------------------
  1317 const Type *TypeInt::filter( const Type *kills ) const {
  1318   const TypeInt* ft = join(kills)->isa_int();
  1319   if (ft == NULL || ft->empty())
  1320     return Type::TOP;           // Canonical empty value
  1321   if (ft->_widen < this->_widen) {
  1322     // Do not allow the value of kill->_widen to affect the outcome.
  1323     // The widen bits must be allowed to run freely through the graph.
  1324     ft = TypeInt::make(ft->_lo, ft->_hi, this->_widen);
  1326   return ft;
  1329 //------------------------------eq---------------------------------------------
  1330 // Structural equality check for Type representations
  1331 bool TypeInt::eq( const Type *t ) const {
  1332   const TypeInt *r = t->is_int(); // Handy access
  1333   return r->_lo == _lo && r->_hi == _hi && r->_widen == _widen;
  1336 //------------------------------hash-------------------------------------------
  1337 // Type-specific hashing function.
  1338 int TypeInt::hash(void) const {
  1339   return _lo+_hi+_widen+(int)Type::Int;
  1342 //------------------------------is_finite--------------------------------------
  1343 // Has a finite value
  1344 bool TypeInt::is_finite() const {
  1345   return true;
  1348 //------------------------------dump2------------------------------------------
  1349 // Dump TypeInt
  1350 #ifndef PRODUCT
  1351 static const char* intname(char* buf, jint n) {
  1352   if (n == min_jint)
  1353     return "min";
  1354   else if (n < min_jint + 10000)
  1355     sprintf(buf, "min+" INT32_FORMAT, n - min_jint);
  1356   else if (n == max_jint)
  1357     return "max";
  1358   else if (n > max_jint - 10000)
  1359     sprintf(buf, "max-" INT32_FORMAT, max_jint - n);
  1360   else
  1361     sprintf(buf, INT32_FORMAT, n);
  1362   return buf;
  1365 void TypeInt::dump2( Dict &d, uint depth, outputStream *st ) const {
  1366   char buf[40], buf2[40];
  1367   if (_lo == min_jint && _hi == max_jint)
  1368     st->print("int");
  1369   else if (is_con())
  1370     st->print("int:%s", intname(buf, get_con()));
  1371   else if (_lo == BOOL->_lo && _hi == BOOL->_hi)
  1372     st->print("bool");
  1373   else if (_lo == BYTE->_lo && _hi == BYTE->_hi)
  1374     st->print("byte");
  1375   else if (_lo == CHAR->_lo && _hi == CHAR->_hi)
  1376     st->print("char");
  1377   else if (_lo == SHORT->_lo && _hi == SHORT->_hi)
  1378     st->print("short");
  1379   else if (_hi == max_jint)
  1380     st->print("int:>=%s", intname(buf, _lo));
  1381   else if (_lo == min_jint)
  1382     st->print("int:<=%s", intname(buf, _hi));
  1383   else
  1384     st->print("int:%s..%s", intname(buf, _lo), intname(buf2, _hi));
  1386   if (_widen != 0 && this != TypeInt::INT)
  1387     st->print(":%.*s", _widen, "wwww");
  1389 #endif
  1391 //------------------------------singleton--------------------------------------
  1392 // TRUE if Type is a singleton type, FALSE otherwise.   Singletons are simple
  1393 // constants.
  1394 bool TypeInt::singleton(void) const {
  1395   return _lo >= _hi;
  1398 bool TypeInt::empty(void) const {
  1399   return _lo > _hi;
  1402 //=============================================================================
  1403 // Convenience common pre-built types.
  1404 const TypeLong *TypeLong::MINUS_1;// -1
  1405 const TypeLong *TypeLong::ZERO; // 0
  1406 const TypeLong *TypeLong::ONE;  // 1
  1407 const TypeLong *TypeLong::POS;  // >=0
  1408 const TypeLong *TypeLong::LONG; // 64-bit integers
  1409 const TypeLong *TypeLong::INT;  // 32-bit subrange
  1410 const TypeLong *TypeLong::UINT; // 32-bit unsigned subrange
  1412 //------------------------------TypeLong---------------------------------------
  1413 TypeLong::TypeLong( jlong lo, jlong hi, int w ) : Type(Long), _lo(lo), _hi(hi), _widen(w) {
  1416 //------------------------------make-------------------------------------------
  1417 const TypeLong *TypeLong::make( jlong lo ) {
  1418   return (TypeLong*)(new TypeLong(lo,lo,WidenMin))->hashcons();
  1421 static int normalize_long_widen( jlong lo, jlong hi, int w ) {
  1422   // Certain normalizations keep us sane when comparing types.
  1423   // The 'SMALLINT' covers constants.
  1424   if (lo <= hi) {
  1425     if ((julong)(hi - lo) <= SMALLINT)   w = Type::WidenMin;
  1426     if ((julong)(hi - lo) >= max_julong) w = Type::WidenMax; // TypeLong::LONG
  1427   } else {
  1428     if ((julong)(lo - hi) <= SMALLINT)   w = Type::WidenMin;
  1429     if ((julong)(lo - hi) >= max_julong) w = Type::WidenMin; // dual TypeLong::LONG
  1431   return w;
  1434 const TypeLong *TypeLong::make( jlong lo, jlong hi, int w ) {
  1435   w = normalize_long_widen(lo, hi, w);
  1436   return (TypeLong*)(new TypeLong(lo,hi,w))->hashcons();
  1440 //------------------------------meet-------------------------------------------
  1441 // Compute the MEET of two types.  It returns a new Type representation object
  1442 // with reference count equal to the number of Types pointing at it.
  1443 // Caller should wrap a Types around it.
  1444 const Type *TypeLong::xmeet( const Type *t ) const {
  1445   // Perform a fast test for common case; meeting the same types together.
  1446   if( this == t ) return this;  // Meeting same type?
  1448   // Currently "this->_base" is a TypeLong
  1449   switch (t->base()) {          // Switch on original type
  1450   case AnyPtr:                  // Mixing with oops happens when javac
  1451   case RawPtr:                  // reuses local variables
  1452   case OopPtr:
  1453   case InstPtr:
  1454   case AryPtr:
  1455   case MetadataPtr:
  1456   case KlassPtr:
  1457   case NarrowOop:
  1458   case NarrowKlass:
  1459   case Int:
  1460   case FloatTop:
  1461   case FloatCon:
  1462   case FloatBot:
  1463   case DoubleTop:
  1464   case DoubleCon:
  1465   case DoubleBot:
  1466   case Bottom:                  // Ye Olde Default
  1467     return Type::BOTTOM;
  1468   default:                      // All else is a mistake
  1469     typerr(t);
  1470   case Top:                     // No change
  1471     return this;
  1472   case Long:                    // Long vs Long?
  1473     break;
  1476   // Expand covered set
  1477   const TypeLong *r = t->is_long(); // Turn into a TypeLong
  1478   return make( MIN2(_lo,r->_lo), MAX2(_hi,r->_hi), MAX2(_widen,r->_widen) );
  1481 //------------------------------xdual------------------------------------------
  1482 // Dual: reverse hi & lo; flip widen
  1483 const Type *TypeLong::xdual() const {
  1484   int w = normalize_long_widen(_hi,_lo, WidenMax-_widen);
  1485   return new TypeLong(_hi,_lo,w);
  1488 //------------------------------widen------------------------------------------
  1489 // Only happens for optimistic top-down optimizations.
  1490 const Type *TypeLong::widen( const Type *old, const Type* limit ) const {
  1491   // Coming from TOP or such; no widening
  1492   if( old->base() != Long ) return this;
  1493   const TypeLong *ot = old->is_long();
  1495   // If new guy is equal to old guy, no widening
  1496   if( _lo == ot->_lo && _hi == ot->_hi )
  1497     return old;
  1499   // If new guy contains old, then we widened
  1500   if( _lo <= ot->_lo && _hi >= ot->_hi ) {
  1501     // New contains old
  1502     // If new guy is already wider than old, no widening
  1503     if( _widen > ot->_widen ) return this;
  1504     // If old guy was a constant, do not bother
  1505     if (ot->_lo == ot->_hi)  return this;
  1506     // Now widen new guy.
  1507     // Check for widening too far
  1508     if (_widen == WidenMax) {
  1509       jlong max = max_jlong;
  1510       jlong min = min_jlong;
  1511       if (limit->isa_long()) {
  1512         max = limit->is_long()->_hi;
  1513         min = limit->is_long()->_lo;
  1515       if (min < _lo && _hi < max) {
  1516         // If neither endpoint is extremal yet, push out the endpoint
  1517         // which is closer to its respective limit.
  1518         if (_lo >= 0 ||                 // easy common case
  1519             (julong)(_lo - min) >= (julong)(max - _hi)) {
  1520           // Try to widen to an unsigned range type of 32/63 bits:
  1521           if (max >= max_juint && _hi < max_juint)
  1522             return make(_lo, max_juint, WidenMax);
  1523           else
  1524             return make(_lo, max, WidenMax);
  1525         } else {
  1526           return make(min, _hi, WidenMax);
  1529       return TypeLong::LONG;
  1531     // Returned widened new guy
  1532     return make(_lo,_hi,_widen+1);
  1535   // If old guy contains new, then we probably widened too far & dropped to
  1536   // bottom.  Return the wider fellow.
  1537   if ( ot->_lo <= _lo && ot->_hi >= _hi )
  1538     return old;
  1540   //  fatal("Long value range is not subset");
  1541   // return this;
  1542   return TypeLong::LONG;
  1545 //------------------------------narrow----------------------------------------
  1546 // Only happens for pessimistic optimizations.
  1547 const Type *TypeLong::narrow( const Type *old ) const {
  1548   if (_lo >= _hi)  return this;   // already narrow enough
  1549   if (old == NULL)  return this;
  1550   const TypeLong* ot = old->isa_long();
  1551   if (ot == NULL)  return this;
  1552   jlong olo = ot->_lo;
  1553   jlong ohi = ot->_hi;
  1555   // If new guy is equal to old guy, no narrowing
  1556   if (_lo == olo && _hi == ohi)  return old;
  1558   // If old guy was maximum range, allow the narrowing
  1559   if (olo == min_jlong && ohi == max_jlong)  return this;
  1561   if (_lo < olo || _hi > ohi)
  1562     return this;                // doesn't narrow; pretty wierd
  1564   // The new type narrows the old type, so look for a "death march".
  1565   // See comments on PhaseTransform::saturate.
  1566   julong nrange = _hi - _lo;
  1567   julong orange = ohi - olo;
  1568   if (nrange < max_julong - 1 && nrange > (orange >> 1) + (SMALLINT*2)) {
  1569     // Use the new type only if the range shrinks a lot.
  1570     // We do not want the optimizer computing 2^31 point by point.
  1571     return old;
  1574   return this;
  1577 //-----------------------------filter------------------------------------------
  1578 const Type *TypeLong::filter( const Type *kills ) const {
  1579   const TypeLong* ft = join(kills)->isa_long();
  1580   if (ft == NULL || ft->empty())
  1581     return Type::TOP;           // Canonical empty value
  1582   if (ft->_widen < this->_widen) {
  1583     // Do not allow the value of kill->_widen to affect the outcome.
  1584     // The widen bits must be allowed to run freely through the graph.
  1585     ft = TypeLong::make(ft->_lo, ft->_hi, this->_widen);
  1587   return ft;
  1590 //------------------------------eq---------------------------------------------
  1591 // Structural equality check for Type representations
  1592 bool TypeLong::eq( const Type *t ) const {
  1593   const TypeLong *r = t->is_long(); // Handy access
  1594   return r->_lo == _lo &&  r->_hi == _hi  && r->_widen == _widen;
  1597 //------------------------------hash-------------------------------------------
  1598 // Type-specific hashing function.
  1599 int TypeLong::hash(void) const {
  1600   return (int)(_lo+_hi+_widen+(int)Type::Long);
  1603 //------------------------------is_finite--------------------------------------
  1604 // Has a finite value
  1605 bool TypeLong::is_finite() const {
  1606   return true;
  1609 //------------------------------dump2------------------------------------------
  1610 // Dump TypeLong
  1611 #ifndef PRODUCT
  1612 static const char* longnamenear(jlong x, const char* xname, char* buf, jlong n) {
  1613   if (n > x) {
  1614     if (n >= x + 10000)  return NULL;
  1615     sprintf(buf, "%s+" JLONG_FORMAT, xname, n - x);
  1616   } else if (n < x) {
  1617     if (n <= x - 10000)  return NULL;
  1618     sprintf(buf, "%s-" JLONG_FORMAT, xname, x - n);
  1619   } else {
  1620     return xname;
  1622   return buf;
  1625 static const char* longname(char* buf, jlong n) {
  1626   const char* str;
  1627   if (n == min_jlong)
  1628     return "min";
  1629   else if (n < min_jlong + 10000)
  1630     sprintf(buf, "min+" JLONG_FORMAT, n - min_jlong);
  1631   else if (n == max_jlong)
  1632     return "max";
  1633   else if (n > max_jlong - 10000)
  1634     sprintf(buf, "max-" JLONG_FORMAT, max_jlong - n);
  1635   else if ((str = longnamenear(max_juint, "maxuint", buf, n)) != NULL)
  1636     return str;
  1637   else if ((str = longnamenear(max_jint, "maxint", buf, n)) != NULL)
  1638     return str;
  1639   else if ((str = longnamenear(min_jint, "minint", buf, n)) != NULL)
  1640     return str;
  1641   else
  1642     sprintf(buf, JLONG_FORMAT, n);
  1643   return buf;
  1646 void TypeLong::dump2( Dict &d, uint depth, outputStream *st ) const {
  1647   char buf[80], buf2[80];
  1648   if (_lo == min_jlong && _hi == max_jlong)
  1649     st->print("long");
  1650   else if (is_con())
  1651     st->print("long:%s", longname(buf, get_con()));
  1652   else if (_hi == max_jlong)
  1653     st->print("long:>=%s", longname(buf, _lo));
  1654   else if (_lo == min_jlong)
  1655     st->print("long:<=%s", longname(buf, _hi));
  1656   else
  1657     st->print("long:%s..%s", longname(buf, _lo), longname(buf2, _hi));
  1659   if (_widen != 0 && this != TypeLong::LONG)
  1660     st->print(":%.*s", _widen, "wwww");
  1662 #endif
  1664 //------------------------------singleton--------------------------------------
  1665 // TRUE if Type is a singleton type, FALSE otherwise.   Singletons are simple
  1666 // constants
  1667 bool TypeLong::singleton(void) const {
  1668   return _lo >= _hi;
  1671 bool TypeLong::empty(void) const {
  1672   return _lo > _hi;
  1675 //=============================================================================
  1676 // Convenience common pre-built types.
  1677 const TypeTuple *TypeTuple::IFBOTH;     // Return both arms of IF as reachable
  1678 const TypeTuple *TypeTuple::IFFALSE;
  1679 const TypeTuple *TypeTuple::IFTRUE;
  1680 const TypeTuple *TypeTuple::IFNEITHER;
  1681 const TypeTuple *TypeTuple::LOOPBODY;
  1682 const TypeTuple *TypeTuple::MEMBAR;
  1683 const TypeTuple *TypeTuple::STORECONDITIONAL;
  1684 const TypeTuple *TypeTuple::START_I2C;
  1685 const TypeTuple *TypeTuple::INT_PAIR;
  1686 const TypeTuple *TypeTuple::LONG_PAIR;
  1687 const TypeTuple *TypeTuple::INT_CC_PAIR;
  1688 const TypeTuple *TypeTuple::LONG_CC_PAIR;
  1691 //------------------------------make-------------------------------------------
  1692 // Make a TypeTuple from the range of a method signature
  1693 const TypeTuple *TypeTuple::make_range(ciSignature* sig) {
  1694   ciType* return_type = sig->return_type();
  1695   uint total_fields = TypeFunc::Parms + return_type->size();
  1696   const Type **field_array = fields(total_fields);
  1697   switch (return_type->basic_type()) {
  1698   case T_LONG:
  1699     field_array[TypeFunc::Parms]   = TypeLong::LONG;
  1700     field_array[TypeFunc::Parms+1] = Type::HALF;
  1701     break;
  1702   case T_DOUBLE:
  1703     field_array[TypeFunc::Parms]   = Type::DOUBLE;
  1704     field_array[TypeFunc::Parms+1] = Type::HALF;
  1705     break;
  1706   case T_OBJECT:
  1707   case T_ARRAY:
  1708   case T_BOOLEAN:
  1709   case T_CHAR:
  1710   case T_FLOAT:
  1711   case T_BYTE:
  1712   case T_SHORT:
  1713   case T_INT:
  1714     field_array[TypeFunc::Parms] = get_const_type(return_type);
  1715     break;
  1716   case T_VOID:
  1717     break;
  1718   default:
  1719     ShouldNotReachHere();
  1721   return (TypeTuple*)(new TypeTuple(total_fields,field_array))->hashcons();
  1724 // Make a TypeTuple from the domain of a method signature
  1725 const TypeTuple *TypeTuple::make_domain(ciInstanceKlass* recv, ciSignature* sig) {
  1726   uint total_fields = TypeFunc::Parms + sig->size();
  1728   uint pos = TypeFunc::Parms;
  1729   const Type **field_array;
  1730   if (recv != NULL) {
  1731     total_fields++;
  1732     field_array = fields(total_fields);
  1733     // Use get_const_type here because it respects UseUniqueSubclasses:
  1734     field_array[pos++] = get_const_type(recv)->join(TypePtr::NOTNULL);
  1735   } else {
  1736     field_array = fields(total_fields);
  1739   int i = 0;
  1740   while (pos < total_fields) {
  1741     ciType* type = sig->type_at(i);
  1743     switch (type->basic_type()) {
  1744     case T_LONG:
  1745       field_array[pos++] = TypeLong::LONG;
  1746       field_array[pos++] = Type::HALF;
  1747       break;
  1748     case T_DOUBLE:
  1749       field_array[pos++] = Type::DOUBLE;
  1750       field_array[pos++] = Type::HALF;
  1751       break;
  1752     case T_OBJECT:
  1753     case T_ARRAY:
  1754     case T_BOOLEAN:
  1755     case T_CHAR:
  1756     case T_FLOAT:
  1757     case T_BYTE:
  1758     case T_SHORT:
  1759     case T_INT:
  1760       field_array[pos++] = get_const_type(type);
  1761       break;
  1762     default:
  1763       ShouldNotReachHere();
  1765     i++;
  1767   return (TypeTuple*)(new TypeTuple(total_fields,field_array))->hashcons();
  1770 const TypeTuple *TypeTuple::make( uint cnt, const Type **fields ) {
  1771   return (TypeTuple*)(new TypeTuple(cnt,fields))->hashcons();
  1774 //------------------------------fields-----------------------------------------
  1775 // Subroutine call type with space allocated for argument types
  1776 const Type **TypeTuple::fields( uint arg_cnt ) {
  1777   const Type **flds = (const Type **)(Compile::current()->type_arena()->Amalloc_4((TypeFunc::Parms+arg_cnt)*sizeof(Type*) ));
  1778   flds[TypeFunc::Control  ] = Type::CONTROL;
  1779   flds[TypeFunc::I_O      ] = Type::ABIO;
  1780   flds[TypeFunc::Memory   ] = Type::MEMORY;
  1781   flds[TypeFunc::FramePtr ] = TypeRawPtr::BOTTOM;
  1782   flds[TypeFunc::ReturnAdr] = Type::RETURN_ADDRESS;
  1784   return flds;
  1787 //------------------------------meet-------------------------------------------
  1788 // Compute the MEET of two types.  It returns a new Type object.
  1789 const Type *TypeTuple::xmeet( const Type *t ) const {
  1790   // Perform a fast test for common case; meeting the same types together.
  1791   if( this == t ) return this;  // Meeting same type-rep?
  1793   // Current "this->_base" is Tuple
  1794   switch (t->base()) {          // switch on original type
  1796   case Bottom:                  // Ye Olde Default
  1797     return t;
  1799   default:                      // All else is a mistake
  1800     typerr(t);
  1802   case Tuple: {                 // Meeting 2 signatures?
  1803     const TypeTuple *x = t->is_tuple();
  1804     assert( _cnt == x->_cnt, "" );
  1805     const Type **fields = (const Type **)(Compile::current()->type_arena()->Amalloc_4( _cnt*sizeof(Type*) ));
  1806     for( uint i=0; i<_cnt; i++ )
  1807       fields[i] = field_at(i)->xmeet( x->field_at(i) );
  1808     return TypeTuple::make(_cnt,fields);
  1810   case Top:
  1811     break;
  1813   return this;                  // Return the double constant
  1816 //------------------------------xdual------------------------------------------
  1817 // Dual: compute field-by-field dual
  1818 const Type *TypeTuple::xdual() const {
  1819   const Type **fields = (const Type **)(Compile::current()->type_arena()->Amalloc_4( _cnt*sizeof(Type*) ));
  1820   for( uint i=0; i<_cnt; i++ )
  1821     fields[i] = _fields[i]->dual();
  1822   return new TypeTuple(_cnt,fields);
  1825 //------------------------------eq---------------------------------------------
  1826 // Structural equality check for Type representations
  1827 bool TypeTuple::eq( const Type *t ) const {
  1828   const TypeTuple *s = (const TypeTuple *)t;
  1829   if (_cnt != s->_cnt)  return false;  // Unequal field counts
  1830   for (uint i = 0; i < _cnt; i++)
  1831     if (field_at(i) != s->field_at(i)) // POINTER COMPARE!  NO RECURSION!
  1832       return false;             // Missed
  1833   return true;
  1836 //------------------------------hash-------------------------------------------
  1837 // Type-specific hashing function.
  1838 int TypeTuple::hash(void) const {
  1839   intptr_t sum = _cnt;
  1840   for( uint i=0; i<_cnt; i++ )
  1841     sum += (intptr_t)_fields[i];     // Hash on pointers directly
  1842   return sum;
  1845 //------------------------------dump2------------------------------------------
  1846 // Dump signature Type
  1847 #ifndef PRODUCT
  1848 void TypeTuple::dump2( Dict &d, uint depth, outputStream *st ) const {
  1849   st->print("{");
  1850   if( !depth || d[this] ) {     // Check for recursive print
  1851     st->print("...}");
  1852     return;
  1854   d.Insert((void*)this, (void*)this);   // Stop recursion
  1855   if( _cnt ) {
  1856     uint i;
  1857     for( i=0; i<_cnt-1; i++ ) {
  1858       st->print("%d:", i);
  1859       _fields[i]->dump2(d, depth-1, st);
  1860       st->print(", ");
  1862     st->print("%d:", i);
  1863     _fields[i]->dump2(d, depth-1, st);
  1865   st->print("}");
  1867 #endif
  1869 //------------------------------singleton--------------------------------------
  1870 // TRUE if Type is a singleton type, FALSE otherwise.   Singletons are simple
  1871 // constants (Ldi nodes).  Singletons are integer, float or double constants
  1872 // or a single symbol.
  1873 bool TypeTuple::singleton(void) const {
  1874   return false;                 // Never a singleton
  1877 bool TypeTuple::empty(void) const {
  1878   for( uint i=0; i<_cnt; i++ ) {
  1879     if (_fields[i]->empty())  return true;
  1881   return false;
  1884 //=============================================================================
  1885 // Convenience common pre-built types.
  1887 inline const TypeInt* normalize_array_size(const TypeInt* size) {
  1888   // Certain normalizations keep us sane when comparing types.
  1889   // We do not want arrayOop variables to differ only by the wideness
  1890   // of their index types.  Pick minimum wideness, since that is the
  1891   // forced wideness of small ranges anyway.
  1892   if (size->_widen != Type::WidenMin)
  1893     return TypeInt::make(size->_lo, size->_hi, Type::WidenMin);
  1894   else
  1895     return size;
  1898 //------------------------------make-------------------------------------------
  1899 const TypeAry* TypeAry::make(const Type* elem, const TypeInt* size, bool stable) {
  1900   if (UseCompressedOops && elem->isa_oopptr()) {
  1901     elem = elem->make_narrowoop();
  1903   size = normalize_array_size(size);
  1904   return (TypeAry*)(new TypeAry(elem,size,stable))->hashcons();
  1907 //------------------------------meet-------------------------------------------
  1908 // Compute the MEET of two types.  It returns a new Type object.
  1909 const Type *TypeAry::xmeet( const Type *t ) const {
  1910   // Perform a fast test for common case; meeting the same types together.
  1911   if( this == t ) return this;  // Meeting same type-rep?
  1913   // Current "this->_base" is Ary
  1914   switch (t->base()) {          // switch on original type
  1916   case Bottom:                  // Ye Olde Default
  1917     return t;
  1919   default:                      // All else is a mistake
  1920     typerr(t);
  1922   case Array: {                 // Meeting 2 arrays?
  1923     const TypeAry *a = t->is_ary();
  1924     return TypeAry::make(_elem->meet(a->_elem),
  1925                          _size->xmeet(a->_size)->is_int(),
  1926                          _stable & a->_stable);
  1928   case Top:
  1929     break;
  1931   return this;                  // Return the double constant
  1934 //------------------------------xdual------------------------------------------
  1935 // Dual: compute field-by-field dual
  1936 const Type *TypeAry::xdual() const {
  1937   const TypeInt* size_dual = _size->dual()->is_int();
  1938   size_dual = normalize_array_size(size_dual);
  1939   return new TypeAry(_elem->dual(), size_dual, !_stable);
  1942 //------------------------------eq---------------------------------------------
  1943 // Structural equality check for Type representations
  1944 bool TypeAry::eq( const Type *t ) const {
  1945   const TypeAry *a = (const TypeAry*)t;
  1946   return _elem == a->_elem &&
  1947     _stable == a->_stable &&
  1948     _size == a->_size;
  1951 //------------------------------hash-------------------------------------------
  1952 // Type-specific hashing function.
  1953 int TypeAry::hash(void) const {
  1954   return (intptr_t)_elem + (intptr_t)_size + (_stable ? 43 : 0);
  1957 //----------------------interface_vs_oop---------------------------------------
  1958 #ifdef ASSERT
  1959 bool TypeAry::interface_vs_oop(const Type *t) const {
  1960   const TypeAry* t_ary = t->is_ary();
  1961   if (t_ary) {
  1962     return _elem->interface_vs_oop(t_ary->_elem);
  1964   return false;
  1966 #endif
  1968 //------------------------------dump2------------------------------------------
  1969 #ifndef PRODUCT
  1970 void TypeAry::dump2( Dict &d, uint depth, outputStream *st ) const {
  1971   if (_stable)  st->print("stable:");
  1972   _elem->dump2(d, depth, st);
  1973   st->print("[");
  1974   _size->dump2(d, depth, st);
  1975   st->print("]");
  1977 #endif
  1979 //------------------------------singleton--------------------------------------
  1980 // TRUE if Type is a singleton type, FALSE otherwise.   Singletons are simple
  1981 // constants (Ldi nodes).  Singletons are integer, float or double constants
  1982 // or a single symbol.
  1983 bool TypeAry::singleton(void) const {
  1984   return false;                 // Never a singleton
  1987 bool TypeAry::empty(void) const {
  1988   return _elem->empty() || _size->empty();
  1991 //--------------------------ary_must_be_exact----------------------------------
  1992 bool TypeAry::ary_must_be_exact() const {
  1993   if (!UseExactTypes)       return false;
  1994   // This logic looks at the element type of an array, and returns true
  1995   // if the element type is either a primitive or a final instance class.
  1996   // In such cases, an array built on this ary must have no subclasses.
  1997   if (_elem == BOTTOM)      return false;  // general array not exact
  1998   if (_elem == TOP   )      return false;  // inverted general array not exact
  1999   const TypeOopPtr*  toop = NULL;
  2000   if (UseCompressedOops && _elem->isa_narrowoop()) {
  2001     toop = _elem->make_ptr()->isa_oopptr();
  2002   } else {
  2003     toop = _elem->isa_oopptr();
  2005   if (!toop)                return true;   // a primitive type, like int
  2006   ciKlass* tklass = toop->klass();
  2007   if (tklass == NULL)       return false;  // unloaded class
  2008   if (!tklass->is_loaded()) return false;  // unloaded class
  2009   const TypeInstPtr* tinst;
  2010   if (_elem->isa_narrowoop())
  2011     tinst = _elem->make_ptr()->isa_instptr();
  2012   else
  2013     tinst = _elem->isa_instptr();
  2014   if (tinst)
  2015     return tklass->as_instance_klass()->is_final();
  2016   const TypeAryPtr*  tap;
  2017   if (_elem->isa_narrowoop())
  2018     tap = _elem->make_ptr()->isa_aryptr();
  2019   else
  2020     tap = _elem->isa_aryptr();
  2021   if (tap)
  2022     return tap->ary()->ary_must_be_exact();
  2023   return false;
  2026 //==============================TypeVect=======================================
  2027 // Convenience common pre-built types.
  2028 const TypeVect *TypeVect::VECTS = NULL; //  32-bit vectors
  2029 const TypeVect *TypeVect::VECTD = NULL; //  64-bit vectors
  2030 const TypeVect *TypeVect::VECTX = NULL; // 128-bit vectors
  2031 const TypeVect *TypeVect::VECTY = NULL; // 256-bit vectors
  2033 //------------------------------make-------------------------------------------
  2034 const TypeVect* TypeVect::make(const Type *elem, uint length) {
  2035   BasicType elem_bt = elem->array_element_basic_type();
  2036   assert(is_java_primitive(elem_bt), "only primitive types in vector");
  2037   assert(length > 1 && is_power_of_2(length), "vector length is power of 2");
  2038   assert(Matcher::vector_size_supported(elem_bt, length), "length in range");
  2039   int size = length * type2aelembytes(elem_bt);
  2040   switch (Matcher::vector_ideal_reg(size)) {
  2041   case Op_VecS:
  2042     return (TypeVect*)(new TypeVectS(elem, length))->hashcons();
  2043   case Op_RegL:
  2044   case Op_VecD:
  2045   case Op_RegD:
  2046     return (TypeVect*)(new TypeVectD(elem, length))->hashcons();
  2047   case Op_VecX:
  2048     return (TypeVect*)(new TypeVectX(elem, length))->hashcons();
  2049   case Op_VecY:
  2050     return (TypeVect*)(new TypeVectY(elem, length))->hashcons();
  2052  ShouldNotReachHere();
  2053   return NULL;
  2056 //------------------------------meet-------------------------------------------
  2057 // Compute the MEET of two types.  It returns a new Type object.
  2058 const Type *TypeVect::xmeet( const Type *t ) const {
  2059   // Perform a fast test for common case; meeting the same types together.
  2060   if( this == t ) return this;  // Meeting same type-rep?
  2062   // Current "this->_base" is Vector
  2063   switch (t->base()) {          // switch on original type
  2065   case Bottom:                  // Ye Olde Default
  2066     return t;
  2068   default:                      // All else is a mistake
  2069     typerr(t);
  2071   case VectorS:
  2072   case VectorD:
  2073   case VectorX:
  2074   case VectorY: {                // Meeting 2 vectors?
  2075     const TypeVect* v = t->is_vect();
  2076     assert(  base() == v->base(), "");
  2077     assert(length() == v->length(), "");
  2078     assert(element_basic_type() == v->element_basic_type(), "");
  2079     return TypeVect::make(_elem->xmeet(v->_elem), _length);
  2081   case Top:
  2082     break;
  2084   return this;
  2087 //------------------------------xdual------------------------------------------
  2088 // Dual: compute field-by-field dual
  2089 const Type *TypeVect::xdual() const {
  2090   return new TypeVect(base(), _elem->dual(), _length);
  2093 //------------------------------eq---------------------------------------------
  2094 // Structural equality check for Type representations
  2095 bool TypeVect::eq(const Type *t) const {
  2096   const TypeVect *v = t->is_vect();
  2097   return (_elem == v->_elem) && (_length == v->_length);
  2100 //------------------------------hash-------------------------------------------
  2101 // Type-specific hashing function.
  2102 int TypeVect::hash(void) const {
  2103   return (intptr_t)_elem + (intptr_t)_length;
  2106 //------------------------------singleton--------------------------------------
  2107 // TRUE if Type is a singleton type, FALSE otherwise.   Singletons are simple
  2108 // constants (Ldi nodes).  Vector is singleton if all elements are the same
  2109 // constant value (when vector is created with Replicate code).
  2110 bool TypeVect::singleton(void) const {
  2111 // There is no Con node for vectors yet.
  2112 //  return _elem->singleton();
  2113   return false;
  2116 bool TypeVect::empty(void) const {
  2117   return _elem->empty();
  2120 //------------------------------dump2------------------------------------------
  2121 #ifndef PRODUCT
  2122 void TypeVect::dump2(Dict &d, uint depth, outputStream *st) const {
  2123   switch (base()) {
  2124   case VectorS:
  2125     st->print("vectors["); break;
  2126   case VectorD:
  2127     st->print("vectord["); break;
  2128   case VectorX:
  2129     st->print("vectorx["); break;
  2130   case VectorY:
  2131     st->print("vectory["); break;
  2132   default:
  2133     ShouldNotReachHere();
  2135   st->print("%d]:{", _length);
  2136   _elem->dump2(d, depth, st);
  2137   st->print("}");
  2139 #endif
  2142 //=============================================================================
  2143 // Convenience common pre-built types.
  2144 const TypePtr *TypePtr::NULL_PTR;
  2145 const TypePtr *TypePtr::NOTNULL;
  2146 const TypePtr *TypePtr::BOTTOM;
  2148 //------------------------------meet-------------------------------------------
  2149 // Meet over the PTR enum
  2150 const TypePtr::PTR TypePtr::ptr_meet[TypePtr::lastPTR][TypePtr::lastPTR] = {
  2151   //              TopPTR,    AnyNull,   Constant, Null,   NotNull, BotPTR,
  2152   { /* Top     */ TopPTR,    AnyNull,   Constant, Null,   NotNull, BotPTR,},
  2153   { /* AnyNull */ AnyNull,   AnyNull,   Constant, BotPTR, NotNull, BotPTR,},
  2154   { /* Constant*/ Constant,  Constant,  Constant, BotPTR, NotNull, BotPTR,},
  2155   { /* Null    */ Null,      BotPTR,    BotPTR,   Null,   BotPTR,  BotPTR,},
  2156   { /* NotNull */ NotNull,   NotNull,   NotNull,  BotPTR, NotNull, BotPTR,},
  2157   { /* BotPTR  */ BotPTR,    BotPTR,    BotPTR,   BotPTR, BotPTR,  BotPTR,}
  2158 };
  2160 //------------------------------make-------------------------------------------
  2161 const TypePtr *TypePtr::make( TYPES t, enum PTR ptr, int offset ) {
  2162   return (TypePtr*)(new TypePtr(t,ptr,offset))->hashcons();
  2165 //------------------------------cast_to_ptr_type-------------------------------
  2166 const Type *TypePtr::cast_to_ptr_type(PTR ptr) const {
  2167   assert(_base == AnyPtr, "subclass must override cast_to_ptr_type");
  2168   if( ptr == _ptr ) return this;
  2169   return make(_base, ptr, _offset);
  2172 //------------------------------get_con----------------------------------------
  2173 intptr_t TypePtr::get_con() const {
  2174   assert( _ptr == Null, "" );
  2175   return _offset;
  2178 //------------------------------meet-------------------------------------------
  2179 // Compute the MEET of two types.  It returns a new Type object.
  2180 const Type *TypePtr::xmeet( const Type *t ) const {
  2181   // Perform a fast test for common case; meeting the same types together.
  2182   if( this == t ) return this;  // Meeting same type-rep?
  2184   // Current "this->_base" is AnyPtr
  2185   switch (t->base()) {          // switch on original type
  2186   case Int:                     // Mixing ints & oops happens when javac
  2187   case Long:                    // reuses local variables
  2188   case FloatTop:
  2189   case FloatCon:
  2190   case FloatBot:
  2191   case DoubleTop:
  2192   case DoubleCon:
  2193   case DoubleBot:
  2194   case NarrowOop:
  2195   case NarrowKlass:
  2196   case Bottom:                  // Ye Olde Default
  2197     return Type::BOTTOM;
  2198   case Top:
  2199     return this;
  2201   case AnyPtr: {                // Meeting to AnyPtrs
  2202     const TypePtr *tp = t->is_ptr();
  2203     return make( AnyPtr, meet_ptr(tp->ptr()), meet_offset(tp->offset()) );
  2205   case RawPtr:                  // For these, flip the call around to cut down
  2206   case OopPtr:
  2207   case InstPtr:                 // on the cases I have to handle.
  2208   case AryPtr:
  2209   case MetadataPtr:
  2210   case KlassPtr:
  2211     return t->xmeet(this);      // Call in reverse direction
  2212   default:                      // All else is a mistake
  2213     typerr(t);
  2216   return this;
  2219 //------------------------------meet_offset------------------------------------
  2220 int TypePtr::meet_offset( int offset ) const {
  2221   // Either is 'TOP' offset?  Return the other offset!
  2222   if( _offset == OffsetTop ) return offset;
  2223   if( offset == OffsetTop ) return _offset;
  2224   // If either is different, return 'BOTTOM' offset
  2225   if( _offset != offset ) return OffsetBot;
  2226   return _offset;
  2229 //------------------------------dual_offset------------------------------------
  2230 int TypePtr::dual_offset( ) const {
  2231   if( _offset == OffsetTop ) return OffsetBot;// Map 'TOP' into 'BOTTOM'
  2232   if( _offset == OffsetBot ) return OffsetTop;// Map 'BOTTOM' into 'TOP'
  2233   return _offset;               // Map everything else into self
  2236 //------------------------------xdual------------------------------------------
  2237 // Dual: compute field-by-field dual
  2238 const TypePtr::PTR TypePtr::ptr_dual[TypePtr::lastPTR] = {
  2239   BotPTR, NotNull, Constant, Null, AnyNull, TopPTR
  2240 };
  2241 const Type *TypePtr::xdual() const {
  2242   return new TypePtr( AnyPtr, dual_ptr(), dual_offset() );
  2245 //------------------------------xadd_offset------------------------------------
  2246 int TypePtr::xadd_offset( intptr_t offset ) const {
  2247   // Adding to 'TOP' offset?  Return 'TOP'!
  2248   if( _offset == OffsetTop || offset == OffsetTop ) return OffsetTop;
  2249   // Adding to 'BOTTOM' offset?  Return 'BOTTOM'!
  2250   if( _offset == OffsetBot || offset == OffsetBot ) return OffsetBot;
  2251   // Addition overflows or "accidentally" equals to OffsetTop? Return 'BOTTOM'!
  2252   offset += (intptr_t)_offset;
  2253   if (offset != (int)offset || offset == OffsetTop) return OffsetBot;
  2255   // assert( _offset >= 0 && _offset+offset >= 0, "" );
  2256   // It is possible to construct a negative offset during PhaseCCP
  2258   return (int)offset;        // Sum valid offsets
  2261 //------------------------------add_offset-------------------------------------
  2262 const TypePtr *TypePtr::add_offset( intptr_t offset ) const {
  2263   return make( AnyPtr, _ptr, xadd_offset(offset) );
  2266 //------------------------------eq---------------------------------------------
  2267 // Structural equality check for Type representations
  2268 bool TypePtr::eq( const Type *t ) const {
  2269   const TypePtr *a = (const TypePtr*)t;
  2270   return _ptr == a->ptr() && _offset == a->offset();
  2273 //------------------------------hash-------------------------------------------
  2274 // Type-specific hashing function.
  2275 int TypePtr::hash(void) const {
  2276   return _ptr + _offset;
  2279 //------------------------------dump2------------------------------------------
  2280 const char *const TypePtr::ptr_msg[TypePtr::lastPTR] = {
  2281   "TopPTR","AnyNull","Constant","NULL","NotNull","BotPTR"
  2282 };
  2284 #ifndef PRODUCT
  2285 void TypePtr::dump2( Dict &d, uint depth, outputStream *st ) const {
  2286   if( _ptr == Null ) st->print("NULL");
  2287   else st->print("%s *", ptr_msg[_ptr]);
  2288   if( _offset == OffsetTop ) st->print("+top");
  2289   else if( _offset == OffsetBot ) st->print("+bot");
  2290   else if( _offset ) st->print("+%d", _offset);
  2292 #endif
  2294 //------------------------------singleton--------------------------------------
  2295 // TRUE if Type is a singleton type, FALSE otherwise.   Singletons are simple
  2296 // constants
  2297 bool TypePtr::singleton(void) const {
  2298   // TopPTR, Null, AnyNull, Constant are all singletons
  2299   return (_offset != OffsetBot) && !below_centerline(_ptr);
  2302 bool TypePtr::empty(void) const {
  2303   return (_offset == OffsetTop) || above_centerline(_ptr);
  2306 //=============================================================================
  2307 // Convenience common pre-built types.
  2308 const TypeRawPtr *TypeRawPtr::BOTTOM;
  2309 const TypeRawPtr *TypeRawPtr::NOTNULL;
  2311 //------------------------------make-------------------------------------------
  2312 const TypeRawPtr *TypeRawPtr::make( enum PTR ptr ) {
  2313   assert( ptr != Constant, "what is the constant?" );
  2314   assert( ptr != Null, "Use TypePtr for NULL" );
  2315   return (TypeRawPtr*)(new TypeRawPtr(ptr,0))->hashcons();
  2318 const TypeRawPtr *TypeRawPtr::make( address bits ) {
  2319   assert( bits, "Use TypePtr for NULL" );
  2320   return (TypeRawPtr*)(new TypeRawPtr(Constant,bits))->hashcons();
  2323 //------------------------------cast_to_ptr_type-------------------------------
  2324 const Type *TypeRawPtr::cast_to_ptr_type(PTR ptr) const {
  2325   assert( ptr != Constant, "what is the constant?" );
  2326   assert( ptr != Null, "Use TypePtr for NULL" );
  2327   assert( _bits==0, "Why cast a constant address?");
  2328   if( ptr == _ptr ) return this;
  2329   return make(ptr);
  2332 //------------------------------get_con----------------------------------------
  2333 intptr_t TypeRawPtr::get_con() const {
  2334   assert( _ptr == Null || _ptr == Constant, "" );
  2335   return (intptr_t)_bits;
  2338 //------------------------------meet-------------------------------------------
  2339 // Compute the MEET of two types.  It returns a new Type object.
  2340 const Type *TypeRawPtr::xmeet( const Type *t ) const {
  2341   // Perform a fast test for common case; meeting the same types together.
  2342   if( this == t ) return this;  // Meeting same type-rep?
  2344   // Current "this->_base" is RawPtr
  2345   switch( t->base() ) {         // switch on original type
  2346   case Bottom:                  // Ye Olde Default
  2347     return t;
  2348   case Top:
  2349     return this;
  2350   case AnyPtr:                  // Meeting to AnyPtrs
  2351     break;
  2352   case RawPtr: {                // might be top, bot, any/not or constant
  2353     enum PTR tptr = t->is_ptr()->ptr();
  2354     enum PTR ptr = meet_ptr( tptr );
  2355     if( ptr == Constant ) {     // Cannot be equal constants, so...
  2356       if( tptr == Constant && _ptr != Constant)  return t;
  2357       if( _ptr == Constant && tptr != Constant)  return this;
  2358       ptr = NotNull;            // Fall down in lattice
  2360     return make( ptr );
  2363   case OopPtr:
  2364   case InstPtr:
  2365   case AryPtr:
  2366   case MetadataPtr:
  2367   case KlassPtr:
  2368     return TypePtr::BOTTOM;     // Oop meet raw is not well defined
  2369   default:                      // All else is a mistake
  2370     typerr(t);
  2373   // Found an AnyPtr type vs self-RawPtr type
  2374   const TypePtr *tp = t->is_ptr();
  2375   switch (tp->ptr()) {
  2376   case TypePtr::TopPTR:  return this;
  2377   case TypePtr::BotPTR:  return t;
  2378   case TypePtr::Null:
  2379     if( _ptr == TypePtr::TopPTR ) return t;
  2380     return TypeRawPtr::BOTTOM;
  2381   case TypePtr::NotNull: return TypePtr::make( AnyPtr, meet_ptr(TypePtr::NotNull), tp->meet_offset(0) );
  2382   case TypePtr::AnyNull:
  2383     if( _ptr == TypePtr::Constant) return this;
  2384     return make( meet_ptr(TypePtr::AnyNull) );
  2385   default: ShouldNotReachHere();
  2387   return this;
  2390 //------------------------------xdual------------------------------------------
  2391 // Dual: compute field-by-field dual
  2392 const Type *TypeRawPtr::xdual() const {
  2393   return new TypeRawPtr( dual_ptr(), _bits );
  2396 //------------------------------add_offset-------------------------------------
  2397 const TypePtr *TypeRawPtr::add_offset( intptr_t offset ) const {
  2398   if( offset == OffsetTop ) return BOTTOM; // Undefined offset-> undefined pointer
  2399   if( offset == OffsetBot ) return BOTTOM; // Unknown offset-> unknown pointer
  2400   if( offset == 0 ) return this; // No change
  2401   switch (_ptr) {
  2402   case TypePtr::TopPTR:
  2403   case TypePtr::BotPTR:
  2404   case TypePtr::NotNull:
  2405     return this;
  2406   case TypePtr::Null:
  2407   case TypePtr::Constant: {
  2408     address bits = _bits+offset;
  2409     if ( bits == 0 ) return TypePtr::NULL_PTR;
  2410     return make( bits );
  2412   default:  ShouldNotReachHere();
  2414   return NULL;                  // Lint noise
  2417 //------------------------------eq---------------------------------------------
  2418 // Structural equality check for Type representations
  2419 bool TypeRawPtr::eq( const Type *t ) const {
  2420   const TypeRawPtr *a = (const TypeRawPtr*)t;
  2421   return _bits == a->_bits && TypePtr::eq(t);
  2424 //------------------------------hash-------------------------------------------
  2425 // Type-specific hashing function.
  2426 int TypeRawPtr::hash(void) const {
  2427   return (intptr_t)_bits + TypePtr::hash();
  2430 //------------------------------dump2------------------------------------------
  2431 #ifndef PRODUCT
  2432 void TypeRawPtr::dump2( Dict &d, uint depth, outputStream *st ) const {
  2433   if( _ptr == Constant )
  2434     st->print(INTPTR_FORMAT, _bits);
  2435   else
  2436     st->print("rawptr:%s", ptr_msg[_ptr]);
  2438 #endif
  2440 //=============================================================================
  2441 // Convenience common pre-built type.
  2442 const TypeOopPtr *TypeOopPtr::BOTTOM;
  2444 //------------------------------TypeOopPtr-------------------------------------
  2445 TypeOopPtr::TypeOopPtr(TYPES t, PTR ptr, ciKlass* k, bool xk, ciObject* o, int offset, int instance_id, const TypeOopPtr* speculative)
  2446   : TypePtr(t, ptr, offset),
  2447     _const_oop(o), _klass(k),
  2448     _klass_is_exact(xk),
  2449     _is_ptr_to_narrowoop(false),
  2450     _is_ptr_to_narrowklass(false),
  2451     _is_ptr_to_boxed_value(false),
  2452     _instance_id(instance_id),
  2453     _speculative(speculative) {
  2454   if (Compile::current()->eliminate_boxing() && (t == InstPtr) &&
  2455       (offset > 0) && xk && (k != 0) && k->is_instance_klass()) {
  2456     _is_ptr_to_boxed_value = k->as_instance_klass()->is_boxed_value_offset(offset);
  2458 #ifdef _LP64
  2459   if (_offset != 0) {
  2460     if (_offset == oopDesc::klass_offset_in_bytes()) {
  2461       _is_ptr_to_narrowklass = UseCompressedClassPointers;
  2462     } else if (klass() == NULL) {
  2463       // Array with unknown body type
  2464       assert(this->isa_aryptr(), "only arrays without klass");
  2465       _is_ptr_to_narrowoop = UseCompressedOops;
  2466     } else if (this->isa_aryptr()) {
  2467       _is_ptr_to_narrowoop = (UseCompressedOops && klass()->is_obj_array_klass() &&
  2468                              _offset != arrayOopDesc::length_offset_in_bytes());
  2469     } else if (klass()->is_instance_klass()) {
  2470       ciInstanceKlass* ik = klass()->as_instance_klass();
  2471       ciField* field = NULL;
  2472       if (this->isa_klassptr()) {
  2473         // Perm objects don't use compressed references
  2474       } else if (_offset == OffsetBot || _offset == OffsetTop) {
  2475         // unsafe access
  2476         _is_ptr_to_narrowoop = UseCompressedOops;
  2477       } else { // exclude unsafe ops
  2478         assert(this->isa_instptr(), "must be an instance ptr.");
  2480         if (klass() == ciEnv::current()->Class_klass() &&
  2481             (_offset == java_lang_Class::klass_offset_in_bytes() ||
  2482              _offset == java_lang_Class::array_klass_offset_in_bytes())) {
  2483           // Special hidden fields from the Class.
  2484           assert(this->isa_instptr(), "must be an instance ptr.");
  2485           _is_ptr_to_narrowoop = false;
  2486         } else if (klass() == ciEnv::current()->Class_klass() &&
  2487                    _offset >= InstanceMirrorKlass::offset_of_static_fields()) {
  2488           // Static fields
  2489           assert(o != NULL, "must be constant");
  2490           ciInstanceKlass* k = o->as_instance()->java_lang_Class_klass()->as_instance_klass();
  2491           ciField* field = k->get_field_by_offset(_offset, true);
  2492           assert(field != NULL, "missing field");
  2493           BasicType basic_elem_type = field->layout_type();
  2494           _is_ptr_to_narrowoop = UseCompressedOops && (basic_elem_type == T_OBJECT ||
  2495                                                        basic_elem_type == T_ARRAY);
  2496         } else {
  2497           // Instance fields which contains a compressed oop references.
  2498           field = ik->get_field_by_offset(_offset, false);
  2499           if (field != NULL) {
  2500             BasicType basic_elem_type = field->layout_type();
  2501             _is_ptr_to_narrowoop = UseCompressedOops && (basic_elem_type == T_OBJECT ||
  2502                                                          basic_elem_type == T_ARRAY);
  2503           } else if (klass()->equals(ciEnv::current()->Object_klass())) {
  2504             // Compile::find_alias_type() cast exactness on all types to verify
  2505             // that it does not affect alias type.
  2506             _is_ptr_to_narrowoop = UseCompressedOops;
  2507           } else {
  2508             // Type for the copy start in LibraryCallKit::inline_native_clone().
  2509             _is_ptr_to_narrowoop = UseCompressedOops;
  2515 #endif
  2518 //------------------------------make-------------------------------------------
  2519 const TypeOopPtr *TypeOopPtr::make(PTR ptr,
  2520                                    int offset, int instance_id, const TypeOopPtr* speculative) {
  2521   assert(ptr != Constant, "no constant generic pointers");
  2522   ciKlass*  k = Compile::current()->env()->Object_klass();
  2523   bool      xk = false;
  2524   ciObject* o = NULL;
  2525   return (TypeOopPtr*)(new TypeOopPtr(OopPtr, ptr, k, xk, o, offset, instance_id, speculative))->hashcons();
  2529 //------------------------------cast_to_ptr_type-------------------------------
  2530 const Type *TypeOopPtr::cast_to_ptr_type(PTR ptr) const {
  2531   assert(_base == OopPtr, "subclass must override cast_to_ptr_type");
  2532   if( ptr == _ptr ) return this;
  2533   return make(ptr, _offset, _instance_id, _speculative);
  2536 //-----------------------------cast_to_instance_id----------------------------
  2537 const TypeOopPtr *TypeOopPtr::cast_to_instance_id(int instance_id) const {
  2538   // There are no instances of a general oop.
  2539   // Return self unchanged.
  2540   return this;
  2543 //-----------------------------cast_to_exactness-------------------------------
  2544 const Type *TypeOopPtr::cast_to_exactness(bool klass_is_exact) const {
  2545   // There is no such thing as an exact general oop.
  2546   // Return self unchanged.
  2547   return this;
  2551 //------------------------------as_klass_type----------------------------------
  2552 // Return the klass type corresponding to this instance or array type.
  2553 // It is the type that is loaded from an object of this type.
  2554 const TypeKlassPtr* TypeOopPtr::as_klass_type() const {
  2555   ciKlass* k = klass();
  2556   bool    xk = klass_is_exact();
  2557   if (k == NULL)
  2558     return TypeKlassPtr::OBJECT;
  2559   else
  2560     return TypeKlassPtr::make(xk? Constant: NotNull, k, 0);
  2563 const Type *TypeOopPtr::xmeet(const Type *t) const {
  2564   const Type* res = xmeet_helper(t);
  2565   if (res->isa_oopptr() == NULL) {
  2566     return res;
  2569   if (res->isa_oopptr() != NULL) {
  2570     // type->speculative() == NULL means that speculation is no better
  2571     // than type, i.e. type->speculative() == type. So there are 2
  2572     // ways to represent the fact that we have no useful speculative
  2573     // data and we should use a single one to be able to test for
  2574     // equality between types. Check whether type->speculative() ==
  2575     // type and set speculative to NULL if it is the case.
  2576     const TypeOopPtr* res_oopptr = res->is_oopptr();
  2577     if (res_oopptr->remove_speculative() == res_oopptr->speculative()) {
  2578       return res_oopptr->remove_speculative();
  2582   return res;
  2585 //------------------------------meet-------------------------------------------
  2586 // Compute the MEET of two types.  It returns a new Type object.
  2587 const Type *TypeOopPtr::xmeet_helper(const Type *t) const {
  2588   // Perform a fast test for common case; meeting the same types together.
  2589   if( this == t ) return this;  // Meeting same type-rep?
  2591   // Current "this->_base" is OopPtr
  2592   switch (t->base()) {          // switch on original type
  2594   case Int:                     // Mixing ints & oops happens when javac
  2595   case Long:                    // reuses local variables
  2596   case FloatTop:
  2597   case FloatCon:
  2598   case FloatBot:
  2599   case DoubleTop:
  2600   case DoubleCon:
  2601   case DoubleBot:
  2602   case NarrowOop:
  2603   case NarrowKlass:
  2604   case Bottom:                  // Ye Olde Default
  2605     return Type::BOTTOM;
  2606   case Top:
  2607     return this;
  2609   default:                      // All else is a mistake
  2610     typerr(t);
  2612   case RawPtr:
  2613   case MetadataPtr:
  2614   case KlassPtr:
  2615     return TypePtr::BOTTOM;     // Oop meet raw is not well defined
  2617   case AnyPtr: {
  2618     // Found an AnyPtr type vs self-OopPtr type
  2619     const TypePtr *tp = t->is_ptr();
  2620     int offset = meet_offset(tp->offset());
  2621     PTR ptr = meet_ptr(tp->ptr());
  2622     switch (tp->ptr()) {
  2623     case Null:
  2624       if (ptr == Null)  return TypePtr::make(AnyPtr, ptr, offset);
  2625       // else fall through:
  2626     case TopPTR:
  2627     case AnyNull: {
  2628       int instance_id = meet_instance_id(InstanceTop);
  2629       const TypeOopPtr* speculative = _speculative;
  2630       return make(ptr, offset, instance_id, speculative);
  2632     case BotPTR:
  2633     case NotNull:
  2634       return TypePtr::make(AnyPtr, ptr, offset);
  2635     default: typerr(t);
  2639   case OopPtr: {                 // Meeting to other OopPtrs
  2640     const TypeOopPtr *tp = t->is_oopptr();
  2641     int instance_id = meet_instance_id(tp->instance_id());
  2642     const TypeOopPtr* speculative = meet_speculative(tp);
  2643     return make(meet_ptr(tp->ptr()), meet_offset(tp->offset()), instance_id, speculative);
  2646   case InstPtr:                  // For these, flip the call around to cut down
  2647   case AryPtr:
  2648     return t->xmeet(this);      // Call in reverse direction
  2650   } // End of switch
  2651   return this;                  // Return the double constant
  2655 //------------------------------xdual------------------------------------------
  2656 // Dual of a pure heap pointer.  No relevant klass or oop information.
  2657 const Type *TypeOopPtr::xdual() const {
  2658   assert(klass() == Compile::current()->env()->Object_klass(), "no klasses here");
  2659   assert(const_oop() == NULL,             "no constants here");
  2660   return new TypeOopPtr(_base, dual_ptr(), klass(), klass_is_exact(), const_oop(), dual_offset(), dual_instance_id(), dual_speculative());
  2663 //--------------------------make_from_klass_common-----------------------------
  2664 // Computes the element-type given a klass.
  2665 const TypeOopPtr* TypeOopPtr::make_from_klass_common(ciKlass *klass, bool klass_change, bool try_for_exact) {
  2666   if (klass->is_instance_klass()) {
  2667     Compile* C = Compile::current();
  2668     Dependencies* deps = C->dependencies();
  2669     assert((deps != NULL) == (C->method() != NULL && C->method()->code_size() > 0), "sanity");
  2670     // Element is an instance
  2671     bool klass_is_exact = false;
  2672     if (klass->is_loaded()) {
  2673       // Try to set klass_is_exact.
  2674       ciInstanceKlass* ik = klass->as_instance_klass();
  2675       klass_is_exact = ik->is_final();
  2676       if (!klass_is_exact && klass_change
  2677           && deps != NULL && UseUniqueSubclasses) {
  2678         ciInstanceKlass* sub = ik->unique_concrete_subklass();
  2679         if (sub != NULL) {
  2680           deps->assert_abstract_with_unique_concrete_subtype(ik, sub);
  2681           klass = ik = sub;
  2682           klass_is_exact = sub->is_final();
  2685       if (!klass_is_exact && try_for_exact
  2686           && deps != NULL && UseExactTypes) {
  2687         if (!ik->is_interface() && !ik->has_subklass()) {
  2688           // Add a dependence; if concrete subclass added we need to recompile
  2689           deps->assert_leaf_type(ik);
  2690           klass_is_exact = true;
  2694     return TypeInstPtr::make(TypePtr::BotPTR, klass, klass_is_exact, NULL, 0);
  2695   } else if (klass->is_obj_array_klass()) {
  2696     // Element is an object array. Recursively call ourself.
  2697     const TypeOopPtr *etype = TypeOopPtr::make_from_klass_common(klass->as_obj_array_klass()->element_klass(), false, try_for_exact);
  2698     bool xk = etype->klass_is_exact();
  2699     const TypeAry* arr0 = TypeAry::make(etype, TypeInt::POS);
  2700     // We used to pass NotNull in here, asserting that the sub-arrays
  2701     // are all not-null.  This is not true in generally, as code can
  2702     // slam NULLs down in the subarrays.
  2703     const TypeAryPtr* arr = TypeAryPtr::make(TypePtr::BotPTR, arr0, klass, xk, 0);
  2704     return arr;
  2705   } else if (klass->is_type_array_klass()) {
  2706     // Element is an typeArray
  2707     const Type* etype = get_const_basic_type(klass->as_type_array_klass()->element_type());
  2708     const TypeAry* arr0 = TypeAry::make(etype, TypeInt::POS);
  2709     // We used to pass NotNull in here, asserting that the array pointer
  2710     // is not-null. That was not true in general.
  2711     const TypeAryPtr* arr = TypeAryPtr::make(TypePtr::BotPTR, arr0, klass, true, 0);
  2712     return arr;
  2713   } else {
  2714     ShouldNotReachHere();
  2715     return NULL;
  2719 //------------------------------make_from_constant-----------------------------
  2720 // Make a java pointer from an oop constant
  2721 const TypeOopPtr* TypeOopPtr::make_from_constant(ciObject* o,
  2722                                                  bool require_constant,
  2723                                                  bool is_autobox_cache) {
  2724   assert(!o->is_null_object(), "null object not yet handled here.");
  2725   ciKlass* klass = o->klass();
  2726   if (klass->is_instance_klass()) {
  2727     // Element is an instance
  2728     if (require_constant) {
  2729       if (!o->can_be_constant())  return NULL;
  2730     } else if (!o->should_be_constant()) {
  2731       return TypeInstPtr::make(TypePtr::NotNull, klass, true, NULL, 0);
  2733     return TypeInstPtr::make(o);
  2734   } else if (klass->is_obj_array_klass()) {
  2735     // Element is an object array. Recursively call ourself.
  2736     const TypeOopPtr *etype =
  2737       TypeOopPtr::make_from_klass_raw(klass->as_obj_array_klass()->element_klass());
  2738     if (is_autobox_cache) {
  2739       // The pointers in the autobox arrays are always non-null.
  2740       etype = etype->cast_to_ptr_type(TypePtr::NotNull)->is_oopptr();
  2742     const TypeAry* arr0 = TypeAry::make(etype, TypeInt::make(o->as_array()->length()));
  2743     // We used to pass NotNull in here, asserting that the sub-arrays
  2744     // are all not-null.  This is not true in generally, as code can
  2745     // slam NULLs down in the subarrays.
  2746     if (require_constant) {
  2747       if (!o->can_be_constant())  return NULL;
  2748     } else if (!o->should_be_constant()) {
  2749       return TypeAryPtr::make(TypePtr::NotNull, arr0, klass, true, 0);
  2751     const TypeAryPtr* arr = TypeAryPtr::make(TypePtr::Constant, o, arr0, klass, true, 0, InstanceBot, NULL, is_autobox_cache);
  2752     return arr;
  2753   } else if (klass->is_type_array_klass()) {
  2754     // Element is an typeArray
  2755     const Type* etype =
  2756       (Type*)get_const_basic_type(klass->as_type_array_klass()->element_type());
  2757     const TypeAry* arr0 = TypeAry::make(etype, TypeInt::make(o->as_array()->length()));
  2758     // We used to pass NotNull in here, asserting that the array pointer
  2759     // is not-null. That was not true in general.
  2760     if (require_constant) {
  2761       if (!o->can_be_constant())  return NULL;
  2762     } else if (!o->should_be_constant()) {
  2763       return TypeAryPtr::make(TypePtr::NotNull, arr0, klass, true, 0);
  2765     const TypeAryPtr* arr = TypeAryPtr::make(TypePtr::Constant, o, arr0, klass, true, 0);
  2766     return arr;
  2769   fatal("unhandled object type");
  2770   return NULL;
  2773 //------------------------------get_con----------------------------------------
  2774 intptr_t TypeOopPtr::get_con() const {
  2775   assert( _ptr == Null || _ptr == Constant, "" );
  2776   assert( _offset >= 0, "" );
  2778   if (_offset != 0) {
  2779     // After being ported to the compiler interface, the compiler no longer
  2780     // directly manipulates the addresses of oops.  Rather, it only has a pointer
  2781     // to a handle at compile time.  This handle is embedded in the generated
  2782     // code and dereferenced at the time the nmethod is made.  Until that time,
  2783     // it is not reasonable to do arithmetic with the addresses of oops (we don't
  2784     // have access to the addresses!).  This does not seem to currently happen,
  2785     // but this assertion here is to help prevent its occurence.
  2786     tty->print_cr("Found oop constant with non-zero offset");
  2787     ShouldNotReachHere();
  2790   return (intptr_t)const_oop()->constant_encoding();
  2794 //-----------------------------filter------------------------------------------
  2795 // Do not allow interface-vs.-noninterface joins to collapse to top.
  2796 const Type *TypeOopPtr::filter(const Type *kills) const {
  2798   const Type* ft = join(kills);
  2799   const TypeInstPtr* ftip = ft->isa_instptr();
  2800   const TypeInstPtr* ktip = kills->isa_instptr();
  2802   if (ft->empty()) {
  2803     // Check for evil case of 'this' being a class and 'kills' expecting an
  2804     // interface.  This can happen because the bytecodes do not contain
  2805     // enough type info to distinguish a Java-level interface variable
  2806     // from a Java-level object variable.  If we meet 2 classes which
  2807     // both implement interface I, but their meet is at 'j/l/O' which
  2808     // doesn't implement I, we have no way to tell if the result should
  2809     // be 'I' or 'j/l/O'.  Thus we'll pick 'j/l/O'.  If this then flows
  2810     // into a Phi which "knows" it's an Interface type we'll have to
  2811     // uplift the type.
  2812     if (!empty() && ktip != NULL && ktip->is_loaded() && ktip->klass()->is_interface())
  2813       return kills;             // Uplift to interface
  2815     return Type::TOP;           // Canonical empty value
  2818   // If we have an interface-typed Phi or cast and we narrow to a class type,
  2819   // the join should report back the class.  However, if we have a J/L/Object
  2820   // class-typed Phi and an interface flows in, it's possible that the meet &
  2821   // join report an interface back out.  This isn't possible but happens
  2822   // because the type system doesn't interact well with interfaces.
  2823   if (ftip != NULL && ktip != NULL &&
  2824       ftip->is_loaded() &&  ftip->klass()->is_interface() &&
  2825       ktip->is_loaded() && !ktip->klass()->is_interface()) {
  2826     // Happens in a CTW of rt.jar, 320-341, no extra flags
  2827     assert(!ftip->klass_is_exact(), "interface could not be exact");
  2828     return ktip->cast_to_ptr_type(ftip->ptr());
  2831   return ft;
  2834 //------------------------------eq---------------------------------------------
  2835 // Structural equality check for Type representations
  2836 bool TypeOopPtr::eq( const Type *t ) const {
  2837   const TypeOopPtr *a = (const TypeOopPtr*)t;
  2838   if (_klass_is_exact != a->_klass_is_exact ||
  2839       _instance_id != a->_instance_id ||
  2840       !eq_speculative(a))  return false;
  2841   ciObject* one = const_oop();
  2842   ciObject* two = a->const_oop();
  2843   if (one == NULL || two == NULL) {
  2844     return (one == two) && TypePtr::eq(t);
  2845   } else {
  2846     return one->equals(two) && TypePtr::eq(t);
  2850 //------------------------------hash-------------------------------------------
  2851 // Type-specific hashing function.
  2852 int TypeOopPtr::hash(void) const {
  2853   return
  2854     (const_oop() ? const_oop()->hash() : 0) +
  2855     _klass_is_exact +
  2856     _instance_id +
  2857     hash_speculative() +
  2858     TypePtr::hash();
  2861 //------------------------------dump2------------------------------------------
  2862 #ifndef PRODUCT
  2863 void TypeOopPtr::dump2( Dict &d, uint depth, outputStream *st ) const {
  2864   st->print("oopptr:%s", ptr_msg[_ptr]);
  2865   if( _klass_is_exact ) st->print(":exact");
  2866   if( const_oop() ) st->print(INTPTR_FORMAT, const_oop());
  2867   switch( _offset ) {
  2868   case OffsetTop: st->print("+top"); break;
  2869   case OffsetBot: st->print("+any"); break;
  2870   case         0: break;
  2871   default:        st->print("+%d",_offset); break;
  2873   if (_instance_id == InstanceTop)
  2874     st->print(",iid=top");
  2875   else if (_instance_id != InstanceBot)
  2876     st->print(",iid=%d",_instance_id);
  2878   dump_speculative(st);
  2881 /**
  2882  *dump the speculative part of the type
  2883  */
  2884 void TypeOopPtr::dump_speculative(outputStream *st) const {
  2885   if (_speculative != NULL) {
  2886     st->print(" (speculative=");
  2887     _speculative->dump_on(st);
  2888     st->print(")");
  2891 #endif
  2893 //------------------------------singleton--------------------------------------
  2894 // TRUE if Type is a singleton type, FALSE otherwise.   Singletons are simple
  2895 // constants
  2896 bool TypeOopPtr::singleton(void) const {
  2897   // detune optimizer to not generate constant oop + constant offset as a constant!
  2898   // TopPTR, Null, AnyNull, Constant are all singletons
  2899   return (_offset == 0) && !below_centerline(_ptr);
  2902 //------------------------------add_offset-------------------------------------
  2903 const TypePtr *TypeOopPtr::add_offset(intptr_t offset) const {
  2904   return make(_ptr, xadd_offset(offset), _instance_id, add_offset_speculative(offset));
  2907 /**
  2908  * Return same type without a speculative part
  2909  */
  2910 const TypeOopPtr* TypeOopPtr::remove_speculative() const {
  2911   return make(_ptr, _offset, _instance_id, NULL);
  2914 //------------------------------meet_instance_id--------------------------------
  2915 int TypeOopPtr::meet_instance_id( int instance_id ) const {
  2916   // Either is 'TOP' instance?  Return the other instance!
  2917   if( _instance_id == InstanceTop ) return  instance_id;
  2918   if(  instance_id == InstanceTop ) return _instance_id;
  2919   // If either is different, return 'BOTTOM' instance
  2920   if( _instance_id != instance_id ) return InstanceBot;
  2921   return _instance_id;
  2924 //------------------------------dual_instance_id--------------------------------
  2925 int TypeOopPtr::dual_instance_id( ) const {
  2926   if( _instance_id == InstanceTop ) return InstanceBot; // Map TOP into BOTTOM
  2927   if( _instance_id == InstanceBot ) return InstanceTop; // Map BOTTOM into TOP
  2928   return _instance_id;              // Map everything else into self
  2931 /**
  2932  * meet of the speculative parts of 2 types
  2934  * @param other  type to meet with
  2935  */
  2936 const TypeOopPtr* TypeOopPtr::meet_speculative(const TypeOopPtr* other) const {
  2937   bool this_has_spec = (_speculative != NULL);
  2938   bool other_has_spec = (other->speculative() != NULL);
  2940   if (!this_has_spec && !other_has_spec) {
  2941     return NULL;
  2944   // If we are at a point where control flow meets and one branch has
  2945   // a speculative type and the other has not, we meet the speculative
  2946   // type of one branch with the actual type of the other. If the
  2947   // actual type is exact and the speculative is as well, then the
  2948   // result is a speculative type which is exact and we can continue
  2949   // speculation further.
  2950   const TypeOopPtr* this_spec = _speculative;
  2951   const TypeOopPtr* other_spec = other->speculative();
  2953   if (!this_has_spec) {
  2954     this_spec = this;
  2957   if (!other_has_spec) {
  2958     other_spec = other;
  2961   return this_spec->meet(other_spec)->is_oopptr();
  2964 /**
  2965  * dual of the speculative part of the type
  2966  */
  2967 const TypeOopPtr* TypeOopPtr::dual_speculative() const {
  2968   if (_speculative == NULL) {
  2969     return NULL;
  2971   return _speculative->dual()->is_oopptr();
  2974 /**
  2975  * add offset to the speculative part of the type
  2977  * @param offset  offset to add
  2978  */
  2979 const TypeOopPtr* TypeOopPtr::add_offset_speculative(intptr_t offset) const {
  2980   if (_speculative == NULL) {
  2981     return NULL;
  2983   return _speculative->add_offset(offset)->is_oopptr();
  2986 /**
  2987  * Are the speculative parts of 2 types equal?
  2989  * @param other  type to compare this one to
  2990  */
  2991 bool TypeOopPtr::eq_speculative(const TypeOopPtr* other) const {
  2992   if (_speculative == NULL || other->speculative() == NULL) {
  2993     return _speculative == other->speculative();
  2996   if (_speculative->base() != other->speculative()->base()) {
  2997     return false;
  3000   return _speculative->eq(other->speculative());
  3003 /**
  3004  * Hash of the speculative part of the type
  3005  */
  3006 int TypeOopPtr::hash_speculative() const {
  3007   if (_speculative == NULL) {
  3008     return 0;
  3011   return _speculative->hash();
  3015 //=============================================================================
  3016 // Convenience common pre-built types.
  3017 const TypeInstPtr *TypeInstPtr::NOTNULL;
  3018 const TypeInstPtr *TypeInstPtr::BOTTOM;
  3019 const TypeInstPtr *TypeInstPtr::MIRROR;
  3020 const TypeInstPtr *TypeInstPtr::MARK;
  3021 const TypeInstPtr *TypeInstPtr::KLASS;
  3023 //------------------------------TypeInstPtr-------------------------------------
  3024 TypeInstPtr::TypeInstPtr(PTR ptr, ciKlass* k, bool xk, ciObject* o, int off, int instance_id, const TypeOopPtr* speculative)
  3025   : TypeOopPtr(InstPtr, ptr, k, xk, o, off, instance_id, speculative), _name(k->name()) {
  3026    assert(k != NULL &&
  3027           (k->is_loaded() || o == NULL),
  3028           "cannot have constants with non-loaded klass");
  3029 };
  3031 //------------------------------make-------------------------------------------
  3032 const TypeInstPtr *TypeInstPtr::make(PTR ptr,
  3033                                      ciKlass* k,
  3034                                      bool xk,
  3035                                      ciObject* o,
  3036                                      int offset,
  3037                                      int instance_id,
  3038                                      const TypeOopPtr* speculative) {
  3039   assert( !k->is_loaded() || k->is_instance_klass(), "Must be for instance");
  3040   // Either const_oop() is NULL or else ptr is Constant
  3041   assert( (!o && ptr != Constant) || (o && ptr == Constant),
  3042           "constant pointers must have a value supplied" );
  3043   // Ptr is never Null
  3044   assert( ptr != Null, "NULL pointers are not typed" );
  3046   assert(instance_id <= 0 || xk || !UseExactTypes, "instances are always exactly typed");
  3047   if (!UseExactTypes)  xk = false;
  3048   if (ptr == Constant) {
  3049     // Note:  This case includes meta-object constants, such as methods.
  3050     xk = true;
  3051   } else if (k->is_loaded()) {
  3052     ciInstanceKlass* ik = k->as_instance_klass();
  3053     if (!xk && ik->is_final())     xk = true;   // no inexact final klass
  3054     if (xk && ik->is_interface())  xk = false;  // no exact interface
  3057   // Now hash this baby
  3058   TypeInstPtr *result =
  3059     (TypeInstPtr*)(new TypeInstPtr(ptr, k, xk, o ,offset, instance_id, speculative))->hashcons();
  3061   return result;
  3064 /**
  3065  *  Create constant type for a constant boxed value
  3066  */
  3067 const Type* TypeInstPtr::get_const_boxed_value() const {
  3068   assert(is_ptr_to_boxed_value(), "should be called only for boxed value");
  3069   assert((const_oop() != NULL), "should be called only for constant object");
  3070   ciConstant constant = const_oop()->as_instance()->field_value_by_offset(offset());
  3071   BasicType bt = constant.basic_type();
  3072   switch (bt) {
  3073     case T_BOOLEAN:  return TypeInt::make(constant.as_boolean());
  3074     case T_INT:      return TypeInt::make(constant.as_int());
  3075     case T_CHAR:     return TypeInt::make(constant.as_char());
  3076     case T_BYTE:     return TypeInt::make(constant.as_byte());
  3077     case T_SHORT:    return TypeInt::make(constant.as_short());
  3078     case T_FLOAT:    return TypeF::make(constant.as_float());
  3079     case T_DOUBLE:   return TypeD::make(constant.as_double());
  3080     case T_LONG:     return TypeLong::make(constant.as_long());
  3081     default:         break;
  3083   fatal(err_msg_res("Invalid boxed value type '%s'", type2name(bt)));
  3084   return NULL;
  3087 //------------------------------cast_to_ptr_type-------------------------------
  3088 const Type *TypeInstPtr::cast_to_ptr_type(PTR ptr) const {
  3089   if( ptr == _ptr ) return this;
  3090   // Reconstruct _sig info here since not a problem with later lazy
  3091   // construction, _sig will show up on demand.
  3092   return make(ptr, klass(), klass_is_exact(), const_oop(), _offset, _instance_id, _speculative);
  3096 //-----------------------------cast_to_exactness-------------------------------
  3097 const Type *TypeInstPtr::cast_to_exactness(bool klass_is_exact) const {
  3098   if( klass_is_exact == _klass_is_exact ) return this;
  3099   if (!UseExactTypes)  return this;
  3100   if (!_klass->is_loaded())  return this;
  3101   ciInstanceKlass* ik = _klass->as_instance_klass();
  3102   if( (ik->is_final() || _const_oop) )  return this;  // cannot clear xk
  3103   if( ik->is_interface() )              return this;  // cannot set xk
  3104   return make(ptr(), klass(), klass_is_exact, const_oop(), _offset, _instance_id, _speculative);
  3107 //-----------------------------cast_to_instance_id----------------------------
  3108 const TypeOopPtr *TypeInstPtr::cast_to_instance_id(int instance_id) const {
  3109   if( instance_id == _instance_id ) return this;
  3110   return make(_ptr, klass(), _klass_is_exact, const_oop(), _offset, instance_id, _speculative);
  3113 //------------------------------xmeet_unloaded---------------------------------
  3114 // Compute the MEET of two InstPtrs when at least one is unloaded.
  3115 // Assume classes are different since called after check for same name/class-loader
  3116 const TypeInstPtr *TypeInstPtr::xmeet_unloaded(const TypeInstPtr *tinst) const {
  3117     int off = meet_offset(tinst->offset());
  3118     PTR ptr = meet_ptr(tinst->ptr());
  3119     int instance_id = meet_instance_id(tinst->instance_id());
  3120     const TypeOopPtr* speculative = meet_speculative(tinst);
  3122     const TypeInstPtr *loaded    = is_loaded() ? this  : tinst;
  3123     const TypeInstPtr *unloaded  = is_loaded() ? tinst : this;
  3124     if( loaded->klass()->equals(ciEnv::current()->Object_klass()) ) {
  3125       //
  3126       // Meet unloaded class with java/lang/Object
  3127       //
  3128       // Meet
  3129       //          |                     Unloaded Class
  3130       //  Object  |   TOP    |   AnyNull | Constant |   NotNull |  BOTTOM   |
  3131       //  ===================================================================
  3132       //   TOP    | ..........................Unloaded......................|
  3133       //  AnyNull |  U-AN    |................Unloaded......................|
  3134       // Constant | ... O-NN .................................. |   O-BOT   |
  3135       //  NotNull | ... O-NN .................................. |   O-BOT   |
  3136       //  BOTTOM  | ........................Object-BOTTOM ..................|
  3137       //
  3138       assert(loaded->ptr() != TypePtr::Null, "insanity check");
  3139       //
  3140       if(      loaded->ptr() == TypePtr::TopPTR ) { return unloaded; }
  3141       else if (loaded->ptr() == TypePtr::AnyNull) { return TypeInstPtr::make(ptr, unloaded->klass(), false, NULL, off, instance_id, speculative); }
  3142       else if (loaded->ptr() == TypePtr::BotPTR ) { return TypeInstPtr::BOTTOM; }
  3143       else if (loaded->ptr() == TypePtr::Constant || loaded->ptr() == TypePtr::NotNull) {
  3144         if (unloaded->ptr() == TypePtr::BotPTR  ) { return TypeInstPtr::BOTTOM;  }
  3145         else                                      { return TypeInstPtr::NOTNULL; }
  3147       else if( unloaded->ptr() == TypePtr::TopPTR )  { return unloaded; }
  3149       return unloaded->cast_to_ptr_type(TypePtr::AnyNull)->is_instptr();
  3152     // Both are unloaded, not the same class, not Object
  3153     // Or meet unloaded with a different loaded class, not java/lang/Object
  3154     if( ptr != TypePtr::BotPTR ) {
  3155       return TypeInstPtr::NOTNULL;
  3157     return TypeInstPtr::BOTTOM;
  3161 //------------------------------meet-------------------------------------------
  3162 // Compute the MEET of two types.  It returns a new Type object.
  3163 const Type *TypeInstPtr::xmeet_helper(const Type *t) const {
  3164   // Perform a fast test for common case; meeting the same types together.
  3165   if( this == t ) return this;  // Meeting same type-rep?
  3167   // Current "this->_base" is Pointer
  3168   switch (t->base()) {          // switch on original type
  3170   case Int:                     // Mixing ints & oops happens when javac
  3171   case Long:                    // reuses local variables
  3172   case FloatTop:
  3173   case FloatCon:
  3174   case FloatBot:
  3175   case DoubleTop:
  3176   case DoubleCon:
  3177   case DoubleBot:
  3178   case NarrowOop:
  3179   case NarrowKlass:
  3180   case Bottom:                  // Ye Olde Default
  3181     return Type::BOTTOM;
  3182   case Top:
  3183     return this;
  3185   default:                      // All else is a mistake
  3186     typerr(t);
  3188   case MetadataPtr:
  3189   case KlassPtr:
  3190   case RawPtr: return TypePtr::BOTTOM;
  3192   case AryPtr: {                // All arrays inherit from Object class
  3193     const TypeAryPtr *tp = t->is_aryptr();
  3194     int offset = meet_offset(tp->offset());
  3195     PTR ptr = meet_ptr(tp->ptr());
  3196     int instance_id = meet_instance_id(tp->instance_id());
  3197     const TypeOopPtr* speculative = meet_speculative(tp);
  3198     switch (ptr) {
  3199     case TopPTR:
  3200     case AnyNull:                // Fall 'down' to dual of object klass
  3201       // For instances when a subclass meets a superclass we fall
  3202       // below the centerline when the superclass is exact. We need to
  3203       // do the same here.
  3204       if (klass()->equals(ciEnv::current()->Object_klass()) && !klass_is_exact()) {
  3205         return TypeAryPtr::make(ptr, tp->ary(), tp->klass(), tp->klass_is_exact(), offset, instance_id, speculative);
  3206       } else {
  3207         // cannot subclass, so the meet has to fall badly below the centerline
  3208         ptr = NotNull;
  3209         instance_id = InstanceBot;
  3210         return TypeInstPtr::make( ptr, ciEnv::current()->Object_klass(), false, NULL, offset, instance_id, speculative);
  3212     case Constant:
  3213     case NotNull:
  3214     case BotPTR:                // Fall down to object klass
  3215       // LCA is object_klass, but if we subclass from the top we can do better
  3216       if( above_centerline(_ptr) ) { // if( _ptr == TopPTR || _ptr == AnyNull )
  3217         // If 'this' (InstPtr) is above the centerline and it is Object class
  3218         // then we can subclass in the Java class hierarchy.
  3219         // For instances when a subclass meets a superclass we fall
  3220         // below the centerline when the superclass is exact. We need
  3221         // to do the same here.
  3222         if (klass()->equals(ciEnv::current()->Object_klass()) && !klass_is_exact()) {
  3223           // that is, tp's array type is a subtype of my klass
  3224           return TypeAryPtr::make(ptr, (ptr == Constant ? tp->const_oop() : NULL),
  3225                                   tp->ary(), tp->klass(), tp->klass_is_exact(), offset, instance_id, speculative);
  3228       // The other case cannot happen, since I cannot be a subtype of an array.
  3229       // The meet falls down to Object class below centerline.
  3230       if( ptr == Constant )
  3231          ptr = NotNull;
  3232       instance_id = InstanceBot;
  3233       return make(ptr, ciEnv::current()->Object_klass(), false, NULL, offset, instance_id, speculative);
  3234     default: typerr(t);
  3238   case OopPtr: {                // Meeting to OopPtrs
  3239     // Found a OopPtr type vs self-InstPtr type
  3240     const TypeOopPtr *tp = t->is_oopptr();
  3241     int offset = meet_offset(tp->offset());
  3242     PTR ptr = meet_ptr(tp->ptr());
  3243     switch (tp->ptr()) {
  3244     case TopPTR:
  3245     case AnyNull: {
  3246       int instance_id = meet_instance_id(InstanceTop);
  3247       const TypeOopPtr* speculative = meet_speculative(tp);
  3248       return make(ptr, klass(), klass_is_exact(),
  3249                   (ptr == Constant ? const_oop() : NULL), offset, instance_id, speculative);
  3251     case NotNull:
  3252     case BotPTR: {
  3253       int instance_id = meet_instance_id(tp->instance_id());
  3254       const TypeOopPtr* speculative = meet_speculative(tp);
  3255       return TypeOopPtr::make(ptr, offset, instance_id, speculative);
  3257     default: typerr(t);
  3261   case AnyPtr: {                // Meeting to AnyPtrs
  3262     // Found an AnyPtr type vs self-InstPtr type
  3263     const TypePtr *tp = t->is_ptr();
  3264     int offset = meet_offset(tp->offset());
  3265     PTR ptr = meet_ptr(tp->ptr());
  3266     switch (tp->ptr()) {
  3267     case Null:
  3268       if( ptr == Null ) return TypePtr::make(AnyPtr, ptr, offset);
  3269       // else fall through to AnyNull
  3270     case TopPTR:
  3271     case AnyNull: {
  3272       int instance_id = meet_instance_id(InstanceTop);
  3273       const TypeOopPtr* speculative = _speculative;
  3274       return make(ptr, klass(), klass_is_exact(),
  3275                   (ptr == Constant ? const_oop() : NULL), offset, instance_id, speculative);
  3277     case NotNull:
  3278     case BotPTR:
  3279       return TypePtr::make(AnyPtr, ptr, offset);
  3280     default: typerr(t);
  3284   /*
  3285                  A-top         }
  3286                /   |   \       }  Tops
  3287            B-top A-any C-top   }
  3288               | /  |  \ |      }  Any-nulls
  3289            B-any   |   C-any   }
  3290               |    |    |
  3291            B-con A-con C-con   } constants; not comparable across classes
  3292               |    |    |
  3293            B-not   |   C-not   }
  3294               | \  |  / |      }  not-nulls
  3295            B-bot A-not C-bot   }
  3296                \   |   /       }  Bottoms
  3297                  A-bot         }
  3298   */
  3300   case InstPtr: {                // Meeting 2 Oops?
  3301     // Found an InstPtr sub-type vs self-InstPtr type
  3302     const TypeInstPtr *tinst = t->is_instptr();
  3303     int off = meet_offset( tinst->offset() );
  3304     PTR ptr = meet_ptr( tinst->ptr() );
  3305     int instance_id = meet_instance_id(tinst->instance_id());
  3306     const TypeOopPtr* speculative = meet_speculative(tinst);
  3308     // Check for easy case; klasses are equal (and perhaps not loaded!)
  3309     // If we have constants, then we created oops so classes are loaded
  3310     // and we can handle the constants further down.  This case handles
  3311     // both-not-loaded or both-loaded classes
  3312     if (ptr != Constant && klass()->equals(tinst->klass()) && klass_is_exact() == tinst->klass_is_exact()) {
  3313       return make(ptr, klass(), klass_is_exact(), NULL, off, instance_id, speculative);
  3316     // Classes require inspection in the Java klass hierarchy.  Must be loaded.
  3317     ciKlass* tinst_klass = tinst->klass();
  3318     ciKlass* this_klass  = this->klass();
  3319     bool tinst_xk = tinst->klass_is_exact();
  3320     bool this_xk  = this->klass_is_exact();
  3321     if (!tinst_klass->is_loaded() || !this_klass->is_loaded() ) {
  3322       // One of these classes has not been loaded
  3323       const TypeInstPtr *unloaded_meet = xmeet_unloaded(tinst);
  3324 #ifndef PRODUCT
  3325       if( PrintOpto && Verbose ) {
  3326         tty->print("meet of unloaded classes resulted in: "); unloaded_meet->dump(); tty->cr();
  3327         tty->print("  this == "); this->dump(); tty->cr();
  3328         tty->print(" tinst == "); tinst->dump(); tty->cr();
  3330 #endif
  3331       return unloaded_meet;
  3334     // Handle mixing oops and interfaces first.
  3335     if( this_klass->is_interface() && !(tinst_klass->is_interface() ||
  3336                                         tinst_klass == ciEnv::current()->Object_klass())) {
  3337       ciKlass *tmp = tinst_klass; // Swap interface around
  3338       tinst_klass = this_klass;
  3339       this_klass = tmp;
  3340       bool tmp2 = tinst_xk;
  3341       tinst_xk = this_xk;
  3342       this_xk = tmp2;
  3344     if (tinst_klass->is_interface() &&
  3345         !(this_klass->is_interface() ||
  3346           // Treat java/lang/Object as an honorary interface,
  3347           // because we need a bottom for the interface hierarchy.
  3348           this_klass == ciEnv::current()->Object_klass())) {
  3349       // Oop meets interface!
  3351       // See if the oop subtypes (implements) interface.
  3352       ciKlass *k;
  3353       bool xk;
  3354       if( this_klass->is_subtype_of( tinst_klass ) ) {
  3355         // Oop indeed subtypes.  Now keep oop or interface depending
  3356         // on whether we are both above the centerline or either is
  3357         // below the centerline.  If we are on the centerline
  3358         // (e.g., Constant vs. AnyNull interface), use the constant.
  3359         k  = below_centerline(ptr) ? tinst_klass : this_klass;
  3360         // If we are keeping this_klass, keep its exactness too.
  3361         xk = below_centerline(ptr) ? tinst_xk    : this_xk;
  3362       } else {                  // Does not implement, fall to Object
  3363         // Oop does not implement interface, so mixing falls to Object
  3364         // just like the verifier does (if both are above the
  3365         // centerline fall to interface)
  3366         k = above_centerline(ptr) ? tinst_klass : ciEnv::current()->Object_klass();
  3367         xk = above_centerline(ptr) ? tinst_xk : false;
  3368         // Watch out for Constant vs. AnyNull interface.
  3369         if (ptr == Constant)  ptr = NotNull;   // forget it was a constant
  3370         instance_id = InstanceBot;
  3372       ciObject* o = NULL;  // the Constant value, if any
  3373       if (ptr == Constant) {
  3374         // Find out which constant.
  3375         o = (this_klass == klass()) ? const_oop() : tinst->const_oop();
  3377       return make(ptr, k, xk, o, off, instance_id, speculative);
  3380     // Either oop vs oop or interface vs interface or interface vs Object
  3382     // !!! Here's how the symmetry requirement breaks down into invariants:
  3383     // If we split one up & one down AND they subtype, take the down man.
  3384     // If we split one up & one down AND they do NOT subtype, "fall hard".
  3385     // If both are up and they subtype, take the subtype class.
  3386     // If both are up and they do NOT subtype, "fall hard".
  3387     // If both are down and they subtype, take the supertype class.
  3388     // If both are down and they do NOT subtype, "fall hard".
  3389     // Constants treated as down.
  3391     // Now, reorder the above list; observe that both-down+subtype is also
  3392     // "fall hard"; "fall hard" becomes the default case:
  3393     // If we split one up & one down AND they subtype, take the down man.
  3394     // If both are up and they subtype, take the subtype class.
  3396     // If both are down and they subtype, "fall hard".
  3397     // If both are down and they do NOT subtype, "fall hard".
  3398     // If both are up and they do NOT subtype, "fall hard".
  3399     // If we split one up & one down AND they do NOT subtype, "fall hard".
  3401     // If a proper subtype is exact, and we return it, we return it exactly.
  3402     // If a proper supertype is exact, there can be no subtyping relationship!
  3403     // If both types are equal to the subtype, exactness is and-ed below the
  3404     // centerline and or-ed above it.  (N.B. Constants are always exact.)
  3406     // Check for subtyping:
  3407     ciKlass *subtype = NULL;
  3408     bool subtype_exact = false;
  3409     if( tinst_klass->equals(this_klass) ) {
  3410       subtype = this_klass;
  3411       subtype_exact = below_centerline(ptr) ? (this_xk & tinst_xk) : (this_xk | tinst_xk);
  3412     } else if( !tinst_xk && this_klass->is_subtype_of( tinst_klass ) ) {
  3413       subtype = this_klass;     // Pick subtyping class
  3414       subtype_exact = this_xk;
  3415     } else if( !this_xk && tinst_klass->is_subtype_of( this_klass ) ) {
  3416       subtype = tinst_klass;    // Pick subtyping class
  3417       subtype_exact = tinst_xk;
  3420     if( subtype ) {
  3421       if( above_centerline(ptr) ) { // both are up?
  3422         this_klass = tinst_klass = subtype;
  3423         this_xk = tinst_xk = subtype_exact;
  3424       } else if( above_centerline(this ->_ptr) && !above_centerline(tinst->_ptr) ) {
  3425         this_klass = tinst_klass; // tinst is down; keep down man
  3426         this_xk = tinst_xk;
  3427       } else if( above_centerline(tinst->_ptr) && !above_centerline(this ->_ptr) ) {
  3428         tinst_klass = this_klass; // this is down; keep down man
  3429         tinst_xk = this_xk;
  3430       } else {
  3431         this_xk = subtype_exact;  // either they are equal, or we'll do an LCA
  3435     // Check for classes now being equal
  3436     if (tinst_klass->equals(this_klass)) {
  3437       // If the klasses are equal, the constants may still differ.  Fall to
  3438       // NotNull if they do (neither constant is NULL; that is a special case
  3439       // handled elsewhere).
  3440       ciObject* o = NULL;             // Assume not constant when done
  3441       ciObject* this_oop  = const_oop();
  3442       ciObject* tinst_oop = tinst->const_oop();
  3443       if( ptr == Constant ) {
  3444         if (this_oop != NULL && tinst_oop != NULL &&
  3445             this_oop->equals(tinst_oop) )
  3446           o = this_oop;
  3447         else if (above_centerline(this ->_ptr))
  3448           o = tinst_oop;
  3449         else if (above_centerline(tinst ->_ptr))
  3450           o = this_oop;
  3451         else
  3452           ptr = NotNull;
  3454       return make(ptr, this_klass, this_xk, o, off, instance_id, speculative);
  3455     } // Else classes are not equal
  3457     // Since klasses are different, we require a LCA in the Java
  3458     // class hierarchy - which means we have to fall to at least NotNull.
  3459     if( ptr == TopPTR || ptr == AnyNull || ptr == Constant )
  3460       ptr = NotNull;
  3461     instance_id = InstanceBot;
  3463     // Now we find the LCA of Java classes
  3464     ciKlass* k = this_klass->least_common_ancestor(tinst_klass);
  3465     return make(ptr, k, false, NULL, off, instance_id, speculative);
  3466   } // End of case InstPtr
  3468   } // End of switch
  3469   return this;                  // Return the double constant
  3473 //------------------------java_mirror_type--------------------------------------
  3474 ciType* TypeInstPtr::java_mirror_type() const {
  3475   // must be a singleton type
  3476   if( const_oop() == NULL )  return NULL;
  3478   // must be of type java.lang.Class
  3479   if( klass() != ciEnv::current()->Class_klass() )  return NULL;
  3481   return const_oop()->as_instance()->java_mirror_type();
  3485 //------------------------------xdual------------------------------------------
  3486 // Dual: do NOT dual on klasses.  This means I do NOT understand the Java
  3487 // inheritance mechanism.
  3488 const Type *TypeInstPtr::xdual() const {
  3489   return new TypeInstPtr(dual_ptr(), klass(), klass_is_exact(), const_oop(), dual_offset(), dual_instance_id(), dual_speculative());
  3492 //------------------------------eq---------------------------------------------
  3493 // Structural equality check for Type representations
  3494 bool TypeInstPtr::eq( const Type *t ) const {
  3495   const TypeInstPtr *p = t->is_instptr();
  3496   return
  3497     klass()->equals(p->klass()) &&
  3498     TypeOopPtr::eq(p);          // Check sub-type stuff
  3501 //------------------------------hash-------------------------------------------
  3502 // Type-specific hashing function.
  3503 int TypeInstPtr::hash(void) const {
  3504   int hash = klass()->hash() + TypeOopPtr::hash();
  3505   return hash;
  3508 //------------------------------dump2------------------------------------------
  3509 // Dump oop Type
  3510 #ifndef PRODUCT
  3511 void TypeInstPtr::dump2( Dict &d, uint depth, outputStream *st ) const {
  3512   // Print the name of the klass.
  3513   klass()->print_name_on(st);
  3515   switch( _ptr ) {
  3516   case Constant:
  3517     // TO DO: Make CI print the hex address of the underlying oop.
  3518     if (WizardMode || Verbose) {
  3519       const_oop()->print_oop(st);
  3521   case BotPTR:
  3522     if (!WizardMode && !Verbose) {
  3523       if( _klass_is_exact ) st->print(":exact");
  3524       break;
  3526   case TopPTR:
  3527   case AnyNull:
  3528   case NotNull:
  3529     st->print(":%s", ptr_msg[_ptr]);
  3530     if( _klass_is_exact ) st->print(":exact");
  3531     break;
  3534   if( _offset ) {               // Dump offset, if any
  3535     if( _offset == OffsetBot )      st->print("+any");
  3536     else if( _offset == OffsetTop ) st->print("+unknown");
  3537     else st->print("+%d", _offset);
  3540   st->print(" *");
  3541   if (_instance_id == InstanceTop)
  3542     st->print(",iid=top");
  3543   else if (_instance_id != InstanceBot)
  3544     st->print(",iid=%d",_instance_id);
  3546   dump_speculative(st);
  3548 #endif
  3550 //------------------------------add_offset-------------------------------------
  3551 const TypePtr *TypeInstPtr::add_offset(intptr_t offset) const {
  3552   return make(_ptr, klass(), klass_is_exact(), const_oop(), xadd_offset(offset), _instance_id, add_offset_speculative(offset));
  3555 const TypeOopPtr *TypeInstPtr::remove_speculative() const {
  3556   return make(_ptr, klass(), klass_is_exact(), const_oop(), _offset, _instance_id, NULL);
  3559 //=============================================================================
  3560 // Convenience common pre-built types.
  3561 const TypeAryPtr *TypeAryPtr::RANGE;
  3562 const TypeAryPtr *TypeAryPtr::OOPS;
  3563 const TypeAryPtr *TypeAryPtr::NARROWOOPS;
  3564 const TypeAryPtr *TypeAryPtr::BYTES;
  3565 const TypeAryPtr *TypeAryPtr::SHORTS;
  3566 const TypeAryPtr *TypeAryPtr::CHARS;
  3567 const TypeAryPtr *TypeAryPtr::INTS;
  3568 const TypeAryPtr *TypeAryPtr::LONGS;
  3569 const TypeAryPtr *TypeAryPtr::FLOATS;
  3570 const TypeAryPtr *TypeAryPtr::DOUBLES;
  3572 //------------------------------make-------------------------------------------
  3573 const TypeAryPtr *TypeAryPtr::make(PTR ptr, const TypeAry *ary, ciKlass* k, bool xk, int offset, int instance_id, const TypeOopPtr* speculative) {
  3574   assert(!(k == NULL && ary->_elem->isa_int()),
  3575          "integral arrays must be pre-equipped with a class");
  3576   if (!xk)  xk = ary->ary_must_be_exact();
  3577   assert(instance_id <= 0 || xk || !UseExactTypes, "instances are always exactly typed");
  3578   if (!UseExactTypes)  xk = (ptr == Constant);
  3579   return (TypeAryPtr*)(new TypeAryPtr(ptr, NULL, ary, k, xk, offset, instance_id, false, speculative))->hashcons();
  3582 //------------------------------make-------------------------------------------
  3583 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) {
  3584   assert(!(k == NULL && ary->_elem->isa_int()),
  3585          "integral arrays must be pre-equipped with a class");
  3586   assert( (ptr==Constant && o) || (ptr!=Constant && !o), "" );
  3587   if (!xk)  xk = (o != NULL) || ary->ary_must_be_exact();
  3588   assert(instance_id <= 0 || xk || !UseExactTypes, "instances are always exactly typed");
  3589   if (!UseExactTypes)  xk = (ptr == Constant);
  3590   return (TypeAryPtr*)(new TypeAryPtr(ptr, o, ary, k, xk, offset, instance_id, is_autobox_cache, speculative))->hashcons();
  3593 //------------------------------cast_to_ptr_type-------------------------------
  3594 const Type *TypeAryPtr::cast_to_ptr_type(PTR ptr) const {
  3595   if( ptr == _ptr ) return this;
  3596   return make(ptr, const_oop(), _ary, klass(), klass_is_exact(), _offset, _instance_id, _speculative);
  3600 //-----------------------------cast_to_exactness-------------------------------
  3601 const Type *TypeAryPtr::cast_to_exactness(bool klass_is_exact) const {
  3602   if( klass_is_exact == _klass_is_exact ) return this;
  3603   if (!UseExactTypes)  return this;
  3604   if (_ary->ary_must_be_exact())  return this;  // cannot clear xk
  3605   return make(ptr(), const_oop(), _ary, klass(), klass_is_exact, _offset, _instance_id, _speculative);
  3608 //-----------------------------cast_to_instance_id----------------------------
  3609 const TypeOopPtr *TypeAryPtr::cast_to_instance_id(int instance_id) const {
  3610   if( instance_id == _instance_id ) return this;
  3611   return make(_ptr, const_oop(), _ary, klass(), _klass_is_exact, _offset, instance_id, _speculative);
  3614 //-----------------------------narrow_size_type-------------------------------
  3615 // Local cache for arrayOopDesc::max_array_length(etype),
  3616 // which is kind of slow (and cached elsewhere by other users).
  3617 static jint max_array_length_cache[T_CONFLICT+1];
  3618 static jint max_array_length(BasicType etype) {
  3619   jint& cache = max_array_length_cache[etype];
  3620   jint res = cache;
  3621   if (res == 0) {
  3622     switch (etype) {
  3623     case T_NARROWOOP:
  3624       etype = T_OBJECT;
  3625       break;
  3626     case T_NARROWKLASS:
  3627     case T_CONFLICT:
  3628     case T_ILLEGAL:
  3629     case T_VOID:
  3630       etype = T_BYTE;           // will produce conservatively high value
  3632     cache = res = arrayOopDesc::max_array_length(etype);
  3634   return res;
  3637 // Narrow the given size type to the index range for the given array base type.
  3638 // Return NULL if the resulting int type becomes empty.
  3639 const TypeInt* TypeAryPtr::narrow_size_type(const TypeInt* size) const {
  3640   jint hi = size->_hi;
  3641   jint lo = size->_lo;
  3642   jint min_lo = 0;
  3643   jint max_hi = max_array_length(elem()->basic_type());
  3644   //if (index_not_size)  --max_hi;     // type of a valid array index, FTR
  3645   bool chg = false;
  3646   if (lo < min_lo) {
  3647     lo = min_lo;
  3648     if (size->is_con()) {
  3649       hi = lo;
  3651     chg = true;
  3653   if (hi > max_hi) {
  3654     hi = max_hi;
  3655     if (size->is_con()) {
  3656       lo = hi;
  3658     chg = true;
  3660   // Negative length arrays will produce weird intermediate dead fast-path code
  3661   if (lo > hi)
  3662     return TypeInt::ZERO;
  3663   if (!chg)
  3664     return size;
  3665   return TypeInt::make(lo, hi, Type::WidenMin);
  3668 //-------------------------------cast_to_size----------------------------------
  3669 const TypeAryPtr* TypeAryPtr::cast_to_size(const TypeInt* new_size) const {
  3670   assert(new_size != NULL, "");
  3671   new_size = narrow_size_type(new_size);
  3672   if (new_size == size())  return this;
  3673   const TypeAry* new_ary = TypeAry::make(elem(), new_size, is_stable());
  3674   return make(ptr(), const_oop(), new_ary, klass(), klass_is_exact(), _offset, _instance_id, _speculative);
  3678 //------------------------------cast_to_stable---------------------------------
  3679 const TypeAryPtr* TypeAryPtr::cast_to_stable(bool stable, int stable_dimension) const {
  3680   if (stable_dimension <= 0 || (stable_dimension == 1 && stable == this->is_stable()))
  3681     return this;
  3683   const Type* elem = this->elem();
  3684   const TypePtr* elem_ptr = elem->make_ptr();
  3686   if (stable_dimension > 1 && elem_ptr != NULL && elem_ptr->isa_aryptr()) {
  3687     // If this is widened from a narrow oop, TypeAry::make will re-narrow it.
  3688     elem = elem_ptr = elem_ptr->is_aryptr()->cast_to_stable(stable, stable_dimension - 1);
  3691   const TypeAry* new_ary = TypeAry::make(elem, size(), stable);
  3693   return make(ptr(), const_oop(), new_ary, klass(), klass_is_exact(), _offset, _instance_id);
  3696 //-----------------------------stable_dimension--------------------------------
  3697 int TypeAryPtr::stable_dimension() const {
  3698   if (!is_stable())  return 0;
  3699   int dim = 1;
  3700   const TypePtr* elem_ptr = elem()->make_ptr();
  3701   if (elem_ptr != NULL && elem_ptr->isa_aryptr())
  3702     dim += elem_ptr->is_aryptr()->stable_dimension();
  3703   return dim;
  3706 //------------------------------eq---------------------------------------------
  3707 // Structural equality check for Type representations
  3708 bool TypeAryPtr::eq( const Type *t ) const {
  3709   const TypeAryPtr *p = t->is_aryptr();
  3710   return
  3711     _ary == p->_ary &&  // Check array
  3712     TypeOopPtr::eq(p);  // Check sub-parts
  3715 //------------------------------hash-------------------------------------------
  3716 // Type-specific hashing function.
  3717 int TypeAryPtr::hash(void) const {
  3718   return (intptr_t)_ary + TypeOopPtr::hash();
  3721 //------------------------------meet-------------------------------------------
  3722 // Compute the MEET of two types.  It returns a new Type object.
  3723 const Type *TypeAryPtr::xmeet_helper(const Type *t) const {
  3724   // Perform a fast test for common case; meeting the same types together.
  3725   if( this == t ) return this;  // Meeting same type-rep?
  3726   // Current "this->_base" is Pointer
  3727   switch (t->base()) {          // switch on original type
  3729   // Mixing ints & oops happens when javac reuses local variables
  3730   case Int:
  3731   case Long:
  3732   case FloatTop:
  3733   case FloatCon:
  3734   case FloatBot:
  3735   case DoubleTop:
  3736   case DoubleCon:
  3737   case DoubleBot:
  3738   case NarrowOop:
  3739   case NarrowKlass:
  3740   case Bottom:                  // Ye Olde Default
  3741     return Type::BOTTOM;
  3742   case Top:
  3743     return this;
  3745   default:                      // All else is a mistake
  3746     typerr(t);
  3748   case OopPtr: {                // Meeting to OopPtrs
  3749     // Found a OopPtr type vs self-AryPtr type
  3750     const TypeOopPtr *tp = t->is_oopptr();
  3751     int offset = meet_offset(tp->offset());
  3752     PTR ptr = meet_ptr(tp->ptr());
  3753     switch (tp->ptr()) {
  3754     case TopPTR:
  3755     case AnyNull: {
  3756       int instance_id = meet_instance_id(InstanceTop);
  3757       const TypeOopPtr* speculative = meet_speculative(tp);
  3758       return make(ptr, (ptr == Constant ? const_oop() : NULL),
  3759                   _ary, _klass, _klass_is_exact, offset, instance_id, speculative);
  3761     case BotPTR:
  3762     case NotNull: {
  3763       int instance_id = meet_instance_id(tp->instance_id());
  3764       const TypeOopPtr* speculative = meet_speculative(tp);
  3765       return TypeOopPtr::make(ptr, offset, instance_id, speculative);
  3767     default: ShouldNotReachHere();
  3771   case AnyPtr: {                // Meeting two AnyPtrs
  3772     // Found an AnyPtr type vs self-AryPtr type
  3773     const TypePtr *tp = t->is_ptr();
  3774     int offset = meet_offset(tp->offset());
  3775     PTR ptr = meet_ptr(tp->ptr());
  3776     switch (tp->ptr()) {
  3777     case TopPTR:
  3778       return this;
  3779     case BotPTR:
  3780     case NotNull:
  3781       return TypePtr::make(AnyPtr, ptr, offset);
  3782     case Null:
  3783       if( ptr == Null ) return TypePtr::make(AnyPtr, ptr, offset);
  3784       // else fall through to AnyNull
  3785     case AnyNull: {
  3786       int instance_id = meet_instance_id(InstanceTop);
  3787       const TypeOopPtr* speculative = _speculative;
  3788       return make(ptr, (ptr == Constant ? const_oop() : NULL),
  3789                   _ary, _klass, _klass_is_exact, offset, instance_id, speculative);
  3791     default: ShouldNotReachHere();
  3795   case MetadataPtr:
  3796   case KlassPtr:
  3797   case RawPtr: return TypePtr::BOTTOM;
  3799   case AryPtr: {                // Meeting 2 references?
  3800     const TypeAryPtr *tap = t->is_aryptr();
  3801     int off = meet_offset(tap->offset());
  3802     const TypeAry *tary = _ary->meet(tap->_ary)->is_ary();
  3803     PTR ptr = meet_ptr(tap->ptr());
  3804     int instance_id = meet_instance_id(tap->instance_id());
  3805     const TypeOopPtr* speculative = meet_speculative(tap);
  3806     ciKlass* lazy_klass = NULL;
  3807     if (tary->_elem->isa_int()) {
  3808       // Integral array element types have irrelevant lattice relations.
  3809       // It is the klass that determines array layout, not the element type.
  3810       if (_klass == NULL)
  3811         lazy_klass = tap->_klass;
  3812       else if (tap->_klass == NULL || tap->_klass == _klass) {
  3813         lazy_klass = _klass;
  3814       } else {
  3815         // Something like byte[int+] meets char[int+].
  3816         // This must fall to bottom, not (int[-128..65535])[int+].
  3817         instance_id = InstanceBot;
  3818         tary = TypeAry::make(Type::BOTTOM, tary->_size, tary->_stable);
  3820     } else // Non integral arrays.
  3821     // Must fall to bottom if exact klasses in upper lattice
  3822     // are not equal or super klass is exact.
  3823     if ( above_centerline(ptr) && klass() != tap->klass() &&
  3824          // meet with top[] and bottom[] are processed further down:
  3825          tap ->_klass != NULL  && this->_klass != NULL   &&
  3826          // both are exact and not equal:
  3827         ((tap ->_klass_is_exact && this->_klass_is_exact) ||
  3828          // 'tap'  is exact and super or unrelated:
  3829          (tap ->_klass_is_exact && !tap->klass()->is_subtype_of(klass())) ||
  3830          // 'this' is exact and super or unrelated:
  3831          (this->_klass_is_exact && !klass()->is_subtype_of(tap->klass())))) {
  3832       tary = TypeAry::make(Type::BOTTOM, tary->_size, tary->_stable);
  3833       return make(NotNull, NULL, tary, lazy_klass, false, off, InstanceBot);
  3836     bool xk = false;
  3837     switch (tap->ptr()) {
  3838     case AnyNull:
  3839     case TopPTR:
  3840       // Compute new klass on demand, do not use tap->_klass
  3841       if (below_centerline(this->_ptr)) {
  3842         xk = this->_klass_is_exact;
  3843       } else {
  3844         xk = (tap->_klass_is_exact | this->_klass_is_exact);
  3846       return make(ptr, const_oop(), tary, lazy_klass, xk, off, instance_id, speculative);
  3847     case Constant: {
  3848       ciObject* o = const_oop();
  3849       if( _ptr == Constant ) {
  3850         if( tap->const_oop() != NULL && !o->equals(tap->const_oop()) ) {
  3851           xk = (klass() == tap->klass());
  3852           ptr = NotNull;
  3853           o = NULL;
  3854           instance_id = InstanceBot;
  3855         } else {
  3856           xk = true;
  3858       } else if(above_centerline(_ptr)) {
  3859         o = tap->const_oop();
  3860         xk = true;
  3861       } else {
  3862         // Only precise for identical arrays
  3863         xk = this->_klass_is_exact && (klass() == tap->klass());
  3865       return TypeAryPtr::make(ptr, o, tary, lazy_klass, xk, off, instance_id, speculative);
  3867     case NotNull:
  3868     case BotPTR:
  3869       // Compute new klass on demand, do not use tap->_klass
  3870       if (above_centerline(this->_ptr))
  3871             xk = tap->_klass_is_exact;
  3872       else  xk = (tap->_klass_is_exact & this->_klass_is_exact) &&
  3873               (klass() == tap->klass()); // Only precise for identical arrays
  3874       return TypeAryPtr::make(ptr, NULL, tary, lazy_klass, xk, off, instance_id, speculative);
  3875     default: ShouldNotReachHere();
  3879   // All arrays inherit from Object class
  3880   case InstPtr: {
  3881     const TypeInstPtr *tp = t->is_instptr();
  3882     int offset = meet_offset(tp->offset());
  3883     PTR ptr = meet_ptr(tp->ptr());
  3884     int instance_id = meet_instance_id(tp->instance_id());
  3885     const TypeOopPtr* speculative = meet_speculative(tp);
  3886     switch (ptr) {
  3887     case TopPTR:
  3888     case AnyNull:                // Fall 'down' to dual of object klass
  3889       // For instances when a subclass meets a superclass we fall
  3890       // below the centerline when the superclass is exact. We need to
  3891       // do the same here.
  3892       if (tp->klass()->equals(ciEnv::current()->Object_klass()) && !tp->klass_is_exact()) {
  3893         return TypeAryPtr::make(ptr, _ary, _klass, _klass_is_exact, offset, instance_id, speculative);
  3894       } else {
  3895         // cannot subclass, so the meet has to fall badly below the centerline
  3896         ptr = NotNull;
  3897         instance_id = InstanceBot;
  3898         return TypeInstPtr::make(ptr, ciEnv::current()->Object_klass(), false, NULL,offset, instance_id, speculative);
  3900     case Constant:
  3901     case NotNull:
  3902     case BotPTR:                // Fall down to object klass
  3903       // LCA is object_klass, but if we subclass from the top we can do better
  3904       if (above_centerline(tp->ptr())) {
  3905         // If 'tp'  is above the centerline and it is Object class
  3906         // then we can subclass in the Java class hierarchy.
  3907         // For instances when a subclass meets a superclass we fall
  3908         // below the centerline when the superclass is exact. We need
  3909         // to do the same here.
  3910         if (tp->klass()->equals(ciEnv::current()->Object_klass()) && !tp->klass_is_exact()) {
  3911           // that is, my array type is a subtype of 'tp' klass
  3912           return make(ptr, (ptr == Constant ? const_oop() : NULL),
  3913                       _ary, _klass, _klass_is_exact, offset, instance_id, speculative);
  3916       // The other case cannot happen, since t cannot be a subtype of an array.
  3917       // The meet falls down to Object class below centerline.
  3918       if( ptr == Constant )
  3919          ptr = NotNull;
  3920       instance_id = InstanceBot;
  3921       return TypeInstPtr::make(ptr, ciEnv::current()->Object_klass(), false, NULL,offset, instance_id, speculative);
  3922     default: typerr(t);
  3926   return this;                  // Lint noise
  3929 //------------------------------xdual------------------------------------------
  3930 // Dual: compute field-by-field dual
  3931 const Type *TypeAryPtr::xdual() const {
  3932   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());
  3935 //----------------------interface_vs_oop---------------------------------------
  3936 #ifdef ASSERT
  3937 bool TypeAryPtr::interface_vs_oop(const Type *t) const {
  3938   const TypeAryPtr* t_aryptr = t->isa_aryptr();
  3939   if (t_aryptr) {
  3940     return _ary->interface_vs_oop(t_aryptr->_ary);
  3942   return false;
  3944 #endif
  3946 //------------------------------dump2------------------------------------------
  3947 #ifndef PRODUCT
  3948 void TypeAryPtr::dump2( Dict &d, uint depth, outputStream *st ) const {
  3949   _ary->dump2(d,depth,st);
  3950   switch( _ptr ) {
  3951   case Constant:
  3952     const_oop()->print(st);
  3953     break;
  3954   case BotPTR:
  3955     if (!WizardMode && !Verbose) {
  3956       if( _klass_is_exact ) st->print(":exact");
  3957       break;
  3959   case TopPTR:
  3960   case AnyNull:
  3961   case NotNull:
  3962     st->print(":%s", ptr_msg[_ptr]);
  3963     if( _klass_is_exact ) st->print(":exact");
  3964     break;
  3967   if( _offset != 0 ) {
  3968     int header_size = objArrayOopDesc::header_size() * wordSize;
  3969     if( _offset == OffsetTop )       st->print("+undefined");
  3970     else if( _offset == OffsetBot )  st->print("+any");
  3971     else if( _offset < header_size ) st->print("+%d", _offset);
  3972     else {
  3973       BasicType basic_elem_type = elem()->basic_type();
  3974       int array_base = arrayOopDesc::base_offset_in_bytes(basic_elem_type);
  3975       int elem_size = type2aelembytes(basic_elem_type);
  3976       st->print("[%d]", (_offset - array_base)/elem_size);
  3979   st->print(" *");
  3980   if (_instance_id == InstanceTop)
  3981     st->print(",iid=top");
  3982   else if (_instance_id != InstanceBot)
  3983     st->print(",iid=%d",_instance_id);
  3985   dump_speculative(st);
  3987 #endif
  3989 bool TypeAryPtr::empty(void) const {
  3990   if (_ary->empty())       return true;
  3991   return TypeOopPtr::empty();
  3994 //------------------------------add_offset-------------------------------------
  3995 const TypePtr *TypeAryPtr::add_offset(intptr_t offset) const {
  3996   return make(_ptr, _const_oop, _ary, _klass, _klass_is_exact, xadd_offset(offset), _instance_id, add_offset_speculative(offset));
  3999 const TypeOopPtr *TypeAryPtr::remove_speculative() const {
  4000   return make(_ptr, _const_oop, _ary, _klass, _klass_is_exact, _offset, _instance_id, NULL);
  4003 //=============================================================================
  4005 //------------------------------hash-------------------------------------------
  4006 // Type-specific hashing function.
  4007 int TypeNarrowPtr::hash(void) const {
  4008   return _ptrtype->hash() + 7;
  4011 bool TypeNarrowPtr::singleton(void) const {    // TRUE if type is a singleton
  4012   return _ptrtype->singleton();
  4015 bool TypeNarrowPtr::empty(void) const {
  4016   return _ptrtype->empty();
  4019 intptr_t TypeNarrowPtr::get_con() const {
  4020   return _ptrtype->get_con();
  4023 bool TypeNarrowPtr::eq( const Type *t ) const {
  4024   const TypeNarrowPtr* tc = isa_same_narrowptr(t);
  4025   if (tc != NULL) {
  4026     if (_ptrtype->base() != tc->_ptrtype->base()) {
  4027       return false;
  4029     return tc->_ptrtype->eq(_ptrtype);
  4031   return false;
  4034 const Type *TypeNarrowPtr::xdual() const {    // Compute dual right now.
  4035   const TypePtr* odual = _ptrtype->dual()->is_ptr();
  4036   return make_same_narrowptr(odual);
  4040 const Type *TypeNarrowPtr::filter( const Type *kills ) const {
  4041   if (isa_same_narrowptr(kills)) {
  4042     const Type* ft =_ptrtype->filter(is_same_narrowptr(kills)->_ptrtype);
  4043     if (ft->empty())
  4044       return Type::TOP;           // Canonical empty value
  4045     if (ft->isa_ptr()) {
  4046       return make_hash_same_narrowptr(ft->isa_ptr());
  4048     return ft;
  4049   } else if (kills->isa_ptr()) {
  4050     const Type* ft = _ptrtype->join(kills);
  4051     if (ft->empty())
  4052       return Type::TOP;           // Canonical empty value
  4053     return ft;
  4054   } else {
  4055     return Type::TOP;
  4059 //------------------------------xmeet------------------------------------------
  4060 // Compute the MEET of two types.  It returns a new Type object.
  4061 const Type *TypeNarrowPtr::xmeet( const Type *t ) const {
  4062   // Perform a fast test for common case; meeting the same types together.
  4063   if( this == t ) return this;  // Meeting same type-rep?
  4065   if (t->base() == base()) {
  4066     const Type* result = _ptrtype->xmeet(t->make_ptr());
  4067     if (result->isa_ptr()) {
  4068       return make_hash_same_narrowptr(result->is_ptr());
  4070     return result;
  4073   // Current "this->_base" is NarrowKlass or NarrowOop
  4074   switch (t->base()) {          // switch on original type
  4076   case Int:                     // Mixing ints & oops happens when javac
  4077   case Long:                    // reuses local variables
  4078   case FloatTop:
  4079   case FloatCon:
  4080   case FloatBot:
  4081   case DoubleTop:
  4082   case DoubleCon:
  4083   case DoubleBot:
  4084   case AnyPtr:
  4085   case RawPtr:
  4086   case OopPtr:
  4087   case InstPtr:
  4088   case AryPtr:
  4089   case MetadataPtr:
  4090   case KlassPtr:
  4091   case NarrowOop:
  4092   case NarrowKlass:
  4094   case Bottom:                  // Ye Olde Default
  4095     return Type::BOTTOM;
  4096   case Top:
  4097     return this;
  4099   default:                      // All else is a mistake
  4100     typerr(t);
  4102   } // End of switch
  4104   return this;
  4107 #ifndef PRODUCT
  4108 void TypeNarrowPtr::dump2( Dict & d, uint depth, outputStream *st ) const {
  4109   _ptrtype->dump2(d, depth, st);
  4111 #endif
  4113 const TypeNarrowOop *TypeNarrowOop::BOTTOM;
  4114 const TypeNarrowOop *TypeNarrowOop::NULL_PTR;
  4117 const TypeNarrowOop* TypeNarrowOop::make(const TypePtr* type) {
  4118   return (const TypeNarrowOop*)(new TypeNarrowOop(type))->hashcons();
  4122 #ifndef PRODUCT
  4123 void TypeNarrowOop::dump2( Dict & d, uint depth, outputStream *st ) const {
  4124   st->print("narrowoop: ");
  4125   TypeNarrowPtr::dump2(d, depth, st);
  4127 #endif
  4129 const TypeNarrowKlass *TypeNarrowKlass::NULL_PTR;
  4131 const TypeNarrowKlass* TypeNarrowKlass::make(const TypePtr* type) {
  4132   return (const TypeNarrowKlass*)(new TypeNarrowKlass(type))->hashcons();
  4135 #ifndef PRODUCT
  4136 void TypeNarrowKlass::dump2( Dict & d, uint depth, outputStream *st ) const {
  4137   st->print("narrowklass: ");
  4138   TypeNarrowPtr::dump2(d, depth, st);
  4140 #endif
  4143 //------------------------------eq---------------------------------------------
  4144 // Structural equality check for Type representations
  4145 bool TypeMetadataPtr::eq( const Type *t ) const {
  4146   const TypeMetadataPtr *a = (const TypeMetadataPtr*)t;
  4147   ciMetadata* one = metadata();
  4148   ciMetadata* two = a->metadata();
  4149   if (one == NULL || two == NULL) {
  4150     return (one == two) && TypePtr::eq(t);
  4151   } else {
  4152     return one->equals(two) && TypePtr::eq(t);
  4156 //------------------------------hash-------------------------------------------
  4157 // Type-specific hashing function.
  4158 int TypeMetadataPtr::hash(void) const {
  4159   return
  4160     (metadata() ? metadata()->hash() : 0) +
  4161     TypePtr::hash();
  4164 //------------------------------singleton--------------------------------------
  4165 // TRUE if Type is a singleton type, FALSE otherwise.   Singletons are simple
  4166 // constants
  4167 bool TypeMetadataPtr::singleton(void) const {
  4168   // detune optimizer to not generate constant metadta + constant offset as a constant!
  4169   // TopPTR, Null, AnyNull, Constant are all singletons
  4170   return (_offset == 0) && !below_centerline(_ptr);
  4173 //------------------------------add_offset-------------------------------------
  4174 const TypePtr *TypeMetadataPtr::add_offset( intptr_t offset ) const {
  4175   return make( _ptr, _metadata, xadd_offset(offset));
  4178 //-----------------------------filter------------------------------------------
  4179 // Do not allow interface-vs.-noninterface joins to collapse to top.
  4180 const Type *TypeMetadataPtr::filter( const Type *kills ) const {
  4181   const TypeMetadataPtr* ft = join(kills)->isa_metadataptr();
  4182   if (ft == NULL || ft->empty())
  4183     return Type::TOP;           // Canonical empty value
  4184   return ft;
  4187  //------------------------------get_con----------------------------------------
  4188 intptr_t TypeMetadataPtr::get_con() const {
  4189   assert( _ptr == Null || _ptr == Constant, "" );
  4190   assert( _offset >= 0, "" );
  4192   if (_offset != 0) {
  4193     // After being ported to the compiler interface, the compiler no longer
  4194     // directly manipulates the addresses of oops.  Rather, it only has a pointer
  4195     // to a handle at compile time.  This handle is embedded in the generated
  4196     // code and dereferenced at the time the nmethod is made.  Until that time,
  4197     // it is not reasonable to do arithmetic with the addresses of oops (we don't
  4198     // have access to the addresses!).  This does not seem to currently happen,
  4199     // but this assertion here is to help prevent its occurence.
  4200     tty->print_cr("Found oop constant with non-zero offset");
  4201     ShouldNotReachHere();
  4204   return (intptr_t)metadata()->constant_encoding();
  4207 //------------------------------cast_to_ptr_type-------------------------------
  4208 const Type *TypeMetadataPtr::cast_to_ptr_type(PTR ptr) const {
  4209   if( ptr == _ptr ) return this;
  4210   return make(ptr, metadata(), _offset);
  4213 //------------------------------meet-------------------------------------------
  4214 // Compute the MEET of two types.  It returns a new Type object.
  4215 const Type *TypeMetadataPtr::xmeet( const Type *t ) const {
  4216   // Perform a fast test for common case; meeting the same types together.
  4217   if( this == t ) return this;  // Meeting same type-rep?
  4219   // Current "this->_base" is OopPtr
  4220   switch (t->base()) {          // switch on original type
  4222   case Int:                     // Mixing ints & oops happens when javac
  4223   case Long:                    // reuses local variables
  4224   case FloatTop:
  4225   case FloatCon:
  4226   case FloatBot:
  4227   case DoubleTop:
  4228   case DoubleCon:
  4229   case DoubleBot:
  4230   case NarrowOop:
  4231   case NarrowKlass:
  4232   case Bottom:                  // Ye Olde Default
  4233     return Type::BOTTOM;
  4234   case Top:
  4235     return this;
  4237   default:                      // All else is a mistake
  4238     typerr(t);
  4240   case AnyPtr: {
  4241     // Found an AnyPtr type vs self-OopPtr type
  4242     const TypePtr *tp = t->is_ptr();
  4243     int offset = meet_offset(tp->offset());
  4244     PTR ptr = meet_ptr(tp->ptr());
  4245     switch (tp->ptr()) {
  4246     case Null:
  4247       if (ptr == Null)  return TypePtr::make(AnyPtr, ptr, offset);
  4248       // else fall through:
  4249     case TopPTR:
  4250     case AnyNull: {
  4251       return make(ptr, NULL, offset);
  4253     case BotPTR:
  4254     case NotNull:
  4255       return TypePtr::make(AnyPtr, ptr, offset);
  4256     default: typerr(t);
  4260   case RawPtr:
  4261   case KlassPtr:
  4262   case OopPtr:
  4263   case InstPtr:
  4264   case AryPtr:
  4265     return TypePtr::BOTTOM;     // Oop meet raw is not well defined
  4267   case MetadataPtr: {
  4268     const TypeMetadataPtr *tp = t->is_metadataptr();
  4269     int offset = meet_offset(tp->offset());
  4270     PTR tptr = tp->ptr();
  4271     PTR ptr = meet_ptr(tptr);
  4272     ciMetadata* md = (tptr == TopPTR) ? metadata() : tp->metadata();
  4273     if (tptr == TopPTR || _ptr == TopPTR ||
  4274         metadata()->equals(tp->metadata())) {
  4275       return make(ptr, md, offset);
  4277     // metadata is different
  4278     if( ptr == Constant ) {  // Cannot be equal constants, so...
  4279       if( tptr == Constant && _ptr != Constant)  return t;
  4280       if( _ptr == Constant && tptr != Constant)  return this;
  4281       ptr = NotNull;            // Fall down in lattice
  4283     return make(ptr, NULL, offset);
  4284     break;
  4286   } // End of switch
  4287   return this;                  // Return the double constant
  4291 //------------------------------xdual------------------------------------------
  4292 // Dual of a pure metadata pointer.
  4293 const Type *TypeMetadataPtr::xdual() const {
  4294   return new TypeMetadataPtr(dual_ptr(), metadata(), dual_offset());
  4297 //------------------------------dump2------------------------------------------
  4298 #ifndef PRODUCT
  4299 void TypeMetadataPtr::dump2( Dict &d, uint depth, outputStream *st ) const {
  4300   st->print("metadataptr:%s", ptr_msg[_ptr]);
  4301   if( metadata() ) st->print(INTPTR_FORMAT, metadata());
  4302   switch( _offset ) {
  4303   case OffsetTop: st->print("+top"); break;
  4304   case OffsetBot: st->print("+any"); break;
  4305   case         0: break;
  4306   default:        st->print("+%d",_offset); break;
  4309 #endif
  4312 //=============================================================================
  4313 // Convenience common pre-built type.
  4314 const TypeMetadataPtr *TypeMetadataPtr::BOTTOM;
  4316 TypeMetadataPtr::TypeMetadataPtr(PTR ptr, ciMetadata* metadata, int offset):
  4317   TypePtr(MetadataPtr, ptr, offset), _metadata(metadata) {
  4320 const TypeMetadataPtr* TypeMetadataPtr::make(ciMethod* m) {
  4321   return make(Constant, m, 0);
  4323 const TypeMetadataPtr* TypeMetadataPtr::make(ciMethodData* m) {
  4324   return make(Constant, m, 0);
  4327 //------------------------------make-------------------------------------------
  4328 // Create a meta data constant
  4329 const TypeMetadataPtr *TypeMetadataPtr::make(PTR ptr, ciMetadata* m, int offset) {
  4330   assert(m == NULL || !m->is_klass(), "wrong type");
  4331   return (TypeMetadataPtr*)(new TypeMetadataPtr(ptr, m, offset))->hashcons();
  4335 //=============================================================================
  4336 // Convenience common pre-built types.
  4338 // Not-null object klass or below
  4339 const TypeKlassPtr *TypeKlassPtr::OBJECT;
  4340 const TypeKlassPtr *TypeKlassPtr::OBJECT_OR_NULL;
  4342 //------------------------------TypeKlassPtr-----------------------------------
  4343 TypeKlassPtr::TypeKlassPtr( PTR ptr, ciKlass* klass, int offset )
  4344   : TypePtr(KlassPtr, ptr, offset), _klass(klass), _klass_is_exact(ptr == Constant) {
  4347 //------------------------------make-------------------------------------------
  4348 // ptr to klass 'k', if Constant, or possibly to a sub-klass if not a Constant
  4349 const TypeKlassPtr *TypeKlassPtr::make( PTR ptr, ciKlass* k, int offset ) {
  4350   assert( k != NULL, "Expect a non-NULL klass");
  4351   assert(k->is_instance_klass() || k->is_array_klass(), "Incorrect type of klass oop");
  4352   TypeKlassPtr *r =
  4353     (TypeKlassPtr*)(new TypeKlassPtr(ptr, k, offset))->hashcons();
  4355   return r;
  4358 //------------------------------eq---------------------------------------------
  4359 // Structural equality check for Type representations
  4360 bool TypeKlassPtr::eq( const Type *t ) const {
  4361   const TypeKlassPtr *p = t->is_klassptr();
  4362   return
  4363     klass()->equals(p->klass()) &&
  4364     TypePtr::eq(p);
  4367 //------------------------------hash-------------------------------------------
  4368 // Type-specific hashing function.
  4369 int TypeKlassPtr::hash(void) const {
  4370   return klass()->hash() + TypePtr::hash();
  4373 //------------------------------singleton--------------------------------------
  4374 // TRUE if Type is a singleton type, FALSE otherwise.   Singletons are simple
  4375 // constants
  4376 bool TypeKlassPtr::singleton(void) const {
  4377   // detune optimizer to not generate constant klass + constant offset as a constant!
  4378   // TopPTR, Null, AnyNull, Constant are all singletons
  4379   return (_offset == 0) && !below_centerline(_ptr);
  4382 // Do not allow interface-vs.-noninterface joins to collapse to top.
  4383 const Type *TypeKlassPtr::filter(const Type *kills) const {
  4384   // logic here mirrors the one from TypeOopPtr::filter. See comments
  4385   // there.
  4386   const Type* ft = join(kills);
  4387   const TypeKlassPtr* ftkp = ft->isa_klassptr();
  4388   const TypeKlassPtr* ktkp = kills->isa_klassptr();
  4390   if (ft->empty()) {
  4391     if (!empty() && ktkp != NULL && ktkp->klass()->is_loaded() && ktkp->klass()->is_interface())
  4392       return kills;             // Uplift to interface
  4394     return Type::TOP;           // Canonical empty value
  4397   // Interface klass type could be exact in opposite to interface type,
  4398   // return it here instead of incorrect Constant ptr J/L/Object (6894807).
  4399   if (ftkp != NULL && ktkp != NULL &&
  4400       ftkp->is_loaded() &&  ftkp->klass()->is_interface() &&
  4401       !ftkp->klass_is_exact() && // Keep exact interface klass
  4402       ktkp->is_loaded() && !ktkp->klass()->is_interface()) {
  4403     return ktkp->cast_to_ptr_type(ftkp->ptr());
  4406   return ft;
  4409 //----------------------compute_klass------------------------------------------
  4410 // Compute the defining klass for this class
  4411 ciKlass* TypeAryPtr::compute_klass(DEBUG_ONLY(bool verify)) const {
  4412   // Compute _klass based on element type.
  4413   ciKlass* k_ary = NULL;
  4414   const TypeInstPtr *tinst;
  4415   const TypeAryPtr *tary;
  4416   const Type* el = elem();
  4417   if (el->isa_narrowoop()) {
  4418     el = el->make_ptr();
  4421   // Get element klass
  4422   if ((tinst = el->isa_instptr()) != NULL) {
  4423     // Compute array klass from element klass
  4424     k_ary = ciObjArrayKlass::make(tinst->klass());
  4425   } else if ((tary = el->isa_aryptr()) != NULL) {
  4426     // Compute array klass from element klass
  4427     ciKlass* k_elem = tary->klass();
  4428     // If element type is something like bottom[], k_elem will be null.
  4429     if (k_elem != NULL)
  4430       k_ary = ciObjArrayKlass::make(k_elem);
  4431   } else if ((el->base() == Type::Top) ||
  4432              (el->base() == Type::Bottom)) {
  4433     // element type of Bottom occurs from meet of basic type
  4434     // and object; Top occurs when doing join on Bottom.
  4435     // Leave k_ary at NULL.
  4436   } else {
  4437     // Cannot compute array klass directly from basic type,
  4438     // since subtypes of TypeInt all have basic type T_INT.
  4439 #ifdef ASSERT
  4440     if (verify && el->isa_int()) {
  4441       // Check simple cases when verifying klass.
  4442       BasicType bt = T_ILLEGAL;
  4443       if (el == TypeInt::BYTE) {
  4444         bt = T_BYTE;
  4445       } else if (el == TypeInt::SHORT) {
  4446         bt = T_SHORT;
  4447       } else if (el == TypeInt::CHAR) {
  4448         bt = T_CHAR;
  4449       } else if (el == TypeInt::INT) {
  4450         bt = T_INT;
  4451       } else {
  4452         return _klass; // just return specified klass
  4454       return ciTypeArrayKlass::make(bt);
  4456 #endif
  4457     assert(!el->isa_int(),
  4458            "integral arrays must be pre-equipped with a class");
  4459     // Compute array klass directly from basic type
  4460     k_ary = ciTypeArrayKlass::make(el->basic_type());
  4462   return k_ary;
  4465 //------------------------------klass------------------------------------------
  4466 // Return the defining klass for this class
  4467 ciKlass* TypeAryPtr::klass() const {
  4468   if( _klass ) return _klass;   // Return cached value, if possible
  4470   // Oops, need to compute _klass and cache it
  4471   ciKlass* k_ary = compute_klass();
  4473   if( this != TypeAryPtr::OOPS && this->dual() != TypeAryPtr::OOPS ) {
  4474     // The _klass field acts as a cache of the underlying
  4475     // ciKlass for this array type.  In order to set the field,
  4476     // we need to cast away const-ness.
  4477     //
  4478     // IMPORTANT NOTE: we *never* set the _klass field for the
  4479     // type TypeAryPtr::OOPS.  This Type is shared between all
  4480     // active compilations.  However, the ciKlass which represents
  4481     // this Type is *not* shared between compilations, so caching
  4482     // this value would result in fetching a dangling pointer.
  4483     //
  4484     // Recomputing the underlying ciKlass for each request is
  4485     // a bit less efficient than caching, but calls to
  4486     // TypeAryPtr::OOPS->klass() are not common enough to matter.
  4487     ((TypeAryPtr*)this)->_klass = k_ary;
  4488     if (UseCompressedOops && k_ary != NULL && k_ary->is_obj_array_klass() &&
  4489         _offset != 0 && _offset != arrayOopDesc::length_offset_in_bytes()) {
  4490       ((TypeAryPtr*)this)->_is_ptr_to_narrowoop = true;
  4493   return k_ary;
  4497 //------------------------------add_offset-------------------------------------
  4498 // Access internals of klass object
  4499 const TypePtr *TypeKlassPtr::add_offset( intptr_t offset ) const {
  4500   return make( _ptr, klass(), xadd_offset(offset) );
  4503 //------------------------------cast_to_ptr_type-------------------------------
  4504 const Type *TypeKlassPtr::cast_to_ptr_type(PTR ptr) const {
  4505   assert(_base == KlassPtr, "subclass must override cast_to_ptr_type");
  4506   if( ptr == _ptr ) return this;
  4507   return make(ptr, _klass, _offset);
  4511 //-----------------------------cast_to_exactness-------------------------------
  4512 const Type *TypeKlassPtr::cast_to_exactness(bool klass_is_exact) const {
  4513   if( klass_is_exact == _klass_is_exact ) return this;
  4514   if (!UseExactTypes)  return this;
  4515   return make(klass_is_exact ? Constant : NotNull, _klass, _offset);
  4519 //-----------------------------as_instance_type--------------------------------
  4520 // Corresponding type for an instance of the given class.
  4521 // It will be NotNull, and exact if and only if the klass type is exact.
  4522 const TypeOopPtr* TypeKlassPtr::as_instance_type() const {
  4523   ciKlass* k = klass();
  4524   bool    xk = klass_is_exact();
  4525   //return TypeInstPtr::make(TypePtr::NotNull, k, xk, NULL, 0);
  4526   const TypeOopPtr* toop = TypeOopPtr::make_from_klass_raw(k);
  4527   guarantee(toop != NULL, "need type for given klass");
  4528   toop = toop->cast_to_ptr_type(TypePtr::NotNull)->is_oopptr();
  4529   return toop->cast_to_exactness(xk)->is_oopptr();
  4533 //------------------------------xmeet------------------------------------------
  4534 // Compute the MEET of two types, return a new Type object.
  4535 const Type    *TypeKlassPtr::xmeet( const Type *t ) const {
  4536   // Perform a fast test for common case; meeting the same types together.
  4537   if( this == t ) return this;  // Meeting same type-rep?
  4539   // Current "this->_base" is Pointer
  4540   switch (t->base()) {          // switch on original type
  4542   case Int:                     // Mixing ints & oops happens when javac
  4543   case Long:                    // reuses local variables
  4544   case FloatTop:
  4545   case FloatCon:
  4546   case FloatBot:
  4547   case DoubleTop:
  4548   case DoubleCon:
  4549   case DoubleBot:
  4550   case NarrowOop:
  4551   case NarrowKlass:
  4552   case Bottom:                  // Ye Olde Default
  4553     return Type::BOTTOM;
  4554   case Top:
  4555     return this;
  4557   default:                      // All else is a mistake
  4558     typerr(t);
  4560   case AnyPtr: {                // Meeting to AnyPtrs
  4561     // Found an AnyPtr type vs self-KlassPtr type
  4562     const TypePtr *tp = t->is_ptr();
  4563     int offset = meet_offset(tp->offset());
  4564     PTR ptr = meet_ptr(tp->ptr());
  4565     switch (tp->ptr()) {
  4566     case TopPTR:
  4567       return this;
  4568     case Null:
  4569       if( ptr == Null ) return TypePtr::make( AnyPtr, ptr, offset );
  4570     case AnyNull:
  4571       return make( ptr, klass(), offset );
  4572     case BotPTR:
  4573     case NotNull:
  4574       return TypePtr::make(AnyPtr, ptr, offset);
  4575     default: typerr(t);
  4579   case RawPtr:
  4580   case MetadataPtr:
  4581   case OopPtr:
  4582   case AryPtr:                  // Meet with AryPtr
  4583   case InstPtr:                 // Meet with InstPtr
  4584     return TypePtr::BOTTOM;
  4586   //
  4587   //             A-top         }
  4588   //           /   |   \       }  Tops
  4589   //       B-top A-any C-top   }
  4590   //          | /  |  \ |      }  Any-nulls
  4591   //       B-any   |   C-any   }
  4592   //          |    |    |
  4593   //       B-con A-con C-con   } constants; not comparable across classes
  4594   //          |    |    |
  4595   //       B-not   |   C-not   }
  4596   //          | \  |  / |      }  not-nulls
  4597   //       B-bot A-not C-bot   }
  4598   //           \   |   /       }  Bottoms
  4599   //             A-bot         }
  4600   //
  4602   case KlassPtr: {  // Meet two KlassPtr types
  4603     const TypeKlassPtr *tkls = t->is_klassptr();
  4604     int  off     = meet_offset(tkls->offset());
  4605     PTR  ptr     = meet_ptr(tkls->ptr());
  4607     // Check for easy case; klasses are equal (and perhaps not loaded!)
  4608     // If we have constants, then we created oops so classes are loaded
  4609     // and we can handle the constants further down.  This case handles
  4610     // not-loaded classes
  4611     if( ptr != Constant && tkls->klass()->equals(klass()) ) {
  4612       return make( ptr, klass(), off );
  4615     // Classes require inspection in the Java klass hierarchy.  Must be loaded.
  4616     ciKlass* tkls_klass = tkls->klass();
  4617     ciKlass* this_klass = this->klass();
  4618     assert( tkls_klass->is_loaded(), "This class should have been loaded.");
  4619     assert( this_klass->is_loaded(), "This class should have been loaded.");
  4621     // If 'this' type is above the centerline and is a superclass of the
  4622     // other, we can treat 'this' as having the same type as the other.
  4623     if ((above_centerline(this->ptr())) &&
  4624         tkls_klass->is_subtype_of(this_klass)) {
  4625       this_klass = tkls_klass;
  4627     // If 'tinst' type is above the centerline and is a superclass of the
  4628     // other, we can treat 'tinst' as having the same type as the other.
  4629     if ((above_centerline(tkls->ptr())) &&
  4630         this_klass->is_subtype_of(tkls_klass)) {
  4631       tkls_klass = this_klass;
  4634     // Check for classes now being equal
  4635     if (tkls_klass->equals(this_klass)) {
  4636       // If the klasses are equal, the constants may still differ.  Fall to
  4637       // NotNull if they do (neither constant is NULL; that is a special case
  4638       // handled elsewhere).
  4639       if( ptr == Constant ) {
  4640         if (this->_ptr == Constant && tkls->_ptr == Constant &&
  4641             this->klass()->equals(tkls->klass()));
  4642         else if (above_centerline(this->ptr()));
  4643         else if (above_centerline(tkls->ptr()));
  4644         else
  4645           ptr = NotNull;
  4647       return make( ptr, this_klass, off );
  4648     } // Else classes are not equal
  4650     // Since klasses are different, we require the LCA in the Java
  4651     // class hierarchy - which means we have to fall to at least NotNull.
  4652     if( ptr == TopPTR || ptr == AnyNull || ptr == Constant )
  4653       ptr = NotNull;
  4654     // Now we find the LCA of Java classes
  4655     ciKlass* k = this_klass->least_common_ancestor(tkls_klass);
  4656     return   make( ptr, k, off );
  4657   } // End of case KlassPtr
  4659   } // End of switch
  4660   return this;                  // Return the double constant
  4663 //------------------------------xdual------------------------------------------
  4664 // Dual: compute field-by-field dual
  4665 const Type    *TypeKlassPtr::xdual() const {
  4666   return new TypeKlassPtr( dual_ptr(), klass(), dual_offset() );
  4669 //------------------------------get_con----------------------------------------
  4670 intptr_t TypeKlassPtr::get_con() const {
  4671   assert( _ptr == Null || _ptr == Constant, "" );
  4672   assert( _offset >= 0, "" );
  4674   if (_offset != 0) {
  4675     // After being ported to the compiler interface, the compiler no longer
  4676     // directly manipulates the addresses of oops.  Rather, it only has a pointer
  4677     // to a handle at compile time.  This handle is embedded in the generated
  4678     // code and dereferenced at the time the nmethod is made.  Until that time,
  4679     // it is not reasonable to do arithmetic with the addresses of oops (we don't
  4680     // have access to the addresses!).  This does not seem to currently happen,
  4681     // but this assertion here is to help prevent its occurence.
  4682     tty->print_cr("Found oop constant with non-zero offset");
  4683     ShouldNotReachHere();
  4686   return (intptr_t)klass()->constant_encoding();
  4688 //------------------------------dump2------------------------------------------
  4689 // Dump Klass Type
  4690 #ifndef PRODUCT
  4691 void TypeKlassPtr::dump2( Dict & d, uint depth, outputStream *st ) const {
  4692   switch( _ptr ) {
  4693   case Constant:
  4694     st->print("precise ");
  4695   case NotNull:
  4697       const char *name = klass()->name()->as_utf8();
  4698       if( name ) {
  4699         st->print("klass %s: " INTPTR_FORMAT, name, klass());
  4700       } else {
  4701         ShouldNotReachHere();
  4704   case BotPTR:
  4705     if( !WizardMode && !Verbose && !_klass_is_exact ) break;
  4706   case TopPTR:
  4707   case AnyNull:
  4708     st->print(":%s", ptr_msg[_ptr]);
  4709     if( _klass_is_exact ) st->print(":exact");
  4710     break;
  4713   if( _offset ) {               // Dump offset, if any
  4714     if( _offset == OffsetBot )      { st->print("+any"); }
  4715     else if( _offset == OffsetTop ) { st->print("+unknown"); }
  4716     else                            { st->print("+%d", _offset); }
  4719   st->print(" *");
  4721 #endif
  4725 //=============================================================================
  4726 // Convenience common pre-built types.
  4728 //------------------------------make-------------------------------------------
  4729 const TypeFunc *TypeFunc::make( const TypeTuple *domain, const TypeTuple *range ) {
  4730   return (TypeFunc*)(new TypeFunc(domain,range))->hashcons();
  4733 //------------------------------make-------------------------------------------
  4734 const TypeFunc *TypeFunc::make(ciMethod* method) {
  4735   Compile* C = Compile::current();
  4736   const TypeFunc* tf = C->last_tf(method); // check cache
  4737   if (tf != NULL)  return tf;  // The hit rate here is almost 50%.
  4738   const TypeTuple *domain;
  4739   if (method->is_static()) {
  4740     domain = TypeTuple::make_domain(NULL, method->signature());
  4741   } else {
  4742     domain = TypeTuple::make_domain(method->holder(), method->signature());
  4744   const TypeTuple *range  = TypeTuple::make_range(method->signature());
  4745   tf = TypeFunc::make(domain, range);
  4746   C->set_last_tf(method, tf);  // fill cache
  4747   return tf;
  4750 //------------------------------meet-------------------------------------------
  4751 // Compute the MEET of two types.  It returns a new Type object.
  4752 const Type *TypeFunc::xmeet( const Type *t ) const {
  4753   // Perform a fast test for common case; meeting the same types together.
  4754   if( this == t ) return this;  // Meeting same type-rep?
  4756   // Current "this->_base" is Func
  4757   switch (t->base()) {          // switch on original type
  4759   case Bottom:                  // Ye Olde Default
  4760     return t;
  4762   default:                      // All else is a mistake
  4763     typerr(t);
  4765   case Top:
  4766     break;
  4768   return this;                  // Return the double constant
  4771 //------------------------------xdual------------------------------------------
  4772 // Dual: compute field-by-field dual
  4773 const Type *TypeFunc::xdual() const {
  4774   return this;
  4777 //------------------------------eq---------------------------------------------
  4778 // Structural equality check for Type representations
  4779 bool TypeFunc::eq( const Type *t ) const {
  4780   const TypeFunc *a = (const TypeFunc*)t;
  4781   return _domain == a->_domain &&
  4782     _range == a->_range;
  4785 //------------------------------hash-------------------------------------------
  4786 // Type-specific hashing function.
  4787 int TypeFunc::hash(void) const {
  4788   return (intptr_t)_domain + (intptr_t)_range;
  4791 //------------------------------dump2------------------------------------------
  4792 // Dump Function Type
  4793 #ifndef PRODUCT
  4794 void TypeFunc::dump2( Dict &d, uint depth, outputStream *st ) const {
  4795   if( _range->_cnt <= Parms )
  4796     st->print("void");
  4797   else {
  4798     uint i;
  4799     for (i = Parms; i < _range->_cnt-1; i++) {
  4800       _range->field_at(i)->dump2(d,depth,st);
  4801       st->print("/");
  4803     _range->field_at(i)->dump2(d,depth,st);
  4805   st->print(" ");
  4806   st->print("( ");
  4807   if( !depth || d[this] ) {     // Check for recursive dump
  4808     st->print("...)");
  4809     return;
  4811   d.Insert((void*)this,(void*)this);    // Stop recursion
  4812   if (Parms < _domain->_cnt)
  4813     _domain->field_at(Parms)->dump2(d,depth-1,st);
  4814   for (uint i = Parms+1; i < _domain->_cnt; i++) {
  4815     st->print(", ");
  4816     _domain->field_at(i)->dump2(d,depth-1,st);
  4818   st->print(" )");
  4820 #endif
  4822 //------------------------------singleton--------------------------------------
  4823 // TRUE if Type is a singleton type, FALSE otherwise.   Singletons are simple
  4824 // constants (Ldi nodes).  Singletons are integer, float or double constants
  4825 // or a single symbol.
  4826 bool TypeFunc::singleton(void) const {
  4827   return false;                 // Never a singleton
  4830 bool TypeFunc::empty(void) const {
  4831   return false;                 // Never empty
  4835 BasicType TypeFunc::return_type() const{
  4836   if (range()->cnt() == TypeFunc::Parms) {
  4837     return T_VOID;
  4839   return range()->field_at(TypeFunc::Parms)->basic_type();

mercurial