src/share/vm/opto/type.cpp

Mon, 09 Mar 2009 03:17:11 -0700

author
twisti
date
Mon, 09 Mar 2009 03:17:11 -0700
changeset 1059
337400e7a5dd
parent 1040
98cb887364d3
child 1063
7bb995fbd3c0
permissions
-rw-r--r--

6797305: Add LoadUB and LoadUI opcode class
Summary: Add a LoadUB (unsigned byte) and LoadUI (unsigned int) opcode class so we have these load optimizations in the first place and do not need to handle them in the matcher.
Reviewed-by: never, kvn

     1 /*
     2  * Copyright 1997-2009 Sun Microsystems, Inc.  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 Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
    20  * CA 95054 USA or visit www.sun.com if you need additional information or
    21  * have any 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 //--------------------------Initialize_shared----------------------------------
   186 void Type::Initialize_shared(Compile* current) {
   187   // This method does not need to be locked because the first system
   188   // compilations (stub compilations) occur serially.  If they are
   189   // changed to proceed in parallel, then this section will need
   190   // locking.
   192   Arena* save = current->type_arena();
   193   Arena* shared_type_arena = new Arena();
   195   current->set_type_arena(shared_type_arena);
   196   _shared_type_dict =
   197     new (shared_type_arena) Dict( (CmpKey)Type::cmp, (Hash)Type::uhash,
   198                                   shared_type_arena, 128 );
   199   current->set_type_dict(_shared_type_dict);
   201   // Make shared pre-built types.
   202   CONTROL = make(Control);      // Control only
   203   TOP     = make(Top);          // No values in set
   204   MEMORY  = make(Memory);       // Abstract store only
   205   ABIO    = make(Abio);         // State-of-machine only
   206   RETURN_ADDRESS=make(Return_Address);
   207   FLOAT   = make(FloatBot);     // All floats
   208   DOUBLE  = make(DoubleBot);    // All doubles
   209   BOTTOM  = make(Bottom);       // Everything
   210   HALF    = make(Half);         // Placeholder half of doublewide type
   212   TypeF::ZERO = TypeF::make(0.0); // Float 0 (positive zero)
   213   TypeF::ONE  = TypeF::make(1.0); // Float 1
   215   TypeD::ZERO = TypeD::make(0.0); // Double 0 (positive zero)
   216   TypeD::ONE  = TypeD::make(1.0); // Double 1
   218   TypeInt::MINUS_1 = TypeInt::make(-1);  // -1
   219   TypeInt::ZERO    = TypeInt::make( 0);  //  0
   220   TypeInt::ONE     = TypeInt::make( 1);  //  1
   221   TypeInt::BOOL    = TypeInt::make(0,1,   WidenMin);  // 0 or 1, FALSE or TRUE.
   222   TypeInt::CC      = TypeInt::make(-1, 1, WidenMin);  // -1, 0 or 1, condition codes
   223   TypeInt::CC_LT   = TypeInt::make(-1,-1, WidenMin);  // == TypeInt::MINUS_1
   224   TypeInt::CC_GT   = TypeInt::make( 1, 1, WidenMin);  // == TypeInt::ONE
   225   TypeInt::CC_EQ   = TypeInt::make( 0, 0, WidenMin);  // == TypeInt::ZERO
   226   TypeInt::CC_LE   = TypeInt::make(-1, 0, WidenMin);
   227   TypeInt::CC_GE   = TypeInt::make( 0, 1, WidenMin);  // == TypeInt::BOOL
   228   TypeInt::BYTE    = TypeInt::make(-128,127,     WidenMin); // Bytes
   229   TypeInt::UBYTE   = TypeInt::make(0, 255,       WidenMin); // Unsigned Bytes
   230   TypeInt::CHAR    = TypeInt::make(0,65535,      WidenMin); // Java chars
   231   TypeInt::SHORT   = TypeInt::make(-32768,32767, WidenMin); // Java shorts
   232   TypeInt::POS     = TypeInt::make(0,max_jint,   WidenMin); // Non-neg values
   233   TypeInt::POS1    = TypeInt::make(1,max_jint,   WidenMin); // Positive values
   234   TypeInt::INT     = TypeInt::make(min_jint,max_jint, WidenMax); // 32-bit integers
   235   TypeInt::SYMINT  = TypeInt::make(-max_jint,max_jint,WidenMin); // symmetric range
   236   // CmpL is overloaded both as the bytecode computation returning
   237   // a trinary (-1,0,+1) integer result AND as an efficient long
   238   // compare returning optimizer ideal-type flags.
   239   assert( TypeInt::CC_LT == TypeInt::MINUS_1, "types must match for CmpL to work" );
   240   assert( TypeInt::CC_GT == TypeInt::ONE,     "types must match for CmpL to work" );
   241   assert( TypeInt::CC_EQ == TypeInt::ZERO,    "types must match for CmpL to work" );
   242   assert( TypeInt::CC_GE == TypeInt::BOOL,    "types must match for CmpL to work" );
   244   TypeLong::MINUS_1 = TypeLong::make(-1);        // -1
   245   TypeLong::ZERO    = TypeLong::make( 0);        //  0
   246   TypeLong::ONE     = TypeLong::make( 1);        //  1
   247   TypeLong::POS     = TypeLong::make(0,max_jlong, WidenMin); // Non-neg values
   248   TypeLong::LONG    = TypeLong::make(min_jlong,max_jlong,WidenMax); // 64-bit integers
   249   TypeLong::INT     = TypeLong::make((jlong)min_jint,(jlong)max_jint,WidenMin);
   250   TypeLong::UINT    = TypeLong::make(0,(jlong)max_juint,WidenMin);
   252   const Type **fboth =(const Type**)shared_type_arena->Amalloc_4(2*sizeof(Type*));
   253   fboth[0] = Type::CONTROL;
   254   fboth[1] = Type::CONTROL;
   255   TypeTuple::IFBOTH = TypeTuple::make( 2, fboth );
   257   const Type **ffalse =(const Type**)shared_type_arena->Amalloc_4(2*sizeof(Type*));
   258   ffalse[0] = Type::CONTROL;
   259   ffalse[1] = Type::TOP;
   260   TypeTuple::IFFALSE = TypeTuple::make( 2, ffalse );
   262   const Type **fneither =(const Type**)shared_type_arena->Amalloc_4(2*sizeof(Type*));
   263   fneither[0] = Type::TOP;
   264   fneither[1] = Type::TOP;
   265   TypeTuple::IFNEITHER = TypeTuple::make( 2, fneither );
   267   const Type **ftrue =(const Type**)shared_type_arena->Amalloc_4(2*sizeof(Type*));
   268   ftrue[0] = Type::TOP;
   269   ftrue[1] = Type::CONTROL;
   270   TypeTuple::IFTRUE = TypeTuple::make( 2, ftrue );
   272   const Type **floop =(const Type**)shared_type_arena->Amalloc_4(2*sizeof(Type*));
   273   floop[0] = Type::CONTROL;
   274   floop[1] = TypeInt::INT;
   275   TypeTuple::LOOPBODY = TypeTuple::make( 2, floop );
   277   TypePtr::NULL_PTR= TypePtr::make( AnyPtr, TypePtr::Null, 0 );
   278   TypePtr::NOTNULL = TypePtr::make( AnyPtr, TypePtr::NotNull, OffsetBot );
   279   TypePtr::BOTTOM  = TypePtr::make( AnyPtr, TypePtr::BotPTR, OffsetBot );
   281   TypeRawPtr::BOTTOM = TypeRawPtr::make( TypePtr::BotPTR );
   282   TypeRawPtr::NOTNULL= TypeRawPtr::make( TypePtr::NotNull );
   284   const Type **fmembar = TypeTuple::fields(0);
   285   TypeTuple::MEMBAR = TypeTuple::make(TypeFunc::Parms+0, fmembar);
   287   const Type **fsc = (const Type**)shared_type_arena->Amalloc_4(2*sizeof(Type*));
   288   fsc[0] = TypeInt::CC;
   289   fsc[1] = Type::MEMORY;
   290   TypeTuple::STORECONDITIONAL = TypeTuple::make(2, fsc);
   292   TypeInstPtr::NOTNULL = TypeInstPtr::make(TypePtr::NotNull, current->env()->Object_klass());
   293   TypeInstPtr::BOTTOM  = TypeInstPtr::make(TypePtr::BotPTR,  current->env()->Object_klass());
   294   TypeInstPtr::MIRROR  = TypeInstPtr::make(TypePtr::NotNull, current->env()->Class_klass());
   295   TypeInstPtr::MARK    = TypeInstPtr::make(TypePtr::BotPTR,  current->env()->Object_klass(),
   296                                            false, 0, oopDesc::mark_offset_in_bytes());
   297   TypeInstPtr::KLASS   = TypeInstPtr::make(TypePtr::BotPTR,  current->env()->Object_klass(),
   298                                            false, 0, oopDesc::klass_offset_in_bytes());
   299   TypeOopPtr::BOTTOM  = TypeOopPtr::make(TypePtr::BotPTR, OffsetBot);
   301   TypeNarrowOop::NULL_PTR = TypeNarrowOop::make( TypePtr::NULL_PTR );
   302   TypeNarrowOop::BOTTOM   = TypeNarrowOop::make( TypeInstPtr::BOTTOM );
   304   mreg2type[Op_Node] = Type::BOTTOM;
   305   mreg2type[Op_Set ] = 0;
   306   mreg2type[Op_RegN] = TypeNarrowOop::BOTTOM;
   307   mreg2type[Op_RegI] = TypeInt::INT;
   308   mreg2type[Op_RegP] = TypePtr::BOTTOM;
   309   mreg2type[Op_RegF] = Type::FLOAT;
   310   mreg2type[Op_RegD] = Type::DOUBLE;
   311   mreg2type[Op_RegL] = TypeLong::LONG;
   312   mreg2type[Op_RegFlags] = TypeInt::CC;
   314   TypeAryPtr::RANGE   = TypeAryPtr::make( TypePtr::BotPTR, TypeAry::make(Type::BOTTOM,TypeInt::POS), current->env()->Object_klass(), false, arrayOopDesc::length_offset_in_bytes());
   316   TypeAryPtr::NARROWOOPS = TypeAryPtr::make(TypePtr::BotPTR, TypeAry::make(TypeNarrowOop::BOTTOM, TypeInt::POS), NULL /*ciArrayKlass::make(o)*/,  false,  Type::OffsetBot);
   318 #ifdef _LP64
   319   if (UseCompressedOops) {
   320     TypeAryPtr::OOPS  = TypeAryPtr::NARROWOOPS;
   321   } else
   322 #endif
   323   {
   324     // There is no shared klass for Object[].  See note in TypeAryPtr::klass().
   325     TypeAryPtr::OOPS  = TypeAryPtr::make(TypePtr::BotPTR, TypeAry::make(TypeInstPtr::BOTTOM,TypeInt::POS), NULL /*ciArrayKlass::make(o)*/,  false,  Type::OffsetBot);
   326   }
   327   TypeAryPtr::BYTES   = TypeAryPtr::make(TypePtr::BotPTR, TypeAry::make(TypeInt::BYTE      ,TypeInt::POS), ciTypeArrayKlass::make(T_BYTE),   true,  Type::OffsetBot);
   328   TypeAryPtr::SHORTS  = TypeAryPtr::make(TypePtr::BotPTR, TypeAry::make(TypeInt::SHORT     ,TypeInt::POS), ciTypeArrayKlass::make(T_SHORT),  true,  Type::OffsetBot);
   329   TypeAryPtr::CHARS   = TypeAryPtr::make(TypePtr::BotPTR, TypeAry::make(TypeInt::CHAR      ,TypeInt::POS), ciTypeArrayKlass::make(T_CHAR),   true,  Type::OffsetBot);
   330   TypeAryPtr::INTS    = TypeAryPtr::make(TypePtr::BotPTR, TypeAry::make(TypeInt::INT       ,TypeInt::POS), ciTypeArrayKlass::make(T_INT),    true,  Type::OffsetBot);
   331   TypeAryPtr::LONGS   = TypeAryPtr::make(TypePtr::BotPTR, TypeAry::make(TypeLong::LONG     ,TypeInt::POS), ciTypeArrayKlass::make(T_LONG),   true,  Type::OffsetBot);
   332   TypeAryPtr::FLOATS  = TypeAryPtr::make(TypePtr::BotPTR, TypeAry::make(Type::FLOAT        ,TypeInt::POS), ciTypeArrayKlass::make(T_FLOAT),  true,  Type::OffsetBot);
   333   TypeAryPtr::DOUBLES = TypeAryPtr::make(TypePtr::BotPTR, TypeAry::make(Type::DOUBLE       ,TypeInt::POS), ciTypeArrayKlass::make(T_DOUBLE), true,  Type::OffsetBot);
   335   // Nobody should ask _array_body_type[T_NARROWOOP]. Use NULL as assert.
   336   TypeAryPtr::_array_body_type[T_NARROWOOP] = NULL;
   337   TypeAryPtr::_array_body_type[T_OBJECT]  = TypeAryPtr::OOPS;
   338   TypeAryPtr::_array_body_type[T_ARRAY]   = TypeAryPtr::OOPS; // arrays are stored in oop arrays
   339   TypeAryPtr::_array_body_type[T_BYTE]    = TypeAryPtr::BYTES;
   340   TypeAryPtr::_array_body_type[T_BOOLEAN] = TypeAryPtr::BYTES;  // boolean[] is a byte array
   341   TypeAryPtr::_array_body_type[T_SHORT]   = TypeAryPtr::SHORTS;
   342   TypeAryPtr::_array_body_type[T_CHAR]    = TypeAryPtr::CHARS;
   343   TypeAryPtr::_array_body_type[T_INT]     = TypeAryPtr::INTS;
   344   TypeAryPtr::_array_body_type[T_LONG]    = TypeAryPtr::LONGS;
   345   TypeAryPtr::_array_body_type[T_FLOAT]   = TypeAryPtr::FLOATS;
   346   TypeAryPtr::_array_body_type[T_DOUBLE]  = TypeAryPtr::DOUBLES;
   348   TypeKlassPtr::OBJECT = TypeKlassPtr::make( TypePtr::NotNull, current->env()->Object_klass(), 0 );
   349   TypeKlassPtr::OBJECT_OR_NULL = TypeKlassPtr::make( TypePtr::BotPTR, current->env()->Object_klass(), 0 );
   351   const Type **fi2c = TypeTuple::fields(2);
   352   fi2c[TypeFunc::Parms+0] = TypeInstPtr::BOTTOM; // methodOop
   353   fi2c[TypeFunc::Parms+1] = TypeRawPtr::BOTTOM; // argument pointer
   354   TypeTuple::START_I2C = TypeTuple::make(TypeFunc::Parms+2, fi2c);
   356   const Type **intpair = TypeTuple::fields(2);
   357   intpair[0] = TypeInt::INT;
   358   intpair[1] = TypeInt::INT;
   359   TypeTuple::INT_PAIR = TypeTuple::make(2, intpair);
   361   const Type **longpair = TypeTuple::fields(2);
   362   longpair[0] = TypeLong::LONG;
   363   longpair[1] = TypeLong::LONG;
   364   TypeTuple::LONG_PAIR = TypeTuple::make(2, longpair);
   366   _const_basic_type[T_NARROWOOP] = TypeNarrowOop::BOTTOM;
   367   _const_basic_type[T_BOOLEAN] = TypeInt::BOOL;
   368   _const_basic_type[T_CHAR]    = TypeInt::CHAR;
   369   _const_basic_type[T_BYTE]    = TypeInt::BYTE;
   370   _const_basic_type[T_SHORT]   = TypeInt::SHORT;
   371   _const_basic_type[T_INT]     = TypeInt::INT;
   372   _const_basic_type[T_LONG]    = TypeLong::LONG;
   373   _const_basic_type[T_FLOAT]   = Type::FLOAT;
   374   _const_basic_type[T_DOUBLE]  = Type::DOUBLE;
   375   _const_basic_type[T_OBJECT]  = TypeInstPtr::BOTTOM;
   376   _const_basic_type[T_ARRAY]   = TypeInstPtr::BOTTOM; // there is no separate bottom for arrays
   377   _const_basic_type[T_VOID]    = TypePtr::NULL_PTR;   // reflection represents void this way
   378   _const_basic_type[T_ADDRESS] = TypeRawPtr::BOTTOM;  // both interpreter return addresses & random raw ptrs
   379   _const_basic_type[T_CONFLICT]= Type::BOTTOM;        // why not?
   381   _zero_type[T_NARROWOOP] = TypeNarrowOop::NULL_PTR;
   382   _zero_type[T_BOOLEAN] = TypeInt::ZERO;     // false == 0
   383   _zero_type[T_CHAR]    = TypeInt::ZERO;     // '\0' == 0
   384   _zero_type[T_BYTE]    = TypeInt::ZERO;     // 0x00 == 0
   385   _zero_type[T_SHORT]   = TypeInt::ZERO;     // 0x0000 == 0
   386   _zero_type[T_INT]     = TypeInt::ZERO;
   387   _zero_type[T_LONG]    = TypeLong::ZERO;
   388   _zero_type[T_FLOAT]   = TypeF::ZERO;
   389   _zero_type[T_DOUBLE]  = TypeD::ZERO;
   390   _zero_type[T_OBJECT]  = TypePtr::NULL_PTR;
   391   _zero_type[T_ARRAY]   = TypePtr::NULL_PTR; // null array is null oop
   392   _zero_type[T_ADDRESS] = TypePtr::NULL_PTR; // raw pointers use the same null
   393   _zero_type[T_VOID]    = Type::TOP;         // the only void value is no value at all
   395   // get_zero_type() should not happen for T_CONFLICT
   396   _zero_type[T_CONFLICT]= NULL;
   398   // Restore working type arena.
   399   current->set_type_arena(save);
   400   current->set_type_dict(NULL);
   401 }
   403 //------------------------------Initialize-------------------------------------
   404 void Type::Initialize(Compile* current) {
   405   assert(current->type_arena() != NULL, "must have created type arena");
   407   if (_shared_type_dict == NULL) {
   408     Initialize_shared(current);
   409   }
   411   Arena* type_arena = current->type_arena();
   413   // Create the hash-cons'ing dictionary with top-level storage allocation
   414   Dict *tdic = new (type_arena) Dict( (CmpKey)Type::cmp,(Hash)Type::uhash, type_arena, 128 );
   415   current->set_type_dict(tdic);
   417   // Transfer the shared types.
   418   DictI i(_shared_type_dict);
   419   for( ; i.test(); ++i ) {
   420     Type* t = (Type*)i._value;
   421     tdic->Insert(t,t);  // New Type, insert into Type table
   422   }
   424 #ifdef ASSERT
   425   verify_lastype();
   426 #endif
   427 }
   429 //------------------------------hashcons---------------------------------------
   430 // Do the hash-cons trick.  If the Type already exists in the type table,
   431 // delete the current Type and return the existing Type.  Otherwise stick the
   432 // current Type in the Type table.
   433 const Type *Type::hashcons(void) {
   434   debug_only(base());           // Check the assertion in Type::base().
   435   // Look up the Type in the Type dictionary
   436   Dict *tdic = type_dict();
   437   Type* old = (Type*)(tdic->Insert(this, this, false));
   438   if( old ) {                   // Pre-existing Type?
   439     if( old != this )           // Yes, this guy is not the pre-existing?
   440       delete this;              // Yes, Nuke this guy
   441     assert( old->_dual, "" );
   442     return old;                 // Return pre-existing
   443   }
   445   // Every type has a dual (to make my lattice symmetric).
   446   // Since we just discovered a new Type, compute its dual right now.
   447   assert( !_dual, "" );         // No dual yet
   448   _dual = xdual();              // Compute the dual
   449   if( cmp(this,_dual)==0 ) {    // Handle self-symmetric
   450     _dual = this;
   451     return this;
   452   }
   453   assert( !_dual->_dual, "" );  // No reverse dual yet
   454   assert( !(*tdic)[_dual], "" ); // Dual not in type system either
   455   // New Type, insert into Type table
   456   tdic->Insert((void*)_dual,(void*)_dual);
   457   ((Type*)_dual)->_dual = this; // Finish up being symmetric
   458 #ifdef ASSERT
   459   Type *dual_dual = (Type*)_dual->xdual();
   460   assert( eq(dual_dual), "xdual(xdual()) should be identity" );
   461   delete dual_dual;
   462 #endif
   463   return this;                  // Return new Type
   464 }
   466 //------------------------------eq---------------------------------------------
   467 // Structural equality check for Type representations
   468 bool Type::eq( const Type * ) const {
   469   return true;                  // Nothing else can go wrong
   470 }
   472 //------------------------------hash-------------------------------------------
   473 // Type-specific hashing function.
   474 int Type::hash(void) const {
   475   return _base;
   476 }
   478 //------------------------------is_finite--------------------------------------
   479 // Has a finite value
   480 bool Type::is_finite() const {
   481   return false;
   482 }
   484 //------------------------------is_nan-----------------------------------------
   485 // Is not a number (NaN)
   486 bool Type::is_nan()    const {
   487   return false;
   488 }
   490 //------------------------------meet-------------------------------------------
   491 // Compute the MEET of two types.  NOT virtual.  It enforces that meet is
   492 // commutative and the lattice is symmetric.
   493 const Type *Type::meet( const Type *t ) const {
   494   if (isa_narrowoop() && t->isa_narrowoop()) {
   495     const Type* result = make_ptr()->meet(t->make_ptr());
   496     return result->make_narrowoop();
   497   }
   499   const Type *mt = xmeet(t);
   500   if (isa_narrowoop() || t->isa_narrowoop()) return mt;
   501 #ifdef ASSERT
   502   assert( mt == t->xmeet(this), "meet not commutative" );
   503   const Type* dual_join = mt->_dual;
   504   const Type *t2t    = dual_join->xmeet(t->_dual);
   505   const Type *t2this = dual_join->xmeet(   _dual);
   507   // Interface meet Oop is Not Symmetric:
   508   // Interface:AnyNull meet Oop:AnyNull == Interface:AnyNull
   509   // Interface:NotNull meet Oop:NotNull == java/lang/Object:NotNull
   510   const TypeInstPtr* this_inst = this->isa_instptr();
   511   const TypeInstPtr*    t_inst =    t->isa_instptr();
   512   bool interface_vs_oop = false;
   513   if( this_inst && this_inst->is_loaded() && t_inst && t_inst->is_loaded() ) {
   514     bool this_interface = this_inst->klass()->is_interface();
   515     bool    t_interface =    t_inst->klass()->is_interface();
   516     interface_vs_oop = this_interface ^ t_interface;
   517   }
   519   if( !interface_vs_oop && (t2t != t->_dual || t2this != _dual) ) {
   520     tty->print_cr("=== Meet Not Symmetric ===");
   521     tty->print("t   =                   ");         t->dump(); tty->cr();
   522     tty->print("this=                   ");            dump(); tty->cr();
   523     tty->print("mt=(t meet this)=       ");        mt->dump(); tty->cr();
   525     tty->print("t_dual=                 ");  t->_dual->dump(); tty->cr();
   526     tty->print("this_dual=              ");     _dual->dump(); tty->cr();
   527     tty->print("mt_dual=                "); mt->_dual->dump(); tty->cr();
   529     tty->print("mt_dual meet t_dual=    "); t2t      ->dump(); tty->cr();
   530     tty->print("mt_dual meet this_dual= "); t2this   ->dump(); tty->cr();
   532     fatal("meet not symmetric" );
   533   }
   534 #endif
   535   return mt;
   536 }
   538 //------------------------------xmeet------------------------------------------
   539 // Compute the MEET of two types.  It returns a new Type object.
   540 const Type *Type::xmeet( const Type *t ) const {
   541   // Perform a fast test for common case; meeting the same types together.
   542   if( this == t ) return this;  // Meeting same type-rep?
   544   // Meeting TOP with anything?
   545   if( _base == Top ) return t;
   547   // Meeting BOTTOM with anything?
   548   if( _base == Bottom ) return BOTTOM;
   550   // Current "this->_base" is one of: Bad, Multi, Control, Top,
   551   // Abio, Abstore, Floatxxx, Doublexxx, Bottom, lastype.
   552   switch (t->base()) {  // Switch on original type
   554   // Cut in half the number of cases I must handle.  Only need cases for when
   555   // the given enum "t->type" is less than or equal to the local enum "type".
   556   case FloatCon:
   557   case DoubleCon:
   558   case Int:
   559   case Long:
   560     return t->xmeet(this);
   562   case OopPtr:
   563     return t->xmeet(this);
   565   case InstPtr:
   566     return t->xmeet(this);
   568   case KlassPtr:
   569     return t->xmeet(this);
   571   case AryPtr:
   572     return t->xmeet(this);
   574   case NarrowOop:
   575     return t->xmeet(this);
   577   case Bad:                     // Type check
   578   default:                      // Bogus type not in lattice
   579     typerr(t);
   580     return Type::BOTTOM;
   582   case Bottom:                  // Ye Olde Default
   583     return t;
   585   case FloatTop:
   586     if( _base == FloatTop ) return this;
   587   case FloatBot:                // Float
   588     if( _base == FloatBot || _base == FloatTop ) return FLOAT;
   589     if( _base == DoubleTop || _base == DoubleBot ) return Type::BOTTOM;
   590     typerr(t);
   591     return Type::BOTTOM;
   593   case DoubleTop:
   594     if( _base == DoubleTop ) return this;
   595   case DoubleBot:               // Double
   596     if( _base == DoubleBot || _base == DoubleTop ) return DOUBLE;
   597     if( _base == FloatTop || _base == FloatBot ) return Type::BOTTOM;
   598     typerr(t);
   599     return Type::BOTTOM;
   601   // These next few cases must match exactly or it is a compile-time error.
   602   case Control:                 // Control of code
   603   case Abio:                    // State of world outside of program
   604   case Memory:
   605     if( _base == t->_base )  return this;
   606     typerr(t);
   607     return Type::BOTTOM;
   609   case Top:                     // Top of the lattice
   610     return this;
   611   }
   613   // The type is unchanged
   614   return this;
   615 }
   617 //-----------------------------filter------------------------------------------
   618 const Type *Type::filter( const Type *kills ) const {
   619   const Type* ft = join(kills);
   620   if (ft->empty())
   621     return Type::TOP;           // Canonical empty value
   622   return ft;
   623 }
   625 //------------------------------xdual------------------------------------------
   626 // Compute dual right now.
   627 const Type::TYPES Type::dual_type[Type::lastype] = {
   628   Bad,          // Bad
   629   Control,      // Control
   630   Bottom,       // Top
   631   Bad,          // Int - handled in v-call
   632   Bad,          // Long - handled in v-call
   633   Half,         // Half
   634   Bad,          // NarrowOop - handled in v-call
   636   Bad,          // Tuple - handled in v-call
   637   Bad,          // Array - handled in v-call
   639   Bad,          // AnyPtr - handled in v-call
   640   Bad,          // RawPtr - handled in v-call
   641   Bad,          // OopPtr - handled in v-call
   642   Bad,          // InstPtr - handled in v-call
   643   Bad,          // AryPtr - handled in v-call
   644   Bad,          // KlassPtr - handled in v-call
   646   Bad,          // Function - handled in v-call
   647   Abio,         // Abio
   648   Return_Address,// Return_Address
   649   Memory,       // Memory
   650   FloatBot,     // FloatTop
   651   FloatCon,     // FloatCon
   652   FloatTop,     // FloatBot
   653   DoubleBot,    // DoubleTop
   654   DoubleCon,    // DoubleCon
   655   DoubleTop,    // DoubleBot
   656   Top           // Bottom
   657 };
   659 const Type *Type::xdual() const {
   660   // Note: the base() accessor asserts the sanity of _base.
   661   assert(dual_type[base()] != Bad, "implement with v-call");
   662   return new Type(dual_type[_base]);
   663 }
   665 //------------------------------has_memory-------------------------------------
   666 bool Type::has_memory() const {
   667   Type::TYPES tx = base();
   668   if (tx == Memory) return true;
   669   if (tx == Tuple) {
   670     const TypeTuple *t = is_tuple();
   671     for (uint i=0; i < t->cnt(); i++) {
   672       tx = t->field_at(i)->base();
   673       if (tx == Memory)  return true;
   674     }
   675   }
   676   return false;
   677 }
   679 #ifndef PRODUCT
   680 //------------------------------dump2------------------------------------------
   681 void Type::dump2( Dict &d, uint depth, outputStream *st ) const {
   682   st->print(msg[_base]);
   683 }
   685 //------------------------------dump-------------------------------------------
   686 void Type::dump_on(outputStream *st) const {
   687   ResourceMark rm;
   688   Dict d(cmpkey,hashkey);       // Stop recursive type dumping
   689   dump2(d,1, st);
   690   if (is_ptr_to_narrowoop()) {
   691     st->print(" [narrow]");
   692   }
   693 }
   695 //------------------------------data-------------------------------------------
   696 const char * const Type::msg[Type::lastype] = {
   697   "bad","control","top","int:","long:","half", "narrowoop:",
   698   "tuple:", "aryptr",
   699   "anyptr:", "rawptr:", "java:", "inst:", "ary:", "klass:",
   700   "func", "abIO", "return_address", "memory",
   701   "float_top", "ftcon:", "float",
   702   "double_top", "dblcon:", "double",
   703   "bottom"
   704 };
   705 #endif
   707 //------------------------------singleton--------------------------------------
   708 // TRUE if Type is a singleton type, FALSE otherwise.   Singletons are simple
   709 // constants (Ldi nodes).  Singletons are integer, float or double constants.
   710 bool Type::singleton(void) const {
   711   return _base == Top || _base == Half;
   712 }
   714 //------------------------------empty------------------------------------------
   715 // TRUE if Type is a type with no values, FALSE otherwise.
   716 bool Type::empty(void) const {
   717   switch (_base) {
   718   case DoubleTop:
   719   case FloatTop:
   720   case Top:
   721     return true;
   723   case Half:
   724   case Abio:
   725   case Return_Address:
   726   case Memory:
   727   case Bottom:
   728   case FloatBot:
   729   case DoubleBot:
   730     return false;  // never a singleton, therefore never empty
   731   }
   733   ShouldNotReachHere();
   734   return false;
   735 }
   737 //------------------------------dump_stats-------------------------------------
   738 // Dump collected statistics to stderr
   739 #ifndef PRODUCT
   740 void Type::dump_stats() {
   741   tty->print("Types made: %d\n", type_dict()->Size());
   742 }
   743 #endif
   745 //------------------------------typerr-----------------------------------------
   746 void Type::typerr( const Type *t ) const {
   747 #ifndef PRODUCT
   748   tty->print("\nError mixing types: ");
   749   dump();
   750   tty->print(" and ");
   751   t->dump();
   752   tty->print("\n");
   753 #endif
   754   ShouldNotReachHere();
   755 }
   757 //------------------------------isa_oop_ptr------------------------------------
   758 // Return true if type is an oop pointer type.  False for raw pointers.
   759 static char isa_oop_ptr_tbl[Type::lastype] = {
   760   0,0,0,0,0,0,0/*narrowoop*/,0/*tuple*/, 0/*ary*/,
   761   0/*anyptr*/,0/*rawptr*/,1/*OopPtr*/,1/*InstPtr*/,1/*AryPtr*/,1/*KlassPtr*/,
   762   0/*func*/,0,0/*return_address*/,0,
   763   /*floats*/0,0,0, /*doubles*/0,0,0,
   764   0
   765 };
   766 bool Type::isa_oop_ptr() const {
   767   return isa_oop_ptr_tbl[_base] != 0;
   768 }
   770 //------------------------------dump_stats-------------------------------------
   771 // // Check that arrays match type enum
   772 #ifndef PRODUCT
   773 void Type::verify_lastype() {
   774   // Check that arrays match enumeration
   775   assert( Type::dual_type  [Type::lastype - 1] == Type::Top, "did not update array");
   776   assert( strcmp(Type::msg [Type::lastype - 1],"bottom") == 0, "did not update array");
   777   // assert( PhiNode::tbl     [Type::lastype - 1] == NULL,    "did not update array");
   778   assert( Matcher::base2reg[Type::lastype - 1] == 0,      "did not update array");
   779   assert( isa_oop_ptr_tbl  [Type::lastype - 1] == (char)0,  "did not update array");
   780 }
   781 #endif
   783 //=============================================================================
   784 // Convenience common pre-built types.
   785 const TypeF *TypeF::ZERO;       // Floating point zero
   786 const TypeF *TypeF::ONE;        // Floating point one
   788 //------------------------------make-------------------------------------------
   789 // Create a float constant
   790 const TypeF *TypeF::make(float f) {
   791   return (TypeF*)(new TypeF(f))->hashcons();
   792 }
   794 //------------------------------meet-------------------------------------------
   795 // Compute the MEET of two types.  It returns a new Type object.
   796 const Type *TypeF::xmeet( const Type *t ) const {
   797   // Perform a fast test for common case; meeting the same types together.
   798   if( this == t ) return this;  // Meeting same type-rep?
   800   // Current "this->_base" is FloatCon
   801   switch (t->base()) {          // Switch on original type
   802   case AnyPtr:                  // Mixing with oops happens when javac
   803   case RawPtr:                  // reuses local variables
   804   case OopPtr:
   805   case InstPtr:
   806   case KlassPtr:
   807   case AryPtr:
   808   case NarrowOop:
   809   case Int:
   810   case Long:
   811   case DoubleTop:
   812   case DoubleCon:
   813   case DoubleBot:
   814   case Bottom:                  // Ye Olde Default
   815     return Type::BOTTOM;
   817   case FloatBot:
   818     return t;
   820   default:                      // All else is a mistake
   821     typerr(t);
   823   case FloatCon:                // Float-constant vs Float-constant?
   824     if( jint_cast(_f) != jint_cast(t->getf()) )         // unequal constants?
   825                                 // must compare bitwise as positive zero, negative zero and NaN have
   826                                 // all the same representation in C++
   827       return FLOAT;             // Return generic float
   828                                 // Equal constants
   829   case Top:
   830   case FloatTop:
   831     break;                      // Return the float constant
   832   }
   833   return this;                  // Return the float constant
   834 }
   836 //------------------------------xdual------------------------------------------
   837 // Dual: symmetric
   838 const Type *TypeF::xdual() const {
   839   return this;
   840 }
   842 //------------------------------eq---------------------------------------------
   843 // Structural equality check for Type representations
   844 bool TypeF::eq( const Type *t ) const {
   845   if( g_isnan(_f) ||
   846       g_isnan(t->getf()) ) {
   847     // One or both are NANs.  If both are NANs return true, else false.
   848     return (g_isnan(_f) && g_isnan(t->getf()));
   849   }
   850   if (_f == t->getf()) {
   851     // (NaN is impossible at this point, since it is not equal even to itself)
   852     if (_f == 0.0) {
   853       // difference between positive and negative zero
   854       if (jint_cast(_f) != jint_cast(t->getf()))  return false;
   855     }
   856     return true;
   857   }
   858   return false;
   859 }
   861 //------------------------------hash-------------------------------------------
   862 // Type-specific hashing function.
   863 int TypeF::hash(void) const {
   864   return *(int*)(&_f);
   865 }
   867 //------------------------------is_finite--------------------------------------
   868 // Has a finite value
   869 bool TypeF::is_finite() const {
   870   return g_isfinite(getf()) != 0;
   871 }
   873 //------------------------------is_nan-----------------------------------------
   874 // Is not a number (NaN)
   875 bool TypeF::is_nan()    const {
   876   return g_isnan(getf()) != 0;
   877 }
   879 //------------------------------dump2------------------------------------------
   880 // Dump float constant Type
   881 #ifndef PRODUCT
   882 void TypeF::dump2( Dict &d, uint depth, outputStream *st ) const {
   883   Type::dump2(d,depth, st);
   884   st->print("%f", _f);
   885 }
   886 #endif
   888 //------------------------------singleton--------------------------------------
   889 // TRUE if Type is a singleton type, FALSE otherwise.   Singletons are simple
   890 // constants (Ldi nodes).  Singletons are integer, float or double constants
   891 // or a single symbol.
   892 bool TypeF::singleton(void) const {
   893   return true;                  // Always a singleton
   894 }
   896 bool TypeF::empty(void) const {
   897   return false;                 // always exactly a singleton
   898 }
   900 //=============================================================================
   901 // Convenience common pre-built types.
   902 const TypeD *TypeD::ZERO;       // Floating point zero
   903 const TypeD *TypeD::ONE;        // Floating point one
   905 //------------------------------make-------------------------------------------
   906 const TypeD *TypeD::make(double d) {
   907   return (TypeD*)(new TypeD(d))->hashcons();
   908 }
   910 //------------------------------meet-------------------------------------------
   911 // Compute the MEET of two types.  It returns a new Type object.
   912 const Type *TypeD::xmeet( const Type *t ) const {
   913   // Perform a fast test for common case; meeting the same types together.
   914   if( this == t ) return this;  // Meeting same type-rep?
   916   // Current "this->_base" is DoubleCon
   917   switch (t->base()) {          // Switch on original type
   918   case AnyPtr:                  // Mixing with oops happens when javac
   919   case RawPtr:                  // reuses local variables
   920   case OopPtr:
   921   case InstPtr:
   922   case KlassPtr:
   923   case AryPtr:
   924   case NarrowOop:
   925   case Int:
   926   case Long:
   927   case FloatTop:
   928   case FloatCon:
   929   case FloatBot:
   930   case Bottom:                  // Ye Olde Default
   931     return Type::BOTTOM;
   933   case DoubleBot:
   934     return t;
   936   default:                      // All else is a mistake
   937     typerr(t);
   939   case DoubleCon:               // Double-constant vs Double-constant?
   940     if( jlong_cast(_d) != jlong_cast(t->getd()) )       // unequal constants? (see comment in TypeF::xmeet)
   941       return DOUBLE;            // Return generic double
   942   case Top:
   943   case DoubleTop:
   944     break;
   945   }
   946   return this;                  // Return the double constant
   947 }
   949 //------------------------------xdual------------------------------------------
   950 // Dual: symmetric
   951 const Type *TypeD::xdual() const {
   952   return this;
   953 }
   955 //------------------------------eq---------------------------------------------
   956 // Structural equality check for Type representations
   957 bool TypeD::eq( const Type *t ) const {
   958   if( g_isnan(_d) ||
   959       g_isnan(t->getd()) ) {
   960     // One or both are NANs.  If both are NANs return true, else false.
   961     return (g_isnan(_d) && g_isnan(t->getd()));
   962   }
   963   if (_d == t->getd()) {
   964     // (NaN is impossible at this point, since it is not equal even to itself)
   965     if (_d == 0.0) {
   966       // difference between positive and negative zero
   967       if (jlong_cast(_d) != jlong_cast(t->getd()))  return false;
   968     }
   969     return true;
   970   }
   971   return false;
   972 }
   974 //------------------------------hash-------------------------------------------
   975 // Type-specific hashing function.
   976 int TypeD::hash(void) const {
   977   return *(int*)(&_d);
   978 }
   980 //------------------------------is_finite--------------------------------------
   981 // Has a finite value
   982 bool TypeD::is_finite() const {
   983   return g_isfinite(getd()) != 0;
   984 }
   986 //------------------------------is_nan-----------------------------------------
   987 // Is not a number (NaN)
   988 bool TypeD::is_nan()    const {
   989   return g_isnan(getd()) != 0;
   990 }
   992 //------------------------------dump2------------------------------------------
   993 // Dump double constant Type
   994 #ifndef PRODUCT
   995 void TypeD::dump2( Dict &d, uint depth, outputStream *st ) const {
   996   Type::dump2(d,depth,st);
   997   st->print("%f", _d);
   998 }
   999 #endif
  1001 //------------------------------singleton--------------------------------------
  1002 // TRUE if Type is a singleton type, FALSE otherwise.   Singletons are simple
  1003 // constants (Ldi nodes).  Singletons are integer, float or double constants
  1004 // or a single symbol.
  1005 bool TypeD::singleton(void) const {
  1006   return true;                  // Always a singleton
  1009 bool TypeD::empty(void) const {
  1010   return false;                 // always exactly a singleton
  1013 //=============================================================================
  1014 // Convience common pre-built types.
  1015 const TypeInt *TypeInt::MINUS_1;// -1
  1016 const TypeInt *TypeInt::ZERO;   // 0
  1017 const TypeInt *TypeInt::ONE;    // 1
  1018 const TypeInt *TypeInt::BOOL;   // 0 or 1, FALSE or TRUE.
  1019 const TypeInt *TypeInt::CC;     // -1,0 or 1, condition codes
  1020 const TypeInt *TypeInt::CC_LT;  // [-1]  == MINUS_1
  1021 const TypeInt *TypeInt::CC_GT;  // [1]   == ONE
  1022 const TypeInt *TypeInt::CC_EQ;  // [0]   == ZERO
  1023 const TypeInt *TypeInt::CC_LE;  // [-1,0]
  1024 const TypeInt *TypeInt::CC_GE;  // [0,1] == BOOL (!)
  1025 const TypeInt *TypeInt::BYTE;   // Bytes, -128 to 127
  1026 const TypeInt *TypeInt::UBYTE;  // Unsigned Bytes, 0 to 255
  1027 const TypeInt *TypeInt::CHAR;   // Java chars, 0-65535
  1028 const TypeInt *TypeInt::SHORT;  // Java shorts, -32768-32767
  1029 const TypeInt *TypeInt::POS;    // Positive 32-bit integers or zero
  1030 const TypeInt *TypeInt::POS1;   // Positive 32-bit integers
  1031 const TypeInt *TypeInt::INT;    // 32-bit integers
  1032 const TypeInt *TypeInt::SYMINT; // symmetric range [-max_jint..max_jint]
  1034 //------------------------------TypeInt----------------------------------------
  1035 TypeInt::TypeInt( jint lo, jint hi, int w ) : Type(Int), _lo(lo), _hi(hi), _widen(w) {
  1038 //------------------------------make-------------------------------------------
  1039 const TypeInt *TypeInt::make( jint lo ) {
  1040   return (TypeInt*)(new TypeInt(lo,lo,WidenMin))->hashcons();
  1043 #define SMALLINT ((juint)3)  // a value too insignificant to consider widening
  1045 const TypeInt *TypeInt::make( jint lo, jint hi, int w ) {
  1046   // Certain normalizations keep us sane when comparing types.
  1047   // The 'SMALLINT' covers constants and also CC and its relatives.
  1048   assert(CC == NULL || (juint)(CC->_hi - CC->_lo) <= SMALLINT, "CC is truly small");
  1049   if (lo <= hi) {
  1050     if ((juint)(hi - lo) <= SMALLINT)   w = Type::WidenMin;
  1051     if ((juint)(hi - lo) >= max_juint)  w = Type::WidenMax; // plain int
  1053   return (TypeInt*)(new TypeInt(lo,hi,w))->hashcons();
  1056 //------------------------------meet-------------------------------------------
  1057 // Compute the MEET of two types.  It returns a new Type representation object
  1058 // with reference count equal to the number of Types pointing at it.
  1059 // Caller should wrap a Types around it.
  1060 const Type *TypeInt::xmeet( const Type *t ) const {
  1061   // Perform a fast test for common case; meeting the same types together.
  1062   if( this == t ) return this;  // Meeting same type?
  1064   // Currently "this->_base" is a TypeInt
  1065   switch (t->base()) {          // Switch on original type
  1066   case AnyPtr:                  // Mixing with oops happens when javac
  1067   case RawPtr:                  // reuses local variables
  1068   case OopPtr:
  1069   case InstPtr:
  1070   case KlassPtr:
  1071   case AryPtr:
  1072   case NarrowOop:
  1073   case Long:
  1074   case FloatTop:
  1075   case FloatCon:
  1076   case FloatBot:
  1077   case DoubleTop:
  1078   case DoubleCon:
  1079   case DoubleBot:
  1080   case Bottom:                  // Ye Olde Default
  1081     return Type::BOTTOM;
  1082   default:                      // All else is a mistake
  1083     typerr(t);
  1084   case Top:                     // No change
  1085     return this;
  1086   case Int:                     // Int vs Int?
  1087     break;
  1090   // Expand covered set
  1091   const TypeInt *r = t->is_int();
  1092   // (Avoid TypeInt::make, to avoid the argument normalizations it enforces.)
  1093   return (new TypeInt( MIN2(_lo,r->_lo), MAX2(_hi,r->_hi), MAX2(_widen,r->_widen) ))->hashcons();
  1096 //------------------------------xdual------------------------------------------
  1097 // Dual: reverse hi & lo; flip widen
  1098 const Type *TypeInt::xdual() const {
  1099   return new TypeInt(_hi,_lo,WidenMax-_widen);
  1102 //------------------------------widen------------------------------------------
  1103 // Only happens for optimistic top-down optimizations.
  1104 const Type *TypeInt::widen( const Type *old ) const {
  1105   // Coming from TOP or such; no widening
  1106   if( old->base() != Int ) return this;
  1107   const TypeInt *ot = old->is_int();
  1109   // If new guy is equal to old guy, no widening
  1110   if( _lo == ot->_lo && _hi == ot->_hi )
  1111     return old;
  1113   // If new guy contains old, then we widened
  1114   if( _lo <= ot->_lo && _hi >= ot->_hi ) {
  1115     // New contains old
  1116     // If new guy is already wider than old, no widening
  1117     if( _widen > ot->_widen ) return this;
  1118     // If old guy was a constant, do not bother
  1119     if (ot->_lo == ot->_hi)  return this;
  1120     // Now widen new guy.
  1121     // Check for widening too far
  1122     if (_widen == WidenMax) {
  1123       if (min_jint < _lo && _hi < max_jint) {
  1124         // If neither endpoint is extremal yet, push out the endpoint
  1125         // which is closer to its respective limit.
  1126         if (_lo >= 0 ||                 // easy common case
  1127             (juint)(_lo - min_jint) >= (juint)(max_jint - _hi)) {
  1128           // Try to widen to an unsigned range type of 31 bits:
  1129           return make(_lo, max_jint, WidenMax);
  1130         } else {
  1131           return make(min_jint, _hi, WidenMax);
  1134       return TypeInt::INT;
  1136     // Returned widened new guy
  1137     return make(_lo,_hi,_widen+1);
  1140   // If old guy contains new, then we probably widened too far & dropped to
  1141   // bottom.  Return the wider fellow.
  1142   if ( ot->_lo <= _lo && ot->_hi >= _hi )
  1143     return old;
  1145   //fatal("Integer value range is not subset");
  1146   //return this;
  1147   return TypeInt::INT;
  1150 //------------------------------narrow---------------------------------------
  1151 // Only happens for pessimistic optimizations.
  1152 const Type *TypeInt::narrow( const Type *old ) const {
  1153   if (_lo >= _hi)  return this;   // already narrow enough
  1154   if (old == NULL)  return this;
  1155   const TypeInt* ot = old->isa_int();
  1156   if (ot == NULL)  return this;
  1157   jint olo = ot->_lo;
  1158   jint ohi = ot->_hi;
  1160   // If new guy is equal to old guy, no narrowing
  1161   if (_lo == olo && _hi == ohi)  return old;
  1163   // If old guy was maximum range, allow the narrowing
  1164   if (olo == min_jint && ohi == max_jint)  return this;
  1166   if (_lo < olo || _hi > ohi)
  1167     return this;                // doesn't narrow; pretty wierd
  1169   // The new type narrows the old type, so look for a "death march".
  1170   // See comments on PhaseTransform::saturate.
  1171   juint nrange = _hi - _lo;
  1172   juint orange = ohi - olo;
  1173   if (nrange < max_juint - 1 && nrange > (orange >> 1) + (SMALLINT*2)) {
  1174     // Use the new type only if the range shrinks a lot.
  1175     // We do not want the optimizer computing 2^31 point by point.
  1176     return old;
  1179   return this;
  1182 //-----------------------------filter------------------------------------------
  1183 const Type *TypeInt::filter( const Type *kills ) const {
  1184   const TypeInt* ft = join(kills)->isa_int();
  1185   if (ft == NULL || ft->_lo > ft->_hi)
  1186     return Type::TOP;           // Canonical empty value
  1187   if (ft->_widen < this->_widen) {
  1188     // Do not allow the value of kill->_widen to affect the outcome.
  1189     // The widen bits must be allowed to run freely through the graph.
  1190     ft = TypeInt::make(ft->_lo, ft->_hi, this->_widen);
  1192   return ft;
  1195 //------------------------------eq---------------------------------------------
  1196 // Structural equality check for Type representations
  1197 bool TypeInt::eq( const Type *t ) const {
  1198   const TypeInt *r = t->is_int(); // Handy access
  1199   return r->_lo == _lo && r->_hi == _hi && r->_widen == _widen;
  1202 //------------------------------hash-------------------------------------------
  1203 // Type-specific hashing function.
  1204 int TypeInt::hash(void) const {
  1205   return _lo+_hi+_widen+(int)Type::Int;
  1208 //------------------------------is_finite--------------------------------------
  1209 // Has a finite value
  1210 bool TypeInt::is_finite() const {
  1211   return true;
  1214 //------------------------------dump2------------------------------------------
  1215 // Dump TypeInt
  1216 #ifndef PRODUCT
  1217 static const char* intname(char* buf, jint n) {
  1218   if (n == min_jint)
  1219     return "min";
  1220   else if (n < min_jint + 10000)
  1221     sprintf(buf, "min+" INT32_FORMAT, n - min_jint);
  1222   else if (n == max_jint)
  1223     return "max";
  1224   else if (n > max_jint - 10000)
  1225     sprintf(buf, "max-" INT32_FORMAT, max_jint - n);
  1226   else
  1227     sprintf(buf, INT32_FORMAT, n);
  1228   return buf;
  1231 void TypeInt::dump2( Dict &d, uint depth, outputStream *st ) const {
  1232   char buf[40], buf2[40];
  1233   if (_lo == min_jint && _hi == max_jint)
  1234     st->print("int");
  1235   else if (is_con())
  1236     st->print("int:%s", intname(buf, get_con()));
  1237   else if (_lo == BOOL->_lo && _hi == BOOL->_hi)
  1238     st->print("bool");
  1239   else if (_lo == BYTE->_lo && _hi == BYTE->_hi)
  1240     st->print("byte");
  1241   else if (_lo == CHAR->_lo && _hi == CHAR->_hi)
  1242     st->print("char");
  1243   else if (_lo == SHORT->_lo && _hi == SHORT->_hi)
  1244     st->print("short");
  1245   else if (_hi == max_jint)
  1246     st->print("int:>=%s", intname(buf, _lo));
  1247   else if (_lo == min_jint)
  1248     st->print("int:<=%s", intname(buf, _hi));
  1249   else
  1250     st->print("int:%s..%s", intname(buf, _lo), intname(buf2, _hi));
  1252   if (_widen != 0 && this != TypeInt::INT)
  1253     st->print(":%.*s", _widen, "wwww");
  1255 #endif
  1257 //------------------------------singleton--------------------------------------
  1258 // TRUE if Type is a singleton type, FALSE otherwise.   Singletons are simple
  1259 // constants.
  1260 bool TypeInt::singleton(void) const {
  1261   return _lo >= _hi;
  1264 bool TypeInt::empty(void) const {
  1265   return _lo > _hi;
  1268 //=============================================================================
  1269 // Convenience common pre-built types.
  1270 const TypeLong *TypeLong::MINUS_1;// -1
  1271 const TypeLong *TypeLong::ZERO; // 0
  1272 const TypeLong *TypeLong::ONE;  // 1
  1273 const TypeLong *TypeLong::POS;  // >=0
  1274 const TypeLong *TypeLong::LONG; // 64-bit integers
  1275 const TypeLong *TypeLong::INT;  // 32-bit subrange
  1276 const TypeLong *TypeLong::UINT; // 32-bit unsigned subrange
  1278 //------------------------------TypeLong---------------------------------------
  1279 TypeLong::TypeLong( jlong lo, jlong hi, int w ) : Type(Long), _lo(lo), _hi(hi), _widen(w) {
  1282 //------------------------------make-------------------------------------------
  1283 const TypeLong *TypeLong::make( jlong lo ) {
  1284   return (TypeLong*)(new TypeLong(lo,lo,WidenMin))->hashcons();
  1287 const TypeLong *TypeLong::make( jlong lo, jlong hi, int w ) {
  1288   // Certain normalizations keep us sane when comparing types.
  1289   // The '1' covers constants.
  1290   if (lo <= hi) {
  1291     if ((julong)(hi - lo) <= SMALLINT)    w = Type::WidenMin;
  1292     if ((julong)(hi - lo) >= max_julong)  w = Type::WidenMax; // plain long
  1294   return (TypeLong*)(new TypeLong(lo,hi,w))->hashcons();
  1298 //------------------------------meet-------------------------------------------
  1299 // Compute the MEET of two types.  It returns a new Type representation object
  1300 // with reference count equal to the number of Types pointing at it.
  1301 // Caller should wrap a Types around it.
  1302 const Type *TypeLong::xmeet( const Type *t ) const {
  1303   // Perform a fast test for common case; meeting the same types together.
  1304   if( this == t ) return this;  // Meeting same type?
  1306   // Currently "this->_base" is a TypeLong
  1307   switch (t->base()) {          // Switch on original type
  1308   case AnyPtr:                  // Mixing with oops happens when javac
  1309   case RawPtr:                  // reuses local variables
  1310   case OopPtr:
  1311   case InstPtr:
  1312   case KlassPtr:
  1313   case AryPtr:
  1314   case NarrowOop:
  1315   case Int:
  1316   case FloatTop:
  1317   case FloatCon:
  1318   case FloatBot:
  1319   case DoubleTop:
  1320   case DoubleCon:
  1321   case DoubleBot:
  1322   case Bottom:                  // Ye Olde Default
  1323     return Type::BOTTOM;
  1324   default:                      // All else is a mistake
  1325     typerr(t);
  1326   case Top:                     // No change
  1327     return this;
  1328   case Long:                    // Long vs Long?
  1329     break;
  1332   // Expand covered set
  1333   const TypeLong *r = t->is_long(); // Turn into a TypeLong
  1334   // (Avoid TypeLong::make, to avoid the argument normalizations it enforces.)
  1335   return (new TypeLong( MIN2(_lo,r->_lo), MAX2(_hi,r->_hi), MAX2(_widen,r->_widen) ))->hashcons();
  1338 //------------------------------xdual------------------------------------------
  1339 // Dual: reverse hi & lo; flip widen
  1340 const Type *TypeLong::xdual() const {
  1341   return new TypeLong(_hi,_lo,WidenMax-_widen);
  1344 //------------------------------widen------------------------------------------
  1345 // Only happens for optimistic top-down optimizations.
  1346 const Type *TypeLong::widen( const Type *old ) const {
  1347   // Coming from TOP or such; no widening
  1348   if( old->base() != Long ) return this;
  1349   const TypeLong *ot = old->is_long();
  1351   // If new guy is equal to old guy, no widening
  1352   if( _lo == ot->_lo && _hi == ot->_hi )
  1353     return old;
  1355   // If new guy contains old, then we widened
  1356   if( _lo <= ot->_lo && _hi >= ot->_hi ) {
  1357     // New contains old
  1358     // If new guy is already wider than old, no widening
  1359     if( _widen > ot->_widen ) return this;
  1360     // If old guy was a constant, do not bother
  1361     if (ot->_lo == ot->_hi)  return this;
  1362     // Now widen new guy.
  1363     // Check for widening too far
  1364     if (_widen == WidenMax) {
  1365       if (min_jlong < _lo && _hi < max_jlong) {
  1366         // If neither endpoint is extremal yet, push out the endpoint
  1367         // which is closer to its respective limit.
  1368         if (_lo >= 0 ||                 // easy common case
  1369             (julong)(_lo - min_jlong) >= (julong)(max_jlong - _hi)) {
  1370           // Try to widen to an unsigned range type of 32/63 bits:
  1371           if (_hi < max_juint)
  1372             return make(_lo, max_juint, WidenMax);
  1373           else
  1374             return make(_lo, max_jlong, WidenMax);
  1375         } else {
  1376           return make(min_jlong, _hi, WidenMax);
  1379       return TypeLong::LONG;
  1381     // Returned widened new guy
  1382     return make(_lo,_hi,_widen+1);
  1385   // If old guy contains new, then we probably widened too far & dropped to
  1386   // bottom.  Return the wider fellow.
  1387   if ( ot->_lo <= _lo && ot->_hi >= _hi )
  1388     return old;
  1390   //  fatal("Long value range is not subset");
  1391   // return this;
  1392   return TypeLong::LONG;
  1395 //------------------------------narrow----------------------------------------
  1396 // Only happens for pessimistic optimizations.
  1397 const Type *TypeLong::narrow( const Type *old ) const {
  1398   if (_lo >= _hi)  return this;   // already narrow enough
  1399   if (old == NULL)  return this;
  1400   const TypeLong* ot = old->isa_long();
  1401   if (ot == NULL)  return this;
  1402   jlong olo = ot->_lo;
  1403   jlong ohi = ot->_hi;
  1405   // If new guy is equal to old guy, no narrowing
  1406   if (_lo == olo && _hi == ohi)  return old;
  1408   // If old guy was maximum range, allow the narrowing
  1409   if (olo == min_jlong && ohi == max_jlong)  return this;
  1411   if (_lo < olo || _hi > ohi)
  1412     return this;                // doesn't narrow; pretty wierd
  1414   // The new type narrows the old type, so look for a "death march".
  1415   // See comments on PhaseTransform::saturate.
  1416   julong nrange = _hi - _lo;
  1417   julong orange = ohi - olo;
  1418   if (nrange < max_julong - 1 && nrange > (orange >> 1) + (SMALLINT*2)) {
  1419     // Use the new type only if the range shrinks a lot.
  1420     // We do not want the optimizer computing 2^31 point by point.
  1421     return old;
  1424   return this;
  1427 //-----------------------------filter------------------------------------------
  1428 const Type *TypeLong::filter( const Type *kills ) const {
  1429   const TypeLong* ft = join(kills)->isa_long();
  1430   if (ft == NULL || ft->_lo > ft->_hi)
  1431     return Type::TOP;           // Canonical empty value
  1432   if (ft->_widen < this->_widen) {
  1433     // Do not allow the value of kill->_widen to affect the outcome.
  1434     // The widen bits must be allowed to run freely through the graph.
  1435     ft = TypeLong::make(ft->_lo, ft->_hi, this->_widen);
  1437   return ft;
  1440 //------------------------------eq---------------------------------------------
  1441 // Structural equality check for Type representations
  1442 bool TypeLong::eq( const Type *t ) const {
  1443   const TypeLong *r = t->is_long(); // Handy access
  1444   return r->_lo == _lo &&  r->_hi == _hi  && r->_widen == _widen;
  1447 //------------------------------hash-------------------------------------------
  1448 // Type-specific hashing function.
  1449 int TypeLong::hash(void) const {
  1450   return (int)(_lo+_hi+_widen+(int)Type::Long);
  1453 //------------------------------is_finite--------------------------------------
  1454 // Has a finite value
  1455 bool TypeLong::is_finite() const {
  1456   return true;
  1459 //------------------------------dump2------------------------------------------
  1460 // Dump TypeLong
  1461 #ifndef PRODUCT
  1462 static const char* longnamenear(jlong x, const char* xname, char* buf, jlong n) {
  1463   if (n > x) {
  1464     if (n >= x + 10000)  return NULL;
  1465     sprintf(buf, "%s+" INT64_FORMAT, xname, n - x);
  1466   } else if (n < x) {
  1467     if (n <= x - 10000)  return NULL;
  1468     sprintf(buf, "%s-" INT64_FORMAT, xname, x - n);
  1469   } else {
  1470     return xname;
  1472   return buf;
  1475 static const char* longname(char* buf, jlong n) {
  1476   const char* str;
  1477   if (n == min_jlong)
  1478     return "min";
  1479   else if (n < min_jlong + 10000)
  1480     sprintf(buf, "min+" INT64_FORMAT, n - min_jlong);
  1481   else if (n == max_jlong)
  1482     return "max";
  1483   else if (n > max_jlong - 10000)
  1484     sprintf(buf, "max-" INT64_FORMAT, max_jlong - n);
  1485   else if ((str = longnamenear(max_juint, "maxuint", buf, n)) != NULL)
  1486     return str;
  1487   else if ((str = longnamenear(max_jint, "maxint", buf, n)) != NULL)
  1488     return str;
  1489   else if ((str = longnamenear(min_jint, "minint", buf, n)) != NULL)
  1490     return str;
  1491   else
  1492     sprintf(buf, INT64_FORMAT, n);
  1493   return buf;
  1496 void TypeLong::dump2( Dict &d, uint depth, outputStream *st ) const {
  1497   char buf[80], buf2[80];
  1498   if (_lo == min_jlong && _hi == max_jlong)
  1499     st->print("long");
  1500   else if (is_con())
  1501     st->print("long:%s", longname(buf, get_con()));
  1502   else if (_hi == max_jlong)
  1503     st->print("long:>=%s", longname(buf, _lo));
  1504   else if (_lo == min_jlong)
  1505     st->print("long:<=%s", longname(buf, _hi));
  1506   else
  1507     st->print("long:%s..%s", longname(buf, _lo), longname(buf2, _hi));
  1509   if (_widen != 0 && this != TypeLong::LONG)
  1510     st->print(":%.*s", _widen, "wwww");
  1512 #endif
  1514 //------------------------------singleton--------------------------------------
  1515 // TRUE if Type is a singleton type, FALSE otherwise.   Singletons are simple
  1516 // constants
  1517 bool TypeLong::singleton(void) const {
  1518   return _lo >= _hi;
  1521 bool TypeLong::empty(void) const {
  1522   return _lo > _hi;
  1525 //=============================================================================
  1526 // Convenience common pre-built types.
  1527 const TypeTuple *TypeTuple::IFBOTH;     // Return both arms of IF as reachable
  1528 const TypeTuple *TypeTuple::IFFALSE;
  1529 const TypeTuple *TypeTuple::IFTRUE;
  1530 const TypeTuple *TypeTuple::IFNEITHER;
  1531 const TypeTuple *TypeTuple::LOOPBODY;
  1532 const TypeTuple *TypeTuple::MEMBAR;
  1533 const TypeTuple *TypeTuple::STORECONDITIONAL;
  1534 const TypeTuple *TypeTuple::START_I2C;
  1535 const TypeTuple *TypeTuple::INT_PAIR;
  1536 const TypeTuple *TypeTuple::LONG_PAIR;
  1539 //------------------------------make-------------------------------------------
  1540 // Make a TypeTuple from the range of a method signature
  1541 const TypeTuple *TypeTuple::make_range(ciSignature* sig) {
  1542   ciType* return_type = sig->return_type();
  1543   uint total_fields = TypeFunc::Parms + return_type->size();
  1544   const Type **field_array = fields(total_fields);
  1545   switch (return_type->basic_type()) {
  1546   case T_LONG:
  1547     field_array[TypeFunc::Parms]   = TypeLong::LONG;
  1548     field_array[TypeFunc::Parms+1] = Type::HALF;
  1549     break;
  1550   case T_DOUBLE:
  1551     field_array[TypeFunc::Parms]   = Type::DOUBLE;
  1552     field_array[TypeFunc::Parms+1] = Type::HALF;
  1553     break;
  1554   case T_OBJECT:
  1555   case T_ARRAY:
  1556   case T_BOOLEAN:
  1557   case T_CHAR:
  1558   case T_FLOAT:
  1559   case T_BYTE:
  1560   case T_SHORT:
  1561   case T_INT:
  1562     field_array[TypeFunc::Parms] = get_const_type(return_type);
  1563     break;
  1564   case T_VOID:
  1565     break;
  1566   default:
  1567     ShouldNotReachHere();
  1569   return (TypeTuple*)(new TypeTuple(total_fields,field_array))->hashcons();
  1572 // Make a TypeTuple from the domain of a method signature
  1573 const TypeTuple *TypeTuple::make_domain(ciInstanceKlass* recv, ciSignature* sig) {
  1574   uint total_fields = TypeFunc::Parms + sig->size();
  1576   uint pos = TypeFunc::Parms;
  1577   const Type **field_array;
  1578   if (recv != NULL) {
  1579     total_fields++;
  1580     field_array = fields(total_fields);
  1581     // Use get_const_type here because it respects UseUniqueSubclasses:
  1582     field_array[pos++] = get_const_type(recv)->join(TypePtr::NOTNULL);
  1583   } else {
  1584     field_array = fields(total_fields);
  1587   int i = 0;
  1588   while (pos < total_fields) {
  1589     ciType* type = sig->type_at(i);
  1591     switch (type->basic_type()) {
  1592     case T_LONG:
  1593       field_array[pos++] = TypeLong::LONG;
  1594       field_array[pos++] = Type::HALF;
  1595       break;
  1596     case T_DOUBLE:
  1597       field_array[pos++] = Type::DOUBLE;
  1598       field_array[pos++] = Type::HALF;
  1599       break;
  1600     case T_OBJECT:
  1601     case T_ARRAY:
  1602     case T_BOOLEAN:
  1603     case T_CHAR:
  1604     case T_FLOAT:
  1605     case T_BYTE:
  1606     case T_SHORT:
  1607     case T_INT:
  1608       field_array[pos++] = get_const_type(type);
  1609       break;
  1610     default:
  1611       ShouldNotReachHere();
  1613     i++;
  1615   return (TypeTuple*)(new TypeTuple(total_fields,field_array))->hashcons();
  1618 const TypeTuple *TypeTuple::make( uint cnt, const Type **fields ) {
  1619   return (TypeTuple*)(new TypeTuple(cnt,fields))->hashcons();
  1622 //------------------------------fields-----------------------------------------
  1623 // Subroutine call type with space allocated for argument types
  1624 const Type **TypeTuple::fields( uint arg_cnt ) {
  1625   const Type **flds = (const Type **)(Compile::current()->type_arena()->Amalloc_4((TypeFunc::Parms+arg_cnt)*sizeof(Type*) ));
  1626   flds[TypeFunc::Control  ] = Type::CONTROL;
  1627   flds[TypeFunc::I_O      ] = Type::ABIO;
  1628   flds[TypeFunc::Memory   ] = Type::MEMORY;
  1629   flds[TypeFunc::FramePtr ] = TypeRawPtr::BOTTOM;
  1630   flds[TypeFunc::ReturnAdr] = Type::RETURN_ADDRESS;
  1632   return flds;
  1635 //------------------------------meet-------------------------------------------
  1636 // Compute the MEET of two types.  It returns a new Type object.
  1637 const Type *TypeTuple::xmeet( const Type *t ) const {
  1638   // Perform a fast test for common case; meeting the same types together.
  1639   if( this == t ) return this;  // Meeting same type-rep?
  1641   // Current "this->_base" is Tuple
  1642   switch (t->base()) {          // switch on original type
  1644   case Bottom:                  // Ye Olde Default
  1645     return t;
  1647   default:                      // All else is a mistake
  1648     typerr(t);
  1650   case Tuple: {                 // Meeting 2 signatures?
  1651     const TypeTuple *x = t->is_tuple();
  1652     assert( _cnt == x->_cnt, "" );
  1653     const Type **fields = (const Type **)(Compile::current()->type_arena()->Amalloc_4( _cnt*sizeof(Type*) ));
  1654     for( uint i=0; i<_cnt; i++ )
  1655       fields[i] = field_at(i)->xmeet( x->field_at(i) );
  1656     return TypeTuple::make(_cnt,fields);
  1658   case Top:
  1659     break;
  1661   return this;                  // Return the double constant
  1664 //------------------------------xdual------------------------------------------
  1665 // Dual: compute field-by-field dual
  1666 const Type *TypeTuple::xdual() const {
  1667   const Type **fields = (const Type **)(Compile::current()->type_arena()->Amalloc_4( _cnt*sizeof(Type*) ));
  1668   for( uint i=0; i<_cnt; i++ )
  1669     fields[i] = _fields[i]->dual();
  1670   return new TypeTuple(_cnt,fields);
  1673 //------------------------------eq---------------------------------------------
  1674 // Structural equality check for Type representations
  1675 bool TypeTuple::eq( const Type *t ) const {
  1676   const TypeTuple *s = (const TypeTuple *)t;
  1677   if (_cnt != s->_cnt)  return false;  // Unequal field counts
  1678   for (uint i = 0; i < _cnt; i++)
  1679     if (field_at(i) != s->field_at(i)) // POINTER COMPARE!  NO RECURSION!
  1680       return false;             // Missed
  1681   return true;
  1684 //------------------------------hash-------------------------------------------
  1685 // Type-specific hashing function.
  1686 int TypeTuple::hash(void) const {
  1687   intptr_t sum = _cnt;
  1688   for( uint i=0; i<_cnt; i++ )
  1689     sum += (intptr_t)_fields[i];     // Hash on pointers directly
  1690   return sum;
  1693 //------------------------------dump2------------------------------------------
  1694 // Dump signature Type
  1695 #ifndef PRODUCT
  1696 void TypeTuple::dump2( Dict &d, uint depth, outputStream *st ) const {
  1697   st->print("{");
  1698   if( !depth || d[this] ) {     // Check for recursive print
  1699     st->print("...}");
  1700     return;
  1702   d.Insert((void*)this, (void*)this);   // Stop recursion
  1703   if( _cnt ) {
  1704     uint i;
  1705     for( i=0; i<_cnt-1; i++ ) {
  1706       st->print("%d:", i);
  1707       _fields[i]->dump2(d, depth-1, st);
  1708       st->print(", ");
  1710     st->print("%d:", i);
  1711     _fields[i]->dump2(d, depth-1, st);
  1713   st->print("}");
  1715 #endif
  1717 //------------------------------singleton--------------------------------------
  1718 // TRUE if Type is a singleton type, FALSE otherwise.   Singletons are simple
  1719 // constants (Ldi nodes).  Singletons are integer, float or double constants
  1720 // or a single symbol.
  1721 bool TypeTuple::singleton(void) const {
  1722   return false;                 // Never a singleton
  1725 bool TypeTuple::empty(void) const {
  1726   for( uint i=0; i<_cnt; i++ ) {
  1727     if (_fields[i]->empty())  return true;
  1729   return false;
  1732 //=============================================================================
  1733 // Convenience common pre-built types.
  1735 inline const TypeInt* normalize_array_size(const TypeInt* size) {
  1736   // Certain normalizations keep us sane when comparing types.
  1737   // We do not want arrayOop variables to differ only by the wideness
  1738   // of their index types.  Pick minimum wideness, since that is the
  1739   // forced wideness of small ranges anyway.
  1740   if (size->_widen != Type::WidenMin)
  1741     return TypeInt::make(size->_lo, size->_hi, Type::WidenMin);
  1742   else
  1743     return size;
  1746 //------------------------------make-------------------------------------------
  1747 const TypeAry *TypeAry::make( const Type *elem, const TypeInt *size) {
  1748   if (UseCompressedOops && elem->isa_oopptr()) {
  1749     elem = elem->make_narrowoop();
  1751   size = normalize_array_size(size);
  1752   return (TypeAry*)(new TypeAry(elem,size))->hashcons();
  1755 //------------------------------meet-------------------------------------------
  1756 // Compute the MEET of two types.  It returns a new Type object.
  1757 const Type *TypeAry::xmeet( const Type *t ) const {
  1758   // Perform a fast test for common case; meeting the same types together.
  1759   if( this == t ) return this;  // Meeting same type-rep?
  1761   // Current "this->_base" is Ary
  1762   switch (t->base()) {          // switch on original type
  1764   case Bottom:                  // Ye Olde Default
  1765     return t;
  1767   default:                      // All else is a mistake
  1768     typerr(t);
  1770   case Array: {                 // Meeting 2 arrays?
  1771     const TypeAry *a = t->is_ary();
  1772     return TypeAry::make(_elem->meet(a->_elem),
  1773                          _size->xmeet(a->_size)->is_int());
  1775   case Top:
  1776     break;
  1778   return this;                  // Return the double constant
  1781 //------------------------------xdual------------------------------------------
  1782 // Dual: compute field-by-field dual
  1783 const Type *TypeAry::xdual() const {
  1784   const TypeInt* size_dual = _size->dual()->is_int();
  1785   size_dual = normalize_array_size(size_dual);
  1786   return new TypeAry( _elem->dual(), size_dual);
  1789 //------------------------------eq---------------------------------------------
  1790 // Structural equality check for Type representations
  1791 bool TypeAry::eq( const Type *t ) const {
  1792   const TypeAry *a = (const TypeAry*)t;
  1793   return _elem == a->_elem &&
  1794     _size == a->_size;
  1797 //------------------------------hash-------------------------------------------
  1798 // Type-specific hashing function.
  1799 int TypeAry::hash(void) const {
  1800   return (intptr_t)_elem + (intptr_t)_size;
  1803 //------------------------------dump2------------------------------------------
  1804 #ifndef PRODUCT
  1805 void TypeAry::dump2( Dict &d, uint depth, outputStream *st ) const {
  1806   _elem->dump2(d, depth, st);
  1807   st->print("[");
  1808   _size->dump2(d, depth, st);
  1809   st->print("]");
  1811 #endif
  1813 //------------------------------singleton--------------------------------------
  1814 // TRUE if Type is a singleton type, FALSE otherwise.   Singletons are simple
  1815 // constants (Ldi nodes).  Singletons are integer, float or double constants
  1816 // or a single symbol.
  1817 bool TypeAry::singleton(void) const {
  1818   return false;                 // Never a singleton
  1821 bool TypeAry::empty(void) const {
  1822   return _elem->empty() || _size->empty();
  1825 //--------------------------ary_must_be_exact----------------------------------
  1826 bool TypeAry::ary_must_be_exact() const {
  1827   if (!UseExactTypes)       return false;
  1828   // This logic looks at the element type of an array, and returns true
  1829   // if the element type is either a primitive or a final instance class.
  1830   // In such cases, an array built on this ary must have no subclasses.
  1831   if (_elem == BOTTOM)      return false;  // general array not exact
  1832   if (_elem == TOP   )      return false;  // inverted general array not exact
  1833   const TypeOopPtr*  toop = NULL;
  1834   if (UseCompressedOops && _elem->isa_narrowoop()) {
  1835     toop = _elem->make_ptr()->isa_oopptr();
  1836   } else {
  1837     toop = _elem->isa_oopptr();
  1839   if (!toop)                return true;   // a primitive type, like int
  1840   ciKlass* tklass = toop->klass();
  1841   if (tklass == NULL)       return false;  // unloaded class
  1842   if (!tklass->is_loaded()) return false;  // unloaded class
  1843   const TypeInstPtr* tinst;
  1844   if (_elem->isa_narrowoop())
  1845     tinst = _elem->make_ptr()->isa_instptr();
  1846   else
  1847     tinst = _elem->isa_instptr();
  1848   if (tinst)
  1849     return tklass->as_instance_klass()->is_final();
  1850   const TypeAryPtr*  tap;
  1851   if (_elem->isa_narrowoop())
  1852     tap = _elem->make_ptr()->isa_aryptr();
  1853   else
  1854     tap = _elem->isa_aryptr();
  1855   if (tap)
  1856     return tap->ary()->ary_must_be_exact();
  1857   return false;
  1860 //=============================================================================
  1861 // Convenience common pre-built types.
  1862 const TypePtr *TypePtr::NULL_PTR;
  1863 const TypePtr *TypePtr::NOTNULL;
  1864 const TypePtr *TypePtr::BOTTOM;
  1866 //------------------------------meet-------------------------------------------
  1867 // Meet over the PTR enum
  1868 const TypePtr::PTR TypePtr::ptr_meet[TypePtr::lastPTR][TypePtr::lastPTR] = {
  1869   //              TopPTR,    AnyNull,   Constant, Null,   NotNull, BotPTR,
  1870   { /* Top     */ TopPTR,    AnyNull,   Constant, Null,   NotNull, BotPTR,},
  1871   { /* AnyNull */ AnyNull,   AnyNull,   Constant, BotPTR, NotNull, BotPTR,},
  1872   { /* Constant*/ Constant,  Constant,  Constant, BotPTR, NotNull, BotPTR,},
  1873   { /* Null    */ Null,      BotPTR,    BotPTR,   Null,   BotPTR,  BotPTR,},
  1874   { /* NotNull */ NotNull,   NotNull,   NotNull,  BotPTR, NotNull, BotPTR,},
  1875   { /* BotPTR  */ BotPTR,    BotPTR,    BotPTR,   BotPTR, BotPTR,  BotPTR,}
  1876 };
  1878 //------------------------------make-------------------------------------------
  1879 const TypePtr *TypePtr::make( TYPES t, enum PTR ptr, int offset ) {
  1880   return (TypePtr*)(new TypePtr(t,ptr,offset))->hashcons();
  1883 //------------------------------cast_to_ptr_type-------------------------------
  1884 const Type *TypePtr::cast_to_ptr_type(PTR ptr) const {
  1885   assert(_base == AnyPtr, "subclass must override cast_to_ptr_type");
  1886   if( ptr == _ptr ) return this;
  1887   return make(_base, ptr, _offset);
  1890 //------------------------------get_con----------------------------------------
  1891 intptr_t TypePtr::get_con() const {
  1892   assert( _ptr == Null, "" );
  1893   return _offset;
  1896 //------------------------------meet-------------------------------------------
  1897 // Compute the MEET of two types.  It returns a new Type object.
  1898 const Type *TypePtr::xmeet( const Type *t ) const {
  1899   // Perform a fast test for common case; meeting the same types together.
  1900   if( this == t ) return this;  // Meeting same type-rep?
  1902   // Current "this->_base" is AnyPtr
  1903   switch (t->base()) {          // switch on original type
  1904   case Int:                     // Mixing ints & oops happens when javac
  1905   case Long:                    // reuses local variables
  1906   case FloatTop:
  1907   case FloatCon:
  1908   case FloatBot:
  1909   case DoubleTop:
  1910   case DoubleCon:
  1911   case DoubleBot:
  1912   case NarrowOop:
  1913   case Bottom:                  // Ye Olde Default
  1914     return Type::BOTTOM;
  1915   case Top:
  1916     return this;
  1918   case AnyPtr: {                // Meeting to AnyPtrs
  1919     const TypePtr *tp = t->is_ptr();
  1920     return make( AnyPtr, meet_ptr(tp->ptr()), meet_offset(tp->offset()) );
  1922   case RawPtr:                  // For these, flip the call around to cut down
  1923   case OopPtr:
  1924   case InstPtr:                 // on the cases I have to handle.
  1925   case KlassPtr:
  1926   case AryPtr:
  1927     return t->xmeet(this);      // Call in reverse direction
  1928   default:                      // All else is a mistake
  1929     typerr(t);
  1932   return this;
  1935 //------------------------------meet_offset------------------------------------
  1936 int TypePtr::meet_offset( int offset ) const {
  1937   // Either is 'TOP' offset?  Return the other offset!
  1938   if( _offset == OffsetTop ) return offset;
  1939   if( offset == OffsetTop ) return _offset;
  1940   // If either is different, return 'BOTTOM' offset
  1941   if( _offset != offset ) return OffsetBot;
  1942   return _offset;
  1945 //------------------------------dual_offset------------------------------------
  1946 int TypePtr::dual_offset( ) const {
  1947   if( _offset == OffsetTop ) return OffsetBot;// Map 'TOP' into 'BOTTOM'
  1948   if( _offset == OffsetBot ) return OffsetTop;// Map 'BOTTOM' into 'TOP'
  1949   return _offset;               // Map everything else into self
  1952 //------------------------------xdual------------------------------------------
  1953 // Dual: compute field-by-field dual
  1954 const TypePtr::PTR TypePtr::ptr_dual[TypePtr::lastPTR] = {
  1955   BotPTR, NotNull, Constant, Null, AnyNull, TopPTR
  1956 };
  1957 const Type *TypePtr::xdual() const {
  1958   return new TypePtr( AnyPtr, dual_ptr(), dual_offset() );
  1961 //------------------------------xadd_offset------------------------------------
  1962 int TypePtr::xadd_offset( intptr_t offset ) const {
  1963   // Adding to 'TOP' offset?  Return 'TOP'!
  1964   if( _offset == OffsetTop || offset == OffsetTop ) return OffsetTop;
  1965   // Adding to 'BOTTOM' offset?  Return 'BOTTOM'!
  1966   if( _offset == OffsetBot || offset == OffsetBot ) return OffsetBot;
  1967   // Addition overflows or "accidentally" equals to OffsetTop? Return 'BOTTOM'!
  1968   offset += (intptr_t)_offset;
  1969   if (offset != (int)offset || offset == OffsetTop) return OffsetBot;
  1971   // assert( _offset >= 0 && _offset+offset >= 0, "" );
  1972   // It is possible to construct a negative offset during PhaseCCP
  1974   return (int)offset;        // Sum valid offsets
  1977 //------------------------------add_offset-------------------------------------
  1978 const TypePtr *TypePtr::add_offset( intptr_t offset ) const {
  1979   return make( AnyPtr, _ptr, xadd_offset(offset) );
  1982 //------------------------------eq---------------------------------------------
  1983 // Structural equality check for Type representations
  1984 bool TypePtr::eq( const Type *t ) const {
  1985   const TypePtr *a = (const TypePtr*)t;
  1986   return _ptr == a->ptr() && _offset == a->offset();
  1989 //------------------------------hash-------------------------------------------
  1990 // Type-specific hashing function.
  1991 int TypePtr::hash(void) const {
  1992   return _ptr + _offset;
  1995 //------------------------------dump2------------------------------------------
  1996 const char *const TypePtr::ptr_msg[TypePtr::lastPTR] = {
  1997   "TopPTR","AnyNull","Constant","NULL","NotNull","BotPTR"
  1998 };
  2000 #ifndef PRODUCT
  2001 void TypePtr::dump2( Dict &d, uint depth, outputStream *st ) const {
  2002   if( _ptr == Null ) st->print("NULL");
  2003   else st->print("%s *", ptr_msg[_ptr]);
  2004   if( _offset == OffsetTop ) st->print("+top");
  2005   else if( _offset == OffsetBot ) st->print("+bot");
  2006   else if( _offset ) st->print("+%d", _offset);
  2008 #endif
  2010 //------------------------------singleton--------------------------------------
  2011 // TRUE if Type is a singleton type, FALSE otherwise.   Singletons are simple
  2012 // constants
  2013 bool TypePtr::singleton(void) const {
  2014   // TopPTR, Null, AnyNull, Constant are all singletons
  2015   return (_offset != OffsetBot) && !below_centerline(_ptr);
  2018 bool TypePtr::empty(void) const {
  2019   return (_offset == OffsetTop) || above_centerline(_ptr);
  2022 //=============================================================================
  2023 // Convenience common pre-built types.
  2024 const TypeRawPtr *TypeRawPtr::BOTTOM;
  2025 const TypeRawPtr *TypeRawPtr::NOTNULL;
  2027 //------------------------------make-------------------------------------------
  2028 const TypeRawPtr *TypeRawPtr::make( enum PTR ptr ) {
  2029   assert( ptr != Constant, "what is the constant?" );
  2030   assert( ptr != Null, "Use TypePtr for NULL" );
  2031   return (TypeRawPtr*)(new TypeRawPtr(ptr,0))->hashcons();
  2034 const TypeRawPtr *TypeRawPtr::make( address bits ) {
  2035   assert( bits, "Use TypePtr for NULL" );
  2036   return (TypeRawPtr*)(new TypeRawPtr(Constant,bits))->hashcons();
  2039 //------------------------------cast_to_ptr_type-------------------------------
  2040 const Type *TypeRawPtr::cast_to_ptr_type(PTR ptr) const {
  2041   assert( ptr != Constant, "what is the constant?" );
  2042   assert( ptr != Null, "Use TypePtr for NULL" );
  2043   assert( _bits==0, "Why cast a constant address?");
  2044   if( ptr == _ptr ) return this;
  2045   return make(ptr);
  2048 //------------------------------get_con----------------------------------------
  2049 intptr_t TypeRawPtr::get_con() const {
  2050   assert( _ptr == Null || _ptr == Constant, "" );
  2051   return (intptr_t)_bits;
  2054 //------------------------------meet-------------------------------------------
  2055 // Compute the MEET of two types.  It returns a new Type object.
  2056 const Type *TypeRawPtr::xmeet( const Type *t ) const {
  2057   // Perform a fast test for common case; meeting the same types together.
  2058   if( this == t ) return this;  // Meeting same type-rep?
  2060   // Current "this->_base" is RawPtr
  2061   switch( t->base() ) {         // switch on original type
  2062   case Bottom:                  // Ye Olde Default
  2063     return t;
  2064   case Top:
  2065     return this;
  2066   case AnyPtr:                  // Meeting to AnyPtrs
  2067     break;
  2068   case RawPtr: {                // might be top, bot, any/not or constant
  2069     enum PTR tptr = t->is_ptr()->ptr();
  2070     enum PTR ptr = meet_ptr( tptr );
  2071     if( ptr == Constant ) {     // Cannot be equal constants, so...
  2072       if( tptr == Constant && _ptr != Constant)  return t;
  2073       if( _ptr == Constant && tptr != Constant)  return this;
  2074       ptr = NotNull;            // Fall down in lattice
  2076     return make( ptr );
  2079   case OopPtr:
  2080   case InstPtr:
  2081   case KlassPtr:
  2082   case AryPtr:
  2083     return TypePtr::BOTTOM;     // Oop meet raw is not well defined
  2084   default:                      // All else is a mistake
  2085     typerr(t);
  2088   // Found an AnyPtr type vs self-RawPtr type
  2089   const TypePtr *tp = t->is_ptr();
  2090   switch (tp->ptr()) {
  2091   case TypePtr::TopPTR:  return this;
  2092   case TypePtr::BotPTR:  return t;
  2093   case TypePtr::Null:
  2094     if( _ptr == TypePtr::TopPTR ) return t;
  2095     return TypeRawPtr::BOTTOM;
  2096   case TypePtr::NotNull: return TypePtr::make( AnyPtr, meet_ptr(TypePtr::NotNull), tp->meet_offset(0) );
  2097   case TypePtr::AnyNull:
  2098     if( _ptr == TypePtr::Constant) return this;
  2099     return make( meet_ptr(TypePtr::AnyNull) );
  2100   default: ShouldNotReachHere();
  2102   return this;
  2105 //------------------------------xdual------------------------------------------
  2106 // Dual: compute field-by-field dual
  2107 const Type *TypeRawPtr::xdual() const {
  2108   return new TypeRawPtr( dual_ptr(), _bits );
  2111 //------------------------------add_offset-------------------------------------
  2112 const TypePtr *TypeRawPtr::add_offset( intptr_t offset ) const {
  2113   if( offset == OffsetTop ) return BOTTOM; // Undefined offset-> undefined pointer
  2114   if( offset == OffsetBot ) return BOTTOM; // Unknown offset-> unknown pointer
  2115   if( offset == 0 ) return this; // No change
  2116   switch (_ptr) {
  2117   case TypePtr::TopPTR:
  2118   case TypePtr::BotPTR:
  2119   case TypePtr::NotNull:
  2120     return this;
  2121   case TypePtr::Null:
  2122   case TypePtr::Constant:
  2123     return make( _bits+offset );
  2124   default:  ShouldNotReachHere();
  2126   return NULL;                  // Lint noise
  2129 //------------------------------eq---------------------------------------------
  2130 // Structural equality check for Type representations
  2131 bool TypeRawPtr::eq( const Type *t ) const {
  2132   const TypeRawPtr *a = (const TypeRawPtr*)t;
  2133   return _bits == a->_bits && TypePtr::eq(t);
  2136 //------------------------------hash-------------------------------------------
  2137 // Type-specific hashing function.
  2138 int TypeRawPtr::hash(void) const {
  2139   return (intptr_t)_bits + TypePtr::hash();
  2142 //------------------------------dump2------------------------------------------
  2143 #ifndef PRODUCT
  2144 void TypeRawPtr::dump2( Dict &d, uint depth, outputStream *st ) const {
  2145   if( _ptr == Constant )
  2146     st->print(INTPTR_FORMAT, _bits);
  2147   else
  2148     st->print("rawptr:%s", ptr_msg[_ptr]);
  2150 #endif
  2152 //=============================================================================
  2153 // Convenience common pre-built type.
  2154 const TypeOopPtr *TypeOopPtr::BOTTOM;
  2156 //------------------------------TypeOopPtr-------------------------------------
  2157 TypeOopPtr::TypeOopPtr( TYPES t, PTR ptr, ciKlass* k, bool xk, ciObject* o, int offset, int instance_id )
  2158   : TypePtr(t, ptr, offset),
  2159     _const_oop(o), _klass(k),
  2160     _klass_is_exact(xk),
  2161     _is_ptr_to_narrowoop(false),
  2162     _instance_id(instance_id) {
  2163 #ifdef _LP64
  2164   if (UseCompressedOops && _offset != 0) {
  2165     if (klass() == NULL) {
  2166       assert(this->isa_aryptr(), "only arrays without klass");
  2167       _is_ptr_to_narrowoop = true;
  2168     } else if (_offset == oopDesc::klass_offset_in_bytes()) {
  2169       _is_ptr_to_narrowoop = true;
  2170     } else if (this->isa_aryptr()) {
  2171       _is_ptr_to_narrowoop = (klass()->is_obj_array_klass() &&
  2172                              _offset != arrayOopDesc::length_offset_in_bytes());
  2173     } else if (klass() == ciEnv::current()->Class_klass() &&
  2174                (_offset == java_lang_Class::klass_offset_in_bytes() ||
  2175                 _offset == java_lang_Class::array_klass_offset_in_bytes())) {
  2176       // Special hidden fields from the Class.
  2177       assert(this->isa_instptr(), "must be an instance ptr.");
  2178       _is_ptr_to_narrowoop = true;
  2179     } else if (klass()->is_instance_klass()) {
  2180       ciInstanceKlass* ik = klass()->as_instance_klass();
  2181       ciField* field = NULL;
  2182       if (this->isa_klassptr()) {
  2183         // Perm objects don't use compressed references, except for
  2184         // static fields which are currently compressed.
  2185         field = ik->get_field_by_offset(_offset, true);
  2186         if (field != NULL) {
  2187           BasicType basic_elem_type = field->layout_type();
  2188           _is_ptr_to_narrowoop = (basic_elem_type == T_OBJECT ||
  2189                                   basic_elem_type == T_ARRAY);
  2191       } else if (_offset == OffsetBot || _offset == OffsetTop) {
  2192         // unsafe access
  2193         _is_ptr_to_narrowoop = true;
  2194       } else { // exclude unsafe ops
  2195         assert(this->isa_instptr(), "must be an instance ptr.");
  2196         // Field which contains a compressed oop references.
  2197         field = ik->get_field_by_offset(_offset, false);
  2198         if (field != NULL) {
  2199           BasicType basic_elem_type = field->layout_type();
  2200           _is_ptr_to_narrowoop = (basic_elem_type == T_OBJECT ||
  2201                                   basic_elem_type == T_ARRAY);
  2202         } else if (klass()->equals(ciEnv::current()->Object_klass())) {
  2203           // Compile::find_alias_type() cast exactness on all types to verify
  2204           // that it does not affect alias type.
  2205           _is_ptr_to_narrowoop = true;
  2206         } else {
  2207           // Type for the copy start in LibraryCallKit::inline_native_clone().
  2208           assert(!klass_is_exact(), "only non-exact klass");
  2209           _is_ptr_to_narrowoop = true;
  2214 #endif
  2217 //------------------------------make-------------------------------------------
  2218 const TypeOopPtr *TypeOopPtr::make(PTR ptr,
  2219                                    int offset) {
  2220   assert(ptr != Constant, "no constant generic pointers");
  2221   ciKlass*  k = ciKlassKlass::make();
  2222   bool      xk = false;
  2223   ciObject* o = NULL;
  2224   return (TypeOopPtr*)(new TypeOopPtr(OopPtr, ptr, k, xk, o, offset, InstanceBot))->hashcons();
  2228 //------------------------------cast_to_ptr_type-------------------------------
  2229 const Type *TypeOopPtr::cast_to_ptr_type(PTR ptr) const {
  2230   assert(_base == OopPtr, "subclass must override cast_to_ptr_type");
  2231   if( ptr == _ptr ) return this;
  2232   return make(ptr, _offset);
  2235 //-----------------------------cast_to_instance_id----------------------------
  2236 const TypeOopPtr *TypeOopPtr::cast_to_instance_id(int instance_id) const {
  2237   // There are no instances of a general oop.
  2238   // Return self unchanged.
  2239   return this;
  2242 //-----------------------------cast_to_exactness-------------------------------
  2243 const Type *TypeOopPtr::cast_to_exactness(bool klass_is_exact) const {
  2244   // There is no such thing as an exact general oop.
  2245   // Return self unchanged.
  2246   return this;
  2250 //------------------------------as_klass_type----------------------------------
  2251 // Return the klass type corresponding to this instance or array type.
  2252 // It is the type that is loaded from an object of this type.
  2253 const TypeKlassPtr* TypeOopPtr::as_klass_type() const {
  2254   ciKlass* k = klass();
  2255   bool    xk = klass_is_exact();
  2256   if (k == NULL || !k->is_java_klass())
  2257     return TypeKlassPtr::OBJECT;
  2258   else
  2259     return TypeKlassPtr::make(xk? Constant: NotNull, k, 0);
  2263 //------------------------------meet-------------------------------------------
  2264 // Compute the MEET of two types.  It returns a new Type object.
  2265 const Type *TypeOopPtr::xmeet( const Type *t ) const {
  2266   // Perform a fast test for common case; meeting the same types together.
  2267   if( this == t ) return this;  // Meeting same type-rep?
  2269   // Current "this->_base" is OopPtr
  2270   switch (t->base()) {          // switch on original type
  2272   case Int:                     // Mixing ints & oops happens when javac
  2273   case Long:                    // reuses local variables
  2274   case FloatTop:
  2275   case FloatCon:
  2276   case FloatBot:
  2277   case DoubleTop:
  2278   case DoubleCon:
  2279   case DoubleBot:
  2280   case NarrowOop:
  2281   case Bottom:                  // Ye Olde Default
  2282     return Type::BOTTOM;
  2283   case Top:
  2284     return this;
  2286   default:                      // All else is a mistake
  2287     typerr(t);
  2289   case RawPtr:
  2290     return TypePtr::BOTTOM;     // Oop meet raw is not well defined
  2292   case AnyPtr: {
  2293     // Found an AnyPtr type vs self-OopPtr type
  2294     const TypePtr *tp = t->is_ptr();
  2295     int offset = meet_offset(tp->offset());
  2296     PTR ptr = meet_ptr(tp->ptr());
  2297     switch (tp->ptr()) {
  2298     case Null:
  2299       if (ptr == Null)  return TypePtr::make(AnyPtr, ptr, offset);
  2300       // else fall through:
  2301     case TopPTR:
  2302     case AnyNull:
  2303       return make(ptr, offset);
  2304     case BotPTR:
  2305     case NotNull:
  2306       return TypePtr::make(AnyPtr, ptr, offset);
  2307     default: typerr(t);
  2311   case OopPtr: {                 // Meeting to other OopPtrs
  2312     const TypeOopPtr *tp = t->is_oopptr();
  2313     return make( meet_ptr(tp->ptr()), meet_offset(tp->offset()) );
  2316   case InstPtr:                  // For these, flip the call around to cut down
  2317   case KlassPtr:                 // on the cases I have to handle.
  2318   case AryPtr:
  2319     return t->xmeet(this);      // Call in reverse direction
  2321   } // End of switch
  2322   return this;                  // Return the double constant
  2326 //------------------------------xdual------------------------------------------
  2327 // Dual of a pure heap pointer.  No relevant klass or oop information.
  2328 const Type *TypeOopPtr::xdual() const {
  2329   assert(klass() == ciKlassKlass::make(), "no klasses here");
  2330   assert(const_oop() == NULL,             "no constants here");
  2331   return new TypeOopPtr(_base, dual_ptr(), klass(), klass_is_exact(), const_oop(), dual_offset(), dual_instance_id()  );
  2334 //--------------------------make_from_klass_common-----------------------------
  2335 // Computes the element-type given a klass.
  2336 const TypeOopPtr* TypeOopPtr::make_from_klass_common(ciKlass *klass, bool klass_change, bool try_for_exact) {
  2337   assert(klass->is_java_klass(), "must be java language klass");
  2338   if (klass->is_instance_klass()) {
  2339     Compile* C = Compile::current();
  2340     Dependencies* deps = C->dependencies();
  2341     assert((deps != NULL) == (C->method() != NULL && C->method()->code_size() > 0), "sanity");
  2342     // Element is an instance
  2343     bool klass_is_exact = false;
  2344     if (klass->is_loaded()) {
  2345       // Try to set klass_is_exact.
  2346       ciInstanceKlass* ik = klass->as_instance_klass();
  2347       klass_is_exact = ik->is_final();
  2348       if (!klass_is_exact && klass_change
  2349           && deps != NULL && UseUniqueSubclasses) {
  2350         ciInstanceKlass* sub = ik->unique_concrete_subklass();
  2351         if (sub != NULL) {
  2352           deps->assert_abstract_with_unique_concrete_subtype(ik, sub);
  2353           klass = ik = sub;
  2354           klass_is_exact = sub->is_final();
  2357       if (!klass_is_exact && try_for_exact
  2358           && deps != NULL && UseExactTypes) {
  2359         if (!ik->is_interface() && !ik->has_subklass()) {
  2360           // Add a dependence; if concrete subclass added we need to recompile
  2361           deps->assert_leaf_type(ik);
  2362           klass_is_exact = true;
  2366     return TypeInstPtr::make(TypePtr::BotPTR, klass, klass_is_exact, NULL, 0);
  2367   } else if (klass->is_obj_array_klass()) {
  2368     // Element is an object array. Recursively call ourself.
  2369     const TypeOopPtr *etype = TypeOopPtr::make_from_klass_common(klass->as_obj_array_klass()->element_klass(), false, try_for_exact);
  2370     bool xk = etype->klass_is_exact();
  2371     const TypeAry* arr0 = TypeAry::make(etype, TypeInt::POS);
  2372     // We used to pass NotNull in here, asserting that the sub-arrays
  2373     // are all not-null.  This is not true in generally, as code can
  2374     // slam NULLs down in the subarrays.
  2375     const TypeAryPtr* arr = TypeAryPtr::make(TypePtr::BotPTR, arr0, klass, xk, 0);
  2376     return arr;
  2377   } else if (klass->is_type_array_klass()) {
  2378     // Element is an typeArray
  2379     const Type* etype = get_const_basic_type(klass->as_type_array_klass()->element_type());
  2380     const TypeAry* arr0 = TypeAry::make(etype, TypeInt::POS);
  2381     // We used to pass NotNull in here, asserting that the array pointer
  2382     // is not-null. That was not true in general.
  2383     const TypeAryPtr* arr = TypeAryPtr::make(TypePtr::BotPTR, arr0, klass, true, 0);
  2384     return arr;
  2385   } else {
  2386     ShouldNotReachHere();
  2387     return NULL;
  2391 //------------------------------make_from_constant-----------------------------
  2392 // Make a java pointer from an oop constant
  2393 const TypeOopPtr* TypeOopPtr::make_from_constant(ciObject* o) {
  2394   if (o->is_method_data() || o->is_method()) {
  2395     // Treat much like a typeArray of bytes, like below, but fake the type...
  2396     assert(o->has_encoding(), "must be a perm space object");
  2397     const Type* etype = (Type*)get_const_basic_type(T_BYTE);
  2398     const TypeAry* arr0 = TypeAry::make(etype, TypeInt::POS);
  2399     ciKlass *klass = ciTypeArrayKlass::make((BasicType) T_BYTE);
  2400     assert(o->has_encoding(), "method data oops should be tenured");
  2401     const TypeAryPtr* arr = TypeAryPtr::make(TypePtr::Constant, o, arr0, klass, true, 0);
  2402     return arr;
  2403   } else {
  2404     assert(o->is_java_object(), "must be java language object");
  2405     assert(!o->is_null_object(), "null object not yet handled here.");
  2406     ciKlass *klass = o->klass();
  2407     if (klass->is_instance_klass()) {
  2408       // Element is an instance
  2409       if (!o->has_encoding()) {  // not a perm-space constant
  2410         // %%% remove this restriction by rewriting non-perm ConPNodes in a later phase
  2411         return TypeInstPtr::make(TypePtr::NotNull, klass, true, NULL, 0);
  2413       return TypeInstPtr::make(o);
  2414     } else if (klass->is_obj_array_klass()) {
  2415       // Element is an object array. Recursively call ourself.
  2416       const Type *etype =
  2417         TypeOopPtr::make_from_klass_raw(klass->as_obj_array_klass()->element_klass());
  2418       const TypeAry* arr0 = TypeAry::make(etype, TypeInt::make(o->as_array()->length()));
  2419       // We used to pass NotNull in here, asserting that the sub-arrays
  2420       // are all not-null.  This is not true in generally, as code can
  2421       // slam NULLs down in the subarrays.
  2422       if (!o->has_encoding()) {  // not a perm-space constant
  2423         // %%% remove this restriction by rewriting non-perm ConPNodes in a later phase
  2424         return TypeAryPtr::make(TypePtr::NotNull, arr0, klass, true, 0);
  2426       const TypeAryPtr* arr = TypeAryPtr::make(TypePtr::Constant, o, arr0, klass, true, 0);
  2427       return arr;
  2428     } else if (klass->is_type_array_klass()) {
  2429       // Element is an typeArray
  2430       const Type* etype =
  2431         (Type*)get_const_basic_type(klass->as_type_array_klass()->element_type());
  2432       const TypeAry* arr0 = TypeAry::make(etype, TypeInt::make(o->as_array()->length()));
  2433       // We used to pass NotNull in here, asserting that the array pointer
  2434       // is not-null. That was not true in general.
  2435       if (!o->has_encoding()) {  // not a perm-space constant
  2436         // %%% remove this restriction by rewriting non-perm ConPNodes in a later phase
  2437         return TypeAryPtr::make(TypePtr::NotNull, arr0, klass, true, 0);
  2439       const TypeAryPtr* arr = TypeAryPtr::make(TypePtr::Constant, o, arr0, klass, true, 0);
  2440       return arr;
  2444   ShouldNotReachHere();
  2445   return NULL;
  2448 //------------------------------get_con----------------------------------------
  2449 intptr_t TypeOopPtr::get_con() const {
  2450   assert( _ptr == Null || _ptr == Constant, "" );
  2451   assert( _offset >= 0, "" );
  2453   if (_offset != 0) {
  2454     // After being ported to the compiler interface, the compiler no longer
  2455     // directly manipulates the addresses of oops.  Rather, it only has a pointer
  2456     // to a handle at compile time.  This handle is embedded in the generated
  2457     // code and dereferenced at the time the nmethod is made.  Until that time,
  2458     // it is not reasonable to do arithmetic with the addresses of oops (we don't
  2459     // have access to the addresses!).  This does not seem to currently happen,
  2460     // but this assertion here is to help prevent its occurence.
  2461     tty->print_cr("Found oop constant with non-zero offset");
  2462     ShouldNotReachHere();
  2465   return (intptr_t)const_oop()->encoding();
  2469 //-----------------------------filter------------------------------------------
  2470 // Do not allow interface-vs.-noninterface joins to collapse to top.
  2471 const Type *TypeOopPtr::filter( const Type *kills ) const {
  2473   const Type* ft = join(kills);
  2474   const TypeInstPtr* ftip = ft->isa_instptr();
  2475   const TypeInstPtr* ktip = kills->isa_instptr();
  2476   const TypeKlassPtr* ftkp = ft->isa_klassptr();
  2477   const TypeKlassPtr* ktkp = kills->isa_klassptr();
  2479   if (ft->empty()) {
  2480     // Check for evil case of 'this' being a class and 'kills' expecting an
  2481     // interface.  This can happen because the bytecodes do not contain
  2482     // enough type info to distinguish a Java-level interface variable
  2483     // from a Java-level object variable.  If we meet 2 classes which
  2484     // both implement interface I, but their meet is at 'j/l/O' which
  2485     // doesn't implement I, we have no way to tell if the result should
  2486     // be 'I' or 'j/l/O'.  Thus we'll pick 'j/l/O'.  If this then flows
  2487     // into a Phi which "knows" it's an Interface type we'll have to
  2488     // uplift the type.
  2489     if (!empty() && ktip != NULL && ktip->is_loaded() && ktip->klass()->is_interface())
  2490       return kills;             // Uplift to interface
  2491     if (!empty() && ktkp != NULL && ktkp->klass()->is_loaded() && ktkp->klass()->is_interface())
  2492       return kills;             // Uplift to interface
  2494     return Type::TOP;           // Canonical empty value
  2497   // If we have an interface-typed Phi or cast and we narrow to a class type,
  2498   // the join should report back the class.  However, if we have a J/L/Object
  2499   // class-typed Phi and an interface flows in, it's possible that the meet &
  2500   // join report an interface back out.  This isn't possible but happens
  2501   // because the type system doesn't interact well with interfaces.
  2502   if (ftip != NULL && ktip != NULL &&
  2503       ftip->is_loaded() &&  ftip->klass()->is_interface() &&
  2504       ktip->is_loaded() && !ktip->klass()->is_interface()) {
  2505     // Happens in a CTW of rt.jar, 320-341, no extra flags
  2506     return ktip->cast_to_ptr_type(ftip->ptr());
  2508   if (ftkp != NULL && ktkp != NULL &&
  2509       ftkp->is_loaded() &&  ftkp->klass()->is_interface() &&
  2510       ktkp->is_loaded() && !ktkp->klass()->is_interface()) {
  2511     // Happens in a CTW of rt.jar, 320-341, no extra flags
  2512     return ktkp->cast_to_ptr_type(ftkp->ptr());
  2515   return ft;
  2518 //------------------------------eq---------------------------------------------
  2519 // Structural equality check for Type representations
  2520 bool TypeOopPtr::eq( const Type *t ) const {
  2521   const TypeOopPtr *a = (const TypeOopPtr*)t;
  2522   if (_klass_is_exact != a->_klass_is_exact ||
  2523       _instance_id != a->_instance_id)  return false;
  2524   ciObject* one = const_oop();
  2525   ciObject* two = a->const_oop();
  2526   if (one == NULL || two == NULL) {
  2527     return (one == two) && TypePtr::eq(t);
  2528   } else {
  2529     return one->equals(two) && TypePtr::eq(t);
  2533 //------------------------------hash-------------------------------------------
  2534 // Type-specific hashing function.
  2535 int TypeOopPtr::hash(void) const {
  2536   return
  2537     (const_oop() ? const_oop()->hash() : 0) +
  2538     _klass_is_exact +
  2539     _instance_id +
  2540     TypePtr::hash();
  2543 //------------------------------dump2------------------------------------------
  2544 #ifndef PRODUCT
  2545 void TypeOopPtr::dump2( Dict &d, uint depth, outputStream *st ) const {
  2546   st->print("oopptr:%s", ptr_msg[_ptr]);
  2547   if( _klass_is_exact ) st->print(":exact");
  2548   if( const_oop() ) st->print(INTPTR_FORMAT, const_oop());
  2549   switch( _offset ) {
  2550   case OffsetTop: st->print("+top"); break;
  2551   case OffsetBot: st->print("+any"); break;
  2552   case         0: break;
  2553   default:        st->print("+%d",_offset); break;
  2555   if (_instance_id == InstanceTop)
  2556     st->print(",iid=top");
  2557   else if (_instance_id != InstanceBot)
  2558     st->print(",iid=%d",_instance_id);
  2560 #endif
  2562 //------------------------------singleton--------------------------------------
  2563 // TRUE if Type is a singleton type, FALSE otherwise.   Singletons are simple
  2564 // constants
  2565 bool TypeOopPtr::singleton(void) const {
  2566   // detune optimizer to not generate constant oop + constant offset as a constant!
  2567   // TopPTR, Null, AnyNull, Constant are all singletons
  2568   return (_offset == 0) && !below_centerline(_ptr);
  2571 //------------------------------add_offset-------------------------------------
  2572 const TypePtr *TypeOopPtr::add_offset( intptr_t offset ) const {
  2573   return make( _ptr, xadd_offset(offset) );
  2576 //------------------------------meet_instance_id--------------------------------
  2577 int TypeOopPtr::meet_instance_id( int instance_id ) const {
  2578   // Either is 'TOP' instance?  Return the other instance!
  2579   if( _instance_id == InstanceTop ) return  instance_id;
  2580   if(  instance_id == InstanceTop ) return _instance_id;
  2581   // If either is different, return 'BOTTOM' instance
  2582   if( _instance_id != instance_id ) return InstanceBot;
  2583   return _instance_id;
  2586 //------------------------------dual_instance_id--------------------------------
  2587 int TypeOopPtr::dual_instance_id( ) const {
  2588   if( _instance_id == InstanceTop ) return InstanceBot; // Map TOP into BOTTOM
  2589   if( _instance_id == InstanceBot ) return InstanceTop; // Map BOTTOM into TOP
  2590   return _instance_id;              // Map everything else into self
  2594 //=============================================================================
  2595 // Convenience common pre-built types.
  2596 const TypeInstPtr *TypeInstPtr::NOTNULL;
  2597 const TypeInstPtr *TypeInstPtr::BOTTOM;
  2598 const TypeInstPtr *TypeInstPtr::MIRROR;
  2599 const TypeInstPtr *TypeInstPtr::MARK;
  2600 const TypeInstPtr *TypeInstPtr::KLASS;
  2602 //------------------------------TypeInstPtr-------------------------------------
  2603 TypeInstPtr::TypeInstPtr(PTR ptr, ciKlass* k, bool xk, ciObject* o, int off, int instance_id)
  2604  : TypeOopPtr(InstPtr, ptr, k, xk, o, off, instance_id), _name(k->name()) {
  2605    assert(k != NULL &&
  2606           (k->is_loaded() || o == NULL),
  2607           "cannot have constants with non-loaded klass");
  2608 };
  2610 //------------------------------make-------------------------------------------
  2611 const TypeInstPtr *TypeInstPtr::make(PTR ptr,
  2612                                      ciKlass* k,
  2613                                      bool xk,
  2614                                      ciObject* o,
  2615                                      int offset,
  2616                                      int instance_id) {
  2617   assert( !k->is_loaded() || k->is_instance_klass() ||
  2618           k->is_method_klass(), "Must be for instance or method");
  2619   // Either const_oop() is NULL or else ptr is Constant
  2620   assert( (!o && ptr != Constant) || (o && ptr == Constant),
  2621           "constant pointers must have a value supplied" );
  2622   // Ptr is never Null
  2623   assert( ptr != Null, "NULL pointers are not typed" );
  2625   assert(instance_id <= 0 || xk || !UseExactTypes, "instances are always exactly typed");
  2626   if (!UseExactTypes)  xk = false;
  2627   if (ptr == Constant) {
  2628     // Note:  This case includes meta-object constants, such as methods.
  2629     xk = true;
  2630   } else if (k->is_loaded()) {
  2631     ciInstanceKlass* ik = k->as_instance_klass();
  2632     if (!xk && ik->is_final())     xk = true;   // no inexact final klass
  2633     if (xk && ik->is_interface())  xk = false;  // no exact interface
  2636   // Now hash this baby
  2637   TypeInstPtr *result =
  2638     (TypeInstPtr*)(new TypeInstPtr(ptr, k, xk, o ,offset, instance_id))->hashcons();
  2640   return result;
  2644 //------------------------------cast_to_ptr_type-------------------------------
  2645 const Type *TypeInstPtr::cast_to_ptr_type(PTR ptr) const {
  2646   if( ptr == _ptr ) return this;
  2647   // Reconstruct _sig info here since not a problem with later lazy
  2648   // construction, _sig will show up on demand.
  2649   return make(ptr, klass(), klass_is_exact(), const_oop(), _offset, _instance_id);
  2653 //-----------------------------cast_to_exactness-------------------------------
  2654 const Type *TypeInstPtr::cast_to_exactness(bool klass_is_exact) const {
  2655   if( klass_is_exact == _klass_is_exact ) return this;
  2656   if (!UseExactTypes)  return this;
  2657   if (!_klass->is_loaded())  return this;
  2658   ciInstanceKlass* ik = _klass->as_instance_klass();
  2659   if( (ik->is_final() || _const_oop) )  return this;  // cannot clear xk
  2660   if( ik->is_interface() )              return this;  // cannot set xk
  2661   return make(ptr(), klass(), klass_is_exact, const_oop(), _offset, _instance_id);
  2664 //-----------------------------cast_to_instance_id----------------------------
  2665 const TypeOopPtr *TypeInstPtr::cast_to_instance_id(int instance_id) const {
  2666   if( instance_id == _instance_id ) return this;
  2667   return make(_ptr, klass(), _klass_is_exact, const_oop(), _offset, instance_id);
  2670 //------------------------------xmeet_unloaded---------------------------------
  2671 // Compute the MEET of two InstPtrs when at least one is unloaded.
  2672 // Assume classes are different since called after check for same name/class-loader
  2673 const TypeInstPtr *TypeInstPtr::xmeet_unloaded(const TypeInstPtr *tinst) const {
  2674     int off = meet_offset(tinst->offset());
  2675     PTR ptr = meet_ptr(tinst->ptr());
  2677     const TypeInstPtr *loaded    = is_loaded() ? this  : tinst;
  2678     const TypeInstPtr *unloaded  = is_loaded() ? tinst : this;
  2679     if( loaded->klass()->equals(ciEnv::current()->Object_klass()) ) {
  2680       //
  2681       // Meet unloaded class with java/lang/Object
  2682       //
  2683       // Meet
  2684       //          |                     Unloaded Class
  2685       //  Object  |   TOP    |   AnyNull | Constant |   NotNull |  BOTTOM   |
  2686       //  ===================================================================
  2687       //   TOP    | ..........................Unloaded......................|
  2688       //  AnyNull |  U-AN    |................Unloaded......................|
  2689       // Constant | ... O-NN .................................. |   O-BOT   |
  2690       //  NotNull | ... O-NN .................................. |   O-BOT   |
  2691       //  BOTTOM  | ........................Object-BOTTOM ..................|
  2692       //
  2693       assert(loaded->ptr() != TypePtr::Null, "insanity check");
  2694       //
  2695       if(      loaded->ptr() == TypePtr::TopPTR ) { return unloaded; }
  2696       else if (loaded->ptr() == TypePtr::AnyNull) { return TypeInstPtr::make( ptr, unloaded->klass() ); }
  2697       else if (loaded->ptr() == TypePtr::BotPTR ) { return TypeInstPtr::BOTTOM; }
  2698       else if (loaded->ptr() == TypePtr::Constant || loaded->ptr() == TypePtr::NotNull) {
  2699         if (unloaded->ptr() == TypePtr::BotPTR  ) { return TypeInstPtr::BOTTOM;  }
  2700         else                                      { return TypeInstPtr::NOTNULL; }
  2702       else if( unloaded->ptr() == TypePtr::TopPTR )  { return unloaded; }
  2704       return unloaded->cast_to_ptr_type(TypePtr::AnyNull)->is_instptr();
  2707     // Both are unloaded, not the same class, not Object
  2708     // Or meet unloaded with a different loaded class, not java/lang/Object
  2709     if( ptr != TypePtr::BotPTR ) {
  2710       return TypeInstPtr::NOTNULL;
  2712     return TypeInstPtr::BOTTOM;
  2716 //------------------------------meet-------------------------------------------
  2717 // Compute the MEET of two types.  It returns a new Type object.
  2718 const Type *TypeInstPtr::xmeet( const Type *t ) const {
  2719   // Perform a fast test for common case; meeting the same types together.
  2720   if( this == t ) return this;  // Meeting same type-rep?
  2722   // Current "this->_base" is Pointer
  2723   switch (t->base()) {          // switch on original type
  2725   case Int:                     // Mixing ints & oops happens when javac
  2726   case Long:                    // reuses local variables
  2727   case FloatTop:
  2728   case FloatCon:
  2729   case FloatBot:
  2730   case DoubleTop:
  2731   case DoubleCon:
  2732   case DoubleBot:
  2733   case NarrowOop:
  2734   case Bottom:                  // Ye Olde Default
  2735     return Type::BOTTOM;
  2736   case Top:
  2737     return this;
  2739   default:                      // All else is a mistake
  2740     typerr(t);
  2742   case RawPtr: return TypePtr::BOTTOM;
  2744   case AryPtr: {                // All arrays inherit from Object class
  2745     const TypeAryPtr *tp = t->is_aryptr();
  2746     int offset = meet_offset(tp->offset());
  2747     PTR ptr = meet_ptr(tp->ptr());
  2748     int instance_id = meet_instance_id(tp->instance_id());
  2749     switch (ptr) {
  2750     case TopPTR:
  2751     case AnyNull:                // Fall 'down' to dual of object klass
  2752       if (klass()->equals(ciEnv::current()->Object_klass())) {
  2753         return TypeAryPtr::make(ptr, tp->ary(), tp->klass(), tp->klass_is_exact(), offset, instance_id);
  2754       } else {
  2755         // cannot subclass, so the meet has to fall badly below the centerline
  2756         ptr = NotNull;
  2757         instance_id = InstanceBot;
  2758         return TypeInstPtr::make( ptr, ciEnv::current()->Object_klass(), false, NULL, offset, instance_id);
  2760     case Constant:
  2761     case NotNull:
  2762     case BotPTR:                // Fall down to object klass
  2763       // LCA is object_klass, but if we subclass from the top we can do better
  2764       if( above_centerline(_ptr) ) { // if( _ptr == TopPTR || _ptr == AnyNull )
  2765         // If 'this' (InstPtr) is above the centerline and it is Object class
  2766         // then we can subclass in the Java class hierarchy.
  2767         if (klass()->equals(ciEnv::current()->Object_klass())) {
  2768           // that is, tp's array type is a subtype of my klass
  2769           return TypeAryPtr::make(ptr, tp->ary(), tp->klass(), tp->klass_is_exact(), offset, instance_id);
  2772       // The other case cannot happen, since I cannot be a subtype of an array.
  2773       // The meet falls down to Object class below centerline.
  2774       if( ptr == Constant )
  2775          ptr = NotNull;
  2776       instance_id = InstanceBot;
  2777       return make( ptr, ciEnv::current()->Object_klass(), false, NULL, offset, instance_id );
  2778     default: typerr(t);
  2782   case OopPtr: {                // Meeting to OopPtrs
  2783     // Found a OopPtr type vs self-InstPtr type
  2784     const TypePtr *tp = t->is_oopptr();
  2785     int offset = meet_offset(tp->offset());
  2786     PTR ptr = meet_ptr(tp->ptr());
  2787     switch (tp->ptr()) {
  2788     case TopPTR:
  2789     case AnyNull: {
  2790       int instance_id = meet_instance_id(InstanceTop);
  2791       return make(ptr, klass(), klass_is_exact(),
  2792                   (ptr == Constant ? const_oop() : NULL), offset, instance_id);
  2794     case NotNull:
  2795     case BotPTR:
  2796       return TypeOopPtr::make(ptr, offset);
  2797     default: typerr(t);
  2801   case AnyPtr: {                // Meeting to AnyPtrs
  2802     // Found an AnyPtr type vs self-InstPtr type
  2803     const TypePtr *tp = t->is_ptr();
  2804     int offset = meet_offset(tp->offset());
  2805     PTR ptr = meet_ptr(tp->ptr());
  2806     switch (tp->ptr()) {
  2807     case Null:
  2808       if( ptr == Null ) return TypePtr::make( AnyPtr, ptr, offset );
  2809       // else fall through to AnyNull
  2810     case TopPTR:
  2811     case AnyNull: {
  2812       int instance_id = meet_instance_id(InstanceTop);
  2813       return make( ptr, klass(), klass_is_exact(),
  2814                    (ptr == Constant ? const_oop() : NULL), offset, instance_id);
  2816     case NotNull:
  2817     case BotPTR:
  2818       return TypePtr::make( AnyPtr, ptr, offset );
  2819     default: typerr(t);
  2823   /*
  2824                  A-top         }
  2825                /   |   \       }  Tops
  2826            B-top A-any C-top   }
  2827               | /  |  \ |      }  Any-nulls
  2828            B-any   |   C-any   }
  2829               |    |    |
  2830            B-con A-con C-con   } constants; not comparable across classes
  2831               |    |    |
  2832            B-not   |   C-not   }
  2833               | \  |  / |      }  not-nulls
  2834            B-bot A-not C-bot   }
  2835                \   |   /       }  Bottoms
  2836                  A-bot         }
  2837   */
  2839   case InstPtr: {                // Meeting 2 Oops?
  2840     // Found an InstPtr sub-type vs self-InstPtr type
  2841     const TypeInstPtr *tinst = t->is_instptr();
  2842     int off = meet_offset( tinst->offset() );
  2843     PTR ptr = meet_ptr( tinst->ptr() );
  2844     int instance_id = meet_instance_id(tinst->instance_id());
  2846     // Check for easy case; klasses are equal (and perhaps not loaded!)
  2847     // If we have constants, then we created oops so classes are loaded
  2848     // and we can handle the constants further down.  This case handles
  2849     // both-not-loaded or both-loaded classes
  2850     if (ptr != Constant && klass()->equals(tinst->klass()) && klass_is_exact() == tinst->klass_is_exact()) {
  2851       return make( ptr, klass(), klass_is_exact(), NULL, off, instance_id );
  2854     // Classes require inspection in the Java klass hierarchy.  Must be loaded.
  2855     ciKlass* tinst_klass = tinst->klass();
  2856     ciKlass* this_klass  = this->klass();
  2857     bool tinst_xk = tinst->klass_is_exact();
  2858     bool this_xk  = this->klass_is_exact();
  2859     if (!tinst_klass->is_loaded() || !this_klass->is_loaded() ) {
  2860       // One of these classes has not been loaded
  2861       const TypeInstPtr *unloaded_meet = xmeet_unloaded(tinst);
  2862 #ifndef PRODUCT
  2863       if( PrintOpto && Verbose ) {
  2864         tty->print("meet of unloaded classes resulted in: "); unloaded_meet->dump(); tty->cr();
  2865         tty->print("  this == "); this->dump(); tty->cr();
  2866         tty->print(" tinst == "); tinst->dump(); tty->cr();
  2868 #endif
  2869       return unloaded_meet;
  2872     // Handle mixing oops and interfaces first.
  2873     if( this_klass->is_interface() && !tinst_klass->is_interface() ) {
  2874       ciKlass *tmp = tinst_klass; // Swap interface around
  2875       tinst_klass = this_klass;
  2876       this_klass = tmp;
  2877       bool tmp2 = tinst_xk;
  2878       tinst_xk = this_xk;
  2879       this_xk = tmp2;
  2881     if (tinst_klass->is_interface() &&
  2882         !(this_klass->is_interface() ||
  2883           // Treat java/lang/Object as an honorary interface,
  2884           // because we need a bottom for the interface hierarchy.
  2885           this_klass == ciEnv::current()->Object_klass())) {
  2886       // Oop meets interface!
  2888       // See if the oop subtypes (implements) interface.
  2889       ciKlass *k;
  2890       bool xk;
  2891       if( this_klass->is_subtype_of( tinst_klass ) ) {
  2892         // Oop indeed subtypes.  Now keep oop or interface depending
  2893         // on whether we are both above the centerline or either is
  2894         // below the centerline.  If we are on the centerline
  2895         // (e.g., Constant vs. AnyNull interface), use the constant.
  2896         k  = below_centerline(ptr) ? tinst_klass : this_klass;
  2897         // If we are keeping this_klass, keep its exactness too.
  2898         xk = below_centerline(ptr) ? tinst_xk    : this_xk;
  2899       } else {                  // Does not implement, fall to Object
  2900         // Oop does not implement interface, so mixing falls to Object
  2901         // just like the verifier does (if both are above the
  2902         // centerline fall to interface)
  2903         k = above_centerline(ptr) ? tinst_klass : ciEnv::current()->Object_klass();
  2904         xk = above_centerline(ptr) ? tinst_xk : false;
  2905         // Watch out for Constant vs. AnyNull interface.
  2906         if (ptr == Constant)  ptr = NotNull;   // forget it was a constant
  2907         instance_id = InstanceBot;
  2909       ciObject* o = NULL;  // the Constant value, if any
  2910       if (ptr == Constant) {
  2911         // Find out which constant.
  2912         o = (this_klass == klass()) ? const_oop() : tinst->const_oop();
  2914       return make( ptr, k, xk, o, off, instance_id );
  2917     // Either oop vs oop or interface vs interface or interface vs Object
  2919     // !!! Here's how the symmetry requirement breaks down into invariants:
  2920     // If we split one up & one down AND they subtype, take the down man.
  2921     // If we split one up & one down AND they do NOT subtype, "fall hard".
  2922     // If both are up and they subtype, take the subtype class.
  2923     // If both are up and they do NOT subtype, "fall hard".
  2924     // If both are down and they subtype, take the supertype class.
  2925     // If both are down and they do NOT subtype, "fall hard".
  2926     // Constants treated as down.
  2928     // Now, reorder the above list; observe that both-down+subtype is also
  2929     // "fall hard"; "fall hard" becomes the default case:
  2930     // If we split one up & one down AND they subtype, take the down man.
  2931     // If both are up and they subtype, take the subtype class.
  2933     // If both are down and they subtype, "fall hard".
  2934     // If both are down and they do NOT subtype, "fall hard".
  2935     // If both are up and they do NOT subtype, "fall hard".
  2936     // If we split one up & one down AND they do NOT subtype, "fall hard".
  2938     // If a proper subtype is exact, and we return it, we return it exactly.
  2939     // If a proper supertype is exact, there can be no subtyping relationship!
  2940     // If both types are equal to the subtype, exactness is and-ed below the
  2941     // centerline and or-ed above it.  (N.B. Constants are always exact.)
  2943     // Check for subtyping:
  2944     ciKlass *subtype = NULL;
  2945     bool subtype_exact = false;
  2946     if( tinst_klass->equals(this_klass) ) {
  2947       subtype = this_klass;
  2948       subtype_exact = below_centerline(ptr) ? (this_xk & tinst_xk) : (this_xk | tinst_xk);
  2949     } else if( !tinst_xk && this_klass->is_subtype_of( tinst_klass ) ) {
  2950       subtype = this_klass;     // Pick subtyping class
  2951       subtype_exact = this_xk;
  2952     } else if( !this_xk && tinst_klass->is_subtype_of( this_klass ) ) {
  2953       subtype = tinst_klass;    // Pick subtyping class
  2954       subtype_exact = tinst_xk;
  2957     if( subtype ) {
  2958       if( above_centerline(ptr) ) { // both are up?
  2959         this_klass = tinst_klass = subtype;
  2960         this_xk = tinst_xk = subtype_exact;
  2961       } else if( above_centerline(this ->_ptr) && !above_centerline(tinst->_ptr) ) {
  2962         this_klass = tinst_klass; // tinst is down; keep down man
  2963         this_xk = tinst_xk;
  2964       } else if( above_centerline(tinst->_ptr) && !above_centerline(this ->_ptr) ) {
  2965         tinst_klass = this_klass; // this is down; keep down man
  2966         tinst_xk = this_xk;
  2967       } else {
  2968         this_xk = subtype_exact;  // either they are equal, or we'll do an LCA
  2972     // Check for classes now being equal
  2973     if (tinst_klass->equals(this_klass)) {
  2974       // If the klasses are equal, the constants may still differ.  Fall to
  2975       // NotNull if they do (neither constant is NULL; that is a special case
  2976       // handled elsewhere).
  2977       ciObject* o = NULL;             // Assume not constant when done
  2978       ciObject* this_oop  = const_oop();
  2979       ciObject* tinst_oop = tinst->const_oop();
  2980       if( ptr == Constant ) {
  2981         if (this_oop != NULL && tinst_oop != NULL &&
  2982             this_oop->equals(tinst_oop) )
  2983           o = this_oop;
  2984         else if (above_centerline(this ->_ptr))
  2985           o = tinst_oop;
  2986         else if (above_centerline(tinst ->_ptr))
  2987           o = this_oop;
  2988         else
  2989           ptr = NotNull;
  2991       return make( ptr, this_klass, this_xk, o, off, instance_id );
  2992     } // Else classes are not equal
  2994     // Since klasses are different, we require a LCA in the Java
  2995     // class hierarchy - which means we have to fall to at least NotNull.
  2996     if( ptr == TopPTR || ptr == AnyNull || ptr == Constant )
  2997       ptr = NotNull;
  2998     instance_id = InstanceBot;
  3000     // Now we find the LCA of Java classes
  3001     ciKlass* k = this_klass->least_common_ancestor(tinst_klass);
  3002     return make( ptr, k, false, NULL, off, instance_id );
  3003   } // End of case InstPtr
  3005   case KlassPtr:
  3006     return TypeInstPtr::BOTTOM;
  3008   } // End of switch
  3009   return this;                  // Return the double constant
  3013 //------------------------java_mirror_type--------------------------------------
  3014 ciType* TypeInstPtr::java_mirror_type() const {
  3015   // must be a singleton type
  3016   if( const_oop() == NULL )  return NULL;
  3018   // must be of type java.lang.Class
  3019   if( klass() != ciEnv::current()->Class_klass() )  return NULL;
  3021   return const_oop()->as_instance()->java_mirror_type();
  3025 //------------------------------xdual------------------------------------------
  3026 // Dual: do NOT dual on klasses.  This means I do NOT understand the Java
  3027 // inheritance mechanism.
  3028 const Type *TypeInstPtr::xdual() const {
  3029   return new TypeInstPtr( dual_ptr(), klass(), klass_is_exact(), const_oop(), dual_offset(), dual_instance_id()  );
  3032 //------------------------------eq---------------------------------------------
  3033 // Structural equality check for Type representations
  3034 bool TypeInstPtr::eq( const Type *t ) const {
  3035   const TypeInstPtr *p = t->is_instptr();
  3036   return
  3037     klass()->equals(p->klass()) &&
  3038     TypeOopPtr::eq(p);          // Check sub-type stuff
  3041 //------------------------------hash-------------------------------------------
  3042 // Type-specific hashing function.
  3043 int TypeInstPtr::hash(void) const {
  3044   int hash = klass()->hash() + TypeOopPtr::hash();
  3045   return hash;
  3048 //------------------------------dump2------------------------------------------
  3049 // Dump oop Type
  3050 #ifndef PRODUCT
  3051 void TypeInstPtr::dump2( Dict &d, uint depth, outputStream *st ) const {
  3052   // Print the name of the klass.
  3053   klass()->print_name_on(st);
  3055   switch( _ptr ) {
  3056   case Constant:
  3057     // TO DO: Make CI print the hex address of the underlying oop.
  3058     if (WizardMode || Verbose) {
  3059       const_oop()->print_oop(st);
  3061   case BotPTR:
  3062     if (!WizardMode && !Verbose) {
  3063       if( _klass_is_exact ) st->print(":exact");
  3064       break;
  3066   case TopPTR:
  3067   case AnyNull:
  3068   case NotNull:
  3069     st->print(":%s", ptr_msg[_ptr]);
  3070     if( _klass_is_exact ) st->print(":exact");
  3071     break;
  3074   if( _offset ) {               // Dump offset, if any
  3075     if( _offset == OffsetBot )      st->print("+any");
  3076     else if( _offset == OffsetTop ) st->print("+unknown");
  3077     else st->print("+%d", _offset);
  3080   st->print(" *");
  3081   if (_instance_id == InstanceTop)
  3082     st->print(",iid=top");
  3083   else if (_instance_id != InstanceBot)
  3084     st->print(",iid=%d",_instance_id);
  3086 #endif
  3088 //------------------------------add_offset-------------------------------------
  3089 const TypePtr *TypeInstPtr::add_offset( intptr_t offset ) const {
  3090   return make( _ptr, klass(), klass_is_exact(), const_oop(), xadd_offset(offset), _instance_id );
  3093 //=============================================================================
  3094 // Convenience common pre-built types.
  3095 const TypeAryPtr *TypeAryPtr::RANGE;
  3096 const TypeAryPtr *TypeAryPtr::OOPS;
  3097 const TypeAryPtr *TypeAryPtr::NARROWOOPS;
  3098 const TypeAryPtr *TypeAryPtr::BYTES;
  3099 const TypeAryPtr *TypeAryPtr::SHORTS;
  3100 const TypeAryPtr *TypeAryPtr::CHARS;
  3101 const TypeAryPtr *TypeAryPtr::INTS;
  3102 const TypeAryPtr *TypeAryPtr::LONGS;
  3103 const TypeAryPtr *TypeAryPtr::FLOATS;
  3104 const TypeAryPtr *TypeAryPtr::DOUBLES;
  3106 //------------------------------make-------------------------------------------
  3107 const TypeAryPtr *TypeAryPtr::make( PTR ptr, const TypeAry *ary, ciKlass* k, bool xk, int offset, int instance_id ) {
  3108   assert(!(k == NULL && ary->_elem->isa_int()),
  3109          "integral arrays must be pre-equipped with a class");
  3110   if (!xk)  xk = ary->ary_must_be_exact();
  3111   assert(instance_id <= 0 || xk || !UseExactTypes, "instances are always exactly typed");
  3112   if (!UseExactTypes)  xk = (ptr == Constant);
  3113   return (TypeAryPtr*)(new TypeAryPtr(ptr, NULL, ary, k, xk, offset, instance_id))->hashcons();
  3116 //------------------------------make-------------------------------------------
  3117 const TypeAryPtr *TypeAryPtr::make( PTR ptr, ciObject* o, const TypeAry *ary, ciKlass* k, bool xk, int offset, int instance_id ) {
  3118   assert(!(k == NULL && ary->_elem->isa_int()),
  3119          "integral arrays must be pre-equipped with a class");
  3120   assert( (ptr==Constant && o) || (ptr!=Constant && !o), "" );
  3121   if (!xk)  xk = (o != NULL) || ary->ary_must_be_exact();
  3122   assert(instance_id <= 0 || xk || !UseExactTypes, "instances are always exactly typed");
  3123   if (!UseExactTypes)  xk = (ptr == Constant);
  3124   return (TypeAryPtr*)(new TypeAryPtr(ptr, o, ary, k, xk, offset, instance_id))->hashcons();
  3127 //------------------------------cast_to_ptr_type-------------------------------
  3128 const Type *TypeAryPtr::cast_to_ptr_type(PTR ptr) const {
  3129   if( ptr == _ptr ) return this;
  3130   return make(ptr, const_oop(), _ary, klass(), klass_is_exact(), _offset, _instance_id);
  3134 //-----------------------------cast_to_exactness-------------------------------
  3135 const Type *TypeAryPtr::cast_to_exactness(bool klass_is_exact) const {
  3136   if( klass_is_exact == _klass_is_exact ) return this;
  3137   if (!UseExactTypes)  return this;
  3138   if (_ary->ary_must_be_exact())  return this;  // cannot clear xk
  3139   return make(ptr(), const_oop(), _ary, klass(), klass_is_exact, _offset, _instance_id);
  3142 //-----------------------------cast_to_instance_id----------------------------
  3143 const TypeOopPtr *TypeAryPtr::cast_to_instance_id(int instance_id) const {
  3144   if( instance_id == _instance_id ) return this;
  3145   return make(_ptr, const_oop(), _ary, klass(), _klass_is_exact, _offset, instance_id);
  3148 //-----------------------------narrow_size_type-------------------------------
  3149 // Local cache for arrayOopDesc::max_array_length(etype),
  3150 // which is kind of slow (and cached elsewhere by other users).
  3151 static jint max_array_length_cache[T_CONFLICT+1];
  3152 static jint max_array_length(BasicType etype) {
  3153   jint& cache = max_array_length_cache[etype];
  3154   jint res = cache;
  3155   if (res == 0) {
  3156     switch (etype) {
  3157     case T_NARROWOOP:
  3158       etype = T_OBJECT;
  3159       break;
  3160     case T_CONFLICT:
  3161     case T_ILLEGAL:
  3162     case T_VOID:
  3163       etype = T_BYTE;           // will produce conservatively high value
  3165     cache = res = arrayOopDesc::max_array_length(etype);
  3167   return res;
  3170 // Narrow the given size type to the index range for the given array base type.
  3171 // Return NULL if the resulting int type becomes empty.
  3172 const TypeInt* TypeAryPtr::narrow_size_type(const TypeInt* size) const {
  3173   jint hi = size->_hi;
  3174   jint lo = size->_lo;
  3175   jint min_lo = 0;
  3176   jint max_hi = max_array_length(elem()->basic_type());
  3177   //if (index_not_size)  --max_hi;     // type of a valid array index, FTR
  3178   bool chg = false;
  3179   if (lo < min_lo) { lo = min_lo; chg = true; }
  3180   if (hi > max_hi) { hi = max_hi; chg = true; }
  3181   // Negative length arrays will produce weird intermediate dead fast-path code
  3182   if (lo > hi)
  3183     return TypeInt::ZERO;
  3184   if (!chg)
  3185     return size;
  3186   return TypeInt::make(lo, hi, Type::WidenMin);
  3189 //-------------------------------cast_to_size----------------------------------
  3190 const TypeAryPtr* TypeAryPtr::cast_to_size(const TypeInt* new_size) const {
  3191   assert(new_size != NULL, "");
  3192   new_size = narrow_size_type(new_size);
  3193   if (new_size == size())  return this;
  3194   const TypeAry* new_ary = TypeAry::make(elem(), new_size);
  3195   return make(ptr(), const_oop(), new_ary, klass(), klass_is_exact(), _offset, _instance_id);
  3199 //------------------------------eq---------------------------------------------
  3200 // Structural equality check for Type representations
  3201 bool TypeAryPtr::eq( const Type *t ) const {
  3202   const TypeAryPtr *p = t->is_aryptr();
  3203   return
  3204     _ary == p->_ary &&  // Check array
  3205     TypeOopPtr::eq(p);  // Check sub-parts
  3208 //------------------------------hash-------------------------------------------
  3209 // Type-specific hashing function.
  3210 int TypeAryPtr::hash(void) const {
  3211   return (intptr_t)_ary + TypeOopPtr::hash();
  3214 //------------------------------meet-------------------------------------------
  3215 // Compute the MEET of two types.  It returns a new Type object.
  3216 const Type *TypeAryPtr::xmeet( const Type *t ) const {
  3217   // Perform a fast test for common case; meeting the same types together.
  3218   if( this == t ) return this;  // Meeting same type-rep?
  3219   // Current "this->_base" is Pointer
  3220   switch (t->base()) {          // switch on original type
  3222   // Mixing ints & oops happens when javac reuses local variables
  3223   case Int:
  3224   case Long:
  3225   case FloatTop:
  3226   case FloatCon:
  3227   case FloatBot:
  3228   case DoubleTop:
  3229   case DoubleCon:
  3230   case DoubleBot:
  3231   case NarrowOop:
  3232   case Bottom:                  // Ye Olde Default
  3233     return Type::BOTTOM;
  3234   case Top:
  3235     return this;
  3237   default:                      // All else is a mistake
  3238     typerr(t);
  3240   case OopPtr: {                // Meeting to OopPtrs
  3241     // Found a OopPtr type vs self-AryPtr type
  3242     const TypePtr *tp = t->is_oopptr();
  3243     int offset = meet_offset(tp->offset());
  3244     PTR ptr = meet_ptr(tp->ptr());
  3245     switch (tp->ptr()) {
  3246     case TopPTR:
  3247     case AnyNull: {
  3248       int instance_id = meet_instance_id(InstanceTop);
  3249       return make(ptr, (ptr == Constant ? const_oop() : NULL),
  3250                   _ary, _klass, _klass_is_exact, offset, instance_id);
  3252     case BotPTR:
  3253     case NotNull:
  3254       return TypeOopPtr::make(ptr, offset);
  3255     default: ShouldNotReachHere();
  3259   case AnyPtr: {                // Meeting two AnyPtrs
  3260     // Found an AnyPtr type vs self-AryPtr type
  3261     const TypePtr *tp = t->is_ptr();
  3262     int offset = meet_offset(tp->offset());
  3263     PTR ptr = meet_ptr(tp->ptr());
  3264     switch (tp->ptr()) {
  3265     case TopPTR:
  3266       return this;
  3267     case BotPTR:
  3268     case NotNull:
  3269       return TypePtr::make(AnyPtr, ptr, offset);
  3270     case Null:
  3271       if( ptr == Null ) return TypePtr::make(AnyPtr, ptr, offset);
  3272       // else fall through to AnyNull
  3273     case AnyNull: {
  3274       int instance_id = meet_instance_id(InstanceTop);
  3275       return make( ptr, (ptr == Constant ? const_oop() : NULL),
  3276                   _ary, _klass, _klass_is_exact, offset, instance_id);
  3278     default: ShouldNotReachHere();
  3282   case RawPtr: return TypePtr::BOTTOM;
  3284   case AryPtr: {                // Meeting 2 references?
  3285     const TypeAryPtr *tap = t->is_aryptr();
  3286     int off = meet_offset(tap->offset());
  3287     const TypeAry *tary = _ary->meet(tap->_ary)->is_ary();
  3288     PTR ptr = meet_ptr(tap->ptr());
  3289     int instance_id = meet_instance_id(tap->instance_id());
  3290     ciKlass* lazy_klass = NULL;
  3291     if (tary->_elem->isa_int()) {
  3292       // Integral array element types have irrelevant lattice relations.
  3293       // It is the klass that determines array layout, not the element type.
  3294       if (_klass == NULL)
  3295         lazy_klass = tap->_klass;
  3296       else if (tap->_klass == NULL || tap->_klass == _klass) {
  3297         lazy_klass = _klass;
  3298       } else {
  3299         // Something like byte[int+] meets char[int+].
  3300         // This must fall to bottom, not (int[-128..65535])[int+].
  3301         instance_id = InstanceBot;
  3302         tary = TypeAry::make(Type::BOTTOM, tary->_size);
  3305     bool xk;
  3306     switch (tap->ptr()) {
  3307     case AnyNull:
  3308     case TopPTR:
  3309       // Compute new klass on demand, do not use tap->_klass
  3310       xk = (tap->_klass_is_exact | this->_klass_is_exact);
  3311       return make( ptr, const_oop(), tary, lazy_klass, xk, off, instance_id );
  3312     case Constant: {
  3313       ciObject* o = const_oop();
  3314       if( _ptr == Constant ) {
  3315         if( tap->const_oop() != NULL && !o->equals(tap->const_oop()) ) {
  3316           ptr = NotNull;
  3317           o = NULL;
  3318           instance_id = InstanceBot;
  3320       } else if( above_centerline(_ptr) ) {
  3321         o = tap->const_oop();
  3323       xk = true;
  3324       return TypeAryPtr::make( ptr, o, tary, tap->_klass, xk, off, instance_id );
  3326     case NotNull:
  3327     case BotPTR:
  3328       // Compute new klass on demand, do not use tap->_klass
  3329       if (above_centerline(this->_ptr))
  3330             xk = tap->_klass_is_exact;
  3331       else if (above_centerline(tap->_ptr))
  3332             xk = this->_klass_is_exact;
  3333       else  xk = (tap->_klass_is_exact & this->_klass_is_exact) &&
  3334               (klass() == tap->klass()); // Only precise for identical arrays
  3335       return TypeAryPtr::make( ptr, NULL, tary, lazy_klass, xk, off, instance_id );
  3336     default: ShouldNotReachHere();
  3340   // All arrays inherit from Object class
  3341   case InstPtr: {
  3342     const TypeInstPtr *tp = t->is_instptr();
  3343     int offset = meet_offset(tp->offset());
  3344     PTR ptr = meet_ptr(tp->ptr());
  3345     int instance_id = meet_instance_id(tp->instance_id());
  3346     switch (ptr) {
  3347     case TopPTR:
  3348     case AnyNull:                // Fall 'down' to dual of object klass
  3349       if( tp->klass()->equals(ciEnv::current()->Object_klass()) ) {
  3350         return TypeAryPtr::make( ptr, _ary, _klass, _klass_is_exact, offset, instance_id );
  3351       } else {
  3352         // cannot subclass, so the meet has to fall badly below the centerline
  3353         ptr = NotNull;
  3354         instance_id = InstanceBot;
  3355         return TypeInstPtr::make( ptr, ciEnv::current()->Object_klass(), false, NULL,offset, instance_id);
  3357     case Constant:
  3358     case NotNull:
  3359     case BotPTR:                // Fall down to object klass
  3360       // LCA is object_klass, but if we subclass from the top we can do better
  3361       if (above_centerline(tp->ptr())) {
  3362         // If 'tp'  is above the centerline and it is Object class
  3363         // then we can subclass in the Java class hierarchy.
  3364         if( tp->klass()->equals(ciEnv::current()->Object_klass()) ) {
  3365           // that is, my array type is a subtype of 'tp' klass
  3366           return make( ptr, _ary, _klass, _klass_is_exact, offset, instance_id );
  3369       // The other case cannot happen, since t cannot be a subtype of an array.
  3370       // The meet falls down to Object class below centerline.
  3371       if( ptr == Constant )
  3372          ptr = NotNull;
  3373       instance_id = InstanceBot;
  3374       return TypeInstPtr::make( ptr, ciEnv::current()->Object_klass(), false, NULL,offset, instance_id);
  3375     default: typerr(t);
  3379   case KlassPtr:
  3380     return TypeInstPtr::BOTTOM;
  3383   return this;                  // Lint noise
  3386 //------------------------------xdual------------------------------------------
  3387 // Dual: compute field-by-field dual
  3388 const Type *TypeAryPtr::xdual() const {
  3389   return new TypeAryPtr( dual_ptr(), _const_oop, _ary->dual()->is_ary(),_klass, _klass_is_exact, dual_offset(), dual_instance_id() );
  3392 //------------------------------dump2------------------------------------------
  3393 #ifndef PRODUCT
  3394 void TypeAryPtr::dump2( Dict &d, uint depth, outputStream *st ) const {
  3395   _ary->dump2(d,depth,st);
  3396   switch( _ptr ) {
  3397   case Constant:
  3398     const_oop()->print(st);
  3399     break;
  3400   case BotPTR:
  3401     if (!WizardMode && !Verbose) {
  3402       if( _klass_is_exact ) st->print(":exact");
  3403       break;
  3405   case TopPTR:
  3406   case AnyNull:
  3407   case NotNull:
  3408     st->print(":%s", ptr_msg[_ptr]);
  3409     if( _klass_is_exact ) st->print(":exact");
  3410     break;
  3413   if( _offset != 0 ) {
  3414     int header_size = objArrayOopDesc::header_size() * wordSize;
  3415     if( _offset == OffsetTop )       st->print("+undefined");
  3416     else if( _offset == OffsetBot )  st->print("+any");
  3417     else if( _offset < header_size ) st->print("+%d", _offset);
  3418     else {
  3419       BasicType basic_elem_type = elem()->basic_type();
  3420       int array_base = arrayOopDesc::base_offset_in_bytes(basic_elem_type);
  3421       int elem_size = type2aelembytes(basic_elem_type);
  3422       st->print("[%d]", (_offset - array_base)/elem_size);
  3425   st->print(" *");
  3426   if (_instance_id == InstanceTop)
  3427     st->print(",iid=top");
  3428   else if (_instance_id != InstanceBot)
  3429     st->print(",iid=%d",_instance_id);
  3431 #endif
  3433 bool TypeAryPtr::empty(void) const {
  3434   if (_ary->empty())       return true;
  3435   return TypeOopPtr::empty();
  3438 //------------------------------add_offset-------------------------------------
  3439 const TypePtr *TypeAryPtr::add_offset( intptr_t offset ) const {
  3440   return make( _ptr, _const_oop, _ary, _klass, _klass_is_exact, xadd_offset(offset), _instance_id );
  3444 //=============================================================================
  3445 const TypeNarrowOop *TypeNarrowOop::BOTTOM;
  3446 const TypeNarrowOop *TypeNarrowOop::NULL_PTR;
  3449 const TypeNarrowOop* TypeNarrowOop::make(const TypePtr* type) {
  3450   return (const TypeNarrowOop*)(new TypeNarrowOop(type))->hashcons();
  3453 //------------------------------hash-------------------------------------------
  3454 // Type-specific hashing function.
  3455 int TypeNarrowOop::hash(void) const {
  3456   return _ooptype->hash() + 7;
  3460 bool TypeNarrowOop::eq( const Type *t ) const {
  3461   const TypeNarrowOop* tc = t->isa_narrowoop();
  3462   if (tc != NULL) {
  3463     if (_ooptype->base() != tc->_ooptype->base()) {
  3464       return false;
  3466     return tc->_ooptype->eq(_ooptype);
  3468   return false;
  3471 bool TypeNarrowOop::singleton(void) const {    // TRUE if type is a singleton
  3472   return _ooptype->singleton();
  3475 bool TypeNarrowOop::empty(void) const {
  3476   return _ooptype->empty();
  3479 //------------------------------xmeet------------------------------------------
  3480 // Compute the MEET of two types.  It returns a new Type object.
  3481 const Type *TypeNarrowOop::xmeet( const Type *t ) const {
  3482   // Perform a fast test for common case; meeting the same types together.
  3483   if( this == t ) return this;  // Meeting same type-rep?
  3486   // Current "this->_base" is OopPtr
  3487   switch (t->base()) {          // switch on original type
  3489   case Int:                     // Mixing ints & oops happens when javac
  3490   case Long:                    // reuses local variables
  3491   case FloatTop:
  3492   case FloatCon:
  3493   case FloatBot:
  3494   case DoubleTop:
  3495   case DoubleCon:
  3496   case DoubleBot:
  3497   case AnyPtr:
  3498   case RawPtr:
  3499   case OopPtr:
  3500   case InstPtr:
  3501   case KlassPtr:
  3502   case AryPtr:
  3504   case Bottom:                  // Ye Olde Default
  3505     return Type::BOTTOM;
  3506   case Top:
  3507     return this;
  3509   case NarrowOop: {
  3510     const Type* result = _ooptype->xmeet(t->make_ptr());
  3511     if (result->isa_ptr()) {
  3512       return TypeNarrowOop::make(result->is_ptr());
  3514     return result;
  3517   default:                      // All else is a mistake
  3518     typerr(t);
  3520   } // End of switch
  3522   return this;
  3525 const Type *TypeNarrowOop::xdual() const {    // Compute dual right now.
  3526   const TypePtr* odual = _ooptype->dual()->is_ptr();
  3527   return new TypeNarrowOop(odual);
  3530 const Type *TypeNarrowOop::filter( const Type *kills ) const {
  3531   if (kills->isa_narrowoop()) {
  3532     const Type* ft =_ooptype->filter(kills->is_narrowoop()->_ooptype);
  3533     if (ft->empty())
  3534       return Type::TOP;           // Canonical empty value
  3535     if (ft->isa_ptr()) {
  3536       return make(ft->isa_ptr());
  3538     return ft;
  3539   } else if (kills->isa_ptr()) {
  3540     const Type* ft = _ooptype->join(kills);
  3541     if (ft->empty())
  3542       return Type::TOP;           // Canonical empty value
  3543     return ft;
  3544   } else {
  3545     return Type::TOP;
  3550 intptr_t TypeNarrowOop::get_con() const {
  3551   return _ooptype->get_con();
  3554 #ifndef PRODUCT
  3555 void TypeNarrowOop::dump2( Dict & d, uint depth, outputStream *st ) const {
  3556   st->print("narrowoop: ");
  3557   _ooptype->dump2(d, depth, st);
  3559 #endif
  3562 //=============================================================================
  3563 // Convenience common pre-built types.
  3565 // Not-null object klass or below
  3566 const TypeKlassPtr *TypeKlassPtr::OBJECT;
  3567 const TypeKlassPtr *TypeKlassPtr::OBJECT_OR_NULL;
  3569 //------------------------------TypeKlasPtr------------------------------------
  3570 TypeKlassPtr::TypeKlassPtr( PTR ptr, ciKlass* klass, int offset )
  3571   : TypeOopPtr(KlassPtr, ptr, klass, (ptr==Constant), (ptr==Constant ? klass : NULL), offset, 0) {
  3574 //------------------------------make-------------------------------------------
  3575 // ptr to klass 'k', if Constant, or possibly to a sub-klass if not a Constant
  3576 const TypeKlassPtr *TypeKlassPtr::make( PTR ptr, ciKlass* k, int offset ) {
  3577   assert( k != NULL, "Expect a non-NULL klass");
  3578   assert(k->is_instance_klass() || k->is_array_klass() ||
  3579          k->is_method_klass(), "Incorrect type of klass oop");
  3580   TypeKlassPtr *r =
  3581     (TypeKlassPtr*)(new TypeKlassPtr(ptr, k, offset))->hashcons();
  3583   return r;
  3586 //------------------------------eq---------------------------------------------
  3587 // Structural equality check for Type representations
  3588 bool TypeKlassPtr::eq( const Type *t ) const {
  3589   const TypeKlassPtr *p = t->is_klassptr();
  3590   return
  3591     klass()->equals(p->klass()) &&
  3592     TypeOopPtr::eq(p);
  3595 //------------------------------hash-------------------------------------------
  3596 // Type-specific hashing function.
  3597 int TypeKlassPtr::hash(void) const {
  3598   return klass()->hash() + TypeOopPtr::hash();
  3602 //------------------------------klass------------------------------------------
  3603 // Return the defining klass for this class
  3604 ciKlass* TypeAryPtr::klass() const {
  3605   if( _klass ) return _klass;   // Return cached value, if possible
  3607   // Oops, need to compute _klass and cache it
  3608   ciKlass* k_ary = NULL;
  3609   const TypeInstPtr *tinst;
  3610   const TypeAryPtr *tary;
  3611   const Type* el = elem();
  3612   if (el->isa_narrowoop()) {
  3613     el = el->make_ptr();
  3616   // Get element klass
  3617   if ((tinst = el->isa_instptr()) != NULL) {
  3618     // Compute array klass from element klass
  3619     k_ary = ciObjArrayKlass::make(tinst->klass());
  3620   } else if ((tary = el->isa_aryptr()) != NULL) {
  3621     // Compute array klass from element klass
  3622     ciKlass* k_elem = tary->klass();
  3623     // If element type is something like bottom[], k_elem will be null.
  3624     if (k_elem != NULL)
  3625       k_ary = ciObjArrayKlass::make(k_elem);
  3626   } else if ((el->base() == Type::Top) ||
  3627              (el->base() == Type::Bottom)) {
  3628     // element type of Bottom occurs from meet of basic type
  3629     // and object; Top occurs when doing join on Bottom.
  3630     // Leave k_ary at NULL.
  3631   } else {
  3632     // Cannot compute array klass directly from basic type,
  3633     // since subtypes of TypeInt all have basic type T_INT.
  3634     assert(!el->isa_int(),
  3635            "integral arrays must be pre-equipped with a class");
  3636     // Compute array klass directly from basic type
  3637     k_ary = ciTypeArrayKlass::make(el->basic_type());
  3640   if( this != TypeAryPtr::OOPS ) {
  3641     // The _klass field acts as a cache of the underlying
  3642     // ciKlass for this array type.  In order to set the field,
  3643     // we need to cast away const-ness.
  3644     //
  3645     // IMPORTANT NOTE: we *never* set the _klass field for the
  3646     // type TypeAryPtr::OOPS.  This Type is shared between all
  3647     // active compilations.  However, the ciKlass which represents
  3648     // this Type is *not* shared between compilations, so caching
  3649     // this value would result in fetching a dangling pointer.
  3650     //
  3651     // Recomputing the underlying ciKlass for each request is
  3652     // a bit less efficient than caching, but calls to
  3653     // TypeAryPtr::OOPS->klass() are not common enough to matter.
  3654     ((TypeAryPtr*)this)->_klass = k_ary;
  3655     if (UseCompressedOops && k_ary != NULL && k_ary->is_obj_array_klass() &&
  3656         _offset != 0 && _offset != arrayOopDesc::length_offset_in_bytes()) {
  3657       ((TypeAryPtr*)this)->_is_ptr_to_narrowoop = true;
  3660   return k_ary;
  3664 //------------------------------add_offset-------------------------------------
  3665 // Access internals of klass object
  3666 const TypePtr *TypeKlassPtr::add_offset( intptr_t offset ) const {
  3667   return make( _ptr, klass(), xadd_offset(offset) );
  3670 //------------------------------cast_to_ptr_type-------------------------------
  3671 const Type *TypeKlassPtr::cast_to_ptr_type(PTR ptr) const {
  3672   assert(_base == KlassPtr, "subclass must override cast_to_ptr_type");
  3673   if( ptr == _ptr ) return this;
  3674   return make(ptr, _klass, _offset);
  3678 //-----------------------------cast_to_exactness-------------------------------
  3679 const Type *TypeKlassPtr::cast_to_exactness(bool klass_is_exact) const {
  3680   if( klass_is_exact == _klass_is_exact ) return this;
  3681   if (!UseExactTypes)  return this;
  3682   return make(klass_is_exact ? Constant : NotNull, _klass, _offset);
  3686 //-----------------------------as_instance_type--------------------------------
  3687 // Corresponding type for an instance of the given class.
  3688 // It will be NotNull, and exact if and only if the klass type is exact.
  3689 const TypeOopPtr* TypeKlassPtr::as_instance_type() const {
  3690   ciKlass* k = klass();
  3691   bool    xk = klass_is_exact();
  3692   //return TypeInstPtr::make(TypePtr::NotNull, k, xk, NULL, 0);
  3693   const TypeOopPtr* toop = TypeOopPtr::make_from_klass_raw(k);
  3694   toop = toop->cast_to_ptr_type(TypePtr::NotNull)->is_oopptr();
  3695   return toop->cast_to_exactness(xk)->is_oopptr();
  3699 //------------------------------xmeet------------------------------------------
  3700 // Compute the MEET of two types, return a new Type object.
  3701 const Type    *TypeKlassPtr::xmeet( const Type *t ) const {
  3702   // Perform a fast test for common case; meeting the same types together.
  3703   if( this == t ) return this;  // Meeting same type-rep?
  3705   // Current "this->_base" is Pointer
  3706   switch (t->base()) {          // switch on original type
  3708   case Int:                     // Mixing ints & oops happens when javac
  3709   case Long:                    // reuses local variables
  3710   case FloatTop:
  3711   case FloatCon:
  3712   case FloatBot:
  3713   case DoubleTop:
  3714   case DoubleCon:
  3715   case DoubleBot:
  3716   case NarrowOop:
  3717   case Bottom:                  // Ye Olde Default
  3718     return Type::BOTTOM;
  3719   case Top:
  3720     return this;
  3722   default:                      // All else is a mistake
  3723     typerr(t);
  3725   case RawPtr: return TypePtr::BOTTOM;
  3727   case OopPtr: {                // Meeting to OopPtrs
  3728     // Found a OopPtr type vs self-KlassPtr type
  3729     const TypePtr *tp = t->is_oopptr();
  3730     int offset = meet_offset(tp->offset());
  3731     PTR ptr = meet_ptr(tp->ptr());
  3732     switch (tp->ptr()) {
  3733     case TopPTR:
  3734     case AnyNull:
  3735       return make(ptr, klass(), offset);
  3736     case BotPTR:
  3737     case NotNull:
  3738       return TypePtr::make(AnyPtr, ptr, offset);
  3739     default: typerr(t);
  3743   case AnyPtr: {                // Meeting to AnyPtrs
  3744     // Found an AnyPtr type vs self-KlassPtr type
  3745     const TypePtr *tp = t->is_ptr();
  3746     int offset = meet_offset(tp->offset());
  3747     PTR ptr = meet_ptr(tp->ptr());
  3748     switch (tp->ptr()) {
  3749     case TopPTR:
  3750       return this;
  3751     case Null:
  3752       if( ptr == Null ) return TypePtr::make( AnyPtr, ptr, offset );
  3753     case AnyNull:
  3754       return make( ptr, klass(), offset );
  3755     case BotPTR:
  3756     case NotNull:
  3757       return TypePtr::make(AnyPtr, ptr, offset);
  3758     default: typerr(t);
  3762   case AryPtr:                  // Meet with AryPtr
  3763   case InstPtr:                 // Meet with InstPtr
  3764     return TypeInstPtr::BOTTOM;
  3766   //
  3767   //             A-top         }
  3768   //           /   |   \       }  Tops
  3769   //       B-top A-any C-top   }
  3770   //          | /  |  \ |      }  Any-nulls
  3771   //       B-any   |   C-any   }
  3772   //          |    |    |
  3773   //       B-con A-con C-con   } constants; not comparable across classes
  3774   //          |    |    |
  3775   //       B-not   |   C-not   }
  3776   //          | \  |  / |      }  not-nulls
  3777   //       B-bot A-not C-bot   }
  3778   //           \   |   /       }  Bottoms
  3779   //             A-bot         }
  3780   //
  3782   case KlassPtr: {  // Meet two KlassPtr types
  3783     const TypeKlassPtr *tkls = t->is_klassptr();
  3784     int  off     = meet_offset(tkls->offset());
  3785     PTR  ptr     = meet_ptr(tkls->ptr());
  3787     // Check for easy case; klasses are equal (and perhaps not loaded!)
  3788     // If we have constants, then we created oops so classes are loaded
  3789     // and we can handle the constants further down.  This case handles
  3790     // not-loaded classes
  3791     if( ptr != Constant && tkls->klass()->equals(klass()) ) {
  3792       return make( ptr, klass(), off );
  3795     // Classes require inspection in the Java klass hierarchy.  Must be loaded.
  3796     ciKlass* tkls_klass = tkls->klass();
  3797     ciKlass* this_klass = this->klass();
  3798     assert( tkls_klass->is_loaded(), "This class should have been loaded.");
  3799     assert( this_klass->is_loaded(), "This class should have been loaded.");
  3801     // If 'this' type is above the centerline and is a superclass of the
  3802     // other, we can treat 'this' as having the same type as the other.
  3803     if ((above_centerline(this->ptr())) &&
  3804         tkls_klass->is_subtype_of(this_klass)) {
  3805       this_klass = tkls_klass;
  3807     // If 'tinst' type is above the centerline and is a superclass of the
  3808     // other, we can treat 'tinst' as having the same type as the other.
  3809     if ((above_centerline(tkls->ptr())) &&
  3810         this_klass->is_subtype_of(tkls_klass)) {
  3811       tkls_klass = this_klass;
  3814     // Check for classes now being equal
  3815     if (tkls_klass->equals(this_klass)) {
  3816       // If the klasses are equal, the constants may still differ.  Fall to
  3817       // NotNull if they do (neither constant is NULL; that is a special case
  3818       // handled elsewhere).
  3819       ciObject* o = NULL;             // Assume not constant when done
  3820       ciObject* this_oop = const_oop();
  3821       ciObject* tkls_oop = tkls->const_oop();
  3822       if( ptr == Constant ) {
  3823         if (this_oop != NULL && tkls_oop != NULL &&
  3824             this_oop->equals(tkls_oop) )
  3825           o = this_oop;
  3826         else if (above_centerline(this->ptr()))
  3827           o = tkls_oop;
  3828         else if (above_centerline(tkls->ptr()))
  3829           o = this_oop;
  3830         else
  3831           ptr = NotNull;
  3833       return make( ptr, this_klass, off );
  3834     } // Else classes are not equal
  3836     // Since klasses are different, we require the LCA in the Java
  3837     // class hierarchy - which means we have to fall to at least NotNull.
  3838     if( ptr == TopPTR || ptr == AnyNull || ptr == Constant )
  3839       ptr = NotNull;
  3840     // Now we find the LCA of Java classes
  3841     ciKlass* k = this_klass->least_common_ancestor(tkls_klass);
  3842     return   make( ptr, k, off );
  3843   } // End of case KlassPtr
  3845   } // End of switch
  3846   return this;                  // Return the double constant
  3849 //------------------------------xdual------------------------------------------
  3850 // Dual: compute field-by-field dual
  3851 const Type    *TypeKlassPtr::xdual() const {
  3852   return new TypeKlassPtr( dual_ptr(), klass(), dual_offset() );
  3855 //------------------------------dump2------------------------------------------
  3856 // Dump Klass Type
  3857 #ifndef PRODUCT
  3858 void TypeKlassPtr::dump2( Dict & d, uint depth, outputStream *st ) const {
  3859   switch( _ptr ) {
  3860   case Constant:
  3861     st->print("precise ");
  3862   case NotNull:
  3864       const char *name = klass()->name()->as_utf8();
  3865       if( name ) {
  3866         st->print("klass %s: " INTPTR_FORMAT, name, klass());
  3867       } else {
  3868         ShouldNotReachHere();
  3871   case BotPTR:
  3872     if( !WizardMode && !Verbose && !_klass_is_exact ) break;
  3873   case TopPTR:
  3874   case AnyNull:
  3875     st->print(":%s", ptr_msg[_ptr]);
  3876     if( _klass_is_exact ) st->print(":exact");
  3877     break;
  3880   if( _offset ) {               // Dump offset, if any
  3881     if( _offset == OffsetBot )      { st->print("+any"); }
  3882     else if( _offset == OffsetTop ) { st->print("+unknown"); }
  3883     else                            { st->print("+%d", _offset); }
  3886   st->print(" *");
  3888 #endif
  3892 //=============================================================================
  3893 // Convenience common pre-built types.
  3895 //------------------------------make-------------------------------------------
  3896 const TypeFunc *TypeFunc::make( const TypeTuple *domain, const TypeTuple *range ) {
  3897   return (TypeFunc*)(new TypeFunc(domain,range))->hashcons();
  3900 //------------------------------make-------------------------------------------
  3901 const TypeFunc *TypeFunc::make(ciMethod* method) {
  3902   Compile* C = Compile::current();
  3903   const TypeFunc* tf = C->last_tf(method); // check cache
  3904   if (tf != NULL)  return tf;  // The hit rate here is almost 50%.
  3905   const TypeTuple *domain;
  3906   if (method->flags().is_static()) {
  3907     domain = TypeTuple::make_domain(NULL, method->signature());
  3908   } else {
  3909     domain = TypeTuple::make_domain(method->holder(), method->signature());
  3911   const TypeTuple *range  = TypeTuple::make_range(method->signature());
  3912   tf = TypeFunc::make(domain, range);
  3913   C->set_last_tf(method, tf);  // fill cache
  3914   return tf;
  3917 //------------------------------meet-------------------------------------------
  3918 // Compute the MEET of two types.  It returns a new Type object.
  3919 const Type *TypeFunc::xmeet( const Type *t ) const {
  3920   // Perform a fast test for common case; meeting the same types together.
  3921   if( this == t ) return this;  // Meeting same type-rep?
  3923   // Current "this->_base" is Func
  3924   switch (t->base()) {          // switch on original type
  3926   case Bottom:                  // Ye Olde Default
  3927     return t;
  3929   default:                      // All else is a mistake
  3930     typerr(t);
  3932   case Top:
  3933     break;
  3935   return this;                  // Return the double constant
  3938 //------------------------------xdual------------------------------------------
  3939 // Dual: compute field-by-field dual
  3940 const Type *TypeFunc::xdual() const {
  3941   return this;
  3944 //------------------------------eq---------------------------------------------
  3945 // Structural equality check for Type representations
  3946 bool TypeFunc::eq( const Type *t ) const {
  3947   const TypeFunc *a = (const TypeFunc*)t;
  3948   return _domain == a->_domain &&
  3949     _range == a->_range;
  3952 //------------------------------hash-------------------------------------------
  3953 // Type-specific hashing function.
  3954 int TypeFunc::hash(void) const {
  3955   return (intptr_t)_domain + (intptr_t)_range;
  3958 //------------------------------dump2------------------------------------------
  3959 // Dump Function Type
  3960 #ifndef PRODUCT
  3961 void TypeFunc::dump2( Dict &d, uint depth, outputStream *st ) const {
  3962   if( _range->_cnt <= Parms )
  3963     st->print("void");
  3964   else {
  3965     uint i;
  3966     for (i = Parms; i < _range->_cnt-1; i++) {
  3967       _range->field_at(i)->dump2(d,depth,st);
  3968       st->print("/");
  3970     _range->field_at(i)->dump2(d,depth,st);
  3972   st->print(" ");
  3973   st->print("( ");
  3974   if( !depth || d[this] ) {     // Check for recursive dump
  3975     st->print("...)");
  3976     return;
  3978   d.Insert((void*)this,(void*)this);    // Stop recursion
  3979   if (Parms < _domain->_cnt)
  3980     _domain->field_at(Parms)->dump2(d,depth-1,st);
  3981   for (uint i = Parms+1; i < _domain->_cnt; i++) {
  3982     st->print(", ");
  3983     _domain->field_at(i)->dump2(d,depth-1,st);
  3985   st->print(" )");
  3988 //------------------------------print_flattened--------------------------------
  3989 // Print a 'flattened' signature
  3990 static const char * const flat_type_msg[Type::lastype] = {
  3991   "bad","control","top","int","long","_", "narrowoop",
  3992   "tuple:", "array:",
  3993   "ptr", "rawptr", "ptr", "ptr", "ptr", "ptr",
  3994   "func", "abIO", "return_address", "mem",
  3995   "float_top", "ftcon:", "flt",
  3996   "double_top", "dblcon:", "dbl",
  3997   "bottom"
  3998 };
  4000 void TypeFunc::print_flattened() const {
  4001   if( _range->_cnt <= Parms )
  4002     tty->print("void");
  4003   else {
  4004     uint i;
  4005     for (i = Parms; i < _range->_cnt-1; i++)
  4006       tty->print("%s/",flat_type_msg[_range->field_at(i)->base()]);
  4007     tty->print("%s",flat_type_msg[_range->field_at(i)->base()]);
  4009   tty->print(" ( ");
  4010   if (Parms < _domain->_cnt)
  4011     tty->print("%s",flat_type_msg[_domain->field_at(Parms)->base()]);
  4012   for (uint i = Parms+1; i < _domain->_cnt; i++)
  4013     tty->print(", %s",flat_type_msg[_domain->field_at(i)->base()]);
  4014   tty->print(" )");
  4016 #endif
  4018 //------------------------------singleton--------------------------------------
  4019 // TRUE if Type is a singleton type, FALSE otherwise.   Singletons are simple
  4020 // constants (Ldi nodes).  Singletons are integer, float or double constants
  4021 // or a single symbol.
  4022 bool TypeFunc::singleton(void) const {
  4023   return false;                 // Never a singleton
  4026 bool TypeFunc::empty(void) const {
  4027   return false;                 // Never empty
  4031 BasicType TypeFunc::return_type() const{
  4032   if (range()->cnt() == TypeFunc::Parms) {
  4033     return T_VOID;
  4035   return range()->field_at(TypeFunc::Parms)->basic_type();

mercurial