test/hotspot/jtreg/compiler/jvmci/compilerToVM/LookupKlassInPoolTest.java
author kvn
Tue, 04 Jun 2019 12:44:53 -0700
changeset 55206 2fe2063fe567
parent 52427 3c6aa484536c
permissions -rw-r--r--
8225019: Update JVMCI Reviewed-by: never, dlong
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
33160
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
     1
/*
55206
2fe2063fe567 8225019: Update JVMCI
kvn
parents: 52427
diff changeset
     2
 * Copyright (c) 2015, 2019, Oracle and/or its affiliates. All rights reserved.
33160
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
     4
 *
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
     7
 * published by the Free Software Foundation.
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
     8
 *
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
    13
 * accompanied this code).
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
    14
 *
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
    18
 *
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
    21
 * questions.
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
    22
 */
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
    23
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
    24
/*
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
    25
 * @test
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
    26
 * @bug 8136421
42607
acd91f1875d4 8170227: use vm.jvmci property in compiler/jvmci tests
iignatyev
parents: 41705
diff changeset
    27
 * @requires vm.jvmci
33160
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
    28
 * @summary Testing compiler.jvmci.CompilerToVM.lookupKlassInPool method
40631
ed82623d7831 8157957: ClassNotFoundException: jdk.test.lib.JDKToolFinder
ctornqvi
parents: 40059
diff changeset
    29
 * @library /test/lib /
36508
5f9eee6b383b 8142968: Module System implementation
alanb
parents: 36305
diff changeset
    30
 * @library ../common/patches
52427
3c6aa484536c 8211122: Reduce the number of internal classes made accessible to jdk.unsupported
mchung
parents: 47216
diff changeset
    31
 * @modules java.base/jdk.internal.access
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: 36305
diff changeset
    33
 *          java.base/jdk.internal.org.objectweb.asm
5f9eee6b383b 8142968: Module System implementation
alanb
parents: 36305
diff changeset
    34
 *          java.base/jdk.internal.org.objectweb.asm.tree
43972
1ade39b8381b 8174879: Rename jdk.vm.ci to jdk.internal.vm.ci
kvn
parents: 42607
diff changeset
    35
 *          jdk.internal.vm.ci/jdk.vm.ci.hotspot
1ade39b8381b 8174879: Rename jdk.vm.ci to jdk.internal.vm.ci
kvn
parents: 42607
diff changeset
    36
 *          jdk.internal.vm.ci/jdk.vm.ci.runtime
1ade39b8381b 8174879: Rename jdk.vm.ci to jdk.internal.vm.ci
kvn
parents: 42607
diff changeset
    37
 *          jdk.internal.vm.ci/jdk.vm.ci.meta
40053
b3617982544e 8160657: Compiler HotSpot tests should use the "run driver" directive where applicable
iignatyev
parents: 39450
diff changeset
    38
 *
43972
1ade39b8381b 8174879: Rename jdk.vm.ci to jdk.internal.vm.ci
kvn
parents: 42607
diff changeset
    39
 * @build jdk.internal.vm.ci/jdk.vm.ci.hotspot.CompilerToVMHelper sun.hotspot.WhiteBox
40053
b3617982544e 8160657: Compiler HotSpot tests should use the "run driver" directive where applicable
iignatyev
parents: 39450
diff changeset
    40
 * @run driver ClassFileInstaller sun.hotspot.WhiteBox
b3617982544e 8160657: Compiler HotSpot tests should use the "run driver" directive where applicable
iignatyev
parents: 39450
diff changeset
    41
 *                                sun.hotspot.WhiteBox$WhiteBoxPermission
36508
5f9eee6b383b 8142968: Module System implementation
alanb
parents: 36305
diff changeset
    42
 * @run main/othervm -Xbootclasspath/a:.
5f9eee6b383b 8142968: Module System implementation
alanb
parents: 36305
diff changeset
    43
 *                   -XX:+UnlockExperimentalVMOptions -XX:+EnableJVMCI
5f9eee6b383b 8142968: Module System implementation
alanb
parents: 36305
diff changeset
    44
 *                   -XX:+UnlockDiagnosticVMOptions -XX:+WhiteBoxAPI
55206
2fe2063fe567 8225019: Update JVMCI
kvn
parents: 52427
diff changeset
    45
 *                   -XX:-UseJVMCICompiler
36508
5f9eee6b383b 8142968: Module System implementation
alanb
parents: 36305
diff changeset
    46
 *                   compiler.jvmci.compilerToVM.LookupKlassInPoolTest
33160
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
    47
 */
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
    48
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
    49
package compiler.jvmci.compilerToVM;
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
    50
