< prev index next >

test/jdk/java/util/HashMap/WhiteBoxResizeTest.java

Print this page

  1 /*
  2  * Copyright (c) 2018, Red Hat, Inc. All rights reserved.
  3  * Copyright (c) 2022, Oracle and/or its affiliates. All rights reserved.
  4  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  5  *
  6  * This code is free software; you can redistribute it and/or modify it
  7  * under the terms of the GNU General Public License version 2 only, as
  8  * published by the Free Software Foundation.
  9  *
 10  * This code is distributed in the hope that it will be useful, but WITHOUT
 11  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
 12  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
 13  * version 2 for more details (a copy is included in the LICENSE file that
 14  * accompanied this code).
 15  *
 16  * You should have received a copy of the GNU General Public License version
 17  * 2 along with this work; if not, write to the Free Software Foundation,
 18  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
 19  *
 20  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
 21  * or visit www.oracle.com if you need additional information or have any
 22  * questions.
 23  */

 38 import java.util.Iterator;
 39 import java.util.LinkedHashMap;
 40 import java.util.LinkedHashSet;
 41 import java.util.List;
 42 import java.util.Map;
 43 import java.util.Set;
 44 import java.util.WeakHashMap;
 45 import java.util.function.Consumer;
 46 import java.util.function.IntFunction;
 47 import java.util.function.Supplier;
 48 
 49 import static org.testng.Assert.assertEquals;
 50 import static org.testng.Assert.assertNull;
 51 import static org.testng.Assert.assertThrows;
 52 
 53 /*
 54  * @test
 55  * @bug 8186958 8210280 8281631 8285386 8284780
 56  * @modules java.base/java.util:open
 57  * @summary White box tests for HashMap-related internals around table sizing


 58  * @run testng/othervm -Xmx2g WhiteBoxResizeTest
 59  */
 60 public class WhiteBoxResizeTest {
 61 
 62     final MethodHandle TABLE_SIZE_FOR;
 63     final VarHandle HM_TABLE;
 64     final VarHandle WHM_TABLE;
 65     final VarHandle HS_MAP;
 66 
 67     public WhiteBoxResizeTest() throws ReflectiveOperationException {
 68         MethodHandles.Lookup hmlookup = MethodHandles.privateLookupIn(HashMap.class, MethodHandles.lookup());
 69         TABLE_SIZE_FOR = hmlookup.findStatic(
 70                 HashMap.class, "tableSizeFor", MethodType.methodType(int.class, int.class));
 71         HM_TABLE = hmlookup.unreflectVarHandle(HashMap.class.getDeclaredField("table"));
 72 
 73         MethodHandles.Lookup whmlookup = MethodHandles.privateLookupIn(WeakHashMap.class, MethodHandles.lookup());
 74         WHM_TABLE = whmlookup.unreflectVarHandle(WeakHashMap.class.getDeclaredField("table"));
 75 
 76         MethodHandles.Lookup hslookup = MethodHandles.privateLookupIn(HashSet.class, MethodHandles.lookup());
 77         HS_MAP = hslookup.unreflectVarHandle(HashSet.class.getDeclaredField("map"));

  1 /*
  2  * Copyright (c) 2018, Red Hat, Inc. All rights reserved.
  3  * Copyright (c) 2022, 2024, Oracle and/or its affiliates. All rights reserved.
  4  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  5  *
  6  * This code is free software; you can redistribute it and/or modify it
  7  * under the terms of the GNU General Public License version 2 only, as
  8  * published by the Free Software Foundation.
  9  *
 10  * This code is distributed in the hope that it will be useful, but WITHOUT
 11  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
 12  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
 13  * version 2 for more details (a copy is included in the LICENSE file that
 14  * accompanied this code).
 15  *
 16  * You should have received a copy of the GNU General Public License version
 17  * 2 along with this work; if not, write to the Free Software Foundation,
 18  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
 19  *
 20  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
 21  * or visit www.oracle.com if you need additional information or have any
 22  * questions.
 23  */

 38 import java.util.Iterator;
 39 import java.util.LinkedHashMap;
 40 import java.util.LinkedHashSet;
 41 import java.util.List;
 42 import java.util.Map;
 43 import java.util.Set;
 44 import java.util.WeakHashMap;
 45 import java.util.function.Consumer;
 46 import java.util.function.IntFunction;
 47 import java.util.function.Supplier;
 48 
 49 import static org.testng.Assert.assertEquals;
 50 import static org.testng.Assert.assertNull;
 51 import static org.testng.Assert.assertThrows;
 52 
 53 /*
 54  * @test
 55  * @bug 8186958 8210280 8281631 8285386 8284780
 56  * @modules java.base/java.util:open
 57  * @summary White box tests for HashMap-related internals around table sizing
 58  * @comment skip running this test on 32 bit VM
 59  * @requires vm.bits == "64"
 60  * @run testng/othervm -Xmx2g WhiteBoxResizeTest
 61  */
 62 public class WhiteBoxResizeTest {
 63 
 64     final MethodHandle TABLE_SIZE_FOR;
 65     final VarHandle HM_TABLE;
 66     final VarHandle WHM_TABLE;
 67     final VarHandle HS_MAP;
 68 
 69     public WhiteBoxResizeTest() throws ReflectiveOperationException {
 70         MethodHandles.Lookup hmlookup = MethodHandles.privateLookupIn(HashMap.class, MethodHandles.lookup());
 71         TABLE_SIZE_FOR = hmlookup.findStatic(
 72                 HashMap.class, "tableSizeFor", MethodType.methodType(int.class, int.class));
 73         HM_TABLE = hmlookup.unreflectVarHandle(HashMap.class.getDeclaredField("table"));
 74 
 75         MethodHandles.Lookup whmlookup = MethodHandles.privateLookupIn(WeakHashMap.class, MethodHandles.lookup());
 76         WHM_TABLE = whmlookup.unreflectVarHandle(WeakHashMap.class.getDeclaredField("table"));
 77 
 78         MethodHandles.Lookup hslookup = MethodHandles.privateLookupIn(HashSet.class, MethodHandles.lookup());
 79         HS_MAP = hslookup.unreflectVarHandle(HashSet.class.getDeclaredField("map"));
< prev index next >