jdk/test/java/lang/invoke/LFCaching/LambdaFormTestCase.java
author martin
Tue, 15 Sep 2015 21:56:04 -0700
changeset 32649 2ee9017c7597
parent 31179 a823fb6fdf2e
child 43535 7888ad60900f
permissions -rw-r--r--
8136583: Core libraries should use blessed modifier order Summary: Run blessed-modifier-order script (see bug) Reviewed-by: psandoz, chegar, alanb, plevart
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
26600
27b115fe8b3c 8057719: Develop new tests for LambdaForm Reduction and Caching feature
kshefov
parents:
diff changeset
     1
/*
31179
a823fb6fdf2e 8062904: TEST_BUG: Tests java/lang/invoke/LFCaching fail when run with -Xcomp option
kshefov
parents: 28405
diff changeset
     2
 * Copyright (c) 2014, 2015, Oracle and/or its affiliates. All rights reserved.
26600
27b115fe8b3c 8057719: Develop new tests for LambdaForm Reduction and Caching feature
kshefov
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
27b115fe8b3c 8057719: Develop new tests for LambdaForm Reduction and Caching feature
kshefov
parents:
diff changeset
     4
 *
27b115fe8b3c 8057719: Develop new tests for LambdaForm Reduction and Caching feature
kshefov
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
27b115fe8b3c 8057719: Develop new tests for LambdaForm Reduction and Caching feature
kshefov
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
27b115fe8b3c 8057719: Develop new tests for LambdaForm Reduction and Caching feature
kshefov
parents:
diff changeset
     7
 * published by the Free Software Foundation.
27b115fe8b3c 8057719: Develop new tests for LambdaForm Reduction and Caching feature
kshefov
parents:
diff changeset
     8
 *
27b115fe8b3c 8057719: Develop new tests for LambdaForm Reduction and Caching feature
kshefov
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
27b115fe8b3c 8057719: Develop new tests for LambdaForm Reduction and Caching feature
kshefov
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
27b115fe8b3c 8057719: Develop new tests for LambdaForm Reduction and Caching feature
kshefov
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
27b115fe8b3c 8057719: Develop new tests for LambdaForm Reduction and Caching feature
kshefov
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
27b115fe8b3c 8057719: Develop new tests for LambdaForm Reduction and Caching feature
kshefov
parents:
diff changeset
    13
 * accompanied this code).
27b115fe8b3c 8057719: Develop new tests for LambdaForm Reduction and Caching feature
kshefov
parents:
diff changeset
    14
 *
27b115fe8b3c 8057719: Develop new tests for LambdaForm Reduction and Caching feature
kshefov
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
27b115fe8b3c 8057719: Develop new tests for LambdaForm Reduction and Caching feature
kshefov
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
27b115fe8b3c 8057719: Develop new tests for LambdaForm Reduction and Caching feature
kshefov
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
27b115fe8b3c 8057719: Develop new tests for LambdaForm Reduction and Caching feature
kshefov
parents:
diff changeset
    18
 *
27b115fe8b3c 8057719: Develop new tests for LambdaForm Reduction and Caching feature
kshefov
parents:
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
27b115fe8b3c 8057719: Develop new tests for LambdaForm Reduction and Caching feature
kshefov
parents:
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
27b115fe8b3c 8057719: Develop new tests for LambdaForm Reduction and Caching feature
kshefov
parents:
diff changeset
    21
 * questions.
27b115fe8b3c 8057719: Develop new tests for LambdaForm Reduction and Caching feature
kshefov
parents:
diff changeset
    22
 */
27b115fe8b3c 8057719: Develop new tests for LambdaForm Reduction and Caching feature
kshefov
parents:
diff changeset
    23
27b115fe8b3c 8057719: Develop new tests for LambdaForm Reduction and Caching feature
kshefov
parents:
diff changeset
    24
import com.oracle.testlibrary.jsr292.Helper;
31179
a823fb6fdf2e 8062904: TEST_BUG: Tests java/lang/invoke/LFCaching fail when run with -Xcomp option
kshefov
parents: 28405
diff changeset
    25
import com.oracle.testlibrary.jsr292.CodeCacheOverflowProcessor;
28405
53e900131e21 8067344: Adjust java/lang/invoke/LFCaching/LFGarbageCollectedTest.java for recent changes in java.lang.invoke
vlivanov
parents: 27958
diff changeset
    26
import java.lang.invoke.MethodHandle;
27803
d04ca9d519ce 8057020: LambdaForm caches should support eviction
vlivanov
parents: 27758
diff changeset
    27
import java.lang.management.GarbageCollectorMXBean;
27030
4e989f27c905 8058733: [TESTBUG] java/lang/invoke/LFCaching/LFSingleThreadCachingTest.java and LFMultiThreadCachingTest.java failed on some platforms due to java.lang.VirtualMachineError
kshefov
parents: 26600
diff changeset
    28
import java.lang.management.ManagementFactory;
28405
53e900131e21 8067344: Adjust java/lang/invoke/LFCaching/LFGarbageCollectedTest.java for recent changes in java.lang.invoke
vlivanov
parents: 27958
diff changeset
    29
import java.lang.ref.Reference;
53e900131e21 8067344: Adjust java/lang/invoke/LFCaching/LFGarbageCollectedTest.java for recent changes in java.lang.invoke
vlivanov
parents: 27958
diff changeset
    30
