src/share/vm/opto/type.cpp

Mon, 30 Aug 2010 11:02:53 -0700

author
kvn
date
Mon, 30 Aug 2010 11:02:53 -0700
changeset 2120
114e6b93e9e1
parent 2116
14b92b91f460
child 2314
f95d63e2154a
permissions
-rw-r--r--

6980978: assert(mt == t->xmeet(this)) failed: meet not commutative
Summary: Fix code in TypeAryPtr::xmeet() for constant array.
Reviewed-by: never

     1 /*
     2  * Copyright (c) 1997, 2009, 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 // Portions of code courtesy of Clifford Click
    27 // Optimization - Graph Style
    29 #include "incls/_precompiled.incl"
    30 #include "incls/_type.cpp.incl"
    32 // Dictionary of types shared among compilations.
    33 Dict* Type::_shared_type_dict = NULL;
    35 // Array which maps compiler types to Basic Types
    36 const BasicType Type::_basic_type[Type::lastype] = {
    37   T_ILLEGAL,    // Bad
    38   T_ILLEGAL,    // Control
    39   T_VOID,       // Top
    40   T_INT,        // Int
    41   T_LONG,       // Long
    42   T_VOID,       // Half
    43   T_NARROWOOP,  // NarrowOop
    45   T_ILLEGAL,    // Tuple
    46   T_ARRAY,      // Array
    48   T_ADDRESS,    // AnyPtr   // shows up in factory methods for NULL_PTR
    49   T_ADDRESS,    // RawPtr
    50   T_OBJECT,     // OopPtr
    51   T_OBJECT,     // InstPtr
    52   T_OBJECT,     // AryPtr
    53   T_OBJECT,     // KlassPtr
    55   T_OBJECT,     // Function
    56   T_ILLEGAL,    // Abio
    57   T_ADDRESS,    // Return_Address
    58   T_ILLEGAL,    // Memory
    59   T_FLOAT,      // FloatTop
    60   T_FLOAT,      // FloatCon
    61   T_FLOAT,      // FloatBot
    62   T_DOUBLE,     // DoubleTop
    63   T_DOUBLE,     // DoubleCon
    64   T_DOUBLE,     // DoubleBot
    65   T_ILLEGAL,    // Bottom
    66 };
    68 // Map ideal registers (machine types) to ideal types
    69 const Type *Type::mreg2type[_last_machine_leaf];
    71 // Map basic types to canonical Type* pointers.
    72 const Type* Type::     _const_basic_type[T_CONFLICT+1];
    74 // Map basic types to constant-zero Types.
    75 const Type* Type::            _zero_type[T_CONFLICT+1];
    77 // Map basic types to array-body alias types.
    78 const TypeAryPtr* TypeAryPtr::_array_body_type[T_CONFLICT+1];
    80 //=============================================================================
    81 // Convenience common pre-built types.
    82 const Type *Type::ABIO;         // State-of-machine only
    83 const Type *Type::BOTTOM;       // All values
    84 const Type *Type::CONTROL;      // Control only
    85 const Type *Type::DOUBLE;       // All doubles
    86 const Type *Type::FLOAT;        // All floats
    87 const Type *Type::HALF;         // Placeholder half of doublewide type
    88 const Type *Type::MEMORY;       // Abstract store only
    89 const Type *Type::RETURN_ADDRESS;
    90 const Type *Type::TOP;          // No values in set
    92 //------------------------------get_const_type---------------------------
    93 const Type* Type::get_const_type(ciType* type) {
    94   if (type == NULL) {
    95     return NULL;
    96   } else if (type->is_primitive_type()) {
    97     return get_const_basic_type(type->basic_type());
    98   } else {
    99     return TypeOopPtr::make_from_klass(type->as_klass());
   100   }
   101 }
   103 //---------------------------array_element_basic_type---------------------------------
   104 // Mapping to the array element's basic type.
   105 BasicType Type::array_element_basic_type() const {
   106   BasicType bt = basic_type();
   107   if (bt == T_INT) {
   108     if (this == TypeInt::INT)   return T_INT;
   109     if (this == TypeInt::CHAR)  return T_CHAR;
   110     if (this == TypeInt::BYTE)  return T_BYTE;
   111     if (this == TypeInt::BOOL)  return T_BOOLEAN;
   112     if (this == TypeInt::SHORT) return T_SHORT;
   113     return T_VOID;
   114   }
   115   return bt;
   116 }
   118 //---------------------------get_typeflow_type---------------------------------
   119 // Import a type produced by ciTypeFlow.
   120 const Type* Type::get_typeflow_type(ciType* type) {
   121   switch (type->basic_type()) {
   123   case ciTypeFlow::StateVector::T_BOTTOM:
   124     assert(type == ciTypeFlow::StateVector::bottom_type(), "");
   125     return Type::BOTTOM;
   127   case ciTypeFlow::StateVector::T_TOP:
   128     assert(type == ciTypeFlow::StateVector::top_type(), "");
   129     return Type::TOP;
   131   case ciTypeFlow::StateVector::T_NULL:
   132     assert(type == ciTypeFlow::StateVector::null_type(), "");
   133     return TypePtr::NULL_PTR;
   135   case ciTypeFlow::StateVector::T_LONG2:
   136     // The ciTypeFlow pass pushes a long, then the half.
   137     // We do the same.
   138     assert(type == ciTypeFlow::StateVector::long2_type(), "");
   139     return TypeInt::TOP;
   141   case ciTypeFlow::StateVector::T_DOUBLE2:
   142     // The ciTypeFlow pass pushes double, then the half.
   143     // Our convention is the same.
   144     assert(type == ciTypeFlow::StateVector::double2_type(), "");
   145     return Type::TOP;
   147   case T_ADDRESS:
   148     assert(type->is_return_address(), "");
   149     return TypeRawPtr::make((address)(intptr_t)type->as_return_address()->bci());
   151   default:
   152     // make sure we did not mix up the cases:
   153     assert(type != ciTypeFlow::StateVector::bottom_type(), "");
   154     assert(type != ciTypeFlow::StateVector::top_type(), "");
   155     assert(type != ciTypeFlow::StateVector::null_type(), "");
   156     assert(type != ciTypeFlow::StateVector::long2_type(), "");
   157     assert(type != ciTypeFlow::StateVector::double2_type(), "");
   158     assert(!type->is_return_address(), "");
   160     return Type::get_const_type(type);
   161   }
   162 }
   165 //------------------------------make-------------------------------------------
   166 // Create a simple Type, with default empty symbol sets.  Then hashcons it
   167 // and look for an existing copy in the type dictionary.
   168 const Type *Type::make( enum TYPES t ) {
   169   return (new Type(t))->hashcons();
   170 }
   172 //------------------------------cmp--------------------------------------------
   173 int Type::cmp( const Type *const t1, const Type *const t2 ) {
   174   if( t1->_base != t2->_base )
   175     return 1;                   // Missed badly
   176   assert(t1 != t2 || t1->eq(t2), "eq must be reflexive");
   177   return !t1->eq(t2);           // Return ZERO if equal
   178 }
   180 //------------------------------hash-------------------------------------------
   181 int Type::uhash( const Type *const t ) {
   182   return t->hash();
   183 }
   185 #define SMALLINT ((juint)3)  // a value too insignificant to consider widening
   187 //--------------------------Initialize_shared----------------------------------
   188 void Type::Initialize_shared(Compile* current) {
   189   // This method does not need to be locked because the first system
   190   // compilations (stub compilations) occur serially.  If they are
   191   // changed to proceed in parallel, then this section will need
   192   // locking.
   194   Arena* save = current->type_arena();
   195   Arena* shared_type_arena = new Arena();
   197   current->set_type_arena(shared_type_arena);
   198   _shared_type_dict =
   199     new (shared_type_arena) Dict( (CmpKey)Type::cmp, (Hash)Type::uhash,
   200                                   shared_type_arena, 128 );
   201   current->set_type_dict(_shared_type_dict);
   203   // Make shared pre-built types.
   204   CONTROL = make(Control);      // Control only
   205   TOP     = make(Top);          // No values in set
   206   MEMORY  = make(Memory);       // Abstract store only
   207   ABIO    = make(Abio);         // State-of-machine only
   208   RETURN_ADDRESS=make(Return_Address);
   209   FLOAT   = make(FloatBot);     // All floats
   210   DOUBLE  = make(DoubleBot);    // All doubles
   211   BOTTOM  = make(Bottom);       // Everything
   212   HALF    = make(Half);         // Placeholder half of doublewide type
   214   TypeF::ZERO = TypeF::make(0.0); // Float 0 (positive zero)
   215   TypeF::ONE  = TypeF::make(1.0); // Float 1
   217   TypeD::ZERO = TypeD::make(0.0); // Double 0 (positive zero)
   218   TypeD::ONE  = TypeD::make(1.0); // Double 1
   220   TypeInt::MINUS_1 = TypeInt::make(-1);  // -1
   221   TypeInt::ZERO    = TypeInt::make( 0);  //  0
   222   TypeInt::ONE     = TypeInt::make( 1);  //  1
   223   TypeInt::BOOL    = TypeInt::make(0,1,   WidenMin);  // 0 or 1, FALSE or TRUE.
   224   TypeInt::CC      = TypeInt::make(-1, 1, WidenMin);  // -1, 0 or 1, condition codes
   225   TypeInt::CC_LT   = TypeInt::make(-1,-1, WidenMin);  // == TypeInt::MINUS_1
   226   TypeInt::CC_GT   = TypeInt::make( 1, 1, WidenMin);  // == TypeInt::ONE
   227   TypeInt::CC_EQ   = TypeInt::make( 0, 0, WidenMin);  // == TypeInt::ZERO
   228   TypeInt::CC_LE   = TypeInt::make(-1, 0, WidenMin);
   229   TypeInt::CC_GE   = TypeInt::make( 0, 1, WidenMin);  // == TypeInt::BOOL
   230   TypeInt::BYTE    = TypeInt::make(-128,127,     WidenMin); // Bytes
   231   TypeInt::UBYTE   = TypeInt::make(0, 255,       WidenMin); // Unsigned Bytes
   232   TypeInt::CHAR    = TypeInt::make(0,65535,      WidenMin); // Java chars
   233   TypeInt::SHORT   = TypeInt::make(-32768,32767, WidenMin); // Java shorts
   234   TypeInt::POS     = TypeInt::make(0,max_jint,   WidenMin); // Non-neg values
   235   TypeInt::POS1    = TypeInt::make(1,max_jint,   WidenMin); // Positive values
   236   TypeInt::INT     = TypeInt::make(min_jint,max_jint, WidenMax); // 32-bit integers
   237   TypeInt::SYMINT  = TypeInt::make(-max_jint,max_jint,WidenMin); // symmetric range
   238   // CmpL is overloaded both as the bytecode computation returning
   239   // a trinary (-1,0,+1) integer result AND as an efficient long
   240   // compare returning optimizer ideal-type flags.
   241   assert( TypeInt::CC_LT == TypeInt::MINUS_1, "types must match for CmpL to work" );
   242   assert( TypeInt::CC_GT == TypeInt::ONE,     "types must match for CmpL to work" );
   243   assert( TypeInt::CC_EQ == TypeInt::ZERO,    "types must match for CmpL to work" );
   244   assert( TypeInt::CC_GE == TypeInt::BOOL,    "types must match for CmpL to work" );
   245   assert( (juint)(TypeInt::CC->_hi - TypeInt::CC->_lo) <= SMALLINT, "CC is truly small");
   247   TypeLong::MINUS_1 = TypeLong::make(-1);        // -1
   248   TypeLong::ZERO    = TypeLong::make( 0);        //  0
   249   TypeLong::ONE     = TypeLong::make( 1);        //  1
   250   TypeLong::POS     = TypeLong::make(0,max_jlong, WidenMin); // Non-neg values
   251   TypeLong::LONG    = TypeLong::make(min_jlong,max_jlong,WidenMax); // 64-bit integers
   252   TypeLong::INT     = TypeLong::make((jlong)min_jint,(jlong)max_jint,WidenMin);
   253   TypeLong::UINT    = TypeLong::make(0,(jlong)max_juint,WidenMin);
   255   const Type **fboth =(const Type**)shared_type_arena->Amalloc_4(2*sizeof(Type*));
   256   fboth[0] = Type::CONTROL;
   257   fboth[1] = Type::CONTROL;
   258   TypeTuple::IFBOTH = TypeTuple::make( 2, fboth );
   260   const Type **ffalse =(const Type**)shared_type_arena->Amalloc_4(2*sizeof(Type*));
   261   ffalse[0] = Type::CONTROL;
   262   ffalse[1] = Type::TOP;
   263   TypeTuple::IFFALSE = TypeTuple::make( 2, ffalse );
   265   const Type **fneither =(const Type**)shared_type_arena->Amalloc_4(2*sizeof(Type*));
   266   fneither[0] = Type::TOP;
   267   fneither[1] = Type::TOP;
   268   TypeTuple::IFNEITHER = TypeTuple::make( 2, fneither );
   270   const Type **ftrue =(const Type**)shared_type_arena->Amalloc_4(2*sizeof(Type*));
   271   ftrue[0] = Type::TOP;
   272   ftrue[1] = Type::CONTROL;
   273   TypeTuple::IFTRUE = TypeTuple::make( 2, ftrue );
   275   const Type **floop =(const Type**)shared_type_arena->Amalloc_4(2*sizeof(Type*));
   276   floop[0] = Type::CONTROL;
   277   floop[1] = TypeInt::INT;
   278   TypeTuple::LOOPBODY = TypeTuple::make( 2, floop );
   280   TypePtr::NULL_PTR= TypePtr::make( AnyPtr, TypePtr::Null, 0 );
   281   TypePtr::NOTNULL = TypePtr::make( AnyPtr, TypePtr::NotNull, OffsetBot );
   282   TypePtr::BOTTOM  = TypePtr::make( AnyPtr, TypePtr::BotPTR, OffsetBot );
   284   TypeRawPtr::BOTTOM = TypeRawPtr::make( TypePtr::BotPTR );
   285   TypeRawPtr::NOTNULL= TypeRawPtr::make( TypePtr::NotNull );
   287   const Type **fmembar = TypeTuple::fields(0);
   288   TypeTuple::MEMBAR = TypeTuple::make(TypeFunc::Parms+0, fmembar);
   290   const Type **fsc = (const Type**)shared_type_arena->Amalloc_4(2*sizeof(Type*));
   291   fsc[0] = TypeInt::CC;
   292   fsc[1] = Type::MEMORY;
   293   TypeTuple::STORECONDITIONAL = TypeTuple::make(2, fsc);
   295   TypeInstPtr::NOTNULL = TypeInstPtr::make(TypePtr::NotNull, current->env()->Object_klass());
   296   TypeInstPtr::BOTTOM  = TypeInstPtr::make(TypePtr::BotPTR,  current->env()->Object_klass());
   297   TypeInstPtr::MIRROR  = TypeInstPtr::make(TypePtr::NotNull, current->env()->Class_klass());
   298   TypeInstPtr::MARK    = TypeInstPtr::make(TypePtr::BotPTR,  current->env()->Object_klass(),
   299                                            false, 0, oopDesc::mark_offset_in_bytes());
   300   TypeInstPtr::KLASS   = TypeInstPtr::make(TypePtr::BotPTR,  current->env()->Object_klass(),
   301                                            false, 0, oopDesc::klass_offset_in_bytes());
   302   TypeOopPtr::BOTTOM  = TypeOopPtr::make(TypePtr::BotPTR, OffsetBot, TypeOopPtr::InstanceBot);
   304   TypeNarrowOop::NULL_PTR = TypeNarrowOop::make( TypePtr::NULL_PTR );
   305   TypeNarrowOop::BOTTOM   = TypeNarrowOop::make( TypeInstPtr::BOTTOM );
   307   mreg2type[Op_Node] = Type::BOTTOM;
   308   mreg2type[Op_Set ] = 0;
   309   mreg2type[Op_RegN] = TypeNarrowOop::BOTTOM;
   310   mreg2type[Op_RegI] = TypeInt::INT;
   311   mreg2type[Op_RegP] = TypePtr::BOTTOM;
   312   mreg2type[Op_RegF] = Type::FLOAT;
   313   mreg2type[Op_RegD] = Type::DOUBLE;
   314   mreg2type[Op_RegL] = TypeLong::LONG;
   315   mreg2type[Op_RegFlags] = TypeInt::CC;
   317   TypeAryPtr::RANGE   = TypeAryPtr::make( TypePtr::BotPTR, TypeAry::make(Type::BOTTOM,TypeInt::POS), NULL /* current->env()->Object_klass() */, false, arrayOopDesc::length_offset_in_bytes());
   319   TypeAryPtr::NARROWOOPS = TypeAryPtr::make(TypePtr::BotPTR, TypeAry::make(TypeNarrowOop::BOTTOM, TypeInt::POS), NULL /*ciArrayKlass::make(o)*/,  false,  Type::OffsetBot);
   321 #ifdef _LP64
   322   if (UseCompressedOops) {
   323     TypeAryPtr::OOPS  = TypeAryPtr::NARROWOOPS;
   324   } else
   325 #endif
   326   {
   327     // There is no shared klass for Object[].  See note in TypeAryPtr::klass().
   328     TypeAryPtr::OOPS  = TypeAryPtr::make(TypePtr::BotPTR, TypeAry::make(TypeInstPtr::BOTTOM,TypeInt::POS), NULL /*ciArrayKlass::make(o)*/,  false,  Type::OffsetBot);
   329   }
   330   TypeAryPtr::BYTES   = TypeAryPtr::make(TypePtr::BotPTR, TypeAry::make(TypeInt::BYTE      ,TypeInt::POS), ciTypeArrayKlass::make(T_BYTE),   true,  Type::OffsetBot);
   331   TypeAryPtr::SHORTS  = TypeAryPtr::make(TypePtr::BotPTR, TypeAry::make(TypeInt::SHORT     ,TypeInt::POS), ciTypeArrayKlass::make(T_SHORT),  true,  Type::OffsetBot);
   332   TypeAryPtr::CHARS   = TypeAryPtr::make(TypePtr::BotPTR, TypeAry::make(TypeInt::CHAR      ,TypeInt::POS), ciTypeArrayKlass::make(T_CHAR),   true,  Type::OffsetBot);
   333   TypeAryPtr::INTS    = TypeAryPtr::make(TypePtr::BotPTR, TypeAry::make(TypeInt::INT       ,TypeInt::POS), ciTypeArrayKlass::make(T_INT),    true,  Type::OffsetBot);
   334   TypeAryPtr::LONGS   = TypeAryPtr::make(TypePtr::BotPTR, TypeAry::make(TypeLong::LONG     ,TypeInt::POS), ciTypeArrayKlass::make(T_LONG),   true,  Type::OffsetBot);
   335   TypeAryPtr::FLOATS  = TypeAryPtr::make(TypePtr::BotPTR, TypeAry::make(Type::FLOAT        ,TypeInt::POS), ciTypeArrayKlass::make(T_FLOAT),  true,  Type::OffsetBot);
   336   TypeAryPtr::DOUBLES = TypeAryPtr::make(TypePtr::BotPTR, TypeAry::make(Type::DOUBLE       ,TypeInt::POS), ciTypeArrayKlass::make(T_DOUBLE), true,  Type::OffsetBot);
   338   // Nobody should ask _array_body_type[T_NARROWOOP]. Use NULL as assert.
   339   TypeAryPtr::_array_body_type[T_NARROWOOP] = NULL;
   340   TypeAryPtr::_array_body_type[T_OBJECT]  = TypeAryPtr::OOPS;
   341   TypeAryPtr::_array_body_type[T_ARRAY]   = TypeAryPtr::OOPS; // arrays are stored in oop arrays
   342   TypeAryPtr::_array_body_type[T_BYTE]    = TypeAryPtr::BYTES;
   343   TypeAryPtr::_array_body_type[T_BOOLEAN] = TypeAryPtr::BYTES;  // boolean[] is a byte array
   344   TypeAryPtr::_array_body_type[T_SHORT]   = TypeAryPtr::SHORTS;
   345   TypeAryPtr::_array_body_type[T_CHAR]    = TypeAryPtr::CHARS;
   346   TypeAryPtr::_array_body_type[T_INT]     = TypeAryPtr::INTS;
   347   TypeAryPtr::_array_body_type[T_LONG]    = TypeAryPtr::LONGS;
   348   TypeAryPtr::_array_body_type[T_FLOAT]   = TypeAryPtr::FLOATS;
   349   TypeAryPtr::_array_body_type[T_DOUBLE]  = TypeAryPtr::DOUBLES;
   351   TypeKlassPtr::OBJECT = TypeKlassPtr::make( TypePtr::NotNull, current->env()->Object_klass(), 0 );
   352   TypeKlassPtr::OBJECT_OR_NULL = TypeKlassPtr::make( TypePtr::BotPTR, current->env()->Object_klass(), 0 );
   354   const Type **fi2c = TypeTuple::fields(2);
   355   fi2c[TypeFunc::Parms+0] = TypeInstPtr::BOTTOM; // methodOop
   356   fi2c[TypeFunc::Parms+1] = TypeRawPtr::BOTTOM; // argument pointer
   357   TypeTuple::START_I2C = TypeTuple::make(TypeFunc::Parms+2, fi2c);
   359   const Type **intpair = TypeTuple::fields(2);
   360   intpair[0] = TypeInt::INT;
   361   intpair[1] = TypeInt::INT;
   362   TypeTuple::INT_PAIR = TypeTuple::make(2, intpair);
   364   const Type **longpair = TypeTuple::fields(2);
   365   longpair[0] = TypeLong::LONG;
   366   longpair[1] = TypeLong::LONG;
   367   TypeTuple::LONG_PAIR = TypeTuple::make(2, longpair);
   369   _const_basic_type[T_NARROWOOP] = TypeNarrowOop::BOTTOM;
   370   _const_basic_type[T_BOOLEAN] = TypeInt::BOOL;
   371   _const_basic_type[T_CHAR]    = TypeInt::CHAR;
   372   _const_basic_type[T_BYTE]    = TypeInt::BYTE;
   373   _const_basic_type[T_SHORT]   = TypeInt::SHORT;
   374   _const_basic_type[T_INT]     = TypeInt::INT;
   375   _const_basic_type[T_LONG]    = TypeLong::LONG;
   376   _const_basic_type[T_FLOAT]   = Type::FLOAT;
   377   _const_basic_type[T_DOUBLE]  = Type::DOUBLE;
   378   _const_basic_type[T_OBJECT]  = TypeInstPtr::BOTTOM;
   379   _const_basic_type[T_ARRAY]   = TypeInstPtr::BOTTOM; // there is no separate bottom for arrays
   380   _const_basic_type[T_VOID]    = TypePtr::NULL_PTR;   // reflection represents void this way
   381   _const_basic_type[T_ADDRESS] = TypeRawPtr::BOTTOM;  // both interpreter return addresses & random raw ptrs
   382   _const_basic_type[T_CONFLICT]= Type::BOTTOM;        // why not?
   384   _zero_type[T_NARROWOOP] = TypeNarrowOop::NULL_PTR;
   385   _zero_type[T_BOOLEAN] = TypeInt::ZERO;     // false == 0
   386   _zero_type[T_CHAR]    = TypeInt::ZERO;     // '\0' == 0
   387   _zero_type[T_BYTE]    = TypeInt::ZERO;     // 0x00 == 0
   388   _zero_type[T_SHORT]   = TypeInt::ZERO;     // 0x0000 == 0
   389   _zero_type[T_INT]     = TypeInt::ZERO;
   390   _zero_type[T_LONG]    = TypeLong::ZERO;
   391   _zero_type[T_FLOAT]   = TypeF::ZERO;
   392   _zero_type[T_DOUBLE]  = TypeD::ZERO;
   393   _zero_type[T_OBJECT]  = TypePtr::NULL_PTR;
   394   _zero_type[T_ARRAY]   = TypePtr::NULL_PTR; // null array is null oop
   395   _zero_type[T_ADDRESS] = TypePtr::NULL_PTR; // raw pointers use the same null
   396   _zero_type[T_VOID]    = Type::TOP;         // the only void value is no value at all
   398   // get_zero_type() should not happen for T_CONFLICT
   399   _zero_type[T_CONFLICT]= NULL;
   401   // Restore working type arena.
   402   current->set_type_arena(save);
   403   current->set_type_dict(NULL);
   404 }
   406 //------------------------------Initialize-------------------------------------
   407 void Type::Initialize(Compile* current) {
   408   assert(current->type_arena() != NULL, "must have created type arena");
   410   if (_shared_type_dict == NULL) {
   411     Initialize_shared(current);
   412   }
   414   Arena* type_arena = current->type_arena();
   416   // Create the hash-cons'ing dictionary with top-level storage allocation
   417   Dict *tdic = new (type_arena) Dict( (CmpKey)Type::cmp,(Hash)Type::uhash, type_arena, 128 );
   418   current->set_type_dict(tdic);
   420   // Transfer the shared types.
   421   DictI i(_shared_type_dict);
   422   for( ; i.test(); ++i ) {
   423     Type* t = (Type*)i._value;
   424     tdic->Insert(t,t);  // New Type, insert into Type table
   425   }
   427 #ifdef ASSERT
   428   verify_lastype();
   429 #endif
   430 }
   432 //------------------------------hashcons---------------------------------------
   433 // Do the hash-cons trick.  If the Type already exists in the type table,
   434 // delete the current Type and return the existing Type.  Otherwise stick the
   435 // current Type in the Type table.
   436 const Type *Type::hashcons(void) {
   437   debug_only(base());           // Check the assertion in Type::base().
   438   // Look up the Type in the Type dictionary
   439   Dict *tdic = type_dict();
   440   Type* old = (Type*)(tdic->Insert(this, this, false));
   441   if( old ) {                   // Pre-existing Type?
   442     if( old != this )           // Yes, this guy is not the pre-existing?
   443       delete this;              // Yes, Nuke this guy
   444     assert( old->_dual, "" );
   445     return old;                 // Return pre-existing
   446   }
   448   // Every type has a dual (to make my lattice symmetric).
   449   // Since we just discovered a new Type, compute its dual right now.
   450   assert( !_dual, "" );         // No dual yet
   451   _dual = xdual();              // Compute the dual
   452   if( cmp(this,_dual)==0 ) {    // Handle self-symmetric
   453     _dual = this;
   454     return this;
   455   }
   456   assert( !_dual->_dual, "" );  // No reverse dual yet
   457   assert( !(*tdic)[_dual], "" ); // Dual not in type system either
   458   // New Type, insert into Type table
   459   tdic->Insert((void*)_dual,(void*)_dual);
   460   ((Type*)_dual)->_dual = this; // Finish up being symmetric
   461 #ifdef ASSERT
   462   Type *dual_dual = (Type*)_dual->xdual();
   463   assert( eq(dual_dual), "xdual(xdual()) should be identity" );
   464   delete dual_dual;
   465 #endif
   466   return this;                  // Return new Type
   467 }
   469 //------------------------------eq---------------------------------------------
   470 // Structural equality check for Type representations
   471 bool Type::eq( const Type * ) const {
   472   return true;                  // Nothing else can go wrong
   473 }
   475 //------------------------------hash-------------------------------------------
   476 // Type-specific hashing function.
   477 int Type::hash(void) const {
   478   return _base;
   479 }
   481 //------------------------------is_finite--------------------------------------
   482 // Has a finite value
   483 bool Type::is_finite() const {
   484   return false;
   485 }
   487 //------------------------------is_nan-----------------------------------------
   488 // Is not a number (NaN)
   489 bool Type::is_nan()    const {
   490   return false;
   491 }
   493 //----------------------interface_vs_oop---------------------------------------
   494 #ifdef ASSERT
   495 bool Type::interface_vs_oop(const Type *t) const {
   496   bool result = false;
   498   const TypePtr* this_ptr = this->make_ptr(); // In case it is narrow_oop
   499   const TypePtr*    t_ptr =    t->make_ptr();
   500   if( this_ptr == NULL || t_ptr == NULL )
   501     return result;
   503   const TypeInstPtr* this_inst = this_ptr->isa_instptr();
   504   const TypeInstPtr*    t_inst =    t_ptr->isa_instptr();
   505   if( this_inst && this_inst->is_loaded() && t_inst && t_inst->is_loaded() ) {
   506     bool this_interface = this_inst->klass()->is_interface();
   507     bool    t_interface =    t_inst->klass()->is_interface();
   508     result = this_interface ^ t_interface;
   509   }
   511   return result;
   512 }
   513 #endif
   515 //------------------------------meet-------------------------------------------
   516 // Compute the MEET of two types.  NOT virtual.  It enforces that meet is
   517 // commutative and the lattice is symmetric.
   518 const Type *Type::meet( const Type *t ) const {
   519   if (isa_narrowoop() && t->isa_narrowoop()) {
   520     const Type* result = make_ptr()->meet(t->make_ptr());
   521     return result->make_narrowoop();
   522   }
   524   const Type *mt = xmeet(t);
   525   if (isa_narrowoop() || t->isa_narrowoop()) return mt;
   526 #ifdef ASSERT
   527   assert( mt == t->xmeet(this), "meet not commutative" );
   528   const Type* dual_join = mt->_dual;
   529   const Type *t2t    = dual_join->xmeet(t->_dual);
   530   const Type *t2this = dual_join->xmeet(   _dual);
   532   // Interface meet Oop is Not Symmetric:
   533   // Interface:AnyNull meet Oop:AnyNull == Interface:AnyNull
   534   // Interface:NotNull meet Oop:NotNull == java/lang/Object:NotNull
   536   if( !interface_vs_oop(t) && (t2t != t->_dual || t2this != _dual) ) {
   537     tty->print_cr("=== Meet Not Symmetric ===");
   538     tty->print("t   =                   ");         t->dump(); tty->cr();
   539     tty->print("this=                   ");            dump(); tty->cr();
   540     tty->print("mt=(t meet this)=       ");        mt->dump(); tty->cr();
   542     tty->print("t_dual=                 ");  t->_dual->dump(); tty->cr();
   543     tty->print("this_dual=              ");     _dual->dump(); tty->cr();
   544     tty->print("mt_dual=                "); mt->_dual->dump(); tty->cr();
   546     tty->print("mt_dual meet t_dual=    "); t2t      ->dump(); tty->cr();
   547     tty->print("mt_dual meet this_dual= "); t2this   ->dump(); tty->cr();
   549     fatal("meet not symmetric" );
   550   }
   551 #endif
   552   return mt;
   553 }
   555 //------------------------------xmeet------------------------------------------
   556 // Compute the MEET of two types.  It returns a new Type object.
   557 const Type *Type::xmeet( const Type *t ) const {
   558   // Perform a fast test for common case; meeting the same types together.
   559   if( this == t ) return this;  // Meeting same type-rep?
   561   // Meeting TOP with anything?
   562   if( _base == Top ) return t;
   564   // Meeting BOTTOM with anything?
   565   if( _base == Bottom ) return BOTTOM;
   567   // Current "this->_base" is one of: Bad, Multi, Control, Top,
   568   // Abio, Abstore, Floatxxx, Doublexxx, Bottom, lastype.
   569   switch (t->base()) {  // Switch on original type
   571   // Cut in half the number of cases I must handle.  Only need cases for when
   572   // the given enum "t->type" is less than or equal to the local enum "type".
   573   case FloatCon:
   574   case DoubleCon:
   575   case Int:
   576   case Long:
   577     return t->xmeet(this);
   579   case OopPtr:
   580     return t->xmeet(this);
   582   case InstPtr:
   583     return t->xmeet(this);
   585   case KlassPtr:
   586     return t->xmeet(this);
   588   case AryPtr:
   589     return t->xmeet(this);
   591   case NarrowOop:
   592     return t->xmeet(this);
   594   case Bad:                     // Type check
   595   default:                      // Bogus type not in lattice
   596     typerr(t);
   597     return Type::BOTTOM;
   599   case Bottom:                  // Ye Olde Default
   600     return t;
   602   case FloatTop:
   603     if( _base == FloatTop ) return this;
   604   case FloatBot:                // Float
   605     if( _base == FloatBot || _base == FloatTop ) return FLOAT;
   606     if( _base == DoubleTop || _base == DoubleBot ) return Type::BOTTOM;
   607     typerr(t);
   608     return Type::BOTTOM;
   610   case DoubleTop:
   611     if( _base == DoubleTop ) return this;
   612   case DoubleBot:               // Double
   613     if( _base == DoubleBot || _base == DoubleTop ) return DOUBLE;
   614     if( _base == FloatTop || _base == FloatBot ) return Type::BOTTOM;
   615     typerr(t);
   616     return Type::BOTTOM;
   618   // These next few cases must match exactly or it is a compile-time error.
   619   case Control:                 // Control of code
   620   case Abio:                    // State of world outside of program
   621   case Memory:
   622     if( _base == t->_base )  return this;
   623     typerr(t);
   624     return Type::BOTTOM;
   626   case Top:                     // Top of the lattice
   627     return this;
   628   }
   630   // The type is unchanged
   631   return this;
   632 }
   634 //-----------------------------filter------------------------------------------
   635 const Type *Type::filter( const Type *kills ) const {
   636   const Type* ft = join(kills);
   637   if (ft->empty())
   638     return Type::TOP;           // Canonical empty value
   639   return ft;
   640 }
   642 //------------------------------xdual------------------------------------------
   643 // Compute dual right now.
   644 const Type::TYPES Type::dual_type[Type::lastype] = {
   645   Bad,          // Bad
   646   Control,      // Control
   647   Bottom,       // Top
   648   Bad,          // Int - handled in v-call
   649   Bad,          // Long - handled in v-call
   650   Half,         // Half
   651   Bad,          // NarrowOop - handled in v-call
   653   Bad,          // Tuple - handled in v-call
   654   Bad,          // Array - handled in v-call
   656   Bad,          // AnyPtr - handled in v-call
   657   Bad,          // RawPtr - handled in v-call
   658   Bad,          // OopPtr - handled in v-call
   659   Bad,          // InstPtr - handled in v-call
   660   Bad,          // AryPtr - handled in v-call
   661   Bad,          // KlassPtr - handled in v-call
   663   Bad,          // Function - handled in v-call
   664   Abio,         // Abio
   665   Return_Address,// Return_Address
   666   Memory,       // Memory
   667   FloatBot,     // FloatTop
   668   FloatCon,     // FloatCon
   669   FloatTop,     // FloatBot
   670   DoubleBot,    // DoubleTop
   671   DoubleCon,    // DoubleCon
   672   DoubleTop,    // DoubleBot
   673   Top           // Bottom
   674 };
   676 const Type *Type::xdual() const {
   677   // Note: the base() accessor asserts the sanity of _base.
   678   assert(dual_type[base()] != Bad, "implement with v-call");
   679   return new Type(dual_type[_base]);
   680 }
   682 //------------------------------has_memory-------------------------------------
   683 bool Type::has_memory() const {
   684   Type::TYPES tx = base();
   685   if (tx == Memory) return true;
   686   if (tx == Tuple) {
   687     const TypeTuple *t = is_tuple();
   688     for (uint i=0; i < t->cnt(); i++) {
   689       tx = t->field_at(i)->base();
   690       if (tx == Memory)  return true;
   691     }
   692   }
   693   return false;
   694 }
   696 #ifndef PRODUCT
   697 //------------------------------dump2------------------------------------------
   698 void Type::dump2( Dict &d, uint depth, outputStream *st ) const {
   699   st->print(msg[_base]);
   700 }
   702 //------------------------------dump-------------------------------------------
   703 void Type::dump_on(outputStream *st) const {
   704   ResourceMark rm;
   705   Dict d(cmpkey,hashkey);       // Stop recursive type dumping
   706   dump2(d,1, st);
   707   if (is_ptr_to_narrowoop()) {
   708     st->print(" [narrow]");
   709   }
   710 }
   712 //------------------------------data-------------------------------------------
   713 const char * const Type::msg[Type::lastype] = {
   714   "bad","control","top","int:","long:","half", "narrowoop:",
   715   "tuple:", "aryptr",
   716   "anyptr:", "rawptr:", "java:", "inst:", "ary:", "klass:",
   717   "func", "abIO", "return_address", "memory",
   718   "float_top", "ftcon:", "float",
   719   "double_top", "dblcon:", "double",
   720   "bottom"
   721 };
   722 #endif
   724 //------------------------------singleton--------------------------------------
   725 // TRUE if Type is a singleton type, FALSE otherwise.   Singletons are simple
   726 // constants (Ldi nodes).  Singletons are integer, float or double constants.
   727 bool Type::singleton(void) const {
   728   return _base == Top || _base == Half;
   729 }
   731 //------------------------------empty------------------------------------------
   732 // TRUE if Type is a type with no values, FALSE otherwise.
   733 bool Type::empty(void) const {
   734   switch (_base) {
   735   case DoubleTop:
   736   case FloatTop:
   737   case Top:
   738     return true;
   740   case Half:
   741   case Abio:
   742   case Return_Address:
   743   case Memory:
   744   case Bottom:
   745   case FloatBot:
   746   case DoubleBot:
   747     return false;  // never a singleton, therefore never empty
   748   }
   750   ShouldNotReachHere();
   751   return false;
   752 }
   754 //------------------------------dump_stats-------------------------------------
   755 // Dump collected statistics to stderr
   756 #ifndef PRODUCT
   757 void Type::dump_stats() {
   758   tty->print("Types made: %d\n", type_dict()->Size());
   759 }
   760 #endif
   762 //------------------------------typerr-----------------------------------------
   763 void Type::typerr( const Type *t ) const {
   764 #ifndef PRODUCT
   765   tty->print("\nError mixing types: ");
   766   dump();
   767   tty->print(" and ");
   768   t->dump();
   769   tty->print("\n");
   770 #endif
   771   ShouldNotReachHere();
   772 }
   774 //------------------------------isa_oop_ptr------------------------------------
   775 // Return true if type is an oop pointer type.  False for raw pointers.
   776 static char isa_oop_ptr_tbl[Type::lastype] = {
   777   0,0,0,0,0,0,0/*narrowoop*/,0/*tuple*/, 0/*ary*/,
   778   0/*anyptr*/,0/*rawptr*/,1/*OopPtr*/,1/*InstPtr*/,1/*AryPtr*/,1/*KlassPtr*/,
   779   0/*func*/,0,0/*return_address*/,0,
   780   /*floats*/0,0,0, /*doubles*/0,0,0,
   781   0
   782 };
   783 bool Type::isa_oop_ptr() const {
   784   return isa_oop_ptr_tbl[_base] != 0;
   785 }
   787 //------------------------------dump_stats-------------------------------------
   788 // // Check that arrays match type enum
   789 #ifndef PRODUCT
   790 void Type::verify_lastype() {
   791   // Check that arrays match enumeration
   792   assert( Type::dual_type  [Type::lastype - 1] == Type::Top, "did not update array");
   793   assert( strcmp(Type::msg [Type::lastype - 1],"bottom") == 0, "did not update array");
   794   // assert( PhiNode::tbl     [Type::lastype - 1] == NULL,    "did not update array");
   795   assert( Matcher::base2reg[Type::lastype - 1] == 0,      "did not update array");
   796   assert( isa_oop_ptr_tbl  [Type::lastype - 1] == (char)0,  "did not update array");
   797 }
   798 #endif
   800 //=============================================================================
   801 // Convenience common pre-built types.
   802 const TypeF *TypeF::ZERO;       // Floating point zero
   803 const TypeF *TypeF::ONE;        // Floating point one
   805 //------------------------------make-------------------------------------------
   806 // Create a float constant
   807 const TypeF *TypeF::make(float f) {
   808   return (TypeF*)(new TypeF(f))->hashcons();
   809 }
   811 //------------------------------meet-------------------------------------------
   812 // Compute the MEET of two types.  It returns a new Type object.
   813 const Type *TypeF::xmeet( const Type *t ) const {
   814   // Perform a fast test for common case; meeting the same types together.
   815   if( this == t ) return this;  // Meeting same type-rep?
   817   // Current "this->_base" is FloatCon
   818   switch (t->base()) {          // Switch on original type
   819   case AnyPtr:                  // Mixing with oops happens when javac
   820   case RawPtr:                  // reuses local variables
   821   case OopPtr:
   822   case InstPtr:
   823   case KlassPtr:
   824   case AryPtr:
   825   case NarrowOop:
   826   case Int:
   827   case Long:
   828   case DoubleTop:
   829   case DoubleCon:
   830   case DoubleBot:
   831   case Bottom:                  // Ye Olde Default
   832     return Type::BOTTOM;
   834   case FloatBot:
   835     return t;
   837   default:                      // All else is a mistake
   838     typerr(t);
   840   case FloatCon:                // Float-constant vs Float-constant?
   841     if( jint_cast(_f) != jint_cast(t->getf()) )         // unequal constants?
   842                                 // must compare bitwise as positive zero, negative zero and NaN have
   843                                 // all the same representation in C++
   844       return FLOAT;             // Return generic float
   845                                 // Equal constants
   846   case Top:
   847   case FloatTop:
   848     break;                      // Return the float constant
   849   }
   850   return this;                  // Return the float constant
   851 }
   853 //------------------------------xdual------------------------------------------
   854 // Dual: symmetric
   855 const Type *TypeF::xdual() const {
   856   return this;
   857 }
   859 //------------------------------eq---------------------------------------------
   860 // Structural equality check for Type representations
   861 bool TypeF::eq( const Type *t ) const {
   862   if( g_isnan(_f) ||
   863       g_isnan(t->getf()) ) {
   864     // One or both are NANs.  If both are NANs return true, else false.
   865     return (g_isnan(_f) && g_isnan(t->getf()));
   866   }
   867   if (_f == t->getf()) {
   868     // (NaN is impossible at this point, since it is not equal even to itself)
   869     if (_f == 0.0) {
   870       // difference between positive and negative zero
   871       if (jint_cast(_f) != jint_cast(t->getf()))  return false;
   872     }
   873     return true;
   874   }
   875   return false;
   876 }
   878 //------------------------------hash-------------------------------------------
   879 // Type-specific hashing function.
   880 int TypeF::hash(void) const {
   881   return *(int*)(&_f);
   882 }
   884 //------------------------------is_finite--------------------------------------
   885 // Has a finite value
   886 bool TypeF::is_finite() const {
   887   return g_isfinite(getf()) != 0;
   888 }
   890 //------------------------------is_nan-----------------------------------------
   891 // Is not a number (NaN)
   892 bool TypeF::is_nan()    const {
   893   return g_isnan(getf()) != 0;
   894 }
   896 //------------------------------dump2------------------------------------------
   897 // Dump float constant Type
   898 #ifndef PRODUCT
   899 void TypeF::dump2( Dict &d, uint depth, outputStream *st ) const {
   900   Type::dump2(d,depth, st);
   901   st->print("%f", _f);
   902 }
   903 #endif
   905 //------------------------------singleton--------------------------------------
   906 // TRUE if Type is a singleton type, FALSE otherwise.   Singletons are simple
   907 // constants (Ldi nodes).  Singletons are integer, float or double constants
   908 // or a single symbol.
   909 bool TypeF::singleton(void) const {
   910   return true;                  // Always a singleton
   911 }
   913 bool TypeF::empty(void) const {
   914   return false;                 // always exactly a singleton
   915 }
   917 //=============================================================================
   918 // Convenience common pre-built types.
   919 const TypeD *TypeD::ZERO;       // Floating point zero
   920 const TypeD *TypeD::ONE;        // Floating point one
   922 //------------------------------make-------------------------------------------
   923 const TypeD *TypeD::make(double d) {
   924   return (TypeD*)(new TypeD(d))->hashcons();
   925 }
   927 //------------------------------meet-------------------------------------------
   928 // Compute the MEET of two types.  It returns a new Type object.
   929 const Type *TypeD::xmeet( const Type *t ) const {
   930   // Perform a fast test for common case; meeting the same types together.
   931   if( this == t ) return this;  // Meeting same type-rep?
   933   // Current "this->_base" is DoubleCon
   934   switch (t->base()) {          // Switch on original type
   935   case AnyPtr:                  // Mixing with oops happens when javac
   936   case RawPtr:                  // reuses local variables
   937   case OopPtr:
   938   case InstPtr:
   939   case KlassPtr:
   940   case AryPtr:
   941   case NarrowOop:
   942   case Int:
   943   case Long:
   944   case FloatTop:
   945   case FloatCon:
   946   case FloatBot:
   947   case Bottom:                  // Ye Olde Default
   948     return Type::BOTTOM;
   950   case DoubleBot:
   951     return t;
   953   default:                      // All else is a mistake
   954     typerr(t);
   956   case DoubleCon:               // Double-constant vs Double-constant?
   957     if( jlong_cast(_d) != jlong_cast(t->getd()) )       // unequal constants? (see comment in TypeF::xmeet)
   958       return DOUBLE;            // Return generic double
   959   case Top:
   960   case DoubleTop:
   961     break;
   962   }
   963   return this;                  // Return the double constant
   964 }
   966 //------------------------------xdual------------------------------------------
   967 // Dual: symmetric
   968 const Type *TypeD::xdual() const {
   969   return this;
   970 }
   972 //------------------------------eq---------------------------------------------
   973 // Structural equality check for Type representations
   974 bool TypeD::eq( const Type *t ) const {
   975   if( g_isnan(_d) ||
   976       g_isnan(t->getd()) ) {
   977     // One or both are NANs.  If both are NANs return true, else false.
   978     return (g_isnan(_d) && g_isnan(t->getd()));
   979   }
   980   if (_d == t->getd()) {
   981     // (NaN is impossible at this point, since it is not equal even to itself)
   982     if (_d == 0.0) {
   983       // difference between positive and negative zero
   984       if (jlong_cast(_d) != jlong_cast(t->getd()))  return false;
   985     }
   986     return true;
   987   }
   988   return false;
   989 }
   991 //------------------------------hash-------------------------------------------
   992 // Type-specific hashing function.
   993 int TypeD::hash(void) const {
   994   return *(int*)(&_d);
   995 }
   997 //------------------------------is_finite--------------------------------------
   998 // Has a finite value
   999 bool TypeD::is_finite() const {
  1000   return g_isfinite(getd()) != 0;
  1003 //------------------------------is_nan-----------------------------------------
  1004 // Is not a number (NaN)
  1005 bool TypeD::is_nan()    const {
  1006   return g_isnan(getd()) != 0;
  1009 //------------------------------dump2------------------------------------------
  1010 // Dump double constant Type
  1011 #ifndef PRODUCT
  1012 void TypeD::dump2( Dict &d, uint depth, outputStream *st ) const {
  1013   Type::dump2(d,depth,st);
  1014   st->print("%f", _d);
  1016 #endif
  1018 //------------------------------singleton--------------------------------------
  1019 // TRUE if Type is a singleton type, FALSE otherwise.   Singletons are simple
  1020 // constants (Ldi nodes).  Singletons are integer, float or double constants
  1021 // or a single symbol.
  1022 bool TypeD::singleton(void) const {
  1023   return true;                  // Always a singleton
  1026 bool TypeD::empty(void) const {
  1027   return false;                 // always exactly a singleton
  1030 //=============================================================================
  1031 // Convience common pre-built types.
  1032 const TypeInt *TypeInt::MINUS_1;// -1
  1033 const TypeInt *TypeInt::ZERO;   // 0
  1034 const TypeInt *TypeInt::ONE;    // 1
  1035 const TypeInt *TypeInt::BOOL;   // 0 or 1, FALSE or TRUE.
  1036 const TypeInt *TypeInt::CC;     // -1,0 or 1, condition codes
  1037 const TypeInt *TypeInt::CC_LT;  // [-1]  == MINUS_1
  1038 const TypeInt *TypeInt::CC_GT;  // [1]   == ONE
  1039 const TypeInt *TypeInt::CC_EQ;  // [0]   == ZERO
  1040 const TypeInt *TypeInt::CC_LE;  // [-1,0]
  1041 const TypeInt *TypeInt::CC_GE;  // [0,1] == BOOL (!)
  1042 const TypeInt *TypeInt::BYTE;   // Bytes, -128 to 127
  1043 const TypeInt *TypeInt::UBYTE;  // Unsigned Bytes, 0 to 255
  1044 const TypeInt *TypeInt::CHAR;   // Java chars, 0-65535
  1045 const TypeInt *TypeInt::SHORT;  // Java shorts, -32768-32767
  1046 const TypeInt *TypeInt::POS;    // Positive 32-bit integers or zero
  1047 const TypeInt *TypeInt::POS1;   // Positive 32-bit integers
  1048 const TypeInt *TypeInt::INT;    // 32-bit integers
  1049 const TypeInt *TypeInt::SYMINT; // symmetric range [-max_jint..max_jint]
  1051 //------------------------------TypeInt----------------------------------------
  1052 TypeInt::TypeInt( jint lo, jint hi, int w ) : Type(Int), _lo(lo), _hi(hi), _widen(w) {
  1055 //------------------------------make-------------------------------------------
  1056 const TypeInt *TypeInt::make( jint lo ) {
  1057   return (TypeInt*)(new TypeInt(lo,lo,WidenMin))->hashcons();
  1060 static int normalize_int_widen( jint lo, jint hi, int w ) {
  1061   // Certain normalizations keep us sane when comparing types.
  1062   // The 'SMALLINT' covers constants and also CC and its relatives.
  1063   if (lo <= hi) {
  1064     if ((juint)(hi - lo) <= SMALLINT)  w = Type::WidenMin;
  1065     if ((juint)(hi - lo) >= max_juint) w = Type::WidenMax; // TypeInt::INT
  1066   } else {
  1067     if ((juint)(lo - hi) <= SMALLINT)  w = Type::WidenMin;
  1068     if ((juint)(lo - hi) >= max_juint) w = Type::WidenMin; // dual TypeInt::INT
  1070   return w;
  1073 const TypeInt *TypeInt::make( jint lo, jint hi, int w ) {
  1074   w = normalize_int_widen(lo, hi, w);
  1075   return (TypeInt*)(new TypeInt(lo,hi,w))->hashcons();
  1078 //------------------------------meet-------------------------------------------
  1079 // Compute the MEET of two types.  It returns a new Type representation object
  1080 // with reference count equal to the number of Types pointing at it.
  1081 // Caller should wrap a Types around it.
  1082 const Type *TypeInt::xmeet( const Type *t ) const {
  1083   // Perform a fast test for common case; meeting the same types together.
  1084   if( this == t ) return this;  // Meeting same type?
  1086   // Currently "this->_base" is a TypeInt
  1087   switch (t->base()) {          // Switch on original type
  1088   case AnyPtr:                  // Mixing with oops happens when javac
  1089   case RawPtr:                  // reuses local variables
  1090   case OopPtr:
  1091   case InstPtr:
  1092   case KlassPtr:
  1093   case AryPtr:
  1094   case NarrowOop:
  1095   case Long:
  1096   case FloatTop:
  1097   case FloatCon:
  1098   case FloatBot:
  1099   case DoubleTop:
  1100   case DoubleCon:
  1101   case DoubleBot:
  1102   case Bottom:                  // Ye Olde Default
  1103     return Type::BOTTOM;
  1104   default:                      // All else is a mistake
  1105     typerr(t);
  1106   case Top:                     // No change
  1107     return this;
  1108   case Int:                     // Int vs Int?
  1109     break;
  1112   // Expand covered set
  1113   const TypeInt *r = t->is_int();
  1114   return make( MIN2(_lo,r->_lo), MAX2(_hi,r->_hi), MAX2(_widen,r->_widen) );
  1117 //------------------------------xdual------------------------------------------
  1118 // Dual: reverse hi & lo; flip widen
  1119 const Type *TypeInt::xdual() const {
  1120   int w = normalize_int_widen(_hi,_lo, WidenMax-_widen);
  1121   return new TypeInt(_hi,_lo,w);
  1124 //------------------------------widen------------------------------------------
  1125 // Only happens for optimistic top-down optimizations.
  1126 const Type *TypeInt::widen( const Type *old, const Type* limit ) const {
  1127   // Coming from TOP or such; no widening
  1128   if( old->base() != Int ) return this;
  1129   const TypeInt *ot = old->is_int();
  1131   // If new guy is equal to old guy, no widening
  1132   if( _lo == ot->_lo && _hi == ot->_hi )
  1133     return old;
  1135   // If new guy contains old, then we widened
  1136   if( _lo <= ot->_lo && _hi >= ot->_hi ) {
  1137     // New contains old
  1138     // If new guy is already wider than old, no widening
  1139     if( _widen > ot->_widen ) return this;
  1140     // If old guy was a constant, do not bother
  1141     if (ot->_lo == ot->_hi)  return this;
  1142     // Now widen new guy.
  1143     // Check for widening too far
  1144     if (_widen == WidenMax) {
  1145       int max = max_jint;
  1146       int min = min_jint;
  1147       if (limit->isa_int()) {
  1148         max = limit->is_int()->_hi;
  1149         min = limit->is_int()->_lo;
  1151       if (min < _lo && _hi < max) {
  1152         // If neither endpoint is extremal yet, push out the endpoint
  1153         // which is closer to its respective limit.
  1154         if (_lo >= 0 ||                 // easy common case
  1155             (juint)(_lo - min) >= (juint)(max - _hi)) {
  1156           // Try to widen to an unsigned range type of 31 bits:
  1157           return make(_lo, max, WidenMax);
  1158         } else {
  1159           return make(min, _hi, WidenMax);
  1162       return TypeInt::INT;
  1164     // Returned widened new guy
  1165     return make(_lo,_hi,_widen+1);
  1168   // If old guy contains new, then we probably widened too far & dropped to
  1169   // bottom.  Return the wider fellow.
  1170   if ( ot->_lo <= _lo && ot->_hi >= _hi )
  1171     return old;
  1173   //fatal("Integer value range is not subset");
  1174   //return this;
  1175   return TypeInt::INT;
  1178 //------------------------------narrow---------------------------------------
  1179 // Only happens for pessimistic optimizations.
  1180 const Type *TypeInt::narrow( const Type *old ) const {
  1181   if (_lo >= _hi)  return this;   // already narrow enough
  1182   if (old == NULL)  return this;
  1183   const TypeInt* ot = old->isa_int();
  1184   if (ot == NULL)  return this;
  1185   jint olo = ot->_lo;
  1186   jint ohi = ot->_hi;
  1188   // If new guy is equal to old guy, no narrowing
  1189   if (_lo == olo && _hi == ohi)  return old;
  1191   // If old guy was maximum range, allow the narrowing
  1192   if (olo == min_jint && ohi == max_jint)  return this;
  1194   if (_lo < olo || _hi > ohi)
  1195     return this;                // doesn't narrow; pretty wierd
  1197   // The new type narrows the old type, so look for a "death march".
  1198   // See comments on PhaseTransform::saturate.
  1199   juint nrange = _hi - _lo;
  1200   juint orange = ohi - olo;
  1201   if (nrange < max_juint - 1 && nrange > (orange >> 1) + (SMALLINT*2)) {
  1202     // Use the new type only if the range shrinks a lot.
  1203     // We do not want the optimizer computing 2^31 point by point.
  1204     return old;
  1207   return this;
  1210 //-----------------------------filter------------------------------------------
  1211 const Type *TypeInt::filter( const Type *kills ) const {
  1212   const TypeInt* ft = join(kills)->isa_int();
  1213   if (ft == NULL || ft->empty())
  1214     return Type::TOP;           // Canonical empty value
  1215   if (ft->_widen < this->_widen) {
  1216     // Do not allow the value of kill->_widen to affect the outcome.
  1217     // The widen bits must be allowed to run freely through the graph.
  1218     ft = TypeInt::make(ft->_lo, ft->_hi, this->_widen);
  1220   return ft;
  1223 //------------------------------eq---------------------------------------------
  1224 // Structural equality check for Type representations
  1225 bool TypeInt::eq( const Type *t ) const {
  1226   const TypeInt *r = t->is_int(); // Handy access
  1227   return r->_lo == _lo && r->_hi == _hi && r->_widen == _widen;
  1230 //------------------------------hash-------------------------------------------
  1231 // Type-specific hashing function.
  1232 int TypeInt::hash(void) const {
  1233   return _lo+_hi+_widen+(int)Type::Int;
  1236 //------------------------------is_finite--------------------------------------
  1237 // Has a finite value
  1238 bool TypeInt::is_finite() const {
  1239   return true;
  1242 //------------------------------dump2------------------------------------------
  1243 // Dump TypeInt
  1244 #ifndef PRODUCT
  1245 static const char* intname(char* buf, jint n) {
  1246   if (n == min_jint)
  1247     return "min";
  1248   else if (n < min_jint + 10000)
  1249     sprintf(buf, "min+" INT32_FORMAT, n - min_jint);
  1250   else if (n == max_jint)
  1251     return "max";
  1252   else if (n > max_jint - 10000)
  1253     sprintf(buf, "max-" INT32_FORMAT, max_jint - n);
  1254   else
  1255     sprintf(buf, INT32_FORMAT, n);
  1256   return buf;
  1259 void TypeInt::dump2( Dict &d, uint depth, outputStream *st ) const {
  1260   char buf[40], buf2[40];
  1261   if (_lo == min_jint && _hi == max_jint)
  1262     st->print("int");
  1263   else if (is_con())
  1264     st->print("int:%s", intname(buf, get_con()));
  1265   else if (_lo == BOOL->_lo && _hi == BOOL->_hi)
  1266     st->print("bool");
  1267   else if (_lo == BYTE->_lo && _hi == BYTE->_hi)
  1268     st->print("byte");
  1269   else if (_lo == CHAR->_lo && _hi == CHAR->_hi)
  1270     st->print("char");
  1271   else if (_lo == SHORT->_lo && _hi == SHORT->_hi)
  1272     st->print("short");
  1273   else if (_hi == max_jint)
  1274     st->print("int:>=%s", intname(buf, _lo));
  1275   else if (_lo == min_jint)
  1276     st->print("int:<=%s", intname(buf, _hi));
  1277   else
  1278     st->print("int:%s..%s", intname(buf, _lo), intname(buf2, _hi));
  1280   if (_widen != 0 && this != TypeInt::INT)
  1281     st->print(":%.*s", _widen, "wwww");
  1283 #endif
  1285 //------------------------------singleton--------------------------------------
  1286 // TRUE if Type is a singleton type, FALSE otherwise.   Singletons are simple
  1287 // constants.
  1288 bool TypeInt::singleton(void) const {
  1289   return _lo >= _hi;
  1292 bool TypeInt::empty(void) const {
  1293   return _lo > _hi;
  1296 //=============================================================================
  1297 // Convenience common pre-built types.
  1298 const TypeLong *TypeLong::MINUS_1;// -1
  1299 const TypeLong *TypeLong::ZERO; // 0
  1300 const TypeLong *TypeLong::ONE;  // 1
  1301 const TypeLong *TypeLong::POS;  // >=0
  1302 const TypeLong *TypeLong::LONG; // 64-bit integers
  1303 const TypeLong *TypeLong::INT;  // 32-bit subrange
  1304 const TypeLong *TypeLong::UINT; // 32-bit unsigned subrange
  1306 //------------------------------TypeLong---------------------------------------
  1307 TypeLong::TypeLong( jlong lo, jlong hi, int w ) : Type(Long), _lo(lo), _hi(hi), _widen(w) {
  1310 //------------------------------make-------------------------------------------
  1311 const TypeLong *TypeLong::make( jlong lo ) {
  1312   return (TypeLong*)(new TypeLong(lo,lo,WidenMin))->hashcons();
  1315 static int normalize_long_widen( jlong lo, jlong hi, int w ) {
  1316   // Certain normalizations keep us sane when comparing types.
  1317   // The 'SMALLINT' covers constants.
  1318   if (lo <= hi) {
  1319     if ((julong)(hi - lo) <= SMALLINT)   w = Type::WidenMin;
  1320     if ((julong)(hi - lo) >= max_julong) w = Type::WidenMax; // TypeLong::LONG
  1321   } else {
  1322     if ((julong)(lo - hi) <= SMALLINT)   w = Type::WidenMin;
  1323     if ((julong)(lo - hi) >= max_julong) w = Type::WidenMin; // dual TypeLong::LONG
  1325   return w;
  1328 const TypeLong *TypeLong::make( jlong lo, jlong hi, int w ) {
  1329   w = normalize_long_widen(lo, hi, w);
  1330   return (TypeLong*)(new TypeLong(lo,hi,w))->hashcons();
  1334 //------------------------------meet-------------------------------------------
  1335 // Compute the MEET of two types.  It returns a new Type representation object
  1336 // with reference count equal to the number of Types pointing at it.
  1337 // Caller should wrap a Types around it.
  1338 const Type *TypeLong::xmeet( const Type *t ) const {
  1339   // Perform a fast test for common case; meeting the same types together.
  1340   if( this == t ) return this;  // Meeting same type?
  1342   // Currently "this->_base" is a TypeLong
  1343   switch (t->base()) {          // Switch on original type
  1344   case AnyPtr:                  // Mixing with oops happens when javac
  1345   case RawPtr:                  // reuses local variables
  1346   case OopPtr:
  1347   case InstPtr:
  1348   case KlassPtr:
  1349   case AryPtr:
  1350   case NarrowOop:
  1351   case Int:
  1352   case FloatTop:
  1353   case FloatCon:
  1354   case FloatBot:
  1355   case DoubleTop:
  1356   case DoubleCon:
  1357   case DoubleBot:
  1358   case Bottom:                  // Ye Olde Default
  1359     return Type::BOTTOM;
  1360   default:                      // All else is a mistake
  1361     typerr(t);
  1362   case Top:                     // No change
  1363     return this;
  1364   case Long:                    // Long vs Long?
  1365     break;
  1368   // Expand covered set
  1369   const TypeLong *r = t->is_long(); // Turn into a TypeLong
  1370   return make( MIN2(_lo,r->_lo), MAX2(_hi,r->_hi), MAX2(_widen,r->_widen) );
  1373 //------------------------------xdual------------------------------------------
  1374 // Dual: reverse hi & lo; flip widen
  1375 const Type *TypeLong::xdual() const {
  1376   int w = normalize_long_widen(_hi,_lo, WidenMax-_widen);
  1377   return new TypeLong(_hi,_lo,w);
  1380 //------------------------------widen------------------------------------------
  1381 // Only happens for optimistic top-down optimizations.
  1382 const Type *TypeLong::widen( const Type *old, const Type* limit ) const {
  1383   // Coming from TOP or such; no widening
  1384   if( old->base() != Long ) return this;
  1385   const TypeLong *ot = old->is_long();
  1387   // If new guy is equal to old guy, no widening
  1388   if( _lo == ot->_lo && _hi == ot->_hi )
  1389     return old;
  1391   // If new guy contains old, then we widened
  1392   if( _lo <= ot->_lo && _hi >= ot->_hi ) {
  1393     // New contains old
  1394     // If new guy is already wider than old, no widening
  1395     if( _widen > ot->_widen ) return this;
  1396     // If old guy was a constant, do not bother
  1397     if (ot->_lo == ot->_hi)  return this;
  1398     // Now widen new guy.
  1399     // Check for widening too far
  1400     if (_widen == WidenMax) {
  1401       jlong max = max_jlong;
  1402       jlong min = min_jlong;
  1403       if (limit->isa_long()) {
  1404         max = limit->is_long()->_hi;
  1405         min = limit->is_long()->_lo;
  1407       if (min < _lo && _hi < max) {
  1408         // If neither endpoint is extremal yet, push out the endpoint
  1409         // which is closer to its respective limit.
  1410         if (_lo >= 0 ||                 // easy common case
  1411             (julong)(_lo - min) >= (julong)(max - _hi)) {
  1412           // Try to widen to an unsigned range type of 32/63 bits:
  1413           if (max >= max_juint && _hi < max_juint)
  1414             return make(_lo, max_juint, WidenMax);
  1415           else
  1416             return make(_lo, max, WidenMax);
  1417         } else {
  1418           return make(min, _hi, WidenMax);
  1421       return TypeLong::LONG;
  1423     // Returned widened new guy
  1424     return make(_lo,_hi,_widen+1);
  1427   // If old guy contains new, then we probably widened too far & dropped to
  1428   // bottom.  Return the wider fellow.
  1429   if ( ot->_lo <= _lo && ot->_hi >= _hi )
  1430     return old;
  1432   //  fatal("Long value range is not subset");
  1433   // return this;
  1434   return TypeLong::LONG;
  1437 //------------------------------narrow----------------------------------------
  1438 // Only happens for pessimistic optimizations.
  1439 const Type *TypeLong::narrow( const Type *old ) const {
  1440   if (_lo >= _hi)  return this;   // already narrow enough
  1441   if (old == NULL)  return this;
  1442   const TypeLong* ot = old->isa_long();
  1443   if (ot == NULL)  return this;
  1444   jlong olo = ot->_lo;
  1445   jlong ohi = ot->_hi;
  1447   // If new guy is equal to old guy, no narrowing
  1448   if (_lo == olo && _hi == ohi)  return old;
  1450   // If old guy was maximum range, allow the narrowing
  1451   if (olo == min_jlong && ohi == max_jlong)  return this;
  1453   if (_lo < olo || _hi > ohi)
  1454     return this;                // doesn't narrow; pretty wierd
  1456   // The new type narrows the old type, so look for a "death march".
  1457   // See comments on PhaseTransform::saturate.
  1458   julong nrange = _hi - _lo;
  1459   julong orange = ohi - olo;
  1460   if (nrange < max_julong - 1 && nrange > (orange >> 1) + (SMALLINT*2)) {
  1461     // Use the new type only if the range shrinks a lot.
  1462     // We do not want the optimizer computing 2^31 point by point.
  1463     return old;
  1466   return this;
  1469 //-----------------------------filter------------------------------------------
  1470 const Type *TypeLong::filter( const Type *kills ) const {
  1471   const TypeLong* ft = join(kills)->isa_long();
  1472   if (ft == NULL || ft->empty())
  1473     return Type::TOP;           // Canonical empty value
  1474   if (ft->_widen < this->_widen) {
  1475     // Do not allow the value of kill->_widen to affect the outcome.
  1476     // The widen bits must be allowed to run freely through the graph.
  1477     ft = TypeLong::make(ft->_lo, ft->_hi, this->_widen);
  1479   return ft;
  1482 //------------------------------eq---------------------------------------------
  1483 // Structural equality check for Type representations
  1484 bool TypeLong::eq( const Type *t ) const {
  1485   const TypeLong *r = t->is_long(); // Handy access
  1486   return r->_lo == _lo &&  r->_hi == _hi  && r->_widen == _widen;
  1489 //------------------------------hash-------------------------------------------
  1490 // Type-specific hashing function.
  1491 int TypeLong::hash(void) const {
  1492   return (int)(_lo+_hi+_widen+(int)Type::Long);
  1495 //------------------------------is_finite--------------------------------------
  1496 // Has a finite value
  1497 bool TypeLong::is_finite() const {
  1498   return true;
  1501 //------------------------------dump2------------------------------------------
  1502 // Dump TypeLong
  1503 #ifndef PRODUCT
  1504 static const char* longnamenear(jlong x, const char* xname, char* buf, jlong n) {
  1505   if (n > x) {
  1506     if (n >= x + 10000)  return NULL;
  1507     sprintf(buf, "%s+" INT64_FORMAT, xname, n - x);
  1508   } else if (n < x) {
  1509     if (n <= x - 10000)  return NULL;
  1510     sprintf(buf, "%s-" INT64_FORMAT, xname, x - n);
  1511   } else {
  1512     return xname;
  1514   return buf;
  1517 static const char* longname(char* buf, jlong n) {
  1518   const char* str;
  1519   if (n == min_jlong)
  1520     return "min";
  1521   else if (n < min_jlong + 10000)
  1522     sprintf(buf, "min+" INT64_FORMAT, n - min_jlong);
  1523   else if (n == max_jlong)
  1524     return "max";
  1525   else if (n > max_jlong - 10000)
  1526     sprintf(buf, "max-" INT64_FORMAT, max_jlong - n);
  1527   else if ((str = longnamenear(max_juint, "maxuint", buf, n)) != NULL)
  1528     return str;
  1529   else if ((str = longnamenear(max_jint, "maxint", buf, n)) != NULL)
  1530     return str;
  1531   else if ((str = longnamenear(min_jint, "minint", buf, n)) != NULL)
  1532     return str;
  1533   else
  1534     sprintf(buf, INT64_FORMAT, n);
  1535   return buf;
  1538 void TypeLong::dump2( Dict &d, uint depth, outputStream *st ) const {
  1539   char buf[80], buf2[80];
  1540   if (_lo == min_jlong && _hi == max_jlong)
  1541     st->print("long");
  1542   else if (is_con())
  1543     st->print("long:%s", longname(buf, get_con()));
  1544   else if (_hi == max_jlong)
  1545     st->print("long:>=%s", longname(buf, _lo));
  1546   else if (_lo == min_jlong)
  1547     st->print("long:<=%s", longname(buf, _hi));
  1548   else
  1549     st->print("long:%s..%s", longname(buf, _lo), longname(buf2, _hi));
  1551   if (_widen != 0 && this != TypeLong::LONG)
  1552     st->print(":%.*s", _widen, "wwww");
  1554 #endif
  1556 //------------------------------singleton--------------------------------------
  1557 // TRUE if Type is a singleton type, FALSE otherwise.   Singletons are simple
  1558 // constants
  1559 bool TypeLong::singleton(void) const {
  1560   return _lo >= _hi;
  1563 bool TypeLong::empty(void) const {
  1564   return _lo > _hi;
  1567 //=============================================================================
  1568 // Convenience common pre-built types.
  1569 const TypeTuple *TypeTuple::IFBOTH;     // Return both arms of IF as reachable
  1570 const TypeTuple *TypeTuple::IFFALSE;
  1571 const TypeTuple *TypeTuple::IFTRUE;
  1572 const TypeTuple *TypeTuple::IFNEITHER;
  1573 const TypeTuple *TypeTuple::LOOPBODY;
  1574 const TypeTuple *TypeTuple::MEMBAR;
  1575 const TypeTuple *TypeTuple::STORECONDITIONAL;
  1576 const TypeTuple *TypeTuple::START_I2C;
  1577 const TypeTuple *TypeTuple::INT_PAIR;
  1578 const TypeTuple *TypeTuple::LONG_PAIR;
  1581 //------------------------------make-------------------------------------------
  1582 // Make a TypeTuple from the range of a method signature
  1583 const TypeTuple *TypeTuple::make_range(ciSignature* sig) {
  1584   ciType* return_type = sig->return_type();
  1585   uint total_fields = TypeFunc::Parms + return_type->size();
  1586   const Type **field_array = fields(total_fields);
  1587   switch (return_type->basic_type()) {
  1588   case T_LONG:
  1589     field_array[TypeFunc::Parms]   = TypeLong::LONG;
  1590     field_array[TypeFunc::Parms+1] = Type::HALF;
  1591     break;
  1592   case T_DOUBLE:
  1593     field_array[TypeFunc::Parms]   = Type::DOUBLE;
  1594     field_array[TypeFunc::Parms+1] = Type::HALF;
  1595     break;
  1596   case T_OBJECT:
  1597   case T_ARRAY:
  1598   case T_BOOLEAN:
  1599   case T_CHAR:
  1600   case T_FLOAT:
  1601   case T_BYTE:
  1602   case T_SHORT:
  1603   case T_INT:
  1604     field_array[TypeFunc::Parms] = get_const_type(return_type);
  1605     break;
  1606   case T_VOID:
  1607     break;
  1608   default:
  1609     ShouldNotReachHere();
  1611   return (TypeTuple*)(new TypeTuple(total_fields,field_array))->hashcons();
  1614 // Make a TypeTuple from the domain of a method signature
  1615 const TypeTuple *TypeTuple::make_domain(ciInstanceKlass* recv, ciSignature* sig) {
  1616   uint total_fields = TypeFunc::Parms + sig->size();
  1618   uint pos = TypeFunc::Parms;
  1619   const Type **field_array;
  1620   if (recv != NULL) {
  1621     total_fields++;
  1622     field_array = fields(total_fields);
  1623     // Use get_const_type here because it respects UseUniqueSubclasses:
  1624     field_array[pos++] = get_const_type(recv)->join(TypePtr::NOTNULL);
  1625   } else {
  1626     field_array = fields(total_fields);
  1629   int i = 0;
  1630   while (pos < total_fields) {
  1631     ciType* type = sig->type_at(i);
  1633     switch (type->basic_type()) {
  1634     case T_LONG:
  1635       field_array[pos++] = TypeLong::LONG;
  1636       field_array[pos++] = Type::HALF;
  1637       break;
  1638     case T_DOUBLE:
  1639       field_array[pos++] = Type::DOUBLE;
  1640       field_array[pos++] = Type::HALF;
  1641       break;
  1642     case T_OBJECT:
  1643     case T_ARRAY:
  1644     case T_BOOLEAN:
  1645     case T_CHAR:
  1646     case T_FLOAT:
  1647     case T_BYTE:
  1648     case T_SHORT:
  1649     case T_INT:
  1650       field_array[pos++] = get_const_type(type);
  1651       break;
  1652     default:
  1653       ShouldNotReachHere();
  1655     i++;
  1657   return (TypeTuple*)(new TypeTuple(total_fields,field_array))->hashcons();
  1660 const TypeTuple *TypeTuple::make( uint cnt, const Type **fields ) {
  1661   return (TypeTuple*)(new TypeTuple(cnt,fields))->hashcons();
  1664 //------------------------------fields-----------------------------------------
  1665 // Subroutine call type with space allocated for argument types
  1666 const Type **TypeTuple::fields( uint arg_cnt ) {
  1667   const Type **flds = (const Type **)(Compile::current()->type_arena()->Amalloc_4((TypeFunc::Parms+arg_cnt)*sizeof(Type*) ));
  1668   flds[TypeFunc::Control  ] = Type::CONTROL;
  1669   flds[TypeFunc::I_O      ] = Type::ABIO;
  1670   flds[TypeFunc::Memory   ] = Type::MEMORY;
  1671   flds[TypeFunc::FramePtr ] = TypeRawPtr::BOTTOM;
  1672   flds[TypeFunc::ReturnAdr] = Type::RETURN_ADDRESS;
  1674   return flds;
  1677 //------------------------------meet-------------------------------------------
  1678 // Compute the MEET of two types.  It returns a new Type object.
  1679 const Type *TypeTuple::xmeet( const Type *t ) const {
  1680   // Perform a fast test for common case; meeting the same types together.
  1681   if( this == t ) return this;  // Meeting same type-rep?
  1683   // Current "this->_base" is Tuple
  1684   switch (t->base()) {          // switch on original type
  1686   case Bottom:                  // Ye Olde Default
  1687     return t;
  1689   default:                      // All else is a mistake
  1690     typerr(t);
  1692   case Tuple: {                 // Meeting 2 signatures?
  1693     const TypeTuple *x = t->is_tuple();
  1694     assert( _cnt == x->_cnt, "" );
  1695     const Type **fields = (const Type **)(Compile::current()->type_arena()->Amalloc_4( _cnt*sizeof(Type*) ));
  1696     for( uint i=0; i<_cnt; i++ )
  1697       fields[i] = field_at(i)->xmeet( x->field_at(i) );
  1698     return TypeTuple::make(_cnt,fields);
  1700   case Top:
  1701     break;
  1703   return this;                  // Return the double constant
  1706 //------------------------------xdual------------------------------------------
  1707 // Dual: compute field-by-field dual
  1708 const Type *TypeTuple::xdual() const {
  1709   const Type **fields = (const Type **)(Compile::current()->type_arena()->Amalloc_4( _cnt*sizeof(Type*) ));
  1710   for( uint i=0; i<_cnt; i++ )
  1711     fields[i] = _fields[i]->dual();
  1712   return new TypeTuple(_cnt,fields);
  1715 //------------------------------eq---------------------------------------------
  1716 // Structural equality check for Type representations
  1717 bool TypeTuple::eq( const Type *t ) const {
  1718   const TypeTuple *s = (const TypeTuple *)t;
  1719   if (_cnt != s->_cnt)  return false;  // Unequal field counts
  1720   for (uint i = 0; i < _cnt; i++)
  1721     if (field_at(i) != s->field_at(i)) // POINTER COMPARE!  NO RECURSION!
  1722       return false;             // Missed
  1723   return true;
  1726 //------------------------------hash-------------------------------------------
  1727 // Type-specific hashing function.
  1728 int TypeTuple::hash(void) const {
  1729   intptr_t sum = _cnt;
  1730   for( uint i=0; i<_cnt; i++ )
  1731     sum += (intptr_t)_fields[i];     // Hash on pointers directly
  1732   return sum;
  1735 //------------------------------dump2------------------------------------------
  1736 // Dump signature Type
  1737 #ifndef PRODUCT
  1738 void TypeTuple::dump2( Dict &d, uint depth, outputStream *st ) const {
  1739   st->print("{");
  1740   if( !depth || d[this] ) {     // Check for recursive print
  1741     st->print("...}");
  1742     return;
  1744   d.Insert((void*)this, (void*)this);   // Stop recursion
  1745   if( _cnt ) {
  1746     uint i;
  1747     for( i=0; i<_cnt-1; i++ ) {
  1748       st->print("%d:", i);
  1749       _fields[i]->dump2(d, depth-1, st);
  1750       st->print(", ");
  1752     st->print("%d:", i);
  1753     _fields[i]->dump2(d, depth-1, st);
  1755   st->print("}");
  1757 #endif
  1759 //------------------------------singleton--------------------------------------
  1760 // TRUE if Type is a singleton type, FALSE otherwise.   Singletons are simple
  1761 // constants (Ldi nodes).  Singletons are integer, float or double constants
  1762 // or a single symbol.
  1763 bool TypeTuple::singleton(void) const {
  1764   return false;                 // Never a singleton
  1767 bool TypeTuple::empty(void) const {
  1768   for( uint i=0; i<_cnt; i++ ) {
  1769     if (_fields[i]->empty())  return true;
  1771   return false;
  1774 //=============================================================================
  1775 // Convenience common pre-built types.
  1777 inline const TypeInt* normalize_array_size(const TypeInt* size) {
  1778   // Certain normalizations keep us sane when comparing types.
  1779   // We do not want arrayOop variables to differ only by the wideness
  1780   // of their index types.  Pick minimum wideness, since that is the
  1781   // forced wideness of small ranges anyway.
  1782   if (size->_widen != Type::WidenMin)
  1783     return TypeInt::make(size->_lo, size->_hi, Type::WidenMin);
  1784   else
  1785     return size;
  1788 //------------------------------make-------------------------------------------
  1789 const TypeAry *TypeAry::make( const Type *elem, const TypeInt *size) {
  1790   if (UseCompressedOops && elem->isa_oopptr()) {
  1791     elem = elem->make_narrowoop();
  1793   size = normalize_array_size(size);
  1794   return (TypeAry*)(new TypeAry(elem,size))->hashcons();
  1797 //------------------------------meet-------------------------------------------
  1798 // Compute the MEET of two types.  It returns a new Type object.
  1799 const Type *TypeAry::xmeet( const Type *t ) const {
  1800   // Perform a fast test for common case; meeting the same types together.
  1801   if( this == t ) return this;  // Meeting same type-rep?
  1803   // Current "this->_base" is Ary
  1804   switch (t->base()) {          // switch on original type
  1806   case Bottom:                  // Ye Olde Default
  1807     return t;
  1809   default:                      // All else is a mistake
  1810     typerr(t);
  1812   case Array: {                 // Meeting 2 arrays?
  1813     const TypeAry *a = t->is_ary();
  1814     return TypeAry::make(_elem->meet(a->_elem),
  1815                          _size->xmeet(a->_size)->is_int());
  1817   case Top:
  1818     break;
  1820   return this;                  // Return the double constant
  1823 //------------------------------xdual------------------------------------------
  1824 // Dual: compute field-by-field dual
  1825 const Type *TypeAry::xdual() const {
  1826   const TypeInt* size_dual = _size->dual()->is_int();
  1827   size_dual = normalize_array_size(size_dual);
  1828   return new TypeAry( _elem->dual(), size_dual);
  1831 //------------------------------eq---------------------------------------------
  1832 // Structural equality check for Type representations
  1833 bool TypeAry::eq( const Type *t ) const {
  1834   const TypeAry *a = (const TypeAry*)t;
  1835   return _elem == a->_elem &&
  1836     _size == a->_size;
  1839 //------------------------------hash-------------------------------------------
  1840 // Type-specific hashing function.
  1841 int TypeAry::hash(void) const {
  1842   return (intptr_t)_elem + (intptr_t)_size;
  1845 //----------------------interface_vs_oop---------------------------------------
  1846 #ifdef ASSERT
  1847 bool TypeAry::interface_vs_oop(const Type *t) const {
  1848   const TypeAry* t_ary = t->is_ary();
  1849   if (t_ary) {
  1850     return _elem->interface_vs_oop(t_ary->_elem);
  1852   return false;
  1854 #endif
  1856 //------------------------------dump2------------------------------------------
  1857 #ifndef PRODUCT
  1858 void TypeAry::dump2( Dict &d, uint depth, outputStream *st ) const {
  1859   _elem->dump2(d, depth, st);
  1860   st->print("[");
  1861   _size->dump2(d, depth, st);
  1862   st->print("]");
  1864 #endif
  1866 //------------------------------singleton--------------------------------------
  1867 // TRUE if Type is a singleton type, FALSE otherwise.   Singletons are simple
  1868 // constants (Ldi nodes).  Singletons are integer, float or double constants
  1869 // or a single symbol.
  1870 bool TypeAry::singleton(void) const {
  1871   return false;                 // Never a singleton
  1874 bool TypeAry::empty(void) const {
  1875   return _elem->empty() || _size->empty();
  1878 //--------------------------ary_must_be_exact----------------------------------
  1879 bool TypeAry::ary_must_be_exact() const {
  1880   if (!UseExactTypes)       return false;
  1881   // This logic looks at the element type of an array, and returns true
  1882   // if the element type is either a primitive or a final instance class.
  1883   // In such cases, an array built on this ary must have no subclasses.
  1884   if (_elem == BOTTOM)      return false;  // general array not exact
  1885   if (_elem == TOP   )      return false;  // inverted general array not exact
  1886   const TypeOopPtr*  toop = NULL;
  1887   if (UseCompressedOops && _elem->isa_narrowoop()) {
  1888     toop = _elem->make_ptr()->isa_oopptr();
  1889   } else {
  1890     toop = _elem->isa_oopptr();
  1892   if (!toop)                return true;   // a primitive type, like int
  1893   ciKlass* tklass = toop->klass();
  1894   if (tklass == NULL)       return false;  // unloaded class
  1895   if (!tklass->is_loaded()) return false;  // unloaded class
  1896   const TypeInstPtr* tinst;
  1897   if (_elem->isa_narrowoop())
  1898     tinst = _elem->make_ptr()->isa_instptr();
  1899   else
  1900     tinst = _elem->isa_instptr();
  1901   if (tinst)
  1902     return tklass->as_instance_klass()->is_final();
  1903   const TypeAryPtr*  tap;
  1904   if (_elem->isa_narrowoop())
  1905     tap = _elem->make_ptr()->isa_aryptr();
  1906   else
  1907     tap = _elem->isa_aryptr();
  1908   if (tap)
  1909     return tap->ary()->ary_must_be_exact();
  1910   return false;
  1913 //=============================================================================
  1914 // Convenience common pre-built types.
  1915 const TypePtr *TypePtr::NULL_PTR;
  1916 const TypePtr *TypePtr::NOTNULL;
  1917 const TypePtr *TypePtr::BOTTOM;
  1919 //------------------------------meet-------------------------------------------
  1920 // Meet over the PTR enum
  1921 const TypePtr::PTR TypePtr::ptr_meet[TypePtr::lastPTR][TypePtr::lastPTR] = {
  1922   //              TopPTR,    AnyNull,   Constant, Null,   NotNull, BotPTR,
  1923   { /* Top     */ TopPTR,    AnyNull,   Constant, Null,   NotNull, BotPTR,},
  1924   { /* AnyNull */ AnyNull,   AnyNull,   Constant, BotPTR, NotNull, BotPTR,},
  1925   { /* Constant*/ Constant,  Constant,  Constant, BotPTR, NotNull, BotPTR,},
  1926   { /* Null    */ Null,      BotPTR,    BotPTR,   Null,   BotPTR,  BotPTR,},
  1927   { /* NotNull */ NotNull,   NotNull,   NotNull,  BotPTR, NotNull, BotPTR,},
  1928   { /* BotPTR  */ BotPTR,    BotPTR,    BotPTR,   BotPTR, BotPTR,  BotPTR,}
  1929 };
  1931 //------------------------------make-------------------------------------------
  1932 const TypePtr *TypePtr::make( TYPES t, enum PTR ptr, int offset ) {
  1933   return (TypePtr*)(new TypePtr(t,ptr,offset))->hashcons();
  1936 //------------------------------cast_to_ptr_type-------------------------------
  1937 const Type *TypePtr::cast_to_ptr_type(PTR ptr) const {
  1938   assert(_base == AnyPtr, "subclass must override cast_to_ptr_type");
  1939   if( ptr == _ptr ) return this;
  1940   return make(_base, ptr, _offset);
  1943 //------------------------------get_con----------------------------------------
  1944 intptr_t TypePtr::get_con() const {
  1945   assert( _ptr == Null, "" );
  1946   return _offset;
  1949 //------------------------------meet-------------------------------------------
  1950 // Compute the MEET of two types.  It returns a new Type object.
  1951 const Type *TypePtr::xmeet( const Type *t ) const {
  1952   // Perform a fast test for common case; meeting the same types together.
  1953   if( this == t ) return this;  // Meeting same type-rep?
  1955   // Current "this->_base" is AnyPtr
  1956   switch (t->base()) {          // switch on original type
  1957   case Int:                     // Mixing ints & oops happens when javac
  1958   case Long:                    // reuses local variables
  1959   case FloatTop:
  1960   case FloatCon:
  1961   case FloatBot:
  1962   case DoubleTop:
  1963   case DoubleCon:
  1964   case DoubleBot:
  1965   case NarrowOop:
  1966   case Bottom:                  // Ye Olde Default
  1967     return Type::BOTTOM;
  1968   case Top:
  1969     return this;
  1971   case AnyPtr: {                // Meeting to AnyPtrs
  1972     const TypePtr *tp = t->is_ptr();
  1973     return make( AnyPtr, meet_ptr(tp->ptr()), meet_offset(tp->offset()) );
  1975   case RawPtr:                  // For these, flip the call around to cut down
  1976   case OopPtr:
  1977   case InstPtr:                 // on the cases I have to handle.
  1978   case KlassPtr:
  1979   case AryPtr:
  1980     return t->xmeet(this);      // Call in reverse direction
  1981   default:                      // All else is a mistake
  1982     typerr(t);
  1985   return this;
  1988 //------------------------------meet_offset------------------------------------
  1989 int TypePtr::meet_offset( int offset ) const {
  1990   // Either is 'TOP' offset?  Return the other offset!
  1991   if( _offset == OffsetTop ) return offset;
  1992   if( offset == OffsetTop ) return _offset;
  1993   // If either is different, return 'BOTTOM' offset
  1994   if( _offset != offset ) return OffsetBot;
  1995   return _offset;
  1998 //------------------------------dual_offset------------------------------------
  1999 int TypePtr::dual_offset( ) const {
  2000   if( _offset == OffsetTop ) return OffsetBot;// Map 'TOP' into 'BOTTOM'
  2001   if( _offset == OffsetBot ) return OffsetTop;// Map 'BOTTOM' into 'TOP'
  2002   return _offset;               // Map everything else into self
  2005 //------------------------------xdual------------------------------------------
  2006 // Dual: compute field-by-field dual
  2007 const TypePtr::PTR TypePtr::ptr_dual[TypePtr::lastPTR] = {
  2008   BotPTR, NotNull, Constant, Null, AnyNull, TopPTR
  2009 };
  2010 const Type *TypePtr::xdual() const {
  2011   return new TypePtr( AnyPtr, dual_ptr(), dual_offset() );
  2014 //------------------------------xadd_offset------------------------------------
  2015 int TypePtr::xadd_offset( intptr_t offset ) const {
  2016   // Adding to 'TOP' offset?  Return 'TOP'!
  2017   if( _offset == OffsetTop || offset == OffsetTop ) return OffsetTop;
  2018   // Adding to 'BOTTOM' offset?  Return 'BOTTOM'!
  2019   if( _offset == OffsetBot || offset == OffsetBot ) return OffsetBot;
  2020   // Addition overflows or "accidentally" equals to OffsetTop? Return 'BOTTOM'!
  2021   offset += (intptr_t)_offset;
  2022   if (offset != (int)offset || offset == OffsetTop) return OffsetBot;
  2024   // assert( _offset >= 0 && _offset+offset >= 0, "" );
  2025   // It is possible to construct a negative offset during PhaseCCP
  2027   return (int)offset;        // Sum valid offsets
  2030 //------------------------------add_offset-------------------------------------
  2031 const TypePtr *TypePtr::add_offset( intptr_t offset ) const {
  2032   return make( AnyPtr, _ptr, xadd_offset(offset) );
  2035 //------------------------------eq---------------------------------------------
  2036 // Structural equality check for Type representations
  2037 bool TypePtr::eq( const Type *t ) const {
  2038   const TypePtr *a = (const TypePtr*)t;
  2039   return _ptr == a->ptr() && _offset == a->offset();
  2042 //------------------------------hash-------------------------------------------
  2043 // Type-specific hashing function.
  2044 int TypePtr::hash(void) const {
  2045   return _ptr + _offset;
  2048 //------------------------------dump2------------------------------------------
  2049 const char *const TypePtr::ptr_msg[TypePtr::lastPTR] = {
  2050   "TopPTR","AnyNull","Constant","NULL","NotNull","BotPTR"
  2051 };
  2053 #ifndef PRODUCT
  2054 void TypePtr::dump2( Dict &d, uint depth, outputStream *st ) const {
  2055   if( _ptr == Null ) st->print("NULL");
  2056   else st->print("%s *", ptr_msg[_ptr]);
  2057   if( _offset == OffsetTop ) st->print("+top");
  2058   else if( _offset == OffsetBot ) st->print("+bot");
  2059   else if( _offset ) st->print("+%d", _offset);
  2061 #endif
  2063 //------------------------------singleton--------------------------------------
  2064 // TRUE if Type is a singleton type, FALSE otherwise.   Singletons are simple
  2065 // constants
  2066 bool TypePtr::singleton(void) const {
  2067   // TopPTR, Null, AnyNull, Constant are all singletons
  2068   return (_offset != OffsetBot) && !below_centerline(_ptr);
  2071 bool TypePtr::empty(void) const {
  2072   return (_offset == OffsetTop) || above_centerline(_ptr);
  2075 //=============================================================================
  2076 // Convenience common pre-built types.
  2077 const TypeRawPtr *TypeRawPtr::BOTTOM;
  2078 const TypeRawPtr *TypeRawPtr::NOTNULL;
  2080 //------------------------------make-------------------------------------------
  2081 const TypeRawPtr *TypeRawPtr::make( enum PTR ptr ) {
  2082   assert( ptr != Constant, "what is the constant?" );
  2083   assert( ptr != Null, "Use TypePtr for NULL" );
  2084   return (TypeRawPtr*)(new TypeRawPtr(ptr,0))->hashcons();
  2087 const TypeRawPtr *TypeRawPtr::make( address bits ) {
  2088   assert( bits, "Use TypePtr for NULL" );
  2089   return (TypeRawPtr*)(new TypeRawPtr(Constant,bits))->hashcons();
  2092 //------------------------------cast_to_ptr_type-------------------------------
  2093 const Type *TypeRawPtr::cast_to_ptr_type(PTR ptr) const {
  2094   assert( ptr != Constant, "what is the constant?" );
  2095   assert( ptr != Null, "Use TypePtr for NULL" );
  2096   assert( _bits==0, "Why cast a constant address?");
  2097   if( ptr == _ptr ) return this;
  2098   return make(ptr);
  2101 //------------------------------get_con----------------------------------------
  2102 intptr_t TypeRawPtr::get_con() const {
  2103   assert( _ptr == Null || _ptr == Constant, "" );
  2104   return (intptr_t)_bits;
  2107 //------------------------------meet-------------------------------------------
  2108 // Compute the MEET of two types.  It returns a new Type object.
  2109 const Type *TypeRawPtr::xmeet( const Type *t ) const {
  2110   // Perform a fast test for common case; meeting the same types together.
  2111   if( this == t ) return this;  // Meeting same type-rep?
  2113   // Current "this->_base" is RawPtr
  2114   switch( t->base() ) {         // switch on original type
  2115   case Bottom:                  // Ye Olde Default
  2116     return t;
  2117   case Top:
  2118     return this;
  2119   case AnyPtr:                  // Meeting to AnyPtrs
  2120     break;
  2121   case RawPtr: {                // might be top, bot, any/not or constant
  2122     enum PTR tptr = t->is_ptr()->ptr();
  2123     enum PTR ptr = meet_ptr( tptr );
  2124     if( ptr == Constant ) {     // Cannot be equal constants, so...
  2125       if( tptr == Constant && _ptr != Constant)  return t;
  2126       if( _ptr == Constant && tptr != Constant)  return this;
  2127       ptr = NotNull;            // Fall down in lattice
  2129     return make( ptr );
  2132   case OopPtr:
  2133   case InstPtr:
  2134   case KlassPtr:
  2135   case AryPtr:
  2136     return TypePtr::BOTTOM;     // Oop meet raw is not well defined
  2137   default:                      // All else is a mistake
  2138     typerr(t);
  2141   // Found an AnyPtr type vs self-RawPtr type
  2142   const TypePtr *tp = t->is_ptr();
  2143   switch (tp->ptr()) {
  2144   case TypePtr::TopPTR:  return this;
  2145   case TypePtr::BotPTR:  return t;
  2146   case TypePtr::Null:
  2147     if( _ptr == TypePtr::TopPTR ) return t;
  2148     return TypeRawPtr::BOTTOM;
  2149   case TypePtr::NotNull: return TypePtr::make( AnyPtr, meet_ptr(TypePtr::NotNull), tp->meet_offset(0) );
  2150   case TypePtr::AnyNull:
  2151     if( _ptr == TypePtr::Constant) return this;
  2152     return make( meet_ptr(TypePtr::AnyNull) );
  2153   default: ShouldNotReachHere();
  2155   return this;
  2158 //------------------------------xdual------------------------------------------
  2159 // Dual: compute field-by-field dual
  2160 const Type *TypeRawPtr::xdual() const {
  2161   return new TypeRawPtr( dual_ptr(), _bits );
  2164 //------------------------------add_offset-------------------------------------
  2165 const TypePtr *TypeRawPtr::add_offset( intptr_t offset ) const {
  2166   if( offset == OffsetTop ) return BOTTOM; // Undefined offset-> undefined pointer
  2167   if( offset == OffsetBot ) return BOTTOM; // Unknown offset-> unknown pointer
  2168   if( offset == 0 ) return this; // No change
  2169   switch (_ptr) {
  2170   case TypePtr::TopPTR:
  2171   case TypePtr::BotPTR:
  2172   case TypePtr::NotNull:
  2173     return this;
  2174   case TypePtr::Null:
  2175   case TypePtr::Constant:
  2176     return make( _bits+offset );
  2177   default:  ShouldNotReachHere();
  2179   return NULL;                  // Lint noise
  2182 //------------------------------eq---------------------------------------------
  2183 // Structural equality check for Type representations
  2184 bool TypeRawPtr::eq( const Type *t ) const {
  2185   const TypeRawPtr *a = (const TypeRawPtr*)t;
  2186   return _bits == a->_bits && TypePtr::eq(t);
  2189 //------------------------------hash-------------------------------------------
  2190 // Type-specific hashing function.
  2191 int TypeRawPtr::hash(void) const {
  2192   return (intptr_t)_bits + TypePtr::hash();
  2195 //------------------------------dump2------------------------------------------
  2196 #ifndef PRODUCT
  2197 void TypeRawPtr::dump2( Dict &d, uint depth, outputStream *st ) const {
  2198   if( _ptr == Constant )
  2199     st->print(INTPTR_FORMAT, _bits);
  2200   else
  2201     st->print("rawptr:%s", ptr_msg[_ptr]);
  2203 #endif
  2205 //=============================================================================
  2206 // Convenience common pre-built type.
  2207 const TypeOopPtr *TypeOopPtr::BOTTOM;
  2209 //------------------------------TypeOopPtr-------------------------------------
  2210 TypeOopPtr::TypeOopPtr( TYPES t, PTR ptr, ciKlass* k, bool xk, ciObject* o, int offset, int instance_id )
  2211   : TypePtr(t, ptr, offset),
  2212     _const_oop(o), _klass(k),
  2213     _klass_is_exact(xk),
  2214     _is_ptr_to_narrowoop(false),
  2215     _instance_id(instance_id) {
  2216 #ifdef _LP64
  2217   if (UseCompressedOops && _offset != 0) {
  2218     if (klass() == NULL) {
  2219       assert(this->isa_aryptr(), "only arrays without klass");
  2220       _is_ptr_to_narrowoop = true;
  2221     } else if (_offset == oopDesc::klass_offset_in_bytes()) {
  2222       _is_ptr_to_narrowoop = true;
  2223     } else if (this->isa_aryptr()) {
  2224       _is_ptr_to_narrowoop = (klass()->is_obj_array_klass() &&
  2225                              _offset != arrayOopDesc::length_offset_in_bytes());
  2226     } else if (klass() == ciEnv::current()->Class_klass() &&
  2227                (_offset == java_lang_Class::klass_offset_in_bytes() ||
  2228                 _offset == java_lang_Class::array_klass_offset_in_bytes())) {
  2229       // Special hidden fields from the Class.
  2230       assert(this->isa_instptr(), "must be an instance ptr.");
  2231       _is_ptr_to_narrowoop = true;
  2232     } else if (klass()->is_instance_klass()) {
  2233       ciInstanceKlass* ik = klass()->as_instance_klass();
  2234       ciField* field = NULL;
  2235       if (this->isa_klassptr()) {
  2236         // Perm objects don't use compressed references, except for
  2237         // static fields which are currently compressed.
  2238         field = ik->get_field_by_offset(_offset, true);
  2239         if (field != NULL) {
  2240           BasicType basic_elem_type = field->layout_type();
  2241           _is_ptr_to_narrowoop = (basic_elem_type == T_OBJECT ||
  2242                                   basic_elem_type == T_ARRAY);
  2244       } else if (_offset == OffsetBot || _offset == OffsetTop) {
  2245         // unsafe access
  2246         _is_ptr_to_narrowoop = true;
  2247       } else { // exclude unsafe ops
  2248         assert(this->isa_instptr(), "must be an instance ptr.");
  2249         // Field which contains a compressed oop references.
  2250         field = ik->get_field_by_offset(_offset, false);
  2251         if (field != NULL) {
  2252           BasicType basic_elem_type = field->layout_type();
  2253           _is_ptr_to_narrowoop = (basic_elem_type == T_OBJECT ||
  2254                                   basic_elem_type == T_ARRAY);
  2255         } else if (klass()->equals(ciEnv::current()->Object_klass())) {
  2256           // Compile::find_alias_type() cast exactness on all types to verify
  2257           // that it does not affect alias type.
  2258           _is_ptr_to_narrowoop = true;
  2259         } else {
  2260           // Type for the copy start in LibraryCallKit::inline_native_clone().
  2261           assert(!klass_is_exact(), "only non-exact klass");
  2262           _is_ptr_to_narrowoop = true;
  2267 #endif
  2270 //------------------------------make-------------------------------------------
  2271 const TypeOopPtr *TypeOopPtr::make(PTR ptr,
  2272                                    int offset, int instance_id) {
  2273   assert(ptr != Constant, "no constant generic pointers");
  2274   ciKlass*  k = ciKlassKlass::make();
  2275   bool      xk = false;
  2276   ciObject* o = NULL;
  2277   return (TypeOopPtr*)(new TypeOopPtr(OopPtr, ptr, k, xk, o, offset, instance_id))->hashcons();
  2281 //------------------------------cast_to_ptr_type-------------------------------
  2282 const Type *TypeOopPtr::cast_to_ptr_type(PTR ptr) const {
  2283   assert(_base == OopPtr, "subclass must override cast_to_ptr_type");
  2284   if( ptr == _ptr ) return this;
  2285   return make(ptr, _offset, _instance_id);
  2288 //-----------------------------cast_to_instance_id----------------------------
  2289 const TypeOopPtr *TypeOopPtr::cast_to_instance_id(int instance_id) const {
  2290   // There are no instances of a general oop.
  2291   // Return self unchanged.
  2292   return this;
  2295 //-----------------------------cast_to_exactness-------------------------------
  2296 const Type *TypeOopPtr::cast_to_exactness(bool klass_is_exact) const {
  2297   // There is no such thing as an exact general oop.
  2298   // Return self unchanged.
  2299   return this;
  2303 //------------------------------as_klass_type----------------------------------
  2304 // Return the klass type corresponding to this instance or array type.
  2305 // It is the type that is loaded from an object of this type.
  2306 const TypeKlassPtr* TypeOopPtr::as_klass_type() const {
  2307   ciKlass* k = klass();
  2308   bool    xk = klass_is_exact();
  2309   if (k == NULL || !k->is_java_klass())
  2310     return TypeKlassPtr::OBJECT;
  2311   else
  2312     return TypeKlassPtr::make(xk? Constant: NotNull, k, 0);
  2316 //------------------------------meet-------------------------------------------
  2317 // Compute the MEET of two types.  It returns a new Type object.
  2318 const Type *TypeOopPtr::xmeet( const Type *t ) const {
  2319   // Perform a fast test for common case; meeting the same types together.
  2320   if( this == t ) return this;  // Meeting same type-rep?
  2322   // Current "this->_base" is OopPtr
  2323   switch (t->base()) {          // switch on original type
  2325   case Int:                     // Mixing ints & oops happens when javac
  2326   case Long:                    // reuses local variables
  2327   case FloatTop:
  2328   case FloatCon:
  2329   case FloatBot:
  2330   case DoubleTop:
  2331   case DoubleCon:
  2332   case DoubleBot:
  2333   case NarrowOop:
  2334   case Bottom:                  // Ye Olde Default
  2335     return Type::BOTTOM;
  2336   case Top:
  2337     return this;
  2339   default:                      // All else is a mistake
  2340     typerr(t);
  2342   case RawPtr:
  2343     return TypePtr::BOTTOM;     // Oop meet raw is not well defined
  2345   case AnyPtr: {
  2346     // Found an AnyPtr type vs self-OopPtr type
  2347     const TypePtr *tp = t->is_ptr();
  2348     int offset = meet_offset(tp->offset());
  2349     PTR ptr = meet_ptr(tp->ptr());
  2350     switch (tp->ptr()) {
  2351     case Null:
  2352       if (ptr == Null)  return TypePtr::make(AnyPtr, ptr, offset);
  2353       // else fall through:
  2354     case TopPTR:
  2355     case AnyNull: {
  2356       int instance_id = meet_instance_id(InstanceTop);
  2357       return make(ptr, offset, instance_id);
  2359     case BotPTR:
  2360     case NotNull:
  2361       return TypePtr::make(AnyPtr, ptr, offset);
  2362     default: typerr(t);
  2366   case OopPtr: {                 // Meeting to other OopPtrs
  2367     const TypeOopPtr *tp = t->is_oopptr();
  2368     int instance_id = meet_instance_id(tp->instance_id());
  2369     return make( meet_ptr(tp->ptr()), meet_offset(tp->offset()), instance_id );
  2372   case InstPtr:                  // For these, flip the call around to cut down
  2373   case KlassPtr:                 // on the cases I have to handle.
  2374   case AryPtr:
  2375     return t->xmeet(this);      // Call in reverse direction
  2377   } // End of switch
  2378   return this;                  // Return the double constant
  2382 //------------------------------xdual------------------------------------------
  2383 // Dual of a pure heap pointer.  No relevant klass or oop information.
  2384 const Type *TypeOopPtr::xdual() const {
  2385   assert(klass() == ciKlassKlass::make(), "no klasses here");
  2386   assert(const_oop() == NULL,             "no constants here");
  2387   return new TypeOopPtr(_base, dual_ptr(), klass(), klass_is_exact(), const_oop(), dual_offset(), dual_instance_id()  );
  2390 //--------------------------make_from_klass_common-----------------------------
  2391 // Computes the element-type given a klass.
  2392 const TypeOopPtr* TypeOopPtr::make_from_klass_common(ciKlass *klass, bool klass_change, bool try_for_exact) {
  2393   assert(klass->is_java_klass(), "must be java language klass");
  2394   if (klass->is_instance_klass()) {
  2395     Compile* C = Compile::current();
  2396     Dependencies* deps = C->dependencies();
  2397     assert((deps != NULL) == (C->method() != NULL && C->method()->code_size() > 0), "sanity");
  2398     // Element is an instance
  2399     bool klass_is_exact = false;
  2400     if (klass->is_loaded()) {
  2401       // Try to set klass_is_exact.
  2402       ciInstanceKlass* ik = klass->as_instance_klass();
  2403       klass_is_exact = ik->is_final();
  2404       if (!klass_is_exact && klass_change
  2405           && deps != NULL && UseUniqueSubclasses) {
  2406         ciInstanceKlass* sub = ik->unique_concrete_subklass();
  2407         if (sub != NULL) {
  2408           deps->assert_abstract_with_unique_concrete_subtype(ik, sub);
  2409           klass = ik = sub;
  2410           klass_is_exact = sub->is_final();
  2413       if (!klass_is_exact && try_for_exact
  2414           && deps != NULL && UseExactTypes) {
  2415         if (!ik->is_interface() && !ik->has_subklass()) {
  2416           // Add a dependence; if concrete subclass added we need to recompile
  2417           deps->assert_leaf_type(ik);
  2418           klass_is_exact = true;
  2422     return TypeInstPtr::make(TypePtr::BotPTR, klass, klass_is_exact, NULL, 0);
  2423   } else if (klass->is_obj_array_klass()) {
  2424     // Element is an object array. Recursively call ourself.
  2425     const TypeOopPtr *etype = TypeOopPtr::make_from_klass_common(klass->as_obj_array_klass()->element_klass(), false, try_for_exact);
  2426     bool xk = etype->klass_is_exact();
  2427     const TypeAry* arr0 = TypeAry::make(etype, TypeInt::POS);
  2428     // We used to pass NotNull in here, asserting that the sub-arrays
  2429     // are all not-null.  This is not true in generally, as code can
  2430     // slam NULLs down in the subarrays.
  2431     const TypeAryPtr* arr = TypeAryPtr::make(TypePtr::BotPTR, arr0, klass, xk, 0);
  2432     return arr;
  2433   } else if (klass->is_type_array_klass()) {
  2434     // Element is an typeArray
  2435     const Type* etype = get_const_basic_type(klass->as_type_array_klass()->element_type());
  2436     const TypeAry* arr0 = TypeAry::make(etype, TypeInt::POS);
  2437     // We used to pass NotNull in here, asserting that the array pointer
  2438     // is not-null. That was not true in general.
  2439     const TypeAryPtr* arr = TypeAryPtr::make(TypePtr::BotPTR, arr0, klass, true, 0);
  2440     return arr;
  2441   } else {
  2442     ShouldNotReachHere();
  2443     return NULL;
  2447 //------------------------------make_from_constant-----------------------------
  2448 // Make a java pointer from an oop constant
  2449 const TypeOopPtr* TypeOopPtr::make_from_constant(ciObject* o, bool require_constant) {
  2450   if (o->is_method_data() || o->is_method() || o->is_cpcache()) {
  2451     // Treat much like a typeArray of bytes, like below, but fake the type...
  2452     const Type* etype = (Type*)get_const_basic_type(T_BYTE);
  2453     const TypeAry* arr0 = TypeAry::make(etype, TypeInt::POS);
  2454     ciKlass *klass = ciTypeArrayKlass::make((BasicType) T_BYTE);
  2455     assert(o->can_be_constant(), "method data oops should be tenured");
  2456     const TypeAryPtr* arr = TypeAryPtr::make(TypePtr::Constant, o, arr0, klass, true, 0);
  2457     return arr;
  2458   } else {
  2459     assert(o->is_java_object(), "must be java language object");
  2460     assert(!o->is_null_object(), "null object not yet handled here.");
  2461     ciKlass *klass = o->klass();
  2462     if (klass->is_instance_klass()) {
  2463       // Element is an instance
  2464       if (require_constant) {
  2465         if (!o->can_be_constant())  return NULL;
  2466       } else if (!o->should_be_constant()) {
  2467         return TypeInstPtr::make(TypePtr::NotNull, klass, true, NULL, 0);
  2469       return TypeInstPtr::make(o);
  2470     } else if (klass->is_obj_array_klass()) {
  2471       // Element is an object array. Recursively call ourself.
  2472       const Type *etype =
  2473         TypeOopPtr::make_from_klass_raw(klass->as_obj_array_klass()->element_klass());
  2474       const TypeAry* arr0 = TypeAry::make(etype, TypeInt::make(o->as_array()->length()));
  2475       // We used to pass NotNull in here, asserting that the sub-arrays
  2476       // are all not-null.  This is not true in generally, as code can
  2477       // slam NULLs down in the subarrays.
  2478       if (require_constant) {
  2479         if (!o->can_be_constant())  return NULL;
  2480       } else if (!o->should_be_constant()) {
  2481         return TypeAryPtr::make(TypePtr::NotNull, arr0, klass, true, 0);
  2483       const TypeAryPtr* arr = TypeAryPtr::make(TypePtr::Constant, o, arr0, klass, true, 0);
  2484       return arr;
  2485     } else if (klass->is_type_array_klass()) {
  2486       // Element is an typeArray
  2487       const Type* etype =
  2488         (Type*)get_const_basic_type(klass->as_type_array_klass()->element_type());
  2489       const TypeAry* arr0 = TypeAry::make(etype, TypeInt::make(o->as_array()->length()));
  2490       // We used to pass NotNull in here, asserting that the array pointer
  2491       // is not-null. That was not true in general.
  2492       if (require_constant) {
  2493         if (!o->can_be_constant())  return NULL;
  2494       } else if (!o->should_be_constant()) {
  2495         return TypeAryPtr::make(TypePtr::NotNull, arr0, klass, true, 0);
  2497       const TypeAryPtr* arr = TypeAryPtr::make(TypePtr::Constant, o, arr0, klass, true, 0);
  2498       return arr;
  2502   ShouldNotReachHere();
  2503   return NULL;
  2506 //------------------------------get_con----------------------------------------
  2507 intptr_t TypeOopPtr::get_con() const {
  2508   assert( _ptr == Null || _ptr == Constant, "" );
  2509   assert( _offset >= 0, "" );
  2511   if (_offset != 0) {
  2512     // After being ported to the compiler interface, the compiler no longer
  2513     // directly manipulates the addresses of oops.  Rather, it only has a pointer
  2514     // to a handle at compile time.  This handle is embedded in the generated
  2515     // code and dereferenced at the time the nmethod is made.  Until that time,
  2516     // it is not reasonable to do arithmetic with the addresses of oops (we don't
  2517     // have access to the addresses!).  This does not seem to currently happen,
  2518     // but this assertion here is to help prevent its occurence.
  2519     tty->print_cr("Found oop constant with non-zero offset");
  2520     ShouldNotReachHere();
  2523   return (intptr_t)const_oop()->constant_encoding();
  2527 //-----------------------------filter------------------------------------------
  2528 // Do not allow interface-vs.-noninterface joins to collapse to top.
  2529 const Type *TypeOopPtr::filter( const Type *kills ) const {
  2531   const Type* ft = join(kills);
  2532   const TypeInstPtr* ftip = ft->isa_instptr();
  2533   const TypeInstPtr* ktip = kills->isa_instptr();
  2534   const TypeKlassPtr* ftkp = ft->isa_klassptr();
  2535   const TypeKlassPtr* ktkp = kills->isa_klassptr();
  2537   if (ft->empty()) {
  2538     // Check for evil case of 'this' being a class and 'kills' expecting an
  2539     // interface.  This can happen because the bytecodes do not contain
  2540     // enough type info to distinguish a Java-level interface variable
  2541     // from a Java-level object variable.  If we meet 2 classes which
  2542     // both implement interface I, but their meet is at 'j/l/O' which
  2543     // doesn't implement I, we have no way to tell if the result should
  2544     // be 'I' or 'j/l/O'.  Thus we'll pick 'j/l/O'.  If this then flows
  2545     // into a Phi which "knows" it's an Interface type we'll have to
  2546     // uplift the type.
  2547     if (!empty() && ktip != NULL && ktip->is_loaded() && ktip->klass()->is_interface())
  2548       return kills;             // Uplift to interface
  2549     if (!empty() && ktkp != NULL && ktkp->klass()->is_loaded() && ktkp->klass()->is_interface())
  2550       return kills;             // Uplift to interface
  2552     return Type::TOP;           // Canonical empty value
  2555   // If we have an interface-typed Phi or cast and we narrow to a class type,
  2556   // the join should report back the class.  However, if we have a J/L/Object
  2557   // class-typed Phi and an interface flows in, it's possible that the meet &
  2558   // join report an interface back out.  This isn't possible but happens
  2559   // because the type system doesn't interact well with interfaces.
  2560   if (ftip != NULL && ktip != NULL &&
  2561       ftip->is_loaded() &&  ftip->klass()->is_interface() &&
  2562       ktip->is_loaded() && !ktip->klass()->is_interface()) {
  2563     // Happens in a CTW of rt.jar, 320-341, no extra flags
  2564     assert(!ftip->klass_is_exact(), "interface could not be exact");
  2565     return ktip->cast_to_ptr_type(ftip->ptr());
  2567   // Interface klass type could be exact in opposite to interface type,
  2568   // return it here instead of incorrect Constant ptr J/L/Object (6894807).
  2569   if (ftkp != NULL && ktkp != NULL &&
  2570       ftkp->is_loaded() &&  ftkp->klass()->is_interface() &&
  2571       !ftkp->klass_is_exact() && // Keep exact interface klass
  2572       ktkp->is_loaded() && !ktkp->klass()->is_interface()) {
  2573     return ktkp->cast_to_ptr_type(ftkp->ptr());
  2576   return ft;
  2579 //------------------------------eq---------------------------------------------
  2580 // Structural equality check for Type representations
  2581 bool TypeOopPtr::eq( const Type *t ) const {
  2582   const TypeOopPtr *a = (const TypeOopPtr*)t;
  2583   if (_klass_is_exact != a->_klass_is_exact ||
  2584       _instance_id != a->_instance_id)  return false;
  2585   ciObject* one = const_oop();
  2586   ciObject* two = a->const_oop();
  2587   if (one == NULL || two == NULL) {
  2588     return (one == two) && TypePtr::eq(t);
  2589   } else {
  2590     return one->equals(two) && TypePtr::eq(t);
  2594 //------------------------------hash-------------------------------------------
  2595 // Type-specific hashing function.
  2596 int TypeOopPtr::hash(void) const {
  2597   return
  2598     (const_oop() ? const_oop()->hash() : 0) +
  2599     _klass_is_exact +
  2600     _instance_id +
  2601     TypePtr::hash();
  2604 //------------------------------dump2------------------------------------------
  2605 #ifndef PRODUCT
  2606 void TypeOopPtr::dump2( Dict &d, uint depth, outputStream *st ) const {
  2607   st->print("oopptr:%s", ptr_msg[_ptr]);
  2608   if( _klass_is_exact ) st->print(":exact");
  2609   if( const_oop() ) st->print(INTPTR_FORMAT, const_oop());
  2610   switch( _offset ) {
  2611   case OffsetTop: st->print("+top"); break;
  2612   case OffsetBot: st->print("+any"); break;
  2613   case         0: break;
  2614   default:        st->print("+%d",_offset); break;
  2616   if (_instance_id == InstanceTop)
  2617     st->print(",iid=top");
  2618   else if (_instance_id != InstanceBot)
  2619     st->print(",iid=%d",_instance_id);
  2621 #endif
  2623 //------------------------------singleton--------------------------------------
  2624 // TRUE if Type is a singleton type, FALSE otherwise.   Singletons are simple
  2625 // constants
  2626 bool TypeOopPtr::singleton(void) const {
  2627   // detune optimizer to not generate constant oop + constant offset as a constant!
  2628   // TopPTR, Null, AnyNull, Constant are all singletons
  2629   return (_offset == 0) && !below_centerline(_ptr);
  2632 //------------------------------add_offset-------------------------------------
  2633 const TypePtr *TypeOopPtr::add_offset( intptr_t offset ) const {
  2634   return make( _ptr, xadd_offset(offset), _instance_id);
  2637 //------------------------------meet_instance_id--------------------------------
  2638 int TypeOopPtr::meet_instance_id( int instance_id ) const {
  2639   // Either is 'TOP' instance?  Return the other instance!
  2640   if( _instance_id == InstanceTop ) return  instance_id;
  2641   if(  instance_id == InstanceTop ) return _instance_id;
  2642   // If either is different, return 'BOTTOM' instance
  2643   if( _instance_id != instance_id ) return InstanceBot;
  2644   return _instance_id;
  2647 //------------------------------dual_instance_id--------------------------------
  2648 int TypeOopPtr::dual_instance_id( ) const {
  2649   if( _instance_id == InstanceTop ) return InstanceBot; // Map TOP into BOTTOM
  2650   if( _instance_id == InstanceBot ) return InstanceTop; // Map BOTTOM into TOP
  2651   return _instance_id;              // Map everything else into self
  2655 //=============================================================================
  2656 // Convenience common pre-built types.
  2657 const TypeInstPtr *TypeInstPtr::NOTNULL;
  2658 const TypeInstPtr *TypeInstPtr::BOTTOM;
  2659 const TypeInstPtr *TypeInstPtr::MIRROR;
  2660 const TypeInstPtr *TypeInstPtr::MARK;
  2661 const TypeInstPtr *TypeInstPtr::KLASS;
  2663 //------------------------------TypeInstPtr-------------------------------------
  2664 TypeInstPtr::TypeInstPtr(PTR ptr, ciKlass* k, bool xk, ciObject* o, int off, int instance_id)
  2665  : TypeOopPtr(InstPtr, ptr, k, xk, o, off, instance_id), _name(k->name()) {
  2666    assert(k != NULL &&
  2667           (k->is_loaded() || o == NULL),
  2668           "cannot have constants with non-loaded klass");
  2669 };
  2671 //------------------------------make-------------------------------------------
  2672 const TypeInstPtr *TypeInstPtr::make(PTR ptr,
  2673                                      ciKlass* k,
  2674                                      bool xk,
  2675                                      ciObject* o,
  2676                                      int offset,
  2677                                      int instance_id) {
  2678   assert( !k->is_loaded() || k->is_instance_klass() ||
  2679           k->is_method_klass(), "Must be for instance or method");
  2680   // Either const_oop() is NULL or else ptr is Constant
  2681   assert( (!o && ptr != Constant) || (o && ptr == Constant),
  2682           "constant pointers must have a value supplied" );
  2683   // Ptr is never Null
  2684   assert( ptr != Null, "NULL pointers are not typed" );
  2686   assert(instance_id <= 0 || xk || !UseExactTypes, "instances are always exactly typed");
  2687   if (!UseExactTypes)  xk = false;
  2688   if (ptr == Constant) {
  2689     // Note:  This case includes meta-object constants, such as methods.
  2690     xk = true;
  2691   } else if (k->is_loaded()) {
  2692     ciInstanceKlass* ik = k->as_instance_klass();
  2693     if (!xk && ik->is_final())     xk = true;   // no inexact final klass
  2694     if (xk && ik->is_interface())  xk = false;  // no exact interface
  2697   // Now hash this baby
  2698   TypeInstPtr *result =
  2699     (TypeInstPtr*)(new TypeInstPtr(ptr, k, xk, o ,offset, instance_id))->hashcons();
  2701   return result;
  2705 //------------------------------cast_to_ptr_type-------------------------------
  2706 const Type *TypeInstPtr::cast_to_ptr_type(PTR ptr) const {
  2707   if( ptr == _ptr ) return this;
  2708   // Reconstruct _sig info here since not a problem with later lazy
  2709   // construction, _sig will show up on demand.
  2710   return make(ptr, klass(), klass_is_exact(), const_oop(), _offset, _instance_id);
  2714 //-----------------------------cast_to_exactness-------------------------------
  2715 const Type *TypeInstPtr::cast_to_exactness(bool klass_is_exact) const {
  2716   if( klass_is_exact == _klass_is_exact ) return this;
  2717   if (!UseExactTypes)  return this;
  2718   if (!_klass->is_loaded())  return this;
  2719   ciInstanceKlass* ik = _klass->as_instance_klass();
  2720   if( (ik->is_final() || _const_oop) )  return this;  // cannot clear xk
  2721   if( ik->is_interface() )              return this;  // cannot set xk
  2722   return make(ptr(), klass(), klass_is_exact, const_oop(), _offset, _instance_id);
  2725 //-----------------------------cast_to_instance_id----------------------------
  2726 const TypeOopPtr *TypeInstPtr::cast_to_instance_id(int instance_id) const {
  2727   if( instance_id == _instance_id ) return this;
  2728   return make(_ptr, klass(), _klass_is_exact, const_oop(), _offset, instance_id);
  2731 //------------------------------xmeet_unloaded---------------------------------
  2732 // Compute the MEET of two InstPtrs when at least one is unloaded.
  2733 // Assume classes are different since called after check for same name/class-loader
  2734 const TypeInstPtr *TypeInstPtr::xmeet_unloaded(const TypeInstPtr *tinst) const {
  2735     int off = meet_offset(tinst->offset());
  2736     PTR ptr = meet_ptr(tinst->ptr());
  2737     int instance_id = meet_instance_id(tinst->instance_id());
  2739     const TypeInstPtr *loaded    = is_loaded() ? this  : tinst;
  2740     const TypeInstPtr *unloaded  = is_loaded() ? tinst : this;
  2741     if( loaded->klass()->equals(ciEnv::current()->Object_klass()) ) {
  2742       //
  2743       // Meet unloaded class with java/lang/Object
  2744       //
  2745       // Meet
  2746       //          |                     Unloaded Class
  2747       //  Object  |   TOP    |   AnyNull | Constant |   NotNull |  BOTTOM   |
  2748       //  ===================================================================
  2749       //   TOP    | ..........................Unloaded......................|
  2750       //  AnyNull |  U-AN    |................Unloaded......................|
  2751       // Constant | ... O-NN .................................. |   O-BOT   |
  2752       //  NotNull | ... O-NN .................................. |   O-BOT   |
  2753       //  BOTTOM  | ........................Object-BOTTOM ..................|
  2754       //
  2755       assert(loaded->ptr() != TypePtr::Null, "insanity check");
  2756       //
  2757       if(      loaded->ptr() == TypePtr::TopPTR ) { return unloaded; }
  2758       else if (loaded->ptr() == TypePtr::AnyNull) { return TypeInstPtr::make( ptr, unloaded->klass(), false, NULL, off, instance_id ); }
  2759       else if (loaded->ptr() == TypePtr::BotPTR ) { return TypeInstPtr::BOTTOM; }
  2760       else if (loaded->ptr() == TypePtr::Constant || loaded->ptr() == TypePtr::NotNull) {
  2761         if (unloaded->ptr() == TypePtr::BotPTR  ) { return TypeInstPtr::BOTTOM;  }
  2762         else                                      { return TypeInstPtr::NOTNULL; }
  2764       else if( unloaded->ptr() == TypePtr::TopPTR )  { return unloaded; }
  2766       return unloaded->cast_to_ptr_type(TypePtr::AnyNull)->is_instptr();
  2769     // Both are unloaded, not the same class, not Object
  2770     // Or meet unloaded with a different loaded class, not java/lang/Object
  2771     if( ptr != TypePtr::BotPTR ) {
  2772       return TypeInstPtr::NOTNULL;
  2774     return TypeInstPtr::BOTTOM;
  2778 //------------------------------meet-------------------------------------------
  2779 // Compute the MEET of two types.  It returns a new Type object.
  2780 const Type *TypeInstPtr::xmeet( const Type *t ) const {
  2781   // Perform a fast test for common case; meeting the same types together.
  2782   if( this == t ) return this;  // Meeting same type-rep?
  2784   // Current "this->_base" is Pointer
  2785   switch (t->base()) {          // switch on original type
  2787   case Int:                     // Mixing ints & oops happens when javac
  2788   case Long:                    // reuses local variables
  2789   case FloatTop:
  2790   case FloatCon:
  2791   case FloatBot:
  2792   case DoubleTop:
  2793   case DoubleCon:
  2794   case DoubleBot:
  2795   case NarrowOop:
  2796   case Bottom:                  // Ye Olde Default
  2797     return Type::BOTTOM;
  2798   case Top:
  2799     return this;
  2801   default:                      // All else is a mistake
  2802     typerr(t);
  2804   case RawPtr: return TypePtr::BOTTOM;
  2806   case AryPtr: {                // All arrays inherit from Object class
  2807     const TypeAryPtr *tp = t->is_aryptr();
  2808     int offset = meet_offset(tp->offset());
  2809     PTR ptr = meet_ptr(tp->ptr());
  2810     int instance_id = meet_instance_id(tp->instance_id());
  2811     switch (ptr) {
  2812     case TopPTR:
  2813     case AnyNull:                // Fall 'down' to dual of object klass
  2814       if (klass()->equals(ciEnv::current()->Object_klass())) {
  2815         return TypeAryPtr::make(ptr, tp->ary(), tp->klass(), tp->klass_is_exact(), offset, instance_id);
  2816       } else {
  2817         // cannot subclass, so the meet has to fall badly below the centerline
  2818         ptr = NotNull;
  2819         instance_id = InstanceBot;
  2820         return TypeInstPtr::make( ptr, ciEnv::current()->Object_klass(), false, NULL, offset, instance_id);
  2822     case Constant:
  2823     case NotNull:
  2824     case BotPTR:                // Fall down to object klass
  2825       // LCA is object_klass, but if we subclass from the top we can do better
  2826       if( above_centerline(_ptr) ) { // if( _ptr == TopPTR || _ptr == AnyNull )
  2827         // If 'this' (InstPtr) is above the centerline and it is Object class
  2828         // then we can subclass in the Java class hierarchy.
  2829         if (klass()->equals(ciEnv::current()->Object_klass())) {
  2830           // that is, tp's array type is a subtype of my klass
  2831           return TypeAryPtr::make(ptr, (ptr == Constant ? tp->const_oop() : NULL),
  2832                                   tp->ary(), tp->klass(), tp->klass_is_exact(), offset, instance_id);
  2835       // The other case cannot happen, since I cannot be a subtype of an array.
  2836       // The meet falls down to Object class below centerline.
  2837       if( ptr == Constant )
  2838          ptr = NotNull;
  2839       instance_id = InstanceBot;
  2840       return make( ptr, ciEnv::current()->Object_klass(), false, NULL, offset, instance_id );
  2841     default: typerr(t);
  2845   case OopPtr: {                // Meeting to OopPtrs
  2846     // Found a OopPtr type vs self-InstPtr type
  2847     const TypeOopPtr *tp = t->is_oopptr();
  2848     int offset = meet_offset(tp->offset());
  2849     PTR ptr = meet_ptr(tp->ptr());
  2850     switch (tp->ptr()) {
  2851     case TopPTR:
  2852     case AnyNull: {
  2853       int instance_id = meet_instance_id(InstanceTop);
  2854       return make(ptr, klass(), klass_is_exact(),
  2855                   (ptr == Constant ? const_oop() : NULL), offset, instance_id);
  2857     case NotNull:
  2858     case BotPTR: {
  2859       int instance_id = meet_instance_id(tp->instance_id());
  2860       return TypeOopPtr::make(ptr, offset, instance_id);
  2862     default: typerr(t);
  2866   case AnyPtr: {                // Meeting to AnyPtrs
  2867     // Found an AnyPtr type vs self-InstPtr type
  2868     const TypePtr *tp = t->is_ptr();
  2869     int offset = meet_offset(tp->offset());
  2870     PTR ptr = meet_ptr(tp->ptr());
  2871     switch (tp->ptr()) {
  2872     case Null:
  2873       if( ptr == Null ) return TypePtr::make( AnyPtr, ptr, offset );
  2874       // else fall through to AnyNull
  2875     case TopPTR:
  2876     case AnyNull: {
  2877       int instance_id = meet_instance_id(InstanceTop);
  2878       return make( ptr, klass(), klass_is_exact(),
  2879                    (ptr == Constant ? const_oop() : NULL), offset, instance_id);
  2881     case NotNull:
  2882     case BotPTR:
  2883       return TypePtr::make( AnyPtr, ptr, offset );
  2884     default: typerr(t);
  2888   /*
  2889                  A-top         }
  2890                /   |   \       }  Tops
  2891            B-top A-any C-top   }
  2892               | /  |  \ |      }  Any-nulls
  2893            B-any   |   C-any   }
  2894               |    |    |
  2895            B-con A-con C-con   } constants; not comparable across classes
  2896               |    |    |
  2897            B-not   |   C-not   }
  2898               | \  |  / |      }  not-nulls
  2899            B-bot A-not C-bot   }
  2900                \   |   /       }  Bottoms
  2901                  A-bot         }
  2902   */
  2904   case InstPtr: {                // Meeting 2 Oops?
  2905     // Found an InstPtr sub-type vs self-InstPtr type
  2906     const TypeInstPtr *tinst = t->is_instptr();
  2907     int off = meet_offset( tinst->offset() );
  2908     PTR ptr = meet_ptr( tinst->ptr() );
  2909     int instance_id = meet_instance_id(tinst->instance_id());
  2911     // Check for easy case; klasses are equal (and perhaps not loaded!)
  2912     // If we have constants, then we created oops so classes are loaded
  2913     // and we can handle the constants further down.  This case handles
  2914     // both-not-loaded or both-loaded classes
  2915     if (ptr != Constant && klass()->equals(tinst->klass()) && klass_is_exact() == tinst->klass_is_exact()) {
  2916       return make( ptr, klass(), klass_is_exact(), NULL, off, instance_id );
  2919     // Classes require inspection in the Java klass hierarchy.  Must be loaded.
  2920     ciKlass* tinst_klass = tinst->klass();
  2921     ciKlass* this_klass  = this->klass();
  2922     bool tinst_xk = tinst->klass_is_exact();
  2923     bool this_xk  = this->klass_is_exact();
  2924     if (!tinst_klass->is_loaded() || !this_klass->is_loaded() ) {
  2925       // One of these classes has not been loaded
  2926       const TypeInstPtr *unloaded_meet = xmeet_unloaded(tinst);
  2927 #ifndef PRODUCT
  2928       if( PrintOpto && Verbose ) {
  2929         tty->print("meet of unloaded classes resulted in: "); unloaded_meet->dump(); tty->cr();
  2930         tty->print("  this == "); this->dump(); tty->cr();
  2931         tty->print(" tinst == "); tinst->dump(); tty->cr();
  2933 #endif
  2934       return unloaded_meet;
  2937     // Handle mixing oops and interfaces first.
  2938     if( this_klass->is_interface() && !tinst_klass->is_interface() ) {
  2939       ciKlass *tmp = tinst_klass; // Swap interface around
  2940       tinst_klass = this_klass;
  2941       this_klass = tmp;
  2942       bool tmp2 = tinst_xk;
  2943       tinst_xk = this_xk;
  2944       this_xk = tmp2;
  2946     if (tinst_klass->is_interface() &&
  2947         !(this_klass->is_interface() ||
  2948           // Treat java/lang/Object as an honorary interface,
  2949           // because we need a bottom for the interface hierarchy.
  2950           this_klass == ciEnv::current()->Object_klass())) {
  2951       // Oop meets interface!
  2953       // See if the oop subtypes (implements) interface.
  2954       ciKlass *k;
  2955       bool xk;
  2956       if( this_klass->is_subtype_of( tinst_klass ) ) {
  2957         // Oop indeed subtypes.  Now keep oop or interface depending
  2958         // on whether we are both above the centerline or either is
  2959         // below the centerline.  If we are on the centerline
  2960         // (e.g., Constant vs. AnyNull interface), use the constant.
  2961         k  = below_centerline(ptr) ? tinst_klass : this_klass;
  2962         // If we are keeping this_klass, keep its exactness too.
  2963         xk = below_centerline(ptr) ? tinst_xk    : this_xk;
  2964       } else {                  // Does not implement, fall to Object
  2965         // Oop does not implement interface, so mixing falls to Object
  2966         // just like the verifier does (if both are above the
  2967         // centerline fall to interface)
  2968         k = above_centerline(ptr) ? tinst_klass : ciEnv::current()->Object_klass();
  2969         xk = above_centerline(ptr) ? tinst_xk : false;
  2970         // Watch out for Constant vs. AnyNull interface.
  2971         if (ptr == Constant)  ptr = NotNull;   // forget it was a constant
  2972         instance_id = InstanceBot;
  2974       ciObject* o = NULL;  // the Constant value, if any
  2975       if (ptr == Constant) {
  2976         // Find out which constant.
  2977         o = (this_klass == klass()) ? const_oop() : tinst->const_oop();
  2979       return make( ptr, k, xk, o, off, instance_id );
  2982     // Either oop vs oop or interface vs interface or interface vs Object
  2984     // !!! Here's how the symmetry requirement breaks down into invariants:
  2985     // If we split one up & one down AND they subtype, take the down man.
  2986     // If we split one up & one down AND they do NOT subtype, "fall hard".
  2987     // If both are up and they subtype, take the subtype class.
  2988     // If both are up and they do NOT subtype, "fall hard".
  2989     // If both are down and they subtype, take the supertype class.
  2990     // If both are down and they do NOT subtype, "fall hard".
  2991     // Constants treated as down.
  2993     // Now, reorder the above list; observe that both-down+subtype is also
  2994     // "fall hard"; "fall hard" becomes the default case:
  2995     // If we split one up & one down AND they subtype, take the down man.
  2996     // If both are up and they subtype, take the subtype class.
  2998     // If both are down and they subtype, "fall hard".
  2999     // If both are down and they do NOT subtype, "fall hard".
  3000     // If both are up and they do NOT subtype, "fall hard".
  3001     // If we split one up & one down AND they do NOT subtype, "fall hard".
  3003     // If a proper subtype is exact, and we return it, we return it exactly.
  3004     // If a proper supertype is exact, there can be no subtyping relationship!
  3005     // If both types are equal to the subtype, exactness is and-ed below the
  3006     // centerline and or-ed above it.  (N.B. Constants are always exact.)
  3008     // Check for subtyping:
  3009     ciKlass *subtype = NULL;
  3010     bool subtype_exact = false;
  3011     if( tinst_klass->equals(this_klass) ) {
  3012       subtype = this_klass;
  3013       subtype_exact = below_centerline(ptr) ? (this_xk & tinst_xk) : (this_xk | tinst_xk);
  3014     } else if( !tinst_xk && this_klass->is_subtype_of( tinst_klass ) ) {
  3015       subtype = this_klass;     // Pick subtyping class
  3016       subtype_exact = this_xk;
  3017     } else if( !this_xk && tinst_klass->is_subtype_of( this_klass ) ) {
  3018       subtype = tinst_klass;    // Pick subtyping class
  3019       subtype_exact = tinst_xk;
  3022     if( subtype ) {
  3023       if( above_centerline(ptr) ) { // both are up?
  3024         this_klass = tinst_klass = subtype;
  3025         this_xk = tinst_xk = subtype_exact;
  3026       } else if( above_centerline(this ->_ptr) && !above_centerline(tinst->_ptr) ) {
  3027         this_klass = tinst_klass; // tinst is down; keep down man
  3028         this_xk = tinst_xk;
  3029       } else if( above_centerline(tinst->_ptr) && !above_centerline(this ->_ptr) ) {
  3030         tinst_klass = this_klass; // this is down; keep down man
  3031         tinst_xk = this_xk;
  3032       } else {
  3033         this_xk = subtype_exact;  // either they are equal, or we'll do an LCA
  3037     // Check for classes now being equal
  3038     if (tinst_klass->equals(this_klass)) {
  3039       // If the klasses are equal, the constants may still differ.  Fall to
  3040       // NotNull if they do (neither constant is NULL; that is a special case
  3041       // handled elsewhere).
  3042       ciObject* o = NULL;             // Assume not constant when done
  3043       ciObject* this_oop  = const_oop();
  3044       ciObject* tinst_oop = tinst->const_oop();
  3045       if( ptr == Constant ) {
  3046         if (this_oop != NULL && tinst_oop != NULL &&
  3047             this_oop->equals(tinst_oop) )
  3048           o = this_oop;
  3049         else if (above_centerline(this ->_ptr))
  3050           o = tinst_oop;
  3051         else if (above_centerline(tinst ->_ptr))
  3052           o = this_oop;
  3053         else
  3054           ptr = NotNull;
  3056       return make( ptr, this_klass, this_xk, o, off, instance_id );
  3057     } // Else classes are not equal
  3059     // Since klasses are different, we require a LCA in the Java
  3060     // class hierarchy - which means we have to fall to at least NotNull.
  3061     if( ptr == TopPTR || ptr == AnyNull || ptr == Constant )
  3062       ptr = NotNull;
  3063     instance_id = InstanceBot;
  3065     // Now we find the LCA of Java classes
  3066     ciKlass* k = this_klass->least_common_ancestor(tinst_klass);
  3067     return make( ptr, k, false, NULL, off, instance_id );
  3068   } // End of case InstPtr
  3070   case KlassPtr:
  3071     return TypeInstPtr::BOTTOM;
  3073   } // End of switch
  3074   return this;                  // Return the double constant
  3078 //------------------------java_mirror_type--------------------------------------
  3079 ciType* TypeInstPtr::java_mirror_type() const {
  3080   // must be a singleton type
  3081   if( const_oop() == NULL )  return NULL;
  3083   // must be of type java.lang.Class
  3084   if( klass() != ciEnv::current()->Class_klass() )  return NULL;
  3086   return const_oop()->as_instance()->java_mirror_type();
  3090 //------------------------------xdual------------------------------------------
  3091 // Dual: do NOT dual on klasses.  This means I do NOT understand the Java
  3092 // inheritance mechanism.
  3093 const Type *TypeInstPtr::xdual() const {
  3094   return new TypeInstPtr( dual_ptr(), klass(), klass_is_exact(), const_oop(), dual_offset(), dual_instance_id()  );
  3097 //------------------------------eq---------------------------------------------
  3098 // Structural equality check for Type representations
  3099 bool TypeInstPtr::eq( const Type *t ) const {
  3100   const TypeInstPtr *p = t->is_instptr();
  3101   return
  3102     klass()->equals(p->klass()) &&
  3103     TypeOopPtr::eq(p);          // Check sub-type stuff
  3106 //------------------------------hash-------------------------------------------
  3107 // Type-specific hashing function.
  3108 int TypeInstPtr::hash(void) const {
  3109   int hash = klass()->hash() + TypeOopPtr::hash();
  3110   return hash;
  3113 //------------------------------dump2------------------------------------------
  3114 // Dump oop Type
  3115 #ifndef PRODUCT
  3116 void TypeInstPtr::dump2( Dict &d, uint depth, outputStream *st ) const {
  3117   // Print the name of the klass.
  3118   klass()->print_name_on(st);
  3120   switch( _ptr ) {
  3121   case Constant:
  3122     // TO DO: Make CI print the hex address of the underlying oop.
  3123     if (WizardMode || Verbose) {
  3124       const_oop()->print_oop(st);
  3126   case BotPTR:
  3127     if (!WizardMode && !Verbose) {
  3128       if( _klass_is_exact ) st->print(":exact");
  3129       break;
  3131   case TopPTR:
  3132   case AnyNull:
  3133   case NotNull:
  3134     st->print(":%s", ptr_msg[_ptr]);
  3135     if( _klass_is_exact ) st->print(":exact");
  3136     break;
  3139   if( _offset ) {               // Dump offset, if any
  3140     if( _offset == OffsetBot )      st->print("+any");
  3141     else if( _offset == OffsetTop ) st->print("+unknown");
  3142     else st->print("+%d", _offset);
  3145   st->print(" *");
  3146   if (_instance_id == InstanceTop)
  3147     st->print(",iid=top");
  3148   else if (_instance_id != InstanceBot)
  3149     st->print(",iid=%d",_instance_id);
  3151 #endif
  3153 //------------------------------add_offset-------------------------------------
  3154 const TypePtr *TypeInstPtr::add_offset( intptr_t offset ) const {
  3155   return make( _ptr, klass(), klass_is_exact(), const_oop(), xadd_offset(offset), _instance_id );
  3158 //=============================================================================
  3159 // Convenience common pre-built types.
  3160 const TypeAryPtr *TypeAryPtr::RANGE;
  3161 const TypeAryPtr *TypeAryPtr::OOPS;
  3162 const TypeAryPtr *TypeAryPtr::NARROWOOPS;
  3163 const TypeAryPtr *TypeAryPtr::BYTES;
  3164 const TypeAryPtr *TypeAryPtr::SHORTS;
  3165 const TypeAryPtr *TypeAryPtr::CHARS;
  3166 const TypeAryPtr *TypeAryPtr::INTS;
  3167 const TypeAryPtr *TypeAryPtr::LONGS;
  3168 const TypeAryPtr *TypeAryPtr::FLOATS;
  3169 const TypeAryPtr *TypeAryPtr::DOUBLES;
  3171 //------------------------------make-------------------------------------------
  3172 const TypeAryPtr *TypeAryPtr::make( PTR ptr, const TypeAry *ary, ciKlass* k, bool xk, int offset, int instance_id ) {
  3173   assert(!(k == NULL && ary->_elem->isa_int()),
  3174          "integral arrays must be pre-equipped with a class");
  3175   if (!xk)  xk = ary->ary_must_be_exact();
  3176   assert(instance_id <= 0 || xk || !UseExactTypes, "instances are always exactly typed");
  3177   if (!UseExactTypes)  xk = (ptr == Constant);
  3178   return (TypeAryPtr*)(new TypeAryPtr(ptr, NULL, ary, k, xk, offset, instance_id))->hashcons();
  3181 //------------------------------make-------------------------------------------
  3182 const TypeAryPtr *TypeAryPtr::make( PTR ptr, ciObject* o, const TypeAry *ary, ciKlass* k, bool xk, int offset, int instance_id ) {
  3183   assert(!(k == NULL && ary->_elem->isa_int()),
  3184          "integral arrays must be pre-equipped with a class");
  3185   assert( (ptr==Constant && o) || (ptr!=Constant && !o), "" );
  3186   if (!xk)  xk = (o != NULL) || ary->ary_must_be_exact();
  3187   assert(instance_id <= 0 || xk || !UseExactTypes, "instances are always exactly typed");
  3188   if (!UseExactTypes)  xk = (ptr == Constant);
  3189   return (TypeAryPtr*)(new TypeAryPtr(ptr, o, ary, k, xk, offset, instance_id))->hashcons();
  3192 //------------------------------cast_to_ptr_type-------------------------------
  3193 const Type *TypeAryPtr::cast_to_ptr_type(PTR ptr) const {
  3194   if( ptr == _ptr ) return this;
  3195   return make(ptr, const_oop(), _ary, klass(), klass_is_exact(), _offset, _instance_id);
  3199 //-----------------------------cast_to_exactness-------------------------------
  3200 const Type *TypeAryPtr::cast_to_exactness(bool klass_is_exact) const {
  3201   if( klass_is_exact == _klass_is_exact ) return this;
  3202   if (!UseExactTypes)  return this;
  3203   if (_ary->ary_must_be_exact())  return this;  // cannot clear xk
  3204   return make(ptr(), const_oop(), _ary, klass(), klass_is_exact, _offset, _instance_id);
  3207 //-----------------------------cast_to_instance_id----------------------------
  3208 const TypeOopPtr *TypeAryPtr::cast_to_instance_id(int instance_id) const {
  3209   if( instance_id == _instance_id ) return this;
  3210   return make(_ptr, const_oop(), _ary, klass(), _klass_is_exact, _offset, instance_id);
  3213 //-----------------------------narrow_size_type-------------------------------
  3214 // Local cache for arrayOopDesc::max_array_length(etype),
  3215 // which is kind of slow (and cached elsewhere by other users).
  3216 static jint max_array_length_cache[T_CONFLICT+1];
  3217 static jint max_array_length(BasicType etype) {
  3218   jint& cache = max_array_length_cache[etype];
  3219   jint res = cache;
  3220   if (res == 0) {
  3221     switch (etype) {
  3222     case T_NARROWOOP:
  3223       etype = T_OBJECT;
  3224       break;
  3225     case T_CONFLICT:
  3226     case T_ILLEGAL:
  3227     case T_VOID:
  3228       etype = T_BYTE;           // will produce conservatively high value
  3230     cache = res = arrayOopDesc::max_array_length(etype);
  3232   return res;
  3235 // Narrow the given size type to the index range for the given array base type.
  3236 // Return NULL if the resulting int type becomes empty.
  3237 const TypeInt* TypeAryPtr::narrow_size_type(const TypeInt* size) const {
  3238   jint hi = size->_hi;
  3239   jint lo = size->_lo;
  3240   jint min_lo = 0;
  3241   jint max_hi = max_array_length(elem()->basic_type());
  3242   //if (index_not_size)  --max_hi;     // type of a valid array index, FTR
  3243   bool chg = false;
  3244   if (lo < min_lo) { lo = min_lo; chg = true; }
  3245   if (hi > max_hi) { hi = max_hi; chg = true; }
  3246   // Negative length arrays will produce weird intermediate dead fast-path code
  3247   if (lo > hi)
  3248     return TypeInt::ZERO;
  3249   if (!chg)
  3250     return size;
  3251   return TypeInt::make(lo, hi, Type::WidenMin);
  3254 //-------------------------------cast_to_size----------------------------------
  3255 const TypeAryPtr* TypeAryPtr::cast_to_size(const TypeInt* new_size) const {
  3256   assert(new_size != NULL, "");
  3257   new_size = narrow_size_type(new_size);
  3258   if (new_size == size())  return this;
  3259   const TypeAry* new_ary = TypeAry::make(elem(), new_size);
  3260   return make(ptr(), const_oop(), new_ary, klass(), klass_is_exact(), _offset, _instance_id);
  3264 //------------------------------eq---------------------------------------------
  3265 // Structural equality check for Type representations
  3266 bool TypeAryPtr::eq( const Type *t ) const {
  3267   const TypeAryPtr *p = t->is_aryptr();
  3268   return
  3269     _ary == p->_ary &&  // Check array
  3270     TypeOopPtr::eq(p);  // Check sub-parts
  3273 //------------------------------hash-------------------------------------------
  3274 // Type-specific hashing function.
  3275 int TypeAryPtr::hash(void) const {
  3276   return (intptr_t)_ary + TypeOopPtr::hash();
  3279 //------------------------------meet-------------------------------------------
  3280 // Compute the MEET of two types.  It returns a new Type object.
  3281 const Type *TypeAryPtr::xmeet( const Type *t ) const {
  3282   // Perform a fast test for common case; meeting the same types together.
  3283   if( this == t ) return this;  // Meeting same type-rep?
  3284   // Current "this->_base" is Pointer
  3285   switch (t->base()) {          // switch on original type
  3287   // Mixing ints & oops happens when javac reuses local variables
  3288   case Int:
  3289   case Long:
  3290   case FloatTop:
  3291   case FloatCon:
  3292   case FloatBot:
  3293   case DoubleTop:
  3294   case DoubleCon:
  3295   case DoubleBot:
  3296   case NarrowOop:
  3297   case Bottom:                  // Ye Olde Default
  3298     return Type::BOTTOM;
  3299   case Top:
  3300     return this;
  3302   default:                      // All else is a mistake
  3303     typerr(t);
  3305   case OopPtr: {                // Meeting to OopPtrs
  3306     // Found a OopPtr type vs self-AryPtr type
  3307     const TypeOopPtr *tp = t->is_oopptr();
  3308     int offset = meet_offset(tp->offset());
  3309     PTR ptr = meet_ptr(tp->ptr());
  3310     switch (tp->ptr()) {
  3311     case TopPTR:
  3312     case AnyNull: {
  3313       int instance_id = meet_instance_id(InstanceTop);
  3314       return make(ptr, (ptr == Constant ? const_oop() : NULL),
  3315                   _ary, _klass, _klass_is_exact, offset, instance_id);
  3317     case BotPTR:
  3318     case NotNull: {
  3319       int instance_id = meet_instance_id(tp->instance_id());
  3320       return TypeOopPtr::make(ptr, offset, instance_id);
  3322     default: ShouldNotReachHere();
  3326   case AnyPtr: {                // Meeting two AnyPtrs
  3327     // Found an AnyPtr type vs self-AryPtr type
  3328     const TypePtr *tp = t->is_ptr();
  3329     int offset = meet_offset(tp->offset());
  3330     PTR ptr = meet_ptr(tp->ptr());
  3331     switch (tp->ptr()) {
  3332     case TopPTR:
  3333       return this;
  3334     case BotPTR:
  3335     case NotNull:
  3336       return TypePtr::make(AnyPtr, ptr, offset);
  3337     case Null:
  3338       if( ptr == Null ) return TypePtr::make(AnyPtr, ptr, offset);
  3339       // else fall through to AnyNull
  3340     case AnyNull: {
  3341       int instance_id = meet_instance_id(InstanceTop);
  3342       return make( ptr, (ptr == Constant ? const_oop() : NULL),
  3343                   _ary, _klass, _klass_is_exact, offset, instance_id);
  3345     default: ShouldNotReachHere();
  3349   case RawPtr: return TypePtr::BOTTOM;
  3351   case AryPtr: {                // Meeting 2 references?
  3352     const TypeAryPtr *tap = t->is_aryptr();
  3353     int off = meet_offset(tap->offset());
  3354     const TypeAry *tary = _ary->meet(tap->_ary)->is_ary();
  3355     PTR ptr = meet_ptr(tap->ptr());
  3356     int instance_id = meet_instance_id(tap->instance_id());
  3357     ciKlass* lazy_klass = NULL;
  3358     if (tary->_elem->isa_int()) {
  3359       // Integral array element types have irrelevant lattice relations.
  3360       // It is the klass that determines array layout, not the element type.
  3361       if (_klass == NULL)
  3362         lazy_klass = tap->_klass;
  3363       else if (tap->_klass == NULL || tap->_klass == _klass) {
  3364         lazy_klass = _klass;
  3365       } else {
  3366         // Something like byte[int+] meets char[int+].
  3367         // This must fall to bottom, not (int[-128..65535])[int+].
  3368         instance_id = InstanceBot;
  3369         tary = TypeAry::make(Type::BOTTOM, tary->_size);
  3372     bool xk = false;
  3373     switch (tap->ptr()) {
  3374     case AnyNull:
  3375     case TopPTR:
  3376       // Compute new klass on demand, do not use tap->_klass
  3377       xk = (tap->_klass_is_exact | this->_klass_is_exact);
  3378       return make( ptr, const_oop(), tary, lazy_klass, xk, off, instance_id );
  3379     case Constant: {
  3380       ciObject* o = const_oop();
  3381       if( _ptr == Constant ) {
  3382         if( tap->const_oop() != NULL && !o->equals(tap->const_oop()) ) {
  3383           xk = (klass() == tap->klass());
  3384           ptr = NotNull;
  3385           o = NULL;
  3386           instance_id = InstanceBot;
  3387         } else {
  3388           xk = true;
  3390       } else if( above_centerline(_ptr) ) {
  3391         o = tap->const_oop();
  3392         xk = true;
  3393       } else {
  3394         // Only precise for identical arrays
  3395         xk = this->_klass_is_exact && (klass() == tap->klass());
  3397       return TypeAryPtr::make( ptr, o, tary, lazy_klass, xk, off, instance_id );
  3399     case NotNull:
  3400     case BotPTR:
  3401       // Compute new klass on demand, do not use tap->_klass
  3402       if (above_centerline(this->_ptr))
  3403             xk = tap->_klass_is_exact;
  3404       else if (above_centerline(tap->_ptr))
  3405             xk = this->_klass_is_exact;
  3406       else  xk = (tap->_klass_is_exact & this->_klass_is_exact) &&
  3407               (klass() == tap->klass()); // Only precise for identical arrays
  3408       return TypeAryPtr::make( ptr, NULL, tary, lazy_klass, xk, off, instance_id );
  3409     default: ShouldNotReachHere();
  3413   // All arrays inherit from Object class
  3414   case InstPtr: {
  3415     const TypeInstPtr *tp = t->is_instptr();
  3416     int offset = meet_offset(tp->offset());
  3417     PTR ptr = meet_ptr(tp->ptr());
  3418     int instance_id = meet_instance_id(tp->instance_id());
  3419     switch (ptr) {
  3420     case TopPTR:
  3421     case AnyNull:                // Fall 'down' to dual of object klass
  3422       if( tp->klass()->equals(ciEnv::current()->Object_klass()) ) {
  3423         return TypeAryPtr::make( ptr, _ary, _klass, _klass_is_exact, offset, instance_id );
  3424       } else {
  3425         // cannot subclass, so the meet has to fall badly below the centerline
  3426         ptr = NotNull;
  3427         instance_id = InstanceBot;
  3428         return TypeInstPtr::make( ptr, ciEnv::current()->Object_klass(), false, NULL,offset, instance_id);
  3430     case Constant:
  3431     case NotNull:
  3432     case BotPTR:                // Fall down to object klass
  3433       // LCA is object_klass, but if we subclass from the top we can do better
  3434       if (above_centerline(tp->ptr())) {
  3435         // If 'tp'  is above the centerline and it is Object class
  3436         // then we can subclass in the Java class hierarchy.
  3437         if( tp->klass()->equals(ciEnv::current()->Object_klass()) ) {
  3438           // that is, my array type is a subtype of 'tp' klass
  3439           return make( ptr, (ptr == Constant ? const_oop() : NULL),
  3440                        _ary, _klass, _klass_is_exact, offset, instance_id );
  3443       // The other case cannot happen, since t cannot be a subtype of an array.
  3444       // The meet falls down to Object class below centerline.
  3445       if( ptr == Constant )
  3446          ptr = NotNull;
  3447       instance_id = InstanceBot;
  3448       return TypeInstPtr::make( ptr, ciEnv::current()->Object_klass(), false, NULL,offset, instance_id);
  3449     default: typerr(t);
  3453   case KlassPtr:
  3454     return TypeInstPtr::BOTTOM;
  3457   return this;                  // Lint noise
  3460 //------------------------------xdual------------------------------------------
  3461 // Dual: compute field-by-field dual
  3462 const Type *TypeAryPtr::xdual() const {
  3463   return new TypeAryPtr( dual_ptr(), _const_oop, _ary->dual()->is_ary(),_klass, _klass_is_exact, dual_offset(), dual_instance_id() );
  3466 //----------------------interface_vs_oop---------------------------------------
  3467 #ifdef ASSERT
  3468 bool TypeAryPtr::interface_vs_oop(const Type *t) const {
  3469   const TypeAryPtr* t_aryptr = t->isa_aryptr();
  3470   if (t_aryptr) {
  3471     return _ary->interface_vs_oop(t_aryptr->_ary);
  3473   return false;
  3475 #endif
  3477 //------------------------------dump2------------------------------------------
  3478 #ifndef PRODUCT
  3479 void TypeAryPtr::dump2( Dict &d, uint depth, outputStream *st ) const {
  3480   _ary->dump2(d,depth,st);
  3481   switch( _ptr ) {
  3482   case Constant:
  3483     const_oop()->print(st);
  3484     break;
  3485   case BotPTR:
  3486     if (!WizardMode && !Verbose) {
  3487       if( _klass_is_exact ) st->print(":exact");
  3488       break;
  3490   case TopPTR:
  3491   case AnyNull:
  3492   case NotNull:
  3493     st->print(":%s", ptr_msg[_ptr]);
  3494     if( _klass_is_exact ) st->print(":exact");
  3495     break;
  3498   if( _offset != 0 ) {
  3499     int header_size = objArrayOopDesc::header_size() * wordSize;
  3500     if( _offset == OffsetTop )       st->print("+undefined");
  3501     else if( _offset == OffsetBot )  st->print("+any");
  3502     else if( _offset < header_size ) st->print("+%d", _offset);
  3503     else {
  3504       BasicType basic_elem_type = elem()->basic_type();
  3505       int array_base = arrayOopDesc::base_offset_in_bytes(basic_elem_type);
  3506       int elem_size = type2aelembytes(basic_elem_type);
  3507       st->print("[%d]", (_offset - array_base)/elem_size);
  3510   st->print(" *");
  3511   if (_instance_id == InstanceTop)
  3512     st->print(",iid=top");
  3513   else if (_instance_id != InstanceBot)
  3514     st->print(",iid=%d",_instance_id);
  3516 #endif
  3518 bool TypeAryPtr::empty(void) const {
  3519   if (_ary->empty())       return true;
  3520   return TypeOopPtr::empty();
  3523 //------------------------------add_offset-------------------------------------
  3524 const TypePtr *TypeAryPtr::add_offset( intptr_t offset ) const {
  3525   return make( _ptr, _const_oop, _ary, _klass, _klass_is_exact, xadd_offset(offset), _instance_id );
  3529 //=============================================================================
  3530 const TypeNarrowOop *TypeNarrowOop::BOTTOM;
  3531 const TypeNarrowOop *TypeNarrowOop::NULL_PTR;
  3534 const TypeNarrowOop* TypeNarrowOop::make(const TypePtr* type) {
  3535   return (const TypeNarrowOop*)(new TypeNarrowOop(type))->hashcons();
  3538 //------------------------------hash-------------------------------------------
  3539 // Type-specific hashing function.
  3540 int TypeNarrowOop::hash(void) const {
  3541   return _ptrtype->hash() + 7;
  3545 bool TypeNarrowOop::eq( const Type *t ) const {
  3546   const TypeNarrowOop* tc = t->isa_narrowoop();
  3547   if (tc != NULL) {
  3548     if (_ptrtype->base() != tc->_ptrtype->base()) {
  3549       return false;
  3551     return tc->_ptrtype->eq(_ptrtype);
  3553   return false;
  3556 bool TypeNarrowOop::singleton(void) const {    // TRUE if type is a singleton
  3557   return _ptrtype->singleton();
  3560 bool TypeNarrowOop::empty(void) const {
  3561   return _ptrtype->empty();
  3564 //------------------------------xmeet------------------------------------------
  3565 // Compute the MEET of two types.  It returns a new Type object.
  3566 const Type *TypeNarrowOop::xmeet( const Type *t ) const {
  3567   // Perform a fast test for common case; meeting the same types together.
  3568   if( this == t ) return this;  // Meeting same type-rep?
  3571   // Current "this->_base" is OopPtr
  3572   switch (t->base()) {          // switch on original type
  3574   case Int:                     // Mixing ints & oops happens when javac
  3575   case Long:                    // reuses local variables
  3576   case FloatTop:
  3577   case FloatCon:
  3578   case FloatBot:
  3579   case DoubleTop:
  3580   case DoubleCon:
  3581   case DoubleBot:
  3582   case AnyPtr:
  3583   case RawPtr:
  3584   case OopPtr:
  3585   case InstPtr:
  3586   case KlassPtr:
  3587   case AryPtr:
  3589   case Bottom:                  // Ye Olde Default
  3590     return Type::BOTTOM;
  3591   case Top:
  3592     return this;
  3594   case NarrowOop: {
  3595     const Type* result = _ptrtype->xmeet(t->make_ptr());
  3596     if (result->isa_ptr()) {
  3597       return TypeNarrowOop::make(result->is_ptr());
  3599     return result;
  3602   default:                      // All else is a mistake
  3603     typerr(t);
  3605   } // End of switch
  3607   return this;
  3610 const Type *TypeNarrowOop::xdual() const {    // Compute dual right now.
  3611   const TypePtr* odual = _ptrtype->dual()->is_ptr();
  3612   return new TypeNarrowOop(odual);
  3615 const Type *TypeNarrowOop::filter( const Type *kills ) const {
  3616   if (kills->isa_narrowoop()) {
  3617     const Type* ft =_ptrtype->filter(kills->is_narrowoop()->_ptrtype);
  3618     if (ft->empty())
  3619       return Type::TOP;           // Canonical empty value
  3620     if (ft->isa_ptr()) {
  3621       return make(ft->isa_ptr());
  3623     return ft;
  3624   } else if (kills->isa_ptr()) {
  3625     const Type* ft = _ptrtype->join(kills);
  3626     if (ft->empty())
  3627       return Type::TOP;           // Canonical empty value
  3628     return ft;
  3629   } else {
  3630     return Type::TOP;
  3635 intptr_t TypeNarrowOop::get_con() const {
  3636   return _ptrtype->get_con();
  3639 #ifndef PRODUCT
  3640 void TypeNarrowOop::dump2( Dict & d, uint depth, outputStream *st ) const {
  3641   st->print("narrowoop: ");
  3642   _ptrtype->dump2(d, depth, st);
  3644 #endif
  3647 //=============================================================================
  3648 // Convenience common pre-built types.
  3650 // Not-null object klass or below
  3651 const TypeKlassPtr *TypeKlassPtr::OBJECT;
  3652 const TypeKlassPtr *TypeKlassPtr::OBJECT_OR_NULL;
  3654 //------------------------------TypeKlasPtr------------------------------------
  3655 TypeKlassPtr::TypeKlassPtr( PTR ptr, ciKlass* klass, int offset )
  3656   : TypeOopPtr(KlassPtr, ptr, klass, (ptr==Constant), (ptr==Constant ? klass : NULL), offset, 0) {
  3659 //------------------------------make-------------------------------------------
  3660 // ptr to klass 'k', if Constant, or possibly to a sub-klass if not a Constant
  3661 const TypeKlassPtr *TypeKlassPtr::make( PTR ptr, ciKlass* k, int offset ) {
  3662   assert( k != NULL, "Expect a non-NULL klass");
  3663   assert(k->is_instance_klass() || k->is_array_klass() ||
  3664          k->is_method_klass(), "Incorrect type of klass oop");
  3665   TypeKlassPtr *r =
  3666     (TypeKlassPtr*)(new TypeKlassPtr(ptr, k, offset))->hashcons();
  3668   return r;
  3671 //------------------------------eq---------------------------------------------
  3672 // Structural equality check for Type representations
  3673 bool TypeKlassPtr::eq( const Type *t ) const {
  3674   const TypeKlassPtr *p = t->is_klassptr();
  3675   return
  3676     klass()->equals(p->klass()) &&
  3677     TypeOopPtr::eq(p);
  3680 //------------------------------hash-------------------------------------------
  3681 // Type-specific hashing function.
  3682 int TypeKlassPtr::hash(void) const {
  3683   return klass()->hash() + TypeOopPtr::hash();
  3687 //----------------------compute_klass------------------------------------------
  3688 // Compute the defining klass for this class
  3689 ciKlass* TypeAryPtr::compute_klass(DEBUG_ONLY(bool verify)) const {
  3690   // Compute _klass based on element type.
  3691   ciKlass* k_ary = NULL;
  3692   const TypeInstPtr *tinst;
  3693   const TypeAryPtr *tary;
  3694   const Type* el = elem();
  3695   if (el->isa_narrowoop()) {
  3696     el = el->make_ptr();
  3699   // Get element klass
  3700   if ((tinst = el->isa_instptr()) != NULL) {
  3701     // Compute array klass from element klass
  3702     k_ary = ciObjArrayKlass::make(tinst->klass());
  3703   } else if ((tary = el->isa_aryptr()) != NULL) {
  3704     // Compute array klass from element klass
  3705     ciKlass* k_elem = tary->klass();
  3706     // If element type is something like bottom[], k_elem will be null.
  3707     if (k_elem != NULL)
  3708       k_ary = ciObjArrayKlass::make(k_elem);
  3709   } else if ((el->base() == Type::Top) ||
  3710              (el->base() == Type::Bottom)) {
  3711     // element type of Bottom occurs from meet of basic type
  3712     // and object; Top occurs when doing join on Bottom.
  3713     // Leave k_ary at NULL.
  3714   } else {
  3715     // Cannot compute array klass directly from basic type,
  3716     // since subtypes of TypeInt all have basic type T_INT.
  3717 #ifdef ASSERT
  3718     if (verify && el->isa_int()) {
  3719       // Check simple cases when verifying klass.
  3720       BasicType bt = T_ILLEGAL;
  3721       if (el == TypeInt::BYTE) {
  3722         bt = T_BYTE;
  3723       } else if (el == TypeInt::SHORT) {
  3724         bt = T_SHORT;
  3725       } else if (el == TypeInt::CHAR) {
  3726         bt = T_CHAR;
  3727       } else if (el == TypeInt::INT) {
  3728         bt = T_INT;
  3729       } else {
  3730         return _klass; // just return specified klass
  3732       return ciTypeArrayKlass::make(bt);
  3734 #endif
  3735     assert(!el->isa_int(),
  3736            "integral arrays must be pre-equipped with a class");
  3737     // Compute array klass directly from basic type
  3738     k_ary = ciTypeArrayKlass::make(el->basic_type());
  3740   return k_ary;
  3743 //------------------------------klass------------------------------------------
  3744 // Return the defining klass for this class
  3745 ciKlass* TypeAryPtr::klass() const {
  3746   if( _klass ) return _klass;   // Return cached value, if possible
  3748   // Oops, need to compute _klass and cache it
  3749   ciKlass* k_ary = compute_klass();
  3751   if( this != TypeAryPtr::OOPS ) {
  3752     // The _klass field acts as a cache of the underlying
  3753     // ciKlass for this array type.  In order to set the field,
  3754     // we need to cast away const-ness.
  3755     //
  3756     // IMPORTANT NOTE: we *never* set the _klass field for the
  3757     // type TypeAryPtr::OOPS.  This Type is shared between all
  3758     // active compilations.  However, the ciKlass which represents
  3759     // this Type is *not* shared between compilations, so caching
  3760     // this value would result in fetching a dangling pointer.
  3761     //
  3762     // Recomputing the underlying ciKlass for each request is
  3763     // a bit less efficient than caching, but calls to
  3764     // TypeAryPtr::OOPS->klass() are not common enough to matter.
  3765     ((TypeAryPtr*)this)->_klass = k_ary;
  3766     if (UseCompressedOops && k_ary != NULL && k_ary->is_obj_array_klass() &&
  3767         _offset != 0 && _offset != arrayOopDesc::length_offset_in_bytes()) {
  3768       ((TypeAryPtr*)this)->_is_ptr_to_narrowoop = true;
  3771   return k_ary;
  3775 //------------------------------add_offset-------------------------------------
  3776 // Access internals of klass object
  3777 const TypePtr *TypeKlassPtr::add_offset( intptr_t offset ) const {
  3778   return make( _ptr, klass(), xadd_offset(offset) );
  3781 //------------------------------cast_to_ptr_type-------------------------------
  3782 const Type *TypeKlassPtr::cast_to_ptr_type(PTR ptr) const {
  3783   assert(_base == KlassPtr, "subclass must override cast_to_ptr_type");
  3784   if( ptr == _ptr ) return this;
  3785   return make(ptr, _klass, _offset);
  3789 //-----------------------------cast_to_exactness-------------------------------
  3790 const Type *TypeKlassPtr::cast_to_exactness(bool klass_is_exact) const {
  3791   if( klass_is_exact == _klass_is_exact ) return this;
  3792   if (!UseExactTypes)  return this;
  3793   return make(klass_is_exact ? Constant : NotNull, _klass, _offset);
  3797 //-----------------------------as_instance_type--------------------------------
  3798 // Corresponding type for an instance of the given class.
  3799 // It will be NotNull, and exact if and only if the klass type is exact.
  3800 const TypeOopPtr* TypeKlassPtr::as_instance_type() const {
  3801   ciKlass* k = klass();
  3802   bool    xk = klass_is_exact();
  3803   //return TypeInstPtr::make(TypePtr::NotNull, k, xk, NULL, 0);
  3804   const TypeOopPtr* toop = TypeOopPtr::make_from_klass_raw(k);
  3805   toop = toop->cast_to_ptr_type(TypePtr::NotNull)->is_oopptr();
  3806   return toop->cast_to_exactness(xk)->is_oopptr();
  3810 //------------------------------xmeet------------------------------------------
  3811 // Compute the MEET of two types, return a new Type object.
  3812 const Type    *TypeKlassPtr::xmeet( const Type *t ) const {
  3813   // Perform a fast test for common case; meeting the same types together.
  3814   if( this == t ) return this;  // Meeting same type-rep?
  3816   // Current "this->_base" is Pointer
  3817   switch (t->base()) {          // switch on original type
  3819   case Int:                     // Mixing ints & oops happens when javac
  3820   case Long:                    // reuses local variables
  3821   case FloatTop:
  3822   case FloatCon:
  3823   case FloatBot:
  3824   case DoubleTop:
  3825   case DoubleCon:
  3826   case DoubleBot:
  3827   case NarrowOop:
  3828   case Bottom:                  // Ye Olde Default
  3829     return Type::BOTTOM;
  3830   case Top:
  3831     return this;
  3833   default:                      // All else is a mistake
  3834     typerr(t);
  3836   case RawPtr: return TypePtr::BOTTOM;
  3838   case OopPtr: {                // Meeting to OopPtrs
  3839     // Found a OopPtr type vs self-KlassPtr type
  3840     const TypePtr *tp = t->is_oopptr();
  3841     int offset = meet_offset(tp->offset());
  3842     PTR ptr = meet_ptr(tp->ptr());
  3843     switch (tp->ptr()) {
  3844     case TopPTR:
  3845     case AnyNull:
  3846       return make(ptr, klass(), offset);
  3847     case BotPTR:
  3848     case NotNull:
  3849       return TypePtr::make(AnyPtr, ptr, offset);
  3850     default: typerr(t);
  3854   case AnyPtr: {                // Meeting to AnyPtrs
  3855     // Found an AnyPtr type vs self-KlassPtr type
  3856     const TypePtr *tp = t->is_ptr();
  3857     int offset = meet_offset(tp->offset());
  3858     PTR ptr = meet_ptr(tp->ptr());
  3859     switch (tp->ptr()) {
  3860     case TopPTR:
  3861       return this;
  3862     case Null:
  3863       if( ptr == Null ) return TypePtr::make( AnyPtr, ptr, offset );
  3864     case AnyNull:
  3865       return make( ptr, klass(), offset );
  3866     case BotPTR:
  3867     case NotNull:
  3868       return TypePtr::make(AnyPtr, ptr, offset);
  3869     default: typerr(t);
  3873   case AryPtr:                  // Meet with AryPtr
  3874   case InstPtr:                 // Meet with InstPtr
  3875     return TypeInstPtr::BOTTOM;
  3877   //
  3878   //             A-top         }
  3879   //           /   |   \       }  Tops
  3880   //       B-top A-any C-top   }
  3881   //          | /  |  \ |      }  Any-nulls
  3882   //       B-any   |   C-any   }
  3883   //          |    |    |
  3884   //       B-con A-con C-con   } constants; not comparable across classes
  3885   //          |    |    |
  3886   //       B-not   |   C-not   }
  3887   //          | \  |  / |      }  not-nulls
  3888   //       B-bot A-not C-bot   }
  3889   //           \   |   /       }  Bottoms
  3890   //             A-bot         }
  3891   //
  3893   case KlassPtr: {  // Meet two KlassPtr types
  3894     const TypeKlassPtr *tkls = t->is_klassptr();
  3895     int  off     = meet_offset(tkls->offset());
  3896     PTR  ptr     = meet_ptr(tkls->ptr());
  3898     // Check for easy case; klasses are equal (and perhaps not loaded!)
  3899     // If we have constants, then we created oops so classes are loaded
  3900     // and we can handle the constants further down.  This case handles
  3901     // not-loaded classes
  3902     if( ptr != Constant && tkls->klass()->equals(klass()) ) {
  3903       return make( ptr, klass(), off );
  3906     // Classes require inspection in the Java klass hierarchy.  Must be loaded.
  3907     ciKlass* tkls_klass = tkls->klass();
  3908     ciKlass* this_klass = this->klass();
  3909     assert( tkls_klass->is_loaded(), "This class should have been loaded.");
  3910     assert( this_klass->is_loaded(), "This class should have been loaded.");
  3912     // If 'this' type is above the centerline and is a superclass of the
  3913     // other, we can treat 'this' as having the same type as the other.
  3914     if ((above_centerline(this->ptr())) &&
  3915         tkls_klass->is_subtype_of(this_klass)) {
  3916       this_klass = tkls_klass;
  3918     // If 'tinst' type is above the centerline and is a superclass of the
  3919     // other, we can treat 'tinst' as having the same type as the other.
  3920     if ((above_centerline(tkls->ptr())) &&
  3921         this_klass->is_subtype_of(tkls_klass)) {
  3922       tkls_klass = this_klass;
  3925     // Check for classes now being equal
  3926     if (tkls_klass->equals(this_klass)) {
  3927       // If the klasses are equal, the constants may still differ.  Fall to
  3928       // NotNull if they do (neither constant is NULL; that is a special case
  3929       // handled elsewhere).
  3930       ciObject* o = NULL;             // Assume not constant when done
  3931       ciObject* this_oop = const_oop();
  3932       ciObject* tkls_oop = tkls->const_oop();
  3933       if( ptr == Constant ) {
  3934         if (this_oop != NULL && tkls_oop != NULL &&
  3935             this_oop->equals(tkls_oop) )
  3936           o = this_oop;
  3937         else if (above_centerline(this->ptr()))
  3938           o = tkls_oop;
  3939         else if (above_centerline(tkls->ptr()))
  3940           o = this_oop;
  3941         else
  3942           ptr = NotNull;
  3944       return make( ptr, this_klass, off );
  3945     } // Else classes are not equal
  3947     // Since klasses are different, we require the LCA in the Java
  3948     // class hierarchy - which means we have to fall to at least NotNull.
  3949     if( ptr == TopPTR || ptr == AnyNull || ptr == Constant )
  3950       ptr = NotNull;
  3951     // Now we find the LCA of Java classes
  3952     ciKlass* k = this_klass->least_common_ancestor(tkls_klass);
  3953     return   make( ptr, k, off );
  3954   } // End of case KlassPtr
  3956   } // End of switch
  3957   return this;                  // Return the double constant
  3960 //------------------------------xdual------------------------------------------
  3961 // Dual: compute field-by-field dual
  3962 const Type    *TypeKlassPtr::xdual() const {
  3963   return new TypeKlassPtr( dual_ptr(), klass(), dual_offset() );
  3966 //------------------------------dump2------------------------------------------
  3967 // Dump Klass Type
  3968 #ifndef PRODUCT
  3969 void TypeKlassPtr::dump2( Dict & d, uint depth, outputStream *st ) const {
  3970   switch( _ptr ) {
  3971   case Constant:
  3972     st->print("precise ");
  3973   case NotNull:
  3975       const char *name = klass()->name()->as_utf8();
  3976       if( name ) {
  3977         st->print("klass %s: " INTPTR_FORMAT, name, klass());
  3978       } else {
  3979         ShouldNotReachHere();
  3982   case BotPTR:
  3983     if( !WizardMode && !Verbose && !_klass_is_exact ) break;
  3984   case TopPTR:
  3985   case AnyNull:
  3986     st->print(":%s", ptr_msg[_ptr]);
  3987     if( _klass_is_exact ) st->print(":exact");
  3988     break;
  3991   if( _offset ) {               // Dump offset, if any
  3992     if( _offset == OffsetBot )      { st->print("+any"); }
  3993     else if( _offset == OffsetTop ) { st->print("+unknown"); }
  3994     else                            { st->print("+%d", _offset); }
  3997   st->print(" *");
  3999 #endif
  4003 //=============================================================================
  4004 // Convenience common pre-built types.
  4006 //------------------------------make-------------------------------------------
  4007 const TypeFunc *TypeFunc::make( const TypeTuple *domain, const TypeTuple *range ) {
  4008   return (TypeFunc*)(new TypeFunc(domain,range))->hashcons();
  4011 //------------------------------make-------------------------------------------
  4012 const TypeFunc *TypeFunc::make(ciMethod* method) {
  4013   Compile* C = Compile::current();
  4014   const TypeFunc* tf = C->last_tf(method); // check cache
  4015   if (tf != NULL)  return tf;  // The hit rate here is almost 50%.
  4016   const TypeTuple *domain;
  4017   if (method->is_static()) {
  4018     domain = TypeTuple::make_domain(NULL, method->signature());
  4019   } else {
  4020     domain = TypeTuple::make_domain(method->holder(), method->signature());
  4022   const TypeTuple *range  = TypeTuple::make_range(method->signature());
  4023   tf = TypeFunc::make(domain, range);
  4024   C->set_last_tf(method, tf);  // fill cache
  4025   return tf;
  4028 //------------------------------meet-------------------------------------------
  4029 // Compute the MEET of two types.  It returns a new Type object.
  4030 const Type *TypeFunc::xmeet( const Type *t ) const {
  4031   // Perform a fast test for common case; meeting the same types together.
  4032   if( this == t ) return this;  // Meeting same type-rep?
  4034   // Current "this->_base" is Func
  4035   switch (t->base()) {          // switch on original type
  4037   case Bottom:                  // Ye Olde Default
  4038     return t;
  4040   default:                      // All else is a mistake
  4041     typerr(t);
  4043   case Top:
  4044     break;
  4046   return this;                  // Return the double constant
  4049 //------------------------------xdual------------------------------------------
  4050 // Dual: compute field-by-field dual
  4051 const Type *TypeFunc::xdual() const {
  4052   return this;
  4055 //------------------------------eq---------------------------------------------
  4056 // Structural equality check for Type representations
  4057 bool TypeFunc::eq( const Type *t ) const {
  4058   const TypeFunc *a = (const TypeFunc*)t;
  4059   return _domain == a->_domain &&
  4060     _range == a->_range;
  4063 //------------------------------hash-------------------------------------------
  4064 // Type-specific hashing function.
  4065 int TypeFunc::hash(void) const {
  4066   return (intptr_t)_domain + (intptr_t)_range;
  4069 //------------------------------dump2------------------------------------------
  4070 // Dump Function Type
  4071 #ifndef PRODUCT
  4072 void TypeFunc::dump2( Dict &d, uint depth, outputStream *st ) const {
  4073   if( _range->_cnt <= Parms )
  4074     st->print("void");
  4075   else {
  4076     uint i;
  4077     for (i = Parms; i < _range->_cnt-1; i++) {
  4078       _range->field_at(i)->dump2(d,depth,st);
  4079       st->print("/");
  4081     _range->field_at(i)->dump2(d,depth,st);
  4083   st->print(" ");
  4084   st->print("( ");
  4085   if( !depth || d[this] ) {     // Check for recursive dump
  4086     st->print("...)");
  4087     return;
  4089   d.Insert((void*)this,(void*)this);    // Stop recursion
  4090   if (Parms < _domain->_cnt)
  4091     _domain->field_at(Parms)->dump2(d,depth-1,st);
  4092   for (uint i = Parms+1; i < _domain->_cnt; i++) {
  4093     st->print(", ");
  4094     _domain->field_at(i)->dump2(d,depth-1,st);
  4096   st->print(" )");
  4099 //------------------------------print_flattened--------------------------------
  4100 // Print a 'flattened' signature
  4101 static const char * const flat_type_msg[Type::lastype] = {
  4102   "bad","control","top","int","long","_", "narrowoop",
  4103   "tuple:", "array:",
  4104   "ptr", "rawptr", "ptr", "ptr", "ptr", "ptr",
  4105   "func", "abIO", "return_address", "mem",
  4106   "float_top", "ftcon:", "flt",
  4107   "double_top", "dblcon:", "dbl",
  4108   "bottom"
  4109 };
  4111 void TypeFunc::print_flattened() const {
  4112   if( _range->_cnt <= Parms )
  4113     tty->print("void");
  4114   else {
  4115     uint i;
  4116     for (i = Parms; i < _range->_cnt-1; i++)
  4117       tty->print("%s/",flat_type_msg[_range->field_at(i)->base()]);
  4118     tty->print("%s",flat_type_msg[_range->field_at(i)->base()]);
  4120   tty->print(" ( ");
  4121   if (Parms < _domain->_cnt)
  4122     tty->print("%s",flat_type_msg[_domain->field_at(Parms)->base()]);
  4123   for (uint i = Parms+1; i < _domain->_cnt; i++)
  4124     tty->print(", %s",flat_type_msg[_domain->field_at(i)->base()]);
  4125   tty->print(" )");
  4127 #endif
  4129 //------------------------------singleton--------------------------------------
  4130 // TRUE if Type is a singleton type, FALSE otherwise.   Singletons are simple
  4131 // constants (Ldi nodes).  Singletons are integer, float or double constants
  4132 // or a single symbol.
  4133 bool TypeFunc::singleton(void) const {
  4134   return false;                 // Never a singleton
  4137 bool TypeFunc::empty(void) const {
  4138   return false;                 // Never empty
  4142 BasicType TypeFunc::return_type() const{
  4143   if (range()->cnt() == TypeFunc::Parms) {
  4144     return T_VOID;
  4146   return range()->field_at(TypeFunc::Parms)->basic_type();

mercurial