New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
8178287: AsyncGetCallTrace fails to traverse valid Java stacks #4436
Closed
Closed
Changes from 6 commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
b0ecec2
Extract sender frame parsing to CodeBlock::FrameParser
luhenry 28a090e
Allow AsyncGetCallTrace and JFR to walk a stub frame
luhenry df2d275
Allow AsyncGetCallTrace and JFR to unwind stack from nmethod's prolog
luhenry 2f2e49b
Allow AsyncGetCallTrace and JFR to unwind stack from vtable stub
luhenry 85f218c
Disable checks in FrameParser when known to be safe
luhenry b1d8611
Fix comments
luhenry 1f5babd
Merge branch 'master' of https://github.com/openjdk/jdk into fix-8178287
luhenry 5433993
Remove FrameParser and the required allocation
luhenry File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,131 @@ | ||
/* | ||
* Copyright (c) 2021, Oracle and/or its affiliates. All rights reserved. | ||
* Copyright (c) 2021, Datadog, Inc. 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 | ||
* under the terms of the GNU General Public License version 2 only, as | ||
* published by the Free Software Foundation. | ||
* | ||
* This code is distributed in the hope that it will be useful, but WITHOUT | ||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | ||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License | ||
* version 2 for more details (a copy is included in the LICENSE file that | ||
* accompanied this code). | ||
* | ||
* You should have received a copy of the GNU General Public License version | ||
* 2 along with this work; if not, write to the Free Software Foundation, | ||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. | ||
* | ||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA | ||
* or visit www.oracle.com if you need additional information or have any | ||
* questions. | ||
* | ||
*/ | ||
|
||
#include "precompiled.hpp" | ||
#include "code/codeBlob.hpp" | ||
#include "code/compiledMethod.hpp" | ||
#include "code/nmethod.hpp" | ||
#include "interpreter/interpreter.hpp" | ||
#include "runtime/frame.hpp" | ||
|
||
bool CodeBlob::FrameParser::sender_frame(JavaThread *thread, bool check, address pc, intptr_t* sp, intptr_t* unextended_sp, intptr_t* fp, bool fp_safe, | ||
address* sender_pc, intptr_t** sender_sp, intptr_t** sender_unextended_sp, intptr_t*** saved_fp) { | ||
// must be some sort of compiled/runtime frame | ||
// fp does not have to be safe (although it could be check for c1?) | ||
|
||
assert(sender_pc != NULL, "invariant"); | ||
assert(sender_sp != NULL, "invariant"); | ||
|
||
// First check if frame is complete and tester is reliable | ||
if (check && !_cb->is_frame_complete_at(pc)) { | ||
// Adapter blobs never have a complete frame and are never ok. | ||
if (_cb->is_adapter_blob()) { | ||
luhenry marked this conversation as resolved.
Show resolved
Hide resolved
|
||
return false; | ||
} | ||
} | ||
|
||
// check for a valid frame_size, otherwise we are unlikely to get a valid sender_pc | ||
if (check && _cb->frame_size() <= 0) { | ||
return false; | ||
} | ||
|
||
*sender_sp = unextended_sp + _cb->frame_size(); | ||
// Is sender_sp safe? | ||
if (check && thread != NULL && !thread->is_in_full_stack_checked((address)*sender_sp)) { | ||
return false; | ||
} | ||
*sender_pc = (address)*((*sender_sp) - frame::return_addr_offset); | ||
|
||
if (sender_unextended_sp) *sender_unextended_sp = *sender_sp; | ||
// Note: frame::sender_sp_offset is only valid for compiled frame | ||
if (saved_fp) *saved_fp = (intptr_t**)((*sender_sp) - frame::sender_sp_offset); | ||
|
||
return true; | ||
} | ||
|
||
bool InterpreterBlob::FrameParser::sender_frame(JavaThread *thread, bool check, address pc, intptr_t* sp, intptr_t* unextended_sp, intptr_t* fp, bool fp_safe, | ||
address* sender_pc, intptr_t** sender_sp, intptr_t** sender_unextended_sp, intptr_t*** saved_fp) { | ||
|
||
assert(sender_pc != NULL, "invariant"); | ||
assert(sender_sp != NULL, "invariant"); | ||
|
||
// fp must be safe | ||
if (check && !fp_safe) { | ||
return false; | ||
} | ||
|
||
*sender_pc = (address)*(fp + frame::return_addr_offset); | ||
// for interpreted frames, the value below is the sender "raw" sp, | ||
// which can be different from the sender unextended sp (the sp seen | ||
// by the sender) because of current frame local variables | ||
*sender_sp = fp + frame::sender_sp_offset; | ||
|
||
if (sender_unextended_sp) *sender_unextended_sp = (intptr_t*)*(fp + frame::interpreter_frame_sender_sp_offset); | ||
if (saved_fp) *saved_fp = (intptr_t**)(fp + frame::link_offset); | ||
|
||
return true; | ||
} | ||
|
||
bool VtableBlob::FrameParser::sender_frame(JavaThread *thread, bool check, address pc, intptr_t* sp, intptr_t* unextended_sp, intptr_t* fp, bool fp_safe, | ||
address* sender_pc, intptr_t** sender_sp, intptr_t** sender_unextended_sp, intptr_t*** saved_fp) { | ||
return CodeBlob::FrameParser::sender_frame(thread, check, pc, sp, unextended_sp, fp, fp_safe, | ||
sender_pc, sender_sp, sender_unextended_sp, saved_fp); | ||
} | ||
|
||
bool StubRoutinesBlob::FrameParser::sender_frame(JavaThread *thread, bool check, address pc, intptr_t* sp, intptr_t* unextended_sp, intptr_t* fp, bool fp_safe, | ||
address* sender_pc, intptr_t** sender_sp, intptr_t** sender_unextended_sp, intptr_t*** saved_fp) { | ||
|
||
assert(sender_pc != NULL, "invariant"); | ||
assert(sender_sp != NULL, "invariant"); | ||
|
||
// First check if frame is complete and tester is reliable | ||
if (check && !_cb->is_frame_complete_at(pc)) { | ||
return false; | ||
} | ||
|
||
return CodeBlob::FrameParser::sender_frame(thread, check, pc, sp, unextended_sp, fp, fp_safe, | ||
sender_pc, sender_sp, sender_unextended_sp, saved_fp); | ||
} | ||
|
||
bool CompiledMethod::FrameParser::sender_frame(JavaThread *thread, bool check, address pc, intptr_t* sp, intptr_t* unextended_sp, intptr_t* fp, bool fp_safe, | ||
address* sender_pc, intptr_t** sender_sp, intptr_t** sender_unextended_sp, intptr_t*** saved_fp) { | ||
|
||
assert(sender_pc != NULL, "invariant"); | ||
assert(sender_sp != NULL, "invariant"); | ||
|
||
// First check if frame is complete and tester is reliable | ||
if (check && !_cb->is_frame_complete_at(pc)) { | ||
return false; | ||
} | ||
|
||
return CodeBlob::FrameParser::sender_frame(thread, check, pc, sp, unextended_sp, fp, fp_safe, | ||
sender_pc, sender_sp, sender_unextended_sp, saved_fp); | ||
} | ||
|
||
bool nmethod::FrameParser::sender_frame(JavaThread *thread, bool check, address pc, intptr_t* sp, intptr_t* unextended_sp, intptr_t* fp, bool fp_safe, | ||
address* sender_pc, intptr_t** sender_sp, intptr_t** sender_unextended_sp, intptr_t*** saved_fp) { | ||
return CompiledMethod::FrameParser::sender_frame(thread, check, pc, sp, unextended_sp, fp, fp_safe, | ||
sender_pc, sender_sp, sender_unextended_sp, saved_fp); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hi @tivrfoa, thanks for making a comment in an OpenJDK project!
All comments and discussions in the OpenJDK Community must be made available under the OpenJDK Terms of Use. If you already are an OpenJDK Author, Committer or Reviewer, please click here to open a new issue so that we can record that fact. Please Use "Add GitHub user tivrfoa for the summary.
If you are not an OpenJDK Author, Committer or Reviewer, simply check the box below to accept the OpenJDK Terms of Use for your comments.
Your comment will be automatically restored once you have accepted the OpenJDK Terms of Use.