< prev index next >

src/hotspot/share/opto/compile.cpp

Print this page
rev 54995 : 8224675: Late GC barrier insertion for ZGC
Reviewed-by:


2189           igvn.remove_dead_node(n);
2190         }
2191         --i;
2192       }
2193     }
2194   }
2195 }
2196 
2197 //------------------------------Optimize---------------------------------------
2198 // Given a graph, optimize it.
2199 void Compile::Optimize() {
2200   TracePhase tp("optimizer", &timers[_t_optimizer]);
2201 
2202 #ifndef PRODUCT
2203   if (_directive->BreakAtCompileOption) {
2204     BREAKPOINT;
2205   }
2206 
2207 #endif
2208 
2209 #ifdef ASSERT
2210   BarrierSetC2* bs = BarrierSet::barrier_set()->barrier_set_c2();

2211   bs->verify_gc_barriers(this, BarrierSetC2::BeforeOptimize);
2212 #endif
2213 
2214   ResourceMark rm;
2215 
2216   print_inlining_reinit();
2217 
2218   NOT_PRODUCT( verify_graph_edges(); )
2219 
2220   print_method(PHASE_AFTER_PARSING);
2221 
2222  {
2223   // Iterative Global Value Numbering, including ideal transforms
2224   // Initialize IterGVN with types and values from parse-time GVN
2225   PhaseIterGVN igvn(initial_gvn());
2226 #ifdef ASSERT
2227   _modified_nodes = new (comp_arena()) Unique_Node_List(comp_arena());
2228 #endif
2229   {
2230     TracePhase tp("iterGVN", &timers[_t_iterGVN]);


2349   }
2350   if (failing())  return;
2351 
2352   // Conditional Constant Propagation;
2353   PhaseCCP ccp( &igvn );
2354   assert( true, "Break here to ccp.dump_nodes_and_types(_root,999,1)");
2355   {
2356     TracePhase tp("ccp", &timers[_t_ccp]);
2357     ccp.do_transform();
2358   }
2359   print_method(PHASE_CPP1, 2);
2360 
2361   assert( true, "Break here to ccp.dump_old2new_map()");
2362 
2363   // Iterative Global Value Numbering, including ideal transforms
2364   {
2365     TracePhase tp("iterGVN2", &timers[_t_iterGVN2]);
2366     igvn = ccp;
2367     igvn.optimize();
2368   }
2369 
2370   print_method(PHASE_ITER_GVN2, 2);
2371 
2372   if (failing())  return;
2373 
2374   // Loop transforms on the ideal graph.  Range Check Elimination,
2375   // peeling, unrolling, etc.
2376   if (!optimize_loops(igvn, LoopOptsDefault)) {
2377     return;
2378   }
2379 
2380 #if INCLUDE_ZGC
2381   if (UseZGC) {
2382     ZBarrierSetC2::find_dominating_barriers(igvn);
2383   }
2384 #endif
2385 
2386   if (failing())  return;
2387 
2388   // Ensure that major progress is now clear
2389   C->clear_major_progress();
2390 
2391   {
2392     // Verify that all previous optimizations produced a valid graph
2393     // at least to this point, even if no loop optimizations were done.
2394     TracePhase tp("idealLoopVerify", &timers[_t_idealLoopVerify]);
2395     PhaseIdealLoop::verify(igvn);
2396   }
2397 
2398   if (range_check_cast_count() > 0) {
2399     // No more loop optimizations. Remove all range check dependent CastIINodes.
2400     C->remove_range_check_casts(igvn);
2401     igvn.optimize();
2402   }
2403 
2404 #ifdef ASSERT
2405   BarrierSetC2* bs = BarrierSet::barrier_set()->barrier_set_c2();
2406   bs->verify_gc_barriers(this, BarrierSetC2::BeforeExpand);






2407 #endif
2408 
2409   {
2410     TracePhase tp("macroExpand", &timers[_t_macroExpand]);
2411     PhaseMacroExpand  mex(igvn);
2412     print_method(PHASE_BEFORE_MACRO_EXPANSION, 2);
2413     if (mex.expand_macro_nodes()) {
2414       assert(failing(), "must bail out w/ explicit message");
2415       return;
2416     }

2417   }
2418 
2419   {
2420     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)) {
2424       assert(failing(), "must bail out w/ explicit message");
2425       return;
2426     }

2427   }
2428 
2429   if (opaque4_count() > 0) {
2430     C->remove_opaque4_nodes(igvn);
2431     igvn.optimize();
2432   }
2433 
2434   DEBUG_ONLY( _modified_nodes = NULL; )
2435  } // (End scope of igvn; run destructor if necessary for asserts.)
2436 
2437  process_print_inlining();
2438  // A method with only infinite loops has no edges entering loops from root
2439  {
2440    TracePhase tp("graphReshape", &timers[_t_graphReshaping]);
2441    if (final_graph_reshaping()) {
2442      assert(failing(), "must bail out w/ explicit message");
2443      return;
2444    }
2445  }
2446 


