type.cpp revision 9099:115188e14c15
1/*
2 * Copyright (c) 1997, 2015, Oracle and/or its affiliates. All rights reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * This code is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation.
8 *
9 * This code is distributed in the hope that it will be useful, but WITHOUT
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
12 * version 2 for more details (a copy is included in the LICENSE file that
13 * accompanied this code).
14 *
15 * You should have received a copy of the GNU General Public License version
16 * 2 along with this work; if not, write to the Free Software Foundation,
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18 *
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20 * or visit www.oracle.com if you need additional information or have any
21 * questions.
22 *
23 */
24
25#include "precompiled.hpp"
26#include "ci/ciMethodData.hpp"
27#include "ci/ciTypeFlow.hpp"
28#include "classfile/symbolTable.hpp"
29#include "classfile/systemDictionary.hpp"
30#include "compiler/compileLog.hpp"
31#include "gc/shared/gcLocker.hpp"
32#include "libadt/dict.hpp"
33#include "memory/oopFactory.hpp"
34#include "memory/resourceArea.hpp"
35#include "oops/instanceKlass.hpp"
36#include "oops/instanceMirrorKlass.hpp"
37#include "oops/objArrayKlass.hpp"
38#include "oops/typeArrayKlass.hpp"
39#include "opto/matcher.hpp"
40#include "opto/node.hpp"
41#include "opto/opcodes.hpp"
42#include "opto/type.hpp"
43
44// Portions of code courtesy of Clifford Click
45
46// Optimization - Graph Style
47
48// Dictionary of types shared among compilations.
49Dict* Type::_shared_type_dict = NULL;
50
51// Array which maps compiler types to Basic Types
52Type::TypeInfo Type::_type_info[Type::lastype] = {
53  { Bad,             T_ILLEGAL,    "bad",           false, Node::NotAMachineReg, relocInfo::none          },  // Bad
54  { Control,         T_ILLEGAL,    "control",       false, 0,                    relocInfo::none          },  // Control
55  { Bottom,          T_VOID,       "top",           false, 0,                    relocInfo::none          },  // Top
56  { Bad,             T_INT,        "int:",          false, Op_RegI,              relocInfo::none          },  // Int
57  { Bad,             T_LONG,       "long:",         false, Op_RegL,              relocInfo::none          },  // Long
58  { Half,            T_VOID,       "half",          false, 0,                    relocInfo::none          },  // Half
59  { Bad,             T_NARROWOOP,  "narrowoop:",    false, Op_RegN,              relocInfo::none          },  // NarrowOop
60  { Bad,             T_NARROWKLASS,"narrowklass:",  false, Op_RegN,              relocInfo::none          },  // NarrowKlass
61  { Bad,             T_ILLEGAL,    "tuple:",        false, Node::NotAMachineReg, relocInfo::none          },  // Tuple
62  { Bad,             T_ARRAY,      "array:",        false, Node::NotAMachineReg, relocInfo::none          },  // Array
63
64#ifdef SPARC
65  { Bad,             T_ILLEGAL,    "vectors:",      false, 0,                    relocInfo::none          },  // VectorS
66  { Bad,             T_ILLEGAL,    "vectord:",      false, Op_RegD,              relocInfo::none          },  // VectorD
67  { Bad,             T_ILLEGAL,    "vectorx:",      false, 0,                    relocInfo::none          },  // VectorX
68  { Bad,             T_ILLEGAL,    "vectory:",      false, 0,                    relocInfo::none          },  // VectorY
69  { Bad,             T_ILLEGAL,    "vectorz:",      false, 0,                    relocInfo::none          },  // VectorZ
70#elif defined(PPC64)
71  { Bad,             T_ILLEGAL,    "vectors:",      false, 0,                    relocInfo::none          },  // VectorS
72  { Bad,             T_ILLEGAL,    "vectord:",      false, Op_RegL,              relocInfo::none          },  // VectorD
73  { Bad,             T_ILLEGAL,    "vectorx:",      false, 0,                    relocInfo::none          },  // VectorX
74  { Bad,             T_ILLEGAL,    "vectory:",      false, 0,                    relocInfo::none          },  // VectorY
75  { Bad,             T_ILLEGAL,    "vectorz:",      false, 0,                    relocInfo::none          },  // VectorZ
76#else // all other
77  { Bad,             T_ILLEGAL,    "vectors:",      false, Op_VecS,              relocInfo::none          },  // VectorS
78  { Bad,             T_ILLEGAL,    "vectord:",      false, Op_VecD,              relocInfo::none          },  // VectorD
79  { Bad,             T_ILLEGAL,    "vectorx:",      false, Op_VecX,              relocInfo::none          },  // VectorX
80  { Bad,             T_ILLEGAL,    "vectory:",      false, Op_VecY,              relocInfo::none          },  // VectorY
81  { Bad,             T_ILLEGAL,    "vectorz:",      false, Op_VecZ,              relocInfo::none          },  // VectorZ
82#endif
83  { Bad,             T_ADDRESS,    "anyptr:",       false, Op_RegP,              relocInfo::none          },  // AnyPtr
84  { Bad,             T_ADDRESS,    "rawptr:",       false, Op_RegP,              relocInfo::none          },  // RawPtr
85  { Bad,             T_OBJECT,     "oop:",          true,  Op_RegP,              relocInfo::oop_type      },  // OopPtr
86  { Bad,             T_OBJECT,     "inst:",         true,  Op_RegP,              relocInfo::oop_type      },  // InstPtr
87  { Bad,             T_OBJECT,     "ary:",          true,  Op_RegP,              relocInfo::oop_type      },  // AryPtr
88  { Bad,             T_METADATA,   "metadata:",     false, Op_RegP,              relocInfo::metadata_type },  // MetadataPtr
89  { Bad,             T_METADATA,   "klass:",        false, Op_RegP,              relocInfo::metadata_type },  // KlassPtr
90  { Bad,             T_OBJECT,     "func",          false, 0,                    relocInfo::none          },  // Function
91  { Abio,            T_ILLEGAL,    "abIO",          false, 0,                    relocInfo::none          },  // Abio
92  { Return_Address,  T_ADDRESS,    "return_address",false, Op_RegP,              relocInfo::none          },  // Return_Address
93  { Memory,          T_ILLEGAL,    "memory",        false, 0,                    relocInfo::none          },  // Memory
94  { FloatBot,        T_FLOAT,      "float_top",     false, Op_RegF,              relocInfo::none          },  // FloatTop
95  { FloatCon,        T_FLOAT,      "ftcon:",        false, Op_RegF,              relocInfo::none          },  // FloatCon
96  { FloatTop,        T_FLOAT,      "float",         false, Op_RegF,              relocInfo::none          },  // FloatBot
97  { DoubleBot,       T_DOUBLE,     "double_top",    false, Op_RegD,              relocInfo::none          },  // DoubleTop
98  { DoubleCon,       T_DOUBLE,     "dblcon:",       false, Op_RegD,              relocInfo::none          },  // DoubleCon
99  { DoubleTop,       T_DOUBLE,     "double",        false, Op_RegD,              relocInfo::none          },  // DoubleBot
100  { Top,             T_ILLEGAL,    "bottom",        false, 0,                    relocInfo::none          }   // Bottom
101};
102
103// Map ideal registers (machine types) to ideal types
104const Type *Type::mreg2type[_last_machine_leaf];
105
106// Map basic types to canonical Type* pointers.
107const Type* Type::     _const_basic_type[T_CONFLICT+1];
108
109// Map basic types to constant-zero Types.
110const Type* Type::            _zero_type[T_CONFLICT+1];
111
112// Map basic types to array-body alias types.
113const TypeAryPtr* TypeAryPtr::_array_body_type[T_CONFLICT+1];
114
115//=============================================================================
116// Convenience common pre-built types.
117const Type *Type::ABIO;         // State-of-machine only
118const Type *Type::BOTTOM;       // All values
119const Type *Type::CONTROL;      // Control only
120const Type *Type::DOUBLE;       // All doubles
121const Type *Type::FLOAT;        // All floats
122const Type *Type::HALF;         // Placeholder half of doublewide type
123const Type *Type::MEMORY;       // Abstract store only
124const Type *Type::RETURN_ADDRESS;
125const Type *Type::TOP;          // No values in set
126
127//------------------------------get_const_type---------------------------
128const Type* Type::get_const_type(ciType* type) {
129  if (type == NULL) {
130    return NULL;
131  } else if (type->is_primitive_type()) {
132    return get_const_basic_type(type->basic_type());
133  } else {
134    return TypeOopPtr::make_from_klass(type->as_klass());
135  }
136}
137
138//---------------------------array_element_basic_type---------------------------------
139// Mapping to the array element's basic type.
140BasicType Type::array_element_basic_type() const {
141  BasicType bt = basic_type();
142  if (bt == T_INT) {
143    if (this == TypeInt::INT)   return T_INT;
144    if (this == TypeInt::CHAR)  return T_CHAR;
145    if (this == TypeInt::BYTE)  return T_BYTE;
146    if (this == TypeInt::BOOL)  return T_BOOLEAN;
147    if (this == TypeInt::SHORT) return T_SHORT;
148    return T_VOID;
149  }
150  return bt;
151}
152
153//---------------------------get_typeflow_type---------------------------------
154// Import a type produced by ciTypeFlow.
155const Type* Type::get_typeflow_type(ciType* type) {
156  switch (type->basic_type()) {
157
158  case ciTypeFlow::StateVector::T_BOTTOM:
159    assert(type == ciTypeFlow::StateVector::bottom_type(), "");
160    return Type::BOTTOM;
161
162  case ciTypeFlow::StateVector::T_TOP:
163    assert(type == ciTypeFlow::StateVector::top_type(), "");
164    return Type::TOP;
165
166  case ciTypeFlow::StateVector::T_NULL:
167    assert(type == ciTypeFlow::StateVector::null_type(), "");
168    return TypePtr::NULL_PTR;
169
170  case ciTypeFlow::StateVector::T_LONG2:
171    // The ciTypeFlow pass pushes a long, then the half.
172    // We do the same.
173    assert(type == ciTypeFlow::StateVector::long2_type(), "");
174    return TypeInt::TOP;
175
176  case ciTypeFlow::StateVector::T_DOUBLE2:
177    // The ciTypeFlow pass pushes double, then the half.
178    // Our convention is the same.
179    assert(type == ciTypeFlow::StateVector::double2_type(), "");
180    return Type::TOP;
181
182  case T_ADDRESS:
183    assert(type->is_return_address(), "");
184    return TypeRawPtr::make((address)(intptr_t)type->as_return_address()->bci());
185
186  default:
187    // make sure we did not mix up the cases:
188    assert(type != ciTypeFlow::StateVector::bottom_type(), "");
189    assert(type != ciTypeFlow::StateVector::top_type(), "");
190    assert(type != ciTypeFlow::StateVector::null_type(), "");
191    assert(type != ciTypeFlow::StateVector::long2_type(), "");
192    assert(type != ciTypeFlow::StateVector::double2_type(), "");
193    assert(!type->is_return_address(), "");
194
195    return Type::get_const_type(type);
196  }
197}
198
199
200//-----------------------make_from_constant------------------------------------
201const Type* Type::make_from_constant(ciConstant constant, bool require_constant) {
202  switch (constant.basic_type()) {
203  case T_BOOLEAN:  return TypeInt::make(constant.as_boolean());
204  case T_CHAR:     return TypeInt::make(constant.as_char());
205  case T_BYTE:     return TypeInt::make(constant.as_byte());
206  case T_SHORT:    return TypeInt::make(constant.as_short());
207  case T_INT:      return TypeInt::make(constant.as_int());
208  case T_LONG:     return TypeLong::make(constant.as_long());
209  case T_FLOAT:    return TypeF::make(constant.as_float());
210  case T_DOUBLE:   return TypeD::make(constant.as_double());
211  case T_ARRAY:
212  case T_OBJECT:
213    {
214      // cases:
215      //   can_be_constant    = (oop not scavengable || ScavengeRootsInCode != 0)
216      //   should_be_constant = (oop not scavengable || ScavengeRootsInCode >= 2)
217      // An oop is not scavengable if it is in the perm gen.
218      ciObject* oop_constant = constant.as_object();
219      if (oop_constant->is_null_object()) {
220        return Type::get_zero_type(T_OBJECT);
221      } else if (require_constant || oop_constant->should_be_constant()) {
222        return TypeOopPtr::make_from_constant(oop_constant, require_constant);
223      }
224    }
225  case T_ILLEGAL:
226    // Invalid ciConstant returned due to OutOfMemoryError in the CI
227    assert(Compile::current()->env()->failing(), "otherwise should not see this");
228    return NULL;
229  }
230  // Fall through to failure
231  return NULL;
232}
233
234
235const Type* Type::make_constant(ciField* field, Node* obj) {
236  if (!field->is_constant())  return NULL;
237
238  const Type* con_type = NULL;
239  if (field->is_static()) {
240    // final static field
241    con_type = Type::make_from_constant(field->constant_value(), /*require_const=*/true);
242    if (Compile::current()->eliminate_boxing() && field->is_autobox_cache() && con_type != NULL) {
243      con_type = con_type->is_aryptr()->cast_to_autobox_cache(true);
244    }
245  } else {
246    // final or stable non-static field
247    // Treat final non-static fields of trusted classes (classes in
248    // java.lang.invoke and sun.invoke packages and subpackages) as
249    // compile time constants.
250    if (obj->is_Con()) {
251      const TypeOopPtr* oop_ptr = obj->bottom_type()->isa_oopptr();
252      ciObject* constant_oop = oop_ptr->const_oop();
253      ciConstant constant = field->constant_value_of(constant_oop);
254      con_type = Type::make_from_constant(constant, /*require_const=*/true);
255    }
256  }
257  if (FoldStableValues && field->is_stable() && con_type != NULL) {
258    if (con_type->is_zero_type()) {
259      return NULL; // the field hasn't been initialized yet
260    } else if (con_type->isa_oopptr()) {
261      const Type* stable_type = Type::get_const_type(field->type());
262      if (field->type()->is_array_klass()) {
263        int stable_dimension = field->type()->as_array_klass()->dimension();
264        stable_type = stable_type->is_aryptr()->cast_to_stable(true, stable_dimension);
265      }
266      if (stable_type != NULL) {
267        con_type = con_type->join_speculative(stable_type);
268      }
269    }
270  }
271  return con_type;
272}
273
274//------------------------------make-------------------------------------------
275// Create a simple Type, with default empty symbol sets.  Then hashcons it
276// and look for an existing copy in the type dictionary.
277const Type *Type::make( enum TYPES t ) {
278  return (new Type(t))->hashcons();
279}
280
281//------------------------------cmp--------------------------------------------
282int Type::cmp( const Type *const t1, const Type *const t2 ) {
283  if( t1->_base != t2->_base )
284    return 1;                   // Missed badly
285  assert(t1 != t2 || t1->eq(t2), "eq must be reflexive");
286  return !t1->eq(t2);           // Return ZERO if equal
287}
288
289const Type* Type::maybe_remove_speculative(bool include_speculative) const {
290  if (!include_speculative) {
291    return remove_speculative();
292  }
293  return this;
294}
295
296//------------------------------hash-------------------------------------------
297int Type::uhash( const Type *const t ) {
298  return t->hash();
299}
300
301#define SMALLINT ((juint)3)  // a value too insignificant to consider widening
302
303//--------------------------Initialize_shared----------------------------------
304void Type::Initialize_shared(Compile* current) {
305  // This method does not need to be locked because the first system
306  // compilations (stub compilations) occur serially.  If they are
307  // changed to proceed in parallel, then this section will need
308  // locking.
309
310  Arena* save = current->type_arena();
311  Arena* shared_type_arena = new (mtCompiler)Arena(mtCompiler);
312
313  current->set_type_arena(shared_type_arena);
314  _shared_type_dict =
315    new (shared_type_arena) Dict( (CmpKey)Type::cmp, (Hash)Type::uhash,
316                                  shared_type_arena, 128 );
317  current->set_type_dict(_shared_type_dict);
318
319  // Make shared pre-built types.
320  CONTROL = make(Control);      // Control only
321  TOP     = make(Top);          // No values in set
322  MEMORY  = make(Memory);       // Abstract store only
323  ABIO    = make(Abio);         // State-of-machine only
324  RETURN_ADDRESS=make(Return_Address);
325  FLOAT   = make(FloatBot);     // All floats
326  DOUBLE  = make(DoubleBot);    // All doubles
327  BOTTOM  = make(Bottom);       // Everything
328  HALF    = make(Half);         // Placeholder half of doublewide type
329
330  TypeF::ZERO = TypeF::make(0.0); // Float 0 (positive zero)
331  TypeF::ONE  = TypeF::make(1.0); // Float 1
332
333  TypeD::ZERO = TypeD::make(0.0); // Double 0 (positive zero)
334  TypeD::ONE  = TypeD::make(1.0); // Double 1
335
336  TypeInt::MINUS_1 = TypeInt::make(-1);  // -1
337  TypeInt::ZERO    = TypeInt::make( 0);  //  0
338  TypeInt::ONE     = TypeInt::make( 1);  //  1
339  TypeInt::BOOL    = TypeInt::make(0,1,   WidenMin);  // 0 or 1, FALSE or TRUE.
340  TypeInt::CC      = TypeInt::make(-1, 1, WidenMin);  // -1, 0 or 1, condition codes
341  TypeInt::CC_LT   = TypeInt::make(-1,-1, WidenMin);  // == TypeInt::MINUS_1
342  TypeInt::CC_GT   = TypeInt::make( 1, 1, WidenMin);  // == TypeInt::ONE
343  TypeInt::CC_EQ   = TypeInt::make( 0, 0, WidenMin);  // == TypeInt::ZERO
344  TypeInt::CC_LE   = TypeInt::make(-1, 0, WidenMin);
345  TypeInt::CC_GE   = TypeInt::make( 0, 1, WidenMin);  // == TypeInt::BOOL
346  TypeInt::BYTE    = TypeInt::make(-128,127,     WidenMin); // Bytes
347  TypeInt::UBYTE   = TypeInt::make(0, 255,       WidenMin); // Unsigned Bytes
348  TypeInt::CHAR    = TypeInt::make(0,65535,      WidenMin); // Java chars
349  TypeInt::SHORT   = TypeInt::make(-32768,32767, WidenMin); // Java shorts
350  TypeInt::POS     = TypeInt::make(0,max_jint,   WidenMin); // Non-neg values
351  TypeInt::POS1    = TypeInt::make(1,max_jint,   WidenMin); // Positive values
352  TypeInt::INT     = TypeInt::make(min_jint,max_jint, WidenMax); // 32-bit integers
353  TypeInt::SYMINT  = TypeInt::make(-max_jint,max_jint,WidenMin); // symmetric range
354  TypeInt::TYPE_DOMAIN  = TypeInt::INT;
355  // CmpL is overloaded both as the bytecode computation returning
356  // a trinary (-1,0,+1) integer result AND as an efficient long
357  // compare returning optimizer ideal-type flags.
358  assert( TypeInt::CC_LT == TypeInt::MINUS_1, "types must match for CmpL to work" );
359  assert( TypeInt::CC_GT == TypeInt::ONE,     "types must match for CmpL to work" );
360  assert( TypeInt::CC_EQ == TypeInt::ZERO,    "types must match for CmpL to work" );
361  assert( TypeInt::CC_GE == TypeInt::BOOL,    "types must match for CmpL to work" );
362  assert( (juint)(TypeInt::CC->_hi - TypeInt::CC->_lo) <= SMALLINT, "CC is truly small");
363
364  TypeLong::MINUS_1 = TypeLong::make(-1);        // -1
365  TypeLong::ZERO    = TypeLong::make( 0);        //  0
366  TypeLong::ONE     = TypeLong::make( 1);        //  1
367  TypeLong::POS     = TypeLong::make(0,max_jlong, WidenMin); // Non-neg values
368  TypeLong::LONG    = TypeLong::make(min_jlong,max_jlong,WidenMax); // 64-bit integers
369  TypeLong::INT     = TypeLong::make((jlong)min_jint,(jlong)max_jint,WidenMin);
370  TypeLong::UINT    = TypeLong::make(0,(jlong)max_juint,WidenMin);
371  TypeLong::TYPE_DOMAIN  = TypeLong::LONG;
372
373  const Type **fboth =(const Type**)shared_type_arena->Amalloc_4(2*sizeof(Type*));
374  fboth[0] = Type::CONTROL;
375  fboth[1] = Type::CONTROL;
376  TypeTuple::IFBOTH = TypeTuple::make( 2, fboth );
377
378  const Type **ffalse =(const Type**)shared_type_arena->Amalloc_4(2*sizeof(Type*));
379  ffalse[0] = Type::CONTROL;
380  ffalse[1] = Type::TOP;
381  TypeTuple::IFFALSE = TypeTuple::make( 2, ffalse );
382
383  const Type **fneither =(const Type**)shared_type_arena->Amalloc_4(2*sizeof(Type*));
384  fneither[0] = Type::TOP;
385  fneither[1] = Type::TOP;
386  TypeTuple::IFNEITHER = TypeTuple::make( 2, fneither );
387
388  const Type **ftrue =(const Type**)shared_type_arena->Amalloc_4(2*sizeof(Type*));
389  ftrue[0] = Type::TOP;
390  ftrue[1] = Type::CONTROL;
391  TypeTuple::IFTRUE = TypeTuple::make( 2, ftrue );
392
393  const Type **floop =(const Type**)shared_type_arena->Amalloc_4(2*sizeof(Type*));
394  floop[0] = Type::CONTROL;
395  floop[1] = TypeInt::INT;
396  TypeTuple::LOOPBODY = TypeTuple::make( 2, floop );
397
398  TypePtr::NULL_PTR= TypePtr::make(AnyPtr, TypePtr::Null, 0);
399  TypePtr::NOTNULL = TypePtr::make(AnyPtr, TypePtr::NotNull, OffsetBot);
400  TypePtr::BOTTOM  = TypePtr::make(AnyPtr, TypePtr::BotPTR, OffsetBot);
401
402  TypeRawPtr::BOTTOM = TypeRawPtr::make( TypePtr::BotPTR );
403  TypeRawPtr::NOTNULL= TypeRawPtr::make( TypePtr::NotNull );
404
405  const Type **fmembar = TypeTuple::fields(0);
406  TypeTuple::MEMBAR = TypeTuple::make(TypeFunc::Parms+0, fmembar);
407
408  const Type **fsc = (const Type**)shared_type_arena->Amalloc_4(2*sizeof(Type*));
409  fsc[0] = TypeInt::CC;
410  fsc[1] = Type::MEMORY;
411  TypeTuple::STORECONDITIONAL = TypeTuple::make(2, fsc);
412
413  TypeInstPtr::NOTNULL = TypeInstPtr::make(TypePtr::NotNull, current->env()->Object_klass());
414  TypeInstPtr::BOTTOM  = TypeInstPtr::make(TypePtr::BotPTR,  current->env()->Object_klass());
415  TypeInstPtr::MIRROR  = TypeInstPtr::make(TypePtr::NotNull, current->env()->Class_klass());
416  TypeInstPtr::MARK    = TypeInstPtr::make(TypePtr::BotPTR,  current->env()->Object_klass(),
417                                           false, 0, oopDesc::mark_offset_in_bytes());
418  TypeInstPtr::KLASS   = TypeInstPtr::make(TypePtr::BotPTR,  current->env()->Object_klass(),
419                                           false, 0, oopDesc::klass_offset_in_bytes());
420  TypeOopPtr::BOTTOM  = TypeOopPtr::make(TypePtr::BotPTR, OffsetBot, TypeOopPtr::InstanceBot);
421
422  TypeMetadataPtr::BOTTOM = TypeMetadataPtr::make(TypePtr::BotPTR, NULL, OffsetBot);
423
424  TypeNarrowOop::NULL_PTR = TypeNarrowOop::make( TypePtr::NULL_PTR );
425  TypeNarrowOop::BOTTOM   = TypeNarrowOop::make( TypeInstPtr::BOTTOM );
426
427  TypeNarrowKlass::NULL_PTR = TypeNarrowKlass::make( TypePtr::NULL_PTR );
428
429  mreg2type[Op_Node] = Type::BOTTOM;
430  mreg2type[Op_Set ] = 0;
431  mreg2type[Op_RegN] = TypeNarrowOop::BOTTOM;
432  mreg2type[Op_RegI] = TypeInt::INT;
433  mreg2type[Op_RegP] = TypePtr::BOTTOM;
434  mreg2type[Op_RegF] = Type::FLOAT;
435  mreg2type[Op_RegD] = Type::DOUBLE;
436  mreg2type[Op_RegL] = TypeLong::LONG;
437  mreg2type[Op_RegFlags] = TypeInt::CC;
438
439  TypeAryPtr::RANGE   = TypeAryPtr::make( TypePtr::BotPTR, TypeAry::make(Type::BOTTOM,TypeInt::POS), NULL /* current->env()->Object_klass() */, false, arrayOopDesc::length_offset_in_bytes());
440
441  TypeAryPtr::NARROWOOPS = TypeAryPtr::make(TypePtr::BotPTR, TypeAry::make(TypeNarrowOop::BOTTOM, TypeInt::POS), NULL /*ciArrayKlass::make(o)*/,  false,  Type::OffsetBot);
442
443#ifdef _LP64
444  if (UseCompressedOops) {
445    assert(TypeAryPtr::NARROWOOPS->is_ptr_to_narrowoop(), "array of narrow oops must be ptr to narrow oop");
446    TypeAryPtr::OOPS  = TypeAryPtr::NARROWOOPS;
447  } else
448#endif
449  {
450    // There is no shared klass for Object[].  See note in TypeAryPtr::klass().
451    TypeAryPtr::OOPS  = TypeAryPtr::make(TypePtr::BotPTR, TypeAry::make(TypeInstPtr::BOTTOM,TypeInt::POS), NULL /*ciArrayKlass::make(o)*/,  false,  Type::OffsetBot);
452  }
453  TypeAryPtr::BYTES   = TypeAryPtr::make(TypePtr::BotPTR, TypeAry::make(TypeInt::BYTE      ,TypeInt::POS), ciTypeArrayKlass::make(T_BYTE),   true,  Type::OffsetBot);
454  TypeAryPtr::SHORTS  = TypeAryPtr::make(TypePtr::BotPTR, TypeAry::make(TypeInt::SHORT     ,TypeInt::POS), ciTypeArrayKlass::make(T_SHORT),  true,  Type::OffsetBot);
455  TypeAryPtr::CHARS   = TypeAryPtr::make(TypePtr::BotPTR, TypeAry::make(TypeInt::CHAR      ,TypeInt::POS), ciTypeArrayKlass::make(T_CHAR),   true,  Type::OffsetBot);
456  TypeAryPtr::INTS    = TypeAryPtr::make(TypePtr::BotPTR, TypeAry::make(TypeInt::INT       ,TypeInt::POS), ciTypeArrayKlass::make(T_INT),    true,  Type::OffsetBot);
457  TypeAryPtr::LONGS   = TypeAryPtr::make(TypePtr::BotPTR, TypeAry::make(TypeLong::LONG     ,TypeInt::POS), ciTypeArrayKlass::make(T_LONG),   true,  Type::OffsetBot);
458  TypeAryPtr::FLOATS  = TypeAryPtr::make(TypePtr::BotPTR, TypeAry::make(Type::FLOAT        ,TypeInt::POS), ciTypeArrayKlass::make(T_FLOAT),  true,  Type::OffsetBot);
459  TypeAryPtr::DOUBLES = TypeAryPtr::make(TypePtr::BotPTR, TypeAry::make(Type::DOUBLE       ,TypeInt::POS), ciTypeArrayKlass::make(T_DOUBLE), true,  Type::OffsetBot);
460
461  // Nobody should ask _array_body_type[T_NARROWOOP]. Use NULL as assert.
462  TypeAryPtr::_array_body_type[T_NARROWOOP] = NULL;
463  TypeAryPtr::_array_body_type[T_OBJECT]  = TypeAryPtr::OOPS;
464  TypeAryPtr::_array_body_type[T_ARRAY]   = TypeAryPtr::OOPS; // arrays are stored in oop arrays
465  TypeAryPtr::_array_body_type[T_BYTE]    = TypeAryPtr::BYTES;
466  TypeAryPtr::_array_body_type[T_BOOLEAN] = TypeAryPtr::BYTES;  // boolean[] is a byte array
467  TypeAryPtr::_array_body_type[T_SHORT]   = TypeAryPtr::SHORTS;
468  TypeAryPtr::_array_body_type[T_CHAR]    = TypeAryPtr::CHARS;
469  TypeAryPtr::_array_body_type[T_INT]     = TypeAryPtr::INTS;
470  TypeAryPtr::_array_body_type[T_LONG]    = TypeAryPtr::LONGS;
471  TypeAryPtr::_array_body_type[T_FLOAT]   = TypeAryPtr::FLOATS;
472  TypeAryPtr::_array_body_type[T_DOUBLE]  = TypeAryPtr::DOUBLES;
473
474  TypeKlassPtr::OBJECT = TypeKlassPtr::make( TypePtr::NotNull, current->env()->Object_klass(), 0 );
475  TypeKlassPtr::OBJECT_OR_NULL = TypeKlassPtr::make( TypePtr::BotPTR, current->env()->Object_klass(), 0 );
476
477  const Type **fi2c = TypeTuple::fields(2);
478  fi2c[TypeFunc::Parms+0] = TypeInstPtr::BOTTOM; // Method*
479  fi2c[TypeFunc::Parms+1] = TypeRawPtr::BOTTOM; // argument pointer
480  TypeTuple::START_I2C = TypeTuple::make(TypeFunc::Parms+2, fi2c);
481
482  const Type **intpair = TypeTuple::fields(2);
483  intpair[0] = TypeInt::INT;
484  intpair[1] = TypeInt::INT;
485  TypeTuple::INT_PAIR = TypeTuple::make(2, intpair);
486
487  const Type **longpair = TypeTuple::fields(2);
488  longpair[0] = TypeLong::LONG;
489  longpair[1] = TypeLong::LONG;
490  TypeTuple::LONG_PAIR = TypeTuple::make(2, longpair);
491
492  const Type **intccpair = TypeTuple::fields(2);
493  intccpair[0] = TypeInt::INT;
494  intccpair[1] = TypeInt::CC;
495  TypeTuple::INT_CC_PAIR = TypeTuple::make(2, intccpair);
496
497  const Type **longccpair = TypeTuple::fields(2);
498  longccpair[0] = TypeLong::LONG;
499  longccpair[1] = TypeInt::CC;
500  TypeTuple::LONG_CC_PAIR = TypeTuple::make(2, longccpair);
501
502  _const_basic_type[T_NARROWOOP]   = TypeNarrowOop::BOTTOM;
503  _const_basic_type[T_NARROWKLASS] = Type::BOTTOM;
504  _const_basic_type[T_BOOLEAN]     = TypeInt::BOOL;
505  _const_basic_type[T_CHAR]        = TypeInt::CHAR;
506  _const_basic_type[T_BYTE]        = TypeInt::BYTE;
507  _const_basic_type[T_SHORT]       = TypeInt::SHORT;
508  _const_basic_type[T_INT]         = TypeInt::INT;
509  _const_basic_type[T_LONG]        = TypeLong::LONG;
510  _const_basic_type[T_FLOAT]       = Type::FLOAT;
511  _const_basic_type[T_DOUBLE]      = Type::DOUBLE;
512  _const_basic_type[T_OBJECT]      = TypeInstPtr::BOTTOM;
513  _const_basic_type[T_ARRAY]       = TypeInstPtr::BOTTOM; // there is no separate bottom for arrays
514  _const_basic_type[T_VOID]        = TypePtr::NULL_PTR;   // reflection represents void this way
515  _const_basic_type[T_ADDRESS]     = TypeRawPtr::BOTTOM;  // both interpreter return addresses & random raw ptrs
516  _const_basic_type[T_CONFLICT]    = Type::BOTTOM;        // why not?
517
518  _zero_type[T_NARROWOOP]   = TypeNarrowOop::NULL_PTR;
519  _zero_type[T_NARROWKLASS] = TypeNarrowKlass::NULL_PTR;
520  _zero_type[T_BOOLEAN]     = TypeInt::ZERO;     // false == 0
521  _zero_type[T_CHAR]        = TypeInt::ZERO;     // '\0' == 0
522  _zero_type[T_BYTE]        = TypeInt::ZERO;     // 0x00 == 0
523  _zero_type[T_SHORT]       = TypeInt::ZERO;     // 0x0000 == 0
524  _zero_type[T_INT]         = TypeInt::ZERO;
525  _zero_type[T_LONG]        = TypeLong::ZERO;
526  _zero_type[T_FLOAT]       = TypeF::ZERO;
527  _zero_type[T_DOUBLE]      = TypeD::ZERO;
528  _zero_type[T_OBJECT]      = TypePtr::NULL_PTR;
529  _zero_type[T_ARRAY]       = TypePtr::NULL_PTR; // null array is null oop
530  _zero_type[T_ADDRESS]     = TypePtr::NULL_PTR; // raw pointers use the same null
531  _zero_type[T_VOID]        = Type::TOP;         // the only void value is no value at all
532
533  // get_zero_type() should not happen for T_CONFLICT
534  _zero_type[T_CONFLICT]= NULL;
535
536  // Vector predefined types, it needs initialized _const_basic_type[].
537  if (Matcher::vector_size_supported(T_BYTE,4)) {
538    TypeVect::VECTS = TypeVect::make(T_BYTE,4);
539  }
540  if (Matcher::vector_size_supported(T_FLOAT,2)) {
541    TypeVect::VECTD = TypeVect::make(T_FLOAT,2);
542  }
543  if (Matcher::vector_size_supported(T_FLOAT,4)) {
544    TypeVect::VECTX = TypeVect::make(T_FLOAT,4);
545  }
546  if (Matcher::vector_size_supported(T_FLOAT,8)) {
547    TypeVect::VECTY = TypeVect::make(T_FLOAT,8);
548  }
549  if (Matcher::vector_size_supported(T_FLOAT,16)) {
550    TypeVect::VECTZ = TypeVect::make(T_FLOAT,16);
551  }
552  mreg2type[Op_VecS] = TypeVect::VECTS;
553  mreg2type[Op_VecD] = TypeVect::VECTD;
554  mreg2type[Op_VecX] = TypeVect::VECTX;
555  mreg2type[Op_VecY] = TypeVect::VECTY;
556  mreg2type[Op_VecZ] = TypeVect::VECTZ;
557
558  // Restore working type arena.
559  current->set_type_arena(save);
560  current->set_type_dict(NULL);
561}
562
563//------------------------------Initialize-------------------------------------
564void Type::Initialize(Compile* current) {
565  assert(current->type_arena() != NULL, "must have created type arena");
566
567  if (_shared_type_dict == NULL) {
568    Initialize_shared(current);
569  }
570
571  Arena* type_arena = current->type_arena();
572
573  // Create the hash-cons'ing dictionary with top-level storage allocation
574  Dict *tdic = new (type_arena) Dict( (CmpKey)Type::cmp,(Hash)Type::uhash, type_arena, 128 );
575  current->set_type_dict(tdic);
576
577  // Transfer the shared types.
578  DictI i(_shared_type_dict);
579  for( ; i.test(); ++i ) {
580    Type* t = (Type*)i._value;
581    tdic->Insert(t,t);  // New Type, insert into Type table
582  }
583}
584
585//------------------------------hashcons---------------------------------------
586// Do the hash-cons trick.  If the Type already exists in the type table,
587// delete the current Type and return the existing Type.  Otherwise stick the
588// current Type in the Type table.
589const Type *Type::hashcons(void) {
590  debug_only(base());           // Check the assertion in Type::base().
591  // Look up the Type in the Type dictionary
592  Dict *tdic = type_dict();
593  Type* old = (Type*)(tdic->Insert(this, this, false));
594  if( old ) {                   // Pre-existing Type?
595    if( old != this )           // Yes, this guy is not the pre-existing?
596      delete this;              // Yes, Nuke this guy
597    assert( old->_dual, "" );
598    return old;                 // Return pre-existing
599  }
600
601  // Every type has a dual (to make my lattice symmetric).
602  // Since we just discovered a new Type, compute its dual right now.
603  assert( !_dual, "" );         // No dual yet
604  _dual = xdual();              // Compute the dual
605  if( cmp(this,_dual)==0 ) {    // Handle self-symmetric
606    _dual = this;
607    return this;
608  }
609  assert( !_dual->_dual, "" );  // No reverse dual yet
610  assert( !(*tdic)[_dual], "" ); // Dual not in type system either
611  // New Type, insert into Type table
612  tdic->Insert((void*)_dual,(void*)_dual);
613  ((Type*)_dual)->_dual = this; // Finish up being symmetric
614#ifdef ASSERT
615  Type *dual_dual = (Type*)_dual->xdual();
616  assert( eq(dual_dual), "xdual(xdual()) should be identity" );
617  delete dual_dual;
618#endif
619  return this;                  // Return new Type
620}
621
622//------------------------------eq---------------------------------------------
623// Structural equality check for Type representations
624bool Type::eq( const Type * ) const {
625  return true;                  // Nothing else can go wrong
626}
627
628//------------------------------hash-------------------------------------------
629// Type-specific hashing function.
630int Type::hash(void) const {
631  return _base;
632}
633
634//------------------------------is_finite--------------------------------------
635// Has a finite value
636bool Type::is_finite() const {
637  return false;
638}
639
640//------------------------------is_nan-----------------------------------------
641// Is not a number (NaN)
642bool Type::is_nan()    const {
643  return false;
644}
645
646//----------------------interface_vs_oop---------------------------------------
647#ifdef ASSERT
648bool Type::interface_vs_oop_helper(const Type *t) const {
649  bool result = false;
650
651  const TypePtr* this_ptr = this->make_ptr(); // In case it is narrow_oop
652  const TypePtr*    t_ptr =    t->make_ptr();
653  if( this_ptr == NULL || t_ptr == NULL )
654    return result;
655
656  const TypeInstPtr* this_inst = this_ptr->isa_instptr();
657  const TypeInstPtr*    t_inst =    t_ptr->isa_instptr();
658  if( this_inst && this_inst->is_loaded() && t_inst && t_inst->is_loaded() ) {
659    bool this_interface = this_inst->klass()->is_interface();
660    bool    t_interface =    t_inst->klass()->is_interface();
661    result = this_interface ^ t_interface;
662  }
663
664  return result;
665}
666
667bool Type::interface_vs_oop(const Type *t) const {
668  if (interface_vs_oop_helper(t)) {
669    return true;
670  }
671  // Now check the speculative parts as well
672  const TypePtr* this_spec = isa_ptr() != NULL ? is_ptr()->speculative() : NULL;
673  const TypePtr* t_spec = t->isa_ptr() != NULL ? t->is_ptr()->speculative() : NULL;
674  if (this_spec != NULL && t_spec != NULL) {
675    if (this_spec->interface_vs_oop_helper(t_spec)) {
676      return true;
677    }
678    return false;
679  }
680  if (this_spec != NULL && this_spec->interface_vs_oop_helper(t)) {
681    return true;
682  }
683  if (t_spec != NULL && interface_vs_oop_helper(t_spec)) {
684    return true;
685  }
686  return false;
687}
688
689#endif
690
691//------------------------------meet-------------------------------------------
692// Compute the MEET of two types.  NOT virtual.  It enforces that meet is
693// commutative and the lattice is symmetric.
694const Type *Type::meet_helper(const Type *t, bool include_speculative) const {
695  if (isa_narrowoop() && t->isa_narrowoop()) {
696    const Type* result = make_ptr()->meet_helper(t->make_ptr(), include_speculative);
697    return result->make_narrowoop();
698  }
699  if (isa_narrowklass() && t->isa_narrowklass()) {
700    const Type* result = make_ptr()->meet_helper(t->make_ptr(), include_speculative);
701    return result->make_narrowklass();
702  }
703
704  const Type *this_t = maybe_remove_speculative(include_speculative);
705  t = t->maybe_remove_speculative(include_speculative);
706
707  const Type *mt = this_t->xmeet(t);
708  if (isa_narrowoop() || t->isa_narrowoop()) return mt;
709  if (isa_narrowklass() || t->isa_narrowklass()) return mt;
710#ifdef ASSERT
711  assert(mt == t->xmeet(this_t), "meet not commutative");
712  const Type* dual_join = mt->_dual;
713  const Type *t2t    = dual_join->xmeet(t->_dual);
714  const Type *t2this = dual_join->xmeet(this_t->_dual);
715
716  // Interface meet Oop is Not Symmetric:
717  // Interface:AnyNull meet Oop:AnyNull == Interface:AnyNull
718  // Interface:NotNull meet Oop:NotNull == java/lang/Object:NotNull
719
720  if( !interface_vs_oop(t) && (t2t != t->_dual || t2this != this_t->_dual) ) {
721    tty->print_cr("=== Meet Not Symmetric ===");
722    tty->print("t   =                   ");              t->dump(); tty->cr();
723    tty->print("this=                   ");         this_t->dump(); tty->cr();
724    tty->print("mt=(t meet this)=       ");             mt->dump(); tty->cr();
725
726    tty->print("t_dual=                 ");       t->_dual->dump(); tty->cr();
727    tty->print("this_dual=              ");  this_t->_dual->dump(); tty->cr();
728    tty->print("mt_dual=                ");      mt->_dual->dump(); tty->cr();
729
730    tty->print("mt_dual meet t_dual=    "); t2t           ->dump(); tty->cr();
731    tty->print("mt_dual meet this_dual= "); t2this        ->dump(); tty->cr();
732
733    fatal("meet not symmetric" );
734  }
735#endif
736  return mt;
737}
738
739//------------------------------xmeet------------------------------------------
740// Compute the MEET of two types.  It returns a new Type object.
741const Type *Type::xmeet( const Type *t ) const {
742  // Perform a fast test for common case; meeting the same types together.
743  if( this == t ) return this;  // Meeting same type-rep?
744
745  // Meeting TOP with anything?
746  if( _base == Top ) return t;
747
748  // Meeting BOTTOM with anything?
749  if( _base == Bottom ) return BOTTOM;
750
751  // Current "this->_base" is one of: Bad, Multi, Control, Top,
752  // Abio, Abstore, Floatxxx, Doublexxx, Bottom, lastype.
753  switch (t->base()) {  // Switch on original type
754
755  // Cut in half the number of cases I must handle.  Only need cases for when
756  // the given enum "t->type" is less than or equal to the local enum "type".
757  case FloatCon:
758  case DoubleCon:
759  case Int:
760  case Long:
761    return t->xmeet(this);
762
763  case OopPtr:
764    return t->xmeet(this);
765
766  case InstPtr:
767    return t->xmeet(this);
768
769  case MetadataPtr:
770  case KlassPtr:
771    return t->xmeet(this);
772
773  case AryPtr:
774    return t->xmeet(this);
775
776  case NarrowOop:
777    return t->xmeet(this);
778
779  case NarrowKlass:
780    return t->xmeet(this);
781
782  case Bad:                     // Type check
783  default:                      // Bogus type not in lattice
784    typerr(t);
785    return Type::BOTTOM;
786
787  case Bottom:                  // Ye Olde Default
788    return t;
789
790  case FloatTop:
791    if( _base == FloatTop ) return this;
792  case FloatBot:                // Float
793    if( _base == FloatBot || _base == FloatTop ) return FLOAT;
794    if( _base == DoubleTop || _base == DoubleBot ) return Type::BOTTOM;
795    typerr(t);
796    return Type::BOTTOM;
797
798  case DoubleTop:
799    if( _base == DoubleTop ) return this;
800  case DoubleBot:               // Double
801    if( _base == DoubleBot || _base == DoubleTop ) return DOUBLE;
802    if( _base == FloatTop || _base == FloatBot ) return Type::BOTTOM;
803    typerr(t);
804    return Type::BOTTOM;
805
806  // These next few cases must match exactly or it is a compile-time error.
807  case Control:                 // Control of code
808  case Abio:                    // State of world outside of program
809  case Memory:
810    if( _base == t->_base )  return this;
811    typerr(t);
812    return Type::BOTTOM;
813
814  case Top:                     // Top of the lattice
815    return this;
816  }
817
818  // The type is unchanged
819  return this;
820}
821
822//-----------------------------filter------------------------------------------
823const Type *Type::filter_helper(const Type *kills, bool include_speculative) const {
824  const Type* ft = join_helper(kills, include_speculative);
825  if (ft->empty())
826    return Type::TOP;           // Canonical empty value
827  return ft;
828}
829
830//------------------------------xdual------------------------------------------
831// Compute dual right now.
832const Type::TYPES Type::dual_type[Type::lastype] = {
833  Bad,          // Bad
834  Control,      // Control
835  Bottom,       // Top
836  Bad,          // Int - handled in v-call
837  Bad,          // Long - handled in v-call
838  Half,         // Half
839  Bad,          // NarrowOop - handled in v-call
840  Bad,          // NarrowKlass - handled in v-call
841
842  Bad,          // Tuple - handled in v-call
843  Bad,          // Array - handled in v-call
844  Bad,          // VectorS - handled in v-call
845  Bad,          // VectorD - handled in v-call
846  Bad,          // VectorX - handled in v-call
847  Bad,          // VectorY - handled in v-call
848  Bad,          // VectorZ - handled in v-call
849
850  Bad,          // AnyPtr - handled in v-call
851  Bad,          // RawPtr - handled in v-call
852  Bad,          // OopPtr - handled in v-call
853  Bad,          // InstPtr - handled in v-call
854  Bad,          // AryPtr - handled in v-call
855
856  Bad,          //  MetadataPtr - handled in v-call
857  Bad,          // KlassPtr - handled in v-call
858
859  Bad,          // Function - handled in v-call
860  Abio,         // Abio
861  Return_Address,// Return_Address
862  Memory,       // Memory
863  FloatBot,     // FloatTop
864  FloatCon,     // FloatCon
865  FloatTop,     // FloatBot
866  DoubleBot,    // DoubleTop
867  DoubleCon,    // DoubleCon
868  DoubleTop,    // DoubleBot
869  Top           // Bottom
870};
871
872const Type *Type::xdual() const {
873  // Note: the base() accessor asserts the sanity of _base.
874  assert(_type_info[base()].dual_type != Bad, "implement with v-call");
875  return new Type(_type_info[_base].dual_type);
876}
877
878//------------------------------has_memory-------------------------------------
879bool Type::has_memory() const {
880  Type::TYPES tx = base();
881  if (tx == Memory) return true;
882  if (tx == Tuple) {
883    const TypeTuple *t = is_tuple();
884    for (uint i=0; i < t->cnt(); i++) {
885      tx = t->field_at(i)->base();
886      if (tx == Memory)  return true;
887    }
888  }
889  return false;
890}
891
892#ifndef PRODUCT
893//------------------------------dump2------------------------------------------
894void Type::dump2( Dict &d, uint depth, outputStream *st ) const {
895  st->print("%s", _type_info[_base].msg);
896}
897
898//------------------------------dump-------------------------------------------
899void Type::dump_on(outputStream *st) const {
900  ResourceMark rm;
901  Dict d(cmpkey,hashkey);       // Stop recursive type dumping
902  dump2(d,1, st);
903  if (is_ptr_to_narrowoop()) {
904    st->print(" [narrow]");
905  } else if (is_ptr_to_narrowklass()) {
906    st->print(" [narrowklass]");
907  }
908}
909#endif
910
911//------------------------------singleton--------------------------------------
912// TRUE if Type is a singleton type, FALSE otherwise.   Singletons are simple
913// constants (Ldi nodes).  Singletons are integer, float or double constants.
914bool Type::singleton(void) const {
915  return _base == Top || _base == Half;
916}
917
918//------------------------------empty------------------------------------------
919// TRUE if Type is a type with no values, FALSE otherwise.
920bool Type::empty(void) const {
921  switch (_base) {
922  case DoubleTop:
923  case FloatTop:
924  case Top:
925    return true;
926
927  case Half:
928  case Abio:
929  case Return_Address:
930  case Memory:
931  case Bottom:
932  case FloatBot:
933  case DoubleBot:
934    return false;  // never a singleton, therefore never empty
935  }
936
937  ShouldNotReachHere();
938  return false;
939}
940
941//------------------------------dump_stats-------------------------------------
942// Dump collected statistics to stderr
943#ifndef PRODUCT
944void Type::dump_stats() {
945  tty->print("Types made: %d\n", type_dict()->Size());
946}
947#endif
948
949//------------------------------typerr-----------------------------------------
950void Type::typerr( const Type *t ) const {
951#ifndef PRODUCT
952  tty->print("\nError mixing types: ");
953  dump();
954  tty->print(" and ");
955  t->dump();
956  tty->print("\n");
957#endif
958  ShouldNotReachHere();
959}
960
961
962//=============================================================================
963// Convenience common pre-built types.
964const TypeF *TypeF::ZERO;       // Floating point zero
965const TypeF *TypeF::ONE;        // Floating point one
966
967//------------------------------make-------------------------------------------
968// Create a float constant
969const TypeF *TypeF::make(float f) {
970  return (TypeF*)(new TypeF(f))->hashcons();
971}
972
973//------------------------------meet-------------------------------------------
974// Compute the MEET of two types.  It returns a new Type object.
975const Type *TypeF::xmeet( const Type *t ) const {
976  // Perform a fast test for common case; meeting the same types together.
977  if( this == t ) return this;  // Meeting same type-rep?
978
979  // Current "this->_base" is FloatCon
980  switch (t->base()) {          // Switch on original type
981  case AnyPtr:                  // Mixing with oops happens when javac
982  case RawPtr:                  // reuses local variables
983  case OopPtr:
984  case InstPtr:
985  case AryPtr:
986  case MetadataPtr:
987  case KlassPtr:
988  case NarrowOop:
989  case NarrowKlass:
990  case Int:
991  case Long:
992  case DoubleTop:
993  case DoubleCon:
994  case DoubleBot:
995  case Bottom:                  // Ye Olde Default
996    return Type::BOTTOM;
997
998  case FloatBot:
999    return t;
1000
1001  default:                      // All else is a mistake
1002    typerr(t);
1003
1004  case FloatCon:                // Float-constant vs Float-constant?
1005    if( jint_cast(_f) != jint_cast(t->getf()) )         // unequal constants?
1006                                // must compare bitwise as positive zero, negative zero and NaN have
1007                                // all the same representation in C++
1008      return FLOAT;             // Return generic float
1009                                // Equal constants
1010  case Top:
1011  case FloatTop:
1012    break;                      // Return the float constant
1013  }
1014  return this;                  // Return the float constant
1015}
1016
1017//------------------------------xdual------------------------------------------
1018// Dual: symmetric
1019const Type *TypeF::xdual() const {
1020  return this;
1021}
1022
1023//------------------------------eq---------------------------------------------
1024// Structural equality check for Type representations
1025bool TypeF::eq(const Type *t) const {
1026  // Bitwise comparison to distinguish between +/-0. These values must be treated
1027  // as different to be consistent with C1 and the interpreter.
1028  return (jint_cast(_f) == jint_cast(t->getf()));
1029}
1030
1031//------------------------------hash-------------------------------------------
1032// Type-specific hashing function.
1033int TypeF::hash(void) const {
1034  return *(int*)(&_f);
1035}
1036
1037//------------------------------is_finite--------------------------------------
1038// Has a finite value
1039bool TypeF::is_finite() const {
1040  return g_isfinite(getf()) != 0;
1041}
1042
1043//------------------------------is_nan-----------------------------------------
1044// Is not a number (NaN)
1045bool TypeF::is_nan()    const {
1046  return g_isnan(getf()) != 0;
1047}
1048
1049//------------------------------dump2------------------------------------------
1050// Dump float constant Type
1051#ifndef PRODUCT
1052void TypeF::dump2( Dict &d, uint depth, outputStream *st ) const {
1053  Type::dump2(d,depth, st);
1054  st->print("%f", _f);
1055}
1056#endif
1057
1058//------------------------------singleton--------------------------------------
1059// TRUE if Type is a singleton type, FALSE otherwise.   Singletons are simple
1060// constants (Ldi nodes).  Singletons are integer, float or double constants
1061// or a single symbol.
1062bool TypeF::singleton(void) const {
1063  return true;                  // Always a singleton
1064}
1065
1066bool TypeF::empty(void) const {
1067  return false;                 // always exactly a singleton
1068}
1069
1070//=============================================================================
1071// Convenience common pre-built types.
1072const TypeD *TypeD::ZERO;       // Floating point zero
1073const TypeD *TypeD::ONE;        // Floating point one
1074
1075//------------------------------make-------------------------------------------
1076const TypeD *TypeD::make(double d) {
1077  return (TypeD*)(new TypeD(d))->hashcons();
1078}
1079
1080//------------------------------meet-------------------------------------------
1081// Compute the MEET of two types.  It returns a new Type object.
1082const Type *TypeD::xmeet( const Type *t ) const {
1083  // Perform a fast test for common case; meeting the same types together.
1084  if( this == t ) return this;  // Meeting same type-rep?
1085
1086  // Current "this->_base" is DoubleCon
1087  switch (t->base()) {          // Switch on original type
1088  case AnyPtr:                  // Mixing with oops happens when javac
1089  case RawPtr:                  // reuses local variables
1090  case OopPtr:
1091  case InstPtr:
1092  case AryPtr:
1093  case MetadataPtr:
1094  case KlassPtr:
1095  case NarrowOop:
1096  case NarrowKlass:
1097  case Int:
1098  case Long:
1099  case FloatTop:
1100  case FloatCon:
1101  case FloatBot:
1102  case Bottom:                  // Ye Olde Default
1103    return Type::BOTTOM;
1104
1105  case DoubleBot:
1106    return t;
1107
1108  default:                      // All else is a mistake
1109    typerr(t);
1110
1111  case DoubleCon:               // Double-constant vs Double-constant?
1112    if( jlong_cast(_d) != jlong_cast(t->getd()) )       // unequal constants? (see comment in TypeF::xmeet)
1113      return DOUBLE;            // Return generic double
1114  case Top:
1115  case DoubleTop:
1116    break;
1117  }
1118  return this;                  // Return the double constant
1119}
1120
1121//------------------------------xdual------------------------------------------
1122// Dual: symmetric
1123const Type *TypeD::xdual() const {
1124  return this;
1125}
1126
1127//------------------------------eq---------------------------------------------
1128// Structural equality check for Type representations
1129bool TypeD::eq(const Type *t) const {
1130  // Bitwise comparison to distinguish between +/-0. These values must be treated
1131  // as different to be consistent with C1 and the interpreter.
1132  return (jlong_cast(_d) == jlong_cast(t->getd()));
1133}
1134
1135//------------------------------hash-------------------------------------------
1136// Type-specific hashing function.
1137int TypeD::hash(void) const {
1138  return *(int*)(&_d);
1139}
1140
1141//------------------------------is_finite--------------------------------------
1142// Has a finite value
1143bool TypeD::is_finite() const {
1144  return g_isfinite(getd()) != 0;
1145}
1146
1147//------------------------------is_nan-----------------------------------------
1148// Is not a number (NaN)
1149bool TypeD::is_nan()    const {
1150  return g_isnan(getd()) != 0;
1151}
1152
1153//------------------------------dump2------------------------------------------
1154// Dump double constant Type
1155#ifndef PRODUCT
1156void TypeD::dump2( Dict &d, uint depth, outputStream *st ) const {
1157  Type::dump2(d,depth,st);
1158  st->print("%f", _d);
1159}
1160#endif
1161
1162//------------------------------singleton--------------------------------------
1163// TRUE if Type is a singleton type, FALSE otherwise.   Singletons are simple
1164// constants (Ldi nodes).  Singletons are integer, float or double constants
1165// or a single symbol.
1166bool TypeD::singleton(void) const {
1167  return true;                  // Always a singleton
1168}
1169
1170bool TypeD::empty(void) const {
1171  return false;                 // always exactly a singleton
1172}
1173
1174//=============================================================================
1175// Convience common pre-built types.
1176const TypeInt *TypeInt::MINUS_1;// -1
1177const TypeInt *TypeInt::ZERO;   // 0
1178const TypeInt *TypeInt::ONE;    // 1
1179const TypeInt *TypeInt::BOOL;   // 0 or 1, FALSE or TRUE.
1180const TypeInt *TypeInt::CC;     // -1,0 or 1, condition codes
1181const TypeInt *TypeInt::CC_LT;  // [-1]  == MINUS_1
1182const TypeInt *TypeInt::CC_GT;  // [1]   == ONE
1183const TypeInt *TypeInt::CC_EQ;  // [0]   == ZERO
1184const TypeInt *TypeInt::CC_LE;  // [-1,0]
1185const TypeInt *TypeInt::CC_GE;  // [0,1] == BOOL (!)
1186const TypeInt *TypeInt::BYTE;   // Bytes, -128 to 127
1187const TypeInt *TypeInt::UBYTE;  // Unsigned Bytes, 0 to 255
1188const TypeInt *TypeInt::CHAR;   // Java chars, 0-65535
1189const TypeInt *TypeInt::SHORT;  // Java shorts, -32768-32767
1190const TypeInt *TypeInt::POS;    // Positive 32-bit integers or zero
1191const TypeInt *TypeInt::POS1;   // Positive 32-bit integers
1192const TypeInt *TypeInt::INT;    // 32-bit integers
1193const TypeInt *TypeInt::SYMINT; // symmetric range [-max_jint..max_jint]
1194const TypeInt *TypeInt::TYPE_DOMAIN; // alias for TypeInt::INT
1195
1196//------------------------------TypeInt----------------------------------------
1197TypeInt::TypeInt( jint lo, jint hi, int w ) : Type(Int), _lo(lo), _hi(hi), _widen(w) {
1198}
1199
1200//------------------------------make-------------------------------------------
1201const TypeInt *TypeInt::make( jint lo ) {
1202  return (TypeInt*)(new TypeInt(lo,lo,WidenMin))->hashcons();
1203}
1204
1205static int normalize_int_widen( jint lo, jint hi, int w ) {
1206  // Certain normalizations keep us sane when comparing types.
1207  // The 'SMALLINT' covers constants and also CC and its relatives.
1208  if (lo <= hi) {
1209    if (((juint)hi - lo) <= SMALLINT)  w = Type::WidenMin;
1210    if (((juint)hi - lo) >= max_juint) w = Type::WidenMax; // TypeInt::INT
1211  } else {
1212    if (((juint)lo - hi) <= SMALLINT)  w = Type::WidenMin;
1213    if (((juint)lo - hi) >= max_juint) w = Type::WidenMin; // dual TypeInt::INT
1214  }
1215  return w;
1216}
1217
1218const TypeInt *TypeInt::make( jint lo, jint hi, int w ) {
1219  w = normalize_int_widen(lo, hi, w);
1220  return (TypeInt*)(new TypeInt(lo,hi,w))->hashcons();
1221}
1222
1223//------------------------------meet-------------------------------------------
1224// Compute the MEET of two types.  It returns a new Type representation object
1225// with reference count equal to the number of Types pointing at it.
1226// Caller should wrap a Types around it.
1227const Type *TypeInt::xmeet( const Type *t ) const {
1228  // Perform a fast test for common case; meeting the same types together.
1229  if( this == t ) return this;  // Meeting same type?
1230
1231  // Currently "this->_base" is a TypeInt
1232  switch (t->base()) {          // Switch on original type
1233  case AnyPtr:                  // Mixing with oops happens when javac
1234  case RawPtr:                  // reuses local variables
1235  case OopPtr:
1236  case InstPtr:
1237  case AryPtr:
1238  case MetadataPtr:
1239  case KlassPtr:
1240  case NarrowOop:
1241  case NarrowKlass:
1242  case Long:
1243  case FloatTop:
1244  case FloatCon:
1245  case FloatBot:
1246  case DoubleTop:
1247  case DoubleCon:
1248  case DoubleBot:
1249  case Bottom:                  // Ye Olde Default
1250    return Type::BOTTOM;
1251  default:                      // All else is a mistake
1252    typerr(t);
1253  case Top:                     // No change
1254    return this;
1255  case Int:                     // Int vs Int?
1256    break;
1257  }
1258
1259  // Expand covered set
1260  const TypeInt *r = t->is_int();
1261  return make( MIN2(_lo,r->_lo), MAX2(_hi,r->_hi), MAX2(_widen,r->_widen) );
1262}
1263
1264//------------------------------xdual------------------------------------------
1265// Dual: reverse hi & lo; flip widen
1266const Type *TypeInt::xdual() const {
1267  int w = normalize_int_widen(_hi,_lo, WidenMax-_widen);
1268  return new TypeInt(_hi,_lo,w);
1269}
1270
1271//------------------------------widen------------------------------------------
1272// Only happens for optimistic top-down optimizations.
1273const Type *TypeInt::widen( const Type *old, const Type* limit ) const {
1274  // Coming from TOP or such; no widening
1275  if( old->base() != Int ) return this;
1276  const TypeInt *ot = old->is_int();
1277
1278  // If new guy is equal to old guy, no widening
1279  if( _lo == ot->_lo && _hi == ot->_hi )
1280    return old;
1281
1282  // If new guy contains old, then we widened
1283  if( _lo <= ot->_lo && _hi >= ot->_hi ) {
1284    // New contains old
1285    // If new guy is already wider than old, no widening
1286    if( _widen > ot->_widen ) return this;
1287    // If old guy was a constant, do not bother
1288    if (ot->_lo == ot->_hi)  return this;
1289    // Now widen new guy.
1290    // Check for widening too far
1291    if (_widen == WidenMax) {
1292      int max = max_jint;
1293      int min = min_jint;
1294      if (limit->isa_int()) {
1295        max = limit->is_int()->_hi;
1296        min = limit->is_int()->_lo;
1297      }
1298      if (min < _lo && _hi < max) {
1299        // If neither endpoint is extremal yet, push out the endpoint
1300        // which is closer to its respective limit.
1301        if (_lo >= 0 ||                 // easy common case
1302            (juint)(_lo - min) >= (juint)(max - _hi)) {
1303          // Try to widen to an unsigned range type of 31 bits:
1304          return make(_lo, max, WidenMax);
1305        } else {
1306          return make(min, _hi, WidenMax);
1307        }
1308      }
1309      return TypeInt::INT;
1310    }
1311    // Returned widened new guy
1312    return make(_lo,_hi,_widen+1);
1313  }
1314
1315  // If old guy contains new, then we probably widened too far & dropped to
1316  // bottom.  Return the wider fellow.
1317  if ( ot->_lo <= _lo && ot->_hi >= _hi )
1318    return old;
1319
1320  //fatal("Integer value range is not subset");
1321  //return this;
1322  return TypeInt::INT;
1323}
1324
1325//------------------------------narrow---------------------------------------
1326// Only happens for pessimistic optimizations.
1327const Type *TypeInt::narrow( const Type *old ) const {
1328  if (_lo >= _hi)  return this;   // already narrow enough
1329  if (old == NULL)  return this;
1330  const TypeInt* ot = old->isa_int();
1331  if (ot == NULL)  return this;
1332  jint olo = ot->_lo;
1333  jint ohi = ot->_hi;
1334
1335  // If new guy is equal to old guy, no narrowing
1336  if (_lo == olo && _hi == ohi)  return old;
1337
1338  // If old guy was maximum range, allow the narrowing
1339  if (olo == min_jint && ohi == max_jint)  return this;
1340
1341  if (_lo < olo || _hi > ohi)
1342    return this;                // doesn't narrow; pretty wierd
1343
1344  // The new type narrows the old type, so look for a "death march".
1345  // See comments on PhaseTransform::saturate.
1346  juint nrange = _hi - _lo;
1347  juint orange = ohi - olo;
1348  if (nrange < max_juint - 1 && nrange > (orange >> 1) + (SMALLINT*2)) {
1349    // Use the new type only if the range shrinks a lot.
1350    // We do not want the optimizer computing 2^31 point by point.
1351    return old;
1352  }
1353
1354  return this;
1355}
1356
1357//-----------------------------filter------------------------------------------
1358const Type *TypeInt::filter_helper(const Type *kills, bool include_speculative) const {
1359  const TypeInt* ft = join_helper(kills, include_speculative)->isa_int();
1360  if (ft == NULL || ft->empty())
1361    return Type::TOP;           // Canonical empty value
1362  if (ft->_widen < this->_widen) {
1363    // Do not allow the value of kill->_widen to affect the outcome.
1364    // The widen bits must be allowed to run freely through the graph.
1365    ft = TypeInt::make(ft->_lo, ft->_hi, this->_widen);
1366  }
1367  return ft;
1368}
1369
1370//------------------------------eq---------------------------------------------
1371// Structural equality check for Type representations
1372bool TypeInt::eq( const Type *t ) const {
1373  const TypeInt *r = t->is_int(); // Handy access
1374  return r->_lo == _lo && r->_hi == _hi && r->_widen == _widen;
1375}
1376
1377//------------------------------hash-------------------------------------------
1378// Type-specific hashing function.
1379int TypeInt::hash(void) const {
1380  return _lo+_hi+_widen+(int)Type::Int;
1381}
1382
1383//------------------------------is_finite--------------------------------------
1384// Has a finite value
1385bool TypeInt::is_finite() const {
1386  return true;
1387}
1388
1389//------------------------------dump2------------------------------------------
1390// Dump TypeInt
1391#ifndef PRODUCT
1392static const char* intname(char* buf, jint n) {
1393  if (n == min_jint)
1394    return "min";
1395  else if (n < min_jint + 10000)
1396    sprintf(buf, "min+" INT32_FORMAT, n - min_jint);
1397  else if (n == max_jint)
1398    return "max";
1399  else if (n > max_jint - 10000)
1400    sprintf(buf, "max-" INT32_FORMAT, max_jint - n);
1401  else
1402    sprintf(buf, INT32_FORMAT, n);
1403  return buf;
1404}
1405
1406void TypeInt::dump2( Dict &d, uint depth, outputStream *st ) const {
1407  char buf[40], buf2[40];
1408  if (_lo == min_jint && _hi == max_jint)
1409    st->print("int");
1410  else if (is_con())
1411    st->print("int:%s", intname(buf, get_con()));
1412  else if (_lo == BOOL->_lo && _hi == BOOL->_hi)
1413    st->print("bool");
1414  else if (_lo == BYTE->_lo && _hi == BYTE->_hi)
1415    st->print("byte");
1416  else if (_lo == CHAR->_lo && _hi == CHAR->_hi)
1417    st->print("char");
1418  else if (_lo == SHORT->_lo && _hi == SHORT->_hi)
1419    st->print("short");
1420  else if (_hi == max_jint)
1421    st->print("int:>=%s", intname(buf, _lo));
1422  else if (_lo == min_jint)
1423    st->print("int:<=%s", intname(buf, _hi));
1424  else
1425    st->print("int:%s..%s", intname(buf, _lo), intname(buf2, _hi));
1426
1427  if (_widen != 0 && this != TypeInt::INT)
1428    st->print(":%.*s", _widen, "wwww");
1429}
1430#endif
1431
1432//------------------------------singleton--------------------------------------
1433// TRUE if Type is a singleton type, FALSE otherwise.   Singletons are simple
1434// constants.
1435bool TypeInt::singleton(void) const {
1436  return _lo >= _hi;
1437}
1438
1439bool TypeInt::empty(void) const {
1440  return _lo > _hi;
1441}
1442
1443//=============================================================================
1444// Convenience common pre-built types.
1445const TypeLong *TypeLong::MINUS_1;// -1
1446const TypeLong *TypeLong::ZERO; // 0
1447const TypeLong *TypeLong::ONE;  // 1
1448const TypeLong *TypeLong::POS;  // >=0
1449const TypeLong *TypeLong::LONG; // 64-bit integers
1450const TypeLong *TypeLong::INT;  // 32-bit subrange
1451const TypeLong *TypeLong::UINT; // 32-bit unsigned subrange
1452const TypeLong *TypeLong::TYPE_DOMAIN; // alias for TypeLong::LONG
1453
1454//------------------------------TypeLong---------------------------------------
1455TypeLong::TypeLong( jlong lo, jlong hi, int w ) : Type(Long), _lo(lo), _hi(hi), _widen(w) {
1456}
1457
1458//------------------------------make-------------------------------------------
1459const TypeLong *TypeLong::make( jlong lo ) {
1460  return (TypeLong*)(new TypeLong(lo,lo,WidenMin))->hashcons();
1461}
1462
1463static int normalize_long_widen( jlong lo, jlong hi, int w ) {
1464  // Certain normalizations keep us sane when comparing types.
1465  // The 'SMALLINT' covers constants.
1466  if (lo <= hi) {
1467    if (((julong)hi - lo) <= SMALLINT)   w = Type::WidenMin;
1468    if (((julong)hi - lo) >= max_julong) w = Type::WidenMax; // TypeLong::LONG
1469  } else {
1470    if (((julong)lo - hi) <= SMALLINT)   w = Type::WidenMin;
1471    if (((julong)lo - hi) >= max_julong) w = Type::WidenMin; // dual TypeLong::LONG
1472  }
1473  return w;
1474}
1475
1476const TypeLong *TypeLong::make( jlong lo, jlong hi, int w ) {
1477  w = normalize_long_widen(lo, hi, w);
1478  return (TypeLong*)(new TypeLong(lo,hi,w))->hashcons();
1479}
1480
1481
1482//------------------------------meet-------------------------------------------
1483// Compute the MEET of two types.  It returns a new Type representation object
1484// with reference count equal to the number of Types pointing at it.
1485// Caller should wrap a Types around it.
1486const Type *TypeLong::xmeet( const Type *t ) const {
1487  // Perform a fast test for common case; meeting the same types together.
1488  if( this == t ) return this;  // Meeting same type?
1489
1490  // Currently "this->_base" is a TypeLong
1491  switch (t->base()) {          // Switch on original type
1492  case AnyPtr:                  // Mixing with oops happens when javac
1493  case RawPtr:                  // reuses local variables
1494  case OopPtr:
1495  case InstPtr:
1496  case AryPtr:
1497  case MetadataPtr:
1498  case KlassPtr:
1499  case NarrowOop:
1500  case NarrowKlass:
1501  case Int:
1502  case FloatTop:
1503  case FloatCon:
1504  case FloatBot:
1505  case DoubleTop:
1506  case DoubleCon:
1507  case DoubleBot:
1508  case Bottom:                  // Ye Olde Default
1509    return Type::BOTTOM;
1510  default:                      // All else is a mistake
1511    typerr(t);
1512  case Top:                     // No change
1513    return this;
1514  case Long:                    // Long vs Long?
1515    break;
1516  }
1517
1518  // Expand covered set
1519  const TypeLong *r = t->is_long(); // Turn into a TypeLong
1520  return make( MIN2(_lo,r->_lo), MAX2(_hi,r->_hi), MAX2(_widen,r->_widen) );
1521}
1522
1523//------------------------------xdual------------------------------------------
1524// Dual: reverse hi & lo; flip widen
1525const Type *TypeLong::xdual() const {
1526  int w = normalize_long_widen(_hi,_lo, WidenMax-_widen);
1527  return new TypeLong(_hi,_lo,w);
1528}
1529
1530//------------------------------widen------------------------------------------
1531// Only happens for optimistic top-down optimizations.
1532const Type *TypeLong::widen( const Type *old, const Type* limit ) const {
1533  // Coming from TOP or such; no widening
1534  if( old->base() != Long ) return this;
1535  const TypeLong *ot = old->is_long();
1536
1537  // If new guy is equal to old guy, no widening
1538  if( _lo == ot->_lo && _hi == ot->_hi )
1539    return old;
1540
1541  // If new guy contains old, then we widened
1542  if( _lo <= ot->_lo && _hi >= ot->_hi ) {
1543    // New contains old
1544    // If new guy is already wider than old, no widening
1545    if( _widen > ot->_widen ) return this;
1546    // If old guy was a constant, do not bother
1547    if (ot->_lo == ot->_hi)  return this;
1548    // Now widen new guy.
1549    // Check for widening too far
1550    if (_widen == WidenMax) {
1551      jlong max = max_jlong;
1552      jlong min = min_jlong;
1553      if (limit->isa_long()) {
1554        max = limit->is_long()->_hi;
1555        min = limit->is_long()->_lo;
1556      }
1557      if (min < _lo && _hi < max) {
1558        // If neither endpoint is extremal yet, push out the endpoint
1559        // which is closer to its respective limit.
1560        if (_lo >= 0 ||                 // easy common case
1561            (julong)(_lo - min) >= (julong)(max - _hi)) {
1562          // Try to widen to an unsigned range type of 32/63 bits:
1563          if (max >= max_juint && _hi < max_juint)
1564            return make(_lo, max_juint, WidenMax);
1565          else
1566            return make(_lo, max, WidenMax);
1567        } else {
1568          return make(min, _hi, WidenMax);
1569        }
1570      }
1571      return TypeLong::LONG;
1572    }
1573    // Returned widened new guy
1574    return make(_lo,_hi,_widen+1);
1575  }
1576
1577  // If old guy contains new, then we probably widened too far & dropped to
1578  // bottom.  Return the wider fellow.
1579  if ( ot->_lo <= _lo && ot->_hi >= _hi )
1580    return old;
1581
1582  //  fatal("Long value range is not subset");
1583  // return this;
1584  return TypeLong::LONG;
1585}
1586
1587//------------------------------narrow----------------------------------------
1588// Only happens for pessimistic optimizations.
1589const Type *TypeLong::narrow( const Type *old ) const {
1590  if (_lo >= _hi)  return this;   // already narrow enough
1591  if (old == NULL)  return this;
1592  const TypeLong* ot = old->isa_long();
1593  if (ot == NULL)  return this;
1594  jlong olo = ot->_lo;
1595  jlong ohi = ot->_hi;
1596
1597  // If new guy is equal to old guy, no narrowing
1598  if (_lo == olo && _hi == ohi)  return old;
1599
1600  // If old guy was maximum range, allow the narrowing
1601  if (olo == min_jlong && ohi == max_jlong)  return this;
1602
1603  if (_lo < olo || _hi > ohi)
1604    return this;                // doesn't narrow; pretty wierd
1605
1606  // The new type narrows the old type, so look for a "death march".
1607  // See comments on PhaseTransform::saturate.
1608  julong nrange = _hi - _lo;
1609  julong orange = ohi - olo;
1610  if (nrange < max_julong - 1 && nrange > (orange >> 1) + (SMALLINT*2)) {
1611    // Use the new type only if the range shrinks a lot.
1612    // We do not want the optimizer computing 2^31 point by point.
1613    return old;
1614  }
1615
1616  return this;
1617}
1618
1619//-----------------------------filter------------------------------------------
1620const Type *TypeLong::filter_helper(const Type *kills, bool include_speculative) const {
1621  const TypeLong* ft = join_helper(kills, include_speculative)->isa_long();
1622  if (ft == NULL || ft->empty())
1623    return Type::TOP;           // Canonical empty value
1624  if (ft->_widen < this->_widen) {
1625    // Do not allow the value of kill->_widen to affect the outcome.
1626    // The widen bits must be allowed to run freely through the graph.
1627    ft = TypeLong::make(ft->_lo, ft->_hi, this->_widen);
1628  }
1629  return ft;
1630}
1631
1632//------------------------------eq---------------------------------------------
1633// Structural equality check for Type representations
1634bool TypeLong::eq( const Type *t ) const {
1635  const TypeLong *r = t->is_long(); // Handy access
1636  return r->_lo == _lo &&  r->_hi == _hi  && r->_widen == _widen;
1637}
1638
1639//------------------------------hash-------------------------------------------
1640// Type-specific hashing function.
1641int TypeLong::hash(void) const {
1642  return (int)(_lo+_hi+_widen+(int)Type::Long);
1643}
1644
1645//------------------------------is_finite--------------------------------------
1646// Has a finite value
1647bool TypeLong::is_finite() const {
1648  return true;
1649}
1650
1651//------------------------------dump2------------------------------------------
1652// Dump TypeLong
1653#ifndef PRODUCT
1654static const char* longnamenear(jlong x, const char* xname, char* buf, jlong n) {
1655  if (n > x) {
1656    if (n >= x + 10000)  return NULL;
1657    sprintf(buf, "%s+" JLONG_FORMAT, xname, n - x);
1658  } else if (n < x) {
1659    if (n <= x - 10000)  return NULL;
1660    sprintf(buf, "%s-" JLONG_FORMAT, xname, x - n);
1661  } else {
1662    return xname;
1663  }
1664  return buf;
1665}
1666
1667static const char* longname(char* buf, jlong n) {
1668  const char* str;
1669  if (n == min_jlong)
1670    return "min";
1671  else if (n < min_jlong + 10000)
1672    sprintf(buf, "min+" JLONG_FORMAT, n - min_jlong);
1673  else if (n == max_jlong)
1674    return "max";
1675  else if (n > max_jlong - 10000)
1676    sprintf(buf, "max-" JLONG_FORMAT, max_jlong - n);
1677  else if ((str = longnamenear(max_juint, "maxuint", buf, n)) != NULL)
1678    return str;
1679  else if ((str = longnamenear(max_jint, "maxint", buf, n)) != NULL)
1680    return str;
1681  else if ((str = longnamenear(min_jint, "minint", buf, n)) != NULL)
1682    return str;
1683  else
1684    sprintf(buf, JLONG_FORMAT, n);
1685  return buf;
1686}
1687
1688void TypeLong::dump2( Dict &d, uint depth, outputStream *st ) const {
1689  char buf[80], buf2[80];
1690  if (_lo == min_jlong && _hi == max_jlong)
1691    st->print("long");
1692  else if (is_con())
1693    st->print("long:%s", longname(buf, get_con()));
1694  else if (_hi == max_jlong)
1695    st->print("long:>=%s", longname(buf, _lo));
1696  else if (_lo == min_jlong)
1697    st->print("long:<=%s", longname(buf, _hi));
1698  else
1699    st->print("long:%s..%s", longname(buf, _lo), longname(buf2, _hi));
1700
1701  if (_widen != 0 && this != TypeLong::LONG)
1702    st->print(":%.*s", _widen, "wwww");
1703}
1704#endif
1705
1706//------------------------------singleton--------------------------------------
1707// TRUE if Type is a singleton type, FALSE otherwise.   Singletons are simple
1708// constants
1709bool TypeLong::singleton(void) const {
1710  return _lo >= _hi;
1711}
1712
1713bool TypeLong::empty(void) const {
1714  return _lo > _hi;
1715}
1716
1717//=============================================================================
1718// Convenience common pre-built types.
1719const TypeTuple *TypeTuple::IFBOTH;     // Return both arms of IF as reachable
1720const TypeTuple *TypeTuple::IFFALSE;
1721const TypeTuple *TypeTuple::IFTRUE;
1722const TypeTuple *TypeTuple::IFNEITHER;
1723const TypeTuple *TypeTuple::LOOPBODY;
1724const TypeTuple *TypeTuple::MEMBAR;
1725const TypeTuple *TypeTuple::STORECONDITIONAL;
1726const TypeTuple *TypeTuple::START_I2C;
1727const TypeTuple *TypeTuple::INT_PAIR;
1728const TypeTuple *TypeTuple::LONG_PAIR;
1729const TypeTuple *TypeTuple::INT_CC_PAIR;
1730const TypeTuple *TypeTuple::LONG_CC_PAIR;
1731
1732
1733//------------------------------make-------------------------------------------
1734// Make a TypeTuple from the range of a method signature
1735const TypeTuple *TypeTuple::make_range(ciSignature* sig) {
1736  ciType* return_type = sig->return_type();
1737  uint arg_cnt = return_type->size();
1738  const Type **field_array = fields(arg_cnt);
1739  switch (return_type->basic_type()) {
1740  case T_LONG:
1741    field_array[TypeFunc::Parms]   = TypeLong::LONG;
1742    field_array[TypeFunc::Parms+1] = Type::HALF;
1743    break;
1744  case T_DOUBLE:
1745    field_array[TypeFunc::Parms]   = Type::DOUBLE;
1746    field_array[TypeFunc::Parms+1] = Type::HALF;
1747    break;
1748  case T_OBJECT:
1749  case T_ARRAY:
1750  case T_BOOLEAN:
1751  case T_CHAR:
1752  case T_FLOAT:
1753  case T_BYTE:
1754  case T_SHORT:
1755  case T_INT:
1756    field_array[TypeFunc::Parms] = get_const_type(return_type);
1757    break;
1758  case T_VOID:
1759    break;
1760  default:
1761    ShouldNotReachHere();
1762  }
1763  return (TypeTuple*)(new TypeTuple(TypeFunc::Parms + arg_cnt, field_array))->hashcons();
1764}
1765
1766// Make a TypeTuple from the domain of a method signature
1767const TypeTuple *TypeTuple::make_domain(ciInstanceKlass* recv, ciSignature* sig) {
1768  uint arg_cnt = sig->size();
1769
1770  uint pos = TypeFunc::Parms;
1771  const Type **field_array;
1772  if (recv != NULL) {
1773    arg_cnt++;
1774    field_array = fields(arg_cnt);
1775    // Use get_const_type here because it respects UseUniqueSubclasses:
1776    field_array[pos++] = get_const_type(recv)->join_speculative(TypePtr::NOTNULL);
1777  } else {
1778    field_array = fields(arg_cnt);
1779  }
1780
1781  int i = 0;
1782  while (pos < TypeFunc::Parms + arg_cnt) {
1783    ciType* type = sig->type_at(i);
1784
1785    switch (type->basic_type()) {
1786    case T_LONG:
1787      field_array[pos++] = TypeLong::LONG;
1788      field_array[pos++] = Type::HALF;
1789      break;
1790    case T_DOUBLE:
1791      field_array[pos++] = Type::DOUBLE;
1792      field_array[pos++] = Type::HALF;
1793      break;
1794    case T_OBJECT:
1795    case T_ARRAY:
1796    case T_BOOLEAN:
1797    case T_CHAR:
1798    case T_FLOAT:
1799    case T_BYTE:
1800    case T_SHORT:
1801    case T_INT:
1802      field_array[pos++] = get_const_type(type);
1803      break;
1804    default:
1805      ShouldNotReachHere();
1806    }
1807    i++;
1808  }
1809
1810  return (TypeTuple*)(new TypeTuple(TypeFunc::Parms + arg_cnt, field_array))->hashcons();
1811}
1812
1813const TypeTuple *TypeTuple::make( uint cnt, const Type **fields ) {
1814  return (TypeTuple*)(new TypeTuple(cnt,fields))->hashcons();
1815}
1816
1817//------------------------------fields-----------------------------------------
1818// Subroutine call type with space allocated for argument types
1819// Memory for Control, I_O, Memory, FramePtr, and ReturnAdr is allocated implicitly
1820const Type **TypeTuple::fields( uint arg_cnt ) {
1821  const Type **flds = (const Type **)(Compile::current()->type_arena()->Amalloc_4((TypeFunc::Parms+arg_cnt)*sizeof(Type*) ));
1822  flds[TypeFunc::Control  ] = Type::CONTROL;
1823  flds[TypeFunc::I_O      ] = Type::ABIO;
1824  flds[TypeFunc::Memory   ] = Type::MEMORY;
1825  flds[TypeFunc::FramePtr ] = TypeRawPtr::BOTTOM;
1826  flds[TypeFunc::ReturnAdr] = Type::RETURN_ADDRESS;
1827
1828  return flds;
1829}
1830
1831//------------------------------meet-------------------------------------------
1832// Compute the MEET of two types.  It returns a new Type object.
1833const Type *TypeTuple::xmeet( const Type *t ) const {
1834  // Perform a fast test for common case; meeting the same types together.
1835  if( this == t ) return this;  // Meeting same type-rep?
1836
1837  // Current "this->_base" is Tuple
1838  switch (t->base()) {          // switch on original type
1839
1840  case Bottom:                  // Ye Olde Default
1841    return t;
1842
1843  default:                      // All else is a mistake
1844    typerr(t);
1845
1846  case Tuple: {                 // Meeting 2 signatures?
1847    const TypeTuple *x = t->is_tuple();
1848    assert( _cnt == x->_cnt, "" );
1849    const Type **fields = (const Type **)(Compile::current()->type_arena()->Amalloc_4( _cnt*sizeof(Type*) ));
1850    for( uint i=0; i<_cnt; i++ )
1851      fields[i] = field_at(i)->xmeet( x->field_at(i) );
1852    return TypeTuple::make(_cnt,fields);
1853  }
1854  case Top:
1855    break;
1856  }
1857  return this;                  // Return the double constant
1858}
1859
1860//------------------------------xdual------------------------------------------
1861// Dual: compute field-by-field dual
1862const Type *TypeTuple::xdual() const {
1863  const Type **fields = (const Type **)(Compile::current()->type_arena()->Amalloc_4( _cnt*sizeof(Type*) ));
1864  for( uint i=0; i<_cnt; i++ )
1865    fields[i] = _fields[i]->dual();
1866  return new TypeTuple(_cnt,fields);
1867}
1868
1869//------------------------------eq---------------------------------------------
1870// Structural equality check for Type representations
1871bool TypeTuple::eq( const Type *t ) const {
1872  const TypeTuple *s = (const TypeTuple *)t;
1873  if (_cnt != s->_cnt)  return false;  // Unequal field counts
1874  for (uint i = 0; i < _cnt; i++)
1875    if (field_at(i) != s->field_at(i)) // POINTER COMPARE!  NO RECURSION!
1876      return false;             // Missed
1877  return true;
1878}
1879
1880//------------------------------hash-------------------------------------------
1881// Type-specific hashing function.
1882int TypeTuple::hash(void) const {
1883  intptr_t sum = _cnt;
1884  for( uint i=0; i<_cnt; i++ )
1885    sum += (intptr_t)_fields[i];     // Hash on pointers directly
1886  return sum;
1887}
1888
1889//------------------------------dump2------------------------------------------
1890// Dump signature Type
1891#ifndef PRODUCT
1892void TypeTuple::dump2( Dict &d, uint depth, outputStream *st ) const {
1893  st->print("{");
1894  if( !depth || d[this] ) {     // Check for recursive print
1895    st->print("...}");
1896    return;
1897  }
1898  d.Insert((void*)this, (void*)this);   // Stop recursion
1899  if( _cnt ) {
1900    uint i;
1901    for( i=0; i<_cnt-1; i++ ) {
1902      st->print("%d:", i);
1903      _fields[i]->dump2(d, depth-1, st);
1904      st->print(", ");
1905    }
1906    st->print("%d:", i);
1907    _fields[i]->dump2(d, depth-1, st);
1908  }
1909  st->print("}");
1910}
1911#endif
1912
1913//------------------------------singleton--------------------------------------
1914// TRUE if Type is a singleton type, FALSE otherwise.   Singletons are simple
1915// constants (Ldi nodes).  Singletons are integer, float or double constants
1916// or a single symbol.
1917bool TypeTuple::singleton(void) const {
1918  return false;                 // Never a singleton
1919}
1920
1921bool TypeTuple::empty(void) const {
1922  for( uint i=0; i<_cnt; i++ ) {
1923    if (_fields[i]->empty())  return true;
1924  }
1925  return false;
1926}
1927
1928//=============================================================================
1929// Convenience common pre-built types.
1930
1931inline const TypeInt* normalize_array_size(const TypeInt* size) {
1932  // Certain normalizations keep us sane when comparing types.
1933  // We do not want arrayOop variables to differ only by the wideness
1934  // of their index types.  Pick minimum wideness, since that is the
1935  // forced wideness of small ranges anyway.
1936  if (size->_widen != Type::WidenMin)
1937    return TypeInt::make(size->_lo, size->_hi, Type::WidenMin);
1938  else
1939    return size;
1940}
1941
1942//------------------------------make-------------------------------------------
1943const TypeAry* TypeAry::make(const Type* elem, const TypeInt* size, bool stable) {
1944  if (UseCompressedOops && elem->isa_oopptr()) {
1945    elem = elem->make_narrowoop();
1946  }
1947  size = normalize_array_size(size);
1948  return (TypeAry*)(new TypeAry(elem,size,stable))->hashcons();
1949}
1950
1951//------------------------------meet-------------------------------------------
1952// Compute the MEET of two types.  It returns a new Type object.
1953const Type *TypeAry::xmeet( const Type *t ) const {
1954  // Perform a fast test for common case; meeting the same types together.
1955  if( this == t ) return this;  // Meeting same type-rep?
1956
1957  // Current "this->_base" is Ary
1958  switch (t->base()) {          // switch on original type
1959
1960  case Bottom:                  // Ye Olde Default
1961    return t;
1962
1963  default:                      // All else is a mistake
1964    typerr(t);
1965
1966  case Array: {                 // Meeting 2 arrays?
1967    const TypeAry *a = t->is_ary();
1968    return TypeAry::make(_elem->meet_speculative(a->_elem),
1969                         _size->xmeet(a->_size)->is_int(),
1970                         _stable & a->_stable);
1971  }
1972  case Top:
1973    break;
1974  }
1975  return this;                  // Return the double constant
1976}
1977
1978//------------------------------xdual------------------------------------------
1979// Dual: compute field-by-field dual
1980const Type *TypeAry::xdual() const {
1981  const TypeInt* size_dual = _size->dual()->is_int();
1982  size_dual = normalize_array_size(size_dual);
1983  return new TypeAry(_elem->dual(), size_dual, !_stable);
1984}
1985
1986//------------------------------eq---------------------------------------------
1987// Structural equality check for Type representations
1988bool TypeAry::eq( const Type *t ) const {
1989  const TypeAry *a = (const TypeAry*)t;
1990  return _elem == a->_elem &&
1991    _stable == a->_stable &&
1992    _size == a->_size;
1993}
1994
1995//------------------------------hash-------------------------------------------
1996// Type-specific hashing function.
1997int TypeAry::hash(void) const {
1998  return (intptr_t)_elem + (intptr_t)_size + (_stable ? 43 : 0);
1999}
2000
2001/**
2002 * Return same type without a speculative part in the element
2003 */
2004const Type* TypeAry::remove_speculative() const {
2005  return make(_elem->remove_speculative(), _size, _stable);
2006}
2007
2008/**
2009 * Return same type with cleaned up speculative part of element
2010 */
2011const Type* TypeAry::cleanup_speculative() const {
2012  return make(_elem->cleanup_speculative(), _size, _stable);
2013}
2014
2015/**
2016 * Return same type but with a different inline depth (used for speculation)
2017 *
2018 * @param depth  depth to meet with
2019 */
2020const TypePtr* TypePtr::with_inline_depth(int depth) const {
2021  if (!UseInlineDepthForSpeculativeTypes) {
2022    return this;
2023  }
2024  return make(AnyPtr, _ptr, _offset, _speculative, depth);
2025}
2026
2027//----------------------interface_vs_oop---------------------------------------
2028#ifdef ASSERT
2029bool TypeAry::interface_vs_oop(const Type *t) const {
2030  const TypeAry* t_ary = t->is_ary();
2031  if (t_ary) {
2032    return _elem->interface_vs_oop(t_ary->_elem);
2033  }
2034  return false;
2035}
2036#endif
2037
2038//------------------------------dump2------------------------------------------
2039#ifndef PRODUCT
2040void TypeAry::dump2( Dict &d, uint depth, outputStream *st ) const {
2041  if (_stable)  st->print("stable:");
2042  _elem->dump2(d, depth, st);
2043  st->print("[");
2044  _size->dump2(d, depth, st);
2045  st->print("]");
2046}
2047#endif
2048
2049//------------------------------singleton--------------------------------------
2050// TRUE if Type is a singleton type, FALSE otherwise.   Singletons are simple
2051// constants (Ldi nodes).  Singletons are integer, float or double constants
2052// or a single symbol.
2053bool TypeAry::singleton(void) const {
2054  return false;                 // Never a singleton
2055}
2056
2057bool TypeAry::empty(void) const {
2058  return _elem->empty() || _size->empty();
2059}
2060
2061//--------------------------ary_must_be_exact----------------------------------
2062bool TypeAry::ary_must_be_exact() const {
2063  if (!UseExactTypes)       return false;
2064  // This logic looks at the element type of an array, and returns true
2065  // if the element type is either a primitive or a final instance class.
2066  // In such cases, an array built on this ary must have no subclasses.
2067  if (_elem == BOTTOM)      return false;  // general array not exact
2068  if (_elem == TOP   )      return false;  // inverted general array not exact
2069  const TypeOopPtr*  toop = NULL;
2070  if (UseCompressedOops && _elem->isa_narrowoop()) {
2071    toop = _elem->make_ptr()->isa_oopptr();
2072  } else {
2073    toop = _elem->isa_oopptr();
2074  }
2075  if (!toop)                return true;   // a primitive type, like int
2076  ciKlass* tklass = toop->klass();
2077  if (tklass == NULL)       return false;  // unloaded class
2078  if (!tklass->is_loaded()) return false;  // unloaded class
2079  const TypeInstPtr* tinst;
2080  if (_elem->isa_narrowoop())
2081    tinst = _elem->make_ptr()->isa_instptr();
2082  else
2083    tinst = _elem->isa_instptr();
2084  if (tinst)
2085    return tklass->as_instance_klass()->is_final();
2086  const TypeAryPtr*  tap;
2087  if (_elem->isa_narrowoop())
2088    tap = _elem->make_ptr()->isa_aryptr();
2089  else
2090    tap = _elem->isa_aryptr();
2091  if (tap)
2092    return tap->ary()->ary_must_be_exact();
2093  return false;
2094}
2095
2096//==============================TypeVect=======================================
2097// Convenience common pre-built types.
2098const TypeVect *TypeVect::VECTS = NULL; //  32-bit vectors
2099const TypeVect *TypeVect::VECTD = NULL; //  64-bit vectors
2100const TypeVect *TypeVect::VECTX = NULL; // 128-bit vectors
2101const TypeVect *TypeVect::VECTY = NULL; // 256-bit vectors
2102const TypeVect *TypeVect::VECTZ = NULL; // 512-bit vectors
2103
2104//------------------------------make-------------------------------------------
2105const TypeVect* TypeVect::make(const Type *elem, uint length) {
2106  BasicType elem_bt = elem->array_element_basic_type();
2107  assert(is_java_primitive(elem_bt), "only primitive types in vector");
2108  assert(length > 1 && is_power_of_2(length), "vector length is power of 2");
2109  assert(Matcher::vector_size_supported(elem_bt, length), "length in range");
2110  int size = length * type2aelembytes(elem_bt);
2111  switch (Matcher::vector_ideal_reg(size)) {
2112  case Op_VecS:
2113    return (TypeVect*)(new TypeVectS(elem, length))->hashcons();
2114  case Op_RegL:
2115  case Op_VecD:
2116  case Op_RegD:
2117    return (TypeVect*)(new TypeVectD(elem, length))->hashcons();
2118  case Op_VecX:
2119    return (TypeVect*)(new TypeVectX(elem, length))->hashcons();
2120  case Op_VecY:
2121    return (TypeVect*)(new TypeVectY(elem, length))->hashcons();
2122  case Op_VecZ:
2123    return (TypeVect*)(new TypeVectZ(elem, length))->hashcons();
2124  }
2125 ShouldNotReachHere();
2126  return NULL;
2127}
2128
2129//------------------------------meet-------------------------------------------
2130// Compute the MEET of two types.  It returns a new Type object.
2131const Type *TypeVect::xmeet( const Type *t ) const {
2132  // Perform a fast test for common case; meeting the same types together.
2133  if( this == t ) return this;  // Meeting same type-rep?
2134
2135  // Current "this->_base" is Vector
2136  switch (t->base()) {          // switch on original type
2137
2138  case Bottom:                  // Ye Olde Default
2139    return t;
2140
2141  default:                      // All else is a mistake
2142    typerr(t);
2143
2144  case VectorS:
2145  case VectorD:
2146  case VectorX:
2147  case VectorY:
2148  case VectorZ: {                // Meeting 2 vectors?
2149    const TypeVect* v = t->is_vect();
2150    assert(  base() == v->base(), "");
2151    assert(length() == v->length(), "");
2152    assert(element_basic_type() == v->element_basic_type(), "");
2153    return TypeVect::make(_elem->xmeet(v->_elem), _length);
2154  }
2155  case Top:
2156    break;
2157  }
2158  return this;
2159}
2160
2161//------------------------------xdual------------------------------------------
2162// Dual: compute field-by-field dual
2163const Type *TypeVect::xdual() const {
2164  return new TypeVect(base(), _elem->dual(), _length);
2165}
2166
2167//------------------------------eq---------------------------------------------
2168// Structural equality check for Type representations
2169bool TypeVect::eq(const Type *t) const {
2170  const TypeVect *v = t->is_vect();
2171  return (_elem == v->_elem) && (_length == v->_length);
2172}
2173
2174//------------------------------hash-------------------------------------------
2175// Type-specific hashing function.
2176int TypeVect::hash(void) const {
2177  return (intptr_t)_elem + (intptr_t)_length;
2178}
2179
2180//------------------------------singleton--------------------------------------
2181// TRUE if Type is a singleton type, FALSE otherwise.   Singletons are simple
2182// constants (Ldi nodes).  Vector is singleton if all elements are the same
2183// constant value (when vector is created with Replicate code).
2184bool TypeVect::singleton(void) const {
2185// There is no Con node for vectors yet.
2186//  return _elem->singleton();
2187  return false;
2188}
2189
2190bool TypeVect::empty(void) const {
2191  return _elem->empty();
2192}
2193
2194//------------------------------dump2------------------------------------------
2195#ifndef PRODUCT
2196void TypeVect::dump2(Dict &d, uint depth, outputStream *st) const {
2197  switch (base()) {
2198  case VectorS:
2199    st->print("vectors["); break;
2200  case VectorD:
2201    st->print("vectord["); break;
2202  case VectorX:
2203    st->print("vectorx["); break;
2204  case VectorY:
2205    st->print("vectory["); break;
2206  case VectorZ:
2207    st->print("vectorz["); break;
2208  default:
2209    ShouldNotReachHere();
2210  }
2211  st->print("%d]:{", _length);
2212  _elem->dump2(d, depth, st);
2213  st->print("}");
2214}
2215#endif
2216
2217
2218//=============================================================================
2219// Convenience common pre-built types.
2220const TypePtr *TypePtr::NULL_PTR;
2221const TypePtr *TypePtr::NOTNULL;
2222const TypePtr *TypePtr::BOTTOM;
2223
2224//------------------------------meet-------------------------------------------
2225// Meet over the PTR enum
2226const TypePtr::PTR TypePtr::ptr_meet[TypePtr::lastPTR][TypePtr::lastPTR] = {
2227  //              TopPTR,    AnyNull,   Constant, Null,   NotNull, BotPTR,
2228  { /* Top     */ TopPTR,    AnyNull,   Constant, Null,   NotNull, BotPTR,},
2229  { /* AnyNull */ AnyNull,   AnyNull,   Constant, BotPTR, NotNull, BotPTR,},
2230  { /* Constant*/ Constant,  Constant,  Constant, BotPTR, NotNull, BotPTR,},
2231  { /* Null    */ Null,      BotPTR,    BotPTR,   Null,   BotPTR,  BotPTR,},
2232  { /* NotNull */ NotNull,   NotNull,   NotNull,  BotPTR, NotNull, BotPTR,},
2233  { /* BotPTR  */ BotPTR,    BotPTR,    BotPTR,   BotPTR, BotPTR,  BotPTR,}
2234};
2235
2236//------------------------------make-------------------------------------------
2237const TypePtr *TypePtr::make(TYPES t, enum PTR ptr, int offset, const TypePtr* speculative, int inline_depth) {
2238  return (TypePtr*)(new TypePtr(t,ptr,offset, speculative, inline_depth))->hashcons();
2239}
2240
2241//------------------------------cast_to_ptr_type-------------------------------
2242const Type *TypePtr::cast_to_ptr_type(PTR ptr) const {
2243  assert(_base == AnyPtr, "subclass must override cast_to_ptr_type");
2244  if( ptr == _ptr ) return this;
2245  return make(_base, ptr, _offset, _speculative, _inline_depth);
2246}
2247
2248//------------------------------get_con----------------------------------------
2249intptr_t TypePtr::get_con() const {
2250  assert( _ptr == Null, "" );
2251  return _offset;
2252}
2253
2254//------------------------------meet-------------------------------------------
2255// Compute the MEET of two types.  It returns a new Type object.
2256const Type *TypePtr::xmeet(const Type *t) const {
2257  const Type* res = xmeet_helper(t);
2258  if (res->isa_ptr() == NULL) {
2259    return res;
2260  }
2261
2262  const TypePtr* res_ptr = res->is_ptr();
2263  if (res_ptr->speculative() != NULL) {
2264    // type->speculative() == NULL means that speculation is no better
2265    // than type, i.e. type->speculative() == type. So there are 2
2266    // ways to represent the fact that we have no useful speculative
2267    // data and we should use a single one to be able to test for
2268    // equality between types. Check whether type->speculative() ==
2269    // type and set speculative to NULL if it is the case.
2270    if (res_ptr->remove_speculative() == res_ptr->speculative()) {
2271      return res_ptr->remove_speculative();
2272    }
2273  }
2274
2275  return res;
2276}
2277
2278const Type *TypePtr::xmeet_helper(const Type *t) const {
2279  // Perform a fast test for common case; meeting the same types together.
2280  if( this == t ) return this;  // Meeting same type-rep?
2281
2282  // Current "this->_base" is AnyPtr
2283  switch (t->base()) {          // switch on original type
2284  case Int:                     // Mixing ints & oops happens when javac
2285  case Long:                    // reuses local variables
2286  case FloatTop:
2287  case FloatCon:
2288  case FloatBot:
2289  case DoubleTop:
2290  case DoubleCon:
2291  case DoubleBot:
2292  case NarrowOop:
2293  case NarrowKlass:
2294  case Bottom:                  // Ye Olde Default
2295    return Type::BOTTOM;
2296  case Top:
2297    return this;
2298
2299  case AnyPtr: {                // Meeting to AnyPtrs
2300    const TypePtr *tp = t->is_ptr();
2301    const TypePtr* speculative = xmeet_speculative(tp);
2302    int depth = meet_inline_depth(tp->inline_depth());
2303    return make(AnyPtr, meet_ptr(tp->ptr()), meet_offset(tp->offset()), speculative, depth);
2304  }
2305  case RawPtr:                  // For these, flip the call around to cut down
2306  case OopPtr:
2307  case InstPtr:                 // on the cases I have to handle.
2308  case AryPtr:
2309  case MetadataPtr:
2310  case KlassPtr:
2311    return t->xmeet(this);      // Call in reverse direction
2312  default:                      // All else is a mistake
2313    typerr(t);
2314
2315  }
2316  return this;
2317}
2318
2319//------------------------------meet_offset------------------------------------
2320int TypePtr::meet_offset( int offset ) const {
2321  // Either is 'TOP' offset?  Return the other offset!
2322  if( _offset == OffsetTop ) return offset;
2323  if( offset == OffsetTop ) return _offset;
2324  // If either is different, return 'BOTTOM' offset
2325  if( _offset != offset ) return OffsetBot;
2326  return _offset;
2327}
2328
2329//------------------------------dual_offset------------------------------------
2330int TypePtr::dual_offset( ) const {
2331  if( _offset == OffsetTop ) return OffsetBot;// Map 'TOP' into 'BOTTOM'
2332  if( _offset == OffsetBot ) return OffsetTop;// Map 'BOTTOM' into 'TOP'
2333  return _offset;               // Map everything else into self
2334}
2335
2336//------------------------------xdual------------------------------------------
2337// Dual: compute field-by-field dual
2338const TypePtr::PTR TypePtr::ptr_dual[TypePtr::lastPTR] = {
2339  BotPTR, NotNull, Constant, Null, AnyNull, TopPTR
2340};
2341const Type *TypePtr::xdual() const {
2342  return new TypePtr(AnyPtr, dual_ptr(), dual_offset(), dual_speculative(), dual_inline_depth());
2343}
2344
2345//------------------------------xadd_offset------------------------------------
2346int TypePtr::xadd_offset( intptr_t offset ) const {
2347  // Adding to 'TOP' offset?  Return 'TOP'!
2348  if( _offset == OffsetTop || offset == OffsetTop ) return OffsetTop;
2349  // Adding to 'BOTTOM' offset?  Return 'BOTTOM'!
2350  if( _offset == OffsetBot || offset == OffsetBot ) return OffsetBot;
2351  // Addition overflows or "accidentally" equals to OffsetTop? Return 'BOTTOM'!
2352  offset += (intptr_t)_offset;
2353  if (offset != (int)offset || offset == OffsetTop) return OffsetBot;
2354
2355  // assert( _offset >= 0 && _offset+offset >= 0, "" );
2356  // It is possible to construct a negative offset during PhaseCCP
2357
2358  return (int)offset;        // Sum valid offsets
2359}
2360
2361//------------------------------add_offset-------------------------------------
2362const TypePtr *TypePtr::add_offset( intptr_t offset ) const {
2363  return make(AnyPtr, _ptr, xadd_offset(offset), _speculative, _inline_depth);
2364}
2365
2366//------------------------------eq---------------------------------------------
2367// Structural equality check for Type representations
2368bool TypePtr::eq( const Type *t ) const {
2369  const TypePtr *a = (const TypePtr*)t;
2370  return _ptr == a->ptr() && _offset == a->offset() && eq_speculative(a) && _inline_depth == a->_inline_depth;
2371}
2372
2373//------------------------------hash-------------------------------------------
2374// Type-specific hashing function.
2375int TypePtr::hash(void) const {
2376  return _ptr + _offset + hash_speculative() + _inline_depth;
2377;
2378}
2379
2380/**
2381 * Return same type without a speculative part
2382 */
2383const Type* TypePtr::remove_speculative() const {
2384  if (_speculative == NULL) {
2385    return this;
2386  }
2387  assert(_inline_depth == InlineDepthTop || _inline_depth == InlineDepthBottom, "non speculative type shouldn't have inline depth");
2388  return make(AnyPtr, _ptr, _offset, NULL, _inline_depth);
2389}
2390
2391/**
2392 * Return same type but drop speculative part if we know we won't use
2393 * it
2394 */
2395const Type* TypePtr::cleanup_speculative() const {
2396  if (speculative() == NULL) {
2397    return this;
2398  }
2399  const Type* no_spec = remove_speculative();
2400  // If this is NULL_PTR then we don't need the speculative type
2401  // (with_inline_depth in case the current type inline depth is
2402  // InlineDepthTop)
2403  if (no_spec == NULL_PTR->with_inline_depth(inline_depth())) {
2404    return no_spec;
2405  }
2406  if (above_centerline(speculative()->ptr())) {
2407    return no_spec;
2408  }
2409  const TypeOopPtr* spec_oopptr = speculative()->isa_oopptr();
2410  // If the speculative may be null and is an inexact klass then it
2411  // doesn't help
2412  if (speculative()->maybe_null() && (spec_oopptr == NULL || !spec_oopptr->klass_is_exact())) {
2413    return no_spec;
2414  }
2415  return this;
2416}
2417
2418/**
2419 * dual of the speculative part of the type
2420 */
2421const TypePtr* TypePtr::dual_speculative() const {
2422  if (_speculative == NULL) {
2423    return NULL;
2424  }
2425  return _speculative->dual()->is_ptr();
2426}
2427
2428/**
2429 * meet of the speculative parts of 2 types
2430 *
2431 * @param other  type to meet with
2432 */
2433const TypePtr* TypePtr::xmeet_speculative(const TypePtr* other) const {
2434  bool this_has_spec = (_speculative != NULL);
2435  bool other_has_spec = (other->speculative() != NULL);
2436
2437  if (!this_has_spec && !other_has_spec) {
2438    return NULL;
2439  }
2440
2441  // If we are at a point where control flow meets and one branch has
2442  // a speculative type and the other has not, we meet the speculative
2443  // type of one branch with the actual type of the other. If the
2444  // actual type is exact and the speculative is as well, then the
2445  // result is a speculative type which is exact and we can continue
2446  // speculation further.
2447  const TypePtr* this_spec = _speculative;
2448  const TypePtr* other_spec = other->speculative();
2449
2450  if (!this_has_spec) {
2451    this_spec = this;
2452  }
2453
2454  if (!other_has_spec) {
2455    other_spec = other;
2456  }
2457
2458  return this_spec->meet(other_spec)->is_ptr();
2459}
2460
2461/**
2462 * dual of the inline depth for this type (used for speculation)
2463 */
2464int TypePtr::dual_inline_depth() const {
2465  return -inline_depth();
2466}
2467
2468/**
2469 * meet of 2 inline depths (used for speculation)
2470 *
2471 * @param depth  depth to meet with
2472 */
2473int TypePtr::meet_inline_depth(int depth) const {
2474  return MAX2(inline_depth(), depth);
2475}
2476
2477/**
2478 * Are the speculative parts of 2 types equal?
2479 *
2480 * @param other  type to compare this one to
2481 */
2482bool TypePtr::eq_speculative(const TypePtr* other) const {
2483  if (_speculative == NULL || other->speculative() == NULL) {
2484    return _speculative == other->speculative();
2485  }
2486
2487  if (_speculative->base() != other->speculative()->base()) {
2488    return false;
2489  }
2490
2491  return _speculative->eq(other->speculative());
2492}
2493
2494/**
2495 * Hash of the speculative part of the type
2496 */
2497int TypePtr::hash_speculative() const {
2498  if (_speculative == NULL) {
2499    return 0;
2500  }
2501
2502  return _speculative->hash();
2503}
2504
2505/**
2506 * add offset to the speculative part of the type
2507 *
2508 * @param offset  offset to add
2509 */
2510const TypePtr* TypePtr::add_offset_speculative(intptr_t offset) const {
2511  if (_speculative == NULL) {
2512    return NULL;
2513  }
2514  return _speculative->add_offset(offset)->is_ptr();
2515}
2516
2517/**
2518 * return exact klass from the speculative type if there's one
2519 */
2520ciKlass* TypePtr::speculative_type() const {
2521  if (_speculative != NULL && _speculative->isa_oopptr()) {
2522    const TypeOopPtr* speculative = _speculative->join(this)->is_oopptr();
2523    if (speculative->klass_is_exact()) {
2524      return speculative->klass();
2525    }
2526  }
2527  return NULL;
2528}
2529
2530/**
2531 * return true if speculative type may be null
2532 */
2533bool TypePtr::speculative_maybe_null() const {
2534  if (_speculative != NULL) {
2535    const TypePtr* speculative = _speculative->join(this)->is_ptr();
2536    return speculative->maybe_null();
2537  }
2538  return true;
2539}
2540
2541/**
2542 * Same as TypePtr::speculative_type() but return the klass only if
2543 * the speculative tells us is not null
2544 */
2545ciKlass* TypePtr::speculative_type_not_null() const {
2546  if (speculative_maybe_null()) {
2547    return NULL;
2548  }
2549  return speculative_type();
2550}
2551
2552/**
2553 * Check whether new profiling would improve speculative type
2554 *
2555 * @param   exact_kls    class from profiling
2556 * @param   inline_depth inlining depth of profile point
2557 *
2558 * @return  true if type profile is valuable
2559 */
2560bool TypePtr::would_improve_type(ciKlass* exact_kls, int inline_depth) const {
2561  // no profiling?
2562  if (exact_kls == NULL) {
2563    return false;
2564  }
2565  // no speculative type or non exact speculative type?
2566  if (speculative_type() == NULL) {
2567    return true;
2568  }
2569  // If the node already has an exact speculative type keep it,
2570  // unless it was provided by profiling that is at a deeper
2571  // inlining level. Profiling at a higher inlining depth is
2572  // expected to be less accurate.
2573  if (_speculative->inline_depth() == InlineDepthBottom) {
2574    return false;
2575  }
2576  assert(_speculative->inline_depth() != InlineDepthTop, "can't do the comparison");
2577  return inline_depth < _speculative->inline_depth();
2578}
2579
2580/**
2581 * Check whether new profiling would improve ptr (= tells us it is non
2582 * null)
2583 *
2584 * @param   maybe_null true if profiling tells the ptr may be null
2585 *
2586 * @return  true if ptr profile is valuable
2587 */
2588bool TypePtr::would_improve_ptr(bool maybe_null) const {
2589  // profiling doesn't tell us anything useful
2590  if (maybe_null) {
2591    return false;
2592  }
2593  // We already know this is not be null
2594  if (!this->maybe_null()) {
2595    return false;
2596  }
2597  // We already know the speculative type cannot be null
2598  if (!speculative_maybe_null()) {
2599    return false;
2600  }
2601  return true;
2602}
2603
2604//------------------------------dump2------------------------------------------
2605const char *const TypePtr::ptr_msg[TypePtr::lastPTR] = {
2606  "TopPTR","AnyNull","Constant","NULL","NotNull","BotPTR"
2607};
2608
2609#ifndef PRODUCT
2610void TypePtr::dump2( Dict &d, uint depth, outputStream *st ) const {
2611  if( _ptr == Null ) st->print("NULL");
2612  else st->print("%s *", ptr_msg[_ptr]);
2613  if( _offset == OffsetTop ) st->print("+top");
2614  else if( _offset == OffsetBot ) st->print("+bot");
2615  else if( _offset ) st->print("+%d", _offset);
2616  dump_inline_depth(st);
2617  dump_speculative(st);
2618}
2619
2620/**
2621 *dump the speculative part of the type
2622 */
2623void TypePtr::dump_speculative(outputStream *st) const {
2624  if (_speculative != NULL) {
2625    st->print(" (speculative=");
2626    _speculative->dump_on(st);
2627    st->print(")");
2628  }
2629}
2630
2631/**
2632 *dump the inline depth of the type
2633 */
2634void TypePtr::dump_inline_depth(outputStream *st) const {
2635  if (_inline_depth != InlineDepthBottom) {
2636    if (_inline_depth == InlineDepthTop) {
2637      st->print(" (inline_depth=InlineDepthTop)");
2638    } else {
2639      st->print(" (inline_depth=%d)", _inline_depth);
2640    }
2641  }
2642}
2643#endif
2644
2645//------------------------------singleton--------------------------------------
2646// TRUE if Type is a singleton type, FALSE otherwise.   Singletons are simple
2647// constants
2648bool TypePtr::singleton(void) const {
2649  // TopPTR, Null, AnyNull, Constant are all singletons
2650  return (_offset != OffsetBot) && !below_centerline(_ptr);
2651}
2652
2653bool TypePtr::empty(void) const {
2654  return (_offset == OffsetTop) || above_centerline(_ptr);
2655}
2656
2657//=============================================================================
2658// Convenience common pre-built types.
2659const TypeRawPtr *TypeRawPtr::BOTTOM;
2660const TypeRawPtr *TypeRawPtr::NOTNULL;
2661
2662//------------------------------make-------------------------------------------
2663const TypeRawPtr *TypeRawPtr::make( enum PTR ptr ) {
2664  assert( ptr != Constant, "what is the constant?" );
2665  assert( ptr != Null, "Use TypePtr for NULL" );
2666  return (TypeRawPtr*)(new TypeRawPtr(ptr,0))->hashcons();
2667}
2668
2669const TypeRawPtr *TypeRawPtr::make( address bits ) {
2670  assert( bits, "Use TypePtr for NULL" );
2671  return (TypeRawPtr*)(new TypeRawPtr(Constant,bits))->hashcons();
2672}
2673
2674//------------------------------cast_to_ptr_type-------------------------------
2675const Type *TypeRawPtr::cast_to_ptr_type(PTR ptr) const {
2676  assert( ptr != Constant, "what is the constant?" );
2677  assert( ptr != Null, "Use TypePtr for NULL" );
2678  assert( _bits==0, "Why cast a constant address?");
2679  if( ptr == _ptr ) return this;
2680  return make(ptr);
2681}
2682
2683//------------------------------get_con----------------------------------------
2684intptr_t TypeRawPtr::get_con() const {
2685  assert( _ptr == Null || _ptr == Constant, "" );
2686  return (intptr_t)_bits;
2687}
2688
2689//------------------------------meet-------------------------------------------
2690// Compute the MEET of two types.  It returns a new Type object.
2691const Type *TypeRawPtr::xmeet( const Type *t ) const {
2692  // Perform a fast test for common case; meeting the same types together.
2693  if( this == t ) return this;  // Meeting same type-rep?
2694
2695  // Current "this->_base" is RawPtr
2696  switch( t->base() ) {         // switch on original type
2697  case Bottom:                  // Ye Olde Default
2698    return t;
2699  case Top:
2700    return this;
2701  case AnyPtr:                  // Meeting to AnyPtrs
2702    break;
2703  case RawPtr: {                // might be top, bot, any/not or constant
2704    enum PTR tptr = t->is_ptr()->ptr();
2705    enum PTR ptr = meet_ptr( tptr );
2706    if( ptr == Constant ) {     // Cannot be equal constants, so...
2707      if( tptr == Constant && _ptr != Constant)  return t;
2708      if( _ptr == Constant && tptr != Constant)  return this;
2709      ptr = NotNull;            // Fall down in lattice
2710    }
2711    return make( ptr );
2712  }
2713
2714  case OopPtr:
2715  case InstPtr:
2716  case AryPtr:
2717  case MetadataPtr:
2718  case KlassPtr:
2719    return TypePtr::BOTTOM;     // Oop meet raw is not well defined
2720  default:                      // All else is a mistake
2721    typerr(t);
2722  }
2723
2724  // Found an AnyPtr type vs self-RawPtr type
2725  const TypePtr *tp = t->is_ptr();
2726  switch (tp->ptr()) {
2727  case TypePtr::TopPTR:  return this;
2728  case TypePtr::BotPTR:  return t;
2729  case TypePtr::Null:
2730    if( _ptr == TypePtr::TopPTR ) return t;
2731    return TypeRawPtr::BOTTOM;
2732  case TypePtr::NotNull: return TypePtr::make(AnyPtr, meet_ptr(TypePtr::NotNull), tp->meet_offset(0), tp->speculative(), tp->inline_depth());
2733  case TypePtr::AnyNull:
2734    if( _ptr == TypePtr::Constant) return this;
2735    return make( meet_ptr(TypePtr::AnyNull) );
2736  default: ShouldNotReachHere();
2737  }
2738  return this;
2739}
2740
2741//------------------------------xdual------------------------------------------
2742// Dual: compute field-by-field dual
2743const Type *TypeRawPtr::xdual() const {
2744  return new TypeRawPtr( dual_ptr(), _bits );
2745}
2746
2747//------------------------------add_offset-------------------------------------
2748const TypePtr *TypeRawPtr::add_offset( intptr_t offset ) const {
2749  if( offset == OffsetTop ) return BOTTOM; // Undefined offset-> undefined pointer
2750  if( offset == OffsetBot ) return BOTTOM; // Unknown offset-> unknown pointer
2751  if( offset == 0 ) return this; // No change
2752  switch (_ptr) {
2753  case TypePtr::TopPTR:
2754  case TypePtr::BotPTR:
2755  case TypePtr::NotNull:
2756    return this;
2757  case TypePtr::Null:
2758  case TypePtr::Constant: {
2759    address bits = _bits+offset;
2760    if ( bits == 0 ) return TypePtr::NULL_PTR;
2761    return make( bits );
2762  }
2763  default:  ShouldNotReachHere();
2764  }
2765  return NULL;                  // Lint noise
2766}
2767
2768//------------------------------eq---------------------------------------------
2769// Structural equality check for Type representations
2770bool TypeRawPtr::eq( const Type *t ) const {
2771  const TypeRawPtr *a = (const TypeRawPtr*)t;
2772  return _bits == a->_bits && TypePtr::eq(t);
2773}
2774
2775//------------------------------hash-------------------------------------------
2776// Type-specific hashing function.
2777int TypeRawPtr::hash(void) const {
2778  return (intptr_t)_bits + TypePtr::hash();
2779}
2780
2781//------------------------------dump2------------------------------------------
2782#ifndef PRODUCT
2783void TypeRawPtr::dump2( Dict &d, uint depth, outputStream *st ) const {
2784  if( _ptr == Constant )
2785    st->print(INTPTR_FORMAT, p2i(_bits));
2786  else
2787    st->print("rawptr:%s", ptr_msg[_ptr]);
2788}
2789#endif
2790
2791//=============================================================================
2792// Convenience common pre-built type.
2793const TypeOopPtr *TypeOopPtr::BOTTOM;
2794
2795//------------------------------TypeOopPtr-------------------------------------
2796TypeOopPtr::TypeOopPtr(TYPES t, PTR ptr, ciKlass* k, bool xk, ciObject* o, int offset,
2797                       int instance_id, const TypePtr* speculative, int inline_depth)
2798  : TypePtr(t, ptr, offset, speculative, inline_depth),
2799    _const_oop(o), _klass(k),
2800    _klass_is_exact(xk),
2801    _is_ptr_to_narrowoop(false),
2802    _is_ptr_to_narrowklass(false),
2803    _is_ptr_to_boxed_value(false),
2804    _instance_id(instance_id) {
2805  if (Compile::current()->eliminate_boxing() && (t == InstPtr) &&
2806      (offset > 0) && xk && (k != 0) && k->is_instance_klass()) {
2807    _is_ptr_to_boxed_value = k->as_instance_klass()->is_boxed_value_offset(offset);
2808  }
2809#ifdef _LP64
2810  if (_offset != 0) {
2811    if (_offset == oopDesc::klass_offset_in_bytes()) {
2812      _is_ptr_to_narrowklass = UseCompressedClassPointers;
2813    } else if (klass() == NULL) {
2814      // Array with unknown body type
2815      assert(this->isa_aryptr(), "only arrays without klass");
2816      _is_ptr_to_narrowoop = UseCompressedOops;
2817    } else if (this->isa_aryptr()) {
2818      _is_ptr_to_narrowoop = (UseCompressedOops && klass()->is_obj_array_klass() &&
2819                             _offset != arrayOopDesc::length_offset_in_bytes());
2820    } else if (klass()->is_instance_klass()) {
2821      ciInstanceKlass* ik = klass()->as_instance_klass();
2822      ciField* field = NULL;
2823      if (this->isa_klassptr()) {
2824        // Perm objects don't use compressed references
2825      } else if (_offset == OffsetBot || _offset == OffsetTop) {
2826        // unsafe access
2827        _is_ptr_to_narrowoop = UseCompressedOops;
2828      } else { // exclude unsafe ops
2829        assert(this->isa_instptr(), "must be an instance ptr.");
2830
2831        if (klass() == ciEnv::current()->Class_klass() &&
2832            (_offset == java_lang_Class::klass_offset_in_bytes() ||
2833             _offset == java_lang_Class::array_klass_offset_in_bytes())) {
2834          // Special hidden fields from the Class.
2835          assert(this->isa_instptr(), "must be an instance ptr.");
2836          _is_ptr_to_narrowoop = false;
2837        } else if (klass() == ciEnv::current()->Class_klass() &&
2838                   _offset >= InstanceMirrorKlass::offset_of_static_fields()) {
2839          // Static fields
2840          assert(o != NULL, "must be constant");
2841          ciInstanceKlass* k = o->as_instance()->java_lang_Class_klass()->as_instance_klass();
2842          ciField* field = k->get_field_by_offset(_offset, true);
2843          assert(field != NULL, "missing field");
2844          BasicType basic_elem_type = field->layout_type();
2845          _is_ptr_to_narrowoop = UseCompressedOops && (basic_elem_type == T_OBJECT ||
2846                                                       basic_elem_type == T_ARRAY);
2847        } else {
2848          // Instance fields which contains a compressed oop references.
2849          field = ik->get_field_by_offset(_offset, false);
2850          if (field != NULL) {
2851            BasicType basic_elem_type = field->layout_type();
2852            _is_ptr_to_narrowoop = UseCompressedOops && (basic_elem_type == T_OBJECT ||
2853                                                         basic_elem_type == T_ARRAY);
2854          } else if (klass()->equals(ciEnv::current()->Object_klass())) {
2855            // Compile::find_alias_type() cast exactness on all types to verify
2856            // that it does not affect alias type.
2857            _is_ptr_to_narrowoop = UseCompressedOops;
2858          } else {
2859            // Type for the copy start in LibraryCallKit::inline_native_clone().
2860            _is_ptr_to_narrowoop = UseCompressedOops;
2861          }
2862        }
2863      }
2864    }
2865  }
2866#endif
2867}
2868
2869//------------------------------make-------------------------------------------
2870const TypeOopPtr *TypeOopPtr::make(PTR ptr, int offset, int instance_id,
2871                                     const TypePtr* speculative, int inline_depth) {
2872  assert(ptr != Constant, "no constant generic pointers");
2873  ciKlass*  k = Compile::current()->env()->Object_klass();
2874  bool      xk = false;
2875  ciObject* o = NULL;
2876  return (TypeOopPtr*)(new TypeOopPtr(OopPtr, ptr, k, xk, o, offset, instance_id, speculative, inline_depth))->hashcons();
2877}
2878
2879
2880//------------------------------cast_to_ptr_type-------------------------------
2881const Type *TypeOopPtr::cast_to_ptr_type(PTR ptr) const {
2882  assert(_base == OopPtr, "subclass must override cast_to_ptr_type");
2883  if( ptr == _ptr ) return this;
2884  return make(ptr, _offset, _instance_id, _speculative, _inline_depth);
2885}
2886
2887//-----------------------------cast_to_instance_id----------------------------
2888const TypeOopPtr *TypeOopPtr::cast_to_instance_id(int instance_id) const {
2889  // There are no instances of a general oop.
2890  // Return self unchanged.
2891  return this;
2892}
2893
2894//-----------------------------cast_to_exactness-------------------------------
2895const Type *TypeOopPtr::cast_to_exactness(bool klass_is_exact) const {
2896  // There is no such thing as an exact general oop.
2897  // Return self unchanged.
2898  return this;
2899}
2900
2901
2902//------------------------------as_klass_type----------------------------------
2903// Return the klass type corresponding to this instance or array type.
2904// It is the type that is loaded from an object of this type.
2905const TypeKlassPtr* TypeOopPtr::as_klass_type() const {
2906  ciKlass* k = klass();
2907  bool    xk = klass_is_exact();
2908  if (k == NULL)
2909    return TypeKlassPtr::OBJECT;
2910  else
2911    return TypeKlassPtr::make(xk? Constant: NotNull, k, 0);
2912}
2913
2914//------------------------------meet-------------------------------------------
2915// Compute the MEET of two types.  It returns a new Type object.
2916const Type *TypeOopPtr::xmeet_helper(const Type *t) const {
2917  // Perform a fast test for common case; meeting the same types together.
2918  if( this == t ) return this;  // Meeting same type-rep?
2919
2920  // Current "this->_base" is OopPtr
2921  switch (t->base()) {          // switch on original type
2922
2923  case Int:                     // Mixing ints & oops happens when javac
2924  case Long:                    // reuses local variables
2925  case FloatTop:
2926  case FloatCon:
2927  case FloatBot:
2928  case DoubleTop:
2929  case DoubleCon:
2930  case DoubleBot:
2931  case NarrowOop:
2932  case NarrowKlass:
2933  case Bottom:                  // Ye Olde Default
2934    return Type::BOTTOM;
2935  case Top:
2936    return this;
2937
2938  default:                      // All else is a mistake
2939    typerr(t);
2940
2941  case RawPtr:
2942  case MetadataPtr:
2943  case KlassPtr:
2944    return TypePtr::BOTTOM;     // Oop meet raw is not well defined
2945
2946  case AnyPtr: {
2947    // Found an AnyPtr type vs self-OopPtr type
2948    const TypePtr *tp = t->is_ptr();
2949    int offset = meet_offset(tp->offset());
2950    PTR ptr = meet_ptr(tp->ptr());
2951    const TypePtr* speculative = xmeet_speculative(tp);
2952    int depth = meet_inline_depth(tp->inline_depth());
2953    switch (tp->ptr()) {
2954    case Null:
2955      if (ptr == Null)  return TypePtr::make(AnyPtr, ptr, offset, speculative, depth);
2956      // else fall through:
2957    case TopPTR:
2958    case AnyNull: {
2959      int instance_id = meet_instance_id(InstanceTop);
2960      return make(ptr, offset, instance_id, speculative, depth);
2961    }
2962    case BotPTR:
2963    case NotNull:
2964      return TypePtr::make(AnyPtr, ptr, offset, speculative, depth);
2965    default: typerr(t);
2966    }
2967  }
2968
2969  case OopPtr: {                 // Meeting to other OopPtrs
2970    const TypeOopPtr *tp = t->is_oopptr();
2971    int instance_id = meet_instance_id(tp->instance_id());
2972    const TypePtr* speculative = xmeet_speculative(tp);
2973    int depth = meet_inline_depth(tp->inline_depth());
2974    return make(meet_ptr(tp->ptr()), meet_offset(tp->offset()), instance_id, speculative, depth);
2975  }
2976
2977  case InstPtr:                  // For these, flip the call around to cut down
2978  case AryPtr:
2979    return t->xmeet(this);      // Call in reverse direction
2980
2981  } // End of switch
2982  return this;                  // Return the double constant
2983}
2984
2985
2986//------------------------------xdual------------------------------------------
2987// Dual of a pure heap pointer.  No relevant klass or oop information.
2988const Type *TypeOopPtr::xdual() const {
2989  assert(klass() == Compile::current()->env()->Object_klass(), "no klasses here");
2990  assert(const_oop() == NULL,             "no constants here");
2991  return new TypeOopPtr(_base, dual_ptr(), klass(), klass_is_exact(), const_oop(), dual_offset(), dual_instance_id(), dual_speculative(), dual_inline_depth());
2992}
2993
2994//--------------------------make_from_klass_common-----------------------------
2995// Computes the element-type given a klass.
2996const TypeOopPtr* TypeOopPtr::make_from_klass_common(ciKlass *klass, bool klass_change, bool try_for_exact) {
2997  if (klass->is_instance_klass()) {
2998    Compile* C = Compile::current();
2999    Dependencies* deps = C->dependencies();
3000    assert((deps != NULL) == (C->method() != NULL && C->method()->code_size() > 0), "sanity");
3001    // Element is an instance
3002    bool klass_is_exact = false;
3003    if (klass->is_loaded()) {
3004      // Try to set klass_is_exact.
3005      ciInstanceKlass* ik = klass->as_instance_klass();
3006      klass_is_exact = ik->is_final();
3007      if (!klass_is_exact && klass_change
3008          && deps != NULL && UseUniqueSubclasses) {
3009        ciInstanceKlass* sub = ik->unique_concrete_subklass();
3010        if (sub != NULL) {
3011          deps->assert_abstract_with_unique_concrete_subtype(ik, sub);
3012          klass = ik = sub;
3013          klass_is_exact = sub->is_final();
3014        }
3015      }
3016      if (!klass_is_exact && try_for_exact
3017          && deps != NULL && UseExactTypes) {
3018        if (!ik->is_interface() && !ik->has_subklass()) {
3019          // Add a dependence; if concrete subclass added we need to recompile
3020          deps->assert_leaf_type(ik);
3021          klass_is_exact = true;
3022        }
3023      }
3024    }
3025    return TypeInstPtr::make(TypePtr::BotPTR, klass, klass_is_exact, NULL, 0);
3026  } else if (klass->is_obj_array_klass()) {
3027    // Element is an object array. Recursively call ourself.
3028    const TypeOopPtr *etype = TypeOopPtr::make_from_klass_common(klass->as_obj_array_klass()->element_klass(), false, try_for_exact);
3029    bool xk = etype->klass_is_exact();
3030    const TypeAry* arr0 = TypeAry::make(etype, TypeInt::POS);
3031    // We used to pass NotNull in here, asserting that the sub-arrays
3032    // are all not-null.  This is not true in generally, as code can
3033    // slam NULLs down in the subarrays.
3034    const TypeAryPtr* arr = TypeAryPtr::make(TypePtr::BotPTR, arr0, klass, xk, 0);
3035    return arr;
3036  } else if (klass->is_type_array_klass()) {
3037    // Element is an typeArray
3038    const Type* etype = get_const_basic_type(klass->as_type_array_klass()->element_type());
3039    const TypeAry* arr0 = TypeAry::make(etype, TypeInt::POS);
3040    // We used to pass NotNull in here, asserting that the array pointer
3041    // is not-null. That was not true in general.
3042    const TypeAryPtr* arr = TypeAryPtr::make(TypePtr::BotPTR, arr0, klass, true, 0);
3043    return arr;
3044  } else {
3045    ShouldNotReachHere();
3046    return NULL;
3047  }
3048}
3049
3050//------------------------------make_from_constant-----------------------------
3051// Make a java pointer from an oop constant
3052const TypeOopPtr* TypeOopPtr::make_from_constant(ciObject* o, bool require_constant) {
3053  assert(!o->is_null_object(), "null object not yet handled here.");
3054  ciKlass* klass = o->klass();
3055  if (klass->is_instance_klass()) {
3056    // Element is an instance
3057    if (require_constant) {
3058      if (!o->can_be_constant())  return NULL;
3059    } else if (!o->should_be_constant()) {
3060      return TypeInstPtr::make(TypePtr::NotNull, klass, true, NULL, 0);
3061    }
3062    return TypeInstPtr::make(o);
3063  } else if (klass->is_obj_array_klass()) {
3064    // Element is an object array. Recursively call ourself.
3065    const TypeOopPtr *etype =
3066      TypeOopPtr::make_from_klass_raw(klass->as_obj_array_klass()->element_klass());
3067    const TypeAry* arr0 = TypeAry::make(etype, TypeInt::make(o->as_array()->length()));
3068    // We used to pass NotNull in here, asserting that the sub-arrays
3069    // are all not-null.  This is not true in generally, as code can
3070    // slam NULLs down in the subarrays.
3071    if (require_constant) {
3072      if (!o->can_be_constant())  return NULL;
3073    } else if (!o->should_be_constant()) {
3074      return TypeAryPtr::make(TypePtr::NotNull, arr0, klass, true, 0);
3075    }
3076    const TypeAryPtr* arr = TypeAryPtr::make(TypePtr::Constant, o, arr0, klass, true, 0);
3077    return arr;
3078  } else if (klass->is_type_array_klass()) {
3079    // Element is an typeArray
3080    const Type* etype =
3081      (Type*)get_const_basic_type(klass->as_type_array_klass()->element_type());
3082    const TypeAry* arr0 = TypeAry::make(etype, TypeInt::make(o->as_array()->length()));
3083    // We used to pass NotNull in here, asserting that the array pointer
3084    // is not-null. That was not true in general.
3085    if (require_constant) {
3086      if (!o->can_be_constant())  return NULL;
3087    } else if (!o->should_be_constant()) {
3088      return TypeAryPtr::make(TypePtr::NotNull, arr0, klass, true, 0);
3089    }
3090    const TypeAryPtr* arr = TypeAryPtr::make(TypePtr::Constant, o, arr0, klass, true, 0);
3091    return arr;
3092  }
3093
3094  fatal("unhandled object type");
3095  return NULL;
3096}
3097
3098//------------------------------get_con----------------------------------------
3099intptr_t TypeOopPtr::get_con() const {
3100  assert( _ptr == Null || _ptr == Constant, "" );
3101  assert( _offset >= 0, "" );
3102
3103  if (_offset != 0) {
3104    // After being ported to the compiler interface, the compiler no longer
3105    // directly manipulates the addresses of oops.  Rather, it only has a pointer
3106    // to a handle at compile time.  This handle is embedded in the generated
3107    // code and dereferenced at the time the nmethod is made.  Until that time,
3108    // it is not reasonable to do arithmetic with the addresses of oops (we don't
3109    // have access to the addresses!).  This does not seem to currently happen,
3110    // but this assertion here is to help prevent its occurence.
3111    tty->print_cr("Found oop constant with non-zero offset");
3112    ShouldNotReachHere();
3113  }
3114
3115  return (intptr_t)const_oop()->constant_encoding();
3116}
3117
3118
3119//-----------------------------filter------------------------------------------
3120// Do not allow interface-vs.-noninterface joins to collapse to top.
3121const Type *TypeOopPtr::filter_helper(const Type *kills, bool include_speculative) const {
3122
3123  const Type* ft = join_helper(kills, include_speculative);
3124  const TypeInstPtr* ftip = ft->isa_instptr();
3125  const TypeInstPtr* ktip = kills->isa_instptr();
3126
3127  if (ft->empty()) {
3128    // Check for evil case of 'this' being a class and 'kills' expecting an
3129    // interface.  This can happen because the bytecodes do not contain
3130    // enough type info to distinguish a Java-level interface variable
3131    // from a Java-level object variable.  If we meet 2 classes which
3132    // both implement interface I, but their meet is at 'j/l/O' which
3133    // doesn't implement I, we have no way to tell if the result should
3134    // be 'I' or 'j/l/O'.  Thus we'll pick 'j/l/O'.  If this then flows
3135    // into a Phi which "knows" it's an Interface type we'll have to
3136    // uplift the type.
3137    if (!empty() && ktip != NULL && ktip->is_loaded() && ktip->klass()->is_interface())
3138      return kills;             // Uplift to interface
3139
3140    return Type::TOP;           // Canonical empty value
3141  }
3142
3143  // If we have an interface-typed Phi or cast and we narrow to a class type,
3144  // the join should report back the class.  However, if we have a J/L/Object
3145  // class-typed Phi and an interface flows in, it's possible that the meet &
3146  // join report an interface back out.  This isn't possible but happens
3147  // because the type system doesn't interact well with interfaces.
3148  if (ftip != NULL && ktip != NULL &&
3149      ftip->is_loaded() &&  ftip->klass()->is_interface() &&
3150      ktip->is_loaded() && !ktip->klass()->is_interface()) {
3151    assert(!ftip->klass_is_exact(), "interface could not be exact");
3152    return ktip->cast_to_ptr_type(ftip->ptr());
3153  }
3154
3155  return ft;
3156}
3157
3158//------------------------------eq---------------------------------------------
3159// Structural equality check for Type representations
3160bool TypeOopPtr::eq( const Type *t ) const {
3161  const TypeOopPtr *a = (const TypeOopPtr*)t;
3162  if (_klass_is_exact != a->_klass_is_exact ||
3163      _instance_id != a->_instance_id)  return false;
3164  ciObject* one = const_oop();
3165  ciObject* two = a->const_oop();
3166  if (one == NULL || two == NULL) {
3167    return (one == two) && TypePtr::eq(t);
3168  } else {
3169    return one->equals(two) && TypePtr::eq(t);
3170  }
3171}
3172
3173//------------------------------hash-------------------------------------------
3174// Type-specific hashing function.
3175int TypeOopPtr::hash(void) const {
3176  return
3177    (const_oop() ? const_oop()->hash() : 0) +
3178    _klass_is_exact +
3179    _instance_id +
3180    TypePtr::hash();
3181}
3182
3183//------------------------------dump2------------------------------------------
3184#ifndef PRODUCT
3185void TypeOopPtr::dump2( Dict &d, uint depth, outputStream *st ) const {
3186  st->print("oopptr:%s", ptr_msg[_ptr]);
3187  if( _klass_is_exact ) st->print(":exact");
3188  if( const_oop() ) st->print(INTPTR_FORMAT, p2i(const_oop()));
3189  switch( _offset ) {
3190  case OffsetTop: st->print("+top"); break;
3191  case OffsetBot: st->print("+any"); break;
3192  case         0: break;
3193  default:        st->print("+%d",_offset); break;
3194  }
3195  if (_instance_id == InstanceTop)
3196    st->print(",iid=top");
3197  else if (_instance_id != InstanceBot)
3198    st->print(",iid=%d",_instance_id);
3199
3200  dump_inline_depth(st);
3201  dump_speculative(st);
3202}
3203#endif
3204
3205//------------------------------singleton--------------------------------------
3206// TRUE if Type is a singleton type, FALSE otherwise.   Singletons are simple
3207// constants
3208bool TypeOopPtr::singleton(void) const {
3209  // detune optimizer to not generate constant oop + constant offset as a constant!
3210  // TopPTR, Null, AnyNull, Constant are all singletons
3211  return (_offset == 0) && !below_centerline(_ptr);
3212}
3213
3214//------------------------------add_offset-------------------------------------
3215const TypePtr *TypeOopPtr::add_offset(intptr_t offset) const {
3216  return make(_ptr, xadd_offset(offset), _instance_id, add_offset_speculative(offset), _inline_depth);
3217}
3218
3219/**
3220 * Return same type without a speculative part
3221 */
3222const Type* TypeOopPtr::remove_speculative() const {
3223  if (_speculative == NULL) {
3224    return this;
3225  }
3226  assert(_inline_depth == InlineDepthTop || _inline_depth == InlineDepthBottom, "non speculative type shouldn't have inline depth");
3227  return make(_ptr, _offset, _instance_id, NULL, _inline_depth);
3228}
3229
3230/**
3231 * Return same type but drop speculative part if we know we won't use
3232 * it
3233 */
3234const Type* TypeOopPtr::cleanup_speculative() const {
3235  // If the klass is exact and the ptr is not null then there's
3236  // nothing that the speculative type can help us with
3237  if (klass_is_exact() && !maybe_null()) {
3238    return remove_speculative();
3239  }
3240  return TypePtr::cleanup_speculative();
3241}
3242
3243/**
3244 * Return same type but with a different inline depth (used for speculation)
3245 *
3246 * @param depth  depth to meet with
3247 */
3248const TypePtr* TypeOopPtr::with_inline_depth(int depth) const {
3249  if (!UseInlineDepthForSpeculativeTypes) {
3250    return this;
3251  }
3252  return make(_ptr, _offset, _instance_id, _speculative, depth);
3253}
3254
3255//------------------------------meet_instance_id--------------------------------
3256int TypeOopPtr::meet_instance_id( int instance_id ) const {
3257  // Either is 'TOP' instance?  Return the other instance!
3258  if( _instance_id == InstanceTop ) return  instance_id;
3259  if(  instance_id == InstanceTop ) return _instance_id;
3260  // If either is different, return 'BOTTOM' instance
3261  if( _instance_id != instance_id ) return InstanceBot;
3262  return _instance_id;
3263}
3264
3265//------------------------------dual_instance_id--------------------------------
3266int TypeOopPtr::dual_instance_id( ) const {
3267  if( _instance_id == InstanceTop ) return InstanceBot; // Map TOP into BOTTOM
3268  if( _instance_id == InstanceBot ) return InstanceTop; // Map BOTTOM into TOP
3269  return _instance_id;              // Map everything else into self
3270}
3271
3272/**
3273 * Check whether new profiling would improve speculative type
3274 *
3275 * @param   exact_kls    class from profiling
3276 * @param   inline_depth inlining depth of profile point
3277 *
3278 * @return  true if type profile is valuable
3279 */
3280bool TypeOopPtr::would_improve_type(ciKlass* exact_kls, int inline_depth) const {
3281  // no way to improve an already exact type
3282  if (klass_is_exact()) {
3283    return false;
3284  }
3285  return TypePtr::would_improve_type(exact_kls, inline_depth);
3286}
3287
3288//=============================================================================
3289// Convenience common pre-built types.
3290const TypeInstPtr *TypeInstPtr::NOTNULL;
3291const TypeInstPtr *TypeInstPtr::BOTTOM;
3292const TypeInstPtr *TypeInstPtr::MIRROR;
3293const TypeInstPtr *TypeInstPtr::MARK;
3294const TypeInstPtr *TypeInstPtr::KLASS;
3295
3296//------------------------------TypeInstPtr-------------------------------------
3297TypeInstPtr::TypeInstPtr(PTR ptr, ciKlass* k, bool xk, ciObject* o, int off,
3298                         int instance_id, const TypePtr* speculative, int inline_depth)
3299  : TypeOopPtr(InstPtr, ptr, k, xk, o, off, instance_id, speculative, inline_depth),
3300    _name(k->name()) {
3301   assert(k != NULL &&
3302          (k->is_loaded() || o == NULL),
3303          "cannot have constants with non-loaded klass");
3304};
3305
3306//------------------------------make-------------------------------------------
3307const TypeInstPtr *TypeInstPtr::make(PTR ptr,
3308                                     ciKlass* k,
3309                                     bool xk,
3310                                     ciObject* o,
3311                                     int offset,
3312                                     int instance_id,
3313                                     const TypePtr* speculative,
3314                                     int inline_depth) {
3315  assert( !k->is_loaded() || k->is_instance_klass(), "Must be for instance");
3316  // Either const_oop() is NULL or else ptr is Constant
3317  assert( (!o && ptr != Constant) || (o && ptr == Constant),
3318          "constant pointers must have a value supplied" );
3319  // Ptr is never Null
3320  assert( ptr != Null, "NULL pointers are not typed" );
3321
3322  assert(instance_id <= 0 || xk || !UseExactTypes, "instances are always exactly typed");
3323  if (!UseExactTypes)  xk = false;
3324  if (ptr == Constant) {
3325    // Note:  This case includes meta-object constants, such as methods.
3326    xk = true;
3327  } else if (k->is_loaded()) {
3328    ciInstanceKlass* ik = k->as_instance_klass();
3329    if (!xk && ik->is_final())     xk = true;   // no inexact final klass
3330    if (xk && ik->is_interface())  xk = false;  // no exact interface
3331  }
3332
3333  // Now hash this baby
3334  TypeInstPtr *result =
3335    (TypeInstPtr*)(new TypeInstPtr(ptr, k, xk, o ,offset, instance_id, speculative, inline_depth))->hashcons();
3336
3337  return result;
3338}
3339
3340/**
3341 *  Create constant type for a constant boxed value
3342 */
3343const Type* TypeInstPtr::get_const_boxed_value() const {
3344  assert(is_ptr_to_boxed_value(), "should be called only for boxed value");
3345  assert((const_oop() != NULL), "should be called only for constant object");
3346  ciConstant constant = const_oop()->as_instance()->field_value_by_offset(offset());
3347  BasicType bt = constant.basic_type();
3348  switch (bt) {
3349    case T_BOOLEAN:  return TypeInt::make(constant.as_boolean());
3350    case T_INT:      return TypeInt::make(constant.as_int());
3351    case T_CHAR:     return TypeInt::make(constant.as_char());
3352    case T_BYTE:     return TypeInt::make(constant.as_byte());
3353    case T_SHORT:    return TypeInt::make(constant.as_short());
3354    case T_FLOAT:    return TypeF::make(constant.as_float());
3355    case T_DOUBLE:   return TypeD::make(constant.as_double());
3356    case T_LONG:     return TypeLong::make(constant.as_long());
3357    default:         break;
3358  }
3359  fatal("Invalid boxed value type '%s'", type2name(bt));
3360  return NULL;
3361}
3362
3363//------------------------------cast_to_ptr_type-------------------------------
3364const Type *TypeInstPtr::cast_to_ptr_type(PTR ptr) const {
3365  if( ptr == _ptr ) return this;
3366  // Reconstruct _sig info here since not a problem with later lazy
3367  // construction, _sig will show up on demand.
3368  return make(ptr, klass(), klass_is_exact(), const_oop(), _offset, _instance_id, _speculative, _inline_depth);
3369}
3370
3371
3372//-----------------------------cast_to_exactness-------------------------------
3373const Type *TypeInstPtr::cast_to_exactness(bool klass_is_exact) const {
3374  if( klass_is_exact == _klass_is_exact ) return this;
3375  if (!UseExactTypes)  return this;
3376  if (!_klass->is_loaded())  return this;
3377  ciInstanceKlass* ik = _klass->as_instance_klass();
3378  if( (ik->is_final() || _const_oop) )  return this;  // cannot clear xk
3379  if( ik->is_interface() )              return this;  // cannot set xk
3380  return make(ptr(), klass(), klass_is_exact, const_oop(), _offset, _instance_id, _speculative, _inline_depth);
3381}
3382
3383//-----------------------------cast_to_instance_id----------------------------
3384const TypeOopPtr *TypeInstPtr::cast_to_instance_id(int instance_id) const {
3385  if( instance_id == _instance_id ) return this;
3386  return make(_ptr, klass(), _klass_is_exact, const_oop(), _offset, instance_id, _speculative, _inline_depth);
3387}
3388
3389//------------------------------xmeet_unloaded---------------------------------
3390// Compute the MEET of two InstPtrs when at least one is unloaded.
3391// Assume classes are different since called after check for same name/class-loader
3392const TypeInstPtr *TypeInstPtr::xmeet_unloaded(const TypeInstPtr *tinst) const {
3393    int off = meet_offset(tinst->offset());
3394    PTR ptr = meet_ptr(tinst->ptr());
3395    int instance_id = meet_instance_id(tinst->instance_id());
3396    const TypePtr* speculative = xmeet_speculative(tinst);
3397    int depth = meet_inline_depth(tinst->inline_depth());
3398
3399    const TypeInstPtr *loaded    = is_loaded() ? this  : tinst;
3400    const TypeInstPtr *unloaded  = is_loaded() ? tinst : this;
3401    if( loaded->klass()->equals(ciEnv::current()->Object_klass()) ) {
3402      //
3403      // Meet unloaded class with java/lang/Object
3404      //
3405      // Meet
3406      //          |                     Unloaded Class
3407      //  Object  |   TOP    |   AnyNull | Constant |   NotNull |  BOTTOM   |
3408      //  ===================================================================
3409      //   TOP    | ..........................Unloaded......................|
3410      //  AnyNull |  U-AN    |................Unloaded......................|
3411      // Constant | ... O-NN .................................. |   O-BOT   |
3412      //  NotNull | ... O-NN .................................. |   O-BOT   |
3413      //  BOTTOM  | ........................Object-BOTTOM ..................|
3414      //
3415      assert(loaded->ptr() != TypePtr::Null, "insanity check");
3416      //
3417      if(      loaded->ptr() == TypePtr::TopPTR ) { return unloaded; }
3418      else if (loaded->ptr() == TypePtr::AnyNull) { return TypeInstPtr::make(ptr, unloaded->klass(), false, NULL, off, instance_id, speculative, depth); }
3419      else if (loaded->ptr() == TypePtr::BotPTR ) { return TypeInstPtr::BOTTOM; }
3420      else if (loaded->ptr() == TypePtr::Constant || loaded->ptr() == TypePtr::NotNull) {
3421        if (unloaded->ptr() == TypePtr::BotPTR  ) { return TypeInstPtr::BOTTOM;  }
3422        else                                      { return TypeInstPtr::NOTNULL; }
3423      }
3424      else if( unloaded->ptr() == TypePtr::TopPTR )  { return unloaded; }
3425
3426      return unloaded->cast_to_ptr_type(TypePtr::AnyNull)->is_instptr();
3427    }
3428
3429    // Both are unloaded, not the same class, not Object
3430    // Or meet unloaded with a different loaded class, not java/lang/Object
3431    if( ptr != TypePtr::BotPTR ) {
3432      return TypeInstPtr::NOTNULL;
3433    }
3434    return TypeInstPtr::BOTTOM;
3435}
3436
3437
3438//------------------------------meet-------------------------------------------
3439// Compute the MEET of two types.  It returns a new Type object.
3440const Type *TypeInstPtr::xmeet_helper(const Type *t) const {
3441  // Perform a fast test for common case; meeting the same types together.
3442  if( this == t ) return this;  // Meeting same type-rep?
3443
3444  // Current "this->_base" is Pointer
3445  switch (t->base()) {          // switch on original type
3446
3447  case Int:                     // Mixing ints & oops happens when javac
3448  case Long:                    // reuses local variables
3449  case FloatTop:
3450  case FloatCon:
3451  case FloatBot:
3452  case DoubleTop:
3453  case DoubleCon:
3454  case DoubleBot:
3455  case NarrowOop:
3456  case NarrowKlass:
3457  case Bottom:                  // Ye Olde Default
3458    return Type::BOTTOM;
3459  case Top:
3460    return this;
3461
3462  default:                      // All else is a mistake
3463    typerr(t);
3464
3465  case MetadataPtr:
3466  case KlassPtr:
3467  case RawPtr: return TypePtr::BOTTOM;
3468
3469  case AryPtr: {                // All arrays inherit from Object class
3470    const TypeAryPtr *tp = t->is_aryptr();
3471    int offset = meet_offset(tp->offset());
3472    PTR ptr = meet_ptr(tp->ptr());
3473    int instance_id = meet_instance_id(tp->instance_id());
3474    const TypePtr* speculative = xmeet_speculative(tp);
3475    int depth = meet_inline_depth(tp->inline_depth());
3476    switch (ptr) {
3477    case TopPTR:
3478    case AnyNull:                // Fall 'down' to dual of object klass
3479      // For instances when a subclass meets a superclass we fall
3480      // below the centerline when the superclass is exact. We need to
3481      // do the same here.
3482      if (klass()->equals(ciEnv::current()->Object_klass()) && !klass_is_exact()) {
3483        return TypeAryPtr::make(ptr, tp->ary(), tp->klass(), tp->klass_is_exact(), offset, instance_id, speculative, depth);
3484      } else {
3485        // cannot subclass, so the meet has to fall badly below the centerline
3486        ptr = NotNull;
3487        instance_id = InstanceBot;
3488        return TypeInstPtr::make( ptr, ciEnv::current()->Object_klass(), false, NULL, offset, instance_id, speculative, depth);
3489      }
3490    case Constant:
3491    case NotNull:
3492    case BotPTR:                // Fall down to object klass
3493      // LCA is object_klass, but if we subclass from the top we can do better
3494      if( above_centerline(_ptr) ) { // if( _ptr == TopPTR || _ptr == AnyNull )
3495        // If 'this' (InstPtr) is above the centerline and it is Object class
3496        // then we can subclass in the Java class hierarchy.
3497        // For instances when a subclass meets a superclass we fall
3498        // below the centerline when the superclass is exact. We need
3499        // to do the same here.
3500        if (klass()->equals(ciEnv::current()->Object_klass()) && !klass_is_exact()) {
3501          // that is, tp's array type is a subtype of my klass
3502          return TypeAryPtr::make(ptr, (ptr == Constant ? tp->const_oop() : NULL),
3503                                  tp->ary(), tp->klass(), tp->klass_is_exact(), offset, instance_id, speculative, depth);
3504        }
3505      }
3506      // The other case cannot happen, since I cannot be a subtype of an array.
3507      // The meet falls down to Object class below centerline.
3508      if( ptr == Constant )
3509         ptr = NotNull;
3510      instance_id = InstanceBot;
3511      return make(ptr, ciEnv::current()->Object_klass(), false, NULL, offset, instance_id, speculative, depth);
3512    default: typerr(t);
3513    }
3514  }
3515
3516  case OopPtr: {                // Meeting to OopPtrs
3517    // Found a OopPtr type vs self-InstPtr type
3518    const TypeOopPtr *tp = t->is_oopptr();
3519    int offset = meet_offset(tp->offset());
3520    PTR ptr = meet_ptr(tp->ptr());
3521    switch (tp->ptr()) {
3522    case TopPTR:
3523    case AnyNull: {
3524      int instance_id = meet_instance_id(InstanceTop);
3525      const TypePtr* speculative = xmeet_speculative(tp);
3526      int depth = meet_inline_depth(tp->inline_depth());
3527      return make(ptr, klass(), klass_is_exact(),
3528                  (ptr == Constant ? const_oop() : NULL), offset, instance_id, speculative, depth);
3529    }
3530    case NotNull:
3531    case BotPTR: {
3532      int instance_id = meet_instance_id(tp->instance_id());
3533      const TypePtr* speculative = xmeet_speculative(tp);
3534      int depth = meet_inline_depth(tp->inline_depth());
3535      return TypeOopPtr::make(ptr, offset, instance_id, speculative, depth);
3536    }
3537    default: typerr(t);
3538    }
3539  }
3540
3541  case AnyPtr: {                // Meeting to AnyPtrs
3542    // Found an AnyPtr type vs self-InstPtr type
3543    const TypePtr *tp = t->is_ptr();
3544    int offset = meet_offset(tp->offset());
3545    PTR ptr = meet_ptr(tp->ptr());
3546    int instance_id = meet_instance_id(InstanceTop);
3547    const TypePtr* speculative = xmeet_speculative(tp);
3548    int depth = meet_inline_depth(tp->inline_depth());
3549    switch (tp->ptr()) {
3550    case Null:
3551      if( ptr == Null ) return TypePtr::make(AnyPtr, ptr, offset, speculative, depth);
3552      // else fall through to AnyNull
3553    case TopPTR:
3554    case AnyNull: {
3555      return make(ptr, klass(), klass_is_exact(),
3556                  (ptr == Constant ? const_oop() : NULL), offset, instance_id, speculative, depth);
3557    }
3558    case NotNull:
3559    case BotPTR:
3560      return TypePtr::make(AnyPtr, ptr, offset, speculative,depth);
3561    default: typerr(t);
3562    }
3563  }
3564
3565  /*
3566                 A-top         }
3567               /   |   \       }  Tops
3568           B-top A-any C-top   }
3569              | /  |  \ |      }  Any-nulls
3570           B-any   |   C-any   }
3571              |    |    |
3572           B-con A-con C-con   } constants; not comparable across classes
3573              |    |    |
3574           B-not   |   C-not   }
3575              | \  |  / |      }  not-nulls
3576           B-bot A-not C-bot   }
3577               \   |   /       }  Bottoms
3578                 A-bot         }
3579  */
3580
3581  case InstPtr: {                // Meeting 2 Oops?
3582    // Found an InstPtr sub-type vs self-InstPtr type
3583    const TypeInstPtr *tinst = t->is_instptr();
3584    int off = meet_offset( tinst->offset() );
3585    PTR ptr = meet_ptr( tinst->ptr() );
3586    int instance_id = meet_instance_id(tinst->instance_id());
3587    const TypePtr* speculative = xmeet_speculative(tinst);
3588    int depth = meet_inline_depth(tinst->inline_depth());
3589
3590    // Check for easy case; klasses are equal (and perhaps not loaded!)
3591    // If we have constants, then we created oops so classes are loaded
3592    // and we can handle the constants further down.  This case handles
3593    // both-not-loaded or both-loaded classes
3594    if (ptr != Constant && klass()->equals(tinst->klass()) && klass_is_exact() == tinst->klass_is_exact()) {
3595      return make(ptr, klass(), klass_is_exact(), NULL, off, instance_id, speculative, depth);
3596    }
3597
3598    // Classes require inspection in the Java klass hierarchy.  Must be loaded.
3599    ciKlass* tinst_klass = tinst->klass();
3600    ciKlass* this_klass  = this->klass();
3601    bool tinst_xk = tinst->klass_is_exact();
3602    bool this_xk  = this->klass_is_exact();
3603    if (!tinst_klass->is_loaded() || !this_klass->is_loaded() ) {
3604      // One of these classes has not been loaded
3605      const TypeInstPtr *unloaded_meet = xmeet_unloaded(tinst);
3606#ifndef PRODUCT
3607      if( PrintOpto && Verbose ) {
3608        tty->print("meet of unloaded classes resulted in: "); unloaded_meet->dump(); tty->cr();
3609        tty->print("  this == "); this->dump(); tty->cr();
3610        tty->print(" tinst == "); tinst->dump(); tty->cr();
3611      }
3612#endif
3613      return unloaded_meet;
3614    }
3615
3616    // Handle mixing oops and interfaces first.
3617    if( this_klass->is_interface() && !(tinst_klass->is_interface() ||
3618                                        tinst_klass == ciEnv::current()->Object_klass())) {
3619      ciKlass *tmp = tinst_klass; // Swap interface around
3620      tinst_klass = this_klass;
3621      this_klass = tmp;
3622      bool tmp2 = tinst_xk;
3623      tinst_xk = this_xk;
3624      this_xk = tmp2;
3625    }
3626    if (tinst_klass->is_interface() &&
3627        !(this_klass->is_interface() ||
3628          // Treat java/lang/Object as an honorary interface,
3629          // because we need a bottom for the interface hierarchy.
3630          this_klass == ciEnv::current()->Object_klass())) {
3631      // Oop meets interface!
3632
3633      // See if the oop subtypes (implements) interface.
3634      ciKlass *k;
3635      bool xk;
3636      if( this_klass->is_subtype_of( tinst_klass ) ) {
3637        // Oop indeed subtypes.  Now keep oop or interface depending
3638        // on whether we are both above the centerline or either is
3639        // below the centerline.  If we are on the centerline
3640        // (e.g., Constant vs. AnyNull interface), use the constant.
3641        k  = below_centerline(ptr) ? tinst_klass : this_klass;
3642        // If we are keeping this_klass, keep its exactness too.
3643        xk = below_centerline(ptr) ? tinst_xk    : this_xk;
3644      } else {                  // Does not implement, fall to Object
3645        // Oop does not implement interface, so mixing falls to Object
3646        // just like the verifier does (if both are above the
3647        // centerline fall to interface)
3648        k = above_centerline(ptr) ? tinst_klass : ciEnv::current()->Object_klass();
3649        xk = above_centerline(ptr) ? tinst_xk : false;
3650        // Watch out for Constant vs. AnyNull interface.
3651        if (ptr == Constant)  ptr = NotNull;   // forget it was a constant
3652        instance_id = InstanceBot;
3653      }
3654      ciObject* o = NULL;  // the Constant value, if any
3655      if (ptr == Constant) {
3656        // Find out which constant.
3657        o = (this_klass == klass()) ? const_oop() : tinst->const_oop();
3658      }
3659      return make(ptr, k, xk, o, off, instance_id, speculative, depth);
3660    }
3661
3662    // Either oop vs oop or interface vs interface or interface vs Object
3663
3664    // !!! Here's how the symmetry requirement breaks down into invariants:
3665    // If we split one up & one down AND they subtype, take the down man.
3666    // If we split one up & one down AND they do NOT subtype, "fall hard".
3667    // If both are up and they subtype, take the subtype class.
3668    // If both are up and they do NOT subtype, "fall hard".
3669    // If both are down and they subtype, take the supertype class.
3670    // If both are down and they do NOT subtype, "fall hard".
3671    // Constants treated as down.
3672
3673    // Now, reorder the above list; observe that both-down+subtype is also
3674    // "fall hard"; "fall hard" becomes the default case:
3675    // If we split one up & one down AND they subtype, take the down man.
3676    // If both are up and they subtype, take the subtype class.
3677
3678    // If both are down and they subtype, "fall hard".
3679    // If both are down and they do NOT subtype, "fall hard".
3680    // If both are up and they do NOT subtype, "fall hard".
3681    // If we split one up & one down AND they do NOT subtype, "fall hard".
3682
3683    // If a proper subtype is exact, and we return it, we return it exactly.
3684    // If a proper supertype is exact, there can be no subtyping relationship!
3685    // If both types are equal to the subtype, exactness is and-ed below the
3686    // centerline and or-ed above it.  (N.B. Constants are always exact.)
3687
3688    // Check for subtyping:
3689    ciKlass *subtype = NULL;
3690    bool subtype_exact = false;
3691    if( tinst_klass->equals(this_klass) ) {
3692      subtype = this_klass;
3693      subtype_exact = below_centerline(ptr) ? (this_xk & tinst_xk) : (this_xk | tinst_xk);
3694    } else if( !tinst_xk && this_klass->is_subtype_of( tinst_klass ) ) {
3695      subtype = this_klass;     // Pick subtyping class
3696      subtype_exact = this_xk;
3697    } else if( !this_xk && tinst_klass->is_subtype_of( this_klass ) ) {
3698      subtype = tinst_klass;    // Pick subtyping class
3699      subtype_exact = tinst_xk;
3700    }
3701
3702    if( subtype ) {
3703      if( above_centerline(ptr) ) { // both are up?
3704        this_klass = tinst_klass = subtype;
3705        this_xk = tinst_xk = subtype_exact;
3706      } else if( above_centerline(this ->_ptr) && !above_centerline(tinst->_ptr) ) {
3707        this_klass = tinst_klass; // tinst is down; keep down man
3708        this_xk = tinst_xk;
3709      } else if( above_centerline(tinst->_ptr) && !above_centerline(this ->_ptr) ) {
3710        tinst_klass = this_klass; // this is down; keep down man
3711        tinst_xk = this_xk;
3712      } else {
3713        this_xk = subtype_exact;  // either they are equal, or we'll do an LCA
3714      }
3715    }
3716
3717    // Check for classes now being equal
3718    if (tinst_klass->equals(this_klass)) {
3719      // If the klasses are equal, the constants may still differ.  Fall to
3720      // NotNull if they do (neither constant is NULL; that is a special case
3721      // handled elsewhere).
3722      ciObject* o = NULL;             // Assume not constant when done
3723      ciObject* this_oop  = const_oop();
3724      ciObject* tinst_oop = tinst->const_oop();
3725      if( ptr == Constant ) {
3726        if (this_oop != NULL && tinst_oop != NULL &&
3727            this_oop->equals(tinst_oop) )
3728          o = this_oop;
3729        else if (above_centerline(this ->_ptr))
3730          o = tinst_oop;
3731        else if (above_centerline(tinst ->_ptr))
3732          o = this_oop;
3733        else
3734          ptr = NotNull;
3735      }
3736      return make(ptr, this_klass, this_xk, o, off, instance_id, speculative, depth);
3737    } // Else classes are not equal
3738
3739    // Since klasses are different, we require a LCA in the Java
3740    // class hierarchy - which means we have to fall to at least NotNull.
3741    if( ptr == TopPTR || ptr == AnyNull || ptr == Constant )
3742      ptr = NotNull;
3743
3744    instance_id = InstanceBot;
3745
3746    // Now we find the LCA of Java classes
3747    ciKlass* k = this_klass->least_common_ancestor(tinst_klass);
3748    return make(ptr, k, false, NULL, off, instance_id, speculative, depth);
3749  } // End of case InstPtr
3750
3751  } // End of switch
3752  return this;                  // Return the double constant
3753}
3754
3755
3756//------------------------java_mirror_type--------------------------------------
3757ciType* TypeInstPtr::java_mirror_type() const {
3758  // must be a singleton type
3759  if( const_oop() == NULL )  return NULL;
3760
3761  // must be of type java.lang.Class
3762  if( klass() != ciEnv::current()->Class_klass() )  return NULL;
3763
3764  return const_oop()->as_instance()->java_mirror_type();
3765}
3766
3767
3768//------------------------------xdual------------------------------------------
3769// Dual: do NOT dual on klasses.  This means I do NOT understand the Java
3770// inheritance mechanism.
3771const Type *TypeInstPtr::xdual() const {
3772  return new TypeInstPtr(dual_ptr(), klass(), klass_is_exact(), const_oop(), dual_offset(), dual_instance_id(), dual_speculative(), dual_inline_depth());
3773}
3774
3775//------------------------------eq---------------------------------------------
3776// Structural equality check for Type representations
3777bool TypeInstPtr::eq( const Type *t ) const {
3778  const TypeInstPtr *p = t->is_instptr();
3779  return
3780    klass()->equals(p->klass()) &&
3781    TypeOopPtr::eq(p);          // Check sub-type stuff
3782}
3783
3784//------------------------------hash-------------------------------------------
3785// Type-specific hashing function.
3786int TypeInstPtr::hash(void) const {
3787  int hash = klass()->hash() + TypeOopPtr::hash();
3788  return hash;
3789}
3790
3791//------------------------------dump2------------------------------------------
3792// Dump oop Type
3793#ifndef PRODUCT
3794void TypeInstPtr::dump2( Dict &d, uint depth, outputStream *st ) const {
3795  // Print the name of the klass.
3796  klass()->print_name_on(st);
3797
3798  switch( _ptr ) {
3799  case Constant:
3800    // TO DO: Make CI print the hex address of the underlying oop.
3801    if (WizardMode || Verbose) {
3802      const_oop()->print_oop(st);
3803    }
3804  case BotPTR:
3805    if (!WizardMode && !Verbose) {
3806      if( _klass_is_exact ) st->print(":exact");
3807      break;
3808    }
3809  case TopPTR:
3810  case AnyNull:
3811  case NotNull:
3812    st->print(":%s", ptr_msg[_ptr]);
3813    if( _klass_is_exact ) st->print(":exact");
3814    break;
3815  }
3816
3817  if( _offset ) {               // Dump offset, if any
3818    if( _offset == OffsetBot )      st->print("+any");
3819    else if( _offset == OffsetTop ) st->print("+unknown");
3820    else st->print("+%d", _offset);
3821  }
3822
3823  st->print(" *");
3824  if (_instance_id == InstanceTop)
3825    st->print(",iid=top");
3826  else if (_instance_id != InstanceBot)
3827    st->print(",iid=%d",_instance_id);
3828
3829  dump_inline_depth(st);
3830  dump_speculative(st);
3831}
3832#endif
3833
3834//------------------------------add_offset-------------------------------------
3835const TypePtr *TypeInstPtr::add_offset(intptr_t offset) const {
3836  return make(_ptr, klass(), klass_is_exact(), const_oop(), xadd_offset(offset),
3837              _instance_id, add_offset_speculative(offset), _inline_depth);
3838}
3839
3840const Type *TypeInstPtr::remove_speculative() const {
3841  if (_speculative == NULL) {
3842    return this;
3843  }
3844  assert(_inline_depth == InlineDepthTop || _inline_depth == InlineDepthBottom, "non speculative type shouldn't have inline depth");
3845  return make(_ptr, klass(), klass_is_exact(), const_oop(), _offset,
3846              _instance_id, NULL, _inline_depth);
3847}
3848
3849const TypePtr *TypeInstPtr::with_inline_depth(int depth) const {
3850  if (!UseInlineDepthForSpeculativeTypes) {
3851    return this;
3852  }
3853  return make(_ptr, klass(), klass_is_exact(), const_oop(), _offset, _instance_id, _speculative, depth);
3854}
3855
3856//=============================================================================
3857// Convenience common pre-built types.
3858const TypeAryPtr *TypeAryPtr::RANGE;
3859const TypeAryPtr *TypeAryPtr::OOPS;
3860const TypeAryPtr *TypeAryPtr::NARROWOOPS;
3861const TypeAryPtr *TypeAryPtr::BYTES;
3862const TypeAryPtr *TypeAryPtr::SHORTS;
3863const TypeAryPtr *TypeAryPtr::CHARS;
3864const TypeAryPtr *TypeAryPtr::INTS;
3865const TypeAryPtr *TypeAryPtr::LONGS;
3866const TypeAryPtr *TypeAryPtr::FLOATS;
3867const TypeAryPtr *TypeAryPtr::DOUBLES;
3868
3869//------------------------------make-------------------------------------------
3870const TypeAryPtr *TypeAryPtr::make(PTR ptr, const TypeAry *ary, ciKlass* k, bool xk, int offset,
3871                                   int instance_id, const TypePtr* speculative, int inline_depth) {
3872  assert(!(k == NULL && ary->_elem->isa_int()),
3873         "integral arrays must be pre-equipped with a class");
3874  if (!xk)  xk = ary->ary_must_be_exact();
3875  assert(instance_id <= 0 || xk || !UseExactTypes, "instances are always exactly typed");
3876  if (!UseExactTypes)  xk = (ptr == Constant);
3877  return (TypeAryPtr*)(new TypeAryPtr(ptr, NULL, ary, k, xk, offset, instance_id, false, speculative, inline_depth))->hashcons();
3878}
3879
3880//------------------------------make-------------------------------------------
3881const TypeAryPtr *TypeAryPtr::make(PTR ptr, ciObject* o, const TypeAry *ary, ciKlass* k, bool xk, int offset,
3882                                   int instance_id, const TypePtr* speculative, int inline_depth,
3883                                   bool is_autobox_cache) {
3884  assert(!(k == NULL && ary->_elem->isa_int()),
3885         "integral arrays must be pre-equipped with a class");
3886  assert( (ptr==Constant && o) || (ptr!=Constant && !o), "" );
3887  if (!xk)  xk = (o != NULL) || ary->ary_must_be_exact();
3888  assert(instance_id <= 0 || xk || !UseExactTypes, "instances are always exactly typed");
3889  if (!UseExactTypes)  xk = (ptr == Constant);
3890  return (TypeAryPtr*)(new TypeAryPtr(ptr, o, ary, k, xk, offset, instance_id, is_autobox_cache, speculative, inline_depth))->hashcons();
3891}
3892
3893//------------------------------cast_to_ptr_type-------------------------------
3894const Type *TypeAryPtr::cast_to_ptr_type(PTR ptr) const {
3895  if( ptr == _ptr ) return this;
3896  return make(ptr, const_oop(), _ary, klass(), klass_is_exact(), _offset, _instance_id, _speculative, _inline_depth);
3897}
3898
3899
3900//-----------------------------cast_to_exactness-------------------------------
3901const Type *TypeAryPtr::cast_to_exactness(bool klass_is_exact) const {
3902  if( klass_is_exact == _klass_is_exact ) return this;
3903  if (!UseExactTypes)  return this;
3904  if (_ary->ary_must_be_exact())  return this;  // cannot clear xk
3905  return make(ptr(), const_oop(), _ary, klass(), klass_is_exact, _offset, _instance_id, _speculative, _inline_depth);
3906}
3907
3908//-----------------------------cast_to_instance_id----------------------------
3909const TypeOopPtr *TypeAryPtr::cast_to_instance_id(int instance_id) const {
3910  if( instance_id == _instance_id ) return this;
3911  return make(_ptr, const_oop(), _ary, klass(), _klass_is_exact, _offset, instance_id, _speculative, _inline_depth);
3912}
3913
3914//-----------------------------narrow_size_type-------------------------------
3915// Local cache for arrayOopDesc::max_array_length(etype),
3916// which is kind of slow (and cached elsewhere by other users).
3917static jint max_array_length_cache[T_CONFLICT+1];
3918static jint max_array_length(BasicType etype) {
3919  jint& cache = max_array_length_cache[etype];
3920  jint res = cache;
3921  if (res == 0) {
3922    switch (etype) {
3923    case T_NARROWOOP:
3924      etype = T_OBJECT;
3925      break;
3926    case T_NARROWKLASS:
3927    case T_CONFLICT:
3928    case T_ILLEGAL:
3929    case T_VOID:
3930      etype = T_BYTE;           // will produce conservatively high value
3931    }
3932    cache = res = arrayOopDesc::max_array_length(etype);
3933  }
3934  return res;
3935}
3936
3937// Narrow the given size type to the index range for the given array base type.
3938// Return NULL if the resulting int type becomes empty.
3939const TypeInt* TypeAryPtr::narrow_size_type(const TypeInt* size) const {
3940  jint hi = size->_hi;
3941  jint lo = size->_lo;
3942  jint min_lo = 0;
3943  jint max_hi = max_array_length(elem()->basic_type());
3944  //if (index_not_size)  --max_hi;     // type of a valid array index, FTR
3945  bool chg = false;
3946  if (lo < min_lo) {
3947    lo = min_lo;
3948    if (size->is_con()) {
3949      hi = lo;
3950    }
3951    chg = true;
3952  }
3953  if (hi > max_hi) {
3954    hi = max_hi;
3955    if (size->is_con()) {
3956      lo = hi;
3957    }
3958    chg = true;
3959  }
3960  // Negative length arrays will produce weird intermediate dead fast-path code
3961  if (lo > hi)
3962    return TypeInt::ZERO;
3963  if (!chg)
3964    return size;
3965  return TypeInt::make(lo, hi, Type::WidenMin);
3966}
3967
3968//-------------------------------cast_to_size----------------------------------
3969const TypeAryPtr* TypeAryPtr::cast_to_size(const TypeInt* new_size) const {
3970  assert(new_size != NULL, "");
3971  new_size = narrow_size_type(new_size);
3972  if (new_size == size())  return this;
3973  const TypeAry* new_ary = TypeAry::make(elem(), new_size, is_stable());
3974  return make(ptr(), const_oop(), new_ary, klass(), klass_is_exact(), _offset, _instance_id, _speculative, _inline_depth);
3975}
3976
3977//------------------------------cast_to_stable---------------------------------
3978const TypeAryPtr* TypeAryPtr::cast_to_stable(bool stable, int stable_dimension) const {
3979  if (stable_dimension <= 0 || (stable_dimension == 1 && stable == this->is_stable()))
3980    return this;
3981
3982  const Type* elem = this->elem();
3983  const TypePtr* elem_ptr = elem->make_ptr();
3984
3985  if (stable_dimension > 1 && elem_ptr != NULL && elem_ptr->isa_aryptr()) {
3986    // If this is widened from a narrow oop, TypeAry::make will re-narrow it.
3987    elem = elem_ptr = elem_ptr->is_aryptr()->cast_to_stable(stable, stable_dimension - 1);
3988  }
3989
3990  const TypeAry* new_ary = TypeAry::make(elem, size(), stable);
3991
3992  return make(ptr(), const_oop(), new_ary, klass(), klass_is_exact(), _offset, _instance_id, _speculative, _inline_depth);
3993}
3994
3995//-----------------------------stable_dimension--------------------------------
3996int TypeAryPtr::stable_dimension() const {
3997  if (!is_stable())  return 0;
3998  int dim = 1;
3999  const TypePtr* elem_ptr = elem()->make_ptr();
4000  if (elem_ptr != NULL && elem_ptr->isa_aryptr())
4001    dim += elem_ptr->is_aryptr()->stable_dimension();
4002  return dim;
4003}
4004
4005//----------------------cast_to_autobox_cache-----------------------------------
4006const TypeAryPtr* TypeAryPtr::cast_to_autobox_cache(bool cache) const {
4007  if (is_autobox_cache() == cache)  return this;
4008  const TypeOopPtr* etype = elem()->make_oopptr();
4009  if (etype == NULL)  return this;
4010  // The pointers in the autobox arrays are always non-null.
4011  TypePtr::PTR ptr_type = cache ? TypePtr::NotNull : TypePtr::AnyNull;
4012  etype = etype->cast_to_ptr_type(TypePtr::NotNull)->is_oopptr();
4013  const TypeAry* new_ary = TypeAry::make(etype, size(), is_stable());
4014  return make(ptr(), const_oop(), new_ary, klass(), klass_is_exact(), _offset, _instance_id, _speculative, _inline_depth, cache);
4015}
4016
4017//------------------------------eq---------------------------------------------
4018// Structural equality check for Type representations
4019bool TypeAryPtr::eq( const Type *t ) const {
4020  const TypeAryPtr *p = t->is_aryptr();
4021  return
4022    _ary == p->_ary &&  // Check array
4023    TypeOopPtr::eq(p);  // Check sub-parts
4024}
4025
4026//------------------------------hash-------------------------------------------
4027// Type-specific hashing function.
4028int TypeAryPtr::hash(void) const {
4029  return (intptr_t)_ary + TypeOopPtr::hash();
4030}
4031
4032//------------------------------meet-------------------------------------------
4033// Compute the MEET of two types.  It returns a new Type object.
4034const Type *TypeAryPtr::xmeet_helper(const Type *t) const {
4035  // Perform a fast test for common case; meeting the same types together.
4036  if( this == t ) return this;  // Meeting same type-rep?
4037  // Current "this->_base" is Pointer
4038  switch (t->base()) {          // switch on original type
4039
4040  // Mixing ints & oops happens when javac reuses local variables
4041  case Int:
4042  case Long:
4043  case FloatTop:
4044  case FloatCon:
4045  case FloatBot:
4046  case DoubleTop:
4047  case DoubleCon:
4048  case DoubleBot:
4049  case NarrowOop:
4050  case NarrowKlass:
4051  case Bottom:                  // Ye Olde Default
4052    return Type::BOTTOM;
4053  case Top:
4054    return this;
4055
4056  default:                      // All else is a mistake
4057    typerr(t);
4058
4059  case OopPtr: {                // Meeting to OopPtrs
4060    // Found a OopPtr type vs self-AryPtr type
4061    const TypeOopPtr *tp = t->is_oopptr();
4062    int offset = meet_offset(tp->offset());
4063    PTR ptr = meet_ptr(tp->ptr());
4064    int depth = meet_inline_depth(tp->inline_depth());
4065    const TypePtr* speculative = xmeet_speculative(tp);
4066    switch (tp->ptr()) {
4067    case TopPTR:
4068    case AnyNull: {
4069      int instance_id = meet_instance_id(InstanceTop);
4070      return make(ptr, (ptr == Constant ? const_oop() : NULL),
4071                  _ary, _klass, _klass_is_exact, offset, instance_id, speculative, depth);
4072    }
4073    case BotPTR:
4074    case NotNull: {
4075      int instance_id = meet_instance_id(tp->instance_id());
4076      return TypeOopPtr::make(ptr, offset, instance_id, speculative, depth);
4077    }
4078    default: ShouldNotReachHere();
4079    }
4080  }
4081
4082  case AnyPtr: {                // Meeting two AnyPtrs
4083    // Found an AnyPtr type vs self-AryPtr type
4084    const TypePtr *tp = t->is_ptr();
4085    int offset = meet_offset(tp->offset());
4086    PTR ptr = meet_ptr(tp->ptr());
4087    const TypePtr* speculative = xmeet_speculative(tp);
4088    int depth = meet_inline_depth(tp->inline_depth());
4089    switch (tp->ptr()) {
4090    case TopPTR:
4091      return this;
4092    case BotPTR:
4093    case NotNull:
4094      return TypePtr::make(AnyPtr, ptr, offset, speculative, depth);
4095    case Null:
4096      if( ptr == Null ) return TypePtr::make(AnyPtr, ptr, offset, speculative, depth);
4097      // else fall through to AnyNull
4098    case AnyNull: {
4099      int instance_id = meet_instance_id(InstanceTop);
4100      return make(ptr, (ptr == Constant ? const_oop() : NULL),
4101                  _ary, _klass, _klass_is_exact, offset, instance_id, speculative, depth);
4102    }
4103    default: ShouldNotReachHere();
4104    }
4105  }
4106
4107  case MetadataPtr:
4108  case KlassPtr:
4109  case RawPtr: return TypePtr::BOTTOM;
4110
4111  case AryPtr: {                // Meeting 2 references?
4112    const TypeAryPtr *tap = t->is_aryptr();
4113    int off = meet_offset(tap->offset());
4114    const TypeAry *tary = _ary->meet_speculative(tap->_ary)->is_ary();
4115    PTR ptr = meet_ptr(tap->ptr());
4116    int instance_id = meet_instance_id(tap->instance_id());
4117    const TypePtr* speculative = xmeet_speculative(tap);
4118    int depth = meet_inline_depth(tap->inline_depth());
4119    ciKlass* lazy_klass = NULL;
4120    if (tary->_elem->isa_int()) {
4121      // Integral array element types have irrelevant lattice relations.
4122      // It is the klass that determines array layout, not the element type.
4123      if (_klass == NULL)
4124        lazy_klass = tap->_klass;
4125      else if (tap->_klass == NULL || tap->_klass == _klass) {
4126        lazy_klass = _klass;
4127      } else {
4128        // Something like byte[int+] meets char[int+].
4129        // This must fall to bottom, not (int[-128..65535])[int+].
4130        instance_id = InstanceBot;
4131        tary = TypeAry::make(Type::BOTTOM, tary->_size, tary->_stable);
4132      }
4133    } else // Non integral arrays.
4134      // Must fall to bottom if exact klasses in upper lattice
4135      // are not equal or super klass is exact.
4136      if ((above_centerline(ptr) || ptr == Constant) && klass() != tap->klass() &&
4137          // meet with top[] and bottom[] are processed further down:
4138          tap->_klass != NULL  && this->_klass != NULL   &&
4139          // both are exact and not equal:
4140          ((tap->_klass_is_exact && this->_klass_is_exact) ||
4141           // 'tap'  is exact and super or unrelated:
4142           (tap->_klass_is_exact && !tap->klass()->is_subtype_of(klass())) ||
4143           // 'this' is exact and super or unrelated:
4144           (this->_klass_is_exact && !klass()->is_subtype_of(tap->klass())))) {
4145      if (above_centerline(ptr)) {
4146        tary = TypeAry::make(Type::BOTTOM, tary->_size, tary->_stable);
4147      }
4148      return make(NotNull, NULL, tary, lazy_klass, false, off, InstanceBot, speculative, depth);
4149    }
4150
4151    bool xk = false;
4152    switch (tap->ptr()) {
4153    case AnyNull:
4154    case TopPTR:
4155      // Compute new klass on demand, do not use tap->_klass
4156      if (below_centerline(this->_ptr)) {
4157        xk = this->_klass_is_exact;
4158      } else {
4159        xk = (tap->_klass_is_exact | this->_klass_is_exact);
4160      }
4161      return make(ptr, const_oop(), tary, lazy_klass, xk, off, instance_id, speculative, depth);
4162    case Constant: {
4163      ciObject* o = const_oop();
4164      if( _ptr == Constant ) {
4165        if( tap->const_oop() != NULL && !o->equals(tap->const_oop()) ) {
4166          xk = (klass() == tap->klass());
4167          ptr = NotNull;
4168          o = NULL;
4169          instance_id = InstanceBot;
4170        } else {
4171          xk = true;
4172        }
4173      } else if(above_centerline(_ptr)) {
4174        o = tap->const_oop();
4175        xk = true;
4176      } else {
4177        // Only precise for identical arrays
4178        xk = this->_klass_is_exact && (klass() == tap->klass());
4179      }
4180      return TypeAryPtr::make(ptr, o, tary, lazy_klass, xk, off, instance_id, speculative, depth);
4181    }
4182    case NotNull:
4183    case BotPTR:
4184      // Compute new klass on demand, do not use tap->_klass
4185      if (above_centerline(this->_ptr))
4186            xk = tap->_klass_is_exact;
4187      else  xk = (tap->_klass_is_exact & this->_klass_is_exact) &&
4188              (klass() == tap->klass()); // Only precise for identical arrays
4189      return TypeAryPtr::make(ptr, NULL, tary, lazy_klass, xk, off, instance_id, speculative, depth);
4190    default: ShouldNotReachHere();
4191    }
4192  }
4193
4194  // All arrays inherit from Object class
4195  case InstPtr: {
4196    const TypeInstPtr *tp = t->is_instptr();
4197    int offset = meet_offset(tp->offset());
4198    PTR ptr = meet_ptr(tp->ptr());
4199    int instance_id = meet_instance_id(tp->instance_id());
4200    const TypePtr* speculative = xmeet_speculative(tp);
4201    int depth = meet_inline_depth(tp->inline_depth());
4202    switch (ptr) {
4203    case TopPTR:
4204    case AnyNull:                // Fall 'down' to dual of object klass
4205      // For instances when a subclass meets a superclass we fall
4206      // below the centerline when the superclass is exact. We need to
4207      // do the same here.
4208      if (tp->klass()->equals(ciEnv::current()->Object_klass()) && !tp->klass_is_exact()) {
4209        return TypeAryPtr::make(ptr, _ary, _klass, _klass_is_exact, offset, instance_id, speculative, depth);
4210      } else {
4211        // cannot subclass, so the meet has to fall badly below the centerline
4212        ptr = NotNull;
4213        instance_id = InstanceBot;
4214        return TypeInstPtr::make(ptr, ciEnv::current()->Object_klass(), false, NULL,offset, instance_id, speculative, depth);
4215      }
4216    case Constant:
4217    case NotNull:
4218    case BotPTR:                // Fall down to object klass
4219      // LCA is object_klass, but if we subclass from the top we can do better
4220      if (above_centerline(tp->ptr())) {
4221        // If 'tp'  is above the centerline and it is Object class
4222        // then we can subclass in the Java class hierarchy.
4223        // For instances when a subclass meets a superclass we fall
4224        // below the centerline when the superclass is exact. We need
4225        // to do the same here.
4226        if (tp->klass()->equals(ciEnv::current()->Object_klass()) && !tp->klass_is_exact()) {
4227          // that is, my array type is a subtype of 'tp' klass
4228          return make(ptr, (ptr == Constant ? const_oop() : NULL),
4229                      _ary, _klass, _klass_is_exact, offset, instance_id, speculative, depth);
4230        }
4231      }
4232      // The other case cannot happen, since t cannot be a subtype of an array.
4233      // The meet falls down to Object class below centerline.
4234      if( ptr == Constant )
4235         ptr = NotNull;
4236      instance_id = InstanceBot;
4237      return TypeInstPtr::make(ptr, ciEnv::current()->Object_klass(), false, NULL,offset, instance_id, speculative, depth);
4238    default: typerr(t);
4239    }
4240  }
4241  }
4242  return this;                  // Lint noise
4243}
4244
4245//------------------------------xdual------------------------------------------
4246// Dual: compute field-by-field dual
4247const Type *TypeAryPtr::xdual() const {
4248  return new TypeAryPtr(dual_ptr(), _const_oop, _ary->dual()->is_ary(),_klass, _klass_is_exact, dual_offset(), dual_instance_id(), is_autobox_cache(), dual_speculative(), dual_inline_depth());
4249}
4250
4251//----------------------interface_vs_oop---------------------------------------
4252#ifdef ASSERT
4253bool TypeAryPtr::interface_vs_oop(const Type *t) const {
4254  const TypeAryPtr* t_aryptr = t->isa_aryptr();
4255  if (t_aryptr) {
4256    return _ary->interface_vs_oop(t_aryptr->_ary);
4257  }
4258  return false;
4259}
4260#endif
4261
4262//------------------------------dump2------------------------------------------
4263#ifndef PRODUCT
4264void TypeAryPtr::dump2( Dict &d, uint depth, outputStream *st ) const {
4265  _ary->dump2(d,depth,st);
4266  switch( _ptr ) {
4267  case Constant:
4268    const_oop()->print(st);
4269    break;
4270  case BotPTR:
4271    if (!WizardMode && !Verbose) {
4272      if( _klass_is_exact ) st->print(":exact");
4273      break;
4274    }
4275  case TopPTR:
4276  case AnyNull:
4277  case NotNull:
4278    st->print(":%s", ptr_msg[_ptr]);
4279    if( _klass_is_exact ) st->print(":exact");
4280    break;
4281  }
4282
4283  if( _offset != 0 ) {
4284    int header_size = objArrayOopDesc::header_size() * wordSize;
4285    if( _offset == OffsetTop )       st->print("+undefined");
4286    else if( _offset == OffsetBot )  st->print("+any");
4287    else if( _offset < header_size ) st->print("+%d", _offset);
4288    else {
4289      BasicType basic_elem_type = elem()->basic_type();
4290      int array_base = arrayOopDesc::base_offset_in_bytes(basic_elem_type);
4291      int elem_size = type2aelembytes(basic_elem_type);
4292      st->print("[%d]", (_offset - array_base)/elem_size);
4293    }
4294  }
4295  st->print(" *");
4296  if (_instance_id == InstanceTop)
4297    st->print(",iid=top");
4298  else if (_instance_id != InstanceBot)
4299    st->print(",iid=%d",_instance_id);
4300
4301  dump_inline_depth(st);
4302  dump_speculative(st);
4303}
4304#endif
4305
4306bool TypeAryPtr::empty(void) const {
4307  if (_ary->empty())       return true;
4308  return TypeOopPtr::empty();
4309}
4310
4311//------------------------------add_offset-------------------------------------
4312const TypePtr *TypeAryPtr::add_offset(intptr_t offset) const {
4313  return make(_ptr, _const_oop, _ary, _klass, _klass_is_exact, xadd_offset(offset), _instance_id, add_offset_speculative(offset), _inline_depth);
4314}
4315
4316const Type *TypeAryPtr::remove_speculative() const {
4317  if (_speculative == NULL) {
4318    return this;
4319  }
4320  assert(_inline_depth == InlineDepthTop || _inline_depth == InlineDepthBottom, "non speculative type shouldn't have inline depth");
4321  return make(_ptr, _const_oop, _ary->remove_speculative()->is_ary(), _klass, _klass_is_exact, _offset, _instance_id, NULL, _inline_depth);
4322}
4323
4324const TypePtr *TypeAryPtr::with_inline_depth(int depth) const {
4325  if (!UseInlineDepthForSpeculativeTypes) {
4326    return this;
4327  }
4328  return make(_ptr, _const_oop, _ary->remove_speculative()->is_ary(), _klass, _klass_is_exact, _offset, _instance_id, _speculative, depth);
4329}
4330
4331//=============================================================================
4332
4333//------------------------------hash-------------------------------------------
4334// Type-specific hashing function.
4335int TypeNarrowPtr::hash(void) const {
4336  return _ptrtype->hash() + 7;
4337}
4338
4339bool TypeNarrowPtr::singleton(void) const {    // TRUE if type is a singleton
4340  return _ptrtype->singleton();
4341}
4342
4343bool TypeNarrowPtr::empty(void) const {
4344  return _ptrtype->empty();
4345}
4346
4347intptr_t TypeNarrowPtr::get_con() const {
4348  return _ptrtype->get_con();
4349}
4350
4351bool TypeNarrowPtr::eq( const Type *t ) const {
4352  const TypeNarrowPtr* tc = isa_same_narrowptr(t);
4353  if (tc != NULL) {
4354    if (_ptrtype->base() != tc->_ptrtype->base()) {
4355      return false;
4356    }
4357    return tc->_ptrtype->eq(_ptrtype);
4358  }
4359  return false;
4360}
4361
4362const Type *TypeNarrowPtr::xdual() const {    // Compute dual right now.
4363  const TypePtr* odual = _ptrtype->dual()->is_ptr();
4364  return make_same_narrowptr(odual);
4365}
4366
4367
4368const Type *TypeNarrowPtr::filter_helper(const Type *kills, bool include_speculative) const {
4369  if (isa_same_narrowptr(kills)) {
4370    const Type* ft =_ptrtype->filter_helper(is_same_narrowptr(kills)->_ptrtype, include_speculative);
4371    if (ft->empty())
4372      return Type::TOP;           // Canonical empty value
4373    if (ft->isa_ptr()) {
4374      return make_hash_same_narrowptr(ft->isa_ptr());
4375    }
4376    return ft;
4377  } else if (kills->isa_ptr()) {
4378    const Type* ft = _ptrtype->join_helper(kills, include_speculative);
4379    if (ft->empty())
4380      return Type::TOP;           // Canonical empty value
4381    return ft;
4382  } else {
4383    return Type::TOP;
4384  }
4385}
4386
4387//------------------------------xmeet------------------------------------------
4388// Compute the MEET of two types.  It returns a new Type object.
4389const Type *TypeNarrowPtr::xmeet( const Type *t ) const {
4390  // Perform a fast test for common case; meeting the same types together.
4391  if( this == t ) return this;  // Meeting same type-rep?
4392
4393  if (t->base() == base()) {
4394    const Type* result = _ptrtype->xmeet(t->make_ptr());
4395    if (result->isa_ptr()) {
4396      return make_hash_same_narrowptr(result->is_ptr());
4397    }
4398    return result;
4399  }
4400
4401  // Current "this->_base" is NarrowKlass or NarrowOop
4402  switch (t->base()) {          // switch on original type
4403
4404  case Int:                     // Mixing ints & oops happens when javac
4405  case Long:                    // reuses local variables
4406  case FloatTop:
4407  case FloatCon:
4408  case FloatBot:
4409  case DoubleTop:
4410  case DoubleCon:
4411  case DoubleBot:
4412  case AnyPtr:
4413  case RawPtr:
4414  case OopPtr:
4415  case InstPtr:
4416  case AryPtr:
4417  case MetadataPtr:
4418  case KlassPtr:
4419  case NarrowOop:
4420  case NarrowKlass:
4421
4422  case Bottom:                  // Ye Olde Default
4423    return Type::BOTTOM;
4424  case Top:
4425    return this;
4426
4427  default:                      // All else is a mistake
4428    typerr(t);
4429
4430  } // End of switch
4431
4432  return this;
4433}
4434
4435#ifndef PRODUCT
4436void TypeNarrowPtr::dump2( Dict & d, uint depth, outputStream *st ) const {
4437  _ptrtype->dump2(d, depth, st);
4438}
4439#endif
4440
4441const TypeNarrowOop *TypeNarrowOop::BOTTOM;
4442const TypeNarrowOop *TypeNarrowOop::NULL_PTR;
4443
4444
4445const TypeNarrowOop* TypeNarrowOop::make(const TypePtr* type) {
4446  return (const TypeNarrowOop*)(new TypeNarrowOop(type))->hashcons();
4447}
4448
4449const Type* TypeNarrowOop::remove_speculative() const {
4450  return make(_ptrtype->remove_speculative()->is_ptr());
4451}
4452
4453const Type* TypeNarrowOop::cleanup_speculative() const {
4454  return make(_ptrtype->cleanup_speculative()->is_ptr());
4455}
4456
4457#ifndef PRODUCT
4458void TypeNarrowOop::dump2( Dict & d, uint depth, outputStream *st ) const {
4459  st->print("narrowoop: ");
4460  TypeNarrowPtr::dump2(d, depth, st);
4461}
4462#endif
4463
4464const TypeNarrowKlass *TypeNarrowKlass::NULL_PTR;
4465
4466const TypeNarrowKlass* TypeNarrowKlass::make(const TypePtr* type) {
4467  return (const TypeNarrowKlass*)(new TypeNarrowKlass(type))->hashcons();
4468}
4469
4470#ifndef PRODUCT
4471void TypeNarrowKlass::dump2( Dict & d, uint depth, outputStream *st ) const {
4472  st->print("narrowklass: ");
4473  TypeNarrowPtr::dump2(d, depth, st);
4474}
4475#endif
4476
4477
4478//------------------------------eq---------------------------------------------
4479// Structural equality check for Type representations
4480bool TypeMetadataPtr::eq( const Type *t ) const {
4481  const TypeMetadataPtr *a = (const TypeMetadataPtr*)t;
4482  ciMetadata* one = metadata();
4483  ciMetadata* two = a->metadata();
4484  if (one == NULL || two == NULL) {
4485    return (one == two) && TypePtr::eq(t);
4486  } else {
4487    return one->equals(two) && TypePtr::eq(t);
4488  }
4489}
4490
4491//------------------------------hash-------------------------------------------
4492// Type-specific hashing function.
4493int TypeMetadataPtr::hash(void) const {
4494  return
4495    (metadata() ? metadata()->hash() : 0) +
4496    TypePtr::hash();
4497}
4498
4499//------------------------------singleton--------------------------------------
4500// TRUE if Type is a singleton type, FALSE otherwise.   Singletons are simple
4501// constants
4502bool TypeMetadataPtr::singleton(void) const {
4503  // detune optimizer to not generate constant metadata + constant offset as a constant!
4504  // TopPTR, Null, AnyNull, Constant are all singletons
4505  return (_offset == 0) && !below_centerline(_ptr);
4506}
4507
4508//------------------------------add_offset-------------------------------------
4509const TypePtr *TypeMetadataPtr::add_offset( intptr_t offset ) const {
4510  return make( _ptr, _metadata, xadd_offset(offset));
4511}
4512
4513//-----------------------------filter------------------------------------------
4514// Do not allow interface-vs.-noninterface joins to collapse to top.
4515const Type *TypeMetadataPtr::filter_helper(const Type *kills, bool include_speculative) const {
4516  const TypeMetadataPtr* ft = join_helper(kills, include_speculative)->isa_metadataptr();
4517  if (ft == NULL || ft->empty())
4518    return Type::TOP;           // Canonical empty value
4519  return ft;
4520}
4521
4522 //------------------------------get_con----------------------------------------
4523intptr_t TypeMetadataPtr::get_con() const {
4524  assert( _ptr == Null || _ptr == Constant, "" );
4525  assert( _offset >= 0, "" );
4526
4527  if (_offset != 0) {
4528    // After being ported to the compiler interface, the compiler no longer
4529    // directly manipulates the addresses of oops.  Rather, it only has a pointer
4530    // to a handle at compile time.  This handle is embedded in the generated
4531    // code and dereferenced at the time the nmethod is made.  Until that time,
4532    // it is not reasonable to do arithmetic with the addresses of oops (we don't
4533    // have access to the addresses!).  This does not seem to currently happen,
4534    // but this assertion here is to help prevent its occurence.
4535    tty->print_cr("Found oop constant with non-zero offset");
4536    ShouldNotReachHere();
4537  }
4538
4539  return (intptr_t)metadata()->constant_encoding();
4540}
4541
4542//------------------------------cast_to_ptr_type-------------------------------
4543const Type *TypeMetadataPtr::cast_to_ptr_type(PTR ptr) const {
4544  if( ptr == _ptr ) return this;
4545  return make(ptr, metadata(), _offset);
4546}
4547
4548//------------------------------meet-------------------------------------------
4549// Compute the MEET of two types.  It returns a new Type object.
4550const Type *TypeMetadataPtr::xmeet( const Type *t ) const {
4551  // Perform a fast test for common case; meeting the same types together.
4552  if( this == t ) return this;  // Meeting same type-rep?
4553
4554  // Current "this->_base" is OopPtr
4555  switch (t->base()) {          // switch on original type
4556
4557  case Int:                     // Mixing ints & oops happens when javac
4558  case Long:                    // reuses local variables
4559  case FloatTop:
4560  case FloatCon:
4561  case FloatBot:
4562  case DoubleTop:
4563  case DoubleCon:
4564  case DoubleBot:
4565  case NarrowOop:
4566  case NarrowKlass:
4567  case Bottom:                  // Ye Olde Default
4568    return Type::BOTTOM;
4569  case Top:
4570    return this;
4571
4572  default:                      // All else is a mistake
4573    typerr(t);
4574
4575  case AnyPtr: {
4576    // Found an AnyPtr type vs self-OopPtr type
4577    const TypePtr *tp = t->is_ptr();
4578    int offset = meet_offset(tp->offset());
4579    PTR ptr = meet_ptr(tp->ptr());
4580    switch (tp->ptr()) {
4581    case Null:
4582      if (ptr == Null)  return TypePtr::make(AnyPtr, ptr, offset, tp->speculative(), tp->inline_depth());
4583      // else fall through:
4584    case TopPTR:
4585    case AnyNull: {
4586      return make(ptr, _metadata, offset);
4587    }
4588    case BotPTR:
4589    case NotNull:
4590      return TypePtr::make(AnyPtr, ptr, offset, tp->speculative(), tp->inline_depth());
4591    default: typerr(t);
4592    }
4593  }
4594
4595  case RawPtr:
4596  case KlassPtr:
4597  case OopPtr:
4598  case InstPtr:
4599  case AryPtr:
4600    return TypePtr::BOTTOM;     // Oop meet raw is not well defined
4601
4602  case MetadataPtr: {
4603    const TypeMetadataPtr *tp = t->is_metadataptr();
4604    int offset = meet_offset(tp->offset());
4605    PTR tptr = tp->ptr();
4606    PTR ptr = meet_ptr(tptr);
4607    ciMetadata* md = (tptr == TopPTR) ? metadata() : tp->metadata();
4608    if (tptr == TopPTR || _ptr == TopPTR ||
4609        metadata()->equals(tp->metadata())) {
4610      return make(ptr, md, offset);
4611    }
4612    // metadata is different
4613    if( ptr == Constant ) {  // Cannot be equal constants, so...
4614      if( tptr == Constant && _ptr != Constant)  return t;
4615      if( _ptr == Constant && tptr != Constant)  return this;
4616      ptr = NotNull;            // Fall down in lattice
4617    }
4618    return make(ptr, NULL, offset);
4619    break;
4620  }
4621  } // End of switch
4622  return this;                  // Return the double constant
4623}
4624
4625
4626//------------------------------xdual------------------------------------------
4627// Dual of a pure metadata pointer.
4628const Type *TypeMetadataPtr::xdual() const {
4629  return new TypeMetadataPtr(dual_ptr(), metadata(), dual_offset());
4630}
4631
4632//------------------------------dump2------------------------------------------
4633#ifndef PRODUCT
4634void TypeMetadataPtr::dump2( Dict &d, uint depth, outputStream *st ) const {
4635  st->print("metadataptr:%s", ptr_msg[_ptr]);
4636  if( metadata() ) st->print(INTPTR_FORMAT, p2i(metadata()));
4637  switch( _offset ) {
4638  case OffsetTop: st->print("+top"); break;
4639  case OffsetBot: st->print("+any"); break;
4640  case         0: break;
4641  default:        st->print("+%d",_offset); break;
4642  }
4643}
4644#endif
4645
4646
4647//=============================================================================
4648// Convenience common pre-built type.
4649const TypeMetadataPtr *TypeMetadataPtr::BOTTOM;
4650
4651TypeMetadataPtr::TypeMetadataPtr(PTR ptr, ciMetadata* metadata, int offset):
4652  TypePtr(MetadataPtr, ptr, offset), _metadata(metadata) {
4653}
4654
4655const TypeMetadataPtr* TypeMetadataPtr::make(ciMethod* m) {
4656  return make(Constant, m, 0);
4657}
4658const TypeMetadataPtr* TypeMetadataPtr::make(ciMethodData* m) {
4659  return make(Constant, m, 0);
4660}
4661
4662//------------------------------make-------------------------------------------
4663// Create a meta data constant
4664const TypeMetadataPtr *TypeMetadataPtr::make(PTR ptr, ciMetadata* m, int offset) {
4665  assert(m == NULL || !m->is_klass(), "wrong type");
4666  return (TypeMetadataPtr*)(new TypeMetadataPtr(ptr, m, offset))->hashcons();
4667}
4668
4669
4670//=============================================================================
4671// Convenience common pre-built types.
4672
4673// Not-null object klass or below
4674const TypeKlassPtr *TypeKlassPtr::OBJECT;
4675const TypeKlassPtr *TypeKlassPtr::OBJECT_OR_NULL;
4676
4677//------------------------------TypeKlassPtr-----------------------------------
4678TypeKlassPtr::TypeKlassPtr( PTR ptr, ciKlass* klass, int offset )
4679  : TypePtr(KlassPtr, ptr, offset), _klass(klass), _klass_is_exact(ptr == Constant) {
4680}
4681
4682//------------------------------make-------------------------------------------
4683// ptr to klass 'k', if Constant, or possibly to a sub-klass if not a Constant
4684const TypeKlassPtr *TypeKlassPtr::make( PTR ptr, ciKlass* k, int offset ) {
4685  assert( k != NULL, "Expect a non-NULL klass");
4686  assert(k->is_instance_klass() || k->is_array_klass(), "Incorrect type of klass oop");
4687  TypeKlassPtr *r =
4688    (TypeKlassPtr*)(new TypeKlassPtr(ptr, k, offset))->hashcons();
4689
4690  return r;
4691}
4692
4693//------------------------------eq---------------------------------------------
4694// Structural equality check for Type representations
4695bool TypeKlassPtr::eq( const Type *t ) const {
4696  const TypeKlassPtr *p = t->is_klassptr();
4697  return
4698    klass()->equals(p->klass()) &&
4699    TypePtr::eq(p);
4700}
4701
4702//------------------------------hash-------------------------------------------
4703// Type-specific hashing function.
4704int TypeKlassPtr::hash(void) const {
4705  return klass()->hash() + TypePtr::hash();
4706}
4707
4708//------------------------------singleton--------------------------------------
4709// TRUE if Type is a singleton type, FALSE otherwise.   Singletons are simple
4710// constants
4711bool TypeKlassPtr::singleton(void) const {
4712  // detune optimizer to not generate constant klass + constant offset as a constant!
4713  // TopPTR, Null, AnyNull, Constant are all singletons
4714  return (_offset == 0) && !below_centerline(_ptr);
4715}
4716
4717// Do not allow interface-vs.-noninterface joins to collapse to top.
4718const Type *TypeKlassPtr::filter_helper(const Type *kills, bool include_speculative) const {
4719  // logic here mirrors the one from TypeOopPtr::filter. See comments
4720  // there.
4721  const Type* ft = join_helper(kills, include_speculative);
4722  const TypeKlassPtr* ftkp = ft->isa_klassptr();
4723  const TypeKlassPtr* ktkp = kills->isa_klassptr();
4724
4725  if (ft->empty()) {
4726    if (!empty() && ktkp != NULL && ktkp->klass()->is_loaded() && ktkp->klass()->is_interface())
4727      return kills;             // Uplift to interface
4728
4729    return Type::TOP;           // Canonical empty value
4730  }
4731
4732  // Interface klass type could be exact in opposite to interface type,
4733  // return it here instead of incorrect Constant ptr J/L/Object (6894807).
4734  if (ftkp != NULL && ktkp != NULL &&
4735      ftkp->is_loaded() &&  ftkp->klass()->is_interface() &&
4736      !ftkp->klass_is_exact() && // Keep exact interface klass
4737      ktkp->is_loaded() && !ktkp->klass()->is_interface()) {
4738    return ktkp->cast_to_ptr_type(ftkp->ptr());
4739  }
4740
4741  return ft;
4742}
4743
4744//----------------------compute_klass------------------------------------------
4745// Compute the defining klass for this class
4746ciKlass* TypeAryPtr::compute_klass(DEBUG_ONLY(bool verify)) const {
4747  // Compute _klass based on element type.
4748  ciKlass* k_ary = NULL;
4749  const TypeInstPtr *tinst;
4750  const TypeAryPtr *tary;
4751  const Type* el = elem();
4752  if (el->isa_narrowoop()) {
4753    el = el->make_ptr();
4754  }
4755
4756  // Get element klass
4757  if ((tinst = el->isa_instptr()) != NULL) {
4758    // Compute array klass from element klass
4759    k_ary = ciObjArrayKlass::make(tinst->klass());
4760  } else if ((tary = el->isa_aryptr()) != NULL) {
4761    // Compute array klass from element klass
4762    ciKlass* k_elem = tary->klass();
4763    // If element type is something like bottom[], k_elem will be null.
4764    if (k_elem != NULL)
4765      k_ary = ciObjArrayKlass::make(k_elem);
4766  } else if ((el->base() == Type::Top) ||
4767             (el->base() == Type::Bottom)) {
4768    // element type of Bottom occurs from meet of basic type
4769    // and object; Top occurs when doing join on Bottom.
4770    // Leave k_ary at NULL.
4771  } else {
4772    // Cannot compute array klass directly from basic type,
4773    // since subtypes of TypeInt all have basic type T_INT.
4774#ifdef ASSERT
4775    if (verify && el->isa_int()) {
4776      // Check simple cases when verifying klass.
4777      BasicType bt = T_ILLEGAL;
4778      if (el == TypeInt::BYTE) {
4779        bt = T_BYTE;
4780      } else if (el == TypeInt::SHORT) {
4781        bt = T_SHORT;
4782      } else if (el == TypeInt::CHAR) {
4783        bt = T_CHAR;
4784      } else if (el == TypeInt::INT) {
4785        bt = T_INT;
4786      } else {
4787        return _klass; // just return specified klass
4788      }
4789      return ciTypeArrayKlass::make(bt);
4790    }
4791#endif
4792    assert(!el->isa_int(),
4793           "integral arrays must be pre-equipped with a class");
4794    // Compute array klass directly from basic type
4795    k_ary = ciTypeArrayKlass::make(el->basic_type());
4796  }
4797  return k_ary;
4798}
4799
4800//------------------------------klass------------------------------------------
4801// Return the defining klass for this class
4802ciKlass* TypeAryPtr::klass() const {
4803  if( _klass ) return _klass;   // Return cached value, if possible
4804
4805  // Oops, need to compute _klass and cache it
4806  ciKlass* k_ary = compute_klass();
4807
4808  if( this != TypeAryPtr::OOPS && this->dual() != TypeAryPtr::OOPS ) {
4809    // The _klass field acts as a cache of the underlying
4810    // ciKlass for this array type.  In order to set the field,
4811    // we need to cast away const-ness.
4812    //
4813    // IMPORTANT NOTE: we *never* set the _klass field for the
4814    // type TypeAryPtr::OOPS.  This Type is shared between all
4815    // active compilations.  However, the ciKlass which represents
4816    // this Type is *not* shared between compilations, so caching
4817    // this value would result in fetching a dangling pointer.
4818    //
4819    // Recomputing the underlying ciKlass for each request is
4820    // a bit less efficient than caching, but calls to
4821    // TypeAryPtr::OOPS->klass() are not common enough to matter.
4822    ((TypeAryPtr*)this)->_klass = k_ary;
4823    if (UseCompressedOops && k_ary != NULL && k_ary->is_obj_array_klass() &&
4824        _offset != 0 && _offset != arrayOopDesc::length_offset_in_bytes()) {
4825      ((TypeAryPtr*)this)->_is_ptr_to_narrowoop = true;
4826    }
4827  }
4828  return k_ary;
4829}
4830
4831
4832//------------------------------add_offset-------------------------------------
4833// Access internals of klass object
4834const TypePtr *TypeKlassPtr::add_offset( intptr_t offset ) const {
4835  return make( _ptr, klass(), xadd_offset(offset) );
4836}
4837
4838//------------------------------cast_to_ptr_type-------------------------------
4839const Type *TypeKlassPtr::cast_to_ptr_type(PTR ptr) const {
4840  assert(_base == KlassPtr, "subclass must override cast_to_ptr_type");
4841  if( ptr == _ptr ) return this;
4842  return make(ptr, _klass, _offset);
4843}
4844
4845
4846//-----------------------------cast_to_exactness-------------------------------
4847const Type *TypeKlassPtr::cast_to_exactness(bool klass_is_exact) const {
4848  if( klass_is_exact == _klass_is_exact ) return this;
4849  if (!UseExactTypes)  return this;
4850  return make(klass_is_exact ? Constant : NotNull, _klass, _offset);
4851}
4852
4853
4854//-----------------------------as_instance_type--------------------------------
4855// Corresponding type for an instance of the given class.
4856// It will be NotNull, and exact if and only if the klass type is exact.
4857const TypeOopPtr* TypeKlassPtr::as_instance_type() const {
4858  ciKlass* k = klass();
4859  bool    xk = klass_is_exact();
4860  //return TypeInstPtr::make(TypePtr::NotNull, k, xk, NULL, 0);
4861  const TypeOopPtr* toop = TypeOopPtr::make_from_klass_raw(k);
4862  guarantee(toop != NULL, "need type for given klass");
4863  toop = toop->cast_to_ptr_type(TypePtr::NotNull)->is_oopptr();
4864  return toop->cast_to_exactness(xk)->is_oopptr();
4865}
4866
4867
4868//------------------------------xmeet------------------------------------------
4869// Compute the MEET of two types, return a new Type object.
4870const Type    *TypeKlassPtr::xmeet( const Type *t ) const {
4871  // Perform a fast test for common case; meeting the same types together.
4872  if( this == t ) return this;  // Meeting same type-rep?
4873
4874  // Current "this->_base" is Pointer
4875  switch (t->base()) {          // switch on original type
4876
4877  case Int:                     // Mixing ints & oops happens when javac
4878  case Long:                    // reuses local variables
4879  case FloatTop:
4880  case FloatCon:
4881  case FloatBot:
4882  case DoubleTop:
4883  case DoubleCon:
4884  case DoubleBot:
4885  case NarrowOop:
4886  case NarrowKlass:
4887  case Bottom:                  // Ye Olde Default
4888    return Type::BOTTOM;
4889  case Top:
4890    return this;
4891
4892  default:                      // All else is a mistake
4893    typerr(t);
4894
4895  case AnyPtr: {                // Meeting to AnyPtrs
4896    // Found an AnyPtr type vs self-KlassPtr type
4897    const TypePtr *tp = t->is_ptr();
4898    int offset = meet_offset(tp->offset());
4899    PTR ptr = meet_ptr(tp->ptr());
4900    switch (tp->ptr()) {
4901    case TopPTR:
4902      return this;
4903    case Null:
4904      if( ptr == Null ) return TypePtr::make(AnyPtr, ptr, offset, tp->speculative(), tp->inline_depth());
4905    case AnyNull:
4906      return make( ptr, klass(), offset );
4907    case BotPTR:
4908    case NotNull:
4909      return TypePtr::make(AnyPtr, ptr, offset, tp->speculative(), tp->inline_depth());
4910    default: typerr(t);
4911    }
4912  }
4913
4914  case RawPtr:
4915  case MetadataPtr:
4916  case OopPtr:
4917  case AryPtr:                  // Meet with AryPtr
4918  case InstPtr:                 // Meet with InstPtr
4919    return TypePtr::BOTTOM;
4920
4921  //
4922  //             A-top         }
4923  //           /   |   \       }  Tops
4924  //       B-top A-any C-top   }
4925  //          | /  |  \ |      }  Any-nulls
4926  //       B-any   |   C-any   }
4927  //          |    |    |
4928  //       B-con A-con C-con   } constants; not comparable across classes
4929  //          |    |    |
4930  //       B-not   |   C-not   }
4931  //          | \  |  / |      }  not-nulls
4932  //       B-bot A-not C-bot   }
4933  //           \   |   /       }  Bottoms
4934  //             A-bot         }
4935  //
4936
4937  case KlassPtr: {  // Meet two KlassPtr types
4938    const TypeKlassPtr *tkls = t->is_klassptr();
4939    int  off     = meet_offset(tkls->offset());
4940    PTR  ptr     = meet_ptr(tkls->ptr());
4941
4942    // Check for easy case; klasses are equal (and perhaps not loaded!)
4943    // If we have constants, then we created oops so classes are loaded
4944    // and we can handle the constants further down.  This case handles
4945    // not-loaded classes
4946    if( ptr != Constant && tkls->klass()->equals(klass()) ) {
4947      return make( ptr, klass(), off );
4948    }
4949
4950    // Classes require inspection in the Java klass hierarchy.  Must be loaded.
4951    ciKlass* tkls_klass = tkls->klass();
4952    ciKlass* this_klass = this->klass();
4953    assert( tkls_klass->is_loaded(), "This class should have been loaded.");
4954    assert( this_klass->is_loaded(), "This class should have been loaded.");
4955
4956    // If 'this' type is above the centerline and is a superclass of the
4957    // other, we can treat 'this' as having the same type as the other.
4958    if ((above_centerline(this->ptr())) &&
4959        tkls_klass->is_subtype_of(this_klass)) {
4960      this_klass = tkls_klass;
4961    }
4962    // If 'tinst' type is above the centerline and is a superclass of the
4963    // other, we can treat 'tinst' as having the same type as the other.
4964    if ((above_centerline(tkls->ptr())) &&
4965        this_klass->is_subtype_of(tkls_klass)) {
4966      tkls_klass = this_klass;
4967    }
4968
4969    // Check for classes now being equal
4970    if (tkls_klass->equals(this_klass)) {
4971      // If the klasses are equal, the constants may still differ.  Fall to
4972      // NotNull if they do (neither constant is NULL; that is a special case
4973      // handled elsewhere).
4974      if( ptr == Constant ) {
4975        if (this->_ptr == Constant && tkls->_ptr == Constant &&
4976            this->klass()->equals(tkls->klass()));
4977        else if (above_centerline(this->ptr()));
4978        else if (above_centerline(tkls->ptr()));
4979        else
4980          ptr = NotNull;
4981      }
4982      return make( ptr, this_klass, off );
4983    } // Else classes are not equal
4984
4985    // Since klasses are different, we require the LCA in the Java
4986    // class hierarchy - which means we have to fall to at least NotNull.
4987    if( ptr == TopPTR || ptr == AnyNull || ptr == Constant )
4988      ptr = NotNull;
4989    // Now we find the LCA of Java classes
4990    ciKlass* k = this_klass->least_common_ancestor(tkls_klass);
4991    return   make( ptr, k, off );
4992  } // End of case KlassPtr
4993
4994  } // End of switch
4995  return this;                  // Return the double constant
4996}
4997
4998//------------------------------xdual------------------------------------------
4999// Dual: compute field-by-field dual
5000const Type    *TypeKlassPtr::xdual() const {
5001  return new TypeKlassPtr( dual_ptr(), klass(), dual_offset() );
5002}
5003
5004//------------------------------get_con----------------------------------------
5005intptr_t TypeKlassPtr::get_con() const {
5006  assert( _ptr == Null || _ptr == Constant, "" );
5007  assert( _offset >= 0, "" );
5008
5009  if (_offset != 0) {
5010    // After being ported to the compiler interface, the compiler no longer
5011    // directly manipulates the addresses of oops.  Rather, it only has a pointer
5012    // to a handle at compile time.  This handle is embedded in the generated
5013    // code and dereferenced at the time the nmethod is made.  Until that time,
5014    // it is not reasonable to do arithmetic with the addresses of oops (we don't
5015    // have access to the addresses!).  This does not seem to currently happen,
5016    // but this assertion here is to help prevent its occurence.
5017    tty->print_cr("Found oop constant with non-zero offset");
5018    ShouldNotReachHere();
5019  }
5020
5021  return (intptr_t)klass()->constant_encoding();
5022}
5023//------------------------------dump2------------------------------------------
5024// Dump Klass Type
5025#ifndef PRODUCT
5026void TypeKlassPtr::dump2( Dict & d, uint depth, outputStream *st ) const {
5027  switch( _ptr ) {
5028  case Constant:
5029    st->print("precise ");
5030  case NotNull:
5031    {
5032      const char *name = klass()->name()->as_utf8();
5033      if( name ) {
5034        st->print("klass %s: " INTPTR_FORMAT, name, p2i(klass()));
5035      } else {
5036        ShouldNotReachHere();
5037      }
5038    }
5039  case BotPTR:
5040    if( !WizardMode && !Verbose && !_klass_is_exact ) break;
5041  case TopPTR:
5042  case AnyNull:
5043    st->print(":%s", ptr_msg[_ptr]);
5044    if( _klass_is_exact ) st->print(":exact");
5045    break;
5046  }
5047
5048  if( _offset ) {               // Dump offset, if any
5049    if( _offset == OffsetBot )      { st->print("+any"); }
5050    else if( _offset == OffsetTop ) { st->print("+unknown"); }
5051    else                            { st->print("+%d", _offset); }
5052  }
5053
5054  st->print(" *");
5055}
5056#endif
5057
5058
5059
5060//=============================================================================
5061// Convenience common pre-built types.
5062
5063//------------------------------make-------------------------------------------
5064const TypeFunc *TypeFunc::make( const TypeTuple *domain, const TypeTuple *range ) {
5065  return (TypeFunc*)(new TypeFunc(domain,range))->hashcons();
5066}
5067
5068//------------------------------make-------------------------------------------
5069const TypeFunc *TypeFunc::make(ciMethod* method) {
5070  Compile* C = Compile::current();
5071  const TypeFunc* tf = C->last_tf(method); // check cache
5072  if (tf != NULL)  return tf;  // The hit rate here is almost 50%.
5073  const TypeTuple *domain;
5074  if (method->is_static()) {
5075    domain = TypeTuple::make_domain(NULL, method->signature());
5076  } else {
5077    domain = TypeTuple::make_domain(method->holder(), method->signature());
5078  }
5079  const TypeTuple *range  = TypeTuple::make_range(method->signature());
5080  tf = TypeFunc::make(domain, range);
5081  C->set_last_tf(method, tf);  // fill cache
5082  return tf;
5083}
5084
5085//------------------------------meet-------------------------------------------
5086// Compute the MEET of two types.  It returns a new Type object.
5087const Type *TypeFunc::xmeet( const Type *t ) const {
5088  // Perform a fast test for common case; meeting the same types together.
5089  if( this == t ) return this;  // Meeting same type-rep?
5090
5091  // Current "this->_base" is Func
5092  switch (t->base()) {          // switch on original type
5093
5094  case Bottom:                  // Ye Olde Default
5095    return t;
5096
5097  default:                      // All else is a mistake
5098    typerr(t);
5099
5100  case Top:
5101    break;
5102  }
5103  return this;                  // Return the double constant
5104}
5105
5106//------------------------------xdual------------------------------------------
5107// Dual: compute field-by-field dual
5108const Type *TypeFunc::xdual() const {
5109  return this;
5110}
5111
5112//------------------------------eq---------------------------------------------
5113// Structural equality check for Type representations
5114bool TypeFunc::eq( const Type *t ) const {
5115  const TypeFunc *a = (const TypeFunc*)t;
5116  return _domain == a->_domain &&
5117    _range == a->_range;
5118}
5119
5120//------------------------------hash-------------------------------------------
5121// Type-specific hashing function.
5122int TypeFunc::hash(void) const {
5123  return (intptr_t)_domain + (intptr_t)_range;
5124}
5125
5126//------------------------------dump2------------------------------------------
5127// Dump Function Type
5128#ifndef PRODUCT
5129void TypeFunc::dump2( Dict &d, uint depth, outputStream *st ) const {
5130  if( _range->cnt() <= Parms )
5131    st->print("void");
5132  else {
5133    uint i;
5134    for (i = Parms; i < _range->cnt()-1; i++) {
5135      _range->field_at(i)->dump2(d,depth,st);
5136      st->print("/");
5137    }
5138    _range->field_at(i)->dump2(d,depth,st);
5139  }
5140  st->print(" ");
5141  st->print("( ");
5142  if( !depth || d[this] ) {     // Check for recursive dump
5143    st->print("...)");
5144    return;
5145  }
5146  d.Insert((void*)this,(void*)this);    // Stop recursion
5147  if (Parms < _domain->cnt())
5148    _domain->field_at(Parms)->dump2(d,depth-1,st);
5149  for (uint i = Parms+1; i < _domain->cnt(); i++) {
5150    st->print(", ");
5151    _domain->field_at(i)->dump2(d,depth-1,st);
5152  }
5153  st->print(" )");
5154}
5155#endif
5156
5157//------------------------------singleton--------------------------------------
5158// TRUE if Type is a singleton type, FALSE otherwise.   Singletons are simple
5159// constants (Ldi nodes).  Singletons are integer, float or double constants
5160// or a single symbol.
5161bool TypeFunc::singleton(void) const {
5162  return false;                 // Never a singleton
5163}
5164
5165bool TypeFunc::empty(void) const {
5166  return false;                 // Never empty
5167}
5168
5169
5170BasicType TypeFunc::return_type() const{
5171  if (range()->cnt() == TypeFunc::Parms) {
5172    return T_VOID;
5173  }
5174  return range()->field_at(TypeFunc::Parms)->basic_type();
5175}
5176