8373820: C2: Robust Node::uncast_helper infinite loop check

Reviewed-by: qamai, chagedorn
This commit is contained in:
Aleksey Shipilev 2025-12-18 09:43:28 +00:00
parent d8eb1259f4
commit 4f283f188c

View File

@ -999,18 +999,22 @@ bool Node::has_out_with(int opcode1, int opcode2, int opcode3, int opcode4) {
//---------------------------uncast_helper------------------------------------- //---------------------------uncast_helper-------------------------------------
Node* Node::uncast_helper(const Node* p, bool keep_deps) { Node* Node::uncast_helper(const Node* p, bool keep_deps) {
#ifdef ASSERT #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; uint depth_count = 0;
const Node* orig_p = p; const Node* orig_p = p;
#endif #endif
while (true) { while (true) {
#ifdef ASSERT #ifdef ASSERT
if (depth_count >= K) { if (depth_count++ >= max_depth) {
orig_p->dump(4); orig_p->dump(4);
if (p != orig_p) if (p != orig_p) {
p->dump(1); p->dump(1);
}
fatal("infinite loop in Node::uncast_helper");
} }
assert(depth_count++ < K, "infinite loop in Node::uncast_helper");
#endif #endif
if (p == nullptr || p->req() != 2) { if (p == nullptr || p->req() != 2) {
break; break;