11/*
22 * Copyright (c) 1997, 2025, Oracle and/or its affiliates. All rights reserved.
3- * Copyright (c) 2012, 2024 SAP SE. All rights reserved.
3+ * Copyright (c) 2012, 2025 SAP SE. All rights reserved.
44 * Copyright (c) 2022, IBM Corp.
55 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
66 *
2727#include " memory/metaspace.hpp"
2828#include " runtime/frame.inline.hpp"
2929#include " runtime/javaThread.hpp"
30+ #include " runtime/os.inline.hpp"
3031
3132frame JavaThread::pd_last_frame () {
3233 assert (has_last_Java_frame (), " must have last_Java_sp() when suspended" );
@@ -47,9 +48,17 @@ bool JavaThread::pd_get_top_frame_for_profiling(frame* fr_addr, void* ucontext,
4748 if (has_last_Java_frame () && frame_anchor ()->walkable ()) {
4849 intptr_t * sp = last_Java_sp ();
4950 address pc = _anchor.last_Java_pc ();
50- // pc can be seen as null because not all writers use store pc + release store sp.
51- // Simply discard the sample in this very rare case.
52- if (pc == nullptr ) return false ;
51+ if (pc == nullptr ) {
52+ // This is not uncommon. Many c1/c2 runtime stubs do not set the pc in the anchor.
53+ intptr_t * top_sp = os::Aix::ucontext_get_sp ((const ucontext_t *)ucontext);
54+ if ((uint64_t )sp <= ((frame::common_abi*)top_sp)->callers_sp ) {
55+ // The interrupt occurred either in the last java frame or in its direct callee.
56+ // We cannot be sure that the link register LR was already saved to the
57+ // java frame. Therefore we discard this sample.
58+ return false ;
59+ }
60+ // The last java pc will be found in the abi part of the last java frame.
61+ }
5362 *fr_addr = frame (sp, pc, frame::kind::code_blob);
5463 return true ;
5564 }
0 commit comments