hotspot/test/compiler/jvmci/compilerToVM/LookupMethodInPoolTest.java
author zmajo
Wed, 15 Jun 2016 14:27:58 +0200
changeset 39421 a9652c919db8
parent 37301 a936b4e01afb
child 39450 78e99b030d5f
permissions -rw-r--r--
8157181: Compilers accept modification of final fields outside initializer methods Summary: Track initialized final field updates; disable constant folding if an update is detected. Enforce final field update rules introduced by JVMS-7 (but only for JDK 9). Reviewed-by: vlivanov, dnsimon, forax, never, kvn, coleenp
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
36306
9b8ba80e9327 8141619: Develop new tests for JVMCI compilerToVM class' CP related methods
kshefov
parents:
diff changeset
     1
/*
9b8ba80e9327 8141619: Develop new tests for JVMCI compilerToVM class' CP related methods
kshefov
parents:
diff changeset
     2
 * Copyright (c) 2016, Oracle and/or its affiliates. All rights reserved.
9b8ba80e9327 8141619: Develop new tests for JVMCI compilerToVM class' CP related methods
kshefov
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
9b8ba80e9327 8141619: Develop new tests for JVMCI compilerToVM class' CP related methods
kshefov
parents:
diff changeset
     4
 *
9b8ba80e9327 8141619: Develop new tests for JVMCI compilerToVM class' CP related methods
kshefov
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
9b8ba80e9327 8141619: Develop new tests for JVMCI compilerToVM class' CP related methods
kshefov
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
9b8ba80e9327 8141619: Develop new tests for JVMCI compilerToVM class' CP related methods
kshefov
parents:
diff changeset
     7
 * published by the Free Software Foundation.
9b8ba80e9327 8141619: Develop new tests for JVMCI compilerToVM class' CP related methods
kshefov
parents:
diff changeset
     8
 *
9b8ba80e9327 8141619: Develop new tests for JVMCI compilerToVM class' CP related methods
kshefov
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
9b8ba80e9327 8141619: Develop new tests for JVMCI compilerToVM class' CP related methods
kshefov
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
9b8ba80e9327 8141619: Develop new tests for JVMCI compilerToVM class' CP related methods
kshefov
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
9b8ba80e9327 8141619: Develop new tests for JVMCI compilerToVM class' CP related methods
kshefov
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
9b8ba80e9327 8141619: Develop new tests for JVMCI compilerToVM class' CP related methods
kshefov
parents:
diff changeset
    13
 * accompanied this code).
9b8ba80e9327 8141619: Develop new tests for JVMCI compilerToVM class' CP related methods
kshefov
parents:
diff changeset
    14
 *
9b8ba80e9327 8141619: Develop new tests for JVMCI compilerToVM class' CP related methods
kshefov
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
9b8ba80e9327 8141619: Develop new tests for JVMCI compilerToVM class' CP related methods
kshefov
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
9b8ba80e9327 8141619: Develop new tests for JVMCI compilerToVM class' CP related methods
kshefov
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
9b8ba80e9327 8141619: Develop new tests for JVMCI compilerToVM class' CP related methods
kshefov
parents:
diff changeset
    18
 *
9b8ba80e9327 8141619: Develop new tests for JVMCI compilerToVM class' CP related methods
kshefov
parents:
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
9b8ba80e9327 8141619: Develop new tests for JVMCI compilerToVM class' CP related methods
kshefov
parents:
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
9b8ba80e9327 8141619: Develop new tests for JVMCI compilerToVM class' CP related methods
kshefov
parents:
diff changeset
    21
 * questions.
9b8ba80e9327 8141619: Develop new tests for JVMCI compilerToVM class' CP related methods
kshefov
parents:
diff changeset
    22
 *
9b8ba80e9327 8141619: Develop new tests for JVMCI compilerToVM class' CP related methods
kshefov
parents:
diff changeset
    23
 */
9b8ba80e9327 8141619: Develop new tests for JVMCI compilerToVM class' CP related methods
kshefov
parents:
diff changeset
    24
