test/hotspot/jtreg/compiler/jvmci/compilerToVM/ExecuteInstalledCodeTest.java
author kvn
Wed, 01 May 2019 12:31:29 -0700
changeset 54669 ad45b3802d4e
parent 50793 ca4eea543d23
permissions -rw-r--r--
8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library Reviewed-by: dnsimon, never, stefank, rehn, neliasso, dholmes, kbarrett, coleenp
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
42607
acd91f1875d4 8170227: use vm.jvmci property in compiler/jvmci tests
iignatyev
parents: 41063
diff changeset
     1
/*
54669
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 50793
diff changeset
     2
 * Copyright (c) 2015, 2019, Oracle and/or its affiliates. All rights reserved.
42607
acd91f1875d4 8170227: use vm.jvmci property in compiler/jvmci tests
iignatyev
parents: 41063
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
acd91f1875d4 8170227: use vm.jvmci property in compiler/jvmci tests
iignatyev
parents: 41063
diff changeset
     4
 *
acd91f1875d4 8170227: use vm.jvmci property in compiler/jvmci tests
iignatyev
parents: 41063
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
acd91f1875d4 8170227: use vm.jvmci property in compiler/jvmci tests
iignatyev
parents: 41063
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
acd91f1875d4 8170227: use vm.jvmci property in compiler/jvmci tests
iignatyev
parents: 41063
diff changeset
     7
 * published by the Free Software Foundation.
acd91f1875d4 8170227: use vm.jvmci property in compiler/jvmci tests
iignatyev
parents: 41063
diff changeset
     8
 *
acd91f1875d4 8170227: use vm.jvmci property in compiler/jvmci tests
iignatyev
parents: 41063
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
acd91f1875d4 8170227: use vm.jvmci property in compiler/jvmci tests
iignatyev
parents: 41063
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
acd91f1875d4 8170227: use vm.jvmci property in compiler/jvmci tests
iignatyev
parents: 41063
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
acd91f1875d4 8170227: use vm.jvmci property in compiler/jvmci tests
iignatyev
parents: 41063
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
acd91f1875d4 8170227: use vm.jvmci property in compiler/jvmci tests
iignatyev
parents: 41063
diff changeset
    13
 * accompanied this code).
acd91f1875d4 8170227: use vm.jvmci property in compiler/jvmci tests
iignatyev
parents: 41063
diff changeset
    14
 *
acd91f1875d4 8170227: use vm.jvmci property in compiler/jvmci tests
iignatyev
parents: 41063
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
acd91f1875d4 8170227: use vm.jvmci property in compiler/jvmci tests
iignatyev
parents: 41063
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
acd91f1875d4 8170227: use vm.jvmci property in compiler/jvmci tests
iignatyev
parents: 41063
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
acd91f1875d4 8170227: use vm.jvmci property in compiler/jvmci tests
iignatyev
parents: 41063
diff changeset
    18
 *
acd91f1875d4 8170227: use vm.jvmci property in compiler/jvmci tests
iignatyev
parents: 41063
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
acd91f1875d4 8170227: use vm.jvmci property in compiler/jvmci tests
iignatyev
parents: 41063
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
acd91f1875d4 8170227: use vm.jvmci property in compiler/jvmci tests
iignatyev
parents: 41063
diff changeset
    21
 * questions.
acd91f1875d4 8170227: use vm.jvmci property in compiler/jvmci tests
iignatyev
parents: 41063
diff changeset
    22
 */
acd91f1875d4 8170227: use vm.jvmci property in compiler/jvmci tests
iignatyev
parents: 41063
diff changeset
    23
43972
1ade39b8381b 8174879: Rename jdk.vm.ci to jdk.internal.vm.ci
kvn
parents: 42607
diff changeset
    24
