Skip to content

Conversation

xmas92
Copy link
Member

@xmas92 xmas92 commented Sep 9, 2025

Add a class OnVMError which uses the VMErrorCallback mechanism which is an ergonomic construction for creating ad-hoc VMErrorCallback which automatically calls the provided invocable f if a VM crash occurs within its lifetime. Can be used to instrument a build for more detailed contextual information gathering. Especially useful when hunting down intermittent bugs, or issues only reproducible in environments where access to a debugger is not readily available. Example use:

  {
    // Note the lambda is invoked after an error occurs within this thread,
    // and during on_error's lifetime. If state prior to the crash is required,
    // capture a copy of it first.
    auto important_value = get_the_value();

    OnVMError on_error([&](outputStream* st) {
      // Dump the important bits.
      st->print("Prior value: ");
      important_value.print_on(st);
      st->print("During crash: ")
      get_the_value().print_on(st);
      // Dump whole the whole state.
      this->print_on(st);
    });

    // Sometimes doing a thing will crash the VM.
    do_a_thing();
  }

C++17 class template argument deduction finally makes these sort of constructions ergonomic to use without the need for auto and helper construction methods.


Progress

  • Change must be properly reviewed (1 review required, with at least 1 Reviewer)
  • Change must not contain extraneous whitespace
  • Commit message must refer to an issue

Issue

  • JDK-8367149: Add ergonomic construction for creating ad-hoc VMErrorCallback (Enhancement - P4)

Reviewers

Reviewing

Using git

Checkout this PR locally:
$ git fetch https://git.openjdk.org/jdk.git pull/27159/head:pull/27159
$ git checkout pull/27159

Update a local copy of the PR:
$ git checkout pull/27159
$ git pull https://git.openjdk.org/jdk.git pull/27159/head

Using Skara CLI tools

Checkout this PR locally:
$ git pr checkout 27159

View PR using the GUI difftool:
$ git pr show -t 27159

Using diff file

Download this PR as a diff file:
https://git.openjdk.org/jdk/pull/27159.diff

Using Webrev

Link to Webrev Comment

@bridgekeeper
Copy link

bridgekeeper bot commented Sep 9, 2025

👋 Welcome back aboldtch! 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.

@openjdk
Copy link

openjdk bot commented Sep 9, 2025

@xmas92 This change is no longer ready for integration - check the PR body for details.

@openjdk
Copy link

openjdk bot commented Sep 9, 2025

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

  • hotspot

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.

@openjdk openjdk bot added hotspot [email protected] rfr Pull request is ready for review labels Sep 9, 2025
@mlbridge
Copy link

mlbridge bot commented Sep 9, 2025

Webrevs

Copy link
Member

@albertnetymk albertnetymk left a comment

Choose a reason for hiding this comment

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

Minor comments/suggestions on the doc.

Comment on lines 277 to 278
// Sometimes doing a thing will crash the VM.
do_a_thing();
Copy link
Member

Choose a reason for hiding this comment

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

// When VM crashes, the above lambda will be invoked and print relevant info.
might_cause_vm_crash();

@@ -251,4 +251,41 @@ class VMErrorCallbackMark : public StackObj {
~VMErrorCallbackMark();
};

// Ergonomic construction for creating ad-hoc VMErrorCallback which automatically
Copy link
Member

Choose a reason for hiding this comment

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

Does Ergonomic construction have specific meanings in cpp/this context? If not, I wonder if lightweight is clearer, as it is less technical.

@openjdk openjdk bot added the ready Pull request is ready to be integrated label Sep 10, 2025
@openjdk openjdk bot removed the ready Pull request is ready to be integrated label Sep 10, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
hotspot [email protected] rfr Pull request is ready for review
Development

Successfully merging this pull request may close these issues.

2 participants