@@ -2658,12 +2658,6 @@ bool PhaseMacroExpand::expand_macro_nodes() {
2658
2658
// Last attempt to eliminate macro nodes.
2659
2659
eliminate_macro_nodes ();
2660
2660
2661
- // Make sure expansion will not cause node limit to be exceeded.
2662
- // Worst case is a macro node gets expanded into about 200 nodes.
2663
- // Allow 50% more for optimization.
2664
- if (C->check_node_count (C->macro_count () * 300 , " out of nodes before macro expansion" ) )
2665
- return true ;
2666
-
2667
2661
// Eliminate Opaque and LoopLimit nodes. Do it after all loop optimizations.
2668
2662
bool progress = true ;
2669
2663
while (progress) {
@@ -2719,17 +2713,44 @@ bool PhaseMacroExpand::expand_macro_nodes() {
2719
2713
}
2720
2714
}
2721
2715
2716
+ // Clean up the graph so we're less likely to hit the maximum node
2717
+ // limit
2718
+ _igvn.set_delay_transform (false );
2719
+ _igvn.optimize ();
2720
+ if (C->failing ()) return true ;
2721
+ _igvn.set_delay_transform (true );
2722
+
2723
+
2724
+ // Because we run IGVN after each expansion, some macro nodes may go
2725
+ // dead and be removed from the list as we iterate over it. Move
2726
+ // Allocate nodes (processed in a second pass) at the beginning of
2727
+ // the list and then iterate from the last element of the list until
2728
+ // an Allocate node is seen. This is robust to random deletion in
2729
+ // the list due to nodes going dead.
2730
+ C->sort_macro_nodes ();
2731
+
2722
2732
// expand arraycopy "macro" nodes first
2723
2733
// For ReduceBulkZeroing, we must first process all arraycopy nodes
2724
2734
// before the allocate nodes are expanded.
2725
- for (int i = C->macro_count (); i > 0 ; i--) {
2726
- Node* n = C->macro_node (i-1 );
2735
+ while (C->macro_count () > 0 ) {
2736
+ int macro_count = C->macro_count ();
2737
+ Node * n = C->macro_node (macro_count-1 );
2727
2738
assert (n->is_macro (), " only macro nodes expected here" );
2728
2739
if (_igvn.type (n) == Type::TOP || (n->in (0 ) != NULL && n->in (0 )->is_top ())) {
2729
2740
// node is unreachable, so don't try to expand it
2730
2741
C->remove_macro_node (n);
2731
2742
continue ;
2732
2743
}
2744
+ if (n->is_Allocate ()) {
2745
+ break ;
2746
+ }
2747
+ // Make sure expansion will not cause node limit to be exceeded.
2748
+ // Worst case is a macro node gets expanded into about 200 nodes.
2749
+ // Allow 50% more for optimization.
2750
+ if (C->check_node_count (300 , " out of nodes before macro expansion" )) {
2751
+ return true ;
2752
+ }
2753
+
2733
2754
debug_only (int old_macro_count = C->macro_count (););
2734
2755
switch (n->class_id ()) {
2735
2756
case Node::Class_Lock:
@@ -2748,18 +2769,23 @@ bool PhaseMacroExpand::expand_macro_nodes() {
2748
2769
expand_subtypecheck_node (n->as_SubTypeCheck ());
2749
2770
assert (C->macro_count () == (old_macro_count - 1 ), " expansion must have deleted one node from macro list" );
2750
2771
break ;
2772
+ default :
2773
+ assert (false , " unknown node type in macro list" );
2751
2774
}
2775
+ assert (C->macro_count () < macro_count, " must have deleted a node from macro list" );
2776
+ if (C->failing ()) return true ;
2777
+
2778
+ // Clean up the graph so we're less likely to hit the maximum node
2779
+ // limit
2780
+ _igvn.set_delay_transform (false );
2781
+ _igvn.optimize ();
2752
2782
if (C->failing ()) return true ;
2783
+ _igvn.set_delay_transform (true );
2753
2784
}
2754
2785
2755
2786
// All nodes except Allocate nodes are expanded now. There could be
2756
2787
// new optimization opportunities (such as folding newly created
2757
2788
// load from a just allocated object). Run IGVN.
2758
- _igvn.set_delay_transform (false );
2759
- _igvn.optimize ();
2760
- if (C->failing ()) return true ;
2761
-
2762
- _igvn.set_delay_transform (true );
2763
2789
2764
2790
// expand "macro" nodes
2765
2791
// nodes are removed from the macro list as they are processed
@@ -2772,6 +2798,12 @@ bool PhaseMacroExpand::expand_macro_nodes() {
2772
2798
C->remove_macro_node (n);
2773
2799
continue ;
2774
2800
}
2801
+ // Make sure expansion will not cause node limit to be exceeded.
2802
+ // Worst case is a macro node gets expanded into about 200 nodes.
2803
+ // Allow 50% more for optimization.
2804
+ if (C->check_node_count (300 , " out of nodes before macro expansion" )) {
2805
+ return true ;
2806
+ }
2775
2807
switch (n->class_id ()) {
2776
2808
case Node::Class_Allocate:
2777
2809
expand_allocate (n->as_Allocate ());
@@ -2784,10 +2816,15 @@ bool PhaseMacroExpand::expand_macro_nodes() {
2784
2816
}
2785
2817
assert (C->macro_count () < macro_count, " must have deleted a node from macro list" );
2786
2818
if (C->failing ()) return true ;
2819
+
2820
+ // Clean up the graph so we're less likely to hit the maximum node
2821
+ // limit
2822
+ _igvn.set_delay_transform (false );
2823
+ _igvn.optimize ();
2824
+ if (C->failing ()) return true ;
2825
+ _igvn.set_delay_transform (true );
2787
2826
}
2788
2827
2789
2828
_igvn.set_delay_transform (false );
2790
- _igvn.optimize ();
2791
- if (C->failing ()) return true ;
2792
2829
return false ;
2793
2830
}
0 commit comments