/*
1ade39b8381b 8174879: Rename jdk.vm.ci to jdk.internal.vm.ci
kvn
parents: 42607
diff changeset
    25
 * @test
1ade39b8381b 8174879: Rename jdk.vm.ci to jdk.internal.vm.ci
kvn
parents: 42607
diff changeset
    26
 * @bug 8136421
1ade39b8381b 8174879: Rename jdk.vm.ci to jdk.internal.vm.ci
kvn
parents: 42607
diff changeset
    27
 * @requires vm.jvmci
1ade39b8381b 8174879: Rename jdk.vm.ci to jdk.internal.vm.ci
kvn
parents: 42607
diff changeset
    28
 * @library /test/lib /
1ade39b8381b 8174879: Rename jdk.vm.ci to jdk.internal.vm.ci
kvn
parents: 42607
diff changeset
    29
 * @library ../common/patches
54669
ad45b3802d4e 8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents: 50793
diff changeset
    30
 * @ignore Not supported JVMCI API
43972
1ade39b8381b 8174879: Rename jdk.vm.ci to jdk.internal.vm.ci
kvn
parents: 42607
diff changeset
    31
 * @modules java.base/jdk.internal.misc
1ade39b8381b 8174879: Rename jdk.vm.ci to jdk.internal.vm.ci
kvn
parents: 42607
diff changeset
    32
 * @modules java.base/jdk.internal.org.objectweb.asm
1ade39b8381b 8174879: Rename jdk.vm.ci to jdk.internal.vm.ci
kvn
parents: 42607
diff changeset
    33
 *          java.base/jdk.internal.org.objectweb.asm.tree
1ade39b8381b 8174879: Rename jdk.vm.ci to jdk.internal.vm.ci
kvn
parents: 42607
diff changeset
    34
 *          jdk.internal.vm.ci/jdk.vm.ci.hotspot
1ade39b8381b 8174879: Rename jdk.vm.ci to jdk.internal.vm.ci
kvn
parents: 42607
diff changeset
    35
 *          jdk.internal.vm.ci/jdk.vm.ci.code
1ade39b8381b 8174879: Rename jdk.vm.ci to jdk.internal.vm.ci
kvn
parents: 42607
diff changeset
    36
 * @build jdk.internal.vm.ci/jdk.vm.ci.hotspot.CompilerToVMHelper sun.hotspot.WhiteBox
1ade39b8381b 8174879: Rename jdk.vm.ci to jdk.internal.vm.ci
kvn
parents: 42607
diff changeset
    37
 * @run driver ClassFileInstaller sun.hotspot.WhiteBox
1ade39b8381b 8174879: Rename jdk.vm.ci to jdk.internal.vm.ci
kvn
parents: 42607
diff changeset
    38
 *                                sun.hotspot.WhiteBox$WhiteBoxPermission
1ade39b8381b 8174879: Rename jdk.vm.ci to jdk.internal.vm.ci
kvn
parents: 42607
diff changeset
    39
 * @run main/othervm -Xbootclasspath/a:.
1ade39b8381b 8174879: Rename jdk.vm.ci to jdk.internal.vm.ci
kvn
parents: 42607
diff changeset
    40
 *                   -XX:+UnlockDiagnosticVMOptions -XX:+WhiteBoxAPI
1ade39b8381b 8174879: Rename jdk.vm.ci to jdk.internal.vm.ci
kvn
parents: 42607
diff changeset
    41
 *                   -XX:+UnlockExperimentalVMOptions -XX:+EnableJVMCI
50793
ca4eea543d23 8205400: [Graal] compiler/jvmci/compilerToVM/DisassembleCodeBlobTest.java fails with can't be enqueued for compilation on level 4
kvn
parents: 47216
diff changeset
    42
 *                   -XX:-BackgroundCompilation
43972
1ade39b8381b 8174879: Rename jdk.vm.ci to jdk.internal.vm.ci
kvn
parents: 42607
diff changeset
    43
 *                   compiler.jvmci.compilerToVM.ExecuteInstalledCodeTest
1ade39b8381b 8174879: Rename jdk.vm.ci to jdk.internal.vm.ci
kvn
parents: 42607
diff changeset
    44
 */
1ade39b8381b 8174879: Rename jdk.vm.ci to jdk.internal.vm.ci
kvn
parents: 42607
diff changeset
    45
33160
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
    46
package compiler.jvmci.compilerToVM;
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
    47
40059
c2304140ed64 8132919: Put compiler tests in packages
tpivovarova
parents: 40053
diff changeset
    48
import jdk.test.lib.Asserts;
40631
ed82623d7831 8157957: ClassNotFoundException: jdk.test.lib.JDKToolFinder
ctornqvi
parents: 40059
diff changeset
    49
import jdk.test.lib.util.Pair;
40059
c2304140ed64 8132919: Put compiler tests in packages
tpivovarova
parents: 40053
diff changeset
    50
import jdk.test.lib.Utils;
33160
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
    51
import jdk.vm.ci.code.InstalledCode;
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
    52
import jdk.vm.ci.code.InvalidInstalledCodeException;
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
    53
import jdk.vm.ci.hotspot.CompilerToVMHelper;
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
    54
