RFR: 8263718: unused-result warning happens at os_linux.cpp

David Holmes david.holmes at oracle.com
Thu Mar 18 13:25:02 UTC 2021


Hi Yasumasa,

On 18/03/2021 10:29 pm, Yasumasa Suenaga wrote:
> On Thu, 18 Mar 2021 10:03:04 GMT, Thomas Stuefe <stuefe at openjdk.org> wrote:
> 
>>> I can't really comment on which is better -- it's up to you hotspot developers.
>>>
>>> Nevertheless, my personal preference is that `(void)` would have been best since it's a well-established idiom. If gcc is buggy about this, then I think I'd preferred to use this workaround with a comment `// the ! is needed to workaround gcc bug`, to keep with the idiom as much as possible. Pragmas also work, but I personally consider them ugly and a last resort. But once again, don't listen to what I'm saying :-)
>>
>> I agree with Magnus. BTW, we are sure that alloca() call is not simply optimized away, right? Otherwise I would assign the return value to some file static volatile holder.
> 
> First, I think it is the best to remove `alloca()`. According to the comment, it seems to aim to reduce cache pollution. But I wonder why this `alloca()` call resolves it because stack memory will be allocated in each threads - they should be different physical memory. This code has existed since initial load, so I cannot find JBS ticket for this. So I'm not sure we can remove it yet. (comments are welcome!)

The alloca was added as a performance boost for hyperthreaded systems 
back in 2003 for JDK 5:

"A per-thread offset was added to each thread's stack to randomize the 
cachelines of hot stack frames (aka, stack coloring)."

The issue is not open, hence why you could not find it, but it says very 
little beyond what I just quoted.

I'm running some of our benchmarks to see if removing it makes a 
difference ... but chances are I'm not going to be running it on the 
kind of machines for which it was introduced.

> If we decide to remain this code, we need to avoid unused-result warning from GCC. I think we can use pragma because other pragmas (format-nonliteral, format-security, stringop-truncation") are used in HotSpot. In addition, this behavior does not seem to determine to be a bug in GCC (status is UNCONFIRMED). However I will agree to use `(void)!` if it is still preferred based on them.

I'd reluctantly prefer to use the pragma as an official mechanism for 
avoiding the warning.

BTW this is not the first time we have had this issue with gcc making a 
function deprecated and casting to void not fixing it. Unfortunately I 
can't remember enough of the previous case's details to actually look it 
up and see what we resolved to do. :(

David
-----

> -------------
> 
> PR: https://git.openjdk.java.net/jdk/pull/3042
> 


More information about the hotspot-dev mailing list