Path: blob/master/test/jdk/java/lang/invoke/LFCaching/LFSingleThreadCachingTest.java
41152 views
/*1* Copyright (c) 2014, 2017, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation.7*8* This code is distributed in the hope that it will be useful, but WITHOUT9* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or10* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License11* version 2 for more details (a copy is included in the LICENSE file that12* accompanied this code).13*14* You should have received a copy of the GNU General Public License version15* 2 along with this work; if not, write to the Free Software Foundation,16* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.17*18* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA19* or visit www.oracle.com if you need additional information or have any20* questions.21*/2223/*24* @test LFSingleThreadCachingTest25* @bug 804670326* @key randomness27* @summary Test verifies that lambda forms are cached when run with single thread28* @author kshefov29* @library /lib/testlibrary /java/lang/invoke/common /test/lib30* @modules java.base/java.lang.ref:open31* java.base/java.lang.invoke:open32* java.management33* @build jdk.test.lib.TimeLimitedRunner34* @build TestMethods35* @build LambdaFormTestCase36* @build LFCachingTestCase37* @build LFSingleThreadCachingTest38* @run main/othervm -XX:ReservedCodeCacheSize=128m LFSingleThreadCachingTest39*/4041import java.lang.invoke.MethodHandle;42import java.util.EnumSet;43import java.util.Map;4445/**46* Single threaded lambda forms caching test class.47*/48public final class LFSingleThreadCachingTest extends LFCachingTestCase {4950/**51* Constructor for a single threaded lambda forms caching test case.52*53* @param testMethod A method from {@code j.l.i.MethodHandles} class that54* returns a {@code j.l.i.MethodHandle} instance.55*/56public LFSingleThreadCachingTest(TestMethods testMethod) {57super(testMethod);58}5960@Override61public void doTest() {62MethodHandle adapter1;63MethodHandle adapter2;64Map<String, Object> data = getTestMethod().getTestCaseData();65try {66adapter1 = getTestMethod().getTestCaseMH(data, TestMethods.Kind.ONE);67adapter2 = getTestMethod().getTestCaseMH(data, TestMethods.Kind.TWO);68} catch (NoSuchMethodException | IllegalAccessException ex) {69throw new Error("Unexpected exception", ex);70}71checkLFCaching(adapter1, adapter2);72}7374/**75* Main routine for single threaded lambda forms caching test.76*77* @param args Accepts no arguments.78*/79public static void main(String[] args) {80LambdaFormTestCase.runTests(LFSingleThreadCachingTest::new,81EnumSet.allOf(TestMethods.class));82}83}848586