import sun.hotspot.code.NMethod;
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
    55
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
    56
import java.lang.reflect.Constructor;
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
    57
import java.lang.reflect.Modifier;
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
    58
import java.util.ArrayList;
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
    59
import java.util.List;
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
    60
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
    61
public class ExecuteInstalledCodeTest {
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
    62
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
    63
    public static void main(String[] args) {
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
    64
        ExecuteInstalledCodeTest test = new ExecuteInstalledCodeTest();
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
    65
        List<CompileCodeTestCase> testCases = new ArrayList<>();
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
    66
        testCases.addAll(CompileCodeTestCase.generate(/* bci = */ -1));
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
    67
        testCases .stream()
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
    68
                // ignore <init> of abstract class -- 8138793
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
    69
                .filter(e -> !(e.executable instanceof Constructor
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
    70
                        && Modifier.isAbstract(
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
    71
                                e.executable.getDeclaringClass()
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
    72
                                        .getModifiers())))
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
    73
                .forEach(test::checkSanity);
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
    74
    }
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
    75
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
    76
    private void checkSanity(CompileCodeTestCase testCase) {
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
    77
        System.out.println(testCase);
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
    78
        // to have a clean state
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
    79
        testCase.deoptimize();
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
    80
        Pair<Object, ? extends Throwable> reflectionResult;
33632
038347770a9e 8139170: JVMCI refresh
twisti
parents: 33182
diff changeset
    81
        Object[] args = Utils.getNullValues(
038347770a9e 8139170: JVMCI refresh
twisti
parents: 33182
diff changeset
    82
                testCase.executable.getParameterTypes());
038347770a9e 8139170: JVMCI refresh
twisti
parents: 33182
diff changeset
    83
        reflectionResult = testCase.invoke(args);
33160
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
    84
        NMethod nMethod = testCase.compile();
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
    85
        if (nMethod == null) {
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
    86
            throw new Error(testCase + " : nmethod is null");
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
    87
        }
33632
038347770a9e 8139170: JVMCI refresh
twisti
parents: 33182
diff changeset
    88
        InstalledCode installedCode = testCase.toInstalledCode();
33160
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
    89
        Object result = null;
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
    90
        Throwable expectedException = reflectionResult.second;
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
    91
        boolean gotException = true;
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
    92
        try {
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
    93
            args = addReceiver(testCase, args);
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
    94
            result = CompilerToVMHelper.executeInstalledCode(
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
    95
                    args, installedCode);
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
    96
            if (testCase.executable instanceof Constructor) {
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
    97
                // <init> doesn't have return value, it changes receiver
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
    98
                result = args[0];
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
    99
            }
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   100
            gotException = false;
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   101
        } catch (InvalidInstalledCodeException e) {
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   102
            throw new AssertionError(
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   103
                    testCase + " : unexpected InvalidInstalledCodeException", e);
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   104
        } catch (Throwable t) {
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   105
            if (expectedException == null) {
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   106
                throw new AssertionError(testCase
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   107
                        + " : got unexpected execption : " + t.getMessage(), t);
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   108
            }
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   109
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   110
            if (expectedException.getClass() != t.getClass()) {
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   111
                System.err.println("exception from CompilerToVM:");
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   112
                t.printStackTrace();
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   113
                System.err.println("exception from reflection:");
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   114
                expectedException.printStackTrace();
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   115
                throw new AssertionError(String.format(
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   116
                        "%s : got unexpected different exceptions : %s != %s",
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   117
                        testCase, expectedException.getClass(), t.getClass()));
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   118
            }
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   119
        }
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   120
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   121
        Asserts.assertEQ(reflectionResult.first, result, testCase
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   122
                + " : different return value");
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   123
        if (!gotException) {
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   124
            Asserts.assertNull(expectedException, testCase
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   125
                    + " : expected exception hasn't been thrown");
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   126
        }
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   127
    }
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   128
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   129
    private Object[] addReceiver(CompileCodeTestCase testCase, Object[] args) {
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   130
        if (!Modifier.isStatic(testCase.executable.getModifiers())) {
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   131
            // add instance as 0th arg
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   132
            Object[] newArgs = new Object[args.length + 1];
33632
038347770a9e 8139170: JVMCI refresh
twisti
parents: 33182
diff changeset
   133
            newArgs[0] = testCase.receiver;
33160
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   134
            System.arraycopy(args, 0, newArgs, 1, args.length);
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   135
            args = newArgs;
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   136
        }
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   137
        return args;
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   138
    }
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   139
}