RFR: 8327093: Add slice function to BitMap API

Matias Saavedra Silva matsaave at openjdk.org
Tue Mar 5 17:33:45 UTC 2024


On Tue, 5 Mar 2024 08:45:03 GMT, Axel Boldt-Christmas <aboldtch at openjdk.org> wrote:

>> The BitMap does not currently have a "slice" method which can return a subset of the bitmap defined by a start and end bit. This utility can be used to analyze portions of a bitmap or to overwrite the existing map with a shorter, modified map. 
>> 
>> This implementation has two core methods: 
>> `copy_of_range` allocates and returns a new word array as used internally by BitMap
>> `truncate` overwrites the internal array with the one generated by `copy_of_range` so none of the internal workings are exposed to callers outside of BitMap.
>> 
>> This change is verified with an included test.
>
> src/hotspot/share/utilities/bitMap.cpp line 126:
> 
>> 124:     // First iteration is a special case:
>> 125:     // There may be left over bits in the last word that we want to keep while discarding the rest
>> 126:     if (i == end_word - 1 && cutoff > 0) {
> 
> Is it important that the msb are cleared (beyond the `size()` bit). Could always just do `new_map[i-start_word] = old_map[i] >> shift;`

I suppose it isn't necessary to clear the leftover MSB so that detail can be excluded. The junk bits will still be present however and that may introduce some confusion when debugging.

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

PR Review Comment: https://git.openjdk.org/jdk/pull/18092#discussion_r1513224925


More information about the hotspot-dev mailing list