9b8ba80e9327 8141619: Develop new tests for JVMCI compilerToVM class' CP related methods
kshefov
parents:
diff changeset
    25
/*
9b8ba80e9327 8141619: Develop new tests for JVMCI compilerToVM class' CP related methods
kshefov
parents:
diff changeset
    26
 * @test
9b8ba80e9327 8141619: Develop new tests for JVMCI compilerToVM class' CP related methods
kshefov
parents:
diff changeset
    27
 * @bug 8138708
9b8ba80e9327 8141619: Develop new tests for JVMCI compilerToVM class' CP related methods
kshefov
parents:
diff changeset
    28
 * @requires (os.simpleArch == "x64" | os.simpleArch == "sparcv9" | os.simpleArch == "aarch64")
9b8ba80e9327 8141619: Develop new tests for JVMCI compilerToVM class' CP related methods
kshefov
parents:
diff changeset
    29
 * @library /testlibrary /test/lib /
36508
5f9eee6b383b 8142968: Module System implementation
alanb
parents: 36306
diff changeset
    30
 * @library ../common/patches
5f9eee6b383b 8142968: Module System implementation
alanb
parents: 36306
diff changeset
    31
 * @modules java.base/jdk.internal.misc
37301
a936b4e01afb 8137058: Clear out all non-Critical APIs from sun.reflect
chegar
parents: 36508
diff changeset
    32
 *          java.base/jdk.internal.reflect
36508
5f9eee6b383b 8142968: Module System implementation
alanb
parents: 36306
diff changeset
    33
 *          java.base/jdk.internal.org.objectweb.asm
5f9eee6b383b 8142968: Module System implementation
alanb
parents: 36306
diff changeset
    34
 *          java.base/jdk.internal.org.objectweb.asm.tree
5f9eee6b383b 8142968: Module System implementation
alanb
parents: 36306
diff changeset
    35
 *          jdk.vm.ci/jdk.vm.ci.hotspot
5f9eee6b383b 8142968: Module System implementation
alanb
parents: 36306
diff changeset
    36
 *          jdk.vm.ci/jdk.vm.ci.meta
39421
a9652c919db8 8157181: Compilers accept modification of final fields outside initializer methods
zmajo
parents: 37301
diff changeset
    37
 *          jdk.vm.ci/jdk.vm.ci.runtime
36508
5f9eee6b383b 8142968: Module System implementation
alanb
parents: 36306
diff changeset
    38
 * @build jdk.vm.ci/jdk.vm.ci.hotspot.CompilerToVMHelper
36306
9b8ba80e9327 8141619: Develop new tests for JVMCI compilerToVM class' CP related methods
kshefov
parents:
diff changeset
    39
 * @build sun.hotspot.WhiteBox
9b8ba80e9327 8141619: Develop new tests for JVMCI compilerToVM class' CP related methods
kshefov
parents:
diff changeset
    40
 *        compiler.jvmci.compilerToVM.LookupMethodInPoolTest
9b8ba80e9327 8141619: Develop new tests for JVMCI compilerToVM class' CP related methods
kshefov
parents:
diff changeset
    41
 * @run main ClassFileInstaller sun.hotspot.WhiteBox
9b8ba80e9327 8141619: Develop new tests for JVMCI compilerToVM class' CP related methods
kshefov
parents:
diff changeset
    42
 *                              sun.hotspot.WhiteBox$WhiteBoxPermission
9b8ba80e9327 8141619: Develop new tests for JVMCI compilerToVM class' CP related methods
kshefov
parents:
diff changeset
    43
 * @run main/othervm -Xbootclasspath/a:. -XX:+UnlockDiagnosticVMOptions
9b8ba80e9327 8141619: Develop new tests for JVMCI compilerToVM class' CP related methods
kshefov
parents:
diff changeset
    44
 *                   -XX:+WhiteBoxAPI -XX:+UnlockExperimentalVMOptions -XX:+EnableJVMCI
9b8ba80e9327 8141619: Develop new tests for JVMCI compilerToVM class' CP related methods
kshefov
parents:
diff changeset
    45
 *                   compiler.jvmci.compilerToVM.LookupMethodInPoolTest
9b8ba80e9327 8141619: Develop new tests for JVMCI compilerToVM class' CP related methods
kshefov
parents:
diff changeset
    46
 */
