RFR: 8346193: Test runtime/ErrorHandling/TestDwarf.java fails build with clang17 [v2]

Kim Barrett kbarrett at openjdk.org
Tue Dec 31 06:23:43 UTC 2024


On Wed, 18 Dec 2024 07:28:50 GMT, SendaoYan <syan at openjdk.org> wrote:

>> Hi all,
>> Function `frame::oops_do_internal` in src/hotspot/share/runtime/frame.cpp assign value to a nullptr `char *t` and intended to cause jvm crash. But after the assignment the nullptr do not use anymore, so clang17 consider the `char *t` initialization and assignment is "dead code". This PR add `volatile` modifier to `char *t`, to make avoid clang do the "dead code" elimination. Risk is low.
>> 
>> Here is the example explain the "dead code" elimination.
>> 
>> 1. Without volatile modifier, clang will delete the "dead code" and cause no more Segmentation fault error by -O1.
>> 
>> 
>>> cat demo.c 
>> int main() { char *t = 0; *t = 'c'; return 0; }
>>> clang -O0 demo.c && ./a.out ; echo $?
>> Segmentation fault (core dumped)
>> 139
>>> clang -O1 demo.c && ./a.out ; echo $?
>> 0
>> 
>> 
>> 2. With volatile modifier, clang do not delete the "dead code" again and and the expected Segmentation fault occur by -O1.
>> 
>>> cat demo.c 
>> int main() { volatile char *t = 0; *t = 'c'; return 0; }
>>> clang -O0 demo.c && ./a.out ; echo $?
>> Segmentation fault (core dumped)
>> 139
>>> clang -O1 demo.c && ./a.out ; echo $?
>> Segmentation fault (core dumped)
>> 139
>
> SendaoYan has updated the pull request incrementally with one additional commit since the last revision:
> 
>   update comment "Use volatile to prevent compiler from optimising away the store"

Changes requested by kbarrett (Reviewer).

src/hotspot/share/runtime/frame.cpp line 1166:

> 1164:   // simulate GC crash here to dump java thread in error report
> 1165:   if (CrashGCForDumpingJavaThread) {
> 1166:     volatile char *t = nullptr; // Use volatile to prevent compiler from optimising away the store

No, don't do this. We don't need more ways to force a crash. Use
VMError::controlled_crash instead. Note that this will require upgrading that
function to !PRODUCT rather than DEBUG_ONLY. (Don't forget "optimized"
builds.)

OTOH, based on the comment's description of what this is needed for, why not
just `guarantee(!CrashGCForDumpingJavaThread, "")` ?

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

PR Review: https://git.openjdk.org/jdk/pull/22757#pullrequestreview-2526195638
PR Review Comment: https://git.openjdk.org/jdk/pull/22757#discussion_r1899937409


More information about the hotspot-dev mailing list