RFR: 8348880: Replace ConcurrentMap with AtomicReferenceArray for ZoneOffset.MINUTES_15_CACHE [v3]
Chen Liang
liach at openjdk.org
Tue Jan 28 16:52:48 UTC 2025
On Tue, 28 Jan 2025 16:44:17 GMT, Shaojin Wen <swen at openjdk.org> wrote:
>> ZoneOffset.MINUTES_15_CACHE uses AtomicReferenceArray to replace ConcurrentMap to avoid object allocation caused by boxing from int to Integer during access.
>
> Shaojin Wen has updated the pull request incrementally with two additional commits since the last revision:
>
> - simplify
> - MINUTES_15_CACHE -> QUARTER_CACHE
src/java.base/share/classes/java/time/ZoneOffset.java line 138:
> 136: implements TemporalAccessor, TemporalAdjuster, Comparable<ZoneOffset>, Serializable {
> 137:
> 138: /** Cache of time-zone offset by offset in seconds. */
Suggestion:
/** Cache of time-zone offset by offset in quarters. */
src/java.base/share/classes/java/time/ZoneOffset.java line 431:
> 429: int quarters = totalSeconds / SECONDS_PER_QUARTER;
> 430: if (totalSeconds - quarters * SECONDS_PER_QUARTER == 0) {
> 431: ZoneOffset result = QUARTER_CACHE.getOpaque(quarters & 0xff);
For the ease of future maintenance, I recommend replacing `quarters & 0xFF` with a new variable `key`:
// quarters range from -72 to 72.
// & 0xFF maps them to 0-72 and 184-255.
int key = quarters & 0xFF;
-------------
PR Review Comment: https://git.openjdk.org/jdk/pull/23337#discussion_r1932514778
PR Review Comment: https://git.openjdk.org/jdk/pull/23337#discussion_r1932526383
More information about the core-libs-dev
mailing list