RFR: 8367149: Add ergonomic construction for creating ad-hoc VMErrorCallback
Albert Mingkun Yang
ayang at openjdk.org
Wed Sep 10 09:07:22 UTC 2025
On Tue, 9 Sep 2025 06:26:32 GMT, Axel Boldt-Christmas <aboldtch at openjdk.org> wrote:
> 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:
> ```C++
> {
> // 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.
Minor comments/suggestions on the doc.
src/hotspot/share/utilities/vmError.hpp line 254:
> 252: };
> 253:
> 254: // Ergonomic construction for creating ad-hoc VMErrorCallback which automatically
Does `Ergonomic construction` have specific meanings in cpp/this context? If not, I wonder if `lightweight` is clearer, as it is less technical.
src/hotspot/share/utilities/vmError.hpp line 278:
> 276:
> 277: // Sometimes doing a thing will crash the VM.
> 278: do_a_thing();
// When VM crashes, the above lambda will be invoked and print relevant info.
might_cause_vm_crash();
-------------
Marked as reviewed by ayang (Reviewer).
PR Review: https://git.openjdk.org/jdk/pull/27159#pullrequestreview-3205163906
PR Review Comment: https://git.openjdk.org/jdk/pull/27159#discussion_r2336080660
PR Review Comment: https://git.openjdk.org/jdk/pull/27159#discussion_r2336064339
More information about the hotspot-dev
mailing list