< 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-----------------------------------------

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










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

2983   if (UncommonNullCast               // Cutout for this technique
2984       && obj != null()               // And not the -Xcomp stupid case?
2985       && !too_many_traps(reason)
2986       ) {
2987     if (speculating) {
2988       return true;
2989     }
2990     if (data == nullptr)
2991       // Edge case:  no mature data.  Be optimistic here.
2992       return true;
2993     // If the profile has not seen a null, assume it won't happen.
2994     assert(java_bc() == Bytecodes::_checkcast ||
2995            java_bc() == Bytecodes::_instanceof ||
2996            java_bc() == Bytecodes::_aastore, "MDO must collect null_seen bit here");
2997     return !data->as_BitData()->null_seen();
2998   }
2999   speculating = false;
3000   return false;
3001 }
3002 









































































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





3041   if (ik->is_being_initialized()) {
3042     if (C->needs_clinit_barrier(ik, context)) {
3043       Node* klass = makecon(TypeKlassPtr::make(ik));
3044       guard_klass_being_initialized(klass);
3045       guard_init_thread(klass);
3046       insert_mem_bar(Op_MemBarCPUOrder);
3047     }
3048   } else if (ik->is_initialized()) {
3049     return; // no barrier needed
3050   } else {




3051     uncommon_trap(Deoptimization::Reason_uninitialized,
3052                   Deoptimization::Action_reinterpret,
3053                   nullptr);
3054   }
3055 }
3056 
3057 //------------------------maybe_cast_profiled_receiver-------------------------
3058 // If the profile has seen exactly one type, narrow to exactly that type.
3059 // Subsequent type checks will always fold up.
3060 Node* GraphKit::maybe_cast_profiled_receiver(Node* not_null_obj,
3061                                              const TypeKlassPtr* require_klass,
3062                                              ciKlass* spec_klass,
3063                                              bool safe_for_replace) {
3064   if (!UseTypeProfile || !TypeProfileCasts) return nullptr;
3065 
3066   Deoptimization::DeoptReason reason = Deoptimization::reason_class_check(spec_klass != nullptr);
3067 
3068   // Make sure we haven't already deoptimized from this tactic.
3069   if (too_many_traps_or_recompiles(reason))
3070     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-----------------------------------------

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

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