RFR: 8304939: os::win32::exit_process_or_thread should be marked noreturn

Julian Waters jwaters at openjdk.org
Mon Oct 23 07:00:48 UTC 2023


On Windows we have a non-trivial function (exit_process_or_thread) that provides the implementation of various functions like os::die, os::abort, &etc. Those os functions are marked as noreturn, so this implementation helper should also be noreturn.

The current change does several things around exit_process_or_thread, which is moved out of the os::win32 class since it does not need access to anything in that class other than the Ept enum, which is also moved to os_windows.cpp as well. The signature is changed to void, since exit_process_or_thread's current return value is simply the exit code parameter that it is passed, and to qualify as noreturn it should not return its current value of int. The only usage of this return value is in thread_native_entry, and this usage can easily be replaced by returning the res local that exit_process_or_thread is passed. For this os::infinite_sleep takes the place of the return statement in exit_process_or_thread, to make sure it qualifies as noreturn.

Although not mentioned in the title, raise_fail_fast has also been fixed. RaiseFailFastException is not itself noreturn, so os::infinite_sleep has been added there as well, to make raise_fail_fast qualify as a noreturn method

All the changes mentioned above fixes any Undefined Behaviour on Windows with regards to noreturn, by making all code marked noreturn (os::die() os::exit() etc) never return. This is not a problem on other platforms since their implementations of os::abort or os::die etc already call noreturn methods.

This fix also fixes compilation on gcc windows, which warns about noreturn methods returning prior to this changeset

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

Commit messages:
 - 8304939

Changes: https://git.openjdk.org/jdk/pull/16303/files
 Webrev: https://webrevs.openjdk.org/?repo=jdk&pr=16303&range=00
  Issue: https://bugs.openjdk.org/browse/JDK-8304939
  Stats: 39 lines in 5 files changed: 11 ins; 8 del; 20 mod
  Patch: https://git.openjdk.org/jdk/pull/16303.diff
  Fetch: git fetch https://git.openjdk.org/jdk.git pull/16303/head:pull/16303

PR: https://git.openjdk.org/jdk/pull/16303


More information about the hotspot-dev mailing list