|
1 | 1 | /* |
2 | | - * Copyright (c) 1997, 2022, Oracle and/or its affiliates. All rights reserved. |
3 | | - * Copyright (c) 2012, 2014 SAP SE. All rights reserved. |
| 2 | + * Copyright (c) 1997, 2025, Oracle and/or its affiliates. All rights reserved. |
| 3 | + * Copyright (c) 2012, 2025 SAP SE. All rights reserved. |
4 | 4 | * Copyright (c) 2022, IBM Corp. |
5 | 5 | * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
6 | 6 | * |
|
27 | 27 | #include "precompiled.hpp" |
28 | 28 | #include "memory/metaspace.hpp" |
29 | 29 | #include "runtime/frame.inline.hpp" |
| 30 | +#include "runtime/os.inline.hpp" |
30 | 31 | #include "runtime/thread.hpp" |
31 | 32 |
|
32 | 33 | frame JavaThread::pd_last_frame() { |
@@ -54,9 +55,19 @@ bool JavaThread::pd_get_top_frame_for_profiling(frame* fr_addr, void* ucontext, |
54 | 55 | if (has_last_Java_frame() && frame_anchor()->walkable()) { |
55 | 56 | intptr_t* sp = last_Java_sp(); |
56 | 57 | address pc = _anchor.last_Java_pc(); |
57 | | - // pc can be seen as null because not all writers use store pc + release store sp. |
58 | | - // Simply discard the sample in this very rare case. |
59 | | - if (pc == nullptr) return false; |
| 58 | + if (pc == nullptr) { |
| 59 | + // This is not uncommon. Many c1/c2 runtime stubs do not set the pc in the anchor. |
| 60 | + intptr_t* top_sp = os::Aix::ucontext_get_sp((const ucontext_t*)ucontext); |
| 61 | + if ((uint64_t)sp <= ((frame::abi_minframe*)top_sp)->callers_sp) { |
| 62 | + // The interrupt occurred either in the last java frame or in its direct callee. |
| 63 | + // We cannot be sure that the link register LR was already saved to the |
| 64 | + // java frame. Therefore we discard this sample. |
| 65 | + return false; |
| 66 | + } |
| 67 | + // The last java pc will be found in the abi part of the last java frame. |
| 68 | + *fr_addr = frame(sp); |
| 69 | + return true; |
| 70 | + } |
60 | 71 | *fr_addr = frame(sp, pc); |
61 | 72 | return true; |
62 | 73 | } |
|
0 commit comments