RFR: 8234328: VectorSet::clear can cause fragmentation

Thomas Stüfe thomas.stuefe at gmail.com
Tue Nov 19 19:31:00 UTC 2019


Hi Claes,

Not that this is wrong, but do we have to live in resource area? I fell
over such problems several times already, e.g. with resource-area-backed
StringStreams. Maybe it would be better to just forbid resizing of
RA-allocated arrays altogether.

Then there is also the problem with passing RA-allocated arrays down the
stack and accidentally resizing them under a different ResourceMark. I am
not sure if this could happen with VectorSet though.

Thanks, Thomas


On Tue, Nov 19, 2019 at 11:16 AM Claes Redestad <claes.redestad at oracle.com>
wrote:

> Hi,
>
> today, VectorSet::clear "reclaims" storage when the size is large.
>
> However, since the backing array is allocated in a resource arena, this
> is dubious since the currently retained memory is only actually freed
> and made reusable if it's currently the last chunk of memory allocated
> in the arena. This means a clear() is likely to just waste the allocated
> memory until we exit the current resource scope
>
> Instead, I propose a strategy where instead of "freeing" we keep track
> of the currently allocated size of the VectorSet separately from the in-
> use size. We can then defer the memset to reset/clear the memory to the
> next time we need to grow, thus avoiding unnecessary reallocations and
> memsets. This limits the memory waste.
>
> Bug:    https://bugs.openjdk.java.net/browse/JDK-8234328
> Webrev: http://cr.openjdk.java.net/~redestad/8234328/open.00/
>
> Testing: tier1-3
>
> Either of reset() or clear() could now be removed, which seems like a
> straightforward follow-up RFE. With some convincing I could roll it into
> this patch.
>
> Thanks!
>
> /Claes
>


More information about the hotspot-compiler-dev mailing list