diff --git a/src/java.base/share/classes/java/time/format/DateTimeTextProvider.java b/src/java.base/share/classes/java/time/format/DateTimeTextProvider.java index 70ad69b03b89c..5be33551c707a 100644 --- a/src/java.base/share/classes/java/time/format/DateTimeTextProvider.java +++ b/src/java.base/share/classes/java/time/format/DateTimeTextProvider.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2012, 2024, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2012, 2025, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -312,8 +312,10 @@ private Object findStore(TemporalField field, Locale locale) { Object store = CACHE.get(key); if (store == null) { store = createStore(field, locale); - CACHE.putIfAbsent(key, store); - store = CACHE.get(key); + var existing = CACHE.putIfAbsent(key, store); + if (existing != null) { + store = existing; + } } return store; } diff --git a/src/java.base/share/classes/java/time/format/DecimalStyle.java b/src/java.base/share/classes/java/time/format/DecimalStyle.java index 98dd52ba021be..a9ad8a4e273e6 100644 --- a/src/java.base/share/classes/java/time/format/DecimalStyle.java +++ b/src/java.base/share/classes/java/time/format/DecimalStyle.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2012, 2024, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2012, 2025, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -163,8 +163,10 @@ public static DecimalStyle of(Locale locale) { DecimalStyle info = CACHE.get(locale); if (info == null) { info = create(locale); - CACHE.putIfAbsent(locale, info); - info = CACHE.get(locale); + var existing = CACHE.putIfAbsent(locale, info); + if (existing != null) { + info = existing; + } } return info; } diff --git a/test/micro/org/openjdk/bench/java/time/ZoneOffsetBench.java b/test/micro/org/openjdk/bench/java/time/ZoneOffsetBench.java deleted file mode 100644 index 247584093a16d..0000000000000 --- a/test/micro/org/openjdk/bench/java/time/ZoneOffsetBench.java +++ /dev/null @@ -1,53 +0,0 @@ -/* - * Copyright (c) 2024, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ -package org.openjdk.bench.java.time; - -import java.time.ZoneOffset; -import java.util.concurrent.TimeUnit; - -import org.openjdk.jmh.annotations.Benchmark; -import org.openjdk.jmh.annotations.BenchmarkMode; -import org.openjdk.jmh.annotations.Fork; -import org.openjdk.jmh.annotations.Measurement; -import org.openjdk.jmh.annotations.Mode; -import org.openjdk.jmh.annotations.OutputTimeUnit; -import org.openjdk.jmh.annotations.Scope; -import org.openjdk.jmh.annotations.State; -import org.openjdk.jmh.annotations.Warmup; - -@BenchmarkMode(Mode.AverageTime) -@State(Scope.Benchmark) -@Fork(1) -@OutputTimeUnit(TimeUnit.NANOSECONDS) -@Warmup(iterations = 2) -@Measurement(iterations = 5) -public class ZoneOffsetBench { - - @Benchmark - public void ofTotalSeconds() { - for (int i = 0; i < 1_000; i++) { - ZoneOffset.ofTotalSeconds(0); - } - } -} -