36305
55c7fe59d6d7 8141618: Change JVMCI compilerToVM constant pool tests to support CP cache
kshefov
parents: 35148
diff changeset
    51
import compiler.jvmci.compilerToVM.ConstantPoolTestCase.ConstantTypes;
55c7fe59d6d7 8141618: Change JVMCI compilerToVM constant pool tests to support CP cache
kshefov
parents: 35148
diff changeset
    52
import compiler.jvmci.compilerToVM.ConstantPoolTestCase.TestedCPEntry;
55c7fe59d6d7 8141618: Change JVMCI compilerToVM constant pool tests to support CP cache
kshefov
parents: 35148
diff changeset
    53
import compiler.jvmci.compilerToVM.ConstantPoolTestCase.Validator;
40059
c2304140ed64 8132919: Put compiler tests in packages
tpivovarova
parents: 40053
diff changeset
    54
import compiler.jvmci.compilerToVM.ConstantPoolTestsHelper.DummyClasses;
33160
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
    55
import jdk.vm.ci.hotspot.CompilerToVMHelper;
33632
038347770a9e 8139170: JVMCI refresh
twisti
parents: 33160
diff changeset
    56
import jdk.vm.ci.hotspot.HotSpotResolvedObjectType;
36305
55c7fe59d6d7 8141618: Change JVMCI compilerToVM constant pool tests to support CP cache
kshefov
parents: 35148
diff changeset
    57
import jdk.vm.ci.meta.ConstantPool;
33160
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
    58
40059
c2304140ed64 8132919: Put compiler tests in packages
tpivovarova
parents: 40053
diff changeset
    59
import java.util.HashMap;
c2304140ed64 8132919: Put compiler tests in packages
tpivovarova
parents: 40053
diff changeset
    60
import java.util.Map;
c2304140ed64 8132919: Put compiler tests in packages
tpivovarova
parents: 40053
diff changeset
    61
c2304140ed64 8132919: Put compiler tests in packages
tpivovarova
parents: 40053
diff changeset
    62
import static compiler.jvmci.compilerToVM.ConstantPoolTestCase.ConstantTypes.CONSTANT_CLASS;
c2304140ed64 8132919: Put compiler tests in packages
tpivovarova
parents: 40053
diff changeset
    63
33160
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
    64
/**
36305
55c7fe59d6d7 8141618: Change JVMCI compilerToVM constant pool tests to support CP cache
kshefov
parents: 35148
diff changeset
    65
 * Test for {@code jdk.vm.ci.hotspot.CompilerToVM.lookupKlassInPool} method
33160
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
    66
 */
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
    67
