diff --git a/test/jdk/java/util/Collection/MOAT.java b/test/jdk/java/util/Collection/MOAT.java index 3528518ca5c..6f4f0b11be5 100644 --- a/test/jdk/java/util/Collection/MOAT.java +++ b/test/jdk/java/util/Collection/MOAT.java @@ -422,31 +422,32 @@ public class MOAT { testMapMutatorsAlwaysThrow(mapCollected2); } - // Test HashMap.putAll() with various source map types + // Test HashMap.putAll() optimization paths private static void testHashMapPutAll() { Map testData = Map.of(1, 101, 2, 202, 3, 303); HashMap target = new HashMap<>(); + target.putAll(new HashMap<>(testData)); + equal(target.size(), testData.size()); + check(target.equals(testData)); + + target.clear(); + target.putAll(new TreeMap<>(testData)); + equal(target.size(), testData.size()); check(target.equals(testData)); target.clear(); - target.putAll(new ConcurrentHashMap<>(testData)); - check(target.equals(testData)); - target.clear(); target.putAll(unmodifiableMap(new HashMap<>(testData))); + equal(target.size(), testData.size()); check(target.equals(testData)); target.clear(); + target.putAll(unmodifiableMap(new TreeMap<>(testData))); + equal(target.size(), testData.size()); check(target.equals(testData)); - - // Test empty HashMap putAll (regression test for NPE) - target.clear(); - HashMap emptySource = new HashMap<>(); - target.putAll(emptySource); - check(target.isEmpty()); } private static void checkContainsSelf(Collection c) { diff --git a/test/micro/org/openjdk/bench/java/util/HashMapConstructorBenchmark.java b/test/micro/org/openjdk/bench/java/util/HashMapConstructorBenchmark.java index 320f5e405ae..c72693fee45 100644 --- a/test/micro/org/openjdk/bench/java/util/HashMapConstructorBenchmark.java +++ b/test/micro/org/openjdk/bench/java/util/HashMapConstructorBenchmark.java @@ -7,13 +7,13 @@ import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.TimeUnit; /** - * Benchmark demonstrating performance impact of polymorphic call sites on HashMap.(Map). + * Benchmark comparing HashMap constructor performance against manual iteration. * - * This test shows that manual inlining of HashMap construction can significantly outperform - * the built-in HashMap(Map) constructor when the constructor call site becomes polymorphic. + * Tests HashMap.(Map) performance across different source map types, with and without + * call site poisoning to simulate real-world megamorphic conditions. * - * The setup ensures polymorphic call sites by using HashMap, TreeMap, and LinkedHashMap - * in both the constructor and manual iteration patterns before benchmarking begins. + * The setup poisons polymorphic call sites by using five different map types + * in both the constructor and manual iteration patterns to ensure megamorphic behavior. */ @BenchmarkMode(Mode.AverageTime) @OutputTimeUnit(TimeUnit.NANOSECONDS) @@ -24,7 +24,6 @@ import java.util.concurrent.TimeUnit; public class HashMapConstructorBenchmark { private static final int POISON_ITERATIONS = 40000; - private static final double CAPACITY_FACTOR = 1.35; // Account for 0.75 load factor @Param({"0", "5", "25"}) private int mapSize; @@ -40,7 +39,6 @@ public class HashMapConstructorBenchmark { private LinkedHashMap inputLinkedHashMap; private ConcurrentHashMap inputConcurrentHashMap; private WeakHashMap inputWeakHashMap; - private Map inputSynchronizedMap; private Map inputUnmodifiableMap; private Map inputUnmodifiableTreeMap; @@ -66,7 +64,6 @@ public class HashMapConstructorBenchmark { } // Create wrapper maps for poisoning - inputSynchronizedMap = Collections.synchronizedMap(new HashMap<>(inputHashMap)); inputUnmodifiableMap = Collections.unmodifiableMap(new HashMap<>(inputHashMap)); inputUnmodifiableTreeMap = Collections.unmodifiableMap(new TreeMap<>(inputTreeMap)); @@ -138,7 +135,7 @@ public class HashMapConstructorBenchmark { /** * Benchmark using HashMap's built-in constructor that takes a Map parameter. - * This approach suffers from polymorphic call site overhead. + * Performance varies based on source map type and call site polymorphism. */ @Benchmark public HashMap hashMapConstructor() { @@ -149,7 +146,6 @@ public class HashMapConstructorBenchmark { * Benchmark using manual iteration over entrySet with individual put() calls. * This approach bypasses bulk operations and their polymorphic call sites. */ - /* @Benchmark public HashMap manualEntrySetLoop() { HashMap result = new HashMap<>(); @@ -158,5 +154,4 @@ public class HashMapConstructorBenchmark { } return result; } - */ }