hotspot/src/share/vm/opto/graphKit.cpp
changeset 26166 4b49fd58bbd9
parent 25930 eae8b7490d2c
child 27150 5a09b3a7b974
equal deleted inserted replaced
25938:d1161ea75e14 26166:4b49fd58bbd9
  2518 
  2518 
  2519   // Get the no-exception control from the CatchNode.
  2519   // Get the no-exception control from the CatchNode.
  2520   set_control(norm);
  2520   set_control(norm);
  2521 }
  2521 }
  2522 
  2522 
       
  2523 static IfNode* gen_subtype_check_compare(Node* ctrl, Node* in1, Node* in2, BoolTest::mask test, float p, PhaseGVN* gvn, BasicType bt) {
       
  2524   Node* cmp = NULL;
       
  2525   switch(bt) {
       
  2526   case T_INT: cmp = new CmpINode(in1, in2); break;
       
  2527   case T_ADDRESS: cmp = new CmpPNode(in1, in2); break;
       
  2528   default: fatal(err_msg("unexpected comparison type %s", type2name(bt)));
       
  2529   }
       
  2530   gvn->transform(cmp);
       
  2531   Node* bol = gvn->transform(new BoolNode(cmp, test));
       
  2532   IfNode* iff = new IfNode(ctrl, bol, p, COUNT_UNKNOWN);
       
  2533   gvn->transform(iff);
       
  2534   if (!bol->is_Con()) gvn->record_for_igvn(iff);
       
  2535   return iff;
       
  2536 }
       
  2537 
  2523 
  2538 
  2524 //-------------------------------gen_subtype_check-----------------------------
  2539 //-------------------------------gen_subtype_check-----------------------------
  2525 // Generate a subtyping check.  Takes as input the subtype and supertype.
  2540 // Generate a subtyping check.  Takes as input the subtype and supertype.
  2526 // Returns 2 values: sets the default control() to the true path and returns
  2541 // Returns 2 values: sets the default control() to the true path and returns
  2527 // the false path.  Only reads invariant memory; sets no (visible) memory.
  2542 // the false path.  Only reads invariant memory; sets no (visible) memory.
  2528 // The PartialSubtypeCheckNode sets the hidden 1-word cache in the encoding
  2543 // The PartialSubtypeCheckNode sets the hidden 1-word cache in the encoding
  2529 // but that's not exposed to the optimizer.  This call also doesn't take in an
  2544 // but that's not exposed to the optimizer.  This call also doesn't take in an
  2530 // Object; if you wish to check an Object you need to load the Object's class
  2545 // Object; if you wish to check an Object you need to load the Object's class
  2531 // prior to coming here.
  2546 // prior to coming here.
  2532 Node* GraphKit::gen_subtype_check(Node* subklass, Node* superklass) {
  2547 Node* Phase::gen_subtype_check(Node* subklass, Node* superklass, Node** ctrl, MergeMemNode* mem, PhaseGVN* gvn) {
       
  2548   Compile* C = gvn->C;
  2533   // Fast check for identical types, perhaps identical constants.
  2549   // Fast check for identical types, perhaps identical constants.
  2534   // The types can even be identical non-constants, in cases
  2550   // The types can even be identical non-constants, in cases
  2535   // involving Array.newInstance, Object.clone, etc.
  2551   // involving Array.newInstance, Object.clone, etc.
  2536   if (subklass == superklass)
  2552   if (subklass == superklass)
  2537     return top();             // false path is dead; no test needed.
  2553     return C->top();             // false path is dead; no test needed.
  2538 
  2554 
  2539   if (_gvn.type(superklass)->singleton()) {
  2555   if (gvn->type(superklass)->singleton()) {
  2540     ciKlass* superk = _gvn.type(superklass)->is_klassptr()->klass();
  2556     ciKlass* superk = gvn->type(superklass)->is_klassptr()->klass();
  2541     ciKlass* subk   = _gvn.type(subklass)->is_klassptr()->klass();
  2557     ciKlass* subk   = gvn->type(subklass)->is_klassptr()->klass();
  2542 
  2558 
  2543     // In the common case of an exact superklass, try to fold up the
  2559     // In the common case of an exact superklass, try to fold up the
  2544     // test before generating code.  You may ask, why not just generate
  2560     // test before generating code.  You may ask, why not just generate
  2545     // the code and then let it fold up?  The answer is that the generated
  2561     // the code and then let it fold up?  The answer is that the generated
  2546     // code will necessarily include null checks, which do not always
  2562     // code will necessarily include null checks, which do not always
  2547     // completely fold away.  If they are also needless, then they turn
  2563     // completely fold away.  If they are also needless, then they turn
  2548     // into a performance loss.  Example:
  2564     // into a performance loss.  Example:
  2549     //    Foo[] fa = blah(); Foo x = fa[0]; fa[1] = x;
  2565     //    Foo[] fa = blah(); Foo x = fa[0]; fa[1] = x;
  2550     // Here, the type of 'fa' is often exact, so the store check
  2566     // Here, the type of 'fa' is often exact, so the store check
  2551     // of fa[1]=x will fold up, without testing the nullness of x.
  2567     // of fa[1]=x will fold up, without testing the nullness of x.
  2552     switch (static_subtype_check(superk, subk)) {
  2568     switch (C->static_subtype_check(superk, subk)) {
  2553     case SSC_always_false:
  2569     case Compile::SSC_always_false:
  2554       {
  2570       {
  2555         Node* always_fail = control();
  2571         Node* always_fail = *ctrl;
  2556         set_control(top());
  2572         *ctrl = gvn->C->top();
  2557         return always_fail;
  2573         return always_fail;
  2558       }
  2574       }
  2559     case SSC_always_true:
  2575     case Compile::SSC_always_true:
  2560       return top();
  2576       return C->top();
  2561     case SSC_easy_test:
  2577     case Compile::SSC_easy_test:
  2562       {
  2578       {
  2563         // Just do a direct pointer compare and be done.
  2579         // Just do a direct pointer compare and be done.
  2564         Node* cmp = _gvn.transform( new CmpPNode(subklass, superklass) );
  2580         IfNode* iff = gen_subtype_check_compare(*ctrl, subklass, superklass, BoolTest::eq, PROB_STATIC_FREQUENT, gvn, T_ADDRESS);
  2565         Node* bol = _gvn.transform( new BoolNode(cmp, BoolTest::eq) );
  2581         *ctrl = gvn->transform(new IfTrueNode(iff));
  2566         IfNode* iff = create_and_xform_if(control(), bol, PROB_STATIC_FREQUENT, COUNT_UNKNOWN);
  2582         return gvn->transform(new IfFalseNode(iff));
  2567         set_control( _gvn.transform( new IfTrueNode (iff) ) );
       
  2568         return       _gvn.transform( new IfFalseNode(iff) );
       
  2569       }
  2583       }
  2570     case SSC_full_test:
  2584     case Compile::SSC_full_test:
  2571       break;
  2585       break;
  2572     default:
  2586     default:
  2573       ShouldNotReachHere();
  2587       ShouldNotReachHere();
  2574     }
  2588     }
  2575   }
  2589   }
  2577   // %%% Possible further optimization:  Even if the superklass is not exact,
  2591   // %%% Possible further optimization:  Even if the superklass is not exact,
  2578   // if the subklass is the unique subtype of the superklass, the check
  2592   // if the subklass is the unique subtype of the superklass, the check
  2579   // will always succeed.  We could leave a dependency behind to ensure this.
  2593   // will always succeed.  We could leave a dependency behind to ensure this.
  2580 
  2594 
  2581   // First load the super-klass's check-offset
  2595   // First load the super-klass's check-offset
  2582   Node *p1 = basic_plus_adr( superklass, superklass, in_bytes(Klass::super_check_offset_offset()) );
  2596   Node *p1 = gvn->transform(new AddPNode(superklass, superklass, gvn->MakeConX(in_bytes(Klass::super_check_offset_offset()))));
  2583   Node *chk_off = _gvn.transform(new LoadINode(NULL, memory(p1), p1, _gvn.type(p1)->is_ptr(),
  2597   Node* m = mem->memory_at(C->get_alias_index(gvn->type(p1)->is_ptr()));
  2584                                                    TypeInt::INT, MemNode::unordered));
  2598   Node *chk_off = gvn->transform(new LoadINode(NULL, m, p1, gvn->type(p1)->is_ptr(), TypeInt::INT, MemNode::unordered));
  2585   int cacheoff_con = in_bytes(Klass::secondary_super_cache_offset());
  2599   int cacheoff_con = in_bytes(Klass::secondary_super_cache_offset());
  2586   bool might_be_cache = (find_int_con(chk_off, cacheoff_con) == cacheoff_con);
  2600   bool might_be_cache = (gvn->find_int_con(chk_off, cacheoff_con) == cacheoff_con);
  2587 
  2601 
  2588   // Load from the sub-klass's super-class display list, or a 1-word cache of
  2602   // Load from the sub-klass's super-class display list, or a 1-word cache of
  2589   // the secondary superclass list, or a failing value with a sentinel offset
  2603   // the secondary superclass list, or a failing value with a sentinel offset
  2590   // if the super-klass is an interface or exceptionally deep in the Java
  2604   // if the super-klass is an interface or exceptionally deep in the Java
  2591   // hierarchy and we have to scan the secondary superclass list the hard way.
  2605   // hierarchy and we have to scan the secondary superclass list the hard way.
  2592   // Worst-case type is a little odd: NULL is allowed as a result (usually
  2606   // Worst-case type is a little odd: NULL is allowed as a result (usually
  2593   // klass loads can never produce a NULL).
  2607   // klass loads can never produce a NULL).
  2594   Node *chk_off_X = ConvI2X(chk_off);
  2608   Node *chk_off_X = chk_off;
  2595   Node *p2 = _gvn.transform( new AddPNode(subklass,subklass,chk_off_X) );
  2609 #ifdef _LP64
       
  2610   chk_off_X = gvn->transform(new ConvI2LNode(chk_off_X));
       
  2611 #endif
       
  2612   Node *p2 = gvn->transform(new AddPNode(subklass,subklass,chk_off_X));
  2596   // For some types like interfaces the following loadKlass is from a 1-word
  2613   // For some types like interfaces the following loadKlass is from a 1-word
  2597   // cache which is mutable so can't use immutable memory.  Other
  2614   // cache which is mutable so can't use immutable memory.  Other
  2598   // types load from the super-class display table which is immutable.
  2615   // types load from the super-class display table which is immutable.
  2599   Node *kmem = might_be_cache ? memory(p2) : immutable_memory();
  2616   m = mem->memory_at(C->get_alias_index(gvn->type(p2)->is_ptr()));
  2600   Node *nkls = _gvn.transform( LoadKlassNode::make( _gvn, kmem, p2, _gvn.type(p2)->is_ptr(), TypeKlassPtr::OBJECT_OR_NULL ) );
  2617   Node *kmem = might_be_cache ? m : C->immutable_memory();
       
  2618   Node *nkls = gvn->transform(LoadKlassNode::make(*gvn, kmem, p2, gvn->type(p2)->is_ptr(), TypeKlassPtr::OBJECT_OR_NULL));
  2601 
  2619 
  2602   // Compile speed common case: ARE a subtype and we canNOT fail
  2620   // Compile speed common case: ARE a subtype and we canNOT fail
  2603   if( superklass == nkls )
  2621   if( superklass == nkls )
  2604     return top();             // false path is dead; no test needed.
  2622     return C->top();             // false path is dead; no test needed.
  2605 
  2623 
  2606   // See if we get an immediate positive hit.  Happens roughly 83% of the
  2624   // See if we get an immediate positive hit.  Happens roughly 83% of the
  2607   // time.  Test to see if the value loaded just previously from the subklass
  2625   // time.  Test to see if the value loaded just previously from the subklass
  2608   // is exactly the superklass.
  2626   // is exactly the superklass.
  2609   Node *cmp1 = _gvn.transform( new CmpPNode( superklass, nkls ) );
  2627   IfNode *iff1 = gen_subtype_check_compare(*ctrl, superklass, nkls, BoolTest::eq, PROB_LIKELY(0.83f), gvn, T_ADDRESS);
  2610   Node *bol1 = _gvn.transform( new BoolNode( cmp1, BoolTest::eq ) );
  2628   Node *iftrue1 = gvn->transform( new IfTrueNode (iff1));
  2611   IfNode *iff1 = create_and_xform_if( control(), bol1, PROB_LIKELY(0.83f), COUNT_UNKNOWN );
  2629   *ctrl = gvn->transform(new IfFalseNode(iff1));
  2612   Node *iftrue1 = _gvn.transform( new IfTrueNode ( iff1 ) );
       
  2613   set_control(    _gvn.transform( new IfFalseNode( iff1 ) ) );
       
  2614 
  2630 
  2615   // Compile speed common case: Check for being deterministic right now.  If
  2631   // Compile speed common case: Check for being deterministic right now.  If
  2616   // chk_off is a constant and not equal to cacheoff then we are NOT a
  2632   // chk_off is a constant and not equal to cacheoff then we are NOT a
  2617   // subklass.  In this case we need exactly the 1 test above and we can
  2633   // subklass.  In this case we need exactly the 1 test above and we can
  2618   // return those results immediately.
  2634   // return those results immediately.
  2619   if (!might_be_cache) {
  2635   if (!might_be_cache) {
  2620     Node* not_subtype_ctrl = control();
  2636     Node* not_subtype_ctrl = *ctrl;
  2621     set_control(iftrue1); // We need exactly the 1 test above
  2637     *ctrl = iftrue1; // We need exactly the 1 test above
  2622     return not_subtype_ctrl;
  2638     return not_subtype_ctrl;
  2623   }
  2639   }
  2624 
  2640 
  2625   // Gather the various success & failures here
  2641   // Gather the various success & failures here
  2626   RegionNode *r_ok_subtype = new RegionNode(4);
  2642   RegionNode *r_ok_subtype = new RegionNode(4);
  2627   record_for_igvn(r_ok_subtype);
  2643   gvn->record_for_igvn(r_ok_subtype);
  2628   RegionNode *r_not_subtype = new RegionNode(3);
  2644   RegionNode *r_not_subtype = new RegionNode(3);
  2629   record_for_igvn(r_not_subtype);
  2645   gvn->record_for_igvn(r_not_subtype);
  2630 
  2646 
  2631   r_ok_subtype->init_req(1, iftrue1);
  2647   r_ok_subtype->init_req(1, iftrue1);
  2632 
  2648 
  2633   // Check for immediate negative hit.  Happens roughly 11% of the time (which
  2649   // Check for immediate negative hit.  Happens roughly 11% of the time (which
  2634   // is roughly 63% of the remaining cases).  Test to see if the loaded
  2650   // is roughly 63% of the remaining cases).  Test to see if the loaded
  2635   // check-offset points into the subklass display list or the 1-element
  2651   // check-offset points into the subklass display list or the 1-element
  2636   // cache.  If it points to the display (and NOT the cache) and the display
  2652   // cache.  If it points to the display (and NOT the cache) and the display
  2637   // missed then it's not a subtype.
  2653   // missed then it's not a subtype.
  2638   Node *cacheoff = _gvn.intcon(cacheoff_con);
  2654   Node *cacheoff = gvn->intcon(cacheoff_con);
  2639   Node *cmp2 = _gvn.transform( new CmpINode( chk_off, cacheoff ) );
  2655   IfNode *iff2 = gen_subtype_check_compare(*ctrl, chk_off, cacheoff, BoolTest::ne, PROB_LIKELY(0.63f), gvn, T_INT);
  2640   Node *bol2 = _gvn.transform( new BoolNode( cmp2, BoolTest::ne ) );
  2656   r_not_subtype->init_req(1, gvn->transform(new IfTrueNode (iff2)));
  2641   IfNode *iff2 = create_and_xform_if( control(), bol2, PROB_LIKELY(0.63f), COUNT_UNKNOWN );
  2657   *ctrl = gvn->transform(new IfFalseNode(iff2));
  2642   r_not_subtype->init_req(1, _gvn.transform( new IfTrueNode (iff2) ) );
       
  2643   set_control(                _gvn.transform( new IfFalseNode(iff2) ) );
       
  2644 
  2658 
  2645   // Check for self.  Very rare to get here, but it is taken 1/3 the time.
  2659   // Check for self.  Very rare to get here, but it is taken 1/3 the time.
  2646   // No performance impact (too rare) but allows sharing of secondary arrays
  2660   // No performance impact (too rare) but allows sharing of secondary arrays
  2647   // which has some footprint reduction.
  2661   // which has some footprint reduction.
  2648   Node *cmp3 = _gvn.transform( new CmpPNode( subklass, superklass ) );
  2662   IfNode *iff3 = gen_subtype_check_compare(*ctrl, subklass, superklass, BoolTest::eq, PROB_LIKELY(0.36f), gvn, T_ADDRESS);
  2649   Node *bol3 = _gvn.transform( new BoolNode( cmp3, BoolTest::eq ) );
  2663   r_ok_subtype->init_req(2, gvn->transform(new IfTrueNode(iff3)));
  2650   IfNode *iff3 = create_and_xform_if( control(), bol3, PROB_LIKELY(0.36f), COUNT_UNKNOWN );
  2664   *ctrl = gvn->transform(new IfFalseNode(iff3));
  2651   r_ok_subtype->init_req(2, _gvn.transform( new IfTrueNode ( iff3 ) ) );
       
  2652   set_control(               _gvn.transform( new IfFalseNode( iff3 ) ) );
       
  2653 
  2665 
  2654   // -- Roads not taken here: --
  2666   // -- Roads not taken here: --
  2655   // We could also have chosen to perform the self-check at the beginning
  2667   // We could also have chosen to perform the self-check at the beginning
  2656   // of this code sequence, as the assembler does.  This would not pay off
  2668   // of this code sequence, as the assembler does.  This would not pay off
  2657   // the same way, since the optimizer, unlike the assembler, can perform
  2669   // the same way, since the optimizer, unlike the assembler, can perform
  2670   // performance impact (too rare) but it's gotta be done.
  2682   // performance impact (too rare) but it's gotta be done.
  2671   // Since the code is rarely used, there is no penalty for moving it
  2683   // Since the code is rarely used, there is no penalty for moving it
  2672   // out of line, and it can only improve I-cache density.
  2684   // out of line, and it can only improve I-cache density.
  2673   // The decision to inline or out-of-line this final check is platform
  2685   // The decision to inline or out-of-line this final check is platform
  2674   // dependent, and is found in the AD file definition of PartialSubtypeCheck.
  2686   // dependent, and is found in the AD file definition of PartialSubtypeCheck.
  2675   Node* psc = _gvn.transform(
  2687   Node* psc = gvn->transform(
  2676     new PartialSubtypeCheckNode(control(), subklass, superklass) );
  2688     new PartialSubtypeCheckNode(*ctrl, subklass, superklass));
  2677 
  2689 
  2678   Node *cmp4 = _gvn.transform( new CmpPNode( psc, null() ) );
  2690   IfNode *iff4 = gen_subtype_check_compare(*ctrl, psc, gvn->zerocon(T_OBJECT), BoolTest::ne, PROB_FAIR, gvn, T_ADDRESS);
  2679   Node *bol4 = _gvn.transform( new BoolNode( cmp4, BoolTest::ne ) );
  2691   r_not_subtype->init_req(2, gvn->transform(new IfTrueNode (iff4)));
  2680   IfNode *iff4 = create_and_xform_if( control(), bol4, PROB_FAIR, COUNT_UNKNOWN );
  2692   r_ok_subtype ->init_req(3, gvn->transform(new IfFalseNode(iff4)));
  2681   r_not_subtype->init_req(2, _gvn.transform( new IfTrueNode (iff4) ) );
       
  2682   r_ok_subtype ->init_req(3, _gvn.transform( new IfFalseNode(iff4) ) );
       
  2683 
  2693 
  2684   // Return false path; set default control to true path.
  2694   // Return false path; set default control to true path.
  2685   set_control( _gvn.transform(r_ok_subtype) );
  2695   *ctrl = gvn->transform(r_ok_subtype);
  2686   return _gvn.transform(r_not_subtype);
  2696   return gvn->transform(r_not_subtype);
  2687 }
       
  2688 
       
  2689 //----------------------------static_subtype_check-----------------------------
       
  2690 // Shortcut important common cases when superklass is exact:
       
  2691 // (0) superklass is java.lang.Object (can occur in reflective code)
       
  2692 // (1) subklass is already limited to a subtype of superklass => always ok
       
  2693 // (2) subklass does not overlap with superklass => always fail
       
  2694 // (3) superklass has NO subtypes and we can check with a simple compare.
       
  2695 int GraphKit::static_subtype_check(ciKlass* superk, ciKlass* subk) {
       
  2696   if (StressReflectiveCode) {
       
  2697     return SSC_full_test;       // Let caller generate the general case.
       
  2698   }
       
  2699 
       
  2700   if (superk == env()->Object_klass()) {
       
  2701     return SSC_always_true;     // (0) this test cannot fail
       
  2702   }
       
  2703 
       
  2704   ciType* superelem = superk;
       
  2705   if (superelem->is_array_klass())
       
  2706     superelem = superelem->as_array_klass()->base_element_type();
       
  2707 
       
  2708   if (!subk->is_interface()) {  // cannot trust static interface types yet
       
  2709     if (subk->is_subtype_of(superk)) {
       
  2710       return SSC_always_true;   // (1) false path dead; no dynamic test needed
       
  2711     }
       
  2712     if (!(superelem->is_klass() && superelem->as_klass()->is_interface()) &&
       
  2713         !superk->is_subtype_of(subk)) {
       
  2714       return SSC_always_false;
       
  2715     }
       
  2716   }
       
  2717 
       
  2718   // If casting to an instance klass, it must have no subtypes
       
  2719   if (superk->is_interface()) {
       
  2720     // Cannot trust interfaces yet.
       
  2721     // %%% S.B. superk->nof_implementors() == 1
       
  2722   } else if (superelem->is_instance_klass()) {
       
  2723     ciInstanceKlass* ik = superelem->as_instance_klass();
       
  2724     if (!ik->has_subklass() && !ik->is_interface()) {
       
  2725       if (!ik->is_final()) {
       
  2726         // Add a dependency if there is a chance of a later subclass.
       
  2727         C->dependencies()->assert_leaf_type(ik);
       
  2728       }
       
  2729       return SSC_easy_test;     // (3) caller can do a simple ptr comparison
       
  2730     }
       
  2731   } else {
       
  2732     // A primitive array type has no subtypes.
       
  2733     return SSC_easy_test;       // (3) caller can do a simple ptr comparison
       
  2734   }
       
  2735 
       
  2736   return SSC_full_test;
       
  2737 }
  2697 }
  2738 
  2698 
  2739 // Profile-driven exact type check:
  2699 // Profile-driven exact type check:
  2740 Node* GraphKit::type_check_receiver(Node* receiver, ciKlass* klass,
  2700 Node* GraphKit::type_check_receiver(Node* receiver, ciKlass* klass,
  2741                                     float prob,
  2701                                     float prob,
  2811   // If we have a speculative type use it instead of profiling (which
  2771   // If we have a speculative type use it instead of profiling (which
  2812   // may not help us)
  2772   // may not help us)
  2813   ciKlass* exact_kls = spec_klass == NULL ? profile_has_unique_klass() : spec_klass;
  2773   ciKlass* exact_kls = spec_klass == NULL ? profile_has_unique_klass() : spec_klass;
  2814   if (exact_kls != NULL) {// no cast failures here
  2774   if (exact_kls != NULL) {// no cast failures here
  2815     if (require_klass == NULL ||
  2775     if (require_klass == NULL ||
  2816         static_subtype_check(require_klass, exact_kls) == SSC_always_true) {
  2776         C->static_subtype_check(require_klass, exact_kls) == Compile::SSC_always_true) {
  2817       // If we narrow the type to match what the type profile sees or
  2777       // If we narrow the type to match what the type profile sees or
  2818       // the speculative type, we can then remove the rest of the
  2778       // the speculative type, we can then remove the rest of the
  2819       // cast.
  2779       // cast.
  2820       // This is a win, even if the exact_kls is very specific,
  2780       // This is a win, even if the exact_kls is very specific,
  2821       // because downstream operations, such as method calls,
  2781       // because downstream operations, such as method calls,
  2831       if (safe_for_replace) {
  2791       if (safe_for_replace) {
  2832         replace_in_map(not_null_obj, exact_obj);
  2792         replace_in_map(not_null_obj, exact_obj);
  2833       }
  2793       }
  2834       return exact_obj;
  2794       return exact_obj;
  2835     }
  2795     }
  2836     // assert(ssc == SSC_always_true)... except maybe the profile lied to us.
  2796     // assert(ssc == Compile::SSC_always_true)... except maybe the profile lied to us.
  2837   }
  2797   }
  2838 
  2798 
  2839   return NULL;
  2799   return NULL;
  2840 }
  2800 }
  2841 
  2801 
  2936   bool known_statically = false;
  2896   bool known_statically = false;
  2937   if (_gvn.type(superklass)->singleton()) {
  2897   if (_gvn.type(superklass)->singleton()) {
  2938     ciKlass* superk = _gvn.type(superklass)->is_klassptr()->klass();
  2898     ciKlass* superk = _gvn.type(superklass)->is_klassptr()->klass();
  2939     ciKlass* subk = _gvn.type(obj)->is_oopptr()->klass();
  2899     ciKlass* subk = _gvn.type(obj)->is_oopptr()->klass();
  2940     if (subk != NULL && subk->is_loaded()) {
  2900     if (subk != NULL && subk->is_loaded()) {
  2941       int static_res = static_subtype_check(superk, subk);
  2901       int static_res = C->static_subtype_check(superk, subk);
  2942       known_statically = (static_res == SSC_always_true || static_res == SSC_always_false);
  2902       known_statically = (static_res == Compile::SSC_always_true || static_res == Compile::SSC_always_false);
  2943     }
  2903     }
  2944   }
  2904   }
  2945 
  2905 
  2946   if (known_statically && UseTypeSpeculation) {
  2906   if (known_statically && UseTypeSpeculation) {
  2947     // If we know the type check always succeeds then we don't use the
  2907     // If we know the type check always succeeds then we don't use the
  3005   // want a residual null check left around.  (Causes a slowdown,
  2965   // want a residual null check left around.  (Causes a slowdown,
  3006   // for example, in some objArray manipulations, such as a[i]=a[j].)
  2966   // for example, in some objArray manipulations, such as a[i]=a[j].)
  3007   if (tk->singleton()) {
  2967   if (tk->singleton()) {
  3008     const TypeOopPtr* objtp = _gvn.type(obj)->isa_oopptr();
  2968     const TypeOopPtr* objtp = _gvn.type(obj)->isa_oopptr();
  3009     if (objtp != NULL && objtp->klass() != NULL) {
  2969     if (objtp != NULL && objtp->klass() != NULL) {
  3010       switch (static_subtype_check(tk->klass(), objtp->klass())) {
  2970       switch (C->static_subtype_check(tk->klass(), objtp->klass())) {
  3011       case SSC_always_true:
  2971       case Compile::SSC_always_true:
  3012         // If we know the type check always succeed then we don't use
  2972         // If we know the type check always succeed then we don't use
  3013         // the profiling data at this bytecode. Don't lose it, feed it
  2973         // the profiling data at this bytecode. Don't lose it, feed it
  3014         // to the type system as a speculative type.
  2974         // to the type system as a speculative type.
  3015         return record_profiled_receiver_for_speculation(obj);
  2975         return record_profiled_receiver_for_speculation(obj);
  3016       case SSC_always_false:
  2976       case Compile::SSC_always_false:
  3017         // It needs a null check because a null will *pass* the cast check.
  2977         // It needs a null check because a null will *pass* the cast check.
  3018         // A non-null value will always produce an exception.
  2978         // A non-null value will always produce an exception.
  3019         return null_assert(obj);
  2979         return null_assert(obj);
  3020       }
  2980       }
  3021     }
  2981     }