hotspot/test/compiler/jsr292/ContinuousCallSiteTargetChange.java
author dsamersoff
Sun, 01 May 2016 12:47:00 +0300
changeset 38152 80e5da81fb2c
parent 36300 5b47f168b948
child 40059 c2304140ed64
permissions -rw-r--r--
8154258: [TESTBUG] Various serviceability tests fail compilation Summary: Replace sun.misc.Unsafe with jdk.internal.misc.Unsafe Reviewed-by: chegar, 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
38152
80e5da81fb2c 8154258: [TESTBUG] Various serviceability tests fail compilation
dsamersoff
parents: 36300
diff changeset
    26
 * @modules java.base/jdk.internal.misc
36300
5b47f168b948 7177745: JSR292: Many Callsite relinkages cause target method to always run in interpreter mode
vlivanov
parents:
diff changeset
    27
 * @library /testlibrary
5b47f168b948 7177745: JSR292: Many Callsite relinkages cause target method to always run in interpreter mode
vlivanov
parents:
diff changeset
    28
 * @run main ContinuousCallSiteTargetChange
5b47f168b948 7177745: JSR292: Many Callsite relinkages cause target method to always run in interpreter mode
vlivanov
parents:
diff changeset
    29
 */
5b47f168b948 7177745: JSR292: Many Callsite relinkages cause target method to always run in interpreter mode
vlivanov
parents:
diff changeset
    30
import java.lang.invoke.*;
5b47f168b948 7177745: JSR292: Many Callsite relinkages cause target method to always run in interpreter mode
vlivanov
parents:
diff changeset
    31
import jdk.test.lib.*;
5b47f168b948 7177745: JSR292: Many Callsite relinkages cause target method to always run in interpreter mode
vlivanov
parents:
diff changeset
    32
5b47f168b948 7177745: JSR292: Many Callsite relinkages cause target method to always run in interpreter mode
vlivanov
parents:
diff changeset
    33
