Skip to content
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

Closed
wants to merge 6 commits into from

Conversation

@albertnetymk
Copy link
Member

@albertnetymk albertnetymk commented Aug 5, 2021

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

  • Change must not contain extraneous whitespace
  • Commit message must refer to an issue
  • Change must be properly reviewed

Issue

  • JDK-8271931: Make AbortVMOnVMOperationTimeout more resilient to OS scheduling

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

@bridgekeeper
Copy link

@bridgekeeper bridgekeeper bot commented Aug 5, 2021

👋 Welcome back ayang! A progress list of the required criteria for merging this PR into master will be added to the body of your pull request. There are additional pull request commands available for use with this pull request.

Loading

@openjdk openjdk bot added the rfr label Aug 5, 2021
@openjdk
Copy link

@openjdk openjdk bot commented Aug 5, 2021

@albertnetymk The following label will be automatically applied to this pull request:

  • hotspot-runtime

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.

Loading

@mlbridge
Copy link

@mlbridge mlbridge bot commented Aug 5, 2021

Loading

Copy link
Contributor

@shipilev shipilev left a comment

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:

Loading

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);
}
Copy link
Contributor

@shipilev shipilev Aug 5, 2021

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.

Loading

Copy link
Contributor

@shipilev shipilev Aug 5, 2021

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.

Loading

Copy link
Member Author

@albertnetymk albertnetymk Aug 5, 2021

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);
  }
}

Loading

Copy link
Contributor

@shipilev shipilev Aug 5, 2021

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)");
}

Loading

Copy link
Member Author

@albertnetymk albertnetymk Aug 5, 2021

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.

Loading

Copy link
Member

@dholmes-ora dholmes-ora Aug 6, 2021

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.

Loading

Copy link
Member

@dholmes-ora dholmes-ora left a comment

Hi Albert,

The changes look good to me.

Thanks,
David

Loading

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);
}
Copy link
Member

@dholmes-ora dholmes-ora Aug 6, 2021

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.

Loading

@openjdk
Copy link

@openjdk openjdk bot commented Aug 6, 2021

@albertnetymk 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:

8271931: Make AbortVMOnVMOperationTimeout more resilient to OS scheduling

Reviewed-by: shade, dholmes

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 master branch:

  • a86ac0d: 8271939: Clean up primitive raw accessors in oopDesc
  • b84a9c7: 8271956: AArch64: C1 build failed after JDK-8270947
  • 38ff85c: 8271461: CompileCommand support for hidden class methods
  • c495ede: 8272099: mark hotspot runtime/Monitor tests which ignore external VM flags
  • e882087: 8271904: mark hotspot runtime/ClassFile tests which ignore external VM flags
  • fa36e33: 8271513: support JavaThreadIteratorWithHandle replacement by new ThreadsList::Iterator
  • cc61520: 8270842: G1: Only young regions need to redirty outside references in remset.
  • f4cf2f7: 8272095: ProblemList java/nio/channels/FileChannel/Transfer2GPlus.java on linux-aarch64
  • 0aca4f7: 8271868: Warn user when using mac-sign option with unsigned app-image.
  • b6a19f1: 8271128: InlineIntrinsics support for 32-bit ARM
  • ... and 43 more: https://git.openjdk.java.net/jdk/compare/efcdcc7fb792c77aef1da69b1fcc652b401115f7...master

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.

➡️ To integrate this PR with the above commit message to the master branch, type /integrate in a new comment.

Loading

@openjdk openjdk bot added the ready label Aug 6, 2021
@albertnetymk
Copy link
Member Author

@albertnetymk albertnetymk commented Aug 6, 2021

we would also not need any other changes here: it would allow to check that task is NULL all the same.

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?

Loading

Copy link
Contributor

@shipilev shipilev left a comment

Yeah, that looks fine. I have two minor suggestions.

Loading

@@ -39,15 +39,15 @@ class VMOperationTimeoutTask : public PeriodicTask {
private:
volatile int _armed;
jlong _arm_time;

const char* _vm_op_name = nullptr;
Copy link
Contributor

@shipilev shipilev Aug 6, 2021

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?

Loading

Copy link
Member Author

@albertnetymk albertnetymk Aug 6, 2021

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.

Loading

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);
}
Copy link
Contributor

@shipilev shipilev Aug 6, 2021

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?

Loading

Copy link
Member Author

@albertnetymk albertnetymk Aug 6, 2021

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.

Loading

Copy link
Contributor

@shipilev shipilev Aug 7, 2021

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.

Loading

Copy link
Member Author

@albertnetymk albertnetymk Aug 7, 2021

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().

Loading

Copy link
Member

@dholmes-ora dholmes-ora left a comment

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

Loading

// 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);
Copy link
Member

@dholmes-ora dholmes-ora Aug 9, 2021

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().

Loading

Copy link
Member Author

@albertnetymk albertnetymk Aug 9, 2021

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.

Loading

Copy link
Member

@dholmes-ora dholmes-ora Aug 9, 2021

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.

Loading

// 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");
Copy link
Member

@dholmes-ora dholmes-ora Aug 9, 2021

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.

Loading

Copy link
Member Author

@albertnetymk albertnetymk Aug 9, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Removed.

Loading

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;
Copy link
Member

@dholmes-ora dholmes-ora Aug 9, 2021

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.

Loading

// 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);
Copy link
Member

@dholmes-ora dholmes-ora Aug 9, 2021

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.

Loading

@albertnetymk
Copy link
Member Author

@albertnetymk albertnetymk commented Aug 9, 2021

Thanks for the review.

/integrate

Loading

@openjdk
Copy link

@openjdk openjdk bot commented Aug 9, 2021

Going to push as commit 2f7a469.
Since your change was applied there have been 53 commits pushed to the master branch:

  • a86ac0d: 8271939: Clean up primitive raw accessors in oopDesc
  • b84a9c7: 8271956: AArch64: C1 build failed after JDK-8270947
  • 38ff85c: 8271461: CompileCommand support for hidden class methods
  • c495ede: 8272099: mark hotspot runtime/Monitor tests which ignore external VM flags
  • e882087: 8271904: mark hotspot runtime/ClassFile tests which ignore external VM flags
  • fa36e33: 8271513: support JavaThreadIteratorWithHandle replacement by new ThreadsList::Iterator
  • cc61520: 8270842: G1: Only young regions need to redirty outside references in remset.
  • f4cf2f7: 8272095: ProblemList java/nio/channels/FileChannel/Transfer2GPlus.java on linux-aarch64
  • 0aca4f7: 8271868: Warn user when using mac-sign option with unsigned app-image.
  • b6a19f1: 8271128: InlineIntrinsics support for 32-bit ARM
  • ... and 43 more: https://git.openjdk.java.net/jdk/compare/efcdcc7fb792c77aef1da69b1fcc652b401115f7...master

Your commit was automatically rebased without conflicts.

Loading

@openjdk openjdk bot closed this Aug 9, 2021
@openjdk openjdk bot added integrated and removed ready rfr labels Aug 9, 2021
@openjdk
Copy link

@openjdk openjdk bot commented Aug 9, 2021

@albertnetymk Pushed as commit 2f7a469.

💡 You may see a message that your pull request was closed with unmerged commits. This can be safely ignored.

Loading

@albertnetymk albertnetymk deleted the vmthread-timeout branch Aug 9, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
3 participants