From 3efbbf8bfdb114f3f43ec8d908aea0cfb47ec974 Mon Sep 17 00:00:00 2001 From: Richard Reingruber Date: Tue, 22 Jul 2025 06:49:33 +0000 Subject: [PATCH 1/4] Backport d5908231ebc16f443b3fc9b2ebf03cc4deb67373 --- src/hotspot/os_cpu/aix_ppc/thread_aix_ppc.cpp | 19 ++++++++++++++----- .../os_cpu/linux_ppc/thread_linux_ppc.cpp | 18 +++++++++++++----- 2 files changed, 27 insertions(+), 10 deletions(-) diff --git a/src/hotspot/os_cpu/aix_ppc/thread_aix_ppc.cpp b/src/hotspot/os_cpu/aix_ppc/thread_aix_ppc.cpp index 3bfee914588..e7478b57a3f 100644 --- a/src/hotspot/os_cpu/aix_ppc/thread_aix_ppc.cpp +++ b/src/hotspot/os_cpu/aix_ppc/thread_aix_ppc.cpp @@ -1,6 +1,6 @@ /* - * Copyright (c) 1997, 2022, Oracle and/or its affiliates. All rights reserved. - * Copyright (c) 2012, 2014 SAP SE. All rights reserved. + * Copyright (c) 1997, 2025, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2012, 2025 SAP SE. All rights reserved. * Copyright (c) 2022, IBM Corp. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * @@ -28,6 +28,7 @@ #include "memory/metaspace.hpp" #include "runtime/frame.inline.hpp" #include "runtime/thread.hpp" +#include "runtime/os.inline.hpp" frame JavaThread::pd_last_frame() { assert(has_last_Java_frame(), "must have last_Java_sp() when suspended"); @@ -54,9 +55,17 @@ bool JavaThread::pd_get_top_frame_for_profiling(frame* fr_addr, void* ucontext, if (has_last_Java_frame() && frame_anchor()->walkable()) { intptr_t* sp = last_Java_sp(); address pc = _anchor.last_Java_pc(); - // pc can be seen as null because not all writers use store pc + release store sp. - // Simply discard the sample in this very rare case. - if (pc == nullptr) return false; + if (pc == nullptr) { + // This is not uncommon. Many c1/c2 runtime stubs do not set the pc in the anchor. + intptr_t* top_sp = os::Aix::ucontext_get_sp((const ucontext_t*)ucontext); + if ((uint64_t)sp <= ((frame::common_abi*)top_sp)->callers_sp) { + // The interrupt occurred either in the last java frame or in its direct callee. + // We cannot be sure that the link register LR was already saved to the + // java frame. Therefore we discard this sample. + return false; + } + // The last java pc will be found in the abi part of the last java frame. + } *fr_addr = frame(sp, pc); return true; } diff --git a/src/hotspot/os_cpu/linux_ppc/thread_linux_ppc.cpp b/src/hotspot/os_cpu/linux_ppc/thread_linux_ppc.cpp index bf15786ae1f..94cf70416bf 100644 --- a/src/hotspot/os_cpu/linux_ppc/thread_linux_ppc.cpp +++ b/src/hotspot/os_cpu/linux_ppc/thread_linux_ppc.cpp @@ -1,6 +1,6 @@ /* - * Copyright (c) 1997, 2022, Oracle and/or its affiliates. All rights reserved. - * Copyright (c) 2012, 2022 SAP SE. All rights reserved. + * Copyright (c) 1997, 2025, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2012, 2025 SAP SE. 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 @@ -53,9 +53,17 @@ bool JavaThread::pd_get_top_frame_for_profiling(frame* fr_addr, void* ucontext, if (has_last_Java_frame() && frame_anchor()->walkable()) { intptr_t* sp = last_Java_sp(); address pc = _anchor.last_Java_pc(); - // pc can be seen as null because not all writers use store pc + release store sp. - // Simply discard the sample in this very rare case. - if (pc == nullptr) return false; + if (pc == nullptr) { + // This is not uncommon. Many c1/c2 runtime stubs do not set the pc in the anchor. + intptr_t* top_sp = os::Linux::ucontext_get_sp((const ucontext_t*)ucontext); + if ((uint64_t)sp <= ((frame::common_abi*)top_sp)->callers_sp) { + // The interrupt occurred either in the last java frame or in its direct callee. + // We cannot be sure that the link register LR was already saved to the + // java frame. Therefore we discard this sample. + return false; + } + // The last java pc will be found in the abi part of the last java frame. + } *fr_addr = frame(sp, pc); return true; } From 4bbbe10f465050c17d3ca2add40bc7feff9b3a5d Mon Sep 17 00:00:00 2001 From: Richard Reingruber Date: Fri, 19 Sep 2025 09:13:10 +0200 Subject: [PATCH 2/4] Order includes in thread_aix_ppc.cpp --- src/hotspot/os_cpu/aix_ppc/thread_aix_ppc.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/hotspot/os_cpu/aix_ppc/thread_aix_ppc.cpp b/src/hotspot/os_cpu/aix_ppc/thread_aix_ppc.cpp index e7478b57a3f..da58b61682c 100644 --- a/src/hotspot/os_cpu/aix_ppc/thread_aix_ppc.cpp +++ b/src/hotspot/os_cpu/aix_ppc/thread_aix_ppc.cpp @@ -27,8 +27,8 @@ #include "precompiled.hpp" #include "memory/metaspace.hpp" #include "runtime/frame.inline.hpp" -#include "runtime/thread.hpp" #include "runtime/os.inline.hpp" +#include "runtime/thread.hpp" frame JavaThread::pd_last_frame() { assert(has_last_Java_frame(), "must have last_Java_sp() when suspended"); From 53461d2d71fceb09c0edc6990cd70cd773a667c4 Mon Sep 17 00:00:00 2001 From: Richard Reingruber Date: Mon, 22 Sep 2025 17:07:24 +0200 Subject: [PATCH 3/4] Rename frame::common_abi to frame::abi_minframe --- src/hotspot/os_cpu/aix_ppc/thread_aix_ppc.cpp | 2 +- src/hotspot/os_cpu/linux_ppc/thread_linux_ppc.cpp | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/hotspot/os_cpu/aix_ppc/thread_aix_ppc.cpp b/src/hotspot/os_cpu/aix_ppc/thread_aix_ppc.cpp index da58b61682c..a592c022381 100644 --- a/src/hotspot/os_cpu/aix_ppc/thread_aix_ppc.cpp +++ b/src/hotspot/os_cpu/aix_ppc/thread_aix_ppc.cpp @@ -58,7 +58,7 @@ bool JavaThread::pd_get_top_frame_for_profiling(frame* fr_addr, void* ucontext, if (pc == nullptr) { // This is not uncommon. Many c1/c2 runtime stubs do not set the pc in the anchor. intptr_t* top_sp = os::Aix::ucontext_get_sp((const ucontext_t*)ucontext); - if ((uint64_t)sp <= ((frame::common_abi*)top_sp)->callers_sp) { + if ((uint64_t)sp <= ((frame::abi_minframe*)top_sp)->callers_sp) { // The interrupt occurred either in the last java frame or in its direct callee. // We cannot be sure that the link register LR was already saved to the // java frame. Therefore we discard this sample. diff --git a/src/hotspot/os_cpu/linux_ppc/thread_linux_ppc.cpp b/src/hotspot/os_cpu/linux_ppc/thread_linux_ppc.cpp index 94cf70416bf..3b254a2f0eb 100644 --- a/src/hotspot/os_cpu/linux_ppc/thread_linux_ppc.cpp +++ b/src/hotspot/os_cpu/linux_ppc/thread_linux_ppc.cpp @@ -56,7 +56,7 @@ bool JavaThread::pd_get_top_frame_for_profiling(frame* fr_addr, void* ucontext, if (pc == nullptr) { // This is not uncommon. Many c1/c2 runtime stubs do not set the pc in the anchor. intptr_t* top_sp = os::Linux::ucontext_get_sp((const ucontext_t*)ucontext); - if ((uint64_t)sp <= ((frame::common_abi*)top_sp)->callers_sp) { + if ((uint64_t)sp <= ((frame::abi_minframe*)top_sp)->callers_sp) { // The interrupt occurred either in the last java frame or in its direct callee. // We cannot be sure that the link register LR was already saved to the // java frame. Therefore we discard this sample. From fcdc188a5d6fb6a498d33ccab513f484bcac21f5 Mon Sep 17 00:00:00 2001 From: Richard Reingruber Date: Tue, 23 Sep 2025 09:33:54 +0200 Subject: [PATCH 4/4] Use frame constructur that inits pc from the lr slot --- src/hotspot/os_cpu/aix_ppc/thread_aix_ppc.cpp | 2 ++ src/hotspot/os_cpu/linux_ppc/thread_linux_ppc.cpp | 2 ++ 2 files changed, 4 insertions(+) diff --git a/src/hotspot/os_cpu/aix_ppc/thread_aix_ppc.cpp b/src/hotspot/os_cpu/aix_ppc/thread_aix_ppc.cpp index a592c022381..69cd56e4f15 100644 --- a/src/hotspot/os_cpu/aix_ppc/thread_aix_ppc.cpp +++ b/src/hotspot/os_cpu/aix_ppc/thread_aix_ppc.cpp @@ -65,6 +65,8 @@ bool JavaThread::pd_get_top_frame_for_profiling(frame* fr_addr, void* ucontext, return false; } // The last java pc will be found in the abi part of the last java frame. + *fr_addr = frame(sp); + return true; } *fr_addr = frame(sp, pc); return true; diff --git a/src/hotspot/os_cpu/linux_ppc/thread_linux_ppc.cpp b/src/hotspot/os_cpu/linux_ppc/thread_linux_ppc.cpp index 3b254a2f0eb..06a2a776923 100644 --- a/src/hotspot/os_cpu/linux_ppc/thread_linux_ppc.cpp +++ b/src/hotspot/os_cpu/linux_ppc/thread_linux_ppc.cpp @@ -63,6 +63,8 @@ bool JavaThread::pd_get_top_frame_for_profiling(frame* fr_addr, void* ucontext, return false; } // The last java pc will be found in the abi part of the last java frame. + *fr_addr = frame(sp); + return true; } *fr_addr = frame(sp, pc); return true;