333 const Type **ffalse =(const Type**)shared_type_arena->Amalloc_4(2*sizeof(Type*));
334 ffalse[0] = Type::CONTROL;
335 ffalse[1] = Type::TOP;
336 TypeTuple::IFFALSE = TypeTuple::make( 2, ffalse );
337
338 const Type **fneither =(const Type**)shared_type_arena->Amalloc_4(2*sizeof(Type*));
339 fneither[0] = Type::TOP;
340 fneither[1] = Type::TOP;
341 TypeTuple::IFNEITHER = TypeTuple::make( 2, fneither );
342
343 const Type **ftrue =(const Type**)shared_type_arena->Amalloc_4(2*sizeof(Type*));
344 ftrue[0] = Type::TOP;
345 ftrue[1] = Type::CONTROL;
346 TypeTuple::IFTRUE = TypeTuple::make( 2, ftrue );
347
348 const Type **floop =(const Type**)shared_type_arena->Amalloc_4(2*sizeof(Type*));
349 floop[0] = Type::CONTROL;
350 floop[1] = TypeInt::INT;
351 TypeTuple::LOOPBODY = TypeTuple::make( 2, floop );
352
353 TypePtr::NULL_PTR= TypePtr::make( AnyPtr, TypePtr::Null, 0 );
354 TypePtr::NOTNULL = TypePtr::make( AnyPtr, TypePtr::NotNull, OffsetBot );
355 TypePtr::BOTTOM = TypePtr::make( AnyPtr, TypePtr::BotPTR, OffsetBot );
356
357 TypeRawPtr::BOTTOM = TypeRawPtr::make( TypePtr::BotPTR );
358 TypeRawPtr::NOTNULL= TypeRawPtr::make( TypePtr::NotNull );
359
360 const Type **fmembar = TypeTuple::fields(0);
361 TypeTuple::MEMBAR = TypeTuple::make(TypeFunc::Parms+0, fmembar);
362
363 const Type **fsc = (const Type**)shared_type_arena->Amalloc_4(2*sizeof(Type*));
364 fsc[0] = TypeInt::CC;
365 fsc[1] = Type::MEMORY;
366 TypeTuple::STORECONDITIONAL = TypeTuple::make(2, fsc);
367
368 TypeInstPtr::NOTNULL = TypeInstPtr::make(TypePtr::NotNull, current->env()->Object_klass());
369 TypeInstPtr::BOTTOM = TypeInstPtr::make(TypePtr::BotPTR, current->env()->Object_klass());
370 TypeInstPtr::MIRROR = TypeInstPtr::make(TypePtr::NotNull, current->env()->Class_klass());
371 TypeInstPtr::MARK = TypeInstPtr::make(TypePtr::BotPTR, current->env()->Object_klass(),
372 false, 0, oopDesc::mark_offset_in_bytes());
373 TypeInstPtr::KLASS = TypeInstPtr::make(TypePtr::BotPTR, current->env()->Object_klass(),
374 false, 0, oopDesc::klass_offset_in_bytes());
375 TypeOopPtr::BOTTOM = TypeOopPtr::make(TypePtr::BotPTR, OffsetBot, TypeOopPtr::InstanceBot, NULL);
376
377 TypeMetadataPtr::BOTTOM = TypeMetadataPtr::make(TypePtr::BotPTR, NULL, OffsetBot);
378
379 TypeNarrowOop::NULL_PTR = TypeNarrowOop::make( TypePtr::NULL_PTR );
380 TypeNarrowOop::BOTTOM = TypeNarrowOop::make( TypeInstPtr::BOTTOM );
381
382 TypeNarrowKlass::NULL_PTR = TypeNarrowKlass::make( TypePtr::NULL_PTR );
383
384 mreg2type[Op_Node] = Type::BOTTOM;
385 mreg2type[Op_Set ] = 0;
386 mreg2type[Op_RegN] = TypeNarrowOop::BOTTOM;
387 mreg2type[Op_RegI] = TypeInt::INT;
388 mreg2type[Op_RegP] = TypePtr::BOTTOM;
389 mreg2type[Op_RegF] = Type::FLOAT;
390 mreg2type[Op_RegD] = Type::DOUBLE;
391 mreg2type[Op_RegL] = TypeLong::LONG;
392 mreg2type[Op_RegFlags] = TypeInt::CC;
393
394 TypeAryPtr::RANGE = TypeAryPtr::make( TypePtr::BotPTR, TypeAry::make(Type::BOTTOM,TypeInt::POS), NULL /* current->env()->Object_klass() */, false, arrayOopDesc::length_offset_in_bytes());
395
603 const TypePtr* t_ptr = t->make_ptr();
604 if( this_ptr == NULL || t_ptr == NULL )
605 return result;
606
607 const TypeInstPtr* this_inst = this_ptr->isa_instptr();
608 const TypeInstPtr* t_inst = t_ptr->isa_instptr();
609 if( this_inst && this_inst->is_loaded() && t_inst && t_inst->is_loaded() ) {
610 bool this_interface = this_inst->klass()->is_interface();
611 bool t_interface = t_inst->klass()->is_interface();
612 result = this_interface ^ t_interface;
613 }
614
615 return result;
616 }
617
618 bool Type::interface_vs_oop(const Type *t) const {
619 if (interface_vs_oop_helper(t)) {
620 return true;
621 }
622 // Now check the speculative parts as well
623 const TypeOopPtr* this_spec = isa_oopptr() != NULL ? isa_oopptr()->speculative() : NULL;
624 const TypeOopPtr* t_spec = t->isa_oopptr() != NULL ? t->isa_oopptr()->speculative() : NULL;
625 if (this_spec != NULL && t_spec != NULL) {
626 if (this_spec->interface_vs_oop_helper(t_spec)) {
627 return true;
628 }
629 return false;
630 }
631 if (this_spec != NULL && this_spec->interface_vs_oop_helper(t)) {
632 return true;
633 }
634 if (t_spec != NULL && interface_vs_oop_helper(t_spec)) {
635 return true;
636 }
637 return false;
638 }
639
640 #endif
641
642 //------------------------------meet-------------------------------------------
643 // Compute the MEET of two types. NOT virtual. It enforces that meet is
644 // commutative and the lattice is symmetric.
1958 bool TypeAry::eq( const Type *t ) const {
1959 const TypeAry *a = (const TypeAry*)t;
1960 return _elem == a->_elem &&
1961 _stable == a->_stable &&
1962 _size == a->_size;
1963 }
1964
1965 //------------------------------hash-------------------------------------------
1966 // Type-specific hashing function.
1967 int TypeAry::hash(void) const {
1968 return (intptr_t)_elem + (intptr_t)_size + (_stable ? 43 : 0);
1969 }
1970
1971 /**
1972 * Return same type without a speculative part in the element
1973 */
1974 const Type* TypeAry::remove_speculative() const {
1975 return make(_elem->remove_speculative(), _size, _stable);
1976 }
1977
1978 //----------------------interface_vs_oop---------------------------------------
1979 #ifdef ASSERT
1980 bool TypeAry::interface_vs_oop(const Type *t) const {
1981 const TypeAry* t_ary = t->is_ary();
1982 if (t_ary) {
1983 return _elem->interface_vs_oop(t_ary->_elem);
1984 }
1985 return false;
1986 }
1987 #endif
1988
1989 //------------------------------dump2------------------------------------------
1990 #ifndef PRODUCT
1991 void TypeAry::dump2( Dict &d, uint depth, outputStream *st ) const {
1992 if (_stable) st->print("stable:");
1993 _elem->dump2(d, depth, st);
1994 st->print("[");
1995 _size->dump2(d, depth, st);
1996 st->print("]");
1997 }
2162
2163 //=============================================================================
2164 // Convenience common pre-built types.
2165 const TypePtr *TypePtr::NULL_PTR;
2166 const TypePtr *TypePtr::NOTNULL;
2167 const TypePtr *TypePtr::BOTTOM;
2168
2169 //------------------------------meet-------------------------------------------
2170 // Meet over the PTR enum
2171 const TypePtr::PTR TypePtr::ptr_meet[TypePtr::lastPTR][TypePtr::lastPTR] = {
2172 // TopPTR, AnyNull, Constant, Null, NotNull, BotPTR,
2173 { /* Top */ TopPTR, AnyNull, Constant, Null, NotNull, BotPTR,},
2174 { /* AnyNull */ AnyNull, AnyNull, Constant, BotPTR, NotNull, BotPTR,},
2175 { /* Constant*/ Constant, Constant, Constant, BotPTR, NotNull, BotPTR,},
2176 { /* Null */ Null, BotPTR, BotPTR, Null, BotPTR, BotPTR,},
2177 { /* NotNull */ NotNull, NotNull, NotNull, BotPTR, NotNull, BotPTR,},
2178 { /* BotPTR */ BotPTR, BotPTR, BotPTR, BotPTR, BotPTR, BotPTR,}
2179 };
2180
2181 //------------------------------make-------------------------------------------
2182 const TypePtr *TypePtr::make( TYPES t, enum PTR ptr, int offset ) {
2183 return (TypePtr*)(new TypePtr(t,ptr,offset))->hashcons();
2184 }
2185
2186 //------------------------------cast_to_ptr_type-------------------------------
2187 const Type *TypePtr::cast_to_ptr_type(PTR ptr) const {
2188 assert(_base == AnyPtr, "subclass must override cast_to_ptr_type");
2189 if( ptr == _ptr ) return this;
2190 return make(_base, ptr, _offset);
2191 }
2192
2193 //------------------------------get_con----------------------------------------
2194 intptr_t TypePtr::get_con() const {
2195 assert( _ptr == Null, "" );
2196 return _offset;
2197 }
2198
2199 //------------------------------meet-------------------------------------------
2200 // Compute the MEET of two types. It returns a new Type object.
2201 const Type *TypePtr::xmeet( const Type *t ) const {
2202 // Perform a fast test for common case; meeting the same types together.
2203 if( this == t ) return this; // Meeting same type-rep?
2204
2205 // Current "this->_base" is AnyPtr
2206 switch (t->base()) { // switch on original type
2207 case Int: // Mixing ints & oops happens when javac
2208 case Long: // reuses local variables
2209 case FloatTop:
2210 case FloatCon:
2211 case FloatBot:
2212 case DoubleTop:
2213 case DoubleCon:
2214 case DoubleBot:
2215 case NarrowOop:
2216 case NarrowKlass:
2217 case Bottom: // Ye Olde Default
2218 return Type::BOTTOM;
2219 case Top:
2220 return this;
2221
2222 case AnyPtr: { // Meeting to AnyPtrs
2223 const TypePtr *tp = t->is_ptr();
2224 return make( AnyPtr, meet_ptr(tp->ptr()), meet_offset(tp->offset()) );
2225 }
2226 case RawPtr: // For these, flip the call around to cut down
2227 case OopPtr:
2228 case InstPtr: // on the cases I have to handle.
2229 case AryPtr:
2230 case MetadataPtr:
2231 case KlassPtr:
2232 return t->xmeet(this); // Call in reverse direction
2233 default: // All else is a mistake
2234 typerr(t);
2235
2236 }
2237 return this;
2238 }
2239
2240 //------------------------------meet_offset------------------------------------
2241 int TypePtr::meet_offset( int offset ) const {
2242 // Either is 'TOP' offset? Return the other offset!
2243 if( _offset == OffsetTop ) return offset;
2244 if( offset == OffsetTop ) return _offset;
2245 // If either is different, return 'BOTTOM' offset
2246 if( _offset != offset ) return OffsetBot;
2247 return _offset;
2248 }
2249
2250 //------------------------------dual_offset------------------------------------
2251 int TypePtr::dual_offset( ) const {
2252 if( _offset == OffsetTop ) return OffsetBot;// Map 'TOP' into 'BOTTOM'
2253 if( _offset == OffsetBot ) return OffsetTop;// Map 'BOTTOM' into 'TOP'
2254 return _offset; // Map everything else into self
2255 }
2256
2257 //------------------------------xdual------------------------------------------
2258 // Dual: compute field-by-field dual
2259 const TypePtr::PTR TypePtr::ptr_dual[TypePtr::lastPTR] = {
2260 BotPTR, NotNull, Constant, Null, AnyNull, TopPTR
2261 };
2262 const Type *TypePtr::xdual() const {
2263 return new TypePtr( AnyPtr, dual_ptr(), dual_offset() );
2264 }
2265
2266 //------------------------------xadd_offset------------------------------------
2267 int TypePtr::xadd_offset( intptr_t offset ) const {
2268 // Adding to 'TOP' offset? Return 'TOP'!
2269 if( _offset == OffsetTop || offset == OffsetTop ) return OffsetTop;
2270 // Adding to 'BOTTOM' offset? Return 'BOTTOM'!
2271 if( _offset == OffsetBot || offset == OffsetBot ) return OffsetBot;
2272 // Addition overflows or "accidentally" equals to OffsetTop? Return 'BOTTOM'!
2273 offset += (intptr_t)_offset;
2274 if (offset != (int)offset || offset == OffsetTop) return OffsetBot;
2275
2276 // assert( _offset >= 0 && _offset+offset >= 0, "" );
2277 // It is possible to construct a negative offset during PhaseCCP
2278
2279 return (int)offset; // Sum valid offsets
2280 }
2281
2282 //------------------------------add_offset-------------------------------------
2283 const TypePtr *TypePtr::add_offset( intptr_t offset ) const {
2284 return make( AnyPtr, _ptr, xadd_offset(offset) );
2285 }
2286
2287 //------------------------------eq---------------------------------------------
2288 // Structural equality check for Type representations
2289 bool TypePtr::eq( const Type *t ) const {
2290 const TypePtr *a = (const TypePtr*)t;
2291 return _ptr == a->ptr() && _offset == a->offset();
2292 }
2293
2294 //------------------------------hash-------------------------------------------
2295 // Type-specific hashing function.
2296 int TypePtr::hash(void) const {
2297 return _ptr + _offset;
2298 }
2299
2300 //------------------------------dump2------------------------------------------
2301 const char *const TypePtr::ptr_msg[TypePtr::lastPTR] = {
2302 "TopPTR","AnyNull","Constant","NULL","NotNull","BotPTR"
2303 };
2304
2305 #ifndef PRODUCT
2306 void TypePtr::dump2( Dict &d, uint depth, outputStream *st ) const {
2307 if( _ptr == Null ) st->print("NULL");
2308 else st->print("%s *", ptr_msg[_ptr]);
2309 if( _offset == OffsetTop ) st->print("+top");
2310 else if( _offset == OffsetBot ) st->print("+bot");
2311 else if( _offset ) st->print("+%d", _offset);
2312 }
2313 #endif
2314
2315 //------------------------------singleton--------------------------------------
2316 // TRUE if Type is a singleton type, FALSE otherwise. Singletons are simple
2317 // constants
2318 bool TypePtr::singleton(void) const {
2319 // TopPTR, Null, AnyNull, Constant are all singletons
2320 return (_offset != OffsetBot) && !below_centerline(_ptr);
2321 }
2322
2323 bool TypePtr::empty(void) const {
2324 return (_offset == OffsetTop) || above_centerline(_ptr);
2325 }
2326
2327 //=============================================================================
2328 // Convenience common pre-built types.
2329 const TypeRawPtr *TypeRawPtr::BOTTOM;
2330 const TypeRawPtr *TypeRawPtr::NOTNULL;
2331
2382 }
2383
2384 case OopPtr:
2385 case InstPtr:
2386 case AryPtr:
2387 case MetadataPtr:
2388 case KlassPtr:
2389 return TypePtr::BOTTOM; // Oop meet raw is not well defined
2390 default: // All else is a mistake
2391 typerr(t);
2392 }
2393
2394 // Found an AnyPtr type vs self-RawPtr type
2395 const TypePtr *tp = t->is_ptr();
2396 switch (tp->ptr()) {
2397 case TypePtr::TopPTR: return this;
2398 case TypePtr::BotPTR: return t;
2399 case TypePtr::Null:
2400 if( _ptr == TypePtr::TopPTR ) return t;
2401 return TypeRawPtr::BOTTOM;
2402 case TypePtr::NotNull: return TypePtr::make( AnyPtr, meet_ptr(TypePtr::NotNull), tp->meet_offset(0) );
2403 case TypePtr::AnyNull:
2404 if( _ptr == TypePtr::Constant) return this;
2405 return make( meet_ptr(TypePtr::AnyNull) );
2406 default: ShouldNotReachHere();
2407 }
2408 return this;
2409 }
2410
2411 //------------------------------xdual------------------------------------------
2412 // Dual: compute field-by-field dual
2413 const Type *TypeRawPtr::xdual() const {
2414 return new TypeRawPtr( dual_ptr(), _bits );
2415 }
2416
2417 //------------------------------add_offset-------------------------------------
2418 const TypePtr *TypeRawPtr::add_offset( intptr_t offset ) const {
2419 if( offset == OffsetTop ) return BOTTOM; // Undefined offset-> undefined pointer
2420 if( offset == OffsetBot ) return BOTTOM; // Unknown offset-> unknown pointer
2421 if( offset == 0 ) return this; // No change
2422 switch (_ptr) {
2446 // Type-specific hashing function.
2447 int TypeRawPtr::hash(void) const {
2448 return (intptr_t)_bits + TypePtr::hash();
2449 }
2450
2451 //------------------------------dump2------------------------------------------
2452 #ifndef PRODUCT
2453 void TypeRawPtr::dump2( Dict &d, uint depth, outputStream *st ) const {
2454 if( _ptr == Constant )
2455 st->print(INTPTR_FORMAT, _bits);
2456 else
2457 st->print("rawptr:%s", ptr_msg[_ptr]);
2458 }
2459 #endif
2460
2461 //=============================================================================
2462 // Convenience common pre-built type.
2463 const TypeOopPtr *TypeOopPtr::BOTTOM;
2464
2465 //------------------------------TypeOopPtr-------------------------------------
2466 TypeOopPtr::TypeOopPtr(TYPES t, PTR ptr, ciKlass* k, bool xk, ciObject* o, int offset, int instance_id, const TypeOopPtr* speculative, int inline_depth)
2467 : TypePtr(t, ptr, offset),
2468 _const_oop(o), _klass(k),
2469 _klass_is_exact(xk),
2470 _is_ptr_to_narrowoop(false),
2471 _is_ptr_to_narrowklass(false),
2472 _is_ptr_to_boxed_value(false),
2473 _instance_id(instance_id),
2474 _speculative(speculative),
2475 _inline_depth(inline_depth){
2476 if (Compile::current()->eliminate_boxing() && (t == InstPtr) &&
2477 (offset > 0) && xk && (k != 0) && k->is_instance_klass()) {
2478 _is_ptr_to_boxed_value = k->as_instance_klass()->is_boxed_value_offset(offset);
2479 }
2480 #ifdef _LP64
2481 if (_offset != 0) {
2482 if (_offset == oopDesc::klass_offset_in_bytes()) {
2483 _is_ptr_to_narrowklass = UseCompressedClassPointers;
2484 } else if (klass() == NULL) {
2485 // Array with unknown body type
2486 assert(this->isa_aryptr(), "only arrays without klass");
2487 _is_ptr_to_narrowoop = UseCompressedOops;
2488 } else if (this->isa_aryptr()) {
2489 _is_ptr_to_narrowoop = (UseCompressedOops && klass()->is_obj_array_klass() &&
2490 _offset != arrayOopDesc::length_offset_in_bytes());
2491 } else if (klass()->is_instance_klass()) {
2492 ciInstanceKlass* ik = klass()->as_instance_klass();
2493 ciField* field = NULL;
2494 if (this->isa_klassptr()) {
2495 // Perm objects don't use compressed references
2521 if (field != NULL) {
2522 BasicType basic_elem_type = field->layout_type();
2523 _is_ptr_to_narrowoop = UseCompressedOops && (basic_elem_type == T_OBJECT ||
2524 basic_elem_type == T_ARRAY);
2525 } else if (klass()->equals(ciEnv::current()->Object_klass())) {
2526 // Compile::find_alias_type() cast exactness on all types to verify
2527 // that it does not affect alias type.
2528 _is_ptr_to_narrowoop = UseCompressedOops;
2529 } else {
2530 // Type for the copy start in LibraryCallKit::inline_native_clone().
2531 _is_ptr_to_narrowoop = UseCompressedOops;
2532 }
2533 }
2534 }
2535 }
2536 }
2537 #endif
2538 }
2539
2540 //------------------------------make-------------------------------------------
2541 const TypeOopPtr *TypeOopPtr::make(PTR ptr,
2542 int offset, int instance_id, const TypeOopPtr* speculative, int inline_depth) {
2543 assert(ptr != Constant, "no constant generic pointers");
2544 ciKlass* k = Compile::current()->env()->Object_klass();
2545 bool xk = false;
2546 ciObject* o = NULL;
2547 return (TypeOopPtr*)(new TypeOopPtr(OopPtr, ptr, k, xk, o, offset, instance_id, speculative, inline_depth))->hashcons();
2548 }
2549
2550
2551 //------------------------------cast_to_ptr_type-------------------------------
2552 const Type *TypeOopPtr::cast_to_ptr_type(PTR ptr) const {
2553 assert(_base == OopPtr, "subclass must override cast_to_ptr_type");
2554 if( ptr == _ptr ) return this;
2555 return make(ptr, _offset, _instance_id, _speculative, _inline_depth);
2556 }
2557
2558 //-----------------------------cast_to_instance_id----------------------------
2559 const TypeOopPtr *TypeOopPtr::cast_to_instance_id(int instance_id) const {
2560 // There are no instances of a general oop.
2561 // Return self unchanged.
2562 return this;
2565 //-----------------------------cast_to_exactness-------------------------------
2566 const Type *TypeOopPtr::cast_to_exactness(bool klass_is_exact) const {
2567 // There is no such thing as an exact general oop.
2568 // Return self unchanged.
2569 return this;
2570 }
2571
2572
2573 //------------------------------as_klass_type----------------------------------
2574 // Return the klass type corresponding to this instance or array type.
2575 // It is the type that is loaded from an object of this type.
2576 const TypeKlassPtr* TypeOopPtr::as_klass_type() const {
2577 ciKlass* k = klass();
2578 bool xk = klass_is_exact();
2579 if (k == NULL)
2580 return TypeKlassPtr::OBJECT;
2581 else
2582 return TypeKlassPtr::make(xk? Constant: NotNull, k, 0);
2583 }
2584
2585 const Type *TypeOopPtr::xmeet(const Type *t) const {
2586 const Type* res = xmeet_helper(t);
2587 if (res->isa_oopptr() == NULL) {
2588 return res;
2589 }
2590
2591 const TypeOopPtr* res_oopptr = res->is_oopptr();
2592 if (res_oopptr->speculative() != NULL) {
2593 // type->speculative() == NULL means that speculation is no better
2594 // than type, i.e. type->speculative() == type. So there are 2
2595 // ways to represent the fact that we have no useful speculative
2596 // data and we should use a single one to be able to test for
2597 // equality between types. Check whether type->speculative() ==
2598 // type and set speculative to NULL if it is the case.
2599 if (res_oopptr->remove_speculative() == res_oopptr->speculative()) {
2600 return res_oopptr->remove_speculative();
2601 }
2602 }
2603
2604 return res;
2605 }
2606
2607 //------------------------------meet-------------------------------------------
2608 // Compute the MEET of two types. It returns a new Type object.
2609 const Type *TypeOopPtr::xmeet_helper(const Type *t) const {
2610 // Perform a fast test for common case; meeting the same types together.
2611 if( this == t ) return this; // Meeting same type-rep?
2612
2613 // Current "this->_base" is OopPtr
2614 switch (t->base()) { // switch on original type
2615
2616 case Int: // Mixing ints & oops happens when javac
2617 case Long: // reuses local variables
2618 case FloatTop:
2619 case FloatCon:
2620 case FloatBot:
2621 case DoubleTop:
2622 case DoubleCon:
2623 case DoubleBot:
2624 case NarrowOop:
2625 case NarrowKlass:
2626 case Bottom: // Ye Olde Default
2627 return Type::BOTTOM;
2628 case Top:
2629 return this;
2630
2631 default: // All else is a mistake
2632 typerr(t);
2633
2634 case RawPtr:
2635 case MetadataPtr:
2636 case KlassPtr:
2637 return TypePtr::BOTTOM; // Oop meet raw is not well defined
2638
2639 case AnyPtr: {
2640 // Found an AnyPtr type vs self-OopPtr type
2641 const TypePtr *tp = t->is_ptr();
2642 int offset = meet_offset(tp->offset());
2643 PTR ptr = meet_ptr(tp->ptr());
2644 switch (tp->ptr()) {
2645 case Null:
2646 if (ptr == Null) return TypePtr::make(AnyPtr, ptr, offset);
2647 // else fall through:
2648 case TopPTR:
2649 case AnyNull: {
2650 int instance_id = meet_instance_id(InstanceTop);
2651 const TypeOopPtr* speculative = _speculative;
2652 return make(ptr, offset, instance_id, speculative, _inline_depth);
2653 }
2654 case BotPTR:
2655 case NotNull:
2656 return TypePtr::make(AnyPtr, ptr, offset);
2657 default: typerr(t);
2658 }
2659 }
2660
2661 case OopPtr: { // Meeting to other OopPtrs
2662 const TypeOopPtr *tp = t->is_oopptr();
2663 int instance_id = meet_instance_id(tp->instance_id());
2664 const TypeOopPtr* speculative = xmeet_speculative(tp);
2665 int depth = meet_inline_depth(tp->inline_depth());
2666 return make(meet_ptr(tp->ptr()), meet_offset(tp->offset()), instance_id, speculative, depth);
2667 }
2668
2669 case InstPtr: // For these, flip the call around to cut down
2670 case AryPtr:
2671 return t->xmeet(this); // Call in reverse direction
2672
2673 } // End of switch
2674 return this; // Return the double constant
2675 }
2676
2677
2678 //------------------------------xdual------------------------------------------
2679 // Dual of a pure heap pointer. No relevant klass or oop information.
2680 const Type *TypeOopPtr::xdual() const {
2681 assert(klass() == Compile::current()->env()->Object_klass(), "no klasses here");
2682 assert(const_oop() == NULL, "no constants here");
2683 return new TypeOopPtr(_base, dual_ptr(), klass(), klass_is_exact(), const_oop(), dual_offset(), dual_instance_id(), dual_speculative(), dual_inline_depth());
2684 }
2842 // the join should report back the class. However, if we have a J/L/Object
2843 // class-typed Phi and an interface flows in, it's possible that the meet &
2844 // join report an interface back out. This isn't possible but happens
2845 // because the type system doesn't interact well with interfaces.
2846 if (ftip != NULL && ktip != NULL &&
2847 ftip->is_loaded() && ftip->klass()->is_interface() &&
2848 ktip->is_loaded() && !ktip->klass()->is_interface()) {
2849 // Happens in a CTW of rt.jar, 320-341, no extra flags
2850 assert(!ftip->klass_is_exact(), "interface could not be exact");
2851 return ktip->cast_to_ptr_type(ftip->ptr());
2852 }
2853
2854 return ft;
2855 }
2856
2857 //------------------------------eq---------------------------------------------
2858 // Structural equality check for Type representations
2859 bool TypeOopPtr::eq( const Type *t ) const {
2860 const TypeOopPtr *a = (const TypeOopPtr*)t;
2861 if (_klass_is_exact != a->_klass_is_exact ||
2862 _instance_id != a->_instance_id ||
2863 !eq_speculative(a) ||
2864 _inline_depth != a->_inline_depth) return false;
2865 ciObject* one = const_oop();
2866 ciObject* two = a->const_oop();
2867 if (one == NULL || two == NULL) {
2868 return (one == two) && TypePtr::eq(t);
2869 } else {
2870 return one->equals(two) && TypePtr::eq(t);
2871 }
2872 }
2873
2874 //------------------------------hash-------------------------------------------
2875 // Type-specific hashing function.
2876 int TypeOopPtr::hash(void) const {
2877 return
2878 (const_oop() ? const_oop()->hash() : 0) +
2879 _klass_is_exact +
2880 _instance_id +
2881 hash_speculative() +
2882 _inline_depth +
2883 TypePtr::hash();
2884 }
2885
2886 //------------------------------dump2------------------------------------------
2887 #ifndef PRODUCT
2888 void TypeOopPtr::dump2( Dict &d, uint depth, outputStream *st ) const {
2889 st->print("oopptr:%s", ptr_msg[_ptr]);
2890 if( _klass_is_exact ) st->print(":exact");
2891 if( const_oop() ) st->print(INTPTR_FORMAT, const_oop());
2892 switch( _offset ) {
2893 case OffsetTop: st->print("+top"); break;
2894 case OffsetBot: st->print("+any"); break;
2895 case 0: break;
2896 default: st->print("+%d",_offset); break;
2897 }
2898 if (_instance_id == InstanceTop)
2899 st->print(",iid=top");
2900 else if (_instance_id != InstanceBot)
2901 st->print(",iid=%d",_instance_id);
2902
2903 dump_inline_depth(st);
2904 dump_speculative(st);
2905 }
2906
2907 /**
2908 *dump the speculative part of the type
2909 */
2910 void TypeOopPtr::dump_speculative(outputStream *st) const {
2911 if (_speculative != NULL) {
2912 st->print(" (speculative=");
2913 _speculative->dump_on(st);
2914 st->print(")");
2915 }
2916 }
2917
2918 void TypeOopPtr::dump_inline_depth(outputStream *st) const {
2919 if (_inline_depth != InlineDepthBottom) {
2920 if (_inline_depth == InlineDepthTop) {
2921 st->print(" (inline_depth=InlineDepthTop)");
2922 } else {
2923 st->print(" (inline_depth=%d)", _inline_depth);
2924 }
2925 }
2926 }
2927 #endif
2928
2929 //------------------------------singleton--------------------------------------
2930 // TRUE if Type is a singleton type, FALSE otherwise. Singletons are simple
2931 // constants
2932 bool TypeOopPtr::singleton(void) const {
2933 // detune optimizer to not generate constant oop + constant offset as a constant!
2934 // TopPTR, Null, AnyNull, Constant are all singletons
2935 return (_offset == 0) && !below_centerline(_ptr);
2936 }
2937
2938 //------------------------------add_offset-------------------------------------
2939 const TypePtr *TypeOopPtr::add_offset(intptr_t offset) const {
2940 return make(_ptr, xadd_offset(offset), _instance_id, add_offset_speculative(offset), _inline_depth);
2941 }
2942
2943 /**
2944 * Return same type without a speculative part
2945 */
2946 const Type* TypeOopPtr::remove_speculative() const {
2947 if (_speculative == NULL) {
2948 return this;
2949 }
2950 assert(_inline_depth == InlineDepthTop || _inline_depth == InlineDepthBottom, "non speculative type shouldn't have inline depth");
2951 return make(_ptr, _offset, _instance_id, NULL, _inline_depth);
2952 }
2953
2954 /**
2955 * Return same type but with a different inline depth (used for speculation)
2956 *
2957 * @param depth depth to meet with
2958 */
2959 const TypeOopPtr* TypeOopPtr::with_inline_depth(int depth) const {
2960 if (!UseInlineDepthForSpeculativeTypes) {
2961 return this;
2962 }
2963 return make(_ptr, _offset, _instance_id, _speculative, depth);
2964 }
2965
2966 /**
2967 * Check whether new profiling would improve speculative type
2968 *
2969 * @param exact_kls class from profiling
2970 * @param inline_depth inlining depth of profile point
2971 *
2972 * @return true if type profile is valuable
2973 */
2974 bool TypeOopPtr::would_improve_type(ciKlass* exact_kls, int inline_depth) const {
2975 // no way to improve an already exact type
2976 if (klass_is_exact()) {
2977 return false;
2978 }
2979 // no profiling?
2980 if (exact_kls == NULL) {
2981 return false;
2982 }
2983 // no speculative type or non exact speculative type?
2984 if (speculative_type() == NULL) {
2985 return true;
2986 }
2987 // If the node already has an exact speculative type keep it,
2988 // unless it was provided by profiling that is at a deeper
2989 // inlining level. Profiling at a higher inlining depth is
2990 // expected to be less accurate.
2991 if (_speculative->inline_depth() == InlineDepthBottom) {
2992 return false;
2993 }
2994 assert(_speculative->inline_depth() != InlineDepthTop, "can't do the comparison");
2995 return inline_depth < _speculative->inline_depth();
2996 }
2997
2998 //------------------------------meet_instance_id--------------------------------
2999 int TypeOopPtr::meet_instance_id( int instance_id ) const {
3000 // Either is 'TOP' instance? Return the other instance!
3001 if( _instance_id == InstanceTop ) return instance_id;
3002 if( instance_id == InstanceTop ) return _instance_id;
3003 // If either is different, return 'BOTTOM' instance
3004 if( _instance_id != instance_id ) return InstanceBot;
3005 return _instance_id;
3006 }
3007
3008 //------------------------------dual_instance_id--------------------------------
3009 int TypeOopPtr::dual_instance_id( ) const {
3010 if( _instance_id == InstanceTop ) return InstanceBot; // Map TOP into BOTTOM
3011 if( _instance_id == InstanceBot ) return InstanceTop; // Map BOTTOM into TOP
3012 return _instance_id; // Map everything else into self
3013 }
3014
3015 /**
3016 * meet of the speculative parts of 2 types
3017 *
3018 * @param other type to meet with
3019 */
3020 const TypeOopPtr* TypeOopPtr::xmeet_speculative(const TypeOopPtr* other) const {
3021 bool this_has_spec = (_speculative != NULL);
3022 bool other_has_spec = (other->speculative() != NULL);
3023
3024 if (!this_has_spec && !other_has_spec) {
3025 return NULL;
3026 }
3027
3028 // If we are at a point where control flow meets and one branch has
3029 // a speculative type and the other has not, we meet the speculative
3030 // type of one branch with the actual type of the other. If the
3031 // actual type is exact and the speculative is as well, then the
3032 // result is a speculative type which is exact and we can continue
3033 // speculation further.
3034 const TypeOopPtr* this_spec = _speculative;
3035 const TypeOopPtr* other_spec = other->speculative();
3036
3037 if (!this_has_spec) {
3038 this_spec = this;
3039 }
3040
3041 if (!other_has_spec) {
3042 other_spec = other;
3043 }
3044
3045 return this_spec->meet_speculative(other_spec)->is_oopptr();
3046 }
3047
3048 /**
3049 * dual of the speculative part of the type
3050 */
3051 const TypeOopPtr* TypeOopPtr::dual_speculative() const {
3052 if (_speculative == NULL) {
3053 return NULL;
3054 }
3055 return _speculative->dual()->is_oopptr();
3056 }
3057
3058 /**
3059 * add offset to the speculative part of the type
3060 *
3061 * @param offset offset to add
3062 */
3063 const TypeOopPtr* TypeOopPtr::add_offset_speculative(intptr_t offset) const {
3064 if (_speculative == NULL) {
3065 return NULL;
3066 }
3067 return _speculative->add_offset(offset)->is_oopptr();
3068 }
3069
3070 /**
3071 * Are the speculative parts of 2 types equal?
3072 *
3073 * @param other type to compare this one to
3074 */
3075 bool TypeOopPtr::eq_speculative(const TypeOopPtr* other) const {
3076 if (_speculative == NULL || other->speculative() == NULL) {
3077 return _speculative == other->speculative();
3078 }
3079
3080 if (_speculative->base() != other->speculative()->base()) {
3081 return false;
3082 }
3083
3084 return _speculative->eq(other->speculative());
3085 }
3086
3087 /**
3088 * Hash of the speculative part of the type
3089 */
3090 int TypeOopPtr::hash_speculative() const {
3091 if (_speculative == NULL) {
3092 return 0;
3093 }
3094
3095 return _speculative->hash();
3096 }
3097
3098 /**
3099 * dual of the inline depth for this type (used for speculation)
3100 */
3101 int TypeOopPtr::dual_inline_depth() const {
3102 return -inline_depth();
3103 }
3104
3105 /**
3106 * meet of 2 inline depth (used for speculation)
3107 *
3108 * @param depth depth to meet with
3109 */
3110 int TypeOopPtr::meet_inline_depth(int depth) const {
3111 return MAX2(inline_depth(), depth);
3112 }
3113
3114 //=============================================================================
3115 // Convenience common pre-built types.
3116 const TypeInstPtr *TypeInstPtr::NOTNULL;
3117 const TypeInstPtr *TypeInstPtr::BOTTOM;
3118 const TypeInstPtr *TypeInstPtr::MIRROR;
3119 const TypeInstPtr *TypeInstPtr::MARK;
3120 const TypeInstPtr *TypeInstPtr::KLASS;
3121
3122 //------------------------------TypeInstPtr-------------------------------------
3123 TypeInstPtr::TypeInstPtr(PTR ptr, ciKlass* k, bool xk, ciObject* o, int off, int instance_id, const TypeOopPtr* speculative, int inline_depth)
3124 : TypeOopPtr(InstPtr, ptr, k, xk, o, off, instance_id, speculative, inline_depth), _name(k->name()) {
3125 assert(k != NULL &&
3126 (k->is_loaded() || o == NULL),
3127 "cannot have constants with non-loaded klass");
3128 };
3129
3130 //------------------------------make-------------------------------------------
3131 const TypeInstPtr *TypeInstPtr::make(PTR ptr,
3132 ciKlass* k,
3133 bool xk,
3134 ciObject* o,
3135 int offset,
3136 int instance_id,
3137 const TypeOopPtr* speculative,
3138 int inline_depth) {
3139 assert( !k->is_loaded() || k->is_instance_klass(), "Must be for instance");
3140 // Either const_oop() is NULL or else ptr is Constant
3141 assert( (!o && ptr != Constant) || (o && ptr == Constant),
3142 "constant pointers must have a value supplied" );
3143 // Ptr is never Null
3144 assert( ptr != Null, "NULL pointers are not typed" );
3145
3146 assert(instance_id <= 0 || xk || !UseExactTypes, "instances are always exactly typed");
3147 if (!UseExactTypes) xk = false;
3148 if (ptr == Constant) {
3149 // Note: This case includes meta-object constants, such as methods.
3150 xk = true;
3151 } else if (k->is_loaded()) {
3152 ciInstanceKlass* ik = k->as_instance_klass();
3153 if (!xk && ik->is_final()) xk = true; // no inexact final klass
3154 if (xk && ik->is_interface()) xk = false; // no exact interface
3155 }
3156
3157 // Now hash this baby
3200 if (!_klass->is_loaded()) return this;
3201 ciInstanceKlass* ik = _klass->as_instance_klass();
3202 if( (ik->is_final() || _const_oop) ) return this; // cannot clear xk
3203 if( ik->is_interface() ) return this; // cannot set xk
3204 return make(ptr(), klass(), klass_is_exact, const_oop(), _offset, _instance_id, _speculative, _inline_depth);
3205 }
3206
3207 //-----------------------------cast_to_instance_id----------------------------
3208 const TypeOopPtr *TypeInstPtr::cast_to_instance_id(int instance_id) const {
3209 if( instance_id == _instance_id ) return this;
3210 return make(_ptr, klass(), _klass_is_exact, const_oop(), _offset, instance_id, _speculative, _inline_depth);
3211 }
3212
3213 //------------------------------xmeet_unloaded---------------------------------
3214 // Compute the MEET of two InstPtrs when at least one is unloaded.
3215 // Assume classes are different since called after check for same name/class-loader
3216 const TypeInstPtr *TypeInstPtr::xmeet_unloaded(const TypeInstPtr *tinst) const {
3217 int off = meet_offset(tinst->offset());
3218 PTR ptr = meet_ptr(tinst->ptr());
3219 int instance_id = meet_instance_id(tinst->instance_id());
3220 const TypeOopPtr* speculative = xmeet_speculative(tinst);
3221 int depth = meet_inline_depth(tinst->inline_depth());
3222
3223 const TypeInstPtr *loaded = is_loaded() ? this : tinst;
3224 const TypeInstPtr *unloaded = is_loaded() ? tinst : this;
3225 if( loaded->klass()->equals(ciEnv::current()->Object_klass()) ) {
3226 //
3227 // Meet unloaded class with java/lang/Object
3228 //
3229 // Meet
3230 // | Unloaded Class
3231 // Object | TOP | AnyNull | Constant | NotNull | BOTTOM |
3232 // ===================================================================
3233 // TOP | ..........................Unloaded......................|
3234 // AnyNull | U-AN |................Unloaded......................|
3235 // Constant | ... O-NN .................................. | O-BOT |
3236 // NotNull | ... O-NN .................................. | O-BOT |
3237 // BOTTOM | ........................Object-BOTTOM ..................|
3238 //
3239 assert(loaded->ptr() != TypePtr::Null, "insanity check");
3240 //
3278 case DoubleBot:
3279 case NarrowOop:
3280 case NarrowKlass:
3281 case Bottom: // Ye Olde Default
3282 return Type::BOTTOM;
3283 case Top:
3284 return this;
3285
3286 default: // All else is a mistake
3287 typerr(t);
3288
3289 case MetadataPtr:
3290 case KlassPtr:
3291 case RawPtr: return TypePtr::BOTTOM;
3292
3293 case AryPtr: { // All arrays inherit from Object class
3294 const TypeAryPtr *tp = t->is_aryptr();
3295 int offset = meet_offset(tp->offset());
3296 PTR ptr = meet_ptr(tp->ptr());
3297 int instance_id = meet_instance_id(tp->instance_id());
3298 const TypeOopPtr* speculative = xmeet_speculative(tp);
3299 int depth = meet_inline_depth(tp->inline_depth());
3300 switch (ptr) {
3301 case TopPTR:
3302 case AnyNull: // Fall 'down' to dual of object klass
3303 // For instances when a subclass meets a superclass we fall
3304 // below the centerline when the superclass is exact. We need to
3305 // do the same here.
3306 if (klass()->equals(ciEnv::current()->Object_klass()) && !klass_is_exact()) {
3307 return TypeAryPtr::make(ptr, tp->ary(), tp->klass(), tp->klass_is_exact(), offset, instance_id, speculative, depth);
3308 } else {
3309 // cannot subclass, so the meet has to fall badly below the centerline
3310 ptr = NotNull;
3311 instance_id = InstanceBot;
3312 return TypeInstPtr::make( ptr, ciEnv::current()->Object_klass(), false, NULL, offset, instance_id, speculative, depth);
3313 }
3314 case Constant:
3315 case NotNull:
3316 case BotPTR: // Fall down to object klass
3317 // LCA is object_klass, but if we subclass from the top we can do better
3318 if( above_centerline(_ptr) ) { // if( _ptr == TopPTR || _ptr == AnyNull )
3329 }
3330 // The other case cannot happen, since I cannot be a subtype of an array.
3331 // The meet falls down to Object class below centerline.
3332 if( ptr == Constant )
3333 ptr = NotNull;
3334 instance_id = InstanceBot;
3335 return make(ptr, ciEnv::current()->Object_klass(), false, NULL, offset, instance_id, speculative, depth);
3336 default: typerr(t);
3337 }
3338 }
3339
3340 case OopPtr: { // Meeting to OopPtrs
3341 // Found a OopPtr type vs self-InstPtr type
3342 const TypeOopPtr *tp = t->is_oopptr();
3343 int offset = meet_offset(tp->offset());
3344 PTR ptr = meet_ptr(tp->ptr());
3345 switch (tp->ptr()) {
3346 case TopPTR:
3347 case AnyNull: {
3348 int instance_id = meet_instance_id(InstanceTop);
3349 const TypeOopPtr* speculative = xmeet_speculative(tp);
3350 int depth = meet_inline_depth(tp->inline_depth());
3351 return make(ptr, klass(), klass_is_exact(),
3352 (ptr == Constant ? const_oop() : NULL), offset, instance_id, speculative, depth);
3353 }
3354 case NotNull:
3355 case BotPTR: {
3356 int instance_id = meet_instance_id(tp->instance_id());
3357 const TypeOopPtr* speculative = xmeet_speculative(tp);
3358 int depth = meet_inline_depth(tp->inline_depth());
3359 return TypeOopPtr::make(ptr, offset, instance_id, speculative, depth);
3360 }
3361 default: typerr(t);
3362 }
3363 }
3364
3365 case AnyPtr: { // Meeting to AnyPtrs
3366 // Found an AnyPtr type vs self-InstPtr type
3367 const TypePtr *tp = t->is_ptr();
3368 int offset = meet_offset(tp->offset());
3369 PTR ptr = meet_ptr(tp->ptr());
3370 switch (tp->ptr()) {
3371 case Null:
3372 if( ptr == Null ) return TypePtr::make(AnyPtr, ptr, offset);
3373 // else fall through to AnyNull
3374 case TopPTR:
3375 case AnyNull: {
3376 int instance_id = meet_instance_id(InstanceTop);
3377 const TypeOopPtr* speculative = _speculative;
3378 return make(ptr, klass(), klass_is_exact(),
3379 (ptr == Constant ? const_oop() : NULL), offset, instance_id, speculative, _inline_depth);
3380 }
3381 case NotNull:
3382 case BotPTR:
3383 return TypePtr::make(AnyPtr, ptr, offset);
3384 default: typerr(t);
3385 }
3386 }
3387
3388 /*
3389 A-top }
3390 / | \ } Tops
3391 B-top A-any C-top }
3392 | / | \ | } Any-nulls
3393 B-any | C-any }
3394 | | |
3395 B-con A-con C-con } constants; not comparable across classes
3396 | | |
3397 B-not | C-not }
3398 | \ | / | } not-nulls
3399 B-bot A-not C-bot }
3400 \ | / } Bottoms
3401 A-bot }
3402 */
3403
3404 case InstPtr: { // Meeting 2 Oops?
3405 // Found an InstPtr sub-type vs self-InstPtr type
3406 const TypeInstPtr *tinst = t->is_instptr();
3407 int off = meet_offset( tinst->offset() );
3408 PTR ptr = meet_ptr( tinst->ptr() );
3409 int instance_id = meet_instance_id(tinst->instance_id());
3410 const TypeOopPtr* speculative = xmeet_speculative(tinst);
3411 int depth = meet_inline_depth(tinst->inline_depth());
3412
3413 // Check for easy case; klasses are equal (and perhaps not loaded!)
3414 // If we have constants, then we created oops so classes are loaded
3415 // and we can handle the constants further down. This case handles
3416 // both-not-loaded or both-loaded classes
3417 if (ptr != Constant && klass()->equals(tinst->klass()) && klass_is_exact() == tinst->klass_is_exact()) {
3418 return make(ptr, klass(), klass_is_exact(), NULL, off, instance_id, speculative, depth);
3419 }
3420
3421 // Classes require inspection in the Java klass hierarchy. Must be loaded.
3422 ciKlass* tinst_klass = tinst->klass();
3423 ciKlass* this_klass = this->klass();
3424 bool tinst_xk = tinst->klass_is_exact();
3425 bool this_xk = this->klass_is_exact();
3426 if (!tinst_klass->is_loaded() || !this_klass->is_loaded() ) {
3427 // One of these classes has not been loaded
3428 const TypeInstPtr *unloaded_meet = xmeet_unloaded(tinst);
3429 #ifndef PRODUCT
3430 if( PrintOpto && Verbose ) {
3546 ciObject* this_oop = const_oop();
3547 ciObject* tinst_oop = tinst->const_oop();
3548 if( ptr == Constant ) {
3549 if (this_oop != NULL && tinst_oop != NULL &&
3550 this_oop->equals(tinst_oop) )
3551 o = this_oop;
3552 else if (above_centerline(this ->_ptr))
3553 o = tinst_oop;
3554 else if (above_centerline(tinst ->_ptr))
3555 o = this_oop;
3556 else
3557 ptr = NotNull;
3558 }
3559 return make(ptr, this_klass, this_xk, o, off, instance_id, speculative, depth);
3560 } // Else classes are not equal
3561
3562 // Since klasses are different, we require a LCA in the Java
3563 // class hierarchy - which means we have to fall to at least NotNull.
3564 if( ptr == TopPTR || ptr == AnyNull || ptr == Constant )
3565 ptr = NotNull;
3566 instance_id = InstanceBot;
3567
3568 // Now we find the LCA of Java classes
3569 ciKlass* k = this_klass->least_common_ancestor(tinst_klass);
3570 return make(ptr, k, false, NULL, off, instance_id, speculative, depth);
3571 } // End of case InstPtr
3572
3573 } // End of switch
3574 return this; // Return the double constant
3575 }
3576
3577
3578 //------------------------java_mirror_type--------------------------------------
3579 ciType* TypeInstPtr::java_mirror_type() const {
3580 // must be a singleton type
3581 if( const_oop() == NULL ) return NULL;
3582
3583 // must be of type java.lang.Class
3584 if( klass() != ciEnv::current()->Class_klass() ) return NULL;
3585
3638
3639 if( _offset ) { // Dump offset, if any
3640 if( _offset == OffsetBot ) st->print("+any");
3641 else if( _offset == OffsetTop ) st->print("+unknown");
3642 else st->print("+%d", _offset);
3643 }
3644
3645 st->print(" *");
3646 if (_instance_id == InstanceTop)
3647 st->print(",iid=top");
3648 else if (_instance_id != InstanceBot)
3649 st->print(",iid=%d",_instance_id);
3650
3651 dump_inline_depth(st);
3652 dump_speculative(st);
3653 }
3654 #endif
3655
3656 //------------------------------add_offset-------------------------------------
3657 const TypePtr *TypeInstPtr::add_offset(intptr_t offset) const {
3658 return make(_ptr, klass(), klass_is_exact(), const_oop(), xadd_offset(offset), _instance_id, add_offset_speculative(offset));
3659 }
3660
3661 const Type *TypeInstPtr::remove_speculative() const {
3662 if (_speculative == NULL) {
3663 return this;
3664 }
3665 assert(_inline_depth == InlineDepthTop || _inline_depth == InlineDepthBottom, "non speculative type shouldn't have inline depth");
3666 return make(_ptr, klass(), klass_is_exact(), const_oop(), _offset, _instance_id, NULL, _inline_depth);
3667 }
3668
3669 const TypeOopPtr *TypeInstPtr::with_inline_depth(int depth) const {
3670 if (!UseInlineDepthForSpeculativeTypes) {
3671 return this;
3672 }
3673 return make(_ptr, klass(), klass_is_exact(), const_oop(), _offset, _instance_id, _speculative, depth);
3674 }
3675
3676 //=============================================================================
3677 // Convenience common pre-built types.
3678 const TypeAryPtr *TypeAryPtr::RANGE;
3679 const TypeAryPtr *TypeAryPtr::OOPS;
3680 const TypeAryPtr *TypeAryPtr::NARROWOOPS;
3681 const TypeAryPtr *TypeAryPtr::BYTES;
3682 const TypeAryPtr *TypeAryPtr::SHORTS;
3683 const TypeAryPtr *TypeAryPtr::CHARS;
3684 const TypeAryPtr *TypeAryPtr::INTS;
3685 const TypeAryPtr *TypeAryPtr::LONGS;
3686 const TypeAryPtr *TypeAryPtr::FLOATS;
3687 const TypeAryPtr *TypeAryPtr::DOUBLES;
3688
3689 //------------------------------make-------------------------------------------
3690 const TypeAryPtr *TypeAryPtr::make(PTR ptr, const TypeAry *ary, ciKlass* k, bool xk, int offset, int instance_id, const TypeOopPtr* speculative, int inline_depth) {
3691 assert(!(k == NULL && ary->_elem->isa_int()),
3692 "integral arrays must be pre-equipped with a class");
3693 if (!xk) xk = ary->ary_must_be_exact();
3694 assert(instance_id <= 0 || xk || !UseExactTypes, "instances are always exactly typed");
3695 if (!UseExactTypes) xk = (ptr == Constant);
3696 return (TypeAryPtr*)(new TypeAryPtr(ptr, NULL, ary, k, xk, offset, instance_id, false, speculative, inline_depth))->hashcons();
3697 }
3698
3699 //------------------------------make-------------------------------------------
3700 const TypeAryPtr *TypeAryPtr::make(PTR ptr, ciObject* o, const TypeAry *ary, ciKlass* k, bool xk, int offset, int instance_id, const TypeOopPtr* speculative, int inline_depth, bool is_autobox_cache) {
3701 assert(!(k == NULL && ary->_elem->isa_int()),
3702 "integral arrays must be pre-equipped with a class");
3703 assert( (ptr==Constant && o) || (ptr!=Constant && !o), "" );
3704 if (!xk) xk = (o != NULL) || ary->ary_must_be_exact();
3705 assert(instance_id <= 0 || xk || !UseExactTypes, "instances are always exactly typed");
3706 if (!UseExactTypes) xk = (ptr == Constant);
3707 return (TypeAryPtr*)(new TypeAryPtr(ptr, o, ary, k, xk, offset, instance_id, is_autobox_cache, speculative, inline_depth))->hashcons();
3708 }
3709
3710 //------------------------------cast_to_ptr_type-------------------------------
3711 const Type *TypeAryPtr::cast_to_ptr_type(PTR ptr) const {
3712 if( ptr == _ptr ) return this;
3713 return make(ptr, const_oop(), _ary, klass(), klass_is_exact(), _offset, _instance_id, _speculative, _inline_depth);
3714 }
3715
3716
3717 //-----------------------------cast_to_exactness-------------------------------
3718 const Type *TypeAryPtr::cast_to_exactness(bool klass_is_exact) const {
3719 if( klass_is_exact == _klass_is_exact ) return this;
3720 if (!UseExactTypes) return this;
3790 const TypeAry* new_ary = TypeAry::make(elem(), new_size, is_stable());
3791 return make(ptr(), const_oop(), new_ary, klass(), klass_is_exact(), _offset, _instance_id, _speculative, _inline_depth);
3792 }
3793
3794
3795 //------------------------------cast_to_stable---------------------------------
3796 const TypeAryPtr* TypeAryPtr::cast_to_stable(bool stable, int stable_dimension) const {
3797 if (stable_dimension <= 0 || (stable_dimension == 1 && stable == this->is_stable()))
3798 return this;
3799
3800 const Type* elem = this->elem();
3801 const TypePtr* elem_ptr = elem->make_ptr();
3802
3803 if (stable_dimension > 1 && elem_ptr != NULL && elem_ptr->isa_aryptr()) {
3804 // If this is widened from a narrow oop, TypeAry::make will re-narrow it.
3805 elem = elem_ptr = elem_ptr->is_aryptr()->cast_to_stable(stable, stable_dimension - 1);
3806 }
3807
3808 const TypeAry* new_ary = TypeAry::make(elem, size(), stable);
3809
3810 return make(ptr(), const_oop(), new_ary, klass(), klass_is_exact(), _offset, _instance_id);
3811 }
3812
3813 //-----------------------------stable_dimension--------------------------------
3814 int TypeAryPtr::stable_dimension() const {
3815 if (!is_stable()) return 0;
3816 int dim = 1;
3817 const TypePtr* elem_ptr = elem()->make_ptr();
3818 if (elem_ptr != NULL && elem_ptr->isa_aryptr())
3819 dim += elem_ptr->is_aryptr()->stable_dimension();
3820 return dim;
3821 }
3822
3823 //------------------------------eq---------------------------------------------
3824 // Structural equality check for Type representations
3825 bool TypeAryPtr::eq( const Type *t ) const {
3826 const TypeAryPtr *p = t->is_aryptr();
3827 return
3828 _ary == p->_ary && // Check array
3829 TypeOopPtr::eq(p); // Check sub-parts
3830 }
3851 case FloatBot:
3852 case DoubleTop:
3853 case DoubleCon:
3854 case DoubleBot:
3855 case NarrowOop:
3856 case NarrowKlass:
3857 case Bottom: // Ye Olde Default
3858 return Type::BOTTOM;
3859 case Top:
3860 return this;
3861
3862 default: // All else is a mistake
3863 typerr(t);
3864
3865 case OopPtr: { // Meeting to OopPtrs
3866 // Found a OopPtr type vs self-AryPtr type
3867 const TypeOopPtr *tp = t->is_oopptr();
3868 int offset = meet_offset(tp->offset());
3869 PTR ptr = meet_ptr(tp->ptr());
3870 int depth = meet_inline_depth(tp->inline_depth());
3871 switch (tp->ptr()) {
3872 case TopPTR:
3873 case AnyNull: {
3874 int instance_id = meet_instance_id(InstanceTop);
3875 const TypeOopPtr* speculative = xmeet_speculative(tp);
3876 return make(ptr, (ptr == Constant ? const_oop() : NULL),
3877 _ary, _klass, _klass_is_exact, offset, instance_id, speculative, depth);
3878 }
3879 case BotPTR:
3880 case NotNull: {
3881 int instance_id = meet_instance_id(tp->instance_id());
3882 const TypeOopPtr* speculative = xmeet_speculative(tp);
3883 return TypeOopPtr::make(ptr, offset, instance_id, speculative, depth);
3884 }
3885 default: ShouldNotReachHere();
3886 }
3887 }
3888
3889 case AnyPtr: { // Meeting two AnyPtrs
3890 // Found an AnyPtr type vs self-AryPtr type
3891 const TypePtr *tp = t->is_ptr();
3892 int offset = meet_offset(tp->offset());
3893 PTR ptr = meet_ptr(tp->ptr());
3894 switch (tp->ptr()) {
3895 case TopPTR:
3896 return this;
3897 case BotPTR:
3898 case NotNull:
3899 return TypePtr::make(AnyPtr, ptr, offset);
3900 case Null:
3901 if( ptr == Null ) return TypePtr::make(AnyPtr, ptr, offset);
3902 // else fall through to AnyNull
3903 case AnyNull: {
3904 int instance_id = meet_instance_id(InstanceTop);
3905 const TypeOopPtr* speculative = _speculative;
3906 return make(ptr, (ptr == Constant ? const_oop() : NULL),
3907 _ary, _klass, _klass_is_exact, offset, instance_id, speculative, _inline_depth);
3908 }
3909 default: ShouldNotReachHere();
3910 }
3911 }
3912
3913 case MetadataPtr:
3914 case KlassPtr:
3915 case RawPtr: return TypePtr::BOTTOM;
3916
3917 case AryPtr: { // Meeting 2 references?
3918 const TypeAryPtr *tap = t->is_aryptr();
3919 int off = meet_offset(tap->offset());
3920 const TypeAry *tary = _ary->meet_speculative(tap->_ary)->is_ary();
3921 PTR ptr = meet_ptr(tap->ptr());
3922 int instance_id = meet_instance_id(tap->instance_id());
3923 const TypeOopPtr* speculative = xmeet_speculative(tap);
3924 int depth = meet_inline_depth(tap->inline_depth());
3925 ciKlass* lazy_klass = NULL;
3926 if (tary->_elem->isa_int()) {
3927 // Integral array element types have irrelevant lattice relations.
3928 // It is the klass that determines array layout, not the element type.
3929 if (_klass == NULL)
3930 lazy_klass = tap->_klass;
3931 else if (tap->_klass == NULL || tap->_klass == _klass) {
3932 lazy_klass = _klass;
3933 } else {
3934 // Something like byte[int+] meets char[int+].
3935 // This must fall to bottom, not (int[-128..65535])[int+].
3936 instance_id = InstanceBot;
3937 tary = TypeAry::make(Type::BOTTOM, tary->_size, tary->_stable);
3938 }
3939 } else // Non integral arrays.
3940 // Must fall to bottom if exact klasses in upper lattice
3941 // are not equal or super klass is exact.
3942 if ((above_centerline(ptr) || ptr == Constant) && klass() != tap->klass() &&
3943 // meet with top[] and bottom[] are processed further down:
3944 tap->_klass != NULL && this->_klass != NULL &&
3945 // both are exact and not equal:
3946 ((tap->_klass_is_exact && this->_klass_is_exact) ||
3947 // 'tap' is exact and super or unrelated:
3948 (tap->_klass_is_exact && !tap->klass()->is_subtype_of(klass())) ||
3949 // 'this' is exact and super or unrelated:
3950 (this->_klass_is_exact && !klass()->is_subtype_of(tap->klass())))) {
3951 tary = TypeAry::make(Type::BOTTOM, tary->_size, tary->_stable);
3952 return make(NotNull, NULL, tary, lazy_klass, false, off, InstanceBot);
3953 }
3954
3955 bool xk = false;
3956 switch (tap->ptr()) {
3957 case AnyNull:
3958 case TopPTR:
3959 // Compute new klass on demand, do not use tap->_klass
3960 if (below_centerline(this->_ptr)) {
3961 xk = this->_klass_is_exact;
3962 } else {
3963 xk = (tap->_klass_is_exact | this->_klass_is_exact);
3964 }
3965 return make(ptr, const_oop(), tary, lazy_klass, xk, off, instance_id, speculative, depth);
3966 case Constant: {
3967 ciObject* o = const_oop();
3968 if( _ptr == Constant ) {
3969 if( tap->const_oop() != NULL && !o->equals(tap->const_oop()) ) {
3970 xk = (klass() == tap->klass());
3971 ptr = NotNull;
3972 o = NULL;
3984 return TypeAryPtr::make(ptr, o, tary, lazy_klass, xk, off, instance_id, speculative, depth);
3985 }
3986 case NotNull:
3987 case BotPTR:
3988 // Compute new klass on demand, do not use tap->_klass
3989 if (above_centerline(this->_ptr))
3990 xk = tap->_klass_is_exact;
3991 else xk = (tap->_klass_is_exact & this->_klass_is_exact) &&
3992 (klass() == tap->klass()); // Only precise for identical arrays
3993 return TypeAryPtr::make(ptr, NULL, tary, lazy_klass, xk, off, instance_id, speculative, depth);
3994 default: ShouldNotReachHere();
3995 }
3996 }
3997
3998 // All arrays inherit from Object class
3999 case InstPtr: {
4000 const TypeInstPtr *tp = t->is_instptr();
4001 int offset = meet_offset(tp->offset());
4002 PTR ptr = meet_ptr(tp->ptr());
4003 int instance_id = meet_instance_id(tp->instance_id());
4004 const TypeOopPtr* speculative = xmeet_speculative(tp);
4005 int depth = meet_inline_depth(tp->inline_depth());
4006 switch (ptr) {
4007 case TopPTR:
4008 case AnyNull: // Fall 'down' to dual of object klass
4009 // For instances when a subclass meets a superclass we fall
4010 // below the centerline when the superclass is exact. We need to
4011 // do the same here.
4012 if (tp->klass()->equals(ciEnv::current()->Object_klass()) && !tp->klass_is_exact()) {
4013 return TypeAryPtr::make(ptr, _ary, _klass, _klass_is_exact, offset, instance_id, speculative, depth);
4014 } else {
4015 // cannot subclass, so the meet has to fall badly below the centerline
4016 ptr = NotNull;
4017 instance_id = InstanceBot;
4018 return TypeInstPtr::make(ptr, ciEnv::current()->Object_klass(), false, NULL,offset, instance_id, speculative, depth);
4019 }
4020 case Constant:
4021 case NotNull:
4022 case BotPTR: // Fall down to object klass
4023 // LCA is object_klass, but if we subclass from the top we can do better
4024 if (above_centerline(tp->ptr())) {
4108 #endif
4109
4110 bool TypeAryPtr::empty(void) const {
4111 if (_ary->empty()) return true;
4112 return TypeOopPtr::empty();
4113 }
4114
4115 //------------------------------add_offset-------------------------------------
4116 const TypePtr *TypeAryPtr::add_offset(intptr_t offset) const {
4117 return make(_ptr, _const_oop, _ary, _klass, _klass_is_exact, xadd_offset(offset), _instance_id, add_offset_speculative(offset), _inline_depth);
4118 }
4119
4120 const Type *TypeAryPtr::remove_speculative() const {
4121 if (_speculative == NULL) {
4122 return this;
4123 }
4124 assert(_inline_depth == InlineDepthTop || _inline_depth == InlineDepthBottom, "non speculative type shouldn't have inline depth");
4125 return make(_ptr, _const_oop, _ary->remove_speculative()->is_ary(), _klass, _klass_is_exact, _offset, _instance_id, NULL, _inline_depth);
4126 }
4127
4128 const TypeOopPtr *TypeAryPtr::with_inline_depth(int depth) const {
4129 if (!UseInlineDepthForSpeculativeTypes) {
4130 return this;
4131 }
4132 return make(_ptr, _const_oop, _ary->remove_speculative()->is_ary(), _klass, _klass_is_exact, _offset, _instance_id, _speculative, depth);
4133 }
4134
4135 //=============================================================================
4136
4137 //------------------------------hash-------------------------------------------
4138 // Type-specific hashing function.
4139 int TypeNarrowPtr::hash(void) const {
4140 return _ptrtype->hash() + 7;
4141 }
4142
4143 bool TypeNarrowPtr::singleton(void) const { // TRUE if type is a singleton
4144 return _ptrtype->singleton();
4145 }
4146
4147 bool TypeNarrowPtr::empty(void) const {
4148 return _ptrtype->empty();
4233
4234 } // End of switch
4235
4236 return this;
4237 }
4238
4239 #ifndef PRODUCT
4240 void TypeNarrowPtr::dump2( Dict & d, uint depth, outputStream *st ) const {
4241 _ptrtype->dump2(d, depth, st);
4242 }
4243 #endif
4244
4245 const TypeNarrowOop *TypeNarrowOop::BOTTOM;
4246 const TypeNarrowOop *TypeNarrowOop::NULL_PTR;
4247
4248
4249 const TypeNarrowOop* TypeNarrowOop::make(const TypePtr* type) {
4250 return (const TypeNarrowOop*)(new TypeNarrowOop(type))->hashcons();
4251 }
4252
4253
4254 #ifndef PRODUCT
4255 void TypeNarrowOop::dump2( Dict & d, uint depth, outputStream *st ) const {
4256 st->print("narrowoop: ");
4257 TypeNarrowPtr::dump2(d, depth, st);
4258 }
4259 #endif
4260
4261 const TypeNarrowKlass *TypeNarrowKlass::NULL_PTR;
4262
4263 const TypeNarrowKlass* TypeNarrowKlass::make(const TypePtr* type) {
4264 return (const TypeNarrowKlass*)(new TypeNarrowKlass(type))->hashcons();
4265 }
4266
4267 #ifndef PRODUCT
4268 void TypeNarrowKlass::dump2( Dict & d, uint depth, outputStream *st ) const {
4269 st->print("narrowklass: ");
4270 TypeNarrowPtr::dump2(d, depth, st);
4271 }
4272 #endif
4359 case DoubleTop:
4360 case DoubleCon:
4361 case DoubleBot:
4362 case NarrowOop:
4363 case NarrowKlass:
4364 case Bottom: // Ye Olde Default
4365 return Type::BOTTOM;
4366 case Top:
4367 return this;
4368
4369 default: // All else is a mistake
4370 typerr(t);
4371
4372 case AnyPtr: {
4373 // Found an AnyPtr type vs self-OopPtr type
4374 const TypePtr *tp = t->is_ptr();
4375 int offset = meet_offset(tp->offset());
4376 PTR ptr = meet_ptr(tp->ptr());
4377 switch (tp->ptr()) {
4378 case Null:
4379 if (ptr == Null) return TypePtr::make(AnyPtr, ptr, offset);
4380 // else fall through:
4381 case TopPTR:
4382 case AnyNull: {
4383 return make(ptr, _metadata, offset);
4384 }
4385 case BotPTR:
4386 case NotNull:
4387 return TypePtr::make(AnyPtr, ptr, offset);
4388 default: typerr(t);
4389 }
4390 }
4391
4392 case RawPtr:
4393 case KlassPtr:
4394 case OopPtr:
4395 case InstPtr:
4396 case AryPtr:
4397 return TypePtr::BOTTOM; // Oop meet raw is not well defined
4398
4399 case MetadataPtr: {
4400 const TypeMetadataPtr *tp = t->is_metadataptr();
4401 int offset = meet_offset(tp->offset());
4402 PTR tptr = tp->ptr();
4403 PTR ptr = meet_ptr(tptr);
4404 ciMetadata* md = (tptr == TopPTR) ? metadata() : tp->metadata();
4405 if (tptr == TopPTR || _ptr == TopPTR ||
4406 metadata()->equals(tp->metadata())) {
4407 return make(ptr, md, offset);
4681 case DoubleBot:
4682 case NarrowOop:
4683 case NarrowKlass:
4684 case Bottom: // Ye Olde Default
4685 return Type::BOTTOM;
4686 case Top:
4687 return this;
4688
4689 default: // All else is a mistake
4690 typerr(t);
4691
4692 case AnyPtr: { // Meeting to AnyPtrs
4693 // Found an AnyPtr type vs self-KlassPtr type
4694 const TypePtr *tp = t->is_ptr();
4695 int offset = meet_offset(tp->offset());
4696 PTR ptr = meet_ptr(tp->ptr());
4697 switch (tp->ptr()) {
4698 case TopPTR:
4699 return this;
4700 case Null:
4701 if( ptr == Null ) return TypePtr::make( AnyPtr, ptr, offset );
4702 case AnyNull:
4703 return make( ptr, klass(), offset );
4704 case BotPTR:
4705 case NotNull:
4706 return TypePtr::make(AnyPtr, ptr, offset);
4707 default: typerr(t);
4708 }
4709 }
4710
4711 case RawPtr:
4712 case MetadataPtr:
4713 case OopPtr:
4714 case AryPtr: // Meet with AryPtr
4715 case InstPtr: // Meet with InstPtr
4716 return TypePtr::BOTTOM;
4717
4718 //
4719 // A-top }
4720 // / | \ } Tops
4721 // B-top A-any C-top }
4722 // | / | \ | } Any-nulls
4723 // B-any | C-any }
4724 // | | |
4725 // B-con A-con C-con } constants; not comparable across classes
4726 // | | |
|
333 const Type **ffalse =(const Type**)shared_type_arena->Amalloc_4(2*sizeof(Type*));
334 ffalse[0] = Type::CONTROL;
335 ffalse[1] = Type::TOP;
336 TypeTuple::IFFALSE = TypeTuple::make( 2, ffalse );
337
338 const Type **fneither =(const Type**)shared_type_arena->Amalloc_4(2*sizeof(Type*));
339 fneither[0] = Type::TOP;
340 fneither[1] = Type::TOP;
341 TypeTuple::IFNEITHER = TypeTuple::make( 2, fneither );
342
343 const Type **ftrue =(const Type**)shared_type_arena->Amalloc_4(2*sizeof(Type*));
344 ftrue[0] = Type::TOP;
345 ftrue[1] = Type::CONTROL;
346 TypeTuple::IFTRUE = TypeTuple::make( 2, ftrue );
347
348 const Type **floop =(const Type**)shared_type_arena->Amalloc_4(2*sizeof(Type*));
349 floop[0] = Type::CONTROL;
350 floop[1] = TypeInt::INT;
351 TypeTuple::LOOPBODY = TypeTuple::make( 2, floop );
352
353 TypePtr::NULL_PTR= TypePtr::make(AnyPtr, TypePtr::Null, 0);
354 TypePtr::NOTNULL = TypePtr::make(AnyPtr, TypePtr::NotNull, OffsetBot);
355 TypePtr::BOTTOM = TypePtr::make(AnyPtr, TypePtr::BotPTR, OffsetBot);
356
357 TypeRawPtr::BOTTOM = TypeRawPtr::make( TypePtr::BotPTR );
358 TypeRawPtr::NOTNULL= TypeRawPtr::make( TypePtr::NotNull );
359
360 const Type **fmembar = TypeTuple::fields(0);
361 TypeTuple::MEMBAR = TypeTuple::make(TypeFunc::Parms+0, fmembar);
362
363 const Type **fsc = (const Type**)shared_type_arena->Amalloc_4(2*sizeof(Type*));
364 fsc[0] = TypeInt::CC;
365 fsc[1] = Type::MEMORY;
366 TypeTuple::STORECONDITIONAL = TypeTuple::make(2, fsc);
367
368 TypeInstPtr::NOTNULL = TypeInstPtr::make(TypePtr::NotNull, current->env()->Object_klass());
369 TypeInstPtr::BOTTOM = TypeInstPtr::make(TypePtr::BotPTR, current->env()->Object_klass());
370 TypeInstPtr::MIRROR = TypeInstPtr::make(TypePtr::NotNull, current->env()->Class_klass());
371 TypeInstPtr::MARK = TypeInstPtr::make(TypePtr::BotPTR, current->env()->Object_klass(),
372 false, 0, oopDesc::mark_offset_in_bytes());
373 TypeInstPtr::KLASS = TypeInstPtr::make(TypePtr::BotPTR, current->env()->Object_klass(),
374 false, 0, oopDesc::klass_offset_in_bytes());
375 TypeOopPtr::BOTTOM = TypeOopPtr::make(TypePtr::BotPTR, OffsetBot, TypeOopPtr::InstanceBot);
376
377 TypeMetadataPtr::BOTTOM = TypeMetadataPtr::make(TypePtr::BotPTR, NULL, OffsetBot);
378
379 TypeNarrowOop::NULL_PTR = TypeNarrowOop::make( TypePtr::NULL_PTR );
380 TypeNarrowOop::BOTTOM = TypeNarrowOop::make( TypeInstPtr::BOTTOM );
381
382 TypeNarrowKlass::NULL_PTR = TypeNarrowKlass::make( TypePtr::NULL_PTR );
383
384 mreg2type[Op_Node] = Type::BOTTOM;
385 mreg2type[Op_Set ] = 0;
386 mreg2type[Op_RegN] = TypeNarrowOop::BOTTOM;
387 mreg2type[Op_RegI] = TypeInt::INT;
388 mreg2type[Op_RegP] = TypePtr::BOTTOM;
389 mreg2type[Op_RegF] = Type::FLOAT;
390 mreg2type[Op_RegD] = Type::DOUBLE;
391 mreg2type[Op_RegL] = TypeLong::LONG;
392 mreg2type[Op_RegFlags] = TypeInt::CC;
393
394 TypeAryPtr::RANGE = TypeAryPtr::make( TypePtr::BotPTR, TypeAry::make(Type::BOTTOM,TypeInt::POS), NULL /* current->env()->Object_klass() */, false, arrayOopDesc::length_offset_in_bytes());
395
603 const TypePtr* t_ptr = t->make_ptr();
604 if( this_ptr == NULL || t_ptr == NULL )
605 return result;
606
607 const TypeInstPtr* this_inst = this_ptr->isa_instptr();
608 const TypeInstPtr* t_inst = t_ptr->isa_instptr();
609 if( this_inst && this_inst->is_loaded() && t_inst && t_inst->is_loaded() ) {
610 bool this_interface = this_inst->klass()->is_interface();
611 bool t_interface = t_inst->klass()->is_interface();
612 result = this_interface ^ t_interface;
613 }
614
615 return result;
616 }
617
618 bool Type::interface_vs_oop(const Type *t) const {
619 if (interface_vs_oop_helper(t)) {
620 return true;
621 }
622 // Now check the speculative parts as well
623 const TypePtr* this_spec = isa_ptr() != NULL ? is_ptr()->speculative() : NULL;
624 const TypePtr* t_spec = t->isa_ptr() != NULL ? t->is_ptr()->speculative() : NULL;
625 if (this_spec != NULL && t_spec != NULL) {
626 if (this_spec->interface_vs_oop_helper(t_spec)) {
627 return true;
628 }
629 return false;
630 }
631 if (this_spec != NULL && this_spec->interface_vs_oop_helper(t)) {
632 return true;
633 }
634 if (t_spec != NULL && interface_vs_oop_helper(t_spec)) {
635 return true;
636 }
637 return false;
638 }
639
640 #endif
641
642 //------------------------------meet-------------------------------------------
643 // Compute the MEET of two types. NOT virtual. It enforces that meet is
644 // commutative and the lattice is symmetric.
1958 bool TypeAry::eq( const Type *t ) const {
1959 const TypeAry *a = (const TypeAry*)t;
1960 return _elem == a->_elem &&
1961 _stable == a->_stable &&
1962 _size == a->_size;
1963 }
1964
1965 //------------------------------hash-------------------------------------------
1966 // Type-specific hashing function.
1967 int TypeAry::hash(void) const {
1968 return (intptr_t)_elem + (intptr_t)_size + (_stable ? 43 : 0);
1969 }
1970
1971 /**
1972 * Return same type without a speculative part in the element
1973 */
1974 const Type* TypeAry::remove_speculative() const {
1975 return make(_elem->remove_speculative(), _size, _stable);
1976 }
1977
1978 /**
1979 * Return same type with cleaned up speculative part of element
1980 */
1981 const Type* TypeAry::cleanup_speculative() const {
1982 return make(_elem->cleanup_speculative(), _size, _stable);
1983 }
1984
1985 /**
1986 * Return same type but with a different inline depth (used for speculation)
1987 *
1988 * @param depth depth to meet with
1989 */
1990 const TypePtr* TypePtr::with_inline_depth(int depth) const {
1991 if (!UseInlineDepthForSpeculativeTypes) {
1992 return this;
1993 }
1994 return make(AnyPtr, _ptr, _offset, _speculative, depth);
1995 }
1996
1997 //----------------------interface_vs_oop---------------------------------------
1998 #ifdef ASSERT
1999 bool TypeAry::interface_vs_oop(const Type *t) const {
2000 const TypeAry* t_ary = t->is_ary();
2001 if (t_ary) {
2002 return _elem->interface_vs_oop(t_ary->_elem);
2003 }
2004 return false;
2005 }
2006 #endif
2007
2008 //------------------------------dump2------------------------------------------
2009 #ifndef PRODUCT
2010 void TypeAry::dump2( Dict &d, uint depth, outputStream *st ) const {
2011 if (_stable) st->print("stable:");
2012 _elem->dump2(d, depth, st);
2013 st->print("[");
2014 _size->dump2(d, depth, st);
2015 st->print("]");
2016 }
2181
2182 //=============================================================================
2183 // Convenience common pre-built types.
2184 const TypePtr *TypePtr::NULL_PTR;
2185 const TypePtr *TypePtr::NOTNULL;
2186 const TypePtr *TypePtr::BOTTOM;
2187
2188 //------------------------------meet-------------------------------------------
2189 // Meet over the PTR enum
2190 const TypePtr::PTR TypePtr::ptr_meet[TypePtr::lastPTR][TypePtr::lastPTR] = {
2191 // TopPTR, AnyNull, Constant, Null, NotNull, BotPTR,
2192 { /* Top */ TopPTR, AnyNull, Constant, Null, NotNull, BotPTR,},
2193 { /* AnyNull */ AnyNull, AnyNull, Constant, BotPTR, NotNull, BotPTR,},
2194 { /* Constant*/ Constant, Constant, Constant, BotPTR, NotNull, BotPTR,},
2195 { /* Null */ Null, BotPTR, BotPTR, Null, BotPTR, BotPTR,},
2196 { /* NotNull */ NotNull, NotNull, NotNull, BotPTR, NotNull, BotPTR,},
2197 { /* BotPTR */ BotPTR, BotPTR, BotPTR, BotPTR, BotPTR, BotPTR,}
2198 };
2199
2200 //------------------------------make-------------------------------------------
2201 const TypePtr *TypePtr::make(TYPES t, enum PTR ptr, int offset, const TypePtr* speculative, int inline_depth) {
2202 return (TypePtr*)(new TypePtr(t,ptr,offset, speculative, inline_depth))->hashcons();
2203 }
2204
2205 //------------------------------cast_to_ptr_type-------------------------------
2206 const Type *TypePtr::cast_to_ptr_type(PTR ptr) const {
2207 assert(_base == AnyPtr, "subclass must override cast_to_ptr_type");
2208 if( ptr == _ptr ) return this;
2209 return make(_base, ptr, _offset, _speculative, _inline_depth);
2210 }
2211
2212 //------------------------------get_con----------------------------------------
2213 intptr_t TypePtr::get_con() const {
2214 assert( _ptr == Null, "" );
2215 return _offset;
2216 }
2217
2218 //------------------------------meet-------------------------------------------
2219 // Compute the MEET of two types. It returns a new Type object.
2220 const Type *TypePtr::xmeet(const Type *t) const {
2221 const Type* res = xmeet_helper(t);
2222 if (res->isa_ptr() == NULL) {
2223 return res;
2224 }
2225
2226 const TypePtr* res_ptr = res->is_ptr();
2227 if (res_ptr->speculative() != NULL) {
2228 // type->speculative() == NULL means that speculation is no better
2229 // than type, i.e. type->speculative() == type. So there are 2
2230 // ways to represent the fact that we have no useful speculative
2231 // data and we should use a single one to be able to test for
2232 // equality between types. Check whether type->speculative() ==
2233 // type and set speculative to NULL if it is the case.
2234 if (res_ptr->remove_speculative() == res_ptr->speculative()) {
2235 return res_ptr->remove_speculative();
2236 }
2237 }
2238
2239 return res;
2240 }
2241
2242 const Type *TypePtr::xmeet_helper(const Type *t) const {
2243 // Perform a fast test for common case; meeting the same types together.
2244 if( this == t ) return this; // Meeting same type-rep?
2245
2246 // Current "this->_base" is AnyPtr
2247 switch (t->base()) { // switch on original type
2248 case Int: // Mixing ints & oops happens when javac
2249 case Long: // reuses local variables
2250 case FloatTop:
2251 case FloatCon:
2252 case FloatBot:
2253 case DoubleTop:
2254 case DoubleCon:
2255 case DoubleBot:
2256 case NarrowOop:
2257 case NarrowKlass:
2258 case Bottom: // Ye Olde Default
2259 return Type::BOTTOM;
2260 case Top:
2261 return this;
2262
2263 case AnyPtr: { // Meeting to AnyPtrs
2264 const TypePtr *tp = t->is_ptr();
2265 const TypePtr* speculative = xmeet_speculative(tp);
2266 int depth = meet_inline_depth(tp->inline_depth());
2267 return make(AnyPtr, meet_ptr(tp->ptr()), meet_offset(tp->offset()), speculative, depth);
2268 }
2269 case RawPtr: // For these, flip the call around to cut down
2270 case OopPtr:
2271 case InstPtr: // on the cases I have to handle.
2272 case AryPtr:
2273 case MetadataPtr:
2274 case KlassPtr:
2275 return t->xmeet(this); // Call in reverse direction
2276 default: // All else is a mistake
2277 typerr(t);
2278
2279 }
2280 return this;
2281 }
2282
2283 //------------------------------meet_offset------------------------------------
2284 int TypePtr::meet_offset( int offset ) const {
2285 // Either is 'TOP' offset? Return the other offset!
2286 if( _offset == OffsetTop ) return offset;
2287 if( offset == OffsetTop ) return _offset;
2288 // If either is different, return 'BOTTOM' offset
2289 if( _offset != offset ) return OffsetBot;
2290 return _offset;
2291 }
2292
2293 //------------------------------dual_offset------------------------------------
2294 int TypePtr::dual_offset( ) const {
2295 if( _offset == OffsetTop ) return OffsetBot;// Map 'TOP' into 'BOTTOM'
2296 if( _offset == OffsetBot ) return OffsetTop;// Map 'BOTTOM' into 'TOP'
2297 return _offset; // Map everything else into self
2298 }
2299
2300 //------------------------------xdual------------------------------------------
2301 // Dual: compute field-by-field dual
2302 const TypePtr::PTR TypePtr::ptr_dual[TypePtr::lastPTR] = {
2303 BotPTR, NotNull, Constant, Null, AnyNull, TopPTR
2304 };
2305 const Type *TypePtr::xdual() const {
2306 return new TypePtr(AnyPtr, dual_ptr(), dual_offset(), dual_speculative(), dual_inline_depth());
2307 }
2308
2309 //------------------------------xadd_offset------------------------------------
2310 int TypePtr::xadd_offset( intptr_t offset ) const {
2311 // Adding to 'TOP' offset? Return 'TOP'!
2312 if( _offset == OffsetTop || offset == OffsetTop ) return OffsetTop;
2313 // Adding to 'BOTTOM' offset? Return 'BOTTOM'!
2314 if( _offset == OffsetBot || offset == OffsetBot ) return OffsetBot;
2315 // Addition overflows or "accidentally" equals to OffsetTop? Return 'BOTTOM'!
2316 offset += (intptr_t)_offset;
2317 if (offset != (int)offset || offset == OffsetTop) return OffsetBot;
2318
2319 // assert( _offset >= 0 && _offset+offset >= 0, "" );
2320 // It is possible to construct a negative offset during PhaseCCP
2321
2322 return (int)offset; // Sum valid offsets
2323 }
2324
2325 //------------------------------add_offset-------------------------------------
2326 const TypePtr *TypePtr::add_offset( intptr_t offset ) const {
2327 return make(AnyPtr, _ptr, xadd_offset(offset), _speculative, _inline_depth);
2328 }
2329
2330 //------------------------------eq---------------------------------------------
2331 // Structural equality check for Type representations
2332 bool TypePtr::eq( const Type *t ) const {
2333 const TypePtr *a = (const TypePtr*)t;
2334 return _ptr == a->ptr() && _offset == a->offset() && eq_speculative(a) && _inline_depth == a->_inline_depth;
2335 }
2336
2337 //------------------------------hash-------------------------------------------
2338 // Type-specific hashing function.
2339 int TypePtr::hash(void) const {
2340 return _ptr + _offset + hash_speculative() + _inline_depth;
2341 ;
2342 }
2343
2344 /**
2345 * Return same type without a speculative part
2346 */
2347 const Type* TypePtr::remove_speculative() const {
2348 if (_speculative == NULL) {
2349 return this;
2350 }
2351 assert(_inline_depth == InlineDepthTop || _inline_depth == InlineDepthBottom, "non speculative type shouldn't have inline depth");
2352 return make(AnyPtr, _ptr, _offset, NULL, _inline_depth);
2353 }
2354
2355 /**
2356 * Return same type but drop speculative part if we know we won't use
2357 * it
2358 */
2359 const Type* TypePtr::cleanup_speculative() const {
2360 if (speculative() == NULL) {
2361 return this;
2362 }
2363 const Type* no_spec = remove_speculative();
2364 // If this is NULL_PTR then we don't need the speculative type
2365 // (with_inline_depth in case the current type inline depth is
2366 // InlineDepthTop)
2367 if (no_spec == NULL_PTR->with_inline_depth(inline_depth())) {
2368 return no_spec;
2369 }
2370 if (above_centerline(speculative()->ptr())) {
2371 return no_spec;
2372 }
2373 const TypeOopPtr* spec_oopptr = speculative()->isa_oopptr();
2374 // If the speculative may be null and is an inexact klass then it
2375 // doesn't help
2376 if (speculative()->maybe_null() && (spec_oopptr == NULL || !spec_oopptr->klass_is_exact())) {
2377 return no_spec;
2378 }
2379 return this;
2380 }
2381
2382 /**
2383 * dual of the speculative part of the type
2384 */
2385 const TypePtr* TypePtr::dual_speculative() const {
2386 if (_speculative == NULL) {
2387 return NULL;
2388 }
2389 return _speculative->dual()->is_ptr();
2390 }
2391
2392 /**
2393 * meet of the speculative parts of 2 types
2394 *
2395 * @param other type to meet with
2396 */
2397 const TypePtr* TypePtr::xmeet_speculative(const TypePtr* other) const {
2398 bool this_has_spec = (_speculative != NULL);
2399 bool other_has_spec = (other->speculative() != NULL);
2400
2401 if (!this_has_spec && !other_has_spec) {
2402 return NULL;
2403 }
2404
2405 // If we are at a point where control flow meets and one branch has
2406 // a speculative type and the other has not, we meet the speculative
2407 // type of one branch with the actual type of the other. If the
2408 // actual type is exact and the speculative is as well, then the
2409 // result is a speculative type which is exact and we can continue
2410 // speculation further.
2411 const TypePtr* this_spec = _speculative;
2412 const TypePtr* other_spec = other->speculative();
2413
2414 if (!this_has_spec) {
2415 this_spec = this;
2416 }
2417
2418 if (!other_has_spec) {
2419 other_spec = other;
2420 }
2421
2422 return this_spec->meet(other_spec)->is_ptr();
2423 }
2424
2425 /**
2426 * dual of the inline depth for this type (used for speculation)
2427 */
2428 int TypePtr::dual_inline_depth() const {
2429 return -inline_depth();
2430 }
2431
2432 /**
2433 * meet of 2 inline depths (used for speculation)
2434 *
2435 * @param depth depth to meet with
2436 */
2437 int TypePtr::meet_inline_depth(int depth) const {
2438 return MAX2(inline_depth(), depth);
2439 }
2440
2441 /**
2442 * Are the speculative parts of 2 types equal?
2443 *
2444 * @param other type to compare this one to
2445 */
2446 bool TypePtr::eq_speculative(const TypePtr* other) const {
2447 if (_speculative == NULL || other->speculative() == NULL) {
2448 return _speculative == other->speculative();
2449 }
2450
2451 if (_speculative->base() != other->speculative()->base()) {
2452 return false;
2453 }
2454
2455 return _speculative->eq(other->speculative());
2456 }
2457
2458 /**
2459 * Hash of the speculative part of the type
2460 */
2461 int TypePtr::hash_speculative() const {
2462 if (_speculative == NULL) {
2463 return 0;
2464 }
2465
2466 return _speculative->hash();
2467 }
2468
2469 /**
2470 * add offset to the speculative part of the type
2471 *
2472 * @param offset offset to add
2473 */
2474 const TypePtr* TypePtr::add_offset_speculative(intptr_t offset) const {
2475 if (_speculative == NULL) {
2476 return NULL;
2477 }
2478 return _speculative->add_offset(offset)->is_ptr();
2479 }
2480
2481 /**
2482 * return exact klass from the speculative type if there's one
2483 */
2484 ciKlass* TypePtr::speculative_type() const {
2485 if (_speculative != NULL && _speculative->isa_oopptr()) {
2486 const TypeOopPtr* speculative = _speculative->join(this)->is_oopptr();
2487 if (speculative->klass_is_exact()) {
2488 return speculative->klass();
2489 }
2490 }
2491 return NULL;
2492 }
2493
2494 /**
2495 * return true if speculative type may be null
2496 */
2497 bool TypePtr::speculative_maybe_null() const {
2498 if (_speculative != NULL) {
2499 const TypePtr* speculative = _speculative->join(this)->is_ptr();
2500 return speculative->maybe_null();
2501 }
2502 return true;
2503 }
2504
2505 /**
2506 * Same as TypePtr::speculative_type() but return the klass only if
2507 * the speculative tells us is not null
2508 */
2509 ciKlass* TypePtr::speculative_type_not_null() const {
2510 if (speculative_maybe_null()) {
2511 return NULL;
2512 }
2513 return speculative_type();
2514 }
2515
2516 /**
2517 * Check whether new profiling would improve speculative type
2518 *
2519 * @param exact_kls class from profiling
2520 * @param inline_depth inlining depth of profile point
2521 *
2522 * @return true if type profile is valuable
2523 */
2524 bool TypePtr::would_improve_type(ciKlass* exact_kls, int inline_depth) const {
2525 // no profiling?
2526 if (exact_kls == NULL) {
2527 return false;
2528 }
2529 // no speculative type or non exact speculative type?
2530 if (speculative_type() == NULL) {
2531 return true;
2532 }
2533 // If the node already has an exact speculative type keep it,
2534 // unless it was provided by profiling that is at a deeper
2535 // inlining level. Profiling at a higher inlining depth is
2536 // expected to be less accurate.
2537 if (_speculative->inline_depth() == InlineDepthBottom) {
2538 return false;
2539 }
2540 assert(_speculative->inline_depth() != InlineDepthTop, "can't do the comparison");
2541 return inline_depth < _speculative->inline_depth();
2542 }
2543
2544 /**
2545 * Check whether new profiling would improve ptr (= tells us it is non
2546 * null)
2547 *
2548 * @param maybe_null true if profiling tells the ptr may be null
2549 *
2550 * @return true if ptr profile is valuable
2551 */
2552 bool TypePtr::would_improve_ptr(bool maybe_null) const {
2553 // profiling doesn't tell us anything useful
2554 if (maybe_null) {
2555 return false;
2556 }
2557 // We already know this is not be null
2558 if (!this->maybe_null()) {
2559 return false;
2560 }
2561 // We already know the speculative type cannot be null
2562 if (!speculative_maybe_null()) {
2563 return false;
2564 }
2565 return true;
2566 }
2567
2568 //------------------------------dump2------------------------------------------
2569 const char *const TypePtr::ptr_msg[TypePtr::lastPTR] = {
2570 "TopPTR","AnyNull","Constant","NULL","NotNull","BotPTR"
2571 };
2572
2573 #ifndef PRODUCT
2574 void TypePtr::dump2( Dict &d, uint depth, outputStream *st ) const {
2575 if( _ptr == Null ) st->print("NULL");
2576 else st->print("%s *", ptr_msg[_ptr]);
2577 if( _offset == OffsetTop ) st->print("+top");
2578 else if( _offset == OffsetBot ) st->print("+bot");
2579 else if( _offset ) st->print("+%d", _offset);
2580 dump_inline_depth(st);
2581 dump_speculative(st);
2582 }
2583
2584 /**
2585 *dump the speculative part of the type
2586 */
2587 void TypePtr::dump_speculative(outputStream *st) const {
2588 if (_speculative != NULL) {
2589 st->print(" (speculative=");
2590 _speculative->dump_on(st);
2591 st->print(")");
2592 }
2593 }
2594
2595 /**
2596 *dump the inline depth of the type
2597 */
2598 void TypePtr::dump_inline_depth(outputStream *st) const {
2599 if (_inline_depth != InlineDepthBottom) {
2600 if (_inline_depth == InlineDepthTop) {
2601 st->print(" (inline_depth=InlineDepthTop)");
2602 } else {
2603 st->print(" (inline_depth=%d)", _inline_depth);
2604 }
2605 }
2606 }
2607 #endif
2608
2609 //------------------------------singleton--------------------------------------
2610 // TRUE if Type is a singleton type, FALSE otherwise. Singletons are simple
2611 // constants
2612 bool TypePtr::singleton(void) const {
2613 // TopPTR, Null, AnyNull, Constant are all singletons
2614 return (_offset != OffsetBot) && !below_centerline(_ptr);
2615 }
2616
2617 bool TypePtr::empty(void) const {
2618 return (_offset == OffsetTop) || above_centerline(_ptr);
2619 }
2620
2621 //=============================================================================
2622 // Convenience common pre-built types.
2623 const TypeRawPtr *TypeRawPtr::BOTTOM;
2624 const TypeRawPtr *TypeRawPtr::NOTNULL;
2625
2676 }
2677
2678 case OopPtr:
2679 case InstPtr:
2680 case AryPtr:
2681 case MetadataPtr:
2682 case KlassPtr:
2683 return TypePtr::BOTTOM; // Oop meet raw is not well defined
2684 default: // All else is a mistake
2685 typerr(t);
2686 }
2687
2688 // Found an AnyPtr type vs self-RawPtr type
2689 const TypePtr *tp = t->is_ptr();
2690 switch (tp->ptr()) {
2691 case TypePtr::TopPTR: return this;
2692 case TypePtr::BotPTR: return t;
2693 case TypePtr::Null:
2694 if( _ptr == TypePtr::TopPTR ) return t;
2695 return TypeRawPtr::BOTTOM;
2696 case TypePtr::NotNull: return TypePtr::make(AnyPtr, meet_ptr(TypePtr::NotNull), tp->meet_offset(0), tp->speculative(), tp->inline_depth());
2697 case TypePtr::AnyNull:
2698 if( _ptr == TypePtr::Constant) return this;
2699 return make( meet_ptr(TypePtr::AnyNull) );
2700 default: ShouldNotReachHere();
2701 }
2702 return this;
2703 }
2704
2705 //------------------------------xdual------------------------------------------
2706 // Dual: compute field-by-field dual
2707 const Type *TypeRawPtr::xdual() const {
2708 return new TypeRawPtr( dual_ptr(), _bits );
2709 }
2710
2711 //------------------------------add_offset-------------------------------------
2712 const TypePtr *TypeRawPtr::add_offset( intptr_t offset ) const {
2713 if( offset == OffsetTop ) return BOTTOM; // Undefined offset-> undefined pointer
2714 if( offset == OffsetBot ) return BOTTOM; // Unknown offset-> unknown pointer
2715 if( offset == 0 ) return this; // No change
2716 switch (_ptr) {
2740 // Type-specific hashing function.
2741 int TypeRawPtr::hash(void) const {
2742 return (intptr_t)_bits + TypePtr::hash();
2743 }
2744
2745 //------------------------------dump2------------------------------------------
2746 #ifndef PRODUCT
2747 void TypeRawPtr::dump2( Dict &d, uint depth, outputStream *st ) const {
2748 if( _ptr == Constant )
2749 st->print(INTPTR_FORMAT, _bits);
2750 else
2751 st->print("rawptr:%s", ptr_msg[_ptr]);
2752 }
2753 #endif
2754
2755 //=============================================================================
2756 // Convenience common pre-built type.
2757 const TypeOopPtr *TypeOopPtr::BOTTOM;
2758
2759 //------------------------------TypeOopPtr-------------------------------------
2760 TypeOopPtr::TypeOopPtr(TYPES t, PTR ptr, ciKlass* k, bool xk, ciObject* o, int offset,
2761 int instance_id, const TypePtr* speculative, int inline_depth)
2762 : TypePtr(t, ptr, offset, speculative, inline_depth),
2763 _const_oop(o), _klass(k),
2764 _klass_is_exact(xk),
2765 _is_ptr_to_narrowoop(false),
2766 _is_ptr_to_narrowklass(false),
2767 _is_ptr_to_boxed_value(false),
2768 _instance_id(instance_id) {
2769 if (Compile::current()->eliminate_boxing() && (t == InstPtr) &&
2770 (offset > 0) && xk && (k != 0) && k->is_instance_klass()) {
2771 _is_ptr_to_boxed_value = k->as_instance_klass()->is_boxed_value_offset(offset);
2772 }
2773 #ifdef _LP64
2774 if (_offset != 0) {
2775 if (_offset == oopDesc::klass_offset_in_bytes()) {
2776 _is_ptr_to_narrowklass = UseCompressedClassPointers;
2777 } else if (klass() == NULL) {
2778 // Array with unknown body type
2779 assert(this->isa_aryptr(), "only arrays without klass");
2780 _is_ptr_to_narrowoop = UseCompressedOops;
2781 } else if (this->isa_aryptr()) {
2782 _is_ptr_to_narrowoop = (UseCompressedOops && klass()->is_obj_array_klass() &&
2783 _offset != arrayOopDesc::length_offset_in_bytes());
2784 } else if (klass()->is_instance_klass()) {
2785 ciInstanceKlass* ik = klass()->as_instance_klass();
2786 ciField* field = NULL;
2787 if (this->isa_klassptr()) {
2788 // Perm objects don't use compressed references
2814 if (field != NULL) {
2815 BasicType basic_elem_type = field->layout_type();
2816 _is_ptr_to_narrowoop = UseCompressedOops && (basic_elem_type == T_OBJECT ||
2817 basic_elem_type == T_ARRAY);
2818 } else if (klass()->equals(ciEnv::current()->Object_klass())) {
2819 // Compile::find_alias_type() cast exactness on all types to verify
2820 // that it does not affect alias type.
2821 _is_ptr_to_narrowoop = UseCompressedOops;
2822 } else {
2823 // Type for the copy start in LibraryCallKit::inline_native_clone().
2824 _is_ptr_to_narrowoop = UseCompressedOops;
2825 }
2826 }
2827 }
2828 }
2829 }
2830 #endif
2831 }
2832
2833 //------------------------------make-------------------------------------------
2834 const TypeOopPtr *TypeOopPtr::make(PTR ptr, int offset, int instance_id,
2835 const TypePtr* speculative, int inline_depth) {
2836 assert(ptr != Constant, "no constant generic pointers");
2837 ciKlass* k = Compile::current()->env()->Object_klass();
2838 bool xk = false;
2839 ciObject* o = NULL;
2840 return (TypeOopPtr*)(new TypeOopPtr(OopPtr, ptr, k, xk, o, offset, instance_id, speculative, inline_depth))->hashcons();
2841 }
2842
2843
2844 //------------------------------cast_to_ptr_type-------------------------------
2845 const Type *TypeOopPtr::cast_to_ptr_type(PTR ptr) const {
2846 assert(_base == OopPtr, "subclass must override cast_to_ptr_type");
2847 if( ptr == _ptr ) return this;
2848 return make(ptr, _offset, _instance_id, _speculative, _inline_depth);
2849 }
2850
2851 //-----------------------------cast_to_instance_id----------------------------
2852 const TypeOopPtr *TypeOopPtr::cast_to_instance_id(int instance_id) const {
2853 // There are no instances of a general oop.
2854 // Return self unchanged.
2855 return this;
2858 //-----------------------------cast_to_exactness-------------------------------
2859 const Type *TypeOopPtr::cast_to_exactness(bool klass_is_exact) const {
2860 // There is no such thing as an exact general oop.
2861 // Return self unchanged.
2862 return this;
2863 }
2864
2865
2866 //------------------------------as_klass_type----------------------------------
2867 // Return the klass type corresponding to this instance or array type.
2868 // It is the type that is loaded from an object of this type.
2869 const TypeKlassPtr* TypeOopPtr::as_klass_type() const {
2870 ciKlass* k = klass();
2871 bool xk = klass_is_exact();
2872 if (k == NULL)
2873 return TypeKlassPtr::OBJECT;
2874 else
2875 return TypeKlassPtr::make(xk? Constant: NotNull, k, 0);
2876 }
2877
2878 //------------------------------meet-------------------------------------------
2879 // Compute the MEET of two types. It returns a new Type object.
2880 const Type *TypeOopPtr::xmeet_helper(const Type *t) const {
2881 // Perform a fast test for common case; meeting the same types together.
2882 if( this == t ) return this; // Meeting same type-rep?
2883
2884 // Current "this->_base" is OopPtr
2885 switch (t->base()) { // switch on original type
2886
2887 case Int: // Mixing ints & oops happens when javac
2888 case Long: // reuses local variables
2889 case FloatTop:
2890 case FloatCon:
2891 case FloatBot:
2892 case DoubleTop:
2893 case DoubleCon:
2894 case DoubleBot:
2895 case NarrowOop:
2896 case NarrowKlass:
2897 case Bottom: // Ye Olde Default
2898 return Type::BOTTOM;
2899 case Top:
2900 return this;
2901
2902 default: // All else is a mistake
2903 typerr(t);
2904
2905 case RawPtr:
2906 case MetadataPtr:
2907 case KlassPtr:
2908 return TypePtr::BOTTOM; // Oop meet raw is not well defined
2909
2910 case AnyPtr: {
2911 // Found an AnyPtr type vs self-OopPtr type
2912 const TypePtr *tp = t->is_ptr();
2913 int offset = meet_offset(tp->offset());
2914 PTR ptr = meet_ptr(tp->ptr());
2915 const TypePtr* speculative = xmeet_speculative(tp);
2916 int depth = meet_inline_depth(tp->inline_depth());
2917 switch (tp->ptr()) {
2918 case Null:
2919 if (ptr == Null) return TypePtr::make(AnyPtr, ptr, offset, speculative, depth);
2920 // else fall through:
2921 case TopPTR:
2922 case AnyNull: {
2923 int instance_id = meet_instance_id(InstanceTop);
2924 return make(ptr, offset, instance_id, speculative, depth);
2925 }
2926 case BotPTR:
2927 case NotNull:
2928 return TypePtr::make(AnyPtr, ptr, offset, speculative, depth);
2929 default: typerr(t);
2930 }
2931 }
2932
2933 case OopPtr: { // Meeting to other OopPtrs
2934 const TypeOopPtr *tp = t->is_oopptr();
2935 int instance_id = meet_instance_id(tp->instance_id());
2936 const TypePtr* speculative = xmeet_speculative(tp);
2937 int depth = meet_inline_depth(tp->inline_depth());
2938 return make(meet_ptr(tp->ptr()), meet_offset(tp->offset()), instance_id, speculative, depth);
2939 }
2940
2941 case InstPtr: // For these, flip the call around to cut down
2942 case AryPtr:
2943 return t->xmeet(this); // Call in reverse direction
2944
2945 } // End of switch
2946 return this; // Return the double constant
2947 }
2948
2949
2950 //------------------------------xdual------------------------------------------
2951 // Dual of a pure heap pointer. No relevant klass or oop information.
2952 const Type *TypeOopPtr::xdual() const {
2953 assert(klass() == Compile::current()->env()->Object_klass(), "no klasses here");
2954 assert(const_oop() == NULL, "no constants here");
2955 return new TypeOopPtr(_base, dual_ptr(), klass(), klass_is_exact(), const_oop(), dual_offset(), dual_instance_id(), dual_speculative(), dual_inline_depth());
2956 }
3114 // the join should report back the class. However, if we have a J/L/Object
3115 // class-typed Phi and an interface flows in, it's possible that the meet &
3116 // join report an interface back out. This isn't possible but happens
3117 // because the type system doesn't interact well with interfaces.
3118 if (ftip != NULL && ktip != NULL &&
3119 ftip->is_loaded() && ftip->klass()->is_interface() &&
3120 ktip->is_loaded() && !ktip->klass()->is_interface()) {
3121 // Happens in a CTW of rt.jar, 320-341, no extra flags
3122 assert(!ftip->klass_is_exact(), "interface could not be exact");
3123 return ktip->cast_to_ptr_type(ftip->ptr());
3124 }
3125
3126 return ft;
3127 }
3128
3129 //------------------------------eq---------------------------------------------
3130 // Structural equality check for Type representations
3131 bool TypeOopPtr::eq( const Type *t ) const {
3132 const TypeOopPtr *a = (const TypeOopPtr*)t;
3133 if (_klass_is_exact != a->_klass_is_exact ||
3134 _instance_id != a->_instance_id) return false;
3135 ciObject* one = const_oop();
3136 ciObject* two = a->const_oop();
3137 if (one == NULL || two == NULL) {
3138 return (one == two) && TypePtr::eq(t);
3139 } else {
3140 return one->equals(two) && TypePtr::eq(t);
3141 }
3142 }
3143
3144 //------------------------------hash-------------------------------------------
3145 // Type-specific hashing function.
3146 int TypeOopPtr::hash(void) const {
3147 return
3148 (const_oop() ? const_oop()->hash() : 0) +
3149 _klass_is_exact +
3150 _instance_id +
3151 TypePtr::hash();
3152 }
3153
3154 //------------------------------dump2------------------------------------------
3155 #ifndef PRODUCT
3156 void TypeOopPtr::dump2( Dict &d, uint depth, outputStream *st ) const {
3157 st->print("oopptr:%s", ptr_msg[_ptr]);
3158 if( _klass_is_exact ) st->print(":exact");
3159 if( const_oop() ) st->print(INTPTR_FORMAT, const_oop());
3160 switch( _offset ) {
3161 case OffsetTop: st->print("+top"); break;
3162 case OffsetBot: st->print("+any"); break;
3163 case 0: break;
3164 default: st->print("+%d",_offset); break;
3165 }
3166 if (_instance_id == InstanceTop)
3167 st->print(",iid=top");
3168 else if (_instance_id != InstanceBot)
3169 st->print(",iid=%d",_instance_id);
3170
3171 dump_inline_depth(st);
3172 dump_speculative(st);
3173 }
3174 #endif
3175
3176 //------------------------------singleton--------------------------------------
3177 // TRUE if Type is a singleton type, FALSE otherwise. Singletons are simple
3178 // constants
3179 bool TypeOopPtr::singleton(void) const {
3180 // detune optimizer to not generate constant oop + constant offset as a constant!
3181 // TopPTR, Null, AnyNull, Constant are all singletons
3182 return (_offset == 0) && !below_centerline(_ptr);
3183 }
3184
3185 //------------------------------add_offset-------------------------------------
3186 const TypePtr *TypeOopPtr::add_offset(intptr_t offset) const {
3187 return make(_ptr, xadd_offset(offset), _instance_id, add_offset_speculative(offset), _inline_depth);
3188 }
3189
3190 /**
3191 * Return same type without a speculative part
3192 */
3193 const Type* TypeOopPtr::remove_speculative() const {
3194 if (_speculative == NULL) {
3195 return this;
3196 }
3197 assert(_inline_depth == InlineDepthTop || _inline_depth == InlineDepthBottom, "non speculative type shouldn't have inline depth");
3198 return make(_ptr, _offset, _instance_id, NULL, _inline_depth);
3199 }
3200
3201 /**
3202 * Return same type but drop speculative part if we know we won't use
3203 * it
3204 */
3205 const Type* TypeOopPtr::cleanup_speculative() const {
3206 // If the klass is exact and the ptr is not null then there's
3207 // nothing that the speculative type can help us with
3208 if (klass_is_exact() && !maybe_null()) {
3209 return remove_speculative();
3210 }
3211 return TypePtr::cleanup_speculative();
3212 }
3213
3214 /**
3215 * Return same type but with a different inline depth (used for speculation)
3216 *
3217 * @param depth depth to meet with
3218 */
3219 const TypePtr* TypeOopPtr::with_inline_depth(int depth) const {
3220 if (!UseInlineDepthForSpeculativeTypes) {
3221 return this;
3222 }
3223 return make(_ptr, _offset, _instance_id, _speculative, depth);
3224 }
3225
3226 //------------------------------meet_instance_id--------------------------------
3227 int TypeOopPtr::meet_instance_id( int instance_id ) const {
3228 // Either is 'TOP' instance? Return the other instance!
3229 if( _instance_id == InstanceTop ) return instance_id;
3230 if( instance_id == InstanceTop ) return _instance_id;
3231 // If either is different, return 'BOTTOM' instance
3232 if( _instance_id != instance_id ) return InstanceBot;
3233 return _instance_id;
3234 }
3235
3236 //------------------------------dual_instance_id--------------------------------
3237 int TypeOopPtr::dual_instance_id( ) const {
3238 if( _instance_id == InstanceTop ) return InstanceBot; // Map TOP into BOTTOM
3239 if( _instance_id == InstanceBot ) return InstanceTop; // Map BOTTOM into TOP
3240 return _instance_id; // Map everything else into self
3241 }
3242
3243 /**
3244 * Check whether new profiling would improve speculative type
3245 *
3246 * @param exact_kls class from profiling
3247 * @param inline_depth inlining depth of profile point
3248 *
3249 * @return true if type profile is valuable
3250 */
3251 bool TypeOopPtr::would_improve_type(ciKlass* exact_kls, int inline_depth) const {
3252 // no way to improve an already exact type
3253 if (klass_is_exact()) {
3254 return false;
3255 }
3256 return TypePtr::would_improve_type(exact_kls, inline_depth);
3257 }
3258
3259 //=============================================================================
3260 // Convenience common pre-built types.
3261 const TypeInstPtr *TypeInstPtr::NOTNULL;
3262 const TypeInstPtr *TypeInstPtr::BOTTOM;
3263 const TypeInstPtr *TypeInstPtr::MIRROR;
3264 const TypeInstPtr *TypeInstPtr::MARK;
3265 const TypeInstPtr *TypeInstPtr::KLASS;
3266
3267 //------------------------------TypeInstPtr-------------------------------------
3268 TypeInstPtr::TypeInstPtr(PTR ptr, ciKlass* k, bool xk, ciObject* o, int off,
3269 int instance_id, const TypePtr* speculative, int inline_depth)
3270 : TypeOopPtr(InstPtr, ptr, k, xk, o, off, instance_id, speculative, inline_depth),
3271 _name(k->name()) {
3272 assert(k != NULL &&
3273 (k->is_loaded() || o == NULL),
3274 "cannot have constants with non-loaded klass");
3275 };
3276
3277 //------------------------------make-------------------------------------------
3278 const TypeInstPtr *TypeInstPtr::make(PTR ptr,
3279 ciKlass* k,
3280 bool xk,
3281 ciObject* o,
3282 int offset,
3283 int instance_id,
3284 const TypePtr* speculative,
3285 int inline_depth) {
3286 assert( !k->is_loaded() || k->is_instance_klass(), "Must be for instance");
3287 // Either const_oop() is NULL or else ptr is Constant
3288 assert( (!o && ptr != Constant) || (o && ptr == Constant),
3289 "constant pointers must have a value supplied" );
3290 // Ptr is never Null
3291 assert( ptr != Null, "NULL pointers are not typed" );
3292
3293 assert(instance_id <= 0 || xk || !UseExactTypes, "instances are always exactly typed");
3294 if (!UseExactTypes) xk = false;
3295 if (ptr == Constant) {
3296 // Note: This case includes meta-object constants, such as methods.
3297 xk = true;
3298 } else if (k->is_loaded()) {
3299 ciInstanceKlass* ik = k->as_instance_klass();
3300 if (!xk && ik->is_final()) xk = true; // no inexact final klass
3301 if (xk && ik->is_interface()) xk = false; // no exact interface
3302 }
3303
3304 // Now hash this baby
3347 if (!_klass->is_loaded()) return this;
3348 ciInstanceKlass* ik = _klass->as_instance_klass();
3349 if( (ik->is_final() || _const_oop) ) return this; // cannot clear xk
3350 if( ik->is_interface() ) return this; // cannot set xk
3351 return make(ptr(), klass(), klass_is_exact, const_oop(), _offset, _instance_id, _speculative, _inline_depth);
3352 }
3353
3354 //-----------------------------cast_to_instance_id----------------------------
3355 const TypeOopPtr *TypeInstPtr::cast_to_instance_id(int instance_id) const {
3356 if( instance_id == _instance_id ) return this;
3357 return make(_ptr, klass(), _klass_is_exact, const_oop(), _offset, instance_id, _speculative, _inline_depth);
3358 }
3359
3360 //------------------------------xmeet_unloaded---------------------------------
3361 // Compute the MEET of two InstPtrs when at least one is unloaded.
3362 // Assume classes are different since called after check for same name/class-loader
3363 const TypeInstPtr *TypeInstPtr::xmeet_unloaded(const TypeInstPtr *tinst) const {
3364 int off = meet_offset(tinst->offset());
3365 PTR ptr = meet_ptr(tinst->ptr());
3366 int instance_id = meet_instance_id(tinst->instance_id());
3367 const TypePtr* speculative = xmeet_speculative(tinst);
3368 int depth = meet_inline_depth(tinst->inline_depth());
3369
3370 const TypeInstPtr *loaded = is_loaded() ? this : tinst;
3371 const TypeInstPtr *unloaded = is_loaded() ? tinst : this;
3372 if( loaded->klass()->equals(ciEnv::current()->Object_klass()) ) {
3373 //
3374 // Meet unloaded class with java/lang/Object
3375 //
3376 // Meet
3377 // | Unloaded Class
3378 // Object | TOP | AnyNull | Constant | NotNull | BOTTOM |
3379 // ===================================================================
3380 // TOP | ..........................Unloaded......................|
3381 // AnyNull | U-AN |................Unloaded......................|
3382 // Constant | ... O-NN .................................. | O-BOT |
3383 // NotNull | ... O-NN .................................. | O-BOT |
3384 // BOTTOM | ........................Object-BOTTOM ..................|
3385 //
3386 assert(loaded->ptr() != TypePtr::Null, "insanity check");
3387 //
3425 case DoubleBot:
3426 case NarrowOop:
3427 case NarrowKlass:
3428 case Bottom: // Ye Olde Default
3429 return Type::BOTTOM;
3430 case Top:
3431 return this;
3432
3433 default: // All else is a mistake
3434 typerr(t);
3435
3436 case MetadataPtr:
3437 case KlassPtr:
3438 case RawPtr: return TypePtr::BOTTOM;
3439
3440 case AryPtr: { // All arrays inherit from Object class
3441 const TypeAryPtr *tp = t->is_aryptr();
3442 int offset = meet_offset(tp->offset());
3443 PTR ptr = meet_ptr(tp->ptr());
3444 int instance_id = meet_instance_id(tp->instance_id());
3445 const TypePtr* speculative = xmeet_speculative(tp);
3446 int depth = meet_inline_depth(tp->inline_depth());
3447 switch (ptr) {
3448 case TopPTR:
3449 case AnyNull: // Fall 'down' to dual of object klass
3450 // For instances when a subclass meets a superclass we fall
3451 // below the centerline when the superclass is exact. We need to
3452 // do the same here.
3453 if (klass()->equals(ciEnv::current()->Object_klass()) && !klass_is_exact()) {
3454 return TypeAryPtr::make(ptr, tp->ary(), tp->klass(), tp->klass_is_exact(), offset, instance_id, speculative, depth);
3455 } else {
3456 // cannot subclass, so the meet has to fall badly below the centerline
3457 ptr = NotNull;
3458 instance_id = InstanceBot;
3459 return TypeInstPtr::make( ptr, ciEnv::current()->Object_klass(), false, NULL, offset, instance_id, speculative, depth);
3460 }
3461 case Constant:
3462 case NotNull:
3463 case BotPTR: // Fall down to object klass
3464 // LCA is object_klass, but if we subclass from the top we can do better
3465 if( above_centerline(_ptr) ) { // if( _ptr == TopPTR || _ptr == AnyNull )
3476 }
3477 // The other case cannot happen, since I cannot be a subtype of an array.
3478 // The meet falls down to Object class below centerline.
3479 if( ptr == Constant )
3480 ptr = NotNull;
3481 instance_id = InstanceBot;
3482 return make(ptr, ciEnv::current()->Object_klass(), false, NULL, offset, instance_id, speculative, depth);
3483 default: typerr(t);
3484 }
3485 }
3486
3487 case OopPtr: { // Meeting to OopPtrs
3488 // Found a OopPtr type vs self-InstPtr type
3489 const TypeOopPtr *tp = t->is_oopptr();
3490 int offset = meet_offset(tp->offset());
3491 PTR ptr = meet_ptr(tp->ptr());
3492 switch (tp->ptr()) {
3493 case TopPTR:
3494 case AnyNull: {
3495 int instance_id = meet_instance_id(InstanceTop);
3496 const TypePtr* speculative = xmeet_speculative(tp);
3497 int depth = meet_inline_depth(tp->inline_depth());
3498 return make(ptr, klass(), klass_is_exact(),
3499 (ptr == Constant ? const_oop() : NULL), offset, instance_id, speculative, depth);
3500 }
3501 case NotNull:
3502 case BotPTR: {
3503 int instance_id = meet_instance_id(tp->instance_id());
3504 const TypePtr* speculative = xmeet_speculative(tp);
3505 int depth = meet_inline_depth(tp->inline_depth());
3506 return TypeOopPtr::make(ptr, offset, instance_id, speculative, depth);
3507 }
3508 default: typerr(t);
3509 }
3510 }
3511
3512 case AnyPtr: { // Meeting to AnyPtrs
3513 // Found an AnyPtr type vs self-InstPtr type
3514 const TypePtr *tp = t->is_ptr();
3515 int offset = meet_offset(tp->offset());
3516 PTR ptr = meet_ptr(tp->ptr());
3517 int instance_id = meet_instance_id(InstanceTop);
3518 const TypePtr* speculative = xmeet_speculative(tp);
3519 int depth = meet_inline_depth(tp->inline_depth());
3520 switch (tp->ptr()) {
3521 case Null:
3522 if( ptr == Null ) return TypePtr::make(AnyPtr, ptr, offset, speculative, depth);
3523 // else fall through to AnyNull
3524 case TopPTR:
3525 case AnyNull: {
3526 return make(ptr, klass(), klass_is_exact(),
3527 (ptr == Constant ? const_oop() : NULL), offset, instance_id, speculative, depth);
3528 }
3529 case NotNull:
3530 case BotPTR:
3531 return TypePtr::make(AnyPtr, ptr, offset, speculative,depth);
3532 default: typerr(t);
3533 }
3534 }
3535
3536 /*
3537 A-top }
3538 / | \ } Tops
3539 B-top A-any C-top }
3540 | / | \ | } Any-nulls
3541 B-any | C-any }
3542 | | |
3543 B-con A-con C-con } constants; not comparable across classes
3544 | | |
3545 B-not | C-not }
3546 | \ | / | } not-nulls
3547 B-bot A-not C-bot }
3548 \ | / } Bottoms
3549 A-bot }
3550 */
3551
3552 case InstPtr: { // Meeting 2 Oops?
3553 // Found an InstPtr sub-type vs self-InstPtr type
3554 const TypeInstPtr *tinst = t->is_instptr();
3555 int off = meet_offset( tinst->offset() );
3556 PTR ptr = meet_ptr( tinst->ptr() );
3557 int instance_id = meet_instance_id(tinst->instance_id());
3558 const TypePtr* speculative = xmeet_speculative(tinst);
3559 int depth = meet_inline_depth(tinst->inline_depth());
3560
3561 // Check for easy case; klasses are equal (and perhaps not loaded!)
3562 // If we have constants, then we created oops so classes are loaded
3563 // and we can handle the constants further down. This case handles
3564 // both-not-loaded or both-loaded classes
3565 if (ptr != Constant && klass()->equals(tinst->klass()) && klass_is_exact() == tinst->klass_is_exact()) {
3566 return make(ptr, klass(), klass_is_exact(), NULL, off, instance_id, speculative, depth);
3567 }
3568
3569 // Classes require inspection in the Java klass hierarchy. Must be loaded.
3570 ciKlass* tinst_klass = tinst->klass();
3571 ciKlass* this_klass = this->klass();
3572 bool tinst_xk = tinst->klass_is_exact();
3573 bool this_xk = this->klass_is_exact();
3574 if (!tinst_klass->is_loaded() || !this_klass->is_loaded() ) {
3575 // One of these classes has not been loaded
3576 const TypeInstPtr *unloaded_meet = xmeet_unloaded(tinst);
3577 #ifndef PRODUCT
3578 if( PrintOpto && Verbose ) {
3694 ciObject* this_oop = const_oop();
3695 ciObject* tinst_oop = tinst->const_oop();
3696 if( ptr == Constant ) {
3697 if (this_oop != NULL && tinst_oop != NULL &&
3698 this_oop->equals(tinst_oop) )
3699 o = this_oop;
3700 else if (above_centerline(this ->_ptr))
3701 o = tinst_oop;
3702 else if (above_centerline(tinst ->_ptr))
3703 o = this_oop;
3704 else
3705 ptr = NotNull;
3706 }
3707 return make(ptr, this_klass, this_xk, o, off, instance_id, speculative, depth);
3708 } // Else classes are not equal
3709
3710 // Since klasses are different, we require a LCA in the Java
3711 // class hierarchy - which means we have to fall to at least NotNull.
3712 if( ptr == TopPTR || ptr == AnyNull || ptr == Constant )
3713 ptr = NotNull;
3714
3715 instance_id = InstanceBot;
3716
3717 // Now we find the LCA of Java classes
3718 ciKlass* k = this_klass->least_common_ancestor(tinst_klass);
3719 return make(ptr, k, false, NULL, off, instance_id, speculative, depth);
3720 } // End of case InstPtr
3721
3722 } // End of switch
3723 return this; // Return the double constant
3724 }
3725
3726
3727 //------------------------java_mirror_type--------------------------------------
3728 ciType* TypeInstPtr::java_mirror_type() const {
3729 // must be a singleton type
3730 if( const_oop() == NULL ) return NULL;
3731
3732 // must be of type java.lang.Class
3733 if( klass() != ciEnv::current()->Class_klass() ) return NULL;
3734
3787
3788 if( _offset ) { // Dump offset, if any
3789 if( _offset == OffsetBot ) st->print("+any");
3790 else if( _offset == OffsetTop ) st->print("+unknown");
3791 else st->print("+%d", _offset);
3792 }
3793
3794 st->print(" *");
3795 if (_instance_id == InstanceTop)
3796 st->print(",iid=top");
3797 else if (_instance_id != InstanceBot)
3798 st->print(",iid=%d",_instance_id);
3799
3800 dump_inline_depth(st);
3801 dump_speculative(st);
3802 }
3803 #endif
3804
3805 //------------------------------add_offset-------------------------------------
3806 const TypePtr *TypeInstPtr::add_offset(intptr_t offset) const {
3807 return make(_ptr, klass(), klass_is_exact(), const_oop(), xadd_offset(offset),
3808 _instance_id, add_offset_speculative(offset), _inline_depth);
3809 }
3810
3811 const Type *TypeInstPtr::remove_speculative() const {
3812 if (_speculative == NULL) {
3813 return this;
3814 }
3815 assert(_inline_depth == InlineDepthTop || _inline_depth == InlineDepthBottom, "non speculative type shouldn't have inline depth");
3816 return make(_ptr, klass(), klass_is_exact(), const_oop(), _offset,
3817 _instance_id, NULL, _inline_depth);
3818 }
3819
3820 const TypePtr *TypeInstPtr::with_inline_depth(int depth) const {
3821 if (!UseInlineDepthForSpeculativeTypes) {
3822 return this;
3823 }
3824 return make(_ptr, klass(), klass_is_exact(), const_oop(), _offset, _instance_id, _speculative, depth);
3825 }
3826
3827 //=============================================================================
3828 // Convenience common pre-built types.
3829 const TypeAryPtr *TypeAryPtr::RANGE;
3830 const TypeAryPtr *TypeAryPtr::OOPS;
3831 const TypeAryPtr *TypeAryPtr::NARROWOOPS;
3832 const TypeAryPtr *TypeAryPtr::BYTES;
3833 const TypeAryPtr *TypeAryPtr::SHORTS;
3834 const TypeAryPtr *TypeAryPtr::CHARS;
3835 const TypeAryPtr *TypeAryPtr::INTS;
3836 const TypeAryPtr *TypeAryPtr::LONGS;
3837 const TypeAryPtr *TypeAryPtr::FLOATS;
3838 const TypeAryPtr *TypeAryPtr::DOUBLES;
3839
3840 //------------------------------make-------------------------------------------
3841 const TypeAryPtr *TypeAryPtr::make(PTR ptr, const TypeAry *ary, ciKlass* k, bool xk, int offset,
3842 int instance_id, const TypePtr* speculative, int inline_depth) {
3843 assert(!(k == NULL && ary->_elem->isa_int()),
3844 "integral arrays must be pre-equipped with a class");
3845 if (!xk) xk = ary->ary_must_be_exact();
3846 assert(instance_id <= 0 || xk || !UseExactTypes, "instances are always exactly typed");
3847 if (!UseExactTypes) xk = (ptr == Constant);
3848 return (TypeAryPtr*)(new TypeAryPtr(ptr, NULL, ary, k, xk, offset, instance_id, false, speculative, inline_depth))->hashcons();
3849 }
3850
3851 //------------------------------make-------------------------------------------
3852 const TypeAryPtr *TypeAryPtr::make(PTR ptr, ciObject* o, const TypeAry *ary, ciKlass* k, bool xk, int offset,
3853 int instance_id, const TypePtr* speculative, int inline_depth,
3854 bool is_autobox_cache) {
3855 assert(!(k == NULL && ary->_elem->isa_int()),
3856 "integral arrays must be pre-equipped with a class");
3857 assert( (ptr==Constant && o) || (ptr!=Constant && !o), "" );
3858 if (!xk) xk = (o != NULL) || ary->ary_must_be_exact();
3859 assert(instance_id <= 0 || xk || !UseExactTypes, "instances are always exactly typed");
3860 if (!UseExactTypes) xk = (ptr == Constant);
3861 return (TypeAryPtr*)(new TypeAryPtr(ptr, o, ary, k, xk, offset, instance_id, is_autobox_cache, speculative, inline_depth))->hashcons();
3862 }
3863
3864 //------------------------------cast_to_ptr_type-------------------------------
3865 const Type *TypeAryPtr::cast_to_ptr_type(PTR ptr) const {
3866 if( ptr == _ptr ) return this;
3867 return make(ptr, const_oop(), _ary, klass(), klass_is_exact(), _offset, _instance_id, _speculative, _inline_depth);
3868 }
3869
3870
3871 //-----------------------------cast_to_exactness-------------------------------
3872 const Type *TypeAryPtr::cast_to_exactness(bool klass_is_exact) const {
3873 if( klass_is_exact == _klass_is_exact ) return this;
3874 if (!UseExactTypes) return this;
3944 const TypeAry* new_ary = TypeAry::make(elem(), new_size, is_stable());
3945 return make(ptr(), const_oop(), new_ary, klass(), klass_is_exact(), _offset, _instance_id, _speculative, _inline_depth);
3946 }
3947
3948
3949 //------------------------------cast_to_stable---------------------------------
3950 const TypeAryPtr* TypeAryPtr::cast_to_stable(bool stable, int stable_dimension) const {
3951 if (stable_dimension <= 0 || (stable_dimension == 1 && stable == this->is_stable()))
3952 return this;
3953
3954 const Type* elem = this->elem();
3955 const TypePtr* elem_ptr = elem->make_ptr();
3956
3957 if (stable_dimension > 1 && elem_ptr != NULL && elem_ptr->isa_aryptr()) {
3958 // If this is widened from a narrow oop, TypeAry::make will re-narrow it.
3959 elem = elem_ptr = elem_ptr->is_aryptr()->cast_to_stable(stable, stable_dimension - 1);
3960 }
3961
3962 const TypeAry* new_ary = TypeAry::make(elem, size(), stable);
3963
3964 return make(ptr(), const_oop(), new_ary, klass(), klass_is_exact(), _offset, _instance_id, _speculative, _inline_depth);
3965 }
3966
3967 //-----------------------------stable_dimension--------------------------------
3968 int TypeAryPtr::stable_dimension() const {
3969 if (!is_stable()) return 0;
3970 int dim = 1;
3971 const TypePtr* elem_ptr = elem()->make_ptr();
3972 if (elem_ptr != NULL && elem_ptr->isa_aryptr())
3973 dim += elem_ptr->is_aryptr()->stable_dimension();
3974 return dim;
3975 }
3976
3977 //------------------------------eq---------------------------------------------
3978 // Structural equality check for Type representations
3979 bool TypeAryPtr::eq( const Type *t ) const {
3980 const TypeAryPtr *p = t->is_aryptr();
3981 return
3982 _ary == p->_ary && // Check array
3983 TypeOopPtr::eq(p); // Check sub-parts
3984 }
4005 case FloatBot:
4006 case DoubleTop:
4007 case DoubleCon:
4008 case DoubleBot:
4009 case NarrowOop:
4010 case NarrowKlass:
4011 case Bottom: // Ye Olde Default
4012 return Type::BOTTOM;
4013 case Top:
4014 return this;
4015
4016 default: // All else is a mistake
4017 typerr(t);
4018
4019 case OopPtr: { // Meeting to OopPtrs
4020 // Found a OopPtr type vs self-AryPtr type
4021 const TypeOopPtr *tp = t->is_oopptr();
4022 int offset = meet_offset(tp->offset());
4023 PTR ptr = meet_ptr(tp->ptr());
4024 int depth = meet_inline_depth(tp->inline_depth());
4025 const TypePtr* speculative = xmeet_speculative(tp);
4026 switch (tp->ptr()) {
4027 case TopPTR:
4028 case AnyNull: {
4029 int instance_id = meet_instance_id(InstanceTop);
4030 return make(ptr, (ptr == Constant ? const_oop() : NULL),
4031 _ary, _klass, _klass_is_exact, offset, instance_id, speculative, depth);
4032 }
4033 case BotPTR:
4034 case NotNull: {
4035 int instance_id = meet_instance_id(tp->instance_id());
4036 return TypeOopPtr::make(ptr, offset, instance_id, speculative, depth);
4037 }
4038 default: ShouldNotReachHere();
4039 }
4040 }
4041
4042 case AnyPtr: { // Meeting two AnyPtrs
4043 // Found an AnyPtr type vs self-AryPtr type
4044 const TypePtr *tp = t->is_ptr();
4045 int offset = meet_offset(tp->offset());
4046 PTR ptr = meet_ptr(tp->ptr());
4047 const TypePtr* speculative = xmeet_speculative(tp);
4048 int depth = meet_inline_depth(tp->inline_depth());
4049 switch (tp->ptr()) {
4050 case TopPTR:
4051 return this;
4052 case BotPTR:
4053 case NotNull:
4054 return TypePtr::make(AnyPtr, ptr, offset, speculative, depth);
4055 case Null:
4056 if( ptr == Null ) return TypePtr::make(AnyPtr, ptr, offset, speculative, depth);
4057 // else fall through to AnyNull
4058 case AnyNull: {
4059 int instance_id = meet_instance_id(InstanceTop);
4060 return make(ptr, (ptr == Constant ? const_oop() : NULL),
4061 _ary, _klass, _klass_is_exact, offset, instance_id, speculative, depth);
4062 }
4063 default: ShouldNotReachHere();
4064 }
4065 }
4066
4067 case MetadataPtr:
4068 case KlassPtr:
4069 case RawPtr: return TypePtr::BOTTOM;
4070
4071 case AryPtr: { // Meeting 2 references?
4072 const TypeAryPtr *tap = t->is_aryptr();
4073 int off = meet_offset(tap->offset());
4074 const TypeAry *tary = _ary->meet_speculative(tap->_ary)->is_ary();
4075 PTR ptr = meet_ptr(tap->ptr());
4076 int instance_id = meet_instance_id(tap->instance_id());
4077 const TypePtr* speculative = xmeet_speculative(tap);
4078 int depth = meet_inline_depth(tap->inline_depth());
4079 ciKlass* lazy_klass = NULL;
4080 if (tary->_elem->isa_int()) {
4081 // Integral array element types have irrelevant lattice relations.
4082 // It is the klass that determines array layout, not the element type.
4083 if (_klass == NULL)
4084 lazy_klass = tap->_klass;
4085 else if (tap->_klass == NULL || tap->_klass == _klass) {
4086 lazy_klass = _klass;
4087 } else {
4088 // Something like byte[int+] meets char[int+].
4089 // This must fall to bottom, not (int[-128..65535])[int+].
4090 instance_id = InstanceBot;
4091 tary = TypeAry::make(Type::BOTTOM, tary->_size, tary->_stable);
4092 }
4093 } else // Non integral arrays.
4094 // Must fall to bottom if exact klasses in upper lattice
4095 // are not equal or super klass is exact.
4096 if ((above_centerline(ptr) || ptr == Constant) && klass() != tap->klass() &&
4097 // meet with top[] and bottom[] are processed further down:
4098 tap->_klass != NULL && this->_klass != NULL &&
4099 // both are exact and not equal:
4100 ((tap->_klass_is_exact && this->_klass_is_exact) ||
4101 // 'tap' is exact and super or unrelated:
4102 (tap->_klass_is_exact && !tap->klass()->is_subtype_of(klass())) ||
4103 // 'this' is exact and super or unrelated:
4104 (this->_klass_is_exact && !klass()->is_subtype_of(tap->klass())))) {
4105 tary = TypeAry::make(Type::BOTTOM, tary->_size, tary->_stable);
4106 return make(NotNull, NULL, tary, lazy_klass, false, off, InstanceBot, speculative, depth);
4107 }
4108
4109 bool xk = false;
4110 switch (tap->ptr()) {
4111 case AnyNull:
4112 case TopPTR:
4113 // Compute new klass on demand, do not use tap->_klass
4114 if (below_centerline(this->_ptr)) {
4115 xk = this->_klass_is_exact;
4116 } else {
4117 xk = (tap->_klass_is_exact | this->_klass_is_exact);
4118 }
4119 return make(ptr, const_oop(), tary, lazy_klass, xk, off, instance_id, speculative, depth);
4120 case Constant: {
4121 ciObject* o = const_oop();
4122 if( _ptr == Constant ) {
4123 if( tap->const_oop() != NULL && !o->equals(tap->const_oop()) ) {
4124 xk = (klass() == tap->klass());
4125 ptr = NotNull;
4126 o = NULL;
4138 return TypeAryPtr::make(ptr, o, tary, lazy_klass, xk, off, instance_id, speculative, depth);
4139 }
4140 case NotNull:
4141 case BotPTR:
4142 // Compute new klass on demand, do not use tap->_klass
4143 if (above_centerline(this->_ptr))
4144 xk = tap->_klass_is_exact;
4145 else xk = (tap->_klass_is_exact & this->_klass_is_exact) &&
4146 (klass() == tap->klass()); // Only precise for identical arrays
4147 return TypeAryPtr::make(ptr, NULL, tary, lazy_klass, xk, off, instance_id, speculative, depth);
4148 default: ShouldNotReachHere();
4149 }
4150 }
4151
4152 // All arrays inherit from Object class
4153 case InstPtr: {
4154 const TypeInstPtr *tp = t->is_instptr();
4155 int offset = meet_offset(tp->offset());
4156 PTR ptr = meet_ptr(tp->ptr());
4157 int instance_id = meet_instance_id(tp->instance_id());
4158 const TypePtr* speculative = xmeet_speculative(tp);
4159 int depth = meet_inline_depth(tp->inline_depth());
4160 switch (ptr) {
4161 case TopPTR:
4162 case AnyNull: // Fall 'down' to dual of object klass
4163 // For instances when a subclass meets a superclass we fall
4164 // below the centerline when the superclass is exact. We need to
4165 // do the same here.
4166 if (tp->klass()->equals(ciEnv::current()->Object_klass()) && !tp->klass_is_exact()) {
4167 return TypeAryPtr::make(ptr, _ary, _klass, _klass_is_exact, offset, instance_id, speculative, depth);
4168 } else {
4169 // cannot subclass, so the meet has to fall badly below the centerline
4170 ptr = NotNull;
4171 instance_id = InstanceBot;
4172 return TypeInstPtr::make(ptr, ciEnv::current()->Object_klass(), false, NULL,offset, instance_id, speculative, depth);
4173 }
4174 case Constant:
4175 case NotNull:
4176 case BotPTR: // Fall down to object klass
4177 // LCA is object_klass, but if we subclass from the top we can do better
4178 if (above_centerline(tp->ptr())) {
4262 #endif
4263
4264 bool TypeAryPtr::empty(void) const {
4265 if (_ary->empty()) return true;
4266 return TypeOopPtr::empty();
4267 }
4268
4269 //------------------------------add_offset-------------------------------------
4270 const TypePtr *TypeAryPtr::add_offset(intptr_t offset) const {
4271 return make(_ptr, _const_oop, _ary, _klass, _klass_is_exact, xadd_offset(offset), _instance_id, add_offset_speculative(offset), _inline_depth);
4272 }
4273
4274 const Type *TypeAryPtr::remove_speculative() const {
4275 if (_speculative == NULL) {
4276 return this;
4277 }
4278 assert(_inline_depth == InlineDepthTop || _inline_depth == InlineDepthBottom, "non speculative type shouldn't have inline depth");
4279 return make(_ptr, _const_oop, _ary->remove_speculative()->is_ary(), _klass, _klass_is_exact, _offset, _instance_id, NULL, _inline_depth);
4280 }
4281
4282 const TypePtr *TypeAryPtr::with_inline_depth(int depth) const {
4283 if (!UseInlineDepthForSpeculativeTypes) {
4284 return this;
4285 }
4286 return make(_ptr, _const_oop, _ary->remove_speculative()->is_ary(), _klass, _klass_is_exact, _offset, _instance_id, _speculative, depth);
4287 }
4288
4289 //=============================================================================
4290
4291 //------------------------------hash-------------------------------------------
4292 // Type-specific hashing function.
4293 int TypeNarrowPtr::hash(void) const {
4294 return _ptrtype->hash() + 7;
4295 }
4296
4297 bool TypeNarrowPtr::singleton(void) const { // TRUE if type is a singleton
4298 return _ptrtype->singleton();
4299 }
4300
4301 bool TypeNarrowPtr::empty(void) const {
4302 return _ptrtype->empty();
4387
4388 } // End of switch
4389
4390 return this;
4391 }
4392
4393 #ifndef PRODUCT
4394 void TypeNarrowPtr::dump2( Dict & d, uint depth, outputStream *st ) const {
4395 _ptrtype->dump2(d, depth, st);
4396 }
4397 #endif
4398
4399 const TypeNarrowOop *TypeNarrowOop::BOTTOM;
4400 const TypeNarrowOop *TypeNarrowOop::NULL_PTR;
4401
4402
4403 const TypeNarrowOop* TypeNarrowOop::make(const TypePtr* type) {
4404 return (const TypeNarrowOop*)(new TypeNarrowOop(type))->hashcons();
4405 }
4406
4407 const Type* TypeNarrowOop::remove_speculative() const {
4408 return make(_ptrtype->remove_speculative()->is_ptr());
4409 }
4410
4411 const Type* TypeNarrowOop::cleanup_speculative() const {
4412 return make(_ptrtype->cleanup_speculative()->is_ptr());
4413 }
4414
4415 #ifndef PRODUCT
4416 void TypeNarrowOop::dump2( Dict & d, uint depth, outputStream *st ) const {
4417 st->print("narrowoop: ");
4418 TypeNarrowPtr::dump2(d, depth, st);
4419 }
4420 #endif
4421
4422 const TypeNarrowKlass *TypeNarrowKlass::NULL_PTR;
4423
4424 const TypeNarrowKlass* TypeNarrowKlass::make(const TypePtr* type) {
4425 return (const TypeNarrowKlass*)(new TypeNarrowKlass(type))->hashcons();
4426 }
4427
4428 #ifndef PRODUCT
4429 void TypeNarrowKlass::dump2( Dict & d, uint depth, outputStream *st ) const {
4430 st->print("narrowklass: ");
4431 TypeNarrowPtr::dump2(d, depth, st);
4432 }
4433 #endif
4520 case DoubleTop:
4521 case DoubleCon:
4522 case DoubleBot:
4523 case NarrowOop:
4524 case NarrowKlass:
4525 case Bottom: // Ye Olde Default
4526 return Type::BOTTOM;
4527 case Top:
4528 return this;
4529
4530 default: // All else is a mistake
4531 typerr(t);
4532
4533 case AnyPtr: {
4534 // Found an AnyPtr type vs self-OopPtr type
4535 const TypePtr *tp = t->is_ptr();
4536 int offset = meet_offset(tp->offset());
4537 PTR ptr = meet_ptr(tp->ptr());
4538 switch (tp->ptr()) {
4539 case Null:
4540 if (ptr == Null) return TypePtr::make(AnyPtr, ptr, offset, tp->speculative(), tp->inline_depth());
4541 // else fall through:
4542 case TopPTR:
4543 case AnyNull: {
4544 return make(ptr, _metadata, offset);
4545 }
4546 case BotPTR:
4547 case NotNull:
4548 return TypePtr::make(AnyPtr, ptr, offset, tp->speculative(), tp->inline_depth());
4549 default: typerr(t);
4550 }
4551 }
4552
4553 case RawPtr:
4554 case KlassPtr:
4555 case OopPtr:
4556 case InstPtr:
4557 case AryPtr:
4558 return TypePtr::BOTTOM; // Oop meet raw is not well defined
4559
4560 case MetadataPtr: {
4561 const TypeMetadataPtr *tp = t->is_metadataptr();
4562 int offset = meet_offset(tp->offset());
4563 PTR tptr = tp->ptr();
4564 PTR ptr = meet_ptr(tptr);
4565 ciMetadata* md = (tptr == TopPTR) ? metadata() : tp->metadata();
4566 if (tptr == TopPTR || _ptr == TopPTR ||
4567 metadata()->equals(tp->metadata())) {
4568 return make(ptr, md, offset);
4842 case DoubleBot:
4843 case NarrowOop:
4844 case NarrowKlass:
4845 case Bottom: // Ye Olde Default
4846 return Type::BOTTOM;
4847 case Top:
4848 return this;
4849
4850 default: // All else is a mistake
4851 typerr(t);
4852
4853 case AnyPtr: { // Meeting to AnyPtrs
4854 // Found an AnyPtr type vs self-KlassPtr type
4855 const TypePtr *tp = t->is_ptr();
4856 int offset = meet_offset(tp->offset());
4857 PTR ptr = meet_ptr(tp->ptr());
4858 switch (tp->ptr()) {
4859 case TopPTR:
4860 return this;
4861 case Null:
4862 if( ptr == Null ) return TypePtr::make(AnyPtr, ptr, offset, tp->speculative(), tp->inline_depth());
4863 case AnyNull:
4864 return make( ptr, klass(), offset );
4865 case BotPTR:
4866 case NotNull:
4867 return TypePtr::make(AnyPtr, ptr, offset, tp->speculative(), tp->inline_depth());
4868 default: typerr(t);
4869 }
4870 }
4871
4872 case RawPtr:
4873 case MetadataPtr:
4874 case OopPtr:
4875 case AryPtr: // Meet with AryPtr
4876 case InstPtr: // Meet with InstPtr
4877 return TypePtr::BOTTOM;
4878
4879 //
4880 // A-top }
4881 // / | \ } Tops
4882 // B-top A-any C-top }
4883 // | / | \ | } Any-nulls
4884 // B-any | C-any }
4885 // | | |
4886 // B-con A-con C-con } constants; not comparable across classes
4887 // | | |
|