9b8ba80e9327 8141619: Develop new tests for JVMCI compilerToVM class' CP related methods
kshefov
parents:
diff changeset
    47
9b8ba80e9327 8141619: Develop new tests for JVMCI compilerToVM class' CP related methods
kshefov
parents:
diff changeset
    48
package compiler.jvmci.compilerToVM;
9b8ba80e9327 8141619: Develop new tests for JVMCI compilerToVM class' CP related methods
kshefov
parents:
diff changeset
    49
9b8ba80e9327 8141619: Develop new tests for JVMCI compilerToVM class' CP related methods
kshefov
parents:
diff changeset
    50
import compiler.jvmci.compilerToVM.ConstantPoolTestsHelper.DummyClasses;
9b8ba80e9327 8141619: Develop new tests for JVMCI compilerToVM class' CP related methods
kshefov
parents:
diff changeset
    51
import compiler.jvmci.compilerToVM.ConstantPoolTestCase.ConstantTypes;
9b8ba80e9327 8141619: Develop new tests for JVMCI compilerToVM class' CP related methods
kshefov
parents:
diff changeset
    52
import static compiler.jvmci.compilerToVM.ConstantPoolTestCase.ConstantTypes.*;
9b8ba80e9327 8141619: Develop new tests for JVMCI compilerToVM class' CP related methods
kshefov
parents:
diff changeset
    53
import compiler.jvmci.compilerToVM.ConstantPoolTestCase.TestedCPEntry;
9b8ba80e9327 8141619: Develop new tests for JVMCI compilerToVM class' CP related methods
kshefov
parents:
diff changeset
    54
import compiler.jvmci.compilerToVM.ConstantPoolTestCase.Validator;
9b8ba80e9327 8141619: Develop new tests for JVMCI compilerToVM class' CP related methods
kshefov
parents:
diff changeset
    55
import java.util.HashMap;
9b8ba80e9327 8141619: Develop new tests for JVMCI compilerToVM class' CP related methods
kshefov
parents:
diff changeset
    56
import java.util.Map;
9b8ba80e9327 8141619: Develop new tests for JVMCI compilerToVM class' CP related methods
kshefov
parents:
diff changeset
    57
import jdk.test.lib.Asserts;
9b8ba80e9327 8141619: Develop new tests for JVMCI compilerToVM class' CP related methods
kshefov
parents:
diff changeset
    58
import jdk.vm.ci.hotspot.CompilerToVMHelper;
9b8ba80e9327 8141619: Develop new tests for JVMCI compilerToVM class' CP related methods
kshefov
parents:
diff changeset
    59
import jdk.vm.ci.hotspot.HotSpotResolvedJavaMethod;
9b8ba80e9327 8141619: Develop new tests for JVMCI compilerToVM class' CP related methods
kshefov
parents:
diff changeset
    60
import jdk.vm.ci.meta.ConstantPool;
9b8ba80e9327 8141619: Develop new tests for JVMCI compilerToVM class' CP related methods
kshefov
parents:
diff changeset
    61
9b8ba80e9327 8141619: Develop new tests for JVMCI compilerToVM class' CP related methods
kshefov
parents:
diff changeset
    62
/**
9b8ba80e9327 8141619: Develop new tests for JVMCI compilerToVM class' CP related methods
kshefov
parents:
diff changeset
    63
 * Test for {@code jdk.vm.ci.hotspot.CompilerToVM.lookupMethodInPool} method
9b8ba80e9327 8141619: Develop new tests for JVMCI compilerToVM class' CP related methods
kshefov
parents:
diff changeset
    64
 */
