< prev index next >

src/hotspot/share/opto/graphKit.cpp

Print this page

  14  *
  15  * You should have received a copy of the GNU General Public License version
  16  * 2 along with this work; if not, write to the Free Software Foundation,
  17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  18  *
  19  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  20  * or visit www.oracle.com if you need additional information or have any
  21  * questions.
  22  *
  23  */
  24 
  25 #include "asm/register.hpp"
  26 #include "ci/ciObjArray.hpp"
  27 #include "ci/ciUtilities.hpp"
  28 #include "classfile/javaClasses.hpp"
  29 #include "compiler/compileLog.hpp"
  30 #include "gc/shared/barrierSet.hpp"
  31 #include "gc/shared/c2/barrierSetC2.hpp"
  32 #include "interpreter/interpreter.hpp"
  33 #include "memory/resourceArea.hpp"

  34 #include "opto/addnode.hpp"
  35 #include "opto/castnode.hpp"
  36 #include "opto/convertnode.hpp"
  37 #include "opto/graphKit.hpp"
  38 #include "opto/idealKit.hpp"
  39 #include "opto/intrinsicnode.hpp"
  40 #include "opto/locknode.hpp"
  41 #include "opto/machnode.hpp"
  42 #include "opto/opaquenode.hpp"
  43 #include "opto/parse.hpp"
  44 #include "opto/rootnode.hpp"
  45 #include "opto/runtime.hpp"
  46 #include "opto/subtypenode.hpp"
  47 #include "runtime/deoptimization.hpp"
  48 #include "runtime/sharedRuntime.hpp"
  49 #include "utilities/bitMap.inline.hpp"
  50 #include "utilities/growableArray.hpp"
  51 #include "utilities/powerOfTwo.hpp"
  52 
  53 //----------------------------GraphKit-----------------------------------------

2132   case Deoptimization::Action_make_not_entrant:
2133     C->set_trap_can_recompile(true);
2134     break;
2135   case Deoptimization::Action_none:
2136   case Deoptimization::Action_make_not_compilable:
2137     break;
2138   default:
2139 #ifdef ASSERT
2140     fatal("unknown action %d: %s", action, Deoptimization::trap_action_name(action));
2141 #endif
2142     break;
2143   }
2144 
2145   if (TraceOptoParse) {
2146     char buf[100];
2147     tty->print_cr("Uncommon trap %s at bci:%d",
2148                   Deoptimization::format_trap_request(buf, sizeof(buf),
2149                                                       trap_request), bci());
2150   }
2151 










