src/hotspot/share/opto/compile.cpp
branchdatagramsocketimpl-branch
changeset 58678 9cf78a70fa4f
parent 54960 e46fe26d7f77
child 58679 9c3209ff7550
equal deleted inserted replaced
58677:13588c901957 58678:9cf78a70fa4f
    74 #include "runtime/stubRoutines.hpp"
    74 #include "runtime/stubRoutines.hpp"
    75 #include "runtime/timer.hpp"
    75 #include "runtime/timer.hpp"
    76 #include "utilities/align.hpp"
    76 #include "utilities/align.hpp"
    77 #include "utilities/copy.hpp"
    77 #include "utilities/copy.hpp"
    78 #include "utilities/macros.hpp"
    78 #include "utilities/macros.hpp"
    79 #if INCLUDE_ZGC
       
    80 #include "gc/z/c2/zBarrierSetC2.hpp"
       
    81 #endif
       
    82 
    79 
    83 
    80 
    84 // -------------------- Compile::mach_constant_base_node -----------------------
    81 // -------------------- Compile::mach_constant_base_node -----------------------
    85 // Constant table base node singleton.
    82 // Constant table base node singleton.
    86 MachConstantBaseNode* Compile::mach_constant_base_node() {
    83 MachConstantBaseNode* Compile::mach_constant_base_node() {
   463   assert(compile == Compile::current(), "sanity");
   460   assert(compile == Compile::current(), "sanity");
   464 
   461 
   465   compile->set_type_dict(NULL);
   462   compile->set_type_dict(NULL);
   466   compile->set_clone_map(new Dict(cmpkey, hashkey, _compile->comp_arena()));
   463   compile->set_clone_map(new Dict(cmpkey, hashkey, _compile->comp_arena()));
   467   compile->clone_map().set_clone_idx(0);
   464   compile->clone_map().set_clone_idx(0);
   468   compile->set_type_hwm(NULL);
       
   469   compile->set_type_last_size(0);
   465   compile->set_type_last_size(0);
   470   compile->set_last_tf(NULL, NULL);
   466   compile->set_last_tf(NULL, NULL);
   471   compile->set_indexSet_arena(NULL);
   467   compile->set_indexSet_arena(NULL);
   472   compile->set_indexSet_free_block_list(NULL);
   468   compile->set_indexSet_free_block_list(NULL);
   473   compile->init_type_arena();
   469   compile->init_type_arena();
   652                   _has_reserved_stack_access(target->has_reserved_stack_access()),
   648                   _has_reserved_stack_access(target->has_reserved_stack_access()),
   653 #ifndef PRODUCT
   649 #ifndef PRODUCT
   654                   _trace_opto_output(directive->TraceOptoOutputOption),
   650                   _trace_opto_output(directive->TraceOptoOutputOption),
   655 #endif
   651 #endif
   656                   _has_method_handle_invokes(false),
   652                   _has_method_handle_invokes(false),
       
   653                   _clinit_barrier_on_entry(false),
   657                   _comp_arena(mtCompiler),
   654                   _comp_arena(mtCompiler),
   658                   _barrier_set_state(BarrierSet::barrier_set()->barrier_set_c2()->create_barrier_state(comp_arena())),
   655                   _barrier_set_state(BarrierSet::barrier_set()->barrier_set_c2()->create_barrier_state(comp_arena())),
   659                   _env(ci_env),
   656                   _env(ci_env),
   660                   _directive(directive),
   657                   _directive(directive),
   661                   _log(ci_env->log()),
   658                   _log(ci_env->log()),
   986     _has_reserved_stack_access(false),
   983     _has_reserved_stack_access(false),
   987 #ifndef PRODUCT
   984 #ifndef PRODUCT
   988     _trace_opto_output(directive->TraceOptoOutputOption),
   985     _trace_opto_output(directive->TraceOptoOutputOption),
   989 #endif
   986 #endif
   990     _has_method_handle_invokes(false),
   987     _has_method_handle_invokes(false),
       
   988     _clinit_barrier_on_entry(false),
   991     _comp_arena(mtCompiler),
   989     _comp_arena(mtCompiler),
       
   990     _barrier_set_state(BarrierSet::barrier_set()->barrier_set_c2()->create_barrier_state(comp_arena())),
   992     _env(ci_env),
   991     _env(ci_env),
   993     _directive(directive),
   992     _directive(directive),
   994     _log(ci_env->log()),
   993     _log(ci_env->log()),
   995     _failure_reason(NULL),
   994     _failure_reason(NULL),
   996     _congraph(NULL),
   995     _congraph(NULL),
  1168       // code if UseRTMDeopt is on.
  1167       // code if UseRTMDeopt is on.
  1169       set_rtm_state(ProfileRTM);
  1168       set_rtm_state(ProfileRTM);
  1170     }
  1169     }
  1171   }
  1170   }
  1172 #endif
  1171 #endif
       
  1172   if (VM_Version::supports_fast_class_init_checks() && has_method() && !is_osr_compilation() && method()->needs_clinit_barrier()) {
       
  1173     set_clinit_barrier_on_entry(true);
       
  1174   }
  1173   if (debug_info()->recording_non_safepoints()) {
  1175   if (debug_info()->recording_non_safepoints()) {
  1174     set_node_note_array(new(comp_arena()) GrowableArray<Node_Notes*>
  1176     set_node_note_array(new(comp_arena()) GrowableArray<Node_Notes*>
  1175                         (comp_arena(), 8, 0, NULL));
  1177                         (comp_arena(), 8, 0, NULL));
  1176     set_default_node_notes(Node_Notes::make(this));
  1178     set_default_node_notes(Node_Notes::make(this));
  1177   }
  1179   }
  2204     BREAKPOINT;
  2206     BREAKPOINT;
  2205   }
  2207   }
  2206 
  2208 
  2207 #endif
  2209 #endif
  2208 
  2210 
       
  2211   BarrierSetC2* bs = BarrierSet::barrier_set()->barrier_set_c2();
  2209 #ifdef ASSERT
  2212 #ifdef ASSERT
  2210   BarrierSetC2* bs = BarrierSet::barrier_set()->barrier_set_c2();
       
  2211   bs->verify_gc_barriers(this, BarrierSetC2::BeforeOptimize);
  2213   bs->verify_gc_barriers(this, BarrierSetC2::BeforeOptimize);
  2212 #endif
  2214 #endif
  2213 
  2215 
  2214   ResourceMark rm;
  2216   ResourceMark rm;
  2215 
  2217 
  2364   {
  2366   {
  2365     TracePhase tp("iterGVN2", &timers[_t_iterGVN2]);
  2367     TracePhase tp("iterGVN2", &timers[_t_iterGVN2]);
  2366     igvn = ccp;
  2368     igvn = ccp;
  2367     igvn.optimize();
  2369     igvn.optimize();
  2368   }
  2370   }
  2369 
       
  2370   print_method(PHASE_ITER_GVN2, 2);
  2371   print_method(PHASE_ITER_GVN2, 2);
  2371 
  2372 
  2372   if (failing())  return;
  2373   if (failing())  return;
  2373 
  2374 
  2374   // Loop transforms on the ideal graph.  Range Check Elimination,
  2375   // Loop transforms on the ideal graph.  Range Check Elimination,
  2375   // peeling, unrolling, etc.
  2376   // peeling, unrolling, etc.
  2376   if (!optimize_loops(igvn, LoopOptsDefault)) {
  2377   if (!optimize_loops(igvn, LoopOptsDefault)) {
  2377     return;
  2378     return;
  2378   }
  2379   }
  2379 
       
  2380 #if INCLUDE_ZGC
       
  2381   if (UseZGC) {
       
  2382     ZBarrierSetC2::find_dominating_barriers(igvn);
       
  2383   }
       
  2384 #endif
       
  2385 
  2380 
  2386   if (failing())  return;
  2381   if (failing())  return;
  2387 
  2382 
  2388   // Ensure that major progress is now clear
  2383   // Ensure that major progress is now clear
  2389   C->clear_major_progress();
  2384   C->clear_major_progress();
  2400     C->remove_range_check_casts(igvn);
  2395     C->remove_range_check_casts(igvn);
  2401     igvn.optimize();
  2396     igvn.optimize();
  2402   }
  2397   }
  2403 
  2398 
  2404 #ifdef ASSERT
  2399 #ifdef ASSERT
  2405   BarrierSetC2* bs = BarrierSet::barrier_set()->barrier_set_c2();
  2400   bs->verify_gc_barriers(this, BarrierSetC2::BeforeMacroExpand);
  2406   bs->verify_gc_barriers(this, BarrierSetC2::BeforeExpand);
       
  2407 #endif
  2401 #endif
  2408 
  2402 
  2409   {
  2403   {
  2410     TracePhase tp("macroExpand", &timers[_t_macroExpand]);
  2404     TracePhase tp("macroExpand", &timers[_t_macroExpand]);
  2411     PhaseMacroExpand  mex(igvn);
  2405     PhaseMacroExpand  mex(igvn);
  2412     print_method(PHASE_BEFORE_MACRO_EXPANSION, 2);
       
  2413     if (mex.expand_macro_nodes()) {
  2406     if (mex.expand_macro_nodes()) {
  2414       assert(failing(), "must bail out w/ explicit message");
  2407       assert(failing(), "must bail out w/ explicit message");
  2415       return;
  2408       return;
  2416     }
  2409     }
       
  2410     print_method(PHASE_MACRO_EXPANSION, 2);
  2417   }
  2411   }
  2418 
  2412 
  2419   {
  2413   {
  2420     TracePhase tp("barrierExpand", &timers[_t_barrierExpand]);
  2414     TracePhase tp("barrierExpand", &timers[_t_barrierExpand]);
  2421     print_method(PHASE_BEFORE_BARRIER_EXPAND, 2);
       
  2422     BarrierSetC2* bs = BarrierSet::barrier_set()->barrier_set_c2();
       
  2423     if (bs->expand_barriers(this, igvn)) {
  2415     if (bs->expand_barriers(this, igvn)) {
  2424       assert(failing(), "must bail out w/ explicit message");
  2416       assert(failing(), "must bail out w/ explicit message");
  2425       return;
  2417       return;
  2426     }
  2418     }
       
  2419     print_method(PHASE_BARRIER_EXPANSION, 2);
  2427   }
  2420   }
  2428 
  2421 
  2429   if (opaque4_count() > 0) {
  2422   if (opaque4_count() > 0) {
  2430     C->remove_opaque4_nodes(igvn);
  2423     C->remove_opaque4_nodes(igvn);
  2431     igvn.optimize();
  2424     igvn.optimize();
  2817   }
  2810   }
  2818   if (n->is_MemBar()) {
  2811   if (n->is_MemBar()) {
  2819     MemBarNode* mb = n->as_MemBar();
  2812     MemBarNode* mb = n->as_MemBar();
  2820     if (mb->trailing_store() || mb->trailing_load_store()) {
  2813     if (mb->trailing_store() || mb->trailing_load_store()) {
  2821       assert(mb->leading_membar()->trailing_membar() == mb, "bad membar pair");
  2814       assert(mb->leading_membar()->trailing_membar() == mb, "bad membar pair");
  2822       Node* mem = mb->in(MemBarNode::Precedent);
  2815       Node* mem = BarrierSet::barrier_set()->barrier_set_c2()->step_over_gc_barrier(mb->in(MemBarNode::Precedent));
  2823       assert((mb->trailing_store() && mem->is_Store() && mem->as_Store()->is_release()) ||
  2816       assert((mb->trailing_store() && mem->is_Store() && mem->as_Store()->is_release()) ||
  2824              (mb->trailing_load_store() && mem->is_LoadStore()), "missing mem op");
  2817              (mb->trailing_load_store() && mem->is_LoadStore()), "missing mem op");
  2825     } else if (mb->leading()) {
  2818     } else if (mb->leading()) {
  2826       assert(mb->trailing_membar()->leading_membar() == mb, "bad membar pair");
  2819       assert(mb->trailing_membar()->leading_membar() == mb, "bad membar pair");
  2827     }
  2820     }
  3467       // Code generation on some platforms doesn't need accurate
  3460       // Code generation on some platforms doesn't need accurate
  3468       // ConvI2L types. Widening the type can help remove redundant
  3461       // ConvI2L types. Widening the type can help remove redundant
  3469       // address computations.
  3462       // address computations.
  3470       n->as_Type()->set_type(TypeLong::INT);
  3463       n->as_Type()->set_type(TypeLong::INT);
  3471       ResourceMark rm;
  3464       ResourceMark rm;
  3472       Node_List wq;
  3465       Unique_Node_List wq;
  3473       wq.push(n);
  3466       wq.push(n);
  3474       for (uint next = 0; next < wq.size(); next++) {
  3467       for (uint next = 0; next < wq.size(); next++) {
  3475         Node *m = wq.at(next);
  3468         Node *m = wq.at(next);
  3476 
  3469 
  3477         for(;;) {
  3470         for(;;) {
  3482           }
  3475           }
  3483           // Push their uses so we get a chance to remove node made
  3476           // Push their uses so we get a chance to remove node made
  3484           // redundant
  3477           // redundant
  3485           for (DUIterator_Fast imax, i = k->fast_outs(imax); i < imax; i++) {
  3478           for (DUIterator_Fast imax, i = k->fast_outs(imax); i < imax; i++) {
  3486             Node* u = k->fast_out(i);
  3479             Node* u = k->fast_out(i);
  3487             assert(!wq.contains(u), "shouldn't process one node several times");
       
  3488             if (u->Opcode() == Op_LShiftL ||
  3480             if (u->Opcode() == Op_LShiftL ||
  3489                 u->Opcode() == Op_AddL ||
  3481                 u->Opcode() == Op_AddL ||
  3490                 u->Opcode() == Op_SubL ||
  3482                 u->Opcode() == Op_SubL ||
  3491                 u->Opcode() == Op_AddP) {
  3483                 u->Opcode() == Op_AddP) {
  3492               wq.push(u);
  3484               wq.push(u);
  3839       }
  3831       }
  3840     }
  3832     }
  3841   }
  3833   }
  3842 }
  3834 }
  3843 
  3835 
  3844 bool Compile::is_compiling_clinit_for(ciKlass* k) {
  3836 bool Compile::needs_clinit_barrier(ciMethod* method, ciMethod* accessing_method) {
  3845   ciMethod* root = method(); // the root method of compilation
  3837   return method->is_static() && needs_clinit_barrier(method->holder(), accessing_method);
  3846   return root->is_static_initializer() && root->holder() == k; // access in the context of clinit
  3838 }
       
  3839 
       
  3840 bool Compile::needs_clinit_barrier(ciField* field, ciMethod* accessing_method) {
       
  3841   return field->is_static() && needs_clinit_barrier(field->holder(), accessing_method);
       
  3842 }
       
  3843 
       
  3844 bool Compile::needs_clinit_barrier(ciInstanceKlass* holder, ciMethod* accessing_method) {
       
  3845   if (holder->is_initialized()) {
       
  3846     return false;
       
  3847   }
       
  3848   if (holder->is_being_initialized()) {
       
  3849     if (accessing_method->holder() == holder) {
       
  3850       // Access inside a class. The barrier can be elided when access happens in <clinit>,
       
  3851       // <init>, or a static method. In all those cases, there was an initialization
       
  3852       // barrier on the holder klass passed.
       
  3853       if (accessing_method->is_static_initializer() ||
       
  3854           accessing_method->is_object_initializer() ||
       
  3855           accessing_method->is_static()) {
       
  3856         return false;
       
  3857       }
       
  3858     } else if (accessing_method->holder()->is_subclass_of(holder)) {
       
  3859       // Access from a subclass. The barrier can be elided only when access happens in <clinit>.
       
  3860       // In case of <init> or a static method, the barrier is on the subclass is not enough:
       
  3861       // child class can become fully initialized while its parent class is still being initialized.
       
  3862       if (accessing_method->is_static_initializer()) {
       
  3863         return false;
       
  3864       }
       
  3865     }
       
  3866     ciMethod* root = method(); // the root method of compilation
       
  3867     if (root != accessing_method) {
       
  3868       return needs_clinit_barrier(holder, root); // check access in the context of compilation root
       
  3869     }
       
  3870   }
       
  3871   return true;
  3847 }
  3872 }
  3848 
  3873 
  3849 #ifndef PRODUCT
  3874 #ifndef PRODUCT
  3850 //------------------------------verify_graph_edges---------------------------
  3875 //------------------------------verify_graph_edges---------------------------
  3851 // Walk the Graph and verify that there is a one-to-one correspondence
  3876 // Walk the Graph and verify that there is a one-to-one correspondence