hotspot/test/compiler/jsr292/ContinuousCallSiteTargetChange.java
author vlivanov
Mon, 30 Jan 2017 16:04:22 +0300
changeset 43674 5d984252fc26
parent 40631 ed82623d7831
permissions -rw-r--r--
8173404: C2: wrong nmethod dependency can be recorded for CallSite.target Reviewed-by: kvn
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
36300
5b47f168b948 7177745: JSR292: Many Callsite relinkages cause target method to always run in interpreter mode
vlivanov
parents:
diff changeset
     1
/*
5b47f168b948 7177745: JSR292: Many Callsite relinkages cause target method to always run in interpreter mode
vlivanov
parents:
diff changeset
     2
 * Copyright (c) 2016, Oracle and/or its affiliates. All rights reserved.
5b47f168b948 7177745: JSR292: Many Callsite relinkages cause target method to always run in interpreter mode
vlivanov
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5b47f168b948 7177745: JSR292: Many Callsite relinkages cause target method to always run in interpreter mode
vlivanov
parents:
diff changeset
     4
 *
5b47f168b948 7177745: JSR292: Many Callsite relinkages cause target method to always run in interpreter mode
vlivanov
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
5b47f168b948 7177745: JSR292: Many Callsite relinkages cause target method to always run in interpreter mode
vlivanov
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
5b47f168b948 7177745: JSR292: Many Callsite relinkages cause target method to always run in interpreter mode
vlivanov
parents:
diff changeset
     7
 * published by the Free Software Foundation.
5b47f168b948 7177745: JSR292: Many Callsite relinkages cause target method to always run in interpreter mode
vlivanov
parents:
diff changeset
     8
 *
5b47f168b948 7177745: JSR292: Many Callsite relinkages cause target method to always run in interpreter mode
vlivanov
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
5b47f168b948 7177745: JSR292: Many Callsite relinkages cause target method to always run in interpreter mode
vlivanov
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
5b47f168b948 7177745: JSR292: Many Callsite relinkages cause target method to always run in interpreter mode
vlivanov
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
5b47f168b948 7177745: JSR292: Many Callsite relinkages cause target method to always run in interpreter mode
vlivanov
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
5b47f168b948 7177745: JSR292: Many Callsite relinkages cause target method to always run in interpreter mode
vlivanov
parents:
diff changeset
    13
 * accompanied this code).
5b47f168b948 7177745: JSR292: Many Callsite relinkages cause target method to always run in interpreter mode
vlivanov
parents:
diff changeset
    14
 *
5b47f168b948 7177745: JSR292: Many Callsite relinkages cause target method to always run in interpreter mode
vlivanov
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
5b47f168b948 7177745: JSR292: Many Callsite relinkages cause target method to always run in interpreter mode
vlivanov
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
5b47f168b948 7177745: JSR292: Many Callsite relinkages cause target method to always run in interpreter mode
vlivanov
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
5b47f168b948 7177745: JSR292: Many Callsite relinkages cause target method to always run in interpreter mode
vlivanov
parents:
diff changeset
    18
 *
5b47f168b948 7177745: JSR292: Many Callsite relinkages cause target method to always run in interpreter mode
vlivanov
parents:
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
5b47f168b948 7177745: JSR292: Many Callsite relinkages cause target method to always run in interpreter mode
vlivanov
parents:
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
5b47f168b948 7177745: JSR292: Many Callsite relinkages cause target method to always run in interpreter mode
vlivanov
parents:
diff changeset
    21
 * questions.
5b47f168b948 7177745: JSR292: Many Callsite relinkages cause target method to always run in interpreter mode
vlivanov
parents:
diff changeset
    22
 */
5b47f168b948 7177745: JSR292: Many Callsite relinkages cause target method to always run in interpreter mode
vlivanov
parents:
diff changeset
    23