import java.lang.reflect.Field;
26600
27b115fe8b3c 8057719: Develop new tests for LambdaForm Reduction and Caching feature
kshefov
parents:
diff changeset
    31
import java.lang.reflect.Method;
27b115fe8b3c 8057719: Develop new tests for LambdaForm Reduction and Caching feature
kshefov
parents:
diff changeset
    32
import java.util.Collection;
27803
d04ca9d519ce 8057020: LambdaForm caches should support eviction
vlivanov
parents: 27758
diff changeset
    33
import java.util.List;
26600
27b115fe8b3c 8057719: Develop new tests for LambdaForm Reduction and Caching feature
kshefov
parents:
diff changeset
    34
import java.util.function.Function;
27758
dfba484228ed 8059070: [TESTBUG] java/lang/invoke/LFCaching/LFMultiThreadCachingTest.java failed - timeout
kshefov
parents: 27030
diff changeset
    35
import jdk.testlibrary.Utils;
27958
51c87937ff0c 8066798: [TEST] Make java/lang/invoke/LFCaching tests use lib/testlibrary/jdk/testlibrary/TimeLimitedRunner.java to define their number of iterations
kshefov
parents: 27803
diff changeset
    36
import jdk.testlibrary.TimeLimitedRunner;
26600
27b115fe8b3c 8057719: Develop new tests for LambdaForm Reduction and Caching feature
kshefov
parents:
diff changeset
    37
27b115fe8b3c 8057719: Develop new tests for LambdaForm Reduction and Caching feature
kshefov
parents:
diff changeset
    38
/**
27b115fe8b3c 8057719: Develop new tests for LambdaForm Reduction and Caching feature
kshefov
parents:
diff changeset
    39
 * Lambda forms caching test case class. Contains all necessary test routines to
27b115fe8b3c 8057719: Develop new tests for LambdaForm Reduction and Caching feature
kshefov
parents:
diff changeset
    40
 * test lambda forms caching in method handles returned by methods of
27b115fe8b3c 8057719: Develop new tests for LambdaForm Reduction and Caching feature
kshefov
parents:
diff changeset
    41
 * MethodHandles class.
27b115fe8b3c 8057719: Develop new tests for LambdaForm Reduction and Caching feature
kshefov
parents:
diff changeset
    42
 *
27b115fe8b3c 8057719: Develop new tests for LambdaForm Reduction and Caching feature
kshefov
parents:
diff changeset
    43
 * @author kshefov
27b115fe8b3c 8057719: Develop new tests for LambdaForm Reduction and Caching feature
kshefov
parents:
diff changeset
    44
 */
27b115fe8b3c 8057719: Develop new tests for LambdaForm Reduction and Caching feature
kshefov
parents:
diff changeset
    45