public class ContinuousCallSiteTargetChange {
5b47f168b948 7177745: JSR292: Many Callsite relinkages cause target method to always run in interpreter mode
vlivanov
parents:
diff changeset
    34
    static void testServer() throws Exception {
5b47f168b948 7177745: JSR292: Many Callsite relinkages cause target method to always run in interpreter mode
vlivanov
parents:
diff changeset
    35
        ProcessBuilder pb = ProcessTools.createJavaProcessBuilder(
5b47f168b948 7177745: JSR292: Many Callsite relinkages cause target method to always run in interpreter mode
vlivanov
parents:
diff changeset
    36
                "-XX:+IgnoreUnrecognizedVMOptions",
5b47f168b948 7177745: JSR292: Many Callsite relinkages cause target method to always run in interpreter mode
vlivanov
parents:
diff changeset
    37
                "-server", "-XX:-TieredCompilation", "-Xbatch",
5b47f168b948 7177745: JSR292: Many Callsite relinkages cause target method to always run in interpreter mode
vlivanov
parents:
diff changeset
    38
                "-XX:PerBytecodeRecompilationCutoff=10", "-XX:PerMethodRecompilationCutoff=10",
5b47f168b948 7177745: JSR292: Many Callsite relinkages cause target method to always run in interpreter mode
vlivanov
parents:
diff changeset
    39
                "-XX:+PrintCompilation", "-XX:+UnlockDiagnosticVMOptions", "-XX:+PrintInlining",
5b47f168b948 7177745: JSR292: Many Callsite relinkages cause target method to always run in interpreter mode
vlivanov
parents:
diff changeset
    40
                "ContinuousCallSiteTargetChange$Test", "100");
5b47f168b948 7177745: JSR292: Many Callsite relinkages cause target method to always run in interpreter mode
vlivanov
parents:
diff changeset
    41
5b47f168b948 7177745: JSR292: Many Callsite relinkages cause target method to always run in interpreter mode
vlivanov
parents:
diff changeset
    42
        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
    43
5b47f168b948 7177745: JSR292: Many Callsite relinkages cause target method to always run in interpreter mode
vlivanov
parents:
diff changeset
    44
        analyzer.shouldHaveExitValue(0);
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
        analyzer.shouldNotContain("made not compilable");
5b47f168b948 7177745: JSR292: Many Callsite relinkages cause target method to always run in interpreter mode
vlivanov
parents:
diff changeset
    47
        analyzer.shouldNotContain("decompile_count > PerMethodRecompilationCutoff");
5b47f168b948 7177745: JSR292: Many Callsite relinkages cause target method to always run in interpreter mode
vlivanov
parents:
diff changeset
    48
    }
5b47f168b948 7177745: JSR292: Many Callsite relinkages cause target method to always run in interpreter mode
vlivanov
parents:
diff changeset
    49
5b47f168b948 7177745: JSR292: Many Callsite relinkages cause target method to always run in interpreter mode
vlivanov
parents:
diff changeset
    50
    static void testClient() throws Exception {
5b47f168b948 7177745: JSR292: Many Callsite relinkages cause target method to always run in interpreter mode
vlivanov
parents:
diff changeset
    51
        ProcessBuilder pb = ProcessTools.createJavaProcessBuilder(
5b47f168b948 7177745: JSR292: Many Callsite relinkages cause target method to always run in interpreter mode
vlivanov
parents:
diff changeset
    52
                "-XX:+IgnoreUnrecognizedVMOptions",
5b47f168b948 7177745: JSR292: Many Callsite relinkages cause target method to always run in interpreter mode
vlivanov
parents:
diff changeset
    53
                "-client", "-XX:+TieredCompilation", "-XX:TieredStopAtLevel=1", "-Xbatch",
5b47f168b948 7177745: JSR292: Many Callsite relinkages cause target method to always run in interpreter mode
vlivanov
parents:
diff changeset
    54
                "-XX:PerBytecodeRecompilationCutoff=10", "-XX:PerMethodRecompilationCutoff=10",
5b47f168b948 7177745: JSR292: Many Callsite relinkages cause target method to always run in interpreter mode
vlivanov
parents:
diff changeset
    55
                "-XX:+PrintCompilation", "-XX:+UnlockDiagnosticVMOptions", "-XX:+PrintInlining",
5b47f168b948 7177745: JSR292: Many Callsite relinkages cause target method to always run in interpreter mode
vlivanov
parents:
diff changeset
    56
                "ContinuousCallSiteTargetChange$Test", "100");
5b47f168b948 7177745: JSR292: Many Callsite relinkages cause target method to always run in interpreter mode
vlivanov
parents:
diff changeset
    57
5b47f168b948 7177745: JSR292: Many Callsite relinkages cause target method to always run in interpreter mode
vlivanov
parents:
diff changeset
    58
        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
    59
5b47f168b948 7177745: JSR292: Many Callsite relinkages cause target method to always run in interpreter mode
vlivanov
parents:
diff changeset
    60
        analyzer.shouldHaveExitValue(0);
5b47f168b948 7177745: JSR292: Many Callsite relinkages cause target method to always run in interpreter mode
vlivanov
parents:
diff changeset
    61
5b47f168b948 7177745: JSR292: Many Callsite relinkages cause target method to always run in interpreter mode
vlivanov
parents:
diff changeset
    62
        analyzer.shouldNotContain("made not compilable");
5b47f168b948 7177745: JSR292: Many Callsite relinkages cause target method to always run in interpreter mode
vlivanov
parents:
diff changeset
    63
        analyzer.shouldNotContain("decompile_count > PerMethodRecompilationCutoff");
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
5b47f168b948 7177745: JSR292: Many Callsite relinkages cause target method to always run in interpreter mode
vlivanov
parents:
diff changeset
    66
    public static void main(String[] args) throws Exception {
5b47f168b948 7177745: JSR292: Many Callsite relinkages cause target method to always run in interpreter mode
vlivanov
parents:
diff changeset
    67
        testServer();
5b47f168b948 7177745: JSR292: Many Callsite relinkages cause target method to always run in interpreter mode
vlivanov
parents:
diff changeset
    68
        testClient();
5b47f168b948 7177745: JSR292: Many Callsite relinkages cause target method to always run in interpreter mode
vlivanov
parents:
diff changeset
    69
    }
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
    static class Test {
5b47f168b948 7177745: JSR292: Many Callsite relinkages cause target method to always run in interpreter mode
vlivanov
parents:
diff changeset
    72
        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
    73
        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
    74
5b47f168b948 7177745: JSR292: Many Callsite relinkages cause target method to always run in interpreter mode
vlivanov
parents:
diff changeset
    75
        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
    76
5b47f168b948 7177745: JSR292: Many Callsite relinkages cause target method to always run in interpreter mode
vlivanov
parents:
diff changeset
    77
        static void f() {
5b47f168b948 7177745: JSR292: Many Callsite relinkages cause target method to always run in interpreter mode
vlivanov
parents:
diff changeset
    78
        }
5b47f168b948 7177745: JSR292: Many Callsite relinkages cause target method to always run in interpreter mode
vlivanov
parents:
diff changeset
    79
5b47f168b948 7177745: JSR292: Many Callsite relinkages cause target method to always run in interpreter mode
vlivanov
parents:
diff changeset
    80
        static void test1() throws Throwable {
5b47f168b948 7177745: JSR292: Many Callsite relinkages cause target method to always run in interpreter mode
vlivanov
parents:
diff changeset
    81
            mh.invokeExact();
5b47f168b948 7177745: JSR292: Many Callsite relinkages cause target method to always run in interpreter mode
vlivanov
parents:
diff changeset
    82
        }
5b47f168b948 7177745: JSR292: Many Callsite relinkages cause target method to always run in interpreter mode
vlivanov
parents:
diff changeset
    83
5b47f168b948 7177745: JSR292: Many Callsite relinkages cause target method to always run in interpreter mode
vlivanov
parents:
diff changeset
    84
        static void test2() throws Throwable {
5b47f168b948 7177745: JSR292: Many Callsite relinkages cause target method to always run in interpreter mode
vlivanov
parents:
diff changeset
    85
            cs.getTarget().invokeExact();
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
        static void iteration() throws Throwable {
5b47f168b948 7177745: JSR292: Many Callsite relinkages cause target method to always run in interpreter mode
vlivanov
parents:
diff changeset
    89
            MethodHandle mh1 = MethodHandles.lookup().findStatic(ContinuousCallSiteTargetChange.Test.class, "f", mt);
5b47f168b948 7177745: JSR292: Many Callsite relinkages cause target method to always run in interpreter mode
vlivanov
parents:
diff changeset
    90
            cs.setTarget(mh1);
5b47f168b948 7177745: JSR292: Many Callsite relinkages cause target method to always run in interpreter mode
vlivanov
parents:
diff changeset
    91
            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
    92
                test1();
5b47f168b948 7177745: JSR292: Many Callsite relinkages cause target method to always run in interpreter mode
vlivanov
parents:
diff changeset
    93
                test2();
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
        }
5b47f168b948 7177745: JSR292: Many Callsite relinkages cause target method to always run in interpreter mode
vlivanov
parents:
diff changeset
    96
5b47f168b948 7177745: JSR292: Many Callsite relinkages cause target method to always run in interpreter mode
vlivanov
parents:
diff changeset
    97
        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
    98
            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
    99
            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
   100
                iteration();
5b47f168b948 7177745: JSR292: Many Callsite relinkages cause target method to always run in interpreter mode
vlivanov
parents:
diff changeset
   101
            }
5b47f168b948 7177745: JSR292: Many Callsite relinkages cause target method to always run in interpreter mode
vlivanov
parents:
diff changeset
   102
        }
5b47f168b948 7177745: JSR292: Many Callsite relinkages cause target method to always run in interpreter mode
vlivanov
parents:
diff changeset
   103
    }
5b47f168b948 7177745: JSR292: Many Callsite relinkages cause target method to always run in interpreter mode
vlivanov
parents:
diff changeset
   104
}