RFR: 8258382: Fix optimization-unstable code
Kim Barrett
kbarrett at openjdk.java.net
Thu Dec 24 18:02:00 UTC 2020
On Thu, 24 Dec 2020 00:24:32 GMT, Hao Sun <github.com+16932759+shqking 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.
Changes requested by kbarrett (Reviewer).
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.
src/hotspot/share/gc/parallel/psPromotionLAB.hpp line 121:
> 119: assert(_start_array != NULL, "Sanity");
> 120: HeapWord* obj = top();
> 121: // Pointer overflow check is needed here.
The comment mentions pointer overflow checking, but that's not what's
being checked for anymore. It's just checking whether there is space
for the desired object. It's just that the check is now being done
safely and correctly, where it wasn't before, but that's not interesting.
I don't think any comment is needed anymore; the updated code (with
my other suggestions) is obvious.
src/hotspot/share/gc/parallel/psPromotionLAB.inline.hpp line 37:
> 35: HeapWord* obj = top();
> 36: // Pointer overflow check is needed here.
> 37: if (end() >= obj && size <= (size_t)(end() - obj)) {
Same suggestions here as for the corresponding changes to the .hpp file.
-------------
PR: https://git.openjdk.java.net/jdk/pull/1886
More information about the hotspot-dev
mailing list