1
1
/*
2
- * Copyright (c) 1997, 2023 , 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
*
28
28
#include " memory/metaspace.hpp"
29
29
#include " runtime/frame.inline.hpp"
30
30
#include " runtime/javaThread.hpp"
31
+ #include " runtime/os.inline.hpp"
31
32
32
33
frame JavaThread::pd_last_frame () {
33
34
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,
47
48
if (has_last_Java_frame () && frame_anchor ()->walkable ()) {
48
49
intptr_t * sp = last_Java_sp ();
49
50
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
+ }
53
62
*fr_addr = frame (sp, pc);
54
63
return true ;
55
64
}
0 commit comments