-
Notifications
You must be signed in to change notification settings - Fork 5.8k
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
8299570: [JVMCI] Insufficient error handling when CodeBuffer is exhausted #11945
Conversation
👋 Welcome back dnsimon! A progress list of the required criteria for merging this PR into |
Webrevs
|
@@ -1178,7 +1178,9 @@ void CodeInstaller::site_Call(CodeBuffer& buffer, u1 tag, jint pc_offset, HotSpo | |||
CodeInstaller::pd_relocate_JavaMethod(buffer, method, pc_offset, JVMCI_CHECK); | |||
if (_next_call_type == INVOKESTATIC || _next_call_type == INVOKESPECIAL) { | |||
// Need a static call stub for transitions from compiled to interpreted. | |||
CompiledStaticCall::emit_to_interp_stub(buffer, _instructions->start() + pc_offset); | |||
if (CompiledStaticCall::emit_to_interp_stub(buffer, _instructions->start() + pc_offset) == nullptr) { |
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.
We use estimate_stubs_size to presize the buffer to include space for these so it should never fail I think, but we should be checking anyway. Maybe estimate_stubs_size should be computing space for the aarch64 trampolines?
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.
it looks like estimate_stubs_size is computing space for the trampolines via
size += trampoline_stubs * CompiledStaticCall::to_trampoline_stub_size();
?
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.
It seems like the estimate agrees with the code emitted for the trampoline, so we either have a general problem in this computation or we have some other unexpected use of code cache space. It isn't critical that we get this estimate right but we do try to avoid resizing during code installation as it can be expensive.
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.
Yes, this is a very defensive (and cheap) check that should never fail. Still, better to have it.
MacroAssembler a(&cbuf); | ||
address stub = NULL; | ||
|
||
if (a.far_branches() | ||
&& ! is_NativeCallTrampolineStub_at(instruction_address() + displacement())) { | ||
stub = a.emit_trampoline_stub(instruction_address() - cbuf.insts()->start(), dest); | ||
if (stub == nullptr) { | ||
JVMCI_ERROR_0("could not emit trampoline stub - code cache is full"); | ||
} | ||
} |
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.
The if (stub == null) test below should be the else branch of this if which I think makes it clearer. Why do we even bother returning the stub?
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.
The if (stub == null) test below should be the else branch of this if which I think makes it clearer
I'm suspecting this is indeed a dormant bug. I will investigate further.
@theRealAph any chance you recall the intended logic here?
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.
I've pushed 0e4fb65 which attempts to clear up the logic in this method. It would be great if some aarch64 experts could help review it (cc @adinn @theRealAph).
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.
@dougxc I'm not sure why the above code is written the way it is rather than the way you rewrote it. I cannot see any reason why there should already be a trampoline stub in place when trampoline_jump is called given how it is being called at present. I thought perhaps it might be something to do with the (newly introduced) shared trampoline code but that is not relevant here and, besides, this routine has been thew way it is since it was first introduced.
I know the trampoline (and related far jump) code has been subject to change over the years so it may be something to do with how this routine was called in an earlier incarnation of the code. Andrew Haley will have a better idea than me as he was the original author.
Anyway, if we may need far branches and the call to is_NativeCallTrampolineStub_at fails then it does not seem tome to make any sense to call set_destination (at least null is returned which is correct). So, I think your rewrite looks like it is doing the right thing.
I think you probably need an ok from Andrew Haley here though.
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.
Ok, thanks for your input. I'll wait for @theRealAph to review it as well.
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.
@theRealAph @adinn can I now merge this PR?
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.
@dougxc Still ok with me. I just pinged Andrew Haley to see if he is ok with it.
@dougxc This change now passes all automated pre-integration checks. ℹ️ This project also has non-automated pre-integration requirements. Please see the file CONTRIBUTING.md for details. After integration, the commit message for the final commit will be:
You can use pull request commands such as /summary, /contributor and /issue to adjust it as needed. At the time when this comment was updated there had been 1 new commit pushed to the Please see this link for an up-to-date comparison between the source branch of this pull request and the ➡️ To integrate this PR with the above commit message to the |
@dougxc this pull request can not be integrated into git checkout JDK-8299570
git fetch https://git.openjdk.org/jdk master
git merge FETCH_HEAD
# resolve conflicts and follow the instructions given by git merge
git commit -m "Merge master"
git push |
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.
I'm happy to approve this.
@dougxc I'm assuming the test failures are unrelated? If so then ok to push. |
JVMCI_ERROR("single-use stub should not exist"); | ||
} | ||
} else { | ||
// If not using far branches, patch this call directly to dest. |
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.
This is all very complicated. Can't we just add JVMCI_ERROR
s where we need them?
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.
I'm not following - isn't this exactly what the code is doing? Maybe you could demonstrate how you think it should look.
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.
Maybe it would be nicer to get the ! far_branches
code path out of the way first, and return immediately.
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.
Something like this?
diff --git a/src/hotspot/cpu/aarch64/nativeInst_aarch64.cpp b/src/hotspot/cpu/aarch64/nativeInst_aarch64.cpp
index 88dc59f80d0..83ec182d2c7 100644
--- a/src/hotspot/cpu/aarch64/nativeInst_aarch64.cpp
+++ b/src/hotspot/cpu/aarch64/nativeInst_aarch64.cpp
@@ -532,21 +532,22 @@ void NativeCallTrampolineStub::set_destination(address new_destination) {
void NativeCall::trampoline_jump(CodeBuffer &cbuf, address dest, JVMCI_TRAPS) {
MacroAssembler a(&cbuf);
- if (a.far_branches()) {
- if (!is_NativeCallTrampolineStub_at(instruction_address() + displacement())) {
- address stub = a.emit_trampoline_stub(instruction_address() - cbuf.insts()->start(), dest);
- if (stub == nullptr) {
- JVMCI_ERROR("could not emit trampoline stub - code cache is full");
- }
- // The relocation is created while emitting the stub will ensure this
- // call instruction is subsequently patched to call the stub.
- } else {
- // Not sure how this can be happen but be defensive
- JVMCI_ERROR("single-use stub should not exist");
- }
- } else {
+ if (!a.far_branches()) {
// If not using far branches, patch this call directly to dest.
set_destination(dest);
+ return;
+ }
+
+ if (!is_NativeCallTrampolineStub_at(instruction_address() + displacement())) {
+ address stub = a.emit_trampoline_stub(instruction_address() - cbuf.insts()->start(), dest);
+ if (stub == nullptr) {
+ JVMCI_ERROR("could not emit trampoline stub - code cache is full");
+ }
+ // The relocation is created while emitting the stub will ensure this
+ // call instruction is subsequently patched to call the stub.
+ } else {
+ // Not sure how this can be happen but be defensive
+ JVMCI_ERROR("single-use stub should not exist");
}
}
#endif
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.
Yes. Or maybe
// Generate a trampoline for a branch to dest. If there's no need for a
// trampoline, simply patch the call directly to dest.
void NativeCall::trampoline_jump(CodeBuffer &cbuf, address dest, JVMCI_TRAPS) {
MacroAssembler a(&cbuf);
if (! a.far_branches()) {
// If not using far branches, patch this call directly to dest.
set_destination(dest);
} else if (!is_NativeCallTrampolineStub_at(instruction_address() + displacement())) {
// If we want far branches and there isn't a trampoline stub, emit one.
address stub = a.emit_trampoline_stub(instruction_address() - cbuf.insts()->start(), dest);
if (stub == nullptr) {
JVMCI_ERROR("could not emit trampoline stub - code cache is full");
}
// The relocation is created while emitting the stub will ensure this
// call instruction is subsequently patched to call the stub.
} else {
// Not sure how this can be happen but be defensive
JVMCI_ERROR("single-use stub should not exist");
}
}
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.
Done.
Thanks for the reviews @adinn @theRealAph and @tkrodriguez . /integrate |
Going to push as commit ad326fc.
Your commit was automatically rebased without conflicts. |
This PR fixes the handling of a full CodeBuffer when emitting stubs as part of JVMCI code installation.
Progress
Issue
Reviewers
Reviewing
Using
git
Checkout this PR locally:
$ git fetch https://git.openjdk.org/jdk pull/11945/head:pull/11945
$ git checkout pull/11945
Update a local copy of the PR:
$ git checkout pull/11945
$ git pull https://git.openjdk.org/jdk pull/11945/head
Using Skara CLI tools
Checkout this PR locally:
$ git pr checkout 11945
View PR using the GUI difftool:
$ git pr show -t 11945
Using diff file
Download this PR as a diff file:
https://git.openjdk.org/jdk/pull/11945.diff