5b47f168b948 7177745: JSR292: Many Callsite relinkages cause target method to always run in interpreter mode
vlivanov
parents:
diff changeset
    24
/**
5b47f168b948 7177745: JSR292: Many Callsite relinkages cause target method to always run in interpreter mode
vlivanov
parents:
diff changeset
    25
 * @test
40631
ed82623d7831 8157957: ClassNotFoundException: jdk.test.lib.JDKToolFinder
ctornqvi
parents: 40059
diff changeset
    26
 * @library /test/lib /
40059
c2304140ed64 8132919: Put compiler tests in packages
tpivovarova
parents: 38152
diff changeset
    27
 *
c2304140ed64 8132919: Put compiler tests in packages
tpivovarova
parents: 38152
diff changeset
    28
 * @run driver compiler.jsr292.ContinuousCallSiteTargetChange
36300
5b47f168b948 7177745: JSR292: Many Callsite relinkages cause target method to always run in interpreter mode
vlivanov
parents:
diff changeset
    29
 */
40059
c2304140ed64 8132919: Put compiler tests in packages
tpivovarova
parents: 38152
diff changeset
    30
c2304140ed64 8132919: Put compiler tests in packages
tpivovarova
parents: 38152
diff changeset
    31
package compiler.jsr292;
c2304140ed64 8132919: Put compiler tests in packages
tpivovarova
parents: 38152
diff changeset
    32
43674
5d984252fc26 8173404: C2: wrong nmethod dependency can be recorded for CallSite.target
vlivanov
parents: 40631
diff changeset
    33
import jdk.test.lib.Asserts;
40631
ed82623d7831 8157957: ClassNotFoundException: jdk.test.lib.JDKToolFinder
ctornqvi
parents: 40059
diff changeset
    34
import jdk.test.lib.process.OutputAnalyzer;
ed82623d7831 8157957: ClassNotFoundException: jdk.test.lib.JDKToolFinder
ctornqvi
parents: 40059
diff changeset
    35
import jdk.test.lib.process.ProcessTools;
40059
c2304140ed64 8132919: Put compiler tests in packages
tpivovarova
parents: 38152
diff changeset
    36
c2304140ed64 8132919: Put compiler tests in packages
tpivovarova
parents: 38152
diff changeset
    37
import java.lang.invoke.CallSite;
c2304140ed64 8132919: Put compiler tests in packages
tpivovarova
parents: 38152
diff changeset
    38
import java.lang.invoke.MethodHandle;
c2304140ed64 8132919: Put compiler tests in packages
tpivovarova
parents: 38152
diff changeset
    39
import java.lang.invoke.MethodHandles;
c2304140ed64 8132919: Put compiler tests in packages
tpivovarova
parents: 38152
diff changeset
    40
import java.lang.invoke.MethodType;
c2304140ed64 8132919: Put compiler tests in packages
tpivovarova
parents: 38152
diff changeset
    41
import java.lang.invoke.MutableCallSite;
43674
5d984252fc26 8173404: C2: wrong nmethod dependency can be recorded for CallSite.target
vlivanov
parents: 40631
diff changeset
    42
import java.util.ArrayList;
5d984252fc26 8173404: C2: wrong nmethod dependency can be recorded for CallSite.target
vlivanov
parents: 40631
diff changeset
    43
import java.util.Arrays;
5d984252fc26 8173404: C2: wrong nmethod dependency can be recorded for CallSite.target
vlivanov
parents: 40631
diff changeset
    44
import java.util.List;
36300
5b47f168b948 7177745: JSR292: Many Callsite relinkages cause target method to always run in interpreter mode
vlivanov
parents:
diff changeset
    45
5b47f168b948 7177745: JSR292: Many Callsite relinkages cause target method to always run in interpreter mode
vlivanov
parents:
diff changeset
    46
