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
8271931: Make AbortVMOnVMOperationTimeout more resilient to OS scheduling #5016
Conversation
|
@albertnetymk The following label will be automatically applied to this pull request:
When this pull request is ready to be reviewed, an "RFR" email will be sent to the corresponding mailing list. If you would like to change these labels, use the /label pull request command. |
Webrevs
|
TBH, the decision to only check this at periodic task was to avoid excess overhead. But I don't think this concern is relevant for this patch, as it would only be entered when timeout is enabled. I do have suggestions to simplify the patch:
jlong delay = nanos_to_millis(os::javaTimeNanos() - vm_op_start_ns); | ||
if (delay > AbortVMOnVMOperationTimeoutDelay) { | ||
fatal("%s VM operation took too long: completed in " JLONG_FORMAT " ms (timeout: " INTX_FORMAT " ms)", | ||
_cur_vm_operation->name(), delay, AbortVMOnVMOperationTimeoutDelay); | ||
} |
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 duplicates VMOperationTimeoutTask::task
body. So I think this is better to be moved to a separate method, e.g. VMOperationTimeoutTask::check_and_fail
, which we can then call from both ::task
and ::disarm
.
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.
After this, we would also not need any other changes here: it would allow to check that task is NULL
all the same.
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.
Note the fatal msg is different: on VM thread we know the VM-op has completed, but on TimeoutTask the VM-op status is unknown.
How about sth like this?
bool check_timeout(jlong& delay) {
delay = nanos_to_millis(os::javaTimeNanos() - _arm_time);
return delay > AbortVMOnVMOperationTimeoutDelay
}
void disarm() {
Atomic::release_store_fence(&_armed, 0);
jlong delay;
if (check_timeout(delay)) {
fatal("%s VM operation took too long: completed in " JLONG_FORMAT " ms (timeout: " INTX_FORMAT " ms)",
_cur_vm_operation->name(), delay, AbortVMOnVMOperationTimeoutDelay);
}
}
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.
Huh, I missed this difference. Yeah, that goes in the right direction. Can we just pass the const char*
with the format string to checking method? So we don't do the out-parameter, and the code ends up being:
bool maybe_fail_with(const char* fail_msg) {
jlong delay = nanos_to_millis(os::javaTimeNanos() - _arm_time);
if (delay > AbortVMOnVMOperationTimeoutDelay) {
fatal(fail_msg, delay, AbortVMOnVMOperationTimeoutDelay);
}
}
void disarm() {
Atomic::release_store_fence(&_armed, 0);
maybe_fail_with("VM operation took too long: completed in " JLONG_FORMAT " ms (timeout: " INTX_FORMAT " ms)");
}
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 actually think having the format string and the variables in the same scope/statement is better, because one can match the format specifier with the corresponding variable easily.
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 have no concerns about "duplicate" related checks here - it just isn't worth overthinking/over-engineering this IMO.
jlong delay = nanos_to_millis(os::javaTimeNanos() - vm_op_start_ns); | ||
if (delay > AbortVMOnVMOperationTimeoutDelay) { | ||
fatal("%s VM operation took too long: completed in " JLONG_FORMAT " ms (timeout: " INTX_FORMAT " ms)", | ||
_cur_vm_operation->name(), delay, AbortVMOnVMOperationTimeoutDelay); | ||
} |
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 have no concerns about "duplicate" related checks here - it just isn't worth overthinking/over-engineering this IMO.
@albertnetymk This change now passes all automated pre-integration checks. 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 53 new commits pushed to the
As there are no conflicts, your changes will automatically be rebased on top of these commits when integrating. If you prefer to avoid this automatic rebasing, please check the documentation for the /integrate command for further details.
|
Hi Aleksey, I have revised the patch to better encapsulate the timeout-check logic; still duplicated, but at least they are very close now (in the same class). Are you OK with the latest version? |
@@ -39,15 +39,15 @@ class VMOperationTimeoutTask : public PeriodicTask { | |||
private: | |||
volatile int _armed; | |||
jlong _arm_time; | |||
|
|||
const char* _vm_op_name = 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.
Style question: are we doing these inits inline, instead of constructor?
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.
My mistake; I will fix it.
if (vm_op_duration > AbortVMOnVMOperationTimeoutDelay) { | ||
fatal("%s VM operation took too long: completed in " JLONG_FORMAT " ms (timeout: " INTX_FORMAT " ms)", | ||
_vm_op_name, vm_op_duration, AbortVMOnVMOperationTimeoutDelay); | ||
} |
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.
Should we null _vm_op_name
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.
It's not read by anyone from here on, so setting it to null is not needed, and a waste of the VM thread time.
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.
My concern would be holding the pointer to something that is already unallocated long after VM op completes. I guess it is a lower risk for const char*
, which is probably a reference to globally available string, but anyway. The overhead argument does not seem very relevant here, as we do other stuff in this handler when it is enabled. It is not a waste in default VM mode.
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 see; cleared _vm_op_name
at the end of disarm()
.
Hi Albert,
I preferred earlier versions that didn't shove all this extra logic into the timeout task, but it isn't worth arguing over.
Thanks,
David
// The two stores to `_armed` are counted in VM-op, but they should be | ||
// insignificant compared to the actual VM-op duration. | ||
jlong vm_op_duration = nanos_to_millis(os::javaTimeNanos() - _arm_time); |
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.
You could move this ahead of the store. And then you only need a small comment in arm().
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.
You previously commented on slack: "Also disarm before getting the end time just to shorten the race with the watcher thread". I agree with that; for non-stuck VM-ops, checking timeout on VM thread is more reliable.
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.
Yep sorry forgot about that aspect.
// Repeat the timeout-check logic on the VM thread, because | ||
// VMOperationTimeoutTask might miss the arm-disarm window depending on | ||
// the scheduling. | ||
assert(Thread::current()->is_VM_thread(), "Check timeout on VM thread"); |
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.
Seems unnecessary to assert this.
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.
Removed.
fatal("%s VM operation took too long: completed in " JLONG_FORMAT " ms (timeout: " INTX_FORMAT " ms)", | ||
_vm_op_name, vm_op_duration, AbortVMOnVMOperationTimeoutDelay); | ||
} | ||
_vm_op_name = 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.
Yes clearing this is good hygiene - no dangling pointers.
// The two stores to `_armed` are counted in VM-op, but they should be | ||
// insignificant compared to the actual VM-op duration. | ||
jlong vm_op_duration = nanos_to_millis(os::javaTimeNanos() - _arm_time); |
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.
Yep sorry forgot about that aspect.
Thanks for the review. /integrate |
Going to push as commit 2f7a469.
Your commit was automatically rebased without conflicts. |
@albertnetymk Pushed as commit 2f7a469. |
Perform VM-op timeout also on the VM thread. If a VM-op is stuck, the existing watcher-thread based machinery will kick in and detect it.
Test: tier1
Progress
Issue
Reviewers
Reviewing
Using
git
Checkout this PR locally:
$ git fetch https://git.openjdk.java.net/jdk pull/5016/head:pull/5016
$ git checkout pull/5016
Update a local copy of the PR:
$ git checkout pull/5016
$ git pull https://git.openjdk.java.net/jdk pull/5016/head
Using Skara CLI tools
Checkout this PR locally:
$ git pr checkout 5016
View PR using the GUI difftool:
$ git pr show -t 5016
Using diff file
Download this PR as a diff file:
https://git.openjdk.java.net/jdk/pull/5016.diff