9b8ba80e9327 8141619: Develop new tests for JVMCI compilerToVM class' CP related methods
kshefov
parents:
diff changeset
    65
public class LookupMethodInPoolTest {
9b8ba80e9327 8141619: Develop new tests for JVMCI compilerToVM class' CP related methods
kshefov
parents:
diff changeset
    66
9b8ba80e9327 8141619: Develop new tests for JVMCI compilerToVM class' CP related methods
kshefov
parents:
diff changeset
    67
    public static void main(String[] args) throws Exception {
9b8ba80e9327 8141619: Develop new tests for JVMCI compilerToVM class' CP related methods
kshefov
parents:
diff changeset
    68
        Map<ConstantTypes, Validator> typeTests = new HashMap<>();
9b8ba80e9327 8141619: Develop new tests for JVMCI compilerToVM class' CP related methods
kshefov
parents:
diff changeset
    69
        typeTests.put(CONSTANT_METHODREF, LookupMethodInPoolTest::validate);
9b8ba80e9327 8141619: Develop new tests for JVMCI compilerToVM class' CP related methods
kshefov
parents:
diff changeset
    70
        typeTests.put(CONSTANT_INTERFACEMETHODREF, LookupMethodInPoolTest::validate);
9b8ba80e9327 8141619: Develop new tests for JVMCI compilerToVM class' CP related methods
kshefov
parents:
diff changeset
    71
        ConstantPoolTestCase testCase = new ConstantPoolTestCase(typeTests);
9b8ba80e9327 8141619: Develop new tests for JVMCI compilerToVM class' CP related methods
kshefov
parents:
diff changeset
    72
        testCase.test();
9b8ba80e9327 8141619: Develop new tests for JVMCI compilerToVM class' CP related methods
kshefov
parents:
diff changeset
    73
        // The next "Class.forName" and repeating "testCase.test()"
9b8ba80e9327 8141619: Develop new tests for JVMCI compilerToVM class' CP related methods
kshefov
parents:
diff changeset
    74
        // are here for the following reason.
9b8ba80e9327 8141619: Develop new tests for JVMCI compilerToVM class' CP related methods
kshefov
parents:
diff changeset
    75
        // The first test run is without dummy class initialization,
9b8ba80e9327 8141619: Develop new tests for JVMCI compilerToVM class' CP related methods
kshefov
parents:
diff changeset
    76
        // which means no constant pool cache exists.
9b8ba80e9327 8141619: Develop new tests for JVMCI compilerToVM class' CP related methods
kshefov
parents:
diff changeset
    77
        // The second run is with initialized class (with constant pool cache available).
9b8ba80e9327 8141619: Develop new tests for JVMCI compilerToVM class' CP related methods
kshefov
parents:
diff changeset
    78
        // Some CompilerToVM methods require different input
9b8ba80e9327 8141619: Develop new tests for JVMCI compilerToVM class' CP related methods
kshefov
parents:
diff changeset
    79
        // depending on whether CP cache exists or not.
9b8ba80e9327 8141619: Develop new tests for JVMCI compilerToVM class' CP related methods
kshefov
parents:
diff changeset
    80
        for (DummyClasses dummy : DummyClasses.values()) {
9b8ba80e9327 8141619: Develop new tests for JVMCI compilerToVM class' CP related methods
kshefov
parents:
diff changeset
    81
            Class.forName(dummy.klass.getName());
9b8ba80e9327 8141619: Develop new tests for JVMCI compilerToVM class' CP related methods
kshefov
parents:
diff changeset
    82
        }
9b8ba80e9327 8141619: Develop new tests for JVMCI compilerToVM class' CP related methods
kshefov
parents:
diff changeset
    83
        testCase.test();
9b8ba80e9327 8141619: Develop new tests for JVMCI compilerToVM class' CP related methods
kshefov
parents:
diff changeset
    84
    }
9b8ba80e9327 8141619: Develop new tests for JVMCI compilerToVM class' CP related methods
kshefov
parents:
diff changeset
    85
9b8ba80e9327 8141619: Develop new tests for JVMCI compilerToVM class' CP related methods
kshefov
parents:
diff changeset
    86
    private static void validate(ConstantPool constantPoolCTVM,
9b8ba80e9327 8141619: Develop new tests for JVMCI compilerToVM class' CP related methods
kshefov
parents:
diff changeset
    87
                                 ConstantTypes cpType,
9b8ba80e9327 8141619: Develop new tests for JVMCI compilerToVM class' CP related methods
kshefov
parents:
diff changeset
    88
                                 DummyClasses dummyClass,
9b8ba80e9327 8141619: Develop new tests for JVMCI compilerToVM class' CP related methods
kshefov
parents:
diff changeset
    89
                                 int cpi) {
9b8ba80e9327 8141619: Develop new tests for JVMCI compilerToVM class' CP related methods
kshefov
parents:
diff changeset
    90
        TestedCPEntry entry = cpType.getTestedCPEntry(dummyClass, cpi);
9b8ba80e9327 8141619: Develop new tests for JVMCI compilerToVM class' CP related methods
kshefov
parents:
diff changeset
    91
        if (entry == null) {
9b8ba80e9327 8141619: Develop new tests for JVMCI compilerToVM class' CP related methods
kshefov
parents:
diff changeset
    92
            return;
9b8ba80e9327 8141619: Develop new tests for JVMCI compilerToVM class' CP related methods
kshefov
parents:
diff changeset
    93
        }
9b8ba80e9327 8141619: Develop new tests for JVMCI compilerToVM class' CP related methods
kshefov
parents:
diff changeset
    94
        int index = cpi;
9b8ba80e9327 8141619: Develop new tests for JVMCI compilerToVM class' CP related methods
kshefov
parents:
diff changeset
    95
        String cached = "";
9b8ba80e9327 8141619: Develop new tests for JVMCI compilerToVM class' CP related methods
kshefov
parents:
diff changeset
    96
        int cpci = dummyClass.getCPCacheIndex(cpi);
9b8ba80e9327 8141619: Develop new tests for JVMCI compilerToVM class' CP related methods
kshefov
parents:
diff changeset
    97
        if (cpci != ConstantPoolTestsHelper.NO_CP_CACHE_PRESENT) {
9b8ba80e9327 8141619: Develop new tests for JVMCI compilerToVM class' CP related methods
kshefov
parents:
diff changeset
    98
            index = cpci;
9b8ba80e9327 8141619: Develop new tests for JVMCI compilerToVM class' CP related methods
kshefov
parents:
diff changeset
    99
            cached = "cached ";
9b8ba80e9327 8141619: Develop new tests for JVMCI compilerToVM class' CP related methods
kshefov
parents:
diff changeset
   100
        }
9b8ba80e9327 8141619: Develop new tests for JVMCI compilerToVM class' CP related methods
kshefov
parents:
diff changeset
   101
        for (int j = 0; j < entry.opcodes.length; j++) {
9b8ba80e9327 8141619: Develop new tests for JVMCI compilerToVM class' CP related methods
kshefov
parents:
diff changeset
   102
            HotSpotResolvedJavaMethod methodToVerify = CompilerToVMHelper
9b8ba80e9327 8141619: Develop new tests for JVMCI compilerToVM class' CP related methods
kshefov
parents:
diff changeset
   103
                    .lookupMethodInPool(constantPoolCTVM, index, entry.opcodes[j]);
9b8ba80e9327 8141619: Develop new tests for JVMCI compilerToVM class' CP related methods
kshefov
parents:
diff changeset
   104
            String msg = String.format("Object returned by lookupMethodInPool method"
9b8ba80e9327 8141619: Develop new tests for JVMCI compilerToVM class' CP related methods
kshefov
parents:
diff changeset
   105
                                               + " for %sindex %d should not be null",
9b8ba80e9327 8141619: Develop new tests for JVMCI compilerToVM class' CP related methods
kshefov
parents:
diff changeset
   106
                                       cached,
9b8ba80e9327 8141619: Develop new tests for JVMCI compilerToVM class' CP related methods
kshefov
parents:
diff changeset
   107
                                       index);
9b8ba80e9327 8141619: Develop new tests for JVMCI compilerToVM class' CP related methods
kshefov
parents:
diff changeset
   108
            Asserts.assertNotNull(methodToVerify, msg);
9b8ba80e9327 8141619: Develop new tests for JVMCI compilerToVM class' CP related methods
kshefov
parents:
diff changeset
   109
            String[] classNameSplit = entry.klass.split("/");
9b8ba80e9327 8141619: Develop new tests for JVMCI compilerToVM class' CP related methods
kshefov
parents:
diff changeset
   110
            String classNameToRefer = classNameSplit[classNameSplit.length - 1];
9b8ba80e9327 8141619: Develop new tests for JVMCI compilerToVM class' CP related methods
kshefov
parents:
diff changeset
   111
            String methodNameToRefer = entry.name;
9b8ba80e9327 8141619: Develop new tests for JVMCI compilerToVM class' CP related methods
kshefov
parents:
diff changeset
   112
            String methodToVerifyToString = methodToVerify.toString();
9b8ba80e9327 8141619: Develop new tests for JVMCI compilerToVM class' CP related methods
kshefov
parents:
diff changeset
   113
            if (!methodToVerifyToString.contains(classNameToRefer)
9b8ba80e9327 8141619: Develop new tests for JVMCI compilerToVM class' CP related methods
kshefov
parents:
diff changeset
   114
                    || !methodToVerifyToString.contains(methodNameToRefer)) {
9b8ba80e9327 8141619: Develop new tests for JVMCI compilerToVM class' CP related methods
kshefov
parents:
diff changeset
   115
                msg = String.format("String representation \"%s\" of the object"
9b8ba80e9327 8141619: Develop new tests for JVMCI compilerToVM class' CP related methods
kshefov
parents:
diff changeset
   116
                                            + " returned by lookupMethodInPool method"
9b8ba80e9327 8141619: Develop new tests for JVMCI compilerToVM class' CP related methods
kshefov
parents:
diff changeset
   117
                                            + " for index %d does not contain a method's class name"
9b8ba80e9327 8141619: Develop new tests for JVMCI compilerToVM class' CP related methods
kshefov
parents:
diff changeset
   118
                                            + " or method's name, should contain %s.%s",
9b8ba80e9327 8141619: Develop new tests for JVMCI compilerToVM class' CP related methods
kshefov
parents:
diff changeset
   119
                                    methodToVerifyToString,
9b8ba80e9327 8141619: Develop new tests for JVMCI compilerToVM class' CP related methods
kshefov
parents:
diff changeset
   120
                                    index,
9b8ba80e9327 8141619: Develop new tests for JVMCI compilerToVM class' CP related methods
kshefov
parents:
diff changeset
   121
                                    classNameToRefer,
9b8ba80e9327 8141619: Develop new tests for JVMCI compilerToVM class' CP related methods
kshefov
parents:
diff changeset
   122
                                    methodNameToRefer);
9b8ba80e9327 8141619: Develop new tests for JVMCI compilerToVM class' CP related methods
kshefov
parents:
diff changeset
   123
                throw new AssertionError(msg);
9b8ba80e9327 8141619: Develop new tests for JVMCI compilerToVM class' CP related methods
kshefov
parents:
diff changeset
   124
            }
9b8ba80e9327 8141619: Develop new tests for JVMCI compilerToVM class' CP related methods
kshefov
parents:
diff changeset
   125
        }
9b8ba80e9327 8141619: Develop new tests for JVMCI compilerToVM class' CP related methods
kshefov
parents:
diff changeset
   126
    }
9b8ba80e9327 8141619: Develop new tests for JVMCI compilerToVM class' CP related methods
kshefov
parents:
diff changeset
   127
}