RFR: 8258382: Fix optimization-unstable code
Kim Barrett
kbarrett at openjdk.java.net
Thu Dec 24 18:02:01 UTC 2020
On Thu, 24 Dec 2020 17:57:33 GMT, Kim Barrett <kbarrett at openjdk.org> wrote:
>> Optimization-unstable code refers to code that is unexpectedly discarded
>> by compiler optimizations due to undefined behavior in the program.
>>
>> We applied a static checker called STACK (prototype from SOSP'13 paper
>> [1]) to OpenJDK source code and found the following eight sites of
>> potential unstable code.
>>
>> Removing undefined behaviors would make the code stable.
>>
>> [1] https://css.csail.mit.edu/stack/
>>
>> --------
>> Note that we tested locally Jtreg tests ( tier1 and jdk::tier3) were passed on Linux x86/aarch64 machines after apply this patch.
>
> src/hotspot/share/gc/parallel/psPromotionLAB.hpp line 122:
>
>> 120: HeapWord* obj = top();
>> 121: // Pointer overflow check is needed here.
>> 122: if (end() >= obj && size <= (size_t) (end() - obj)) {
>
> `top() <= end()` is always true by design and construction, so the
> `end() >= obj` test is unnecessary and undesirable. An assertion could
> be added, but there are lots of places where that relation is assumed
> to hold and that don't bother asserting, so I wouldn't bother here
> either.
Instead of `(size_t)(end() - obj)` use `pointer_delta(end(), obj)`.
-------------
PR: https://git.openjdk.java.net/jdk/pull/1886
More information about the hotspot-dev
mailing list