Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-8367149

Add ergonomic construction for creating ad-hoc VMErrorCallback

XMLWordPrintable

    • Icon: Enhancement Enhancement
    • Resolution: Unresolved
    • Icon: P4 P4
    • 26
    • None
    • hotspot

      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.

            aboldtch Axel Boldt-Christmas
            aboldtch Axel Boldt-Christmas
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated: