From f080b4bb8a75284db1b6037f8c00ef3b1ef1add1 Mon Sep 17 00:00:00 2001 From: Matthias Baesken Date: Thu, 29 Aug 2024 07:07:12 +0000 Subject: [PATCH] 8333098: ubsan: bytecodeInfo.cpp:318:59: runtime error: division by zero Reviewed-by: kvn, iveresov --- src/hotspot/share/opto/bytecodeInfo.cpp | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/hotspot/share/opto/bytecodeInfo.cpp b/src/hotspot/share/opto/bytecodeInfo.cpp index 9e0fa6f760f..35365f37f48 100644 --- a/src/hotspot/share/opto/bytecodeInfo.cpp +++ b/src/hotspot/share/opto/bytecodeInfo.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 1998, 2023, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 1998, 2024, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -315,7 +315,9 @@ bool InlineTree::should_not_inline(ciMethod* callee_method, ciMethod* caller_met int invoke_count = caller_method->interpreter_invocation_count(); assert(invoke_count != 0, "require invocation count greater than zero"); double freq = (double)call_site_count / (double)invoke_count; - double min_freq = MAX2(MinInlineFrequencyRatio, 1.0 / CompilationPolicy::min_invocations()); + // avoid division by 0, set divisor to at least 1 + int cp_min_inv = MAX2(1, CompilationPolicy::min_invocations()); + double min_freq = MAX2(MinInlineFrequencyRatio, 1.0 / cp_min_inv); if (freq < min_freq) { set_msg("low call site frequency");