RFR: 8367149: Add convenient construction for creating ad-hoc VMErrorCallback [v6]

Stefan Karlsson stefank at openjdk.org
Fri Oct 10 08:04:42 UTC 2025


On Fri, 10 Oct 2025 07:54:34 GMT, Axel Boldt-Christmas <aboldtch at openjdk.org> wrote:

>> Add a class OnVMError which uses the VMErrorCallback mechanism which is a convenient 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.
>
> Axel Boldt-Christmas has updated the pull request with a new target base due to a merge or a rebase. The incremental webrev excludes the unrelated changes brought in by the merge/rebase. The pull request contains eight additional commits since the last revision:
> 
>  - Merge tag 'jdk-26+19' into JDK-8367149
>    
>    Added tag jdk-26+19 for changeset b37a1a33
>  - Merge tag 'jdk-26+18' into JDK-8367149
>    
>    Added tag jdk-26+18 for changeset 5251405c
>  - Merge tag 'jdk-26+17' into JDK-8367149
>    
>    Added tag jdk-26+17 for changeset 2aafda19
>  - Replace ergonomic with convenient
>  - Add a comment explaining the deduction rules
>  - Skip multiple inheritance and allow more than lambda like callables.
>  - Update doc example
>  - 8367149: Add ergonomic construction for creating ad-hoc VMErrorCallback

Marked as reviewed by stefank (Reviewer).

-------------

PR Review: https://git.openjdk.org/jdk/pull/27159#pullrequestreview-3321850393


More information about the hotspot-dev mailing list