public class LookupKlassInPoolTest {
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
    68
36305
55c7fe59d6d7 8141618: Change JVMCI compilerToVM constant pool tests to support CP cache
kshefov
parents: 35148
diff changeset
    69
    public static void main(String[] args) throws Exception  {
55c7fe59d6d7 8141618: Change JVMCI compilerToVM constant pool tests to support CP cache
kshefov
parents: 35148
diff changeset
    70
        Map<ConstantTypes, Validator> typeTests = new HashMap<>();
55c7fe59d6d7 8141618: Change JVMCI compilerToVM constant pool tests to support CP cache
kshefov
parents: 35148
diff changeset
    71
        typeTests.put(CONSTANT_CLASS, LookupKlassInPoolTest::validate);
33160
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
    72
        ConstantPoolTestCase testCase = new ConstantPoolTestCase(typeTests);
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
    73
        testCase.test();
36305
55c7fe59d6d7 8141618: Change JVMCI compilerToVM constant pool tests to support CP cache
kshefov
parents: 35148
diff changeset
    74
        // The next "Class.forName" and repeating "testCase.test()"
55c7fe59d6d7 8141618: Change JVMCI compilerToVM constant pool tests to support CP cache
kshefov
parents: 35148
diff changeset
    75
        // are here for the following reason.
55c7fe59d6d7 8141618: Change JVMCI compilerToVM constant pool tests to support CP cache
kshefov
parents: 35148
diff changeset
    76
        // The first test run is without dummy class initialization,
55c7fe59d6d7 8141618: Change JVMCI compilerToVM constant pool tests to support CP cache
kshefov
parents: 35148
diff changeset
    77
        // which means no constant pool cache exists.
55c7fe59d6d7 8141618: Change JVMCI compilerToVM constant pool tests to support CP cache
kshefov
parents: 35148
diff changeset
    78
        // The second run is with initialized class (with constant pool cache available).
55c7fe59d6d7 8141618: Change JVMCI compilerToVM constant pool tests to support CP cache
kshefov
parents: 35148
diff changeset
    79
        // Some CompilerToVM methods require different input
55c7fe59d6d7 8141618: Change JVMCI compilerToVM constant pool tests to support CP cache
kshefov
parents: 35148
diff changeset
    80
        // depending on whether CP cache exists or not.
55c7fe59d6d7 8141618: Change JVMCI compilerToVM constant pool tests to support CP cache
kshefov
parents: 35148
diff changeset
    81
        for (DummyClasses dummy : DummyClasses.values()) {
55c7fe59d6d7 8141618: Change JVMCI compilerToVM constant pool tests to support CP cache
kshefov
parents: 35148
diff changeset
    82
            Class.forName(dummy.klass.getName());
55c7fe59d6d7 8141618: Change JVMCI compilerToVM constant pool tests to support CP cache
kshefov
parents: 35148
diff changeset
    83
        }
55c7fe59d6d7 8141618: Change JVMCI compilerToVM constant pool tests to support CP cache
kshefov
parents: 35148
diff changeset
    84
        testCase.test();
33160
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
    85
    }
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
    86
36305
55c7fe59d6d7 8141618: Change JVMCI compilerToVM constant pool tests to support CP cache
kshefov
parents: 35148
diff changeset
    87
    public static void validate(ConstantPool constantPoolCTVM,
55c7fe59d6d7 8141618: Change JVMCI compilerToVM constant pool tests to support CP cache
kshefov
parents: 35148
diff changeset
    88
                                ConstantTypes cpType,
55c7fe59d6d7 8141618: Change JVMCI compilerToVM constant pool tests to support CP cache
kshefov
parents: 35148
diff changeset
    89
                                DummyClasses dummyClass,
55c7fe59d6d7 8141618: Change JVMCI compilerToVM constant pool tests to support CP cache
kshefov
parents: 35148
diff changeset
    90
                                int i) {
55c7fe59d6d7 8141618: Change JVMCI compilerToVM constant pool tests to support CP cache
kshefov
parents: 35148
diff changeset
    91
        TestedCPEntry entry = cpType.getTestedCPEntry(dummyClass, i);
55c7fe59d6d7 8141618: Change JVMCI compilerToVM constant pool tests to support CP cache
kshefov
parents: 35148
diff changeset
    92
        if (entry == null) {
55c7fe59d6d7 8141618: Change JVMCI compilerToVM constant pool tests to support CP cache
kshefov
parents: 35148
diff changeset
    93
            return;
55c7fe59d6d7 8141618: Change JVMCI compilerToVM constant pool tests to support CP cache
kshefov
parents: 35148
diff changeset
    94
        }
55c7fe59d6d7 8141618: Change JVMCI compilerToVM constant pool tests to support CP cache
kshefov
parents: 35148
diff changeset
    95
        Object classToVerify = CompilerToVMHelper.lookupKlassInPool(constantPoolCTVM, i);
55c7fe59d6d7 8141618: Change JVMCI compilerToVM constant pool tests to support CP cache
kshefov
parents: 35148
diff changeset
    96
        if (!(classToVerify instanceof HotSpotResolvedObjectType) && !(classToVerify instanceof String)) {
55c7fe59d6d7 8141618: Change JVMCI compilerToVM constant pool tests to support CP cache
kshefov
parents: 35148
diff changeset
    97
            String msg = String.format("Output of method CTVM.lookupKlassInPool is neither"
55c7fe59d6d7 8141618: Change JVMCI compilerToVM constant pool tests to support CP cache
kshefov
parents: 35148
diff changeset
    98
                                               + " a HotSpotResolvedObjectType, nor a String");
33160
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
    99
            throw new AssertionError(msg);
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   100
        }
36305
55c7fe59d6d7 8141618: Change JVMCI compilerToVM constant pool tests to support CP cache
kshefov
parents: 35148
diff changeset
   101
        String classNameToRefer = entry.klass;
33160
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   102
        String outputToVerify = classToVerify.toString();
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   103
        if (!outputToVerify.contains(classNameToRefer)) {
36305
55c7fe59d6d7 8141618: Change JVMCI compilerToVM constant pool tests to support CP cache
kshefov
parents: 35148
diff changeset
   104
            String msg = String.format("Wrong class accessed by constant pool index %d: %s, but should be %s",
55c7fe59d6d7 8141618: Change JVMCI compilerToVM constant pool tests to support CP cache
kshefov
parents: 35148
diff changeset
   105
                                       i,
55c7fe59d6d7 8141618: Change JVMCI compilerToVM constant pool tests to support CP cache
kshefov
parents: 35148
diff changeset
   106
                                       outputToVerify,
55c7fe59d6d7 8141618: Change JVMCI compilerToVM constant pool tests to support CP cache
kshefov
parents: 35148
diff changeset
   107
                                       classNameToRefer);
33160
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   108
            throw new AssertionError(msg);
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
    }
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   111
}