From 1461683d72218ea12d00bf3b5a56b4a857af698d Mon Sep 17 00:00:00 2001 From: XenoAmess Date: Thu, 24 Mar 2022 02:32:19 +0800 Subject: [PATCH 01/26] 8186958: Need method to create pre-sized HashMap --- .../share/classes/java/util/Collections.java | 57 +++++++++ .../CalculateHashMapCapacityTestJMH.java | 112 ++++++++++++++++++ 2 files changed, 169 insertions(+) create mode 100644 test/jdk/java/util/Collections/CalculateHashMapCapacityTestJMH.java diff --git a/src/java.base/share/classes/java/util/Collections.java b/src/java.base/share/classes/java/util/Collections.java index b68de65f15f62..1bb86da18669d 100644 --- a/src/java.base/share/classes/java/util/Collections.java +++ b/src/java.base/share/classes/java/util/Collections.java @@ -5798,4 +5798,61 @@ public boolean removeIf(Predicate filter) { @Override public Stream parallelStream() {return q.parallelStream();} } + + /** + * Calculate initial capacity for HashMap based classes, from expected size. + * + * @param expectedSize expected size + * @return initial capacity for HashMap based classes. + * @since 19 + */ + private static int calculateHashMapCapacity(int expectedSize) { + if (expectedSize >= 1610612736) { + return Integer.MAX_VALUE; + } + return (expectedSize + (expectedSize + 2) / 3); + } + + /** + * Create new HashMap from expected size. + * + * @param expectedSize expected size + * @param the type of keys maintained by this map + * @param the type of mapped values + * @return initial capacity for HashMap based classes. + * @throws IllegalArgumentException if the initial capacity is negative. + * @since 19 + */ + public static HashMap newHashMap(int expectedSize) { + return new HashMap<>(calculateHashMapCapacity(expectedSize)); + } + + /** + * Create new LinkedHashMap from expected size. + * + * @param expectedSize expected size + * @param the type of keys maintained by this map + * @param the type of mapped values + * @return initial capacity for HashMap based classes. + * @throws IllegalArgumentException if the initial capacity is negative. + * @since 19 + */ + public static LinkedHashMap newLinkedHashMap(int expectedSize) { + return new LinkedHashMap<>(calculateHashMapCapacity(expectedSize)); + } + + /** + * Create new WeakHashMap from expected size. + * + * @param expectedSize expected size + * @param the type of keys maintained by this map + * @param the type of mapped values + * @return initial capacity for HashMap based classes. + * @throws IllegalArgumentException if the initial capacity is negative. + * @since 19 + */ + public static WeakHashMap newWeakHashMap(int expectedSize) { + return new WeakHashMap<>(calculateHashMapCapacity(expectedSize)); + } + } diff --git a/test/jdk/java/util/Collections/CalculateHashMapCapacityTestJMH.java b/test/jdk/java/util/Collections/CalculateHashMapCapacityTestJMH.java new file mode 100644 index 0000000000000..e6da4faaf7db3 --- /dev/null +++ b/test/jdk/java/util/Collections/CalculateHashMapCapacityTestJMH.java @@ -0,0 +1,112 @@ +/* + * Copyright (c) 1997, 2021, 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. Oracle designates this + * particular file as subject to the "Classpath" exception as provided + * by Oracle in the LICENSE file that accompanied this code. + * + * 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. + */ + +import org.openjdk.jmh.annotations.Benchmark; +import org.openjdk.jmh.annotations.BenchmarkMode; +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; + +import java.util.concurrent.TimeUnit; + +@State(Scope.Thread) +@BenchmarkMode(Mode.Throughput) +@OutputTimeUnit(TimeUnit.SECONDS) +public class CalculateHashMapCapacityTestJMH { + + private void consume(int tmp) { + // do nothing; + } + + /** + * Calculate initial capacity for HashMap based classes, from expected size. + * + * @param expectedSize expected size + * @return initial capacity for HashMap based classes. + * @since 19 + */ + private static int calculateHashMapCapacity1(int expectedSize) { + return (int) Math.ceil(expectedSize / 0.75); + } + + /** + * Calculate initial capacity for HashMap based classes, from expected size. + * + * @param expectedSize expected size + * @return initial capacity for HashMap based classes. + * @since 19 + */ + private static int calculateHashMapCapacity2(int expectedSize) { + if (expectedSize >= 1610612736) { + return Integer.MAX_VALUE; + } + return (expectedSize + (expectedSize + 2) / 3); + } + + /** + * Calculate initial capacity for HashMap based classes, from expected size. + * + * @param expectedSize expected size + * @return initial capacity for HashMap based classes. + * @since 19 + */ + private static int calculateHashMapCapacity3(int expectedSize) { + if(expectedSize >= 805306368){ + return (1<<30); + } + return (expectedSize + (expectedSize + 2) / 3); + } + + @Warmup(iterations = 20) + @Measurement(iterations = 10) + @Benchmark + public void testCalculateHashMapCapacity1() { + for (int i = 0; i < Integer.MAX_VALUE; i++) { + consume(calculateHashMapCapacity1(i)); + } + } + + @Warmup(iterations = 20) + @Measurement(iterations = 10) + @Benchmark + public void testCalculateHashMapCapacity2() { + for (int i = 0; i < Integer.MAX_VALUE; i++) { + consume(calculateHashMapCapacity2(i)); + } + } + + @Warmup(iterations = 20) + @Measurement(iterations = 10) + @Benchmark + public void testCalculateHashMapCapacity3() { + for (int i = 0; i < Integer.MAX_VALUE; i++) { + consume(calculateHashMapCapacity3(i)); + } + } + +} From 68787ac453c8274f53242147590b710a2a38a373 Mon Sep 17 00:00:00 2001 From: XenoAmess Date: Thu, 24 Mar 2022 19:41:03 +0800 Subject: [PATCH 02/26] fix javadoc's @return --- .../share/classes/java/util/Collections.java | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/src/java.base/share/classes/java/util/Collections.java b/src/java.base/share/classes/java/util/Collections.java index 1bb86da18669d..d6108b37e0ba1 100644 --- a/src/java.base/share/classes/java/util/Collections.java +++ b/src/java.base/share/classes/java/util/Collections.java @@ -30,6 +30,7 @@ import java.io.ObjectOutputStream; import java.io.Serializable; import java.lang.reflect.Array; +import java.util.concurrent.ConcurrentHashMap; import java.util.function.BiConsumer; import java.util.function.BiFunction; import java.util.function.Consumer; @@ -5814,12 +5815,14 @@ private static int calculateHashMapCapacity(int expectedSize) { } /** - * Create new HashMap from expected size. + * Creates a new, empty HashMap with an initial table size + * accommodating the specified number of elements without the need + * to dynamically resize. * * @param expectedSize expected size * @param the type of keys maintained by this map * @param the type of mapped values - * @return initial capacity for HashMap based classes. + * @return the HashMap created. * @throws IllegalArgumentException if the initial capacity is negative. * @since 19 */ @@ -5828,12 +5831,14 @@ public static HashMap newHashMap(int expectedSize) { } /** - * Create new LinkedHashMap from expected size. + * Creates a new, empty LinkedHashMap with an initial table size + * accommodating the specified number of elements without the need + * to dynamically resize. * * @param expectedSize expected size * @param the type of keys maintained by this map * @param the type of mapped values - * @return initial capacity for HashMap based classes. + * @return the LinkedHashMap created. * @throws IllegalArgumentException if the initial capacity is negative. * @since 19 */ @@ -5842,12 +5847,14 @@ public static LinkedHashMap newLinkedHashMap(int expectedSize) { } /** - * Create new WeakHashMap from expected size. + * Creates a new, empty WeakHashMap with an initial table size + * accommodating the specified number of elements without the need + * to dynamically resize. * * @param expectedSize expected size * @param the type of keys maintained by this map * @param the type of mapped values - * @return initial capacity for HashMap based classes. + * @return the WeakHashMap created. * @throws IllegalArgumentException if the initial capacity is negative. * @since 19 */ From 2b294b31ca5feb907a98bbdabd8b2d5348d0ac03 Mon Sep 17 00:00:00 2001 From: XenoAmess Date: Thu, 24 Mar 2022 19:48:51 +0800 Subject: [PATCH 03/26] move the static functions to map classes themselves. --- .../share/classes/java/util/Collections.java | 64 ------------------- .../share/classes/java/util/HashMap.java | 30 +++++++++ .../classes/java/util/LinkedHashMap.java | 15 +++++ .../share/classes/java/util/WeakHashMap.java | 16 +++++ 4 files changed, 61 insertions(+), 64 deletions(-) diff --git a/src/java.base/share/classes/java/util/Collections.java b/src/java.base/share/classes/java/util/Collections.java index d6108b37e0ba1..b68de65f15f62 100644 --- a/src/java.base/share/classes/java/util/Collections.java +++ b/src/java.base/share/classes/java/util/Collections.java @@ -30,7 +30,6 @@ import java.io.ObjectOutputStream; import java.io.Serializable; import java.lang.reflect.Array; -import java.util.concurrent.ConcurrentHashMap; import java.util.function.BiConsumer; import java.util.function.BiFunction; import java.util.function.Consumer; @@ -5799,67 +5798,4 @@ public boolean removeIf(Predicate filter) { @Override public Stream parallelStream() {return q.parallelStream();} } - - /** - * Calculate initial capacity for HashMap based classes, from expected size. - * - * @param expectedSize expected size - * @return initial capacity for HashMap based classes. - * @since 19 - */ - private static int calculateHashMapCapacity(int expectedSize) { - if (expectedSize >= 1610612736) { - return Integer.MAX_VALUE; - } - return (expectedSize + (expectedSize + 2) / 3); - } - - /** - * Creates a new, empty HashMap with an initial table size - * accommodating the specified number of elements without the need - * to dynamically resize. - * - * @param expectedSize expected size - * @param the type of keys maintained by this map - * @param the type of mapped values - * @return the HashMap created. - * @throws IllegalArgumentException if the initial capacity is negative. - * @since 19 - */ - public static HashMap newHashMap(int expectedSize) { - return new HashMap<>(calculateHashMapCapacity(expectedSize)); - } - - /** - * Creates a new, empty LinkedHashMap with an initial table size - * accommodating the specified number of elements without the need - * to dynamically resize. - * - * @param expectedSize expected size - * @param the type of keys maintained by this map - * @param the type of mapped values - * @return the LinkedHashMap created. - * @throws IllegalArgumentException if the initial capacity is negative. - * @since 19 - */ - public static LinkedHashMap newLinkedHashMap(int expectedSize) { - return new LinkedHashMap<>(calculateHashMapCapacity(expectedSize)); - } - - /** - * Creates a new, empty WeakHashMap with an initial table size - * accommodating the specified number of elements without the need - * to dynamically resize. - * - * @param expectedSize expected size - * @param the type of keys maintained by this map - * @param the type of mapped values - * @return the WeakHashMap created. - * @throws IllegalArgumentException if the initial capacity is negative. - * @since 19 - */ - public static WeakHashMap newWeakHashMap(int expectedSize) { - return new WeakHashMap<>(calculateHashMapCapacity(expectedSize)); - } - } diff --git a/src/java.base/share/classes/java/util/HashMap.java b/src/java.base/share/classes/java/util/HashMap.java index 997273aa104f1..d9f2b436757d4 100644 --- a/src/java.base/share/classes/java/util/HashMap.java +++ b/src/java.base/share/classes/java/util/HashMap.java @@ -2545,4 +2545,34 @@ static boolean checkInvariants(TreeNode t) { } } + /** + * Calculate initial capacity for HashMap based classes, from expected size. + * + * @param expectedSize expected size + * @return initial capacity for HashMap based classes. + * @since 19 + */ + static int calculateHashMapCapacity(int expectedSize) { + if (expectedSize >= 1610612736) { + return Integer.MAX_VALUE; + } + return (expectedSize + (expectedSize + 2) / 3); + } + + /** + * Creates a new, empty HashMap with an initial table size + * accommodating the specified number of elements without the need + * to dynamically resize. + * + * @param expectedSize expected size + * @param the type of keys maintained by this map + * @param the type of mapped values + * @return the HashMap created. + * @throws IllegalArgumentException if the initial capacity is negative. + * @since 19 + */ + public static HashMap newHashMap(int expectedSize) { + return new HashMap<>(calculateHashMapCapacity(expectedSize)); + } + } diff --git a/src/java.base/share/classes/java/util/LinkedHashMap.java b/src/java.base/share/classes/java/util/LinkedHashMap.java index 92c5ff847ed8a..cd2560faeaa2d 100644 --- a/src/java.base/share/classes/java/util/LinkedHashMap.java +++ b/src/java.base/share/classes/java/util/LinkedHashMap.java @@ -788,5 +788,20 @@ final class LinkedEntryIterator extends LinkedHashIterator public final Map.Entry next() { return nextNode(); } } + /** + * Creates a new, empty LinkedHashMap with an initial table size + * accommodating the specified number of elements without the need + * to dynamically resize. + * + * @param expectedSize expected size + * @param the type of keys maintained by this map + * @param the type of mapped values + * @return the LinkedHashMap created. + * @throws IllegalArgumentException if the initial capacity is negative. + * @since 19 + */ + public static LinkedHashMap newLinkedHashMap(int expectedSize) { + return new LinkedHashMap<>(HashMap.calculateHashMapCapacity(expectedSize)); + } } diff --git a/src/java.base/share/classes/java/util/WeakHashMap.java b/src/java.base/share/classes/java/util/WeakHashMap.java index bc31985b66ee2..43661835d6b37 100644 --- a/src/java.base/share/classes/java/util/WeakHashMap.java +++ b/src/java.base/share/classes/java/util/WeakHashMap.java @@ -1335,4 +1335,20 @@ public int characteristics() { } } + /** + * Creates a new, empty WeakHashMap with an initial table size + * accommodating the specified number of elements without the need + * to dynamically resize. + * + * @param expectedSize expected size + * @param the type of keys maintained by this map + * @param the type of mapped values + * @return the WeakHashMap created. + * @throws IllegalArgumentException if the initial capacity is negative. + * @since 19 + */ + public static WeakHashMap newWeakHashMap(int expectedSize) { + return new WeakHashMap<>(HashMap.calculateHashMapCapacity(expectedSize)); + } + } From 5457e6ccca6e6f1564a3e4dcbe7d51fe1824e10e Mon Sep 17 00:00:00 2001 From: XenoAmess Date: Thu, 24 Mar 2022 19:53:32 +0800 Subject: [PATCH 04/26] use jmh Blackhole --- .../CalculateHashMapCapacityTestJMH.java | 21 ++++++++----------- 1 file changed, 9 insertions(+), 12 deletions(-) diff --git a/test/jdk/java/util/Collections/CalculateHashMapCapacityTestJMH.java b/test/jdk/java/util/Collections/CalculateHashMapCapacityTestJMH.java index e6da4faaf7db3..4bba3ea211736 100644 --- a/test/jdk/java/util/Collections/CalculateHashMapCapacityTestJMH.java +++ b/test/jdk/java/util/Collections/CalculateHashMapCapacityTestJMH.java @@ -31,6 +31,7 @@ import org.openjdk.jmh.annotations.Scope; import org.openjdk.jmh.annotations.State; import org.openjdk.jmh.annotations.Warmup; +import org.openjdk.jmh.infra.Blackhole; import java.util.concurrent.TimeUnit; @@ -39,10 +40,6 @@ @OutputTimeUnit(TimeUnit.SECONDS) public class CalculateHashMapCapacityTestJMH { - private void consume(int tmp) { - // do nothing; - } - /** * Calculate initial capacity for HashMap based classes, from expected size. * @@ -76,8 +73,8 @@ private static int calculateHashMapCapacity2(int expectedSize) { * @since 19 */ private static int calculateHashMapCapacity3(int expectedSize) { - if(expectedSize >= 805306368){ - return (1<<30); + if (expectedSize >= 805306368) { + return (1 << 30); } return (expectedSize + (expectedSize + 2) / 3); } @@ -85,27 +82,27 @@ private static int calculateHashMapCapacity3(int expectedSize) { @Warmup(iterations = 20) @Measurement(iterations = 10) @Benchmark - public void testCalculateHashMapCapacity1() { + public void testCalculateHashMapCapacity1(Blackhole blackhole) { for (int i = 0; i < Integer.MAX_VALUE; i++) { - consume(calculateHashMapCapacity1(i)); + blackhole.consume(calculateHashMapCapacity1(i)); } } @Warmup(iterations = 20) @Measurement(iterations = 10) @Benchmark - public void testCalculateHashMapCapacity2() { + public void testCalculateHashMapCapacity2(Blackhole blackhole) { for (int i = 0; i < Integer.MAX_VALUE; i++) { - consume(calculateHashMapCapacity2(i)); + blackhole.consume(calculateHashMapCapacity2(i)); } } @Warmup(iterations = 20) @Measurement(iterations = 10) @Benchmark - public void testCalculateHashMapCapacity3() { + public void testCalculateHashMapCapacity3(Blackhole blackhole) { for (int i = 0; i < Integer.MAX_VALUE; i++) { - consume(calculateHashMapCapacity3(i)); + blackhole.consume(calculateHashMapCapacity3(i)); } } From 4cf926d0c8231e059f86d1c80d3af97a1c13a837 Mon Sep 17 00:00:00 2001 From: XenoAmess Date: Thu, 24 Mar 2022 20:06:11 +0800 Subject: [PATCH 05/26] delete a space. --- src/java.base/share/classes/java/util/WeakHashMap.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/java.base/share/classes/java/util/WeakHashMap.java b/src/java.base/share/classes/java/util/WeakHashMap.java index 43661835d6b37..e91cd4fad1647 100644 --- a/src/java.base/share/classes/java/util/WeakHashMap.java +++ b/src/java.base/share/classes/java/util/WeakHashMap.java @@ -1347,7 +1347,7 @@ public int characteristics() { * @throws IllegalArgumentException if the initial capacity is negative. * @since 19 */ - public static WeakHashMap newWeakHashMap(int expectedSize) { + public static WeakHashMap newWeakHashMap(int expectedSize) { return new WeakHashMap<>(HashMap.calculateHashMapCapacity(expectedSize)); } From dadde82b4702f280b4da8201c778d3653155b811 Mon Sep 17 00:00:00 2001 From: XenoAmess Date: Fri, 25 Mar 2022 00:37:10 +0800 Subject: [PATCH 06/26] refine javadoc about default load factor --- src/java.base/share/classes/java/util/HashMap.java | 6 +++--- src/java.base/share/classes/java/util/LinkedHashMap.java | 4 ++-- src/java.base/share/classes/java/util/WeakHashMap.java | 4 ++-- 3 files changed, 7 insertions(+), 7 deletions(-) diff --git a/src/java.base/share/classes/java/util/HashMap.java b/src/java.base/share/classes/java/util/HashMap.java index d9f2b436757d4..4f8f847c582c7 100644 --- a/src/java.base/share/classes/java/util/HashMap.java +++ b/src/java.base/share/classes/java/util/HashMap.java @@ -2546,7 +2546,7 @@ static boolean checkInvariants(TreeNode t) { } /** - * Calculate initial capacity for HashMap based classes, from expected size. + * Calculate initial capacity for HashMap based classes, from expected size and default load factor (0.75). * * @param expectedSize expected size * @return initial capacity for HashMap based classes. @@ -2561,8 +2561,8 @@ static int calculateHashMapCapacity(int expectedSize) { /** * Creates a new, empty HashMap with an initial table size - * accommodating the specified number of elements without the need - * to dynamically resize. + * accommodating the specified number of elements and default load factor (0.75) + * without the need to dynamically resize. * * @param expectedSize expected size * @param the type of keys maintained by this map diff --git a/src/java.base/share/classes/java/util/LinkedHashMap.java b/src/java.base/share/classes/java/util/LinkedHashMap.java index cd2560faeaa2d..090cf81411bcf 100644 --- a/src/java.base/share/classes/java/util/LinkedHashMap.java +++ b/src/java.base/share/classes/java/util/LinkedHashMap.java @@ -790,8 +790,8 @@ final class LinkedEntryIterator extends LinkedHashIterator /** * Creates a new, empty LinkedHashMap with an initial table size - * accommodating the specified number of elements without the need - * to dynamically resize. + * accommodating the specified number of elements and default load factor (0.75) + * without the need to dynamically resize. * * @param expectedSize expected size * @param the type of keys maintained by this map diff --git a/src/java.base/share/classes/java/util/WeakHashMap.java b/src/java.base/share/classes/java/util/WeakHashMap.java index e91cd4fad1647..45ec368c36fd1 100644 --- a/src/java.base/share/classes/java/util/WeakHashMap.java +++ b/src/java.base/share/classes/java/util/WeakHashMap.java @@ -1337,8 +1337,8 @@ public int characteristics() { /** * Creates a new, empty WeakHashMap with an initial table size - * accommodating the specified number of elements without the need - * to dynamically resize. + * accommodating the specified number of elements and default load factor (0.75) + * without the need to dynamically resize. * * @param expectedSize expected size * @param the type of keys maintained by this map From aea7edf93817dd711ac3cd9327062dc29dc785fb Mon Sep 17 00:00:00 2001 From: XenoAmess Date: Fri, 25 Mar 2022 01:35:51 +0800 Subject: [PATCH 07/26] refine javadoc; refine implement when expectedSize < 0 --- .../share/classes/java/util/HashMap.java | 25 +++++++++++++++++-- 1 file changed, 23 insertions(+), 2 deletions(-) diff --git a/src/java.base/share/classes/java/util/HashMap.java b/src/java.base/share/classes/java/util/HashMap.java index 4f8f847c582c7..cb7399e4189ac 100644 --- a/src/java.base/share/classes/java/util/HashMap.java +++ b/src/java.base/share/classes/java/util/HashMap.java @@ -2548,15 +2548,36 @@ static boolean checkInvariants(TreeNode t) { /** * Calculate initial capacity for HashMap based classes, from expected size and default load factor (0.75). * + *

This function is designed to return equal results than {@code (int)Math.ceil(expectedSize / 0.75)} when expectedSize>=0. + * When expectedSize<0, result of this function is meaningless. + * + *

Implementation logic of this function is: + * + *

1. When expectedSize is a small enough positive number, + * {@code (expectedSize + (expectedSize + 2) / 3)} always equals to {@code (int)Math.ceil(expectedSize / 0.75)}, as + * {@code (int)Math.ceil(expectedSize / 0.75)} equals to {@code (int)Math.ceil(expectedSize + expectedSize / 3.0)}, + * thus equals to {@code expectedSize + (int)Math.ceil(expectedSize / 3.0)}, + * thus equals to {@code (expectedSize + (expectedSize + 2) / 3)}. + * + *

2. When expectedSize is a big enough positive number (at least {@code Integer.MAX_VALUE / 4 * 3 + 3}, or say, 1610612736), + * {@code (expectedSize + (expectedSize + 2) / 3)} would overflow, in this turn we just return {@code Integer.MAX_VALUE} + * + *

3. When expectedSize is 0, return 0. + * + *

4. User must never let expectedSize be negative.Otherwise, return any number < 0. + * * @param expectedSize expected size * @return initial capacity for HashMap based classes. * @since 19 */ static int calculateHashMapCapacity(int expectedSize) { - if (expectedSize >= 1610612736) { + if (expectedSize >= Integer.MAX_VALUE / 4 * 3 + 3) { return Integer.MAX_VALUE; } - return (expectedSize + (expectedSize + 2) / 3); + if (expectedSize > 0) { + return (expectedSize + (expectedSize + 2) / 3); + } + return expectedSize; } /** From e5bc2002e1a2aa9366fe1e97177b0c5ad7b58867 Mon Sep 17 00:00:00 2001 From: XenoAmess Date: Fri, 25 Mar 2022 01:39:44 +0800 Subject: [PATCH 08/26] update jmh --- .../Collections/CalculateHashMapCapacityTestJMH.java | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/test/jdk/java/util/Collections/CalculateHashMapCapacityTestJMH.java b/test/jdk/java/util/Collections/CalculateHashMapCapacityTestJMH.java index 4bba3ea211736..3ee9a480a3f12 100644 --- a/test/jdk/java/util/Collections/CalculateHashMapCapacityTestJMH.java +++ b/test/jdk/java/util/Collections/CalculateHashMapCapacityTestJMH.java @@ -59,10 +59,13 @@ private static int calculateHashMapCapacity1(int expectedSize) { * @since 19 */ private static int calculateHashMapCapacity2(int expectedSize) { - if (expectedSize >= 1610612736) { + if (expectedSize >= Integer.MAX_VALUE / 4 * 3 + 3) { return Integer.MAX_VALUE; } - return (expectedSize + (expectedSize + 2) / 3); + if (expectedSize > 0) { + return (expectedSize + (expectedSize + 2) / 3); + } + return expectedSize; } /** @@ -76,7 +79,10 @@ private static int calculateHashMapCapacity3(int expectedSize) { if (expectedSize >= 805306368) { return (1 << 30); } - return (expectedSize + (expectedSize + 2) / 3); + if (expectedSize > 0) { + return (expectedSize + (expectedSize + 2) / 3); + } + return expectedSize; } @Warmup(iterations = 20) From 7a1f3b07efd4694db502354a66dde87b2f9e7f96 Mon Sep 17 00:00:00 2001 From: XenoAmess Date: Thu, 31 Mar 2022 07:16:30 +0800 Subject: [PATCH 09/26] update codes --- .../share/classes/java/util/HashMap.java | 52 ++++++------------- .../classes/java/util/LinkedHashMap.java | 21 ++++---- .../share/classes/java/util/WeakHashMap.java | 21 ++++---- 3 files changed, 37 insertions(+), 57 deletions(-) diff --git a/src/java.base/share/classes/java/util/HashMap.java b/src/java.base/share/classes/java/util/HashMap.java index cb7399e4189ac..4e6b9312ed2ee 100644 --- a/src/java.base/share/classes/java/util/HashMap.java +++ b/src/java.base/share/classes/java/util/HashMap.java @@ -2548,52 +2548,30 @@ static boolean checkInvariants(TreeNode t) { /** * Calculate initial capacity for HashMap based classes, from expected size and default load factor (0.75). * - *

This function is designed to return equal results than {@code (int)Math.ceil(expectedSize / 0.75)} when expectedSize>=0. - * When expectedSize<0, result of this function is meaningless. - * - *

Implementation logic of this function is: - * - *

1. When expectedSize is a small enough positive number, - * {@code (expectedSize + (expectedSize + 2) / 3)} always equals to {@code (int)Math.ceil(expectedSize / 0.75)}, as - * {@code (int)Math.ceil(expectedSize / 0.75)} equals to {@code (int)Math.ceil(expectedSize + expectedSize / 3.0)}, - * thus equals to {@code expectedSize + (int)Math.ceil(expectedSize / 3.0)}, - * thus equals to {@code (expectedSize + (expectedSize + 2) / 3)}. - * - *

2. When expectedSize is a big enough positive number (at least {@code Integer.MAX_VALUE / 4 * 3 + 3}, or say, 1610612736), - * {@code (expectedSize + (expectedSize + 2) / 3)} would overflow, in this turn we just return {@code Integer.MAX_VALUE} - * - *

3. When expectedSize is 0, return 0. - * - *

4. User must never let expectedSize be negative.Otherwise, return any number < 0. - * - * @param expectedSize expected size + * @param numMappings the expected number of mappings * @return initial capacity for HashMap based classes. * @since 19 */ - static int calculateHashMapCapacity(int expectedSize) { - if (expectedSize >= Integer.MAX_VALUE / 4 * 3 + 3) { - return Integer.MAX_VALUE; - } - if (expectedSize > 0) { - return (expectedSize + (expectedSize + 2) / 3); - } - return expectedSize; + static int calculateHashMapCapacity(int numMappings) { + return (int) Math.ceil(numMappings / 0.75); } /** - * Creates a new, empty HashMap with an initial table size - * accommodating the specified number of elements and default load factor (0.75) - * without the need to dynamically resize. + * Creates a new, empty HashMap suitable for the expected number of mappings. + * The returned map uses the default load factor of 0.75, and its initial capacity is + * generally large enough so that the expected number of mappings can be added + * without resizing the map. * - * @param expectedSize expected size - * @param the type of keys maintained by this map - * @param the type of mapped values - * @return the HashMap created. - * @throws IllegalArgumentException if the initial capacity is negative. + * @param numMappings the expected number of mappings + * @param the type of keys maintained by this map + * @param the type of mapped values + * @return the newly created map + * @throws IllegalArgumentException if numMappings is negative * @since 19 */ - public static HashMap newHashMap(int expectedSize) { - return new HashMap<>(calculateHashMapCapacity(expectedSize)); + public static HashMap newHashMap(int numMappings) { + return new HashMap<>(calculateHashMapCapacity(numMappings)); } + } diff --git a/src/java.base/share/classes/java/util/LinkedHashMap.java b/src/java.base/share/classes/java/util/LinkedHashMap.java index 090cf81411bcf..13ef1ba65f741 100644 --- a/src/java.base/share/classes/java/util/LinkedHashMap.java +++ b/src/java.base/share/classes/java/util/LinkedHashMap.java @@ -789,19 +789,20 @@ final class LinkedEntryIterator extends LinkedHashIterator } /** - * Creates a new, empty LinkedHashMap with an initial table size - * accommodating the specified number of elements and default load factor (0.75) - * without the need to dynamically resize. + * Creates a new, empty LinkedHashMap suitable for the expected number of mappings. + * The returned map uses the default load factor of 0.75, and its initial capacity is + * generally large enough so that the expected number of mappings can be added + * without resizing the map. * - * @param expectedSize expected size - * @param the type of keys maintained by this map - * @param the type of mapped values - * @return the LinkedHashMap created. - * @throws IllegalArgumentException if the initial capacity is negative. + * @param numMappings the expected number of mappings + * @param the type of keys maintained by this map + * @param the type of mapped values + * @return the newly created map + * @throws IllegalArgumentException if numMappings is negative * @since 19 */ - public static LinkedHashMap newLinkedHashMap(int expectedSize) { - return new LinkedHashMap<>(HashMap.calculateHashMapCapacity(expectedSize)); + public static LinkedHashMap newLinkedHashMap(int numMappings) { + return new LinkedHashMap<>(HashMap.calculateHashMapCapacity(numMappings)); } } diff --git a/src/java.base/share/classes/java/util/WeakHashMap.java b/src/java.base/share/classes/java/util/WeakHashMap.java index 45ec368c36fd1..557d9fa2979a7 100644 --- a/src/java.base/share/classes/java/util/WeakHashMap.java +++ b/src/java.base/share/classes/java/util/WeakHashMap.java @@ -1336,19 +1336,20 @@ public int characteristics() { } /** - * Creates a new, empty WeakHashMap with an initial table size - * accommodating the specified number of elements and default load factor (0.75) - * without the need to dynamically resize. + * Creates a new, empty WeakHashMap suitable for the expected number of mappings. + * The returned map uses the default load factor of 0.75, and its initial capacity is + * generally large enough so that the expected number of mappings can be added + * without resizing the map. * - * @param expectedSize expected size - * @param the type of keys maintained by this map - * @param the type of mapped values - * @return the WeakHashMap created. - * @throws IllegalArgumentException if the initial capacity is negative. + * @param numMappings the expected number of mappings + * @param the type of keys maintained by this map + * @param the type of mapped values + * @return the newly created map + * @throws IllegalArgumentException if numMappings is negative * @since 19 */ - public static WeakHashMap newWeakHashMap(int expectedSize) { - return new WeakHashMap<>(HashMap.calculateHashMapCapacity(expectedSize)); + public static WeakHashMap newWeakHashMap(int numMappings) { + return new WeakHashMap<>(HashMap.calculateHashMapCapacity(numMappings)); } } From d4147bcb4d93008ea9edcf1b625b287f6a52462e Mon Sep 17 00:00:00 2001 From: XenoAmess Date: Sun, 3 Apr 2022 06:06:24 +0800 Subject: [PATCH 10/26] update usages of HashMap --- .../locale/provider/HostLocaleProviderAdapterImpl.java | 2 +- src/java.base/share/classes/java/lang/Character.java | 5 ++--- src/java.base/share/classes/java/lang/Class.java | 2 +- src/java.base/share/classes/java/lang/Module.java | 5 ++--- src/java.base/share/classes/java/lang/Thread.java | 2 +- .../share/classes/java/lang/module/Resolver.java | 9 ++++----- .../security/cert/CertificateRevokedException.java | 2 +- .../java/security/cert/PKIXRevocationChecker.java | 4 ++-- src/java.base/share/classes/java/util/HashMap.java | 1 - .../share/classes/java/util/ListResourceBundle.java | 2 +- .../share/classes/java/util/jar/JarVerifier.java | 2 +- .../share/classes/jdk/internal/module/ModuleInfo.java | 2 +- .../sun/security/provider/certpath/OCSPResponse.java | 4 ++-- .../share/classes/sun/security/util/Cache.java | 2 +- .../sun/util/resources/OpenListResourceBundle.java | 2 +- .../unix/classes/java/lang/ProcessEnvironment.java | 4 ++-- .../classes/sun/nio/fs/MimeTypesFileTypeDetector.java | 2 +- .../com/sun/java/swing/plaf/gtk/GTKLookAndFeel.java | 2 +- .../share/classes/java/beans/MetaData.java | 2 +- .../classes/sun/awt/datatransfer/DataTransferer.java | 10 +++++----- .../lang/management/DefaultPlatformMBeanProvider.java | 6 +++--- .../share/classes/sun/management/HotspotThread.java | 2 +- .../jdk/internal/net/http/hpack/HeaderTable.java | 4 ++-- .../dsig/internal/dom/DOMXPathFilter2Transform.java | 2 +- .../jcp/xml/dsig/internal/dom/DOMXPathTransform.java | 2 +- .../apache/xalan/internal/xsltc/dom/DocumentCache.java | 2 +- .../apache/xerces/internal/dom/CoreDocumentImpl.java | 2 +- .../impl/xs/traversers/XSAttributeChecker.java | 2 +- .../classes/com/sun/tools/javac/comp/Operators.java | 4 ++-- .../javac/processing/JavacProcessingEnvironment.java | 2 +- .../src/jdk/vm/ci/hotspot/HotSpotVMConfigStore.java | 8 ++++---- .../src/jdk/vm/ci/services/Services.java | 2 +- .../share/classes/jdk/jfr/consumer/MetadataEvent.java | 2 +- .../share/classes/jdk/jfr/internal/MetadataLoader.java | 2 +- src/jdk.jfr/share/classes/jdk/jfr/internal/Utils.java | 2 +- .../classes/jdk/management/jfr/ConfigurationInfo.java | 2 +- .../management/internal/PlatformMBeanProviderImpl.java | 2 +- .../main/java/com/sun/hotspot/igv/data/InputGraph.java | 4 ++-- .../com/sun/hotspot/igv/difference/Difference.java | 6 +++--- .../java/com/sun/hotspot/igv/layout/LayoutGraph.java | 6 +++--- .../igv/servercompiler/ServerCompilerScheduler.java | 8 ++++---- .../java/com/sun/hotspot/igv/view/DiagramScene.java | 2 +- 42 files changed, 68 insertions(+), 72 deletions(-) diff --git a/src/java.base/macosx/classes/sun/util/locale/provider/HostLocaleProviderAdapterImpl.java b/src/java.base/macosx/classes/sun/util/locale/provider/HostLocaleProviderAdapterImpl.java index cfea1e21bece5..3e3fc85120771 100644 --- a/src/java.base/macosx/classes/sun/util/locale/provider/HostLocaleProviderAdapterImpl.java +++ b/src/java.base/macosx/classes/sun/util/locale/provider/HostLocaleProviderAdapterImpl.java @@ -570,7 +570,7 @@ public Map getDisplayNames(String calendarType, String[] names = getCalendarDisplayStrings(locale.toLanguageTag(), field, style); if (names != null) { - map = new HashMap<>((int)Math.ceil(names.length / 0.75)); + map = HashMap.newHashMap(names.length); for (int value = 0; value < names.length; value++) { if (names[value] != null) { map.put(names[value], value); diff --git a/src/java.base/share/classes/java/lang/Character.java b/src/java.base/share/classes/java/lang/Character.java index d30743b143cb8..9853f068d8e23 100644 --- a/src/java.base/share/classes/java/lang/Character.java +++ b/src/java.base/share/classes/java/lang/Character.java @@ -744,8 +744,7 @@ public static final class UnicodeBlock extends Subset { * 0.75 - the default load factor of HashMap */ private static final int NUM_ENTITIES = 737; - private static Map map = - new HashMap<>((int)(NUM_ENTITIES / 0.75f + 1.0f)); + private static Map map = HashMap.newHashMap(NUM_ENTITIES); /** * Creates a UnicodeBlock with the given identifier name. @@ -8572,7 +8571,7 @@ public static enum UnicodeScript { private static final HashMap aliases; static { - aliases = new HashMap<>((int)(162 / 0.75f + 1.0f)); + aliases = HashMap.newHashMap(162); aliases.put("ADLM", ADLAM); aliases.put("AGHB", CAUCASIAN_ALBANIAN); aliases.put("AHOM", AHOM); diff --git a/src/java.base/share/classes/java/lang/Class.java b/src/java.base/share/classes/java/lang/Class.java index 840abc63aaf0e..76428a9b92131 100644 --- a/src/java.base/share/classes/java/lang/Class.java +++ b/src/java.base/share/classes/java/lang/Class.java @@ -3910,7 +3910,7 @@ Map enumConstantDirectory() { if (universe == null) throw new IllegalArgumentException( getName() + " is not an enum class"); - directory = new HashMap<>((int)(universe.length / 0.75f) + 1); + directory = HashMap.newHashMap(universe.length); for (T constant : universe) { directory.put(((Enum)constant).name(), constant); } diff --git a/src/java.base/share/classes/java/lang/Module.java b/src/java.base/share/classes/java/lang/Module.java index e822c95142066..d7f7eda02d837 100644 --- a/src/java.base/share/classes/java/lang/Module.java +++ b/src/java.base/share/classes/java/lang/Module.java @@ -980,7 +980,7 @@ void implAddOpensToAllUnnamed(Set concealedPkgs, Set exportedPkg // the packages to all unnamed modules. Map> openPackages = this.openPackages; if (openPackages == null) { - openPackages = new HashMap<>((4 * (concealedPkgs.size() + exportedPkgs.size()) / 3) + 1); + openPackages = HashMap.newHashMap(concealedPkgs.size() + exportedPkgs.size()); } else { openPackages = new HashMap<>(openPackages); } @@ -1133,8 +1133,7 @@ static Map defineModules(Configuration cf, boolean isBootLayer = (ModuleLayer.boot() == null); int numModules = cf.modules().size(); - int cap = (int)(numModules / 0.75f + 1.0f); - Map nameToModule = new HashMap<>(cap); + Map nameToModule = HashMap.newHashMap(numModules); // to avoid repeated lookups and reduce iteration overhead, we create // arrays holding correlated information about each module. diff --git a/src/java.base/share/classes/java/lang/Thread.java b/src/java.base/share/classes/java/lang/Thread.java index 0d41973b99e42..27bc3c71254c0 100644 --- a/src/java.base/share/classes/java/lang/Thread.java +++ b/src/java.base/share/classes/java/lang/Thread.java @@ -1655,7 +1655,7 @@ public static Map getAllStackTraces() { // Get a snapshot of the list of all threads Thread[] threads = getThreads(); StackTraceElement[][] traces = dumpThreads(threads); - Map m = new HashMap<>(threads.length); + Map m = HashMap.newHashMap(threads.length); for (int i = 0; i < threads.length; i++) { StackTraceElement[] stackTrace = traces[i]; if (stackTrace != null) { diff --git a/src/java.base/share/classes/java/lang/module/Resolver.java b/src/java.base/share/classes/java/lang/module/Resolver.java index 8cbb35cb78e2b..3db279c124ac1 100644 --- a/src/java.base/share/classes/java/lang/module/Resolver.java +++ b/src/java.base/share/classes/java/lang/module/Resolver.java @@ -498,12 +498,11 @@ private void checkHashes() { */ private Map> makeGraph(Configuration cf) { - // initial capacity of maps to avoid resizing - int capacity = 1 + (4 * nameToReference.size())/ 3; + int nameToReferenceSize = nameToReference.size(); // the "reads" graph starts as a module dependence graph and // is iteratively updated to be the readability graph - Map> g1 = new HashMap<>(capacity); + Map> g1 = HashMap.newHashMap(nameToReferenceSize); // the "requires transitive" graph, contains requires transitive edges only Map> g2; @@ -512,7 +511,7 @@ private Map> makeGraph(Configuration cf) { // as there may be selected modules that have a dependency on modules in // the parent configuration. if (ModuleLayer.boot() == null) { - g2 = new HashMap<>(capacity); + g2 = HashMap.newHashMap(nameToReferenceSize); } else { g2 = parents.stream() .flatMap(Configuration::configurations) @@ -539,7 +538,7 @@ private Map> makeGraph(Configuration cf) { // populate g1 and g2 with the dependences from the selected modules - Map nameToResolved = new HashMap<>(capacity); + Map nameToResolved = HashMap.newHashMap(nameToReferenceSize); for (ModuleReference mref : nameToReference.values()) { ModuleDescriptor descriptor = mref.descriptor(); diff --git a/src/java.base/share/classes/java/security/cert/CertificateRevokedException.java b/src/java.base/share/classes/java/security/cert/CertificateRevokedException.java index 607662f39dfd9..a7cb039697873 100644 --- a/src/java.base/share/classes/java/security/cert/CertificateRevokedException.java +++ b/src/java.base/share/classes/java/security/cert/CertificateRevokedException.java @@ -245,7 +245,7 @@ private void readObject(ObjectInputStream ois) } else if (size < 0) { throw new IOException("size cannot be negative"); } else { - extensions = new HashMap<>(size > 20 ? 20 : size); + extensions = HashMap.newHashMap(size > 20 ? 20 : size); } // Read in the extensions and put the mappings in the extensions map diff --git a/src/java.base/share/classes/java/security/cert/PKIXRevocationChecker.java b/src/java.base/share/classes/java/security/cert/PKIXRevocationChecker.java index f176568d224e5..751bd0c3cbadc 100644 --- a/src/java.base/share/classes/java/security/cert/PKIXRevocationChecker.java +++ b/src/java.base/share/classes/java/security/cert/PKIXRevocationChecker.java @@ -197,7 +197,7 @@ public void setOcspResponses(Map responses) if (responses == null) { this.ocspResponses = Collections.emptyMap(); } else { - Map copy = new HashMap<>(responses.size()); + Map copy = HashMap.newHashMap(responses.size()); for (Map.Entry e : responses.entrySet()) { copy.put(e.getKey(), e.getValue().clone()); } @@ -216,7 +216,7 @@ public void setOcspResponses(Map responses) * Returns an empty map if no responses have been specified. */ public Map getOcspResponses() { - Map copy = new HashMap<>(ocspResponses.size()); + Map copy = HashMap.newHashMap(ocspResponses.size()); for (Map.Entry e : ocspResponses.entrySet()) { copy.put(e.getKey(), e.getValue().clone()); } diff --git a/src/java.base/share/classes/java/util/HashMap.java b/src/java.base/share/classes/java/util/HashMap.java index 4e6b9312ed2ee..e2003962c4b20 100644 --- a/src/java.base/share/classes/java/util/HashMap.java +++ b/src/java.base/share/classes/java/util/HashMap.java @@ -2573,5 +2573,4 @@ public static HashMap newHashMap(int numMappings) { return new HashMap<>(calculateHashMapCapacity(numMappings)); } - } diff --git a/src/java.base/share/classes/java/util/ListResourceBundle.java b/src/java.base/share/classes/java/util/ListResourceBundle.java index 053d70b1cf704..122f9d17393ab 100644 --- a/src/java.base/share/classes/java/util/ListResourceBundle.java +++ b/src/java.base/share/classes/java/util/ListResourceBundle.java @@ -193,7 +193,7 @@ private synchronized void loadLookup() { return; Object[][] contents = getContents(); - HashMap temp = new HashMap<>(contents.length); + HashMap temp = HashMap.newHashMap(contents.length); for (Object[] content : contents) { // key must be non-null String, value must be non-null String key = (String) content[0]; diff --git a/src/java.base/share/classes/java/util/jar/JarVerifier.java b/src/java.base/share/classes/java/util/jar/JarVerifier.java index e6a217b424cc7..ef203fd1ab5e7 100644 --- a/src/java.base/share/classes/java/util/jar/JarVerifier.java +++ b/src/java.base/share/classes/java/util/jar/JarVerifier.java @@ -672,7 +672,7 @@ private synchronized Map signerMap() { * only about the asserted signatures. Verification of * signature validity happens via the JarEntry apis. */ - signerMap = new HashMap<>(verifiedSigners.size() + sigFileSigners.size()); + signerMap = HashMap.newHashMap(verifiedSigners.size() + sigFileSigners.size()); signerMap.putAll(verifiedSigners); signerMap.putAll(sigFileSigners); } diff --git a/src/java.base/share/classes/jdk/internal/module/ModuleInfo.java b/src/java.base/share/classes/jdk/internal/module/ModuleInfo.java index 338fbeb9555ae..71f34c18cdebd 100644 --- a/src/java.base/share/classes/jdk/internal/module/ModuleInfo.java +++ b/src/java.base/share/classes/jdk/internal/module/ModuleInfo.java @@ -588,7 +588,7 @@ private ModuleHashes readModuleHashesAttribute(DataInput in, ConstantPool cpool) String algorithm = cpool.getUtf8(algorithm_index); int hash_count = in.readUnsignedShort(); - Map map = new HashMap<>(hash_count); + Map map = HashMap.newHashMap(hash_count); for (int i=0; i(singleResponseDer.length); + singleResponseMap = HashMap.newHashMap(singleResponseDer.length); if (debug != null) { debug.println("OCSP number of SingleResponses: " + singleResponseDer.length); @@ -751,7 +751,7 @@ public String toString() { parseExtensions(DerValue derVal) throws IOException { DerValue[] extDer = derVal.data.getSequence(3); Map extMap = - new HashMap<>(extDer.length); + HashMap.newHashMap(extDer.length); for (DerValue extDerVal : extDer) { Extension ext = new Extension(extDerVal); diff --git a/src/java.base/share/classes/sun/security/util/Cache.java b/src/java.base/share/classes/sun/security/util/Cache.java index 65bf6cc758112..40006779d37da 100644 --- a/src/java.base/share/classes/sun/security/util/Cache.java +++ b/src/java.base/share/classes/sun/security/util/Cache.java @@ -481,7 +481,7 @@ public synchronized void accept(CacheVisitor visitor) { } private Map getCachedEntries() { - Map kvmap = new HashMap<>(cacheMap.size()); + Map kvmap = HashMap.newHashMap(cacheMap.size()); for (CacheEntry entry : cacheMap.values()) { kvmap.put(entry.getKey(), entry.getValue()); diff --git a/src/java.base/share/classes/sun/util/resources/OpenListResourceBundle.java b/src/java.base/share/classes/sun/util/resources/OpenListResourceBundle.java index 4d31cf2834d80..c516257965bed 100644 --- a/src/java.base/share/classes/sun/util/resources/OpenListResourceBundle.java +++ b/src/java.base/share/classes/sun/util/resources/OpenListResourceBundle.java @@ -157,7 +157,7 @@ private void loadLookup() { * Default uses HashMap. */ protected Map createMap(int size) { - return new HashMap<>(size); + return HashMap.newHashMap(size); } protected Set createSet() { diff --git a/src/java.base/unix/classes/java/lang/ProcessEnvironment.java b/src/java.base/unix/classes/java/lang/ProcessEnvironment.java index e4341e5322cf3..f9086c0921886 100644 --- a/src/java.base/unix/classes/java/lang/ProcessEnvironment.java +++ b/src/java.base/unix/classes/java/lang/ProcessEnvironment.java @@ -68,7 +68,7 @@ final class ProcessEnvironment // We cache the C environment. This means that subsequent calls // to putenv/setenv from C will not be visible from Java code. byte[][] environ = environ(); - theEnvironment = new HashMap<>(environ.length/2 + 3); + theEnvironment = HashMap.newHashMap(environ.length/2 + 3); // Read environment variables back to front, // so that earlier variables override later ones. for (int i = environ.length-1; i > 0; i-=2) @@ -99,7 +99,7 @@ static Map environment() { /* Only for use by Runtime.exec(...String[]envp...) */ static Map emptyEnvironment(int capacity) { - return new StringEnvironment(new HashMap<>(capacity)); + return new StringEnvironment(HashMap.newHashMap(capacity)); } private static native byte[][] environ(); diff --git a/src/java.base/unix/classes/sun/nio/fs/MimeTypesFileTypeDetector.java b/src/java.base/unix/classes/sun/nio/fs/MimeTypesFileTypeDetector.java index 8e0b47eb25dbc..60b44e7d9e435 100644 --- a/src/java.base/unix/classes/sun/nio/fs/MimeTypesFileTypeDetector.java +++ b/src/java.base/unix/classes/sun/nio/fs/MimeTypesFileTypeDetector.java @@ -107,7 +107,7 @@ public List run() { } }); - mimeTypeMap = new HashMap<>(lines.size()); + mimeTypeMap = HashMap.newHashMap(lines.size()); String entry = ""; for (String line : lines) { entry += line; diff --git a/src/java.desktop/share/classes/com/sun/java/swing/plaf/gtk/GTKLookAndFeel.java b/src/java.desktop/share/classes/com/sun/java/swing/plaf/gtk/GTKLookAndFeel.java index 40d713123c734..84482d5d6da1c 100644 --- a/src/java.desktop/share/classes/com/sun/java/swing/plaf/gtk/GTKLookAndFeel.java +++ b/src/java.desktop/share/classes/com/sun/java/swing/plaf/gtk/GTKLookAndFeel.java @@ -1445,7 +1445,7 @@ public void initialize() { * XRender. */ gtkAAFontSettingsCond = SwingUtilities2.isLocalDisplay(); - aaTextInfo = new HashMap<>(2); + aaTextInfo = HashMap.newHashMap(2); SwingUtilities2.putAATextInfo(gtkAAFontSettingsCond, aaTextInfo); } diff --git a/src/java.desktop/share/classes/java/beans/MetaData.java b/src/java.desktop/share/classes/java/beans/MetaData.java index 52237b15792ad..7d67ff426ca20 100644 --- a/src/java.desktop/share/classes/java/beans/MetaData.java +++ b/src/java.desktop/share/classes/java/beans/MetaData.java @@ -653,7 +653,7 @@ protected Expression instantiate(Object oldInstance, Encoder out) { int size = 12; Map basic = font.getAttributes(); - Map clone = new HashMap<>(basic.size()); + Map clone = HashMap.newHashMap(basic.size()); for (TextAttribute key : basic.keySet()) { Object value = basic.get(key); if (value != null) { diff --git a/src/java.desktop/share/classes/sun/awt/datatransfer/DataTransferer.java b/src/java.desktop/share/classes/sun/awt/datatransfer/DataTransferer.java index 8ca34787e1958..5cc186bfd907a 100644 --- a/src/java.desktop/share/classes/sun/awt/datatransfer/DataTransferer.java +++ b/src/java.desktop/share/classes/sun/awt/datatransfer/DataTransferer.java @@ -329,13 +329,13 @@ public SortedMap getFormatsForTransferable(Transferable content public SortedMap getFormatsForFlavors(DataFlavor[] flavors, FlavorTable map) { - Map formatMap = new HashMap<>(flavors.length); - Map textPlainMap = new HashMap<>(flavors.length); + Map formatMap = HashMap.newHashMap(flavors.length); + Map textPlainMap = HashMap.newHashMap(flavors.length); // Maps formats to indices that will be used to sort the formats // according to the preference order. // Larger index value corresponds to the more preferable format. - Map indexMap = new HashMap<>(flavors.length); - Map textPlainIndexMap = new HashMap<>(flavors.length); + Map indexMap = HashMap.newHashMap(flavors.length); + Map textPlainIndexMap = HashMap.newHashMap(flavors.length); int currentIndex = 0; @@ -409,7 +409,7 @@ public long[] getFormatsForTransferableAsArray(Transferable contents, * when converting to the DataFlavor. */ public Map getFlavorsForFormats(long[] formats, FlavorTable map) { - Map flavorMap = new HashMap<>(formats.length); + Map flavorMap = HashMap.newHashMap(formats.length); Set> mappingSet = new HashSet<>(formats.length); Set flavorSet = new HashSet<>(formats.length); diff --git a/src/java.management/share/classes/java/lang/management/DefaultPlatformMBeanProvider.java b/src/java.management/share/classes/java/lang/management/DefaultPlatformMBeanProvider.java index 9d9c524b5336d..e9e905918ccb9 100644 --- a/src/java.management/share/classes/java/lang/management/DefaultPlatformMBeanProvider.java +++ b/src/java.management/share/classes/java/lang/management/DefaultPlatformMBeanProvider.java @@ -184,7 +184,7 @@ public Map nameToMBeanMap() { if (list.isEmpty()) { map = Collections.emptyMap(); } else { - map = new HashMap<>(list.size()); + map = HashMap.newHashMap(list.size()); for (MemoryManagerMXBean gcm : list) { map.put(gcm.getObjectName().getCanonicalName(), gcm); @@ -278,7 +278,7 @@ public Map nameToMBeanMap() { if (list.isEmpty()) { map = Collections.emptyMap(); } else { - map = new HashMap<>(list.size()); + map = HashMap.newHashMap(list.size()); for (MemoryPoolMXBean mpm : list) { map.put(mpm.getObjectName().getCanonicalName(), mpm); @@ -415,7 +415,7 @@ public Map nameToMBeanMap() { if (list.isEmpty()) { map = Collections.emptyMap(); } else { - map = new HashMap<>(list.size()); + map = HashMap.newHashMap(list.size()); list.forEach(mbean -> map.put(mbean.getObjectName().getCanonicalName(),mbean)); } return map; diff --git a/src/java.management/share/classes/sun/management/HotspotThread.java b/src/java.management/share/classes/sun/management/HotspotThread.java index 03e403a89831a..2fd205db37180 100644 --- a/src/java.management/share/classes/sun/management/HotspotThread.java +++ b/src/java.management/share/classes/sun/management/HotspotThread.java @@ -58,7 +58,7 @@ public Map getInternalThreadCpuTimes() { String[] names = new String[count]; long[] times = new long[count]; int numThreads = getInternalThreadTimes0(names, times); - Map result = new HashMap<>(numThreads); + Map result = HashMap.newHashMap(numThreads); for (int i = 0; i < numThreads; i++) { result.put(names[i], times[i]); } diff --git a/src/java.net.http/share/classes/jdk/internal/net/http/hpack/HeaderTable.java b/src/java.net.http/share/classes/jdk/internal/net/http/hpack/HeaderTable.java index bda48ee2330c8..a453be264fc22 100644 --- a/src/java.net.http/share/classes/jdk/internal/net/http/hpack/HeaderTable.java +++ b/src/java.net.http/share/classes/jdk/internal/net/http/hpack/HeaderTable.java @@ -108,7 +108,7 @@ final class HeaderTable extends SimpleHeaderTable { static { Map> map - = new HashMap<>(STATIC_TABLE_LENGTH); + = HashMap.newHashMap(STATIC_TABLE_LENGTH); for (int i = 1; i <= STATIC_TABLE_LENGTH; i++) { HeaderField f = staticTable.get(i); Map values @@ -116,7 +116,7 @@ final class HeaderTable extends SimpleHeaderTable { values.put(f.value, i); } // create an immutable deep copy - Map> copy = new HashMap<>(map.size()); + Map> copy = HashMap.newHashMap(map.size()); for (Map.Entry> e : map.entrySet()) { copy.put(e.getKey(), Map.copyOf(e.getValue())); } diff --git a/src/java.xml.crypto/share/classes/org/jcp/xml/dsig/internal/dom/DOMXPathFilter2Transform.java b/src/java.xml.crypto/share/classes/org/jcp/xml/dsig/internal/dom/DOMXPathFilter2Transform.java index 51cbfbd6f3034..bdcfa9c0b0b41 100644 --- a/src/java.xml.crypto/share/classes/org/jcp/xml/dsig/internal/dom/DOMXPathFilter2Transform.java +++ b/src/java.xml.crypto/share/classes/org/jcp/xml/dsig/internal/dom/DOMXPathFilter2Transform.java @@ -107,7 +107,7 @@ private void unmarshalParams(Element curXPathElem) throws MarshalException if (attributes != null) { int length = attributes.getLength(); Map namespaceMap = - new HashMap<>(length); + HashMap.newHashMap(length); for (int i = 0; i < length; i++) { Attr attr = (Attr)attributes.item(i); String prefix = attr.getPrefix(); diff --git a/src/java.xml.crypto/share/classes/org/jcp/xml/dsig/internal/dom/DOMXPathTransform.java b/src/java.xml.crypto/share/classes/org/jcp/xml/dsig/internal/dom/DOMXPathTransform.java index b250c1f1b09b4..f568843cd2f39 100644 --- a/src/java.xml.crypto/share/classes/org/jcp/xml/dsig/internal/dom/DOMXPathTransform.java +++ b/src/java.xml.crypto/share/classes/org/jcp/xml/dsig/internal/dom/DOMXPathTransform.java @@ -75,7 +75,7 @@ private void unmarshalParams(Element paramsElem) { if (attributes != null) { int length = attributes.getLength(); Map namespaceMap = - new HashMap<>(length); + HashMap.newHashMap(length); for (int i = 0; i < length; i++) { Attr attr = (Attr)attributes.item(i); String prefix = attr.getPrefix(); diff --git a/src/java.xml/share/classes/com/sun/org/apache/xalan/internal/xsltc/dom/DocumentCache.java b/src/java.xml/share/classes/com/sun/org/apache/xalan/internal/xsltc/dom/DocumentCache.java index e0e526427f48b..afeed3d5fd0ef 100644 --- a/src/java.xml/share/classes/com/sun/org/apache/xalan/internal/xsltc/dom/DocumentCache.java +++ b/src/java.xml/share/classes/com/sun/org/apache/xalan/internal/xsltc/dom/DocumentCache.java @@ -168,7 +168,7 @@ public DocumentCache(int size, XSLTCDTMManager dtmManager) throws SAXException { _count = 0; _current = 0; _size = size; - _references = new HashMap<>(_size+2); + _references = HashMap.newHashMap(_size); _URIs = new String[_size]; try { diff --git a/src/java.xml/share/classes/com/sun/org/apache/xerces/internal/dom/CoreDocumentImpl.java b/src/java.xml/share/classes/com/sun/org/apache/xerces/internal/dom/CoreDocumentImpl.java index 05de2aff9b4b8..257c8ccfe5551 100644 --- a/src/java.xml/share/classes/com/sun/org/apache/xerces/internal/dom/CoreDocumentImpl.java +++ b/src/java.xml/share/classes/com/sun/org/apache/xerces/internal/dom/CoreDocumentImpl.java @@ -393,7 +393,7 @@ protected void cloneNode(CoreDocumentImpl newdoc, boolean deep) { if (identifiers != null) { // Build a reverse mapping from element to identifier. - reversedIdentifiers = new HashMap<>(identifiers.size()); + reversedIdentifiers = HashMap.newHashMap(identifiers.size()); for (String elementId : identifiers.keySet()) { reversedIdentifiers.put(identifiers.get(elementId), elementId); } diff --git a/src/java.xml/share/classes/com/sun/org/apache/xerces/internal/impl/xs/traversers/XSAttributeChecker.java b/src/java.xml/share/classes/com/sun/org/apache/xerces/internal/impl/xs/traversers/XSAttributeChecker.java index ed099cc4951f6..86dd766ec1a49 100644 --- a/src/java.xml/share/classes/com/sun/org/apache/xerces/internal/impl/xs/traversers/XSAttributeChecker.java +++ b/src/java.xml/share/classes/com/sun/org/apache/xerces/internal/impl/xs/traversers/XSAttributeChecker.java @@ -1816,7 +1816,7 @@ OneAttr get(String key) { class LargeContainer extends Container { Map items; LargeContainer(int size) { - items = new HashMap<>(size*2+1); + items = HashMap.newHashMap(size*2+1); values = new OneAttr[size]; } void put(String key, OneAttr value) { diff --git a/src/jdk.compiler/share/classes/com/sun/tools/javac/comp/Operators.java b/src/jdk.compiler/share/classes/com/sun/tools/javac/comp/Operators.java index 6ca0578339d3c..23fd6b4827994 100644 --- a/src/jdk.compiler/share/classes/com/sun/tools/javac/comp/Operators.java +++ b/src/jdk.compiler/share/classes/com/sun/tools/javac/comp/Operators.java @@ -74,10 +74,10 @@ public class Operators { private final Types types; /** Unary operators map. */ - private Map> unaryOperators = new HashMap<>(Tag.getNumberOfOperators()); + private Map> unaryOperators = HashMap.newHashMap(Tag.getNumberOfOperators()); /** Binary operators map. */ - private Map> binaryOperators = new HashMap<>(Tag.getNumberOfOperators()); + private Map> binaryOperators = HashMap.newHashMap(Tag.getNumberOfOperators()); /** The names of all operators. */ private Name[] opname = new Name[Tag.getNumberOfOperators()]; diff --git a/src/jdk.compiler/share/classes/com/sun/tools/javac/processing/JavacProcessingEnvironment.java b/src/jdk.compiler/share/classes/com/sun/tools/javac/processing/JavacProcessingEnvironment.java index 9174f0b7385dc..ee096a78877f6 100644 --- a/src/jdk.compiler/share/classes/com/sun/tools/javac/processing/JavacProcessingEnvironment.java +++ b/src/jdk.compiler/share/classes/com/sun/tools/javac/processing/JavacProcessingEnvironment.java @@ -884,7 +884,7 @@ private void discoverAndRunProcs(Set annotationsPresent, List topLevelClasses, List packageInfoFiles, List moduleInfoFiles) { - Map unmatchedAnnotations = new HashMap<>(annotationsPresent.size()); + Map unmatchedAnnotations = HashMap.newHashMap(annotationsPresent.size()); for(TypeElement a : annotationsPresent) { ModuleElement mod = elementUtils.getModuleOf(a); diff --git a/src/jdk.internal.vm.ci/share/classes/jdk.vm.ci.hotspot/src/jdk/vm/ci/hotspot/HotSpotVMConfigStore.java b/src/jdk.internal.vm.ci/share/classes/jdk.vm.ci.hotspot/src/jdk/vm/ci/hotspot/HotSpotVMConfigStore.java index 647779d579480..e0fb0827de783 100644 --- a/src/jdk.internal.vm.ci/share/classes/jdk.vm.ci.hotspot/src/jdk/vm/ci/hotspot/HotSpotVMConfigStore.java +++ b/src/jdk.internal.vm.ci/share/classes/jdk.vm.ci.hotspot/src/jdk/vm/ci/hotspot/HotSpotVMConfigStore.java @@ -120,10 +120,10 @@ public List getIntrinsics() { Object[] vmAddressesInfo = (Object[]) data[2]; VMFlag[] vmFlagsInfo = (VMFlag[]) data[3]; - vmFields = new HashMap<>(vmFieldsInfo.length); - vmConstants = new HashMap<>(vmConstantsInfo.length); - vmAddresses = new HashMap<>(vmAddressesInfo.length); - vmFlags = new HashMap<>(vmFlagsInfo.length); + vmFields = HashMap.newHashMap(vmFieldsInfo.length); + vmConstants = HashMap.newHashMap(vmConstantsInfo.length); + vmAddresses = HashMap.newHashMap(vmAddressesInfo.length); + vmFlags = HashMap.newHashMap(vmFlagsInfo.length); vmIntrinsics = Arrays.asList((VMIntrinsicMethod[]) data[4]); // @formatter:on diff --git a/src/jdk.internal.vm.ci/share/classes/jdk.vm.ci.services/src/jdk/vm/ci/services/Services.java b/src/jdk.internal.vm.ci/share/classes/jdk.vm.ci.services/src/jdk/vm/ci/services/Services.java index 9a6774b935f3d..6e19236897bec 100644 --- a/src/jdk.internal.vm.ci/share/classes/jdk.vm.ci.services/src/jdk/vm/ci/services/Services.java +++ b/src/jdk.internal.vm.ci/share/classes/jdk.vm.ci.services/src/jdk/vm/ci/services/Services.java @@ -317,7 +317,7 @@ private static Map deserializeProperties(byte[] serializedProper DataInputStream in = new DataInputStream(new ByteArrayInputStream(serializedProperties)); int utf8Props = in.readInt(); int nonUtf8Props = in.readInt(); - Map props = new HashMap<>(utf8Props + nonUtf8Props); + Map props = HashMap.newHashMap(utf8Props + nonUtf8Props); int index = 0; while (in.available() != 0) { if (index < utf8Props) { diff --git a/src/jdk.jfr/share/classes/jdk/jfr/consumer/MetadataEvent.java b/src/jdk.jfr/share/classes/jdk/jfr/consumer/MetadataEvent.java index b400562d2a4ae..c3b7faa8cce18 100644 --- a/src/jdk.jfr/share/classes/jdk/jfr/consumer/MetadataEvent.java +++ b/src/jdk.jfr/share/classes/jdk/jfr/consumer/MetadataEvent.java @@ -102,7 +102,7 @@ public List getConfigurations() { private void calculateDelta() { List added = new ArrayList<>(); - Map previousSet = new HashMap<>(previous.size()); + Map previousSet = HashMap.newHashMap(previous.size()); for (EventType eventType : previous) { previousSet.put(eventType.getId(), eventType); } diff --git a/src/jdk.jfr/share/classes/jdk/jfr/internal/MetadataLoader.java b/src/jdk.jfr/share/classes/jdk/jfr/internal/MetadataLoader.java index 552b070527e84..97913568e0ada 100644 --- a/src/jdk.jfr/share/classes/jdk/jfr/internal/MetadataLoader.java +++ b/src/jdk.jfr/share/classes/jdk/jfr/internal/MetadataLoader.java @@ -272,7 +272,7 @@ private AnnotationElement newAnnotation(Type type, Object value) { } private Map buildTypeMap() { - Map typeMap = new HashMap<>(2 * types.size()); + Map typeMap = HashMap.newHashMap(2 * types.size()); Map knownTypeMap = new HashMap<>(20); for (Type kt : Type.getKnownTypes()) { typeMap.put(kt.getName(), kt); diff --git a/src/jdk.jfr/share/classes/jdk/jfr/internal/Utils.java b/src/jdk.jfr/share/classes/jdk/jfr/internal/Utils.java index c0324d2d7f6d3..497b3515b7422 100644 --- a/src/jdk.jfr/share/classes/jdk/jfr/internal/Utils.java +++ b/src/jdk.jfr/share/classes/jdk/jfr/internal/Utils.java @@ -462,7 +462,7 @@ static synchronized void setHandler(Class ev } public static Map sanitizeNullFreeStringMap(Map settings) { - HashMap map = new HashMap<>(settings.size()); + HashMap map = HashMap.newHashMap(settings.size()); for (Map.Entry e : settings.entrySet()) { String key = e.getKey(); if (key == null) { diff --git a/src/jdk.management.jfr/share/classes/jdk/management/jfr/ConfigurationInfo.java b/src/jdk.management.jfr/share/classes/jdk/management/jfr/ConfigurationInfo.java index e9f5a7fdfa6e7..bbfa853ab0962 100644 --- a/src/jdk.management.jfr/share/classes/jdk/management/jfr/ConfigurationInfo.java +++ b/src/jdk.management.jfr/share/classes/jdk/management/jfr/ConfigurationInfo.java @@ -73,7 +73,7 @@ private static Map createMap(Object o) { if (o instanceof TabularData) { TabularData td = (TabularData) o; Collection values = td.values(); - Map map = new HashMap<>(values.size()); + Map map = HashMap.newHashMap(values.size()); for (Object value : td.values()) { if (value instanceof CompositeData) { CompositeData cdRow = (CompositeData) value; diff --git a/src/jdk.management/share/classes/com/sun/management/internal/PlatformMBeanProviderImpl.java b/src/jdk.management/share/classes/com/sun/management/internal/PlatformMBeanProviderImpl.java index cddb9127d2e9b..869b02f75db94 100644 --- a/src/jdk.management/share/classes/com/sun/management/internal/PlatformMBeanProviderImpl.java +++ b/src/jdk.management/share/classes/com/sun/management/internal/PlatformMBeanProviderImpl.java @@ -113,7 +113,7 @@ public Map nameToMBeanMap() { if (list.isEmpty()) { map = Collections.emptyMap(); } else { - map = new HashMap<>(list.size()); + map = HashMap.newHashMap(list.size()); for (MemoryManagerMXBean gcm : list) { map.put(gcm.getObjectName().getCanonicalName(), gcm); diff --git a/src/utils/IdealGraphVisualizer/Data/src/main/java/com/sun/hotspot/igv/data/InputGraph.java b/src/utils/IdealGraphVisualizer/Data/src/main/java/com/sun/hotspot/igv/data/InputGraph.java index c218b10002d1a..da05f56749a38 100644 --- a/src/utils/IdealGraphVisualizer/Data/src/main/java/com/sun/hotspot/igv/data/InputGraph.java +++ b/src/utils/IdealGraphVisualizer/Data/src/main/java/com/sun/hotspot/igv/data/InputGraph.java @@ -85,7 +85,7 @@ public List findRootNodes() { } public Map> findAllOutgoingEdges() { - Map> result = new HashMap<>(getNodes().size()); + Map> result = HashMap.newHashMap(getNodes().size()); for(InputNode n : this.getNodes()) { result.put(n, new ArrayList()); } @@ -107,7 +107,7 @@ public Map> findAllOutgoingEdges() { } public Map> findAllIngoingEdges() { - Map> result = new HashMap<>(getNodes().size()); + Map> result = HashMap.newHashMap(getNodes().size()); for(InputNode n : this.getNodes()) { result.put(n, new ArrayList()); } diff --git a/src/utils/IdealGraphVisualizer/Difference/src/main/java/com/sun/hotspot/igv/difference/Difference.java b/src/utils/IdealGraphVisualizer/Difference/src/main/java/com/sun/hotspot/igv/difference/Difference.java index 0b2f01c47e82a..4367b4a18cec4 100644 --- a/src/utils/IdealGraphVisualizer/Difference/src/main/java/com/sun/hotspot/igv/difference/Difference.java +++ b/src/utils/IdealGraphVisualizer/Difference/src/main/java/com/sun/hotspot/igv/difference/Difference.java @@ -55,7 +55,7 @@ public static InputGraph createDiffGraph(InputGraph a, InputGraph b) { } private static InputGraph createDiffSameGroup(InputGraph a, InputGraph b) { - Map keyMapB = new HashMap<>(b.getNodes().size()); + Map keyMapB = HashMap.newHashMap(b.getNodes().size()); for (InputNode n : b.getNodes()) { Integer key = n.getId(); assert !keyMapB.containsKey(key); @@ -108,7 +108,7 @@ private static InputGraph createDiff(InputGraph a, InputGraph b, Set p InputGraph graph = new InputGraph(a.getName() + ", " + b.getName()); g.addElement(graph); - Map blocksMap = new HashMap<>(); + Map blocksMap = HashMap.newHashMap(a.getBlocks().size()); for (InputBlock blk : a.getBlocks()) { InputBlock diffblk = graph.addBlock(blk.getName()); blocksMap.put(blk, diffblk); @@ -151,7 +151,7 @@ private static InputGraph createDiff(InputGraph a, InputGraph b, Set p Set nodesA = new HashSet<>(a.getNodes()); Set nodesB = new HashSet<>(b.getNodes()); - Map inputNodeMap = new HashMap<>(pairs.size()); + Map inputNodeMap = HashMap.newHashMap(pairs.size()); for (NodePair p : pairs) { InputNode n = p.getLeft(); assert nodesA.contains(n); diff --git a/src/utils/IdealGraphVisualizer/Layout/src/main/java/com/sun/hotspot/igv/layout/LayoutGraph.java b/src/utils/IdealGraphVisualizer/Layout/src/main/java/com/sun/hotspot/igv/layout/LayoutGraph.java index 0409aa82d10ff..93fe72922817f 100644 --- a/src/utils/IdealGraphVisualizer/Layout/src/main/java/com/sun/hotspot/igv/layout/LayoutGraph.java +++ b/src/utils/IdealGraphVisualizer/Layout/src/main/java/com/sun/hotspot/igv/layout/LayoutGraph.java @@ -46,9 +46,9 @@ public LayoutGraph(Set links, Set additionalVe assert verify(); vertices = new TreeSet<>(); - portLinks = new HashMap<>(links.size()); - inputPorts = new HashMap<>(links.size()); - outputPorts = new HashMap<>(links.size()); + portLinks = HashMap.newHashMap(links.size()); + inputPorts = HashMap.newHashMap(links.size()); + outputPorts = HashMap.newHashMap(links.size()); for (Link l : links) { if (l.getFrom() == null || l.getTo() == null) { diff --git a/src/utils/IdealGraphVisualizer/ServerCompiler/src/main/java/com/sun/hotspot/igv/servercompiler/ServerCompilerScheduler.java b/src/utils/IdealGraphVisualizer/ServerCompiler/src/main/java/com/sun/hotspot/igv/servercompiler/ServerCompilerScheduler.java index 09ef77818e919..aafc87ad93abb 100644 --- a/src/utils/IdealGraphVisualizer/ServerCompiler/src/main/java/com/sun/hotspot/igv/servercompiler/ServerCompilerScheduler.java +++ b/src/utils/IdealGraphVisualizer/ServerCompiler/src/main/java/com/sun/hotspot/igv/servercompiler/ServerCompilerScheduler.java @@ -233,7 +233,7 @@ public void buildBlocks() { // Compute block index map for dominator computation. int z = 0; - blockIndex = new HashMap<>(blocks.size()); + blockIndex = HashMap.newHashMap(blocks.size()); for (InputBlock b : blocks) { blockIndex.put(b, z); z++; @@ -262,7 +262,7 @@ public Collection schedule(InputGraph graph) { return graph.getBlocks(); } else { nodes = new ArrayList<>(); - inputNodeToNode = new HashMap<>(graph.getNodes().size()); + inputNodeToNode = HashMap.newHashMap(graph.getNodes().size()); this.graph = graph; if (!hasCategoryInformation()) { @@ -538,7 +538,7 @@ public InputBlock getCommonDominator(int a, int b) { } public void buildDominators() { - dominatorMap = new HashMap<>(graph.getBlocks().size()); + dominatorMap = HashMap.newHashMap(graph.getBlocks().size()); if (blocks.size() == 0) { return; } @@ -636,7 +636,7 @@ public void buildUpGraph() { inputNodeToNode.put(n, node); } - Map> edgeMap = new HashMap<>(graph.getEdges().size()); + Map> edgeMap = HashMap.newHashMap(graph.getEdges().size()); for (InputEdge e : graph.getEdges()) { int to = e.getTo(); diff --git a/src/utils/IdealGraphVisualizer/View/src/main/java/com/sun/hotspot/igv/view/DiagramScene.java b/src/utils/IdealGraphVisualizer/View/src/main/java/com/sun/hotspot/igv/view/DiagramScene.java index 703cbe6e6180b..5a133824e66e5 100644 --- a/src/utils/IdealGraphVisualizer/View/src/main/java/com/sun/hotspot/igv/view/DiagramScene.java +++ b/src/utils/IdealGraphVisualizer/View/src/main/java/com/sun/hotspot/igv/view/DiagramScene.java @@ -836,7 +836,7 @@ private void relayoutWithoutLayout(Set oldVisibleWidgets) { private final Point specialNullPoint = new Point(Integer.MAX_VALUE, Integer.MAX_VALUE); private void processOutputSlot(Set> lastLineCache, OutputSlot s, List connections, int controlPointIndex, Point lastPoint, LineWidget predecessor, int offx, int offy, SceneAnimator animator) { - Map> pointMap = new HashMap<>(connections.size()); + Map> pointMap = HashMap.newHashMap(connections.size()); for (Connection c : connections) { From ec0b08cf150dc7ccf5be90fccd248fafc44e014c Mon Sep 17 00:00:00 2001 From: XenoAmess Date: Sun, 3 Apr 2022 06:23:06 +0800 Subject: [PATCH 11/26] update usages of LinkedHashMap --- src/java.base/share/classes/java/lang/Class.java | 4 ++-- .../share/classes/java/lang/invoke/MethodHandleImpl.java | 2 +- src/java.base/share/classes/java/util/HashSet.java | 2 +- src/java.base/share/classes/java/util/jar/Attributes.java | 4 ++-- .../share/classes/sun/util/resources/TimeZoneNamesBundle.java | 2 +- src/jdk.jfr/share/classes/jdk/jfr/EventType.java | 2 +- .../share/classes/jdk/jfr/internal/MetadataWriter.java | 2 +- .../share/classes/jdk/jfr/internal/SettingsManager.java | 2 +- src/jdk.zipfs/share/classes/jdk/nio/zipfs/ZipFileSystem.java | 2 +- 9 files changed, 11 insertions(+), 11 deletions(-) diff --git a/src/java.base/share/classes/java/lang/Class.java b/src/java.base/share/classes/java/lang/Class.java index 76428a9b92131..a55f4ced30900 100644 --- a/src/java.base/share/classes/java/lang/Class.java +++ b/src/java.base/share/classes/java/lang/Class.java @@ -4125,10 +4125,10 @@ private AnnotationData createAnnotationData(int classRedefinedCount) { Class annotationClass = e.getKey(); if (AnnotationType.getInstance(annotationClass).isInherited()) { if (annotations == null) { // lazy construction - annotations = new LinkedHashMap<>((Math.max( + annotations = LinkedHashMap.newLinkedHashMap(Math.max( declaredAnnotations.size(), Math.min(12, declaredAnnotations.size() + superAnnotations.size()) - ) * 4 + 2) / 3 + ) ); } annotations.put(annotationClass, e.getValue()); diff --git a/src/java.base/share/classes/java/lang/invoke/MethodHandleImpl.java b/src/java.base/share/classes/java/lang/invoke/MethodHandleImpl.java index 27176314b25d9..b1d867d3f7b2c 100644 --- a/src/java.base/share/classes/java/lang/invoke/MethodHandleImpl.java +++ b/src/java.base/share/classes/java/lang/invoke/MethodHandleImpl.java @@ -290,7 +290,7 @@ static MethodHandle makePairwiseConvertByEditor(MethodHandle target, MethodType BoundMethodHandle mh = target.rebind(); // Match each unique conversion to the positions at which it is to be applied - var convSpecMap = new HashMap(((4 * convCount) / 3) + 1); + HashMap convSpecMap = HashMap.newHashMap(convCount); for (int i = 0; i < convSpecs.length - MH_RECEIVER_OFFSET; i++) { Object convSpec = convSpecs[i]; if (convSpec == null) continue; diff --git a/src/java.base/share/classes/java/util/HashSet.java b/src/java.base/share/classes/java/util/HashSet.java index 3e87b4455ba45..6dbc22f1ea9fa 100644 --- a/src/java.base/share/classes/java/util/HashSet.java +++ b/src/java.base/share/classes/java/util/HashSet.java @@ -117,7 +117,7 @@ public HashSet() { * @throws NullPointerException if the specified collection is null */ public HashSet(Collection c) { - map = new HashMap<>(Math.max((int) (c.size()/.75f) + 1, 16)); + map = HashMap.newHashMap(Math.max(c.size(), 12)); addAll(c); } diff --git a/src/java.base/share/classes/java/util/jar/Attributes.java b/src/java.base/share/classes/java/util/jar/Attributes.java index 3b59f74275fd6..73618a4f332aa 100644 --- a/src/java.base/share/classes/java/util/jar/Attributes.java +++ b/src/java.base/share/classes/java/util/jar/Attributes.java @@ -69,7 +69,7 @@ public class Attributes implements Map, Cloneable { * Constructs a new, empty Attributes object with default size. */ public Attributes() { - this(11); + this(16); } /** @@ -79,7 +79,7 @@ public Attributes() { * @param size the initial number of attributes */ public Attributes(int size) { - map = new LinkedHashMap<>(size); + map = LinkedHashMap.newLinkedHashMap(size); } /** diff --git a/src/java.base/share/classes/sun/util/resources/TimeZoneNamesBundle.java b/src/java.base/share/classes/sun/util/resources/TimeZoneNamesBundle.java index 8a6fd8c52fd95..6495a5fba5484 100644 --- a/src/java.base/share/classes/sun/util/resources/TimeZoneNamesBundle.java +++ b/src/java.base/share/classes/sun/util/resources/TimeZoneNamesBundle.java @@ -96,7 +96,7 @@ public Object handleGetObject(String key) { */ @Override protected Map createMap(int size) { - return new LinkedHashMap<>(size); + return LinkedHashMap.newLinkedHashMap(size); } /** diff --git a/src/jdk.jfr/share/classes/jdk/jfr/EventType.java b/src/jdk.jfr/share/classes/jdk/jfr/EventType.java index 3d069fe8e396c..9835056fb22a5 100644 --- a/src/jdk.jfr/share/classes/jdk/jfr/EventType.java +++ b/src/jdk.jfr/share/classes/jdk/jfr/EventType.java @@ -78,7 +78,7 @@ public ValueDescriptor getField(String name) { Objects.requireNonNull(name, "name"); if (cache == null) { List fields = getFields(); - Map newCache = new LinkedHashMap<>(fields.size()); + Map newCache = LinkedHashMap.newLinkedHashMap(fields.size()); for (ValueDescriptor v :fields) { newCache.put(v.getName(), v); } diff --git a/src/jdk.jfr/share/classes/jdk/jfr/internal/MetadataWriter.java b/src/jdk.jfr/share/classes/jdk/jfr/internal/MetadataWriter.java index 149bc1795a9aa..a8d5333f934a5 100644 --- a/src/jdk.jfr/share/classes/jdk/jfr/internal/MetadataWriter.java +++ b/src/jdk.jfr/share/classes/jdk/jfr/internal/MetadataWriter.java @@ -80,7 +80,7 @@ public void writeBinary(DataOutput output) throws IOException { // Possible improvement, sort string by how often they occur. // and assign low number to the most frequently used. buildStringPool(root, stringPool); - HashMap lookup = new LinkedHashMap<>(stringPool.size()); + HashMap lookup = LinkedHashMap.newLinkedHashMap(stringPool.size()); int index = 0; int poolSize = stringPool.size(); writeInt(output, poolSize); diff --git a/src/jdk.jfr/share/classes/jdk/jfr/internal/SettingsManager.java b/src/jdk.jfr/share/classes/jdk/jfr/internal/SettingsManager.java index d6078ef9f985e..d5b17b5640492 100644 --- a/src/jdk.jfr/share/classes/jdk/jfr/internal/SettingsManager.java +++ b/src/jdk.jfr/share/classes/jdk/jfr/internal/SettingsManager.java @@ -172,7 +172,7 @@ public void updateRetransform(List> ev } private Map createSettingsMap(List> activeSettings) { - Map map = new LinkedHashMap<>(activeSettings.size()); + Map map = LinkedHashMap.newLinkedHashMap(activeSettings.size()); for (Map rec : activeSettings) { for (InternalSetting internal : makeInternalSettings(rec)) { InternalSetting is = map.get(internal.getSettingsId()); diff --git a/src/jdk.zipfs/share/classes/jdk/nio/zipfs/ZipFileSystem.java b/src/jdk.zipfs/share/classes/jdk/nio/zipfs/ZipFileSystem.java index dd85df4cc609e..c78101e6e86f8 100644 --- a/src/jdk.zipfs/share/classes/jdk/nio/zipfs/ZipFileSystem.java +++ b/src/jdk.zipfs/share/classes/jdk/nio/zipfs/ZipFileSystem.java @@ -1561,7 +1561,7 @@ private byte[] initCEN() throws IOException { throw new ZipException("read CEN tables failed"); } // Iterate through the entries in the central directory - inodes = new LinkedHashMap<>(end.centot + 1); + inodes = LinkedHashMap.newLinkedHashMap(end.centot + 1); int pos = 0; int limit = cen.length - ENDHDR; while (pos < limit) { From 796975b093bc6fe9fe7aa5c72e7e26e693c2a6c6 Mon Sep 17 00:00:00 2001 From: XenoAmess Date: Sun, 3 Apr 2022 06:41:57 +0800 Subject: [PATCH 12/26] revert changes in jdk.compile --- .../share/classes/com/sun/tools/javac/comp/Operators.java | 4 ++-- .../tools/javac/processing/JavacProcessingEnvironment.java | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/jdk.compiler/share/classes/com/sun/tools/javac/comp/Operators.java b/src/jdk.compiler/share/classes/com/sun/tools/javac/comp/Operators.java index 23fd6b4827994..6ca0578339d3c 100644 --- a/src/jdk.compiler/share/classes/com/sun/tools/javac/comp/Operators.java +++ b/src/jdk.compiler/share/classes/com/sun/tools/javac/comp/Operators.java @@ -74,10 +74,10 @@ public class Operators { private final Types types; /** Unary operators map. */ - private Map> unaryOperators = HashMap.newHashMap(Tag.getNumberOfOperators()); + private Map> unaryOperators = new HashMap<>(Tag.getNumberOfOperators()); /** Binary operators map. */ - private Map> binaryOperators = HashMap.newHashMap(Tag.getNumberOfOperators()); + private Map> binaryOperators = new HashMap<>(Tag.getNumberOfOperators()); /** The names of all operators. */ private Name[] opname = new Name[Tag.getNumberOfOperators()]; diff --git a/src/jdk.compiler/share/classes/com/sun/tools/javac/processing/JavacProcessingEnvironment.java b/src/jdk.compiler/share/classes/com/sun/tools/javac/processing/JavacProcessingEnvironment.java index ee096a78877f6..9174f0b7385dc 100644 --- a/src/jdk.compiler/share/classes/com/sun/tools/javac/processing/JavacProcessingEnvironment.java +++ b/src/jdk.compiler/share/classes/com/sun/tools/javac/processing/JavacProcessingEnvironment.java @@ -884,7 +884,7 @@ private void discoverAndRunProcs(Set annotationsPresent, List topLevelClasses, List packageInfoFiles, List moduleInfoFiles) { - Map unmatchedAnnotations = HashMap.newHashMap(annotationsPresent.size()); + Map unmatchedAnnotations = new HashMap<>(annotationsPresent.size()); for(TypeElement a : annotationsPresent) { ModuleElement mod = elementUtils.getModuleOf(a); From e548cd6d7dac2edd58d7c522168f066d104e579f Mon Sep 17 00:00:00 2001 From: XenoAmess Date: Wed, 6 Apr 2022 23:50:02 +0800 Subject: [PATCH 13/26] refine javadoc for LinkedHashMap#newLinkedHashMap --- src/java.base/share/classes/java/util/LinkedHashMap.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/java.base/share/classes/java/util/LinkedHashMap.java b/src/java.base/share/classes/java/util/LinkedHashMap.java index 13ef1ba65f741..555bf110a77fb 100644 --- a/src/java.base/share/classes/java/util/LinkedHashMap.java +++ b/src/java.base/share/classes/java/util/LinkedHashMap.java @@ -789,7 +789,7 @@ final class LinkedEntryIterator extends LinkedHashIterator } /** - * Creates a new, empty LinkedHashMap suitable for the expected number of mappings. + * Creates a new, empty, insertion-ordered LinkedHashMap suitable for the expected number of mappings. * The returned map uses the default load factor of 0.75, and its initial capacity is * generally large enough so that the expected number of mappings can be added * without resizing the map. From 4769b87b1819c844c4dfb31dceaf58e4b2439cd8 Mon Sep 17 00:00:00 2001 From: XenoAmess Date: Wed, 6 Apr 2022 23:51:58 +0800 Subject: [PATCH 14/26] drop CalculateHashMapCapacityTestJMH --- .../CalculateHashMapCapacityTestJMH.java | 115 ------------------ 1 file changed, 115 deletions(-) delete mode 100644 test/jdk/java/util/Collections/CalculateHashMapCapacityTestJMH.java diff --git a/test/jdk/java/util/Collections/CalculateHashMapCapacityTestJMH.java b/test/jdk/java/util/Collections/CalculateHashMapCapacityTestJMH.java deleted file mode 100644 index 3ee9a480a3f12..0000000000000 --- a/test/jdk/java/util/Collections/CalculateHashMapCapacityTestJMH.java +++ /dev/null @@ -1,115 +0,0 @@ -/* - * Copyright (c) 1997, 2021, 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. Oracle designates this - * particular file as subject to the "Classpath" exception as provided - * by Oracle in the LICENSE file that accompanied this code. - * - * 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. - */ - -import org.openjdk.jmh.annotations.Benchmark; -import org.openjdk.jmh.annotations.BenchmarkMode; -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; -import org.openjdk.jmh.infra.Blackhole; - -import java.util.concurrent.TimeUnit; - -@State(Scope.Thread) -@BenchmarkMode(Mode.Throughput) -@OutputTimeUnit(TimeUnit.SECONDS) -public class CalculateHashMapCapacityTestJMH { - - /** - * Calculate initial capacity for HashMap based classes, from expected size. - * - * @param expectedSize expected size - * @return initial capacity for HashMap based classes. - * @since 19 - */ - private static int calculateHashMapCapacity1(int expectedSize) { - return (int) Math.ceil(expectedSize / 0.75); - } - - /** - * Calculate initial capacity for HashMap based classes, from expected size. - * - * @param expectedSize expected size - * @return initial capacity for HashMap based classes. - * @since 19 - */ - private static int calculateHashMapCapacity2(int expectedSize) { - if (expectedSize >= Integer.MAX_VALUE / 4 * 3 + 3) { - return Integer.MAX_VALUE; - } - if (expectedSize > 0) { - return (expectedSize + (expectedSize + 2) / 3); - } - return expectedSize; - } - - /** - * Calculate initial capacity for HashMap based classes, from expected size. - * - * @param expectedSize expected size - * @return initial capacity for HashMap based classes. - * @since 19 - */ - private static int calculateHashMapCapacity3(int expectedSize) { - if (expectedSize >= 805306368) { - return (1 << 30); - } - if (expectedSize > 0) { - return (expectedSize + (expectedSize + 2) / 3); - } - return expectedSize; - } - - @Warmup(iterations = 20) - @Measurement(iterations = 10) - @Benchmark - public void testCalculateHashMapCapacity1(Blackhole blackhole) { - for (int i = 0; i < Integer.MAX_VALUE; i++) { - blackhole.consume(calculateHashMapCapacity1(i)); - } - } - - @Warmup(iterations = 20) - @Measurement(iterations = 10) - @Benchmark - public void testCalculateHashMapCapacity2(Blackhole blackhole) { - for (int i = 0; i < Integer.MAX_VALUE; i++) { - blackhole.consume(calculateHashMapCapacity2(i)); - } - } - - @Warmup(iterations = 20) - @Measurement(iterations = 10) - @Benchmark - public void testCalculateHashMapCapacity3(Blackhole blackhole) { - for (int i = 0; i < Integer.MAX_VALUE; i++) { - blackhole.consume(calculateHashMapCapacity3(i)); - } - } - -} From b973ee513a28986443a9eb42a3940b03ee4af4f0 Mon Sep 17 00:00:00 2001 From: XenoAmess Date: Wed, 6 Apr 2022 23:57:44 +0800 Subject: [PATCH 15/26] use (double) DEFAULT_LOAD_FACTOR instead of 0.75 --- src/java.base/share/classes/java/util/HashMap.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/java.base/share/classes/java/util/HashMap.java b/src/java.base/share/classes/java/util/HashMap.java index e2003962c4b20..a1efc828ee412 100644 --- a/src/java.base/share/classes/java/util/HashMap.java +++ b/src/java.base/share/classes/java/util/HashMap.java @@ -2553,7 +2553,7 @@ static boolean checkInvariants(TreeNode t) { * @since 19 */ static int calculateHashMapCapacity(int numMappings) { - return (int) Math.ceil(numMappings / 0.75); + return (int) Math.ceil(numMappings / (double) DEFAULT_LOAD_FACTOR); } /** From bdf47f32d8399329783aa0ea5e0ff6fa811ee03c Mon Sep 17 00:00:00 2001 From: XenoAmess Date: Mon, 11 Apr 2022 01:29:36 +0800 Subject: [PATCH 16/26] variable nameToReferenceSize rename to moduleCount --- .../share/classes/java/lang/module/Resolver.java | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/java.base/share/classes/java/lang/module/Resolver.java b/src/java.base/share/classes/java/lang/module/Resolver.java index 3db279c124ac1..0973615442c02 100644 --- a/src/java.base/share/classes/java/lang/module/Resolver.java +++ b/src/java.base/share/classes/java/lang/module/Resolver.java @@ -498,11 +498,11 @@ private void checkHashes() { */ private Map> makeGraph(Configuration cf) { - int nameToReferenceSize = nameToReference.size(); + int moduleCount = nameToReference.size(); // the "reads" graph starts as a module dependence graph and // is iteratively updated to be the readability graph - Map> g1 = HashMap.newHashMap(nameToReferenceSize); + Map> g1 = HashMap.newHashMap(moduleCount); // the "requires transitive" graph, contains requires transitive edges only Map> g2; @@ -511,7 +511,7 @@ private Map> makeGraph(Configuration cf) { // as there may be selected modules that have a dependency on modules in // the parent configuration. if (ModuleLayer.boot() == null) { - g2 = HashMap.newHashMap(nameToReferenceSize); + g2 = HashMap.newHashMap(moduleCount); } else { g2 = parents.stream() .flatMap(Configuration::configurations) @@ -538,7 +538,7 @@ private Map> makeGraph(Configuration cf) { // populate g1 and g2 with the dependences from the selected modules - Map nameToResolved = HashMap.newHashMap(nameToReferenceSize); + Map nameToResolved = HashMap.newHashMap(moduleCount); for (ModuleReference mref : nameToReference.values()) { ModuleDescriptor descriptor = mref.descriptor(); From 5801dc73bcce8612fc3388d8fec1df85b764686e Mon Sep 17 00:00:00 2001 From: Stuart Marks Date: Tue, 12 Apr 2022 20:26:12 -0700 Subject: [PATCH 17/26] Minor adjustment to test cases of WhiteBoxResizeTest --- .../java/util/HashMap/WhiteBoxResizeTest.java | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/test/jdk/java/util/HashMap/WhiteBoxResizeTest.java b/test/jdk/java/util/HashMap/WhiteBoxResizeTest.java index ad02b3000e218..5dfa928b9b231 100644 --- a/test/jdk/java/util/HashMap/WhiteBoxResizeTest.java +++ b/test/jdk/java/util/HashMap/WhiteBoxResizeTest.java @@ -201,7 +201,7 @@ public void defaultCapacity(Supplier> s) { @DataProvider(name = "requestedCapacity") public Iterator requestedCapacityCases() { ArrayList cases = new ArrayList<>(); - for (int i = 2; i < 128; i++) { + for (int i = 2; i < 64; i++) { int cap = i; cases.add(new Object[]{"rhm1", cap, (Supplier>) () -> new HashMap<>(cap)}); cases.add(new Object[]{"rhm2", cap, (Supplier>) () -> new HashMap<>(cap, 0.75f)}); @@ -280,7 +280,7 @@ List genFakePopulatedCapacityCases(int size, int cap) { pcc("flm2pa", size, cap, () -> new LinkedHashMap<>(cap, 0.75f), map -> { map.putAll(fakeMap(size)); }), pcc("fwmcpy", size, cap, () -> new WeakHashMap<>(fakeMap(size)), map -> { }), - // pcc("fwm0pa", size, cap, () -> new WeakHashMap<>(), map -> { map.putAll(fakeMap(size)); }), // see note + // pcc("fwm0pa", size, cap, () -> new WeakHashMap<>(), map -> { map.putAll(fakeMap(size)); }), // see note pcc("fwm1pa", size, cap, () -> new WeakHashMap<>(cap), map -> { map.putAll(fakeMap(size)); }), pcc("fwm2pa", size, cap, () -> new WeakHashMap<>(cap, 0.75f), map -> { map.putAll(fakeMap(size)); }) ); @@ -292,16 +292,19 @@ List genFakePopulatedCapacityCases(int size, int cap) { @DataProvider(name = "populatedCapacity") public Iterator populatedCapacityCases() { ArrayList cases = new ArrayList<>(); - cases.addAll(genPopulatedCapacityCases(11, 16)); cases.addAll(genPopulatedCapacityCases(12, 16)); cases.addAll(genPopulatedCapacityCases(13, 32)); - cases.addAll(genPopulatedCapacityCases(64, 128)); + cases.addAll(genPopulatedCapacityCases(24, 32)); + cases.addAll(genPopulatedCapacityCases(25, 64)); + cases.addAll(genPopulatedCapacityCases(48, 64)); + cases.addAll(genPopulatedCapacityCases(49, 128)); // numbers in this range are truncated by a float computation with 0.75f // but can get an exact result with a double computation with 0.75d - cases.addAll(genFakePopulatedCapacityCases(25165824, 33554432)); - cases.addAll(genFakePopulatedCapacityCases(25165825, 67108864)); - cases.addAll(genFakePopulatedCapacityCases(25165826, 67108864)); + cases.addAll(genFakePopulatedCapacityCases(25165824, 33554432)); + cases.addAll(genFakePopulatedCapacityCases(25165825, 67108864)); + cases.addAll(genFakePopulatedCapacityCases(50331648, 67108864)); + cases.addAll(genFakePopulatedCapacityCases(50331649, 134217728)); return cases.iterator(); } From 2f6f8f44a80250094783974c6a97f4effbe9fc6b Mon Sep 17 00:00:00 2001 From: Stuart Marks Date: Tue, 12 Apr 2022 20:42:42 -0700 Subject: [PATCH 18/26] Add test cases for static factory methods. --- .../java/util/HashMap/WhiteBoxResizeTest.java | 51 ++++++++++++++++++- 1 file changed, 50 insertions(+), 1 deletion(-) diff --git a/test/jdk/java/util/HashMap/WhiteBoxResizeTest.java b/test/jdk/java/util/HashMap/WhiteBoxResizeTest.java index 5dfa928b9b231..4b70d8e802ddc 100644 --- a/test/jdk/java/util/HashMap/WhiteBoxResizeTest.java +++ b/test/jdk/java/util/HashMap/WhiteBoxResizeTest.java @@ -48,7 +48,7 @@ /* * @test - * @bug 8210280 8281631 + * @bug 8186958 8210280 8281631 * @modules java.base/java.util:open * @summary White box tests for HashMap-related internals around table sizing * @run testng WhiteBoxResizeTest @@ -320,4 +320,53 @@ public void populatedCapacity(String label, // unused, included for diagnostics assertEquals(capacity(map), expectedCapacity); } + /* + * tests for requested size (static factory methods) + */ + + // helper method for one requested size case, to provide target types for lambda + Object[] rsc(String label, + int size, + int expectedCapacity, + Supplier> supplier) { + return new Object[]{label, size, expectedCapacity, supplier}; + } + + List genRequestedSizeCases(int size, int cap) { + return Arrays.asList( + rsc("rshm", size, cap, () -> HashMap.newHashMap(size)), + rsc("rslm", size, cap, () -> LinkedHashMap.newLinkedHashMap(size)), + rsc("rswm", size, cap, () -> WeakHashMap.newWeakHashMap(size)) + ); + } + + @DataProvider(name = "requestedSize") + public Iterator requestedSizeCases() { + ArrayList cases = new ArrayList<>(); + cases.addAll(genRequestedSizeCases(12, 16)); + cases.addAll(genRequestedSizeCases(13, 32)); + cases.addAll(genRequestedSizeCases(24, 32)); + cases.addAll(genRequestedSizeCases(25, 64)); + cases.addAll(genRequestedSizeCases(48, 64)); + cases.addAll(genRequestedSizeCases(49, 128)); + + // numbers in this range are truncated by a float computation with 0.75f + // but can get an exact result with a double computation with 0.75d + cases.addAll(genRequestedSizeCases(25165824, 33554432)); + cases.addAll(genRequestedSizeCases(25165825, 67108864)); + cases.addAll(genRequestedSizeCases(50331648, 67108864)); + cases.addAll(genRequestedSizeCases(50331649, 134217728)); + + return cases.iterator(); + } + + @Test(dataProvider = "requestedSize") + public void requestedSize(String label, // unused, included for diagnostics + int size, // unused, included for diagnostics + int expectedCapacity, + Supplier> s) { + Map map = s.get(); + map.put("", ""); + assertEquals(capacity(map), expectedCapacity); + } } From ab8fbb832e4d9c8e552a9a601bc82a73a18009fb Mon Sep 17 00:00:00 2001 From: Stuart Marks Date: Tue, 12 Apr 2022 20:53:58 -0700 Subject: [PATCH 19/26] Add apiNote to appropriate constructors of HM, LHM, and WHM. --- src/java.base/share/classes/java/util/HashMap.java | 8 ++++++++ src/java.base/share/classes/java/util/LinkedHashMap.java | 8 ++++++++ src/java.base/share/classes/java/util/WeakHashMap.java | 8 ++++++++ 3 files changed, 24 insertions(+) diff --git a/src/java.base/share/classes/java/util/HashMap.java b/src/java.base/share/classes/java/util/HashMap.java index a1efc828ee412..f6c77a494c318 100644 --- a/src/java.base/share/classes/java/util/HashMap.java +++ b/src/java.base/share/classes/java/util/HashMap.java @@ -433,6 +433,10 @@ static final int tableSizeFor(int cap) { * Constructs an empty {@code HashMap} with the specified initial * capacity and load factor. * + * @apiNote + * To create a {@code HashMap} with an initial capacity that accommodates + * an expected number of mappings, use {@link #newHashMap(int) newHashMap}. + * * @param initialCapacity the initial capacity * @param loadFactor the load factor * @throws IllegalArgumentException if the initial capacity is negative @@ -455,6 +459,10 @@ public HashMap(int initialCapacity, float loadFactor) { * Constructs an empty {@code HashMap} with the specified initial * capacity and the default load factor (0.75). * + * @apiNote + * To create a {@code HashMap} with an initial capacity that accommodates + * an expected number of mappings, use {@link #newHashMap(int) newHashMap}. + * * @param initialCapacity the initial capacity. * @throws IllegalArgumentException if the initial capacity is negative. */ diff --git a/src/java.base/share/classes/java/util/LinkedHashMap.java b/src/java.base/share/classes/java/util/LinkedHashMap.java index 555bf110a77fb..b2b7536f06505 100644 --- a/src/java.base/share/classes/java/util/LinkedHashMap.java +++ b/src/java.base/share/classes/java/util/LinkedHashMap.java @@ -339,6 +339,10 @@ void internalWriteEntries(java.io.ObjectOutputStream s) throws IOException { * Constructs an empty insertion-ordered {@code LinkedHashMap} instance * with the specified initial capacity and load factor. * + * @apiNote + * To create a {@code LinkedHashMap} with an initial capacity that accommodates + * an expected number of mappings, use {@link #newLinkedHashMap(int) newLinkedHashMap}. + * * @param initialCapacity the initial capacity * @param loadFactor the load factor * @throws IllegalArgumentException if the initial capacity is negative @@ -353,6 +357,10 @@ public LinkedHashMap(int initialCapacity, float loadFactor) { * Constructs an empty insertion-ordered {@code LinkedHashMap} instance * with the specified initial capacity and a default load factor (0.75). * + * @apiNote + * To create a {@code LinkedHashMap} with an initial capacity that accommodates + * an expected number of mappings, use {@link #newLinkedHashMap(int) newLinkedHashMap}. + * * @param initialCapacity the initial capacity * @throws IllegalArgumentException if the initial capacity is negative */ diff --git a/src/java.base/share/classes/java/util/WeakHashMap.java b/src/java.base/share/classes/java/util/WeakHashMap.java index 557d9fa2979a7..68727d53b8ae4 100644 --- a/src/java.base/share/classes/java/util/WeakHashMap.java +++ b/src/java.base/share/classes/java/util/WeakHashMap.java @@ -198,6 +198,10 @@ private Entry[] newTable(int n) { * Constructs a new, empty {@code WeakHashMap} with the given initial * capacity and the given load factor. * + * @apiNote + * To create a {@code WeakHashMap} with an initial capacity that accommodates + * an expected number of mappings, use {@link #newWeakHashMap(int) newWeakHashMap}. + * * @param initialCapacity The initial capacity of the {@code WeakHashMap} * @param loadFactor The load factor of the {@code WeakHashMap} * @throws IllegalArgumentException if the initial capacity is negative, @@ -223,6 +227,10 @@ public WeakHashMap(int initialCapacity, float loadFactor) { * Constructs a new, empty {@code WeakHashMap} with the given initial * capacity and the default load factor (0.75). * + * @apiNote + * To create a {@code WeakHashMap} with an initial capacity that accommodates + * an expected number of mappings, use {@link #newWeakHashMap(int) newWeakHashMap}. + * * @param initialCapacity The initial capacity of the {@code WeakHashMap} * @throws IllegalArgumentException if the initial capacity is negative */ From 2f5617bb4dac0513984ac119d54d9f9198bedf58 Mon Sep 17 00:00:00 2001 From: XenoAmess Date: Thu, 14 Apr 2022 00:19:26 +0800 Subject: [PATCH 20/26] revert changes in: src/java.desktop src/java.management src/jdk.internal.vm.ci src/jdk.jfr src/jdk.management.jfr src/jdk.management src/utils/IdealGraphVisualizer --- .../com/sun/java/swing/plaf/gtk/GTKLookAndFeel.java | 2 +- .../share/classes/java/beans/MetaData.java | 2 +- .../classes/sun/awt/datatransfer/DataTransferer.java | 10 +++++----- .../lang/management/DefaultPlatformMBeanProvider.java | 6 +++--- .../share/classes/sun/management/HotspotThread.java | 2 +- .../src/jdk/vm/ci/hotspot/HotSpotVMConfigStore.java | 8 ++++---- .../src/jdk/vm/ci/services/Services.java | 2 +- src/jdk.jfr/share/classes/jdk/jfr/EventType.java | 2 +- .../share/classes/jdk/jfr/consumer/MetadataEvent.java | 2 +- .../share/classes/jdk/jfr/internal/MetadataLoader.java | 2 +- .../share/classes/jdk/jfr/internal/MetadataWriter.java | 2 +- .../classes/jdk/jfr/internal/SettingsManager.java | 2 +- src/jdk.jfr/share/classes/jdk/jfr/internal/Utils.java | 2 +- .../classes/jdk/management/jfr/ConfigurationInfo.java | 2 +- .../management/internal/PlatformMBeanProviderImpl.java | 2 +- .../main/java/com/sun/hotspot/igv/data/InputGraph.java | 4 ++-- .../com/sun/hotspot/igv/difference/Difference.java | 6 +++--- .../java/com/sun/hotspot/igv/layout/LayoutGraph.java | 6 +++--- .../igv/servercompiler/ServerCompilerScheduler.java | 6 +++--- .../java/com/sun/hotspot/igv/view/DiagramScene.java | 2 +- 20 files changed, 36 insertions(+), 36 deletions(-) diff --git a/src/java.desktop/share/classes/com/sun/java/swing/plaf/gtk/GTKLookAndFeel.java b/src/java.desktop/share/classes/com/sun/java/swing/plaf/gtk/GTKLookAndFeel.java index 84482d5d6da1c..40d713123c734 100644 --- a/src/java.desktop/share/classes/com/sun/java/swing/plaf/gtk/GTKLookAndFeel.java +++ b/src/java.desktop/share/classes/com/sun/java/swing/plaf/gtk/GTKLookAndFeel.java @@ -1445,7 +1445,7 @@ public void initialize() { * XRender. */ gtkAAFontSettingsCond = SwingUtilities2.isLocalDisplay(); - aaTextInfo = HashMap.newHashMap(2); + aaTextInfo = new HashMap<>(2); SwingUtilities2.putAATextInfo(gtkAAFontSettingsCond, aaTextInfo); } diff --git a/src/java.desktop/share/classes/java/beans/MetaData.java b/src/java.desktop/share/classes/java/beans/MetaData.java index 7d67ff426ca20..52237b15792ad 100644 --- a/src/java.desktop/share/classes/java/beans/MetaData.java +++ b/src/java.desktop/share/classes/java/beans/MetaData.java @@ -653,7 +653,7 @@ protected Expression instantiate(Object oldInstance, Encoder out) { int size = 12; Map basic = font.getAttributes(); - Map clone = HashMap.newHashMap(basic.size()); + Map clone = new HashMap<>(basic.size()); for (TextAttribute key : basic.keySet()) { Object value = basic.get(key); if (value != null) { diff --git a/src/java.desktop/share/classes/sun/awt/datatransfer/DataTransferer.java b/src/java.desktop/share/classes/sun/awt/datatransfer/DataTransferer.java index 5cc186bfd907a..8ca34787e1958 100644 --- a/src/java.desktop/share/classes/sun/awt/datatransfer/DataTransferer.java +++ b/src/java.desktop/share/classes/sun/awt/datatransfer/DataTransferer.java @@ -329,13 +329,13 @@ public SortedMap getFormatsForTransferable(Transferable content public SortedMap getFormatsForFlavors(DataFlavor[] flavors, FlavorTable map) { - Map formatMap = HashMap.newHashMap(flavors.length); - Map textPlainMap = HashMap.newHashMap(flavors.length); + Map formatMap = new HashMap<>(flavors.length); + Map textPlainMap = new HashMap<>(flavors.length); // Maps formats to indices that will be used to sort the formats // according to the preference order. // Larger index value corresponds to the more preferable format. - Map indexMap = HashMap.newHashMap(flavors.length); - Map textPlainIndexMap = HashMap.newHashMap(flavors.length); + Map indexMap = new HashMap<>(flavors.length); + Map textPlainIndexMap = new HashMap<>(flavors.length); int currentIndex = 0; @@ -409,7 +409,7 @@ public long[] getFormatsForTransferableAsArray(Transferable contents, * when converting to the DataFlavor. */ public Map getFlavorsForFormats(long[] formats, FlavorTable map) { - Map flavorMap = HashMap.newHashMap(formats.length); + Map flavorMap = new HashMap<>(formats.length); Set> mappingSet = new HashSet<>(formats.length); Set flavorSet = new HashSet<>(formats.length); diff --git a/src/java.management/share/classes/java/lang/management/DefaultPlatformMBeanProvider.java b/src/java.management/share/classes/java/lang/management/DefaultPlatformMBeanProvider.java index e9e905918ccb9..9d9c524b5336d 100644 --- a/src/java.management/share/classes/java/lang/management/DefaultPlatformMBeanProvider.java +++ b/src/java.management/share/classes/java/lang/management/DefaultPlatformMBeanProvider.java @@ -184,7 +184,7 @@ public Map nameToMBeanMap() { if (list.isEmpty()) { map = Collections.emptyMap(); } else { - map = HashMap.newHashMap(list.size()); + map = new HashMap<>(list.size()); for (MemoryManagerMXBean gcm : list) { map.put(gcm.getObjectName().getCanonicalName(), gcm); @@ -278,7 +278,7 @@ public Map nameToMBeanMap() { if (list.isEmpty()) { map = Collections.emptyMap(); } else { - map = HashMap.newHashMap(list.size()); + map = new HashMap<>(list.size()); for (MemoryPoolMXBean mpm : list) { map.put(mpm.getObjectName().getCanonicalName(), mpm); @@ -415,7 +415,7 @@ public Map nameToMBeanMap() { if (list.isEmpty()) { map = Collections.emptyMap(); } else { - map = HashMap.newHashMap(list.size()); + map = new HashMap<>(list.size()); list.forEach(mbean -> map.put(mbean.getObjectName().getCanonicalName(),mbean)); } return map; diff --git a/src/java.management/share/classes/sun/management/HotspotThread.java b/src/java.management/share/classes/sun/management/HotspotThread.java index 2fd205db37180..03e403a89831a 100644 --- a/src/java.management/share/classes/sun/management/HotspotThread.java +++ b/src/java.management/share/classes/sun/management/HotspotThread.java @@ -58,7 +58,7 @@ public Map getInternalThreadCpuTimes() { String[] names = new String[count]; long[] times = new long[count]; int numThreads = getInternalThreadTimes0(names, times); - Map result = HashMap.newHashMap(numThreads); + Map result = new HashMap<>(numThreads); for (int i = 0; i < numThreads; i++) { result.put(names[i], times[i]); } diff --git a/src/jdk.internal.vm.ci/share/classes/jdk.vm.ci.hotspot/src/jdk/vm/ci/hotspot/HotSpotVMConfigStore.java b/src/jdk.internal.vm.ci/share/classes/jdk.vm.ci.hotspot/src/jdk/vm/ci/hotspot/HotSpotVMConfigStore.java index e0fb0827de783..647779d579480 100644 --- a/src/jdk.internal.vm.ci/share/classes/jdk.vm.ci.hotspot/src/jdk/vm/ci/hotspot/HotSpotVMConfigStore.java +++ b/src/jdk.internal.vm.ci/share/classes/jdk.vm.ci.hotspot/src/jdk/vm/ci/hotspot/HotSpotVMConfigStore.java @@ -120,10 +120,10 @@ public List getIntrinsics() { Object[] vmAddressesInfo = (Object[]) data[2]; VMFlag[] vmFlagsInfo = (VMFlag[]) data[3]; - vmFields = HashMap.newHashMap(vmFieldsInfo.length); - vmConstants = HashMap.newHashMap(vmConstantsInfo.length); - vmAddresses = HashMap.newHashMap(vmAddressesInfo.length); - vmFlags = HashMap.newHashMap(vmFlagsInfo.length); + vmFields = new HashMap<>(vmFieldsInfo.length); + vmConstants = new HashMap<>(vmConstantsInfo.length); + vmAddresses = new HashMap<>(vmAddressesInfo.length); + vmFlags = new HashMap<>(vmFlagsInfo.length); vmIntrinsics = Arrays.asList((VMIntrinsicMethod[]) data[4]); // @formatter:on diff --git a/src/jdk.internal.vm.ci/share/classes/jdk.vm.ci.services/src/jdk/vm/ci/services/Services.java b/src/jdk.internal.vm.ci/share/classes/jdk.vm.ci.services/src/jdk/vm/ci/services/Services.java index 6e19236897bec..9a6774b935f3d 100644 --- a/src/jdk.internal.vm.ci/share/classes/jdk.vm.ci.services/src/jdk/vm/ci/services/Services.java +++ b/src/jdk.internal.vm.ci/share/classes/jdk.vm.ci.services/src/jdk/vm/ci/services/Services.java @@ -317,7 +317,7 @@ private static Map deserializeProperties(byte[] serializedProper DataInputStream in = new DataInputStream(new ByteArrayInputStream(serializedProperties)); int utf8Props = in.readInt(); int nonUtf8Props = in.readInt(); - Map props = HashMap.newHashMap(utf8Props + nonUtf8Props); + Map props = new HashMap<>(utf8Props + nonUtf8Props); int index = 0; while (in.available() != 0) { if (index < utf8Props) { diff --git a/src/jdk.jfr/share/classes/jdk/jfr/EventType.java b/src/jdk.jfr/share/classes/jdk/jfr/EventType.java index 9835056fb22a5..3d069fe8e396c 100644 --- a/src/jdk.jfr/share/classes/jdk/jfr/EventType.java +++ b/src/jdk.jfr/share/classes/jdk/jfr/EventType.java @@ -78,7 +78,7 @@ public ValueDescriptor getField(String name) { Objects.requireNonNull(name, "name"); if (cache == null) { List fields = getFields(); - Map newCache = LinkedHashMap.newLinkedHashMap(fields.size()); + Map newCache = new LinkedHashMap<>(fields.size()); for (ValueDescriptor v :fields) { newCache.put(v.getName(), v); } diff --git a/src/jdk.jfr/share/classes/jdk/jfr/consumer/MetadataEvent.java b/src/jdk.jfr/share/classes/jdk/jfr/consumer/MetadataEvent.java index c3b7faa8cce18..b400562d2a4ae 100644 --- a/src/jdk.jfr/share/classes/jdk/jfr/consumer/MetadataEvent.java +++ b/src/jdk.jfr/share/classes/jdk/jfr/consumer/MetadataEvent.java @@ -102,7 +102,7 @@ public List getConfigurations() { private void calculateDelta() { List added = new ArrayList<>(); - Map previousSet = HashMap.newHashMap(previous.size()); + Map previousSet = new HashMap<>(previous.size()); for (EventType eventType : previous) { previousSet.put(eventType.getId(), eventType); } diff --git a/src/jdk.jfr/share/classes/jdk/jfr/internal/MetadataLoader.java b/src/jdk.jfr/share/classes/jdk/jfr/internal/MetadataLoader.java index 97913568e0ada..552b070527e84 100644 --- a/src/jdk.jfr/share/classes/jdk/jfr/internal/MetadataLoader.java +++ b/src/jdk.jfr/share/classes/jdk/jfr/internal/MetadataLoader.java @@ -272,7 +272,7 @@ private AnnotationElement newAnnotation(Type type, Object value) { } private Map buildTypeMap() { - Map typeMap = HashMap.newHashMap(2 * types.size()); + Map typeMap = new HashMap<>(2 * types.size()); Map knownTypeMap = new HashMap<>(20); for (Type kt : Type.getKnownTypes()) { typeMap.put(kt.getName(), kt); diff --git a/src/jdk.jfr/share/classes/jdk/jfr/internal/MetadataWriter.java b/src/jdk.jfr/share/classes/jdk/jfr/internal/MetadataWriter.java index a8d5333f934a5..149bc1795a9aa 100644 --- a/src/jdk.jfr/share/classes/jdk/jfr/internal/MetadataWriter.java +++ b/src/jdk.jfr/share/classes/jdk/jfr/internal/MetadataWriter.java @@ -80,7 +80,7 @@ public void writeBinary(DataOutput output) throws IOException { // Possible improvement, sort string by how often they occur. // and assign low number to the most frequently used. buildStringPool(root, stringPool); - HashMap lookup = LinkedHashMap.newLinkedHashMap(stringPool.size()); + HashMap lookup = new LinkedHashMap<>(stringPool.size()); int index = 0; int poolSize = stringPool.size(); writeInt(output, poolSize); diff --git a/src/jdk.jfr/share/classes/jdk/jfr/internal/SettingsManager.java b/src/jdk.jfr/share/classes/jdk/jfr/internal/SettingsManager.java index d5b17b5640492..d6078ef9f985e 100644 --- a/src/jdk.jfr/share/classes/jdk/jfr/internal/SettingsManager.java +++ b/src/jdk.jfr/share/classes/jdk/jfr/internal/SettingsManager.java @@ -172,7 +172,7 @@ public void updateRetransform(List> ev } private Map createSettingsMap(List> activeSettings) { - Map map = LinkedHashMap.newLinkedHashMap(activeSettings.size()); + Map map = new LinkedHashMap<>(activeSettings.size()); for (Map rec : activeSettings) { for (InternalSetting internal : makeInternalSettings(rec)) { InternalSetting is = map.get(internal.getSettingsId()); diff --git a/src/jdk.jfr/share/classes/jdk/jfr/internal/Utils.java b/src/jdk.jfr/share/classes/jdk/jfr/internal/Utils.java index 497b3515b7422..c0324d2d7f6d3 100644 --- a/src/jdk.jfr/share/classes/jdk/jfr/internal/Utils.java +++ b/src/jdk.jfr/share/classes/jdk/jfr/internal/Utils.java @@ -462,7 +462,7 @@ static synchronized void setHandler(Class ev } public static Map sanitizeNullFreeStringMap(Map settings) { - HashMap map = HashMap.newHashMap(settings.size()); + HashMap map = new HashMap<>(settings.size()); for (Map.Entry e : settings.entrySet()) { String key = e.getKey(); if (key == null) { diff --git a/src/jdk.management.jfr/share/classes/jdk/management/jfr/ConfigurationInfo.java b/src/jdk.management.jfr/share/classes/jdk/management/jfr/ConfigurationInfo.java index bbfa853ab0962..e9f5a7fdfa6e7 100644 --- a/src/jdk.management.jfr/share/classes/jdk/management/jfr/ConfigurationInfo.java +++ b/src/jdk.management.jfr/share/classes/jdk/management/jfr/ConfigurationInfo.java @@ -73,7 +73,7 @@ private static Map createMap(Object o) { if (o instanceof TabularData) { TabularData td = (TabularData) o; Collection values = td.values(); - Map map = HashMap.newHashMap(values.size()); + Map map = new HashMap<>(values.size()); for (Object value : td.values()) { if (value instanceof CompositeData) { CompositeData cdRow = (CompositeData) value; diff --git a/src/jdk.management/share/classes/com/sun/management/internal/PlatformMBeanProviderImpl.java b/src/jdk.management/share/classes/com/sun/management/internal/PlatformMBeanProviderImpl.java index 869b02f75db94..cddb9127d2e9b 100644 --- a/src/jdk.management/share/classes/com/sun/management/internal/PlatformMBeanProviderImpl.java +++ b/src/jdk.management/share/classes/com/sun/management/internal/PlatformMBeanProviderImpl.java @@ -113,7 +113,7 @@ public Map nameToMBeanMap() { if (list.isEmpty()) { map = Collections.emptyMap(); } else { - map = HashMap.newHashMap(list.size()); + map = new HashMap<>(list.size()); for (MemoryManagerMXBean gcm : list) { map.put(gcm.getObjectName().getCanonicalName(), gcm); diff --git a/src/utils/IdealGraphVisualizer/Data/src/main/java/com/sun/hotspot/igv/data/InputGraph.java b/src/utils/IdealGraphVisualizer/Data/src/main/java/com/sun/hotspot/igv/data/InputGraph.java index da05f56749a38..c218b10002d1a 100644 --- a/src/utils/IdealGraphVisualizer/Data/src/main/java/com/sun/hotspot/igv/data/InputGraph.java +++ b/src/utils/IdealGraphVisualizer/Data/src/main/java/com/sun/hotspot/igv/data/InputGraph.java @@ -85,7 +85,7 @@ public List findRootNodes() { } public Map> findAllOutgoingEdges() { - Map> result = HashMap.newHashMap(getNodes().size()); + Map> result = new HashMap<>(getNodes().size()); for(InputNode n : this.getNodes()) { result.put(n, new ArrayList()); } @@ -107,7 +107,7 @@ public Map> findAllOutgoingEdges() { } public Map> findAllIngoingEdges() { - Map> result = HashMap.newHashMap(getNodes().size()); + Map> result = new HashMap<>(getNodes().size()); for(InputNode n : this.getNodes()) { result.put(n, new ArrayList()); } diff --git a/src/utils/IdealGraphVisualizer/Difference/src/main/java/com/sun/hotspot/igv/difference/Difference.java b/src/utils/IdealGraphVisualizer/Difference/src/main/java/com/sun/hotspot/igv/difference/Difference.java index 4367b4a18cec4..0b2f01c47e82a 100644 --- a/src/utils/IdealGraphVisualizer/Difference/src/main/java/com/sun/hotspot/igv/difference/Difference.java +++ b/src/utils/IdealGraphVisualizer/Difference/src/main/java/com/sun/hotspot/igv/difference/Difference.java @@ -55,7 +55,7 @@ public static InputGraph createDiffGraph(InputGraph a, InputGraph b) { } private static InputGraph createDiffSameGroup(InputGraph a, InputGraph b) { - Map keyMapB = HashMap.newHashMap(b.getNodes().size()); + Map keyMapB = new HashMap<>(b.getNodes().size()); for (InputNode n : b.getNodes()) { Integer key = n.getId(); assert !keyMapB.containsKey(key); @@ -108,7 +108,7 @@ private static InputGraph createDiff(InputGraph a, InputGraph b, Set p InputGraph graph = new InputGraph(a.getName() + ", " + b.getName()); g.addElement(graph); - Map blocksMap = HashMap.newHashMap(a.getBlocks().size()); + Map blocksMap = new HashMap<>(); for (InputBlock blk : a.getBlocks()) { InputBlock diffblk = graph.addBlock(blk.getName()); blocksMap.put(blk, diffblk); @@ -151,7 +151,7 @@ private static InputGraph createDiff(InputGraph a, InputGraph b, Set p Set nodesA = new HashSet<>(a.getNodes()); Set nodesB = new HashSet<>(b.getNodes()); - Map inputNodeMap = HashMap.newHashMap(pairs.size()); + Map inputNodeMap = new HashMap<>(pairs.size()); for (NodePair p : pairs) { InputNode n = p.getLeft(); assert nodesA.contains(n); diff --git a/src/utils/IdealGraphVisualizer/Layout/src/main/java/com/sun/hotspot/igv/layout/LayoutGraph.java b/src/utils/IdealGraphVisualizer/Layout/src/main/java/com/sun/hotspot/igv/layout/LayoutGraph.java index 93fe72922817f..0409aa82d10ff 100644 --- a/src/utils/IdealGraphVisualizer/Layout/src/main/java/com/sun/hotspot/igv/layout/LayoutGraph.java +++ b/src/utils/IdealGraphVisualizer/Layout/src/main/java/com/sun/hotspot/igv/layout/LayoutGraph.java @@ -46,9 +46,9 @@ public LayoutGraph(Set links, Set additionalVe assert verify(); vertices = new TreeSet<>(); - portLinks = HashMap.newHashMap(links.size()); - inputPorts = HashMap.newHashMap(links.size()); - outputPorts = HashMap.newHashMap(links.size()); + portLinks = new HashMap<>(links.size()); + inputPorts = new HashMap<>(links.size()); + outputPorts = new HashMap<>(links.size()); for (Link l : links) { if (l.getFrom() == null || l.getTo() == null) { diff --git a/src/utils/IdealGraphVisualizer/ServerCompiler/src/main/java/com/sun/hotspot/igv/servercompiler/ServerCompilerScheduler.java b/src/utils/IdealGraphVisualizer/ServerCompiler/src/main/java/com/sun/hotspot/igv/servercompiler/ServerCompilerScheduler.java index 7e2d586b01f89..9a5b72b76fca5 100644 --- a/src/utils/IdealGraphVisualizer/ServerCompiler/src/main/java/com/sun/hotspot/igv/servercompiler/ServerCompilerScheduler.java +++ b/src/utils/IdealGraphVisualizer/ServerCompiler/src/main/java/com/sun/hotspot/igv/servercompiler/ServerCompilerScheduler.java @@ -252,7 +252,7 @@ public Collection schedule(InputGraph graph) { return graph.getBlocks(); } else { nodes = new ArrayList<>(); - inputNodeToNode = HashMap.newHashMap(graph.getNodes().size()); + inputNodeToNode = new HashMap<>(graph.getNodes().size()); this.graph = graph; if (!hasCategoryInformation()) { @@ -516,7 +516,7 @@ public InputBlock getCommonDominator(InputBlock ba, InputBlock bb) { } public void buildDominators() { - dominatorMap = HashMap.newHashMap(graph.getBlocks().size()); + dominatorMap = new HashMap<>(graph.getBlocks().size()); if (blocks.size() == 0) { return; } @@ -614,7 +614,7 @@ public void buildUpGraph() { inputNodeToNode.put(n, node); } - Map> edgeMap = HashMap.newHashMap(graph.getEdges().size()); + Map> edgeMap = new HashMap<>(graph.getEdges().size()); for (InputEdge e : graph.getEdges()) { int to = e.getTo(); diff --git a/src/utils/IdealGraphVisualizer/View/src/main/java/com/sun/hotspot/igv/view/DiagramScene.java b/src/utils/IdealGraphVisualizer/View/src/main/java/com/sun/hotspot/igv/view/DiagramScene.java index 522112ae2f156..72ad1aa102f61 100644 --- a/src/utils/IdealGraphVisualizer/View/src/main/java/com/sun/hotspot/igv/view/DiagramScene.java +++ b/src/utils/IdealGraphVisualizer/View/src/main/java/com/sun/hotspot/igv/view/DiagramScene.java @@ -853,7 +853,7 @@ private void relayoutWithoutLayout(Set oldVisibleWidgets) { private final Point specialNullPoint = new Point(Integer.MAX_VALUE, Integer.MAX_VALUE); private void processOutputSlot(Set> lastLineCache, OutputSlot s, List connections, int controlPointIndex, Point lastPoint, LineWidget predecessor, int offx, int offy, SceneAnimator animator) { - Map> pointMap = HashMap.newHashMap(connections.size()); + Map> pointMap = new HashMap<>(connections.size()); for (Connection c : connections) { From 4476c7619c37d4b4deb858cc955669fea57eeda8 Mon Sep 17 00:00:00 2001 From: XenoAmess Date: Thu, 14 Apr 2022 06:03:46 +0800 Subject: [PATCH 21/26] Copyright latest year to 2022 --- .../sun/util/locale/provider/HostLocaleProviderAdapterImpl.java | 2 +- src/java.base/share/classes/java/lang/Module.java | 2 +- .../share/classes/java/lang/invoke/MethodHandleImpl.java | 2 +- src/java.base/share/classes/java/lang/module/Resolver.java | 2 +- .../classes/java/security/cert/CertificateRevokedException.java | 2 +- .../share/classes/java/security/cert/PKIXRevocationChecker.java | 2 +- src/java.base/share/classes/java/util/HashMap.java | 2 +- src/java.base/share/classes/java/util/HashSet.java | 2 +- src/java.base/share/classes/java/util/LinkedHashMap.java | 2 +- src/java.base/share/classes/java/util/ListResourceBundle.java | 2 +- src/java.base/share/classes/java/util/WeakHashMap.java | 2 +- src/java.base/share/classes/java/util/jar/Attributes.java | 2 +- src/java.base/share/classes/jdk/internal/module/ModuleInfo.java | 2 +- .../classes/sun/security/provider/certpath/OCSPResponse.java | 2 +- src/java.base/share/classes/sun/security/util/Cache.java | 2 +- .../classes/sun/util/resources/OpenListResourceBundle.java | 2 +- .../share/classes/sun/util/resources/TimeZoneNamesBundle.java | 2 +- src/java.base/unix/classes/java/lang/ProcessEnvironment.java | 2 +- .../unix/classes/sun/nio/fs/MimeTypesFileTypeDetector.java | 2 +- .../share/classes/jdk/internal/net/http/hpack/HeaderTable.java | 2 +- .../sun/org/apache/xalan/internal/xsltc/dom/DocumentCache.java | 2 +- .../sun/org/apache/xerces/internal/dom/CoreDocumentImpl.java | 2 +- .../xerces/internal/impl/xs/traversers/XSAttributeChecker.java | 2 +- src/jdk.zipfs/share/classes/jdk/nio/zipfs/ZipFileSystem.java | 2 +- 24 files changed, 24 insertions(+), 24 deletions(-) diff --git a/src/java.base/macosx/classes/sun/util/locale/provider/HostLocaleProviderAdapterImpl.java b/src/java.base/macosx/classes/sun/util/locale/provider/HostLocaleProviderAdapterImpl.java index 3e3fc85120771..e587ee54097af 100644 --- a/src/java.base/macosx/classes/sun/util/locale/provider/HostLocaleProviderAdapterImpl.java +++ b/src/java.base/macosx/classes/sun/util/locale/provider/HostLocaleProviderAdapterImpl.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2012, 2019, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2012, 2022, 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 diff --git a/src/java.base/share/classes/java/lang/Module.java b/src/java.base/share/classes/java/lang/Module.java index d7f7eda02d837..01540fb73e117 100644 --- a/src/java.base/share/classes/java/lang/Module.java +++ b/src/java.base/share/classes/java/lang/Module.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014, 2021, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2014, 2022, 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 diff --git a/src/java.base/share/classes/java/lang/invoke/MethodHandleImpl.java b/src/java.base/share/classes/java/lang/invoke/MethodHandleImpl.java index b1d867d3f7b2c..181603d3bf75e 100644 --- a/src/java.base/share/classes/java/lang/invoke/MethodHandleImpl.java +++ b/src/java.base/share/classes/java/lang/invoke/MethodHandleImpl.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2008, 2021, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2008, 2022, 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 diff --git a/src/java.base/share/classes/java/lang/module/Resolver.java b/src/java.base/share/classes/java/lang/module/Resolver.java index 0973615442c02..b41e6d1c65e19 100644 --- a/src/java.base/share/classes/java/lang/module/Resolver.java +++ b/src/java.base/share/classes/java/lang/module/Resolver.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2013, 2020, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2013, 2022, 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 diff --git a/src/java.base/share/classes/java/security/cert/CertificateRevokedException.java b/src/java.base/share/classes/java/security/cert/CertificateRevokedException.java index a7cb039697873..4e694a73e84d1 100644 --- a/src/java.base/share/classes/java/security/cert/CertificateRevokedException.java +++ b/src/java.base/share/classes/java/security/cert/CertificateRevokedException.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2007, 2021, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2007, 2022, 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 diff --git a/src/java.base/share/classes/java/security/cert/PKIXRevocationChecker.java b/src/java.base/share/classes/java/security/cert/PKIXRevocationChecker.java index 751bd0c3cbadc..247fdc1f823de 100644 --- a/src/java.base/share/classes/java/security/cert/PKIXRevocationChecker.java +++ b/src/java.base/share/classes/java/security/cert/PKIXRevocationChecker.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2012, 2013, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2012, 2022, 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 diff --git a/src/java.base/share/classes/java/util/HashMap.java b/src/java.base/share/classes/java/util/HashMap.java index f6c77a494c318..abba8045d17a4 100644 --- a/src/java.base/share/classes/java/util/HashMap.java +++ b/src/java.base/share/classes/java/util/HashMap.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 1997, 2021, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 1997, 2022, 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 diff --git a/src/java.base/share/classes/java/util/HashSet.java b/src/java.base/share/classes/java/util/HashSet.java index 6dbc22f1ea9fa..601401ca669eb 100644 --- a/src/java.base/share/classes/java/util/HashSet.java +++ b/src/java.base/share/classes/java/util/HashSet.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 1997, 2021, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 1997, 2022, 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 diff --git a/src/java.base/share/classes/java/util/LinkedHashMap.java b/src/java.base/share/classes/java/util/LinkedHashMap.java index b2b7536f06505..f1c388f996089 100644 --- a/src/java.base/share/classes/java/util/LinkedHashMap.java +++ b/src/java.base/share/classes/java/util/LinkedHashMap.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 1997, 2020, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 1997, 2022, 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 diff --git a/src/java.base/share/classes/java/util/ListResourceBundle.java b/src/java.base/share/classes/java/util/ListResourceBundle.java index 122f9d17393ab..bac72b3dfe6a8 100644 --- a/src/java.base/share/classes/java/util/ListResourceBundle.java +++ b/src/java.base/share/classes/java/util/ListResourceBundle.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 1996, 2019, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 1996, 2022, 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 diff --git a/src/java.base/share/classes/java/util/WeakHashMap.java b/src/java.base/share/classes/java/util/WeakHashMap.java index 68727d53b8ae4..1d50e8239bdac 100644 --- a/src/java.base/share/classes/java/util/WeakHashMap.java +++ b/src/java.base/share/classes/java/util/WeakHashMap.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 1998, 2020, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 1998, 2022, 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 diff --git a/src/java.base/share/classes/java/util/jar/Attributes.java b/src/java.base/share/classes/java/util/jar/Attributes.java index 73618a4f332aa..3e6e67345405c 100644 --- a/src/java.base/share/classes/java/util/jar/Attributes.java +++ b/src/java.base/share/classes/java/util/jar/Attributes.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 1997, 2021, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 1997, 2022, 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 diff --git a/src/java.base/share/classes/jdk/internal/module/ModuleInfo.java b/src/java.base/share/classes/jdk/internal/module/ModuleInfo.java index 71f34c18cdebd..91507a1b1708d 100644 --- a/src/java.base/share/classes/jdk/internal/module/ModuleInfo.java +++ b/src/java.base/share/classes/jdk/internal/module/ModuleInfo.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014, 2020, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2014, 2022, 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 diff --git a/src/java.base/share/classes/sun/security/provider/certpath/OCSPResponse.java b/src/java.base/share/classes/sun/security/provider/certpath/OCSPResponse.java index 36a9abe42aa84..05d90c95b5f98 100644 --- a/src/java.base/share/classes/sun/security/provider/certpath/OCSPResponse.java +++ b/src/java.base/share/classes/sun/security/provider/certpath/OCSPResponse.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2003, 2021, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2003, 2022, 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 diff --git a/src/java.base/share/classes/sun/security/util/Cache.java b/src/java.base/share/classes/sun/security/util/Cache.java index 40006779d37da..b7a6ef024425f 100644 --- a/src/java.base/share/classes/sun/security/util/Cache.java +++ b/src/java.base/share/classes/sun/security/util/Cache.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2002, 2021, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2002, 2022, 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 diff --git a/src/java.base/share/classes/sun/util/resources/OpenListResourceBundle.java b/src/java.base/share/classes/sun/util/resources/OpenListResourceBundle.java index c516257965bed..d375930dde066 100644 --- a/src/java.base/share/classes/sun/util/resources/OpenListResourceBundle.java +++ b/src/java.base/share/classes/sun/util/resources/OpenListResourceBundle.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2005, 2013, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2005, 2022, 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 diff --git a/src/java.base/share/classes/sun/util/resources/TimeZoneNamesBundle.java b/src/java.base/share/classes/sun/util/resources/TimeZoneNamesBundle.java index 6495a5fba5484..a30b84c6872b0 100644 --- a/src/java.base/share/classes/sun/util/resources/TimeZoneNamesBundle.java +++ b/src/java.base/share/classes/sun/util/resources/TimeZoneNamesBundle.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2005, 2018, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2005, 2022, 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 diff --git a/src/java.base/unix/classes/java/lang/ProcessEnvironment.java b/src/java.base/unix/classes/java/lang/ProcessEnvironment.java index f9086c0921886..c3bd135c22fc0 100644 --- a/src/java.base/unix/classes/java/lang/ProcessEnvironment.java +++ b/src/java.base/unix/classes/java/lang/ProcessEnvironment.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2003, 2011, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2003, 2022, 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 diff --git a/src/java.base/unix/classes/sun/nio/fs/MimeTypesFileTypeDetector.java b/src/java.base/unix/classes/sun/nio/fs/MimeTypesFileTypeDetector.java index 60b44e7d9e435..f9b9caf04ed71 100644 --- a/src/java.base/unix/classes/sun/nio/fs/MimeTypesFileTypeDetector.java +++ b/src/java.base/unix/classes/sun/nio/fs/MimeTypesFileTypeDetector.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2015, 2021, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2015, 2022, 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 diff --git a/src/java.net.http/share/classes/jdk/internal/net/http/hpack/HeaderTable.java b/src/java.net.http/share/classes/jdk/internal/net/http/hpack/HeaderTable.java index a453be264fc22..72d02655dac98 100644 --- a/src/java.net.http/share/classes/jdk/internal/net/http/hpack/HeaderTable.java +++ b/src/java.net.http/share/classes/jdk/internal/net/http/hpack/HeaderTable.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014, 2018, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2014, 2022, 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 diff --git a/src/java.xml/share/classes/com/sun/org/apache/xalan/internal/xsltc/dom/DocumentCache.java b/src/java.xml/share/classes/com/sun/org/apache/xalan/internal/xsltc/dom/DocumentCache.java index afeed3d5fd0ef..1ef170bb0173d 100644 --- a/src/java.xml/share/classes/com/sun/org/apache/xalan/internal/xsltc/dom/DocumentCache.java +++ b/src/java.xml/share/classes/com/sun/org/apache/xalan/internal/xsltc/dom/DocumentCache.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2015, 2017, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2015, 2022, Oracle and/or its affiliates. All rights reserved. */ /* * Licensed to the Apache Software Foundation (ASF) under one or more diff --git a/src/java.xml/share/classes/com/sun/org/apache/xerces/internal/dom/CoreDocumentImpl.java b/src/java.xml/share/classes/com/sun/org/apache/xerces/internal/dom/CoreDocumentImpl.java index 257c8ccfe5551..77b3a03f3e538 100644 --- a/src/java.xml/share/classes/com/sun/org/apache/xerces/internal/dom/CoreDocumentImpl.java +++ b/src/java.xml/share/classes/com/sun/org/apache/xerces/internal/dom/CoreDocumentImpl.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2009, 2019, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2009, 2022, Oracle and/or its affiliates. All rights reserved. */ /* * Licensed to the Apache Software Foundation (ASF) under one or more diff --git a/src/java.xml/share/classes/com/sun/org/apache/xerces/internal/impl/xs/traversers/XSAttributeChecker.java b/src/java.xml/share/classes/com/sun/org/apache/xerces/internal/impl/xs/traversers/XSAttributeChecker.java index 86dd766ec1a49..7135109f39a3e 100644 --- a/src/java.xml/share/classes/com/sun/org/apache/xerces/internal/impl/xs/traversers/XSAttributeChecker.java +++ b/src/java.xml/share/classes/com/sun/org/apache/xerces/internal/impl/xs/traversers/XSAttributeChecker.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2016, 2017, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2016, 2022, Oracle and/or its affiliates. All rights reserved. */ /* * Licensed to the Apache Software Foundation (ASF) under one or more diff --git a/src/jdk.zipfs/share/classes/jdk/nio/zipfs/ZipFileSystem.java b/src/jdk.zipfs/share/classes/jdk/nio/zipfs/ZipFileSystem.java index c78101e6e86f8..f4375cfc51fa9 100644 --- a/src/jdk.zipfs/share/classes/jdk/nio/zipfs/ZipFileSystem.java +++ b/src/jdk.zipfs/share/classes/jdk/nio/zipfs/ZipFileSystem.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2009, 2021, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2009, 2022, 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 From d110ecfdf3740a09fb87ce7de62b8f7799c03f0b Mon Sep 17 00:00:00 2001 From: XenoAmess Date: Thu, 14 Apr 2022 06:13:00 +0800 Subject: [PATCH 22/26] update LastModified --- .../sun/org/apache/xerces/internal/dom/CoreDocumentImpl.java | 2 +- .../xerces/internal/impl/xs/traversers/XSAttributeChecker.java | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/java.xml/share/classes/com/sun/org/apache/xerces/internal/dom/CoreDocumentImpl.java b/src/java.xml/share/classes/com/sun/org/apache/xerces/internal/dom/CoreDocumentImpl.java index 77b3a03f3e538..1fd84e9f6397e 100644 --- a/src/java.xml/share/classes/com/sun/org/apache/xerces/internal/dom/CoreDocumentImpl.java +++ b/src/java.xml/share/classes/com/sun/org/apache/xerces/internal/dom/CoreDocumentImpl.java @@ -83,7 +83,7 @@ * @author Andy Clark, IBM * @author Ralf Pfeiffer, IBM * @since PR-DOM-Level-1-19980818. - * @LastModified: Sept 2019 + * @LastModified: Apr 2022 */ public class CoreDocumentImpl extends ParentNode implements Document { diff --git a/src/java.xml/share/classes/com/sun/org/apache/xerces/internal/impl/xs/traversers/XSAttributeChecker.java b/src/java.xml/share/classes/com/sun/org/apache/xerces/internal/impl/xs/traversers/XSAttributeChecker.java index 7135109f39a3e..149c8098dedb9 100644 --- a/src/java.xml/share/classes/com/sun/org/apache/xerces/internal/impl/xs/traversers/XSAttributeChecker.java +++ b/src/java.xml/share/classes/com/sun/org/apache/xerces/internal/impl/xs/traversers/XSAttributeChecker.java @@ -67,7 +67,7 @@ * @xerces.internal * * @author Sandy Gao, IBM - * @LastModified: Nov 2017 + * @LastModified: Apr 2022 */ public class XSAttributeChecker { From 5603f19397b56882774dc00705f349be75f33a0c Mon Sep 17 00:00:00 2001 From: XenoAmess Date: Fri, 15 Apr 2022 00:51:47 +0800 Subject: [PATCH 23/26] fix usage in XSAttributeChecker --- .../xerces/internal/impl/xs/traversers/XSAttributeChecker.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/java.xml/share/classes/com/sun/org/apache/xerces/internal/impl/xs/traversers/XSAttributeChecker.java b/src/java.xml/share/classes/com/sun/org/apache/xerces/internal/impl/xs/traversers/XSAttributeChecker.java index 149c8098dedb9..17ff84c5c423b 100644 --- a/src/java.xml/share/classes/com/sun/org/apache/xerces/internal/impl/xs/traversers/XSAttributeChecker.java +++ b/src/java.xml/share/classes/com/sun/org/apache/xerces/internal/impl/xs/traversers/XSAttributeChecker.java @@ -1816,7 +1816,7 @@ OneAttr get(String key) { class LargeContainer extends Container { Map items; LargeContainer(int size) { - items = HashMap.newHashMap(size*2+1); + items = HashMap.newHashMap(size); values = new OneAttr[size]; } void put(String key, OneAttr value) { From 5b437dab0685c30d4202278c9ace2bbc1966bc21 Mon Sep 17 00:00:00 2001 From: XenoAmess Date: Fri, 15 Apr 2022 00:59:09 +0800 Subject: [PATCH 24/26] revert changes on ProcessEnvironment --- .../unix/classes/java/lang/ProcessEnvironment.java | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/java.base/unix/classes/java/lang/ProcessEnvironment.java b/src/java.base/unix/classes/java/lang/ProcessEnvironment.java index c3bd135c22fc0..e4341e5322cf3 100644 --- a/src/java.base/unix/classes/java/lang/ProcessEnvironment.java +++ b/src/java.base/unix/classes/java/lang/ProcessEnvironment.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2003, 2022, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2003, 2011, 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 @@ -68,7 +68,7 @@ final class ProcessEnvironment // We cache the C environment. This means that subsequent calls // to putenv/setenv from C will not be visible from Java code. byte[][] environ = environ(); - theEnvironment = HashMap.newHashMap(environ.length/2 + 3); + theEnvironment = new HashMap<>(environ.length/2 + 3); // Read environment variables back to front, // so that earlier variables override later ones. for (int i = environ.length-1; i > 0; i-=2) @@ -99,7 +99,7 @@ static Map environment() { /* Only for use by Runtime.exec(...String[]envp...) */ static Map emptyEnvironment(int capacity) { - return new StringEnvironment(HashMap.newHashMap(capacity)); + return new StringEnvironment(new HashMap<>(capacity)); } private static native byte[][] environ(); From 71b7dba326fa8d359e0d99525f9208fd12b80381 Mon Sep 17 00:00:00 2001 From: XenoAmess Date: Fri, 15 Apr 2022 02:04:17 +0800 Subject: [PATCH 25/26] add `@LastModified: Apr 2022` to DocumentCache --- .../sun/org/apache/xalan/internal/xsltc/dom/DocumentCache.java | 1 + 1 file changed, 1 insertion(+) diff --git a/src/java.xml/share/classes/com/sun/org/apache/xalan/internal/xsltc/dom/DocumentCache.java b/src/java.xml/share/classes/com/sun/org/apache/xalan/internal/xsltc/dom/DocumentCache.java index 1ef170bb0173d..c6722c98465ce 100644 --- a/src/java.xml/share/classes/com/sun/org/apache/xalan/internal/xsltc/dom/DocumentCache.java +++ b/src/java.xml/share/classes/com/sun/org/apache/xalan/internal/xsltc/dom/DocumentCache.java @@ -50,6 +50,7 @@ /** * @author Morten Jorgensen + * @LastModified: Apr 2022 */ public final class DocumentCache implements DOMCache { From 95e22f257179d25dff259c06f5b4fedff5277fbb Mon Sep 17 00:00:00 2001 From: XenoAmess Date: Fri, 15 Apr 2022 05:21:32 +0800 Subject: [PATCH 26/26] java.xml.crypto's usage downgrade grammar to 1.8 --- .../org/jcp/xml/dsig/internal/dom/DOMXPathFilter2Transform.java | 2 +- .../org/jcp/xml/dsig/internal/dom/DOMXPathTransform.java | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/java.xml.crypto/share/classes/org/jcp/xml/dsig/internal/dom/DOMXPathFilter2Transform.java b/src/java.xml.crypto/share/classes/org/jcp/xml/dsig/internal/dom/DOMXPathFilter2Transform.java index bdcfa9c0b0b41..1d538aa3eddd5 100644 --- a/src/java.xml.crypto/share/classes/org/jcp/xml/dsig/internal/dom/DOMXPathFilter2Transform.java +++ b/src/java.xml.crypto/share/classes/org/jcp/xml/dsig/internal/dom/DOMXPathFilter2Transform.java @@ -107,7 +107,7 @@ private void unmarshalParams(Element curXPathElem) throws MarshalException if (attributes != null) { int length = attributes.getLength(); Map namespaceMap = - HashMap.newHashMap(length); + new HashMap<>((int) Math.ceil(length / 0.75)); for (int i = 0; i < length; i++) { Attr attr = (Attr)attributes.item(i); String prefix = attr.getPrefix(); diff --git a/src/java.xml.crypto/share/classes/org/jcp/xml/dsig/internal/dom/DOMXPathTransform.java b/src/java.xml.crypto/share/classes/org/jcp/xml/dsig/internal/dom/DOMXPathTransform.java index f568843cd2f39..9888e63d74a2f 100644 --- a/src/java.xml.crypto/share/classes/org/jcp/xml/dsig/internal/dom/DOMXPathTransform.java +++ b/src/java.xml.crypto/share/classes/org/jcp/xml/dsig/internal/dom/DOMXPathTransform.java @@ -75,7 +75,7 @@ private void unmarshalParams(Element paramsElem) { if (attributes != null) { int length = attributes.getLength(); Map namespaceMap = - HashMap.newHashMap(length); + new HashMap<>((int) Math.ceil(length / 0.75)); for (int i = 0; i < length; i++) { Attr attr = (Attr)attributes.item(i); String prefix = attr.getPrefix();