2802       break;
2803     }
2804     default:
2805       break;
2806     }
2807   }
2808 
2809 #ifdef ASSERT
2810   if( n->is_Mem() ) {
2811     int alias_idx = get_alias_index(n->as_Mem()->adr_type());
2812     assert( n->in(0) != NULL || alias_idx != Compile::AliasIdxRaw ||
2813             // oop will be recorded in oop map if load crosses safepoint
2814             n->is_Load() && (n->as_Load()->bottom_type()->isa_oopptr() ||
2815                              LoadNode::is_immutable_value(n->in(MemNode::Address))),
2816             "raw memory operations should have control edge");
2817   }
2818   if (n->is_MemBar()) {
2819     MemBarNode* mb = n->as_MemBar();
2820     if (mb->trailing_store() || mb->trailing_load_store()) {
2821       assert(mb->leading_membar()->trailing_membar() == mb, "bad membar pair");
2822       Node* mem = mb->in(MemBarNode::Precedent);
2823       assert((mb->trailing_store() && mem->is_Store() && mem->as_Store()->is_release()) ||
2824              (mb->trailing_load_store() && mem->is_LoadStore()), "missing mem op");
2825     } else if (mb->leading()) {
2826       assert(mb->trailing_membar()->leading_membar() == mb, "bad membar pair");
2827     }
2828   }
2829 #endif
2830   // Count FPU ops and common calls, implements item (3)
2831   bool gc_handled = BarrierSet::barrier_set()->barrier_set_c2()->final_graph_reshaping(this, n, nop);
2832   if (!gc_handled) {
2833     final_graph_reshaping_main_switch(n, frc, nop);
2834   }
2835 
2836   // Collect CFG split points
2837   if (n->is_MultiBranch() && !n->is_RangeCheck()) {
2838     frc._tests.push(n);
2839   }
2840 }
2841 
2842 void Compile::final_graph_reshaping_main_switch(Node* n, Final_Reshape_Counts& frc, uint nop) {




2189           igvn.remove_dead_node(n);
2190         }
2191         --i;
2192       }
2193     }
2194   }
2195 }
2196 
2197 //------------------------------Optimize---------------------------------------
2198 // Given a graph, optimize it.
2199 void Compile::Optimize() {
2200   TracePhase tp("optimizer", &timers[_t_optimizer]);
2201 
2202 #ifndef PRODUCT
2203   if (_directive->BreakAtCompileOption) {
2204     BREAKPOINT;
2205   }
2206 
2207 #endif
2208 

2209   BarrierSetC2* bs = BarrierSet::barrier_set()->barrier_set_c2();
2210 #ifdef ASSERT
2211   bs->verify_gc_barriers(this, BarrierSetC2::BeforeOptimize);
2212 #endif
2213 
2214   ResourceMark rm;
2215 
2216   print_inlining_reinit();
2217 
2218   NOT_PRODUCT( verify_graph_edges(); )
2219 
2220   print_method(PHASE_AFTER_PARSING);
2221 
2222  {
2223   // Iterative Global Value Numbering, including ideal transforms
2224   // Initialize IterGVN with types and values from parse-time GVN
2225   PhaseIterGVN igvn(initial_gvn());
2226 #ifdef ASSERT
2227   _modified_nodes = new (comp_arena()) Unique_Node_List(comp_arena());
2228 #endif
2229   {
2230     TracePhase tp("iterGVN", &timers[_t_iterGVN]);


2349   }
2350   if (failing())  return;
2351 
2352   // Conditional Constant Propagation;
2353   PhaseCCP ccp( &igvn );
2354   assert( true, "Break here to ccp.dump_nodes_and_types(_root,999,1)");
2355   {
2356     TracePhase tp("ccp", &timers[_t_ccp]);
2357     ccp.do_transform();
2358   }
2359   print_method(PHASE_CPP1, 2);
2360 
2361   assert( true, "Break here to ccp.dump_old2new_map()");
2362 
2363   // Iterative Global Value Numbering, including ideal transforms
2364   {
2365     TracePhase tp("iterGVN2", &timers[_t_iterGVN2]);
2366     igvn = ccp;
2367     igvn.optimize();
2368   }

2369   print_method(PHASE_ITER_GVN2, 2);
2370 
2371   if (failing())  return;
2372 
2373   // Loop transforms on the ideal graph.  Range Check Elimination,
2374   // peeling, unrolling, etc.
2375   if (!optimize_loops(igvn, LoopOptsDefault)) {
2376     return;
2377   }
2378 






2379   if (failing())  return;
2380 
2381   // Ensure that major progress is now clear
2382   C->clear_major_progress();
2383 
2384   {
2385     // Verify that all previous optimizations produced a valid graph
2386     // at least to this point, even if no loop optimizations were done.
2387     TracePhase tp("idealLoopVerify", &timers[_t_idealLoopVerify]);
2388     PhaseIdealLoop::verify(igvn);
2389   }
2390 
2391   if (range_check_cast_count() > 0) {
2392     // No more loop optimizations. Remove all range check dependent CastIINodes.
2393     C->remove_range_check_casts(igvn);
2394     igvn.optimize();
2395   }
2396 
2397 #ifdef ASSERT
2398   bs->verify_gc_barriers(this, BarrierSetC2::BeforeLateInsertion);
2399 #endif
2400 
2401   bs->barrier_insertion_phase(igvn);
2402   if (failing())  return;
2403 
2404 #ifdef ASSERT
2405   bs->verify_gc_barriers(this, BarrierSetC2::BeforeMacroExpand);
2406 #endif
2407 
2408   {
2409     TracePhase tp("macroExpand", &timers[_t_macroExpand]);
2410     PhaseMacroExpand  mex(igvn);

2411     if (mex.expand_macro_nodes()) {
2412       assert(failing(), "must bail out w/ explicit message");
2413       return;
2414     }
2415     print_method(PHASE_MACRO_EXPANSION, 2);
2416   }
2417 
2418   {
2419     TracePhase tp("barrierExpand", &timers[_t_barrierExpand]);


2420     if (bs->expand_barriers(this, igvn)) {
2421       assert(failing(), "must bail out w/ explicit message");
2422       return;
2423     }
2424     print_method(PHASE_BARRIER_EXPANSION, 2);
2425   }
2426 
2427   if (opaque4_count() > 0) {
2428     C->remove_opaque4_nodes(igvn);
2429     igvn.optimize();
2430   }
2431 
2432   DEBUG_ONLY( _modified_nodes = NULL; )
2433  } // (End scope of igvn; run destructor if necessary for asserts.)
2434 
2435  process_print_inlining();
2436  // A method with only infinite loops has no edges entering loops from root
2437  {
2438    TracePhase tp("graphReshape", &timers[_t_graphReshaping]);
2439    if (final_graph_reshaping()) {
2440      assert(failing(), "must bail out w/ explicit message");
2441      return;
2442    }
2443  }
2444 


2800       break;
2801     }
2802     default:
2803       break;
2804     }
2805   }
2806 
2807 #ifdef ASSERT
2808   if( n->is_Mem() ) {
2809     int alias_idx = get_alias_index(n->as_Mem()->adr_type());
2810     assert( n->in(0) != NULL || alias_idx != Compile::AliasIdxRaw ||
2811             // oop will be recorded in oop map if load crosses safepoint
2812             n->is_Load() && (n->as_Load()->bottom_type()->isa_oopptr() ||
2813                              LoadNode::is_immutable_value(n->in(MemNode::Address))),
2814             "raw memory operations should have control edge");
2815   }
2816   if (n->is_MemBar()) {
2817     MemBarNode* mb = n->as_MemBar();
2818     if (mb->trailing_store() || mb->trailing_load_store()) {
2819       assert(mb->leading_membar()->trailing_membar() == mb, "bad membar pair");
2820       Node* mem = BarrierSet::barrier_set()->barrier_set_c2()->step_over_gc_barrier(mb->in(MemBarNode::Precedent));
2821       assert((mb->trailing_store() && mem->is_Store() && mem->as_Store()->is_release()) ||
2822              (mb->trailing_load_store() && mem->is_LoadStore()), "missing mem op");
2823     } else if (mb->leading()) {
2824       assert(mb->trailing_membar()->leading_membar() == mb, "bad membar pair");
2825     }
2826   }
2827 #endif
2828   // Count FPU ops and common calls, implements item (3)
2829   bool gc_handled = BarrierSet::barrier_set()->barrier_set_c2()->final_graph_reshaping(this, n, nop);
2830   if (!gc_handled) {
2831     final_graph_reshaping_main_switch(n, frc, nop);
2832   }
2833 
2834   // Collect CFG split points
2835   if (n->is_MultiBranch() && !n->is_RangeCheck()) {
2836     frc._tests.push(n);
2837   }
2838 }
2839 
2840 void Compile::final_graph_reshaping_main_switch(Node* n, Final_Reshape_Counts& frc, uint nop) {


< prev index next >