2152   CompileLog* log = C->log();
2153   if (log != nullptr) {
2154     int kid = (klass == nullptr)? -1: log->identify(klass);
2155     log->begin_elem("uncommon_trap bci='%d'", bci());
2156     char buf[100];
2157     log->print(" %s", Deoptimization::format_trap_request(buf, sizeof(buf),
2158                                                           trap_request));
2159     if (kid >= 0)         log->print(" klass='%d'", kid);
2160     if (comment != nullptr)  log->print(" comment='%s'", comment);
2161     log->end_elem();
2162   }
2163 
2164   // Make sure any guarding test views this path as very unlikely
2165   Node *i0 = control()->in(0);
2166   if (i0 != nullptr && i0->is_If()) {        // Found a guarding if test?
2167     IfNode *iff = i0->as_If();
2168     float f = iff->_prob;   // Get prob
2169     if (control()->Opcode() == Op_IfTrue) {
2170       if (f > PROB_UNLIKELY_MAG(4))
2171         iff->_prob = PROB_MIN;

2973   if (UncommonNullCast               // Cutout for this technique
2974       && obj != null()               // And not the -Xcomp stupid case?
2975       && !too_many_traps(reason)
2976       ) {
2977     if (speculating) {
2978       return true;
2979     }
2980     if (data == nullptr)
2981       // Edge case:  no mature data.  Be optimistic here.
2982       return true;
2983     // If the profile has not seen a null, assume it won't happen.
2984     assert(java_bc() == Bytecodes::_checkcast ||
2985            java_bc() == Bytecodes::_instanceof ||
2986            java_bc() == Bytecodes::_aastore, "MDO must collect null_seen bit here");
2987     return !data->as_BitData()->null_seen();
2988   }
2989   speculating = false;
2990   return false;
2991 }
2992 









































































2993 void GraphKit::guard_klass_being_initialized(Node* klass) {
2994   int init_state_off = in_bytes(InstanceKlass::init_state_offset());
2995   Node* adr = basic_plus_adr(top(), klass, init_state_off);
2996   Node* init_state = LoadNode::make(_gvn, nullptr, immutable_memory(), adr,
2997                                     adr->bottom_type()->is_ptr(), TypeInt::BYTE,
2998                                     T_BYTE, MemNode::acquire);
2999   init_state = _gvn.transform(init_state);
3000 
3001   Node* being_initialized_state = makecon(TypeInt::make(InstanceKlass::being_initialized));
3002 
3003   Node* chk = _gvn.transform(new CmpINode(being_initialized_state, init_state));
3004   Node* tst = _gvn.transform(new BoolNode(chk, BoolTest::eq));
3005 
3006   { BuildCutout unless(this, tst, PROB_MAX);
3007     uncommon_trap(Deoptimization::Reason_initialized, Deoptimization::Action_reinterpret);
3008   }
3009 }
3010 
3011 void GraphKit::guard_init_thread(Node* klass) {
3012   int init_thread_off = in_bytes(InstanceKlass::init_thread_offset());
3013   Node* adr = basic_plus_adr(top(), klass, init_thread_off);
3014 
3015   Node* init_thread = LoadNode::make(_gvn, nullptr, immutable_memory(), adr,
3016                                      adr->bottom_type()->is_ptr(), TypePtr::NOTNULL,
3017                                      T_ADDRESS, MemNode::unordered);
3018   init_thread = _gvn.transform(init_thread);
3019 
3020   Node* cur_thread = _gvn.transform(new ThreadLocalNode());
3021 
3022   Node* chk = _gvn.transform(new CmpPNode(cur_thread, init_thread));
3023   Node* tst = _gvn.transform(new BoolNode(chk, BoolTest::eq));
3024 
3025   { BuildCutout unless(this, tst, PROB_MAX);
3026     uncommon_trap(Deoptimization::Reason_uninitialized, Deoptimization::Action_none);
3027   }
3028 }
3029 
3030 void GraphKit::clinit_barrier(ciInstanceKlass* ik, ciMethod* context) {





3031   if (ik->is_being_initialized()) {
3032     if (C->needs_clinit_barrier(ik, context)) {
3033       Node* klass = makecon(TypeKlassPtr::make(ik));
3034       guard_klass_being_initialized(klass);
3035       guard_init_thread(klass);
3036       insert_mem_bar(Op_MemBarCPUOrder);
3037     }
3038   } else if (ik->is_initialized()) {
3039     return; // no barrier needed
3040   } else {




3041     uncommon_trap(Deoptimization::Reason_uninitialized,
3042                   Deoptimization::Action_reinterpret,
3043                   nullptr);
3044   }
3045 }
3046 
3047 //------------------------maybe_cast_profiled_receiver-------------------------
3048 // If the profile has seen exactly one type, narrow to exactly that type.
3049 // Subsequent type checks will always fold up.
3050 Node* GraphKit::maybe_cast_profiled_receiver(Node* not_null_obj,
3051                                              const TypeKlassPtr* require_klass,
3052                                              ciKlass* spec_klass,
3053                                              bool safe_for_replace) {
3054   if (!UseTypeProfile || !TypeProfileCasts) return nullptr;
3055 
3056   Deoptimization::DeoptReason reason = Deoptimization::reason_class_check(spec_klass != nullptr);
3057 
3058   // Make sure we haven't already deoptimized from this tactic.
3059   if (too_many_traps_or_recompiles(reason))
3060     return nullptr;

  14  *
  15  * You should have received a copy of the GNU General Public License version
  16  * 2 along with this work; if not, write to the Free Software Foundation,
  17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  18  *
  19  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  20  * or visit www.oracle.com if you need additional information or have any
  21  * questions.
  22  *
  23  */
  24 
  25 #include "asm/register.hpp"
  26 #include "ci/ciObjArray.hpp"
  27 #include "ci/ciUtilities.hpp"
  28 #include "classfile/javaClasses.hpp"
  29 #include "compiler/compileLog.hpp"
  30 #include "gc/shared/barrierSet.hpp"
  31 #include "gc/shared/c2/barrierSetC2.hpp"
  32 #include "interpreter/interpreter.hpp"
  33 #include "memory/resourceArea.hpp"
  34 #include "oops/trainingData.hpp"
  35 #include "opto/addnode.hpp"
  36 #include "opto/castnode.hpp"
  37 #include "opto/convertnode.hpp"
  38 #include "opto/graphKit.hpp"
  39 #include "opto/idealKit.hpp"
  40 #include "opto/intrinsicnode.hpp"
  41 #include "opto/locknode.hpp"
  42 #include "opto/machnode.hpp"
  43 #include "opto/opaquenode.hpp"
  44 #include "opto/parse.hpp"
  45 #include "opto/rootnode.hpp"
  46 #include "opto/runtime.hpp"
  47 #include "opto/subtypenode.hpp"
  48 #include "runtime/deoptimization.hpp"
  49 #include "runtime/sharedRuntime.hpp"
  50 #include "utilities/bitMap.inline.hpp"
  51 #include "utilities/growableArray.hpp"
  52 #include "utilities/powerOfTwo.hpp"
  53 
  54 //----------------------------GraphKit-----------------------------------------

2133   case Deoptimization::Action_make_not_entrant:
2134     C->set_trap_can_recompile(true);
2135     break;
2136   case Deoptimization::Action_none:
2137   case Deoptimization::Action_make_not_compilable:
2138     break;
2139   default:
2140 #ifdef ASSERT
2141     fatal("unknown action %d: %s", action, Deoptimization::trap_action_name(action));
2142 #endif
2143     break;
2144   }
2145 
2146   if (TraceOptoParse) {
2147     char buf[100];
2148     tty->print_cr("Uncommon trap %s at bci:%d",
2149                   Deoptimization::format_trap_request(buf, sizeof(buf),
2150                                                       trap_request), bci());
2151   }
2152 
2153   if (PreloadReduceTraps && Compile::current()->for_preload() &&
2154       (action != Deoptimization::Action_none)) {
2155     ResourceMark rm;
2156     ciMethod* cim = Compile::current()->method();
2157     log_debug(aot, codecache, deoptimization)("Uncommon trap in preload code: reason=%s action=%s method=%s::%s bci=%d, %s",
2158                   Deoptimization::trap_reason_name(reason), Deoptimization::trap_action_name(action),
2159                   cim->holder()->name()->as_klass_external_name(), cim->name()->as_klass_external_name(),
2160                   bci(), comment);
2161   }
2162 
2163   CompileLog* log = C->log();
2164   if (log != nullptr) {
2165     int kid = (klass == nullptr)? -1: log->identify(klass);
2166     log->begin_elem("uncommon_trap bci='%d'", bci());
2167     char buf[100];
2168     log->print(" %s", Deoptimization::format_trap_request(buf, sizeof(buf),
2169                                                           trap_request));
2170     if (kid >= 0)         log->print(" klass='%d'", kid);
2171     if (comment != nullptr)  log->print(" comment='%s'", comment);
2172     log->end_elem();
2173   }
2174 
2175   // Make sure any guarding test views this path as very unlikely
2176   Node *i0 = control()->in(0);
2177   if (i0 != nullptr && i0->is_If()) {        // Found a guarding if test?
2178     IfNode *iff = i0->as_If();
2179     float f = iff->_prob;   // Get prob
2180     if (control()->Opcode() == Op_IfTrue) {
2181       if (f > PROB_UNLIKELY_MAG(4))
2182         iff->_prob = PROB_MIN;

2984   if (UncommonNullCast               // Cutout for this technique
2985       && obj != null()               // And not the -Xcomp stupid case?
2986       && !too_many_traps(reason)
2987       ) {
2988     if (speculating) {
2989       return true;
2990     }
2991     if (data == nullptr)
2992       // Edge case:  no mature data.  Be optimistic here.
2993       return true;
2994     // If the profile has not seen a null, assume it won't happen.
2995     assert(java_bc() == Bytecodes::_checkcast ||
2996            java_bc() == Bytecodes::_instanceof ||
2997            java_bc() == Bytecodes::_aastore, "MDO must collect null_seen bit here");
2998     return !data->as_BitData()->null_seen();
2999   }
3000   speculating = false;
3001   return false;
3002 }
3003 
3004 void GraphKit::guard_klass_is_initialized(Node* klass) {
3005   assert(C->do_clinit_barriers(), "should be called only for clinit barriers");
3006   int init_state_off = in_bytes(InstanceKlass::init_state_offset());
3007   Node* adr = basic_plus_adr(top(), klass, init_state_off);
3008   Node* init_state = LoadNode::make(_gvn, nullptr, immutable_memory(), adr,
3009                                     adr->bottom_type()->is_ptr(), TypeInt::BYTE,
3010                                     T_BYTE, MemNode::unordered);
3011   init_state = _gvn.transform(init_state);
3012 
3013   Node* initialized_state = makecon(TypeInt::make(InstanceKlass::fully_initialized));
3014 
3015   Node* chk = _gvn.transform(new CmpINode(initialized_state, init_state));
3016   Node* tst = _gvn.transform(new BoolNode(chk, BoolTest::eq));
3017 
3018   switch (ClassInitBarrierMode) {
3019     case 1: { // uncommon trap on slow path
3020       BuildCutout unless(this, tst, PROB_MAX);
3021       // Do not deoptimize this nmethod. Go to Interpreter to initialize class.
3022       uncommon_trap(Deoptimization::Reason_uninitialized, Deoptimization::Action_none);
3023       break;
3024     }
3025     case 2: { // runtime call on slow path
3026       if (StressClassInitBarriers) {
3027         tst = makecon(TypeInt::ZERO); // always go through slow path
3028       }
3029       IfNode* iff = create_and_xform_if(control(), tst, PROB_MAX, COUNT_UNKNOWN);
3030 //    IfNode* iff = create_and_map_if(control(), tst, PROB_MAX, COUNT_UNKNOWN);
3031 
3032       RegionNode* r = new RegionNode(3);
3033       r->init_req(1, _gvn.transform(new IfTrueNode(iff)));
3034 
3035       set_control(_gvn.transform(new IfFalseNode(iff)));
3036 
3037       if (!stopped()) {
3038         kill_dead_locals();
3039 
3040         Node* call = make_runtime_call(RC_NO_LEAF,
3041                                        OptoRuntime::class_init_barrier_Type(),
3042                                        OptoRuntime::class_init_barrier_Java(),
3043                                        nullptr, TypePtr::BOTTOM,
3044                                        klass);
3045         // Deoptimization during class init barrier execution should trigger current bytecode reexecution.
3046         call->jvms()->set_should_reexecute(true);
3047 
3048         // FIXME: deoptimize for now. deoptimize=false doesn't work with late inlining yet.
3049         // Parse::create_entry_map() introduces a barrier which uses distinct JVM state (*before* call).
3050         // Compilation fails when distinct exception states are combined.
3051         make_slow_call_ex(call, env()->Throwable_klass(), /*separate_io_proj=*/true, /*deoptimize=*/true);
3052 
3053         Node* fast_io  = call->in(TypeFunc::I_O);
3054         Node* fast_mem = call->in(TypeFunc::Memory);
3055         // These two phis are pre-filled with copies of of the fast IO and Memory
3056         Node* io_phi   = PhiNode::make(r, fast_io,  Type::ABIO);
3057         Node* mem_phi  = PhiNode::make(r, fast_mem, Type::MEMORY, TypePtr::BOTTOM);
3058 
3059         r->init_req(2, control());
3060         io_phi->init_req(2, i_o());
3061         mem_phi->init_req(2, reset_memory());
3062 
3063         set_all_memory(_gvn.transform(mem_phi));
3064         set_i_o(_gvn.transform(io_phi));
3065       } else {
3066         r->init_req(2, top());
3067       }
3068       set_control(_gvn.transform(r));
3069       break;
3070     }
3071 
3072     default: fatal("unknown barrier mode: %d", ClassInitBarrierMode);
3073   }
3074   C->set_has_clinit_barriers(true);
3075 }
3076 
3077 void GraphKit::guard_klass_being_initialized(Node* klass) {
3078   int init_state_off = in_bytes(InstanceKlass::init_state_offset());
3079   Node* adr = basic_plus_adr(top(), klass, init_state_off);
3080   Node* init_state = LoadNode::make(_gvn, nullptr, immutable_memory(), adr,
3081                                     adr->bottom_type()->is_ptr(), TypeInt::BYTE,
3082                                     T_BYTE, MemNode::acquire);
3083   init_state = _gvn.transform(init_state);
3084 
3085   Node* being_initialized_state = makecon(TypeInt::make(InstanceKlass::being_initialized));
3086 
3087   Node* chk = _gvn.transform(new CmpINode(being_initialized_state, init_state));
3088   Node* tst = _gvn.transform(new BoolNode(chk, BoolTest::eq));
3089 
3090   { BuildCutout unless(this, tst, PROB_MAX);
3091     uncommon_trap(Deoptimization::Reason_initialized, Deoptimization::Action_reinterpret);
3092   }
3093 }
3094 
3095 void GraphKit::guard_init_thread(Node* klass) {
3096   int init_thread_off = in_bytes(InstanceKlass::init_thread_offset());
3097   Node* adr = basic_plus_adr(top(), klass, init_thread_off);
3098 
3099   Node* init_thread = LoadNode::make(_gvn, nullptr, immutable_memory(), adr,
3100                                      adr->bottom_type()->is_ptr(), TypePtr::NOTNULL,
3101                                      T_ADDRESS, MemNode::unordered);
3102   init_thread = _gvn.transform(init_thread);
3103 
3104   Node* cur_thread = _gvn.transform(new ThreadLocalNode());
3105 
3106   Node* chk = _gvn.transform(new CmpPNode(cur_thread, init_thread));
3107   Node* tst = _gvn.transform(new BoolNode(chk, BoolTest::eq));
3108 
3109   { BuildCutout unless(this, tst, PROB_MAX);
3110     uncommon_trap(Deoptimization::Reason_uninitialized, Deoptimization::Action_none);
3111   }
3112 }
3113 
3114 void GraphKit::clinit_barrier(ciInstanceKlass* ik, ciMethod* context) {
3115   if (C->do_clinit_barriers()) {
3116     Node* klass = makecon(TypeKlassPtr::make(ik, Type::trust_interfaces));
3117     guard_klass_is_initialized(klass);
3118     return;
3119   }
3120   if (ik->is_being_initialized()) {
3121     if (C->needs_clinit_barrier(ik, context)) {
3122       Node* klass = makecon(TypeKlassPtr::make(ik, Type::trust_interfaces));
3123       guard_klass_being_initialized(klass);
3124       guard_init_thread(klass);
3125       insert_mem_bar(Op_MemBarCPUOrder);
3126     }
3127   } else if (ik->is_initialized()) {
3128     return; // no barrier needed
3129   } else {
3130     if (C->env()->task()->is_precompile()) {
3131       ResourceMark rm;
3132       log_debug(precompile)("Emitting uncommon trap (clinit barrier) in AOT code for %s", ik->name()->as_klass_external_name());
3133     }
3134     uncommon_trap(Deoptimization::Reason_uninitialized,
3135                   Deoptimization::Action_reinterpret,
3136                   nullptr);
3137   }
3138 }
3139 
3140 //------------------------maybe_cast_profiled_receiver-------------------------
3141 // If the profile has seen exactly one type, narrow to exactly that type.
3142 // Subsequent type checks will always fold up.
3143 Node* GraphKit::maybe_cast_profiled_receiver(Node* not_null_obj,
3144                                              const TypeKlassPtr* require_klass,
3145                                              ciKlass* spec_klass,
3146                                              bool safe_for_replace) {
3147   if (!UseTypeProfile || !TypeProfileCasts) return nullptr;
3148 
3149   Deoptimization::DeoptReason reason = Deoptimization::reason_class_check(spec_klass != nullptr);
3150 
3151   // Make sure we haven't already deoptimized from this tactic.
3152   if (too_many_traps_or_recompiles(reason))
3153     return nullptr;
< prev index next >