public class ContinuousCallSiteTargetChange {
43674
5d984252fc26 8173404: C2: wrong nmethod dependency can be recorded for CallSite.target
vlivanov
parents: 40631
diff changeset
    47
    static final int ITERATIONS = Integer.parseInt(System.getProperty("iterations", "50"));
5d984252fc26 8173404: C2: wrong nmethod dependency can be recorded for CallSite.target
vlivanov
parents: 40631
diff changeset
    48
5d984252fc26 8173404: C2: wrong nmethod dependency can be recorded for CallSite.target
vlivanov
parents: 40631
diff changeset
    49
    static void runTest(Class<?> test, String... extraArgs) throws Exception {
5d984252fc26 8173404: C2: wrong nmethod dependency can be recorded for CallSite.target
vlivanov
parents: 40631
diff changeset
    50
        List<String> argsList = new ArrayList<>(
5d984252fc26 8173404: C2: wrong nmethod dependency can be recorded for CallSite.target
vlivanov
parents: 40631
diff changeset
    51
                List.of("-XX:+IgnoreUnrecognizedVMOptions",
5d984252fc26 8173404: C2: wrong nmethod dependency can be recorded for CallSite.target
vlivanov
parents: 40631
diff changeset
    52
                    "-XX:PerBytecodeRecompilationCutoff=10", "-XX:PerMethodRecompilationCutoff=10",
5d984252fc26 8173404: C2: wrong nmethod dependency can be recorded for CallSite.target
vlivanov
parents: 40631
diff changeset
    53
                    "-XX:+PrintCompilation", "-XX:+UnlockDiagnosticVMOptions", "-XX:+PrintInlining"));
5d984252fc26 8173404: C2: wrong nmethod dependency can be recorded for CallSite.target
vlivanov
parents: 40631
diff changeset
    54
5d984252fc26 8173404: C2: wrong nmethod dependency can be recorded for CallSite.target
vlivanov
parents: 40631
diff changeset
    55
        argsList.addAll(Arrays.asList(extraArgs));
5d984252fc26 8173404: C2: wrong nmethod dependency can be recorded for CallSite.target
vlivanov
parents: 40631
diff changeset
    56
5d984252fc26 8173404: C2: wrong nmethod dependency can be recorded for CallSite.target
vlivanov
parents: 40631
diff changeset
    57
        argsList.add(test.getName());
5d984252fc26 8173404: C2: wrong nmethod dependency can be recorded for CallSite.target
vlivanov
parents: 40631
diff changeset
    58
        argsList.add(Integer.toString(ITERATIONS));
5d984252fc26 8173404: C2: wrong nmethod dependency can be recorded for CallSite.target
vlivanov
parents: 40631
diff changeset
    59
36300
5b47f168b948 7177745: JSR292: Many Callsite relinkages cause target method to always run in interpreter mode
vlivanov
parents:
diff changeset
    60
        ProcessBuilder pb = ProcessTools.createJavaProcessBuilder(
43674
5d984252fc26 8173404: C2: wrong nmethod dependency can be recorded for CallSite.target
vlivanov
parents: 40631
diff changeset
    61
                argsList.toArray(new String[argsList.size()]));
36300
5b47f168b948 7177745: JSR292: Many Callsite relinkages cause target method to always run in interpreter mode
vlivanov
parents:
diff changeset
    62
5b47f168b948 7177745: JSR292: Many Callsite relinkages cause target method to always run in interpreter mode
vlivanov
parents:
diff changeset
    63
        OutputAnalyzer analyzer = new OutputAnalyzer(pb.start());
5b47f168b948 7177745: JSR292: Many Callsite relinkages cause target method to always run in interpreter mode
vlivanov
parents:
diff changeset
    64
5b47f168b948 7177745: JSR292: Many Callsite relinkages cause target method to always run in interpreter mode
vlivanov
parents:
diff changeset
    65
        analyzer.shouldHaveExitValue(0);
5b47f168b948 7177745: JSR292: Many Callsite relinkages cause target method to always run in interpreter mode
vlivanov
parents:
diff changeset
    66
5b47f168b948 7177745: JSR292: Many Callsite relinkages cause target method to always run in interpreter mode
vlivanov
parents:
diff changeset
    67
        analyzer.shouldNotContain("made not compilable");
5b47f168b948 7177745: JSR292: Many Callsite relinkages cause target method to always run in interpreter mode
vlivanov
parents:
diff changeset
    68
        analyzer.shouldNotContain("decompile_count > PerMethodRecompilationCutoff");
43674
5d984252fc26 8173404: C2: wrong nmethod dependency can be recorded for CallSite.target
vlivanov
parents: 40631
diff changeset
    69
36300
5b47f168b948 7177745: JSR292: Many Callsite relinkages cause target method to always run in interpreter mode
vlivanov
parents:
diff changeset
    70
    }
5b47f168b948 7177745: JSR292: Many Callsite relinkages cause target method to always run in interpreter mode
vlivanov
parents:
diff changeset
    71
43674
5d984252fc26 8173404: C2: wrong nmethod dependency can be recorded for CallSite.target
vlivanov
parents: 40631
diff changeset
    72
    static void testServer(Class<?> test, String... args) throws Exception {
5d984252fc26 8173404: C2: wrong nmethod dependency can be recorded for CallSite.target
vlivanov
parents: 40631
diff changeset
    73
        List<String> extraArgsList = new ArrayList<>(
5d984252fc26 8173404: C2: wrong nmethod dependency can be recorded for CallSite.target
vlivanov
parents: 40631
diff changeset
    74
                List.of("-server", "-XX:-TieredCompilation"));
5d984252fc26 8173404: C2: wrong nmethod dependency can be recorded for CallSite.target
vlivanov
parents: 40631
diff changeset
    75
        extraArgsList.addAll(Arrays.asList(args));
36300
5b47f168b948 7177745: JSR292: Many Callsite relinkages cause target method to always run in interpreter mode
vlivanov
parents:
diff changeset
    76
43674
5d984252fc26 8173404: C2: wrong nmethod dependency can be recorded for CallSite.target
vlivanov
parents: 40631
diff changeset
    77
        runTest(test, extraArgsList.toArray(new String[extraArgsList.size()]));
5d984252fc26 8173404: C2: wrong nmethod dependency can be recorded for CallSite.target
vlivanov
parents: 40631
diff changeset
    78
    }
36300
5b47f168b948 7177745: JSR292: Many Callsite relinkages cause target method to always run in interpreter mode
vlivanov
parents:
diff changeset
    79
43674
5d984252fc26 8173404: C2: wrong nmethod dependency can be recorded for CallSite.target
vlivanov
parents: 40631
diff changeset
    80
    static void testClient(Class<?> test, String... args) throws Exception {
5d984252fc26 8173404: C2: wrong nmethod dependency can be recorded for CallSite.target
vlivanov
parents: 40631
diff changeset
    81
        List<String> extraArgsList = new ArrayList<>(
5d984252fc26 8173404: C2: wrong nmethod dependency can be recorded for CallSite.target
vlivanov
parents: 40631
diff changeset
    82
                List.of("-client", "-XX:+TieredCompilation", "-XX:TieredStopAtLevel=1"));
5d984252fc26 8173404: C2: wrong nmethod dependency can be recorded for CallSite.target
vlivanov
parents: 40631
diff changeset
    83
        extraArgsList.addAll(Arrays.asList(args));
36300
5b47f168b948 7177745: JSR292: Many Callsite relinkages cause target method to always run in interpreter mode
vlivanov
parents:
diff changeset
    84
43674
5d984252fc26 8173404: C2: wrong nmethod dependency can be recorded for CallSite.target
vlivanov
parents: 40631
diff changeset
    85
        runTest(test, extraArgsList.toArray(new String[extraArgsList.size()]));
36300
5b47f168b948 7177745: JSR292: Many Callsite relinkages cause target method to always run in interpreter mode
vlivanov
parents:
diff changeset
    86
    }
5b47f168b948 7177745: JSR292: Many Callsite relinkages cause target method to always run in interpreter mode
vlivanov
parents:
diff changeset
    87
5b47f168b948 7177745: JSR292: Many Callsite relinkages cause target method to always run in interpreter mode
vlivanov
parents:
diff changeset
    88
    public static void main(String[] args) throws Exception {
43674
5d984252fc26 8173404: C2: wrong nmethod dependency can be recorded for CallSite.target
vlivanov
parents: 40631
diff changeset
    89
        testServer(RecompilationTest.class, "-Xbatch");
5d984252fc26 8173404: C2: wrong nmethod dependency can be recorded for CallSite.target
vlivanov
parents: 40631
diff changeset
    90
        testClient(RecompilationTest.class, "-Xbatch");
5d984252fc26 8173404: C2: wrong nmethod dependency can be recorded for CallSite.target
vlivanov
parents: 40631
diff changeset
    91
5d984252fc26 8173404: C2: wrong nmethod dependency can be recorded for CallSite.target
vlivanov
parents: 40631
diff changeset
    92
        testServer(PingPongTest.class);
5d984252fc26 8173404: C2: wrong nmethod dependency can be recorded for CallSite.target
vlivanov
parents: 40631
diff changeset
    93
        testClient(PingPongTest.class);
36300
5b47f168b948 7177745: JSR292: Many Callsite relinkages cause target method to always run in interpreter mode
vlivanov
parents:
diff changeset
    94
    }
5b47f168b948 7177745: JSR292: Many Callsite relinkages cause target method to always run in interpreter mode
vlivanov
parents:
diff changeset
    95
43674
5d984252fc26 8173404: C2: wrong nmethod dependency can be recorded for CallSite.target
vlivanov
parents: 40631
diff changeset
    96
    static MethodHandle findStatic(Class<?> cls, String name, MethodType mt) {
5d984252fc26 8173404: C2: wrong nmethod dependency can be recorded for CallSite.target
vlivanov
parents: 40631
diff changeset
    97
        try {
5d984252fc26 8173404: C2: wrong nmethod dependency can be recorded for CallSite.target
vlivanov
parents: 40631
diff changeset
    98
            return MethodHandles.lookup().findStatic(cls, name, mt);
5d984252fc26 8173404: C2: wrong nmethod dependency can be recorded for CallSite.target
vlivanov
parents: 40631
diff changeset
    99
        } catch (Exception e) {
5d984252fc26 8173404: C2: wrong nmethod dependency can be recorded for CallSite.target
vlivanov
parents: 40631
diff changeset
   100
            throw new Error(e);
5d984252fc26 8173404: C2: wrong nmethod dependency can be recorded for CallSite.target
vlivanov
parents: 40631
diff changeset
   101
        }
5d984252fc26 8173404: C2: wrong nmethod dependency can be recorded for CallSite.target
vlivanov
parents: 40631
diff changeset
   102
    }
5d984252fc26 8173404: C2: wrong nmethod dependency can be recorded for CallSite.target
vlivanov
parents: 40631
diff changeset
   103
5d984252fc26 8173404: C2: wrong nmethod dependency can be recorded for CallSite.target
vlivanov
parents: 40631
diff changeset
   104
    static class RecompilationTest {
36300
5b47f168b948 7177745: JSR292: Many Callsite relinkages cause target method to always run in interpreter mode
vlivanov
parents:
diff changeset
   105
        static final MethodType mt = MethodType.methodType(void.class);
5b47f168b948 7177745: JSR292: Many Callsite relinkages cause target method to always run in interpreter mode
vlivanov
parents:
diff changeset
   106
        static final CallSite cs = new MutableCallSite(mt);
5b47f168b948 7177745: JSR292: Many Callsite relinkages cause target method to always run in interpreter mode
vlivanov
parents:
diff changeset
   107
5b47f168b948 7177745: JSR292: Many Callsite relinkages cause target method to always run in interpreter mode
vlivanov
parents:
diff changeset
   108
        static final MethodHandle mh = cs.dynamicInvoker();
5b47f168b948 7177745: JSR292: Many Callsite relinkages cause target method to always run in interpreter mode
vlivanov
parents:
diff changeset
   109
5b47f168b948 7177745: JSR292: Many Callsite relinkages cause target method to always run in interpreter mode
vlivanov
parents:
diff changeset
   110
        static void f() {
5b47f168b948 7177745: JSR292: Many Callsite relinkages cause target method to always run in interpreter mode
vlivanov
parents:
diff changeset
   111
        }
5b47f168b948 7177745: JSR292: Many Callsite relinkages cause target method to always run in interpreter mode
vlivanov
parents:
diff changeset
   112
5b47f168b948 7177745: JSR292: Many Callsite relinkages cause target method to always run in interpreter mode
vlivanov
parents:
diff changeset
   113
        static void test1() throws Throwable {
5b47f168b948 7177745: JSR292: Many Callsite relinkages cause target method to always run in interpreter mode
vlivanov
parents:
diff changeset
   114
            mh.invokeExact();
5b47f168b948 7177745: JSR292: Many Callsite relinkages cause target method to always run in interpreter mode
vlivanov
parents:
diff changeset
   115
        }
5b47f168b948 7177745: JSR292: Many Callsite relinkages cause target method to always run in interpreter mode
vlivanov
parents:
diff changeset
   116
5b47f168b948 7177745: JSR292: Many Callsite relinkages cause target method to always run in interpreter mode
vlivanov
parents:
diff changeset
   117
        static void test2() throws Throwable {
5b47f168b948 7177745: JSR292: Many Callsite relinkages cause target method to always run in interpreter mode
vlivanov
parents:
diff changeset
   118
            cs.getTarget().invokeExact();
5b47f168b948 7177745: JSR292: Many Callsite relinkages cause target method to always run in interpreter mode
vlivanov
parents:
diff changeset
   119
        }
5b47f168b948 7177745: JSR292: Many Callsite relinkages cause target method to always run in interpreter mode
vlivanov
parents:
diff changeset
   120
5b47f168b948 7177745: JSR292: Many Callsite relinkages cause target method to always run in interpreter mode
vlivanov
parents:
diff changeset
   121
        static void iteration() throws Throwable {
43674
5d984252fc26 8173404: C2: wrong nmethod dependency can be recorded for CallSite.target
vlivanov
parents: 40631
diff changeset
   122
            MethodHandle mh1 = findStatic(RecompilationTest.class, "f", mt);
36300
5b47f168b948 7177745: JSR292: Many Callsite relinkages cause target method to always run in interpreter mode
vlivanov
parents:
diff changeset
   123
            cs.setTarget(mh1);
5b47f168b948 7177745: JSR292: Many Callsite relinkages cause target method to always run in interpreter mode
vlivanov
parents:
diff changeset
   124
            for (int i = 0; i < 20_000; i++) {
5b47f168b948 7177745: JSR292: Many Callsite relinkages cause target method to always run in interpreter mode
vlivanov
parents:
diff changeset
   125
                test1();
5b47f168b948 7177745: JSR292: Many Callsite relinkages cause target method to always run in interpreter mode
vlivanov
parents:
diff changeset
   126
                test2();
5b47f168b948 7177745: JSR292: Many Callsite relinkages cause target method to always run in interpreter mode
vlivanov
parents:
diff changeset
   127
            }
5b47f168b948 7177745: JSR292: Many Callsite relinkages cause target method to always run in interpreter mode
vlivanov
parents:
diff changeset
   128
        }
5b47f168b948 7177745: JSR292: Many Callsite relinkages cause target method to always run in interpreter mode
vlivanov
parents:
diff changeset
   129
5b47f168b948 7177745: JSR292: Many Callsite relinkages cause target method to always run in interpreter mode
vlivanov
parents:
diff changeset
   130
        public static void main(String[] args) throws Throwable {
5b47f168b948 7177745: JSR292: Many Callsite relinkages cause target method to always run in interpreter mode
vlivanov
parents:
diff changeset
   131
            int iterations = Integer.parseInt(args[0]);
5b47f168b948 7177745: JSR292: Many Callsite relinkages cause target method to always run in interpreter mode
vlivanov
parents:
diff changeset
   132
            for (int i = 0; i < iterations; i++) {
5b47f168b948 7177745: JSR292: Many Callsite relinkages cause target method to always run in interpreter mode
vlivanov
parents:
diff changeset
   133
                iteration();
5b47f168b948 7177745: JSR292: Many Callsite relinkages cause target method to always run in interpreter mode
vlivanov
parents:
diff changeset
   134
            }
5b47f168b948 7177745: JSR292: Many Callsite relinkages cause target method to always run in interpreter mode
vlivanov
parents:
diff changeset
   135
        }
5b47f168b948 7177745: JSR292: Many Callsite relinkages cause target method to always run in interpreter mode
vlivanov
parents:
diff changeset
   136
    }
43674
5d984252fc26 8173404: C2: wrong nmethod dependency can be recorded for CallSite.target
vlivanov
parents: 40631
diff changeset
   137
5d984252fc26 8173404: C2: wrong nmethod dependency can be recorded for CallSite.target
vlivanov
parents: 40631
diff changeset
   138
    static class PingPongTest {
5d984252fc26 8173404: C2: wrong nmethod dependency can be recorded for CallSite.target
vlivanov
parents: 40631
diff changeset
   139
        static final MethodType mt = MethodType.methodType(void.class);
5d984252fc26 8173404: C2: wrong nmethod dependency can be recorded for CallSite.target
vlivanov
parents: 40631
diff changeset
   140
        static final CallSite cs = new MutableCallSite(mt);
5d984252fc26 8173404: C2: wrong nmethod dependency can be recorded for CallSite.target
vlivanov
parents: 40631
diff changeset
   141
5d984252fc26 8173404: C2: wrong nmethod dependency can be recorded for CallSite.target
vlivanov
parents: 40631
diff changeset
   142
        static final MethodHandle mh = cs.dynamicInvoker();
5d984252fc26 8173404: C2: wrong nmethod dependency can be recorded for CallSite.target
vlivanov
parents: 40631
diff changeset
   143
5d984252fc26 8173404: C2: wrong nmethod dependency can be recorded for CallSite.target
vlivanov
parents: 40631
diff changeset
   144
        static final MethodHandle ping = findStatic(PingPongTest.class, "ping", mt);
5d984252fc26 8173404: C2: wrong nmethod dependency can be recorded for CallSite.target
vlivanov
parents: 40631
diff changeset
   145
        static final MethodHandle pong = findStatic(PingPongTest.class, "pong", mt);
5d984252fc26 8173404: C2: wrong nmethod dependency can be recorded for CallSite.target
vlivanov
parents: 40631
diff changeset
   146
5d984252fc26 8173404: C2: wrong nmethod dependency can be recorded for CallSite.target
vlivanov
parents: 40631
diff changeset
   147
        static void ping() {
5d984252fc26 8173404: C2: wrong nmethod dependency can be recorded for CallSite.target
vlivanov
parents: 40631
diff changeset
   148
            Asserts.assertEQ(cs.getTarget(), ping, "wrong call site target");
5d984252fc26 8173404: C2: wrong nmethod dependency can be recorded for CallSite.target
vlivanov
parents: 40631
diff changeset
   149
            cs.setTarget(pong);
5d984252fc26 8173404: C2: wrong nmethod dependency can be recorded for CallSite.target
vlivanov
parents: 40631
diff changeset
   150
        }
5d984252fc26 8173404: C2: wrong nmethod dependency can be recorded for CallSite.target
vlivanov
parents: 40631
diff changeset
   151
5d984252fc26 8173404: C2: wrong nmethod dependency can be recorded for CallSite.target
vlivanov
parents: 40631
diff changeset
   152
        static void pong() {
5d984252fc26 8173404: C2: wrong nmethod dependency can be recorded for CallSite.target
vlivanov
parents: 40631
diff changeset
   153
            Asserts.assertEQ(cs.getTarget(), pong, "wrong call site target");
5d984252fc26 8173404: C2: wrong nmethod dependency can be recorded for CallSite.target
vlivanov
parents: 40631
diff changeset
   154
            cs.setTarget(ping);
5d984252fc26 8173404: C2: wrong nmethod dependency can be recorded for CallSite.target
vlivanov
parents: 40631
diff changeset
   155
        }
5d984252fc26 8173404: C2: wrong nmethod dependency can be recorded for CallSite.target
vlivanov
parents: 40631
diff changeset
   156
5d984252fc26 8173404: C2: wrong nmethod dependency can be recorded for CallSite.target
vlivanov
parents: 40631
diff changeset
   157
        static void iteration() throws Throwable {
5d984252fc26 8173404: C2: wrong nmethod dependency can be recorded for CallSite.target
vlivanov
parents: 40631
diff changeset
   158
            cs.setTarget(ping);
5d984252fc26 8173404: C2: wrong nmethod dependency can be recorded for CallSite.target
vlivanov
parents: 40631
diff changeset
   159
            for (int i = 0; i < 20_000; i++) {
5d984252fc26 8173404: C2: wrong nmethod dependency can be recorded for CallSite.target
vlivanov
parents: 40631
diff changeset
   160
                mh.invokeExact();
5d984252fc26 8173404: C2: wrong nmethod dependency can be recorded for CallSite.target
vlivanov
parents: 40631
diff changeset
   161
            }
5d984252fc26 8173404: C2: wrong nmethod dependency can be recorded for CallSite.target
vlivanov
parents: 40631
diff changeset
   162
        }
5d984252fc26 8173404: C2: wrong nmethod dependency can be recorded for CallSite.target
vlivanov
parents: 40631
diff changeset
   163
5d984252fc26 8173404: C2: wrong nmethod dependency can be recorded for CallSite.target
vlivanov
parents: 40631
diff changeset
   164
        public static void main(String[] args) throws Throwable {
5d984252fc26 8173404: C2: wrong nmethod dependency can be recorded for CallSite.target
vlivanov
parents: 40631
diff changeset
   165
            int iterations = Integer.parseInt(args[0]);
5d984252fc26 8173404: C2: wrong nmethod dependency can be recorded for CallSite.target
vlivanov
parents: 40631
diff changeset
   166
            for (int i = 0; i < iterations; i++) {
5d984252fc26 8173404: C2: wrong nmethod dependency can be recorded for CallSite.target
vlivanov
parents: 40631
diff changeset
   167
                iteration();
5d984252fc26 8173404: C2: wrong nmethod dependency can be recorded for CallSite.target
vlivanov
parents: 40631
diff changeset
   168
            }
5d984252fc26 8173404: C2: wrong nmethod dependency can be recorded for CallSite.target
vlivanov
parents: 40631
diff changeset
   169
        }
5d984252fc26 8173404: C2: wrong nmethod dependency can be recorded for CallSite.target
vlivanov
parents: 40631
diff changeset
   170
    }
36300
5b47f168b948 7177745: JSR292: Many Callsite relinkages cause target method to always run in interpreter mode
vlivanov
parents:
diff changeset
   171
}