From 9925014035ed203ba42cce80a23730328bbe8a50 Mon Sep 17 00:00:00 2001 From: Vladimir Ivanov Date: Fri, 1 Jul 2022 22:56:48 +0000 Subject: [PATCH] 8280320: C2: Loop opts are missing during OSR compilation Reviewed-by: thartmann, iveresov --- src/hotspot/share/ci/ciMethodData.cpp | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/src/hotspot/share/ci/ciMethodData.cpp b/src/hotspot/share/ci/ciMethodData.cpp index d8b77ab2f5193..fb3d40b063056 100644 --- a/src/hotspot/share/ci/ciMethodData.cpp +++ b/src/hotspot/share/ci/ciMethodData.cpp @@ -248,8 +248,15 @@ bool ciMethodData::load_data() { // Note: Extra data are all BitData, and do not need translation. _invocation_counter = mdo->invocation_count(); - _state = mdo->is_mature()? mature_state: immature_state; + if (_invocation_counter == 0 && mdo->backedge_count() > 0) { + // Avoid skewing counter data during OSR compilation. + // Sometimes, MDO is allocated during the very first invocation and OSR compilation is triggered + // solely by backedge counter while invocation counter stays zero. In such case, it's important + // to observe non-zero invocation count to properly scale profile counts (see ciMethod::scale_count()). + _invocation_counter = 1; + } + _state = mdo->is_mature() ? mature_state : immature_state; _eflags = mdo->eflags(); _arg_local = mdo->arg_local(); _arg_stack = mdo->arg_stack();