public abstract class LambdaFormTestCase {
27b115fe8b3c 8057719: Develop new tests for LambdaForm Reduction and Caching feature
kshefov
parents:
diff changeset
    46
27958
51c87937ff0c 8066798: [TEST] Make java/lang/invoke/LFCaching tests use lib/testlibrary/jdk/testlibrary/TimeLimitedRunner.java to define their number of iterations
kshefov
parents: 27803
diff changeset
    47
    private static final long TIMEOUT = Helper.IS_THOROUGH ? 0L : (long) (Utils.adjustTimeout(Utils.DEFAULT_TEST_TIMEOUT) * 0.9);
26600
27b115fe8b3c 8057719: Develop new tests for LambdaForm Reduction and Caching feature
kshefov
parents:
diff changeset
    48
27b115fe8b3c 8057719: Develop new tests for LambdaForm Reduction and Caching feature
kshefov
parents:
diff changeset
    49
    /**
27b115fe8b3c 8057719: Develop new tests for LambdaForm Reduction and Caching feature
kshefov
parents:
diff changeset
    50
     * Reflection link to {@code j.l.i.MethodHandle.internalForm} method. It is
27b115fe8b3c 8057719: Develop new tests for LambdaForm Reduction and Caching feature
kshefov
parents:
diff changeset
    51
     * used to get a lambda form from a method handle.
27b115fe8b3c 8057719: Develop new tests for LambdaForm Reduction and Caching feature
kshefov
parents:
diff changeset
    52
     */
32649
2ee9017c7597 8136583: Core libraries should use blessed modifier order
martin
parents: 31179
diff changeset
    53
    protected static final Method INTERNAL_FORM;
2ee9017c7597 8136583: Core libraries should use blessed modifier order
martin
parents: 31179
diff changeset
    54
    protected static final Field DEBUG_NAME;
2ee9017c7597 8136583: Core libraries should use blessed modifier order
martin
parents: 31179
diff changeset
    55
    protected static final Field REF_FIELD;
27803
d04ca9d519ce 8057020: LambdaForm caches should support eviction
vlivanov
parents: 27758
diff changeset
    56
    private static final List<GarbageCollectorMXBean> gcInfo;
d04ca9d519ce 8057020: LambdaForm caches should support eviction
vlivanov
parents: 27758
diff changeset
    57
d04ca9d519ce 8057020: LambdaForm caches should support eviction
vlivanov
parents: 27758
diff changeset
    58
    private static long gcCount() {
d04ca9d519ce 8057020: LambdaForm caches should support eviction
vlivanov
parents: 27758
diff changeset
    59
        return gcInfo.stream().mapToLong(GarbageCollectorMXBean::getCollectionCount).sum();
d04ca9d519ce 8057020: LambdaForm caches should support eviction
vlivanov
parents: 27758
diff changeset
    60
    }
26600
27b115fe8b3c 8057719: Develop new tests for LambdaForm Reduction and Caching feature
kshefov
parents:
diff changeset
    61
27b115fe8b3c 8057719: Develop new tests for LambdaForm Reduction and Caching feature
kshefov
parents:
diff changeset
    62
    static {
27b115fe8b3c 8057719: Develop new tests for LambdaForm Reduction and Caching feature
kshefov
parents:
diff changeset
    63
        try {
28405
53e900131e21 8067344: Adjust java/lang/invoke/LFCaching/LFGarbageCollectedTest.java for recent changes in java.lang.invoke
vlivanov
parents: 27958
diff changeset
    64
            INTERNAL_FORM = MethodHandle.class.getDeclaredMethod("internalForm");
26600
27b115fe8b3c 8057719: Develop new tests for LambdaForm Reduction and Caching feature
kshefov
parents:
diff changeset
    65
            INTERNAL_FORM.setAccessible(true);
28405
53e900131e21 8067344: Adjust java/lang/invoke/LFCaching/LFGarbageCollectedTest.java for recent changes in java.lang.invoke
vlivanov
parents: 27958
diff changeset
    66
53e900131e21 8067344: Adjust java/lang/invoke/LFCaching/LFGarbageCollectedTest.java for recent changes in java.lang.invoke
vlivanov
parents: 27958
diff changeset
    67
            DEBUG_NAME = Class.forName("java.lang.invoke.LambdaForm").getDeclaredField("debugName");
53e900131e21 8067344: Adjust java/lang/invoke/LFCaching/LFGarbageCollectedTest.java for recent changes in java.lang.invoke
vlivanov
parents: 27958
diff changeset
    68
            DEBUG_NAME.setAccessible(true);
53e900131e21 8067344: Adjust java/lang/invoke/LFCaching/LFGarbageCollectedTest.java for recent changes in java.lang.invoke
vlivanov
parents: 27958
diff changeset
    69
53e900131e21 8067344: Adjust java/lang/invoke/LFCaching/LFGarbageCollectedTest.java for recent changes in java.lang.invoke
vlivanov
parents: 27958
diff changeset
    70
            REF_FIELD = Reference.class.getDeclaredField("referent");
53e900131e21 8067344: Adjust java/lang/invoke/LFCaching/LFGarbageCollectedTest.java for recent changes in java.lang.invoke
vlivanov
parents: 27958
diff changeset
    71
            REF_FIELD.setAccessible(true);
26600
27b115fe8b3c 8057719: Develop new tests for LambdaForm Reduction and Caching feature
kshefov
parents:
diff changeset
    72
        } catch (Exception ex) {
31179
a823fb6fdf2e 8062904: TEST_BUG: Tests java/lang/invoke/LFCaching fail when run with -Xcomp option
kshefov
parents: 28405
diff changeset
    73
            throw new Error("Unexpected exception", ex);
26600
27b115fe8b3c 8057719: Develop new tests for LambdaForm Reduction and Caching feature
kshefov
parents:
diff changeset
    74
        }
27803
d04ca9d519ce 8057020: LambdaForm caches should support eviction
vlivanov
parents: 27758
diff changeset
    75
d04ca9d519ce 8057020: LambdaForm caches should support eviction
vlivanov
parents: 27758
diff changeset
    76
        gcInfo = ManagementFactory.getGarbageCollectorMXBeans();
27958
51c87937ff0c 8066798: [TEST] Make java/lang/invoke/LFCaching tests use lib/testlibrary/jdk/testlibrary/TimeLimitedRunner.java to define their number of iterations
kshefov
parents: 27803
diff changeset
    77
        if (gcInfo.size() == 0) {
27803
d04ca9d519ce 8057020: LambdaForm caches should support eviction
vlivanov
parents: 27758
diff changeset
    78
            throw new Error("No GarbageCollectorMXBeans found.");
d04ca9d519ce 8057020: LambdaForm caches should support eviction
vlivanov
parents: 27758
diff changeset
    79
        }
26600
27b115fe8b3c 8057719: Develop new tests for LambdaForm Reduction and Caching feature
kshefov
parents:
diff changeset
    80
    }
27b115fe8b3c 8057719: Develop new tests for LambdaForm Reduction and Caching feature
kshefov
parents:
diff changeset
    81
27b115fe8b3c 8057719: Develop new tests for LambdaForm Reduction and Caching feature
kshefov
parents:
diff changeset
    82
    private final TestMethods testMethod;
27803
d04ca9d519ce 8057020: LambdaForm caches should support eviction
vlivanov
parents: 27758
diff changeset
    83
    private long gcCountAtStart;
27958
51c87937ff0c 8066798: [TEST] Make java/lang/invoke/LFCaching tests use lib/testlibrary/jdk/testlibrary/TimeLimitedRunner.java to define their number of iterations
kshefov
parents: 27803
diff changeset
    84
51c87937ff0c 8066798: [TEST] Make java/lang/invoke/LFCaching tests use lib/testlibrary/jdk/testlibrary/TimeLimitedRunner.java to define their number of iterations
kshefov
parents: 27803
diff changeset
    85
    private static class TestRun {
51c87937ff0c 8066798: [TEST] Make java/lang/invoke/LFCaching tests use lib/testlibrary/jdk/testlibrary/TimeLimitedRunner.java to define their number of iterations
kshefov
parents: 27803
diff changeset
    86
51c87937ff0c 8066798: [TEST] Make java/lang/invoke/LFCaching tests use lib/testlibrary/jdk/testlibrary/TimeLimitedRunner.java to define their number of iterations
kshefov
parents: 27803
diff changeset
    87
        final Function<TestMethods, LambdaFormTestCase> ctor;
51c87937ff0c 8066798: [TEST] Make java/lang/invoke/LFCaching tests use lib/testlibrary/jdk/testlibrary/TimeLimitedRunner.java to define their number of iterations
kshefov
parents: 27803
diff changeset
    88
        final Collection<TestMethods> testMethods;
51c87937ff0c 8066798: [TEST] Make java/lang/invoke/LFCaching tests use lib/testlibrary/jdk/testlibrary/TimeLimitedRunner.java to define their number of iterations
kshefov
parents: 27803
diff changeset
    89
        final long totalIterations;
51c87937ff0c 8066798: [TEST] Make java/lang/invoke/LFCaching tests use lib/testlibrary/jdk/testlibrary/TimeLimitedRunner.java to define their number of iterations
kshefov
parents: 27803
diff changeset
    90
        long doneIterations;
51c87937ff0c 8066798: [TEST] Make java/lang/invoke/LFCaching tests use lib/testlibrary/jdk/testlibrary/TimeLimitedRunner.java to define their number of iterations
kshefov
parents: 27803
diff changeset
    91
        long testCounter;
51c87937ff0c 8066798: [TEST] Make java/lang/invoke/LFCaching tests use lib/testlibrary/jdk/testlibrary/TimeLimitedRunner.java to define their number of iterations
kshefov
parents: 27803
diff changeset
    92
        long failCounter;
51c87937ff0c 8066798: [TEST] Make java/lang/invoke/LFCaching tests use lib/testlibrary/jdk/testlibrary/TimeLimitedRunner.java to define their number of iterations
kshefov
parents: 27803
diff changeset
    93
        boolean passed;
51c87937ff0c 8066798: [TEST] Make java/lang/invoke/LFCaching tests use lib/testlibrary/jdk/testlibrary/TimeLimitedRunner.java to define their number of iterations
kshefov
parents: 27803
diff changeset
    94
51c87937ff0c 8066798: [TEST] Make java/lang/invoke/LFCaching tests use lib/testlibrary/jdk/testlibrary/TimeLimitedRunner.java to define their number of iterations
kshefov
parents: 27803
diff changeset
    95
        TestRun(Function<TestMethods, LambdaFormTestCase> ctor, Collection<TestMethods> testMethods) {
51c87937ff0c 8066798: [TEST] Make java/lang/invoke/LFCaching tests use lib/testlibrary/jdk/testlibrary/TimeLimitedRunner.java to define their number of iterations
kshefov
parents: 27803
diff changeset
    96
            this.ctor = ctor;
51c87937ff0c 8066798: [TEST] Make java/lang/invoke/LFCaching tests use lib/testlibrary/jdk/testlibrary/TimeLimitedRunner.java to define their number of iterations
kshefov
parents: 27803
diff changeset
    97
            this.testMethods = testMethods;
51c87937ff0c 8066798: [TEST] Make java/lang/invoke/LFCaching tests use lib/testlibrary/jdk/testlibrary/TimeLimitedRunner.java to define their number of iterations
kshefov
parents: 27803
diff changeset
    98
            long testCaseNum = testMethods.size();
51c87937ff0c 8066798: [TEST] Make java/lang/invoke/LFCaching tests use lib/testlibrary/jdk/testlibrary/TimeLimitedRunner.java to define their number of iterations
kshefov
parents: 27803
diff changeset
    99
            long iterations = Math.max(1, Helper.TEST_LIMIT / testCaseNum);
51c87937ff0c 8066798: [TEST] Make java/lang/invoke/LFCaching tests use lib/testlibrary/jdk/testlibrary/TimeLimitedRunner.java to define their number of iterations
kshefov
parents: 27803
diff changeset
   100
            System.out.printf("Number of iterations according to -DtestLimit is %d (%d cases)%n",
51c87937ff0c 8066798: [TEST] Make java/lang/invoke/LFCaching tests use lib/testlibrary/jdk/testlibrary/TimeLimitedRunner.java to define their number of iterations
kshefov
parents: 27803
diff changeset
   101
                    iterations, iterations * testCaseNum);
51c87937ff0c 8066798: [TEST] Make java/lang/invoke/LFCaching tests use lib/testlibrary/jdk/testlibrary/TimeLimitedRunner.java to define their number of iterations
kshefov
parents: 27803
diff changeset
   102
            System.out.printf("Number of iterations is set to %d (%d cases)%n",
51c87937ff0c 8066798: [TEST] Make java/lang/invoke/LFCaching tests use lib/testlibrary/jdk/testlibrary/TimeLimitedRunner.java to define their number of iterations
kshefov
parents: 27803
diff changeset
   103
                    iterations, iterations * testCaseNum);
51c87937ff0c 8066798: [TEST] Make java/lang/invoke/LFCaching tests use lib/testlibrary/jdk/testlibrary/TimeLimitedRunner.java to define their number of iterations
kshefov
parents: 27803
diff changeset
   104
            System.out.flush();
51c87937ff0c 8066798: [TEST] Make java/lang/invoke/LFCaching tests use lib/testlibrary/jdk/testlibrary/TimeLimitedRunner.java to define their number of iterations
kshefov
parents: 27803
diff changeset
   105
            totalIterations = iterations;
51c87937ff0c 8066798: [TEST] Make java/lang/invoke/LFCaching tests use lib/testlibrary/jdk/testlibrary/TimeLimitedRunner.java to define their number of iterations
kshefov
parents: 27803
diff changeset
   106
            doneIterations = 0L;
51c87937ff0c 8066798: [TEST] Make java/lang/invoke/LFCaching tests use lib/testlibrary/jdk/testlibrary/TimeLimitedRunner.java to define their number of iterations
kshefov
parents: 27803
diff changeset
   107
            testCounter = 0L;
51c87937ff0c 8066798: [TEST] Make java/lang/invoke/LFCaching tests use lib/testlibrary/jdk/testlibrary/TimeLimitedRunner.java to define their number of iterations
kshefov
parents: 27803
diff changeset
   108
            failCounter = 0L;
51c87937ff0c 8066798: [TEST] Make java/lang/invoke/LFCaching tests use lib/testlibrary/jdk/testlibrary/TimeLimitedRunner.java to define their number of iterations
kshefov
parents: 27803
diff changeset
   109
            passed = true;
51c87937ff0c 8066798: [TEST] Make java/lang/invoke/LFCaching tests use lib/testlibrary/jdk/testlibrary/TimeLimitedRunner.java to define their number of iterations
kshefov
parents: 27803
diff changeset
   110
        }
51c87937ff0c 8066798: [TEST] Make java/lang/invoke/LFCaching tests use lib/testlibrary/jdk/testlibrary/TimeLimitedRunner.java to define their number of iterations
kshefov
parents: 27803
diff changeset
   111
51c87937ff0c 8066798: [TEST] Make java/lang/invoke/LFCaching tests use lib/testlibrary/jdk/testlibrary/TimeLimitedRunner.java to define their number of iterations
kshefov
parents: 27803
diff changeset
   112
        Boolean doIteration() {
51c87937ff0c 8066798: [TEST] Make java/lang/invoke/LFCaching tests use lib/testlibrary/jdk/testlibrary/TimeLimitedRunner.java to define their number of iterations
kshefov
parents: 27803
diff changeset
   113
            if (doneIterations >= totalIterations) {
51c87937ff0c 8066798: [TEST] Make java/lang/invoke/LFCaching tests use lib/testlibrary/jdk/testlibrary/TimeLimitedRunner.java to define their number of iterations
kshefov
parents: 27803
diff changeset
   114
                return false;
51c87937ff0c 8066798: [TEST] Make java/lang/invoke/LFCaching tests use lib/testlibrary/jdk/testlibrary/TimeLimitedRunner.java to define their number of iterations
kshefov
parents: 27803
diff changeset
   115
            }
51c87937ff0c 8066798: [TEST] Make java/lang/invoke/LFCaching tests use lib/testlibrary/jdk/testlibrary/TimeLimitedRunner.java to define their number of iterations
kshefov
parents: 27803
diff changeset
   116
            System.err.println(String.format("Iteration %d:", doneIterations));
51c87937ff0c 8066798: [TEST] Make java/lang/invoke/LFCaching tests use lib/testlibrary/jdk/testlibrary/TimeLimitedRunner.java to define their number of iterations
kshefov
parents: 27803
diff changeset
   117
            for (TestMethods testMethod : testMethods) {
51c87937ff0c 8066798: [TEST] Make java/lang/invoke/LFCaching tests use lib/testlibrary/jdk/testlibrary/TimeLimitedRunner.java to define their number of iterations
kshefov
parents: 27803
diff changeset
   118
                LambdaFormTestCase testCase = ctor.apply(testMethod);
51c87937ff0c 8066798: [TEST] Make java/lang/invoke/LFCaching tests use lib/testlibrary/jdk/testlibrary/TimeLimitedRunner.java to define their number of iterations
kshefov
parents: 27803
diff changeset
   119
                try {
31179
a823fb6fdf2e 8062904: TEST_BUG: Tests java/lang/invoke/LFCaching fail when run with -Xcomp option
kshefov
parents: 28405
diff changeset
   120
                    System.err.printf("Tested LF caching feature"
a823fb6fdf2e 8062904: TEST_BUG: Tests java/lang/invoke/LFCaching fail when run with -Xcomp option
kshefov
parents: 28405
diff changeset
   121
                            + " with MethodHandles.%s method.%n",
27958
51c87937ff0c 8066798: [TEST] Make java/lang/invoke/LFCaching tests use lib/testlibrary/jdk/testlibrary/TimeLimitedRunner.java to define their number of iterations
kshefov
parents: 27803
diff changeset
   122
                            testCase.getTestMethod().name);
31179
a823fb6fdf2e 8062904: TEST_BUG: Tests java/lang/invoke/LFCaching fail when run with -Xcomp option
kshefov
parents: 28405
diff changeset
   123
                    Throwable t = CodeCacheOverflowProcessor
a823fb6fdf2e 8062904: TEST_BUG: Tests java/lang/invoke/LFCaching fail when run with -Xcomp option
kshefov
parents: 28405
diff changeset
   124
                            .runMHTest(testCase::doTest);
a823fb6fdf2e 8062904: TEST_BUG: Tests java/lang/invoke/LFCaching fail when run with -Xcomp option
kshefov
parents: 28405
diff changeset
   125
                    if (t != null) {
a823fb6fdf2e 8062904: TEST_BUG: Tests java/lang/invoke/LFCaching fail when run with -Xcomp option
kshefov
parents: 28405
diff changeset
   126
                        return false;
a823fb6fdf2e 8062904: TEST_BUG: Tests java/lang/invoke/LFCaching fail when run with -Xcomp option
kshefov
parents: 28405
diff changeset
   127
                    }
27958
51c87937ff0c 8066798: [TEST] Make java/lang/invoke/LFCaching tests use lib/testlibrary/jdk/testlibrary/TimeLimitedRunner.java to define their number of iterations
kshefov
parents: 27803
diff changeset
   128
                    System.err.println("PASSED");
31179
a823fb6fdf2e 8062904: TEST_BUG: Tests java/lang/invoke/LFCaching fail when run with -Xcomp option
kshefov
parents: 28405
diff changeset
   129
                } catch (OutOfMemoryError oome) {
28405
53e900131e21 8067344: Adjust java/lang/invoke/LFCaching/LFGarbageCollectedTest.java for recent changes in java.lang.invoke
vlivanov
parents: 27958
diff changeset
   130
                    // Don't swallow OOME so a heap dump can be created.
53e900131e21 8067344: Adjust java/lang/invoke/LFCaching/LFGarbageCollectedTest.java for recent changes in java.lang.invoke
vlivanov
parents: 27958
diff changeset
   131
                    System.err.println("FAILED");
31179
a823fb6fdf2e 8062904: TEST_BUG: Tests java/lang/invoke/LFCaching fail when run with -Xcomp option
kshefov
parents: 28405
diff changeset
   132
                    throw oome;
27958
51c87937ff0c 8066798: [TEST] Make java/lang/invoke/LFCaching tests use lib/testlibrary/jdk/testlibrary/TimeLimitedRunner.java to define their number of iterations
kshefov
parents: 27803
diff changeset
   133
                } catch (Throwable t) {
51c87937ff0c 8066798: [TEST] Make java/lang/invoke/LFCaching tests use lib/testlibrary/jdk/testlibrary/TimeLimitedRunner.java to define their number of iterations
kshefov
parents: 27803
diff changeset
   134
                    t.printStackTrace();
51c87937ff0c 8066798: [TEST] Make java/lang/invoke/LFCaching tests use lib/testlibrary/jdk/testlibrary/TimeLimitedRunner.java to define their number of iterations
kshefov
parents: 27803
diff changeset
   135
                    System.err.printf("FAILED. Caused by %s%n", t.getMessage());
51c87937ff0c 8066798: [TEST] Make java/lang/invoke/LFCaching tests use lib/testlibrary/jdk/testlibrary/TimeLimitedRunner.java to define their number of iterations
kshefov
parents: 27803
diff changeset
   136
                    passed = false;
51c87937ff0c 8066798: [TEST] Make java/lang/invoke/LFCaching tests use lib/testlibrary/jdk/testlibrary/TimeLimitedRunner.java to define their number of iterations
kshefov
parents: 27803
diff changeset
   137
                    failCounter++;
51c87937ff0c 8066798: [TEST] Make java/lang/invoke/LFCaching tests use lib/testlibrary/jdk/testlibrary/TimeLimitedRunner.java to define their number of iterations
kshefov
parents: 27803
diff changeset
   138
                }
31179
a823fb6fdf2e 8062904: TEST_BUG: Tests java/lang/invoke/LFCaching fail when run with -Xcomp option
kshefov
parents: 28405
diff changeset
   139
                testCounter++;
a823fb6fdf2e 8062904: TEST_BUG: Tests java/lang/invoke/LFCaching fail when run with -Xcomp option
kshefov
parents: 28405
diff changeset
   140
            }
27958
51c87937ff0c 8066798: [TEST] Make java/lang/invoke/LFCaching tests use lib/testlibrary/jdk/testlibrary/TimeLimitedRunner.java to define their number of iterations
kshefov
parents: 27803
diff changeset
   141
            doneIterations++;
51c87937ff0c 8066798: [TEST] Make java/lang/invoke/LFCaching tests use lib/testlibrary/jdk/testlibrary/TimeLimitedRunner.java to define their number of iterations
kshefov
parents: 27803
diff changeset
   142
            return true;
51c87937ff0c 8066798: [TEST] Make java/lang/invoke/LFCaching tests use lib/testlibrary/jdk/testlibrary/TimeLimitedRunner.java to define their number of iterations
kshefov
parents: 27803
diff changeset
   143
        }
51c87937ff0c 8066798: [TEST] Make java/lang/invoke/LFCaching tests use lib/testlibrary/jdk/testlibrary/TimeLimitedRunner.java to define their number of iterations
kshefov
parents: 27803
diff changeset
   144
51c87937ff0c 8066798: [TEST] Make java/lang/invoke/LFCaching tests use lib/testlibrary/jdk/testlibrary/TimeLimitedRunner.java to define their number of iterations
kshefov
parents: 27803
diff changeset
   145
        void checkPassed() {
51c87937ff0c 8066798: [TEST] Make java/lang/invoke/LFCaching tests use lib/testlibrary/jdk/testlibrary/TimeLimitedRunner.java to define their number of iterations
kshefov
parents: 27803
diff changeset
   146
            if (!passed) {
51c87937ff0c 8066798: [TEST] Make java/lang/invoke/LFCaching tests use lib/testlibrary/jdk/testlibrary/TimeLimitedRunner.java to define their number of iterations
kshefov
parents: 27803
diff changeset
   147
                throw new Error(String.format("%d of %d test cases FAILED! %n"
51c87937ff0c 8066798: [TEST] Make java/lang/invoke/LFCaching tests use lib/testlibrary/jdk/testlibrary/TimeLimitedRunner.java to define their number of iterations
kshefov
parents: 27803
diff changeset
   148
                        + "Rerun the test with the same \"-Dseed=\" option as in the log file!",
51c87937ff0c 8066798: [TEST] Make java/lang/invoke/LFCaching tests use lib/testlibrary/jdk/testlibrary/TimeLimitedRunner.java to define their number of iterations
kshefov
parents: 27803
diff changeset
   149
                        failCounter, testCounter));
51c87937ff0c 8066798: [TEST] Make java/lang/invoke/LFCaching tests use lib/testlibrary/jdk/testlibrary/TimeLimitedRunner.java to define their number of iterations
kshefov
parents: 27803
diff changeset
   150
            } else {
51c87937ff0c 8066798: [TEST] Make java/lang/invoke/LFCaching tests use lib/testlibrary/jdk/testlibrary/TimeLimitedRunner.java to define their number of iterations
kshefov
parents: 27803
diff changeset
   151
                System.err.printf("All %d test cases PASSED!%n", testCounter);
51c87937ff0c 8066798: [TEST] Make java/lang/invoke/LFCaching tests use lib/testlibrary/jdk/testlibrary/TimeLimitedRunner.java to define their number of iterations
kshefov
parents: 27803
diff changeset
   152
            }
51c87937ff0c 8066798: [TEST] Make java/lang/invoke/LFCaching tests use lib/testlibrary/jdk/testlibrary/TimeLimitedRunner.java to define their number of iterations
kshefov
parents: 27803
diff changeset
   153
        }
51c87937ff0c 8066798: [TEST] Make java/lang/invoke/LFCaching tests use lib/testlibrary/jdk/testlibrary/TimeLimitedRunner.java to define their number of iterations
kshefov
parents: 27803
diff changeset
   154
    }
51c87937ff0c 8066798: [TEST] Make java/lang/invoke/LFCaching tests use lib/testlibrary/jdk/testlibrary/TimeLimitedRunner.java to define their number of iterations
kshefov
parents: 27803
diff changeset
   155
26600
27b115fe8b3c 8057719: Develop new tests for LambdaForm Reduction and Caching feature
kshefov
parents:
diff changeset
   156
    /**
27b115fe8b3c 8057719: Develop new tests for LambdaForm Reduction and Caching feature
kshefov
parents:
diff changeset
   157
     * Test case constructor. Generates test cases with random method types for
27b115fe8b3c 8057719: Develop new tests for LambdaForm Reduction and Caching feature
kshefov
parents:
diff changeset
   158
     * given methods form {@code j.l.i.MethodHandles} class.
27b115fe8b3c 8057719: Develop new tests for LambdaForm Reduction and Caching feature
kshefov
parents:
diff changeset
   159
     *
27b115fe8b3c 8057719: Develop new tests for LambdaForm Reduction and Caching feature
kshefov
parents:
diff changeset
   160
     * @param testMethod A method from {@code j.l.i.MethodHandles} class which
27b115fe8b3c 8057719: Develop new tests for LambdaForm Reduction and Caching feature
kshefov
parents:
diff changeset
   161
     * returns a {@code j.l.i.MethodHandle}.
27b115fe8b3c 8057719: Develop new tests for LambdaForm Reduction and Caching feature
kshefov
parents:
diff changeset
   162
     */
27b115fe8b3c 8057719: Develop new tests for LambdaForm Reduction and Caching feature
kshefov
parents:
diff changeset
   163
    protected LambdaFormTestCase(TestMethods testMethod) {
27b115fe8b3c 8057719: Develop new tests for LambdaForm Reduction and Caching feature
kshefov
parents:
diff changeset
   164
        this.testMethod = testMethod;
27803
d04ca9d519ce 8057020: LambdaForm caches should support eviction
vlivanov
parents: 27758
diff changeset
   165
        this.gcCountAtStart = gcCount();
26600
27b115fe8b3c 8057719: Develop new tests for LambdaForm Reduction and Caching feature
kshefov
parents:
diff changeset
   166
    }
27b115fe8b3c 8057719: Develop new tests for LambdaForm Reduction and Caching feature
kshefov
parents:
diff changeset
   167
27b115fe8b3c 8057719: Develop new tests for LambdaForm Reduction and Caching feature
kshefov
parents:
diff changeset
   168
    public TestMethods getTestMethod() {
27b115fe8b3c 8057719: Develop new tests for LambdaForm Reduction and Caching feature
kshefov
parents:
diff changeset
   169
        return testMethod;
27b115fe8b3c 8057719: Develop new tests for LambdaForm Reduction and Caching feature
kshefov
parents:
diff changeset
   170
    }
27b115fe8b3c 8057719: Develop new tests for LambdaForm Reduction and Caching feature
kshefov
parents:
diff changeset
   171
27803
d04ca9d519ce 8057020: LambdaForm caches should support eviction
vlivanov
parents: 27758
diff changeset
   172
    protected boolean noGCHappened() {
d04ca9d519ce 8057020: LambdaForm caches should support eviction
vlivanov
parents: 27758
diff changeset
   173
        return gcCount() == gcCountAtStart;
d04ca9d519ce 8057020: LambdaForm caches should support eviction
vlivanov
parents: 27758
diff changeset
   174
    }
d04ca9d519ce 8057020: LambdaForm caches should support eviction
vlivanov
parents: 27758
diff changeset
   175
26600
27b115fe8b3c 8057719: Develop new tests for LambdaForm Reduction and Caching feature
kshefov
parents:
diff changeset
   176
    /**
27b115fe8b3c 8057719: Develop new tests for LambdaForm Reduction and Caching feature
kshefov
parents:
diff changeset
   177
     * Routine that executes a test case.
27b115fe8b3c 8057719: Develop new tests for LambdaForm Reduction and Caching feature
kshefov
parents:
diff changeset
   178
     */
27b115fe8b3c 8057719: Develop new tests for LambdaForm Reduction and Caching feature
kshefov
parents:
diff changeset
   179
    public abstract void doTest();
27b115fe8b3c 8057719: Develop new tests for LambdaForm Reduction and Caching feature
kshefov
parents:
diff changeset
   180
27b115fe8b3c 8057719: Develop new tests for LambdaForm Reduction and Caching feature
kshefov
parents:
diff changeset
   181
    /**
27b115fe8b3c 8057719: Develop new tests for LambdaForm Reduction and Caching feature
kshefov
parents:
diff changeset
   182
     * Runs a number of test cases defined by the size of testCases list.
27b115fe8b3c 8057719: Develop new tests for LambdaForm Reduction and Caching feature
kshefov
parents:
diff changeset
   183
     *
27b115fe8b3c 8057719: Develop new tests for LambdaForm Reduction and Caching feature
kshefov
parents:
diff changeset
   184
     * @param ctor constructor of LambdaFormCachingTest or its child classes
27b115fe8b3c 8057719: Develop new tests for LambdaForm Reduction and Caching feature
kshefov
parents:
diff changeset
   185
     * object.
27b115fe8b3c 8057719: Develop new tests for LambdaForm Reduction and Caching feature
kshefov
parents:
diff changeset
   186
     * @param testMethods list of test methods
27b115fe8b3c 8057719: Develop new tests for LambdaForm Reduction and Caching feature
kshefov
parents:
diff changeset
   187
     */
27b115fe8b3c 8057719: Develop new tests for LambdaForm Reduction and Caching feature
kshefov
parents:
diff changeset
   188
    public static void runTests(Function<TestMethods, LambdaFormTestCase> ctor, Collection<TestMethods> testMethods) {
31179
a823fb6fdf2e 8062904: TEST_BUG: Tests java/lang/invoke/LFCaching fail when run with -Xcomp option
kshefov
parents: 28405
diff changeset
   189
        LambdaFormTestCase.TestRun run
a823fb6fdf2e 8062904: TEST_BUG: Tests java/lang/invoke/LFCaching fail when run with -Xcomp option
kshefov
parents: 28405
diff changeset
   190
                = new LambdaFormTestCase.TestRun(ctor, testMethods);
27958
51c87937ff0c 8066798: [TEST] Make java/lang/invoke/LFCaching tests use lib/testlibrary/jdk/testlibrary/TimeLimitedRunner.java to define their number of iterations
kshefov
parents: 27803
diff changeset
   191
        TimeLimitedRunner runner = new TimeLimitedRunner(TIMEOUT, 4.0d, run::doIteration);
51c87937ff0c 8066798: [TEST] Make java/lang/invoke/LFCaching tests use lib/testlibrary/jdk/testlibrary/TimeLimitedRunner.java to define their number of iterations
kshefov
parents: 27803
diff changeset
   192
        try {
51c87937ff0c 8066798: [TEST] Make java/lang/invoke/LFCaching tests use lib/testlibrary/jdk/testlibrary/TimeLimitedRunner.java to define their number of iterations
kshefov
parents: 27803
diff changeset
   193
            runner.call();
51c87937ff0c 8066798: [TEST] Make java/lang/invoke/LFCaching tests use lib/testlibrary/jdk/testlibrary/TimeLimitedRunner.java to define their number of iterations
kshefov
parents: 27803
diff changeset
   194
        } catch (Exception ex) {
51c87937ff0c 8066798: [TEST] Make java/lang/invoke/LFCaching tests use lib/testlibrary/jdk/testlibrary/TimeLimitedRunner.java to define their number of iterations
kshefov
parents: 27803
diff changeset
   195
            System.err.println("FAILED");
51c87937ff0c 8066798: [TEST] Make java/lang/invoke/LFCaching tests use lib/testlibrary/jdk/testlibrary/TimeLimitedRunner.java to define their number of iterations
kshefov
parents: 27803
diff changeset
   196
            throw new Error("Unexpected error!", ex);
27030
4e989f27c905 8058733: [TESTBUG] java/lang/invoke/LFCaching/LFSingleThreadCachingTest.java and LFMultiThreadCachingTest.java failed on some platforms due to java.lang.VirtualMachineError
kshefov
parents: 26600
diff changeset
   197
        }
27958
51c87937ff0c 8066798: [TEST] Make java/lang/invoke/LFCaching tests use lib/testlibrary/jdk/testlibrary/TimeLimitedRunner.java to define their number of iterations
kshefov
parents: 27803
diff changeset
   198
        run.checkPassed();
26600
27b115fe8b3c 8057719: Develop new tests for LambdaForm Reduction and Caching feature
kshefov
parents:
diff changeset
   199
    }
27b115fe8b3c 8057719: Develop new tests for LambdaForm Reduction and Caching feature
kshefov
parents:
diff changeset
   200
}