From 4f283f188c43cb25c4eafcdf22eb7f58eae286cc Mon Sep 17 00:00:00 2001 From: Aleksey Shipilev Date: Thu, 18 Dec 2025 09:43:28 +0000 Subject: [PATCH] 8373820: C2: Robust Node::uncast_helper infinite loop check Reviewed-by: qamai, chagedorn --- src/hotspot/share/opto/node.cpp | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/src/hotspot/share/opto/node.cpp b/src/hotspot/share/opto/node.cpp index 2452677caf3..40aa2943dcd 100644 --- a/src/hotspot/share/opto/node.cpp +++ b/src/hotspot/share/opto/node.cpp @@ -999,18 +999,22 @@ bool Node::has_out_with(int opcode1, int opcode2, int opcode3, int opcode4) { //---------------------------uncast_helper------------------------------------- Node* Node::uncast_helper(const Node* p, bool keep_deps) { #ifdef ASSERT + // If we end up traversing more nodes than we actually have, + // it is definitely an infinite loop. + uint max_depth = Compile::current()->unique(); uint depth_count = 0; const Node* orig_p = p; #endif while (true) { #ifdef ASSERT - if (depth_count >= K) { + if (depth_count++ >= max_depth) { orig_p->dump(4); - if (p != orig_p) + if (p != orig_p) { p->dump(1); + } + fatal("infinite loop in Node::uncast_helper"); } - assert(depth_count++ < K, "infinite loop in Node::uncast_helper"); #endif if (p == nullptr || p->req() != 2) { break;