Skip to content

Commit

Permalink
8318183: C2: VM may crash after hitting node limit
Browse files Browse the repository at this point in the history
Reviewed-by: phh
Backport-of: 31ef400f31b1fd9a861870cce69f6d3eec72aa46
  • Loading branch information
shipilev committed Jan 3, 2024
1 parent 53211e0 commit 2a0d0ac
Show file tree
Hide file tree
Showing 8 changed files with 25 additions and 4 deletions.
1 change: 1 addition & 0 deletions src/hotspot/share/gc/shenandoah/c2/shenandoahSupport.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ bool ShenandoahBarrierC2Support::expand(Compile* C, PhaseIterGVN& igvn) {
C->clear_major_progress();

C->process_for_post_loop_opts_igvn(igvn);
if (C->failing()) return false;
}
C->set_post_loop_opts_phase(); // now for real!
}
Expand Down
2 changes: 2 additions & 0 deletions src/hotspot/share/opto/callGenerator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,8 @@ JVMState* ParseGenerator::generate(JVMState* jvms) {
}

Parse parser(jvms, method(), _expected_uses);
if (C->failing()) return nullptr;

// Grab signature for matching/allocation
GraphKit& exits = parser.exits();

Expand Down
14 changes: 13 additions & 1 deletion src/hotspot/share/opto/compile.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2107,6 +2107,8 @@ void Compile::Optimize() {
// Inline valueOf() methods now.
inline_boxing_calls(igvn);

if (failing()) return;

if (AlwaysIncrementalInline) {
inline_incrementally(igvn);
}
Expand All @@ -2122,16 +2124,20 @@ void Compile::Optimize() {
// CastPP nodes.
remove_speculative_types(igvn);

if (failing()) return;

// No more new expensive nodes will be added to the list from here
// so keep only the actual candidates for optimizations.
cleanup_expensive_nodes(igvn);

if (failing()) return;

assert(EnableVectorSupport || !has_vbox_nodes(), "sanity");
if (EnableVectorSupport && has_vbox_nodes()) {
TracePhase tp("", &timers[_t_vector]);
PhaseVector pv(igvn);
pv.optimize_vector_boxes();

if (failing()) return;
print_method(PHASE_ITER_GVN_AFTER_VECTOR, 2);
}
assert(!has_vbox_nodes(), "sanity");
Expand All @@ -2156,6 +2162,8 @@ void Compile::Optimize() {
// safepoints
remove_root_to_sfpts_edges(igvn);

if (failing()) return;

// Perform escape analysis
if (_do_escape_analysis && ConnectionGraph::has_candidates(this)) {
if (has_loops()) {
Expand Down Expand Up @@ -2255,6 +2263,8 @@ void Compile::Optimize() {

process_for_post_loop_opts_igvn(igvn);

if (failing()) return;

#ifdef ASSERT
bs->verify_gc_barriers(this, BarrierSetC2::BeforeMacroExpand);
#endif
Expand Down Expand Up @@ -2293,6 +2303,7 @@ void Compile::Optimize() {
// More opportunities to optimize virtual and MH calls.
// Though it's maybe too late to perform inlining, strength-reducing them to direct calls is still an option.
process_late_inline_calls_no_inline(igvn);
if (failing()) return;
}
} // (End scope of igvn; run destructor if necessary for asserts.)

Expand Down Expand Up @@ -4619,6 +4630,7 @@ void Compile::remove_speculative_types(PhaseIterGVN &igvn) {
igvn.remove_speculative_types();
if (modified > 0) {
igvn.optimize();
if (failing()) return;
}
#ifdef ASSERT
// Verify that after the IGVN is over no speculative type has resurfaced
Expand Down
3 changes: 2 additions & 1 deletion src/hotspot/share/opto/graphKit.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,8 @@ class GraphKit : public Phase {

#ifdef ASSERT
~GraphKit() {
assert(!has_exceptions(), "user must call transfer_exceptions_into_jvms");
assert(failing() || !has_exceptions(),
"unless compilation failed, user must call transfer_exceptions_into_jvms");
}
#endif

Expand Down
2 changes: 2 additions & 0 deletions src/hotspot/share/opto/loopnode.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4145,6 +4145,8 @@ void PhaseIdealLoop::verify() const {
int old_progress = C->major_progress();
ResourceMark rm;
PhaseIdealLoop loop_verify(_igvn, this);
if (C->failing()) return;

VectorSet visited;

fail = 0;
Expand Down
2 changes: 1 addition & 1 deletion src/hotspot/share/opto/loopnode.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -1156,7 +1156,7 @@ class PhaseIdealLoop : public PhaseTransform {
if (!C->failing()) {
// Cleanup any modified bits
igvn.optimize();

if (C->failing()) { return; }
v.log_loop_tree();
}
}
Expand Down
4 changes: 3 additions & 1 deletion src/hotspot/share/opto/matcher.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -353,7 +353,9 @@ void Matcher::match( ) {
// Recursively match trees from old space into new space.
// Correct leaves of new-space Nodes; they point to old-space.
_visited.clear();
C->set_cached_top_node(xform( C->top(), live_nodes ));
Node* const n = xform(C->top(), live_nodes);
if (C->failing()) return;
C->set_cached_top_node(n);
if (!C->failing()) {
Node* xroot = xform( C->root(), 1 );
if (xroot == nullptr) {
Expand Down
1 change: 1 addition & 0 deletions src/hotspot/share/opto/parse1.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1555,6 +1555,7 @@ void Parse::do_one_block() {
#endif //ASSERT

do_one_bytecode();
if (failing()) return;

assert(!have_se || stopped() || failing() || (sp() - pre_bc_sp) == depth,
"incorrect depth prediction: sp=%d, pre_bc_sp=%d, depth=%d", sp(), pre_bc_sp, depth);
Expand Down

1 comment on commit 2a0d0ac

@openjdk-notifier
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.